public static WzObject GetObjectByRelativePath(WzObject currentObject, string path) { foreach (string directive in path.Split("/".ToCharArray())) { if (directive == "..") { currentObject = currentObject.Parent; } else if (currentObject is WzImageProperty) { currentObject = ((WzImageProperty)currentObject)[directive]; } else if (currentObject is WzImage) { currentObject = ((WzImage)currentObject)[directive]; } else if (currentObject is WzDirectory) { currentObject = ((WzDirectory)currentObject)[directive]; } else { throw new Exception("invalid type"); } } return(currentObject); }
public override Bitmap GetBitmap() { if (this["_inlink"] is WzStringProperty inlink) { 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.Value); if (foundProperty != null && foundProperty is WzImageProperty) { return(foundProperty.GetBitmap()); } } } else if (this["_outlink"] is WzStringProperty outlink) { WzObject foundProperty = WzFileParent.GetObjectFromPath(outlink.Value); if (foundProperty is WzImageProperty) { return(foundProperty.GetBitmap()); } } return(imageProp.GetPNG(false)); }
public BodyAction(WzSubProperty src) { _stance = Look.Stance.ByString(((WzStringProperty)src["action"]).Value); if (src["frame"] != null) { Frame = (short)src["frame"]; } WzObject moveProperty = src["move"]; if (moveProperty != null && moveProperty is WzVectorProperty) { _move = (Vector2)moveProperty.WzValue; } short sgnDelay = 0; if (src["delay"] != null) { sgnDelay = (short)src["delay"]; } if (sgnDelay == 0) { sgnDelay = 100; } if (sgnDelay > 0) { Delay = sgnDelay; AttackFrame = true; } else if (sgnDelay < 0) { Delay = (short)-sgnDelay; AttackFrame = false; } }
public List <WzObject> GetChildObjects(WzObject node) { List <WzObject> childs = new List <WzObject>(); bool flag = node is WzDirectory; if (flag) { childs.AddRange(((WzDirectory)node).WzImages); childs.AddRange(((WzDirectory)node).WzDirectories); } else { bool flag2 = node is WzImage; if (flag2) { childs.AddRange(((WzImage)node).WzProperties); } else { bool flag3 = node is WzImageProperty && !(node is WzUOLProperty); if (flag3) { bool flag4 = ((WzImageProperty)node).WzProperties != null; if (flag4) { childs.AddRange(((WzImageProperty)node).WzProperties); } } } } return(childs); }
private void AddSkillRow(WzImageProperty s) { var id = int.Parse(s.Name); var name = StringWz.GetSkill(s.Name); var properties = GetAllProperties(s); WzObject icon = s.GetFromPath("icon"); SkillsView.GridView.Rows.Add(id, icon?.GetBitmap(), name, properties); }
/// <summary> /// Remove all WZ image resource to optimize for botting purposes /// </summary> public void DoRemoveImageResource() { foreach (WzNode node in DataTree.SelectedNodes) { WzObject wzObj = (WzObject)node.Tag;// CloneWzObject((WzObject)node.Tag); } }
public ContextMenuStrip CreateMenu(WzNode node, WzObject Tag) { ContextMenuStrip menu = null; if (Tag is WzImage || Tag is IPropertyContainer) { if (Tag is WzSubProperty) { menu = new ContextMenuStrip(); menu.Items.AddRange(new ToolStripItem[] { AddPropsSubMenu, /*export, import,*/ Remove }); } else { menu = new ContextMenuStrip(); menu.Items.AddRange(new ToolStripItem[] { AddPropsSubMenu, /*export, import,*/ Remove }); } } else if (Tag is WzImageProperty) { menu = new ContextMenuStrip(); menu.Items.AddRange(new ToolStripItem[] { /*export, import,*/ Remove }); } else if (Tag is WzDirectory) { menu = new ContextMenuStrip(); menu.Items.AddRange(new ToolStripItem[] { AddDirsSubMenu, /*export, import,*/ Remove }); } else if (Tag is WzFile) { menu = new ContextMenuStrip(); menu.Items.AddRange(new ToolStripItem[] { AddDirsSubMenu, SaveFile, Unload, Reload }); } currNode = node; return(menu); }
private bool addObjInternal(WzObject obj) { WzObject TaggedObject = (WzObject)Tag; if (TaggedObject is WzFile) { TaggedObject = ((WzFile)TaggedObject).WzDirectory; } if (TaggedObject is WzDirectory) { if (obj is WzDirectory) { ((WzDirectory)TaggedObject).AddDirectory((WzDirectory)obj); } else if (obj is WzImage) { ((WzDirectory)TaggedObject).AddImage((WzImage)obj); } else { return(false); } } else if (TaggedObject is WzImage) { if (!((WzImage)TaggedObject).Parsed) { ((WzImage)TaggedObject).ParseImage(); } if (obj is WzImageProperty) { ((WzImage)TaggedObject).AddProperty((WzImageProperty)obj); ((WzImage)TaggedObject).Changed = true; } else { return(false); } } else if (TaggedObject is IPropertyContainer) { if (obj is WzImageProperty) { ((IPropertyContainer)TaggedObject).AddProperty((WzImageProperty)obj); if (TaggedObject is WzImageProperty) { ((WzImageProperty)TaggedObject).ParentImage.Changed = true; } } else { return(false); } } else { return(false); } return(true); }
/// <summary> /// Adds a WzObject to the WzNode and returns the newly created WzNode /// </summary> /// <param name="obj"></param> /// <param name="undoRedoMan"></param> /// <returns></returns> public WzNode AddObject(WzObject obj, UndoRedoManager undoRedoMan) { if (CanNodeBeInserted(this, obj.Name)) { TryParseImage(); if (addObjInternal(obj)) { WzNode node = new WzNode(obj, true); Nodes.Add(node); if (node.Tag is WzImageProperty) { ((WzImageProperty)node.Tag).ParentImage.Changed = true; } undoRedoMan.AddUndoBatch(new System.Collections.Generic.List <UndoRedoAction> { UndoRedoManager.ObjectAdded(this, node) }); node.EnsureVisible(); return(node); } else { Warning.Error("Could not insert property, make sure all types are correct"); return(null); } } else { MessageBox.Show("Cannot insert object \"" + obj.Name + "\" because an object with the same name already exists. Skipping.", "Skipping Object", MessageBoxButtons.OK, MessageBoxIcon.Information); return(null); } }
public ContextMenuStrip CreateMenu(WzNode node, WzObject Tag) { int currentDataTreeSelectedCount = parentPanel.DataTree.SelectedNodes.Count; ContextMenuStrip menu = new ContextMenuStrip(); if (Tag is WzImage || Tag is IPropertyContainer) { if (Tag is WzSubProperty) { menu.Items.AddRange(new ToolStripItem[] { AddPropsSubMenu, Rename, /*export, import,*/ Remove }); } else { menu.Items.AddRange(new ToolStripItem[] { AddPropsSubMenu, Rename, /*export, import,*/ Remove }); } } else if (Tag is WzImageProperty) { menu.Items.AddRange(new ToolStripItem[] { Rename, /*export, import,*/ Remove }); } else if (Tag is WzDirectory) { menu.Items.AddRange(new ToolStripItem[] { AddDirsSubMenu, Rename, /*export, import,*/ Remove }); } else if (Tag is WzFile) { menu.Items.AddRange(new ToolStripItem[] { AddDirsSubMenu, SaveFile, Unload, Reload }); } currNode = node; return(menu); }
public void DoCopy() { if (!Warning.Warn(Properties.Resources.MainConfirmCopy)) { return; } clipboard.Clear(); foreach (WzNode node in DataTree.SelectedNodes) { WzObject clone = null; if (node.Tag is WzDirectory) { Warning.Error(Properties.Resources.MainCopyDirError); continue; } else if (node.Tag is WzImage) { clone = ((WzImage)node.Tag).DeepClone(); } else if (node.Tag is WzImageProperty) { clone = ((WzImageProperty)node.Tag).DeepClone(); } else { continue; } clipboard.Add(clone); } }
public void InitializeMaps(bool special) { WzObject mapLogin1 = Program.WzManager["ui"]["MapLogin1.img"]; WzObject mapLogin2 = Program.WzManager["ui"]["MapLogin2.img"]; WzObject mapLogin3 = Program.WzManager["ui"]["MapLogin3.img"]; // pretty rare, happened a few times in ascension patch foreach (KeyValuePair <string, Tuple <string, string> > map in Program.InfoManager.Maps) { maps.Add(string.Format("{0} - {1} : {2}", map.Key, map.Value.Item1, map.Value.Item2)); } maps.Sort(); if (special) { maps.Insert(0, "CashShopPreview"); maps.Insert(0, "MapLogin"); if (mapLogin1 != null) { maps.Insert(0, "MapLogin1"); } if (mapLogin2 != null) { maps.Insert(0, "MapLogin2"); } if (mapLogin3 != null) { maps.Insert(0, "MapLogin3"); } } object[] mapsObjs = maps.Cast <object>().ToArray(); mapNamesBox.Items.AddRange(mapsObjs); }
/// <summary> /// Loads spine texture from the specified WZ path /// </summary> /// <param name="page"></param> /// <param name="path"></param> public void Load(AtlasPage page, string path) { WzObject frameNode = this.ParentNode[path]; if (frameNode == null) { return; } WzCanvasProperty canvasProperty = null; WzImageProperty imageChild = (WzImageProperty)ParentNode[path]; if (imageChild is WzUOLProperty uolProperty) { WzObject uolLink = uolProperty.LinkValue; if (uolLink is WzCanvasProperty uolPropertyLink) { canvasProperty = uolPropertyLink; } else { // other unimplemented prop? } } else if (imageChild is WzCanvasProperty property) { canvasProperty = property; } if (canvasProperty != null) { Bitmap bitmap = canvasProperty.GetLinkedWzCanvasBitmap(); if (bitmap != null && graphicsDevice != null) { Texture2D tex = new Texture2D(graphicsDevice, bitmap.Width, bitmap.Height, true, SurfaceFormat.Color); BitmapData data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat); int bufferSize = data.Height * data.Stride; //create data buffer byte[] bytes = new byte[bufferSize]; // copy bitmap data into buffer Marshal.Copy(data.Scan0, bytes, 0, bytes.Length); // copy our buffer to the texture tex.SetData(bytes); // unlock the bitmap data bitmap.UnlockBits(data); page.rendererObject = tex; page.width = bitmap.Width; page.height = bitmap.Height; } } }
public static WzObject GetByUol(this WzObject wzObject) { return(wzObject is WzUolProperty ? (WzObject)(wzObject.WzValue is WzUolProperty ? ((WzUolProperty)wzObject.WzValue).WzValue : wzObject.WzValue) : wzObject); }
private void AddSound(string itemId, WzObject src) { var id = AddSound(src); if (id != null) { _itemIds[itemId] = id; } }
public Foothold(WzObject src, short id, short layer) { Prev = (short)src["prev"]; Next = (short)src["next"]; Horizontal = new Range((short)src["x1"], (short)src["x2"]); Vertical = new Range((short)src["y1"], (short)src["y2"]); Id = id; Layer = layer; }
private void AddSound(Name name, WzObject src) { var id = AddSound(src); if (id != null) { _soundIds[name] = id; } }
/// <summary> /// 播放音效 /// </summary> /// <param name="src">wz节点</param> internal void Play(WzObject src) { var id = AddSound(src); if (id != null) { PlaySfx(id); } }
/// <summary> /// Save button clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void saveImageButton_Click(object sender, EventArgs e) { if (!(DataTree.SelectedNode.Tag is WzCanvasProperty) && !(DataTree.SelectedNode.Tag is WzUOLProperty)) { return; } Bitmap bmp; if (DataTree.SelectedNode.Tag is WzCanvasProperty) { bmp = ((WzCanvasProperty)DataTree.SelectedNode.Tag).PngProperty.GetPNG(false); } else { WzObject linkValue = ((WzUOLProperty)DataTree.SelectedNode.Tag).LinkValue; if (linkValue is WzCanvasProperty) { bmp = ((WzCanvasProperty)linkValue).PngProperty.GetPNG(false); } else { return; } } SaveFileDialog dialog = new SaveFileDialog() { Title = "Select where to save the image...", Filter = "Portable Network Grpahics (*.png)|*.png|CompuServe Graphics Interchange Format (*.gif)|*.gif|Bitmap (*.bmp)|*.bmp|Joint Photographic Experts Group Format (*.jpg)|*.jpg|Tagged Image File Format (*.tif)|*.tif" }; if (dialog.ShowDialog() != DialogResult.OK) { return; } switch (dialog.FilterIndex) { case 1: //png bmp.Save(dialog.FileName, ImageFormat.Png); break; case 2: //gif bmp.Save(dialog.FileName, ImageFormat.Gif); break; case 3: //bmp bmp.Save(dialog.FileName, ImageFormat.Bmp); break; case 4: //jpg bmp.Save(dialog.FileName, ImageFormat.Jpeg); break; case 5: //tiff bmp.Save(dialog.FileName, ImageFormat.Tiff); break; } }
public TileInfo(Bitmap image, System.Drawing.Point origin, string tS, string u, string no, int mag, int z, WzObject parentObject) : base(image, origin, parentObject) { this._tS = tS; this._u = u; this._no = no; this._mag = mag; this._z = z; }
private void AddSkillRow(WzImageProperty s) { int id = int.Parse(s.Name); string name = StringUtility.GetSkill(s.Name); string properties = BuildProperties(s); WzObject icon = s.GetFromPath("icon"); SkillsView.GridView.Rows.Add(id, icon?.GetBitmap(), name, properties); }
public ObjectInfo(Bitmap image, System.Drawing.Point origin, string oS, string l0, string l1, string l2, WzObject parentObject) : base(image, origin, parentObject) { this._oS = oS; this._l0 = l0; this._l1 = l1; this._l2 = l2; this.connect = oS.StartsWith("connect"); }
private void WzImporterThread(object param) { ChangeApplicationState(false); object[] arr = (object[])param; ProgressingWzSerializer deserializer = (ProgressingWzSerializer)arr[0]; string[] files = (string[])arr[1]; WzNode parent = (WzNode)arr[2]; byte[] iv = (byte[])arr[3]; WzObject parentObj = (WzObject)parent.Tag; if (parentObj is WzFile) { parentObj = ((WzFile)parentObj).WzDirectory; } UpdateProgressBar(MainPanel.mainProgressBar, files.Length, true, true); foreach (string file in files) { List <WzObject> objs; try { if (deserializer is WzXmlDeserializer) { objs = ((WzXmlDeserializer)deserializer).ParseXML(file); } else { objs = new List <WzObject> { ((WzImgDeserializer)deserializer).WzImageFromIMGFile(file, iv, Path.GetFileName(file)) } }; } catch (ThreadAbortException) { return; } catch (Exception e) { Warning.Error(string.Format(HaRepacker.Properties.Resources.MainInvalidFileError, file, e.Message)); UpdateProgressBar(MainPanel.mainProgressBar, 1, false, false); continue; } foreach (WzObject obj in objs) { if (((obj is WzDirectory || obj is WzImage) && parentObj is WzDirectory) || (obj is WzImageProperty && parentObj is IPropertyContainer)) { WzNode node = new WzNode(obj); InsertWzNodeThreadSafe(node, parent); } } UpdateProgressBar(MainPanel.mainProgressBar, 1, false, false); } threadDone = true; }
/// <summary> /// Load skeleton data by json or binary automatically /// </summary> /// <param name="atlasNode"></param> /// <param name="atlas"></param> /// <param name="data"></param> /// <returns></returns> private static bool TryLoadSkeletonJsonOrBinary(WzImageProperty atlasNode, Atlas atlas, out SkeletonData data) { data = null; if (atlasNode == null || atlasNode.Parent == null || atlas == null) { return(false); } WzObject parent = atlasNode.Parent; List <WzImageProperty> childProperties; if (parent is WzImageProperty) { childProperties = ((WzImageProperty)parent).WzProperties; } else { childProperties = ((WzImage)parent).WzProperties; } if (childProperties != null) { WzStringProperty stringJsonProp = (WzStringProperty)childProperties.Where(child => child.Name.EndsWith(".json")).FirstOrDefault(); if (stringJsonProp != null) // read json based { StringReader skeletonReader = new StringReader(stringJsonProp.GetString()); SkeletonJson json = new SkeletonJson(atlas); data = json.ReadSkeletonData(skeletonReader); return(true); } else { // try read binary based foreach (WzImageProperty property in childProperties) { if (property is WzBinaryProperty) { WzBinaryProperty soundProp = (WzBinaryProperty)property; // should be called binaryproperty actually using (MemoryStream ms = new MemoryStream(soundProp.GetBytes(false))) { SkeletonBinary skeletonBinary = new SkeletonBinary(atlas); data = skeletonBinary.ReadSkeletonData(ms); return(true); } } } } } return(false); }
public void TestEmptyWzFileSerializes() { var file = new WzFile(1, WzMapleVersionType.Classic); using var ms = new MemoryStream(); file.Serialize(ms); var contents = Encoding.ASCII.GetString(ms.ToArray()); var deserialized = WzObject.DeserializeFile(contents); Assert.IsNotNull(deserialized); }
public WzNode(WzObject SourceObject, bool isWzObjectAddedManually = false) : base(SourceObject.Name) { this.isWzObjectAddedManually = isWzObjectAddedManually; if (isWzObjectAddedManually) { ForeColor = NewObjectForeColor; } // Childs ParseChilds(SourceObject); }
public Frame(WzObject src) { var shift = (((WzVectorProperty)src["face"]["map"]["brow"]).Pos()); Tex = new TextureD(src["Face"]).Shift(-shift); delay = (short)(((WzIntProperty)src["delay"])?.Value ?? 0); if (delay == 0) { delay = 2500; } }
public void ExtractSoundFile(string soundWzFile) { WzDirectory directory = this[soundWzFile]; if (directory == null) { return; } foreach (WzImage soundImage in directory.WzImages) { if (!soundImage.Name.ToLower().Contains("bgm")) { continue; } if (!soundImage.Parsed) { soundImage.ParseImage(); } try { foreach (WzImageProperty bgmImage in soundImage.WzProperties) { WzBinaryProperty binProperty = null; if (bgmImage is WzBinaryProperty bgm) { binProperty = bgm; } else if (bgmImage is WzUOLProperty uolBGM) // is UOL property { WzObject linkVal = ((WzUOLProperty)bgmImage).LinkValue; if (linkVal is WzBinaryProperty linkCanvas) { binProperty = linkCanvas; } } if (binProperty != null) { Program.InfoManager.BGMs[WzInfoTools.RemoveExtension(soundImage.Name) + @"/" + binProperty.Name] = binProperty; } } } catch (Exception e) { string error = string.Format("[ExtractSoundFile] Error parsing {0}, {1} file.\r\nError: {2}", soundWzFile, soundImage.Name, e.ToString()); MapleLib.Helpers.ErrorLogger.Log(ErrorLevel.IncorrectStructure, error); continue; } } }
private int CalculateTotal(WzObject currObj) { int result = 0; if (currObj is WzFile) { result += ((WzFile)currObj).WzDirectory.CountImages(); } else if (currObj is WzDirectory) { result += ((WzDirectory)currObj).CountImages(); } return(result); }
/// <summary> /// Toolstrip menu when right clicking on nodes /// </summary> /// <param name="node"></param> /// <param name="Tag"></param> /// <returns></returns> public ContextMenuStrip CreateMenu(WzNode node, WzObject Tag) { int currentDataTreeSelectedCount = parentPanel.DataTree.SelectedNodes.Count; List <ToolStripItem> toolStripmenuItems = new List <ToolStripItem>(); ContextMenuStrip menu = new ContextMenuStrip(); if (Tag is WzImage || Tag is IPropertyContainer) { toolStripmenuItems.Add(AddPropsSubMenu); toolStripmenuItems.Add(Rename); // export, import toolStripmenuItems.Add(Remove); } else if (Tag is WzImageProperty) { toolStripmenuItems.Add(Rename); toolStripmenuItems.Add(Remove); } else if (Tag is WzDirectory) { toolStripmenuItems.Add(AddDirsSubMenu); toolStripmenuItems.Add(Rename); toolStripmenuItems.Add(Remove); } else if (Tag is WzFile) { toolStripmenuItems.Add(AddDirsSubMenu); toolStripmenuItems.Add(Rename); toolStripmenuItems.Add(SaveFile); toolStripmenuItems.Add(Unload); toolStripmenuItems.Add(Reload); } toolStripmenuItems.Add(FixLink); toolStripmenuItems.Add(ExpandAllChildNode); toolStripmenuItems.Add(CollapseAllChildNode); toolStripmenuItems.Add(SortAllChildNode); // Add foreach (ToolStripItem toolStripItem in toolStripmenuItems) { menu.Items.Add(toolStripItem); } currNode = node; return(menu); }
/// <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 GetLinkedWzCanvasProperty() { if (!HaveInlinkProperty() && !HaveOutlinkProperty()) { return(null); } 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) { return((WzImageProperty)foundProperty); } } } else if (_outlink != null) { WzObject currentWzObj = this; // first object to work with while ((currentWzObj = currentWzObj.Parent) != null) { System.Diagnostics.Debug.WriteLine(currentWzObj.ToString()); if (!(currentWzObj is WzDirectory)) // keep looping if its not a WzImage { continue; } WzFile wzFileParent = ((WzDirectory)currentWzObj).wzFile; WzObject foundProperty = wzFileParent.GetObjectFromPath(_outlink); if (foundProperty != null && foundProperty is WzImageProperty) { return((WzImageProperty)foundProperty); } } } return(null); }
public void DoPaste() { if (!Warning.Warn(Properties.Resources.MainConfirmPaste)) { return; } yesToAll = false; noToAll = false; WzNode parent = (WzNode)DataTree.SelectedNode; WzObject parentObj = (WzObject)parent.Tag; if (parent != null && parent.Tag is WzImage && parent.Nodes.Count == 0) { ParseOnDataTreeSelectedItem(parent); } if (parentObj is WzFile) { parentObj = ((WzFile)parentObj).WzDirectory; } foreach (WzObject obj in clipboard) { if (((obj is WzDirectory || obj is WzImage) && parentObj is WzDirectory) || (obj is WzImageProperty && parentObj is IPropertyContainer)) { WzObject clone = CloneWzObject(obj); if (clone == null) { continue; } WzNode node = new WzNode(clone); WzNode child = WzNode.GetChildNode(parent, node.Text); if (child != null) { if (ShowReplaceDialog(node.Text)) { child.Delete(); } else { return; } } parent.AddNode(node); } } }
public WzObject CloneWzObject(WzObject obj) { if (obj is WzDirectory) { Warning.Error(Properties.Resources.MainCopyDirError); return null; } else if (obj is WzImage) { return ((WzImage)obj).DeepClone(); } else if (obj is WzImageProperty) { return ((WzImageProperty)obj).DeepClone(); } else { return null; } }
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"); } }
public void SerializeObject(WzObject obj, string outPath) { //imagesToUnparse.Clear(); total = 0; curr = 0; this.outPath = outPath; if (!Directory.Exists(outPath)) WzXmlSerializer.createDirSafe(ref outPath); if (outPath.Substring(outPath.Length - 1,1) != @"\") outPath += @"\"; total = CalculateTotal(obj); ExportRecursion(obj, outPath); /*foreach (WzImage img in imagesToUnparse) img.UnparseImage(); imagesToUnparse.Clear();*/ }
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; }
private void ParseChilds(WzObject SourceObject) { if (SourceObject == null) throw new NullReferenceException("Cannot create a null WzNode"); Tag = SourceObject; SourceObject.HRTag = this; if (SourceObject is WzFile) SourceObject = ((WzFile)SourceObject).WzDirectory; if (SourceObject is WzDirectory) { foreach (WzDirectory dir in ((WzDirectory)SourceObject).WzDirectories) Nodes.Add(new WzNode(dir)); foreach (WzImage img in ((WzDirectory)SourceObject).WzImages) Nodes.Add(new WzNode(img)); } else if (SourceObject is WzImage) { if (((WzImage)SourceObject).Parsed) foreach (WzImageProperty prop in ((WzImage)SourceObject).WzProperties) Nodes.Add(new WzNode(prop)); } else if (SourceObject is IPropertyContainer) { foreach (WzImageProperty prop in ((IPropertyContainer)SourceObject).WzProperties) Nodes.Add(new WzNode(prop)); } }
private int CalculateTotal(WzObject currObj) { int result = 0; if (currObj is WzFile) result += ((WzFile)currObj).WzDirectory.CountImages(); else if (currObj is WzDirectory) result += ((WzDirectory)currObj).CountImages(); return result; }
private void ExportRecursion(WzObject currObj, string outPath) { if (currObj is WzFile) ExportRecursion(((WzFile)currObj).WzDirectory, outPath); else if (currObj is WzDirectory) { outPath += 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.GetPNG(false); string path = outPath + currObj.Name + ".png"; bmp.Save(path, ImageFormat.Png); //curr++; } else if (currObj is WzSoundProperty) { string path = outPath + currObj.Name + ".mp3"; ((WzSoundProperty)currObj).SaveToFile(path); } else if (currObj is WzImage) { outPath += currObj.Name + @"\"; if (!Directory.Exists(outPath)) Directory.CreateDirectory(outPath); bool parse = ((WzImage)currObj).Parsed || ((WzImage)currObj).Changed; if (!parse) ((WzImage)currObj).ParseImage(); foreach (WzImageProperty subprop in ((IPropertyContainer)currObj).WzProperties) ExportRecursion(subprop, outPath); if (!parse) ((WzImage)currObj).UnparseImage(); curr++; } else if (currObj is IPropertyContainer) { outPath += currObj.Name + "."; foreach (WzImageProperty subprop in ((IPropertyContainer)currObj).WzProperties) ExportRecursion(subprop, outPath); } else if (currObj is WzUOLProperty) ExportRecursion(((WzUOLProperty)currObj).LinkValue, outPath); }
public WzNode(WzObject SourceObject) : base(SourceObject.Name) { ParseChilds(SourceObject); }
private bool ValidAnimation(WzObject prop) { if (!(prop is WzSubProperty)) return false; WzSubProperty castedProp = (WzSubProperty)prop; List<WzCanvasProperty> props = new List<WzCanvasProperty>(castedProp.WzProperties.Count); int foo; foreach (WzImageProperty subprop in castedProp.WzProperties) { if (!(subprop is WzCanvasProperty)) continue; if (!int.TryParse(subprop.Name, out foo)) return false; props.Add((WzCanvasProperty)subprop); } if (props.Count < 2) return false; props.Sort(new Comparison<WzCanvasProperty>(AnimationBuilder.PropertySorter)); for (int i = 0; i < props.Count; i++) if (i.ToString() != props[i].Name) return false; return true; }
private bool addObjInternal(WzObject obj) { WzObject TaggedObject = (WzObject)Tag; if (TaggedObject is WzFile) TaggedObject = ((WzFile)TaggedObject).WzDirectory; if (TaggedObject is WzDirectory) { if (obj is WzDirectory) ((WzDirectory)TaggedObject).AddDirectory((WzDirectory)obj); else if (obj is WzImage) ((WzDirectory)TaggedObject).AddImage((WzImage)obj); else return false; } else if (TaggedObject is WzImage) { if (!((WzImage)TaggedObject).Parsed) ((WzImage)TaggedObject).ParseImage(); if (obj is WzImageProperty) { ((WzImage)TaggedObject).AddProperty((WzImageProperty)obj); ((WzImage)TaggedObject).Changed = true; } else return false; } else if (TaggedObject is IPropertyContainer) { if (obj is WzImageProperty) { ((IPropertyContainer)TaggedObject).AddProperty((WzImageProperty)obj); if (TaggedObject is WzImageProperty) ((WzImageProperty)TaggedObject).ParentImage.Changed = true; } else return false; } else return false; return true; }
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); } }
public MapleDrawableInfo(Bitmap image, Point origin, WzObject parentObject) { this.Image = image; this.origin = origin; this.parentObject = parentObject; }
public static WzObject GetObjectByRelativePath(WzObject currentObject, string path) { foreach (string directive in path.Split("/".ToCharArray())) { if (directive == "..") currentObject = currentObject.Parent; else if (currentObject is WzImageProperty) currentObject = ((WzImageProperty)currentObject)[directive]; else if (currentObject is WzImage) currentObject = ((WzImage)currentObject)[directive]; else if (currentObject is WzDirectory) currentObject = ((WzDirectory)currentObject)[directive]; else throw new Exception("invalid type"); } return currentObject; }
public MapleExtractableInfo(Bitmap image, System.Drawing.Point origin, WzObject parentObject) : base(image, origin, parentObject) { }
public PortalInfo(string type, Bitmap image, System.Drawing.Point origin, WzObject parentObject) : base(image, origin, parentObject) { this.type = type; }
public ContextMenuStrip CreateMenu(WzNode node, WzObject Tag) { ContextMenuStrip menu = null; if (Tag is WzImage || Tag is IPropertyContainer) { if (Tag is WzSubProperty) { menu = new ContextMenuStrip(); menu.Items.AddRange(new ToolStripItem[] { AddPropsSubMenu, /*export, import,*/Remove }); } else { menu = new ContextMenuStrip(); menu.Items.AddRange(new ToolStripItem[] { AddPropsSubMenu, /*export, import,*/Remove }); } } else if (Tag is WzImageProperty) { menu = new ContextMenuStrip(); menu.Items.AddRange(new ToolStripItem[] { /*export, import,*/Remove }); } else if (Tag is WzDirectory) { menu = new ContextMenuStrip(); menu.Items.AddRange(new ToolStripItem[] { AddDirsSubMenu, /*export, import,*/Remove }); } else if (Tag is WzFile) { menu = new ContextMenuStrip(); menu.Items.AddRange(new ToolStripItem[] { AddDirsSubMenu, SaveFile, Unload, Reload }); } currNode = node; return menu; }
private void ShowObjectValue(WzObject obj) { mp3Player.SoundProperty = null; nameBox.Text = obj is WzFile ? ((WzFile)obj).Header.Copyright : obj.Name; nameBox.ButtonEnabled = false; if (obj is WzFile || obj is WzDirectory || obj is WzImage || obj is WzNullProperty || obj is WzSubProperty || obj is WzConvexProperty) { nameBox.Visible = true; canvasPropBox.Visible = false; pictureBoxPanel.Visible = false; textPropBox.Visible = false; mp3Player.Visible = false; vectorPanel.Visible = false; applyChangesButton.Visible = false; changeImageButton.Visible = false; saveImageButton.Visible = false; changeSoundButton.Visible = false; saveSoundButton.Visible = false; } else if (obj is WzCanvasProperty) { nameBox.Visible = true; canvasPropBox.Visible = true; pictureBoxPanel.Visible = true; textPropBox.Visible = false; mp3Player.Visible = false; canvasPropBox.Image = obj.GetBitmap(); vectorPanel.Visible = false; applyChangesButton.Visible = false; changeImageButton.Visible = true; saveImageButton.Visible = true; changeSoundButton.Visible = false; saveSoundButton.Visible = false; } else if (obj is WzSoundProperty) { nameBox.Visible = true; canvasPropBox.Visible = false; pictureBoxPanel.Visible = false; textPropBox.Visible = false; mp3Player.Visible = true; mp3Player.SoundProperty = (WzSoundProperty)obj; vectorPanel.Visible = false; applyChangesButton.Visible = false; changeImageButton.Visible = false; saveImageButton.Visible = false; changeSoundButton.Visible = true; saveSoundButton.Visible = true; } else if (obj is WzStringProperty || obj is WzIntProperty || obj is WzDoubleProperty || obj is WzFloatProperty || obj is WzShortProperty || obj is WzUOLProperty) { nameBox.Visible = true; canvasPropBox.Visible = false; pictureBoxPanel.Visible = false; textPropBox.Visible = true; mp3Player.Visible = false; textPropBox.Text = obj.ToString(); vectorPanel.Visible = false; applyChangesButton.Visible = true; changeImageButton.Visible = false; saveImageButton.Visible = false; changeSoundButton.Visible = false; saveSoundButton.Visible = false; } else if (obj is WzVectorProperty) { nameBox.Visible = true; canvasPropBox.Visible = false; pictureBoxPanel.Visible = false; textPropBox.Visible = false; mp3Player.Visible = false; vectorPanel.Visible = true; vectorPanel.X = ((WzVectorProperty)obj).X.Value; vectorPanel.Y = ((WzVectorProperty)obj).Y.Value; applyChangesButton.Visible = true; changeImageButton.Visible = false; saveImageButton.Visible = false; changeSoundButton.Visible = false; saveSoundButton.Visible = false; } else { } }
public MobInfo(Bitmap image, System.Drawing.Point origin, string id, string name, WzObject parentObject) : base(image, origin, parentObject) { this.id = id; this.name = name; }
public bool AddObject(WzObject obj, UndoRedoManager undoRedoMan) { if (CanNodeBeInserted(this, obj.Name)) { TryParseImage(); if (addObjInternal(obj)) { WzNode node = new WzNode(obj); Nodes.Add(node); if (node.Tag is WzImageProperty) ((WzImageProperty)node.Tag).ParentImage.Changed = true; undoRedoMan.AddUndoBatch(new System.Collections.Generic.List<UndoRedoAction> { UndoRedoManager.ObjectAdded(this, node) }); node.EnsureVisible(); return true; } else { Warning.Error("Could not insert property, make sure all types are correct"); return false; } } else { MessageBox.Show("Cannot insert object \"" + obj.Name + "\" because an object with the same name already exists. Skipping.", "Skipping Object", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } }