From a4e2c33cdf83c2164adb34112a44671d8bed1c9a Mon Sep 17 00:00:00 2001 From: videogame hacker Date: Fri, 4 Feb 2022 20:05:42 +0000 Subject: [PATCH] Add Ghost, Anti-Ghost --- .../mixins/MixinClientConnection.java | 22 +++++++ .../som/hibiscus/mixins/MixinExtEntity.java | 15 +++++ .../hibiscus/api/feature/FeatureCategory.kt | 1 + .../som/hibiscus/events/NetworkEvents.kt | 2 + .../som/hibiscus/features/FeatureList.kt | 2 - .../som/hibiscus/features/FeaturesRegistry.kt | 4 ++ .../hibiscus/features/exploits/AntiGhost.kt | 33 ++++++++++ .../som/hibiscus/features/exploits/Ghost.kt | 61 +++++++++++++++++++ src/main/resources/hibiscus.mixins.json | 36 +++++------ 9 files changed, 157 insertions(+), 19 deletions(-) create mode 100644 src/main/java/codes/som/hibiscus/mixins/MixinClientConnection.java create mode 100644 src/main/java/codes/som/hibiscus/mixins/MixinExtEntity.java delete mode 100644 src/main/kotlin/codes/som/hibiscus/features/FeatureList.kt create mode 100644 src/main/kotlin/codes/som/hibiscus/features/exploits/AntiGhost.kt create mode 100644 src/main/kotlin/codes/som/hibiscus/features/exploits/Ghost.kt diff --git a/src/main/java/codes/som/hibiscus/mixins/MixinClientConnection.java b/src/main/java/codes/som/hibiscus/mixins/MixinClientConnection.java new file mode 100644 index 0000000..1c50938 --- /dev/null +++ b/src/main/java/codes/som/hibiscus/mixins/MixinClientConnection.java @@ -0,0 +1,22 @@ +package codes.som.hibiscus.mixins; + +import codes.som.hibiscus.HibiscusMod; +import codes.som.hibiscus.events.ReceivePacketEvent; +import net.minecraft.network.ClientConnection; +import net.minecraft.network.Packet; +import net.minecraft.network.listener.PacketListener; +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(ClientConnection.class) +public abstract class MixinClientConnection { + @Inject(method = "handlePacket", at = @At("HEAD"), cancellable = true) + private static void onHandlePacket(Packet packet, PacketListener listener, CallbackInfo ci) { + var event = new ReceivePacketEvent(packet); + HibiscusMod.bus().fire(event); + if (event.isCancelled()) + ci.cancel(); + } +} diff --git a/src/main/java/codes/som/hibiscus/mixins/MixinExtEntity.java b/src/main/java/codes/som/hibiscus/mixins/MixinExtEntity.java new file mode 100644 index 0000000..e52ce23 --- /dev/null +++ b/src/main/java/codes/som/hibiscus/mixins/MixinExtEntity.java @@ -0,0 +1,15 @@ +package codes.som.hibiscus.mixins; + +import net.minecraft.entity.Entity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(Entity.class) +public interface MixinExtEntity { + @Invoker("setFlag") + void callSetFlag(int flag, boolean set); + + @Accessor + void setRemovalReason(Entity.RemovalReason reason); +} diff --git a/src/main/kotlin/codes/som/hibiscus/api/feature/FeatureCategory.kt b/src/main/kotlin/codes/som/hibiscus/api/feature/FeatureCategory.kt index 74ab128..5b6e855 100644 --- a/src/main/kotlin/codes/som/hibiscus/api/feature/FeatureCategory.kt +++ b/src/main/kotlin/codes/som/hibiscus/api/feature/FeatureCategory.kt @@ -2,6 +2,7 @@ package codes.som.hibiscus.api.feature enum class FeatureCategory(val humanName: String) { COMBAT("Combat"), + EXPLOITS("Exploits"), PLAYER("Player"), MOVEMENT("Movement"), OVERLAY("Overlay"), diff --git a/src/main/kotlin/codes/som/hibiscus/events/NetworkEvents.kt b/src/main/kotlin/codes/som/hibiscus/events/NetworkEvents.kt index b547a59..4394fa7 100644 --- a/src/main/kotlin/codes/som/hibiscus/events/NetworkEvents.kt +++ b/src/main/kotlin/codes/som/hibiscus/events/NetworkEvents.kt @@ -5,6 +5,8 @@ import codes.som.hibiscus.api.event.Event import net.minecraft.network.Packet data class SendPacketEvent(var packet: Packet<*>) : Cancellable(), Event +data class ReceivePacketEvent(var packet: Packet<*>) : Cancellable(), Event + class NetworkMovingEvent( var x: Double, var y: Double, diff --git a/src/main/kotlin/codes/som/hibiscus/features/FeatureList.kt b/src/main/kotlin/codes/som/hibiscus/features/FeatureList.kt deleted file mode 100644 index 0049937..0000000 --- a/src/main/kotlin/codes/som/hibiscus/features/FeatureList.kt +++ /dev/null @@ -1,2 +0,0 @@ -package codes.som.hibiscus.features - diff --git a/src/main/kotlin/codes/som/hibiscus/features/FeaturesRegistry.kt b/src/main/kotlin/codes/som/hibiscus/features/FeaturesRegistry.kt index d1277fc..5f42b4f 100644 --- a/src/main/kotlin/codes/som/hibiscus/features/FeaturesRegistry.kt +++ b/src/main/kotlin/codes/som/hibiscus/features/FeaturesRegistry.kt @@ -2,9 +2,11 @@ package codes.som.hibiscus.features import codes.som.hibiscus.api.feature.Feature import codes.som.hibiscus.features.combat.Criticals +import codes.som.hibiscus.features.exploits.AntiGhost import codes.som.hibiscus.features.movement.Flight import codes.som.hibiscus.features.movement.Speed import codes.som.hibiscus.features.overlay.Overlay +import codes.som.hibiscus.features.exploits.Ghost import codes.som.hibiscus.features.player.NoFallDamage val ALL_FEATURES: Array<() -> Feature> = arrayOf( @@ -13,6 +15,8 @@ val ALL_FEATURES: Array<() -> Feature> = arrayOf( ::Overlay, ::Speed, ::Criticals, + ::Ghost, + ::AntiGhost, ) class FeaturesRegistry { diff --git a/src/main/kotlin/codes/som/hibiscus/features/exploits/AntiGhost.kt b/src/main/kotlin/codes/som/hibiscus/features/exploits/AntiGhost.kt new file mode 100644 index 0000000..aa91c18 --- /dev/null +++ b/src/main/kotlin/codes/som/hibiscus/features/exploits/AntiGhost.kt @@ -0,0 +1,33 @@ +package codes.som.hibiscus.features.exploits + +import codes.som.hibiscus.api.feature.Feature +import codes.som.hibiscus.api.feature.FeatureCategory +import codes.som.hibiscus.events.PlayerTickEvent +import codes.som.hibiscus.mc +import codes.som.hibiscus.mixins.MixinExtEntity +import codes.som.hibiscus.util.ext.requireExtension +import codes.som.hibiscus.world + +class AntiGhost : Feature("Anti Ghost", FeatureCategory.EXPLOITS) { + init { + on { _: PlayerTickEvent -> + + for (player in world.players) { + if (player == mc.player) + continue + + if (player.health <= 0) { + player.deathTime = -1 + + requireExtension(player) + player.setRemovalReason(null) + + player.hurtTime = Int.MAX_VALUE + + player.prevHeadYaw = player.prevYaw + player.headYaw = player.yaw + } + } + } + } +} diff --git a/src/main/kotlin/codes/som/hibiscus/features/exploits/Ghost.kt b/src/main/kotlin/codes/som/hibiscus/features/exploits/Ghost.kt new file mode 100644 index 0000000..9213c04 --- /dev/null +++ b/src/main/kotlin/codes/som/hibiscus/features/exploits/Ghost.kt @@ -0,0 +1,61 @@ +package codes.som.hibiscus.features.exploits + +import codes.som.hibiscus.api.feature.Feature +import codes.som.hibiscus.api.feature.FeatureCategory +import codes.som.hibiscus.events.PlayerTickEvent +import codes.som.hibiscus.events.ReceivePacketEvent +import codes.som.hibiscus.mc +import codes.som.hibiscus.mixins.MixinExtEntity +import codes.som.hibiscus.player +import net.minecraft.client.gui.screen.DeathScreen +import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket +import net.minecraft.network.packet.s2c.play.HealthUpdateS2CPacket +import net.minecraft.network.packet.s2c.play.PlayerRespawnS2CPacket + +class Ghost : Feature("Ghost", FeatureCategory.EXPLOITS) { + var dead = false + + init { + on { _: PlayerTickEvent -> + if (player.health <= 0) { + dead = true + player.health = Float.MIN_VALUE + } + + if (dead) { + player.hurtTime = 0 + player.knockbackVelocity = 0f + player.hungerManager.foodLevel = 20 + player.hungerManager.saturationLevel = 1000F + (player as MixinExtEntity).callSetFlag(0, false) + } + + if (mc.currentScreen is DeathScreen) { + dead = true + mc.setScreen(null) + } + } + + on { event: ReceivePacketEvent -> + val (packet) = event + + if (packet is HealthUpdateS2CPacket) { + if (packet.health <= 0) { + event.cancel() + } + } + + if (packet is GameJoinS2CPacket || packet is PlayerRespawnS2CPacket) { + dead = false + } + } + + // TODO: Render 0 health on the status bar when dead + } + + override fun createFeatureCommand() = super.createFeatureCommand().apply { + branch("respawn") { + player.requestRespawn() + } + } +} diff --git a/src/main/resources/hibiscus.mixins.json b/src/main/resources/hibiscus.mixins.json index 48f9c46..0b54c61 100644 --- a/src/main/resources/hibiscus.mixins.json +++ b/src/main/resources/hibiscus.mixins.json @@ -1,19 +1,21 @@ { - "required": true, - "package": "codes.som.hibiscus.mixins", - "compatibilityLevel": "JAVA_17", - "injectors": { - "defaultRequire": 1 - }, - "mixins": [ - "MixinClientPlayerEntity", - "MixinClientPlayNetworkHandler", - "MixinExtClientPlayerEntity", - "MixinExtPlayerInteractEntityC2SPacket", - "MixinExtPlayerMoveC2SPacket", - "MixinExtUpdatePlayerAbilitiesC2SPacket", - "MixinGameRenderer", - "MixinKeyboard", - "MixinMinecraftClient" - ] + "required": true, + "package": "codes.som.hibiscus.mixins", + "compatibilityLevel": "JAVA_17", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "MixinClientConnection", + "MixinClientPlayerEntity", + "MixinClientPlayNetworkHandler", + "MixinExtClientPlayerEntity", + "MixinExtEntity", + "MixinExtPlayerInteractEntityC2SPacket", + "MixinExtPlayerMoveC2SPacket", + "MixinExtUpdatePlayerAbilitiesC2SPacket", + "MixinGameRenderer", + "MixinKeyboard", + "MixinMinecraftClient" + ] }