From 24a7e7d906a8d81dc682977824f7fc6ee9b22a90 Mon Sep 17 00:00:00 2001 From: Yimura Date: Mon, 21 Mar 2022 18:02:30 +0100 Subject: [PATCH] refactor: Improvements and small changes (#125) * fix(Looped): Typo in spectate function name * fix(Spectate): Prevent falling through world * feat(Pointers): Shortened useless part of signature * feat(ReceivedEvent): Removed unused include * feat(Protections): Optimised NET_ARRAY_ERROR protection * feat(View/Settings): Restructured protections dropdown --- BigBaseV2/src/backend/backend.cpp | 3 +-- BigBaseV2/src/backend/looped/looped.hpp | 2 +- .../src/backend/looped/player/spectate.cpp | 9 ++++--- BigBaseV2/src/hooking.hpp | 2 +- BigBaseV2/src/hooks/net_array_handler.cpp | 24 ++++--------------- BigBaseV2/src/hooks/received_event.cpp | 1 - BigBaseV2/src/pointers.cpp | 2 +- BigBaseV2/src/views/view_settings.cpp | 12 ++++++++++ 8 files changed, 26 insertions(+), 29 deletions(-) diff --git a/BigBaseV2/src/backend/backend.cpp b/BigBaseV2/src/backend/backend.cpp index c3b036ec..63789663 100644 --- a/BigBaseV2/src/backend/backend.cpp +++ b/BigBaseV2/src/backend/backend.cpp @@ -2,7 +2,6 @@ #include "backend.hpp" #include "fiber_pool.hpp" #include "looped/looped.hpp" -#include "pointers.hpp" #include "script.hpp" #include "thread_pool.hpp" @@ -57,7 +56,7 @@ namespace big QUEUE_JOB_BEGIN_CLAUSE() { looped::player_never_wanted(); - looped::player_specate(); + looped::player_spectate(); }QUEUE_JOB_END_CLAUSE QUEUE_JOB_BEGIN_CLAUSE() diff --git a/BigBaseV2/src/backend/looped/looped.hpp b/BigBaseV2/src/backend/looped/looped.hpp index c2dca1fa..c68e9e63 100644 --- a/BigBaseV2/src/backend/looped/looped.hpp +++ b/BigBaseV2/src/backend/looped/looped.hpp @@ -13,7 +13,7 @@ namespace big static void tunables_no_idle_kick(); static void player_never_wanted(); - static void player_specate(); + static void player_spectate(); static void protections_replay_interface(); diff --git a/BigBaseV2/src/backend/looped/player/spectate.cpp b/BigBaseV2/src/backend/looped/player/spectate.cpp index e65d4995..86f78a12 100644 --- a/BigBaseV2/src/backend/looped/player/spectate.cpp +++ b/BigBaseV2/src/backend/looped/player/spectate.cpp @@ -1,5 +1,4 @@ #include "backend/looped/looped.hpp" -#include "pointers.hpp" #include "natives.hpp" #include "services/player_service.hpp" @@ -7,7 +6,7 @@ namespace big { static bool bReset = true; - void looped::player_specate() + void looped::player_spectate() { if (!g_player_service->get_selected()->is_valid() || !g->player.spectating) { @@ -19,16 +18,20 @@ namespace big NETWORK::NETWORK_SET_IN_SPECTATOR_MODE(false, -1); HUD::SET_MINIMAP_IN_SPECTATOR_MODE(false, -1); + + ENTITY::FREEZE_ENTITY_POSITION(PLAYER::PLAYER_PED_ID(), true); } return; } - Ped target = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(g_player_service->get_selected()->id()); + const Ped target = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(g_player_service->get_selected()->id()); NETWORK::NETWORK_SET_IN_SPECTATOR_MODE(true, target); HUD::SET_MINIMAP_IN_SPECTATOR_MODE(true, target); + ENTITY::FREEZE_ENTITY_POSITION(PLAYER::PLAYER_PED_ID(), false); + bReset = false; } } \ No newline at end of file diff --git a/BigBaseV2/src/hooking.hpp b/BigBaseV2/src/hooking.hpp index 3cd4a810..fde36a59 100644 --- a/BigBaseV2/src/hooking.hpp +++ b/BigBaseV2/src/hooking.hpp @@ -42,7 +42,7 @@ namespace big static void network_player_mgr_shutdown(CNetworkPlayerMgr* _this); - static bool net_array_handler(__int64 netArrayHandlerBaseMgr, unsigned __int8* a2, rage::datBitBuffer* datbitbuffer, unsigned int bytes_to_read, __int16 a5); + static bool net_array_handler(__int64 netArrayHandlerBaseMgr, CNetGamePlayer* a2, rage::datBitBuffer* datbitbuffer, unsigned int bytes_to_read, __int16 a5); static void player_join(CNetworkObjectMgr* _this, CNetGamePlayer* net_player); static void player_leave(CNetworkObjectMgr* _this, CNetGamePlayer* net_player); diff --git a/BigBaseV2/src/hooks/net_array_handler.cpp b/BigBaseV2/src/hooks/net_array_handler.cpp index 7a1ba80c..5159e346 100644 --- a/BigBaseV2/src/hooks/net_array_handler.cpp +++ b/BigBaseV2/src/hooks/net_array_handler.cpp @@ -5,29 +5,13 @@ namespace big // in this hook we rebuild how the game reads data from the datBitBuffer // we specifically recreate what the game uses to "detect" the NET_ARRAY_ERROR // then if we find such a crash we just return false; - bool hooks::net_array_handler(long long netArrayHandlerBaseMgr, unsigned char* a2, rage::datBitBuffer* datbitbuffer, unsigned int bytes_to_read, short a5) + bool hooks::net_array_handler(long long netArrayHandlerBaseMgr, CNetGamePlayer* a2, rage::datBitBuffer* datbitbuffer, unsigned int bytes_to_read, short a5) { - if (g_running) + if (datbitbuffer->m_bitsRead + bytes_to_read > datbitbuffer->m_curBit) { - DWORD test = 0; + LOG(WARNING) << "Received NET_ARRAY_ERROR crash from " << a2->get_name(); - const auto bytes_start = datbitbuffer->m_bitsRead; - for (unsigned int i = datbitbuffer->m_bitsRead - bytes_start; - i < bytes_to_read; - i = datbitbuffer->m_bitsRead - bytes_start) - { - const auto bytes_read_before = datbitbuffer->m_bitsRead; - g_pointers->m_read_bitbuf_dword(datbitbuffer, &test, 1u); - - if (bytes_read_before == datbitbuffer->m_bitsRead) - { - LOG(INFO) << "NET_ARRAY_ERROR caught, someones probably trying to crash us."; - - return false; - } - } - - datbitbuffer->Seek(bytes_start); + return false; } return g_hooking->m_net_array_handler_hook.get_original()(netArrayHandlerBaseMgr, a2, datbitbuffer, bytes_to_read, a5); diff --git a/BigBaseV2/src/hooks/received_event.cpp b/BigBaseV2/src/hooks/received_event.cpp index 8fa5ef47..3fde8bff 100644 --- a/BigBaseV2/src/hooks/received_event.cpp +++ b/BigBaseV2/src/hooks/received_event.cpp @@ -1,7 +1,6 @@ #include "gta/enums.hpp" #include "gta/net_game_event.hpp" #include "hooking.hpp" -#include "natives.hpp" namespace big { diff --git a/BigBaseV2/src/pointers.cpp b/BigBaseV2/src/pointers.cpp index 4fe2f465..b9de1add 100644 --- a/BigBaseV2/src/pointers.cpp +++ b/BigBaseV2/src/pointers.cpp @@ -127,7 +127,7 @@ namespace big // Received Event Signatures START // Received Event Hook - main_batch.add("REH", "66 41 83 F9 ? 0F 83 ? ? ? ?", [this](memory::handle ptr) + main_batch.add("REH", "66 41 83 F9 ? 0F 83", [this](memory::handle ptr) { m_received_event = ptr.as(); }); diff --git a/BigBaseV2/src/views/view_settings.cpp b/BigBaseV2/src/views/view_settings.cpp index 0faa1519..78ed8e9d 100644 --- a/BigBaseV2/src/views/view_settings.cpp +++ b/BigBaseV2/src/views/view_settings.cpp @@ -21,6 +21,7 @@ namespace big if (ImGui::TreeNode("Protections")) { + ImGui::BeginGroup(); ImGui::Checkbox("Bounty", &g->protections.script_events.bounty); ImGui::Checkbox("CEO Ban", &g->protections.script_events.ceo_ban); ImGui::Checkbox("CEO Kick", &g->protections.script_events.ceo_kick); @@ -28,18 +29,29 @@ namespace big ImGui::Checkbox("Wanted Level", &g->protections.script_events.clear_wanted_level); ImGui::Checkbox("Fake Deposit", &g->protections.script_events.fake_deposit); ImGui::Checkbox("Force Mission", &g->protections.script_events.force_mission); + ImGui::EndGroup(); + + ImGui::SameLine(); + + ImGui::BeginGroup(); ImGui::Checkbox("Force Teleport", &g->protections.script_events.force_teleport); ImGui::Checkbox("GTA Banner", &g->protections.script_events.gta_banner); ImGui::Checkbox("Network Bail", &g->protections.script_events.network_bail); ImGui::Checkbox("Destroy Personal Vehicle", &g->protections.script_events.personal_vehicle_destroyed); ImGui::Checkbox("Remote Off Radar", &g->protections.script_events.remote_off_radar); ImGui::Checkbox("Rotate Cam", &g->protections.script_events.rotate_cam); + ImGui::EndGroup(); + + ImGui::SameLine(); + + ImGui::BeginGroup(); ImGui::Checkbox("Send to Cutscene", &g->protections.script_events.send_to_cutscene); ImGui::Checkbox("Send to Island", &g->protections.script_events.send_to_island); ImGui::Checkbox("Sound Spam", &g->protections.script_events.sound_spam); ImGui::Checkbox("Spectate", &g->protections.script_events.spectate); ImGui::Checkbox("Transaction Error", &g->protections.script_events.transaction_error); ImGui::Checkbox("Vehicle Kick", &g->protections.script_events.vehicle_kick); + ImGui::EndGroup(); ImGui::TreePop(); }