mirror of
https://github.com/FalsePattern/FalsePatternLib.git
synced 2026-11-15 19:34:44 +00:00
Annotate all the things
This commit is contained in:
63 files changed
+623
-369
No files matched your search
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
package com.falsepattern.lib.asm;
|
||||
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
import com.falsepattern.lib.asm.exceptions.AsmClassNotFoundException;
|
||||
import com.falsepattern.lib.asm.exceptions.AsmFieldNotFoundException;
|
||||
import com.falsepattern.lib.asm.exceptions.AsmMethodNotFoundException;
|
||||
@@ -42,7 +43,9 @@ import org.objectweb.asm.tree.MethodNode;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
public class ASMUtil {
|
||||
@StableAPI.Expose
|
||||
public static FieldNode findFieldStandard(ClassNode cn, String name, boolean optional) {
|
||||
for (final FieldNode ret : cn.fields) {
|
||||
if (name.equals(ret.name)) {
|
||||
@@ -56,6 +59,7 @@ public class ASMUtil {
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@StableAPI.Expose
|
||||
public static FieldNode findFieldFromMCP(ClassNode cn, String fieldName, boolean optional) {
|
||||
val classMapping = discoverClassMappingType(cn);
|
||||
if (classMapping == null) {
|
||||
@@ -67,6 +71,7 @@ public class ASMUtil {
|
||||
.getName(classMapping), optional);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static FieldNode findFieldFromUniversal(ClassNode cn, UniversalField field, boolean optional) {
|
||||
String[] possibilities = CoreLoadingPlugin.isObfuscated() ? new String[]{field.getName(MappingType.SRG),
|
||||
field.getName(MappingType.Notch)}
|
||||
@@ -83,6 +88,7 @@ public class ASMUtil {
|
||||
possibilities.length == 1 ? possibilities[0] : Arrays.toString(possibilities));
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static MethodNode findMethodStandard(ClassNode cn, String name, String descriptor, boolean optional) {
|
||||
for (final MethodNode ret : cn.methods) {
|
||||
if (name.equals(ret.name) && descriptor.equals(ret.desc)) {
|
||||
@@ -96,6 +102,7 @@ public class ASMUtil {
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@StableAPI.Expose
|
||||
public static MethodNode findMethodFromMCP(ClassNode cn, String mcpName, String mcpDescriptor, boolean optional) {
|
||||
val classMapping = discoverClassMappingType(cn);
|
||||
if (classMapping == null) {
|
||||
@@ -107,6 +114,7 @@ public class ASMUtil {
|
||||
return findMethodStandard(cn, method.getName(classMapping), method.getDescriptor(classMapping), optional);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static MethodNode findMethodFromUniversal(ClassNode cn, UniversalMethod method, boolean optional) {
|
||||
String[] possibleNames = CoreLoadingPlugin.isObfuscated() ? new String[]{method.getName(MappingType.SRG),
|
||||
method.getName(MappingType.Notch)}
|
||||
@@ -127,6 +135,7 @@ public class ASMUtil {
|
||||
possibleDescriptors.length == 1 ? possibleDescriptors[0] : Arrays.toString(possibleDescriptors));
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static MappingType discoverClassMappingType(ClassNode cn) {
|
||||
if (CoreLoadingPlugin.isObfuscated()) {
|
||||
if (MappingManager.containsClass(NameType.Internal, MappingType.MCP, cn.name)) {
|
||||
@@ -140,6 +149,7 @@ public class ASMUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static UniversalClass toUniversalClass(ClassNode cn) {
|
||||
if (CoreLoadingPlugin.isObfuscated()) {
|
||||
try {
|
||||
@@ -160,6 +170,7 @@ public class ASMUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static ClassNode parseClass(byte[] bytes, int readerFlags) {
|
||||
val cn = new ClassNode(Opcodes.ASM5);
|
||||
val reader = new ClassReader(bytes);
|
||||
@@ -167,11 +178,13 @@ public class ASMUtil {
|
||||
return cn;
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static byte[] serializeClass(ClassNode cn, int writerFlags) {
|
||||
val writer = new ClassWriter(writerFlags);
|
||||
return writer.toByteArray();
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static boolean anyEquals(String str, String... options) {
|
||||
for (val option : options) {
|
||||
if (Objects.equals(str, option)) {
|
||||
|
||||
Reference in new issue
Block a user