From 6d99b5d3328cbb1544b52afdf246c65d66aabadb Mon Sep 17 00:00:00 2001 From: Vitor Kiguchi Date: Sat, 5 Jun 2021 18:34:15 -0300 Subject: [PATCH 1/2] service/frd: return cfg username on GetMyScreenName as some games apparently use this for the multiplayer display name --- src/core/hle/service/frd/frd.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/core/hle/service/frd/frd.cpp b/src/core/hle/service/frd/frd.cpp index bd408420d..1e49a1e8b 100644 --- a/src/core/hle/service/frd/frd.cpp +++ b/src/core/hle/service/frd/frd.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include "common/assert.h" #include "common/logging/log.h" @@ -10,6 +11,7 @@ #include "core/core.h" #include "core/hle/ipc_helpers.h" #include "core/hle/result.h" +#include "core/hle/service/cfg/cfg.h" #include "core/hle/service/frd/frd.h" #include "core/hle/service/frd/frd_a.h" #include "core/hle/service/frd/frd_u.h" @@ -93,16 +95,21 @@ void Module::Interface::GetMyScreenName(Kernel::HLERequestContext& ctx) { IPC::RequestBuilder rb = rp.MakeBuilder(7, 0); struct ScreenName { - std::array name; + // 20 bytes according to 3dbrew + char16_t name[10]; }; - // TODO: (mailwl) get the name from config - ScreenName screen_name{u"Citra"}; + auto cfg = Service::CFG::GetModule(Core::System::GetInstance()); + ASSERT_MSG(cfg, "CFG Module missing!"); + auto username = cfg->GetUsername(); + ASSERT_MSG(username.length() <= 10, "Username longer than expected!"); + ScreenName screen_name{0}; + std::memcpy(screen_name.name, username.data(), username.length() * sizeof(char16_t)); rb.Push(RESULT_SUCCESS); rb.PushRaw(screen_name); - LOG_WARNING(Service_FRD, "(STUBBED) called"); + LOG_INFO(Service_FRD, "returning the username defined in cfg"); } void Module::Interface::UnscrambleLocalFriendCode(Kernel::HLERequestContext& ctx) { From 3e71d68b94964f913986e045ac998994c3cfe370 Mon Sep 17 00:00:00 2001 From: Vitor Kiguchi Date: Wed, 7 Jul 2021 05:09:33 -0300 Subject: [PATCH 2/2] service/frd: don't use global system address review comments + clang format --- src/core/hle/service/frd/frd.cpp | 14 ++++++++------ src/core/hle/service/frd/frd.h | 5 ++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/core/hle/service/frd/frd.cpp b/src/core/hle/service/frd/frd.cpp index 1e49a1e8b..605fc9ab4 100644 --- a/src/core/hle/service/frd/frd.cpp +++ b/src/core/hle/service/frd/frd.cpp @@ -16,6 +16,8 @@ #include "core/hle/service/frd/frd_a.h" #include "core/hle/service/frd/frd_u.h" +SERVICE_CONSTRUCT_IMPL(Service::FRD::Module) + namespace Service::FRD { Module::Interface::Interface(std::shared_ptr frd, const char* name, u32 max_session) @@ -96,15 +98,15 @@ void Module::Interface::GetMyScreenName(Kernel::HLERequestContext& ctx) { struct ScreenName { // 20 bytes according to 3dbrew - char16_t name[10]; + std::array name; }; - auto cfg = Service::CFG::GetModule(Core::System::GetInstance()); + auto cfg = Service::CFG::GetModule(frd->system); ASSERT_MSG(cfg, "CFG Module missing!"); auto username = cfg->GetUsername(); ASSERT_MSG(username.length() <= 10, "Username longer than expected!"); - ScreenName screen_name{0}; - std::memcpy(screen_name.name, username.data(), username.length() * sizeof(char16_t)); + ScreenName screen_name{}; + std::memcpy(screen_name.name.data(), username.data(), username.length() * sizeof(char16_t)); rb.Push(RESULT_SUCCESS); rb.PushRaw(screen_name); @@ -154,12 +156,12 @@ void Module::Interface::SetClientSdkVersion(Kernel::HLERequestContext& ctx) { LOG_WARNING(Service_FRD, "(STUBBED) called, version: 0x{:08X}", version); } -Module::Module() = default; +Module::Module(Core::System& system) : system(system){}; Module::~Module() = default; void InstallInterfaces(Core::System& system) { auto& service_manager = system.ServiceManager(); - auto frd = std::make_shared(); + auto frd = std::make_shared(system); std::make_shared(frd)->InstallAsService(service_manager); std::make_shared(frd)->InstallAsService(service_manager); } diff --git a/src/core/hle/service/frd/frd.h b/src/core/hle/service/frd/frd.h index 1f34e61fa..16902e45d 100644 --- a/src/core/hle/service/frd/frd.h +++ b/src/core/hle/service/frd/frd.h @@ -50,7 +50,7 @@ struct Profile { class Module final { public: - Module(); + explicit Module(Core::System& system); ~Module(); class Interface : public ServiceFramework { @@ -153,6 +153,7 @@ public: private: FriendKey my_friend_key = {0, 0, 0ull}; MyPresence my_presence = {}; + Core::System& system; template void serialize(Archive& ar, const unsigned int) { @@ -165,3 +166,5 @@ private: void InstallInterfaces(Core::System& system); } // namespace Service::FRD + +SERVICE_CONSTRUCT(Service::FRD::Module)