Search in sources :

Example 1 with ChainingTransformer

use of net.md_5.specialsource.transformer.ChainingTransformer in project SpecialSource by md-5.

the class JarMapping method loadMappingsDir.

/**
 * Load mappings from an MCP directory
 *
 * @param dirname MCP directory name, local file or remote URL ending in '/'
 * @param reverse If true, swap input and output
 * @param ignoreCsv If true, ignore fields.csv and methods.csv (but not
 * packages.csv)
 * @param numericSrgNames If true, load numeric "srg" names (num->mcp
 * instead of obf->mcp)
 */
private void loadMappingsDir(String dirname, boolean reverse, boolean ignoreCsv, boolean numericSrgNames) throws IOException {
    File dir = new File(dirname);
    if (!FileLocator.isHTTPURL(dirname) && !dir.isDirectory()) {
        throw new IllegalArgumentException("loadMappingsDir(" + dir + "): not a directory");
    }
    String sep = System.getProperty("file.separator");
    List<File> srgFiles = new ArrayList<File>();
    File joinedSrg = FileLocator.getFile(dirname + sep + "joined.srg");
    if (joinedSrg.exists()) {
        // FML/MCP client/server joined
        srgFiles.add(joinedSrg);
    } else {
        // vanilla MCP separated sides
        File serverSrg = FileLocator.getFile(dirname + sep + "server.srg");
        File clientSrg = FileLocator.getFile(dirname + sep + "client.srg");
        if (serverSrg.exists()) {
            srgFiles.add(serverSrg);
        }
        if (clientSrg.exists()) {
            srgFiles.add(clientSrg);
        }
    }
    if (srgFiles.size() == 0) {
        throw new IOException("loadMappingsDir(" + dirname + "): no joined.srg, client.srg, or server.srg found");
    }
    // Read output names through csv mappings, if available & enabled
    File fieldsCsv = FileLocator.getFile(dirname + sep + "fields.csv");
    File methodsCsv = FileLocator.getFile(dirname + sep + "methods.csv");
    // FML repackaging, optional
    File packagesCsv = FileLocator.getFile(dirname + sep + "packages.csv");
    MinecraftCodersPack outputTransformer;
    MappingTransformer inputTransformer;
    if (numericSrgNames) {
        // Wants numeric "srg" names -> descriptive "csv" names. To accomplish this:
        // 1. load obf->mcp (descriptive "csv") as chainMappings
        // 2. load again but chaining input (obf) through mcp, and ignoring csv on output
        // 3. result: mcp->srg, similar to MCP ./reobfuscate --srgnames
        JarMapping chainMappings = new JarMapping();
        chainMappings.loadMappingsDir(dirname, reverse, false, /*ignoreCsv*/
        false);
        inputTransformer = new ChainingTransformer(new JarRemapper(chainMappings));
        // keep numeric srg as output
        ignoreCsv = true;
    } else {
        inputTransformer = null;
    }
    if (fieldsCsv.exists() && methodsCsv.exists()) {
        outputTransformer = new MinecraftCodersPack(ignoreCsv ? null : fieldsCsv, ignoreCsv ? null : methodsCsv, packagesCsv);
    } else {
        outputTransformer = null;
    }
    for (File srg : srgFiles) {
        loadMappings(new BufferedReader(new FileReader(srg)), inputTransformer, outputTransformer, reverse);
    }
}
Also used : MinecraftCodersPack(net.md_5.specialsource.transformer.MinecraftCodersPack) MappingTransformer(net.md_5.specialsource.transformer.MappingTransformer) ChainingTransformer(net.md_5.specialsource.transformer.ChainingTransformer)

Aggregations

ChainingTransformer (net.md_5.specialsource.transformer.ChainingTransformer)1 MappingTransformer (net.md_5.specialsource.transformer.MappingTransformer)1 MinecraftCodersPack (net.md_5.specialsource.transformer.MinecraftCodersPack)1