fix: solved various (glaring) mistakes, now it works!

This commit is contained in:
zaaarf 2024-05-31 18:56:00 +02:00
parent c48450085b
commit f712320610
No known key found for this signature in database
GPG key ID: 102E445F4C3F829B
6 changed files with 38 additions and 33 deletions

View file

@ -24,7 +24,7 @@ repositories {
}
dependencies {
implementation 'ftbsc:lll:0.5.0'
implementation 'ftbsc:lll:0.5.1'
implementation 'com.google.auto.service:auto-service-annotations:1.1.0'
annotationProcessor 'com.google.auto.service:auto-service:1.1.0'
}

View file

@ -36,7 +36,7 @@ public class MapperProvider {
*/
private void loadMappers() {
this.loadedMappers = new HashSet<>();
for(IMappingFormat mapper: ServiceLoader.load(IMappingFormat.class))
for(IMappingFormat mapper: ServiceLoader.load(IMappingFormat.class, this.getClass().getClassLoader()))
this.loadedMappers.add(mapper);
if(this.loadedMappers.isEmpty())
throw new RuntimeException("Something went wrong: no mapper types were loaded successfully!");
@ -79,7 +79,9 @@ public class MapperProvider {
}
}
return new BufferedReader(new InputStreamReader(targetStream,
StandardCharsets.UTF_8)).lines().collect(Collectors.toList());
return new BufferedReader(new InputStreamReader(
targetStream,
StandardCharsets.UTF_8)
).lines().collect(Collectors.toList());
}
}

View file

@ -87,7 +87,7 @@ public class ClassData {
*/
public ClassData generateReverseMappings(Mapper mapper) {
ClassData reverse = new ClassData(this.nameMapped, this.name);
this.methods.forEach((signature, data) -> reverse.addMethod(nameMapped, signature.name,
this.methods.forEach((signature, data) -> reverse.addMethod(data.nameMapped, signature.name,
MappingUtils.mapMethodDescriptor(signature.descriptor, mapper, false)));
this.fields.forEach((name, data) -> reverse.addField(data.nameMapped, name, data.descriptor));
return reverse;

View file

@ -18,7 +18,7 @@ public class MethodSignature {
/**
* Constructs a new {@link MethodSignature}. The parameters should be
* either plain or obfuscated in the same way;
* either plain or mapped in the same way;
* @param name the method name
* @param descriptor the method descriptor
*/
@ -37,7 +37,7 @@ public class MethodSignature {
if(this == o) return true;
if(o == null || getClass() != o.getClass()) return false;
MethodSignature signature = (MethodSignature) o;
return Objects.equals(name, signature.name) && Objects.equals(descriptor, signature.descriptor);
return Objects.equals(this.name, signature.name) && Objects.equals(this.descriptor, signature.descriptor);
}
/**
@ -46,6 +46,6 @@ public class MethodSignature {
*/
@Override
public int hashCode() {
return Objects.hash(name, descriptor);
return Objects.hash(this.name, this.descriptor);
}
}

View file

@ -78,17 +78,17 @@ public class SRGMapper implements IMappingFormat {
String[] split = tokens[1].split("/");
String memberName = split[split.length - 1];
String parent = tokens[1].substring(0, tokens[1].length() - split[split.length - 1].length() - 1);
int obfPosition = field ? 2 : 3;
split = tokens[obfPosition].split("/");
String memberNameObf = split[split.length - 1];
String parentObf = tokens[obfPosition].substring(0, tokens[obfPosition].length() - split[split.length - 1].length() - 1);
this.registerMember(mapper, invertedMapper, parent, parentObf, memberName, memberNameObf,
int mappedPosition = field ? 2 : 3;
split = tokens[mappedPosition].split("/");
String memberNameMapped = split[split.length - 1];
String parentMapped = tokens[mappedPosition].substring(0, tokens[mappedPosition].length() - split[split.length - 1].length() - 1);
this.registerMember(mapper, invertedMapper, parent, parentMapped, memberName, memberNameMapped,
field ? null : tokens[2], field ? null : tokens[4]);
return true;
}
/**
* Registers a class in the mapper, if it isn't already.
* Registers a class in the mapper, if it isn't already known.
* @param mapper the {@link Mapper} with normal mappings
* @param invertedMapper the {@link Mapper} with inverted mappings
* @param name the name
@ -118,12 +118,10 @@ public class SRGMapper implements IMappingFormat {
this.registerClass(mapper, invertedMapper, parent, parentMapped);
ClassData data = mapper.getClassData(parent);
ClassData dataReverse = invertedMapper.getClassData(data.nameMapped);
if(descriptor == null || descriptorMapped == null) {
//field
if(descriptor == null || descriptorMapped == null) { // field
data.addField(name, nameMapped);
dataReverse.addField(nameMapped, name);
} else {
//method
} else { // method
data.addMethod(name, nameMapped, descriptor);
dataReverse.addMethod(nameMapped, name, descriptorMapped);
}

View file

@ -28,41 +28,46 @@ public class TinyV2Mapper implements IMappingFormat {
for(int i = 1; i < lines.size(); i++) {
String currentLine = lines.get(i);
String[] tokens = currentLine.trim().split("\t");
int tabCount = currentLine.indexOf(tokens[0]); //get number of leading tabs
int tabCount = currentLine.indexOf(tokens[0]); // get number of leading tabs
switch(tabCount) {
case 0: //classes
case 0: // classes
if(tokens.length == 3) {
if(tokens[0].charAt(0) == 'c') {
result.getRawMappings().put(tokens[1], new ClassData(tokens[1], tokens[2]));
currentClass = tokens[1];
} else if(!ignoreErrors)
throw new MalformedMappingsException(i, "root-level element must be class");
throw new MalformedMappingsException(i + 1, "root-level element must be class");
continue;
}
break;
case 1: //class members
case 1: // class members
if(currentClass.isEmpty()) {
if(ignoreErrors) continue;
else throw new MalformedMappingsException(i, "class member without parent class");
else throw new MalformedMappingsException(i + 1, "class member without parent class");
}
switch(tokens[0].charAt(0)) {
case 'm': //methods
case 'm': // methods
if(tokens.length == 4)
break;
result.getClassData(currentClass).addMethod(tokens[2], tokens[3], tokens[1]);
else if(!ignoreErrors)
throw new MalformedMappingsException(i + 1, "incomplete method member");
continue;
case 'f': //fields
case 'f': // fields
if(tokens.length == 4)
break;
result.getClassData(currentClass).addField(tokens[2], tokens[3], tokens[1]);
else if(!ignoreErrors)
throw new MalformedMappingsException(i + 1, "incomplete field member");
continue;
}
break;
case 2: //parameters, our mappers don't really support those
break;
}
case 2: // parameters, our mappers don't really support those
continue;
default:
if(tokens[0].charAt(0) == 'c')
continue; // skip comments
if(!ignoreErrors)
throw new MalformedMappingsException(i, "wrong number of tab-separated tokens");
throw new MalformedMappingsException(i + 1, "wrong number of tab-separated tokens");
}
}
return result;
}