Skip to content

Commit 558030f

Browse files
committed
[+] AntiLag
1 parent 28e213b commit 558030f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

AquaMai.Mods/Utils/AntiLag.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System.Runtime.InteropServices;
2+
using AquaMai.Config.Attributes;
3+
using HarmonyLib;
4+
using Main;
5+
using MelonLoader;
6+
using UnityEngine;
7+
8+
namespace AquaMai.Mods.Utils;
9+
10+
[ConfigSection(
11+
en: "Some tricks to prevent the system from lagging",
12+
zh: "奇妙的防掉帧,如果你有莫名其妙的掉帧,可以试试这个")]
13+
public class AntiLag : MonoBehaviour
14+
{
15+
[HarmonyPostfix]
16+
[HarmonyPatch(typeof(GameMainObject), "Awake")]
17+
public static void OnGameMainObjectAwake()
18+
{
19+
var go = new GameObject("妙妙防掉帧");
20+
go.AddComponent<AntiLag>();
21+
}
22+
23+
private void Awake()
24+
{
25+
InvokeRepeating(nameof(OnTimer), 10f, 10f);
26+
}
27+
28+
[DllImport("user32.dll", EntryPoint = "keybd_event", SetLastError = true)]
29+
private static extern void keybd_event(uint bVk, byte bScan, uint dwFlags, uint dwExtraInfo);
30+
31+
const int KEYEVENTF_KEYDOWN = 0x0000;
32+
const int KEYEVENTF_KEYUP = 0x0002;
33+
const int CTRL = 17;
34+
35+
private void OnTimer()
36+
{
37+
if (!Application.isFocused) return;
38+
#if DEBUG
39+
MelonLogger.Msg("[AntiLag] Trigger");
40+
#endif
41+
keybd_event(CTRL, 0, KEYEVENTF_KEYDOWN, 0);
42+
keybd_event(CTRL, 0, KEYEVENTF_KEYUP, 0);
43+
}
44+
}

0 commit comments

Comments
 (0)