Results 1 to 9 of 9

Thread: [CoD] File Formats

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    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:

    Click image for larger version. 

Name:	bce389d79c63399a19b0208d7f99e45b.png 
Views:	62 
Size:	161.1 KB 
ID:	1246

    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 <u8Usage {
        
    Color 0x00,
        Default = 
    0x01// Fallback texture for engine
        
    Skybox 0x05
    };

    enum <u8ImageFormat {
        
    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
    {
        
    SetBackColorcLtBlue );
        
    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 != )
            return -
    4;
        else if( 
    flag != && flag != )
            return -
    5;

    HEADER;

    typedef struct
    {
        
    SetBackColorcLtRed );
        
    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",
    sizeofDXT1 ),
    sizeofDXT3 ),
    sizeofDXT5 )
    );

    local int getSizelocal int width local int height local int depth )
    {
        return ( ( 
    width ) / ) * ( ( height ) / );// * ( DXTVERSION == 0 ? 8 : 16 );   
    }

    local int getMipmapCountlocal int width local int height )
    {
        
    local int max width height width height;
        
    local int count 0;
        
    local int i 0;

        for( 
    max >> i++ )
        {
            
    count++;
        }

        return 
    count;
    }

    void readMipmaplocal int count )
    {
        if( 
    DXTVERSION == )
            
    DXT1 blocks[count] <optimize=false>;
        else if( 
    DXTVERSION == )
            
    DXT3 blocks[count] <optimize=false>;
        else if( 
    DXTVERSION == )
            
    DXT5 blocks[count] <optimize=false>;
    }

    typedef struct
    {
        
    HEADER header <open=true>;

        
    local int numMipmaps getMipmapCountheader.width header.height );
        
        
    Printf"numMipmaps: %d\n" numMipmaps );

        while( 
    numMipmaps )
        {
            
    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:

    Click image for larger version. 

Name:	dca43237ee4c51e5e1d36e58bd403017.png 
Views:	51 
Size:	23.8 KB 
ID:	1247
    timescale 0.01

  2. The Following 3 Users Say Thank You to kung foo man For This Useful Post:

    brague (25th March 2024),Mitch (8th January 2017),serthy (7th January 2017)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •