Beispiel #1
0
        /// <summary>
        /// Gets a wz property by a path name
        /// </summary>
        /// <param name="pPath">path to property</param>
        /// <returns>the wz property with the specified name</returns>
        public virtual AWzImageProperty GetFromPath(string pPath)
        {
            string[] segments = pPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            if (segments[0] == "..")
            {
                return(((AWzImageProperty)Parent)[pPath.Substring(Name.IndexOf('/') + 1)]);
            }
            AWzImageProperty ret = this;

            if (ret.WzProperties == null)
            {
                return(null);
            }
            foreach (string t in segments)
            {
                bool foundChild = false;
                if (ret is WzPngProperty && t == "PNG")
                {
                    return(ret.ToPngProperty());
                }
                string t1 = t;
                foreach (AWzImageProperty iwp in ret.WzProperties.Where(iwp => iwp.Name == t1))
                {
                    ret        = iwp;
                    foundChild = true;
                    break;
                }
                if (!foundChild)
                {
                    return(null);
                }
            }
            return(ret);
        }
Beispiel #2
0
        public static AWzObject[] GetObjectsFromProperty(AWzImageProperty prop)
        {
            List <AWzObject> objList = new List <AWzObject>();

            switch (prop.PropertyType)
            {
            case WzPropertyType.Canvas:
                objList.AddRange(prop.WzProperties);
                objList.Add(((WzCanvasProperty)prop).PngProperty);
                break;

            case WzPropertyType.Convex:
                objList.AddRange(prop.WzProperties);
                break;

            case WzPropertyType.SubProperty:
                objList.AddRange(prop.WzProperties);
                break;

            case WzPropertyType.Vector:
                objList.Add(((WzVectorProperty)prop).X);
                objList.Add(((WzVectorProperty)prop).Y);
                break;
            }
            return(objList.ToArray());
        }
Beispiel #3
0
        internal static void WriteExtendedProperty(WzBinaryWriter pWriter, AWzImageProperty pProp)
        {
            pWriter.Write((byte)9);
            long beforePos = pWriter.BaseStream.Position;

            pWriter.Write(0); // Placeholder
            pProp.WriteValue(pWriter);
            int  len    = (int)(pWriter.BaseStream.Position - beforePos);
            long newPos = pWriter.BaseStream.Position;

            pWriter.BaseStream.Position = beforePos;
            pWriter.Write(len - 4);
            pWriter.BaseStream.Position = newPos;
        }
Beispiel #4
0
        internal string[] GetPathsFromProperty(AWzImageProperty prop, string curPath)
        {
            List <string> objList = new List <string>();

            switch (prop.PropertyType)
            {
            case WzPropertyType.Canvas:
                foreach (AWzImageProperty canvasProp in prop.WzProperties)
                {
                    objList.Add(curPath + "/" + canvasProp.Name);
                    objList.AddRange(GetPathsFromProperty(canvasProp, curPath + "/" + canvasProp.Name));
                }
                objList.Add(curPath + "/PNG");
                break;

            case WzPropertyType.Convex:
                foreach (AWzImageProperty conProp in prop.WzProperties)
                {
                    objList.Add(curPath + "/" + conProp.Name);
                    objList.AddRange(GetPathsFromProperty(conProp, curPath + "/" + conProp.Name));
                }
                break;

            case WzPropertyType.SubProperty:
                foreach (AWzImageProperty subProp in prop.WzProperties)
                {
                    objList.Add(curPath + "/" + subProp.Name);
                    objList.AddRange(GetPathsFromProperty(subProp, curPath + "/" + subProp.Name));
                }
                break;

            case WzPropertyType.Vector:
                objList.Add(curPath + "/X");
                objList.Add(curPath + "/Y");
                break;
            }
            return(objList.ToArray());
        }
Beispiel #5
0
 public virtual void AddProperty(AWzImageProperty pProp)
 {
     pProp.Parent      = this;
     pProp.ParentImage = ParentImage;
     WzProperties.Add(pProp);
 }
Beispiel #6
0
 public virtual void RemoveProperty(AWzImageProperty pProp)
 {
     WzProperties.Remove(pProp);
 }
Beispiel #7
0
        internal static AWzImageProperty ExtractMore(WzBinaryReader pReader, uint pOffset, int pEndOfBlock, string pName, string pImageName, AWzObject pParent, WzImage pImgParent)
        {
            switch (pImageName)
            {
            case "Property":
                WzSubProperty subProp = new WzSubProperty(pName)
                {
                    Parent = pParent, ParentImage = pImgParent
                };
                pReader.BaseStream.Position += 2;
                subProp.AddProperties(ParsePropertyList(pOffset, pReader, subProp, pImgParent));
                return(subProp);

            case "Canvas":
                WzCanvasProperty canvasProp = new WzCanvasProperty(pName)
                {
                    Parent = pParent, ParentImage = pImgParent
                };
                pReader.BaseStream.Position++;
                if (pReader.ReadByte() == 1)
                {
                    pReader.BaseStream.Position += 2;
                    canvasProp.AddProperties(ParsePropertyList(pOffset, pReader, canvasProp, pImgParent));
                }
                canvasProp.PngProperty = new WzPngProperty(pReader)
                {
                    Parent = canvasProp, ParentImage = pImgParent
                };
                return(canvasProp);

            case "Shape2D#Vector2D":
                WzVectorProperty vecProp = new WzVectorProperty(pName)
                {
                    Parent = pParent, ParentImage = pImgParent
                };
                vecProp.X = new WzCompressedIntProperty("X", pReader.ReadCompressedInt())
                {
                    Parent = vecProp, ParentImage = pImgParent
                };
                vecProp.Y = new WzCompressedIntProperty("Y", pReader.ReadCompressedInt())
                {
                    Parent = vecProp, ParentImage = pImgParent
                };
                return(vecProp);

            case "Shape2D#Convex2D":
                WzConvexProperty convexProp = new WzConvexProperty(pName)
                {
                    Parent = pParent, ParentImage = pImgParent
                };
                int convexEntryCount = pReader.ReadCompressedInt();
                for (int i = 0; i < convexEntryCount; i++)
                {
                    AWzImageProperty imgProp = ParseExtendedProp(pReader, pOffset, 0, pName, convexProp, pImgParent);
                    if (imgProp != null)
                    {
                        convexProp.AddProperty(imgProp);
                    }
                }
                return(convexProp);

            case "Sound_DX8":
                WzSoundProperty soundProp = new WzSoundProperty(pName)
                {
                    Parent = pParent, ParentImage = pImgParent
                };
                soundProp.ParseSound(pReader);
                return(soundProp);

            case "UOL":
                pReader.BaseStream.Position++;
                byte b = pReader.ReadByte();
                switch (b)
                {
                case 0:
                    return(new WzUOLProperty(pName, pReader.ReadString())
                    {
                        Parent = pParent, ParentImage = pImgParent
                    });

                case 1:
                    return(new WzUOLProperty(pName, pReader.ReadStringAtOffset(pOffset + pReader.ReadInt32()))
                    {
                        Parent = pParent, ParentImage = pImgParent
                    });

                default:
                    throw new Exception("Unsupported UOL type: " + b);
                }

            default:
                throw new Exception("Unknown image name: " + pImageName);
            }
        }
Beispiel #8
0
        internal static List <AWzImageProperty> ParsePropertyList(uint pOffset, WzBinaryReader pReader, AWzObject pParent, WzImage pParentImg)
        {
            List <AWzImageProperty> properties = new List <AWzImageProperty>();
            int entryCount = pReader.ReadCompressedInt();

            for (int i = 0; i < entryCount; i++)
            {
                string name = pReader.ReadStringBlock(pOffset).Trim();
                byte   b    = pReader.ReadByte();
                switch (b)
                {
                case 0:
                    properties.Add(new WzNullProperty(name)
                    {
                        Parent = pParent, ParentImage = pParentImg
                    });
                    break;

                case 2:
                case 11:     //UShort
                    properties.Add(new WzShortProperty(name, pReader.ReadInt16())
                    {
                        Parent = pParent, ParentImage = pParentImg
                    });
                    break;

                case 3:
                case 19:     //UInt
                    properties.Add(new WzCompressedIntProperty(name, pReader.ReadCompressedInt())
                    {
                        Parent = pParent, ParentImage = pParentImg
                    });
                    break;

                case 4:
                    byte type = pReader.ReadByte();
                    if (type == 0x80)
                    {
                        properties.Add(new WzByteFloatProperty(name, pReader.ReadSingle())
                        {
                            Parent = pParent, ParentImage = pParentImg
                        });
                    }
                    else if (type == 0)
                    {
                        properties.Add(new WzByteFloatProperty(name, 0f)
                        {
                            Parent = pParent, ParentImage = pParentImg
                        });
                    }
                    break;

                case 5:
                    properties.Add(new WzDoubleProperty(name, pReader.ReadDouble())
                    {
                        Parent = pParent, ParentImage = pParentImg
                    });
                    break;

                case 8:
                    properties.Add(new WzStringProperty(name, pReader.ReadStringBlock(pOffset))
                    {
                        Parent = pParent, ParentImage = pParentImg
                    });
                    break;

                case 9:
                    int eob = (int)(pReader.ReadUInt32() + pReader.BaseStream.Position);
                    AWzImageProperty exProp = ParseExtendedProp(pReader, pOffset, eob, name, pParent, pParentImg);
                    if (exProp != null)
                    {
                        properties.Add(exProp);
                    }
                    pReader.BaseStream.Position = eob;
                    break;

                case 20:
                    properties.Add(new WzCompressedLongProperty(name, pReader.ReadCompressedLong())
                    {
                        Parent = pParent, ParentImage = pParentImg
                    });
                    break;

                default:
                    throw new Exception("Unknown property type at ParsePropertyList: " + b + " name: " + name + " offset: " + pReader.getCurrentOffset());
                }
            }
            return(properties);
        }