Skip to content

Commit

Permalink
Simplify previous fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LunNova committed May 22, 2017
1 parent 5d3ae56 commit c15a62d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public static String untransformName(String name) {
public static void removeRedundantExclusions() {
removeRedundantExclusions(getTransformerExceptions());
removeRedundantExclusions(getClassLoaderExceptions());
getClassLoaderExceptions().removeIf(it -> it.startsWith("org.minimallycorrect.modpatcher"));
}

static void removeRedundantExclusions(Set<String> transformerExceptions) {
Expand All @@ -251,8 +252,4 @@ public static void releaseSrgBytes(String transformedName) {
cachedSrgClasses.remove(transformedName);
ModPatcherTransformer.pool.dropCache(transformedName, true);
}

public static void removeClassLoaderExclusions(String name) {
classLoaderExceptions.removeIf(it -> it.startsWith(name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ static void initialiseClassLoader(LaunchClassLoader classLoader) {
classLoader.addTransformerExclusion("javassist");
classLoader.addTransformerExclusion("com.github.javaparser");
LaunchClassLoaderUtil.addTransformer(ModPatcherTransformer.getInstance());
LaunchClassLoaderUtil.removeRedundantExclusions();
}

static String getDefaultPatchesDirectory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,23 @@
import net.minecraft.launchwrapper.ITweaker;
import net.minecraft.launchwrapper.Launch;
import net.minecraft.launchwrapper.LaunchClassLoader;
import org.minimallycorrect.modpatcher.api.LaunchClassLoaderUtil;
import org.minimallycorrect.modpatcher.api.ModPatcherTransformer;
import org.minimallycorrect.modpatcher.api.PatcherLog;

import java.io.*;
import java.lang.reflect.*;
import java.util.*;

/**
* Tries to ensure that our transformer is last
*/
public class ModPatcherTweaker implements ITweaker {
@SuppressWarnings("unchecked")
public static void add() {
((List<String>) Launch.blackboard.get("TweakClasses")).add(ModPatcherTweaker.class.getName());
}

private static void inject() {
LaunchClassLoaderUtil.addTransformer(ModPatcherTransformer.getInstance());
try {
Class<?> mixinEnvironmentClass = Class.forName("org.spongepowered.asm.mixin.MixinEnvironment", false, ModPatcherTweaker.class.getClassLoader());
Field f = mixinEnvironmentClass.getDeclaredField("excludeTransformers");
f.setAccessible(true);
@SuppressWarnings("unchecked")
Set<String> vals = (Set<String>) f.get(null);
vals.add(ModPatcherTransformer.class.getName());
} catch (ClassNotFoundException ignored) {
// TODO Silence this once confirmed working?
PatcherLog.trace("Failed to find mixin environment, normal for non-spongepowered", ignored);
} catch (NoSuchFieldException | IllegalAccessException e) {
PatcherLog.warn("Failed to add mixin transformer exclusion for our transformer", e);
}
}

@Override
public void acceptOptions(List<String> list, File file, File file1, String s) {
LaunchClassLoaderUtil.removeClassLoaderExclusions("org.minimallycorrect.modpatcher");
ModPatcherTweaker2.add();
}

@Override
public void injectIntoClassLoader(LaunchClassLoader launchClassLoader) {
inject();
}

@Override
Expand All @@ -55,7 +29,6 @@ public String getLaunchTarget() {

@Override
public String[] getLaunchArguments() {
inject();
return new String[0];
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,57 @@
package org.minimallycorrect.modpatcher.api.tweaker;

import net.minecraft.launchwrapper.ITweaker;
import net.minecraft.launchwrapper.Launch;
import net.minecraft.launchwrapper.LaunchClassLoader;
import org.minimallycorrect.modpatcher.api.LaunchClassLoaderUtil;
import org.minimallycorrect.modpatcher.api.ModPatcherTransformer;
import org.minimallycorrect.modpatcher.api.PatcherLog;

import java.io.*;
import java.lang.reflect.*;
import java.util.*;

public class ModPatcherTweaker2 extends ModPatcherTweaker {
public class ModPatcherTweaker2 implements ITweaker {
@SuppressWarnings("unchecked")
public static void add() {
((List<String>) Launch.blackboard.get("TweakClasses")).add(ModPatcherTweaker2.class.getName());
}

private static void inject() {
LaunchClassLoaderUtil.addTransformer(ModPatcherTransformer.getInstance());
try {
Class<?> mixinEnvironmentClass = Class.forName("org.spongepowered.asm.mixin.MixinEnvironment", false, ModPatcherTweaker.class.getClassLoader());
Field f = mixinEnvironmentClass.getDeclaredField("excludeTransformers");
f.setAccessible(true);
@SuppressWarnings("unchecked")
Set<String> vals = (Set<String>) f.get(null);
vals.add(ModPatcherTransformer.class.getName());
} catch (ClassNotFoundException ignored) {
// TODO Silence this once confirmed working?
PatcherLog.trace("Failed to find mixin environment, normal for non-spongepowered", ignored);
} catch (NoSuchFieldException | IllegalAccessException e) {
PatcherLog.warn("Failed to add mixin transformer exclusion for our transformer", e);
}
}

@Override
public void acceptOptions(List<String> list, File file, File file1, String s) {
LaunchClassLoaderUtil.removeClassLoaderExclusions("org.minimallycorrect.modpatcher");
}

@Override
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
}

@Override
public String getLaunchTarget() {
throw new UnsupportedOperationException("ModPatcherTweaker is not a primary tweaker.");
}

@Override
public String[] getLaunchArguments() {
inject();
LaunchClassLoaderUtil.dumpTransformersIfEnabled();
return super.getLaunchArguments();
LaunchClassLoaderUtil.removeRedundantExclusions();
return new String[0];
}
}

0 comments on commit c15a62d

Please sign in to comment.