Created
January 25, 2015 01:25
-
-
Save x1nixmzeng/57ae36e65e6612015859 to your computer and use it in GitHub Desktop.
IES binary template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-------------------------------------- | |
//--- 010 Editor v5.0 Binary Template | |
// | |
// File: IESv2.bt | |
// Author: WRS | |
// Revision: 2 | |
// Purpose: IES Database Parser | |
//-------------------------------------- | |
#include "prelen.bt" | |
#define ENABLE_IES_WARNINGS | |
//////////////////////////////////////////////////////////// | |
struct str_custom(int type) | |
{ | |
str _str(type); | |
}; | |
typedef str_custom cstr <read=GetCStrValue>; | |
string GetCStrValue(cstr &t) | |
{ | |
local string result = ""; | |
local int i = 0; | |
while(i<t._str.len) { | |
if(t._str.val[i]==0) break; | |
result += (char)(t._str.val[i] ^ 0x1); | |
++i; | |
} | |
return result; | |
} | |
//////////////////////////////////////////////////////////// | |
// File header | |
//////////////////////////////////////////////////////////// | |
struct HEADER | |
{ | |
str Filename(128); | |
uint int_val_1; | |
uint offset_hint_a; // subtract from file_size to get ptr | |
uint offset_hint_b; | |
uint file_size; | |
} | |
hdr; | |
#ifdef ENABLE_IES_WARNINGS | |
Assert( hdr.file_size == FileSize() ); | |
#endif | |
//////////////////////////////////////////////////////////// | |
// Data info | |
//////////////////////////////////////////////////////////// | |
struct INFO | |
{ | |
ushort short_val_1; // always 1? | |
ushort Rows; // number of rows | |
ushort Columns; // total number of int and string columns | |
ushort ColInt; // cols which are ints | |
ushort ColString; // cols which are strings | |
} | |
info; | |
#ifdef ENABLE_IES_WARNINGS | |
if(info.ColString + info.ColInt != info.Columns) | |
{ | |
Warning("Wrong number of column type descriptors"); | |
} | |
#endif | |
local uint OffsetColumns = hdr.file_size - (hdr.offset_hint_a+hdr.offset_hint_b); | |
local uint OffsetRows = hdr.file_size - hdr.offset_hint_b; | |
FSeek(OffsetColumns); | |
//////////////////////////////////////////////////////////// | |
// Column format | |
//////////////////////////////////////////////////////////// | |
enum<ushort> FmtType | |
{ | |
TYPE_INT = 0, | |
TYPE_STR = 1 | |
}; | |
struct | |
{ | |
local int count_int = 0; | |
local int count_str = 0; | |
Printf("%i Columns:\n", info.Columns); | |
struct Col | |
{ | |
//ushort unknown; | |
cstr Name1(64); | |
cstr Name2(64); | |
FmtType Type; | |
byte unknown[6]; | |
switch(Type) | |
{ | |
case TYPE_INT: ++count_int; break; | |
case TYPE_STR: ++count_str; break; | |
#ifdef ENABLE_IES_WARNINGS | |
default: Warning("Unknown column type"); | |
#endif | |
} | |
Printf("[%s] %s\n", EnumToString(Type), GetCStrValue(Name1)); | |
} col[info.Columns] <optimize=false>; | |
#ifdef ENABLE_IES_WARNINGS | |
Assert(count_int == info.ColInt); | |
Assert(count_str == info.ColString); | |
#endif | |
} | |
ColumnList; | |
#ifdef ENABLE_IES_WARNINGS | |
Assert(FTell() == OffsetRows); | |
#endif | |
//////////////////////////////////////////////////////////// | |
// Rows | |
// NOTE: Strings are sometimes scrambled differently from the xor | |
//////////////////////////////////////////////////////////// | |
struct | |
{ | |
struct Row | |
{ | |
int row_index; | |
cstr optional_str(plen16); | |
int IntPool[info.ColInt]; | |
cstr StringPool(plen16)[info.ColString] <optimize=false>; | |
// Not sure why these are there | |
FSkip(info.ColString); | |
} row[info.Rows] <optimize=false>; | |
} | |
RowList; | |
//////////////////////////////////////////////////////////// | |
// End of file | |
//////////////////////////////////////////////////////////// | |
#ifdef ENABLE_IES_WARNINGS | |
Assert(FEof()); | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment