Skip to content

Commit

Permalink
Merge pull request #140 from juanmuscaria/newJava
Browse files Browse the repository at this point in the history
Support for newer java versions by integrating lwjgl3ify directly
  • Loading branch information
juanmuscaria authored Feb 5, 2024
2 parents 81fcb90 + 20bc506 commit 88c045f
Show file tree
Hide file tree
Showing 65 changed files with 2,229 additions and 304 deletions.
22 changes: 18 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ buildscript {
}
dependencies {
classpath 'com.anatawa12.forge:ForgeGradle:1.2-1.1.0'
classpath 'io.github.cruciblemc:CrucibleGradle:1.1-SNAPSHOT'
classpath 'io.github.cruciblemc:CrucibleGradle:1.2-SNAPSHOT'
}
}

Expand Down Expand Up @@ -81,6 +81,21 @@ configurations {
}

dependencies {
// New java stuff
libraries 'org.apache.commons:commons-lang3:3.12.0'
libraries 'org.apache.commons:commons-compress:1.21'
libraries 'org.ow2.asm:asm:9.5'
libraries 'org.ow2.asm:asm-commons:9.5'
libraries 'org.ow2.asm:asm-tree:9.5'
libraries 'org.ow2.asm:asm-analysis:9.5'
libraries 'org.ow2.asm:asm-util:9.5'
libraries 'org.ow2.asm:asm-deprecated:7.1'
libraries 'jakarta.xml.bind:jakarta.xml.bind-api:3.0.1'
libraries 'jakarta.servlet:jakarta.servlet-api:6.0.0'
libraries 'com.sun.xml.bind:jaxb-impl:3.0.2'
libraries 'org.mozilla:rhino-engine:1.7.14'

// Other libs
libraries 'pw.prok:Damask:0.1.2@jar'
libraries 'commons-cli:commons-cli:1.3@jar'
libraries 'org.slf4j:slf4j-simple:1.6.2@jar'
Expand All @@ -89,7 +104,6 @@ dependencies {
libraries 'net.sf.opencsv:opencsv:2.0@jar'
libraries 'com.beust:jcommander:1.30@jar'
libraries 'io.github.cruciblemc:launchwrapper:1.13@jar'
libraries 'org.ow2.asm:asm-all:5.0.3'
libraries 'com.typesafe.akka:akka-actor_2.11:2.3.3'
libraries 'com.typesafe:config:1.2.1'
libraries 'org.scala-lang:scala-actors-migration_2.11:1.1.0'
Expand All @@ -107,20 +121,20 @@ dependencies {
libraries 'commons-lang:commons-lang:2.6'
libraries 'org.avaje:ebean:2.7.3'
libraries 'jline:jline:2.6'
libraries 'net.md-5:SpecialSource:1.7.4'
libraries 'net.md-5:SpecialSource:1.10.0'
libraries 'net.sourceforge.argo:argo:2.25'
libraries 'com.googlecode.json-simple:json-simple:1.1'
libraries 'org.xerial:sqlite-jdbc:3.7.2'
libraries 'mysql:mysql-connector-java:5.1.14'
libraries 'javax.persistence:persistence-api:1.0.2'
libraries 'net.minecraft:server:1.7.10'
libraries 'pw.prok:KImagine:0.2.0@jar'
libraries 'org.apache.httpcomponents:httpclient:4.4.1'
libraries 'net.openhft:affinity:3.0.1'
libraries 'org.fusesource.jansi:jansi:1.11'
libraries 'com.koloboke:koloboke-impl-jdk8:1.0.0'
libraries 'java3d:vecmath:1.3.1'
libraries 'it.unimi.dsi:fastutil:8.2.2'
libraries 'net.minecraft:server:1.7.10'
}

packageApi {
Expand Down
36 changes: 36 additions & 0 deletions java9args.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--illegal-access=warn
-Djava.security.manager=allow
-Dfile.encoding=UTF-8
-Dcrucible.weAreJava9=true
--add-opens
java.base/jdk.internal.loader=ALL-UNNAMED
--add-opens
java.base/java.net=ALL-UNNAMED
--add-opens
java.base/java.nio=ALL-UNNAMED
--add-opens
java.base/java.io=ALL-UNNAMED
--add-opens
java.base/java.lang=ALL-UNNAMED
--add-opens
java.base/java.lang.reflect=ALL-UNNAMED
--add-opens
java.base/java.text=ALL-UNNAMED
--add-opens
java.base/java.util=ALL-UNNAMED
--add-opens
java.base/jdk.internal.reflect=ALL-UNNAMED
--add-opens
java.base/sun.nio.ch=ALL-UNNAMED
--add-opens
jdk.naming.dns/com.sun.jndi.dns=ALL-UNNAMED,java.naming
--add-opens
java.desktop/sun.awt.image=ALL-UNNAMED
--add-opens
java.desktop/com.sun.imageio.plugins.png=ALL-UNNAMED
--add-modules jdk.dynalink
--add-opens
jdk.dynalink/jdk.dynalink.beans=ALL-UNNAMED
--add-modules java.sql.rowset
--add-opens
java.sql.rowset/javax.sql.rowset.serial=ALL-UNNAMED
13 changes: 13 additions & 0 deletions patches/cpw/mods/fml/common/TracingPrintStream.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- ../src-base/minecraft/cpw/mods/fml/common/TracingPrintStream.java
+++ ../src-work/minecraft/cpw/mods/fml/common/TracingPrintStream.java
@@ -47,4 +47,10 @@
return "[" + elem.getClassName() + ":" + elem.getMethodName() + ":" + elem.getLineNumber() + "]: ";
}

+ @Override
+ public void close() {
+ // no-op
+ //println("Something tried to close the main output stream");
+ //new Throwable().printStackTrace();
+ }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--- ../src-base/minecraft/cpw/mods/fml/common/asm/transformers/EventSubscriptionTransformer.java
+++ ../src-work/minecraft/cpw/mods/fml/common/asm/transformers/EventSubscriptionTransformer.java
@@ -123,7 +123,7 @@
{
for (AnnotationNode node : classNode.visibleAnnotations)
{
- if (!hasResult && node.desc.equals("Lcpw/mods/fml/common/eventhandler/Event$HasResult;"))
+ if (!hasResult && node.desc.replace('$', '/').equals("Lcpw/mods/fml/common/eventhandler/Event/HasResult;"))
{
/* Add:
* public boolean hasResult()
@@ -162,7 +162,7 @@
return edited;
}

- Type tSuper = Type.getType(classNode.superName);
+ Type tSuper = Type.getObjectType(classNode.superName);

//Add private static ListenerList LISTENER_LIST
classNode.fields.add(new FieldNode(ACC_PRIVATE | ACC_STATIC, "LISTENER_LIST", listDesc, null, null));
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
--- ../src-base/minecraft/cpw/mods/fml/common/asm/transformers/TerminalTransformer.java
+++ ../src-work/minecraft/cpw/mods/fml/common/asm/transformers/TerminalTransformer.java
@@ -46,7 +46,8 @@
@@ -29,7 +29,7 @@

private ExitVisitor(ClassVisitor cv)
{
- super(Opcodes.ASM5, cv);
+ super(Opcodes.ASM9, cv);
}

@Override
@@ -46,10 +46,11 @@
clsName.equals("net/minecraft/server/dedicated/DedicatedServer") ||
clsName.equals("cpw/mods/fml/common/FMLCommonHandler") ||
clsName.startsWith("com/jcraft/jogg/") ||
Expand All @@ -9,4 +18,8 @@
+ clsName.startsWith("net/md_5/specialsource")
);

return new MethodVisitor(Opcodes.ASM5, super.visitMethod(mAccess, mName, mDesc, mSignature, mExceptions))
- return new MethodVisitor(Opcodes.ASM5, super.visitMethod(mAccess, mName, mDesc, mSignature, mExceptions))
+ return new MethodVisitor(Opcodes.ASM9, super.visitMethod(mAccess, mName, mDesc, mSignature, mExceptions))
{
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean isIntf)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
for (ZipEntry ze : Collections.list(jar.entries()))
{
- if (ze.getName()!=null && ze.getName().startsWith("__MACOSX"))
+ if (ze.getName()!=null && (ze.getName().startsWith("__MACOSX") || ze.getName().startsWith("META-INF/versions")))
+ if (ze.getName().startsWith("__MACOSX") || ze.getName().startsWith("META-INF/versions") || ze.getName().contains("org/openjdk/nashorn") || ze.getName().contains("jakarta/servlet/"))
{
continue;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- ../src-base/minecraft/cpw/mods/fml/common/discovery/asm/ModAnnotationVisitor.java
+++ ../src-work/minecraft/cpw/mods/fml/common/discovery/asm/ModAnnotationVisitor.java
@@ -25,7 +25,7 @@

public ModAnnotationVisitor(ASMModParser discoverer)
{
- super(Opcodes.ASM5);
+ super(Opcodes.ASM9);
this.discoverer = discoverer;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- ../src-base/minecraft/cpw/mods/fml/common/discovery/asm/ModClassVisitor.java
+++ ../src-work/minecraft/cpw/mods/fml/common/discovery/asm/ModClassVisitor.java
@@ -24,7 +24,7 @@

public ModClassVisitor(ASMModParser discoverer)
{
- super(Opcodes.ASM5);
+ super(Opcodes.ASM9);
this.discoverer = discoverer;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- ../src-base/minecraft/cpw/mods/fml/common/discovery/asm/ModFieldVisitor.java
+++ ../src-work/minecraft/cpw/mods/fml/common/discovery/asm/ModFieldVisitor.java
@@ -24,7 +24,7 @@

public ModFieldVisitor(String name, ASMModParser discoverer)
{
- super(Opcodes.ASM5);
+ super(Opcodes.ASM9);
this.fieldName = name;
this.discoverer = discoverer;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- ../src-base/minecraft/cpw/mods/fml/common/discovery/asm/ModMethodVisitor.java
+++ ../src-work/minecraft/cpw/mods/fml/common/discovery/asm/ModMethodVisitor.java
@@ -12,7 +12,7 @@

public ModMethodVisitor(String name, String desc, ASMModParser discoverer)
{
- super(Opcodes.ASM5);
+ super(Opcodes.ASM9);
this.methodName = name;
this.methodDescriptor = desc;
this.discoverer = discoverer;
10 changes: 0 additions & 10 deletions patches/cpw/mods/fml/common/launcher/FMLServerTweaker.java.patch

This file was deleted.

54 changes: 54 additions & 0 deletions patches/cpw/mods/fml/common/patcher/ClassPatchManager.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
--- ../src-base/minecraft/cpw/mods/fml/common/patcher/ClassPatchManager.java
+++ ../src-work/minecraft/cpw/mods/fml/common/patcher/ClassPatchManager.java
@@ -14,11 +14,13 @@
import java.util.jar.Pack200;
import java.util.regex.Pattern;

+import org.apache.commons.compress.harmony.unpack200.Archive;
import org.apache.logging.log4j.Level;

import net.minecraft.launchwrapper.LaunchClassLoader;

-import LZMA.LzmaInputStream;
+import org.apache.commons.compress.harmony.unpack200.Pack200UnpackerAdapter;
+import org.apache.logging.log4j.Level;

import com.google.common.base.Joiner;
import com.google.common.base.Throwables;
@@ -30,11 +32,13 @@
import com.google.common.io.ByteStreams;
import com.google.common.io.Files;

+import LZMA.LzmaInputStream;
import cpw.mods.fml.relauncher.FMLRelaunchLog;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.repackage.com.nothome.delta.GDiffPatcher;

public class ClassPatchManager {
+
public static final ClassPatchManager INSTANCE = new ClassPatchManager();

public static final boolean dumpPatched = Boolean.parseBoolean(System.getProperty("fml.dumpPatchedClasses", "false"));
@@ -155,10 +159,20 @@
FMLRelaunchLog.log(Level.ERROR, "The binary patch set is missing. Either you are in a development environment, or things are not going to work!");
return;
}
- LzmaInputStream binpatchesDecompressed = new LzmaInputStream(binpatchesCompressed);
+ // Crucible start - apply lwjgl3ify patch
+ // LzmaInputStream binpatchesDecompressed = new LzmaInputStream(binpatchesCompressed);
+ LzmaInputStream binpatchesDecompressedLzma = new LzmaInputStream(binpatchesCompressed);
+ // The Apache pack200 stream chokes on a lzmainputstream for some reason
+ byte[] decompressed = ByteStreams.toByteArray(binpatchesDecompressedLzma);
+ binpatchesDecompressedLzma.close();
+ ByteArrayInputStream binpatchesDecompressed = new ByteArrayInputStream(decompressed);
ByteArrayOutputStream jarBytes = new ByteArrayOutputStream();
JarOutputStream jos = new JarOutputStream(jarBytes);
- Pack200.newUnpacker().unpack(binpatchesDecompressed, jos);
+
+ //Pack200.newUnpacker().unpack(binpatchesDecompressed, jos);
+ new Pack200UnpackerAdapter().unpack(binpatchesDecompressed, jos);
+ // Crucible end
+
jis = new JarInputStream(new ByteArrayInputStream(jarBytes.toByteArray()));
}
catch (Exception e)
114 changes: 114 additions & 0 deletions patches/cpw/mods/fml/common/registry/ItemStackHolderRef.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
--- ../src-base/minecraft/cpw/mods/fml/common/registry/ItemStackHolderRef.java
+++ ../src-work/minecraft/cpw/mods/fml/common/registry/ItemStackHolderRef.java
@@ -1,5 +1,7 @@
package cpw.mods.fml.common.registry;

+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@@ -40,20 +42,26 @@
private static Object reflectionFactory;
private static Method newFieldAccessor;
private static Method fieldAccessorSet;
+ private static MethodHandle fieldSetter; // Crucible - lwjgl3ify field
private static void makeWritable(Field f)
{
try
{
- if (modifiersField == null)
- {
- Method getReflectionFactory = Class.forName("sun.reflect.ReflectionFactory").getDeclaredMethod("getReflectionFactory");
- reflectionFactory = getReflectionFactory.invoke(null);
- newFieldAccessor = Class.forName("sun.reflect.ReflectionFactory").getDeclaredMethod("newFieldAccessor", Field.class, boolean.class);
- fieldAccessorSet = Class.forName("sun.reflect.FieldAccessor").getDeclaredMethod("set", Object.class, Object.class);
- modifiersField = Field.class.getDeclaredField("modifiers");
- modifiersField.setAccessible(true);
- }
- modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL);
+ // Crucible start - implement lwjgl3ify patch directly
+// if (modifiersField == null)
+// {
+// Method getReflectionFactory = Class.forName("sun.reflect.ReflectionFactory").getDeclaredMethod("getReflectionFactory");
+// reflectionFactory = getReflectionFactory.invoke(null);
+// newFieldAccessor = Class.forName("sun.reflect.ReflectionFactory").getDeclaredMethod("newFieldAccessor", Field.class, boolean.class);
+// fieldAccessorSet = Class.forName("sun.reflect.FieldAccessor").getDeclaredMethod("set", Object.class, Object.class);
+// modifiersField = Field.class.getDeclaredField("modifiers");
+// modifiersField.setAccessible(true);
+// }
+// modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL);
+ f.setAccessible(true);
+ fieldSetter = MethodHandles.lookup()
+ .unreflectSetter(f);
+ // Crucible end
} catch (Exception e)
{
throw Throwables.propagate(e);
@@ -62,23 +70,53 @@

public void apply()
{
+ // Crucible start - implement lwjgl3ify patch directly
+// ItemStack is;
+// try
+// {
+// is = GameRegistry.makeItemStack(itemName, meta, 1, serializednbt);
+// } catch (RuntimeException e)
+// {
+// FMLLog.getLogger().log(Level.ERROR, "Caught exception processing itemstack {},{},{} in annotation at {}.{}", itemName, meta, serializednbt,field.getClass().getName(),field.getName());
+// throw e;
+// }
+// try
+// {
+// Object fieldAccessor = newFieldAccessor.invoke(reflectionFactory, field, false);
+// fieldAccessorSet.invoke(fieldAccessor, null, is);
+// }
+// catch (Exception e)
+// {
+// FMLLog.getLogger().log(Level.WARN, "Unable to set {} with value {},{},{}", this.field, this.itemName, this.meta, this.serializednbt);
+// }
ItemStack is;
- try
- {
+ try {
is = GameRegistry.makeItemStack(itemName, meta, 1, serializednbt);
- } catch (RuntimeException e)
- {
- FMLLog.getLogger().log(Level.ERROR, "Caught exception processing itemstack {},{},{} in annotation at {}.{}", itemName, meta, serializednbt,field.getClass().getName(),field.getName());
+ } catch (RuntimeException e) {
+ FMLLog.getLogger()
+ .log(
+ Level.ERROR,
+ "Caught exception processing itemstack {},{},{} in annotation at {}.{}",
+ itemName,
+ meta,
+ serializednbt,
+ field.getClass()
+ .getName(),
+ field.getName());
throw e;
}
- try
- {
- Object fieldAccessor = newFieldAccessor.invoke(reflectionFactory, field, false);
- fieldAccessorSet.invoke(fieldAccessor, null, is);
+ try {
+ fieldSetter.invoke(is);
+ } catch (Throwable e) {
+ FMLLog.getLogger()
+ .log(
+ Level.WARN,
+ "Unable to set {} with value {},{},{}",
+ this.field,
+ this.itemName,
+ this.meta,
+ this.serializednbt);
}
- catch (Exception e)
- {
- FMLLog.getLogger().log(Level.WARN, "Unable to set {} with value {},{},{}", this.field, this.itemName, this.meta, this.serializednbt);
- }
+ // Crucible end
}
}
Loading

0 comments on commit 88c045f

Please sign in to comment.