feat: game_event component
This commit is contained in:
parent
07885a7920
commit
a59462f3c3
58
src/client/component/game_event.cpp
Normal file
58
src/client/component/game_event.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
#include <game/game.hpp>
|
||||
|
||||
#include "game_event.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
|
||||
namespace game_event
|
||||
{
|
||||
namespace
|
||||
{
|
||||
std::vector<std::function<void()>> g_init_game_tasks_;
|
||||
std::vector<std::function<void()>> 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<void()>& callback)
|
||||
{
|
||||
g_init_game_tasks_.emplace_back(callback);
|
||||
}
|
||||
|
||||
void on_g_shutdown_game(const std::function<void()>& 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)
|
7
src/client/component/game_event.hpp
Normal file
7
src/client/component/game_event.hpp
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
namespace game_event
|
||||
{
|
||||
void on_g_init_game(const std::function<void()>& callback);
|
||||
void on_g_shutdown_game(const std::function<void()>& callback);
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
#include "loader/component_loader.hpp"
|
||||
#include "game/game.hpp"
|
||||
|
||||
#include "scheduler.hpp"
|
||||
#include "game_event.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/string.hpp>
|
||||
@ -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<void>(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);
|
||||
|
@ -113,6 +113,15 @@ namespace game
|
||||
WEAK symbol<TLSData*()> Sys_GetTLS{0x1421837B0, 0x140525EB0};
|
||||
WEAK symbol<TLSData*()> Sys_IsDatabaseReady{0x142183A60};
|
||||
|
||||
// Rope
|
||||
WEAK symbol<void()> Rope_InitRopes{0x1420D8D00, 0x1404E4300};
|
||||
|
||||
// Glass
|
||||
WEAK symbol<void()> GlassSv_Shutdown{0x1425AA7A0, 0x14065BCC0};
|
||||
|
||||
// Mantle
|
||||
WEAK symbol<void()> Mantle_ShutdownAnims{0x142678C80, 0x1406A1B50};
|
||||
|
||||
// Unnamed
|
||||
WEAK symbol<const char*(const char* name)> CopyString{0x1422AC220, 0x14056BD70};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user