Skip to content

Commit 661e9f8

Browse files
committed
MinecraftLaunch.python
1 parent 789f34e commit 661e9f8

File tree

3 files changed

+277
-277
lines changed

3 files changed

+277
-277
lines changed
Lines changed: 116 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,117 @@
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")
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,81 @@
1-
from requests import post, get
2-
import webbrowser
3-
from json import loads, dumps
4-
5-
6-
7-
def OAuth():
8-
# 重定向
9-
webbrowser.open("https://login.live.com/oauth20_authorize.srf\
10-
?client_id=00000000402b5328\
11-
&response_type=code\
12-
&scope=service%3A%3Auser.auth.xboxlive.com%3A%3AMBI_SSL\
13-
&redirect_uri=https%3A%2F%2Flogin.live.com%2Foauth20_desktop.srf")
14-
result = input("请输入重定向链接:")
15-
begin = result.find("code=") + 5
16-
end = result.find("&lc")
17-
code = str("")
18-
for i in range(begin, end):
19-
code += result[i]
20-
data = {
21-
"client_id": "00000000402b5328",
22-
"code": code,
23-
"grant_type": "authorization_code",
24-
"redirect_uri": "https://login.live.com/oauth20_desktop.srf",
25-
"scope": "service::user.auth.xboxlive.com::MBI_SSL"
26-
}
27-
url = "https://login.live.com/oauth20_token.srf"
28-
header = {
29-
"Content-Type": "application/x-www-form-urlencoded"
30-
}
31-
res = post(url = url, data = data, headers = header)
32-
dic = loads(res.text)
33-
access_token = dic["access_token"]
34-
# Xbox Live 验证
35-
data = dumps({
36-
"Properties": {
37-
"AuthMethod": "RPS",
38-
"SiteName": "user.auth.xboxlive.com",
39-
"RpsTicket": access_token
40-
},
41-
"RelyingParty": "http://auth.xboxlive.com",
42-
"TokenType": "JWT"
43-
})
44-
url = "https://user.auth.xboxlive.com/user/authenticate"
45-
header = {
46-
"Content-Type": "application/json",
47-
"Accept": "application/json"
48-
}
49-
res = post(url = url, data = data, headers = header)
50-
Token = loads(res.text)["Token"]
51-
uhs = str()
52-
for i in loads(res.text)["DisplayClaims"]["xui"]:
53-
uhs = i["uhs"]
54-
# XSTS 验证
55-
data = dumps({
56-
" Properties": {
57-
"SandboxId": "RETAIL",
58-
"UserTokens": [
59-
Token
60-
]
61-
},
62-
"RelyingParty": "rp://api.minecraftservices.com/",
63-
"TokenType": "JWT"
64-
})
65-
url = "https://xsts.auth.xboxlive.com/xsts/authorize"
66-
header = {
67-
"Content-Type": "application/json",
68-
"Accept": "application/json"
69-
}
70-
res = post(url = url, data = data, headers = header)
71-
dic = loads(res.text)
72-
XSTS_Token = dic["Token"]
73-
# 获取Minecrat访问令牌
74-
data = dumps({
75-
"identityToken": f"XBL3.0 x={uhs}{XSTS_Token}"
76-
})
77-
url = "https://api.minecraftservices.com/authentication/login_with_xbox"
78-
res = post(url = url, data = data)
79-
print(res.text)
80-
1+
from requests import post, get
2+
import webbrowser
3+
from json import loads, dumps
4+
5+
6+
7+
def OAuth():
8+
# 重定向
9+
webbrowser.open("https://login.live.com/oauth20_authorize.srf\
10+
?client_id=00000000402b5328\
11+
&response_type=code\
12+
&scope=service%3A%3Auser.auth.xboxlive.com%3A%3AMBI_SSL\
13+
&redirect_uri=https%3A%2F%2Flogin.live.com%2Foauth20_desktop.srf")
14+
result = input("请输入重定向链接:")
15+
begin = result.find("code=") + 5
16+
end = result.find("&lc")
17+
code = str("")
18+
for i in range(begin, end):
19+
code += result[i]
20+
data = {
21+
"client_id": "00000000402b5328",
22+
"code": code,
23+
"grant_type": "authorization_code",
24+
"redirect_uri": "https://login.live.com/oauth20_desktop.srf",
25+
"scope": "service::user.auth.xboxlive.com::MBI_SSL"
26+
}
27+
url = "https://login.live.com/oauth20_token.srf"
28+
header = {
29+
"Content-Type": "application/x-www-form-urlencoded"
30+
}
31+
res = post(url = url, data = data, headers = header)
32+
dic = loads(res.text)
33+
access_token = dic["access_token"]
34+
# Xbox Live 验证
35+
data = dumps({
36+
"Properties": {
37+
"AuthMethod": "RPS",
38+
"SiteName": "user.auth.xboxlive.com",
39+
"RpsTicket": access_token
40+
},
41+
"RelyingParty": "http://auth.xboxlive.com",
42+
"TokenType": "JWT"
43+
})
44+
url = "https://user.auth.xboxlive.com/user/authenticate"
45+
header = {
46+
"Content-Type": "application/json",
47+
"Accept": "application/json"
48+
}
49+
res = post(url = url, data = data, headers = header)
50+
Token = loads(res.text)["Token"]
51+
uhs = str()
52+
for i in loads(res.text)["DisplayClaims"]["xui"]:
53+
uhs = i["uhs"]
54+
# XSTS 验证
55+
data = dumps({
56+
" Properties": {
57+
"SandboxId": "RETAIL",
58+
"UserTokens": [
59+
Token
60+
]
61+
},
62+
"RelyingParty": "rp://api.minecraftservices.com/",
63+
"TokenType": "JWT"
64+
})
65+
url = "https://xsts.auth.xboxlive.com/xsts/authorize"
66+
header = {
67+
"Content-Type": "application/json",
68+
"Accept": "application/json"
69+
}
70+
res = post(url = url, data = data, headers = header)
71+
dic = loads(res.text)
72+
XSTS_Token = dic["Token"]
73+
# 获取Minecrat访问令牌
74+
data = dumps({
75+
"identityToken": f"XBL3.0 x={uhs}{XSTS_Token}"
76+
})
77+
url = "https://api.minecraftservices.com/authentication/login_with_xbox"
78+
res = post(url = url, data = data)
79+
print(res.text)
80+
8181
OAuth()

0 commit comments

Comments
 (0)