diff --git a/.github/workflows/dotnet-desktop.yml b/.github/workflows/dotnet-desktop.yml index 75eda59..c826127 100644 --- a/.github/workflows/dotnet-desktop.yml +++ b/.github/workflows/dotnet-desktop.yml @@ -56,7 +56,7 @@ jobs: uses: mathieudutour/github-tag-action@v6.0 with: github_token: ${{ secrets.TOKEN }} - default_bump: patch + default_bump: minor - name: Create a GitHub release uses: actions/create-release@v1 diff --git a/LittleWarGameClient/GameForm.cs b/LittleWarGameClient/GameForm.cs index 611a6a5..a6aadb5 100644 --- a/LittleWarGameClient/GameForm.cs +++ b/LittleWarGameClient/GameForm.cs @@ -18,6 +18,9 @@ internal static GameForm Instance return formInstance; } } +#pragma warning disable CS8618 + internal static string InstanceName { get; set; } +#pragma warning restore CS8618 internal const string baseUrl = @"https://littlewargame.com/play"; private readonly SettingsHandler settings; @@ -34,8 +37,11 @@ internal static GameForm Instance internal GameForm() { + if (InstanceName == null) + throw new MissingFieldException(nameof(InstanceName)); PreInitWeb(); InitializeComponent(); + Text = $"Littlewargame({InstanceName})"; loadingText.Font = new Font(FontHandler.lwgFont, 48F, FontStyle.Regular, GraphicsUnit.Point); settings = new SettingsHandler(); audioHandler = new AudioHandler(Text); @@ -52,7 +58,7 @@ private void PreInitWeb() cefSettings.CefCommandLineArgs.Add("no-proxy-server", "1"); cefSettings.CefCommandLineArgs.Add("disable-plugins-discovery", "1"); cefSettings.CefCommandLineArgs.Add("disable-extensions", "1"); - cefSettings.RootCachePath = Path.Join(path, "data"); + cefSettings.RootCachePath = Path.Join(path, "data", InstanceName); Cef.Initialize(cefSettings); } diff --git a/LittleWarGameClient/Program.cs b/LittleWarGameClient/Program.cs index 616929e..b21656f 100644 --- a/LittleWarGameClient/Program.cs +++ b/LittleWarGameClient/Program.cs @@ -29,6 +29,7 @@ internal static class Program [STAThread] static void Main() { + var args = ParseArguments(Environment.GetCommandLineArgs()[1..]); Thread splashthread = new Thread(() => { SplashScreen.Instance.ShowDialog(); @@ -37,12 +38,16 @@ static void Main() splashthread.SetApartmentState(ApartmentState.STA); splashthread.Start(); bool createdNew = true; - using (Mutex mutex = new Mutex(true, "Global\\LittleWarGameClient", out createdNew)) + string? profileName; + if (!args.TryGetValue("profile", out profileName)) + profileName = "main"; + using (Mutex mutex = new Mutex(true, $"Global\\LittleWarGameClient_{profileName}", out createdNew)) { if (createdNew) { // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. + GameForm.InstanceName = profileName; ApplicationConfiguration.Initialize(); Application.Run(OverlayForm.Instance); } @@ -54,7 +59,7 @@ static void Main() { if (process.Id != current.Id) { - var clientWindows = GetWindows(process.Handle).Where(window => window.WinTitle == "Littlewargame"); + var clientWindows = GetWindows(process.Handle).Where(window => window.WinTitle == $"Littlewargame({profileName})"); if (clientWindows.Count() > 0) { var clientMainWindow = clientWindows.First(); @@ -67,6 +72,24 @@ static void Main() } } + private static Dictionary ParseArguments(string[] args) + { + args = Array.ConvertAll(args, d => d.ToLower()); + Dictionary arguments = new Dictionary(); + + for (int i = 0; i < args.Length; i += 2) + { + if (args.Length == i + 1 || args[i + 1].StartsWith("-")) + { + arguments.Add(args[i][1..], string.Empty); + i--; + } + if (args.Length >= i + 1 && !args[i + 1].StartsWith("-")) + arguments.Add(args[i][1..], args[i + 1]); + } + return arguments; + } + private static bool Callback(IntPtr hWnd, int lparam) { StringBuilder sb = new StringBuilder(256); diff --git a/LittleWarGameClient/Properties/launchSettings.json b/LittleWarGameClient/Properties/launchSettings.json new file mode 100644 index 0000000..f1c3d7b --- /dev/null +++ b/LittleWarGameClient/Properties/launchSettings.json @@ -0,0 +1,11 @@ +{ + "profiles": { + "LWGClient": { + "commandName": "Project" + }, + "MultiProfile LWGClient": { + "commandName": "Project", + "commandLineArgs": "-profile test" + } + } +} \ No newline at end of file diff --git a/README.md b/README.md index cb5bcc6..1d58c1a 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,25 @@ It contains additional improvements to the web-based client such as borderless windowed mode, additional hotkeys, not being tied to your web browser to play and cursor lock to window not lagging. +The client also supports the Steam overlay, as well as multiple profiles. + This project is completely open source. Feel free to fork and make pull requests, additionally please report any issues [here](https://github.com/ivanpmartell/LittleWarGameClient/issues). # Important -If updating from versions below 0.3.0: +If updating from versions below 0.4.0: -Versions 0.3.0+ are not compatible with previous versions. Extract to an empty folder. Do not simply replace files with updated files. +Versions 0.4.0+ are not compatible with previous versions. Extract to an empty folder. Do not simply replace files with updated files. Unfortunately this means that saved data from previous version cannot be carried over. Make sure to backup your data, e.g. downloaded replays # Download Grab the `lwg_clientx64.zip` file from the latest release. Click [here](https://github.com/ivanpmartell/LittleWarGameClient/releases/latest) for easier access to the download. + +# Profiles + +To run with a certain profile add the command line argument `-profile` and the name you want the profile to have: + +`LittleWarGameClient.exe -profile name` + +This will let you run multiple instance of the game at the same time. \ No newline at end of file