Skip to content

Commit

Permalink
Try to avoid more class loading issues...
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmuscaria committed Jan 15, 2024
1 parent 34392a6 commit ba95571
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 26 deletions.
25 changes: 16 additions & 9 deletions patches/cpw/mods/fml/relauncher/CoreModManager.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,21 @@
public static void handleLaunch(File mcDir, LaunchClassLoader classLoader, FMLTweaker tweaker)
{
CoreModManager.mcDir = mcDir;
@@ -219,7 +230,23 @@
@@ -206,6 +217,9 @@
}

FMLRelaunchLog.fine("All fundamental core mods are successfully located");
+ // Crucible start - too lazy for creating a coremod
+ CrucibleServerMainHook.coremodHandleLaunch(mcDir, classLoader, tweaker);
+ // Crucible end
// Now that we have the root plugins loaded - lets see what else might
// be around
String commandLineCoremods = System.getProperty("fml.coreMods.load", "");
@@ -219,7 +233,19 @@
loadCoreMod(classLoader, coreModClassName, null);
}
discoverCoreMods(mcDir, classLoader);
-
+ // Cauldron start - group output of @MCVersion warnings
+ if (!noVersionAnnotationCoreMods.isEmpty())
+ {
Expand All @@ -102,14 +113,10 @@
+ FMLRelaunchLog.warning(sb.toString());
+ }
+ // Cauldron end

+ // Crucible start - too lazy for creating a coremod
+ CrucibleServerMainHook.coremodHandleLaunch(mcDir, classLoader, tweaker);
+ // Crucible end
}

private static void discoverCoreMods(File mcDir, LaunchClassLoader classLoader)
@@ -336,6 +363,10 @@
@@ -336,6 +362,10 @@
String cascadedTweaker = mfAttributes.getValue("TweakClass");
if (cascadedTweaker != null)
{
Expand All @@ -120,7 +127,7 @@
FMLRelaunchLog.info("Loading tweaker %s from %s", cascadedTweaker, coreMod.getName());
Integer sortOrder = Ints.tryParse(Strings.nullToEmpty(mfAttributes.getValue("TweakOrder")));
sortOrder = (sortOrder == null ? Integer.valueOf(0) : sortOrder);
@@ -365,6 +396,10 @@
@@ -365,6 +395,10 @@
FMLRelaunchLog.fine("Not found coremod data in %s", coreMod.getName());
continue;
}
Expand All @@ -131,7 +138,7 @@
// Support things that are mod jars, but not FML mod jars
try
{
@@ -377,40 +412,76 @@
@@ -377,40 +411,76 @@
else
{
FMLRelaunchLog.finer("Found FMLCorePluginContainsFMLMod marker in %s, it will be examined later for regular @Mod instances",
Expand Down Expand Up @@ -225,7 +232,7 @@
}

/**
@@ -467,19 +538,22 @@
@@ -467,19 +537,22 @@
MCVersion requiredMCVersion = coreModClazz.getAnnotation(IFMLLoadingPlugin.MCVersion.class);
if (!Arrays.asList(rootPlugins).contains(coreModClass) && (requiredMCVersion == null || Strings.isNullOrEmpty(requiredMCVersion.value())))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,13 @@ public static void restoreStreams() {

// Too lazy for a coremod
public static void coremodHandleLaunch(File mcDir, LaunchClassLoader classLoader, FMLTweaker tweaker) {
classLoader.addClassLoaderExclusion("io.github.crucible.bootstrap.");
try {
// Ensure some essential classes are loaded before we register the tweaker
// Ensure our config is loaded way before everything that may need it
Class.forName("io.github.crucible.CrucibleConfigs", true, classLoader);
Class.forName("io.github.crucible.CrucibleModContainer", true, classLoader);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
Lwjgl3ifyGlue.doCoremodWork(classLoader);
classLoader.addClassLoaderExclusion("io.github.crucible.bootstrap.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import io.github.crucible.CrucibleModContainer;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
Expand All @@ -23,7 +24,7 @@

public class ExtensibleEnumTransformerHelper {

private final Logger LOGGER = CrucibleModContainer.logger;
private final Logger LOGGER = LogManager.getLogger("lwjgl3ify");
private final Type STRING = Type.getType(String.class);
private final Type ENUM = Type.getType(Enum.class);
public final Type MARKER_IFACE = Type.getType(IExtensibleEnum.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import java.util.concurrent.atomic.AtomicBoolean;

import io.github.crucible.CrucibleModContainer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
Expand All @@ -20,6 +21,7 @@
* CONSTANT_InterfaceMethodRef
*/
public class FixConstantPoolInterfaceMethodRefHelper {
private final Logger LOGGER = LogManager.getLogger("lwjgl3ify");

public boolean transform(ClassNode node) {
if (System.getProperty("java.specification.version", "1.8")
Expand Down Expand Up @@ -80,7 +82,7 @@ private Handle fixHandle(String internalClassName, boolean iAmAnInterface, Handl
}
} catch (ClassNotFoundException cnfe) {
// no-op
CrucibleModContainer.logger.warn("Reference to non-existing java class {} found.", regularName, cnfe);
LOGGER.warn("Reference to non-existing java class {} found.", regularName, cnfe);
}
}
if (fixSelfReference || fixJavaReference) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import java.util.ArrayList;
import java.util.List;

import io.github.crucible.CrucibleModContainer;
import io.github.crucible.CrucibleConfigs;
import io.github.crucible.bootstrap.CrucibleMetadata;
import net.minecraft.launchwrapper.IClassTransformer;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
Expand All @@ -19,7 +19,7 @@
import me.eigenraven.lwjgl3ify.WasFinalObjectHolder;

public class UnfinalizeObjectHoldersTransformer implements IClassTransformer {

private final Logger LOGGER = LogManager.getLogger("lwjgl3ify");
// Keep ClassNode-operating transformers together for efficiency (don't read/write the class multiple times)
final ExtensibleEnumTransformerHelper enumTransformer = new ExtensibleEnumTransformerHelper();
final FixConstantPoolInterfaceMethodRefHelper cpiMethodRefTransformer = new FixConstantPoolInterfaceMethodRefHelper();
Expand Down Expand Up @@ -47,9 +47,7 @@ public byte[] transform(String name, String transformedName, byte[] basicClass)
return null;
}

// Crucible classes and some of its dependencies *must* be ignored because we depend on Crucible config
if (transformedName.startsWith("me.eigenraven.lwjgl3ify") || transformedName.startsWith("io.github.crucible")
|| transformedName.startsWith("org.yaml.snakeyaml")) {
if (transformedName.startsWith("me.eigenraven.lwjgl3ify")) {
return basicClass;
}
try {
Expand All @@ -66,7 +64,7 @@ public byte[] transform(String name, String transformedName, byte[] basicClass)
}
transformClass |= isHolder(node.visibleAnnotations);
if (transformedName.equals("team.chisel.init.ChiselBlocks")) {
CrucibleModContainer.logger.debug("chiselblocks");
LOGGER.debug("chiselblocks");
}
int fieldsModified = 0;
for (FieldNode field : node.fields) {
Expand All @@ -88,7 +86,7 @@ public byte[] transform(String name, String transformedName, byte[] basicClass)
}
}
if (workDone) {
CrucibleModContainer.logger.info("Unfinalized {} Holder fields in {}", fieldsModified, transformedName);
LOGGER.info("Unfinalized {} Holder fields in {}", fieldsModified, transformedName);
}

if (CrucibleConfigs.configs.lwjgl3ify_extensibleEnums
Expand All @@ -103,14 +101,14 @@ public byte[] transform(String name, String transformedName, byte[] basicClass)

if (enumsTransformed) {
workDone = true;
CrucibleModContainer.logger.info("Dynamicized enum {}={}", name, transformedName);
LOGGER.info("Dynamicized enum {}={}", name, transformedName);
}

final boolean ifaceMethodRefsTransformed = cpiMethodRefTransformer.transform(node);

if (ifaceMethodRefsTransformed) {
workDone = true;
CrucibleModContainer.logger
LOGGER
.warn("Fixed missing CONSTANT_InterfaceMethodRef miscompilation in {}={}", name, transformedName);
}

Expand All @@ -120,7 +118,7 @@ public byte[] transform(String name, String transformedName, byte[] basicClass)
return writer.toByteArray();
}
} catch (Exception e) {
CrucibleModContainer.logger.error("Error when unfinalizing ObjectHolder transformer", e);
LOGGER.error("Error when unfinalizing ObjectHolder transformer", e);
}
return basicClass;
}
Expand Down

0 comments on commit ba95571

Please sign in to comment.