public static async Task <Dictionary <long, List <MythicPackage> > > GetMythicHashList(string warfolder)
        {
            Dictionary <long, List <MythicPackage> > results = new Dictionary <long, List <MythicPackage> >();
            await Task.Run(() =>
            {
                foreach (string file in Directory.GetFiles(warfolder, "*.MYP"))
                {
                    MythicPackage p;
                    if (Enum.TryParse <MythicPackage>(Path.GetFileNameWithoutExtension(file).ToUpper(), out p))
                    {
                        var myp = new MYP();
                        using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read))
                        {
                            myp.Load(stream);
                            foreach (long key in myp.Files.Keys)
                            {
                                if (!results.ContainsKey(key))
                                {
                                    results[key] = new List <MythicPackage>();
                                }
                                results[key].Add(p);
                            }
                        }
                    }
                }
            });

            return(results);
        }
        public static byte[] GetAssetData(string warfolder, Asset asset, int mypIndex)
        {
            string path = asset.Path;
            uint   ph = 0, sh = 0;

            MYP.HashWAR(path, 0xDEADBEEF, out ph, out sh);
            long key = ((long)ph << 32) + sh;

            byte[] data = null;
            if (MYPHash.Hashes.ContainsKey(key))
            {
                var myp = new MYP();
                using (var stream = new FileStream(Path.Combine(warfolder, Hashes[key][mypIndex].ToString() + ".myp"), FileMode.Open, FileAccess.ReadWrite))
                {
                    myp.Load(stream);
                    var mypFile = myp.GetByFilename(asset.Path);
                    if (mypFile != null)
                    {
                        data = myp.ReadFile(stream, mypFile);
                    }
                }
            }

            return(data);
        }
        private static Asset BuildPath(List <string> tokens, Asset parent = null)
        {
            if (parent == null)
            {
                if (!Assets.ContainsKey(tokens[0]))
                {
                    Assets[tokens[0]] = new Asset()
                    {
                        Name = tokens[0]
                    };
                }
                parent = Assets[tokens[0]];
                DeHash[MYP.HashWAR(parent.Path)] = parent.Path;

                BuildPath(tokens.GetRange(1, tokens.Count - 1), parent);
            }
            else
            {
                if (tokens.Count > 1)
                {
                    Asset asset = null;
                    if (!parent.Assets.ContainsKey(tokens[0]))
                    {
                        parent.Assets[tokens[0]] = new Asset()
                        {
                            Name = tokens[0]
                        };
                        asset        = parent.Assets[tokens[0]];
                        asset.Parent = parent;
                        DeHash[MYP.HashWAR(asset.Path)] = asset.Path;
                    }
                    else
                    {
                        asset = parent.Assets[tokens[0]];
                    }

                    BuildPath(tokens.GetRange(1, tokens.Count - 1), asset);
                }
                else
                {
                    parent.Assets[tokens[0]] = new Asset()
                    {
                        Name   = tokens[0],
                        Parent = parent
                    };
                    var asset = parent.Assets[tokens[0]];

                    DeHash[MYP.HashWAR(asset.Path)] = asset.Path;
                }
            }
            return(null);
        }
 private void txtFileName_TextChanged(object sender, EventArgs e)
 {
     lblHash.Text    = Convert.ToString(MYP.HashWAR(txtFileName.Text), 16);
     txtResults.Text = "";
     if (MYPHash.Hashes.ContainsKey(MYP.HashWAR(txtFileName.Text)))
     {
         txtResults.Text = "Found in " + MYPHash.Hashes[MYP.HashWAR(txtFileName.Text)].ToString();
     }
     else
     {
         txtResults.Text = "Not Found";
     }
 }
        public static async Task SaveAsset(string warfolder, Asset asset, byte[] data, int mypIndex)
        {
            List <MythicPackage> p = Hashes[MYP.HashWAR(asset.Path)];

            using (var stream = new FileStream(Path.Combine(warfolder, p[mypIndex].ToString() + ".myp"), FileMode.Open, FileAccess.ReadWrite))
            {
                var myp = new MYP();
                myp.Load(stream);
                var mypFile = myp.GetByFilename(asset.Path);
                if (mypFile != null)
                {
                    myp.WriteFile(stream, mypFile, data);
                }
            }
        }
        public static byte[] GetAssetData(string warfolder, long key, int mypIndex)
        {
            byte[] data = null;
            if (MYPHash.Hashes.ContainsKey(key))
            {
                var myp = new MYP();
                using (var stream = new FileStream(Path.Combine(warfolder, Hashes[key][mypIndex].ToString() + ".myp"), FileMode.Open, FileAccess.ReadWrite))
                {
                    myp.Load(stream);
                    var mypFile = myp.GetByHash(key);
                    if (mypFile != null)
                    {
                        data = myp.ReadFile(stream, mypFile);
                    }
                }
            }

            return(data);
        }