Skip to content

Commit 49a1edd

Browse files
committed
Adjust Game Launch API extension
1 parent 5382e4d commit 49a1edd

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

Utility/GameManagerExtension.cs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,35 @@ public class RunGameFromGameManagerContext
5656
/// <summary>
5757
/// Indicates whether the Game Launch API is supported on the plugin.
5858
/// </summary>
59-
public bool CanUseGameLaunchApi => _canUseGameLaunchApi ??= this.IsGameRunning(out _, out _);
59+
public bool CanUseGameLaunchApi => _canUseGameLaunchApi ??= this.IsGameRunning(out _, out _, out _);
6060

6161
/// <summary>
6262
/// Indicates whether the game is currently running.
6363
/// </summary>
6464
// ReSharper disable once MemberHidesStaticFromOuterClass
65-
public bool IsGameRunning => CanUseGameLaunchApi && this.IsGameRunning(out bool running, out _) && running;
65+
public bool IsGameRunning => CanUseGameLaunchApi && this.IsGameRunning(out bool running, out _, out _) && running;
66+
67+
/// <summary>
68+
/// Indicates when the game launched. If the game isn't running, it will return a default value.
69+
/// </summary>
70+
public DateTime GameLaunchStartTime
71+
{
72+
get
73+
{
74+
if (!CanUseGameLaunchApi)
75+
{
76+
return default;
77+
}
78+
79+
if (!this.IsGameRunning(out bool running, out DateTime dateTime, out _) ||
80+
!running)
81+
{
82+
return default;
83+
}
84+
85+
return dateTime;
86+
}
87+
}
6688
}
6789

6890
/// <summary>
@@ -147,6 +169,7 @@ public class RunGameFromGameManagerContext
147169
/// <param name="context">The context to launch the game from <see cref="IGameManager"/>.</param>
148170
/// <param name="isGameRunning">Whether the game is currently running or not.</param>
149171
/// <param name="errorException">Represents an exception from HRESULT of the plugin's function.</param>
172+
/// <param name="gameStartTime">The date time stamp of when the process was started.</param>
150173
/// <returns>
151174
/// To find the actual return value, please use <paramref name="isGameRunning"/> out-argument.<br/><br/>
152175
///
@@ -155,11 +178,13 @@ public class RunGameFromGameManagerContext
155178
/// </returns>
156179
public static bool IsGameRunning(this RunGameFromGameManagerContext context,
157180
out bool isGameRunning,
181+
out DateTime gameStartTime,
158182
[NotNullWhen(false)] out Exception? errorException)
159183
{
160184
ArgumentNullException.ThrowIfNull(context, nameof(context));
161185
isGameRunning = false;
162186
errorException = null;
187+
gameStartTime = default;
163188

164189
if (!context.PluginHandle.TryGetExport("IsGameRunning", out SharedStatic.IsGameRunningDelegate isGameRunningCallback))
165190
{
@@ -182,7 +207,7 @@ public static bool IsGameRunning(this RunGameFromGameManager
182207
return false;
183208
}
184209

185-
int hResult = isGameRunningCallback(gameManagerP, presetConfigP, out int isGameRunningInt);
210+
int hResult = isGameRunningCallback(gameManagerP, presetConfigP, out int isGameRunningInt, out gameStartTime);
186211

187212
errorException = Marshal.GetExceptionForHR(hResult);
188213
if (errorException != null)
@@ -256,6 +281,7 @@ public static bool IsGameRunning(this RunGameFromGameManager
256281
/// </summary>
257282
/// <param name="context">The context to launch the game from <see cref="IGameManager"/>.</param>
258283
/// <param name="wasGameRunning">Whether to indicate that the game was running or not.</param>
284+
/// <param name="gameStartTime">The date time stamp of when the process was started.</param>
259285
/// <param name="errorException">Represents an exception from HRESULT of the plugin's function.</param>
260286
/// <returns>
261287
/// To find the actual return value, please use <paramref name="wasGameRunning"/> out-argument.<br/><br/>
@@ -265,11 +291,13 @@ public static bool IsGameRunning(this RunGameFromGameManager
265291
/// </returns>
266292
public static bool KillRunningGame(this RunGameFromGameManagerContext context,
267293
out bool wasGameRunning,
294+
out DateTime gameStartTime,
268295
[NotNullWhen(false)] out Exception? errorException)
269296
{
270297
ArgumentNullException.ThrowIfNull(context, nameof(context));
271298
errorException = null;
272299
wasGameRunning = false;
300+
gameStartTime = default;
273301

274302
if (!context.PluginHandle.TryGetExport("KillRunningGame", out SharedStatic.IsGameRunningDelegate killRunningGameCallback))
275303
{
@@ -292,7 +320,7 @@ public static bool KillRunningGame(this RunGameFromGameManag
292320
return false;
293321
}
294322

295-
int hResult = killRunningGameCallback(gameManagerP, presetConfigP, out int wasGameRunningInt);
323+
int hResult = killRunningGameCallback(gameManagerP, presetConfigP, out int wasGameRunningInt, out gameStartTime);
296324

297325
errorException = Marshal.GetExceptionForHR(hResult);
298326
if (errorException != null)

0 commit comments

Comments
 (0)