From 7dfc562a87b2f2ae1825d156e8a8b9e2d5a25857 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Wed, 19 May 2021 21:41:33 +0900 Subject: [PATCH] use multiple coremod loading by jar-in-jar --- build.gradle.kts | 11 ++++-- .../anatawa12/fixRtm/asm/FixRtmCorePlugin.kt | 34 ------------------- 2 files changed, 9 insertions(+), 36 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 908f8e76..2bb34b33 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -102,8 +102,15 @@ val reprocessResources by tasks.getting(Copy::class) { configure() } +val coremods = mutableListOf( + "com.anatawa12.fixRtm.asm.FixRtmCorePlugin", + "com.anatawa12.fixRtm.asm.patching.PatchingFixRtmCorePlugin", + "com.anatawa12.fixRtm.asm.preprocessing.PreprocessingFixRtmCorePlugin", + "com.anatawa12.fixRtm.asm.hooking.HookingFixRtmCorePlugin" +) + val runClient by tasks.getting(JavaExec::class) { - environment("fml.coreMods.load", "com.anatawa12.fixRtm.asm.FixRtmCorePlugin") + systemProperties["fml.coreMods.load"] = coremods.joinToString(",") systemProperties["legacy.debugClassLoading"] = "true" /* systemProperties["legacy.debugClassLoadingSave"] = "true" @@ -128,7 +135,7 @@ val jar by tasks.getting(Jar::class) { manifest { attributes(mapOf( - "FMLCorePlugin" to "com.anatawa12.fixRtm.asm.FixRtmCorePlugin", + "FMLCorePlugin" to coremods.joinToString(";"), "FMLCorePluginContainsFMLMod" to "*", "FMLAT" to "fix-rtm_at.cfg" )) diff --git a/src/main/java/com/anatawa12/fixRtm/asm/FixRtmCorePlugin.kt b/src/main/java/com/anatawa12/fixRtm/asm/FixRtmCorePlugin.kt index 4f3d774d..23fcc643 100644 --- a/src/main/java/com/anatawa12/fixRtm/asm/FixRtmCorePlugin.kt +++ b/src/main/java/com/anatawa12/fixRtm/asm/FixRtmCorePlugin.kt @@ -1,46 +1,12 @@ package com.anatawa12.fixRtm.asm -import com.anatawa12.fixRtm.asm.hooking.HookingFixRtmCorePlugin -import com.anatawa12.fixRtm.asm.patching.PatchingFixRtmCorePlugin -import com.anatawa12.fixRtm.asm.preprocessing.PreprocessingFixRtmCorePlugin -import net.minecraft.launchwrapper.Launch -import net.minecraft.launchwrapper.LaunchClassLoader -import net.minecraftforge.fml.relauncher.CoreModManager import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin -import java.io.File - @IFMLLoadingPlugin.TransformerExclusions( "com.anatawa12.fixRtm.asm.", "com.anatawa12.fixRtm.libs.", ) class FixRtmCorePlugin : IFMLLoadingPlugin { - init { - val loadCoreMod = CoreModManager::class.java.getDeclaredMethod("loadCoreMod", - LaunchClassLoader::class.java, - String::class.java, - File::class.java) - loadCoreMod.isAccessible = true - - val classLoader = Launch.classLoader - val jar = getJarPath() - - val classes = arrayOf( - PreprocessingFixRtmCorePlugin::class, - PatchingFixRtmCorePlugin::class, - HookingFixRtmCorePlugin::class, - ) - for (clazz in classes) { - loadCoreMod.invoke(null, classLoader, clazz.qualifiedName!!, jar) - } - } - - private fun getJarPath(): File? { - val jarFile = File(FixRtmCorePlugin::class.java.protectionDomain.codeSource.location.toURI()) - if (jarFile.extension == "jar") return null - return jarFile - } - override fun getModContainerClass(): String? = null override fun getASMTransformerClass(): Array = arrayOf()