about summary refs log tree commit diff stats
path: root/App/Main.cpp
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2021-08-21 23:29:29 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2021-08-21 23:29:29 -0400
commitb4328af638852e57ff2d75836266d887700bee1e (patch)
tree32c0e6b596a86da89659645964ac6c674bb938c4 /App/Main.cpp
parent1591ee64b865c0f432ec3a178cfec80dfbae1e86 (diff)
downloadwitness-tutorializer-b4328af638852e57ff2d75836266d887700bee1e.tar.gz
witness-tutorializer-b4328af638852e57ff2d75836266d887700bee1e.tar.bz2
witness-tutorializer-b4328af638852e57ff2d75836266d887700bee1e.zip
Backported some of sigma's stuff
Diffstat (limited to 'App/Main.cpp')
-rw-r--r--App/Main.cpp58
1 files changed, 58 insertions, 0 deletions
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 @@
1#include "pch.h" 1#include "pch.h"
2#include "Richedit.h" 2#include "Richedit.h"
3#include "Version.h" 3#include "Version.h"
4#include <fstream>
4 5
5#include "Memory.h" 6#include "Memory.h"
6#include "Random.h" 7#include "Random.h"
@@ -124,6 +125,29 @@ HWND CreateCheckbox(int x, int y, int message) {
124} 125}
125#pragma warning(pop) 126#pragma warning(pop)
126 127
128int findGlobals() {
129 int address = 0;
130 for (int i = 0x620000; i < 0x660000; i += 4) {
131 Memory::GLOBALS = i;
132 try {
133 if ((address = g_witnessProc->ReadPanelData<int>(0x17E52, STYLE_FLAGS, 1)[0]) == 0x0000A040) {
134 return i;
135 }
136 }
137 catch (std::exception) {}
138 }
139 for (int i = 0x600000; i < 0x620000; i += 4) {
140 Memory::GLOBALS = i;
141 try {
142 if ((address = g_witnessProc->ReadPanelData<int>(0x17E52, STYLE_FLAGS, 1)[0]) == 0x0000A040) {
143 return i;
144 }
145 }
146 catch (std::exception) {}
147 }
148 return 0;
149}
150
127int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { 151int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) {
128 LoadLibrary(L"Msftedit.dll"); 152 LoadLibrary(L"Msftedit.dll");
129 WNDCLASSW wndClass = { 153 WNDCLASSW wndClass = {
@@ -140,6 +164,40 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance
140 }; 164 };
141 RegisterClassW(&wndClass); 165 RegisterClassW(&wndClass);
142 166
167 //Initialize memory globals constant depending on game version
168 for (int g : Memory::globalsTests) {
169 try {
170 Memory::GLOBALS = g;
171 if (g_witnessProc->ReadPanelData<int>(0x17E52, STYLE_FLAGS) != 0xA040) throw std::exception();
172 break;
173 }
174 catch (std::exception) { Memory::GLOBALS = 0; }
175 }
176 if (!Memory::GLOBALS) {
177 std::ifstream file("globals.txt");
178 if (file.is_open()) {
179 file >> std::hex >> Memory::GLOBALS;
180 }
181 else {
182 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.";
183 if (MessageBox(GetActiveWindow(), std::wstring(str.begin(), str.end()).c_str(), NULL, MB_OK) != IDOK) return 0;
184 int address = findGlobals();
185 if (address) {
186 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.";
187 std::string str = ss.str();
188 MessageBox(GetActiveWindow(), std::wstring(str.begin(), str.end()).c_str(), NULL, MB_OK);
189 std::ofstream ofile("globals.txt", std::ofstream::app);
190 ofile << std::hex << address << std::endl;
191 }
192 else {
193 str = "Address could not be found. Please post an issue on the Github page.";
194 MessageBox(GetActiveWindow(), std::wstring(str.begin(), str.end()).c_str(), NULL, MB_OK);
195 return 0;
196 }
197 }
198 }
199
200
143 g_hInstance = hInstance; 201 g_hInstance = hInstance;
144 202
145 RECT rect; 203 RECT rect;