Skip to content

Commit 81b28b8

Browse files
committed
Added a delayed method call
1 parent 9506984 commit 81b28b8

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ Need to install MelonLoader?<br>
66
Click [this link](https://melonwiki.xyz/) to get started!
77

88
## Mod Info
9-
**Mod Version**: v2.0.0<br>
9+
**Mod Version**: v2.0.1<br>
1010
**MelonLoader Version**: 0.5.4+
1111

1212
### Tested Games
1313
- BONEWORKS
14+
- BONELAB
1415
- VRChat (EAC Prevention)
1516
- Risk of Rain 2
1617
- NeosVR
@@ -20,5 +21,5 @@ Click [this link](https://melonwiki.xyz/) to get started!
2021
- Totally Accurate Battle Simulator
2122
- SynthRiders
2223
- Audica
23-
- Beat Saber _(Yes, with ML on top of IPA)_
24+
- Beat Saber _(Yes, with ML replacement)_
2425
- ChilloutVR

UniversalGamePriorityMod.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
using System;
12
using MelonLoader;
23
using System.Diagnostics;
4+
using System.Threading.Tasks;
35

46
namespace GamePriority;
57
public class GamePriorityChanger : MelonMod {
68
public static class BuildInfo {
79
public const string Name = "GamePriority";
810
public const string Author = "Lily";
911
public const string Company = "Minty Labs";
10-
public const string Version = "2.0.0";
12+
public const string Version = "2.0.1";
1113
public const string DownloadLink = "https://github.com/MintLily/GamePriority";
1214
}
1315

@@ -17,17 +19,29 @@ public static class BuildInfo {
1719
private const string ModCategory = "GamePriority";
1820
private const string SetGamePriority = "SetGamePriorityToHigh";
1921

22+
private int _failedProcessPriorityChange;
23+
2024
public override void OnApplicationStart() {
2125
_modCategory = MelonPreferences.CreateCategory(ModCategory, "Game Priority");
2226
_isSetToHigh = _modCategory.CreateEntry(SetGamePriority, false, "Set game priority to high");
2327

2428
ApplyChanges();
2529
}
2630

27-
public override void OnPreferencesSaved() => ApplyChanges();
31+
private void ApplyChanges() => Task.Run(async () => await DelayedRun());
2832

29-
private void ApplyChanges() {
30-
using var p = Process.GetCurrentProcess();
31-
p.PriorityClass = _isSetToHigh.Value ? ProcessPriorityClass.High : ProcessPriorityClass.Normal;
33+
private async Task DelayedRun() {
34+
await Task.Delay(5000);
35+
try {
36+
using var p = Process.GetCurrentProcess();
37+
p.PriorityClass = _isSetToHigh.Value ? ProcessPriorityClass.High : ProcessPriorityClass.Normal;
38+
}
39+
catch (Exception e) {
40+
MelonLogger.Error($"Failed to change ProcessPriority, retying ...\nEXCEPTION:\n{e}\nSTACK TRACE:\n{e.StackTrace}");
41+
if (_failedProcessPriorityChange >= 5)
42+
return;
43+
ApplyChanges();
44+
_failedProcessPriorityChange += 1;
45+
}
3246
}
3347
}

UniversalGamePriorityMod.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</PropertyGroup>
3030
<ItemGroup>
3131
<Reference Include="MelonLoader">
32-
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\MelonLoader.dll</HintPath>
32+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\MelonLoader.dll</HintPath>
3333
</Reference>
3434
<Reference Include="System" />
3535
</ItemGroup>

0 commit comments

Comments
 (0)