From 3bf199ca627309e5ae477d957c0af387f9781182 Mon Sep 17 00:00:00 2001 From: lcdr Date: Sat, 10 Jun 2017 12:29:37 +0200 Subject: [PATCH] Definition updates and changes to use bitstream's changed string handling --- captureviewer.pyw | 78 ++++++++++++++++--- luzviewer.pyw | 16 ++-- packetdefinitions/gamemessages.xml | 1 - .../replica/components/Component 108.structs | 2 +- .../replica/components/Model.structs | 17 ++++ .../replica/components/Stats.structs | 2 +- pkviewer.pyw | 2 +- structparser.py | 8 +- 8 files changed, 99 insertions(+), 27 deletions(-) create mode 100644 packetdefinitions/replica/components/Model.structs diff --git a/captureviewer.pyw b/captureviewer.pyw index fde7208..4de0178 100644 --- a/captureviewer.pyw +++ b/captureviewer.pyw @@ -24,7 +24,7 @@ def compressed_ldf_handler(stream): is_compressed = stream.read(c_bool) if is_compressed: uncompressed_size = stream.read(c_uint) - uncompressed = zlib.decompress(stream.read(bytes, length=stream.read(c_uint))) + uncompressed = zlib.decompress(stream.read(bytes, length_type=c_uint)) assert len(uncompressed) == uncompressed_size else: uncompressed = stream.read(bytes, length=size) @@ -33,9 +33,9 @@ def compressed_ldf_handler(stream): type_handlers = {} type_handlers["compressed_ldf"] = compressed_ldf_handler -with open("packetdefinitions/replica/creation_header.structs", encoding="utf-8") as file: +with open(__file__+"/../packetdefinitions/replica/creation_header.structs", encoding="utf-8") as file: creation_header_parser = structparser.StructParser(file.read(), type_handlers) -with open("packetdefinitions/replica/serialization_header.structs", encoding="utf-8") as file: +with open(__file__+"/../packetdefinitions/replica/serialization_header.structs", encoding="utf-8") as file: serialization_header_parser = structparser.StructParser(file.read(), type_handlers) component_name = OrderedDict() @@ -63,6 +63,7 @@ component_name[6] = "Bouncer", component_name[39] = "ScriptedActivity", component_name[71] = "RacingControl", component_name[75] = "Exhibit", +component_name[42] = "Model", component_name[2] = "Render", component_name[107] = "Component 107", component_name[69] = "Trigger", @@ -79,6 +80,8 @@ component_name[64] = None component_name[65] = None component_name[68] = None component_name[73] = None +component_name[74] = None +component_name[95] = None component_name[104] = None component_name[113] = None component_name[114] = None @@ -89,11 +92,11 @@ for comp_id, indices in component_name.items(): if indices is not None: comp_parser[comp_id] = [] for index in indices: - with open("packetdefinitions/replica/components/"+index+".structs") as file: + with open(__file__+"/../packetdefinitions/replica/components/"+index+".structs") as file: comp_parser[comp_id].append(structparser.StructParser(file.read(), type_handlers)) norm_parser = {} -for rootdir, _, files in os.walk("packetdefinitions"): +for rootdir, _, files in os.walk(__file__+"/../packetdefinitions"): for filename in files: with open(rootdir+"/"+filename) as file: norm_parser[filename[:filename.rindex(".")]] = structparser.StructParser(file.read(), type_handlers) @@ -495,6 +498,62 @@ class CaptureViewer(viewer.Viewer): properties.append(property) + elif msg_name == "ClientTradeUpdate": + attr_values["currency"] = packet.read(c_uint64) + + items = [] + for _ in range(packet.read(c_uint)): + item = {} + item["object_id"] = packet.read(c_int64) + item_obj_id_again = packet.read(c_int64) + assert item["object_id"] == item_obj_id_again + item["lot"] = packet.read(c_int) + if packet.read(c_bit): + item["unknown1"] = packet.read(c_int64) + if packet.read(c_bit): + item["unknown2"] = packet.read(c_uint) + if packet.read(c_bit): + item["slot"] = packet.read(c_ushort) + if packet.read(c_bit): + item["unknown3"] = packet.read(c_uint) + if packet.read(c_bit): + item["extra_info"] = compressed_ldf_handler(packet) + item["unknown4"] = packet.read(c_bit) + items.append(item) + attr_values["items"] = items + + elif msg_name == "ServerTradeUpdate": + attr_values["aboutToPerform"] = packet.read(c_bit) + attr_values["currency"] = packet.read(c_uint64) + + items = [] + for _ in range(packet.read(c_uint)): + item = {} + item["object_id"] = packet.read(c_int64) + item_obj_id_again = packet.read(c_int64) + assert item["object_id"] == item_obj_id_again + item["lot"] = packet.read(c_int) + if packet.read(c_bit): + item["unknown1"] = packet.read(c_int64) + if packet.read(c_bit): + item["amount"] = packet.read(c_uint) + if packet.read(c_bit): + item["slot"] = packet.read(c_ushort) + if packet.read(c_bit): + item["unknown2"] = packet.read(c_uint) + if packet.read(c_bit): + item["extra_info"] = compressed_ldf_handler(packet) + item["unknown3"] = packet.read(c_bit) + items.append(item) + attr_values["items"] = items + + elif msg_name == "PropertyBuildModeUpdate": + attr_values["start"] = packet.read(c_bit) + attr_values["friends"] = {} + for _ in range(packet.read(c_uint)): + attr_values["friends"][packet.read(c_int64)] = packet.read(c_bit) + attr_values["numSent"] = packet.read(c_int) + elif msg_name == "ModularBuildFinish": lots = [] for _ in range(packet.read(c_ubyte)): @@ -569,14 +628,11 @@ class CaptureViewer(viewer.Viewer): elif type_ == "float": value = packet.read(c_float) elif type_ == "BinaryBuffer": - length = packet.read(c_uint) - value = packet.read(bytes, length=length) + value = packet.read(bytes, length_type=c_uint) elif type_ == "std::string": - length = packet.read(c_uint) - value = packet.read(str, char_size=1, allocated_length=length) + value = packet.read(bytes, length_type=c_uint) elif type_ == "std::wstring": - length = packet.read(c_uint) - value = packet.read(str, char_size=2, allocated_length=length*2) + value = packet.read(str, length_type=c_uint) elif type_ == "NiPoint3": value = packet.read(c_float), packet.read(c_float), packet.read(c_float) elif type_ == "NiQuaternion": diff --git a/luzviewer.pyw b/luzviewer.pyw index 44488c4..ff81344 100644 --- a/luzviewer.pyw +++ b/luzviewer.pyw @@ -75,9 +75,9 @@ class LUZViewer(viewer.Viewer): number_of_scenes = stream.read(c_ubyte) for _ in range(number_of_scenes): - filename = stream.read(str, char_size=1, length_type=c_ubyte) + filename = stream.read(bytes, length_type=c_ubyte).decode("latin1") scene_id = stream.read(c_uint64) - scene_name = stream.read(str, char_size=1, length_type=c_ubyte) + scene_name = stream.read(bytes, length_type=c_ubyte).decode("latin1") scene = self.tree.insert(scenes, END, text="Scene", values=(filename, scene_id, scene_name)) assert stream.read(bytes, length=3) lvl_path = os.path.join(os.path.dirname(luz_path), filename) @@ -92,9 +92,9 @@ class LUZViewer(viewer.Viewer): assert stream.read(c_ubyte) == 0 ### terrain - filename = stream.read(str, char_size=1, length_type=c_ubyte) - name = stream.read(str, char_size=1, length_type=c_ubyte) - description = stream.read(str, char_size=1, length_type=c_ubyte) + filename = stream.read(bytes, length_type=c_ubyte).decode("latin1") + name = stream.read(bytes, length_type=c_ubyte).decode("latin1") + description = stream.read(bytes, length_type=c_ubyte).decode("latin1") self.tree.insert(zone, END, text="Terrain", values=(filename, name, description)) ### scene transitions @@ -102,7 +102,7 @@ class LUZViewer(viewer.Viewer): for _ in range(stream.read(c_uint)): scene_transition_values = () if version < 40: - scene_transition_values += stream.read(str, char_size=1, length_type=c_ubyte), + scene_transition_values += stream.read(bytes, length_type=c_ubyte), scene_transition_values += stream.read(c_float), scene_transition = self.tree.insert(scene_transitions, END, text="Scene Transition", values=scene_transition_values) if version < 39: @@ -241,9 +241,9 @@ class LUZViewer(viewer.Viewer): else: # older lvl file structure stream.skip_read(265) - stream.read(str, char_size=1, length_type=c_uint) + stream.read(bytes, length_type=c_uint) for _ in range(5): - stream.read(str, char_size=1, length_type=c_uint) + stream.read(bytes, 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) diff --git a/packetdefinitions/gamemessages.xml b/packetdefinitions/gamemessages.xml index d41b353..1c6e0ff 100644 --- a/packetdefinitions/gamemessages.xml +++ b/packetdefinitions/gamemessages.xml @@ -1258,7 +1258,6 @@ - diff --git a/packetdefinitions/replica/components/Component 108.structs b/packetdefinitions/replica/components/Component 108.structs index 67743ea..4996596 100644 --- a/packetdefinitions/replica/components/Component 108.structs +++ b/packetdefinitions/replica/components/Component 108.structs @@ -4,5 +4,5 @@ Index 1 ($+7DC1F0) [bit] - flag [s64] - driver object id [bit] - flag - [u32] - ??? + [u32] - possessable component id? [bit] - ??? diff --git a/packetdefinitions/replica/components/Model.structs b/packetdefinitions/replica/components/Model.structs new file mode 100644 index 0000000..cf9bdbf --- /dev/null +++ b/packetdefinitions/replica/components/Model.structs @@ -0,0 +1,17 @@ +Component 42 - Model +Index 1: +[bit] - flag + [bit] - ??? + [s32] - model type + [float] - position x + [float] - position y + [float] - position z + [float] - rotation w + [float] - rotation x + [float] - rotation y + [float] - rotation z +[bit] - flag + [u32] - ??? + [bit] - ??? + [bit] - flag + [u64] - ??? diff --git a/packetdefinitions/replica/components/Stats.structs b/packetdefinitions/replica/components/Stats.structs index b62165d..aa5d305 100644 --- a/packetdefinitions/replica/components/Stats.structs +++ b/packetdefinitions/replica/components/Stats.structs @@ -5,7 +5,7 @@ if creation: [u32] - is boss?, expect == 0 [u32] - ??? [u32] - ??? - [u32] - ???, assert == 0 + [u32] - ???, expect == 0 [u32] - ???, assert == 0 [u32] - ???, assert == 0 [u32] - ??? diff --git a/pkviewer.pyw b/pkviewer.pyw index ba2f8e2..87f1ddd 100644 --- a/pkviewer.pyw +++ b/pkviewer.pyw @@ -82,7 +82,7 @@ class PKViewer(viewer.Viewer): assert stream.read(c_uint) == 3 pack_files = [] for _ in range(stream.read(c_uint)): - pack_files.append(stream.read(str, char_size=1, length_type=c_uint)) + pack_files.append(stream.read(bytes, length_type=c_uint).decode("latin1")) for _ in range(stream.read(c_uint)): stream.skip_read(20) diff --git a/structparser.py b/structparser.py index 57ae7cd..b8c5ab9 100644 --- a/structparser.py +++ b/structparser.py @@ -61,11 +61,11 @@ class StructParser: self._type_handlers["s64"] = lambda stream: stream.read(c_int64) self._type_handlers["u64"] = lambda stream: stream.read(c_uint64) # string types - self._type_handlers["u8-string"] = lambda stream: stream.read(str, char_size=1, length_type=c_uint8) - self._type_handlers["u16-string"] = lambda stream: stream.read(str, char_size=1, length_type=c_uint16) + self._type_handlers["u8-string"] = lambda stream: stream.read(bytes, length_type=c_uint8) + self._type_handlers["u16-string"] = lambda stream: stream.read(bytes, length_type=c_uint16) - self._type_handlers["u8-wstring"] = lambda stream: stream.read(str, char_size=2, length_type=c_uint8) - self._type_handlers["u16-wstring"] = lambda stream: stream.read(str, char_size=2, length_type=c_uint16) + self._type_handlers["u8-wstring"] = lambda stream: stream.read(str, length_type=c_uint8) + self._type_handlers["u16-wstring"] = lambda stream: stream.read(str, length_type=c_uint16) self._type_handlers.update(type_handlers) def parse(self, data, variables=None):