From 19fe45bf9db78cf40603f2373e0e8f4410899efc Mon Sep 17 00:00:00 2001 From: Mr-X-GTA <110748953+Mr-X-GTA@users.noreply.github.com> Date: Sat, 27 Jul 2024 21:43:45 +0200 Subject: [PATCH] fix: fix chat (#3454) --- src/function_types.hpp | 4 ++ src/gta_pointers.hpp | 6 +++ src/hooks/misc/send_chat_message.cpp | 4 +- src/hooks/protections/receive_net_message.cpp | 3 ++ src/pointers.cpp | 27 +++++++++++++ src/util/chat.hpp | 39 +++++++++++-------- 6 files changed, 65 insertions(+), 18 deletions(-) diff --git a/src/function_types.hpp b/src/function_types.hpp index 9882bcfa..a92fd40c 100644 --- a/src/function_types.hpp +++ b/src/function_types.hpp @@ -221,4 +221,8 @@ namespace big::functions using get_peer_by_security_id = rage::SecurityPeer*(*)(int id); using set_head_blend_data = void(*)(CPed* ped, CHeadBlendData* data); + + using create_chat_guid = void (*)(GUID* guid); + + using begin_scaleform = bool (*)(uint32_t* scaleform, const char* method); } diff --git a/src/gta_pointers.hpp b/src/gta_pointers.hpp index cc171452..a8664a09 100644 --- a/src/gta_pointers.hpp +++ b/src/gta_pointers.hpp @@ -401,6 +401,12 @@ namespace big PVOID m_scope_sway_function; PVOID m_report_myself_sender; + + functions::create_chat_guid m_create_chat_guid; + + uint32_t* m_game_lifetime; + + functions::begin_scaleform m_begin_scaleform; }; #pragma pack(pop) static_assert(sizeof(gta_pointers) % 8 == 0, "Pointers are not properly aligned"); diff --git a/src/hooks/misc/send_chat_message.cpp b/src/hooks/misc/send_chat_message.cpp index 8ed8b43f..3c5ae54e 100644 --- a/src/hooks/misc/send_chat_message.cpp +++ b/src/hooks/misc/send_chat_message.cpp @@ -11,11 +11,11 @@ namespace big if (g.session.chat_commands && message[0] == g.session.chat_command_prefix) command::process(std::string(message + 1), std::make_shared(g_player_service->get_self())); - // chat::send_message(message, nullptr, false, is_team); + chat::send_message(message, nullptr, false, is_team); if (g.session.log_chat_messages) chat::log_chat(message, g_player_service->get_self(), SpamReason::NOT_A_SPAMMER, is_team); - return g_hooking->get_original()(team_mgr, local_gamer_info, message, is_team); + return true; } } \ No newline at end of file diff --git a/src/hooks/protections/receive_net_message.cpp b/src/hooks/protections/receive_net_message.cpp index 62c6770f..895e76e5 100644 --- a/src/hooks/protections/receive_net_message.cpp +++ b/src/hooks/protections/receive_net_message.cpp @@ -684,9 +684,12 @@ namespace big case rage::eNetMessage::MsgTextMessage2: { char message[256]; + char guid[40]; rage::rlGamerHandle handle{}; bool is_team; buffer.ReadString(message, sizeof(message)); + if (msgType == rage::eNetMessage::MsgTextMessage) + buffer.ReadString(guid, sizeof(guid)); gamer_handle_deserialize(handle, buffer); is_team = buffer.Read(1); diff --git a/src/pointers.cpp b/src/pointers.cpp index 78e4321e..eaeb7ec5 100644 --- a/src/pointers.cpp +++ b/src/pointers.cpp @@ -1902,6 +1902,33 @@ namespace big { g_pointers->m_gta.m_report_myself_sender = ptr.add(1).rip().as(); } + }, + // Create Chat GUID + { + "CCG", + "48 89 5C 24 08 48 89 6C 24 18 48 89 74 24 20 57 41 56 41 57 48 83 EC 20 33", + [](memory::handle ptr) + { + g_pointers->m_gta.m_create_chat_guid = ptr.as(); + } + }, + // Game Lifetime + { + "GL", + "8B 05 ? ? ? ? 89 ? 48 8D 4D C8", + [](memory::handle ptr) + { + g_pointers->m_gta.m_game_lifetime = ptr.add(2).rip().as(); + } + }, + // Begin Scaleform Movie Method + { + "BS", + "48 83 EC 38 4C 8B C2 8B 51 04", + [](memory::handle ptr) + { + g_pointers->m_gta.m_begin_scaleform = ptr.as(); + } } >(); // don't leave a trailing comma at the end diff --git a/src/util/chat.hpp b/src/util/chat.hpp index 83662de8..d96bf0db 100644 --- a/src/util/chat.hpp +++ b/src/util/chat.hpp @@ -186,12 +186,11 @@ namespace big::chat inline void render_chat(const char* msg, const char* player_name, bool is_team) { - int scaleform = GRAPHICS::REQUEST_SCALEFORM_MOVIE("MULTIPLAYER_CHAT"); + const auto chat_data = *g_pointers->m_gta.m_chat_data; - while (!GRAPHICS::HAS_SCALEFORM_MOVIE_LOADED(scaleform)) - script::get_current()->yield(); + if (!g_pointers->m_gta.m_begin_scaleform(&chat_data->m_scaleform, "ADD_MESSAGE")) + return; - GRAPHICS::BEGIN_SCALEFORM_MOVIE_METHOD(scaleform, "ADD_MESSAGE"); GRAPHICS::SCALEFORM_MOVIE_METHOD_ADD_PARAM_PLAYER_NAME_STRING(player_name); // player name GRAPHICS::SCALEFORM_MOVIE_METHOD_ADD_PARAM_LITERAL_STRING(msg); // content GRAPHICS::SCALEFORM_MOVIE_METHOD_ADD_PARAM_TEXTURE_NAME_STRING(HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(is_team ? "MP_CHAT_TEAM" : "MP_CHAT_ALL")); // scope @@ -199,19 +198,20 @@ namespace big::chat GRAPHICS::SCALEFORM_MOVIE_METHOD_ADD_PARAM_INT((int)HudColor::HUD_COLOUR_PURE_WHITE); // eHudColour GRAPHICS::END_SCALEFORM_MOVIE_METHOD(); - GRAPHICS::BEGIN_SCALEFORM_MOVIE_METHOD(scaleform, "SET_FOCUS"); - GRAPHICS::SCALEFORM_MOVIE_METHOD_ADD_PARAM_INT(1); // VISIBLE_STATE_DEFAULT - GRAPHICS::SCALEFORM_MOVIE_METHOD_ADD_PARAM_INT(0); // scopeType (unused) - GRAPHICS::SCALEFORM_MOVIE_METHOD_ADD_PARAM_INT(0); // scope (unused) - GRAPHICS::SCALEFORM_MOVIE_METHOD_ADD_PARAM_PLAYER_NAME_STRING(player_name); // player - GRAPHICS::SCALEFORM_MOVIE_METHOD_ADD_PARAM_INT((int)HudColor::HUD_COLOUR_PURE_WHITE); // eHudColour - GRAPHICS::END_SCALEFORM_MOVIE_METHOD(); + if (!chat_data->m_chat_open && !chat_data->m_timer_two) + { + if (g_pointers->m_gta.m_begin_scaleform(&chat_data->m_scaleform, "SET_FOCUS")) + { + GRAPHICS::SCALEFORM_MOVIE_METHOD_ADD_PARAM_INT(1); // VISIBLE_STATE_DEFAULT + GRAPHICS::SCALEFORM_MOVIE_METHOD_ADD_PARAM_INT(0); // scopeType (unused) + GRAPHICS::SCALEFORM_MOVIE_METHOD_ADD_PARAM_INT(0); // scope (unused) + GRAPHICS::SCALEFORM_MOVIE_METHOD_ADD_PARAM_PLAYER_NAME_STRING(player_name); // player + GRAPHICS::SCALEFORM_MOVIE_METHOD_ADD_PARAM_INT((int)HudColor::HUD_COLOUR_PURE_WHITE); // eHudColour + GRAPHICS::END_SCALEFORM_MOVIE_METHOD(); + } + } - GRAPHICS::DRAW_SCALEFORM_MOVIE_FULLSCREEN(scaleform, 255, 255, 255, 255, 0); - - // fix broken scaleforms, when chat alrdy opened - if (const auto chat_data = *g_pointers->m_gta.m_chat_data; chat_data && (chat_data->m_chat_open || chat_data->m_timer_two)) - HUD::CLOSE_MP_TEXT_CHAT(); + chat_data->m_timer_one = *g_pointers->m_gta.m_game_lifetime; } inline void draw_chat(const std::string& message, const std::string& sender, bool is_team) @@ -265,9 +265,16 @@ namespace big::chat if (!*g_pointers->m_gta.m_is_session_started) return; + GUID guid; + g_pointers->m_gta.m_create_chat_guid(&guid); + + char guid_str[40]; + std::sprintf(guid_str, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]); + packet msg{}; msg.write_message(rage::eNetMessage::MsgTextMessage); msg.m_buffer.WriteString(message.c_str(), 256); + msg.m_buffer.WriteString(guid_str, 40); gamer_handle_serialize(g_player_service->get_self()->get_net_data()->m_gamer_handle, msg.m_buffer); msg.write(is_team, 1);