|
|
|
@ -2,127 +2,120 @@
|
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include "common/assert.h"
|
|
|
|
|
#include "common/logging/log.h"
|
|
|
|
|
#include "common/string_util.h"
|
|
|
|
|
#include "core/hle/ipc.h"
|
|
|
|
|
#include "core/hle/ipc_helpers.h"
|
|
|
|
|
#include "core/hle/result.h"
|
|
|
|
|
#include "core/hle/service/frd/frd.h"
|
|
|
|
|
#include "core/hle/service/frd/frd_a.h"
|
|
|
|
|
#include "core/hle/service/frd/frd_u.h"
|
|
|
|
|
#include "core/hle/service/service.h"
|
|
|
|
|
#include "core/memory.h"
|
|
|
|
|
|
|
|
|
|
namespace Service {
|
|
|
|
|
namespace FRD {
|
|
|
|
|
|
|
|
|
|
static FriendKey my_friend_key = {0, 0, 0ull};
|
|
|
|
|
static MyPresence my_presence = {};
|
|
|
|
|
Module::Interface::Interface(std::shared_ptr<Module> frd, const char* name, u32 max_session)
|
|
|
|
|
: ServiceFramework(name, max_session), frd(std::move(frd)) {}
|
|
|
|
|
|
|
|
|
|
void GetMyPresence(Service::Interface* self) {
|
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
Module::Interface::~Interface() = default;
|
|
|
|
|
|
|
|
|
|
u32 shifted_out_size = cmd_buff[64];
|
|
|
|
|
u32 my_presence_addr = cmd_buff[65];
|
|
|
|
|
void Module::Interface::GetMyPresence(Kernel::HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp(ctx, 0x08, 0, 0);
|
|
|
|
|
|
|
|
|
|
ASSERT(shifted_out_size == ((sizeof(MyPresence) << 14) | 2));
|
|
|
|
|
std::vector<u8> buffer(sizeof(MyPresence));
|
|
|
|
|
std::memcpy(buffer.data(), &frd->my_presence, buffer.size());
|
|
|
|
|
|
|
|
|
|
Memory::WriteBlock(my_presence_addr, &my_presence, sizeof(MyPresence));
|
|
|
|
|
|
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
|
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
|
rb.PushStaticBuffer(buffer, 0);
|
|
|
|
|
|
|
|
|
|
LOG_WARNING(Service_FRD, "(STUBBED) called");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GetFriendKeyList(Service::Interface* self) {
|
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
void Module::Interface::GetFriendKeyList(Kernel::HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp(ctx, 0x11, 2, 0);
|
|
|
|
|
u32 unknown = rp.Pop<u32>();
|
|
|
|
|
u32 frd_count = rp.Pop<u32>();
|
|
|
|
|
|
|
|
|
|
u32 unknown = cmd_buff[1];
|
|
|
|
|
u32 frd_count = cmd_buff[2];
|
|
|
|
|
u32 frd_key_addr = cmd_buff[65];
|
|
|
|
|
std::vector<u8> buffer(sizeof(FriendKey) * frd_count, 0);
|
|
|
|
|
|
|
|
|
|
FriendKey zero_key = {};
|
|
|
|
|
for (u32 i = 0; i < frd_count; ++i) {
|
|
|
|
|
Memory::WriteBlock(frd_key_addr + i * sizeof(FriendKey), &zero_key, sizeof(FriendKey));
|
|
|
|
|
}
|
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(2, 2);
|
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
|
rb.Push<u32>(0); // 0 friends
|
|
|
|
|
rb.PushStaticBuffer(buffer, 0);
|
|
|
|
|
|
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
|
|
|
|
|
cmd_buff[2] = 0; // 0 friends
|
|
|
|
|
LOG_WARNING(Service_FRD, "(STUBBED) called, unknown=%d, frd_count=%d, frd_key_addr=0x%08X",
|
|
|
|
|
unknown, frd_count, frd_key_addr);
|
|
|
|
|
LOG_WARNING(Service_FRD, "(STUBBED) called, unknown=%u, frd_count=%u", unknown, frd_count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GetFriendProfile(Service::Interface* self) {
|
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
void Module::Interface::GetFriendProfile(Kernel::HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp(ctx, 0x15, 1, 2);
|
|
|
|
|
u32 count = rp.Pop<u32>();
|
|
|
|
|
std::vector<u8> frd_keys = rp.PopStaticBuffer();
|
|
|
|
|
ASSERT(frd_keys.size() == count * sizeof(FriendKey));
|
|
|
|
|
|
|
|
|
|
u32 count = cmd_buff[1];
|
|
|
|
|
u32 frd_key_addr = cmd_buff[3];
|
|
|
|
|
u32 profiles_addr = cmd_buff[65];
|
|
|
|
|
std::vector<u8> buffer(sizeof(Profile) * count, 0);
|
|
|
|
|
|
|
|
|
|
Profile zero_profile = {};
|
|
|
|
|
for (u32 i = 0; i < count; ++i) {
|
|
|
|
|
Memory::WriteBlock(profiles_addr + i * sizeof(Profile), &zero_profile, sizeof(Profile));
|
|
|
|
|
}
|
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
|
rb.PushStaticBuffer(buffer, 0);
|
|
|
|
|
|
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
|
|
|
|
|
LOG_WARNING(Service_FRD,
|
|
|
|
|
"(STUBBED) called, count=%d, frd_key_addr=0x%08X, profiles_addr=0x%08X", count,
|
|
|
|
|
frd_key_addr, profiles_addr);
|
|
|
|
|
LOG_WARNING(Service_FRD, "(STUBBED) called, count=%u", count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GetFriendAttributeFlags(Service::Interface* self) {
|
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
void Module::Interface::GetFriendAttributeFlags(Kernel::HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp(ctx, 0x17, 1, 2);
|
|
|
|
|
u32 count = rp.Pop<u32>();
|
|
|
|
|
std::vector<u8> frd_keys = rp.PopStaticBuffer();
|
|
|
|
|
ASSERT(frd_keys.size() == count * sizeof(FriendKey));
|
|
|
|
|
|
|
|
|
|
u32 count = cmd_buff[1];
|
|
|
|
|
u32 frd_key_addr = cmd_buff[3];
|
|
|
|
|
u32 attr_flags_addr = cmd_buff[65];
|
|
|
|
|
|
|
|
|
|
for (u32 i = 0; i < count; ++i) {
|
|
|
|
|
// TODO:(mailwl) figure out AttributeFlag size and zero all buffer. Assume 1 byte
|
|
|
|
|
Memory::Write8(attr_flags_addr + i, 0);
|
|
|
|
|
}
|
|
|
|
|
std::vector<u8> buffer(1 * count, 0);
|
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
|
rb.PushStaticBuffer(buffer, 0);
|
|
|
|
|
|
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
|
|
|
|
|
LOG_WARNING(Service_FRD,
|
|
|
|
|
"(STUBBED) called, count=%d, frd_key_addr=0x%08X, attr_flags_addr=0x%08X", count,
|
|
|
|
|
frd_key_addr, attr_flags_addr);
|
|
|
|
|
LOG_WARNING(Service_FRD, "(STUBBED) called, count=%u", count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GetMyFriendKey(Service::Interface* self) {
|
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
void Module::Interface::GetMyFriendKey(Kernel::HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp(ctx, 0x5, 0, 0);
|
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(5, 0);
|
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
|
rb.PushRaw(frd->my_friend_key);
|
|
|
|
|
|
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
|
|
|
|
|
std::memcpy(&cmd_buff[2], &my_friend_key, sizeof(FriendKey));
|
|
|
|
|
LOG_WARNING(Service_FRD, "(STUBBED) called");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GetMyScreenName(Service::Interface* self) {
|
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
void Module::Interface::GetMyScreenName(Kernel::HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp(ctx, 0x9, 0, 0);
|
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(7, 0);
|
|
|
|
|
|
|
|
|
|
struct ScreenName {
|
|
|
|
|
std::array<char16_t, 12> name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
|
|
|
|
|
// TODO: (mailwl) get the name from config
|
|
|
|
|
Common::UTF8ToUTF16("Citra").copy(reinterpret_cast<char16_t*>(&cmd_buff[2]), 11);
|
|
|
|
|
ScreenName screen_name{u"Citra"};
|
|
|
|
|
|
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
|
rb.PushRaw(screen_name);
|
|
|
|
|
|
|
|
|
|
LOG_WARNING(Service_FRD, "(STUBBED) called");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UnscrambleLocalFriendCode(Service::Interface* self) {
|
|
|
|
|
void Module::Interface::UnscrambleLocalFriendCode(Kernel::HLERequestContext& ctx) {
|
|
|
|
|
const size_t scrambled_friend_code_size = 12;
|
|
|
|
|
const size_t friend_code_size = 8;
|
|
|
|
|
|
|
|
|
|
IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1C, 1, 2);
|
|
|
|
|
IPC::RequestParser rp(ctx, 0x1C, 1, 2);
|
|
|
|
|
const u32 friend_code_count = rp.Pop<u32>();
|
|
|
|
|
size_t in_buffer_size;
|
|
|
|
|
const VAddr scrambled_friend_codes = rp.PopStaticBuffer(&in_buffer_size);
|
|
|
|
|
ASSERT_MSG(in_buffer_size == (friend_code_count * scrambled_friend_code_size),
|
|
|
|
|
std::vector<u8> scrambled_friend_codes = rp.PopStaticBuffer();
|
|
|
|
|
ASSERT_MSG(scrambled_friend_codes.size() == (friend_code_count * scrambled_friend_code_size),
|
|
|
|
|
"Wrong input buffer size");
|
|
|
|
|
|
|
|
|
|
size_t out_buffer_size;
|
|
|
|
|
VAddr unscrambled_friend_codes = rp.PeekStaticBuffer(0, &out_buffer_size);
|
|
|
|
|
ASSERT_MSG(out_buffer_size == (friend_code_count * friend_code_size),
|
|
|
|
|
"Wrong output buffer size");
|
|
|
|
|
|
|
|
|
|
for (u32 current = 0; current < friend_code_count; ++current) {
|
|
|
|
|
std::vector<u8> unscrambled_friend_codes(friend_code_count * friend_code_size, 0);
|
|
|
|
|
// TODO(B3N30): Unscramble the codes and compare them against the friend list
|
|
|
|
|
// Only write 0 if the code isn't in friend list, otherwise write the
|
|
|
|
|
// unscrambled one
|
|
|
|
@ -137,38 +130,32 @@ void UnscrambleLocalFriendCode(Service::Interface* self) {
|
|
|
|
|
// scambled_friend_code[5]; unscrambled_friend_code[3] = scambled_friend_code[3] ^
|
|
|
|
|
// scambled_friend_code[5];
|
|
|
|
|
|
|
|
|
|
u64 result = 0ull;
|
|
|
|
|
Memory::WriteBlock(unscrambled_friend_codes + (current * sizeof(result)), &result,
|
|
|
|
|
sizeof(result));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG_WARNING(Service_FRD, "(STUBBED) called");
|
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
|
rb.PushStaticBuffer(unscrambled_friend_codes, out_buffer_size, 0);
|
|
|
|
|
rb.PushStaticBuffer(unscrambled_friend_codes, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetClientSdkVersion(Service::Interface* self) {
|
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
void Module::Interface::SetClientSdkVersion(Kernel::HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp(ctx, 0x32, 1, 2);
|
|
|
|
|
u32 version = rp.Pop<u32>();
|
|
|
|
|
rp.PopPID();
|
|
|
|
|
|
|
|
|
|
const u32 version = cmd_buff[1];
|
|
|
|
|
|
|
|
|
|
self->SetVersion(version);
|
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
|
|
|
|
|
|
LOG_WARNING(Service_FRD, "(STUBBED) called, version: 0x%08X", version);
|
|
|
|
|
|
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Init() {
|
|
|
|
|
using namespace Kernel;
|
|
|
|
|
Module::Module() = default;
|
|
|
|
|
Module::~Module() = default;
|
|
|
|
|
|
|
|
|
|
AddService(new FRD_A_Interface);
|
|
|
|
|
AddService(new FRD_U_Interface);
|
|
|
|
|
void InstallInterfaces(SM::ServiceManager& service_manager) {
|
|
|
|
|
auto frd = std::make_shared<Module>();
|
|
|
|
|
std::make_shared<FRD_U>(frd)->InstallAsService(service_manager);
|
|
|
|
|
std::make_shared<FRD_A>(frd)->InstallAsService(service_manager);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Shutdown() {}
|
|
|
|
|
|
|
|
|
|
} // namespace FRD
|
|
|
|
|
|
|
|
|
|
} // namespace Service
|
|
|
|
|