Example #1
0
        private void RunWzFilesExtraction(object param)
        {
            ChangeApplicationState(false);
            string[]          wzFilesToDump = (string[])((object[])param)[0];
            string            baseDir       = (string)((object[])param)[1];
            WzMapleVersion    version       = (WzMapleVersion)((object[])param)[2];
            IWzFileSerializer serializer    = (IWzFileSerializer)((object[])param)[3];

            UpdateProgressBar(MainPanel.mainProgressBar, 0, false, true);
            UpdateProgressBar(MainPanel.mainProgressBar, wzFilesToDump.Length, true, true);
            foreach (string wzpath in wzFilesToDump)
            {
                if (WzTool.IsListFile(wzpath))
                {
                    Warning.Error(string.Format(HaRepacker.Properties.Resources.MainListWzDetected, wzpath));
                    continue;
                }
                WzFile f = new WzFile(wzpath, version);
                f.ParseWzFile();
                serializer.SerializeFile(f, Path.Combine(baseDir, f.Name));
                f.Dispose();
                UpdateProgressBar(MainPanel.mainProgressBar, 1, false, false);
            }
            threadDone = true;
        }
Example #2
0
        void loadDifferences()
        {
            // here we would query a website for latest patch rev.
            WzMapleVersion vrs     = WzMapleVersion.GMS; // is classic old GMS??
            string         imgPath = textBox1.Text;
            string         wzPath  = textBox2.Text;

            Console.WriteLine("imgPath: " + imgPath + ", wzPath: " + wzPath);
            WzFile affected = new WzFile(wzPath, vrs);

            affected.ParseWzFile();
            char[] split   = { '\\', '/' };
            string imgName = imgPath.Split(split)[imgPath.Split(split).Length - 1].Trim();

            Console.WriteLine("imgName: " + imgName);
            WzImage    toPatch = affected.WzDirectory.GetImageByName(imgName);
            FileStream stream  = File.OpenRead(imgPath);
            WzImage    img     = new WzImage("-" + imgName, stream, vrs);

            img.ParseImage();
            toPatch.ParseImage();
            toPatch.ClearProperties();
            toPatch.AddProperties(img.WzProperties);
            affected.WzDirectory.GetImageByName(imgName).changed = true;
            affected.SaveToDisk(wzPath + ".new");
            affected.Dispose();
            stream.Close();
            while (!tryDelete(wzPath))
            {
                Thread.Sleep(1000);             // ensure that we can rename the file
            }
            File.Move(wzPath + ".new", wzPath); // rewrite w/ patched file
            button1.Text = "Done!";
        }
Example #3
0
        /// <summary>
        /// Checks if the given path is the root of .wz files (at least for Character.wz)
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static bool PathIsValid(string path)
        {
            WzFile characterFile = new WzFile(PathIO.Combine(path, "Character.wz"), WzMapleVersion.CLASSIC);

            try
            {
                try
                {
                    try
                    {
                        characterFile.ParseWzFile();
                    }
                    catch (NotSupportedException)
                    {
                        return(false);
                    }
                }
                catch (FileNotFoundException)
                {
                    return(false);
                }
            }
            catch (DirectoryNotFoundException)
            {
                return(false);
            }
            finally
            {
                characterFile.Dispose();
                characterFile = null;
            }
            return(true);
        }
Example #4
0
        static void Main(string[] args)
        {
            // Refer to MainForm::RunWzFilesExtraction
            if (args.Length < 2)
            {
                Console.WriteLine("Wrong number of arguments.");
                Console.WriteLine("Usage: <WZ File> <Output Directory>");
                System.Environment.Exit(1);
            }
            var wzPath  = args[0];
            var baseDir = args[1];

            Console.WriteLine($"Exporting {wzPath} to {baseDir}");
            WzMapleVersion    version    = WzMapleVersion.GMS;
            IWzFileSerializer serializer = new WzJsonSerializer(false);

            if (!Directory.Exists(baseDir))
            {
                Directory.CreateDirectory(baseDir);
            }
            WzFile wz = new WzFile(wzPath, version);

            wz.ParseWzFile();
            serializer.SerializeFile(wz, Path.Combine(baseDir, wz.Name));
            wz.Dispose();
        }
Example #5
0
        public static bool TryBruteforcingWzIVKey(string wzPath, byte[] wzIvKey)
        {
            using (WzFile wzf = new WzFile(wzPath, wzIvKey))
            {
                string            parseErrorMessage = string.Empty;
                WzFileParseStatus parseStatus       = wzf.ParseMainWzDirectory(true);
                if (parseStatus != WzFileParseStatus.Success)
                {
                    wzf.Dispose();
                    return(false);
                }
                if (wzf.WzDirectory.WzImages.Count > 0 && wzf.WzDirectory.WzImages[0].Name.EndsWith(".img"))
                {
                    wzf.Dispose();
                    return(true);
                }

                wzf.Dispose();
            }
            return(false);
        }
Example #6
0
        /// <summary>
        /// Attempts to bruteforce the WzKey with a given WZ file
        /// </summary>
        /// <param name="wzPath"></param>
        /// <param name="wzIvKey"></param>
        /// <returns>The probability. Normalized to 100</returns>
        public static bool TryBruteforcingWzIVKey(string wzPath, byte[] wzIvKey)
        {
            using (WzFile wzf = new WzFile(wzPath, wzIvKey))
            {
                string parseErrorMessage  = string.Empty;
                bool   parsedSuccessfully = wzf.LazyParseWzFile(out parseErrorMessage);
                if (!parsedSuccessfully)
                {
                    wzf.Dispose();
                    return(false);
                }
                if (wzf.WzDirectory.WzImages.Count > 0 && wzf.WzDirectory.WzImages[0].Name.EndsWith(".img"))
                {
                    wzf.Dispose();
                    return(true);
                }

                wzf.Dispose();
            }
            return(false);
        }
Example #7
0
        private static uint getItemIMGCRC(int itemID, bool isRaw)
        {
            uint             linesum = 0;
            WzCanvasProperty image   = null;
            string           type    = Database.getItemType(itemID);

            if (type != "Equip")
            {
                while (Utilities.IsFileLocked(new FileInfo(@"WZFiles/Item.wz")))
                {
                    Thread.Sleep(1000);
                }
                WzFile wzFile = new WzFile(@"WZFiles/Item.wz", Constants.WzType);
                wzFile.ParseWzFile();
                if (wzFile.WzDirectory != null)
                {
                    WzDirectory dir = null;
                    dir = wzFile.WzDirectory.GetDirectoryByName(type);
                    if (dir == null)
                    {
                        return(linesum);
                    }
                    image = Database.getItemBitMap(dir, wzFile, itemID, isRaw);
                    if (image != null)
                    {
                        linesum = image.PngProperty.getLineSum();
                        wzFile.Dispose();
                    }
                    else
                    {
                        wzFile.Dispose();
                        linesum = getItemIMGCRC(Database.crcID, isRaw);
                    }
                }
            }
            else
            {
            }
            return(linesum);
        }
        public void UnloadWzFile(WzFile file)
        {
            lock (wzFiles)
            {
                if (wzFiles.Contains(file)) // check again within scope
                {
                    file.Dispose();

                    ((WzNode)file.HRTag).DeleteWzNode();
                    wzFiles.Remove(file);
                }
            }
        }
Example #9
0
        /// <summary>
        /// clears all collections, closes underlying file readers
        /// then calls the garbage collector for each loaded WZ file
        /// </summary>
        private void DisposeWzFiles()
        {
            StringWz?.Dispose();
            ItemWz?.Dispose();
            CharacterWz?.Dispose();
            MapWz?.Dispose();
            MobWz?.Dispose();
            SkillWz?.Dispose();
            NpcWz?.Dispose();

            StringWz    = null;
            ItemWz      = null;
            CharacterWz = null;
            MapWz       = null;
            MobWz       = null;
            SkillWz     = null;
            NpcWz       = null;
        }
Example #10
0
        /// <summary>
        /// clears all collections, closes underlying file readers
        /// then calls the garbage collector for each loaded WZ file
        /// </summary>
        private void DisposeWzFiles()
        {
            stringWz?.Dispose();
            itemWz?.Dispose();
            characterWz?.Dispose();
            mapWz?.Dispose();
            mobWz?.Dispose();
            skillWz?.Dispose();
            npcWz?.Dispose();

            stringWz    = null;
            itemWz      = null;
            characterWz = null;
            mapWz       = null;
            mobWz       = null;
            skillWz     = null;
            npcWz       = null;
        }
Example #11
0
        public static void Initialize()
        {
            var sw = Stopwatch.StartNew();

            Styles       = new AvailableStylesDataLoader().Load();
            CreationData = new CreationDataLoader().Load();
            Skills       = new SkillsLoader().Load();
            Mobs         = new MobsLoader().Load();
            Npcs         = new NpcsLoader().Load();
            MobSkills    = new MobSkillsLoader().Load();
            Strings      = new StringLoader().Load();
            Quests       = new QuestsLoader().Load();
            Quizzes      = new QuizzesLoader().Load();
            Maps         = new MapsLoader().Load();
            Items        = new ItemsLoader().Load();
            WzFile?.Dispose();

            sw.Stop();

            Logger.Information("Data loaded in {0}ms.", sw.ElapsedMilliseconds);
        }
Example #12
0
        /// <summary>
        /// Gets all the info to be shown by DataGrid
        /// </summary>
        /// <param name="chosenPath"></param>
        /// <returns></returns>
        public static List <Familiar> LoadCollectionData(string chosenPath)
        {
            List <Familiar> familiars     = new List <Familiar>();
            WzFile          characterFile = new WzFile(PathIO.Combine(chosenPath, "Character.wz"), WzMapleVersion.CLASSIC);
            WzFile          etcFile       = new WzFile(PathIO.Combine(chosenPath, "Etc.wz"), WzMapleVersion.CLASSIC);
            WzFile          stringFile    = new WzFile(PathIO.Combine(chosenPath, "String.wz"), WzMapleVersion.CLASSIC);
            WzFile          uiFile        = new WzFile(PathIO.Combine(chosenPath, "UI.wz"), WzMapleVersion.CLASSIC);
            WzFile          mobFile       = new WzFile(PathIO.Combine(chosenPath, "Mob.wz"), WzMapleVersion.CLASSIC);
            WzFile          mob2File      = new WzFile(PathIO.Combine(chosenPath, "Mob2.wz"), WzMapleVersion.CLASSIC);
            WzFile          skill001File  = new WzFile(PathIO.Combine(chosenPath, "Skill001.wz"), WzMapleVersion.CLASSIC);
            WzFile          itemFile      = new WzFile(PathIO.Combine(chosenPath, "Item.wz"), WzMapleVersion.CLASSIC);
            CharacterWz     character     = new CharacterWz(characterFile);
            EtcWz           etc           = new EtcWz(etcFile);
            StringWz        stringM       = new StringWz(stringFile, true);
            UIWz            ui            = new UIWz(uiFile);
            MobWz           mob           = new MobWz(mobFile);
            MobWz           mob2          = new MobWz(mob2File);
            Skill001Wz      skill001      = new Skill001Wz(skill001File);
            ItemWz          item          = new ItemWz(itemFile);
            int             loopNumber    = character.GetFamiliarQuantity();

            for (int i = 0; i < loopNumber; i++)
            {
                int familiarID = character.GetFamiliarID(i);
                character.SetFamiliarImage(familiarID);
                int mobID = etc.GetMobID(familiarID);
                if (mobID == -1)
                {
                    mobID = character.GetMobID();
                }
                mob.SetMobImage(mobID, mobFile);
                mob2.SetMobImage(mobID, mob2File);
                MobWz realMob;
                if (mob.MobImage != null)
                {
                    realMob = mob;
                }
                else
                {
                    realMob = mob2;
                }
                int skillID         = character.GetSkillID();
                int passiveEffectID = etc.GetPassiveEffectID(familiarID);
                int cardID          = etc.GetCardID(familiarID);
                if (cardID == -1)
                {
                    cardID = character.GetCardID();
                }
                int level = character.GetLevel(); // DON'T CHANGE THE ORDER, OR IT'LL BE MESSED UP
                if (level == 0)
                {
                    level = realMob.GetLevel();
                }
                int att = character.GetATT(); // SAME AS LEVEL, DON'T CHANGE ORDER
                if (att == 0)
                {
                    att = realMob.GetATT();
                }
                Bitmap mobImage = realMob.GetMobImage();
                //BitmapSource finalCardImage = CreateBitmapSourceFromGdiBitmap(item.GetCardImage(cardID));
                //BitmapSource finalMobImage = CreateBitmapSourceFromGdiBitmap(mobImage);
                Bitmap finalCardImage = item.GetCardImage(cardID);
                Bitmap finalMobImage  = mobImage;
                int    hasCardImage   = 1;
                int    hasMobImage    = 1;
                if (finalCardImage == null || finalCardImage.Height <= 1)
                {
                    hasCardImage = 0;
                }
                if (finalMobImage == null)
                {
                    hasMobImage = 0;
                }

                familiars.Add(new Familiar()
                {
                    FamiliarID       = familiarID,
                    MobID            = mobID,
                    MobName          = stringM.GetMobName(mobID),
                    SkillID          = skillID,
                    SkillName        = stringM.GetSkillName(skillID),
                    SkillDescription = stringM.GetSkillDesc(skillID),
                    PassiveEffectID  = passiveEffectID,
                    PassiveEffect    = stringM.GetPassiveEffect(passiveEffectID),
                    Range            = character.GetRange(),
                    Rarity           = item.GetRarity(cardID),
                    CardID           = cardID,
                    CardName         = stringM.GetCardName(cardID),
                    SkillCategory    = skill001.GetSkillCategory(skillID),
                    Level            = level,
                    ATT = att,
                    PassiveEffectTarget = item.GetPassiveEffectTarget(passiveEffectID),
                    PassiveEffectBonus  = item.GetPassiveEffectBonus(passiveEffectID),
                    CardImage           = finalCardImage,
                    MobImage            = finalMobImage,
                    HasCardImage        = hasCardImage,
                    HasMobImage         = hasMobImage,
                });
            }
            characterFile.Dispose();
            etcFile.Dispose();
            stringFile.Dispose();
            uiFile.Dispose();
            mobFile.Dispose();
            mob2File.Dispose();
            skill001File.Dispose();
            itemFile.Dispose();

            return(familiars);
        }
Example #13
0
        public static List <Equip> LoadEquipData(string chosenPath, string category)
        {
            List <Equip> equips        = new List <Equip>();
            WzFile       characterFile = new WzFile(PathIO.Combine(chosenPath, "Character.wz"), WzMapleVersion.CLASSIC);
            WzFile       stringFile    = new WzFile(PathIO.Combine(chosenPath, "String.wz"), WzMapleVersion.CLASSIC);
            CharacterWz  character     = new CharacterWz(characterFile, category);
            StringWz     stringM       = new StringWz(stringFile, false);
            int          loopNumber    = character.GetEquipQuantity();

            for (int i = 0; i < loopNumber; i++)
            {
                int    equipID             = character.GetEquipID(i);
                string equipName           = stringM.GetEquipName(equipID, category);
                string equipClassification = character.GetEquipClassification();
                Bitmap equipImage          = character.GetEquipImage(characterFile);
                int    hasEquipImage       = 1;
                if (equipImage.Height <= 1)
                {
                    hasEquipImage = 0;
                }
                if (equipClassification == "Cash")
                {
                    equips.Add(new Equip()
                    {
                        /* Missing Int Properties don't make the program crash, like Level.
                         * But I'll put it anyway for organization sake.
                         */
                        EquipID             = equipID,
                        EquipName           = equipName,
                        EquipImage          = equipImage,
                        HasEquipImage       = hasEquipImage,
                        EquipLevel          = 0,
                        EquipClassification = equipClassification,
                        EquipType           = "",
                        RequiredStats       = "",
                        RequiredJob         = "",
                        TotalUpgradeCount   = 0,
                        EquipStats          = "",
                    });
                    continue;
                }

                equips.Add(new Equip()
                {
                    EquipID             = equipID,
                    EquipName           = equipName,
                    EquipImage          = equipImage,
                    HasEquipImage       = hasEquipImage,
                    EquipLevel          = character.GetEquipLevel(),
                    EquipClassification = equipClassification,
                    EquipType           = character.GetEquipType(equipID),
                    RequiredStats       = character.GetRequiredStats(),
                    RequiredJob         = character.GetRequiredJob(equipID),
                    TotalUpgradeCount   = character.GetTotalUpgradeCount(),
                    EquipStats          = character.GetEquipStats(),
                });
            }
            characterFile.Dispose();
            stringFile.Dispose();

            return(equips);
        }
 public void UnloadWzFile(WzFile file)
 {
     file.Dispose();
     mWzFiles.Remove(Path.GetFileNameWithoutExtension(file.name));
 }
        public override void Start()
        {
            WzFile file = MapleFileCache.Instance["Character"];

            string[] emoteList = new string[] {
                "angry", "bewildered", "blaze", "blink", "bowing", "cheers", "chu", "cry", "dam", "despair", "glitter", "hit", "hot", "hum",
                "love", "oops", "pain", "shine", "smile", "stunned", "troubled", "vomit", "wink",
                "default"
            };

            string tmp = exDir;

            foreach (var item in file.WzDirectory.WzImages) // 00002000.img
            {
                exDir    += Path.DirectorySeparatorChar + item.Name + Path.DirectorySeparatorChar;
                currentID = Convert.ToInt32(item.Name.Replace(".img", ""));

                foreach (var stance in STANCES)
                {
                    if (item[stance] != null)
                    {
                        HandleHairStyle(exDir, item[stance].ToSubProperty(), stance);
                    }
                }


                exDir = RemoveFromBackDirSlash(exDir);
                exDir = RemoveFromBackDirSlash(exDir);
                item.Dispose();
            }

            tmp = exDir;
            foreach (var dir in file.WzDirectory.WzDirectories.Where(a =>
            {
                return(a.Name != "Familiar" && a.Name != "Afterimage");
            })) // Accessory
            {
                Console.WriteLine("> {0}", dir.Name);
                exDir += Path.DirectorySeparatorChar + dir.Name; // Pet
                foreach (var item in dir.WzImages)               // 01010000.img
                {
                    exDir += Path.DirectorySeparatorChar + item.Name + Path.DirectorySeparatorChar;
                    if (item.Name.IndexOf(".img") != -1)
                    {
                        currentID = int.Parse(item.Name.Remove(item.Name.Length - 4));
                    }
                    else
                    {
                        currentID = int.Parse(item.Name);
                    }

                    if (item["info"] != null)
                    {
                        HandleInfoBlock(exDir, item["info"].ToSubProperty(), "info");
                    }

                    if (dir.Name == "Weapon")
                    {
                        bool found = false;
                        for (int i = 30; i <= 53; i++)
                        {
                            if (item[i.ToString()] != null)
                            {
                                var inner = item[i.ToString()];

                                foreach (var stance in STANCES)
                                {
                                    if (inner[stance] != null)
                                    {
                                        HandleStance(exDir, inner[stance].ToSubProperty(), i.ToString() + "." + stance);
                                    }
                                }

                                found = true;
                            }
                        }
                        if (!found)
                        {
                            foreach (var stance in STANCES)
                            {
                                if (item[stance] != null)
                                {
                                    HandleStance(exDir, item[stance].ToSubProperty(), stance);
                                }
                            }
                        }
                    }
                    else if (dir.Name == "PetEquip")
                    {
                        for (int i = 0; i <= 300; i++)
                        {
                            int actualID = 5000000 + i;
                            if (item[actualID.ToString()] != null)
                            {
                                var inner = item[actualID.ToString()];

                                foreach (var stance in STANCES)
                                {
                                    if (item[stance] != null)
                                    {
                                        HandleStance(exDir, inner[stance].ToSubProperty(), actualID + "." + stance);
                                    }
                                }
                            }
                        }
                    }
                    else if (dir.Name == "Hair")
                    {
                        foreach (var stance in STANCES)
                        {
                            if (item[stance] != null)
                            {
                                HandleHairStyle(exDir, item[stance].ToSubProperty(), stance);
                            }
                        }
                    }
                    else
                    {
                        foreach (var stance in STANCES)
                        {
                            if (item[stance] != null)
                            {
                                HandleStance(exDir, item[stance].ToSubProperty(), stance);
                            }
                        }
                    }

                    foreach (var emote in emoteList)
                    {
                        if (item[emote] == null)
                        {
                            continue;
                        }
                        HandleEmote(exDir, item[emote].ToSubProperty(), emote);
                    }
                    exDir = RemoveFromBackDirSlash(exDir);
                    exDir = RemoveFromBackDirSlash(exDir);
                }

                exDir = RemoveFromBackDirSlash(exDir);

                dir.Dispose();
            }
            file.Dispose();

            MapleFileCache.Instance["Character"] = null; // unload
        }
Example #16
0
        public override void Start()
        {
            WzFile file = MapleFileCache.Instance["String"];

            {
                var equiptypes = file.WzDirectory["Eqp.img"];
                foreach (var key in (equiptypes as WzImage)["Eqp"].WzProperties)
                {
                    ExtractItems(key.ToSubProperty());
                }
            }

            {
                var list = file.WzDirectory["Etc.img"];
                ExtractItems((list as WzImage)["Etc"] as WzSubProperty);
            }

            {
                var list = file.WzDirectory["Consume.img"];
                ExtractItems(list as WzImage);
            }

            {
                var list = file.WzDirectory["Ins.img"];
                ExtractItems(list as WzImage);
            }

            {
                var list = file.WzDirectory["Cash.img"];
                ExtractItems(list as WzImage);
            }

            {
                var list = file.WzDirectory["Pet.img"];
                ExtractItems(list as WzImage);
            }

            {
                var list = file.WzDirectory["Skill.img"];
                ExtractSkills(list as WzImage);
            }

            {
                var list = file.WzDirectory["Mob.img"];
                ExtractItems(list as WzImage, "mob");
            }

            {
                var list = file.WzDirectory["Npc.img"];
                ExtractItems((list as WzImage).WzProperties, "npc");
            }

            {
                var list = file.WzDirectory["Familiar.img"];
                if (list != null)
                {
                    ExtractItems((list as WzImage)["skill"] as WzSubProperty, "familiar_skill");
                }
            }

            {
                var maptypes = file.WzDirectory["Map.img"];
                foreach (var key in (maptypes as WzImage).WzProperties)
                {
                    Console.WriteLine("-> {0}", key.Name);
                    ExtractMaps(key as WzSubProperty);
                }
            }

            file.Dispose();
            MapleFileCache.Instance["String"] = null;
        }