Commit Graph
478 Commits
Author SHA1 Message Date
Henrik RydgårdandClaude Opus 5.5 dc450f79b3 sceNetAdhoc: Hand out socket IDs in increasing order, like the PSP
A PSP numbers adhoc sockets in increasing order instead of reusing the
lowest free ID, and a PDP or PTP create that fails its address or port
check, or finds the PDP port in use, uses up an ID too (pspautotests
net/adhoc/pdp and net/adhoc/ptp). Find free slots starting after the last
one handed out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 22:39:05 +01:00
Henrik RydgårdandClaude Opus 5.5 97b18b95bb sceNetAdhocPollSocket: Report what a PSP reports
On a PSP (pspautotests net/adhoc/poll):
- a PTP listener reports SEND and FLUSH, and ACCEPT with a connection
  waiting;
- a connected PTP socket reports SEND, CONNECT and FLUSH, and RECV with
  data waiting;
- a connection whose peer has closed reports DISCONNECT alone, and the
  call returns EXCEPTION_EVENT;
- an unknown ID puts INVALID in the first entry;
- a blocking poll with nothing to report by its timeout returns TIMEOUT,
  and one that hits a disconnected socket or the poll alert returns at
  once.

A connection PtpOpen started counts as connected once it's up. Sockets
still connecting keep PPSSPP's own events (Fate Unlimited Codes,
Bleach), and a refused connect still isn't reported, since PPSSPP keeps
retrying it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 22:39:05 +01:00
Henrik RydgårdandClaude Opus 5.5 0d089972a3 sceNetAdhoc: Socket alerts don't stop calls that can complete at once
On a PSP (pspautotests net/adhoc/alerts), PtpConnect on a connected
socket and PtpFlush with nothing left to send return 0 with their alerts
set, and the poll alert reports ALERT alone in revents. A connection
PtpOpen started counts as connected once it's up, even if no call has
looked at it since.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 22:39:05 +01:00
Henrik RydgårdandClaude Opus 5.5 7e44dc7e8d sceNetAdhocPdpCreate: Give port 0 a port in 0x1000-0x7FFF
On a PSP, a PDP socket created on port 0 gets a free port between
0x1000 and 0x7FFF (pspautotests net/adhoc/limits). The host picked
one instead, usually 0x8000 or above once the port offset was taken
off. Pick it the way PtpOpen already does for PTP, and try another if
the host port is taken. Port 0 still doesn't become the fixed port the
offset alone would give (Phantasy Star Portable 2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 22:39:05 +01:00
Henrik RydgårdandClaude Opus 5.5 b40c427807 Built-in relay: Pump every millisecond
Every message through the relay waited for the next pump, every 8 ms,
or 100 ms while nobody was connected, which is when a game's first
connection comes in. That was most of what a round trip took once the
emulators stopped running in frame bursts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 07:33:14 +01:00
Henrik RydgårdandClaude Opus 5.5 fc9a3d3a39 sceNetAdhoc: Give the built-in relay the port its client connects to
aemu_postoffice's default happens to match, but nothing tied the two.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 14:48:47 +01:00
Henrik RydgårdandClaude Opus 5.5 5e92e0e02a sceNetAdhoc: Fix the built-in relay's thread
Join the old relay thread before starting a new one (assigning to a
joinable std::thread terminates), don't map the UPnP port when another
relay already has it, sleep the intended interval (the elapsed time was
subtracted the wrong way round), use one worker per pool, and guard the
log helper against empty messages. Drop the warning that the built-in
server doesn't support relay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 13:56:56 +01:00
Katharine Chui 92b00eb28a fix code formatting 2026-10-28 13:56:56 +01:00
Katharine Chui 7af6661cf0 add upnp call around relay server loop 2026-10-28 13:56:56 +01:00
Katharine Chui c8a9ed025a start aemu_postoffice relay with built-in adhoc server 2026-10-28 13:56:56 +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 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
Henrik RydgårdandClaude Opus 5.5 a4fe8e8f17 sceNetAdhoc: Don't fault on NULL pointers the PSP accepts
sceNetAdhocPdpSend with NULL data and a length of 0, sceNetAdhocPdpRecv
with a NULL sender MAC or port, and sceNetAdhocPtpSend with a NULL length
pointer all raised a memory exception before the call ran, which stopped
the game. On a PSP the first two succeed and the last returns INVALID_ARG
(net/adhoc/pdp and net/adhoc/ptp in pspautotests).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 17:13:45 +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 07190a820d adhoc load state bring up adhoc before adhocctl and bring down adhoc after adhocctl 2026-10-21 18:13:40 +02:00
Katharine Chui c086eab2ed spin down aemu_postoffice during netAdhocInited -> !netAdhocInited load state transition 2026-10-21 16:22:57 +02:00
Katharine Chui 23dadb11bf fix savestate enet thread handling again 2026-10-21 15:39:32 +02:00
Katharine Chui 8474ca35b6 guard built-in server warnings with isLocalServer 2026-10-21 14:29:16 +02:00
Katharine Chui 3662d69fb0 restore port offset hint on udp bind failure 2026-10-21 14:19:55 +02:00
Katharine Chui b8297795ef fix relay + built-in server warning reading stale serverHasRelay 2026-10-21 14:19:55 +02:00
Katharine Chui 3c35584f47 join aemuPostofficeEnetThread if active during load state 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 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 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
Henrik RydgårdandClaude Opus 5.5 19e4b77be4 Android: Ask for the local network permission for ad hoc, UPnP and servers
Part of #21585

Android 17 blocks LAN traffic in both directions (TCP and UDP, including
broadcast and multicast) without ACCESS_LOCAL_NETWORK. Ask for it when
networking, the built-in ad hoc server, UPnP, share-on-startup or the
remote debugger gets turned on, when a game initializes ad hoc with
networking enabled, and at startup if a server is set to start then.

A denied ad hoc send fails with EPERM, which the games never see, so show
a message for it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-16 20:44:05 +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
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 11c6111027 Only show the relay mode notification if networking is enabled 2026-09-19 13:02:44 -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 0596ee97f6 More memory access cleanup 2026-08-11 20:14:01 +02:00
Henrik Rydgård 3bd41376da More memory cleanup 2026-08-11 20:12:10 +02:00
Henrik Rydgård 3c81d6b121 More manual Read_U32 cleanup
Buildfix
2026-08-11 10:28:36 +02:00
Katharine Chui 01849c251e use new aemu_postoffice apis during polling 2026-07-19 11:30:27 +02:00
Katharine Chui ff83e8c896 bump aemu_postoffice
- Make GetPdpStat behave more like in P2P mode
  - Now fetches accumulated ready to be received amount of data
    instead of only the immediate to be received Pdp block
- Make GetPtpStat behave more like in P2P mode
  - Now fetches accumulated ready to be received amount of data
    instead of the size of the next server send block
- Make PtpRecv behave more like in P2P mode
  - Fix block like behavior where whole server send block has
    to be consumed before getting data from the next send block
  - Fix block like bahavior where sender sends in small PtpSend
    calls while receiver receive with less frequent but bigger
    buffer PtpRecv causes bloat(and eventually server kick)
    on relay
2026-07-19 11:30:27 +02:00
Henrik Rydgård 61e76fcf68 Add the ability to hide adhoc servers using a "hidden" entry in the json.
Useful when servers are temporarily down.
2026-04-23 11:12:58 +02:00
Henrik Rydgård d9ee8cb538 Fix json parsing bugs, add data.json for Relay Brasiliero 2026-04-05 12:57:41 -06:00
Henrik Rydgård c63d30508e GamesNexus also has data.json. Also, do an inventory of favicons. Not many usable... 2026-03-30 16:05:29 -06:00
Henrik Rydgård 6a977bd27f Fix bug preventing us from loading the server list from the server 2026-03-30 13:51:27 -06:00
Henrik Rydgård cfc5d74602 Some progress with server status UI 2026-03-30 11:34:19 -06:00
Henrik Rydgård 90f52b88a1 Initial work on downloading and showing the status from adhoc servers 2026-03-28 12:41:34 -06:00
Katharine Chui f1f6f3d75f fix the warriors in relay mode
The behavior of https://github.com/hrydgard/ppsspp/pull/13967 was
missing in relay mode, adding that back.

Also skips ptp flush in relay mode.
2026-03-19 19:00:08 +01: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 ae08b31573 Avoid the HTTP request on sceNetAdhoc init by reading from cache 2026-03-09 10:50:24 +01:00
Henrik Rydgård 71d884379d Fix a potential race condition 2026-03-09 00:51:39 +01:00
Henrik Rydgård cf9ee07b8e Adhoc: Forgot that we have to load the server list in-game to check the connection mode 2026-03-09 00:44:56 +01:00
Henrik Rydgård f6dda460f9 Translate relay connection messages 2026-03-09 00:19:36 +01:00
Henrik Rydgård d5c2a7ce62 Change some message timeouts 2026-03-09 00:19:36 +01:00
Henrik Rydgård ba6ff9a224 Improve the adhoc server selector a little bit, add metadata viewer 2026-03-08 00:31:29 +01:00
Henrik Rydgård 781be0d251 Add missing fallback for loading the adhoc server list 2026-03-07 09:52:20 +01:00