private void selectBtn_Click(object sender, EventArgs e) { if (pluginsListBox.SelectedItem != null) { selectedPlugin = Program.plugins.AvailablePlugins.Find(pluginsListBox.SelectedItem.ToString()); updateClient = pluginsListBox.SelectedItem as SupportedClient; this.DialogResult = DialogResult.OK; Close(); } }
private void AddPlugin(string path) { Assembly pluginAssembly = Assembly.LoadFrom(path); foreach (Type pluginType in pluginAssembly.GetTypes()) { if (pluginType.IsPublic) { if (!pluginType.IsAbstract) { Type typeInterface = pluginType.GetInterface("PluginInterface.IPlugin", true); if (typeInterface != null) { Plugin newPlugin = new Plugin(); newPlugin.AssemblyPath = path; newPlugin.Instance = (IPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); newPlugin.Instance.Host = this; newPlugin.Instance.Initialize(); this.AvailablePlugins.Add(newPlugin); newPlugin = null; } typeInterface = null; } } } pluginAssembly = null; }
private void OnSelectFiles(string directory) { this.alertLabel.Text = string.Empty; if (string.IsNullOrEmpty(directory) || !Directory.Exists(directory)) { this.alertLabel.Text = "Directory not found"; return; } string datPath = Utils.FindClientFile(directory, ".dat"); string sprPath = Utils.FindClientFile(directory, ".spr"); if (!File.Exists(datPath) || !File.Exists(sprPath)) { this.alertLabel.Text = "Client files not found"; return; } uint datSignature = this.GetSignature(datPath); uint sprSignature = this.GetSignature(sprPath); this.Plugin = Program.plugins.AvailablePlugins.Find(datSignature, sprSignature); if (this.Plugin == null) { alertLabel.Text = string.Format("Unsupported version\nDat Signature: {0:X}\nSpr Signature: {1:X}", datSignature, sprSignature); return; } this.Client = this.Plugin.Instance.GetClientBySignatures(datSignature, sprSignature); this.extendedCheckBox.Checked = this.extendedCheckBox.Checked || this.Client.Version >= 960; this.extendedCheckBox.Enabled = this.Client.Version < 960; this.datSignature = datSignature; this.sprSignature = sprSignature; this.directoryPathTextBox.Text = directory; }
/// <summary> /// Removes a plugin /// </summary> /// <param name="plugin">The Plugin to Remove</param> public void Remove(Plugin plugin) { this.List.Remove(plugin); }
private bool LoadClient(Plugin plugin, uint 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; } uint datSignature = (uint)Properties.Settings.Default["DatSignature"]; uint sprSignature = (uint)Properties.Settings.Default["SprSignature"]; if (client.DatSignature != datSignature || client.SprSignature != sprSignature) { string message; if (datSignature == 0 || sprSignature == 0) { message = "No client is selected. Please navigate to the client folder."; } else { message = string.Format("The selected client is not compatible with this otb. Please navigate to the folder of a compatible client {0}.", client.Version); } MessageBox.Show(message); PreferencesForm form = new PreferencesForm(); if (form.ShowDialog() == DialogResult.OK && form.Plugin != null) { return this.LoadClient(form.Plugin, otbVersion); } else { return false; } } string clientFolder = (string)Properties.Settings.Default["ClientDirectory"]; if (string.IsNullOrEmpty(clientFolder)) { return false; } string datPath = Utils.FindClientFile(clientFolder, ".dat"); string sprPath = Utils.FindClientFile(clientFolder, ".spr"); bool extended = (bool)Properties.Settings.Default["Extended"]; bool transparency = (bool)Properties.Settings.Default["Transparency"]; extended = extended || client.Version >= 960; if (!File.Exists(datPath) || !File.Exists(sprPath)) { MessageBox.Show("Client files not found."); return false; } Trace.WriteLine(string.Format("OTB version {0}.", otbVersion)); bool result; try { result = plugin.Instance.LoadClient(client, extended, transparency, datPath, sprPath); } catch (UnauthorizedAccessException error) { MessageBox.Show(error.Message + " Please run this program as administrator."); return false; } Trace.WriteLine("Loading client files."); if (!result) { MessageBox.Show(string.Format("The plugin could not load dat or spr.")); } this.serverItems.ClientVersion = client.Version; Trace.WriteLine(string.Format("Client version {0}.", client.Version)); return result; }
/// <summary> /// Add a plugin /// </summary> /// <param name="plugin">The Plugin to Add</param> public void Add(Plugin plugin) { this.List.Add(plugin); }
private bool LoadClient(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; } UInt32 datSignature = Program.preferences.DatSignature; UInt32 sprSignature = Program.preferences.SprSignature; if (client.DatSignature != datSignature || client.SprSignature != sprSignature) { string message; if (datSignature == 0 || sprSignature == 0) message = "No client is selected. Please navigate to the client folder."; else message = String.Format("The selected client is not compatible with this otb. Please navigate to the folder of a compatible client {0}.", client.Version); MessageBox.Show(message); PreferencesForm form = new PreferencesForm(); form.ShowDialog(); return false; } string clientFolder = Program.preferences.ClientDirectory; if (String.IsNullOrEmpty(clientFolder)) { return false; } string datPath = Utils.FindClientFile(clientFolder, ".dat"); string sprPath = Utils.FindClientFile(clientFolder, ".spr"); bool extended = Program.preferences.Extended; bool transparency = Program.preferences.Transparency; extended = (extended || client.Version >= 960); if (!File.Exists(datPath) || !File.Exists(sprPath)) { MessageBox.Show("Client files not found."); return false; } Trace.WriteLine(String.Format("OTB version {0}.", otbVersion)); bool result; try { result = plugin.Instance.LoadClient(client, extended, transparency, datPath, sprPath); } catch (UnauthorizedAccessException error) { MessageBox.Show(error.Message + " Please run this program as administrator."); return false; } Trace.WriteLine("Loading client files."); if (!result) { MessageBox.Show(String.Format("The plugin could not load dat or spr.")); } items.clientVersion = client.Version; Trace.WriteLine(String.Format("Client version {0}.", client.Version)); return result; }
public void Clear() { this.SelectItem(null); this.currentItem = null; this.currentPlugin = null; this.previousPlugin = null; this.currentOtbVersion = 0; this.currentOtbFullPath = ""; this.items.Clear(); this.itemsListBox.Items.Clear(); this.itemsListBox.Enabled = false; this.fileSaveMenuItem.Enabled = false; this.fileSaveAsMenuItem.Enabled = false; this.editCreateItemMenuItem.Enabled = false; this.editDuplicateItemMenuItem.Enabled = false; this.editReloadItemMenuItem.Enabled = false; this.editFindItemMenuItem.Enabled = false; this.viewShowOnlyMismatchedMenuItem.Enabled = false; this.viewShowDecaptedItemsMenuItem.Enabled = false; this.viewUpdateItemsListMenuItem.Enabled = false; this.toolsUpdateVersionMenuItem.Enabled = false; this.toolsReloadItemAttributesMenuItem.Enabled = false; this.toolStripSaveButton.Enabled = false; this.toolStripSaveAsButton.Enabled = false; this.toolStripFindItemButton.Enabled = false; this.loaded = false; this.textBoxListener.Clear(); }
private void toolsUpdateVersionMenuItem_Click(object sender, EventArgs e) { UpdateForm form = new UpdateForm(); form.mainForm = this; DialogResult result = form.ShowDialog(); if (result == DialogResult.OK) { //Update OTB 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. ClientItems currentClientItems = currentPlugin.Instance.Items; GenerateSpriteSignatures(ref currentClientItems); ClientItems updateClientItems = updatePlugin.Instance.Items; GenerateSpriteSignatures(ref updateClientItems); } ClientItems currentItems = currentPlugin.Instance.Items; ClientItems 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 (ServerItem item in items) { item.spriteAssigned = false; if (item.type == ItemType.Deprecated) { continue; } ClientItem updateClientItem; if (updateItems.TryGetValue(item.spriteId, out updateClientItem)) { bool compareResult = updateClientItem.IsEqual(item); if (Utils.ByteArrayCompare(updateClientItem.SpriteHash, item.SpriteHash)) { if (compareResult) { item.prevSpriteId = item.spriteId; item.spriteId = updateClientItem.id; item.spriteAssigned = true; assignedSpriteIdList.Add(updateClientItem.id); ++foundItemCounter; //Trace.WriteLine(String.Format("Match found id: {0}, clientid: {1}", item.otb.id, item.dat.id)); } else { //Sprite matches, but not the other attributes. //Trace.WriteLine(String.Format("Attribute changes found id: {0}.", item.id)); } } } } if (updateSettingsForm.reassignUnmatchedSpritesCheck.Checked) { foreach (Item updateItem in updateItems.Values) { foreach (ServerItem 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) { 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; } } } } } Trace.WriteLine(String.Format("Found {0} of {1}.", foundItemCounter, items.maxId)); if (updateSettingsForm.reloadItemAttributesCheck.Checked) { UInt32 reloadedItemCounter = 0; foreach (ServerItem 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; } } Trace.WriteLine(String.Format("Reloaded {0} of {1} items.", reloadedItemCounter, items.maxId)); } if (updateSettingsForm.createNewItemsCheck.Checked) { UInt32 newItemCounter = 0; foreach (Item updateItem in updateItems.Values) { if (!assignedSpriteIdList.Contains(updateItem.id)) { ++newItemCounter; ServerItem newItem = CreateItem(updateItem); items.Add(newItem); Trace.WriteLine(String.Format("Creating item id {0}", newItem.id)); } } Trace.WriteLine(String.Format("Created {0} new items.", newItemCounter)); } //done BuildItemsListBox(); } }
public void Open(string fileName = null) { if (String.IsNullOrEmpty(fileName)) { FileDialog dialog = new OpenFileDialog(); dialog.Filter = "OTB files (*.otb)|*.otb|All files (*.*)|*.*"; dialog.Title = "Open OTB File"; if (dialog.ShowDialog() != DialogResult.OK || dialog.FileName.Length == 0) { return; } fileName = dialog.FileName; isTemp = false; saved = true; } if (this.Loaded) { this.Clear(); } if (Otb.Open(fileName, ref items)) { currentOtbFullPath = fileName; currentOtbVersion = items.dwMinorVersion; //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; } this.BuildItemsListBox(); 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.itemsListBox.Enabled = true; this.loaded = true; } }