Data Ram (.drm)
Data ram files are containers for storing sections. Sections are often memory of structures, but can also contain asset such as textures, animations and audio.
Note
This page currently only talks about the format in Tomb Raider Legend, however the concepts are the same across all games.Format
The file starts with the SectionList
header containing all section headers. It will follow by every section in the same order as the header,
with relocations first and the data after.
struct SectionInfo
{
int32_t size; // Size of the section data, this is without relocations
uint8_t sectionType;
uint8_t pad;
uint16_t versionID;
uint32_t packedData; // See below
uint32_t id; // If section is an asset, then this is the asset ID
uint32_t specMask;
}
struct SectionList
{
int32_t version; // 14 in Legend
int32_t numSections;
SectionInfo sections[numSections];
}
The packedData
member is a bitfield, the last 24 bits are the number of relocations.
auto numRelocations = packedData >> 8;
Relocations
Sections loaded into memory can contain pointers, these will be relocated by the game during loading. Relocations are located before the data.
struct Relocation
{
struct {
int16_t type: 3
int16_t sectionIndexOrType : 13;
} typeAndSectionInfo;
int16_t typeSpecific;
uint32_t offset;
}
Relocation relocations[packedData.numRelocations]
For each pointer there is a relocation, the sectionIndexOrType
member contains the target section. The offset
member is the offset the data the pointer should be relocated.
An example of this is:
auto pointer = (int*)(curSectionAddr + relocation->offset);
// Get the offset of the pointer
auto offset = *addr;
// Patch the pointer by adding the base of the other section
*addr = targetSectionAddr + offset;
An example implementation can be found here.
Section types
Normal sections are just loaded into memory. Other section types are processed additionally, such as textures being loaded into the GPU.
# | Section type |
---|---|
0 | General |
1 | Empty |
2 | Animation |
3 | Pushbuffer |
4 | Pushbuffer |
5 | Texture |
6 | Wave |
7 | DTPData |
8 | Script (unused) |
9 | ShaderLib |