Esempio n. 1
0
        private void LoadMap()
        {
            if (MapListBox.SelectedValue == null)
                return;

            var basedir = ConfigurationManager.AppSettings["basedir"];
            string _SelectedMapName = ((KeyValuePair<int, string>)MapListBox.SelectedValue).Value;
            WDTGrid.Children.Clear();
            pbLoadMap.Value = 0d;

            var wdt = new WDTReader(basedir);
            if (File.Exists(System.IO.Path.Combine(basedir, "World\\Maps\\", _SelectedMapName, _SelectedMapName + ".wdt")))
            {
                Stopwatch _SW = new Stopwatch();
                BackgroundWorker _BackgroundWorker = new BackgroundWorker();
                _BackgroundWorker.WorkerReportsProgress = true;

                _BackgroundWorker.DoWork += new DoWorkEventHandler(
                    (object o, DoWorkEventArgs args) =>
                    {
                        _SW.Start();
                        BackgroundWorker _Worker = o as BackgroundWorker;
                        wdt.LoadWDT(System.IO.Path.Combine("World\\Maps\\", _SelectedMapName, _SelectedMapName + ".wdt"));
                        List<int[]> tiles = wdt.getTiles();

                        for (int i = 0; i < tiles.Count; i++)
                        {
                            if (fCancelMapLoading)
                                break;

                            Action _LoadTileAction = delegate() { LoadTile(basedir, tiles[i]); };
                            this.Dispatcher.Invoke(_LoadTileAction);
                            _Worker.ReportProgress((i * 100) / tiles.Count);
                        }

                        _Worker.ReportProgress(100);
                    });

                _BackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(
                    (object o, ProgressChangedEventArgs args) =>
                    {
                        pbLoadMap.Value = args.ProgressPercentage;
                    });

                _BackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
                (object sender, RunWorkerCompletedEventArgs args) =>
                {
                    fCancelMapLoading = false;
                    _SW.Stop();
                    Console.WriteLine("Loading {0} took {1} seconds", _SelectedMapName, _SW.Elapsed.TotalSeconds, _SW.ElapsedMilliseconds);
                });

                _BackgroundWorker.RunWorkerAsync();
            }
        }
Esempio n. 2
0
        public void LoadADT(uint wdtFileDataID, byte tileX, byte tileY, bool loadSecondaryADTs = true)
        {
            adtfile.x = tileX;
            adtfile.y = tileY;

            m2Files  = new List <string>();
            wmoFiles = new List <string>();
            blpFiles = new List <string>();

            uint rootFileDataID;
            uint tex0FileDataID;
            uint obj0FileDataID;

            if (CASC.FileExists(wdtFileDataID))
            {
                var wdtr = new WDTReader();
                wdtr.LoadWDT(wdtFileDataID);
                wdt            = wdtr.wdtfile;
                rootFileDataID = wdtr.tileFiles[(tileX, tileY)].rootADT;
Esempio n. 3
0
        public void LoadADT(uint wdtFileDataID, byte tileX, byte tileY, bool loadSecondaryADTs = true, string wdtFilename = "")
        {
            adtfile.x = tileX;
            adtfile.y = tileY;

            m2Files  = new List <string>();
            wmoFiles = new List <string>();
            blpFiles = new List <string>();

            uint rootFileDataID;
            uint tex0FileDataID;
            uint obj0FileDataID;

            if (CASC.FileExists(wdtFileDataID))
            {
                var wdtr = new WDTReader();
                wdtr.LoadWDT(wdtFileDataID);
                wdt = wdtr.wdtfile;

                if (wdtr.tileFiles.Count == 0)
                {
                    if (string.IsNullOrEmpty(wdtFilename))
                    {
                        throw new Exception("Require WDT filename for filename based ADT loading!");
                    }

                    var mapName = Path.GetFileNameWithoutExtension(wdtFilename);

                    // Still filename based
                    rootFileDataID = CASC.getFileDataIdByName("world/maps/" + mapName + "/" + mapName + "_" + tileX + "_" + tileY + ".adt");
                    obj0FileDataID = CASC.getFileDataIdByName("world/maps/" + mapName + "/" + mapName + "_" + tileX + "_" + tileY + "_obj0.adt");
                    tex0FileDataID = CASC.getFileDataIdByName("world/maps/" + mapName + "/" + mapName + "_" + tileX + "_" + tileY + "_tex0.adt");
                }
                else
                {
                    // ID based
                    rootFileDataID = wdtr.tileFiles[(tileX, tileY)].rootADT;
Esempio n. 4
0
        /* ROOT */
        public void LoadADT(string filename, bool loadSecondaryADTs = true)
        {
            m2Files  = new List <string>();
            wmoFiles = new List <string>();
            blpFiles = new List <string>();

            filename = Path.ChangeExtension(filename, ".adt");

            if (!CASC.cascHandler.FileExists(filename) || !CASC.cascHandler.FileExists(filename.Replace(".adt", "_obj0.adt")) || !CASC.cascHandler.FileExists(filename.Replace(".adt", "_tex0.adt")))
            {
                throw new FileNotFoundException("One or more ADT files for ADT " + filename + " could not be found.");
            }

            var mapname = filename.Replace("world\\maps\\", "").Substring(0, filename.Replace("world\\maps\\", "").IndexOf("\\"));

            if (CASC.cascHandler.FileExists("world\\maps\\" + mapname + "\\" + mapname + ".wdt"))
            {
                var wdtr = new WDTReader();
                wdtr.LoadWDT("world\\maps\\" + mapname + "\\" + mapname + ".wdt");
                wdt = wdtr.wdtfile;
            }
            else
            {
                throw new Exception("WDT does not exist, need this for MCAL flags!");
            }

            using (var adt = CASC.cascHandler.OpenFile(filename))
                using (var bin = new BinaryReader(adt))
                {
                    long position = 0;
                    int  MCNKi    = 0;
                    adtfile.chunks = new MCNK[16 * 16];

                    while (position < adt.Length)
                    {
                        adt.Position = position;

                        var chunkName = new string(bin.ReadChars(4).Reverse().ToArray());
                        var chunkSize = bin.ReadUInt32();

                        position = adt.Position + chunkSize;

                        switch (chunkName)
                        {
                        case "MVER":
                            uint version = bin.ReadUInt32();
                            if (version != 18)
                            {
                                throw new Exception("Unsupported ADT version!");
                            }
                            else
                            {
                                adtfile.version = version;
                            }
                            break;

                        case "MCNK":
                            adtfile.chunks[MCNKi] = ReadMCNKChunk(chunkSize, bin);
                            MCNKi++;
                            break;

                        case "MHDR":
                            adtfile.header = bin.Read <MHDR>();
                            break;

                        case "MH2O":
                        case "MFBO":
                        //model.blob stuff
                        case "MBMH":
                        case "MBBB":
                        case "MBMI":
                        case "MBNV":
                            break;

                        default:
                            throw new Exception(String.Format("{2} Found unknown header at offset {1} \"{0}\" while we should've already read them all!", chunkName, position, filename));
                        }
                    }
                }

            if (loadSecondaryADTs)
            {
                using (var adtobj0 = CASC.cascHandler.OpenFile(filename.Replace(".adt", "_obj0.adt")))
                {
                    ReadObjFile(adtobj0);
                }

                using (var adttex0 = CASC.cascHandler.OpenFile(filename.Replace(".adt", "_tex0.adt")))
                {
                    ReadTexFile(adttex0);
                }
            }
        }
Esempio n. 5
0
        private void LoadMap()
        {
            if (MapListBox.SelectedValue == null)
                return;

            string _SelectedMapName = ((KeyValuePair<int, string>)MapListBox.SelectedValue).Value;
            WDTGrid.Children.Clear();

            progressBar.Visibility = Visibility.Visible;
            progressLabel.Visibility = Visibility.Visible;

            progressBar.Value = 0;
            progressLabel.Content = "Loading minimap..";

            var wdt = new WDTReader();
            if (CASC.FileExists(System.IO.Path.Combine(@"world\maps\", _SelectedMapName, _SelectedMapName + ".wdt")))
            {
                Stopwatch _SW = new Stopwatch();
                BackgroundWorker _BackgroundWorker = new BackgroundWorker();
                _BackgroundWorker.WorkerReportsProgress = true;

                _BackgroundWorker.DoWork += new DoWorkEventHandler(
                    (object o, DoWorkEventArgs args) =>
                    {
                        _SW.Start();
                        BackgroundWorker _Worker = o as BackgroundWorker;
                        wdt.LoadWDT(System.IO.Path.Combine(@"world\maps\", _SelectedMapName, _SelectedMapName + ".wdt"));
                        List<int[]> tiles = wdt.getTiles();

                        for (int i = 0; i < tiles.Count; i++)
                        {
                            if (fCancelMapLoading)
                                break;

                            Action _LoadTileAction = delegate() { LoadTile(tiles[i]); };
                            this.Dispatcher.Invoke(_LoadTileAction);
                            _Worker.ReportProgress((i * 100) / tiles.Count, "Loading minimap..");
                        }

                        _Worker.ReportProgress(100, "Minimap loaded.");
                    });

                _BackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(
                    (object o, ProgressChangedEventArgs args) =>
                    {
                        progressBar.Value = args.ProgressPercentage;
                        progressLabel.Content = (string) args.UserState;
                    });

                _BackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
                (object sender, RunWorkerCompletedEventArgs args) =>
                {
                    fCancelMapLoading = false;
                    _SW.Stop();
                });

                _BackgroundWorker.RunWorkerAsync();
            }
        }
Esempio n. 6
0
        public void LoadADT(string filename, bool loadSecondaryADTs = true, bool filenamesOnly = false, bool localFile = false)
        {
            m2Files = new List<string>();
            wmoFiles = new List<string>();
            blpFiles = new List<string>();

            filename = Path.ChangeExtension(filename, ".adt");

            if (!localFile)
            {
                if (!CASC.FileExists(filename)) { new WoWFormatLib.Utils.MissingFile(filename); return; }
                if (!CASC.FileExists(filename.Replace(".adt", "_obj0.adt"))) { new WoWFormatLib.Utils.MissingFile(filename.Replace(".adt", "_obj0.adt")); return; }
                if (!CASC.FileExists(filename.Replace(".adt", "_obj1.adt"))) { new WoWFormatLib.Utils.MissingFile(filename.Replace(".adt", "_obj1.adt")); return; }
                if (!CASC.FileExists(filename.Replace(".adt", "_tex0.adt"))) { new WoWFormatLib.Utils.MissingFile(filename.Replace(".adt", "_tex0.adt")); return; }
                if (!CASC.FileExists(filename.Replace(".adt", "_tex1.adt"))) { new WoWFormatLib.Utils.MissingFile(filename.Replace(".adt", "_tex1.adt")); return; }
            }
            else
            {
                if (!File.Exists(filename)) { throw new Exception("Missing file!"); }
            }

            Stream adt;

            if (!localFile)
            {
                var mapname = filename.Replace("world\\maps\\", "").Substring(0, filename.Replace("world\\maps\\", "").IndexOf("\\"));

                if (CASC.FileExists("world\\maps\\" + mapname + "\\" + mapname + ".wdt"))
                {
                    var wdtr = new WDTReader();
                    wdtr.LoadWDT("world\\maps\\" + mapname + "\\" + mapname + ".wdt");
                    wdt = wdtr.wdtfile;
                }
                else
                {
                    throw new Exception("WDT does not exist, need this for MCAL flags!");
                }


                adt = CASC.OpenFile(filename);
            }
            else
            {
                adt = File.OpenRead(filename);
            }


            BlizzHeader chunk = null;
            if (filenamesOnly == false)
            {
                var bin = new BinaryReader(adt);
                long position = 0;
                int MCNKi = 0;
                adtfile.chunks = new MCNK[16 * 16];

                while (position < adt.Length)
                {
                    adt.Position = position;
                    chunk = new BlizzHeader(bin.ReadChars(4), bin.ReadUInt32());
                    chunk.Flip();
                    position = adt.Position + chunk.Size;

                    switch (chunk.ToString())
                    {
                        case "MVER":
                            uint version = bin.ReadUInt32();
                            if (version != 18)
                            {
                                throw new Exception("Unsupported ADT version!");
                            }
                            else
                            {
                                adtfile.version = version;
                            }
                            continue;
                        case "MCNK":
                            adtfile.chunks[MCNKi] = ReadMCNKChunk(chunk, bin);
                            MCNKi++;
                            continue;
                        case "MHDR":
                            adtfile.header = ReadMHDRChunk(chunk, bin);
                            continue;
                        case "MH2O":
                        case "MFBO":
                        //model.blob stuff
                        case "MBMH":
                        case "MBBB":
                        case "MBMI":
                        case "MBNV": continue;
                        default:
                            throw new Exception(String.Format("{2} Found unknown header at offset {1} \"{0}\" while we should've already read them all!", chunk.ToString(), position.ToString(), filename));
                    }
                }

                adt.Close();
            }

            if (loadSecondaryADTs)
            {
                using (var adtobj0 = CASC.OpenFile(filename.Replace(".adt", "_obj0.adt")))
                {
                    ReadObjFile(filename, adtobj0, ref chunk);
                }

                using (var adttex0 = CASC.OpenFile(filename.Replace(".adt", "_tex0.adt")))
                {
                    ReadTexFile(filename, adttex0, ref chunk);
                }
            }
        }
Esempio n. 7
0
        public int currentChunk; //very ghetto, much wow

        /* ROOT */

        //----------------------------------------------------------------------------------------------------------
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ///ADT READER
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //----------------------------------------------------------------------------------------------------------

        #region Split-File_ADT_READER
        public void LoadADT(string filename, bool loadSecondaryADTs = true)
        {
            m2Files  = new List <string>();
            wmoFiles = new List <string>();
            blpFiles = new List <string>();

            var WDTfile = filename.Substring(0, filename.Length - 10) + ".wdt";

            if (Managers.ArchiveManager.FileExists(WDTfile))
            {
                var wdtr = new WDTReader();
                wdtr.LoadWDT(WDTfile);
                wdt = wdtr.wdtfile;
            }
            else
            {
                throw new Exception("WDT does not exist, need this for MCAL flags!");
            }

            var adt = Managers.ArchiveManager.ReadThisFile(filename);

            using (var bin = new BinaryReader(adt))
            {
                long position = 0;
                var  MCNKi    = 0;
                adtfile.chunks = new MCNK[16 * 16];

                while (position < adt.Length)
                {
                    adt.Position = position;

                    var chunkName = new string(bin.ReadChars(4).Reverse().ToArray());
                    var chunkSize = bin.ReadUInt32();

                    position = adt.Position + chunkSize;

                    switch (chunkName)
                    {
                    case "MVER":
                        var version = bin.ReadUInt32();
                        if (version != 18)
                        {
                            throw new Exception("Unsupported ADT version!");
                        }
                        else
                        {
                            adtfile.version = version;
                        }
                        break;

                    case "MCNK":
                        adtfile.chunks[MCNKi] = ReadMCNKChunk(chunkSize, bin);
                        MCNKi++;
                        break;

                    case "MHDR":
                        adtfile.header = bin.Read <MHDR>();
                        break;

                    case "MH2O":
                        adtfile.mh2o = ReadMH20SubChunk(chunkSize, bin);
                        break;

                    case "MFBO":
                    //model.blob stuff
                    case "MBMH":
                    case "MBBB":
                    case "MBMI":
                    case "MBNV":
                        break;

                    default:
                        throw new Exception(string.Format("{2} Found unknown header at offset {1} \"{0}\" while we should've already read them all!", chunkName, position, filename));
                    }
                }
            }

            if (loadSecondaryADTs)
            {
                using (var adtobj0 = Managers.ArchiveManager.ReadThisFile(filename.Replace(".adt", "_obj0.adt")))
                {
                    ReadObjFile(adtobj0);
                }

                using (var adttex0 = Managers.ArchiveManager.ReadThisFile(filename.Replace(".adt", "_tex0.adt")))
                {
                    ReadTexFile(adttex0);
                }
            }
        }
Esempio n. 8
0
        public void LoadADT(string filename, bool loadSecondaryADTs = true, bool filenamesOnly = false, bool localFile = false)
        {
            m2Files  = new List <string>();
            wmoFiles = new List <string>();
            blpFiles = new List <string>();

            filename = Path.ChangeExtension(filename, ".adt");

            if (!localFile)
            {
                if (!CASC.FileExists(filename))
                {
                    new WoWFormatLib.Utils.MissingFile(filename); return;
                }
                if (!CASC.FileExists(filename.Replace(".adt", "_obj0.adt")))
                {
                    new WoWFormatLib.Utils.MissingFile(filename.Replace(".adt", "_obj0.adt")); return;
                }
                if (!CASC.FileExists(filename.Replace(".adt", "_obj1.adt")))
                {
                    new WoWFormatLib.Utils.MissingFile(filename.Replace(".adt", "_obj1.adt")); return;
                }
                if (!CASC.FileExists(filename.Replace(".adt", "_tex0.adt")))
                {
                    new WoWFormatLib.Utils.MissingFile(filename.Replace(".adt", "_tex0.adt")); return;
                }
                if (!CASC.FileExists(filename.Replace(".adt", "_tex1.adt")))
                {
                    new WoWFormatLib.Utils.MissingFile(filename.Replace(".adt", "_tex1.adt")); return;
                }
            }
            else
            {
                if (!File.Exists(filename))
                {
                    throw new Exception("Missing file!");
                }
            }

            Stream adt;

            if (!localFile)
            {
                var mapname = filename.Replace("world\\maps\\", "").Substring(0, filename.Replace("world\\maps\\", "").IndexOf("\\"));

                if (CASC.FileExists("world\\maps\\" + mapname + "\\" + mapname + ".wdt"))
                {
                    var wdtr = new WDTReader();
                    wdtr.LoadWDT("world\\maps\\" + mapname + "\\" + mapname + ".wdt");
                    wdt = wdtr.wdtfile;
                }
                else
                {
                    throw new Exception("WDT does not exist, need this for MCAL flags!");
                }


                adt = CASC.OpenFile(filename);
            }
            else
            {
                adt = File.OpenRead(filename);
            }


            BlizzHeader chunk = null;

            if (filenamesOnly == false)
            {
                var  bin      = new BinaryReader(adt);
                long position = 0;
                int  MCNKi    = 0;
                adtfile.chunks = new MCNK[16 * 16];

                while (position < adt.Length)
                {
                    adt.Position = position;
                    chunk        = new BlizzHeader(bin.ReadChars(4), bin.ReadUInt32());
                    chunk.Flip();
                    position = adt.Position + chunk.Size;

                    switch (chunk.ToString())
                    {
                    case "MVER":
                        uint version = bin.ReadUInt32();
                        if (version != 18)
                        {
                            throw new Exception("Unsupported ADT version!");
                        }
                        else
                        {
                            adtfile.version = version;
                        }
                        continue;

                    case "MCNK":
                        adtfile.chunks[MCNKi] = ReadMCNKChunk(chunk, bin);
                        MCNKi++;
                        continue;

                    case "MHDR":
                        adtfile.header = ReadMHDRChunk(chunk, bin);
                        continue;

                    case "MH2O":
                    case "MFBO":
                    //model.blob stuff
                    case "MBMH":
                    case "MBBB":
                    case "MBMI":
                    case "MBNV": continue;

                    default:
                        throw new Exception(String.Format("{2} Found unknown header at offset {1} \"{0}\" while we should've already read them all!", chunk.ToString(), position.ToString(), filename));
                    }
                }

                adt.Close();
            }

            if (loadSecondaryADTs)
            {
                using (var adtobj0 = CASC.OpenFile(filename.Replace(".adt", "_obj0.adt")))
                {
                    ReadObjFile(filename, adtobj0, ref chunk);
                }

                using (var adttex0 = CASC.OpenFile(filename.Replace(".adt", "_tex0.adt")))
                {
                    ReadTexFile(filename, adttex0, ref chunk);
                }
            }
        }
Esempio n. 9
0
        private static void Main(string[] args)
        {
            //string basedir = ConfigurationManager.AppSettings["basedir"];
            //LoadAllMaps(basedir);
            //LoadFromListfile("C:\\WoD\\18663listfile.txt", basedir);
            //var wdtreader = new WDTReader(basedir);
            //wdtreader.LoadWDT(@"World\Maps\BlackrockFoundryTrainDepot\BlackrockFoundryTrainDepot.wdt");

            CASC.InitCasc();
            Console.WriteLine("CASC loaded!");
            var wdtreader = new WDTReader();
            wdtreader.LoadWDT("World\\Maps\\EdgeOfRealityMount\\EdgeOfRealityMount.wdt");
            Console.WriteLine("DONE!");
            Console.ReadLine();
        }