68 lines
3.2 KiB
Python
68 lines
3.2 KiB
Python
"""Original bank identity/RIFF regression checks, including the bars sounds."""
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import struct
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]/'tools/extractors'))
|
|
from omt import Database, FormatError
|
|
from sound_bank import export_sound_bank
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
ORIGINAL = ROOT.parent/'Original'
|
|
|
|
|
|
class SoundBankTests(unittest.TestCase):
|
|
def test_exact_original_identities_and_riff_bytes(self):
|
|
source = ORIGINAL/'omt/soundeffects.omt'
|
|
before = hashlib.sha256(source.read_bytes()).hexdigest()
|
|
database = Database(source)
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
output = Path(directory)
|
|
manifest = export_sound_bank(ORIGINAL, output)
|
|
self.assertEqual(len(manifest['resources']), 251)
|
|
entries = {e.id: e for e in database.entries if e.type == 'Wave'}
|
|
for item in manifest['resources']:
|
|
payload = database.payload(entries[item['id']])
|
|
start = payload.index(b'RIFF')
|
|
size = struct.unpack_from('<I', payload, start+4)[0]+8
|
|
decoded = (output/item['path']).read_bytes()
|
|
self.assertEqual(decoded, payload[start:start+size])
|
|
self.assertEqual(hashlib.sha256(decoded).hexdigest(), item['sha256'])
|
|
by_id = {r['id']: r for r in manifest['resources']}
|
|
self.assertEqual(by_id[58]['name'], 'door closing')
|
|
self.assertEqual(by_id[59]['name'], 'Door opening loop')
|
|
self.assertEqual(by_id[230]['name'], 'winning prize2')
|
|
self.assertEqual(json.loads((output/'effects.json').read_text()), manifest)
|
|
self.assertEqual(hashlib.sha256(source.read_bytes()).hexdigest(), before)
|
|
|
|
def test_original_output_boundary_and_executable_bank_reference(self):
|
|
with self.assertRaises(FormatError):
|
|
export_sound_bank(ORIGINAL, ORIGINAL/'not-created')
|
|
exe = (ORIGINAL/'Neutron.exe').read_bytes()
|
|
self.assertEqual(exe[0x23642:0x23647], bytes.fromhex('68 8c e0 4e 00'))
|
|
self.assertEqual(exe[0xee08c:0xee09d], b'SoundEffects.omt\0')
|
|
self.assertEqual(exe[0x589de:0x589e3], bytes.fromhex('e8 5d 4c 02 00'))
|
|
self.assertEqual(exe[0x7d3bc:0x7d3c2], bytes.fromhex('56 68 65 76 61 57'))
|
|
|
|
def test_cutscene_stops_music_and_default_restarts_original_handle(self):
|
|
exe = (ORIGINAL/'Neutron.exe').read_bytes()
|
|
for offset, expected in [
|
|
(0x16776, 'a1 04 60 69 00'), # CAM current music database.
|
|
(0x16790, '8b 90 38 0a 00 00'), # Jimmy music handle.
|
|
(0x16796, '53 52 e8 03 70 06 00'), # Stop(handle,0).
|
|
(0x167e1, '89 1d 04 60 69 00'), # Clear current music DB.
|
|
(0x47d5c, '3b c6 75 3f'), # DEFAULT skips restart when Jimmy owns control.
|
|
(0x47f20, 'a3 04 60 69 00'), # Restore selected music DB.
|
|
(0x47f37, '53 6a 00 6a ff 50 e8 ce 57 03 00'), # Wave0,loop.
|
|
]:
|
|
raw = bytes.fromhex(expected)
|
|
self.assertEqual(exe[offset:offset+len(raw)], raw, hex(offset+0x400000))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|