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;
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;

View File

@ -47,12 +47,15 @@ public class MCPHTConfig implements ConfigData {
MCPHTClient.LOGGER.info("loading configs");
MCPHTClient.networkPacketFilter = compileFilter();
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
Networking
NetworkLogging
RX: %b
TX: %b
@ -60,14 +63,19 @@ public class MCPHTConfig implements ConfigData {
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() {

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.MaybeKey;
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.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;
}
}

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;
@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 = "<None>";
"Ground: %b", pmPacket.getX(0), pmPacket.getY(0), pmPacket.getZ(0), pmPacket.isOnGround());
}
default -> fieldInfo = "<None>";
}
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"))

View File

@ -2,33 +2,26 @@ 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();
}
}
});
}
}
@ -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;
}
}

View File

@ -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?)
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;
}
}

View File

@ -4,8 +4,7 @@
"compatibilityLevel": "JAVA_17",
"client": [
"MixinBlock",
"MixinNetworkPacketLog",
"MixinBlockOcclusionCache",
"MixinClientConnection",
"MixinLightmapTextureManager",
"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",
"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": {