Skip to content

Commit ef3b431

Browse files
authored
Merge pull request #158 from SubnauticaModding/checkMinimumBuildVersion
GameDetector now supports hard-coding required build versions per game.
2 parents 7c7c958 + 1a577eb commit ef3b431

File tree

7 files changed

+39
-11
lines changed

7 files changed

+39
-11
lines changed

Build/InstallerExtensions.dll

0 Bytes
Binary file not shown.

Build/QModInstaller.dll

512 Bytes
Binary file not shown.

Build/QModInstaller.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Build/QModManager.exe

0 Bytes
Binary file not shown.

Build/QModManager_Setup.exe

362 Bytes
Binary file not shown.

QModManager/Patching/GameDetector.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
namespace QModManager.Patching
22
{
33
using System;
4+
using System.Collections.Generic;
45
using System.IO;
6+
using System.Reflection;
57
using QModManager.API;
68
using QModManager.Utility;
79

810
internal class GameDetector
911
{
1012
internal readonly QModGame CurrentlyRunningGame;
13+
internal readonly int CurrentGameVersion = -1;
1114

12-
internal bool IsValidGameRunning => CurrentlyRunningGame == QModGame.Subnautica || CurrentlyRunningGame == QModGame.BelowZero;
15+
/// <summary>
16+
/// Game -> game version.
17+
/// 0 = no minimum version required.
18+
/// </summary>
19+
private static readonly Dictionary<QModGame, int> SupportedGameVersions = new Dictionary<QModGame, int>
20+
{
21+
{ QModGame.Subnautica, 0 },
22+
{ QModGame.BelowZero, 0 }
23+
};
24+
25+
internal bool IsValidGameRunning => SupportedGameVersions.ContainsKey(CurrentlyRunningGame);
26+
internal int MinimumBuildVersion => IsValidGameVersion ? SupportedGameVersions[CurrentlyRunningGame] : -1;
27+
internal bool IsValidGameVersion => IsValidGameRunning && MinimumBuildVersion == 0 || (CurrentGameVersion > -1 && CurrentGameVersion >= MinimumBuildVersion);
1328

1429
internal GameDetector()
1530
{
@@ -38,6 +53,17 @@ internal GameDetector()
3853
Logger.Fatal("A fatal error has occurred. No game executable was found!");
3954
throw new FatalPatchingException("No game executable was found!");
4055
}
56+
57+
Logger.Info($"Game Version: {SNUtils.GetPlasticChangeSetOfBuild()} Build Date: {SNUtils.GetDateTimeOfBuild():dd-MMMM-yyyy}");
58+
Logger.Info($"Loading QModManager v{Assembly.GetExecutingAssembly().GetName().Version.ToStringParsed()}{(IsValidGameRunning && MinimumBuildVersion != 0 ? $" built for {CurrentlyRunningGame} v{MinimumBuildVersion}" : string.Empty)}...");
59+
Logger.Info($"Today is {DateTime.Today:dd-MMMM-yyyy}");
60+
61+
CurrentGameVersion = SNUtils.GetPlasticChangeSetOfBuild(-1);
62+
if (!IsValidGameVersion)
63+
{
64+
Logger.Fatal("A fatal error has occurred. An invalid game version was detected!");
65+
throw new FatalPatchingException("An invalid game version was detected!");
66+
}
4167
}
4268
}
4369
}

QModManager/Patching/Patcher.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ internal static void Patch()
4141

4242
Patched = true;
4343

44-
Logger.Info($"Game Version: {SNUtils.GetPlasticChangeSetOfBuild()} Build Date: {SNUtils.GetDateTimeOfBuild():dd-MMMM-yyyy}");
45-
Logger.Info($"Loading QModManager v{Assembly.GetExecutingAssembly().GetName().Version.ToStringParsed()}...");
46-
Logger.Info($"Today is {DateTime.Today:dd-MMMM-yyyy}");
44+
var gameDetector = new GameDetector();
45+
46+
if (!gameDetector.IsValidGameRunning || !gameDetector.IsValidGameVersion)
47+
return;
48+
49+
CurrentlyRunningGame = gameDetector.CurrentlyRunningGame;
4750

4851
if (QModBaseDir == null)
4952
{
@@ -74,13 +77,6 @@ internal static void Patch()
7477

7578
PirateCheck.IsPirate(Environment.CurrentDirectory);
7679

77-
var gameDetector = new GameDetector();
78-
79-
if (!gameDetector.IsValidGameRunning)
80-
return;
81-
82-
CurrentlyRunningGame = gameDetector.CurrentlyRunningGame;
83-
8480
PatchHarmony();
8581

8682
if (NitroxCheck.IsInstalled)

0 commit comments

Comments
 (0)