[facebook] [skype] [twitter]
[view] magnacarta-fpb.md [raw]
MIME: text/plain Modified: 2017/07/13 @ 11:19:57 File Size: 2.36KB

Magna Carta Script Format

Long ago in a galaxy far, far away, I was working on a translation of Magna Carta. I had to dump it because there are no Korean speakers on the Internet. The project was picked up by Talbain at Lakuuna, and I handed off all my tools to him.

When he finally got the script translated five years later, it turned out my earlier assessment of the game's FPB file format was incorrect. Since I had to go back and fix what I got wrong in 2001, it seemed worth my time to write up how the file format works here.

File Format

These files are used to store all the text for Magna Carta events and are tied to event numbers via string ID codes. Most of the time these increment from 1: sometimes they do not.

String count [4 bytes, long]
(string loop)
  ID number [4 bytes, long]
  Offset [4 bytes, long]
  Length [4 bytes, long]
(end loop)
String block size [4 bytes, long]
(data)

The first string always has an offset of 0. The offsets begin from position "0," which is at the end of the header. The fastest way to get this position is one of two calculations:

When re-assembling script files, it is important to keep the string ID numbers identical to the source files. If you do not, the game will crash.

Proof of Concept

Proof of method code is included below:

$fd = fopen ('0094.fpb', 'rb');
list($junk, $count) = unpack('V*', fread($fd, 4));
$id = array(); $offset = array(); $length = array();
for($i = 0; $i < $count; $i ++) {
  list($junk, $id[]) = unpack('V*', fread($fd, 4));
  list($junk, $offset[]) = unpack('V*', fread($fd, 4));
  list($junk, $length[]) = unpack('V*', fread($fd, 4));
}
$data = unpack('V*', fread($fd, 4));
$fo = fopen("0094.txt", "w");
for($i = 0; $i < $count; $i ++) {
  fseek($fd, $offset[$i] + ($count * 12) + 8, SEEK_SET);
  fputs($fo, "<" . $id[$i] . ">\n");
  $string = fread($fd, $length[$i]);
  fputs($fo, str_replace("\$n", "\n", $string));
  fputs($fo, "<>\n\n");
}
fclose($fo);
fclose($fd);

Copyright

Copyright (c) 2005 Derrick Sobodash. Some Rights Reserved.

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

[dir] Parent Directory
Directory