about summary refs log tree commit diff stats
path: root/Source/Memory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Memory.cpp')
-rw-r--r--Source/Memory.cpp40
1 files changed, 27 insertions, 13 deletions
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 @@
7#undef PROCESSENTRY32 7#undef PROCESSENTRY32
8#undef Process32Next 8#undef Process32Next
9 9
10Memory::Memory() {
11}
12
13[[nodiscard]] 10[[nodiscard]]
14bool Memory::Initialize(const std::wstring& processName) { 11bool Memory::Initialize(const std::wstring& processName) {
15 // First, get the handle of the process 12 // First, get the handle of the process
@@ -48,23 +45,40 @@ bool Memory::Initialize(const std::wstring& processName) {
48 return true; 45 return true;
49} 46}
50 47
51Memory::~Memory() { 48ProcStatus Memory::Heartbeat(const std::wstring& processName) {
52 if (_handle != nullptr) { 49 if (!_handle && !Initialize(processName)) {
53 CloseHandle(_handle); 50 // Couldn't initialize, definitely not running
51 return ProcStatus::NotRunning;
52 }
53
54 DWORD exitCode = 0;
55 GetExitCodeProcess(_handle, &exitCode);
56 if (exitCode != STILL_ACTIVE) {
57 // Process has exited, clean up.
58 _computedAddresses.clear();
59 _handle = NULL;
60 return ProcStatus::NotRunning;
54 } 61 }
55}
56 62
57int Memory::GetCurrentFrame() { 63 int currentFrame = 0x7FFFFFFF;
58 int SCRIPT_FRAMES;
59 if (GLOBALS == 0x5B28C0) { 64 if (GLOBALS == 0x5B28C0) {
60 SCRIPT_FRAMES = 0x5BE3B0; 65 currentFrame = ReadData<int>({0x5BE3B0}, 1)[0];
61 } else if (GLOBALS == 0x62D0A0) { 66 } else if (GLOBALS == 0x62D0A0) {
62 SCRIPT_FRAMES = 0x63954C; 67 currentFrame = ReadData<int>({0x63954C}, 1)[0];
63 } else { 68 } else {
64 assert(false); 69 assert(false);
65 return 0x7FFFFFFF;
66 } 70 }
67 return ReadData<int>({SCRIPT_FRAMES}, 1)[0]; 71 if (currentFrame < 80) return ProcStatus::NewGame;
72
73 // TODO: Some way to return ProcStatus::Randomized vs ProcStatus::NotRandomized vs ProcStatus::DeRandomized;
74
75 return ProcStatus::Running;
76}
77
78Memory::~Memory() {
79 if (_handle != nullptr) {
80 CloseHandle(_handle);
81 }
68} 82}
69 83
70void Memory::AddSigScan(const std::vector<byte>& scanBytes, const std::function<void(int index)>& scanFunc) 84void Memory::AddSigScan(const std::vector<byte>& scanBytes, const std::function<void(int index)>& scanFunc)