public bool loadClient(Host.Types.Plugin plugin, UInt32 otbVersion) { SupportedClient client = plugin.Instance.SupportedClients.Find( delegate(SupportedClient sc) { return(sc.otbVersion == otbVersion); }); if (client == null) { MessageBox.Show("The selected plugin does not support this version."); return(false); } string dataFolder = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "data"); if (Directory.Exists(dataFolder) == false) { Directory.CreateDirectory(dataFolder); } string datPath = FindClientFile(Path.Combine(dataFolder, client.version.ToString()), ".dat"); string sprPath = FindClientFile(Path.Combine(dataFolder, client.version.ToString()), ".spr"); if (File.Exists(datPath) == false || File.Exists(sprPath) == false) { string text = String.Empty; if (File.Exists(datPath) == false) { text = String.Format("Unable to load dat file, please place a valid dat in 'data\\{0}\\'.", client.version); } if (File.Exists(sprPath) == false) { if (text != String.Empty) { text += "\n"; } text += String.Format("Unable to load spr file, please place a valid spr in 'data\\{0}\\'.", client.version); } MessageBox.Show(text); return(false); } bool result = plugin.Instance.LoadClient(client, datPath, sprPath); if (!result) { MessageBox.Show(String.Format("The plugin could not load dat or spr.")); } items.clientVersion = client.version; return(result); }
private void selectBtn_Click(object sender, EventArgs e) { if(pluginsListBox.SelectedItem != null){ selectedPlugin = Program.plugins.AvailablePlugins.Find(pluginsListBox.SelectedItem.ToString()); updateClient = clientList[(Int32)pluginsListBox.SelectedIndex]; this.DialogResult = DialogResult.OK; Close(); } }
private void selectBtn_Click(object sender, EventArgs e) { if (pluginsListBox.SelectedItem != null) { selectedPlugin = Program.plugins.AvailablePlugins.Find(pluginsListBox.SelectedItem.ToString()); updateClient = clientList[(Int32)pluginsListBox.SelectedIndex]; this.DialogResult = DialogResult.OK; Close(); } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { FileDialog dialog = new OpenFileDialog(); //Now set the file type dialog.Filter = "otb files (*.otb)|*.otb|All files (*.*)|*.*"; dialog.Title = "Open otb file..."; if (dialog.ShowDialog() != DialogResult.OK || dialog.FileName.Length == 0) { return; } currentItem = null; currentPlugin = null; previousPlugin = null; currentOtbVersion = 0; items.Clear(); if (otb.open(dialog.FileName, ref items, showOtbOutput)) { currentOtbFullPath = dialog.FileName; currentOtbVersion = items.dwMinorVersion; saveAsToolStripMenuItem.Enabled = true; saveToolStripMenuItem.Enabled = true; //try find a plugin that can handle this version of otb currentPlugin = Program.plugins.AvailablePlugins.Find(currentOtbVersion); if (currentPlugin == null) { items.Clear(); MessageBox.Show(String.Format("Could not find a plugin that could handle client version {0}", currentOtbVersion)); return; } if (!loadClient(currentPlugin, currentOtbVersion)) { currentPlugin = null; items.Clear(); return; } createItemToolStripMenuItem.Enabled = true; updateToolStripMenuItem.Enabled = true; buildTreeView(); } }
private void updateToolStripMenuItem_Click(object sender, EventArgs e) { UpdateForm form = new UpdateForm(); form.mainForm = this; DialogResult result = form.ShowDialog(); if (result == DialogResult.OK) { //Update OTB Host.Types.Plugin updatePlugin = form.selectedPlugin; SupportedClient updateClient = form.updateClient; if (updatePlugin == null) { return; } if (!loadClient(updatePlugin, updateClient.otbVersion)) { return; } UpdateSettingsForm updateSettingsForm = new UpdateSettingsForm(); result = updateSettingsForm.ShowDialog(); if (result != DialogResult.OK) { return; } if (updateSettingsForm.generateSignatureCheck.Checked) { //Calculate an image signature using fourier transformation and calculate a signature we can //use to compare it to other images (kinda similar to md5 hash) except this //can also be used to find images with some variation. SpriteItems currentSpriteItems = currentPlugin.Instance.Items; generateSpriteSignatures(ref currentSpriteItems); SpriteItems updateSpriteItems = updatePlugin.Instance.Items; generateSpriteSignatures(ref updateSpriteItems); } SpriteItems currentItems = currentPlugin.Instance.Items; SpriteItems updateItems = updatePlugin.Instance.Items; List <UInt16> assignedSpriteIdList = new List <UInt16>(); //store the previous plugin (so we can display previous sprite, and do other comparisions) previousPlugin = currentPlugin; //update the current plugin the one we are updating to currentPlugin = updatePlugin; //update version information items.clientVersion = updateClient.version; items.dwMinorVersion = updateClient.otbVersion; items.dwBuildNumber = items.dwBuildNumber + 1; currentOtbVersion = items.dwMinorVersion; //Most items does have the same sprite after an update, so lets try that first UInt32 foundItemCounter = 0; foreach (OtbItem item in items) { item.spriteAssigned = false; if (item.type == ItemType.Deprecated) { continue; } SpriteItem updateSpriteItem; if (updateItems.TryGetValue(item.spriteId, out updateSpriteItem)) { bool compareResult = updateSpriteItem.isEqual(item); if (Utils.ByteArrayCompare(updateSpriteItem.spriteHash, item.spriteHash)) { if (compareResult) { item.prevSpriteId = item.spriteId; item.spriteId = updateSpriteItem.id; item.spriteAssigned = true; assignedSpriteIdList.Add(updateSpriteItem.id); ++foundItemCounter; if (showUpdateOutput) { //Trace.WriteLine(String.Format("Match found id: {0}, clientid: {1}", item.otb.id, item.dat.id)); } } else { //Sprite matches, but not the other attributes. if (showUpdateOutput) { Trace.WriteLine(String.Format("Attribute changes found id: {0}", item.id)); } } } } } if (updateSettingsForm.reassignUnmatchedSpritesCheck.Checked) { foreach (Item updateItem in updateItems.Values) { foreach (OtbItem item in items) { if (item.type == ItemType.Deprecated) { continue; } if (item.spriteAssigned) { continue; } if (Utils.ByteArrayCompare(updateItem.spriteHash, item.spriteHash)) { if (updateItem.isEqual(item)) { if (updateItem.id != item.spriteId) { if (showUpdateOutput) { Trace.WriteLine(String.Format("New sprite found id: {0}, old: {1}, new: {2}", item.id, item.spriteId, updateItem.id)); } } item.prevSpriteId = item.spriteId; item.spriteId = updateItem.id; item.spriteAssigned = true; assignedSpriteIdList.Add(updateItem.id); ++foundItemCounter; break; } } } } } if (showUpdateOutput) { Trace.WriteLine(String.Format("Found {0} of {1}", foundItemCounter, items.maxId)); } if (updateSettingsForm.reloadItemAttributesCheck.Checked) { UInt32 reloadedItemCounter = 0; foreach (OtbItem item in items) { if (item.type == ItemType.Deprecated) { continue; } //implicit assigned item.prevSpriteId = item.spriteId; item.spriteAssigned = true; if (!assignedSpriteIdList.Contains(item.spriteId)) { assignedSpriteIdList.Add(item.spriteId); } if (!compareItem(item, true)) { //sync with dat info reloadItem(item); ++reloadedItemCounter; } } if (showUpdateOutput) { Trace.WriteLine(String.Format("Reloaded {0} of {1}", reloadedItemCounter, items.maxId)); } } if (updateSettingsForm.createNewItemsCheck.Checked) { UInt32 newItemCounter = 0; foreach (Item updateItem in updateItems.Values) { if (!assignedSpriteIdList.Contains(updateItem.id)) { ++newItemCounter; UInt16 newId = createItem(updateItem); if (showUpdateOutput) { Trace.WriteLine(String.Format("Creating item id {0}", newId)); } } } if (showUpdateOutput) { Trace.WriteLine(String.Format("Created {0} new items", newItemCounter)); } } //done buildTreeView(); } }
private void updateToolStripMenuItem_Click(object sender, EventArgs e) { UpdateForm form = new UpdateForm(); form.mainForm = this; DialogResult result = form.ShowDialog(); if (result == DialogResult.OK) { //Update OTB Host.Types.Plugin updatePlugin = form.selectedPlugin; SupportedClient updateClient = form.updateClient; if (updatePlugin == null) { return; } if (!loadClient(updatePlugin, updateClient.otbVersion)) { return; } UpdateSettingsForm updateSettingsForm = new UpdateSettingsForm(); result = updateSettingsForm.ShowDialog(); if (result != DialogResult.OK) { return; } if (updateSettingsForm.generateSignatureCheck.Checked) { //Calculate an image signature using fourier transformation and calculate a signature we can //use to compare it to other images (kinda similar to md5 hash) except this //can also be used to find images with some variation. SpriteItems currentSpriteItems = currentPlugin.Instance.Items; generateSpriteSignatures(ref currentSpriteItems); SpriteItems updateSpriteItems = updatePlugin.Instance.Items; generateSpriteSignatures(ref updateSpriteItems); } SpriteItems currentItems = currentPlugin.Instance.Items; SpriteItems updateItems = updatePlugin.Instance.Items; List<UInt16> assignedSpriteIdList = new List<UInt16>(); //store the previous plugin (so we can display previous sprite, and do other comparisions) previousPlugin = currentPlugin; //update the current plugin the one we are updating to currentPlugin = updatePlugin; //update version information items.clientVersion = updateClient.version; items.dwMinorVersion = updateClient.otbVersion; items.dwBuildNumber = items.dwBuildNumber + 1; currentOtbVersion = items.dwMinorVersion; //Most items does have the same sprite after an update, so lets try that first UInt32 foundItemCounter = 0; foreach (OtbItem item in items) { item.spriteAssigned = false; if (item.type == ItemType.Deprecated) { continue; } SpriteItem updateSpriteItem; if (updateItems.TryGetValue(item.spriteId, out updateSpriteItem)) { bool compareResult = updateSpriteItem.isEqual(item); if (Utils.ByteArrayCompare(updateSpriteItem.spriteHash, item.spriteHash)) { if (compareResult) { item.prevSpriteId = item.spriteId; item.spriteId = updateSpriteItem.id; item.spriteAssigned = true; assignedSpriteIdList.Add(updateSpriteItem.id); ++foundItemCounter; if (showUpdateOutput) { //Trace.WriteLine(String.Format("Match found id: {0}, clientid: {1}", item.otb.id, item.dat.id)); } } else { //Sprite matches, but not the other attributes. if (showUpdateOutput) { Trace.WriteLine(String.Format("Attribute changes found id: {0}", item.id)); } } } } } if (updateSettingsForm.reassignUnmatchedSpritesCheck.Checked) { foreach (Item updateItem in updateItems.Values) { foreach (OtbItem item in items) { if (item.type == ItemType.Deprecated) { continue; } if (item.spriteAssigned) { continue; } if (Utils.ByteArrayCompare(updateItem.spriteHash, item.spriteHash)) { if (updateItem.isEqual(item)) { if (updateItem.id != item.spriteId) { if (showUpdateOutput) { Trace.WriteLine(String.Format("New sprite found id: {0}, old: {1}, new: {2}", item.id, item.spriteId, updateItem.id)); } } item.prevSpriteId = item.spriteId; item.spriteId = updateItem.id; item.spriteAssigned = true; assignedSpriteIdList.Add(updateItem.id); ++foundItemCounter; break; } } } } } if (showUpdateOutput) { Trace.WriteLine(String.Format("Found {0} of {1}", foundItemCounter, items.maxId)); } if (updateSettingsForm.reloadItemAttributesCheck.Checked) { UInt32 reloadedItemCounter = 0; foreach (OtbItem item in items) { if (item.type == ItemType.Deprecated) { continue; } //implicit assigned item.prevSpriteId = item.spriteId; item.spriteAssigned = true; if (!assignedSpriteIdList.Contains(item.spriteId)) { assignedSpriteIdList.Add(item.spriteId); } if (!compareItem(item, true)) { //sync with dat info reloadItem(item); ++reloadedItemCounter; } } if (showUpdateOutput) { Trace.WriteLine(String.Format("Reloaded {0} of {1}", reloadedItemCounter, items.maxId)); } } if (updateSettingsForm.createNewItemsCheck.Checked) { UInt32 newItemCounter = 0; foreach (Item updateItem in updateItems.Values) { if (!assignedSpriteIdList.Contains(updateItem.id)) { ++newItemCounter; UInt16 newId = createItem(updateItem); if (showUpdateOutput) { Trace.WriteLine(String.Format("Creating item id {0}", newId)); } } } if (showUpdateOutput) { Trace.WriteLine(String.Format("Created {0} new items", newItemCounter)); } } //done buildTreeView(); } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { FileDialog dialog = new OpenFileDialog(); //Now set the file type dialog.Filter = "otb files (*.otb)|*.otb|All files (*.*)|*.*"; dialog.Title = "Open otb file..."; if (dialog.ShowDialog() != DialogResult.OK || dialog.FileName.Length == 0) { return; } currentItem = null; currentPlugin = null; previousPlugin = null; currentOtbVersion = 0; items.Clear(); if (otb.open(dialog.FileName, ref items, showOtbOutput)) { currentOtbFullPath = dialog.FileName; currentOtbVersion = items.dwMinorVersion; saveAsToolStripMenuItem.Enabled = true; saveToolStripMenuItem.Enabled = true; //try find a plugin that can handle this version of otb currentPlugin = Program.plugins.AvailablePlugins.Find(currentOtbVersion); if (currentPlugin == null) { items.Clear(); MessageBox.Show(String.Format("Could not find a plugin that could handle client version {0}", currentOtbVersion)); return; } if (!loadClient(currentPlugin, currentOtbVersion)) { currentPlugin = null; items.Clear(); return; } createItemToolStripMenuItem.Enabled = true; updateToolStripMenuItem.Enabled = true; buildTreeView(); } }