Пример #1
0
        public static XT2 Load(string path)
        {
            FileInfo fi = new FileInfo(path);

            Console.WriteLine("{0}", path);
            XT2 xt2 = new XT2()
            {
                Name = fi.Name.Replace(fi.Extension, "")
            };

            using (BEBinaryReader br = new BEBinaryReader(fi.OpenRead()))
            {
                Console.WriteLine("Always 0 : {0}", br.ReadUInt32());

                int magic = (int)br.ReadUInt32();

                br.ReadUInt32();    // datasize
                Console.WriteLine("Always 52 : {0}", br.ReadUInt32());
                Console.WriteLine("Always 0 : {0}", br.ReadUInt16());
                xt2.Width  = br.ReadUInt16();
                xt2.Height = br.ReadUInt16();
                Console.WriteLine("{0} {1}", br.ReadUInt16(), br.ReadUInt16());

                xt2.Header = new D3DBaseTexture(br);

                int W          = 0;
                int H          = 0;
                int TexelPitch = 0;
                int DataSize   = 0;
                int OutSize    = 0;
                int w          = xt2.Width;
                int h          = xt2.Height;

                switch (xt2.Header.DataFormat)
                {
                    //case D3DFormat.X360_A8R8G8B8:
                    //    W = w;
                    //    H = h;
                    //    TexelPitch = 4;
                    //    DataSize = w * h * 4;
                    //    break;

                    //case D3DFormat.X360_DXT1:
                    //    W = w / 4;
                    //    H = h / 4;
                    //    TexelPitch = 8;
                    //    DataSize = w * h / 2;
                    //    break;

                    //case D3DFormat.X360_DXT2:
                    //    W = w / 4;
                    //    H = h / 4;
                    //    TexelPitch = 16;
                    //    DataSize = W * H;
                    //    break;
                }

                if (H % 128 != 0)
                {
                    H += 128 - H % 128;
                }

                switch (xt2.Header.DataFormat)
                {
                    //case D3DFormat.X360_A8R8G8B8:
                    //    OutSize = W * H * TexelPitch;
                    //    break;

                    //case D3DFormat.X360_DXT1:
                    //    OutSize = W * H * TexelPitch;
                    //    break;

                    //case D3DFormat.X360_DXT2:
                    //    DataSize = w * H * 2;
                    //    OutSize = W * H * TexelPitch;
                    //    break;
                }

                byte[] data    = new byte[DataSize];
                byte[] outdata = new byte[OutSize];

                Array.Copy(br.ReadBytes(DataSize), data, DataSize);

                int step = xt2.Header.Endian == 1 ? 2 : 4;
                for (int i = 0; i < data.Length; i += step)
                {
                    for (int j = 0; j < step / 2; j++)
                    {
                        byte tmp = data[i + j];
                        data[i + j]            = data[i + step - j - 1];
                        data[i + step - j - 1] = tmp;
                    }
                }

                for (int y = 0; y < H; y++)
                {
                    for (int x = 0; x < W; x++)
                    {
                        int offset = Xbox360ConvertTextureAddress(x, y, W, TexelPitch);
                        if (offset * TexelPitch < data.Length)
                        {
                            Array.Copy(data, offset * TexelPitch, outdata, (x + y * W) * TexelPitch, TexelPitch);
                        }
                    }
                }

                MipMap mip = new MipMap
                {
                    Width  = xt2.Width,
                    Height = xt2.Height,
                    Data   = data
                };

                xt2.MipMaps.Add(mip);
            }

            return(xt2);
        }
Пример #2
0
        public static XT2 Load(string Path)
        {
            FileInfo fi = new FileInfo(Path);
            Console.WriteLine("{0}", Path);
            XT2 xt2 = new XT2();

            xt2.Name = fi.Name.Replace(fi.Extension, "");

            using (BEBinaryReader br = new BEBinaryReader(fi.OpenRead()))
            {
                Console.WriteLine("Always 0 : {0}", br.ReadUInt32());

                int magic = (int)br.ReadUInt32();

                xt2.dataSize = (int)br.ReadUInt32();
                Console.WriteLine("Always 52 : {0}", br.ReadUInt32());
                Console.WriteLine("Always 0 : {0}", br.ReadUInt16());
                xt2.width = br.ReadUInt16();
                xt2.height = br.ReadUInt16();
                Console.WriteLine("{0} {1}", br.ReadUInt16(), br.ReadUInt16());

                xt2.header = new D3DBaseTexture(br);

                Console.WriteLine("{0}x{1} :: {2} :: {3} :: {4} :: {5}", xt2.width, xt2.height, xt2.header.DataFormat, xt2.header.Endian, xt2.dataSize, magic);

                int W = 0;
                int H = 0;
                int TexelPitch = 0;
                int DataSize = 0;
                int OutSize = 0;
                int w = xt2.width;
                int h = xt2.height;

                switch (xt2.header.DataFormat)
                {
                    case D3DFormat.X360_A8R8G8B8:
                        W = w;
                        H = h;
                        TexelPitch = 4;
                        DataSize = w * h * 4;
                        break;

                    case D3DFormat.X360_DXT1:
                        W = w / 4;
                        H = h / 4;
                        TexelPitch = 8;
                        DataSize = w * h / 2;
                        break;

                    case D3DFormat.X360_DXT2:
                        W = w / 4;
                        H = h / 4;
                        TexelPitch = 16;
                        DataSize = W * H;
                        break;
                }

                if (H % 128 != 0) { H = H + (128 - H % 128); }

                switch (xt2.header.DataFormat)
                {
                    case D3DFormat.X360_A8R8G8B8:
                        OutSize = W * H * TexelPitch;
                        break;

                    case D3DFormat.X360_DXT1:
                        OutSize = W * H * TexelPitch;
                        break;

                    case D3DFormat.X360_DXT2:
                        DataSize = w * H * 2;
                        OutSize = W * H * TexelPitch;
                        break;
                }

                byte[] data = new byte[DataSize];
                byte[] outdata = new byte[OutSize];

                Array.Copy(br.ReadBytes(DataSize), data, DataSize);

                int step = (xt2.header.Endian == 1 ? 2 : 4);
                for (int i = 0; i < data.Length; i += step)
                {
                    for (int j = 0; j < step / 2; j++)
                    {
                        byte tmp = data[i + j];
                        data[i + j] = data[i + step - j - 1];
                        data[i + step - j - 1] = tmp;
                    }
                }

                for (int y = 0; y < H; y++)
                {
                    for (int x = 0; x < W; x++)
                    {
                        int offset = Xbox360ConvertTextureAddress(x, y, W, TexelPitch);
                        if (offset * TexelPitch < data.Length) { Array.Copy(data, offset * TexelPitch, outdata, (x + y * W) * TexelPitch, TexelPitch); }
                    }
                }

                var mip = new MipMap();
                mip.Width = xt2.width;
                mip.Height = xt2.height;
                mip.Data = data;
                xt2.MipMaps.Add(mip);
            }

            return xt2;
        }