From a59462f3c3c9bf3572b843285c2c1fcc55bd392f Mon Sep 17 00:00:00 2001 From: FutureRave Date: Sun, 14 May 2023 10:02:32 +0100 Subject: [PATCH] feat: game_event component --- src/client/component/game_event.cpp | 58 +++++++++++++++++++++++++++++ src/client/component/game_event.hpp | 7 ++++ src/client/component/script.cpp | 8 ++-- src/client/game/symbols.hpp | 9 +++++ 4 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 src/client/component/game_event.cpp create mode 100644 src/client/component/game_event.hpp diff --git a/src/client/component/game_event.cpp b/src/client/component/game_event.cpp new file mode 100644 index 00000000..1ac93daa --- /dev/null +++ b/src/client/component/game_event.cpp @@ -0,0 +1,58 @@ +#include +#include "loader/component_loader.hpp" +#include + +#include "game_event.hpp" + +#include + +namespace game_event +{ + namespace + { + std::vector> g_init_game_tasks_; + std::vector> g_shutdown_game_tasks_; + + void rope_init_ropes_stub() + { + for (const auto& func : g_init_game_tasks_) + { + func(); + } + + game::Rope_InitRopes(); + } + + void mantle_shutdown_anims_stub() + { + for (const auto& func : g_init_game_tasks_) + { + func(); + } + + game::Mantle_ShutdownAnims(); + } + } + + void on_g_init_game(const std::function& callback) + { + g_init_game_tasks_.emplace_back(callback); + } + + void on_g_shutdown_game(const std::function& callback) + { + g_shutdown_game_tasks_.emplace_back(callback); + } + + class component final : public generic_component + { + public: + void post_unpack() override + { + utils::hook::call(game::select(0x1419DD6EC, 0x1402ABC1B), rope_init_ropes_stub); + utils::hook::call(game::select(0x141A02AAD, 0x1402ADF1D), rope_init_ropes_stub); + } + }; +} + +REGISTER_COMPONENT(game_event::component) diff --git a/src/client/component/game_event.hpp b/src/client/component/game_event.hpp new file mode 100644 index 00000000..875cc719 --- /dev/null +++ b/src/client/component/game_event.hpp @@ -0,0 +1,7 @@ +#pragma once + +namespace game_event +{ + void on_g_init_game(const std::function& callback); + void on_g_shutdown_game(const std::function& callback); +} diff --git a/src/client/component/script.cpp b/src/client/component/script.cpp index d551b278..0a0bfceb 100644 --- a/src/client/component/script.cpp +++ b/src/client/component/script.cpp @@ -2,7 +2,7 @@ #include "loader/component_loader.hpp" #include "game/game.hpp" -#include "scheduler.hpp" +#include "game_event.hpp" #include #include @@ -15,7 +15,6 @@ namespace script constexpr size_t GSC_MAGIC = 0x1C000A0D43534780; utils::hook::detour db_find_x_asset_header_hook; - utils::hook::detour g_shutdown_game_hook; utils::hook::detour gscr_get_bgb_remaining_hook; utils::memory::allocator allocator; @@ -130,11 +129,10 @@ namespace script return asset_header; } - void g_shutdown_game_stub(bool free_scripts) + void clear_script_memory() { loaded_scripts.clear(); allocator.clear(); - g_shutdown_game_hook.invoke(free_scripts); } void load_gametype_script_stub() @@ -168,7 +166,7 @@ namespace script db_find_x_asset_header_hook.create(game::select(0x141420ED0, 0x1401D5FB0), db_find_x_asset_header_stub); // Free our scripts when the game ends - g_shutdown_game_hook.create(game::select(0x141A02900, 0x1402ADD70), g_shutdown_game_stub); + game_event::on_g_shutdown_game(clear_script_memory); // Load our scripts when the gametype script is loaded utils::hook::call(game::select(0x141AAF37C, 0x1402D8C7F), load_gametype_script_stub); diff --git a/src/client/game/symbols.hpp b/src/client/game/symbols.hpp index a40f6ce2..ee415ce6 100644 --- a/src/client/game/symbols.hpp +++ b/src/client/game/symbols.hpp @@ -113,6 +113,15 @@ namespace game WEAK symbol Sys_GetTLS{0x1421837B0, 0x140525EB0}; WEAK symbol Sys_IsDatabaseReady{0x142183A60}; + // Rope + WEAK symbol Rope_InitRopes{0x1420D8D00, 0x1404E4300}; + + // Glass + WEAK symbol GlassSv_Shutdown{0x1425AA7A0, 0x14065BCC0}; + + // Mantle + WEAK symbol Mantle_ShutdownAnims{0x142678C80, 0x1406A1B50}; + // Unnamed WEAK symbol CopyString{0x1422AC220, 0x14056BD70};