Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
exejar committed Apr 29, 2024
1 parent 4c43674 commit d27522a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 37 deletions.
32 changes: 0 additions & 32 deletions loader/src/main/kotlin/net/weavemc/loader/bootstrap/Agent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,38 +45,6 @@ fun premain(opt: String?, inst: Instrumentation) {
Bootstrap.bootstrap(inst)
}

private fun setGameInfo() {
val cwd = Path(System.getProperty("user.dir"))
val version = System.getProperty("weave.environment.version")
?: if (cwd.pathString.contains("instances")) {
val instance = cwd.parent
val instanceData =
JSON.decodeFromString<MultiMCInstance>(instance.resolve("mmc-pack.json").toFile().readText())

instanceData.components.find { it.uid == "net.minecraft" }?.version
?: fatalError("Failed to find \"Minecraft\" component in ${instance.pathString}'s mmc-pack.json")
} else {
"""--version\s+(\S+)""".toRegex()
.find(System.getProperty("sun.java.command"))
?.groupValues?.get(1) ?: fatalError("Could not parse version from command line arguments")
}

fun classExists(name: String): Boolean =
GameInfo::class.java.classLoader.getResourceAsStream("${name.replace('.', '/')}.class") != null

val client = when {
classExists("com.moonsworth.lunar.genesis.Genesis") -> "lunar client"
classExists("net.minecraftforge.fml.common.Loader") -> "forge"
GameInfo.commandLineArgs.contains("labymod") -> "labymod"
else -> "vanilla"
}

System.getProperties()["weave.game.info"] = mapOf(
"version" to version,
"client" to client
)
}

private fun callTweakers(inst: Instrumentation) {
println("[Weave] Calling tweakers")

Expand Down
39 changes: 34 additions & 5 deletions loader/src/main/kotlin/net/weavemc/loader/util/Utility.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package net.weavemc.loader.util

import kotlinx.serialization.json.Json
import net.weavemc.internals.GameInfo
import net.weavemc.internals.ModConfig
import net.weavemc.loader.fetchModConfig
import org.objectweb.asm.ClassReader
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.MethodNode
Expand All @@ -17,10 +17,7 @@ import java.security.MessageDigest
import java.security.NoSuchAlgorithmException
import java.util.jar.JarFile
import javax.swing.JOptionPane
import kotlin.io.path.createDirectories
import kotlin.io.path.exists
import kotlin.io.path.inputStream
import kotlin.io.path.isDirectory
import kotlin.io.path.*
import kotlin.system.exitProcess

/**
Expand Down Expand Up @@ -169,6 +166,38 @@ fun File.createRemappedTemp(name: String, config: ModConfig): File {
return temp
}

internal fun setGameInfo() {
val cwd = Path(System.getProperty("user.dir"))
val version = System.getProperty("weave.environment.version")
?: if (cwd.pathString.contains("instances")) {
val instance = cwd.parent
val instanceData =
JSON.decodeFromString<MultiMCInstance>(instance.resolve("mmc-pack.json").toFile().readText())

instanceData.components.find { it.uid == "net.minecraft" }?.version
?: fatalError("Failed to find \"Minecraft\" component in ${instance.pathString}'s mmc-pack.json")
} else {
"""--version\s+(\S+)""".toRegex()
.find(System.getProperty("sun.java.command"))
?.groupValues?.get(1) ?: fatalError("Could not parse version from command line arguments")
}

fun classExists(name: String): Boolean =
GameInfo::class.java.classLoader.getResourceAsStream("${name.replace('.', '/')}.class") != null

val client = when {
classExists("com.moonsworth.lunar.genesis.Genesis") -> "lunar client"
classExists("net.minecraftforge.fml.common.Loader") -> "forge"
GameInfo.commandLineArgs.contains("labymod") -> "labymod"
else -> "vanilla"
}

System.getProperties()["weave.game.info"] = mapOf(
"version" to version,
"client" to client
)
}

// TODO: give this a good place
val illegalToReload = setOf(
"java.", "javax.", "org.xml.", "org.w3c.", "sun.", "jdk.",
Expand Down

0 comments on commit d27522a

Please sign in to comment.