This commit is contained in:
0x3C50 2022-04-30 01:42:07 +02:00
parent c688782225
commit 494f4ec502
11 changed files with 163 additions and 30 deletions

View file

@ -44,7 +44,7 @@ public class Help extends Command {
message("All commands and their description");
for (Command command : CommandRegistry.getCommands()) {
message(command.getName() + ": " + command.getDescription());
message0(" " + String.join(", ", command.getAliases()), Color.GRAY);
message(" " + String.join(", ", command.getAliases()), Color.GRAY);
}
} else {
String s = args[0];
@ -52,8 +52,8 @@ public class Help extends Command {
if (c == null) error("Command \"" + s + "\" was not found");
else {
message("Command " + c.getName());
message0(c.getDescription(), Color.GRAY);
message0("Aliases: " + String.join(", ", c.getAliases()), Color.GRAY);
message(c.getDescription(), Color.GRAY);
message("Aliases: " + String.join(", ", c.getAliases()), Color.GRAY);
message("");
ExamplesEntry e = c.getExampleArguments();
if (e == null) {

View file

@ -250,12 +250,12 @@ public class OnlineServicesDashboardScreen extends ClientScreen implements FastT
@Override
public void onFastTick() {
deleteBtn.onFastTick();
if (deleteBtn != null) deleteBtn.onFastTick();
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
return deleteBtn.mouseClicked(mouseX, mouseY, button);
return deleteBtn != null && deleteBtn.mouseClicked(mouseX, mouseY, button);
}
}

View file

@ -19,7 +19,7 @@ import java.net.URI;
public class IRC extends Module {
static String ircPrefix = "#";
IRCWebSocket wsS;
public IRCWebSocket wsS;
public IRC() {
super("IRC", "Chat with others using the client", ModuleType.MISC);
@ -48,6 +48,9 @@ public class IRC extends Module {
setEnabled(false);
return;
}
initSock();
}
void initSock() {
this.wsS = new IRCWebSocket(URI.create(ShadowAPIWrapper.BASE_WS + "/irc"), ShadowAPIWrapper.getAuthKey(), () -> {
this.wsS = null;
if (this.isEnabled()) this.setEnabled(false);
@ -60,6 +63,11 @@ public class IRC extends Module {
if (this.wsS != null) this.wsS.close();
}
public void reconnect() {
if (this.wsS != null) this.wsS.close();
initSock();
}
@Override
public String getContext() {
return null;

View file

@ -4,6 +4,7 @@
package net.shadow.client.feature.module.impl.render;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.client.util.math.MatrixStack;
@ -13,6 +14,8 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.world.GameMode;
import net.shadow.client.feature.module.Module;
import net.shadow.client.feature.module.ModuleType;
import net.shadow.client.helper.GameTexture;
import net.shadow.client.helper.IRCWebSocket;
import net.shadow.client.helper.font.FontRenderers;
import net.shadow.client.helper.font.adapter.FontAdapter;
import net.shadow.client.helper.render.Renderer;
@ -74,11 +77,28 @@ public class NameTags extends Module {
}
MatrixStack stack1 = Renderer.R3D.getEmptyMatrixStack();
Vec3d actual = new Vec3d(screenPos.x, screenPos.y - labelHeight, screenPos.z);
float fontWidth = nameDrawer.getStringWidth(text) + 4;
float width = fontWidth;
width = Math.max(width, 70);
float width = nameDrawer.getStringWidth(text) + 4;
width = Math.max(width, 60);
boolean in = IRCWebSocket.knownIRCPlayers.stream().anyMatch(playerEntry -> playerEntry.uuid().equals(entity.getUuid()));
double origWidth = 782;
double origHeight = 1000;
double newHeight = nameDrawer.getFontHeight();
double newWidth = origWidth*(newHeight /origHeight);
double req = newWidth+5;
if (in) {
if (width-req < nameDrawer.getStringWidth(text)) width += newWidth+5; // make sure we always have some space to draw the icon
}
Renderer.R2D.renderRoundedQuad(stack1, new Color(0, 0, 5, 200), actual.x - width / 2d, actual.y, actual.x + width / 2d, actual.y + labelHeight, 3, 20);
nameDrawer.drawString(stack1, text, actual.x - fontWidth / 2d + 2, actual.y + 2, 0xFFFFFF);
nameDrawer.drawString(stack1, text, actual.x + width/2d - nameDrawer.getStringWidth(text)-2, actual.y + 2, 0xFFFFFF);
if (in) {
RenderSystem.setShaderTexture(0, GameTexture.TEXTURE_ICON.getWhere());
Renderer.R2D.renderTexture(stack1, actual.x -width/2d+2,actual.y+2, newWidth,newHeight,0,0, newWidth,newHeight, newWidth,newHeight);
}
infoDrawer.drawString(stack1, gmString, actual.x + width / 2d - infoDrawer.getStringWidth(gmString) - 2, actual.y + 2 + nameDrawer.getFontHeight(), 0xAAAAAA);
if (ping != -1)
infoDrawer.drawString(stack1, pingStr, actual.x - width / 2d + 2, actual.y + 2 + nameDrawer.getFontHeight(), 0xAAAAAA);
@ -105,7 +125,7 @@ public class NameTags extends Module {
@Override
public void onWorldRender(MatrixStack matrices) {
// sort the entire thing based on the most distant to the least distant because thats how rendering works
for (AbstractClientPlayerEntity player : client.world.getPlayers().stream().sorted(Comparator.comparingDouble(value -> -value.getPos().distanceTo(client.gameRenderer.getCamera().getPos()))).filter(abstractClientPlayerEntity -> !abstractClientPlayerEntity.equals(client.player)).toList()) {
for (AbstractClientPlayerEntity player : client.world.getPlayers().stream().sorted(Comparator.comparingDouble(value -> -value.getPos().distanceTo(client.gameRenderer.getCamera().getPos())))/*.filter(abstractClientPlayerEntity -> !abstractClientPlayerEntity.equals(client.player))*/.toList()) {
// String t = player.getEntityName();
render(matrices, player, player.getName());
}

View file

@ -5,6 +5,7 @@
package net.shadow.client.helper;
import com.google.gson.Gson;
import com.google.gson.internal.LinkedTreeMap;
import lombok.AllArgsConstructor;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
@ -14,18 +15,25 @@ import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
public class IRCWebSocket extends WebSocketClient {
public record PlayerEntry(String username, UUID uuid) {
}
public static List<PlayerEntry> knownIRCPlayers = new CopyOnWriteArrayList<>();
String authToken;
Runnable onClose;
public IRCWebSocket(URI serverUri, String authToken, Runnable onClose) {
super(serverUri, Map.of("Authorization", authToken));
super(serverUri, Map.of("Authorization", authToken, "X-MC-UUID", ShadowMain.client.getSession().getUuid(), "X-MC-USERNAME", ShadowMain.client.getSession().getUsername()));
this.authToken = authToken;
this.onClose = onClose;
}
@Override
public void onOpen(ServerHandshake handshakedata) {
Utils.Logging.success("Connected to IRC");
@ -38,20 +46,35 @@ public class IRCWebSocket extends WebSocketClient {
case "message" -> {
String uname = p.data.get("who").toString();
String msg = p.data.get("message").toString();
ShadowMain.client.player.sendMessage(Text.of(String.format("%s[IRC] %s[%s] %s", Formatting.AQUA, Formatting.BLUE, uname, msg)), false);
Utils.Logging.message(Text.of(String.format("%s[IRC] %s[%s] %s", Formatting.AQUA, Formatting.BLUE, uname, msg)));
}
case "userJoined" -> {
String uname = p.data.get("who").toString();
ShadowMain.client.player.sendMessage(Text.of(String.format("%s[IRC] %s%s joined the IRC", Formatting.AQUA, Formatting.GREEN, uname)), false);
Utils.Logging.message(Text.of(String.format("%s[IRC] %s%s joined the IRC", Formatting.AQUA, Formatting.GREEN, uname)));
}
case "userLeft" -> {
String uname = p.data.get("who").toString();
ShadowMain.client.player.sendMessage(Text.of(String.format("%s[IRC] %s%s left the IRC", Formatting.AQUA, Formatting.RED, uname)), false);
Utils.Logging.message(Text.of(String.format("%s[IRC] %s%s left the IRC", Formatting.AQUA, Formatting.RED, uname)));
}
case "connectFailed" -> {
String reason = p.data.get("reason").toString();
Utils.Logging.error("Failed to establish connection, server said: " + reason);
}
case "usersList" -> {
knownIRCPlayers.clear();
for (LinkedTreeMap<String, String> who : ((ArrayList<LinkedTreeMap<String, String>>) p.data.get("who"))) {
String u = who.get("username");
UUID uuid;
try {
uuid = UUID.fromString(who.get("uuid"));
} catch (Exception ignored) {
continue;
}
PlayerEntry pe = new PlayerEntry(u,uuid);
if(!knownIRCPlayers.contains(pe)) knownIRCPlayers.add(pe);
}
}
}
}
@ -59,6 +82,7 @@ public class IRCWebSocket extends WebSocketClient {
public void onClose(int code, String reason, boolean remote) {
Utils.Logging.error("IRC Disconnected");
this.onClose.run();
knownIRCPlayers.clear();
}
@Override

View file

@ -19,9 +19,9 @@ import java.util.List;
import java.util.Map;
public class ShadowAPIWrapper {
public static final String BASE_DOMAIN = "api.shadowclient.cf";
public static final String BASE_URL = "https://" + BASE_DOMAIN;
public static final String BASE_WS = "wss://" + BASE_DOMAIN;
public static final String BASE_DOMAIN = "localhost:8080";
public static final String BASE_URL = "http://" + BASE_DOMAIN;
public static final String BASE_WS = "ws://" + BASE_DOMAIN;
static String authKey = "";
static HttpClient client = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.ALWAYS).build();
static Gson gson = new Gson();

View file

@ -16,6 +16,7 @@ import net.minecraft.nbt.StringNbtReader;
import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TextColor;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
@ -46,11 +47,13 @@ import java.net.http.HttpResponse;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Queue;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
@ -367,27 +370,37 @@ public class Utils {
}
public static class Logging {
static Queue<Text> messageQueue = new ArrayDeque<>();
static void sendMessages() {
if (ShadowMain.client.player != null) {
Text next;
while((next = messageQueue.poll()) != null) {
ShadowMain.client.player.sendMessage(next, false);
}
}
}
public static void warn(String n) {
message0(n, Color.YELLOW);
message(n, Color.YELLOW);
}
public static void success(String n) {
message0(n, new Color(65, 217, 101));
message(n, new Color(65, 217, 101));
}
public static void error(String n) {
message0(n, new Color(214, 93, 62));
message(n, new Color(214, 93, 62));
}
public static void message(String n) {
message0(n, Color.WHITE);
message(n, Color.WHITE);
}
public static void message0(String n, Color c) {
public static void message(Text text) {
messageQueue.add(text);
}
public static void message(String n, Color c) {
LiteralText t = new LiteralText(n);
t.setStyle(t.getStyle().withColor(TextColor.fromRgb(c.getRGB())));
if (ShadowMain.client.player != null) if (!(ShadowMain.client.currentScreen instanceof ConsoleScreen))
ShadowMain.client.player.sendMessage(t, false);
if (!(ShadowMain.client.currentScreen instanceof ConsoleScreen)) message(t);
// if (c.equals(Color.WHITE)) c = Color.BLACK;
ConsoleScreen.instance().addLog(new ConsoleScreen.LogEntry(n, c));
}
@ -404,6 +417,7 @@ public class Utils {
}
public static void tick() {
Logging.sendMessages();
for (TickEntry entry : entries.toArray(new TickEntry[0])) {
entry.v--;
if (entry.v <= 0) {

View file

@ -7,15 +7,20 @@ package net.shadow.client.mixin;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.RunArgs;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.Session;
import net.shadow.client.ShadowMain;
import net.shadow.client.feature.module.ModuleRegistry;
import net.shadow.client.feature.module.impl.misc.IRC;
import net.shadow.client.feature.module.impl.world.FastUse;
import net.shadow.client.helper.event.EventType;
import net.shadow.client.helper.event.Events;
import net.shadow.client.helper.event.events.base.NonCancellableEvent;
import net.shadow.client.helper.manager.ConfigManager;
import net.shadow.client.mixinUtil.MinecraftClientDuck;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@ -25,16 +30,29 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Objects;
@Mixin(MinecraftClient.class)
public class MinecraftClientMixin {
public class MinecraftClientMixin implements MinecraftClientDuck {
@Shadow
private int itemUseCooldown;
@Mutable
@Shadow @Final private Session session;
@Inject(method = "stop", at = @At("HEAD"))
void real(CallbackInfo ci) {
ConfigManager.saveState();
Events.fireEvent(EventType.GAME_EXIT, new NonCancellableEvent());
}
@Override
public void setSession(Session newSession) {
this.session = newSession;
IRC i = ModuleRegistry.getByClass(IRC.class);
// reconnect to the irc with the new session to stay up to date
if (i.isEnabled()) {
i.reconnect();
}
}
@Inject(method = "<init>", at = @At("TAIL"))
void postInit(RunArgs args, CallbackInfo ci) {
ShadowMain.INSTANCE.postWindowInit();

View file

@ -0,0 +1,37 @@
/*
* Copyright (c) Shadow client, 0x150, Saturn5VFive 2022. All rights reserved.
*/
package net.shadow.client.mixin;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.hud.PlayerListHud;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.client.util.math.MatrixStack;
import net.shadow.client.helper.GameTexture;
import net.shadow.client.helper.IRCWebSocket;
import net.shadow.client.helper.render.Renderer;
import net.shadow.client.helper.util.Utils;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(PlayerListHud.class)
public abstract class PlayerListHudMixin {
@Inject(method="renderLatencyIcon",at=@At("HEAD"),cancellable = true)
void a(MatrixStack matrices, int width, int x, int y, PlayerListEntry entry, CallbackInfo ci) {
if (IRCWebSocket.knownIRCPlayers.stream().anyMatch(playerEntry -> playerEntry.uuid().equals(entry.getProfile().getId()))) {
ci.cancel();
double supposedWidth = 10;
double origWidth = 782;
double origHeight = 1000;
double newHeight = 8;
double newWidth = origWidth*(newHeight /origHeight);
Utils.TickManager.runOnNextRender(() -> {
RenderSystem.setShaderTexture(0, GameTexture.TEXTURE_ICON.getWhere());
Renderer.R2D.renderTexture(matrices,x + width - supposedWidth/2d - newWidth/2d -1,y, newWidth,newHeight,0,0, newWidth,newHeight, newWidth,newHeight);
});
}
}
}

View file

@ -0,0 +1,11 @@
/*
* Copyright (c) Shadow client, 0x150, Saturn5VFive 2022. All rights reserved.
*/
package net.shadow.client.mixinUtil;
import net.minecraft.client.util.Session;
public interface MinecraftClientDuck {
void setSession(Session newSession);
}

View file

@ -33,6 +33,7 @@
"IClientPlayerInteractionManagerAccessor",
"ICustomPayloadC2SPacketAccessor",
"IDebugHudAccessor",
"IdentifierAccessor",
"IEntityVelocityUpdateS2CPacketMixin",
"IInGameHudAccessor",
"ILivingEntityAccessor",
@ -57,6 +58,7 @@
"PlayerEntityMixin",
"PlayerEntityRendererMixin",
"PlayerInteractEntityC2SPacketAccessor",
"PlayerListHudMixin",
"RebuildTaskMixin",
"ScreenMixin",
"SelectWorldScreenMixin",
@ -67,8 +69,7 @@
"SliderWidgetMixin",
"TitleScreenMixin",
"WorldRendererAccessor",
"WorldRendererMixin",
"IdentifierAccessor"
"WorldRendererMixin"
],
"client": [],
"server": [],