-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
36 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 35 additions & 3 deletions
38
src/main/java/org/minimallycorrect/modpatcher/api/tweaker/ModPatcherTweaker2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} |