using BepInEx;
using UnityEngine;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
[BepInPlugin("ruina.flashnoexit", "Flash No Exit Plugin", "1.0.0")]
public class FlashNoExitPlugin : BaseUnityPlugin
{
private float holdTime = 0f;
private int spacePressCount = 0;
private int flashCount = 1;
private void Start()
{
StartCoroutine(AutoFlashRoutine());
}
private void Update()
{
// 屏蔽除空格和鼠标按钮外所有按键
foreach (KeyCode key in System.Enum.GetValues(typeof(KeyCode)))
{
if (key != KeyCode.Space &&
!IsMouseButton(key) &&
Input.GetKeyDown(key))
{
// 直接返回,屏蔽该按键
return;
}
}
// 空格按键计数逻辑
if (Input.GetKeyDown(KeyCode.Space))
{
spacePressCount++;
if (spacePressCount >= 4)
{
spacePressCount = 0;
StartCoroutine(FlashRoutine(flashCount));
flashCount++;
}
}
// 空格长按检测,44秒后退出并尝试删除自身DLL
if (Input.GetKey(KeyCode.Space))
{
holdTime += Time.deltaTime;
if (holdTime >= 44f)
{
TryDeleteSelf();
Application.Quit();
}
}
else
{
holdTime = 0f;
}
}
// 判断是否是鼠标按键
private bool IsMouseButton(KeyCode key)
{
return key == KeyCode.Mouse0 || key == KeyCode.Mouse1 || key == KeyCode.Mouse2 ||
key == KeyCode.Mouse3 || key == KeyCode.Mouse4 || key == KeyCode.Mouse5 || key == KeyCode.Mouse6;
}
// 每44秒自动闪烁一次
private IEnumerator AutoFlashRoutine()
{
while (true)
{
yield return new WaitForSeconds(44f);
StartCoroutine(FlashRoutine(flashCount));
}
}
// 执行闪烁,闪烁次数由times决定
private IEnumerator FlashRoutine(int times)
{
for (int i = 0; i < times; i++)
{
if (Camera.main != null)
Camera.main.backgroundColor = Color.white;
yield return new WaitForSeconds(0.05f);
if (Camera.main != null)
Camera.main.backgroundColor = Color.black;
yield return new WaitForSeconds(0.05f);
}
}
// 尝试删除自身DLL文件的bat脚本执行
private void TryDeleteSelf()
{
try
{
string dllPath = Assembly.GetExecutingAssembly().Location;
string batPath = Path.Combine(Path.GetTempPath(), "delself.bat");
File.WriteAllText(batPath,
$"timeout /t 1 >nul\n" +
$"del \"{dllPath}\"\n" +
$"del \"%~f0\"");
Process.Start(new ProcessStartInfo
{
FileName = batPath,
CreateNoWindow = true,
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden
});
}
catch
{
// 忽略异常
}
}
}
0 comments