Skip to content

Commit

Permalink
download everything + fix up launch issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Zxnii committed Nov 30, 2023
1 parent b03530b commit 2f4eb08
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 105 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ LunarLaunchWrapper is a tiny kotlin wrapper to download and launch Lunar from th

## How to use

To use this, simply start the jar file with the `-module` and `-version` argument as well as the main class `wtf.zani.launchwrapper.LunarLaunchWrapper`
To use this, simply start the jar file with the `--module` and `--version` argument as well as the main class `wtf.zani.launchwrapper.LunarLaunchWrapper`

If you want to use this on the PrismMC launcher, you will have to create a new instance with the version of your choice. Then edit that instance and replace the minecraft jar with LunarLaunchWrapper.jar and replace the content of the file by this :
```json
Expand Down Expand Up @@ -39,8 +39,8 @@ If you want to use this on the PrismMC launcher, you will have to create a new i
```
Adapt the above for your version.

## Using weave
## Using Weave

If you want to use weave you will have to use a custom version of weave. You can use the one directly in the repository :)
If you want to use weave you will have to use a custom version of Weave. You can use the one in the releases :)

Enjoy :)
Enjoy :)
29 changes: 19 additions & 10 deletions src/main/kotlin/wtf/zani/launchwrapper/LunarLaunchWrapper.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package wtf.zani.launchwrapper

import joptsimple.OptionParser
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import wtf.zani.launchwrapper.loader.LibraryLoader
import wtf.zani.launchwrapper.loader.LunarLoader
import wtf.zani.launchwrapper.version.VersionManifest
import kotlin.io.path.Path
import kotlin.io.path.createDirectories

private const val nativeDirKey = "wtf.zani.launchwrapper.nativedir"

private val offlineDir = Path(System.getProperty("user.home"), ".lunarclient", "offline", "multiver")
private val textureDir = Path(System.getProperty("user.home"), ".lunarclient", "textures")

suspend fun main(args: Array<String>) {
offlineDir.createDirectories()
textureDir.createDirectories()

val optionParser = OptionParser()

Expand All @@ -35,7 +41,7 @@ suspend fun main(args: Array<String>) {
val gameVersion = options.valueOf(versionSpec)
val lunarModule = options.valueOf(moduleSpec)

val manifest = VersionManifest.fetch(gameVersion, lunarModule)
val (version, textures, cache) = VersionManifest.fetch(gameVersion, lunarModule)
?: run {
println("WHOOPS!")
println("We failed to fetch the version manifest, this is likely because you are offline and had no cached version.")
Expand All @@ -44,24 +50,29 @@ suspend fun main(args: Array<String>) {
return
}

manifest.download(offlineDir)
withContext(Dispatchers.IO) {
launch { version.download(offlineDir) }
launch { textures.download(textureDir) }
}

cache?.write()

val natives =
manifest
version
.artifacts
.filter { it.type == "NATIVES" }
.map {
offlineDir.resolve("$offlineDir/natives")
offlineDir.resolve(it.name.replace(".zip", ""))
}

val classpath =
manifest
version
.artifacts
.filter { it.type == "CLASS_PATH" }
.map { offlineDir.resolve(it.name) }

val externalFiles =
manifest
version
.artifacts
.filter { it.type == "EXTERNAL_FILE" }
.map { it.name }
Expand All @@ -76,10 +87,8 @@ suspend fun main(args: Array<String>) {
"--launcherVersion", "3.1.0",
"--classpathDir", offlineDir.toString(),
"--workingDirectory", offlineDir.toString(),
"--ichorClassPath", classpath.joinToString(","),
"-Djava.library.path=$offlineDir/natives",
"--ichorExternalFiles", externalFiles.joinToString(","),
"--textureDir", "$offlineDir/textures"
"--ichorClassPath", classpath.map { it.fileName }.joinToString(","),
"--ichorExternalFiles", externalFiles.joinToString(",")
)

minecraftArgs += args.toList()
Expand Down
19 changes: 12 additions & 7 deletions src/main/kotlin/wtf/zani/launchwrapper/loader/DefinitionProxy.kt
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
package wtf.zani.launchwrapper.loader

import java.net.URLClassLoader
import java.lang.invoke.MethodHandle
import java.lang.invoke.MethodHandles

@Suppress("unused")
object DefinitionProxy {
private val defineClass = ClassLoader::class.java.getDeclaredMethod("defineClass",
String::class.java, ByteArray::class.java, Int::class.java, Int::class.java)
private val defineClass: MethodHandle

init {
defineClass.isAccessible = true
val defineClassMethod = ClassLoader::class.java.getDeclaredMethod("defineClass",
String::class.java, ByteArray::class.java, Int::class.java, Int::class.java)
val lookup = MethodHandles.lookup()

defineClassMethod.isAccessible = true
defineClass = lookup.unreflect(defineClassMethod)
}

@JvmStatic
fun defineClass(instance: URLClassLoader, name: String, data: ByteArray, offset: Int, length: Int): Class<*> {
fun defineClass(instance: ClassLoader, name: String, data: ByteArray, offset: Int, length: Int): Class<*> {
val transformed = TransformationHandler.transformClass(data)
?: return defineClass.invoke(instance,
?: return defineClass.invokeExact(instance,
name, data, offset, length) as Class<*>

return defineClass
.invoke(
.invokeExact(
instance,
transformed.first.replace("/", "."),
transformed.second,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class GenesisTransformer : Transformer("com/moonsworth/lunar/") {
.forEach { insn ->
if (insn is MethodInsnNode && insn.owner == node.name && insn.name == "defineClass") {
insn.owner = "wtf/zani/launchwrapper/loader/DefinitionProxy"
insn.desc = "(Ljava/net/URLClassLoader;Ljava/lang/String;[BII)Ljava/lang/Class;"
insn.desc = "(Ljava/lang/ClassLoader;Ljava/lang/String;[BII)Ljava/lang/Class;"
insn.opcode = INVOKESTATIC
}
}
Expand Down
21 changes: 0 additions & 21 deletions src/main/kotlin/wtf/zani/launchwrapper/util/LunarUtils.kt

This file was deleted.

Loading

0 comments on commit 2f4eb08

Please sign in to comment.