Skip to content

Commit e194506

Browse files
committed
Run With Auth
1 parent cc9f90a commit e194506

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

build.gradle.kts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import com.google.gson.Gson
12
import com.smushytaco.lwjgl_gradle.Preset
23
import java.nio.file.Files
34

@@ -17,9 +18,62 @@ val javaVersion: Provider<Int> = libs.versions.java.map { it.toInt() }
1718
base.archivesName = modName
1819
group = modGroup.get()
1920
version = modVersion.get()
21+
22+
class AccountsJson(val accounts: List<Account>)
23+
class Account(val profile: Profile, val ygg: YGG)
24+
class YGG(val token: String)
25+
class Profile(val name: String, val id: String)
26+
27+
val prismAccountsFile = providers.provider {
28+
val explicit = providers.gradleProperty("prism.accounts.file").orNull
29+
if (explicit != null) {
30+
val explicitFile = File(explicit)
31+
if (explicitFile.exists()) return@provider explicitFile
32+
}
33+
34+
val home = System.getProperty("user.home")
35+
36+
val candidates = buildList {
37+
// Windows
38+
System.getenv("APPDATA")?.let { add(File(it, "PrismLauncher/accounts.json")) }
39+
System.getenv("HOMEPATH")?.let { add(File(it, "scoop/persist/prismlauncher/accounts.json")) }
40+
// Linux / XDG
41+
val xdgDataHome = System.getenv("XDG_DATA_HOME")
42+
if (xdgDataHome != null) {
43+
add(File(xdgDataHome, "PrismLauncher/accounts.json"))
44+
} else {
45+
add(File(home, ".local/share/PrismLauncher/accounts.json"))
46+
}
47+
// Flatpak
48+
add(File(home, ".var/app/org.prismlauncher.PrismLauncher/data/PrismLauncher/accounts.json"))
49+
// macOS
50+
add(File(home, "Library/Application Support/PrismLauncher/accounts.json"))
51+
}
52+
candidates.firstOrNull(File::exists)
53+
}
54+
2055
loom {
2156
customMinecraftMetadata.set("https://downloads.betterthanadventure.net/bta-client/${libs.versions.btaChannel.get()}/v${libs.versions.bta.get()}/manifest.json")
57+
runs {
58+
prismAccountsFile.orNull?.let { file ->
59+
val account: Provider<Account> = providers.fileContents(layout.file(providers.provider { file }))
60+
.asText
61+
.map { jsonStr ->
62+
val accountNumber = (providers.gradleProperty("prism.accounts.number").orNull?.toInt() ?: 1) - 1
63+
val accounts = Gson().fromJson(jsonStr, AccountsJson::class.java).accounts
64+
accounts.getOrNull(accountNumber.coerceIn(0, accounts.size - 1))
65+
?: error("No PrismLauncher accounts found in ${file.absolutePath}")
66+
}
67+
register("clientAuth") {
68+
inherit(getByName("client"))
69+
configName = "Minecraft Client (Auth)"
70+
val acc = account.get()
71+
programArgs("--username", acc.profile.name, "--uuid", acc.profile.id, "--session", acc.ygg.token)
72+
}
73+
}
74+
}
2275
}
76+
2377
repositories {
2478
mavenCentral()
2579
maven("https://maven.fabricmc.net/") { name = "Fabric" }

0 commit comments

Comments
 (0)