Added parsing support for older lvl format.

This commit is contained in:
lcdr 2016-11-26 14:10:59 +01:00
parent b2946a5c28
commit 60dbb0178d

View File

@ -80,7 +80,9 @@ class LUZViewer(viewer.Viewer):
scene_name = stream.read(str, char_size=1, length_type=c_ubyte) scene_name = stream.read(str, char_size=1, length_type=c_ubyte)
scene = self.tree.insert(scenes, END, text="Scene", values=(filename, scene_id, scene_name)) scene = self.tree.insert(scenes, END, text="Scene", values=(filename, scene_id, scene_name))
assert stream.read(bytes, length=3) assert stream.read(bytes, length=3)
with open(os.path.join(os.path.dirname(luz_path), filename), "rb") as lvl: lvl_path = os.path.join(os.path.dirname(luz_path), filename)
if os.path.exists(lvl_path):
with open(lvl_path, "rb") as lvl:
print("Loading lvl", filename) print("Loading lvl", filename)
try: try:
self.parse_lvl(BitStream(lvl.read()), scene) self.parse_lvl(BitStream(lvl.read()), scene)
@ -208,22 +210,42 @@ class LUZViewer(viewer.Viewer):
self.tree.insert(waypoint, END, text="Config", values=(config_name, config_type_and_value)) self.tree.insert(waypoint, END, text="Config", values=(config_name, config_type_and_value))
def parse_lvl(self, stream, scene): def parse_lvl(self, stream, scene):
if stream[0:4] == b"CHNK":
# newer lvl file structure
# chunk based
while not stream.all_read(): while not stream.all_read():
assert stream._read_offset//8 % 16 == 0 # seems everything is aligned like this? assert stream._read_offset//8 % 16 == 0 # seems everything is aligned like this?
start_pos = stream._read_offset//8 start_pos = stream._read_offset//8
assert stream.read(bytes, length=4) == b"CHNK" assert stream.read(bytes, length=4) == b"CHNK"
chunktype = stream.read(c_uint) chunk_type = stream.read(c_uint)
assert stream.read(c_ushort) == 1 assert stream.read(c_ushort) == 1
assert stream.read(c_ushort) in (1, 2) assert stream.read(c_ushort) in (1, 2)
chunk_length = stream.read(c_uint) chunk_length = stream.read(c_uint)
data_pos = stream.read(c_uint) data_pos = stream.read(c_uint)
stream._read_offset = data_pos * 8 stream._read_offset = data_pos * 8
assert stream._read_offset//8 % 16 == 0 assert stream._read_offset//8 % 16 == 0
if chunktype == 1000: if chunk_type == 1000:
pass pass
elif chunktype == 2000: elif chunk_type == 2000:
pass pass
elif chunktype == 2001: elif chunk_type == 2001:
self.lvl_parse_chunk_type_2001(stream, scene)
elif chunk_type == 2002:
pass
stream._read_offset = (start_pos + chunk_length) * 8 # go to the next CHNK
else:
# older lvl file structure
stream.skip_read(265)
stream.read(str, char_size=1, length_type=c_uint)
for _ in range(5):
stream.read(str, char_size=1, length_type=c_uint)
stream.skip_read(4)
for _ in range(stream.read(c_uint)):
stream.read(c_float), stream.read(c_float), stream.read(c_float)
self.lvl_parse_chunk_type_2001(stream, scene)
def lvl_parse_chunk_type_2001(self, stream, scene):
for _ in range(stream.read(c_uint)): for _ in range(stream.read(c_uint)):
object_id = stream.read(c_int64) # seems like the object id, but without some bits object_id = stream.read(c_int64) # seems like the object id, but without some bits
lot = stream.read(c_uint) lot = stream.read(c_uint)
@ -245,9 +267,6 @@ class LUZViewer(viewer.Viewer):
print("Name for lot", lot, "not found") print("Name for lot", lot, "not found")
lot_name += " - "+str(lot) lot_name += " - "+str(lot)
self.tree.insert(scene, END, text="Object", values=(object_id, lot_name, unknown1, unknown2, position, rotation, scale, config_data)) self.tree.insert(scene, END, text="Object", values=(object_id, lot_name, unknown1, unknown2, position, rotation, scale, config_data))
elif chunktype == 2002:
pass
stream._read_offset = (start_pos + chunk_length) * 8 # go to the next CHNK
def on_item_select(self, _): def on_item_select(self, _):
item = self.tree.selection()[0] item = self.tree.selection()[0]