Skip to content

Commit 789f34e

Browse files
authored
Add files via upload
1 parent 5531554 commit 789f34e

File tree

3 files changed

+279
-0
lines changed

3 files changed

+279
-0
lines changed

Authenticator/MicrosoftAuth.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +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+
81+
OAuth()

Installer/GameCoreInstaller.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
from json import loads, dump, load
2+
from urllib.request import urlretrieve
3+
from sys import stdout
4+
from os.path import split
5+
import threading
6+
7+
def makedir(path):
8+
import os
9+
path = path.strip()
10+
path = path.rstrip("\\")
11+
isExists = os.path.exists(path)
12+
if not isExists:
13+
os.makedirs(path)
14+
return True
15+
else:
16+
return False
17+
18+
def beautifyjson(json_path: str):
19+
with open(json_path,encoding="utf-8") as f:
20+
json_to_dict = load(f)
21+
with open(json_path, "w", encoding='utf-8') as f:
22+
dump(json_to_dict,
23+
f,
24+
indent=2,
25+
sort_keys=True,
26+
ensure_ascii=False)
27+
28+
def download(url: str, path: str):
29+
try:
30+
(file_path, file_name) = split(path)
31+
makedir(file_path)
32+
def hook(blocknum, bs, size):
33+
a = int(float(blocknum * bs) / size * 100)
34+
if a >= 100:
35+
a = 100
36+
stdout.write("\r >>正在下载" + file_name + str(a) + "%")
37+
urlretrieve(url, path, reporthook = hook)
38+
print("\n")
39+
except:
40+
print("\n 网络异常,正在尝试重新下载\n")
41+
download(url = url, path = path)
42+
43+
def Install(version: str, mcdir: str, source: str):
44+
if source == "BMCLAPI":
45+
download(f"https://bmclapi2.bangbang93.com/version/{version}/client",
46+
f"{mcdir}\\versions\\{version}\\{version}.jar")
47+
download(f"https://bmclapi2.bangbang93.com/version/{version}/json",
48+
f"{mcdir}\\versions\\{version}\\{version}.json")
49+
beautifyjson(f"{mcdir}\\versions\\{version}\\{version}.json")
50+
version_json = open(f"{mcdir}\\versions\\{version}\\{version}.json", "r")
51+
dic = loads(version_json.read())
52+
version_json.close()
53+
for lib in dic["libraries"]:
54+
if 'artifact' in lib["downloads"] and not "classifiers" in lib["downloads"]:
55+
url = lib["downloads"]["artifact"]["url"].replace("https://libraries.minecraft.net",
56+
"https://bmclapi2.bangbang93.com/maven")
57+
path = f'{mcdir}\\libraries\\{lib["downloads"]["artifact"]["path"]}'
58+
t = threading.Thread(target = download, args = (url, path))
59+
if "classifiers" in lib["downloads"]:
60+
for cl in lib["downloads"]["classifiers"].values():
61+
url = cl["url"].replace("https://libraries.minecraft.net",
62+
"https://bmclapi2.bangbang93.com/maven")
63+
path = f'{mcdir}\\libraries\\{cl["path"]}'
64+
t = threading.Thread(target = download, args=(url ,path))
65+
t.start()
66+
url = dic["assetIndex"]["url"].replace("https://launchermeta.mojang.com",
67+
"https://bmclapi2.bangbang93.com")
68+
path = f"{mcdir}\\assets\\indexes\\{dic['assetIndex']['id']}.json"
69+
download(url, path)
70+
beautifyjson(path)
71+
assets_json = open(f"{mcdir}\\assets\\indexes\\{dic['assetIndex']['id']}.json", "r")
72+
assets_dic = loads(assets_json.read())
73+
assets_json.close()
74+
for lib in assets_dic["objects"]:
75+
objects_dir = assets_dic["objects"][lib]["hash"]
76+
t = threading.Thread(target = download, args = (f"https://bmclapi2.bangbang93.com/assets/{objects_dir[:2]}/{objects_dir}",
77+
f"{mcdir}\\assets\\objects\\{objects_dir[:2]}\\{objects_dir}"))
78+
t.start()
79+
80+
if __name__ == "__main__":
81+
Install("1.7.10", ".minecraft", "BMCLAPI")

Launcher/Launch.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +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")
117+
remove("run.bat")

0 commit comments

Comments
 (0)