[+] AntiLag

This commit is contained in:
Clansty 2025-04-22 22:08:29 +08:00
parent 28e213b662
commit 558030f72a
No known key found for this signature in database
GPG Key ID: 3A6BE8BAF2EDE134

View 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);
}
}