-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
draft of dynamic proposal (no definitions file)
- Loading branch information
Showing
5 changed files
with
115 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/org/quiltmc/enigma_plugin/proposal/MojmapPackageProposer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.quiltmc.enigma_plugin.proposal; | ||
|
||
import org.quiltmc.enigma.api.Enigma; | ||
import org.quiltmc.enigma.api.analysis.index.jar.EntryIndex; | ||
import org.quiltmc.enigma.api.analysis.index.jar.JarIndex; | ||
import org.quiltmc.enigma.api.translation.mapping.EntryMapping; | ||
import org.quiltmc.enigma.api.translation.mapping.EntryRemapper; | ||
import org.quiltmc.enigma.api.translation.representation.entry.ClassEntry; | ||
import org.quiltmc.enigma.api.translation.representation.entry.Entry; | ||
import org.tinylog.Logger; | ||
|
||
import java.util.Map; | ||
|
||
public class MojmapPackageProposer extends NameProposer { | ||
public static final String ID = "mojmap_packages"; | ||
|
||
public MojmapPackageProposer() { | ||
super(ID); | ||
} | ||
|
||
@Override | ||
public void insertProposedNames(Enigma enigma, JarIndex index, Map<Entry<?>, EntryMapping> mappings) { | ||
// no-op | ||
} | ||
|
||
@Override | ||
public void proposeDynamicNames(EntryRemapper remapper, Entry<?> obfEntry, EntryMapping oldMapping, EntryMapping newMapping, Map<Entry<?>, EntryMapping> mappings) { | ||
// todo definitions file | ||
|
||
if (obfEntry == null) { | ||
// initial proposal for all classes | ||
for (ClassEntry classEntry : remapper.getJarIndex().getIndex(EntryIndex.class).getClasses()) { | ||
this.tryProposeForEntry(remapper, mappings, classEntry); | ||
} | ||
} else { | ||
this.tryProposeForEntry(remapper, mappings, obfEntry); | ||
} | ||
} | ||
|
||
private void tryProposeForEntry(EntryRemapper remapper, Map<Entry<?>, EntryMapping> mappings, Entry<?> entry) { | ||
var mojmaps = MojmapNameProposer.mojmaps; | ||
|
||
if (entry instanceof ClassEntry classEntry && !classEntry.isInnerClass() && mojmaps != null) { | ||
String newName = getMojmappedName(remapper, classEntry); | ||
mappings.put(classEntry, new EntryMapping(newName)); | ||
} | ||
} | ||
|
||
private String getMojmappedName(EntryRemapper remapper, ClassEntry classEntry) { | ||
var mojmaps = MojmapNameProposer.mojmaps; | ||
|
||
var mapping = mojmaps.get(classEntry); | ||
if (mapping != null && mapping.targetName() != null) { | ||
String mojmapName = mapping.targetName(); | ||
String oldPackage = mojmapName.substring(0, mojmapName.lastIndexOf('/')); | ||
String className = remapper.deobfuscate(classEntry).getSimpleName(); | ||
|
||
return oldPackage + "/" + className; | ||
} else { | ||
Logger.error("failed to propose name: could not find mojmap for " + classEntry.getFullName()); | ||
return null; | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/org/quiltmc/enigma_plugin/proposal/UncheckedProposalService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.quiltmc.enigma_plugin.proposal; | ||
|
||
import org.quiltmc.enigma.api.service.EnigmaServiceContext; | ||
import org.quiltmc.enigma.api.service.NameProposalService; | ||
import org.quiltmc.enigma_plugin.Arguments; | ||
import org.quiltmc.enigma_plugin.QuiltEnigmaPlugin; | ||
import org.quiltmc.enigma_plugin.index.JarIndexer; | ||
|
||
public class UncheckedProposalService extends NameProposerService { | ||
public UncheckedProposalService(JarIndexer indexer, EnigmaServiceContext<NameProposalService> context) { | ||
super(); | ||
this.addIfEnabled(context, Arguments.DISABLE_MOJMAP, MojmapPackageProposer::new); | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return QuiltEnigmaPlugin.UNCHECKED_NAME_PROPOSAL_SERVICE_ID; | ||
} | ||
|
||
@Override | ||
public boolean bypassValidation() { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters