Ir para conteúdo
Faça parte da equipe! (2024) ×
Conheça nossa Beta Zone! Novas áreas a caminho! ×
  • Quem está por aqui   0 membros estão online

    • Nenhum usuário registrado visualizando esta página.

Python Script for Strdef.bin editor


aakarsh98
 Compartilhar

Posts Recomendados

import struct
import tkinter as tk
from tkinter import filedialog, messagebox, simpledialog, ttk

# Constants
NUM_STRINGS = 2000
CHARS_PER_STRING = 128

# Read the binary file and return list of strings
def read_strdef_bin(filepath):
    with open(filepath, 'rb') as f:
        data = f.read(NUM_STRINGS * CHARS_PER_STRING)
    strings = [data[i*CHARS_PER_STRING:(i+1)*CHARS_PER_STRING].decode('latin1').rstrip('\x00') for i in range(NUM_STRINGS)]
    return strings

# Write the list of strings back to binary format
def write_strdef_bin(filepath, strings):
    with open(filepath, 'wb') as f:
        for s in strings:
            encoded = s.encode('latin1')[:CHARS_PER_STRING]
            padded = encoded + b'\x00' * (CHARS_PER_STRING - len(encoded))
            f.write(padded)

# GUI application class
class StrDefEditorApp:
    def __init__(self, root):
        self.root = root
        self.root.title("STRDEF.BIN Editor")
        self.file_path = ""
        self.strings = []

        self.create_widgets()

    def create_widgets(self):
        frame = ttk.Frame(self.root)
        frame.pack(fill='both', expand=True)

        self.listbox = tk.Listbox(frame, font=('Courier', 10))
        self.listbox.pack(side='left', fill='both', expand=True)
        self.listbox.bind('<<ListboxSelect>>', self.edit_string)

        scrollbar = tk.Scrollbar(frame)
        scrollbar.pack(side='right', fill='y')
        self.listbox.config(yscrollcommand=scrollbar.set)
        scrollbar.config(command=self.listbox.yview)

        menubar = tk.Menu(self.root)
        filemenu = tk.Menu(menubar, tearoff=0)
        filemenu.add_command(label="Open", command=self.open_file)
        filemenu.add_command(label="Save", command=self.save_file)
        menubar.add_cascade(label="File", menu=filemenu)
        self.root.config(menu=menubar)

    def open_file(self):
        path = filedialog.askopenfilename(filetypes=[("BIN files", "*.bin")])
        if not path:
            return
        self.file_path = path
        self.strings = read_strdef_bin(path)
        self.listbox.delete(0, tk.END)
        for i, s in enumerate(self.strings):
            self.listbox.insert(tk.END, f"{i:04}: {s}")

    def save_file(self):
        if not self.file_path or not self.strings:
            return
        write_strdef_bin(self.file_path, self.strings)
        messagebox.showinfo("Saved", "Changes saved to file.")

    def edit_string(self, event):
        selection = self.listbox.curselection()
        if not selection:
            return
        index = selection[0]
        old_value = self.strings[index]
        new_value = simpledialog.askstring("Edit String", f"Edit string at index {index}:", initialvalue=old_value)
        if new_value is not None:
            self.strings[index] = new_value
            self.listbox.delete(index)
            self.listbox.insert(index, f"{index:04}: {new_value}")

# Run the app
def run_app():
    root = tk.Tk()
    app = StrDefEditorApp(root)
    root.mainloop()

run_app()
Link para o comentário
Compartilhar em outros sites

Participe da Conversa

Você pode postar agora e se cadastrar mais tarde. Cadastre-se Agora para publicar com Sua Conta.
Observação: sua postagem exigirá aprovação do moderador antes de ficar visível.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Responder

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.

 Compartilhar

×
×
  • Criar Novo...

Informação Importante

Nós fazemos uso de cookies no seu dispositivo para ajudar a tornar este site melhor. Você pode ajustar suas configurações de cookies , caso contrário, vamos supor que você está bem para continuar.