mirror of
https://github.com/FalsePattern/FalsePatternLib.git
synced 2026-11-15 14:54:45 +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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user