From 54300eb017325f7806c98b5a9680b4d446581e0b Mon Sep 17 00:00:00 2001 From: ANR2ME Date: Mon, 28 Feb 2022 16:20:03 +0700 Subject: [PATCH] Updated NP Library PS: Some of registered modules should probably moved to a separate files (ie. sceNp2.cpp). --- Core/HLE/sceNp.cpp | 886 +++++++++++++++++++++++++++++++++++++++++---- Core/HLE/sceNp.h | 432 +++++++++++++++++++++- 2 files changed, 1225 insertions(+), 93 deletions(-) diff --git a/Core/HLE/sceNp.cpp b/Core/HLE/sceNp.cpp index 3bd9d228b0..fd6eb1563c 100644 --- a/Core/HLE/sceNp.cpp +++ b/Core/HLE/sceNp.cpp @@ -26,25 +26,39 @@ #include #include "Core/HLE/HLE.h" #include "Core/HLE/FunctionWrappers.h" - #include "Core/HLE/sceNp.h" -#include bool npAuthInited = false; +int npSigninState = NP_SIGNIN_STATUS_NONE; SceNpAuthMemoryStat npAuthMemStat = {}; -std::string serviceId = ""; +SceNpAuthMemoryStat npMatching2MemStat = {}; +PSPTimeval npSigninTimestamp{}; -int parentalControl = PARENTAL_CONTROL_ENABLED; -int userAge = 24; // faking user Age to 24 yo -int chatRestriction = 0; // default/initial value on Patapon 3 is 1 (restricted boolean?) -std::string onlineId = "DummyOnlineId"; -std::string avatarUrl = "http://DummyAvatarUrl"; +// TODO: These should probably be grouped in a struct, since they're used to generate an auth ticket +int npParentalControl = PARENTAL_CONTROL_ENABLED; +int npUserAge = 24; // faking user Age to 24 yo +int npChatRestriction = 0; // default/initial value on Patapon 3 is 1 (restricted boolean?) +SceNpMyLanguages npMyLangList = { 1033, 2057, 1036 }; +char npCountryCode[3] = "fr"; // dummy data taken from https://www.psdevwiki.com/ps3/X-I-5-Ticket +char npRegionCode[3] = "c9"; // not sure what "c9" meant, since it was close to country code data, might be region-related data? +std::string npOnlineId = "DummyOnlineId"; // SceNpOnlineId struct? +std::string npServiceId = ""; // UNO game uses EP2006-NPEH00020_00 +std::string npAvatarUrl = "http://DummyAvatarUrl"; // SceNpAvatarUrl struct? + +bool npMatching2Inited = false; +SceNpCommunicationId npTitleId; std::recursive_mutex npAuthEvtMtx; std::deque npAuthEvents; std::map npAuthHandlers; +// TODO: Moves NpMatching2-related stuff to sceNp2.cpp +std::recursive_mutex npMatching2EvtMtx; +std::deque npMatching2Events; +std::map npMatching2Handlers; +//std::map npMatching2Contexts; + // Tickets data are in big-endian based on captured packets int writeTicketParam(u8* buffer, const u16_be type, const char* data = nullptr, const u16_be size = 0) { @@ -53,7 +67,8 @@ int writeTicketParam(u8* buffer, const u16_be type, const char* data = nullptr, u16_be sz = (data == nullptr)? static_cast(0): size; memcpy(buffer, &type, 2); memcpy(buffer + 2, &sz, 2); - if (sz>0) memcpy(buffer + 4, data, sz); + if (sz > 0 && data != nullptr) + memcpy(buffer + 4, data, sz); return sz + 4; } @@ -98,40 +113,163 @@ void notifyNpAuthHandlers(u32 id, u32 result, u32 argAddr) { npAuthEvents.push_back({ id, result, argAddr }); } +// serverId: 0 on 0x0103/0x0104/0x0105/0x0107/0x0108/0x0109/0x010a/0x010b/0x010c/0x010d (ie. when already joined to a server?) +// unk1~unk5 usually 0, +// unk1: 1st 32-bit of LeaveRoom/etc's Arg2 on 0x0103/0x0104/0x0105/0x0107/0x0108/0x0109/0x010a/0x010b/0x010c/0x010d/0x010e +// unk2: 2nd 32-bit of LeaveRoom/etc's Arg2 on 0x0103/0x0104/0x0105/0x0107/0x0108/0x0109/0x010a/0x010b/0x010c/0x010d/0x010e +// unk5: 1 on 0x0002/0x0003/0x0005/0x0006/0x0007/0x0101/0x0102/0x0106 +// unk6 (new state?): 8-bit?(masked with 0xff) 0x01 on 0x0001, 0x03 on 0x0002, 0x04 on 0x0003, 0x05 on 0x0004, 0x06 on 0x0005, 0x07 on 0x0006, 0x08 on 0x0007, +// 0x09 on 0x0101, 0x0A on 0x0102, 0x0C on 0x0103, 0x0D on 0x0104, 0x0E on 0x0105, 0x0F on 0x0106, 0x10 on 0x0107, 0x11 on 0x0108, +// 0x12 on 0x0109, 0x13 on 0x010a, 0x14 on 0x010b, 0x15 on 0x010c, 0x16 on 0x010d, 0x17 on 0x010e, 0x18 on 0xa102 +void notifyNpMatching2Handlers(NpMatching2Args &args, u32 ctxId, u32 serverId, u32 cbFuncAddr, u32 cbArgAddr, u32 unk3, u32 unk4, u32 unk5, u8 unk6) { + std::lock_guard npMatching2Guard(npMatching2EvtMtx); + // TODO: separate/map each list per ctxId + npMatching2Events.push_back(args); +} + static int sceNpInit() { - ERROR_LOG(HLE, "UNIMPL %s()", __FUNCTION__); + ERROR_LOG(SCENET, "UNIMPL %s()", __FUNCTION__); return 0; } static int sceNpTerm() { // No parameters - ERROR_LOG(HLE, "UNIMPL %s()", __FUNCTION__); + ERROR_LOG(SCENET, "UNIMPL %s()", __FUNCTION__); return 0; } static int sceNpGetContentRatingFlag(u32 parentalControlAddr, u32 userAgeAddr) { - WARN_LOG(HLE, "UNTESTED %s(%08x, %08x)", __FUNCTION__, parentalControlAddr, userAgeAddr); + WARN_LOG(SCENET, "UNTESTED %s(%08x, %08x)", __FUNCTION__, parentalControlAddr, userAgeAddr); if (!Memory::IsValidAddress(parentalControlAddr) || !Memory::IsValidAddress(userAgeAddr)) - return hleLogError(HLE, SCE_NP_ERROR_INVALID_ARGUMENT, "invalid arg"); + return hleLogError(SCENET, SCE_NP_ERROR_INVALID_ARGUMENT, "invalid arg"); - Memory::Write_U32(parentalControl, parentalControlAddr); - Memory::Write_U32(userAge, userAgeAddr); + INFO_LOG(SCENET, "%s - Parental Control: %d", __FUNCTION__, npParentalControl); + INFO_LOG(SCENET, "%s - User Age: %d", __FUNCTION__, npUserAge); + + Memory::Write_U32(npParentalControl, parentalControlAddr); + Memory::Write_U32(npUserAge, userAgeAddr); return 0; } static int sceNpGetChatRestrictionFlag(u32 flagAddr) { - WARN_LOG(HLE, "UNTESTED %s(%08x)", __FUNCTION__, flagAddr); + WARN_LOG(SCENET, "UNTESTED %s(%08x)", __FUNCTION__, flagAddr); if (!Memory::IsValidAddress(flagAddr)) - return hleLogError(HLE, SCE_NP_ERROR_INVALID_ARGUMENT, "invalid arg"); + return hleLogError(SCENET, SCE_NP_ERROR_INVALID_ARGUMENT, "invalid arg"); - Memory::Write_U32(chatRestriction, flagAddr); + INFO_LOG(SCENET, "%s - Chat Restriction: %d", __FUNCTION__, npChatRestriction); + + Memory::Write_U32(npChatRestriction, flagAddr); + + return 0; +} + +static int sceNpGetOnlineId(u32 idPtr) +{ + WARN_LOG(SCENET, "UNTESTED %s(%08x)", __FUNCTION__, idPtr); + + if (!Memory::IsValidAddress(idPtr)) + return hleLogError(SCENET, SCE_NP_ERROR_INVALID_ARGUMENT, "invalid arg"); + + SceNpOnlineId dummyOnlineId{}; + truncate_cpy(dummyOnlineId.data, sizeof(dummyOnlineId.data), npOnlineId.c_str()); + + INFO_LOG(SCENET, "%s - Online ID: %s", __FUNCTION__, dummyOnlineId.data); + + Memory::WriteStruct(idPtr, &dummyOnlineId); + + return 0; +} + +int NpGetNpId(SceNpId* npid) +{ + truncate_cpy(npid->handle.data, sizeof(npid->handle.data), npOnlineId.c_str()); + return 0; +} + +static int sceNpGetNpId(u32 idPtr) +{ + WARN_LOG(SCENET, "UNTESTED %s(%08x)", __FUNCTION__, idPtr); + + if (!Memory::IsValidAddress(idPtr)) + return hleLogError(SCENET, SCE_NP_ERROR_INVALID_ARGUMENT, "invalid arg"); + + SceNpId dummyNpId{}; + int retval = NpGetNpId(&dummyNpId); + if (retval < 0) + return hleLogError(SCENET, retval); + + INFO_LOG(SCENET, "%s - Online ID: %s", __FUNCTION__, dummyNpId.handle.data); + std::string datahex; + DataToHexString(dummyNpId.opt, sizeof(dummyNpId.opt), &datahex); + INFO_LOG(SCENET, "%s - Options?: %s", __FUNCTION__, datahex.c_str()); + + Memory::WriteStruct(idPtr, &dummyNpId); + + return 0; +} + +static int sceNpGetAccountRegion(u32 countryCodePtr, u32 regionCodePtr) +{ + WARN_LOG(SCENET, "UNTESTED %s(%08x, %08x)", __FUNCTION__, countryCodePtr, regionCodePtr); + + if (!Memory::IsValidAddress(countryCodePtr) || !Memory::IsValidAddress(regionCodePtr)) + return hleLogError(SCENET, SCE_NP_ERROR_INVALID_ARGUMENT, "invalid arg"); + + SceNpCountryCode dummyCountryCode{}; + memcpy(dummyCountryCode.data, npCountryCode, sizeof(dummyCountryCode.data)); + SceNpCountryCode dummyRegionCode{}; + memcpy(dummyRegionCode.data, npRegionCode, sizeof(dummyRegionCode.data)); + + INFO_LOG(SCENET, "%s - Country Code: %d", __FUNCTION__, dummyCountryCode.data); + INFO_LOG(SCENET, "%s - Region? Code: %d", __FUNCTION__, dummyRegionCode.data); + + Memory::WriteStruct(countryCodePtr, &dummyCountryCode); + Memory::WriteStruct(regionCodePtr, &dummyRegionCode); + + return 0; +} + +static int sceNpGetMyLanguages(u32 langListPtr) +{ + WARN_LOG(SCENET, "UNTESTED %s(%08x)", __FUNCTION__, langListPtr); + + if (!Memory::IsValidAddress(langListPtr)) + return hleLogError(SCENET, SCE_NP_ERROR_INVALID_ARGUMENT, "invalid arg"); + + INFO_LOG(SCENET, "%s - Language1 Code: %d", __FUNCTION__, npMyLangList.language1); + INFO_LOG(SCENET, "%s - Language2 Code: %d", __FUNCTION__, npMyLangList.language2); + INFO_LOG(SCENET, "%s - Language3 Code: %d", __FUNCTION__, npMyLangList.language3); + + Memory::WriteStruct(langListPtr, &npMyLangList); + + return 0; +} + +static int sceNpGetUserProfile(u32 profilePtr) +{ + WARN_LOG(SCENET, "UNTESTED %s(%08x)", __FUNCTION__, profilePtr); + + if (!Memory::IsValidAddress(profilePtr)) + return hleLogError(SCENET, SCE_NP_ERROR_INVALID_ARGUMENT, "invalid arg"); + + SceNpUserInformation dummyProfile{}; + truncate_cpy(dummyProfile.userId.handle.data, sizeof(dummyProfile.userId.handle.data), npOnlineId.c_str()); + truncate_cpy(dummyProfile.icon.data, sizeof(dummyProfile.icon.data), npAvatarUrl.c_str()); + + INFO_LOG(SCENET, "%s - Online ID: %s", __FUNCTION__, dummyProfile.userId.handle.data); + std::string datahex; + DataToHexString(dummyProfile.userId.opt, sizeof(dummyProfile.userId.opt), &datahex); + INFO_LOG(SCENET, "%s - Options?: %s", __FUNCTION__, datahex.c_str()); + INFO_LOG(SCENET, "%s - Avatar URL: %s", __FUNCTION__, dummyProfile.icon.data); + + Memory::WriteStruct(profilePtr, &dummyProfile); return 0; } @@ -141,6 +279,11 @@ const HLEFunction sceNp[] = { {0X37E1E274, &WrapI_V, "sceNpTerm", 'i', "" }, {0XBB069A87, &WrapI_UU, "sceNpGetContentRatingFlag", 'i', "xx" }, {0X1D60AE4B, &WrapI_U, "sceNpGetChatRestrictionFlag", 'i', "x" }, + {0x4B5C71C8, &WrapI_U, "sceNpGetOnlineId", 'i', "x" }, + {0x633B5F71, &WrapI_U, "sceNpGetNpId", 'i', "x" }, + {0x7E0864DF, &WrapI_U, "sceNpGetUserProfile", 'i', "x" }, + {0xA0BE3C4B, &WrapI_UU, "sceNpGetAccountRegion", 'i', "xx" }, + {0xCDCC21D3, &WrapI_U, "sceNpGetMyLanguages", 'i', "x" }, }; void Register_sceNp() @@ -151,29 +294,29 @@ void Register_sceNp() static int sceNpAuthTerm() { // No parameters - ERROR_LOG(HLE, "UNIMPL %s()", __FUNCTION__); + ERROR_LOG(SCENET, "UNIMPL %s()", __FUNCTION__); npAuthInited = false; return 0; } static int sceNpAuthInit(u32 poolSize, u32 stackSize, u32 threadPrio) { - ERROR_LOG(HLE, "UNIMPL %s(%d, %d, %d)", __FUNCTION__, poolSize, stackSize, threadPrio); - npAuthMemStat.npMemSize = poolSize; - npAuthMemStat.npMaxMemSize = poolSize / 2; // Dummy - npAuthMemStat.npFreeMemSize = poolSize - 16; // Dummy. + ERROR_LOG(SCENET, "UNIMPL %s(%d, %d, %d)", __FUNCTION__, poolSize, stackSize, threadPrio); + npAuthMemStat.npMemSize = poolSize - 0x20; + npAuthMemStat.npMaxMemSize = 0x4050; // Dummy maximum foot print + npAuthMemStat.npFreeMemSize = npAuthMemStat.npMemSize; npAuthEvents.clear(); npAuthInited = true; return 0; } -static int sceNpAuthGetMemoryStat(u32 memStatAddr) +int sceNpAuthGetMemoryStat(u32 memStatAddr) { - ERROR_LOG(HLE, "UNIMPL %s(%08x)", __FUNCTION__, memStatAddr); + ERROR_LOG(SCENET, "UNIMPL %s(%08x)", __FUNCTION__, memStatAddr); if (!Memory::IsValidAddress(memStatAddr)) - return hleLogError(HLE, SCE_NP_AUTH_ERROR_INVALID_ARGUMENT, "invalid arg"); + return hleLogError(SCENET, SCE_NP_AUTH_ERROR_INVALID_ARGUMENT, "invalid arg"); Memory::WriteStruct(memStatAddr, &npAuthMemStat); @@ -192,22 +335,23 @@ param seems to be a struct where offset: +20: 32-bit a pointer to a random data (4 to 8-bytes data max? both 2x 32-bit seems to be a valid pointer). optional handler args? return value >= 0 and <0 seems to be stored at a different location by the game (valid result vs error code?) */ -static int sceNpAuthCreateStartRequest(u32 paramAddr) +int sceNpAuthCreateStartRequest(u32 paramAddr) { - WARN_LOG(HLE, "UNTESTED %s(%08x) at %08x", __FUNCTION__, paramAddr, currentMIPS->pc); + WARN_LOG(SCENET, "UNTESTED %s(%08x) at %08x", __FUNCTION__, paramAddr, currentMIPS->pc); if (!Memory::IsValidAddress(paramAddr)) - return hleLogError(HLE, SCE_NP_AUTH_ERROR_INVALID_ARGUMENT, "invalid arg"); + return hleLogError(SCENET, SCE_NP_AUTH_ERROR_INVALID_ARGUMENT, "invalid arg"); SceNpAuthRequestParameter params = {}; int size = Memory::Read_U32(paramAddr); Memory::Memcpy(¶ms, paramAddr, size); - serviceId = Memory::GetCharPointer(params.serviceIdAddr); + npServiceId = Memory::GetCharPointer(params.serviceIdAddr); - INFO_LOG(HLE, "%s - Max Version: %u.%u", __FUNCTION__, params.version.major, params.version.minor); - INFO_LOG(HLE, "%s - Service ID: %s", __FUNCTION__, Memory::GetCharPointer(params.serviceIdAddr)); - INFO_LOG(HLE, "%s - Entitlement ID: %s", __FUNCTION__, Memory::GetCharPointer(params.entitlementIdAddr)); - INFO_LOG(HLE, "%s - Cookie (size = %d): %s", __FUNCTION__, params.cookieSize, Memory::GetCharPointer(params.cookieAddr)); + INFO_LOG(SCENET, "%s - Max Version: %u.%u", __FUNCTION__, params.version.major, params.version.minor); + INFO_LOG(SCENET, "%s - Service ID: %s", __FUNCTION__, Memory::GetCharPointer(params.serviceIdAddr)); + INFO_LOG(SCENET, "%s - Entitlement ID: %s", __FUNCTION__, Memory::GetCharPointer(params.entitlementIdAddr)); + INFO_LOG(SCENET, "%s - Consumed Count: %d", __FUNCTION__, params.consumedCount); + INFO_LOG(SCENET, "%s - Cookie (size = %d): %s", __FUNCTION__, params.cookieSize, Memory::GetCharPointer(params.cookieAddr)); u32 retval = 0; if (params.size >= 32 && params.ticketCbAddr != 0) { @@ -254,12 +398,12 @@ static int sceNpAuthCreateStartRequest(u32 paramAddr) // Used within callback of sceNpAuthCreateStartRequest (arg1 = callback's args[0], arg2 = output structPtr?, arg3 = callback's args[1]) // Is this using request id for Arg1 or cbId? // JPCSP is using length = 248 for dummy ticket -static int sceNpAuthGetTicket(u32 requestId, u32 bufferAddr, u32 length) +int sceNpAuthGetTicket(u32 requestId, u32 bufferAddr, u32 length) { - ERROR_LOG(HLE, "UNIMPL %s(%d, %08x, %d) at %08x", __FUNCTION__, requestId, bufferAddr, length, currentMIPS->pc); + ERROR_LOG(SCENET, "UNIMPL %s(%d, %08x, %d) at %08x", __FUNCTION__, requestId, bufferAddr, length, currentMIPS->pc); if (!Memory::IsValidAddress(bufferAddr)) - return hleLogError(HLE, SCE_NP_AUTH_ERROR_INVALID_ARGUMENT, "invalid arg"); + return hleLogError(SCENET, SCE_NP_AUTH_ERROR_INVALID_ARGUMENT, "invalid arg"); int result = length; Memory::Memset(bufferAddr, 0, length); @@ -269,35 +413,35 @@ static int sceNpAuthGetTicket(u32 requestId, u32 bufferAddr, u32 length) ticket.header.size = 0xF0; // size excluding the header u8* buf = Memory::GetPointerWrite(bufferAddr + sizeof(ticket)); int ofs = 0; - ofs += writeTicketParam(buf, PARAM_TYPE_STRING_ASCII, "\x4c\x47\x56\x3b\x81\x39\x4a\x22\xd8\x6b\xc1\x57\x71\x6e\xfd\xb8\xab\x63\xcc\x51", 20); // 20 random letters, token key? + ofs += writeTicketParam(buf, PARAM_TYPE_STRING_ASCII, "\x4c\x47\x56\x3b\x81\x39\x4a\x22\xd8\x6b\xc1\x57\x71\x6e\xfd\xb8\xab\x63\xcc\x51", 20); // 20 random letters, token key or SceNpSignature? ofs += writeTicketU32Param(buf + ofs, PARAM_TYPE_INT, 0x0100); // a flags? - PSPTimeval tv; + PSPTimeval tv; //npSigninTimestamp __RtcTimeOfDay(&tv); u64 now = 1000ULL*tv.tv_sec + tv.tv_usec/1000ULL; // in milliseconds, since 1900? ofs += writeTicketU64Param(buf + ofs, PARAM_TYPE_DATE, now); ofs += writeTicketU64Param(buf + ofs, PARAM_TYPE_DATE, now + 10 * 60 * 1000); // now + 10 minutes, expired time? ofs += writeTicketU64Param(buf + ofs, PARAM_TYPE_LONG, 0x592e71c546e86859); // seems to be consistent, 8-bytes password hash may be? or related to entitlement? or console id? - ofs += writeTicketStringParam(buf + ofs, PARAM_TYPE_STRING, onlineId.c_str(), 32); // username - ofs += writeTicketParam(buf + ofs, PARAM_TYPE_STRING_ASCII, "fr\0\2", 4); // SceNpCountryCode ? ie. "fr" + 00 02 - ofs += writeTicketStringParam(buf + ofs, PARAM_TYPE_STRING, "c9", 4); // 2-char code? related to country/lang code? ie. "c9" + 00 00 - ofs += writeTicketParam(buf + ofs, PARAM_TYPE_STRING_ASCII, serviceId.c_str(), 24); + ofs += writeTicketStringParam(buf + ofs, PARAM_TYPE_STRING, npOnlineId.c_str(), 32); // username + ofs += writeTicketParam(buf + ofs, PARAM_TYPE_STRING_ASCII, npCountryCode, 4); // SceNpCountryCode ? ie. "fr" + 00 02 + ofs += writeTicketStringParam(buf + ofs, PARAM_TYPE_STRING, npRegionCode, 4); // 2-char code? related to country/lang code? ie. "c9" + 00 00 + ofs += writeTicketParam(buf + ofs, PARAM_TYPE_STRING_ASCII, npServiceId.c_str(), 24); int status = 0; - if (parentalControl == PARENTAL_CONTROL_ENABLED) { + if (npParentalControl == PARENTAL_CONTROL_ENABLED) { status |= STATUS_ACCOUNT_PARENTAL_CONTROL_ENABLED; } - status |= (userAge & 0x7F) << 24; + status |= (npUserAge & 0x7F) << 24; ofs += writeTicketU32Param(buf + ofs, PARAM_TYPE_INT, status); ofs += writeTicketParam(buf + ofs, PARAM_TYPE_NULL); ofs += writeTicketParam(buf + ofs, PARAM_TYPE_NULL); ticket.section.type = SECTION_TYPE_BODY; ticket.section.size = ofs; Memory::WriteStruct(bufferAddr, &ticket); - SceNpTicketSection footer = { SECTION_TYPE_FOOTER, 32 }; // footer section? ie. 32-bytes on ver 2.1 containing 4-chars ASCII + 20-chars ASCII + SceNpTicketSection footer = { SECTION_TYPE_FOOTER, 32 }; // footer section? ie. 32-bytes on version 2.1 containing 4-chars ASCII + 20-chars ASCII Memory::WriteStruct(bufferAddr + sizeof(ticket) + ofs, &footer); ofs += sizeof(footer); ofs += writeTicketParam(buf + ofs, PARAM_TYPE_STRING_ASCII, "\x34\xcd\x3c\xa9", 4); - ofs += writeTicketParam(buf + ofs, PARAM_TYPE_STRING_ASCII, "\x3a\x4b\x42\x66\x92\xda\x6b\x7c\xb7\x4c\xe8\xd9\x4f\x2b\x77\x15\x91\xb8\xa4\xa9", 20); - u8 unknownBytes[36] = {}; + ofs += writeTicketParam(buf + ofs, PARAM_TYPE_STRING_ASCII, "\x3a\x4b\x42\x66\x92\xda\x6b\x7c\xb7\x4c\xe8\xd9\x4f\x2b\x77\x15\x91\xb8\xa4\xa9", 20); // 20 random letters, token key or SceNpSignature? + u8 unknownBytes[36] = {}; // includes Language list? Memory::WriteStruct(bufferAddr + sizeof(ticket) + ofs, unknownBytes); result = ticket.header.size + sizeof(ticket.header); // dummy ticket is 248 bytes @@ -307,28 +451,30 @@ static int sceNpAuthGetTicket(u32 requestId, u32 bufferAddr, u32 length) // Used within callback of sceNpAuthCreateStartRequest (arg1 = structPtr?, arg2 = callback's args[1], arg3 = DLCcode? ie. "EP9000-UCES01421_00-DLL001", arg4 = Patapon 3 always set to 0?) // Patapon 3 will loop (for each DLC?) through an array of 4+4 bytes, ID addr (pchar) + result (int). Each loop calls this function using the same ticket addr but use different ID addr (arg3) and store the return value in result field (default/initial = -1) -static int sceNpAuthGetEntitlementById(u32 ticketBufferAddr, u32 ticketLength, u32 entitlementIdAddr, u32 arg4) +int sceNpAuthGetEntitlementById(u32 ticketBufferAddr, u32 ticketLength, u32 entitlementIdAddr, u32 arg4) { - ERROR_LOG(HLE, "UNIMPL %s(%08x, %d, %08x, %d)", __FUNCTION__, ticketBufferAddr, ticketLength, entitlementIdAddr, arg4); - INFO_LOG(HLE, "%s - Entitlement ID: %s", __FUNCTION__, Memory::GetCharPointer(entitlementIdAddr)); + ERROR_LOG(SCENET, "UNIMPL %s(%08x, %d, %08x, %d)", __FUNCTION__, ticketBufferAddr, ticketLength, entitlementIdAddr, arg4); + INFO_LOG(SCENET, "%s - Entitlement ID: %s", __FUNCTION__, Memory::GetCharPointer(entitlementIdAddr)); + // Do we return the entitlement through function result? or update the ticket content? or replace the arg3 data with SceNpEntitlement struct? return 1; // dummy value assuming it's a boolean/flag, since we don't know how to return the entitlement result yet } -static int sceNpAuthAbortRequest(int requestId) +int sceNpAuthAbortRequest(int requestId) { - WARN_LOG(HLE, "UNTESTED %s(%i)", __FUNCTION__, requestId); + WARN_LOG(SCENET, "UNTESTED %s(%i)", __FUNCTION__, requestId); // TODO: Disconnect HTTPS connection & cancel the callback event std::lock_guard npAuthGuard(npAuthEvtMtx); for (auto it = npAuthEvents.begin(); it != npAuthEvents.end(); ) { (it->data[0] == requestId) ? it = npAuthEvents.erase(it) : ++it; } + return 0; } -static int sceNpAuthDestroyRequest(int requestId) +int sceNpAuthDestroyRequest(int requestId) { - WARN_LOG(HLE, "UNTESTED %s(%i)", __FUNCTION__, requestId); + WARN_LOG(SCENET, "UNTESTED %s(%i)", __FUNCTION__, requestId); // Remove callback handler int handlerID = requestId - 1; if (npAuthHandlers.find(handlerID) != npAuthHandlers.end()) { @@ -338,20 +484,50 @@ static int sceNpAuthDestroyRequest(int requestId) else { ERROR_LOG(SCENET, "%s: Invalid request ID %d", __FUNCTION__, requestId); } + // Patapon 3 is checking for error code 0x80550402 return 0; } +int sceNpAuthGetTicketParam(u32 ticketBufPtr, int ticketLen, int paramNum, u32 bufferPtr) +{ + ERROR_LOG(SCENET, "UNIMPL %s(%08x, %0d, %d, %08x) at %08x", __FUNCTION__, ticketBufPtr, ticketLen, paramNum, bufferPtr, currentMIPS->pc); + const u32 PARAM_BUFFER_MAX_SIZE = 256; + Memory::Memset(bufferPtr, 0, PARAM_BUFFER_MAX_SIZE); // JPCSP: This clear is always done, even when an error is returned + if (paramNum < 0 || paramNum >= NUMBER_PARAMETERS) { + return SCE_NP_MANAGER_ERROR_INVALID_ARGUMENT; + } + + SceNpTicket* ticket = (SceNpTicket*)Memory::GetPointer(ticketBufPtr); + u32 inbuf = ticketBufPtr; + inbuf += sizeof(ticket->header); + inbuf += ticket->section.size + sizeof(ticket->section); + u32 outbuf = bufferPtr; + for (int i = 0; i < paramNum; i++) { + SceNpTicketParamData* ticketParam = (SceNpTicketParamData*)Memory::GetPointer(inbuf); + u32 sz = (u32)sizeof(SceNpTicketParamData) + ticketParam->length; + Memory::Memcpy(outbuf, inbuf, sz); + DEBUG_LOG(SCENET, "%s - Param #%d: Type = %04x, Length = %u", __FUNCTION__, i, ticketParam->type, static_cast(ticketParam->length)); + outbuf += sz; + inbuf += sz; + if (outbuf - bufferPtr >= PARAM_BUFFER_MAX_SIZE || inbuf - ticketBufPtr >= (u32)ticketLen) + break; + } + + return 0; +} const HLEFunction sceNpAuth[] = { - {0X4EC1F667, &WrapI_V, "sceNpAuthTerm", 'i', "" }, - {0XA1DE86F8, &WrapI_UUU, "sceNpAuthInit", 'i', "xxx" }, - {0XF4531ADC, &WrapI_U, "sceNpAuthGetMemoryStat", 'i', "x" }, - {0XCD86A656, &WrapI_U, "sceNpAuthCreateStartRequest", 'i', "x" }, - {0X3F1C1F70, &WrapI_UUU, "sceNpAuthGetTicket", 'i', "xxx" }, - {0X6900F084, &WrapI_UUUU, "sceNpAuthGetEntitlementById", 'i', "xxxx" }, - {0XD99455DD, &WrapI_I, "sceNpAuthAbortRequest", 'i', "i" }, - {0X72BB0467, &WrapI_I, "sceNpAuthDestroyRequest", 'i', "i" }, + {0X4EC1F667, &WrapI_V, "sceNpAuthTerm", 'i', "" }, + {0XA1DE86F8, &WrapI_UUU, "sceNpAuthInit", 'i', "xxx" }, + {0XF4531ADC, &WrapI_U, "sceNpAuthGetMemoryStat", 'i', "x" }, + {0XCD86A656, &WrapI_U, "sceNpAuthCreateStartRequest", 'i', "x" }, + {0X3F1C1F70, &WrapI_UUU, "sceNpAuthGetTicket", 'i', "xxx" }, + {0X6900F084, &WrapI_UUUU, "sceNpAuthGetEntitlementById", 'i', "xxxx" }, + {0XD99455DD, &WrapI_I, "sceNpAuthAbortRequest", 'i', "i" }, + {0X72BB0467, &WrapI_I, "sceNpAuthDestroyRequest", 'i', "i" }, + {0x5A3CB57A, &WrapI_UIIU, "sceNpAuthGetTicketParam", 'i', "xiix" }, + {0x75FB0AE3, nullptr, "sceNpAuthGetEntitlementIdList", 'i', "" }, }; void Register_sceNpAuth() @@ -362,46 +538,90 @@ void Register_sceNpAuth() static int sceNpServiceTerm() { // No parameters - ERROR_LOG(HLE, "UNIMPL %s()", __FUNCTION__); + ERROR_LOG(SCENET, "UNIMPL %s()", __FUNCTION__); return 0; } static int sceNpServiceInit(u32 poolSize, u32 stackSize, u32 threadPrio) { - ERROR_LOG(HLE, "UNIMPL %s(%08x, %08x, %08x)", __FUNCTION__, poolSize, stackSize, threadPrio); + ERROR_LOG(SCENET, "UNIMPL %s(%08x, %08x, %08x)", __FUNCTION__, poolSize, stackSize, threadPrio); return 0; } +// FIXME: On Patapon 3 the Arg is pointing to a String, but based on RPCS3 the Arg is an Id integer ? static int sceNpLookupCreateTransactionCtx(u32 lookupTitleCtxIdAddr) { - ERROR_LOG(HLE, "UNIMPL %s(%08x)", __FUNCTION__, lookupTitleCtxIdAddr); + ERROR_LOG(SCENET, "UNIMPL %s(%08x)", __FUNCTION__, lookupTitleCtxIdAddr); INFO_LOG(SCENET, "%s - Title ID: %s", __FUNCTION__, Memory::GetCharPointer(lookupTitleCtxIdAddr)); // Patapon 3 will only Destroy if returned Id > 0. Is 0 a valid id? return 1; // returning dummy transaction id } // transId: id returned from sceNpLookupCreateTransactionCtx -static int sceNpLookupDestroyTransactionCtx(u32 transId) +static int sceNpLookupDestroyTransactionCtx(s32 transId) { - ERROR_LOG(HLE, "UNIMPL %s(%d)", __FUNCTION__, transId); + ERROR_LOG(SCENET, "UNIMPL %s(%d)", __FUNCTION__, transId); return 0; } // transId: id returned from sceNpLookupCreateTransactionCtx // Patapon 3 always set Arg5 to 0 // Addr args have something to do with GameUpdate? -static int sceNpLookupTitleSmallStorage(u32 transId, u32 arg2Addr, u32 arg3, u32 arg4Addr, u32 arg5) +// FIXME: maxSize and contentLength are u64 based on https://github.com/RPCS3/rpcs3/blob/master/rpcs3/Emu/Cell/Modules/sceNp.cpp ? But on Patapon 3 optionAddr will be deadbeef if maxSize is u64 ? +static int sceNpLookupTitleSmallStorage(s32 transId, u32 dataAddr, u32 maxSize, u32 contentLengthAddr, u32 optionAddr) { - ERROR_LOG(HLE, "UNIMPL %s(%d, %08x, %08x, %08x, %08x)", __FUNCTION__, transId, arg2Addr, arg3, arg4Addr, arg5); + ERROR_LOG(SCENET, "UNIMPL %s(%d, %08x, %d, %08x[%d], %08x) at %08x", __FUNCTION__, transId, dataAddr, maxSize, contentLengthAddr, (Memory::IsValidAddress(contentLengthAddr)? Memory::Read_U32(contentLengthAddr): 0), optionAddr, currentMIPS->pc); + return 0; +} + +// On Resistance Retribution: +// unknownAddr pointing to a struct of: +// 32-bit pointer (ie. 08efc6c4)? or a timestamp combined with the next 32-bit value? +// 32-bit pointer (ie. 08f9d101)? but unaligned (the lowest byte seems to be intentionally set to 1)? so probably not a pointer, may be a timestamp combined with previous 32-bit value? +// 32-bit pointer? Seems to be pointing to dummy ticket data generated by sceNpAuthGetTicket +// 32-bit value (248) dummy ticket length from NpAuth Ticket? +// There could be more data in the struct? (at least 48-bytes?) +static int sceNpRosterCreateRequest(u32 unknownAddr) +{ + ERROR_LOG(SCENET, "UNIMPL %s(%08x) at %08x", __FUNCTION__, unknownAddr, currentMIPS->pc); + return 1; // returning dummy roster id +} + +// On Resistance Retribution: +// unknown1 set to 50 (max entries?), +// unknown2 set to 0, +// unknown3Addr pointing to unset buffer? (output entry data? usually located right after number of entries?), +// unknown4Addr pointing to 32-bit value set to 0 (output number of entries?), +// unknown5Addr pointing to zeroed buffer?, +// unknown6 set to 0 +static int sceNpRosterGetFriendListEntry(s32 rosterId, u32 unknown1, u32 unknown2, u32 unknown3Addr, u32 unknown4Addr, u32 unknown5Addr, u32 unknown6) +{ + ERROR_LOG(SCENET, "UNIMPL %s(%d, %08x, %08x, %08x, %08x, %08x, %08x) at %08x", __FUNCTION__, rosterId, unknown1, unknown2, unknown3Addr, unknown4Addr, unknown5Addr, unknown6, currentMIPS->pc); + return 0; +} + +static int sceNpRosterAbort(s32 rosterId) +{ + ERROR_LOG(SCENET, "UNIMPL %s(%d) at %08x", __FUNCTION__, rosterId, currentMIPS->pc); + return 0; +} + +static int sceNpRosterDeleteRequest(s32 rosterId) +{ + ERROR_LOG(SCENET, "UNIMPL %s(%d) at %08x", __FUNCTION__, rosterId, currentMIPS->pc); return 0; } const HLEFunction sceNpService[] = { - {0X00ACFAC3, &WrapI_V, "sceNpServiceTerm", 'i', "" }, - {0X0F8F5821, &WrapI_UUU, "sceNpServiceInit", 'i', "xxx" }, - {0X5494274B, &WrapI_U, "sceNpLookupCreateTransactionCtx", 'i', "x" }, - {0XA670D3A3, &WrapI_U, "sceNpLookupDestroyTransactionCtx", 'i', "x" }, - {0XC76F55ED, &WrapI_UUUUU, "sceNpLookupTitleSmallStorage", 'i', "xxxxx" }, + {0X00ACFAC3, &WrapI_V, "sceNpServiceTerm", 'i', "" }, + {0X0F8F5821, &WrapI_UUU, "sceNpServiceInit", 'i', "xxx" }, + {0X5494274B, &WrapI_U, "sceNpLookupCreateTransactionCtx", 'i', "x" }, + {0XA670D3A3, &WrapI_I, "sceNpLookupDestroyTransactionCtx", 'i', "i" }, + {0XC76F55ED, &WrapI_IUUUU, "sceNpLookupTitleSmallStorage", 'i', "ixxxx" }, + {0XBE22EEA3, &WrapI_U, "sceNpRosterCreateRequest", 'i', "x" }, + {0X4E851B10, &WrapI_IUUUUUU, "sceNpRosterGetFriendListEntry", 'i', "ixxxxxx"}, + {0X5F5E32AF, &WrapI_I, "sceNpRosterAbort", 'i', "i" }, + {0X66C64821, &WrapI_I, "sceNpRosterDeleteRequest", 'i', "i" }, }; void Register_sceNpService() @@ -409,6 +629,7 @@ void Register_sceNpService() RegisterModule("sceNpService", ARRAY_SIZE(sceNpService), sceNpService); } +// TODO: Moves NpCommerce2-related stuff to sceNpCommerce2.cpp const HLEFunction sceNpCommerce2[] = { {0X005B5F20, nullptr, "sceNpCommerce2GetProductInfoStart", '?', "" }, {0X0E9956E3, nullptr, "sceNpCommerce2Init", '?', "" }, @@ -432,3 +653,518 @@ void Register_sceNpCommerce2() { RegisterModule("sceNpCommerce2", ARRAY_SIZE(sceNpCommerce2), sceNpCommerce2); } + +static int sceNpMatching2Init(int poolSize, int threadPriority, int cpuAffinityMask, int threadStackSize) +{ + ERROR_LOG(SCENET, "UNIMPL %s(%d, %d, %d, %d) at %08x", __FUNCTION__, poolSize, threadPriority, cpuAffinityMask, threadStackSize, currentMIPS->pc); + //if (npMatching2Inited) + // return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_ALREADY_INITIALIZED); + + npMatching2MemStat.npMemSize = poolSize - 0x20; + npMatching2MemStat.npMaxMemSize = 0x4050; // Dummy maximum foot print + npMatching2MemStat.npFreeMemSize = npMatching2MemStat.npMemSize; + + npMatching2Handlers.clear(); + npMatching2Events.clear(); + npMatching2Inited = true; + return 0; +} + +static int sceNpMatching2Term() +{ + ERROR_LOG(SCENET, "UNIMPL %s() at %08x", __FUNCTION__, currentMIPS->pc); + npMatching2Inited = false; + npMatching2Handlers.clear(); + npMatching2Events.clear(); + + return 0; +} + +static int sceNpMatching2CreateContext(u32 communicationIdPtr, u32 passPhrasePtr, u32 ctxIdPtr, int unknown) +{ + ERROR_LOG(SCENET, "UNIMPL %s(%08x[%s], %08x[%08x], %08x[%d], %d) at %08x", __FUNCTION__, communicationIdPtr, Memory::GetCharPointer(communicationIdPtr), passPhrasePtr, Memory::Read_U32(passPhrasePtr), ctxIdPtr, Memory::Read_U16(ctxIdPtr), unknown, currentMIPS->pc); + if (!npMatching2Inited) + return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED); + + if (!Memory::IsValidAddress(communicationIdPtr) || !Memory::IsValidAddress(passPhrasePtr) || !Memory::IsValidAddress(ctxIdPtr)) + return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_CONTEXT_MAX); + + // FIXME: It seems Context are mapped to TitleID? may return 0x80550C05 or 0x80550C06 when finding an existing context + SceNpCommunicationId* titleid = (SceNpCommunicationId*)Memory::GetCharPointer(communicationIdPtr); + memcpy(npTitleId.data, titleid->data, sizeof(npTitleId)); + + SceNpCommunicationPassphrase* passph = (SceNpCommunicationPassphrase*)Memory::GetCharPointer(passPhrasePtr); + + SceNpId npid{}; + int retval = NpGetNpId(&npid); + if (retval < 0) + return hleLogError(SCENET, retval); + + INFO_LOG(SCENET, "%s - Title ID: %s", __FUNCTION__, titleid->data); + INFO_LOG(SCENET, "%s - Online ID: %s", __FUNCTION__, npid.handle.data); + std::string datahex; + DataToHexString(npid.opt, sizeof(npid.opt), &datahex); + INFO_LOG(SCENET, "%s - Options?: %s", __FUNCTION__, datahex.c_str()); + datahex.clear(); + DataToHexString(10, 0, passph->data, sizeof(passph->data), &datahex); + INFO_LOG(SCENET, "%s - Passphrase: \n%s", __FUNCTION__, datahex.c_str()); + + // TODO: Allocate & zeroed a memory of 68 bytes where npId (36 bytes) is copied to offset 8, offset 44 = 0x00026808, offset 48 = 0 + + // Returning dummy Id, a 16-bit variable according to JPCSP + // FIXME: It seems ctxId need to be in the range of 1 to 7 to be valid ? + Memory::Write_U16(1, ctxIdPtr); + return 0; +} + +static int sceNpMatching2ContextStart(int ctxId) +{ + ERROR_LOG(SCENET, "UNIMPL %s(%d) at %08x", __FUNCTION__, ctxId, currentMIPS->pc); + if (!npMatching2Inited) + return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED); + + //if (!npMatching2Ctx) + // return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_FOUND); //SCE_NP_MATCHING2_ERROR_INVALID_CONTEXT_ID + + //if (npMatching2Ctx.started) + // return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_CONTEXT_ALREADY_STARTED); + + // TODO: use sceNpGetUserProfile and check server availability using sceNpService_76867C01 + //npMatching2Ctx.started = true; + Url url("http://static-resource.np.community.playstation.net/np/resource/psp-title/" + std::string(npTitleId.data) + "_00/matching/" + std::string(npTitleId.data) + "_00-matching.xml"); + http::Client client; + http::RequestProgress progress; + if (!client.Resolve(url.Host().c_str(), url.Port())) { + return hleLogError(SCENET, SCE_NP_COMMUNITY_SERVER_ERROR_NO_SUCH_TITLE, "HTTP failed to resolve %s", url.Resource().c_str()); + } + + client.SetDataTimeout(20.0); + if (client.Connect()) { + char requestHeaders[4096]; + snprintf(requestHeaders, sizeof(requestHeaders), + "User-Agent: PS3Community-agent/1.0.0 libhttp/1.0.0\r\n"); + + DEBUG_LOG(SCENET, "GET URI: %s", url.ToString().c_str()); + http::RequestParams req(url.Resource(), "*/*"); + int err = client.SendRequest("GET", req, requestHeaders, &progress); + if (err < 0) { + client.Disconnect(); + return hleLogError(SCENET, SCE_NP_COMMUNITY_SERVER_ERROR_NO_SUCH_TITLE, "HTTP GET Error = %d", err); + } + + net::Buffer readbuf; + std::vector responseHeaders; + int code = client.ReadResponseHeaders(&readbuf, responseHeaders, &progress); + if (code != 200) { + client.Disconnect(); + return hleLogError(SCENET, SCE_NP_COMMUNITY_SERVER_ERROR_NO_SUCH_TITLE, "HTTP Error Code = %d", code); + } + + net::Buffer output; + int res = client.ReadResponseEntity(&readbuf, responseHeaders, &output, &progress); + if (res != 0) { + WARN_LOG(SCENET, "Unable to read HTTP response entity: %d", res); + } + client.Disconnect(); + + std::string entity; + size_t readBytes = output.size(); + output.Take(readBytes, &entity); + + // TODO: Use XML Parser to get the Tag and it's attributes instead of searching for keywords on the string + std::string text; + size_t ofs = entity.find("titleid="); + if (ofs == std::string::npos) + return hleLogError(SCENET, SCE_NP_COMMUNITY_SERVER_ERROR_NO_SUCH_TITLE, "titleid not found"); + + ofs += 9; + size_t ofs2 = entity.find('"', ofs); + text = entity.substr(ofs, ofs2-ofs); + INFO_LOG(SCENET, "%s - Title ID: %s", __FUNCTION__, text.c_str()); + + int i = 1; + while (true) { + ofs = entity.find("", ++ofs2); + if (ofs == std::string::npos) + return hleLogError(SCENET, SCE_NP_COMMUNITY_SERVER_ERROR_NO_SUCH_TITLE, "agent host not found"); + + ofs2 = entity.find("pc); + if (!npMatching2Inited) + return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED); + + //if (!npMatching2Ctx) + // return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_FOUND); //SCE_NP_MATCHING2_ERROR_INVALID_CONTEXT_ID + + //if (!npMatching2Ctx.started) + // return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_STARTED); + + //TODO: Stop any in-progress HTTPClient communication used on sceNpMatching2ContextStart + //npMatching2Ctx.started = false; + + return 0; +} + +static int sceNpMatching2DestroyContext(int ctxId) +{ + ERROR_LOG(SCENET, "UNIMPL %s(%d) at %08x", __FUNCTION__, ctxId, currentMIPS->pc); + if (!npMatching2Inited) + return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED); + + //if (!npMatching2Ctx) + // return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_FOUND); //SCE_NP_MATCHING2_ERROR_INVALID_CONTEXT_ID + + // Remove callback handler + int handlerID = ctxId - 1; + if (npMatching2Handlers.find(handlerID) != npMatching2Handlers.end()) { + npMatching2Handlers.erase(handlerID); + WARN_LOG(SCENET, "%s: Deleted handler %d", __FUNCTION__, handlerID); + } + else { + ERROR_LOG(SCENET, "%s: Invalid Context ID %d", __FUNCTION__, ctxId); + } + + return 0; +} + +static int sceNpMatching2GetMemoryStat(u32 memStatPtr) +{ + ERROR_LOG(SCENET, "UNIMPL %s(%08x) at %08x", __FUNCTION__, memStatPtr, currentMIPS->pc); + if (!npMatching2Inited) + return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED); + + if (!Memory::IsValidAddress(memStatPtr)) + return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_INVALID_ARGUMENT); + + Memory::WriteStruct(memStatPtr, &npMatching2MemStat); + + return 0; +} + +static int sceNpMatching2RegisterSignalingCallback(int ctxId, u32 callbackFunctionAddr, u32 callbackArgument) +{ + ERROR_LOG(SCENET, "UNIMPL %s(%d, %08x, %08x) at %08x", __FUNCTION__, ctxId, callbackFunctionAddr, callbackArgument, currentMIPS->pc); + if (!npMatching2Inited) + return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED); + + if (ctxId <= 0) + return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_INVALID_CONTEXT_ID); + + int id = ctxId - 1; + if (callbackFunctionAddr != 0) { + bool foundHandler = false; + + struct NpMatching2Handler handler; + memset(&handler, 0, sizeof(handler)); + + handler.entryPoint = callbackFunctionAddr; + handler.argument = callbackArgument; + + for (std::map::iterator it = npMatching2Handlers.begin(); it != npMatching2Handlers.end(); it++) { + if (it->second.entryPoint == handler.entryPoint) { + foundHandler = true; + id = it->first; + break; + } + } + + if (!foundHandler && Memory::IsValidAddress(handler.entryPoint)) { + npMatching2Handlers[id] = handler; + WARN_LOG(SCENET, "%s - Added handler(%08x, %08x) : %d", __FUNCTION__, handler.entryPoint, handler.argument, id); + } + else { + ERROR_LOG(SCENET, "%s - Same handler(%08x, %08x) already exists", __FUNCTION__, handler.entryPoint, handler.argument); + } + + //u32 dataLength = 4097; + //notifyNpMatching2Handlers(retval, dataLength, handler.argument); + + // callback struct have 57 * u32? where [0]=0, [40]=flags, [55]=callbackFunc, and [56]=callbackArgs? + //hleEnqueueCall(callbackFunctionAddr, 7, (u32*)Memory::GetPointer(callbackArgument), nullptr); // 7 args? since the callback handler is trying to use t2 register + } + return 0; +} + +static int sceNpMatching2GetServerIdListLocal(int ctxId, u32 serverIdsPtr, int maxServerIds) +{ + ERROR_LOG(SCENET, "UNIMPL %s(%d, %08x, %d) at %08x", __FUNCTION__, ctxId, serverIdsPtr, maxServerIds, currentMIPS->pc); + if (!npMatching2Inited) + return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED); + + if (!Memory::IsValidAddress(serverIdsPtr)) + return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_INVALID_ARGUMENT); + + // Returning dummy Id, a 16-bit variable according to JPCSP + for (int i = 0; i < maxServerIds; i++) + Memory::Write_U16(1234+i, serverIdsPtr+(i*2)); + + return maxServerIds; // dummy value +} + +// Unknown1 = optParam, unknown2 = assignedReqId according to https://github.com/RPCS3/rpcs3/blob/master/rpcs3/Emu/Cell/Modules/sceNp2.cpp ? +static int sceNpMatching2GetServerInfo(int ctxId, u32 serverIdPtr, u32 unknown1Ptr, u32 unknown2Ptr) +{ + ERROR_LOG(SCENET, "UNIMPL %s(%d, %08x[%d], %08x, %08x[%08x]) at %08x", __FUNCTION__, ctxId, serverIdPtr, Memory::Read_U16(serverIdPtr), unknown1Ptr, unknown2Ptr, Memory::Read_U32(unknown2Ptr), currentMIPS->pc); + if (!npMatching2Inited) + return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED); + + if (!Memory::IsValidAddress(serverIdPtr) || !Memory::IsValidAddress(unknown2Ptr)) + return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_CONTEXT_MAX); // Should be SCE_NP_MATCHING2_ERROR_INVALID_ARGUMENT ? + + // Server ID is a 16-bit variable according to JPCSP + int serverId = Memory::Read_U16(serverIdPtr); + + if (serverId == 0) + return hleLogError(SCENET, 0x80550CBF); // Should be SCE_NP_MATCHING2_ERROR_INVALID_SERVER_ID ? + + // Output to unknown1(infoBuffer)? and unknown2(infoLength or flags)? + // Patapon 3 is using serverId at 09FFF2F4, unknown1 at 09FFF2E4, unknown2 at 09FFF2E0, which mean unknown1's can only fit upto 16-bytes + // Patapon 3 seems to be copying data from unknown1 with a fixed size of 20-bytes? + // input unknown1 struct: based on Fat Princess (US) + // 0000 32-bit function address (callback?) 0x08A08B40 + // 0004 32-bit pointer to a struct? (callback args?) 0x09888158 (contains 32-bit (-1) + 32-bit (1) + 16-bit ctxId(0001) + 32bit 0x06913801? + 16-bit serverId(1234), so on), probably only 2x 32-bit struct? + // 0008 32-bit set to 0 + // 000a 16-bit set to 0 + // + u32 cbFunc = Memory::Read_U32(unknown1Ptr); + u32 cbArg = Memory::Read_U32(unknown1Ptr + 0x04); + + // Notify callback handler + if (Memory::IsValidAddress(cbFunc)) { + // The cbFunc seems to be storing s0~s4(s0 pointing to 0x0996DD58 containing data similar to 0x09888158 above on the 1st 2x 32-bit data, s1 seems to be ctxId, s2~s4=0xdeadbeef) into stack and use a0~t1 (6 args?): + // Arg1(a0) & Arg3(a2) are being masked with 0xffff (16-bit id?) + // This callback tried to load data from address 0x08BD4860+8 (not part of arg? which being set using content of unknown2 not long after returning from sceNpMatching2GetServerInfo, so we may need to give some delay before calling this callback) + // and comparing it with Arg2(a1), repeated by increasing the address 0x08BD4860 by 288 bytes on each loop for 64 times or until it found a matching one. + // When a match is found the callback will process the address further, otherwise exit the callback. + // Matching address struct: (zeroed before calling sceNpMatching2GetServerInfo? and set after returning from sceNpMatching2GetServerInfo?) + // 0000 32-bit func address (another callback?) 0x08A07EF4 + // 0008 32-bit value from unknown2 content, being set not long after returning from sceNpMatching2GetServerInfo + // 000c 32-bit unknown + // 0010 8-bit status to indicate not updated from callback yet? initially 0, set to 1 not long after returning from sceNpMatching2GetServerInfo (along with unknown2 content) + // + // There args are supposed to be constructed in the stack and the data need to be available even after returning from this function, so these args + optional data probably copied to somewhere + NpMatching2Args args = {}; + args.data[0] = PSP_NP_MATCHING2_EVENT_0001; + args.data[1] = PSP_NP_MATCHING2_STATE_1001; // or size of data? + args.data[2] = serverIdPtr; // serverId or was it pointing to optional data at last arg (ie. args[10] where serverId is stored)? + args.data[3] = unknown1Ptr; + //args.data[4] = a boolean(0/1) related to a u8 value from the struct at args[9] (value XOR 0x04 == 0) + args.data[5] = unknown2Ptr; + args.data[6] = 0; + //args.data[8] = 0 or a pointer to a struct related to context? + //args.data[9] = 0 or a pointer to a struct related to context and matched serverId? + //args.data[10] = serverId; + + notifyNpMatching2Handlers(args, ctxId, serverId, 0, 0, 0, 0, 0, 1); + + Memory::Write_U32(args.data[1], unknown2Ptr); // server status or flags? + } + + // After returning, Fat Princess will loop for 64 times (increasing the address by 288 bytes on each loop) or until found a zero status byte (0x08BD4860 + 0x10), looking for empty/available entry to set? + return 0; +} + +static int sceNpMatching2LeaveRoom(int ctxId, u32 reqParamPtr, u32 optParamPtr, u32 assignedReqIdPtr) +{ + ERROR_LOG(SCENET, "UNIMPL %s(%d, %08x, %08x, %08x[%08x]) at %08x", __FUNCTION__, ctxId, reqParamPtr, optParamPtr, assignedReqIdPtr, Memory::Read_U32(assignedReqIdPtr), currentMIPS->pc); + if (!npMatching2Inited) + return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED); + + if (!Memory::IsValidAddress(reqParamPtr) || !Memory::IsValidAddress(assignedReqIdPtr)) + return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_CONTEXT_MAX); // Should be SCE_NP_MATCHING2_ERROR_INVALID_ARGUMENT ? + + u32 cbFunc = Memory::Read_U32(reqParamPtr); + u32 cbArg = Memory::Read_U32(reqParamPtr + 0x04); + + // Notify callback handler + if (Memory::IsValidAddress(cbFunc)) { + // There args are supposed to be constructed in the stack and the data need to be available even after returning from this function, so these args + optional data probably copied to somewhere + NpMatching2Args args = {}; + args.data[0] = PSP_NP_MATCHING2_EVENT_0103; + args.data[1] = PSP_NP_MATCHING2_STATE_3202; + //args.data[2] = pointer to arg[8], where the 1st 20 bytes copied from (reqParamPtr+0x08), the rest of the struct are zeroed + args.data[3] = optParamPtr; + args.data[4] = 0; + args.data[5] = assignedReqIdPtr; + args.data[6] = 0; + //args.data[8] = an initially zeroed struct of 536 bytes where the 1st 20 bytes were taken from reqParam offset 0x08 + + notifyNpMatching2Handlers(args, ctxId, 0, cbFunc, cbArg, 0, 0, 0, 0x0c); + + Memory::Write_U32(args.data[1], assignedReqIdPtr); + } + + // After returning, Fat Princess will loop for 64 times (increasing the address by 288 bytes on each loop) or until found a zero status byte (0x08BD4860 + 0x10), looking for empty/available entry to set? + return 0; +} + +static int sceNpMatching2JoinRoom(int ctxId, u32 reqParamPtr, u32 optParamPtr, u32 unknown1, u32 unknown2, u32 assignedReqIdPtr) +{ + ERROR_LOG(SCENET, "UNIMPL %s(%d, %08x, %08x, %08x[%08x]) at %08x", __FUNCTION__, ctxId, reqParamPtr, optParamPtr, assignedReqIdPtr, Memory::Read_U32(assignedReqIdPtr), currentMIPS->pc); + if (!npMatching2Inited) + return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED); + + if (!Memory::IsValidAddress(reqParamPtr) || !Memory::IsValidAddress(assignedReqIdPtr)) + return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_CONTEXT_MAX); // Should be SCE_NP_MATCHING2_ERROR_INVALID_ARGUMENT ? + + // Server ID is a 16-bit variable according to JPCSP + int serverId = Memory::Read_U16(reqParamPtr + 0x06); + + if (serverId == 0) + return hleLogError(SCENET, 0x80550CBF); // Should be SCE_NP_MATCHING2_ERROR_INVALID_SERVER_ID ? + + u32 cbFunc = Memory::Read_U32(reqParamPtr); + u32 cbArg = Memory::Read_U32(reqParamPtr + 0x04); + + // Notify callback handler + if (Memory::IsValidAddress(cbFunc)) { + // There args are supposed to be constructed in the stack and the data need to be available even after returning from this function, so these args + optional data probably copied to somewhere + NpMatching2Args args = {}; + args.data[0] = PSP_NP_MATCHING2_EVENT_0102; + args.data[1] = PSP_NP_MATCHING2_STATE_1209; + //args.data[2] = pointer to arg[8] (optional data?) + args.data[3] = optParamPtr; + args.data[4] = 0; + args.data[5] = assignedReqIdPtr; + args.data[6] = 0; + // Followed by optional data? + args.data[8] = reqParamPtr; // an initially zeroed struct of 1224 bytes, where the 1st 32bit is set to reqParamPtr + args.data[9] = unknown1; + args.data[10] = unknown2; + + notifyNpMatching2Handlers(args, ctxId, serverId, 0, 0, 0, 0, 1, 0x0a); + + Memory::Write_U32(args.data[1], assignedReqIdPtr); + } + + // After returning, Fat Princess will loop for 64 times (increasing the address by 288 bytes on each loop) or until found a zero status byte (0x08BD4860 + 0x10), looking for empty/available entry to set? + return 0; +} + +static int sceNpMatching2SearchRoom(int ctxId, u32 reqParamPtr, u32 optParamPtr, u32 assignedReqIdPtr) +{ + ERROR_LOG(SCENET, "UNIMPL %s(%d, %08x, %08x, %08x[%08x]) at %08x", __FUNCTION__, ctxId, reqParamPtr, optParamPtr, assignedReqIdPtr, Memory::Read_U32(assignedReqIdPtr), currentMIPS->pc); + if (!npMatching2Inited) + return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED); + + if (!Memory::IsValidAddress(reqParamPtr) || !Memory::IsValidAddress(assignedReqIdPtr)) + return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_CONTEXT_MAX); // Should be SCE_NP_MATCHING2_ERROR_INVALID_ARGUMENT ? + + u32 cbFunc = Memory::Read_U32(reqParamPtr); + u32 cbArg = Memory::Read_U32(reqParamPtr + 0x04); + + // Notify callback handler + if (Memory::IsValidAddress(cbFunc)) { + // There args are supposed to be constructed in the stack and the data need to be available even after returning from this function, so these args + optional data probably copied to somewhere + NpMatching2Args args = {}; + // TODO: Set the correct callback args + + Memory::Write_U32(args.data[1], assignedReqIdPtr); // server status or flags? + } + + return 0; +} + +static int sceNpMatching2SendRoomChatMessage(int ctxId, u32 reqParamPtr, u32 optParamPtr, u32 assignedReqIdPtr) +{ + ERROR_LOG(SCENET, "UNIMPL %s(%d, %08x, %08x, %08x[%08x]) at %08x", __FUNCTION__, ctxId, reqParamPtr, optParamPtr, assignedReqIdPtr, Memory::Read_U32(assignedReqIdPtr), currentMIPS->pc); + if (!npMatching2Inited) + return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED); + + if (!Memory::IsValidAddress(reqParamPtr) || !Memory::IsValidAddress(assignedReqIdPtr)) + return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_CONTEXT_MAX); // Should be SCE_NP_MATCHING2_ERROR_INVALID_ARGUMENT ? + + u32 cbFunc = Memory::Read_U32(reqParamPtr); + u32 cbArg = Memory::Read_U32(reqParamPtr + 0x04); + + // Notify callback handler + if (Memory::IsValidAddress(cbFunc)) { + // There args are supposed to be constructed in the stack and the data need to be available even after returning from this function, so these args + optional data probably copied to somewhere + NpMatching2Args args = {}; + args.data[0] = PSP_NP_MATCHING2_EVENT_0107; + args.data[1] = PSP_NP_MATCHING2_STATE_3208; + //args.data[2] = pointer to arg[8] + args.data[3] = optParamPtr; + args.data[4] = 0; + args.data[5] = assignedReqIdPtr; + args.data[6] = 0; + //args.data[8] = reqParamPtr; + + notifyNpMatching2Handlers(args, ctxId, 0, cbFunc, cbArg, 0, 0, 0, 0x10); + + Memory::Write_U32(args.data[1], assignedReqIdPtr); // server status or flags? + } + + // After returning, Fat Princess will loop for 64 times (increasing the address by 288 bytes on each loop) or until found a zero status byte (0x08BD4860 + 0x10), looking for empty/available entry to set? + return 0; +} + +const HLEFunction sceNpMatching2[] = { + {0x2E61F6E1, &WrapI_IIII, "sceNpMatching2Init", 'i', "iiii" }, + {0x8BF37D8C, &WrapI_V, "sceNpMatching2Term", 'i', "" }, + {0x5030CC53, &WrapI_UUUI, "sceNpMatching2CreateContext", 'i', "xxxi" }, + {0x190FF903, &WrapI_I, "sceNpMatching2ContextStart", 'i', "i" }, + {0x2B3892FC, &WrapI_I, "sceNpMatching2ContextStop", 'i', "i" }, + {0x3DE70241, &WrapI_I, "sceNpMatching2DestroyContext", 'i', "i" }, + {0x22F38DAF, &WrapI_U, "sceNpMatching2GetMemoryStat", 'i', "x" }, + {0xA3C298D1, &WrapI_IUU, "sceNpMatching2RegisterSignalingCallback", 'i', "ixx" }, + {0xF47342FC, &WrapI_IUI, "sceNpMatching2GetServerIdListLocal", 'i', "ixi" }, + {0x4EE3A8EC, &WrapI_IUUU, "sceNpMatching2GetServerInfo", 'i', "ixxx" }, + {0xC870535A, &WrapI_IUUU, "sceNpMatching2LeaveRoom", 'i', "ixxx" }, + {0xAAD0946A, &WrapI_IUUUUU, "sceNpMatching2JoinRoom", 'i', "ixxxxx" }, + {0x81C13E6D, &WrapI_IUUU, "sceNpMatching2SearchRoom", 'i', "ixxx" }, + {0x55F7837F, &WrapI_IUUU, "sceNpMatching2SendRoomChatMessage", 'i', "ixxx" }, +}; + +void Register_sceNpMatching2() +{ + RegisterModule("sceNpMatching2", ARRAY_SIZE(sceNpMatching2), sceNpMatching2); +} diff --git a/Core/HLE/sceNp.h b/Core/HLE/sceNp.h index 3c117b33c7..0be9f0ca54 100644 --- a/Core/HLE/sceNp.h +++ b/Core/HLE/sceNp.h @@ -17,9 +17,13 @@ #pragma once -#ifdef _MSC_VER +#include +#include "Common/Net/HTTPClient.h" +#include "Common/Net/Resolve.h" +#include "Common/Net/URL.h" + + #pragma pack(push,1) -#endif // Based on https://playstationdev.wiki/psvitadevwiki/index.php?title=Error_Codes #define SCE_NP_ERROR_ALREADY_INITIALIZED 0x80550001 @@ -47,6 +51,261 @@ #define SCE_NP_AUTH_ERROR_SERVICE_END 0x80550400 #define SCE_NP_AUTH_ERROR_SERVICE_DOWN 0x80550401 #define SCE_NP_AUTH_ERROR_SERVICE_BUSY 0x80550402 +#define SCE_NP_AUTH_ERROR_SERVER_MAINTENANCE 0x80550403 +#define SCE_NP_AUTH_ERROR_UNKNOWN 0x80550480 + +#define SCE_NP_MANAGER_ERROR_ALREADY_INITIALIZED 0x80550501 +#define SCE_NP_MANAGER_ERROR_NOT_INITIALIZED 0x80550502 +#define SCE_NP_MANAGER_ERROR_INVALID_ARGUMENT 0x80550503 +#define SCE_NP_MANAGER_ERROR_OUT_OF_MEMORY 0x80550504 +#define SCE_NP_MANAGER_ERROR_INVALID_TICKET_SIZE 0x80550505 +#define SCE_NP_MANAGER_ERROR_INVALID_STATE 0x80550506 +#define SCE_NP_MANAGER_ERROR_ABORTED 0x80550507 +#define SCE_NP_MANAGER_ERROR_VARIANT_ACCOUNT_ID 0x80550508 +#define SCE_NP_MANAGER_ERROR_ID_NOT_AVAIL 0x80550509 +#define SCE_NP_MANAGER_ERROR_SIGNOUT 0x8055050a +#define SCE_NP_MANAGER_ERROR_NOT_SIGNIN 0x8055050b + +#define SCE_NP_UTIL_ERROR_INVALID_ARGUMENT 0x80550601 +#define SCE_NP_UTIL_ERROR_INSUFFICIENT 0x80550602 +#define SCE_NP_UTIL_ERROR_PARSER_FAILED 0x80550603 +#define SCE_NP_UTIL_ERROR_INVALID_PROTOCOL_ID 0x80550604 +#define SCE_NP_UTIL_ERROR_INVALID_NP_ID 0x80550605 +#define SCE_NP_UTIL_ERROR_INVALID_NP_ENV 0x80550606 +#define SCE_NP_UTIL_ERROR_INVALID_NPCOMMID 0x80550607 +#define SCE_NP_UTIL_ERROR_INVALID_CHARACTER 0x80550608 +#define SCE_NP_UTIL_ERROR_NOT_MATCH 0x80550609 +#define SCE_NP_UTIL_ERROR_INVALID_TITLEID 0x8055060a +#define SCE_NP_UTIL_ERROR_INVALID_ESCAPE_STRING 0x8055060c +#define SCE_NP_UTIL_ERROR_UNKNOWN_TYPE 0x8055060d +#define SCE_NP_UTIL_ERROR_UNKNOWN 0x8055060e + +#define SCE_NP_COMMUNITY_ERROR_ALREADY_INITIALIZED 0x80550701 +#define SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED 0x80550702 +#define SCE_NP_COMMUNITY_ERROR_OUT_OF_MEMORY 0x80550703 +#define SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT 0x80550704 +#define SCE_NP_COMMUNITY_ERROR_NO_LOGIN 0x80550705 +#define SCE_NP_COMMUNITY_ERROR_TOO_MANY_OBJECTS 0x80550706 +#define SCE_NP_COMMUNITY_ERROR_ABORTED 0x80550707 +#define SCE_NP_COMMUNITY_ERROR_BAD_RESPONSE 0x80550708 +#define SCE_NP_COMMUNITY_ERROR_BODY_TOO_LARGE 0x80550709 +#define SCE_NP_COMMUNITY_ERROR_HTTP_SERVER 0x8055070a +#define SCE_NP_COMMUNITY_ERROR_INVALID_SIGNATURE 0x8055070b +#define SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT 0x8055070c +#define SCE_NP_COMMUNITY_ERROR_UNKNOWN_TYPE 0x8055070d +#define SCE_NP_COMMUNITY_ERROR_INVALID_ID 0x8055070e +#define SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID 0x8055070f +#define SCE_NP_COMMUNITY_ERROR_CONNECTION_HANDLE_ALREADY_EXISTS 0x80550710 +#define SCE_NP_COMMUNITY_ERROR_INVALID_TYPE 0x80550711 +#define SCE_NP_COMMUNITY_ERROR_TRANSACTION_ALREADY_END 0x80550712 +#define SCE_NP_COMMUNITY_ERROR_INVALID_PARTITION 0x80550713 +#define SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT 0x80550714 +#define SCE_NP_COMMUNITY_ERROR_CLIENT_HANDLE_ALREADY_EXISTS 0x80550715 +#define SCE_NP_COMMUNITY_ERROR_NO_RESOURCE 0x80550716 + +#define SCE_NP_COMMUNITY_SERVER_ERROR_BAD_REQUEST 0x80550801 +#define SCE_NP_COMMUNITY_SERVER_ERROR_INVALID_TICKET 0x80550802 +#define SCE_NP_COMMUNITY_SERVER_ERROR_INVALID_SIGNATURE 0x80550803 +#define SCE_NP_COMMUNITY_SERVER_ERROR_INVALID_NPID 0x80550805 +#define SCE_NP_COMMUNITY_SERVER_ERROR_FORBIDDEN 0x80550806 +#define SCE_NP_COMMUNITY_SERVER_ERROR_INTERNAL_SERVER_ERROR 0x80550807 +#define SCE_NP_COMMUNITY_SERVER_ERROR_VERSION_NOT_SUPPORTED 0x80550808 +#define SCE_NP_COMMUNITY_SERVER_ERROR_SERVICE_UNAVAILABLE 0x80550809 +#define SCE_NP_COMMUNITY_SERVER_ERROR_PLAYER_BANNED 0x8055080a +#define SCE_NP_COMMUNITY_SERVER_ERROR_CENSORED 0x8055080b +#define SCE_NP_COMMUNITY_SERVER_ERROR_RANKING_RECORD_FORBIDDEN 0x8055080c +#define SCE_NP_COMMUNITY_SERVER_ERROR_USER_PROFILE_NOT_FOUND 0x8055080d +#define SCE_NP_COMMUNITY_SERVER_ERROR_UPLOADER_DATA_NOT_FOUND 0x8055080e +#define SCE_NP_COMMUNITY_SERVER_ERROR_QUOTA_MASTER_NOT_FOUND 0x8055080f +#define SCE_NP_COMMUNITY_SERVER_ERROR_RANKING_TITLE_NOT_FOUND 0x80550810 +#define SCE_NP_COMMUNITY_SERVER_ERROR_BLACKLISTED_USER_ID 0x80550811 +#define SCE_NP_COMMUNITY_SERVER_ERROR_GAME_RANKING_NOT_FOUND 0x80550812 +#define SCE_NP_COMMUNITY_SERVER_ERROR_RANKING_STORE_NOT_FOUND 0x80550814 +#define SCE_NP_COMMUNITY_SERVER_ERROR_NOT_BEST_SCORE 0x80550815 +#define SCE_NP_COMMUNITY_SERVER_ERROR_LATEST_UPDATE_NOT_FOUND 0x80550816 +#define SCE_NP_COMMUNITY_SERVER_ERROR_RANKING_BOARD_MASTER_NOT_FOUND 0x80550817 +#define SCE_NP_COMMUNITY_SERVER_ERROR_RANKING_GAME_DATA_MASTER_NOT_FOUND 0x80550818 +#define SCE_NP_COMMUNITY_SERVER_ERROR_INVALID_ANTICHEAT_DATA 0x80550819 +#define SCE_NP_COMMUNITY_SERVER_ERROR_TOO_LARGE_DATA 0x8055081a +#define SCE_NP_COMMUNITY_SERVER_ERROR_NO_SUCH_USER_NPID 0x8055081b +#define SCE_NP_COMMUNITY_SERVER_ERROR_INVALID_ENVIRONMENT 0x8055081d +#define SCE_NP_COMMUNITY_SERVER_ERROR_INVALID_ONLINE_NAME_CHARACTER 0x8055081f +#define SCE_NP_COMMUNITY_SERVER_ERROR_INVALID_ONLINE_NAME_LENGTH 0x80550820 +#define SCE_NP_COMMUNITY_SERVER_ERROR_INVALID_ABOUT_ME_CHARACTER 0x80550821 +#define SCE_NP_COMMUNITY_SERVER_ERROR_INVALID_ABOUT_ME_LENGTH 0x80550822 +#define SCE_NP_COMMUNITY_SERVER_ERROR_INVALID_SCORE 0x80550823 +#define SCE_NP_COMMUNITY_SERVER_ERROR_OVER_THE_RANKING_LIMIT 0x80550824 +#define SCE_NP_COMMUNITY_SERVER_ERROR_FAIL_TO_CREATE_SIGNATURE 0x80550826 +#define SCE_NP_COMMUNITY_SERVER_ERROR_RANKING_MASTER_INFO_NOT_FOUND 0x80550827 +#define SCE_NP_COMMUNITY_SERVER_ERROR_OVER_THE_GAME_DATA_LIMIT 0x80550828 +#define SCE_NP_COMMUNITY_SERVER_ERROR_SELF_DATA_NOT_FOUND 0x8055082a +#define SCE_NP_COMMUNITY_SERVER_ERROR_USER_NOT_ASSIGNED 0x8055082b +#define SCE_NP_COMMUNITY_SERVER_ERROR_GAME_DATA_ALREADY_EXISTS 0x8055082c +#define SCE_NP_COMMUNITY_SERVER_ERROR_MATCHING_BEFORE_SERVICE 0x805508a0 +#define SCE_NP_COMMUNITY_SERVER_ERROR_MATCHING_END_OF_SERVICE 0x805508a1 +#define SCE_NP_COMMUNITY_SERVER_ERROR_MATCHING_MAINTENANCE 0x805508a2 +#define SCE_NP_COMMUNITY_SERVER_ERROR_RANKING_BEFORE_SERVICE 0x805508a3 +#define SCE_NP_COMMUNITY_SERVER_ERROR_RANKING_END_OF_SERVICE 0x805508a4 +#define SCE_NP_COMMUNITY_SERVER_ERROR_RANKING_MAINTENANCE 0x805508a5 +#define SCE_NP_COMMUNITY_SERVER_ERROR_NO_SUCH_TITLE 0x805508a6 +#define SCE_NP_COMMUNITY_SERVER_ERROR_TITLE_USER_STORAGE_BEFORE_SERVICE 0x805508aa +#define SCE_NP_COMMUNITY_SERVER_ERROR_TITLE_USER_STORAGE_END_OF_SERVICE 0x805508ab +#define SCE_NP_COMMUNITY_SERVER_ERROR_TITLE_USER_STORAGE_MAINTENANCE 0x805508ac +#define SCE_NP_COMMUNITY_SERVER_ERROR_FSR_BEFORE_SERVICE 0x805508ad +#define SCE_NP_COMMUNITY_SERVER_ERROR_FSR_END_OF_SERVICE 0x805508ae +#define SCE_NP_COMMUNITY_SERVER_ERROR_FSR_MAINTENANCE 0x805508af +#define SCE_NP_COMMUNITY_SERVER_ERROR_UBS_BEFORE_SERVICE 0x805508b1 +#define SCE_NP_COMMUNITY_SERVER_ERROR_UBS_END_OF_SERVICE 0x805508b2 +#define SCE_NP_COMMUNITY_SERVER_ERROR_UBS_MAINTENANCE 0x805508b3 +#define SCE_NP_COMMUNITY_SERVER_ERROR_UNSPECIFIED 0x805508ff + +// TODO: Moves NpMatching2-related stuff to sceNp2.h +// Based on https://gist.githubusercontent.com/raw/4140449/PS%20Vita (Might be slightly different with PSP?) +#define SCE_NP_MATCHING2_ERROR_OUT_OF_MEMORY 0x80550c01 +#define SCE_NP_MATCHING2_ERROR_ALREADY_INITIALIZED 0x80550c02 +#define SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED 0x80550c03 +#define SCE_NP_MATCHING2_ERROR_CONTEXT_MAX 0x80550c04 // might be "Invalid Argument" on PSP? +#define SCE_NP_MATCHING2_ERROR_CONTEXT_ALREADY_EXISTS 0x80550c05 // might be "Context Max/Context Id higher than 7" on PSP? +#define SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_FOUND 0x80550c06 +#define SCE_NP_MATCHING2_ERROR_CONTEXT_ALREADY_STARTED 0x80550c07 +#define SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_STARTED 0x80550c08 +#define SCE_NP_MATCHING2_ERROR_SERVER_NOT_FOUND 0x80550c09 +#define SCE_NP_MATCHING2_ERROR_INVALID_ARGUMENT 0x80550c0a +#define SCE_NP_MATCHING2_ERROR_INVALID_CONTEXT_ID 0x80550c0b +#define SCE_NP_MATCHING2_ERROR_INVALID_SERVER_ID 0x80550c0c +#define SCE_NP_MATCHING2_ERROR_INVALID_LOBBY_ID 0x80550c0e +#define SCE_NP_MATCHING2_ERROR_INVALID_ROOM_ID 0x80550c0f +#define SCE_NP_MATCHING2_ERROR_INVALID_MEMBER_ID 0x80550c10 +#define SCE_NP_MATCHING2_ERROR_INVALID_ATTRIBUTE_ID 0x80550c11 +#define SCE_NP_MATCHING2_ERROR_INVALID_CASTTYPE 0x80550c12 +#define SCE_NP_MATCHING2_ERROR_INVALID_SORT_METHOD 0x80550c13 +#define SCE_NP_MATCHING2_ERROR_INVALID_MAX_SLOT 0x80550c14 +#define SCE_NP_MATCHING2_ERROR_INVALID_OPT_SIZE 0x80550c15 +#define SCE_NP_MATCHING2_ERROR_INVALID_MATCHING_SPACE 0x80550c16 +#define SCE_NP_MATCHING2_ERROR_INVALID_BLOCK_KICK_FLAG 0x80550c18 +#define SCE_NP_MATCHING2_ERROR_INVALID_MESSAGE_TARGET 0x80550c19 +#define SCE_NP_MATCHING2_ERROR_RANGE_FILTER_MAX 0x80550c1a +#define SCE_NP_MATCHING2_ERROR_INVALID_ALIGNMENT 0x80550c1e +#define SCE_NP_MATCHING2_ERROR_CONNECTION_CLOSED_BY_SERVER 0x80550c22 +#define SCE_NP_MATCHING2_ERROR_SSL_VERIFY_FAILED 0x80550c23 +#define SCE_NP_MATCHING2_ERROR_SSL_HANDSHAKE 0x80550c24 +#define SCE_NP_MATCHING2_ERROR_SSL_SEND 0x80550c25 +#define SCE_NP_MATCHING2_ERROR_SSL_RECV 0x80550c26 +#define SCE_NP_MATCHING2_ERROR_JOINED_SESSION_MAX 0x80550c27 +#define SCE_NP_MATCHING2_ERROR_ALREADY_JOINED 0x80550c28 +#define SCE_NP_MATCHING2_ERROR_INVALID_SESSION_TYPE 0x80550c29 +#define SCE_NP_MATCHING2_ERROR_NP_SIGNED_OUT 0x80550c2b +#define SCE_NP_MATCHING2_ERROR_BUSY 0x80550c2c +#define SCE_NP_MATCHING2_ERROR_SERVER_NOT_AVAILABLE 0x80550c2d +#define SCE_NP_MATCHING2_ERROR_NOT_ALLOWED 0x80550c2e +#define SCE_NP_MATCHING2_ERROR_ABORTED 0x80550c2f +#define SCE_NP_MATCHING2_ERROR_REQUEST_NOT_FOUND 0x80550c30 +#define SCE_NP_MATCHING2_ERROR_SESSION_DESTROYED 0x80550c31 +#define SCE_NP_MATCHING2_ERROR_CONTEXT_STOPPED 0x80550c32 +#define SCE_NP_MATCHING2_ERROR_INVALID_REQUEST_PARAMETER 0x80550c33 +#define SCE_NP_MATCHING2_ERROR_NOT_NP_SIGN_IN 0x80550c34 +#define SCE_NP_MATCHING2_ERROR_ROOM_NOT_FOUND 0x80550c35 +#define SCE_NP_MATCHING2_ERROR_ROOM_MEMBER_NOT_FOUND 0x80550c36 +#define SCE_NP_MATCHING2_ERROR_LOBBY_NOT_FOUND 0x80550c37 +#define SCE_NP_MATCHING2_ERROR_LOBBY_MEMBER_NOT_FOUND 0x80550c38 +#define SCE_NP_MATCHING2_ERROR_KEEPALIVE_TIMEOUT 0x80550c3a +#define SCE_NP_MATCHING2_ERROR_TIMEOUT_TOO_SHORT 0x80550c3b +#define SCE_NP_MATCHING2_ERROR_TIMEDOUT 0x80550c3c +#define SCE_NP_MATCHING2_ERROR_INVALID_SLOTGROUP 0x80550c3d +#define SCE_NP_MATCHING2_ERROR_INVALID_ATTRIBUTE_SIZE 0x80550c3e +#define SCE_NP_MATCHING2_ERROR_CANNOT_ABORT 0x80550c3f +#define SCE_NP_MATCHING2_ERROR_SESSION_NOT_FOUND 0x80550c40 + +#define SCE_NP_MATCHING2_SERVER_ERROR_BAD_REQUEST 0x80550d01 +#define SCE_NP_MATCHING2_SERVER_ERROR_SERVICE_UNAVAILABLE 0x80550d02 +#define SCE_NP_MATCHING2_SERVER_ERROR_BUSY 0x80550d03 +#define SCE_NP_MATCHING2_SERVER_ERROR_END_OF_SERVICE 0x80550d04 +#define SCE_NP_MATCHING2_SERVER_ERROR_INTERNAL_SERVER_ERROR 0x80550d05 +#define SCE_NP_MATCHING2_SERVER_ERROR_PLAYER_BANNED 0x80550d06 +#define SCE_NP_MATCHING2_SERVER_ERROR_FORBIDDEN 0x80550d07 +#define SCE_NP_MATCHING2_SERVER_ERROR_BLOCKED 0x80550d08 +#define SCE_NP_MATCHING2_SERVER_ERROR_UNSUPPORTED_NP_ENV 0x80550d09 +#define SCE_NP_MATCHING2_SERVER_ERROR_INVALID_TICKET 0x80550d0a +#define SCE_NP_MATCHING2_SERVER_ERROR_INVALID_SIGNATURE 0x80550d0b +#define SCE_NP_MATCHING2_SERVER_ERROR_EXPIRED_TICKET 0x80550d0c +#define SCE_NP_MATCHING2_SERVER_ERROR_ENTITLEMENT_REQUIRED 0x80550d0d +#define SCE_NP_MATCHING2_SERVER_ERROR_NO_SUCH_CONTEXT 0x80550d0e +#define SCE_NP_MATCHING2_SERVER_ERROR_CLOSED 0x80550d0f +#define SCE_NP_MATCHING2_SERVER_ERROR_NO_SUCH_TITLE 0x80550d10 +#define SCE_NP_MATCHING2_SERVER_ERROR_NO_SUCH_WORLD 0x80550d11 +#define SCE_NP_MATCHING2_SERVER_ERROR_NO_SUCH_LOBBY 0x80550d12 +#define SCE_NP_MATCHING2_SERVER_ERROR_NO_SUCH_ROOM 0x80550d13 +#define SCE_NP_MATCHING2_SERVER_ERROR_NO_SUCH_LOBBY_INSTANCE 0x80550d14 +#define SCE_NP_MATCHING2_SERVER_ERROR_NO_SUCH_ROOM_INSTANCE 0x80550d15 +#define SCE_NP_MATCHING2_SERVER_ERROR_PASSWORD_MISMATCH 0x80550d17 +#define SCE_NP_MATCHING2_SERVER_ERROR_LOBBY_FULL 0x80550d18 +#define SCE_NP_MATCHING2_SERVER_ERROR_ROOM_FULL 0x80550d19 +#define SCE_NP_MATCHING2_SERVER_ERROR_GROUP_FULL 0x80550d1b +#define SCE_NP_MATCHING2_SERVER_ERROR_NO_SUCH_USER 0x80550d1c +#define SCE_NP_MATCHING2_SERVER_ERROR_TITLE_PASSPHRASE_MISMATCH 0x80550d1e +#define SCE_NP_MATCHING2_SERVER_ERROR_CONSOLE_BANNED 0x80550d28 +#define SCE_NP_MATCHING2_SERVER_ERROR_NO_ROOMGROUP 0x80550d29 +#define SCE_NP_MATCHING2_SERVER_ERROR_NO_SUCH_GROUP 0x80550d2a +#define SCE_NP_MATCHING2_SERVER_ERROR_NO_PASSWORD 0x80550d2b +#define SCE_NP_MATCHING2_SERVER_ERROR_INVALID_GROUP_SLOT_NUM 0x80550d2c +#define SCE_NP_MATCHING2_SERVER_ERROR_INVALID_PASSWORD_SLOT_MASK 0x80550d2d +#define SCE_NP_MATCHING2_SERVER_ERROR_DUPLICATE_GROUP_LABEL 0x80550d2e +#define SCE_NP_MATCHING2_SERVER_ERROR_REQUEST_OVERFLOW 0x80550d2f +#define SCE_NP_MATCHING2_SERVER_ERROR_ALREADY_JOINED 0x80550d30 +#define SCE_NP_MATCHING2_SERVER_ERROR_NAT_TYPE_MISMATCH 0x80550d31 +#define SCE_NP_MATCHING2_SERVER_ERROR_ROOM_INCONSISTENCY 0x80550d32 + +#define SCE_NP_MATCHING2_SIGNALING_ERROR_NOT_INITIALIZED 0x80550e01 +#define SCE_NP_MATCHING2_SIGNALING_ERROR_ALREADY_INITIALIZED 0x80550e02 +#define SCE_NP_MATCHING2_SIGNALING_ERROR_OUT_OF_MEMORY 0x80550e03 +#define SCE_NP_MATCHING2_SIGNALING_ERROR_CTXID_NOT_AVAILABLE 0x80550e04 +#define SCE_NP_MATCHING2_SIGNALING_ERROR_CTX_NOT_FOUND 0x80550e05 +#define SCE_NP_MATCHING2_SIGNALING_ERROR_REQID_NOT_AVAILABLE 0x80550e06 +#define SCE_NP_MATCHING2_SIGNALING_ERROR_REQ_NOT_FOUND 0x80550e07 +#define SCE_NP_MATCHING2_SIGNALING_ERROR_PARSER_CREATE_FAILED 0x80550e08 +#define SCE_NP_MATCHING2_SIGNALING_ERROR_PARSER_FAILED 0x80550e09 +#define SCE_NP_MATCHING2_SIGNALING_ERROR_INVALID_NAMESPACE 0x80550e0a +#define SCE_NP_MATCHING2_SIGNALING_ERROR_NETINFO_NOT_AVAILABLE 0x80550e0b +#define SCE_NP_MATCHING2_SIGNALING_ERROR_PEER_NOT_RESPONDING 0x80550e0c +#define SCE_NP_MATCHING2_SIGNALING_ERROR_CONNID_NOT_AVAILABLE 0x80550e0d +#define SCE_NP_MATCHING2_SIGNALING_ERROR_CONN_NOT_FOUND 0x80550e0e +#define SCE_NP_MATCHING2_SIGNALING_ERROR_PEER_UNREACHABLE 0x80550e0f +#define SCE_NP_MATCHING2_SIGNALING_ERROR_TERMINATED_BY_PEER 0x80550e10 +#define SCE_NP_MATCHING2_SIGNALING_ERROR_TIMEOUT 0x80550e11 +#define SCE_NP_MATCHING2_SIGNALING_ERROR_CTX_MAX 0x80550e12 +#define SCE_NP_MATCHING2_SIGNALING_ERROR_RESULT_NOT_FOUND 0x80550e13 +#define SCE_NP_MATCHING2_SIGNALING_ERROR_CONN_IN_PROGRESS 0x80550e14 +#define SCE_NP_MATCHING2_SIGNALING_ERROR_INVALID_ARGUMENT 0x80550e15 +#define SCE_NP_MATCHING2_SIGNALING_ERROR_OWN_NP_ID 0x80550e16 +#define SCE_NP_MATCHING2_SIGNALING_ERROR_TOO_MANY_CONN 0x80550e17 +#define SCE_NP_MATCHING2_SIGNALING_ERROR_TERMINATED_BY_MYSELF 0x80550e18 +#define SCE_NP_MATCHING2_SIGNALING_ERROR_MATCHING2_PEER_NOT_FOUND 0x80550e19 + +#define SCE_NP_TROPHY_ERROR_UNKNOWN 0x80551600 +#define SCE_NP_TROPHY_ERROR_NOT_INITIALIZED 0x80551601 +#define SCE_NP_TROPHY_ERROR_ALREADY_INITIALIZED 0x80551602 +#define SCE_NP_TROPHY_ERROR_NO_MEMORY 0x80551603 +#define SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT 0x80551604 +#define SCE_NP_TROPHY_ERROR_INSUFFICIENT_BUFFER 0x80551605 +#define SCE_NP_TROPHY_ERROR_EXCEEDS_MAX 0x80551606 +#define SCE_NP_TROPHY_ERROR_ABORT 0x80551607 +#define SCE_NP_TROPHY_ERROR_INVALID_HANDLE 0x80551608 +#define SCE_NP_TROPHY_ERROR_INVALID_CONTEXT 0x80551609 +#define SCE_NP_TROPHY_ERROR_INVALID_NPCOMMID 0x8055160a +#define SCE_NP_TROPHY_ERROR_INVALID_NPCOMMSIGN 0x8055160b + +#define SCE_NP_BASIC_ERROR_BASE 0x80551d00 +#define SCE_NP_BASIC_ERROR_UNKNOWN 0x80551d01 +#define SCE_NP_BASIC_ERROR_INVALID_ARGUMENT 0x80551d02 +#define SCE_NP_BASIC_ERROR_OUT_OF_MEMORY 0x80551d03 +#define SCE_NP_BASIC_ERROR_NOT_INITIALIZED 0x80551d04 +#define SCE_NP_BASIC_ERROR_ALREADY_INITIALIZED 0x80551d05 +#define SCE_NP_BASIC_ERROR_SIGNED_OUT 0x80551d06 +#define SCE_NP_BASIC_ERROR_NOT_ONLINE 0x80551d07 +#define SCE_NP_BASIC_ERROR_DATA_NOT_FOUND 0x80551d08 +#define SCE_NP_BASIC_ERROR_BUSY 0x80551d09 +#define SCE_NP_BASIC_ERROR_NOT_READY_TO_COMMUNICATE 0x80551d0a +#define SCE_NP_BASIC_ERROR_NO_COMM_ID_SUPPLIED 0x80551d0b // Based on https://github.com/RPCS3/rpcs3/blob/psp2/rpcs3/Emu/PSP2/Modules/sceNpCommon.h enum SceNpServiceState : s32 @@ -82,6 +341,7 @@ struct SceNpCommunicationConfig PSPPointer commSignature; }; +// Part of BCP 47 Code (ie. "fr" for France/French)? struct SceNpCountryCode { char data[2]; @@ -117,6 +377,7 @@ struct SceNpUserInformation u8 reserved[52]; }; +// Language Code (ie. 1033 for "en-US")? struct SceNpMyLanguages { s32_le language1; @@ -172,8 +433,13 @@ struct NpAuthHandler { u32 argument; }; -struct NpAuthArgs { +union NpAuthArgs { u32_le data[3]; // id, result, ArgAddr + struct { + s32_le id; + s32_le result; + u32_le argAddr; + }; }; using SceNpAuthCallback = s32(s32 id, s32 result, PSPPointer arg); @@ -227,9 +493,9 @@ struct SceNpEntitlement // Tickets data are in big-endian based on captured packets struct SceNpTicketParamData { - u16_be type; - u16_be length; - //u8 value[]; // optional data + u16_be type; // 0(NULL), 1(32-bit int), 2(64-bi long), 4(ansi string?), 7(date/timestamp), 8(ascii string) + u16_be length; // size of the following data value + //u8 value[]; // optional data of length size }; struct SceNpTicketHeader @@ -242,7 +508,7 @@ struct SceNpTicketHeader // A section can contain other sections or param data, thus sharing their enum/def? struct SceNpTicketSection { - u16_be type; // section type? ie. 30 XX where known XX are 00, 02, 10, 11 + u16_be type; // section type? ie. 30 XX where known XX are 00(Body), 02(Footer), 10, 11 u16_be size; // total section size (excluding this 4-bytes section delimiter struct) }; @@ -250,10 +516,127 @@ struct SceNpTicket { SceNpTicketHeader header; SceNpTicketSection section; // Body or Parameter sections? - //SceNpTicketParamData parameters[]; // a list of TicketParamData + //SceNpTicketParamData parameters[]; // a list of TicketParamData following the section //u8 unknownBytes[]; // optional data? }; +struct SceNpAuthMemoryStat { + int npMemSize; // Memory allocated by the NP utility. Pool Size? + int npMaxMemSize; // Maximum memory used by the NP utility. + int npFreeMemSize; // Free memory available to use by the NP utility. +}; + + +// Based on https://github.com/RPCS3/rpcs3/blob/master/rpcs3/Emu/Cell/Modules/sceNp2.h (Just as reference, might be slightly different than PSP) +// Event of request functions +enum PS3Matching2RequestEvent +{ + SCE_NP_MATCHING2_REQUEST_EVENT_GetServerInfo = 0x0001, + SCE_NP_MATCHING2_REQUEST_EVENT_GetWorldInfoList = 0x0002, + SCE_NP_MATCHING2_REQUEST_EVENT_GetRoomMemberDataExternalList = 0x0003, + SCE_NP_MATCHING2_REQUEST_EVENT_SetRoomDataExternal = 0x0004, + SCE_NP_MATCHING2_REQUEST_EVENT_GetRoomDataExternalList = 0x0005, + SCE_NP_MATCHING2_REQUEST_EVENT_GetLobbyInfoList = 0x0006, + SCE_NP_MATCHING2_REQUEST_EVENT_SetUserInfo = 0x0007, + SCE_NP_MATCHING2_REQUEST_EVENT_GetUserInfoList = 0x0008, + SCE_NP_MATCHING2_REQUEST_EVENT_CreateServerContext = 0x0009, + SCE_NP_MATCHING2_REQUEST_EVENT_DeleteServerContext = 0x000a, + SCE_NP_MATCHING2_REQUEST_EVENT_CreateJoinRoom = 0x0101, + SCE_NP_MATCHING2_REQUEST_EVENT_JoinRoom = 0x0102, + SCE_NP_MATCHING2_REQUEST_EVENT_LeaveRoom = 0x0103, + SCE_NP_MATCHING2_REQUEST_EVENT_GrantRoomOwner = 0x0104, + SCE_NP_MATCHING2_REQUEST_EVENT_KickoutRoomMember = 0x0105, + SCE_NP_MATCHING2_REQUEST_EVENT_SearchRoom = 0x0106, + SCE_NP_MATCHING2_REQUEST_EVENT_SendRoomChatMessage = 0x0107, + SCE_NP_MATCHING2_REQUEST_EVENT_SendRoomMessage = 0x0108, + SCE_NP_MATCHING2_REQUEST_EVENT_SetRoomDataInternal = 0x0109, + SCE_NP_MATCHING2_REQUEST_EVENT_GetRoomDataInternal = 0x010a, + SCE_NP_MATCHING2_REQUEST_EVENT_SetRoomMemberDataInternal = 0x010b, + SCE_NP_MATCHING2_REQUEST_EVENT_GetRoomMemberDataInternal = 0x010c, + SCE_NP_MATCHING2_REQUEST_EVENT_SetSignalingOptParam = 0x010d, + SCE_NP_MATCHING2_REQUEST_EVENT_JoinLobby = 0x0201, + SCE_NP_MATCHING2_REQUEST_EVENT_LeaveLobby = 0x0202, + SCE_NP_MATCHING2_REQUEST_EVENT_SendLobbyChatMessage = 0x0203, + SCE_NP_MATCHING2_REQUEST_EVENT_SendLobbyInvitation = 0x0204, + SCE_NP_MATCHING2_REQUEST_EVENT_SetLobbyMemberDataInternal = 0x0205, + SCE_NP_MATCHING2_REQUEST_EVENT_GetLobbyMemberDataInternal = 0x0206, + SCE_NP_MATCHING2_REQUEST_EVENT_GetLobbyMemberDataInternalList = 0x0207, + SCE_NP_MATCHING2_REQUEST_EVENT_SignalingGetPingInfo = 0x0e01, +}; + +// Based on decompiled np_matching2.prx, commented with syscalls where the event id is being used +#define PSP_NP_MATCHING2_EVENT_0001 0x0001 // GetServerInfo +#define PSP_NP_MATCHING2_EVENT_0002 0x0002 // GetWorldInfoList +#define PSP_NP_MATCHING2_EVENT_0003 0x0003 // SetUserInfo +#define PSP_NP_MATCHING2_EVENT_0004 0x0004 // GetUserInfoList +#define PSP_NP_MATCHING2_EVENT_0005 0x0005 // GetRoomMemberDataExternalList +#define PSP_NP_MATCHING2_EVENT_0006 0x0006 // SetRoomDataExternal +#define PSP_NP_MATCHING2_EVENT_0007 0x0007 // GetRoomDataExternalList + +#define PSP_NP_MATCHING2_EVENT_0101 0x0101 // CreateJoinRoom +#define PSP_NP_MATCHING2_EVENT_0102 0x0102 // JoinRoom +#define PSP_NP_MATCHING2_EVENT_0103 0x0103 // LeaveRoom +#define PSP_NP_MATCHING2_EVENT_0104 0x0104 // GrantRoomOwner +#define PSP_NP_MATCHING2_EVENT_0105 0x0105 // KickoutRoomMember +#define PSP_NP_MATCHING2_EVENT_0106 0x0106 // SearchRoom +#define PSP_NP_MATCHING2_EVENT_0107 0x0107 // SendRoomChatMessage +#define PSP_NP_MATCHING2_EVENT_0108 0x0108 // SendRoomMessage, also used on various places (internal function) +#define PSP_NP_MATCHING2_EVENT_0109 0x0109 // SetRoomDataInternal +#define PSP_NP_MATCHING2_EVENT_010A 0x010A // GetRoomDataInternal +#define PSP_NP_MATCHING2_EVENT_010B 0x010B // SetRoomMemberDataInternal +#define PSP_NP_MATCHING2_EVENT_010C 0x010C // GetRoomMemberDataInternal +#define PSP_NP_MATCHING2_EVENT_010D 0x010D // GetRoomMemberDataInternalList +#define PSP_NP_MATCHING2_EVENT_010E 0x010E // SetSignalingOptParam + +#define PSP_NP_MATCHING2_EVENT_A102 0xA102 // Used on various places (internal function) + +// Either this is an ID, state/status, flags, or might be size of data? +#define PSP_NP_MATCHING2_STATE_1001 0x1001 +#define PSP_NP_MATCHING2_STATE_1006 0x1006 +#define PSP_NP_MATCHING2_STATE_1007 0x1007 +#define PSP_NP_MATCHING2_STATE_1008 0x1008 + +#define PSP_NP_MATCHING2_STATE_1200 0x1200 +#define PSP_NP_MATCHING2_STATE_1206 0x1206 +#define PSP_NP_MATCHING2_STATE_1207 0x1207 +#define PSP_NP_MATCHING2_STATE_1208 0x1208 +#define PSP_NP_MATCHING2_STATE_1209 0x1209 +#define PSP_NP_MATCHING2_STATE_120B 0x120B +#define PSP_NP_MATCHING2_STATE_120C 0x120C + +#define PSP_NP_MATCHING2_STATE_3202 0x3202 +#define PSP_NP_MATCHING2_STATE_3203 0x3203 +#define PSP_NP_MATCHING2_STATE_3204 0x3204 +#define PSP_NP_MATCHING2_STATE_3205 0x3205 +#define PSP_NP_MATCHING2_STATE_3206 0x3206 +#define PSP_NP_MATCHING2_STATE_3207 0x3207 +#define PSP_NP_MATCHING2_STATE_3208 0x3208 +#define PSP_NP_MATCHING2_STATE_320A 0x320A +#define PSP_NP_MATCHING2_STATE_3210 0x3210 +#define PSP_NP_MATCHING2_STATE_3211 0x3211 + +#define PSP_NP_MATCHING2_MAX_CONTEXTID 7; + +struct NpMatching2Handler { + u32 entryPoint; + u32 argument; +}; + +// Arg1 and Arg2 seems to be a pair and predefined: 0x0001 with 0x1001, 0x0002 with 0x1008, 0x0003 with 0x1006, 0x0004 with 0x1007, +// 0x0005 with 0x1206, 0x0006 with 0x1207, 0x0007 with 0x1208, 0x0101 with 0x1209, 0x0102 with 0x1209, 0x0103 with 0x3202, +// 0x0104 with 0x3210, 0x0105 with 0x3211, 0x0106 with 2 possibilities (0x1200 and 0x120c), 0x0107 with 0x3208, 0x0108 with 0x320a, +// 0x0109 with 0x3204, 0x010a with 0x3205, 0x010b with 0x3206, 0x010c with 0x3207, 0x010d with 0x3203, 0x010e with 0x3204, +// 0xa102 with 0x120b. +// Arg5 seems to be boolean (0/1), mostly 0, conditional when Arg1=0x0001 +// Arg7 seems to be integer/state? (0..2), mostly 0, conditional when Arg1=0x0108 (0 on SendRoomMessage, 2 on others), 1 when Arg1=0xa102 +struct NpMatching2Args { + u32_le data[11]; // 7 elements (excluding optional data)? or may be 11 elements (including optional data)? + // May be followed by optional data? since these Args usually created on the stack +}; + +#pragma pack(pop) + + #define PARENTAL_CONTROL_DISABLED 0 #define PARENTAL_CONTROL_ENABLED 1 @@ -261,22 +644,35 @@ struct SceNpTicket #define STATUS_ACCOUNT_CHAT_RESTRICTED 0x100 #define STATUS_ACCOUNT_PARENTAL_CONTROL_ENABLED 0x200 -struct SceNpAuthMemoryStat { - int npMemSize; // Memory allocated by the NP utility. - int npMaxMemSize; // Maximum memory used by the NP utility. - int npFreeMemSize; // Free memory available to use by the NP utility. -}; - -#ifdef _MSC_VER -#pragma pack(pop) -#endif +#define NP_SIGNIN_STATUS_NONE 0 // SIGNEDOUT? +#define NP_SIGNIN_STATUS_SUCCESS 1 +#define NP_SIGNIN_STATUS_CANCELED 2 +#define NP_SIGNIN_STATUS_FAILED 3 // ERROR/ABORTED/SIGNEDOUT? +// Used by PSPNpSigninDialog.cpp +extern int npSigninState; +extern PSPTimeval npSigninTimestamp; +// Used by sceNet.cpp since we're borrowing Apctl's PSPThread to process NP events & callbacks. +// TODO: NP events should be processed on it's own PSPThread extern std::recursive_mutex npAuthEvtMtx; extern std::deque npAuthEvents; extern std::map npAuthHandlers; +// Used by sceNp2.cpp +extern SceNpCommunicationId npTitleId; + +int NpGetNpId(SceNpId* npid); + +int sceNpAuthGetMemoryStat(u32 memStatAddr); +int sceNpAuthCreateStartRequest(u32 paramAddr); +int sceNpAuthGetTicket(u32 requestId, u32 bufferAddr, u32 length); +int sceNpAuthGetEntitlementById(u32 ticketBufferAddr, u32 ticketLength, u32 entitlementIdAddr, u32 arg4); +int sceNpAuthAbortRequest(int requestId); +int sceNpAuthDestroyRequest(int requestId); + void Register_sceNp(); -void Register_sceNpCommerce2(); void Register_sceNpService(); void Register_sceNpAuth(); +void Register_sceNpCommerce2(); +void Register_sceNpMatching2();