From d83be697a303dfcda37a59e979b14988abbcbb29 Mon Sep 17 00:00:00 2001 From: Arthur <121949966+ShinyWasabi@users.noreply.github.com> Date: Sat, 24 Aug 2024 00:24:23 +0300 Subject: [PATCH 1/5] Fix Disable Phone (#3616) --- src/backend/looped/tunables/disable_phone.cpp | 4 ++-- src/core/scr_globals.hpp | 10 ++-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/backend/looped/tunables/disable_phone.cpp b/src/backend/looped/tunables/disable_phone.cpp index 49fae5e8..90816bed 100644 --- a/src/backend/looped/tunables/disable_phone.cpp +++ b/src/backend/looped/tunables/disable_phone.cpp @@ -10,12 +10,12 @@ namespace big virtual void on_tick() override { - *scr_globals::transaction_overlimit.as() = TRUE; + *scr_globals::disable_phone.as() = TRUE; } virtual void on_disable() override { - *scr_globals::transaction_overlimit.as() = FALSE; + *scr_globals::disable_phone.as() = FALSE; } }; diff --git a/src/core/scr_globals.hpp b/src/core/scr_globals.hpp index 194602f1..1ac5bdaa 100644 --- a/src/core/scr_globals.hpp +++ b/src/core/scr_globals.hpp @@ -5,11 +5,8 @@ namespace big::scr_globals { static inline const script_global gsbd(2648938); - static inline const script_global gsbd_fm(1845281); static inline const script_global gsbd_kicking(1877252); static inline const script_global gsbd_fm_events(1916617); - static inline const script_global gsbd_block_c(2652592); - static inline const script_global gsbd_property_instances(1936863); static inline const script_global globalplayer_bd(2657971); static inline const script_global gpbd_fm_3(1887305); @@ -18,11 +15,7 @@ namespace big::scr_globals static inline const script_global launcher_global(2699171); - static inline const script_global sp(114370); // check flow_controller - static inline const script_global mission_definition(92160); // standard_global_init (66, "agency_heist1", "AH1", 230, 1, 1, -1, -1, 8192) - // creator globals usually remain the same after updates - static inline const script_global creator_job_metadata(4718592); static inline const script_global terminate_creator(1574607); // NETWORK::NETWORK_BAIL(1, 0, 0); fm_*_creator static inline const script_global switch_struct(1574633); static inline const script_global mission_creator_radar_follows_camera(2621443); @@ -60,8 +53,9 @@ namespace big::scr_globals static inline const script_global reset_clothing(104077); // freemode 75, &iLocal_.*, 2\); - static inline const script_global gun_van(1949748); // return -29.532f, 6435.136f, 31.162f; + + static inline const script_global disable_phone(20913); } namespace big::scr_locals From e61dc44a55946913342a4e2845c336721f50fcb8 Mon Sep 17 00:00:00 2001 From: gir489 <100792176+gir489returns@users.noreply.github.com> Date: Fri, 23 Aug 2024 17:49:11 -0400 Subject: [PATCH 2/5] Incorporate eThreadState changes (#3558) --- cmake/gtav-classes.cmake | 2 +- src/backend/commands/player/toxic/turn_into_beast.cpp | 2 +- src/services/gta_data/gta_data_service.cpp | 2 +- src/services/script_connection/script_connection.cpp | 2 +- src/util/scripts.hpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmake/gtav-classes.cmake b/cmake/gtav-classes.cmake index 079284b4..c0125956 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 aebd69542e58fab8975da76c3e555b122ddef5d6 + GIT_TAG 21cbc2076b8d0ac9cbd98d05ebabadcced546f30 GIT_PROGRESS TRUE CONFIGURE_COMMAND "" BUILD_COMMAND "" diff --git a/src/backend/commands/player/toxic/turn_into_beast.cpp b/src/backend/commands/player/toxic/turn_into_beast.cpp index 6a8c839b..4d6213d7 100644 --- a/src/backend/commands/player/toxic/turn_into_beast.cpp +++ b/src/backend/commands/player/toxic/turn_into_beast.cpp @@ -117,7 +117,7 @@ namespace big if (!stack || !net_component) return; - thread->m_context.m_state = rage::eThreadState::unk_3; + thread->m_context.m_state = rage::eThreadState::paused; g.m_hunt_the_beast_thread = thread; for (int i = 0; i < 15; i++) diff --git a/src/services/gta_data/gta_data_service.cpp b/src/services/gta_data/gta_data_service.cpp index d0c68164..eca9c22e 100644 --- a/src/services/gta_data/gta_data_service.cpp +++ b/src/services/gta_data/gta_data_service.cpp @@ -369,7 +369,7 @@ namespace big mp_weapons_thread_id = SYSTEM::START_NEW_SCRIPT_WITH_NAME_HASH(script_hash, 1424); auto thread = gta_util::find_script_thread_by_id(mp_weapons_thread_id); if (thread) - thread->m_context.m_state = rage::eThreadState::unk_3; + thread->m_context.m_state = rage::eThreadState::paused; else LOG(FATAL) << "Failed to find MP_Weapons script!"; SCRIPT::SET_SCRIPT_WITH_NAME_HASH_AS_NO_LONGER_NEEDED(script_hash); diff --git a/src/services/script_connection/script_connection.cpp b/src/services/script_connection/script_connection.cpp index 8fa099de..ed1670e9 100644 --- a/src/services/script_connection/script_connection.cpp +++ b/src/services/script_connection/script_connection.cpp @@ -35,7 +35,7 @@ namespace big if (!m_thread) return false; - m_thread->m_context.m_state = rage::eThreadState::unk_3; + m_thread->m_context.m_state = rage::eThreadState::paused; return true; } diff --git a/src/util/scripts.hpp b/src/util/scripts.hpp index 790bb9bb..366bc69d 100644 --- a/src/util/scripts.hpp +++ b/src/util/scripts.hpp @@ -127,7 +127,7 @@ namespace big::scripts return; } - launcher->m_context.m_state = rage::eThreadState::unk_3; // prevent bad things from happening to the thread in the meantime + launcher->m_context.m_state = rage::eThreadState::paused; // prevent bad things from happening to the thread in the meantime // 3) Remove players from that annoying waiting stage if (check_players_in_state(launcher, 5)) From 6af80e936d10bc506dc10ed79d9d276df29562d9 Mon Sep 17 00:00:00 2001 From: Arthur <121949966+ShinyWasabi@users.noreply.github.com> Date: Mon, 26 Aug 2024 00:16:56 +0300 Subject: [PATCH 3/5] Fix Thread State for Script Functions and cellphone_flashhand (#3619) --- src/lua/bindings/scr_function.cpp | 4 ++-- src/script_function.hpp | 2 +- src/services/hotkey/hotkey_service.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lua/bindings/scr_function.cpp b/src/lua/bindings/scr_function.cpp index 2c80a633..69ee4742 100644 --- a/src/lua/bindings/scr_function.cpp +++ b/src/lua/bindings/scr_function.cpp @@ -161,7 +161,7 @@ namespace lua::scr_function stack[ctx.m_stack_pointer++] = 0; ctx.m_instruction_pointer = instruction_pointer; - ctx.m_state = rage::eThreadState::idle; + ctx.m_state = rage::eThreadState::running; big::g_pointers->m_gta.m_script_vm(stack, big::g_pointers->m_gta.m_script_globals, program, &ctx); @@ -313,7 +313,7 @@ namespace lua::scr_function stack[ctx.m_stack_pointer++] = 0; ctx.m_instruction_pointer = instruction_pointer; - ctx.m_state = rage::eThreadState::idle; + ctx.m_state = rage::eThreadState::running; big::g_pointers->m_gta.m_script_vm(stack, big::g_pointers->m_gta.m_script_globals, program, &ctx); diff --git a/src/script_function.hpp b/src/script_function.hpp index 059d172a..d96a8227 100644 --- a/src/script_function.hpp +++ b/src/script_function.hpp @@ -55,7 +55,7 @@ namespace big stack[ctx.m_stack_pointer++] = 0; ctx.m_instruction_pointer = ip; - ctx.m_state = rage::eThreadState::idle; + ctx.m_state = rage::eThreadState::running; g_pointers->m_gta.m_script_vm(stack, g_pointers->m_gta.m_script_globals, program, &ctx); diff --git a/src/services/hotkey/hotkey_service.cpp b/src/services/hotkey/hotkey_service.cpp index 28641eda..fd6960ba 100644 --- a/src/services/hotkey/hotkey_service.cpp +++ b/src/services/hotkey/hotkey_service.cpp @@ -94,7 +94,7 @@ namespace big { if (script && script->m_script_hash == "cellphone_flashhand"_J) { - is_using_cellphone = script->m_context.m_state == rage::eThreadState::running; + is_using_cellphone = script->m_context.m_state == rage::eThreadState::idle; } } From 1f985a5a2182e83afea3b3820da10415fc0ee348 Mon Sep 17 00:00:00 2001 From: gir489 <100792176+gir489returns@users.noreply.github.com> Date: Wed, 28 Aug 2024 17:38:13 -0400 Subject: [PATCH 4/5] Disables script patches from the Lua layer on eject. (#3628) --- src/lua/bindings/scr_patch.cpp | 6 + src/lua/bindings/scr_patch.hpp | 3 +- src/lua/lua_module.cpp | 1 + src/services/script_patcher/script_patch.hpp | 71 +++--- .../script_patcher/script_patcher_service.cpp | 215 ++++++++++-------- .../script_patcher/script_patcher_service.hpp | 3 +- 6 files changed, 164 insertions(+), 135 deletions(-) diff --git a/src/lua/bindings/scr_patch.cpp b/src/lua/bindings/scr_patch.cpp index 1e27649b..1ffbeb77 100644 --- a/src/lua/bindings/scr_patch.cpp +++ b/src/lua/bindings/scr_patch.cpp @@ -25,6 +25,12 @@ namespace lua::scr_patch module->m_registered_script_patches.push_back(std::make_unique(*this)); } + scr_patch::~scr_patch() + { + disable(); + big::g_script_patcher_service->remove_patch(m_patch_name); + } + void scr_patch::enable() { if (!m_enable) diff --git a/src/lua/bindings/scr_patch.hpp b/src/lua/bindings/scr_patch.hpp index 2e509366..8d771a6d 100644 --- a/src/lua/bindings/scr_patch.hpp +++ b/src/lua/bindings/scr_patch.hpp @@ -2,7 +2,7 @@ namespace lua::scr_patch { - struct scr_patch + class scr_patch { rage::joaat_t m_script; std::string m_patch_name; @@ -21,6 +21,7 @@ namespace lua::scr_patch // Param: patch_: table: The bytes to be written into the script's bytecode. // Adds a patch for the specified script. explicit scr_patch(const std::string& script_name, const std::string& patch_name, const std::string& pattern, const int offset, sol::table patch_, sol::this_state state); + ~scr_patch(); // Lua API: Function // Class: scr_patch diff --git a/src/lua/lua_module.cpp b/src/lua/lua_module.cpp index 2e0a7c43..562c7825 100644 --- a/src/lua/lua_module.cpp +++ b/src/lua/lua_module.cpp @@ -126,6 +126,7 @@ namespace big { std::lock_guard guard(m_registered_scripts_mutex); m_registered_scripts.clear(); + m_registered_script_patches.clear(); } for (const auto owned_tab : m_owned_tabs) diff --git a/src/services/script_patcher/script_patch.hpp b/src/services/script_patcher/script_patch.hpp index e577be74..8ea866c5 100644 --- a/src/services/script_patcher/script_patch.hpp +++ b/src/services/script_patcher/script_patch.hpp @@ -1,34 +1,39 @@ -#pragma once -#include "memory/pattern.hpp" - -namespace big -{ - struct script_data; - - class script_patch - { - rage::joaat_t m_script; - const memory::pattern m_pattern; - std::string m_name; - int32_t m_offset; - std::vector m_patch; - std::vector m_original; - bool* m_bool; - int32_t m_ip; - - static uint8_t* get_code_address(script_data* data, uint32_t index); - static const std::optional get_code_location_by_pattern(script_data* data, const memory::pattern& pattern); - - public: - void enable(script_data* data); - void disable(script_data* data); - - inline rage::joaat_t get_script() - { - return m_script; - } - - script_patch(rage::joaat_t script, std::string name, const memory::pattern pattern, int32_t offset, std::vector patch, bool* enable_bool); - void update(script_data* data); - }; +#pragma once +#include "memory/pattern.hpp" + +namespace big +{ + struct script_data; + + class script_patch + { + rage::joaat_t m_script; + const memory::pattern m_pattern; + std::string m_name; + int32_t m_offset; + std::vector m_patch; + std::vector m_original; + bool* m_bool; + int32_t m_ip; + + static uint8_t* get_code_address(script_data* data, uint32_t index); + static const std::optional get_code_location_by_pattern(script_data* data, const memory::pattern& pattern); + + public: + void enable(script_data* data); + void disable(script_data* data); + + inline rage::joaat_t get_script() + { + return m_script; + } + + inline std::string get_name() + { + return m_name; + } + + script_patch(rage::joaat_t script, std::string name, const memory::pattern pattern, int32_t offset, std::vector patch, bool* enable_bool); + void update(script_data* data); + }; } \ No newline at end of file diff --git a/src/services/script_patcher/script_patcher_service.cpp b/src/services/script_patcher/script_patcher_service.cpp index 37cddb1f..8466a9c6 100644 --- a/src/services/script_patcher/script_patcher_service.cpp +++ b/src/services/script_patcher/script_patcher_service.cpp @@ -1,101 +1,116 @@ -#include "script_patcher_service.hpp" - -#include "script_data.hpp" -#include "script_patch.hpp" - -#include