From b38e0d1c15a7f5c81c4af840a3606fefad82eebc Mon Sep 17 00:00:00 2001 From: CorrM Date: Thu, 23 Feb 2023 11:48:03 +0200 Subject: [PATCH] - Add `SharedData::Discard` method --- examples/UnrealInternalExample/dllmain.cpp | 5 ++++- src/CleanCheat/CleanCheatManager.h | 3 +++ src/CleanCheat/SharedDataBase.h | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/examples/UnrealInternalExample/dllmain.cpp b/examples/UnrealInternalExample/dllmain.cpp index 0010951..4542c7d 100644 --- a/examples/UnrealInternalExample/dllmain.cpp +++ b/examples/UnrealInternalExample/dllmain.cpp @@ -4,6 +4,8 @@ #include "CleanCheat.h" +#define GAME_VIEW_PORT_INDEX 0x02 // Maybe you need to change that number + typedef void (__thiscall* ProcessEventType)(CG::UObject*, CG::UFunction*, void*); typedef void (__thiscall* PostRenderType)(CG::UGameViewportClient*, CG::UCanvas*); @@ -64,6 +66,7 @@ void __stdcall PostRenderHook(CG::UGameViewportClient* gameViewportClient, CG::U Once = true; CleanCheat::Hook->Detour(reinterpret_cast(&OProcessEvent), reinterpret_cast(&ProcessEventHook)); + LOG("Hook 'ProcessEvent' ... Success"); } } catch (...) @@ -134,7 +137,7 @@ void MainEntryPoint(HMODULE hModule) std::vector gameViewportClients = CG::UObject::FindObjects(); LOG("GameViewportClientCount: %d", static_cast(gameViewportClients.size())); - CG::UGameViewportClient*& gameViewportClient = gameViewportClients[1]; // Maybe you need to change that number + CG::UGameViewportClient*& gameViewportClient = gameViewportClients[GAME_VIEW_PORT_INDEX]; void** gameViewportClientVmt = *reinterpret_cast(gameViewportClient); LOG("PostRender : 0x%llx", reinterpret_cast(gameViewportClientVmt[POST_RENDER_INDEX])); diff --git a/src/CleanCheat/CleanCheatManager.h b/src/CleanCheat/CleanCheatManager.h index 4245b62..f655652 100644 --- a/src/CleanCheat/CleanCheatManager.h +++ b/src/CleanCheat/CleanCheatManager.h @@ -136,6 +136,9 @@ class CleanCheat final // Un hook all functions Hook->UnSwapAll(); Hook->UnDetourAll(); + + // Shared data + SharedData->Discard(); // Free memory DELETE_HEAP(Memory); diff --git a/src/CleanCheat/SharedDataBase.h b/src/CleanCheat/SharedDataBase.h index 8dfaea7..0ebe7b5 100644 --- a/src/CleanCheat/SharedDataBase.h +++ b/src/CleanCheat/SharedDataBase.h @@ -6,10 +6,24 @@ ABSTRACT class SharedDataBase { public: virtual ~SharedDataBase() = default; + +protected: + /// + /// Called by Discard method + /// + virtual void OnDestroy() { } public: /// /// Called every tick /// virtual void Tick(TInit* data) = 0; + + /// + /// Discard runner task + /// + void Discard() + { + OnDestroy(); + } };