Guest User

FC Quest Dump

a guest
Mar 11th, 2017
128
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import struct
  2. import sys
  3.  
  4. def get_str(pos, filedata):
  5.     return filedata[pos:filedata.find(b'\x00', pos)].decode(
  6.         'cp932')
  7.  
  8. class Quest(object):
  9.     def __init__(self):
  10.         self.name = ''
  11.         self.lines = []
  12.     def __repr__(self):
  13.         return self.name
  14.  
  15. sys.argv.append('T_QUEST._DT')
  16. #Strip out linebreaks and change fullwidth spaces to regular spaces
  17. #Ended up not using this
  18. trans_tbl = dict(((1, None),    
  19.                   (ord(' '), ' ')))
  20. ptr_start = 0x0
  21. ptr_end = 0xAE
  22.  
  23. with open(sys.argv[1], 'rb') as f:
  24.     filedata = f.read()
  25.  
  26. quests = []
  27. ptrs = tuple(struct.unpack(
  28.     '<H', filedata[x:x+2])[0] for x in range(ptr_start, ptr_end, 2))
  29. for ptr in ptrs:
  30.     quest = Quest()
  31.     quest_ptrs = tuple(struct.unpack('<H', filedata[x:x+2])[0] for x in range(
  32.         ptr + 0x12, ptr + 0x12 + 0x24, 2))
  33.     quest.name = get_str(quest_ptrs[0], filedata)
  34.     quest.desc = get_str(quest_ptrs[1], filedata)
  35.     for ptr2 in quest_ptrs[2:]:
  36.         quest.lines.append(get_str(ptr2, filedata))
  37. ##        quest.lines.append(get_str(ptr2, filedata).translate(trans_tbl))
  38.     quests.append(quest)
  39. with open('questdump.tsv', 'w', encoding='utf-8') as f:
  40.     for i, quest in enumerate(quests):
  41.         f.write('{}\tName:\t{}\n\tIntro:\t'.format(i, quest.name))
  42.         f.write(quest.desc.replace('\x01', '\n\t\t'))
  43.         f.write('\n')
  44.         for j, line in enumerate(quest.lines):
  45.             f.write('\t{}\t{}\n'.format(j, line.replace('\x01', '\n\t\t')))
RAW Paste Data