Skip to content

Commit 60c885b

Browse files
committed
Adjust Core changes
1 parent 0f1c429 commit 60c885b

File tree

3 files changed

+49
-37
lines changed

3 files changed

+49
-37
lines changed

Hi3Helper.Plugin.HBR/Exports.GameLaunch.cs

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,48 @@ namespace Hi3Helper.Plugin.HBR;
1515
public partial class Seraphim
1616
{
1717
/// <inheritdoc/>
18-
public override async Task<bool> LaunchGameFromGameManagerCoreAsync(GameManagerExtension.RunGameFromGameManagerContext context, string? startArgument, bool isRunBoosted, ProcessPriorityClass processPriority, CancellationToken token)
18+
protected override (bool IsSupported, Task<bool> Task) LaunchGameFromGameManagerCoreAsync(GameManagerExtension.RunGameFromGameManagerContext context, string? startArgument, bool isRunBoosted, ProcessPriorityClass processPriority, CancellationToken token)
1919
{
20-
if (!TryGetGameProcessFromContext(context, startArgument, out Process? process))
21-
{
22-
return false;
23-
}
20+
return (true, Impl());
2421

25-
using (process)
22+
async Task<bool> Impl()
2623
{
27-
process.Start();
28-
29-
try
24+
if (!TryGetGameProcessFromContext(context, startArgument, out Process? process))
3025
{
31-
process.PriorityBoostEnabled = isRunBoosted;
32-
process.PriorityClass = processPriority;
26+
return false;
3327
}
34-
catch (Exception e)
28+
29+
using (process)
3530
{
36-
InstanceLogger.LogError(e, "[Seraphim::LaunchGameFromGameManagerCoreAsync()] An error has occurred while trying to set process priority, Ignoring!");
37-
}
31+
process.Start();
3832

39-
CancellationTokenSource gameLogReaderCts = new CancellationTokenSource();
40-
CancellationTokenSource coopCts = CancellationTokenSource.CreateLinkedTokenSource(token, gameLogReaderCts.Token);
33+
try
34+
{
35+
process.PriorityBoostEnabled = isRunBoosted;
36+
process.PriorityClass = processPriority;
37+
}
38+
catch (Exception e)
39+
{
40+
InstanceLogger.LogError(e, "[Seraphim::LaunchGameFromGameManagerCoreAsync()] An error has occurred while trying to set process priority, Ignoring!");
41+
}
4142

42-
// Run game log reader (Create a new thread)
43-
_ = ReadGameLog(context, process, coopCts.Token);
43+
CancellationTokenSource gameLogReaderCts = new();
44+
CancellationTokenSource coopCts = CancellationTokenSource.CreateLinkedTokenSource(token, gameLogReaderCts.Token);
4445

45-
// ReSharper disable once PossiblyMistakenUseOfCancellationToken
46-
await process.WaitForExitAsync(token);
47-
await gameLogReaderCts.CancelAsync();
46+
// Run game log reader (Create a new thread)
47+
_ = ReadGameLog(context, process, coopCts.Token);
4848

49-
return true;
49+
// ReSharper disable once PossiblyMistakenUseOfCancellationToken
50+
await process.WaitForExitAsync(token);
51+
await gameLogReaderCts.CancelAsync();
52+
53+
return true;
54+
}
5055
}
5156
}
5257

5358
/// <inheritdoc/>
54-
public override bool IsGameRunningCore(GameManagerExtension.RunGameFromGameManagerContext context, out bool isGameRunning, out DateTime gameStartTime)
59+
protected override bool IsGameRunningCore(GameManagerExtension.RunGameFromGameManagerContext context, out bool isGameRunning, out DateTime gameStartTime)
5560
{
5661
isGameRunning = false;
5762
gameStartTime = default;
@@ -69,25 +74,30 @@ public override bool IsGameRunningCore(GameManagerExtension.RunGameFromGameManag
6974
}
7075

7176
/// <inheritdoc/>
72-
public override async Task<bool> WaitRunningGameCoreAsync(GameManagerExtension.RunGameFromGameManagerContext context, CancellationToken token)
77+
protected override (bool IsSupported, Task<bool> Task) WaitRunningGameCoreAsync(GameManagerExtension.RunGameFromGameManagerContext context, CancellationToken token)
7378
{
74-
if (!TryGetGameExecutablePath(context, out string? gameExecutablePath))
75-
{
76-
return false;
77-
}
79+
return (true, Impl());
7880

79-
using Process? process = FindExecutableProcess(gameExecutablePath);
80-
if (process == null)
81+
async Task<bool> Impl()
8182
{
83+
if (!TryGetGameExecutablePath(context, out string? gameExecutablePath))
84+
{
85+
return false;
86+
}
87+
88+
using Process? process = FindExecutableProcess(gameExecutablePath);
89+
if (process == null)
90+
{
91+
return true;
92+
}
93+
94+
await process.WaitForExitAsync(token);
8295
return true;
8396
}
84-
85-
await process.WaitForExitAsync(token);
86-
return true;
8797
}
8898

8999
/// <inheritdoc/>
90-
public override bool KillRunningGameCore(GameManagerExtension.RunGameFromGameManagerContext context, out bool wasGameRunning, out DateTime gameStartTime)
100+
protected override bool KillRunningGameCore(GameManagerExtension.RunGameFromGameManagerContext context, out bool wasGameRunning, out DateTime gameStartTime)
91101
{
92102
wasGameRunning = false;
93103
gameStartTime = default;

Hi3Helper.Plugin.HBR/Exports.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ namespace Hi3Helper.Plugin.HBR;
1212
/// NOTE FOR DEVELOPERS:<br/>
1313
/// The export class name can be anything you want. In this example, we use "Seraphim" as a name to the weapon used by the characters.
1414
/// </summary>
15-
public partial class Seraphim : SharedStatic<Seraphim> // 2025-08-18: We use generic version of SharedStatic<T> to add support for game launch API.
16-
// Though, the devs can still use the old SharedStatic without any compatibility issue.
15+
public partial class Seraphim : SharedStaticV1Ext<Seraphim> // 2025-08-18: We use generic version of SharedStatic<T> to add extension for game launch API.
16+
// Though, the devs can still use the old SharedStatic without any compatibility issue.
17+
// 2025-09-24: SharedStatic<T> is now changed to SharedStaticV1Ext<T>.
18+
// This changes also bring new extension methods for Discord Presence API.
1719
{
1820
static Seraphim() => Load<HBRPlugin>(!RuntimeFeature.IsDynamicCodeCompiled ? new Core.Management.GameVersion(0, 8, 1, 0) : default); // Loads the IPlugin instance as HBRPlugin.
1921

0 commit comments

Comments
 (0)