Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
cubewhy committed Jan 6, 2024
2 parents 68eb97c + ac61a86 commit 227e324
Show file tree
Hide file tree
Showing 26 changed files with 914 additions and 458 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: gradle
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: build

on:
- push

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
- name: Java setup
uses: actions/setup-java@v3
with:
distribution: "zulu"
java-version: 17
cache: "gradle"
# - name: Set outputs
# id: vars
# run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
- name: Build
run: chmod +x ./gradlew && ./gradlew build
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: celestial
path: build/libs/celestial-*.jar
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@

1. Full open source (GPLv3)
2. No electron
3. No installation needed
4. Ready out of the box
5. External browser login support (In working)
6. Cross-platform (You might need to complete natives)
7. Custom API address ([LunarCN API](https://github.com/CubeWhyMC/website) only)
8. Multi version, one jre
9. Javaagent support (Experimental)
10. LunarCN support (In working)
11. Weave support (In working)
3. Lite, high performance (For example, the downloader)
4. No installation needed
5. Ready out of the box
6. External browser login support
7. Cross-platform (Experimental)
8. Custom API address ([LunarCN API](https://github.com/CubeWhyMC/website) only)
9. Multi version, one jre
10. Javaagent support (Experimental)
11. LunarCN support (In working)
12. Weave support (Experimental)

## Get celestial

Expand All @@ -30,7 +31,7 @@ Donate at [lunarclient.top](https://www.lunarclient.top/donate) (CNY only/仅支
## Translation

All languages except Chinese are translated via Google Translate.
If there are any translation errors, please submit a PR or issue (English)
If there are any translation errors, please submit a PR or an issue (in English)

## License

Expand Down
15 changes: 8 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ plugins {
}

group = 'org.cubewhy.celestial'
version = '1.2-pre1-SNAPSHOT'
version = '1.2-pre4-SNAPSHOT'

println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
println('Celestial Launcher -> https://www.lunarclient.top/celestial')
println('Celestial Launcher -> https://www.lunarclient.top/')

compileJava.options.encoding = "UTF-8"

Expand All @@ -30,12 +30,12 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok:1.18.30'


include 'org.slf4j:slf4j-api:2.0.7'
include 'org.slf4j:slf4j-log4j12:2.0.7'
include 'org.apache.logging.log4j:log4j-api:2.20.0'
include 'org.apache.logging.log4j:log4j-core:2.20.0'
include 'org.slf4j:slf4j-api:2.0.10'
include 'org.slf4j:slf4j-log4j12:2.0.10'
include 'org.apache.logging.log4j:log4j-api:2.22.1'
include 'org.apache.logging.log4j:log4j-core:2.22.1'

include 'com.squareup.okhttp3:okhttp:4.11.0'
include 'com.squareup.okhttp3:okhttp:4.12.0'
include 'com.google.code.gson:gson:2.10.1'
include 'net.sf.jopt-simple:jopt-simple:6.0-alpha-3'
include 'com.formdev:flatlaf:3.3-SNAPSHOT'
Expand All @@ -51,6 +51,7 @@ dependencies {
}

test {
enabled = false
useJUnitPlatform()
}

Expand Down
68 changes: 53 additions & 15 deletions src/main/java/org/cubewhy/celestial/Celestial.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
import org.cubewhy.celestial.game.AuthServer;
import org.cubewhy.celestial.game.GameArgs;
import org.cubewhy.celestial.game.GameArgsResult;
import org.cubewhy.celestial.game.JavaAgent;
import org.cubewhy.celestial.game.addon.JavaAgent;
import org.cubewhy.celestial.gui.GuiLauncher;
import org.cubewhy.celestial.utils.*;
import org.cubewhy.celestial.utils.game.MinecraftData;
import org.cubewhy.celestial.utils.lunar.LauncherData;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
Expand All @@ -31,27 +32,32 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;

import static org.cubewhy.celestial.gui.GuiLauncher.statusBar;

@Slf4j
public class Celestial {


public static final File configDir = new File(System.getProperty("user.home"), ".cubewhy/lunarcn");
public static final File themesDir = new File(configDir, "themes");
public static final ConfigFile config = new ConfigFile(new File(configDir, "celestial.json"));
public static Locale locale;
public static String userLanguage;
public static ResourceBundle f;

public static LauncherData launcherData;
public static JsonObject metadata;
public static JsonObject minecraftManifest;
public static GuiLauncher launcherFrame;
public static boolean themed = true;
public static String os = System.getProperty("os.name");
public static final File launchScript = new File(configDir, (os.contains("Windows")) ? "launch.bat" : "launch.sh");
public static final File gameLogFile = new File(configDir, "logs/game.log");
public static final File launcherLogFile = new File(configDir, "logs/launcher.log");
public static final boolean isDevelopMode = System.getProperties().containsKey("dev-mode");
public static long gamePid = 0;
public static final AtomicLong gamePid = new AtomicLong();
public static File sessionFile;

static {
Expand All @@ -65,6 +71,8 @@ public class Celestial {
}

public static void main(String[] args) throws Exception {
// set encoding
System.setProperty("file.encoding", "UTF-8");
log.info("Celestial v" + GitUtils.getBuildVersion() + " build by " + GitUtils.getBuildUser());
try {
System.setProperty("file.encoding", "UTF-8");
Expand Down Expand Up @@ -182,17 +190,15 @@ private static void checkJava() throws IOException {
JOptionPane.showMessageDialog(null, f.getString("compatibility.warn.message"), f.getString("compatibility.warn.title"), JOptionPane.WARNING_MESSAGE);
}

// detect the official launcher (Windows only)
if (OSEnum.getCurrent().equals(OSEnum.Windows)) {
if (sessionFile.exists() && LunarUtils.isReallyOfficial(sessionFile)) {
log.warn("Detected the official launcher");
JOptionPane.showMessageDialog(null, f.getString("warn.official-launcher.message"), f.getString("warn.official-launcher.title"), JOptionPane.WARNING_MESSAGE);
}
if (sessionFile.exists() && LunarUtils.isReallyOfficial(sessionFile)) {
log.warn("Detected the official launcher");
JOptionPane.showMessageDialog(null, f.getString("warn.official-launcher.message"), f.getString("warn.official-launcher.title"), JOptionPane.WARNING_MESSAGE);
}
}

public static void initLauncher() throws IOException {
metadata = launcherData.metadata();
minecraftManifest = MinecraftData.manifest();
if (metadata.has("error")) {
// trouble here
log.error("Metadata info: " + metadata);
Expand All @@ -201,6 +207,14 @@ public static void initLauncher() throws IOException {
}

private static void initConfig() {
// init dirs
if (configDir.mkdirs()) {
log.info("Making config dir");
}
if (themesDir.mkdirs()) {
log.info("Making themes dir");
}
// init config
JsonObject resize = new JsonObject();
resize.addProperty("width", 854);
resize.addProperty("height", 480);
Expand Down Expand Up @@ -262,7 +276,7 @@ public static void initTheme() throws IOException {
themed = false;
}
default -> {
File themeFile = new File(configDir, "themes/" + themeType);
File themeFile = new File(themesDir, themeType);
if (!themeFile.exists()) {
// cannot load custom theme without theme.json
JOptionPane.showMessageDialog(null, f.getString("theme.custom.notfound.message"), f.getString("theme.custom.notfound.title"), JOptionPane.WARNING_MESSAGE);
Expand Down Expand Up @@ -426,14 +440,17 @@ public static File launch(String version, String branch, String module) throws I
if (launchScript.createNewFile()) {
log.info("Launch script was created");
}
try (FileWriter writer = new FileWriter(launchScript)) {
try (FileWriter writer = new FileWriter(launchScript, StandardCharsets.UTF_8)) {
if (OSEnum.getCurrent().equals(OSEnum.Windows)) {
// Microsoft Windows
writer.write("@echo off\n");
writer.write("rem Generated by LunarCN (Celestial Launcher)\nrem Website: https://www.lunarclient.top/\n");
writer.write("rem Please donate to support us to continue develop https://www.lunarclient.top/donate\n");
writer.write("rem You can run this script to debug your game, or share this script to developers to resolve your launch problem\n");
writer.write("cd /d " + installationDir + "\n");
// NEW: Use CRLF (Windows 7)
writer.write("@echo off\r\n");
writer.write("chcp 65001\r\n"); // unicode support for Windows which uses Chinese
writer.write("@rem Generated by LunarCN (Celestial Launcher)\r\n@rem Website: https://www.lunarclient.top/\r\n");
writer.write(String.format("@rem Version %s\r\n", GitUtils.getBuildVersion()));
writer.write("@rem Please donate to support us to continue develop https://www.lunarclient.top/donate\r\n");
writer.write("@rem You can run this script to debug your game, or share this script to developers to resolve your launch problem\r\n");
writer.write("cd /d " + installationDir + "\r\n");
} else {
// Others
writer.write("#!/bin/bash\n");
Expand Down Expand Up @@ -499,5 +516,26 @@ public synchronized static void checkUpdate(String version, String module, Strin
File file = new File(installation, "textures/" + fileName);
DownloadManager.download(new Downloadable(url, file, full[full.length - 1]));
});

File minecraftFolder = new File(config.getValue("game-dir").getAsString());

// TODO vanilla Minecraft textures
statusBar.setText("Complete textures for vanilla Minecraft");
JsonObject textureIndex = MinecraftData.getTextureIndex(Objects.requireNonNull(MinecraftData.getVersion(version, minecraftManifest)));
// dump to .minecraft/assets/indexes
File assetsFolder = new File(minecraftFolder, "assets");
File indexFile = new File(assetsFolder, "indexes/" + String.join(".", Arrays.copyOfRange(version.split("\\."), 0, 2)) + ".json");
org.apache.commons.io.FileUtils.writeStringToFile(indexFile, new Gson().toJson(textureIndex), StandardCharsets.UTF_8);

Map<String, JsonElement> objects = textureIndex.getAsJsonObject("objects").asMap();
// baseURL/hash[0:2]/hash
for (JsonElement s : objects.values()) {
JsonObject resource = s.getAsJsonObject();
String hash = resource.get("hash").getAsString();
String folder = hash.substring(0, 2);
URL finalURL = new URL(String.format("%s/%s/%s", MinecraftData.texture, folder, hash));
File finalFile = new File(assetsFolder, "objects/" + folder + "/" + hash);
DownloadManager.download(new Downloadable(finalURL, finalFile, hash));
}
}
}
30 changes: 30 additions & 0 deletions src/main/java/org/cubewhy/celestial/event/impl/AddonAddEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Celestial Launcher <me@lunarclient.top>
* License under GPLv3
* Do NOT remove this note if you want to copy this file.
*/

package org.cubewhy.celestial.event.impl;

import org.cubewhy.celestial.event.Event;
import org.cubewhy.celestial.game.BaseAddon;

import java.io.File;

public class AddonAddEvent extends Event {

public final Type type;
public final BaseAddon addon;

public enum Type {
JAVAAGENT,
WEAVE,
LUNARCN;
}

public AddonAddEvent(Type type, BaseAddon addon) {
this.type = type;
this.addon = addon;
}

}
5 changes: 4 additions & 1 deletion src/main/java/org/cubewhy/celestial/files/ConfigFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.extern.slf4j.Slf4j;

import java.io.*;
import java.nio.charset.StandardCharsets;

@Slf4j
public class ConfigFile {
Expand Down Expand Up @@ -84,7 +85,7 @@ public ConfigFile load() {

while (!successful) {
try {
bufferedReader = new BufferedReader(new FileReader(this.file));
bufferedReader = new BufferedReader(new FileReader(this.file, StandardCharsets.UTF_8));
config = gson.fromJson(bufferedReader, JsonObject.class);
if (config == null) {
config = new JsonObject();
Expand All @@ -100,6 +101,8 @@ public ConfigFile load() {
} catch (IOException ex) {
throw new RuntimeException(ex);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Celestial Launcher <me@lunarclient.top>
* License under GPLv3
* Do NOT remove this note if you want to copy this file.
*/

package org.cubewhy.celestial.files.sources;

import java.net.URL;

public interface DownloadSource {
// TODO complete this class
URL getBaseURL();
}
35 changes: 35 additions & 0 deletions src/main/java/org/cubewhy/celestial/game/BaseAddon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Celestial Launcher <me@lunarclient.top>
* License under GPLv3
* Do NOT remove this note if you want to copy this file.
*/

package org.cubewhy.celestial.game;

import org.apache.commons.io.FileUtils;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
import java.util.List;

public abstract class BaseAddon {
@Contract(pure = true)
public static List<? extends BaseAddon> findAll() {
return null;
}

protected static File autoCopy(File file, File folder) throws IOException {
String name = file.getName();
if (!name.endsWith(".jar")) {
name += ".jar"; // adds an ends with for the file
}
File target = new File(folder, name);
if (target.exists()) {
return null;
}
FileUtils.copyFile(file, target);
return target;
}
}
Loading

0 comments on commit 227e324

Please sign in to comment.