-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrender_osr.py
213 lines (186 loc) · 4.31 KB
/
render_osr.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
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
211
212
213
import lzma
import struct
import sys
from collections import deque
from textwrap import dedent
import pygame
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (64, 64, 64)
BLUE = (0, 0, 255)
WHITE = (255, 255, 255)
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 = ["", "NF", "EZ", "", "HD", "HR", "SD", "DT", "RX", "HT", "NC", "FL"]
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 = r"""C:\Users\notan\AppData\Local\osu!\Replays\Cookiezi - xi - Blue Zenith [FOUR DIMENSIONS] (2016-01-02) Osu.osr"""
out = deque()
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))
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,
)
)
data = lzma.decompress(f.read(length)).decode()
t = 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)
if w >= 0:
t += w
out.append((t, int(x), int(y)))
pygame.init()
pygame.mixer.init(44100)
pygame.mixer.music.load(
r"""C:\Users\notan\AppData\Local\osu!\Songs\292301 xi - Blue Zenith\zenith.mp3"""
)
pygame.mixer.music.play()
screen = pygame.display.set_mode((512, 384))
clock = pygame.time.Clock()
while pygame.mixer.music.get_busy():
while out and out[0][0] < pygame.mixer.music.get_pos():
out.popleft()
screen.fill(BLACK)
if out:
t, x, y = out[0]
screen.fill(WHITE, (x, y, 10, 10))
sys.stdout.write("%3d %3d\r" % (x, y))
pygame.display.flip()
clock.tick(60)