2022-05-28 17:44:05 +02:00
|
|
|
#include "hooking.hpp"
|
2022-12-23 00:03:34 +01:00
|
|
|
#include "memory/byte_patch.hpp"
|
|
|
|
#include "pointers.hpp"
|
2022-06-30 00:11:54 +02:00
|
|
|
#include "services/players/player_service.hpp"
|
2022-11-13 16:34:44 +00:00
|
|
|
#include <network/CNetworkPlayerMgr.hpp>
|
2022-05-28 17:44:05 +02:00
|
|
|
|
|
|
|
namespace big
|
|
|
|
{
|
2022-12-23 00:03:34 +01:00
|
|
|
static memory::byte_patch* local_name_patch{};
|
|
|
|
|
2022-05-28 17:44:05 +02:00
|
|
|
void hooks::network_player_mgr_init(CNetworkPlayerMgr* _this, std::uint64_t a2, std::uint32_t a3, std::uint32_t a4[4])
|
|
|
|
{
|
2022-12-18 23:15:52 +01:00
|
|
|
if (g.notifications.network_player_mgr_init.log)
|
2022-05-28 17:44:05 +02:00
|
|
|
LOG(INFO) << "CNetworkPlayerMgr#init got called, we're probably entering a session.";
|
2022-12-18 23:15:52 +01:00
|
|
|
if (g.notifications.network_player_mgr_init.notify)
|
2022-05-28 17:44:05 +02:00
|
|
|
g_notification_service->push("Network Player Manager", "Entering session and initializing player data.");
|
|
|
|
|
2022-12-23 00:03:34 +01:00
|
|
|
// set our local spoofed name
|
|
|
|
if (g.spoofing.spoof_username && g.spoofing.spoof_local_username)
|
|
|
|
{
|
2022-12-31 14:24:59 +01:00
|
|
|
std::array<char, 17> local_name;
|
|
|
|
std::copy(g.spoofing.username.begin(), g.spoofing.username.end(), local_name.data());
|
|
|
|
local_name_patch = memory::byte_patch::make(g_pointers->m_chat_gamer_info->m_name, local_name).get();
|
2022-12-23 00:03:34 +01:00
|
|
|
local_name_patch->apply();
|
|
|
|
}
|
|
|
|
|
2022-10-30 19:32:51 +01:00
|
|
|
g_hooking->get_original<hooks::network_player_mgr_init>()(_this, a2, a3, a4);
|
2022-05-28 17:44:05 +02:00
|
|
|
|
|
|
|
g_player_service->player_join(_this->m_local_net_player);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hooks::network_player_mgr_shutdown(CNetworkPlayerMgr* _this)
|
|
|
|
{
|
2022-12-18 23:15:52 +01:00
|
|
|
g.m_spoofed_peer_ids.clear();
|
2022-05-28 17:44:05 +02:00
|
|
|
g_player_service->do_cleanup();
|
|
|
|
|
2022-12-23 00:03:34 +01:00
|
|
|
// restore our original name
|
|
|
|
if (strcmp(g_pointers->m_chat_gamer_info->m_name, _this->m_local_net_player->get_name()) && local_name_patch)
|
|
|
|
{
|
|
|
|
local_name_patch->remove();
|
|
|
|
}
|
|
|
|
|
2022-12-18 23:15:52 +01:00
|
|
|
if (g.notifications.network_player_mgr_shutdown.log)
|
2022-05-28 17:44:05 +02:00
|
|
|
LOG(INFO) << "CNetworkPlayerMgr#shutdown got called, we're probably leaving our session.";
|
2022-12-18 23:15:52 +01:00
|
|
|
if (g.notifications.network_player_mgr_shutdown.notify)
|
2022-05-28 17:44:05 +02:00
|
|
|
g_notification_service->push("Network Player Manager", "Leaving session and cleaning up player data.");
|
|
|
|
|
2022-10-30 19:32:51 +01:00
|
|
|
g_hooking->get_original<hooks::network_player_mgr_shutdown>()(_this);
|
2022-05-28 17:44:05 +02:00
|
|
|
}
|
2022-10-30 19:32:51 +01:00
|
|
|
}
|