Ejemplo n.º 1
0
 /// <summary>
 /// Get WZ object from multiple loaded WZ files in memory
 /// </summary>
 /// <param name="path"></param>
 /// <param name="wzFiles"></param>
 /// <returns></returns>
 public static WzObject GetObjectFromMultipleWzFilePath(string path, IReadOnlyCollection <WzFile> wzFiles)
 {
     foreach (WzFile file in wzFiles)
     {
         WzObject obj = file.GetObjectFromPath(path, false);
         if (obj != null)
         {
             return(obj);
         }
     }
     return(null);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the top most WZObject directory (i.e Map.wz, Skill.wz)
        /// </summary>
        /// <returns></returns>
        public WzObject GetTopMostWzDirectory()
        {
            WzObject parent = this.Parent;

            if (parent == null)
            {
                return(this); // this
            }
            while (parent.Parent != null)
            {
                parent = parent.Parent;
            }
            return(parent);
        }
Ejemplo n.º 3
0
        public WzObject GetObjectFromPath(string path)
        {
            string[] seperatedPath = path.Split("/".ToCharArray());
            if (seperatedPath[0].ToLower() != wzDir.name.ToLower() && seperatedPath[0].ToLower() != wzDir.name.Substring(0, wzDir.name.Length - 3).ToLower())
            {
                return(null);
            }
            if (seperatedPath.Length == 1)
            {
                return(WzDirectory);
            }
            WzObject curObj = WzDirectory;

            for (int i = 1; i < seperatedPath.Length; i++)
            {
                if (curObj == null)
                {
                    return(null);
                }
                switch (curObj.ObjectType)
                {
                case WzObjectType.Directory:
                    curObj = ((WzDirectory)curObj)[seperatedPath[i]];
                    continue;

                case WzObjectType.Image:
                    curObj = ((WzImage)curObj)[seperatedPath[i]];
                    continue;

                case WzObjectType.Property:
                    switch (((WzImageProperty)curObj).PropertyType)
                    {
                    case WzPropertyType.Canvas:
                        curObj = ((WzCanvasProperty)curObj)[seperatedPath[i]];
                        continue;

                    case WzPropertyType.Convex:
                        curObj = ((WzConvexProperty)curObj)[seperatedPath[i]];
                        continue;

                    case WzPropertyType.SubProperty:
                        curObj = ((WzSubProperty)curObj)[seperatedPath[i]];
                        continue;

                    case WzPropertyType.Vector:
                        if (seperatedPath[i] == "X")
                        {
                            return(((WzVectorProperty)curObj).X);
                        }
                        else if (seperatedPath[i] == "Y")
                        {
                            return(((WzVectorProperty)curObj).Y);
                        }
                        else
                        {
                            return(null);
                        }

                    default:                                     // Wut?
                        return(null);
                    }
                }
            }
            if (curObj == null)
            {
                return(null);
            }
            return(curObj);
        }
Ejemplo n.º 4
0
        internal static WzExtended ExtractMore(WzBinaryReader reader, uint offset, int eob, string name, string iname, WzObject parent, WzImage imgParent)
        {
            if (iname == "")
            {
                iname = reader.ReadString();
            }
            switch (iname)
            {
            case "Property":
                WzSubProperty subProp = new WzSubProperty(name)
                {
                    Parent = parent
                };
                reader.BaseStream.Position += 2;     // Reserved?
                subProp.AddProperties(WzImageProperty.ParsePropertyList(offset, reader, subProp, imgParent));
                return(subProp);

            case "Canvas":
                WzCanvasProperty canvasProp = new WzCanvasProperty(name)
                {
                    Parent = parent
                };
                reader.BaseStream.Position++;
                if (reader.ReadByte() == 1)
                {
                    reader.BaseStream.Position += 2;
                    canvasProp.AddProperties(WzImageProperty.ParsePropertyList(offset, reader, canvasProp, imgParent));
                }
                canvasProp.PngProperty = new WzPngProperty(reader, imgParent.parseEverything)
                {
                    Parent = canvasProp
                };
                return(canvasProp);

            case "Shape2D#Vector2D":
                WzVectorProperty vecProp = new WzVectorProperty(name)
                {
                    Parent = parent
                };
                vecProp.X = new WzIntProperty("X", reader.ReadCompressedInt())
                {
                    Parent = vecProp
                };
                vecProp.Y = new WzIntProperty("Y", reader.ReadCompressedInt())
                {
                    Parent = vecProp
                };
                return(vecProp);

            case "Shape2D#Convex2D":
                WzConvexProperty convexProp = new WzConvexProperty(name)
                {
                    Parent = parent
                };
                int convexEntryCount = reader.ReadCompressedInt();
                convexProp.WzProperties.Capacity = convexEntryCount;
                for (int i = 0; i < convexEntryCount; i++)
                {
                    convexProp.AddProperty(ParseExtendedProp(reader, offset, 0, name, convexProp, imgParent));
                }
                return(convexProp);

            case "Sound_DX8":
                WzSoundProperty soundProp = new WzSoundProperty(name, reader, imgParent.parseEverything)
                {
                    Parent = parent
                };
                return(soundProp);

            case "UOL":
                reader.BaseStream.Position++;
                switch (reader.ReadByte())
                {
                case 0:
                    return(new WzUOLProperty(name, reader.ReadString())
                    {
                        Parent = parent
                    });

                case 1:
                    return(new WzUOLProperty(name, reader.ReadStringAtOffset(offset + reader.ReadInt32()))
                    {
                        Parent = parent
                    });
                }
                throw new Exception("Unsupported UOL type");

            default:
                throw new Exception("Unknown iname: " + iname);
            }
        }
Ejemplo n.º 5
0
        internal static WzExtended ParseExtendedProp(WzBinaryReader reader, uint offset, int endOfBlock, string name, WzObject parent, WzImage imgParent)
        {
            switch (reader.ReadByte())
            {
            case 0x01:
            case 0x1B:
                return(ExtractMore(reader, offset, endOfBlock, name, reader.ReadStringAtOffset(offset + reader.ReadInt32()), parent, imgParent));

            case 0x00:
            case 0x73:
                return(ExtractMore(reader, offset, endOfBlock, name, "", parent, imgParent));

            default:
                throw new System.Exception("Invlid byte read at ParseExtendedProp");
            }
        }
Ejemplo n.º 6
0
        internal static List <WzImageProperty> ParsePropertyList(uint offset, WzBinaryReader reader, WzObject parent, WzImage parentImg)
        {
            int entryCount = reader.ReadCompressedInt();
            List <WzImageProperty> properties = new List <WzImageProperty>(entryCount);

            for (int i = 0; i < entryCount; i++)
            {
                string name  = reader.ReadStringBlock(offset);
                byte   ptype = reader.ReadByte();
                switch (ptype)
                {
                case 0:
                    properties.Add(new WzNullProperty(name)
                    {
                        Parent = parent
                    });
                    break;

                case 11:
                case 2:
                    properties.Add(new WzShortProperty(name, reader.ReadInt16())
                    {
                        Parent = parent
                    });
                    break;

                case 3:
                case 19:
                    properties.Add(new WzIntProperty(name, reader.ReadCompressedInt())
                    {
                        Parent = parent
                    });
                    break;

                case 20:
                    properties.Add(new WzLongProperty(name, reader.ReadLong())
                    {
                        Parent = parent
                    });
                    break;

                case 4:
                    byte type = reader.ReadByte();
                    if (type == 0x80)
                    {
                        properties.Add(new WzFloatProperty(name, reader.ReadSingle())
                        {
                            Parent = parent
                        });
                    }
                    else if (type == 0)
                    {
                        properties.Add(new WzFloatProperty(name, 0f)
                        {
                            Parent = parent
                        });
                    }
                    break;

                case 5:
                    properties.Add(new WzDoubleProperty(name, reader.ReadDouble())
                    {
                        Parent = parent
                    });
                    break;

                case 8:
                    properties.Add(new WzStringProperty(name, reader.ReadStringBlock(offset))
                    {
                        Parent = parent
                    });
                    break;

                case 9:
                    int             eob    = (int)(reader.ReadUInt32() + reader.BaseStream.Position);
                    WzImageProperty exProp = ParseExtendedProp(reader, offset, eob, name, parent, parentImg);
                    properties.Add(exProp);
                    if (reader.BaseStream.Position != eob)
                    {
                        reader.BaseStream.Position = eob;
                    }
                    break;

                default:
                    throw new Exception("Unknown property type at ParsePropertyList");
                }
            }
            return(properties);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Parses .lua property
        /// </summary>
        /// <param name="offset"></param>
        /// <param name="reader"></param>
        /// <param name="parent"></param>
        /// <param name="parentImg"></param>
        /// <returns></returns>
        internal static WzLuaProperty ParseLuaProperty(uint offset, WzBinaryReader reader, WzObject parent, WzImage parentImg)
        {
            // 28 71 4F EF 1B 65 F9 1F A7 48 8D 11 73 E7 F0 27 55 09 DD 3C 07 32 D7 38 21 57 84 70 C1 79 9A 3F 49 F7 79 03 41 F4 9D B9 1B 5F CF 26 80 3D EC 25 5F 9C
            // [compressed int] [bytes]
            int length = reader.ReadCompressedInt();

            byte[] rawEncBytes = reader.ReadBytes(length);

            WzLuaProperty lua = new WzLuaProperty("Script", rawEncBytes)
            {
                Parent = parent
            };

            return(lua);
        }