Example #1
0
        public static BinMesh Read(Reader reader)
        {
            BinMesh b = new BinMesh();

            b.flags           = reader.ReadUInt32();
            b.numMeshes       = reader.ReadUInt32();
            b.numTotalIndices = reader.ReadUInt32();
            b.meshes          = new BinMeshMesh[b.numMeshes];
            for (int i = 0; i < b.numMeshes; i++)
            {
                BinMeshMesh m = new BinMeshMesh();
                m.numIndices    = reader.ReadUInt32();
                m.materialIndex = reader.ReadUInt32();
                m.indices       = new uint[m.numIndices];
                for (int j = 0; j < m.numIndices; j++)
                {
                    m.indices[j] = reader.ReadUInt32();
                }
                b.meshes[i] = m;
            }
            return(b);
        }
Example #2
0
        public static Section Read(Reader reader, SectionRead specialRead = null)
        {
            MapLoader l       = MapLoader.Loader;
            Type      type    = (Type)reader.ReadUInt32();
            uint      size    = reader.ReadUInt32();
            uint      version = reader.ReadUInt32();
            Section   sec     = new Section(type, size, version);

            if (specialRead != null)
            {
                specialRead(sec);
            }
            switch (sec.type)
            {
            case Type.String:
                sec.data      = reader.ReadBytes((int)size);
                sec["string"] = System.Text.Encoding.UTF8.GetString(sec.data).TrimEnd('\0');
                break;

            case Type.TextureDictionary:
                ushort numTextures = 0;
                sec.ReadChild(reader, (s) => {
                    numTextures      = reader.ReadUInt16();
                    s["numTextures"] = numTextures;
                    s["unk"]         = reader.ReadUInt16();
                });                         // Info Struct
                for (uint i = 0; i < numTextures; i++)
                {
                    sec.ReadChild(reader);                     // TextureNative
                }
                sec.ReadChild(reader);                         // Extension
                break;

            case Type.TextureNative:
                sec.ReadChild(reader, (s) => {
                    s["platform"]       = reader.ReadUInt32();
                    s["filterMode"]     = reader.ReadByte();
                    s["addressingMode"] = reader.ReadByte();
                    reader.ReadUInt16();    // padding
                });                         // Info Struct
                sec.ReadChild(reader);      // Texture name
                sec.ReadChild(reader);      // Alpha name
                sec.ReadChild(reader, (st) => {
                    st.ReadChild(reader, (s) => {
                        s["width"]        = reader.ReadUInt32();
                        s["height"]       = reader.ReadUInt32();
                        s["bpp"]          = reader.ReadUInt32();
                        s["rasterFormat"] = reader.ReadUInt32();
                        reader.ReadUInt32();                                 // PS2 TEX0 GS register
                        reader.ReadUInt32();                                 // PS2 TEX0 GS register
                        reader.ReadUInt32();                                 // PS2 TEX1 GS register
                        reader.ReadUInt32();                                 // PS2 TEX1 GS register
                        reader.ReadUInt32();                                 // PS2 MIPTBP1 GS register
                        reader.ReadUInt32();                                 // PS2 MIPTBP1 GS register
                        reader.ReadUInt32();                                 // PS2 MIPTBP2 GS register
                        reader.ReadUInt32();                                 // PS2 MIPTBP2 GS register
                        s["textureDataSize"]    = reader.ReadUInt32();
                        s["paletteDataSize"]    = reader.ReadUInt32();
                        s["gpuDataAlignedSize"] = reader.ReadUInt32();
                        s["skyMipmapVal"]       = reader.ReadUInt32();
                    });                     // Texture - info struct
                    st.ReadChild(reader);   // Texture - data
                });                         // Texture
                sec.ReadChild(reader, (se) => {
                    se.ReadChild(reader);   // Extension - sky mipmap val - 4 bytes unknown
                });                         // Extension
                break;

            case Type.Clump:
                uint numAtomics = 0;
                sec.ReadChild(reader, (s) => {
                    numAtomics      = reader.ReadUInt32();
                    s["numAtomics"] = numAtomics;
                });                         // Info Struct
                sec.ReadChild(reader);      // Frame list
                sec.ReadChild(reader);      // Geometry list
                for (int i = 0; i < numAtomics; i++)
                {
                    sec.ReadChild(reader);
                }
                sec.ReadChild(reader);                         // Extension
                //l.print("Clump size: " + reader.BaseStream.Position);
                break;

            case Type.FrameList:
                uint numFrames = 0;
                sec.ReadChild(reader, (s) => {
                    numFrames      = reader.ReadUInt32();
                    s["numFrames"] = numFrames;
                    Frame[] frames = new Frame[numFrames];
                    for (int i = 0; i < numFrames; i++)
                    {
                        frames[i]        = new Frame();
                        frames[i].matrix = Matrix.ReadRenderware(reader);
                        frames[i].index  = reader.ReadInt32();
                        frames[i].flags  = reader.ReadUInt32();
                    }
                    s["frames"] = frames;
                });                         // Info Struct
                for (int i = 0; i < numFrames; i++)
                {
                    sec.ReadChild(reader);                             // Extension
                }
                break;

            case Type.GeometryList:
                uint numMeshes = 0;
                sec.ReadChild(reader, (s) => {
                    numMeshes      = reader.ReadUInt32();
                    s["numMeshes"] = numMeshes;
                });                         // Info Struct
                for (int i = 0; i < numMeshes; i++)
                {
                    sec.ReadChild(reader);                             // Geometry
                }
                break;

            case Type.Geometry:
                sec.ReadChild(reader, (s) => {
                    s["geometry"] = Geometry.Read(reader);
                });                         // Info Struct
                sec.ReadChild(reader);      // Material list
                sec.ReadChild(reader, (s) => {
                    if (s.size > 0)
                    {
                        s.ReadChild(reader); // Bin Mesh
                    }
                });                          // Extension
                break;

            case Type.MaterialList:
                uint numMaterials       = 0;
                uint numUniqueMaterials = 0;
                sec.ReadChild(reader, (s) => {
                    numMaterials          = reader.ReadUInt32();
                    int[] materialIndices = new int[numMaterials];
                    for (int i = 0; i < numMaterials; i++)
                    {
                        materialIndices[i] = reader.ReadInt32();
                        if (materialIndices[i] == -1)
                        {
                            numUniqueMaterials++;
                        }
                    }
                    s["numMaterials"]       = numMaterials;
                    s["numUniqueMaterials"] = numUniqueMaterials;
                    s["materialIndices"]    = materialIndices;
                });                         // Info struct
                for (int i = 0; i < numUniqueMaterials; i++)
                {
                    sec.ReadChild(reader);                             // Material
                }
                break;

            case Type.Material:
                bool isTextured = false;
                sec.ReadChild(reader, (s) => {
                    Material mat  = Material.Read(reader);
                    s["material"] = mat;
                    isTextured    = mat.isTextured;
                });                         // Material struct
                if (isTextured)
                {
                    sec.ReadChild(reader);
                }
                sec.ReadChild(reader);                         // Extension
                if (sec.children.Last().data != null && sec.children.Last().data.Length > 0)
                {
                    l.print("Check material extension ending at " + reader.BaseStream.Position + "!");
                }
                break;

            case Type.Texture:
                sec.ReadChild(reader, (s) => {
                    s["texture"] = MaterialTexture.Read(reader);
                });                         // Info struct
                sec.ReadChild(reader);      // Texture name
                sec.ReadChild(reader);      // Alpha name
                sec.ReadChild(reader);      // Extension
                if (sec.children.Last().data != null && sec.children.Last().data.Length > 0)
                {
                    l.print("Check texturematerial extension ending at " + reader.BaseStream.Position + "!");
                }
                break;

            case Type.BinMeshPlg:
                sec["binMesh"] = BinMesh.Read(reader);
                break;

            case Type.Atomic:
                sec.ReadChild(reader, (s) => {
                    s["frameIndex"]    = reader.ReadUInt32();
                    s["geometryIndex"] = reader.ReadUInt32();
                    s["flags"]         = reader.ReadUInt32();
                    s["unused"]        = reader.ReadUInt32();
                });                         // Struct
                sec.ReadChild(reader);      // Extension
                break;

            default:
                if (specialRead == null)
                {
                    sec.data = reader.ReadBytes((int)size);
                }
                break;
            }

            return(sec);
        }