Esempio n. 1
0
        public static DAT Load(string path)
        {
            FileInfo fi = new FileInfo(path);
            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            DAT dat = new DAT();

            DatMesh D = new DatMesh();
            int count;

            using (BEBinaryReader br = new BEBinaryReader(fi.OpenRead(), Encoding.Default))
            {
                if (br.ReadUInt32() != 18 ||
                    br.ReadUInt32() != 8 ||
                    br.ReadUInt32() != 64206 ||
                    br.ReadUInt32() != 2)
                {
                    Logger.LogToFile(Logger.LogLevel.Error, "{0} isn't a valid DAT file", path);
                    return null;
                }

                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    int tag = (int)br.ReadUInt32();
                    int length = (int)br.ReadUInt32();

                    switch (tag)
                    {
                        case 54: // 00 00 00 36
                            D = new DatMesh();
                            D.UnknownAttribute = br.ReadUInt16();   // I think this is actually two byte values
                            D.Name = br.ReadString();
                            break;

                        case 23: // 00 00 00 17 : vertex data
                            count = (int)br.ReadUInt32();

                            for (int i = 0; i < count; i++)
                            {
                                D.Mesh.AddListVertex(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                            }
                            break;

                        case 24: // 00 00 00 18 : UV co-ordinates
                            count = (int)br.ReadUInt32();

                            for (int i = 0; i < count; i++)
                            {
                                D.Mesh.AddListUV(br.ReadSingle(), br.ReadSingle());
                            }
                            break;

                        case 53:    // 00 00 00 35 : faces
                            count = (int)br.ReadUInt32();

                            for (int i = 0; i < count; i++)
                            {
                                int faceID = D.Mesh.AddFace(br.ReadUInt16(), br.ReadUInt16(), br.ReadUInt16());

                                D.Mesh.Faces[faceID].SmoothingGroup = br.ReadUInt16();

                                br.ReadByte(); // number of edges, 0 and 3 = tri.  4 = quad.
                            }
                            break;

                        case 22: // 00 00 00 16 : material list
                            D.Mesh.Materials.AddRange(br.ReadStrings((int)br.ReadUInt32()));
                            break;

                        case 26: // 00 00 00 1A : face textures
                            count = (int)br.ReadUInt32();
                            br.ReadBytes(4); // f**k knows what this is
                            for (int i = 0; i < count; i++)
                            {
                                D.Mesh.SetMaterialForFace(i, br.ReadUInt16() - 1);
                            }
                            break;

                        case 0:
                            // EndOfFile
                            D.Mesh.ProcessMesh();
                            dat.DatMeshes.Add(D);
                            break;

                        default:
                            Logger.LogToFile(Logger.LogLevel.Error, "Unknown DAT tag: {0} ({1:x2})", tag, br.BaseStream.Position);
                            return null;
                    }
                }
            }

            return dat;
        }
Esempio n. 2
0
        public static EXP Load(string path)
        {
            FileInfo fi = new FileInfo(path);
            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            EXP exp = new EXP();

            exp.name = Path.GetFileNameWithoutExtension(path);
            exp.location = Path.GetDirectoryName(path) + "\\";

            using (var br = new BEBinaryReader(fi.OpenRead()))
            {
                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    string section = br.ReadString(4);
                    int length = 0;

                    switch (section)
                    {
                        case "FORM":
                            length = (int)br.ReadUInt32();
                            break;

                        case "TERR":
                        case "XOBF":
                            break;

                        case "TITL":
                            length = (int)br.ReadUInt32();
                            if (length > 0) { throw new NotImplementedException(string.Format("TITL section has a length ({0}), don't know what to do!", length)); }
                            break;

                        case "TEXT":
                            length = (int)br.ReadUInt32();
                            if (length > 0) { throw new NotImplementedException(string.Format("TEXT section has a length ({0}), don't know what to do!", length)); }
                            break;

                        case "HEAD":
                            length = (int)br.ReadUInt32();
                            Logger.LogToFile(Logger.LogLevel.Debug, "U: {0}", br.ReadUInt16());
                            Logger.LogToFile(Logger.LogLevel.Debug, "U: {0}", br.ReadUInt32());
                            exp.entryCount = br.ReadUInt16();
                            Logger.LogToFile(Logger.LogLevel.Debug, "U: {0}", br.ReadUInt32());
                            Logger.LogToFile(Logger.LogLevel.Debug, "U: {0}", br.ReadUInt16());
                            Logger.LogToFile(Logger.LogLevel.Debug, "U: {0}", br.ReadUInt16());
                            Logger.LogToFile(Logger.LogLevel.Debug, "U: {0}", br.ReadUInt16());
                            Logger.LogToFile(Logger.LogLevel.Debug, "U: {0}", br.ReadUInt32());
                            Logger.LogToFile(Logger.LogLevel.Debug, "U: {0}", br.ReadUInt32());
                            break;

                        case "BIN ":
                            length = (int)br.ReadUInt32();
                            exp.contents.Add(new EXPEntry { Size = length, Offset = (int)br.BaseStream.Position, EntryType = EXPEntryType.Binary });
                            br.ReadBytes(length);
                            break;

                        case "ANM ":
                            length = (int)br.ReadUInt32();
                            exp.contents.Add(new EXPEntry { Size = length, Offset = (int)br.BaseStream.Position, EntryType = EXPEntryType.Animation });
                            br.ReadBytes(length);
                            break;

                        case "PLTX":
                            length = (int)br.ReadUInt32();
                            if (length > 0) { throw new NotImplementedException(string.Format("PLTX section has a length ({0}), don't know what to do!", length)); }
                            break;

                        default:
                            throw new NotImplementedException(string.Format("Unexpected section \"{0}\" at {1,0:X0}", section, br.BaseStream.Position - 4));
                    }
                }
            }

            return exp;
        }
Esempio n. 3
0
        public static MAT Load(string path)
        {
            FileInfo fi = new FileInfo(path);
            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            MAT mat = new MAT();

            MATMaterial M = new MATMaterial();
            bool bDebug = false;

            using (BEBinaryReader br = new BEBinaryReader(fi.OpenRead(), Encoding.Default))
            {
                br.ReadBytes(16); // Header

                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    int tag = (int)br.ReadUInt32();
                    int length = (int)br.ReadUInt32();

                    switch (tag)
                    {
                        case 0x4:
                            // C1 mat file
                            M = new MATMaterial();

                            M.DiffuseColour[0] = br.ReadByte(); // R
                            M.DiffuseColour[1] = br.ReadByte(); // G
                            M.DiffuseColour[2] = br.ReadByte(); // B
                            M.DiffuseColour[3] = br.ReadByte(); // A
                            M.AmbientLighting = br.ReadSingle();
                            M.DirectionalLighting = br.ReadSingle();
                            M.SpecularLighting = br.ReadSingle();
                            M.SpecularPower = br.ReadSingle();
                            M.SetFlags((int)br.ReadUInt16()); // Flags
                            if (M.GetFlag(MATMaterial.Settings.UnknownSetting) || M.GetFlag(MATMaterial.Settings.IFromV) || M.GetFlag(MATMaterial.Settings.UFromI) || M.GetFlag(MATMaterial.Settings.VFromI)) { bDebug = true; }
                            M.UVMatrix = new Matrix2D(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                            byte x1 = br.ReadByte(); // ??
                            byte x2 = br.ReadByte(); // ??
                            M.Name = br.ReadString();

                            if (bDebug) { Console.WriteLine(path + " :: " + M.Name); bDebug = false; }
                            break;

                        case 0x3c:
                            M = new MATMaterial();

                            M.DiffuseColour[0] = br.ReadByte(); // R
                            M.DiffuseColour[1] = br.ReadByte(); // G
                            M.DiffuseColour[2] = br.ReadByte(); // B
                            M.DiffuseColour[3] = br.ReadByte(); // A
                            M.AmbientLighting = br.ReadSingle();
                            M.DirectionalLighting = br.ReadSingle();
                            M.SpecularLighting = br.ReadSingle();
                            M.SpecularPower = br.ReadSingle();
                            M.SetFlags((int)br.ReadUInt32()); // Flags
                            M.UVMatrix = new Matrix2D(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                            if (br.ReadUInt32() != 169803776) { Console.WriteLine("Weird Beard! (" + path + ")"); }
                            br.ReadBytes(13); // 13 bytes of nothing
                            M.Name = br.ReadString();
                            break;

                        case 0x1c:
                            M.Texture = br.ReadString();
                            break;

                        case 0x1f:
                            string s = br.ReadString(); // shadetable
                            break;

                        case 0x0:
                            mat.materials.Add(M);
                            break;

                        default:
                            Logger.LogToFile(Logger.LogLevel.Error, "Unknown MAT tag: {0} ({1})", tag, br.BaseStream.Position.ToString("X"));
                            return null;
                    }
                }
            }

            return mat;
        }
Esempio n. 4
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;
        }
Esempio n. 5
0
        public static PIX Load(string path)
        {
            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            FileInfo fi = new FileInfo(path);
            PIX pix = new PIX();

            using (var br = new BEBinaryReader(fi.OpenRead(), Encoding.Default))
            {
                if (br.ReadUInt32() != 0x12 ||
                    br.ReadUInt32() != 0x08 ||
                    br.ReadUInt32() != 0x02 ||
                    br.ReadUInt32() != 0x02)
                {
                    Logger.LogToFile(Logger.LogLevel.Error, "{0} isn't a valid PIX file", path);
                    return null;
                }

                PIXIE pixelmap = new PIXIE();

                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    int tag = (int)br.ReadUInt32();
                    int length = (int)br.ReadUInt32();

                    switch (tag)
                    {
                        case 0x03:
                            pixelmap = new PIXIE();

                            pixelmap.Format = (PIXIE.PixelmapFormat)br.ReadByte();
                            pixelmap.RowSize = br.ReadUInt16();
                            pixelmap.Width = br.ReadUInt16();
                            pixelmap.Height = br.ReadUInt16();
                            pixelmap.HalfWidth = br.ReadUInt16();
                            pixelmap.HalfHeight = br.ReadUInt16();
                            pixelmap.Name = br.ReadString();
                            break;

                        case 0x21:
                            pixelmap.PixelCount = (int)br.ReadUInt32();
                            pixelmap.PixelSize = (int)br.ReadUInt32();
                            pixelmap.SetData(br.ReadBytes(pixelmap.DataLength));
                            break;

                        case 0x00:
                            pix.pixies.Add(pixelmap);
                            break;

                        case 0x3d:
                            pixelmap = new PIXIE();

                            pixelmap.Format = (PIXIE.PixelmapFormat)br.ReadByte();
                            pixelmap.RowSize = br.ReadUInt16();
                            pixelmap.Width = br.ReadUInt16();
                            pixelmap.Height = br.ReadUInt16();
                            br.ReadBytes(6);
                            pixelmap.Name = br.ReadString();
                            break;

                        default:
                            Logger.LogToFile(Logger.LogLevel.Error, "Unknown PIX tag: {0} ({1:x2})", tag, br.BaseStream.Position);
                            return null;
                    }
                }
            }

            return pix;
        }