Skip to content

Commit

Permalink
Rework some String remapper again
Browse files Browse the repository at this point in the history
  • Loading branch information
thecatcore committed Aug 21, 2023
1 parent ae73bc2 commit a634242
Showing 1 changed file with 56 additions and 64 deletions.
120 changes: 56 additions & 64 deletions src/main/java/fr/catcore/fabricatedforge/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,36 @@ public static Pair<String, String> getRemappedMethodNameNative(String owner, Str
}

public static Pair<String, String> getRemappedMethodName(String owner, String methodName, String argDesc) {
try {
return getRemappedMethodName(
Class.forName(owner.replace("/", "."), false, Constants.class.getClassLoader()),
methodName, argDesc
);
} catch (Exception e) {
MappingTreeView.ClassMappingView classView = MappingsUtils.getMinecraftMappings().getClass(owner.replace(".", "/"), getTargetNamespace());
if (methodName.equals("<init>") || methodName.length() > 3 || methodName.equals("*")) {
return Pair.of(methodName, argDesc == null || argDesc.isEmpty() || argDesc.equals("()") ? argDesc
: remapMethodDescriptor(argDesc));
}

if (classView != null) {
MappingTreeView.MethodMappingView methodView = classView.getMethod(methodName, argDesc, getSrcNamespace());
MappingTreeView.ClassMappingView classView = MappingsUtils.getMinecraftMappings().getClass(owner.replace(".", "/"), getTargetNamespace());

if (methodView != null) {
return Pair.of(methodView.getName(getTargetNamespace()), methodView.getDesc(getTargetNamespace()));
}
if (classView != null) {
MappingTreeView.MethodMappingView methodView = classView.getMethod(methodName, argDesc, getSrcNamespace());

for (MappingTreeView.MethodMappingView methodViews : classView.getMethods()) {
if (methodViews.getName(getSrcNamespace()).equals(methodName)) {
if (methodViews.getDesc(getSrcNamespace()).equals(argDesc)) {
return Pair.of(methodViews.getName(getTargetNamespace()), methodViews.getDesc(getTargetNamespace()));
}
if (methodView != null) {
return Pair.of(methodView.getName(getTargetNamespace()), methodView.getDesc(getTargetNamespace()));
}

for (MappingTreeView.MethodMappingView methodViews : classView.getMethods()) {
if (methodViews.getName(getSrcNamespace()).equals(methodName)) {
if (methodViews.getDesc(getSrcNamespace()).equals(argDesc)) {
return Pair.of(methodViews.getName(getTargetNamespace()), methodViews.getDesc(getTargetNamespace()));
}
}
}
}

try {
return getRemappedMethodName(
Class.forName(owner.replace("/", "."), false, Constants.class.getClassLoader()),
methodName, argDesc
);
} catch (Exception e) {
e.printStackTrace();
return Pair.of(methodName, argDesc);
}
}
Expand All @@ -74,16 +80,16 @@ public static Pair<String, String> getRemappedMethodName(Class<?> cl, String met
}
}

for (Class<?> interfaces : cl.getInterfaces()) {
Pair<String, String> result = getRemappedMethodName(interfaces, methodName, argDesc);
if (cl.getSuperclass() != null) {
Pair<String, String> result = getRemappedMethodName(cl.getSuperclass(), methodName, argDesc);

if (!methodName.equals(result.first()) || !argDesc.equals(result.second())) {
return result;
}
}

if (cl.getSuperclass() != null) {
Pair<String, String> result = getRemappedMethodName(cl.getSuperclass(), methodName, argDesc);
for (Class<?> interfaces : cl.getInterfaces()) {
Pair<String, String> result = getRemappedMethodName(interfaces, methodName, argDesc);

if (!methodName.equals(result.first()) || !argDesc.equals(result.second())) {
return result;
Expand Down Expand Up @@ -112,51 +118,53 @@ public static String getRemappedFieldNameNative(String owner, String fieldName)
}

public static String getRemappedFieldName(String owner, String fieldName) {
MappingTreeView.ClassMappingView classView = MappingsUtils.getMinecraftMappings().getClass(owner.replace(".", "/"), getTargetNamespace());

if (classView != null) {
for (MappingTreeView.FieldMappingView fieldViews : classView.getFields()) {
if (fieldViews.getName(getSrcNamespace()).equals(fieldName)) {
return fieldViews.getName(getTargetNamespace());
}
}
}

try {
return getRemappedField(
Class.forName(owner.replace("/", "."), false, Constants.class.getClassLoader()),
fieldName
);
} catch (Exception e) {
MappingTreeView.ClassMappingView classView = MappingsUtils.getMinecraftMappings().getClass(owner.replace(".", "/"), getTargetNamespace());

if (classView != null) {
for (MappingTreeView.FieldMappingView fieldViews : classView.getFields()) {
if (fieldViews.getName(getSrcNamespace()).equals(fieldName)) {
return fieldViews.getName(getTargetNamespace());
}
}
}

e.printStackTrace();
return fieldName;
}
}

public static Pair<String, String> getRemappedFieldName(String owner, String fieldName, String fieldDesc) {
try {
return getRemappedField(
Class.forName(owner.replace("/", "."), false, Constants.class.getClassLoader()),
fieldName, fieldDesc
);
} catch (Exception e) {
MappingTreeView.ClassMappingView classView = MappingsUtils.getMinecraftMappings().getClass(owner.replace(".", "/"), getTargetNamespace());
MappingTreeView.ClassMappingView classView = MappingsUtils.getMinecraftMappings().getClass(owner.replace(".", "/"), getTargetNamespace());

if (classView != null) {
MappingTreeView.FieldMappingView methodView = classView.getField(fieldName, fieldDesc, getSrcNamespace());
if (classView != null) {
MappingTreeView.FieldMappingView methodView = classView.getField(fieldName, fieldDesc, getSrcNamespace());

if (methodView != null) {
return Pair.of(methodView.getName(getTargetNamespace()), methodView.getDesc(getTargetNamespace()));
}
if (methodView != null) {
return Pair.of(methodView.getName(getTargetNamespace()), methodView.getDesc(getTargetNamespace()));
}

for (MappingTreeView.FieldMappingView fieldViews : classView.getFields()) {
if (fieldViews.getName(getSrcNamespace()).equals(fieldName)) {
if (fieldViews.getDesc(getSrcNamespace()).equals(fieldDesc)) {
return Pair.of(fieldViews.getName(getTargetNamespace()), fieldViews.getDesc(getTargetNamespace()));
}
for (MappingTreeView.FieldMappingView fieldViews : classView.getFields()) {
if (fieldViews.getName(getSrcNamespace()).equals(fieldName)) {
if (fieldViews.getDesc(getSrcNamespace()).equals(fieldDesc)) {
return Pair.of(fieldViews.getName(getTargetNamespace()), fieldViews.getDesc(getTargetNamespace()));
}
}
}
}

try {
return getRemappedField(
Class.forName(owner.replace("/", "."), false, Constants.class.getClassLoader()),
fieldName, fieldDesc
);
} catch (Exception e) {
e.printStackTrace();
return Pair.of(fieldName, fieldDesc);
}
}
Expand All @@ -180,14 +188,6 @@ public static Pair<String, String> getRemappedField(Class<?> cl, String fieldNam
}
}

for (Class<?> interfaces : cl.getInterfaces()) {
Pair<String, String> result = getRemappedField(interfaces, fieldName, argDesc);

if (!fieldName.equals(result.first()) || !argDesc.equals(result.second())) {
return result;
}
}

if (cl.getSuperclass() != null) {
Pair<String, String> result = getRemappedField(cl.getSuperclass(), fieldName, argDesc);

Expand All @@ -210,14 +210,6 @@ public static String getRemappedField(Class<?> cl, String fieldName) {
}
}

for (Class<?> interfaces : cl.getInterfaces()) {
String result = getRemappedField(cl.getSuperclass(), fieldName);

if (!fieldName.equals(result)) {
return result;
}
}

if (cl.getSuperclass() != null) {
String result = getRemappedField(cl.getSuperclass(), fieldName);

Expand Down

0 comments on commit a634242

Please sign in to comment.