Commit Graph
46 Commits
Author SHA1 Message Date
Henrik RydgårdandClaude Opus 5.5 acb2acf0b4 sceNetAdhocMatching: Run the input and event loops from CoreTiming instead of host threads
Each started context had two host threads, polling every 10 ms of wall
time: one sent queued packets, received, and ran hellos, keepalives and
timeouts, and the other handed events to the callbacks. A single
CoreTiming event now does both for every running context, every 1 ms of
emulated time, and Stop does what the threads did on their way out.

Matching no longer depends on host scheduling or wall-clock delays, so an
accept's ESTABLISHED comes 1-10 ms after SelectTarget at any emulation
speed, as on a PSP (pspautotests net/adhoc/pair/matchingaccept).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 00:44:36 +01:00
Henrik RydgårdandClaude Opus 5.5 603a63bc09 sceNetAdhocMatching: Report the pool as empty right after Init
A PSP reports the pool size less 0x20 and a maximum of 0 until anything
is allocated (net/adhoc/matching, recorded on a PSP). With a context the
faked half-pool maximum stays, since that isn't measured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 10:15:35 +01:00
Henrik RydgårdandClaude Opus 5.5 d0d6f0f61b sceNetAdhocMatching: A child lists its parent first after a keepalive
- Fixes #22331

A child's GetMembers starts with itself, then switches to the parent
first one keepalive interval after it was accepted
(net/adhoc/pair/matchingorder, recorded on two PSPs). We kept it self
first. Bomberman's client checks that the first member is the host
before it marks itself ready, so its lobby stayed empty and the host's
start failed with "failed to connect to the game".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 10:15:14 +01:00
Henrik RydgårdandClaude Opus 5.5 882eee4c13 sceNetAdhocMatching: A denied P2P request goes back to a known peer
CancelTarget on an incoming P2P request marked the peer timed out. It
only escaped a TIMEOUT if one of its hellos came in before the next
timeout check, which it no longer does now that timeouts are checked
all the time. On a PSP it's a peer known from its hellos again, with no
TIMEOUT (pspautotests net/adhoc/pair/matching3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 10:15:14 +01:00
Henrik RydgårdandClaude Opus 5.5 60a49ccfd2 Ad hoc: Use the PSP's measured times instead of guessed ones
Where pspautotests net/adhoc/timing or net/adhoc/pair/timing measured
a value, use it:

- Call costs: PdpSend 21 us (10 broadcast), PtpSend 122, PtpFlush 196,
  GetPdpStat 1, GetPtpStat 2, PollSocket 18, GetScanInfo 2, GetPeerList
  and MatchingGetMembers 4 (no longer a 100 us reschedule),
  MatchingStart 416 instead of 30 ms, sceNetAdhocctlTerm 154,
  sceNetAdhocTerm 10 and sceNetTerm 209 instead of 10 ms each,
  GameModeUpdateMaster 80, UpdateReplica 9.
- Game mode data goes out every 12 ms, not every 0.5 ms.
- DISCONNECT comes 640 ms after ExitGameMode, not 105 ms.
- CONNECT after a Join no longer waits for a peer: a PSP delivers it
  before the host shows up in the peer list.

Several of the old values were tuned for particular games (BattleZone's
frame rate, Fate Unlimited Codes and Bleach through PollSocket), and
may have been making up for other differences that are fixed now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 10:15:13 +01:00
Henrik RydgårdandClaude Opus 5.5 f449129dec sceNetAdhoc: Time a vanished peer's timeouts as a PSP does
A PSP checks a PTP connection's oldest unacknowledged data every
rexmt_int, counting from when the connection was established, and drops
the connection at the first check where that data is older than
(rexmt_cnt + 1) * rexmt_int. A matching peer times out keepalive_int *
init_count after its last keepalive, checked all the time instead of on
the console's own keepalive tick, which could add up to an interval.
Both measured with several settings in pspautotests
net/adhoc/pair/vanishtiming; DATA_TIMEOUT already matched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 22:39:07 +01:00
Henrik RydgårdandClaude Opus 5.5 4197f2326a sceNetAdhoc: A console that leaves the network goes quiet, as on a PSP
The vanish pair test (recorded on two PSPs) now passes on both sides,
over the relay:

- From the Disconnect call, a console's PDP and PTP sends succeed and go
  nowhere, and nothing reaches it.
- A PTP connection to a peer that has left the group fails with
  DISCONNECTED after rexmt_int * rexmt_cnt. Relay sockets now get their
  retry settings (and are zeroed), and an accepted one counts as
  connected.
- Matching data to a peer that has left gets DATA_TIMEOUT after the
  retransmissions instead of a DATA_ACK.
- The matching timeout for a silent peer is keepalive_int * init_count,
  plus MATCHING_TIMEOUT_EXTRA_US (0) to tune for internet latency. It
  was (keepalive + rexmt) * count + 500ms, later than a PSP's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 22:39:07 +01:00
Henrik RydgårdandClaude Opus 5.5 e5bafd423d sceNetAdhocMatching: Report every join request, after SetHelloOpt too
The rule that dropped the first join after the hello data changed came
from a race in pspautotests net/adhoc/pair/matching2, where the host
started looking for the REQUEST after it had come. A PSP reports the
join at once however soon after SetHelloOpt it arrives, also when the
host changes its hello data every second (net/adhoc/pair/matchingjoin).
Ridge Racer does that every 5 seconds, so its clients could never enter
a race.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 22:39:06 +01:00
Henrik RydgårdandClaude Opus 5.5 5cc3554667 sceNetAdhocMatching: Pass the pair matching tests
The matching, matching2 and matching3 pair tests (recorded on two PSPs)
now pass on both sides:

- Event and input messages are queued in order. They were stacks, so a
  burst came out reversed (PONG and PANG crossed), and two places spawned
  their messages backwards to compensate.
- A peer stays busy until its DATA_ACK is delivered (DATA_BUSY), and
  AbortSendData discards that DATA_ACK.
- A host's SelectTarget while its accept is in progress gives
  REQUEST_IN_PROGRESS.
- A child that leaves, a cancelled request and a denied request (client
  and P2P) go back to a known non-member peer: no TIMEOUT, hellos keep
  coming, and it can ask again; a cancelled request gives
  TARGET_NOT_READY. A client says BYE to a host it has left.
- After SetHelloOpt the next join from an unknown peer reaches the host
  without a REQUEST.
- GetMembers lists the console itself first, also on a client.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 22:39:05 +01:00
Henrik RydgårdandClaude Opus 5.5 e94ae7f190 sceNetAdhocMatchingStart2: Check the stack sizes and partitions
A stack size too small to be one (where a partition was passed) gives
STACKSIZE_TOO_SHORT, and a partition outside 1-6 then INVALID_ID
(pspautotests net/adhoc/matching). How small a stack still works isn't
known, so only sizes below 0x100 are refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 22:39:05 +01:00
Henrik RydgårdandClaude Opus 5.5 ce81c07a69 sceNetAdhocMatching: Start returns 0, not the matching thread's ID
The fake matching thread was started through sceKernelStartThread,
which switched threads inside the call, and the game got the new
thread's ID back. On a PSP, Start returns 0 (pspautotests
net/adhoc/matching). Create and start it like adhocctl's thread instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 22:39:05 +01:00
Henrik RydgårdandClaude Opus 5.5 ae906cb292 sceNetAdhocMatching: Don't list a member twice
A child the host accepts right after another one learns about that one
twice: from the sibling list in its accept packet, and from the BIRTH
packet the host sends about it. It added it both times, so with three or
four players the last one to join had an extra member (pspautotests
net/adhoc/group/matching, not recorded on PSPs yet).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 22:39:05 +01:00
Henrik RydgårdandClaude Opus 5.5 e0a6a662f4 sceNet, sceNetAdhoc: Cite the tests for behaviour that's the PSP's
Several comments called PSP behaviour a workaround for one game: PDP
send and receive returning 0 and writing the length back, Scan while
connected reporting ALREADY_CONNECTED, PtpOpen connecting by itself,
connecting a connected socket returning 0, PtpAccept's optional peer
address and port, the malloc stat's pool size, and matching dropping
hellos from a host mid-join. The pspautotests recorded on PSPs show the
PSP does all of these, so say that, and keep the games as examples.

Also bumps pspautotests for the new adhocctl Disconnect events and the
pair/matching3 test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 09:52:55 +01:00
Henrik RydgårdandClaude Opus 5.5 591cec315e sceNetAdhocMatching: Put the game workarounds behind compat flags
CancelTarget on a MAC that isn't a peer, and Start on a context ID that
doesn't exist, faked success for every game. On the PSP they fail with
UNKNOWN_TARGET and INVALID_ID (pspautotests net/adhoc/matching). Only
the games they were added for keep them now:
MatchingCancelUnknownTargetSucceeds for Soulcalibur: Broken Destiny, and
MatchingStartUnknownIdSucceeds for GTA: Vice City Stories.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 09:52:40 +01:00
Henrik RydgårdandClaude Opus 5.5 0904b47639 sceNetAdhocMatching: Check arguments like the PSP
From the net/adhoc/matching and limits pspautotests, recorded on PSPs:

- Create: a bad mode gives INVALID_MODE, rxbuflen has to be at least
  6 * maxnum + 4, host and P2P contexts need nonzero hello and keep-alive
  intervals, init_count can't be negative and rexmt_int can't be 0. At
  most 15 contexts exist at once.
- Start on a running context gives IS_RUNNING. Start2 takes each
  thread's partition after its stack size, not before.
- Stop and Delete on unknown IDs give INVALID_ID, and Delete on a running
  context IS_RUNNING (internal cleanup still stops and deletes).
- GetHelloOpt fails before Start, copies at most the game's buffer and
  leaves the length alone. It used to write the whole hello past the
  buffer.

CancelTarget on an unknown peer still succeeds, as Soul Calibur needs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 09:52:22 +01:00
Katharine Chui 880158cfdb initial enet mode for adhocctl & aemu_postoffice relay 2026-10-21 14:19:54 +02:00
Henrik RydgårdandClaude Opus 5.5 7dd1475ed7 HLE: Pass the MIPSState to syscalls and their implementations
HLEFunc and ReplaceFunc now take the MIPSState they run on. The dispatch
paths (both interpreters and every JIT backend) pass in the state they
belong to, and CallSyscall*, hleFinishSyscall and the HLE mips call
machinery use it instead of currentMIPS.

The wrappers in FunctionWrappers.h take the function as `auto` and call it
through HLECall, which also accepts an implementation with an extra leading
MIPSState * parameter and passes the state to it. Any other signature still
fails to compile, as before. PARAM/RETURN now refer to a local `mips`.

The HLE functions (and replacement functions) that used currentMIPS now take
the state that way. Callers outside a syscall's own frame - CoreTiming
events, the adhoc matching thread, dialogs, PPGe, the debugger UIs - pass
currentMIPS or &mipsr4k explicitly. The kernel's thread internals still use
currentMIPS.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-20 15:45:14 +02:00
Henrik RydgårdandClaude Opus 5.5 1cf65ab6a4 Clarify comments from the crash fixes
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 09:10:03 +02:00
Henrik RydgårdandClaude Opus 5.5 d9db5cf63b Adhoc: Stop a running matching context before deleting it
NetAdhocMatching_Delete unlinked the context before calling Stop, which then
couldn't find it, so the input and event threads were never joined and
deleting the context destroyed joinable std::threads (std::terminate). Seen
on Android when shutting down a game with matching running.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 07:47:49 +02:00
Henrik RydgårdandClaude Opus 5.5 16a03f16e8 Adhoc: Restore the inited flags from savestates
Loading a savestate kept the current session's netAdhocInited,
netAdhocctlInited and matching-inited flags rather than the saved ones.
Loaded into a fresh boot, a state saved with adhocctl initialized (but not
connected) then failed every adhocctl call with NOT_INITIALIZED. MGS Peace
Walker shuts ad hoc down before a cutscene and retried
sceNetAdhocctlDisconnect forever, leaving the screen black.

Take the flags from the state, and bring the host side in line: start the
friendFinder and log in again when the state has adhocctl up and we don't,
stop it in the opposite case. Also save the product code, which that login
sends.

Also add a game.state.save debugger command, used to reproduce this.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-18 09:15:51 +02:00
Acts1631 7de6a6ccfb Avoid overflow in matching packet length checks
Matching packet handlers added untrusted payload lengths to fixed header
sizes before comparing them with the datagram length. Large values could
overflow and permit out-of-bounds reads. Compare against the remaining
packet size instead, and reject negative ACCEPT sibling counts.
2026-10-03 21:55:32 -04:00
Henrik RydgårdandClaude Opus 5.5 639e57c2bd Savestate: Keep pending adhocctl requests, so a waiting Init survives a load
With WLAN on and no server reachable, sceNetAdhocctlInit keeps its thread
waiting for the login. The load dropped the request, and the wait ended in
BUSY, which Init can't retry. Splinter Cell then ran its failure path with
a deleted event flag. Also stop freeing matching event buffers into the
restored allocator, and take the event lock when clearing.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 09:34:06 -06:00
Henrik Rydgård c5e4d0d90d Rename the get-memory-pointer functions to make it clear where CPU exceptions can happen. 2026-08-12 14:06:16 +02:00
Henrik Rydgård 3bd41376da More memory cleanup 2026-08-11 20:12:10 +02:00
Henrik Rydgård 8cb1732564 Clean up the memory partition ID enum 2026-07-25 14:53:02 +02:00
Henrik Rydgård 040996f185 Use new/delete properly for SceNetAdhocMatchingContext. It contains non-POD C++ objects. 2026-07-23 11:17:44 +02:00
Henrik Rydgård 702e18bd2d Fix typo (thanks Nemo)
See #d0dd10c
2026-07-18 23:55:25 +02:00
Henrik Rydgård d0dd10ce6b Avoid memsetting a non-POD struct (fixes compiler warning) 2026-06-16 11:05:16 +02:00
Katharine Chui f218138f2e add missing null check during actOnDeathPacket
It is not impossible for deadkid to not be tracked, so we have to
null check that
2026-02-26 13:18:03 +01:00
Henrik Rydgård 3e2dce1e54 Move AdHoc error codes to the big enum, fix the naming convention to be consistent 2025-08-06 17:44:54 +02:00
Nemoumbra c7aafd4cbe Deduplicated a config variable 2025-07-02 01:30:21 +03:00
Nemoumbra 921fd32969 8 vars moved to NetAdhocCommon, 1 var moved to sceNetAdhocMatching 2025-07-01 19:56:09 +03:00
Henrik Rydgård 4e25f44eef Rename some module-related functions to include HLE where appropriate 2025-03-31 11:17:50 +02:00
Henrik Rydgård 0f840e6240 Move JPEG error codes to the big enum, some include cleanup 2025-03-21 20:44:46 +01:00
Henrik Rydgård e24317b20b A lot more logging fixes 2025-01-20 12:20:21 +01:00
Henrik Rydgård 7d2ad6980e Another batch of changes 2025-01-20 12:20:21 +01:00
Nemoumbra aae7b187d5 Hadouken fixes: SendData funcs + sceNetAdhocMatchingGetPoolStat 2025-01-05 01:07:10 +03:00
Nemoumbra 94f4ad200b Hadooken fixes: sceNetAdhocMatchingSelectTarget, NetAdhocMatching_CancelTargetWithOpt 2025-01-05 00:46:42 +03:00
Nemoumbra 3497ccacb5 Hadooken codestyle fix + cleaned up NetAdhocMatching_Start 2025-01-05 00:08:20 +03:00
Nemoumbra f7289ff22a Simplified 2 more matching funcs 2025-01-04 23:52:31 +03:00
Nemoumbra 4f623db57a Added early returns for actOn{X}Packet funcs 2025-01-04 23:42:39 +03:00
Nemoumbra 110799f09d Cleaned up broadcastHelloMessage and broadcastPingMessage 2025-01-04 21:08:31 +03:00
Nemoumbra 9f94e035a7 Added early returns for send{X}Packet funcs 2025-01-04 20:29:39 +03:00
Nemoumbra 9f4f0a4e6a Brace codestyle fix 2025-01-04 19:55:50 +03:00
Nemoumbra 96f9749e2e Split out the matching code from sceNetAdhoc.cpp 2025-01-03 04:59:26 +03:00
Nemoumbra b265b3b994 Added empty sceNetAdhocMatching files 2025-01-02 16:03:37 +03:00