From ca39b48f88540f728b236361806dc55279e8c948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCssig?= Date: Fri, 25 Oct 2024 22:57:02 +0200 Subject: [PATCH 1/7] Added an option to edit the default ServerList. This also added a dependency to Newtonsoft.Json Also updated .NetFramework to 4.8 since 4.6 is EoL since April 22 --- patcher/.gitignore | 1 + patcher/App.config | 3 +- patcher/GameServer.cs | 14 ++ patcher/HitmanPatcher.csproj | 28 ++-- patcher/MainForm.Designer.cs | 208 ++++++++++++++------------- patcher/MainForm.cs | 87 +++++++++-- patcher/ServerListEditor.Designer.cs | 102 +++++++++++++ patcher/ServerListEditor.cs | 52 +++++++ patcher/ServerListEditor.resx | 132 +++++++++++++++++ patcher/packages.config | 4 + 10 files changed, 506 insertions(+), 125 deletions(-) create mode 100644 patcher/GameServer.cs create mode 100644 patcher/ServerListEditor.Designer.cs create mode 100644 patcher/ServerListEditor.cs create mode 100644 patcher/ServerListEditor.resx create mode 100644 patcher/packages.config diff --git a/patcher/.gitignore b/patcher/.gitignore index 1747fa209..4d374e113 100644 --- a/patcher/.gitignore +++ b/patcher/.gitignore @@ -4,3 +4,4 @@ obj/* /HitmanPatcher.sln.DotSettings.user /.idea/.idea.HitmanPatcher/.idea/riderMarkupCache.xml *.suo +packages/* \ No newline at end of file diff --git a/patcher/App.config b/patcher/App.config index fcf2f62a0..4e0cab57c 100644 --- a/patcher/App.config +++ b/patcher/App.config @@ -16,9 +16,8 @@ - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . --> - - + diff --git a/patcher/GameServer.cs b/patcher/GameServer.cs new file mode 100644 index 000000000..457e61c3b --- /dev/null +++ b/patcher/GameServer.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HitmanPatcher +{ + public class GameServer + { + public string ServerName { get; set; } + public string ServerAddress { get; set; } + } +} diff --git a/patcher/HitmanPatcher.csproj b/patcher/HitmanPatcher.csproj index c2914cd5e..989085336 100644 --- a/patcher/HitmanPatcher.csproj +++ b/patcher/HitmanPatcher.csproj @@ -16,10 +16,8 @@ - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . --> - - Debug x64 @@ -28,7 +26,7 @@ Properties HitmanPatcher PeacockPatcher - v4.6 + v4.8 512 True @@ -40,7 +38,6 @@ None.None.None.Increment 8 - true bin\x64\Debug\ @@ -51,7 +48,6 @@ MinimumRecommendedRules.ruleset true - bin\x64\Release\ TRACE;PLATFORM_STEAM;PLATFORM_EPIC @@ -62,14 +58,16 @@ MinimumRecommendedRules.ruleset true - patcher.ico - + + packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll + + @@ -79,7 +77,6 @@ - @@ -87,6 +84,7 @@ True CliLocale.resx + Form @@ -119,6 +117,12 @@ + + Form + + + ServerListEditor.cs + Form @@ -148,12 +152,16 @@ Resources.resx True + + ServerListEditor.cs + TrayOptionsForm.Designer.cs + SettingsSingleFileGenerator Settings.Designer.cs @@ -167,11 +175,9 @@ - - - + \ No newline at end of file diff --git a/patcher/MainForm.Designer.cs b/patcher/MainForm.Designer.cs index 5778da907..23f11966d 100644 --- a/patcher/MainForm.Designer.cs +++ b/patcher/MainForm.Designer.cs @@ -1,4 +1,4 @@ -namespace HitmanPatcher +namespace HitmanPatcher { partial class MainForm { @@ -32,7 +32,7 @@ private void InitializeComponent() System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); this.serverAddressLabel = new System.Windows.Forms.Label(); this.logListView = new System.Windows.Forms.ListView(); - this.columnHeader1 = new System.Windows.Forms.ColumnHeader(); + this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.logContextMenu = new System.Windows.Forms.ContextMenuStrip(this.components); this.copyLogToClipboardToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.logLabel = new System.Windows.Forms.Label(); @@ -49,231 +49,239 @@ private void InitializeComponent() this.menuItemRepatch = new System.Windows.Forms.ToolStripMenuItem(); this.domainsTrayMenu = new System.Windows.Forms.ToolStripMenuItem(); this.menuItemExit = new System.Windows.Forms.ToolStripMenuItem(); + this.serverList = new System.Windows.Forms.Button(); this.logContextMenu.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.novikovPictureBox)).BeginInit(); this.trayMenu.SuspendLayout(); this.SuspendLayout(); - // + // // serverAddressLabel - // + // this.serverAddressLabel.AccessibleDescription = "Server address label."; this.serverAddressLabel.AccessibleName = "Server address"; this.serverAddressLabel.AutoSize = true; - this.serverAddressLabel.Location = new System.Drawing.Point(9, 15); + this.serverAddressLabel.Location = new System.Drawing.Point(7, 12); + this.serverAddressLabel.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.serverAddressLabel.Name = "serverAddressLabel"; - this.serverAddressLabel.Size = new System.Drawing.Size(103, 16); + this.serverAddressLabel.Size = new System.Drawing.Size(81, 13); this.serverAddressLabel.TabIndex = 0; this.serverAddressLabel.Text = "Server address:"; - // + // // logListView - // + // this.logListView.AccessibleDescription = "Patcher log"; this.logListView.AccessibleName = "Log"; - this.logListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.logListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] - { - this.columnHeader1 - }); + this.logListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.logListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.columnHeader1}); this.logListView.ContextMenuStrip = this.logContextMenu; this.logListView.FullRowSelect = true; this.logListView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; this.logListView.HideSelection = false; - this.logListView.Location = new System.Drawing.Point(12, 81); - this.logListView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.logListView.Location = new System.Drawing.Point(9, 66); + this.logListView.Margin = new System.Windows.Forms.Padding(2); this.logListView.Name = "logListView"; - this.logListView.Size = new System.Drawing.Size(402, 106); + this.logListView.Size = new System.Drawing.Size(309, 87); this.logListView.TabIndex = 2; this.logListView.UseCompatibleStateImageBehavior = false; this.logListView.View = System.Windows.Forms.View.Details; - // + // // columnHeader1 - // + // this.columnHeader1.Width = 300; - // + // // logContextMenu - // + // this.logContextMenu.AccessibleDescription = "Patcher log context menu"; this.logContextMenu.AccessibleName = "Log context"; this.logContextMenu.BackColor = System.Drawing.SystemColors.Control; this.logContextMenu.ImageScalingSize = new System.Drawing.Size(20, 20); - this.logContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] - { - this.copyLogToClipboardToolStripMenuItem - }); + this.logContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.copyLogToClipboardToolStripMenuItem}); this.logContextMenu.Name = "logContextMenu"; - this.logContextMenu.Size = new System.Drawing.Size(225, 28); - // + this.logContextMenu.Size = new System.Drawing.Size(190, 26); + // // copyLogToClipboardToolStripMenuItem - // + // this.copyLogToClipboardToolStripMenuItem.AccessibleDescription = "Action for copying patcher logs to the clipboard."; this.copyLogToClipboardToolStripMenuItem.AccessibleName = "Copy log to clipboard action"; this.copyLogToClipboardToolStripMenuItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; this.copyLogToClipboardToolStripMenuItem.Name = "copyLogToClipboardToolStripMenuItem"; - this.copyLogToClipboardToolStripMenuItem.Size = new System.Drawing.Size(224, 24); + this.copyLogToClipboardToolStripMenuItem.Size = new System.Drawing.Size(189, 22); this.copyLogToClipboardToolStripMenuItem.Text = "Copy log to clipboard"; this.copyLogToClipboardToolStripMenuItem.Click += new System.EventHandler(this.copyLogToClipboardToolStripMenuItem_Click); - // + // // logLabel - // + // this.logLabel.AutoSize = true; - this.logLabel.Location = new System.Drawing.Point(9, 50); + this.logLabel.Location = new System.Drawing.Point(7, 41); this.logLabel.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.logLabel.Name = "logLabel"; - this.logLabel.Size = new System.Drawing.Size(33, 16); + this.logLabel.Size = new System.Drawing.Size(28, 13); this.logLabel.TabIndex = 3; this.logLabel.Text = "Log:"; - // + // // buttonRepatch - // + // this.buttonRepatch.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRepatch.Location = new System.Drawing.Point(313, 11); - this.buttonRepatch.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRepatch.Location = new System.Drawing.Point(236, 36); + this.buttonRepatch.Margin = new System.Windows.Forms.Padding(2); this.buttonRepatch.Name = "buttonRepatch"; - this.buttonRepatch.Size = new System.Drawing.Size(101, 28); + this.buttonRepatch.Size = new System.Drawing.Size(82, 23); this.buttonRepatch.TabIndex = 1; this.buttonRepatch.Text = "Re-patch"; this.buttonRepatch.UseVisualStyleBackColor = true; this.buttonRepatch.Click += new System.EventHandler(this.RePatchButton_Click); - // + // // serverUrlComboBox - // + // this.serverUrlComboBox.AccessibleDescription = ""; this.serverUrlComboBox.AccessibleName = "Server address picker"; - this.serverUrlComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); + this.serverUrlComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.serverUrlComboBox.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.serverUrlComboBox.FormattingEnabled = true; - this.serverUrlComboBox.Location = new System.Drawing.Point(127, 12); - this.serverUrlComboBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.serverUrlComboBox.Location = new System.Drawing.Point(95, 10); + this.serverUrlComboBox.Margin = new System.Windows.Forms.Padding(2); this.serverUrlComboBox.MaxLength = 150; this.serverUrlComboBox.Name = "serverUrlComboBox"; - this.serverUrlComboBox.Size = new System.Drawing.Size(180, 24); + this.serverUrlComboBox.Size = new System.Drawing.Size(136, 21); this.serverUrlComboBox.TabIndex = 0; - // + // // localghostLinkLabel - // + // this.localghostLinkLabel.AccessibleDescription = "Link to LocalGhost GitLab repository."; this.localghostLinkLabel.AccessibleName = "LocalGhost link"; this.localghostLinkLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.localghostLinkLabel.AutoSize = true; - this.localghostLinkLabel.Location = new System.Drawing.Point(225, 202); + this.localghostLinkLabel.Location = new System.Drawing.Point(169, 164); + this.localghostLinkLabel.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.localghostLinkLabel.Name = "localghostLinkLabel"; - this.localghostLinkLabel.Size = new System.Drawing.Size(189, 16); + this.localghostLinkLabel.Size = new System.Drawing.Size(149, 13); this.localghostLinkLabel.TabIndex = 3; this.localghostLinkLabel.TabStop = true; this.localghostLinkLabel.Text = "LocalGhost by grappigegovert"; this.localghostLinkLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; this.localghostLinkLabel.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.LocalghostLink_LinkClicked); - // + // // buttonOptions - // + // this.buttonOptions.AccessibleDescription = "Button that opens the options menu."; this.buttonOptions.AccessibleName = "Options button"; this.buttonOptions.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.buttonOptions.Location = new System.Drawing.Point(12, 194); - this.buttonOptions.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonOptions.Location = new System.Drawing.Point(9, 158); + this.buttonOptions.Margin = new System.Windows.Forms.Padding(2); this.buttonOptions.Name = "buttonOptions"; - this.buttonOptions.Size = new System.Drawing.Size(93, 33); + this.buttonOptions.Size = new System.Drawing.Size(70, 27); this.buttonOptions.TabIndex = 2; this.buttonOptions.Text = "Options"; this.buttonOptions.UseVisualStyleBackColor = true; this.buttonOptions.Click += new System.EventHandler(this.ButtonOptions_Click); - // + // // basedOnLabel - // + // this.basedOnLabel.AccessibleName = "Based on"; this.basedOnLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.basedOnLabel.AutoSize = true; - this.basedOnLabel.Location = new System.Drawing.Point(153, 202); - this.basedOnLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.basedOnLabel.Location = new System.Drawing.Point(115, 164); this.basedOnLabel.Name = "basedOnLabel"; - this.basedOnLabel.Size = new System.Drawing.Size(65, 16); + this.basedOnLabel.Size = new System.Drawing.Size(52, 13); this.basedOnLabel.TabIndex = 9; this.basedOnLabel.Text = "Based on"; this.basedOnLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight; - // + // // statusLabel - // + // this.statusLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.statusLabel.AutoSize = true; - this.statusLabel.Location = new System.Drawing.Point(260, 50); + this.statusLabel.Location = new System.Drawing.Point(152, 41); + this.statusLabel.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.statusLabel.Name = "statusLabel"; - this.statusLabel.Size = new System.Drawing.Size(47, 16); + this.statusLabel.Size = new System.Drawing.Size(40, 13); this.statusLabel.TabIndex = 10; this.statusLabel.Text = "Status:"; - // + // // novikovPictureBox - // + // this.novikovPictureBox.AccessibleDescription = "Icon showing the patcher status."; this.novikovPictureBox.AccessibleName = "Status icon"; this.novikovPictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.novikovPictureBox.Image = global::HitmanPatcher.Properties.Resources.Novikov_standard; this.novikovPictureBox.InitialImage = ((System.Drawing.Image)(resources.GetObject("novikovPictureBox.InitialImage"))); - this.novikovPictureBox.Location = new System.Drawing.Point(313, 44); - this.novikovPictureBox.Margin = new System.Windows.Forms.Padding(4); + this.novikovPictureBox.Location = new System.Drawing.Point(197, 36); this.novikovPictureBox.Name = "novikovPictureBox"; - this.novikovPictureBox.Size = new System.Drawing.Size(45, 31); + this.novikovPictureBox.Size = new System.Drawing.Size(34, 25); this.novikovPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; this.novikovPictureBox.TabIndex = 11; this.novikovPictureBox.TabStop = false; - // + // // trayIcon - // + // this.trayIcon.ContextMenuStrip = this.trayMenu; this.trayIcon.Icon = ((System.Drawing.Icon)(resources.GetObject("trayIcon.Icon"))); this.trayIcon.Text = "Peacock Patcher"; this.trayIcon.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.menuItemOpen_Click); - // + // // trayMenu - // + // this.trayMenu.ImageScalingSize = new System.Drawing.Size(20, 20); - this.trayMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] - { - this.menuItemOpen, - this.menuItemRepatch, - this.domainsTrayMenu, - this.menuItemExit - }); + this.trayMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.menuItemOpen, + this.menuItemRepatch, + this.domainsTrayMenu, + this.menuItemExit}); this.trayMenu.Name = "trayMenu"; - this.trayMenu.Size = new System.Drawing.Size(173, 100); - // + this.trayMenu.Size = new System.Drawing.Size(151, 92); + // // menuItemOpen - // + // this.menuItemOpen.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold); this.menuItemOpen.Name = "menuItemOpen"; - this.menuItemOpen.Size = new System.Drawing.Size(172, 24); + this.menuItemOpen.Size = new System.Drawing.Size(150, 22); this.menuItemOpen.Text = "&Open Patcher"; this.menuItemOpen.Click += new System.EventHandler(this.menuItemOpen_Click); - // + // // menuItemRepatch - // + // this.menuItemRepatch.Name = "menuItemRepatch"; - this.menuItemRepatch.Size = new System.Drawing.Size(172, 24); + this.menuItemRepatch.Size = new System.Drawing.Size(150, 22); this.menuItemRepatch.Text = "&Re-patch"; this.menuItemRepatch.Click += new System.EventHandler(this.RePatchButton_Click); - // + // // domainsTrayMenu - // + // this.domainsTrayMenu.Name = "domainsTrayMenu"; - this.domainsTrayMenu.Size = new System.Drawing.Size(172, 24); + this.domainsTrayMenu.Size = new System.Drawing.Size(150, 22); this.domainsTrayMenu.Text = "Set &Domain"; - // + // // menuItemExit - // + // this.menuItemExit.Name = "menuItemExit"; - this.menuItemExit.Size = new System.Drawing.Size(172, 24); + this.menuItemExit.Size = new System.Drawing.Size(150, 22); this.menuItemExit.Text = "&Exit"; this.menuItemExit.Click += new System.EventHandler(this.menuItemExit_Click); - // + // + // serverList + // + this.serverList.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.serverList.Location = new System.Drawing.Point(235, 8); + this.serverList.Name = "serverList"; + this.serverList.Size = new System.Drawing.Size(83, 23); + this.serverList.TabIndex = 12; + this.serverList.Text = "Edit Serverlist"; + this.serverList.UseVisualStyleBackColor = true; + this.serverList.Click += new System.EventHandler(this.serverList_Click); + // // MainForm - // + // this.AccessibleName = "Peacock Patcher"; - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.SystemColors.Control; - this.ClientSize = new System.Drawing.Size(429, 233); + this.ClientSize = new System.Drawing.Size(322, 189); + this.Controls.Add(this.serverList); this.Controls.Add(this.novikovPictureBox); this.Controls.Add(this.statusLabel); this.Controls.Add(this.basedOnLabel); @@ -285,9 +293,9 @@ private void InitializeComponent() this.Controls.Add(this.logListView); this.Controls.Add(this.serverAddressLabel); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Margin = new System.Windows.Forms.Padding(2); this.MaximizeBox = false; - this.MinimumSize = new System.Drawing.Size(423, 238); + this.MinimumSize = new System.Drawing.Size(321, 201); this.Name = "MainForm"; this.Text = "Peacock Patcher"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing); @@ -297,6 +305,7 @@ private void InitializeComponent() this.trayMenu.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); + } #endregion @@ -320,6 +329,7 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem menuItemOpen; private System.Windows.Forms.ContextMenuStrip logContextMenu; private System.Windows.Forms.ToolStripMenuItem copyLogToClipboardToolStripMenuItem; + private System.Windows.Forms.Button serverList; } } diff --git a/patcher/MainForm.cs b/patcher/MainForm.cs index 5a30dfe0e..2fe475499 100644 --- a/patcher/MainForm.cs +++ b/patcher/MainForm.cs @@ -6,26 +6,20 @@ using System.Drawing; using System.IO; using System.Text; +using Newtonsoft.Json; namespace HitmanPatcher { public partial class MainForm : Form, ILoggingProvider { private static MainForm instance; + private GameServer[] gameServers; public static MainForm GetInstance() { return instance ??= new MainForm(); } - private static readonly Dictionary servers = new Dictionary() - { - {"IOI Official", "config.hitman.io"}, - {"Peacock Local", "127.0.0.1"} - }; - - private static readonly Dictionary serversReverse = servers.ToDictionary(kvp => kvp.Value, kvp => kvp.Key); - private void ToggleTheme(bool darkModeEnabled) { // Change main form background @@ -60,6 +54,27 @@ private void ToggleTheme(bool darkModeEnabled) public MainForm() { InitializeComponent(); + + // Try to get ServerList + try + { + var fileContent = File.ReadAllText("Servers.json", Encoding.UTF8); + gameServers = JsonConvert.DeserializeObject(fileContent); + if (gameServers == null || gameServers.Length == 0) + { + gameServers = CreateDefautServerList(); + } + + } + catch ( FileNotFoundException ex) + { + gameServers = CreateDefautServerList(); + } + catch (JsonSerializationException ex) + { + gameServers = CreateDefautServerList(); + } + logListView.Columns[0].Width = logListView.Width - 4 - SystemInformation.VerticalScrollBarWidth; Timer timer = new Timer { @@ -92,6 +107,16 @@ public MainForm() } } + private static GameServer[] CreateDefautServerList() + { + GameServer[] gameServers = new GameServer[2]; + gameServers[0] = new GameServer { ServerName = "IOI Official", ServerAddress = "config.hitman.io" }; + gameServers[1] = new GameServer { ServerName = "Peacock Local", ServerAddress = "127.0.0.1" }; + var serverList = JsonConvert.SerializeObject(gameServers); + File.WriteAllText("Servers.json", serverList, Encoding.UTF8); + return gameServers; + } + public void log(string msg) { if (msg.Contains("Failed to patch")) @@ -128,14 +153,16 @@ private void MainForm_FormClosing(object sender, FormClosingEventArgs e) private string GetSelectedServerHostname() { - if (!servers.TryGetValue(serverUrlComboBox.Text, out string hostname)) + string hostname = ""; + var result = gameServers.FirstOrDefault(server => server.ServerName == serverUrlComboBox.Text); + if(result == null) { hostname = serverUrlComboBox.Text; } if (string.IsNullOrEmpty(hostname)) { - hostname = "localhost"; + hostname = "127.0.0.1"; } return hostname; @@ -143,9 +170,24 @@ private string GetSelectedServerHostname() private void SetSelectedServerHostname(string input) { - if (!serversReverse.TryGetValue(input, out string result)) + GameServer server = null; + if (input == "localhost" || input == "127.0.0.1") + { + server = gameServers.FirstOrDefault(server => server.ServerAddress == input); + } + else { - result = input; + server = gameServers.FirstOrDefault(server => server.ServerName == input); + } + + string result; + if (server == null) + { + result = input; + } + else + { + result = server.ServerName; } serverUrlComboBox.Text = result; @@ -183,7 +225,10 @@ private Settings CurrentSettings SetSelectedServerHostname(value.patchOptions.CustomConfigDomain); serverUrlComboBox.Items.Clear(); - serverUrlComboBox.Items.AddRange(servers.Keys.ToArray()); + foreach(var gameserver in gameServers) + { + serverUrlComboBox.Items.Add(gameserver.ServerName); + } } } @@ -279,5 +324,21 @@ private void copyLogToClipboardToolStripMenuItem_Click(object sender, EventArgs } Clipboard.SetText(builder.ToString()); } + + private void serverList_Click(object sender, EventArgs e) + { + ServerListEditor serverListEditor = new ServerListEditor(); + serverListEditor.GameServers = gameServers; + var result = serverListEditor.ShowDialog(); + if (result == DialogResult.OK) + { + gameServers = serverListEditor.GameServers; + serverUrlComboBox.Items.Clear(); + foreach (var gameserver in gameServers) + { + serverUrlComboBox.Items.Add(gameserver.ServerName); + } + } + } } } diff --git a/patcher/ServerListEditor.Designer.cs b/patcher/ServerListEditor.Designer.cs new file mode 100644 index 000000000..6b0fab62f --- /dev/null +++ b/patcher/ServerListEditor.Designer.cs @@ -0,0 +1,102 @@ +namespace HitmanPatcher +{ + partial class ServerListEditor + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.saveButton = new System.Windows.Forms.Button(); + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.ServerName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ServerAddress = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.SuspendLayout(); + // + // saveButton + // + this.saveButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.saveButton.Location = new System.Drawing.Point(154, 237); + this.saveButton.Name = "saveButton"; + this.saveButton.Size = new System.Drawing.Size(75, 23); + this.saveButton.TabIndex = 0; + this.saveButton.Text = "Save"; + this.saveButton.UseVisualStyleBackColor = true; + this.saveButton.Click += new System.EventHandler(this.saveButton_Click); + // + // dataGridView1 + // + this.dataGridView1.AllowUserToOrderColumns = true; + this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ServerName, + this.ServerAddress}); + this.dataGridView1.Location = new System.Drawing.Point(0, -1); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.Size = new System.Drawing.Size(383, 230); + this.dataGridView1.TabIndex = 1; + // + // ServerName + // + this.ServerName.HeaderText = "Name"; + this.ServerName.Name = "ServerName"; + this.ServerName.Width = 140; + // + // ServerAddress + // + this.ServerAddress.HeaderText = "Address"; + this.ServerAddress.Name = "ServerAddress"; + this.ServerAddress.Width = 200; + // + // ServerListEditor + // + this.AcceptButton = this.saveButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(383, 265); + this.Controls.Add(this.dataGridView1); + this.Controls.Add(this.saveButton); + this.MaximizeBox = false; + this.MaximumSize = new System.Drawing.Size(399, 2000); + this.MinimumSize = new System.Drawing.Size(399, 175); + this.Name = "ServerListEditor"; + this.Text = "Server Editor"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button saveButton; + private System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.DataGridViewTextBoxColumn ServerName; + private System.Windows.Forms.DataGridViewTextBoxColumn ServerAddress; + } +} \ No newline at end of file diff --git a/patcher/ServerListEditor.cs b/patcher/ServerListEditor.cs new file mode 100644 index 000000000..43dfeb5cb --- /dev/null +++ b/patcher/ServerListEditor.cs @@ -0,0 +1,52 @@ +using Newtonsoft.Json; +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace HitmanPatcher +{ + public partial class ServerListEditor : Form + { + private GameServer[] gameServers; + public GameServer[] GameServers { + get { return gameServers; } + set + { + gameServers = value; + foreach (GameServer server in gameServers) + { + string[] tmp = { server.ServerName, server.ServerAddress }; + dataGridView1.Rows.Add(tmp); + } + } + } + public ServerListEditor() + { + InitializeComponent(); + } + + private void saveButton_Click(object sender, EventArgs e) + { + var list = new List(); + + for(int i = 0; i < dataGridView1.RowCount - 1; i++) + { + var item = dataGridView1.Rows[i]; + list.Add(new GameServer { ServerName = item.Cells[0].Value.ToString(), ServerAddress = item.Cells[1].Value.ToString() }); + } + GameServers = list.ToArray(); + var serverString = JsonConvert.SerializeObject(GameServers); + File.WriteAllText("Servers.json", serverString, Encoding.UTF8); + this.DialogResult = DialogResult.OK; + this.Close(); + } + } +} diff --git a/patcher/ServerListEditor.resx b/patcher/ServerListEditor.resx new file mode 100644 index 000000000..584faa6e3 --- /dev/null +++ b/patcher/ServerListEditor.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/patcher/packages.config b/patcher/packages.config new file mode 100644 index 000000000..0b14af3ad --- /dev/null +++ b/patcher/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file From ecf5aed092566a410b54fccf61fd46a9ae45c745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCssig?= Date: Thu, 31 Oct 2024 12:38:46 +0100 Subject: [PATCH 2/7] Update patcher/.gitignore add the newline back Co-authored-by: Govert de Gans --- patcher/.gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patcher/.gitignore b/patcher/.gitignore index 4d374e113..b05f388d3 100644 --- a/patcher/.gitignore +++ b/patcher/.gitignore @@ -4,4 +4,4 @@ obj/* /HitmanPatcher.sln.DotSettings.user /.idea/.idea.HitmanPatcher/.idea/riderMarkupCache.xml *.suo -packages/* \ No newline at end of file +packages/* From 629ce36520adbc7f7fd7b4389177a4ba8b2d5310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCssig?= Date: Thu, 31 Oct 2024 14:29:23 +0100 Subject: [PATCH 3/7] server.json is saved to "%appdata%\Peackock" now --- patcher/MainForm.cs | 76 +++++++++++++++++++++---------------- patcher/ServerListEditor.cs | 7 +++- 2 files changed, 49 insertions(+), 34 deletions(-) diff --git a/patcher/MainForm.cs b/patcher/MainForm.cs index 2fe475499..9f0439917 100644 --- a/patcher/MainForm.cs +++ b/patcher/MainForm.cs @@ -14,6 +14,7 @@ public partial class MainForm : Form, ILoggingProvider { private static MainForm instance; private GameServer[] gameServers; + private readonly string configLocation; public static MainForm GetInstance() { @@ -54,26 +55,14 @@ private void ToggleTheme(bool darkModeEnabled) public MainForm() { InitializeComponent(); - + // Try to get ServerList - try - { - var fileContent = File.ReadAllText("Servers.json", Encoding.UTF8); - gameServers = JsonConvert.DeserializeObject(fileContent); - if (gameServers == null || gameServers.Length == 0) - { - gameServers = CreateDefautServerList(); - } + string appData = Environment.GetFolderPath(Environment + .SpecialFolder + .ApplicationData); - } - catch ( FileNotFoundException ex) - { - gameServers = CreateDefautServerList(); - } - catch (JsonSerializationException ex) - { - gameServers = CreateDefautServerList(); - } + configLocation = $@"{appData}\PeacockProject\"; + logListView.Columns[0].Width = logListView.Width - 4 - SystemInformation.VerticalScrollBarWidth; Timer timer = new Timer @@ -82,7 +71,7 @@ public MainForm() }; timer.Tick += (sender, args) => MemoryPatcher.PatchAllProcesses(this, CurrentSettings.patchOptions); timer.Enabled = true; - + gameServers = new GameServer[0]; try { CurrentSettings = Settings.GetFromFile(); @@ -91,6 +80,26 @@ public MainForm() { CurrentSettings = new Settings(); } + try + { + var fileContent = File.ReadAllText($@"{configLocation}\Servers.json", Encoding.UTF8); + gameServers = JsonConvert.DeserializeObject(fileContent); + if (gameServers == null || gameServers.Length == 0) + { + gameServers = CreateDefautServerList(); + } + + } + catch (FileNotFoundException ex) + { + gameServers = CreateDefautServerList(); + } + catch (JsonSerializationException ex) + { + gameServers = CreateDefautServerList(); + } + SetSelectedServerHostname(serverUrlComboBox.Text); + UpdateServerUrlCombobox(); updateTrayDomains(); ToggleTheme(CurrentSettings.darkModeEnabled); @@ -107,13 +116,14 @@ public MainForm() } } - private static GameServer[] CreateDefautServerList() + private GameServer[] CreateDefautServerList() { GameServer[] gameServers = new GameServer[2]; gameServers[0] = new GameServer { ServerName = "IOI Official", ServerAddress = "config.hitman.io" }; gameServers[1] = new GameServer { ServerName = "Peacock Local", ServerAddress = "127.0.0.1" }; var serverList = JsonConvert.SerializeObject(gameServers); - File.WriteAllText("Servers.json", serverList, Encoding.UTF8); + + File.WriteAllText($@"{configLocation}Servers.json", serverList, Encoding.UTF8); return gameServers; } @@ -143,9 +153,9 @@ private void RePatchButton_Click(object sender, EventArgs e) private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { - if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\PeacockProject")) + if (!Directory.Exists(configLocation)) { - Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\PeacockProject"); + Directory.CreateDirectory(configLocation); } CurrentSettings.SaveToFile(); @@ -223,12 +233,16 @@ private Settings CurrentSettings _currentSettings = value; SetSelectedServerHostname(value.patchOptions.CustomConfigDomain); + UpdateServerUrlCombobox(); + } + } - serverUrlComboBox.Items.Clear(); - foreach(var gameserver in gameServers) - { - serverUrlComboBox.Items.Add(gameserver.ServerName); - } + private void UpdateServerUrlCombobox() + { + serverUrlComboBox.Items.Clear(); + foreach (var gameserver in gameServers) + { + serverUrlComboBox.Items.Add(gameserver.ServerName); } } @@ -333,11 +347,7 @@ private void serverList_Click(object sender, EventArgs e) if (result == DialogResult.OK) { gameServers = serverListEditor.GameServers; - serverUrlComboBox.Items.Clear(); - foreach (var gameserver in gameServers) - { - serverUrlComboBox.Items.Add(gameserver.ServerName); - } + UpdateServerUrlCombobox(); } } } diff --git a/patcher/ServerListEditor.cs b/patcher/ServerListEditor.cs index 43dfeb5cb..c9b8fe143 100644 --- a/patcher/ServerListEditor.cs +++ b/patcher/ServerListEditor.cs @@ -43,8 +43,13 @@ private void saveButton_Click(object sender, EventArgs e) list.Add(new GameServer { ServerName = item.Cells[0].Value.ToString(), ServerAddress = item.Cells[1].Value.ToString() }); } GameServers = list.ToArray(); + string appData = Environment.GetFolderPath(Environment + .SpecialFolder + .ApplicationData); + + var folder = $@"{appData}\PeacockProject\"; var serverString = JsonConvert.SerializeObject(GameServers); - File.WriteAllText("Servers.json", serverString, Encoding.UTF8); + File.WriteAllText(@$"{folder}Servers.json", serverString, Encoding.UTF8); this.DialogResult = DialogResult.OK; this.Close(); } From 9a9f474f6fe0472e2dff61409c608694399402d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCssig?= Date: Thu, 31 Oct 2024 17:57:16 +0100 Subject: [PATCH 4/7] Location refactoring Introduce static ConfigLocation string use Path.Combine instead of string operations --- patcher/MainForm.cs | 13 ++++--------- patcher/ServerListEditor.cs | 8 ++------ patcher/Settings.cs | 27 ++++++++++++++------------- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/patcher/MainForm.cs b/patcher/MainForm.cs index 9f0439917..279a95376 100644 --- a/patcher/MainForm.cs +++ b/patcher/MainForm.cs @@ -14,7 +14,7 @@ public partial class MainForm : Form, ILoggingProvider { private static MainForm instance; private GameServer[] gameServers; - private readonly string configLocation; + private readonly string serverlistLocation; public static MainForm GetInstance() { @@ -61,7 +61,7 @@ public MainForm() .SpecialFolder .ApplicationData); - configLocation = $@"{appData}\PeacockProject\"; + serverlistLocation = Path.Combine(Settings.ConfigLocation, "Server.json"); logListView.Columns[0].Width = logListView.Width - 4 - SystemInformation.VerticalScrollBarWidth; @@ -82,7 +82,7 @@ public MainForm() } try { - var fileContent = File.ReadAllText($@"{configLocation}\Servers.json", Encoding.UTF8); + var fileContent = File.ReadAllText(serverlistLocation, Encoding.UTF8); gameServers = JsonConvert.DeserializeObject(fileContent); if (gameServers == null || gameServers.Length == 0) { @@ -123,7 +123,7 @@ private GameServer[] CreateDefautServerList() gameServers[1] = new GameServer { ServerName = "Peacock Local", ServerAddress = "127.0.0.1" }; var serverList = JsonConvert.SerializeObject(gameServers); - File.WriteAllText($@"{configLocation}Servers.json", serverList, Encoding.UTF8); + File.WriteAllText(serverlistLocation, serverList, Encoding.UTF8); return gameServers; } @@ -153,11 +153,6 @@ private void RePatchButton_Click(object sender, EventArgs e) private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { - if (!Directory.Exists(configLocation)) - { - Directory.CreateDirectory(configLocation); - } - CurrentSettings.SaveToFile(); } diff --git a/patcher/ServerListEditor.cs b/patcher/ServerListEditor.cs index c9b8fe143..8edc400e4 100644 --- a/patcher/ServerListEditor.cs +++ b/patcher/ServerListEditor.cs @@ -43,13 +43,9 @@ private void saveButton_Click(object sender, EventArgs e) list.Add(new GameServer { ServerName = item.Cells[0].Value.ToString(), ServerAddress = item.Cells[1].Value.ToString() }); } GameServers = list.ToArray(); - string appData = Environment.GetFolderPath(Environment - .SpecialFolder - .ApplicationData); - - var folder = $@"{appData}\PeacockProject\"; + var serverString = JsonConvert.SerializeObject(GameServers); - File.WriteAllText(@$"{folder}Servers.json", serverString, Encoding.UTF8); + File.WriteAllText(Path.Combine(Settings.ConfigLocation, "Server.json"), serverString, Encoding.UTF8); this.DialogResult = DialogResult.OK; this.Close(); } diff --git a/patcher/Settings.cs b/patcher/Settings.cs index eb7cabece..a40e56222 100644 --- a/patcher/Settings.cs +++ b/patcher/Settings.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; @@ -11,6 +11,17 @@ public class Settings public bool minimizeToTray; public bool darkModeEnabled; public List trayDomains; + public static readonly string ConfigLocation; + + static Settings() + { + ConfigLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "PeacockProject"); + + if (!Directory.Exists(ConfigLocation)) + { + Directory.CreateDirectory(ConfigLocation); + } + } public Settings() { @@ -32,18 +43,8 @@ public Settings() private static string GetSavePath() { - if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\PeacockProject")) - { - Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\PeacockProject"); - } - - string appData = Environment.GetFolderPath(Environment - .SpecialFolder - .ApplicationData); - - string folder = $@"{appData}\PeacockProject\"; - string config1 = folder + "peacock_patcher.conf"; - string config2 = folder + "peacock_patcher2.conf"; + string config1 = Path.Combine(ConfigLocation, "peacock_patcher.conf"); + string config2 = Path.Combine(ConfigLocation, "peacock_patcher2.conf"); if (File.Exists(config1)) { From 9103eae4f262607db4065c04eab26a9789138d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCssig?= Date: Thu, 31 Oct 2024 18:38:14 +0100 Subject: [PATCH 5/7] revert .Net Framework version back to 4.6 --- patcher/App.config | 2 +- patcher/CliLocale.Designer.cs | 87 ++++++++++++++++-------- patcher/HitmanPatcher.csproj | 2 +- patcher/Properties/Resources.Designer.cs | 7 +- patcher/Properties/Settings.Designer.cs | 10 +-- 5 files changed, 72 insertions(+), 36 deletions(-) diff --git a/patcher/App.config b/patcher/App.config index 4e0cab57c..5b517b5da 100644 --- a/patcher/App.config +++ b/patcher/App.config @@ -18,6 +18,6 @@ --> - + diff --git a/patcher/CliLocale.Designer.cs b/patcher/CliLocale.Designer.cs index 679a1f453..149cceb6e 100644 --- a/patcher/CliLocale.Designer.cs +++ b/patcher/CliLocale.Designer.cs @@ -1,9 +1,10 @@ //------------------------------------------------------------------------------ // -// This code was generated by a tool. +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 // -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. // //------------------------------------------------------------------------------ @@ -11,32 +12,46 @@ namespace HitmanPatcher { using System; - [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [System.Diagnostics.DebuggerNonUserCodeAttribute()] - [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class CliLocale { - private static System.Resources.ResourceManager resourceMan; + private static global::System.Resources.ResourceManager resourceMan; - private static System.Globalization.CultureInfo resourceCulture; + private static global::System.Globalization.CultureInfo resourceCulture; - [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal CliLocale() { } - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] - internal static System.Resources.ResourceManager ResourceManager { + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { get { - if (object.Equals(null, resourceMan)) { - System.Resources.ResourceManager temp = new System.Resources.ResourceManager("HitmanPatcher.CliLocale", typeof(CliLocale).Assembly); + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("HitmanPatcher.CliLocale", typeof(CliLocale).Assembly); resourceMan = temp; } return resourceMan; } } - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] - internal static System.Globalization.CultureInfo Culture { + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { get { return resourceCulture; } @@ -45,39 +60,57 @@ internal static System.Globalization.CultureInfo Culture { } } - internal static string HeadlessDescription { + /// + /// Sucht eine lokalisierte Zeichenfolge, die The domain for the game to connect to. ähnelt. + /// + internal static string DomainDescription { get { - return ResourceManager.GetString("HeadlessDescription", resourceCulture); + return ResourceManager.GetString("DomainDescription", resourceCulture); } } - internal static string DomainDescription { + /// + /// Sucht eine lokalisierte Zeichenfolge, die ====== Peacock Patcher - Headless mode ====== ähnelt. + /// + internal static string HeadlessBanner { get { - return ResourceManager.GetString("DomainDescription", resourceCulture); + return ResourceManager.GetString("HeadlessBanner", resourceCulture); } } - internal static string UseHttpDescription { + /// + /// Sucht eine lokalisierte Zeichenfolge, die If the patcher should be run without the GUI. ähnelt. + /// + internal static string HeadlessDescription { get { - return ResourceManager.GetString("UseHttpDescription", resourceCulture); + return ResourceManager.GetString("HeadlessDescription", resourceCulture); } } - internal static string OptionalDynResDescription { + /// + /// Sucht eine lokalisierte Zeichenfolge, die Peacock Patcher CLI - Copyright (c) 2020-2024 grappigegovert & The Peacock Project ähnelt. + /// + internal static string HelpHeader { get { - return ResourceManager.GetString("OptionalDynResDescription", resourceCulture); + return ResourceManager.GetString("HelpHeader", resourceCulture); } } - internal static string HeadlessBanner { + /// + /// Sucht eine lokalisierte Zeichenfolge, die If the game should not force the user offline if the dynamic resources are missing or invalid. ähnelt. + /// + internal static string OptionalDynResDescription { get { - return ResourceManager.GetString("HeadlessBanner", resourceCulture); + return ResourceManager.GetString("OptionalDynResDescription", resourceCulture); } } - internal static string HelpHeader { + /// + /// Sucht eine lokalisierte Zeichenfolge, die If the game should connect using "http://" instead of the default, "https://". ähnelt. + /// + internal static string UseHttpDescription { get { - return ResourceManager.GetString("HelpHeader", resourceCulture); + return ResourceManager.GetString("UseHttpDescription", resourceCulture); } } } diff --git a/patcher/HitmanPatcher.csproj b/patcher/HitmanPatcher.csproj index 989085336..fab6890cb 100644 --- a/patcher/HitmanPatcher.csproj +++ b/patcher/HitmanPatcher.csproj @@ -26,7 +26,7 @@ Properties HitmanPatcher PeacockPatcher - v4.8 + v4.6 512 True diff --git a/patcher/Properties/Resources.Designer.cs b/patcher/Properties/Resources.Designer.cs index 9aeb8e631..55d4ecab6 100644 --- a/patcher/Properties/Resources.Designer.cs +++ b/patcher/Properties/Resources.Designer.cs @@ -8,7 +8,10 @@ // //------------------------------------------------------------------------------ -namespace HitmanPatcher.Properties { +namespace HitmanPatcher.Properties { + using System; + + /// /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. /// @@ -16,7 +19,7 @@ namespace HitmanPatcher.Properties { // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { diff --git a/patcher/Properties/Settings.Designer.cs b/patcher/Properties/Settings.Designer.cs index eeee566bd..36d8d2918 100644 --- a/patcher/Properties/Settings.Designer.cs +++ b/patcher/Properties/Settings.Designer.cs @@ -1,10 +1,10 @@ //------------------------------------------------------------------------------ // -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 // -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. // //------------------------------------------------------------------------------ @@ -12,7 +12,7 @@ namespace HitmanPatcher.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.11.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); From ee57e29f5781498a7188d39c1c5eaa0508d22e28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCssig?= Date: Thu, 31 Oct 2024 19:05:35 +0100 Subject: [PATCH 6/7] Remove Json and use a CSV format remove Newtonsoft.Json --- patcher/GameServer.cs | 36 +++++++++++++++++++++++++++ patcher/HitmanPatcher.csproj | 4 --- patcher/MainForm.cs | 47 ++++++++++++++---------------------- patcher/ServerListEditor.cs | 7 +++--- patcher/packages.config | 4 --- 5 files changed, 58 insertions(+), 40 deletions(-) delete mode 100644 patcher/packages.config diff --git a/patcher/GameServer.cs b/patcher/GameServer.cs index 457e61c3b..d148ff96a 100644 --- a/patcher/GameServer.cs +++ b/patcher/GameServer.cs @@ -1,5 +1,7 @@ using System; +using System.Collections; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,5 +12,39 @@ public class GameServer { public string ServerName { get; set; } public string ServerAddress { get; set; } + + public static void SaveServers(string path, GameServer[] servers) + { + StringBuilder stringBuilder = new StringBuilder(); + foreach (GameServer server in servers) + { + stringBuilder.Append(server.ServerName + ";" + server.ServerAddress + '\n'); + } + File.WriteAllText(path, stringBuilder.ToString().Trim()); + } + + public static GameServer[] LoadServers(string path) + { + if (File.Exists(path)) + { + var serversString = File.ReadAllText(path).Trim(); + List servers = new List(); + foreach (var line in serversString.Split( '\n')) + { + var serverString = line.Split(';'); + var server = new GameServer(); + server.ServerName = serverString[0]; + server.ServerAddress = serverString[1]; + servers.Add(server); + } + return servers.ToArray(); + } + else + { + throw new FileNotFoundException(path); + } + + } } + } diff --git a/patcher/HitmanPatcher.csproj b/patcher/HitmanPatcher.csproj index fab6890cb..c299786c6 100644 --- a/patcher/HitmanPatcher.csproj +++ b/patcher/HitmanPatcher.csproj @@ -62,9 +62,6 @@ patcher.ico - - packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll - @@ -161,7 +158,6 @@ - SettingsSingleFileGenerator Settings.Designer.cs diff --git a/patcher/MainForm.cs b/patcher/MainForm.cs index 279a95376..ddf12e0de 100644 --- a/patcher/MainForm.cs +++ b/patcher/MainForm.cs @@ -6,7 +6,6 @@ using System.Drawing; using System.IO; using System.Text; -using Newtonsoft.Json; namespace HitmanPatcher { @@ -57,13 +56,22 @@ public MainForm() InitializeComponent(); // Try to get ServerList - string appData = Environment.GetFolderPath(Environment - .SpecialFolder - .ApplicationData); + serverlistLocation = Path.Combine(Settings.ConfigLocation, "ServerList.txt"); + try + { + gameServers = GameServer.LoadServers(serverlistLocation); + if (gameServers == null || gameServers.Length == 0) + { + gameServers = CreateDefautServerList(); + } + + } + catch (FileNotFoundException ex) + { + gameServers = CreateDefautServerList(); + } + - serverlistLocation = Path.Combine(Settings.ConfigLocation, "Server.json"); - - logListView.Columns[0].Width = logListView.Width - 4 - SystemInformation.VerticalScrollBarWidth; Timer timer = new Timer { @@ -71,7 +79,6 @@ public MainForm() }; timer.Tick += (sender, args) => MemoryPatcher.PatchAllProcesses(this, CurrentSettings.patchOptions); timer.Enabled = true; - gameServers = new GameServer[0]; try { CurrentSettings = Settings.GetFromFile(); @@ -80,24 +87,7 @@ public MainForm() { CurrentSettings = new Settings(); } - try - { - var fileContent = File.ReadAllText(serverlistLocation, Encoding.UTF8); - gameServers = JsonConvert.DeserializeObject(fileContent); - if (gameServers == null || gameServers.Length == 0) - { - gameServers = CreateDefautServerList(); - } - - } - catch (FileNotFoundException ex) - { - gameServers = CreateDefautServerList(); - } - catch (JsonSerializationException ex) - { - gameServers = CreateDefautServerList(); - } + SetSelectedServerHostname(serverUrlComboBox.Text); UpdateServerUrlCombobox(); updateTrayDomains(); @@ -121,9 +111,7 @@ private GameServer[] CreateDefautServerList() GameServer[] gameServers = new GameServer[2]; gameServers[0] = new GameServer { ServerName = "IOI Official", ServerAddress = "config.hitman.io" }; gameServers[1] = new GameServer { ServerName = "Peacock Local", ServerAddress = "127.0.0.1" }; - var serverList = JsonConvert.SerializeObject(gameServers); - - File.WriteAllText(serverlistLocation, serverList, Encoding.UTF8); + GameServer.SaveServers(serverlistLocation, gameServers); return gameServers; } @@ -338,6 +326,7 @@ private void serverList_Click(object sender, EventArgs e) { ServerListEditor serverListEditor = new ServerListEditor(); serverListEditor.GameServers = gameServers; + serverListEditor.SaveLocation = serverlistLocation; var result = serverListEditor.ShowDialog(); if (result == DialogResult.OK) { diff --git a/patcher/ServerListEditor.cs b/patcher/ServerListEditor.cs index 8edc400e4..eb16d150d 100644 --- a/patcher/ServerListEditor.cs +++ b/patcher/ServerListEditor.cs @@ -1,4 +1,3 @@ -using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; @@ -16,6 +15,8 @@ namespace HitmanPatcher public partial class ServerListEditor : Form { private GameServer[] gameServers; + public string SaveLocation { get; set; } + public GameServer[] GameServers { get { return gameServers; } set @@ -44,8 +45,8 @@ private void saveButton_Click(object sender, EventArgs e) } GameServers = list.ToArray(); - var serverString = JsonConvert.SerializeObject(GameServers); - File.WriteAllText(Path.Combine(Settings.ConfigLocation, "Server.json"), serverString, Encoding.UTF8); + + GameServer.SaveServers(Path.Combine(Settings.ConfigLocation, SaveLocation), gameServers); this.DialogResult = DialogResult.OK; this.Close(); } diff --git a/patcher/packages.config b/patcher/packages.config deleted file mode 100644 index 0b14af3ad..000000000 --- a/patcher/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file From 4cd6ab7524b4be85ca069806b0b465649150c578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCssig?= Date: Thu, 31 Oct 2024 19:15:27 +0100 Subject: [PATCH 7/7] prevent users from destroying the config file by replacing ';' --- patcher/GameServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patcher/GameServer.cs b/patcher/GameServer.cs index d148ff96a..1141da341 100644 --- a/patcher/GameServer.cs +++ b/patcher/GameServer.cs @@ -18,7 +18,7 @@ public static void SaveServers(string path, GameServer[] servers) StringBuilder stringBuilder = new StringBuilder(); foreach (GameServer server in servers) { - stringBuilder.Append(server.ServerName + ";" + server.ServerAddress + '\n'); + stringBuilder.Append(server.ServerName.Replace(";","-") + ";" + server.ServerAddress.Replace(";", "-") + '\n'); } File.WriteAllText(path, stringBuilder.ToString().Trim()); }