Skip to content

Commit 2c9341f

Browse files
committed
rough analyzer
1 parent beef3e0 commit 2c9341f

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

Teddy_Ruxpin/ruxalyzer.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/local/bin/python3
2+
3+
import struct
4+
5+
FILENAME = "Intro.bin"
6+
7+
storyfile = open(FILENAME, "rb")
8+
9+
SNXROM = {}
10+
11+
# check for magic bytes
12+
SNXROM['SNXROM'] = storyfile.read(12).decode('utf-16')
13+
if SNXROM['SNXROM'] != 'SNXROM':
14+
raise RuntimeError("Didn't find SNXROM magic bytes")
15+
16+
print(SNXROM['SNXROM'], "found")
17+
18+
# read and toss next 28 bytes all 0xFF
19+
storyfile.read(28)
20+
# find 0x400 bytes
21+
if 0x400 != struct.unpack('I', storyfile.read(4))[0]:
22+
raise RuntimeError("Didn't find 0x400 magic bytes")
23+
24+
SNXROM['assetTableLengthWords'] = struct.unpack('I', storyfile.read(4))[0]
25+
print("Asset table length (words):", SNXROM['assetTableLengthWords'], "& bytes:", SNXROM['assetTableLengthWords'] * 4)
26+
27+
# read and toss next 464 bytes all 0xFF
28+
storyfile.read(464)
29+
30+
# NOTE: the pointers are in byte offsets not words!
31+
print("Looking for asset table pointers at", hex(storyfile.tell()))
32+
assetTablePointers = [0] * SNXROM['assetTableLengthWords']
33+
for i in range(SNXROM['assetTableLengthWords']):
34+
assetTablePointers[i] = struct.unpack('I', storyfile.read(4))[0]
35+
print("Asset table pointers:", [hex(i) for i in assetTablePointers])
36+
37+
SNXROM['audioOffset'] = assetTablePointers[-1]
38+
39+
# verify audio offset
40+
print("Looking for audio at", hex(SNXROM['audioOffset']))
41+
storyfile.seek(SNXROM['audioOffset'])
42+
if "AU" != storyfile.read(2).decode('utf-8'):
43+
raise RuntimeError("Didn't find AU at beginning of audio")
44+
print("Found beginning of audio")
45+
"""
46+
SNXROM['metaOffset'] = struct.unpack('I', storyfile.read(4))[0]
47+
SNXROM['leftEyeOffset'] = struct.unpack('I', storyfile.read(4))[0]
48+
SNXROM['rightEyeOffset'] = struct.unpack('I', storyfile.read(4))[0]
49+
50+
51+
print("Metadata offset: %d bytes, address 0x%0X" % (SNXROM['metaOffset'], SNXROM['metaOffset']))
52+
print("Left Eye offset: %d bytes, address 0x%0X" % (SNXROM['leftEyeOffset'], SNXROM['leftEyeOffset']))
53+
print("Right Eye offset: %d bytes, address 0x%0X" % (SNXROM['rightEyeOffset'], SNXROM['rightEyeOffset']))
54+
print("Audio data offset: %d bytes, address 0x%0X" % (SNXROM['audioOffset'], SNXROM['audioOffset']))
55+
56+
print(storyfile.tell())
57+
58+
# Go to the metadata table
59+
storyfile.seek(SNXROM['metaOffset'])
60+
61+
if 0x0000 != struct.unpack('h', storyfile.read(2))[0]:
62+
raise RuntimeError("Didn't find 0x0000 magic bytes")
63+
SNXROM['storyId'] = struct.unpack('h', storyfile.read(2))[0]
64+
SNXROM['numberOfEyeAnimations'] = struct.unpack('h', storyfile.read(2))[0]
65+
SNXROM['numberOfEyeBitmaps'] = struct.unpack('h', storyfile.read(2))[0]
66+
SNXROM['numberOfVideoSequences'] = struct.unpack('h', storyfile.read(2))[0]
67+
SNXROM['numberOfAudioBlocks'] = struct.unpack('h', storyfile.read(2))[0]
68+
print("Story ID: ", SNXROM['storyId'])
69+
print("Eye animations:", SNXROM['numberOfEyeAnimations'])
70+
print("Eye bitmaps:", SNXROM['numberOfEyeBitmaps'])
71+
print("Video seqs:", SNXROM['numberOfVideoSequences'])
72+
print("Audio blocks:", SNXROM['numberOfAudioBlocks'])
73+
74+
SNXROM['ROMfilesize'] = struct.unpack('i', storyfile.read(4))[0]
75+
print(SNXROM['ROMfilesize'])
76+
"""

0 commit comments

Comments
 (0)