public MainWindow() { InitializeComponent(); try { var filename = @"Wz\Character.wz"; filename = @"D:\NEXON\Europe MapleStory for Vista\Character.wz"; var xz = new WZFile(filename, WZVariant.EMS, false); Title = Path.GetFileName(filename); BaseTree.Items.SortDescriptions.Clear(); BaseTree.Items.SortDescriptions.Add(new SortDescription("Header", ListSortDirection.Ascending)); foreach (var item in xz.MainDirectory) { AddNode(BaseTree, item); } } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); } }
public static List <Frame> InputWz(WZFile wz, string inpath) { WZObject iwahz = wz.ResolvePath(inpath); WZSubProperty iwah = iwahz as WZSubProperty; if (iwah == null) { throw new ArgumentException("The path provided did not lead to an animation; check input-wzfile, input-wzpath and input-wzver"); } List <Frame> r = new List <Frame>(); foreach (WZObject iwzo in iwah) { WZCanvasProperty iwc = iwzo.ResolveUOL() as WZCanvasProperty; if (iwc == null) { continue; } int n; if (!int.TryParse(iwzo.Name, out n)) { continue; } r.Add(new Frame(n, new Bitmap(iwc.Value), ((WZPointProperty)iwc["origin"]).Value, iwc.HasChild("delay") ? Math.Max(iwc["delay"].ToInt(), 1) : 100)); iwc.Dispose(); } return(r.OrderBy(f => f.Number).ToList()); }
public void LoadFile(string fileName) { var path = WzConstant.GetFilePath(fileName); var file = new WZFile(path, WZVariant.GMS, true, WzConstant.WZReadSelection); m_wzFiles.Add(fileName, file); }
public ExtractString(string fileName, string output) { WZFile xz = new WZFile(fileName, WZVariant.Classic, true, WZReadSelection.EagerParseStrings); WZObject consume = xz.MainDirectory["Consume.img"]; StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); HashSet <string> listOfDamageSkins = new HashSet <string>(); string[] exceptions = new string[] { "30", "Protected", "Permanent", "Box", "Ticket" }; using (JsonWriter writer = new JsonTextWriter(sw)) { writer.Formatting = Formatting.Indented; writer.WriteStartArray(); foreach (var item in consume) { foreach (var child in item) { if (child.Name == "name") { if (child.ValueOrDie <String>().Contains("Damage Skin -")) { string damageSkin = child.ValueOrDie <string>(); if (exceptions.Any(damageSkin.Contains)) { break; } string[] split = damageSkin.Split('-'); string actualString = split[1].Trim(); if (listOfDamageSkins.Contains(actualString)) { Console.WriteLine(actualString + " is already in the list"); break; } else { listOfDamageSkins.Add(actualString); writer.WriteStartObject(); writer.WritePropertyName("itemId"); writer.WriteValue(item.Name); writer.WritePropertyName("itemName"); writer.WriteValue(damageSkin); writer.WriteEndObject(); Console.WriteLine(damageSkin); } } } } } writer.WriteEndArray(); } File.WriteAllText(output, sb.ToString()); Console.WriteLine("Number of Damage Skins: " + listOfDamageSkins.Count); Console.Write("done"); Console.ReadKey(); }
public void Run() { try { using (var xz = new WZFile(Settings.FullPath, WZVariant.EMS, false, WZReadSelection.None)) { //var q = ((WZAudioProperty)xz.MainDirectory["BgmGL.img"]["011_Mach"]).Value; //var q = xz.MainDirectory["00012012.img"]["alert"]["0"]; //File.WriteAllBytes("face.png", q); foreach (var item in xz.MainDirectory) { Export(item, null, false); } } } catch (Exception ex) { Error("Uncaught exception: " + Settings.Filename, ex); } var writerThreads = Settings.GetWritersSnapshot(); while (!Task.WaitAll(writerThreads, 1000)) { Settings.WriteToLog("Waiting for " + writerThreads.Where(f => !f.IsCompleted).Count() + " writer threads to complete"); } Settings.WriteToLog("-------------------------\r\nDone exporting " + Settings.Filename + "\r\n-------------------------"); Settings.Dispose(); }
public static void LoadMusic(string name) { if (name == current) return; MediaPlayer.Stop(); if (name == "") return; string[] path = name.Split('/'); if (!Directory.Exists("Music")) { DirectoryInfo dir = Directory.CreateDirectory("Music"); dir.Attributes = FileAttributes.Directory | FileAttributes.Hidden; } //Play Music if (!File.Exists("\\Music\\" + path[1] + ".mp3")) { using (Stream s = File.Create(System.Windows.Forms.Application.StartupPath + @"\Music\" + path[1] + ".mp3")) { WZFile soundWz = new WZFile("Sound.wz", WZVariant.GMS, true, WZReadSelection.LowMemory); byte[] sound = ((WZMP3Property)soundWz.ResolvePath(path[0] + ".img/" + path[1])).Value; s.Write(sound, 0, sound.Length); } } Song music = Song.FromUri(name, new Uri("file:///" + System.Windows.Forms.Application.StartupPath + "/Music/" + path[1] + ".mp3")); MediaPlayer.Play(music); MediaPlayer.IsRepeating = true; current = name; }
public Zevms027Controller(ILogger <Zevms027Controller> logger, IOptions <AppSettings> appSettings, WZFile wzFile, WzData wzData, zevms027Context dbContext) { _logger = logger; _appSettings = appSettings.Value; _wzFile = wzFile; _wzData = wzData; _context = dbContext; }
public Startup(IConfiguration configuration, IWebHostEnvironment env) { Configuration = configuration; ContentRootPath = env.ContentRootPath; var wzFilePath = Path.Combine(ContentRootPath, "wz", "Data.wz"); WZFile = new WZFile(wzFilePath, WZVariant.Classic, true); }
internal WZImage(string name, WZObject parent, WZFile file, WZBinaryReader reader) : base(name, parent, file, true, WZObjectType.Image) { _r = reader; if ((file._flag & WZReadSelection.EagerParseImage) == WZReadSelection.EagerParseImage) { Parse(); } }
internal WZObject(string name, WZObject parent, WZFile container, bool children, WZObjectType type) { Name = string.Intern(name); Parent = parent; File = container; _canContainChildren = children; if (_canContainChildren) { _backing = new ChildCollection(); } Type = type; }
public static void Export(string inputPath, string outputPath) { List <ItemData> items = new List <ItemData>(); using (WZFile file = new WZFile(Path.Combine(inputPath, "Item.wz"), WZVariant.GMS, true, WZReadSelection.None)) { foreach (var category in file.MainDirectory) { if (category.Name == "Pet" || category.Name == "Special") { continue; } foreach (var subcategory in category) { foreach (var node in subcategory) { ItemData item = new ItemData(); item.MapleID = int.Parse(node.Name); item.MaxSlotQuantity = (short)node["info"].GetInt("slotMax", 1); item.SalePrice = node["info"].GetInt("price"); items.Add(item); } } } } items = items.OrderBy(i => i.MapleID).ToList(); using (FileStream stream = File.Create(Path.Combine(outputPath, "Items.bin"))) { using (BinaryWriter writer = new BinaryWriter(stream)) { writer.Write(items.Count); foreach (ItemData item in items) { item.Save(writer); } } } Logger.Write(LogLevel.Info, "Exported {0} items.", items.Count); items.Clear(); }
public static void Export(string inputPath, string outputPath) { List <NpcData> npcs = new List <NpcData>(); using (WZFile file = new WZFile(Path.Combine(inputPath, "Npc.wz"), WZVariant.GMS, true, WZReadSelection.None)) { foreach (var npcNode in file.MainDirectory) { NpcData npc = new NpcData(); npc.MapleID = npcNode.GetID(); npc.IsMoving = npcNode.HasChild("move"); npc.IsMapleTV = npcNode["info"].HasChild("MapleTV"); npc.IsGuildRank = npcNode["info"].HasChild("guildRank"); npc.StorageCost = npcNode["info"].GetInt("trunkPut"); if (npcNode.HasChild("script")) { npc.Script = npcNode["script"]["0"].GetString("script"); } else { npc.Script = string.Empty; } npcs.Add(npc); } } npcs = npcs.OrderBy(m => m.MapleID).ToList(); using (FileStream stream = File.Create(Path.Combine(outputPath, "Npcs.bin"))) { using (BinaryWriter writer = new BinaryWriter(stream)) { writer.Write(npcs.Count); foreach (NpcData npc in npcs) { npc.Save(writer); } } } Logger.Write(LogLevel.Info, "Exported {0} npcs.", npcs.Count); npcs.Clear(); }
public static List<Frame> InputWz(WZFile wz, string inpath) { WZObject iwahz = wz.ResolvePath(inpath); WZSubProperty iwah = iwahz as WZSubProperty; if (iwah == null) throw new ArgumentException("The path provided did not lead to an animation; check input-wzfile, input-wzpath and input-wzver"); List<Frame> r = new List<Frame>(); foreach (WZObject iwzo in iwah) { WZCanvasProperty iwc = iwzo.ResolveUOL() as WZCanvasProperty; if (iwc == null) continue; int n; if (!int.TryParse(iwzo.Name, out n)) continue; r.Add(new Frame(n, new Bitmap(iwc.Value), ((WZPointProperty)iwc["origin"]).Value, iwc.HasChild("delay") ? Math.Max(iwc["delay"].ToInt(), 1) : 100)); iwc.Dispose(); } return r.OrderBy(f => f.Number).ToList(); }
public WzNode(NodeView nodeView, string directoryPath) : base(nodeView) { this.DirectoryPath = directoryPath; this.Text = Path.GetFileName(directoryPath); if (Program.WzFileCache.ContainsKey(this.Text)) { _wzFile = Program.WzFileCache[this.Text]; } else { _wzFile = new WZFile(directoryPath, WZVariant.GMS, true); Program.WzFileCache[this.Text] = _wzFile; } }
protected override void LoadContent() { loadTimer.Restart(); spriteBatch = new SpriteBatch(GraphicsDevice); // Get Cursor Animations WZFile uiWz = new WZFile("UI.wz", WZVariant.GMS, true, WZReadSelection.LowMemory); MapleCursor.LoadCursor(GraphicsDevice, (WZSubProperty)uiWz.ResolvePath("Basic.img/Cursor")); // Load the cursor animations c: Constants.Globals.Font = Content.Load<SpriteFont>("lolwut"); // TODO: Load character equips'n'shit.. MapEngine.LoadMap(GraphicsDevice, 100000000); // Load a map by id :3 MapleConsole.Write(MapleConsole.LogType.MESSAGE, "MapleSharp", "Content Loaded in " + loadTimer.ElapsedMilliseconds.ToString() + "ms."); }
public MapleEquip(GraphicsDevice graphics, int id, EquipType type) { // Load animations.. WZFile charWz = new WZFile("Character.wz", WZVariant.GMS, true, WZReadSelection.LowMemory); string equipPath = EquipTypes[(int)type] + "/" + id.ToString("00000000") + ".img"; Vector2 extraOffset = Vector2.Zero; switch (type) { case EquipType.Top: extraOffset = new Vector2(2, 25); break; } foreach (MapleCharacter.CharacterState state in Enum.GetValues(typeof(MapleCharacter.CharacterState))) // Loop through the states and get the frames for each animation.. { Dictionary<int, MapleFrame> eFrames = new Dictionary<int, MapleFrame>(); Dictionary<int, MapleFrame> aFrames = new Dictionary<int, MapleFrame>(); string statePath = equipPath + "/" + MapleCharacter.States[(int)state]; foreach (WZObject frame in charWz.ResolvePath(statePath)) { foreach (WZObject bit in frame) { if (bit is WZCanvasProperty) { WZPointProperty origin = (WZPointProperty)bit["origin"]; switch (bit.Name) { case "mail": eFrames.Add(int.Parse(frame.Name), new MapleFrame(new MapleCanvas(Tools.BitmapToTexture(graphics, bit.ValueOrDie<System.Drawing.Bitmap>()), new Vector2(-origin.Value.X, -origin.Value.Y)), 100)); break; case "mailArm": aFrames.Add(int.Parse(frame.Name), new MapleFrame(new MapleCanvas(Tools.BitmapToTexture(graphics, bit.ValueOrDie<System.Drawing.Bitmap>()), new Vector2(-origin.Value.X, -origin.Value.Y)), 100)); break; } } } } ani.Add(state, new MapleAnimation(eFrames)); armAni.Add(state, new MapleAnimation(aFrames)); } }
public WZDataDirectory(WZFile file) { _file = file; }
public ExtractImg(string fileName, string location, string jsonLocation, string iconLocation) { int count = 0; var dmgSkins = JsonConvert.DeserializeObject <List <DamageSkin> >(File.ReadAllText(jsonLocation)); Directory.CreateDirectory(location); Directory.CreateDirectory(iconLocation); WZFile xz = new WZFile(fileName, WZVariant.MSEA, false); WZImage dmgSkinImg = (WZImage)xz.MainDirectory["Consume"]["0243.img"]; WZImage dmgSkinImg2 = (WZImage)xz.MainDirectory["Consume"]["0263.img"]; foreach (var itemImg in dmgSkinImg) { foreach (var jsonDmg in dmgSkins) { //Console.Write("debug"); string itemId = "0" + jsonDmg.itemId; if (itemId.StartsWith("0243")) { if (itemImg.Name == itemId) { if (itemImg["info"].HasChild("sample")) { Bitmap dmgSkinPng = null; Bitmap dmgSkinIconPng = null; WZCanvasProperty iconTest = null; WZCanvasProperty test = (WZCanvasProperty)itemImg["info"]["sample"]; if (itemImg["info"].HasChild("icon")) { if (itemImg["info"]["icon"].Type == WZObjectType.UOL) { iconTest = (WZCanvasProperty)itemImg["info"]["iconRaw"]; } else { iconTest = (WZCanvasProperty)itemImg["info"]["icon"]; } if (iconTest.HasChild("_outlink")) { string path = iconTest["_outlink"].ValueOrDie <string>(); path = path.Substring(path.IndexOf('/') + 1); dmgSkinIconPng = xz.ResolvePath(path).ValueOrDie <Bitmap>(); } else if (iconTest.HasChild("_inlink")) { string path = iconTest["_inlink"].ValueOrDie <string>(); string[] pathList = path.Split('/'); dmgSkinIconPng = dmgSkinImg[pathList[0]][pathList[1]][pathList[2]].ValueOrDie <Bitmap>(); } else { dmgSkinIconPng = iconTest.Value; } } // Damage Skin Section if (test.HasChild("_outlink")) { string path = test["_outlink"].ValueOrDie <string>(); path = path.Substring(path.IndexOf('/') + 1); dmgSkinPng = xz.ResolvePath(path).ValueOrDie <Bitmap>(); } else if (test.HasChild("_inlink")) { string path = test["_inlink"].ValueOrDie <string>(); string[] pathList = path.Split('/'); dmgSkinPng = dmgSkinImg[pathList[0]][pathList[1]][pathList[2]].ValueOrDie <Bitmap>(); } else { dmgSkinPng = test.Value; } dmgSkinPng.Save($@"{location}\{itemId}.png", ImageFormat.Png); dmgSkinIconPng.Save($@"{iconLocation}\{itemId}.png", ImageFormat.Png); Console.WriteLine($"Dumped {jsonDmg.itemId} - {jsonDmg.itemName}"); count++; } } } } } foreach (var itemImg2 in dmgSkinImg2) { foreach (var jsonDmg in dmgSkins) { //Console.Write("debug"); string itemId = "0" + jsonDmg.itemId; if (itemId.StartsWith("0263")) { if (itemImg2.Name == itemId) { if (itemImg2["info"].HasChild("sample")) { Bitmap dmgSkinPng = null; Bitmap dmgSkinIconPng = null; WZCanvasProperty iconTest = null; WZCanvasProperty test = (WZCanvasProperty)itemImg2["info"]["sample"]; if (itemImg2["info"].HasChild("icon")) { if (itemImg2["info"]["icon"].Type == WZObjectType.UOL) { iconTest = (WZCanvasProperty)itemImg2["info"]["iconRaw"]; } else { iconTest = (WZCanvasProperty)itemImg2["info"]["icon"]; } if (iconTest.HasChild("_outlink")) { string path = iconTest["_outlink"].ValueOrDie <string>(); path = path.Substring(path.IndexOf('/') + 1); dmgSkinIconPng = xz.ResolvePath(path).ValueOrDie <Bitmap>(); } else if (iconTest.HasChild("_inlink")) { string path = iconTest["_inlink"].ValueOrDie <string>(); string[] pathList = path.Split('/'); dmgSkinIconPng = dmgSkinImg2[pathList[0]][pathList[1]][pathList[2]].ValueOrDie <Bitmap>(); } else { dmgSkinIconPng = iconTest.Value; } } // damage skin if (test.HasChild("_outlink")) { string path = test["_outlink"].ValueOrDie <string>(); path = path.Substring(path.IndexOf('/') + 1); dmgSkinPng = xz.ResolvePath(path).ValueOrDie <Bitmap>(); } else if (test.HasChild("_inlink")) { string path = test["_inlink"].ValueOrDie <string>(); string[] pathList = path.Split('/'); if (path.Contains("2630086")) { dmgSkinPng = dmgSkinImg2[pathList[0]][pathList[1]][pathList[2]][pathList[3]].ValueOrDie <Bitmap>(); } else { dmgSkinPng = dmgSkinImg2[pathList[0]][pathList[1]][pathList[2]].ValueOrDie <Bitmap>(); } } else { dmgSkinPng = test.Value; } dmgSkinIconPng = iconTest.Value; dmgSkinPng.Save($@"{location}\{itemId}.png", ImageFormat.Png); dmgSkinIconPng.Save($@"{iconLocation}\{itemId}.png", ImageFormat.Png); Console.WriteLine($"Dumped {jsonDmg.itemId} - {jsonDmg.itemName}"); count++; } } } } } Console.WriteLine($"Successfully dumped {count.ToString()} number of damage skins"); Console.ReadKey(); }
public Copy(WZFile source, int offset, int size) { this.source = source; this.offset = offset; this.size = size ; }
private static void Run(string inWz, string outPath, WZVariant wzVar, bool initialEnc) { Console.WriteLine("Input .wz: {0}{1}Output .nx: {2}", Path.GetFullPath(inWz), Environment.NewLine, Path.GetFullPath(outPath)); Stopwatch swOperation = new Stopwatch(); Stopwatch fullTimer = new Stopwatch(); Action<string> reportDone = str => { Console.WriteLine("done. E{0} T{1}", swOperation.Elapsed, fullTimer.Elapsed); swOperation.Restart(); Console.Write(str); }; fullTimer.Start(); swOperation.Start(); Console.Write("Parsing input WZ... ".PadRight(31)); WZReadSelection rFlags = WZReadSelection.EagerParseImage | WZReadSelection.EagerParseStrings; if (!dumpImg) rFlags |= WZReadSelection.NeverParseCanvas; using (WZFile wzf = new WZFile(inWz, wzVar, initialEnc, rFlags)) using ( FileStream outFs = new FileStream(outPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None)) using (BinaryWriter bw = new BinaryWriter(outFs)) { DumpState state = new DumpState(); reportDone("Writing header... ".PadRight(31)); bw.Write(PKG4); bw.Write(new byte[(4 + 8)*4]); reportDone("Writing nodes... ".PadRight(31)); outFs.EnsureMultiple(4); ulong nodeOffset = (ulong) bw.BaseStream.Position; List<WZObject> nodeLevel = new List<WZObject> {wzf.MainDirectory}; while (nodeLevel.Count > 0) WriteNodeLevel(ref nodeLevel, state, bw); ulong stringOffset; uint stringCount = (uint) state.Strings.Count; { reportDone("Writing string data...".PadRight(31)); Dictionary<uint, string> strings = state.Strings.ToDictionary(kvp => kvp.Value, kvp => kvp.Key); ulong[] offsets = new ulong[stringCount]; for (uint idx = 0; idx < stringCount; ++idx) { outFs.EnsureMultiple(2); offsets[idx] = (ulong) bw.BaseStream.Position; WriteString(strings[idx], bw); } outFs.EnsureMultiple(8); stringOffset = (ulong) bw.BaseStream.Position; for (uint idx = 0; idx < stringCount; ++idx) bw.Write(offsets[idx]); } ulong bitmapOffset = 0UL; uint bitmapCount = 0U; if (dumpImg) { reportDone("Writing canvas data...".PadRight(31)); bitmapCount = (uint) state.Canvases.Count; ulong[] offsets = new ulong[bitmapCount]; long cId = 0; foreach (WZCanvasProperty cNode in state.Canvases) { outFs.EnsureMultiple(8); offsets[cId++] = (ulong) bw.BaseStream.Position; WriteBitmap(cNode, bw); } outFs.EnsureMultiple(8); bitmapOffset = (ulong) bw.BaseStream.Position; for (uint idx = 0; idx < bitmapCount; ++idx) bw.Write(offsets[idx]); } ulong soundOffset = 0UL; uint soundCount = 0U; if (dumpSnd) { reportDone("Writing MP3 data... ".PadRight(31)); soundCount = (uint) state.MP3s.Count; ulong[] offsets = new ulong[soundCount]; long cId = 0; foreach (WZAudioProperty mNode in state.MP3s) { outFs.EnsureMultiple(8); offsets[cId++] = (ulong) bw.BaseStream.Position; WriteMP3(mNode, bw); } outFs.EnsureMultiple(8); soundOffset = (ulong) bw.BaseStream.Position; for (uint idx = 0; idx < soundCount; ++idx) bw.Write(offsets[idx]); } reportDone("Writing linked node data... ".PadRight(31)); byte[] uolReplace = new byte[16]; foreach (KeyValuePair<WZUOLProperty, Action<BinaryWriter, byte[]>> pair in state.UOLs) { WZObject result = pair.Key.FinalTarget; if (result == null) continue; bw.BaseStream.Position = (long) (nodeOffset + state.GetNodeID(result)*20 + 4); bw.BaseStream.Read(uolReplace, 0, 16); pair.Value(bw, uolReplace); } reportDone("Finalising... ".PadRight(31)); bw.Seek(4, SeekOrigin.Begin); bw.Write((uint) state.Nodes.Count); bw.Write(nodeOffset); bw.Write(stringCount); bw.Write(stringOffset); bw.Write(bitmapCount); bw.Write(bitmapOffset); bw.Write(soundCount); bw.Write(soundOffset); reportDone("Completed!"); } }
private static void MainMain(string[] args) { #region getopt bool printHelp = false; string aWzInPath = null; bool aWzNamesEnc = true; bool aPngOutput = false; WZVariant aWzVer = (WZVariant)int.MinValue; string aOutputPath = null; Color aBgColor = Color.Black; LoopType aLoop = LoopType.NoLoop; int aPadding = 10; // input, input-wzfile, input-wzpath, input-wzver, output, output-path, background-color, padding OptionSet set = new OptionSet(); set.Add("iwzp=|input-wzpath=", "The path of the animation or image. Required", s => aWzInPath = s); set.Add("iwzv=|input-wzver=", "The WZ key to use when decoding the WZ. Required", s => aWzVer = (WZVariant)Enum.Parse(typeof(WZVariant), s)); set.Add("iwzne|input-wz-names-not-encrypted", "Flag if WZ image names are not encrypted. ", s => aWzNamesEnc = false); set.Add("o=|of=|output-format=", "The method of output: (a)png or gif", s => { switch (s.ToLower()) { case "png": aPngOutput = true; break; case "gif": aPngOutput = false; break; default: throw new ArgumentException("output must be either png or gif"); } }); set.Add("op=|output-path=", "The path to write the output, (A)PNG or GIF, to", s => aOutputPath = s); set.Add("abg=|a-background-color=", "The background color of the animated output. Default is black. Ignored if there is no animation.", s => aBgColor = Color.FromArgb(int.Parse(s))); set.Add("ap=|a-padding=", "The amount of padding in pixels to pad the animated output with. Default is 10. Ignored if there is no animation.", s => aPadding = int.Parse(s)); set.Add("al=|a-looping=", "The method to loop multi-animations with. Default is NoLoop. Ignored if there is no animation.", s => aLoop = (LoopType)Enum.Parse(typeof(LoopType), s, true)); set.Add("?|h|help", "Shows help", s => printHelp = true); set.Parse(args); #endregion #region check params printHelp |= aWzInPath == null || aWzVer == (WZVariant)int.MinValue || aOutputPath == null; if (printHelp) { PrintHelp(set); return; } #endregion string[] wzpaths = aWzInPath.Split('*'); List<List<Frame>> framess = new List<List<Frame>>(); string newPath = null, cWzPath = null; WZFile wz = null; foreach (string[] split in wzpaths.Select(wzpath => wzpath.Split('?'))) { string inPath; if (newPath != null && split.Length == 1) inPath = split[0]; else { newPath = split[0]; inPath = split[1]; } if (cWzPath != newPath && wz != null) wz.Dispose(); #region wz parsing if(cWzPath != newPath) wz = new WZFile(newPath, aWzVer, aWzNamesEnc); cWzPath = newPath; #endregion #region getting single image WZCanvasProperty wzcp = wz.ResolvePath(inPath).ResolveUOL() as WZCanvasProperty; if (wzcp != null) { Bitmap b = wzcp.Value; if(aPngOutput) OutputMethods.OutputPNG(b, aOutputPath); else OutputMethods.OutputGIF(b, aOutputPath); return; } #endregion try { List<Frame> data = InputMethods.InputWz(wz, inPath); if (data.Count > 0) framess.Add(data); } catch (Exception e) { Console.WriteLine("An error occured while retrieving frames. Check your arguments."); Console.WriteLine(e); throw; } } IEnumerable<Frame> final = OffsetAnimator.Process(new Rectangle(aPadding, aPadding, aPadding, aPadding), aBgColor, aLoop, framess.ToArray()); framess.ForEach(f => f.ForEach(g => g.Image.Dispose())); if (aPngOutput) #if APNG OutputMethods.OutputAPNG(final, aOutputPath); else #else Console.WriteLine("APNG output not supported in this version; outputting GIF."); #endif OutputMethods.OutputAGIF(final, aOutputPath); }
public CGraphicsEngine() { Map = new WZFile(GameConstants.FileLocation + @"\Map.wz", GameConstants.Variant, true); UI = new WZFile(GameConstants.FileLocation + @"\UI.wz", GameConstants.Variant, true); }
public Rebuild(string name, WZFile oldWZ, WZFile newWZ) : base(name) { o = oldWZ; n = newWZ; }
public static void Export(string inputPath, string outputPath) { List <EquipData> equips = new List <EquipData>(); using (WZFile file = new WZFile(Path.Combine(inputPath, "Character.wz"), WZVariant.GMS, true, WZReadSelection.None)) { foreach (var category in file.MainDirectory) { if (category.Name.EndsWith(".img") || category.Name == "Afterimage" || category.Name == "Face" || category.Name == "Hair") { continue; } foreach (var node in category) { EquipData equip = new EquipData(); equip.MapleID = node.GetID(); equip.MaxSlotQuantity = 1; equip.SalePrice = node["info"].GetInt("price"); equip.Slots = (byte)node["info"].GetInt("tuc"); equip.Strength = (short)node["info"].GetInt("incSTR"); equip.Dexterity = (short)node["info"].GetInt("incDEX"); equip.Intelligence = (short)node["info"].GetInt("incINT"); equip.Luck = (short)node["info"].GetInt("incLUK"); equip.Health = (short)node["info"].GetInt("incHP"); equip.Mana = (short)node["info"].GetInt("incMP"); equip.WeaponAttack = (short)node["info"].GetInt("incPAD"); equip.MagicAttack = (short)node["info"].GetInt("incMAD"); equip.WeaponDefense = (short)node["info"].GetInt("incPDD"); equip.MagicDefense = (short)node["info"].GetInt("incMDD"); equip.Accuracy = (short)node["info"].GetInt("incACC"); equip.Avoidability = (short)node["info"].GetInt("incEVA"); equip.Hands = (short)node["info"].GetInt("incHands"); equip.Speed = (short)node["info"].GetInt("incSpeed"); equip.Jump = (short)node["info"].GetInt("incJump"); equips.Add(equip); } } } equips = equips.OrderBy(e => e.MapleID).ToList(); using (FileStream stream = File.Create(Path.Combine(outputPath, "Equips.bin"))) { using (BinaryWriter writer = new BinaryWriter(stream)) { writer.Write(equips.Count); foreach (EquipData equip in equips) { equip.Save(writer); } } } Logger.Write(LogLevel.Info, "Exported {0} equips.", equips.Count); equips.Clear(); }
public static void Export(string inputPath, string outputPath) { List <MapData> maps = new List <MapData>(); using (WZFile file = new WZFile(Path.Combine(inputPath, "Map.wz"), WZVariant.GMS, true, WZReadSelection.None)) { foreach (var category in file.MainDirectory["Map"]) { if (category.Name == "AreaCode.img") { continue; } foreach (var node in category) { MapData map = new MapData(); map.MapleID = node.GetID(); map.ReturnMapID = node["info"].GetInt("returnMap"); map.ForcedReturnMapID = node["info"].GetInt("forcedReturn"); map.Footholds = new List <MapFootholdData>(); if (node.HasChild("foothold")) { foreach (var footholdNode in node["foothold"]) { } } map.Mobs = new List <MapMobSpawnData>(); map.Npcs = new List <MapNpcSpawnData>(); if (node.HasChild("life")) { foreach (var lifeNode in node["life"]) { string type = lifeNode.GetString("type"); int mapleID = lifeNode.GetInt("id"); short foothold = (short)lifeNode.GetInt("fh"); Point position = new Point(lifeNode.GetInt("x"), lifeNode.GetInt("y")); bool flip = lifeNode.GetInt("f") == 1; bool hide = lifeNode.GetInt("hide") == 1; if (type == "m") { MapMobSpawnData mob = new MapMobSpawnData(); mob.MapleID = mapleID; mob.Foothold = foothold; mob.Positon = position; mob.Flip = flip; mob.Hide = hide; mob.RespawnTime = lifeNode.GetInt("mobTime"); map.Mobs.Add(mob); } else if (type == "n") { MapNpcSpawnData npc = new MapNpcSpawnData(); npc.MapleID = mapleID; npc.Foothold = foothold; npc.Positon = position; npc.Flip = flip; npc.Hide = hide; npc.MinimumClickX = (short)lifeNode.GetInt("rx0"); npc.MaximumClickX = (short)lifeNode.GetInt("rx1"); map.Npcs.Add(npc); } } } map.Portals = new List <MapPortalData>(); if (node.HasChild("portal")) { foreach (var portalNode in node["portal"]) { MapPortalData portal = new MapPortalData(); portal.ID = byte.Parse(portalNode.Name); portal.Label = portalNode.GetString("pn"); portal.DestinationMap = portalNode.GetInt("tm"); portal.DestinationLabel = portalNode.GetString("tn"); portal.Script = portalNode.GetString("script"); portal.Position = new Point(portalNode.GetInt("x"), portalNode.GetInt("y")); map.Portals.Add(portal); } } map.Reactors = new List <MapReactorData>(); if (node.HasChild("reactor")) { foreach (var reactorNode in node["reactor"]) { } } map.Seats = new List <MapSeatData>(); if (node.HasChild("seat")) { foreach (var seatNode in node["seat"]) { } } maps.Add(map); } } } maps = maps.OrderBy(m => m.MapleID).ToList(); using (FileStream stream = File.Create(Path.Combine(outputPath, "Maps.bin"))) { using (BinaryWriter writer = new BinaryWriter(stream)) { writer.Write(maps.Count); foreach (MapData map in maps) { map.Save(writer); } } } Logger.Write(LogLevel.Info, "Exported {0} maps.", maps.Count); maps.Clear(); }
internal WZDirectory(string name, WZObject parent, WZFile file, WZBinaryReader wzbr, long offset) : base(name, parent, file, true, WZObjectType.Directory) { Parse(wzbr, offset); }
public Create(WZFile file) : base(file.Name) { }
private int _f, zM; // f is actually a bool but lets leave it like this for now... #endregion Fields #region Constructors public CGraphicsEngine() { gl = new OpenGL(); Map = new WZFile(FileLocation + @"\Map.wz", Variant, true); UI = new WZFile(FileLocation + @"\UI.wz", Variant, true); }
public static string GetImageBase64String(int itemId, int inventoryType, WZFile wzfile) { if (_itemImageDic.ContainsKey(itemId)) { return(_itemImageDic[itemId]); } WZCanvasProperty wzcp = null; try { switch (inventoryType) { case 1: // 装备 var cat = GetCharacterItemTypeName(itemId); if (string.IsNullOrEmpty(cat)) { return(string.Empty); } wzcp = wzfile.MainDirectory["Character"][cat][string.Concat(itemId.ToString().PadLeft(8, '0'), ".img")]["info"]["icon"] as WZCanvasProperty; break; case 2: // 消耗 case 3: // 消耗 case 4: // 材料 cat = "Consume"; if (inventoryType == 3 || inventoryType == 4) { cat = "Etc"; } var o = wzfile.MainDirectory["Item"][cat][string.Concat(itemId.ToString().PadLeft(8, '0').Substring(0, 4), ".img")][itemId.ToString().PadLeft(8, '0')]["info"]["icon"]; if (o is WZUOLProperty) { var uol = o as WZUOLProperty; // ../../02040002/info/icon if (uol != null) { var path = uol.Value; o = o.Parent; while (path.StartsWith("../")) { o = o.Parent; path = path.Substring(3); } wzcp = o.ResolvePath(path) as WZCanvasProperty; } } else { wzcp = o as WZCanvasProperty; } break; default: break; } if (wzcp == null) { return(string.Empty); } } catch { return(string.Empty); } using (Bitmap m = wzcp.Value) { if (m != null) { using (MemoryStream ms = new MemoryStream()) { m.Save(ms, ImageFormat.Png); byte[] byteImage = ms.ToArray(); var str = Convert.ToBase64String(byteImage); _itemImageDic.Add(itemId, str); return(str); } } } return(string.Empty); }
//TODO: Fade public static void LoadMap(GraphicsDevice graphics, int id, string spawn = "") { if (id == 999999999) // This is used to tell it not to load a new map.. return; sw.Restart(); MapLoaded = false; if (graphics != null) _device = graphics; if (Constants.Globals.Player == null) { Constants.Globals.Player = new MapleCharacter(MapleCharacter.CharacterColor.Light, 20000, 33400, _device); Constants.Globals.Player.SetTop(graphics, 1040002); } MapleMap map = new MapleMap(); map.MapID = id; MapleConsole.Write(MapleConsole.LogType.MESSAGE, "Loading Map \"" + map.FormattedMapID + "\"."); string path = "Map/Map" + map.FormattedMapID.Substring(0, 1) + "/" + map.FormattedMapID + ".img"; WZFile mapWz = new WZFile("Map.wz", WZVariant.GMS, true, WZReadSelection.LowMemory); try { mapWz.ResolvePath(path); } // Make sure the map exists catch (Exception) { MapleConsole.Write(MapleConsole.LogType.ERROR, "Map Doesn't Exist!"); return; } if (!Constants.Game.MuteMusic) MusicEngine.LoadMusic(mapWz.ResolvePath(path + "/info/bgm").ValueOrDefault<string>("")); // Load the music // TODO: Get map name bool boundsDefined = false; try { map.Top = mapWz.ResolvePath(path + "/info/VRTop").ValueOrDefault<int>(0); map.Bottom = mapWz.ResolvePath(path + "/info/VRBottom").ValueOrDefault<int>(0); map.Left = mapWz.ResolvePath(path + "/info/VRLeft").ValueOrDefault<int>(0); map.Right = mapWz.ResolvePath(path + "/info/VRRight").ValueOrDefault<int>(0); boundsDefined = true; } catch (Exception) { // TODO: Find out the coords for maps that don't tell you the camera limit.. //map.Top = 0; //map.Bottom = map.Top + 2009; // I got these values from orbis but I'm not sure whats going to happen on other maps.. } map.Width = map.Right - map.Left; map.Height = map.Bottom - map.Top; map.HideMinimap = mapWz.ResolvePath(path + "/info/hideMinimap").ValueOrDefault<int>(1) == 1 ? true : false; //int miniw = mapWz.ResolvePath(path + "/miniMap/width").ValueOrDefault<int>(0); //int minih = mapWz.ResolvePath(path + "/miniMap/height").ValueOrDefault<int>(0); // Set the global portal animation if its null if (Constants.Globals.PortalAnimation == null) { Dictionary<int, MapleFrame> frames = new Dictionary<int, MapleFrame>(); foreach (WZCanvasProperty frame in mapWz.ResolvePath("MapHelper.img/portal/game/pv")) { WZPointProperty offset = (WZPointProperty)frame["origin"]; frames.Add(int.Parse(frame.Name), new MapleFrame( new MapleCanvas(Tools.BitmapToTexture(_device, frame.Value), new Vector2(-offset.Value.X, -offset.Value.Y)), 100)); // wtf.. The portal frame delay isn't in the wz files?! } Constants.Globals.PortalAnimation = new MapleAnimation(frames); } #region Load Footholds foreach (WZObject fsp in mapWz.ResolvePath(path + "/foothold")) foreach (WZObject fs in fsp) foreach (WZObject fh in fs) { map.Footholds.Add(new MapleFoothold(int.Parse(fh.Name), new Vector2(fh["x1"].ValueOrDie<int>(), fh["y1"].ValueOrDie<int>()), new Vector2(fh["x2"].ValueOrDie<int>(), fh["y2"].ValueOrDie<int>()), int.Parse(fsp.Name))); } #endregion #region Load Backgrounds foreach (WZObject bg in mapWz.ResolvePath(path + "/back")) { if (bg is WZSubProperty && Tools.IsNumeric(bg.Name)) { try { string fPath = "Back/" + bg["bS"].ValueOrDefault<string>("") + ".img/back/" + bg["no"].ValueOrDefault<int>(0); WZCanvasProperty frame = (WZCanvasProperty)mapWz.ResolvePath(fPath); WZPointProperty origin = (WZPointProperty)frame["origin"]; Dictionary<int, MapleFrame> bgs = new Dictionary<int, MapleFrame>(); bool isBack = bg["no"].ValueOrDefault<int>(-1) == 0; if (!Constants.Globals.BackCache.ContainsKey(fPath)) Constants.Globals.BackCache.Add(fPath, Tools.BitmapToTexture(_device, frame.Value)); // TODO: Animated backgrounds.. // Again these algorithms are guessed.. Took me hours to get it realistic.. I pretty much just added random shit onto it XD float newX = bg["x"].ValueOrDefault<int>(0) - bg["rx"].ValueOrDefault<int>(0) / 100 * (map.Width + (_device.Viewport.Width / 2)) + (map.Left * 1.65f); float newY = bg["y"].ValueOrDefault<int>(0) - 100 + bg["ry"].ValueOrDefault<int>(0) / 100 * (map.Height + (_device.Viewport.Height / 2)) + map.Top + (map.Height - 300); // 300.. random if (isBack) { newX = map.Left; newY = map.Top; } bgs.Add(0, new MapleFrame(new MapleCanvas(Constants.Globals.BackCache[fPath], new Vector2(-origin.Value.X, -origin.Value.Y)), 100)); if (newX + -origin.Value.X > map.BackWidth) { int bW = (int)Math.Ceiling(newX); map.BackWidth = bW + -origin.Value.X; } if (-newY + -origin.Value.Y > map.BackHeight) // Somethings up with this o.o why do we need to make newY negative? { int bH = (int)Math.Ceiling(-newY); map.BackHeight = bH + -origin.Value.Y; } map.Backgrounds.Add(new MapleBackground(int.Parse(bg.Name), new MapleAnimation(bgs), new Vector2(newX, newY), bg["type"].ValueOrDie<int>(), isBack)); } catch (Exception) { continue; } } } #endregion #region Load Tiles/Objects foreach (WZObject wLayer in mapWz.ResolvePath(path)) { if (wLayer is WZSubProperty && Tools.IsNumeric(wLayer.Name)) { string tS = ""; List<MapleTile> tiles = new List<MapleTile>(); List<MapleObject> objs = new List<MapleObject>(); bool hasSetBounds = false; foreach (WZSubProperty item in wLayer) { switch (item.Name) { case "info": if (item.ChildCount > 0) tS = item["tS"].ValueOrDefault<string>(""); break; case "obj": foreach (WZObject wObj in item) { string oS = wObj["oS"].ValueOrDie<string>(); string l0 = wObj["l0"].ValueOrDie<string>(); string l1 = wObj["l1"].ValueOrDie<string>(); string l2 = wObj["l2"].ValueOrDie<string>(); string objPath = "Obj/" + oS + ".img/" + l0 + "/" + l1 + "/" + l2; if (l1 == "cherryBlossom") // Skip this shit.. its all over henesys.. continue; Dictionary<int, MapleFrame> frames = new Dictionary<int, MapleFrame>(); int z = wObj["z"].ValueOrDefault<int>(0); foreach (WZObject oF in mapWz.ResolvePath(objPath)) { if (oF is WZCanvasProperty && Tools.IsNumeric(oF.Name)) { try { WZPointProperty offset = null; int frameDelay = 150; if (!Constants.Globals.ObjectCache.ContainsKey(objPath + "/" + oF.Name)) Constants.Globals.ObjectCache.Add(objPath + "/" + oF.Name, Tools.BitmapToTexture(_device, ((WZCanvasProperty)oF).Value)); foreach (WZObject o in oF) if (o.Name == "origin") offset = (WZPointProperty)o; else if (o.Name == "delay") frameDelay = o.ValueOrDefault<int>(150); frames.Add(int.Parse(oF.Name), new MapleFrame(new MapleCanvas(Constants.Globals.ObjectCache[objPath + "/" + oF.Name], (offset != null) ? new Vector2(-offset.Value.X, -offset.Value.Y) : Vector2.Zero), frameDelay)); } catch (Exception ex) { MapleConsole.Write(MapleConsole.LogType.ERROR, "Error loading object \"" + objPath + "\": " + ex.Message); } } } objs.Add(new MapleObject(new Vector2(wObj["x"].ValueOrDefault<int>(0), wObj["y"].ValueOrDefault<int>(0)), z, new MapleAnimation(frames), int.Parse(wLayer.Name))); } break; case "tile": foreach (WZObject wTile in item) { MapleCanvas tileTex = null; Vector2 tileLoc = Vector2.Zero; string tilePath = "Tile/" + tS + ".img/" + wTile["u"].ValueOrDie<string>() + "/" + wTile["no"].ValueOrDefault<int>(0).ToString(); WZCanvasProperty tileCanvas = (WZCanvasProperty)mapWz.ResolvePath(tilePath); if (!Constants.Globals.TileCache.ContainsKey(tilePath)) Constants.Globals.TileCache.Add(tilePath, Tools.BitmapToTexture(_device, tileCanvas.Value)); WZPointProperty tOrigin = (WZPointProperty)tileCanvas["origin"]; tileTex = new MapleCanvas(Constants.Globals.TileCache[tilePath], new Vector2(-tOrigin.Value.X, -tOrigin.Value.Y)); tileLoc = new Vector2(wTile["x"].ValueOrDefault<int>(0), wTile["y"].ValueOrDefault<int>(0)); if (!boundsDefined) { // TODO Fix this.. if (!hasSetBounds) { map.Left = (int)tileLoc.X; map.Right = (int)tileLoc.X + tileTex.Texture.Width; map.Top = (int)tileLoc.Y; map.Bottom = (int)tileLoc.Y + tileTex.Texture.Height; hasSetBounds = true; } else { if (tileLoc.X < map.Left) map.Left = (int)tileLoc.X + -tOrigin.Value.X; if (tileLoc.X + tileTex.Texture.Width > map.Right) map.Right = (int)tileLoc.X + tileTex.Texture.Width + -tOrigin.Value.X; if (tileLoc.Y < map.Top) map.Top = (int)tileLoc.Y + -tOrigin.Value.Y; if (tileLoc.Y + tileTex.Texture.Height > map.Bottom) map.Bottom = (int)tileLoc.Y + tileTex.Texture.Height + -tOrigin.Value.Y; } } tiles.Add(new MapleTile(tileTex, tileLoc, int.Parse(wTile.Name))); } break; default: //lolwut o.o MapleConsole.Write(MapleConsole.LogType.WARNING, "Invalid Layer Property \"" + item.Name + "\"."); break; } } map.Layers.Add(int.Parse(wLayer.Name),new MapleLayer(int.Parse(wLayer.Name), tS, tiles, objs)); } } #endregion MapleConsole.Write(MapleConsole.LogType.WARNING, "Left: " + map.Left.ToString() + " - Top: " + map.Top.ToString() + " - Right: " + map.Right.ToString() + " - Bottom: " + map.Bottom.ToString()); #region Load Portals foreach (WZObject portal in mapWz.ResolvePath(path + "/portal")) { int pType = portal["pt"].ValueOrDefault<int>(-1); int pTo = portal["tm"].ValueOrDefault<int>(999999999); string script = ""; try { script = portal["script"].ValueOrDefault<string>(""); } catch (Exception) { } if (pTo == map.MapID || (pTo == 999999999 && script == "")) pType = 9; map.Portals.Add(new MaplePortal(portal["pn"].ValueOrDefault<string>(""), script, portal["tn"].ValueOrDefault<string>(""), new Vector2(portal["x"].ValueOrDefault<int>(0), portal["y"].ValueOrDefault<int>(0)), pTo, pType)); } #endregion #region Load Life WZFile npcWz = new WZFile("Npc.wz", WZVariant.GMS, true, WZReadSelection.LowMemory); WZFile mobWz = new WZFile("Mob.wz", WZVariant.GMS, true, WZReadSelection.LowMemory); foreach (WZObject life in mapWz.ResolvePath(path + "/life")) { if (life is WZSubProperty) { string type = life["type"].ValueOrDefault<string>(""); int lifeId = int.Parse(life["id"].ValueOrDie<string>()); if (lifeId == 9300018) continue; switch (type) { case "n": // NPC string lifePath = lifeId.ToString() + ".img"; Dictionary<int, MapleFrame> ani = new Dictionary<int, MapleFrame>(); try { foreach (WZObject f in npcWz.ResolvePath(lifePath + "/stand")) { if (f is WZCanvasProperty) { if (!Constants.Globals.LifeCache.ContainsKey(lifePath + "/stand/" + f.Name)) Constants.Globals.LifeCache.Add(lifePath + "/stand/" + f.Name, Tools.BitmapToTexture(_device, f.ValueOrDie<System.Drawing.Bitmap>())); WZPointProperty origin = (WZPointProperty)npcWz.ResolvePath(lifePath + "/stand/" + f.Name)["origin"]; int delay = 100; try { delay = f["delay"].ValueOrDefault<int>(100); } catch (Exception) { } ani.Add(int.Parse(f.Name), new MapleFrame(new MapleCanvas(Constants.Globals.LifeCache[lifePath + "/stand/" + f.Name], new Vector2(-origin.Value.X, -origin.Value.Y)), delay)); } } } catch (Exception) { continue; } bool hide = false; try { hide = life["hide"].ValueOrDefault<int>(1) == 0; } catch (Exception) { } int Layer = map.Footholds.Where(o => o.ID == life["fh"].ValueOrDefault<int>(7)).ToArray<MapleFoothold>()[0].Layer; map.Npcs.Add(new MapleNpc(lifeId, new MapleAnimation(ani), new Vector2(life["x"].ValueOrDefault<int>(0), life["cy"].ValueOrDefault<int>(0) + 0), Layer, !hide)); // Why is this 10px off? o.o break; case "m": // Mob break; default: // o.o MapleConsole.Write(MapleConsole.LogType.WARNING, "Invalid Life Type \"" + type + "\"."); break; } } } #endregion // Load strings from string.wz.. #region Load Strings #endregion if (!map.HideMinimap) { try { InterfaceEngine.MiniMap = new MapleMinimap(map, Tools.BitmapToTexture(_device, mapWz.ResolvePath(path + "/miniMap/canvas").ValueOrDie<System.Drawing.Bitmap>())); } catch (Exception) { map.HideMinimap = true; } } CurrentMap = map; Camera.Set(map.Left, map.Top); // Set camera inside map bounds.. TODO: Spawn Points Vector2 pOrigin = new Vector2(Constants.Globals.PortalAnimation.Frames[0].Canvas.Origin.X / 2, Constants.Globals.PortalAnimation.Frames[0].Canvas.Origin.Y / 2); if (spawn != "") Constants.Globals.Player.Position = map.Portals.Where(o => o.PortalName == spawn).ToArray<MaplePortal>()[0].Location + pOrigin; else Constants.Globals.Player.Position = map.Portals.Where(o => o.PortalName == "sp").ToArray<MaplePortal>()[0].Location + pOrigin; sw.Stop(); MapleConsole.Write(MapleConsole.LogType.MESSAGE, "Map loaded in " + sw.ElapsedMilliseconds.ToString() + "ms."); Constants.Globals.Player.CenterCamera(); MapLoaded = true; }
private static void MainMain(string[] args) { #region getopt bool printHelp = false; string aWzInPath = null; bool aWzNamesEnc = true; bool aPngOutput = false; WZVariant aWzVer = (WZVariant)int.MinValue; string aOutputPath = null; Color aBgColor = Color.Black; LoopType aLoop = LoopType.NoLoop; int aPadding = 10; // input, input-wzfile, input-wzpath, input-wzver, output, output-path, background-color, padding OptionSet set = new OptionSet(); set.Add("iwzp=|input-wzpath=", "The path of the animation or image. Required", s => aWzInPath = s); set.Add("iwzv=|input-wzver=", "The WZ key to use when decoding the WZ. Required", s => aWzVer = (WZVariant)Enum.Parse(typeof(WZVariant), s)); set.Add("iwzne|input-wz-names-not-encrypted", "Flag if WZ image names are not encrypted. ", s => aWzNamesEnc = false); set.Add("o=|of=|output-format=", "The method of output: (a)png or gif", s => { switch (s.ToLower()) { case "png": aPngOutput = true; break; case "gif": aPngOutput = false; break; default: throw new ArgumentException("output must be either png or gif"); } }); set.Add("op=|output-path=", "The path to write the output, (A)PNG or GIF, to", s => aOutputPath = s); set.Add("abg=|a-background-color=", "The background color of the animated output. Default is black. Ignored if there is no animation.", s => aBgColor = Color.FromArgb(int.Parse(s))); set.Add("ap=|a-padding=", "The amount of padding in pixels to pad the animated output with. Default is 10. Ignored if there is no animation.", s => aPadding = int.Parse(s)); set.Add("al=|a-looping=", "The method to loop multi-animations with. Default is NoLoop. Ignored if there is no animation.", s => aLoop = (LoopType)Enum.Parse(typeof(LoopType), s, true)); set.Add("?|h|help", "Shows help", s => printHelp = true); set.Parse(args); #endregion #region check params printHelp |= aWzInPath == null || aWzVer == (WZVariant)int.MinValue || aOutputPath == null; if (printHelp) { PrintHelp(set); return; } #endregion string[] wzpaths = aWzInPath.Split('*'); List <List <Frame> > framess = new List <List <Frame> >(); string newPath = null, cWzPath = null; WZFile wz = null; foreach (string[] split in wzpaths.Select(wzpath => wzpath.Split('?'))) { string inPath; if (newPath != null && split.Length == 1) { inPath = split[0]; } else { newPath = split[0]; inPath = split[1]; } if (cWzPath != newPath && wz != null) { wz.Dispose(); } #region wz parsing if (cWzPath != newPath) { wz = new WZFile(newPath, aWzVer, aWzNamesEnc); } cWzPath = newPath; #endregion #region getting single image WZCanvasProperty wzcp = wz.ResolvePath(inPath).ResolveUOL() as WZCanvasProperty; if (wzcp != null) { Bitmap b = wzcp.Value; if (aPngOutput) { OutputMethods.OutputPNG(b, aOutputPath); } else { OutputMethods.OutputGIF(b, aOutputPath); } return; } #endregion try { List <Frame> data = InputMethods.InputWz(wz, inPath); if (data.Count > 0) { framess.Add(data); } } catch (Exception e) { Console.WriteLine("An error occured while retrieving frames. Check your arguments."); Console.WriteLine(e); throw; } } IEnumerable <Frame> final = OffsetAnimator.Process(new Rectangle(aPadding, aPadding, aPadding, aPadding), aBgColor, aLoop, framess.ToArray()); framess.ForEach(f => f.ForEach(g => g.Image.Dispose())); if (aPngOutput) #if APNG { OutputMethods.OutputAPNG(final, aOutputPath); } else #else { Console.WriteLine("APNG output not supported in this version; outputting GIF."); } #endif { OutputMethods.OutputAGIF(final, aOutputPath); } }
public ExtractDamageSkinNumbers(string fileName, string outputLocation) { int count = 0; //var dmgSkins = JsonConvert.DeserializeObject<List<DamageSkin>>(File.ReadAllText(jsonLocation)); WZFile xz = new WZFile(fileName, WZVariant.MSEA, false); WZSubProperty damageSkinNumberImg = (WZSubProperty)xz.MainDirectory["BasicEff.img"]["damageSkin"]; foreach (var numberType in damageSkinNumberImg) { Bitmap dmgSkinNumberPng = null; //foreach (var numberImg in numberType) //{ // foreach (var number in numberImg) // { // if (!(number is WZCanvasProperty)) // { // break; // } // WZCanvasProperty test = (WZCanvasProperty)number; // string[] pathNames = number.Path.Split('/'); // int itemId = 0; // if (numberType.HasChild("ItemID")) // { // itemId = numberType["ItemID"].ValueOrDefault<Int32>(Int32.Parse(pathNames[3])); // } // if (numberType["NoRed0"]["3"].HasChild("_inlink")) // { // break; // //string path = numberType["NoCri1"]["5"]["_inlink"].ValueOrDie<string>(); // //dmgSkinNumberPng = xz.ResolvePath($"BasicEff.img/{path}").ValueOrDie<Bitmap>(); // } // else // { // dmgSkinNumberPng = numberType["NoRed0"]["3"].ValueOrDie<Bitmap>(); // } // //Directory.CreateDirectory($@"{outputLocation}\"); // if (numberType.HasChild("ItemID")) // { // dmgSkinNumberPng.Save($@"{outputLocation}\{numberType.Name}_{itemId}.png", ImageFormat.Png); // } // else // { // dmgSkinNumberPng.Save($@"{outputLocation}\{numberType.Name}.png", ImageFormat.Png); // } // Console.WriteLine($"Exported damage skin - {pathNames[3]}"); // } //} if (numberType.HasChild("ItemID")) { Console.WriteLine("hi"); foreach (var numberImg in numberType) { foreach (var number in numberImg) { if (!(number is WZCanvasProperty)) { break; } WZCanvasProperty test = (WZCanvasProperty)number; string[] pathNames = number.Path.Split('/'); int itemId = numberType["ItemID"].ValueOrDefault <Int32>(Int32.Parse(pathNames[3])); if (number.HasChild("_inlink")) { break; string path = number["_inlink"].ValueOrDie <string>(); dmgSkinNumberPng = xz.ResolvePath($"BasicEff.img/{path}").ValueOrDie <Bitmap>(); } else { dmgSkinNumberPng = test.Value; } Directory.CreateDirectory($@"{outputLocation}\{pathNames[3]}_{itemId.ToString()}\{pathNames[4]}"); dmgSkinNumberPng.Save($@"{outputLocation}\{pathNames[3]}_{itemId.ToString()}\{pathNames[4]}\{pathNames[5]}.png", ImageFormat.Png); Console.WriteLine("Exported damage skin"); } } } else { foreach (var numberImg in numberType) { foreach (var number in numberImg) { if (!(number is WZCanvasProperty)) { break; } WZCanvasProperty test = (WZCanvasProperty)number; string[] pathNames = number.Path.Split('/'); if (number.HasChild("_inlink")) { string path = number["_inlink"].ValueOrDie <string>(); dmgSkinNumberPng = xz.ResolvePath($"BasicEff.img/{path}").ValueOrDie <Bitmap>(); } else { dmgSkinNumberPng = test.Value; } Directory.CreateDirectory($@"{outputLocation}\{pathNames[3]}\{pathNames[4]}"); dmgSkinNumberPng.Save($@"{outputLocation}\{pathNames[3]}\{pathNames[4]}\{pathNames[5]}.png", ImageFormat.Png); Console.WriteLine($"Exported damage skin - {pathNames[3]}"); } } } count++; } Console.WriteLine($"Successfully dumped {count.ToString()} number of damage skins"); Console.ReadKey(); }
public static void Export(string inputPath, string outputPath) { List <SkillData> skills = new List <SkillData>(); using (WZFile file = new WZFile(Path.Combine(inputPath, "Skill.wz"), WZVariant.GMS, true, WZReadSelection.None)) { foreach (var jobNode in file.MainDirectory) { if (jobNode.Name == "MCGuardian.img" || jobNode.Name == "MCSkill.img" || jobNode.Name == "MobSkill.img" || jobNode.Name == "BFSkill.img" || jobNode.Name == "ItemSkill.img") // TODO: Deal with these later. { continue; } foreach (var skillNode in jobNode["skill"]) { foreach (var levelNode in skillNode["level"]) { SkillData skill = new SkillData(); skill.MapleID = skillNode.GetID(); skill.Level = byte.Parse(levelNode.Name); skill.MobCount = (byte)levelNode.GetInt("mobCount"); skill.HitCount = (byte)levelNode.GetInt("attackCount"); skill.Range = (ushort)levelNode.GetInt("range"); skill.Duration = 0; skill.MPCost = (ushort)skillNode.GetInt("mpCon"); skill.HPCost = (byte)skillNode.GetInt("hpCon"); skill.Damage = 0; skill.FixedDamage = 0; // TODO: The 'damage' property is uncastable for some reason. Check why. skill.CriticalDamage = 0; skill.Mastery = 0; skill.OptionalItemCost = 0; skill.ItemCost = levelNode.GetInt("itemCon"); skill.ItemCount = (byte)levelNode.GetInt("itemConNo"); skill.BulletCost = (byte)levelNode.GetInt("bulletConsume"); skill.MoneyCost = (ushort)levelNode.GetInt("moneyCon"); skill.Parameter1 = levelNode.GetInt("x"); skill.Parameter2 = levelNode.GetInt("y"); skill.Speed = (byte)levelNode.GetInt("speed"); skill.Jump = (byte)levelNode.GetInt("jump"); skill.Strength = 0; skill.WeaponAttack = 0; skill.MagicAttack = 0; skill.WeaponDefense = 0; skill.MagicDefense = 0; skill.Accuracy = 0; skill.Avoidance = 0; skill.HP = (byte)levelNode.GetInt("hp"); skill.MP = (byte)levelNode.GetInt("mp"); skill.Prop = (byte)levelNode.GetInt("prop"); skill.Morph = 0; skill.LeftTopX = 0; // lt skill.LeftTopY = 0; // lt skill.RightBottomX = 0; // rb skill.RightBottomY = 0; // rb skill.Cooldown = (ushort)levelNode.GetInt("time"); skills.Add(skill); } } } skills = skills.OrderBy(m => m.MapleID).ToList(); using (FileStream stream = File.Create(Path.Combine(outputPath, "Skills.bin"))) { using (BinaryWriter writer = new BinaryWriter(stream)) { writer.Write(skills.Count); foreach (SkillData skill in skills) { skill.Save(writer); } } } Logger.Write(LogLevel.Info, "Exported {0} skills.", skills.Count); skills.Clear(); } }
private static void Run(string inWz, string outPath, WZVariant wzVar, bool initialEnc) { Console.WriteLine("Input .wz: {0}{1}Output .nx: {2}", Path.GetFullPath(inWz), Environment.NewLine, Path.GetFullPath(outPath)); Stopwatch swOperation = new Stopwatch(); Stopwatch fullTimer = new Stopwatch(); Action <string> reportDone = str => { Console.WriteLine("done. E{0} T{1}", swOperation.Elapsed, fullTimer.Elapsed); swOperation.Restart(); Console.Write(str); }; fullTimer.Start(); swOperation.Start(); Console.Write("Parsing input WZ... ".PadRight(31)); WZReadSelection rFlags = WZReadSelection.EagerParseImage | WZReadSelection.EagerParseStrings; if (!dumpImg) { rFlags |= WZReadSelection.NeverParseCanvas; } using (WZFile wzf = new WZFile(inWz, wzVar, initialEnc, rFlags)) using ( FileStream outFs = new FileStream(outPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None)) using (BinaryWriter bw = new BinaryWriter(outFs)) { DumpState state = new DumpState(); reportDone("Writing header... ".PadRight(31)); bw.Write(PKG4); bw.Write(new byte[(4 + 8) * 4]); reportDone("Writing nodes... ".PadRight(31)); outFs.EnsureMultiple(4); ulong nodeOffset = (ulong)bw.BaseStream.Position; List <WZObject> nodeLevel = new List <WZObject> { wzf.MainDirectory }; while (nodeLevel.Count > 0) { WriteNodeLevel(ref nodeLevel, state, bw); } ulong stringOffset; uint stringCount = (uint)state.Strings.Count; { reportDone("Writing string data...".PadRight(31)); Dictionary <uint, string> strings = state.Strings.ToDictionary(kvp => kvp.Value, kvp => kvp.Key); ulong[] offsets = new ulong[stringCount]; for (uint idx = 0; idx < stringCount; ++idx) { outFs.EnsureMultiple(2); offsets[idx] = (ulong)bw.BaseStream.Position; WriteString(strings[idx], bw); } outFs.EnsureMultiple(8); stringOffset = (ulong)bw.BaseStream.Position; for (uint idx = 0; idx < stringCount; ++idx) { bw.Write(offsets[idx]); } } ulong bitmapOffset = 0UL; uint bitmapCount = 0U; if (dumpImg) { reportDone("Writing canvas data...".PadRight(31)); bitmapCount = (uint)state.Canvases.Count; ulong[] offsets = new ulong[bitmapCount]; long cId = 0; foreach (WZCanvasProperty cNode in state.Canvases) { outFs.EnsureMultiple(8); offsets[cId++] = (ulong)bw.BaseStream.Position; WriteBitmap(cNode, bw); } outFs.EnsureMultiple(8); bitmapOffset = (ulong)bw.BaseStream.Position; for (uint idx = 0; idx < bitmapCount; ++idx) { bw.Write(offsets[idx]); } } ulong soundOffset = 0UL; uint soundCount = 0U; if (dumpSnd) { reportDone("Writing MP3 data... ".PadRight(31)); soundCount = (uint)state.MP3s.Count; ulong[] offsets = new ulong[soundCount]; long cId = 0; foreach (WZAudioProperty mNode in state.MP3s) { outFs.EnsureMultiple(8); offsets[cId++] = (ulong)bw.BaseStream.Position; WriteMP3(mNode, bw); } outFs.EnsureMultiple(8); soundOffset = (ulong)bw.BaseStream.Position; for (uint idx = 0; idx < soundCount; ++idx) { bw.Write(offsets[idx]); } } reportDone("Writing linked node data... ".PadRight(31)); byte[] uolReplace = new byte[16]; foreach (KeyValuePair <WZUOLProperty, Action <BinaryWriter, byte[]> > pair in state.UOLs) { WZObject result = pair.Key.FinalTarget; if (result == null) { continue; } bw.BaseStream.Position = (long)(nodeOffset + state.GetNodeID(result) * 20 + 4); bw.BaseStream.Read(uolReplace, 0, 16); pair.Value(bw, uolReplace); } reportDone("Finalising... ".PadRight(31)); bw.Seek(4, SeekOrigin.Begin); bw.Write((uint)state.Nodes.Count); bw.Write(nodeOffset); bw.Write(stringCount); bw.Write(stringOffset); bw.Write(bitmapCount); bw.Write(bitmapOffset); bw.Write(soundCount); bw.Write(soundOffset); reportDone("Completed!"); } }
public Copy(WZFile source, int offset, int size) { this.source = source; this.offset = offset; this.size = size; }
public MapleCharacter(CharacterColor c, int face, int hair, GraphicsDevice graphics) { try { SkinColor = c; WZFile charWz = new WZFile("Character.wz", WZVariant.GMS, true, WZReadSelection.LowMemory); string path = ((int)SkinColor).ToString("00000000") + ".img"; WZCanvasProperty h = (WZCanvasProperty)charWz.ResolvePath(((int)SkinColor).ToString("00010000") + ".img/front/head"); WZPointProperty o = (WZPointProperty)h["origin"]; Head = new MapleCanvas(Tools.BitmapToTexture(graphics, h.Value), new Vector2(-o.Value.X, -o.Value.Y)); Bounds.X = -o.Value.X; Bounds.Y = -o.Value.Y; WZPointProperty neckPos = (WZPointProperty)h["map"]["neck"]; NeckPosition = new Vector2(neckPos.Value.X, neckPos.Value.Y); foreach (CharacterState state in Enum.GetValues(typeof(CharacterState))) // Loop through the states and get the frames for each animation.. { Dictionary<int, MapleFrame> bodyState = new Dictionary<int, MapleFrame>(); Dictionary<int, MapleFrame> armState = new Dictionary<int, MapleFrame>(); foreach (WZObject frame in charWz.ResolvePath(path + "/" + States[(int)state])) if (Tools.IsNumeric(frame.Name)) { int delay = frame["delay"].ValueOrDefault<int>(250); Vector2 bodyNavel = Vector2.Zero; Vector2 frameNeckPos = Vector2.Zero; bool ani = Ani[(int)state]; foreach (WZObject part in frame) { WZObject p = part; if (p is WZCanvasProperty) { Texture2D PartTexture = Tools.BitmapToTexture(graphics, p.ValueOrDie<System.Drawing.Bitmap>()); WZPointProperty origin = (WZPointProperty)p["origin"]; switch (p.Name) { case "body": WZPointProperty navel = (WZPointProperty)p["map"]["navel"]; WZPointProperty neck = (WZPointProperty)p["map"]["neck"]; Navel.Add(States[(int)state] + frame.Name, new Vector2(-navel.Value.X, -navel.Value.Y)); bodyNavel = new Vector2(navel.Value.X, navel.Value.Y); frameNeckPos = new Vector2(-neck.Value.X, -neck.Value.Y); Vector2 BodyLoc = new Vector2(-origin.Value.X + frameNeckPos.X + NeckPosition.X, -origin.Value.Y + frameNeckPos.Y + NeckPosition.Y); bodyState.Add(bodyState.Count, new MapleFrame(new MapleCanvas(PartTexture, BodyLoc), delay)); break; case "arm": WZPointProperty armNavel = (WZPointProperty)p["map"]["navel"]; Vector2 ArmLoc = new Vector2((-origin.Value.X + -armNavel.Value.X - -bodyNavel.X) + frameNeckPos.X + NeckPosition.X, (-origin.Value.Y + -armNavel.Value.Y - -bodyNavel.Y) + frameNeckPos.Y + NeckPosition.Y); armState.Add(armState.Count, new MapleFrame(new MapleCanvas(PartTexture, ArmLoc), delay)); break; } } } if (ani == false) break; } Body.Add(state, new MapleAnimation(bodyState, true)); Arm.Add(state, new MapleAnimation(armState)); if (Hair.ContainsKey(HairStates[(int)state])) continue; // Hair string hairPath = "Hair/" + hair.ToString("00000000") + ".img"; Dictionary<int, MapleFrame> hf = new Dictionary<int, MapleFrame>(); Dictionary<int, MapleFrame> hfh = new Dictionary<int, MapleFrame>(); WZCanvasProperty hairCanvas = (WZCanvasProperty)charWz.ResolvePath(hairPath + "/" + HairStates[(int)state] + "/hairOverHead"); WZPointProperty hairOrigin = (WZPointProperty)hairCanvas["origin"]; WZCanvasProperty hhatCanvas = (WZCanvasProperty)charWz.ResolvePath(hairPath + "/" + HairStates[(int)state] + "/hair"); WZPointProperty hhatOrigin = (WZPointProperty)hhatCanvas["origin"]; hf.Add(hf.Count, new MapleFrame(new MapleCanvas(Tools.BitmapToTexture(graphics, hairCanvas.Value), new Vector2(-hairOrigin.Value.X - 2, -hairOrigin.Value.Y - 5)), 100)); hfh.Add(hfh.Count, new MapleFrame(new MapleCanvas(Tools.BitmapToTexture(graphics, hhatCanvas.Value), new Vector2(-hhatOrigin.Value.X - 2, -hhatOrigin.Value.Y - 5)), 100)); Hair.Add(HairStates[(int)state], new MapleAnimation(hf)); HatHair.Add(HairStates[(int)state], new MapleAnimation(hfh)); } // Face string facePath = "Face/" + face.ToString("00000000") + ".img"; Dictionary<int, MapleFrame> ff = new Dictionary<int, MapleFrame>(); foreach (WZObject fs in charWz.ResolvePath(facePath + "/default")) // TODO Other expressions { if (fs is WZCanvasProperty && fs.Name == "face") { WZPointProperty faceOrigin = (WZPointProperty)fs["origin"]; ff.Add(ff.Count, new MapleFrame(new MapleCanvas(Tools.BitmapToTexture(graphics, fs.ValueOrDie<System.Drawing.Bitmap>()), new Vector2(-faceOrigin.Value.X - 3, -faceOrigin.Value.Y + 7)), 0)); } } Face = new MapleAnimation(ff); } catch (Exception ex) { MapleConsole.Write(MapleConsole.LogType.ERROR, "Error initializing character: " + ex.Message); MapleConsole.Write(MapleConsole.LogType.WARNING, "StackTrace", ex.StackTrace); } }