Skip to content

Commit

Permalink
Implement custom game lists
Browse files Browse the repository at this point in the history
  • Loading branch information
ijre committed Nov 18, 2022
1 parent 44d299a commit 64819b6
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 17 deletions.
11 changes: 11 additions & 0 deletions src/GAMES.cfg
Original file line number Diff line number Diff line change
@@ -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
90 changes: 75 additions & 15 deletions src/MainForm.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// TODO: custom games list file

using System;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
Expand All @@ -15,18 +13,34 @@ 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()
{
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;
Expand Down Expand Up @@ -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}";
Expand All @@ -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<string> maps;

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
6 changes: 6 additions & 0 deletions src/SteamCMD-GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<PropertyGroup>
<ApplicationIcon>Resources\Icon.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<RunPostBuildEvent>Always</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.WindowsAPICodePack, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\WindowsAPICodePack.1.1.1\lib\Microsoft.WindowsAPICodePack.dll</HintPath>
Expand Down Expand Up @@ -107,4 +110,7 @@
<None Include="Resources\Icon.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy "$(ProjectDir)\GAMES.cfg" "$(TargetDir)"</PostBuildEvent>
</PropertyGroup>
</Project>

0 comments on commit 64819b6

Please sign in to comment.