mirror of
https://github.com/SK8-ENGINE/skate-3-rust-engine.git
synced 2026-10-26 19:47:44 +00:00
Resolve VLT text array values before discarding the binary bank
This commit is contained in:
1 parent
1888e48a99
commit
051a73ed6a
2 files changed
+25
-1
No files matched your search
@@ -1,7 +1,7 @@
|
||||
"""Synthetic fixtures for the binary array layout; contains no game data."""
|
||||
import struct
|
||||
import unittest
|
||||
from .vlt import array_items
|
||||
from .vlt import array_items, array_text_items
|
||||
|
||||
|
||||
class ArrayLayoutTests(unittest.TestCase):
|
||||
@@ -32,6 +32,13 @@ class ArrayLayoutTests(unittest.TestCase):
|
||||
with self.assertRaises(ValueError):
|
||||
array_items(raw, 0, 4, 2)
|
||||
|
||||
def test_text_array_resolves_relocated_pointers(self):
|
||||
binary = bytes(8) + 'test\0caf\u00e9\0'.encode()
|
||||
self.assertEqual(array_text_items(binary, ['00000008', '0000000D', '00000000']),
|
||||
['test', 'caf\u00e9', ''])
|
||||
with self.assertRaises(ValueError):
|
||||
array_text_items(binary, ['0000FFFF'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -65,6 +65,20 @@ def array_items(data, pos, size, alignment):
|
||||
'alignment': boundary, 'items': items}
|
||||
|
||||
|
||||
def array_text_items(binary, items):
|
||||
values = []
|
||||
for raw in items:
|
||||
ptr, = unpack('I', bytes.fromhex(raw), 0)
|
||||
if not ptr:
|
||||
values.append('')
|
||||
continue
|
||||
end = binary.find(b'\0', ptr)
|
||||
if end < 0:
|
||||
raise ValueError(f'Unterminated VLT array text at {ptr:#x}')
|
||||
values.append(take(binary, ptr, end-ptr).decode('utf-8'))
|
||||
return values
|
||||
|
||||
|
||||
def chunks(data):
|
||||
at=0
|
||||
while at<len(data):
|
||||
@@ -140,6 +154,9 @@ def convert(schema_stem, collections_stem, names):
|
||||
# Keep the legacy data field unchanged for existing
|
||||
# gameplay consumers. New readers use the full array.
|
||||
out[name(fkey)]['array']=array_items(data,pos,n,alignment)
|
||||
if t=='EA::Reflection::Text':
|
||||
array=out[name(fkey)]['array']
|
||||
array['text_items']=array_text_items(cb,array['items'])
|
||||
for fk,f in fields.items():
|
||||
if f[4]&2 and layout: value(fk,cb,layout+f[1])
|
||||
entries=at+48+typeslen*8
|
||||
|
||||
Reference in new issue
Block a user