utils are now used and working

This commit is contained in:
Christoph J. Scherr 2023-11-12 18:39:32 +01:00
parent e5ec40b8c2
commit 78a0bc2034
11 changed files with 57 additions and 96 deletions

View File

@ -1,6 +1,7 @@
package de.cscherr.mcpht; package de.cscherr.mcpht;
import de.cscherr.mcpht.config.MCPHTConfig; import de.cscherr.mcpht.config.MCPHTConfig;
import de.cscherr.mcpht.hack.XRay;
import me.shedaniel.autoconfig.AutoConfig; import me.shedaniel.autoconfig.AutoConfig;
import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ClientModInitializer;
import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer; import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer;

View File

@ -47,27 +47,35 @@ public class MCPHTConfig implements ConfigData {
MCPHTClient.LOGGER.info("loading configs"); MCPHTClient.LOGGER.info("loading configs");
MCPHTClient.networkPacketFilter = compileFilter(); MCPHTClient.networkPacketFilter = compileFilter();
MCPHTClient.MC.worldRenderer.reload(); if (MCPHTClient.MC.worldRenderer != null) {
MCPHTClient.MC.worldRenderer.reload();
}
logSettings(); logSettings();
} }
public void logSettings() { public void logSettings() {
// TODO: autogenerate this from Hack classes
MCPHTClient.LOGGER.info(String.format(""" MCPHTClient.LOGGER.info(String.format("""
CONFIG:\s Networking
NetworkLogging NetworkLogging
RX: %b RX: %b
TX: %b TX: %b
verbosity: %s verbosity: %s
regex: '%s' regex: '%s'
filter: %s filter: %s
Rendering Rendering
enabled: %b""", XRay:
enabled: %b
XRay:
enabled: %b
""",
MCPHTClient.CONFIG.networkLogging.RX, MCPHTClient.CONFIG.networkLogging.RX,
MCPHTClient.CONFIG.networkLogging.TX, MCPHTClient.CONFIG.networkLogging.TX,
MCPHTClient.CONFIG.networkLogging.verbosity, MCPHTClient.CONFIG.networkLogging.verbosity,
MCPHTClient.CONFIG.networkLogging.regex, MCPHTClient.CONFIG.networkLogging.regex,
MCPHTClient.networkPacketFilter, MCPHTClient.networkPacketFilter,
MCPHTClient.CONFIG.xRay.enable MCPHTClient.CONFIG.xRay.enable,
MCPHTClient.CONFIG.fly.enable
)); ));
} }
private Pattern compileFilter() { private Pattern compileFilter() {

View File

@ -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.Hack;
import de.cscherr.mcpht.util.MaybeKey; import de.cscherr.mcpht.util.MaybeKey;
import net.minecraft.client.option.KeyBinding; import net.minecraft.client.option.KeyBinding;

View File

@ -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.Hack;
import de.cscherr.mcpht.util.MaybeKey; import de.cscherr.mcpht.util.MaybeKey;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.client.option.KeyBinding;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import java.util.ArrayList; import java.util.ArrayList;
@ -83,11 +83,12 @@ public class XRay extends Hack {
super(new MaybeKey("key.mcpht.toggleXray", super(new MaybeKey("key.mcpht.toggleXray",
"category.mcpht.rendering", "category.mcpht.rendering",
GLFW.GLFW_KEY_X)); GLFW.GLFW_KEY_X));
MCPHTClient.LOGGER.info(String.format("xray key: %s (%b)", this.toggleKey, this.toggleKey.hasKey));
} }
@Override @Override
public void onKeyPress() { public void onKeyPress() {
MCPHTClient.XRAY.enable = !MCPHTClient.XRAY.enable; MCPHTClient.XRAY.setEnable(!MCPHTClient.XRAY.getEnable());
MCPHTClient.MC.worldRenderer.reload(); MCPHTClient.MC.worldRenderer.reload();
} }
@ -97,6 +98,6 @@ public class XRay extends Hack {
@Override @Override
public boolean getEnable() { public boolean getEnable() {
return enable && MCPHTClient.CONFIG.xRay.enable; return this.enable && MCPHTClient.CONFIG.xRay.enable;
} }
} }

View File

@ -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<Boolean> ci) {
}
}

View File

@ -15,37 +15,32 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@Mixin(ClientConnection.class) @Mixin(ClientConnection.class)
public class MixinNetworkPacketLog { public class MixinClientConnection {
@Unique
private static boolean filterPacket(Packet<?> packet) { private static boolean filterPacket(Packet<?> packet) {
return MCPHTClient.networkPacketFilter.matcher(packet.getClass().getSimpleName()).find(); return MCPHTClient.networkPacketFilter.matcher(packet.getClass().getSimpleName()).find();
} }
@Unique
private static String getPacketInfo(Packet<?> packet) { private static String getPacketInfo(Packet<?> packet) {
String information = null; String information;
switch (MCPHTClient.CONFIG.networkLogging.verbosity) { switch (MCPHTClient.CONFIG.networkLogging.verbosity) {
case NAME -> { case NAME -> information = packet.getClass().getSimpleName();
information = packet.getClass().getSimpleName(); case ALL -> information = String.format("%s:\n%s", packet.getClass().getSimpleName(), getPacketFields(packet));
break;
}
case ALL -> {
information = String.format("%s:\n%s", packet.getClass().getSimpleName(), getPacketFields(packet));
break;
}
default -> default ->
throw new IllegalStateException("Unexpected value: " + MCPHTClient.CONFIG.networkLogging.verbosity); throw new IllegalStateException("Unexpected value: " + MCPHTClient.CONFIG.networkLogging.verbosity);
} }
return information; return information;
} }
@Unique
private static String getPacketFields(Packet<?> packet) { private static String getPacketFields(Packet<?> packet) {
String fieldInfo = ""; String fieldInfo;
switch (packet.getClass().getSimpleName()) { switch (packet.getClass().getSimpleName()) {
case "PositionAndOnGround" -> { case "PositionAndOnGround" -> {
PlayerMoveC2SPacket ppacket = (PlayerMoveC2SPacket)packet; PlayerMoveC2SPacket pmPacket = (PlayerMoveC2SPacket)packet;
fieldInfo = String.format("X: %f | Y: %f | Z: %f\n" + fieldInfo = String.format("X: %f | Y: %f | Z: %f\n" +
"Ground: %b", ppacket.getX(0), ppacket.getY(0), ppacket.getZ(0), ppacket.isOnGround()); "Ground: %b", pmPacket.getX(0), pmPacket.getY(0), pmPacket.getZ(0), pmPacket.isOnGround());
}
default -> {
fieldInfo = "<None>";
} }
default -> fieldInfo = "<None>";
} }
return fieldInfo; return fieldInfo;
} }
@ -72,7 +67,7 @@ public class MixinNetworkPacketLog {
* Must be static for some reason * Must be static for some reason
* *
* @param packet the Network packet to be sent * @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 * @param ci magical fabric mixin stuff
*/ */
@Inject(method = "handlePacket", at = @At("HEAD")) @Inject(method = "handlePacket", at = @At("HEAD"))

View File

@ -2,32 +2,25 @@ package de.cscherr.mcpht.util;
import de.cscherr.mcpht.MCPHTClient; import de.cscherr.mcpht.MCPHTClient;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; 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 abstract class Hack {
public boolean enable = false; public boolean enable = false;
public MaybeKey toggleKey; public MaybeKey toggleKey;
public Hack(MaybeKey toggleKey) { public Hack(MaybeKey toggleKey) {
toggleKey = toggleKey; this.toggleKey = toggleKey;
} }
public void init() { public void init() {
if (toggleKey.hasKey) { if (toggleKey.hasKey) {
MCPHTClient.LOGGER.info("init key register start");
ClientTickEvents.END_CLIENT_TICK.register(client -> { ClientTickEvents.END_CLIENT_TICK.register(client -> {
// NOTE: IDK why we need a while here // NOTE: IDK why we need a while here
while (toggleKey.key.wasPressed()) { while (toggleKey.key.wasPressed()) {
if (this.getEnable()) { MCPHTClient.LOGGER.info(String.format("toggle %s: %s",
MCPHTClient.LOGGER.info(String.format("toggle %s: %s", this.getClass().getSimpleName(),
this.getClass().getSimpleName(), this.getEnable()));
this.getEnable())); onKeyPress();
onKeyPress();
}
} }
}); });
} }
@ -36,4 +29,9 @@ public abstract class Hack {
public abstract void onKeyPress(); public abstract void onKeyPress();
public abstract boolean getEnable(); public abstract boolean getEnable();
public void setEnable(boolean newEnable) {
MCPHTClient.LOGGER.info(String.format("set enable xray: %b", newEnable));
this.enable = newEnable;
}
} }

View File

@ -1,5 +1,6 @@
package de.cscherr.mcpht.util; package de.cscherr.mcpht.util;
import de.cscherr.mcpht.MCPHTClient;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.option.KeyBinding; import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil; import net.minecraft.client.util.InputUtil;
@ -16,12 +17,13 @@ public class MaybeKey {
} }
public MaybeKey(String translationKey, String translationCategory, int keyCode) { public MaybeKey(String translationKey, String translationCategory, int keyCode) {
key = KeyBindingHelper.registerKeyBinding(new KeyBinding( this.key = KeyBindingHelper.registerKeyBinding(new KeyBinding(
translationKey, // Translation of name translationKey, // Translation of name
InputUtil.Type.KEYSYM, // Type: MOUSE or KESYM (Keyboard) InputUtil.Type.KEYSYM, // Type: MOUSE or KESYM (Keyboard)
keyCode, // The keycode of the key (default?) keyCode, // The keycode of the key (default key)
translationCategory // Translation key for the keybinding category translationCategory // Translation key for the keybinding category
)); ));
hasKey = true; MCPHTClient.LOGGER.info(String.format("key: %s", this.key));
this.hasKey = true;
} }
} }

View File

@ -4,8 +4,7 @@
"compatibilityLevel": "JAVA_17", "compatibilityLevel": "JAVA_17",
"client": [ "client": [
"MixinBlock", "MixinBlock",
"MixinNetworkPacketLog", "MixinClientConnection",
"MixinBlockOcclusionCache",
"MixinLightmapTextureManager", "MixinLightmapTextureManager",
"MixinMinecraftClient" "MixinMinecraftClient"
], ],

View File

@ -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
}
}

View File

@ -6,8 +6,7 @@
"description": "Plex Hack Tools", "description": "Plex Hack Tools",
"authors": [ "authors": [
{ {
"name": "Christoph J. Scherr", "name": "Christoph J. Scherr"
"email": "software@cscherr.de"
} }
], ],
"contact": { "contact": {
@ -35,10 +34,6 @@
{ {
"config": "mcpht.client.mixins.json", "config": "mcpht.client.mixins.json",
"environment": "client" "environment": "client"
},
{
"config": "mcpht.sodium.mixins.json",
"environment": "client"
} }
], ],
"depends": { "depends": {