Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import shutil
- import struct
- import textwrap
- #Up to 50 characters used in original file (counting the star as 1 character)
- INPUT_COL = 3
- trans_tbl_fr = (('|',';'),
- ('é','<'),
- ('è','>'),
- ('à','^'),
- ('ê','_'),
- ('ù','+'),
- ('…','...'),
- ('ç','c'),
- ('â','a'),
- ('ä','a'),
- ('î','i'),
- ('ï','i'),
- ('ö','o'),
- ('ô','o'),
- ('ü','u'),
- ('û','u'),
- ('ë','e'),
- ('æ','ae'),
- ('œ','oe'))
- trans_tbl_fr = dict((ord(x[0]), x[1]) for x in trans_tbl_fr)
- if os.path.isfile('T_QUEST.orig'):
- pass
- elif os.path.isfile('T_QUEST._DT'):
- shutil.copy('T_QUEST._DT', 'T_QUEST.orig')
- else:
- print('Missing T_QUEST. Place in this tool\'s folder.')
- quit()
- if not os.path.isfile('t_quest.tsv'):
- print('Missing input file t_quest.tsv. Place in this tool\'s folder.')
- quit()
- inputdata = []
- with open('t_quest.tsv', 'r', encoding='utf-8') as f:
- for line in f:
- line = line.split('\t')
- if len(line) < 3:
- print('hit')
- break
- if line[0] != '':
- inputdata.append([])
- if line[1] != '':
- inputdata[-1].append([line[INPUT_COL]])
- else:
- inputdata[-1][-1].append(line[INPUT_COL])
- #First 0x12 bytes of each quest are unknown
- unknown_data = []
- with open('T_QUEST.orig', 'rb') as f:
- filedata = f.read()
- ptr_start = 0x0
- ptr_end = 0xAE
- ptrs = tuple(struct.unpack(
- '<H', filedata[x:x+2])[0] for x in range(ptr_start, ptr_end, 2))
- for ptr in reversed(ptrs):
- unknown_data.append(filedata[ptr:ptr + 0x12])
- filedata = bytearray(0xAE)
- header_ptrs = []
- for quest in inputdata:
- header_ptrs.append(len(filedata))
- filedata += unknown_data.pop()
- quest_ptrs_pos = len(filedata)
- quest_ptrs = []
- filedata += bytearray(0x24)
- for s_list in quest:
- quest_ptrs.append(len(filedata))
- s_out = []
- for s in s_list:
- s = s.translate(trans_tbl_fr)
- if s == 'X':
- s_out.append('')
- continue
- if s == '':
- continue
- s_out.append('\x01 '.join(textwrap.wrap(s, 50)))
- filedata += '\x01'.join(s_out).encode('cp932') + b'\x00'
- filedata[quest_ptrs_pos:quest_ptrs_pos + 0x24] = (
- struct.pack('<' + 'H' * 18, *quest_ptrs))
- filedata[:0xAE] = struct.pack('<' + 'H' * len(header_ptrs), *header_ptrs)
- with open('T_QUEST._DT', 'wb') as f:
- f.write(filedata)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement