Skip to content

Commit

Permalink
Added a delayed method call
Browse files Browse the repository at this point in the history
  • Loading branch information
MintLily committed Nov 4, 2022
1 parent 9506984 commit 81b28b8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ Need to install MelonLoader?<br>
Click [this link](https://melonwiki.xyz/) to get started!

## Mod Info
**Mod Version**: v2.0.0<br>
**Mod Version**: v2.0.1<br>
**MelonLoader Version**: 0.5.4+

### Tested Games
- BONEWORKS
- BONELAB
- VRChat (EAC Prevention)
- Risk of Rain 2
- NeosVR
Expand All @@ -20,5 +21,5 @@ Click [this link](https://melonwiki.xyz/) to get started!
- Totally Accurate Battle Simulator
- SynthRiders
- Audica
- Beat Saber _(Yes, with ML on top of IPA)_
- Beat Saber _(Yes, with ML replacement)_
- ChilloutVR
24 changes: 19 additions & 5 deletions UniversalGamePriorityMod.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using System;
using MelonLoader;
using System.Diagnostics;
using System.Threading.Tasks;

namespace GamePriority;
public class GamePriorityChanger : MelonMod {
public static class BuildInfo {
public const string Name = "GamePriority";
public const string Author = "Lily";
public const string Company = "Minty Labs";
public const string Version = "2.0.0";
public const string Version = "2.0.1";
public const string DownloadLink = "https://github.com/MintLily/GamePriority";
}

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

private int _failedProcessPriorityChange;

public override void OnApplicationStart() {
_modCategory = MelonPreferences.CreateCategory(ModCategory, "Game Priority");
_isSetToHigh = _modCategory.CreateEntry(SetGamePriority, false, "Set game priority to high");

ApplyChanges();
}

public override void OnPreferencesSaved() => ApplyChanges();
private void ApplyChanges() => Task.Run(async () => await DelayedRun());

private void ApplyChanges() {
using var p = Process.GetCurrentProcess();
p.PriorityClass = _isSetToHigh.Value ? ProcessPriorityClass.High : ProcessPriorityClass.Normal;
private async Task DelayedRun() {
await Task.Delay(5000);
try {
using var p = Process.GetCurrentProcess();
p.PriorityClass = _isSetToHigh.Value ? ProcessPriorityClass.High : ProcessPriorityClass.Normal;
}
catch (Exception e) {
MelonLogger.Error($"Failed to change ProcessPriority, retying ...\nEXCEPTION:\n{e}\nSTACK TRACE:\n{e.StackTrace}");
if (_failedProcessPriorityChange >= 5)
return;
ApplyChanges();
_failedProcessPriorityChange += 1;
}
}
}
2 changes: 1 addition & 1 deletion UniversalGamePriorityMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="MelonLoader">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\MelonLoader.dll</HintPath>
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\MelonLoader.dll</HintPath>
</Reference>
<Reference Include="System" />
</ItemGroup>
Expand Down

0 comments on commit 81b28b8

Please sign in to comment.