Skip to content

Commit

Permalink
Desync kick protection (#3086)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-X-GTA committed May 10, 2024
1 parent dada469 commit 86c63df
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 39 deletions.
2 changes: 1 addition & 1 deletion cmake/gtav-classes.cmake
Expand Up @@ -3,7 +3,7 @@ include(FetchContent)
FetchContent_Declare(
gtav_classes
GIT_REPOSITORY https://github.com/Yimura/GTAV-Classes.git
GIT_TAG b13929ce04c86abb0b5aac3149bafca84de26677
GIT_TAG df0def702dac8f7ba9bf7107734ac30b4db54e96
GIT_PROGRESS TRUE
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
Expand Down
3 changes: 2 additions & 1 deletion src/core/settings.hpp
Expand Up @@ -286,8 +286,9 @@ namespace big
bool kick_rejoin = true;
bool force_relay_connections = false;
bool stop_traffic = true;
bool desync_kick = false;

NLOHMANN_DEFINE_TYPE_INTRUSIVE(protections, script_events, rid_join, receive_pickup, admin_check, kick_rejoin, force_relay_connections, stop_traffic)
NLOHMANN_DEFINE_TYPE_INTRUSIVE(protections, script_events, rid_join, receive_pickup, admin_check, kick_rejoin, force_relay_connections, stop_traffic, desync_kick)
} protections{};

struct self
Expand Down
2 changes: 1 addition & 1 deletion src/gta_pointers.hpp
Expand Up @@ -209,9 +209,9 @@ namespace big
PVOID m_sort_session_details;

PVOID m_process_matchmaking_find_response;
PVOID m_serialize_player_data_msg;

PVOID m_serialize_join_request_message;
PVOID m_serialize_join_request_message_2;

functions::give_pickup_rewards m_give_pickup_rewards;
functions::send_network_damage m_send_network_damage;
Expand Down
2 changes: 1 addition & 1 deletion src/hooking/hooking.cpp
Expand Up @@ -80,9 +80,9 @@ namespace big
detour_hook_helper::add<hooks::send_chat_message>("SCM", g_pointers->m_gta.m_send_chat_message);

detour_hook_helper::add<hooks::process_matchmaking_find_response>("PMFR", g_pointers->m_gta.m_process_matchmaking_find_response);
detour_hook_helper::add<hooks::serialize_player_data_msg>("SJPD", g_pointers->m_gta.m_serialize_player_data_msg);

detour_hook_helper::add<hooks::serialize_join_request_message>("SJRM", g_pointers->m_gta.m_serialize_join_request_message);
detour_hook_helper::add<hooks::serialize_join_request_message_2>("SJRM2", g_pointers->m_gta.m_serialize_join_request_message_2);

detour_hook_helper::add<hooks::start_matchmaking_find_sessions>("SMFS", g_pointers->m_gta.m_start_matchmaking_find_sessions);

Expand Down
2 changes: 1 addition & 1 deletion src/hooking/hooking.hpp
Expand Up @@ -119,8 +119,8 @@ namespace big

static bool process_matchmaking_find_response(void* _this, void* unused, rage::JSONNode* node, int* unk);

static bool serialize_player_data_msg(CNetGamePlayerDataMsg* msg, rage::datBitBuffer* buffer);
static bool serialize_join_request_message(RemoteGamerInfoMsg* info, void* data, int size, int* bits_serialized);
static bool serialize_join_request_message_2(__int64 msg, void* buf, int size, int* bits_serialized);

static bool start_matchmaking_find_sessions(int profile_index, int available_slots, NetworkGameFilterMatchmakingComponent* filter, unsigned int max_sessions, rage::rlSessionInfo* results, int* num_sessions_found, rage::rlTaskStatus* status);

Expand Down
17 changes: 17 additions & 0 deletions src/hooks/misc/serialize_join_request_message.cpp
@@ -1,6 +1,7 @@
#include "gta_util.hpp"
#include "hooking/hooking.hpp"

#include <network/CNetGamePlayerDataMsg.hpp>
#include <network/Network.hpp>
#include <network/RemoteGamerInfoMsg.hpp>

Expand All @@ -11,7 +12,23 @@ namespace big
if (info->unk_0xC0 == 0)
info->unk_0xC0 = 1; // TODO: do we need this anymore?

if (g.protections.desync_kick)
info->m_gamer_info.m_nat_type = 0;

info->m_num_handles = 0;
return g_hooking->get_original<hooks::serialize_join_request_message>()(info, data, size, bits_serialized);
}

bool hooks::serialize_join_request_message_2(__int64 msg, void* buf, int size, int* bits_serialized)
{
auto& data = *(CNetGamePlayerDataMsg*)(msg + 0x128);

if (g.session.join_in_sctv_slots)
data.m_matchmaking_group = 4;

if (g.protections.desync_kick)
data.m_nat_type = 0;

return g_hooking->get_original<hooks::serialize_join_request_message_2>()(msg, buf, size, bits_serialized);
}
}
20 changes: 0 additions & 20 deletions src/hooks/misc/serialize_player_data_msg.cpp

This file was deleted.

12 changes: 6 additions & 6 deletions src/hooks/protections/can_apply_data.cpp
Expand Up @@ -426,8 +426,8 @@ namespace big
break;
case sync_node_id("CDynamicEntityGameStateDataNode"):
LOG_FIELD(CDynamicEntityGameStateDataNode, m_interior_index);
LOG_FIELD_B(CDynamicEntityGameStateDataNode, unk_00C4);
LOG_FIELD_B(CDynamicEntityGameStateDataNode, unk_00C5);
LOG_FIELD_B(CDynamicEntityGameStateDataNode, m_loads_collisions);
LOG_FIELD_B(CDynamicEntityGameStateDataNode, m_retained);
LOG_FIELD(CDynamicEntityGameStateDataNode, m_decor_count);
for (int i = 0; i < ((CDynamicEntityGameStateDataNode*)node)->m_decor_count; i++)
{
Expand Down Expand Up @@ -635,13 +635,13 @@ namespace big
LOG_FIELD_B(CPhysicalAttachDataNode, m_is_cargo_vehicle);
break;
case sync_node_id("CPhysicalHealthDataNode"):
LOG_FIELD_B(CPhysicalHealthDataNode, unk_00C0);
LOG_FIELD_B(CPhysicalHealthDataNode, m_has_max_health);
LOG_FIELD_B(CPhysicalHealthDataNode, m_has_max_health_changed);
LOG_FIELD(CPhysicalHealthDataNode, m_max_health);
LOG_FIELD(CPhysicalHealthDataNode, m_current_health);
LOG_FIELD_NI(CPhysicalHealthDataNode, m_weapon_damage_entity);
LOG_FIELD_H(CPhysicalHealthDataNode, m_weapon_damage_hash);
LOG_FIELD(CPhysicalHealthDataNode, unk_00D8);
LOG_FIELD(CPhysicalHealthDataNode, m_last_damaged_material_id);
break;
case sync_node_id("CPhysicalMigrationDataNode"):
LOG_FIELD_B(CPhysicalMigrationDataNode, m_unk);
Expand Down Expand Up @@ -933,8 +933,8 @@ namespace big
LOG_FIELD_B(CPhysicalGameStateDataNode, m_flag2);
LOG_FIELD_B(CPhysicalGameStateDataNode, m_flag3);
LOG_FIELD_B(CPhysicalGameStateDataNode, m_flag4);
LOG_FIELD(CPhysicalGameStateDataNode, m_val1);
LOG_FIELD(CPhysicalGameStateDataNode, m_unk204);
LOG_FIELD(CPhysicalGameStateDataNode, m_alpha_type);
LOG_FIELD(CPhysicalGameStateDataNode, m_custom_fade_duration);
LOG_FIELD_B(CPhysicalGameStateDataNode, m_unk5);
break;
case sync_node_id("CPhysicalScriptGameStateDataNode"):
Expand Down
16 changes: 8 additions & 8 deletions src/pointers.cpp
Expand Up @@ -752,22 +752,22 @@ namespace big
g_pointers->m_gta.m_process_matchmaking_find_response = ptr.as<PVOID>();
}
},
// Serialize Player Data Message
// Serialize Join Request Message
{
"SPDM",
"48 89 5C 24 08 48 89 74 24 10 48 89 7C 24 18 41 56 48 83 EC 20 BF 01 00 00 00",
"SJRM",
"E8 ? ? ? ? 84 C0 0F 84 9B 00 00 00 49 8D 8F 48 11 00 00",
[](memory::handle ptr)
{
g_pointers->m_gta.m_serialize_player_data_msg = ptr.as<PVOID>();
g_pointers->m_gta.m_serialize_join_request_message = ptr.add(1).rip().as<PVOID>();
}
},
// Serialize Join Request Message
// Serialize Join Request Message 2
{
"SJRM",
"E8 ? ? ? ? 84 C0 0F 84 9B 00 00 00 49 8D 8F 48 11 00 00",
"SJRM2",
"E8 ? ? ? ? 48 8D 8D 08 01 00 00 8A D8",
[](memory::handle ptr)
{
g_pointers->m_gta.m_serialize_join_request_message = ptr.add(1).rip().as<PVOID>();
g_pointers->m_gta.m_serialize_join_request_message_2 = ptr.add(1).rip().as<PVOID>();
}
},
// Send Network Damage
Expand Down
1 change: 1 addition & 0 deletions src/views/settings/view_protection_settings.cpp
Expand Up @@ -60,6 +60,7 @@ namespace big
ImGui::Checkbox("VIEW_PROTECTION_SETTINGS_KICK_REJOIN"_T.data(), &g.protections.kick_rejoin);
ImGui::Checkbox("BLOCK_TRAFFIC_MANIPULATION"_T.data(), &g.protections.stop_traffic);
components::command_checkbox<"forcerelays">();
ImGui::Checkbox("DESYNC_KICK"_T.data(), &g.protections.desync_kick);
ImGui::EndGroup();

ImGui::SeparatorText("VIEW_PROTECTION_SETTINGS_OPTIONS"_T.data());
Expand Down

0 comments on commit 86c63df

Please sign in to comment.