Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invert Mapping-IO Proguard mappings to mirror legacy behavior #542

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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