From ce81c07a693d936cd3c24c2bc33cbedeca3546fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 28 Oct 2026 15:48:39 +0100 Subject: [PATCH] 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 --- Core/HLE/sceNetAdhocMatching.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Core/HLE/sceNetAdhocMatching.cpp b/Core/HLE/sceNetAdhocMatching.cpp index f926b76496..01a9be8102 100644 --- a/Core/HLE/sceNetAdhocMatching.cpp +++ b/Core/HLE/sceNetAdhocMatching.cpp @@ -1925,10 +1925,13 @@ int NetAdhocMatching_Start(int matchingId, int evthPri, int evthPartitionId, int // Create & Start the Fake PSP Thread ("matching_ev%d" and "matching_io%d") netAdhocMatchingValidateLoopMemory(); std::string thrname = std::string("MatchingThr") + std::to_string(matchingId); - matchingThreads[item->matching_thid] = hleCall(ThreadManForUser, int, sceKernelCreateThread, thrname.c_str(), matchingThreadHackAddr, evthPri, evthStack, 0, 0); + // Created and started without rescheduling, like adhocctl's thread: starting it through + // sceKernelStartThread switched threads inside this call, and the game got the thread's ID back + // instead of 0 (pspautotests net/adhoc/matching). + matchingThreads[item->matching_thid] = __KernelCreateThread(thrname.c_str(), __KernelGetCurThreadModuleId(), matchingThreadHackAddr, evthPri, evthStack, PSP_THREAD_ATTR_USER, 0, true); //item->matchingThread = new HLEHelperThread(thrname.c_str(), "sceNetAdhocMatching", "__NetMatchingCallbacks", inthPri, inthStack); if (matchingThreads[item->matching_thid] > 0) { - hleCall(ThreadManForUser, int, sceKernelStartThread, matchingThreads[item->matching_thid], 0, 0); //sceKernelStartThread(context->event_thid, sizeof(context), &context); + __KernelStartThread(matchingThreads[item->matching_thid], 0, 0); //item->matchingThread->Start(matchingId, 0); }