From a796f83114c3fa86f1e4258251c365fed623eb1a Mon Sep 17 00:00:00 2001 From: 0x3C50 Date: Fri, 22 Apr 2022 14:06:24 +0200 Subject: [PATCH 1/2] fix bug --- .../client/feature/command/impl/Test.java | 19 +- .../shadow/client/feature/module/Module.java | 3 + .../client/feature/module/ModuleRegistry.java | 289 ++++++++++-------- .../feature/module/impl/combat/Fling.java | 3 +- .../module/impl/combat/ReverseKnockback.java | 3 +- .../module/impl/crash/FlightCrash.java | 3 +- .../module/impl/crash/InteractCrash.java | 3 +- .../module/impl/exploit/FilterBypass.java | 10 +- .../client/feature/module/impl/misc/Test.java | 3 +- .../feature/module/impl/movement/ClickTP.java | 3 +- .../module/impl/render/ChestHighlighter.java | 3 +- .../feature/module/impl/render/NameTags.java | 8 +- .../shadow/client/helper/event/Events.java | 22 +- .../client/mixin/GameRendererMixin.java | 2 +- src/main/resources/changelogLatest.txt | 5 +- src/main/resources/version.txt | 2 +- 16 files changed, 208 insertions(+), 173 deletions(-) diff --git a/src/main/java/net/shadow/client/feature/command/impl/Test.java b/src/main/java/net/shadow/client/feature/command/impl/Test.java index a8e7011..c7c06a2 100644 --- a/src/main/java/net/shadow/client/feature/command/impl/Test.java +++ b/src/main/java/net/shadow/client/feature/command/impl/Test.java @@ -5,6 +5,13 @@ package net.shadow.client.feature.command.impl; import net.shadow.client.feature.command.Command; +import net.shadow.client.feature.module.AddonModule; +import net.shadow.client.feature.module.Module; +import net.shadow.client.feature.module.ModuleRegistry; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.StandardOpenOption; public class Test extends Command { public Test() { @@ -13,6 +20,16 @@ public class Test extends Command { @Override public void onExecute(String[] args) { - success("jooj"); + StringBuilder sb = new StringBuilder(); + for (Module module : ModuleRegistry.getModules()) { + if (module instanceof AddonModule) continue; + String cname = module.getClass().getSimpleName(); + sb.append(String.format("registerModule(%s.class);",cname)).append("\n"); + } + try { + Files.writeString(new File("bruh.txt").toPath(), sb.toString(), StandardOpenOption.CREATE); + } catch (Exception e) { + e.printStackTrace(); + } } } diff --git a/src/main/java/net/shadow/client/feature/module/Module.java b/src/main/java/net/shadow/client/feature/module/Module.java index a478245..ce08938 100644 --- a/src/main/java/net/shadow/client/feature/module/Module.java +++ b/src/main/java/net/shadow/client/feature/module/Module.java @@ -11,6 +11,7 @@ import net.shadow.client.feature.config.BooleanSetting; import net.shadow.client.feature.config.DoubleSetting; import net.shadow.client.feature.config.ModuleConfig; import net.shadow.client.feature.gui.notifications.Notification; +import net.shadow.client.helper.event.Events; import net.shadow.client.helper.util.Utils; import java.lang.annotation.Annotation; @@ -119,9 +120,11 @@ public abstract class Module { Notification.create(1000, "Module toggle", Notification.Type.INFO, (this.enabled ? "§aEn" : "§cDis") + "abled §r" + this.getName()); } if (this.enabled) { + Events.registerEventHandlerClass(this); this.enable(); } else { this.disable(); + Events.unregisterEventHandlerClass(this); } } diff --git a/src/main/java/net/shadow/client/feature/module/ModuleRegistry.java b/src/main/java/net/shadow/client/feature/module/ModuleRegistry.java index 228c5ab..3f09e55 100644 --- a/src/main/java/net/shadow/client/feature/module/ModuleRegistry.java +++ b/src/main/java/net/shadow/client/feature/module/ModuleRegistry.java @@ -49,6 +49,7 @@ import net.shadow.client.feature.module.impl.misc.AdBlock; import net.shadow.client.feature.module.impl.misc.AdSpammer; import net.shadow.client.feature.module.impl.misc.AllowFormatCodes; import net.shadow.client.feature.module.impl.misc.AntiCrash; +import net.shadow.client.feature.module.impl.misc.AntiOffhandCrash; import net.shadow.client.feature.module.impl.misc.AntiPacketKick; import net.shadow.client.feature.module.impl.misc.ClientSettings; import net.shadow.client.feature.module.impl.misc.DauntedAutoClaim; @@ -133,6 +134,7 @@ import net.shadow.client.feature.module.impl.world.SurvivalNuker; import net.shadow.client.feature.module.impl.world.XRAY; import org.apache.logging.log4j.Level; +import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -180,14 +182,27 @@ public class ModuleRegistry { try { initInner(); } catch (Exception e) { - e.printStackTrace(); - System.exit(1); + throw new RuntimeException(e); } } - private static void registerModule(Module module) { - ShadowMain.log(Level.INFO, "Initialized " + module.getName()); - vanillaModules.add(module); + private static void registerModule(Class moduleClass) { + Module instance = null; + for (Constructor declaredConstructor : moduleClass.getDeclaredConstructors()) { + if (declaredConstructor.getParameterCount() != 0) { + throw new IllegalArgumentException(moduleClass.getName()+" has invalid constructor: expected "+moduleClass.getName()+"(), got "+declaredConstructor); + } + try { + instance = (Module) declaredConstructor.newInstance(); + } catch (Exception e) { + throw new IllegalArgumentException("Failed to make instance of "+moduleClass.getName(), e); + } + } + if (instance == null) { + throw new IllegalArgumentException("Failed to make instance of "+moduleClass.getName()); + } + ShadowMain.log(Level.INFO, "Initialized " + instance.getName()+" via "+moduleClass.getName()); + vanillaModules.add(instance); } private static void initInner() { @@ -195,133 +210,131 @@ public class ModuleRegistry { initialized.set(true); vanillaModules.clear(); - registerModule(new Flight()); - registerModule(new Sprint()); - registerModule(new Fullbright()); - registerModule(new Hud()); - registerModule(new TargetHud()); - //modules.add(new AntiOffhandCrash()); this should be under anticrash - registerModule(new AntiPacketKick()); - registerModule(new AntiRDI()); - registerModule(new BoatPhase()); - registerModule(new BoatCrash()); - registerModule(new Boom()); - registerModule(new CaveMapper()); // its fun - registerModule(new InstaBow()); - registerModule(new ChunkCrash()); - registerModule(new OffhandCrash()); - registerModule(new OOBCrash()); - registerModule(new Phase()); - registerModule(new VanillaSpoof()); - registerModule(new XRAY()); - registerModule(new Decimator()); - registerModule(new ClickGUI()); - registerModule(new TpRange()); - registerModule(new AnyPlacer()); - registerModule(new FireballDeflector()); // its a fucking utility client saturn - registerModule(new ShulkerDeflector()); - registerModule(new CarpetBomb()); - //modules.add(new SkinChangeExploit()); litteral fucking joke module, to be re-written as personhider or whatever i named it (skinfuscator is a good name lol) - registerModule(new AutoTrap()); - registerModule(new AutoTNT()); - //modules.add(new LetThereBeLight()); awful why? - registerModule(new FakeHacker()); - registerModule(new NoFall()); - registerModule(new ESP()); - registerModule(new Tracers()); - registerModule(new Hyperspeed()); - registerModule(new AntiAnvil()); - registerModule(new Swing()); - registerModule(new AimAssist()); - registerModule(new Criticals()); - registerModule(new Killaura()); //TODO: add settings and shit - registerModule(new Velocity()); - registerModule(new AntiAntiXray()); - registerModule(new PingSpoof()); - registerModule(new AutoAttack()); - registerModule(new MouseEars()); //i really wanna remove this one | dont - registerModule(new Spinner()); - registerModule(new AllowFormatCodes()); - registerModule(new InfChatLength()); - registerModule(new NoTitles()); - registerModule(new PortalGUI()); - registerModule(new Timer()); - registerModule(new XCarry()); - registerModule(new AirJump()); //TODO: unshit - registerModule(new AutoElytra()); - registerModule(new Blink()); - registerModule(new Boost()); - registerModule(new EdgeJump()); // UTILITY CLIENT - registerModule(new EdgeSneak()); - registerModule(new EntityFly()); - registerModule(new IgnoreWorldBorder()); //i'll allow it | as you should - registerModule(new InventoryWalk()); - registerModule(new Jesus()); - registerModule(new LongJump()); - registerModule(new MoonGravity()); - registerModule(new NoJumpCool()); - registerModule(new NoLevitation()); - registerModule(new NoPush()); - registerModule(new Step()); - registerModule(new Freecam()); - registerModule(new FreeLook()); - registerModule(new ItemByteSize()); // TO BE RE-WRITTEN AS TOOLTIPS | keep it in for now tho - registerModule(new Zoom()); - registerModule(new AutoTool()); // WHY????? this is so useless | how? - registerModule(new BlockTagViewer()); - registerModule(new Annihilator()); - registerModule(new FastUse()); - registerModule(new Flattener()); - registerModule(new GodBridge()); //TODO: add this as a mode to scaffold - registerModule(new InstantBreak()); //TODO: unshit - registerModule(new MassUse()); - registerModule(new NoBreakDelay()); - registerModule(new SurvivalNuker()); - registerModule(new Nuker()); - registerModule(new Scaffold()); - registerModule(new Test()); - registerModule(new BlocksMCFlight()); - registerModule(new NameTags()); - registerModule(new Trail()); - registerModule(new AdBlock()); - registerModule(new AutoLavacast()); - registerModule(new Backtrack()); - registerModule(new TabGui()); - registerModule(new Theme()); - registerModule(new AntiCrash()); - registerModule(new ClientSettings()); - registerModule(new NoLiquidFog()); - registerModule(new Spotlight()); - registerModule(new ShowTntPrime()); - registerModule(new ToolsScreen()); - registerModule(new BookInflaterCrash()); - registerModule(new BlockHighlighting()); - registerModule(new AutoIgnite()); - registerModule(new DiscordRPC()); - registerModule(new AirPlace()); - registerModule(new AdSpammer()); - registerModule(new AnimationCrash()); - registerModule(new AutoFireball()); - registerModule(new AutoFish()); - registerModule(new AutoRun()); - registerModule(new LecternCrash()); - registerModule(new MinehutCrash()); - registerModule(new ArmorStandCrash()); - registerModule(new LoominaCrash()); - registerModule(new Reach()); - registerModule(new Fling()); - registerModule(new AutoSign()); - registerModule(new SuperCrossbow()); - registerModule(new ReverseKnockback()); - registerModule(new Speed()); - registerModule(new BoatFling()); - registerModule(new FilterBypass()); - registerModule(new InteractCrash()); - registerModule(new FlightCrash()); - registerModule(new ClickTP()); - registerModule(new ChestHighlighter()); - registerModule(new DauntedAutoClaim()); - registerModule(new MoreChatHistory()); + registerModule(Flight.class); + registerModule(Sprint.class); + registerModule(Fullbright.class); + registerModule(Hud.class); + registerModule(TargetHud.class); + registerModule(AntiOffhandCrash.class); + registerModule(AntiPacketKick.class); + registerModule(AntiRDI.class); + registerModule(BoatPhase.class); + registerModule(BoatCrash.class); + registerModule(Boom.class); + registerModule(CaveMapper.class); + registerModule(InstaBow.class); + registerModule(ChunkCrash.class); + registerModule(OffhandCrash.class); + registerModule(OOBCrash.class); + registerModule(Phase.class); + registerModule(VanillaSpoof.class); + registerModule(XRAY.class); + registerModule(Decimator.class); + registerModule(ClickGUI.class); + registerModule(TpRange.class); + registerModule(AnyPlacer.class); + registerModule(FireballDeflector.class); + registerModule(ShulkerDeflector.class); + registerModule(CarpetBomb.class); + registerModule(AutoTrap.class); + registerModule(AutoTNT.class); + registerModule(FakeHacker.class); + registerModule(NoFall.class); + registerModule(ESP.class); + registerModule(Tracers.class); + registerModule(Hyperspeed.class); + registerModule(AntiAnvil.class); + registerModule(Swing.class); + registerModule(AimAssist.class); + registerModule(Criticals.class); + registerModule(Killaura.class); + registerModule(Velocity.class); + registerModule(AntiAntiXray.class); + registerModule(PingSpoof.class); + registerModule(AutoAttack.class); + registerModule(MouseEars.class); + registerModule(Spinner.class); + registerModule(AllowFormatCodes.class); + registerModule(InfChatLength.class); + registerModule(NoTitles.class); + registerModule(PortalGUI.class); + registerModule(Timer.class); + registerModule(XCarry.class); + registerModule(AirJump.class); + registerModule(AutoElytra.class); + registerModule(Blink.class); + registerModule(Boost.class); + registerModule(EdgeJump.class); + registerModule(EdgeSneak.class); + registerModule(EntityFly.class); + registerModule(IgnoreWorldBorder.class); + registerModule(InventoryWalk.class); + registerModule(Jesus.class); + registerModule(LongJump.class); + registerModule(MoonGravity.class); + registerModule(NoJumpCool.class); + registerModule(NoLevitation.class); + registerModule(NoPush.class); + registerModule(Step.class); + registerModule(Freecam.class); + registerModule(FreeLook.class); + registerModule(ItemByteSize.class); + registerModule(Zoom.class); + registerModule(AutoTool.class); + registerModule(BlockTagViewer.class); + registerModule(Annihilator.class); + registerModule(FastUse.class); + registerModule(Flattener.class); + registerModule(GodBridge.class); + registerModule(InstantBreak.class); + registerModule(MassUse.class); + registerModule(NoBreakDelay.class); + registerModule(SurvivalNuker.class); + registerModule(Nuker.class); + registerModule(Scaffold.class); + registerModule(Test.class); + registerModule(BlocksMCFlight.class); + registerModule(NameTags.class); + registerModule(Trail.class); + registerModule(AdBlock.class); + registerModule(AutoLavacast.class); + registerModule(Backtrack.class); + registerModule(TabGui.class); + registerModule(Theme.class); + registerModule(AntiCrash.class); + registerModule(ClientSettings.class); + registerModule(NoLiquidFog.class); + registerModule(Spotlight.class); + registerModule(ShowTntPrime.class); + registerModule(ToolsScreen.class); + registerModule(BookInflaterCrash.class); + registerModule(BlockHighlighting.class); + registerModule(AutoIgnite.class); + registerModule(DiscordRPC.class); + registerModule(AirPlace.class); + registerModule(AdSpammer.class); + registerModule(AnimationCrash.class); + registerModule(AutoFireball.class); + registerModule(AutoFish.class); + registerModule(AutoRun.class); + registerModule(LecternCrash.class); + registerModule(MinehutCrash.class); + registerModule(ArmorStandCrash.class); + registerModule(LoominaCrash.class); + registerModule(Reach.class); + registerModule(Fling.class); + registerModule(AutoSign.class); + registerModule(SuperCrossbow.class); + registerModule(ReverseKnockback.class); + registerModule(Speed.class); + registerModule(BoatFling.class); + registerModule(FilterBypass.class); + registerModule(InteractCrash.class); + registerModule(FlightCrash.class); + registerModule(ClickTP.class); + registerModule(ChestHighlighter.class); + registerModule(DauntedAutoClaim.class); + registerModule(MoreChatHistory.class); rebuildSharedModuleList(); } @@ -330,13 +343,21 @@ public class ModuleRegistry { if (!initialized.get()) { init(); } + awaitLockOpen(); return sharedModuleList; } private static void awaitLockOpen() { - while (reloadInProgress.get()) { - Thread.onSpinWait(); + if (reloadInProgress.get()) { + ShadowMain.log(Level.INFO, "Locking for some time for reload to complete"); + long lockStart = System.currentTimeMillis(); + long lockStartns = System.nanoTime(); + while (reloadInProgress.get()) { + Thread.onSpinWait(); + } + ShadowMain.log(Level.INFO, "Lock opened within "+(System.currentTimeMillis()-lockStart)+" ms ("+(System.nanoTime()-lockStartns)+" ns)"); } + } @SuppressWarnings("unchecked") diff --git a/src/main/java/net/shadow/client/feature/module/impl/combat/Fling.java b/src/main/java/net/shadow/client/feature/module/impl/combat/Fling.java index c19db77..2ce6205 100644 --- a/src/main/java/net/shadow/client/feature/module/impl/combat/Fling.java +++ b/src/main/java/net/shadow/client/feature/module/impl/combat/Fling.java @@ -15,7 +15,6 @@ import net.shadow.client.feature.module.Module; import net.shadow.client.feature.module.ModuleType; import net.shadow.client.helper.event.EventListener; import net.shadow.client.helper.event.EventType; -import net.shadow.client.helper.event.Events; import net.shadow.client.helper.event.events.PacketEvent; import net.shadow.client.helper.util.Utils; @@ -29,7 +28,7 @@ public class Fling extends Module { public Fling() { super("Fling", "Fling players in the air", ModuleType.COMBAT); - Events.registerEventHandlerClass(this); +// Events.registerEventHandlerClass(this); } @Override diff --git a/src/main/java/net/shadow/client/feature/module/impl/combat/ReverseKnockback.java b/src/main/java/net/shadow/client/feature/module/impl/combat/ReverseKnockback.java index 119b149..7edc42a 100644 --- a/src/main/java/net/shadow/client/feature/module/impl/combat/ReverseKnockback.java +++ b/src/main/java/net/shadow/client/feature/module/impl/combat/ReverseKnockback.java @@ -13,7 +13,6 @@ import net.shadow.client.feature.module.Module; import net.shadow.client.feature.module.ModuleType; import net.shadow.client.helper.event.EventListener; import net.shadow.client.helper.event.EventType; -import net.shadow.client.helper.event.Events; import net.shadow.client.helper.event.events.PacketEvent; import java.util.ArrayList; @@ -25,7 +24,7 @@ public class ReverseKnockback extends Module { public ReverseKnockback() { super("ReverseKnockback", "Reverse the knockback you deal", ModuleType.MISC); - Events.registerEventHandlerClass(this); +// Events.registerEventHandlerClass(this); } @Override diff --git a/src/main/java/net/shadow/client/feature/module/impl/crash/FlightCrash.java b/src/main/java/net/shadow/client/feature/module/impl/crash/FlightCrash.java index 5b6e0d2..478f55c 100644 --- a/src/main/java/net/shadow/client/feature/module/impl/crash/FlightCrash.java +++ b/src/main/java/net/shadow/client/feature/module/impl/crash/FlightCrash.java @@ -14,7 +14,6 @@ import net.shadow.client.feature.module.Module; import net.shadow.client.feature.module.ModuleType; import net.shadow.client.helper.event.EventListener; import net.shadow.client.helper.event.EventType; -import net.shadow.client.helper.event.Events; import net.shadow.client.helper.event.events.PacketEvent; import net.shadow.client.helper.util.Utils; @@ -29,7 +28,7 @@ public class FlightCrash extends Module { public FlightCrash() { super("FlightCrash", "Generates a ton of chunks", ModuleType.CRASH); - Events.registerEventHandlerClass(this); +// Events.registerEventHandlerClass(this); } @Override diff --git a/src/main/java/net/shadow/client/feature/module/impl/crash/InteractCrash.java b/src/main/java/net/shadow/client/feature/module/impl/crash/InteractCrash.java index 613716c..003e0fd 100644 --- a/src/main/java/net/shadow/client/feature/module/impl/crash/InteractCrash.java +++ b/src/main/java/net/shadow/client/feature/module/impl/crash/InteractCrash.java @@ -19,7 +19,6 @@ import net.shadow.client.feature.module.Module; import net.shadow.client.feature.module.ModuleType; import net.shadow.client.helper.event.EventListener; import net.shadow.client.helper.event.EventType; -import net.shadow.client.helper.event.Events; import net.shadow.client.helper.event.events.PacketEvent; public class InteractCrash extends Module { @@ -29,7 +28,7 @@ public class InteractCrash extends Module { public InteractCrash() { super("InteractCrash", "Crash using interaction packets", ModuleType.CRASH); - Events.registerEventHandlerClass(this); +// Events.registerEventHandlerClass(this); } @Override diff --git a/src/main/java/net/shadow/client/feature/module/impl/exploit/FilterBypass.java b/src/main/java/net/shadow/client/feature/module/impl/exploit/FilterBypass.java index 6bff1d9..a8b8866 100644 --- a/src/main/java/net/shadow/client/feature/module/impl/exploit/FilterBypass.java +++ b/src/main/java/net/shadow/client/feature/module/impl/exploit/FilterBypass.java @@ -10,7 +10,6 @@ import net.shadow.client.feature.module.Module; import net.shadow.client.feature.module.ModuleType; import net.shadow.client.helper.event.EventListener; import net.shadow.client.helper.event.EventType; -import net.shadow.client.helper.event.Events; import net.shadow.client.helper.event.events.PacketEvent; public class FilterBypass extends Module { @@ -19,7 +18,7 @@ public class FilterBypass extends Module { public FilterBypass() { super("FilterBypass", "Bypass chat filters", ModuleType.EXPLOIT); - Events.registerEventHandlerClass(this); +// Events.registerEventHandlerClass(this); } @Override @@ -40,9 +39,9 @@ public class FilterBypass extends Module { return null; } - @EventListener(type = EventType.PACKET_RECEIVE) - void onRecievePacket(PacketEvent event) { - if (!this.isEnabled()) return; + @EventListener(type = EventType.PACKET_SEND) + void onSendPacket(PacketEvent event) { +// if (!this.isEnabled()) return; if (!blockPackets) return; if (event.getPacket() instanceof ChatMessageC2SPacket packet) { event.setCancelled(true); @@ -51,7 +50,6 @@ public class FilterBypass extends Module { return; } StringBuilder rvmsg = new StringBuilder(message).reverse(); - String msgout = rvmsg.toString(); String msgformatted = "\u202E " + rvmsg; blockPackets = false; client.player.networkHandler.sendPacket(new ChatMessageC2SPacket(msgformatted)); diff --git a/src/main/java/net/shadow/client/feature/module/impl/misc/Test.java b/src/main/java/net/shadow/client/feature/module/impl/misc/Test.java index c37166a..6be1dd4 100644 --- a/src/main/java/net/shadow/client/feature/module/impl/misc/Test.java +++ b/src/main/java/net/shadow/client/feature/module/impl/misc/Test.java @@ -13,7 +13,6 @@ import net.shadow.client.feature.module.Module; import net.shadow.client.feature.module.ModuleType; import net.shadow.client.helper.event.EventListener; import net.shadow.client.helper.event.EventType; -import net.shadow.client.helper.event.Events; import net.shadow.client.helper.event.events.BlockRenderingEvent; import net.shadow.client.helper.render.Renderer; import net.shadow.client.helper.util.Utils; @@ -26,7 +25,7 @@ public class Test extends Module { public Test() { super("Test", "Testing stuff with the client, can be ignored", ModuleType.MISC); - Events.registerEventHandlerClass(this); +// Events.registerEventHandlerClass(this); } @EventListener(type = EventType.BLOCK_RENDER) diff --git a/src/main/java/net/shadow/client/feature/module/impl/movement/ClickTP.java b/src/main/java/net/shadow/client/feature/module/impl/movement/ClickTP.java index b49da2a..d244630 100644 --- a/src/main/java/net/shadow/client/feature/module/impl/movement/ClickTP.java +++ b/src/main/java/net/shadow/client/feature/module/impl/movement/ClickTP.java @@ -18,7 +18,6 @@ import net.shadow.client.feature.module.Module; import net.shadow.client.feature.module.ModuleType; import net.shadow.client.helper.event.EventListener; import net.shadow.client.helper.event.EventType; -import net.shadow.client.helper.event.Events; import net.shadow.client.helper.event.events.MouseEvent; import net.shadow.client.helper.render.Renderer; import net.shadow.client.helper.util.Utils; @@ -31,7 +30,7 @@ public class ClickTP extends Module { public ClickTP() { super("ClickTP", "Teleport somewhere you clicked to", ModuleType.MOVEMENT); - Events.registerEventHandlerClass(this); +// Events.registerEventHandlerClass(this); } private static int lengthTo(BlockPos p) { diff --git a/src/main/java/net/shadow/client/feature/module/impl/render/ChestHighlighter.java b/src/main/java/net/shadow/client/feature/module/impl/render/ChestHighlighter.java index 3235cb1..dac2b00 100644 --- a/src/main/java/net/shadow/client/feature/module/impl/render/ChestHighlighter.java +++ b/src/main/java/net/shadow/client/feature/module/impl/render/ChestHighlighter.java @@ -13,7 +13,6 @@ import net.shadow.client.feature.module.Module; import net.shadow.client.feature.module.ModuleType; import net.shadow.client.helper.event.EventListener; import net.shadow.client.helper.event.EventType; -import net.shadow.client.helper.event.Events; import net.shadow.client.helper.event.events.BlockEntityRenderEvent; import net.shadow.client.helper.render.Renderer; @@ -26,7 +25,7 @@ public class ChestHighlighter extends Module { public ChestHighlighter() { super("ChestHighlighter", "No description", ModuleType.RENDER); - Events.registerEventHandlerClass(this); +// Events.registerEventHandlerClass(this); } void addIfNotExisting(BlockPos p) { diff --git a/src/main/java/net/shadow/client/feature/module/impl/render/NameTags.java b/src/main/java/net/shadow/client/feature/module/impl/render/NameTags.java index 8da8dde..2888446 100644 --- a/src/main/java/net/shadow/client/feature/module/impl/render/NameTags.java +++ b/src/main/java/net/shadow/client/feature/module/impl/render/NameTags.java @@ -52,12 +52,6 @@ public class NameTags extends Module { } } - GameMode getGamemode(AbstractClientPlayerEntity p) { - PlayerListEntry ple = client.getNetworkHandler().getPlayerListEntry(p.getUuid()); - if (ple == null) return null; - return ple.getGameMode(); - } - void drawInternal(Vec3d screenPos, String text, AbstractClientPlayerEntity entity) { FontAdapter nameDrawer = FontRenderers.getRenderer(); FontAdapter infoDrawer = FontRenderers.getCustomSize(12); @@ -111,7 +105,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()))).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()); } diff --git a/src/main/java/net/shadow/client/helper/event/Events.java b/src/main/java/net/shadow/client/helper/event/Events.java index 91331ef..cc52db2 100644 --- a/src/main/java/net/shadow/client/helper/event/Events.java +++ b/src/main/java/net/shadow/client/helper/event/Events.java @@ -11,6 +11,7 @@ import org.apache.logging.log4j.Level; import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; @@ -21,8 +22,12 @@ public class Events { static final List entries = new CopyOnWriteArrayList<>(); public static ListenerEntry registerEventHandler(int uniqueId, EventType event, Consumer handler) { + return registerEventHandler(uniqueId, event, handler, Events.class); + } + + public static ListenerEntry registerEventHandler(int uniqueId, EventType event, Consumer handler, Class owner) { if (entries.stream().noneMatch(listenerEntry -> listenerEntry.id == uniqueId)) { - ListenerEntry le = new ListenerEntry(uniqueId, event, handler); + ListenerEntry le = new ListenerEntry(uniqueId, event, handler, owner); entries.add(le); return le; } else { @@ -38,7 +43,14 @@ public class Events { public static ListenerEntry registerEventHandler(EventType event, Consumer handler) { return registerEventHandler((int) Math.floor(Math.random() * 0xFFFFFF), event, handler); } - + public static void unregisterEventHandlerClass(Object instance) { + for (ListenerEntry entry : new ArrayList<>(entries)) { + if (entry.owner.equals(instance.getClass())) { + ShadowMain.log(Level.INFO, "Unregistering "+entry.type+":"+entry.id); + entries.remove(entry); + } + } + } public static void registerEventHandlerClass(Object instance) { for (Method declaredMethod : instance.getClass().getDeclaredMethods()) { for (Annotation declaredAnnotation : declaredMethod.getDeclaredAnnotations()) { @@ -56,11 +68,9 @@ public class Events { } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); } - }); + }, instance.getClass()); ShadowMain.log(Level.INFO, "Registered event handler " + declaredMethod + " with id " + l.id); } - - } } } @@ -76,6 +86,6 @@ public class Events { return argument.isCancelled(); } - record ListenerEntry(int id, EventType type, Consumer eventListener) { + record ListenerEntry(int id, EventType type, Consumer eventListener, Class owner) { } } diff --git a/src/main/java/net/shadow/client/mixin/GameRendererMixin.java b/src/main/java/net/shadow/client/mixin/GameRendererMixin.java index 88a51b9..f444b5c 100644 --- a/src/main/java/net/shadow/client/mixin/GameRendererMixin.java +++ b/src/main/java/net/shadow/client/mixin/GameRendererMixin.java @@ -90,7 +90,7 @@ public class GameRendererMixin { } } - @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;raycast(DFZ)Lnet/minecraft/util/hit/HitResult;"), method = "updateTargetedEntity") + @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;raycast(DFZ)Lnet/minecraft/util/hit/HitResult;"), method = "updateTargetedEntity",require = 0) HitResult replaceFreelookHitResult(Entity instance, double maxDistance, float tickDelta, boolean includeFluids) { if (ModuleRegistry.getByClass(FreeLook.class).isEnabled()) { Vec3d vec3d = instance.getCameraPosVec(tickDelta); diff --git a/src/main/resources/changelogLatest.txt b/src/main/resources/changelogLatest.txt index d57b722..f05059f 100644 --- a/src/main/resources/changelogLatest.txt +++ b/src/main/resources/changelogLatest.txt @@ -1,3 +1,2 @@ -Port all the items -Fix automated crash reports -Sus +Fixed compat issues +Fixed race condition crash on startup diff --git a/src/main/resources/version.txt b/src/main/resources/version.txt index dec2bf5..2edeafb 100644 --- a/src/main/resources/version.txt +++ b/src/main/resources/version.txt @@ -1 +1 @@ -19 \ No newline at end of file +20 \ No newline at end of file From 265efbe1ae542ba56943be95bd8c2fbe68166e7e Mon Sep 17 00:00:00 2001 From: 0x3C50 Date: Fri, 22 Apr 2022 14:21:22 +0200 Subject: [PATCH 2/2] performance --- .../shadow/client/feature/command/impl/Test.java | 2 +- .../client/feature/module/ModuleRegistry.java | 10 +++++----- .../feature/module/impl/exploit/FilterBypass.java | 4 ++-- .../net/shadow/client/helper/event/Events.java | 15 ++++++++++----- .../shadow/client/mixin/GameRendererMixin.java | 2 +- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/shadow/client/feature/command/impl/Test.java b/src/main/java/net/shadow/client/feature/command/impl/Test.java index c7c06a2..3d0d21a 100644 --- a/src/main/java/net/shadow/client/feature/command/impl/Test.java +++ b/src/main/java/net/shadow/client/feature/command/impl/Test.java @@ -24,7 +24,7 @@ public class Test extends Command { for (Module module : ModuleRegistry.getModules()) { if (module instanceof AddonModule) continue; String cname = module.getClass().getSimpleName(); - sb.append(String.format("registerModule(%s.class);",cname)).append("\n"); + sb.append(String.format("registerModule(%s.class);", cname)).append("\n"); } try { Files.writeString(new File("bruh.txt").toPath(), sb.toString(), StandardOpenOption.CREATE); diff --git a/src/main/java/net/shadow/client/feature/module/ModuleRegistry.java b/src/main/java/net/shadow/client/feature/module/ModuleRegistry.java index 3f09e55..37aab91 100644 --- a/src/main/java/net/shadow/client/feature/module/ModuleRegistry.java +++ b/src/main/java/net/shadow/client/feature/module/ModuleRegistry.java @@ -190,18 +190,18 @@ public class ModuleRegistry { Module instance = null; for (Constructor declaredConstructor : moduleClass.getDeclaredConstructors()) { if (declaredConstructor.getParameterCount() != 0) { - throw new IllegalArgumentException(moduleClass.getName()+" has invalid constructor: expected "+moduleClass.getName()+"(), got "+declaredConstructor); + throw new IllegalArgumentException(moduleClass.getName() + " has invalid constructor: expected " + moduleClass.getName() + "(), got " + declaredConstructor); } try { instance = (Module) declaredConstructor.newInstance(); } catch (Exception e) { - throw new IllegalArgumentException("Failed to make instance of "+moduleClass.getName(), e); + throw new IllegalArgumentException("Failed to make instance of " + moduleClass.getName(), e); } } if (instance == null) { - throw new IllegalArgumentException("Failed to make instance of "+moduleClass.getName()); + throw new IllegalArgumentException("Failed to make instance of " + moduleClass.getName()); } - ShadowMain.log(Level.INFO, "Initialized " + instance.getName()+" via "+moduleClass.getName()); + ShadowMain.log(Level.INFO, "Initialized " + instance.getName() + " via " + moduleClass.getName()); vanillaModules.add(instance); } @@ -355,7 +355,7 @@ public class ModuleRegistry { while (reloadInProgress.get()) { Thread.onSpinWait(); } - ShadowMain.log(Level.INFO, "Lock opened within "+(System.currentTimeMillis()-lockStart)+" ms ("+(System.nanoTime()-lockStartns)+" ns)"); + ShadowMain.log(Level.INFO, "Lock opened within " + (System.currentTimeMillis() - lockStart) + " ms (" + (System.nanoTime() - lockStartns) + " ns)"); } } diff --git a/src/main/java/net/shadow/client/feature/module/impl/exploit/FilterBypass.java b/src/main/java/net/shadow/client/feature/module/impl/exploit/FilterBypass.java index a8b8866..2f18663 100644 --- a/src/main/java/net/shadow/client/feature/module/impl/exploit/FilterBypass.java +++ b/src/main/java/net/shadow/client/feature/module/impl/exploit/FilterBypass.java @@ -44,11 +44,11 @@ public class FilterBypass extends Module { // if (!this.isEnabled()) return; if (!blockPackets) return; if (event.getPacket() instanceof ChatMessageC2SPacket packet) { - event.setCancelled(true); String message = packet.getChatMessage(); - if (message.startsWith("/") || message.startsWith(">")) { + if (message.startsWith("/")) { return; } + event.setCancelled(true); StringBuilder rvmsg = new StringBuilder(message).reverse(); String msgformatted = "\u202E " + rvmsg; blockPackets = false; diff --git a/src/main/java/net/shadow/client/helper/event/Events.java b/src/main/java/net/shadow/client/helper/event/Events.java index cc52db2..4768089 100644 --- a/src/main/java/net/shadow/client/helper/event/Events.java +++ b/src/main/java/net/shadow/client/helper/event/Events.java @@ -43,14 +43,16 @@ public class Events { public static ListenerEntry registerEventHandler(EventType event, Consumer handler) { return registerEventHandler((int) Math.floor(Math.random() * 0xFFFFFF), event, handler); } + public static void unregisterEventHandlerClass(Object instance) { for (ListenerEntry entry : new ArrayList<>(entries)) { if (entry.owner.equals(instance.getClass())) { - ShadowMain.log(Level.INFO, "Unregistering "+entry.type+":"+entry.id); + ShadowMain.log(Level.INFO, "Unregistering " + entry.type + ":" + entry.id); entries.remove(entry); } } } + public static void registerEventHandlerClass(Object instance) { for (Method declaredMethod : instance.getClass().getDeclaredMethods()) { for (Annotation declaredAnnotation : declaredMethod.getDeclaredAnnotations()) { @@ -78,10 +80,13 @@ public class Events { @SuppressWarnings({"unchecked", "rawtypes"}) public static boolean fireEvent(EventType event, Event argument) { - for (ListenerEntry entry : entries) { - if (entry.type == event) { - ((Consumer) entry.eventListener()).accept(argument); - } + List le = entries.stream().filter(listenerEntry -> listenerEntry.type == event).toList(); + if (le.size() == 0) { +// ShadowMain.log(Level.INFO, "no one cares about "+event+" so we're gonna skip it"); + return false; + } + for (ListenerEntry entry : le) { + ((Consumer) entry.eventListener()).accept(argument); } return argument.isCancelled(); } diff --git a/src/main/java/net/shadow/client/mixin/GameRendererMixin.java b/src/main/java/net/shadow/client/mixin/GameRendererMixin.java index f444b5c..350db95 100644 --- a/src/main/java/net/shadow/client/mixin/GameRendererMixin.java +++ b/src/main/java/net/shadow/client/mixin/GameRendererMixin.java @@ -90,7 +90,7 @@ public class GameRendererMixin { } } - @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;raycast(DFZ)Lnet/minecraft/util/hit/HitResult;"), method = "updateTargetedEntity",require = 0) + @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;raycast(DFZ)Lnet/minecraft/util/hit/HitResult;"), method = "updateTargetedEntity", require = 0) HitResult replaceFreelookHitResult(Entity instance, double maxDistance, float tickDelta, boolean includeFluids) { if (ModuleRegistry.getByClass(FreeLook.class).isEnabled()) { Vec3d vec3d = instance.getCameraPosVec(tickDelta);