Skip to content

Commit

Permalink
ChaosMod: Refactor OnPresentCallback into an ChaosEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
pongo1231 committed Oct 19, 2023
1 parent f504863 commit 4b98b4b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions ChaosMod/ChaosMod.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@
<ClInclude Include="Util\HelpText.h" />
<ClInclude Include="Components\HelpTextQueue.h" />
<ClInclude Include="Memory\Hooks\GetLabelTextHook.h" />
<ClInclude Include="Memory\Hooks\PresentHook.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="ChaosMod.rc" />
Expand Down
4 changes: 3 additions & 1 deletion ChaosMod/Memory/Hooks/PresentHook.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <stdafx.h>

#include "PresentHook.h"

#include "Memory/Hooks/Hook.h"
#include "Memory/Hooks/ShaderHook.h"

Expand All @@ -10,7 +12,7 @@ HRESULT HK_IDXGISwapChain_Present(IDXGISwapChain *swapChain, UINT syncInterval,
{
if (!(flags & DXGI_PRESENT_TEST))
{
Hooks::OnPresentCallback();
Hooks::OnPresent.Fire();
}

return OG_IDXGISwapChain_Present(swapChain, syncInterval, flags);
Expand Down
8 changes: 8 additions & 0 deletions ChaosMod/Memory/Hooks/PresentHook.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include "Util/Events.h"

namespace Hooks
{
inline ChaosEvent OnPresent;
}
2 changes: 1 addition & 1 deletion ChaosMod/Memory/Hooks/ScriptThreadRunHook.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <Util/Events.h>
#include "Util/Events.h"

namespace rage
{
Expand Down
25 changes: 15 additions & 10 deletions ChaosMod/Memory/Hooks/ShaderHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

#include "ShaderHook.h"

#include "Memory/Hooks/Hook.h"
#include "Memory/Shader.h"

#include "Memory/Hooks/Hook.h"
#include "Memory/Hooks/PresentHook.h"

#define SHADER_CACHE_MAX_ENTRIES 20

using DWORD64 = unsigned long long;
Expand Down Expand Up @@ -41,6 +43,18 @@ void *HK_rage__CreateShader(const char *name, BYTE *data, DWORD size, DWORD type

static bool OnHook()
{
static CHAOS_EVENT_LISTENER(Hooks::OnPresent) onPresentListener;

onPresentListener.Register(Hooks::OnPresent,
[]()
{
if (ms_RefreshShaders)
{
ms_RefreshShaders = false;
Memory::InvalidateShaderCache();
}
});

Handle handle;

//
Expand Down Expand Up @@ -128,13 +142,4 @@ namespace Hooks
ms_ShaderBytecode.clear();
ms_RefreshShaders = true;
}

void OnPresentCallback()
{
if (ms_RefreshShaders)
{
ms_RefreshShaders = false;
Memory::InvalidateShaderCache();
}
}
}

0 comments on commit 4b98b4b

Please sign in to comment.