From 69d636f0653fbd19f183602fb3b044317ce478d6 Mon Sep 17 00:00:00 2001 From: Aure7138 <100095051+Aure7138@users.noreply.github.com> Date: Mon, 14 Nov 2022 23:37:38 +0800 Subject: [PATCH] feat(Network): Send Chat Message (#594) --- src/core/globals.hpp | 5 ++++- src/function_types.hpp | 3 +++ src/gta_util.hpp | 1 + src/hooks/protections/receive_net_message.cpp | 2 +- src/pointers.cpp | 12 ++++++++++++ src/pointers.hpp | 7 +++++-- src/util/notify.hpp | 11 +++++++++++ src/views/network/view_session.cpp | 15 +++++++++++++++ 8 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/core/globals.hpp b/src/core/globals.hpp index 46270de9..c1a67586 100644 --- a/src/core/globals.hpp +++ b/src/core/globals.hpp @@ -195,6 +195,7 @@ namespace big bool log_text_messages = false; bool decloak_players = false; bool force_session_host = false; + bool is_team = false; }; struct settings { @@ -602,6 +603,7 @@ namespace big this->session.disable_chat_filter = j["session"]["disable_chat_filter"]; this->session.decloak_players = j["session"]["decloak_players"]; this->session.force_session_host = j["session"]["force_session_host"]; + this->session.is_team = j["session"]["is_team"]; this->settings.dev_dlc = j["settings"]["dev_dlc"]; this->settings.hotkeys.menu_toggle = j["settings"]["hotkeys"]["menu_toggle"]; @@ -918,7 +920,8 @@ namespace big { "log_text_messages", this->session.log_text_messages }, { "disable_chat_filter", this->session.disable_chat_filter }, { "decloak_players", this->session.decloak_players }, - { "force_session_host", this->session.force_session_host } + { "force_session_host", this->session.force_session_host }, + { "is_team", this->session.is_team } } }, { diff --git a/src/function_types.hpp b/src/function_types.hpp index ea3ba2c6..94f146c4 100644 --- a/src/function_types.hpp +++ b/src/function_types.hpp @@ -1,5 +1,6 @@ #pragma once #include "datanodes/player/CPlayerGameStateDataNode.hpp" +#include "rage/rlGamerInfo.hpp" namespace big::functions { @@ -67,4 +68,6 @@ namespace big::functions using join_session_by_info = bool(*)(Network* network, rage::rlSessionInfo* info, int unk, int flags, rage::rlGamerHandle* handles, int handlecount); using generate_uuid = bool(*)(std::uint64_t* uuid); + + using send_chat_message = bool(*)(int64_t* send_chat_ptr, rage::rlGamerInfo* game_info, char* message, bool is_team); } diff --git a/src/gta_util.hpp b/src/gta_util.hpp index ec96c64b..7bc88c86 100644 --- a/src/gta_util.hpp +++ b/src/gta_util.hpp @@ -4,6 +4,7 @@ #include "gta/tls_context.hpp" #include "ped/CPedFactory.hpp" #include "pointers.hpp" +#include "network/CNetworkPlayerMgr.hpp" namespace big::gta_util { diff --git a/src/hooks/protections/receive_net_message.cpp b/src/hooks/protections/receive_net_message.cpp index 5f6c22d6..74d05bde 100644 --- a/src/hooks/protections/receive_net_message.cpp +++ b/src/hooks/protections/receive_net_message.cpp @@ -64,7 +64,7 @@ namespace big buffer.ReadString(message, 256); buffer.ReadQWord(&unk, 64); buffer.ReadBool(&is_team); - LOG(INFO) << "[CHAT] from " << player->get_name() << ": " << message << (is_team) ? " [TEAM]" : " [ALL]"; + LOG(INFO) << "[CHAT] from " << player->get_name() << ": " << message << (is_team ? " [TEAM]" : " [ALL]"); } break; } diff --git a/src/pointers.cpp b/src/pointers.cpp index 539c35cd..d7000dc6 100644 --- a/src/pointers.cpp +++ b/src/pointers.cpp @@ -410,6 +410,18 @@ namespace big m_invalid_mods_crash_detour = ptr.add(1).rip().as(); }); + // Send Chat Ptr + main_batch.add("SCP", "41 83 7F ? ? 4C 8B 35", [this](memory::handle ptr) + { + m_send_chat_ptr = ptr.add(8).rip().as(); + }); + + // Send Chat Message + main_batch.add("SCM", "48 83 EC 20 48 8B F9 48 8B CA 45 8A F1", [this](memory::handle ptr) + { + m_send_chat_message = ptr.sub(21).as(); + }); + // Format Metric For Sending main_batch.add("FMFS", "48 8B C4 48 89 58 ? 48 89 70 ? 48 89 78 ? 4C 89 70 ? 55 48 8D A8 ? ? ? ? 48 81 EC ? ? ? ? 48 83 3D", [this](memory::handle ptr) { diff --git a/src/pointers.hpp b/src/pointers.hpp index fc4dd550..ad09fbe1 100644 --- a/src/pointers.hpp +++ b/src/pointers.hpp @@ -138,6 +138,9 @@ namespace big PVOID m_invalid_mods_crash_detour{}; + int64_t** m_send_chat_ptr{}; + functions::send_chat_message m_send_chat_message{}; + PVOID m_init_native_tables{}; PVOID m_script_vm{}; @@ -147,8 +150,8 @@ namespace big rage::rlGamerInfo* m_player_info_gamer_info{}; // the gamer info that is applied to CPlayerInfo CCommunications** m_communications{}; - PVOID m_update_presence_attribute_int; - PVOID m_update_presence_attribute_string; + PVOID m_update_presence_attribute_int{}; + PVOID m_update_presence_attribute_string{}; }; inline pointers* g_pointers{}; diff --git a/src/util/notify.hpp b/src/util/notify.hpp index 570e2936..0287961f 100644 --- a/src/util/notify.hpp +++ b/src/util/notify.hpp @@ -53,4 +53,15 @@ namespace big::notify std::format("{} joined.", net_game_player->get_name()) ); } + + inline void draw_chat(char* msg, const char* player_name, bool is_team) + { + int scaleform = GRAPHICS::REQUEST_SCALEFORM_MOVIE("MULTIPLAYER_CHAT"); + 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 + GRAPHICS::DRAW_SCALEFORM_MOVIE_FULLSCREEN(scaleform, 255, 255, 255, 255, 0); + GRAPHICS::END_SCALEFORM_MOVIE_METHOD(); + } } \ No newline at end of file diff --git a/src/views/network/view_session.cpp b/src/views/network/view_session.cpp index 420ba74d..7b392dba 100644 --- a/src/views/network/view_session.cpp +++ b/src/views/network/view_session.cpp @@ -2,6 +2,8 @@ #include "fiber_pool.hpp" #include "util/session.hpp" #include "core/data/region_codes.hpp" +#include "gta_util.hpp" +#include "util/notify.hpp" namespace big { @@ -44,6 +46,19 @@ namespace big ImGui::Checkbox("Disable Filter", &g->session.disable_chat_filter); ImGui::Checkbox("Log Chat Messages", &g->session.log_chat_messages); ImGui::Checkbox("Log Text Messages", &g->session.log_text_messages); + static char msg[256]; + ImGui::InputText("##message", msg, sizeof(msg)); + ImGui::SameLine(); + ImGui::Checkbox("Is Team", &g->session.is_team); + ImGui::SameLine(); + components::button("Send", [] + { + if(const auto net_game_player = gta_util::get_network_player_mgr()->m_local_net_player; net_game_player) + { + if(g_pointers->m_send_chat_message(*g_pointers->m_send_chat_ptr, net_game_player->get_net_data(), msg, g->session.is_team)) + notify::draw_chat(msg, net_game_player->get_name(), g->session.is_team); + } + }); components::sub_title("Decloak"); components::script_patch_checkbox("Reveal OTR Players", &g->session.decloak_players);