Skip to content

Commit

Permalink
Reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
LunNova committed Jan 4, 2016
1 parent 3eb9963 commit a9be665
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 77 deletions.
8 changes: 4 additions & 4 deletions src/main/java/me/nallar/modpatcher/CoreMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
@IFMLLoadingPlugin.Name("ModPatcher")
@IFMLLoadingPlugin.SortingIndex(1001) // Magic value, after deobf transformer.
public class CoreMod implements IFMLLoadingPlugin {
static {
logToFile();
}

private static void logToFile() {
FileAppender fa = FileAppender.createAppender("./logs/ModPatcher.log", "false", "false", "PatcherAppender", "true", "true", "true", null, null, "false", null, null);
fa.start();
((org.apache.logging.log4j.core.Logger) LogManager.getLogger("ModPatcher")).addAppender(fa);
((org.apache.logging.log4j.core.Logger) LogManager.getLogger("JavaPatcher")).addAppender(fa);
}

static {
logToFile();
}

@Override
public String[] getASMTransformerClass() {
return new String[0];
Expand Down
18 changes: 7 additions & 11 deletions src/main/java/me/nallar/modpatcher/LaunchClassLoaderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@

public enum LaunchClassLoaderUtil {
;
public static final String AFTER_TRANSFORMER_NAME = "cpw.mods.fml.common.asm.transformers.DeobfuscationTransformer";
private static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("legacy.debugClassLoading", "false"));
private static final boolean DEBUG_FINER = DEBUG && Boolean.parseBoolean(System.getProperty("legacy.debugClassLoadingFiner", "false"));
private static final String ALREADY_LOADED_PROPERTY_NAME = "nallar.LaunchClassLoaderUtil.alreadyLoaded";
public static final String AFTER_TRANSFORMER_NAME = "cpw.mods.fml.common.asm.transformers.DeobfuscationTransformer";
private static final HashMap<String, byte[]> cachedSrgClasses = new HashMap<String, byte[]>();
static LaunchClassLoader instance;

private static List<IClassTransformer> transformers;
private static IClassNameTransformer renameTransformer;
private static Set<String> classLoaderExceptions;

static {
boolean alreadyLoaded = System.getProperty(ALREADY_LOADED_PROPERTY_NAME) != null;
Expand All @@ -27,10 +33,6 @@ public enum LaunchClassLoaderUtil {
}
}

static LaunchClassLoader instance;

private static List<IClassTransformer> transformers;

public static List<IClassTransformer> getTransformers() {
if (transformers != null) {
return transformers;
Expand All @@ -51,8 +53,6 @@ public static LaunchClassLoader getInstance() {
throw new Error("Tried to retrieve LaunchClassLoader instance before setting up the transformer");
}

private static IClassNameTransformer renameTransformer;

private static IClassNameTransformer getRenameTransformer() {
if (renameTransformer != null) {
return renameTransformer;
Expand All @@ -66,8 +66,6 @@ private static IClassNameTransformer getRenameTransformer() {
}
}

private static Set<String> classLoaderExceptions;

private static Set<String> getClassLoaderExceptions() {
if (classLoaderExceptions != null) {
return classLoaderExceptions;
Expand All @@ -90,8 +88,6 @@ public static boolean excluded(String name) {
return false;
}

private static final HashMap<String, byte[]> cachedSrgClasses = new HashMap<String, byte[]>();

@SuppressWarnings("ConstantConditions")
private static byte[] runTransformer(final String name, final String transformedName, byte[] basicClass, final IClassTransformer transformer) {
try {
Expand Down
78 changes: 36 additions & 42 deletions src/main/java/me/nallar/modpatcher/ModPatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,18 @@
import me.nallar.modpatcher.mappings.MCPMappings;
import net.minecraft.launchwrapper.IClassTransformer;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.io.*;
import java.nio.file.*;

public class ModPatcher implements IClassTransformer {
/**
* Gets the JavaPatcher Patcher instance
*
* @return the Patcher
*/
public static Patcher getPatcher() {
return postSrgPatcher;
}

/**
* Gets the name of the setup class to use in your IFMLLoadingPlugin
*
* @return Name of the ModPatcher setup class
*/
public static String getSetupClass() {
return "me.nallar.modpatcher.ModPatcherSetupClass";
}

public static final String MOD_PATCHES_DIRECTORY = "./ModPatches/";
public static final String MOD_PATCHES_SRG_DIRECTORY = "./ModPatchesSrg/";
private static final Patcher preSrgPatcher;
private static final Patcher postSrgPatcher;
private static final String ALREADY_LOADED_PROPERTY_NAME = "nallar.ModPatcher.alreadyLoaded";
private static final String DUMP_PROPERTY_NAME = "nallar.ModPatcher.dump";
private static final boolean DUMP = !System.getProperty(DUMP_PROPERTY_NAME, "").isEmpty();

public static final String MOD_PATCHES_DIRECTORY = "./ModPatches/";
public static final String MOD_PATCHES_SRG_DIRECTORY = "./ModPatchesSrg/";

static {
PatcherLog.info("ModPatcher running under classloader " + ModPatcher.class.getClassLoader().getClass().getName());
boolean alreadyLoaded = System.getProperty(ALREADY_LOADED_PROPERTY_NAME) != null;
Expand All @@ -66,6 +42,26 @@ public static String getSetupClass() {
recursivelyAddXmlFiles(new File(MOD_PATCHES_DIRECTORY), postSrgPatcher);
}

private boolean init;

/**
* Gets the JavaPatcher Patcher instance
*
* @return the Patcher
*/
public static Patcher getPatcher() {
return postSrgPatcher;
}

/**
* Gets the name of the setup class to use in your IFMLLoadingPlugin
*
* @return Name of the ModPatcher setup class
*/
public static String getSetupClass() {
return "me.nallar.modpatcher.ModPatcherSetupClass";
}

private static void recursivelyAddXmlFiles(File directory, Patcher patcher) {
if (!directory.isDirectory()) {
return;
Expand Down Expand Up @@ -108,7 +104,18 @@ public static byte[] postSrgTransformationHook(String name, String transformedNa
return originalBytes;
}

private boolean init;
static void modPatcherAsCoreModStartup() {
File modPatchesDirectory = new File(MOD_PATCHES_DIRECTORY);
if (!modPatchesDirectory.exists()) {
modPatchesDirectory.mkdir();
try {
Files.copy(ModPatcher.class.getResourceAsStream("/modpatcher.json.example"), new File(modPatchesDirectory, "/modpatcher.json.example").toPath(), StandardCopyOption.REPLACE_EXISTING);
Files.copy(ModPatcher.class.getResourceAsStream("/modpatcher.xml.example"), new File(modPatchesDirectory, "/modpatcher.xml.example").toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
PatcherLog.warn("Failed to extract example patcher files", e);
}
}
}

@Override
public byte[] transform(String name, String transformedName, byte[] bytes) {
Expand All @@ -127,17 +134,4 @@ public byte[] transform(String name, String transformedName, byte[] bytes) {
}
return postSrgTransformationHook(name, transformedName, bytes);
}

static void modPatcherAsCoreModStartup() {
File modPatchesDirectory = new File(MOD_PATCHES_DIRECTORY);
if (!modPatchesDirectory.exists()) {
modPatchesDirectory.mkdir();
try {
Files.copy(ModPatcher.class.getResourceAsStream("/modpatcher.json.example"), new File(modPatchesDirectory, "/modpatcher.json.example").toPath(), StandardCopyOption.REPLACE_EXISTING);
Files.copy(ModPatcher.class.getResourceAsStream("/modpatcher.xml.example"), new File(modPatchesDirectory, "/modpatcher.xml.example").toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
PatcherLog.warn("Failed to extract example patcher files", e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private void initialised(LaunchClassLoader classLoader) {
i++;
if (!foundDeobfuscationTransformer) {
PatcherLog.warn("Didn't find deobfuscation transformer " + LaunchClassLoaderUtil.AFTER_TRANSFORMER_NAME + " in transformers list.\n" +
"Did you forget to set the SortingIndex for your coremod >= 1001? This message is expected in a deobf environment.");
"Did you forget to set the SortingIndex for your coremod >= 1001? This message is expected in a deobf environment.");
modPatcherInitialised = false;
return;
}
Expand Down
38 changes: 19 additions & 19 deletions src/main/java/me/nallar/modpatcher/mappings/MCPMappings.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ public MCPMappings(boolean seargeMappings) throws IOException {
}
}*/

private static void loadCsv(InputStream mappingsCsv, Map<String, String> seargeMappings) throws IOException {
Scanner in = new Scanner(mappingsCsv);
try {
in.useDelimiter(",");
while (in.hasNextLine()) {
String seargeName = in.next();
String name = in.next();
String side = in.next();
in.nextLine();
if ("2".equals(side) || "0".equals(side)) { // 2 = joined 'side'.
seargeMappings.put(seargeName, name);
}
}
} finally {
in.close();
}
mappingsCsv.close();
}

private Map<String, List<String>> loadExtends(InputStream resourceAsStream) throws IOException {
ObjectInputStream objectInputStream = new ObjectInputStream(resourceAsStream);
try {
Expand Down Expand Up @@ -250,23 +269,4 @@ private void recursiveExtendFieldMappings(FieldDescription deobfuscatedField, Fi
recursiveExtendFieldMappings(newDeobf, newSrgField);
}
}

private static void loadCsv(InputStream mappingsCsv, Map<String, String> seargeMappings) throws IOException {
Scanner in = new Scanner(mappingsCsv);
try {
in.useDelimiter(",");
while (in.hasNextLine()) {
String seargeName = in.next();
String name = in.next();
String side = in.next();
in.nextLine();
if ("2".equals(side) || "0".equals(side)) { // 2 = joined 'side'.
seargeMappings.put(seargeName, name);
}
}
} finally {
in.close();
}
mappingsCsv.close();
}
}

0 comments on commit a9be665

Please sign in to comment.