-
Notifications
You must be signed in to change notification settings - Fork 1
/
gameInformation.py
156 lines (131 loc) · 4.52 KB
/
gameInformation.py
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
from UnityPy import Environment
from tqdm import tqdm
import os
import zipfile
import requests
import struct
import sys
# download gameinformation from
filename = sys.argv[1].split("/")[-1]
class ByteReader:
def __init__(self, data: bytes):
self.data = data
self.position = 0
self.d = {int: self.readInt, float: self.readFloat, str: self.readString}
def readInt(self):
self.position += 4
return self.data[self.position - 4] ^ self.data[self.position - 3] << 8
def readFloat(self):
self.position += 4
return struct.unpack("f", self.data[self.position - 4 : self.position])[0]
def readString(self):
length = self.readInt()
result = self.data[self.position : self.position + length].decode()
self.position += length // 4 * 4
if length % 4 != 0:
self.position += 4
return result
def skipString(self):
length = self.readInt()
self.position += length // 4 * 4
if length % 4 != 0:
self.position += 4
def readSchema(self, schema: dict):
result = []
for x in range(self.readInt()):
item = {}
for key, value in schema.items():
if value in (int, str, float):
item[key] = self.d[value]()
elif type(value) == list:
l = []
for i in range(self.readInt()):
l.append(self.d[value[0]]())
item[key] = l
elif type(value) == tuple:
for t in value:
self.d[t]()
elif type(value) == dict:
item[key] = self.readSchema(value)
else:
raise Exception("无")
result.append(item)
return result
def run(path):
env = Environment()
with zipfile.ZipFile(path) as apk:
with apk.open("assets/bin/Data/globalgamemanagers.assets") as f:
env.load_file(f.read(), name="assets/bin/Data/globalgamemanagers.assets")
with apk.open("assets/bin/Data/level0") as f:
env.load_file(f.read())
for obj in env.objects:
if obj.type.name != "MonoBehaviour":
continue
data = obj.read()
if data.m_Script.get_obj().read().name == "GameInformation":
information = data.raw_data.tobytes()
position = information.index(b"\x16\x00\x00\x00Glaciaxion.SunsetRay.0\x00\x00\n")
reader = ByteReader(information[position - 4 :])
information_schema = {
"songId": str,
"songKey": str,
"songName": str,
"songTitle": str,
"difficulty": [float],
"illustrator": str,
"charter": [str],
"composer": str,
"levels": [str],
"previewTime": float,
"unlockList": {"unlockType": int, "unlockInfo": [str]},
"n": [int],
}
difficulty = []
table = []
for i in range(3):
for item in reader.readSchema(information_schema):
item["songId"] = item["songId"][:-2]
if len(item["levels"]) == 5:
item["difficulty"].pop()
item["charter"].pop()
if item["difficulty"][-1] == 0:
item["difficulty"].pop()
item["charter"].pop()
for i in range(len(item["difficulty"])):
item["difficulty"][i] = round(item["difficulty"][i], 1)
difficulty.append([item["songId"]] + item["difficulty"])
table.append(
(
item["songId"],
item["songName"],
item["composer"],
item["illustrator"],
*item["charter"],
)
)
print(difficulty)
print(table)
with open("difficulty.csv", "w", encoding="utf8") as f:
for item in difficulty:
f.write(",".join(map(str, item)))
f.write("\n")
with open("info.csv", "w", encoding="utf8") as f:
for item in table:
f.write("\\".join(item))
f.write("\n")
if __name__ == "__main__":
response = requests.get(sys.argv[1], stream=True)
# get length.
total = int(response.headers.get("content-length", 0))
with open(filename, "wb") as file, tqdm(
desc=filename,
total=total,
unit="iB",
unit_scale=True,
unit_divisor=1024,
) as bar:
for data in response.iter_content(chunk_size=1024):
size = file.write(data)
bar.update(size)
run(filename)
os.remove(filename)