mirror of
https://github.com/FalsePattern/FalsePatternLib.git
synced 2026-11-16 21:05:10 +00:00
code cleanup
This commit is contained in:
76 files changed
+691
-622
No files matched your search
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* Copyright (C) 2022 FalsePattern
|
||||
* All Rights Reserved
|
||||
*
|
||||
@@ -32,15 +32,12 @@ import com.falsepattern.lib.mapping.types.UniversalField;
|
||||
import com.falsepattern.lib.mapping.types.UniversalMethod;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.val;
|
||||
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.Opcodes;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.FieldNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.objectweb.asm.util.CheckClassAdapter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
@@ -65,17 +62,15 @@ public class ASMUtil {
|
||||
throw new AsmClassNotFoundException("The class " + cn + " is not from Minecraft, or the mapping manager" +
|
||||
"doesn't have it, cannot use findFieldFromMCP! Use findFieldStandard instead!");
|
||||
}
|
||||
return findFieldStandard(cn,
|
||||
MappingManager.classForName(NameType.Internal, classMapping, cn.name)
|
||||
.getField(MappingType.MCP, fieldName)
|
||||
.getName(classMapping),
|
||||
optional);
|
||||
return findFieldStandard(cn, MappingManager.classForName(NameType.Internal, classMapping, cn.name)
|
||||
.getField(MappingType.MCP, fieldName)
|
||||
.getName(classMapping), optional);
|
||||
}
|
||||
|
||||
public static FieldNode findFieldFromUniversal(ClassNode cn, UniversalField field, boolean optional) {
|
||||
String[] possibilities = CoreLoadingPlugin.isObfuscated() ?
|
||||
new String[]{field.getName(MappingType.SRG), field.getName(MappingType.Notch)} :
|
||||
new String[] {field.getName(MappingType.MCP)};
|
||||
String[] possibilities = CoreLoadingPlugin.isObfuscated() ? new String[]{field.getName(MappingType.SRG),
|
||||
field.getName(MappingType.Notch)}
|
||||
: new String[]{field.getName(MappingType.MCP)};
|
||||
for (final FieldNode ret : cn.fields) {
|
||||
if (anyEquals(ret.name, possibilities)) {
|
||||
return ret;
|
||||
@@ -84,7 +79,8 @@ public class ASMUtil {
|
||||
if (optional) {
|
||||
return null;
|
||||
}
|
||||
throw new AsmFieldNotFoundException(possibilities.length == 1 ? possibilities[0] : Arrays.toString(possibilities));
|
||||
throw new AsmFieldNotFoundException(
|
||||
possibilities.length == 1 ? possibilities[0] : Arrays.toString(possibilities));
|
||||
}
|
||||
|
||||
public static MethodNode findMethodStandard(ClassNode cn, String name, String descriptor, boolean optional) {
|
||||
@@ -112,12 +108,13 @@ public class ASMUtil {
|
||||
}
|
||||
|
||||
public static MethodNode findMethodFromUniversal(ClassNode cn, UniversalMethod method, boolean optional) {
|
||||
String[] possibleNames = CoreLoadingPlugin.isObfuscated() ?
|
||||
new String[]{method.getName(MappingType.SRG), method.getName(MappingType.Notch)} :
|
||||
new String[] {method.getName(MappingType.MCP)};
|
||||
String[] possibleDescriptors = CoreLoadingPlugin.isObfuscated() ?
|
||||
new String[]{method.getDescriptor(MappingType.SRG), method.getDescriptor(MappingType.Notch)} :
|
||||
new String[] {method.getDescriptor(MappingType.MCP)};
|
||||
String[] possibleNames = CoreLoadingPlugin.isObfuscated() ? new String[]{method.getName(MappingType.SRG),
|
||||
method.getName(MappingType.Notch)}
|
||||
: new String[]{method.getName(MappingType.MCP)};
|
||||
String[] possibleDescriptors =
|
||||
CoreLoadingPlugin.isObfuscated() ? new String[]{method.getDescriptor(MappingType.SRG),
|
||||
method.getDescriptor(MappingType.Notch)}
|
||||
: new String[]{method.getDescriptor(MappingType.MCP)};
|
||||
for (final MethodNode ret : cn.methods) {
|
||||
if (anyEquals(ret.name, possibleNames) && anyEquals(ret.desc, possibleDescriptors)) {
|
||||
return ret;
|
||||
@@ -126,7 +123,8 @@ public class ASMUtil {
|
||||
if (optional) {
|
||||
return null;
|
||||
}
|
||||
throw new AsmFieldNotFoundException(possibleDescriptors.length == 1 ? possibleDescriptors[0] : Arrays.toString(possibleDescriptors));
|
||||
throw new AsmFieldNotFoundException(
|
||||
possibleDescriptors.length == 1 ? possibleDescriptors[0] : Arrays.toString(possibleDescriptors));
|
||||
}
|
||||
|
||||
public static MappingType discoverClassMappingType(ClassNode cn) {
|
||||
@@ -175,7 +173,7 @@ public class ASMUtil {
|
||||
}
|
||||
|
||||
public static boolean anyEquals(String str, String... options) {
|
||||
for (val option: options) {
|
||||
for (val option : options) {
|
||||
if (Objects.equals(str, option)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* Copyright (C) 2022 FalsePattern
|
||||
* All Rights Reserved
|
||||
*
|
||||
@@ -24,7 +24,9 @@ import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
public interface IClassNodeTransformer {
|
||||
String getName();
|
||||
|
||||
boolean shouldTransform(ClassNode cn, String transformedName, boolean obfuscated);
|
||||
|
||||
default int internalSortingOrder() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* Copyright (C) 2022 FalsePattern
|
||||
* All Rights Reserved
|
||||
*
|
||||
@@ -20,7 +20,6 @@
|
||||
*/
|
||||
package com.falsepattern.lib.asm;
|
||||
|
||||
import com.falsepattern.lib.asm.exceptions.AsmTransformException;
|
||||
import com.falsepattern.lib.internal.CoreLoadingPlugin;
|
||||
import lombok.val;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -38,7 +37,9 @@ import java.util.List;
|
||||
*/
|
||||
public interface SmartTransformer extends IClassTransformer {
|
||||
Logger logger();
|
||||
|
||||
List<IClassNodeTransformer> transformers();
|
||||
|
||||
@Override
|
||||
default byte[] transform(String name, String transformedName, byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
@@ -46,7 +47,7 @@ public interface SmartTransformer extends IClassTransformer {
|
||||
}
|
||||
val transformers = new ArrayList<IClassNodeTransformer>();
|
||||
val cn = ASMUtil.parseClass(bytes, ClassReader.EXPAND_FRAMES);
|
||||
for (val transformer: transformers()) {
|
||||
for (val transformer : transformers()) {
|
||||
if (transformer.shouldTransform(cn, transformedName, CoreLoadingPlugin.isObfuscated())) {
|
||||
transformers.add(transformer);
|
||||
}
|
||||
@@ -56,7 +57,7 @@ public interface SmartTransformer extends IClassTransformer {
|
||||
}
|
||||
transformers.sort(Comparator.comparingInt(IClassNodeTransformer::internalSortingOrder));
|
||||
val log = logger();
|
||||
for (val transformer: transformers) {
|
||||
for (val transformer : transformers) {
|
||||
log.debug("Patching {} with {}...", transformedName, transformer.getName());
|
||||
try {
|
||||
transformer.transform(cn, transformedName, CoreLoadingPlugin.isObfuscated());
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* Copyright (C) 2022 FalsePattern
|
||||
* All Rights Reserved
|
||||
*
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* Copyright (C) 2022 FalsePattern
|
||||
* All Rights Reserved
|
||||
*
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* Copyright (C) 2022 FalsePattern
|
||||
* All Rights Reserved
|
||||
*
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* Copyright (C) 2022 FalsePattern
|
||||
* All Rights Reserved
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user