1- from os .path import exists
2- from json import loads
3- from os import remove , system
4- import zipfile
5-
6-
7-
8- def unpress (filename : str , path : str ):
9- Zip = zipfile .ZipFile (filename )
10- for z in Zip .namelist ():
11- Zip .extract (z , path )
12- Zip .close ()
13-
14- def isMyversion (version : str , mcdir : str ):
15- if (exists (f"{ mcdir } \\ versions\\ { version } \\ { version } .json" )):
16- return True
17- else :
18- return False
19-
20- def Launch (mcdir : str , version : str , javaw_path : str , MaxMem : str , username : str , width : str , height : str ):
21- commandLine = str ("" )
22- JVM = str ("" )
23- classpath = str ("" )
24- mc_args = str ("" )
25-
26- if ((not javaw_path == "" )\
27- and (not version == "" )\
28- and (not MaxMem == "" )\
29- and (not username == "" )\
30- and (not mcdir == "" )):
31- if (isMyversion (version , mcdir )):
32- version_json = open (f"{ mcdir } \\ versions\\ { version } \\ { version } .json" , "r" )
33- dic = loads (version_json .read ())
34- version_json .close ()
35- for lib in dic ["libraries" ]:
36- if "classifiers" in lib ['downloads' ]:
37- for native in lib ['downloads' ]:
38- if native == "artifact" :
39- dirct_path = f"{ mcdir } \\ versions\\ { version } \\ natives"
40- filepath = f"{ mcdir } \\ libraries\\ { lib ['downloads' ][native ]['path' ]} "
41- try :
42- unpress (filepath , dirct_path )
43- except :
44- pass
45- elif native == 'classifiers' :
46- for n in lib ['downloads' ][native ].values ():
47- dirct_path = f"{ mcdir } \\ versions\\ { version } \\ natives"
48- filepath = f'{ mcdir } \\ libraries\\ { n ["path" ]} '
49- try :
50- unpress (filepath , dirct_path )
51- except :
52- pass
53- JVM = '"' + javaw_path + '" -XX:+UseG1GC -XX:-UseAdaptiveSizePolicy' + \
54- ' -XX:-OmitStackTraceInFastThrow -Dfml.ignoreInvalidMinecraftCertificates=True ' + \
55- '-Dfml.ignorePatchDiscrepancies=True -Dlog4j2.formatMsgNoLookups=true ' + \
56- '-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump ' + \
57- '-Dos.name="Windows 10" -Dos.version=10.0 -Djava.library.path="' + \
58- mcdir + "\\ versions\\ " + version + "\\ " + "natives" + \
59- '" -Dminecraft.launcher.brand=launcher ' + \
60- '-Dminecraft.launcher.version=1.0.0 -cp'
61- classpath += '"'
62- for lib in dic ["libraries" ]:
63- if not 'classifiers' in lib ["downloads" ]:
64- normal = f'{ mcdir } \\ libraries\\ { lib ["downloads" ]["artifact" ]["path" ]} '
65- classpath += normal + ";"
66- classpath = f'{ classpath } { mcdir } \\ versions\\ { version } \\ { version } .jar"'
67- JVM = f"{ JVM } { classpath } -Xmx{ MaxMem } -Xmn256m -Dlog4j.formatMsgNoLookups=true"
68-
69- mc_args += dic ["mainClass" ] + " "
70- if "minecraftArguments" in dic :
71- mc_args += dic ["minecraftArguments" ]
72- mc_args = mc_args .replace ("${auth_player_name}" , username )# 玩家名称
73- mc_args = mc_args .replace ("${version_name}" , version )# 版本名称
74- mc_args = mc_args .replace ("${game_directory}" , mcdir )# mc路径
75- mc_args = mc_args .replace ("${assets_root}" , mcdir + "\\ assets" )# 资源文件路径
76- mc_args = mc_args .replace ("${assets_index_name}" ,dic ["assetIndex" ]["id" ])# 资源索引文件名称
77- mc_args = mc_args .replace ("${auth_uuid}" , "{}" )# 由于没有写微软登录,所以uuid为空的
78- mc_args = mc_args .replace ("${auth_access_token}" , "{}" )# 同上
79- mc_args = mc_args .replace ("${clientid}" , version )# 客户端id
80- mc_args = mc_args .replace ("${auth_xuid}" , "{}" )# 离线登录,不填
81- mc_args = mc_args .replace ("${user_type}" , "Legacy" )# 用户类型,离线模式是Legacy
82- mc_args = mc_args .replace ("${version_type}" , dic ["type" ])# 版本类型
83- mc_args = mc_args .replace ("${user_properties}" , "{}" )
84- mc_args += f"--width { width } "
85- mc_args += f" --height { height } "
86- else :
87- for arg in dic ["arguments" ]["game" ]:
88- if isinstance (arg , str ):
89- mc_args += arg + " "
90- elif isinstance (arg , dict ):
91- if isinstance (arg ["value" ], list ):
92- for a in arg ["value" ]:
93- mc_args += a + " "
94- elif isinstance (arg ["value" ], str ):
95- mc_args += arg ["value" ] + " "
96-
97- mc_args = mc_args .replace ("${auth_player_name}" , username )# 玩家名称
98- mc_args = mc_args .replace ("${version_name}" , version )# 版本名称
99- mc_args = mc_args .replace ("${game_directory}" , mcdir )# mc路径
100- mc_args = mc_args .replace ("${assets_root}" , mcdir + "\\ assets" )# 资源文件路径
101- mc_args = mc_args .replace ("${assets_index_name}" ,dic ["assetIndex" ]["id" ])# 资源索引文件名称
102- mc_args = mc_args .replace ("${auth_uuid}" , "{}" )# 由于没有写微软登录,所以uuid为空的
103- mc_args = mc_args .replace ("${auth_access_token}" , "{}" )# 同上
104- mc_args = mc_args .replace ("${clientid}" , version )# 客户端id
105- mc_args = mc_args .replace ("${auth_xuid}" , "{}" )# 离线登录,不填
106- mc_args = mc_args .replace ("${user_type}" , "Legacy" )# 用户类型,离线模式是Legacy
107- mc_args = mc_args .replace ("${version_type}" , dic ["type" ])# 版本类型
108- mc_args = mc_args .replace ("${resolution_width}" , width )# 窗口宽度
109- mc_args = mc_args .replace ("${resolution_height}" , height )# 窗口高度
110- mc_args = mc_args .replace ("-demo " , "" )# 去掉-demo参数,退出试玩版
111-
112- commandLine = JVM + " " + mc_args
113- bat = open ("run.bat" , "w" )
114- bat .write (commandLine )
115- bat .close ()
116- system ("run.bat" )
1+ from os .path import exists
2+ from json import loads
3+ from os import remove , system
4+ import zipfile
5+
6+
7+
8+ def unpress (filename : str , path : str ):
9+ Zip = zipfile .ZipFile (filename )
10+ for z in Zip .namelist ():
11+ Zip .extract (z , path )
12+ Zip .close ()
13+
14+ def isMyversion (version : str , mcdir : str ):
15+ if (exists (f"{ mcdir } \\ versions\\ { version } \\ { version } .json" )):
16+ return True
17+ else :
18+ return False
19+
20+ def Launch (mcdir : str , version : str , javaw_path : str , MaxMem : str , username : str , width : str , height : str ):
21+ commandLine = str ("" )
22+ JVM = str ("" )
23+ classpath = str ("" )
24+ mc_args = str ("" )
25+
26+ if ((not javaw_path == "" )\
27+ and (not version == "" )\
28+ and (not MaxMem == "" )\
29+ and (not username == "" )\
30+ and (not mcdir == "" )):
31+ if (isMyversion (version , mcdir )):
32+ version_json = open (f"{ mcdir } \\ versions\\ { version } \\ { version } .json" , "r" )
33+ dic = loads (version_json .read ())
34+ version_json .close ()
35+ for lib in dic ["libraries" ]:
36+ if "classifiers" in lib ['downloads' ]:
37+ for native in lib ['downloads' ]:
38+ if native == "artifact" :
39+ dirct_path = f"{ mcdir } \\ versions\\ { version } \\ natives"
40+ filepath = f"{ mcdir } \\ libraries\\ { lib ['downloads' ][native ]['path' ]} "
41+ try :
42+ unpress (filepath , dirct_path )
43+ except :
44+ pass
45+ elif native == 'classifiers' :
46+ for n in lib ['downloads' ][native ].values ():
47+ dirct_path = f"{ mcdir } \\ versions\\ { version } \\ natives"
48+ filepath = f'{ mcdir } \\ libraries\\ { n ["path" ]} '
49+ try :
50+ unpress (filepath , dirct_path )
51+ except :
52+ pass
53+ JVM = '"' + javaw_path + '" -XX:+UseG1GC -XX:-UseAdaptiveSizePolicy' + \
54+ ' -XX:-OmitStackTraceInFastThrow -Dfml.ignoreInvalidMinecraftCertificates=True ' + \
55+ '-Dfml.ignorePatchDiscrepancies=True -Dlog4j2.formatMsgNoLookups=true ' + \
56+ '-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump ' + \
57+ '-Dos.name="Windows 10" -Dos.version=10.0 -Djava.library.path="' + \
58+ mcdir + "\\ versions\\ " + version + "\\ " + "natives" + \
59+ '" -Dminecraft.launcher.brand=launcher ' + \
60+ '-Dminecraft.launcher.version=1.0.0 -cp'
61+ classpath += '"'
62+ for lib in dic ["libraries" ]:
63+ if not 'classifiers' in lib ["downloads" ]:
64+ normal = f'{ mcdir } \\ libraries\\ { lib ["downloads" ]["artifact" ]["path" ]} '
65+ classpath += normal + ";"
66+ classpath = f'{ classpath } { mcdir } \\ versions\\ { version } \\ { version } .jar"'
67+ JVM = f"{ JVM } { classpath } -Xmx{ MaxMem } -Xmn256m -Dlog4j.formatMsgNoLookups=true"
68+
69+ mc_args += dic ["mainClass" ] + " "
70+ if "minecraftArguments" in dic :
71+ mc_args += dic ["minecraftArguments" ]
72+ mc_args = mc_args .replace ("${auth_player_name}" , username )# 玩家名称
73+ mc_args = mc_args .replace ("${version_name}" , version )# 版本名称
74+ mc_args = mc_args .replace ("${game_directory}" , mcdir )# mc路径
75+ mc_args = mc_args .replace ("${assets_root}" , mcdir + "\\ assets" )# 资源文件路径
76+ mc_args = mc_args .replace ("${assets_index_name}" ,dic ["assetIndex" ]["id" ])# 资源索引文件名称
77+ mc_args = mc_args .replace ("${auth_uuid}" , "{}" )# 由于没有写微软登录,所以uuid为空的
78+ mc_args = mc_args .replace ("${auth_access_token}" , "{}" )# 同上
79+ mc_args = mc_args .replace ("${clientid}" , version )# 客户端id
80+ mc_args = mc_args .replace ("${auth_xuid}" , "{}" )# 离线登录,不填
81+ mc_args = mc_args .replace ("${user_type}" , "Legacy" )# 用户类型,离线模式是Legacy
82+ mc_args = mc_args .replace ("${version_type}" , dic ["type" ])# 版本类型
83+ mc_args = mc_args .replace ("${user_properties}" , "{}" )
84+ mc_args += f"--width { width } "
85+ mc_args += f" --height { height } "
86+ else :
87+ for arg in dic ["arguments" ]["game" ]:
88+ if isinstance (arg , str ):
89+ mc_args += arg + " "
90+ elif isinstance (arg , dict ):
91+ if isinstance (arg ["value" ], list ):
92+ for a in arg ["value" ]:
93+ mc_args += a + " "
94+ elif isinstance (arg ["value" ], str ):
95+ mc_args += arg ["value" ] + " "
96+
97+ mc_args = mc_args .replace ("${auth_player_name}" , username )# 玩家名称
98+ mc_args = mc_args .replace ("${version_name}" , version )# 版本名称
99+ mc_args = mc_args .replace ("${game_directory}" , mcdir )# mc路径
100+ mc_args = mc_args .replace ("${assets_root}" , mcdir + "\\ assets" )# 资源文件路径
101+ mc_args = mc_args .replace ("${assets_index_name}" ,dic ["assetIndex" ]["id" ])# 资源索引文件名称
102+ mc_args = mc_args .replace ("${auth_uuid}" , "{}" )# 由于没有写微软登录,所以uuid为空的
103+ mc_args = mc_args .replace ("${auth_access_token}" , "{}" )# 同上
104+ mc_args = mc_args .replace ("${clientid}" , version )# 客户端id
105+ mc_args = mc_args .replace ("${auth_xuid}" , "{}" )# 离线登录,不填
106+ mc_args = mc_args .replace ("${user_type}" , "Legacy" )# 用户类型,离线模式是Legacy
107+ mc_args = mc_args .replace ("${version_type}" , dic ["type" ])# 版本类型
108+ mc_args = mc_args .replace ("${resolution_width}" , width )# 窗口宽度
109+ mc_args = mc_args .replace ("${resolution_height}" , height )# 窗口高度
110+ mc_args = mc_args .replace ("-demo " , "" )# 去掉-demo参数,退出试玩版
111+
112+ commandLine = JVM + " " + mc_args
113+ bat = open ("run.bat" , "w" )
114+ bat .write (commandLine )
115+ bat .close ()
116+ system ("run.bat" )
117117 remove ("run.bat" )
0 commit comments