Skip to content

Instantly share code, notes, and snippets.

@heksesang
Last active April 27, 2022 08:52
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save heksesang/fdda3e4f8a5ed53b71ed to your computer and use it in GitHub Desktop.
010 Template for CASC encoding file.
//--------------------------------------
//--- 010 Editor v6.0.2 Binary Template
//
// File: CascEncoding.bt
// Author: Gunnar Lilleaasen
// Revision: 1.0
// Purpose: Parsing CASC encoding files.
//--------------------------------------
// Headers
struct header
{
char signature[2];
char unk1;
char checksumSizeA;
char checksumSizeB;
LittleEndian();
uint16 flagsA;
uint16 flagsB;
BigEndian();
uint32 hashTableSizeA;
uint32 hashTableSizeB;
char unk2;
uint32 stringTableSize;
};
header head;
// Encoding profiles
struct encodingprofile
{
string str;
};
local int position = FTell();
while (FTell() < position + head.stringTableSize)
{
encodingprofile profile;
}
// Checksum blocks
struct checksumblock(uint32 checksumSize)
{
char fileHash[checksumSize];
char blockHash[checksumSize];
};
local int i;
for (i = 0; i < head.hashTableSizeA; ++i)
{
checksumblock checksumsA(head.checksumSizeA);
}
// Key blocks
struct keyblockentry(uint32 checksumSize)
{
LittleEndian();
uint16 keyCount;
BigEndian();
uint32 fileSize;
LittleEndian();
char fileHash[checksumSize] <optimize=true>;
char fileKey[keyCount*checksumSize] <optimize=true>;
};
position = FTell();
local int remaining = 0;
local ushort keyCount = 0;
while (FTell() < position + 4096 * head.hashTableSizeA)
{
remaining = 4096 - (FTell() - position) % 4096;
keyCount = ReadUShort();
if (keyCount == 0)
{
FSkip(remaining);
continue;
}
keyblockentry keysA(head.checksumSizeA);
}
// Second checksum and key blocks
struct keyblockentry2(uint32 checksumSize)
{
char key[checksumSize];
BigEndian();
uint32 profileIndex;
char unk;
uint32 fileSize;
};
string ProfileComment( keyblockentry2 &block )
{
return profile[block.profileIndex].str;
}
for (i = 0; i < head.hashTableSizeB; ++i)
{
checksumblock checksumsB(head.checksumSizeB);
}
position = FTell();
local int secondEntryCount = 0;
remaining = 0;
while (FTell() < position + 4096 * head.hashTableSizeB)
{
remaining = 4096 - (FTell() - position) % 4096;
if (remaining < 25 || ReadUInt(FTell() + head.checksumSizeB) == -1)
{
FSkip(remaining);
continue;
}
keyblockentry2 keysB(head.checksumSizeB) <comment=ProfileComment>;
}
// Encoding profile for encoding file
encodingprofile encodingFile;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment