This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
YimMenu/src/hooks/misc/process_matchmaking_find_response.cpp
maybegreat48 9ccb77e8eb
Add more spoofing options and added clang-format (#1020)
* feat(Spoofing): add spoofing
* feat(Spoofing): prepare code for player attach
* remove(PlayerAttach): isn't going to work due to netsync architecture
* fix(GUI): fix scaling
* feat(Project): add clang-format file
* feat(Classes): update classes
* fix(BlackHole): remove unnecessary cleanup
* fix(Formatting): fix formatting for initializer lists
* feat(clang-format): Set tab width and 1 space before comment

Co-authored-by: Yimura <24669514+Yimura@users.noreply.github.com>
2023-03-01 21:27:15 +00:00

76 lines
2.0 KiB
C++

#include "hooking.hpp"
#include "services/matchmaking/matchmaking_service.hpp"
namespace rage
{
class JSONNode
{
public:
char* m_key; //0x0000
char pad_0008[32]; //0x0008
class rage::JSONNode* m_sibling;//0x0028
class rage::JSONNode* m_child; //0x0030
char* m_value; //0x0038
char pad_0040[8]; //0x0040
inline JSONNode* get_child_node(const char* name)
{
for (auto node = m_child; node; node = node->m_sibling)
{
if (strcmp(name, node->m_key) == 0)
return node;
}
return nullptr;
}
};//Size: 0x0048
static_assert(sizeof(rage::JSONNode) == 0x48);
}
namespace
{
// https://stackoverflow.com/a/5167641
static std::vector<std::string> split(const std::string& s, char seperator)
{
std::vector<std::string> output;
std::string::size_type prev_pos = 0, pos = 0;
while ((pos = s.find(seperator, pos)) != std::string::npos)
{
std::string substring(s.substr(prev_pos, pos - prev_pos));
output.push_back(substring);
prev_pos = ++pos;
}
output.push_back(s.substr(prev_pos, pos - prev_pos));// Last word
return output;
}
}
namespace big
{
bool hooks::process_matchmaking_find_response(void* _this, void* unused, rage::JSONNode* node, int* unk)
{
bool ret = g_hooking->get_original<hooks::process_matchmaking_find_response>()(_this, unused, node, unk);
if (g_matchmaking_service->is_active())
{
int i = 0;
for (auto result = node->get_child_node("Results")->m_child; result; result = result->m_sibling)
{
const auto& values = split(result->get_child_node("Attributes")->m_value, ',');
g_matchmaking_service->get_found_sessions()[i].attributes.discriminator = std::stoi(values[2]);
g_matchmaking_service->get_found_sessions()[i].attributes.player_count = std::stoi(values[4]);
g_matchmaking_service->get_found_sessions()[i].attributes.language = std::stoi(values[5]);
g_matchmaking_service->get_found_sessions()[i].attributes.region = std::stoi(values[6]);
i++;
}
}
return ret;
}
}