Difference between revisions of "RwBinaryStream"

From GTAMods Wiki
Jump to navigation Jump to search
m
m
Line 12: Line 12:
 
to know when you have parsed all it's children by comparing the stream pointer to the address of the section
 
to know when you have parsed all it's children by comparing the stream pointer to the address of the section
 
RwHeader added to the sectionSize.
 
RwHeader added to the sectionSize.
 +
 +
===Example Code to read a Binary Stream===
 +
void * ReadSection(Stream * stream)
 +
{
 +
RwHeader header = ReadRwHeader(stream);
 +
 +
RwSection * section = CreateAppropriateSection(header.sectionType);
 +
 +
u8 * endOfSection = stream.GetPosition() + header.sectionSize;
 +
while(stream.GetPosition() < endOfSection)
 +
{
 +
section->AddChild(ReadSection( stream));
 +
}
 +
}
  
 
===RwType===
 
===RwType===

Revision as of 01:43, 29 May 2007


Reading Binary Streams

RwStreams are heirarchical streams of sections. Every section consists of:

  • (gauranteed) RwHeader
  • (gauranteed) RwData child section (the contents are specific to the section type, see definitions below.)
  • (optional) Children sections

The RwHeader contains the size (sectionSize member) of all the data and children (and their data and children). This allows you to either skip the entire section and it's children by advancing the stream pointer, or to know when you have parsed all it's children by comparing the stream pointer to the address of the section RwHeader added to the sectionSize.

Example Code to read a Binary Stream

void * ReadSection(Stream * stream)
{
	RwHeader header = ReadRwHeader(stream);
	
	RwSection * section = CreateAppropriateSection(header.sectionType);
	
	u8 * endOfSection = stream.GetPosition() + header.sectionSize;
	while(stream.GetPosition() < endOfSection)
	{
		section->AddChild(ReadSection( stream));
	}
}

RwType

enum
{
    rwDATA = 1,
    rwSTRING = 2,
    rwEXTENSION = 3,
    rwTEXTURE = 6,
    rwMATERIAL = 7,
    rwMATERIALLIST = 8,
    rwFRAMELIST = 14,
    rwGEOMETRY = 15,
    rwCLUMP = 16,
    rwLIGHT = 18,
    rwATOMIC = 20,
    rwTEXTURENATIVE = 21,
    rwTEXDICT = 22,
    rwGEOMETRYLIST = 26,
    rwMATERIALSPLIT = 124,
    rwFRAME = 39056126,
    rwPLUGIN_PARTICLES = 0x118,
    rwPLUGIN_MATERIALEFFECTS = 0x120,
    rwPLUGIN_BINMESH = 0x50e,
};

RwHeader

struct RwHeader
{
    s32 sectionType; // RwType
    s32 sectionSize;
    u8 unknown[2];
    s16 versionNumber;
};

Dff Files

Top level section is always a single RwClump.

RwClump section

VersionNumber(s) 0, 2048
  • Gauranteed
  • First and only data
struct RwClump_RwData
{
    s32 objectCount;
}; 
VersionNumber(s) 3074, 4099, 6147
  • Gauranteed
  • First data
struct RwClump_RwData
{
    s32 objectCount;
    u8 unknown[8];
};
  • Optional
  • Second and subsequent data
struct RwClump_RwData
{
    u8 unknown[4];
};

Txd Files

Top level section is always a single RwTexdict.