-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathparse_osr.py
More file actions
210 lines (190 loc) · 3.73 KB
/
parse_osr.py
File metadata and controls
210 lines (190 loc) · 3.73 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import lzma
import struct
import sys
from textwrap import dedent
def parse_uleb128(f):
result = 0
shift = 0
while True:
byte = struct.unpack("<B", f.read(1))[0]
result |= (byte & 0x7F) << shift
if (byte & 0x80) == 0:
break
shift += 7
return result
def parse_string(f):
head = struct.unpack("<B", f.read(1))[0]
if head == 0x00:
return ""
elif head == 0x0B:
length = parse_uleb128(f)
return f.read(length).decode()
MODES = ["osu!", "Taiko", "Catch the Beat", "osu!mania"]
SHORTMODS = [
None,
"NF",
"EZ",
None,
"HD",
"HR",
"SD",
"DT",
"RX",
"HT",
"NC",
"FL",
"AO",
"SO",
"AP",
"PF",
"4K",
"5K",
"6K",
"7K",
"8K",
"FI",
"RD",
None,
"TP",
"9K",
"CO",
"1K",
"3K",
"2K",
]
MODS = [
"None",
"NoFail",
"Easy",
"NoVideo",
"Hidden",
"HardRock",
"SuddenDeath",
"DoubleTime",
"Relax",
"HalfTime",
"NightCore",
"Flashlight",
"Autoplay",
"SpunOut",
"Autopilot",
"Perfect",
"Key4",
"Key5",
"Key6",
"Key7",
"Key8",
"FadeIn",
"Random",
"Cinema",
"TargetPractice",
"Key9",
"Co-op",
"Key1",
"Key3",
"Key2",
]
def mods_to_str(n):
i = 1
s = set()
while n:
if n & 1:
s.add(MODS[i])
i += 1
n >>= 1
return ",".join(s)
def shortmods(n):
i = 1
s = ""
while n:
if n & 1:
s += SHORTMODS[i]
i += 1
n >>= 1
return s
def to_bin(n, size):
s = ""
while size:
s = s + "01"[n & 1]
n >>= 1
size -= 1
return s
def keys(n):
k1 = n & 5 == 5
k2 = n & 10 == 10
m1 = not k1 and n & 1 == 1
m2 = not k2 and n & 2 == 2
smoke = n & 16 == 16
return " ".join(
[
("K1" if k1 else " "),
("K2" if k2 else " "),
("M1" if m1 else " "),
("M2" if m2 else " "),
("SMOKE" if smoke else " "),
]
)
path = sys.argv[1]
with open(path, "rb") as f:
mode, version = struct.unpack("<BI", f.read(5))
beatmap_md5 = parse_string(f)
player_name = parse_string(f)
replay_md5 = parse_string(f)
n300, n100, n50, ngeki, nkatu, nmiss, score, combo, perfect, mods = struct.unpack(
"<HHHHHHIH?I", f.read(23)
)
life_bar = parse_string(f) # ms|life
timestamp, length = struct.unpack("<QI", f.read(12))
data = lzma.decompress(f.read(length)).decode()
last_w = 0
for record in data.split(","):
if record:
w, x, y, z = record.split("|")
w, z = int(w), int(z)
x, y = float(x), float(y)
print("%10d %10.4f %10.4f %s" % (w, x, y, keys(z)))
last_w = w
print(
dedent(
"""
Game mode : %s
Version : %d
Beatmap MD5 : %s
Player : %s
Replay MD5 : %s
300s : %d
100s : %d
50s : %d
Gekis : %d
Katus : %d
Misses : %d
Score : %d
Combo : %d
Perfect : %s
Mods : %s
Life : %s
Timestamp : %d
Length : %d
"""
)
% (
MODES[mode],
version,
beatmap_md5,
player_name,
replay_md5,
n300,
n100,
n50,
ngeki,
nkatu,
nmiss,
score,
combo,
perfect,
shortmods(mods),
life_bar,
timestamp,
length,
)
)