private WzVirtualNode RebuildWzFile(Wz_File wzFile) { //分组 List <Wz_File> subFiles = new List <Wz_File>(); WzVirtualNode topNode = new WzVirtualNode(wzFile.Node); foreach (var childNode in wzFile.Node.Nodes) { var subFile = childNode.GetValue <Wz_File>(); if (subFile != null) //wz子文件 { subFiles.Add(subFile); } else //其他 { topNode.AddChild(childNode, true); } } if (wzFile.Type == Wz_Type.Base) { foreach (var grp in subFiles.GroupBy(f => f.Type)) { WzVirtualNode fileNode = new WzVirtualNode(); fileNode.Name = grp.Key.ToString(); foreach (var file in grp) { fileNode.Combine(file.Node); } topNode.AddChild(fileNode); } } return(topNode); }
/// <summary> /// wz1节点选中事件。 /// </summary> public void OnSelectedNode1Changed(object sender, WzNodeEventArgs e) { if (PluginEntry.Context.SelectedTab != PluginEntry.Tab || e.Node == null || this.btnLock.Checked) { return; } Wz_File file = e.Node.GetNodeWzFile(); if (file == null) { return; } switch (file.Type) { case Wz_Type.Character: //读取装备 Wz_Image wzImg = e.Node.GetValue <Wz_Image>(); if (wzImg != null && wzImg.TryExtract()) { this.SuspendUpdateDisplay(); LoadPart(wzImg.Node); this.ResumeUpdateDisplay(); } break; } }
void btnItem_Click(object sender, EventArgs e) { btnItemMapRender.Enabled = false; Wz_Node node = Context.SelectedNode1; if (node != null) { Wz_Image img = node.Value as Wz_Image; Wz_File wzFile = node.GetNodeWzFile(); if (img != null && img.TryExtract()) { if (wzFile == null || wzFile.Type != Wz_Type.Map) { if (MessageBoxEx.Show("所选Img不属于Map.wz,是否继续?", "提示", MessageBoxButtons.OKCancel) != DialogResult.OK) { goto exit; } } StringLinker sl = this.Context.DefaultStringLinker; if (!sl.HasValues) //生成默认stringLinker { sl = new StringLinker(); sl.Load(PluginManager.FindWz(Wz_Type.String).GetValueEx <Wz_File>(null)); } //开始绘制 Thread thread = new Thread(() => { #if !DEBUG try { #endif FrmMapRender frm = new MapRender.FrmMapRender(img); frm.StringLinker = sl; frm.Run(); #if !DEBUG } catch (Exception ex) { MessageBoxEx.Show(ex.ToString(), "MapRender"); } #endif }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); goto exit; } } MessageBoxEx.Show("没有选择一个map的img", "MapRender"); exit: btnItemMapRender.Enabled = true; }
private void OutputFile(Wz_File fileNew, Wz_File fileOld, Wz_Type type, List <CompareDifference> diffLst, string outputDir) { OutputFile(new List <Wz_File>() { fileNew }, new List <Wz_File>() { fileOld }, type, diffLst, outputDir); }
public static MapleFileInfo GetFileInfo(this Wz_File wz_File) { return(new MapleFileInfo { Signature = wz_File.Header.Signature, Copyright = wz_File.Header.Copyright, FileName = wz_File.Header.FileName, HeaderSize = wz_File.Header.HeaderSize, DataSize = wz_File.Header.DataSize, FileSize = wz_File.Header.FileSize, EncryptedVersion = wz_File.Header.EncryptedVersion, VersionChecked = wz_File.Header.VersionChecked, TextEncoding = wz_File.TextEncoding.ToString(), ImageCount = wz_File.ImageCount }); }
public void EasyCompareWzFiles(Wz_File fileNew, Wz_File fileOld, string outputDir) { StateInfo = "正在对比wz概况..."; if (fileNew.Type == Wz_Type.Base || fileOld.Type == Wz_Type.Base) //至少有一个base 拆分对比 { var virtualNodeNew = RebuildWzFile(fileNew); var virtualNodeOld = RebuildWzFile(fileOld); WzFileComparer comparer = new WzFileComparer(); comparer.IgnoreWzFile = true; var dictNew = SplitVirtualNode(virtualNodeNew); var dictOld = SplitVirtualNode(virtualNodeOld); //寻找共同wzType var wzTypeList = dictNew.Select(kv => kv.Key) .Where(wzType => dictOld.ContainsKey(wzType)); CreateStyleSheet(outputDir); foreach (var wzType in wzTypeList) { var vNodeNew = dictNew[wzType]; var vNodeOld = dictOld[wzType]; var cmp = comparer.Compare(vNodeNew, vNodeOld); OutputFile(vNodeNew.LinkNodes.Select(node => node.Value).OfType <Wz_File>().ToList(), vNodeOld.LinkNodes.Select(node => node.Value).OfType <Wz_File>().ToList(), wzType, cmp.ToList(), outputDir); } } else //执行传统对比 { WzFileComparer comparer = new WzFileComparer(); comparer.IgnoreWzFile = false; var cmp = comparer.Compare(fileNew.Node, fileOld.Node); CreateStyleSheet(outputDir); OutputFile(fileNew, fileOld, fileNew.Type, cmp.ToList(), outputDir); } GC.Collect(); }
public void EasyCompareWzFiles(Wz_File fileNew, Wz_File fileOld, string outputDir) { StateInfo = "Comparing Wz..."; if (fileNew.Type == Wz_Type.Base || fileOld.Type == Wz_Type.Base) //At least one base split comparison { var virtualNodeNew = RebuildWzFile(fileNew); var virtualNodeOld = RebuildWzFile(fileOld); WzFileComparer comparer = new WzFileComparer(); comparer.IgnoreWzFile = true; var dictNew = SplitVirtualNode(virtualNodeNew); var dictOld = SplitVirtualNode(virtualNodeOld); //Find a common Wztype var wzTypeList = dictNew.Select(kv => kv.Key) .Where(wzType => dictOld.ContainsKey(wzType)); CreateStyleSheet(outputDir); foreach (var wzType in wzTypeList) { var vNodeNew = dictNew[wzType]; var vNodeOld = dictOld[wzType]; var cmp = comparer.Compare(vNodeNew, vNodeOld); OutputFile(vNodeNew.LinkNodes.Select(node => node.Value).OfType <Wz_File>().ToList(), vNodeOld.LinkNodes.Select(node => node.Value).OfType <Wz_File>().ToList(), wzType, cmp.ToList(), outputDir); } } else //Perform traditional comparisons { WzFileComparer comparer = new WzFileComparer(); comparer.IgnoreWzFile = false; var cmp = comparer.Compare(fileNew.Node, fileOld.Node); CreateStyleSheet(outputDir); OutputFile(fileNew, fileOld, fileNew.Type, cmp.ToList(), outputDir); } GC.Collect(); }
private Dictionary <Wz_Type, WzVirtualNode> SplitVirtualNode(WzVirtualNode node) { var dict = new Dictionary <Wz_Type, WzVirtualNode>(); Wz_File wzFile = node.LinkNodes[0].Value as Wz_File; dict[wzFile.Type] = node; if (wzFile.Type == Wz_Type.Base) //额外处理 { var wzFileList = node.ChildNodes .Select(child => new { Node = child, WzFile = child.LinkNodes[0].Value as Wz_File }) .Where(item => item.WzFile != null); foreach (var item in wzFileList) { dict[item.WzFile.Type] = item.Node; } } return(dict); }
public static Wz_Node FindWz(string fullPath, Wz_File sourceWzFile) { FindWzEventArgs e = new FindWzEventArgs() { FullPath = fullPath, WzFile = sourceWzFile }; if (WzFileFinding != null) { WzFileFinding(null, e); if (e.WzNode != null) { return(e.WzNode); } if (e.WzFile != null) { return(e.WzFile.Node); } } return(null); }
public static Wz_Node FindWz(Wz_Type type, Wz_File sourceWzFile) { FindWzEventArgs e = new FindWzEventArgs(type) { WzFile = sourceWzFile }; if (WzFileFinding != null) { WzFileFinding(null, e); if (e.WzNode != null) { return(e.WzNode); } if (e.WzFile != null) { return(e.WzFile.Node); } } return(null); }
void btnItem_Click(object sender, EventArgs e) { Wz_Node node = Context.SelectedNode1; if (node != null) { Wz_Image img = node.Value as Wz_Image; Wz_File wzFile = node.GetNodeWzFile(); if (img != null && img.TryExtract()) { if (wzFile == null || wzFile.Type != Wz_Type.Map) { if (MessageBoxEx.Show("The selected Img does not belong to Map.wz. Continue?", "Message", MessageBoxButtons.OKCancel) != DialogResult.OK) { goto exit; } } StringLinker sl = this.Context.DefaultStringLinker; if (!sl.HasValues) //生成默认stringLinker { sl = new StringLinker(); sl.Load(PluginManager.FindWz(Wz_Type.String).GetValueEx <Wz_File>(null)); } //开始绘制 Thread thread = new Thread(() => { #if !DEBUG try { #endif #if MapRenderV1 if (sender == btnItemMapRender) { if (this.mapRenderGame1 != null) { return; } this.mapRenderGame1 = new FrmMapRender(img) { StringLinker = sl }; try { using (this.mapRenderGame1) { this.mapRenderGame1.Run(); } } finally { this.mapRenderGame1 = null; } } else #endif { if (this.mapRenderGame2 != null) { return; } this.mapRenderGame2 = new FrmMapRender2(img) { StringLinker = sl }; this.mapRenderGame2.Window.Title = "MapRender " + this.Version; try { using (this.mapRenderGame2) { this.mapRenderGame2.Run(); } } finally { this.mapRenderGame2 = null; } } #if !DEBUG } catch (Exception ex) { PluginManager.LogError("MapRender", ex, "MapRender error:"); MessageBoxEx.Show(ex.ToString(), "MapRender"); } #endif }); thread.SetApartmentState(ApartmentState.STA); thread.IsBackground = true; thread.Start(); goto exit; } } MessageBoxEx.Show("Please select a Map Img.", "Message"); exit: return; }
/// <summary> /// 比较两个节点绑定的值是否相同。 /// </summary> /// <param Name="dataNew">新的值。</param> /// <param Name="dataOld">旧的值。</param> /// <returns></returns> public virtual bool CompareData(object dataNew, object dataOld) { // skip virtual dir { if (dataNew is Wz_File fileNew && fileNew.IsSubDir) { dataNew = null; } if (dataOld is Wz_File fileOld && fileOld.IsSubDir) { dataNew = null; } } if (dataNew == null && dataOld == null) { return(true); } if (dataNew == null ^ dataOld == null) { return(false); } Type type = dataNew.GetType(); if (type != dataOld.GetType()) { return(false); } if (type.IsClass) { switch (dataNew) { case string str: return(str == (string)dataOld); case Wz_Image img: Wz_Image imgOld = (Wz_Image)dataOld; return(img.Size == imgOld.Size && img.Checksum == imgOld.Checksum); case Wz_File file: Wz_File fileOld = (Wz_File)dataOld; return(file.Type == fileOld.Type); case Wz_Png png: Wz_Png pngOld = (Wz_Png)dataOld; switch (this.PngComparison) { case WzPngComparison.SizeOnly: return(png.Width == pngOld.Width && png.Height == pngOld.Height); case WzPngComparison.SizeAndDataLength: return(png.Width == pngOld.Width && png.Height == pngOld.Height && png.DataLength == pngOld.DataLength); case WzPngComparison.Pixel: if (!(png.Width == pngOld.Width && png.Height == pngOld.Height && png.Form == pngOld.Form)) { return(false); } byte[] pixelNew = png.GetRawData(); byte[] pixelOld = pngOld.GetRawData(); if (pixelNew == null || pixelOld == null || pixelNew.Length != pixelOld.Length) { return(false); } for (int i = 0, i1 = pixelNew.Length; i < i1; i++) { if (pixelNew[i] != pixelOld[i]) { return(false); } } return(true); default: goto case WzPngComparison.SizeAndDataLength; } break; case Wz_Vector vector: Wz_Vector vectorOld = (Wz_Vector)dataOld; return(vector.X == vectorOld.X && vector.Y == vectorOld.Y); case Wz_Uol uol: return(uol.Uol == ((Wz_Uol)dataOld).Uol); case Wz_Sound sound: Wz_Sound soundOld = (Wz_Sound)dataOld; return(sound.Ms == soundOld.Ms && sound.DataLength == soundOld.DataLength); } } return(object.Equals(dataNew, dataOld)); }
public bool Load(Wz_File stringWz) { if (stringWz == null || stringWz.Node == null) { return(false); } this.Clear(); int id; foreach (Wz_Node node in stringWz.Node.Nodes) { Wz_Image image = node.Value as Wz_Image; if (image == null) { continue; } switch (node.Text) { case "Pet.img": case "Cash.img": case "Ins.img": case "Consume.img": if (!image.TryExtract()) { break; } foreach (Wz_Node tree in image.Node.Nodes) { if (Int32.TryParse(tree.Text, out id)) { StringResult strResult = new StringResult(); strResult.Name = GetDefaultString(tree, "name"); strResult.Desc = GetDefaultString(tree, "desc"); strResult.AutoDesc = GetDefaultString(tree, "autodesc"); strResult.FullPath = tree.FullPath; AddAllValue(strResult, tree); stringItem[id] = strResult; } } break; case "Etc.img": if (!image.TryExtract()) { break; } foreach (Wz_Node tree0 in image.Node.Nodes) { foreach (Wz_Node tree in tree0.Nodes) { if (Int32.TryParse(tree.Text, out id)) { StringResult strResult = new StringResult(); strResult.Name = GetDefaultString(tree, "name"); strResult.Desc = GetDefaultString(tree, "desc"); strResult.FullPath = tree.FullPath; AddAllValue(strResult, tree); stringItem[id] = strResult; } } } break; case "Mob.img": if (!image.TryExtract()) { break; } foreach (Wz_Node tree in image.Node.Nodes) { if (Int32.TryParse(tree.Text, out id)) { StringResult strResult = new StringResult(); strResult.Name = GetDefaultString(tree, "name"); strResult.FullPath = tree.FullPath; AddAllValue(strResult, tree); stringMob[id] = strResult; } } break; case "Npc.img": if (!image.TryExtract()) { break; } foreach (Wz_Node tree in image.Node.Nodes) { if (Int32.TryParse(tree.Text, out id)) { StringResult strResult = new StringResult(); strResult.Name = GetDefaultString(tree, "name"); strResult.Desc = GetDefaultString(tree, "func"); strResult.FullPath = tree.FullPath; AddAllValue(strResult, tree); stringNpc[id] = strResult; } } break; case "Map.img": if (!image.TryExtract()) { break; } foreach (Wz_Node tree0 in image.Node.Nodes) { foreach (Wz_Node tree in tree0.Nodes) { if (Int32.TryParse(tree.Text, out id)) { StringResult strResult = new StringResult(); strResult.Name = string.Format("{0}:{1}", GetDefaultString(tree, "streetName"), GetDefaultString(tree, "mapName")); strResult.Desc = GetDefaultString(tree, "mapDesc"); strResult.FullPath = tree.FullPath; AddAllValue(strResult, tree); stringMap[id] = strResult; } } } break; case "Skill.img": if (!image.TryExtract()) { break; } foreach (Wz_Node tree in image.Node.Nodes) { StringResult strResult = new StringResultSkill(); strResult.Name = GetDefaultString(tree, "name"); //?? GetDefaultString(tree, "bookName"); strResult.Desc = GetDefaultString(tree, "desc"); strResult.Pdesc = GetDefaultString(tree, "pdesc"); strResult.SkillH.Add(GetDefaultString(tree, "h")); strResult.SkillpH.Add(GetDefaultString(tree, "ph")); strResult.SkillhcH.Add(GetDefaultString(tree, "hch")); if (strResult.SkillH[0] == null) { strResult.SkillH.RemoveAt(0); for (int i = 1; ; i++) { string hi = GetDefaultString(tree, "h" + i); if (string.IsNullOrEmpty(hi)) { break; } strResult.SkillH.Add(hi); } } strResult.SkillH.TrimExcess(); strResult.SkillpH.TrimExcess(); strResult.FullPath = tree.FullPath; AddAllValue(strResult, tree); if (tree.Text.Length >= 7 && Int32.TryParse(tree.Text, out id)) { stringSkill[id] = strResult; } stringSkill2[tree.Text] = strResult; } break; case "Eqp.img": if (!image.TryExtract()) { break; } foreach (Wz_Node tree0 in image.Node.Nodes) { foreach (Wz_Node tree1 in tree0.Nodes) { foreach (Wz_Node tree in tree1.Nodes) { if (Int32.TryParse(tree.Text, out id)) { StringResult strResult = new StringResult(); strResult.Name = GetDefaultString(tree, "name"); strResult.Desc = GetDefaultString(tree, "desc"); strResult.FullPath = tree.FullPath; AddAllValue(strResult, tree); stringEqp[id] = strResult; } } } } break; } } return(this.HasValues); }
/// <summary> /// !!!!!!!!!!!!COPIED CODE!!!!!!!!!!!!!! /// Version: [email protected]:Kagamia/WzComparerR2.git:f6ecfb18cae661f125a189e527feea1964f5bda8 /// </summary> /// <see cref="WzComparerR2.MainForm.CharaSimLoader_WzFileFinding"/> private void CharaSimLoader_WzFileFinding(object sender, WzComparerR2.FindWzEventArgs e) { string[] fullPath = null; if (!string.IsNullOrEmpty(e.FullPath)) //用fullpath作为输入参数 { fullPath = e.FullPath.Split('/', '\\'); try { e.WzType = (Wz_Type)Enum.Parse(typeof(Wz_Type), fullPath[0], true); } catch { e.WzType = Wz_Type.Unknown; } } List <Wz_Node> preSearch = new List <Wz_Node>(); if (e.WzType != Wz_Type.Unknown) //用wztype作为输入参数 { IEnumerable <Wz_Structure> preSearchWz = e.WzFile?.WzStructure != null? Enumerable.Repeat(e.WzFile.WzStructure, 1) : new List <Wz_Structure>() { _wzStructure }; foreach (var wzs in preSearchWz) { Wz_File baseWz = null; bool find = false; foreach (Wz_File wz_f in wzs.wz_files) { if (wz_f.Type == e.WzType) { preSearch.Add(wz_f.Node); find = true; //e.WzFile = wz_f; } if (wz_f.Type == Wz_Type.Base) { baseWz = wz_f; } } // detect data.wz if (baseWz != null && !find) { string key = e.WzType.ToString(); foreach (Wz_Node node in baseWz.Node.Nodes) { if (node.Text == key && node.Nodes.Count > 0) { preSearch.Add(node); } } } } } if (fullPath == null || fullPath.Length <= 1) { if (e.WzType != Wz_Type.Unknown && preSearch.Count > 0) //返回wzFile { e.WzNode = preSearch[0]; e.WzFile = preSearch[0].Value as Wz_File; } return; } if (preSearch.Count <= 0) { return; } foreach (var wzFileNode in preSearch) { var searchNode = wzFileNode; for (int i = 1; i < fullPath.Length && searchNode != null; i++) { searchNode = searchNode.Nodes[fullPath[i]]; var img = searchNode.GetValueEx <Wz_Image>(null); if (img != null) { searchNode = img.TryExtract() ? img.Node : null; } } if (searchNode != null) { e.WzNode = searchNode; e.WzFile = wzFileNode.Value as Wz_File; return; } } //寻找失败 e.WzNode = null; }