aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gq/malwarefight/nosession/tweaks/CleanupTweaker.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gq/malwarefight/nosession/tweaks/CleanupTweaker.java')
-rw-r--r--src/main/java/gq/malwarefight/nosession/tweaks/CleanupTweaker.java82
1 files changed, 0 insertions, 82 deletions
diff --git a/src/main/java/gq/malwarefight/nosession/tweaks/CleanupTweaker.java b/src/main/java/gq/malwarefight/nosession/tweaks/CleanupTweaker.java
deleted file mode 100644
index 6deeeb0..0000000
--- a/src/main/java/gq/malwarefight/nosession/tweaks/CleanupTweaker.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package gq.malwarefight.nosession.tweaks;
-
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
-import net.minecraft.launchwrapper.ITweaker;
-import net.minecraft.launchwrapper.Launch;
-import net.minecraft.launchwrapper.LaunchClassLoader;
-import net.minecraftforge.fml.common.asm.ASMTransformerWrapper;
-
-import java.io.File;
-import java.lang.reflect.*;
-import java.net.URL;
-import java.net.URLStreamHandler;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import gq.malwarefight.nosession.utils.Utils;
-
-public class CleanupTweaker implements ITweaker {
- /**
- * Cached to avoid expensive reflection operations
- */
- public Method makeWrapper;
-
- public CleanupTweaker() throws NoSuchMethodException {
- makeWrapper = ASMTransformerWrapper.class.getDeclaredMethod("makeWrapper", String.class);
- makeWrapper.setAccessible(true);
- }
- @Override
- @SuppressWarnings("unchecked")
- public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
- // add the FMLTweaker
- ArrayList<String> tweakerList = (ArrayList<String>) Launch.blackboard.get("TweakClasses");
- tweakerList.add("net.minecraftforge.fml.common.launcher.FMLTweaker");
- // reset ASMTransformerWrapper
- Class<ASMTransformerWrapper> cls = ASMTransformerWrapper.class;
- try {
- Utils.setStaticValue(cls, "wrapperModMap", new HashMap<String, String>());
- Utils.setStaticValue(cls, "wrapperParentMap", new HashMap<String, String>());
- Utils.setStaticValue(cls, "wrapperCache", CacheBuilder.newBuilder().maximumSize(30L).weakValues().build(new CacheLoader<String, byte[]>() {
- public byte[] load(String file) throws Exception {
- return (byte[]) makeWrapper.invoke(null, file);
- }
- }));
- Utils.setStaticValue(cls, "asmGenRoot", new URL("asmgen", null, -1, "/", getAsmGenHandler()));
- Utils.setStaticValue(cls, "injected", false);
- } catch (Exception e) {
- System.err.println("NoSession: Fixing ASMTransformerWrapper failed. Things may break.");
- e.printStackTrace();
- }
- }
-
- @Override
- public void injectIntoClassLoader(LaunchClassLoader classLoader) {}
-
- @Override
- public String getLaunchTarget() {
- return "net.minecraft.client.main.Main";
- }
-
- @Override
- public String[] getLaunchArguments() {
- return new String[0];
- }
-
-
-
- @SuppressWarnings("unchecked")
- private URLStreamHandler getAsmGenHandler() throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
- Class<ASMTransformerWrapper> cls = ASMTransformerWrapper.class;
- for (Class<?> candidate: cls.getDeclaredClasses()) {
- if (candidate.getSimpleName().equals("ASMGenHandler")) {
- Method pgdc = Class.class.getDeclaredMethod("privateGetDeclaredConstructors", boolean.class);
- pgdc.setAccessible(true);
- Constructor<? extends URLStreamHandler> constructor = ((Constructor<? extends URLStreamHandler>[]) pgdc.invoke(candidate, false))[0];
- constructor.setAccessible(true);
- return constructor.newInstance();
- }
- }
- throw new RuntimeException("NoSession: unable to get the ASMGenHandler");
- }
-}