Commit Graph
257 Commits
Author SHA1 Message Date
Henrik RydgårdandClaude Opus 5.5 0a778a13ff HLE: Check more guest buffers by their full length, and an empty insert
Calls that checked one byte of a game's buffer and then wrote or read the
whole thing, or trusted a negative length:
- sceNetEtherNtostr/Strton, the apctl BSS descriptor calls, GetState and
  sceNetGetDropRate.
- sceNpAuthGetTicket wrote its whole ticket whatever the length; it's
  now built locally and written once the buffer is known to hold it.
  sceNpAuthGetTicketParam checked its limits after copying, and walked
  ticket params past the ticket's end.
- sceNp2's communication ID and passphrase, a negative maxServerIds, and
  an unchecked unknown1Ptr.
- sceParseUri's work area and scheme string, sceParseHttp's negative
  header length and value address, and ReadVariableSizedStruct's size.
- sceKernelCreateLwMutex initialized the work area without checking it
  at all, and the other LwMutex calls checked one byte of it.
- sceNetAdhocctlGetScanInfo cleared the length the game gave, of a
  buffer checked by one byte (or any length, negative ones included).

Also: a game mode join inserted at begin() + 1 into a possibly empty
list of players.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 11:26:03 +01:00
Henrik RydgårdandClaude Opus 5.5 4221c4cd54 sceNetAdhoc: Receive PDP through a queue of the socket's buffer size
A PSP keeps what arrives in the socket's buffer, of the size given to
PdpCreate, and drops a datagram that doesn't fit: a buffer of 0 gets
nothing, one of 2048 bytes only some of ten 1000-byte datagrams
(pspautotests net/adhoc/pair/flow). Each transport now only hands over
the datagrams that have arrived (PdpTakeDatagram), into a queue per
socket that is filled every millisecond and whenever the game looks, and
PdpRecv, its blocking retry, GetPdpStat, PollSocket and game mode read
from that. This replaces each transport's own receive paths, so the
relay now reports the sender with NOT_ENOUGH_SPACE too, and P2P's
blocking receive no longer misreads a stale errno.

A datagram to ourselves goes straight into our own socket's queue, as on
a PSP, so it's there at once through the relay too (net/adhoc/term).

Also from comparing the transports:
- P2P: a blocking Accept of a connection from outside the group keeps
  waiting instead of returning -1.
- Relay: an accepted socket gets an id of its own, not its listener's,
  which blocking calls are told apart by.
- ALERT in PollSocket comes from the socket in both transports.
- No send/receive timeouts are set on the game's sockets: all host
  sockets are non-blocking, and in relay mode the ids aren't host
  sockets at all.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 08:05:38 +01:00
Henrik RydgårdandClaude Opus 5.5 b5db43ca9d sceNetAdhoc: Put PTP, polling and socket cleanup behind AdhocTransport
The relay and P2P halves of PtpOpen, PtpListen, PtpClose, PtpSend,
PtpRecv, PtpAccept and their blocking retries, GetPtpStat, PtpFlush,
PollSocket and deleting all sockets move into RelayTransport and
P2PTransport. Connecting stays shared, with the transports answering
the steps that differ (start, check on, confirm, still pending).

No change in behaviour, except that a relay poll asks the postoffice
whether a socket is readable once instead of twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 19:09:35 +01:00
Henrik RydgårdandClaude Opus 5.5 a0669ffbe4 sceNetAdhoc: Don't let an abandoned group join put us in the group
When the game gives up on a join (game mode timed out, or it
disconnected), a join still queued isn't sent anymore, and the rest of
the server's answer to one already sent is dropped: its players, and the
BSSID that came last and connected us. Players joining a group we've
just left (before the server knew) are dropped too, instead of staying
in our peer list.

Replaces the previous fix, which only dropped a late BSSID: on Windows
the join itself was still queued when game mode timed out in
net/adhoc/gamemode, and went out after it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 11:53:44 +01:00
Henrik RydgårdandClaude Opus 5.5 9d8ef5e8f5 sceNetAdhoc: Ignore the server's answer to a timed-out game mode join
When entering game mode timed out before the server's group BSSID came
back, the late BSSID was taken for a normal group's, and the state went
to CONNECTED: every later CreateEnterGameMode then got ALREADY_CONNECTED.
At the ad hoc tests' 8x speed the 1 s timeouts in net/adhoc/gamemode are
125 ms of wall time, short enough for that on Windows; at 50x it happens
on macOS too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 11:21:57 +01:00
Henrik RydgårdandClaude Opus 5.5 e7548e1bea sceNetAdhoc: Measure socket and game mode timeouts in emulated time
The timeouts of blocking socket calls and of entering game mode are the
PSP's, but they were measured on the wall clock, so they came out
shorter in PSP time whenever emulation ran fast or slow. The wait for
the ad hoc server, which is a host-side round trip, stays on the wall
clock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 10:15:35 +01:00
Henrik RydgårdandClaude Opus 5.5 ee86058ec7 sceNetAdhocctl: Leave the console out of its own peer lookups; give groups their own BSSID
From the basic and lifecycle pair tests, recorded on two PSPs:

- GetNameByAddr for the console's own MAC gives NO_ENTRY, and
  GetAddrByName doesn't find the console itself.
- GetPeerInfo with a size too small for the entry gives INVALID_BUFLEN.
- A PTP connection accepted over the relay reports the peer's port as
  the game sees it, not the relay's offset port.
- The built-in server makes up a locally administered BSSID for each
  group, which stays when the creator leaves. It was the MAC of the
  oldest member.

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 fa51700d58 sceNetAdhocctl: Fail entering game mode the way a PSP does
On a PSP (pspautotests net/adhoc/gamemode):
- a JoinEnterGameMode whose host never shows up gets ERROR with TIMEOUT
  when its timeout runs out, and is out of the group afterwards. The
  joiner's GAMEMODE, queued as soon as the server answered and held
  until the host appeared, came after 5 s anyway;
- a CreateEnterGameMode whose first member isn't this console returns
  0 and reports INVALID_ADDR;
- in a normal group, CreateEnterGameMode reports ALREADY_CONNECTED and
  stays in the group, and ExitGameMode returns INVALID_IBSS;
- ExitGameMode outside game mode returns 0 with no event.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 22:39:07 +01:00
Henrik RydgårdandClaude Opus 5.5 b58368405b proAdhoc: Keep pinging the server while emulation is paused
The adhocctl poll only runs while emulation does, so with the pause menu
open, or stopped in a debugger, for 15 s the server dropped the client,
and a game in a lobby lost its peers until it rejoined. A small thread
pings when the poll hasn't, as the friendFinder thread used to.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 22:39:07 +01:00
Henrik RydgårdandClaude Opus 5.5 5021e3ccc1 sceNetAdhocctlInit: Don't wait for the login to the server
On a PSP, Init returns at once and a Create, Connect or Scan right after
it works (pspautotests net/adhoc/ctlinit). The login now runs on in the
background, and those requests wait for it, as they already did when it
was lost. The first login no longer resets the busy flag, which would
have cleared it for a request already waiting on it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 22:39:07 +01:00
Henrik RydgårdandClaude Opus 5.5 a276f00dd0 proAdhoc: Run the adhocctl client from a CoreTiming event
The friendFinder thread is replaced by friendFinderPoll(), which a
CoreTiming event calls every millisecond of emulated time on the CPU
thread. It handles everything the server has sent since the last poll,
instead of one event every 10 ms, and pings it at the same real-time
interval. Resolving the server and logging in, which can take seconds,
run on a thread of their own; the poll starts it and takes over the
session when it's done.

Everything else about the client is unchanged, including sceNetAdhocctlInit
waiting for the login. The savestate section goes to version 11 for the
poll event; older states get it scheduled on load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 22:39:07 +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 25ee41f135 sceNetAdhocMatching: Hand out context IDs in increasing order
A PSP numbers matching contexts 1 to 15 in increasing order and then
starts over, instead of reusing the lowest free ID (pspautotests
net/adhoc/matching).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 22:39:05 +01:00
Henrik RydgårdandClaude Opus 5.5 de175c7d03 proAdhoc: Say why MAC comparisons ignore the first byte
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 09:52:55 +01:00
Henrik RydgårdandClaude Opus 5.5 58d73cbbc6 sceNetAdhoc, adhocctl: Check arguments like the PSP
From the net/adhoc pspautotests (pdp, ptp, poll, limits, adhocctl,
gamemode), recorded on PSPs:

- PDP and PTP: NULL pointers and nonzero flags give INVALID_ARG, before
  the socket ID is checked. Zero and multicast addresses give
  INVALID_ADDR, ports 0 and 65535 INVALID_PORT, and send lengths over
  65523 or NULL data INVALID_DATALEN. A length of 0 sends nothing and
  succeeds. Zero buffer sizes, retransmit settings and backlogs are
  accepted. PdpRecv takes a NULL sender address or port. Running out of
  socket IDs gives SOCKET_ID_NOT_AVAIL, and out-of-range IDs on
  delete/close INVALID_SOCKET_ID. PollSocket rejects flags other than
  NONBLOCK.
- adhocctl: Init checks its stack size, priority and ad hoc ID;
  AddHandler needs Init, allows the same function twice and takes at most
  4 handlers; DelHandler on an unknown ID gives ID_NOT_FOUND; bad group
  names give adhocctl's INVALID_ARG; GetParameter and GetPeerList fail
  outside a group.
- Game mode: a NULL group name and a bad minimum are rejected,
  GetGameModeInfo fails outside game mode, and the entry timeout reports
  adhocctl's TIMEOUT.

The DBZ Shin Budokai 2 workaround that replaces the game's local MAC with
ours stays, so another console's MAC is still accepted when creating a
socket.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 09:52:22 +01:00
Katharine Chui 262416ad90 fix adhocctl regression by restoring wrongly removed logic
- 23efd22efb : Fix Stuck issue on some games (Dissidia 012, Full Auto 2, etc) when Failed to connect to Adhoc Server (faked success)
- 7ec860c24f : Adhoc: Stop waiting for a login that has already failed
2026-10-27 15:02:04 +01:00
Katharine Chui 3db71ea1ed fix missing htons in getRelativeLocalIpFromRoutingTable 2026-10-21 16:08:49 +02:00
Katharine Chui ee06afa3bc do not hold adhocctlMutex while adhocctl client is being created 2026-10-21 16:06:29 +02:00
Katharine Chui 9c8ebfd59f make use of isLocalServer during adhocctl client binding 2026-10-21 14:19:55 +02:00
Katharine Chui eb9e31a647 refactor initNetwork into adhocctlClientMaintenance 2026-10-21 14:19:55 +02: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 5080cb23b6 sceNetInet: Only let the ad hoc settings change bind addresses during ad hoc
- Fixes #22647

sceNetInetBind rewrote the address whenever the ad hoc server was set to
localhost (to 127.0.0.x, even an explicit address) or the built-in ad hoc
server was enabled (INADDR_ANY to the address facing the ad hoc server),
breaking infrastructure sockets. Both rewrites now only apply while
adhocctl is initialized, which keeps ad hoc as it was.

sceNetApctlGetInfo reported its IP from the same ad hoc-relative
getLocalIp(), so a localhost ad hoc server told infrastructure games their
IP was 127.0.0.x. It now uses the host interface's IP (getHostLocalIp(),
split out of getLocalIp()).

Adds the net/inet/bind test, which failed every bind under headless (whose
ad hoc server is localhost).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-20 08:59:03 +02:00
Henrik RydgårdandClaude Opus 5.5 84ba31eb9f Adhoc: stop connecting to the adhoc server when the friend finder is stopped
initNetwork() runs on the friend finder thread and its connect loop only
gave up on power-down or after the timeout. sceNetAdhocctlTerm joins that
thread from the emulation thread, so terminating while the server was
unreachable could freeze emulation for up to adhocDefaultTimeout.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-13 02:24:27 +02:00
Henrik RydgårdandClaude Opus 5.5 7ec860c24f Adhoc: Stop waiting for a login that has already failed
sceNetAdhocctlInit waits until the friend finder has logged into the adhoc
server, polling in emulated time but giving up only after 5s of wall time.
The friend finder makes one attempt per login request, and it too waited
the full 5s on a connection that had already been refused, because it
only looked for success. Now it checks the socket error and gives up at
once, and records the failure so the wait ends with it.

In headless, which runs far ahead of real time, Gods Eater Burst sat in
this wait for its whole run.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-29 12:37:48 -06:00
Henrik RydgårdandClaude Opus 5.5 2cd84012d0 Adhoc: Fix shutdown hanging when it comes right after adhoc init
The friend finder thread set friendFinderRunning itself, after a DNS
lookup of the adhoc server. A shutdown in that window cleared the flag
first; the thread then set it again, looped forever, and the join in
NetAdhocctl_Term() never returned. Gods Eater Burst hit this in about one
headless run in six. The flag is now set before the thread is created,
and a finished thread is joined before a new one replaces it, which
would otherwise call std::terminate.

The built-in adhoc server thread had the same race, behind its check for
an existing server, and gets the same fix.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-29 11:58:42 -06:00
Katharine Chui aa4a4eb18d allow connecting to adhoc server on 127.0.0.1 with built-in server disabled 2026-09-06 14:11:18 +02:00
Henrik RydgårdandClaude Opus 5 fbdf611fc4 Chat: keep more lines of history, and add timestamps
The log was trimmed to 50 lines, which isn't enough to scroll back
through a conversation - now 250. Chat entries also carry the time they
arrived, shown as a dimmed HH:MM in front of the name, behind a new
"Show timestamps in chat" setting.

The timestamp is kept next to the text rather than baked into it, since
the chat view finds the sender by splitting the line at the first colon.

Fixes #15444

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JvJR8oJNSCimCM9KXVLjfq
2026-09-04 13:10:54 -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 cc0ece038c Clean up the string type in RequestCallback - somehow was both char* and std::string????
Might be related to #21695
2026-05-18 14:16:34 +02:00
Katharine Chui 0f219edcc9 fix street rider sending pdp packets using wrong pdp dst addresses in relay mode
In P2P mode, this issue was solved by resolving the final IP
address without the first byte. Fix the issue again for relay mode
by resolving the true mac address before sending.

True mac resolving was also added to relay mode ptp connect as a
precaution.
2026-03-17 17:40:31 +01:00
Henrik Rydgård b01001a2e0 Merge pull request #21116 from Kethen/aemu_postoffice_integrate_v2
Support adhoc relay from aemu to ppsspp
2026-01-20 15:10:07 +01:00
Katharine Chui f1bd8aca34 save g_Config.bServerHasRelay at adhoc startup 2026-01-19 22:32:04 +01:00
Henrik Rydgård 1d2f846c66 Partial drive-by cleanup of quick chat code 2026-01-19 17:14:24 +01:00
Henrik Rydgård f4dbff0f14 Merge branch 'master' into aemu_postoffice_integrate_v2 2026-01-19 11:40:38 +01:00
MMaZaHaKa aa350b3082 upd proAdhoc 2026-01-16 06:17:03 +02:00
Katharine Chui f03b6d76b2 code formatting cleanup 2026-01-15 21:05:08 +01:00
Katharine Chui 3c38b5cfe1 rework ptp connect in relay mode, logic cleanup 2026-01-14 00:53:29 +01:00
Katharine Chui 97a3f1df91 implement nonblock ptp connect 2026-01-13 02:13:18 +01:00
Henrik Rydgård ed940a9d38 Introduce alias maps built from the reference translation 2025-08-22 14:04:34 +02: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 921fd32969 8 vars moved to NetAdhocCommon, 1 var moved to sceNetAdhocMatching 2025-07-01 19:56:09 +03:00
AdamN 2a59e75ea3 This too. 2025-04-13 16:16:46 +07:00
Henrik Rydgård cf059ff84c Stub a lua console, add the sol lua wrapper library 2025-03-27 08:59:37 +01:00
Henrik Rydgård 698a98c9bb Merge pull request #19927 from hrydgard/more-network-work
Add a hidden option to not download infra-dns.json, instead use the file from assets
2025-01-28 14:13:22 +01:00
Henrik Rydgård 8818e440ad Add a hidden option to not download infra-dns.json, instead use the file from assets 2025-01-28 13:45:28 +01:00
Henrik Rydgård ae2d5c1b41 getLocalIp: Have the fallback path keep looking if the IP found is 127.0.0.1
Fixes #19919
2025-01-28 13:32:31 +01:00
Henrik Rydgård 57b6850ea0 Pause screen improvements 2025-01-22 11:50:01 +01:00
Henrik Rydgård a710faf27b Remove the Network Connected/Shutdown popups. Replace with more info on pause screen 2025-01-21 18:07:52 +01:00
Henrik Rydgård c7078f31fd Rename "networkInited" to g_adhocServerConnected, which is what it is 2025-01-20 20:58:22 +01:00