diff --git a/BigBaseV2/src/backend/backend.cpp b/BigBaseV2/src/backend/backend.cpp index 3aa40593..429c1285 100644 --- a/BigBaseV2/src/backend/backend.cpp +++ b/BigBaseV2/src/backend/backend.cpp @@ -14,7 +14,6 @@ namespace big QUEUE_JOB_BEGIN_CLAUSE() { looped::system_screen_size(); - looped::system_update_players(); looped::system_update_pointers(); }QUEUE_JOB_END_CLAUSE diff --git a/BigBaseV2/src/backend/looped/player/spectate.cpp b/BigBaseV2/src/backend/looped/player/spectate.cpp index 0b63a473..d9732d32 100644 --- a/BigBaseV2/src/backend/looped/player/spectate.cpp +++ b/BigBaseV2/src/backend/looped/player/spectate.cpp @@ -1,6 +1,7 @@ #include "backend/looped/looped.hpp" #include "pointers.hpp" #include "natives.hpp" +#include "services/player_service.hpp" namespace big { @@ -8,7 +9,7 @@ namespace big void looped::player_specate() { - if (!g.selected_player.is_online || !g.player.spectating) + if (g_player_service->m_selected_player == nullptr || !g.player.spectating) { if (g.player.spectating) g.player.spectating = false; @@ -23,7 +24,7 @@ namespace big return; } - Ped target = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(g.selected_player.id); + Ped target = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(g_player_service->m_selected_player->id()); g_pointers->m_spectate_player(true, target); HUD::SET_MINIMAP_IN_SPECTATOR_MODE(true, target); diff --git a/BigBaseV2/src/backend/looped/system/update_player_structs.cpp b/BigBaseV2/src/backend/looped/system/update_player_structs.cpp deleted file mode 100644 index f4d9020f..00000000 --- a/BigBaseV2/src/backend/looped/system/update_player_structs.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "backend/looped/looped.hpp" -#include "natives.hpp" -#include "pointers.hpp" -#include "script.hpp" -#include "util/notify.hpp" - -namespace big -{ - static bool busy = false; - - void looped::system_update_players() - { - if (busy) return; - busy = true; - - for (Player i = 0; i < 32; i++) - { - CPlayer& player = g.players[i]; - - if (NETWORK::NETWORK_IS_PLAYER_ACTIVE(i)) - { - strcpy(g.players[i].name, PLAYER::GET_PLAYER_NAME(i)); - - player.net_player = g_pointers->m_get_net_game_player(i); - - if (player.is_online) - continue; - - player.id = i; - player.is_online = true; - - int iNetworkHandle[13]; - NETWORK::NETWORK_HANDLE_FROM_PLAYER(i, iNetworkHandle, 13); - bool is_friend = NETWORK::NETWORK_IS_HANDLE_VALID(&iNetworkHandle[0], 13) && NETWORK::NETWORK_IS_FRIEND(&iNetworkHandle[0]); - - if (is_friend) - { - player.is_friend = true; - - g.friend_count++; - } - else g.player_count++; - - notify::player_joined(player); - } - else if (player.is_online) - { - if (player.is_friend) g.friend_count--; - else g.player_count--; - - player.is_friend = false; - player.is_online = false; - } - - script::get_current()->yield(); - } - - if (g.window.player) // update selected player only while the player menu is open - g.selected_player = g.players[g.selected_player.id]; - - busy = false; - } -} \ No newline at end of file diff --git a/BigBaseV2/src/core/data/player_struct.hpp b/BigBaseV2/src/core/data/player_struct.hpp deleted file mode 100644 index a87a96dc..00000000 --- a/BigBaseV2/src/core/data/player_struct.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once -#include "CNetGamePlayer.hpp" - -#ifndef PLAYER_STRUCT -#define PLAYER_STRUCT - -namespace big -{ - struct CPlayer - { - int32_t id; - char name[20]; - - bool is_friend = false; - bool is_online = false; - - CNetGamePlayer* net_player; - - bool operator < (const CPlayer& another) const - { - char temp[20], temp2[20]; - - for (uint8_t i = 0; i < 20; i++) - { - temp[i] = tolower(this->name[i]); - temp2[i] = tolower(another.name[i]); - } - - return strcmp(temp, temp2) < 0; - } - }; -} - -#endif \ No newline at end of file diff --git a/BigBaseV2/src/core/globals.hpp b/BigBaseV2/src/core/globals.hpp index 10f00968..5aefb517 100644 --- a/BigBaseV2/src/core/globals.hpp +++ b/BigBaseV2/src/core/globals.hpp @@ -1,5 +1,4 @@ #pragma once -#include "data/player_struct.hpp" #include "enums.hpp" #ifndef GLOBALS_H @@ -133,8 +132,6 @@ struct globals { int friend_count = 0; int player_count = 0; - CPlayer players[32]; - CPlayer selected_player; debug debug{}; tunables tunables{}; diff --git a/BigBaseV2/src/gta/player.hpp b/BigBaseV2/src/gta/player.hpp index 87b0e537..055141a4 100644 --- a/BigBaseV2/src/gta/player.hpp +++ b/BigBaseV2/src/gta/player.hpp @@ -5,59 +5,7 @@ #include "vector.hpp" #include "gta\natives.hpp" -#pragma pack(push, 1) -namespace rage -{ - class netPlayerMgrBase - { - public: - virtual ~netPlayerMgrBase() = default; // 0 (0x00) - }; -} - namespace gta { inline constexpr auto num_players = 32; } - -//class CPlayerInfo : public rage::fwExtensibleBase -//{ -//public: -// char pad_0020[20]; //0x0020 -// uint32_t m_internal_ip; //0x0034 -// uint16_t m_internal_port; //0x0038 -// char pad_003A[2]; //0x003A -// uint32_t m_relay_ip; //0x003C -// uint16_t m_relay_port; //0x0040 -// char pad_0042[2]; //0x0042 -// uint32_t m_external_ip; //0x0044 -// uint16_t m_external_port; //0x0048 -// char pad_004A[38]; //0x004A -// uint64_t m_rockstar_id; //0x0070 -// char pad_0078[12]; //0x0078 -// char m_name[20]; //0x0084 -// char pad_0098[180]; //0x0098 -// float m_swim_speed; //0x014C -// float m_run_speed; //0x0150 -// char pad_0154[81]; //0x0154 -// bool m_is_rockstar_dev; //0x01A5 -// char pad_01A6[1]; //0x01A6 -// bool m_is_cheater; //0x01A7 -// char pad_01A8[11]; //0x01A8 -// bool m_is_online; //0x01B3 -// char pad_01B4[20]; //0x01B4 -// class CPed* m_ped; //0x01C8 -// char pad_01D0[40]; //0x01D0 -// uint32_t m_frame_flags; //0x01F8 -// char pad_01FC[28]; //0x01FC -// uint32_t m_player_controls; //0x0218 -// char pad_021C[1604]; //0x021C -// bool m_is_wanted; //0x0860 -// char pad_0861[3]; //0x0861 -// int8_t m_wanted_level_display; //0x0864 -// char pad_0865[3]; //0x0865 -// int8_t m_wanted_level; //0x0868 -//}; //Size: 0x0869 -//static_assert(sizeof(CPlayerInfo) == 0x869); - -#pragma pack(pop) diff --git a/BigBaseV2/src/gta_util.hpp b/BigBaseV2/src/gta_util.hpp index 2ed065a7..221316dd 100644 --- a/BigBaseV2/src/gta_util.hpp +++ b/BigBaseV2/src/gta_util.hpp @@ -1,8 +1,7 @@ #pragma once -#include "common.hpp" #include "gta/array.hpp" #include "CPedFactory.hpp" -#include "gta/player.hpp" +#include "CNetworkPlayerMgr.hpp" #include "gta/script_thread.hpp" #include "gta/tls_context.hpp" #include "pointers.hpp" @@ -32,6 +31,11 @@ namespace big::gta_util return nullptr; } + inline CNetworkPlayerMgr* get_network_player_mgr() + { + return *g_pointers->m_network_player_mgr; + } + template void execute_as_script(rage::joaat_t script_hash, F &&callback, Args &&...args) { diff --git a/BigBaseV2/src/gui/window.hpp b/BigBaseV2/src/gui/window.hpp index c7eeadb3..1a9bbe60 100644 --- a/BigBaseV2/src/gui/window.hpp +++ b/BigBaseV2/src/gui/window.hpp @@ -9,7 +9,7 @@ namespace big static void handling(); static void log(); static void main(); - static void player(); + static void w_player(); static void users(); public: @@ -24,7 +24,7 @@ namespace big window::main(); window::handling(); - window::player(); + window::w_player(); window::users(); } }; diff --git a/BigBaseV2/src/gui/window/player/player_info.cpp b/BigBaseV2/src/gui/window/player/player_info.cpp index ef6495be..e1d7d20d 100644 --- a/BigBaseV2/src/gui/window/player/player_info.cpp +++ b/BigBaseV2/src/gui/window/player/player_info.cpp @@ -11,31 +11,35 @@ namespace big ImGui::Separator(); - ImGui::Text("Player ID: %d", g.selected_player.id); + ImGui::Text("Player ID: %d", g_player_service->m_selected_player->id()); - - if (CNetGamePlayer* net_player = g.selected_player.net_player; net_player != nullptr) - { - if (CPlayerInfo* player_info = net_player->m_player_info; player_info != nullptr) - { - rage::netPlayerData& netData = player_info->m_net_player_data; - - ImGui::Text("Session Host: %s", net_player->is_host() ? "Yes" : "No"); + ImGui::Text("Session Host: %s", g_player_service->m_selected_player->is_host() ? "Yes" : "No"); - ImGui::Separator(); + ImGui::Separator(); - ImGui::Text("Wanted Level: %d", player_info->m_wanted_level); - ImGui::Text("Player God Mode: %s", misc::has_bit_set((int*)&player_info->m_ped->m_damage_bits, 8) ? "Yes" : "No"); - ImGui::Text("Vehicle God Mode: %s", - player_info->m_ped->m_vehicle == nullptr ? "No vehicle detected" : - misc::has_bit_set((int*)&player_info->m_ped->m_vehicle->m_damage_bits, 8) ? "Yes" : "No" - ); + if (CPlayerInfo* player_info = g_player_service->m_selected_player->get_player_info(); player_info != nullptr) + { + ImGui::Text("Wanted Level: %d", player_info->m_wanted_level); + ImGui::Text("Player God Mode: %s", misc::has_bit_set((int*)&player_info->m_ped->m_damage_bits, 8) ? "Yes" : "No"); + ImGui::Text("Vehicle God Mode: %s", + player_info->m_ped->m_vehicle == nullptr ? "No vehicle detected" : + misc::has_bit_set((int*)&player_info->m_ped->m_vehicle->m_damage_bits, 8) ? "Yes" : "No" + ); + } - ImGui::Separator(); + ImGui::Separator(); - ImGui::Text("Rockstar ID: %d", netData.m_rockstar_id); - ImGui::Text("IP Address: %d.%d.%d.%d:%d", netData.m_external_ip.m_field1, netData.m_external_ip.m_field2, netData.m_external_ip.m_field3, netData.m_external_ip.m_field4, netData.m_external_port); - } + if (rage::netPlayerData* net_player_data = g_player_service->m_selected_player->get_net_data(); net_player_data != nullptr) + { + ImGui::Text("Rockstar ID: %d", net_player_data->m_rockstar_id); + ImGui::Text( + "IP Address: %d.%d.%d.%d:%d", + net_player_data->m_external_ip.m_field1, + net_player_data->m_external_ip.m_field2, + net_player_data->m_external_ip.m_field3, + net_player_data->m_external_ip.m_field4, + net_player_data->m_external_port + ); } ImGui::EndTabItem(); diff --git a/BigBaseV2/src/gui/window/player/player_tabs.hpp b/BigBaseV2/src/gui/window/player/player_tabs.hpp index 5b300659..7ead0891 100644 --- a/BigBaseV2/src/gui/window/player/player_tabs.hpp +++ b/BigBaseV2/src/gui/window/player/player_tabs.hpp @@ -1,6 +1,6 @@ #pragma once -#include "common.hpp" #include "imgui.h" +#include "services/player_service.hpp" namespace big::tab_player { diff --git a/BigBaseV2/src/gui/window/player/player_teleport.cpp b/BigBaseV2/src/gui/window/player/player_teleport.cpp index 801cd422..8cace2ad 100644 --- a/BigBaseV2/src/gui/window/player/player_teleport.cpp +++ b/BigBaseV2/src/gui/window/player/player_teleport.cpp @@ -12,7 +12,7 @@ namespace big { QUEUE_JOB_BEGIN_CLAUSE() { - teleport::to_player(g.selected_player.id); + teleport::to_player(g_player_service->m_selected_player->id()); }QUEUE_JOB_END_CLAUSE } @@ -21,7 +21,7 @@ namespace big { QUEUE_JOB_BEGIN_CLAUSE() { - teleport::bring_player(g.selected_player.id); + teleport::bring_player(g_player_service->m_selected_player->id()); }QUEUE_JOB_END_CLAUSE } @@ -29,7 +29,7 @@ namespace big { QUEUE_JOB_BEGIN_CLAUSE() { - Vehicle veh = PED::GET_VEHICLE_PED_IS_IN(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(g.selected_player.id), false); + Vehicle veh = PED::GET_VEHICLE_PED_IS_IN(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(g_player_service->m_selected_player->id()), false); teleport::into_vehicle(veh); }QUEUE_JOB_END_CLAUSE diff --git a/BigBaseV2/src/gui/window/player/player_toxic.cpp b/BigBaseV2/src/gui/window/player/player_toxic.cpp index 5a5b25a6..01810075 100644 --- a/BigBaseV2/src/gui/window/player/player_toxic.cpp +++ b/BigBaseV2/src/gui/window/player/player_toxic.cpp @@ -16,7 +16,11 @@ namespace big { QUEUE_JOB_BEGIN_CLAUSE() { - toxic::blame_explode_player(g.selected_player.id, g.selected_player.id, eExplosionType::PLANE, 1000, false, true, 0.f); + toxic::blame_explode_player( + g_player_service->m_selected_player->id(), + g_player_service->m_selected_player->id(), + eExplosionType::PLANE, 1000, false, true, 0.f + ); }QUEUE_JOB_END_CLAUSE } diff --git a/BigBaseV2/src/gui/window/window_player.cpp b/BigBaseV2/src/gui/window/window_player.cpp index 97addd48..f7f538c4 100644 --- a/BigBaseV2/src/gui/window/window_player.cpp +++ b/BigBaseV2/src/gui/window/window_player.cpp @@ -4,18 +4,19 @@ namespace big { - void window::player() + void window::w_player() { - if (!g.selected_player.is_online) + if (g_player_service->m_selected_player == nullptr || !g_player_service->m_selected_player->is_valid()) { g.window.player = false; return; } + else g.window.player = true; char title[64]; strcpy(title, "Player Options: "); - strcat(title, g.selected_player.name); + strcat(title, g_player_service->m_selected_player->get_name()); strcat(title, "###player_options"); ImGui::SetNextWindowSize({ 350.f, 300.f }, ImGuiCond_FirstUseEver); @@ -29,5 +30,8 @@ namespace big ImGui::End(); } + + if (!g.window.player) + g_player_service->m_selected_player = nullptr; } } \ No newline at end of file diff --git a/BigBaseV2/src/gui/window/window_users.cpp b/BigBaseV2/src/gui/window/window_users.cpp index be17b58c..54745943 100644 --- a/BigBaseV2/src/gui/window/window_users.cpp +++ b/BigBaseV2/src/gui/window/window_users.cpp @@ -1,7 +1,6 @@ -#include -#include #include "gui/window.hpp" #include "imgui.h" +#include "services/player_service.hpp" namespace big { @@ -14,73 +13,13 @@ namespace big ImGui::SetNextWindowPos({ g.window.x - width, height_correction }, ImGuiCond_Always); if (g.window.users && ImGui::Begin("###player_menu", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoNav)) { - auto vecButtonWidth = ImVec2(ImGui::GetWindowSize().x - 15.f, 0.0f); - - //ImGui::TextColored({ 255,255,255,255 }, "YOU:"); - - //if (ImGui::Button(g_player.name, vecButtonWidth)) - //{ - // g_selectedPlayer = g_player; - // g_temp.windows.player = true; - //} - - //ImGui::Separator(); - - CPlayer players[32]; - std::copy(std::begin(g.players), std::end(g.players), std::begin(players)); - std::sort(std::begin(players), std::end(players)); - - char title[64]; - sprintf(title, "Friends (%d)###friend_lists", g.friend_count); - if (ImGui::TreeNode(title)) + for (auto& item : g_player_service->m_players) { - ImGui::Unindent(); - - bool friendInLobby = false; - - for (auto& player : players) + std::unique_ptr& plyr = item.second; + if (ImGui::Button(plyr->get_name(), { ImGui::GetWindowSize().x - 15.f, 0.f })) { - if (player.is_friend && player.is_online) - { - friendInLobby = true; - - if (ImGui::Button(player.name, vecButtonWidth)) - { - g.selected_player = player; - g.window.player = true; - } - } + g_player_service->m_selected_player = plyr.get(); } - - if (!friendInLobby) - { - ImGui::TextColored({ 180,180,180,255 }, "No friends in\ncurrent lobby."); - } - - ImGui::Indent(); - ImGui::TreePop(); - ImGui::Separator(); - } - - sprintf(title, "Players (%d)###player_lists", g.player_count); - if (ImGui::TreeNode(title)) - { - ImGui::Unindent(); - - for (auto& player : players) - { - if (!player.is_friend && player.is_online) - { - if (ImGui::Button(player.name, vecButtonWidth)) - { - g.selected_player = player; - g.window.player = true; - } - } - } - - ImGui::Indent(); - ImGui::TreePop(); } ImGui::End(); diff --git a/BigBaseV2/src/hooking.cpp b/BigBaseV2/src/hooking.cpp index 12f4492a..dfd10099 100644 --- a/BigBaseV2/src/hooking.cpp +++ b/BigBaseV2/src/hooking.cpp @@ -34,6 +34,9 @@ namespace big // GTA Thread Kill m_gta_thread_kill_hook("GTK", g_pointers->m_gta_thread_kill, &hooks::gta_thread_kill), + // Network Player Mgr Shutdown + m_network_player_mgr_shutdown_hook("NPMS", g_pointers->m_network_player_mgr_shutdown, &hooks::network_player_mgr_shutdown), + // Increment Stat Event m_increment_stat_hook("ISE", g_pointers->m_increment_stat_event, &hooks::increment_stat_event), // Is DLC Present @@ -83,6 +86,8 @@ namespace big m_gta_thread_kill_hook.enable(); m_gta_thread_tick_hook.enable(); + m_network_player_mgr_shutdown_hook.enable(); + m_player_has_joined_hook.enable(); m_player_has_left_hook.enable(); @@ -116,6 +121,8 @@ namespace big m_player_has_joined_hook.disable(); m_player_has_left_hook.disable(); + m_network_player_mgr_shutdown_hook.disable(); + m_gta_thread_tick_hook.disable(); m_gta_thread_kill_hook.disable(); m_gta_thread_start_hook.disable(); diff --git a/BigBaseV2/src/hooking.hpp b/BigBaseV2/src/hooking.hpp index 1cc831b7..a36dcdce 100644 --- a/BigBaseV2/src/hooking.hpp +++ b/BigBaseV2/src/hooking.hpp @@ -40,6 +40,8 @@ namespace big static rage::eThreadState gta_thread_tick(GtaThread* a1, unsigned int a2); static rage::eThreadState gta_thread_kill(GtaThread* thread); + static void network_player_mgr_shutdown(CNetworkPlayerMgr* _this); + static void player_join(CNetworkObjectMgr* _this, CNetGamePlayer* net_player); static void player_leave(CNetworkObjectMgr* _this, CNetGamePlayer* net_player); @@ -95,6 +97,8 @@ namespace big detour_hook m_gta_thread_tick_hook; detour_hook m_gta_thread_kill_hook; + detour_hook m_network_player_mgr_shutdown_hook; + detour_hook m_player_has_joined_hook; detour_hook m_player_has_left_hook; diff --git a/BigBaseV2/src/hooks/network_player_mgr_shutdown.cpp b/BigBaseV2/src/hooks/network_player_mgr_shutdown.cpp new file mode 100644 index 00000000..265b81d4 --- /dev/null +++ b/BigBaseV2/src/hooks/network_player_mgr_shutdown.cpp @@ -0,0 +1,12 @@ +#include "hooking.hpp" +#include "services/player_service.hpp" + +namespace big +{ + void hooks::network_player_mgr_shutdown(CNetworkPlayerMgr* _this) + { + g_player_service->do_cleanup(); + + return g_hooking->m_network_player_mgr_shutdown_hook.get_original()(_this); + } +} \ No newline at end of file diff --git a/BigBaseV2/src/hooks/player_join.cpp b/BigBaseV2/src/hooks/player_join.cpp index 8934e6d0..416f1043 100644 --- a/BigBaseV2/src/hooks/player_join.cpp +++ b/BigBaseV2/src/hooks/player_join.cpp @@ -1,4 +1,5 @@ #include "hooking.hpp" +#include "services/player_service.hpp" namespace big { @@ -6,6 +7,8 @@ namespace big { LOG(INFO) << "Player '" << net_player->get_name() << "' joined taking slot #" << (int)net_player->m_player_id; + g_player_service->player_join(net_player); + return g_hooking->m_player_has_joined_hook.get_original()(_this, net_player); } } \ No newline at end of file diff --git a/BigBaseV2/src/hooks/player_left.cpp b/BigBaseV2/src/hooks/player_left.cpp index 1fd042c3..6f5453e0 100644 --- a/BigBaseV2/src/hooks/player_left.cpp +++ b/BigBaseV2/src/hooks/player_left.cpp @@ -1,4 +1,5 @@ #include "hooking.hpp" +#include "services/player_service.hpp" namespace big { @@ -6,6 +7,8 @@ namespace big { LOG(INFO) << "Player '" << net_player->get_name() << "' left freeing slot #" << (int)net_player->m_player_id; + g_player_service->player_leave(net_player); + return g_hooking->m_player_has_left_hook.get_original()(_this, net_player); } } \ No newline at end of file diff --git a/BigBaseV2/src/main.cpp b/BigBaseV2/src/main.cpp index 2bd3df14..4cd896d9 100644 --- a/BigBaseV2/src/main.cpp +++ b/BigBaseV2/src/main.cpp @@ -11,6 +11,7 @@ #include "native_hooks/native_hooks.hpp" #include "services/globals_service.hpp" +#include "services/player_service.hpp" #include "services/mobile_service.hpp" #include "services/vehicle_service.hpp" @@ -49,47 +50,49 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID) auto thread_pool_instance = std::make_unique(); LOG(INFO) << "Thread pool initialized."; + auto globals_service_instace = std::make_unique(); + auto mobile_service_instance = std::make_unique(); + auto player_service_instance = std::make_unique(); + auto vehicle_service_instance = std::make_unique(); + LOG(INFO) << "Registered service instances..."; + g_script_mgr.add_script(std::make_unique