Skip to content

Commit

Permalink
fixed bug with zlib decompression
Browse files Browse the repository at this point in the history
  • Loading branch information
Yay5379 authored Mar 30, 2024
1 parent c1feaad commit 7c8230e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
import json

def parse_replay(file):
def parse_replay_unit_list(file):

units = []
print(f"parsing {file}")
Expand Down Expand Up @@ -112,7 +112,7 @@ def main():

print(f"parsing replay in {file}")

data = parse_replay(file)
data = parse_replay_unit_list(file)

folder_name = os.path.basename(file)
file_path = os.getcwd()
Expand Down
10 changes: 2 additions & 8 deletions src/wt_client_replay_parser/formats/wrpl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,11 @@ def FatBlockStream(sz: t.Union[int, callable, None] = None) -> ct.Construct:
con = ct.GreedyBytes if sz is None else ct.Bytes(sz)
return ct.RestreamData(con, bin.Fat)


def ZlibStream(sz: t.Union[int, callable, None] = None):
con = ct.GreedyBytes if sz is None else ct.Bytes(sz)
return ct.RestreamData(con, ct.Compressed(con, 'zlib'))


WRPLCliFile = ct.Struct(
'header' / Header,
ct.Bytes(2),
'm_set' / FatBlockStream(this.header.m_set_size),
'wrplu_offset' / ct.Tell,
'wrplu' / ZlibStream(this.header.rez_offset - this.wrplu_offset),
'wrplu' / ct.Bytes(this.header.rez_offset - this.wrplu_offset),
'rez' / bin.Fat,
)
)
31 changes: 12 additions & 19 deletions src/wt_client_replay_parser/wrpl_unpacker.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
import argparse
import json
from pathlib import Path
import json
import zlib
import typing as t
import os
import sys
import construct as ct
from blk.types import Section
import blk.text as txt
try:
from formats.wrpl_parser import WRPLCliFile
except ImportError:
from formats.wrpl_parser import WRPLCliFile
try:
from formats.parse_datablocks import parse_datablocks
except ImportError:
from formats.parse_datablocks import parse_datablocks
try:
from formats.parse_replay import parse_replay
except ImportError:
from formats.parse_replay import parse_replay
from formats.wrpl_parser import WRPLCliFile
from formats.parse_datablocks import parse_datablocks
from formats.parse_unit_list import parse_replay_unit_list

def serialize_text(root: Section, ostream: t.TextIO):
txt.serialize(root, ostream, dialect=txt.StrictDialect)
Expand Down Expand Up @@ -57,9 +49,14 @@ def main():
serialize_text(section, ostream)

out_path = out_dir / 'wrplu.bin'
out_path.write_bytes(parsed.wrplu)
out_path.write_bytes(zlib.decompress(parsed.wrplu))
parse_datablocks(out_path)

data = parse_replay_unit_list(out_path)

with create_text(f'{out_dir}/units.json') as ostream:
json.dump(data, ostream, indent=2)

out_path = out_dir / 'info.blk'
info=(
f'wrpl_version:i={parsed.header.version}\n'
Expand All @@ -81,14 +78,10 @@ def main():
with create_text(out_path) as ostream:
print(info, file=ostream)

data = parse_replay(f'{out_dir}/wrplu.bin')
with create_text(f'{out_dir}/units.json') as ostream:
json.dump(data, ostream, indent=2)

print(f'{replay.name} => {out_dir}')

return 0


if __name__ == '__main__':
sys.exit(main())
sys.exit(main())

0 comments on commit 7c8230e

Please sign in to comment.