Revamp GameInput backend and enhance diagnostics for gamepad support#37
Merged
Conversation
移除已封存的 GameInput.Net、UsbVendorsLibrary 與 usb.ids 授權流程,改由專案自有 native shim 連接 Microsoft GameInput runtime,並維持 XInput 作為預設控制器提供者。 更新 release workflow 以在 Windows runner 編譯 native shim、發佈 single-file、隨附 GameInputRedist.msi 與 Microsoft 授權聲明,並驗證 ZIP 不含舊授權檔、gameinput.dll 或可見 shim sidecar。 補上 GameInput fallback、VID 判斷、Pause/Resume、斷線重列舉與 rumble safety 測試,同時修正 PhraseService 併發匯出在 CI 下的檔案替換競態。
直接更新 embedded native shim 與 managed GameInput layer 的同版 ABI。 補齊 Gamepad device info、timestamp、v3 buttons、callbacks 與 capabilities metadata,並維持 60 FPS polling 作為唯一正式輸入流程。 新增 GameInput primitives 測試與工程規範,確認 release single-file publish 不暴露 shim sidecar。
補強 GameInput native shim 的 runtime probe、ABI size 防呆、安全 DLL 載入來源記錄與 SRW lock 保護。 Managed layer 同步驗證 shim struct size,新增診斷模型與 Gamepad-only 測試,並更新工程文件與測試清單。
新增 InputBox.GameInput.Native README,說明 gamepad-only 範圍、ABI 規則、runtime 載入、回呼與發佈驗證邊界。 補上 C++ shim 維護註解,並讓 native 專案以 /utf-8 編譯,避免正體中文註解在 MSVC CP950 環境產生 C4819。 同步將 Microsoft.Testing.Extensions.CodeCoverage 更新至 18.7.0,保持 CI coverage 工具鏈使用新版套件。
新增 native shim export/probe 驗證腳本,並接入 CI 與 release workflow。 補強 GameInput 診斷快照 log,維持 Gamepad-only 行為不變。 同步更新 GameInput shim 文件、工程規範與 P/Invoke export 清單測試。
讓 tools 變更觸發 CI,避免驗證腳本修改未進入 native shim 守門流程。 補強 GameInput native probe smoke,直接比對 native 回報與 managed mirror 的 struct size。 同步更新 GameInput shim 文件與工程規範。
新增 GameInput 手動硬體驗證文件,整理實體控制器與發佈 ZIP 抽測情境。 同步更新 GameInput API 規範與 native shim README,說明此矩陣不是日常 PR 或 CI 必跑關卡。
在 GameInput native shim 驗證腳本加入 lifecycle stress smoke,覆蓋 context 建立、callback 註冊解除與銷毀清理。 同步更新 CI/release 步驟名稱與 GameInput shim 文件,說明 runtime 不可用時只略過 lifecycle 守門。
- 取消 XInput 的非對稱右向退出閾值(max(exit, enter × 0.75f)),
改與 GameInput 統一使用 GamepadDeadzoneHysteresis.ResolveDirection
對稱 Enter/Exit 閾值,落實「硬體平等」原則並對齊業界黃金標準
(Steam Input / DS4Windows / Unity InputSystem 均不做 per-direction
差別補償)。若特定硬體出現右向 sticky 現象,正確處方是請使用者
(對稱地)提高 ThumbDeadzoneEnter / Exit 設定值,而非在程式碼路徑
做差別補償。
- 修補兩個控制器 ClearAllEvents 漏清的 LeftShoulderReleased 與
RightShoulderReleased 事件訂閱,避免處置後仍殘留呼叫鏈造成事件洩漏。
- GameInput EmitMechanismHealthLog 補上 mapGuard={...} 欄位與
_lastHealthMapGuardActive 比對欄位,與 XInput 端日誌格式對齊,
便於跨後端排查 anti-stuck 啟動狀態(DEBUG 模式)。
- 改寫 docs/engineering/gamepad-api.md §4.5:移除文件債(既有程式碼
中不存在的 _suppressMappedRightFromLeftStick 旗標)與「非對稱
退出閾值」描述,改為「方向映射統一規範(硬體平等原則)」並補上
業界標準佐證與硬體漂移處方。
- 新增單元測試守門:GamepadDeadzoneHysteresis 正負方向對稱性
(int / float 各一)與兩個控制器 ClearAllEvents 肩鍵釋放清除。
- 同步更新 tests/InputBox.Tests/README.md 測試數(382 → 386)。
ToS 合規分析(git-commit-safety.md §2 / §5):
- FFXIV 使用者合約已成功擷取並評估:本次變更為內部 deadzone 閾值
對稱化、DEBUG-only 診斷日誌補強、事件訂閱清除,未改變遊戲平衡、
未提供不正當優勢、未規避防護機制、未做自動化或輸入模擬,符合條款。
- UserJoy EULA / 隱私權政策頁面僅回傳客服界面(疑為 JS 渲染),
依規範明確記錄「未能擷取完整本文」;本次變更不屬於「按鍵處理 /
剪貼簿自動化 / 控制器映射」的高風險核心輸入/輸出異動,仍符合
AGENTS.md §2 安全紅線。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- src/InputBox/Core/Input/GameInputNative.cs:為 GameInputNativeMethods 內 15 個 P/Invoke 方法、2 個 callback delegate 與 NativeLibraryName 常數補上完整 XML doc(/// summary + param + returns),涵蓋 ProbeRuntime、Create、Destroy、GetShimInfo、GetDiagnosticsSnapshot、 SetFocusPolicy、RefreshDevices、GetDeviceCount、GetDeviceInfo、 GetDeviceStatus、ReadGamepadState、RegisterReadingCallback、 RegisterDeviceCallback、UnregisterCallback、SetRumbleState,以及 GameInputNativeReadingCallback / GameInputNativeDeviceCallback。 - src/InputBox.GameInput.Native/InputBoxGameInputNative.cpp:為 15 個 __declspec(dllexport) 導出函式補上 Doxygen 風格頂端註解 (@brief + @param + @return),標註每個參數的 nullptr 合法性、 UTF-8 編碼語意、out 參數行為,以及特殊 HRESULT 回傳值 (InputBoxGameInputNoReading、ERROR_DEVICE_NOT_CONNECTED、 ERROR_NOT_FOUND)。 純文件補強,不改變任何執行階段行為;Debug/Release 全量重建(含 native shim vcxproj)與 375 個非 UI 單元測試皆通過,0 警告 0 錯誤。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
在 CI 與 release 的 GameInput native shim build 明確覆寫 PlatformToolset=v143,符合 GitHub windows-latest 的 Visual Studio 2022 工具鏈。 保留本機 vcxproj 預設 v145,避免影響 VS2026 開發環境。
Contributor
There was a problem hiding this comment.
Pull request overview
這個 PR 以「自有 native shim + 受控端窄版 ABI」全面重整 GameInput 後端,並同步強化 CI / Release 的驗證與 Microsoft GameInput Redistributable 的打包合規流程,讓 GameInput 變成可選後端且在失敗時能可靠退避至 XInput,同時提供更完整的診斷資訊。
Changes:
- 新增
InputBox.GameInput.Native(C++)shim 與對應 C# interop/資料模型,並將主程式的 DLL resolver 擴充為同時支援 XInput 與 GameInput shim。 - 更新 GameInput 控制器輪詢/重連/診斷紀錄邏輯,新增多組針對 ABI、exports、VID/PID、missing-reading 等行為的測試守門。
- 重整 CI / Release:在 Windows runner 上建置與驗證 native shim、打包
redist/GameInputRedist.msi與授權/notice、並對 ZIP 內容做 required/forbidden 驗證。
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/Validate-GameInputNativeShim.ps1 | 新增 shim exports/probe/lifecycle 的 PowerShell 驗證腳本,供 CI/Release 守門。 |
| tests/InputBox.Tests/README.md | 更新測試清單與覆蓋範圍說明(GameInput/shim 相關)。 |
| tests/InputBox.Tests/InputBox.Tests.csproj | 允許 unsafe 測試並更新 code coverage 套件版本。 |
| tests/InputBox.Tests/GamepadFaceButtonProfileTests.cs | 新增 VID/PID identity 下的 Auto 版面解析測試。 |
| tests/InputBox.Tests/GamepadDeadzoneHysteresisTests.cs | 新增 deadzone enter/exit 的正負方向對稱性守門測試。 |
| tests/InputBox.Tests/GamepadControllerPauseTests.cs | 補強 StopVibration、missing-reading、ClearAllEvents 等回歸測試。 |
| tests/InputBox.Tests/GamepadControllerFactoryTests.cs | 新增 GameInput 失敗退避至 XInput 的工廠策略測試。 |
| tests/InputBox.Tests/GameInputPrimitivesTests.cs | 新增 shim ABI/常數/exports/資料模型轉換等核心守門測試。 |
| src/InputBox/Program.cs | 將 DllImportResolver 改為統一解析控制器相關 native DLL(XInput + shim)。 |
| src/InputBox/MainForm.Gamepad.cs | 改用 GamepadControllerFactory 集中處理 GameInput 初始化與 XInput 退避。 |
| src/InputBox/InputBox.csproj | 引入 Microsoft.GameInput、加入 vcxproj 參考與 native shim 的 publish/build 複製規則。 |
| src/InputBox/Core/Services/PhraseService.cs | 匯出流程改用 PhrasePersistenceLock 包住序列化與寫檔,避免交錯。 |
| src/InputBox/Core/Interop/DllResolver.cs | 擴充 DLL resolver:新增 GameInput shim 的載入與 handle 快取。 |
| src/InputBox/Core/Input/XInputGamepadController.cs | 改用共用的 GamepadDeadzoneHysteresis.ResolveDirection,並補齊事件清理。 |
| src/InputBox/Core/Input/GamepadControllerFactory.cs | 新增集中化工廠:GameInput 失敗保留例外並退避 XInput。 |
| src/InputBox/Core/Input/GameInputPrimitives.cs | 新增 shim 受控端資料結構/enum/ABI metadata 定義。 |
| src/InputBox/Core/Input/GameInputNative.cs | 新增 shim P/Invoke、SafeHandle、runtime probe 與受控 wrapper。 |
| src/InputBox/Core/Input/GameInputGamepadController.cs | 以新 shim 後端重構讀取/診斷/missing reading 重列舉等邏輯。 |
| src/InputBox.GameInput.Native/README.md | 說明 shim 的範圍、ABI 規則、安全載入與驗證流程。 |
| src/InputBox.GameInput.Native/InputBoxGameInputNative.cpp | 新增 C++ shim:安全載入 GameInput runtime、窄版 ABI、診斷與 callback 管理。 |
| src/InputBox.GameInput.Native/InputBox.GameInput.Native.vcxproj | 新增 native shim 的 vcxproj(含 GameInput header 來源設定)。 |
| README.md | 更新發佈 ZIP 內含 GameInput redist 的「僅手動安裝」政策與第三方聲明。 |
| InputBox.slnx | 將 native shim 專案加入 solution。 |
| docs/engineering/gamepad-api.md | 更新 GameInput shim 的架構邊界、CI/Release 驗證規範與安全載入要求。 |
| docs/engineering/gameinput-hardware-verification.md | 新增正式發佈/高風險修改前的手動硬體驗證矩陣文件。 |
| .github/workflows/release.yml | Release 改為 windows runner;建置/驗證 shim;打包 redist + license/notice;ZIP 內容驗證。 |
| .github/workflows/ci.yml | CI code filter 納入 tools/**;新增 shim 建置與 Validate 腳本守門步驟。 |
Comments suppressed due to low confidence (1)
src/InputBox/Core/Interop/DllResolver.cs:42
- ResolveGameInputShim 目前用傳入的 libraryName 直接嘗試 TryLoad(libraryName) / TryLoad($"{libraryName}.dll")。當 libraryName 已經是 "InputBox.GameInput.Native.dll" 時,第二次嘗試會變成 "InputBox.GameInput.Native.dll.dll",且不會嘗試不含副檔名的候選,導致這個分支在遇到帶 .dll 的請求名稱時可能永遠載不到。建議先正規化名稱(去掉 .dll)或改成同時嘗試 {name} 與 {name}.dll(避免 .dll.dll)。
if (libraryName.Equals("InputBox.GameInput.Native", StringComparison.OrdinalIgnoreCase) ||
libraryName.Equals("InputBox.GameInput.Native.dll", StringComparison.OrdinalIgnoreCase))
{
return ResolveGameInputShim(libraryName, assembly, searchPath);
}
Agent-Logs-Url: https://github.com/rubujo/InputBox/sessions/817496c4-aaa2-40a9-8c11-8a704d99237a Co-authored-by: perditavojo <117562794+perditavojo@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces major improvements to the build and release workflow for handling the Microsoft GameInput Redistributable in the InputBox project. The changes ensure that the GameInput redist installer and its license files are bundled in release ZIPs for optional manual installation, update legal attributions, and strengthen packaging validation. The workflows are now more robust and compliant with Microsoft licensing requirements, and documentation has been updated to reflect these changes.
Build & Release Workflow Enhancements
GameInputRedist.msi) and its associated license/notice files into the release ZIP under aredist/directory. The workflow validates the presence and hash of these files, and updatesThirdPartyNotices.txtaccordingly. [1] [2] [3] [4]windows-latestto support native build steps and sets new environment variables for the native shim and GameInput redist hash. [1] [2]CI Workflow Updates
tools/**directory for code checks, and adds steps to build and validate the GameInput native shim, including reading and verifying the Microsoft.GameInput package version. [1] [2]Legal and Attribution Updates
Documentation Updates
README.mdhas been updated to clarify that the release ZIP includes the Microsoft GameInput Redistributable for manual installation only, and that InputBox does not auto-install it. Legal attributions for GameInput.Net, UsbVendorsLibrary, and usb.ids have been removed, replaced by an attribution for Microsoft GameInput Redistributable. [1] [2]Solution File Update
InputBox.slnx) now includes the native shim project for completeness.