Skip to content

Latest commit

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

AsyncInput

A cross-platform input hook for ADOFAI (A Dance of Fire and Ice).
Replaces the game's built-in keyboard hook with a lower-latency, more precise implementation using platform-native APIs.

Features

  • Precise event timing — microsecond-resolution timestamps via Stopwatch.GetTimestamp()
  • Cross-platform — Windows (Win32 LL hook), Linux (XInput2), macOS (CGEventTap)
  • Harmony patches — intercepts AsyncInputManager.StartHook / StopHook / isActive for seamless integration
  • Direct memory queue — writes events directly to the game's keyQueue via IL emit, bypassing managed overhead

Supported platforms

PlatformAPINotes
WindowsSetWindowsHookEx(WH_KEYBOARD_LL)Low-level keyboard hook, works out of the box
LinuxXInput2 raw key events (libXi.so.6)Requires an X11 session; not compatible with Wayland
macOSCGEventTap (CoreGraphics.framework)Requires Input Monitoring permission (macOS 10.15+)

All platforms normalize key events to Windows virtual-key codes, sharing a single _vkToLabel mapping table.

Build

dotnet build AsyncInput/AsyncInput.csproj

Prerequisites

  • .NET Framework 4.8.1 SDK
  • References (not shipped): UnityModManager.dll, 0Harmony.dll, UnityEngine.dll, UnityEngine.CoreModule.dll

Place required DLLs in Lib/ (gitignored).

Usage

Install as a Unity Mod Manager mod. Toggle in the mod menu to enable/disable.

Project structure

AsyncInput/
├── AsyncInput.slnx
├── AsyncInput/
│ ├── Main.cs — Mod entry point, Harmony patches, provider lifecycle
│ ├── EventBridge.cs — OnKeyEvent handler: writes events to game queue
│ ├── ReflectionCache.cs — Runtime reflection + IL emit for queue access
│ ├── Native/ — P/Invoke declarations per platform
│ │ ├── WindowsNative.cs
│ │ ├── LinuxNative.cs
│ │ └── MacNative.cs
│ └── Platform/ — Input providers + keycode mapping tables
│ ├── IInputProvider.cs
│ ├── WindowsInputProvider.cs
│ ├── LinuxInputProvider.cs
│ ├── MacInputProvider.cs
│ ├── X11ToVk.cs — X11 keycode → Windows VK
│ └── MacToVk.cs — macOS keycode → Windows VK

Risk notes

  • Linux: XInput2 global hooks do not work under Wayland. Requires X11 session.
  • macOS: CGEventTap requires Input Monitoring permission. The mod logs a warning if the tap fails.

License

MIT

About

Cross-platform low-latency input hook for ADOFAI — Windows (Win32), Linux (XInput2), macOS (CGEventTap)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages