mirror of
https://github.com/GTMEGA/EndlessIDs.git
synced 2026-11-20 02:59:45 +00:00
restyle code
This commit is contained in:
58 files changed
+567
-480
No files matched your search
@@ -1,17 +1,16 @@
|
||||
package com.falsepattern.endlessids.asm;
|
||||
|
||||
public class AsmTransformException extends RuntimeException
|
||||
{
|
||||
public class AsmTransformException extends RuntimeException {
|
||||
private static final long serialVersionUID = 5128914670008752449L;
|
||||
|
||||
|
||||
public AsmTransformException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
||||
public AsmTransformException(final Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
|
||||
public AsmTransformException(final String message, final Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,20 @@
|
||||
package com.falsepattern.endlessids.asm;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.util.Printer;
|
||||
import org.objectweb.asm.util.TraceMethodVisitor;
|
||||
import org.objectweb.asm.util.Textifier;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import java.util.ListIterator;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.FieldNode;
|
||||
import org.objectweb.asm.tree.InsnNode;
|
||||
import org.objectweb.asm.tree.IntInsnNode;
|
||||
import org.objectweb.asm.tree.LdcInsnNode;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.FieldNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
public class AsmUtil
|
||||
{
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class AsmUtil {
|
||||
public AsmUtil() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
public static FieldNode findField(final ClassNode cn, final String name, final boolean optional) {
|
||||
for (final FieldNode ret : cn.fields) {
|
||||
if (name.equals(ret.name)) {
|
||||
@@ -32,7 +26,7 @@ public class AsmUtil
|
||||
}
|
||||
throw new FieldNotFoundException(name);
|
||||
}
|
||||
|
||||
|
||||
public static boolean transformInlinedSizeMethod(final ClassNode cn, final MethodNode method, final int oldValue, final int newValue, final boolean optional) {
|
||||
boolean found = false;
|
||||
boolean foundOnce = false;
|
||||
@@ -42,30 +36,23 @@ public class AsmUtil
|
||||
final AbstractInsnNode insn = it.next();
|
||||
if (insn.getOpcode() == 3 && oldValue == 0) {
|
||||
found = true;
|
||||
}
|
||||
else if (insn.getOpcode() == 4 && oldValue == 1) {
|
||||
} else if (insn.getOpcode() == 4 && oldValue == 1) {
|
||||
found = true;
|
||||
}
|
||||
else if (insn.getOpcode() == 5 && oldValue == 2) {
|
||||
} else if (insn.getOpcode() == 5 && oldValue == 2) {
|
||||
found = true;
|
||||
}
|
||||
else if (insn.getOpcode() == 6 && oldValue == 3) {
|
||||
} else if (insn.getOpcode() == 6 && oldValue == 3) {
|
||||
found = true;
|
||||
}
|
||||
else if (insn.getOpcode() == 7 && oldValue == 4) {
|
||||
} else if (insn.getOpcode() == 7 && oldValue == 4) {
|
||||
found = true;
|
||||
}
|
||||
else if (insn.getOpcode() == 8 && oldValue == 5) {
|
||||
} else if (insn.getOpcode() == 8 && oldValue == 5) {
|
||||
found = true;
|
||||
}
|
||||
else if (insn.getOpcode() == 18) {
|
||||
final LdcInsnNode node = (LdcInsnNode)insn;
|
||||
if (node.cst instanceof Integer && (int)node.cst == oldValue) {
|
||||
} else if (insn.getOpcode() == 18) {
|
||||
final LdcInsnNode node = (LdcInsnNode) insn;
|
||||
if (node.cst instanceof Integer && (int) node.cst == oldValue) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
else if (insn.getOpcode() == 17 || insn.getOpcode() == 16) {
|
||||
final IntInsnNode node2 = (IntInsnNode)insn;
|
||||
} else if (insn.getOpcode() == 17 || insn.getOpcode() == 16) {
|
||||
final IntInsnNode node2 = (IntInsnNode) insn;
|
||||
if (node2.operand == oldValue) {
|
||||
found = true;
|
||||
}
|
||||
@@ -74,29 +61,21 @@ public class AsmUtil
|
||||
foundOnce = true;
|
||||
if (newValue == 0) {
|
||||
it.set(new InsnNode(3));
|
||||
}
|
||||
else if (newValue == 1) {
|
||||
} else if (newValue == 1) {
|
||||
it.set(new InsnNode(4));
|
||||
}
|
||||
else if (newValue == 2) {
|
||||
} else if (newValue == 2) {
|
||||
it.set(new InsnNode(5));
|
||||
}
|
||||
else if (newValue == 3) {
|
||||
} else if (newValue == 3) {
|
||||
it.set(new InsnNode(6));
|
||||
}
|
||||
else if (newValue == 4) {
|
||||
} else if (newValue == 4) {
|
||||
it.set(new InsnNode(7));
|
||||
}
|
||||
else if (newValue == 5) {
|
||||
} else if (newValue == 5) {
|
||||
it.set(new InsnNode(8));
|
||||
}
|
||||
else if (newValue >= -128 && newValue <= 127) {
|
||||
} else if (newValue >= -128 && newValue <= 127) {
|
||||
it.set(new IntInsnNode(16, newValue));
|
||||
}
|
||||
else if (newValue >= -32768 && newValue <= 32767) {
|
||||
} else if (newValue >= -32768 && newValue <= 32767) {
|
||||
it.set(new IntInsnNode(17, newValue));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
it.set(new LdcInsnNode(newValue));
|
||||
}
|
||||
found = false;
|
||||
@@ -107,5 +86,5 @@ public class AsmUtil
|
||||
}
|
||||
return foundOnce;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,35 +1,17 @@
|
||||
package com.falsepattern.endlessids.asm;
|
||||
|
||||
import java.util.HashMap;
|
||||
import com.falsepattern.endlessids.asm.transformer.FmlRegistry;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum ClassEdit
|
||||
{
|
||||
FmlRegistry(new FmlRegistry(), new String[] { "cpw.mods.fml.common.registry.GameData", "cpw.mods.fml.common.registry.FMLControlledNamespacedRegistry" }),
|
||||
public enum ClassEdit {
|
||||
FmlRegistry(new FmlRegistry(), new String[]{"cpw.mods.fml.common.registry.GameData",
|
||||
"cpw.mods.fml.common.registry.FMLControlledNamespacedRegistry"}),
|
||||
;
|
||||
|
||||
|
||||
private static final Map<String, ClassEdit> editMap;
|
||||
private final IClassNodeTransformer transformer;
|
||||
private final String[] classNames;
|
||||
|
||||
ClassEdit(final IClassNodeTransformer transformer, final String[] classNames) {
|
||||
this.transformer = transformer;
|
||||
this.classNames = classNames;
|
||||
}
|
||||
|
||||
public static ClassEdit get(final String className) {
|
||||
return ClassEdit.editMap.get(className);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
public IClassNodeTransformer getTransformer() {
|
||||
return this.transformer;
|
||||
}
|
||||
|
||||
|
||||
static {
|
||||
editMap = new HashMap<>();
|
||||
for (final ClassEdit edit : values()) {
|
||||
@@ -38,4 +20,24 @@ public enum ClassEdit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final IClassNodeTransformer transformer;
|
||||
private final String[] classNames;
|
||||
|
||||
ClassEdit(final IClassNodeTransformer transformer, final String[] classNames) {
|
||||
this.transformer = transformer;
|
||||
this.classNames = classNames;
|
||||
}
|
||||
|
||||
public static ClassEdit get(final String className) {
|
||||
return ClassEdit.editMap.get(className);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
public IClassNodeTransformer getTransformer() {
|
||||
return this.transformer;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.falsepattern.endlessids.asm;
|
||||
|
||||
public class FieldNotFoundException extends AsmTransformException
|
||||
{
|
||||
public class FieldNotFoundException extends AsmTransformException {
|
||||
public FieldNotFoundException(final String field) {
|
||||
super("can't find field " + field);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.falsepattern.endlessids.asm;
|
||||
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
public interface IClassNodeTransformer
|
||||
{
|
||||
public interface IClassNodeTransformer {
|
||||
void transform(final ClassNode p0, final boolean p1);
|
||||
}
|
||||
@@ -2,23 +2,27 @@ package com.falsepattern.endlessids.asm;
|
||||
|
||||
import com.falsepattern.endlessids.Tags;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.objectweb.asm.util.CheckClassAdapter;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.util.CheckClassAdapter;
|
||||
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
|
||||
public class IETransformer implements IClassTransformer
|
||||
{
|
||||
public class IETransformer implements IClassTransformer {
|
||||
public static final Logger logger;
|
||||
public static boolean isObfuscated;
|
||||
|
||||
static {
|
||||
logger = LogManager.getLogger(Tags.MODNAME + " ASM");
|
||||
}
|
||||
|
||||
public IETransformer() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
public byte[] transform(final String name, final String transformedName, final byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
return bytes;
|
||||
@@ -33,29 +37,25 @@ public class IETransformer implements IClassTransformer
|
||||
reader.accept(cn, 0);
|
||||
try {
|
||||
edit.getTransformer().transform(cn, IETransformer.isObfuscated);
|
||||
}
|
||||
catch (AsmTransformException t) {
|
||||
IETransformer.logger.error("Error transforming {} with {}: {}", transformedName, edit.getName(), t.getMessage());
|
||||
} catch (AsmTransformException t) {
|
||||
IETransformer.logger.error("Error transforming {} with {}: {}", transformedName, edit.getName(),
|
||||
t.getMessage());
|
||||
throw t;
|
||||
}
|
||||
catch (Throwable t2) {
|
||||
IETransformer.logger.error("Error transforming {} with {}: {}", transformedName, edit.getName(), t2.getMessage());
|
||||
} catch (Throwable t2) {
|
||||
IETransformer.logger.error("Error transforming {} with {}: {}", transformedName, edit.getName(),
|
||||
t2.getMessage());
|
||||
throw new RuntimeException(t2);
|
||||
}
|
||||
final ClassWriter writer = new ClassWriter(0);
|
||||
try {
|
||||
final ClassVisitor check = new CheckClassAdapter(writer);
|
||||
cn.accept(check);
|
||||
}
|
||||
catch (Throwable t3) {
|
||||
IETransformer.logger.error("Error verifying {} transformed with {}: {}", transformedName, edit.getName(), t3.getMessage());
|
||||
} catch (Throwable t3) {
|
||||
IETransformer.logger.error("Error verifying {} transformed with {}: {}", transformedName, edit.getName(),
|
||||
t3.getMessage());
|
||||
throw new RuntimeException(t3);
|
||||
}
|
||||
IETransformer.logger.debug("Patched {} successfully.", edit.getName());
|
||||
return writer.toByteArray();
|
||||
}
|
||||
|
||||
static {
|
||||
logger = LogManager.getLogger(Tags.MODNAME + " ASM");
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.falsepattern.endlessids.asm;
|
||||
|
||||
public class MethodNotFoundException extends AsmTransformException
|
||||
{
|
||||
public class MethodNotFoundException extends AsmTransformException {
|
||||
public MethodNotFoundException(final String method) {
|
||||
super("can't find method " + method);
|
||||
}
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
package com.falsepattern.endlessids.asm.transformer;
|
||||
|
||||
import com.falsepattern.endlessids.asm.AsmTransformException;
|
||||
import com.falsepattern.endlessids.asm.AsmUtil;
|
||||
import com.falsepattern.endlessids.asm.IClassNodeTransformer;
|
||||
import com.falsepattern.endlessids.constants.ExtendedConstants;
|
||||
import com.falsepattern.endlessids.constants.VanillaConstants;
|
||||
import lombok.var;
|
||||
import org.objectweb.asm.tree.FieldNode;
|
||||
import com.falsepattern.endlessids.asm.AsmTransformException;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import com.falsepattern.endlessids.asm.AsmUtil;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import com.falsepattern.endlessids.asm.IClassNodeTransformer;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
public class FmlRegistry implements IClassNodeTransformer
|
||||
{
|
||||
public class FmlRegistry implements IClassNodeTransformer {
|
||||
public FmlRegistry() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void transform(final ClassNode cn, final boolean obfuscated) {
|
||||
var field = AsmUtil.findField(cn, "MAX_BLOCK_ID", true);
|
||||
@@ -28,7 +26,8 @@ public class FmlRegistry implements IClassNodeTransformer
|
||||
}
|
||||
boolean found = false;
|
||||
for (final MethodNode method : cn.methods) {
|
||||
if (AsmUtil.transformInlinedSizeMethod(cn, method, VanillaConstants.maxBlockID, ExtendedConstants.maxBlockID, true)) {
|
||||
if (AsmUtil.transformInlinedSizeMethod(cn, method, VanillaConstants.maxBlockID,
|
||||
ExtendedConstants.maxBlockID, true)) {
|
||||
found = true;
|
||||
}
|
||||
AsmUtil.transformInlinedSizeMethod(cn, method, 31999, ExtendedConstants.maxBlockID, true);
|
||||
|
||||
Reference in new issue
Block a user