From e0884c8f6d4a86ba180c648e34ad8be1bf46cd04 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+Alexdoru@users.noreply.github.com> Date: Wed, 11 Oct 2023 19:53:59 +0200 Subject: [PATCH 1/3] clean coremod and stop using COMPUTE_FRAMES which triggers unwanted classloading --- .../txloader/MinecraftClassTransformer.java | 90 +++++++------------ .../glowredman/txloader/MinecraftHook.java | 13 +++ .../glowredman/txloader/TXLoaderCore.java | 11 ++- 3 files changed, 51 insertions(+), 63 deletions(-) create mode 100644 src/main/java/glowredman/txloader/MinecraftHook.java diff --git a/src/main/java/glowredman/txloader/MinecraftClassTransformer.java b/src/main/java/glowredman/txloader/MinecraftClassTransformer.java index 9c60c3f..32af966 100644 --- a/src/main/java/glowredman/txloader/MinecraftClassTransformer.java +++ b/src/main/java/glowredman/txloader/MinecraftClassTransformer.java @@ -1,7 +1,5 @@ package glowredman.txloader; -import java.util.List; - import net.minecraft.launchwrapper.IClassTransformer; import net.minecraft.launchwrapper.Launch; @@ -10,80 +8,52 @@ import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.InsnList; import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode; -import org.objectweb.asm.tree.VarInsnNode; public class MinecraftClassTransformer implements IClassTransformer { @Override public byte[] transform(String name, String transformedName, byte[] basicClass) { - if (!"net.minecraft.client.Minecraft".equals(transformedName)) { - return basicClass; + if ("net.minecraft.client.Minecraft".equals(transformedName)) { + return transformMinecraft(basicClass); } - return transformMinecraft(basicClass); + return basicClass; } private static byte[] transformMinecraft(byte[] basicClass) { - TXLoaderCore.LOGGER.info("Transforming net.minecraft.client.Minecraft"); - boolean devEnv = (boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment"); - - ClassNode classNode = new ClassNode(); - ClassReader classReader = new ClassReader(basicClass); - classReader.accept(classNode, 0); - - // find refreshResources() method - MethodNode targetMethod = null; - final String refreshResourcesName = devEnv ? "refreshResources" : "func_110436_a"; - final String refreshResourcesDesc = "()V"; - - for (MethodNode method : classNode.methods) { - if (method.name.equals(refreshResourcesName) && method.desc.equals(refreshResourcesDesc)) { - targetMethod = method; - break; - } - } - - if (targetMethod == null) throw new RuntimeException("Could not find method refreshResources()!"); - - // find first invocation of IReloadableResourceManager.reloadResources() - AbstractInsnNode targetInsn = null; - final String reloadResourcesName = devEnv ? "reloadResources" : "func_110541_a"; - final String reloadResourcesDesc = "(Ljava/util/List;)V"; - - for (AbstractInsnNode ain : targetMethod.instructions.toArray()) { - if (ain instanceof MethodInsnNode) { - MethodInsnNode min = (MethodInsnNode) ain; - if (min.name.equals(reloadResourcesName) && min.desc.equals(reloadResourcesDesc)) { - targetInsn = ain; - break; + TXLoaderCore.LOGGER.debug("Transforming net.minecraft.client.Minecraft"); + final boolean devEnv = (boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment"); + final ClassNode classNode = new ClassNode(); + final ClassReader classReader = new ClassReader(basicClass); + classReader.accept(classNode, ClassReader.SKIP_DEBUG); + final String targetMethodName = devEnv ? "refreshResources" : "func_110436_a"; + final String targetMethodInsnName = devEnv ? "reloadResources" : "func_110541_a"; + boolean success = false; + for (MethodNode mn : classNode.methods) { + if (mn.name.equals(targetMethodName) && mn.desc.equals("()V")) { + for (AbstractInsnNode node : mn.instructions.toArray()) { + if (node instanceof MethodInsnNode && ((MethodInsnNode) node).name.equals(targetMethodInsnName) + && ((MethodInsnNode) node).desc.equals("(Ljava/util/List;)V")) { + mn.instructions.insertBefore( + node, + new MethodInsnNode( + Opcodes.INVOKESTATIC, + "glowredman/txloader/MinecraftHook", + "insertForcePack", + "(Ljava/util/List;)Ljava/util/List;", + false)); + success = true; + break; + } } + break; } } - - if (targetInsn == null) - throw new RuntimeException("Could not find invocation of reloadResources() in method refreshResources()!"); - - // insert new instructions - InsnList insertForcePackInsnList = new InsnList(); - insertForcePackInsnList.add( - new MethodInsnNode( - Opcodes.INVOKESTATIC, - "glowredman/txloader/MinecraftClassTransformer", - "insertForcePack", - "(Ljava/util/List;)V", - false)); - insertForcePackInsnList.add(new VarInsnNode(Opcodes.ALOAD, 1)); - targetMethod.instructions.insertBefore(targetInsn, insertForcePackInsnList); - - ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); + if (!success) throw new RuntimeException("TX Loader couldn't transform Minecraft!"); + final ClassWriter classWriter = new ClassWriter(0); classNode.accept(classWriter); return classWriter.toByteArray(); } - @SuppressWarnings({ "rawtypes", "unchecked" }) - public static void insertForcePack(List resourcePackList) { - resourcePackList.add(new TXResourcePack.Force()); - } } diff --git a/src/main/java/glowredman/txloader/MinecraftHook.java b/src/main/java/glowredman/txloader/MinecraftHook.java new file mode 100644 index 0000000..25eb647 --- /dev/null +++ b/src/main/java/glowredman/txloader/MinecraftHook.java @@ -0,0 +1,13 @@ +package glowredman.txloader; + +import java.util.List; + +@SuppressWarnings("unused") +public class MinecraftHook { + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public static List insertForcePack(List resourcePackList) { + resourcePackList.add(new TXResourcePack.Force()); + return resourcePackList; + } +} diff --git a/src/main/java/glowredman/txloader/TXLoaderCore.java b/src/main/java/glowredman/txloader/TXLoaderCore.java index 0768973..ac23712 100644 --- a/src/main/java/glowredman/txloader/TXLoaderCore.java +++ b/src/main/java/glowredman/txloader/TXLoaderCore.java @@ -36,13 +36,18 @@ public class TXLoaderCore implements IFMLLoadingPlugin { @Override public String[] getASMTransformerClass() { - return FMLLaunchHandler.side().isClient() ? new String[] { MinecraftClassTransformer.class.getName() } - : new String[0]; + if (FMLLaunchHandler.side().isClient()) { + return new String[] { MinecraftClassTransformer.class.getName() }; + } + return null; } @Override public String getModContainerClass() { - return FMLLaunchHandler.side().isClient() ? "glowredman.txloader.TXLoaderModContainer" : null; + if (FMLLaunchHandler.side().isClient()) { + return "glowredman.txloader.TXLoaderModContainer"; + } + return null; } @Override From d1d4e88a048bc6a2f43898f0cf72aa53716846ee Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+Alexdoru@users.noreply.github.com> Date: Wed, 11 Oct 2023 22:01:51 +0200 Subject: [PATCH 2/3] changes asked --- .../glowredman/txloader/MinecraftClassTransformer.java | 8 ++++++-- src/main/java/glowredman/txloader/MinecraftHook.java | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/glowredman/txloader/MinecraftClassTransformer.java b/src/main/java/glowredman/txloader/MinecraftClassTransformer.java index 32af966..0dd37ee 100644 --- a/src/main/java/glowredman/txloader/MinecraftClassTransformer.java +++ b/src/main/java/glowredman/txloader/MinecraftClassTransformer.java @@ -33,8 +33,7 @@ private static byte[] transformMinecraft(byte[] basicClass) { for (MethodNode mn : classNode.methods) { if (mn.name.equals(targetMethodName) && mn.desc.equals("()V")) { for (AbstractInsnNode node : mn.instructions.toArray()) { - if (node instanceof MethodInsnNode && ((MethodInsnNode) node).name.equals(targetMethodInsnName) - && ((MethodInsnNode) node).desc.equals("(Ljava/util/List;)V")) { + if (isTargetNode(node, targetMethodInsnName)) { mn.instructions.insertBefore( node, new MethodInsnNode( @@ -56,4 +55,9 @@ private static byte[] transformMinecraft(byte[] basicClass) { return classWriter.toByteArray(); } + private static boolean isTargetNode(AbstractInsnNode node, String name) { + return node instanceof MethodInsnNode && ((MethodInsnNode) node).name.equals(name) + && ((MethodInsnNode) node).desc.equals("(Ljava/util/List;)V"); + } + } diff --git a/src/main/java/glowredman/txloader/MinecraftHook.java b/src/main/java/glowredman/txloader/MinecraftHook.java index 25eb647..7163c21 100644 --- a/src/main/java/glowredman/txloader/MinecraftHook.java +++ b/src/main/java/glowredman/txloader/MinecraftHook.java @@ -2,11 +2,12 @@ import java.util.List; +import net.minecraft.client.resources.IResourcePack; + @SuppressWarnings("unused") public class MinecraftHook { - @SuppressWarnings({ "rawtypes", "unchecked" }) - public static List insertForcePack(List resourcePackList) { + public static List insertForcePack(List resourcePackList) { resourcePackList.add(new TXResourcePack.Force()); return resourcePackList; } From 0db479ee24cb4814e157a9dbebd119f1c7059ba8 Mon Sep 17 00:00:00 2001 From: Martin Robertz Date: Thu, 12 Oct 2023 12:32:53 +0200 Subject: [PATCH 3/3] update bs+deps (cherry picked from commit cdd4be9ca9bb2127dd1e1e59928b719bfffa4091) --- build.gradle | 73 ++++++++++++++++++++++++++++++++------------- dependencies.gradle | 2 +- 2 files changed, 54 insertions(+), 21 deletions(-) diff --git a/build.gradle b/build.gradle index b894d64..b74b980 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: 1692122114 +//version: 1696952014 /* DO NOT CHANGE THIS FILE! Also, you may replace this file at any time if there is an update available. @@ -89,6 +89,23 @@ def out = services.get(StyledTextOutputFactory).create('an-output') def projectJavaVersion = JavaLanguageVersion.of(8) boolean disableSpotless = project.hasProperty("disableSpotless") ? project.disableSpotless.toBoolean() : false +boolean disableCheckstyle = project.hasProperty("disableCheckstyle") ? project.disableCheckstyle.toBoolean() : false + +final String CHECKSTYLE_CONFIG = """ + + + + + + + + + + + +""" checkPropertyExists("modName") checkPropertyExists("modId") @@ -140,6 +157,17 @@ if (!disableSpotless) { apply from: Blowdryer.file('spotless.gradle') } +if (!disableCheckstyle) { + apply plugin: 'checkstyle' + tasks.named("checkstylePatchedMc") { enabled = false } + tasks.named("checkstyleMcLauncher") { enabled = false } + tasks.named("checkstyleIdeVirtualMain") { enabled = false } + tasks.named("checkstyleInjectedTags") { enabled = false } + checkstyle { + config = resources.text.fromString(CHECKSTYLE_CONFIG) + } +} + String javaSourceDir = "src/main/java/" String scalaSourceDir = "src/main/scala/" String kotlinSourceDir = "src/main/kotlin/" @@ -600,15 +628,10 @@ repositories { } maven { name = "ic2" - url = "https://maven.ic2.player.to/" - metadataSources { - mavenPom() - artifact() + url = getURL("https://maven.ic2.player.to/", "https://maven2.ic2.player.to/") + content { + includeGroup "net.industrial-craft" } - } - maven { - name = "ic2-mirror" - url = "https://maven2.ic2.player.to/" metadataSources { mavenPom() artifact() @@ -770,23 +793,14 @@ ext.java17PatchDependenciesCfg = configurations.create("java17PatchDependencies" } dependencies { - def lwjgl3ifyVersion = '1.4.0' - def asmVersion = '9.4' + def lwjgl3ifyVersion = '1.5.1' if (modId != 'lwjgl3ify') { java17Dependencies("com.github.GTNewHorizons:lwjgl3ify:${lwjgl3ifyVersion}") } if (modId != 'hodgepodge') { - java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.2.26') + java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.3.7') } - java17PatchDependencies('net.minecraft:launchwrapper:1.17.2') {transitive = false} - java17PatchDependencies("org.ow2.asm:asm:${asmVersion}") - java17PatchDependencies("org.ow2.asm:asm-commons:${asmVersion}") - java17PatchDependencies("org.ow2.asm:asm-tree:${asmVersion}") - java17PatchDependencies("org.ow2.asm:asm-analysis:${asmVersion}") - java17PatchDependencies("org.ow2.asm:asm-util:${asmVersion}") - java17PatchDependencies('org.ow2.asm:asm-deprecated:7.1') - java17PatchDependencies("org.apache.commons:commons-lang3:3.12.0") java17PatchDependencies("com.github.GTNewHorizons:lwjgl3ify:${lwjgl3ifyVersion}:forgePatches") {transitive = false} } @@ -1576,6 +1590,25 @@ def getSecondaryArtifacts() { return secondaryArtifacts } +def getURL(String main, String fallback) { + return pingURL(main, 10000) ? main : fallback +} + +// credit: https://stackoverflow.com/a/3584332 +def pingURL(String url, int timeout) { + url = url.replaceFirst("^https", "http") // Otherwise an exception may be thrown on invalid SSL certificates. + try { + HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection() + connection.setConnectTimeout(timeout) + connection.setReadTimeout(timeout) + connection.setRequestMethod("HEAD") + int responseCode = connection.getResponseCode() + return 200 <= responseCode && responseCode <= 399 + } catch (IOException ignored) { + return false + } +} + // For easier scripting of things that require variables defined earlier in the buildscript if (file('addon.late.gradle.kts').exists()) { apply from: 'addon.late.gradle.kts' diff --git a/dependencies.gradle b/dependencies.gradle index 95bded7..d615426 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,3 +1,3 @@ dependencies { - compileOnly("com.github.GTNewHorizons:BetterLoadingScreen:1.4.4-GTNH:dev") { transitive = false } + compileOnly("com.github.GTNewHorizons:BetterLoadingScreen:1.5.0-GTNH:dev") { transitive = false } }