From 98681e82516bcfcde4013206d1db2c5eb7b99040 Mon Sep 17 00:00:00 2001 From: ZekerZhayard Date: Mon, 8 Feb 2021 11:37:04 +0800 Subject: [PATCH] Remove updateGameProfile transformer. (#143) * Add an option to control updateGameProfile transformer. * Remove unnecessary FrameNodes --- Common/source/customskinloader/config/Config.java | 1 + Forge/resource/transformers.js | 12 ++++++++++-- .../transformer/TileEntitySkullTransformer.java | 8 ++++++++ .../customskinloader/mixin/MixinTileEntitySkull.java | 5 ++++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Common/source/customskinloader/config/Config.java b/Common/source/customskinloader/config/Config.java index 8b291cd..1b9ed06 100644 --- a/Common/source/customskinloader/config/Config.java +++ b/Common/source/customskinloader/config/Config.java @@ -27,6 +27,7 @@ public class Config { public boolean forceIgnoreHttpsCertificate = false; public boolean forceLoadAllTextures=false; public boolean enableCape = true; + public boolean forceFillSkullNBT = false; public int threadPoolSize = 3; public int retryTime = 1; diff --git a/Forge/resource/transformers.js b/Forge/resource/transformers.js index 7c2fcf7..e726659 100644 --- a/Forge/resource/transformers.js +++ b/Forge/resource/transformers.js @@ -2,6 +2,8 @@ var ASMAPI = Java.type('net.minecraftforge.coremod.api.ASMAPI'); var Opcodes = Java.type('org.objectweb.asm.Opcodes'); var FieldInsnNode = Java.type('org.objectweb.asm.tree.FieldInsnNode'); var InsnNode = Java.type('org.objectweb.asm.tree.InsnNode'); +var JumpInsnNode = Java.type('org.objectweb.asm.tree.JumpInsnNode'); +var LabelNode = Java.type('org.objectweb.asm.tree.LabelNode'); var MethodInsnNode = Java.type('org.objectweb.asm.tree.MethodInsnNode'); var VarInsnNode = Java.type('org.objectweb.asm.tree.VarInsnNode'); @@ -55,8 +57,14 @@ function initializeCoreMod() { 'transformer': function (cn) { cn.methods.forEach(function (mn) { if (checkName(mn.name, "func_174884_b", "updateGameProfile")) { - mn.instructions.insert(new InsnNode(Opcodes.ARETURN)); - mn.instructions.insert(new VarInsnNode(Opcodes.ALOAD, 0)); + var first = mn.instructions.getFirst(); + var label = new LabelNode(); + mn.instructions.insertBefore(first, new FieldInsnNode(Opcodes.GETSTATIC, "customskinloader/CustomSkinLoader", "config", "Lcustomskinloader/config/Config;")); + mn.instructions.insertBefore(first, new FieldInsnNode(Opcodes.GETFIELD, "customskinloader/config/Config", "forceFillSkullNBT", "Z")); + mn.instructions.insertBefore(first, new JumpInsnNode(Opcodes.IFNE, label)); + mn.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 0)); + mn.instructions.insertBefore(first, new InsnNode(Opcodes.ARETURN)); + mn.instructions.insertBefore(first, label); } }); return cn; diff --git a/Forge/source/customskinloader/forge/transformer/TileEntitySkullTransformer.java b/Forge/source/customskinloader/forge/transformer/TileEntitySkullTransformer.java index 53270fe..bbc63f7 100644 --- a/Forge/source/customskinloader/forge/transformer/TileEntitySkullTransformer.java +++ b/Forge/source/customskinloader/forge/transformer/TileEntitySkullTransformer.java @@ -3,9 +3,12 @@ package customskinloader.forge.transformer; import customskinloader.forge.TransformerManager; import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.FieldInsnNode; import org.objectweb.asm.tree.FrameNode; import org.objectweb.asm.tree.InsnList; import org.objectweb.asm.tree.InsnNode; +import org.objectweb.asm.tree.JumpInsnNode; +import org.objectweb.asm.tree.LabelNode; import org.objectweb.asm.tree.MethodNode; import org.objectweb.asm.tree.VarInsnNode; @@ -19,8 +22,13 @@ public class TileEntitySkullTransformer { @Override public MethodNode transform(ClassNode cn, MethodNode mn) { InsnList il = new InsnList(); + LabelNode ln = new LabelNode(); + il.add(new FieldInsnNode(Opcodes.GETSTATIC, "customskinloader/CustomSkinLoader", "config", "Lcustomskinloader/config/Config;")); + il.add(new FieldInsnNode(Opcodes.GETFIELD, "customskinloader/config/Config", "forceFillSkullNBT", "Z")); + il.add(new JumpInsnNode(Opcodes.IFNE, ln)); il.add(new VarInsnNode(Opcodes.ALOAD, 0)); il.add(new InsnNode(Opcodes.ARETURN)); + il.add(ln); il.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null)); mn.instructions.insert(il); return mn; diff --git a/Vanilla/source/customskinloader/mixin/MixinTileEntitySkull.java b/Vanilla/source/customskinloader/mixin/MixinTileEntitySkull.java index c5add08..8a816e7 100644 --- a/Vanilla/source/customskinloader/mixin/MixinTileEntitySkull.java +++ b/Vanilla/source/customskinloader/mixin/MixinTileEntitySkull.java @@ -1,6 +1,7 @@ package customskinloader.mixin; import com.mojang.authlib.GameProfile; +import customskinloader.CustomSkinLoader; import net.minecraft.tileentity.TileEntitySkull; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -15,6 +16,8 @@ public abstract class MixinTileEntitySkull { cancellable = true ) private static void inject_updateGameProfile(GameProfile input, CallbackInfoReturnable callbackInfoReturnable) { - callbackInfoReturnable.setReturnValue(input); + if (!CustomSkinLoader.config.forceFillSkullNBT) { + callbackInfoReturnable.setReturnValue(input); + } } }