Exemple #1
0
        public void startExtractCharacters()
        {
            WzFile file = new WzFile(wzDir + @"\Character.wz", Version);
            //WzFile file = new WzFile(wzDir + @"\Data - kopie.wz", Version);
            file.ParseWzFile();
            //Console.WriteLine("Version: {0}", file.);
            
            string tempDir = currentDir;
            WzDirectory loldir = file.WzDirectory.GetDirectoryByName("Character");
            if (loldir == null)
            {
                loldir = file.WzDirectory;
            }
            loldir.ParseImages();

            foreach (WzImage img in loldir.WzImages)
            {
                currentDir += img.Name + "\\";
                parseImage(img);
                currentDir = tempDir;
            }

            foreach (WzDirectory dir in loldir.WzDirectories)
            {
                currentDir += dir.Name + "\\";
                parseDir(dir);
                currentDir = tempDir;
            }

        }
Exemple #2
0
 private bool OpenWzFile(string path, WzMapleVersion encVersion, short version, out WzFile file)
 {
     try
     {
         WzFile f = new WzFile(path, version, encVersion);
         wzFiles.Add(f);
         f.ParseWzFile();
         file = f;
         return true;
     }
     catch (Exception e)
     {
         Warning.Error("Error initializing " + Path.GetFileName(path) + " (" + e.Message + ").\r\nCheck that the directory is valid and the file is not in use.");
         file = null;
         return false;
     }
 }
        public void Save()
        {
            bool   settingsExist = File.Exists(wzPath);
            WzFile wzFile;

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

                string parseErrorMessage = string.Empty;
                bool   success           = wzFile.ParseWzFile(out parseErrorMessage);
            }
            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);
                wzFile.Dispose();
                File.Delete(settingsPath);
                File.Move(tempFile, settingsPath);
            }
            else
            {
                wzFile.SaveToDisk(wzPath);
            }
        }
Exemple #4
0
 public void Load()
 {
     if (File.Exists(wzPath))
     {
         WzFile wzFile = new WzFile(wzPath, 1337, WzMapleVersion.CLASSIC);
         try
         {
             wzFile.ParseWzFile();
             ExtractSettingsImage((WzImage)wzFile["UserSettings.img"], userSettingsType);
             ExtractSettingsImage((WzImage)wzFile["ApplicationSettings.img"], appSettingsType);
             wzFile.Dispose();
         }
         catch
         {
             wzFile.Dispose();
             throw;
         }
     }
 }
 public void Load()
 {
     if (File.Exists(wzPath))
     {
         WzFile wzFile = new WzFile(wzPath, 1337, WzMapleVersion.CLASSIC);
         try
         {
             wzFile.ParseWzFile();
             ExtractSettingsImage((WzImage)wzFile["UserSettings.img"], userSettingsType);
             ExtractSettingsImage((WzImage)wzFile["ApplicationSettings.img"], appSettingsType);
             wzFile.Dispose();
         }
         catch
         {
             wzFile.Dispose();
             throw;
         }
     }
 }
Exemple #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;
                    }
                }
            }
        }
        /// <summary>
        /// Load UserSettings and ApplicationSettings
        /// </summary>
        public void LoadSettings()
        {
            if (File.Exists(wzPath))
            {
                using (WzFile wzFile = new WzFile(wzPath, 1337, WzMapleVersion.CLASSIC))
                {
                    try
                    {
                        string parseErrorMessage = string.Empty;
                        bool   success           = wzFile.ParseWzFile(out parseErrorMessage);

                        ExtractSettingsImage((WzImage)wzFile["UserSettings.img"], userSettingsType);
                        ExtractSettingsImage((WzImage)wzFile["ApplicationSettings.img"], appSettingsType);
                    }
                    catch
                    {
                        throw;
                    }
                }
            }
        }
Exemple #8
0
        public void Patch()
        {
            string curVTxt = "(Current V" + Patcher_UserSettings.CurrentVersion + ")";
            AppendStatus(curVTxt + " Checking for updates...");
            ProgressStyle(ProgressBarStyle.Marquee);
            WebClient download = new WebClient();
            //MessageBox.Show("hai");
            if (!CheckPath(Patcher_AppSettings.PatchURL)) //Check if the website directory actually exists. -DeathRight
            {
                download.Dispose();
                MessageBox.Show("The specified URL cannot be found, please contact the server owner or post in the help section of the server forum.", "Unreachable URL");
                Application.Exit();
            }

            //MessageBox.Show("hai2");

            if (!CheckPath(Patcher_AppSettings.PatchURL + "/" + (Patcher_UserSettings.CurrentVersion + 1).ToString()))
            {
                download.Dispose();
                Application.Exit(); //If there isn't a folder with a version 1 higher than the current, we can't update, so exit. -DeathRight
            }

            Dictionary<string, WzFile> WzFiles = new Dictionary<string, WzFile>();
            AppendStatus(curVTxt + " Downloading patch files...");
            ProgressValue(0);
            ProgressStyle(ProgressBarStyle.Marquee);
            RefreshStuff();
            Directory.CreateDirectory(Application.StartupPath + @"\Patches");
            foreach (string wzFile in WzTypes)
            {
                if (CheckFile(Patcher_AppSettings.PatchURL + "/" + (Patcher_UserSettings.CurrentVersion + 1).ToString() + "/" + wzFile))
                {
                    download.DownloadFile(Patcher_AppSettings.PatchURL + "/" + (Patcher_UserSettings.CurrentVersion + 1).ToString() + "/" + wzFile, Application.StartupPath + @"\Patches\" + wzFile);
                    short version = -1;
                    WzMapleVersion nWzFV = WzTool.DetectMapleVersion(Application.StartupPath + @"\Patches\" + wzFile, out version);
                    WzFile nWzF = new WzFile(Application.StartupPath + @"\Patches\" + wzFile, nWzFV);
                    nWzF.ParseWzFile();
                    nWzF.WzDirectory.ParseImages(); //Just to be safe -DeathRight
                    WzFiles.Add(wzFile, nWzF);
                }
            }
            download.Dispose();

            if (WzFiles.Count <= 0)
            {
                return;
            }

            string slTxt = curVTxt + " Patching files...";
            AppendStatus(slTxt);
            ProgressStyle(ProgressBarStyle.Continuous);
            //ProgressMax(WzFiles.Count);
            RefreshStuff();
            Directory.CreateDirectory(Application.StartupPath + @"\Patches\TEMP");
            foreach (WzFile wzFile in WzFiles.Values)
            {
                if (wzFile.WzDirectory["PatchInfo"] != null)
                    wzFile.WzDirectory["PatchInfo"].Remove();

                if (!File.Exists(Application.StartupPath + @"\" + wzFile.Name))
                {
                    MessageBox.Show("Unable to find WZ '" + wzFile.Name + "' in path '" + Application.StartupPath + "'","Unable to find WZ file");
                    Application.Exit();
                }

                ProgressValue(0);
                ProgressStyle(ProgressBarStyle.Marquee);
                RefreshStuff();
                AppendStatus(slTxt + " [" + wzFile.Name + "]");
                RefreshStuff();

                short version = -1;
                WzFile origWz = new WzFile(Application.StartupPath + @"\" + wzFile.Name, WzTool.DetectMapleVersion(Application.StartupPath + @"\" + wzFile.Name, out version));
                origWz.ParseWzFile();
                origWz.WzDirectory.ParseImages();
                try
                {
                    ReplaceDirs(wzFile.WzDirectory, origWz);
                    origWz.SaveToDisk(Application.StartupPath + @"\Patches\TEMP\" + wzFile.Name);
                }
                catch
                {
                    MessageBox.Show("Error while trying to save WZ file '" + wzFile.Name + "'", "Error saving WZ file");
                    wzFile.Dispose();
                    origWz.Dispose();
                    File.Delete(Application.StartupPath + @"\Patches\" + wzFile);
                    Application.Exit();
                }
                string wzName = wzFile.Name;
                wzFile.Dispose();
                origWz.Dispose();
                File.Delete(Application.StartupPath + @"\Patches\" + wzName);
                File.Delete(Application.StartupPath + @"\" + wzName);
                File.Move(Application.StartupPath + @"\Patches\TEMP\" + wzName, Application.StartupPath + @"\" + wzName);

                //ProgressValue();

                //RefreshStuff();
            }

            Patcher_UserSettings.CurrentVersion++;
            Patch();
        }
Exemple #9
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("The file at " + wzpath + " is a List.wz file and will be skipped.");
             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;
 }
Exemple #10
0
        /// <summary>
        /// Checks if any current wz files are not set to the latest version number.
        /// </summary>
        /// <returns>
        /// Returns a List<Tuple<string, int>> array with the file name and detected version.
        /// </returns>
        protected List<Tuple<string, int>> outDatedFiles()
        {
            BinaryReader verificationWz;
            wzSignature vs;
            var outOfDateFiles = new List<Tuple<string, int>>();
            if (haveFiles())
            {
                for (int i = 0; i < wzFiles.Length; i++)
                {
                    try
                    {
                        verificationWz = new BinaryReader(new FileStream(wzFiles[i], FileMode.Open));
                        vs = new wzSignature(verificationWz, currentLauncherVersion);
                        if (!(vs.WzVersion == latestWZVersion) || !(vs.UIAdded && vs.EssenceAdded))
                            outOfDateFiles.Add(new Tuple<string, int>(wzFiles[i], vs.WzVersion));

                        verificationWz.Close();
                    }
                    catch (Exception)
                    {
                        updateLabel("Please close any program using " + wzFiles[0] + ".");
                        setStateWrapper(3);
                        backgroundWorker.ReportProgress(100);
                        //throw new Exception("Please close any program using " + wzFiles[0] + ".");
                    }
                }
            }

            List<string> toCheck = new List<string>();
            foreach (WzPatcherEntry patch in WzPatcher.customPatches) {
                if (!toCheck.Contains(patch.WzFileName)) {
                    toCheck.Add(patch.WzFileName);
                }
            }

            //Check for hardcoded changes.
            foreach (string i in toCheck) {
                WzFile wz = new WzFile(i, (short)mapleVersion, WzMapleVersion.BMS);
                wz.ParseWzFile();
                allWzFiles.Add(wz);
                foreach (WzPatcherEntry patch in WzPatcher.customPatches) {
                    WzPatcherEntry newPatch = patch;
                    newPatch.wzFile = wz;
                    if (newPatch.WzFileName.Equals(i)) {
                        if (!WzPatcher.checkSingleNode(newPatch)) {
                            bool found = false;
                            foreach (Tuple<string, int> toPatch in outOfDateFiles) {
                                if (toPatch.Item1.Equals(i)) {
                                    found = true;
                                }
                            }
                            if (!found) {
                                outOfDateFiles.Add(new Tuple<string, int>(i, latestWZVersion));
                            }
                        }
                    }
                }
            }
            return outOfDateFiles;
        }
Exemple #11
0
 public bool LoadWzFile(string name)
 {
     try
     {
         WzFile wzf = new WzFile(Path.Combine(baseDir, Capitalize(name) + ".wz"), version);
         wzf.ParseWzFile();
         name = name.ToLower();
         wzFiles[name] = wzf;
         wzFilesUpdated[wzf] = false;
         wzDirs[name] = new WzMainDirectory(wzf);
         return true;
     }
     catch (Exception e)
     {
         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;
     }
 }
Exemple #12
0
 public bool LoadDataWzFile(string name)
 {
     try
     {
         WzFile wzf = new WzFile(Path.Combine(baseDir, Capitalize(name) + ".wz"), version);
         wzf.ParseWzFile();
         name = name.ToLower();
         wzFiles[name] = wzf;
         wzFilesUpdated[wzf] = false;
         wzDirs[name] = new WzMainDirectory(wzf);
         foreach (WzDirectory mainDir in wzf.WzDirectory.WzDirectories)
         {
             wzDirs[mainDir.Name.ToLower()] = new WzMainDirectory(wzf, mainDir);
         }
         return true;
     }
     catch (Exception e)
     {
         MessageBox.Show("Error initializing " + name + ".wz (" + e.Message + ").\r\nCheck that the directory is valid and the file is not in use.");
         return false;
     }
 }
Exemple #13
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!";
 }
Exemple #14
0
        public void patch(Dictionary<String, List<String>> patches, string dir, int patchNum)
        {
            WzMapleVersion vrs = WzMapleVersion.GMS;
            foreach (String wzName in patches.Keys)
            {
                WzFile wzFile = null;
                foreach (WzFile patching in toPatch)
                {
                    if (patching.Name == wzName)
                    {
                        Console.WriteLine("Currently patching: {0}, nextToPatch: {1}", patching.Name, wzName);
                        wzFile = patching;
                        break;
                    }
                }
                if (wzFile == null)
                {
                    wzFile = new WzFile(wzName, vrs);
                    wzFile.ParseWzFile();
                }
                foreach (string img in patches[wzName])
                {
                    WzImage patchedImg = null;
                    string[] subdirs = img.Split(new char[] { '/' });
                    WzDirectory targetDir = wzFile.WzDirectory;
                    string targetImgName = null;
                    foreach (string subdir in subdirs)
                    {
                        Console.WriteLine("subdir: {0}", subdir);
                        if (!subdir.EndsWith(".img")) // if this isn't the img
                        {
                            targetDir = targetDir.GetDirectoryByName(subdir);
                            if (targetDir == null)
                            {
                                Console.WriteLine("ERROR: {0} is not a valid directory.", subdir);
                                return;
                            }
                        }
                        else
                        {
                            targetImgName = subdir;
                        }

                    }
                    patchedImg = new WzImage(targetImgName, File.OpenRead(dir + "-" + patchNum + targetImgName), vrs);
                    patchedImg.ParseImage();
                    WzImage targetImg = targetDir.GetImageByName(targetImgName);
                    if (targetImg != null) // patching an existing .img
                    {
                        targetDir.RemoveImage(targetImg);
                        targetDir.AddImage(patchedImg);
                        patchedImg.changed = true;
                        Console.WriteLine("Existing wz img found for name: {0} and successfully applied patch.", img);
                    }
                    else
                    {
                        targetDir.AddImage(patchedImg);
                        patchedImg.changed = true;
                        Console.WriteLine("Added new wz img with name: {0} in dir: {1} and sucessfully applied patch.", patchedImg.Name, targetDir.Name);
                    }
                }
                if (!toPatch.Contains(wzFile))
                {
                    toPatch.Add(wzFile);
                }
            }
        }
Exemple #15
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;
 }
 public void Save()
 {
     bool settingsExist = File.Exists(wzPath);
     WzFile wzFile;
     if (settingsExist)
     {
         wzFile = new WzFile(wzPath, 1337, WzMapleVersion.CLASSIC);
         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);
         wzFile.Dispose();
         File.Delete(settingsPath);
         File.Move(tempFile, settingsPath);
     }
     else
         wzFile.SaveToDisk(wzPath);
 }
Exemple #17
0
 static void ParseFile(string InputFileName,string OutputFileName)
 {
     JsonCreator Creator=new JsonCreator();
     WzFile File=new WzFile(InputFileName,WzMapleVersion.BMS);
     File.ParseWzFile();
     List<WzDirectory> RootDirectory=new List<WzDirectory>();
     RootDirectory.Add(File.WzDirectory);
     var Dirs=new Stack<DirObject>();
     var RootHash=new Dictionary<string,object>();
     Dirs.Push(new DirObject(RootDirectory.GetEnumerator(),RootHash));
     for(;Dirs.Count>0;){
         if(!Dirs.Peek().Dir.MoveNext()){
             Dirs.Pop();
             continue;
         }else{
             foreach(WzImage Image in Dirs.Peek().Dir.Current.WzImages){
                 var Props=new Stack<PropObject>();
                 var Temp1=new Dictionary<string,object>();
                 Dirs.Peek().Hash.Add(Image.Name,Temp1);
                 Props.Push(new PropObject(Image.WzProperties.GetEnumerator(),Temp1));
                 for(;Props.Count>0;){
                     if(!Props.Peek().Prop.MoveNext()){
                         Props.Pop();
                         continue;
                     }
                     var Obj=Props.Peek().Prop.Current;
                     switch(Props.Peek().Prop.Current.PropertyType){
                     case WzPropertyType.ByteFloat:
                         Props.Peek().Hash.Add(Obj.Name,(double)((WzByteFloatProperty)Obj).Value);
                         break;
                     case WzPropertyType.Canvas:
                         //Not Implemented
                         break;
                     case WzPropertyType.CompressedInt:
                         Props.Peek().Hash.Add(Obj.Name,(long)((WzCompressedIntProperty)Obj).Value);
                         break;
                     case WzPropertyType.Convex:
                         //Not Implemented
                         break;
                     case WzPropertyType.Double:
                         Props.Peek().Hash.Add(Obj.Name,((WzDoubleProperty)Obj).Value);
                         break;
                     case WzPropertyType.Null:
                         Props.Peek().Hash.Add(Obj.Name,null);
                         break;
                     case WzPropertyType.PNG:
                         var Temp2=((WzPngProperty)Obj).GetCompressedBytes(false).OfType<long>().ToList();
                         var Temp3=new Dictionary<string,object>();
                         Temp3.Add("Width",(long)((WzPngProperty)Obj).Width);
                         Temp3.Add("Height",(long)((WzPngProperty)Obj).Height);
                         Temp3.Add("Data",Temp2);
                         break;
                     case WzPropertyType.Sound:
                         var Temp4=((WzSoundProperty)Obj).GetBytes(false).OfType<long>().ToList();
                         var Temp5=new Dictionary<string,object>();
                         Temp5.Add("Frequency",(long)((WzSoundProperty)Obj).Frequency);
                         Temp5.Add("Length",(long)((WzSoundProperty)Obj).Length);
                         Temp5.Add("Data",Temp4);
                         Props.Peek().Hash.Add(Obj.Name,Temp5);
                         break;
                     case WzPropertyType.String:
                         Props.Peek().Hash.Add(Obj.Name,((WzStringProperty)Obj).Value);
                         break;
                     case WzPropertyType.SubProperty:
                         var Temp6=new Dictionary<string,object>();
                         Props.Peek().Hash.Add(Obj.Name,Temp6);
                         Props.Push(new PropObject(((WzSubProperty)Obj).WzProperties.GetEnumerator(),Temp6));
                         break;
                     case WzPropertyType.UnsignedShort:
                         Props.Peek().Hash.Add(Obj.Name,(long)((WzUnsignedShortProperty)Obj).Value);
                         break;
                     case WzPropertyType.UOL:
                         //Not Implemented
                         break;
                     case WzPropertyType.Vector:
                         var Temp7=new Dictionary<string,object>();
                         Temp7.Add("X",(long)((WzVectorProperty)Obj).X);
                         Temp7.Add("Y",(long)((WzVectorProperty)Obj).Y);
                         Props.Peek().Hash.Add(Obj.Name,Temp7);
                         break;
                     }
                 }
             }
             var Temp8=new Dictionary<string,object>();
             Dirs.Peek().Hash.Add(Dirs.Peek().Dir.Current.Name,Temp8);
             Dirs.Push(new DirObject(Dirs.Peek().Dir.Current.WzDirectories.GetEnumerator(),Temp8));
         }
     }
     var Json=Creator.Create(RootHash);
     System.IO.File.WriteAllText(OutputFileName,Json,Encoding.UTF8);
     return;
 }
Exemple #18
0
 private void asdfToolStripMenuItem_Click(object sender, EventArgs e)
 {
     WzFile f = new WzFile(@"C:\Mob.wz", WzMapleVersion.BMS);
     //WzFile f = new WzFile(@"C:\Nexon\MapleStoryExt\Skill.wz", WzMapleVersion.BMS);
     f.ParseWzFile();
     foreach (WzImage mob in f.WzDirectory.WzImages)
     {
         mob.ParseImage();
         WzSubProperty info = (WzSubProperty)mob["info"];
         if (info != null)
         {
             WzCompressedIntProperty bodyatt = (WzCompressedIntProperty)info["bodyAttack"];
             if (bodyatt != null)
             {
                 bodyatt.Value = 0;
                 mob.Changed = true;
             }
         }
     }
     f.SaveToDisk(@"C:\Mob2.wz");
 }
Exemple #19
0
        protected void downloadLatestVersion()
        {
            //oldversion_newversion.txt
                string updateFile = verificationSignature.WzVersion.ToString() + "_" + latestWZVersion.ToString() + ".txt";
            //Download and prepare the XML list for parsing.

            List<string> XMLsToUpdate = mergeFiles();
            List<Tuple<string, string>> XMLListing = new List<Tuple<string, string>>();
            WzXmlDeserializer xmlParser = new WzXmlDeserializer(true, new byte[] { 0, 0, 0, 0 });

            List<string> wzFilesNeedingPatch = new List<string>();

            updateLabel("(2/6) Receiving the update patch list."); //Removed the display here since it doesn't play well with merged files

            //splits the update log into <WzFile, WzNode>
            foreach (string XMLLine in XMLsToUpdate)
            {
                //Check for which files actually need patching first
                foreach (string wzName in wzFiles)
                {
                    if (!wzFilesNeedingPatch.Contains(wzName) && XMLLine.Contains(wzName))
                    {
                        wzFilesNeedingPatch.Add(wzName);
                    }
                }

                string[] splitted = XMLLine.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                if (!XMLListing.Contains(new Tuple<string, string>(splitted[0], splitted[1])))
                {
                    XMLListing.Add(new Tuple<string, string>(splitted[0], splitted[1]));
                }
            }

            //open the WZ files for patching
            foreach (string wzName in wzFilesNeedingPatch)
            {
                WzFile tmp = new WzFile(wzName, WzMapleVersion.BMS);
                tmp.ParseWzFile();
                allWzFiles.Add(tmp);
            }

            //Parse XML's and add the nodes to the WZ files.
            int counter = 0;
            foreach (WzFile wzFile in allWzFiles) //foreach (Tuple<string, string> XMLFile in XMLListing)
            {
                updateLabel("(3/6) Applying: " + wzFile.Name + " (Downloading and applying patch files)");

                foreach (Tuple<string, string> XMLFile in XMLListing) //foreach (WzFile wzFile in allWzFiles)
                {
                    if (wzFile.Name == XMLFile.Item1)
                    {
                        counter += 1;
                        string xmlContent = "";
                        try
                        {
                            xmlContent = readEntireWebFile(updateServer + @"wz/" + XMLFile.Item1 + "/" + XMLFile.Item2);
                        }
                        catch (Exception)
                        {
                            //Throw "Unable to connect to the update server" if unable to read any file from update server.
                            setStateWrapper(12);
                            backgroundWorker.ReportProgress(100);
                        }
                        try
                        {
                            WzImage imageToAdd = (WzImage)xmlParser.ParseXML(xmlContent)[0];
                            AddWzImage(wzFile, XMLFile.Item2, imageToAdd);
                            int percentage = (int)((double)counter * 100) / XMLListing.Count;
                            backgroundWorker.ReportProgress(percentage);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error on XML ("+ XMLFile.Item2 + ") " + e.ToString());
                        }
                    }
                }
                WzPatcher.applyPatches(wzFile);
            }

            //Done patching, save in temporary dir
            if (Directory.Exists(temporaryDirectory))
            {
                Directory.Delete(temporaryDirectory, true);
                Directory.CreateDirectory(temporaryDirectory);
            }
            else
            {
                Directory.CreateDirectory(temporaryDirectory);
            }

            updateLabel("(4/6) Adding custom content.");

            backgroundWorker.ReportProgress(0);

            WzFile CharacterWz = null;
            WzFile MapWz = null;
            WzFile UIWz = null;
            foreach (WzFile wzfile in allWzFiles)
            {
                if(wzfile.Name == "Character.wz")
                    CharacterWz = wzfile;
                if(wzfile.Name == "Map.wz")
                    MapWz = wzfile;
                if (wzfile.Name == "UI.wz")
                    UIWz = wzfile;
            }

            if (!verificationSignature.UIAdded)
            {
                if (MapWz == null)
                {
                    MapWz = new WzFile("Map.wz", WzMapleVersion.BMS);
                    MapWz.ParseWzFile();
                    allWzFiles.Add(MapWz);
                }
                AddCustomImages(MapWz, backgroundWorker);
                verificationSignature.UIAdded = true;
                backgroundWorker.ReportProgress(75);
            }
            if (!verificationSignature.EssenceAdded)
            {
                if (UIWz == null)
                {
                    UIWz = new WzFile("UI.wz", WzMapleVersion.BMS);
                    UIWz.ParseWzFile();
                    allWzFiles.Add(UIWz);
                }
                AddCustomImages(UIWz, backgroundWorker);
                verificationSignature.EssenceAdded = true;
                backgroundWorker.ReportProgress(100);
            }

            backgroundWorker.ReportProgress(100);

            //Generate the new signature
            wzSignature newSignature = verificationSignature;
            newSignature.LauncherVersion = currentLauncherVersion;
            newSignature.WzVersion = (ushort)latestWZVersion;

            counter = 0;
            backgroundWorker.ReportProgress(0);
            foreach (WzFile wzFile in allWzFiles)
            {
                    counter += 1;
                    updateLabel("(5/6) Creating: " + wzFile.Name + " (Saving files to disk)");

                    wzFile.SaveToDisk(temporaryDirectory + wzFile.Name);
                    wzFile.Dispose();

                    int percentage = (int)((double)counter * 100) / allWzFiles.Count;
                    backgroundWorker.ReportProgress(percentage);
            }

            counter = 0;
            backgroundWorker.ReportProgress(0);
            //Done patching, copy the patched files over to the game installation.
            foreach (FileInfo wzFile in new DirectoryInfo(temporaryDirectory).GetFiles())
            {
                counter += 1;
                updateLabel("(6/6) Finalizing: " + wzFile.Name + " (Replacing files with patched files)");
                File.Delete(Directory.GetCurrentDirectory() + "\\" + wzFile.Name);
                File.Copy(wzFile.FullName, Directory.GetCurrentDirectory() + "\\" + wzFile.Name);

                int percentage = (int)((double)counter * 100) / (new DirectoryInfo(temporaryDirectory).GetFiles().Length);
                backgroundWorker.ReportProgress(percentage);
            }

            allWzFiles.Clear();
            foreach (string wzName in wzFiles)
            {
                allWzFiles.Add(new WzFile(wzName, WzMapleVersion.BMS));
            }

            //Sign each WZ file
            foreach (WzFile wzFile in allWzFiles)
            {
                try
                {
                    string wzPath = wzFile.FilePath;
                    BinaryReader wzReaderStream = new BinaryReader(new FileStream(wzPath, FileMode.Open));
                    bool needsNewSignature = wzSignature.isSignedWzFile(wzReaderStream);
                    wzReaderStream.Close();

                    BinaryWriter wzWriterStream = new BinaryWriter(new FileStream(wzPath, FileMode.Open));
                    newSignature.writeSignature(wzWriterStream, !needsNewSignature);
                    wzWriterStream.Flush();
                    wzWriterStream.Close();
                }
                catch (Exception)
                {
                    updateLabel("Please close any program using " + wzFiles[0] + ".");
                    setStateWrapper(3);
                    backgroundWorker.ReportProgress(100);
                    //throw new Exception("Please close any program using " + wzFiles[0] + ".");
                }
            }

            Directory.Delete(temporaryDirectory, true);
            updateLabel("The patch is done.");
            backgroundWorker.ReportProgress(100);
            setStateWrapper(2);
        }