aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/mixins/init/SkyhanniMixinPlugin.java132
-rw-r--r--src/main/resources/mixins.skyhanni.json38
2 files changed, 134 insertions, 36 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/init/SkyhanniMixinPlugin.java b/src/main/java/at/hannibal2/skyhanni/mixins/init/SkyhanniMixinPlugin.java
new file mode 100644
index 000000000..17cfb45e6
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/mixins/init/SkyhanniMixinPlugin.java
@@ -0,0 +1,132 @@
+package at.hannibal2.skyhanni.mixins.init;
+
+import org.spongepowered.asm.lib.tree.ClassNode;
+import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
+import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Stream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+public class SkyhanniMixinPlugin implements IMixinConfigPlugin {
+ @Override
+ public void onLoad(String s) {
+
+ }
+
+ @Override
+ public String getRefMapperConfig() {
+ return null;
+ }
+
+ @Override
+ public boolean shouldApplyMixin(String s, String s1) {
+ return false;
+ }
+
+ @Override
+ public void acceptTargets(Set<String> set, Set<String> set1) {
+
+ }
+
+ public URL baseUrl(URL classUrl) {
+ String string = classUrl.toString();
+ if (classUrl.getProtocol().equals("jar")) {
+ try {
+ return new URL(string.substring(4).split("\\!")[0]);
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ if (string.endsWith(".class")) {
+ try {
+ return new URL(string.replace("\\", "/")
+ .replace(getClass().getCanonicalName().replace(".", "/") + ".class", ""));
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return classUrl;
+ }
+
+ String mixinBasePackage = "at.hannibal2.skyhanni.mixins.transformers.";
+ String mixinBaseDir = mixinBasePackage.replace(".", "/");
+
+ List<String> mixins = null;
+
+ public void tryAddMixinClass(String className) {
+ String norm = (className.endsWith(".class") ? className.substring(0, className.length() - ".class".length()) : className)
+ .replace("\\", "/")
+ .replace("/", ".");
+ if (norm.startsWith(mixinBasePackage) && !norm.endsWith(".")) {
+ mixins.add(norm.substring(mixinBasePackage.length()));
+ }
+ }
+
+ public void walkDir(Path file) {
+ System.out.println("Trying to find mixins from directory");
+ try (Stream<Path> classes = Files.walk(file.resolve(mixinBaseDir))) {
+ classes.map(it -> file.relativize(it).toString())
+ .forEach(this::tryAddMixinClass);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public List<String> getMixins() {
+ if (mixins != null) return mixins;
+ System.out.println("Trying to discover mixins");
+ mixins = new ArrayList<>();
+ URL classUrl = getClass().getProtectionDomain().getCodeSource().getLocation();
+ System.out.println("Found classes at " + classUrl);
+ Path file;
+ try {
+ file = Paths.get(baseUrl(classUrl).toURI());
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ System.out.println("Base directory found at " + file);
+ if (Files.isDirectory(file)) {
+ walkDir(file);
+ } else {
+ walkJar(file);
+ }
+ System.out.println("Found mixins: " + mixins);
+
+ return mixins;
+ }
+
+ private void walkJar(Path file) {
+ System.out.println("Trying to find mixins from jar file");
+ try (ZipInputStream zis = new ZipInputStream(Files.newInputStream(file))) {
+ ZipEntry next;
+ while ((next = zis.getNextEntry()) != null) {
+ tryAddMixinClass(next.getName());
+ zis.closeEntry();
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void preApply(String s, ClassNode classNode, String s1, IMixinInfo iMixinInfo) {
+
+ }
+
+ @Override
+ public void postApply(String s, ClassNode classNode, String s1, IMixinInfo iMixinInfo) {
+
+ }
+}
diff --git a/src/main/resources/mixins.skyhanni.json b/src/main/resources/mixins.skyhanni.json
index aa1b61873..3b1770fe6 100644
--- a/src/main/resources/mixins.skyhanni.json
+++ b/src/main/resources/mixins.skyhanni.json
@@ -1,43 +1,9 @@
{
"package": "at.hannibal2.skyhanni.mixins.transformers",
"refmap": "mixins.skyhanni.refmap.json",
+ "plugin": "at.hannibal2.skyhanni.mixins.init.SkyhanniMixinPlugin",
"compatibilityLevel": "JAVA_8",
"injectors": {
"maxShiftBy": 2
- },
- "mixins": [
- "AccessorChatComponentText",
- "AccessorGuiPlayerTabOverlay",
- "MixinBlockFire",
- "MixinEntityBlaze",
- "MixinEntityEnderman",
- "MixinEntityFireball",
- "MixinEntityPlayerSP",
- "MixinItemStack",
- "MixinNetHandlerPlayClient",
- "MixinNetworkManager",
- "MixinPatcherFontRendererHook",
- "MixinRendererLivingEntity",
- "MixinRenderGlobal",
- "MixinRenderItem",
- "MixinRenderManager",
- "gui.AccessorGuiContainer",
- "gui.MixinGuiContainer",
- "renderer.MixinRendererLivingEntity"
- ],
- "client": [
- "AccessorFontRenderer",
- "AccessorGuiEditSign",
- "AccessorKeyBinding",
- "AccessorMinecraft",
- "CustomRenderGlobal",
- "MixinEntityRenderer",
- "MixinFontRenderer",
- "MixinGuiChat",
- "MixinGuiIngame",
- "MixinGuiPlayerTabOverlay",
- "MixinKeyBinding",
- "gui.MixinGuiNewChat",
- "gui.MixinGuiScreen"
- ]
+ }
}