fix(libScePad): open the special port with a handle that reads as disconnected #9878

Merged
ntamas94 merged 7 commits from upstream-pr/9878 into main 2026-10-23 12:14:24 +00:00
ntamas94 commented 2026-10-22 20:18:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-22T20:18:19Z.


What

scePadOpen returned DEVICE_NOT_CONNECTED (0x80920007) for a special port (type 2) since #3838, which fixed a real bug (both ports read the same input queue) but guessed the console side: its debt entry says whether the console opens a handle and reports the device as disconnected later is unknown.

Measured on a PS4 Pro, firmware 10.71, with no special controller connected (probe/padspecial.c and the 97-case libScePad survey of the ps4probe homebrew, survey/results/libScePad.ps4.txt): scePadOpen(user, SPECIAL, 0, NULL) returns a handle (0x03070502) and ALREADY_OPENED (0x80920004) on a second open; scePadGetHandle returns it; scePadRead returns one record and scePadReadState the same record (buttons 0, sticks 0x80, orientation (0, 0, 0, 1), acceleration (0, 1, 0), connected 0, timestamp 0); scePadGetControllerInformation is all zero; scePadDeviceClassGetExtendedInformation writes device class -1; scePadSetVibration, scePadSetLightBar, scePadResetLightBar, scePadSetMotionSensorState, scePadResetOrientation and scePadClose return 0; scePadRead(-1) is INVALID_HANDLE.

Unity's PS4 input module opens the standard port and then the special port of a user and keeps the pad handle only if both opens succeed; otherwise it reads with handle -1 every frame (disassembly of the relinked eboot of CUSA09558 at 0x140f20251..0x140f202ee; traced scePadRead(0xffffffff) per frame). Knowledge is Power (CUSA09558) and Knowledge is Power: Decades (CUSA12435) had no controller input under AnyPS5 for that reason.

The special port now opens a handle per user (PAD_SPECIAL_HANDLE + slot, 16 slots for the console's 16 accounts; a 17th user id gets 0x809b0081, the code the survey measured for an unknown user), tracked apart from the standard handle by scePadClose and scePadGetHandle; a second open by the same user returns ALREADY_OPENED. Every pad call accepts the handle: reads return the measured rest record, scePadGetControllerInformation and scePadDeviceClassParseData zeroed structures, extended information device class -1, and the setters succeed without touching the emulated pad. The standard handle keeps its own queue, so the double drain #3838 fixed for PPSA16827 does not come back: that title's per-frame scePadRead, scePadGetControllerInformation and scePadDeviceClassParseData on the special handle now get a disconnected record instead of draining the standard queue. scePadOpenExt is unchanged (PPSA01317 expects DEVICE_NOT_CONNECTED and skips the user). With two users logged in, the survey probe shows each user's handle, ALREADY_OPENED and close are independent of the other user's (rows in the review thread). Not measured: the console's handle values (fresh per open), the calls the survey did not cover on the special handle, and a PS5; all of it is in docs/dev/debt/libScePad.md.

Overlap (the overlap comment): #7881 (up to 4 controllers) and #9178 (remote control port handle) change the same scePadOpen / scePadGetHandle lines; PAD_SPECIAL_HANDLE + slot is 0x20..0x2f, outside #7881's PAD_HANDLE_BASE + port range and apart from #9178's PAD_REMOTE_HANDLE (0x10), so the rebase is mechanical whichever lands first. #5038 (libScePad stubs) touches scePadOpenExt and the same debt entry, not scePadOpen. #6337 (timestamped samples) and #6044 (test suite labels) touch GuestPad.cpp near the new test but not the same checks. None of them implements the special port, so this PR depends on none of them; it will be rebased on whichever merges first.

Tested

  • Windows 11, WinLibs GCC 15.2.0, Release, -DBUILD_TESTING=ON: guest_pad (special port: handle, ALREADY_OPENED, rest record, information, extended information, setters, close; two users, close of one, reads on the other) and guest_pad_vibration_mode pass. With the Export.cpp change reverted, guest_pad aborts at the first special-port Require (the special open returns 0x80920007).
  • PS4 Pro, firmware 10.71: probe/padspecial.c, the libScePad survey and the two-user special-port survey (second user logged in) as described above; the special-port rows are in the review thread.

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: CUSA09558, CUSA12435 (no Game bring-up discussion yet)
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4973555044 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9878). Originally posted by [ntamas94](https://github.com/ntamas94) on 2026-10-22T20:18:19Z. --- ### What `scePadOpen` returned `DEVICE_NOT_CONNECTED` (0x80920007) for a special port (type 2) since #3838, which fixed a real bug (both ports read the same input queue) but guessed the console side: its debt entry says whether the console opens a handle and reports the device as disconnected later is unknown. Measured on a PS4 Pro, firmware 10.71, with no special controller connected (`probe/padspecial.c` and the 97-case libScePad survey of the ps4probe homebrew, `survey/results/libScePad.ps4.txt`): `scePadOpen(user, SPECIAL, 0, NULL)` returns a handle (0x03070502) and `ALREADY_OPENED` (0x80920004) on a second open; `scePadGetHandle` returns it; `scePadRead` returns one record and `scePadReadState` the same record (buttons 0, sticks 0x80, orientation (0, 0, 0, 1), acceleration (0, 1, 0), `connected` 0, timestamp 0); `scePadGetControllerInformation` is all zero; `scePadDeviceClassGetExtendedInformation` writes device class -1; `scePadSetVibration`, `scePadSetLightBar`, `scePadResetLightBar`, `scePadSetMotionSensorState`, `scePadResetOrientation` and `scePadClose` return 0; `scePadRead(-1)` is `INVALID_HANDLE`. Unity's PS4 input module opens the standard port and then the special port of a user and keeps the pad handle only if both opens succeed; otherwise it reads with handle -1 every frame (disassembly of the relinked eboot of CUSA09558 at `0x140f20251..0x140f202ee`; traced `scePadRead(0xffffffff)` per frame). Knowledge is Power (CUSA09558) and Knowledge is Power: Decades (CUSA12435) had no controller input under AnyPS5 for that reason. The special port now opens a handle per user (`PAD_SPECIAL_HANDLE` + slot, 16 slots for the console's 16 accounts; a 17th user id gets 0x809b0081, the code the survey measured for an unknown user), tracked apart from the standard handle by `scePadClose` and `scePadGetHandle`; a second open by the same user returns `ALREADY_OPENED`. Every pad call accepts the handle: reads return the measured rest record, `scePadGetControllerInformation` and `scePadDeviceClassParseData` zeroed structures, extended information device class -1, and the setters succeed without touching the emulated pad. The standard handle keeps its own queue, so the double drain #3838 fixed for PPSA16827 does not come back: that title's per-frame `scePadRead`, `scePadGetControllerInformation` and `scePadDeviceClassParseData` on the special handle now get a disconnected record instead of draining the standard queue. `scePadOpenExt` is unchanged (PPSA01317 expects `DEVICE_NOT_CONNECTED` and skips the user). With two users logged in, the survey probe shows each user's handle, `ALREADY_OPENED` and close are independent of the other user's (rows in the review thread). Not measured: the console's handle values (fresh per open), the calls the survey did not cover on the special handle, and a PS5; all of it is in `docs/dev/debt/libScePad.md`. Overlap (the overlap comment): #7881 (up to 4 controllers) and #9178 (remote control port handle) change the same `scePadOpen` / `scePadGetHandle` lines; `PAD_SPECIAL_HANDLE` + slot is 0x20..0x2f, outside #7881's `PAD_HANDLE_BASE + port` range and apart from #9178's `PAD_REMOTE_HANDLE` (0x10), so the rebase is mechanical whichever lands first. #5038 (libScePad stubs) touches `scePadOpenExt` and the same debt entry, not `scePadOpen`. #6337 (timestamped samples) and #6044 (test suite labels) touch `GuestPad.cpp` near the new test but not the same checks. None of them implements the special port, so this PR depends on none of them; it will be rebased on whichever merges first. ### Tested - Windows 11, WinLibs GCC 15.2.0, Release, `-DBUILD_TESTING=ON`: `guest_pad` (special port: handle, `ALREADY_OPENED`, rest record, information, extended information, setters, close; two users, close of one, reads on the other) and `guest_pad_vibration_mode` pass. With the `Export.cpp` change reverted, `guest_pad` aborts at the first special-port `Require` (the special open returns 0x80920007). - PS4 Pro, firmware 10.71: `probe/padspecial.c`, the libScePad survey and the two-user special-port survey (second user logged in) as described above; the special-port rows are in the review thread. ### 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: CUSA09558, CUSA12435 (no Game bring-up discussion yet) - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!9878
No description provided.