Ejemplo n.º 1
0
        private static ObjectInfo Load(WzSubProperty parentObject, string oS, string l0, string l1, string l2)
        {
            WzCanvasProperty frame1 = (WzCanvasProperty)WzInfoTools.GetRealProperty(parentObject["0"]);
            ObjectInfo       result = new ObjectInfo(
                frame1.GetLinkedWzCanvasBitmap(),
                WzInfoTools.PointFToSystemPoint(frame1.GetCanvasOriginPosition()),
                oS,
                l0,
                l1,
                l2,
                parentObject);
            WzImageProperty chairs    = parentObject["seat"];
            WzImageProperty ropes     = frame1["rope"];
            WzImageProperty ladders   = frame1["ladder"];
            WzImageProperty footholds = frame1["foothold"];

            result.footholdOffsets = ParsePropToOffsetMap(footholds);
            result.ropeOffsets     = ParsePropToOffsetMap(ropes);
            result.ladderOffsets   = ParsePropToOffsetMap(ladders);
            if (chairs != null)
            {
                result.chairOffsets = ParsePropToOffsetList(chairs);
            }
            return(result);
        }
        /// <summary>
        /// Load background from WzImageProperty
        /// </summary>
        /// <param name="parentObject"></param>
        /// <param name="spineParentObject"></param>
        /// <param name="bS"></param>
        /// <param name="type"></param>
        /// <param name="no"></param>
        /// <returns></returns>
        private static BackgroundInfo Load(WzImageProperty parentObject, string bS, BackgroundInfoType type, string no)
        {
            WzCanvasProperty frame0;

            if (type == BackgroundInfoType.Animation)
            {
                frame0 = (WzCanvasProperty)WzInfoTools.GetRealProperty(parentObject["0"]);
            }
            else if (type == BackgroundInfoType.Spine)
            {
                // TODO: make a preview of the spine image ffs
                WzCanvasProperty spineCanvas = (WzCanvasProperty)parentObject["0"];
                if (spineCanvas != null)
                {
                    Bitmap bitmap   = spineCanvas.GetLinkedWzCanvasBitmap();
                    PointF origin__ = spineCanvas.GetCanvasOriginPosition();

                    return(new BackgroundInfo(parentObject, bitmap, WzInfoTools.PointFToSystemPoint(origin__), bS, type, no, parentObject));
                }
                else
                {
                    PointF origin_ = new PointF();
                    return(new BackgroundInfo(parentObject, Properties.Resources.placeholder, WzInfoTools.PointFToSystemPoint(origin_), bS, type, no, parentObject));
                }
            }
            else
            {
                frame0 = (WzCanvasProperty)WzInfoTools.GetRealProperty(parentObject);
            }

            PointF origin = frame0.GetCanvasOriginPosition();

            return(new BackgroundInfo(frame0, frame0.GetLinkedWzCanvasBitmap(), WzInfoTools.PointFToSystemPoint(origin), bS, type, no, parentObject));
        }
Ejemplo n.º 3
0
        private static BackgroundInfo Load(WzImageProperty parentObject, string bS, bool ani, string no)
        {
            WzCanvasProperty frame0 = ani ? (WzCanvasProperty)WzInfoTools.GetRealProperty(parentObject["0"]) : (WzCanvasProperty)WzInfoTools.GetRealProperty(parentObject);

            PointF origin = frame0.GetCanvasOriginPosition();

            return(new BackgroundInfo(frame0.GetLinkedWzCanvasBitmap(), WzInfoTools.PointFToSystemPoint(origin), bS, ani, no, parentObject));
        }
Ejemplo n.º 4
0
        public static PortalInfo Load(WzCanvasProperty parentObject)
        {
            PortalInfo portal = new PortalInfo(
                parentObject.Name,
                parentObject.GetLinkedWzCanvasBitmap(),
                WzInfoTools.PointFToSystemPoint(parentObject.GetCanvasOriginPosition()), parentObject);

            Program.InfoManager.Portals.Add(portal.type, portal);
            return(portal);
        }
        /// <summary>
        /// Load background from WzImageProperty
        /// </summary>
        /// <param name="graphicsDevice">The graphics device that the backgroundInfo is to be rendered on (loading spine)</param>
        /// <param name="parentObject"></param>
        /// <param name="spineParentObject"></param>
        /// <param name="bS"></param>
        /// <param name="type"></param>
        /// <param name="no"></param>
        /// <returns></returns>
        private static BackgroundInfo Load(GraphicsDevice graphicsDevice, WzImageProperty parentObject, string bS, BackgroundInfoType type, string no)
        {
            WzCanvasProperty frame0;

            if (type == BackgroundInfoType.Animation)
            {
                frame0 = (WzCanvasProperty)WzInfoTools.GetRealProperty(parentObject["0"]);
            }
            else if (type == BackgroundInfoType.Spine)
            {
                // TODO: make a preview of the spine image ffs
                WzCanvasProperty spineCanvas = (WzCanvasProperty)parentObject["0"];
                if (spineCanvas != null)
                {
                    // Load spine
                    WzSpineAnimationItem wzSpineAnimationItem = null;
                    if (graphicsDevice != null) // graphicsdevice needed to work.. assuming that it is loaded by now before BackgroundPanel
                    {
                        WzImageProperty spineAtlasProp = ((WzSubProperty)parentObject).WzProperties.FirstOrDefault(
                            wzprop => wzprop is WzStringProperty property && property.IsSpineAtlasResources);
                        if (spineAtlasProp != null)
                        {
                            WzStringProperty stringObj = (WzStringProperty)spineAtlasProp;
                            wzSpineAnimationItem = new WzSpineAnimationItem(stringObj);

                            wzSpineAnimationItem.LoadResources(graphicsDevice);
                        }
                    }

                    // Preview Image
                    Bitmap bitmap = spineCanvas.GetLinkedWzCanvasBitmap();

                    // Origin
                    PointF origin__ = spineCanvas.GetCanvasOriginPosition();

                    return(new BackgroundInfo(parentObject, bitmap, WzInfoTools.PointFToSystemPoint(origin__), bS, type, no, parentObject, wzSpineAnimationItem));
                }
                else
                {
                    PointF origin_ = new PointF();
                    return(new BackgroundInfo(parentObject, Properties.Resources.placeholder, WzInfoTools.PointFToSystemPoint(origin_), bS, type, no, parentObject, null));
                }
            }
            else
            {
                frame0 = (WzCanvasProperty)WzInfoTools.GetRealProperty(parentObject);
            }

            PointF origin = frame0.GetCanvasOriginPosition();

            return(new BackgroundInfo(frame0, frame0.GetLinkedWzCanvasBitmap(), WzInfoTools.PointFToSystemPoint(origin), bS, type, no, parentObject, null));
        }
Ejemplo n.º 6
0
        private void ExtractPNGFromImage(WzImage image)
        {
            WzCanvasProperty reactorImage = WzInfoTools.GetReactorImage(image);

            if (reactorImage != null)
            {
                Image  = reactorImage.GetLinkedWzCanvasBitmap();
                Origin = WzInfoTools.PointFToSystemPoint(reactorImage.GetCanvasOriginPosition());
            }
            else
            {
                Image  = new Bitmap(1, 1);
                Origin = new System.Drawing.Point();
            }
        }
Ejemplo n.º 7
0
        private void ExtractPNGFromImage(WzImage image)
        {
            WzCanvasProperty npcImage = WzInfoTools.GetNpcImage(image);

            if (npcImage != null)
            {
                Image = npcImage.GetLinkedWzCanvasBitmap();
                if (Image.Width == 1 && Image.Height == 1)
                {
                    Image = global::HaCreator.Properties.Resources.placeholder;
                }
                Origin = WzInfoTools.PointFToSystemPoint(npcImage.GetCanvasOriginPosition());
            }
            else
            {
                Image  = new Bitmap(1, 1);
                Origin = new System.Drawing.Point();
            }
        }
Ejemplo n.º 8
0
        private static TileInfo Load(WzCanvasProperty parentObject, string tS, string u, string no, int?mag)
        {
            WzImageProperty zProp  = parentObject["z"];
            int             z      = zProp == null ? 0 : InfoTool.GetInt(zProp);
            TileInfo        result = new TileInfo(
                parentObject.GetLinkedWzCanvasBitmap(),
                WzInfoTools.PointFToSystemPoint(parentObject.GetCanvasOriginPosition()),
                tS, u, no, mag.HasValue ? mag.Value : 1, z, parentObject);
            WzConvexProperty footholds = (WzConvexProperty)parentObject["foothold"];

            if (footholds != null)
            {
                foreach (WzVectorProperty foothold in footholds.WzProperties)
                {
                    result.footholdOffsets.Add(WzInfoTools.VectorToXNAPoint(foothold));
                }
            }
            if (UserSettings.FixFootholdMispositions)
            {
                FixFootholdMispositions(result);
            }
            return(result);
        }
        /// <summary>
        /// Load frames from WzSubProperty or WzCanvasProperty
        /// </summary>
        /// <param name="texturePool"></param>
        /// <param name="source"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="device"></param>
        /// <param name="usedProps"></param>
        /// <param name="spineAni">Spine animation path</param>
        /// <returns></returns>
        private static List <IDXObject> LoadFrames(TexturePool texturePool, WzImageProperty source, int x, int y, GraphicsDevice device, ref List <WzObject> usedProps, string spineAni = null)
        {
            List <IDXObject> frames = new List <IDXObject>();

            source = WzInfoTools.GetRealProperty(source);

            if (source is WzSubProperty property1 && property1.WzProperties.Count == 1)
            {
                source = property1.WzProperties[0];
            }

            if (source is WzCanvasProperty property) //one-frame
            {
                bool bLoadedSpine = LoadSpineMapObjectItem(source, source, device, spineAni);
                if (!bLoadedSpine)
                {
                    string    canvasBitmapPath = property.FullPath;
                    Texture2D textureFromCache = texturePool.GetTexture(canvasBitmapPath);
                    if (textureFromCache != null)
                    {
                        source.MSTag = textureFromCache;
                    }
                    else
                    {
                        source.MSTag = property.GetLinkedWzCanvasBitmap().ToTexture2D(device);

                        // add to cache
                        texturePool.AddTextureToPool(canvasBitmapPath, (Texture2D)source.MSTag);
                    }
                }
                usedProps.Add(source);

                if (source.MSTagSpine != null)
                {
                    WzSpineObject         spineObject = (WzSpineObject)source.MSTagSpine;
                    System.Drawing.PointF origin      = property.GetCanvasOriginPosition();

                    frames.Add(new DXSpineObject(spineObject, x, y, origin));
                }
                else if (source.MSTag != null)
                {
                    Texture2D             texture = (Texture2D)source.MSTag;
                    System.Drawing.PointF origin  = property.GetCanvasOriginPosition();

                    frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture));
                }
                else // fallback
                {
                    Texture2D             texture = Properties.Resources.placeholder.ToTexture2D(device);
                    System.Drawing.PointF origin  = property.GetCanvasOriginPosition();

                    frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture));
                }
            }
            else if (source is WzSubProperty) // animated
            {
                WzImageProperty _frameProp;
                int             i = 0;

                while ((_frameProp = WzInfoTools.GetRealProperty(source[(i++).ToString()])) != null)
                {
                    if (_frameProp is WzSubProperty) // issue with 867119250
                    {
                        frames.AddRange(LoadFrames(texturePool, _frameProp, x, y, device, ref usedProps, null));
                    }
                    else
                    {
                        WzCanvasProperty frameProp = (WzCanvasProperty)_frameProp;

                        int delay = (int)InfoTool.GetOptionalInt(frameProp["delay"], 100);

                        bool bLoadedSpine = LoadSpineMapObjectItem((WzImageProperty)frameProp.Parent, frameProp, device, spineAni);
                        if (!bLoadedSpine)
                        {
                            if (frameProp.MSTag == null)
                            {
                                string    canvasBitmapPath = frameProp.FullPath;
                                Texture2D textureFromCache = texturePool.GetTexture(canvasBitmapPath);
                                if (textureFromCache != null)
                                {
                                    frameProp.MSTag = textureFromCache;
                                }
                                else
                                {
                                    frameProp.MSTag = frameProp.GetLinkedWzCanvasBitmap().ToTexture2D(device);

                                    // add to cache
                                    texturePool.AddTextureToPool(canvasBitmapPath, (Texture2D)frameProp.MSTag);
                                }
                            }
                        }
                        usedProps.Add(frameProp);

                        if (frameProp.MSTagSpine != null)
                        {
                            WzSpineObject         spineObject = (WzSpineObject)frameProp.MSTagSpine;
                            System.Drawing.PointF origin      = frameProp.GetCanvasOriginPosition();

                            frames.Add(new DXSpineObject(spineObject, x, y, origin, delay));
                        }
                        else if (frameProp.MSTag != null)
                        {
                            Texture2D             texture = (Texture2D)frameProp.MSTag;
                            System.Drawing.PointF origin  = frameProp.GetCanvasOriginPosition();

                            frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture, delay));
                        }
                        else
                        {
                            Texture2D             texture = Properties.Resources.placeholder.ToTexture2D(device);
                            System.Drawing.PointF origin  = frameProp.GetCanvasOriginPosition();

                            frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture, delay));
                        }
                    }
                }
            }
            return(frames);
        }
        public static void ExtractAnimation(WzSubProperty parent, string savePath, bool apngFirstFrame)
        {
            List <Bitmap> bmpList                    = new List <Bitmap>(parent.WzProperties.Count);
            List <int>    delayList                  = new List <int>(parent.WzProperties.Count);
            Point         biggestPng                 = new Point(0, 0);
            Point         SmallestEmptySpace         = new Point(65535, 65535);
            Point         MaximumPngMappingEndingPts = new Point(0, 0);

            foreach (WzImageProperty subprop in parent.WzProperties)
            {
                if (subprop is WzCanvasProperty)
                {
                    //System.Drawing.PointF origin = ((WzCanvasProperty)subprop).GetCanvasOriginPosition();
                    WzPngProperty png = ((WzCanvasProperty)subprop).PngProperty;
                    if (png.Height > biggestPng.Y)
                    {
                        biggestPng.Y = png.Height;
                    }
                    if (png.Width > biggestPng.X)
                    {
                        biggestPng.X = png.Width;
                    }
                }
            }
            List <WzCanvasProperty> sortedProps = new List <WzCanvasProperty>();

            foreach (WzImageProperty subprop in parent.WzProperties)
            {
                if (subprop is WzCanvasProperty property)
                {
                    sortedProps.Add(property);
                    WzPngProperty         png    = property.PngProperty;
                    System.Drawing.PointF origin = property.GetCanvasOriginPosition();

                    Point StartPoints          = new Point(biggestPng.X - (int)origin.X, biggestPng.Y - (int)origin.Y);
                    Point PngMapppingEndingPts = new Point(StartPoints.X + png.Width, StartPoints.Y + png.Height);
                    if (StartPoints.X < SmallestEmptySpace.X)
                    {
                        SmallestEmptySpace.X = StartPoints.X;
                    }
                    if (StartPoints.Y < SmallestEmptySpace.Y)
                    {
                        SmallestEmptySpace.Y = StartPoints.Y;
                    }
                    if (PngMapppingEndingPts.X > MaximumPngMappingEndingPts.X)
                    {
                        MaximumPngMappingEndingPts.X = PngMapppingEndingPts.X;
                    }
                    if (PngMapppingEndingPts.Y > MaximumPngMappingEndingPts.Y)
                    {
                        MaximumPngMappingEndingPts.Y = PngMapppingEndingPts.Y;
                    }
                }
            }
            sortedProps.Sort(new Comparison <WzCanvasProperty>(PropertySorter));
            for (int i = 0; i < sortedProps.Count; i++)
            {
                WzCanvasProperty subprop = sortedProps[i];
                if (i.ToString() != subprop.Name)
                {
                    Warning.Error(string.Format(Properties.Resources.AnimError, i.ToString()));
                    return;
                }
                Bitmap bmp = subprop.PngProperty.GetImage(false);
                System.Drawing.PointF origin = subprop.GetCanvasOriginPosition();
                bmpList.Add(OptimizeBitmapTransparent(bmp, new WzVectorProperty("", origin.X, origin.Y), biggestPng, SmallestEmptySpace, MaximumPngMappingEndingPts));

                int?delay = subprop[WzCanvasProperty.AnimationDelayPropertyName]?.GetInt();
                if (delay == null)
                {
                    delay = 100;
                }

                delayList.Add((int)delay);
            }
            SharpApng apngBuilder = new SharpApng();

            if (apngFirstFrame)
            {
                apngBuilder.AddFrame(new SharpApngFrame(CreateIncompatibilityFrame(new Size(bmpList[0].Width, bmpList[0].Height)), 1, 1));
            }
            for (int i = 0; i < bmpList.Count; i++)
            {
                apngBuilder.AddFrame(new SharpApngFrame(bmpList[i], GetNumByDelay(delayList[i]), GetDenByDelay(delayList[i])));
            }
            apngBuilder.WriteApng(savePath, apngFirstFrame, true);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Attempts to render the map and save the progress
        /// </summary>
        /// <param name="img"></param>
        /// <param name="zoom"></param>
        /// <param name="errorList"></param>
        public bool TryRenderMapAndSave(WzImage img, double zoom, ref List <string> errorList)
        {
            string mapIdName = img.Name.Substring(0, img.Name.Length - 4);

            node = MainPanel.DataTree.SelectedNode;
            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;

            WzSubProperty miniMapSubProperty = ((WzSubProperty)img["miniMap"]);

            try
            {
                bmpSize = new Size(((WzIntProperty)miniMapSubProperty["width"]).Value, ((WzIntProperty)miniMapSubProperty["height"]).Value);
                center  = new Point(((WzIntProperty)miniMapSubProperty["centerX"]).Value, ((WzIntProperty)miniMapSubProperty["centerY"]).Value);
            }
            catch (Exception exp)
            {
                if (exp is KeyNotFoundException || exp is NullReferenceException)
                {
                    try
                    {
                        WzSubProperty infoSubProperty = ((WzSubProperty)img["info"]);

                        bmpSize = new Size(((WzIntProperty)infoSubProperty["VRRight"]).Value - ((WzIntProperty)infoSubProperty["VRLeft"]).Value, ((WzIntProperty)infoSubProperty["VRBottom"]).Value - ((WzIntProperty)infoSubProperty["VRTop"]).Value);
                        center  = new Point(((WzIntProperty)infoSubProperty["VRRight"]).Value, ((WzIntProperty)infoSubProperty["VRBottom"]).Value);
                    }
                    catch
                    {
                        errorList.Add("Missing map info WzSubProperty. Path: " + mapIdName + ".img/info/VRRight; VRLeft; VRBottom; VRTop\r\n OR info/miniMap/width ; height; centerX; centerY");
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }

            // Render minimap
            Bitmap minimapRender = RenderMinimap(bmpSize, wzFile, img, mapIdName, miniMapSubProperty);

            // Render map
            Bitmap mapRender = new Bitmap(bmpSize.Width, bmpSize.Height);

            using (Graphics drawBuf = Graphics.FromImage(mapRender))
            {
                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    pt = ((WzIntProperty)p["pt"]).Value;
                    string pn = ((WzStringProperty)p["pn"]).ReadString(string.Empty);
                    int    tm = ((WzIntProperty)p["tm"]).ReadValue(999999999);

                    Color pColor = Color.Red;
                    if (pt == 0)
                    {
                        pColor = Color.Orange;
                    }
                    else if (pt == 2 || pt == 7)//Normal
                    {
                        pColor = Color.Blue;
                    }
                    else if (pt == 3)//Auto-enter
                    {
                        pColor = Color.Magenta;
                    }
                    else if (pt == 1 || pt == 8)
                    {
                        pColor = Color.BlueViolet;
                    }
                    else
                    {
                        pColor = Color.IndianRed;
                    }

                    // Draw portal preview image
                    bool drewPortalImg = false;
                    if (pn != string.Empty || pt == 2)
                    {
                        string           portalEditorImage  = wzFile.WzDirectory.Name + "/MapHelper.img/portal/editor/" + (pt == 2 ? "pv" : pn);
                        WzCanvasProperty portalEditorCanvas = (WzCanvasProperty)wzFile.GetObjectFromPath(portalEditorImage);
                        if (portalEditorCanvas != null)
                        {
                            drewPortalImg = true;

                            PointF canvasOriginPosition = portalEditorCanvas.GetCanvasOriginPosition();
                            drawBuf.DrawImage(portalEditorCanvas.GetLinkedWzCanvasBitmap(), x - canvasOriginPosition.X, y - canvasOriginPosition.Y);
                        }
                    }
                    if (!drewPortalImg)
                    {
                        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);
                    }

                    // Draw portal name
                    drawBuf.DrawString("Portal: " + p.Name, FONT_DISPLAY_PORTAL_LFIE_FOOTHOLD, 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);
                }

                WzSubProperty SPs = (WzSubProperty)img["life"];
                foreach (WzSubProperty sp in SPs.WzProperties)
                {
                    Color MSPColor = Color.ForestGreen;

                    string type = ((WzStringProperty)sp["type"]).Value;
                    switch (type)
                    {
                    case "n":     // NPC
                    case "m":     // monster
                    {
                        bool isNPC  = type == "n";
                        int  lifeId = int.Parse(((WzStringProperty)sp["id"]).GetString());

                        int  x          = ((WzIntProperty)sp["x"]).Value + center.X;
                        int  y          = ((WzIntProperty)sp["y"]).Value + center.Y;
                        int  x_text     = x - 15;
                        int  y_text     = y - 15;
                        bool facingLeft = ((WzIntProperty)sp["f"]).ReadValue(0) == 0;         // This value is optional. If its not stated in the WZ, its assumed to be 0

                        SpawnPoint.Spawnpoint MSP = new SpawnPoint.Spawnpoint();
                        MSP.Shape = new Rectangle(x_text, y_text, 30, 30);
                        MSP.Data  = sp;
                        MSPs.Add(MSP);


                        // Render monster image
                        string lifeStrId = lifeId.ToString().PadLeft(7, '0');

                        string mobWzPath;
                        string mobLinkWzPath;
                        string mobNamePath;

                        if (!isNPC)
                        {
                            mobWzPath   = string.Format("Mob.wz/{0}.img/info/link", lifeStrId);
                            mobNamePath = string.Format("String.wz/Mob.img/{0}/name", lifeId);
                        }
                        else
                        {
                            mobWzPath   = string.Format("Npc.wz/{0}.img/info/link", lifeStrId);
                            mobNamePath = string.Format("String.wz/Npc.img/{0}/name", lifeId);
                        }

                        WzStringProperty linkInfo = (WzStringProperty)WzFile.GetObjectFromMultipleWzFilePath(mobWzPath, Program.WzMan.WzFileListReadOnly);
                        if (linkInfo != null)
                        {
                            lifeId    = int.Parse(linkInfo.GetString());
                            lifeStrId = lifeId.ToString().PadLeft(7, '0');
                        }

                        if (!isNPC)
                        {
                            mobLinkWzPath = string.Format("Mob.wz/{0}.img/stand/0", lifeStrId);
                        }
                        else
                        {
                            mobLinkWzPath = string.Format("Npc.wz/{0}.img/stand/0", lifeStrId);
                        }

                        WzCanvasProperty lifeImg = (WzCanvasProperty)WzFile.GetObjectFromMultipleWzFilePath(mobLinkWzPath, Program.WzMan.WzFileListReadOnly);
                        if (lifeImg != null)
                        {
                            PointF canvasOriginPosition = lifeImg.GetCanvasOriginPosition();
                            PointF renderXY             = new PointF(x - canvasOriginPosition.X, y - canvasOriginPosition.Y);

                            Bitmap renderMobbitmap = lifeImg.GetLinkedWzCanvasBitmap();

                            if (!facingLeft)
                            {
                                renderMobbitmap.RotateFlip(RotateFlipType.RotateNoneFlipX);
                            }

                            drawBuf.DrawImage(renderMobbitmap, renderXY);
                        }
                        else
                        {
                            //drawBuf.FillRectangle(new SolidBrush(Color.FromArgb(95, MSPColor.R, MSPColor.G, MSPColor.B)), x_text, y_text, 30, 30);
                            //drawBuf.DrawRectangle(new Pen(Color.Black, 1F), x_text, y_text, 30, 30);
                            errorList.Add("Missing monster/npc object. Path: " + mobWzPath + "\r\n" + mobLinkWzPath);
                        }

                        // Get monster name
                        WzStringProperty stringName = (WzStringProperty)WzFile.GetObjectFromMultipleWzFilePath(mobNamePath, Program.WzMan.WzFileListReadOnly);
                        if (stringName != null)
                        {
                            drawBuf.DrawString(string.Format("SP: {0}, Name: {1}, ID: {2}", sp.Name, stringName.GetString(), lifeId), FONT_DISPLAY_PORTAL_LFIE_FOOTHOLD, new SolidBrush(Color.Red), x_text + 7, y_text + 7.3F);
                        }
                        else
                        {
                            errorList.Add("Missing monster/npc string object. Path: " + mobNamePath);
                        }
                        break;
                    }

                    default:
                    {
                        break;
                    }
                    }
                }


                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, FONT_DISPLAY_PORTAL_LFIE_FOOTHOLD, new SolidBrush(Color.Red), new PointF(x + (width / 2) - 8, y + (height / 2) - 7.7F));
                        }
                    }
                }
            }
            mapRender.Save("Renders\\" + mapIdName + "\\" + mapIdName + "_footholdRender.bmp");

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

            using (Graphics tileBuf = Graphics.FromImage(backgroundRender))
            {
                WzSubProperty backImg = (WzSubProperty)img["back"];
                if (backImg != null)
                {
                    foreach (WzSubProperty bgItem in backImg.WzProperties)
                    {
                        string bS         = ((WzStringProperty)bgItem["bS"]).Value;
                        int    front      = ((WzIntProperty)bgItem["front"]).Value;
                        int    ani        = ((WzIntProperty)bgItem["ani"]).Value;
                        int    no         = ((WzIntProperty)bgItem["no"]).Value;
                        int    x          = ((WzIntProperty)bgItem["x"]).Value;
                        int    y          = ((WzIntProperty)bgItem["y"]).Value;
                        int    rx         = ((WzIntProperty)bgItem["rx"]).Value;
                        int    ry         = ((WzIntProperty)bgItem["ry"]).Value;
                        int    type       = ((WzIntProperty)bgItem["type"]).Value;
                        int    cx         = ((WzIntProperty)bgItem["cx"]).Value;
                        int    cy         = ((WzIntProperty)bgItem["cy"]).Value;
                        int    a          = ((WzIntProperty)bgItem["a"]).Value;
                        bool   facingLeft = ((WzIntProperty)bgItem["f"]).ReadValue(0) == 0;

                        if (bS == string.Empty)
                        {
                            continue;
                        }

                        string           bgObjImagePath = "Map.wz/Back/" + bS + ".img/Back/" + no;
                        WzCanvasProperty wzBgCanvas     = (WzCanvasProperty)WzFile.GetObjectFromMultipleWzFilePath(bgObjImagePath, Program.WzMan.WzFileListReadOnly);
                        if (wzBgCanvas != null)
                        {
                            PointF canvasOriginPosition = wzBgCanvas.GetCanvasOriginPosition();
                            PointF renderXY             = new PointF(x + canvasOriginPosition.X + center.X, y + canvasOriginPosition.X + center.Y);

                            Bitmap drawImage = wzBgCanvas.GetLinkedWzCanvasBitmap();

                            if (!facingLeft)
                            {
                                drawImage.RotateFlip(RotateFlipType.RotateNoneFlipX);
                            }

                            tileBuf.DrawImage(drawImage, renderXY);
                        }
                        else
                        {
                            errorList.Add("Missing Map BG object. Path: " + bgObjImagePath);
                        }
                    }
                }
            }
            backgroundRender.Save("Renders\\" + mapIdName + "\\" + mapIdName + "_backgroundRender.bmp");


            // Render tooltip
            WzSubProperty tooltipProperty = (WzSubProperty)img["ToolTip"];
            Bitmap        toolTip         = null;

            if (tooltipProperty != null)
            {
                toolTip = new Bitmap(bmpSize.Width, bmpSize.Height);
                using (Graphics toolTipBuf = Graphics.FromImage(toolTip))
                {
                    string        stringTooltipPath = "String.wz/ToolTipHelp.img/Mapobject/" + mapIdName;
                    WzSubProperty wzToolTip         = (WzSubProperty)WzFile.GetObjectFromMultipleWzFilePath(stringTooltipPath, Program.WzMan.WzFileListReadOnly);

                    if (wzToolTip == null)
                    {
                        errorList.Add("Map tooltip object is missing. Path: " + stringTooltipPath);
                    }

                    for (int i = 0; i < 99; i++) // starts from 0
                    {
                        WzSubProperty toolTipItem = (WzSubProperty)tooltipProperty[i.ToString()];
                        if (toolTipItem == null)
                        {
                            break;
                        }

                        int x1 = toolTipItem["x1"].ReadValue();
                        int x2 = toolTipItem["x2"].ReadValue();
                        int y1 = toolTipItem["y1"].ReadValue();
                        int y2 = toolTipItem["y2"].ReadValue();

                        // Check String.wz
                        WzSubProperty wzToolTipForI = (WzSubProperty)wzToolTip[i.ToString()];
                        if (wzToolTipForI == null)
                        {
                            errorList.Add("Map tooltip is missing. Path: " + stringTooltipPath + "/" + i);
                        }
                        string title = wzToolTipForI["Title"].ReadString(null);
                        string desc  = wzToolTipForI["Desc"].ReadString(null);

                        if (title == null)
                        {
                            errorList.Add("Map tooltip is missing. Path: " + stringTooltipPath + "/" + i + "/Title");
                        }
                        toolTipBuf.DrawString(string.Format("{0}\n{1}", title, desc == null ? string.Empty : desc), FONT_GAME_TOOLTIP, new SolidBrush(Color.Black), new PointF(x1 + center.X, y1 + center.Y));
                    }
                }
                toolTip.Save("Renders\\" + mapIdName + "\\" + mapIdName + "_tooltip.bmp");
            }

            // Render Tiles
            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
                    WzSubProperty iProperty      = (WzSubProperty)img[i.ToString()];
                    WzSubProperty objProperties  = ((WzSubProperty)iProperty["obj"]);
                    WzSubProperty infoProperties = ((WzSubProperty)iProperty["info"]);
                    WzSubProperty tileProperties = ((WzSubProperty)iProperty["tile"]);

                    if (objProperties.WzProperties.Count > 0)
                    {
                        foreach (WzSubProperty obj in objProperties.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;

                            PointF           origin;
                            WzCanvasProperty png;

                            string imgObjPath = string.Format("{0}/Obj/{1}/{2}/{3}/{4}/0", wzFile.WzDirectory.Name, imgName, l0, l1, l2);

                            WzImageProperty objData = (WzImageProperty)WzFile.GetObjectFromMultipleWzFilePath(imgObjPath, Program.WzMan.WzFileListReadOnly);
tryagain:
                            if (objData is WzCanvasProperty)
                            {
                                png    = ((WzCanvasProperty)objData);
                                origin = ((WzCanvasProperty)objData).GetCanvasOriginPosition();
                            }
                            else if (objData is WzUOLProperty)
                            {
                                WzObject currProp = objData.Parent;
                                foreach (string directive in ((WzUOLProperty)objData).Value.Split("/".ToCharArray()))
                                {
                                    if (directive == "..")
                                    {
                                        currProp = currProp.Parent;
                                    }
                                    else
                                    {
                                        if (currProp.GetType() == typeof(WzSubProperty))
                                        {
                                            currProp = ((WzSubProperty)currProp)[directive];
                                        }
                                        else if (currProp.GetType() == typeof(WzCanvasProperty))
                                        {
                                            currProp = ((WzCanvasProperty)currProp)[directive];
                                        }
                                        else if (currProp.GetType() == typeof(WzImage))
                                        {
                                            currProp = ((WzImage)currProp)[directive];
                                        }
                                        else if (currProp.GetType() == typeof(WzConvexProperty))
                                        {
                                            currProp = ((WzConvexProperty)currProp)[directive];
                                        }
                                        else
                                        {
                                            errorList.Add("UOL error at map renderer");
                                            return(false);
                                        }
                                    }
                                }
                                objData = (WzImageProperty)currProp;
                                goto tryagain;
                            }
                            else
                            {
                                errorList.Add("Unknown Wz type at map renderer");
                                return(false);
                            }

                            //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.GetLinkedWzCanvasBitmap(), x - origin.X, y - origin.Y);
                        }
                    }
                    if (infoProperties.WzProperties.Count == 0)
                    {
                        continue;
                    }

                    if (tileProperties.WzProperties.Count == 0)
                    {
                        continue;
                    }

                    // Ok, we have some tiles and a tileset
                    string tileSetName = ((WzStringProperty)infoProperties["tS"]).Value;

                    // Browse to the tileset
                    string  tilePath = wzFile.WzDirectory.Name + "/Tile/" + tileSetName + ".img";
                    WzImage tileSet  = (WzImage)WzFile.GetObjectFromMultipleWzFilePath(tilePath, Program.WzMan.WzFileListReadOnly);
                    if (!tileSet.Parsed)
                    {
                        tileSet.ParseImage();
                    }

                    foreach (WzSubProperty tile in tileProperties.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();

                        WzSubProperty    tilePack   = ((WzSubProperty)tileSet[tilePackName]);
                        WzCanvasProperty tileCanvas = (WzCanvasProperty)tilePack[tileID];
                        if (tileCanvas == null)
                        {
                            errorList.Add(string.Format("Tile {0}, ID: {1} is not found.", tilePackName, tileID));
                        }
                        PointF tileVector = tileCanvas.GetCanvasOriginPosition();
                        tileBuf.DrawImage(tileCanvas.GetLinkedWzCanvasBitmap(), x - tileVector.X, y - tileVector.Y);
                    }
                }
            }
            tileRender.Save("Renders\\" + mapIdName + "\\" + mapIdName + "_tileRender.bmp");

            // Render nodeInfo
            Bitmap        nodeInfoRender   = null;
            WzSubProperty nodeInfoProperty = (WzSubProperty)img["nodeInfo"];

            if (nodeInfoProperty != null)
            {
                nodeInfoRender = new Bitmap(bmpSize.Width, bmpSize.Height);
                using (Graphics nodeInfoBuffer = Graphics.FromImage(nodeInfoRender))
                {
                    int start = 0;
                    int end   = 0;

                    foreach (WzImageProperty nodeInfoImg in nodeInfoProperty.WzProperties)
                    {
                        switch (nodeInfoImg.Name)
                        {
                        case "edgeInfo":
                        {
                            break;
                        }

                        case "end":
                        {
                            end = ((WzIntProperty)nodeInfoImg).ReadValue();
                            break;
                        }

                        case "start":
                        {
                            start = ((WzIntProperty)nodeInfoImg).ReadValue();
                            break;
                        }

                        default:
                        {
                            int nodeInfoImgFileName = -1;
                            if (int.TryParse(nodeInfoImg.Name, out nodeInfoImgFileName))
                            {
                                int attr = ((WzIntProperty)nodeInfoImg["attr"]).ReadValue();
                                int key  = ((WzIntProperty)nodeInfoImg["key"]).ReadValue();
                                int x    = ((WzIntProperty)nodeInfoImg["x"]).ReadValue() + center.X;
                                int y    = ((WzIntProperty)nodeInfoImg["y"]).ReadValue() + center.Y;

                                List <int> edges = new List <int>();
                                foreach (WzImageProperty edge in nodeInfoImg["edge"].WzProperties)
                                {
                                    edges.Add(edge.ReadValue());
                                }

                                const int width  = 200;
                                const int height = 20;

                                nodeInfoBuffer.FillRectangle(new SolidBrush(Color.Wheat), x, y, width, height);
                                nodeInfoBuffer.DrawRectangle(new Pen(Color.Black, 1F), x, y, width, height);
                                nodeInfoBuffer.DrawString(
                                    string.Format("Key: {0}, x: {1}, y: {1}", key, x, y),
                                    FONT_DISPLAY_PORTAL_LFIE_FOOTHOLD, new SolidBrush(Color.Black), new PointF(x + (width / 2) - 8, y + (height / 2) - 7.7F));
                            }
                            break;
                        }
                        }
                    }
                }
                nodeInfoRender.Save("Renders\\" + mapIdName + "\\" + mapIdName + "_nodeInfoRender.bmp");
            }


            // Render everything combined
            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(backgroundRender, 0, 0);
                fullBuf.DrawImage(tileRender, 0, 0);
                fullBuf.DrawImage(mapRender, 0, 0);
                if (toolTip != null)
                {
                    fullBuf.DrawImage(toolTip, 0, 0);
                }
                if (nodeInfoRender != null)
                {
                    fullBuf.DrawImage(nodeInfoRender, 0, 0);
                }
                fullBuf.DrawImage(minimapRender, 0, 0);
            }
            //pbx_Foothold_Render.Image = fullBmp;
            fullBmp.Save("Renders\\" + mapIdName + "\\" + mapIdName + "_fullRender.bmp");

            // Cleanup resources
            backgroundRender.Dispose();
            tileRender.Dispose();
            mapRender.Dispose();
            toolTip?.Dispose();
            minimapRender.Dispose();

            if (errorList.Count() > 0)
            {
                return(false);
            }

            // Display render map
            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();
                return(true);
            }
            catch (FormatException)
            {
                MessageBox.Show("You must set the render scale to a valid number.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
        }