Skip to content

TALK.DAT

ProgSys edited this page Jul 6, 2024 · 69 revisions

Contains scripts, mainly for cut scenes. Is located at SUBDATA.DAT->START.DAT , START.DAT needs to be decompressed first.

Original work has been done by Krisan Thyme by his Toolpack.

File structure

Header

Type Size Description
uInt 4 byte Number of scripts
uInt 4 byte Number of scripts again

For each script (32 byte):

Type Size Description
uInt 4 byte Start address (The header size is not counted, therefore is first value is 0)
uInt 4 byte The script id
uShort 2 byte DungeonId
uShort 2 byte Unknown Search Flag (mostly 0-2, 102-111)
uShort 2 byte Game state filter positive size (from 0-4)
uShort 2 byte Game state filter negative size (from 0-4)
uShort 2 byte Game state filter positive 0
uShort 2 byte Game state filter positive 1
uShort 2 byte Game state filter positive 2
uShort 2 byte Game state filter positive 3
uShort 2 byte Game state filter negative 0
uShort 2 byte Game state filter negative 1
uShort 2 byte Game state filter negative 2
uShort 2 byte Game state filter negative 3

To find the size of each talk script, subtract the start address of the next script from the start address of the current script.

How a script is chosen by the game

The game chooses a script based on a combination of ID, Dungeon ID, and some Unknown Flag. Afterwards the game checks the current state of the game (probably from the save file), but only if any are given, i.e the size is bigger 0. If these checks pass, then the script is chosen. Otherwise it searches until it finds one.

The positive filter tests if a bit is set, while the negative tests if a bit is not set. The first 3 bits of "game state filter" are used to create a bit mask for checking against a global game state, determined by the rest of the bits:

struct DisaGameStateFilter {
    unsigned short bitIndex: 3; //the bit that should be tested (same as x & 7)
    unsigned short index: 13; //the index of a gamestate (same as  x >> 3)
    inline unsigned short getIndex() const noexcept { return index; } 
    inline byte getMask() const noexcept { return 1 << bitIndex; }
};

const byte mask = gameStateFilter.getMask(); // Create a bit mask (0-7)
const byte state = (globalStateStartPtr)[gameStateFilter.getIndex()]; // Get the state to check
return (state & mask) != 0; // Positive: When true then script is valid
return (state & mask) == 0; // Negative: When true then script is valid

Known Flags

Name Index Bit Description
Skip Story 275 0 When set then the story at the beginning of a stage should be skipped

Scripts

Two script languages are used: TALK and SCRIPT. Each has its own unique commands, though some commands are shared between them. They serve different purposes in the game:

  • TALK: Manages dialogue and serves as an entry point to game levels.
  • SCRIPT: Handles a broader range of in-game functions and effects.

What TALK can do

  • Play dialog in the game
  • Show character images and animations
  • Opening menus like the area select, shop, assembly, etc
  • Execute scripts from SCRIPT.DAT

What TALK can not do

  • Controll the camera
  • Spawn units on map and play there animations (for cutscenes)
  • Control sounds and background musik

All other effects are achived with the scripts within SCRIPT.DAT.

Commands overview

Each command consists of a op code (byte) and a body with arguments.

Name Op Code Arguments Arguments Size Description
Dialog 01 Display string in Shift JIS. x + 1 byte Display dialog
Confirm 03 Wait for user to confirm 0 byte
CharLeft 04 Char slot, uShort image effects 2 + 3 byte Display image in slot at left.
Portrait 05 Character portrait Id 2 byte Character portrait to display
Voice 06 Id of dialog 2 byte Play character dialog
SpeechBubble 07 Bubble type, arrow position 1 + 1 byte The style of pop speech bubble.
NameLabel 08 uShort name id, Char label position 2 + 1 byte Display name lable
Set 09 Set a game state flag 3 byte Set a bit in game state
Clear 0A Clear a game state flag 3 byte Clear a bit in game state
Script 0B Id of script from SCRIPT.DAT 3 byte Exectue script form SCRIPT.DAT
Call 0C Id of talk script 3 byte Exectue another talk script
ShowBox C9 Type? 1 byte Will open a box?
CharRight 18 Char slot, uShort image effects 2 + 3 byte Display image in slot at right.
CharMid 0E Char slot, uShort image effects 2 + 3 byte Display image in slot at center.
LoadImg 64 slot * 10000 + BUImageId 3 byte Load a BU** Image into a slot.
Select 14 If it is the first select, then it must follow by a number of menu options, else it has no arguments 1 byte Defines a conversation selection entry, a dialog command must follow directly afterwards. If it the first entry then it also must define the number of total entrys.
EndSelect FD None Marks the end of conversation selection.

Commands detailed overview

Dialog

  • Op Code: 01
  • Construction: 01 XX XX 00
  • Arguments: Zero terminating string in Shift JIS.

Display the given string inside the text box. The string must be provided in Shift_JIS and be terminated by a 0 byte.

LoadImg

  • Op Code: 64
  • Construction: 64 00 00 00
  • Argument: slot * 10000 + BUImageId (3 byte)

Before an character image can be used it must be loaded into a slot so it can be refereced later. LoadImg takes one argument that is the BU** image id, plus the slot times 10000: slot * 10000 + BUImageId. For example, 50103, will load BU0103.TX2 (angry Laharl) from DATA.DAT into slot 5. The image is loaded asynchronous. If you attempt to use an image from a slot that has not been properly loaded, the game will crash! Thus call script(0); to force the game to wait for the image to be loaded.

CharLeft/CharMid/CharRight

  • Op Code: 04/0E/18
  • Construction: 04/0E/18 00 11 11
  • Arguments: Slot Id (2 byte), Image effects (3 byte)

Display image in slot at position defined by op code. Image must have been fully loaded with LoadImg otherwise the game will crash. Image effects seem to do nothing.

SpeechBubble

  • Op Code: 07
  • Construction: 07 00 11
  • Arguments: Bubble type (1 byte), Arrow position (1 byte)

Defines the style and position of the arrow of the character that is speeking.

Bubble types: * 1: Normal * 2: Shouting * 3: Inner thoght

The arrow position is defined from left to right with the corresponding values 1 to 4. Some bubble types don't support arrows.

NameLabel

  • Op Code: 08
  • Construction: 08 00 00 11
  • Arguments: Name Id (2 byte), Label position (1 byte)

Display a name tag at given position. The position is defined from left to right with the corresponding values 1 to 4. If Id is -1 or position is out of bounds then name tag will not be displayed.

Script

  • Op Code: 0B
  • Construction: 0B 00 00 00
  • Arguments: Script Id (3 byte)

Execute a script from SCRIPT.DAT. The script will run asynchronous. To wait for the script to finish call script with id 0: script(0);. A script from SCRIPT.DAT is used to control the camera, spawn cutscene characters, play sound effects and more.

Call

  • Op Code: 0C
  • Construction: 0C 00 00 00
  • Arguments: Talk script Id (3 byte)

Execute a script from TALK.DAT. The script will not run asynchronous.

OLD TEXT

Each command is identified by exacly one byte. Then commands are then followed by x number of arguments. In most cases its just one.

List of shared commands between TALK and PROGRAMM:

Name Op Code Arguments Arguments Size Description
Set 09 Game state filter 2 byte (uShort) Set a bit in game state flags
Clear 0A Game state filter 2 byte (uShort) Clears a bit in game state flags
Script 0B PROGRAMM Id to call 3 byte (uInt) Runs the PROGRAMM script
Call 0C TALK Id to call, opcode (type of script?) 2 byte (uShort), 1 byte (Enum) Runs a TALK script
Return FF None End of script. Must follow by a script call to Id 0?

Exculusive commands to PROGRAMM:

Generall construction: Op Code, Size of Body, Arguments

Name Op Code Size of Body Arguments Arguments Size Description
Play BGM 91 2 BGM Index, Volume(0-128) 1 byte, 1 byte Will start playing background music (BGM). Index is equivalent to the file name in DATA.DAT, for instance "BGM003" is the castle theme.

Exculusive commands to TALK:

Name Op Code Arguments Arguments Size Description
PopUp 07 Pop up window style 2 byte (uShort) The style of pop up window. Must be closed by 'EndPopUp'.
ShowBox C9 Type? 1 byte Will open a box?
Portrait 05 Character portrait Id 2 byte (uShort) Character portrait to display
LoadImg 64 Load a BU** Image into a slot. (arg = slot * 10000 + BUImageId) 3 byte (UInt) Before a character image can be used it must be loaded into a slot to be referenced later. Example: 50103, will load BU0103.TX2 (angry Laharl) from DATA.DAT into slot 5.
CharLeft 04 Char (1 byte) slot, uShort image effects 3 byte (Char) + (uShort) Display image in slot at left.
CharMid 0E Char (1 byte) slot, uShort image effects 3 byte (Char) + (uShort) Display image in slot at center.
CharRight 18 Char (1 byte) slot, uShort image effects 3 byte (Char) + (uShort) Display image in slot at right.
NameLabel 08
Voice 06 Id of a sound clip 2 byte (uShort) Will play a sound clip, usually character dialog
Dialog 01
Confirm 02
EndPopUp 03 Defines the end of the Pop Up dialog
Select 14 If it is the first select, then it must follow by a number of menu options, else it has no arguments 1 byte (UChar) Defines a conversation selection entry, a dialog command must follow directly afterwards. If it the first entry then it also must define the number of total entrys.
EndSelect FD None Marks the end of conversation selection.

Clone this wiki locally