Skip to content

Commit

Permalink
Invert Mapping-IO Proguard mappings to mirror legacy behavior (#542)
Browse files Browse the repository at this point in the history
* Invert Proguard data read from / written by Mapping-IO to mirror legacy behavior

* Fix code style
  • Loading branch information
NebelNidas authored Apr 8, 2024
1 parent 537ecc8 commit 6a517c6
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import cuchaz.enigma.analysis.index.JarIndex;
import cuchaz.enigma.translation.mapping.EntryMapping;
import cuchaz.enigma.translation.mapping.MappingDelta;
import cuchaz.enigma.translation.mapping.MappingOperations;
import cuchaz.enigma.translation.mapping.serde.enigma.EnigmaMappingsReader;
import cuchaz.enigma.translation.mapping.serde.enigma.EnigmaMappingsWriter;
import cuchaz.enigma.translation.mapping.serde.proguard.ProguardMappingsReader;
Expand Down Expand Up @@ -77,6 +78,10 @@ public void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> d
}

try {
if (this == PROGUARD) {
mappings = MappingOperations.invert(mappings);
}

VisitableMappingTree tree = MappingIoConverter.toMappingIo(mappings, progressListener);
progressListener.init(1, I18n.translate("progress.mappings.writing"));
progressListener.step(1, null); // Reset message
Expand Down Expand Up @@ -115,15 +120,31 @@ public EntryTree<EntryMapping> read(Path path, ProgressListener progressListener

VisitableMappingTree mappingTree = new MemoryMappingTree();
MappingReader.read(path, mappingIoCounterpart, mappingTree);
return MappingIoConverter.fromMappingIo(mappingTree, progressListener, index);
EntryTree<EntryMapping> mappings = MappingIoConverter.fromMappingIo(mappingTree, progressListener, index);

return this == PROGUARD ? MappingOperations.invert(mappings) : mappings;
}

/**
* @return Enigma's native writer for the format, or {@code null} if none exists.
*
* @deprecated Use {@link #isWritable()} and {@link #write(EntryTree, Path, ProgressListener, MappingSaveParameters)} instead,
* which take the new Mapping-IO equivalents (and eventual replacements) into account.
*/
@Nullable
@Deprecated
public MappingsWriter getWriter() {
return writer;
}

/**
* @return Enigma's native reader for the format, or {@code null} if none exists.
*
* @deprecated Use {@link #isReadable()} and {@link #read(Path, ProgressListener, MappingSaveParameters, JarIndex)} instead,
* which take the new Mapping-IO equivalents (and eventual replacements) into account.
*/
@Nullable
@Deprecated
public MappingsReader getReader() {
return reader;
}
Expand Down

0 comments on commit 6a517c6

Please sign in to comment.