2nd demon file & contact parser
This commit is contained in:
97
_Utils/Dungeon/contact_parser.py
Normal file
97
_Utils/Dungeon/contact_parser.py
Normal file
@@ -0,0 +1,97 @@
|
||||
import sys
|
||||
import struct
|
||||
import os
|
||||
|
||||
# Таблица команд
|
||||
COMMANDS = {
|
||||
0x01: "ShowTextID (u16)",
|
||||
# Сюда можно добавлять другие команды по мере обнаружения
|
||||
}
|
||||
|
||||
def read_int16(data, offset):
|
||||
"""Читает int16 из данных по смещению"""
|
||||
return struct.unpack('<h', data[offset:offset+2])[0]
|
||||
|
||||
def read_uint16(data, offset):
|
||||
"""Читает uint16 из данных по смещению"""
|
||||
return struct.unpack('<H', data[offset:offset+2])[0]
|
||||
|
||||
def parse_script_commands(data, start_offset, end_offset):
|
||||
"""Парсит скриптовые данные от start_offset до end_offset"""
|
||||
results = []
|
||||
offset = start_offset
|
||||
|
||||
while offset < end_offset:
|
||||
value = read_uint16(data, offset)
|
||||
results.append({
|
||||
'offset': offset,
|
||||
'value': value,
|
||||
'is_command': (value & 0x8000) != 0
|
||||
})
|
||||
offset += 2
|
||||
|
||||
return results
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python script.py <file_path>")
|
||||
sys.exit(1)
|
||||
|
||||
file_path = sys.argv[1]
|
||||
|
||||
# Читаем файл
|
||||
with open(file_path, 'rb') as f:
|
||||
data = f.read()
|
||||
|
||||
# Читаем заголовок
|
||||
header = {
|
||||
'script_pointers_offset': read_int16(data, 0),
|
||||
'script_start_offset': read_int16(data, 2),
|
||||
'text_pointers_offset': read_int16(data, 4),
|
||||
'text_start_offset': read_int16(data, 6)
|
||||
}
|
||||
|
||||
# Вычисляем количество указателей
|
||||
script_count = (header['script_start_offset'] - header['script_pointers_offset']) // 2
|
||||
text_count = (header['text_start_offset'] - header['text_pointers_offset']) // 2
|
||||
|
||||
# Читаем указатели скриптов
|
||||
script_pointers = []
|
||||
for i in range(script_count):
|
||||
offset = header['script_pointers_offset'] + i * 2
|
||||
ptr = read_uint16(data, offset)
|
||||
abs_offset = header['script_start_offset'] + ptr
|
||||
script_pointers.append(abs_offset)
|
||||
|
||||
# Добавляем фиктивный указатель на конец области скриптов (до текстовых данных)
|
||||
script_pointers.append(header['text_start_offset'])
|
||||
|
||||
# Формируем имя выходного файла
|
||||
output_file = file_path + '.txt'
|
||||
|
||||
with open(output_file, 'w', encoding='utf-8') as out:
|
||||
for i in range(script_count):
|
||||
start = script_pointers[i]
|
||||
end = script_pointers[i + 1]
|
||||
|
||||
# Пишем заголовок указателя
|
||||
out.write(f"{i:02X}:\n")
|
||||
|
||||
# Парсим команды на этом участке
|
||||
offset = start
|
||||
while offset < end:
|
||||
value = read_uint16(data, offset)
|
||||
|
||||
if value & 0x8000: # Это команда
|
||||
cmd_id = value & 0xFF
|
||||
cmd_desc = COMMANDS.get(cmd_id, "")
|
||||
out.write(f" cmd_{cmd_id:02X} // {cmd_desc}\n")
|
||||
else: # Это данные
|
||||
out.write(f" {value:04X}\n")
|
||||
|
||||
offset += 2
|
||||
|
||||
print(f"Done! Output saved to: {output_file}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user