-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbin_to_vpk.py
40 lines (39 loc) · 1.69 KB
/
bin_to_vpk.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
'''Split Game Boy Advance e-Reader binaries into their component VPK files.'''
import os
from bitstring import BitArray
# in Animal Crossing mode, VPKs will be split with filenames like this:
# originalfilename_0.header
# originalfilename_1_GBA.vpk
# originalfilename_2_GC.vpk
CARD_TYPE = 'Animal Crossing'
# CARD_TYPE could be expanded to other cards later;
# only Animal Crossing is currently supported.
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) + '/cards'
IN_DIR = BASE_DIR + '/bin/'
OUT_DIR = BASE_DIR + '/vpk/'
for file in os.listdir(IN_DIR):
if file.endswith(".bin"):
full_path = IN_DIR + file
# https://pythonhosted.org/bitstring/creation.html#from-a-file
a = BitArray(filename=full_path)
# vpk0 = 76 70 6B 30. vpk0 is the header for each chunk of data we want
for chunk_num, chunk in enumerate(
a.split('0x76706B30', bytealigned=True)):
card_extension = '.vpk'
note = '_'
# skip chunk 0 (when batch processing *.vpk files).
# it's a header rather than a compressed VPK chunk
if chunk_num == 0:
card_extension = '.header'
if CARD_TYPE == 'Animal Crossing':
if chunk_num == 1:
# hunch, bigger because of graphics data
note = note + "GBA"
if chunk_num == 2:
# almost certain, I've sent stuff to GC from this chunk
note = note + "GC"
if note == '_':
note = ''
out_name = OUT_DIR + file[:-4] + '_' + \
str(chunk_num) + note + card_extension
open(out_name, 'wb').write(chunk.tobytes())