From 655c37daa8f3b2bc5483b524e29555b4bd3115aa Mon Sep 17 00:00:00 2001 From: kirillsaint Date: Thu, 27 Jul 2023 14:15:21 +0600 Subject: [PATCH] Nick Hider --- .../AbstractClientPlayerAccessor.java | 12 -- .../accessors/NetworkPlayerInfoAccessor.java | 4 +- .../mixin/ducks/AbstractClientPlayerExt.java | 2 +- .../mixin/ducks/NetworkPlayerInfoExt.java | 6 + .../mixins/AbstractClientPlayerMixin.java | 8 ++ .../mixin/mixins/NetworkPlayerInfoMixin.java | 111 +++++++++++++++++- src/main/resources/mixins.SilentClient.json | 3 +- 7 files changed, 128 insertions(+), 18 deletions(-) delete mode 100644 src/main/java/net/silentclient/client/mixin/accessors/AbstractClientPlayerAccessor.java create mode 100644 src/main/java/net/silentclient/client/mixin/ducks/NetworkPlayerInfoExt.java diff --git a/src/main/java/net/silentclient/client/mixin/accessors/AbstractClientPlayerAccessor.java b/src/main/java/net/silentclient/client/mixin/accessors/AbstractClientPlayerAccessor.java deleted file mode 100644 index fed1cb9..0000000 --- a/src/main/java/net/silentclient/client/mixin/accessors/AbstractClientPlayerAccessor.java +++ /dev/null @@ -1,12 +0,0 @@ -package net.silentclient.client.mixin.accessors; - -import net.minecraft.client.entity.AbstractClientPlayer; -import net.minecraft.client.network.NetworkPlayerInfo; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(AbstractClientPlayer.class) -public interface AbstractClientPlayerAccessor { - @Accessor - NetworkPlayerInfo getPlayerInfo(); -} diff --git a/src/main/java/net/silentclient/client/mixin/accessors/NetworkPlayerInfoAccessor.java b/src/main/java/net/silentclient/client/mixin/accessors/NetworkPlayerInfoAccessor.java index 888ca85..78d9117 100644 --- a/src/main/java/net/silentclient/client/mixin/accessors/NetworkPlayerInfoAccessor.java +++ b/src/main/java/net/silentclient/client/mixin/accessors/NetworkPlayerInfoAccessor.java @@ -2,9 +2,9 @@ package net.silentclient.client.mixin.accessors; import net.minecraft.client.network.NetworkPlayerInfo; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; +import org.spongepowered.asm.mixin.gen.Invoker; @Mixin(NetworkPlayerInfo.class) public interface NetworkPlayerInfoAccessor { - @Accessor("skinType") String silent$getSkinType(); + @Invoker("loadPlayerTextures") void silent$loadPlayerTextures(); } diff --git a/src/main/java/net/silentclient/client/mixin/ducks/AbstractClientPlayerExt.java b/src/main/java/net/silentclient/client/mixin/ducks/AbstractClientPlayerExt.java index 7391d5c..591256c 100644 --- a/src/main/java/net/silentclient/client/mixin/ducks/AbstractClientPlayerExt.java +++ b/src/main/java/net/silentclient/client/mixin/ducks/AbstractClientPlayerExt.java @@ -1,6 +1,5 @@ package net.silentclient.client.mixin.ducks; -import net.minecraft.util.ResourceLocation; import net.silentclient.client.cosmetics.*; import net.silentclient.client.cosmetics.dynamiccurved.DynamicCape; import net.silentclient.client.utils.types.PlayerResponse; @@ -35,4 +34,5 @@ public interface AbstractClientPlayerExt { AnimatedResourceLocation silent$getCape(); String silent$getNameClear(); void silent$setNameClear(String a); + Object silent$getPlayerInfo(); } diff --git a/src/main/java/net/silentclient/client/mixin/ducks/NetworkPlayerInfoExt.java b/src/main/java/net/silentclient/client/mixin/ducks/NetworkPlayerInfoExt.java new file mode 100644 index 0000000..bcb1369 --- /dev/null +++ b/src/main/java/net/silentclient/client/mixin/ducks/NetworkPlayerInfoExt.java @@ -0,0 +1,6 @@ +package net.silentclient.client.mixin.ducks; + +public interface NetworkPlayerInfoExt { + String silent$getSkinType(); + Object silent$getLocationSkin(); +} diff --git a/src/main/java/net/silentclient/client/mixin/mixins/AbstractClientPlayerMixin.java b/src/main/java/net/silentclient/client/mixin/mixins/AbstractClientPlayerMixin.java index c78c4b2..5358059 100644 --- a/src/main/java/net/silentclient/client/mixin/mixins/AbstractClientPlayerMixin.java +++ b/src/main/java/net/silentclient/client/mixin/mixins/AbstractClientPlayerMixin.java @@ -3,6 +3,7 @@ package net.silentclient.client.mixin.mixins; import com.mojang.authlib.GameProfile; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; +import net.minecraft.client.network.NetworkPlayerInfo; import net.minecraft.client.renderer.texture.DynamicTexture; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StringUtils; @@ -20,6 +21,7 @@ import net.silentclient.client.utils.Players; import net.silentclient.client.utils.SCTextureManager; import net.silentclient.client.utils.types.PlayerResponse; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -30,6 +32,7 @@ import java.util.Random; @Mixin(AbstractClientPlayer.class) public abstract class AbstractClientPlayerMixin implements AbstractClientPlayerExt { + @Shadow private NetworkPlayerInfo playerInfo; @Unique private AnimatedResourceLocation silent$cape; @Unique private AnimatedResourceLocation silent$bandana; @Unique private HatData silent$hat; @@ -276,4 +279,9 @@ public abstract class AbstractClientPlayerMixin implements AbstractClientPlayerE public void silent$setPlayerIcon(StaticResourceLocation a) { this.silent$playerIcon = a; } + + @Override + public Object silent$getPlayerInfo() { + return this.playerInfo; + } } diff --git a/src/main/java/net/silentclient/client/mixin/mixins/NetworkPlayerInfoMixin.java b/src/main/java/net/silentclient/client/mixin/mixins/NetworkPlayerInfoMixin.java index 1cf6b77..835ac1c 100644 --- a/src/main/java/net/silentclient/client/mixin/mixins/NetworkPlayerInfoMixin.java +++ b/src/main/java/net/silentclient/client/mixin/mixins/NetworkPlayerInfoMixin.java @@ -1,17 +1,43 @@ package net.silentclient.client.mixin.mixins; +import com.google.common.base.Objects; +import com.mojang.authlib.GameProfile; +import net.minecraft.client.Minecraft; import net.minecraft.client.network.NetworkPlayerInfo; +import net.minecraft.client.resources.DefaultPlayerSkin; +import net.minecraft.util.ResourceLocation; +import net.silentclient.client.Client; +import net.silentclient.client.admin.AdminRender; +import net.silentclient.client.mixin.accessors.NetworkPlayerInfoAccessor; +import net.silentclient.client.mixin.ducks.AbstractClientPlayerExt; +import net.silentclient.client.mixin.ducks.NetworkPlayerInfoExt; +import net.silentclient.client.mods.player.NickHiderMod; +import net.silentclient.client.mods.render.AnimationsMod; import net.silentclient.client.utils.NetworkPlayerInfoOptimization; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +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.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(NetworkPlayerInfo.class) -public abstract class NetworkPlayerInfoMixin { - @Inject(method = "loadPlayerTextures", at = @At("HEAD")) +public abstract class NetworkPlayerInfoMixin implements NetworkPlayerInfoExt { + @Shadow public abstract GameProfile getGameProfile(); + + @Shadow @Final private GameProfile gameProfile; + + @Shadow private String skinType; + + @Shadow private ResourceLocation locationSkin; + + @Shadow protected abstract void loadPlayerTextures(); + + @Inject(method = "loadPlayerTextures", at = @At("HEAD"), cancellable = true) public void optimizationOfLoadingTexturesStart(CallbackInfo ci) { if(NetworkPlayerInfoOptimization.isLoadingSkin) { + ci.cancel(); return; } NetworkPlayerInfoOptimization.isLoadingSkin = true; @@ -28,4 +54,85 @@ public abstract class NetworkPlayerInfoMixin { NetworkPlayerInfoOptimization.isLoadingSkin = false; })).start(); } + + @Inject(method = "getLocationSkin", at = @At("HEAD"), cancellable = true) + public void customSkinLocation(CallbackInfoReturnable cir) { + if(Minecraft.getMinecraft().currentScreen instanceof AdminRender) { + cir.setReturnValue(new ResourceLocation("textures/entity/steve.png")); + cir.cancel(); + return; + } + if(Client.getInstance().getModInstances().getNickHiderMod().isEnabled() && Client.getInstance().getSettingsManager().getSettingByClass(NickHiderMod.class, "Hide Skins").getValBoolean()) { + if(Client.getInstance().getSettingsManager().getSettingByClass(NickHiderMod.class, "Use Own Skin For All").getValBoolean()) { + if(((AbstractClientPlayerExt) Minecraft.getMinecraft().thePlayer).silent$getPlayerInfo() != null) { + if (((NetworkPlayerInfoExt) ((AbstractClientPlayerExt) Minecraft.getMinecraft().thePlayer).silent$getPlayerInfo()).silent$getLocationSkin() == null) + { + ((NetworkPlayerInfoAccessor) ((AbstractClientPlayerExt) Minecraft.getMinecraft().thePlayer).silent$getPlayerInfo()).silent$loadPlayerTextures(); + } + cir.setReturnValue((ResourceLocation) Objects.firstNonNull(((NetworkPlayerInfoExt) ((AbstractClientPlayerExt) Minecraft.getMinecraft().thePlayer).silent$getPlayerInfo()).silent$getLocationSkin(), DefaultPlayerSkin.getDefaultSkin(this.gameProfile.getId()))); + cir.cancel(); + return; + } else { + cir.setReturnValue(DefaultPlayerSkin.getDefaultSkin(Minecraft.getMinecraft().thePlayer.getGameProfile().getId())); + cir.cancel(); + return; + } + } + + if(this.gameProfile.getId().equals(Minecraft.getMinecraft().thePlayer.getGameProfile().getId()) && Client.getInstance().getSettingsManager().getSettingByClass(NickHiderMod.class, "Use Real Skin For Self").getValBoolean()) { + if (this.locationSkin == null) + { + this.loadPlayerTextures(); + } + cir.setReturnValue((ResourceLocation)Objects.firstNonNull(this.locationSkin, DefaultPlayerSkin.getDefaultSkin(this.gameProfile.getId()))); + cir.cancel(); + return; + } + + cir.setReturnValue(DefaultPlayerSkin.getDefaultSkin(this.gameProfile.getId())); + cir.cancel(); + } + } + + @Inject(method = "getSkinType", at = @At("HEAD"), cancellable = true) + public void customSkinType(CallbackInfoReturnable cir) { + if(Client.getInstance().getModInstances().getModByClass(AnimationsMod.class).isEnabled() && Client.getInstance().getSettingsManager().getSettingByClass(AnimationsMod.class, "1.7 Skins").getValBoolean()) { + cir.setReturnValue("default"); + cir.cancel(); + return; + } + if(Client.getInstance().getModInstances().getNickHiderMod().isEnabled() && Client.getInstance().getSettingsManager().getSettingByClass(NickHiderMod.class, "Hide Skins").getValBoolean() && !Client.getInstance().getSettingsManager().getSettingByClass(NickHiderMod.class, "Use Real Skin For Self").getValBoolean()) { + if(Client.getInstance().getSettingsManager().getSettingByClass(NickHiderMod.class, "Use Own Skin For All").getValBoolean()) { + if(((AbstractClientPlayerExt) Minecraft.getMinecraft().thePlayer).silent$getPlayerInfo() != null) { + cir.setReturnValue(((NetworkPlayerInfoExt) ((AbstractClientPlayerExt) Minecraft.getMinecraft().thePlayer).silent$getPlayerInfo()).silent$getSkinType() == null ? DefaultPlayerSkin.getSkinType(this.gameProfile.getId()) : ((NetworkPlayerInfoExt) ((AbstractClientPlayerExt) Minecraft.getMinecraft().thePlayer).silent$getPlayerInfo()).silent$getSkinType()); + cir.cancel(); + return; + } else { + cir.setReturnValue(DefaultPlayerSkin.getSkinType(Minecraft.getMinecraft().thePlayer.getGameProfile().getId())); + cir.cancel(); + return; + } + } + + if(this.gameProfile.getId().equals(Minecraft.getMinecraft().thePlayer.getGameProfile().getId()) && Client.getInstance().getSettingsManager().getSettingByClass(NickHiderMod.class, "Use Real Skin For Self").getValBoolean()) { + cir.setReturnValue(this.skinType == null ? DefaultPlayerSkin.getSkinType(this.gameProfile.getId()) : this.skinType); + cir.cancel(); + return; + } + + cir.setReturnValue(DefaultPlayerSkin.getSkinType(this.gameProfile.getId())); + cir.cancel(); + return; + } + } + + @Override + public String silent$getSkinType() { + return skinType; + } + + @Override + public Object silent$getLocationSkin() { + return locationSkin; + } } diff --git a/src/main/resources/mixins.SilentClient.json b/src/main/resources/mixins.SilentClient.json index 4e3cdfd..a230184 100644 --- a/src/main/resources/mixins.SilentClient.json +++ b/src/main/resources/mixins.SilentClient.json @@ -113,6 +113,7 @@ "mixins.GuiDisconnectedMixin", "accessors.optifine.CustomColorsAccessor", "accessors.optifine.ConfigAccessor", - "mixins.NetworkPlayerInfoMixin" + "mixins.NetworkPlayerInfoMixin", + "accessors.NetworkPlayerInfoAccessor" ] } \ No newline at end of file