From 19f700f8f33360823c890a55f43de9c338ef4ea6 Mon Sep 17 00:00:00 2001
From: AL <26797547+Al12rs@users.noreply.github.com>
Date: Thu, 14 Nov 2024 10:46:41 +0100
Subject: [PATCH] Use game exe rather than launcher for getting BG3 version
 info

---
 .../BaldursGate3/BaldursGate3.cs              | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/Games/NexusMods.Games.Larian/BaldursGate3/BaldursGate3.cs b/src/Games/NexusMods.Games.Larian/BaldursGate3/BaldursGate3.cs
index 23f3907e54..b26c249e42 100644
--- a/src/Games/NexusMods.Games.Larian/BaldursGate3/BaldursGate3.cs
+++ b/src/Games/NexusMods.Games.Larian/BaldursGate3/BaldursGate3.cs
@@ -33,6 +33,26 @@ public BaldursGate3(IServiceProvider provider) : base(provider)
         _serviceProvider = provider;
         _osInformation = provider.GetRequiredService<IOSInformation>();
     }
+    
+    protected override Version GetVersion(GameLocatorResult locatorResult)
+    {
+        try
+        {
+            // Use the vulkan executable to get the version, not the primary file (launcher)
+            var executableGamePath = _osInformation.IsOSX 
+                ? new GamePath(LocationId.Game, "Contents/MacOS/Baldur's Gate 3") 
+                : new GamePath(LocationId.Game, "bin/bg3.exe");
+
+            var fvi = executableGamePath
+                .Combine(locatorResult.Path).FileInfo
+                .GetFileVersionInfo();
+            return fvi.ProductVersion;
+        }
+        catch (Exception)
+        {
+            return new Version(0, 0, 0, 0);
+        }
+    }
 
     public override GamePath GetPrimaryFile(GameStore store)
     {