Exemplo n.º 1
0
        /// <summary>
        /// Load map
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LoadButton_Click(object sender, EventArgs e)
        {
            //Hide();
            WaitWindow ww = new WaitWindow("Loading...");

            ww.Show();
            Application.DoEvents();

            WzImage       mapImage = null;
            int           mapid = -1;
            string        mapName = null, streetName = "", categoryName = "";
            WzSubProperty strMapProp = null;


            if (HAMSelect.Checked)
            {
                MapLoader.CreateMapFromHam(multiBoard, Tabs, File.ReadAllText(HAMBox.Text), rightClickHandler);
                DialogResult = DialogResult.OK;
                ww.EndWait();
                Close();
                return;
            }
            else if (XMLSelect.Checked)
            {
                try
                {
                    mapImage = (WzImage) new WzXmlDeserializer(false, null).ParseXML(XMLBox.Text)[0];
                }
                catch
                {
                    MessageBox.Show("Error while loading XML. Aborted.");
                    ww.EndWait();
                    Show();
                    return;
                }
            }
            else if (WZSelect.Checked)
            {
                if (mapBrowser.SelectedItem == null)
                {
                    return; // racing event
                }
                string selectedName = mapBrowser.SelectedItem;

                if (selectedName.StartsWith("MapLogin")) // MapLogin, MapLogin1, MapLogin2, MapLogin3
                {
                    mapImage = (WzImage)Program.WzManager["ui"][selectedName + ".img"];
                    mapName  = streetName = categoryName = selectedName;
                }
                else if (mapBrowser.SelectedItem == "CashShopPreview")
                {
                    mapImage = (WzImage)Program.WzManager["ui"]["CashShopPreview.img"];
                    mapName  = streetName = categoryName = "CashShopPreview";
                }
                else
                {
                    string mapid_str = mapBrowser.SelectedItem.Substring(0, 9);
                    int.TryParse(mapid_str, out mapid);

                    string mapcat = "Map" + mapid_str.Substring(0, 1);

                    WzDirectory directory = Program.WzManager.FindMapWz(mapcat);
                    mapImage = (WzImage)directory[mapid_str + ".img"];

                    strMapProp   = WzInfoTools.GetMapStringProp(mapid_str);
                    mapName      = WzInfoTools.GetMapName(strMapProp);
                    streetName   = WzInfoTools.GetMapStreetName(strMapProp);
                    categoryName = WzInfoTools.GetMapCategoryName(strMapProp);
                }
            }
            MapLoader.CreateMapFromImage(mapid, mapImage, mapName, streetName, categoryName, strMapProp, Tabs, multiBoard, rightClickHandler);

            DialogResult = DialogResult.OK;
            ww.EndWait();
            Close();
        }
Exemplo n.º 2
0
        private static MobInfo Load(WzImage parentObject)
        {
            string id = WzInfoTools.RemoveExtension(parentObject.Name);

            return(new MobInfo(null, new System.Drawing.Point(), id, WzInfoTools.GetMobNameById(id), parentObject));
        }
Exemplo n.º 3
0
 public void SerializeImage(WzImage file, string path)
 {
     SerializeObject(file, path);
 }
Exemplo n.º 4
0
        internal void ParsePng()
        {
            DeflateStream zlib;
            int           uncompressedSize = 0;
            int           x = 0, y = 0, b = 0, g = 0;
            Bitmap        bmp = null;
            BitmapData    bmpData;
            WzImage       imgParent = ParentImage;

            byte[] decBuf;

            BinaryReader reader = new BinaryReader(new MemoryStream(compressedBytes));
            ushort       header = reader.ReadUInt16();

            listWzUsed = header != 0x9C78 && header != 0xDA78 && header != 0x0178 && header != 0x5E78;
            if (!listWzUsed)
            {
                zlib = new DeflateStream(reader.BaseStream, CompressionMode.Decompress);
            }
            else
            {
                reader.BaseStream.Position -= 2;
                MemoryStream dataStream = new MemoryStream();
                int          blocksize  = 0;
                int          endOfPng   = compressedBytes.Length;

                while (reader.BaseStream.Position < endOfPng)
                {
                    blocksize = reader.ReadInt32();
                    for (int i = 0; i < blocksize; i++)
                    {
                        dataStream.WriteByte((byte)(reader.ReadByte() ^ imgParent.reader.WzKey[i]));
                    }
                }
                dataStream.Position = 2;
                zlib = new DeflateStream(dataStream, CompressionMode.Decompress);
            }

            switch (format + format2)
            {
            case 1:
                bmp              = new Bitmap(width, height, PixelFormat.Format32bppArgb);
                bmpData          = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                uncompressedSize = width * height * 2;
                decBuf           = new byte[uncompressedSize];
                zlib.Read(decBuf, 0, uncompressedSize);
                byte[] argb = new Byte[uncompressedSize * 2];
                for (int i = 0; i < uncompressedSize; i++)
                {
                    b = decBuf[i] & 0x0F; b |= (b << 4); argb[i * 2] = (byte)b;
                    g = decBuf[i] & 0xF0; g |= (g >> 4); argb[i * 2 + 1] = (byte)g;
                }
                Marshal.Copy(argb, 0, bmpData.Scan0, argb.Length);
                bmp.UnlockBits(bmpData);
                break;

            case 2:
                bmp              = new Bitmap(width, height, PixelFormat.Format32bppArgb);
                bmpData          = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                uncompressedSize = width * height * 4;
                decBuf           = new byte[uncompressedSize];
                zlib.Read(decBuf, 0, uncompressedSize);
                Marshal.Copy(decBuf, 0, bmpData.Scan0, decBuf.Length);
                bmp.UnlockBits(bmpData);
                break;

            case 3: {
                // New format 黑白缩略图
                // thank you Elem8100, http://forum.ragezone.com/f702/wz-png-format-decode-code-1114978/
                // you'll be remembered forever <3
                bmp     = new Bitmap(width, height, PixelFormat.Format32bppArgb);
                bmpData = bmp.LockBits(new Rectangle(Point.Empty, bmp.Size), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

                uncompressedSize = width * height * 4;
                decBuf           = new byte[uncompressedSize];
                zlib.Read(decBuf, 0, uncompressedSize);
                zlib.Close();

                byte[] decoded = GetPixelDataDXT3(decBuf, width, height);

                Marshal.Copy(decoded, 0, bmpData.Scan0, width * height);
                bmp.UnlockBits(bmpData);
                break;
            }

            case 513:
                bmp              = new Bitmap(width, height, PixelFormat.Format16bppRgb565);
                bmpData          = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format16bppRgb565);
                uncompressedSize = width * height * 2;
                decBuf           = new byte[uncompressedSize];
                zlib.Read(decBuf, 0, uncompressedSize);
                Marshal.Copy(decBuf, 0, bmpData.Scan0, decBuf.Length);
                bmp.UnlockBits(bmpData);
                break;

            case 517:
                bmp = new Bitmap(width, height);
                uncompressedSize = width * height / 128;
                decBuf           = new byte[uncompressedSize];
                zlib.Read(decBuf, 0, uncompressedSize);
                byte iB = 0;
                for (int i = 0; i < uncompressedSize; i++)
                {
                    for (byte j = 0; j < 8; j++)
                    {
                        iB = Convert.ToByte(((decBuf[i] & (0x01 << (7 - j))) >> (7 - j)) * 0xFF);
                        for (int k = 0; k < 16; k++)
                        {
                            if (x == width)
                            {
                                x = 0; y++;
                            }
                            bmp.SetPixel(x, y, Color.FromArgb(0xFF, iB, iB, iB));
                            x++;
                        }
                    }
                }
                break;

            case 1026:
                bmp              = new Bitmap(width, height, PixelFormat.Format32bppArgb);
                bmpData          = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                uncompressedSize = width * height;
                decBuf           = new byte[uncompressedSize];
                zlib.Read(decBuf, 0, uncompressedSize);
                decBuf = GetPixelDataDXT3(decBuf, Width, Height);
                Marshal.Copy(decBuf, 0, bmpData.Scan0, decBuf.Length);
                bmp.UnlockBits(bmpData);
                break;

            case 2050:     // new
                bmp     = new Bitmap(width, height, PixelFormat.Format32bppArgb);
                bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

                uncompressedSize = width * height;
                decBuf           = new byte[uncompressedSize];
                zlib.Read(decBuf, 0, uncompressedSize);
                zlib.Close();

                decBuf = GetPixelDataDXT5(decBuf, Width, Height);

                Marshal.Copy(decBuf, 0, bmpData.Scan0, decBuf.Length);
                bmp.UnlockBits(bmpData);
                break;

            default:
                Helpers.ErrorLogger.Log(Helpers.ErrorLevel.MissingFeature, string.Format("Unknown PNG format {0} {1}", format, format2));
                break;
            }
            png = bmp;
        }
 public void SerializeImage(WzImage file, string path)
 {
     SerializeObject(file, path);
 }
Exemplo n.º 6
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();
            }
        }
Exemplo n.º 7
0
        public MobReference(WzImage img, WzImage linkImg = null)
        {
            var name = img.Name.Remove(7);

            if (!int.TryParse(name, out var id))
            {
                return;
            }

            MapleId = id;
            var info = img["info"];

            info.WzProperties.ForEach(node =>
            {
                switch (node.Name)
                {
                case "link":
                    break;

                case "level":
                    Level = (byte)node.GetInt();
                    break;

                case "undead":
                    IsUndead = node.GetInt() > 0;
                    break;

                case "bodyAttack":
                    IsBodyAttack = node.GetInt() > 0;
                    break;

                case "summonType":
                    SummonType = node.GetShort();
                    break;

                case "exp":
                    Experience = (uint)node.GetInt();
                    break;

                case "maxHP":
                    MaxHealth = (uint)node.GetInt();
                    Health    = MaxHealth;
                    break;

                case "maxMP":
                    MaxMana = (uint)node.GetInt();
                    Mana    = MaxMana;
                    break;

                case "elemAttr":
                    ElementAttribute = node.GetString();
                    break;

                case "PADamage":
                    WeaponAttack = node.GetInt();
                    break;

                case "PDDamage":
                    WeaponDefense = node.GetInt();
                    break;

                case "MADamage":
                    MagicAttack = node.GetInt();
                    break;

                case "MDDamage":
                    MagicDefense = node.GetInt();
                    break;

                case "eva":
                    Avoidability = node.GetShort();
                    break;

                case "pushed":
                    IsPushed = node.GetInt() > 0;
                    break;

                case "noregen":
                    IsNoRegen = node.GetInt() > 0;
                    break;

                case "invincible":
                    IsInvincible = node.GetInt() > 0;
                    break;

                case "selfDestruction":
                    IsSelfDestruction = node.GetInt() > 0;
                    break;

                case "firstAttack":
                    IsFirstAttack = node.GetInt() > 0;
                    break;

                case "noFlip":
                    IsNoFlip = node.GetInt() > 0;
                    break;

                case "acc":
                    Accuracy = node.GetShort();
                    break;

                case "publicReward":
                    IsPublicReward = node.GetInt() > 0;
                    break;

                case "fs":
                    Traction = node.GetFloat();
                    break;

                case "flySpeed":
                    IsFlies = true;
                    Speed   = node.GetShort();
                    break;

                case "speed":
                    Speed = node.GetShort();
                    break;

                case "revive":
                    node.WzProperties?.ForEach(x => DeathSummons.Add(x.GetInt()));
                    break;

                case "skill":
                    node.WzProperties.ForEach(x => Skills.Add(new MobSkillReference(x)));
                    break;

                case "hpRecovery":
                    HealthRecovery = node.GetInt();
                    break;

                case "mpRecovery":
                    ManaRecovery = node.GetInt();
                    break;

                case "hpTagColor":
                    HpBarForeColor = (byte)node.GetInt();
                    break;

                case "hpTagBgcolor":
                    HpBarBackColor = (byte)node.GetInt();
                    break;

                case "boss":
                    IsBoss = node.GetInt() > 0;
                    break;

                default:
                    _log.Warning($"Unknown mob info node Mob={MapleId} Name={node.Name} Value={node.WzValue}");
                    break;
                }
            });

            Link = info["link"]?.GetInt() ?? 0;
            var nonInfoNodes = Link > 0 && linkImg != null ? linkImg.WzProperties : img.WzProperties;
            var attackNodes  = nonInfoNodes.Where(x => x.Name.StartsWith("attack")).ToList();

            foreach (var attackNode in attackNodes)
            {
                var attackData = new MobAttackDataReference(attackNode);
                Attacks.Add(attackData.Id, attackData);
            }
        }
 public void SerializeImage(WzImage img, string outPath)
 {
     total = 1; curr = 0;
     if (Path.GetExtension(outPath) != ".img") outPath += ".img";
     serializeImageInternal(img, outPath);
 }
Exemplo n.º 9
0
 private void mapNamesBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     if ((string)mapNamesBox.SelectedItem == "MapLogin" ||
         (string)mapNamesBox.SelectedItem == "MapLogin1" ||
         (string)mapNamesBox.SelectedItem == "CashShopPreview" ||
         mapNamesBox.SelectedItem == null)
     {
         linkLabel.Visible   = false;
         mapNotExist.Visible = false;
         minimapBox.Image    = (Image) new Bitmap(1, 1);
         load = mapNamesBox.SelectedItem != null;
     }
     else
     {
         string  mapid    = ((string)mapNamesBox.SelectedItem).Substring(0, 9);
         string  mapcat   = "Map" + mapid.Substring(0, 1);
         WzImage mapImage = null;
         if (Program.WzManager.wzFiles.ContainsKey("map002"))//i hate nexon so much
         {
             mapImage = (WzImage)Program.WzManager["map002"]["Map"][mapcat][mapid + ".img"];
         }
         else
         {
             mapImage = (WzImage)Program.WzManager["map"]["Map"][mapcat][mapid + ".img"];
         }
         if (mapImage == null)
         {
             linkLabel.Visible   = false;
             mapNotExist.Visible = true;
             minimapBox.Image    = (Image) new Bitmap(1, 1);
             load = false;
         }
         else
         {
             using (WzImageResource rsrc = new WzImageResource(mapImage))
             {
                 if (mapImage["info"]["link"] != null)
                 {
                     linkLabel.Visible   = true;
                     mapNotExist.Visible = false;
                     minimapBox.Image    = (Image) new Bitmap(1, 1);
                     load = false;
                 }
                 else
                 {
                     linkLabel.Visible   = false;
                     mapNotExist.Visible = false;
                     load = true;
                     WzCanvasProperty minimap = (WzCanvasProperty)mapImage.GetFromPath("miniMap/canvas");
                     if (minimap != null)
                     {
                         minimapBox.Image = (Image)minimap.PngProperty.GetPNG(false);
                     }
                     else
                     {
                         minimapBox.Image = (Image) new Bitmap(1, 1);
                     }
                     load = true;
                 }
             }
             GC.Collect();
         }
     }
     SelectionChanged.Invoke();
 }
Exemplo n.º 10
0
        public MapInfo(WzImage image, string strMapName, string strStreetName, string strCategoryName)
        {
            this.image = image;
            int?startHour;
            int?endHour;

            this.strMapName      = strMapName;
            this.strStreetName   = strStreetName;
            this.strCategoryName = strCategoryName;
            WzFile file         = (WzFile)image.WzFileParent;
            string loggerSuffix = ", map " + image.Name + ((file != null) ? (" of version " + Enum.GetName(typeof(WzMapleVersion), file.MapleVersion) + ", v" + file.Version.ToString()) : "");

            foreach (WzImageProperty prop in image["info"].WzProperties)
            {
                switch (prop.Name)
                {
                case "bgm":
                    bgm = InfoTool.GetString(prop);
                    break;

                case "cloud":
                    cloud = InfoTool.GetBool(prop);
                    break;

                case "swim":
                    swim = InfoTool.GetBool(prop);
                    break;

                case "forcedReturn":
                    forcedReturn = InfoTool.GetInt(prop);
                    break;

                case "hideMinimap":
                    hideMinimap = InfoTool.GetBool(prop);
                    break;

                case "mapDesc":
                    mapDesc = InfoTool.GetString(prop);
                    break;

                case "mapName":
                    mapName = InfoTool.GetString(prop);
                    break;

                case "mapMark":
                    mapMark = InfoTool.GetString(prop);
                    break;

                case "mobRate":
                    mobRate = InfoTool.GetFloat(prop);
                    break;

                case "moveLimit":
                    moveLimit = InfoTool.GetInt(prop);
                    break;

                case "returnMap":
                    returnMap = InfoTool.GetInt(prop);
                    break;

                case "town":
                    town = InfoTool.GetBool(prop);
                    break;

                case "version":
                    version = InfoTool.GetInt(prop);
                    break;

                case "fieldLimit":
                    int fl = InfoTool.GetInt(prop);
                    if (fl >= (int)Math.Pow(2, 23))
                    {
                        ErrorLogger.Log(ErrorLevel.IncorrectStructure, "Invalid fieldlimit " + fl.ToString() + loggerSuffix);
                        fl = fl & ((int)Math.Pow(2, 23) - 1);
                    }
                    fieldLimit = (FieldLimit)fl;
                    break;

                case "VRTop":
                case "VRBottom":
                case "VRLeft":
                case "VRRight":
                    break;

                case "link":
                    //link = InfoTool.GetInt(prop);
                    break;

                case "timeLimit":
                    timeLimit = InfoTool.GetInt(prop);
                    break;

                case "lvLimit":
                    lvLimit = InfoTool.GetInt(prop);
                    break;

                case "onFirstUserEnter":
                    onFirstUserEnter = InfoTool.GetString(prop);
                    break;

                case "onUserEnter":
                    onUserEnter = InfoTool.GetString(prop);
                    break;

                case "fly":
                    fly = InfoTool.GetBool(prop);
                    break;

                case "noMapCmd":
                    noMapCmd = InfoTool.GetBool(prop);
                    break;

                case "partyOnly":
                    partyOnly = InfoTool.GetBool(prop);
                    break;

                case "fieldType":
                    int ft = InfoTool.GetInt(prop);
                    if (!Enum.IsDefined(typeof(FieldType), ft))
                    {
                        ErrorLogger.Log(ErrorLevel.IncorrectStructure, "Invalid fieldType " + ft.ToString() + loggerSuffix);
                        ft = 0;
                    }
                    fieldType = (FieldType)ft;
                    break;

                case "miniMapOnOff":
                    miniMapOnOff = InfoTool.GetBool(prop);
                    break;

                case "reactorShuffle":
                    reactorShuffle = InfoTool.GetBool(prop);
                    break;

                case "reactorShuffleName":
                    reactorShuffleName = InfoTool.GetString(prop);
                    break;

                case "personalShop":
                    personalShop = InfoTool.GetBool(prop);
                    break;

                case "entrustedShop":
                    entrustedShop = InfoTool.GetBool(prop);
                    break;

                case "effect":
                    effect = InfoTool.GetString(prop);
                    break;

                case "lvForceMove":
                    lvForceMove = InfoTool.GetInt(prop);
                    break;

                case "timeMob":
                    startHour = InfoTool.GetOptionalInt(prop["startHour"]);
                    endHour   = InfoTool.GetOptionalInt(prop["endHour"]);
                    int?   id      = InfoTool.GetOptionalInt(prop["id"]);
                    string message = InfoTool.GetOptionalString(prop["message"]);
                    if (id == null || message == null || (startHour == null ^ endHour == null))
                    {
                        ErrorLogger.Log(ErrorLevel.IncorrectStructure, "timeMob" + loggerSuffix);
                    }
                    else
                    {
                        timeMob = new TimeMob((int?)startHour, (int?)endHour, (int)id, message);
                    }
                    break;

                case "help":
                    help = InfoTool.GetString(prop);
                    break;

                case "snow":
                    snow = InfoTool.GetBool(prop);
                    break;

                case "rain":
                    rain = InfoTool.GetBool(prop);
                    break;

                case "dropExpire":
                    dropExpire = InfoTool.GetInt(prop);
                    break;

                case "decHP":
                    decHP = InfoTool.GetInt(prop);
                    break;

                case "decInterval":
                    decInterval = InfoTool.GetInt(prop);
                    break;

                case "autoLieDetector":
                    startHour = InfoTool.GetOptionalInt(prop["startHour"]);
                    endHour   = InfoTool.GetOptionalInt(prop["endHour"]);
                    int?interval = InfoTool.GetOptionalInt(prop["interval"]);
                    int?propInt  = InfoTool.GetOptionalInt(prop["prop"]);
                    if (startHour == null || endHour == null || interval == null || propInt == null)
                    {
                        ErrorLogger.Log(ErrorLevel.IncorrectStructure, "autoLieDetector" + loggerSuffix);
                    }
                    else
                    {
                        autoLieDetector = new AutoLieDetector((int)startHour, (int)endHour, (int)interval, (int)propInt);
                    }
                    break;

                case "expeditionOnly":
                    expeditionOnly = InfoTool.GetBool(prop);
                    break;

                case "fs":
                    fs = InfoTool.GetFloat(prop);
                    break;

                case "protectItem":
                    protectItem = InfoTool.GetInt(prop);
                    break;

                case "createMobInterval":
                    createMobInterval = InfoTool.GetInt(prop);
                    break;

                case "fixedMobCapacity":
                    fixedMobCapacity = InfoTool.GetInt(prop);
                    break;

                case "streetName":
                    streetName = InfoTool.GetString(prop);
                    break;

                case "noRegenMap":
                    noRegenMap = InfoTool.GetBool(prop);
                    break;

                case "allowedItem":
                    allowedItem = new List <int>();
                    if (prop.WzProperties != null && prop.WzProperties.Count > 0)
                    {
                        foreach (WzImageProperty item in prop.WzProperties)
                        {
                            allowedItem.Add(item.GetInt());
                        }
                    }
                    break;

                case "recovery":
                    recovery = InfoTool.GetFloat(prop);
                    break;

                case "blockPBossChange":
                    blockPBossChange = InfoTool.GetBool(prop);
                    break;

                case "everlast":
                    everlast = InfoTool.GetBool(prop);
                    break;

                case "damageCheckFree":
                    damageCheckFree = InfoTool.GetBool(prop);
                    break;

                case "dropRate":
                    dropRate = InfoTool.GetFloat(prop);
                    break;

                case "scrollDisable":
                    scrollDisable = InfoTool.GetBool(prop);
                    break;

                case "needSkillForFly":
                    needSkillForFly = InfoTool.GetBool(prop);
                    break;

                case "zakum2Hack":
                    zakum2Hack = InfoTool.GetBool(prop);
                    break;

                case "allMoveCheck":
                    allMoveCheck = InfoTool.GetBool(prop);
                    break;

                case "VRLimit":
                    VRLimit = InfoTool.GetBool(prop);
                    break;

                case "consumeItemCoolTime":
                    consumeItemCoolTime = InfoTool.GetBool(prop);
                    break;

                default:
                    ErrorLogger.Log(ErrorLevel.MissingFeature, "Unknown Prop: " + prop.Name + loggerSuffix);
                    additionalProps.Add(prop.DeepClone());
                    break;
                }
            }
        }
Exemplo n.º 11
0
        private void LoadWzData(WzMapleVersion mapleVersion, string mapleDirectory)
        {
            int selectedRoot = TabControlMain.SelectedIndex;

            switch (TabControlMain.SelectedTab.Controls[0])
            {
            case DataViewer view: {
                view.GridView.Rows.Clear();
                break;
            }

            case TabControl ctrl: {
                if (ctrl.SelectedTab.Controls[0] is DataViewer view)
                {
                    view.GridView.Rows.Clear();
                }
                break;
            }
            }
            ((DataViewer)EquipTab.SelectedTab.Controls[0]).GridView.Rows.Clear();
            switch (selectedRoot)
            {
            default:
                Debug.WriteLine($"Unable to load WZ data unhandled selected index: {TabControlMain.SelectedIndex}");
                break;

            case 0:     // Equips
            {
                if (!LoadWzFileIfAbsent(ref characterWz, mapleDirectory + "/Character", mapleVersion))
                {
                    return;
                }
                List <WzImage> children = characterWz.WzDirectory.GetChildImages();
                children.Sort((a, b) => a.Name.CompareTo(b.Name));
                for (int i = 0; i < characterWz.WzDirectory.CountImages(); i++)
                {
                    WzImage image = children[i];
                    string  name  = Path.GetFileNameWithoutExtension(image.Name);
                    if (int.TryParse(name, out int equipId))
                    {
                        int selectedTab = EquipTab.SelectedIndex;
                        int bodyPart    = equipId / 10000;
                        switch (bodyPart)
                        {
                        default:
                            if (selectedTab == 2 && bodyPart >= 130 && bodyPart <= 170)
                            {
                                AddGridRow(EquipWeaponsView.GridView, image);
                            }
                            else if (selectedTab == 1 && bodyPart == 2)
                            {
                                AddFaceRow(image);
                            }
                            else if (selectedTab == 0 && (bodyPart == 3 || bodyPart == 4))
                            {
                                AddHairRow(image);
                            }
                            break;

                        case 100:         // Caps
                            if (selectedTab == 4)
                            {
                                AddGridRow(EquipCapsView.GridView, image);
                            }
                            break;

                        case 101:
                        case 102:
                        case 103:
                        case 112:
                        case 113:
                        case 114:         // Accessory
                            if (selectedTab == 3)
                            {
                                AddGridRow(EquipAccessoryView.GridView, image);
                            }
                            break;

                        case 110:         // Cape
                            if (selectedTab == 9)
                            {
                                AddGridRow(EquipCapesView.GridView, image);
                            }
                            break;

                        case 104:         // Coat
                            if (selectedTab == 6)
                            {
                                AddGridRow(EquipTopsView.GridView, image);
                            }
                            break;

                        case 108:         // Glove
                            if (selectedTab == 10)
                            {
                                AddGridRow(EquipGlovesView.GridView, image);
                            }
                            break;

                        case 105:         // Longcoat
                            if (selectedTab == 5)
                            {
                                AddGridRow(EquipsOverallsView.GridView, image);
                            }
                            break;

                        case 106:         // Pants
                            if (selectedTab == 7)
                            {
                                AddGridRow(EquipPantsView.GridView, image);
                            }
                            break;

                        case 180:
                        case 181:
                        case 182:
                        case 183:         // Pet Equips
                                          // image.ParseImage();
                            break;

                        case 111:         // Rings
                            if (selectedTab == 11)
                            {
                                AddGridRow(EquipRingsView.GridView, image);
                            }
                            break;

                        case 109:         // Shield
                            if (selectedTab == 12)
                            {
                                AddGridRow(EquipShieldsView.GridView, image);
                            }
                            break;

                        case 107:         // Shoes
                            if (selectedTab == 8)
                            {
                                AddGridRow(EquipShoesView.GridView, image);
                            }
                            break;

                        case 190:
                        case 191:
                        case 193:         // Taming Mob
                            //if (selectedTab == 13) AddGridRow(, image);
                            break;
                        }
                    }
                }
                break;
            }

            case 1:     // Use
            case 2:     // Setup
            case 3:     // Etc
            case 4:     // Cash
            case 9:     // Pets
            {
                if (!LoadWzFileIfAbsent(ref itemWz, mapleDirectory + "/Item", mapleVersion))
                {
                    return;
                }
                List <WzImage> children = itemWz.WzDirectory.GetChildImages();
                children.Sort((a, b) => a.Name.CompareTo(b.Name));
                for (int i = 0; i < itemWz.WzDirectory.CountImages(); i++)
                {
                    WzImage image = children[i];
                    string  name  = Path.GetFileNameWithoutExtension(image.Name);
                    if (int.TryParse(name, out int itemId))
                    {
                        switch (itemId)
                        {
                        default:
                            image.ParseImage();
                            if (selectedRoot == 9 && ItemConstants.IsPet(itemId))         // pet
                            {
                                AddGridRow(PetsView.GridView, image);
                            }
                            if (selectedRoot == 3 && ItemConstants.IsEtc(itemId))         // etc
                            {
                                image.WzProperties.ForEach(img => AddGridRow(EtcView.GridView, img));
                            }
                            if (selectedRoot == 4 && ItemConstants.IsCash(itemId))         // cash
                            {
                                image.WzProperties.ForEach(img => AddGridRow(CashView.GridView, img));
                            }
                            if (selectedRoot == 1 && ItemConstants.IsConsume(itemId))         // consume
                            {
                                image.WzProperties.ForEach(img => AddGridRow(UseConsumeView.GridView, img));
                            }
                            break;

                        case 204:         // scrolls
                            if (selectedRoot == 1)
                            {
                                image.WzProperties.ForEach(img => AddGridRow(UseScrollsView.GridView, img));
                            }
                            break;

                        case 206:
                        case 207:
                        case 233:         // projectiles
                            if (selectedRoot == 1)
                            {
                                image.WzProperties.ForEach(img => AddGridRow(UseProjectileView.GridView, img));
                            }
                            break;

                        case 301:         // chairs
                        case 399:         // x-mas characters
                            if (selectedRoot == 2)
                            {
                                image.WzProperties.ForEach(img => AddGridRow((itemId == 301 ? SetupChairsView : SetupOthersView).GridView, img));
                            }
                            break;
                        }
                    }
                }
                break;
            }

            case 5:     // Map
            {
                if (!LoadWzFileIfAbsent(ref mapWz, mapleDirectory + "/Map", mapleVersion))
                {
                    return;
                }
                List <WzImage> children = mapWz.WzDirectory.GetChildImages();
                children.Sort((a, b) => a.Name.CompareTo(b.Name));
                for (int i = 0; i < mapWz.WzDirectory.CountImages(); i++)
                {
                    WzImage image  = children[i];
                    string  sMapId = Path.GetFileNameWithoutExtension(image.Name);
                    if (int.TryParse(sMapId, out int mapId))
                    {
                        image.ParseImage();
                        string           properties = BuildProperties(image);
                        WzCanvasProperty icon       = (WzCanvasProperty)image.GetFromPath("miniMap/canvas");
                        string           name       = StringUtility.GetFieldFullName(mapId);

                        MapsView.GridView.Rows.Add(mapId, icon?.GetBitmap(), name, properties);
                    }
                }
                break;
            }

            case 6:     // Mob
            {
                if (!LoadWzFileIfAbsent(ref mobWz, mapleDirectory + "/Mob", mapleVersion))
                {
                    return;
                }
                MobsView.GridView.Rows.Clear();

                List <WzImage> children = mobWz.WzDirectory.GetChildImages();
                children.Sort((a, b) => a.Name.CompareTo(b.Name));
                for (int i = 0; i < mobWz.WzDirectory.CountImages(); i++)
                {
                    WzImage image = children[i];
                    AddGridRow(MobsView.GridView, image);
                }
                break;
            }

            case 7:     // Skills
            {
                if (!LoadWzFileIfAbsent(ref skillWz, mapleDirectory + "/Skill", mapleVersion))
                {
                    return;
                }
                SkillsView.GridView.Rows.Clear();

                List <WzImage> children = skillWz.WzDirectory.GetChildImages();
                children.Sort((a, b) => a.Name.CompareTo(b.Name));
                for (int i = 0; i < skillWz.WzDirectory.CountImages(); i++)
                {
                    WzImage image = children[i];
                    string  name  = Path.GetFileNameWithoutExtension(image.Name);
                    if (int.TryParse(name, out _))
                    {
                        WzImageProperty tree = image.GetFromPath("skill");
                        if (tree is WzSubProperty)
                        {
                            List <WzImageProperty> skills = tree.WzProperties;
                            skills.ForEach(s => AddGridRow(SkillsView.GridView, s));
                            skills.Clear();
                        }
                    }
                }
                break;
            }

            case 8:     // NPCs
            {
                if (!LoadWzFileIfAbsent(ref npcWz, mapleDirectory + "/Npc", mapleVersion))
                {
                    return;
                }
                NPCView.GridView.Rows.Clear();

                List <WzImage> children = npcWz.WzDirectory.GetChildImages();
                children.Sort((a, b) => a.Name.CompareTo(b.Name));
                for (int i = 0; i < npcWz.WzDirectory.CountImages(); i++)
                {
                    WzImage image = children[i];
                    AddGridRow(NPCView.GridView, image);
                }
                break;
            }

            case 10:     // Reactors
            {
                if (!LoadWzFileIfAbsent(ref reactorWz, mapleDirectory + "/Reactor", mapleVersion))
                {
                    return;
                }
                ReactorView.GridView.Rows.Clear();

                List <WzImage> children = reactorWz.WzDirectory.GetChildImages();
                children.Sort((a, b) => a.Name.CompareTo(b.Name));
                for (int i = 0; i < reactorWz.WzDirectory.CountImages(); i++)
                {
                    WzImage image = children[i];
                    AddGridRow(ReactorView.GridView, image);
                }
                break;
            }
            }
        }
        /// <summary>
        /// Gets the '_inlink' WzCanvasProperty of this.
        ///
        /// '_inlink' is not implemented as part of WzCanvasProperty as I dont want to override existing Wz structure.
        /// It will be handled via HaRepackerMainPanel instead.
        /// </summary>
        /// <returns></returns>
        public WzImageProperty GetLinkedWzImageProperty()
        {
            string _inlink  = ((WzStringProperty)this[InlinkPropertyName])?.Value;  // could get nexon'd here. In case they place an _inlink that's not WzStringProperty
            string _outlink = ((WzStringProperty)this[OutlinkPropertyName])?.Value; // could get nexon'd here. In case they place an _outlink that's not WzStringProperty

            if (_inlink != null)
            {
                WzObject currentWzObj = this; // first object to work with
                while ((currentWzObj = currentWzObj.Parent) != null)
                {
                    if (!(currentWzObj is WzImage))  // keep looping if its not a WzImage
                    {
                        continue;
                    }

                    WzImage         wzImageParent = (WzImage)currentWzObj;
                    WzImageProperty foundProperty = wzImageParent.GetFromPath(_inlink);
                    if (foundProperty != null && foundProperty is WzImageProperty property)
                    {
                        return(property);
                    }
                }
            }
            else if (_outlink != null)
            {
                WzObject currentWzObj = this; // first object to work with
                while ((currentWzObj = currentWzObj.Parent) != null)
                {
                    if (!(currentWzObj is WzDirectory))  // keep looping if its not a WzImage
                    {
                        continue;
                    }
                    WzFile wzFileParent = ((WzDirectory)currentWzObj).wzFile;

                    // TODO
                    // Given the way it is structured, it might possibility also point to a different WZ file (i.e NPC.wz instead of Mob.wz).
                    // Mob001.wz/8800103.img/8800103.png has an outlink to "Mob/8800141.img/8800141.png"
                    // https://github.com/lastbattle/Harepacker-resurrected/pull/142

                    Match  match    = Regex.Match(wzFileParent.Name, @"^([A-Za-z]+)([0-9]*).wz");
                    string prefixWz = match.Groups[1].Value + "/"; // remove ended numbers and .wz from wzfile name

                    WzObject foundProperty;

                    if (_outlink.StartsWith(prefixWz))
                    {
                        // fixed root path
                        string realpath = _outlink.Replace(prefixWz, WzFileParent.Name.Replace(".wz", "") + "/");
                        foundProperty = wzFileParent.GetObjectFromPath(realpath);
                    }
                    else
                    {
                        foundProperty = wzFileParent.GetObjectFromPath(_outlink);
                    }
                    if (foundProperty != null && foundProperty is WzImageProperty property)
                    {
                        return(property);
                    }
                }
            }
            return(this);
        }
Exemplo n.º 13
0
        private void ExportRecursion(WzObject currObj, string outPath)
        {
            if (currObj is WzFile)
            {
                ExportRecursion(((WzFile)currObj).WzDirectory, outPath);
            }
            else if (currObj is WzDirectory)
            {
                outPath += ProgressingWzSerializer.EscapeInvalidFilePathNames(currObj.Name) + @"\";
                if (!Directory.Exists(outPath))
                {
                    Directory.CreateDirectory(outPath);
                }
                foreach (WzDirectory subdir in ((WzDirectory)currObj).WzDirectories)
                {
                    ExportRecursion(subdir, outPath + subdir.Name + @"\");
                }
                foreach (WzImage subimg in ((WzDirectory)currObj).WzImages)
                {
                    ExportRecursion(subimg, outPath + subimg.Name + @"\");
                }
            }
            else if (currObj is WzCanvasProperty)
            {
                Bitmap bmp = ((WzCanvasProperty)currObj).PngProperty.GetImage(false);

                string path = outPath + ProgressingWzSerializer.EscapeInvalidFilePathNames(currObj.Name) + ".png";

                bmp.Save(path, ImageFormat.Png);
                //curr++;
            }
            else if (currObj is WzBinaryProperty)
            {
                string path = outPath + ProgressingWzSerializer.EscapeInvalidFilePathNames(currObj.Name) + ".mp3";
                ((WzBinaryProperty)currObj).SaveToFile(path);
            }
            else if (currObj is WzImage)
            {
                WzImage wzImage = ((WzImage)currObj);

                outPath += ProgressingWzSerializer.EscapeInvalidFilePathNames(currObj.Name) + @"\";
                if (!Directory.Exists(outPath))
                {
                    Directory.CreateDirectory(outPath);
                }

                bool parse = wzImage.Parsed || wzImage.Changed;
                if (!parse)
                {
                    wzImage.ParseImage();
                }
                foreach (WzImageProperty subprop in wzImage.WzProperties)
                {
                    ExportRecursion(subprop, outPath);
                }
                if (!parse)
                {
                    wzImage.UnparseImage();
                }
                curr++;
            }
            else if (currObj is IPropertyContainer)
            {
                outPath += ProgressingWzSerializer.EscapeInvalidFilePathNames(currObj.Name) + ".";
                foreach (WzImageProperty subprop in ((IPropertyContainer)currObj).WzProperties)
                {
                    ExportRecursion(subprop, outPath);
                }
            }
            else if (currObj is WzUOLProperty)
            {
                ExportRecursion(((WzUOLProperty)currObj).LinkValue, outPath);
            }
        }
Exemplo n.º 14
0
 private void exportXmlInternal(WzImage img, string path)
 {
     bool parsed = img.Parsed;
     if (!parsed) img.ParseImage();
     curr++;
     TextWriter tw = new StreamWriter(path);
     tw.Write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + lineBreak);
     tw.Write("<imgdir name=\"" + XmlUtil.SanitizeText(img.Name) + "\">" + lineBreak);
     foreach (IWzImageProperty property in img.WzProperties)
         WritePropertyToXML(tw, indent, property);
     tw.Write("</imgdir>" + lineBreak);
     tw.Close();
     if (!parsed) img.UnparseImage();
 }
 /// <summary>
 /// Sets WZ file as updated for saving
 /// </summary>
 /// <param name="name"></param>
 /// <param name="img"></param>
 public void SetWzFileUpdated(string name, WzImage img)
 {
     img.Changed = true;
     updatedImages.Add(img);
     wzFilesUpdated[GetMainDirectoryByName(name).File] = true;
 }
Exemplo n.º 16
0
 public WzImage WzImageFromIMGFile(string inPath, byte[] iv, string name)
 {
     FileStream stream = File.OpenRead(inPath);
     WzBinaryReader wzReader = new WzBinaryReader(stream, iv);
     WzImage img = new WzImage(name, wzReader);
     img.BlockSize = (int)stream.Length;
     img.Checksum = 0;
     byte[] bytes = new byte[stream.Length];
     stream.Read(bytes, 0, (int)stream.Length);
     stream.Position = 0;
     foreach (byte b in bytes) img.Checksum += b;
     img.Offset = 0;
     if (freeResources)
     {
         img.ParseImage(true);
         img.Changed = true;
         wzReader.Close();
     }
     return img;
 }
Exemplo n.º 17
0
        internal void ParsePng()
        {
            DeflateStream zlib;
            int           uncompressedSize = 0;
            int           x = 0, y = 0, b = 0, g = 0;
            Bitmap        bmp = null;
            BitmapData    bmpData;
            WzImage       imgParent = ParentImage;

            byte[] decBuf;

            BinaryReader reader = new BinaryReader(new MemoryStream(compressedBytes));
            ushort       header = reader.ReadUInt16();

            listWzUsed = header != 0x9C78 && header != 0xDA78;
            if (!listWzUsed)
            {
                zlib = new DeflateStream(reader.BaseStream, CompressionMode.Decompress);
            }
            else
            {
                reader.BaseStream.Position -= 2;
                MemoryStream dataStream = new MemoryStream();
                int          blocksize  = 0;
                int          endOfPng   = compressedBytes.Length;

                while (reader.BaseStream.Position < endOfPng)
                {
                    blocksize = reader.ReadInt32();
                    File.WriteAllBytes(@"D:\test2.bin", imgParent.reader.WzKey);
                    for (int i = 0; i < blocksize; i++)
                    {
                        dataStream.WriteByte((byte)(reader.ReadByte() ^ imgParent.reader.WzKey[i]));
                    }
                }
                dataStream.Position = 2;
                zlib = new DeflateStream(dataStream, CompressionMode.Decompress);
            }

            switch (format + format2)
            {
            case 1:
                bmp              = new Bitmap(width, height, PixelFormat.Format32bppArgb);
                bmpData          = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                uncompressedSize = width * height * 2;
                decBuf           = new byte[uncompressedSize];
                zlib.Read(decBuf, 0, uncompressedSize);
                byte[] argb = new Byte[uncompressedSize * 2];
                for (int i = 0; i < uncompressedSize; i++)
                {
                    b = decBuf[i] & 0x0F; b |= (b << 4); argb[i * 2] = (byte)b;
                    g = decBuf[i] & 0xF0; g |= (g >> 4); argb[i * 2 + 1] = (byte)g;
                }
                Marshal.Copy(argb, 0, bmpData.Scan0, argb.Length);
                bmp.UnlockBits(bmpData);
                break;

            case 2:
                bmp              = new Bitmap(width, height, PixelFormat.Format32bppArgb);
                bmpData          = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                uncompressedSize = width * height * 4;
                decBuf           = new byte[uncompressedSize];
                zlib.Read(decBuf, 0, uncompressedSize);
                Marshal.Copy(decBuf, 0, bmpData.Scan0, decBuf.Length);
                bmp.UnlockBits(bmpData);
                break;

            case 513:
                bmp              = new Bitmap(width, height, PixelFormat.Format16bppRgb565);
                bmpData          = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format16bppRgb565);
                uncompressedSize = width * height * 2;
                decBuf           = new byte[uncompressedSize];
                zlib.Read(decBuf, 0, uncompressedSize);
                Marshal.Copy(decBuf, 0, bmpData.Scan0, decBuf.Length);
                bmp.UnlockBits(bmpData);
                break;

            case 517:
                bmp = new Bitmap(width, height);
                uncompressedSize = width * height / 128;
                decBuf           = new byte[uncompressedSize];
                zlib.Read(decBuf, 0, uncompressedSize);
                byte iB = 0;
                for (int i = 0; i < uncompressedSize; i++)
                {
                    for (byte j = 0; j < 8; j++)
                    {
                        iB = Convert.ToByte(((decBuf[i] & (0x01 << (7 - j))) >> (7 - j)) * 0xFF);
                        for (int k = 0; k < 16; k++)
                        {
                            if (x == width)
                            {
                                x = 0; y++;
                            }
                            bmp.SetPixel(x, y, Color.FromArgb(0xFF, iB, iB, iB));
                            x++;
                        }
                    }
                }
                break;
            }
            png = bmp;
        }
Exemplo n.º 18
0
 private void serializeImageInternal(WzImage img, string outPath)
 {
     FileStream stream = File.Create(outPath);
     WzBinaryWriter wzWriter = new WzBinaryWriter(stream, ((WzDirectory)img.parent).WzIv);
     img.SaveImage(wzWriter);
     wzWriter.Close();
 }
Exemplo n.º 19
0
        internal void ParsePng()
        {
            DeflateStream zlib;
            int           uncompressedSize = 0;
            Bitmap        bmp = null;
            BitmapData    bmpData;
            WzImage       imgParent = ParentImage;

            byte[] decBuf;

            BinaryReader reader = new BinaryReader(new MemoryStream(compressedBytes));
            ushort       header = reader.ReadUInt16();

            listWzUsed = header != 0x9C78 && header != 0xDA78 && header != 0x0178 && header != 0x5E78;
            if (!listWzUsed)
            {
                zlib = new DeflateStream(reader.BaseStream, CompressionMode.Decompress);
            }
            else
            {
                reader.BaseStream.Position -= 2;
                MemoryStream dataStream = new MemoryStream();
                int          blocksize  = 0;
                int          endOfPng   = compressedBytes.Length;

                while (reader.BaseStream.Position < endOfPng)
                {
                    blocksize = reader.ReadInt32();
                    for (int i = 0; i < blocksize; i++)
                    {
                        dataStream.WriteByte((byte)(reader.ReadByte() ^ imgParent.reader.WzKey[i]));
                    }
                }
                dataStream.Position = 2;
                zlib = new DeflateStream(dataStream, CompressionMode.Decompress);
            }

            // System.Diagnostics.Debug.WriteLine("nPixFormat {0}, this.nMagLevel {1}", nPixFormat, this.nMagLevel);
            switch (nPixFormat + this.nMagLevel)
            {
            case 1:
                bmp              = new Bitmap(width, height, PixelFormat.Format32bppArgb);
                bmpData          = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                uncompressedSize = width * height * 2;
                decBuf           = new byte[uncompressedSize];
                zlib.Read(decBuf, 0, uncompressedSize);

                byte[] argb = new Byte[uncompressedSize * 2];     // argb
                for (int i = 0; i < uncompressedSize; i++)
                {
                    int low  = decBuf[i] & 0x0F;
                    int high = decBuf[i] & 0xF0;

                    argb[i * 2]     = (byte)(low | (low << 4));
                    argb[i * 2 + 1] = (byte)(high | (high >> 4));
                }
                Marshal.Copy(argb, 0, bmpData.Scan0, argb.Length);
                bmp.UnlockBits(bmpData);

                break;

            case 2:
                bmp              = new Bitmap(width, height, PixelFormat.Format32bppArgb);
                bmpData          = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                uncompressedSize = width * height * 4;
                decBuf           = new byte[uncompressedSize];
                zlib.Read(decBuf, 0, uncompressedSize);
                Marshal.Copy(decBuf, 0, bmpData.Scan0, decBuf.Length);
                bmp.UnlockBits(bmpData);
                break;

            case 3:
                // New format 黑白缩略图
                // thank you Elem8100, http://forum.ragezone.com/f702/wz-png-format-decode-code-1114978/
                // you'll be remembered forever <3
                bmp              = new Bitmap(width, height, PixelFormat.Format32bppArgb);
                bmpData          = bmp.LockBits(new Rectangle(Point.Empty, bmp.Size), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                uncompressedSize = width * height * 4;
                decBuf           = new byte[uncompressedSize];
                zlib.Read(decBuf, 0, uncompressedSize);


                int[] argb2 = new int[this.width * this.height];
                {
                    int index;
                    int index2;
                    int p;
                    int w = ((int)Math.Ceiling(this.width / 4.0));
                    int h = ((int)Math.Ceiling(this.height / 4.0));
                    for (int y_ = 0; y_ < h; y_++)
                    {
                        for (int x_ = 0; x_ < w; x_++)
                        {
                            index  = (x_ + y_ * w) * 2;            //原像素索引
                            index2 = x_ * 4 + y_ * this.width * 4; //目标像素索引
                            p      = (decBuf[index] & 0x0F) | ((decBuf[index] & 0x0F) << 4);
                            p     |= ((decBuf[index] & 0xF0) | ((decBuf[index] & 0xF0) >> 4)) << 8;
                            p     |= ((decBuf[index + 1] & 0x0F) | ((decBuf[index + 1] & 0x0F) << 4)) << 16;
                            p     |= ((decBuf[index + 1] & 0xF0) | ((decBuf[index] & 0xF0) >> 4)) << 24;

                            for (int i = 0; i < 4; i++)
                            {
                                if (x_ * 4 + i < this.width)
                                {
                                    argb2[index2 + i] = p;
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        //复制行
                        index2 = y_ * this.width * 4;
                        for (int j = 1; j < 4; j++)
                        {
                            if (y_ * 4 + j < this.height)
                            {
                                Array.Copy(argb2, index2, argb2, index2 + j * this.width, this.width);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                Marshal.Copy(decBuf, 0, bmpData.Scan0, argb2.Length);
                bmp.UnlockBits(bmpData);
                break;

            case 513:
                bmp              = new Bitmap(width, height, PixelFormat.Format16bppRgb565);
                bmpData          = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format16bppRgb565);
                uncompressedSize = width * height * 2;
                decBuf           = new byte[uncompressedSize];
                zlib.Read(decBuf, 0, uncompressedSize);
                Marshal.Copy(decBuf, 0, bmpData.Scan0, decBuf.Length);
                bmp.UnlockBits(bmpData);
                break;

            case 517:
                bmp = new Bitmap(width, height);
                uncompressedSize = width * height / 128;
                decBuf           = new byte[uncompressedSize];
                zlib.Read(decBuf, 0, uncompressedSize);
                byte iB = 0;
                int  x  = 0;
                int  y  = 0;

                for (int i = 0; i < uncompressedSize; i++)
                {
                    for (byte j = 0; j < 8; j++)
                    {
                        iB = Convert.ToByte(((decBuf[i] & (0x01 << (7 - j))) >> (7 - j)) * 0xFF);
                        for (int k = 0; k < 16; k++)
                        {
                            if (x == width)
                            {
                                x = 0;
                                y++;
                            }
                            bmp.SetPixel(x, y, Color.FromArgb(0xFF, iB, iB, iB));
                            x++;
                        }
                    }
                }
                break;

            case 1026:
                bmp              = new Bitmap(width, height, PixelFormat.Format32bppArgb);
                bmpData          = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                uncompressedSize = width * height;
                decBuf           = new byte[uncompressedSize];
                zlib.Read(decBuf, 0, uncompressedSize);
                decBuf = GetPixelDataDXT3(decBuf, Width, Height);
                Marshal.Copy(decBuf, 0, bmpData.Scan0, decBuf.Length);
                bmp.UnlockBits(bmpData);
                break;


            case 2050:     // new
                bmp              = new Bitmap(width, height, PixelFormat.Format32bppArgb);
                bmpData          = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                uncompressedSize = width * height;
                decBuf           = new byte[uncompressedSize];
                zlib.Read(decBuf, 0, uncompressedSize);
                decBuf = GetPixelDataDXT5(decBuf, Width, Height);
                Marshal.Copy(decBuf, 0, bmpData.Scan0, decBuf.Length);
                bmp.UnlockBits(bmpData);
                break;

            default:
                Helpers.ErrorLogger.Log(Helpers.ErrorLevel.MissingFeature, string.Format("Unknown PNG format. nPixFormat: {0}, nMagLevel: {1}", this.nPixFormat, this.nMagLevel));
                break;
            }
            png = bmp;
        }
Exemplo n.º 20
0
        public void SaveMap(WzImage img, double zoom)
        {
            node = MainPanel.DataTree.SelectedNode;
            WzFile wzFile = (WzFile)((WzObject)node.Tag).WzFileParent;
            // Spawnpoint foothold and portal lists
            List <SpawnPoint.Spawnpoint> MSPs = new List <SpawnPoint.Spawnpoint>();
            List <FootHold.Foothold>     FHs  = new List <FootHold.Foothold>();
            List <Portals.Portal>        Ps   = new List <Portals.Portal>();
            Size  bmpSize;
            Point center;

            try
            {
                bmpSize = new Size(((WzIntProperty)((WzSubProperty)img["miniMap"])["width"]).Value, ((WzIntProperty)((WzSubProperty)img["miniMap"])["height"]).Value);
                center  = new Point(((WzIntProperty)((WzSubProperty)img["miniMap"])["centerX"]).Value, ((WzIntProperty)((WzSubProperty)img["miniMap"])["centerY"]).Value);
            }
            catch (KeyNotFoundException)
            {
                try
                {
                    bmpSize = new Size(((WzIntProperty)((WzSubProperty)img["info"])["VRRight"]).Value - ((WzIntProperty)((WzSubProperty)img["info"])["VRLeft"]).Value, ((WzIntProperty)((WzSubProperty)img["info"])["VRBottom"]).Value - ((WzIntProperty)((WzSubProperty)img["info"])["VRTop"]).Value);
                    center  = new Point(((WzIntProperty)((WzSubProperty)img["info"])["VRRight"]).Value, ((WzIntProperty)((WzSubProperty)img["info"])["VRBottom"]).Value);
                    //center = new Point(0, 0);
                }
                catch
                {
                    return;
                }
            }
            catch
            {
                return;
            }
            Bitmap mapRender = new Bitmap(bmpSize.Width, bmpSize.Height + 10);

            using (Graphics drawBuf = Graphics.FromImage(mapRender))
            {
                //drawBuf.FillRectangle(new SolidBrush(Color.CornflowerBlue), 0, 0, bmpSize.Width, bmpSize.Height);
                drawBuf.DrawString("Map " + img.Name.Substring(0, img.Name.Length - 4), new Font("Pragmata", 20), new SolidBrush(Color.Black), new PointF(10, 10));
                try
                {
                    drawBuf.DrawImage(((WzCanvasProperty)((WzSubProperty)img["miniMap"])["canvas"]).PngProperty.GetPNG(false), 10, 45);
                }
                catch (KeyNotFoundException)
                {
                    drawBuf.DrawString("Minimap not availible", new Font("Pragmata", 18), new SolidBrush(Color.Black), new PointF(10, 45));
                }
                WzSubProperty ps = (WzSubProperty)img["portal"];
                foreach (WzSubProperty p in ps.WzProperties)
                {
                    //WzSubProperty p = (WzSubProperty)p10.ExtendedProperty;
                    int   x      = ((WzIntProperty)p["x"]).Value + center.X;
                    int   y      = ((WzIntProperty)p["y"]).Value + center.Y;
                    int   type   = ((WzIntProperty)p["pt"]).Value;
                    Color pColor = Color.Red;
                    if (type == 0)
                    {
                        pColor = Color.Orange;
                    }
                    else if (type == 2 || type == 7)//Normal
                    {
                        pColor = Color.Blue;
                    }
                    else if (type == 3)//Auto-enter
                    {
                        pColor = Color.Magenta;
                    }
                    else if (type == 1 || type == 8)
                    {
                        pColor = Color.BlueViolet;
                    }
                    else
                    {
                        pColor = Color.IndianRed;
                    }
                    drawBuf.FillRectangle(new SolidBrush(Color.FromArgb(95, pColor.R, pColor.G, pColor.B)), x - 20, y - 20, 40, 40);
                    drawBuf.DrawRectangle(new Pen(Color.Black, 1F), x - 20, y - 20, 40, 40);
                    drawBuf.DrawString(p.Name, new Font("Pragmata", 8), new SolidBrush(Color.Red), x - 8, y - 7.7F);
                    Portals.Portal portal = new Portals.Portal();
                    portal.Shape = new Rectangle(x - 20, y - 20, 40, 40);
                    portal.Data  = p;
                    Ps.Add(portal);
                }
                try
                {
                    WzSubProperty SPs = (WzSubProperty)img["life"];
                    foreach (WzSubProperty sp in SPs.WzProperties)
                    {
                        Color MSPColor = Color.ForestGreen;
                        if (((WzStringProperty)sp["type"]).Value == "m")// Only mobs (NPC = "n")
                        {
                            int x = ((WzIntProperty)sp["x"]).Value + center.X - 15;
                            int y = ((WzIntProperty)sp["y"]).Value + center.Y - 15;
                            drawBuf.FillRectangle(new SolidBrush(Color.FromArgb(95, MSPColor.R, MSPColor.G, MSPColor.B)), x, y, 30, 30);
                            drawBuf.DrawRectangle(new Pen(Color.Black, 1F), x, y, 30, 30);
                            drawBuf.DrawString(sp.Name, new Font("Pragmata", 8), new SolidBrush(Color.Red), x + 7, y + 7.3F);
                            SpawnPoint.Spawnpoint MSP = new SpawnPoint.Spawnpoint();
                            MSP.Shape = new Rectangle(x, y, 30, 30);
                            MSP.Data  = sp;
                            MSPs.Add(MSP);
                        }
                    }
                }
                catch
                {
                }
                WzSubProperty fhs = (WzSubProperty)img["foothold"];
                foreach (WzImageProperty fhspl0 in fhs.WzProperties)
                {
                    foreach (WzImageProperty fhspl1 in fhspl0.WzProperties)
                    {
                        Color c = Color.FromArgb(95, Color.FromArgb(GetPseudoRandomColor(fhspl1.Name)));
                        foreach (WzSubProperty fh in fhspl1.WzProperties)
                        {
                            int x      = ((WzIntProperty)fh["x1"]).Value + center.X;
                            int y      = ((WzIntProperty)fh["y1"]).Value + center.Y;
                            int width  = ((((WzIntProperty)fh["x2"]).Value + center.X) - x);
                            int height = ((((WzIntProperty)fh["y2"]).Value + center.Y) - y);
                            if (width < 0)
                            {
                                x    += width;// *2;
                                width = -width;
                            }
                            if (height < 0)
                            {
                                y     += height;// *2;
                                height = -height;
                            }
                            if (width == 0 || width < 15)
                            {
                                width = 15;
                            }
                            height += 10;
                            FootHold.Foothold nFH = new FootHold.Foothold();
                            nFH.Shape = new Rectangle(x, y, width, height);
                            nFH.Data  = fh;
                            FHs.Add(nFH);
                            //drawBuf.FillRectangle(new SolidBrush(Color.FromArgb(95, Color.Gray.R, Color.Gray.G, Color.Gray.B)), x, y, width, height);
                            drawBuf.FillRectangle(new SolidBrush(c), x, y, width, height);
                            drawBuf.DrawRectangle(new Pen(Color.Black, 1F), x, y, width, height);
                            drawBuf.DrawString(fh.Name, new Font("Pragmata", 8), new SolidBrush(Color.Red), new PointF(x + (width / 2) - 8, y + (height / 2) - 7.7F));
                        }
                    }
                }
            }

            mapRender.Save("Renders\\" + img.Name.Substring(0, img.Name.Length - 4) + "\\" + img.Name.Substring(0, img.Name.Length - 4) + "_footholdRender.bmp");

            Bitmap tileRender = new Bitmap(bmpSize.Width, bmpSize.Height);

            using (Graphics tileBuf = Graphics.FromImage(tileRender))
            {
                for (int i = 0; i < 7; i++)
                {
                    // The below code was commented out because it was creating problems when loading certain maps. When debugging it would throw an exception at line 469.
                    // Objects first
                    if (((WzSubProperty)((WzSubProperty)img[i.ToString()])["obj"]).WzProperties.Count > 0)
                    {
                        foreach (WzSubProperty obj in ((WzSubProperty)((WzSubProperty)img[i.ToString()])["obj"]).WzProperties)
                        {
                            //WzSubProperty obj = (WzSubProperty)oe.ExtendedProperty;
                            string           imgName = ((WzStringProperty)obj["oS"]).Value + ".img";
                            string           l0      = ((WzStringProperty)obj["l0"]).Value;
                            string           l1      = ((WzStringProperty)obj["l1"]).Value;
                            string           l2      = ((WzStringProperty)obj["l2"]).Value;
                            int              x       = ((WzIntProperty)obj["x"]).Value + center.X;
                            int              y       = ((WzIntProperty)obj["y"]).Value + center.Y;
                            WzVectorProperty origin;
                            WzPngProperty    png;
                            WzImageProperty  objData = (WzImageProperty)wzFile.GetObjectFromPath(wzFile.WzDirectory.Name + "/Obj/" + imgName + "/" + l0 + "/" + l1 + "/" + l2 + "/0");
tryagain:
                            if (objData is WzCanvasProperty)
                            {
                                png    = ((WzCanvasProperty)objData).PngProperty;
                                origin = (WzVectorProperty)((WzCanvasProperty)objData)["origin"];
                            }
                            else if (objData is WzUOLProperty)
                            {
                                WzObject currProp = objData.Parent;
                                foreach (string directive in ((WzUOLProperty)objData).Value.Split("/".ToCharArray()))
                                {
                                    if (directive == "..")
                                    {
                                        currProp = currProp.Parent;
                                    }
                                    else
                                    {
                                        switch (currProp.GetType().Name)
                                        {
                                        case "WzSubProperty":
                                            currProp = ((WzSubProperty)currProp)[directive];
                                            break;

                                        case "WzCanvasProperty":
                                            currProp = ((WzCanvasProperty)currProp)[directive];
                                            break;

                                        case "WzImage":
                                            currProp = ((WzImage)currProp)[directive];
                                            break;

                                        case "WzConvexProperty":
                                            currProp = ((WzConvexProperty)currProp)[directive];
                                            break;

                                        default:
                                            throw new Exception("UOL error at map renderer");
                                        }
                                    }
                                }
                                objData = (WzImageProperty)currProp;
                                goto tryagain;
                            }
                            else
                            {
                                throw new Exception("unknown type at map renderer");
                            }
                            //WzVectorProperty origin = (WzVectorProperty)wzFile.GetObjectFromPath(wzFile.WzDirectory.Name + "/Obj/" + imgName + "/" + l0 + "/" + l1 + "/" + l2 + "/0");
                            //WzPngProperty png = (WzPngProperty)wzFile.GetObjectFromPath(wzFile.WzDirectory.Name + "/Obj/" + imgName + "/" + l0 + "/" + l1 + "/" + l2 + "/0/PNG");
                            tileBuf.DrawImage(png.GetPNG(false), x - origin.X.Value, y - origin.Y.Value);
                        }
                    }
                    if (((WzSubProperty)((WzSubProperty)img[i.ToString()])["info"]).WzProperties.Count == 0)
                    {
                        continue;
                    }

                    if (((WzSubProperty)((WzSubProperty)img[i.ToString()])["tile"]).WzProperties.Count == 0)
                    {
                        continue;
                    }

                    // Ok, we have some tiles and a tileset

                    string tileSetName = ((WzStringProperty)((WzSubProperty)((WzSubProperty)img[i.ToString()])["info"])["tS"]).Value;

                    // Browse to the tileset

                    WzImage tileSet = (WzImage)wzFile.GetObjectFromPath(wzFile.WzDirectory.Name + "/Tile/" + tileSetName + ".img");
                    if (!tileSet.Parsed)
                    {
                        tileSet.ParseImage();
                    }

                    foreach (WzSubProperty tile in ((WzSubProperty)((WzSubProperty)img[i.ToString()])["tile"]).WzProperties)
                    {
                        //WzSubProperty tile = (WzSubProperty)te.ExtendedProperty;

                        int x = ((WzIntProperty)tile["x"]).Value + center.X;

                        int y = ((WzIntProperty)tile["y"]).Value + center.Y;

                        string tilePackName = ((WzStringProperty)tile["u"]).Value;

                        string tileID = ((WzIntProperty)tile["no"]).Value.ToString();

                        Point origin = new Point(((WzVectorProperty)((WzCanvasProperty)((WzSubProperty)tileSet[tilePackName])[tileID])["origin"]).X.Value, ((WzVectorProperty)((WzCanvasProperty)((WzSubProperty)tileSet[tilePackName])[tileID])["origin"]).Y.Value);

                        tileBuf.DrawImage(((WzCanvasProperty)((WzSubProperty)tileSet[tilePackName])[tileID]).PngProperty.GetPNG(false), x - origin.X, y - origin.Y);
                    }
                }
            }

            tileRender.Save("Renders\\" + img.Name.Substring(0, img.Name.Length - 4) + "\\" + img.Name.Substring(0, img.Name.Length - 4) + "_tileRender.bmp");

            Bitmap fullBmp = new Bitmap(bmpSize.Width, bmpSize.Height + 10);

            using (Graphics fullBuf = Graphics.FromImage(fullBmp))
            {
                fullBuf.FillRectangle(new SolidBrush(Color.CornflowerBlue), 0, 0, bmpSize.Width, bmpSize.Height + 10);

                fullBuf.DrawImage(tileRender, 0, 0);

                fullBuf.DrawImage(mapRender, 0, 0);
            }
            //pbx_Foothold_Render.Image = fullBmp;
            fullBmp.Save("Renders\\" + img.Name.Substring(0, img.Name.Length - 4) + "\\" + img.Name.Substring(0, img.Name.Length - 4) + "_fullRender.bmp");

            DisplayMap showMap = new DisplayMap();

            showMap.map            = fullBmp;
            showMap.Footholds      = FHs;
            showMap.thePortals     = Ps;
            showMap.settings       = settings;
            showMap.MobSpawnPoints = MSPs;
            showMap.FormClosed    += new FormClosedEventHandler(DisplayMapClosed);
            try
            {
                showMap.scale = zoom;
                showMap.Show();
            }
            catch (FormatException)
            {
                MessageBox.Show("You must set the render scale to a valid number.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemplo n.º 21
0
        public static NpcInfo Load(WzImage parentObject)
        {
            string id = /*WzInfoTools.RemoveLeadingZeros(*/ WzInfoTools.RemoveExtension(parentObject.Name) /*)*/;

            return(new NpcInfo(null, new System.Drawing.Point(), id, WzInfoTools.GetNpcNameById(id), parentObject));
        }
Exemplo n.º 22
0
 public byte[] SerializeImage(WzImage img)
 {
     total = 1; curr = 0;
     return(serializeImageInternal(img));
 }
Exemplo n.º 23
0
 public static ReactorInfo Load(WzImage parentObject)
 {
     return(new ReactorInfo(null, new System.Drawing.Point(), /*WzInfoTools.RemoveLeadingZeros(*/ WzInfoTools.RemoveExtension(parentObject.Name) /*)*/, parentObject));
 }
Exemplo n.º 24
0
        public override void Start()
        {
            WzFile      file         = MapleFileCache.Instance["Etc"];
            WzDirectory familiarscwz = MapleFileCache.Instance["Character"].GetObjectFromPath("Character.wz/Familiar") as WzDirectory;

            if (familiarscwz != null)
            {
                WzFile mobfile = MapleFileCache.Instance["Mob"];

                familiarscwz.ParseImages();

                string familiarDir = exDir + "Character" + Path.DirectorySeparatorChar + "Familiar" + Path.DirectorySeparatorChar;
                //if (false)
                {
                    foreach (WzSubProperty prop in (file.WzDirectory["FamiliarInfo.img"] as WzImage).WzProperties)
                    {
                        int    famid   = int.Parse(prop.Name);
                        int    mobid   = prop["mob"].ToInt();
                        string tempdir = familiarDir + string.Format("{0:D7}.img", famid) + Path.DirectorySeparatorChar;

                        WzSubProperty charwzProp   = familiarscwz.GetImageByName(string.Format("{0}.img", famid))["info"] as WzSubProperty;
                        WzSubProperty skillSubProp = prop["skill"] as WzSubProperty;
                        FamiliarInfoSQL.Instance.AddFamiliar(famid, prop["consume"].ToInt(), mobid, charwzProp["grade"].ToInt(), charwzProp["range"].ToInt(), skillSubProp == null ? 0 : skillSubProp["id"].ToInt());

                        // Export images, too

                        WzImage mobimg = mobfile.WzDirectory[string.Format("{0:D7}.img", mobid)] as WzImage;

                        if (mobimg["info"] != null && mobimg["info"]["link"] != null)
                        {
                            // ---
                            Console.WriteLine("Nekson leik links");
                            mobimg = mobfile.WzDirectory[string.Format("{0:D7}.img", mobimg["info"]["link"].ToInt())] as WzImage;
                        }

                        if (mobimg["stand"] != null)
                        {
                            WzSubProperty subprop = mobimg["stand"] as WzSubProperty;
                            ExportIfExists(tempdir, subprop["0"], "stand");
                            foreach (var prop2 in subprop["0"].WzProperties)
                            {
                                ExportIfExists(tempdir, prop2, "stand.0");
                            }
                        }
                        else if (mobimg["fly"] != null)
                        {
                            WzSubProperty subprop = mobimg["fly"] as WzSubProperty;
                            ExportIfExists(tempdir, subprop["0"], "stand");
                            foreach (var prop2 in subprop["0"].WzProperties)
                            {
                                ExportIfExists(tempdir, prop2, "stand.0");
                            }
                        }
                    }
                }
            }

            this.currentID = 90000000;
            foreach (WzSubProperty prop in (file.WzDirectory["SetItemInfo.img"] as WzImage).WzProperties)
            {
                ExportProps(prop, prop.Name);
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="image"></param>
        /// <param name="strMapName"></param>
        /// <param name="strStreetName"></param>
        /// <param name="strCategoryName"></param>
        public MapInfo(WzImage image, string strMapName, string strStreetName, string strCategoryName)
        {
            this.image = image;
            int?startHour;
            int?endHour;

            this.strMapName      = strMapName;
            this.strStreetName   = strStreetName;
            this.strCategoryName = strCategoryName;
            WzFile file         = (WzFile)image.WzFileParent;
            string loggerSuffix = ", map " + image.Name + ((file != null) ? (" of version " + Enum.GetName(typeof(WzMapleVersion), file.MapleVersion) + ", v" + file.Version.ToString()) : "");

            foreach (WzImageProperty prop in image["info"].WzProperties)
            {
                switch (prop.Name)
                {
                case "bgm":
                    bgm = InfoTool.GetString(prop);
                    break;

                case "cloud":
                    cloud = InfoTool.GetBool(prop);
                    break;

                case "swim":
                    swim = InfoTool.GetBool(prop);
                    break;

                case "forcedReturn":
                    forcedReturn = InfoTool.GetInt(prop);
                    break;

                case "hideMinimap":
                    hideMinimap = InfoTool.GetBool(prop);
                    break;

                case "mapDesc":
                    mapDesc = InfoTool.GetString(prop);
                    break;

                case "mapName":
                    mapName = InfoTool.GetString(prop);
                    break;

                case "mapMark":
                    mapMark = InfoTool.GetString(prop);
                    break;

                case "mobRate":
                    mobRate = InfoTool.GetFloat(prop);
                    break;

                case "moveLimit":
                    moveLimit = InfoTool.GetInt(prop);
                    break;

                case "returnMap":
                    returnMap = InfoTool.GetInt(prop);
                    break;

                case "town":
                    town = InfoTool.GetBool(prop);
                    break;

                case "version":
                    version = InfoTool.GetInt(prop);
                    break;

                case "fieldLimit":
                    long fl = InfoTool.GetLong(prop);
                    fieldLimit = fl;
                    break;

                case "VRTop":
                    VRTop = InfoTool.GetOptionalInt(prop, 0);
                    break;

                case "VRBottom":
                    VRBottom = InfoTool.GetOptionalInt(prop, 0);
                    break;

                case "VRLeft":
                    VRLeft = InfoTool.GetOptionalInt(prop, 0);
                    break;

                case "VRRight":
                    VRRight = InfoTool.GetOptionalInt(prop, 0);
                    break;

                case "link":
                    //link = InfoTool.GetInt(prop);
                    break;

                case "timeLimit":
                    timeLimit = InfoTool.GetInt(prop);
                    break;

                case "lvLimit":
                    lvLimit = InfoTool.GetInt(prop);
                    break;

                case "onFirstUserEnter":
                    onFirstUserEnter = InfoTool.GetString(prop);
                    break;

                case "onUserEnter":
                    onUserEnter = InfoTool.GetString(prop);
                    break;

                case "fly":
                    fly = InfoTool.GetBool(prop);
                    break;

                case "noMapCmd":
                    noMapCmd = InfoTool.GetBool(prop);
                    break;

                case "partyOnly":
                    partyOnly = InfoTool.GetBool(prop);
                    break;

                case "fieldType":
                    int ft = InfoTool.GetInt(prop);
                    if (!Enum.IsDefined(typeof(FieldType), ft))
                    {
                        ErrorLogger.Log(ErrorLevel.IncorrectStructure, "Invalid fieldType " + ft.ToString() + loggerSuffix);
                        ft = 0;
                    }
                    fieldType = (FieldType)ft;
                    break;

                case "miniMapOnOff":
                    miniMapOnOff = InfoTool.GetBool(prop);
                    break;

                case "reactorShuffle":
                    reactorShuffle = InfoTool.GetBool(prop);
                    break;

                case "reactorShuffleName":
                    reactorShuffleName = InfoTool.GetString(prop);
                    break;

                case "personalShop":
                    personalShop = InfoTool.GetBool(prop);
                    break;

                case "entrustedShop":
                    entrustedShop = InfoTool.GetBool(prop);
                    break;

                case "effect":
                    effect = InfoTool.GetString(prop);
                    break;

                case "lvForceMove":
                    lvForceMove = InfoTool.GetInt(prop);
                    break;

                case "timeMob":
                    startHour = InfoTool.GetOptionalInt(prop["startHour"]);
                    endHour   = InfoTool.GetOptionalInt(prop["endHour"]);
                    int?   id      = InfoTool.GetOptionalInt(prop["id"]);
                    string message = InfoTool.GetOptionalString(prop["message"]);
                    if (id == null || message == null || (startHour == null ^ endHour == null))
                    {
                        ErrorLogger.Log(ErrorLevel.IncorrectStructure, "timeMob" + loggerSuffix);
                    }
                    else
                    {
                        timeMob = new TimeMob((int?)startHour, (int?)endHour, (int)id, message);
                    }
                    break;

                case "help":
                    help = InfoTool.GetString(prop);
                    break;

                case "snow":
                    snow = InfoTool.GetBool(prop);
                    break;

                case "rain":
                    rain = InfoTool.GetBool(prop);
                    break;

                case "dropExpire":
                    dropExpire = InfoTool.GetInt(prop);
                    break;

                case "decHP":
                    decHP = InfoTool.GetInt(prop);
                    break;

                case "decInterval":
                    decInterval = InfoTool.GetInt(prop);
                    break;

                case "autoLieDetector":
                    startHour = InfoTool.GetOptionalInt(prop["startHour"]);
                    endHour   = InfoTool.GetOptionalInt(prop["endHour"]);
                    int?interval = InfoTool.GetOptionalInt(prop["interval"]);
                    int?propInt  = InfoTool.GetOptionalInt(prop["prop"]);
                    if (startHour == null || endHour == null || interval == null || propInt == null)
                    {
                        ErrorLogger.Log(ErrorLevel.IncorrectStructure, "autoLieDetector" + loggerSuffix);
                    }
                    else
                    {
                        autoLieDetector = new AutoLieDetector((int)startHour, (int)endHour, (int)interval, (int)propInt);
                    }
                    break;

                case "expeditionOnly":
                    expeditionOnly = InfoTool.GetBool(prop);
                    break;

                case "fs":
                    fs = InfoTool.GetFloat(prop);
                    break;

                case "protectItem":
                    protectItem = InfoTool.GetInt(prop);
                    break;

                case "createMobInterval":
                    createMobInterval = InfoTool.GetInt(prop);
                    break;

                case "fixedMobCapacity":
                    fixedMobCapacity = InfoTool.GetInt(prop);
                    break;

                case "streetName":
                    streetName = InfoTool.GetString(prop);
                    break;

                case "noRegenMap":
                    noRegenMap = InfoTool.GetBool(prop);
                    break;

                case "allowedItem":
                    allowedItem = new List <int>();
                    if (prop.WzProperties != null && prop.WzProperties.Count > 0)
                    {
                        foreach (WzImageProperty item in prop.WzProperties)
                        {
                            allowedItem.Add(item.GetInt());
                        }
                    }
                    break;

                case "recovery":
                    recovery = InfoTool.GetFloat(prop);
                    break;

                case "blockPBossChange":
                    blockPBossChange = InfoTool.GetBool(prop);
                    break;

                case "everlast":
                    everlast = InfoTool.GetBool(prop);
                    break;

                case "damageCheckFree":
                    damageCheckFree = InfoTool.GetBool(prop);
                    break;

                case "dropRate":
                    dropRate = InfoTool.GetFloat(prop);
                    break;

                case "scrollDisable":
                    scrollDisable = InfoTool.GetBool(prop);
                    break;

                case "needSkillForFly":
                    needSkillForFly = InfoTool.GetBool(prop);
                    break;

                case "zakum2Hack":
                    zakum2Hack = InfoTool.GetBool(prop);
                    break;

                case "allMoveCheck":
                    allMoveCheck = InfoTool.GetBool(prop);
                    break;

                case "VRLimit":
                    VRLimit = InfoTool.GetBool(prop);
                    break;

                case "consumeItemCoolTime":
                    consumeItemCoolTime = InfoTool.GetBool(prop);
                    break;

                case "zeroSideOnly":
                    zeroSideOnly = InfoTool.GetBool(prop);
                    break;

                case "mirror_Bottom":
                    mirror_Bottom = InfoTool.GetBool(prop);
                    break;

                case "AmbientBGM":
                case "AmbientBGMv":
                case "areaCtrl":
                case "onlyUseSkill":
                case "limitUseShop":
                case "limitUseTrunk":
                case "freeFallingVX":
                case "midAirAccelVX":
                case "midAirDecelVX":
                case "jumpSpeedR":
                case "jumpAccUpKey":
                case "jumpAccDownKey":
                case "jumpApplyVX":
                case "dashSkill":
                case "speedMaxOver":
                case "speedMaxOver ":     // with a space, stupid nexon
                case "isSpecialMoveCheck":
                case "forceSpeed":
                case "forceJump":
                case "forceUseIndie":
                case "vanishPet":
                case "vanishAndroid":
                case "vanishDragon":
                case "limitUI":
                case "largeSplit":
                case "qrLimit":
                case "noChair":
                case "fieldScript":
                case "standAlone":
                case "partyStandAlone":
                case "HobbangKing":
                case "quarterView":
                case "MRLeft":
                case "MRTop":
                case "MRRight":
                case "MRBottom":
                case "limitSpeedAndJump":
                case "directionInfo":
                case "LBSide":
                case "LBTop":
                case "LBBottom":
                case "bgmSub":
                case "fieldLimit2":
                case "fieldLimit_tw":
                case "particle":
                case "qrLimitJob":
                case "individualMobPool":
                case "barrier":
                case "remoteEffect":
                case "isFixDec":
                case "decHPr":
                case "isDecView":
                case "forceFadeInTime":
                case "forceFadeOutTime":
                case "qrLimitState":
                case "qrLimitState2":
                case "difficulty":
                case "alarm":
                case "bossMobID":
                case "reviveCurField":
                case "ReviveCurFieldOfNoTransfer":
                case "ReviveCurFieldOfNoTransferPoint":
                case "limitUserEffectField":
                case "nofollowCharacter":
                case "functionObjInfo":
                case "quest":
                case "ridingMove":
                case "ridingField":
                case "noLanding":
                case "noCancelSkill":
                case "defaultAvatarDir":
                case "footStepSound":
                case "taggedObjRegenInfo":
                case "offSoulAbsorption":
                case "canPartyStatChangeIgnoreParty":
                case "canPartyStatChangeIgnoreParty ":     // with a space
                case "forceReturnOnDead":
                case "zoomOutField":
                case "EscortMinTime":
                case "deathCount":
                case "onEnterResetFifthSkill":
                case "potionLimit":
                case "lifeCount":
                case "respawnCooltimeField":
                case "scale":
                case "skills":
                case "noResurection":
                case "incInterval":
                case "incMPr":
                case "bonusExpPerUserHPRate":
                case "barrierArc":
                case "noBackOverlapped":
                case "partyBonusR":
                case "specialSound":
                case "inFieldsetForcedReturn":
                case "chaser":
                case "chaserEndTime":
                case "chaserEffect":
                case "cagePotal":
                case "cageLT":
                case "cageRB":
                case "chaserHoldTime":
                case "phase":
                case "boss":
                case "actionBarIdx":
                case "shadowzone":
                case "towerChairEnable":
                case "DiceMasterUpIndex":
                case "DiceMasterDownIndex":
                case "ChangeName":
                case "entrustedFishing":
                case "forcedScreenMode":
                case "isHideUI":
                case "resetRidingField":
                case "PL_Gunman":
                case "noHekatonEffect":
                case "mode":
                case "skill":
                case "MR":
                case "ratemob":
                case "bonusStageNoChangeBack":
                case "questAmbience":
                case "blockScriptItem":
                case "remoteTranslucenceView":
                case "rewardContentName":
                case "specialDeadAction":
                case "FriendsStoryBossDelay":
                case "soulFieldType":
                case "cameraMoveY":
                case "subType":
                case "playTime":
                case "noEvent":
                case "forParty":
                case "whiteOut":
                case "UserInvisible":
                case "OnFirstUserEnter":     // the same as onFirstUserEnter
                case "teamPortal":
                case "typingGame":
                case "lt":
                case "rb":
                case "fieldAttackObj":
                case "timeLeft":
                case "timeLeft_d":
                case "eventSummon":
                case "rankCheckMob":
                case "questCheckMob":
                case "bindSkillLimit":
                case "NoMobCapacityLimit":
                case "userTimer":
                case "eventChairIndex":
                case "onlyEventChair":
                case "waitReviveTime":
                case "RidingTop":
                case "temporarySkill":
                case "largeSplt":
                case "blockTakeOffItem":
                case "PartyOnly":
                case "climb":
                case "bulletConsume":
                case "gaugeDelay":
                case "individualPet":
                case "level":
                case "hungryMuto":
                case "property":                //  map 921172300.img
                case "spiritSavior":
                case "standAlonePermitUpgrade": //  993059600.img
                case "limitHeadAlarmField":     // 993180000.img
                {
                    WzImageProperty cloneProperty = prop.DeepClone();
                    //cloneProperty.Parent = prop.Parent;

                    unsupportedInfoProperties.Add(cloneProperty);
                    break;
                }

                default:
                    ErrorLogger.Log(ErrorLevel.MissingFeature, string.Format("[MapInfo] Unknown field info/ property: '{0}'. {1}. Please fix it at MapInfo.cs", prop.Name, loggerSuffix));
                    additionalProps.Add(prop.DeepClone());
                    break;
                }
            }
        }
        /// <summary>
        /// Caches all inventory data from String.wz
        /// </summary>
        private void CacheInventoryData()
        {
            WzDirectory StringDir = Files["String.wz"].WzDirectory;

            // Directories
            WzImage MobDir = (WzImage)StringDir["Mob.img"];

            WzImage CashDir    = (WzImage)StringDir["Cash.img"];
            WzImage ConsumeDir = (WzImage)StringDir["Consume.img"];
            WzImage EqpDir     = (WzImage)StringDir["Eqp.img"];
            WzImage EtcDir     = (WzImage)StringDir["Etc.img"];
            WzImage InsDir     = (WzImage)StringDir["Ins.img"];
            WzImage NpcDir     = (WzImage)StringDir["Npc.img"];
            WzImage SkillDir   = (WzImage)StringDir["Skill.img"];

            // Skills
            foreach (WzSubProperty skill in SkillDir.WzProperties)
            {
                int SkillIdOrJobID = int.Parse(skill.Name);

                string bookName = skill["bookName"]?.ReadString(null);
                if (bookName != null)
                {
                    if (!JobsCache.ContainsKey(SkillIdOrJobID))
                    {
                        JobsCache.Add(SkillIdOrJobID, bookName);
                    }
                }
                else
                {
                    string name = skill["name"]?.ReadString("NULL");
                    string desc = skill["desc"]?.ReadString(null);
                    string h1   = skill["h1"]?.ReadString(null);

                    if (desc == null)
                    {
                        desc = string.Empty;
                    }
                    if (h1 == null)
                    {
                        h1 = string.Empty;
                    }

                    if (name != null)
                    {
                        if (!SkillsCache.ContainsKey(SkillIdOrJobID))
                        {
                            SkillsCache.Add(SkillIdOrJobID, new Tuple <string, string, string>(name, desc, h1));
                        }
                        else
                        {
                            Debug.WriteLine("[WzDataCache] Skillid already exist in the key " + SkillIdOrJobID);
                        }
                    }
                }
            }

            // NPCs
            foreach (WzSubProperty NPC in NpcDir.WzProperties)
            {
                int NPCId = int.Parse(NPC.Name);

                if (NPCsCache.ContainsKey(NPCId))
                {
                    continue;
                }

                NPCsCache.Add(NPCId, new KeyValuePair <string, string>(
                                  NPC["name"].ReadString("NULL"),
                                  NPC["func"].ReadString("NULL")));
            }

            // Cash Item
            foreach (WzSubProperty Item in CashDir.WzProperties)
            {
                int Id = int.Parse(Item.Name);

                if (CashItemCache.ContainsKey(Id))
                {
                    continue;
                }

                CashItemCache.Add(Id, new KeyValuePair <string, string>(
                                      Item["name"].ReadString("NULL"),
                                      Item["desc"].ReadString("NULL")));
            }

            // Consume
            foreach (WzSubProperty Item in ConsumeDir.WzProperties)
            {
                int Id = int.Parse(Item.Name);

                if (UseItemCache.ContainsKey(Id))
                {
                    continue;
                }

                UseItemCache.Add(Id, new KeyValuePair <string, string>(
                                     Item["name"].ReadString("NULL"),
                                     Item["desc"].ReadString("NULL")));
            }

            // Ins / Setup
            foreach (WzSubProperty Item in InsDir.WzProperties)
            {
                int Id = int.Parse(Item.Name);

                if (SetupItemCache.ContainsKey(Id))
                {
                    continue;
                }

                SetupItemCache.Add(Id, new KeyValuePair <string, string>(
                                       Item["name"].ReadString("NULL"),
                                       Item["desc"].ReadString("NULL")));
            }

            // Etc
            foreach (WzSubProperty MapArea in EtcDir.WzProperties)
            {
                string dirName = MapArea.Name;

                foreach (WzSubProperty Item in MapArea.WzProperties)
                {
                    int Id = int.Parse(Item.Name);

                    if (EtcItemCache.ContainsKey(Id))
                    {
                        continue;
                    }

                    EtcItemCache.Add(Id, new KeyValuePair <string, string>(
                                         Item["name"].ReadString("NULL"),
                                         Item["desc"].ReadString("NULL")));
                }
            }

            // Equip
            foreach (WzSubProperty Eqp in EqpDir.WzProperties)
            {
                string dirName = Eqp.Name;

                foreach (WzSubProperty EqpCategories in Eqp.WzProperties)
                {
                    string EqpCategoriesName = Eqp.Name;

                    foreach (WzSubProperty EqpCategoriesItem in EqpCategories.WzProperties)
                    {
                        int Id = int.Parse(EqpCategoriesItem.Name);

                        if (EqpItemCache.ContainsKey(Id))
                        {
                            continue;
                        }
                        EqpItemCache.Add(Id, new KeyValuePair <string, string>(
                                             EqpCategoriesItem["name"].ReadString("NULL"),
                                             EqpCategoriesItem["desc"].ReadString("NULL")));
                    }
                }
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Save MapInfo variables to WzImage
        /// </summary>
        /// <param name="dest"></param>
        /// <param name="VR"></param>
        public void Save(WzImage dest, Rectangle?VR)
        {
            WzSubProperty info = new WzSubProperty();

            info["bgm"]          = InfoTool.SetString(bgm);
            info["cloud"]        = InfoTool.SetBool(cloud);
            info["swim"]         = InfoTool.SetBool(swim);
            info["forcedReturn"] = InfoTool.SetInt(forcedReturn);
            info["hideMinimap"]  = InfoTool.SetBool(hideMinimap);
            info["mapDesc"]      = InfoTool.SetOptionalString(mapDesc);
            info["mapName"]      = InfoTool.SetOptionalString(mapDesc);
            info["mapMark"]      = InfoTool.SetString(mapMark);
            info["mobRate"]      = InfoTool.SetFloat(mobRate);
            info["moveLimit"]    = InfoTool.SetOptionalInt(moveLimit);
            info["returnMap"]    = InfoTool.SetInt(returnMap);
            info["town"]         = InfoTool.SetBool(town);
            info["version"]      = InfoTool.SetInt(version);
            info["fieldLimit"]   = InfoTool.SetInt((int)fieldLimit);
            info["timeLimit"]    = InfoTool.SetOptionalInt(timeLimit);
            info["lvLimit"]      = InfoTool.SetOptionalInt(lvLimit);

            info["VRTop"]    = InfoTool.SetOptionalInt(VRTop);
            info["VRBottom"] = InfoTool.SetOptionalInt(VRBottom);
            info["VRLeft"]   = InfoTool.SetOptionalInt(VRLeft);
            info["VRRight"]  = InfoTool.SetOptionalInt(VRRight);

            info["onFirstUserEnter"] = InfoTool.SetOptionalString(onFirstUserEnter);
            info["onUserEnter"]      = InfoTool.SetOptionalString(onUserEnter);
            info["fly"]                = InfoTool.SetOptionalBool(fly);
            info["noMapCmd"]           = InfoTool.SetOptionalBool(noMapCmd);
            info["partyOnly"]          = InfoTool.SetOptionalBool(partyOnly);
            info["fieldType"]          = InfoTool.SetOptionalInt((int?)fieldType);
            info["miniMapOnOff"]       = InfoTool.SetOptionalBool(miniMapOnOff);
            info["reactorShuffle"]     = InfoTool.SetOptionalBool(reactorShuffle);
            info["reactorShuffleName"] = InfoTool.SetOptionalString(reactorShuffleName);
            info["personalShop"]       = InfoTool.SetOptionalBool(personalShop);
            info["entrustedShop"]      = InfoTool.SetOptionalBool(entrustedShop);
            info["effect"]             = InfoTool.SetOptionalString(effect);
            info["lvForceMove"]        = InfoTool.SetOptionalInt(lvForceMove);
            info["mirror_Bottom"]      = InfoTool.SetOptionalBool(mirror_Bottom);

            // Time mob
            if (timeMob != null)
            {
                WzSubProperty prop = new WzSubProperty();
                prop["startHour"] = InfoTool.SetOptionalInt(timeMob.Value.startHour);
                prop["endHour"]   = InfoTool.SetOptionalInt(timeMob.Value.endHour);
                prop["id"]        = InfoTool.SetOptionalInt(timeMob.Value.id);
                prop["message"]   = InfoTool.SetOptionalString(timeMob.Value.message);
                info["timeMob"]   = prop;
            }
            info["help"]        = InfoTool.SetOptionalString(help);
            info["snow"]        = InfoTool.SetOptionalBool(snow);
            info["rain"]        = InfoTool.SetOptionalBool(rain);
            info["dropExpire"]  = InfoTool.SetOptionalInt(dropExpire);
            info["decHP"]       = InfoTool.SetOptionalInt(decHP);
            info["decInterval"] = InfoTool.SetOptionalInt(decInterval);

            // Lie detector
            if (autoLieDetector != null)
            {
                WzSubProperty prop = new WzSubProperty();
                prop["startHour"]       = InfoTool.SetOptionalInt(autoLieDetector.startHour);
                prop["endHour"]         = InfoTool.SetOptionalInt(autoLieDetector.endHour);
                prop["interval"]        = InfoTool.SetOptionalInt(autoLieDetector.interval);
                prop["prop"]            = InfoTool.SetOptionalInt(autoLieDetector.prop);
                info["autoLieDetector"] = prop;
            }
            info["expeditionOnly"]    = InfoTool.SetOptionalBool(expeditionOnly);
            info["fs"]                = InfoTool.SetOptionalFloat(fs);
            info["protectItem"]       = InfoTool.SetOptionalInt(protectItem);
            info["createMobInterval"] = InfoTool.SetOptionalInt(createMobInterval);
            info["fixedMobCapacity"]  = InfoTool.SetOptionalInt(fixedMobCapacity);
            info["streetName"]        = InfoTool.SetOptionalString(streetName);
            info["noRegenMap"]        = InfoTool.SetOptionalBool(noRegenMap);
            if (allowedItem != null)
            {
                WzSubProperty prop = new WzSubProperty();
                for (int i = 0; i < allowedItem.Count; i++)
                {
                    prop[i.ToString()] = InfoTool.SetInt(allowedItem[i]);
                }
                info["allowedItem"] = prop;
            }
            info["recovery"]            = InfoTool.SetOptionalFloat(recovery);
            info["blockPBossChange"]    = InfoTool.SetOptionalBool(blockPBossChange);
            info["everlast"]            = InfoTool.SetOptionalBool(everlast);
            info["damageCheckFree"]     = InfoTool.SetOptionalBool(damageCheckFree);
            info["dropRate"]            = InfoTool.SetOptionalFloat(dropRate);
            info["scrollDisable"]       = InfoTool.SetOptionalBool(scrollDisable);
            info["needSkillForFly"]     = InfoTool.SetOptionalBool(needSkillForFly);
            info["zakum2Hack"]          = InfoTool.SetOptionalBool(zakum2Hack);
            info["allMoveCheck"]        = InfoTool.SetOptionalBool(allMoveCheck);
            info["VRLimit"]             = InfoTool.SetOptionalBool(VRLimit);
            info["consumeItemCoolTime"] = InfoTool.SetOptionalBool(consumeItemCoolTime);
            info["zeroSideOnly"]        = InfoTool.SetOptionalBool(zeroSideOnly);
            foreach (WzImageProperty prop in additionalProps)
            {
                info.AddProperty(prop);
            }
            if (VR.HasValue)
            {
                info["VRLeft"]   = InfoTool.SetInt(VR.Value.Left);
                info["VRRight"]  = InfoTool.SetInt(VR.Value.Right);
                info["VRTop"]    = InfoTool.SetInt(VR.Value.Top);
                info["VRBottom"] = InfoTool.SetInt(VR.Value.Bottom);
            }

            // Add back all unsupported properties
            info.AddProperties(unsupportedInfoProperties);

            //
            dest["info"] = info;
        }
Exemplo n.º 28
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            if (versionBox.Value < 0)
            {
                Warning.Error(HaRepacker.Properties.Resources.SaveVersionError);
                return;
            }

            using (SaveFileDialog dialog = new SaveFileDialog()
            {
                Title = HaRepacker.Properties.Resources.SelectOutWz,
                FileName = wzNode.Text,
                Filter = string.Format("{0}|*.wz",
                                       HaRepacker.Properties.Resources.WzFilter)
            })
            {
                if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                WzMapleVersion wzMapleVersionSelected = (WzMapleVersion)encryptionBox.SelectedIndex;
                if (this.IsRegularWzFile)
                {
                    if (wzf is WzFile && wzf.MapleVersion != wzMapleVersionSelected)
                    {
                        PrepareAllImgs(((WzFile)wzf).WzDirectory);
                    }

                    wzf.MapleVersion = (WzMapleVersion)encryptionBox.SelectedIndex;
                    if (wzf is WzFile)
                    {
                        ((WzFile)wzf).Version = (short)versionBox.Value;
                    }
                    if (wzf.FilePath != null && wzf.FilePath.ToLower() == dialog.FileName.ToLower())
                    {
                        wzf.SaveToDisk(dialog.FileName + "$tmp");
                        wzNode.Delete();
                        File.Delete(dialog.FileName);
                        File.Move(dialog.FileName + "$tmp", dialog.FileName);
                    }
                    else
                    {
                        wzf.SaveToDisk(dialog.FileName);
                        wzNode.Delete();
                    }

                    // Reload the new file
                    WzFile loadedWzFile = Program.WzMan.LoadWzFile(dialog.FileName, (WzMapleVersion)encryptionBox.SelectedIndex);
                    if (loadedWzFile != null)
                    {
                        Program.WzMan.AddLoadedWzFileToMainPanel(loadedWzFile, panel);
                    }
                }
                else
                {
                    byte[] WzIv = WzTool.GetIvByMapleVersion(wzMapleVersionSelected);

                    // Save file
                    string tmpFilePath    = dialog.FileName + ".tmp";
                    string targetFilePath = dialog.FileName;

                    bool error_noAdminPriviledge = false;
                    try
                    {
                        using (FileStream oldfs = File.Open(tmpFilePath, FileMode.OpenOrCreate))
                        {
                            using (WzBinaryWriter wzWriter = new WzBinaryWriter(oldfs, WzIv))
                            {
                                wzImg.SaveImage(wzWriter, true); // Write to temp folder
                            }
                        }
                        try
                        {
                            File.Copy(tmpFilePath, targetFilePath, true);
                            File.Delete(tmpFilePath);
                        }
                        catch (Exception exp)
                        {
                            Debug.WriteLine(exp); // nvm, dont show to user
                        }
                        wzNode.Delete();
                    }
                    catch (UnauthorizedAccessException)
                    {
                        error_noAdminPriviledge = true;
                    }

                    // Reload the new file
                    WzImage img = Program.WzMan.LoadDataWzHotfixFile(dialog.FileName, wzMapleVersionSelected, panel);
                    if (img == null || error_noAdminPriviledge)
                    {
                        MessageBox.Show(HaRepacker.Properties.Resources.MainFileOpenFail, HaRepacker.Properties.Resources.Error);
                    }
                }
            }
            Close();
        }
        /// <summary>
        /// Draws the frame and the UI of the minimap.
        /// TODO: This whole thing needs to be dramatically simplified via further abstraction to keep it noob-proof :(
        /// </summary>
        /// <param name="UIWZFile">UI.wz file directory</param>
        /// <param name="mapBoard"></param>
        /// <param name="device"></param>
        /// <param name="UserScreenScaleFactor">The scale factor of the window (DPI)</param>
        /// <param name="MapName">The map name. i.e The Hill North</param>
        /// <param name="StreetName">The street name. i.e Hidden street</param>
        /// <param name="bBigBang">Big bang update</param>
        /// <returns></returns>
        public static MinimapItem CreateMinimapFromProperty(WzDirectory UIWZFile, Board mapBoard, GraphicsDevice device, float UserScreenScaleFactor, string MapName, string StreetName, WzDirectory SoundWZFile, bool bBigBang)
        {
            if (mapBoard.MiniMap == null)
            {
                return(null);
            }

            WzSubProperty minimapFrameProperty = (WzSubProperty)UIWZFile["UIWindow2.img"]?["MiniMap"];

            if (minimapFrameProperty == null) // UIWindow2 not available pre-BB.
            {
                minimapFrameProperty = (WzSubProperty)UIWZFile["UIWindow.img"]?["MiniMap"];
            }

            WzSubProperty maxMapProperty        = (WzSubProperty)minimapFrameProperty["MaxMap"];
            WzSubProperty miniMapProperty       = (WzSubProperty)minimapFrameProperty["MinMap"];
            WzSubProperty maxMapMirrorProperty  = (WzSubProperty)minimapFrameProperty["MaxMapMirror"]; // for Zero maps
            WzSubProperty miniMapMirrorProperty = (WzSubProperty)minimapFrameProperty["MinMapMirror"]; // for Zero maps


            WzSubProperty useFrame;

            if (mapBoard.MapInfo.zeroSideOnly || MapConstants.IsZerosTemple(mapBoard.MapInfo.id)) // zero's temple
            {
                useFrame = maxMapMirrorProperty;
            }
            else
            {
                useFrame = maxMapProperty;
            }

            // Wz frames
            System.Drawing.Bitmap c  = ((WzCanvasProperty)useFrame?["c"])?.GetLinkedWzCanvasBitmap();
            System.Drawing.Bitmap e  = ((WzCanvasProperty)useFrame?["e"])?.GetLinkedWzCanvasBitmap();
            System.Drawing.Bitmap n  = ((WzCanvasProperty)useFrame?["n"])?.GetLinkedWzCanvasBitmap();
            System.Drawing.Bitmap s  = ((WzCanvasProperty)useFrame?["s"])?.GetLinkedWzCanvasBitmap();
            System.Drawing.Bitmap w  = ((WzCanvasProperty)useFrame?["w"])?.GetLinkedWzCanvasBitmap();
            System.Drawing.Bitmap ne = ((WzCanvasProperty)useFrame?["ne"])?.GetLinkedWzCanvasBitmap(); // top right
            System.Drawing.Bitmap nw = ((WzCanvasProperty)useFrame?["nw"])?.GetLinkedWzCanvasBitmap(); // top left
            System.Drawing.Bitmap se = ((WzCanvasProperty)useFrame?["se"])?.GetLinkedWzCanvasBitmap(); // bottom right
            System.Drawing.Bitmap sw = ((WzCanvasProperty)useFrame?["sw"])?.GetLinkedWzCanvasBitmap(); // bottom left

            // Constants
            const float TOOLTIP_FONTSIZE         = 10f;
            const int   MAPMARK_IMAGE_ALIGN_LEFT = 7; // the number of pixels from the left to draw the map mark image
            const int   MAP_IMAGE_PADDING        = 2; // the number of pixels from the left to draw the minimap image

            System.Drawing.Color color_bgFill     = System.Drawing.Color.Transparent;
            System.Drawing.Color color_foreGround = System.Drawing.Color.White;

            string renderText = string.Format("{0}{1}{2}", StreetName, Environment.NewLine, MapName);


            // Map background image
            System.Drawing.Bitmap miniMapImage = mapBoard.MiniMap; // the original minimap image without UI frame overlay
            int effective_width  = miniMapImage.Width + e.Width + w.Width;
            int effective_height = miniMapImage.Height + n.Height + s.Height;

            using (System.Drawing.Font font = new System.Drawing.Font(GLOBAL_FONT, TOOLTIP_FONTSIZE / UserScreenScaleFactor))
            {
                // Get the width of the 'streetName' or 'mapName'
                System.Drawing.Graphics graphics_dummy = System.Drawing.Graphics.FromImage(new System.Drawing.Bitmap(1, 1)); // dummy image just to get the Graphics object for measuring string
                System.Drawing.SizeF    tooltipSize    = graphics_dummy.MeasureString(renderText, font);

                effective_width = Math.Max((int)tooltipSize.Width + nw.Width, effective_width); // set new width

                int miniMapAlignXFromLeft = MAP_IMAGE_PADDING;
                if (effective_width > miniMapImage.Width) // if minimap is smaller in size than the (text + frame), minimap will be aligned to the center instead
                {
                    miniMapAlignXFromLeft = (effective_width - miniMapImage.Width) / 2 /* - miniMapAlignXFromLeft*/;
                }

                System.Drawing.Bitmap miniMapUIImage = new System.Drawing.Bitmap(effective_width, effective_height);
                using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(miniMapUIImage))
                {
                    // Frames and background
                    UIFrameHelper.DrawUIFrame(graphics, color_bgFill, ne, nw, se, sw, e, w, n, s, null, effective_width, effective_height);

                    // Map name + street name
                    graphics.DrawString(
                        renderText,
                        font, new System.Drawing.SolidBrush(color_foreGround), 50, 20);

                    // Map mark
                    if (Program.InfoManager.MapMarks.ContainsKey(mapBoard.MapInfo.mapMark))
                    {
                        System.Drawing.Bitmap mapMark = Program.InfoManager.MapMarks[mapBoard.MapInfo.mapMark];
                        graphics.DrawImage(mapMark.ToImage(), MAPMARK_IMAGE_ALIGN_LEFT, 17);
                    }

                    // Map image
                    graphics.DrawImage(miniMapImage,
                                       miniMapAlignXFromLeft, // map is on the center
                                       n.Height);

                    graphics.Flush();
                }

                // Dots pixel
                System.Drawing.Bitmap bmp_DotPixel = new System.Drawing.Bitmap(2, 4);
                using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bmp_DotPixel))
                {
                    graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Yellow), new System.Drawing.RectangleF(0, 0, bmp_DotPixel.Width, bmp_DotPixel.Height));
                    graphics.Flush();
                }
                IDXObject          dxObj_miniMapPixel = new DXObject(0, n.Height, bmp_DotPixel.ToTexture2D(device), 0);
                BaseDXDrawableItem item_pixelDot      = new BaseDXDrawableItem(dxObj_miniMapPixel, false)
                {
                    Position = new Point(
                        miniMapAlignXFromLeft, // map is on the center
                        0)
                };

                // Map
                Texture2D texturer_miniMap = miniMapUIImage.ToTexture2D(device);

                IDXObject   dxObj       = new DXObject(0, 0, texturer_miniMap, 0);
                MinimapItem minimapItem = new MinimapItem(dxObj, item_pixelDot);

                ////////////// Minimap buttons////////////////////
                // This must be in order.
                // >>> If aligning from the left to the right. Items at the left must be at the top of the code
                // >>> If aligning from the right to the left. Items at the right must be at the top of the code with its (x position - parent width).
                // TODO: probably a wrapper class in the future, such as HorizontalAlignment and VerticalAlignment, or Grid/ StackPanel
                WzBinaryProperty BtMouseClickSoundProperty = (WzBinaryProperty)SoundWZFile["UI.img"]?["BtMouseClick"];
                WzBinaryProperty BtMouseOverSoundProperty  = (WzBinaryProperty)SoundWZFile["UI.img"]?["BtMouseOver"];

                if (bBigBang)
                {
                    WzSubProperty BtNpc = (WzSubProperty)minimapFrameProperty["BtNpc"]; // npc button
                    WzSubProperty BtMin = (WzSubProperty)minimapFrameProperty["BtMin"]; // mininise button
                    WzSubProperty BtMax = (WzSubProperty)minimapFrameProperty["BtMax"]; // maximise button
                    WzSubProperty BtBig = (WzSubProperty)minimapFrameProperty["BtBig"]; // big button
                    WzSubProperty BtMap = (WzSubProperty)minimapFrameProperty["BtMap"]; // world button

                    UIObject objUIBtMap = new UIObject(BtMap, BtMouseClickSoundProperty, BtMouseOverSoundProperty,
                                                       false,
                                                       new Point(MAP_IMAGE_PADDING, MAP_IMAGE_PADDING), device);
                    objUIBtMap.X = effective_width - objUIBtMap.CanvasSnapshotWidth - 8; // render at the (width of minimap - obj width)

                    UIObject objUIBtBig = new UIObject(BtBig, BtMouseClickSoundProperty, BtMouseOverSoundProperty,
                                                       false,
                                                       new Point(MAP_IMAGE_PADDING, MAP_IMAGE_PADDING), device);
                    objUIBtBig.X = objUIBtMap.X - objUIBtBig.CanvasSnapshotWidth; // render at the (width of minimap - obj width)

                    UIObject objUIBtMax = new UIObject(BtMax, BtMouseClickSoundProperty, BtMouseOverSoundProperty,
                                                       false,
                                                       new Point(MAP_IMAGE_PADDING, MAP_IMAGE_PADDING), device);
                    objUIBtMax.X = objUIBtBig.X - objUIBtMax.CanvasSnapshotWidth; // render at the (width of minimap - obj width)

                    UIObject objUIBtMin = new UIObject(BtMin, BtMouseClickSoundProperty, BtMouseOverSoundProperty,
                                                       false,
                                                       new Point(MAP_IMAGE_PADDING, MAP_IMAGE_PADDING), device);
                    objUIBtMin.X = objUIBtMax.X - objUIBtMin.CanvasSnapshotWidth; // render at the (width of minimap - obj width)

                    // BaseClickableUIObject objUINpc = new BaseClickableUIObject(BtNpc, false, new Point(objUIBtMap.CanvasSnapshotWidth + objUIBtBig.CanvasSnapshotWidth + objUIBtMax.CanvasSnapshotWidth + objUIBtMin.CanvasSnapshotWidth, MAP_IMAGE_PADDING), device);

                    minimapItem.InitializeMinimapButtons(objUIBtMin, objUIBtMax, objUIBtBig, objUIBtMap);
                }
                else
                {
                    WzImage BasicImg = (WzImage)UIWZFile["Basic.img"];

                    WzSubProperty BtMin = (WzSubProperty)BasicImg["BtMin"];             // mininise button
                    WzSubProperty BtMax = (WzSubProperty)BasicImg["BtMax"];             // maximise button
                    WzSubProperty BtMap = (WzSubProperty)minimapFrameProperty["BtMap"]; // world button

                    UIObject objUIBtMap = new UIObject(BtMap, BtMouseClickSoundProperty, BtMouseOverSoundProperty,
                                                       false,
                                                       new Point(MAP_IMAGE_PADDING, MAP_IMAGE_PADDING), device);
                    objUIBtMap.X = effective_width - objUIBtMap.CanvasSnapshotWidth - 8; // render at the (width of minimap - obj width)

                    UIObject objUIBtMax = new UIObject(BtMax, BtMouseClickSoundProperty, BtMouseOverSoundProperty,
                                                       false,
                                                       new Point(MAP_IMAGE_PADDING, MAP_IMAGE_PADDING), device);
                    objUIBtMax.X = objUIBtMap.X - objUIBtMax.CanvasSnapshotWidth; // render at the (width of minimap - obj width)

                    UIObject objUIBtMin = new UIObject(BtMin, BtMouseClickSoundProperty, BtMouseOverSoundProperty,
                                                       false,
                                                       new Point(MAP_IMAGE_PADDING, MAP_IMAGE_PADDING), device);
                    objUIBtMin.X = objUIBtMax.X - objUIBtMin.CanvasSnapshotWidth; // render at the (width of minimap - obj width)

                    // BaseClickableUIObject objUINpc = new BaseClickableUIObject(BtNpc, false, new Point(objUIBtMap.CanvasSnapshotWidth + objUIBtBig.CanvasSnapshotWidth + objUIBtMax.CanvasSnapshotWidth + objUIBtMin.CanvasSnapshotWidth, MAP_IMAGE_PADDING), device);

                    minimapItem.InitializeMinimapButtons(objUIBtMin, objUIBtMax, null, objUIBtMap);
                }

                //////////////////////////////////////////////////

                return(minimapItem);
            }
        }
Exemplo n.º 30
0
 public void SerializeImage(WzImage img, string path)
 {
     total = 1; curr = 0;
     if (Path.GetExtension(path) != ".xml") path += ".xml";
     exportXmlInternal(img, path);
 }
Exemplo n.º 31
0
        private static bool GetMapVR(WzImage mapImage, ref System.Drawing.Rectangle?VR)
        {
            WzSubProperty fhParent = (WzSubProperty)mapImage["foothold"];

            if (fhParent == null)
            {
                VR = null; return(false);
            }
            int mostRight = int.MinValue, mostLeft = int.MaxValue, mostTop = int.MaxValue, mostBottom = int.MinValue;

            foreach (WzSubProperty fhLayer in fhParent.WzProperties)
            {
                foreach (WzSubProperty fhCat in fhLayer.WzProperties)
                {
                    foreach (WzSubProperty fh in fhCat.WzProperties)
                    {
                        int x1 = InfoTool.GetInt(fh["x1"]);
                        int x2 = InfoTool.GetInt(fh["x2"]);
                        int y1 = InfoTool.GetInt(fh["y1"]);
                        int y2 = InfoTool.GetInt(fh["y2"]);
                        if (x1 > mostRight)
                        {
                            mostRight = x1;
                        }
                        if (x1 < mostLeft)
                        {
                            mostLeft = x1;
                        }
                        if (x2 > mostRight)
                        {
                            mostRight = x2;
                        }
                        if (x2 < mostLeft)
                        {
                            mostLeft = x2;
                        }
                        if (y1 > mostBottom)
                        {
                            mostBottom = y1;
                        }
                        if (y1 < mostTop)
                        {
                            mostTop = y1;
                        }
                        if (y2 > mostBottom)
                        {
                            mostBottom = y2;
                        }
                        if (y2 < mostTop)
                        {
                            mostTop = y2;
                        }
                    }
                }
            }
            if (mostRight == int.MinValue || mostLeft == int.MaxValue || mostTop == int.MaxValue || mostBottom == int.MinValue)
            {
                VR = null; return(false);
            }
            int VRLeft   = mostLeft - 10;
            int VRRight  = mostRight + 10;
            int VRBottom = mostBottom + 110;
            int VRTop    = Math.Min(mostBottom - 600, mostTop - 360);

            VR = new System.Drawing.Rectangle(VRLeft, VRTop, VRRight - VRLeft, VRBottom - VRTop);
            return(true);
        }
Exemplo n.º 32
0
 public WzImage WzImageFromIMGBytes(byte[] bytes, WzMapleVersion version, string name, bool freeResources)
 {
     byte[] iv = WzTool.GetIvByMapleVersion(version);
     MemoryStream stream = new MemoryStream(bytes);
     WzBinaryReader wzReader = new WzBinaryReader(stream, iv);
     WzImage img = new WzImage(name, wzReader);
     img.BlockSize = bytes.Length;
     img.Checksum = 0;
     foreach (byte b in bytes) img.Checksum += b;
     img.Offset = 0;
     if (freeResources)
     {
         img.ParseImage(true);
         img.Changed = true;
         wzReader.Close();
     }
     return img;
 }
Exemplo n.º 33
0
 public void LoadLayers(WzImage mapImage, Board mapBoard)
 {
     for (int layer = 0; layer <= 7; layer++)
     {
         WzSubProperty   layerProp = (WzSubProperty)mapImage[layer.ToString()];
         WzImageProperty tSprop    = layerProp["info"]["tS"];
         string          tS        = null;
         if (tSprop != null)
         {
             tS = InfoTool.GetString(tSprop);
         }
         foreach (WzImageProperty obj in layerProp["obj"].WzProperties)
         {
             int                        x           = InfoTool.GetInt(obj["x"]);
             int                        y           = InfoTool.GetInt(obj["y"]);
             int                        z           = InfoTool.GetInt(obj["z"]);
             int                        zM          = InfoTool.GetInt(obj["zM"]);
             string                     oS          = InfoTool.GetString(obj["oS"]);
             string                     l0          = InfoTool.GetString(obj["l0"]);
             string                     l1          = InfoTool.GetString(obj["l1"]);
             string                     l2          = InfoTool.GetString(obj["l2"]);
             string                     name        = InfoTool.GetOptionalString(obj["name"]);
             MapleBool                  r           = InfoTool.GetOptionalBool(obj["r"]);
             MapleBool                  hide        = InfoTool.GetOptionalBool(obj["hide"]);
             MapleBool                  reactor     = InfoTool.GetOptionalBool(obj["reactor"]);
             MapleBool                  flow        = InfoTool.GetOptionalBool(obj["flow"]);
             int?                       rx          = InfoTool.GetOptionalTranslatedInt(obj["rx"]);
             int?                       ry          = InfoTool.GetOptionalTranslatedInt(obj["ry"]);
             int?                       cx          = InfoTool.GetOptionalTranslatedInt(obj["cx"]);
             int?                       cy          = InfoTool.GetOptionalTranslatedInt(obj["cy"]);
             string                     tags        = InfoTool.GetOptionalString(obj["tags"]);
             WzImageProperty            questParent = obj["quest"];
             List <ObjectInstanceQuest> questInfo   = null;
             if (questParent != null)
             {
                 questInfo = new List <ObjectInstanceQuest>();
                 foreach (WzIntProperty info in questParent.WzProperties)
                 {
                     questInfo.Add(new ObjectInstanceQuest(int.Parse(info.Name), (QuestState)info.Value));
                 }
             }
             bool       flip    = InfoTool.GetBool(obj["f"]);
             ObjectInfo objInfo = ObjectInfo.Get(oS, l0, l1, l2);
             Layer      l       = mapBoard.Layers[layer];
             mapBoard.BoardItems.TileObjs.Add((LayeredItem)objInfo.CreateInstance(l, mapBoard, x, y, z, zM, r, hide, reactor, flow, rx, ry, cx, cy, name, tags, questInfo, flip, false));
             l.zMList.Add(zM);
         }
         WzImageProperty tileParent = layerProp["tile"];
         foreach (WzImageProperty tile in tileParent.WzProperties)
         {
             int      x        = InfoTool.GetInt(tile["x"]);
             int      y        = InfoTool.GetInt(tile["y"]);
             int      zM       = InfoTool.GetInt(tile["zM"]);
             string   u        = InfoTool.GetString(tile["u"]);
             int      no       = InfoTool.GetInt(tile["no"]);
             Layer    l        = mapBoard.Layers[layer];
             TileInfo tileInfo = TileInfo.Get(tS, u, no.ToString());
             mapBoard.BoardItems.TileObjs.Add((LayeredItem)tileInfo.CreateInstance(l, mapBoard, x, y, int.Parse(tile.Name), zM, false, false));
             l.zMList.Add(zM);
         }
     }
 }
Exemplo n.º 34
0
 public byte[] SerializeImage(WzImage img)
 {
     total = 1; curr = 0;
     return serializeImageInternal(img);
 }
Exemplo n.º 35
0
        public List <string> VerifyMapPropsKnown(WzImage mapImage, bool userless)
        {
            List <string> copyPropNames = new List <string>();

            foreach (WzImageProperty prop in mapImage.WzProperties)
            {
                switch (prop.Name)
                {
                case "0":
                case "1":
                case "2":
                case "3":
                case "4":
                case "5":
                case "6":
                case "7":
                case "info":
                case "life":
                case "ladderRope":
                case "reactor":
                case "back":
                case "foothold":
                case "miniMap":
                case "portal":
                case "seat":
                case "ToolTip":
                case "clock":
                case "shipObj":
                case "area":
                case "healer":
                case "pulley":
                case "BuffZone":
                case "swimArea":
                    continue;

                case "coconut":     // The coconut event. Prop is copied but not edit-supported, we don't need to notify the user since it has no stateful objects. (e.g. 109080002)
                case "user":        // A map prop that dresses the user with predefined items according to his job. No stateful objects. (e.g. 930000010)
                case "noSkill":     // Preset in Monster Carnival maps, can only guess by its name that it blocks skills. Nothing stateful. (e.g. 980031100)
                case "snowMan":     // I don't even know what is this for; it seems to only have 1 prop with a path to the snowman, which points to a nonexistant image. (e.g. 889100001)
                case "weather":     // This has something to do with cash weather items, and exists in some nautlius maps (e.g. 108000500)
                case "mobMassacre": // This is the Mu Lung Dojo header property (e.g. 926021200)
                case "battleField": // The sheep vs wolf event and other useless maps (e.g. 109090300, 910040100)
                    copyPropNames.Add(prop.Name);
                    continue;

                case "snowBall":        // The snowball/snowman event. It has the snowman itself, which is a stateful object (somewhat of a mob), but we do not support it.
                case "monsterCarnival": // The Monster Carnival. It has an immense amount of info and stateful objects, including the mobs and guardians. We do not support it. (e.g. 980000201)
                    copyPropNames.Add(prop.Name);
                    if (!userless)
                    {
                        MessageBox.Show("The map you are opening has the feature \"" + prop.Name + "\", which is purposely not supported in the editor.\r\nTo get around this, HaCreator will copy the original feature's data byte-to-byte. This might cause the feature to stop working if it depends on map objects, such as footholds or mobs.");
                    }
                    continue;

                default:
                    string loggerSuffix = ", map " + mapImage.Name + ((mapImage.WzFileParent != null) ? (" of version " + Enum.GetName(typeof(WzMapleVersion), mapImage.WzFileParent.MapleVersion) + ", v" + mapImage.WzFileParent.Version.ToString()) : "");
                    string error        = "Unknown property " + prop.Name + loggerSuffix;
                    MapleLib.Helpers.ErrorLogger.Log(ErrorLevel.MissingFeature, error);
                    copyPropNames.Add(prop.Name);
                    break;
                }
            }
            return(copyPropNames);
        }
Exemplo n.º 36
0
 private byte[] serializeImageInternal(WzImage img)
 {
     MemoryStream stream = new MemoryStream();
     WzBinaryWriter wzWriter = new WzBinaryWriter(stream, ((WzDirectory)img.parent).WzIv);
     img.SaveImage(wzWriter);
     byte[] result = stream.ToArray();
     wzWriter.Close();
     return result;
 }
Exemplo n.º 37
0
        public void LoadFootholds(WzImage mapImage, Board mapBoard)
        {
            List <FootholdAnchor> anchors        = new List <FootholdAnchor>();
            WzSubProperty         footholdParent = (WzSubProperty)mapImage["foothold"];
            int            layer;
            FootholdAnchor a;
            FootholdAnchor b;
            Dictionary <int, FootholdLine> fhs = new Dictionary <int, FootholdLine>();

            foreach (WzSubProperty layerProp in footholdParent.WzProperties)
            {
                layer = int.Parse(layerProp.Name);
                Layer l = mapBoard.Layers[layer];
                foreach (WzSubProperty platProp in layerProp.WzProperties)
                {
                    int zM = int.Parse(platProp.Name);
                    l.zMList.Add(zM);
                    foreach (WzSubProperty fhProp in platProp.WzProperties)
                    {
                        a = new FootholdAnchor(mapBoard, InfoTool.GetInt(fhProp["x1"]), InfoTool.GetInt(fhProp["y1"]), layer, zM, false);
                        b = new FootholdAnchor(mapBoard, InfoTool.GetInt(fhProp["x2"]), InfoTool.GetInt(fhProp["y2"]), layer, zM, false);
                        int       num            = int.Parse(fhProp.Name);
                        int       next           = InfoTool.GetInt(fhProp["next"]);
                        int       prev           = InfoTool.GetInt(fhProp["prev"]);
                        MapleBool cantThrough    = InfoTool.GetOptionalBool(fhProp["cantThrough"]);
                        MapleBool forbidFallDown = InfoTool.GetOptionalBool(fhProp["forbidFallDown"]);
                        int?      piece          = InfoTool.GetOptionalInt(fhProp["piece"]);
                        int?      force          = InfoTool.GetOptionalInt(fhProp["force"]);
                        if (a.X != b.X || a.Y != b.Y)
                        {
                            FootholdLine fh = new FootholdLine(mapBoard, a, b, forbidFallDown, cantThrough, piece, force);
                            fh.num  = num;
                            fh.prev = prev;
                            fh.next = next;
                            mapBoard.BoardItems.FootholdLines.Add(fh);
                            fhs[num] = fh;
                            anchors.Add(a);
                            anchors.Add(b);
                        }
                    }
                }

                anchors.Sort(new Comparison <FootholdAnchor>(FootholdAnchor.FHAnchorSorter));
                for (int i = 0; i < anchors.Count - 1; i++)
                {
                    a = anchors[i];
                    b = anchors[i + 1];
                    if (a.X == b.X && a.Y == b.Y)
                    {
                        FootholdAnchor.MergeAnchors(a, b); // Transfer lines from b to a
                        anchors.RemoveAt(i + 1);           // Remove b
                        i--;                               // Fix index after we removed b
                    }
                }
                foreach (FootholdAnchor anchor in anchors)
                {
                    if (anchor.connectedLines.Count > 2)
                    {
                        foreach (FootholdLine line in anchor.connectedLines)
                        {
                            if (IsAnchorPrevOfFoothold(anchor, line))
                            {
                                if (fhs.ContainsKey(line.prev))
                                {
                                    line.prevOverride = fhs[line.prev];
                                }
                            }
                            else
                            {
                                if (fhs.ContainsKey(line.next))
                                {
                                    line.nextOverride = fhs[line.next];
                                }
                            }
                        }
                    }
                    mapBoard.BoardItems.FHAnchors.Add(anchor);
                }
                anchors.Clear();
            }
        }
Exemplo n.º 38
0
 internal void DumpImageToXML(TextWriter tw, string depth, WzImage img)
 {
     bool parsed = img.Parsed;
     if (!parsed) img.ParseImage();
     curr++;
     tw.Write(depth + "<wzimg name=\"" + XmlUtil.SanitizeText(img.Name) + "\">" + lineBreak);
     string newDepth = depth + indent;
     foreach (IWzImageProperty property in img.WzProperties)
         WritePropertyToXML(tw, newDepth, property);
     tw.Write(depth + "</wzimg>");
     if (!parsed) img.UnparseImage();
 }
Exemplo n.º 39
0
        public void LoadMisc(WzImage mapImage, Board mapBoard)
        {
            // All of the following properties are extremely esoteric features that only appear in a handful of maps.
            // They are implemented here for the sake of completeness, and being able to repack their maps without corruption.

            WzImageProperty clock    = mapImage["clock"];
            WzImageProperty ship     = mapImage["shipObj"];
            WzImageProperty area     = mapImage["area"];
            WzImageProperty healer   = mapImage["healer"];
            WzImageProperty pulley   = mapImage["pulley"];
            WzImageProperty BuffZone = mapImage["BuffZone"];
            WzImageProperty swimArea = mapImage["swimArea"];

            if (clock != null)
            {
                Clock clockInstance = new Clock(mapBoard, new Rectangle(InfoTool.GetInt(clock["x"]), InfoTool.GetInt(clock["y"]), InfoTool.GetInt(clock["width"]), InfoTool.GetInt(clock["height"])));
                mapBoard.BoardItems.Add(clockInstance, false);
            }
            if (ship != null)
            {
                string     objPath      = InfoTool.GetString(ship["shipObj"]);
                string[]   objPathParts = objPath.Split("/".ToCharArray());
                string     oS           = WzInfoTools.RemoveExtension(objPathParts[objPathParts.Length - 4]);
                string     l0           = objPathParts[objPathParts.Length - 3];
                string     l1           = objPathParts[objPathParts.Length - 2];
                string     l2           = objPathParts[objPathParts.Length - 1];
                ObjectInfo objInfo      = ObjectInfo.Get(oS, l0, l1, l2);
                ShipObject shipInstance = new ShipObject(objInfo, mapBoard,
                                                         InfoTool.GetInt(ship["x"]),
                                                         InfoTool.GetInt(ship["y"]),
                                                         InfoTool.GetOptionalInt(ship["z"]),
                                                         InfoTool.GetOptionalInt(ship["x0"]),
                                                         InfoTool.GetInt(ship["tMove"]),
                                                         InfoTool.GetInt(ship["shipKind"]),
                                                         InfoTool.GetBool(ship["f"]));
                mapBoard.BoardItems.Add(shipInstance, false);
            }
            if (area != null)
            {
                foreach (WzImageProperty prop in area.WzProperties)
                {
                    int  x1       = InfoTool.GetInt(prop["x1"]);
                    int  x2       = InfoTool.GetInt(prop["x2"]);
                    int  y1       = InfoTool.GetInt(prop["y1"]);
                    int  y2       = InfoTool.GetInt(prop["y2"]);
                    Area currArea = new Area(mapBoard, new Rectangle(Math.Min(x1, x2), Math.Min(y1, y2), Math.Abs(x2 - x1), Math.Abs(y2 - y1)), prop.Name);
                    mapBoard.BoardItems.Add(currArea, false);
                }
            }
            if (healer != null)
            {
                string     objPath        = InfoTool.GetString(healer["healer"]);
                string[]   objPathParts   = objPath.Split("/".ToCharArray());
                string     oS             = WzInfoTools.RemoveExtension(objPathParts[objPathParts.Length - 4]);
                string     l0             = objPathParts[objPathParts.Length - 3];
                string     l1             = objPathParts[objPathParts.Length - 2];
                string     l2             = objPathParts[objPathParts.Length - 1];
                ObjectInfo objInfo        = ObjectInfo.Get(oS, l0, l1, l2);
                Healer     healerInstance = new Healer(objInfo, mapBoard,
                                                       InfoTool.GetInt(healer["x"]),
                                                       InfoTool.GetInt(healer["yMin"]),
                                                       InfoTool.GetInt(healer["yMax"]),
                                                       InfoTool.GetInt(healer["healMin"]),
                                                       InfoTool.GetInt(healer["healMax"]),
                                                       InfoTool.GetInt(healer["fall"]),
                                                       InfoTool.GetInt(healer["rise"]));
                mapBoard.BoardItems.Add(healerInstance, false);
            }
            if (pulley != null)
            {
                string     objPath        = InfoTool.GetString(pulley["pulley"]);
                string[]   objPathParts   = objPath.Split("/".ToCharArray());
                string     oS             = WzInfoTools.RemoveExtension(objPathParts[objPathParts.Length - 4]);
                string     l0             = objPathParts[objPathParts.Length - 3];
                string     l1             = objPathParts[objPathParts.Length - 2];
                string     l2             = objPathParts[objPathParts.Length - 1];
                ObjectInfo objInfo        = ObjectInfo.Get(oS, l0, l1, l2);
                Pulley     pulleyInstance = new Pulley(objInfo, mapBoard,
                                                       InfoTool.GetInt(pulley["x"]),
                                                       InfoTool.GetInt(pulley["y"]));
                mapBoard.BoardItems.Add(pulleyInstance, false);
            }
            if (BuffZone != null)
            {
                foreach (WzImageProperty zone in BuffZone.WzProperties)
                {
                    int      x1       = InfoTool.GetInt(zone["x1"]);
                    int      x2       = InfoTool.GetInt(zone["x2"]);
                    int      y1       = InfoTool.GetInt(zone["y1"]);
                    int      y2       = InfoTool.GetInt(zone["y2"]);
                    int      id       = InfoTool.GetInt(zone["ItemID"]);
                    int      interval = InfoTool.GetInt(zone["Interval"]);
                    int      duration = InfoTool.GetInt(zone["Duration"]);
                    BuffZone currZone = new BuffZone(mapBoard, new Rectangle(Math.Min(x1, x2), Math.Min(y1, y2), Math.Abs(x2 - x1), Math.Abs(y2 - y1)), id, interval, duration, zone.Name);
                    mapBoard.BoardItems.Add(currZone, false);
                }
            }
            if (swimArea != null)
            {
                foreach (WzImageProperty prop in swimArea.WzProperties)
                {
                    int      x1       = InfoTool.GetInt(prop["x1"]);
                    int      x2       = InfoTool.GetInt(prop["x2"]);
                    int      y1       = InfoTool.GetInt(prop["y1"]);
                    int      y2       = InfoTool.GetInt(prop["y2"]);
                    SwimArea currArea = new SwimArea(mapBoard, new Rectangle(Math.Min(x1, x2), Math.Min(y1, y2), Math.Abs(x2 - x1), Math.Abs(y2 - y1)), prop.Name);
                    mapBoard.BoardItems.Add(currArea, false);
                }
            }
            // Some misc items are not implemented here; these are copied byte-to-byte from the original. See VerifyMapPropsKnown for details.
        }
Exemplo n.º 40
0
 internal WzImage ParseXMLWzImg(XmlElement imgElement)
 {
     string name = imgElement.GetAttribute("name");
     WzImage result = new WzImage(name);
     foreach (XmlElement subelement in imgElement)
         result.WzProperties.Add(ParsePropertyFromXMLElement(subelement));
     result.Changed = true;
     if (this.useMemorySaving)
     {
         string path = Path.GetTempFileName();
         WzBinaryWriter wzWriter = new WzBinaryWriter(File.Create(path), iv);
         result.SaveImage(wzWriter);
         wzWriter.Close();
         result.Dispose();
         result = imgDeserializer.WzImageFromIMGFile(path, iv, name);
     }
     return result;
 }
Exemplo n.º 41
0
        private void loadButton_Click(object sender, EventArgs e)
        {
            //Hide();
            WaitWindow ww = new WaitWindow("Loading...");

            ww.Show();
            Application.DoEvents();

            MapLoader     loader = new MapLoader();
            WzImage       mapImage = null;
            string        mapName = null, streetName = "", categoryName = "";
            WzSubProperty strMapProp = null;

            if (HAMSelect.Checked)
            {
                loader.CreateMapFromHam(multiBoard, Tabs, File.ReadAllText(HAMBox.Text), rightClickHandler);
                DialogResult = DialogResult.OK;
                ww.EndWait();
                Close();
                return;
            }
            else if (XMLSelect.Checked)
            {
                try
                {
                    mapImage = (WzImage) new WzXmlDeserializer(false, null).ParseXML(XMLBox.Text)[0];
                }
                catch
                {
                    Warning.Error("Error while loading XML. Aborted.");
                    ww.EndWait();
                    Show();
                    return;
                }
            }
            else if (WZSelect.Checked)
            {
                if (mapBrowser.SelectedItem == "MapLogin")
                {
                    mapImage = (WzImage)Program.WzManager["ui"]["MapLogin.img"];
                    mapName  = streetName = categoryName = "MapLogin";
                }
                else if (mapBrowser.SelectedItem == "MapLogin1")
                {
                    mapImage = (WzImage)Program.WzManager["ui"]["MapLogin1.img"];
                    mapName  = streetName = categoryName = "MapLogin1";
                }
                else if (mapBrowser.SelectedItem == "CashShopPreview")
                {
                    mapImage = (WzImage)Program.WzManager["ui"]["CashShopPreview.img"];
                    mapName  = streetName = categoryName = "CashShopPreview";
                }
                else
                {
                    string mapid  = mapBrowser.SelectedItem.Substring(0, 9);
                    string mapcat = "Map" + mapid.Substring(0, 1);
                    if (Program.WzManager.wzFiles.ContainsKey("map002"))//i hate nexon so much
                    {
                        mapImage = (WzImage)Program.WzManager["map002"]["Map"][mapcat][mapid + ".img"];
                    }
                    else
                    {
                        mapImage = (WzImage)Program.WzManager["map"]["Map"][mapcat][mapid + ".img"];
                    }
                    strMapProp   = WzInfoTools.GetMapStringProp(mapid);
                    mapName      = WzInfoTools.GetMapName(strMapProp);
                    streetName   = WzInfoTools.GetMapStreetName(strMapProp);
                    categoryName = WzInfoTools.GetMapCategoryName(strMapProp);
                }
            }
            loader.CreateMapFromImage(mapImage, mapName, streetName, categoryName, strMapProp, Tabs, multiBoard, rightClickHandler);
            DialogResult = DialogResult.OK;
            ww.EndWait();
            Close();
        }