Skip to content

Commit

Permalink
Launch game via celewrap (Experimental)
Browse files Browse the repository at this point in the history
  • Loading branch information
cubewhy committed Jun 1, 2024
1 parent 16d1918 commit bf0da87
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
1. Full open source (GPLv3)
2. No electron
3. Lite, high performance (For example, the downloader)
3. Lite, high performance
4. No installation needed
5. Ready out of the box
6. External browser login support
Expand Down Expand Up @@ -44,7 +44,7 @@ If there are any translation errors, please submit a PR or an issue (in English)

## License

Celestial license under GPLv3
Celestial is licensed under GPLv3

You're allowed

Expand Down
39 changes: 29 additions & 10 deletions src/main/kotlin/org/cubewhy/celestial/Celestial.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ package org.cubewhy.celestial
import com.formdev.flatlaf.FlatDarkLaf
import com.formdev.flatlaf.FlatLightLaf
import com.formdev.flatlaf.IntelliJTheme
import com.google.gson.*
import com.google.gson.Gson
import com.google.gson.JsonParser
import kotlinx.serialization.json.Json
import org.apache.commons.io.FileUtils
import org.cubewhy.celestial.event.impl.CreateLauncherEvent
Expand All @@ -19,7 +20,10 @@ import org.cubewhy.celestial.game.AuthServer
import org.cubewhy.celestial.game.GameArgs
import org.cubewhy.celestial.game.addon.JavaAgent
import org.cubewhy.celestial.gui.GuiLauncher
import org.cubewhy.celestial.utils.*
import org.cubewhy.celestial.utils.CrashReportType
import org.cubewhy.celestial.utils.GitUtils
import org.cubewhy.celestial.utils.OSEnum
import org.cubewhy.celestial.utils.currentJavaExec
import org.cubewhy.celestial.utils.game.MinecraftData
import org.cubewhy.celestial.utils.game.MinecraftManifest
import org.cubewhy.celestial.utils.lunar.GameArtifactInfo
Expand Down Expand Up @@ -118,6 +122,7 @@ fun main() {
System.setProperty("file.encoding", "UTF-8")
log.info("Celestial v${GitUtils.buildVersion} build by ${GitUtils.buildUser}")
log.info("Git remote: ${GitUtils.remote} (${GitUtils.branch})")
log.info("Classpath: ${System.getProperty("java.class.path")}")
try {
System.setProperty("file.encoding", "UTF-8")
run()
Expand Down Expand Up @@ -269,13 +274,14 @@ private fun checkJava() {
}

if (sessionFile.exists() && sessionFile.isReallyOfficial()) {
log.warn("Detected the official launcher")
JOptionPane.showMessageDialog(
null,
f.getString("warn.official-launcher.message"),
f.getString("warn.official-launcher.title"),
JOptionPane.WARNING_MESSAGE
)
log.warn("session.json exists, did you forgot to close the official lc launcher?")
// the latest lc launcher doesn't use port 28189, so we needn't let user knows this thing.
// JOptionPane.showMessageDialog(
// null,
// f.getString("warn.official-launcher.message"),
// f.getString("warn.official-launcher.title"),
// JOptionPane.WARNING_MESSAGE
// )
}
}

Expand Down Expand Up @@ -403,6 +409,7 @@ fun getArgs(
if (cn.state) {
val file = cn.installationDir
log.info("LunarCN enabled! $file")
log.warn("LunarCN might not working probably at the latest version of LunarClient")
javaAgents.add(JavaAgent(file))
}
if (lcqt.state) {
Expand Down Expand Up @@ -446,13 +453,25 @@ fun getArgs(
}
}
}
if (config.launchWrap) {
// [celewrap] add Celestial's classpath
log.info("CeleWrap is enabled")
classpath.add(System.getProperty("java.class.path")) // fixme squid
}
if (OSEnum.Windows.isCurrent) {
args.add(classpath.joinToString(";"))
} else {
args.add(classpath.joinToString(":"))
}
// === main class ===
args.add(LauncherData.getMainClass(json))
val mainClass = LauncherData.getMainClass(json)
if (config.launchWrap) {
// using celestial
args.add("-DlunarMain=$mainClass")
args.add("org.cubewhy.celestial.game.CeleWrapKt") // celestial wrapper
} else {
args.add(mainClass)
}
// === game args ===
val ichorEnabled = LauncherData.getIchorState(json)
args.add("--version $version") // what version will lunarClient inject
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/org/cubewhy/celestial/Configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ data class BasicConfig(
var maxThreads: Int = Runtime.getRuntime().availableProcessors() * 2,
var addon: AddonConfiguration = AddonConfiguration(),
var proxy: ProxyConfig = ProxyConfig(),
var connectMethod: ConnectMethod = ConnectMethod.DISABLE
var connectMethod: ConnectMethod = ConnectMethod.DISABLE,
var launchWrap: Boolean = true
) {

enum class ConnectMethod {
ATTACH, // using the attachment API to inject LunarClient (recommend)
CMDLINE, // using the "-javaagent" parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,33 @@ import co.gongzh.procbridge.IDelegate
import co.gongzh.procbridge.Server
import com.google.gson.JsonObject
import org.cubewhy.celestial.event.impl.AuthEvent
import org.cubewhy.celestial.utils.GitUtils
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.net.URL
import kotlin.system.exitProcess

fun main(args: Array<String>) {
// lc wrapper
val mainClassName = System.getProperty("lunarMain")
if (mainClassName == null) {
println("Main class not set, did you launch the game from celestial?")
exitProcess(1)
}
println("[Celestial] LC Wrapper is working!")
println("[Celestial] celestial version: v${GitUtils.buildVersion}")
println("[Celestial] LC main class: $mainClassName")
println("[Celestial] Current classpath: ${System.getProperty("java.class.path")}")
println("[Celestial] Getting main function via reflection")
val lunarMain = Class.forName(mainClassName)
val mainFunction = lunarMain.getDeclaredMethod("main", Array<String>::class.java)
mainFunction.invoke(lunarMain.getConstructor().newInstance(), args)
// println("[Celestial] starting IPC listener...")
// todo ipc

}

// Please notice that: Moonsworth changed its auth method since 2024/4, AuthServer is now deprecated
class AuthServer private constructor() {
private val server: Server = Server(28189, IDelegate { method: String?, args: Any? ->
try {
Expand All @@ -39,7 +62,9 @@ class AuthServer private constructor() {
*/
private fun handleRequest(method: String, args: Any?): Map<String, String> {
val result = HashMap<String, String>()
log.info("Received request! Method: $method")
if (method == "open-window" && args is JsonObject) {
// Old auth function
// Pop a token url
val url = URL(args.get("url").asString)
val auth = (AuthEvent(url).call() as AuthEvent).waitForAuth()
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/cubewhy/celestial/gui/GuiLauncher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class GuiLauncher : JFrame() {

private fun findExistGame() {
try {
val java = findJava(getMainClass(null))
val java = if (config.launchWrap) findJava("org.cubewhy.celestial.game.CeleWrapKt") else findJava(getMainClass(null))
if (java != null) {
val pid = java.id()
log.info("Exist game process found! Pid: $pid")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ class GuiSettings : JScrollPane(panel, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_
)
)
panelLauncher.add(p6)
// cele wrap
panelLauncher.add(getAutoSaveCheckBox(config, "launchWrap", f.getString("gui.settings.launcher.celewrap")))
// max-threads
val p7 = JPanel()
p7.add(JLabel(f.getString("gui.settings.launcher.max-threads")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import org.cubewhy.celestial.JSON
import org.cubewhy.celestial.config
import org.cubewhy.celestial.event.impl.CrashReportUploadEvent
import org.cubewhy.celestial.game.AddonMeta
import org.cubewhy.celestial.game.RemoteAddon
Expand Down Expand Up @@ -131,10 +132,11 @@ class LauncherData(val api: URI = URI.create("https://api.lunarclientprod.com"))
* @param json Json of the special LunarClient instance
* @return main class of the LunarClient instance
*/
fun getMainClass(json: GameArtifactInfo? = null) =
fun getMainClass(json: GameArtifactInfo? = null): String =
json?.launchTypeData?.mainClass ?: "com.moonsworth.lunar.genesis.Genesis"



/**
* Get ICHOR state
*
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/languages/launcher.properties
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,5 @@ gui.news.empty=You got an empty button!
gui.news.api.reopen=API setup is successful, reopen Celestial to see the effect!
gui.news.api.confirm=Are you sure you want to switch the API to %s?\n\
Unknown APIs may carry viruses, please decide with caution.
gui.settings.launcher.celewrap=CeleWrap
1 change: 1 addition & 0 deletions src/main/resources/languages/launcher_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,4 @@ gui.news.empty=You got an empty button!
gui.news.api.reopen=API setup is successful, reopen Celestial to see the effect!
gui.news.api.confirm=Are you sure you want to switch the API to %s?\n\
Unknown APIs may carry viruses, please decide with caution.
gui.settings.launcher.celewrap=CeleWrap
1 change: 1 addition & 0 deletions src/main/resources/languages/launcher_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,5 @@ gui.news.empty=これは空のボタンです!
gui.news.api.reopen=API のセットアップが成功しました。Celestial を再度開いて効果を確認してください。
gui.news.api.confirm=API を %s に切り替えてもよろしいですか?\n\
未知の API にはウイルスが感染している可能性がありますので、慎重に決定してください。
gui.settings.launcher.celewrap=CeleWrap

1 change: 1 addition & 0 deletions src/main/resources/languages/launcher_ko.properties
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,5 @@ gui.news.empty=이것은 빈 버튼입니다!
gui.news.api.reopen=API 설정이 성공했습니다. Celestial을 다시 열어 효과를 확인하세요!
gui.news.api.confirm=API를 %s(으)로 전환하시겠습니까?\n\
알 수 없는 API에는 바이러스가 있을 수 있으므로 신중하게 결정하시기 바랍니다.
gui.settings.launcher.celewrap=CeleWrap

1 change: 1 addition & 0 deletions src/main/resources/languages/launcher_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,5 @@ gui.news.empty=这是个空按纽!
gui.news.api.reopen=API设置成功, 重新打开Celestial以查看效果!
gui.news.api.confirm=确认将API切换到 %s 吗?\n\
未知的API可能携带病毒, 请谨慎决定.
gui.settings.launcher.celewrap=CeleWrap

0 comments on commit bf0da87

Please sign in to comment.