diff --git a/BigBaseV2/src/core/globals.hpp b/BigBaseV2/src/core/globals.hpp index 00770730..2589060c 100644 --- a/BigBaseV2/src/core/globals.hpp +++ b/BigBaseV2/src/core/globals.hpp @@ -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 }, diff --git a/BigBaseV2/src/hooking.cpp b/BigBaseV2/src/hooking.cpp index 5c4e1738..88bf034f 100644 --- a/BigBaseV2/src/hooking.cpp +++ b/BigBaseV2/src/hooking.cpp @@ -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(); diff --git a/BigBaseV2/src/hooking.hpp b/BigBaseV2/src/hooking.hpp index 1ab34e06..b855dcc5 100644 --- a/BigBaseV2/src/hooking.hpp +++ b/BigBaseV2/src/hooking.hpp @@ -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; diff --git a/BigBaseV2/src/hooks/network_player_mgr.cpp b/BigBaseV2/src/hooks/network_player_mgr.cpp new file mode 100644 index 00000000..07e85015 --- /dev/null +++ b/BigBaseV2/src/hooks/network_player_mgr.cpp @@ -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()(_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()(_this); + } +} \ No newline at end of file diff --git a/BigBaseV2/src/hooks/network_player_mgr_shutdown.cpp b/BigBaseV2/src/hooks/network_player_mgr_shutdown.cpp deleted file mode 100644 index 0fd3f1a0..00000000 --- a/BigBaseV2/src/hooks/network_player_mgr_shutdown.cpp +++ /dev/null @@ -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()(_this); - } -} \ No newline at end of file diff --git a/BigBaseV2/src/pointers.cpp b/BigBaseV2/src/pointers.cpp index 1cbfa4fb..acb23064 100644 --- a/BigBaseV2/src/pointers.cpp +++ b/BigBaseV2/src/pointers.cpp @@ -200,10 +200,16 @@ namespace big m_player_has_left = ptr.sub(0x26).as(); }); - // 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(); + m_network_player_mgr_init = ptr.sub(0x13).as(); + }); + + // 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(); }); // FriendRegistry diff --git a/BigBaseV2/src/pointers.hpp b/BigBaseV2/src/pointers.hpp index db6c7616..1122be0d 100644 --- a/BigBaseV2/src/pointers.hpp +++ b/BigBaseV2/src/pointers.hpp @@ -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; diff --git a/BigBaseV2/src/services/player_service.cpp b/BigBaseV2/src/services/player_service.cpp index 37df865c..1c7985e8 100644 --- a/BigBaseV2/src/services/player_service.cpp +++ b/BigBaseV2/src/services/player_service.cpp @@ -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 plyr = std::make_unique(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() diff --git a/BigBaseV2/src/views/settings/view_notification_settings.cpp b/BigBaseV2/src/views/settings/view_notification_settings.cpp index ef14d809..b3603f43 100644 --- a/BigBaseV2/src/views/settings/view_notification_settings.cpp +++ b/BigBaseV2/src/views/settings/view_notification_settings.cpp @@ -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");