From b4328af638852e57ff2d75836266d887700bee1e Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 21 Aug 2021 23:29:29 -0400 Subject: Backported some of sigma's stuff --- App/Main.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'App') diff --git a/App/Main.cpp b/App/Main.cpp index f0f770a..54d876d 100644 --- a/App/Main.cpp +++ b/App/Main.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include "Richedit.h" #include "Version.h" +#include #include "Memory.h" #include "Random.h" @@ -124,6 +125,29 @@ HWND CreateCheckbox(int x, int y, int message) { } #pragma warning(pop) +int findGlobals() { + int address = 0; + for (int i = 0x620000; i < 0x660000; i += 4) { + Memory::GLOBALS = i; + try { + if ((address = g_witnessProc->ReadPanelData(0x17E52, STYLE_FLAGS, 1)[0]) == 0x0000A040) { + return i; + } + } + catch (std::exception) {} + } + for (int i = 0x600000; i < 0x620000; i += 4) { + Memory::GLOBALS = i; + try { + if ((address = g_witnessProc->ReadPanelData(0x17E52, STYLE_FLAGS, 1)[0]) == 0x0000A040) { + return i; + } + } + catch (std::exception) {} + } + return 0; +} + int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { LoadLibrary(L"Msftedit.dll"); WNDCLASSW wndClass = { @@ -140,6 +164,40 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance }; RegisterClassW(&wndClass); + //Initialize memory globals constant depending on game version + for (int g : Memory::globalsTests) { + try { + Memory::GLOBALS = g; + if (g_witnessProc->ReadPanelData(0x17E52, STYLE_FLAGS) != 0xA040) throw std::exception(); + break; + } + catch (std::exception) { Memory::GLOBALS = 0; } + } + if (!Memory::GLOBALS) { + std::ifstream file("globals.txt"); + if (file.is_open()) { + file >> std::hex >> Memory::GLOBALS; + } + else { + std::string str = "Globals ptr not found. Press OK to search for globals ptr. It will probably take around 5 minutes. This popup will close and the calculation will run in the background. Please keep The Witness open during this time."; + if (MessageBox(GetActiveWindow(), std::wstring(str.begin(), str.end()).c_str(), NULL, MB_OK) != IDOK) return 0; + int address = findGlobals(); + if (address) { + std::stringstream ss; ss << std::hex << "Address found: 0x" << address << ". This address wil be automatically loaded next time. Please post an issue on Github with this address so that it can be added in the future."; + std::string str = ss.str(); + MessageBox(GetActiveWindow(), std::wstring(str.begin(), str.end()).c_str(), NULL, MB_OK); + std::ofstream ofile("globals.txt", std::ofstream::app); + ofile << std::hex << address << std::endl; + } + else { + str = "Address could not be found. Please post an issue on the Github page."; + MessageBox(GetActiveWindow(), std::wstring(str.begin(), str.end()).c_str(), NULL, MB_OK); + return 0; + } + } + } + + g_hInstance = hInstance; RECT rect; -- cgit 1.4.1