mirror of
https://github.com/lcdr/utils.git
synced 2024-08-30 17:32:16 +00:00
Made the BitStream interface more stream-like.
This commit is contained in:
parent
54eccf854f
commit
c3841d65d3
@ -202,7 +202,7 @@ class CaptureViewer(viewer.Viewer):
|
||||
print("Parsing creations")
|
||||
creations = [i for i in files if "[24]" in i]
|
||||
for packet_name in creations:
|
||||
packet = ReadStream(capture.read(packet_name))
|
||||
packet = ReadStream(capture.read(packet_name), unlocked=True)
|
||||
self.parse_creation(packet_name, packet)
|
||||
|
||||
if self.parse_serializations.get():
|
||||
@ -333,7 +333,7 @@ class CaptureViewer(viewer.Viewer):
|
||||
parser_output.text += "\n"+name+"\n\n"
|
||||
parser_output.append(parser.parse(packet, {"creation":is_creation}))
|
||||
if not packet.all_read():
|
||||
raise IndexError("Not completely read, %i bytes unread" % (len(packet) - math.ceil(packet.read_offset / 8)))
|
||||
raise IndexError("Not completely read, %i bytes unread" % len(packet.read_remaining()))
|
||||
|
||||
def parse_serialization_packet(self, packet_name, packet):
|
||||
network_id = packet.read(c_ushort)
|
||||
|
@ -53,7 +53,9 @@ class LUZViewer(viewer.Viewer):
|
||||
self.tree.set_children("")
|
||||
print("Loading", luz_path)
|
||||
with open(luz_path, "rb") as file:
|
||||
stream = ReadStream(file.read())
|
||||
data = file.read()
|
||||
luz_len = len(data)
|
||||
stream = ReadStream(data, unlocked=True)
|
||||
|
||||
version = stream.read(c_uint)
|
||||
assert version in (36, 38, 39, 40, 41), version
|
||||
@ -85,7 +87,7 @@ class LUZViewer(viewer.Viewer):
|
||||
with open(lvl_path, "rb") as lvl:
|
||||
print("Loading lvl", filename)
|
||||
try:
|
||||
self.parse_lvl(ReadStream(lvl.read()), scene)
|
||||
self.parse_lvl(ReadStream(lvl.read(), unlocked=True), scene)
|
||||
except Exception:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
@ -115,7 +117,7 @@ class LUZViewer(viewer.Viewer):
|
||||
self.tree.insert(scene_transition, END, text="Transition Point", values=(transition_point_scene_id, transition_point_position))
|
||||
|
||||
remaining_length = stream.read(c_uint)
|
||||
assert len(stream) - stream.read_offset//8 == remaining_length
|
||||
assert luz_len - stream.read_offset//8 == remaining_length
|
||||
assert stream.read(c_uint) == 1
|
||||
|
||||
### paths
|
||||
@ -227,7 +229,9 @@ class LUZViewer(viewer.Viewer):
|
||||
self.tree.insert(waypoint, END, text="Config", values=(config_name, config_type_and_value))
|
||||
|
||||
def parse_lvl(self, stream, scene):
|
||||
if stream[0:4] == b"CHNK":
|
||||
header = stream.read(bytes, length=4)
|
||||
stream.read_offset = 0
|
||||
if header == b"CHNK":
|
||||
# newer lvl file structure
|
||||
# chunk based
|
||||
while not stream.all_read():
|
||||
|
Loading…
Reference in New Issue
Block a user