Initial work
This commit is contained in:
commit
2e740e1117
|
@ -0,0 +1,5 @@
|
|||
.gradle/
|
||||
.idea/
|
||||
build/
|
||||
run/
|
||||
imgui.ini
|
|
@ -0,0 +1,49 @@
|
|||
plugins {
|
||||
id 'java'
|
||||
id 'application'
|
||||
id 'com.github.johnrengelman.shadow' version '7.0.0'
|
||||
}
|
||||
|
||||
group 'io.gitlab.jfronny'
|
||||
version '1.0'
|
||||
|
||||
application {
|
||||
mainClass = 'io.gitlab.jfronny.glaunch.GLaunch'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
ext {
|
||||
lwjglVersion = '3.2.3'
|
||||
imguiVersion = '1.84.1.3'
|
||||
log4jVersion = '2.14.1'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.google.code.gson:gson:2.8.8'
|
||||
implementation "org.apache.logging.log4j:log4j-api:$log4jVersion"
|
||||
implementation "org.apache.logging.log4j:log4j-core:$log4jVersion"
|
||||
|
||||
|
||||
implementation platform("org.lwjgl:lwjgl-bom:$lwjglVersion")
|
||||
|
||||
['', '-opengl', '-glfw'].each {
|
||||
implementation "org.lwjgl:lwjgl$it:$lwjglVersion"
|
||||
implementation "org.lwjgl:lwjgl$it::natives-windows"
|
||||
implementation "org.lwjgl:lwjgl$it::natives-linux"
|
||||
implementation "org.lwjgl:lwjgl$it::natives-macos"
|
||||
}
|
||||
|
||||
implementation "io.github.spair:imgui-java-binding:$imguiVersion" // https://github.com/SpaiR/imgui-java
|
||||
implementation "io.github.spair:imgui-java-lwjgl3:$imguiVersion"
|
||||
|
||||
implementation "io.github.spair:imgui-java-natives-windows:$imguiVersion"
|
||||
implementation "io.github.spair:imgui-java-natives-linux:$imguiVersion"
|
||||
implementation "io.github.spair:imgui-java-natives-macos:$imguiVersion"
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,5 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
|
@ -0,0 +1,185 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MSYS* | MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
case $i in
|
||||
0) set -- ;;
|
||||
1) set -- "$args0" ;;
|
||||
2) set -- "$args0" "$args1" ;;
|
||||
3) set -- "$args0" "$args1" "$args2" ;;
|
||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=`save "$@"`
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
exec "$JAVACMD" "$@"
|
|
@ -0,0 +1,89 @@
|
|||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
|
@ -0,0 +1,205 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace McMan
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
if (args.Length == 0)
|
||||
{
|
||||
args = new string[1];
|
||||
Console.WriteLine("Username");
|
||||
Console.Write("> ");
|
||||
args[0] = Console.ReadLine();
|
||||
}
|
||||
if (args.Length == 1)
|
||||
{
|
||||
args = new [] {args[0], "choose"};
|
||||
}
|
||||
if (args.Length == 2)
|
||||
{
|
||||
Console.WriteLine("Max memory (empty for 2G)");
|
||||
Console.Write("> ");
|
||||
args = new [] {args[0], args[1], Console.ReadLine()};
|
||||
}
|
||||
if (Directory.Exists("assets"))
|
||||
Directory.Delete("assets", true);
|
||||
if (Directory.Exists("Game"))
|
||||
Directory.Delete("Game", true);
|
||||
Directory.CreateDirectory("Game");
|
||||
using WebClient client = new WebClient();
|
||||
string maxMem = args[2];
|
||||
maxMem = string.IsNullOrWhiteSpace(maxMem) ? "2G" : maxMem;
|
||||
Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
JObject gameJson = GetMinecraftJson(client, args[1], out string ver);
|
||||
DownloadClient(client, gameJson["downloads"]["client"]);
|
||||
DownloadAssets(client, gameJson["assetIndex"], ver);
|
||||
string classpath = DownloadLibs(client, (JArray) gameJson["libraries"]);
|
||||
Console.WriteLine("Creating launch script");
|
||||
classpath += "client.jar";
|
||||
const string mainClass = "net.minecraft.client.main.Main";
|
||||
const string java = "javaw";
|
||||
const string lowMem = "768M";
|
||||
string javaOptions =
|
||||
$"-server -splash:splash.png -d64 -da -dsa -Xrs -Xms{lowMem} -Xmx{maxMem} -XX:NewSize={lowMem} -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:-UseAdaptiveSizePolicy -XX:+DisableExplicitGC -Djava.library.path=libraries -cp {classpath} {mainClass}";
|
||||
string jvmBat =
|
||||
$"start /D %cd% /I /HIGH {java} {javaOptions} --username {args[0]} --version {ver} --gameDir %cd% --assetsDir assets --assetIndex {gameJson.Value<string>("assets")} --uuid 2536abce90e8476a871679918164abc5 --accessToken 99abe417230342cb8e9e2168ab46297a --userType legacy --versionType release --nativeLauncherVersion 307";
|
||||
File.WriteAllText(Path.Combine("Game", "start.bat"), jvmBat);
|
||||
Console.WriteLine("Done!");
|
||||
}
|
||||
|
||||
//Downloads a JRE, doesn't start
|
||||
/*private static void GetJRE(WebClient client, bool x64)
|
||||
{
|
||||
Console.WriteLine("Fetching JRE Versions...");
|
||||
IEnumerable<JToken> json = JArray.Parse(client.DownloadString("https://api.adoptopenjdk.net/v2/info/releases/openjdk11"))
|
||||
.SelectMany(s => (JArray)s["binaries"]);
|
||||
Console.WriteLine("Selecting version...");
|
||||
string download = json.Last(s =>
|
||||
s.Value<string>("os") == "windows" && s.Value<string>("architecture") == (x64 ? "x64" : "x32") &&
|
||||
s.Value<string>("binary_type") == "jre" && s.Value<string>("heap_size") == "normal")
|
||||
.Value<string>("binary_link");
|
||||
Console.WriteLine($"Downloading from {download}...");
|
||||
if (Directory.Exists("jdk"))
|
||||
Directory.Delete("jdk", true);
|
||||
Directory.CreateDirectory("jdk");
|
||||
using MemoryStream ms = new MemoryStream(client.DownloadData(download));
|
||||
Console.WriteLine("Extracting...");
|
||||
using ZipArchive archive = new ZipArchive(ms);
|
||||
archive.ExtractToDirectory("jdk");
|
||||
Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(Directory.GetDirectories("jdk")[0], "Game");
|
||||
Directory.Delete("jdk", true);
|
||||
}*/
|
||||
|
||||
private static string DownloadLibs(WebClient client, JArray libraries)
|
||||
{
|
||||
string output = "";
|
||||
string libdir = Path.Combine("Game", "libraries");
|
||||
Console.WriteLine("Downloading libs...");
|
||||
Directory.CreateDirectory(libdir);
|
||||
Console.CursorTop++;
|
||||
JToken[] tmp = libraries.ToArray();
|
||||
for (int i = 0; i < tmp.Length; i++)
|
||||
{
|
||||
JToken lib = tmp[i];
|
||||
if (lib["downloads"].Any(s => ((JProperty) s).Name == "classifiers"))
|
||||
output = lib["downloads"]["classifiers"].Where(lib2 => ((JProperty) lib2).Name == "natives-windows")
|
||||
.Aggregate(
|
||||
output,
|
||||
(current, lib2) => current + DownloadLib(client, lib2.First.Value<string>("sha1"),
|
||||
lib2.First.Value<string>("url"), lib2.First.Value<string>("path"),
|
||||
libdir));
|
||||
Console.CursorLeft = 0;
|
||||
Console.CursorTop--;
|
||||
Console.WriteLine($"[{i + 1}/{tmp.Length}] Getting {lib["downloads"]["artifact"].Value<string>("path")}{new string(' ', 10)}");
|
||||
output += DownloadLib(client,
|
||||
lib["downloads"]["artifact"].Value<string>("sha1"),
|
||||
lib["downloads"]["artifact"].Value<string>("url"),
|
||||
lib["downloads"]["artifact"].Value<string>("path"),
|
||||
libdir);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
private static string DownloadLib(WebClient client, string hash, string url, string path, string libdir)
|
||||
{
|
||||
string tmp = path.Split('/').Aggregate(libdir, Path.Combine);
|
||||
byte[] libB = client.DownloadData(url);
|
||||
if (Tools.Hash(libB) != hash)
|
||||
{
|
||||
Console.WriteLine("ERROR: HASH MISMATCH IN LIBRARY");
|
||||
throw new Exception();
|
||||
}
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(tmp));
|
||||
File.WriteAllBytes(tmp, libB);
|
||||
return $"{path.Split('/').Aggregate("libraries", Path.Combine)};";
|
||||
}
|
||||
|
||||
private static void DownloadAssets(WebClient client, JToken assetIndex, string version)
|
||||
{
|
||||
bool success = false;
|
||||
byte[] indexB = new byte[0];
|
||||
while (!success)
|
||||
{
|
||||
Console.WriteLine("Downloading asset index...");
|
||||
indexB = client.DownloadData(assetIndex.Value<string>("url"));
|
||||
success = Tools.Hash(indexB) == assetIndex.Value<string>("sha1");
|
||||
}
|
||||
JObject index = JObject.Parse(Encoding.Default.GetString(indexB));
|
||||
string assetPath = Path.Combine("Game", "assets");
|
||||
Directory.CreateDirectory(Path.Combine(assetPath, "indexes"));
|
||||
File.WriteAllBytes(Path.Combine(assetPath, "indexes", Path.GetFileName(assetIndex.Value<string>("url"))), indexB);
|
||||
Console.WriteLine("Processing...");
|
||||
Console.CursorTop++;
|
||||
JToken[] tmp = Enumerable.ToArray(index["objects"]);
|
||||
for (int i = 0; i < tmp.Length; i++)
|
||||
{
|
||||
JProperty asset = (JProperty)tmp[i];
|
||||
string name = asset.Name;
|
||||
Console.CursorLeft = 0;
|
||||
Console.CursorTop--;
|
||||
Console.WriteLine($"[{i + 1}/{tmp.Length}] Getting {name}{new string(' ', 10)}");
|
||||
string hash = asset.First.Value<string>("hash");
|
||||
string url = $"http://resources.download.minecraft.net/{string.Join("", hash.Substring(0, 2))}/{hash}";
|
||||
byte[] file = client.DownloadData(url);
|
||||
if (Tools.Hash(file) != hash)
|
||||
{
|
||||
Console.WriteLine("ERROR: HASH MISMATCH IN ASSET");
|
||||
throw new Exception();
|
||||
}
|
||||
string path = Path.Combine(assetPath, "objects", hash.Substring(0, 2));
|
||||
if (!Directory.Exists(path))
|
||||
Directory.CreateDirectory(path);
|
||||
File.WriteAllBytes(Path.Combine(path, hash), file);
|
||||
}
|
||||
}
|
||||
|
||||
private static void DownloadClient(WebClient client, JToken clientJson)
|
||||
{
|
||||
bool success = false;
|
||||
byte[] mcClient = new byte[0];
|
||||
while (!success)
|
||||
{
|
||||
Console.WriteLine("Downloading client...");
|
||||
mcClient = client.DownloadData(clientJson.Value<string>("url"));
|
||||
success = Tools.Hash(mcClient) == clientJson.Value<string>("sha1");
|
||||
}
|
||||
File.WriteAllBytes(Path.Combine("Game", "client.jar"), mcClient);
|
||||
}
|
||||
|
||||
private static JObject GetMinecraftJson(WebClient client, string verdat, out string version)
|
||||
{
|
||||
Tuple<string, string> tmp;
|
||||
Tuple<string, string>[] versions = GetVersions(client);
|
||||
if (verdat == "choose")
|
||||
{
|
||||
Console.WriteLine("Select a Version (empty for latest)");
|
||||
for (int i = 0; i < versions.Length; i++) Console.WriteLine($"{i + 1}\t- {versions[i].Item1}");
|
||||
Console.Write("> ");
|
||||
string inp = Console.ReadLine();
|
||||
tmp = string.IsNullOrWhiteSpace(inp) ? versions.Last() : versions[int.Parse(inp) - 1];
|
||||
}
|
||||
else
|
||||
tmp = versions.First(s => s.Item1.ToLower().Equals(verdat.ToLower(), StringComparison.InvariantCultureIgnoreCase));
|
||||
version = tmp.Item1;
|
||||
Console.WriteLine($"Using minecraft {version}");
|
||||
return JObject.Parse(client.DownloadString(tmp.Item2));
|
||||
}
|
||||
|
||||
private static Tuple<string, string>[] GetVersions(WebClient client)
|
||||
{
|
||||
JObject tmp =
|
||||
JObject.Parse(client.DownloadString("https://launchermeta.mojang.com/mc/game/version_manifest.json"));
|
||||
return tmp["versions"].Where(token => token.Value<string>("type") == "release").Select(token => new Tuple<string, string>(token.Value<string>("id"), token.Value<string>("url"))).OrderBy(s => Version.Parse(s.Item1)).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
rootProject.name = 'GLaunch2'
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package io.gitlab.jfronny.glaunch;
|
||||
|
||||
public class Config {
|
||||
public boolean snapshots = false;
|
||||
}
|
|
@ -0,0 +1,260 @@
|
|||
package io.gitlab.jfronny.glaunch;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import imgui.ImGui;
|
||||
import imgui.ImGuiIO;
|
||||
import imgui.flag.ImGuiConfigFlags;
|
||||
import imgui.gl3.ImGuiImplGl3;
|
||||
import imgui.glfw.ImGuiImplGlfw;
|
||||
import io.gitlab.jfronny.glaunch.gson.MinecraftArgumentDeserializer;
|
||||
import io.gitlab.jfronny.glaunch.model.MinecraftArgument;
|
||||
import io.gitlab.jfronny.glaunch.windows.MainWindow;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.glfw.*;
|
||||
import org.lwjgl.opengl.GL;
|
||||
import org.lwjgl.opengl.GL32;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
//TODO generate gitignore
|
||||
//TODO mods browser
|
||||
//TODO load and launch instance from metadata
|
||||
//TODO allow instance sync through metadata
|
||||
public class GLaunch {
|
||||
public static final Set<Window> WINDOWS = new LinkedHashSet<>();
|
||||
public static final Logger LOGGER = LogManager.getFormatterLogger("GLaunch");
|
||||
public static final Gson GSON = new GsonBuilder()
|
||||
.registerTypeAdapter(MinecraftArgument.class, new MinecraftArgumentDeserializer())
|
||||
.create();
|
||||
public static final Path CACHE_DIR = Path.of("run/cache");
|
||||
public static final Path INSTANCE_DIR = Path.of("run/instances");
|
||||
public static final Path ASSETS_DIR = Path.of("run/assets");
|
||||
public static final Path LIBRARIES_DIR = Path.of("run/libraries");
|
||||
public static final Config CONFIG = new Config(); //TODO from gson
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
LOGGER.info("Setting up cache dir");
|
||||
if (!Files.exists(CACHE_DIR)) Files.createDirectories(CACHE_DIR);
|
||||
if (!Files.exists(INSTANCE_DIR)) Files.createDirectories(INSTANCE_DIR);
|
||||
if (!Files.exists(ASSETS_DIR)) Files.createDirectories(ASSETS_DIR);
|
||||
if (!Files.exists(LIBRARIES_DIR)) Files.createDirectories(LIBRARIES_DIR);
|
||||
LOGGER.info("Initializing UI");
|
||||
WINDOWS.add(new MainWindow());
|
||||
GLaunch gLaunch = new GLaunch();
|
||||
gLaunch.init();
|
||||
gLaunch.run();
|
||||
gLaunch.dispose();
|
||||
}
|
||||
|
||||
public static void open(Window window) {
|
||||
WINDOWS.add(window);
|
||||
}
|
||||
|
||||
private final ImGuiImplGlfw imGuiGlfw = new ImGuiImplGlfw();
|
||||
private final ImGuiImplGl3 imGuiGl3 = new ImGuiImplGl3();
|
||||
|
||||
private String glslVersion = null;
|
||||
|
||||
/**
|
||||
* Pointer to the native GLFW window.
|
||||
*/
|
||||
protected long handle;
|
||||
|
||||
/**
|
||||
* Method to initialize application.
|
||||
*/
|
||||
protected void init() {
|
||||
initWindow();
|
||||
initImGui();
|
||||
imGuiGlfw.init(handle, true);
|
||||
imGuiGl3.init(glslVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to dispose all used application resources and destroy its window.
|
||||
*/
|
||||
protected void dispose() {
|
||||
imGuiGl3.dispose();
|
||||
imGuiGlfw.dispose();
|
||||
disposeImGui();
|
||||
disposeWindow();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create and initialize GLFW window.
|
||||
*/
|
||||
protected void initWindow() {
|
||||
GLFWErrorCallback.createPrint(System.err).set();
|
||||
|
||||
if (!GLFW.glfwInit()) {
|
||||
throw new IllegalStateException("Unable to initialize GLFW");
|
||||
}
|
||||
|
||||
decideGlGlslVersions();
|
||||
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GLFW.GLFW_FALSE);
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, GLFW.GLFW_FALSE);
|
||||
handle = GLFW.glfwCreateWindow(10, 10, "GLaunch", MemoryUtil.NULL, MemoryUtil.NULL);
|
||||
|
||||
if (handle == MemoryUtil.NULL) {
|
||||
throw new RuntimeException("Failed to create the GLFW window");
|
||||
}
|
||||
|
||||
try (MemoryStack stack = MemoryStack.stackPush()) {
|
||||
final IntBuffer pWidth = stack.mallocInt(1); // int*
|
||||
final IntBuffer pHeight = stack.mallocInt(1); // int*
|
||||
|
||||
GLFW.glfwGetWindowSize(handle, pWidth, pHeight);
|
||||
final GLFWVidMode vidmode = Objects.requireNonNull(GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor()));
|
||||
GLFW.glfwSetWindowPos(handle, (vidmode.width() - pWidth.get(0)) / 2, (vidmode.height() - pHeight.get(0)) / 2);
|
||||
}
|
||||
|
||||
GLFW.glfwMakeContextCurrent(handle);
|
||||
|
||||
GL.createCapabilities();
|
||||
|
||||
GLFW.glfwSwapInterval(GLFW.GLFW_TRUE);
|
||||
|
||||
//GLFW.glfwShowWindow(handle);
|
||||
|
||||
clearBuffer();
|
||||
renderBuffer();
|
||||
|
||||
GLFW.glfwSetWindowSizeCallback(handle, new GLFWWindowSizeCallback() {
|
||||
@Override
|
||||
public void invoke(final long window, final int width, final int height) {
|
||||
runFrame();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void decideGlGlslVersions() {
|
||||
final boolean isMac = System.getProperty("os.name").toLowerCase().contains("mac");
|
||||
if (isMac) {
|
||||
glslVersion = "#version 150";
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, 2);
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, GLFW.GLFW_TRUE); // Required on Mac
|
||||
} else {
|
||||
glslVersion = "#version 130";
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to initialize Dear ImGui context. Could be overridden to do custom Dear ImGui setup before application start.
|
||||
*/
|
||||
protected void initImGui() {
|
||||
ImGui.createContext();
|
||||
ImGuiIO io = ImGui.getIO();
|
||||
io.addConfigFlags(ImGuiConfigFlags.ViewportsEnable);
|
||||
//io.setConfigViewportsNoDecoration(false);
|
||||
io.setConfigViewportsNoAutoMerge(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Main application loop.
|
||||
*/
|
||||
protected void run() {
|
||||
while (!GLFW.glfwWindowShouldClose(handle)) {
|
||||
runFrame();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used to run the next frame.
|
||||
*/
|
||||
protected void runFrame() {
|
||||
startFrame();
|
||||
process();
|
||||
endFrame();
|
||||
}
|
||||
|
||||
public void process() {
|
||||
if (GLaunch.WINDOWS.isEmpty()) close();
|
||||
else {
|
||||
for (Window window : GLaunch.WINDOWS.toArray(new Window[0])) {
|
||||
if (window.isNew()) window.preFirstDraw();
|
||||
ImGui.begin(window.getName());
|
||||
window.draw();
|
||||
ImGui.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used to clear the OpenGL buffer.
|
||||
*/
|
||||
private void clearBuffer() {
|
||||
GL32.glClear(GL32.GL_COLOR_BUFFER_BIT | GL32.GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method called at the beginning of the main cycle.
|
||||
* It clears OpenGL buffer and starts an ImGui frame.
|
||||
*/
|
||||
protected void startFrame() {
|
||||
clearBuffer();
|
||||
imGuiGlfw.newFrame();
|
||||
ImGui.newFrame();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method called in the end of the main cycle.
|
||||
* It renders ImGui and swaps GLFW buffers to show an updated frame.
|
||||
*/
|
||||
protected void endFrame() {
|
||||
ImGui.render();
|
||||
imGuiGl3.renderDrawData(ImGui.getDrawData());
|
||||
|
||||
if (ImGui.getIO().hasConfigFlags(ImGuiConfigFlags.ViewportsEnable)) {
|
||||
final long backupWindowPtr = GLFW.glfwGetCurrentContext();
|
||||
ImGui.updatePlatformWindows();
|
||||
ImGui.renderPlatformWindowsDefault();
|
||||
GLFW.glfwMakeContextCurrent(backupWindowPtr);
|
||||
}
|
||||
|
||||
renderBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to render the OpenGL buffer and poll window events.
|
||||
*/
|
||||
private void renderBuffer() {
|
||||
GLFW.glfwSwapBuffers(handle);
|
||||
GLFW.glfwPollEvents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to destroy Dear ImGui context.
|
||||
*/
|
||||
protected void disposeImGui() {
|
||||
ImGui.destroyContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to destroy GLFW window.
|
||||
*/
|
||||
protected void disposeWindow() {
|
||||
Callbacks.glfwFreeCallbacks(handle);
|
||||
GLFW.glfwDestroyWindow(handle);
|
||||
GLFW.glfwTerminate();
|
||||
Objects.requireNonNull(GLFW.glfwSetErrorCallback(null)).free();
|
||||
}
|
||||
|
||||
public void close() {
|
||||
GLFW.glfwSetWindowShouldClose(handle, true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package io.gitlab.jfronny.glaunch;
|
||||
|
||||
public abstract class Window {
|
||||
private final String name;
|
||||
private boolean isNew = true;
|
||||
|
||||
public Window(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void preFirstDraw() {
|
||||
}
|
||||
public abstract void draw();
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
GLaunch.WINDOWS.remove(this);
|
||||
}
|
||||
|
||||
public boolean isNew() {
|
||||
if (isNew) {
|
||||
isNew = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package io.gitlab.jfronny.glaunch.gson;
|
||||
|
||||
import com.google.gson.*;
|
||||
import io.gitlab.jfronny.glaunch.model.MinecraftArgument;
|
||||
import io.gitlab.jfronny.glaunch.model.Rules;
|
||||
import io.gitlab.jfronny.glaunch.util.Utils;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class MinecraftArgumentDeserializer implements JsonDeserializer<MinecraftArgument> {
|
||||
@Override
|
||||
public MinecraftArgument deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isString()) {
|
||||
return new MinecraftArgument(Set.of(json.getAsString()));
|
||||
}
|
||||
else if (json.isJsonObject()) {
|
||||
JsonObject jo = json.getAsJsonObject();
|
||||
if (jo.size() != 2 || !jo.has("rules") || !jo.has("value"))
|
||||
throw new JsonParseException("Not a valid minecraft argument");
|
||||
/*boolean valid = true;
|
||||
for (JsonElement rule : jo.get("rules").getAsJsonArray()) {
|
||||
JsonObject ro = rule.getAsJsonObject();
|
||||
if (!ro.get("action").getAsJsonPrimitive().getAsString().equals("allow"))
|
||||
throw new JsonParseException("Unexpected action in argument");
|
||||
if (ro.has("features")) { //TODO support has_custom_resolution
|
||||
valid = false;
|
||||
continue;
|
||||
}
|
||||
if (ro.has("os")) {
|
||||
JsonObject osObject = ro.get("os").getAsJsonObject();
|
||||
if (osObject.has("name")) {
|
||||
if (!Utils.getOs().equals(osObject.get("name").getAsString())) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (osObject.has("version")) {
|
||||
if (!System.getProperty("os.version").matches(osObject.get("version").getAsString())) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
Rules r = context.deserialize(jo.get("rules"), Rules.class);
|
||||
if (!r.allow()) return new MinecraftArgument(Set.of());
|
||||
Set<String> sel = new LinkedHashSet<>();
|
||||
for (JsonElement value : jo.get("value").getAsJsonArray()) {
|
||||
sel.add(value.getAsString());
|
||||
}
|
||||
return new MinecraftArgument(Set.copyOf(sel));
|
||||
}
|
||||
else throw new JsonParseException("Not a valid minecraft argument");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package io.gitlab.jfronny.glaunch.gson;
|
||||
|
||||
import com.google.gson.*;
|
||||
import io.gitlab.jfronny.glaunch.model.Rules;
|
||||
import io.gitlab.jfronny.glaunch.util.Utils;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class RulesDeserializer implements JsonDeserializer<Rules> {
|
||||
@Override
|
||||
public Rules deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
boolean valid = true;
|
||||
for (JsonElement rule : json.getAsJsonArray()) {
|
||||
JsonObject ro = rule.getAsJsonObject();
|
||||
if (!ro.get("action").getAsJsonPrimitive().getAsString().equals("allow"))
|
||||
throw new JsonParseException("Unexpected action in argument");
|
||||
if (ro.has("features")) { //TODO support has_custom_resolution
|
||||
valid = false;
|
||||
continue;
|
||||
}
|
||||
if (ro.has("os")) {
|
||||
JsonObject osObject = ro.get("os").getAsJsonObject();
|
||||
if (osObject.has("name")) {
|
||||
if (!Utils.getOs().equals(osObject.get("name").getAsString())) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (osObject.has("version")) {
|
||||
if (!System.getProperty("os.version").matches(osObject.get("version").getAsString())) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Rules(valid);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package io.gitlab.jfronny.glaunch.install;
|
||||
|
||||
import io.gitlab.jfronny.glaunch.model.VersionInfo;
|
||||
import io.gitlab.jfronny.glaunch.windows.NewInstanceWindow;
|
||||
|
||||
public final class SetupStepInfo {
|
||||
private final VersionInfo version;
|
||||
private final NewInstanceWindow.LoaderType loaderType;
|
||||
private final String name;
|
||||
private String classpath;
|
||||
|
||||
public SetupStepInfo(VersionInfo version, NewInstanceWindow.LoaderType loaderType, String name) {
|
||||
this.version = version;
|
||||
this.loaderType = loaderType;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public VersionInfo getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public NewInstanceWindow.LoaderType getLoaderType() {
|
||||
return loaderType;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setClasspath(String classpath) {
|
||||
this.classpath = classpath;
|
||||
}
|
||||
|
||||
public String getClasspath() {
|
||||
return classpath;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package io.gitlab.jfronny.glaunch.install;
|
||||
|
||||
import io.gitlab.jfronny.glaunch.model.VersionInfo;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface Step {
|
||||
void execute(SetupStepInfo info) throws IOException;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package io.gitlab.jfronny.glaunch.install;
|
||||
|
||||
import io.gitlab.jfronny.glaunch.install.steps.*;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class Steps {
|
||||
public static Set<Step> STEPS = Set.of(
|
||||
new SetupDirsStep(),
|
||||
new DownloadClientStep(),
|
||||
new DownloadAssetsStep(),
|
||||
new DownloadLibrariesStep(),
|
||||
new WriteMetadataStep()
|
||||
);
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package io.gitlab.jfronny.glaunch.install.steps;
|
||||
|
||||
import io.gitlab.jfronny.glaunch.GLaunch;
|
||||
import io.gitlab.jfronny.glaunch.install.SetupStepInfo;
|
||||
import io.gitlab.jfronny.glaunch.install.Step;
|
||||
import io.gitlab.jfronny.glaunch.model.AssetIndex;
|
||||
import io.gitlab.jfronny.glaunch.util.mojang.McApi;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
|
||||
public class DownloadAssetsStep implements Step {
|
||||
@Override
|
||||
public void execute(SetupStepInfo info) throws IOException {
|
||||
//TODO feedback
|
||||
Path o = GLaunch.ASSETS_DIR.resolve("objects");
|
||||
for (Map.Entry<String, AssetIndex.Asset> entry : McApi.getAssetIndex(info.getVersion()).objects.entrySet()) {
|
||||
Path fPath = o.resolve(entry.getValue().hash.substring(0, 2));
|
||||
if (!Files.exists(fPath)) Files.createDirectories(fPath);
|
||||
McApi.downloadAsset(entry.getValue(), fPath.resolve(entry.getValue().hash));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package io.gitlab.jfronny.glaunch.install.steps;
|
||||
|
||||
import io.gitlab.jfronny.glaunch.GLaunch;
|
||||
import io.gitlab.jfronny.glaunch.install.SetupStepInfo;
|
||||
import io.gitlab.jfronny.glaunch.install.Step;
|
||||
import io.gitlab.jfronny.glaunch.model.VersionInfo;
|
||||
import io.gitlab.jfronny.glaunch.util.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class DownloadClientStep implements Step {
|
||||
@Override
|
||||
public void execute(SetupStepInfo info) throws IOException {
|
||||
VersionInfo.Downloads.Download client = info.getVersion().downloads.client;
|
||||
Utils.downloadFile(client.url, client.sha1, GLaunch.LIBRARIES_DIR.resolve(info.getVersion().id + ".jar"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package io.gitlab.jfronny.glaunch.install.steps;
|
||||
|
||||
import io.gitlab.jfronny.glaunch.GLaunch;
|
||||
import io.gitlab.jfronny.glaunch.install.SetupStepInfo;
|
||||
import io.gitlab.jfronny.glaunch.install.Step;
|
||||
import io.gitlab.jfronny.glaunch.model.Rules;
|
||||
import io.gitlab.jfronny.glaunch.model.VersionInfo;
|
||||
import io.gitlab.jfronny.glaunch.util.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class DownloadLibrariesStep implements Step {
|
||||
@Override
|
||||
public void execute(SetupStepInfo info) throws IOException {
|
||||
//TODO info.setClasspath("");
|
||||
//TODO feedback
|
||||
mainLoop: for (VersionInfo.Library library : info.getVersion().libraries) {
|
||||
for (Rules rule : library.rules) {
|
||||
if (!rule.allow()) continue mainLoop;
|
||||
}
|
||||
if (library.classifiers != null) {
|
||||
downloadLib(switch (Utils.getOs()) {
|
||||
case "osx" -> library.classifiers.nativesMacos;
|
||||
case "windows" -> library.classifiers.nativesWindows;
|
||||
case "linux" -> library.classifiers.nativesLinux;
|
||||
default -> throw new RuntimeException("Not a valid OS");
|
||||
});
|
||||
}
|
||||
downloadLib(library.artifact);
|
||||
}
|
||||
}
|
||||
|
||||
private void downloadLib(VersionInfo.Library.Artifact artifact) throws IOException {
|
||||
//TODO allow maven-like download for fabric
|
||||
Utils.downloadFile(artifact.url, artifact.sha1, GLaunch.LIBRARIES_DIR.resolve(artifact.path));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package io.gitlab.jfronny.glaunch.install.steps;
|
||||
|
||||
import io.gitlab.jfronny.glaunch.GLaunch;
|
||||
import io.gitlab.jfronny.glaunch.install.SetupStepInfo;
|
||||
import io.gitlab.jfronny.glaunch.install.Step;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class SetupDirsStep implements Step {
|
||||
@Override
|
||||
public void execute(SetupStepInfo info) throws IOException {
|
||||
Path iDir = GLaunch.INSTANCE_DIR.resolve(info.getName());
|
||||
if (!Files.exists(iDir))
|
||||
Files.createDirectories(iDir);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package io.gitlab.jfronny.glaunch.install.steps;
|
||||
|
||||
import io.gitlab.jfronny.glaunch.GLaunch;
|
||||
import io.gitlab.jfronny.glaunch.install.SetupStepInfo;
|
||||
import io.gitlab.jfronny.glaunch.install.Step;
|
||||
import io.gitlab.jfronny.glaunch.model.InstanceMeta;
|
||||
import io.gitlab.jfronny.glaunch.util.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class WriteMetadataStep implements Step {
|
||||
@Override
|
||||
public void execute(SetupStepInfo info) throws IOException {
|
||||
Path metaDir = GLaunch.INSTANCE_DIR.resolve(info.getName()).resolve("instance.json");
|
||||
InstanceMeta meta = new InstanceMeta();
|
||||
meta.loaderType = info.getLoaderType();
|
||||
meta.version = info.getVersion().id;
|
||||
Utils.writeObject(metaDir, meta);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package io.gitlab.jfronny.glaunch.model;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class AssetIndex {
|
||||
public Map<String, Asset> objects;
|
||||
|
||||
public static class Asset {
|
||||
public String hash;
|
||||
public int size;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package io.gitlab.jfronny.glaunch.model;
|
||||
|
||||
import io.gitlab.jfronny.glaunch.windows.NewInstanceWindow;
|
||||
|
||||
public class InstanceMeta {
|
||||
public NewInstanceWindow.LoaderType loaderType;
|
||||
public String version;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package io.gitlab.jfronny.glaunch.model;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public record MinecraftArgument(Set<String> arg) {
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package io.gitlab.jfronny.glaunch.model;
|
||||
|
||||
public record Rules(boolean allow) {
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
package io.gitlab.jfronny.glaunch.model;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class VersionInfo {
|
||||
public Arguments arguments;
|
||||
public AssetIndex assetIndex;
|
||||
public String assets;
|
||||
public int complianceLevel;
|
||||
public Downloads downloads;
|
||||
public String id;
|
||||
public JavaVersion javaVersion;
|
||||
public List<Library> libraries;
|
||||
public String mainClass;
|
||||
public Integer minimumLauncherVersion;
|
||||
public String releaseTime;
|
||||
public String time;
|
||||
public String type;
|
||||
|
||||
public static class Arguments {
|
||||
public List<MinecraftArgument> game;
|
||||
public List<MinecraftArgument> jvm;
|
||||
}
|
||||
|
||||
public static class AssetIndex {
|
||||
public String id;
|
||||
public String sha1;
|
||||
public int size;
|
||||
public int totalSize;
|
||||
public String url;
|
||||
}
|
||||
|
||||
public static class Downloads {
|
||||
public Download client;
|
||||
public Download client_mappings;
|
||||
public Download server;
|
||||
public Download server_mappings;
|
||||
|
||||
public static class Download {
|
||||
public String sha1;
|
||||
public int size;
|
||||
public String url;
|
||||
}
|
||||
}
|
||||
|
||||
public static class JavaVersion {
|
||||
public String component;
|
||||
public int majorVersion;
|
||||
}
|
||||
|
||||
public static class Library {
|
||||
public Artifact artifact;
|
||||
public String name;
|
||||
public Set<Rules> rules = new LinkedHashSet<>();
|
||||
public Classifiers classifiers;
|
||||
|
||||
public static class Artifact {
|
||||
public String path;
|
||||
public String sha1;
|
||||
public int size;
|
||||
public String url;
|
||||
}
|
||||
|
||||
public static class Classifiers {
|
||||
public Artifact javadoc;
|
||||
public Artifact nativesLinux;
|
||||
public Artifact nativesMacos;
|
||||
public Artifact nativesWindows;
|
||||
public Artifact sources;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Logging {
|
||||
public Client client;
|
||||
|
||||
public static class Client {
|
||||
public String argument;
|
||||
public Library.Artifact file;
|
||||
public String type;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package io.gitlab.jfronny.glaunch.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class VersionsList {
|
||||
public Latest latest;
|
||||
public List<VersionsListInfo> versions;
|
||||
|
||||
public static class Latest {
|
||||
public String release;
|
||||
public String snapshot;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package io.gitlab.jfronny.glaunch.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class VersionsListInfo {
|
||||
public String id;
|
||||
public String type;
|
||||
public String url;
|
||||
public Date time;
|
||||
public Date releaseTime;
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
package io.gitlab.jfronny.glaunch.util;
|
||||
|
||||
import io.gitlab.jfronny.glaunch.GLaunch;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Formatter;
|
||||
import java.util.Locale;
|
||||
|
||||
public class Utils {
|
||||
public static String hash(byte[] data) {
|
||||
Formatter formatter = new Formatter();
|
||||
try {
|
||||
for (byte b : MessageDigest.getInstance("SHA-1").digest(data))
|
||||
formatter.format("%02x", b);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException("Could not hash using SHA1", e);
|
||||
}
|
||||
return formatter.toString();
|
||||
}
|
||||
|
||||
public static String getOs() {
|
||||
String os = System.getProperty("os.name", "generic").toLowerCase(Locale.ROOT);
|
||||
if ((os.contains("mac")) || (os.contains("darwin"))) {
|
||||
return "osx";
|
||||
} else if (os.contains("win")) {
|
||||
return "windows";
|
||||
} else if (os.contains("nux")) {
|
||||
return "linux";
|
||||
} else {
|
||||
throw new RuntimeException("Unrecognized OS");
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] downloadData(String url) throws IOException {
|
||||
try (InputStream is = new URL(url).openStream()) {
|
||||
return is.readAllBytes();
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] downloadData(String url, String sha1) throws IOException {
|
||||
byte[] buf = downloadData(url);
|
||||
if (!Utils.hash(buf).equals(sha1)) throw new IOException("Invalid hash");
|
||||
return buf;
|
||||
}
|
||||
|
||||
//TODO generify
|
||||
public static <T> T downloadObject(String url, Class<T> type) throws IOException {
|
||||
Path cache = GLaunch.CACHE_DIR.resolve(Integer.toString(url.hashCode()));
|
||||
try {
|
||||
String download = downloadString(url);
|
||||
Files.writeString(cache, download);
|
||||
return GLaunch.GSON.fromJson(download, type);
|
||||
} catch (IOException e) {
|
||||
if (Files.exists(cache)) {
|
||||
GLaunch.LOGGER.info("Using cache for " + url, e);
|
||||
try (BufferedReader br = Files.newBufferedReader(cache)) {
|
||||
return GLaunch.GSON.fromJson(br, type);
|
||||
} catch (IOException ioE) {
|
||||
throw new IOException("Could not download object and failed loading cache", ioE);
|
||||
}
|
||||
} else
|
||||
throw new IOException("Could not download object and no cache exists", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T downloadObject(String url, String sha1, Class<T> type) throws IOException {
|
||||
Path cache = GLaunch.CACHE_DIR.resolve(Integer.toString(url.hashCode()));
|
||||
try {
|
||||
String download = downloadString(url, sha1);
|
||||
Files.writeString(cache, download);
|
||||
return GLaunch.GSON.fromJson(download, type);
|
||||
} catch (IOException e) {
|
||||
if (Files.exists(cache)) {
|
||||
GLaunch.LOGGER.info("Using cache for " + url, e);
|
||||
try (BufferedReader br = Files.newBufferedReader(cache)) {
|
||||
return GLaunch.GSON.fromJson(br, type);
|
||||
} catch (IOException ioE) {
|
||||
throw new IOException("Could not download object and failed loading cache", ioE);
|
||||
}
|
||||
} else
|
||||
throw new IOException("Could not download object and no cache exists", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T loadObject(Path file, Class<T> type) throws IOException {
|
||||
try (BufferedReader br = Files.newBufferedReader(file)) {
|
||||
return GLaunch.GSON.fromJson(br, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void writeObject(Path file, T object) throws IOException {
|
||||
try (BufferedWriter bw = Files.newBufferedWriter(file)) {
|
||||
GLaunch.GSON.toJson(object, bw);
|
||||
}
|
||||
}
|
||||
|
||||
private static String downloadString(String url) throws IOException {
|
||||
try (InputStream is = new URL(url).openStream();
|
||||
Reader isr = new InputStreamReader(is);
|
||||
BufferedReader br = new BufferedReader(isr)) {
|
||||
StringBuilder text = new StringBuilder();
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
text.append('\n').append(line);
|
||||
return text.substring(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static String downloadString(String url, String sha1) throws IOException {
|
||||
return new String(downloadData(url, sha1), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static void downloadFile(String url, String sha1, Path path) throws IOException {
|
||||
Files.write(path, downloadData(url, sha1));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package io.gitlab.jfronny.glaunch.util.mojang;
|
||||
|
||||
import io.gitlab.jfronny.glaunch.GLaunch;
|
||||
import io.gitlab.jfronny.glaunch.model.AssetIndex;
|
||||
import io.gitlab.jfronny.glaunch.model.VersionInfo;
|
||||
import io.gitlab.jfronny.glaunch.model.VersionsList;
|
||||
import io.gitlab.jfronny.glaunch.model.VersionsListInfo;
|
||||
import io.gitlab.jfronny.glaunch.util.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static io.gitlab.jfronny.glaunch.util.Utils.downloadObject;
|
||||
|
||||
public class McApi {
|
||||
public static VersionsList getVersions() {
|
||||
try {
|
||||
return downloadObject("https://launchermeta.mojang.com/mc/game/version_manifest.json", VersionsList.class);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Could not load version manifest", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static VersionInfo getVersionInfo(VersionsListInfo listInfo) throws IOException {
|
||||
return downloadObject(listInfo.url, VersionInfo.class);
|
||||
}
|
||||
|
||||
public static AssetIndex getAssetIndex(VersionInfo info) throws IOException {
|
||||
Path file = GLaunch.ASSETS_DIR.resolve("indexes");
|
||||
if (!Files.exists(file)) Files.createDirectories(file);
|
||||
file = file.resolve(Path.of(info.assetIndex.url).getFileName());
|
||||
try {
|
||||
Utils.downloadFile(info.assetIndex.url, info.assetIndex.sha1, file);
|
||||
}
|
||||
catch (IOException e) {
|
||||
if (!Files.exists(file)) throw e;
|
||||
}
|
||||
return Utils.loadObject(file, AssetIndex.class);
|
||||
}
|
||||
|
||||
public static void downloadAsset(AssetIndex.Asset asset, Path path) throws IOException {
|
||||
String url = "http://resources.download.minecraft.net/" + asset.hash.substring(0, 2) + "/" + asset.hash;
|
||||
Utils.downloadFile(url, asset.hash, path);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package io.gitlab.jfronny.glaunch.windows;
|
||||
|
||||
import imgui.ImGui;
|
||||
import io.gitlab.jfronny.glaunch.Window;
|
||||
|
||||
public class AlertWindow extends Window {
|
||||
private final String message;
|
||||
|
||||
public AlertWindow(String message) {
|
||||
super("Warning");
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
ImGui.text(message);
|
||||
if (ImGui.button("OK")) close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package io.gitlab.jfronny.glaunch.windows;
|
||||
|
||||
import imgui.ImGui;
|
||||
import io.gitlab.jfronny.glaunch.GLaunch;
|
||||
import io.gitlab.jfronny.glaunch.Window;
|
||||
|
||||
public class MainWindow extends Window {
|
||||
public MainWindow() {
|
||||
super("GLaunch");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
if (ImGui.button("Close"))
|
||||
close();
|
||||
if (ImGui.button("New")) {
|
||||
GLaunch.open(new NewInstanceWindow());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
package io.gitlab.jfronny.glaunch.windows;
|
||||
|
||||
import imgui.ImGui;
|
||||
import imgui.type.ImString;
|
||||
import io.gitlab.jfronny.glaunch.GLaunch;
|
||||
import io.gitlab.jfronny.glaunch.Window;
|
||||
import io.gitlab.jfronny.glaunch.install.SetupStepInfo;
|
||||
import io.gitlab.jfronny.glaunch.install.Step;
|
||||
import io.gitlab.jfronny.glaunch.install.Steps;
|
||||
import io.gitlab.jfronny.glaunch.model.VersionsList;
|
||||
import io.gitlab.jfronny.glaunch.model.VersionsListInfo;
|
||||
import io.gitlab.jfronny.glaunch.util.mojang.McApi;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class NewInstanceWindow extends Window {
|
||||
VersionsList manifest = McApi.getVersions();
|
||||
VersionsListInfo selected = null;
|
||||
LoaderType loaderType = null;
|
||||
State state = State.Version;
|
||||
String name = "";
|
||||
public NewInstanceWindow() {
|
||||
super("New Instance");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preFirstDraw() {
|
||||
ImGui.setNextWindowSize(200, 800);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
if (ImGui.button("Cancel")) close();
|
||||
switch (state) {
|
||||
case Version -> {
|
||||
ImGui.text("Select a version");
|
||||
GLaunch.CONFIG.snapshots = ImGui.checkbox("Show snapshots", GLaunch.CONFIG.snapshots);
|
||||
if (ImGui.checkbox("Ae", true)) { //TODO fix
|
||||
GLaunch.LOGGER.info("Ao");
|
||||
}
|
||||
for (VersionsListInfo version : manifest.versions) {
|
||||
if (!version.type.equals("release") && !GLaunch.CONFIG.snapshots) continue;
|
||||
if (ImGui.button(version.id)) {
|
||||
selected = version;
|
||||
state = State.Loader;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
case Loader -> {
|
||||
ImGui.text("Select a mod loader"); //TODO implement fabric support
|
||||
for (LoaderType value : LoaderType.values()) {
|
||||
if (ImGui.button(value.name())) {
|
||||
state = State.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
case Name -> {
|
||||
ImString is = new ImString(name);
|
||||
ImGui.text("Select a name");
|
||||
ImGui.inputText("", is);
|
||||
name = is.get();
|
||||
if (ImGui.button("OK"))
|
||||
state = State.Installing;
|
||||
}
|
||||
case Installing -> {
|
||||
ImGui.text("Installing...");
|
||||
try {
|
||||
SetupStepInfo stepInfo = new SetupStepInfo(McApi.getVersionInfo(selected), loaderType, name);
|
||||
for (Step step : Steps.STEPS) {
|
||||
step.execute(stepInfo);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
GLaunch.LOGGER.error("Could not initialize instance", e);
|
||||
GLaunch.open(new AlertWindow("Could not initialize instance, look at the log for details"));
|
||||
close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum State {
|
||||
Version,
|
||||
Loader,
|
||||
Name,
|
||||
Installing
|
||||
}
|
||||
|
||||
public enum LoaderType {
|
||||
None,
|
||||
Fabric
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration xmlns="http://logging.apache.org/log4j/2.0/config">
|
||||
<Properties>
|
||||
<Property name="basePath">../Log4j2Example/logs</Property>
|
||||
</Properties>
|
||||
<Appenders>
|
||||
<Console name="STDOUT" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%-5p | %d{yyyy-MM-dd HH:mm:ss} | [%t] %C{2} (%F:%L) - %m%n" />
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Logger name="com.jcg" level="debug" />
|
||||
<Root level="info">
|
||||
<AppenderRef ref="STDOUT" />
|
||||
<AppenderRef ref="FILE" />
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
Loading…
Reference in New Issue