From 0af79083d4a431a3012f30d8a6435f63b037f38b Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sat, 23 Nov 2019 22:28:15 +0000 Subject: [PATCH] Initial loader 0.7.0 update. May be buggy --- build.gradle | 6 ++--- gradle.properties | 9 ++++---- .../optifabric/mod/OptifabricSetup.java | 2 +- .../optifabric/mod/OptifineInjector.java | 23 +++++++++++++++---- .../optifabric/mod/OptifineSetup.java | 17 ++++++++++---- .../optifabric/mod/OptifineVersion.java | 4 ++-- .../optifabric/patcher/ASMUtils.java | 13 +++++++---- .../optifabric/patcher/ChunkRendererFix.java | 8 +++++-- .../optifabric/patcher/ClassCache.java | 3 +++ .../optifabric/patcher/LambadaRebuiler.java | 5 ++-- 10 files changed, 60 insertions(+), 30 deletions(-) diff --git a/build.gradle b/build.gradle index 887d1bd9..67c96bd5 100644 --- a/build.gradle +++ b/build.gradle @@ -32,13 +32,13 @@ repositories { dependencies { minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}" + mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modCompile "net.fabricmc:fabric-loader:${project.loader_version}" modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - modCompile "com.github.Chocohead:Fabric-ASM:${project.fabric_asm_version}" - include "com.github.Chocohead:Fabric-ASM:${project.fabric_asm_version}" + modCompile "com.github.modmuss50:Fabric-ASM:${project.fabric_asm_version}" + include "com.github.modmuss50:Fabric-ASM:${project.fabric_asm_version}" //Used to handle the zip processing compile "org.zeroturnaround:zt-zip:${project.zt_zip_version}" diff --git a/gradle.properties b/gradle.properties index 7a090485..b42249f2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,15 +2,14 @@ org.gradle.jvmargs=-Xmx1G minecraft_version=1.14.4 -yarn_mappings=1.14.4+build.14 -loader_version=0.6.4+build.169 +yarn_mappings=1.14.4+build.15 +loader_version=0.7.0+build.171 fabric_version=0.4.1+build.245-1.14 -fabric_asm_version=697a7c18da +fabric_asm_version=b97939c03a zt_zip_version=1.13 slf4j_version=1.7.29 -stitch_version=0.3.0.66 -mod_version = 0.6.0 +mod_version = 0.7.0 maven_group = me.modmuss50 archives_base_name = optifabric diff --git a/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java b/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java index 5c9c978e..443e2658 100644 --- a/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java +++ b/src/main/java/me/modmuss50/optifabric/mod/OptifabricSetup.java @@ -69,7 +69,7 @@ private void validateIndigoVersion() { private boolean validateLoaderVersion() { try { - if (!isVersionValid("fabricloader", ">=0.6.4")) { + if (!isVersionValid("fabricloader", ">=0.7.0")) { if(!OptifabricError.hasError()){ OptifineVersion.jarType = OptifineVersion.JarType.INCOMPATIBE; OptifabricError.setError("You are using an outdated version of Fabric Loader, please update!\n\nRe-run the installer, or update via your launcher. See the link for help!", "https://fabricmc.net/wiki/install"); diff --git a/src/main/java/me/modmuss50/optifabric/mod/OptifineInjector.java b/src/main/java/me/modmuss50/optifabric/mod/OptifineInjector.java index f65f25a0..4ffb54ea 100644 --- a/src/main/java/me/modmuss50/optifabric/mod/OptifineInjector.java +++ b/src/main/java/me/modmuss50/optifabric/mod/OptifineInjector.java @@ -6,16 +6,19 @@ import me.modmuss50.optifabric.patcher.ClassCache; import net.fabricmc.loader.api.FabricLoader; import org.objectweb.asm.Opcodes; -import org.spongepowered.asm.lib.tree.AbstractInsnNode; -import org.spongepowered.asm.lib.tree.ClassNode; -import org.spongepowered.asm.lib.tree.FrameNode; -import org.spongepowered.asm.lib.tree.MethodNode; +import org.objectweb.asm.tree.AbstractInsnNode; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.FrameNode; +import org.objectweb.asm.tree.MethodNode; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.List; import java.util.function.Consumer; public class OptifineInjector { @@ -25,6 +28,8 @@ public class OptifineInjector { String chunkRenderer; String particleManager; + private static List patched = new ArrayList<>(); + public OptifineInjector(ClassCache classCache) { this.classCache = classCache; } @@ -39,6 +44,12 @@ public void setup() throws IOException { //I have no idea why and how this works, if you know better please let me know public final Consumer transformer = target -> { + if(patched.contains(target.name)) { + System.out.println("Already patched" + target.name); + return; + } + patched.add(target.name); + //I cannot imagine this being very good at all ClassNode source = getSourceClassNode(target); @@ -75,7 +86,6 @@ public void setup() throws IOException { target.methods.forEach(methodNode -> methodNode.access = modAccess(methodNode.access)); target.fields.forEach(fieldNode -> fieldNode.access = modAccess(fieldNode.access)); } - }; private static int modAccess(int access) { @@ -89,6 +99,9 @@ private static int modAccess(int access) { private ClassNode getSourceClassNode(ClassNode classNode) { String name = classNode.name.replaceAll("\\.", "/") + ".class"; byte[] bytes = classCache.getAndRemove(name); + if(bytes == null) { + throw new RuntimeException("Failed to find patched class for: " + name); + } return ASMUtils.readClassFromBytes(bytes); } diff --git a/src/main/java/me/modmuss50/optifabric/mod/OptifineSetup.java b/src/main/java/me/modmuss50/optifabric/mod/OptifineSetup.java index 73633cb1..2f4a0618 100644 --- a/src/main/java/me/modmuss50/optifabric/mod/OptifineSetup.java +++ b/src/main/java/me/modmuss50/optifabric/mod/OptifineSetup.java @@ -21,14 +21,21 @@ import org.apache.commons.lang3.tuple.Pair; import org.zeroturnaround.zip.ZipUtil; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; -import java.util.*; -import java.util.Map.Entry; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; public class OptifineSetup { diff --git a/src/main/java/me/modmuss50/optifabric/mod/OptifineVersion.java b/src/main/java/me/modmuss50/optifabric/mod/OptifineVersion.java index 37b1f7b0..09021005 100644 --- a/src/main/java/me/modmuss50/optifabric/mod/OptifineVersion.java +++ b/src/main/java/me/modmuss50/optifabric/mod/OptifineVersion.java @@ -5,8 +5,8 @@ import me.modmuss50.optifabric.patcher.ASMUtils; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.main.Main; -import org.spongepowered.asm.lib.tree.ClassNode; -import org.spongepowered.asm.lib.tree.FieldNode; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.FieldNode; import org.zeroturnaround.zip.ZipUtil; import java.io.*; diff --git a/src/main/java/me/modmuss50/optifabric/patcher/ASMUtils.java b/src/main/java/me/modmuss50/optifabric/patcher/ASMUtils.java index fe301c8f..d0e4cfd4 100644 --- a/src/main/java/me/modmuss50/optifabric/patcher/ASMUtils.java +++ b/src/main/java/me/modmuss50/optifabric/patcher/ASMUtils.java @@ -1,10 +1,12 @@ package me.modmuss50.optifabric.patcher; import org.apache.commons.io.IOUtils; -import org.spongepowered.asm.lib.ClassReader; -import org.spongepowered.asm.lib.ClassWriter; -import org.spongepowered.asm.lib.Opcodes; -import org.spongepowered.asm.lib.tree.ClassNode; +import org.apache.commons.lang3.Validate; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.tree.ClassNode; + import java.io.IOException; import java.io.InputStream; @@ -14,9 +16,10 @@ public class ASMUtils { public static ClassNode readClassFromBytes(byte[] bytes) { + Validate.notNull(bytes, "Cannot read null bytes"); ClassNode classNode = new ClassNode(); ClassReader classReader = new ClassReader(bytes); - classReader.accept(classNode, ClassReader.EXPAND_FRAMES); + classReader.accept(classNode, ClassReader.SKIP_FRAMES); return classNode; } diff --git a/src/main/java/me/modmuss50/optifabric/patcher/ChunkRendererFix.java b/src/main/java/me/modmuss50/optifabric/patcher/ChunkRendererFix.java index 3728efc8..116a8fdc 100644 --- a/src/main/java/me/modmuss50/optifabric/patcher/ChunkRendererFix.java +++ b/src/main/java/me/modmuss50/optifabric/patcher/ChunkRendererFix.java @@ -2,8 +2,12 @@ import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.MappingResolver; -import org.spongepowered.asm.lib.Opcodes; -import org.spongepowered.asm.lib.tree.*; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.tree.AbstractInsnNode; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.MethodInsnNode; +import org.objectweb.asm.tree.MethodNode; + public class ChunkRendererFix { diff --git a/src/main/java/me/modmuss50/optifabric/patcher/ClassCache.java b/src/main/java/me/modmuss50/optifabric/patcher/ClassCache.java index ba7fa7c7..95434d1b 100644 --- a/src/main/java/me/modmuss50/optifabric/patcher/ClassCache.java +++ b/src/main/java/me/modmuss50/optifabric/patcher/ClassCache.java @@ -1,5 +1,7 @@ package me.modmuss50.optifabric.patcher; +import org.apache.commons.lang3.Validate; + import java.io.*; import java.nio.charset.StandardCharsets; import java.util.HashMap; @@ -24,6 +26,7 @@ public void addClass(String name, byte[] bytes){ if(classes.containsKey(name)){ throw new UnsupportedOperationException(name + " is already in ClassCache"); } + Validate.notNull(bytes, "bytes cannot be null"); classes.put(name, bytes); } diff --git a/src/main/java/me/modmuss50/optifabric/patcher/LambadaRebuiler.java b/src/main/java/me/modmuss50/optifabric/patcher/LambadaRebuiler.java index 6b9c6230..686dfb12 100644 --- a/src/main/java/me/modmuss50/optifabric/patcher/LambadaRebuiler.java +++ b/src/main/java/me/modmuss50/optifabric/patcher/LambadaRebuiler.java @@ -2,8 +2,9 @@ import net.fabricmc.tinyremapper.IMappingProvider; import net.fabricmc.tinyremapper.MemberInstance; -import org.spongepowered.asm.lib.tree.ClassNode; -import org.spongepowered.asm.lib.tree.MethodNode; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.MethodNode; + import java.io.File; import java.io.IOException;