Added parsing of dem_stringtables
This commit is contained in:
parent
2ed3320b84
commit
6304643a89
@ -98,6 +98,56 @@ void ParsePacket(uint8_t* packet, size_t length, SourceGameContext& context, IDe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReadStringTable(bf_read& bitbuf)
|
||||||
|
{
|
||||||
|
std::vector<uint8_t> data;
|
||||||
|
size_t numEntries = bitbuf.ReadWord();
|
||||||
|
char entryName[4096];
|
||||||
|
while (numEntries--)
|
||||||
|
{
|
||||||
|
bitbuf.ReadString(entryName, sizeof(entryName));
|
||||||
|
printf("%s ", entryName);
|
||||||
|
if (bitbuf.ReadOneBit() != 0)
|
||||||
|
{
|
||||||
|
size_t numDataBytes = bitbuf.ReadWord();
|
||||||
|
data.resize(numDataBytes);
|
||||||
|
bitbuf.ReadBytes(data.data(), numDataBytes);
|
||||||
|
printf("bytes %i ", numDataBytes);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
if (bitbuf.ReadOneBit() == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while (numEntries--)
|
||||||
|
{
|
||||||
|
bitbuf.ReadString(entryName, sizeof(entryName));
|
||||||
|
printf("%s ", entryName);
|
||||||
|
if (bitbuf.ReadOneBit() != 0)
|
||||||
|
{
|
||||||
|
size_t numDataBytes = bitbuf.ReadWord();
|
||||||
|
data.resize(numDataBytes);
|
||||||
|
bitbuf.ReadBytes(data.data(), numDataBytes);
|
||||||
|
printf("bytes %i ", numDataBytes);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParseStringTables(uint8_t* stringtables, size_t length, SourceGameContext& context, IDemoWriter* writer)
|
||||||
|
{
|
||||||
|
bf_read bitbuf(stringtables, length);
|
||||||
|
size_t numTables = bitbuf.ReadByte();
|
||||||
|
char tablename[256];
|
||||||
|
while (numTables--)
|
||||||
|
{
|
||||||
|
bitbuf.ReadString(tablename, sizeof(tablename));
|
||||||
|
printf("stringtable %s\n", tablename);
|
||||||
|
ReadStringTable(bitbuf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DemoReader::ProcessDem(void* inputFp, IDemoWriter* writer)
|
void DemoReader::ProcessDem(void* inputFp, IDemoWriter* writer)
|
||||||
{
|
{
|
||||||
CreateNetMsgStructs();
|
CreateNetMsgStructs();
|
||||||
@ -113,21 +163,25 @@ void DemoReader::ProcessDem(void* inputFp, IDemoWriter* writer)
|
|||||||
democmdinfo_t cmdInfo;
|
democmdinfo_t cmdInfo;
|
||||||
CommandPacket packet;
|
CommandPacket packet;
|
||||||
packet.cmdInfo = &cmdInfo;
|
packet.cmdInfo = &cmdInfo;
|
||||||
std::vector<uint8_t> buffer;
|
std::unique_ptr<uint8_t[]> buffer(new uint8_t[NET_MAX_PAYLOAD]);
|
||||||
buffer.resize(NET_MAX_PAYLOAD);
|
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
size_t rawDataSize = 0;
|
size_t rawDataSize = 0;
|
||||||
reader.ReadCmdHeader(packet.cmd, packet.tick);
|
reader.ReadCmdHeader(packet.cmd, packet.tick);
|
||||||
|
if (packet.cmd == dem_packet || packet.cmd == dem_signon)
|
||||||
|
{
|
||||||
|
reader.ReadCmdInfo(*packet.cmdInfo);
|
||||||
|
reader.ReadSequenceInfo(packet.sequenceInfo1, packet.sequenceInfo2);
|
||||||
|
assert(packet.sequenceInfo1 == packet.sequenceInfo2);
|
||||||
|
}
|
||||||
|
|
||||||
|
writer->StartCommandPacket(packet);
|
||||||
switch (packet.cmd)
|
switch (packet.cmd)
|
||||||
{
|
{
|
||||||
case dem_signon:
|
case dem_signon:
|
||||||
case dem_packet:
|
case dem_packet:
|
||||||
reader.ReadCmdInfo(*packet.cmdInfo);
|
rawDataSize = reader.ReadRawData(buffer.get(), NET_MAX_PAYLOAD);
|
||||||
reader.ReadSequenceInfo(packet.sequenceInfo1, packet.sequenceInfo2);
|
ParsePacket(buffer.get(), rawDataSize, context, writer);
|
||||||
assert(packet.sequenceInfo1 == packet.sequenceInfo2);
|
|
||||||
rawDataSize = reader.ReadRawData(buffer.data(), buffer.size());
|
|
||||||
break;
|
break;
|
||||||
case dem_synctick:
|
case dem_synctick:
|
||||||
// nothing
|
// nothing
|
||||||
@ -149,17 +203,17 @@ void DemoReader::ProcessDem(void* inputFp, IDemoWriter* writer)
|
|||||||
// TODO assert frame and tick numbers
|
// TODO assert frame and tick numbers
|
||||||
break;
|
break;
|
||||||
case dem_stringtables:
|
case dem_stringtables:
|
||||||
reader.ReadRawData(nullptr, 0);
|
{
|
||||||
|
uint8_t* stringtables = reinterpret_cast<uint8_t*>(malloc(MAX_STRINGTABLE_DATA));
|
||||||
|
size_t length = reader.ReadRawData(stringtables, MAX_STRINGTABLE_DATA);
|
||||||
|
ParseStringTables(stringtables, length, context, writer);
|
||||||
|
free(stringtables);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
writer->StartCommandPacket(packet);
|
|
||||||
if (packet.cmd == dem_packet || packet.cmd == dem_signon)
|
|
||||||
{
|
|
||||||
ParsePacket(buffer.data(), rawDataSize, context, writer);
|
|
||||||
}
|
|
||||||
writer->EndCommandPacket();
|
writer->EndCommandPacket();
|
||||||
} while (packet.cmd != dem_stop);
|
} while (packet.cmd != dem_stop);
|
||||||
writer->EndWriting();
|
writer->EndWriting();
|
||||||
|
@ -44,5 +44,7 @@ enum constants
|
|||||||
SIGNONSTATE_PRESPAWN = 4, // received signon buffers
|
SIGNONSTATE_PRESPAWN = 4, // received signon buffers
|
||||||
SIGNONSTATE_SPAWN = 5, // ready to receive entity packets
|
SIGNONSTATE_SPAWN = 5, // ready to receive entity packets
|
||||||
SIGNONSTATE_FULL = 6, // we are fully connected, first non-delta packet received
|
SIGNONSTATE_FULL = 6, // we are fully connected, first non-delta packet received
|
||||||
SIGNONSTATE_CHANGELEVEL = 7 // server is changing level, please wait
|
SIGNONSTATE_CHANGELEVEL = 7, // server is changing level, please wait
|
||||||
|
|
||||||
|
MAX_STRINGTABLE_DATA = 524288 // 2^19
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user