Skip to content

Commit 8ff5b9c

Browse files
committed
更改JavaMinecraftArgumentsBuilder构造方法
1 parent 4283437 commit 8ff5b9c

File tree

8 files changed

+122
-82
lines changed

8 files changed

+122
-82
lines changed
2.46 KB
Binary file not shown.
Binary file not shown.
Lines changed: 96 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,157 @@
11
from os.path import exists
22
from json import loads
3+
from modules.models.launch.game_core import GameCore
4+
from modules.models.launch.launch_config import LaunchConfig
35
import zipfile
46

57

68
class JavaMinecraftArgumentsBuilder():
7-
def __init__(self, mcDir: str, version: str, javawPath: str, maxMem: str, userName: str, width: str, height: str):
8-
self.McDir = mcDir
9-
self.Version = version
10-
self.JavawPath = javawPath
11-
self.MaxMem = maxMem
12-
self.UserName = userName
13-
self.Width = width
14-
self.Height = height
9+
# new __init__
10+
def __init__(self, game_core: GameCore, launch_config: LaunchConfig):
11+
self.path = game_core.root
12+
self.version = game_core.id
13+
self.javawpath = launch_config.jvm_config[0]
14+
self.max_memory = launch_config.jvm_config[1]
15+
self.user_name = launch_config.account
16+
self.width = launch_config.game_window_config[0]
17+
self.height = launch_config.game_window_config[1]
1518

16-
def unpress(self, filename: str, path: str):
17-
Zip = zipfile.ZipFile(filename)
18-
for z in Zip.namelist():
19-
Zip.extract(z, path)
20-
Zip.close()
19+
# old __init__,暂时先不改
20+
def __init__(self, path: str, version: str, javaw_path: str, max_memory: str, user_name: str, width: str, height: str):
21+
self.path = path
22+
self.version = version
23+
self.javaw_path = javaw_path
24+
self.max_memory = max_memory
25+
self.user_name = user_name
26+
self.width = width
27+
self.height = height
2128

22-
def isMyversion(self, version: str, mcdir: str):
23-
if (exists(f"{mcdir}\\versions\\{version}\\{version}.json")):
29+
def unpress(self, name: str, path: str):
30+
zip = zipfile.ZipFile(name)
31+
for z in zip.namelist():
32+
zip.extract(z, path)
33+
zip.close()
34+
35+
def is_my_version(self, version: str, path: str):
36+
if (exists(f"{path}\\versions\\{version}\\{version}.json")):
2437
return True
2538
else:
2639
return False
2740

2841
def build(self) -> str:
29-
commandLine = str("")
42+
command_line = str("")
3043
JVM = str("")
31-
classPath = str("")
32-
mcArgs = str("")
44+
class_path = str("")
45+
mc_args = str("")
3346

34-
if ((not self.JavawPath == "")
35-
and (not self.Version == "")
36-
and (not self.MaxMem == "")
37-
and (not self.UserName == "")
38-
and (not self.McDir == "")):
39-
if (self.isMyversion(self.Version, self.McDir)):
47+
if ((not self.javaw_path == "")
48+
and (not self.version == "")
49+
and (not self.max_memory == "")
50+
and (not self.user_name == "")
51+
and (not self.path == "")):
52+
if (self.is_my_version(self.version, self.path)):
4053
json = open(
41-
f"{self.McDir}\\versions\\{self.Version}\\{self.Version}.json", "r")
54+
f"{self.path}\\versions\\{self.version}\\{self.version}.json", "r")
4255
dic = loads(json.read())
4356
json.close()
4457
for lib in dic["libraries"]:
4558
if "classifiers" in lib['downloads']:
4659
for native in lib['downloads']:
4760
if native == "artifact":
48-
path = f"{self.McDir}\\versions\\{self.Version}\\natives"
49-
filePath = f"{self.McDir}\\libraries\\{lib['downloads'][native]['path']}"
61+
path = f"{self.path}\\versions\\{self.version}\\natives"
62+
filePath = f"{self.path}\\libraries\\{lib['downloads'][native]['path']}"
5063
try:
5164
self.unpress(filePath, path)
5265
except:
5366
pass
5467
elif native == 'classifiers':
5568
for n in lib['downloads'][native].values():
56-
path = f"{self.McDir}\\versions\\{self.Version}\\natives"
57-
filePath = f'{self.McDir}\\libraries\\{n["path"]}'
69+
path = f"{self.path}\\versions\\{self.version}\\natives"
70+
filePath = f'{self.path}\\libraries\\{n["path"]}'
5871
try:
5972
self.unpress(filePath, path)
6073
except:
6174
pass
62-
JVM = '"' + self.JavawPath + '" -XX:+UseG1GC -XX:-UseAdaptiveSizePolicy' +\
75+
JVM = '"' + self.javaw_path + '" -XX:+UseG1GC -XX:-UseAdaptiveSizePolicy' +\
6376
' -XX:-OmitStackTraceInFastThrow -Dfml.ignoreInvalidMinecraftCertificates=True ' +\
6477
'-Dfml.ignorePatchDiscrepancies=True -Dlog4j2.formatMsgNoLookups=true ' +\
6578
'-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump ' +\
6679
'-Dos.name="Windows 10" -Dos.version=10.0 -Djava.library.path="' +\
67-
self.McDir + "\\versions\\" + self.Version + "\\" + "natives" +\
80+
self.path + "\\versions\\" + self.version + "\\" + "natives" +\
6881
'" -Dminecraft.launcher.brand=launcher ' +\
6982
'-Dminecraft.launcher.version=1.0.0 -cp'
70-
classPath += '"'
83+
class_path += '"'
7184
for lib in dic["libraries"]:
7285
if not 'classifiers' in lib["downloads"]:
73-
normal = f'{self.McDir}\\libraries\\{lib["downloads"]["artifact"]["path"]}'
74-
classPath += normal + ";"
75-
classPath = f'{classPath}{self.McDir}\\versions\\{self.Version}\\{self.Version}.jar"'
76-
JVM = f"{JVM} {classPath} -Xmx{self.MaxMem} -Xmn256m -Dlog4j.formatMsgNoLookups=true"
86+
normal = f'{self.path}\\libraries\\{lib["downloads"]["artifact"]["path"]}'
87+
class_path += normal + ";"
88+
class_path = f'{class_path}{self.path}\\versions\\{self.version}\\{self.version}.jar"'
89+
JVM = f"{JVM} {class_path} -Xmx{self.max_memory} -Xmn256m -Dlog4j.formatMsgNoLookups=true"
7790

78-
mcArgs += dic["mainClass"] + " "
91+
mc_args += dic["mainClass"] + " "
7992
if "minecraftArguments" in dic:
80-
mcArgs += dic["minecraftArguments"]
81-
mcArgs = mcArgs.replace(
82-
"${auth_player_name}", self.UserName) # 玩家名称
83-
mcArgs = mcArgs.replace(
84-
"${version_name}", self.Version) # 版本名称
85-
mcArgs = mcArgs.replace(
86-
"${game_directory}", self.McDir) # mc路径
87-
mcArgs = mcArgs.replace(
88-
"${assets_root}", self.McDir + "\\assets") # 资源文件路径
89-
mcArgs = mcArgs.replace(
93+
mc_args += dic["minecraftArguments"]
94+
mc_args = mc_args.replace(
95+
"${auth_player_name}", self.user_name) # 玩家名称
96+
mc_args = mc_args.replace(
97+
"${version_name}", self.version) # 版本名称
98+
mc_args = mc_args.replace(
99+
"${game_directory}", self.path) # mc路径
100+
mc_args = mc_args.replace(
101+
"${assets_root}", self.path + "\\assets") # 资源文件路径
102+
mc_args = mc_args.replace(
90103
"${assets_index_name}", dic["assetIndex"]["id"]) # 资源索引文件名称
91-
mcArgs = mcArgs.replace(
104+
mc_args = mc_args.replace(
92105
"${auth_uuid}", "{}") # 由于没有写微软登录,所以uuid为空的
93-
mcArgs = mcArgs.replace(
106+
mc_args = mc_args.replace(
94107
"${auth_access_token}", "{}") # 同上
95-
mcArgs = mcArgs.replace("${clientid}", self.Version) # 客户端id
96-
mcArgs = mcArgs.replace("${auth_xuid}", "{}") # 离线登录,不填
97-
mcArgs = mcArgs.replace(
108+
mc_args = mc_args.replace(
109+
"${clientid}", self.version) # 客户端id
110+
mc_args = mc_args.replace("${auth_xuid}", "{}") # 离线登录,不填
111+
mc_args = mc_args.replace(
98112
"${user_type}", "Legacy") # 用户类型,离线模式是Legacy
99-
mcArgs = mcArgs.replace(
113+
mc_args = mc_args.replace(
100114
"${version_type}", dic["type"]) # 版本类型
101-
mcArgs = mcArgs.replace("${user_properties}", "{}")
102-
mcArgs += f"--width {self.Width}"
103-
mcArgs += f" --height {self.Height}"
115+
mc_args = mc_args.replace("${user_properties}", "{}")
116+
mc_args += f"--width {self.width}"
117+
mc_args += f" --height {self.height}"
104118
else:
105119
for arg in dic["arguments"]["game"]:
106120
if isinstance(arg, str):
107-
mcArgs += arg + " "
121+
mc_args += arg + " "
108122
elif isinstance(arg, dict):
109123
if isinstance(arg["value"], list):
110124
for a in arg["value"]:
111-
mcArgs += a + " "
125+
mc_args += a + " "
112126
elif isinstance(arg["value"], str):
113-
mcArgs += arg["value"] + " "
127+
mc_args += arg["value"] + " "
114128

115-
mcArgs = mcArgs.replace(
116-
"${auth_player_name}", self.UserName) # 玩家名称
117-
mcArgs = mcArgs.replace(
118-
"${version_name}", self.Version) # 版本名称
119-
mcArgs = mcArgs.replace(
120-
"${game_directory}", self.McDir) # mc路径
121-
mcArgs = mcArgs.replace(
122-
"${assets_root}", self.McDir + "\\assets") # 资源文件路径
123-
mcArgs = mcArgs.replace(
129+
mc_args = mc_args.replace(
130+
"${auth_player_name}", self.user_name) # 玩家名称
131+
mc_args = mc_args.replace(
132+
"${version_name}", self.version) # 版本名称
133+
mc_args = mc_args.replace(
134+
"${game_directory}", self.path) # mc路径
135+
mc_args = mc_args.replace(
136+
"${assets_root}", self.path + "\\assets") # 资源文件路径
137+
mc_args = mc_args.replace(
124138
"${assets_index_name}", dic["assetIndex"]["id"]) # 资源索引文件名称
125-
mcArgs = mcArgs.replace(
139+
mc_args = mc_args.replace(
126140
"${auth_uuid}", "{}") # 由于没有写微软登录,所以uuid为空的
127-
mcArgs = mcArgs.replace(
141+
mc_args = mc_args.replace(
128142
"${auth_access_token}", "{}") # 同上
129-
mcArgs = mcArgs.replace("${clientid}", self.Version) # 客户端id
130-
mcArgs = mcArgs.replace("${auth_xuid}", "{}") # 离线登录,不填
131-
mcArgs = mcArgs.replace(
143+
mc_args = mc_args.replace(
144+
"${clientid}", self.version) # 客户端id
145+
mc_args = mc_args.replace("${auth_xuid}", "{}") # 离线登录,不填
146+
mc_args = mc_args.replace(
132147
"${user_type}", "Legacy") # 用户类型,离线模式是Legacy
133-
mcArgs = mcArgs.replace(
148+
mc_args = mc_args.replace(
134149
"${version_type}", dic["type"]) # 版本类型
135-
mcArgs = mcArgs.replace(
136-
"${resolution_width}", self.Width) # 窗口宽度
137-
mcArgs = mcArgs.replace(
138-
"${resolution_height}", self.Height) # 窗口高度
139-
mcArgs = mcArgs.replace("-demo ", "") # 去掉-demo参数,退出试玩版
150+
mc_args = mc_args.replace(
151+
"${resolution_width}", self.width) # 窗口宽度
152+
mc_args = mc_args.replace(
153+
"${resolution_height}", self.height) # 窗口高度
154+
mc_args = mc_args.replace("-demo ", "") # 去掉-demo参数,退出试玩版
140155

141-
commandLine = JVM + " " + mcArgs
142-
return commandLine
156+
command_line = JVM + " " + mc_args
157+
return command_line
755 Bytes
Binary file not shown.

modules/models/launch/game_core.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#咕咕ing
2+
3+
class GameCore():
4+
id = str()
5+
root = str()
6+
7+

modules/parser/game_core_parser.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#咕咕ing
2+
3+
class GameCoreParser():
4+
def __init__(self, root: str, json_entities):
5+
self.root = root
6+
self.json_entities = json_entities
7+
8+
9+
614 Bytes
Binary file not shown.
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
from modules.models.launch.game_core import GameCore
2+
3+
14
class GameCoreToolkit():
25
def __init__(self, path: str = ".minecraft"):
3-
self.root = path
6+
self.root = path
7+
8+
def get_game_core(id: str) -> GameCore:
9+
pass # 咕咕ing,先放个pass占位
10+
11+
def get_geme_cores() -> list[GameCore]:
12+
pass # 同上

0 commit comments

Comments
 (0)