You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
139 lines
3.9 KiB
139 lines
3.9 KiB
|
2 years ago
|
class gbxReplay {
|
||
|
|
|
||
|
|
CHUNKS_OFFSET = 17;
|
||
|
|
HEADER_OFFSET = 21;
|
||
|
|
UNASSIGNED = 0xFFFFFFFF;
|
||
|
|
|
||
|
|
calcChunkOffset(num) {
|
||
|
|
return (((num) * 8) + this.HEADER_OFFSET)
|
||
|
|
}
|
||
|
|
|
||
|
|
isNumber(id) { return (((id) & 0xC0000000) == 0)}
|
||
|
|
isString(id) { return (((id) & 0xC0000000) != 0)}
|
||
|
|
isUnassigned(id) {return ((id) == this.UNASSIGNED)}
|
||
|
|
getIndex(id) {return ((id) & 0x3FFFFFFF)}
|
||
|
|
|
||
|
|
readIdentifier(buff, idList, outString, stringLen)
|
||
|
|
{
|
||
|
|
if ( idList.version < 3 ) {
|
||
|
|
idList.version = buff.readUInt32();
|
||
|
|
}
|
||
|
|
|
||
|
|
let id = buff.readUInt32();
|
||
|
|
if(this.isUnassigned(id)) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if(this.isNumber(id)){
|
||
|
|
console.log("number")
|
||
|
|
}
|
||
|
|
|
||
|
|
if(idList.version == 2) {
|
||
|
|
outString = buff.readString(stringLen)
|
||
|
|
console.log(outString)
|
||
|
|
}
|
||
|
|
|
||
|
|
if(this.isString(id) && this.getIndex(id) == 0) {
|
||
|
|
outString = buff.readString(stringLen)
|
||
|
|
|
||
|
|
console.log(outString)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
parseReplayChunk(buff, chunkInfo) {
|
||
|
|
buff.seek(0+chunkInfo.dwOffset);
|
||
|
|
let version = buff.readUInt32();
|
||
|
|
let isVSK = version >= 9999 ? true : false;
|
||
|
|
|
||
|
|
let idList = { version: 0, index: 0, list:[[]]}
|
||
|
|
|
||
|
|
if( chunkInfo.dwSize <= 4) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if((!isVSK && version >= 3) || (isVSK && version >= 10000)) {
|
||
|
|
let outString = "";
|
||
|
|
this.readIdentifier(buff, idList, outString, 512);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
parseAuthorChunk(buff, chunkInfo) {
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
parseCommunityChunk(buff, chunkInfo) {
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
parse(buff)
|
||
|
|
{
|
||
|
|
buff.seek(0+this.CHUNKS_OFFSET);
|
||
|
|
let numChunks = buff.readUInt32();
|
||
|
|
|
||
|
|
if(numChunks == 0) {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
else if (numChunks > 0xff) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
let chunkId, chunkSize = 0;
|
||
|
|
let chunkOffset = this.calcChunkOffset(numChunks)
|
||
|
|
let chunkVersion = {}
|
||
|
|
let chunkCommunity = {}
|
||
|
|
let chunkAuthor = {}
|
||
|
|
|
||
|
|
for (let counter = 1; counter <= numChunks; counter++) {
|
||
|
|
chunkId = buff.readUInt32();
|
||
|
|
chunkSize = buff.readUInt32();
|
||
|
|
|
||
|
|
chunkSize &= 0x7FFFFFFF;
|
||
|
|
|
||
|
|
switch (chunkId){
|
||
|
|
case 0x03093000: // (TM)
|
||
|
|
case 0x2403F000: // (VSK, TM)
|
||
|
|
chunkVersion.dwId = chunkId;
|
||
|
|
chunkVersion.dwSize = chunkSize;
|
||
|
|
chunkVersion.dwOffset = chunkOffset;
|
||
|
|
chunkOffset += chunkSize;
|
||
|
|
break;
|
||
|
|
case 0x03093001: // (TM)
|
||
|
|
case 0x2403F001: // (VSK, TM)
|
||
|
|
chunkCommunity.dwId = chunkId;
|
||
|
|
chunkCommunity.dwSize = chunkSize;
|
||
|
|
chunkCommunity.dwOffset = chunkOffset;
|
||
|
|
chunkOffset += chunkSize;
|
||
|
|
//OutputTextFmt(hwndCtl, szOutput, _countof(szOutput), g_szChunk, dwCouter, dwChunkId, dwChunkSize);
|
||
|
|
break;
|
||
|
|
|
||
|
|
case 0x03093002: // (MP)
|
||
|
|
chunkAuthor.dwId = chunkId;
|
||
|
|
chunkAuthor.dwSize = chunkSize;
|
||
|
|
chunkAuthor.dwOffset = chunkOffset;
|
||
|
|
chunkOffset += chunkSize;
|
||
|
|
//OutputTextFmt(hwndCtl, szOutput, _countof(szOutput), g_szChunk, dwCouter, dwChunkId, dwChunkSize);
|
||
|
|
break;
|
||
|
|
|
||
|
|
default:
|
||
|
|
chunkOffset += chunkSize;
|
||
|
|
//OutputTextFmt(hwndCtl, szOutput, _countof(szOutput), g_szChunk, dwCouter, dwChunkId, dwChunkSize);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (chunkVersion.dwSize > 0) {
|
||
|
|
this.parseReplayChunk(buff, chunkVersion);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (chunkCommunity.dwSize > 0) {
|
||
|
|
this.parseCommunityChunk(buff, chunkCommunity);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (chunkAuthor.dwSize > 0) {
|
||
|
|
this.parseAuthorChunk(buff, chunkAuthor);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
module.exports = gbxReplay;
|