Exemple #1
0
 public WzImageResource(WzImage img)
 {
     this.img = img;
     this.parsed = img.Parsed;
     if (!parsed)
     {
         img.ParseImage();
     }
 }
Exemple #2
0
 private void ExtractSettingsImage(WzImage settingsImage, Type settingsHolderType)
 {
     if (!settingsImage.Parsed) settingsImage.ParseImage();
     foreach (FieldInfo fieldInfo in settingsHolderType.GetFields(BindingFlags.Public | BindingFlags.Static))
     {
         string settingName = fieldInfo.Name;
         IWzImageProperty settingProp = settingsImage[settingName];
         byte[] argb;
         if (settingProp == null)
             SaveField(settingsImage, fieldInfo);
         else if (fieldInfo.FieldType.BaseType != null && fieldInfo.FieldType.BaseType.FullName == "System.Enum")
             fieldInfo.SetValue(null, InfoTool.GetInt(settingProp));
         else switch (fieldInfo.FieldType.FullName)
             {
                 //case "Microsoft.Xna.Framework.Graphics.Color":
                 case "Microsoft.Xna.Framework.Color":
                     if (xnaColorType == null) throw new InvalidDataException("XNA color detected, but XNA type activator is null");
                     argb = BitConverter.GetBytes((uint)((WzDoubleProperty)settingProp).Value);
                     fieldInfo.SetValue(null, Activator.CreateInstance(xnaColorType, argb[0], argb[1], argb[2], argb[3]));
                     break;
                 case "System.Drawing.Color":
                     argb = BitConverter.GetBytes((uint)((WzDoubleProperty)settingProp).Value);
                     fieldInfo.SetValue(null, System.Drawing.Color.FromArgb(argb[3], argb[2], argb[1], argb[0]));
                     break;
                 case "System.Int32":
                     fieldInfo.SetValue(null, InfoTool.GetInt(settingProp));
                     break;
                 case "System.Double":
                     fieldInfo.SetValue(null, ((WzDoubleProperty)settingProp).Value);
                     break;
                 case "System.Boolean":
                     fieldInfo.SetValue(null, InfoTool.GetBool(settingProp));
                     //bool a = (bool)fieldInfo.GetValue(null);
                     break;
                 case "System.Single":
                     fieldInfo.SetValue(null, ((WzByteFloatProperty)settingProp).Value);
                     break;
                 /*case "WzMapleVersion":
                     fieldInfo.SetValue(null, (WzMapleVersion)InfoTool.GetInt(settingProp));
                     break;
                 case "ItemTypes":
                     fieldInfo.SetValue(null, (ItemTypes)InfoTool.GetInt(settingProp));
                     break;*/
                 case "System.Drawing.Size":
                     fieldInfo.SetValue(null, new System.Drawing.Size(((WzVectorProperty)settingProp).X.Value, ((WzVectorProperty)settingProp).Y.Value));
                     break;
                 case "System.String":
                     fieldInfo.SetValue(null, InfoTool.GetString(settingProp));
                     break;
                 case "System.Drawing.Bitmap":
                     fieldInfo.SetValue(null, ((WzCanvasProperty)settingProp).PngProperty.GetPNG(false));
                     break;
                 default:
                     throw new Exception("unrecognized setting type");
             }
     }
 }
Exemple #3
0
 public WzImageResource(WzImage img)
 {
     this.img    = img;
     this.parsed = img.Parsed;
     if (!parsed)
     {
         img.ParseImage();
     }
 }
Exemple #4
0
        private void SaveSettingsImage(WzImage settingsImage, Type settingsHolderType)
        {
            if (!settingsImage.Parsed) settingsImage.ParseImage();
            foreach (FieldInfo fieldInfo in settingsHolderType.GetFields(BindingFlags.Public | BindingFlags.Static))
            {
                SaveField(settingsImage, fieldInfo);
            }

            settingsImage.Changed = true;
        }
        private void ExtractSettingsImage(WzImage settingsImage, Type settingsHolderType)
        {
            if (!settingsImage.Parsed)
            {
                settingsImage.ParseImage();
            }
            foreach (FieldInfo fieldInfo in settingsHolderType.GetFields(BindingFlags.Public | BindingFlags.Static))
            {
                string          settingName = fieldInfo.Name;
                WzImageProperty settingProp = settingsImage[settingName];
                byte[]          argb;
                if (settingProp == null)
                {
                    SaveField(settingsImage, fieldInfo);
                }
                else if (fieldInfo.FieldType.BaseType != null && fieldInfo.FieldType.BaseType.FullName == "System.Enum")
                {
                    fieldInfo.SetValue(null, InfoTool.GetInt(settingProp));
                }
                else
                {
                    switch (fieldInfo.FieldType.FullName)
                    {
                    //case "Microsoft.Xna.Framework.Graphics.Color":
                    case "Microsoft.Xna.Framework.Color":
                        if (xnaColorType == null)
                        {
                            throw new InvalidDataException("XNA color detected, but XNA type activator is null");
                        }
                        argb = BitConverter.GetBytes((uint)((WzDoubleProperty)settingProp).Value);
                        fieldInfo.SetValue(null, Activator.CreateInstance(xnaColorType, argb[0], argb[1], argb[2], argb[3]));
                        break;

                    case "System.Drawing.Color":
                        argb = BitConverter.GetBytes((uint)((WzDoubleProperty)settingProp).Value);
                        fieldInfo.SetValue(null, System.Drawing.Color.FromArgb(argb[3], argb[2], argb[1], argb[0]));
                        break;

                    case "System.Int32":
                        fieldInfo.SetValue(null, InfoTool.GetInt(settingProp));
                        break;

                    case "System.Double":
                        fieldInfo.SetValue(null, ((WzDoubleProperty)settingProp).Value);
                        break;

                    case "System.Boolean":
                        fieldInfo.SetValue(null, InfoTool.GetBool(settingProp));
                        //bool a = (bool)fieldInfo.GetValue(null);
                        break;

                    case "System.Single":
                        fieldInfo.SetValue(null, ((WzFloatProperty)settingProp).Value);
                        break;

                    /*case "WzMapleVersion":
                     *  fieldInfo.SetValue(null, (WzMapleVersion)InfoTool.GetInt(settingProp));
                     *  break;
                     * case "ItemTypes":
                     *  fieldInfo.SetValue(null, (ItemTypes)InfoTool.GetInt(settingProp));
                     *  break;*/
                    case "System.Drawing.Size":
                        fieldInfo.SetValue(null, new System.Drawing.Size(((WzVectorProperty)settingProp).X.Value, ((WzVectorProperty)settingProp).Y.Value));
                        break;

                    case "System.String":
                        fieldInfo.SetValue(null, InfoTool.GetString(settingProp));
                        break;

                    case "System.Drawing.Bitmap":
                        fieldInfo.SetValue(null, ((WzCanvasProperty)settingProp).PngProperty.GetImage(false));
                        break;

                    default:
                        throw new Exception("unrecognized setting type");
                    }
                }
            }
        }
 private void SaveSettingsImage(WzImage settingsImage, Type settingsHolderType)
 {
     if (!settingsImage.Parsed) settingsImage.ParseImage();
     foreach (FieldInfo fieldInfo in settingsHolderType.GetFields(BindingFlags.Public | BindingFlags.Static))
     {
         SaveField(settingsImage, fieldInfo);
     }
     settingsImage.Changed = true;
 }
Exemple #7
0
        public void CreateMapFromImage(WzImage mapImage, string mapName, string streetName, string categoryName, WzSubProperty strMapProp, PageCollection Tabs, MultiBoard multiBoard, EventHandler[] rightClickHandler)
        {
            if (!mapImage.Parsed) mapImage.ParseImage();
            List<string> copyPropNames = VerifyMapPropsKnown(mapImage, false);
            MapInfo info = new MapInfo(mapImage, mapName, streetName, categoryName);
            foreach (string copyPropName in copyPropNames)
            {
                info.additionalNonInfoProps.Add(mapImage[copyPropName]);
            }
            MapType type = GetMapType(mapImage);
            if (type == MapType.RegularMap)
                info.id = int.Parse(WzInfoTools.RemoveLeadingZeros(WzInfoTools.RemoveExtension(mapImage.Name)));
            info.mapType = type;

            Rectangle VR = new Rectangle();
            Point center = new Point();
            Point size = new Point();
            Point minimapSize = new Point();
            Point minimapCenter = new Point();
            bool hasMinimap = false;
            bool hasVR = false;

            try
            {
                GetMapDimensions(mapImage, out VR, out center, out size, out minimapCenter, out minimapSize, out hasVR, out hasMinimap);
            }
            catch (NoVRException)
            {
                MessageBox.Show("Error - map does not contain size information and HaCreator was unable to generate it. An error has been logged.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ErrorLogger.Log(ErrorLevel.IncorrectStructure, "no size @map " + info.id.ToString());
                return;
            }

            lock (multiBoard)
            {
                CreateMap(mapName, WzInfoTools.RemoveLeadingZeros(WzInfoTools.RemoveExtension(mapImage.Name)), CreateStandardMapMenu(rightClickHandler), size, center, 8, Tabs, multiBoard);
                Board mapBoard = multiBoard.SelectedBoard;
                mapBoard.Loading = true; // prevents TS Change callbacks
                mapBoard.MapInfo = info;
                if (hasMinimap)
                {
                    mapBoard.MiniMap = ((WzCanvasProperty)mapImage["miniMap"]["canvas"]).PngProperty.GetPNG(false);
                    System.Drawing.Point mmPos = new System.Drawing.Point(-minimapCenter.X, -minimapCenter.Y);
                    mapBoard.MinimapPosition = mmPos;
                    mapBoard.MinimapRectangle = new MinimapRectangle(mapBoard, new Rectangle(mmPos.X, mmPos.Y, minimapSize.X, minimapSize.Y));
                }
                if (hasVR)
                {
                    mapBoard.VRRectangle = new VRRectangle(mapBoard, VR);
                }
                LoadLayers(mapImage, mapBoard);
                LoadLife(mapImage, mapBoard);
                LoadFootholds(mapImage, mapBoard);
                GenerateDefaultZms(mapBoard);
                LoadRopes(mapImage, mapBoard);
                LoadChairs(mapImage, mapBoard);
                LoadPortals(mapImage, mapBoard);
                LoadReactors(mapImage, mapBoard);
                LoadToolTips(mapImage, mapBoard);
                LoadBackgrounds(mapImage, mapBoard);
                LoadMisc(mapImage, mapBoard);

                mapBoard.BoardItems.Sort();
                mapBoard.Loading = false;
            }
            if (ErrorLogger.ErrorsPresent())
            {
                ErrorLogger.SaveToFile("errors.txt");
                if (UserSettings.ShowErrorsMessage)
                {
                    MessageBox.Show("Errors were encountered during the loading process. These errors were saved to \"errors.txt\". Please send this file to the author, either via mail (" + ApplicationSettings.AuthorEmail + ") or from the site you got this software from.\n\n(In the case that this program was not updated in so long that this message is now thrown on every map load, you may cancel this message from the settings)", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                ErrorLogger.ClearErrors();
            }
        }
Exemple #8
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 #9
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 #10
0
 public static void CreateMapFromImage(WzImage mapImage, string mapName, string streetName, PageCollection Tabs, MultiBoard multiBoard, EventHandler rightClickHandler)
 {
     if (!mapImage.Parsed) mapImage.ParseImage();
     VerifyMapPropsKnown(mapImage);
     MapInfo info = new MapInfo(mapImage, mapName, streetName);
     MapType type = GetMapType(mapImage);
     if (type == MapType.RegularMap)
         info.id = int.Parse(WzInfoTools.RemoveLeadingZeros(WzInfoTools.RemoveExtension(mapImage.Name)));
     info.mapType = type;
     Point center = new Point();
     Point size = new Point();
     if (mapImage["miniMap"] == null)
     {
         if (info.VR == null)
         {
             if (!GetMapVR(mapImage, ref info.VR))
             {
                 new GUI.ErrorBox("Error - map does not contain size information and HaCreator was unable to generate it. An error has been logged.");
                 //MessageBox.Show("Error - map does not contain size information and HaCreator was unable to generate it. An error has been logged.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 ErrorLogger.Log(ErrorLevel.IncorrectStructure, "no size @map " + info.id.ToString());
                 return;
             }
         }
         size = new Point(info.VR.Value.Width + 10, info.VR.Value.Height + 10); //leave 5 pixels on each side
         center = new Point(5 - info.VR.Value.Left, 5 - info.VR.Value.Top);
     }
     else
     {
         IWzImageProperty miniMap = mapImage["miniMap"];
         size = new Point(InfoTool.GetInt(miniMap["width"]), InfoTool.GetInt(miniMap["height"]));
         center = new Point(InfoTool.GetInt(miniMap["centerX"]), InfoTool.GetInt(miniMap["centerY"]));
     }
     CreateMap(mapName, WzInfoTools.RemoveLeadingZeros(WzInfoTools.RemoveExtension(mapImage.Name)), CreateStandardMapMenu(rightClickHandler), size, center, 8, Tabs, multiBoard);
     Board mapBoard = multiBoard.SelectedBoard;
     mapBoard.MapInfo = info;
     if (mapImage["miniMap"] != null)
         mapBoard.MiniMap = ((WzCanvasProperty)mapImage["miniMap"]["canvas"]).PngProperty.GetPNG(false);
     LoadLayers(mapImage, mapBoard);
     LoadLife(mapImage, mapBoard);
     LoadFootholds(mapImage, mapBoard);
     LoadRopes(mapImage, mapBoard);
     LoadChairs(mapImage, mapBoard);
     LoadPortals(mapImage, mapBoard);
     LoadReactors(mapImage, mapBoard);
     LoadToolTips(mapImage, mapBoard);
     LoadBackgrounds(mapImage, mapBoard);
     mapBoard.BoardItems.Sort();
 }
Exemple #11
0
        public void parseImage(WzImage image)
        {
            image.ParseImage();
            deep++;
            makeRealDir();
            string tempDir = currentDir;
            string tempDir2 = currentDirdunno;
            /*
            Form1.Instance.BeginInvoke((MethodInvoker)delegate
            {
                Form1.Instance.progress.Maximum += image.WzProperties.Length;
            });
             * */

            foreach (IWzImageProperty prop in image.WzProperties)
            {
                /*
                    Form1.Instance.BeginInvoke((MethodInvoker)delegate
                    {
                        Form1.Instance.progress.Value++;
                    });
                 * */
                currentDir += prop.Name + ".";
                currentDirdunno += prop.Name + ".";
                parseProperties(prop, 1);
                currentDir = tempDir;
                currentDirdunno = tempDir2;
            }
            image.UnparseImage();
            image.Dispose();
            deep--;
        }