Add Ghost, Anti-Ghost

main
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) { enum class FeatureCategory(val humanName: String) {
COMBAT("Combat"), COMBAT("Combat"),
EXPLOITS("Exploits"),
PLAYER("Player"), PLAYER("Player"),
MOVEMENT("Movement"), MOVEMENT("Movement"),
OVERLAY("Overlay"), OVERLAY("Overlay"),

View File

@ -5,6 +5,8 @@ import codes.som.hibiscus.api.event.Event
import net.minecraft.network.Packet import net.minecraft.network.Packet
data class SendPacketEvent(var packet: Packet<*>) : Cancellable(), Event data class SendPacketEvent(var packet: Packet<*>) : Cancellable(), Event
data class ReceivePacketEvent(var packet: Packet<*>) : Cancellable(), Event
class NetworkMovingEvent( class NetworkMovingEvent(
var x: Double, var x: Double,
var y: 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.api.feature.Feature
import codes.som.hibiscus.features.combat.Criticals 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.Flight
import codes.som.hibiscus.features.movement.Speed import codes.som.hibiscus.features.movement.Speed
import codes.som.hibiscus.features.overlay.Overlay import codes.som.hibiscus.features.overlay.Overlay
import codes.som.hibiscus.features.exploits.Ghost
import codes.som.hibiscus.features.player.NoFallDamage import codes.som.hibiscus.features.player.NoFallDamage
val ALL_FEATURES: Array<() -> Feature> = arrayOf( val ALL_FEATURES: Array<() -> Feature> = arrayOf(
@ -13,6 +15,8 @@ val ALL_FEATURES: Array<() -> Feature> = arrayOf(
::Overlay, ::Overlay,
::Speed, ::Speed,
::Criticals, ::Criticals,
::Ghost,
::AntiGhost,
) )
class FeaturesRegistry { 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, "required": true,
"package": "codes.som.hibiscus.mixins", "package": "codes.som.hibiscus.mixins",
"compatibilityLevel": "JAVA_17", "compatibilityLevel": "JAVA_17",
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1
}, },
"mixins": [ "mixins": [
"MixinClientPlayerEntity", "MixinClientConnection",
"MixinClientPlayNetworkHandler", "MixinClientPlayerEntity",
"MixinExtClientPlayerEntity", "MixinClientPlayNetworkHandler",
"MixinExtPlayerInteractEntityC2SPacket", "MixinExtClientPlayerEntity",
"MixinExtPlayerMoveC2SPacket", "MixinExtEntity",
"MixinExtUpdatePlayerAbilitiesC2SPacket", "MixinExtPlayerInteractEntityC2SPacket",
"MixinGameRenderer", "MixinExtPlayerMoveC2SPacket",
"MixinKeyboard", "MixinExtUpdatePlayerAbilitiesC2SPacket",
"MixinMinecraftClient" "MixinGameRenderer",
] "MixinKeyboard",
"MixinMinecraftClient"
]
} }