This commit is contained in:
Sahik committed 2026-09-14 22:42:35 +08:00
1 parent d3aff16344
commit 74bf542515
20 files changed
+1416 -166

No files matched your search

@@ -0,0 +1,42 @@
using UnityEngine;
using TMPro;
public class AssistIntro : MonoBehaviour
{
[Header("UI 參照")]
[Tooltip("Dropdown")]
public TMP_Dropdown assistDropdown;
[Tooltip("Text (TMP)")]
public TextMeshProUGUI introDisplayText;
private readonly string[] intros = new string[]
{
" 不使用任何瞄準輔助,使用你最純粹的反應力與控制力瞄準。如果可以的話,無輔助與有輔助的測試次數請盡量控制在 1 : 1。",
" 依照敵方在螢幕上的座標,直接移動準心以實現瞄準。輔助強度為移動量,如設定 100% 會形成暴力鎖。",
" 依照敵方在螢幕上與你準心的距離,動態更改你的靈敏度(接近敵方時降低靈敏度)以吸附準心。輔助強度為靈敏度降低程度。"
};
void Start()
{
if (assistDropdown != null)
{
UpdateIntro(assistDropdown.value);
assistDropdown.onValueChanged.AddListener(OnDropdownChanged);
}
}
void OnDropdownChanged(int index)
{
UpdateIntro(index);
}
void UpdateIntro(int index)
{
if (introDisplayText != null && index >= 0 && index < intros.Length)
{
introDisplayText.text = intros[index];
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: eb773ea3cff4cd3458860b9d3eab1303
@@ -0,0 +1,45 @@
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class AssistStrength : MonoBehaviour
{
[Header("UI 參照")]
[Tooltip("Slider")]
public Slider targetSlider;
[Tooltip("Text (TMP)")]
public TextMeshProUGUI valueDisplayText;
void Start()
{
if (targetSlider != null)
{
// 設定拉桿的屬性
targetSlider.minValue = 1f;
targetSlider.maxValue = 100f;
targetSlider.wholeNumbers = true; // 每 1 一個階梯,使用整數
// 初始化顯示
UpdateDisplayText(targetSlider.value);
// 註冊拉桿數值改變事件
targetSlider.onValueChanged.AddListener(OnSliderValueChanged);
}
}
void OnSliderValueChanged(float rawValue)
{
int steppedValue = Mathf.RoundToInt(rawValue);
UpdateDisplayText(steppedValue);
}
void UpdateDisplayText(float val)
{
if (valueDisplayText != null)
{
int intVal = Mathf.RoundToInt(val);
valueDisplayText.text = $"輔助強度 : {intVal}%";
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e5ffef45c6a94f543a4f4bb8b1ed2f48
@@ -0,0 +1,41 @@
using UnityEngine;
using TMPro;
using UnityEngine.InputSystem;
public class Movement : MonoBehaviour
{
[Header("UI 參照")]
[Tooltip("Text (TMP)")]
public TextMeshProUGUI movementVectorText;
private Vector2 smoothedDelta = Vector2.zero;
private const float alpha = 0.1f; // 數值越大 越貼最新數值
void Update()
{
if (Mouse.current != null)
{
Vector2 currentDelta = Mouse.current.delta.ReadValue();
if (smoothedDelta == Vector2.zero)
{
smoothedDelta = currentDelta;
}
else
{
smoothedDelta = (alpha * currentDelta) + ((1.0f - alpha) * smoothedDelta);
}
}
else
{
smoothedDelta = Vector2.zero;
}
if (movementVectorText != null)
{
string xStr = (smoothedDelta.x >= 0 ? "+" : "") + smoothedDelta.x.ToString("F1");
string yStr = (smoothedDelta.y >= 0 ? "+" : "") + smoothedDelta.y.ToString("F1");
movementVectorText.text = $"移動向量: X: {xStr}, Y: {yStr}";
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0baddb7dc6fc5184997d41c4fe35bb25
@@ -0,0 +1,180 @@
using UnityEngine;
using TMPro;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Collections.Generic;
public class Polling : MonoBehaviour
{
[Header("UI 參照")]
[Tooltip("Text (TMP) ")]
public TextMeshProUGUI pollingDisplay;
private const int WH_MOUSE_LL = 14;
private const int WM_MOUSEMOVE = 0x0200;
private delegate IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam);
private static LowLevelMouseProc _proc;
private static IntPtr _hookID = IntPtr.Zero;
private static Stopwatch stopwatch = new Stopwatch();
private static long lastTicks = 0;
private static List<double> intervals = new List<double>();
private static readonly object lockObj = new object();
// EMA
private double smoothedMs = 0;
private const double alpha = 0.25;
// 無動作計時
private List<int> recentRates = new List<int>();
private float timeSinceLastEvent = 0f;
private const float idleTimeout = 2f; // 超過 2 秒沒動就歸零
void OnEnable()
{
stopwatch.Start();
_proc = HookCallback;
_hookID = SetHook(_proc);
}
void OnDisable()
{
UnhookWindowsHookEx(_hookID);
}
private IntPtr SetHook(LowLevelMouseProc proc)
{
using (Process curProcess = Process.GetCurrentProcess())
using (ProcessModule curModule = curProcess.MainModule)
{
return SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
}
}
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0 && wParam == (IntPtr)WM_MOUSEMOVE)
{
long currentTicks = stopwatch.ElapsedTicks;
if (lastTicks != 0)
{
double ms = (double)(currentTicks - lastTicks) / Stopwatch.Frequency * 1000.0;
lock (lockObj)
{
if (ms > 0.001 && ms < 100.0)
{
intervals.Add(ms);
}
}
}
lastTicks = currentTicks;
}
return CallNextHookEx(_hookID, nCode, wParam, lParam);
}
void Update()
{
List<double> currentBatch;
lock (lockObj)
{
currentBatch = new List<double>(intervals);
intervals.Clear();
}
if (currentBatch.Count > 0)
{
timeSinceLastEvent = 0f;
double sum = 0;
foreach (var val in currentBatch) sum += val;
double batchAvgMs = sum / currentBatch.Count;
if (smoothedMs == 0)
{
smoothedMs = batchAvgMs;
}
else
{
smoothedMs = (alpha * batchAvgMs) + ((1.0 - alpha) * smoothedMs);
}
if (smoothedMs > 0)
{
double rawHz = 1000.0 / smoothedMs;
int standardHz = SnapToStandardPollingRate(rawHz);
recentRates.Add(standardHz);
}
}
else
{
timeSinceLastEvent += Time.unscaledDeltaTime;
}
if (timeSinceLastEvent >= idleTimeout)
{
recentRates.Clear();
smoothedMs = 0;
}
// 更新 UI
if (pollingDisplay != null)
{
if (recentRates.Count > 0)
{
int maxHz = recentRates[0];
foreach (int rate in recentRates)
{
if (rate >= maxHz) maxHz = rate;
}
pollingDisplay.text = $"滑鼠回報率: {maxHz} Hz";
if (recentRates.Count > 60)
{
recentRates.RemoveAt(0);
}
}
else
{
pollingDisplay.text = "滑鼠回報率: 0 Hz";
}
}
}
private int SnapToStandardPollingRate(double rawHz)
{
int[] standardRates = {63, 125, 250, 500, 1000, 2000, 4000, 8000, 16000};
int closestRate = standardRates[0];
double minDifference = double.MaxValue;
foreach (int rate in standardRates)
{
double diff = Math.Abs(rawHz - rate);
if (diff < minDifference)
{
minDifference = diff;
closestRate = rate;
}
}
return closestRate;
}
#region Win32 API 匯入
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelMouseProc lpfn, IntPtr hMod, uint dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool UnhookWindowsHookEx(IntPtr hk);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr CallNextHookEx(IntPtr hk, int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr GetModuleHandle(string lpModuleName);
#endregion
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: dbfae505c051b8241a378b2712dd7b5d
@@ -1,71 +0,0 @@
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.LowLevel;
using System.Collections.Generic;
public class MouseTrailLogger : MonoBehaviour
{
// 定義單筆數據結構:包含時間戳記與當下的微小位移量
[System.Serializable]
public struct MouseSample
{
public double timestamp; // 作業系統級別的時間戳記(秒,可換算為 ms)
public Vector2 delta; // 該瞬間的滑鼠位移量 (Delta)
}
private List<MouseSample> recordedSamples = new List<MouseSample>();
private bool isRecording = false;
void OnEnable()
{
// 註冊 Input System 的底層事件攔截器
InputSystem.onEvent += OnDataEvent;
}
void OnDisable()
{
// 記得取消註冊,避免記憶體洩漏
InputSystem.onEvent -= OnDataEvent;
}
public void StartRecording()
{
recordedSamples.Clear();
isRecording = true;
}
public void StopRecording()
{
isRecording = false;
// 這裡可以把 recordedSamples 序列化成 JSON 準備上傳到 GitHub 或後端
}
private void OnDataEvent(InputEventPtr eventPtr, InputDevice device)
{
if (!isRecording) return;
// 檢查這個事件是否由「滑鼠」發出,且是否包含狀態更新
if (device is Mouse mouse)
{
// 判斷事件類型是否為滑鼠動態 (State Event)
if (eventPtr.IsA<StateEvent>() || eventPtr.IsA<DeltaStateEvent>())
{
// 取得該事件發生時作業系統的高精度時間戳記 (Unscaled Time)
double eventTime = eventPtr.time;
// 讀取當下的滑鼠位移量
Vector2 mouseDelta = mouse.delta.ReadValue();
// 只有當滑鼠真有移動時才記錄,避免無效資料浪費記憶體
if (mouseDelta != Vector2.zero)
{
recordedSamples.Add(new MouseSample
{
timestamp = eventTime,
delta = mouseDelta
});
}
}
}
}
}
@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 20bda67a74291514cac9cd232e2093ee
@@ -0,0 +1,42 @@
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class Sensitivity : MonoBehaviour
{
[Header("UI 參照")]
[Tooltip("Slider")]
public Slider targetSlider;
[Tooltip("Text (TMP)")]
public TextMeshProUGUI valueDisplayText;
void Start()
{
if (targetSlider != null)
{
targetSlider.minValue = 0.1f;
targetSlider.maxValue = 10.0f;
targetSlider.wholeNumbers = false;
UpdateDisplayText(targetSlider.value);
targetSlider.onValueChanged.AddListener(OnSliderValueChanged);
}
}
void OnSliderValueChanged(float rawValue)
{
float steppedValue = Mathf.Round(rawValue * 10f) / 10f;
UpdateDisplayText(steppedValue);
}
void UpdateDisplayText(float val)
{
if (valueDisplayText != null)
{
valueDisplayText.text = $"靈敏度 : {val:F1}";
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0c0bf45cb5cebd14190d7c1e7ec7f6d7
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 652d306d5da9f394ba03403e88093a84
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+107
View File
@@ -0,0 +1,107 @@
using UnityEngine;
using TMPro;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Collections.Generic;
public class Win32PollingAnalyzer : MonoBehaviour
{
[Header("UI 參照")]
[Tooltip("請把顯示輪詢率的 Text (TMP) 拖進這裡")]
public TextMeshProUGUI pollingDisplay;
private const int WH_MOUSE_LL = 14;
private const int WM_MOUSEMOVE = 0x0200;
private delegate IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam);
private static LowLevelMouseProc _proc;
private static IntPtr _hookID = IntPtr.Zero;
private static Stopwatch stopwatch = new Stopwatch();
private static long lastTicks = 0;
private static List<double> intervals = new List<double>();
private static readonly object lockObj = new object();
void OnEnable()
{
stopwatch.Start();
_proc = HookCallback;
// 在 Unity 啟動時安裝 Windows 底層滑鼠勾子
_hookID = SetHook(_proc);
}
void OnDisable()
{
// 離開或關閉時務必解除安裝,否則容易造成 Unity 編輯器卡頓
UnhookWindowsHookEx(_hookID);
}
private IntPtr SetHook(LowLevelMouseProc proc)
{
using (Process curProcess = Process.GetCurrentProcess())
using (ProcessModule curModule = curProcess.MainModule)
{
return SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
}
}
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0 && wParam == (IntPtr)WM_MOUSEMOVE)
{
long currentTicks = stopwatch.ElapsedTicks;
if (lastTicks != 0)
{
// 計算兩次底層滑鼠事件之間的高精度毫秒差
double ms = (double)(currentTicks - lastTicks) / Stopwatch.Frequency * 1000.0;
lock (lockObj)
{
if (ms > 0.001 && ms < 100.0) // 過濾極端異常值
{
intervals.Add(ms);
}
}
}
lastTicks = currentTicks;
}
return CallNextHookEx(_hookID, nCode, wParam, lParam);
}
void Update()
{
// 每幀從清單中抓取並清空累積的數據,計算平均值更新到 UI
List<double> currentBatch;
lock (lockObj)
{
currentBatch = new List<double>(intervals);
intervals.Clear();
}
if (currentBatch.Count > 0 && pollingDisplay != null)
{
double sum = 0;
foreach (var val in currentBatch) sum += val;
double avgMs = sum / currentBatch.Count;
int hz = avgMs > 0 ? (int)Math.Round(1000.0 / avgMs) : 0;
pollingDisplay.text = $"延遲: {avgMs:F2} ms | 實測回報率: {hz} Hz";
}
}
#region Win32 API 匯入
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelMouseProc lpfn, IntPtr hMod, uint dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool UnhookWindowsHookEx(IntPtr hk);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr CallNextHookEx(IntPtr hk, int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr GetModuleHandle(string lpModuleName);
#endregion
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: f41105b446ed5b547a12f7b50c59d367
+136
View File
@@ -0,0 +1,136 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Collections.Generic;
class Program
{
private const int WH_MOUSE_LL = 14;
private const int WM_MOUSEMOVE = 0x0200;
private delegate IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam);
private static LowLevelMouseProc _proc = HookCallback;
private static IntPtr _hookID = IntPtr.Zero;
private static Stopwatch stopwatch = Stopwatch.StartNew();
private static long lastTicks = 0;
private static List<double> intervals = new List<double>();
private static readonly object lockObj = new object();
static void Main(string[] args)
{
Console.WriteLine("========================================");
Console.WriteLine("純 C# 獨立滑鼠輪詢率 (Polling Rate) 檢測工具");
Console.WriteLine("請在視窗外「持續滑動滑鼠」...");
Console.WriteLine("關閉主控台視窗即可結束。");
Console.WriteLine("========================================");
// 安裝全域滑鼠 Hook
_hookID = SetHook(_proc);
// 啟動背景執行緒,每 0.5 秒計算並印出數據
Thread statsThread = new Thread(PrintStats);
statsThread.IsBackground = true;
statsThread.Start();
// Windows 低階 Hook 需要訊息迴圈 (Message Loop) 來接收事件
MSG msg;
while (GetMessage(out msg, IntPtr.Zero, 0, 0) > 0)
{
TranslateMessage(ref msg);
DispatchMessage(ref msg);
}
UnhookWindowsHookEx(_hookID);
}
private static IntPtr SetHook(LowLevelMouseProc proc)
{
using (Process curProcess = Process.GetCurrentProcess())
using (ProcessModule curModule = curProcess.MainModule)
{
return SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
}
}
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0 && wParam == (IntPtr)WM_MOUSEMOVE)
{
long currentTicks = stopwatch.ElapsedTicks;
if (lastTicks != 0)
{
// 計算兩次滑鼠移動事件之間的高精度毫秒差
double ms = (double)(currentTicks - lastTicks) / Stopwatch.Frequency * 1000.0;
lock (lockObj)
{
if (ms > 0.001 && ms < 100.0) // 過濾異常極端值
{
intervals.Add(ms);
}
}
}
lastTicks = currentTicks;
}
return CallNextHookEx(_hookID, nCode, wParam, lParam);
}
private static void PrintStats()
{
while (true)
{
Thread.Sleep(500);
List<double> currentBatch;
lock (lockObj)
{
currentBatch = new List<double>(intervals);
intervals.Clear();
}
if (currentBatch.Count > 0)
{
double sum = 0;
foreach (var val in currentBatch) sum += val;
double avgMs = sum / currentBatch.Count;
int hz = avgMs > 0 ? (int)Math.Round(1000.0 / avgMs) : 0;
Console.WriteLine($"平均間隔: {avgMs,6:F2} ms | 實測回報率: {hz,5} Hz (樣本數: {currentBatch.Count})");
}
else
{
Console.WriteLine("等待滑鼠移動...");
}
}
}
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelMouseProc lpfn, IntPtr hMod, uint dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool UnhookWindowsHookEx(IntPtr hk);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr CallNextHookEx(IntPtr hk, int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr GetModuleHandle(string lpModuleName);
[DllImport("user32.dll")]
private static extern int GetMessage(out MSG lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax);
[DllImport("user32.dll")]
private static extern bool TranslateMessage(ref MSG lpMsg);
[DllImport("user32.dll")]
private static extern IntPtr DispatchMessage(ref MSG lpMsg);
[StructLayout(LayoutKind.Sequential)]
public struct POINT { public int x; public int y; }
[StructLayout(LayoutKind.Sequential)]
public struct MSG { public IntPtr hwnd; public uint message; public IntPtr wParam; public IntPtr lParam; public uint time; public POINT pt; }
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 9707f3354094cab459e58a8aded637f1
+44
View File
@@ -0,0 +1,44 @@
import time
from pynput import mouse
last_time = time.perf_counter()
event_intervals = []
def on_move(x, y):
global last_time
current_time = time.perf_counter()
delta = current_time - last_time
last_time = current_time
if 0.0001 < delta < 0.1:
event_intervals.append(delta)
def main():
print("=" * 40)
print("滑鼠輪詢率 (Polling Rate) 獨立檢測工具")
print("請在視窗外「持續滑動滑鼠」以獲取數據...")
print("按 Ctrl + C 可以結束程式並查看統計")
print("=" * 40)
listener = mouse.Listener(on_move=on_move)
listener.start()
try:
while True:
time.sleep(0.5)
if event_intervals:
current_batch = event_intervals.copy()
event_intervals.clear()
avg_interval = sum(current_batch) / len(current_batch)
hz = 1.0 / avg_interval if avg_interval > 0 else 0
print(f"平均間隔: {avg_interval * 1000:.2f} ms | 實測回報率: {round(hz):4d} Hz")
except KeyboardInterrupt:
print("\n正在停止監聽...")
listener.stop()
print("已結束。")
if __name__ == "__main__":
main()
+7
View File
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: fe5e9aac1dc105f43a01d71557cccfaf
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: