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
This commit is contained in:
Yimura 2022-03-21 18:02:30 +01:00 committed by GitHub
parent 30847d05cb
commit 24a7e7d906
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 26 additions and 29 deletions

View File

@ -2,7 +2,6 @@
#include "backend.hpp" #include "backend.hpp"
#include "fiber_pool.hpp" #include "fiber_pool.hpp"
#include "looped/looped.hpp" #include "looped/looped.hpp"
#include "pointers.hpp"
#include "script.hpp" #include "script.hpp"
#include "thread_pool.hpp" #include "thread_pool.hpp"
@ -57,7 +56,7 @@ namespace big
QUEUE_JOB_BEGIN_CLAUSE() QUEUE_JOB_BEGIN_CLAUSE()
{ {
looped::player_never_wanted(); looped::player_never_wanted();
looped::player_specate(); looped::player_spectate();
}QUEUE_JOB_END_CLAUSE }QUEUE_JOB_END_CLAUSE
QUEUE_JOB_BEGIN_CLAUSE() QUEUE_JOB_BEGIN_CLAUSE()

View File

@ -13,7 +13,7 @@ namespace big
static void tunables_no_idle_kick(); static void tunables_no_idle_kick();
static void player_never_wanted(); static void player_never_wanted();
static void player_specate(); static void player_spectate();
static void protections_replay_interface(); static void protections_replay_interface();

View File

@ -1,5 +1,4 @@
#include "backend/looped/looped.hpp" #include "backend/looped/looped.hpp"
#include "pointers.hpp"
#include "natives.hpp" #include "natives.hpp"
#include "services/player_service.hpp" #include "services/player_service.hpp"
@ -7,7 +6,7 @@ namespace big
{ {
static bool bReset = true; static bool bReset = true;
void looped::player_specate() void looped::player_spectate()
{ {
if (!g_player_service->get_selected()->is_valid() || !g->player.spectating) 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); NETWORK::NETWORK_SET_IN_SPECTATOR_MODE(false, -1);
HUD::SET_MINIMAP_IN_SPECTATOR_MODE(false, -1); HUD::SET_MINIMAP_IN_SPECTATOR_MODE(false, -1);
ENTITY::FREEZE_ENTITY_POSITION(PLAYER::PLAYER_PED_ID(), true);
} }
return; 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); NETWORK::NETWORK_SET_IN_SPECTATOR_MODE(true, target);
HUD::SET_MINIMAP_IN_SPECTATOR_MODE(true, target); HUD::SET_MINIMAP_IN_SPECTATOR_MODE(true, target);
ENTITY::FREEZE_ENTITY_POSITION(PLAYER::PLAYER_PED_ID(), false);
bReset = false; bReset = false;
} }
} }

View File

@ -42,7 +42,7 @@ namespace big
static void network_player_mgr_shutdown(CNetworkPlayerMgr* _this); 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_join(CNetworkObjectMgr* _this, CNetGamePlayer* net_player);
static void player_leave(CNetworkObjectMgr* _this, CNetGamePlayer* net_player); static void player_leave(CNetworkObjectMgr* _this, CNetGamePlayer* net_player);

View File

@ -5,30 +5,14 @@ namespace big
// in this hook we rebuild how the game reads data from the datBitBuffer // 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 // we specifically recreate what the game uses to "detect" the NET_ARRAY_ERROR
// then if we find such a crash we just return false; // 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; return false;
} }
}
datbitbuffer->Seek(bytes_start);
}
return g_hooking->m_net_array_handler_hook.get_original<decltype(&hooks::net_array_handler)>()(netArrayHandlerBaseMgr, a2, datbitbuffer, bytes_to_read, a5); return g_hooking->m_net_array_handler_hook.get_original<decltype(&hooks::net_array_handler)>()(netArrayHandlerBaseMgr, a2, datbitbuffer, bytes_to_read, a5);
} }

View File

@ -1,7 +1,6 @@
#include "gta/enums.hpp" #include "gta/enums.hpp"
#include "gta/net_game_event.hpp" #include "gta/net_game_event.hpp"
#include "hooking.hpp" #include "hooking.hpp"
#include "natives.hpp"
namespace big namespace big
{ {

View File

@ -127,7 +127,7 @@ namespace big
// Received Event Signatures START // Received Event Signatures START
// Received Event Hook // 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<decltype(m_received_event)>(); m_received_event = ptr.as<decltype(m_received_event)>();
}); });

View File

@ -21,6 +21,7 @@ namespace big
if (ImGui::TreeNode("Protections")) if (ImGui::TreeNode("Protections"))
{ {
ImGui::BeginGroup();
ImGui::Checkbox("Bounty", &g->protections.script_events.bounty); ImGui::Checkbox("Bounty", &g->protections.script_events.bounty);
ImGui::Checkbox("CEO Ban", &g->protections.script_events.ceo_ban); ImGui::Checkbox("CEO Ban", &g->protections.script_events.ceo_ban);
ImGui::Checkbox("CEO Kick", &g->protections.script_events.ceo_kick); 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("Wanted Level", &g->protections.script_events.clear_wanted_level);
ImGui::Checkbox("Fake Deposit", &g->protections.script_events.fake_deposit); ImGui::Checkbox("Fake Deposit", &g->protections.script_events.fake_deposit);
ImGui::Checkbox("Force Mission", &g->protections.script_events.force_mission); 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("Force Teleport", &g->protections.script_events.force_teleport);
ImGui::Checkbox("GTA Banner", &g->protections.script_events.gta_banner); ImGui::Checkbox("GTA Banner", &g->protections.script_events.gta_banner);
ImGui::Checkbox("Network Bail", &g->protections.script_events.network_bail); ImGui::Checkbox("Network Bail", &g->protections.script_events.network_bail);
ImGui::Checkbox("Destroy Personal Vehicle", &g->protections.script_events.personal_vehicle_destroyed); 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("Remote Off Radar", &g->protections.script_events.remote_off_radar);
ImGui::Checkbox("Rotate Cam", &g->protections.script_events.rotate_cam); 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 Cutscene", &g->protections.script_events.send_to_cutscene);
ImGui::Checkbox("Send to Island", &g->protections.script_events.send_to_island); ImGui::Checkbox("Send to Island", &g->protections.script_events.send_to_island);
ImGui::Checkbox("Sound Spam", &g->protections.script_events.sound_spam); ImGui::Checkbox("Sound Spam", &g->protections.script_events.sound_spam);
ImGui::Checkbox("Spectate", &g->protections.script_events.spectate); ImGui::Checkbox("Spectate", &g->protections.script_events.spectate);
ImGui::Checkbox("Transaction Error", &g->protections.script_events.transaction_error); ImGui::Checkbox("Transaction Error", &g->protections.script_events.transaction_error);
ImGui::Checkbox("Vehicle Kick", &g->protections.script_events.vehicle_kick); ImGui::Checkbox("Vehicle Kick", &g->protections.script_events.vehicle_kick);
ImGui::EndGroup();
ImGui::TreePop(); ImGui::TreePop();
} }