public OtbWriter(ServerItemList items) { if (items == null) { throw new ArgumentNullException("items"); } this.Items = items; }
public void ConstructorInitialisesListWithChildren() { var children = new[] { new ServerItem(), new ServerItem() }; var list = new ServerItemList(children); CollectionAssert.AreEqual(children, list.Children); }
private bool CompareItems() { if (System.IO.File.Exists(file1Text.Text) && System.IO.File.Exists(file2Text.Text)) { ServerItemList items1 = new ServerItemList(); ServerItemList items2 = new ServerItemList(); bool result; result = Otb.Open(file1Text.Text, ref items1); if (!result) { MessageBox.Show("Could not open {0}.", file1Text.Text); return(false); } result = Otb.Open(file2Text.Text, ref items2); if (!result) { MessageBox.Show("Could not open {0}.", file2Text.Text); return(false); } IEnumerator <ServerItem> enumerator1 = items1.GetEnumerator(); IEnumerator <ServerItem> enumerator2 = items2.GetEnumerator(); if (items1.Count != items2.Count) { resultTextBox.AppendText(string.Format("Item count: [ {0} / {1} ]" + Environment.NewLine, items1.Count, items2.Count)); } while (enumerator1.MoveNext()) { if (!enumerator2.MoveNext()) { return(false); } ServerItem item1 = enumerator1.Current; ServerItem item2 = enumerator2.Current; if (item1.spriteId != item2.spriteId) { resultTextBox.AppendText(string.Format("Id: {0} - Sprite changed - [ {1} / {2} ]" + Environment.NewLine, item1.id, item1.spriteId, item2.spriteId)); continue; } if (item1.SpriteHash != null && item2.SpriteHash != null && !Utils.ByteArrayCompare(item1.SpriteHash, item2.SpriteHash)) { resultTextBox.AppendText(string.Format("Id: {0} - Sprite updated." + Environment.NewLine, item1.id)); } foreach (PropertyInfo property in item1.GetType().GetProperties()) { if (property.Name != "spriteHash" && property.Name != "spriteId") { object value1 = property.GetValue(item1, null); object value2 = item2.GetType().GetProperty(property.Name).GetValue(item2, null); if (!value1.Equals(value2)) { resultTextBox.AppendText(string.Format("Id: {0} - {1} - [ {2} / {3} ]{4}", item1.id, property.Name, value1, value2, Environment.NewLine)); } } } } if (resultTextBox.Text.Length == 0) { MessageBox.Show("No differences found!"); } return(true); } return(false); }
public void DefaultConstructorInitialisesEmptyList() { var list = new ServerItemList(); CollectionAssert.IsEmpty(list.Children); }
public bool Read(string directory, ServerItemList items) { if (directory == null) { throw new ArgumentNullException(nameof(directory)); } if (!System.IO.Directory.Exists(directory)) { throw new DirectoryNotFoundException(directory); } if (items == null) { throw new ArgumentNullException(nameof(items)); } string file = Path.Combine(directory, "items.xml"); if (!System.IO.File.Exists(file)) { return(false); } try { XDocument xml = XDocument.Load(file); foreach (XElement element in xml.Root.Elements("item")) { if (element.Attribute("id") != null) { ushort id = ushort.Parse(element.Attribute("id").Value); if (items.TryGetValue(id, out ServerItem item)) { ParseItem(item, element); } } else if (element.Attribute("fromid") != null && element.Attribute("toid") != null) { ushort fromid = ushort.Parse(element.Attribute("fromid").Value); ushort toid = ushort.Parse(element.Attribute("toid").Value); for (ushort id = fromid; id <= toid; id++) { if (items.TryGetValue(id, out ServerItem item)) { ParseItem(item, element); } } } } } catch (Exception ex) { Trace.WriteLine(ex.ToString()); return(false); } Directory = directory; File = file; return(true); }
private bool CompareItems() { if (System.IO.File.Exists(file1Text.Text) && System.IO.File.Exists(file2Text.Text)) { ServerItemList items1 = new ServerItemList(); ServerItemList items2 = new ServerItemList(); bool result; result = Otb.Open(file1Text.Text, ref items1); if (!result) { MessageBox.Show("Could not open {0}.", file1Text.Text); return false; } result = Otb.Open(file2Text.Text, ref items2); if (!result) { MessageBox.Show("Could not open {0}.", file2Text.Text); return false; } IEnumerator<ServerItem> enumerator1 = items1.GetEnumerator(); IEnumerator<ServerItem> enumerator2 = items2.GetEnumerator(); if (items1.Count != items2.Count) { resultTextBox.AppendText(string.Format("Item count: [ {0} / {1} ]" + Environment.NewLine, items1.Count, items2.Count)); } while (enumerator1.MoveNext()) { if (!enumerator2.MoveNext()) { return false; } ServerItem item1 = enumerator1.Current; ServerItem item2 = enumerator2.Current; if (item1.spriteId != item2.spriteId) { resultTextBox.AppendText(string.Format("Id: {0} - Sprite changed - [ {1} / {2} ]" + Environment.NewLine, item1.id, item1.spriteId, item2.spriteId)); continue; } if (item1.SpriteHash != null && item2.SpriteHash != null && !Utils.ByteArrayCompare(item1.SpriteHash, item2.SpriteHash)) { resultTextBox.AppendText(string.Format("Id: {0} - Sprite updated." + Environment.NewLine, item1.id)); } foreach (PropertyInfo property in item1.GetType().GetProperties()) { if (property.Name != "spriteHash" && property.Name != "spriteId") { object value1 = property.GetValue(item1, null); object value2 = item2.GetType().GetProperty(property.Name).GetValue(item2, null); if (!value1.Equals(value2)) { resultTextBox.AppendText(string.Format("Id: {0} - {1} - [ {2} / {3} ]{4}", item1.id, property.Name, value1, value2, Environment.NewLine)); } } } } if (resultTextBox.Text.Length == 0) { MessageBox.Show("No differences found!"); } return true; } return false; }
public void Open(string path = null) { if (string.IsNullOrEmpty(path)) { FileDialog dialog = new OpenFileDialog(); dialog.Filter = "OTB files (*.otb)|*.otb"; dialog.Title = "Open OTB File"; if (dialog.ShowDialog() != DialogResult.OK || dialog.FileName.Length == 0) { return; } path = dialog.FileName; this.IsTemporary = false; this.Saved = true; } if (this.Loaded) { this.Clear(); } OtbReader reader = new OtbReader(); if (reader.Read(path)) { this.serverItems = reader.Items; this.CurrentOtbFullPath = path; this.CurrentOtbVersion = this.serverItems.MinorVersion; // try find a plugin that can handle this version of otb this.CurrentPlugin = Program.plugins.AvailablePlugins.Find(this.CurrentOtbVersion); if (this.CurrentPlugin == null) { this.serverItems.Clear(); MessageBox.Show(string.Format("Could not find a plugin that could handle client version {0}", this.CurrentOtbVersion)); return; } if (!this.LoadClient(this.CurrentPlugin, this.CurrentOtbVersion)) { this.Clear(false); return; } this.fileSaveAsMenuItem.Enabled = true; this.fileSaveMenuItem.Enabled = true; this.editCreateItemMenuItem.Enabled = true; this.editFindItemMenuItem.Enabled = true; this.viewShowOnlyMismatchedMenuItem.Enabled = true; this.viewShowDecaptedItemsMenuItem.Enabled = true; this.viewUpdateItemsListMenuItem.Enabled = true; this.toolsUpdateVersionMenuItem.Enabled = true; this.toolsReloadItemAttributesMenuItem.Enabled = true; this.toolStripSaveButton.Enabled = true; this.toolStripSaveAsButton.Enabled = true; this.toolStripFindItemButton.Enabled = true; this.serverItemListBox.Plugin = this.CurrentPlugin.Instance; this.serverItemListBox.Enabled = true; this.newItemButton.Enabled = true; this.duplicateItemButton.Enabled = true; this.reloadItemButton.Enabled = true; this.findItemButton.Enabled = true; this.Loaded = true; this.BuildItemsListBox(); } }
public void CreateEmptyOTB(string filePath, SupportedClient client, bool isTemporary = true) { ServerItem item = new ServerItem(); item.SpriteHash = new byte[16]; item.ClientId = 100; item.ID = 100; ServerItemList items = new ServerItemList(); items.MajorVersion = 3; items.MinorVersion = client.OtbVersion; items.BuildNumber = 1; items.ClientVersion = client.Version; items.Add(item); if (!File.Exists(filePath)) { using (File.Create(filePath)) { //// } } OtbWriter writer = new OtbWriter(items); if (writer.Write(filePath)) { this.Open(filePath); this.IsTemporary = isTemporary; this.Saved = !isTemporary; } }
public void CreateEmptyOTB(string filePath, SupportedClient client, bool isTemp = true) { ServerItem item = new ServerItem(); item.SpriteHash = new byte[16]; item.spriteId = 100; item.id = 100; ServerItemList items = new ServerItemList(); items.dwMajorVersion = 3; items.dwMinorVersion = client.OtbVersion; items.dwBuildNumber = 1; items.clientVersion = client.Version; items.Add(item); if (!File.Exists(filePath)) { using (File.Create(filePath)) { } } if (Otb.Save(filePath, ref items)) { this.Open(filePath); this.isTemp = isTemp; this.saved = !isTemp; } }