Skip to content

Instantly share code, notes, and snippets.

@Xzonn
Created August 22, 2021 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xzonn/bc9454ec711d4c547776825c5eaea476 to your computer and use it in GitHub Desktop.
Save Xzonn/bc9454ec711d4c547776825c5eaea476 to your computer and use it in GitHub Desktop.
Try to export etb files from "Buddy Misson BOND" into a txt file
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
#
# Try to export etb files from "Buddy Misson BOND" into a txt file
#
# 用于从《搭档任务 秘密搜查组》的 etb 文件提取 txt 文本
import os
import struct
file_list = [i for i in os.listdir("./") if i.endswith(".etb")]
export_buffer = open("export.txt", "w", -1, "utf-8")
for file_name in file_list:
export_buffer.write(f"{file_name}\n")
with open(file_name, "rb") as read_buffer:
count, = struct.unpack("<I", read_buffer.read(4))
for s_id in range(count):
tmp, = struct.unpack("<I", read_buffer.read(4))
assert tmp == s_id
for s_id in range(count):
s_start, s_length = struct.unpack("<II", read_buffer.read(8))
pos = read_buffer.tell()
read_buffer.seek(count * 4 * 3 + 4 + s_start)
string_bytes = read_buffer.read(s_length)
assert(string_bytes[-1] == 0)
# For Chinese, the encoding is "gbk", and for Korean, the encoding is "eur-kr".
string = string_bytes[:-1].decode("shift-jis", errors="backslashreplace").replace("\n", "\\n")
export_buffer.write(f"{s_id}\t{string}\n")
read_buffer.seek(pos)
export_buffer.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment