private void CreateWzProp(IPropertyContainer parent, WzPropertyType propType, string propName, object value) { WzImageProperty addedProp; switch (propType) { case WzPropertyType.Float: addedProp = new WzFloatProperty(propName); break; case WzPropertyType.Canvas: addedProp = new WzCanvasProperty(propName); ((WzCanvasProperty)addedProp).PngProperty = new WzPngProperty(); break; case WzPropertyType.Int: addedProp = new WzIntProperty(propName); break; case WzPropertyType.Double: addedProp = new WzDoubleProperty(propName); break; /*case WzPropertyType.Sound: * addedProp = new WzSoundProperty(propName); * break;*/ case WzPropertyType.String: addedProp = new WzStringProperty(propName); break; case WzPropertyType.Short: addedProp = new WzShortProperty(propName); break; case WzPropertyType.Vector: addedProp = new WzVectorProperty(propName); ((WzVectorProperty)addedProp).X = new WzIntProperty("X"); ((WzVectorProperty)addedProp).Y = new WzIntProperty("Y"); break; case WzPropertyType.Lua: // probably dont allow the user to create custom Lua for now.. { addedProp = new WzLuaProperty(propName, new byte[] { }); break; } default: throw new NotSupportedException("Not supported type"); } addedProp.SetValue(value); parent.AddProperty(addedProp); }
/// <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); }
/// <summary> /// Parses the image from the wz filetod /// </summary> /// <param name="wzReader">The BinaryReader that is currently reading the wz file</param> /// <returns>bool Parse status</returns> public bool ParseImage(bool forceReadFromData = false) { if (!forceReadFromData) // only check if parsed or changed if its not false read { if (Parsed) { return(true); } else if (Changed) { Parsed = true; return(true); } } lock (reader) // for multi threaded XMLWZ export. { long originalPos = reader.BaseStream.Position; reader.BaseStream.Position = offset; byte b = reader.ReadByte(); switch (b) { case 0x1: // .lua { if (IsLuaWzImage) { WzLuaProperty lua = WzImageProperty.ParseLuaProperty(offset, reader, this, this); List <WzImageProperty> luaImage = new List <WzImageProperty>(); luaImage.Add(lua); properties.AddRange(luaImage); parsed = true; // test return(true); } return(false); // unhandled for now, if it isnt an .lua image } case WzImageHeaderByte: { string prop = reader.ReadString(); ushort val = reader.ReadUInt16(); if (prop != "Property" || val != 0) { return(false); } break; } default: { // todo: log this or warn. Helpers.ErrorLogger.Log(Helpers.ErrorLevel.MissingFeature, "[WzImage] New Wz image header found. b = " + b); return(false); } } List <WzImageProperty> images = WzImageProperty.ParsePropertyList(offset, reader, this, this); properties.AddRange(images); parsed = true; } return(true); }
/// <summary> /// /// </summary> /// <param name="tw"></param> /// <param name="depth"></param> /// <param name="prop"></param> /// <param name="exportFilePath"></param> protected void WritePropertyToXML(TextWriter tw, string depth, WzImageProperty prop, string exportFilePath) { if (prop is WzCanvasProperty) { WzCanvasProperty property3 = (WzCanvasProperty)prop; if (ExportBase64Data) { MemoryStream stream = new MemoryStream(); property3.PngProperty.GetPNG(false).Save(stream, System.Drawing.Imaging.ImageFormat.Png); byte[] pngbytes = stream.ToArray(); stream.Close(); tw.Write(string.Concat(new object[] { depth, "<canvas name=\"", XmlUtil.SanitizeText(property3.Name), "\" width=\"", property3.PngProperty.Width, "\" height=\"", property3.PngProperty.Height, "\" basedata=\"", Convert.ToBase64String(pngbytes), "\">" }) + lineBreak); } else { tw.Write(string.Concat(new object[] { depth, "<canvas name=\"", XmlUtil.SanitizeText(property3.Name), "\" width=\"", property3.PngProperty.Width, "\" height=\"", property3.PngProperty.Height, "\">" }) + lineBreak); } string newDepth = depth + indent; foreach (WzImageProperty property in property3.WzProperties) { WritePropertyToXML(tw, newDepth, property, exportFilePath); } tw.Write(depth + "</canvas>" + lineBreak); } else if (prop is WzIntProperty) { WzIntProperty property4 = (WzIntProperty)prop; tw.Write(string.Concat(new object[] { depth, "<int name=\"", XmlUtil.SanitizeText(property4.Name), "\" value=\"", property4.Value, "\"/>" }) + lineBreak); } else if (prop is WzDoubleProperty) { WzDoubleProperty property5 = (WzDoubleProperty)prop; tw.Write(string.Concat(new object[] { depth, "<double name=\"", XmlUtil.SanitizeText(property5.Name), "\" value=\"", property5.Value, "\"/>" }) + lineBreak); } else if (prop is WzNullProperty) { WzNullProperty property6 = (WzNullProperty)prop; tw.Write(depth + "<null name=\"" + XmlUtil.SanitizeText(property6.Name) + "\"/>" + lineBreak); } else if (prop is WzBinaryProperty) { WzBinaryProperty property7 = (WzBinaryProperty)prop; if (ExportBase64Data) { tw.Write(string.Concat(new object[] { depth, "<sound name=\"", XmlUtil.SanitizeText(property7.Name), "\" length=\"", property7.Length.ToString(), "\" basehead=\"", Convert.ToBase64String(property7.Header), "\" basedata=\"", Convert.ToBase64String(property7.GetBytes(false)), "\"/>" }) + lineBreak); } else { tw.Write(depth + "<sound name=\"" + XmlUtil.SanitizeText(property7.Name) + "\"/>" + lineBreak); } } else if (prop is WzStringProperty) { WzStringProperty property8 = (WzStringProperty)prop; string str = XmlUtil.SanitizeText(property8.Value); tw.Write(depth + "<string name=\"" + XmlUtil.SanitizeText(property8.Name) + "\" value=\"" + str + "\"/>" + lineBreak); } else if (prop is WzSubProperty) { WzSubProperty property9 = (WzSubProperty)prop; tw.Write(depth + "<imgdir name=\"" + XmlUtil.SanitizeText(property9.Name) + "\">" + lineBreak); string newDepth = depth + indent; foreach (WzImageProperty property in property9.WzProperties) { WritePropertyToXML(tw, newDepth, property, exportFilePath); } tw.Write(depth + "</imgdir>" + lineBreak); } else if (prop is WzShortProperty) { WzShortProperty property10 = (WzShortProperty)prop; tw.Write(string.Concat(new object[] { depth, "<short name=\"", XmlUtil.SanitizeText(property10.Name), "\" value=\"", property10.Value, "\"/>" }) + lineBreak); } else if (prop is WzLongProperty) { WzLongProperty long_prop = (WzLongProperty)prop; tw.Write(string.Concat(new object[] { depth, "<long name=\"", XmlUtil.SanitizeText(long_prop.Name), "\" value=\"", long_prop.Value, "\"/>" }) + lineBreak); } else if (prop is WzUOLProperty) { WzUOLProperty property11 = (WzUOLProperty)prop; tw.Write(depth + "<uol name=\"" + property11.Name + "\" value=\"" + XmlUtil.SanitizeText(property11.Value) + "\"/>" + lineBreak); } else if (prop is WzVectorProperty) { WzVectorProperty property12 = (WzVectorProperty)prop; tw.Write(string.Concat(new object[] { depth, "<vector name=\"", XmlUtil.SanitizeText(property12.Name), "\" x=\"", property12.X.Value, "\" y=\"", property12.Y.Value, "\"/>" }) + lineBreak); } else if (prop is WzFloatProperty) { WzFloatProperty property13 = (WzFloatProperty)prop; string str2 = Convert.ToString(property13.Value, formattingInfo); if (!str2.Contains(".")) { str2 = str2 + ".0"; } tw.Write(depth + "<float name=\"" + XmlUtil.SanitizeText(property13.Name) + "\" value=\"" + str2 + "\"/>" + lineBreak); } else if (prop is WzConvexProperty) { tw.Write(depth + "<extended name=\"" + XmlUtil.SanitizeText(prop.Name) + "\">" + lineBreak); WzConvexProperty property14 = (WzConvexProperty)prop; string newDepth = depth + indent; foreach (WzImageProperty property in property14.WzProperties) { WritePropertyToXML(tw, newDepth, property, exportFilePath); } tw.Write(depth + "</extended>" + lineBreak); } else if (prop is WzLuaProperty) // probably added on v188 gms? { WzLuaProperty property15 = (WzLuaProperty)prop; string parentName = property15.Parent.Name; tw.Write(depth); tw.Write(lineBreak); // Export standalone file here using (TextWriter twLua = new StreamWriter(File.Create(exportFilePath.Replace(parentName + ".xml", parentName)))) { twLua.Write(property15.ToString()); } } }