#!python # python 3 actually # The code is not the prettiest, sorry # The tool will convert between binary and textual IPL files # -p gtapath is used to load object names from IDE when converting to textual import os import glob import sys from struct import * # join path def jp(*paths): return os.path.normcase(os.path.join(paths[0], *paths[1:])) # create file def opencreate(path, mode): path = os.path.normcase(path) dir = os.path.dirname(path) if dir != '' and not os.path.exists(dir): os.makedirs(dir) return open(path, mode) # get argument to dash option def getarg(usage): global _args if _args != '': t = _args _args = '' return t if len(sys.argv) < 2: usage() exit(1) t = sys.argv[1] sys.argv.pop(0) return t # parse arguments def parseargs(argfun): global argv0, _args, _argc argv0 = os.path.basename(sys.argv.pop(0)) while len(sys.argv) > 0 and \ sys.argv[0][0] == '-' and \ len(sys.argv[0]) > 1: _args = sys.argv[0][1:] if _args == '-': sys.argv.pop(0) break while _args != '': _argc = _args[0] _args = _args[1:] argfun(_argc) sys.argv.pop(0) objects = {} def readide(idefile): f = open(jp(gtapath, idefile), 'r') indef = False for line in f: line = line.strip().replace(',', ' ') if len(line) > 1 and line[0] == '#': continue line = line.split() if len(line) < 1: continue if line[0] in ['objs', 'tobj', 'anim']: indef = True continue if line[0] == 'end': indef = False continue if indef: objects[int(line[0])] = line[1] f.close() def readdat(dat): for line in dat: line = line.strip().replace(',', ' ') if len(line) > 1 and line[0] == '#': continue line = line.split() if len(line) >= 2 and line[0] == 'IDE': readide(line[1]) def readnames(): f = open(jp(gtapath, "data/default.dat"), 'r') readdat(f) f.close() f = open(jp(gtapath, "data/gta.dat"), 'r') readdat(f) f.close() def convtextipl(data, outf): insts = [] cars = [] state = 0 for line in data.decode('ascii').splitlines(): line = line.strip().replace(',', ' ') if len(line) > 1 and line[0] == '#': continue line = line.split() if len(line) < 1: continue if line[0] == 'inst': state = 1 continue if line[0] == 'cars': state = 2 continue if line[0] == 'end': state = 0 continue if state == 1: # inst inst = [int(line[0]), int(line[2]), float(line[3]), float(line[4]), float(line[5]), float(line[6]), float(line[7]), float(line[8]), float(line[9]), int(line[10])] insts.append(inst) if state == 2: # cars car = [float(line[0]), float(line[1]), float(line[2]), float(line[3]), int(line[4]), int(line[5]), int(line[6]), int(line[7]), int(line[8]), int(line[9]), int(line[10]), int(line[11])] cars.append(car) instoff = 0x4C caroff = instoff + len(insts)*0x28 header = b'bnry' + \ pack('