Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Serverlist editor to the Patcher #527

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Tondorian
Copy link

@Tondorian Tondorian commented Oct 25, 2024

This will fix #428

Scope

Add a button to the patcher to open a new Dialog to edit the serverList
This pull request also added a dependency to Newtonsoft.Json
Also updated .NetFramework to 4.8 since 4.6 is EoL since April 22

Test Plan

Clicked the new button
edit the entries and save them
changes are stored in "Servers.json"

Checklist

  • I have run Prettier to reformat any changed files
  • I have verified my changes work

This also added a dependency to Newtonsoft.Json
Also updated .NetFramework to 4.8 since 4.6 is EoL since April 22
@riisikumi
Copy link
Contributor

Doesn't this already have an equivalent in the LocalGhost Patcher? I wonder why it hasn't been added to the Peacock one

@RDIL RDIL changed the title feat add Serverlist editor to the Patcher feat: add Serverlist editor to the Patcher Oct 30, 2024
Copy link
Member

@grappigegovert grappigegovert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted some issues and other points.
Also, it would be preferable if this didn't use Newtonsoft.Json, as it would mean having to include a dll file along with the patcher exe.

patcher/.gitignore Outdated Show resolved Hide resolved
patcher/MainForm.cs Outdated Show resolved Hide resolved
patcher/MainForm.cs Outdated Show resolved Hide resolved
@@ -128,24 +153,41 @@ 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);
Copy link
Member

@grappigegovert grappigegovert Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This result isn't actually used anywhere, and this function will now always return "127.0.0.1" unless you manually type something into the server combobox.

}

return hostname;
}

private void SetSelectedServerHostname(string input)
{
if (!serversReverse.TryGetValue(input, out string result))
GameServer server = null;
if (input == "localhost" || input == "127.0.0.1")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand why this if-statement is here - I think you always want to compare against the ServerAddress, and then return the corresponding ServerName.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I introduced this check for the edge case a user used a custom name for "Peacock Local" at the moment the program starts. At the moment it shows 127.0.0.1 or "Peacock Local"

@LennardF1989
Copy link
Member

LennardF1989 commented Oct 31, 2024

I think we should first move to patcher-core. That is a more modern setup (.NET instead of .NET Framework, UI separated from logic) and has support for DPI and Steam Deck (through CLI). And for size reasons, it can still back-compile to .NET 4.8.

Also, couldn't we just get the actual serverlist editor from @grappigegovert version back in the source?

add the newline back

Co-authored-by: Govert de Gans <grappigegovert@hotmail.com>
@Tondorian
Copy link
Author

I think we should first move to patcher-core. That is a more modern setup (.NET instead of .NET Framework, UI separated from logic) and has support for DPI and Steam Deck (through CLI). And for size reasons, it can still back-compile to .NET 4.8.

Also, couldn't we just get the actual serverlist editor from @grappigegovert version back in the source?

I just checked out the ghostmod patchers menu, in my opinion it does not resolve the issue, because it is hidden in the options menu and not easy to find or understand how it works

Also, it would be preferable if this didn't use Newtonsoft.Json, as it would mean having to include a dll file along with the patcher exe.

I used JSON because it is easy to read and understand and most typescript devs know it. but if an additional dll is not wanted I can use another format to

@LennardF1989
Copy link
Member

I used JSON because it is easy to read and understand and most typescript devs know it. but if an additional dll is not wanted I can use another format to

You mean C# right :P?

As for the replacement: https://www.nuget.org/packages/system.text.json - this is part of .NET (not .NET Framework) by default now. For simple situations, there is no need to use Newtonsoft anymore. Another reason why I feel we should first adopt the core version, then reapply this.

{
gameServers = CreateDefautServerList();
}
configLocation = $@"{appData}\PeacockProject\";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please always use Path.Combine.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had stolen this line from Settings.cs :P

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, there are quite a few weird things in the code that make my hands itch. But if we make sure newly added stuff to be correct, the rest will follow, haha.

@@ -91,6 +80,26 @@ public MainForm()
{
CurrentSettings = new Settings();
}
try
{
var fileContent = File.ReadAllText($@"{configLocation}\Servers.json", Encoding.UTF8);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Member

@LennardF1989 LennardF1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for the editor itself, we can easily port that over to the new version.

.SpecialFolder
.ApplicationData);

var folder = $@"{appData}\PeacockProject\";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also feel there should just be a single static readonly in a file with the path to the configuration and server.json.

{
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

var serverString = JsonConvert.SerializeObject(GameServers);
File.WriteAllText("Servers.json", serverString, Encoding.UTF8);
File.WriteAllText(@$"{folder}Servers.json", serverString, Encoding.UTF8);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@LennardF1989
Copy link
Member

Also, please change the version to 4.6. This is pre-installed on all Windows 10 and up, preventing players from having to install .NET Framework.

@Tondorian
Copy link
Author

You mean C# right :P?
I really mean Typescript because the core project is typescript :)
I was not aware of the patcher-core branch before

Also, please change the version to 4.6. This is pre-installed on all Windows 10 and up, preventing players from having to install .NET Framework.

I updated to 4.8 because Microsoft do not support 4.6 anymore, but will revert this change

Introduce static ConfigLocation string
use Path.Combine instead of string operations
@Tondorian
Copy link
Author

Tondorian commented Oct 31, 2024

Also, please change the version to 4.6. This is pre-installed on all Windows 10 and up, preventing players from having to install .NET Framework.

On my win 11 Pc 4.6 is not available to compile the project is 4.6.2 okay, too?
@LennardF1989

@LennardF1989
Copy link
Member

Also, please change the version to 4.6. This is pre-installed on all Windows 10 and up, preventing players from having to install .NET Framework.

On my win 11 Pc 4.6 is not available to compile the project is 4.6.2 okay, too? @LennardF1989

https://learn.microsoft.com/en-us/dotnet/framework/install/guide-for-developers

I had a reason for targeting 4.6.1 for the patcher-core. Pretty sure it was related to something that was simply unavailable in .NET 4.6 and/or more trouble than it's worth to backport. Can you target that? Get this: https://dotnet.microsoft.com/en-us/download/dotnet-framework/thank-you/net461-developer-pack-offline-installer

@Tondorian
Copy link
Author

I managed to find the target installer for 4.6 was a bit hidden

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Patcher: improve UX for the server picker
4 participants