This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
YimMenu/src/byte_patch_manager.cpp

107 lines
4.9 KiB
C++
Raw Normal View History

2023-04-14 18:54:07 +02:00
#include "byte_patch_manager.hpp"
#include "gta/net_array.hpp"
#include "hooking/hooking.hpp"
2023-04-14 18:54:07 +02:00
#include "memory/byte_patch.hpp"
#include "pointers.hpp"
#include "util/explosion_anti_cheat_bypass.hpp"
2023-04-14 18:54:07 +02:00
#include "util/police.hpp"
#include "util/vehicle.hpp"
#include "util/world_model.hpp"
2023-04-14 18:54:07 +02:00
extern "C" void sound_overload_detour();
uint64_t g_sound_overload_ret_addr;
2023-04-14 18:54:07 +02:00
namespace big
{
static void init()
{
2023-04-16 18:28:49 +00:00
// Restore max wanted level after menu unload
2023-04-14 18:54:07 +02:00
police::m_max_wanted_level =
memory::byte_patch::make(g_pointers->m_gta.m_max_wanted_level.add(5).rip().as<uint32_t*>(), 0).get();
police::m_max_wanted_level_2 =
memory::byte_patch::make(g_pointers->m_gta.m_max_wanted_level.add(14).rip().as<uint32_t*>(), 0).get();
// Patch World Model Spawn Bypass
world_model_bypass::m_world_model_spawn_bypass =
2024-02-12 09:08:38 -05:00
memory::byte_patch::make(g_pointers->m_gta.m_world_model_spawn_bypass.add(3).rip().as<PVOID*>(), 0).get();
2023-04-16 18:28:49 +00:00
// Patch blocked explosions
explosion_anti_cheat_bypass::m_can_blame_others =
memory::byte_patch::make(g_pointers->m_gta.m_blame_explode.as<uint16_t*>(), 0xE990).get();
explosion_anti_cheat_bypass::m_can_use_blocked_explosions =
2023-04-14 18:54:07 +02:00
memory::byte_patch::make(g_pointers->m_gta.m_explosion_patch.sub(12).as<uint16_t*>(), 0x9090).get();
2023-04-16 18:28:49 +00:00
// Skip matchmaking session validity checks
2023-04-14 18:54:07 +02:00
memory::byte_patch::make(g_pointers->m_gta.m_is_matchmaking_session_valid.as<void*>(), std::to_array({0xB0, 0x01, 0xC3}))
->apply(); // has no observable side effects
2023-04-16 18:28:49 +00:00
// Bypass netarray buffer cache when enabled
2023-04-14 18:54:07 +02:00
broadcast_net_array::m_patch =
memory::byte_patch::make(g_pointers->m_gta.m_broadcast_patch.as<uint8_t*>(), 0xEB).get();
2023-04-16 18:28:49 +00:00
// Disable cheat activated netevent when creator warping
2023-04-14 18:54:07 +02:00
memory::byte_patch::make(g_pointers->m_gta.m_creator_warp_cheat_triggered_patch.as<uint8_t*>(), 0xEB)->apply();
2023-04-16 18:28:49 +00:00
// Setup inline hook for sound overload crash protection
2023-04-14 18:54:07 +02:00
g_sound_overload_ret_addr = g_pointers->m_gta.m_sound_overload_detour.add(13 + 15).as<decltype(g_sound_overload_ret_addr)>();
std::vector<byte> bytes = {0xFF, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90}; // far jump opcode + a nop opcode
*(void**)(bytes.data() + 6) = sound_overload_detour;
memory::byte_patch::make(g_pointers->m_gta.m_sound_overload_detour.add(13).as<void*>(), bytes)->apply();
2023-04-16 18:28:49 +00:00
// Disable collision when enabled
2023-04-14 18:54:07 +02:00
vehicle::disable_collisions::m_patch =
memory::byte_patch::make(g_pointers->m_gta.m_disable_collision.sub(2).as<uint8_t*>(), 0xEB).get();
// Crash Trigger
memory::byte_patch::make(g_pointers->m_gta.m_crash_trigger.add(4).as<uint8_t*>(), 0x00)->apply();
2023-04-16 22:27:02 +00:00
// Script VM patches
memory::byte_patch::make(g_pointers->m_gta.m_script_vm_patch_1.add(2).as<uint32_t*>(), 0xc9310272)->apply();
memory::byte_patch::make(g_pointers->m_gta.m_script_vm_patch_1.add(6).as<uint16_t*>(), 0x9090)->apply();
memory::byte_patch::make(g_pointers->m_gta.m_script_vm_patch_2.add(2).as<uint32_t*>(), 0xc9310272)->apply();
memory::byte_patch::make(g_pointers->m_gta.m_script_vm_patch_2.add(6).as<uint16_t*>(), 0x9090)->apply();
memory::byte_patch::make(g_pointers->m_gta.m_script_vm_patch_3.add(2).as<uint32_t*>(), 0xd2310272)->apply();
memory::byte_patch::make(g_pointers->m_gta.m_script_vm_patch_3.add(6).as<uint16_t*>(), 0x9090)->apply();
memory::byte_patch::make(g_pointers->m_gta.m_script_vm_patch_4.add(2).as<uint32_t*>(), 0xd2310272)->apply();
memory::byte_patch::make(g_pointers->m_gta.m_script_vm_patch_4.add(6).as<uint16_t*>(), 0x9090)->apply();
memory::byte_patch::make(g_pointers->m_gta.m_script_vm_patch_5.add(2).as<uint32_t*>(), 0xd2310272)->apply();
memory::byte_patch::make(g_pointers->m_gta.m_script_vm_patch_5.add(6).as<uint16_t*>(), 0x9090)->apply();
memory::byte_patch::make(g_pointers->m_gta.m_script_vm_patch_6.add(2).as<uint32_t*>(), 0xd2310272)->apply();
memory::byte_patch::make(g_pointers->m_gta.m_script_vm_patch_6.add(6).as<uint16_t*>(), 0x9090)->apply();
// Patch script network check
memory::byte_patch::make(g_pointers->m_gta.m_model_spawn_bypass, std::vector{0x90, 0x90})->apply(); // this is no longer integrity checked
// Prevent the attribute task from failing
memory::byte_patch::make(g_pointers->m_sc.m_read_attribute_patch, std::vector{0x90, 0x90})->apply();
memory::byte_patch::make(g_pointers->m_sc.m_read_attribute_patch_2, std::vector{0xB0, 0x01})->apply();
// Prevent the game from crashing when flooded with outgoing events
memory::byte_patch::make(g_pointers->m_gta.m_free_event_error, std::vector{0x90, 0x90, 0x90, 0x90, 0x90})->apply();
// Always send the special ability event
memory::byte_patch::make(g_pointers->m_gta.m_activate_special_ability_patch, std::to_array({0xB0, 0x01, 0xC3}))->apply();
2023-04-14 18:54:07 +02:00
}
byte_patch_manager::byte_patch_manager()
{
init();
g_byte_patch_manager = this;
}
byte_patch_manager::~byte_patch_manager()
{
memory::byte_patch::restore_all();
g_byte_patch_manager = nullptr;
}
}