From 75e571b9ac4d2ad719807a9ee19ead4e45e530e8 Mon Sep 17 00:00:00 2001 From: praydog Date: Sun, 19 May 2024 12:25:45 -0700 Subject: [PATCH 1/2] Lua: Possible fix for hook storage not always working --- src/HookManager.cpp | 6 +++++- src/mods/ScriptRunner.hpp | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/HookManager.cpp b/src/HookManager.cpp index 22d3624e2..d723c9a48 100644 --- a/src/HookManager.cpp +++ b/src/HookManager.cpp @@ -1,3 +1,5 @@ +#include + #include #include @@ -127,7 +129,9 @@ void HookManager::HookedFn::on_post_hook() { auto& ret_val = storage->ret_val; //auto& ret_addr = storage->ret_addr_post; - for (const auto& cb : cbs) { + // Iterate in reverse because it helps with the hook storage we use in Lua + // It should help with any other system that wants to use a stack-based storage system. + for (const auto& cb : cbs | std::views::reverse) { if (cb.post_fn) { // Valid return address in recursion scenario is no longer supported with this API. // We just pass ret_addr_pre for now, even though it's not accurate. diff --git a/src/mods/ScriptRunner.hpp b/src/mods/ScriptRunner.hpp index 81a07749e..8a79348ff 100644 --- a/src/mods/ScriptRunner.hpp +++ b/src/mods/ScriptRunner.hpp @@ -178,7 +178,7 @@ class ScriptState { auto it = m_hook_storage.find(thread_hash); if (it != m_hook_storage.end()) { if (!it->second.empty()) { - it->second.pop_front(); + it->second.pop_back(); } } @@ -196,7 +196,7 @@ class ScriptState { auto it = m_hook_storage.find(thread_hash); if (it != m_hook_storage.end()) { if (!it->second.empty()) { - return it->second.front(); + return it->second.back(); } } From c0b88490fcae1b420c26dbb2541e1340465bf000 Mon Sep 17 00:00:00 2001 From: praydog Date: Wed, 22 May 2024 19:50:01 -0700 Subject: [PATCH 2/2] Deps: Update kananlib (fix case where scans could cause crashes) --- CMakeLists.txt | 4 ++-- cmake.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fba96bec..4f21cc321 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -134,13 +134,13 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(bddisasm) -message(STATUS "Fetching kananlib (ccf2e5a32cf4c85a90641ae7a35c2b1d636c7636)...") +message(STATUS "Fetching kananlib (cca66766b139994f478ea48befd67a179b7310ab)...") FetchContent_Declare( kananlib GIT_REPOSITORY https://github.com/cursey/kananlib GIT_TAG - ccf2e5a32cf4c85a90641ae7a35c2b1d636c7636 + cca66766b139994f478ea48befd67a179b7310ab ) FetchContent_MakeAvailable(kananlib) diff --git a/cmake.toml b/cmake.toml index fc8c50e14..5c4767cc4 100644 --- a/cmake.toml +++ b/cmake.toml @@ -175,7 +175,7 @@ tag = "v1.34.10" [fetch-content.kananlib] git = "https://github.com/cursey/kananlib" -tag = "ccf2e5a32cf4c85a90641ae7a35c2b1d636c7636" +tag = "cca66766b139994f478ea48befd67a179b7310ab" [target.utility] type = "static"