Ejemplo n.º 1
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);
                }
            }
        }
Ejemplo n.º 2
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);
                }
            }
        }