Exemplo n.º 1
0
        public WmoGroup(mpq.Wrapper mpq_h, string name)
        {
            MemoryStream ms = new MemoryStream(mpq_h.GetFile(name));

            this.name = name;

            // read in chunk by chunk
            _mverChunk.Read(ms);
            _mogpChunk.Read(ms);

            // read MOPY chunk: material infos
            _mopyChunk.Read(ms);

            // read MOVI chunk: vertex indices
            _moviChunk.Read(ms);

            // read MOVT chunk: vertices
            _movtChunk.Read(ms);

            // read MONR chunk: normals
            _monrChunk.Read(ms);

            // read MOTV chunk: texture coordinates
            _motvChunk.Read(ms);

            // read MOBA chunk / skip
            _mobaChunk.Read(ms);

            if (ms.Position < ms.Length)
            {
                string _h = Util.hdr(ms);
                if (Util.hdr(ms) == "MOBS")
                {
                    // read MOBS chunk / skip
                    _mobsChunk.Read(ms);
                }

                // optional chunks, we need mobr
                if (Util.hdr(ms) == "MOLR")
                {
                    // read MOLR chunk / skip
                    _molrChunk.Read(ms);
                }

                if (Util.hdr(ms) == "MODR")
                {
                    // read MODS chunk
                    _modrChunk.Read(ms);
                }
            }

            // common model properties
            vertices = new Vertices_t();
            vertices.AddRange(_movtChunk.vertices);

            indices = new Indices_t();
            indices.AddRange(_moviChunk.indices);

            // filter non collide triangles
            filterTriangles();
        }
Exemplo n.º 2
0
        public bool Load(mpq.Wrapper mpq_h, string name)
        {
            byte[] buf = mpq_h.GetFile(name + ".adt");
            if (buf == null)
                return false;

            MemoryStream ms = new MemoryStream(buf);
            int chunk_size = 0;

            chunk_size = (int) _mverChunk.Read(ms);
            chunk_size = (int)_mhdrChunk.Read(ms);

            if (_mhdrChunk.mh2oOff != 0)
            {
                chunk_size = (int)_mh2oChunk.Read(ms);
            }

            _adtTerrain.Capacity = 256;
            for (int i = 0; i < 256; i++)
            {
                Terrain_s terrain = new Terrain_s();
                McnkChunk_s mcnk_chunk = parseMcnkChunk(ms, terrain);
                terrain.areaId = mcnk_chunk.areaId;
                terrain.position = mcnk_chunk.position;
                terrain.holes = mcnk_chunk.holes ;

                // deal w/ water
                if (i < _mh2oChunk.headers.Count)
                {
                    Mh2oChunk_s.Header_s hdr = _mh2oChunk.headers[i];
                    terrain.GenerateTerrain();
                    if ( hdr.renderMap == 0 &&
                        hdr.numLayers > 0 &&
                        hdr.infos[0].type == 0x2 )
                        hdr.renderMap = 0xffffffffffffffff;

                    if (hdr.renderMap != 0)
                    {
                        for (int wy = 0; wy < 8; wy++)
                        {
                            for (int wx = 0; wx < 8; wx++)
                            {
                                int cell_idx = wy * 8 + wx; // water cell index
                                // Do we have water in this cell?
                                if ((hdr.renderMap & (1UL << cell_idx)) != 0)
                                {
                                    int terr_idx = cell_idx; // terrain index
                                    // A terrain cell is made up of 12 indices which describe
                                    // 4 polygons that make up a cell in our map chunk.
                                    for (int ii = 0; ii < 12; ii++)
                                    {
                                        terrain.indices[terr_idx * 12 + ii] = -1;  // mark every index with uint max
                                    }
                                }
                            }
                        }
                    }
                    Util.removeGeometry(ref terrain.indices, ref terrain.vertices, ref terrain.normals);
                }

                _adtTerrain.Add(terrain);
            }
            return true;
        }
Exemplo n.º 3
0
        public M2(mpq.Wrapper mpq_h, string name)
        {
            MemoryStream ms = new MemoryStream(mpq_h.GetFile(name));

            // read in chunk by chunk
            ms.Read(id, 0, id.Length);
            ms.Read(version, 0, id.Length);
            nameLength = (uint) ms.ReadInt32();
            nameOff = (uint)ms.ReadInt32();
            flags = (uint)ms.ReadInt32();

            ms.Read(pad0, 0, pad0.Length);

            numVertices = (uint) ms.ReadInt32();
            verticesOff = (uint)ms.ReadInt32();

            ms.Read(pad1, 0, pad1.Length);

            numBoundingTriangles = (uint)ms.ReadInt32();
            boundingTriangleOff = (uint)ms.ReadInt32();
            numBoundingVertices = (uint)ms.ReadInt32();
            boundingVerticesOff = (uint)ms.ReadInt32();
            numBoundingNormals = (uint)ms.ReadInt32();
            boundingNormalsOff = (uint)ms.ReadInt32();

            isCollide = numBoundingTriangles > 0;

            // ignore non collidable M2s
            if (!isCollide)
                return;

            // get M2 model name
            ms.Position = nameOff;
            byte[] _b = new byte[nameLength];
            ms.Read(_b, 0, (int) nameLength);
            System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
            _m2name = enc.GetString(_b);

            if (numVertices > 0)
            {
                ms.Position = verticesOff;
                for (int i = 0; i < numVertices; i++)
                {
                    Vector3 v;
                    v.X = ms.ReadFloat(); v.Y = ms.ReadFloat(); v.Z = ms.ReadFloat();
                    _vertices.Add(v);
                }
            }

            // get bounding triangles
            if (numBoundingTriangles > 0)
            {
                ms.Position = boundingTriangleOff;
                for (int i = 0; i < numBoundingTriangles; i++)
                {
                    // in the file those are 16bit, so read short
                    _boundingIndices.Add(ms.ReadShort());
                }
            }

            // get bounding vertices
            if (numBoundingVertices > 0)
            {
                ms.Position = boundingVerticesOff;
                for (int i = 0; i < numBoundingVertices; i++)
                {
                    Vector3 v;
                    v.X = ms.ReadFloat(); v.Y = ms.ReadFloat(); v.Z = ms.ReadFloat();
                    _boundingVertices.Add(v);
                }
            }

            // get bounding normals
            if (numBoundingNormals > 0)
            {
                ms.Position = boundingNormalsOff;
                for (int i = 0; i < numBoundingNormals; i++)
                {
                    Vector3 v;
                    v.X = ms.ReadFloat(); v.Y = ms.ReadFloat(); v.Z = ms.ReadFloat();
                    _boundingNormals.Add(v);
                }
            }

            bbox = BoundingBox.CreateFromPoints(_boundingVertices);
        }
Exemplo n.º 4
0
        public bool Load(mpq.Wrapper mpq_h, string map_name)
        {
            byte[] buf = mpq_h.GetFile(map_name + "_obj0.adt") ;
            if (buf == null)
                return false;

            MemoryStream ms = new MemoryStream(buf);
            uint chunk_size = 0;

            // read MVER chunk
            chunk_size = _mverChunk.Read(ms);
            // read MMDX chunk
            chunk_size = _mmdxChunk.Read(ms);
            // read MMID chunk
            chunk_size = _mmidChunk.Read(ms);
            // read MWMO chunk
            chunk_size = _mwmoChunk.Read(ms);
            // read MMID chunk
            chunk_size = _mwidChunk.Read(ms);
            // read MDDF chunk
            chunk_size = _mddfChunk.Read(ms);
            // read MODF chunk
            chunk_size = _modfChunk.Read(ms);

            // parse collected data
            parseObjectReferences(ms);
            loadObjectReferences(mpq_h);
            return true;
        }
Exemplo n.º 5
0
        public WmoModel(mpq.Wrapper mpq_h, string name)
        {
            MemoryStream ms = new MemoryStream(mpq_h.GetFile(name)) ;

            // read in chunk by chunk
            _mverChunk.Read(ms);
            _mohdChunk.Read(ms);

            // read MOTX filenames
            _motxChunk.Read(ms);

            // read MOTM chunk and material structs for each BLP inside
            _momtChunk.Read(ms);

            // read MOGN group names
            _mognChunk.Read(ms);

            // read MOGI chunk and its group informations
            _mogiChunk.Read(ms);

            // read MOSB chunk: sky box
            _mosbChunk.Read(ms);

            // read MOPV chunk: portal vertices
            _mopvChunk.Read(ms);

            // read MOPT chunk: portal informations
            _moptChunk.Read(ms);

            // read MOPR chunk: portal refererences
            _moprChunk.Read(ms);

            // read MOVV chunk
            _movvChunk.Read(ms);

            // read MOVB chunk, skip
            _movbChunk.Read(ms);

            // read MOLT chunk: lighting information, skip
            _moltChunk.Read(ms);

            // read MODS chunk: doodad sets
            _modsChunk.Read(ms);

            // read MODN chunk: doodad names
            _modnChunk.Read(ms);

            // read MODD chunk: doodad informations
            _moddChunk.Read(ms);

            if (name.IndexOf("ORCHOVELORGRIMMAR") > 0)
            {
                int i = 1;
            }

            // load groups
            loadGroups(mpq_h, name) ;
        }
Exemplo n.º 6
0
        public Wdt(mpq.Wrapper mpq_h, string file)
        {
            try
            {
                MemoryStream ms = new MemoryStream(mpq_h.GetFile(file));

                uint chunk_size = 0;

                // read in chunk by chunk
                chunk_size = _mverChunk.Read(ms);
                chunk_size = _mphdChunk.Read(ms);
                chunk_size = _mainChunk.Read(ms);

                for (int y = 0; y < 64; y++)
                {
                    for (int x = 0; x < 64; x++)
                    {
                        uint f = _mainChunk._asyncObjects[y * 64 + x].flags;
                        // get all tiles with flag & 1
                        if ((_mainChunk._asyncObjects[y * 64 + x].flags & 2) == 0)
                        {
                            Vector2 co = new Vector2(x, y);
                            _adtCoords.Add(co);
                        }
                        else
                            continue;
                    }
                }
            }
            catch
            {
            }
        }
Exemplo n.º 7
0
        public WDBC(mpq.Wrapper mpq_h)
        {
            MemoryStream ms;
            List<uint> raw = new List<uint>();
            byte[] b;

            // read Map.dbc
            ms = new MemoryStream(mpq_h.GetFile(@"DBFilesClient\Map.dbc"));
            base.Read(ms, "CBDW");
            fieldCount = ms.ReadInt32();
            recordSize = ms.ReadInt32();
            stringSize = ms.ReadInt32();

            for (uint i = 0; i < size; i++)
            {
                for (int j = 0; j < fieldCount; j++)
                {
                    raw.Add((uint)ms.ReadInt32());
                }
            }
            b = new byte[stringSize];
            ms.Read(b, 0, stringSize);

            for (int i = 0; i < size; i++)
            {
                int mapId = (int)raw[i * fieldCount + 0];
                string file = Util.ExtractString(b, (int)raw[i * fieldCount + 1]);
                worldIdToName.Add(mapId, file);
            }
            ms.Close();

            // read AreaTable

            ms = new MemoryStream(mpq_h.GetFile(@"DBFilesClient\AreaTable.dbc"));
            base.Read(ms, "CBDW");

            fieldCount = ms.ReadInt32();
            recordSize = ms.ReadInt32();
            stringSize = ms.ReadInt32();

            raw.Clear();
            for (uint i = 0; i < size; i++)
            {
                for (int j = 0; j < fieldCount; j++)
                {
                    raw.Add((uint) ms.ReadInt32());
                }
            }
            b = new byte[stringSize] ;
            ms.Read(b, 0, stringSize);

            for (int i = 0; i < size; i++)
            {
                int areaId = (int) raw[i * fieldCount + 0];
                int worldId = (int)raw[i * fieldCount + 1];
                int parent = (int)raw[i * fieldCount + 2];
                string name = Util.ExtractString(b, (int) raw[i * fieldCount + 11]);
                areas.Add(new areaInfo(worldId, name));
            }
            ms.Close();
        }