mirror of
https://github.com/hykilpikonna/AquaDX.git
synced 2026-08-09 12:41:56 -05:00
[+] AntiLag
This commit is contained in:
parent
28e213b662
commit
558030f72a
44
AquaMai.Mods/Utils/AntiLag.cs
Normal file
44
AquaMai.Mods/Utils/AntiLag.cs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
using System.Runtime.InteropServices;
|
||||
using AquaMai.Config.Attributes;
|
||||
using HarmonyLib;
|
||||
using Main;
|
||||
using MelonLoader;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AquaMai.Mods.Utils;
|
||||
|
||||
[ConfigSection(
|
||||
en: "Some tricks to prevent the system from lagging",
|
||||
zh: "奇妙的防掉帧,如果你有莫名其妙的掉帧,可以试试这个")]
|
||||
public class AntiLag : MonoBehaviour
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(GameMainObject), "Awake")]
|
||||
public static void OnGameMainObjectAwake()
|
||||
{
|
||||
var go = new GameObject("妙妙防掉帧");
|
||||
go.AddComponent<AntiLag>();
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
InvokeRepeating(nameof(OnTimer), 10f, 10f);
|
||||
}
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "keybd_event", SetLastError = true)]
|
||||
private static extern void keybd_event(uint bVk, byte bScan, uint dwFlags, uint dwExtraInfo);
|
||||
|
||||
const int KEYEVENTF_KEYDOWN = 0x0000;
|
||||
const int KEYEVENTF_KEYUP = 0x0002;
|
||||
const int CTRL = 17;
|
||||
|
||||
private void OnTimer()
|
||||
{
|
||||
if (!Application.isFocused) return;
|
||||
#if DEBUG
|
||||
MelonLogger.Msg("[AntiLag] Trigger");
|
||||
#endif
|
||||
keybd_event(CTRL, 0, KEYEVENTF_KEYDOWN, 0);
|
||||
keybd_event(CTRL, 0, KEYEVENTF_KEYUP, 0);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user