mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-22 02:42:15 +00:00
No longer remove any elements in SkinManager. (#151)
This commit is contained in:
1 parent
fb50a3db6d
commit
8befcb32d8
3 files changed
+180
-127
No files matched your search
@@ -2,9 +2,12 @@ package customskinloader.forge.transformer;
|
||||
|
||||
import customskinloader.forge.TransformerManager;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.FieldInsnNode;
|
||||
import org.objectweb.asm.tree.FieldNode;
|
||||
import org.objectweb.asm.tree.FrameNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.InsnNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
@@ -12,90 +15,98 @@ import org.objectweb.asm.tree.TypeInsnNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
|
||||
public class SkinManagerTransformer {
|
||||
@TransformerManager.TransformTarget(className="net.minecraft.client.resources.SkinManager",
|
||||
methodNameSrg="<init>",
|
||||
desc="(Lnet/minecraft/client/renderer/texture/TextureManager;Ljava/io/File;Lcom/mojang/authlib/minecraft/MinecraftSessionService;)V")
|
||||
public static class InitTransformer implements TransformerManager.IMethodTransformer{
|
||||
@TransformerManager.TransformTarget(
|
||||
className = "net.minecraft.client.resources.SkinManager",
|
||||
methodNameSrg = "<init>",
|
||||
desc = "(Lnet/minecraft/client/renderer/texture/TextureManager;Ljava/io/File;Lcom/mojang/authlib/minecraft/MinecraftSessionService;)V"
|
||||
)
|
||||
public static class InitTransformer implements TransformerManager.IMethodTransformer {
|
||||
@Override
|
||||
public MethodNode transform(ClassNode cn, MethodNode mn) {
|
||||
boolean hasField = false;
|
||||
for (FieldNode fn : cn.fields) {
|
||||
if (fn.name.equals("fakeManager")) {
|
||||
hasField = true;
|
||||
break;
|
||||
cn.fields.removeIf(fn -> fn.name.equals("fakeManager") && fn.desc.equals("Lcustomskinloader/fake/FakeSkinManager;"));
|
||||
cn.fields.add(new FieldNode(Opcodes.ACC_PRIVATE, "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;", null, null));
|
||||
|
||||
for (AbstractInsnNode ain : mn.instructions.toArray()) {
|
||||
if (ain.getOpcode() == Opcodes.RETURN) {
|
||||
InsnList il = new InsnList();
|
||||
il.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||
il.add(new TypeInsnNode(Opcodes.NEW, "customskinloader/fake/FakeSkinManager"));
|
||||
il.add(new InsnNode(Opcodes.DUP));
|
||||
il.add(new VarInsnNode(Opcodes.ALOAD, 1));
|
||||
il.add(new VarInsnNode(Opcodes.ALOAD, 2));
|
||||
il.add(new VarInsnNode(Opcodes.ALOAD, 3));
|
||||
il.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "customskinloader/fake/FakeSkinManager", "<init>", "(Lnet/minecraft/client/renderer/texture/TextureManager;Ljava/io/File;Lcom/mojang/authlib/minecraft/MinecraftSessionService;)V", false));
|
||||
il.add(new FieldInsnNode(Opcodes.PUTFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||
mn.instructions.insert(il);
|
||||
}
|
||||
}
|
||||
if (!hasField) {
|
||||
cn.fields.add(new FieldNode(Opcodes.ACC_PRIVATE, "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;", null, null));
|
||||
}
|
||||
mn.instructions.clear();
|
||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,0));
|
||||
mn.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL,"java/lang/Object","<init>","()V", false));
|
||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,0));
|
||||
mn.instructions.add(new TypeInsnNode(Opcodes.NEW, "customskinloader/fake/FakeSkinManager"));
|
||||
mn.instructions.add(new InsnNode(Opcodes.DUP));
|
||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,1));
|
||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,2));
|
||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,3));
|
||||
mn.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL,"customskinloader/fake/FakeSkinManager","<init>",
|
||||
"(Lnet/minecraft/client/renderer/texture/TextureManager;Ljava/io/File;Lcom/mojang/authlib/minecraft/MinecraftSessionService;)V", false));
|
||||
mn.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||
mn.instructions.add(new InsnNode(Opcodes.RETURN));
|
||||
return mn;
|
||||
}
|
||||
}
|
||||
@TransformerManager.TransformTarget(className="net.minecraft.client.resources.SkinManager",
|
||||
methodNameSrg="func_152789_a",
|
||||
methodNames="loadSkin",
|
||||
desc="(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;)Lnet/minecraft/util/ResourceLocation;")
|
||||
public static class LoadSkinTransformer implements TransformerManager.IMethodTransformer{
|
||||
|
||||
@TransformerManager.TransformTarget(
|
||||
className = "net.minecraft.client.resources.SkinManager",
|
||||
methodNameSrg = "func_152789_a",
|
||||
methodNames = "loadSkin",
|
||||
desc = "(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;)Lnet/minecraft/util/ResourceLocation;"
|
||||
)
|
||||
public static class LoadSkinTransformer implements TransformerManager.IMethodTransformer {
|
||||
@Override
|
||||
public MethodNode transform(ClassNode cn, MethodNode mn) {
|
||||
mn.instructions.clear();
|
||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,0));
|
||||
mn.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,1));
|
||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,2));
|
||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,3));
|
||||
mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL,"customskinloader/fake/FakeSkinManager","loadSkin",
|
||||
"(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;)Lnet/minecraft/util/ResourceLocation;", false));
|
||||
mn.instructions.add(new InsnNode(Opcodes.ARETURN));
|
||||
InsnList il = new InsnList();
|
||||
il.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||
il.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||
il.add(new VarInsnNode(Opcodes.ALOAD, 1));
|
||||
il.add(new VarInsnNode(Opcodes.ALOAD, 2));
|
||||
il.add(new VarInsnNode(Opcodes.ALOAD, 3));
|
||||
il.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "customskinloader/fake/FakeSkinManager", "loadSkin", "(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;)Lnet/minecraft/util/ResourceLocation;", false));
|
||||
il.add(new InsnNode(Opcodes.ARETURN));
|
||||
il.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null));
|
||||
mn.instructions.insert(il);
|
||||
return mn;
|
||||
}
|
||||
}
|
||||
@TransformerManager.TransformTarget(className="net.minecraft.client.resources.SkinManager",
|
||||
methodNameSrg="func_152790_a",
|
||||
methodNames="loadProfileTextures",
|
||||
desc="(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;Z)V")
|
||||
public static class LoadProfileTexturesTransformer implements TransformerManager.IMethodTransformer{
|
||||
|
||||
@TransformerManager.TransformTarget(
|
||||
className = "net.minecraft.client.resources.SkinManager",
|
||||
methodNameSrg = "func_152790_a",
|
||||
methodNames = "loadProfileTextures",
|
||||
desc = "(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;Z)V"
|
||||
)
|
||||
public static class LoadProfileTexturesTransformer implements TransformerManager.IMethodTransformer {
|
||||
@Override
|
||||
public MethodNode transform(ClassNode cn, MethodNode mn) {
|
||||
mn.instructions.clear();
|
||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,0));
|
||||
mn.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,1));
|
||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,2));
|
||||
mn.instructions.add(new VarInsnNode(Opcodes.ILOAD,3));
|
||||
mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL,"customskinloader/fake/FakeSkinManager","loadProfileTextures",
|
||||
"(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;Z)V", false));
|
||||
mn.instructions.add(new InsnNode(Opcodes.RETURN));
|
||||
InsnList il = new InsnList();
|
||||
il.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||
il.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||
il.add(new VarInsnNode(Opcodes.ALOAD, 1));
|
||||
il.add(new VarInsnNode(Opcodes.ALOAD, 2));
|
||||
il.add(new VarInsnNode(Opcodes.ILOAD, 3));
|
||||
il.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "customskinloader/fake/FakeSkinManager", "loadProfileTextures", "(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;Z)V", false));
|
||||
il.add(new InsnNode(Opcodes.RETURN));
|
||||
il.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null));
|
||||
mn.instructions.insert(il);
|
||||
return mn;
|
||||
}
|
||||
}
|
||||
@TransformerManager.TransformTarget(className="net.minecraft.client.resources.SkinManager",
|
||||
methodNameSrg="func_152788_a",
|
||||
methodNames="loadSkinFromCache",
|
||||
desc="(Lcom/mojang/authlib/GameProfile;)Ljava/util/Map;")
|
||||
public static class LoadSkinFromCacheTransformer implements TransformerManager.IMethodTransformer{
|
||||
|
||||
@TransformerManager.TransformTarget(
|
||||
className = "net.minecraft.client.resources.SkinManager",
|
||||
methodNameSrg = "func_152788_a",
|
||||
methodNames = "loadSkinFromCache",
|
||||
desc = "(Lcom/mojang/authlib/GameProfile;)Ljava/util/Map;"
|
||||
)
|
||||
public static class LoadSkinFromCacheTransformer implements TransformerManager.IMethodTransformer {
|
||||
@Override
|
||||
public MethodNode transform(ClassNode cn, MethodNode mn) {
|
||||
mn.instructions.clear();
|
||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,0));
|
||||
mn.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,1));
|
||||
mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL,"customskinloader/fake/FakeSkinManager","loadSkinFromCache",
|
||||
"(Lcom/mojang/authlib/GameProfile;)Ljava/util/Map;", false));
|
||||
mn.instructions.add(new InsnNode(Opcodes.ARETURN));
|
||||
InsnList il = new InsnList();
|
||||
il.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||
il.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||
il.add(new VarInsnNode(Opcodes.ALOAD, 1));
|
||||
il.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "customskinloader/fake/FakeSkinManager", "loadSkinFromCache", "(Lcom/mojang/authlib/GameProfile;)Ljava/util/Map;", false));
|
||||
il.add(new InsnNode(Opcodes.ARETURN));
|
||||
il.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null));
|
||||
mn.instructions.insert(il);
|
||||
return mn;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
package net.minecraft.client.resources;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||
import com.mojang.authlib.minecraft.MinecraftSessionService;
|
||||
import customskinloader.fake.FakeSkinManager;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class SkinManager {
|
||||
private FakeSkinManager fakeManager;
|
||||
|
||||
public SkinManager(TextureManager textureManagerInstance, File skinCacheDirectory, MinecraftSessionService sessionService) {
|
||||
this.fakeManager = new FakeSkinManager(textureManagerInstance, skinCacheDirectory, sessionService);
|
||||
}
|
||||
|
||||
public ResourceLocation loadSkin(MinecraftProfileTexture profileTexture, MinecraftProfileTexture.Type textureType) {
|
||||
return this.loadSkin(profileTexture, textureType, null);
|
||||
}
|
||||
|
||||
public ResourceLocation loadSkin(MinecraftProfileTexture profileTexture, MinecraftProfileTexture.Type textureType, SkinManager.SkinAvailableCallback skinAvailableCallback) {
|
||||
return this.fakeManager.loadSkin(profileTexture, textureType, skinAvailableCallback);
|
||||
}
|
||||
|
||||
// For 1.14+
|
||||
public ResourceLocation func_152789_a(MinecraftProfileTexture profileTexture, MinecraftProfileTexture.Type textureType, SkinManager.ISkinAvailableCallback skinAvailableCallback) {
|
||||
return this.loadSkin(profileTexture, textureType, skinAvailableCallback);
|
||||
}
|
||||
|
||||
public void loadProfileTextures(GameProfile profile, SkinManager.SkinAvailableCallback skinAvailableCallback, boolean requireSecure) {
|
||||
this.fakeManager.loadProfileTextures(profile, skinAvailableCallback, requireSecure);
|
||||
}
|
||||
|
||||
// For 1.14+
|
||||
public void func_152790_a(GameProfile profile, SkinManager.ISkinAvailableCallback skinAvailableCallback, boolean requireSecure) {
|
||||
this.loadProfileTextures(profile, skinAvailableCallback, requireSecure);
|
||||
}
|
||||
|
||||
public Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> loadSkinFromCache(GameProfile profile) {
|
||||
return this.fakeManager.loadSkinFromCache(profile);
|
||||
}
|
||||
|
||||
public interface SkinAvailableCallback {
|
||||
default void skinAvailable(MinecraftProfileTexture.Type typeIn, ResourceLocation location, MinecraftProfileTexture profileTexture) {
|
||||
this.onSkinTextureAvailable(typeIn, location, profileTexture);
|
||||
}
|
||||
|
||||
default void onSkinTextureAvailable(MinecraftProfileTexture.Type typeIn, ResourceLocation location, MinecraftProfileTexture profileTexture) {
|
||||
this.skinAvailable(typeIn, location, profileTexture);
|
||||
}
|
||||
}
|
||||
|
||||
public interface ISkinAvailableCallback extends SkinAvailableCallback {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user