Add Ghost, Anti-Ghost

This commit is contained in:
Charlotte Som 2022-02-04 20:05:42 +00:00
parent e6ae1efcbc
commit a4e2c33cdf
9 changed files with 157 additions and 19 deletions

View file

@ -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 <T extends PacketListener> void onHandlePacket(Packet<T> packet, PacketListener listener, CallbackInfo ci) {
var event = new ReceivePacketEvent(packet);
HibiscusMod.bus().fire(event);
if (event.isCancelled())
ci.cancel();
}
}

View file

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

View file

@ -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"),

View file

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

View file

@ -1,2 +0,0 @@
package codes.som.hibiscus.features

View file

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

View file

@ -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<MixinExtEntity>(player)
player.setRemovalReason(null)
player.hurtTime = Int.MAX_VALUE
player.prevHeadYaw = player.prevYaw
player.headYaw = player.yaw
}
}
}
}
}

View file

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

View file

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