Skip to content

Commit

Permalink
-s defaults to client
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoPangxie732 committed Jan 17, 2025
1 parent 62267b9 commit 6a7e915
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static void main(String[] args) throws Throwable {
OptionParser parser = new OptionParser();
ArgumentAcceptingOptionSpec<SideType> sideTypeO = parser.acceptsAll(of("s", "side"), "Side to deobfuscate/" +
"decompile. Values are \"CLIENT\" and \"SERVER\". With this option, you must specify --version option and can't " +
"specify --input option.").withRequiredArg().ofType(SideType.class);
"specify --input option.").withRequiredArg().ofType(SideType.class).defaultsTo(SideType.CLIENT);
ArgumentAcceptingOptionSpec<String> versionO = parser.acceptsAll(of("v", "ver", "version"), "Version to " +
"deobfuscate/decompile. Only works on Proguard mappings or downloading libraries for the decompiler.")
.requiredIf(sideTypeO).withRequiredArg();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private static <M extends Mapping, C extends ClassifiedMapping<M>> void test(Pat
try (var reader = Files.newBufferedReader(path)) {
var c2 = format.read(reader);
// c1.classes.stream().collect(Collectors.toMap(cm -> cm.mapping.getUnmappedName(), Function.identity()));
// assertEquals(c1, c2);// FIXME: How to assert equals mappings?
// assertEquals(c1, c2);// FIXME: How to assertEquals mappings?
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,8 @@

package cn.maxpixel.mcdecompiler.test;

import cn.maxpixel.mcdecompiler.mapping.PairedMapping;
import cn.maxpixel.mcdecompiler.mapping.collection.ClassMapping;
import cn.maxpixel.mcdecompiler.mapping.collection.ClassifiedMapping;
import cn.maxpixel.mcdecompiler.mapping.component.Descriptor;
import cn.maxpixel.mcdecompiler.mapping.remapper.ClassifiedMappingRemapper;
import cn.maxpixel.mcdecompiler.mapping.util.MappingUtil;
import cn.maxpixel.rewh.logging.LogManager;
import cn.maxpixel.rewh.logging.Logger;
import org.jetbrains.annotations.NotNull;

public class FunctionTest {
private static final Logger LOGGER = LogManager.getLogger();
Expand Down Expand Up @@ -146,46 +139,46 @@ public static void main(String[] args) throws Throwable {
// MappingFormats.SRG.write(MappingFormats.TSRG_V1.read(in), out);
// }
}

private static void process(ClassifiedMapping<PairedMapping> src, ClassifiedMappingRemapper int2obf, ClassifiedMappingRemapper obf2srg,
ClassifiedMappingRemapper srg2moj, ClassifiedMapping<PairedMapping> out, String fileName) {
for (var cm : src.classes) {
String intClassName = cm.mapping.mappedName;
String obfClassName = int2obf.mapClass(intClassName);
if (obfClassName == null) {
LOGGER.warn("[{}] missing intermediary entry {}", fileName, intClassName);
obfClassName = intClassName;
}
String srgClassName = obf2srg.mapClassOrDefault(obfClassName);
ClassMapping<PairedMapping> outClass = new ClassMapping<>(
new PairedMapping(srg2moj.mapClassOrDefault(srgClassName), srgClassName)
);
for (@NotNull PairedMapping field : cm.getFields()) {
String obfFieldName = int2obf.mapField(intClassName, field.mappedName);
if (obfFieldName == null) {
LOGGER.warn("[{}] missing intermediary entry {}", fileName, field.mappedName);
obfFieldName = field.mappedName;
}
String srgFieldName = obf2srg.mapFieldOrDefault(obfClassName, obfFieldName);
outClass.addField(MappingUtil.Paired.o(srg2moj.mapFieldOrDefault(srgClassName, srgFieldName), srgFieldName));
}
for (@NotNull PairedMapping method : cm.getMethods()) {
String srgMethodDesc = method.getComponent(Descriptor.class).unmappedDescriptor;
String obfMethodDesc = obf2srg.unmapMethodDesc(srgMethodDesc);
String intMethodDesc = int2obf.unmapMethodDesc(obfMethodDesc);
String obfMethodName = int2obf.mapMethod(intClassName, method.mappedName, intMethodDesc);
if (obfMethodName == null) {
LOGGER.warn("[{}] missing intermediary entry {}", fileName, method.mappedName);
obfMethodName = method.mappedName;
}
String srgMethodName = obf2srg.mapMethodOrDefault(obfClassName, obfMethodName, obfMethodDesc);
outClass.addMethod(MappingUtil.Paired.duo(srg2moj.mapMethodOrDefault(srgClassName, srgMethodName, srgMethodDesc),
srgMethodName, srg2moj.mapMethodDesc(srgMethodDesc)));
}
out.classes.add(outClass);
}
}

//
// private static void process(ClassifiedMapping<PairedMapping> src, ClassifiedMappingRemapper int2obf, ClassifiedMappingRemapper obf2srg,
// ClassifiedMappingRemapper srg2moj, ClassifiedMapping<PairedMapping> out, String fileName) {
// for (var cm : src.classes) {
// String intClassName = cm.mapping.mappedName;
// String obfClassName = int2obf.mapClass(intClassName);
// if (obfClassName == null) {
// LOGGER.warn("[{}] missing intermediary entry {}", fileName, intClassName);
// obfClassName = intClassName;
// }
// String srgClassName = obf2srg.mapClassOrDefault(obfClassName);
// ClassMapping<PairedMapping> outClass = new ClassMapping<>(
// new PairedMapping(srg2moj.mapClassOrDefault(srgClassName), srgClassName)
// );
// for (@NotNull PairedMapping field : cm.getFields()) {
// String obfFieldName = int2obf.mapField(intClassName, field.mappedName);
// if (obfFieldName == null) {
// LOGGER.warn("[{}] missing intermediary entry {}", fileName, field.mappedName);
// obfFieldName = field.mappedName;
// }
// String srgFieldName = obf2srg.mapFieldOrDefault(obfClassName, obfFieldName);
// outClass.addField(MappingUtil.Paired.o(srg2moj.mapFieldOrDefault(srgClassName, srgFieldName), srgFieldName));
// }
// for (@NotNull PairedMapping method : cm.getMethods()) {
// String srgMethodDesc = method.getComponent(Descriptor.class).unmappedDescriptor;
// String obfMethodDesc = obf2srg.unmapMethodDesc(srgMethodDesc);
// String intMethodDesc = int2obf.unmapMethodDesc(obfMethodDesc);
// String obfMethodName = int2obf.mapMethod(intClassName, method.mappedName, intMethodDesc);
// if (obfMethodName == null) {
// LOGGER.warn("[{}] missing intermediary entry {}", fileName, method.mappedName);
// obfMethodName = method.mappedName;
// }
// String srgMethodName = obf2srg.mapMethodOrDefault(obfClassName, obfMethodName, obfMethodDesc);
// outClass.addMethod(MappingUtil.Paired.duo(srg2moj.mapMethodOrDefault(srgClassName, srgMethodName, srgMethodDesc),
// srgMethodName, srg2moj.mapMethodDesc(srgMethodDesc)));
// }
// out.classes.add(outClass);
// }
// }
//
// private enum MCP implements MappingFormat.Unique<PairedMapping> {
// INSTANCE;
// @Override
Expand Down

0 comments on commit 6a7e915

Please sign in to comment.