Oh shiet, I never knew what kind of pseudo C code that was, but today Serthy told me about the 010 Hex Editor. This is how the .iwi template code looks on a .iwi file:
It's extremly powerful to actually understand whats going on in binary data. You can execute C like code inside structs and even color the structs, as seen in image (header is blue, colorblocks are red).
I wish I had known this tool before :')
Edit:
IWI implementation for C++: https://github.com/DentonW/DevIL/blo...src/il_iwi.cpp
IWI format description by CptAsgard: https://github.com/CptAsgard/CoD2Uni...d2iwifiles.txt
IWI implementation in C#: https://github.com/CptAsgard/CoD2Uni...s/IWILoader.cs
I experimented a bit with 010 Editor, and this is what I added for IWI format (Enums and added the filesize/offsets in header):
PHP Code:
LittleEndian();
typedef float f32;
typedef double f64;
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef char i8;
typedef short i16;
typedef int i32;
local int DXTVERSION = 0;
enum <u8> Usage {
Color = 0x00,
Default = 0x01, // Fallback texture for engine
Skybox = 0x05
};
enum <u8> ImageFormat {
ARGB32 = 0x01,
RGB24 = 0x02,
GA16 = 0x03,
A8 = 0x04,
DXT1 = 0x0B,
DXT3 = 0x0C,
DXT5 = 0x0D
};
string comment_dxtformat(u8 dxtformat) {
//switch (dxtformat) {
// case 0x01: return "one";
// case 0x0d: return "DXT5";
//}
string buffer;
SPrintf(buffer, "whatever is %d", dxtformat);
return buffer;
}
//
typedef struct
{
SetBackColor( cLtBlue );
u8 start_I;
u8 start_W;
u8 start_i;
u8 version;
ImageFormat DXTformat <comment=comment_dxtformat>;
Usage flag;
u16 width;
u16 height;
u16 u3;
u32 filesize;
u32 offset_texture;
u32 offset_mipmap1;
u32 offset_mipmap2;
if( start_I != 73 || start_W != 87 || start_i != 105 )
return 0;
else if( version != 0x05 )
return -2;
if( DXTformat == 0x0b ) {
DXTVERSION = 1;
}
else if( DXTformat == 0x0d )
DXTVERSION = 5;
else
return -3;
if( u3 != 1 )
return -4;
else if( flag != 1 && flag != 0 )
return -5;
} HEADER;
typedef struct
{
SetBackColor( cLtRed );
u16 color0;
u16 color1;
u8 index[4];
} COLORBLOCK;
typedef struct
{
COLORBLOCK cb;
} DXT1;
typedef struct
{
u8 alpha[8];
COLORBLOCK cb;
} DXT3;
typedef struct
{
u8 alpha1;
u8 alpha2;
u8 alpha_indices[6];
COLORBLOCK cb;
} DXT5;
Printf("sizeof dxt1=%d dxt3=%d dxt5=%d\n",
sizeof( DXT1 ),
sizeof( DXT3 ),
sizeof( DXT5 )
);
local int getSize( local int width , local int height , local int depth )
{
return ( ( width + 3 ) / 4 ) * ( ( height + 3 ) / 4 );// * ( DXTVERSION == 0 ? 8 : 16 );
}
local int getMipmapCount( local int width , local int height )
{
local int max = width > height ? width : height;
local int count = 0;
local int i = 0;
for( i = 0 ; max >> i > 0 ; i++ )
{
count++;
}
return count;
}
void readMipmap( local int count )
{
if( DXTVERSION == 1 )
DXT1 blocks[count] <optimize=false>;
else if( DXTVERSION == 3 )
DXT3 blocks[count] <optimize=false>;
else if( DXTVERSION == 5 )
DXT5 blocks[count] <optimize=false>;
}
typedef struct
{
HEADER header <open=true>;
local int numMipmaps = getMipmapCount( header.width , header.height );
Printf( "numMipmaps: %d\n" , numMipmaps );
while( numMipmaps > 0 )
{
numMipmaps--;
// remove comment for seeing the blocks
// kinda wrong tho, since it doesnt care about offset_texture/offset_mipmap1/offset_mipmap2?
//readMipmap( getSize( header.width >> numMipmaps , header.height >> numMipmaps , 4 ) );
}
} IWI;
IWI x <open=true>;
Looks like: