Example #1
0
        public void Add(mpq.Wrapper mpq_h, string continent, int x, int y)
        {
            uint id = (uint) ((x << 16)+(y&0xff)) ;

            string path = String.Format(@"world\maps\{0}\{0}_{1}_{2}", continent, x, y);

            if (!_adts.ContainsKey(id))
            {
                if (!_obj0s.ContainsKey(id))
                {
                    Obj0 obj0 = new Obj0();
                    if (obj0.Load(mpq_h, path))
                    {
                        if (obj0.Models.Count == 0)
                            return;

                        _obj0s.Add(id, obj0);
                    }
                }

                if (_adts.ContainsKey(id))
                    return;

                Adt adt = new Adt();
                if (adt.Load(mpq_h, path))
                    _adts.Add(id, adt);
            }
        }
Example #2
0
        static void dumpContinent(mpq.Wrapper mpq_h, string continent)
        {
            Console.WriteLine(@"Dumping " + continent);
            wow.Map map = new wow.Map();
            string wdt_file = mpq_h.FindFile("*"+continent + ".wdt")[0];
            wow.Wdt wdt = new wow.Wdt(mpq_h, wdt_file);
            Vertices_t v = new Vertices_t();
            Indices32_t i = new Indices32_t();
            Normals_t n = new Normals_t();
            float tile_step = 533 + (1 / 3.0f);
            float border_width = tile_step / 16;
            Vector3 border = new Vector3(border_width, 0, border_width);

            //wdt._adtCoords.Clear();
            //wdt._adtCoords.Add(new Vector2(40, 29));
            //wdt._adtCoords.Add(new Vector2(40, 30));
            foreach (Vector2 coords in wdt._adtCoords)
            {
                BoundingBox bb;
                bb.Min = new Vector3((coords.X - 32) * tile_step, float.MinValue, (coords.Y - 32) * tile_step);
                bb.Max = bb.Min + new Vector3(tile_step, float.MaxValue * 2, tile_step);
                Vector2 _min, _max;
                BoundingBox gbb = bb;
                gbb.Min -= border;
                gbb.Max += border;
                _min = wow.Util.coords2map(gbb.Min);
                _max = wow.Util.coords2map(gbb.Max);
                for (int _x = (int)_min.X; _x <= _max.X; _x++)
                {
                    for (int _y = (int)_min.Y; _y <= _max.Y; _y++)
                    {
                        Console.WriteLine(String.Format(@"Loading : {0} {1} {2}", continent, _x, _y));
                        map.Add(mpq_h, continent, _x, _y);
                    }
                }

                //map.Add(mpq_h, "kalimdor", 40, 29);
                //                map.Add(mpq_h, "kalimdor", 40, 30);

                string fn = String.Format("{0}_{1}_{2}", continent, (int)coords.X, (int)coords.Y);
                string path = @"C:\g\maps\" + continent + @".mesh\";
                string filename = path + fn + ".mesh" ;

                Console.Write("Tiling " + coords.X + " x " + coords.Y);

                int ov = map.GetTile(gbb, ref v, ref i);
                if (ov > 0)
                {
                    Console.WriteLine(" - " + v.Count + " vertices");

                    if (v.Count > 0)
                    {
                        Vector3 v_min, v_max;
                        v_min = v_max = v[0];
                        v.ForEach(xx =>
                        {
                            v_min.X = Math.Min(v_min.X, xx.X); v_min.Y = Math.Min(v_min.Y, xx.Y); v_min.Z = Math.Min(v_min.Z, xx.Z);
                            v_max.X = Math.Max(v_max.X, xx.X); v_max.Y = Math.Max(v_max.Y, xx.Y); v_max.Z = Math.Max(v_max.Z, xx.Z);
                        });
                        //StreamWriter fs = new StreamWriter(@"C:\Dev\wow\Nav\recastnavigation.svn\RecastDemo\Bin\Meshes\" + fn + ".obj");
                        //v.ForEach(xx => fs.WriteLine("v {0} {1} {2}", xx.X, xx.Y, xx.Z));
                        //for (int ii = 0; ii < i.Count; ii += 3)
                        //{
                        //    fs.WriteLine("f {0} {1} {2}", i[ii + 0] + 1, i[ii + 1] + 1, i[ii + 2] + 1);
                        //}
                        //fs.Close();

                        Directory.CreateDirectory(path);
                        BinaryWriter bs = new BinaryWriter(File.Create(filename));
                        bb.Min.Y = v_min.Y;
                        bb.Max.Y = v_max.Y;

                        bs.Write(bb.Min.X);
                        bs.Write(bb.Min.Y);
                        bs.Write(bb.Min.Z);
                        bs.Write(bb.Max.X);
                        bs.Write(bb.Max.Y);
                        bs.Write(bb.Max.Z);
                        bs.Write(v_min.X);
                        bs.Write(v_min.Y);
                        bs.Write(v_min.Z);

                        bs.Write(v.Count);
                        bs.Write(i.Count);
                        v.ForEach(xx => { bs.Write(xx.X); bs.Write(xx.Y); bs.Write(xx.Z); });
                        i.ForEach(xx => bs.Write(xx));
                        bs.Close();
                    }
                }
                else
                    Console.WriteLine(" - is empty");

                i.Clear();
                v.Clear();

                map.Clear();
            }
        }
Example #3
0
 static void loadMpq(mpq.Wrapper mpq_h, string filename)
 {
     Console.WriteLine("Loading " + filename + " ");
     mpq_h.Add(filename);
 }
Example #4
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;
        }
Example #5
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();
        }
Example #6
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);
        }
Example #7
0
        void loadObjectReferences(mpq.Wrapper mpq_h)
        {
            models = new List<Model>();

            foreach (ObjectReference_s oref in _objectRefs)
            {
                // doodas
                foreach (uint oref_index in oref.doodadIndices)
                {
                    Doodad_s doodad = getDoodad(oref_index);

                    // find unique identifier in map, only one uid can be present
                    if (loaded_objects.ContainsKey(doodad.info.uid))
                        continue;
                    loaded_objects.Add(doodad.info.uid, true);

                    M2 m2 = new M2(mpq_h, doodad.name);
                    if (!m2.isCollide)
                        continue;

                    // doodad buffers
                    Indices32_t m2_i;
                    Vertices_t m2_v ;
                    m2_v = Util.transformVertices(doodad.info.pos, doodad.info.rot, doodad.info.scale/1024f, m2._boundingVertices);
                    m2_i = m2._boundingIndices;
                    //

                    Model model = new Model();
                    model.uid = doodad.info.uid;
                    model.name = doodad.name;
                    model.indices = m2_i;
                    model.vertices = m2_v;
                    model.bbox = BoundingBox.CreateFromPoints(m2_v);
                    models.Add(model);
                }

                // wmo
                foreach (uint oref_index in oref.wmoIndices)
                {
                    Wmo_s wmo = getWmo(oref_index);

                    if (loaded_objects.ContainsKey(wmo.info.uid))
                        continue;
                    loaded_objects.Add(wmo.info.uid, true);

                    WmoModel wmo_model = new WmoModel(mpq_h, wmo.name);

                    foreach (WmoGroup wg in wmo_model._wmoGroups)
                    {
                        if (wg.vertices.Count == 0)
                            continue;

                        Model model = new Model();
                        model.uid = wmo.info.uid;
                        model.name = wg.name;

                        Vertices_t w_v = Util.transformVertices(wmo.info.pos, wmo.info.rot, 1f, wg.vertices);
                        Indices32_t w_i = wg.indices;
                        model.indices = w_i;
                        model.vertices = w_v;
                        model.bbox = BoundingBox.CreateFromPoints(w_v);
                        models.Add(model);
                    }

                    if (wmo.info.doodadSet < wmo_model._modsChunk.doodadSets.Count)
                    {
                        ModsChunk_s.DoodadSet_s _dset = wmo_model._modsChunk.doodadSets[wmo.info.doodadSet] ;
                        // interior doodas set
                        for (int modd_idx = (int)_dset.firstIndex; modd_idx < _dset.firstIndex + _dset.numDoodads; modd_idx++)
                        {
                            ModdChunk_s.DoodadInformation_s info = wmo_model._moddChunk.infos[modd_idx];
                            string m2file = info.file;
                            M2 m2 = new M2(mpq_h, m2file);

                            if (!m2.isCollide)
                                continue;

                            // doodad buffers
                            Indices32_t m2_i;
                            Vertices_t m2_v = new Vertices_t();

                            m2_i = m2._boundingIndices;
                            foreach (Vector3 v in m2._boundingVertices)
                            {
                                Vector3 _v;
                                _v = Vector3.Transform(v, info.rotation);
                                _v *= info.scale;
                                _v += info.position;
                                m2_v.Add(_v);
                            }
                            //
                            m2_v = Util.transformVertices(wmo.info.pos, wmo.info.rot, 1f, m2_v);
                            Model model = new Model();
                            model.uid = info.id;
                            model.name = m2file;
                            model.indices = m2_i;
                            model.vertices = m2_v;
                            model.bbox = BoundingBox.CreateFromPoints(m2_v);
                            models.Add(model);
                        }
                    }
                }
            }
        }
Example #8
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;
        }
Example #9
0
        public void loadGroups(mpq.Wrapper mpq_h, string wmo_name)
        {
            string group_name = wmo_name.Substring(0, wmo_name.Length - 4);

            for (int i = 0; i < _mohdChunk.numGroups; i++)
            {
                string filename = String.Format("{0}_{1,3:000}.wmo", group_name, i);
                WmoGroup _g = new WmoGroup(mpq_h, filename);
                _wmoGroups.Add(_g);
            }

            _moddChunk.infos.ForEach(info =>
                {
                    string name = Util.ExtractString(_modnChunk.doodadNames, (int) info.id);
                    info.file = name.Substring(0, name.Length - 4) + ".M2";
                }
            );
        }
Example #10
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) ;
        }
Example #11
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
            {
            }
        }
Example #12
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();
        }