private void loadClientToolStripMenuItem_Click(object sender, EventArgs e) { try { var chooserOptions = new ClientChooserOptions(); chooserOptions.Smart = true; chooserOptions.ShowOTOption = false; chooserOptions.OfflineOnly = true; var c = ClientChooser.ShowBox(chooserOptions); if (c != null) { if (c.Version.OtbMajorVersion != otItems.MajorVersion || c.Version.OtbMinorVersion != otItems.MinorVersion) Trace.WriteLine("[Warning] This client requires the version " + c.Version.OtbMajorVersion + "." + c.Version.OtbMinorVersion + " of items.otb."); c.LoginServers = new LoginServer[] { new LoginServer("127.0.0.1", 7171) }; c.EnableProxy(); Client = c; Trace.WriteLine("Client successfully loaded."); } } catch (Exception ex) { Trace.WriteLine("[Error] Unable to load tibia client. Details: " + ex.StackTrace.ToString()); } }
public static Client ChooseClient(ClientChooserOptions options, object selectedItem, LoginServer loginServer) { Client client = null; if (selectedItem.GetType() == typeof(string)) { switch ((string)selectedItem) { case NewClientDefaultText: client = Client.OpenMC(); break; case NewClientCustomText: OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Executable files (*.exe)|*.exe|All files (*.*)|*.*"; dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); dialog.Title = "Select a Tibia client executable"; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(dialog.FileName); if (fvi.ProductName.Equals("Tibia Player")) { client = Client.OpenMC(dialog.FileName, options.Arguments); if (options.SaveClientPath == true) { ClientChooserBase.SaveClientPath( options.SavedClientPathsLocation, dialog.FileName, fvi.FileVersion); } } else { client = null; } } else { client = null; } break; } } else if (selectedItem.GetType() == typeof(ClientPathInfo)) { string clientPath = ((ClientPathInfo)selectedItem).Path; client = Client.OpenMC(clientPath, options.Arguments); } else { client = (Client)selectedItem; } // Set OT server if (client != null) { if (options.UseOT) { client.LoginServers = new LoginServer[] { loginServer }; client.IsOpenTibiaServer = true; client.WindowText = string.Format("SharpMapTracker - {0}:{1}", loginServer.Server, loginServer.Port); SaveOtServer(options.SavedServersLocation, loginServer, client.Version.FileVersion); } else { client.WindowText = "SharpMapTracker - Global"; } // Set client to run on one processor if instructed by the user if (options.UseSingleProcessor) { client.Process.ProcessorAffinity = (IntPtr)1; } } return(client); }
/// <summary> /// Open a box to pick a client with the desired options. /// </summary> /// <param name="options"></param> /// <returns></returns> public static Client ShowBox(ClientChooserOptions options, IWin32Window owner) { List<Client> clients = null; if (options.LookUpClients) { clients = Client.GetClients(options.Version, options.OfflineOnly); } if (options.Smart && options.LookUpClients && !options.ShowOTOption && clients != null && clients.Count == 1) { return clients[0]; } else { newClientChooser = new ClientChooser(); newClientChooser.Text = String.IsNullOrEmpty(options.Title) ? "Choose a client." : options.Title; if (options.LookUpClients) { foreach (Client c in clients) { newClientChooser.uxClients.Items.Add(c); } } if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"Tibia\tibia.exe"))) { newClientChooser.uxClients.Items.Add(ClientChooserBase.NewClientDefaultText); } foreach (ClientPathInfo cpi in ClientChooserBase.GetClientPaths(options.SavedClientPathsLocation)) { newClientChooser.uxClients.Items.Add(cpi); } newClientChooser.uxClients.Items.Add(ClientChooserBase.NewClientCustomText); newClientChooser.uxClients.SelectedIndex = 0; foreach (var ot in ClientChooserBase.GetServers(options.SavedServersLocation)) { newClientChooser.uxLoginServer.Items.Add(ot.LoginServer.Server + ":" + ot.LoginServer.Port); } if (newClientChooser.uxLoginServer.Items.Count > 0) newClientChooser.uxLoginServer.SelectedIndex = 0; if (options.ShowOTOption) { newClientChooser.Height = 109; newClientChooser.uxUseOT.Checked = options.UseOT; newClientChooser.SetOTState(); newClientChooser.uxLoginServer.Text = options.Server + ":" + options.Port.ToString(); } else { newClientChooser.Height = 54; } newClientChooser.options = options; newClientChooser.TopMost = options.Topmost; newClientChooser.ShowDialog(owner); return client; } }
/// <summary> /// Open a box to pick a client with the desired options. /// </summary> /// <param name="options"></param> /// <returns></returns> public static Client ShowBox(ClientChooserOptions options, IWin32Window owner) { List <Client> clients = null; if (options.LookUpClients) { clients = Client.GetClients(options.Version, options.OfflineOnly); } if (options.Smart && options.LookUpClients && !options.ShowOTOption && clients != null && clients.Count == 1) { return(clients[0]); } else { newClientChooser = new ClientChooser(); newClientChooser.Text = String.IsNullOrEmpty(options.Title) ? "Choose a client." : options.Title; if (options.LookUpClients) { foreach (Client c in clients) { newClientChooser.uxClients.Items.Add(c); } } if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"Tibia\tibia.exe"))) { newClientChooser.uxClients.Items.Add(ClientChooserBase.NewClientDefaultText); } foreach (ClientPathInfo cpi in ClientChooserBase.GetClientPaths(options.SavedClientPathsLocation)) { newClientChooser.uxClients.Items.Add(cpi); } newClientChooser.uxClients.Items.Add(ClientChooserBase.NewClientCustomText); newClientChooser.uxClients.SelectedIndex = 0; foreach (var ot in ClientChooserBase.GetServers(options.SavedServersLocation)) { newClientChooser.uxLoginServer.Items.Add(ot.LoginServer.Server + ":" + ot.LoginServer.Port); } if (newClientChooser.uxLoginServer.Items.Count > 0) { newClientChooser.uxLoginServer.SelectedIndex = 0; } if (options.ShowOTOption) { newClientChooser.Height = 109; newClientChooser.uxUseOT.Checked = options.UseOT; newClientChooser.SetOTState(); newClientChooser.uxLoginServer.Text = options.Server + ":" + options.Port.ToString(); } else { newClientChooser.Height = 54; } newClientChooser.options = options; newClientChooser.TopMost = options.Topmost; newClientChooser.ShowDialog(owner); return(client); } }
public static Client ChooseClient(ClientChooserOptions options, object selectedItem, LoginServer loginServer) { Client client = null; if (selectedItem.GetType() == typeof(string)) { switch ((string)selectedItem) { case NewClientDefaultText: client = Client.OpenMC(); break; case NewClientCustomText: OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Executable files (*.exe)|*.exe|All files (*.*)|*.*"; dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); dialog.Title = "Select a Tibia client executable"; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(dialog.FileName); if (fvi.ProductName.Equals("Tibia Player")) { client = Client.Open(dialog.FileName, options.Arguments); if (options.SaveClientPath == true) { ClientChooserBase.SaveClientPath( options.SavedClientPathsLocation, dialog.FileName, fvi.FileVersion); } } else { client = null; } } else { client = null; } break; } } else if (selectedItem.GetType() == typeof(ClientPathInfo)) { string clientPath = ((ClientPathInfo)selectedItem).Path; client = Client.OpenMC(clientPath, options.Arguments); } else { client = (Client)selectedItem; } // Set OT server if (client != null) { if (options.UseOT) { client.LoginServers = new LoginServer[] { loginServer }; client.IsOpenTibiaServer = true; client.WindowText = string.Format("SharpMapTracker - {0}:{1}", loginServer.Server, loginServer.Port); SaveOtServer(options.SavedServersLocation, loginServer, client.Version.FileVersion); } else { client.WindowText = "SharpMapTracker - Global"; } // Set client to run on one processor if instructed by the user if (options.UseSingleProcessor) client.Process.ProcessorAffinity = (IntPtr)1; } return client; }