From d0b523873d9d9dde51e9caac822aabf4b00a72b3 Mon Sep 17 00:00:00 2001 From: Aure7138 <100095051+Aure7138@users.noreply.github.com> Date: Wed, 23 Nov 2022 06:12:40 +0800 Subject: [PATCH] chore: Renamed ptr_to_handle & some small refactoring (#632) --- src/function_types.hpp | 4 ++-- src/pointers.cpp | 16 +++++----------- src/pointers.hpp | 4 ++-- src/services/vehicle/persist_car_service.cpp | 4 ++-- src/views/self/view_weapons.cpp | 5 ++++- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/function_types.hpp b/src/function_types.hpp index 23abfea5..81044a09 100644 --- a/src/function_types.hpp +++ b/src/function_types.hpp @@ -22,8 +22,8 @@ namespace big::functions using increment_stat_event = bool(*)(uint64_t net_event_struct, int64_t sender, int64_t a3); - using ptr_to_handle = Entity(*)(void* entity); - using get_script_handle_t = uint64_t(*)(int64_t); + using ptr_to_handle = Entity(*)(void*); + using handle_to_ptr = void*(*)(Entity); using multiplayer_chat_filter = int(__int64 chat_type, const char* input, const char** output); using write_player_game_state_data_node = bool(*)(rage::netObject* plr, CPlayerGameStateDataNode* node); diff --git a/src/pointers.cpp b/src/pointers.cpp index 723c28be..ddbeaf46 100644 --- a/src/pointers.cpp +++ b/src/pointers.cpp @@ -224,16 +224,16 @@ namespace big m_replay_interface = ptr.add(0x1F).rip().as(); }); - // Pointer to Handle + // Ptr To Handle main_batch.add("PTH", "48 8B F9 48 83 C1 10 33 DB", [this](memory::handle ptr) { m_ptr_to_handle = ptr.sub(0x15).as(); }); - // Get Script Handle + // Handle To Ptr main_batch.add("GSH", "83 F9 FF 74 31 4C 8B 0D", [this](memory::handle ptr) { - m_get_script_handle = ptr.as(); + m_handle_to_ptr = ptr.as(); }); // Blame Explode @@ -576,16 +576,10 @@ namespace big if (auto pat = mem_region.scan("41 80 78 28 ? 0F 85 F5 01 00 00")) { - m_bypass_max_count_of_active_sticky_bombs = pat.add(4).as(); - - // declare it right now even though we write the same value - // so that it get cleaned up in the dctor - memory::byte_patch::make(m_bypass_max_count_of_active_sticky_bombs, *m_bypass_max_count_of_active_sticky_bombs); + m_bypass_max_count_of_active_sticky_bombs = memory::byte_patch::make(pat.add(4).as(), { 99 }).get(); if (g->weapons.bypass_c4_limit) - { - *m_bypass_max_count_of_active_sticky_bombs = 99; - } + m_bypass_max_count_of_active_sticky_bombs->apply(); } /** diff --git a/src/pointers.hpp b/src/pointers.hpp index 82692f85..dd23c1c4 100644 --- a/src/pointers.hpp +++ b/src/pointers.hpp @@ -30,7 +30,7 @@ namespace big rage::CReplayInterface** m_replay_interface{}; functions::ptr_to_handle m_ptr_to_handle{}; - functions::get_script_handle_t m_get_script_handle{}; + functions::handle_to_ptr m_handle_to_ptr{}; rage::scrNativeRegistrationTable* m_native_registration_table{}; functions::get_native_handler m_get_native_handler{}; functions::fix_vectors m_fix_vectors{}; @@ -122,7 +122,7 @@ namespace big functions::start_get_session_by_gamer_handle m_start_get_session_by_gamer_handle; functions::join_session_by_info m_join_session_by_info; - uint8_t* m_bypass_max_count_of_active_sticky_bombs; + memory::byte_patch* m_bypass_max_count_of_active_sticky_bombs; functions::reset_network_complaints m_reset_network_complaints{}; diff --git a/src/services/vehicle/persist_car_service.cpp b/src/services/vehicle/persist_car_service.cpp index 7da41fe6..b102d57b 100644 --- a/src/services/vehicle/persist_car_service.cpp +++ b/src/services/vehicle/persist_car_service.cpp @@ -296,7 +296,7 @@ namespace big const auto vehicle_rotation = ENTITY::GET_ENTITY_ROTATION(vehicle, 0); bool has_collision = ENTITY::GET_ENTITY_COLLISION_DISABLED(object); bool is_visible = ENTITY::IS_ENTITY_VISIBLE(object); - CObject* cobject = (CObject*)g_pointers->m_get_script_handle(vehicle); + CObject* cobject = (CObject*)g_pointers->m_handle_to_ptr(vehicle); bool is_invincible = misc::has_bit_set(&(int&)cobject->m_damage_bits, 8); Vector3 rotation; @@ -423,7 +423,7 @@ namespace big vehicle_json[pearlescent_color_key] = pearlescent_color; bool has_collision = ENTITY::GET_ENTITY_COLLISION_DISABLED(vehicle); bool is_visible = ENTITY::IS_ENTITY_VISIBLE(vehicle); - CVehicle* cvehicle = (CVehicle*)g_pointers->m_get_script_handle(vehicle); + CVehicle* cvehicle = (CVehicle*)g_pointers->m_handle_to_ptr(vehicle); bool is_invincible = misc::has_bit_set(&(int&)cvehicle->m_damage_bits, 8); vehicle_json[has_collision_key] = !has_collision; vehicle_json[is_visible_key] = is_visible; diff --git a/src/views/self/view_weapons.cpp b/src/views/self/view_weapons.cpp index bce75038..acadb31c 100644 --- a/src/views/self/view_weapons.cpp +++ b/src/views/self/view_weapons.cpp @@ -22,7 +22,10 @@ namespace big if (ImGui::Checkbox("Bypass C4 Limit", &g->weapons.bypass_c4_limit)) { - *g_pointers->m_bypass_max_count_of_active_sticky_bombs = g->weapons.bypass_c4_limit ? 99 : 4; + if (g->weapons.bypass_c4_limit) + g_pointers->m_bypass_max_count_of_active_sticky_bombs->apply(); + else + g_pointers->m_bypass_max_count_of_active_sticky_bombs->restore(); } eAmmoSpecialType selected_ammo = g->weapons.ammo_special.type;