fix(libScePad): open the system remote control port as a disconnected device #9178

Merged
norton62 merged 1 commit from upstream-pr/9178 into main 2026-10-24 15:40:16 +00:00
norton62 commented 2026-10-21 14:24:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by norton62 on 2026-10-21T14:24:09Z.


What

scePadOpen for the system user's remote control port (type 16) returned the DualSense handle, so scePadReadState on the "remote" reported the controller's buttons with connected set. SDL's PS5 video driver (SDL_ps5remote.c) opens that port and maps its buttons to keys, so every Cross also arrived as Return, Circle as Escape and the D-pad as arrow keys.

In Raptor: Call of the Shadows (PPSA94002), the on-screen keyboard injects the selected key and the remote's Return overwrites it in lastscan before the name field reads it, so no character can be typed (gdb watchpoint on lastscan: 2 from the keyboard, then 28 from SDL's event queue). Circle closed the registration dialog instead of the keyboard for the same reason.

The remote control port now opens a handle of its own (PAD_REMOTE_HANDLE, 0x10, outside the special port range) that reads one zeroed entry with no buttons and connected false, and scePadClose / scePadGetHandle track it independently of the DualSense handle. Unlike the special port handles it stays out of KnownHandle, so the calls that act on the DualSense (light bar, vibration and the rest) reject it with INVALID_HANDLE. The unmeasured console behaviour is recorded in docs/dev/debt/libScePad.md.

Overlap: #7881 (up to 4 controllers) changes the same lines, and its PortForUser maps the system remote port to controller slot 0, which would restore this bug. Agreed with its author (https://github.com/boykopovar/AnyPS5/pull/9178#issuecomment-6341429190): whichever of the two lands second keeps the remote port out of the per-port slots, on its own disconnected handle outside PAD_HANDLE_BASE + port. This PR is rebased on current main instead of waiting for #7881, as the reviews asked.

#10361 records a PS5 payload measurement where scePadOpen rejects type 16 with INVALID_ARG before looking at the user; it is not stated whether that covers the system user (0xff). If it does, the remote port should fail to open rather than open a disconnected handle. SDL's remote code treats a failed open the same way (it stops reading the port), so either result fixes the title; whichever lands second can switch the remote open to that measured error.

Tested

  • Rebased on main 4221f82dc. Windows 11, WinLibs GCC 15.2.0 r7, Release: guest_pad and guest_pad_vibration_mode pass. guest_pad aborts with Export.cpp and Pad.hpp reverted to main (new CheckSystemRemote, which also checks that the remote handle cannot set the DualSense light bar).
  • Raptor PPSA94002 (catalog release v1.0.0-rc.2, GPL-3.0, sha256 matches the catalog; shareware data from its own pinned download), relinked with --windows, RTX 5070 Ti: on the pilot registration screen the on-screen keyboard now types into NAME (1SD typed with injected pad input on the rebased build, relinked with its relinker and run against its libraries; before: nothing typed; the same failure was reproduced by hand with a physical DualSense before the fix), and the overlay keeps redrawing. On the earlier base (27bcd6a29 with this fix) the first mission was played through by hand with a DualSense at 60 FPS (#9687).

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: PPSA94002 #9687
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4953188645 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9178). Originally posted by [norton62](https://github.com/norton62) on 2026-10-21T14:24:09Z. --- ### What `scePadOpen` for the system user's remote control port (type 16) returned the DualSense handle, so `scePadReadState` on the "remote" reported the controller's buttons with `connected` set. SDL's PS5 video driver (`SDL_ps5remote.c`) opens that port and maps its buttons to keys, so every Cross also arrived as Return, Circle as Escape and the D-pad as arrow keys. In Raptor: Call of the Shadows (PPSA94002), the on-screen keyboard injects the selected key and the remote's Return overwrites it in `lastscan` before the name field reads it, so no character can be typed (gdb watchpoint on `lastscan`: `2` from the keyboard, then `28` from SDL's event queue). Circle closed the registration dialog instead of the keyboard for the same reason. The remote control port now opens a handle of its own (`PAD_REMOTE_HANDLE`, `0x10`, outside the special port range) that reads one zeroed entry with no buttons and `connected` false, and `scePadClose` / `scePadGetHandle` track it independently of the DualSense handle. Unlike the special port handles it stays out of `KnownHandle`, so the calls that act on the DualSense (light bar, vibration and the rest) reject it with `INVALID_HANDLE`. The unmeasured console behaviour is recorded in `docs/dev/debt/libScePad.md`. Overlap: #7881 (up to 4 controllers) changes the same lines, and its `PortForUser` maps the system remote port to controller slot 0, which would restore this bug. Agreed with its author (https://github.com/boykopovar/AnyPS5/pull/9178#issuecomment-6341429190): whichever of the two lands second keeps the remote port out of the per-port slots, on its own disconnected handle outside `PAD_HANDLE_BASE + port`. This PR is rebased on current `main` instead of waiting for #7881, as the reviews asked. #10361 records a PS5 payload measurement where `scePadOpen` rejects type 16 with `INVALID_ARG` before looking at the user; it is not stated whether that covers the system user (0xff). If it does, the remote port should fail to open rather than open a disconnected handle. SDL's remote code treats a failed open the same way (it stops reading the port), so either result fixes the title; whichever lands second can switch the remote open to that measured error. ### Tested - Rebased on `main` 4221f82dc. Windows 11, WinLibs GCC 15.2.0 r7, Release: `guest_pad` and `guest_pad_vibration_mode` pass. `guest_pad` aborts with `Export.cpp` and `Pad.hpp` reverted to `main` (new `CheckSystemRemote`, which also checks that the remote handle cannot set the DualSense light bar). - Raptor PPSA94002 (catalog release v1.0.0-rc.2, GPL-3.0, sha256 matches the catalog; shareware data from its own pinned download), relinked with `--windows`, RTX 5070 Ti: on the pilot registration screen the on-screen keyboard now types into NAME (`1SD` typed with injected pad input on the rebased build, relinked with its relinker and run against its libraries; before: nothing typed; the same failure was reproduced by hand with a physical DualSense before the fix), and the overlay keeps redrawing. On the earlier base (27bcd6a29 with this fix) the first mission was played through by hand with a DualSense at 60 FPS (#9687). ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: PPSA94002 #9687 - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
xXPBSXx commented 2026-10-21 16:44:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T16:44:17Z.


Linux data point for fb628dcbb5: WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal Linux), GCC 13.3.0, Release, BUILD_TESTING=ON, PR head alone (not merged onto main; its merge-base is 27bcd6a29).

  • With the PR: ctest -R '^guest_pad$' passes 3 of 3.
  • With libScePad/Export.cpp and libScePad/include/Pad.hpp restored to the merge-base (the PR's tests kept): fails (Subprocess aborted).
    Not tested: macOS, Windows, a title run.
    AI-assisted (Claude Code).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6321373065 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9178#issuecomment-6321373065). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T16:44:17Z. --- Linux data point for `fb628dcbb5`: WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal Linux), GCC 13.3.0, Release, `BUILD_TESTING=ON`, PR head alone (not merged onto `main`; its merge-base is `27bcd6a29`). - With the PR: `ctest -R '^guest_pad$'` passes 3 of 3. - With `libScePad/Export.cpp and libScePad/include/Pad.hpp` restored to the merge-base (the PR's tests kept): fails (`Subprocess aborted`). Not tested: macOS, Windows, a title run. AI-assisted (Claude Code).
MarcZX10 commented 2026-10-22 08:16:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T08:16:33Z.

Review: DISMISSED


Thanks for providing the SDL/game reproduction and the isolated Windows and WSL test results. I reviewed head fb628dcbb50572f3a3e41a31f812359e495f43d5; the focused guest_pad_tests target builds locally. Its CTest process aborts before assertions at this host's mandatory CPU-feature check (Xeon E5-1620 v2 lacks LZCNT, BMI1, BMI2, MOVBE, AVX2 and FMA), so I could not run the test assertions here. The reported Windows and WSL runs remain useful, but they are against the old branch base.

Please address these repository requirements before approval:

  1. The checklist says this is based on current main, but the head's merge base is 27bcd6a29e and current main is 633 commits ahead. The current merge preview conflicts in docs/dev/debt/libScePad.md, and the PR already has the needs rebase label. Please rebase/update onto current main, correct the checklist, and rerun the focused pad tests on the updated head. Current hosted checks are conventions/intake/labels; no product build or test job ran.

  2. The title checklist says Unblocks: PPSA94002 but also says there is no Game bring-up discussion yet. CONTRIBUTING.md requires the Game bring-up discussion to list the open PRs and local changes the title still needs. Please provide the appropriate discussion link and keep it updated with this PR and any remaining title work.

  3. Please coordinate the integration with open #7881. Its current PortForUser maps the system remote port to controller slot 0, and its scePadOpen returns PAD_HANDLE_BASE + port; this PR instead gives that port a separate disconnected handle. If #7881 lands unchanged after this, it restores the bug this PR fixes. That is a behavioral interaction, not just a textual rebase. The two changes are distinct, but please confirm with the #7881 author how the multi-controller change will preserve the remote-port behavior and update the overlap notes accordingly. I checked #9664's adjacent tracker-query changes as well; they do not duplicate this implementation.

git diff --check passed and tools/check_conventions.py --base upstream/main --head refs/review/9178 passed. guest_pad_tests compiled successfully; its local runtime was blocked by the host CPU guard described above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5611174962 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9178#pullrequestreview-5611174962). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T08:16:33Z. **Review:** DISMISSED --- Thanks for providing the SDL/game reproduction and the isolated Windows and WSL test results. I reviewed head `fb628dcbb50572f3a3e41a31f812359e495f43d5`; the focused `guest_pad_tests` target builds locally. Its CTest process aborts before assertions at this host's mandatory CPU-feature check (Xeon E5-1620 v2 lacks LZCNT, BMI1, BMI2, MOVBE, AVX2 and FMA), so I could not run the test assertions here. The reported Windows and WSL runs remain useful, but they are against the old branch base. Please address these repository requirements before approval: 1. The checklist says this is based on current `main`, but the head's merge base is `27bcd6a29e` and current `main` is 633 commits ahead. The current merge preview conflicts in `docs/dev/debt/libScePad.md`, and the PR already has the `needs rebase` label. Please rebase/update onto current `main`, correct the checklist, and rerun the focused pad tests on the updated head. Current hosted checks are conventions/intake/labels; no product build or test job ran. 2. The title checklist says `Unblocks: PPSA94002` but also says there is no Game bring-up discussion yet. CONTRIBUTING.md requires the Game bring-up discussion to list the open PRs and local changes the title still needs. Please provide the appropriate discussion link and keep it updated with this PR and any remaining title work. 3. Please coordinate the integration with open #7881. Its current `PortForUser` maps the system remote port to controller slot 0, and its `scePadOpen` returns `PAD_HANDLE_BASE + port`; this PR instead gives that port a separate disconnected handle. If #7881 lands unchanged after this, it restores the bug this PR fixes. That is a behavioral interaction, not just a textual rebase. The two changes are distinct, but please confirm with the #7881 author how the multi-controller change will preserve the remote-port behavior and update the overlap notes accordingly. I checked #9664's adjacent tracker-query changes as well; they do not duplicate this implementation. `git diff --check` passed and `tools/check_conventions.py --base upstream/main --head refs/review/9178` passed. `guest_pad_tests` compiled successfully; its local runtime was blocked by the host CPU guard described above.
slugzero commented 2026-10-22 13:03:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slugzero on 2026-10-22T13:03:08Z.


Author of #7881 here - thanks @norton62 for making me aware of this dependency. Fully on board with the proposed coordination as stated in the description: once #7881 merges, rebase #9178 onto it and keep the system remote
control port on its own disconnected handle.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6341429190 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9178#issuecomment-6341429190). Originally posted by [slugzero](https://github.com/slugzero) on 2026-10-22T13:03:08Z. --- Author of #7881 here - thanks @norton62 for making me aware of this dependency. Fully on board with the proposed coordination as stated in the description: once #7881 merges, rebase #9178 onto it and keep the system remote control port on its own disconnected handle.
adriadam10 commented 2026-10-23 20:20:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-23T20:20:44Z.

Review: CHANGES_REQUESTED


Thanks for the fix and the SDL/title analysis; the diff matches the description and CheckSystemRemote pins the new behaviour (own handle, no buttons, connected false, independent close and scePadGetHandle).

  • The head is on an old base: libScePad/Export.cpp, include/Pad.hpp, tests/GuestPad.cpp and docs/dev/debt/libScePad.md all conflict with current main (Export.cpp was reworked there), so the checklist line "Based on current main" no longer holds. Please rebase, adapt the remote-port handling to the current file, and rerun guest_pad on the updated head.
  • #7881 is still open and also conflicts. As agreed with its author, after it lands the remote port must stay out of the per-port slots with its own disconnected handle outside PAD_HANDLE_BASE + port; keep that in the rebase and keep the overlap note in the body up to date.
  • MarcZX10 asked for the Game bring-up discussion link for PPSA94002 (Unblocks); please add it.

Happy to look again on the rebased head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5633981993 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9178#pullrequestreview-5633981993). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-23T20:20:44Z. **Review:** CHANGES_REQUESTED --- Thanks for the fix and the SDL/title analysis; the diff matches the description and `CheckSystemRemote` pins the new behaviour (own handle, no buttons, `connected` false, independent close and `scePadGetHandle`). - The head is on an old base: `libScePad/Export.cpp`, `include/Pad.hpp`, `tests/GuestPad.cpp` and `docs/dev/debt/libScePad.md` all conflict with current `main` (Export.cpp was reworked there), so the checklist line "Based on current `main`" no longer holds. Please rebase, adapt the remote-port handling to the current file, and rerun `guest_pad` on the updated head. - #7881 is still open and also conflicts. As agreed with its author, after it lands the remote port must stay out of the per-port slots with its own disconnected handle outside `PAD_HANDLE_BASE + port`; keep that in the rebase and keep the overlap note in the body up to date. - MarcZX10 asked for the Game bring-up discussion link for PPSA94002 (`Unblocks`); please add it. Happy to look again on the rebased head.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!9178
No description provided.