Lots of backend work

This commit is contained in:
Steven Tracey 2022-04-09 18:35:02 -04:00
parent 02ef8b3bd1
commit 42d168ca21
21 changed files with 513 additions and 283 deletions

View File

@ -26,5 +26,10 @@
<option name="name" value="maven2" />
<option name="url" value="https://repo.nevets.tech/repository/maven-public" />
</remote-repository>
<remote-repository>
<option name="id" value="maven3" />
<option name="name" value="maven3" />
<option name="url" value="https://europe-maven.pkg.dev/jxbrowser/releases" />
</remote-repository>
</component>
</project>

View File

@ -1,5 +1,3 @@
import edu.sc.seis.launch4j.tasks.Launch4jLibraryTask
plugins {
id 'java'
id 'com.github.johnrengelman.shadow' version '5.2.0'
@ -7,7 +5,7 @@ plugins {
}
group 'tech.nevets.jaml'
version '0.7.1'
version '0.8.0'
def build = 'dev'
repositories {
@ -31,6 +29,7 @@ dependencies {
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'net.arikia.dev:drpc:1.0'
implementation 'commons-io:commons-io:2.11.0'
//implementation 'com.microsoft.azure.msal4j:1.11.3'
}
shadowJar {

View File

@ -1,15 +0,0 @@
{
"platform": "windows64",
"jdk": "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.2%2B8/OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8.zip",
"executable": "JAML",
"jrePath": "",
"mainclass": "tech.nevets.jaml.JAML",
"vmargs": [
"Xmx2G"
],
"resources": [
"../src/main/resources"
],
"minimizejre": "soft",
"output": "packr-out"
}

Binary file not shown.

View File

@ -0,0 +1,4 @@
package tech.nevets.jaml;
public class AutoUpdater {
}

View File

@ -48,6 +48,7 @@ public class Config {
YML_FILE.setComment("java.jdk8", "Set these to the bin directory of each JDK version");
YML_FILE.addDefault("java.jdk16", "");
YML_FILE.addDefault("java.jdk17", "");
YML_FILE.addDefault("game.show-snapshots", false);
YML_FILE.addDefault("launcher.default-profile", "default");
YML_FILE.setComment("launcher.default-profile", "Set's the profile that will be loaded automatically");
YML_FILE.addDefault("launcher.path","default");
@ -58,7 +59,8 @@ public class Config {
YML_FILE.setComment("launcher.first-launch", "Do Not Change, will regenerate files");
YML_FILE.addDefault("launcher.verbose", false);
YML_FILE.setComment("launcher.verbose", "If true, will print out all the messages");
YML_FILE.addDefault("launcher.version", "0.1.0");
YML_FILE.addDefault("launcher.version", JAML.VERSION);
YML_FILE.set("launcher.version", JAML.VERSION);
YML_FILE.setComment("launcher.version", "Jaml version, don't change it!");
try {
@ -90,91 +92,3 @@ public class Config {
YML_FILE.set(path, data);
}
}
//package tech.nevets.jaml.util;
//
//import org.simpleyaml.configuration.file.YamlFile;
//import tech.nevets.jaml.JAML;
//
//import java.io.IOException;
//
//public class Config {
// private static final YamlFile YML_FILE = new YamlFile(JAML.path + "\\config.yml");
//
// public static void loadConfig() {
// try {
// if (!YML_FILE.exists()) {
// System.out.println("Config file not found, creating new one...");
// YML_FILE.createNewFile(true);
// System.out.println("Config file created!");
// } else {
// System.out.println("Loading Config file...");
// YML_FILE.loadWithComments();
// System.out.println("Config file loaded!");
// }
// } catch (final Exception e) {
// System.out.println("Error while loading config file!");
// e.printStackTrace();
// }
//
// YML_FILE.setComment("java",
// "\n"
// + " JJJJJJJJJJJ AAA MMMMMMMM MMMMMMMM LLLLLLLLLLL \n"
// + " J:::::::::J A:::A M:::::::M M:::::::M L:::::::::L \n"
// + " J:::::::::J A:::::A M::::::::M M::::::::M L:::::::::L \n"
// + " JJ:::::::JJ A:::::::A M:::::::::M M:::::::::M LL:::::::LL \n"
// + " J:::::J A:::::::::A M::::::::::M M::::::::::M L:::::L \n"
// + " J:::::J A:::::A:::::A M:::::::::::M M:::::::::::M L:::::L \n"
// + " J:::::J A:::::A A:::::A M:::::::M::::M M::::M:::::::M L:::::L \n"
// + " J:::::j A:::::A A:::::A M::::::M M::::M M::::M M::::::M L:::::L \n"
// + " J:::::J A:::::A A:::::A M::::::M M::::M::::M M::::::M L:::::L \n"
// + " JJJJJJJ J:::::J A:::::AAAAAAAAA:::::A M::::::M M:::::::M M::::::M L:::::L \n"
// + " J:::::J J:::::J A:::::::::::::::::::::A M::::::M M:::::M M::::::M L:::::L \n"
// + " J::::::J J::::::J A:::::AAAAAAAAAAAAA:::::A M::::::M MMMMM M::::::M L:::::L LLLLLL\n"
// + " J:::::::JJJ:::::::J A:::::A A:::::A M::::::M M::::::M LL:::::::LLLLLLLLL:::::L\n"
// + " JJ:::::::::::::JJ A:::::A A:::::A M::::::M M::::::M L::::::::::::::::::::::L\n"
// + " JJ:::::::::JJ A:::::A A:::::A M::::::M M::::::M L::::::::::::::::::::::L\n"
// + " JJJJJJJJJ AAAAAAA AAAAAAA MMMMMMMM MMMMMMMM LLLLLLLLLLLLLLLLLLLLLLLL\n"
// );
//
// YML_FILE.addDefault("java.jdk8", "");
// YML_FILE.setComment("java.jdk8", "Set these to the bin directory of each JDK version");
// YML_FILE.addDefault("java.jdk16", "");
// YML_FILE.addDefault("java.jdk17", "");
// YML_FILE.addDefault("game.skin", "");
// YML_FILE.setComment("game.skin", "Current skin being used, DO NOT change this");
// YML_FILE.addDefault("launcher.default-profile", "default");
// YML_FILE.setComment("launcher.default-profile", "Set's the profile that will be loaded automatically");
// YML_FILE.addDefault("launcher.path","default");
// YML_FILE.setComment("launcher.path","Path to JAML files\n" + "default: " + JAML.path.toString());
// YML_FILE.addDefault("launcher.first-launch", true);
// YML_FILE.setComment("launcher.first-launch", "Do Not Change, will regenerate files");
// YML_FILE.addDefault("launcher.verbose", false);
// YML_FILE.setComment("launcher.verbose", "If true, will print out all the messages");
// YML_FILE.addDefault("launcher.version", "0.1.0");
// YML_FILE.setComment("launcher.version", "Jaml version, don't change it!");
//
// try {
// YML_FILE.save();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// public static YamlFile getConfig() {
// return YML_FILE;
// }
//
// public static void saveConfig() {
// try {
// YML_FILE.save();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// public static void setValue(String path, Object data) {
// YML_FILE.set(path, data);
// }
//}

View File

@ -7,11 +7,10 @@ import java.nio.file.Path;
public class JAML {
public static Path path;
public static GuiHandler guiHandler;
public static final String VERSION = "0.8.0";
public static void main(String[] args) {
//TODO make bash script for jenkins to download optimized jre and bundle it with launch4j
GuiHandler.startup();
DiscordRP.start();
@ -19,11 +18,5 @@ public class JAML {
DiscordRP.update("", "");
guiHandler = new GuiHandler();
// try {
// System.out.println(VersionFetcher.getLatestVersion("release"));
// } catch (IOException e) {
// e.printStackTrace();
// }
}
}

View File

@ -9,48 +9,55 @@ import java.io.InputStreamReader;
import java.util.ArrayList;
public class Launcher {
//TODO add progressbar for launch progress
//TODO add console output option
public Launcher(int jdkVersion, int memoryAmount, String garbageCollection, boolean printConsole) throws IOException {
ArrayList<String> commandArray = parseCommand(jdkVersion, memoryAmount, garbageCollection);
StringBuilder sb = new StringBuilder();
public Launcher(int jdkVersion, int memoryAmount, String garbageCollection, boolean printConsole) {
try {
ArrayList<String> commandArray = parseCommand(jdkVersion, memoryAmount, garbageCollection);
for (String commandString : commandArray) {
sb.append(commandString);
sb.append(" ");
StringBuilder sb = new StringBuilder();
for (String commandString : commandArray) {
sb.append(commandString);
sb.append(" ");
}
String command = sb.toString();
System.out.println(command);
LaunchEvent e = new LaunchEvent();
e.triggerEvent();
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.directory(ProfileUtils.activeProfile.getGamePath());
processBuilder.command(command);
Process process = processBuilder.start();
if (printConsole) {
printResults(process);
}
process.destroy();
} catch (IOException e) {
e.printStackTrace();
}
String command = sb.toString();
System.out.println(command);
LaunchEvent e = new LaunchEvent();
e.triggerEvent();
ProcessBuilder process = new ProcessBuilder();
process.directory(ProfileUtils.activeProfile.getGamePath());
process.command(command);
Process processVar = process.start();
if (printConsole) {
printResults(processVar);
}
processVar.destroy();
}
public static ArrayList<String> parseCommand(int jdkVersion, int memoryAmount, String garbageCollection) {
ArrayList<String> cmd = new ArrayList<String>();
ArrayList<String> cmd = new ArrayList<>();
if (jdkVersion == 8) {
cmd.add(("\"" + Config.getConfig().getString("java.jdk8") + "\\javaw.exe\""));
cmd.add((Config.getConfig().getString("java.jdk8") + "\\java.exe\""));
} else if (jdkVersion == 16) {
cmd.add(("\"" + Config.getConfig().getString("java.jdk16") + "\\javaw.exe\""));
cmd.add((Config.getConfig().getString("java.jdk16") + "\\java.exe\""));
} else if (jdkVersion == 17) {
cmd.add(("\"" + Config.getConfig().getString("java.jdk17") + "\\java.exe\""));
cmd.add((Config.getConfig().getString("java.jdk17") + "\\java.exe\""));
}
cmd.add(("-Xmx" + memoryAmount + "M"));
cmd.add(("-Xms" + memoryAmount + "M"));
cmd.add((garbageCollection));
//cmd.add((garbageCollection));
cmd.add("-Dlog4j2.formatMsgNoLookups=true -Dlog4j.configurationFile=assets\\log_configs\\client-1.12.xml");
cmd.add("-Djava.library.path=versions\\1.18.1\\natives\" \"-cp\" \"libraries\\com\\mojang\\blocklist\\1.0.6\\blocklist-1.0.6.jar;libraries\\com\\mojang\\patchy\\2.1.6\\patchy-2.1.6.jar;libraries\\com\\github\\oshi\\oshi-core\\5.8.2\\oshi-core-5.8.2.jar;libraries\\net\\java\\dev\\jna\\jna\\5.9.0\\jna-5.9.0.jar;libraries\\net\\java\\dev\\jna\\jna-platform\\5.9.0\\jna-platform-5.9.0.jar;libraries\\org\\slf4j\\slf4j-api\\1.8.0-beta4\\slf4j-api-1.8.0-beta4.jar;libraries\\org\\apache\\logging\\log4j\\log4j-slf4j18-impl\\2.14.1\\log4j-slf4j18-impl-2.14.1.jar;libraries\\com\\ibm\\icu\\icu4j\\69.1\\icu4j-69.1.jar;libraries\\com\\mojang\\javabridge\\1.2.24\\javabridge-1.2.24.jar;libraries\\net\\sf\\jopt-simple\\jopt-simple\\5.0.4\\jopt-simple-5.0.4.jar;libraries\\io\\netty\\netty-all\\4.1.68.Final\\netty-all-4.1.68.Final.jar;libraries\\com\\google\\guava\\failureaccess\\1.0.1\\failureaccess-1.0.1.jar;libraries\\com\\google\\guava\\guava\\31.0.1-jre\\guava-31.0.1-jre.jar;libraries\\org\\apache\\commons\\commons-lang3\\3.12.0\\commons-lang3-3.12.0.jar;libraries\\commons-io\\commons-io\\2.11.0\\commons-io-2.11.0.jar;libraries\\commons-codec\\commons-codec\\1.15\\commons-codec-1.15.jar;libraries\\com\\mojang\\brigadier\\1.0.18\\brigadier-1.0.18.jar;libraries\\com\\mojang\\datafixerupper\\4.0.26\\datafixerupper-4.0.26.jar;libraries\\com\\google\\code\\gson\\gson\\2.8.8\\gson-2.8.8.jar;libraries\\com\\mojang\\authlib\\3.2.38\\authlib-3.2.38.jar;libraries\\org\\apache\\commons\\commons-compress\\1.21\\commons-compress-1.21.jar;libraries\\org\\apache\\httpcomponents\\httpclient\\4.5.13\\httpclient-4.5.13.jar;libraries\\commons-logging\\commons-logging\\1.2\\commons-logging-1.2.jar;libraries\\org\\apache\\httpcomponents\\httpcore\\4.4.14\\httpcore-4.4.14.jar;libraries\\it\\unimi\\dsi\\fastutil\\8.5.6\\fastutil-8.5.6.jar;libraries\\org\\apache\\logging\\log4j\\log4j-api\\2.14.1\\log4j-api-2.14.1.jar;libraries\\org\\apache\\logging\\log4j\\log4j-core\\2.14.1\\log4j-core-2.14.1.jar;libraries\\org\\lwjgl\\lwjgl\\3.2.2\\lwjgl-3.2.2.jar;libraries\\org\\lwjgl\\lwjgl-jemalloc\\3.2.2\\lwjgl-jemalloc-3.2.2.jar;libraries\\org\\lwjgl\\lwjgl-openal\\3.2.2\\lwjgl-openal-3.2.2.jar;libraries\\org\\lwjgl\\lwjgl-opengl\\3.2.2\\lwjgl-opengl-3.2.2.jar;libraries\\org\\lwjgl\\lwjgl-glfw\\3.2.2\\lwjgl-glfw-3.2.2.jar;libraries\\org\\lwjgl\\lwjgl-stb\\3.2.2\\lwjgl-stb-3.2.2.jar;libraries\\org\\lwjgl\\lwjgl-tinyfd\\3.2.2\\lwjgl-tinyfd-3.2.2.jar;libraries\\com\\mojang\\text2speech\\1.11.3\\text2speech-1.11.3.jar;versions\\1.18.1\\1.18.1.jar\"");
cmd.add("net.minecraft.client.main.Main");

View File

@ -1,5 +1,6 @@
package tech.nevets.jaml.auth;
import tech.nevets.jaml.util.DataCompressor;
import tech.nevets.jaml.util.HttpUtils;
import java.net.URI;
@ -9,17 +10,78 @@ import java.util.Map;
public class AuthRequests {
public static void login() {
String accountName = "account_name";
String accountPassword = "password123";
public static DataCompressor initGet() {
try {
URI liveLogin = new URI("https://login.live.com/oauth20_authorize.srf?client_id=000000004C12AE6F&redirect_uri=https://login.live.com/oauth20_desktop.srf&scope=service::user.auth.xboxlive.com::MBI_SSL&display=touch&response_type=token&locale=en");
Map<String, String> headers = new HashMap<>();
String response = HttpUtils.get(liveLogin, headers);
String urlPost = "";
String value = "";
System.out.println("Response: " + response);
String[] cutResponse = response.split("<");
for (String cut : cutResponse) {
if (cut.contains("urlPost")) {
urlPost = cut;
}
if (cut.contains("value")) {
value = cut;
}
}
while (urlPost.indexOf(",urlPost:") < urlPost.indexOf("',at:true")) {
urlPost = urlPost.substring(urlPost.indexOf(",urlPost:") + 10, urlPost.indexOf("',at:true"));
}
while (value.indexOf("value=\"") < value.indexOf("\"/>',")) {
value = value.substring(value.indexOf("value=\"") + 7, value.indexOf("\"/>',"));
}
System.out.println("Param 1: " + urlPost);
System.out.println("Param 2: " + value);
return new DataCompressor(urlPost, value);
} catch (URISyntaxException e) {
e.printStackTrace();
return new DataCompressor();
}
}
public static String loginMicrosoft() {
DataCompressor urlPostPlusValue = initGet();
String urlPost = urlPostPlusValue.getKey();
String value = urlPostPlusValue.getValue();
String accountEmail = "SVTracey9@gmail.com";
String accountPassword = "Dolly1000!!";
try {
Map<String, String> headers = new HashMap<>();
String json = "{ \"agent\": { \"name\": \"Minecraft\", \"version\": 1 }, \"username\": \"" + accountName + "\", \"password\": \"" + accountPassword + "\" }";
HttpUtils.post(new URI("https://authserver.mojang.com/authenticate"), headers, json);
Map<String,String> data = new HashMap<>();
data.put("login", accountEmail);
data.put("loginfmt", accountEmail);
data.put("passwd", accountPassword);
data.put("PPFT", value);
String response = HttpUtils.post(new URI(urlPost), headers, data);
System.out.println(response);
return "";
} catch (URISyntaxException e) {
e.printStackTrace();
return "";
}
}
public static void loginMSApi() {
}
}

View File

@ -13,7 +13,7 @@ import java.io.File;
import java.io.IOException;
public class FirstLaunchGui implements Runnable, ActionListener {
//TODO Formatting
//TODO Rework first launch logic
private JFrame frame;
private JPanel panel;
@ -84,7 +84,7 @@ public class FirstLaunchGui implements Runnable, ActionListener {
profile.setProfileName("default");
profile.setGamePath(new File(gamePathField.getText()));
profile.setVersion(versionField.getText());
//profile.setVersion(versionField.getText());
profile.setLoader(loaderField.getText());
profile.setOfflineMode(Boolean.parseBoolean(offlineModeField.getText()));
try {

View File

@ -84,7 +84,7 @@ public class FirstLoginGui extends JFrame {
profile.setProfileName(profileNameField.getText());
profile.setGamePath(new File(gamePathField.getText()));
profile.setVersion(versionField.getText());
//profile.setVersion(versionField.getText());
profile.setLoader(loaderDropdown.getSelectedItem().toString());
profile.setOfflineMode(offlineModeBox.isSelected());
try {

View File

@ -7,6 +7,7 @@ import java.awt.*;
import java.util.ArrayList;
public class GuiHandler {
//TODO add config gui for easier config modification
public static final int SCREEN_WIDTH = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();
public static final int SCREEN_HEIGHT = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();

View File

@ -1,8 +1,10 @@
package tech.nevets.jaml.gui;
import tech.nevets.jaml.objects.Profile;
import tech.nevets.jaml.objects.Version;
import tech.nevets.jaml.util.LoaderUtils;
import tech.nevets.jaml.util.ProfileUtils;
import tech.nevets.jaml.util.VersionUtils;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
@ -10,13 +12,14 @@ import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
public class NewProfileGui extends JFrame {
private JPanel contentPane;
public NewProfileGui() {
setUndecorated(true);
setAlwaysOnTop(true);
setResizable(false);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
addWindowListener(new WindowAdapter() {
@ -58,10 +61,16 @@ public class NewProfileGui extends JFrame {
contentPane.add(gamePathField);
contentPane.add(gamePathButton);
Version[] versionsArray = VersionUtils.versionsList;
ArrayList<String> versions = new ArrayList<>();
for (Version version : versionsArray) {
versions.add(version.getId());
}
JLabel versionLabel = new JLabel("Version:");
versionLabel.setBounds(10, 98, 84, 31);
contentPane.add(versionLabel);
JTextField versionField = new JTextField(20);
JComboBox<String> versionField = new JComboBox<>(versions.toArray(new String[versions.size()]));
versionField.setBounds(94, 102, 231, 23);
contentPane.add(versionField);
@ -81,13 +90,13 @@ public class NewProfileGui extends JFrame {
contentPane.add(offlineModeBox);
JButton button = new JButton("Create Profile");
button.setBounds(64, 234, 217, 37);
button.setBounds(24, 243, 217, 37);
button.addActionListener(al -> {
Profile profile = new Profile();
profile.setProfileName(profileNameField.getText());
profile.setGamePath(new File(gamePathField.getText()));
profile.setVersion(versionField.getText());
profile.setVersion(versionField.getSelectedItem().toString());
profile.setLoader(loaderDropdown.getSelectedItem().toString());
profile.setOfflineMode(offlineModeBox.isSelected());
try {
@ -100,6 +109,13 @@ public class NewProfileGui extends JFrame {
this.dispose();
});
contentPane.add(button);
JButton cancelButton = new JButton("Cancel");
cancelButton.setBounds(242, 243, 83, 37);
cancelButton.addActionListener(al -> {
this.dispose();
});
contentPane.add(cancelButton);
}
private void removeFromArray() {

View File

@ -6,14 +6,19 @@ import tech.nevets.jaml.gui.panels.CustomProgressBarPanel;
import tech.nevets.jaml.util.ImageUtils;
import tech.nevets.jaml.util.LoaderUtils;
import tech.nevets.jaml.util.ProfileUtils;
import tech.nevets.jaml.util.VersionUtils;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.io.IOException;
import java.nio.file.Path;
public class StartupGui extends JFrame {
JPanel contentPane;
private static JLabel currentTaskLabel;
private static CustomProgressBarPanel progressBar;
private static final int TASKS = 7;
private static int task = 0;
public StartupGui() {
setUndecorated(true);
@ -43,7 +48,7 @@ public class StartupGui extends JFrame {
progressBarOutline.setIcon(pgOutline);
contentPane.add(progressBarOutline);
CustomProgressBarPanel progressBar = new CustomProgressBarPanel(pbWidth, pbHeight);
progressBar = new CustomProgressBarPanel(pbWidth, pbHeight);
progressBar.setBounds(pbX, pbY, pbWidth, pbHeight);
contentPane.add(progressBar);
@ -56,24 +61,45 @@ public class StartupGui extends JFrame {
setVisible(true);
progressBar.setProgress(0);
currentTaskLabel.setText("Making Directories...");
task++;
makeDirs();
smoothIncrease(progressBar, 20);
smoothIncrease();
currentTaskLabel.setText("Loading Config...");
task++;
Config.loadConfig();
smoothIncrease(progressBar, 40);
smoothIncrease();
currentTaskLabel.setText("Downloading Version List...");
task++;
VersionUtils.downloadList();
smoothIncrease();
currentTaskLabel.setText("Loading Profiles...");
task++;
ProfileUtils.getProfileList();
smoothIncrease(progressBar, 60);
smoothIncrease();
currentTaskLabel.setText("Loading Active Profile...");
task++;
ProfileUtils.getActiveProfile();
smoothIncrease(progressBar, 80);
smoothIncrease();
currentTaskLabel.setText("Getting Game Loaders...");
task++;
LoaderUtils.getLoaders();
smoothIncrease();
currentTaskLabel.setText("Getting versions...");
task++;
VersionUtils.updateVersionsList();
smoothIncrease();
currentTaskLabel.setText("Done!");
smoothIncrease(progressBar, 100);
smoothIncrease();
}
@ -96,55 +122,40 @@ public class StartupGui extends JFrame {
JAML.path = Path.of(System.getenv("JAML_HOME"));
}
try {
if (!JAML.path.toFile().exists()) {
JAML.path.toFile().mkdirs();
}
} catch (Exception e) {
System.out.println("Invalid path, please check your config.yml and try again");
if (!JAML.path.toFile().exists()) {
JAML.path.toFile().mkdirs();
}
try {
Path profilePath = Path.of(JAML.path + "\\profiles\\");
if (!profilePath.toFile().exists()) {
profilePath.toFile().mkdirs();
}
} catch (Exception e) {
e.printStackTrace();
Path profilePath = Path.of(JAML.path + "\\profiles\\");
if (!profilePath.toFile().exists()) {
profilePath.toFile().mkdirs();
}
try {
Path profilePath = Path.of(JAML.path + "\\assets\\");
if (!profilePath.toFile().exists()) {
profilePath.toFile().mkdirs();
}
} catch (Exception e) {
e.printStackTrace();
Path dataPath = Path.of(JAML.path + "\\data\\");
if (!dataPath.toFile().exists()) {
dataPath.toFile().mkdirs();
}
try {
Path dataPath = Path.of(JAML.path + "\\data\\");
if (!dataPath.toFile().exists()) {
dataPath.toFile().mkdirs();
}
} catch (Exception e) {
e.printStackTrace();
Path skinsPath = Path.of(JAML.path + "\\data\\skins\\");
if (!skinsPath.toFile().exists()) {
skinsPath.toFile().mkdirs();
}
try {
Path skinsPath = Path.of(JAML.path + "\\data\\skins\\");
if (!skinsPath.toFile().exists()) {
skinsPath.toFile().mkdirs();
}
} catch (Exception e) {
e.printStackTrace();
Path versionManifestPath = Path.of(JAML.path + "\\data\\version-manifest\\");
if (!versionManifestPath.toFile().exists()) {
versionManifestPath.toFile().mkdirs();
}
Path cachePath = Path.of(JAML.path + "\\cache");
if (!cachePath.toFile().exists()) {
cachePath.toFile().mkdirs();
}
}
private static void smoothIncrease(CustomProgressBarPanel pb, int to) {
int i = pb.getProgress();
while (i <= to) {
pb.setProgress(i);
private static void smoothIncrease() {
int i = progressBar.getProgress();
while (i <= (100 / TASKS) * task) {
progressBar.setProgress(i);
i += 1;
}
}

View File

@ -2,6 +2,7 @@ package tech.nevets.jaml.gui.panels;
import tech.nevets.jaml.JAML;
import tech.nevets.jaml.Launcher;
import tech.nevets.jaml.util.ImageUtils;
import tech.nevets.jaml.util.ProfileUtils;
@ -18,7 +19,9 @@ public class HomePanel extends JPanel {
JButton launchButton = new JButton("Launch");
launchButton.setBounds(512, 619, 196, 51);
//launchButton.setIcon(); //TODO Create nice looking buttons and apply them to project
launchButton.addActionListener(al -> {
new Launcher(17, 6, "zgc", true);
});
add(launchButton);
JComboBox activeProfileDropdown = new JComboBox(ProfileUtils.profileList);

View File

@ -0,0 +1,135 @@
package tech.nevets.jaml.util;
import com.google.gson.*;
import org.apache.commons.io.FileUtils;
import tech.nevets.jaml.JAML;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
public class CacheUtils {
public static final String CACHE_PATH = JAML.path + "\\cache\\";
public static void generateCache(String cacheName) {
try {
File file = new File(CACHE_PATH + "\\" + cacheName + ".json");
if (!file.exists()) {
file.createNewFile();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void writeCache(String cacheName, String[] values) {
try {
Writer writer = new FileWriter(CACHE_PATH + "\\" + cacheName + ".json");
GsonBuilder builder = new GsonBuilder();
builder.setPrettyPrinting();
Gson gson = builder.create();
String jsonString = gson.toJson(values);
writer.write(jsonString);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void addToCache(String cacheName, String value) {
try {
File cacheFile = new File(CACHE_PATH + "\\" + cacheName + ".json");
if (!cacheFile.exists()) {
generateCache(cacheName);
}
String[] cacheArray = new Gson().fromJson(FileUtils.readFileToString(cacheFile, StandardCharsets.UTF_8), String[].class);
ArrayList<String> cacheArrayList;
if (cacheArray == null) {
cacheArrayList = new ArrayList<>();
} else {
cacheArrayList = new ArrayList<>(List.of(cacheArray));
}
if (!cacheArrayList.contains(value)) {
cacheArrayList.add(value);
}
writeCache(cacheName, cacheArrayList.toArray(new String[cacheArrayList.size()]));
} catch (IOException e) {
e.printStackTrace();
}
}
public static void addToCache(String cacheName, String[] values) {
try {
File cacheFile = new File(CACHE_PATH + "\\" + cacheName + ".json");
if (!cacheFile.exists()) {
generateCache(cacheName);
}
String[] cacheArray = new Gson().fromJson(FileUtils.readFileToString(cacheFile, StandardCharsets.UTF_8), String[].class);
ArrayList<String> cacheArrayList;
if (cacheArray == null) {
cacheArrayList = new ArrayList<>();
} else {
cacheArrayList = new ArrayList<>(List.of(cacheArray));
}
for (String value : values) {
if (!cacheArrayList.contains(value)) {
cacheArrayList.add(value);
}
}
writeCache(cacheName, cacheArrayList.toArray(new String[cacheArrayList.size()]));
} catch (IOException e) {
e.printStackTrace();
}
}
public static void removeFromCache(String cacheName, String value) {
try {
File cacheFile = new File(CACHE_PATH + "\\" + cacheName + ".json");
String[] cacheArray = new Gson().fromJson(FileUtils.readFileToString(cacheFile, StandardCharsets.UTF_8), String[].class);
ArrayList<String> cacheArrayList;
if (cacheArray == null) {
cacheArrayList = new ArrayList<>();
} else {
cacheArrayList = new ArrayList<>(List.of(cacheArray));
}
cacheArrayList.remove(value);
writeCache(cacheName, cacheArrayList.toArray(new String[cacheArrayList.size()]));
} catch (IOException e) {
e.printStackTrace();
}
}
public static String[] getCache(String cacheName) {
try {
File cacheFile = new File(CACHE_PATH + "\\" + cacheName + ".json");
if (!cacheFile.exists()) {
generateCache(cacheName);
}
return new Gson().fromJson(FileUtils.readFileToString(cacheFile, StandardCharsets.UTF_8), String[].class);
} catch (IOException e) {
e.printStackTrace();
return new String[]{};
}
}
}

View File

@ -2,9 +2,19 @@ package tech.nevets.jaml.util;
public class DataCompressor {
private final String data;
private final String key;
private final String salt;
private String value;
private String data;
private String key;
private String salt;
public DataCompressor() {
}
public DataCompressor(String key, String value) {
this.key = key;
this.value = value;
}
public DataCompressor(String data, String key, String salt) {
this.data = data;
@ -12,6 +22,10 @@ public class DataCompressor {
this.salt = salt;
}
public String getValue() {
return value;
}
public String getData() {
return data;
}

View File

@ -24,7 +24,7 @@ public class HttpUtils {
return response.body();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
return null;
return "";
}
}

View File

@ -1,74 +0,0 @@
package tech.nevets.jaml.util;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.apache.commons.io.FileUtils;
import tech.nevets.jaml.JAML;
import tech.nevets.jaml.objects.Version;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
public class VersionFetcher {
public static Version getVersion(String version) {
Gson gson = new Gson();
JsonObject versionManifestJson = getList();
JsonArray versionsJsonArray = versionManifestJson.getAsJsonArray("versions");
Version[] versionArray = gson.fromJson(versionsJsonArray, Version[].class);
for (Version value : versionArray) {
if (value.getId().equalsIgnoreCase(version)) {
return value;
}
}
return null;
}
public static Version getVersion(String version, String type) {
Gson gson = new Gson();
JsonObject versionManifestJson = getList();
JsonArray versionsJsonArray = versionManifestJson.getAsJsonArray("versions");
Version[] versionArray = gson.fromJson(versionsJsonArray, Version[].class);
for (Version value : versionArray) {
if (value.getType().equalsIgnoreCase(type)) {
if (value.getId().equalsIgnoreCase(version)) {
return value;
}
}
}
return null;
}
/**
*
* @param branch, release or snapshot
* @return
* @throws IOException
*/
public static String getLatestVersion(String branch) {
JsonObject versionManifestJson = getList();
JsonObject latestJsonObject = versionManifestJson.get("latest").getAsJsonObject();
return latestJsonObject.get(branch).getAsString();
}
@SuppressWarnings("Deprecated")
public static JsonObject getList() {
try {
URL versionManifestUrl = new URL("https://launchermeta.mojang.com/mc/game/version_manifest.json");
FileUtils.copyURLToFile(versionManifestUrl, new File(JAML.path + "\\data\\version.json"));
File versionManifestFile = new File(JAML.path + "\\data\\version.json");
return new Gson().fromJson(FileUtils.readFileToString(versionManifestFile, StandardCharsets.UTF_8), JsonObject.class);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}

View File

@ -0,0 +1,144 @@
package tech.nevets.jaml.util;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.apache.commons.io.FileUtils;
import tech.nevets.jaml.Config;
import tech.nevets.jaml.JAML;
import tech.nevets.jaml.objects.Version;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
public class VersionUtils {
public static Version[] versionsList;
public static Version[] getVersionsList() {
Gson gson = new Gson();
JsonObject versionManifestJson = getList();
JsonArray versionsJsonArray = versionManifestJson.getAsJsonArray("versions");
Version[] versionArray = gson.fromJson(versionsJsonArray, Version[].class);
if (Config.CONFIG.getBoolean("game.show-snapshots")) {
return versionArray;
} else {
ArrayList<Version> versionArrayList = new ArrayList<>();
for (Version version : versionArray) {
if (version.getType().equalsIgnoreCase("release")) {
versionArrayList.add(version);
}
}
return versionArrayList.toArray(new Version[versionArrayList.size()]);
}
}
public static Version toVersion(String version) {
Version[] versionArray = getVersionsList();
for (Version value : versionArray) {
if (value.getId().equalsIgnoreCase(version)) {
return value;
}
}
return null;
}
/**
*
* @param branch, release or snapshot
* @return something
*/
public static String getLatestVersion(String branch) {
JsonObject versionManifestJson = getList();
JsonObject latestJsonObject = versionManifestJson.get("latest").getAsJsonObject();
return latestJsonObject.get(branch).getAsString();
}
public static void downloadList() {
try {
URL versionManifestUrl = new URL("https://launchermeta.mojang.com/mc/game/version_manifest.json");
FileUtils.copyURLToFile(versionManifestUrl, new File(JAML.path + "\\data\\version.json"));
} catch (IOException e) {
e.printStackTrace();
}
}
public static JsonObject getList() {
try {
File versionManifestFile = new File(JAML.path + "\\data\\version.json");
return new Gson().fromJson(FileUtils.readFileToString(versionManifestFile, StandardCharsets.UTF_8), JsonObject.class);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public static void getLibs() {
try {
Version version = toVersion(ProfileUtils.getActiveProfile().getVersion());
URL versionManifestUrl = version.getUrl();
FileUtils.copyURLToFile(versionManifestUrl, new File(JAML.path + "\\data\\" + version.getId() + ".json"));
File versionFile = new File(JAML.path + "\\data\\" + version.getId() + ".json");
JsonObject versionJson = new Gson().fromJson(FileUtils.readFileToString(versionFile, StandardCharsets.UTF_8), JsonObject.class);
JsonArray libsJson = versionJson.getAsJsonArray("libraries");
ArrayList<String> cache = new ArrayList<>();
String[] cacheArray = CacheUtils.getCache("libs");
if (cacheArray != null) {
for (String value : CacheUtils.getCache("libs")) {
cache.add(value);
}
}
//TODO Account for only native downloads
//TODO Implement OS Check and set constants accordingly
if (!cache.contains(version.getId())) {
for (int i = 0; i < libsJson.size(); i++) {
JsonElement downloads = libsJson.get(i);
JsonObject download = downloads.getAsJsonObject().getAsJsonObject("downloads");
JsonElement artifact = download.getAsJsonObject().get("artifact");
JsonElement classifiers = download.getAsJsonObject().get("classifiers");
JsonElement pathJson;
if (artifact != null) {
pathJson = artifact.getAsJsonObject().get("path");
} else if (classifiers != null) {
//TODO add logic for classifiers
System.out.println("classifier");
continue;
} else {
System.out.println("Something unexpected was in the libraries array...");
return;
}
String path = pathJson.getAsString();
String url = artifact.getAsJsonObject().get("url").toString();
FileUtils.copyURLToFile(new URL(url.replace("\"", "")), new File((ProfileUtils.getActiveProfile().getGamePath()) + "\\libraries\\" + path));
}
CacheUtils.addToCache("libs", version.getId());
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void updateVersionsList() {
versionsList = getVersionsList();
}
}

View File

@ -1,5 +1,16 @@
```
#!/bin/bash
java -Xms16G -Xmx16G -Dlog4j2.formatMsgNoLookups=true -Dlog4j.configurationFile=assets/log_configs/client-1.12.xml "-DFabricMcEmu= net.minecraft.client.main.Main " "-Djava.library.path=versions/1.18.2/natives" "-cp" "libraries/com/mojang/logging/1.0.0/logging-1.0.0.jar:libraries/com/mojang/blocklist/1.0.10/blocklist-1.0.10.jar:libraries/com/mojang/patchy/2.2.10/patchy-2.2.10.jar:libraries/com/github/oshi/oshi-core/5.8.5/oshi-core-5.8.5.jar:libraries/net/java/dev/jna/jna/5.10.0/jna-5.10.0.jar:libraries/net/java/dev/jna/jna-platform/5.10.0/jna-platform-5.10.0.jar:libraries/org/slf4j/slf4j-api/1.8.0-beta4/slf4j-api-1.8.0-beta4.jar:libraries/org/apache/logging/log4j/log4j-slf4j18-impl/2.17.0/log4j-slf4j18-impl-2.17.0.jar:libraries/com/ibm/icu/icu4j/70.1/icu4j-70.1.jar:libraries/com/mojang/javabridge/1.2.24/javabridge-1.2.24.jar:libraries/net/sf/jopt-simple/jopt-simple/5.0.4/jopt-simple-5.0.4.jar:libraries/io/netty/netty-all/4.1.68.Final/netty-all-4.1.68.Final.jar:libraries/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar:libraries/com/google/guava/guava/31.0.1-jre/guava-31.0.1-jre.jar:libraries/org/apache/commons/commons-lang3/3.12.0/commons-lang3-3.12.0.jar:libraries/commons-io/commons-io/2.11.0/commons-io-2.11.0.jar:libraries/commons-codec/commons-codec/1.15/commons-codec-1.15.jar:libraries/com/mojang/brigadier/1.0.18/brigadier-1.0.18.jar:libraries/com/mojang/datafixerupper/4.1.27/datafixerupper-4.1.27.jar:libraries/com/google/code/gson/gson/2.8.9/gson-2.8.9.jar:libraries/com/mojang/authlib/3.3.39/authlib-3.3.39.jar:libraries/org/apache/commons/commons-compress/1.21/commons-compress-1.21.jar:libraries/org/apache/httpcomponents/httpclient/4.5.13/httpclient-4.5.13.jar:libraries/commons-logging/commons-logging/1.2/commons-logging-1.2.jar:libraries/org/apache/httpcomponents/httpcore/4.4.14/httpcore-4.4.14.jar:libraries/it/unimi/dsi/fastutil/8.5.6/fastutil-8.5.6.jar:libraries/org/apache/logging/log4j/log4j-api/2.17.0/log4j-api-2.17.0.jar:libraries/org/apache/logging/log4j/log4j-core/2.17.0/log4j-core-2.17.0.jar:libraries/org/lwjgl/lwjgl/3.2.2/lwjgl-3.2.2.jar:libraries/org/lwjgl/lwjgl-jemalloc/3.2.2/lwjgl-jemalloc-3.2.2.jar:libraries/org/lwjgl/lwjgl-openal/3.2.2/lwjgl-openal-3.2.2.jar:libraries/org/lwjgl/lwjgl-opengl/3.2.2/lwjgl-opengl-3.2.2.jar:libraries/org/lwjgl/lwjgl-glfw/3.2.2/lwjgl-glfw-3.2.2.jar:libraries/org/lwjgl/lwjgl-stb/3.2.2/lwjgl-stb-3.2.2.jar:libraries/org/lwjgl/lwjgl-tinyfd/3.2.2/lwjgl-tinyfd-3.2.2.jar:libraries/com/mojang/text2speech/1.12.4/text2speech-1.12.4.jar:versions/fabric-loader-0.13.3-1.18.2/fabric-loader-0.13.3-1.18.2.jar" net.minecraft.client.Main --username <your username here> --version 1.18.2 --gameDir . --assetsDir assets --assetIndex 1.18 --uuid <your uuid here> --accessToken 00000000000000000000000000000000 --clientId 0000 --xuid 0000 --userType mojang --versionType release
java
-Xms16G -Xmx16G
-Dlog4j2.formatMsgNoLookups=true -Dlog4j.configurationFile=assets/log_configs/client-1.12.xml "-Djava.library.path=versions/1.18.2/natives"
"-cp" "libraries/com/mojang/logging/1.0.0/logging-1.0.0.jar:libraries/com/mojang/blocklist/1.0.10/blocklist-1.0.10.jar:libraries/com/mojang/patchy/2.2.10/patchy-2.2.10.jar:libraries/com/github/oshi/oshi-core/5.8.5/oshi-core-5.8.5.jar:libraries/net/java/dev/jna/jna/5.10.0/jna-5.10.0.jar:libraries/net/java/dev/jna/jna-platform/5.10.0/jna-platform-5.10.0.jar:libraries/org/slf4j/slf4j-api/1.8.0-beta4/slf4j-api-1.8.0-beta4.jar:libraries/org/apache/logging/log4j/log4j-slf4j18-impl/2.17.0/log4j-slf4j18-impl-2.17.0.jar:libraries/com/ibm/icu/icu4j/70.1/icu4j-70.1.jar:libraries/com/mojang/javabridge/1.2.24/javabridge-1.2.24.jar:libraries/net/sf/jopt-simple/jopt-simple/5.0.4/jopt-simple-5.0.4.jar:libraries/io/netty/netty-all/4.1.68.Final/netty-all-4.1.68.Final.jar:libraries/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar:libraries/com/google/guava/guava/31.0.1-jre/guava-31.0.1-jre.jar:libraries/org/apache/commons/commons-lang3/3.12.0/commons-lang3-3.12.0.jar:libraries/commons-io/commons-io/2.11.0/commons-io-2.11.0.jar:libraries/commons-codec/commons-codec/1.15/commons-codec-1.15.jar:libraries/com/mojang/brigadier/1.0.18/brigadier-1.0.18.jar:libraries/com/mojang/datafixerupper/4.1.27/datafixerupper-4.1.27.jar:libraries/com/google/code/gson/gson/2.8.9/gson-2.8.9.jar:libraries/com/mojang/authlib/3.3.39/authlib-3.3.39.jar:libraries/org/apache/commons/commons-compress/1.21/commons-compress-1.21.jar:libraries/org/apache/httpcomponents/httpclient/4.5.13/httpclient-4.5.13.jar:libraries/commons-logging/commons-logging/1.2/commons-logging-1.2.jar:libraries/org/apache/httpcomponents/httpcore/4.4.14/httpcore-4.4.14.jar:libraries/it/unimi/dsi/fastutil/8.5.6/fastutil-8.5.6.jar:libraries/org/apache/logging/log4j/log4j-api/2.17.0/log4j-api-2.17.0.jar:libraries/org/apache/logging/log4j/log4j-core/2.17.0/log4j-core-2.17.0.jar:libraries/org/lwjgl/lwjgl/3.2.2/lwjgl-3.2.2.jar:libraries/org/lwjgl/lwjgl-jemalloc/3.2.2/lwjgl-jemalloc-3.2.2.jar:libraries/org/lwjgl/lwjgl-openal/3.2.2/lwjgl-openal-3.2.2.jar:libraries/org/lwjgl/lwjgl-opengl/3.2.2/lwjgl-opengl-3.2.2.jar:libraries/org/lwjgl/lwjgl-glfw/3.2.2/lwjgl-glfw-3.2.2.jar:libraries/org/lwjgl/lwjgl-stb/3.2.2/lwjgl-stb-3.2.2.jar:libraries/org/lwjgl/lwjgl-tinyfd/3.2.2/lwjgl-tinyfd-3.2.2.jar:libraries/com/mojang/text2speech/1.12.4/text2speech-1.12.4.jar"
net.minecraft.client.Main
--username <your username here>
--version 1.18.2
--gameDir .
--assetsDir assets --assetIndex 1.18
--uuid <your uuid here>
--accessToken 00000000000000000000000000000000 --clientId 0000 --xuid 0000
--userType mojang
--versionType release
```