Jump to content

[nds] Monster tale text tool


katashi
Go to solution Solved by LinkOFF,

Recommended Posts

Hello, I want to translate the game monster tale into my language
The text structure is quite simple

header 8 bytes,
- filesize-(something) 4byte,
- pointers counter, 4byte
- pointers table, 4byte * counter
mt1.png
mt2.png

But editing manually will be very difficult and I'm not good at programming to write a program for it

Someone please help me, thank you very much

Note: i found the tool on this site: https://gbatemp.net/threads/trying-to-enable-hidden-unavailable-language-modes-in-nds-games.558533/page-2 but it only supports cp-1252, but i need utf 16 LE because cp-1252 won't be enough

loctext_IntroCutscene_ENG_US.zip

Edited by katashi
Link to comment
Share on other sites

  • Engineer
  • Solution
Spoiler
import os
import sys
import struct

def writeInt32(f, val):
    f.write((val).to_bytes(4, byteorder='little'))
    
def readInt32(f):
    return struct.unpack('<i', f.read(4))[0]
    
def writeString(f, string):
    f.write(string.encode('utf-16le'))
    f.write(b'\x00\x00')

def readString(f, pos):
    cur = f.tell()
    f.seek(pos)
    cstr = bytearray()
    while True:
        ch = f.read(2)
        if(ch == b'\x00\x00'):
            f.seek(cur)
            return str(cstr, "utf-16")
        cstr.extend(ch)
        

def extract(file):
    f = open(file, 'rb')
    magic, start, length, num = struct.unpack('<4I', f.read(16))
    text = ''
    for i in range(0, num):
        text += '%s\n' % readString(f, readInt32(f)).replace('\n', '<lf>')
    f.close()
    f = open('%s.txt' % file, 'w', encoding='utf-8')
    f.write(text)
    f.close()
    
def build(file):
    f = open(file, 'r', encoding='utf-8')
    lines = f.readlines()
    f.close()
    f = open(os.path.splitext(file)[0], 'wb')
    f.seek(16 + (len(lines) * 4)) # calculate string table start offset and slice to it
    offsets = []
    for line in lines: # store offsets and write lines itself
        offsets.append(f.tell())
        writeString(f, line.strip('\n').replace('<lf>', '\n'))
    length = f.tell() - 0xC # for header
    # write header + offsets
    f.seek(0)
    writeInt32(f, 0x54434C)
    writeInt32(f, 0xC)
    writeInt32(f, length)
    writeInt32(f, len(lines))
    for offset in offsets:
        writeInt32(f, offset)
    f.close()
    
    
#extract('loctext_IntroCutscene_ENG_US.bin_')
#build('loctext_IntroCutscene_ENG_US.bin.txt')

 

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...