Results 1 to 9 of 9

Thread: [CoD] File Formats

  1. #1
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts

    [CoD] File Formats

    Happy New Year!

    Here are all file formats i've done so far.
    All formats are little endian and use the same basic types.
    These are templates of a hex editor, basically C-style so everyone should be able to understand this.
    With them i was able to decompile some simple models and textures, but the code is rly poor atm, if its worth, ill release it in the near future.

    Here you go:

    [CoD2 iwi]
    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;



    typedef struct
    {
        
    u8 start_I;
        
    u8 start_W;
        
    u8 start_i;
        
    u8 version;
        
    u8 DXTformat//0x0b -> DXT1? | 0x0d -> DXT5?
        
    u8 flag;
        
    u16 width;
        
    u16 height;
        
    u16 u3;
        
    u32 lol[4];

        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
    {
        
    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;

    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;

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

        while( 
    numMipmaps )
        {
            
    numMipmaps--;

            
    readMipmapgetSizeheader.width >> numMipmaps header.height >> numMipmaps ) );
        }
    IWI;

    IWI x
    Okay, the iwi structure is kind of simple, it is DXT compressed and seems to have always all possible mipmaps.
    There are still some unknown bits, but i am able to convert alot of textures to dds and tga yet.


    [CoD2 xModel]
    PHP Code:
    //SetBackColor( cLtPurple );

    //BigEndian();
    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;

    //SetBackColor( cLtGreen );

    //SetBackColor( cNone );


    typedef struct
    {
        
    u16 start;
    HEADER;

    typedef struct
    {
        
    f32 x;
        
    f32 y;
        
    f32 z;
    VEC3;

    typedef struct
    {
        
    SetBackColorcLtGreen );
        
    string name;
    MATERIALNAME;

    typedef struct
    {
        
    VEC3 min;
        
    VEC3 max;
    MINMAX;

    typedef struct
    {
        
    VEC3 min;
        
    VEC3 max;
    BOUNDS;

    typedef struct
    {
        
    f32 LODdistance;
        
    string LODxmodelsurfs;
    LOD;

    typedef struct
    {
        
    VEC3 normal;
        
    VEC3 xVec// 
        
    VEC3 yVec// 
        
    VEC3 zVec// 
    COLLFACE;

    typedef struct
    {
        
    u16 numMaterials;
        
    MATERIALNAME materials[numMaterials] <optimize=false>;
    LODMATERIAL;

    typedef struct
    {
        
    SetBackColorcLtGreen );

        
    HEADER header;

        
    u8 groundLit// 00

        
    BOUNDS bounds;

        
    local int numLOD 1;

        
    LOD lod[numLOD] <optimize=false>;

        
    f32 ukn;
        
    u32 endLOD_null;

        
    SetBackColorcLtRed );

        
    u8 u4[3];

        
    //u32 unknown0;
        
    u32 unknown1;
        
    i32 unknown2;
        
    i32 hasColl;

        if( 
    hasColl )
        {
            
    u32 numCollData;
            
    COLLFACE c[numCollData];
            
    MINMAX mm1;
            
    u8 unknown3[12];
        }

        
    SetBackColorcLtGreen );

        
    LODMATERIAL LODMat[numLOD] <optimize=false>;

        
    SetBackColorcLtYellow );

        
    local int count 1;
        
    MINMAX mm2[count];
    XMODEL;

    XMODEL x

    Okay, the xModel format seems to be more troublesome when i did this first look some weeks ago, seems that all collision data (if any, LOD to HIGH) is in this file.



    [CoD2 xModelSurf]
    PHP Code:
    LittleEndian();

    // modelType 0 -> rigid
    // modelType 1 -> animated
    // modelType 2 -> viewmodel
    // modelType 3 -> playerbody
    // modelType 4 -> viewhands

    local int fileType 2;

    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;

    typedef struct
    {
        
    f32 x;
        
    f32 y;
        
    f32 z;
    VEC3;

    typedef struct
    {
        
    SetBackColorcLtGreen );
        
    u8 color_b//OK!
        
    u8 color_g//OK!
        
    u8 color_r//OK!
        
    u8 color_a//OK!
        
    SetBackColorcNone );
    COLOR;

    typedef struct
    {
        
    f32 u;
        
    f32 v;
    UV;

    local int modus 1//different possibilities to read this chunk

    typedef struct
    {
        if( 
    modus == )
        {
            
    u16 boneID;
            
    VEC3 v1;
            
    u16 unkn;
        }
        else
        {
            
    u8 unkn1;
            
    u16 boneID;
            
    VEC3 v1;
            
    u8 unkn2;
        }
    CHUNK;

    typedef struct
    {
        
    VEC3 normal;
        
    COLOR color;
        
    UV uv;

        if( 
    fileType == )
        {
            
    u8 lol1[4];
            
    f32 unknownFloats[4];
            
    u8 lol2[4];
            
    VEC3 position;
        }
        else if( 
    fileType == )
        {
            
    f32 unknownFloats[6];
            
    u8 chunkCount;
            
    u16 u7;
            
    VEC3 position;
       
            if( 
    chunkCount != )
            {
                if( 
    modus == )
                    
    i8 y;

                
    Printf"%d\n" chunkCount );

                
    CHUNK chunk[chunkCount] <optimize=false>;
        
                if( 
    modus != )
                    
    u8 lol;
            }
        }
    VERTEX;

    typedef struct
    {
        
    u16 start//14 00
    HEADER;

    typedef struct
    {
        
    u16 ID[3];
    VERTORDER;

    typedef struct
    {
        
    u8 u1;
        
    u16 numVerts;
        
    u16 numTris;

        if( 
    u1 == && ReadUShortFTell() ) != )
        {
            
    u8 u2 u3;

            
    Printf"u2 = %d | u3 = %d\n" u2 u3 );
        }

        
    u16 u4;
        
    VERTEX v[numVerts] <optimize=false>;
        
    VERTORDER vertOrder[numTris] <optimize=false>;
    MATCHUNK;

    typedef struct
    {
        
    HEADER header;
        
    u16 numMatChunks;
        
    MATCHUNK mc[numMatChunks] <optimize=false>;
    XMODELSURF;

    XMODELSURF x

    I didnt get the mesh weight part to the vertices, and also some coords (Z-coord) is kind of distorted, but cant remember correctly for now.



    [CoD2 xModelPart]
    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 modelType 1;
    // modelType 0 -> rigid
    // modelType 1 -> animated
    // modelType 2 -> viewmodel
    // modelType 3 -> playerbody
    // modelType 4 -> viewhands

    typedef struct
    {
        
    u16 start;
    HEADER;

    typedef struct
    {
        
    string name;
    BONENAME;

    typedef struct
    {
        
    u8 parentBoneID;

        if( 
    modelType == || modelType == //rigid|animated
        
    {
            
    f32 x// offset relative to its
            
    f32 y// parent bone position
            
    f32 z// they seem distorted/wrong im 50% of all cases
            
    i16 unkn[3];
        }
        else if( 
    modelType == // playerbody
        
    {
            
    u8 unknown[18]; // differs from the same model as modelType = 2
        
    }
        else if( 
    modelType == || modelType == // viewmodel & viewhands
        
    {
            
    f32 zero[3];
            
    u8 unknown[6];
        }
    RELATIVE;

    typedef struct
    {
        
    HEADER header;
        
    u16 numBonesRelative// position relative to parent bone
        
    u16 numBonesAbsolute// position absolute to world/origin
        
    RELATIVE rel[numBonesRelative] <optimize=false>;
        
    BONENAME bones[numBonesRelative numBonesAbsolute] <optimize=false>;
        
    u8 unknown[numBonesRelative numBonesAbsolute]; // hit location ID? depends on jointnames
    XMODELPARTS;

    XMODELPARTS x
    The xModelPart is known to 99% if i remember correctly. So there shouldnt be any problems here.






    I've done them some weeks ago, so i dont remember correctly if theyre the latest ones and when they apply.
    Would apprecciate it if some1 want to help me to unreveal the complete formats, also for other ones.
    If you improved them, please share them to the remaining community and make them public!

    Cheers, Serthy
    Last edited by serthy; 3rd January 2014 at 21:19.

  2. The Following 2 Users Say Thank You to serthy For This Useful Post:

    kung foo man (5th January 2014),smect@ (4th January 2014)

  3. #2
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    Quote Originally Posted by serthy View Post
    but i am able to convert alot of textures to dds and tga yet
    Here it is (only iwi to dds for now lol): Attachment 585

  4. #3
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    I dont get what it do or how to use it :P

  5. #4
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    Quote Originally Posted by Ni3ls View Post
    I dont get what it do or how to use it :P
    Drag'n'Drop iwi's to the exe.
    It's only iwi to dds right now, i try to add the other way around too and some opengl stuff for model displaying maybe animation loading later on.

  6. The Following User Says Thank You to serthy For This Useful Post:

    Ni3ls (4th January 2014)

  7. #5
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,010
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    CoD2 D3DBSP

    Tech: LuaJIT + FFI for C-structs

    Toujane example
    Click image for larger version. 

Name:	codu.jpg 
Views:	161 
Size:	594.7 KB 
ID:	587

    Movement:

    WASD for Position
    Arrow Keys for Camera
    Q/E for Camera Down/Up (like in CoD2)

    PHP Code:
    typedef struct
    {
        
    float position[3];
        
    float normal[3];
        
    int bla[11];
    aDrawVert;

    typedef struct
    {
        
    int length;
        
    int offset;
    aLump;

    typedef struct
    {
        
    char ident[4];
        
    int version;
        
    aLump lumps[100];
    aHeader;

    typedef struct
    {
        
    short index[3];
    aTriangle// depricated

    typedef struct
    {
        
    unsigned short offset;
        
    //unsigned short b;
        //unsigned short c;
    aDrawIndex;

    /*typedef struct
    {
        unsigned short a;
        unsigned short b;
        unsigned short c;
    } aDrawIndex;*/


    // is empty in mp_analyse1
    typedef struct
    {
        
    float position[3];
    aCollisionVert;

    typedef struct
    {
        
    int planeIndex;
        
    int children[2];
        
    int mins[3];
        
    int maxs[3];
    aNode;

    typedef struct
    {
        
    //int cluster; // ???
        //int area; // ???
        //int mins[3]; // ???
        //int maxs[3]; // ???
        //int faceFirst;
        //int faceCount;
        //int brushFirst;
        //int brushCount;
        
    int someA[4];
        
    int firstLeafBrush// lookup in leafbrushes
        
    int numLeafBrushes;
        
    int someB[3];
    aLeaf;

    typedef struct
    {
        
    unsigned short bla;
        
    unsigned short foo;
        
    unsigned int vertexFirst;
        
    unsigned short nVertex;

        
    unsigned short nTriangles;
        
    unsigned int triangleFirst;
    aTriangleSoup
    Draw all triangle faces:
    PHP Code:

    function bspdraw()

        
    colors = {
            {
    000},
            {
    001},
            {
    010},
            {
    011},
            {
    100},
            {
    101},
            {
    110},
            {
    111}
        }

        for 
    0,nTriangleSoups-do
            
    soup triangleSoups i
            
            gl
    .glBegin(gl.GL_TRIANGLES)
            for 
    nTriangles 0soup.nTriangles-do
                
    drawIndex drawIndexes + (soup.triangleFirst nTriangles)
                
                
    co colors[(nTriangles%8) + 1]
                
    gl.glColor3f(co[1], co[2], co[3])
                
                
    a  vertices + (drawIndex.offset soup.vertexFirst)
                
    gl.glVertex3fv(a.position)
            
    end
            gl
    .glEnd()
        
    end
    end 
    Serthy, could you post your full solution of how to use your structs? That would help alot
    Attached Files Attached Files
    timescale 0.01

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

    php (5th January 2014),smect@ (5th January 2014)

  9. #6
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,010
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    Hey Serthy, sorry for late respone, I didn't see your answer in the other thread for some reason.

    I tried to port your code to C# and it works so far, but I wonder how to "read the pixels" now, like "RGBA color = iwi.getPixel(x,y)". This is what I got so far:

    PHP Code:
    using UnityEngine;
    using System.Collections;
    using System// System.Byte etc.

    public class HEADER
    {
        public 
    Byte start_I;
        public 
    Byte start_W;
        public 
    Byte start_i;
        public 
    Byte version;
        public 
    Byte DXTformat//0x0b -> DXT1? | 0x0d -> DXT5?
        
    public Byte flag;
        public 
    UInt16 width;
        public 
    UInt16 height;
        public 
    UInt16 u3;
        public 
    UInt32[/*4*/lol;

        public 
    HEADER(System.IO.BinaryReader binaryReader)
        {
            
    start_I binaryReader.ReadByte();
            
    start_W binaryReader.ReadByte();
            
    start_i binaryReader.ReadByte();
            
    version binaryReader.ReadByte();
            
    DXTformat binaryReader.ReadByte(); //0x0b -> DXT1? | 0x0d -> DXT5?
            
    flag binaryReader.ReadByte();
            
    width binaryReader.ReadUInt16();
            
    height binaryReader.ReadUInt16();
            
    u3 binaryReader.ReadUInt16();
            
    lol = new UInt32[4] {
                
    binaryReader.ReadUInt32(),
                
    binaryReader.ReadUInt32(),
                
    binaryReader.ReadUInt32(),
                
    binaryReader.ReadUInt32()
            };
        }

        public 
    int getVersion()
        {
            if( 
    start_I != 73 || start_W != 87 || start_i != 105 )
                return 
    0;
            else if( 
    version != 0x05 )
                return -
    2;
        
            
    int DXTVERSION 0;

            if( 
    DXTformat == 0x0b )
                
    DXTVERSION 1;
            else if( 
    DXTformat == 0x0d )
                
    DXTVERSION 5;
            else
                return -
    3;

            if( 
    u3 != )
                return -
    4;
            else if( 
    flag != && flag != )
                return -
    5;

            return 
    DXTVERSION;
        }
    }

    public class 
    COLORBLOCK
    {
        public 
    UInt16 color0;
        public 
    UInt16 color1;
        public 
    Byte[/*4*/index;

        public 
    COLORBLOCK(System.IO.BinaryReader binaryReader_)
        {
            
    color0 binaryReader_.ReadUInt16();
            
    color1 binaryReader_.ReadUInt16();
            
    index binaryReader_.ReadBytes(4);
        }
    }

    public class 
    DXT1
    {
        public 
    COLORBLOCK cb;

        public 
    DXT1(System.IO.BinaryReader binaryReader_)
        {
            
    cb = new COLORBLOCK(binaryReader_);
        }
    }

    public class 
    DXT3
    {
        public 
    Byte[/*8*/alpha;
        public 
    COLORBLOCK cb;
    }

    public class 
    DXT5
    {
        public 
    Byte alpha1;
        public 
    Byte alpha2;
        public 
    Byte[/*6*/alpha_indices;
        
    COLORBLOCK cb;
    }

    public class 
    IWI
    {
        
    HEADER header;
        
    System.IO.BinaryReader binaryReader;

        public 
    IWI(System.IO.BinaryReader binaryReader_) {
            
    binaryReader binaryReader_;

            
    header = new HEADER(binaryReader);
            
    int numMipmaps getMipmapCountheader.width header.height );
        
            
    Debug.Log("numMipmaps: " numMipmaps " size="+header.width "/"+header.height " version=" header.getVersion());

            while( 
    numMipmaps )
            {
                
    numMipmaps--;
                
    readMipmapgetSizeheader.width >> numMipmaps header.height >> numMipmaps ) );
            }
        }

        
    int getSize(int widthint heightint depth)
        {
            return ( ( 
    width ) / ) * ( ( height ) / );// * ( DXTVERSION == 0 ? 8 : 16 );   
        
    }

        
    int getMipmapCount(int widthint height)
        {
            
    int max width height width height;
            
    int count 0;
            
    int i 0;

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

            return 
    count;
        }

        
    DXT1[] dxt1;

        
    void readMipmap(int count)
        {
            
    int DXTVERSION header.getVersion();

            
    dxt1 = new DXT1[count];
            for (
    int i 0counti++)
                
    dxt1[i] = new DXT1(binaryReader);

            
    Debug.Log("num of dxt1=" dxt1.Length);

            
    //if( DXTVERSION == 1 )
            //    DXT1 blocks[count];
            //else if( DXTVERSION == 3 )
            //    DXT3 blocks[count];
            //else if( DXTVERSION == 5 )
            //    DXT5 blocks[count];
        
    }
    }

    public class 
    iwi2dds MonoBehaviour {
        
    KILLTUBE.GreatExplorer explorer = new KILLTUBE.GreatExplorer();
        
    IWI iwi;

        
    void Start () {
            
    explorer.AddArchive(@"G:\GAMES\CoD2 1.3\main\iw_08.iwd");
            
    System.IO.BinaryReader binaryReader explorer.GetGreatFile("images/155_cannon.iwi");
            
    iwi = new IWI(binaryReader);
        }

    Output:

    Click image for larger version. 

Name:	output.jpg 
Views:	108 
Size:	105.1 KB 
ID:	728

    (I hope thats correct so far xD)
    timescale 0.01

  10. The Following User Says Thank You to kung foo man For This Useful Post:

    smect@ (9th August 2014)

  11. #7
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    Quote Originally Posted by kung foo man View Post
    I tried to port your code to C# and it works so far, but I wonder how to "read the pixels" now, like "RGBA color = iwi.getPixel(x,y)".
    DXT is a texture compression format, you have to decompress it to extract RGBA values from it.
    MSDN has one of the best explanations of DXT texture compression and here is a good C++ library for compression/decompression of the DXT format.
    However, gpu's can handle DXT textures the best and almost all editing programs can handle DDS images (DXT compression), so why bother converting it to RGBA?

  12. #8
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,010
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    Unity3D needs at some point the raw RGBA data ^^

    I found a good DevIL C# wrapper and it works perfect so far

    PHP Code:
        public Texture2D LoadImageFromData(byte[] imageData)
        {
            const 
    int cNumImages 1;
            
    uint[] handles = new uint[cNumImages];
            
    Texture2D resTexture null;

            
    /* First we initialize the library. */
            /*Do not forget that... */
            
    DevILLoader.ilInit();

            
    /* We want all images to be loaded in a consistent manner */
            
    DevILLoader.ilEnable(DevILConstants.IL_ORIGIN_SET);

            
    /* In the next section, we load one image */
            
    DevILLoader.ilGenImages(cNumImageshandles);
            
    DevILLoader.ilBindImage(handles[0]);

            
    //
            //uint res = PluginLoader.ilLoadL(DevILConstants.IL_PNG, imageData, (uint)imageData.Length);
            
    bool res DevILLoader.ilLoadL(DevILConstants.IL_TYPE_UNKNOWNimageData, (uint)imageData.Length);
            if (!
    res)
            {
                
    Debug.LogWarning("Error! Cannot load image from data");
                return 
    resTexture;
            }

            
    /* Let's spy on it a little bit */
            
    int width DevILLoader.ilGetInteger(DevILConstants.IL_IMAGE_WIDTH); // getting image width
            
    int height DevILLoader.ilGetInteger(DevILConstants.IL_IMAGE_HEIGHT); // and height
            
    Debug.Log("Base image resolution: w = " width "; h = " height);

            
    // create result texture
            
    resTexture = new Texture2D(widthheightTextureFormat.RGBA32true);

            
    //
            
    Color32[] texColors GetColorDataFromCurrentImage();
            
            
    // set first mip map
            
    resTexture.SetPixels32(texColors0);

            
    // now, try to set another levels of bitmap
            
    {
                
    uint currMipMapLevel 1;
                const 
    uint cMaxMipMapLevel 15;
                while (
    currMipMapLevel cMaxMipMapLevel)
                {
                    
    res DevILLoader.ilActiveMipmap(currMipMapLevel);
                    
    Debug.Log("res = " res " currMipMapLevel = " currMipMapLevel);
                    if (!
    res)
                    {
                        break;
                    }

                    
    //
                    
    texColors GetColorDataFromCurrentImage();

                    
    Debug.Log("currMipMapLevel = " currMipMapLevel);

                    
    // set next mip map
                    
    resTexture.SetPixels32(texColors, (int)currMipMapLevel);

                    ++
    currMipMapLevel;

                    
    // restore base image
                    
    DevILLoader.ilBindImage(handles[0]);
                }
            }

            
    resTexture.Apply(true);
            
    //resTexture.Apply(false); // show this to ven!

            /* Finally, clean the mess! */
            
    DevILLoader.ilDeleteImages(cNumImageshandles);

            return 
    resTexture;
        }

        public 
    Color32[] GetColorDataFromCurrentImage()
        {
            
    int width DevILLoader.ilGetInteger(DevILConstants.IL_IMAGE_WIDTH); // getting image width
            
    int height DevILLoader.ilGetInteger(DevILConstants.IL_IMAGE_HEIGHT); // and height

            
    Debug.Log("Image resolution: w = " width "; h = " height);

            
    /* how much memory will we need? */
            
    int memoryNeeded width height 4;

            
    /* We multiply by 4 here because we want 4 components per pixel */
            
    byte[] imageColorData = new byte[memoryNeeded];

            
    /* finally get the image data */
            
    DevILLoader.ilCopyPixels(000, (uint)width, (uint)height1DevILConstants.IL_RGBADevILConstants.IL_UNSIGNED_BYTEimageColorData);

            if (
    imageColorData.Length <= 0)
            {
                return 
    null;
            }

            
    // create colors from color data
            
    Color32[] texColors = new Color32[imageColorData.Length 4];

            for (
    int i 00imageColorData.Length+= 4, ++j)
            {
                
    texColors[j].imageColorData[i];
                
    texColors[j].imageColorData[1];
                
    texColors[j].imageColorData[2];
                
    texColors[j].imageColorData[3];
            }

            return 
    texColors;
        } 
    IWI is supported by default.
    timescale 0.01

  13. The Following User Says Thank You to kung foo man For This Useful Post:

    smect@ (9th August 2014)

  14. #9
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,010
    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

  15. 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
  •