Skip to content

Commit 73ee6e9

Browse files
committed
0.1
1 parent 2c098a2 commit 73ee6e9

18 files changed

Lines changed: 514 additions & 0 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/.idea
2+
/build
3+
/.gradle
4+
/run

build.gradle.kts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
plugins {
2+
kotlin("jvm") version "1.5.31"
3+
}
4+
5+
group = "org.bundleproject"
6+
version = "0.1"
7+
8+
repositories {
9+
mavenCentral()
10+
}
11+
12+
dependencies {
13+
val ktorVersion: String by project
14+
15+
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.5.31")
16+
implementation("org.jetbrains.kotlin:kotlin-reflect:1.5.31")
17+
18+
implementation("io.ktor:ktor-client-core:$ktorVersion")
19+
implementation("io.ktor:ktor-client-apache:$ktorVersion")
20+
implementation("io.ktor:ktor-client-gson:$ktorVersion")
21+
}

gradle/wrapper/gradle-wrapper.jar

58.1 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

gradlew

Lines changed: 185 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 89 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rootProject.name = "Launchwrapper"
2+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.bundleproject.launchwrapper
2+
3+
import org.bundleproject.launchwrapper.utils.bundleClassName
4+
import org.bundleproject.launchwrapper.utils.err
5+
import org.bundleproject.launchwrapper.utils.get
6+
import org.bundleproject.launchwrapper.utils.info
7+
import java.io.File
8+
import kotlin.reflect.KClass
9+
import kotlin.reflect.full.callSuspend
10+
import kotlin.reflect.full.createType
11+
import kotlin.reflect.full.functions
12+
import kotlin.reflect.full.primaryConstructor
13+
14+
val fallbackEntrypoints = arrayOf(
15+
"net.fabricmc.loader.launch.knot.KnotClient",
16+
"cpw.mods.bootstraplauncher.BootstrapLauncher",
17+
"net.minecraft.launchwrapper.Launch",
18+
"org.bookmc.loader.impl.launch.Quilt",
19+
"com.github.glassmc.loader.client.GlassClientMain",
20+
"net.minecraft.client.main.Main", // just in case user installed to vanilla
21+
)
22+
23+
suspend fun launch(args: Array<String>, gameDir: File, classLoader: ClassLoader) {
24+
(args["bundleMainClass"]?.let { Class.forName(it).kotlin } ?: findEntrypoint())?.run {
25+
val version = args["version"]
26+
?.takeIf { it != "MultiMC5" }
27+
val modFolderName = "mods"
28+
29+
val bundleClass = runCatching { Class.forName(bundleClassName, true, classLoader).kotlin }
30+
.onFailure {
31+
err("Bundle is not in the classpath! Cannot launch bundle!")
32+
return@launch
33+
}
34+
.getOrThrow()
35+
36+
info("Invoking constructor...")
37+
bundleClass.constructors.find { it.typeParameters[1] == String::class.createType() }
38+
?.call(gameDir, version, modFolderName)
39+
40+
info("Starting Bundle... Goodbye, Launchwrapper...")
41+
bundleClass.functions.find { it.name == "start" }?.callSuspend()
42+
}
43+
}
44+
45+
private fun findEntrypoint(): KClass<*>? {
46+
err("Relying on fallback entrypoint! Please re-install bundle!")
47+
fallbackEntrypoints.forEach {
48+
runCatching { Class.forName(it) }
49+
.onSuccess { return it.kotlin }
50+
}
51+
52+
return null
53+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.bundleproject.launchwrapper
2+
3+
import java.io.File
4+
import java.net.URLClassLoader
5+
6+
fun load(gameDir: File, version: String): URLClassLoader {
7+
val bundleFolder = File(gameDir, "bundle")
8+
val jarsFolder = File(bundleFolder, "jars")
9+
10+
val bundleJar = File(jarsFolder, "bundle-$version.jar")
11+
val bundleJarUrl = bundleJar.toURI().toURL()
12+
13+
return URLClassLoader(arrayOf(bundleJarUrl))
14+
}

0 commit comments

Comments
 (0)