Skip to content

Instantly share code, notes, and snippets.

@pushrbx
Created October 22, 2018 21:17
Show Gist options
  • Save pushrbx/188e1de1f3dd5bb584d46cd9d0e51bc4 to your computer and use it in GitHub Desktop.
Save pushrbx/188e1de1f3dd5bb584d46cd9d0e51bc4 to your computer and use it in GitHub Desktop.
Ugly python script which extracts the text from tb_Quest_Scripts_eng.res file of Soulworker into a json file.
import os
import json
import codecs
def read_block(f):
block_size = 0
index = int.from_bytes(bytes(f.read(4)), byteorder='little')
block_size += 4
len1 = int.from_bytes(bytes(f.read(2)), byteorder='little')
block_size += 2
str1 = codecs.decode(bytes(f.read(len1 * 2)), encoding='utf-8', errors='replace').replace('\0', '')
block_size += len1 * 2
len2 = int.from_bytes(bytes(f.read(2)), byteorder='little')
block_size += 2
str2 = codecs.decode(bytes(f.read(len2 * 2)), encoding='utf-8', errors='replace').replace('\0', '')
block_size += len2 * 2
len3 = int.from_bytes(bytes(f.read(2)), byteorder='little')
block_size += 2
str3 = codecs.decode(bytes(f.read(len3 * 2)), encoding='utf-8', errors='replace').replace('\0', '')
block_size += len3 * 2
len4 = int.from_bytes(bytes(f.read(2)), byteorder='little')
block_size += 2
str4 = codecs.decode(bytes(f.read(len4 * 2)), encoding='utf-8', errors='replace').replace('\0', '')
block_size += len4 * 2
len5 = int.from_bytes(bytes(f.read(2)), byteorder='little')
block_size += 2
str5 = codecs.decode(bytes(f.read(len5* 2)), encoding='utf-8', errors='replace').replace('\0', '')
block_size += len5 * 2
return {"index": index, "str1": str1, "str2": str2, "str3": str3, "str4": str4, "str5": str5, "size": block_size}
fname = "tb_Quest_Script_eng.res"
fsize = os.path.getsize(fname)
entries = []
with open("tb_Quest_Script_eng.res", "rb") as f:
try:
entry_count = int.from_bytes(f.read(4), byteorder='little')
fsize -= 4
while entry_count > 0:
block = read_block(f)
fsize -= block["size"]
entry_count -= 1
entries.append(block)
except Exception as e:
print(e)
with open('sw_quests.json', 'w', encoding='utf-8') as c:
json.dump(entries, c, ensure_ascii=False, indent=4)
print('done')
@pushrbx
Copy link
Author

pushrbx commented Feb 16, 2019

Oh come on, you can do it yourself! You only need to modify it to make it read 3 bytes instead of 2 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment