Results 1 to 9 of 9

Thread: [CoD] File Formats

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    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
    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

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

    smect@ (9th August 2014)

Posting Permissions

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