initial
This commit is contained in:
commit
138eeff898
64
extract.py
Normal file
64
extract.py
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
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")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
map_file = args.map_file
|
||||||
|
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)
|
||||||
|
|
||||||
|
logger.info("Opening %s", bin_filename)
|
||||||
|
with zip_file.open(bin_filename) as bin_file:
|
||||||
|
byte = bin_file.read(1)
|
||||||
|
while byte != b"":
|
||||||
|
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)
|
||||||
|
byte = bin_file.read(1)
|
||||||
|
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()
|
Loading…
Reference in New Issue
Block a user