Script directory

From Boktai Hacking Wiki
Revision as of 19:05, 6 August 2024 by Raphi (talk | contribs) (Created page with "The script directory (contained in the master file table) contains both bytecode scripts and strings used in the game. It's layout is different than the other directories in the MFT: <syntaxhighlight lang="c"> struct script_directory { u32 unknown; // 0x3ea8eae6 in Boktai 1 (U) script_entry script_entries[]; directory_offsets offsets; // string_index contains the start index (in string_data) for each string // NOTE: offsets.string_i...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The script directory (contained in the master file table) contains both bytecode scripts and strings used in the game. It's layout is different than the other directories in the MFT:

struct script_directory {
  u32 unknown;                   // 0x3ea8eae6 in Boktai 1 (U)
  script_entry script_entries[];

  directory_offsets offsets;

  // string_index contains the start index (in string_data) for each string
  // NOTE: offsets.string_index points here
  u32 string_index[(offsets.string_data-offsets.string_index)/4];
  // NOTE: offsets.string_data points here
  char string_data[];

  // NOTE: offsets.script_data points here
  u32 special_script_offset; // unknown...

  // NOTE: script_entry.offset is relative to here
  u8 bytecode[];

  // Unknown data, including the "special script"
  u8[?] unknown;
};

// Use one of these two structs for script_entry, depending on the game:

// sizeof(script_entry) == 8, (unknown and offset are packed into 1 word)
// script_entries[] array is null-terminated (ends when all fields are 0)
struct script_entry_boktai_1 {
  u32 id;          // script id
  u8 unknown : 8;
  u32 offset : 24;
};

// script_entries[] array is -1 terminated (ends when unknown = 0xff && offset == 0xffffff)
struct script_entry_boktai_2_and_3 {
  // id is implied (id = array index + 1)
  // Meaning the 1st script has ID 1, not ID 0!
  u8 unknown : 8;
  u32 offset : 24;
};

struct directory_offsets {
  // all offsets here are relative to the start of this struct
  u32 script_data;
  u32 string_index;
  u32 string_data;
  u32 unknown;     // offset to unknown data
};