From d077447322ee1b3000b63d394637bc61793d73f4 Mon Sep 17 00:00:00 2001 From: maybegreat48 Date: Mon, 23 Sep 2024 07:24:23 -0400 Subject: [PATCH] fixes --- cmake/gtav-classes.cmake | 2 +- src/function_types.hpp | 2 - src/gta_pointers.hpp | 2 - src/hooks/protections/receive_net_message.cpp | 2 +- src/pointers.cpp | 9 ---- src/services/battleye/battleye_service.cpp | 51 ++++++++++++++++--- src/services/battleye/battleye_service.hpp | 2 +- 7 files changed, 48 insertions(+), 22 deletions(-) diff --git a/cmake/gtav-classes.cmake b/cmake/gtav-classes.cmake index d1d028ad..27bd4c1a 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 e45f7f505ac2394c9213f1577831ab100cc74fa2 + GIT_TAG b1a2ef201bdbd8b4171e932d5c8de68cc9df0283 GIT_PROGRESS TRUE CONFIGURE_COMMAND "" BUILD_COMMAND "" diff --git a/src/function_types.hpp b/src/function_types.hpp index 88117ec1..c199f11f 100644 --- a/src/function_types.hpp +++ b/src/function_types.hpp @@ -230,6 +230,4 @@ namespace big::functions using can_do_damage_to_ped = bool (*)(CPed* from, CWeaponInfo* current_weapon, CPed* target); using get_last_keyboard_state = KeyboardState (*)(); - - using base_64_encode = bool(*)(void* in, int in_size, char* out, int out_size, int* bytes_written); } diff --git a/src/gta_pointers.hpp b/src/gta_pointers.hpp index c45b49c8..9fda7522 100644 --- a/src/gta_pointers.hpp +++ b/src/gta_pointers.hpp @@ -419,8 +419,6 @@ namespace big functions::get_last_keyboard_state m_get_last_keyboard_state; PVOID m_network_can_access_multiplayer; - - functions::base_64_encode m_base_64_encode; }; #pragma pack(pop) static_assert(sizeof(gta_pointers) % 8 == 0, "Pointers are not properly aligned"); diff --git a/src/hooks/protections/receive_net_message.cpp b/src/hooks/protections/receive_net_message.cpp index 7f599d0d..7a93e3d0 100644 --- a/src/hooks/protections/receive_net_message.cpp +++ b/src/hooks/protections/receive_net_message.cpp @@ -753,7 +753,7 @@ namespace big if (client && player) { - g_battleye_service.recieve_message(player->get_net_game_player()->get_host_token(), &data, size); + g_battleye_service.receive_message(player->get_net_game_player()->get_host_token(), &data, size); } break; diff --git a/src/pointers.cpp b/src/pointers.cpp index 05f5894c..f6eec04c 100644 --- a/src/pointers.cpp +++ b/src/pointers.cpp @@ -1986,15 +1986,6 @@ namespace big { g_pointers->m_gta.m_network_can_access_multiplayer = ptr.add(1).rip().as(); } - }, - // Base 64 Encode - { - "B64E", - "8D 2C 95 01 00 00 00", - [](memory::handle ptr) - { - g_pointers->m_gta.m_base_64_encode = ptr.sub(0x4F).as(); - } } >(); // don't leave a trailing comma at the end diff --git a/src/services/battleye/battleye_service.cpp b/src/services/battleye/battleye_service.cpp index c2354e1f..4d5abc5b 100644 --- a/src/services/battleye/battleye_service.cpp +++ b/src/services/battleye/battleye_service.cpp @@ -8,6 +8,46 @@ #include +namespace +{ + static std::string base64_encode(const std::string& data) + { + static constexpr char sEncodingTable[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'}; + + size_t in_len = data.size(); + size_t out_len = 4 * ((in_len + 2) / 3); + std::string ret(out_len, '\0'); + size_t i; + char* p = ret.data(); + + for (i = 0; i < in_len - 2; i += 3) + { + *p++ = sEncodingTable[(data[i] >> 2) & 0x3F]; + *p++ = sEncodingTable[((data[i] & 0x3) << 4) | ((int)(data[i + 1] & 0xF0) >> 4)]; + *p++ = sEncodingTable[((data[i + 1] & 0xF) << 2) | ((int)(data[i + 2] & 0xC0) >> 6)]; + *p++ = sEncodingTable[data[i + 2] & 0x3F]; + } + if (i < in_len) + { + *p++ = sEncodingTable[(data[i] >> 2) & 0x3F]; + if (i == (in_len - 1)) + { + *p++ = sEncodingTable[((data[i] & 0x3) << 4)]; + *p++ = '='; + } + else + { + *p++ = sEncodingTable[((data[i] & 0x3) << 4) | ((int)(data[i + 1] & 0xF0) >> 4)]; + *p++ = sEncodingTable[((data[i + 1] & 0xF) << 2)]; + } + *p++ = '='; + } + + return ret; + } + +} + namespace big { class battleye_server : looped_command @@ -175,14 +215,13 @@ namespace big return; char string[32]{}; - char guid[45]{}; snprintf(string, sizeof(string), "%I64d", rockstar_id); - g_pointers->m_gta.m_base_64_encode(string, strlen(string), guid, sizeof(guid), nullptr); - + auto guid = base64_encode(string); + m_battleye_api.m_add_player(token, -1, 0, name, false); - m_battleye_api.m_assign_guid(token, guid, strlen(guid)); - m_battleye_api.m_assign_guid_verified(token, guid, strlen(guid)); + m_battleye_api.m_assign_guid(token, guid.data(), guid.length()); + m_battleye_api.m_assign_guid_verified(token, guid.data(), guid.length()); m_battleye_api.m_set_player_state(token, 1); } @@ -196,7 +235,7 @@ namespace big m_battleye_api.m_set_player_state(token, -1); } - void battleye_service::recieve_message(std::uint64_t token, void* message, int size) + void battleye_service::receive_message(std::uint64_t token, void* message, int size) { std::lock_guard lock(m_mutex); diff --git a/src/services/battleye/battleye_service.hpp b/src/services/battleye/battleye_service.hpp index 48b6a540..eedc9907 100644 --- a/src/services/battleye/battleye_service.hpp +++ b/src/services/battleye/battleye_service.hpp @@ -50,7 +50,7 @@ namespace big void stop(); void add_player(std::uint64_t token, std::uint64_t rockstar_id, const char* name); void remove_player(std::uint64_t token); - void recieve_message(std::uint64_t token, void* message, int size); + void receive_message(std::uint64_t token, void* message, int size); void send_message(std::uint64_t token, void* message, int size); void kick_player(std::uint64_t token, const char* reason); void script_func();