public bool LoadWzFile(string name)
        {
            try
            {
                WzFile wzf = new WzFile(Path.Combine(baseDir, Capitalize(name) + ".wz"), version);

                WzFileParseStatus parseStatus = wzf.ParseWzFile();
                if (parseStatus != WzFileParseStatus.Success)
                {
                    MessageBox.Show("Error parsing " + name + ".wz (" + parseStatus.GetErrorDescription() + ")");
                    return(false);
                }

                name                = name.ToLower();
                wzFiles[name]       = wzf;
                wzFilesUpdated[wzf] = false;
                wzDirs[name]        = new WzMainDirectory(wzf);
                return(true);
            }
            catch (Exception)
            {
                //HaRepackerLib.Warning.Error("Error initializing " + name + ".wz (" + e.Message + ").\r\nCheck that the directory is valid and the file is not in use.");
                return(false);
            }
        }
        private bool OpenWzFile(string path, WzMapleVersion encVersion, short version, out WzFile file)
        {
            try
            {
                WzFile f = new WzFile(path, version, encVersion);
                lock (wzFiles)
                {
                    wzFiles.Add(f);
                }
                WzFileParseStatus parseStatus = f.ParseWzFile();
                if (parseStatus != WzFileParseStatus.Success)
                {
                    file = null;
                    Warning.Error("Error initializing " + Path.GetFileName(path) + " (" + parseStatus.GetErrorDescription() + ").");
                    return(false);
                }

                file = f;
                return(true);
            }
            catch (Exception e)
            {
                Warning.Error("Error initializing " + Path.GetFileName(path) + " (" + e.Message + ").\r\nAlso, check that the directory is valid and the file is not in use.");
                file = null;
                return(false);
            }
        }
Beispiel #3
0
        public void Save()
        {
            bool   settingsExist = File.Exists(wzPath);
            WzFile wzFile;

            if (settingsExist)
            {
                wzFile = new WzFile(wzPath, 1337, WzMapleVersion.CLASSIC);

                WzFileParseStatus parseStatus = wzFile.ParseWzFile();
            }
            else
            {
                wzFile = new WzFile(1337, WzMapleVersion.CLASSIC);
                wzFile.Header.Copyright = "Wz settings file generated by MapleLib's WzSettings module created by haha01haha01";
                wzFile.Header.RecalculateFileStart();
                WzImage US = new WzImage("UserSettings.img")
                {
                    Changed = true,
                    Parsed  = true
                };
                WzImage AS = new WzImage("ApplicationSettings.img")
                {
                    Changed = true,
                    Parsed  = true
                };
                wzFile.WzDirectory.WzImages.Add(US);
                wzFile.WzDirectory.WzImages.Add(AS);
            }
            SaveSettingsImage((WzImage)wzFile["UserSettings.img"], userSettingsType);
            SaveSettingsImage((WzImage)wzFile["ApplicationSettings.img"], appSettingsType);
            if (settingsExist)
            {
                string tempFile     = Path.GetTempFileName();
                string settingsPath = wzFile.FilePath;

                wzFile.SaveToDisk(tempFile, false);
                wzFile.Dispose();
                File.Delete(settingsPath);
                File.Move(tempFile, settingsPath);
            }
            else
            {
                wzFile.SaveToDisk(wzPath, false);
            }
        }
        public static string GetErrorDescription(this WzFileParseStatus status)
        {
            switch (status) // TODO localisation via Resources
            {
            case WzFileParseStatus.Success:
                return("Success");

            case WzFileParseStatus.Failed_Unknown:
                return("Failed, in this case the causes are undetermined.");

            case WzFileParseStatus.Path_Is_Null:
                return("Path is null");

            case WzFileParseStatus.Error_Game_Ver_Hash:
                return("Error with game version hash : The specified game version is incorrect and WzLib was unable to determine the version itself");
            }
            return(string.Empty);
        }
        /// <summary>
        /// Open Base.WZ maplestory data
        /// </summary>
        public bool OpenBaseWZFile(out string LoadedVersion)
        {
            LoadedVersion = string.Empty;

            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Filter = "MapleStory Base.wz | Base.wz";
                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string Dir = ofd.FileName.Replace("\\Base.wz", "");
                    foreach (string Name in Directory.GetFiles(Dir))
                    {
                        FileInfo Info = new FileInfo(Name);
                        if (Info.Extension != ".wz")
                        {
                            continue;
                        }
                        WzFile File = new WzFile(Name, WzMapleVersion);


                        WzFileParseStatus parseStatus = File.ParseWzFile();
                        if (parseStatus == WzFileParseStatus.Success)
                        {
                            this.Files.Add(Info.Name, File);

                            if (LoadedVersion == string.Empty)
                            {
                                LoadedVersion = "MapleStory v." + File.Version + " WZ version: " + File.MapleVersion.ToString();
                            }
                        }
                        else
                        {
                            MessageBox.Show(parseStatus.GetErrorDescription(), Properties.Resources.Error);
                        }
                    }
                    ParseWZFiles();

                    return(true);
                }
            }
            return(false);
        }
Beispiel #6
0
        /// <summary>
        /// Load UserSettings and ApplicationSettings
        /// </summary>
        public void LoadSettings()
        {
            if (File.Exists(wzPath))
            {
                using (WzFile wzFile = new WzFile(wzPath, 1337, WzMapleVersion.CLASSIC))
                {
                    try
                    {
                        WzFileParseStatus parseStatus = wzFile.ParseWzFile();

                        ExtractSettingsImage((WzImage)wzFile["UserSettings.img"], userSettingsType);
                        ExtractSettingsImage((WzImage)wzFile["ApplicationSettings.img"], appSettingsType);
                    }
                    catch
                    {
                        throw;
                    }
                }
            }
        }
Beispiel #7
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);
        }
Beispiel #8
0
        private static double GetDecryptionSuccessRate(string wzPath, WzMapleVersion encVersion, ref short?version)
        {
            WzFile wzf;

            if (version == null)
            {
                wzf = new WzFile(wzPath, encVersion);
            }
            else
            {
                wzf = new WzFile(wzPath, (short)version, encVersion);
            }

            WzFileParseStatus parseStatus = wzf.ParseWzFile();

            if (parseStatus != WzFileParseStatus.Success)
            {
                return(0.0d);
            }

            if (version == null)
            {
                version = wzf.Version;
            }
            int recognizedChars = 0;
            int totalChars      = 0;

            foreach (WzDirectory wzdir in wzf.WzDirectory.WzDirectories)
            {
                recognizedChars += GetRecognizedCharacters(wzdir.Name);
                totalChars      += wzdir.Name.Length;
            }
            foreach (WzImage wzimg in wzf.WzDirectory.WzImages)
            {
                recognizedChars += GetRecognizedCharacters(wzimg.Name);
                totalChars      += wzimg.Name.Length;
            }
            wzf.Dispose();
            return((double)recognizedChars / (double)totalChars);
        }