Skip to content

Commit

Permalink
[WakingUpNpcs] Clear npc waking up state on level transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
OrfeasZ committed Oct 10, 2022
1 parent 77897c7 commit 8256ed2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Mods/WakingUpNpcs/Src/WakingUpNpcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ WakingUpNpcs::~WakingUpNpcs()
void WakingUpNpcs::PreInit()
{
Hooks::ZEntitySceneContext_LoadScene->AddDetour(this, &WakingUpNpcs::OnLoadScene);
Hooks::ZEntitySceneContext_ClearScene->AddDetour(this, &WakingUpNpcs::OnClearScene);
}

void WakingUpNpcs::OnEngineInitialized()
Expand Down Expand Up @@ -84,12 +85,20 @@ void WakingUpNpcs::OnFrameUpdate(const SGameUpdateEvent& p_UpdateEvent)

DECLARE_PLUGIN_DETOUR(WakingUpNpcs, void, OnLoadScene, ZEntitySceneContext* th, ZSceneData& sceneData)
{
// TODO: This doesn't get called when loading a save on the same level or restarting. Find something that does.
Logger::Debug("Loading scene: {}", sceneData.m_sceneName);

m_PacifiedTimes.clear();

return HookResult<void>(HookAction::Continue());
}

DECLARE_PLUGIN_DETOUR(WakingUpNpcs, void, OnClearScene, ZEntitySceneContext* th, bool)
{
Logger::Debug("Clearing scene.");

m_PacifiedTimes.clear();

return HookResult<void>(HookAction::Continue());
}

DECLARE_ZHM_PLUGIN(WakingUpNpcs);
1 change: 1 addition & 0 deletions Mods/WakingUpNpcs/Src/WakingUpNpcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class WakingUpNpcs : public IPluginInterface

private:
DEFINE_PLUGIN_DETOUR(WakingUpNpcs, void, OnLoadScene, ZEntitySceneContext*, ZSceneData&);
DEFINE_PLUGIN_DETOUR(WakingUpNpcs, void, OnClearScene, ZEntitySceneContext*, bool);

private:
std::unordered_map<ZActor*, double> m_PacifiedTimes;
Expand Down

0 comments on commit 8256ed2

Please sign in to comment.