Advertisement
Guest User

Untitled

a guest
Jul 15th, 2023
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. import os
  2. import sys
  3.  
  4. def alignpos(f, align):
  5.     cur = f.tell()
  6.     if cur % align != 0:
  7.         f.seek((align - cur % align) + cur)
  8.    
  9. def readstr(f):
  10.     strbytes = bytearray()
  11.     strln = int.from_bytes(f.read(4), byteorder='little')
  12.     for i in range(strln):
  13.         strbytes.append(ord(f.read(1)))
  14.     return str(strbytes, 'utf-8')
  15.    
  16. def read(file, lc='en'):
  17.     result = ''
  18.     with open(file, 'rb') as f:
  19.         f.seek(-12, os.SEEK_END)
  20.         loc = readstr(f)
  21.         if loc != lc:
  22.             return
  23.         print('Locale: %s' % loc)
  24.         f.seek(0x1C)
  25.         filename = readstr(f)
  26.         alignpos(f, 4)
  27.         count = int.from_bytes(f.read(4), byteorder='little')
  28.         print('File: %s\nCount: %i\n' % (filename, count))
  29.         f.read(12)
  30.         for i in range(count):
  31.             mesid = readstr(f)
  32.             alignpos(f, 4)
  33.             messtr = readstr(f)
  34.             alignpos(f, 4)
  35.             f.read(0x10)
  36.             result += messtr + '\n'
  37.         with open(filename + '.txt', 'w', encoding='utf-8') as r:
  38.             r.write(result)
  39.  
  40. # en - english, ru - russian
  41. read(sys.argv[1], 'en')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement