Skip to content

Commit

Permalink
Merge pull request #4 from Chocohead/moderniser
Browse files Browse the repository at this point in the history
1.13.1 Port
  • Loading branch information
Runemoro authored Nov 9, 2018
2 parents 3986a9c + b3951bc commit 70d441a
Show file tree
Hide file tree
Showing 14 changed files with 364 additions and 246 deletions.
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ dependencies {
compile 'com.nothome:javaxdelta:2.0.1' // GDIFF implementation for BinPatches
compile 'com.google.code.gson:gson:2.2.4' // Used instead of Argo for buuilding changelog.
compile 'com.github.tony19:named-regexp:0.2.3' // 1.7 Named regexp features
compile 'net.minecraftforge:forgeflower:1.0.342-SNAPSHOT' // Fernflower Forge edition
compile 'net.minecraftforge:forgeflower:1.5.380.22' // Fernflower Forge edition

shade 'net.md-5:SpecialSource:1.8.2' // deobf and reobf
shade 'net.md-5:SpecialSource:1.8.3' // deobf and reobf

// because curse
compile 'org.apache.httpcomponents:httpclient:4.3.3'
compile 'org.apache.httpcomponents:httpmime:4.3.3'

// mcp stuff
shade 'de.oceanlabs.mcp:RetroGuard:3.6.6'
shade('de.oceanlabs.mcp:mcinjector:3.4-SNAPSHOT'){
shade('de.oceanlabs.mcp:mcinjector:3.7.3'){
exclude group: 'org.ow2.asm', module: 'asm-debug-all'
}
shade('net.minecraftforge.srg2source:Srg2Source:4.0-SNAPSHOT'){
Expand All @@ -94,7 +94,7 @@ dependencies {

//Stuff used in the GradleStart classes
compileOnly 'com.mojang:authlib:1.5.16'
compileOnly('net.minecraft:launchwrapper:1.11'){
compileOnly('net.minecraft:launchwrapper:1.12'){
exclude group: 'org.ow2.asm', module: 'asm-debug-all'
}

Expand Down Expand Up @@ -214,7 +214,7 @@ pluginBundle {
uploadArchives {
repositories.mavenDeployer {

dependsOn 'build'
dependsOn 'jar'

if (project.hasProperty('forgeMavenPass'))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ protected void afterEvaluate()
// ApplyFernFlowerTask ffTask = ((ApplyFernFlowerTask) project.getTasks().getByName("decompileJar"));
// ffTask.setClasspath(javaConv.getSourceSets().getByName("main").getCompileClasspath());

// http://files.minecraftforge.net/maven/de/oceanlabs/mcp/mcp/1.7.10/mcp-1.7.10-srg.zip
// http://files.minecraftforge.net/maven/de/oceanlabs/mcp/mcp_config/1.13.1/mcp_config-1.13.1.zip
project.getDependencies().add(CONFIG_MAPPINGS, ImmutableMap.of(
"group", "de.oceanlabs.mcp",
"name", delayedString("mcp_" + REPLACE_MCP_CHANNEL).call(),
Expand All @@ -233,9 +233,8 @@ protected void afterEvaluate()

project.getDependencies().add(CONFIG_MCP_DATA, ImmutableMap.of(
"group", "de.oceanlabs.mcp",
"name", "mcp",
"name", "mcp_config",
"version", delayedString(REPLACE_MC_VERSION).call(),
"classifier", "srg",
"ext", "zip"
));

Expand Down Expand Up @@ -523,7 +522,7 @@ public String call()
merge.setDescription(null);
}

ExtractConfigTask extractMcpData = makeTask(TASK_EXTRACT_MCP, ExtractConfigTask.class);
ExtractConfigTask extractMcpData = makeTask(TASK_EXTRACT_MCP, ExtractMcpConfigTask.class);
{
extractMcpData.setDestinationDir(delayedFile(DIR_MCP_DATA));
extractMcpData.setConfig(CONFIG_MCP_DATA);
Expand All @@ -540,7 +539,7 @@ public String call()
GenSrgs genSrgs = makeTask(TASK_GENERATE_SRGS, GenSrgs.class);
{
genSrgs.setInSrg(delayedFile(MCP_DATA_SRG));
genSrgs.setInExc(delayedFile(MCP_DATA_EXC));
genSrgs.setInConstructors(delayedFile(MCP_DATA_CONSTRUCTORS));
genSrgs.setInStatics(delayedFile(MCP_DATA_STATICS));
genSrgs.setMethodsCsv(delayedFile(CSV_METHOD));
genSrgs.setFieldsCsv(delayedFile(CSV_FIELD));
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/net/minecraftforge/gradle/common/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,16 @@ public Boolean call(Object o)
};

// mcp data constants
public static final String MCP_DATA_SRG = DIR_MCP_DATA + "/joined.srg";
public static final String MCP_DATA_EXC = DIR_MCP_DATA + "/joined.exc";
public static final String MCP_DATA_EXC_JSON = DIR_MCP_DATA + "/exceptor.json";
public static final String MCP_DATA_STYLE = DIR_MCP_DATA + "/astyle.cfg";
public static final String MCP_DATA_STATICS = DIR_MCP_DATA + "/static_methods.txt";
public static final String MCP_PATCHES_CLIENT = DIR_MCP_DATA + "/patches/minecraft_ff";
public static final String MCP_PATCHES_SERVER = DIR_MCP_DATA + "/patches/minecraft_server_ff";
public static final String MCP_PATCHES_MERGED = DIR_MCP_DATA + "/patches/minecraft_merged_ff";
public static final String MCP_INJECT = DIR_MCP_DATA + "/patches/inject";
public static final String MCP_DATA_SRG = DIR_MCP_DATA + "/config/joined.srg";
public static final String MCP_DATA_STYLE = DIR_MCP_DATA + "/astyle.cfg";
public static final String MCP_DATA_ACCESS = DIR_MCP_DATA + "/config/access.txt";
public static final String MCP_DATA_EXCEPTIONS = DIR_MCP_DATA + "/config/exceptions.txt";
public static final String MCP_DATA_CONSTRUCTORS = DIR_MCP_DATA + "/config/constructors.txt";
public static final String MCP_DATA_STATICS = DIR_MCP_DATA + "/config/static_methods.txt";
public static final String MCP_PATCHES_CLIENT = DIR_MCP_DATA + "/patches/client";
public static final String MCP_PATCHES_SERVER = DIR_MCP_DATA + "/patches/server";
public static final String MCP_PATCHES_MERGED = DIR_MCP_DATA + "/patches/joined";
public static final String MCP_INJECT = DIR_MCP_DATA + "/config/inject";

// generated off of MCP data constants
public static final String CSV_METHOD = DIR_MCP_MAPPINGS + "/methods.csv";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ protected void makeGeneralSetupTasks()
deobfJar.setOutJar(delayedFile(JAR_DEOBF));
deobfJar.setSrg(delayedFile(SRG_NOTCH_TO_SRG));
deobfJar.setExceptorCfg(delayedFile(EXC_SRG));
deobfJar.setExceptorJson(delayedFile(MCP_DATA_EXC_JSON));
deobfJar.setApplyMarkers(true);
deobfJar.setAccessCfg(delayedFile(MCP_DATA_ACCESS));
deobfJar.setConstructorCfg(delayedFile(MCP_DATA_CONSTRUCTORS));
deobfJar.setExceptionsCfg(delayedFile(MCP_DATA_EXCEPTIONS));
deobfJar.setDoesCache(false);
// access transformers are added afterEvaluate
deobfJar.dependsOn(TASK_MERGE_JARS, TASK_GENERATE_SRGS);
Expand Down
216 changes: 43 additions & 173 deletions src/main/java/net/minecraftforge/gradle/tasks/DeobfuscateJar.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,32 @@
import com.google.common.collect.Maps;
import com.google.common.io.Files;
import com.google.common.io.LineProcessor;
import de.oceanlabs.mcp.mcinjector.LVTNaming;
import de.oceanlabs.mcp.mcinjector.MCInjectorImpl;

import de.oceanlabs.mcp.mcinjector.lvt.LVTNaming;
import de.oceanlabs.mcp.mcinjector.MCInjector;

import groovy.lang.Closure;

import net.md_5.specialsource.*;
import net.md_5.specialsource.provider.JarProvider;
import net.md_5.specialsource.provider.JointProvider;

import net.minecraftforge.gradle.common.Constants;
import net.minecraftforge.gradle.util.caching.Cached;
import net.minecraftforge.gradle.util.caching.CachedTask;
import net.minecraftforge.gradle.util.json.JsonFactory;
import net.minecraftforge.gradle.util.json.MCInjectorStruct;
import net.minecraftforge.gradle.util.json.MCInjectorStruct.InnerClass;

import org.gradle.api.file.FileCollection;
import org.gradle.api.tasks.*;
import org.gradle.api.tasks.Optional;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.*;
import java.util.zip.ZipFile;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import static org.objectweb.asm.Opcodes.*;

public class DeobfuscateJar extends CachedTask
{
Expand All @@ -69,10 +71,13 @@ public class DeobfuscateJar extends CachedTask
private Object exceptorCfg;

@InputFile
private Object exceptorJson;

@Input
private boolean applyMarkers = false;
private Object access;

@InputFile
private Object constructors;

@InputFile
private Object exceptions;

@Input
private boolean failOnAtError = true;
Expand Down Expand Up @@ -163,158 +168,22 @@ private void deobfJar(File inJar, File outJar, File srg, Collection<File> ats) t
}
}

private int fixAccess(int access, String target)
{
int ret = access & ~7;
int t = 0;

if (target.startsWith("public"))
t = ACC_PUBLIC;
else if (target.startsWith("private"))
t = ACC_PRIVATE;
else if (target.startsWith("protected"))
t = ACC_PROTECTED;

switch (access & 7)
{
case ACC_PRIVATE:
ret |= t;
break;
case 0:
ret |= (t != ACC_PRIVATE ? t : 0);
break;
case ACC_PROTECTED:
ret |= (t != ACC_PRIVATE && t != 0 ? t : ACC_PROTECTED);
break;
case ACC_PUBLIC:
ret |= ACC_PUBLIC;
break;
}

if (target.endsWith("-f"))
ret &= ~ACC_FINAL;
else if (target.endsWith("+f"))
ret |= ACC_FINAL;
return ret;
}

public void applyExceptor(File inJar, File outJar, File config, File log, Set<File> ats) throws IOException
{
String json = null;
File getJson = getExceptorJson();
if (getJson != null)
{
final Map<String, MCInjectorStruct> struct = JsonFactory.loadMCIJson(getJson);
for (File at : ats)
{
getLogger().info("loading AT: " + at.getCanonicalPath());

Files.readLines(at, Charset.defaultCharset(), new LineProcessor<Object>()
{
@Override
public boolean processLine(String line) throws IOException
{
if (line.indexOf('#') != -1)
line = line.substring(0, line.indexOf('#'));
line = line.trim().replace('.', '/');
if (line.isEmpty())
return true;

String[] s = line.split(" ");
if (s.length == 2 && s[1].indexOf('$') > 0)
{
String parent = s[1].substring(0, s[1].indexOf('$'));
for (MCInjectorStruct cls : new MCInjectorStruct[] { struct.get(parent), struct.get(s[1]) })
{
if (cls != null && cls.innerClasses != null)
{
for (InnerClass inner : cls.innerClasses)
{
if (inner.inner_class.equals(s[1]))
{
int access = fixAccess(inner.getAccess(), s[0]);
inner.access = (access == 0 ? null : Integer.toHexString(access));
}
}
}
}
}

return true;
}

@Override
public Object getResult()
{
return null;
}
});
}

// Remove unknown classes from configuration
removeUnknownClasses(inJar, struct);

File jsonTmp = new File(this.getTemporaryDir(), "transformed.json");
json = jsonTmp.getCanonicalPath();
Files.write(JsonFactory.GSON.toJson(struct).getBytes(), jsonTmp);
}

getLogger().debug("INPUT: " + inJar);
getLogger().debug("OUTPUT: " + outJar);
getLogger().debug("CONFIG: " + config);
getLogger().debug("JSON: " + json);
getLogger().debug("ACCESS: " + getAccessCfg());
getLogger().debug("CONSTRUCTOR: " + getConstructorCfg());
getLogger().debug("EXCEPTION: " + getExceptionsCfg());
getLogger().debug("LOG: " + log);
getLogger().debug("PARAMS: true");

MCInjectorImpl.process(inJar.getCanonicalPath(),
outJar.getCanonicalPath(),
config.getCanonicalPath(),
log.getCanonicalPath(),
null,
0,
json,
isApplyMarkers(),
true,
LVTNaming.LVT
);
}

private void removeUnknownClasses(File inJar, Map<String, MCInjectorStruct> config) throws IOException
{
try (ZipFile zip = new ZipFile(inJar))
{
Iterator<Map.Entry<String, MCInjectorStruct>> entries = config.entrySet().iterator();
while (entries.hasNext())
{
Map.Entry<String, MCInjectorStruct> entry = entries.next();
String className = entry.getKey();

// Verify the configuration contains only classes we actually have
if (zip.getEntry(className + ".class") == null)
{
getLogger().info("Removing unknown class {}", className);
entries.remove();
continue;
}

MCInjectorStruct struct = entry.getValue();

// Verify the inner classes in the configuration actually exist in our deobfuscated JAR file
if (struct.innerClasses != null)
{
Iterator<InnerClass> innerClasses = struct.innerClasses.iterator();
while (innerClasses.hasNext())
{
InnerClass innerClass = innerClasses.next();
if (zip.getEntry(innerClass.inner_class + ".class") == null)
{
getLogger().info("Removing unknown inner class {} from {}", innerClass.inner_class, className);
innerClasses.remove();
}
}
}
}
}
new MCInjector(inJar.toPath(), outJar.toPath()).log(log.toPath())
.access(getAccessCfg().toPath())
.constructors(getConstructorCfg().toPath())
.exceptions(getExceptionsCfg().toPath())
.lvt(LVTNaming.LVT).process();
}

public File getExceptorCfg()
Expand All @@ -327,27 +196,28 @@ public void setExceptorCfg(Object exceptorCfg)
this.exceptorCfg = exceptorCfg;
}

public File getExceptorJson()
{
if (exceptorJson == null)
return null;
else
return getProject().file(exceptorJson);
public File getAccessCfg() {
return getProject().file(access);
}

public void setExceptorJson(Object exceptorJson)
{
this.exceptorJson = exceptorJson;
public void setAccessCfg(Object accessCfg) {
access = accessCfg;
}

public boolean isApplyMarkers()
{
return applyMarkers;
public File getConstructorCfg() {
return getProject().file(constructors);
}

public void setApplyMarkers(boolean applyMarkers)
{
this.applyMarkers = applyMarkers;
public void setConstructorCfg(Object constructorCfg) {
constructors = constructorCfg;
}

public File getExceptionsCfg() {
return getProject().file(exceptions);
}

public void setExceptionsCfg(Object exceptionCfg) {
exceptions = exceptionCfg;
}

public boolean isFailOnAtError()
Expand Down
Loading

0 comments on commit 70d441a

Please sign in to comment.