Skip to content

Instantly share code, notes, and snippets.

@amPerl
Created November 8, 2016 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amPerl/669354c1f7a93ad14ac0488cfe7cb1ab to your computer and use it in GitHub Desktop.
Save amPerl/669354c1f7a93ad14ac0488cfe7cb1ab to your computer and use it in GitHub Desktop.
tool to unpack Drift City modeltable0.LOF files
import argparse
import struct
import os
def extract(path, out_path):
try:
os.makedirs(out_path, exist_ok=True)
except OSError:
raise Exception("Couldn't create output path.")
with open(path, 'rb') as f:
file_count = struct.unpack('6I', f.read(6 * 4))[-2]
files = []
for i in range(file_count):
idx = struct.unpack('I', f.read(4))[0]
f.read(5 * 4)
cur_pos = f.tell()
korean_garbage = f.read(32).split(b'\0')[0]
f.seek(cur_pos + len(korean_garbage) + 1)
cur_pos = f.tell()
file_name = f.read(32).split(b'\0')[0].decode()
f.seek(cur_pos + len(file_name) + 1 + 4 + 8)
file_pos, file_len = struct.unpack('II', f.read(8))
files.append((file_name, file_pos, file_len))
for file_name, file_pos, file_len in files:
print(file_name, file_pos, file_len)
f.seek(file_pos)
buf = f.read(file_len)
with open(os.path.join(out_path, file_name), 'wb') as of:
of.write(buf)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('lof', help="path to the modeltable .LOF file")
parser.add_argument('path', help="directory to put the extracted files in")
parser.set_defaults(ignore_existing=False)
args = parser.parse_args()
extract(args.lof, args.path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment