Skip to content

Instantly share code, notes, and snippets.

@LiamKarlMitchell
Last active May 26, 2017 10:37
Show Gist options
  • Save LiamKarlMitchell/aa631f8229244601a3c26a647905c1a2 to your computer and use it in GitHub Desktop.
Save LiamKarlMitchell/aa631f8229244601a3c26a647905c1a2 to your computer and use it in GitHub Desktop.
Lithtech REZ file template for 010 Hex Editor.
//--------------------------------------
//--- 010 Editor v8.0 Binary Template
//
// File: Lithtech REZ File Version 1
// Author: MegaByte
// Revision: 1
// Purpose: To understand REZ Files.
//--------------------------------------
// TODO: Detect empty areas.
// TODO: Identify more parts of the Archive.
enum <unsigned int> EntryType { EntryType_File, EntryType_Directory };
local int newVersion = 1;
char[] Strrev(char input[]) {
local char temp;
local int len = Strlen(input);
char output[len];
local int halfLen = len/2;
local int i, k;
for(i = 0,k=len-1 ; i < halfLen+1; i++,k--)
{
output[k] = input[i];
output[i] = input[k];
}
return output;
}
typedef struct {
unsigned int ID;
char Ext[8];
string Name;
char Pad[2];
if (Length > 0) {
local int oldPosition = FTell();
FSeek(Offset);
byte Data[Length];
FSeek(oldPosition);
}
} RezFileEntry <size=SizeRezFileEntry,
name=RezFileEntry_GetName>;
char[] RezFileEntry_GetName( RezFileEntry& r )
{
return r.Name + "." + Strrev(r.Ext);
}
int SizeRezFileEntry( RezFileEntry &r )
{
return 14 + // Base Size + 1 byte pad.
ReadStringLength( startof(r) + 13 , header.Max_FileName ); // Read Name length.
}
struct RezEntry;
typedef struct {
char Name[header.Max_DirectoryName];
// Note: May have to use a stack here if a rez file has multiple directories inside each other, not sure on scoping of local variables.
if (Length > 0) {
local int oldPosition = FTell();
FSeek(Offset);
// Read this directories file entries.
while(FTell() < Offset + Length) {
RezEntry entries <optimize=false>;
}
FSeek(oldPosition);
}
} RezDirectoryEntry <size=SizeRezDirectoryEntry,
name=RezDirectoryEntry_GetName>;
string RezDirectoryEntry_GetName( RezDirectoryEntry& r ) {
return r.Name;
}
int SizeRezDirectoryEntry( RezDirectoryEntry &r )
{
return ReadStringLength( startof(r) , header.Max_DirectoryName ); // Read Name length.
}
struct RezEntry {
EntryType Type;
unsigned int Offset;
unsigned int Length;
time_t Date;
if (Type == EntryType_File) {
RezFileEntry file;
} else if (Type == EntryType_Directory) {
RezDirectoryEntry directory;
} else {
Warning("Unhandled RezEntry file type.");
}
};
struct REZ {
byte num; // 38
byte num2; // 35
// TODO: Assert values.
if (num == 13 && num2 == 10) {
newVersion = 0;
} else if (num == 38 && num2 == 35) {
newVersion = 1;
} else {
Warning( "Unknown Version encountered. Halt!" );
return -1;
}
char CreatedBy[60];
if (Strncmp(CreatedBy, "RezMgr Version 1 ", 17) != 0) {
Warning("Expecting RezMgr Version 1 in header.");
}
byte num3;
byte num4;
char Description[60];
if (newVersion) {
FSeek(195);
} else {
FSeek(127);
}
struct Header {
unsigned int Start_Vars;
unsigned int Root_Offset;
unsigned int Offset_Length;
unsigned int Blank1;
unsigned int Index_Offset;
time_t Date;
unsigned int Blank2;
unsigned int Max_DirectoryName;
unsigned int Max_FileName;
unsigned int Blank;
unsigned int Start;
} header;
FSeek(file.header.Root_Offset);
RezEntry rootEntry;
} file < bgcolor=0xFF00FF>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment