From 78a0bc20345b4f0d9335bb9a6f9bf9ac382398ff Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Sun, 12 Nov 2023 18:39:32 +0100 Subject: [PATCH] utils are now used and working --- .../java/de/cscherr/mcpht/MCPHTClient.java | 1 + .../de/cscherr/mcpht/config/MCPHTConfig.java | 28 +++++++++++------- .../java/de/cscherr/mcpht/{ => hack}/Fly.java | 3 +- .../de/cscherr/mcpht/{ => hack}/XRay.java | 9 +++--- .../client/MixinBlockOcclusionCache.java | 23 --------------- ...ketLog.java => MixinClientConnection.java} | 29 ++++++++----------- .../java/de/cscherr/mcpht/util/Hack.java | 24 +++++++-------- .../java/de/cscherr/mcpht/util/MaybeKey.java | 10 ++++--- src/client/resources/mcpht.client.mixins.json | 3 +- src/client/resources/mcpht.sodium.mixins.json | 16 ---------- src/main/resources/fabric.mod.json | 7 +---- 11 files changed, 57 insertions(+), 96 deletions(-) rename src/client/java/de/cscherr/mcpht/{ => hack}/Fly.java (84%) rename src/client/java/de/cscherr/mcpht/{ => hack}/XRay.java (91%) delete mode 100644 src/client/java/de/cscherr/mcpht/mixin/client/MixinBlockOcclusionCache.java rename src/client/java/de/cscherr/mcpht/mixin/client/{MixinNetworkPacketLog.java => MixinClientConnection.java} (78%) delete mode 100644 src/client/resources/mcpht.sodium.mixins.json diff --git a/src/client/java/de/cscherr/mcpht/MCPHTClient.java b/src/client/java/de/cscherr/mcpht/MCPHTClient.java index 09d2259..1c5c6d1 100644 --- a/src/client/java/de/cscherr/mcpht/MCPHTClient.java +++ b/src/client/java/de/cscherr/mcpht/MCPHTClient.java @@ -1,6 +1,7 @@ package de.cscherr.mcpht; import de.cscherr.mcpht.config.MCPHTConfig; +import de.cscherr.mcpht.hack.XRay; import me.shedaniel.autoconfig.AutoConfig; import net.fabricmc.api.ClientModInitializer; import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer; diff --git a/src/client/java/de/cscherr/mcpht/config/MCPHTConfig.java b/src/client/java/de/cscherr/mcpht/config/MCPHTConfig.java index 257b708..1fbe087 100644 --- a/src/client/java/de/cscherr/mcpht/config/MCPHTConfig.java +++ b/src/client/java/de/cscherr/mcpht/config/MCPHTConfig.java @@ -47,27 +47,35 @@ public class MCPHTConfig implements ConfigData { MCPHTClient.LOGGER.info("loading configs"); MCPHTClient.networkPacketFilter = compileFilter(); - MCPHTClient.MC.worldRenderer.reload(); + if (MCPHTClient.MC.worldRenderer != null) { + MCPHTClient.MC.worldRenderer.reload(); + } logSettings(); } public void logSettings() { + // TODO: autogenerate this from Hack classes MCPHTClient.LOGGER.info(String.format(""" - CONFIG:\s - NetworkLogging - RX: %b - TX: %b - verbosity: %s - regex: '%s' - filter: %s + Networking + NetworkLogging + RX: %b + TX: %b + verbosity: %s + regex: '%s' + filter: %s Rendering - enabled: %b""", + XRay: + enabled: %b + XRay: + enabled: %b + """, MCPHTClient.CONFIG.networkLogging.RX, MCPHTClient.CONFIG.networkLogging.TX, MCPHTClient.CONFIG.networkLogging.verbosity, MCPHTClient.CONFIG.networkLogging.regex, MCPHTClient.networkPacketFilter, - MCPHTClient.CONFIG.xRay.enable + MCPHTClient.CONFIG.xRay.enable, + MCPHTClient.CONFIG.fly.enable )); } private Pattern compileFilter() { diff --git a/src/client/java/de/cscherr/mcpht/Fly.java b/src/client/java/de/cscherr/mcpht/hack/Fly.java similarity index 84% rename from src/client/java/de/cscherr/mcpht/Fly.java rename to src/client/java/de/cscherr/mcpht/hack/Fly.java index 1319d1a..e51640b 100644 --- a/src/client/java/de/cscherr/mcpht/Fly.java +++ b/src/client/java/de/cscherr/mcpht/hack/Fly.java @@ -1,6 +1,7 @@ -package de.cscherr.mcpht; +package de.cscherr.mcpht.hack; +import de.cscherr.mcpht.MCPHTClient; import de.cscherr.mcpht.util.Hack; import de.cscherr.mcpht.util.MaybeKey; import net.minecraft.client.option.KeyBinding; diff --git a/src/client/java/de/cscherr/mcpht/XRay.java b/src/client/java/de/cscherr/mcpht/hack/XRay.java similarity index 91% rename from src/client/java/de/cscherr/mcpht/XRay.java rename to src/client/java/de/cscherr/mcpht/hack/XRay.java index bb0412d..4154990 100644 --- a/src/client/java/de/cscherr/mcpht/XRay.java +++ b/src/client/java/de/cscherr/mcpht/hack/XRay.java @@ -1,11 +1,11 @@ -package de.cscherr.mcpht; +package de.cscherr.mcpht.hack; +import de.cscherr.mcpht.MCPHTClient; import de.cscherr.mcpht.util.Hack; import de.cscherr.mcpht.util.MaybeKey; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; -import net.minecraft.client.option.KeyBinding; import org.lwjgl.glfw.GLFW; import java.util.ArrayList; @@ -83,11 +83,12 @@ public class XRay extends Hack { super(new MaybeKey("key.mcpht.toggleXray", "category.mcpht.rendering", GLFW.GLFW_KEY_X)); + MCPHTClient.LOGGER.info(String.format("xray key: %s (%b)", this.toggleKey, this.toggleKey.hasKey)); } @Override public void onKeyPress() { - MCPHTClient.XRAY.enable = !MCPHTClient.XRAY.enable; + MCPHTClient.XRAY.setEnable(!MCPHTClient.XRAY.getEnable()); MCPHTClient.MC.worldRenderer.reload(); } @@ -97,6 +98,6 @@ public class XRay extends Hack { @Override public boolean getEnable() { - return enable && MCPHTClient.CONFIG.xRay.enable; + return this.enable && MCPHTClient.CONFIG.xRay.enable; } } \ No newline at end of file diff --git a/src/client/java/de/cscherr/mcpht/mixin/client/MixinBlockOcclusionCache.java b/src/client/java/de/cscherr/mcpht/mixin/client/MixinBlockOcclusionCache.java deleted file mode 100644 index f4a6fd4..0000000 --- a/src/client/java/de/cscherr/mcpht/mixin/client/MixinBlockOcclusionCache.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.cscherr.mcpht.mixin.client; - -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.BlockView; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Pseudo -@Mixin(targets = "me.jellysquid.mods.sodium.client.render.occlusion.BlockOcclusionCache") -/** - * Fix for sodium, so that it doesn't break xray. - */ -public class MixinBlockOcclusionCache { - @Inject(at = @At("HEAD"), method = "shouldDrawSide", cancellable = true, remap = false) - private void shouldDrawSide(BlockState state, BlockView reader, BlockPos pos, Direction face, - CallbackInfoReturnable ci) { - } -} \ No newline at end of file diff --git a/src/client/java/de/cscherr/mcpht/mixin/client/MixinNetworkPacketLog.java b/src/client/java/de/cscherr/mcpht/mixin/client/MixinClientConnection.java similarity index 78% rename from src/client/java/de/cscherr/mcpht/mixin/client/MixinNetworkPacketLog.java rename to src/client/java/de/cscherr/mcpht/mixin/client/MixinClientConnection.java index f6620f2..48570f8 100644 --- a/src/client/java/de/cscherr/mcpht/mixin/client/MixinNetworkPacketLog.java +++ b/src/client/java/de/cscherr/mcpht/mixin/client/MixinClientConnection.java @@ -15,37 +15,32 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.jetbrains.annotations.Nullable; @Mixin(ClientConnection.class) -public class MixinNetworkPacketLog { +public class MixinClientConnection { + @Unique private static boolean filterPacket(Packet packet) { return MCPHTClient.networkPacketFilter.matcher(packet.getClass().getSimpleName()).find(); } + @Unique private static String getPacketInfo(Packet packet) { - String information = null; + String information; switch (MCPHTClient.CONFIG.networkLogging.verbosity) { - case NAME -> { - information = packet.getClass().getSimpleName(); - break; - } - case ALL -> { - information = String.format("%s:\n%s", packet.getClass().getSimpleName(), getPacketFields(packet)); - break; - } + case NAME -> information = packet.getClass().getSimpleName(); + case ALL -> information = String.format("%s:\n%s", packet.getClass().getSimpleName(), getPacketFields(packet)); default -> throw new IllegalStateException("Unexpected value: " + MCPHTClient.CONFIG.networkLogging.verbosity); } return information; } + @Unique private static String getPacketFields(Packet packet) { - String fieldInfo = ""; + String fieldInfo; switch (packet.getClass().getSimpleName()) { case "PositionAndOnGround" -> { - PlayerMoveC2SPacket ppacket = (PlayerMoveC2SPacket)packet; + PlayerMoveC2SPacket pmPacket = (PlayerMoveC2SPacket)packet; fieldInfo = String.format("X: %f | Y: %f | Z: %f\n" + - "Ground: %b", ppacket.getX(0), ppacket.getY(0), ppacket.getZ(0), ppacket.isOnGround()); - } - default -> { - fieldInfo = ""; + "Ground: %b", pmPacket.getX(0), pmPacket.getY(0), pmPacket.getZ(0), pmPacket.isOnGround()); } + default -> fieldInfo = ""; } return fieldInfo; } @@ -72,7 +67,7 @@ public class MixinNetworkPacketLog { * Must be static for some reason * * @param packet the Network packet to be sent - * @param listener i dont know what this does + * @param listener i don't know what this does * @param ci magical fabric mixin stuff */ @Inject(method = "handlePacket", at = @At("HEAD")) diff --git a/src/client/java/de/cscherr/mcpht/util/Hack.java b/src/client/java/de/cscherr/mcpht/util/Hack.java index cf1a463..1fd2405 100644 --- a/src/client/java/de/cscherr/mcpht/util/Hack.java +++ b/src/client/java/de/cscherr/mcpht/util/Hack.java @@ -2,32 +2,25 @@ package de.cscherr.mcpht.util; import de.cscherr.mcpht.MCPHTClient; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; -import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; -import net.minecraft.client.option.KeyBinding; -import net.minecraft.client.util.InputUtil; -import org.lwjgl.glfw.GLFW; - -import java.util.Optional; public abstract class Hack { public boolean enable = false; public MaybeKey toggleKey; public Hack(MaybeKey toggleKey) { - toggleKey = toggleKey; + this.toggleKey = toggleKey; } public void init() { if (toggleKey.hasKey) { + MCPHTClient.LOGGER.info("init key register start"); ClientTickEvents.END_CLIENT_TICK.register(client -> { // NOTE: IDK why we need a while here while (toggleKey.key.wasPressed()) { - if (this.getEnable()) { - MCPHTClient.LOGGER.info(String.format("toggle %s: %s", - this.getClass().getSimpleName(), - this.getEnable())); - onKeyPress(); - } + MCPHTClient.LOGGER.info(String.format("toggle %s: %s", + this.getClass().getSimpleName(), + this.getEnable())); + onKeyPress(); } }); } @@ -36,4 +29,9 @@ public abstract class Hack { public abstract void onKeyPress(); public abstract boolean getEnable(); + + public void setEnable(boolean newEnable) { + MCPHTClient.LOGGER.info(String.format("set enable xray: %b", newEnable)); + this.enable = newEnable; + } } \ No newline at end of file diff --git a/src/client/java/de/cscherr/mcpht/util/MaybeKey.java b/src/client/java/de/cscherr/mcpht/util/MaybeKey.java index f5790a5..fd9a7f8 100644 --- a/src/client/java/de/cscherr/mcpht/util/MaybeKey.java +++ b/src/client/java/de/cscherr/mcpht/util/MaybeKey.java @@ -1,5 +1,6 @@ package de.cscherr.mcpht.util; +import de.cscherr.mcpht.MCPHTClient; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.minecraft.client.option.KeyBinding; import net.minecraft.client.util.InputUtil; @@ -16,12 +17,13 @@ public class MaybeKey { } public MaybeKey(String translationKey, String translationCategory, int keyCode) { - key = KeyBindingHelper.registerKeyBinding(new KeyBinding( + this.key = KeyBindingHelper.registerKeyBinding(new KeyBinding( translationKey, // Translation of name InputUtil.Type.KEYSYM, // Type: MOUSE or KESYM (Keyboard) - keyCode, // The keycode of the key (default?) - translationCategory // Translation key for the keybinding category + keyCode, // The keycode of the key (default key) + translationCategory // Translation key for the keybinding category )); - hasKey = true; + MCPHTClient.LOGGER.info(String.format("key: %s", this.key)); + this.hasKey = true; } } diff --git a/src/client/resources/mcpht.client.mixins.json b/src/client/resources/mcpht.client.mixins.json index e745139..ea9a9d2 100644 --- a/src/client/resources/mcpht.client.mixins.json +++ b/src/client/resources/mcpht.client.mixins.json @@ -4,8 +4,7 @@ "compatibilityLevel": "JAVA_17", "client": [ "MixinBlock", - "MixinNetworkPacketLog", - "MixinBlockOcclusionCache", + "MixinClientConnection", "MixinLightmapTextureManager", "MixinMinecraftClient" ], diff --git a/src/client/resources/mcpht.sodium.mixins.json b/src/client/resources/mcpht.sodium.mixins.json deleted file mode 100644 index 5f36411..0000000 --- a/src/client/resources/mcpht.sodium.mixins.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "de.cscherr.mcpht.mixin.client", - "compatibilityLevel": "JAVA_8", - "mixins": [], - "client": [ - "MixinBlock", - "MixinBlockOcclusionCache", - "MixinMinecraftClient", - "MixinLightmapTextureManager" - ], - "injectors": { - "defaultRequire": 1 - } -} \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 61f94c9..b495867 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -6,8 +6,7 @@ "description": "Plex Hack Tools", "authors": [ { - "name": "Christoph J. Scherr", - "email": "software@cscherr.de" + "name": "Christoph J. Scherr" } ], "contact": { @@ -35,10 +34,6 @@ { "config": "mcpht.client.mixins.json", "environment": "client" - }, - { - "config": "mcpht.sodium.mixins.json", - "environment": "client" } ], "depends": {