Fix Script Event Handler hook from clogging event queue (#163)

* fixes #154

* fix(ReceivedEvent): BitBuffer was incorrectly initialised
This commit is contained in:
Yimura 2022-05-08 22:00:55 +02:00 committed by GitHub
parent 2660c4f96d
commit 1443bc0cab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 41 deletions

View File

@ -26,16 +26,6 @@ namespace big::functions
// Received Event Signatures START
using read_bitbuf_array = bool(rage::datBitBuffer* buffer, PVOID read, int bits, int);
using read_bitbuf_dword = bool(rage::datBitBuffer* buffer, PVOID read, int bits);
using received_event = bool(
rage::netEventMgr* event_manager,
CNetGamePlayer* source_player,
CNetGamePlayer* target_player,
uint16_t event_id,
int event_index,
int event_handled_bitset,
int64_t bit_buffer_size,
int64_t bit_buffer
);
using send_event_ack = void(rage::netEventMgr* event_manager, CNetGamePlayer* source_player, CNetGamePlayer* target_player, int event_index, int event_handled_bitset);
// Received Event Signatures END
}

View File

@ -50,9 +50,6 @@ namespace big
// Received Event
m_received_event_hook("RE", g_pointers->m_received_event, &hooks::received_event),
// Scripted Game Event Hook
m_scripted_game_event_hook("SGEH", g_pointers->m_scripted_game_event, &hooks::scripted_game_event),
// Send NET Info to Lobby
m_send_net_info_to_lobby("SNITL", g_pointers->m_send_net_info_to_lobby, &hooks::send_net_info_to_lobby),
@ -101,8 +98,6 @@ namespace big
m_received_event_hook.enable();
m_scripted_game_event_hook.enable();
m_send_net_info_to_lobby.enable();
m_enabled = true;
@ -114,8 +109,6 @@ namespace big
m_send_net_info_to_lobby.disable();
m_scripted_game_event_hook.disable();
m_received_event_hook.disable();
m_error_screen_hook.disable();

View File

@ -57,8 +57,8 @@ namespace big
uint16_t event_id,
int event_index,
int event_handled_bitset,
int64_t bit_buffer_size,
int64_t bit_buffer
int unk,
rage::datBitBuffer* bit_buffer
);
static bool scripted_game_event(CScriptedGameEvent* scripted_game_event, CNetGamePlayer* player);
@ -110,8 +110,7 @@ namespace big
detour_hook m_is_dlc_present_hook;
detour_hook m_received_event_hook;
detour_hook m_scripted_game_event_hook;
detour_hook m_send_net_info_to_lobby;
};

View File

@ -11,15 +11,18 @@ namespace big
uint16_t event_id,
int event_index,
int event_handled_bitset,
int64_t bit_buffer_size,
int64_t bit_buffer
int unk,
rage::datBitBuffer* buffer
)
{
auto buffer = std::make_unique<rage::datBitBuffer>((void*)bit_buffer, (uint32_t)bit_buffer_size);
if (event_id > 91u)
{
g_pointers->m_send_event_ack(event_manager, source_player, target_player, event_index, event_handled_bitset);
if (event_id > 90u) return false;
return false;
}
const char* event_name = *(char**)((DWORD64)event_manager + 8i64 * event_id + 243376);
const auto event_name = *(char**)((DWORD64)event_manager + 8i64 * event_id + 243376);
if (event_name == nullptr || source_player == nullptr || source_player->m_player_id < 0 || source_player->m_player_id >= 32)
{
g_pointers->m_send_event_ack(event_manager, source_player, target_player, event_index, event_handled_bitset);
@ -28,6 +31,22 @@ namespace big
switch ((RockstarEvent)event_id)
{
case RockstarEvent::SCRIPTED_GAME_EVENT:
{
const auto scripted_game_event = std::make_unique<CScriptedGameEvent>();
buffer->ReadDword(&scripted_game_event->m_args_size, 32);
if (scripted_game_event->m_args_size - 1 <= 0x1AF)
buffer->ReadArray(&scripted_game_event->m_args, 8 * scripted_game_event->m_args_size);
if (hooks::scripted_game_event(scripted_game_event.get(), source_player))
{
g_pointers->m_send_event_ack(event_manager, source_player, target_player, event_index, event_handled_bitset);
return false;
}
break;
}
case RockstarEvent::NETWORK_CLEAR_PED_TASKS_EVENT:
{
if (source_player->m_player_id < 32)
@ -100,6 +119,6 @@ namespace big
}
}
return g_hooking->m_received_event_hook.get_original<decltype(&received_event)>()(event_manager, source_player, target_player, event_id, event_index, event_handled_bitset, bit_buffer_size, bit_buffer);
return g_hooking->m_received_event_hook.get_original<decltype(&received_event)>()(event_manager, source_player, target_player, event_id, event_index, event_handled_bitset, unk, buffer);
}
}

View File

@ -16,10 +16,10 @@ namespace big
bool hooks::scripted_game_event(CScriptedGameEvent* scripted_game_event, CNetGamePlayer* player)
{
auto args = scripted_game_event->m_args;
const auto args = scripted_game_event->m_args;
const eRemoteEvent hash = static_cast<eRemoteEvent>(args[0]);
const char* player_name = player->get_name();
const auto hash = static_cast<eRemoteEvent>(args[0]);
const auto player_name = player->get_name();
const auto& notify = g->notifications.script_event_handler;
@ -187,12 +187,12 @@ namespace big
LOG(INFO) << "Player: " << player->get_name();
LOG(INFO) << "Hash/Arg #0: " << (int)hash;
for (int i = 1; i < sizeof(args); i++)
for (std::size_t i = 1; i < sizeof(args); i++)
LOG(INFO) << "Arg #" << i << ": " << args[i];
LOG(INFO) << "== End of Script Event ==";
}
return g_hooking->m_scripted_game_event_hook.get_original<decltype(&hooks::scripted_game_event)>()(scripted_game_event, player);
return false;
}
}

View File

@ -165,12 +165,6 @@ namespace big
memset(spectator_check, 0x90, 0x4);
});
// Scripted Game Event Handler
main_batch.add("SGEH", "40 53 48 81 EC ? ? ? ? 44 8B 81 ? ? ? ? 4C 8B CA 41 8D 40 FF 3D ? ? ? ? 77 42", [this](memory::handle ptr)
{
m_scripted_game_event = ptr.as<decltype(m_scripted_game_event)>();
});
// GET CNetGamePlayer
main_batch.add("GCNGP", "48 83 EC ? 33 C0 38 05 ? ? ? ? 74 ? 83 F9", [this](memory::handle ptr)
{

View File

@ -72,14 +72,13 @@ namespace big
functions::get_gameplay_cam_coords* m_get_gamplay_cam_coords;
functions::increment_stat_event* m_increment_stat_event{};
PVOID m_scripted_game_event{};
functions::trigger_script_event* m_trigger_script_event{};
// Received Event Signatures START
functions::read_bitbuf_array* m_read_bitbuf_array{};
functions::read_bitbuf_dword* m_read_bitbuf_dword{};
functions::received_event* m_received_event{};
PVOID m_received_event{};
functions::send_event_ack* m_send_event_ack{};
// Received Event Signatures END