Skip to content

Commit 2f4eb08

Browse files
committed
download everything + fix up launch issues
1 parent b03530b commit 2f4eb08

File tree

6 files changed

+169
-105
lines changed

6 files changed

+169
-105
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ LunarLaunchWrapper is a tiny kotlin wrapper to download and launch Lunar from th
44

55
## How to use
66

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

99
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 :
1010
```json
@@ -39,8 +39,8 @@ If you want to use this on the PrismMC launcher, you will have to create a new i
3939
```
4040
Adapt the above for your version.
4141

42-
## Using weave
42+
## Using Weave
4343

44-
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 :)
44+
If you want to use weave you will have to use a custom version of Weave. You can use the one in the releases :)
4545

46-
Enjoy :)
46+
Enjoy :)

src/main/kotlin/wtf/zani/launchwrapper/LunarLaunchWrapper.kt

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
package wtf.zani.launchwrapper
22

33
import joptsimple.OptionParser
4+
import kotlinx.coroutines.Dispatchers
5+
import kotlinx.coroutines.launch
6+
import kotlinx.coroutines.withContext
47
import wtf.zani.launchwrapper.loader.LibraryLoader
58
import wtf.zani.launchwrapper.loader.LunarLoader
69
import wtf.zani.launchwrapper.version.VersionManifest
710
import kotlin.io.path.Path
811
import kotlin.io.path.createDirectories
912

1013
private const val nativeDirKey = "wtf.zani.launchwrapper.nativedir"
14+
1115
private val offlineDir = Path(System.getProperty("user.home"), ".lunarclient", "offline", "multiver")
16+
private val textureDir = Path(System.getProperty("user.home"), ".lunarclient", "textures")
1217

1318
suspend fun main(args: Array<String>) {
1419
offlineDir.createDirectories()
20+
textureDir.createDirectories()
1521

1622
val optionParser = OptionParser()
1723

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

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

47-
manifest.download(offlineDir)
53+
withContext(Dispatchers.IO) {
54+
launch { version.download(offlineDir) }
55+
launch { textures.download(textureDir) }
56+
}
57+
58+
cache?.write()
4859

4960
val natives =
50-
manifest
61+
version
5162
.artifacts
5263
.filter { it.type == "NATIVES" }
5364
.map {
54-
offlineDir.resolve("$offlineDir/natives")
65+
offlineDir.resolve(it.name.replace(".zip", ""))
5566
}
5667

5768
val classpath =
58-
manifest
69+
version
5970
.artifacts
6071
.filter { it.type == "CLASS_PATH" }
6172
.map { offlineDir.resolve(it.name) }
6273

6374
val externalFiles =
64-
manifest
75+
version
6576
.artifacts
6677
.filter { it.type == "EXTERNAL_FILE" }
6778
.map { it.name }
@@ -76,10 +87,8 @@ suspend fun main(args: Array<String>) {
7687
"--launcherVersion", "3.1.0",
7788
"--classpathDir", offlineDir.toString(),
7889
"--workingDirectory", offlineDir.toString(),
79-
"--ichorClassPath", classpath.joinToString(","),
80-
"-Djava.library.path=$offlineDir/natives",
81-
"--ichorExternalFiles", externalFiles.joinToString(","),
82-
"--textureDir", "$offlineDir/textures"
90+
"--ichorClassPath", classpath.map { it.fileName }.joinToString(","),
91+
"--ichorExternalFiles", externalFiles.joinToString(",")
8392
)
8493

8594
minecraftArgs += args.toList()

src/main/kotlin/wtf/zani/launchwrapper/loader/DefinitionProxy.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
package wtf.zani.launchwrapper.loader
22

3-
import java.net.URLClassLoader
3+
import java.lang.invoke.MethodHandle
4+
import java.lang.invoke.MethodHandles
45

56
@Suppress("unused")
67
object DefinitionProxy {
7-
private val defineClass = ClassLoader::class.java.getDeclaredMethod("defineClass",
8-
String::class.java, ByteArray::class.java, Int::class.java, Int::class.java)
8+
private val defineClass: MethodHandle
99

1010
init {
11-
defineClass.isAccessible = true
11+
val defineClassMethod = ClassLoader::class.java.getDeclaredMethod("defineClass",
12+
String::class.java, ByteArray::class.java, Int::class.java, Int::class.java)
13+
val lookup = MethodHandles.lookup()
14+
15+
defineClassMethod.isAccessible = true
16+
defineClass = lookup.unreflect(defineClassMethod)
1217
}
1318

1419
@JvmStatic
15-
fun defineClass(instance: URLClassLoader, name: String, data: ByteArray, offset: Int, length: Int): Class<*> {
20+
fun defineClass(instance: ClassLoader, name: String, data: ByteArray, offset: Int, length: Int): Class<*> {
1621
val transformed = TransformationHandler.transformClass(data)
17-
?: return defineClass.invoke(instance,
22+
?: return defineClass.invokeExact(instance,
1823
name, data, offset, length) as Class<*>
1924

2025
return defineClass
21-
.invoke(
26+
.invokeExact(
2227
instance,
2328
transformed.first.replace("/", "."),
2429
transformed.second,

src/main/kotlin/wtf/zani/launchwrapper/loader/transformers/GenesisTransformer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class GenesisTransformer : Transformer("com/moonsworth/lunar/") {
1313
.forEach { insn ->
1414
if (insn is MethodInsnNode && insn.owner == node.name && insn.name == "defineClass") {
1515
insn.owner = "wtf/zani/launchwrapper/loader/DefinitionProxy"
16-
insn.desc = "(Ljava/net/URLClassLoader;Ljava/lang/String;[BII)Ljava/lang/Class;"
16+
insn.desc = "(Ljava/lang/ClassLoader;Ljava/lang/String;[BII)Ljava/lang/Class;"
1717
insn.opcode = INVOKESTATIC
1818
}
1919
}

src/main/kotlin/wtf/zani/launchwrapper/util/LunarUtils.kt

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)