diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 18ba7bb..8a0cefa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ jobs: name: MSVC x64 runs-on: windows-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 - name: Configure # No -G: CMake picks the newest Visual Studio on the runner image. @@ -24,8 +24,11 @@ jobs: - name: Stage the release layout run: cmake --install build --config Release --prefix stage/RemoteMouseFix-win-x64 + - name: Include MouseLookProbe in diagnostic artifact + run: Copy-Item build/bin/Release/MouseLookProbe.exe stage/RemoteMouseFix-win-x64/MouseLookProbe.exe + - name: Upload the build output - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v7 with: name: RemoteMouseFix-win-x64 path: stage/RemoteMouseFix-win-x64 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fd2fd8..573593e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,27 @@ correction is still experimental. ## [Unreleased] +### Added + +- A/B profile enables the optional 250 ms `## TIMING` summary for incoming deltas, + timer gaps, blocked anchor gates and queued movement. Normal playing remains unchanged. +- A/B diagnostic logs are isolated in `logs-ab/` with up to 50 retained files; + game logs remain in `logs/`. Back up original captures outside rotating folders. + + +- MouseLookProbe now provides visible/no-warp, hidden/no-warp and hidden/warp + modes to distinguish cursor hiding from cursor repositioning. The original + hidden/warp mode remains the default for automated regression testing. +- Both `Start-AB-Test.cmd` and `Start-Playing.cmd` read independent + targets from `[AB-Test]` and `[Playing]` in `RemoteMouseFix.ini`. + Select by executable filename or a full absolute path (exact process-image + match). Missing or invalid INI settings fail safely before correction. + The tool does not launch the configured game. +- The A/B console displays Ctrl+Alt+M, the number of markers written and all + correction/diagnostic hotkeys. +- The CI diagnostic artifact includes MouseLookProbe.exe for direct tests. + + ## [0.7.0] - 2026-09-21 ### Added diff --git a/CMakeLists.txt b/CMakeLists.txt index d4e08e7..1bfa8c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,6 +84,7 @@ add_custom_command(TARGET RemoteMouseFix POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/config/Start-AB-Test.cmd" "${CMAKE_SOURCE_DIR}/config/Start-Playing.cmd" + "${CMAKE_SOURCE_DIR}/config/RemoteMouseFix.ini" "$" COMMENT "Staging the shipped layout next to RemoteMouseFix.exe") @@ -108,6 +109,7 @@ install(TARGETS RemoteMouseFix InputEchoCheck RUNTIME DESTINATION .) install(FILES config/Start-AB-Test.cmd config/Start-Playing.cmd + config/RemoteMouseFix.ini README.md LICENSE DESTINATION .) install(FILES diff --git a/README.md b/README.md index c0a3062..2a81737 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,8 @@ in a folder of its own: README.md LICENSE config/ the three profiles docs/ diagnostic reference - logs/ created on the first start + logs/ created by Start-Playing.cmd + logs-ab/ created by Start-AB-Test.cmd ``` ### Windows warnings on first start @@ -79,27 +80,64 @@ colour repeats the answer: green means working, yellow means waiting for you, re the fix stopped itself. ```text - GAME * Wow.exe is in front + TARGET * Wow.exe is in front FIX * on (absolute) - correcting the pointer WORK 20 jumps seen, 51 corrections applied + MARK #2 Ctrl+Alt+M = mark the start of a test section in the log NEXT > Everything is working. Ctrl+Alt+C switches the fix off at any time. - KEYS Ctrl+Alt+1 fix on | Ctrl+Alt+C fix off | Ctrl+Alt+P pause log | Ctrl+Alt+Q quit + MODES Ctrl+Alt+1 absolute | Ctrl+Alt+2 relative | Ctrl+Alt+C OFF + KEYS Ctrl+Alt+M MARK | Ctrl+Alt+P pause log | Ctrl+Alt+Q quit ``` -`GAME` is yellow while the game is not running or while another window is in front: the -fix only works on the window you are actually playing in, so clicking into the game is -what turns this line green. `FIX` turns red when a watchdog switched the correction off, +`TARGET` in A/B mode (or `GAME` in the normal profile) is yellow while the +selected executable is not running or another window is in front. The fix only +works while that target window is in the foreground, so switching to it turns +the line green. `FIX` turns red when a watchdog switched the correction off, and then says why; that state stays on screen instead of scrolling away. `NEXT` always names the one thing to do next. Set `NO_COLOR=1` for a monochrome panel. When the output is redirected to a file, the panel is printed once per change instead of being repainted. +Both launchers read their own section of `RemoteMouseFix.ini` next to +`RemoteMouseFix.exe`: + +```ini +[AB-Test] +Executable=MouseLookProbe.exe + +[Playing] +Executable=C:\Games\World of Warcraft\Wow.exe +``` + +Use `Executable=Wow.exe` to match any running game process with that filename, +**regardless of its installation directory**. Alternatively supply a full +absolute Windows path to match **only that exact executable installation**. +Spaces in the path are supported. Enclosing the whole value in double quotes is optional; +Windows removes them when reading the INI. Your runtime test confirmed both forms. +Change the INI while the tool is stopped, save, and start the desired +`Start-AB-Test.cmd` or `Start-Playing.cmd` launcher as usual. No startup +question or JSON edit is needed. The shipped file uses `Wow.exe` for both +sections, and the settings persist across sessions. + +RemoteMouseFix **does not launch a game**. The path selects the process to +monitor and correct when the game is already running and in the foreground. +The selected target is shown as `TARGET` in A/B mode (or `GAME` in the +regular playing display). A missing INI or invalid target fails closed +before correction starts. The diagnostic-only profile remains unchanged. + +The A/B profile additionally shows the number of markers written so far and all +test hotkeys. Each press of `Ctrl+Alt+M` creates the next numbered `## MARKER #N` +entry. Keep a short note of what each marker represents; a marker identifies a +section boundary, not its meaning. An immediate notice confirms each marker. + ### Controls | Hotkey | Effect | | --- | --- | | `Ctrl+Alt+C` | switch the correction off immediately | +| `Ctrl+Alt+M` | add a numbered marker to the log | +| `Ctrl+Alt+P` | pause/resume logging (correction continues) | | `Ctrl+Alt+1` | enable the recommended `absolute` correction | | `Ctrl+Alt+2` | enable the alternative `relative` correction | | `Ctrl+Alt+Q` | quit RemoteMouseFix cleanly | @@ -126,13 +164,19 @@ can still add latency. ## Report a problem or test another setup -The A/B profile records detailed mouse movement for comparison. It never records keyboard -input or text, and it has no upload or network feature. You decide whether to share a log. +The A/B profile records detailed mouse movement and opt-in 250 ms timing summaries +(`## TIMING`) to distinguish missing remote input, irregular timers and +unsent movement gated by the cursor anchor. Test logs are written to `logs-ab/` +separately from normal-play `logs/`; up to 50 files are retained, but the +oldest still rotate out. Copy important captures into an archive outside the +rotating folders. The tool never records keyboard input or text, and it has no +upload or network feature. You decide whether to share a log. 1. Start the game and move to a quiet, safe location. 2. Double-click `Start-AB-Test.cmd` from the RemoteMouseFix folder. -3. Confirm that the console names `config-ab-test.json` and that the panel shows - `FIX` on with `absolute`, and `GAME` turning green when you click into the game. +3. Confirm that the console names `config-ab-test.json`, that `TARGET` shows + the executable from `[AB-Test]` in `RemoteMouseFix.ini`, and that `FIX` is on with `absolute`. + `TARGET` turns green when you click into the chosen application. 4. Test the same actions in each mode: `absolute`, `off`, then `relative`. Use `Ctrl+Alt+1`, `Ctrl+Alt+C` and `Ctrl+Alt+2` to select the modes. 5. Before every action, press `Ctrl+Alt+M` to add a marker to the log: @@ -141,7 +185,7 @@ input or text, and it has no upload or network feature. You decide whether to sh - hold the left mouse button and drag slowly. 6. Note for each mode whether the camera is smooth, jumps, or moves too fast or too slowly. 7. Press `Ctrl+Alt+C`, then `Ctrl+Alt+Q`. -8. Open the newest file in `logs` and check that its final lines report `queue drops 0` +8. Open the newest file in `logs-ab` and check that its final lines report `queue drops 0` and `watchdog trips 0`. 9. ZIP that log and attach it to a [GitHub issue](https://github.com/quasistatic-setup/RemoteMouseFix/issues/new) together @@ -242,13 +286,15 @@ Keys beginning with `_` in the supplied configuration files are explanatory comm | Key | Built-in default | Meaning | | --- | --- | --- | -| `target_process` | `Wow.exe` | executable to observe, matched case-insensitively | +| `target_process` | `Wow.exe` | fallback target name; the A/B and Playing profiles select their executable from `RemoteMouseFix.ini` | +| `target_ini_section` | empty | `AB-Test` or `Playing` enables that named section in `RemoteMouseFix.ini` for a name or full-path match | | `diagnostic_mode` | `true` | `true` prevents all correction; `false` permits correction modes | | `correction_mode` | `off` | startup mode: `off`, `absolute` or `relative` | | `watchdog_max_hidden_ms` | `180000` | hidden cursor duration before correction is disabled; `0` disables this check | | `watchdog_max_unechoed` | `50` | own events allowed outstanding before the echo watchdog trips | | `watchdog_max_output_failures` | `5` | consecutive failed output calls before the watchdog trips | | `log_mouse_moves` | `true` | `false` records buttons, wheel and state only | +| `trace_correction_timing` | `false` | opt-in 250 ms timer/anchor/pending-delta summaries; enabled in A/B profile | | `log_directory` | `logs` | relative paths resolve beside the EXE | | `log_file_prefix` | `remotemousefix` | log filename prefix | | `max_log_bytes` | `8388608` | rotate after this size | @@ -261,8 +307,9 @@ Keys beginning with `_` in the supplied configuration files are explanatory comm | `console_status_interval_ms` | `2000` | live console interval; `0` disables it | | `heartbeat_interval_ms` | `10000` | log heartbeat interval; `0` disables it | -Log files rotate by prefix. Copy a log you want to retain out of `logs` before taking many -further captures. +Log files rotate by prefix. The A/B profile uses `logs-ab/` (50 files maximum) and +normal playing uses `logs/` (5 files maximum). Copy any log you wish to preserve +into another folder before taking more captures. ## Build from source @@ -306,9 +353,26 @@ kind of input this check sends, so its filter, not the system, would decide the ## Developer test with MouseLookProbe -`MouseLookProbe.exe` reproduces the measured mouse-look mechanism without the game. It -hides the cursor on a button press, warps it to an off-centre anchor and records the summed -movement of each phase in `mouselook-probe.log`. +`MouseLookProbe.exe` has three selectable experiment modes to isolate why +TeamViewer pauses during mouse-look. The original hidden-cursor + warp behavior +remains the default, including for the automated script. + +| Probe mode | Cursor | Repeated `SetCursorPos` | Purpose | +| --- | --- | --- | --- | +| A – visible / no warp | visible | no | character-selection-like baseline | +| B – hidden / no warp | hidden | no | isolate cursor hiding | +| C – hidden + warp | hidden | yes | original WoW-like mouse-look simulation | + +Choose a radio button in the probe window before dragging. Hold the left or right +mouse button in the empty area, then release before switching modes. Modes A/B use +ordinary `GetCursorPos` deltas, so keep drags short to avoid the screen edge. +Each phase records its selected mode in `mouselook-probe.log`. The optional +`--mode visible|hidden|warp` selects the initial mode; `warp` is the default. + +Test A, B and C via TeamViewer first **without RemoteMouseFix targeting the probe**. +Pauses only in C suggest repeated cursor repositioning; pauses in B and C suggest +that hiding the cursor contributes. These are indicators rather than proof of +WoW behavior: the probe is only an approximation of the game's input loop. [tools/probe/emulate-remote.ps1](tools/probe/emulate-remote.ps1) starts both programs, injects a TeamViewer-shaped absolute stream and runs a click without motion, a steady drag diff --git a/config/RemoteMouseFix.ini b/config/RemoteMouseFix.ini new file mode 100644 index 0000000..ad9879b --- /dev/null +++ b/config/RemoteMouseFix.ini @@ -0,0 +1,13 @@ +; RemoteMouseFix target selection. Save changes before starting a launcher. +; Give the EXE filename OR a complete Windows path to the game EXE. +; A full path limits correction to the matching game installation. +; Quotation marks around the full value are optional; Windows strips them when reading. +; This tool does NOT launch the executable. +; Example: Executable=C:\Games\World of Warcraft\Wow.exe +; Example: Executable=D:\Games\AnotherGame\Game.exe + +[AB-Test] +Executable=Wow.exe + +[Playing] +Executable=Wow.exe diff --git a/config/Start-AB-Test.cmd b/config/Start-AB-Test.cmd index 0298090..25058c3 100644 --- a/config/Start-AB-Test.cmd +++ b/config/Start-AB-Test.cmd @@ -2,3 +2,8 @@ setlocal title RemoteMouseFix A/B correction test "%~dp0RemoteMouseFix.exe" "%~dp0config\config-ab-test.json" %* +if errorlevel 1 ( + echo. + echo RemoteMouseFix could not start. Review the error above. + pause +) diff --git a/config/Start-Playing.cmd b/config/Start-Playing.cmd index 4a35201..1b631bc 100644 --- a/config/Start-Playing.cmd +++ b/config/Start-Playing.cmd @@ -2,3 +2,8 @@ setlocal title RemoteMouseFix gameplay "%~dp0RemoteMouseFix.exe" "%~dp0config\config-play.json" %* +if errorlevel 1 ( + echo. + echo RemoteMouseFix could not start. Review the error above. + pause +) diff --git a/config/config-ab-test.json b/config/config-ab-test.json index f621a80..7c0483b 100644 --- a/config/config-ab-test.json +++ b/config/config-ab-test.json @@ -1,8 +1,10 @@ { "_about": "RemoteMouseFix A/B test configuration: absolute correction starts immediately and can be switched by hotkey. Keys starting with _ are comments.", - "_target_process": "Executable to observe, matched case-insensitively on the file name.", + "_target_process": "A/B target is set in [AB-Test] of RemoteMouseFix.ini beside the EXE.", "target_process": "Wow.exe", + "_target_ini_section": "Read the target from [AB-Test] in RemoteMouseFix.ini beside the EXE, supporting a filename or full executable path.", + "target_ini_section": "AB-Test", "_diagnostic_mode": "true: input is never modified and no correction mode can be enabled. false: correction modes become available (see config-ab-test.json).", "diagnostic_mode": false, @@ -10,6 +12,9 @@ "_log_mouse_moves": "false records buttons, wheel and state transitions only, which keeps logs small.", "log_mouse_moves": true, + "_show_ab_test_ui": "Show marker number and complete hotkeys in the A/B status panel.", + "show_ab_test_ui": true, + "_correction_mode": "Starts in absolute. Switch while running: Ctrl+Alt+1 absolute, Ctrl+Alt+2 relative, Ctrl+Alt+C off.", "correction_mode": "absolute", @@ -19,12 +24,12 @@ "watchdog_max_output_failures": 5, "_log_directory": "Relative paths resolve next to RemoteMouseFix.exe.", - "log_directory": "logs", + "log_directory": "logs-ab", "log_file_prefix": "remotemousefix", "_rotation": "Roll over past max_log_bytes and keep at most max_log_files files.", "max_log_bytes": 8388608, - "max_log_files": 5, + "max_log_files": 50, "_flush_on_button": "Flush after every button event so a crash still keeps the interesting moment.", "flush_on_button": true, @@ -38,6 +43,8 @@ "_state_poll_interval_ms": "Sampling period for cursor visibility, ClipCursor state and anchor learning.", "state_poll_interval_ms": 10, "log_state_changes": true, + "_trace_correction_timing": "Log 250 ms timing/anchor-gate summaries while absolute correction is active and the target holds the cursor.", + "trace_correction_timing": true, "_console_status_interval_ms": "Live counter refresh in the console. 0 disables it.", "console_status_interval_ms": 2000, diff --git a/config/config-play.json b/config/config-play.json index 7e15e5c..1506597 100644 --- a/config/config-play.json +++ b/config/config-play.json @@ -2,6 +2,8 @@ "_about": "RemoteMouseFix gameplay configuration: absolute correction starts immediately. Keys starting with _ are comments.", "target_process": "Wow.exe", + "_target_ini_section": "Read the target from [Playing] in RemoteMouseFix.ini beside the EXE, supporting a filename or full executable path.", + "target_ini_section": "Playing", "diagnostic_mode": false, "log_mouse_moves": false, "correction_mode": "absolute", diff --git a/docs/diagnostics.md b/docs/diagnostics.md index 6e4cd7a..01d5b8a 100644 --- a/docs/diagnostics.md +++ b/docs/diagnostics.md @@ -210,3 +210,95 @@ delta. `own seen` should track `applied` closely in both correction modes. mode the `OWN` position must equal `target`. In `relative` mode the `OWN` move's offset from the anchor (`anc=`) shows what pointer speed and acceleration made of `rd`; comparing the two measures the acceleration distortion directly. + +## MouseLookProbe three-mode comparison + +Select a radio button in `MouseLookProbe.exe` before holding the mouse button: +A = visible cursor with no `SetCursorPos`, B = hidden cursor without +`SetCursorPos`, C = hidden cursor with repeated `SetCursorPos` to an +off-centre anchor. C remains the old/default behavior. + +Perform comparable short drags over TeamViewer and release between modes. +In A/B the pointer can reach the screen edge. The probe records the +`mode=visible|hidden|warp` in each `LOOK-START` and `PHASE` line, plus a +`MODE` line on every selection change. Idle samples alone do not prove that +the operator continued moving their mouse. + +First run the probe without RemoteMouseFix correcting it. If later capturing +low-level input timing with RemoteMouseFix, set `Executable=MouseLookProbe.exe` under `[AB-Test]` in `RemoteMouseFix.ini` +and use an isolated log folder when preserving historical traces. This test compares cursor behavior; it does not establish that the +probe matches every detail of WoW's mouse input. + +### Selecting a target for A/B or normal playing + +Edit `RemoteMouseFix.ini` beside `RemoteMouseFix.exe`: + +```ini +[AB-Test] +Executable=MouseLookProbe.exe + +[Playing] +Executable=D:\Games\MyGame\Game.exe +``` + +Both sections ship with `Wow.exe` by default. `Start-AB-Test.cmd` uses +`[AB-Test]`, and `Start-Playing.cmd` uses `[Playing]`. A bare executable +filename matches the corresponding running process wherever it was installed. +A full absolute Windows image path (with or without enclosing quotes) matches only that specific installation +and prevents accidental cross-matching of similarly named games. The app does +**not launch** the selected EXE. No user prompt or JSON editing is required. +Missing/invalid INI fails safely before the mouse hook starts. +The diagnostic-only profile continues using its JSON target, and existing +foreground, hidden-cursor, injected-move-only and emergency-off checks remain. + +The name/path lookup is done in process enumeration and the PID cache, +not in the low-level hook, which continues to rely on a prevalidated foreground PID. + +## Opt-in timing trace for intermittent camera stalls + +The `Start-AB-Test.cmd` profile now sets `trace_correction_timing=true` and writes to +`logs-ab/` beside the executable (separate from the ordinary `logs/` gameplay +directory). The normal gameplay and diagnostic-only profiles leave this trace off. +`diagnostic_mode=true` is **not** the way to enable it: that setting locks all correction. + +With absolute correction active and the selected target holding the hidden cursor, the message loop writes +one aggregated `## TIMING` line approximately every 250 ms: + +```text +## TIMING qpc_ms=81234567 window_ms=256 ticks=16 max_timer_gap_ms=19 input=14 apply=13 skip=no_anchor:0,cursor:0,off_anchor:2,empty:1 pending=(10,0) pending_age_ms=87 input_age_ms=12 anchor_delta=(5,0) anchor=(803,554) cursor=(808,554) +``` + +- `qpc_ms` uses the same system clock as `APPLY qpc_ms`; `window_ms` is elapsed + time since the previous summary. These are diagnostics, **not frame times**. +- `ticks` counts received `WM_TIMER` callbacks, and `max_timer_gap_ms` is the + largest gap between consecutive callbacks in that window (including message-loop delays). +- `input` counts remote deltas posted by the hook to the message loop. Cross-reference + `DROP` events and their QPC timestamps in the same trace to distinguish missing + TeamViewer input from delayed processing. +- `apply` counts attempted output steps; successes/failures are in `APPLY` lines. +- `skip` counts timer cycles unable to emit because the anchor was not yet learned, + `GetCursorPos` failed, the cursor was outside the configured anchor tolerance, + or the final check had no movement pending. Anchor-related counts only include cycles with queued movement. +- `pending` is the unsent horizontal/vertical delta. `pending_age_ms` measures how long + movement has stayed continuously queued (an estimate of age, not the oldest pixel's age). + `input_age_ms` is the time since the last processed remote delta, or -1 before the + first observed delta in a held-cursor phase. +- `anchor_delta` is the last observed offset from the learned anchor; `anchor` and + `cursor` are the last measured screen coordinates. These values are from the last + timer check, not necessarily the same instant as the summary. + +No new logging takes place inside the mouse hook. The trace is a sampled aggregate, +not proof that the target consumed each injected move. Do not infer a cause merely from the +counts; compare them around visible stalls against `DROP`, `APPLY` and `OWN`. + +For a practical WoW test: start `Start-AB-Test.cmd`, leave `absolute` correction on, +mark the beginning with `Ctrl+Alt+M`, hold right-click and rotate slowly for 20–30 s +through several pauses, then quit with `Ctrl+Alt+Q`. Optionally mark and record a +short `off` reference with `Ctrl+Alt+C`; expect camera jumps without the fix. +Do not alter the smoothing or anchor tolerance for the measurement. + +**Keep historical evidence outside the rotating directory.** The A/B profile keeps up +to 50 files of 8 MiB in `logs-ab/` and still deletes the oldest matching files. +Before repeating tests, copy important captures into a separate folder that does not +contain the `remotemousefix-*.log` rotation target. Preserve the raw timestamps, and +do not commit session logs to Git. diff --git a/include/rmf/Config.h b/include/rmf/Config.h index 8d24c8a..d276ae7 100644 --- a/include/rmf/Config.h +++ b/include/rmf/Config.h @@ -17,6 +17,9 @@ struct Config { // false: correction modes become available; the tool still starts with correction_mode. bool diagnosticMode = true; bool logMouseMoves = true; // false logs buttons/wheel/state only + bool showAbTestUi = false; // only affects the status panel; no input changes + std::wstring targetIniSection; // AB-Test or Playing; empty = use JSON target + std::wstring targetPath; // optional exact image path (not just basename) // --- correction (only effective with diagnostic_mode = false) --- CorrectionMode correctionMode = CorrectionMode::Off; // mode at startup @@ -36,6 +39,7 @@ struct Config { int anchorTolerancePx = 3; // real move this close to the learned anchor => ANCHOR unsigned statePollIntervalMs = 10; // cursor visibility / clip / anchor sampling period bool logStateChanges = true; + bool traceCorrectionTiming = false; // opt-in timing trace for A/B tests unsigned consoleStatusIntervalMs = 2000; // 0 disables the live console status line unsigned heartbeatIntervalMs = 10000; // periodic liveness line, 0 disables it diff --git a/include/rmf/ProcessInfo.h b/include/rmf/ProcessInfo.h index 53e16a0..70d9692 100644 --- a/include/rmf/ProcessInfo.h +++ b/include/rmf/ProcessInfo.h @@ -12,7 +12,7 @@ namespace rmf { // foreground state alone cannot make, and the one users read wrong most often. // // Walks the process list, so it belongs on a slow timer, never in the hook callback. -bool IsProcessRunning(const std::wstring& imageFileName); +bool IsProcessRunning(const std::wstring& imageFileName, const std::wstring& fullImagePath = {}); // Caches PID -> image file name so the writer thread never pays for a process query // twice, and so the hook thread can take a fast "is this even the target" decision. @@ -22,7 +22,7 @@ bool IsProcessRunning(const std::wstring& imageFileName); // no longer matches. class ProcessNameCache { public: - explicit ProcessNameCache(std::wstring targetProcessName); + explicit ProcessNameCache(std::wstring targetProcessName, std::wstring fullImagePath = {}); // File name only (e.g. "Wow.exe"), or an empty string when it cannot be determined. const std::wstring& NameForPid(DWORD pid); @@ -47,6 +47,7 @@ class ProcessNameCache { Entry& Resolve(DWORD pid); std::wstring target_; + std::wstring targetPath_; std::unordered_map cache_; std::wstring empty_; bool sawAccessDenied_ = false; diff --git a/include/rmf/StatusView.h b/include/rmf/StatusView.h index ca6a0dd..903b617 100644 --- a/include/rmf/StatusView.h +++ b/include/rmf/StatusView.h @@ -41,6 +41,8 @@ struct StatusSnapshot { GameState game = GameState::NotRunning; bool loggingPaused = false; bool correctionAllowed = false; + bool abTestUi = false; + unsigned markers = 0; CorrectionMode mode = CorrectionMode::Off; // Plain-language reason why no correction can run at all this session, e.g. the diff --git a/src/Config.cpp b/src/Config.cpp index cc76042..5d5d12e 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -242,7 +242,10 @@ bool LoadConfig(const std::wstring& path, Config& cfg) { std::uint64_t u = 0; int i = 0; - if (key == L"target_process") { + if (key == L"target_ini_section") { + if (value == L"AB-Test" || value == L"Playing") cfg.targetIniSection = value; + else cfg.warnings.push_back(L"invalid target_ini_section (expected AB-Test or Playing): " + value); + } else if (key == L"target_process") { if (value.empty()) { cfg.warnings.push_back(L"target_process is empty, keeping " + cfg.targetProcess); } else { @@ -254,6 +257,9 @@ bool LoadConfig(const std::wstring& path, Config& cfg) { } else if (key == L"log_mouse_moves") { if (ParseBool(value, b)) cfg.logMouseMoves = b; else cfg.warnings.push_back(L"log_mouse_moves is not a boolean: " + value); + } else if (key == L"show_ab_test_ui") { + if (ParseBool(value, b)) cfg.showAbTestUi = b; + else cfg.warnings.push_back(L"show_ab_test_ui is not a boolean: " + value); } else if (key == L"log_directory") { cfg.logDirectory = value; } else if (key == L"log_file_prefix") { @@ -295,6 +301,9 @@ bool LoadConfig(const std::wstring& path, Config& cfg) { } else if (key == L"log_state_changes") { if (ParseBool(value, b)) cfg.logStateChanges = b; else cfg.warnings.push_back(L"log_state_changes is not a boolean: " + value); + } else if (key == L"trace_correction_timing") { + if (ParseBool(value, b)) cfg.traceCorrectionTiming = b; + else cfg.warnings.push_back(L"trace_correction_timing is not a boolean: " + value); } else if (key == L"console_status_interval_ms") { if (ParseU64(value, u) && u <= 60000) cfg.consoleStatusIntervalMs = static_cast(u); else cfg.warnings.push_back(L"console_status_interval_ms must be 0..60000: " + value); diff --git a/src/ProcessInfo.cpp b/src/ProcessInfo.cpp index ebad9a0..c198e95 100644 --- a/src/ProcessInfo.cpp +++ b/src/ProcessInfo.cpp @@ -34,7 +34,7 @@ bool GetProcessCreateTime(DWORD pid, FILETIME& out) { } // namespace -bool IsProcessRunning(const std::wstring& imageFileName) { +bool IsProcessRunning(const std::wstring& imageFileName, const std::wstring& fullImagePath) { if (imageFileName.empty()) { return false; } @@ -48,8 +48,17 @@ bool IsProcessRunning(const std::wstring& imageFileName) { if (Process32FirstW(snapshot, &entry)) { do { if (EqualsIgnoreCase(entry.szExeFile, imageFileName)) { - found = true; - break; + if (fullImagePath.empty()) { + found = true; + break; + } + std::wstring imagePath; + bool accessDenied = false; + if (QueryProcessImagePath(entry.th32ProcessID, imagePath, accessDenied) && + EqualsIgnoreCase(imagePath, fullImagePath)) { + found = true; + break; + } } } while (Process32NextW(snapshot, &entry)); } @@ -57,8 +66,8 @@ bool IsProcessRunning(const std::wstring& imageFileName) { return found; } -ProcessNameCache::ProcessNameCache(std::wstring targetProcessName) - : target_(std::move(targetProcessName)) {} +ProcessNameCache::ProcessNameCache(std::wstring targetProcessName, std::wstring fullImagePath) + : target_(std::move(targetProcessName)), targetPath_(std::move(fullImagePath)) {} ProcessNameCache::Entry& ProcessNameCache::Resolve(DWORD pid) { auto it = cache_.find(pid); @@ -87,7 +96,8 @@ ProcessNameCache::Entry& ProcessNameCache::Resolve(DWORD pid) { bool accessDenied = false; if (QueryProcessImagePath(pid, path, accessDenied)) { entry.name = FileNameOf(path); - entry.isTarget = EqualsIgnoreCase(entry.name, target_); + entry.isTarget = EqualsIgnoreCase(entry.name, target_) && + (targetPath_.empty() || EqualsIgnoreCase(path, targetPath_)); entry.haveCreateTime = GetProcessCreateTime(pid, entry.createTime); } else if (accessDenied) { sawAccessDenied_ = true; diff --git a/src/StatusView.cpp b/src/StatusView.cpp index c4e2fa0..f2a49a7 100644 --- a/src/StatusView.cpp +++ b/src/StatusView.cpp @@ -187,16 +187,17 @@ std::vector StatusView::Render() const { std::vector lines; - // ---- the game window ---------------------------------------------------------- + // ---- selected application ----------------------------------------------------- + const wchar_t* targetLabel = snapshot_.abTestUi ? L"TARGET" : L"GAME "; switch (snapshot_.game) { case GameState::NotRunning: - lines.push_back({yellow, L" GAME o " + game + L" is not running yet"}); + lines.push_back({yellow, std::wstring(L" ") + targetLabel + L" o " + game + L" is not running yet"}); break; case GameState::Background: - lines.push_back({yellow, L" GAME o " + game + L" is running, but another window is in front"}); + lines.push_back({yellow, std::wstring(L" ") + targetLabel + L" o " + game + L" is running, but another window is in front"}); break; case GameState::Foreground: - lines.push_back({green, L" GAME * " + game + L" is in front"}); + lines.push_back({green, std::wstring(L" ") + targetLabel + L" * " + game + L" is in front"}); break; } @@ -228,6 +229,11 @@ std::vector StatusView::Render() const { } lines.push_back({snapshot_.problems > 0 ? yellow : grey, work}); + if (snapshot_.abTestUi) { + lines.push_back({grey, L" MARK #" + std::to_wstring(snapshot_.markers) + + L" Ctrl+Alt+M = mark the start of a test section in the log"}); + } + // ---- the one line that says what to do next ------------------------------------- std::wstring hint; const wchar_t* hintColour = grey; @@ -237,9 +243,11 @@ std::vector StatusView::Render() const { } else if (locked) { hint = L"Nothing is being changed. Start-AB-Test.cmd is the profile that corrects."; } else if (snapshot_.game == GameState::NotRunning) { - hint = L"Start the game now. This panel follows along."; + hint = snapshot_.abTestUi ? L"Start the selected application now." + : L"Start the game now. This panel follows along."; } else if (!inFront) { - hint = L"Click into the game window; the top line turns green."; + hint = snapshot_.abTestUi ? L"Click into the target window; the top line turns green." + : L"Click into the game window; the top line turns green."; } else if (!correcting) { hint = L"Press Ctrl+Alt+1 to switch the fix on."; } else if (snapshot_.corrections == 0) { @@ -249,11 +257,14 @@ std::vector StatusView::Render() const { } lines.push_back({hintColour, L" NEXT > " + hint}); - lines.push_back({grey, snapshot_.correctionAllowed - ? L" KEYS Ctrl+Alt+1 fix on | Ctrl+Alt+C fix off | " - L"Ctrl+Alt+P pause log | Ctrl+Alt+Q quit" - : L" KEYS Ctrl+Alt+M mark the log | Ctrl+Alt+P pause log | " - L"Ctrl+Alt+Q quit"}); + if (snapshot_.abTestUi) { + lines.push_back({grey, L" MODES Ctrl+Alt+1 absolute | Ctrl+Alt+2 relative | Ctrl+Alt+C OFF"}); + lines.push_back({grey, L" KEYS Ctrl+Alt+M MARK | Ctrl+Alt+P pause log | Ctrl+Alt+Q quit"}); + } else { + lines.push_back({grey, snapshot_.correctionAllowed + ? L" KEYS Ctrl+Alt+1 fix on | Ctrl+Alt+2 relative | Ctrl+Alt+C fix off" + : L" KEYS Ctrl+Alt+M mark log | Ctrl+Alt+P pause log | Ctrl+Alt+Q quit"}); + } return lines; } diff --git a/src/main.cpp b/src/main.cpp index 0143191..b9b6092 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -219,7 +219,8 @@ int main() { if (arg == L"--help" || arg == L"-h" || arg == L"/?") { ConsoleOut(L"RemoteMouseFix %ls - diagnostics with optional correction\n\n" L"Usage: RemoteMouseFix.exe [path\\to\\config.json] [--seconds N]\n\n" - L" --seconds N stop automatically after N seconds (0 = run until stopped)\n\n" + L" --seconds N stop automatically after N seconds (0 = run until stopped)\n" + L" A/B and Playing targets are read from RemoteMouseFix.ini.\n\n" L"Hotkeys while running:\n" L" Ctrl+Alt+M write a marker line into the log\n" L" Ctrl+Alt+P pause / resume logging (correction keeps running)\n" @@ -261,6 +262,73 @@ int main() { rmf::Config cfg; rmf::LoadConfig(configPath, cfg); + // Each gameplay profile opts into its own section of the common INI. A full + // path is matched against the running process image, not used to launch it. + // Missing/invalid INI fails closed before installing a mouse hook. + if (!cfg.targetIniSection.empty()) { + const std::wstring iniPath = rmf::ResolveAgainstExeDir(L"RemoteMouseFix.ini"); + if (!FileExists(iniPath)) { + ConsoleOut(L"ERROR: RemoteMouseFix.ini is missing beside RemoteMouseFix.exe.\n" + L" Restore it from the package; no correction started.\n"); + return 2; + } + wchar_t selected[32768] {}; + const DWORD len = GetPrivateProfileStringW(cfg.targetIniSection.c_str(), + L"Executable", L"", selected, 32768, iniPath.c_str()); + const std::wstring target(selected, static_cast(len)); + if (target.empty() || len >= 32767) { + ConsoleOut(L"ERROR: [%ls] Executable in RemoteMouseFix.ini is missing or too long.\n", + cfg.targetIniSection.c_str()); + return 2; + } + const bool invalidCharacters = std::any_of(target.begin(), target.end(), [](wchar_t ch) { + return ch < 32 || ch == L'<' || ch == L'>' || ch == L'"' || + ch == L'|' || ch == L'?' || ch == L'*'; + }); + const bool hasPathSeparator = target.find_first_of(L"\\/") != std::wstring::npos; + const bool absoluteDrivePath = + target.size() >= 6 && ((target[0] >= L'A' && target[0] <= L'Z') || + (target[0] >= L'a' && target[0] <= L'z')) && + target[1] == L':' && (target[2] == L'\\' || target[2] == L'/'); + const bool uncPath = target.size() >= 7 && + (target[0] == L'\\' || target[0] == L'/') && + (target[1] == L'\\' || target[1] == L'/'); + const bool hasPath = hasPathSeparator || target.find(L':') != std::wstring::npos; + if (invalidCharacters || target.front() == L' ' || target.back() == L' ' || + (hasPath && !(absoluteDrivePath || uncPath)) || target.back() == L'\\' || + target.back() == L'/') { + ConsoleOut(L"ERROR: invalid [%ls] Executable in RemoteMouseFix.ini.\n" + L" Use Name.exe or a full absolute path such as C:\\Games\\MyGame.exe.\n", + cfg.targetIniSection.c_str()); + return 2; + } + std::wstring filename = target; + if (hasPath) { + // Normalize relative components such as ".." in a configured absolute path. + std::wstring expanded(32768, L'\0'); + const DWORD size = GetFullPathNameW(target.c_str(), + static_cast(expanded.size()), expanded.data(), nullptr); + if (size == 0 || size >= expanded.size()) { + ConsoleOut(L"ERROR: cannot resolve target path in RemoteMouseFix.ini.\n"); + return 2; + } + expanded.resize(size); + std::replace(expanded.begin(), expanded.end(), L'/', L'\\'); + cfg.targetPath = std::move(expanded); + filename = cfg.targetPath.substr(cfg.targetPath.find_last_of(L"\\/") + 1); + } + if (filename.size() < 5 || + CompareStringOrdinal(filename.c_str() + filename.size() - 4, 4, + L".exe", 4, TRUE) != CSTR_EQUAL || + filename.find_first_of(L":\\/") != std::wstring::npos) { + ConsoleOut(L"ERROR: [%ls] target must end with an .exe filename.\n", + cfg.targetIniSection.c_str()); + return 2; + } + cfg.targetProcess = filename; + ConsoleOut(L" target from [%ls]: %ls\n", cfg.targetIniSection.c_str(), target.c_str()); + } + SetConsoleTitleW(cfg.diagnosticMode ? L"RemoteMouseFix " RMF_VERSION_W L" - DIAGNOSTIC ONLY" : L"RemoteMouseFix " RMF_VERSION_W L" - A/B CORRECTION TEST"); @@ -345,7 +413,9 @@ int main() { header.push_back(L"# elevated : " + std::wstring(elevated ? L"yes" : L"no")); header.push_back(L"# config file : " + (cfg.loadedFrom.empty() ? L"" : cfg.loadedFrom)); header.push_back(L"# target process : " + cfg.targetProcess); + if (!cfg.targetPath.empty()) header.push_back(L"# target image : " + cfg.targetPath); header.push_back(L"# log mouse moves: " + std::wstring(cfg.logMouseMoves ? L"yes" : L"no")); + header.push_back(L"# A/B panel : " + std::wstring(cfg.showAbTestUi ? L"on" : L"off")); header.push_back(L"# diagnostic mode: " + std::wstring(cfg.diagnosticMode ? L"yes" : L"no")); header.push_back(L"# correction : " + (correction.allowed @@ -358,6 +428,8 @@ int main() { cfg.jumpThresholdPx, cfg.anchorTolerancePx, cfg.statePollIntervalMs)); header.push_back(Format(L"# smoothing : absolute only, interval=%ums max_step=%ldpx", kSmoothIntervalMs, kSmoothMaxStepPx)); + header.push_back(L"# timing trace : " + + std::wstring(cfg.traceCorrectionTiming ? L"on (250ms windows)" : L"off")); header.push_back(Format(L"# heartbeat : every %u ms (0 = off)", cfg.heartbeatIntervalMs)); header.push_back(Format(L"# rotation : %llu bytes, keep %u files", static_cast(cfg.maxLogBytes), cfg.maxLogFiles)); @@ -397,6 +469,7 @@ int main() { } ConsoleOut(L" target process : %ls\n", cfg.targetProcess.c_str()); + if (!cfg.targetPath.empty()) ConsoleOut(L" target image : %ls\n", cfg.targetPath.c_str()); ConsoleOut(L" config file : %ls\n", cfg.loadedFrom.empty() ? L"" : cfg.loadedFrom.c_str()); ConsoleOut(L" run profile : %ls\n", @@ -418,8 +491,9 @@ int main() { rmf::StatusSnapshot initial; initial.targetProcess = cfg.targetProcess; initial.correctionAllowed = correction.allowed; + initial.abTestUi = cfg.showAbTestUi; initial.lockReason = lockHint; - initial.game = rmf::IsProcessRunning(cfg.targetProcess) + initial.game = rmf::IsProcessRunning(cfg.targetProcess, cfg.targetPath) ? rmf::GameState::Background : rmf::GameState::NotRunning; panel.Start(cfg.consoleStatusIntervalMs > 0, initial); @@ -452,7 +526,7 @@ int main() { }; // ---- state sampler ----------------------------------------------------------------- - rmf::ProcessNameCache samplerNames(cfg.targetProcess); + rmf::ProcessNameCache samplerNames(cfg.targetProcess, cfg.targetPath); std::atomic targetInForeground {false}; std::atomic cursorHeldByTarget {false}; @@ -620,9 +694,10 @@ int main() { std::atomic anchorCount {0}; std::atomic jumpCount {0}; std::atomic injectedCount {0}; + std::atomic markerCount {0}; std::thread writer([&] { - rmf::ProcessNameCache names(cfg.targetProcess); + rmf::ProcessNameCache names(cfg.targetProcess, cfg.targetPath); POINT previousPt {0, 0}; bool havePrevious = false; @@ -733,6 +808,8 @@ int main() { snap.targetProcess = cfg.targetProcess; snap.loggingPaused = filter.paused.load(); snap.correctionAllowed = correction.allowed; + snap.abTestUi = cfg.showAbTestUi; + snap.markers = markerCount.load(std::memory_order_relaxed); snap.mode = correction.Mode(); snap.lockReason = lockHint; { @@ -747,7 +824,7 @@ int main() { // "has the game been started at all" changes slowly. const ULONGLONG tick = GetTickCount64(); if (lastProcessScan == 0 || tick - lastProcessScan >= 2000) { - gameRunning = rmf::IsProcessRunning(cfg.targetProcess); + gameRunning = rmf::IsProcessRunning(cfg.targetProcess, cfg.targetPath); lastProcessScan = tick; } snap.game = gameRunning ? rmf::GameState::Background : rmf::GameState::NotRunning; @@ -817,10 +894,38 @@ int main() { // ---- message loop -------------------------------------------------------------------- // WH_MOUSE_LL callbacks are delivered on this thread, so this loop drives the hook and // must stay responsive. It also executes the correction output posted by the hook. - unsigned markerCounter = 0; long long smoothPendingX = 0; long long smoothPendingY = 0; + // Opt-in A/B diagnostics. These counters belong to the message-loop thread; the + // mouse hook does no additional work and logging is limited to one summary per 250 ms. + struct TimingWindow { + unsigned timerTicks = 0; + unsigned incoming = 0; + unsigned outputAttempts = 0; + unsigned missingAnchor = 0; + unsigned cursorReadFailed = 0; + unsigned offAnchor = 0; + unsigned emptyPending = 0; + std::uint64_t maxTimerGapMs = 0; + long lastAnchorDx = 0; + long lastAnchorDy = 0; + POINT lastCursor {0, 0}; + POINT lastAnchor {0, 0}; + } timing; + std::uint64_t timingLastTickMs = 0; + std::uint64_t timingLastReportMs = 0; + std::uint64_t timingLastInputMs = 0; + std::uint64_t timingPendingSinceMs = 0; + + auto qpcNowMs = [&]() -> std::uint64_t { + LARGE_INTEGER now {}; + QueryPerformanceCounter(&now); + // Split before multiplying to avoid overflow during long system uptimes. + return static_cast(now.QuadPart / qpcFreq) * 1000 + + static_cast((now.QuadPart % qpcFreq) * 1000 / qpcFreq); + }; + auto applyDelta = [&](rmf::CorrectionMode mode, long dx, long dy) { POINT before {}; GetCursorPos(&before); @@ -890,7 +995,14 @@ int main() { } const long dx = static_cast(static_cast(msg.wParam)); const long dy = static_cast(static_cast(msg.lParam)); + if (cfg.traceCorrectionTiming && mode == rmf::CorrectionMode::Absolute) { + ++timing.incoming; + timingLastInputMs = qpcNowMs(); + } if (mode == rmf::CorrectionMode::Absolute && smoothTimerId != 0) { + if (cfg.traceCorrectionTiming && smoothPendingX == 0 && smoothPendingY == 0) { + timingPendingSinceMs = qpcNowMs(); + } auto retargetAxis = [&](long long& pending, long incoming, wchar_t axis) { constexpr long kRetargetMinPx = 5; const bool reversed = @@ -907,6 +1019,9 @@ int main() { retargetAxis(smoothPendingY, dy, L'y'); smoothPendingX += dx; smoothPendingY += dy; + if (cfg.traceCorrectionTiming && smoothPendingX == 0 && smoothPendingY == 0) { + timingPendingSinceMs = 0; + } } else { applyDelta(mode, dx, dy); } @@ -914,6 +1029,48 @@ int main() { } if (msg.message == WM_TIMER && msg.wParam == smoothTimerId) { + if (cfg.traceCorrectionTiming) { + const bool active = correction.Mode() == rmf::CorrectionMode::Absolute && + cursorHeldByTarget.load(std::memory_order_relaxed); + if (!active) { + timing = TimingWindow{}; + timingLastTickMs = 0; + timingLastReportMs = 0; + timingLastInputMs = 0; + timingPendingSinceMs = 0; + } else { + const std::uint64_t nowMs = qpcNowMs(); + if (timingLastReportMs == 0) timingLastReportMs = nowMs; + if (timingLastTickMs != 0) { + timing.maxTimerGapMs = std::max(timing.maxTimerGapMs, nowMs - timingLastTickMs); + } + timingLastTickMs = nowMs; + ++timing.timerTicks; + if (nowMs - timingLastReportMs >= 250) { + const auto inputAge = timingLastInputMs == 0 ? -1LL : + static_cast(nowMs - timingLastInputMs); + const auto pendingAge = timingPendingSinceMs == 0 ? 0ULL : + static_cast(nowMs - timingPendingSinceMs); + LogLine(Format( + L"## TIMING qpc_ms=%llu window_ms=%llu ticks=%u max_timer_gap_ms=%llu " + L"input=%u apply=%u skip=no_anchor:%u,cursor:%u,off_anchor:%u,empty:%u " + L"pending=(%lld,%lld) pending_age_ms=%llu input_age_ms=%lld " + L"anchor_delta=(%ld,%ld) anchor=(%ld,%ld) cursor=(%ld,%ld)", + static_cast(nowMs), + static_cast(nowMs - timingLastReportMs), + timing.timerTicks, + static_cast(timing.maxTimerGapMs), + timing.incoming, timing.outputAttempts, timing.missingAnchor, + timing.cursorReadFailed, timing.offAnchor, timing.emptyPending, + smoothPendingX, smoothPendingY, pendingAge, inputAge, + timing.lastAnchorDx, timing.lastAnchorDy, + timing.lastAnchor.x, timing.lastAnchor.y, + timing.lastCursor.x, timing.lastCursor.y)); + timing = TimingWindow{}; + timingLastReportMs = nowMs; + } + } + } if (correction.Mode() != rmf::CorrectionMode::Absolute || !cursorHeldByTarget.load(std::memory_order_relaxed)) { smoothPendingX = 0; @@ -925,19 +1082,28 @@ int main() { // camera motion. The learned anchor is the proof that the previous step was // read and the game warped back. if (!filter.anchorValid.load(std::memory_order_relaxed)) { + if (cfg.traceCorrectionTiming && (smoothPendingX || smoothPendingY)) ++timing.missingAnchor; continue; } const rmf::StateSampler::Snapshot snap = sampler.Current(); POINT current {}; if (!GetCursorPos(¤t)) { + if (cfg.traceCorrectionTiming && (smoothPendingX || smoothPendingY)) ++timing.cursorReadFailed; continue; } const long anchorX = snap.clientScreenRect.left + filter.anchorOffsetX.load(std::memory_order_relaxed); const long anchorY = snap.clientScreenRect.top + filter.anchorOffsetY.load(std::memory_order_relaxed); + if (cfg.traceCorrectionTiming) { + timing.lastCursor = current; + timing.lastAnchor = POINT{anchorX, anchorY}; + timing.lastAnchorDx = current.x - anchorX; + timing.lastAnchorDy = current.y - anchorY; + } if (std::abs(current.x - anchorX) > cfg.anchorTolerancePx || std::abs(current.y - anchorY) > cfg.anchorTolerancePx) { + if (cfg.traceCorrectionTiming && (smoothPendingX || smoothPendingY)) ++timing.offAnchor; continue; } const long dx = static_cast(std::clamp( @@ -949,7 +1115,13 @@ int main() { if (dx != 0 || dy != 0) { smoothPendingX -= dx; smoothPendingY -= dy; + if (cfg.traceCorrectionTiming) { + ++timing.outputAttempts; + if (smoothPendingX == 0 && smoothPendingY == 0) timingPendingSinceMs = 0; + } applyDelta(rmf::CorrectionMode::Absolute, dx, dy); + } else if (cfg.traceCorrectionTiming) { + ++timing.emptyPending; } continue; } @@ -957,16 +1129,16 @@ int main() { if (msg.message == WM_HOTKEY) { switch (static_cast(msg.wParam)) { case kHotkeyMarker: { - ++markerCounter; + const unsigned markerNumber = markerCount.fetch_add(1, std::memory_order_relaxed) + 1; const rmf::StateSampler::Snapshot snap = sampler.Current(); LogLine(Format(L"## MARKER #%u at cursor=(%ld,%ld) cursor_visible=%ls clip=%ls correction=%ls", - markerCounter, snap.cursorPos.x, snap.cursorPos.y, + markerNumber, snap.cursorPos.x, snap.cursorPos.y, snap.cursorVisible ? L"yes" : L"no", snap.clipIsFullScreen ? L"released" : L"CONFINED", modeLabel())); FlushLog(); panel.Notice(rmf::NoticeLevel::Info, - Format(L"marker #%u written to the log", markerCounter)); + Format(L"marker #%u written to the log", markerNumber)); break; } case kHotkeyPause: { diff --git a/tools/probe/MouseLookProbe.cpp b/tools/probe/MouseLookProbe.cpp index 9b71af1..a3fdeba 100644 --- a/tools/probe/MouseLookProbe.cpp +++ b/tools/probe/MouseLookProbe.cpp @@ -1,10 +1,9 @@ // MouseLookProbe - stand-in for a game's mouse-look loop, used to test RemoteMouseFix // without the game. // -// It reproduces the mechanism measured in WoW 3.3.5a (docs/findings-2026-09-12.md): on a -// button press it hides the cursor and warps it to a fixed, deliberately off-centre -// anchor; on a timer it reads the distance from that anchor as camera movement and warps -// back; on release it restores the cursor. Every phase is summarised in a log file. +// The original mode reproduces the WoW 3.3.5a cursor-warp mechanism +// (docs/findings-2026-09-12.md). Two additional modes isolate cursor visibility +// from cursor warping to compare TeamViewer behavior. All phases are logged. // // It reads the pointer through GetCursorPos. A game reading Raw Input would behave // differently, so a pass here proves the correction logic, not compatibility with a @@ -32,6 +31,31 @@ constexpr UINT_PTR kTimerQuit = 2; constexpr UINT kLookPeriodMs = 10; // clamped to the ~15.6 ms timer tick, about a game frame constexpr long kJumpPx = 40; +// Each mode isolates a part of the input path. The original warp mode remains +// the default, including for existing scripted regression tests. +enum class ProbeMode { Visible, Hidden, Warp }; +constexpr int kModeVisibleId = 1001; +constexpr int kModeHiddenId = 1002; +constexpr int kModeWarpId = 1003; + +const wchar_t* ModeName(ProbeMode mode) { + switch (mode) { + case ProbeMode::Visible: return L"A: visible / no warp"; + case ProbeMode::Hidden: return L"B: hidden / no warp"; + case ProbeMode::Warp: return L"C: hidden + warp (WoW-like)"; + } + return L"unknown"; +} + +const char* ModeKey(ProbeMode mode) { + switch (mode) { + case ProbeMode::Visible: return "visible"; + case ProbeMode::Hidden: return "hidden"; + case ProbeMode::Warp: return "warp"; + } + return "unknown"; +} + struct Phase { int number = 0; wchar_t button = L'?'; @@ -45,6 +69,9 @@ struct Phase { }; HWND g_window = nullptr; +HWND g_modeButtons[3] {nullptr, nullptr, nullptr}; +ProbeMode g_mode = ProbeMode::Warp; +POINT g_previousPoint {0, 0}; FILE* g_log = nullptr; bool g_looking = false; int g_buttons = 0; @@ -81,7 +108,8 @@ POINT AnchorScreen() { return anchor; } -// One "frame" of mouse-look: read the offset from the anchor, consume it, warp back. +// One sample: modes A/B read ordinary pointer deltas; mode C reads from its +// anchor and warps back as the game's camera loop does. long long QpcMs() { LARGE_INTEGER now {}; QueryPerformanceCounter(&now); @@ -94,9 +122,10 @@ void Sample() { return; } const long long readMs = QpcMs(); - const POINT anchor = AnchorScreen(); - const long dx = cursor.x - anchor.x; - const long dy = cursor.y - anchor.y; + const POINT reference = g_mode == ProbeMode::Warp ? AnchorScreen() : g_previousPoint; + const long dx = cursor.x - reference.x; + const long dy = cursor.y - reference.y; + if (g_mode != ProbeMode::Warp) g_previousPoint = cursor; ++g_phase.ticks; if (dx == 0 && dy == 0) { // Idle ticks are traced too: when a pointer update goes missing, the question is @@ -116,7 +145,7 @@ void Sample() { // Warp back immediately after reading, as a game loop does. Anything slow between the // read and the warp (logging, file flushes) would widen the window in which a pointer // update is overwritten, and make the probe report losses a real game would not have. - SetCursorPos(anchor.x, anchor.y); + if (g_mode == ProbeMode::Warp) SetCursorPos(reference.x, reference.y); g_yaw += dx; g_pitch += dy; LogF("%10.3f tick d=(%+ld,%+ld) cur=(%ld,%ld) qpc_ms=%lld%s\n", Elapsed(), dx, dy, @@ -125,12 +154,16 @@ void Sample() { void StartLook(wchar_t button) { GetCursorPos(&g_restore); - while (ShowCursor(FALSE) >= 0) { + g_previousPoint = g_restore; + if (g_mode != ProbeMode::Visible) { + while (ShowCursor(FALSE) >= 0) { + } } SetCapture(g_window); const POINT anchor = AnchorScreen(); - SetCursorPos(anchor.x, anchor.y); + if (g_mode == ProbeMode::Warp) SetCursorPos(anchor.x, anchor.y); + for (HWND buttonControl : g_modeButtons) EnableWindow(buttonControl, FALSE); g_looking = true; g_phase = Phase{}; @@ -139,8 +172,9 @@ void StartLook(wchar_t button) { g_phase.startTick = GetTickCount64(); SetTimer(g_window, kTimerLook, kLookPeriodMs, nullptr); - LogF("%10.3f LOOK-START #%d button=%lc restore=(%ld,%ld) anchor=(%ld,%ld)\n", - Elapsed(), g_phase.number, button, g_restore.x, g_restore.y, anchor.x, anchor.y); + LogF("%10.3f LOOK-START #%d button=%lc mode=%s restore=(%ld,%ld) anchor=(%ld,%ld)\n", + Elapsed(), g_phase.number, button, ModeKey(g_mode), g_restore.x, g_restore.y, + anchor.x, anchor.y); } void EndLook() { @@ -151,20 +185,26 @@ void EndLook() { g_looking = false; KillTimer(g_window, kTimerLook); - SetCursorPos(g_restore.x, g_restore.y); - while (ShowCursor(TRUE) < 0) { + // In mode A the visible cursor must continue normally after the drag. + if (g_mode != ProbeMode::Visible) { + SetCursorPos(g_restore.x, g_restore.y); + while (ShowCursor(TRUE) < 0) { + } } ReleaseCapture(); + for (HWND buttonControl : g_modeButtons) EnableWindow(buttonControl, TRUE); const ULONGLONG duration = GetTickCount64() - g_phase.startTick; - LogF("%10.3f PHASE #%d button=%lc ticks=%u motion_ticks=%u sum=(%+ld,%+ld) max_tick=%ld jumps40=%u duration_ms=%llu\n", - Elapsed(), g_phase.number, g_phase.button, g_phase.ticks, g_phase.motionTicks, + LogF("%10.3f PHASE #%d button=%lc mode=%s ticks=%u motion_ticks=%u sum=(%+ld,%+ld) max_tick=%ld jumps40=%u duration_ms=%llu\n", + Elapsed(), g_phase.number, g_phase.button, ModeKey(g_mode), + g_phase.ticks, g_phase.motionTicks, g_phase.sumX, g_phase.sumY, g_phase.maxTick, g_phase.jumps, static_cast(duration)); wchar_t buffer[256]; - swprintf(buffer, 256, L"#%d %lc: sum=(%+ld,%+ld) max_tick=%ld jumps=%u", - g_phase.number, g_phase.button, g_phase.sumX, g_phase.sumY, g_phase.maxTick, g_phase.jumps); + swprintf(buffer, 256, L"#%d %lc %ls: sum=(%+ld,%+ld) max_tick=%ld jumps=%u", + g_phase.number, g_phase.button, ModeName(g_mode), g_phase.sumX, + g_phase.sumY, g_phase.maxTick, g_phase.jumps); g_lastSummary = buffer; InvalidateRect(g_window, nullptr, TRUE); } @@ -192,25 +232,40 @@ void Paint(HWND hwnd) { wchar_t text[512]; swprintf(text, 512, - L"MouseLookProbe - stand-in for a game mouse-look loop\n\n" - L"Hold the left or right mouse button in this window to turn the camera.\n" + L"MouseLookProbe - TeamViewer input comparison\n\n" + L"Selected: %ls\n" + L"Hold left/right mouse button in the empty area to drag.\n" + L"Complete a short drag, release, then select another mode.\n" + L"Modes A/B have no cursor recentering; stop before screen edges.\n\n" L"yaw=%ld pitch=%ld phases=%d\n" L"last phase: %ls\n\n" L"Esc closes.", - g_yaw, g_pitch, g_phaseCount, g_lastSummary.c_str()); - RECT textRect {20, 20, client.right - 20, client.bottom - 20}; + ModeName(g_mode), g_yaw, g_pitch, g_phaseCount, g_lastSummary.c_str()); + RECT textRect {20, 150, client.right - 20, client.bottom - 20}; DrawTextW(dc, text, -1, &textRect, DT_LEFT | DT_TOP); - // Mark the anchor so a human tester can see where the warp goes. - MoveToEx(dc, kAnchorOffset.x - 10, kAnchorOffset.y, nullptr); - LineTo(dc, kAnchorOffset.x + 11, kAnchorOffset.y); - MoveToEx(dc, kAnchorOffset.x, kAnchorOffset.y - 10, nullptr); - LineTo(dc, kAnchorOffset.x, kAnchorOffset.y + 11); + // The cross is meaningful only in the legacy warp test mode. + if (g_mode == ProbeMode::Warp) { + MoveToEx(dc, kAnchorOffset.x - 10, kAnchorOffset.y, nullptr); + LineTo(dc, kAnchorOffset.x + 11, kAnchorOffset.y); + MoveToEx(dc, kAnchorOffset.x, kAnchorOffset.y - 10, nullptr); + LineTo(dc, kAnchorOffset.x, kAnchorOffset.y + 11); + } EndPaint(hwnd, &ps); } LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { + case WM_COMMAND: + if (HIWORD(wParam) == BN_CLICKED && !g_looking) { + if (LOWORD(wParam) == kModeVisibleId) g_mode = ProbeMode::Visible; + else if (LOWORD(wParam) == kModeHiddenId) g_mode = ProbeMode::Hidden; + else if (LOWORD(wParam) == kModeWarpId) g_mode = ProbeMode::Warp; + else return 0; + LogF("%10.3f MODE %s\n", Elapsed(), ModeKey(g_mode)); + InvalidateRect(hwnd, nullptr, TRUE); + } + return 0; case WM_LBUTTONDOWN: OnButtonDown(1, L'L'); return 0; case WM_RBUTTONDOWN: OnButtonDown(2, L'R'); return 0; case WM_LBUTTONUP: OnButtonUp(1); return 0; @@ -266,6 +321,17 @@ int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int showCommand) { quitSeconds = static_cast(std::max(0L, std::wcstol(argv[++i], nullptr, 10))); } else if (arg == L"--log") { logPath = argv[++i]; + } else if (arg == L"--mode") { + const std::wstring value = argv[++i]; + if (value == L"visible") g_mode = ProbeMode::Visible; + else if (value == L"hidden") g_mode = ProbeMode::Hidden; + else if (value == L"warp") g_mode = ProbeMode::Warp; + else { + LocalFree(argv); + MessageBoxW(nullptr, L"Use --mode visible, hidden or warp.", + L"MouseLookProbe", MB_ICONERROR | MB_OK); + return 2; + } } } LocalFree(argv); @@ -280,8 +346,9 @@ int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int showCommand) { #else g_log = _wfopen(logPath.c_str(), L"w"); #endif - LogF("# MouseLookProbe client=%dx%d anchor_offset=(%ld,%ld) jump=%ld look_period_ms=%u\n", - kClientWidth, kClientHeight, kAnchorOffset.x, kAnchorOffset.y, kJumpPx, kLookPeriodMs); + LogF("# MouseLookProbe client=%dx%d anchor_offset=(%ld,%ld) jump=%ld look_period_ms=%u initial_mode=%s\n", + kClientWidth, kClientHeight, kAnchorOffset.x, kAnchorOffset.y, kJumpPx, + kLookPeriodMs, ModeKey(g_mode)); WNDCLASSW windowClass {}; windowClass.lpfnWndProc = WindowProc; @@ -300,6 +367,26 @@ int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int showCommand) { if (!g_window) { return 1; } + // Native radio buttons make the three experiments selectable without additional + // keyboard hooks, new dependencies, or edits to the WoW client. + const wchar_t* labels[] = { + L"A Visible cursor - no warp (character-select baseline)", + L"B Hidden cursor - no warp", + L"C Hidden cursor + warp (WoW-like, original probe mode)" + }; + const int ids[] = {kModeVisibleId, kModeHiddenId, kModeWarpId}; + const int selected = g_mode == ProbeMode::Visible ? 0 : + g_mode == ProbeMode::Hidden ? 1 : 2; + for (int i = 0; i < 3; ++i) { + g_modeButtons[i] = CreateWindowW(L"BUTTON", labels[i], + WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON | (i == 0 ? WS_GROUP : 0), + 20, 18 + i * 33, 620, 30, g_window, + reinterpret_cast(static_cast(ids[i])), instance, nullptr); + SendMessageW(g_modeButtons[i], WM_SETFONT, + reinterpret_cast(GetStockObject(DEFAULT_GUI_FONT)), TRUE); + SendMessageW(g_modeButtons[i], BM_SETCHECK, + i == selected ? BST_CHECKED : BST_UNCHECKED, 0); + } ShowWindow(g_window, showCommand); UpdateWindow(g_window);