Crystal Beans from Dungeon Explorer/Cutscene Text Compression: Difference between revisions

From Data Crystal
Jump to navigation Jump to search
(Created page)
 
m (Added a link to the tutorial section on removing the compression)
Line 25: Line 25:
}
}
</pre>
</pre>
==See also==
* [[Crystal Beans From Dungeon Explorer:Tutorials#Removing the cutscene text compression|Removing the cutscene text compression]]

Revision as of 18:23, 17 January 2012

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
  }
}

See also