User:Zarevak/GLM

Overview
GLM files are base data source files for Tabula Rasa. All textures (and icons), sounds, music, models, ... are stored in these files.

Basic structure
The GLM files consists of 4 parts
 * 1) data
 * 2) filenames table
 * 3) file allocation table (FAT)
 * 4) DWORD (4byte) pointer to FAT

FAT structure

 * 8-bytes long "CHNKBLXX" string - ID of the FAT?
 * DWORD pointer to filenames table
 * DWORD size (in bytes) of the filenames table
 * DWORD count of the items in the filenames table
 * records for each file in the GLM file:
 * DWORD pointer to beginning of the file
 * DWORD size of the file in GLM file
 * DWORD uncompressed? size of the file
 * DWORD offset to the filenames table, where the filename string for this file begins (ends with NULL character)
 * SHORT (2bytes) flags?:
 * 0 - uncompressed data
 * 1 - compressed data? - only found in effects.glm file
 * DWORD unix timestamp - count of seconds from 00:00:00 UTC on January 1, 1970

Decoding

 * 1) Start by reading the last 4 bytes of the GLM file and move to the location it represents (offset from beginning of the file) = beginning FAT table
 * 2) read FAT header (ID, pointer to Filenames table, size of filenames table, filecount)
 * 3) read the whole filenames table into memory
 * 4) for each file (count from the FAT header):
 * 5) read the next file information from FAT
 * 6) extract the filename from filename table - beginning is known from FAT, ends with NULL character
 * 7) extract the file data