-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconverter.py
More file actions
40 lines (33 loc) · 1.28 KB
/
converter.py
File metadata and controls
40 lines (33 loc) · 1.28 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
import os
from glob import glob
offset = 0x02 # Change it to the number you want - for now KH1 uses 01 as offset
def rename_bgm():
current_dir = os.path.dirname(__file__) or '.'
files = glob(f"{current_dir}/*.bgm")
for file in files:
with open(file, 'rb') as f:
data = bytearray(f.read())
data[0x05] = offset
data[0x07] = offset
old_filename = os.path.basename(file)
old_number = old_filename[5:8]
new_number = offset * 0x100 + data[0x04]
new_file = str(file).replace(old_number, str(new_number).rjust(3, '0'))
with open(f"converted/{os.path.basename(new_file)}", 'wb') as f:
f.write(data)
def rename_wd():
current_dir = os.path.dirname(__file__) or '.'
files = glob(f"{current_dir}/*.wd")
for file in files:
with open(file, 'rb') as f:
data = bytearray(f.read())
data[0x03] = offset
old_filename = os.path.basename(file)
old_number = old_filename[4:8]
new_number = offset * 0x100 + data[0x02]
new_file = str(file).replace(old_number, str(new_number).rjust(4, '0'))
with open(f"converted/{os.path.basename(new_file)}", 'wb') as f:
f.write(data)
if __name__ == '__main__':
rename_bgm()
rename_wd()