From 5f17804280835757ff225d3a88f49d777d0e5bc4 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Fri, 24 Dec 2021 17:51:52 +0100 Subject: [PATCH] Actually fix checkpoint loading --- src/client/component/scripting.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/client/component/scripting.cpp b/src/client/component/scripting.cpp index c6ad6c0e..61465388 100644 --- a/src/client/component/scripting.cpp +++ b/src/client/component/scripting.cpp @@ -97,6 +97,17 @@ namespace scripting script_function_table[current_file][function_name] = codePos; scr_set_thread_position_hook.invoke(threadName, codePos); } + + utils::hook::detour sub_6B2940_hook; + char sub_6B2940_stub(void* a1) + { + const auto result = sub_6B2940_hook.invoke(a1); + if (a1 != nullptr) + { + lua::engine::start(); + } + return result; + } } class component final : public component_interface @@ -113,6 +124,11 @@ namespace scripting scr_set_thread_position_hook.create(0x5BC7E0_b, scr_set_thread_position_stub); process_script_hook.create(0x5C6160_b, process_script_stub); + // Loading last checkpoint doesn't call spawn player again (player_spawn_hook) + // Not sure what this function does but `a1` is != nullptr when loading + // the last checkpoint so we need to start lua in this context + sub_6B2940_hook.create(0x6B2940_b, sub_6B2940_stub); + scheduler::loop([]() { lua::engine::run_frame();