From 021cb61563e7b3df591aace188a4a9a53b68f21e Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Tue, 1 Dec 2020 15:58:07 -0700 Subject: [PATCH] MW5 Support --- Compression.BSA/Compression.BSA.csproj | 2 +- Wabbajack.Common/GameMetaData.cs | 34 +++++++- .../StoreHandlers/EpicGameStoreHandler.cs | 80 +++++++++++++++++++ .../StoreHandlers/StoreHandler.cs | 18 ++++- Wabbajack.Common/Wabbajack.Common.csproj | 4 +- Wabbajack.Lib/Wabbajack.Lib.csproj | 4 +- Wabbajack.Test/Wabbajack.Test.csproj | 4 +- .../Wabbajack.VirtualFileSystem.csproj | 2 +- Wabbajack/Wabbajack.csproj | 6 +- 9 files changed, 140 insertions(+), 14 deletions(-) create mode 100644 Wabbajack.Common/StoreHandlers/EpicGameStoreHandler.cs diff --git a/Compression.BSA/Compression.BSA.csproj b/Compression.BSA/Compression.BSA.csproj index 7b51c3b9..25f52db0 100644 --- a/Compression.BSA/Compression.BSA.csproj +++ b/Compression.BSA/Compression.BSA.csproj @@ -21,7 +21,7 @@ - + diff --git a/Wabbajack.Common/GameMetaData.cs b/Wabbajack.Common/GameMetaData.cs index fc4bcded..d4d0e397 100644 --- a/Wabbajack.Common/GameMetaData.cs +++ b/Wabbajack.Common/GameMetaData.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Linq; +using System.Net.Http.Headers; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Wabbajack.Common.StoreHandlers; @@ -38,7 +39,8 @@ namespace Wabbajack.Common Witcher3, [Description("Stardew Valley")] StardewValley, - KingdomComeDeliverance + KingdomComeDeliverance, + MechWarrior5Mercenaries } public static class GameExtensions @@ -67,6 +69,8 @@ namespace Wabbajack.Common // to get gog ids: https://www.gogdb.org public List? GOGIDs { get; internal set; } + + public List EpicGameStoreIDs { get; internal set; } = new List(); // to get BethNet IDs: check the registry public int BethNetID { get; internal set; } @@ -99,7 +103,16 @@ namespace Wabbajack.Common if (MainExecutable == null) throw new NotImplementedException(); - return FileVersionInfo.GetVersionInfo((string)gameLoc.Combine(MainExecutable)).ProductVersion; + var info = FileVersionInfo.GetVersionInfo((string)gameLoc.Combine(MainExecutable)); + var version = info.ProductVersion; + if (string.IsNullOrWhiteSpace(version)) + { + version = + $"{info.ProductMajorPart}.{info.ProductMinorPart}.{info.ProductBuildPart}.{info.ProductPrivatePart}"; + return version; + } + + return version; } } @@ -508,6 +521,23 @@ namespace Wabbajack.Common }, MainExecutable = @"bin\Win64\KingdomCome.exe" } + }, + { + Game.MechWarrior5Mercenaries, new GameMetaData + { + Game = Game.MechWarrior5Mercenaries, + NexusName = "mechwarrior5mercenaries", + MO2Name = "Mechwarrior 5: Mercenaries", + MO2ArchiveName = "mechwarrior5mercenaries", + NexusGameId = 3099, + EpicGameStoreIDs = new List {"9fd39d8ac72946a2a10a887ce86e6c35"}, + IsGenericMO2Plugin = true, + RequiredFiles = new List + { + @"MW5Mercs\Binaries\Win64\MechWarrior-Win64-Shipping.exe" + }, + MainExecutable = @"MW5Mercs\Binaries\Win64\MechWarrior-Win64-Shipping.exe" + } } }; diff --git a/Wabbajack.Common/StoreHandlers/EpicGameStoreHandler.cs b/Wabbajack.Common/StoreHandlers/EpicGameStoreHandler.cs new file mode 100644 index 00000000..67cf1852 --- /dev/null +++ b/Wabbajack.Common/StoreHandlers/EpicGameStoreHandler.cs @@ -0,0 +1,80 @@ +using System; +using System.Linq; +using Microsoft.Win32; + +namespace Wabbajack.Common.StoreHandlers +{ + public class EpicGameStoreHandler : AStoreHandler + { + public override StoreType Type { get; internal set; } + + public string BaseRegKey = @"SOFTWARE\Epic Games\EOS"; + public override bool Init() + { + return true; + } + + public override bool LoadAllGames() + { + using var eosKey = Registry.CurrentUser.OpenSubKey(BaseRegKey); + if (eosKey == null) + { + Utils.Log("Epic Game Store is not installed"); + return false; + } + + var name = eosKey.GetValue("ModSdkMetadataDir"); + if (name == null) + { + Utils.Log("Registry key entry does not exist for Epic Game store"); + return false; + } + + var byID = GameRegistry.Games.SelectMany(g => g.Value.EpicGameStoreIDs + .Select(id => (id, g.Value.Game))) + .GroupBy(t => t.id) + .ToDictionary(t => t.Key, t => t.First().Game); + + foreach (var itm in ((AbsolutePath)(string)(name!)).EnumerateFiles(false, "*.item")) + { + var item = itm.FromJson(); + Console.WriteLine($"Found Epic Game Store Game: {item.DisplayName} at {item.InstallLocation}"); + + if (byID.TryGetValue(item.CatalogItemId, out var game)) + { + Games.Add(new EpicStoreGame(game, item)); + } + + } + + + + return true; + } + + public class EpicStoreGame : AStoreGame + { + public EpicStoreGame(Game game, EpicGameItem item) + { + Type = StoreType.EpicGameStore; + Game = game; + Path = (AbsolutePath)item.InstallLocation; + Name = game.MetaData().HumanFriendlyGameName; + + } + + public override Game Game { get; internal set; } + public override StoreType Type { get; internal set; } + } + + public class EpicGameItem + { + public string DisplayName { get; set; } = ""; + public string InstallationGuid { get; set; } = ""; + public string CatalogItemId { get; set; } = ""; + public string CatalogNamespace { get; set; } = ""; + public string InstallSessionId { get; set; } = ""; + public string InstallLocation { get; set; } = ""; + } + } +} diff --git a/Wabbajack.Common/StoreHandlers/StoreHandler.cs b/Wabbajack.Common/StoreHandlers/StoreHandler.cs index 295c2225..68d3653c 100644 --- a/Wabbajack.Common/StoreHandlers/StoreHandler.cs +++ b/Wabbajack.Common/StoreHandlers/StoreHandler.cs @@ -9,7 +9,8 @@ namespace Wabbajack.Common.StoreHandlers { STEAM, GOG, - BethNet + BethNet, + EpicGameStore } public class StoreHandler @@ -25,6 +26,9 @@ namespace Wabbajack.Common.StoreHandlers private static readonly Lazy _bethNetHandler = new Lazy(() => new BethNetHandler()); public BethNetHandler BethNetHandler = _bethNetHandler.Value; + + private static readonly Lazy _epicGameStoreHandler = new Lazy(() => new EpicGameStoreHandler()); + public EpicGameStoreHandler EpicGameStoreHandler = _epicGameStoreHandler.Value; public List StoreGames; @@ -67,6 +71,18 @@ namespace Wabbajack.Common.StoreHandlers { Utils.Error(new StoreException("Could not Init the BethNetHandler, check previous error messages!")); } + + if (EpicGameStoreHandler.Init()) + { + if (EpicGameStoreHandler.LoadAllGames()) + StoreGames.AddRange(EpicGameStoreHandler.Games); + else + Utils.Error(new StoreException("Could not load all Games from the EpicGameStoreHandler, check previous error messages!")); + } + else + { + Utils.Error(new StoreException("Could not Init the EpicGameStoreHandler, check previous error messages!")); + } } public AbsolutePath? TryGetGamePath(Game game) diff --git a/Wabbajack.Common/Wabbajack.Common.csproj b/Wabbajack.Common/Wabbajack.Common.csproj index 3bebdf1c..7a349848 100644 --- a/Wabbajack.Common/Wabbajack.Common.csproj +++ b/Wabbajack.Common/Wabbajack.Common.csproj @@ -56,13 +56,13 @@ - + - + diff --git a/Wabbajack.Lib/Wabbajack.Lib.csproj b/Wabbajack.Lib/Wabbajack.Lib.csproj index 5f42ead1..a00d3242 100644 --- a/Wabbajack.Lib/Wabbajack.Lib.csproj +++ b/Wabbajack.Lib/Wabbajack.Lib.csproj @@ -8,10 +8,10 @@ - 85.3.130 + 86.0.241 - 85.3.130 + 86.0.241 3.1.0 diff --git a/Wabbajack.Test/Wabbajack.Test.csproj b/Wabbajack.Test/Wabbajack.Test.csproj index 4ef2cd16..bc2acc5a 100644 --- a/Wabbajack.Test/Wabbajack.Test.csproj +++ b/Wabbajack.Test/Wabbajack.Test.csproj @@ -28,8 +28,8 @@ - - + + diff --git a/Wabbajack.VirtualFileSystem/Wabbajack.VirtualFileSystem.csproj b/Wabbajack.VirtualFileSystem/Wabbajack.VirtualFileSystem.csproj index 505d0256..bc1043c9 100644 --- a/Wabbajack.VirtualFileSystem/Wabbajack.VirtualFileSystem.csproj +++ b/Wabbajack.VirtualFileSystem/Wabbajack.VirtualFileSystem.csproj @@ -16,7 +16,7 @@ - + diff --git a/Wabbajack/Wabbajack.csproj b/Wabbajack/Wabbajack.csproj index 58ff96eb..c1035ef7 100644 --- a/Wabbajack/Wabbajack.csproj +++ b/Wabbajack/Wabbajack.csproj @@ -55,8 +55,8 @@ - - + + all @@ -67,7 +67,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - +