Skip to content

Commit 08d3a37

Browse files
committed
feat: support fps unlocker for 5.8
1 parent e83c25a commit 08d3a37

File tree

5 files changed

+27
-66
lines changed

5 files changed

+27
-66
lines changed

src/Fischless.Relauncher/Core/Relaunchs/GenshinFpsUnlocker.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
using Fischless.Relauncher.Relaunchs;
22
using System.Diagnostics;
33
using System.Runtime.InteropServices;
4+
using UnlockerPatch;
45

56
namespace Fischless.Relauncher.Core.Relaunchs;
67

7-
internal sealed class GenshinFpsUnlocker(Process gameProcess)
8+
internal sealed class GenshinFpsUnlocker(string gamePath, string? cli = null)
89
{
9-
private readonly Process gameProcess = gameProcess;
10+
private readonly string gamePath = gamePath;
11+
private readonly string? cli = cli;
1012
private int unlockFps;
1113

1214
public GenshinFpsUnlocker SetTargetFps(int unlockFps)
@@ -18,33 +20,26 @@ public GenshinFpsUnlocker SetTargetFps(int unlockFps)
1820
public async Task UnlockAsync(GenshinUnlockerOption options, CancellationTokenSource cts = null!)
1921
{
2022
options.UnlockFps = unlockFps;
21-
await Task.Run(() => GameFpsUnlockerImpl.Start(options, pid: (uint)gameProcess.Id, cts: cts));
23+
await Task.Run(() => GameFpsUnlockerImpl.Start(options, gamePath, cli, cts: cts));
2224
}
2325
}
2426

2527
internal sealed partial class GameFpsUnlockerImpl
2628
{
27-
private static partial class Interop
28-
{
29-
[LibraryImport(@".\runtimes\win-x64\native\Fischless.UnlockerPatch.dll", EntryPoint = "unlock")]
30-
public static partial int Unlock(int pid, int targetFPS);
31-
}
32-
33-
public static unsafe void Start(GenshinUnlockerOption option, string? gamePath = null, uint? pid = null, CancellationTokenSource? cts = null)
29+
public static void Start(GenshinUnlockerOption option, string? gamePath = null, string? cli = null, CancellationTokenSource? cts = null)
3430
{
3531
if (!option.UnlockFps.HasValue)
3632
{
3733
return;
3834
}
3935

40-
if (string.IsNullOrWhiteSpace(gamePath) && pid == null)
36+
if (string.IsNullOrWhiteSpace(gamePath))
4137
{
4238
return;
4339
}
4440

45-
int targetPid = (int)pid!.Value;
4641
int targetFps = option.UnlockFps.Value;
47-
int ret = Interop.Unlock(targetPid, targetFps);
42+
bool ret = UnlockerLauncher.Start(gamePath, targetFps, cli);
4843

4944
Debug.WriteLine("[Unlocker] Unlock ret is " + ret);
5045
}

src/Fischless.Relauncher/Core/Relaunchs/GenshinLauncher.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -288,21 +288,16 @@ public static async Task LaunchAsync(int? delayMs = null, GenshinRelaunchMethod
288288
}
289289
}
290290

291-
using Process? gameProcess = Process.Start(new ProcessStartInfo()
291+
if (option.Unlocker == null)
292292
{
293-
UseShellExecute = true,
294-
FileName = fileName,
295-
Arguments = option.Arguments?.ToArguments(),
296-
WorkingDirectory = option.WorkingDirectory ?? new FileInfo(fileName).DirectoryName,
297-
Verb = "runas",
298-
});
299-
300-
if (option.Linkage != null)
301-
{
302-
if (option.Linkage.IsUseBetterGI)
293+
using Process? gameProcess = Process.Start(new ProcessStartInfo()
303294
{
304-
await Launcher.LaunchUriAsync(new Uri("bettergi://start"));
305-
}
295+
UseShellExecute = true,
296+
FileName = fileName,
297+
Arguments = option.Arguments?.ToArguments(),
298+
WorkingDirectory = option.WorkingDirectory ?? Path.GetDirectoryName(fileName),
299+
Verb = "runas",
300+
});
306301
}
307302

308303
if (option.Unlocker != null)
@@ -315,15 +310,12 @@ public static async Task LaunchAsync(int? delayMs = null, GenshinRelaunchMethod
315310
{
316311
if (((GenshinUnlockerOption)option.Unlocker).UnlockFpsMethod == 0)
317312
{
318-
await new GenshinFpsUnlocker(gameProcess!)
313+
await new GenshinFpsUnlocker(fileName, option.Arguments?.ToArguments())
319314
.SetTargetFps((int)option.Unlocker.UnlockFps)
320315
.UnlockAsync(GenshinUnlockerOption.Default.Value);
321316
}
322317
else
323318
{
324-
//await new GenshinFpsUnlocker1(gameProcess!)
325-
// .SetTargetFps((int)option.Unlocker.UnlockFps)
326-
// .UnlockAsync(GenshinUnlockerOption.Default.Value);
327319
}
328320
}
329321
catch
@@ -333,6 +325,14 @@ public static async Task LaunchAsync(int? delayMs = null, GenshinRelaunchMethod
333325
}
334326
}
335327
}
328+
329+
if (option.Linkage != null)
330+
{
331+
if (option.Linkage.IsUseBetterGI)
332+
{
333+
await Launcher.LaunchUriAsync(new Uri("bettergi://start"));
334+
}
335+
}
336336
}
337337

338338
public static async Task<bool> TryGetProcessAsync(Func<Process?, Task> callback = null!)
Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
1-
using System.Diagnostics.CodeAnalysis;
2-
3-
namespace Fischless.Relauncher.Relaunchs.Abstraction;
1+
namespace Fischless.Relauncher.Relaunchs.Abstraction;
42

53
public interface IGameUnlockerOption
64
{
75
public bool IsUnlockFps { get; set; }
86

97
public int? UnlockFps { get; set; }
10-
11-
[Obsolete]
12-
[SuppressMessage("Design", "CA1041:Provide ObsoleteAttribute message")]
13-
public int FindModuleDelay { get; set; }
14-
15-
[Obsolete]
16-
[SuppressMessage("Design", "CA1041:Provide ObsoleteAttribute message")]
17-
public int FindModuleLimit { get; set; }
18-
19-
[Obsolete]
20-
[SuppressMessage("Design", "CA1041:Provide ObsoleteAttribute message")]
21-
public int FpsDelay { get; set; }
228
}
Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Fischless.Relauncher.Relaunchs.Abstraction;
2-
using System.Diagnostics.CodeAnalysis;
32

43
namespace Fischless.Relauncher.Relaunchs;
54

@@ -12,16 +11,4 @@ public sealed class GenshinUnlockerOption : IGameUnlockerOption
1211
public int? UnlockFps { get; set; } = 120;
1312

1413
public int UnlockFpsMethod { get; set; } = 0;
15-
16-
[Obsolete]
17-
[SuppressMessage("Design", "CA1041:Provide ObsoleteAttribute message")]
18-
public int FindModuleDelay { get; set; } = 100;
19-
20-
[Obsolete]
21-
[SuppressMessage("Design", "CA1041:Provide ObsoleteAttribute message")]
22-
public int FindModuleLimit { get; set; } = 2000;
23-
24-
[Obsolete]
25-
[SuppressMessage("Design", "CA1041:Provide ObsoleteAttribute message")]
26-
public int FpsDelay { get; set; } = 2000;
2714
}

src/Fischless.Relauncher/Fischless.Relauncher.csproj

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,7 @@
4949
<PackageReference Include="Fischless.Logger" Version="1.0.0" />
5050
<PackageReference Include="Fischless.Configuration" Version="1.0.0" />
5151
<PackageReference Include="Fischless.Configuration.Yaml" Version="1.0.0" />
52-
<PackageReference Include="Fischless.UnlockerPatch" Version="4.8.0">
53-
<PrivateAssets>all</PrivateAssets>
54-
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
55-
</PackageReference>
56-
<PackageReference Include="Snap.Hutao.UnlockerIsland" Version="1.4.0">
57-
<PrivateAssets>all</PrivateAssets>
58-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
59-
</PackageReference>
52+
<PackageReference Include="Fischless.UnlockerPatch" Version="5.8.0.3" />
6053
</ItemGroup>
6154

6255
</Project>

0 commit comments

Comments
 (0)