This commit is contained in:
Amazed 2021-01-27 13:57:57 +01:00
parent 3f725592e5
commit aa6adeb000
2 changed files with 2 additions and 99 deletions

View File

@ -1,98 +0,0 @@
import zipfile
import argparse
import logging
import struct
def main():
objects = []
_ch = logging.StreamHandler()
_ch.setLevel("DEBUG")
_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
_ch.setFormatter(_formatter)
logger = logging.getLogger(__name__)
logger.addHandler(_ch)
logger.setLevel("DEBUG")
parser = argparse.ArgumentParser()
parser.add_argument("map_file", help="map file, or bin if you also use --bin")
parser.add_argument("--bin", action="store_true", help="use this if the file is already a .bin file")
args = parser.parse_args()
map_file = args.map_file
_fh = logging.FileHandler(args.map_file+".log")
_fh.setFormatter(_formatter)
logger.addHandler(_fh)
if not args.bin:
logger.info("Opening %s", map_file)
zip_file = zipfile.ZipFile(map_file)
files = zip_file.namelist()
bin_filename = None
for file in files:
logger.info("Found file %s", file)
if file.endswith(".bin"):
bin_filename = file
logger.info("Found BIN file %s", bin_filename)
break
if not bin_filename:
logger.error("FATAL: BIN file not found")
zip_file.close()
exit(1)
fp = zip_file.open(bin_filename)
else:
bin_filename = args.map_file
fp = open(bin_filename, "rb")
logger.info("Opening %s", bin_filename)
with fp as bin_file:
byte = bin_file.read(1)
while byte != b"":
angle_y = 0
angle_z = 0
scale = 1
has_extended_angle = False
if byte == b'\x46':
has_extended_angle = True
model = struct.unpack("<L", bin_file.read(4))[0]
x = struct.unpack("<f", bin_file.read(4))[0]
y = struct.unpack("<f", bin_file.read(4))[0]
z = struct.unpack("<f", bin_file.read(4))[0]
angle = struct.unpack("<f", bin_file.read(4))[0]
if has_extended_angle:
angle_y = struct.unpack("<f", bin_file.read(4))[0]
angle_z = struct.unpack("<f", bin_file.read(4))[0]
unk = struct.unpack("<b", bin_file.read(1))[0]
scale = struct.unpack("<f", bin_file.read(4))[0]
objects.append(
{"model": model, "x": x, "y": y, "z": z, "angle": angle, "angle_y": angle_y, "angle_z": angle_z, "scale": scale})
logger.info("Object model=%s x=%s y=%s z=%s angle=%s angley=%s anglez=%s scale=%s", model, x, y, z, angle, angle_y, angle_z, scale)
if byte == b'\x2a': # start object
# object is 20 bytes long
model = struct.unpack("<L", bin_file.read(4))[0]
x = struct.unpack("<f", bin_file.read(4))[0]
y = struct.unpack("<f", bin_file.read(4))[0]
z = struct.unpack("<f", bin_file.read(4))[0]
angle = struct.unpack("<f", bin_file.read(4))[0]
objects.append({"model": model, "x": x, "y": y, "z": z, "angle": angle})
logger.info("Object model=%s x=%s y=%s z=%s angle=%s", model, x, y, z, angle)
if byte == b'\x46': # start object too
# object is 20 bytes long
byte = bin_file.read(1)
if not args.bin:
zip_file.close()
logger.info("Number of objects: %s", len(objects))
models_count = {}
for game_object in objects:
if not game_object["model"] in models_count:
models_count[game_object["model"]] = 0
models_count[game_object["model"]] += 1
models_count = sorted(models_count.items(), key=lambda kv: kv[1], reverse=True)
for top_model in models_count:
logger.info("Model %s was found %s times", top_model[0], top_model[1])
if __name__ == '__main__':
main()

View File

@ -43,7 +43,8 @@ def extract_gzp(gzp_file, extensions, output_dir):
checksum = read_int(gzp_fp)
if checksum != 0x6608F101:
raise Exception("Invalid GZP checksum")
pass
#raise Exception("Invalid GZP checksum")
logger.info("Checksum OK")