diff --git a/rpcs3/Emu/Cell/Modules/sceNp.h b/rpcs3/Emu/Cell/Modules/sceNp.h index 6006e3f82f..60eba34214 100644 --- a/rpcs3/Emu/Cell/Modules/sceNp.h +++ b/rpcs3/Emu/Cell/Modules/sceNp.h @@ -853,8 +853,7 @@ struct SceNpDrmOpenArg // NP communication ID structure struct SceNpCommunicationId { - char data[9]; - char term; + char data[9 + 1]; // char term; u8 num; char dummy; }; @@ -862,8 +861,7 @@ struct SceNpCommunicationId // OnlineId structure struct SceNpOnlineId { - char data[16]; - char term; + char data[16 + 1]; // char term; char dummy[3]; }; @@ -888,16 +886,14 @@ CHECK_SIZE_ALIGN(SceNpId, 0x24, 1); // Online Name structure struct SceNpOnlineName { - char data[48]; - char term; + char data[48 + 1]; // char term; char padding[3]; }; // Avatar structure struct SceNpAvatarUrl { - char data[127]; - char term; + char data[127 + 1]; // char term; }; // Avatar image structure @@ -911,8 +907,7 @@ struct SceNpAvatarImage // Self introduction structure struct SceNpAboutMe { - char data[SCE_NET_NP_ABOUT_ME_MAX_LENGTH]; - char term; + char data[SCE_NET_NP_ABOUT_ME_MAX_LENGTH + 1]; // char term; }; // User information structure diff --git a/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp b/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp index 23f7248e16..982ca4266c 100644 --- a/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp +++ b/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp @@ -392,7 +392,7 @@ error_code sceNpTrophyCreateContext(vm::ptr context, vm::cptrterm, commId->term, commId->num); + sceNpTrophy.warning("sceNpTrophyCreateContext(): data='%s' term='%c' (0x%x) num=%d", name_sv, commId->data[9], commId->data[9], commId->num); // append the commId number as "_xx" const std::string name = fmt::format("%s_%02d", name_sv, commId->num); diff --git a/rpcs3/Emu/NP/fb_helpers.cpp b/rpcs3/Emu/NP/fb_helpers.cpp index 7545043e4e..dd5b1f8537 100644 --- a/rpcs3/Emu/NP/fb_helpers.cpp +++ b/rpcs3/Emu/NP/fb_helpers.cpp @@ -41,17 +41,17 @@ void np_handler::RoomGroup_to_SceNpMatching2RoomGroup(const flatbuffers::Vector< void np_handler::UserInfo2_to_SceNpUserInfo2(const UserInfo2* user, SceNpUserInfo2* user_info) { if (user->npId()) - memcpy(user_info->npId.handle.data, user->npId()->c_str(), std::min(sizeof(user_info->npId.handle.data), static_cast(user->npId()->size()))); + std::memcpy(user_info->npId.handle.data, user->npId()->c_str(), std::min(9, user->npId()->size())); if (user->onlineName()) { user_info->onlineName.set(allocate(sizeof(SceNpOnlineName))); - memcpy(user_info->onlineName->data, user->onlineName()->c_str(), std::min(sizeof(user_info->onlineName->data), static_cast(user->onlineName()->size()))); + std::memcpy(user_info->onlineName->data, user->onlineName()->c_str(), std::min(48, user->onlineName()->size())); } if (user->avatarUrl()) { user_info->avatarUrl.set(allocate(sizeof(SceNpAvatarUrl))); - memcpy(user_info->avatarUrl->data, user->avatarUrl()->c_str(), std::min(sizeof(user_info->avatarUrl->data), static_cast(user->avatarUrl()->size()))); + std::memcpy(user_info->avatarUrl->data, user->avatarUrl()->c_str(), std::min(127, user->avatarUrl()->size())); } } diff --git a/rpcs3/Emu/NP/np_contexts.cpp b/rpcs3/Emu/NP/np_contexts.cpp index a295abec6c..37f69bfea0 100644 --- a/rpcs3/Emu/NP/np_contexts.cpp +++ b/rpcs3/Emu/NP/np_contexts.cpp @@ -5,7 +5,7 @@ score_ctx::score_ctx(vm::cptr communicationId, vm::cptr passphrase) { - ensure(!communicationId->term && strlen(communicationId->data) == 9); + ensure(!communicationId->data[9] && strlen(communicationId->data) == 9); memcpy(&this->communicationId, communicationId.get_ptr(), sizeof(SceNpCommunicationId)); memcpy(&this->passphrase, passphrase.get_ptr(), sizeof(SceNpCommunicationPassphrase)); } @@ -33,7 +33,7 @@ bool destroy_score_transaction_context(s32 ctx_id) match2_ctx::match2_ctx(vm::cptr communicationId, vm::cptr passphrase) { - ensure(!communicationId->term && strlen(communicationId->data) == 9); + ensure(!communicationId->data[9] && strlen(communicationId->data) == 9); memcpy(&this->communicationId, communicationId.get_ptr(), sizeof(SceNpCommunicationId)); memcpy(&this->passphrase, passphrase.get_ptr(), sizeof(SceNpCommunicationPassphrase)); } @@ -56,7 +56,7 @@ std::shared_ptr get_match2_context(u16 ctx_id) lookup_title_ctx::lookup_title_ctx(vm::cptr communicationId) { - ensure(!communicationId->term && strlen(communicationId->data) == 9); + ensure(!communicationId->data[9] && strlen(communicationId->data) == 9); memcpy(&this->communicationId, communicationId.get_ptr(), sizeof(SceNpCommunicationId)); } s32 create_lookup_title_context(vm::cptr communicationId) diff --git a/rpcs3/Emu/NP/np_handler.cpp b/rpcs3/Emu/NP/np_handler.cpp index f624c7d520..06dfaed075 100644 --- a/rpcs3/Emu/NP/np_handler.cpp +++ b/rpcs3/Emu/NP/np_handler.cpp @@ -282,24 +282,21 @@ std::string np_handler::ether_to_string(std::array& ether) return fmt::format("%02X:%02X:%02X:%02X:%02X:%02X", ether[0], ether[1], ether[2], ether[3], ether[4], ether[5]); } -void np_handler::string_to_npid(const char* str, SceNpId* npid) +void np_handler::string_to_npid(const std::string& str, SceNpId* npid) { memset(npid, 0, sizeof(SceNpId)); - strncpy(npid->handle.data, str, sizeof(npid->handle.data)); - npid->handle.term = 0; + strcpy_trunc(npid->handle.data, str); // npid->reserved[0] = 1; } -void np_handler::string_to_online_name(const char* str, SceNpOnlineName* online_name) +void np_handler::string_to_online_name(const std::string& str, SceNpOnlineName* online_name) { - strncpy(online_name->data, str, sizeof(online_name->data)); - online_name->term = 0; + strcpy_trunc(online_name->data, str); } -void np_handler::string_to_avatar_url(const char* str, SceNpAvatarUrl* avatar_url) +void np_handler::string_to_avatar_url(const std::string& str, SceNpAvatarUrl* avatar_url) { - strncpy(avatar_url->data, str, sizeof(avatar_url->data)); - avatar_url->term = 0; + strcpy_trunc(avatar_url->data, str); } void np_handler::init_NP(u32 poolsize, vm::ptr poolptr) @@ -319,7 +316,7 @@ void np_handler::init_NP(u32 poolsize, vm::ptr poolptr) std::string s_npid = g_cfg_rpcn.get_npid(); ensure(!s_npid.empty()); // It should have been generated before this - np_handler::string_to_npid(s_npid.c_str(), &npid); + np_handler::string_to_npid(s_npid, &npid); const auto sigh = g_fxo->get>(); sigh->set_self_sig_info(npid); } @@ -354,8 +351,8 @@ void np_handler::init_NP(u32 poolsize, vm::ptr poolptr) return; } - np_handler::string_to_online_name(rpcn.get_online_name().c_str(), &online_name); - np_handler::string_to_avatar_url(rpcn.get_avatar_url().c_str(), &avatar_url); + np_handler::string_to_online_name(rpcn.get_online_name(), &online_name); + np_handler::string_to_avatar_url(rpcn.get_avatar_url(), &avatar_url); public_ip_addr = rpcn.get_addr_sig(); break; diff --git a/rpcs3/Emu/NP/np_handler.h b/rpcs3/Emu/NP/np_handler.h index 002e2f3f4a..5c01cffd22 100644 --- a/rpcs3/Emu/NP/np_handler.h +++ b/rpcs3/Emu/NP/np_handler.h @@ -35,9 +35,9 @@ public: static std::string ip_to_string(u32 addr); static std::string ether_to_string(std::array& ether); // Helpers for setting various structures from string - static void string_to_npid(const char* str, SceNpId* npid); - static void string_to_online_name(const char* str, SceNpOnlineName* online_name); - static void string_to_avatar_url(const char* str, SceNpAvatarUrl* avatar_url); + static void string_to_npid(const std::string&, SceNpId* npid); + static void string_to_online_name(const std::string&, SceNpOnlineName* online_name); + static void string_to_avatar_url(const std::string&, SceNpAvatarUrl* avatar_url); // DNS hooking functions void add_dns_spy(u32 sock); diff --git a/rpcs3/Emu/NP/signaling_handler.cpp b/rpcs3/Emu/NP/signaling_handler.cpp index f4abd2c322..580f6b93fa 100644 --- a/rpcs3/Emu/NP/signaling_handler.cpp +++ b/rpcs3/Emu/NP/signaling_handler.cpp @@ -557,7 +557,7 @@ void signaling_handler::disconnect_sig2_users(u64 room_id) u32 signaling_handler::create_sig_infos(const SceNpId* npid) { - ensure(npid->handle.term == 0); + ensure(npid->handle.data[16] == 0); std::string npid_str(reinterpret_cast(npid->handle.data)); if (npid_to_conn_id.count(npid_str))