Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed LunarLaunchWrapper for latest lunar version + Added Readme #1

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.gradle
build/

!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
Expand Down
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
# LunarLaunchWrapper

LunarLaunchWrapper is a tiny kotlin wrapper to download and launch Lunar from the CLI or from a Minecraft launcher of your choice.

## 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`

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
{
"assetIndex": {
"id": "1.8",
"sha1": "f6ad102bcaa53b1a58358f16e376d548d44933ec",
"size": 78494,
"totalSize": 114885064,
"url": "https://piston-meta.mojang.com/v1/packages/f6ad102bcaa53b1a58358f16e376d548d44933ec/1.8.json"
},
"formatVersion": 1,
"libraries": [],
"mainClass": "wtf.zani.launchwrapper.LunarLaunchWrapperKt",
"mainJar": {
"downloads": {
"artifact": {
"sha1": "3870888a6c3d349d3771a3e9d16c9bf5e076b908",
"size": 8461484,
"url": "https://launcher.mojang.com/v1/objects/3870888a6c3d349d3771a3e9d16c9bf5e076b908/client.jar"
}
},
"name": "com.mojang:minecraft:1.8.9:client"
},
"minecraftArguments": "--username ${auth_player_name} --version ${version_name} -module lunar --gameDir ${game_directory} --assetsDir ${assets_root} --assetIndex ${assets_index_name} --uuid ${auth_uuid} --accessToken ${auth_access_token} --userProperties ${user_properties} --userType ${user_type}",
"name": "Minecraft",
"releaseTime": "2015-12-03T09:24:39+00:00",
"type": "release",
"uid": "net.minecraft",
"version": "1.8.9"
}
```
Adapt the above for your version.

## 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 :)

Enjoy :)
Binary file added Weave-Loader-Patched-0.2.4.jar
Binary file not shown.
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,5 @@ task("run", type = JavaExec::class) {

args = listOf("--version", "1.8.9", "--module", "lunar")
jvmArgs = listOf("--add-opens", "java.base/java.io=ALL-UNNAMED", "--add-opens", "java.base/java.lang=ALL-UNNAMED")

classpath = sourceSets.main.get().runtimeClasspath
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
kotlin.code.style=official
org.gradle.unsafe.watch-fs=true
7 changes: 5 additions & 2 deletions src/main/kotlin/wtf/zani/launchwrapper/LunarLaunchWrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ suspend fun main(args: Array<String>) {
.artifacts
.filter { it.type == "NATIVES" }
.map {
offlineDir.resolve(it.name.replace(".zip", ""))
offlineDir.resolve("$offlineDir/natives")
}

val classpath =
Expand All @@ -76,7 +76,10 @@ suspend fun main(args: Array<String>) {
"--launcherVersion", "3.1.0",
"--classpathDir", offlineDir.toString(),
"--workingDirectory", offlineDir.toString(),
"--ichorExternalFiles", externalFiles.joinToString(",")
"--ichorClassPath", classpath.joinToString(","),
"-Djava.library.path=$offlineDir/natives",
"--ichorExternalFiles", externalFiles.joinToString(","),
"--textureDir", "$offlineDir/textures"
)

minecraftArgs += args.toList()
Expand Down
21 changes: 21 additions & 0 deletions src/main/kotlin/wtf/zani/launchwrapper/util/LunarUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package wtf.zani.launchwrapper.util

import java.io.File
import java.io.FileNotFoundException
import kotlin.system.exitProcess

class LunarUtils {
companion object {
fun getInstallationId(): String {
var installationId = ""
try {
installationId = File( "${System.getProperty("user.home")}/.lunarclient/launcher-cache/installation-id").readLines()[0]
} catch(_: FileNotFoundException) {
println("You must run lunar at least once before using this, exiting...")
exitProcess(1)
}
return installationId
}
}

}
14 changes: 10 additions & 4 deletions src/main/kotlin/wtf/zani/launchwrapper/version/VersionManifest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import wtf.zani.launchwrapper.util.LunarUtils
import wtf.zani.launchwrapper.util.SystemInfo
import wtf.zani.launchwrapper.util.toHexString
import java.io.File
Expand All @@ -26,15 +27,17 @@ private data class ManifestResponse(

@Serializable
data class LauncherInfo(
@SerialName("installation_id")
val installationId: String,
val os: String,
@SerialName("os_release")
val osRelease: String = "0",
val arch: String,
val module: String,
val launchType: String = "OFFLINE",
val version: String,
val branch: String = "master",
val launcherVersion: String = "3.1.0",
@SerialName("launcher_version")
val launcherVersion: String = "3.1.3",
val hwid: String = ""
) {
@Transient
Expand All @@ -53,6 +56,7 @@ data class Artifact(
data class VersionManifest(
val artifacts: List<Artifact>
) {

suspend fun download(directory: Path) {
artifacts
.forEach { artifact ->
Expand Down Expand Up @@ -117,6 +121,7 @@ data class VersionManifest(
val systemInfo = SystemInfo.get()

val launcherInfo = LauncherInfo(
installationId = LunarUtils.getInstallationId(),
os = systemInfo.os.internalName,
arch = systemInfo.arch,
osRelease = systemInfo.os.version(),
Expand All @@ -125,19 +130,20 @@ data class VersionManifest(
)

val cacheFile = File(launcherInfo.cacheName)

println(json.encodeToString(launcherInfo))
return try {
val rawResponse = httpClient.post("https://api.lunarclientprod.com/launcher/launch") {
header("Content-Type", "application/json")
setBody(
json.encodeToString(launcherInfo)
)
}.bodyAsText()
println(rawResponse)

val response = json.decodeFromString<ManifestResponse>(rawResponse)

if (!response.success) {
throw Exception("Failed to fetch manifest")
throw Exception("Failed to fetch manifest : ")
}

cacheFile.writeText(json.encodeToString(response.launchTypeData!!))
Expand Down