Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use multiple coremod loading by jar-in-jar #218

Merged
merged 1 commit into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
))
Expand Down
34 changes: 0 additions & 34 deletions src/main/java/com/anatawa12/fixRtm/asm/FixRtmCorePlugin.kt
Original file line number Diff line number Diff line change
@@ -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<String> = arrayOf()
Expand Down