Загрузка данных


import os
import json
import re

# Создаем папку для чистых JSON файлов
os.makedirs("json_output", exist_ok=True)

# Ищем читаемые строки латиницы (диалоги) от 4 символов
string_pattern = re.compile(b'[\x20-\x7E]{4,}')

# Список системного бреда, который мы отсекаем
blacklist = ["bg_", "flg_", "switch", "sure", "memory_", "EXPORT_", "init", "exit", "local", "UTC"]
total_files = 0

print("Прямая конвертация файлов .stcm2l в JSON...")

for file_name in os.listdir("."):
    if file_name.endswith(".stcm2l"):
        json_data = {}
        
        with open(file_name, "rb") as f:
            content = f.read()
            
        # Находим все строки в байтах
        matches = list(string_pattern.finditer(content))
        
        for match in matches:
            text_bytes = match.group(0)
            # Проверяем, есть ли там реальные буквы, а не просто знаки
            if any(c in text_bytes for c in b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'):
                try:
                    text_content = text_bytes.decode('utf-8', errors='ignore').strip()
                    
                    # Фильтруем системные коды
                    is_system = any(word in text_content for word in blacklist)
                    
                    if not is_system and len(text_content) > 1:
                        # Ключом делаем HEX-адрес в файле, значением - английский текст
                        hex_address = f"[0x{hex(match.start())[2:].upper()}]"
                        json_data[hex_address] = text_content
                except:
                    pass
        
        # Если в файле нашли текст диалогов, сохраняем JSON
        if json_data:
            total_files += 1
            output_name = os.path.join("json_output", file_name.replace(".stcm2l", ".json"))
            with open(output_name, "w", encoding="utf-8") as out_f:
                json.dump(json_data, out_f, ensure_ascii=False, indent=4)

print(f"Успешно! Сконвертировано файлов: {total_files}. Ищите их в папке 'json_output'")