diff --git a/src/main/java/net/aspw/client/Launch.kt b/src/main/java/net/aspw/client/Launch.kt index 43079d6f..857d8f1d 100644 --- a/src/main/java/net/aspw/client/Launch.kt +++ b/src/main/java/net/aspw/client/Launch.kt @@ -24,7 +24,7 @@ object Launch { // Client information const val CLIENT_BEST = "NightX" const val CLIENT_FOLDER = "NightX-Client" - const val CLIENT_VERSION = "B114" + const val CLIENT_VERSION = "B115" const val CLIENT_CHAT = "§c[$CLIENT_BEST] §r" var isStarting = false diff --git a/src/main/java/net/aspw/client/injection/forge/mixins/network/MixinNetHandlerPlayClient.java b/src/main/java/net/aspw/client/injection/forge/mixins/network/MixinNetHandlerPlayClient.java index a45e8f8f..93d97e44 100644 --- a/src/main/java/net/aspw/client/injection/forge/mixins/network/MixinNetHandlerPlayClient.java +++ b/src/main/java/net/aspw/client/injection/forge/mixins/network/MixinNetHandlerPlayClient.java @@ -1,25 +1,53 @@ package net.aspw.client.injection.forge.mixins.network; +import io.netty.buffer.Unpooled; import net.aspw.client.Launch; +import net.aspw.client.event.EntityMovementEvent; import net.aspw.client.event.TeleportEvent; +import net.aspw.client.utils.MinecraftInstance; +import net.minecraft.client.ClientBrandRetriever; import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityOtherPlayerMP; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.gui.GuiDownloadTerrain; +import net.minecraft.client.multiplayer.PlayerControllerMP; +import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.network.NetHandlerPlayClient; +import net.minecraft.client.network.NetworkPlayerInfo; +import net.minecraft.entity.DataWatcher; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.network.NetworkManager; +import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketThreadUtil; import net.minecraft.network.play.INetHandlerPlayClient; import net.minecraft.network.play.client.C03PacketPlayer; -import net.minecraft.network.play.server.S08PacketPlayerPosLook; +import net.minecraft.network.play.client.C17PacketCustomPayload; +import net.minecraft.network.play.server.*; +import net.minecraft.util.IChatComponent; +import net.minecraft.world.WorldSettings; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.Slice; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import java.util.List; +import java.util.UUID; @Mixin(NetHandlerPlayClient.class) public abstract class MixinNetHandlerPlayClient implements INetHandlerPlayClient { + @Shadow + public int currentServerMaxPlayers; @Shadow public boolean doneLoadingTerrain; @Shadow @@ -27,9 +55,148 @@ public abstract class MixinNetHandlerPlayClient implements INetHandlerPlayClient private NetworkManager netManager; @Shadow private Minecraft gameController; + @Shadow + private WorldClient clientWorldController; + + @Shadow + public abstract NetworkPlayerInfo getPlayerInfo(UUID p_175102_1_); + + @Inject(method = "handleSpawnPlayer", at = @At("HEAD"), cancellable = true) + private void handleSpawnPlayer(S0CPacketSpawnPlayer packetIn, CallbackInfo callbackInfo) { + try { + PacketThreadUtil.checkThreadAndEnqueue(packetIn, (NetHandlerPlayClient) (Object) this, gameController); + double d0 = (double) packetIn.getX() / 32.0D; + double d1 = (double) packetIn.getY() / 32.0D; + double d2 = (double) packetIn.getZ() / 32.0D; + float f = (float) (packetIn.getYaw() * 360) / 256.0F; + float f1 = (float) (packetIn.getPitch() * 360) / 256.0F; + EntityOtherPlayerMP entityotherplayermp = new EntityOtherPlayerMP(gameController.theWorld, getPlayerInfo(packetIn.getPlayer()).getGameProfile()); + entityotherplayermp.prevPosX = entityotherplayermp.lastTickPosX = entityotherplayermp.serverPosX = packetIn.getX(); + entityotherplayermp.prevPosY = entityotherplayermp.lastTickPosY = entityotherplayermp.serverPosY = packetIn.getY(); + entityotherplayermp.prevPosZ = entityotherplayermp.lastTickPosZ = entityotherplayermp.serverPosZ = packetIn.getZ(); + int i = packetIn.getCurrentItemID(); + + if (i == 0) { + entityotherplayermp.inventory.mainInventory[entityotherplayermp.inventory.currentItem] = null; + } else { + entityotherplayermp.inventory.mainInventory[entityotherplayermp.inventory.currentItem] = new ItemStack(Item.getItemById(i), 1, 0); + } + + entityotherplayermp.setPositionAndRotation(d0, d1, d2, f, f1); + clientWorldController.addEntityToWorld(packetIn.getEntityID(), entityotherplayermp); + List list = packetIn.func_148944_c(); + + if (list != null) { + entityotherplayermp.getDataWatcher().updateWatchedObjectsFromList(list); + } + } catch (Exception ignored) { + } + callbackInfo.cancel(); + } + + @Inject(method = "handleJoinGame", at = @At("HEAD"), cancellable = true) + private void handleJoinGameWithAntiForge(S01PacketJoinGame packetIn, final CallbackInfo callbackInfo) { + if (MinecraftInstance.mc.isIntegratedServerRunning()) + return; + + PacketThreadUtil.checkThreadAndEnqueue(packetIn, (NetHandlerPlayClient) (Object) this, gameController); + this.gameController.playerController = new PlayerControllerMP(gameController, (NetHandlerPlayClient) (Object) this); + this.clientWorldController = new WorldClient((NetHandlerPlayClient) (Object) this, new WorldSettings(0L, packetIn.getGameType(), false, packetIn.isHardcoreMode(), packetIn.getWorldType()), packetIn.getDimension(), packetIn.getDifficulty(), this.gameController.mcProfiler); + this.gameController.gameSettings.difficulty = packetIn.getDifficulty(); + this.gameController.loadWorld(this.clientWorldController); + this.gameController.thePlayer.dimension = packetIn.getDimension(); + this.gameController.displayGuiScreen(new GuiDownloadTerrain((NetHandlerPlayClient) (Object) this)); + this.gameController.thePlayer.setEntityId(packetIn.getEntityId()); + this.currentServerMaxPlayers = packetIn.getMaxPlayers(); + this.gameController.thePlayer.setReducedDebug(packetIn.isReducedDebugInfo()); + this.gameController.playerController.setGameType(packetIn.getGameType()); + this.gameController.gameSettings.sendSettingsToServer(); + this.netManager.sendPacket(new C17PacketCustomPayload("MC|Brand", (new PacketBuffer(Unpooled.buffer())).writeString(ClientBrandRetriever.getClientModName()))); + callbackInfo.cancel(); + } + + @Inject(method = "handleEntityMovement", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/Entity;onGround:Z")) + private void handleEntityMovementEvent(S14PacketEntity packetIn, final CallbackInfo callbackInfo) { + final Entity entity = packetIn.getEntity(this.clientWorldController); + + if (entity != null) + Launch.eventManager.callEvent(new EntityMovementEvent(entity)); + } + + @Redirect( + method = "handleUpdateSign", + slice = @Slice(from = @At(value = "CONSTANT", args = "stringValue=Unable to locate sign at ", ordinal = 0)), + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/EntityPlayerSP;addChatMessage(Lnet/minecraft/util/IChatComponent;)V", ordinal = 0) + ) + private void removeDebugMessage(EntityPlayerSP instance, IChatComponent component) { + } + + @Inject(method = {"handleAnimation"}, at = {@At(value = "INVOKE", target = "Lnet/minecraft/network/PacketThreadUtil;checkThreadAndEnqueue(Lnet/minecraft/network/Packet;Lnet/minecraft/network/INetHandler;Lnet/minecraft/util/IThreadListener;)V", shift = At.Shift.AFTER)}, cancellable = true) + private void handleAnimation(S0BPacketAnimation s0BPacketAnimation, CallbackInfo callbackInfo) { + this.cancelIfNull(this.clientWorldController, callbackInfo); + } + + @Inject(method = {"handleEntityTeleport"}, at = {@At(value = "INVOKE", target = "Lnet/minecraft/network/PacketThreadUtil;checkThreadAndEnqueue(Lnet/minecraft/network/Packet;Lnet/minecraft/network/INetHandler;Lnet/minecraft/util/IThreadListener;)V", shift = At.Shift.AFTER)}, cancellable = true) + private void handleEntityTeleport(S18PacketEntityTeleport s18PacketEntityTeleport, CallbackInfo callbackInfo) { + this.cancelIfNull(this.clientWorldController, callbackInfo); + } - @Inject(method = "handlePlayerPosLook", at = @At("HEAD"), cancellable = true) - private void handlePlayerPosLook(S08PacketPlayerPosLook packetIn, final CallbackInfo ci) { + @Inject(method = {"handleEntityMovement"}, at = {@At(value = "INVOKE", target = "Lnet/minecraft/network/PacketThreadUtil;checkThreadAndEnqueue(Lnet/minecraft/network/Packet;Lnet/minecraft/network/INetHandler;Lnet/minecraft/util/IThreadListener;)V", shift = At.Shift.AFTER)}, cancellable = true) + private void handleEntityMovement(S14PacketEntity s14PacketEntity, CallbackInfo callbackInfo) { + this.cancelIfNull(this.clientWorldController, callbackInfo); + } + + @Inject(method = {"handleEntityHeadLook"}, at = {@At(value = "INVOKE", target = "Lnet/minecraft/network/PacketThreadUtil;checkThreadAndEnqueue(Lnet/minecraft/network/Packet;Lnet/minecraft/network/INetHandler;Lnet/minecraft/util/IThreadListener;)V", shift = At.Shift.AFTER)}, cancellable = true) + private void handleEntityHeadLook(S19PacketEntityHeadLook s19PacketEntityHeadLook, CallbackInfo callbackInfo) { + this.cancelIfNull(this.clientWorldController, callbackInfo); + } + + @Inject(method = {"handleEntityProperties"}, at = {@At(value = "INVOKE", target = "Lnet/minecraft/network/PacketThreadUtil;checkThreadAndEnqueue(Lnet/minecraft/network/Packet;Lnet/minecraft/network/INetHandler;Lnet/minecraft/util/IThreadListener;)V", shift = At.Shift.AFTER)}, cancellable = true) + private void handleEntityProperties(S20PacketEntityProperties s20PacketEntityProperties, CallbackInfo callbackInfo) { + this.cancelIfNull(this.clientWorldController, callbackInfo); + } + + @Inject(method = {"handleEntityMetadata"}, at = {@At(value = "INVOKE", target = "Lnet/minecraft/network/PacketThreadUtil;checkThreadAndEnqueue(Lnet/minecraft/network/Packet;Lnet/minecraft/network/INetHandler;Lnet/minecraft/util/IThreadListener;)V", shift = At.Shift.AFTER)}, cancellable = true) + private void handleEntityMetadata(S1CPacketEntityMetadata s1CPacketEntityMetadata, CallbackInfo callbackInfo) { + this.cancelIfNull(this.clientWorldController, callbackInfo); + } + + @Inject(method = {"handleEntityEquipment"}, at = {@At(value = "INVOKE", target = "Lnet/minecraft/network/PacketThreadUtil;checkThreadAndEnqueue(Lnet/minecraft/network/Packet;Lnet/minecraft/network/INetHandler;Lnet/minecraft/util/IThreadListener;)V", shift = At.Shift.AFTER)}, cancellable = true) + private void handleEntityEquipment(S04PacketEntityEquipment s04PacketEntityEquipment, CallbackInfo callbackInfo) { + this.cancelIfNull(this.clientWorldController, callbackInfo); + } + + @Inject(method = {"handleDestroyEntities"}, at = {@At(value = "INVOKE", target = "Lnet/minecraft/network/PacketThreadUtil;checkThreadAndEnqueue(Lnet/minecraft/network/Packet;Lnet/minecraft/network/INetHandler;Lnet/minecraft/util/IThreadListener;)V", shift = At.Shift.AFTER)}, cancellable = true) + private void handleDestroyEntities(S13PacketDestroyEntities s13PacketDestroyEntities, CallbackInfo callbackInfo) { + this.cancelIfNull(this.clientWorldController, callbackInfo); + } + + @Inject(method = {"handleScoreboardObjective"}, at = {@At(value = "INVOKE", target = "Lnet/minecraft/network/PacketThreadUtil;checkThreadAndEnqueue(Lnet/minecraft/network/Packet;Lnet/minecraft/network/INetHandler;Lnet/minecraft/util/IThreadListener;)V", shift = At.Shift.AFTER)}, cancellable = true) + private void handleScoreboardObjective(S3BPacketScoreboardObjective s3BPacketScoreboardObjective, CallbackInfo callbackInfo) { + this.cancelIfNull(this.clientWorldController, callbackInfo); + } + + @Inject(method = {"handleConfirmTransaction"}, at = {@At(value = "INVOKE", target = "Lnet/minecraft/network/play/server/S32PacketConfirmTransaction;getWindowId()I", ordinal = 0)}, cancellable = true, locals = LocalCapture.CAPTURE_FAILEXCEPTION) + private void handleConfirmTransaction(S32PacketConfirmTransaction s32PacketConfirmTransaction, CallbackInfo callbackInfo, Container container, EntityPlayer entityPlayer) { + this.cancelIfNull(entityPlayer, callbackInfo); + } + + @Inject(method = {"handleSoundEffect"}, at = {@At(value = "INVOKE", target = "Lnet/minecraft/network/PacketThreadUtil;checkThreadAndEnqueue(Lnet/minecraft/network/Packet;Lnet/minecraft/network/INetHandler;Lnet/minecraft/util/IThreadListener;)V")}, cancellable = true) + private void handleSoundEffect(S29PacketSoundEffect s29PacketSoundEffect, CallbackInfo callbackInfo) { + this.cancelIfNull(this.gameController.theWorld, callbackInfo); + } + + @Inject(method = {"handleTimeUpdate"}, at = {@At(value = "INVOKE", target = "Lnet/minecraft/network/PacketThreadUtil;checkThreadAndEnqueue(Lnet/minecraft/network/Packet;Lnet/minecraft/network/INetHandler;Lnet/minecraft/util/IThreadListener;)V")}, cancellable = true) + private void handleTimeUpdate(S03PacketTimeUpdate s03PacketTimeUpdate, CallbackInfo callbackInfo) { + this.cancelIfNull(this.gameController.theWorld, callbackInfo); + } + + /** + * @author As_pw + * @reason Teleport Event + */ + @Overwrite + public void handlePlayerPosLook(S08PacketPlayerPosLook packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController); final EntityPlayer entityplayer = this.gameController.thePlayer; double d0 = packetIn.getX(); @@ -41,8 +208,9 @@ private void handlePlayerPosLook(S08PacketPlayerPosLook packetIn, final Callback TeleportEvent event = new TeleportEvent(new C03PacketPlayer.C06PacketPlayerPosLook(entityplayer.posX, entityplayer.posY, entityplayer.posZ, entityplayer.rotationYaw, entityplayer.rotationPitch, false), d0, d1, d2, f, f1); Launch.eventManager.callEvent(event); - if (event.isCancelled()) + if (event.isCancelled()) { return; + } d0 = event.getPosX(); d1 = event.getPosY(); @@ -93,7 +261,11 @@ private void handlePlayerPosLook(S08PacketPlayerPosLook packetIn, final Callback this.doneLoadingTerrain = true; this.gameController.displayGuiScreen(null); } + } - ci.cancel(); + private void cancelIfNull(T t, CallbackInfo callbackInfo) { + if (t == null) { + callbackInfo.cancel(); + } } } \ No newline at end of file