Difference between revisions of "Relocatable chunk"

From GTAMods Wiki
Jump to navigation Jump to search
(Created page with "In GTA Liberty City Stories and Vice City Stories Rockstar Leeds used a reloctable chunk format for all types of data. struct base::sChunkHeader { uint32 ident; uint32...")
 
m
Line 72: Line 72:
 
(local) pointers, vtables and function pointers. These are described elsewhere.
 
(local) pointers, vtables and function pointers. These are described elsewhere.
  
[[Category:3D File Formats]]
+
[[Category:File Formats]]
 
[[Category:GTA LCS]]
 
[[Category:GTA LCS]]
 
[[Category:GTA VCS]]
 
[[Category:GTA VCS]]

Revision as of 15:01, 1 August 2017

In GTA Liberty City Stories and Vice City Stories Rockstar Leeds used a reloctable chunk format for all types of data.

struct base::sChunkHeader
{
	uint32 ident;
	uint32 shrink;
	uint32 fileEnd;
	uint32 dataEnd;
	uint32 relocTab;
	uint32 numRelocs;
	uint32 globalTab;
	uint16 numClasses;
	uint16 numFuncs;
};

Where ident is a character constant and shrink is a boolean that coincides with the game's decision to free the relocation tables after loading. It is checked together with the character constant but does otherwise not seem to be used directly for anything. In the following all offsets are from the beginning of the chunk header.

The different file types are:

ident shrink description
WRLD 0 level
GTAG 1 resource image/game data
mdl 0 3d model
tex 0 texture
anim 0 animation
col2 0 collision

FileEnd and DataEnd are offsets to the end of file and actual data respectively.

After the data comes a relocation table (at offset relocTab with numRelocs entries) that contains offsets to all pointers in the data. On load those pointers (stored as offsets in the file) are converted to pointers by adding to them the address of the loaded file in memory.

After the relocation table comes a table of class and function fixups (at offset globalTab with numClasses class fixups and numFuncs function fixups). The class values in the file are hashes of their class names and are replaced by pointers to the vtable on load. The function values are indices that are replaced by function pointers. Class fixups are used for the classes stored in game.dtz. Function fixups are used for atomic render callbacks.

The actual contents of the files are then just C(++) structures with relocated (local) pointers, vtables and function pointers. These are described elsewhere.