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.

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: (File size - String block size) or ((String count * 12) + 8). When re-assembling script files, it is important to keep the string ID numbers identical to the source files’, otherwise the game will crash.

$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);


Info

My name is Derrick Sobodash.

I live in Beijing, China, where I work as a professional copy editor and freelance journalist. My articles have appeared in The Oakland Press, Beijing Today and PiQ.

You may contact me for any reason at derrickļ¼ cinnamonpirate.com or find me on Facebook and Flickr.

Photostream

DSC_0024-DSC_0020-DSC_0019-DSC_0015-DSC_0007-The world is ending at HujialouUnder the Guomao side streetUnder the Dabeiyao junctionThird Ring Road at CBDBridge in Tuanjiehu ParkOutside the apartmentMorning clouds