Skip to content

Commit fd86c53

Browse files
authored
Merge pull request #707 from CnCNet/develop
Release 2.12.0
2 parents d1ddf93 + 988f27f commit fd86c53

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1568
-2193
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ on:
99
jobs:
1010
build-clients:
1111
runs-on: windows-2022
12-
strategy:
13-
matrix:
14-
Game:
15-
- Ares
16-
- TS
17-
- YR
18-
1912
steps:
2013
- uses: actions/checkout@v4
2114
with:
@@ -26,13 +19,12 @@ jobs:
2619
with:
2720
global-json-file: ./global.json
2821

29-
- name: Build ${{matrix.Game}}
30-
run: ./Scripts/build.ps1 ${{matrix.Game}}
22+
- name: Build
23+
run: ./Scripts/build.ps1
3124
shell: pwsh
3225

3326
- uses: actions/upload-artifact@v4
3427
name: Upload Artifacts
3528
with:
36-
name: artifacts-${{matrix.Game}}
37-
path: ./Compiled/${{matrix.Game}}
38-
29+
name: artifacts
30+
path: ./Compiled

.github/workflows/release-build.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: release build
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build:
9+
runs-on: windows-2022
10+
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Setup .NET SDK
18+
uses: actions/setup-dotnet@v4
19+
with:
20+
global-json-file: ./global.json
21+
22+
- name: Build
23+
run: ./Scripts/build.ps1
24+
shell: pwsh
25+
26+
- name: Development Build Check
27+
shell: pwsh
28+
run: |
29+
if ($env:GitVersion_CommitsSinceVersionSource -ne "0") {
30+
Write-Output "::error:: This is a development build and should not be released. Did you forget to create a new tag for the release?"
31+
exit 1
32+
}
33+
34+
- name: Zip Artifact
35+
run: 7z a -t7z -mx=9 -m0=lzma2 -ms=on -r -- ${{ format('xna-cncnet-client-{0}.7z', env.GitVersion_SemVer) }} ./Compiled/*
36+
shell: pwsh
37+
38+
- name: Upload Final Artifact to the Release
39+
uses: softprops/action-gh-release@v2
40+
with:
41+
append_body: true
42+
files: ${{ format('xna-cncnet-client-{0}.7z', env.GitVersion_SemVer) }}

ClientCore/ClientConfiguration.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Runtime.InteropServices;
77
using ClientCore.I18N;
88
using ClientCore.Extensions;
9+
using ClientCore.Enums;
910

1011
namespace ClientCore
1112
{
@@ -187,6 +188,10 @@ public void RefreshSettings()
187188

188189
#region Client definitions
189190

191+
private string _ClientGameTypeString => clientDefinitionsIni.GetStringValue(SETTINGS, "ClientGameType", string.Empty);
192+
private ClientType? _ClientGameType = null;
193+
public ClientType ClientGameType => _ClientGameType ??= ClientTypeHelper.FromString(_ClientGameTypeString);
194+
190195
public string DiscordAppId => clientDefinitionsIni.GetStringValue(SETTINGS, "DiscordAppId", string.Empty);
191196

192197
public int SendSleep => clientDefinitionsIni.GetIntValue(SETTINGS, "SendSleep", 2500);
@@ -397,6 +402,11 @@ public string GetGameExecutableName()
397402
/// </summary>
398403
public string[] ForbiddenFiles => clientDefinitionsIni.GetStringValue(SETTINGS, "ForbiddenFiles", String.Empty).Split(',');
399404

405+
/// <summary>
406+
/// The main map file extension that is read by the client.
407+
/// </summary>
408+
public string MapFileExtension => clientDefinitionsIni.GetStringValue(SETTINGS, "MapFileExtension", "map");
409+
400410
/// <summary>
401411
/// This tells the client which supplemental map files are ok to copy over during "spawnmap.ini" file creation.
402412
/// IE, if "BIN" is listed, then the client will look for and copy the file "map_a.bin"

ClientCore/ClientCore.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
<PackageReference Include="Rampastring.XNAUI.$(Engine)" Condition="'!$(Configuration.Contains(Debug))'" />
1212
<PackageReference Include="Rampastring.XNAUI.$(Engine).Debug" Condition="'$(Configuration.Contains(Debug))'" />
1313
<PackageReference Include="System.Text.Encoding.CodePages" />
14+
<PackageReference Include="Ude.NetStandard" />
1415
</ItemGroup>
1516
</Project>

ClientCore/Enums/ClientType.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace ClientCore.Enums
2+
{
3+
public enum ClientType
4+
{
5+
TS,
6+
YR,
7+
Ares,
8+
}
9+
}

ClientCore/Enums/ClientTypeHelper.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace ClientCore.Enums
4+
{
5+
public static class ClientTypeHelper
6+
{
7+
public static ClientType FromString(string value) => value switch
8+
{
9+
"TS" => ClientType.TS,
10+
"YR" => ClientType.YR,
11+
"Ares" => ClientType.Ares,
12+
_ => throw new Exception("It seems the client configuration was not migrated to accommodate for the v2.12 changes. Please specify 'ClientGameType' in `[Settings]` section of the 'ClientDefinitions.ini' file, e.g., 'ClientGameType=Ares'."),
13+
};
14+
}
15+
}

ClientCore/Extensions/StringExtensions.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Collections.Generic;
3+
24
using ClientCore.I18N;
35

46
namespace ClientCore.Extensions;
@@ -77,4 +79,38 @@ public static string L10N(this string defaultValue, string key, bool notify = tr
7779
=> string.IsNullOrEmpty(defaultValue)
7880
? defaultValue
7981
: Translation.Instance.LookUp(key, defaultValue, notify);
82+
83+
/// <summary>
84+
/// Replace special characters with spaces in the filename to avoid conflicts with WIN32API.
85+
/// </summary>
86+
/// <param name="defaultValue">The default string value.</param>
87+
/// <returns>File name without special characters or reserved combinations.</returns>
88+
/// <remarks>
89+
/// Reference: <a href="https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file">Naming Files, Paths, and Namespaces</a>.
90+
/// </remarks>
91+
public static string ToWin32FileName(this string filename)
92+
{
93+
foreach (char ch in "/\\:*?<>|")
94+
filename = filename.Replace(ch, '_');
95+
96+
// If the user is somehow using "con" or any other filename that is
97+
// reserved by WIN32API, it would be better to rename it.
98+
99+
HashSet<string> reservedFileNames = new HashSet<string>(new List<string>(){
100+
"CON",
101+
"PRN",
102+
"AUX",
103+
"NUL",
104+
"COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "COM¹", "COM²", "COM³",
105+
"LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9", "LPT¹", "LPT²", "LPT³"
106+
}, StringComparer.InvariantCultureIgnoreCase);
107+
108+
if (reservedFileNames.Contains(filename))
109+
filename += "_";
110+
111+
return filename;
112+
}
113+
114+
public static T ToEnum<T>(this string value) where T : Enum
115+
=> (T)Enum.Parse(typeof(T), value, true);
80116
}

ClientCore/FileHelper.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,21 @@ public static void CreateHardLinkFromSource(string source, string destination, b
9090
throw new PlatformNotSupportedException();
9191
}
9292
}
93+
94+
public static Encoding GetEncoding(string filename)
95+
{
96+
Encoding encoding = new UTF8Encoding(false);
97+
98+
using (FileStream fs = File.OpenRead(filename))
99+
{
100+
Ude.CharsetDetector cdet = new Ude.CharsetDetector();
101+
cdet.Feed(fs);
102+
cdet.DataEnd();
103+
if (cdet.Charset != null)
104+
encoding = Encoding.GetEncoding(cdet.Charset);
105+
}
106+
107+
return encoding;
108+
}
93109
}
94110
}

ClientCore/Settings/UserINISettings.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ protected UserINISettings(IniFile iniFile)
4949
SettingsIni = iniFile;
5050

5151
const string WINDOWED_MODE_KEY = "Video.Windowed";
52-
#if TS
53-
BackBufferInVRAM = new BoolSetting(iniFile, VIDEO, "UseGraphicsPatch", true);
54-
#else
55-
BackBufferInVRAM = new BoolSetting(iniFile, VIDEO, "VideoBackBuffer", false);
56-
#endif
52+
53+
if (ClientConfiguration.Instance.ClientGameType == ClientType.TS)
54+
BackBufferInVRAM = new BoolSetting(iniFile, VIDEO, "UseGraphicsPatch", true);
55+
else
56+
BackBufferInVRAM = new BoolSetting(iniFile, VIDEO, "VideoBackBuffer", false);
5757

5858
IngameScreenWidth = new IntSetting(iniFile, VIDEO, "ScreenWidth", 1024);
5959
IngameScreenHeight = new IntSetting(iniFile, VIDEO, "ScreenHeight", 768);
@@ -75,6 +75,7 @@ protected UserINISettings(IniFile iniFile)
7575
ClientVolume = new DoubleSetting(iniFile, AUDIO, "ClientVolume", 1.0);
7676
PlayMainMenuMusic = new BoolSetting(iniFile, AUDIO, "PlayMainMenuMusic", true);
7777
StopMusicOnMenu = new BoolSetting(iniFile, AUDIO, "StopMusicOnMenu", true);
78+
StopGameLobbyMessageAudio = new BoolSetting(iniFile, AUDIO, "StopGameLobbyMessageAudio", true);
7879
MessageSound = new BoolSetting(iniFile, AUDIO, "ChatMessageSound", true);
7980

8081
ScrollRate = new IntSetting(iniFile, OPTIONS, "ScrollRate", 3);
@@ -93,6 +94,7 @@ protected UserINISettings(IniFile iniFile)
9394
PersistentMode = new BoolSetting(iniFile, MULTIPLAYER, "PersistentMode", false);
9495
AutomaticCnCNetLogin = new BoolSetting(iniFile, MULTIPLAYER, "AutomaticCnCNetLogin", false);
9596
DiscordIntegration = new BoolSetting(iniFile, MULTIPLAYER, "DiscordIntegration", true);
97+
SteamIntegration = new BoolSetting(iniFile, MULTIPLAYER, "SteamIntegration", true);
9698
AllowGameInvitesFromFriendsOnly = new BoolSetting(iniFile, MULTIPLAYER, "AllowGameInvitesFromFriendsOnly", false);
9799
NotifyOnUserListChange = new BoolSetting(iniFile, MULTIPLAYER, "NotifyOnUserListChange", true);
98100
DisablePrivateMessagePopups = new BoolSetting(iniFile, MULTIPLAYER, "DisablePrivateMessagePopups", false);
@@ -167,6 +169,7 @@ protected UserINISettings(IniFile iniFile)
167169
public DoubleSetting ClientVolume { get; private set; }
168170
public BoolSetting PlayMainMenuMusic { get; private set; }
169171
public BoolSetting StopMusicOnMenu { get; private set; }
172+
public BoolSetting StopGameLobbyMessageAudio { get; private set; }
170173
public BoolSetting MessageSound { get; private set; }
171174

172175
/********/
@@ -194,6 +197,7 @@ protected UserINISettings(IniFile iniFile)
194197
public BoolSetting PersistentMode { get; private set; }
195198
public BoolSetting AutomaticCnCNetLogin { get; private set; }
196199
public BoolSetting DiscordIntegration { get; private set; }
200+
public BoolSetting SteamIntegration { get; private set; }
197201
public BoolSetting AllowGameInvitesFromFriendsOnly { get; private set; }
198202

199203
public BoolSetting NotifyOnUserListChange { get; private set; }

ClientCore/Statistics/StatisticsManager.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,12 @@ public void ClearDatabase()
290290

291291
public void AddMatchAndSaveDatabase(bool addMatch, MatchStatistics ms)
292292
{
293+
if (ms == null)
294+
{
295+
Logger.Log("Skipping adding match to statistics because match statistics is null.");
296+
return;
297+
}
298+
293299
// Skip adding stats if the game only had one player, make exception for co-op since it doesn't recognize pre-placed houses as players.
294300
if (ms.GetPlayerCount() <= 1 && !ms.MapIsCoop)
295301
{

0 commit comments

Comments
 (0)