def read_children(stream, ptype, strings): if ptype == KEY_ROOM: sub = {"exits": []} fr1 = read_uint16be(stream) fr2 = read_uint16be(stream) # j = fr2 # size = 10 # for i in range(6): # if j & 3: # size += 2 # j >>= 2 sub['table'] = fr1 sub['exit_states'] = fr2 j = fr2 for i in range(6): if j & 3: sub['exits'] += [read_item(stream)] j >>= 2 return sub elif ptype == KEY_OBJECT: sub = {"params": []} flags = read_uint32be(stream) # size = 10 # for n in range(16): # if flags & (1 << n) != 0: # size += 2 sub['flags'] = flags if flags & 1: sub["params"] += [read_text(stream).resolve(strings)] for n in range(1, 16): if flags & (1 << n) != 0: sub["params"] += [read_uint16be(stream)] sub['name'] = read_text(stream).resolve(strings) return sub elif ptype == KEY_PLAYER: raise NotImplementedError('KEY_PLAYER') elif ptype == KEY_SUPER_ROOM: raise NotImplementedError('KEY_SUPER_ROOM') elif ptype == KEY_CHAIN: raise NotImplementedError('KEY_CHAIN') elif ptype == KEY_USERFLAG: raise NotImplementedError('KEY_USERFLAG') else: raise NotImplementedError(ptype)
def read_gamepc(stream): total_item_count = read_uint32be(stream) version = read_uint32be(stream) assert version == 128, version item_count = read_uint32be(stream) string_table_count = read_uint32be(stream) total_item_count += 2 item_count += 2 text_size = read_uint32be(stream) texts = stream.read(text_size).split(b'\0') last_text = texts.pop() assert last_text == b'' assert len(texts) == string_table_count, (len(texts), string_table_count) tables = stream.read() return total_item_count, version, item_count, texts, tables
def read_object(stream, strings): item = {} item['adjective'] = read_uint16be(stream) item['noun'] = read_uint16be(stream) item['state'] = read_uint16be(stream) item['next'] = read_item(stream) item['child'] = read_item(stream) item['parent'] = read_item(stream) item['unk'] = read_uint16be(stream) item['class'] = read_uint16be(stream) item['children'] = [] # print(item) props = read_uint32be(stream) while props: props = read_uint16be(stream) if props != 0: prop = read_children(stream, props, strings) prop['type'] = props item['children'] += [prop] return item
def read_item(stream): val = read_uint32be(stream) return 0 if val == 0xFFFFFFFF else val + 2
def read_text(stream): return Text(read_uint32be(stream))
def realize_params(params, stream, strings): for ptype in params: if ptype == ' ': continue if ptype == 'T': msg = None val = read_uint16be(stream) if val == 0: t = 0xFFFFFFFF elif val == 3: t = 0xFFFFFFFD else: t = read_uint32be(stream) num = t & 0xFFFF if num != 0xFFFF: msg = strings.get(num, "MISSING STRING") yield f'{num}("{msg}")' continue if ptype == 'B': num = ord(stream.read(1)) if num == 0xFF: yield [ord(stream.read(1))] else: yield num continue if ptype == 'I': num = read_uint16be(stream) if num == 1: yield 'SUBJECT_ITEM' elif num == 3: yield 'OBJECT_ITEM' elif num == 5: yield 'ME_ITEM' elif num == 7: yield 'ACTOR_ITEM' elif num == 9: yield 'ITEM_A_PARENT' else: num = read_uint32be(stream) + 2 & 0xFFFF yield f'<{num}>' continue if ptype in { 'v', 'p', 'n', 'a', 'S', 'N', }: num = read_uint16be(stream) yield num continue # if ptype == 'J': # yield '->' # continue # if ptype == 'W': # num = read_uint16be(stream) # yield [num - 3000] if 30000 <= num < 30512 else num # continue # if ptype == 'V': # num = ord(stream.read(1)) # if num == 0xFF: # yield [[ord(stream.read(1))]] # else: # yield [num] # continue raise NotImplementedError(ptype)