Crystal Beans From Dungeon Explorer:Cutscene Text Compression

From Data Crystal
Revision as of 10:44, 9 January 2012 by Neige (talk | contribs) (Created page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Format

The cutscene text is slightly compressed in a format a bit similar to LZ.

There is a control byte for every 8 byte sequence, starting from the most significant bit, if the bit is set, 256 is added to the byte to form the character index described in the table. Another way to think of it is to consider the bits in the control byte as the 8th bit in the character index.

C Source

in is the input file pointer and out is the output file pointer. TableGetTextValue is the function to convert a character index to a character string.

int endLoop = 0;
int controlByte, curChar, tableIndex;

while(!endLoop) { // until the end of the string
  controlByte = fgetc(in);
  for (j = 0; j < 8; j++) { // for each bit in controlByte
    curChar = fgetc(in);
    tableIndex = curChar + ((controlByte & 0x80) ? 256 : 0); // if bit 7 is set, add 256
    fputs(TableGetTextValue(tableIndex), out);
    if (tableIndex == 0) { // char 0 is end-of-string
      endLoop = 1; // end-of-string, get out of while loop
      break; // get out of for loop
    }
    controlByte <<= 1; // get next bit
  }
}