This repository has been archived by the owner on Dec 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path573-to-a20.py
222 lines (191 loc) · 9.96 KB
/
573-to-a20.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
214
215
216
217
218
219
220
221
222
from pathlib import Path
import subprocess
import sys
from shutil import copyfile, rmtree
import re
import json
import math
import lxml.etree as ET
from lxml.builder import E
required = [
'ffmpeg.exe',
'magick.exe',
Path('x86', 'XactBld.exe'),
'jacket_thumbnails_ja_8.arc',
'startup.arc',
]
missing = []
for file in required:
if not Path(file).exists():
missing.append(file)
if missing:
raise SystemExit("MISSING REQUIRED FILES:\n" + '\n'.join(map(str, missing)))
if not Path('packages').is_dir():
raise SystemExit("MISSING packages FOLDER FROM ddrextreme_omnimix.rar")
contents = Path('contents')
output = Path('output')
xact = Path('x86', 'XactBld.exe')
Path(contents, 'data', 'arc', 'jacket').mkdir(parents=True, exist_ok=True)
Path(contents, 'data', 'arc', 'thumbnail').mkdir(parents=True, exist_ok=True)
Path(contents, 'data', 'mdb_apx', 'ssq').mkdir(parents=True, exist_ok=True)
Path(contents, 'data', 'sound', 'win', 'dance').mkdir(parents=True, exist_ok=True)
subprocess.run([sys.executable, 'arcutils_extract.py', 'startup.arc'])
Path.rename(Path('data'), Path('startup'))
if Path('jacket_thumbnails_ja_8.arc').is_file():
region = 'ja'
elif Path('jacket_thumbnails_ua_8.arc').is_file():
region = 'ua'
subprocess.run([sys.executable, 'arcutils_extract.py', f'jacket_thumbnails_{region}_8.arc'])
existing = ['inst', 'name', 'netp', 'scal', 'selc', 'sele', 'stae', 'staf', 'titl']
xml_parser = ET.XMLParser(remove_blank_text=True)
mdb = ET.parse(str(Path('startup', 'gamedata', 'musicdb.xml')), xml_parser).getroot()
for music in mdb:
existing.append(music.find('basename').text)
skipped = []
for packages in Path('packages').glob('*'):
basename = packages.name
info = Path(packages, 'package.json')
with open(info) as package_json:
json_data = json.load(package_json)
# excess example for what must be accounted for when expanding to packages other than Extreme, as the formats vary:
if basename not in existing and json_data.get('_origin') in ('max', 'max2', 'extreme') and Path(packages, f'{basename}_th.png').exists() and Path(packages, f'{basename}_bk.png').exists() and Path(packages, 'song.mp3').exists() and Path(packages, 'preview.mp3').exists() and Path(packages, 'all.csq').exists():
thumb_input = Path(packages, f'{basename}_th.png')
jacket_input = Path(packages, f'{basename}_bk.png')
song_input = Path(packages, 'song.mp3')
prev_input = Path(packages, 'preview.mp3')
csq = Path(packages, 'all.csq')
Path(output, basename, 'Win').mkdir(parents=True, exist_ok=True)
Path(output, basename, 'data', 'jacket').mkdir(parents=True, exist_ok=True)
thumb_output = Path(output, basename, f'{basename}_tn.dds')
jacket_output = Path(output, basename, 'data', 'jacket', f'{basename}_jk.dds')
song_output = Path(output, basename, f'{basename}.wav')
prev_output = Path(output, basename, f'{basename}_s.wav')
ssq = Path(output, basename, f'{basename}.ssq')
xap = Path(output, basename, f'{basename}.xap')
subprocess.run(f'magick.exe convert {thumb_input} -background black -gravity center -resize 192x192! -extent 192x192 -flatten {thumb_output}')
subprocess.run(f'magick.exe convert {jacket_input} -background black -gravity center -resize 512x512! -extent 512x512 -flatten {jacket_output}')
if json_data.get('_origin') == 'extreme':
offset = '0.0507'
volume = '3'
else:
offset = '0.0235'
volume = '0'
subprocess.run(f'ffmpeg -ss {offset} -i {song_input} -af "apad=pad_dur=1" {song_output} -loglevel error')
subprocess.run(f'ffmpeg -i {prev_input} -af "volume={volume}dB" {prev_output} -loglevel error')
copyfile(csq, ssq)
# this will be required if functionality is expanded to other origins
if json_data.get('_origin') != "extreme":
chart = bytearray(open(ssq, "rb").read())
chunks = []
while len(chart) > 0:
chunk_size = int.from_bytes(chart[:4], 'little')
if chunk_size == 0:
chunks.append([])
chart = chart[4:]
else:
chunks.append(chart[4:chunk_size])
chart = chart[chunk_size:]
for idx, chunk in enumerate(chunks):
if not chunk:
continue
chunk_type = int.from_bytes(chunk[:2], 'little')
if chunk_type != 1:
continue
time = int.from_bytes(chunk[2:4], 'little')
count = int.from_bytes(chunk[4:6], 'little')
if time == 0x96:
continue
diff = 0x96 // time
if diff != 0x96 / time:
print("Is not a clean division", time, 0x96)
exit(1)
idx = 0x08 + count * 4
for x in range(0, count * 4, 4):
point = int.from_bytes(chunk[idx+x:idx+x+4], 'little') * diff
print("%08x" % point)
chunk[idx+x:idx+x+4] = int.to_bytes(point, 4, 'little')
chunk[2] = 0x96
chunk[3] = 0
chart = bytearray(b"".join([int.to_bytes(len(x) + (4 if x else 0), 4, 'little') + bytearray(x) for x in chunks]))
open(ssq, "wb").write(chart)
with open('dummy.xap', 'r') as f:
with open(xap, 'w') as o:
o.write(re.sub(r"DUMMY", basename, f.read()))
subprocess.run(f'{xact} {xap} {Path(output, basename)} /WIN32 /F')
title = json_data['title']
title_yomi = ''.join(title.split()).lower()
title_yomi = ''.join(e for e in title_yomi if e.isalnum())
artist = json_data.get('artist', 'OMNIMIX')
bpm_max = json_data['bpms'][0]
bpm_min = json_data['bpms'][1]
SPL = math.floor(json_data.get('difficulties', {}).get('single', {}).get('light', 0) * 1.5)
SPS = math.floor(json_data.get('difficulties', {}).get('single', {}).get('standard', 0) * 1.5)
SPH = math.floor(json_data.get('difficulties', {}).get('single', {}).get('heavy', 0) * 1.5)
SPO = math.floor(json_data.get('difficulties', {}).get('single', {}).get('challenge', 0) * 1.5)
DPL = math.floor(json_data.get('difficulties', {}).get('double', {}).get('light', 0) * 1.5)
DPS = math.floor(json_data.get('difficulties', {}).get('double', {}).get('standard', 0) * 1.5)
DPH = math.floor(json_data.get('difficulties', {}).get('double', {}).get('heavy', 0) * 1.5)
DPO = math.floor(json_data.get('difficulties', {}).get('double', {}).get('challenge', 0) * 1.5)
diff_level = [0, SPL, SPS, SPH, SPO, 0, DPL, DPS, DPH, DPO]
mcode = json_data['memory_card_link_id']
bgstage = 3
if json_data.get('_origin') == 'max':
series = 6
elif json_data.get('_origin') == 'max2':
series = 7
elif json_data.get('_origin') == 'extreme':
series = 8
diff_level_str = " ".join([str(d) for d in diff_level])
print(' <music>')
print(f' <mcode __type="u32">{mcode}</mcode>')
print(f' <basename>{basename}</basename>')
print(f' <title>{title}</title>')
print(f' <title_yomi>{title_yomi}</title_yomi>')
print(f' <artist>{artist}</artist>')
if bpm_max == bpm_min:
print(f' <bpmmax __type="u16">{bpm_max}</bpmmax>')
else:
print(f' <bpmmin __type="u16">{bpm_min}</bpmmin>')
print(f' <bpmmax __type="u16">{bpm_max}</bpmmax>')
print(f' <series __type="u8">{series}</series>')
print(f' <bgstage __type="u16">{bgstage}</bgstage>')
print(f' <diffLv __type="u8" __count="10">{diff_level}</diffLv>')
print(' </music>')
mdb_entry = E.music(
E.mcode(str(mcode), __type="u32"),
E.basename(str(basename), __type="str"),
E.title(str(title), __type="str"),
E.title_yomi(str(title_yomi), __type="str"),
E.artist(str(artist), __type="str"),
E.bpmmax(str(bpm_max), __type="u16"),
E.series(str(series), __type="u8"),
E.bgstage(str(bgstage), __type="u16"),
E.diffLv(diff_level_str, __type="u8", __count=str(len(diff_level))),
)
if bpm_max != bpm_min:
mdb_entry.append(E.bpmmin(str(bpm_min), __type="u16"))
mdb.append(mdb_entry)
print()
copyfile(ssq, Path(contents, 'data', 'mdb_apx', 'ssq', f'{basename}.ssq'))
copyfile(Path(output, basename, f'{basename}.xsb'), Path(contents, 'data', 'sound', 'win', 'dance', f'{basename}.xsb'))
copyfile(Path(output, basename, f'{basename}.xwb'), Path(contents, 'data', 'sound', 'win', 'dance', f'{basename}.xwb'))
subprocess.run([sys.executable, 'arcutils_create.py', f'{basename}_jk.arc', '--directory', f'{Path(output, basename, "data")}'])
Path(f'{basename}_jk.arc').rename(Path(contents, 'data', 'arc', 'jacket', f'{basename}_jk.arc'))
copyfile(thumb_output, Path('data', 'jacket', 'thumbnail', f'{basename}_tn.dds'))
else:
skipped.append(basename)
subprocess.run([sys.executable, 'arcutils_create.py', f'jacket_thumbnails_{region}_8.arc_omni'])
Path(f'jacket_thumbnails_{region}_8.arc_omni').rename(Path(contents, 'data', 'arc', 'thumbnail', f'jacket_thumbnails_{region}_8.arc'))
rmtree(Path('data'))
rmtree(output)
print('Already exist in the mdb:')
print(len(skipped))
print(skipped)
# sort mdb by mcode
mdb[:] = sorted(mdb, key=lambda x:int(x.find('mcode').text))
open("omni_musicdb.xml", "wb").write(ET.tostring(mdb, pretty_print=True, method='xml', encoding='utf-8', xml_declaration=True))
Path.rename(Path('startup'), Path('data'))
copyfile("omni_musicdb.xml", Path('data', 'gamedata', 'musicdb.xml'))
subprocess.run([sys.executable, 'arcutils_create.py', 'startup.arc_omni'])
Path('startup.arc_omni').rename(Path(contents, 'data', 'arc', 'startup.arc'))
rmtree(Path('data'))