From cbe44f75fe421576cba3b7c3c610bb0739e977c8 Mon Sep 17 00:00:00 2001 From: Bitl Date: Tue, 23 Mar 2021 12:13:06 -0700 Subject: [PATCH] ported over to compact. sesperated ports --- Novetus/NovetusCMD/NovetusCMD.cs | 21 +- .../NovetusCore/Classes/SimpleHTTPServer.cs | 21 +- .../StorageAndFunctions/GlobalVars.cs | 2 +- .../StorageAndFunctions/ScriptFuncs.cs | 5 +- .../StorageAndFunctions/SecurityFuncs.cs | 2 +- .../CharacterCustomizationShared.cs | 15 + .../Compact/LauncherFormCompact.Designer.cs | 70 +- .../Compact/LauncherFormCompact.cs | 1155 +---------------- .../Extended/LauncherFormExtended.Designer.cs | 45 +- .../Extended/LauncherFormExtended.cs | 176 +-- .../Forms/LauncherFormShared.cs | 157 ++- .../Forms/SDK/ClientinfoCreator.Designer.cs | 24 +- .../NovetusLauncher/Novetus.Launcher.csproj | 1 + Novetus/NovetusURI/Classes/LocalFuncs.cs | 2 +- 14 files changed, 368 insertions(+), 1328 deletions(-) create mode 100644 Novetus/NovetusLauncher/Forms/CharCustom/CharacterCustomizationShared.cs diff --git a/Novetus/NovetusCMD/NovetusCMD.cs b/Novetus/NovetusCMD/NovetusCMD.cs index 0cc6667..39254e2 100644 --- a/Novetus/NovetusCMD/NovetusCMD.cs +++ b/Novetus/NovetusCMD/NovetusCMD.cs @@ -129,7 +129,8 @@ namespace NovetusCMD { GlobalFuncs.ConsolePrint("WebServer: Server has stopped on port: " + GlobalVars.WebServer.Port.ToString(), 2); GlobalVars.WebServer.Stop(); - } + GlobalVars.WebServer = null; + } catch (Exception ex) { GlobalFuncs.ConsolePrint("WebServer: Failed to stop WebServer. Some features may not function. (" + ex.Message + ")", 2); @@ -230,14 +231,6 @@ namespace NovetusCMD static void ProgramClose(object sender, EventArgs e) { - if (!LocalVars.OverrideINI) - { - WriteConfigValues(); - } - if (GlobalVars.IsWebServerOn) - { - StopWebServer(); - } if (GlobalVars.ProcessID != 0) { if (LocalFuncs.ProcessExists(GlobalVars.ProcessID)) @@ -246,6 +239,16 @@ namespace NovetusCMD proc.Kill(); } } + + if (!LocalVars.OverrideINI) + { + WriteConfigValues(); + } + if (GlobalVars.IsWebServerOn) + { + StopWebServer(); + } + Application.Exit(); } static void LoadCMDArgs(string[] args) diff --git a/Novetus/NovetusCore/Classes/SimpleHTTPServer.cs b/Novetus/NovetusCore/Classes/SimpleHTTPServer.cs index f342412..2423322 100644 --- a/Novetus/NovetusCore/Classes/SimpleHTTPServer.cs +++ b/Novetus/NovetusCore/Classes/SimpleHTTPServer.cs @@ -134,27 +134,28 @@ public class SimpleHTTPServer /// public void Stop() { - _serverThread.Abort(); + _listener.Prefixes.Clear(); _listener.Stop(); GlobalVars.IsWebServerOn = false; + _serverThread.Abort(); } private void Listen() { - _listener = new HttpListener(); - _listener.Prefixes.Add("http://*:" + _port.ToString() + "/"); - _listener.Start(); - while (true) + try { - try + _listener = new HttpListener(); + _listener.Prefixes.Add("http://*:" + _port.ToString() + "/"); + _listener.Start(); + while (true) { HttpListenerContext context = _listener.GetContext(); Process(context); } - catch (Exception) - { - - } + } + catch (Exception) + { + Stop(); } } diff --git a/Novetus/NovetusCore/StorageAndFunctions/GlobalVars.cs b/Novetus/NovetusCore/StorageAndFunctions/GlobalVars.cs index 19284df..988bc7a 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/GlobalVars.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/GlobalVars.cs @@ -33,8 +33,8 @@ public static class GlobalVars #region Joining public static string IP = "localhost"; - public static int JoinPort = 53640; public static int DefaultRobloxPort = 53640; + public static int JoinPort = DefaultRobloxPort; #endregion #region NovetusCMD diff --git a/Novetus/NovetusCore/StorageAndFunctions/ScriptFuncs.cs b/Novetus/NovetusCore/StorageAndFunctions/ScriptFuncs.cs index e2ca831..11d511d 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/ScriptFuncs.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/ScriptFuncs.cs @@ -60,7 +60,7 @@ public class ScriptFuncs return "_G.CSConnect(" + (info.UsesID ? GlobalVars.UserConfiguration.UserID : 0) + ",'" + GlobalVars.IP + "'," - + GlobalVars.UserConfiguration.RobloxPort + ",'" + + GlobalVars.JoinPort + ",'" + (info.UsesPlayerName ? GlobalVars.UserConfiguration.PlayerName : "Player") + "'," + GlobalVars.Loadout + "," + md5s + ",'" @@ -186,7 +186,7 @@ public class ScriptFuncs return "dofile('" + luafile + "'); _G.CSConnect(" + (GlobalVars.SelectedClientInfo.UsesID ? GlobalVars.UserConfiguration.UserID : 0) + ",'" + GlobalVars.IP + "'," - + GlobalVars.UserConfiguration.RobloxPort + ",'" + + GlobalVars.JoinPort + ",'" + (GlobalVars.SelectedClientInfo.UsesPlayerName ? GlobalVars.UserConfiguration.PlayerName : "Player") + "'," + GlobalVars.Loadout + "," + md5s + ",'" @@ -321,6 +321,7 @@ public class ScriptFuncs .Replace("%charapp%", GlobalVars.UserCustomization.CharacterID) .Replace("%ip%", GlobalVars.IP) .Replace("%port%", GlobalVars.UserConfiguration.RobloxPort.ToString()) + .Replace("%joinport%", GlobalVars.JoinPort.ToString()) .Replace("%name%", GlobalVars.UserConfiguration.PlayerName) .Replace("%icone%", ConvertIconStringToInt().ToString()) .Replace("%icon%", GlobalVars.UserCustomization.Icon) diff --git a/Novetus/NovetusCore/StorageAndFunctions/SecurityFuncs.cs b/Novetus/NovetusCore/StorageAndFunctions/SecurityFuncs.cs index 9f13460..b12a3eb 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/SecurityFuncs.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/SecurityFuncs.cs @@ -207,7 +207,7 @@ public class SecurityFuncs + GlobalVars.ProgramInformation.Version + " - " + clientname + " " + ScriptFuncs.Generator.GetNameForType(type) - + " [" + GlobalVars.IP + ":" + GlobalVars.UserConfiguration.RobloxPort + "]" + + " [" + GlobalVars.IP + ":" + GlobalVars.JoinPort + "]" + RandomStringTitle()); break; case ScriptType.Server: diff --git a/Novetus/NovetusLauncher/Forms/CharCustom/CharacterCustomizationShared.cs b/Novetus/NovetusLauncher/Forms/CharCustom/CharacterCustomizationShared.cs new file mode 100644 index 0000000..c8613dd --- /dev/null +++ b/Novetus/NovetusLauncher/Forms/CharCustom/CharacterCustomizationShared.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NovetusLauncher +{ + class CharacterCustomizationShared + { + public CharacterCustomizationShared() + { + //Stub + } + } +} diff --git a/Novetus/NovetusLauncher/Forms/LauncherForm/Compact/LauncherFormCompact.Designer.cs b/Novetus/NovetusLauncher/Forms/LauncherForm/Compact/LauncherFormCompact.Designer.cs index 2b00f73..e1552a8 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherForm/Compact/LauncherFormCompact.Designer.cs +++ b/Novetus/NovetusLauncher/Forms/LauncherForm/Compact/LauncherFormCompact.Designer.cs @@ -63,7 +63,6 @@ namespace NovetusLauncher this.label19 = new System.Windows.Forms.Label(); this.textBox3 = new System.Windows.Forms.TextBox(); this.checkBox4 = new System.Windows.Forms.CheckBox(); - this.button23 = new System.Windows.Forms.Button(); this.button22 = new System.Windows.Forms.Button(); this.numericUpDown3 = new System.Windows.Forms.NumericUpDown(); this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); @@ -366,7 +365,6 @@ namespace NovetusLauncher this.tabPage2.Controls.Add(this.label19); this.tabPage2.Controls.Add(this.textBox3); this.tabPage2.Controls.Add(this.checkBox4); - this.tabPage2.Controls.Add(this.button23); this.tabPage2.Controls.Add(this.button22); this.tabPage2.Controls.Add(this.numericUpDown3); this.tabPage2.Controls.Add(this.numericUpDown2); @@ -441,24 +439,13 @@ namespace NovetusLauncher this.checkBox4.CheckedChanged += new System.EventHandler(this.CheckBox4CheckedChanged); this.checkBox4.Click += new System.EventHandler(this.CheckBox4Click); // - // button23 - // - this.button23.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.button23.Location = new System.Drawing.Point(23, 184); - this.button23.Name = "button23"; - this.button23.Size = new System.Drawing.Size(66, 25); - this.button23.TabIndex = 51; - this.button23.Text = "SAVE"; - this.button23.UseVisualStyleBackColor = true; - this.button23.Click += new System.EventHandler(this.Button23Click); - // // button22 // - this.button22.Location = new System.Drawing.Point(97, 184); + this.button22.Location = new System.Drawing.Point(23, 184); this.button22.Name = "button22"; - this.button22.Size = new System.Drawing.Size(63, 25); + this.button22.Size = new System.Drawing.Size(137, 25); this.button22.TabIndex = 50; - this.button22.Text = "RESET"; + this.button22.Text = "RESET PORT"; this.button22.UseVisualStyleBackColor = true; this.button22.Click += new System.EventHandler(this.Button22Click); // @@ -1428,6 +1415,55 @@ namespace NovetusLauncher this.PerformLayout(); } + + private void InitCompactForm() + { + //*vomits* + launcherForm = new LauncherFormShared(); + launcherForm.Parent = this; + launcherForm.FormStyle = Settings.UIOptions.Style.Compact; + launcherForm.ConsoleBox = richTextBox1; + launcherForm.Tabs = tabControl1; + launcherForm.MapDescBox = textBox4; + launcherForm.ServerInfo = textBox3; + launcherForm.Tree = treeView1; + launcherForm._TreeCache = _fieldsTreeCache; + launcherForm.TabPageHost = "tabPage2"; + launcherForm.TabPageMaps = "tabPage4"; + launcherForm.TabPageClients = "tabPage3"; + launcherForm.TabPageSaved = "tabPage6"; + launcherForm.ServerBox = listBox3; + launcherForm.PortBox = listBox4; + launcherForm.ClientBox = listBox2; + launcherForm.SplashLabel = label12; + launcherForm.SearchBar = SearchBar; + launcherForm.StyleSelectorBox = comboBox3; + launcherForm.ChangelogBox = richTextBox2; + launcherForm.ReadmeBox = richTextBox3; + launcherForm.ProductVersionLabel = label8; + launcherForm.NovetusVersionLabel = label11; + launcherForm.WebServerCheckbox = checkBox8; + launcherForm.CloseOnLaunchCheckbox = checkBox1; + launcherForm.DiscordPresenceCheckbox = checkBox2; + launcherForm.uPnPCheckBox = checkBox4; + launcherForm.ShowServerNotifsCheckBox = checkBox9; + launcherForm.PlayerIDTextBox = textBox5; + launcherForm.PlayerTripcodeLabel = label18; + launcherForm.RegeneratePlayerIDButton = button4; + launcherForm.PlayerNameTextBox = textBox2; + launcherForm.LocalPlayCheckBox = checkBox3; + launcherForm.IPLabel = label37; + launcherForm.PortLabel = label38; + launcherForm.SelectedClientLabel = label26; + launcherForm.SelectedMapLabel = label28; + launcherForm.PlayerLimitBox = numericUpDown3; + launcherForm.HostPortBox = numericUpDown2; + launcherForm.JoinPortBox = numericUpDown1; + launcherForm.ClientWarningLabel = label30; + launcherForm.ClientDescriptionBox = textBox6; + launcherForm.IPBox = textBox1; + } + private System.Windows.Forms.CheckBox checkBox4; private System.Windows.Forms.Button button6; private System.Windows.Forms.TreeView treeView1; @@ -1437,7 +1473,6 @@ namespace NovetusLauncher private System.Windows.Forms.Label label7; private System.Windows.Forms.Label label2; private System.Windows.Forms.TabPage tabPage5; - private System.Windows.Forms.Button button23; private System.Windows.Forms.Button button22; private System.Windows.Forms.Button button7; private System.Windows.Forms.PictureBox pictureBox2; @@ -1545,5 +1580,6 @@ namespace NovetusLauncher private System.Windows.Forms.Button button36; private System.Windows.Forms.CheckBox checkBox9; //private System.Windows.Forms.CheckBox checkBox8; + private LauncherFormShared launcherForm; } } diff --git a/Novetus/NovetusLauncher/Forms/LauncherForm/Compact/LauncherFormCompact.cs b/Novetus/NovetusLauncher/Forms/LauncherForm/Compact/LauncherFormCompact.cs index e4a1b57..e0be179 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherForm/Compact/LauncherFormCompact.cs +++ b/Novetus/NovetusLauncher/Forms/LauncherForm/Compact/LauncherFormCompact.cs @@ -15,556 +15,54 @@ namespace NovetusLauncher #region LauncherForm - Compact public partial class LauncherFormCompact : Form { - #region Private Variables - private DiscordRPC.EventHandlers handlers; - private List CurrentNodeMatches = new List(); - private int LastNodeIndex = 0; - private string LastSearchText; - #endregion - #region Constructor public LauncherFormCompact() { _fieldsTreeCache = new TreeView(); InitializeComponent(); - } - #endregion - - #region UPnP - public void InitUPnP() - { - if (GlobalVars.UserConfiguration.UPnP) - { - try - { - NetFuncs.InitUPnP(DeviceFound, DeviceLost); - GlobalFuncs.ConsolePrint("UPnP: Service initialized", 3, richTextBox1); - } - catch (Exception ex) - { - GlobalFuncs.ConsolePrint("UPnP: Unable to initialize UPnP. Reason - " + ex.Message, 2, richTextBox1); - } - } - } - - public void StartUPnP(INatDevice device, Protocol protocol, int port) - { - if (GlobalVars.UserConfiguration.UPnP) - { - try - { - NetFuncs.StartUPnP(device, protocol, port); - string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString()); - GlobalFuncs.ConsolePrint("UPnP: Port " + port + " opened on '" + IP + "' (" + protocol.ToString() + ")", 3, richTextBox1); - } - catch (Exception ex) - { - GlobalFuncs.ConsolePrint("UPnP: Unable to open port mapping. Reason - " + ex.Message, 2, richTextBox1); - } - } - } - - public void StopUPnP(INatDevice device, Protocol protocol, int port) - { - if (GlobalVars.UserConfiguration.UPnP) - { - try - { - NetFuncs.StopUPnP(device, protocol, port); - string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString()); - GlobalFuncs.ConsolePrint("UPnP: Port " + port + " closed on '" + IP + "' (" + protocol.ToString() + ")", 3, richTextBox1); - } - catch (Exception ex) - { - GlobalFuncs.ConsolePrint("UPnP: Unable to close port mapping. Reason - " + ex.Message, 2, richTextBox1); - } - } - } - - private void DeviceFound(object sender, DeviceEventArgs args) - { - try - { - INatDevice device = args.Device; - string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString()); - GlobalFuncs.ConsolePrint("UPnP: Device '" + IP + "' registered.", 3, richTextBox1); - StartUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.RobloxPort); - StartUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.RobloxPort); - StartUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.WebServerPort); - StartUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.WebServerPort); - } - catch (Exception ex) - { - GlobalFuncs.ConsolePrint("UPnP: Unable to register device. Reason - " + ex.Message, 2, richTextBox1); - } - } - - private void DeviceLost(object sender, DeviceEventArgs args) - { - try - { - INatDevice device = args.Device; - string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString()); - GlobalFuncs.ConsolePrint("UPnP: Device '" + IP + "' disconnected.", 3, richTextBox1); - StopUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.RobloxPort); - StopUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.RobloxPort); - StopUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.WebServerPort); - StopUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.WebServerPort); - } - catch (Exception ex) - { - GlobalFuncs.ConsolePrint("UPnP: Unable to disconnect device. Reason - " + ex.Message, 2, richTextBox1); - } - } - #endregion - - #region Discord - public void ReadyCallback() - { - GlobalFuncs.ConsolePrint("Discord RPC: Ready", 3, richTextBox1); - } - - public void DisconnectedCallback(int errorCode, string message) - { - GlobalFuncs.ConsolePrint("Discord RPC: Disconnected. Reason - " + errorCode + ": " + message, 2, richTextBox1); - } - - public void ErrorCallback(int errorCode, string message) - { - GlobalFuncs.ConsolePrint("Discord RPC: Error. Reason - " + errorCode + ": " + message, 2, richTextBox1); - } - - public void JoinCallback(string secret) - { - } - - public void SpectateCallback(string secret) - { - } - - public void RequestCallback(DiscordRPC.JoinRequest request) - { - } - - void StartDiscord() - { - if (GlobalVars.UserConfiguration.DiscordPresence) - { - handlers = new DiscordRPC.EventHandlers(); - handlers.readyCallback = ReadyCallback; - handlers.disconnectedCallback += DisconnectedCallback; - handlers.errorCallback += ErrorCallback; - handlers.joinCallback += JoinCallback; - handlers.spectateCallback += SpectateCallback; - handlers.requestCallback += RequestCallback; - DiscordRPC.Initialize(GlobalVars.appid, ref handlers, true, ""); - - GlobalFuncs.UpdateRichPresence(GlobalVars.LauncherState.InLauncher, "", true); - } - } - #endregion - - #region Web Server - //udp clients will connect to the web server alongside the game. - void StartWebServer() - { - if (SecurityFuncs.IsElevated) - { - try - { - GlobalVars.WebServer = new SimpleHTTPServer(GlobalPaths.DataPath, GlobalVars.UserConfiguration.WebServerPort); - GlobalFuncs.ConsolePrint("WebServer: Server is running on port: " + GlobalVars.WebServer.Port.ToString(), 3, richTextBox1); - } - catch (Exception ex) - { - GlobalFuncs.ConsolePrint("WebServer: Failed to launch WebServer. Some features may not function. (" + ex.Message + ")", 2, richTextBox1); - } - } - else - { - GlobalFuncs.ConsolePrint("WebServer: Failed to launch WebServer. Some features may not function. (Did not run as Administrator)", 2, richTextBox1); - } - } - - void StopWebServer() - { - if (SecurityFuncs.IsElevated) - { - try - { - GlobalFuncs.ConsolePrint("WebServer: Server has stopped on port: " + GlobalVars.WebServer.Port.ToString(), 2, richTextBox1); - GlobalVars.WebServer.Stop(); - } - catch (Exception ex) - { - GlobalFuncs.ConsolePrint("WebServer: Failed to stop WebServer. Some features may not function. (" + ex.Message + ")", 2, richTextBox1); - } - } - else - { - GlobalFuncs.ConsolePrint("WebServer: Failed to stop WebServer. Some features may not function. (Did not run as Administrator)", 2, richTextBox1); - } + InitCompactForm(); } #endregion #region Form Events async void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { - switch (tabControl1.SelectedTab) - { - case TabPage pg2 when pg2 == tabControl1.TabPages["tabPage2"]: - treeView1.Nodes.Clear(); - _fieldsTreeCache.Nodes.Clear(); - textBox4.Text = ""; - listBox2.Items.Clear(); - listBox3.Items.Clear(); - listBox4.Items.Clear(); - //since we are async, DO THESE first or we'll clear out random stuff. - textBox3.Text = "Loading..."; - string IP = await SecurityFuncs.GetExternalIPAddressAsync(); - textBox3.Text = ""; - string[] lines1 = { - SecurityFuncs.Base64Encode((!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : IP)), - SecurityFuncs.Base64Encode(GlobalVars.UserConfiguration.RobloxPort.ToString()), - SecurityFuncs.Base64Encode(GlobalVars.UserConfiguration.SelectedClient) - }; - string URI = "novetus://" + SecurityFuncs.Base64Encode(string.Join("|", lines1), true); - string[] lines2 = { - SecurityFuncs.Base64Encode("localhost"), - SecurityFuncs.Base64Encode(GlobalVars.UserConfiguration.RobloxPort.ToString()), - SecurityFuncs.Base64Encode(GlobalVars.UserConfiguration.SelectedClient) - }; - string URI2 = "novetus://" + SecurityFuncs.Base64Encode(string.Join("|", lines2), true); - string[] text = { - "Client: " + GlobalVars.UserConfiguration.SelectedClient, - "IP: " + (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : IP), - "Port: " + GlobalVars.UserConfiguration.RobloxPort.ToString(), - "Map: " + GlobalVars.UserConfiguration.Map, - "Players: " + GlobalVars.UserConfiguration.PlayerLimit, - "Version: Novetus " + GlobalVars.ProgramInformation.Version, - "Online URI Link:", - URI, - "Local URI Link:", - URI2, - GlobalVars.IsWebServerOn ? "Web Server URL:" : "", - GlobalVars.IsWebServerOn ? "http://" + (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : IP) + ":" + GlobalVars.WebServer.Port.ToString() : "", - GlobalVars.IsWebServerOn ? "Local Web Server URL:" : "", - GlobalVars.IsWebServerOn ? "http://localhost:" + (GlobalVars.WebServer.Port.ToString()).ToString() : "" - }; - - foreach (string str in text) - { - if (!string.IsNullOrWhiteSpace(str)) - { - textBox3.AppendText(str + Environment.NewLine); - } - } - textBox3.SelectionStart = 0; - textBox3.ScrollToCaret(); - break; - case TabPage pg4 when pg4 == tabControl1.TabPages["tabPage4"]: - string mapdir = GlobalPaths.MapsDir; - string[] fileexts = new string[] { ".rbxl", ".rbxlx"}; - TreeNodeHelper.ListDirectory(treeView1, mapdir, fileexts); - TreeNodeHelper.CopyNodes(treeView1.Nodes, _fieldsTreeCache.Nodes); - treeView1.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.UserConfiguration.Map, treeView1.Nodes); - treeView1.Focus(); - textBox3.Text = ""; - listBox2.Items.Clear(); - listBox3.Items.Clear(); - listBox4.Items.Clear(); - break; - case TabPage pg3 when pg3 == tabControl1.TabPages["tabPage3"]: - string clientdir = GlobalPaths.ClientDir; - DirectoryInfo dinfo = new DirectoryInfo(clientdir); - DirectoryInfo[] Dirs = dinfo.GetDirectories(); - foreach (DirectoryInfo dir in Dirs) - { - listBox2.Items.Add(dir.Name); - } - listBox2.SelectedItem = GlobalVars.UserConfiguration.SelectedClient; - treeView1.Nodes.Clear(); - _fieldsTreeCache.Nodes.Clear(); - textBox4.Text = ""; - textBox3.Text = ""; - listBox3.Items.Clear(); - listBox4.Items.Clear(); - break; - case TabPage pg6 when pg6 == tabControl1.TabPages["tabPage6"]: - string[] lines_server = File.ReadAllLines(GlobalPaths.ConfigDir + "\\servers.txt"); - string[] lines_ports = File.ReadAllLines(GlobalPaths.ConfigDir + "\\ports.txt"); - listBox3.Items.AddRange(lines_server); - listBox4.Items.AddRange(lines_ports); - treeView1.Nodes.Clear(); - _fieldsTreeCache.Nodes.Clear(); - textBox4.Text = ""; - textBox3.Text = ""; - listBox2.Items.Clear(); - break; - default: - treeView1.Nodes.Clear(); - _fieldsTreeCache.Nodes.Clear(); - textBox4.Text = ""; - textBox3.Text = ""; - listBox2.Items.Clear(); - listBox3.Items.Clear(); - listBox4.Items.Clear(); - break; - } + await launcherForm.ChangeTabs(); } void Button1Click(object sender, EventArgs e) { - if (GlobalVars.LocalPlayMode) - { - GeneratePlayerID(); - GenerateTripcode(); - } - else - { - WriteConfigValues(); - } - - StartClient(); - - if (GlobalVars.UserConfiguration.CloseOnLaunch) - { - Visible = false; - } + launcherForm.StartGame(ScriptType.Client); } void Button2Click(object sender, EventArgs e) { - WriteConfigValues(); - StartServer(false); + launcherForm.StartGame(ScriptType.Server); + } - if (GlobalVars.UserConfiguration.CloseOnLaunch) - { - Visible = false; - } + void Button3Click_legacy(object sender, EventArgs e) + { + launcherForm.StartGame(ScriptType.Studio); } void Button18Click(object sender, EventArgs e) { - WriteConfigValues(); - StartServer(true); - - if (GlobalVars.UserConfiguration.CloseOnLaunch) - { - Visible = false; - } + launcherForm.StartGame(ScriptType.Server, true); } void Button19Click(object sender, EventArgs e) { - WriteConfigValues(); - StartSolo(); - - if (GlobalVars.UserConfiguration.CloseOnLaunch) - { - Visible = false; - } + launcherForm.StartGame(ScriptType.Solo); } void MainFormLoad(object sender, EventArgs e) { - Text = "Novetus " + GlobalVars.ProgramInformation.Version; - GlobalFuncs.ConsolePrint("Novetus version " + GlobalVars.ProgramInformation.Version + " loaded. Initializing config.", 4, richTextBox1); - GlobalFuncs.ConsolePrint("Novetus path: " + GlobalPaths.BasePath, 4, richTextBox1); - - if (File.Exists(GlobalPaths.RootPath + "\\changelog.txt")) - { - richTextBox2.Text = File.ReadAllText(GlobalPaths.RootPath + "\\changelog.txt"); - } - else - { - GlobalFuncs.ConsolePrint("ERROR - " + GlobalPaths.RootPath + "\\changelog.txt not found.", 2, richTextBox1); - } - - if (File.Exists(GlobalPaths.RootPath + "\\README-AND-CREDITS.TXT")) - { - richTextBox3.Text = File.ReadAllText(GlobalPaths.RootPath + "\\README-AND-CREDITS.TXT"); - } - else - { - GlobalFuncs.ConsolePrint("ERROR - " + GlobalPaths.RootPath + "\\README-AND-CREDITS.TXT not found.", 2, richTextBox1); - } - - if (!File.Exists(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigName)) - { - GlobalFuncs.ConsolePrint("WARNING - " + GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigName + " not found. Creating one with default values.", 5, richTextBox1); - WriteConfigValues(); - } - if (!File.Exists(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigNameCustomization)) - { - GlobalFuncs.ConsolePrint("WARNING - " + GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigNameCustomization + " not found. Creating one with default values.", 5, richTextBox1); - WriteCustomizationValues(); - } - if (!File.Exists(GlobalPaths.ConfigDir + "\\servers.txt")) - { - GlobalFuncs.ConsolePrint("WARNING - " + GlobalPaths.ConfigDir + "\\servers.txt not found. Creating empty file.", 5, richTextBox1); - File.Create(GlobalPaths.ConfigDir + "\\servers.txt").Dispose(); - } - if (!File.Exists(GlobalPaths.ConfigDir + "\\ports.txt")) - { - GlobalFuncs.ConsolePrint("WARNING - " + GlobalPaths.ConfigDir + "\\ports.txt not found. Creating empty file.", 5, richTextBox1); - File.Create(GlobalPaths.ConfigDir + "\\ports.txt").Dispose(); - } - - GlobalFuncs.CreateAssetCacheDirectories(); - - label8.Text = Application.ProductVersion; - LocalVars.important = SecurityFuncs.GenerateMD5(Assembly.GetExecutingAssembly().Location); - label11.Text = GlobalVars.ProgramInformation.Version; - - label12.Text = SplashReader.GetSplash(); - LocalVars.prevsplash = label12.Text; - - ReadConfigValues(true); - InitUPnP(); - StartDiscord(); - if (GlobalVars.UserConfiguration.WebServer) - { - StartWebServer(); - } + launcherForm.InitForm(); } void MainFormClose(object sender, CancelEventArgs e) { - CloseEvent(); - } - - void CloseEvent() - { - if (!GlobalVars.LocalPlayMode) - { - WriteConfigValues(); - } - if (GlobalVars.UserConfiguration.DiscordPresence) - { - DiscordRPC.Shutdown(); - } - if (GlobalVars.IsWebServerOn) - { - StopWebServer(); - } - } - - void ReadConfigValues(bool initial = false) - { - GlobalFuncs.Config(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigName, false); - - checkBox1.Checked = GlobalVars.UserConfiguration.CloseOnLaunch; - textBox5.Text = GlobalVars.UserConfiguration.UserID.ToString(); - label18.Text = GlobalVars.UserConfiguration.PlayerTripcode.ToString(); - numericUpDown3.Value = Convert.ToDecimal(GlobalVars.UserConfiguration.PlayerLimit); - textBox2.Text = GlobalVars.UserConfiguration.PlayerName; - label26.Text = GlobalVars.UserConfiguration.SelectedClient; - label28.Text = GlobalVars.UserConfiguration.Map; - treeView1.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.UserConfiguration.Map, treeView1.Nodes); - treeView1.Focus(); - numericUpDown1.Value = Convert.ToDecimal(GlobalVars.UserConfiguration.RobloxPort); - numericUpDown2.Value = Convert.ToDecimal(GlobalVars.UserConfiguration.RobloxPort); - label37.Text = GlobalVars.IP; - label38.Text = GlobalVars.UserConfiguration.RobloxPort.ToString(); - checkBox2.Checked = GlobalVars.UserConfiguration.DiscordPresence; - checkBox4.Checked = GlobalVars.UserConfiguration.UPnP; - checkBox9.Checked = GlobalVars.UserConfiguration.ShowServerNotifications; - - if (SecurityFuncs.IsElevated) - { - checkBox8.Enabled = true; - checkBox8.Checked = GlobalVars.UserConfiguration.WebServer; - } - else - { - checkBox8.Enabled = false; - } - - switch (GlobalVars.UserConfiguration.LauncherStyle) - { - case Settings.UIOptions.Style.Compact: - comboBox3.SelectedIndex = 1; - break; - case Settings.UIOptions.Style.Extended: - default: - comboBox3.SelectedIndex = 0; - break; - } - - GlobalFuncs.ConsolePrint("Config loaded.", 3, richTextBox1); - ReadClientValues(initial); - } - - void WriteConfigValues() - { - GlobalFuncs.Config(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigName, true); - GlobalFuncs.ReadClientValues(richTextBox1); - GlobalFuncs.ConsolePrint("Config Saved.", 3, richTextBox1); - } - - void WriteCustomizationValues() - { - GlobalFuncs.Customization(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigNameCustomization, true); - GlobalFuncs.ConsolePrint("Config Saved.", 3, richTextBox1); - } - - void ReadClientValues(bool initial = false) - { - GlobalFuncs.ReadClientValues(richTextBox1, initial); - - switch (GlobalVars.SelectedClientInfo.UsesPlayerName) - { - case true: - textBox2.Enabled = true; - break; - case false: - textBox2.Enabled = false; - break; - } - - switch (GlobalVars.SelectedClientInfo.UsesID) - { - case true: - textBox5.Enabled = true; - button4.Enabled = true; - if (GlobalVars.IP.Equals("localhost")) - { - checkBox3.Enabled = true; - } - break; - case false: - textBox5.Enabled = false; - button4.Enabled = false; - checkBox3.Enabled = false; - GlobalVars.LocalPlayMode = false; - break; - } - - if (!string.IsNullOrWhiteSpace(GlobalVars.SelectedClientInfo.Warning)) - { - label30.Text = GlobalVars.SelectedClientInfo.Warning; - label30.Visible = true; - } - else - { - label30.Visible = false; - } - - textBox6.Text = GlobalVars.SelectedClientInfo.Description; - label26.Text = GlobalVars.UserConfiguration.SelectedClient; - } - - void GeneratePlayerID() - { - GlobalFuncs.GeneratePlayerID(); - textBox5.Text = Convert.ToString(GlobalVars.UserConfiguration.UserID); - } - - void GenerateTripcode() - { - GlobalFuncs.GenerateTripcode(); - label18.Text = GlobalVars.UserConfiguration.PlayerTripcode; + launcherForm.CloseEvent(); } void TextBox1TextChanged(object sender, EventArgs e) @@ -582,13 +80,12 @@ namespace NovetusLauncher void Button4Click(object sender, EventArgs e) { - GeneratePlayerID(); + launcherForm.GeneratePlayerID(); } void Button5Click(object sender, EventArgs e) { - WriteConfigValues(); - MessageBox.Show("Config Saved!"); + launcherForm.WriteConfigValues(true); } void TextBox2TextChanged(object sender, EventArgs e) @@ -598,29 +95,7 @@ namespace NovetusLauncher void ListBox2SelectedIndexChanged(object sender, EventArgs e) { - string ourselectedclient = GlobalVars.UserConfiguration.SelectedClient; - GlobalVars.UserConfiguration.SelectedClient = listBox2.SelectedItem.ToString(); - if (!ourselectedclient.Equals(GlobalVars.UserConfiguration.SelectedClient)) - { - ReadClientValues(true); - } - else - { - ReadClientValues(); - } - GlobalFuncs.UpdateRichPresence(GlobalVars.LauncherState.InLauncher, ""); - - FormCollection fc = Application.OpenForms; - - foreach (Form frm in fc) - { - //iterate through - if (frm.Name == "CustomGraphicsOptions") - { - frm.Close(); - break; - } - } + launcherForm.ChangeClient(); } void CheckBox3CheckedChanged(object sender, EventArgs e) @@ -630,22 +105,7 @@ namespace NovetusLauncher void TextBox5TextChanged(object sender, EventArgs e) { - int parsedValue; - if (int.TryParse(textBox5.Text, out parsedValue)) - { - if (textBox5.Text.Equals("")) - { - GlobalVars.UserConfiguration.UserID = 0; - } - else - { - GlobalVars.UserConfiguration.UserID = Convert.ToInt32(textBox5.Text); - } - } - else - { - GlobalVars.UserConfiguration.UserID = 0; - } + launcherForm.ChangeUserID(); } void Button8Click(object sender, EventArgs e) @@ -656,364 +116,77 @@ namespace NovetusLauncher void Button9Click(object sender, EventArgs e) { - ResetConfigValues(); - MessageBox.Show("Config Reset!"); + launcherForm.ResetConfigValues(true); } void ListBox3SelectedIndexChanged(object sender, EventArgs e) { - GlobalVars.IP = listBox3.SelectedItem.ToString(); - textBox1.Text = GlobalVars.IP; - checkBox3.Enabled = false; - GlobalVars.LocalPlayMode = false; - label37.Text = GlobalVars.IP; + launcherForm.SelectIPListing(); } void ListBox4SelectedIndexChanged(object sender, EventArgs e) { - GlobalVars.UserConfiguration.RobloxPort = Convert.ToInt32(listBox4.SelectedItem.ToString()); - numericUpDown1.Value = Convert.ToDecimal(GlobalVars.UserConfiguration.RobloxPort); - numericUpDown2.Value = Convert.ToDecimal(GlobalVars.UserConfiguration.RobloxPort); + launcherForm.SelectPortListing(); } void Button10Click(object sender, EventArgs e) { - File.AppendAllText(GlobalPaths.ConfigDir + "\\servers.txt", GlobalVars.IP + Environment.NewLine); + launcherForm.AddIPPortListing(null, GlobalPaths.ConfigDir + "\\servers.txt", GlobalVars.IP); } void Button11Click(object sender, EventArgs e) { - File.AppendAllText(GlobalPaths.ConfigDir + "\\ports.txt", GlobalVars.UserConfiguration.RobloxPort + Environment.NewLine); + launcherForm.AddIPPortListing(null, GlobalPaths.ConfigDir + "\\ports.txt", GlobalVars.JoinPort); } void Button12Click(object sender, EventArgs e) { - if (listBox3.SelectedIndex >= 0) - { - TextLineRemover.RemoveTextLines(new List { listBox3.SelectedItem.ToString() }, GlobalPaths.ConfigDir + "\\servers.txt", GlobalPaths.ConfigDir + "\\servers.tmp"); - listBox3.Items.Clear(); - string[] lines_server = File.ReadAllLines(GlobalPaths.ConfigDir + "\\servers.txt"); - listBox3.Items.AddRange(lines_server); - } + launcherForm.RemoveIPPortListing(listBox3, GlobalPaths.ConfigDir + "\\servers.txt", GlobalPaths.ConfigDir + "\\servers.tmp"); } void Button13Click(object sender, EventArgs e) { - if (listBox4.SelectedIndex >= 0) - { - TextLineRemover.RemoveTextLines(new List { listBox4.SelectedItem.ToString() }, GlobalPaths.ConfigDir + "\\ports.txt", GlobalPaths.ConfigDir + "\\ports.tmp"); - listBox4.Items.Clear(); - string[] lines_ports = File.ReadAllLines(GlobalPaths.ConfigDir + "\\ports.txt"); - listBox4.Items.AddRange(lines_ports); - } + launcherForm.RemoveIPPortListing(listBox4, GlobalPaths.ConfigDir + "\\ports.txt", GlobalPaths.ConfigDir + "\\ports.tmp"); } void Button14Click(object sender, EventArgs e) { - File.Create(GlobalPaths.ConfigDir + "\\servers.txt").Dispose(); - listBox3.Items.Clear(); - string[] lines_server = File.ReadAllLines(GlobalPaths.ConfigDir + "\\servers.txt"); - listBox3.Items.AddRange(lines_server); + launcherForm.ResetIPPortListing(listBox3, GlobalPaths.ConfigDir + "\\servers.txt"); } void Button15Click(object sender, EventArgs e) { - File.Create(GlobalPaths.ConfigDir + "\\ports.txt").Dispose(); - listBox4.Items.Clear(); - string[] lines_ports = File.ReadAllLines(GlobalPaths.ConfigDir + "\\ports.txt"); - listBox4.Items.AddRange(lines_ports); + launcherForm.ResetIPPortListing(listBox4, GlobalPaths.ConfigDir + "\\ports.txt"); } void Button16Click(object sender, EventArgs e) { - File.AppendAllText(GlobalPaths.ConfigDir + "\\servers.txt", GlobalVars.IP + Environment.NewLine); - listBox3.Items.Clear(); - string[] lines_server = File.ReadAllLines(GlobalPaths.ConfigDir + "\\servers.txt"); - listBox3.Items.AddRange(lines_server); + launcherForm.AddIPPortListing(listBox3, GlobalPaths.ConfigDir + "\\servers.txt", GlobalVars.IP); } void Button17Click(object sender, EventArgs e) { - File.AppendAllText(GlobalPaths.ConfigDir + "\\ports.txt", GlobalVars.UserConfiguration.RobloxPort + Environment.NewLine); - listBox4.Items.Clear(); - string[] lines_ports = File.ReadAllLines(GlobalPaths.ConfigDir + "\\ports.txt"); - listBox4.Items.AddRange(lines_ports); + launcherForm.AddIPPortListing(listBox4, GlobalPaths.ConfigDir + "\\ports.txt", GlobalVars.JoinPort); } - - void richTextBox1_KeyDown(object sender, KeyEventArgs e) { - //Command proxy - - int totalLines = richTextBox1.Lines.Length; - if (totalLines > 0) - { - string lastLine = richTextBox1.Lines[totalLines - 1]; - - if (e.KeyCode == Keys.Enter) - { - richTextBox1.AppendText(Environment.NewLine); - ConsoleProcessCommands(lastLine); - e.Handled = true; - } - } - - if (e.Modifiers == Keys.Control) - { - switch (e.KeyCode) - { - case Keys.X: - case Keys.Z: - e.Handled = true; - break; - default: - break; - } - } - } - - void ResetConfigValues() - { - //https://stackoverflow.com/questions/9029351/close-all-open-forms-except-the-main-menu-in-c-sharp - List
openForms = new List(); - - foreach (Form f in Application.OpenForms) - openForms.Add(f); - - foreach (Form f in openForms) - { - if (f.Name != "LauncherFormCompact") - f.Close(); - } - - GlobalFuncs.ResetConfigValues(true); - WriteConfigValues(); - ReadConfigValues(); - } - - void StartClient() - { - GlobalFuncs.LaunchRBXClient(ScriptType.Client, false, true, new EventHandler(ClientExited), richTextBox1); - } - - void StartSolo() - { - GlobalFuncs.LaunchRBXClient(ScriptType.Solo, false, false, new EventHandler(ClientExited), richTextBox1); - } - - void StartServer(bool no3d) - { - GlobalFuncs.LaunchRBXClient(ScriptType.Server, no3d, false, new EventHandler(ServerExited), richTextBox1); - } - - void StartStudio(bool nomap) - { - GlobalFuncs.LaunchRBXClient(ScriptType.Studio, false, nomap, new EventHandler(ClientExited), richTextBox1); - } - - void StartEasterEgg() - { - GlobalFuncs.LaunchRBXClient(ScriptType.EasterEgg, false, false, new EventHandler(EasterEggExited), richTextBox1); - } - - void ClientExited(object sender, EventArgs e) - { - GlobalFuncs.UpdateRichPresence(GlobalVars.LauncherState.InLauncher, ""); - if (GlobalVars.UserConfiguration.CloseOnLaunch) - { - Visible = true; - } - } - - void ServerExited(object sender, EventArgs e) - { - if (GlobalVars.UserConfiguration.CloseOnLaunch) - { - Visible = true; - } - } - - void EasterEggExited(object sender, EventArgs e) - { - GlobalFuncs.UpdateRichPresence(GlobalVars.LauncherState.InLauncher, ""); - label12.Text = LocalVars.prevsplash; - if (GlobalVars.UserConfiguration.CloseOnLaunch) - { - Visible = true; - } - } - - void ConsoleProcessCommands(string cmd) - { - switch (cmd) - { - case string server3d when string.Compare(server3d, "server 3d", true, CultureInfo.InvariantCulture) == 0: - StartServer(false); - break; - case string serverno3d when string.Compare(serverno3d, "server no3d", true, CultureInfo.InvariantCulture) == 0: - StartServer(false); - break; - case string client when string.Compare(client, "client", true, CultureInfo.InvariantCulture) == 0: - StartClient(); - break; - case string solo when string.Compare(solo, "solo", true, CultureInfo.InvariantCulture) == 0: - StartSolo(); - break; - case string studiomap when string.Compare(studiomap, "studio map", true, CultureInfo.InvariantCulture) == 0: - StartStudio(false); - break; - case string studionomap when string.Compare(studionomap, "studio nomap", true, CultureInfo.InvariantCulture) == 0: - StartStudio(true); - break; - case string configsave when string.Compare(configsave, "config save", true, CultureInfo.InvariantCulture) == 0: - WriteConfigValues(); - break; - case string configload when string.Compare(configload, "config load", true, CultureInfo.InvariantCulture) == 0: - ReadConfigValues(); - break; - case string configreset when string.Compare(configreset, "config reset", true, CultureInfo.InvariantCulture) == 0: - ResetConfigValues(); - break; - case string help when string.Compare(help, "help", true, CultureInfo.InvariantCulture) == 0: - ConsoleHelp(); - break; - case string sdk when string.Compare(sdk, "sdk", true, CultureInfo.InvariantCulture) == 0: - LoadLauncher(); - break; - case string webserverstart when string.Compare(webserverstart, "webserver start", true, CultureInfo.InvariantCulture) == 0: - if (!GlobalVars.IsWebServerOn) - { - StartWebServer(); - } - else - { - GlobalFuncs.ConsolePrint("WebServer: There is already a web server on.", 2, richTextBox1); - } - break; - case string webserverstop when string.Compare(webserverstop, "webserver stop", true, CultureInfo.InvariantCulture) == 0: - if (GlobalVars.IsWebServerOn) - { - StopWebServer(); - } - else - { - GlobalFuncs.ConsolePrint("WebServer: There is no web server on.", 2, richTextBox1); - } - break; - case string webserverrestart when string.Compare(webserverrestart, "webserver restart", true, CultureInfo.InvariantCulture) == 0: - try - { - GlobalFuncs.ConsolePrint("WebServer: Restarting...", 4, richTextBox1); - StopWebServer(); - StartWebServer(); - } - catch (Exception ex) - { - GlobalFuncs.ConsolePrint("WebServer: Cannot restart web server. (" + ex.Message + ")", 2, richTextBox1); - } - break; - case string dlldeleteon when string.Compare(dlldeleteon, "dlldelete on", true, CultureInfo.InvariantCulture) == 0: - GlobalVars.UserConfiguration.DisableReshadeDelete = false; - GlobalFuncs.ConsolePrint("ReShade DLL deletion enabled.", 4, richTextBox1); - break; - case string dlldeleteoff when string.Compare(dlldeleteoff, "dlldelete off", true, CultureInfo.InvariantCulture) == 0: - GlobalVars.UserConfiguration.DisableReshadeDelete = true; - GlobalFuncs.ConsolePrint("ReShade DLL deletion disabled.", 4, richTextBox1); - break; - case string important when string.Compare(important, LocalVars.important, true, CultureInfo.InvariantCulture) == 0: - GlobalVars.AdminMode = true; - GlobalFuncs.ConsolePrint("ADMIN MODE ENABLED.", 4, richTextBox1); - GlobalFuncs.ConsolePrint("YOU ARE GOD.", 2, richTextBox1); - break; - default: - GlobalFuncs.ConsolePrint("ERROR 3 - Command is either not registered or valid", 2, richTextBox1); - break; - } - } - - void LoadLauncher() - { - NovetusSDK im = new NovetusSDK(); - im.Show(); - GlobalFuncs.ConsolePrint("Novetus SDK Launcher Loaded.", 4, richTextBox1); - } - - void ConsoleHelp() - { - GlobalFuncs.ConsolePrint("Help:", 3, richTextBox1); - GlobalFuncs.ConsolePrint("---------", 1, richTextBox1); - GlobalFuncs.ConsolePrint("= client | Launches client with launcher settings", 4, richTextBox1); - GlobalFuncs.ConsolePrint("= solo | Launches client in Play Solo mode with launcher settings", 4, richTextBox1); - GlobalFuncs.ConsolePrint("= server 3d | Launches server with launcher settings", 4, richTextBox1); - GlobalFuncs.ConsolePrint("= server no3d | Launches server in NoGraphics mode with launcher settings", 4, richTextBox1); - GlobalFuncs.ConsolePrint("= studio map | Launches Roblox Studio with the selected map", 4, richTextBox1); - GlobalFuncs.ConsolePrint("= studio nomap | Launches Roblox Studio without the selected map", 4, richTextBox1); - GlobalFuncs.ConsolePrint("= sdk | Launches the Novetus SDK Launcher", 4, richTextBox1); - GlobalFuncs.ConsolePrint("---------", 1, richTextBox1); - GlobalFuncs.ConsolePrint("= config save | Saves the config file", 4, richTextBox1); - GlobalFuncs.ConsolePrint("= config load | Reloads the config file", 4, richTextBox1); - GlobalFuncs.ConsolePrint("= config reset | Resets the config file", 4, richTextBox1); - GlobalFuncs.ConsolePrint("---------", 1, richTextBox1); - GlobalFuncs.ConsolePrint("= webserver restart | Restarts the web server", 4, richTextBox1); - GlobalFuncs.ConsolePrint("= webserver stop | Stops a web server if there is one on.", 4, richTextBox1); - GlobalFuncs.ConsolePrint("= webserver start | Starts a web server if there isn't one on yet.", 4, richTextBox1); - GlobalFuncs.ConsolePrint("---------", 1, richTextBox1); - GlobalFuncs.ConsolePrint("= dlldelete off | Turn off the deletion of opengl32.dll when ReShade is off.", 4, richTextBox1); - GlobalFuncs.ConsolePrint("= dlldelete on | Turn on the deletion of opengl32.dll when ReShade is off.", 4, richTextBox1); - GlobalFuncs.ConsolePrint("---------", 1, richTextBox1); + launcherForm.ProcessConsole(e); } void Button21Click(object sender, EventArgs e) { - if (SecurityFuncs.IsElevated) - { - try - { - Process process = new Process(); - ProcessStartInfo startInfo = new ProcessStartInfo(); - startInfo.FileName = GlobalPaths.ClientDir + @"\\" + GlobalVars.ProgramInformation.RegisterClient1 + @"\\RobloxApp_studio.exe"; - startInfo.Arguments = "/regserver"; - startInfo.Verb = "runas"; - process.StartInfo = startInfo; - process.Start(); - - Process process2 = new Process(); - ProcessStartInfo startInfo2 = new ProcessStartInfo(); - startInfo2.FileName = GlobalPaths.ClientDir + @"\\" + GlobalVars.ProgramInformation.RegisterClient2 + @"\\RobloxApp_studio.exe"; - startInfo2.Arguments = "/regserver"; - startInfo2.Verb = "runas"; - process2.StartInfo = startInfo2; - process2.Start(); - - GlobalFuncs.ConsolePrint("UserAgent Library successfully installed and registered!", 3, richTextBox1); - MessageBox.Show("UserAgent Library successfully installed and registered!", "Novetus - Register UserAgent Library", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - catch (Exception ex) - { - GlobalFuncs.ConsolePrint("ERROR - Failed to register. (" + ex.Message + ")", 2, richTextBox1); - MessageBox.Show("Failed to register. (Error: " + ex.Message + ")", "Novetus - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - else - { - GlobalFuncs.ConsolePrint("ERROR - Failed to register. (Did not run as Administrator)", 2, richTextBox1); - MessageBox.Show("Failed to register. (Error: Did not run as Administrator)", "Novetus - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - } + launcherForm.InstallRegServer(); } void NumericUpDown1ValueChanged(object sender, EventArgs e) { - GlobalVars.UserConfiguration.RobloxPort = Convert.ToInt32(numericUpDown1.Value); - numericUpDown2.Value = Convert.ToDecimal(GlobalVars.UserConfiguration.RobloxPort); - label38.Text = GlobalVars.UserConfiguration.RobloxPort.ToString(); + launcherForm.ChangeJoinPort(); } void NumericUpDown2ValueChanged(object sender, EventArgs e) { - GlobalVars.UserConfiguration.RobloxPort = Convert.ToInt32(numericUpDown2.Value); - numericUpDown1.Value = Convert.ToDecimal(GlobalVars.UserConfiguration.RobloxPort); - label38.Text = GlobalVars.UserConfiguration.RobloxPort.ToString(); + launcherForm.ChangeServerPort(); } void NumericUpDown3ValueChanged(object sender, EventArgs e) @@ -1023,41 +196,17 @@ namespace NovetusLauncher void Button7Click(object sender, EventArgs e) { - numericUpDown1.Value = Convert.ToDecimal(GlobalVars.DefaultRobloxPort); - numericUpDown2.Value = Convert.ToDecimal(GlobalVars.DefaultRobloxPort); - GlobalVars.UserConfiguration.RobloxPort = GlobalVars.DefaultRobloxPort; - } - - void Button23Click(object sender, EventArgs e) - { - File.AppendAllText(GlobalPaths.ConfigDir + "\\ports.txt", GlobalVars.UserConfiguration.RobloxPort + Environment.NewLine); + launcherForm.ResetCurPort(numericUpDown1, GlobalVars.JoinPort); } void Button22Click(object sender, EventArgs e) { - numericUpDown1.Value = Convert.ToDecimal(GlobalVars.DefaultRobloxPort); - numericUpDown2.Value = Convert.ToDecimal(GlobalVars.DefaultRobloxPort); - GlobalVars.UserConfiguration.RobloxPort = GlobalVars.DefaultRobloxPort; + launcherForm.ResetCurPort(numericUpDown2, GlobalVars.UserConfiguration.RobloxPort); } void TreeView1AfterSelect(object sender, TreeViewEventArgs e) { - if (treeView1.SelectedNode.Nodes.Count == 0) - { - GlobalVars.UserConfiguration.Map = treeView1.SelectedNode.Text.ToString(); - GlobalVars.UserConfiguration.MapPathSnip = treeView1.SelectedNode.FullPath.ToString().Replace(@"\", @"\\"); - GlobalVars.UserConfiguration.MapPath = GlobalPaths.BasePath + @"\\" + GlobalVars.UserConfiguration.MapPathSnip; - label28.Text = GlobalVars.UserConfiguration.Map; - - if (File.Exists(GlobalPaths.RootPath + @"\\" + treeView1.SelectedNode.FullPath.ToString().Replace(".rbxl", "").Replace(".rbxlx", "") + "_desc.txt")) - { - textBox4.Text = File.ReadAllText(GlobalPaths.RootPath + @"\\" + treeView1.SelectedNode.FullPath.ToString().Replace(".rbxl", "").Replace(".rbxlx", "") + "_desc.txt"); - } - else - { - textBox4.Text = treeView1.SelectedNode.Text.ToString(); - } - } + launcherForm.SelectMap(); } void Button6Click(object sender, EventArgs e) @@ -1072,78 +221,23 @@ namespace NovetusLauncher void CheckBox4Click(object sender, EventArgs e) { - switch (checkBox4.Checked) - { - case false: - MessageBox.Show("Novetus will now restart.", "Novetus - UPnP", MessageBoxButtons.OK, MessageBoxIcon.Information); - break; - default: - MessageBox.Show("Novetus will now restart." + Environment.NewLine + "Make sure to check if your router has UPnP functionality enabled. Please note that some routers may not support UPnP, and some ISPs will block the UPnP protocol. This may not work for all users.", "Novetus - UPnP", MessageBoxButtons.OK, MessageBoxIcon.Information); - break; - } - - WriteConfigValues(); - Application.Restart(); + launcherForm.RestartLauncherAfterSetting(checkBox4, "Novetus - UPnP", "Make sure to check if your router has UPnP functionality enabled.\n" + + "Please note that some routers may not support UPnP, and some ISPs will block the UPnP protocol.\nThis may not work for all users."); } void Button24Click(object sender, EventArgs e) { - treeView1.Nodes.Clear(); - _fieldsTreeCache.Nodes.Clear(); - string mapdir = GlobalPaths.MapsDir; - string[] fileexts = new string[] { ".rbxl", ".rbxlx" }; - TreeNodeHelper.ListDirectory(treeView1, mapdir, fileexts); - TreeNodeHelper.CopyNodes(treeView1.Nodes, _fieldsTreeCache.Nodes); - treeView1.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.UserConfiguration.Map, treeView1.Nodes); - treeView1.Focus(); - if (File.Exists(GlobalPaths.RootPath + @"\\" + treeView1.SelectedNode.FullPath.ToString().Replace(".rbxl", "").Replace(".rbxlx", "") + "_desc.txt")) - { - textBox4.Text = File.ReadAllText(GlobalPaths.RootPath + @"\\" + treeView1.SelectedNode.FullPath.ToString().Replace(".rbxl", "").Replace(".rbxlx", "") + "_desc.txt"); - } - else - { - textBox4.Text = treeView1.SelectedNode.Text.ToString(); - } + launcherForm.RefreshMaps(); } private void button25_Click(object sender, EventArgs e) { - AddonLoader addon = new AddonLoader(); - addon.setFileListDisplay(10); - try - { - addon.LoadAddon(); - if (!string.IsNullOrWhiteSpace(addon.getInstallOutcome())) - { - GlobalFuncs.ConsolePrint("AddonLoader - " + addon.getInstallOutcome(), 3, richTextBox1); - } - } - catch (Exception) - { - if (!string.IsNullOrWhiteSpace(addon.getInstallOutcome())) - { - GlobalFuncs.ConsolePrint("AddonLoader - " + addon.getInstallOutcome(), 2, richTextBox1); - } - } - - if (!string.IsNullOrWhiteSpace(addon.getInstallOutcome())) - { - MessageBox.Show(addon.getInstallOutcome()); - } + launcherForm.InstallAddon(); } private void button26_Click(object sender, EventArgs e) { - if (Directory.Exists(GlobalPaths.AssetCacheDir)) - { - Directory.Delete(GlobalPaths.AssetCacheDir, true); - GlobalFuncs.ConsolePrint("Asset cache cleared!", 3, richTextBox1); - MessageBox.Show("Asset cache cleared!"); - } - else - { - MessageBox.Show("There is no asset cache to clear."); - } + launcherForm.ClearAssetCache(); } private void checkBox2_CheckedChanged(object sender, EventArgs e) @@ -1153,59 +247,7 @@ namespace NovetusLauncher void CheckBox2Click(object sender, EventArgs e) { - switch (checkBox2.Checked) - { - case false: - MessageBox.Show("Novetus will now restart.", "Novetus - Discord Rich Presence", MessageBoxButtons.OK, MessageBoxIcon.Information); - break; - default: - MessageBox.Show("Novetus will now restart." + Environment.NewLine + "Make sure the Discord app is open so this change can take effect.", "Novetus - Discord Rich Presence", MessageBoxButtons.OK, MessageBoxIcon.Information); - break; - } - - WriteConfigValues(); - Application.Restart(); - } - - private void button34_Click(object sender, EventArgs e) - { - LoadLauncher(); - } - - private void label8_Click(object sender, EventArgs e) - { - if (LocalVars.Clicks < 10) - { - LocalVars.Clicks += 1; - - switch (LocalVars.Clicks) - { - case 1: - label12.Text = "Hi " + GlobalVars.UserConfiguration.PlayerName + "!"; - break; - case 3: - label12.Text = "How are you doing today?"; - break; - case 6: - label12.Text = "I just wanted to say something."; - break; - case 9: - label12.Text = "Just wait a little on the last click, OK?"; - break; - case 10: - label12.Text = "Thank you. <3"; - WriteConfigValues(); - StartEasterEgg(); - - if (GlobalVars.UserConfiguration.CloseOnLaunch) - { - Visible = false; - } - break; - default: - break; - } - } + launcherForm.RestartLauncherAfterSetting(checkBox2, "Novetus - Discord Rich Presence", "Make sure the Discord app is open so this change can take effect."); } void SettingsButtonClick(object sender, EventArgs e) @@ -1220,92 +262,24 @@ namespace NovetusLauncher GlobalFuncs.ReadClientValues(richTextBox1); } - void Button3Click_legacy(object sender, EventArgs e) + private void button34_Click(object sender, EventArgs e) { - DialogResult result = MessageBox.Show("If you want to test out your place, you will have to save your place in Novetus's map folder, then launch your place in Play Solo." + Environment.NewLine + Environment.NewLine + "Press Yes to launch Studio with a map, or No to launch Studio without a map.", "Novetus - Launch ROBLOX Studio", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information); - bool nomap = false; + launcherForm.LoadLauncher(); + } - switch (result) - { - case DialogResult.Cancel: - return; - case DialogResult.No: - nomap = true; - break; - default: - break; - } - - WriteConfigValues(); - StartStudio(nomap); - if (GlobalVars.UserConfiguration.CloseOnLaunch) - { - Visible = false; - } + private void label8_Click(object sender, EventArgs e) + { + launcherForm.EasterEggLogic(); } private void comboBox3_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBox3.SelectedIndex) - { - case 1: - break; - default: - GlobalVars.UserConfiguration.LauncherStyle = Settings.UIOptions.Style.Extended; - CloseEvent(); - Application.Restart(); - break; - } + launcherForm.SwitchStyles(); } - // FINALLY. https://stackoverflow.com/questions/11530643/treeview-search - private void SearchButton_Click(object sender, EventArgs e) { - string searchText = SearchBar.Text; - - if (string.IsNullOrWhiteSpace(searchText)) - { - return; - }; - - try - { - if (LastSearchText != searchText) - { - //It's a new Search - CurrentNodeMatches.Clear(); - LastSearchText = searchText; - LastNodeIndex = 0; - SearchNodes(searchText, treeView1.Nodes[0]); - } - - if (LastNodeIndex >= 0 && CurrentNodeMatches.Count > 0 && LastNodeIndex < CurrentNodeMatches.Count) - { - TreeNode selectedNode = CurrentNodeMatches[LastNodeIndex]; - LastNodeIndex++; - treeView1.SelectedNode = selectedNode; - treeView1.SelectedNode.Expand(); - treeView1.Select(); - } - else - { - //It's a new Search - CurrentNodeMatches.Clear(); - LastSearchText = searchText; - LastNodeIndex = 0; - SearchNodes(searchText, treeView1.Nodes[0]); - TreeNode selectedNode = CurrentNodeMatches[LastNodeIndex]; - LastNodeIndex++; - treeView1.SelectedNode = selectedNode; - treeView1.SelectedNode.Expand(); - treeView1.Select(); - } - } - catch (Exception) - { - MessageBox.Show("The map '" + searchText + "' cannot be found. Please try another term."); - } + launcherForm.SearchMaps(); } private void checkBox8_CheckedChanged(object sender, EventArgs e) @@ -1315,18 +289,8 @@ namespace NovetusLauncher void CheckBox8Click(object sender, EventArgs e) { - switch (checkBox8.Checked) - { - case false: - MessageBox.Show("Novetus will now restart.", "Novetus - Web Server", MessageBoxButtons.OK, MessageBoxIcon.Information); - break; - default: - MessageBox.Show("Novetus will now restart." + Environment.NewLine + "Make sure you are running the launcher in Administrator Mode in order for the Web Server to function.", "Novetus - Web Server", MessageBoxButtons.OK, MessageBoxIcon.Information); - break; - } - - WriteConfigValues(); - Application.Restart(); + launcherForm.RestartLauncherAfterSetting(checkBox8, "Novetus - Web Server", "Make sure you are running the launcher in Administrator Mode" + + "in order for the Web Server to function."); } private void button36_Click(object sender, EventArgs e) @@ -1340,25 +304,6 @@ namespace NovetusLauncher GlobalVars.UserConfiguration.ShowServerNotifications = checkBox9.Checked; } #endregion - - #region Functions - private void SearchNodes(string SearchText, TreeNode StartNode) - { - while (StartNode != null) - { - if (StartNode.Text.ToLower().Contains(SearchText.ToLower())) - { - CurrentNodeMatches.Add(StartNode); - }; - if (StartNode.Nodes.Count != 0) - { - SearchNodes(SearchText, StartNode.Nodes[0]);//Recursive Search - }; - StartNode = StartNode.NextNode; - }; - - } - #endregion } #endregion } diff --git a/Novetus/NovetusLauncher/Forms/LauncherForm/Extended/LauncherFormExtended.Designer.cs b/Novetus/NovetusLauncher/Forms/LauncherForm/Extended/LauncherFormExtended.Designer.cs index 5230ca4..5a11c6f 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherForm/Extended/LauncherFormExtended.Designer.cs +++ b/Novetus/NovetusLauncher/Forms/LauncherForm/Extended/LauncherFormExtended.Designer.cs @@ -86,11 +86,11 @@ namespace NovetusLauncher this.button1 = new System.Windows.Forms.Button(); this.textBox1 = new System.Windows.Forms.TextBox(); this.tabPage2 = new System.Windows.Forms.TabPage(); + this.checkBox9 = new System.Windows.Forms.CheckBox(); this.checkBox8 = new System.Windows.Forms.CheckBox(); this.label19 = new System.Windows.Forms.Label(); this.textBox3 = new System.Windows.Forms.TextBox(); this.checkBox4 = new System.Windows.Forms.CheckBox(); - this.button23 = new System.Windows.Forms.Button(); this.button22 = new System.Windows.Forms.Button(); this.numericUpDown3 = new System.Windows.Forms.NumericUpDown(); this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); @@ -156,7 +156,6 @@ namespace NovetusLauncher this.panel4 = new System.Windows.Forms.Panel(); this.button35 = new System.Windows.Forms.Button(); this.UAButton = new System.Windows.Forms.Button(); - this.checkBox9 = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); this.panel1.SuspendLayout(); this.panel2.SuspendLayout(); @@ -656,7 +655,6 @@ namespace NovetusLauncher this.tabPage2.Controls.Add(this.label19); this.tabPage2.Controls.Add(this.textBox3); this.tabPage2.Controls.Add(this.checkBox4); - this.tabPage2.Controls.Add(this.button23); this.tabPage2.Controls.Add(this.button22); this.tabPage2.Controls.Add(this.numericUpDown3); this.tabPage2.Controls.Add(this.numericUpDown2); @@ -673,6 +671,17 @@ namespace NovetusLauncher this.tabPage2.ToolTipText = "Start a server for other players to play"; this.tabPage2.UseVisualStyleBackColor = true; // + // checkBox9 + // + this.checkBox9.AutoSize = true; + this.checkBox9.Location = new System.Drawing.Point(468, 180); + this.checkBox9.Name = "checkBox9"; + this.checkBox9.Size = new System.Drawing.Size(84, 17); + this.checkBox9.TabIndex = 62; + this.checkBox9.Text = "Notifications"; + this.checkBox9.UseVisualStyleBackColor = true; + this.checkBox9.CheckedChanged += new System.EventHandler(this.checkBox9_CheckedChanged); + // // checkBox8 // this.checkBox8.AutoSize = true; @@ -716,24 +725,13 @@ namespace NovetusLauncher this.checkBox4.CheckedChanged += new System.EventHandler(this.CheckBox4CheckedChanged); this.checkBox4.Click += new System.EventHandler(this.CheckBox4Click); // - // button23 - // - this.button23.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.button23.Location = new System.Drawing.Point(176, 177); - this.button23.Name = "button23"; - this.button23.Size = new System.Drawing.Size(66, 25); - this.button23.TabIndex = 51; - this.button23.Text = "SAVE"; - this.button23.UseVisualStyleBackColor = true; - this.button23.Click += new System.EventHandler(this.Button23Click); - // // button22 // - this.button22.Location = new System.Drawing.Point(248, 177); + this.button22.Location = new System.Drawing.Point(179, 178); this.button22.Name = "button22"; - this.button22.Size = new System.Drawing.Size(63, 25); + this.button22.Size = new System.Drawing.Size(131, 24); this.button22.TabIndex = 50; - this.button22.Text = "RESET"; + this.button22.Text = "RESET PORT"; this.button22.UseVisualStyleBackColor = true; this.button22.Click += new System.EventHandler(this.Button22Click); // @@ -1465,17 +1463,6 @@ namespace NovetusLauncher this.UAButton.Size = new System.Drawing.Size(75, 23); this.UAButton.TabIndex = 0; // - // checkBox9 - // - this.checkBox9.AutoSize = true; - this.checkBox9.Location = new System.Drawing.Point(468, 180); - this.checkBox9.Name = "checkBox9"; - this.checkBox9.Size = new System.Drawing.Size(84, 17); - this.checkBox9.TabIndex = 62; - this.checkBox9.Text = "Notifications"; - this.checkBox9.UseVisualStyleBackColor = true; - this.checkBox9.CheckedChanged += new System.EventHandler(this.checkBox9_CheckedChanged); - // // LauncherFormExtended // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -1577,6 +1564,7 @@ namespace NovetusLauncher launcherForm.JoinPortBox = numericUpDown1; launcherForm.ClientWarningLabel = label30; launcherForm.ClientDescriptionBox = textBox6; + launcherForm.IPBox = textBox1; } private System.Windows.Forms.CheckBox checkBox4; @@ -1588,7 +1576,6 @@ namespace NovetusLauncher private System.Windows.Forms.Label label7; private System.Windows.Forms.Label label2; private System.Windows.Forms.TabPage tabPage5; - private System.Windows.Forms.Button button23; private System.Windows.Forms.Button button22; private System.Windows.Forms.Button button7; private System.Windows.Forms.PictureBox pictureBox2; diff --git a/Novetus/NovetusLauncher/Forms/LauncherForm/Extended/LauncherFormExtended.cs b/Novetus/NovetusLauncher/Forms/LauncherForm/Extended/LauncherFormExtended.cs index 4d66279..fda6db0 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherForm/Extended/LauncherFormExtended.cs +++ b/Novetus/NovetusLauncher/Forms/LauncherForm/Extended/LauncherFormExtended.cs @@ -105,29 +105,7 @@ namespace NovetusLauncher void ListBox2SelectedIndexChanged(object sender, EventArgs e) { - string ourselectedclient = GlobalVars.UserConfiguration.SelectedClient; - GlobalVars.UserConfiguration.SelectedClient = listBox2.SelectedItem.ToString(); - if (!ourselectedclient.Equals(GlobalVars.UserConfiguration.SelectedClient)) - { - launcherForm.ReadClientValues(true); - } - else - { - launcherForm.ReadClientValues(); - } - GlobalFuncs.UpdateRichPresence(GlobalVars.LauncherState.InLauncher, ""); - - FormCollection fc = Application.OpenForms; - - foreach (Form frm in fc) - { - //iterate through - if (frm.Name == "CustomGraphicsOptions") - { - frm.Close(); - break; - } - } + launcherForm.ChangeClient(); } void CheckBox3CheckedChanged(object sender, EventArgs e) @@ -137,22 +115,7 @@ namespace NovetusLauncher void TextBox5TextChanged(object sender, EventArgs e) { - int parsedValue; - if (int.TryParse(textBox5.Text, out parsedValue)) - { - if (textBox5.Text.Equals("")) - { - GlobalVars.UserConfiguration.UserID = 0; - } - else - { - GlobalVars.UserConfiguration.UserID = Convert.ToInt32(textBox5.Text); - } - } - else - { - GlobalVars.UserConfiguration.UserID = 0; - } + launcherForm.ChangeUserID(); } void Button8Click(object sender, EventArgs e) @@ -163,88 +126,57 @@ namespace NovetusLauncher void Button9Click(object sender, EventArgs e) { - launcherForm.ResetConfigValues(); - MessageBox.Show("Config Reset!"); + launcherForm.ResetConfigValues(true); } void ListBox3SelectedIndexChanged(object sender, EventArgs e) { - GlobalVars.IP = listBox3.SelectedItem.ToString(); - textBox1.Text = GlobalVars.IP; - checkBox3.Enabled = false; - GlobalVars.LocalPlayMode = false; - label37.Text = GlobalVars.IP; + launcherForm.SelectIPListing(); } void ListBox4SelectedIndexChanged(object sender, EventArgs e) { - GlobalVars.UserConfiguration.RobloxPort = Convert.ToInt32(listBox4.SelectedItem.ToString()); - numericUpDown1.Value = Convert.ToDecimal(GlobalVars.UserConfiguration.RobloxPort); - numericUpDown2.Value = Convert.ToDecimal(GlobalVars.UserConfiguration.RobloxPort); + launcherForm.SelectPortListing(); } void Button10Click(object sender, EventArgs e) { - File.AppendAllText(GlobalPaths.ConfigDir + "\\servers.txt", GlobalVars.IP + Environment.NewLine); + launcherForm.AddIPPortListing(null, GlobalPaths.ConfigDir + "\\servers.txt", GlobalVars.IP); } void Button11Click(object sender, EventArgs e) { - File.AppendAllText(GlobalPaths.ConfigDir + "\\ports.txt", GlobalVars.UserConfiguration.RobloxPort + Environment.NewLine); + launcherForm.AddIPPortListing(null, GlobalPaths.ConfigDir + "\\ports.txt", GlobalVars.JoinPort); } void Button12Click(object sender, EventArgs e) { - if (listBox3.SelectedIndex >= 0) - { - TextLineRemover.RemoveTextLines(new List { listBox3.SelectedItem.ToString() }, GlobalPaths.ConfigDir + "\\servers.txt", GlobalPaths.ConfigDir + "\\servers.tmp"); - listBox3.Items.Clear(); - string[] lines_server = File.ReadAllLines(GlobalPaths.ConfigDir + "\\servers.txt"); - listBox3.Items.AddRange(lines_server); - } + launcherForm.RemoveIPPortListing(listBox3, GlobalPaths.ConfigDir + "\\servers.txt", GlobalPaths.ConfigDir + "\\servers.tmp"); } void Button13Click(object sender, EventArgs e) { - if (listBox4.SelectedIndex >= 0) - { - TextLineRemover.RemoveTextLines(new List { listBox4.SelectedItem.ToString() }, GlobalPaths.ConfigDir + "\\ports.txt", GlobalPaths.ConfigDir + "\\ports.tmp"); - listBox4.Items.Clear(); - string[] lines_ports = File.ReadAllLines(GlobalPaths.ConfigDir + "\\ports.txt"); - listBox4.Items.AddRange(lines_ports); - } + launcherForm.RemoveIPPortListing(listBox4, GlobalPaths.ConfigDir + "\\ports.txt", GlobalPaths.ConfigDir + "\\ports.tmp"); } void Button14Click(object sender, EventArgs e) { - File.Create(GlobalPaths.ConfigDir + "\\servers.txt").Dispose(); - listBox3.Items.Clear(); - string[] lines_server = File.ReadAllLines(GlobalPaths.ConfigDir + "\\servers.txt"); - listBox3.Items.AddRange(lines_server); + launcherForm.ResetIPPortListing(listBox3, GlobalPaths.ConfigDir + "\\servers.txt"); } void Button15Click(object sender, EventArgs e) { - File.Create(GlobalPaths.ConfigDir + "\\ports.txt").Dispose(); - listBox4.Items.Clear(); - string[] lines_ports = File.ReadAllLines(GlobalPaths.ConfigDir + "\\ports.txt"); - listBox4.Items.AddRange(lines_ports); + launcherForm.ResetIPPortListing(listBox4, GlobalPaths.ConfigDir + "\\ports.txt"); } void Button16Click(object sender, EventArgs e) { - File.AppendAllText(GlobalPaths.ConfigDir + "\\servers.txt", GlobalVars.IP + Environment.NewLine); - listBox3.Items.Clear(); - string[] lines_server = File.ReadAllLines(GlobalPaths.ConfigDir + "\\servers.txt"); - listBox3.Items.AddRange(lines_server); + launcherForm.AddIPPortListing(listBox3, GlobalPaths.ConfigDir + "\\servers.txt", GlobalVars.IP); } void Button17Click(object sender, EventArgs e) { - File.AppendAllText(GlobalPaths.ConfigDir + "\\ports.txt", GlobalVars.UserConfiguration.RobloxPort + Environment.NewLine); - listBox4.Items.Clear(); - string[] lines_ports = File.ReadAllLines(GlobalPaths.ConfigDir + "\\ports.txt"); - listBox4.Items.AddRange(lines_ports); + launcherForm.AddIPPortListing(listBox4, GlobalPaths.ConfigDir + "\\ports.txt", GlobalVars.JoinPort); } void richTextBox1_KeyDown(object sender, KeyEventArgs e) @@ -259,16 +191,12 @@ namespace NovetusLauncher void NumericUpDown1ValueChanged(object sender, EventArgs e) { - GlobalVars.UserConfiguration.RobloxPort = Convert.ToInt32(numericUpDown1.Value); - numericUpDown2.Value = Convert.ToDecimal(GlobalVars.UserConfiguration.RobloxPort); - label38.Text = GlobalVars.UserConfiguration.RobloxPort.ToString(); + launcherForm.ChangeJoinPort(); } void NumericUpDown2ValueChanged(object sender, EventArgs e) { - GlobalVars.UserConfiguration.RobloxPort = Convert.ToInt32(numericUpDown2.Value); - numericUpDown1.Value = Convert.ToDecimal(GlobalVars.UserConfiguration.RobloxPort); - label38.Text = GlobalVars.UserConfiguration.RobloxPort.ToString(); + launcherForm.ChangeServerPort(); } void NumericUpDown3ValueChanged(object sender, EventArgs e) @@ -278,21 +206,12 @@ namespace NovetusLauncher void Button7Click(object sender, EventArgs e) { - numericUpDown1.Value = Convert.ToDecimal(GlobalVars.DefaultRobloxPort); - numericUpDown2.Value = Convert.ToDecimal(GlobalVars.DefaultRobloxPort); - GlobalVars.UserConfiguration.RobloxPort = GlobalVars.DefaultRobloxPort; - } - - void Button23Click(object sender, EventArgs e) - { - File.AppendAllText(GlobalPaths.ConfigDir + "\\ports.txt", GlobalVars.UserConfiguration.RobloxPort + Environment.NewLine); + launcherForm.ResetCurPort(numericUpDown1, GlobalVars.JoinPort); } void Button22Click(object sender, EventArgs e) { - numericUpDown1.Value = Convert.ToDecimal(GlobalVars.DefaultRobloxPort); - numericUpDown2.Value = Convert.ToDecimal(GlobalVars.DefaultRobloxPort); - GlobalVars.UserConfiguration.RobloxPort = GlobalVars.DefaultRobloxPort; + launcherForm.ResetCurPort(numericUpDown2, GlobalVars.UserConfiguration.RobloxPort); } void TreeView1AfterSelect(object sender, TreeViewEventArgs e) @@ -312,7 +231,8 @@ namespace NovetusLauncher void CheckBox4Click(object sender, EventArgs e) { - launcherForm.RestartLauncherAfterSetting(checkBox4); + launcherForm.RestartLauncherAfterSetting(checkBox4, "Novetus - UPnP", "Make sure to check if your router has UPnP functionality enabled.\n" + + "Please note that some routers may not support UPnP, and some ISPs will block the UPnP protocol.\nThis may not work for all users."); } void Button24Click(object sender, EventArgs e) @@ -337,18 +257,7 @@ namespace NovetusLauncher void CheckBox2Click(object sender, EventArgs e) { - switch (checkBox2.Checked) - { - case false: - MessageBox.Show("Novetus will now restart.", "Novetus - Discord Rich Presence", MessageBoxButtons.OK, MessageBoxIcon.Information); - break; - default: - MessageBox.Show("Novetus will now restart." + Environment.NewLine + "Make sure the Discord app is open so this change can take effect.", "Novetus - Discord Rich Presence", MessageBoxButtons.OK, MessageBoxIcon.Information); - break; - } - - launcherForm.WriteConfigValues(); - Application.Restart(); + launcherForm.RestartLauncherAfterSetting(checkBox2, "Novetus - Discord Rich Presence", "Make sure the Discord app is open so this change can take effect."); } private void button27_Click(object sender, EventArgs e) @@ -391,16 +300,6 @@ namespace NovetusLauncher tabControl1.SelectedTab = tabPage5; } - private void button34_Click(object sender, EventArgs e) - { - launcherForm.LoadLauncher(); - } - - private void label8_Click(object sender, EventArgs e) - { - launcherForm.EasterEggLogic(); - } - private void checkBox5_CheckedChanged(object sender, EventArgs e) { GlobalVars.UserConfiguration.ReShade = checkBox5.Checked; @@ -417,7 +316,7 @@ namespace NovetusLauncher } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) - { + { switch (comboBox1.SelectedIndex) { case 1: @@ -481,16 +380,6 @@ namespace NovetusLauncher } } - private void comboBox3_SelectedIndexChanged(object sender, EventArgs e) - { - launcherForm.SwitchStyles(); - } - - private void SearchButton_Click(object sender, EventArgs e) - { - launcherForm.SearchMaps(); - } - private void button36_Click(object sender, EventArgs e) { if (GlobalVars.UserConfiguration.QualityLevel == Settings.GraphicsOptions.Level.Custom) @@ -504,6 +393,26 @@ namespace NovetusLauncher } } + private void button34_Click(object sender, EventArgs e) + { + launcherForm.LoadLauncher(); + } + + private void label8_Click(object sender, EventArgs e) + { + launcherForm.EasterEggLogic(); + } + + private void comboBox3_SelectedIndexChanged(object sender, EventArgs e) + { + launcherForm.SwitchStyles(); + } + + private void SearchButton_Click(object sender, EventArgs e) + { + launcherForm.SearchMaps(); + } + private void checkBox8_CheckedChanged(object sender, EventArgs e) { GlobalVars.UserConfiguration.WebServer = checkBox8.Checked; @@ -511,7 +420,8 @@ namespace NovetusLauncher void CheckBox8Click(object sender, EventArgs e) { - launcherForm.RestartLauncherAfterSetting(checkBox8, true); + launcherForm.RestartLauncherAfterSetting(checkBox8, "Novetus - Web Server", "Make sure you are running the launcher in Administrator Mode" + + "in order for the Web Server to function."); } private void button37_Click(object sender, EventArgs e) diff --git a/Novetus/NovetusLauncher/Forms/LauncherFormShared.cs b/Novetus/NovetusLauncher/Forms/LauncherFormShared.cs index 1c82f9f..a3bae40 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherFormShared.cs +++ b/Novetus/NovetusLauncher/Forms/LauncherFormShared.cs @@ -29,7 +29,7 @@ namespace NovetusLauncher public Settings.UIOptions.Style FormStyle = Settings.UIOptions.Style.None; public RichTextBox ConsoleBox, ChangelogBox, ReadmeBox = null; public TabControl Tabs = null; - public TextBox MapDescBox, ServerInfo, SearchBar, PlayerIDTextBox, PlayerNameTextBox, ClientDescriptionBox = null; + public TextBox MapDescBox, ServerInfo, SearchBar, PlayerIDTextBox, PlayerNameTextBox, ClientDescriptionBox, IPBox = null; public TreeView Tree, _TreeCache = null; public ListBox ServerBox, PortBox, ClientBox = null; public Label SplashLabel, ProductVersionLabel, NovetusVersionLabel, PlayerTripcodeLabel, IPLabel, PortLabel, @@ -214,6 +214,7 @@ namespace NovetusLauncher { GlobalFuncs.ConsolePrint("WebServer: Server has stopped on port: " + GlobalVars.WebServer.Port.ToString(), 2, ConsoleBox); GlobalVars.WebServer.Stop(); + GlobalVars.WebServer = null; } catch (Exception ex) { @@ -305,6 +306,7 @@ namespace NovetusLauncher { StopWebServer(); } + Application.Exit(); } public async Task ChangeTabs() @@ -766,14 +768,22 @@ namespace NovetusLauncher SelectedMapLabel.Text = GlobalVars.UserConfiguration.Map; Tree.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.UserConfiguration.Map, Tree.Nodes); Tree.Focus(); - JoinPortBox.Value = Convert.ToDecimal(GlobalVars.UserConfiguration.RobloxPort); + JoinPortBox.Value = Convert.ToDecimal(GlobalVars.JoinPort); HostPortBox.Value = Convert.ToDecimal(GlobalVars.UserConfiguration.RobloxPort); IPLabel.Text = GlobalVars.IP; - PortLabel.Text = GlobalVars.UserConfiguration.RobloxPort.ToString(); + PortLabel.Text = GlobalVars.JoinPort.ToString(); DiscordPresenceCheckbox.Checked = GlobalVars.UserConfiguration.DiscordPresence; - ReShadeCheckbox.Checked = GlobalVars.UserConfiguration.ReShade; - ReShadeFPSDisplayCheckBox.Checked = GlobalVars.UserConfiguration.ReShadeFPSDisplay; - ReShadePerformanceModeCheckBox.Checked = GlobalVars.UserConfiguration.ReShadePerformanceMode; + if (FormStyle == Settings.UIOptions.Style.Extended) + { + if (ReShadeCheckbox != null) + ReShadeCheckbox.Checked = GlobalVars.UserConfiguration.ReShade; + + if (ReShadeFPSDisplayCheckBox != null) + ReShadeFPSDisplayCheckBox.Checked = GlobalVars.UserConfiguration.ReShadeFPSDisplay; + + if (ReShadePerformanceModeCheckBox != null) + ReShadePerformanceModeCheckBox.Checked = GlobalVars.UserConfiguration.ReShadePerformanceMode; + } uPnPCheckBox.Checked = GlobalVars.UserConfiguration.UPnP; ShowServerNotifsCheckBox.Checked = GlobalVars.UserConfiguration.ShowServerNotifications; @@ -866,7 +876,7 @@ namespace NovetusLauncher GlobalFuncs.ConsolePrint("Config Saved.", 3, ConsoleBox); } - public void ResetConfigValues() + public void ResetConfigValues(bool ShowBox = false) { //https://stackoverflow.com/questions/9029351/close-all-open-forms-except-the-main-menu-in-c-sharp List openForms = new List(); @@ -883,6 +893,10 @@ namespace NovetusLauncher GlobalFuncs.ResetConfigValues(); WriteConfigValues(); ReadConfigValues(); + if (ShowBox) + { + MessageBox.Show("Config Reset!"); + } } public void ReadClientValues(bool initial = false) @@ -1003,13 +1017,8 @@ namespace NovetusLauncher } } - public void RestartLauncherAfterSetting(CheckBox box, bool webServer = false) + public void RestartLauncherAfterSetting(CheckBox box, string title, string subText) { - string title = webServer ? "Novetus - Web Server" : "Novetus - UPnP"; - string subText = webServer ? "Make sure you are running the launcher in Administrator Mode in order for the Web Server to function." : - "Make sure to check if your router has UPnP functionality enabled.\n" + - "Please note that some routers may not support UPnP, and some ISPs will block the UPnP protocol.\nThis may not work for all users."; - switch (box.Checked) { case false: @@ -1081,6 +1090,128 @@ namespace NovetusLauncher MessageBox.Show("Failed to register. (Error: Did not run as Administrator)", "Novetus - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + public void AddIPPortListing(ListBox box, string file, object val) + { + File.AppendAllText(file, val + Environment.NewLine); + + if (box != null) + { + box.Items.Clear(); + string[] lines = File.ReadAllLines(file); + box.Items.AddRange(lines); + } + } + + public void ResetIPPortListing(ListBox box, string file) + { + File.Create(file).Dispose(); + + if (box != null) + { + box.Items.Clear(); + string[] lines = File.ReadAllLines(file); + box.Items.AddRange(lines); + } + } + + public void RemoveIPPortListing(ListBox box, string file, string file_tmp) + { + if (box != null) + { + if (box.SelectedIndex >= 0) + { + TextLineRemover.RemoveTextLines(new List { box.SelectedItem.ToString() }, file, file_tmp); + box.Items.Clear(); + string[] lines = File.ReadAllLines(file); + box.Items.AddRange(lines); + } + } + else + { + //requires a ListBox. + return; + } + } + + public void SelectIPListing() + { + GlobalVars.IP = ServerBox.SelectedItem.ToString(); + IPBox.Text = GlobalVars.IP; + LocalPlayCheckBox.Enabled = false; + GlobalVars.LocalPlayMode = false; + IPLabel.Text = GlobalVars.IP; + } + + public void SelectPortListing() + { + GlobalVars.JoinPort = Convert.ToInt32(PortBox.SelectedItem.ToString()); + JoinPortBox.Value = Convert.ToDecimal(GlobalVars.JoinPort); + } + + public void ResetCurPort(NumericUpDown box, int value) + { + box.Value = Convert.ToDecimal(GlobalVars.DefaultRobloxPort); + value = GlobalVars.DefaultRobloxPort; + } + + public void ChangeJoinPort() + { + GlobalVars.JoinPort = Convert.ToInt32(JoinPortBox.Value); + PortLabel.Text = GlobalVars.JoinPort.ToString(); + } + + public void ChangeServerPort() + { + GlobalVars.UserConfiguration.RobloxPort = Convert.ToInt32(HostPortBox.Value); + } + + public void ChangeClient() + { + string ourselectedclient = GlobalVars.UserConfiguration.SelectedClient; + GlobalVars.UserConfiguration.SelectedClient = ClientBox.SelectedItem.ToString(); + if (!ourselectedclient.Equals(GlobalVars.UserConfiguration.SelectedClient)) + { + ReadClientValues(true); + } + else + { + ReadClientValues(); + } + GlobalFuncs.UpdateRichPresence(GlobalVars.LauncherState.InLauncher, ""); + + FormCollection fc = Application.OpenForms; + + foreach (Form frm in fc) + { + //iterate through + if (frm.Name == "CustomGraphicsOptions") + { + frm.Close(); + break; + } + } + } + + public void ChangeUserID() + { + int parsedValue; + if (int.TryParse(PlayerIDTextBox.Text, out parsedValue)) + { + if (PlayerIDTextBox.Text.Equals("")) + { + GlobalVars.UserConfiguration.UserID = 0; + } + else + { + GlobalVars.UserConfiguration.UserID = Convert.ToInt32(PlayerIDTextBox.Text); + } + } + else + { + GlobalVars.UserConfiguration.UserID = 0; + } + } #endregion #region Helper Functions diff --git a/Novetus/NovetusLauncher/Forms/SDK/ClientinfoCreator.Designer.cs b/Novetus/NovetusLauncher/Forms/SDK/ClientinfoCreator.Designer.cs index 0b38251..995147e 100644 --- a/Novetus/NovetusLauncher/Forms/SDK/ClientinfoCreator.Designer.cs +++ b/Novetus/NovetusLauncher/Forms/SDK/ClientinfoCreator.Designer.cs @@ -76,6 +76,7 @@ partial class ClientinfoEditor this.doublequoteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.serverToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.limitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.notificationsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.securityToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.md5launcherToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.md5scriptToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -151,7 +152,7 @@ partial class ClientinfoEditor this.label9 = new System.Windows.Forms.Label(); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.label10 = new System.Windows.Forms.Label(); - this.notificationsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.joinportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); // @@ -402,7 +403,8 @@ partial class ClientinfoEditor this.addonscriptpathToolStripMenuItem, this.scripttypeToolStripMenuItem, this.versionToolStripMenuItem, - this.doublequoteToolStripMenuItem}); + this.doublequoteToolStripMenuItem, + this.joinportToolStripMenuItem}); this.generalToolStripMenuItem.Name = "generalToolStripMenuItem"; this.generalToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.generalToolStripMenuItem.Text = "General"; @@ -493,6 +495,13 @@ partial class ClientinfoEditor this.limitToolStripMenuItem.Text = "%limit%"; this.limitToolStripMenuItem.Click += new System.EventHandler(this.variableToolStripMenuItem_Click); // + // notificationsToolStripMenuItem + // + this.notificationsToolStripMenuItem.Name = "notificationsToolStripMenuItem"; + this.notificationsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.notificationsToolStripMenuItem.Text = "%notifications%"; + this.notificationsToolStripMenuItem.Click += new System.EventHandler(this.variableToolStripMenuItem_Click); + // // securityToolStripMenuItem // this.securityToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -1119,12 +1128,12 @@ partial class ClientinfoEditor this.label10.TabIndex = 33; this.label10.Text = "When applying the settings (if there is a settings XML file):"; // - // notificationsToolStripMenuItem + // joinportToolStripMenuItem // - this.notificationsToolStripMenuItem.Name = "notificationsToolStripMenuItem"; - this.notificationsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.notificationsToolStripMenuItem.Text = "%notifications%"; - this.notificationsToolStripMenuItem.Click += new System.EventHandler(this.variableToolStripMenuItem_Click); + this.joinportToolStripMenuItem.Name = "joinportToolStripMenuItem"; + this.joinportToolStripMenuItem.Size = new System.Drawing.Size(181, 22); + this.joinportToolStripMenuItem.Text = "%joinport%"; + this.joinportToolStripMenuItem.Click += new System.EventHandler(this.variableToolStripMenuItem_Click); // // ClientinfoEditor // @@ -1279,4 +1288,5 @@ partial class ClientinfoEditor private System.Windows.Forms.ToolStripMenuItem doublequoteToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem disabledToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem notificationsToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem joinportToolStripMenuItem; } diff --git a/Novetus/NovetusLauncher/Novetus.Launcher.csproj b/Novetus/NovetusLauncher/Novetus.Launcher.csproj index 85ae021..0ecadd6 100644 --- a/Novetus/NovetusLauncher/Novetus.Launcher.csproj +++ b/Novetus/NovetusLauncher/Novetus.Launcher.csproj @@ -151,6 +151,7 @@ + Form diff --git a/Novetus/NovetusURI/Classes/LocalFuncs.cs b/Novetus/NovetusURI/Classes/LocalFuncs.cs index 0cd0bdc..0757873 100644 --- a/Novetus/NovetusURI/Classes/LocalFuncs.cs +++ b/Novetus/NovetusURI/Classes/LocalFuncs.cs @@ -43,7 +43,7 @@ namespace NovetusURI string client = SecurityFuncs.Base64Decode(SplitArg[2]); GlobalVars.UserConfiguration.SelectedClient = client; GlobalVars.IP = ip; - GlobalVars.UserConfiguration.RobloxPort = Convert.ToInt32(port); + GlobalVars.JoinPort = Convert.ToInt32(port); GlobalFuncs.ReadClientValues(); } }