diff options
-rw-r--r-- | App/App.vcxproj | 10 | ||||
-rw-r--r-- | App/Main.cpp | 247 | ||||
-rw-r--r-- | Source/Memory.cpp | 24 | ||||
-rw-r--r-- | Source/Memory.h | 3 | ||||
-rw-r--r-- | Source/Randomizer.cpp | 63 | ||||
-rw-r--r-- | Source/Randomizer.h | 2 | ||||
-rw-r--r-- | Source/Source.vcxproj | 20 | ||||
-rw-r--r-- | Test/Test.vcxproj | 9 |
8 files changed, 155 insertions, 223 deletions
diff --git a/App/App.vcxproj b/App/App.vcxproj index 9b10e92..698d364 100644 --- a/App/App.vcxproj +++ b/App/App.vcxproj | |||
@@ -23,32 +23,32 @@ | |||
23 | <ProjectGuid>{235D27F1-9907-489B-8D58-636A0C5CD079}</ProjectGuid> | 23 | <ProjectGuid>{235D27F1-9907-489B-8D58-636A0C5CD079}</ProjectGuid> |
24 | <Keyword>Win32Proj</Keyword> | 24 | <Keyword>Win32Proj</Keyword> |
25 | <RootNamespace>App</RootNamespace> | 25 | <RootNamespace>App</RootNamespace> |
26 | <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion> | 26 | <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> |
27 | </PropertyGroup> | 27 | </PropertyGroup> |
28 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | 28 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> |
29 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | 29 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> |
30 | <ConfigurationType>Application</ConfigurationType> | 30 | <ConfigurationType>Application</ConfigurationType> |
31 | <UseDebugLibraries>true</UseDebugLibraries> | 31 | <UseDebugLibraries>true</UseDebugLibraries> |
32 | <PlatformToolset>v141</PlatformToolset> | 32 | <PlatformToolset>v142</PlatformToolset> |
33 | <CharacterSet>Unicode</CharacterSet> | 33 | <CharacterSet>Unicode</CharacterSet> |
34 | </PropertyGroup> | 34 | </PropertyGroup> |
35 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | 35 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> |
36 | <ConfigurationType>Application</ConfigurationType> | 36 | <ConfigurationType>Application</ConfigurationType> |
37 | <UseDebugLibraries>false</UseDebugLibraries> | 37 | <UseDebugLibraries>false</UseDebugLibraries> |
38 | <PlatformToolset>v141</PlatformToolset> | 38 | <PlatformToolset>v142</PlatformToolset> |
39 | <WholeProgramOptimization>true</WholeProgramOptimization> | 39 | <WholeProgramOptimization>true</WholeProgramOptimization> |
40 | <CharacterSet>Unicode</CharacterSet> | 40 | <CharacterSet>Unicode</CharacterSet> |
41 | </PropertyGroup> | 41 | </PropertyGroup> |
42 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | 42 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> |
43 | <ConfigurationType>Application</ConfigurationType> | 43 | <ConfigurationType>Application</ConfigurationType> |
44 | <UseDebugLibraries>true</UseDebugLibraries> | 44 | <UseDebugLibraries>true</UseDebugLibraries> |
45 | <PlatformToolset>v141</PlatformToolset> | 45 | <PlatformToolset>v142</PlatformToolset> |
46 | <CharacterSet>Unicode</CharacterSet> | 46 | <CharacterSet>Unicode</CharacterSet> |
47 | </PropertyGroup> | 47 | </PropertyGroup> |
48 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | 48 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> |
49 | <ConfigurationType>Application</ConfigurationType> | 49 | <ConfigurationType>Application</ConfigurationType> |
50 | <UseDebugLibraries>false</UseDebugLibraries> | 50 | <UseDebugLibraries>false</UseDebugLibraries> |
51 | <PlatformToolset>v141</PlatformToolset> | 51 | <PlatformToolset>v142</PlatformToolset> |
52 | <WholeProgramOptimization>true</WholeProgramOptimization> | 52 | <WholeProgramOptimization>true</WholeProgramOptimization> |
53 | <CharacterSet>Unicode</CharacterSet> | 53 | <CharacterSet>Unicode</CharacterSet> |
54 | </PropertyGroup> | 54 | </PropertyGroup> |
diff --git a/App/Main.cpp b/App/Main.cpp index 82600bf..2484577 100644 --- a/App/Main.cpp +++ b/App/Main.cpp | |||
@@ -1,15 +1,15 @@ | |||
1 | #include "windows.h" | 1 | #include "Windows.h" |
2 | #include <Richedit.h> | 2 | #include "Richedit.h" |
3 | #include "Version.h" | ||
3 | 4 | ||
4 | #include <string> | 5 | #include <cassert> |
5 | #include <sstream> | 6 | #include <iostream> |
6 | 7 | ||
7 | #include "Version.h" | 8 | #include "Memory.h" |
8 | #include "Random.h" | 9 | |
9 | #include "Randomizer.h" | 10 | #define EXE_NAME L"witness64_d3d11.exe" |
10 | #include "Panel.h" | ||
11 | 11 | ||
12 | #define IDC_RANDOMIZE 0x401 | 12 | #define PROC_ATTACH 0x401 |
13 | #define IDC_TOGGLESPEED 0x402 | 13 | #define IDC_TOGGLESPEED 0x402 |
14 | #define IDC_SPEEDRUNNER 0x403 | 14 | #define IDC_SPEEDRUNNER 0x403 |
15 | #define IDC_HARDMODE 0x404 | 15 | #define IDC_HARDMODE 0x404 |
@@ -21,102 +21,56 @@ | |||
21 | #define IDC_TOGGLELASERS 0x410 | 21 | #define IDC_TOGGLELASERS 0x410 |
22 | #define IDC_TOGGLESNIPES 0x411 | 22 | #define IDC_TOGGLESNIPES 0x411 |
23 | 23 | ||
24 | HWND hwndSeed, hwndRandomize; | 24 | // Globals |
25 | // int panel = 0x18AF; | 25 | HWND g_hwnd; |
26 | int panel = 0x33D4; | 26 | HINSTANCE g_hInstance; |
27 | std::shared_ptr<Panel> _panel; | 27 | auto g_witnessProc = std::make_shared<Memory>(); |
28 | std::shared_ptr<Randomizer> randomizer = std::make_shared<Randomizer>(); | ||
29 | |||
30 | LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) | ||
31 | { | ||
32 | static bool seedIsRNG = false; | ||
33 | 28 | ||
29 | LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { | ||
34 | if (message == WM_DESTROY) { | 30 | if (message == WM_DESTROY) { |
35 | PostQuitMessage(0); | 31 | PostQuitMessage(0); |
36 | } else if (message == WM_COMMAND || message == WM_TIMER) { | 32 | } else if (message == WM_COMMAND) { |
37 | switch (HIWORD(wParam)) { | 33 | switch (LOWORD(wParam)) { |
38 | // Seed contents changed | 34 | case PROC_ATTACH: |
39 | case EN_CHANGE: | 35 | if (!g_witnessProc->Initialize(EXE_NAME)) { |
40 | seedIsRNG = false; | 36 | OutputDebugString(L"Failed to initialize, trying again in 5 seconds"); |
41 | } | 37 | SetTimer(g_hwnd, PROC_ATTACH, 5000, NULL); // Re-attach in 10s |
42 | switch (LOWORD(wParam)) { | 38 | } |
43 | // Checkboxes | 39 | break; |
44 | case IDC_TOGGLESPEED: | 40 | case IDC_TOGGLELASERS: |
45 | CheckDlgButton(hwnd, IDC_TOGGLESPEED, !IsDlgButtonChecked(hwnd, IDC_TOGGLESPEED)); | 41 | OutputDebugString(L"Hello, world!"); |
46 | break; | 42 | break; |
47 | case IDC_TOGGLELASERS: | 43 | default: |
48 | CheckDlgButton(hwnd, IDC_TOGGLELASERS, !IsDlgButtonChecked(hwnd, IDC_TOGGLELASERS)); | 44 | assert(false); |
49 | break; | 45 | break; |
50 | case IDC_TOGGLESNIPES: | 46 | } |
51 | CheckDlgButton(hwnd, IDC_TOGGLESNIPES, !IsDlgButtonChecked(hwnd, IDC_TOGGLESNIPES)); | 47 | } |
52 | break; | ||
53 | |||
54 | // Randomize button | ||
55 | case IDC_RANDOMIZE: | ||
56 | { | ||
57 | std::wstring text; | ||
58 | text.reserve(100); | ||
59 | GetWindowText(hwndSeed, &text[0], 100); | ||
60 | int seed = _wtoi(text.c_str()); | ||
61 | |||
62 | // TODO: text needs to be resized! | ||
63 | if (seedIsRNG || wcslen(text.c_str()) == 0) { | ||
64 | seed = Random::RandInt(0, 100000); | ||
65 | seedIsRNG = true; | ||
66 | } | ||
67 | |||
68 | randomizer->ClearOffsets(); | ||
69 | /* TODO: | ||
70 | if (!randomizer->GameIsRunning()) { | ||
71 | randomizer->StartGame(); // Try: CreateProcess(L"/path/to/TW.exe", ...); | ||
72 | } | ||
73 | */ | ||
74 | if (randomizer->GameIsRandomized()) break; | ||
75 | Random::SetSeed(seed); | ||
76 | |||
77 | // Show seed and force redraw | ||
78 | std::wstring seedString = std::to_wstring(seed); | ||
79 | SetWindowText(hwndRandomize, L"Randomizing..."); | ||
80 | SetWindowText(hwndSeed, seedString.c_str()); | ||
81 | RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW); | ||
82 | |||
83 | // Randomize, then apply settings | ||
84 | randomizer->Randomize(); | ||
85 | if (IsDlgButtonChecked(hwnd, IDC_TOGGLESPEED)) randomizer->AdjustSpeed(); | ||
86 | if (IsDlgButtonChecked(hwnd, IDC_TOGGLELASERS)) randomizer->RandomizeLasers(); | ||
87 | if (IsDlgButtonChecked(hwnd, IDC_TOGGLESNIPES)) randomizer->PreventSnipes(); | ||
88 | |||
89 | // Cleanup, and set timer for "randomization done" | ||
90 | SetWindowText(hwndRandomize, L"Randomized!"); | ||
91 | SetTimer(hwnd, IDT_RANDOMIZED, 10000, NULL); | ||
92 | break; | ||
93 | } | ||
94 | |||
95 | case IDT_RANDOMIZED: | ||
96 | SetWindowText(hwndRandomize, L"Randomize"); | ||
97 | randomizer->GameIsRandomized(); // "Check" if the game is randomized to update the last known safe frame. | ||
98 | break; | ||
99 | case IDC_READ: | ||
100 | _panel = std::make_shared<Panel>(panel); | ||
101 | break; | ||
102 | case IDC_RANDOM: | ||
103 | _panel->Random(); | ||
104 | break; | ||
105 | case IDC_WRITE: | ||
106 | _panel->Write(panel); | ||
107 | break; | ||
108 | case IDC_DUMP: | ||
109 | _panel->Serialize(); | ||
110 | break; | ||
111 | } | ||
112 | } | ||
113 | return DefWindowProc(hwnd, message, wParam, lParam); | 48 | return DefWindowProc(hwnd, message, wParam, lParam); |
114 | } | 49 | } |
115 | 50 | ||
116 | int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) | 51 | void CreateLabel(int x, int y, int width, LPCWSTR text) { |
117 | { | 52 | CreateWindow(L"STATIC", text, |
118 | LoadLibrary(L"Msftedit.dll"); | 53 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, |
54 | x, y, width, 16, g_hwnd, NULL, g_hInstance, NULL); | ||
55 | } | ||
56 | |||
57 | void CreateButton(int x, int y, int width, LPCWSTR text, int message) { | ||
58 | #pragma warning(push) | ||
59 | #pragma warning(disable: 4312) | ||
60 | CreateWindow(L"BUTTON", text, | ||
61 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, | ||
62 | x, y, width, 26, g_hwnd, (HMENU)message, g_hInstance, NULL); | ||
63 | #pragma warning(pop) | ||
64 | } | ||
65 | |||
66 | /* | ||
67 | hwndSeed = CreateWindow(MSFTEDIT_CLASS, L"", | ||
68 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | WS_BORDER, | ||
69 | 100, 10, 50, 26, hwnd, NULL, hInstance, NULL); | ||
70 | */ | ||
119 | 71 | ||
72 | int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { | ||
73 | LoadLibrary(L"Msftedit.dll"); | ||
120 | WNDCLASSW wndClass = { | 74 | WNDCLASSW wndClass = { |
121 | CS_HREDRAW | CS_VREDRAW, | 75 | CS_HREDRAW | CS_VREDRAW, |
122 | WndProc, | 76 | WndProc, |
@@ -131,101 +85,22 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd | |||
131 | }; | 85 | }; |
132 | RegisterClassW(&wndClass); | 86 | RegisterClassW(&wndClass); |
133 | 87 | ||
88 | g_hInstance = hInstance; | ||
89 | |||
134 | RECT rect; | 90 | RECT rect; |
135 | GetClientRect(GetDesktopWindow(), &rect); | 91 | GetClientRect(GetDesktopWindow(), &rect); |
136 | HWND hwnd = CreateWindow(WINDOW_CLASS, PRODUCT_NAME, WS_OVERLAPPEDWINDOW, | 92 | g_hwnd = CreateWindow(WINDOW_CLASS, PRODUCT_NAME, WS_OVERLAPPEDWINDOW, |
137 | rect.right - 550, 200, 500, 500, nullptr, nullptr, hInstance, nullptr); | 93 | rect.right - 550, 200, 500, 500, nullptr, nullptr, hInstance, nullptr); |
138 | 94 | ||
139 | CreateWindow(L"STATIC", L"Version: " VERSION_STR, | 95 | CreateLabel(390, 15, 90, L"Version: " VERSION_STR); |
140 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, | 96 | CreateButton(10, 72, 100, L"Button text", IDC_TOGGLELASERS); |
141 | 390, 15, 90, 16, hwnd, NULL, hInstance, NULL); | 97 | PostMessage(g_hwnd, WM_COMMAND, PROC_ATTACH, NULL); |
142 | |||
143 | CreateWindow(L"STATIC", L"Enter a seed:", | ||
144 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, | ||
145 | 10, 15, 90, 16, hwnd, NULL, hInstance, NULL); | ||
146 | hwndSeed = CreateWindow(MSFTEDIT_CLASS, L"", | ||
147 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | WS_BORDER, | ||
148 | 100, 10, 50, 26, hwnd, NULL, hInstance, NULL); | ||
149 | SendMessage(hwndSeed, EM_SETEVENTMASK, NULL, ENM_CHANGE); // Notify on text change | ||
150 | |||
151 | hwndRandomize = CreateWindow(L"BUTTON", L"Randomize", | ||
152 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, | ||
153 | 160, 10, 110, 26, hwnd, (HMENU)IDC_RANDOMIZE, hInstance, NULL); | ||
154 | |||
155 | #if GLOBALS == 0x5B28C0 | ||
156 | CreateWindow(L"BUTTON", L"READ", | ||
157 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, | ||
158 | 160, 100, 100, 26, hwnd, (HMENU)IDC_READ, hInstance, NULL); | ||
159 | CreateWindow(L"BUTTON", L"RANDOM", | ||
160 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, | ||
161 | 160, 130, 100, 26, hwnd, (HMENU)IDC_RANDOM, hInstance, NULL); | ||
162 | CreateWindow(L"BUTTON", L"WRITE", | ||
163 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, | ||
164 | 160, 160, 100, 26, hwnd, (HMENU)IDC_WRITE, hInstance, NULL); | ||
165 | CreateWindow(L"BUTTON", L"DUMP", | ||
166 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, | ||
167 | 160, 190, 100, 26, hwnd, (HMENU)IDC_DUMP, hInstance, NULL); | ||
168 | #endif | ||
169 | |||
170 | CreateWindow(L"BUTTON", L"", | ||
171 | WS_VISIBLE | WS_CHILD | BS_CHECKBOX, | ||
172 | 10, 52, 12, 12, hwnd, (HMENU)IDC_TOGGLESPEED, hInstance, NULL); | ||
173 | CreateWindow(L"STATIC", L"Speed up various autoscrollers", | ||
174 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, | ||
175 | 27, 50, 210, 16, hwnd, NULL, hInstance, NULL); | ||
176 | |||
177 | CreateWindow(L"BUTTON", L"", | ||
178 | WS_VISIBLE | WS_CHILD | BS_CHECKBOX, | ||
179 | 10, 72, 12, 12, hwnd, (HMENU)IDC_TOGGLELASERS, hInstance, NULL); | ||
180 | CreateWindow(L"STATIC", L"Randomize laser activations", | ||
181 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, | ||
182 | 27, 70, 210, 16, hwnd, NULL, hInstance, NULL); | ||
183 | |||
184 | CreateWindow(L"BUTTON", L"", | ||
185 | WS_VISIBLE | WS_CHILD | BS_CHECKBOX, | ||
186 | 10, 92, 12, 12, hwnd, (HMENU)IDC_TOGGLESNIPES, hInstance, NULL); | ||
187 | CheckDlgButton(hwnd, IDC_TOGGLESNIPES, TRUE); | ||
188 | CreateWindow(L"STATIC", L"Prevent sniping certain puzzles", | ||
189 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, | ||
190 | 27, 90, 210, 16, hwnd, NULL, hInstance, NULL); | ||
191 | |||
192 | /* | ||
193 | CreateWindow(L"BUTTON", L"", | ||
194 | WS_VISIBLE | WS_CHILD | BS_CHECKBOX, | ||
195 | 10, 52, 12, 12, hwnd, (HMENU)IDC_SPEEDRUNNER, hInstance, NULL); | ||
196 | CreateWindow(L"STATIC", L"Allow hard-to-identify panels to be shuffled", | ||
197 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, | ||
198 | 27, 50, 205, 16, hwnd, NULL, hInstance, NULL); | ||
199 | |||
200 | CreateWindow(L"BUTTON", L"", | ||
201 | WS_VISIBLE | WS_CHILD | BS_CHECKBOX, | ||
202 | 10, 52, 12, 12, hwnd, (HMENU)IDC_HARDMODE, hInstance, NULL); | ||
203 | CreateWindow(L"STATIC", L"Place harder puzzles in annoying spots", | ||
204 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, | ||
205 | 27, 50, 205, 16, hwnd, NULL, hInstance, NULL); | ||
206 | |||
207 | CreateWindow(L"BUTTON", L"", | ||
208 | WS_VISIBLE | WS_CHILD | BS_CHECKBOX, | ||
209 | 10, 52, 12, 12, hwnd, (HMENU)IDC_NORANDOMIZE, hInstance, NULL); | ||
210 | CreateWindow(L"STATIC", L"Do not randomize any puzzles", | ||
211 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, | ||
212 | 27, 50, 205, 16, hwnd, NULL, hInstance, NULL); | ||
213 | |||
214 | CreateWindow(L"BUTTON", L"", | ||
215 | WS_VISIBLE | WS_CHILD | BS_CHECKBOX, | ||
216 | 10, 52, 12, 12, hwnd, (HMENU)IDC_CASUAL, hInstance, NULL); | ||
217 | CreateWindow(L"STATIC", L"Don't randomize context-based puzzles", | ||
218 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, | ||
219 | 27, 50, 205, 16, hwnd, NULL, hInstance, NULL); | ||
220 | |||
221 | */ | ||
222 | 98 | ||
223 | ShowWindow(hwnd, nCmdShow); | 99 | ShowWindow(g_hwnd, nCmdShow); |
224 | UpdateWindow(hwnd); | 100 | UpdateWindow(g_hwnd); |
225 | 101 | ||
226 | MSG msg; | 102 | MSG msg; |
227 | while (!GetMessage(&msg, nullptr, 0, 0) == 0) | 103 | while (GetMessage(&msg, nullptr, 0, 0) == TRUE) { |
228 | { | ||
229 | TranslateMessage(&msg); | 104 | TranslateMessage(&msg); |
230 | DispatchMessage(&msg); | 105 | DispatchMessage(&msg); |
231 | } | 106 | } |
diff --git a/Source/Memory.cpp b/Source/Memory.cpp index 7bc3b2f..1f1ae0a 100644 --- a/Source/Memory.cpp +++ b/Source/Memory.cpp | |||
@@ -6,12 +6,16 @@ | |||
6 | #undef PROCESSENTRY32 | 6 | #undef PROCESSENTRY32 |
7 | #undef Process32Next | 7 | #undef Process32Next |
8 | 8 | ||
9 | Memory::Memory(const std::string& processName) { | 9 | Memory::Memory() { |
10 | } | ||
11 | |||
12 | [[nodiscard]] | ||
13 | bool Memory::Initialize(const std::wstring& processName) { | ||
10 | // First, get the handle of the process | 14 | // First, get the handle of the process |
11 | PROCESSENTRY32 entry; | 15 | PROCESSENTRY32W entry; |
12 | entry.dwSize = sizeof(entry); | 16 | entry.dwSize = sizeof(entry); |
13 | HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); | 17 | HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
14 | while (Process32Next(snapshot, &entry)) { | 18 | while (Process32NextW(snapshot, &entry)) { |
15 | if (processName == entry.szExeFile) { | 19 | if (processName == entry.szExeFile) { |
16 | _handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID); | 20 | _handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID); |
17 | break; | 21 | break; |
@@ -19,7 +23,7 @@ Memory::Memory(const std::string& processName) { | |||
19 | } | 23 | } |
20 | if (!_handle) { | 24 | if (!_handle) { |
21 | std::cerr << "Couldn't find " << processName.c_str() << ", is it open?" << std::endl; | 25 | std::cerr << "Couldn't find " << processName.c_str() << ", is it open?" << std::endl; |
22 | throw std::exception("Unable to find process!"); | 26 | return false; |
23 | } | 27 | } |
24 | 28 | ||
25 | // Next, get the process base address | 29 | // Next, get the process base address |
@@ -27,9 +31,9 @@ Memory::Memory(const std::string& processName) { | |||
27 | std::vector<HMODULE> moduleList(1024); | 31 | std::vector<HMODULE> moduleList(1024); |
28 | EnumProcessModulesEx(_handle, &moduleList[0], static_cast<DWORD>(moduleList.size()), &numModules, 3); | 32 | EnumProcessModulesEx(_handle, &moduleList[0], static_cast<DWORD>(moduleList.size()), &numModules, 3); |
29 | 33 | ||
30 | std::string name(64, '\0'); | 34 | std::wstring name(64, '\0'); |
31 | for (DWORD i = 0; i < numModules / sizeof(HMODULE); i++) { | 35 | for (DWORD i = 0; i < numModules / sizeof(HMODULE); i++) { |
32 | int length = GetModuleBaseNameA(_handle, moduleList[i], &name[0], static_cast<DWORD>(name.size())); | 36 | int length = GetModuleBaseNameW(_handle, moduleList[i], &name[0], static_cast<DWORD>(name.size())); |
33 | name.resize(length); | 37 | name.resize(length); |
34 | if (processName == name) { | 38 | if (processName == name) { |
35 | _baseAddress = (uintptr_t)moduleList[i]; | 39 | _baseAddress = (uintptr_t)moduleList[i]; |
@@ -37,12 +41,16 @@ Memory::Memory(const std::string& processName) { | |||
37 | } | 41 | } |
38 | } | 42 | } |
39 | if (_baseAddress == 0) { | 43 | if (_baseAddress == 0) { |
40 | throw std::exception("Couldn't find the base process address!"); | 44 | std::cerr << "Couldn't locate base address" << std::endl; |
45 | return false; | ||
41 | } | 46 | } |
47 | return true; | ||
42 | } | 48 | } |
43 | 49 | ||
44 | Memory::~Memory() { | 50 | Memory::~Memory() { |
45 | CloseHandle(_handle); | 51 | if (_handle != nullptr) { |
52 | CloseHandle(_handle); | ||
53 | } | ||
46 | } | 54 | } |
47 | 55 | ||
48 | int Memory::GetCurrentFrame() | 56 | int Memory::GetCurrentFrame() |
diff --git a/Source/Memory.h b/Source/Memory.h index cce06ba..9c00dab 100644 --- a/Source/Memory.h +++ b/Source/Memory.h | |||
@@ -14,7 +14,8 @@ | |||
14 | class Memory | 14 | class Memory |
15 | { | 15 | { |
16 | public: | 16 | public: |
17 | Memory(const std::string& processName); | 17 | Memory(); |
18 | bool Initialize(const std::wstring& processName); | ||
18 | ~Memory(); | 19 | ~Memory(); |
19 | 20 | ||
20 | Memory(const Memory& memory) = delete; | 21 | Memory(const Memory& memory) = delete; |
diff --git a/Source/Randomizer.cpp b/Source/Randomizer.cpp index 5e57ca3..71ec89b 100644 --- a/Source/Randomizer.cpp +++ b/Source/Randomizer.cpp | |||
@@ -1,4 +1,67 @@ | |||
1 | /* | 1 | /* |
2 | Things to do for V2: | ||
3 | - Better interface design. It's way too simplistic, take (some) notes from talos. | ||
4 | - Seed: [ ] (Randomize) | ||
5 | ?? Challenge | ||
6 | |||
7 | - [] Prevent speedrun snipes // Shadows, Swamp, Town, Quarry stairs | ||
8 | - [] Speed up various autoscrollers // Swamp platforms, Desert/Mountain elevators, Desert rotating panels | ||
9 | |||
10 | (Additional required panels) | ||
11 | - [] Desert 8 | ||
12 | - [] Pond 5 | ||
13 | - [] Both keep halves | ||
14 | - [] Town lattice requires stars door // and stars door will be randomized | ||
15 | |||
16 | (Debug version only) | ||
17 | - [] Noclip | ||
18 | - [] Noclip speed | ||
19 | |||
20 | |||
21 | - Really randomize panels. Sorted by ROI | ||
22 | - Random with style | ||
23 | - Tutorial | ||
24 | - Mountain 1 orange, green, blue, purple | ||
25 | - Mountain 2 multipanel | ||
26 | - Mountain 3 pillars | ||
27 | - Laser areas (Glass Factory, Symmetry, Quarry, Treehouse, Swamp, Keep pressure plates, Town 25 dots) | ||
28 | - (low) Discarded panels | ||
29 | - (low) Tutorials // Dots, Stones, Swamp | ||
30 | |||
31 | - Keep Hedges become like hedges 4, intersection between path and panel | ||
32 | - Keep Pressure plates: Random with style | ||
33 | |||
34 | - No idea how to randomize: | ||
35 | - Symmetry transparent | ||
36 | - Desert | ||
37 | - Shadows | ||
38 | - Town (lattice, RGB area, snipes, triple) | ||
39 | - Monastery | ||
40 | - Jungle | ||
41 | - Bunker | ||
42 | - UTM | ||
43 | - Mountain 2 rainbow | ||
44 | - Challenge | ||
45 | |||
46 | - Any RNG rerolls should be based on previous seed so that everyone can go to next seed easily | ||
47 | |||
48 | - Stability. Duh. I need to clearly define the ownership between the randomizer and the game. | ||
49 | |||
50 | - Challenge should have some way to 'reroll every run' | ||
51 | - Challenge should not turn off after time limit? | ||
52 | - Challenge triangles should not turn off | ||
53 | |||
54 | |||
55 | |||
56 | |||
57 | */ | ||
58 | |||
59 | |||
60 | |||
61 | |||
62 | |||
63 | |||
64 | /* | ||
2 | * Try to wire up both keep halves | 65 | * Try to wire up both keep halves |
3 | * Wire up both halves of symmetry laser | 66 | * Wire up both halves of symmetry laser |
4 | * Turn off floating panel in desert | 67 | * Turn off floating panel in desert |
diff --git a/Source/Randomizer.h b/Source/Randomizer.h index 6029513..020851b 100644 --- a/Source/Randomizer.h +++ b/Source/Randomizer.h | |||
@@ -45,7 +45,7 @@ private: | |||
45 | void ReassignTargets(const std::vector<int>& panels, const std::vector<int>& order, std::vector<int> targets = {}); | 45 | void ReassignTargets(const std::vector<int>& panels, const std::vector<int>& order, std::vector<int> targets = {}); |
46 | void ReassignNames(const std::vector<int>& panels, const std::vector<int>& order); | 46 | void ReassignNames(const std::vector<int>& panels, const std::vector<int>& order); |
47 | 47 | ||
48 | std::shared_ptr<Memory> _memory = std::make_shared<Memory>("witness64_d3d11.exe"); | 48 | std::shared_ptr<Memory> _memory = std::make_shared<Memory>(L"witness64_d3d11.exe"); |
49 | 49 | ||
50 | friend class SwapTests_Shipwreck_Test; | 50 | friend class SwapTests_Shipwreck_Test; |
51 | }; | 51 | }; |
diff --git a/Source/Source.vcxproj b/Source/Source.vcxproj index cf6756a..3e66f83 100644 --- a/Source/Source.vcxproj +++ b/Source/Source.vcxproj | |||
@@ -23,32 +23,32 @@ | |||
23 | <ProjectGuid>{6B5DF051-A51A-48CB-8ACD-C6FAD726019F}</ProjectGuid> | 23 | <ProjectGuid>{6B5DF051-A51A-48CB-8ACD-C6FAD726019F}</ProjectGuid> |
24 | <Keyword>Win32Proj</Keyword> | 24 | <Keyword>Win32Proj</Keyword> |
25 | <RootNamespace>Source</RootNamespace> | 25 | <RootNamespace>Source</RootNamespace> |
26 | <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion> | 26 | <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> |
27 | </PropertyGroup> | 27 | </PropertyGroup> |
28 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | 28 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> |
29 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | 29 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> |
30 | <ConfigurationType>StaticLibrary</ConfigurationType> | 30 | <ConfigurationType>StaticLibrary</ConfigurationType> |
31 | <UseDebugLibraries>true</UseDebugLibraries> | 31 | <UseDebugLibraries>true</UseDebugLibraries> |
32 | <PlatformToolset>v141</PlatformToolset> | 32 | <PlatformToolset>v142</PlatformToolset> |
33 | <CharacterSet>Unicode</CharacterSet> | 33 | <CharacterSet>Unicode</CharacterSet> |
34 | </PropertyGroup> | 34 | </PropertyGroup> |
35 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | 35 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> |
36 | <ConfigurationType>StaticLibrary</ConfigurationType> | 36 | <ConfigurationType>StaticLibrary</ConfigurationType> |
37 | <UseDebugLibraries>false</UseDebugLibraries> | 37 | <UseDebugLibraries>false</UseDebugLibraries> |
38 | <PlatformToolset>v141</PlatformToolset> | 38 | <PlatformToolset>v142</PlatformToolset> |
39 | <WholeProgramOptimization>true</WholeProgramOptimization> | 39 | <WholeProgramOptimization>true</WholeProgramOptimization> |
40 | <CharacterSet>Unicode</CharacterSet> | 40 | <CharacterSet>Unicode</CharacterSet> |
41 | </PropertyGroup> | 41 | </PropertyGroup> |
42 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | 42 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> |
43 | <ConfigurationType>StaticLibrary</ConfigurationType> | 43 | <ConfigurationType>StaticLibrary</ConfigurationType> |
44 | <UseDebugLibraries>true</UseDebugLibraries> | 44 | <UseDebugLibraries>true</UseDebugLibraries> |
45 | <PlatformToolset>v141</PlatformToolset> | 45 | <PlatformToolset>v142</PlatformToolset> |
46 | <CharacterSet>Unicode</CharacterSet> | 46 | <CharacterSet>Unicode</CharacterSet> |
47 | </PropertyGroup> | 47 | </PropertyGroup> |
48 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | 48 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> |
49 | <ConfigurationType>StaticLibrary</ConfigurationType> | 49 | <ConfigurationType>StaticLibrary</ConfigurationType> |
50 | <UseDebugLibraries>false</UseDebugLibraries> | 50 | <UseDebugLibraries>false</UseDebugLibraries> |
51 | <PlatformToolset>v141</PlatformToolset> | 51 | <PlatformToolset>v142</PlatformToolset> |
52 | <WholeProgramOptimization>true</WholeProgramOptimization> | 52 | <WholeProgramOptimization>true</WholeProgramOptimization> |
53 | <CharacterSet>Unicode</CharacterSet> | 53 | <CharacterSet>Unicode</CharacterSet> |
54 | </PropertyGroup> | 54 | </PropertyGroup> |
@@ -157,20 +157,10 @@ | |||
157 | </Link> | 157 | </Link> |
158 | </ItemDefinitionGroup> | 158 | </ItemDefinitionGroup> |
159 | <ItemGroup> | 159 | <ItemGroup> |
160 | <ClInclude Include="ChallengeRandomizer.h" /> | ||
161 | <ClInclude Include="json.hpp" /> | ||
162 | <ClInclude Include="Memory.h" /> | 160 | <ClInclude Include="Memory.h" /> |
163 | <ClInclude Include="Panel.h" /> | ||
164 | <ClInclude Include="Panels.h" /> | ||
165 | <ClInclude Include="Random.h" /> | ||
166 | <ClInclude Include="Randomizer.h" /> | ||
167 | </ItemGroup> | 161 | </ItemGroup> |
168 | <ItemGroup> | 162 | <ItemGroup> |
169 | <ClCompile Include="ChallengeRandomizer.cpp" /> | ||
170 | <ClCompile Include="Memory.cpp" /> | 163 | <ClCompile Include="Memory.cpp" /> |
171 | <ClCompile Include="Panel.cpp" /> | ||
172 | <ClCompile Include="Random.cpp" /> | ||
173 | <ClCompile Include="Randomizer.cpp" /> | ||
174 | </ItemGroup> | 164 | </ItemGroup> |
175 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | 165 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> |
176 | <ImportGroup Label="ExtensionTargets"> | 166 | <ImportGroup Label="ExtensionTargets"> |
diff --git a/Test/Test.vcxproj b/Test/Test.vcxproj index 55f3ce8..1beb5a4 100644 --- a/Test/Test.vcxproj +++ b/Test/Test.vcxproj | |||
@@ -21,9 +21,9 @@ | |||
21 | <PropertyGroup Label="Globals"> | 21 | <PropertyGroup Label="Globals"> |
22 | <ProjectGuid>{128784c2-9157-4291-8fd6-44637be162fb}</ProjectGuid> | 22 | <ProjectGuid>{128784c2-9157-4291-8fd6-44637be162fb}</ProjectGuid> |
23 | <Keyword>Win32Proj</Keyword> | 23 | <Keyword>Win32Proj</Keyword> |
24 | <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion> | 24 | <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> |
25 | <ConfigurationType>Application</ConfigurationType> | 25 | <ConfigurationType>Application</ConfigurationType> |
26 | <PlatformToolset>v141</PlatformToolset> | 26 | <PlatformToolset>v142</PlatformToolset> |
27 | <CharacterSet>Unicode</CharacterSet> | 27 | <CharacterSet>Unicode</CharacterSet> |
28 | </PropertyGroup> | 28 | </PropertyGroup> |
29 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | 29 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> |
@@ -33,11 +33,6 @@ | |||
33 | <ImportGroup Label="PropertySheets" /> | 33 | <ImportGroup Label="PropertySheets" /> |
34 | <PropertyGroup Label="UserMacros" /> | 34 | <PropertyGroup Label="UserMacros" /> |
35 | <ItemGroup> | 35 | <ItemGroup> |
36 | <ClCompile Include="PanelExtractionTests.cpp" /> | ||
37 | <ClCompile Include="Temp.cpp" /> | ||
38 | <ClCompile Include="RandomTests.cpp" /> | ||
39 | </ItemGroup> | ||
40 | <ItemGroup> | ||
41 | <ProjectReference Include="..\Source\Source.vcxproj"> | 36 | <ProjectReference Include="..\Source\Source.vcxproj"> |
42 | <Project>{6b5df051-a51a-48cb-8acd-c6fad726019f}</Project> | 37 | <Project>{6b5df051-a51a-48cb-8acd-c6fad726019f}</Project> |
43 | </ProjectReference> | 38 | </ProjectReference> |