From 4636ef834694c49a58d0b02ae13f6c94e184887b Mon Sep 17 00:00:00 2001 From: gir489 <100792176+gir489returns@users.noreply.github.com> Date: Wed, 27 Mar 2024 16:43:31 -0400 Subject: [PATCH] Unify rlGamerHandle code and fix chat inaccuracies. (#2883) --- cmake/gtav-classes.cmake | 2 +- src/hooks/misc/send_chat_message.cpp | 8 ------- src/hooks/protections/can_apply_data.cpp | 10 +++------ src/hooks/protections/receive_net_message.cpp | 22 +++++++------------ src/util/chat.hpp | 12 +++++----- src/util/session.hpp | 10 --------- 6 files changed, 19 insertions(+), 45 deletions(-) diff --git a/cmake/gtav-classes.cmake b/cmake/gtav-classes.cmake index de8a6723..5b2ffdfa 100644 --- a/cmake/gtav-classes.cmake +++ b/cmake/gtav-classes.cmake @@ -3,7 +3,7 @@ include(FetchContent) FetchContent_Declare( gtav_classes GIT_REPOSITORY https://github.com/Yimura/GTAV-Classes.git - GIT_TAG 09a586011a296cf8ce3ffb9c15db7ce474ea4363 + GIT_TAG a3031a89788141f292a83d18587277e04d367c4a GIT_PROGRESS TRUE CONFIGURE_COMMAND "" BUILD_COMMAND "" diff --git a/src/hooks/misc/send_chat_message.cpp b/src/hooks/misc/send_chat_message.cpp index b80ef10f..40c3a845 100644 --- a/src/hooks/misc/send_chat_message.cpp +++ b/src/hooks/misc/send_chat_message.cpp @@ -9,14 +9,6 @@ namespace big { - inline void gamer_handle_serialize(rage::rlGamerHandle& hnd, rage::datBitBuffer& buf) - { - constexpr int PC_PLATFORM = 3; - buf.Write(PC_PLATFORM, 8); - buf.WriteInt64(*(int64_t*)&hnd.m_rockstar_id, 64); - buf.Write(hnd.unk_0009, 8); - } - bool hooks::send_chat_message(void* team_mgr, rage::rlGamerInfo* local_gamer_info, char* message, bool is_team) { if (g.session.chat_commands && message[0] == g.session.chat_command_prefix) diff --git a/src/hooks/protections/can_apply_data.cpp b/src/hooks/protections/can_apply_data.cpp index 36792bb8..96ebabb3 100644 --- a/src/hooks/protections/can_apply_data.cpp +++ b/src/hooks/protections/can_apply_data.cpp @@ -716,13 +716,9 @@ namespace big case sync_node_id("CPlayerExtendedGameStateNode"): LOG_FIELD(CPlayerExtendedGameStateNode, waypoint_x); LOG_FIELD(CPlayerExtendedGameStateNode, waypoint_y); - LOG_FIELD_B(CPlayerExtendedGameStateNode, unk1); - LOG_FIELD_B(CPlayerExtendedGameStateNode, unk2); - LOG_FIELD_B(CPlayerExtendedGameStateNode, unk3); - LOG_FIELD_B(CPlayerExtendedGameStateNode, unk4); - LOG_FIELD_B(CPlayerExtendedGameStateNode, unk5); - LOG_FIELD_B(CPlayerExtendedGameStateNode, has_waypoint_data); - LOG_FIELD_B(CPlayerExtendedGameStateNode, is_waypoint_set); + LOG_FIELD(CPlayerExtendedGameStateNode, waypoint_entity); + LOG_FIELD(CPlayerExtendedGameStateNode, has_active_waypoint); + LOG_FIELD(CPlayerExtendedGameStateNode, owns_waypoint); break; case sync_node_id("CPlayerGameStateDataNode"): LOG_FIELD(CPlayerGameStateDataNode, m_player_state); diff --git a/src/hooks/protections/receive_net_message.cpp b/src/hooks/protections/receive_net_message.cpp index 28507146..37b199af 100644 --- a/src/hooks/protections/receive_net_message.cpp +++ b/src/hooks/protections/receive_net_message.cpp @@ -19,12 +19,11 @@ inline void gamer_handle_deserialize(rage::rlGamerHandle& hnd, rage::datBitBuffer& buf) { - constexpr int PC_PLATFORM = 3; - if ((hnd.m_platform = buf.Read(8)) != PC_PLATFORM) + if ((hnd.m_platform = buf.Read(sizeof(hnd.m_platform))) != rage::rlPlatforms::PC) return; - buf.ReadInt64((int64_t*)&hnd.m_rockstar_id, 64); - hnd.unk_0009 = buf.Read(8); + buf.ReadPeerId(&hnd.m_rockstar_id); + hnd.m_padding = buf.Read(sizeof(hnd.m_padding)); } inline bool is_kick_instruction(rage::datBitBuffer& buffer) @@ -107,8 +106,10 @@ namespace big case rage::eNetMessage::MsgTextMessage2: { char message[256]; - buffer.ReadString(message, 256); + rage::rlGamerHandle handle{}; bool is_team; + buffer.ReadString(message, sizeof(message)); + gamer_handle_deserialize(handle, buffer); buffer.ReadBool(&is_team); if (player->is_spammer) @@ -146,15 +147,8 @@ namespace big if (msgType == rage::eNetMessage::MsgTextMessage && g_pointers->m_gta.m_chat_data && player->get_net_data()) { - rage::rlGamerHandle temp{}; - gamer_handle_deserialize(temp, buffer); - - g_pointers->m_gta.m_handle_chat_message(*g_pointers->m_gta.m_chat_data, - nullptr, - &player->get_net_data()->m_gamer_handle, - message, - is_team); - return true; + buffer.Seek(0); + return g_hooking->get_original()(netConnectionManager, a2, frame); // Call original function since we can't seem to handle it } } break; diff --git a/src/util/chat.hpp b/src/util/chat.hpp index d4b7274e..23eb53c0 100644 --- a/src/util/chat.hpp +++ b/src/util/chat.hpp @@ -16,12 +16,14 @@ namespace { - inline void gamer_handle_serialize(rage::rlGamerHandle& hnd, rage::datBitBuffer& buf) + static void gamer_handle_serialize(rage::rlGamerHandle& hnd, rage::datBitBuffer& buf) { - constexpr int PC_PLATFORM = 3; - buf.Write(PC_PLATFORM, 8); - buf.WriteInt64(*(int64_t*)&hnd.m_rockstar_id, 64); - buf.Write(hnd.unk_0009, 8); + buf.Write(hnd.m_platform, sizeof(hnd.m_platform)); + if (hnd.m_platform == rage::rlPlatforms::PC) + { + buf.WriteQWord(hnd.m_rockstar_id, sizeof(hnd.m_rockstar_id)); + buf.Write(hnd.m_padding, sizeof(hnd.m_padding)); + } } static const char* spam_texts[] = diff --git a/src/util/session.hpp b/src/util/session.hpp index 1a03e746..79d480f5 100644 --- a/src/util/session.hpp +++ b/src/util/session.hpp @@ -24,16 +24,6 @@ namespace big::session { - static void gamer_handle_serialize(rage::rlGamerHandle& hnd, rage::datBitBuffer& buf) - { - buf.Write(*reinterpret_cast(&hnd.m_platform), 8); - if (*reinterpret_cast(&hnd.m_platform) == 3) - { - buf.WriteInt64(*(int64_t*)&hnd.m_rockstar_id, 64); - buf.Write(*reinterpret_cast(reinterpret_cast<__int64>(&hnd) + 9), 8); - } - } - inline bool join_type(eSessionType session) { SCRIPT::REQUEST_SCRIPT_WITH_NAME_HASH("pausemenu_multiplayer"_J);