Skip to content

Commit

Permalink
Merge pull request #218 from fixrtm/use-multiple-coremod-by-jar-in-jar
Browse files Browse the repository at this point in the history
use multiple coremod loading by jar-in-jar
  • Loading branch information
anatawa12 authored May 19, 2021
2 parents 95924de + 7dfc562 commit 1dc1105
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 36 deletions.
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

0 comments on commit 1dc1105

Please sign in to comment.