Skip to content

Offsets in STY files

robotanarchy edited this page Jan 8, 2015 · 2 revisions

In G2HR we want to display the original fonts in our custom menu. To load such fonts, one needs to parse the fstyle.sty file chunk by chunk (documentation). In order to verify that the chunk loader was working right, an offset table was generated.

Chunk offsets in fstyle.sty
Chunk: PPAL - Size: 0065536 - Delta: 0000006 - Offset: 0000006
Chunk: SPRB - Size: 0000012 - Delta: 0065544 - Offset: 0065550
Chunk: FONB - Size: 0000030 - Delta: 0000020 - Offset: 0065570
Chunk: PALX - Size: 0032768 - Delta: 0000038 - Offset: 0065608
Chunk: SPRG - Size: 0655360 - Delta: 0032776 - Offset: 0098384
Chunk: SPRX - Size: 0014128 - Delta: 0655368 - Offset: 0753752
Chunk: PALB - Size: 0000016 - Delta: 0014136 - Offset: 0767888
Simple offset finder
void sty_parser_find_chunks(char* buffer, uint32_t size)
{
    const char *GTA2_STY_CHUNK_NAMES [] =
        {"PALX", "PPAL","PALB","TILE",
        "SPRG","SPRX","SPRB","DELS","DELX","FONB","CARI",
        "OBJI","PSXT","RECY"};
    uint32_t last = 0;

    for(uint32_t i=0;i<size;i++)
    {
        for(int j=0;j<14;j++)
        {
            if(   buffer[i+0] != GTA2_STY_CHUNK_NAMES[j][0]
               || buffer[i+1] != GTA2_STY_CHUNK_NAMES[j][1]
               || buffer[i+2] != GTA2_STY_CHUNK_NAMES[j][2]
               || buffer[i+3] != GTA2_STY_CHUNK_NAMES[j][3]
            ) continue;

            uint32_t chunk_size = *(uint32_t*) (buffer + i + 4);

            printf("Chunk: %c%c%c%c ", buffer[i], buffer[i+1],
                buffer[i+2], buffer[i+3]);
            printf("- Size: %07i ", chunk_size);
            printf("- Delta: %07i ", i -last);
            printf("- Offset: %07i ", i);
            printf("\n");
            last = i;
        }
    }
}