From 64819b60504cbae0ec4d83ae5a0c35061f545ccd Mon Sep 17 00:00:00 2001 From: Paige Seivertson Date: Fri, 18 Nov 2022 10:51:55 -0500 Subject: [PATCH] Implement custom game lists --- src/GAMES.cfg | 11 +++++ src/MainForm.cs | 90 ++++++++++++++++++++++++++++------ src/Properties/AssemblyInfo.cs | 4 +- src/SteamCMD-GUI.csproj | 6 +++ 4 files changed, 94 insertions(+), 17 deletions(-) create mode 100644 src/GAMES.cfg diff --git a/src/GAMES.cfg b/src/GAMES.cfg new file mode 100644 index 0000000..47b9c5f --- /dev/null +++ b/src/GAMES.cfg @@ -0,0 +1,11 @@ +// FORMAT: appid launchid nameInList +// GO TO https://developer.valvesoftware.com/wiki/Dedicated_Server_Name_Enumeration FOR A LIST OF LAUNCH IDs + // YOU WANT THE ONE UNDER "LAUNCH" + // IF THIS LIST DOESN'T HAVE YOUR GAME, FIND A GUIDE FOR SETTING UP YOUR GAME AND USE WHAT THEY TELL YOU TO DO "-game" WITH +// APP IDS CAN BE FOUND FROM https://github.com/dgibbs64/SteamCMD-AppID-List +// KEEP IN MIND DEDICATED SERVER APPIDs ARE SEPARATE FROM GAME APPIDs + +232250 tf Team Fortress 2 +740 csgo Counter-Strike: Global Offensive +232330 cstrike Counter-Strike: Source +222860 left4dead2 Left 4 Dead 2 \ No newline at end of file diff --git a/src/MainForm.cs b/src/MainForm.cs index 8a63512..f8de3dc 100644 --- a/src/MainForm.cs +++ b/src/MainForm.cs @@ -1,6 +1,4 @@ -// TODO: custom games list file - -using System; +using System; using System.Diagnostics; using System.IO; using System.Linq; @@ -15,7 +13,7 @@ namespace SteamCMD_GUI public partial class MainForm : Form { // ReSharper disable once FieldCanBeMadeReadOnly.Local - private string[][] GameInfo = GetDefaultGames(); + private string[][] GameInfo = GetGames(); private const string ReleaseUrl = "https://github.com/ijre/SteamCMD-GUI_Rewrite/releases/latest"; public MainForm() @@ -23,10 +21,26 @@ public MainForm() InitializeComponent(); Icon = Properties.Resources.Icon; + if (GameInfo == null) + { + if (MessageBox.Show("GAMES.cfg missing; download from repository?", "Fatal Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes) + { + Process.Start("https://github.com/ijre/SteamCMD-GUI_Rewrite"); + } + + Close(); + return; + } + for (int i = 0; i < GameInfo.GetLength(0); i++) { - GameListUpdateTab.Items.Add(GameInfo[i][1]); - GameListRunTab.Items.Add(GameInfo[i][1]); + if (GameInfo[i][0] == null) + { + break; + } + + GameListUpdateTab.Items.Add(GameInfo[i][2]); + GameListRunTab.Items.Add(GameInfo[i][2]); } GameListUpdateTab.SelectedIndex = 0; @@ -223,7 +237,7 @@ private void RunServerButton_Click(object sender, EventArgs e) } string arguments = - $"-console -game {GameInfo[GameListRunTab.SelectedIndex][2]} -port {UDPPort.Text} +hostname \"{Hostname.Text}\" " + + $"-console -game {GameInfo[GameListRunTab.SelectedIndex][1]} -port {UDPPort.Text} +hostname \"{Hostname.Text}\" " + $"+map {MapList.SelectedItem} +maxplayers {MaxPlayers.Text} +sv_lan {NetworkType.SelectedIndex} " + $"+rcon_password {Rcon.Text} +sv_password {PasswordServer.Text} " + $"{buttonParams} {AdditionalCommands.Text}"; @@ -235,7 +249,7 @@ private void RunServerButton_Click(object sender, EventArgs e) private int lastCount; private void MapList_EnterOrLeave(object sender, EventArgs e) { - string root = GameInfo[GameListRunTab.SelectedIndex][2]; + string root = GameInfo[GameListRunTab.SelectedIndex][1]; List maps; @@ -325,15 +339,61 @@ private static void StartCLI(string path, string args) process.Start(); } - private static string[][] GetDefaultGames() + private static string[][] GetGames() { - return new[] + if (!File.Exists("GAMES.cfg")) + { + return null; + } + + string[] gamesRaw = File.ReadAllLines("GAMES.cfg"); + int size = gamesRaw.Length; + + string[][] games = new string[size][]; + for (int i = 0; i < size; i++) { - new[] { "232250", "Team Fortress 2", "tf" }, - new[] { "740", "Counter-Strike: Global Offensive", "csgo" }, - new[] { "232330", "Counter-Strike: Source", "cstrike" }, - new[] { "222860", "Left 4 Dead 2", "left4dead2" } - }; + games[i] = new string[3]; + } + + int linesToSkip = 0; + + for (int i = 0; i < size; i++) + { + string line = gamesRaw[i]; + if (line.Trim().Equals("") || line.Trim().StartsWith("//")) + { + linesToSkip++; + continue; + } + + int trueIndex = i - linesToSkip; + + string[] split = line.Split(' '); + int splitSize = split.Length; + + for (int i2 = 0; i2 < splitSize; i2++) + { + if (split[i2].Equals("")) + { + continue; + } + + if (string.IsNullOrEmpty(games[trueIndex][0])) + { + games[trueIndex][0] = split[i2]; + } + else if (string.IsNullOrEmpty(games[trueIndex][1])) + { + games[trueIndex][1] = split[i2]; + } + else + { + games[trueIndex][2] += $"{ split[i2] }{ (i2 != splitSize - 1 ? " " : "") }"; + } + } + } + + return games; } private static string GetFolder(string title) diff --git a/src/Properties/AssemblyInfo.cs b/src/Properties/AssemblyInfo.cs index d1123f5..ddbe7d5 100644 --- a/src/Properties/AssemblyInfo.cs +++ b/src/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("4.0.1.5")] -[assembly: AssemblyFileVersion("4.0.1.5")] +[assembly: AssemblyVersion("4.1.0.0")] +[assembly: AssemblyFileVersion("4.1.0.0")] diff --git a/src/SteamCMD-GUI.csproj b/src/SteamCMD-GUI.csproj index ab769d1..0f1f6c1 100644 --- a/src/SteamCMD-GUI.csproj +++ b/src/SteamCMD-GUI.csproj @@ -36,6 +36,9 @@ Resources\Icon.ico + + Always + packages\WindowsAPICodePack.1.1.1\lib\Microsoft.WindowsAPICodePack.dll @@ -107,4 +110,7 @@ + + copy "$(ProjectDir)\GAMES.cfg" "$(TargetDir)" + \ No newline at end of file