feat(Hooks, PlayerList): CNetworkPlayerMgr::init(), add self (#251)

This commit is contained in:
mentolixite 2022-05-28 17:44:05 +02:00 committed by GitHub
parent b76af4e443
commit 30a48b6c6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 68 additions and 37 deletions

View File

@ -64,6 +64,8 @@ namespace big
pair gta_thread_start{};
pair net_array_error{};
pair network_player_mgr_init{};
pair network_player_mgr_shutdown{};
struct
@ -327,6 +329,8 @@ namespace big
g->notifications.net_array_error.log = j["notifications"]["net_array_error"]["log"];
g->notifications.net_array_error.notify = j["notifications"]["net_array_error"]["notify"];
g->notifications.network_player_mgr_init.log = j["notifications"]["network_player_mgr_init"]["log"];
g->notifications.network_player_mgr_init.notify = j["notifications"]["network_player_mgr_init"]["notify"];
g->notifications.network_player_mgr_shutdown.log = j["notifications"]["network_player_mgr_shutdown"]["log"];
g->notifications.network_player_mgr_shutdown.notify = j["notifications"]["network_player_mgr_shutdown"]["notify"];
@ -566,6 +570,7 @@ namespace big
{ "gta_thread_kill", return_notify_pair(g->notifications.gta_thread_kill) },
{ "gta_thread_start", return_notify_pair(g->notifications.gta_thread_start) },
{"net_array_error", return_notify_pair(g->notifications.net_array_error)},
{ "network_player_mgr_init", return_notify_pair(g->notifications.network_player_mgr_init) },
{ "network_player_mgr_shutdown", return_notify_pair(g->notifications.network_player_mgr_shutdown) },
{ "player_join", {
{ "above_map", g->notifications.player_join.above_map },

View File

@ -32,6 +32,8 @@ namespace big
// GTA Thread Kill
m_gta_thread_kill_hook("GTK", g_pointers->m_gta_thread_kill, &hooks::gta_thread_kill),
// Network Player Mgr Init
m_network_player_mgr_init_hook("NPMI", g_pointers->m_network_player_mgr_init, &hooks::network_player_mgr_init),
// Network Player Mgr Shutdown
m_network_player_mgr_shutdown_hook("NPMS", g_pointers->m_network_player_mgr_shutdown, &hooks::network_player_mgr_shutdown),
@ -90,6 +92,8 @@ namespace big
m_gta_thread_kill_hook.enable();
m_network_group_override.enable();
m_network_player_mgr_init_hook.enable();
m_network_player_mgr_shutdown_hook.enable();
m_net_array_handler_hook.enable();
@ -131,7 +135,9 @@ namespace big
m_net_array_handler_hook.disable();
m_network_player_mgr_init_hook.disable();
m_network_player_mgr_shutdown_hook.disable();
m_network_group_override.disable();
m_gta_thread_kill_hook.disable();

View File

@ -26,6 +26,7 @@ namespace big
static GtaThread* gta_thread_start(unsigned int** a1, unsigned int a2);
static rage::eThreadState gta_thread_kill(GtaThread* thread);
static void network_player_mgr_init(CNetworkPlayerMgr* _this, std::uint64_t a2, std::uint32_t a3, std::uint32_t a4[4]);
static void network_player_mgr_shutdown(CNetworkPlayerMgr* _this);
static void network_group_override(std::int64_t a1, std::int64_t a2, std::int64_t a3);
@ -89,6 +90,7 @@ namespace big
detour_hook m_gta_thread_start_hook;
detour_hook m_gta_thread_kill_hook;
detour_hook m_network_player_mgr_init_hook;
detour_hook m_network_player_mgr_shutdown_hook;
detour_hook m_network_group_override;

View File

@ -0,0 +1,29 @@
#include "hooking.hpp"
#include "services/player_service.hpp"
namespace big
{
void hooks::network_player_mgr_init(CNetworkPlayerMgr* _this, std::uint64_t a2, std::uint32_t a3, std::uint32_t a4[4])
{
if (g->notifications.network_player_mgr_init.log)
LOG(INFO) << "CNetworkPlayerMgr#init got called, we're probably entering a session.";
if (g->notifications.network_player_mgr_init.notify)
g_notification_service->push("Network Player Manager", "Entering session and initializing player data.");
g_hooking->m_network_player_mgr_init_hook.get_original<decltype(&hooks::network_player_mgr_init)>()(_this, a2, a3, a4);
g_player_service->player_join(_this->m_local_net_player);
}
void hooks::network_player_mgr_shutdown(CNetworkPlayerMgr* _this)
{
g_player_service->do_cleanup();
if (g->notifications.network_player_mgr_shutdown.log)
LOG(INFO) << "CNetworkPlayerMgr#shutdown got called, we're probably leaving our session.";
if (g->notifications.network_player_mgr_shutdown.notify)
g_notification_service->push("Network Player Manager", "Leaving session and cleaning up player data.");
g_hooking->m_network_player_mgr_shutdown_hook.get_original<decltype(&hooks::network_player_mgr_shutdown)>()(_this);
}
}

View File

@ -1,17 +0,0 @@
#include "hooking.hpp"
#include "services/player_service.hpp"
namespace big
{
void hooks::network_player_mgr_shutdown(CNetworkPlayerMgr* _this)
{
g_player_service->do_cleanup();
if (g->notifications.network_player_mgr_shutdown.log)
LOG(INFO) << "CNetworkPlayerMgr#shutdown got called, we're probably leaving our session.";
if (g->notifications.network_player_mgr_shutdown.notify)
g_notification_service->push("Network Player Manager", "Leaving session and cleaning up player data.");
return g_hooking->m_network_player_mgr_shutdown_hook.get_original<decltype(&hooks::network_player_mgr_shutdown)>()(_this);
}
}

View File

@ -200,10 +200,16 @@ namespace big
m_player_has_left = ptr.sub(0x26).as<PVOID>();
});
// Network Player Mgr Shutdown
main_batch.add("NPMS", "41 57 48 81 EC ? ? ? ? 8A 81 ? ? ? ? 48", [this](memory::handle ptr)
// Network Player Mgr Init
main_batch.add("NPMI", "41 56 48 83 EC ? 48 8B F1 B9 ? ? ? ? 49 8B F9 41 8B E8 4C 8B F2 E8", [this](memory::handle ptr)
{
m_network_player_mgr_shutdown = ptr.sub(0x17).as<PVOID>();
m_network_player_mgr_init = ptr.sub(0x13).as<decltype(m_network_player_mgr_init)>();
});
// Network Player Mgr Shutdown
main_batch.add("NPMS", "48 8D 9F ? ? ? ? EB ? 48 8B 13 48 85 D2 74 ? 48 8B CB E8 ? ? ? ? 48 83 7B ? ? 75 ? 48 8D 9F", [this](memory::handle ptr)
{
m_network_player_mgr_shutdown = ptr.sub(0x1A).as<decltype(m_network_player_mgr_shutdown)>();
});
// FriendRegistry

View File

@ -58,6 +58,7 @@ namespace big
PVOID m_gta_thread_start{};
PVOID m_gta_thread_kill{};
PVOID m_network_player_mgr_init;
PVOID m_network_player_mgr_shutdown;
PVOID m_net_array_handler;

View File

@ -84,26 +84,23 @@ namespace big
player_service::player_service()
{
if (CNetworkPlayerMgr* network_player_mgr = gta_util::get_network_player_mgr())
{
for (size_t i = 0; i < network_player_mgr->m_player_limit; i++)
{
if (CNetGamePlayer* net_game_player = network_player_mgr->m_player_list[i]; net_game_player != nullptr)
{
std::unique_ptr<player> plyr = std::make_unique<player>(net_game_player);
plyr->m_is_friend = friends_service::is_friend(plyr);
m_players.emplace(
plyr->to_lowercase_identifier(),
std::move(plyr)
);
}
}
}
g_player_service = this;
m_dummy_player = new player(nullptr);
g_player_service = this;
auto network_player_mgr = gta_util::get_network_player_mgr();
if (!network_player_mgr)
return;
auto net_game_player = network_player_mgr->m_local_net_player;
if (!net_game_player)
return;
for (uint16_t i = 0; i < network_player_mgr->m_player_limit; ++i)
{
net_game_player = network_player_mgr->m_player_list[i];
player_join(net_game_player);
}
}
player_service::~player_service()

View File

@ -31,6 +31,8 @@ namespace big
ImGui::SameLine();
draw_pair_option("Player Leave", g->notifications.player_leave);
draw_pair_option("Init", g->notifications.network_player_mgr_init);
draw_pair_option("Shutdown", g->notifications.network_player_mgr_shutdown);
components::small_text("Received Event");