From 57f6eab74ac89b26ed8a89aa973af2cf2a0689b6 Mon Sep 17 00:00:00 2001 From: maybegreat48 <96936658+maybegreat48@users.noreply.github.com> Date: Sun, 23 Jul 2023 16:47:25 +0000 Subject: [PATCH] Force relay connections (#1813) * feat(protections): add force relay servers * feat(network): add support for non-direct connections * feat(info): add helpful tooltip to prevent unnecessary bug reports --- scripts/gtav-classes.cmake | 2 +- .../looped/system/force_relay_connections.cpp | 23 ++++ src/core/settings.hpp | 11 +- src/function_types.hpp | 3 +- src/gta_pointers.hpp | 4 +- src/packet.cpp | 5 +- src/pointers.cpp | 23 +++- src/services/players/player.cpp | 36 ++++-- src/services/players/player.hpp | 4 +- src/util/spam.hpp | 17 +-- src/util/toxic.hpp | 17 ++- src/views/players/player/player_info.cpp | 107 ++++++++++++++++-- .../settings/view_protection_settings.cpp | 1 + 13 files changed, 207 insertions(+), 46 deletions(-) create mode 100644 src/backend/looped/system/force_relay_connections.cpp diff --git a/scripts/gtav-classes.cmake b/scripts/gtav-classes.cmake index f1df2198..fca74cb9 100644 --- a/scripts/gtav-classes.cmake +++ b/scripts/gtav-classes.cmake @@ -3,7 +3,7 @@ include(FetchContent) FetchContent_Declare( gtav_classes GIT_REPOSITORY https://github.com/Yimura/GTAV-Classes.git - GIT_TAG fe0893ffb589da617442015b97a62c117ac5bed4 + GIT_TAG 468161a36d95a355d9783eef5b245f3f1542e2bb GIT_PROGRESS TRUE CONFIGURE_COMMAND "" BUILD_COMMAND "" diff --git a/src/backend/looped/system/force_relay_connections.cpp b/src/backend/looped/system/force_relay_connections.cpp new file mode 100644 index 00000000..c3987d81 --- /dev/null +++ b/src/backend/looped/system/force_relay_connections.cpp @@ -0,0 +1,23 @@ +#include "backend/looped_command.hpp" +#include "pointers.hpp" + +namespace big +{ + class force_relay_connections : looped_command + { + using looped_command::looped_command; + + virtual void on_tick() override + { + *g_pointers->m_gta.m_force_relay_connections = true; + } + + virtual void on_disable() override + { + *g_pointers->m_gta.m_force_relay_connections = false; + } + }; + + force_relay_connections g_force_relay_connections("forcerelays", "Force Relay Connections", "Hides your IP address by rerouting your connection through dedicated servers and other players", + g.protections.force_relay_connections); +} diff --git a/src/core/settings.hpp b/src/core/settings.hpp index c745550b..d348158c 100644 --- a/src/core/settings.hpp +++ b/src/core/settings.hpp @@ -274,12 +274,13 @@ namespace big NLOHMANN_DEFINE_TYPE_INTRUSIVE(script_events, bounty, ceo_money, clear_wanted_level, fake_deposit, force_mission, force_teleport, gta_banner, mc_teleport, personal_vehicle_destroyed, remote_off_radar, rotate_cam, send_to_cutscene, send_to_location, sound_spam, spectate, give_collectible, vehicle_kick, teleport_to_warehouse, start_activity, send_sms) } script_events{}; - bool rid_join = false; - bool receive_pickup = false; - bool admin_check = true; - bool kick_rejoin = true; + bool rid_join = false; + bool receive_pickup = false; + bool admin_check = true; + bool kick_rejoin = true; + bool force_relay_connections = true; - NLOHMANN_DEFINE_TYPE_INTRUSIVE(protections, script_events, rid_join, receive_pickup, admin_check, kick_rejoin) + NLOHMANN_DEFINE_TYPE_INTRUSIVE(protections, script_events, rid_join, receive_pickup, admin_check, kick_rejoin, force_relay_connections) } protections{}; struct self diff --git a/src/function_types.hpp b/src/function_types.hpp index 4103d04b..112b78fd 100644 --- a/src/function_types.hpp +++ b/src/function_types.hpp @@ -16,6 +16,7 @@ namespace rage class netConnection; class netMessageQueue; class netQueuedMessage; + class netConnectionPeer; class snMsgRemoveGamersFromSessionCmd; class snSession; class snPlayer; @@ -120,7 +121,7 @@ namespace big::functions using request_ragdoll = void (*)(uint16_t object_id); using request_control = void (*)(rage::netObject* net_object); - using get_peer_address = rage::netPeerAddress* (*)(rage::netConnectionManager* manager, int peer_id); + using get_connection_peer = rage::netConnectionPeer* (*)(rage::netConnectionManager* manager, int peer_id); using send_remove_gamer_cmd = void (*)(rage::netConnectionManager* net_connection_mgr, rage::netPeerAddress* adde, int connection_id, rage::snMsgRemoveGamersFromSessionCmd* cmd, int flags); using handle_remove_gamer_cmd = void* (*)(rage::snSession* session, rage::snPlayer* origin, rage::snMsgRemoveGamersFromSessionCmd* cmd); diff --git a/src/gta_pointers.hpp b/src/gta_pointers.hpp index 1e766326..9c02823c 100644 --- a/src/gta_pointers.hpp +++ b/src/gta_pointers.hpp @@ -194,7 +194,7 @@ namespace big functions::request_control m_request_control; functions::clear_ped_tasks_network m_clear_ped_tasks_network; - functions::get_peer_address m_get_peer_address; + functions::get_connection_peer m_get_connection_peer; functions::send_remove_gamer_cmd m_send_remove_gamer_cmd; functions::handle_remove_gamer_cmd m_handle_remove_gamer_cmd; @@ -298,6 +298,8 @@ namespace big PVOID m_render_ped; PVOID m_render_entity; PVOID m_render_big_ped; + + bool* m_force_relay_connections; }; #pragma pack(pop) static_assert(sizeof(gta_pointers) % 8 == 0, "Pointers are not properly aligned"); diff --git a/src/packet.cpp b/src/packet.cpp index a7905ea1..6a85a8d6 100644 --- a/src/packet.cpp +++ b/src/packet.cpp @@ -5,6 +5,7 @@ #include "services/players/player_service.hpp" #include +#include namespace big { @@ -27,7 +28,7 @@ namespace big void packet::send(int peer_id, int connection_id) { auto mgr = gta_util::get_network()->m_game_session_ptr->m_net_connection_mgr; - auto peer = g_pointers->m_gta.m_get_peer_address(mgr, peer_id); - g_pointers->m_gta.m_send_packet(mgr, peer, connection_id, m_data, (m_buffer.m_curBit + 7) >> 3, 0x1000000); + auto peer = g_pointers->m_gta.m_get_connection_peer(mgr, peer_id); + g_pointers->m_gta.m_send_packet(mgr, &peer->m_peer_address, connection_id, m_data, (m_buffer.m_curBit + 7) >> 3, 0x1000000); } } \ No newline at end of file diff --git a/src/pointers.cpp b/src/pointers.cpp index c9fd8a56..b24c16db 100644 --- a/src/pointers.cpp +++ b/src/pointers.cpp @@ -754,16 +754,24 @@ namespace big g_pointers->m_gta.m_request_control = ptr.add(1).rip().as(); } }, - // Get Connection Peer & Send Remove Gamer Command + // Send Remove Gamer Command { - "GCP&SRGC", + "SRGC", "8D 42 FF 83 F8 FD 77 3D", [](memory::handle ptr) { - g_pointers->m_gta.m_get_peer_address = ptr.add(23).rip().as(); g_pointers->m_gta.m_send_remove_gamer_cmd = ptr.add(65).rip().as(); } }, + // Get Connection Peer + { + "GCP", + "48 89 5C 24 08 48 89 74 24 18 89 54 24 10 57 48 83 EC 40 48", + [](memory::handle ptr) + { + g_pointers->m_gta.m_get_connection_peer = ptr.as(); + } + }, // Handle Remove Gamer Command { "HRGC", @@ -1282,6 +1290,15 @@ namespace big g_pointers->m_gta.m_render_big_ped = ptr.as(); } }, + // Force Relay Connections + { + "FRC", + "8A 05 ? ? ? ? 88 83 BC 00 00 00", + [](memory::handle ptr) + { + g_pointers->m_gta.m_force_relay_connections = ptr.add(2).rip().as(); + } + }, // Max Wanted Level { "MWL", diff --git a/src/services/players/player.cpp b/src/services/players/player.cpp index 3147d4b7..5103cd50 100644 --- a/src/services/players/player.cpp +++ b/src/services/players/player.cpp @@ -83,17 +83,30 @@ namespace big return nullptr; } - netAddress player::get_ip_address() + rage::netConnectionPeer* player::get_connection_peer() + { + if (auto session_player = get_session_player()) + if (auto peer = g_pointers->m_gta.m_get_connection_peer(gta_util::get_network()->m_game_session_ptr->m_net_connection_mgr, + (int)get_session_player()->m_player_data.m_peer_id_2)) + return peer; + + return nullptr; + } + + std::optional player::get_ip_address() { if (this == g_player_service->get_self().get() && get_net_data()) return get_net_data()->m_external_ip; - if (auto session_player = get_session_player()) - if (auto peer = g_pointers->m_gta.m_get_peer_address(gta_util::get_network()->m_game_session_ptr->m_net_connection_mgr, - (int)get_session_player()->m_player_data.m_peer_id_2)) - return netAddress{((rage::netPeerAddress*)peer)->m_external_ip}; + if (auto peer = get_connection_peer()) + { + if (peer->m_peer_address.m_connection_type != 1) + return std::nullopt; - return {0}; + return peer->m_peer_address.m_external_ip; + } + + return std::nullopt; } uint16_t player::get_port() @@ -101,10 +114,13 @@ namespace big if (this == g_player_service->get_self().get() && get_net_data()) return get_net_data()->m_external_port; - if (auto session_player = get_session_player()) - if (auto peer = g_pointers->m_gta.m_get_peer_address(gta_util::get_network()->m_game_session_ptr->m_net_connection_mgr, - (int)get_session_player()->m_player_data.m_peer_id_2)) - return ((rage::netPeerAddress*)peer)->m_external_port; + if (auto peer = get_connection_peer()) + { + if (peer->m_peer_address.m_connection_type != 1) + return 0; + + return peer->m_peer_address.m_external_port; + } return 0; } diff --git a/src/services/players/player.hpp b/src/services/players/player.hpp index ffef0d10..b82d5730 100644 --- a/src/services/players/player.hpp +++ b/src/services/players/player.hpp @@ -12,6 +12,7 @@ namespace rage class snPlayer; class snPeer; class rlGamerInfo; + class netConnectionPeer; } namespace big @@ -44,7 +45,8 @@ namespace big [[nodiscard]] CPlayerInfo* get_player_info() const; [[nodiscard]] class rage::snPlayer* get_session_player(); [[nodiscard]] class rage::snPeer* get_session_peer(); - [[nodiscard]] netAddress get_ip_address(); + [[nodiscard]] class rage::netConnectionPeer* get_connection_peer(); + [[nodiscard]] std::optional get_ip_address(); [[nodiscard]] uint16_t get_port(); [[nodiscard]] uint8_t id() const; diff --git a/src/util/spam.hpp b/src/util/spam.hpp index d9cb2633..6671bd22 100644 --- a/src/util/spam.hpp +++ b/src/util/spam.hpp @@ -72,16 +72,17 @@ namespace big::spam inline void log_chat(char* msg, player_ptr player, bool is_spam) { - std::ofstream spam_log(g_file_manager.get_project_file(is_spam ? "./spam.log" : "./chat.log").get_path(), std::ios::app); + std::ofstream log(g_file_manager.get_project_file(is_spam ? "./spam.log" : "./chat.log").get_path(), std::ios::app); - auto& plData = *player->get_net_data(); - auto ip = player->get_ip_address(); + auto& data = *player->get_net_data(); + auto ip = player->get_ip_address(); - spam_log << player->get_name() << " (" << plData.m_gamer_handle.m_rockstar_id << ") <" << (int)ip.m_field1 << "." - << (int)ip.m_field2 << "." << (int)ip.m_field3 << "." << (int)ip.m_field4 << ">: " << msg << std::endl; + if (ip) + log << player->get_name() << " (" << data.m_gamer_handle.m_rockstar_id << ") <" << (int)ip.value().m_field1 << "." + << (int)ip.value().m_field2 << "." << (int)ip.value().m_field3 << "." << (int)ip.value().m_field4 << ">: " << msg << std::endl; + else + log << player->get_name() << " (" << data.m_gamer_handle.m_rockstar_id << ") : " << msg << std::endl; - spam_log.close(); + log.close(); } - - } diff --git a/src/util/toxic.hpp b/src/util/toxic.hpp index 2ebe36c9..d247645d 100644 --- a/src/util/toxic.hpp +++ b/src/util/toxic.hpp @@ -10,6 +10,7 @@ #include "util/system.hpp" #include +#include #include #include