From e3758a15a6430e7ab7ce9821c0d9e19bbf7a1e87 Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Tue, 5 Nov 2019 08:45:44 -0800 Subject: Memory / Main are now cleaned up --- Source/Memory.cpp | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'Source/Memory.cpp') diff --git a/Source/Memory.cpp b/Source/Memory.cpp index d7f0212..b0e2e9d 100644 --- a/Source/Memory.cpp +++ b/Source/Memory.cpp @@ -7,9 +7,6 @@ #undef PROCESSENTRY32 #undef Process32Next -Memory::Memory() { -} - [[nodiscard]] bool Memory::Initialize(const std::wstring& processName) { // First, get the handle of the process @@ -48,23 +45,40 @@ bool Memory::Initialize(const std::wstring& processName) { return true; } -Memory::~Memory() { - if (_handle != nullptr) { - CloseHandle(_handle); +ProcStatus Memory::Heartbeat(const std::wstring& processName) { + if (!_handle && !Initialize(processName)) { + // Couldn't initialize, definitely not running + return ProcStatus::NotRunning; + } + + DWORD exitCode = 0; + GetExitCodeProcess(_handle, &exitCode); + if (exitCode != STILL_ACTIVE) { + // Process has exited, clean up. + _computedAddresses.clear(); + _handle = NULL; + return ProcStatus::NotRunning; } -} -int Memory::GetCurrentFrame() { - int SCRIPT_FRAMES; + int currentFrame = 0x7FFFFFFF; if (GLOBALS == 0x5B28C0) { - SCRIPT_FRAMES = 0x5BE3B0; + currentFrame = ReadData({0x5BE3B0}, 1)[0]; } else if (GLOBALS == 0x62D0A0) { - SCRIPT_FRAMES = 0x63954C; + currentFrame = ReadData({0x63954C}, 1)[0]; } else { assert(false); - return 0x7FFFFFFF; } - return ReadData({SCRIPT_FRAMES}, 1)[0]; + if (currentFrame < 80) return ProcStatus::NewGame; + + // TODO: Some way to return ProcStatus::Randomized vs ProcStatus::NotRandomized vs ProcStatus::DeRandomized; + + return ProcStatus::Running; +} + +Memory::~Memory() { + if (_handle != nullptr) { + CloseHandle(_handle); + } } void Memory::AddSigScan(const std::vector& scanBytes, const std::function& scanFunc) -- cgit 1.4.1