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 != 1 )
return -4;
else if( flag != 1 && flag != 0 )
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 = getMipmapCount( header.width , header.height );
Debug.Log("numMipmaps: " + numMipmaps + " size="+header.width + "/"+header.height + " version=" + header.getVersion());
while( numMipmaps > 0 )
{
numMipmaps--;
readMipmap( getSize( header.width >> numMipmaps , header.height >> numMipmaps , 4 ) );
}
}
int getSize(int width, int height, int depth)
{
return ( ( width + 3 ) / 4 ) * ( ( height + 3 ) / 4 );// * ( DXTVERSION == 0 ? 8 : 16 );
}
int getMipmapCount(int width, int height)
{
int max = width > height ? width : height;
int count = 0;
int i = 0;
for( i = 0 ; max >> i > 0 ; i++ )
{
count++;
}
return count;
}
DXT1[] dxt1;
void readMipmap(int count)
{
int DXTVERSION = header.getVersion();
dxt1 = new DXT1[count];
for (int i = 0; i < count; i++)
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:
(I hope thats correct so far xD)