Skip to content

Commit

Permalink
Lua: Possible fix for hook storage not always working
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed May 19, 2024
1 parent 82cbd4b commit 75e571b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/HookManager.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <ranges>

#include <hde64.h>
#include <spdlog/spdlog.h>

Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/mods/ScriptRunner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand All @@ -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();
}
}

Expand Down

0 comments on commit 75e571b

Please sign in to comment.