Skip to content

Commit

Permalink
Allowing multiple profiles (instances) of the game to run at the same…
Browse files Browse the repository at this point in the history
… time
  • Loading branch information
ivanpmartell committed Aug 29, 2024
1 parent 79aafd6 commit 7bfd387
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.TOKEN }}
default_bump: patch
default_bump: minor

- name: Create a GitHub release
uses: actions/create-release@v1
Expand Down
8 changes: 7 additions & 1 deletion LittleWarGameClient/GameForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
}

Expand Down
27 changes: 25 additions & 2 deletions LittleWarGameClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
Expand All @@ -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();
Expand All @@ -67,6 +72,24 @@ static void Main()
}
}

private static Dictionary<string, string> ParseArguments(string[] args)
{
args = Array.ConvertAll(args, d => d.ToLower());
Dictionary<string, string> arguments = new Dictionary<string, string>();

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);
Expand Down
11 changes: 11 additions & 0 deletions LittleWarGameClient/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"profiles": {
"LWGClient": {
"commandName": "Project"
},
"MultiProfile LWGClient": {
"commandName": "Project",
"commandLineArgs": "-profile test"
}
}
}
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 7bfd387

Please sign in to comment.