-
Notifications
You must be signed in to change notification settings - Fork 0
/
launcher.nim
85 lines (71 loc) · 2.88 KB
/
launcher.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import os, system, json, rdstdin, sequtils, strutils
type
User* = ref object of RootObj
uuid*: string
username*: string
accessToken*: string
Client* = ref object of RootObj
path*: string
version*: string
proc getAssetIndex(path, mc_version: string): string =
if(fileExists(path&"/assets/indexes/"&mc_version&".json")):
return mc_version
else:
return mc_version.split(".")[0]&"."&mc_version.split(".")[1]
proc getVersionConfigPath(path, version: string): string =
return path&"/versions/"&version&"/"&version&".json"
proc getLibraryClasspath(path, lib: string): string =
return path&"/libraries/"&lib.split(":")[0].replace(".","/")&"/"&lib.split(":")[1]&"/"&lib.split(":")[2]&"/"
proc getLibraries(path, config: string): seq[string] =
var libs: seq[string]
var json = parseJson(readFile(config))
for lib in json["libraries"]:
var classpath = getLibraryClasspath(path, lib["name"].getStr())
try:
if lib["clientreq"].getBool() == true:
for file in walkDir(classpath):
echo file.path
libs.add file.path
except:
for file in walkDir(classpath):
echo file.path
libs.add file.path
return libs
proc collectClasspath(path, fg_version, mc_version: string): string =
echo "LOADING FORGE CLASSPATH"
var fg_libs = getLibraries(path, getVersionConfigPath(path, fg_version))
echo "LOADING GAME CLASSPATH"
var mc_libs = getLibraries(path, getVersionConfigPath(path, mc_version))
var gm_libs = concat(fg_libs, mc_libs)
return gm_libs.join(";")&";"&path&"/versions/"&mc_version&"/"&mc_version&".jar";
proc startClient(client: Client, user: User) =
if(fileExists(getVersionConfigPath(client.path, client.version))):
var json = parseJson(readFile(getVersionConfigPath(client.path, client.version)))
var cp = collectClasspath(client.path, client.version, json["inheritsFrom"].getStr())
var args: seq[string]
args.add "-Xms1024M"
args.add "-Xmx1024M"
args.add "-Djava.library.path="&client.path&"/versions/"&json["jar"].getStr()&"/natives"
args.add "-cp "&cp
args.add "net.minecraft.launchwrapper.Launch"
args.add "--width 854"
args.add "--height 480"
args.add "--username "&user.username
args.add "--uuid "&user.uuid
args.add "--accessToken "&user.accessToken
args.add "--userType mojang"
args.add "--version "&client.version
args.add "--gameDir "&client.path
args.add "--assetsDir "&client.path&"/assets"
args.add "--assetIndex "&getAssetIndex(client.path, json["inheritsFrom"].getStr())
args.add "--tweakClass net.minecraftforge.fml.common.launcher.FMLTweaker"
args.add "--versionType Forge"
discard execShellCmd("java "&args.join(" "))
var client = Client(
path: $getCurrentDir(),
version: "1.12.2-forge1.12.2-14.23.5.2847")
var user = User(
uuid: "N/A",
username: "Dev1lroot",
accessToken: "N/A")
startClient(client, user)