private void AddGridRow(DataGridView grid, object wzObject) { int id; string name = null; WzObject png; string properties = GetAllProperties(wzObject); if (wzObject is WzImage img) { id = int.Parse(Path.GetFileNameWithoutExtension(img.Name)); WzImageProperty link = img.GetFromPath("info/link"); if (link is WzStringProperty) { string linkName = ((WzStringProperty) link).Value; img = ((WzDirectory) img.Parent).GetChildImages().Find(p => p.Name.Equals(linkName + ".img")); if (img == null) return; } png = img.GetFromPath("stand/0"); if (img.WzFileParent.Name.StartsWith("Npc")) { // icon path like: '{ID}/stand/0' name = StringWz.GetNpc(id); } else if (img.WzFileParent.Name.StartsWith("Mob")) { // icon path like: '{ID}/(move|stand|fly)/0' name = StringWz.GetMob(id); if (png == null) { png = img.GetFromPath("fly/0") ?? img.GetFromPath("move/0"); // attempt to get image of the monster } } else if (img.WzFileParent.Name.StartsWith("Reactor")) { name = img.GetFromPath("action")?.GetString(); png = img.GetFromPath("0/0"); } else if (img.WzFileParent.Name.StartsWith("Map")) { name = StringWz.GetFieldFullName(id); png = img.GetFromPath("miniMap/canvas"); } else { // for breadcrumb like: '{ID}.img/info/icon' if (ItemConstants.IsEquip(id)) name = StringWz.GetEqp(id); else if (ItemConstants.IsPet(id)) name = StringWz.GetPet(id); png = img.GetFromPath("info/icon"); } } else if (wzObject is WzSubProperty subProperty) { id = int.Parse(subProperty.Name); if (subProperty.WzFileParent.Name.StartsWith("Skill")) { name = StringWz.GetSkill(subProperty.Name); properties = GetAllProperties(subProperty); png = subProperty.GetFromPath("icon"); } else { // for path like: 'category.img/{ID}/info/icon' (Etc.wz) id = int.Parse(subProperty.Name); if (ItemConstants.IsEtc(id)) name = StringWz.GetEtc(id); else if (ItemConstants.IsCash(id)) name = StringWz.GetCash(id); else if (ItemConstants.IsChair(id)) name = StringWz.GetChair(id); else if (ItemConstants.IsConsume(id)) name = StringWz.GetConsume(id); png = subProperty.GetFromPath("info/icon"); } } else return; if (grid.Parent is DataViewport dv) { ((List<BinData>)dv.Tag)?.Add(new BinData(id, png?.GetBitmap(), name, properties)); } grid.Rows.Add(id, png?.GetBitmap(), name, properties); }
private void LoadWzData(int selectedRoot, WzMapleVersion encryption, string directory) { if (selectedRoot == -1) { var result = MessageBox.Show("You have opted to load data for every tab. Are you sure you want to do this?", "Warning", MessageBoxButtons.YesNo); if (result != DialogResult.Yes) return; loadAll = true; for (int i = 0; i <= 10; i++) { try { TabControlMain.SelectedIndex = i; LoadWzData(i, encryption, directory); } catch (Exception e) { MessageBox.Show($"Could not load tab {i}: {e.Message}"); } } BtnSave_Click(null, new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0)); return; } switch (selectedRoot) { case 0: // Equips { // var selectedTab = EquipTab.SelectedIndex; var file = Wz.Character.LoadFile($@"{directory}\Character", encryption, false); List<WzImage> children = file.WzDirectory.GetChildImages(); children.Sort((a, b) => a.Name.CompareTo(b.Name)); foreach (var img in children) { string sId = Path.GetFileNameWithoutExtension(img.Name); if (int.TryParse(sId, out int itemId)) { var name = StringWz.GetEqp(itemId); var properties = GetAllProperties(img); var icon = img.GetFromPath("info/icon"); Bitmap image = null; DataViewport dv; int bodyPart = itemId / 10000; switch (bodyPart) { default: continue; case int n when (n == 3 || n == 4): { image = (img.GetFromPath("default/hairOverHead") ?? img.GetFromPath("default/hair"))?.GetBitmap(); var hairBelowBody = (img.GetFromPath("default/hairBelowBody") as WzCanvasProperty)?.GetBitmap(); if (image != null && hairBelowBody != null) { var merge = new Bitmap(Math.Max(image.Width, hairBelowBody.Width), Math.Max(image.Height, hairBelowBody.Height)); using (var g = Graphics.FromImage(merge)) { g.DrawImage(hairBelowBody, Point.Empty); g.DrawImage(image, Point.Empty); } image = merge; } dv = EquipHairsView; break; } case int n when (n == 2 || n == 5): image = img.GetFromPath("blink/0/face")?.GetBitmap(); dv = EquipFacesView; break; case int n when (n >= 130 && n <= 170): dv = EquipWeaponsView; break; case int n when ((n >= 101 && n <= 103) || (n >= 112 && n <= 114)): dv = EquipAccessoryView; break; case 100: dv = EquipCapsView; break; case 105: dv = EquipsOverallsView; break; case 104: dv = EquipTopsView; break; case 106: dv = EquipPantsView; break; case 107: dv = EquipShoesView; break; case 110: dv = EquipCapesView; break; case 108: dv = EquipGlovesView; break; case 111: dv = EquipRingsView; break; case 109: dv = EquipShieldsView; break; case int n when (n is 190 or 191 || n == 193): dv = EquipMountsView; break; } if (dv == null) continue; image ??= icon?.GetBitmap(); ((List<BinData>) dv.Tag)?.Add(new BinData(itemId, image, name, properties)); dv.GridView.Rows.Add(itemId, image, name, properties); } } Wz.Character.Dispose(); break; } case 1: // Use case 2: // Setup case 3: // Etc case 4: // Cash case 9: // Pets { var file = Wz.Item.LoadFile($@"{directory}\Item", encryption, false); var children = file.WzDirectory.GetChildImages(); children.Sort((a, b) => String.Compare(a.Name, b.Name, StringComparison.Ordinal)); void AddRow(WzImage wz, DataViewport dv) => wz.WzProperties.ForEach(imgs => AddGridRow(dv.GridView, imgs)); foreach (var img in children) { string name = Path.GetFileNameWithoutExtension(img.Name); if (int.TryParse(name, out int itemId)) { switch (selectedRoot) { case 1: switch (itemId) { default: if (ItemConstants.IsConsume(itemId)) AddRow(img, UseConsumeView); break; case 204: case 234: AddRow(img, UseScrollsView); break; case 206: case 207: case 233: AddRow(img, UseProjectileView); break; } break; case 2 when itemId == 301 || itemId == 399: AddRow(img, (itemId == 301 ? SetupChairsView : SetupOthersView)); break; case 3 when ItemConstants.IsEtc(itemId): AddRow(img, EtcView); break; case 4 when ItemConstants.IsCash(itemId): AddRow(img, CashView); break; case 9 when ItemConstants.IsPet(itemId): AddGridRow(PetsView.GridView, img); break; } } } Wz.Item.Dispose(); break; } case 5: { // Map var file = Wz.Map.LoadFile($@"{directory}\Map", encryption, false); var children = file.WzDirectory.GetChildImages(); children.Sort((a, b) => String.Compare(a.Name, b.Name, StringComparison.Ordinal)); foreach (var img in children) { string sMapId = Path.GetFileNameWithoutExtension(img.Name); if (!int.TryParse(sMapId, out int mapId)) continue; img.ParseImage(); AddGridRow(MapsView.GridView, img); } Wz.Map.Dispose(); break; } case 6: { // Mob var file = Wz.Mob.LoadFile($@"{directory}\Mob", encryption, false); var children = file.WzDirectory.GetChildImages(); children.Sort((a, b) => String.Compare(a.Name, b.Name, StringComparison.Ordinal)); foreach (var img in children) { AddGridRow(MobsView.GridView, img); } Wz.Mob.Dispose(); break; } case 7: { // Skills var file = Wz.Skill.LoadFile($@"{directory}\Skill", encryption, false); var children = file.WzDirectory.GetChildImages(); foreach (var img in children) { string name = Path.GetFileNameWithoutExtension(img.Name); if (!int.TryParse(name, out _)) continue; WzImageProperty tree = img.GetFromPath("skill"); if (!(tree is WzSubProperty)) continue; List<WzImageProperty> skills = tree.WzProperties; skills.ForEach(s => AddGridRow(SkillsView.GridView, s)); } Wz.Skill.Dispose(); break; } case 8: { // NPCs var file = Wz.Npc.LoadFile($@"{directory}\Npc", encryption, false); var children = file.WzDirectory.GetChildImages(); children.Sort((a, b) => String.Compare(a.Name, b.Name, StringComparison.Ordinal)); foreach (var img in children) { AddGridRow(NPCView.GridView, img); } Wz.Npc.Dispose(); break; } case 10: { // Reactors var file = Wz.Reactor.LoadFile($@"{directory}\Reactor", encryption, false); var children = file.WzDirectory.GetChildImages(); children.Sort((a, b) => String.Compare(a.Name, b.Name, StringComparison.Ordinal)); foreach (var img in children) { AddGridRow(ReactorView.GridView, img); } Wz.Reactor.Dispose(); break; } } }