Skip to content

Commit

Permalink
run level gen callbacks for transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Dregu committed Oct 12, 2023
1 parent e70b5cb commit 54a993a
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/game_api/level_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,62 @@ void level_gen(LevelGenSystem* level_gen_sys, float param_2, size_t param_3)
g_levels_to_load.clear();
}

using TransGenFun = void(ThemeInfo*);
TransGenFun* g_trans_gen_trampoline{nullptr};
TransGenFun* g_trans_gen2_trampoline{nullptr};
using TransGenFun3 = void(size_t, size_t, ThemeInfo*);
TransGenFun3* g_trans_gen3_trampoline{nullptr};
using TransGenFun4 = void(size_t, size_t, size_t, size_t, size_t, size_t);
TransGenFun4* g_trans_gen4_trampoline{nullptr};
// generic transition hook
void trans_gen(ThemeInfo* theme)
{
push_spawn_type_flags(SPAWN_TYPE_LEVEL_GEN_GENERAL);
OnScopeExit pop{[]
{ pop_spawn_type_flags(SPAWN_TYPE_LEVEL_GEN_GENERAL); }};

if (pre_level_generation())
return;
g_trans_gen_trampoline(theme);
post_level_generation();
}
// cosmic transition hook
void trans_gen2(ThemeInfo* theme)
{
push_spawn_type_flags(SPAWN_TYPE_LEVEL_GEN_GENERAL);
OnScopeExit pop{[]
{ pop_spawn_type_flags(SPAWN_TYPE_LEVEL_GEN_GENERAL); }};

if (pre_level_generation())
return;
g_trans_gen2_trampoline(theme);
post_level_generation();
}
// duat transition hook
void trans_gen3(size_t a, size_t b, ThemeInfo* theme)
{
push_spawn_type_flags(SPAWN_TYPE_LEVEL_GEN_GENERAL);
OnScopeExit pop{[]
{ pop_spawn_type_flags(SPAWN_TYPE_LEVEL_GEN_GENERAL); }};

if (pre_level_generation())
return;
g_trans_gen3_trampoline(a, b, theme);
post_level_generation();
}
// olmecship transition hook
void trans_gen4(size_t a, size_t b, size_t c, size_t d, size_t e, size_t f)
{
push_spawn_type_flags(SPAWN_TYPE_LEVEL_GEN_GENERAL);
OnScopeExit pop{[]
{ pop_spawn_type_flags(SPAWN_TYPE_LEVEL_GEN_GENERAL); }};

if (pre_level_generation())
return;
g_trans_gen4_trampoline(a, b, c, d, e, f);
post_level_generation();
}

using LoadScreenFun = void(StateMemory*, size_t, size_t);
LoadScreenFun* g_load_screen_trampoline{nullptr};
void load_screen(StateMemory* state, size_t param_2, size_t param_3)
Expand Down Expand Up @@ -1500,6 +1556,10 @@ void LevelGenData::init()
g_load_screen_trampoline = (LoadScreenFun*)get_address("load_screen_func"sv);
g_unload_layer_trampoline = (UnloadLayerFun*)get_address("unload_layer"sv);
g_init_layer_trampoline = (InitLayerFun*)get_address("init_layer"sv);
g_trans_gen_trampoline = (TransGenFun*)get_address("spawn_transition"sv);
g_trans_gen2_trampoline = (TransGenFun*)get_address("spawn_transition_cosmic"sv);
g_trans_gen3_trampoline = (TransGenFun3*)get_address("spawn_transition_duat"sv);
g_trans_gen4_trampoline = (TransGenFun4*)get_address("spawn_transition_olmecship"sv);

DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
Expand All @@ -1517,6 +1577,10 @@ void LevelGenData::init()
DetourAttach((void**)&g_load_screen_trampoline, load_screen);
DetourAttach((void**)&g_unload_layer_trampoline, unload_layer);
DetourAttach((void**)&g_init_layer_trampoline, load_layer);
DetourAttach((void**)&g_trans_gen_trampoline, trans_gen);
DetourAttach((void**)&g_trans_gen2_trampoline, trans_gen2);
DetourAttach((void**)&g_trans_gen3_trampoline, trans_gen3);
DetourAttach((void**)&g_trans_gen4_trampoline, trans_gen4);

const LONG error = DetourTransactionCommit();
if (error != NO_ERROR)
Expand Down
24 changes: 24 additions & 0 deletions src/game_api/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2054,6 +2054,30 @@ std::unordered_map<std::string_view, AddressRule> g_address_rules{
PatternCommandBuffer{}
.from_exe_base(0x22c061d0),
},
{
"spawn_transition"sv,
// TODO
PatternCommandBuffer{}
.from_exe_base(0x22afe5c0),
},
{
"spawn_transition_cosmic"sv,
// TODO
PatternCommandBuffer{}
.from_exe_base(0x22b373b0),
},
{
"spawn_transition_duat"sv,
// TODO
PatternCommandBuffer{}
.from_exe_base(0x22b34940),
},
{
"spawn_transition_olmecship"sv,
// TODO
PatternCommandBuffer{}
.from_exe_base(0x22b2d350),
},
};
std::unordered_map<std::string_view, size_t> g_cached_addresses;

Expand Down

0 comments on commit 54a993a

Please sign in to comment.