Repository navigation
MSBT
MSBT, short for Message Studio Binary Text is a file format used to store messages linked to labels. PylibMS offers several function used for dealing with these files. Currently, the LBL1, ATR1 and TXT2 blocks are the main ones supported.
from LMS.Message.MSBT import MSBT
from LMS.Stream.Reader import Reader
# Create the MSBT object
msbt = MSBT()
with open("Ballad.msbt", "rb+) as message:
# Create the reader object
reader = Reader(message.read())
# Read the MSBT
msbt.read(reader)Now, you can access several attributes of the MSBT object through, msbt.LBL1.labels, msbt.ATR1.attributes, and msbt.TXT2.messages.
index = msbt.LBL1.get_index_by_label("label_00")
attribute = msbt.ATR1.attributes[index]
message = msbt.TXT2.messages[index]# Provide the MSBP object when reading
msbt.read(reader, msbp)If an error occurs, the attributes will be reverted back to the default bytes object. Some games define attribute structure within a single MSBP but vary it.
Presets are generated python source files via a msbp that define functions for reading control tags. This allows for custom behavior and editing of what is parsed, and to provide more readability with tags. or to An example of a read function and write function in this preset is the following:
def read_System_Color(reader: Reader):
data = {}
data['r'] = reader.read_uint8()
data['g'] = reader.read_uint8()
data['b'] = reader.read_uint8()
data['a'] = reader.read_uint8()
return datadef write_System_Color(writer: Writer, data: dict):
writer.write_uint8(int(data['r']))
writer.write_uint8(int(data['g']))
writer.write_uint8(int(data['b']))
writer.write_uint8(int(data['a']))A preset can be generated for every function automatically using generate_preset_msbp function of the TXT2 class. In addition, the tag decoding mode must be set properly.
-
defaultuses near Kuriimu syntax[n0.4:],[n0.3:00-00-00-FF], -
presetcompletely decodes it completely.[System:PageBreak:],[System:Color r="0" g="0" b="0" a="255].
# Generate the preset
msbt.TXT2.generate_preset_msbt("example", msbp)
# Import the preset dictionary from the generated file.
from example import preset
msbt.TXT2.set_preset(preset)
# Read the MSBT with tag_decoding_mode set to preset
msbt.read(reader, msbp, tag_decoding_mode="preset")It is wise not to generate a new preset every time the program is ran to not overwrite the preset each launch.