about summary refs log tree commit diff stats
path: root/WitnessRandomizer
diff options
context:
space:
mode:
Diffstat (limited to 'WitnessRandomizer')
-rw-r--r--WitnessRandomizer/Memory.cpp80
-rw-r--r--WitnessRandomizer/Memory.h51
-rw-r--r--WitnessRandomizer/Panels.h681
-rw-r--r--WitnessRandomizer/WitnessRandomizer.cpp251
-rw-r--r--WitnessRandomizer/WitnessRandomizer.h156
-rw-r--r--WitnessRandomizer/WitnessRandomizer.vcxproj173
-rw-r--r--WitnessRandomizer/WitnessRandomizer.vcxproj.filters36
7 files changed, 0 insertions, 1428 deletions
diff --git a/WitnessRandomizer/Memory.cpp b/WitnessRandomizer/Memory.cpp deleted file mode 100644 index 0afeded..0000000 --- a/WitnessRandomizer/Memory.cpp +++ /dev/null
@@ -1,80 +0,0 @@
1#include "Memory.h"
2#include <psapi.h>
3#include <tlhelp32.h>
4#include <iostream>
5
6#undef PROCESSENTRY32
7#undef Process32Next
8
9Memory::Memory(const std::string& processName) {
10 // First, get the handle of the process
11 PROCESSENTRY32 entry;
12 entry.dwSize = sizeof(entry);
13 HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
14 while (Process32Next(snapshot, &entry)) {
15 if (processName == entry.szExeFile) {
16 _handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID);
17 break;
18 }
19 }
20 if (!_handle) {
21 std::cout << "Couldn't find " << processName.c_str() << ", is it open?" << std::endl;
22 exit(EXIT_FAILURE);
23 }
24
25 // Next, get the process base address
26 DWORD numModules;
27 std::vector<HMODULE> moduleList(1024);
28 EnumProcessModulesEx(_handle, &moduleList[0], static_cast<DWORD>(moduleList.size()), &numModules, 3);
29
30 std::string name(64, 0);
31 for (DWORD i = 0; i < numModules / sizeof(HMODULE); i++) {
32 GetModuleBaseNameA(_handle, moduleList[i], &name[0], sizeof(name));
33
34 // TODO: Filling with 0s still yeilds name.size() == 64...
35 if (strcmp(processName.c_str(), name.c_str()) == 0) {
36 _baseAddress = (uintptr_t)moduleList[i];
37 break;
38 }
39 }
40 if (_baseAddress == 0) {
41 std::cout << "Couldn't find the base process address!" << std::endl;
42 exit(EXIT_FAILURE);
43 }
44}
45
46Memory::~Memory() {
47 CloseHandle(_handle);
48}
49
50void Memory::ThrowError() {
51 std::string message(256, '\0');
52 FormatMessageA(4096, nullptr, GetLastError(), 1024, &message[0], static_cast<DWORD>(message.length()), nullptr);
53 std::cout << message.c_str() << std::endl;
54 exit(EXIT_FAILURE);
55}
56
57void* Memory::ComputeOffset(std::vector<int> offsets)
58{
59 // Leave off the last offset, since it will be either read/write, and may not be of type unitptr_t.
60 int final_offset = offsets.back();
61 offsets.pop_back();
62
63 uintptr_t cumulativeAddress = _baseAddress;
64 for (const int offset : offsets) {
65 cumulativeAddress += offset;
66
67 const auto search = _computedAddresses.find(cumulativeAddress);
68 if (search == std::end(_computedAddresses)) {
69 // If the address is not yet computed, then compute it.
70 uintptr_t computedAddress = 0;
71 if (!ReadProcessMemory(_handle, reinterpret_cast<LPVOID>(cumulativeAddress), &computedAddress, sizeof(uintptr_t), NULL)) {
72 ThrowError();
73 }
74 _computedAddresses[cumulativeAddress] = computedAddress;
75 }
76
77 cumulativeAddress = _computedAddresses[cumulativeAddress];
78 }
79 return reinterpret_cast<void*>(cumulativeAddress + final_offset);
80}
diff --git a/WitnessRandomizer/Memory.h b/WitnessRandomizer/Memory.h deleted file mode 100644 index 8e8bbc3..0000000 --- a/WitnessRandomizer/Memory.h +++ /dev/null
@@ -1,51 +0,0 @@
1#pragma once
2#include <vector>
3#include <map>
4#include <windows.h>
5
6// https://github.com/erayarslan/WriteProcessMemory-Example
7// http://stackoverflow.com/q/32798185
8// http://stackoverflow.com/q/36018838
9// http://stackoverflow.com/q/1387064
10class Memory
11{
12public:
13 Memory(const std::string& processName);
14 ~Memory();
15
16 Memory(const Memory& memory) = delete;
17 Memory& operator=(const Memory& other) = delete;
18
19 template<class T>
20 std::vector<T> ReadData(const std::vector<int>& offsets, size_t numItems) {
21 std::vector<T> data;
22 data.resize(numItems);
23 for (int i=0; i<5; i++) {
24 if (ReadProcessMemory(_handle, ComputeOffset(offsets), &data[0], sizeof(T) * numItems, nullptr))
25 {
26 return data;
27 }
28 }
29 ThrowError();
30 return {};
31 }
32
33 template <class T>
34 void WriteData(const std::vector<int>& offsets, const std::vector<T>& data) {
35 for (int i=0; i<5; i++) {
36 if (WriteProcessMemory(_handle, ComputeOffset(offsets), &data[0], sizeof(T) * data.size(), nullptr)) {
37 return;
38 }
39 }
40 ThrowError();
41 }
42
43private:
44 void ThrowError();
45
46 void* ComputeOffset(std::vector<int> offsets);
47
48 std::map<uintptr_t, uintptr_t> _computedAddresses;
49 uintptr_t _baseAddress = 0;
50 HANDLE _handle = nullptr;
51}; \ No newline at end of file
diff --git a/WitnessRandomizer/Panels.h b/WitnessRandomizer/Panels.h deleted file mode 100644 index e070005..0000000 --- a/WitnessRandomizer/Panels.h +++ /dev/null
@@ -1,681 +0,0 @@
1#pragma once
2#include <vector>
3
4// Some of these (the puzzle ones) are duplicated elsewhere
5std::vector<int> lasers = {
6 0x0360D, // Symmetry
7 0x03615, // Swamp
8 0x09DE0, // Bunker
9 0x17CA4, // Monastery
10 0x032F5, // Town
11 0x03613, // Treehouse
12 0x0360E, // Keep Front Laser
13// 0x03317, // Keep Back Laser
14// 0x03608, // Desert
15 0x03612, // Quarry
16 0x03616, // Jungle
17 0x19650, // Shadows
18};
19
20// Note: Some of these (non-desert) are duplicated elsewhere
21std::vector<int> burnablePanels = {
22 0x17D9C, // Treehouse Yellow 7
23 0x17DC2, // Treehouse Yellow 8
24 0x17DC4, // Treehouse Yellow 9
25 0x00999, // Swamp Discontinuous 1
26 0x0099D, // Swamp Discontinuous 2
27 0x009A0, // Swamp Discontinuous 3
28 0x009A1, // Swamp Discontinuous 4
29 0x00007, // Swamp Rotation Tutorial 1
30 0x00008, // Swamp Rotation Tutorial 2
31 0x00009, // Swamp Rotation Tutorial 3
32 0x0000A, // Swamp Rotation Tutorial 4
33 0x28AC7, // Town Blue 1
34 0x28AC8, // Town Blue 2
35 0x28ACA, // Town Blue 3
36 0x28ACB, // Town Blue 4
37 0x28ACC, // Town Blue 5
38 0x17CF0, // Mill Discard
39
40 0x00698, // Desert Surface 1
41 0x0048F, // Desert Surface 2
42 0x09F92, // Desert Surface 3
43 0x0A036, // Desert Surface 4
44 0x09DA6, // Desert Surface 5
45 0x0A049, // Desert Surface 6
46 0x0A053, // Desert Surface 7
47 0x09F94, // Desert Surface 8
48 0x00422, // Desert Light 1
49 0x006E3, // Desert Light 2
50 0x0A02D, // Desert Light 3
51 0x00C72, // Desert Pond 1
52 0x0129D, // Desert Pond 2
53 0x008BB, // Desert Pond 3
54 0x0078D, // Desert Pond 4
55 0x18313, // Desert Pond 5
56 0x04D18, // Desert Flood 1
57 0x01205, // Desert Flood 2
58 0x181AB, // Desert Flood 3
59 0x0117A, // Desert Flood 4
60 0x17ECA, // Desert Flood 5
61 0x012D7, // Desert Final Far
62};
63
64// Note: Some of these (non-controls) are duplicated elsewhere
65// TODO: Gave up
66std::vector<int> leftRightPanels = {
67 0x01A54, // Glass Factory Entry
68 0x00086, // Glass Factory Vertical Symmetry 1
69 0x00087, // Glass Factory Vertical Symmetry 2
70 0x00059, // Glass Factory Vertical Symmetry 3
71 0x00062, // Glass Factory Vertical Symmetry 4
72 0x00025, // Symmetry Island Black Dots 4
73 0x00026, // Symmetry Island Black Dots 5
74 0x00072, // Symmetry Island Fading Lines 3
75
76 0x17D02, // Town Windmill Control
77};
78
79// These panels are very tall (aka not square) and can't take symmetry panels on them.
80std::vector<int> tallUpDownPanels = {
81 0x335AB, // UTM In Elevator Control
82 0x3369D, // UTM Lower Elevator Control
83 0x335AC, // UTM Upper Elevator Control
84 0x09EEB, // Mountain 2 Elevator
85};
86
87// Note: Some of these (non-controls) are duplicated elsewhere
88std::vector<int> upDownPanels = {
89 0x0008D, // Glass Factory Rotational Symmetry 1
90 0x00081, // Glass Factory Rotational Symmetry 2
91 0x00083, // Glass Factory Rotational Symmetry 3
92 0x00084, // Glass Factory Melting 1
93 0x00070, // Symmetry Island Fading Lines 5
94 0x01E5A, // Mill Entry Door Left
95 0x28AC7, // Town Blue 1
96 0x28AC8, // Town Blue 2
97 0x28ACA, // Town Blue 3
98 0x28ACB, // Town Blue 4
99 0x28ACC, // Town Blue 5
100 0x00029, // UTM Invisible Dots Symmetry 3
101
102 0x0A3B5, // Tutorial Back Left
103 0x17CC4, // Mill Elevator Control
104};
105
106// Note: Some of these (non-controls) are duplicated elsewhere
107std::vector<int> leftForwardRightPanels = {
108// 0x00075, // Symmetry Island Colored Dots 3
109// 0x288EA, // UTM Perspective 1
110// 0x288FC, // UTM Perspective 2
111// 0x289E7, // UTM Perspective 3
112
113 0x17DD1, // Treehouse Left Orange 9
114 0x17CE3, // Treehouse Right Orange 4
115 0x17DB7, // Treehouse Right Orange 10
116 0x17E52, // Treehouse Green 4
117};
118
119std::vector<int> pillars = {
120 0x0383D, // Mountain 3 Left Pillar 1
121 0x0383F, // Mountain 3 Left Pillar 2
122 0x03859, // Mountain 3 Left Pillar 3
123 0x339BB, // Mountain 3 Left Pillar 4
124 0x0383A, // Mountain 3 Right Pillar 1
125 0x09E56, // Mountain 3 Right Pillar 2
126 0x09E5A, // Mountain 3 Right Pillar 3
127 0x33961, // Mountain 3 Right Pillar 4
128 0x09DD5, // UTM Challenge Pillar
129// 0x1C31A, // Challenge Left Pillar
130// 0x1C319, // Challenge Right Pillar
131};
132
133std::vector<int> mountainMultipanel = {
134 0x09FCC, // Mountain 2 Multipanel 1
135 0x09FCE, // Mountain 2 Multipanel 2
136 0x09FCF, // Mountain 2 Multipanel 3
137 0x09FD0, // Mountain 2 Multipanel 4
138 0x09FD1, // Mountain 2 Multipanel 5
139 0x09FD2, // Mountain 2 Multipanel 6
140};
141
142std::vector<int> squarePanels = {
143 0x00064, // Tutorial Straight
144 0x00182, // Tutorial Bend
145 0x0A3B2, // Tutorial Back Right
146 0x00295, // Tutorial Center Left
147 0x00293, // Tutorial Front Center
148 0x002C2, // Tutorial Front Left
149 0x0005D, // Outside Tutorial Dots Tutorial 1
150 0x0005E, // Outside Tutorial Dots Tutorial 2
151 0x0005F, // Outside Tutorial Dots Tutorial 3
152 0x00060, // Outside Tutorial Dots Tutorial 4
153 0x00061, // Outside Tutorial Dots Tutorial 5
154 0x018AF, // Outside Tutorial Stones Tutorial 1
155 0x0001B, // Outside Tutorial Stones Tutorial 2
156 0x012C9, // Outside Tutorial Stones Tutorial 3
157 0x0001C, // Outside Tutorial Stones Tutorial 4
158 0x0001D, // Outside Tutorial Stones Tutorial 5
159 0x0001E, // Outside Tutorial Stones Tutorial 6
160 0x0001F, // Outside Tutorial Stones Tutorial 7
161 0x00020, // Outside Tutorial Stones Tutorial 8
162 0x00021, // Outside Tutorial Stones Tutorial 9
163 0x033D4, // Outside Tutorial Vault
164 0x0A171, // Tutorial Optional Door 1
165 0x04CA4, // Tutorial Optional Door 2
166 0x17CFB, // Outside Tutorial Discard
167 0x3C12B, // Glass Factory Discard
168 0x01A54, // Glass Factory Entry
169 0x00086, // Glass Factory Vertical Symmetry 1
170 0x00087, // Glass Factory Vertical Symmetry 2
171 0x00059, // Glass Factory Vertical Symmetry 3
172 0x00062, // Glass Factory Vertical Symmetry 4
173 0x0008D, // Glass Factory Rotational Symmetry 1
174 0x00081, // Glass Factory Rotational Symmetry 2
175 0x00083, // Glass Factory Rotational Symmetry 3
176 0x00084, // Glass Factory Melting 1
177 0x00082, // Glass Factory Melting 2
178 0x0343A, // Glass Factory Melting 3
179 0x000B0, // Symmetry Island Door 1
180 0x00022, // Symmetry Island Black Dots 1
181 0x00023, // Symmetry Island Black Dots 2
182 0x00024, // Symmetry Island Black Dots 3
183 0x00025, // Symmetry Island Black Dots 4
184 0x00026, // Symmetry Island Black Dots 5
185 0x0007C, // Symmetry Island Colored Dots 1
186 0x0007E, // Symmetry Island Colored Dots 2
187 0x00075, // Symmetry Island Colored Dots 3
188 0x00073, // Symmetry Island Colored Dots 4
189 0x00077, // Symmetry Island Colored Dots 5
190 0x00079, // Symmetry Island Colored Dots 6
191 0x00065, // Symmetry Island Fading Lines 1
192 0x0006D, // Symmetry Island Fading Lines 2
193 0x00072, // Symmetry Island Fading Lines 3
194 0x0006F, // Symmetry Island Fading Lines 4
195 0x00070, // Symmetry Island Fading Lines 5
196 0x00071, // Symmetry Island Fading Lines 6
197 0x00076, // Symmetry Island Fading Lines 7
198 0x00A52, // Symmetry Island Laser Yellow 1
199 0x00A57, // Symmetry Island Laser Yellow 2
200 0x00A5B, // Symmetry Island Laser Yellow 3
201 0x00A61, // Symmetry Island Laser Blue 1
202 0x00A64, // Symmetry Island Laser Blue 2
203 0x00A68, // Symmetry Island Laser Blue 3
204 0x17CE7, // Desert Discard
205 0x0CC7B, // Desert Vault
206 0x01E5A, // Mill Entry Door Left
207 0x01E59, // Mill Entry Door Right
208 0x00E0C, // Mill Lower Row 1
209 0x01489, // Mill Lower Row 2
210 0x0148A, // Mill Lower Row 3
211 0x014D9, // Mill Lower Row 4
212 0x014E7, // Mill Lower Row 5
213 0x014E8, // Mill Lower Row 6
214 0x00557, // Mill Upper Row 1
215 0x005F1, // Mill Upper Row 2
216 0x00620, // Mill Upper Row 3
217 0x009F5, // Mill Upper Row 4
218 0x0146C, // Mill Upper Row 5
219 0x3C12D, // Mill Upper Row 6
220 0x03686, // Mill Upper Row 7
221 0x014E9, // Mill Upper Row 8
222 0x0367C, // Mill Control Room 1
223 0x3C125, // Mill Control Room 2
224 0x03677, // Mill Stairs Control
225 0x17CF0, // Mill Discard
226 0x03612, // Quarry Laser
227 0x021D5, // Boathouse Ramp Activation Shapers
228 0x034D4, // Boathouse Ramp Activation Stars
229 0x021B3, // Boathouse Erasers and Shapers 1
230 0x021B4, // Boathouse Erasers and Shapers 2
231 0x021B0, // Boathouse Erasers and Shapers 3
232 0x021AF, // Boathouse Erasers and Shapers 4
233 0x021AE, // Boathouse Erasers and Shapers 5
234 0x021B5, // Boathouse Erasers and Stars 1
235 0x021B6, // Boathouse Erasers and Stars 2
236 0x021B7, // Boathouse Erasers and Stars 3
237 0x021BB, // Boathouse Erasers and Stars 4
238 0x09DB5, // Boathouse Erasers and Stars 5
239 0x09DB1, // Boathouse Erasers and Stars 6
240 0x3C124, // Boathouse Erasers and Stars 7
241 0x09DB3, // Boathouse Erasers Shapers and Stars 1
242 0x09DB4, // Boathouse Erasers Shapers and Stars 2
243 0x0A3CB, // Boathouse Erasers Shapers and Stars 3
244 0x0A3CC, // Boathouse Erasers Shapers and Stars 4
245 0x0A3D0, // Boathouse Erasers Shapers and Stars 5
246 0x09E57, // Quarry Entry Gate 1
247 0x17C09, // Quarry Entry Gate 2
248 0x0288C, // Treehouse Door 1
249 0x02886, // Treehouse Door 2
250 0x17D72, // Treehouse Yellow 1
251 0x17D8F, // Treehouse Yellow 2
252 0x17D74, // Treehouse Yellow 3
253 0x17DAC, // Treehouse Yellow 4
254 0x17D9E, // Treehouse Yellow 5
255 0x17DB9, // Treehouse Yellow 6
256 0x17D9C, // Treehouse Yellow 7
257 0x17DC2, // Treehouse Yellow 8
258 0x17DC4, // Treehouse Yellow 9
259 0x0A182, // Treehouse Door 3
260 0x17DC8, // Treehouse First Purple 1
261 0x17DC7, // Treehouse First Purple 2
262 0x17CE4, // Treehouse First Purple 3
263 0x17D2D, // Treehouse First Purple 4
264 0x17D6C, // Treehouse First Purple 5
265 0x17D9B, // Treehouse Second Purple 1
266 0x17D99, // Treehouse Second Purple 2
267 0x17DAA, // Treehouse Second Purple 3
268 0x17D97, // Treehouse Second Purple 4
269 0x17BDF, // Treehouse Second Purple 5
270 0x17D91, // Treehouse Second Purple 6
271 0x17DC6, // Treehouse Second Purple 7
272 0x17DB3, // Treehouse Left Orange 1
273 0x17DB5, // Treehouse Left Orange 2
274 0x17DB6, // Treehouse Left Orange 3
275 0x17DC0, // Treehouse Left Orange 4
276 0x17DD7, // Treehouse Left Orange 5
277 0x17DD9, // Treehouse Left Orange 6
278 0x17DB8, // Treehouse Left Orange 7
279 0x17DDC, // Treehouse Left Orange 8
280 0x17DDE, // Treehouse Left Orange 10
281 0x17DE3, // Treehouse Left Orange 11
282 0x17DEC, // Treehouse Left Orange 12
283 0x17DAE, // Treehouse Left Orange 13
284 0x17DB0, // Treehouse Left Orange 14
285 0x17DDB, // Treehouse Left Orange 15
286 0x17D88, // Treehouse Right Orange 1
287 0x17DB4, // Treehouse Right Orange 2
288 0x17D8C, // Treehouse Right Orange 3
289 0x17DCD, // Treehouse Right Orange 5
290 0x17DB2, // Treehouse Right Orange 6
291 0x17DCC, // Treehouse Right Orange 7
292 0x17DCA, // Treehouse Right Orange 8
293 0x17D8E, // Treehouse Right Orange 9
294 0x17DB1, // Treehouse Right Orange 11
295 0x17DA2, // Treehouse Right Orange 12
296 0x17E3C, // Treehouse Green 1
297 0x17E4D, // Treehouse Green 2
298 0x17E4F, // Treehouse Green 3
299 0x17E5B, // Treehouse Green 5
300 0x17E5F, // Treehouse Green 6
301 0x17E61, // Treehouse Green 7
302 0x17FA9, // Treehouse Green Bridge Discard
303 0x17FA0, // Treehouse Laser Discard
304 0x00139, // Keep Hedges 1
305 0x019DC, // Keep Hedges 2
306 0x019E7, // Keep Hedges 3
307 0x01A0F, // Keep Hedges 4
308 0x0360E, // Keep Front Laser
309 0x03317, // Keep Back Laser
310 0x17D27, // Keep Discard
311 0x17D28, // Shipwreck Discard
312 0x00AFB, // Shipwreck Vault
313 0x2899C, // Town 25 Dots 1
314 0x28A33, // Town 25 Dots 2
315 0x28ABF, // Town 25 Dots 3
316 0x28AC0, // Town 25 Dots 4
317 0x28AC1, // Town 25 Dots 5
318 0x28938, // Town Apple Tree
319 0x28AC7, // Town Blue 1
320 0x28AC8, // Town Blue 2
321 0x28ACA, // Town Blue 3
322 0x28ACB, // Town Blue 4
323 0x28ACC, // Town Blue 5
324 0x28A0D, // Town Church Stars
325 0x28AD9, // Town Eraser
326 0x28998, // Town Green Door
327 0x0A0C8, // Town Orange Crate
328 0x17D01, // Town Orange Crate Discard
329 0x03C08, // Town RGB Stars
330 0x03C0C, // Town RGB Stones
331 0x17C71, // Town Rooftop Discard
332 0x17F5F, // Town Windmill Door
333 0x17F89, // Theater Entrance
334 0x17CF7, // Theater Discard
335 0x33AB2, // Theater Corona Exit
336 0x0A168, // Theater Sun Exit
337 0x00B10, // Monastery Left Door
338 0x00C92, // Monastery Right Door
339 0x17C2E, // Bunker Entry Door
340 0x0056E, // Swamp Entry
341 0x00469, // Swamp Tutorial 1
342 0x00472, // Swamp Tutorial 2
343 0x00262, // Swamp Tutorial 3
344 0x00474, // Swamp Tutorial 4
345 0x00553, // Swamp Tutorial 5
346 0x0056F, // Swamp Tutorial 6
347 0x00390, // Swamp Tutorial 7
348 0x010CA, // Swamp Tutorial 8
349 0x00983, // Swamp Tutorial 9
350 0x00984, // Swamp Tutorial 10
351 0x00986, // Swamp Tutorial 11
352 0x00985, // Swamp Tutorial 12
353 0x00987, // Swamp Tutorial 13
354 0x181A9, // Swamp Tutorial 14
355 0x00982, // Swamp Red 1
356 0x0097F, // Swamp Red 2
357 0x0098F, // Swamp Red 3
358 0x00990, // Swamp Red 4
359 0x17C0D, // Swamp Red Shortcut 1
360 0x17C0E, // Swamp Red Shortcut 2
361 0x00999, // Swamp Discontinuous 1
362 0x0099D, // Swamp Discontinuous 2
363 0x009A0, // Swamp Discontinuous 3
364 0x009A1, // Swamp Discontinuous 4
365 0x00007, // Swamp Rotation Tutorial 1
366 0x00008, // Swamp Rotation Tutorial 2
367 0x00009, // Swamp Rotation Tutorial 3
368 0x0000A, // Swamp Rotation Tutorial 4
369 0x009AB, // Swamp Blue Underwater 1
370 0x009AD, // Swamp Blue Underwater 2
371 0x009AE, // Swamp Blue Underwater 3
372 0x009AF, // Swamp Blue Underwater 4
373 0x00006, // Swamp Blue Underwater 5
374 0x003B2, // Swamp Rotation Advanced 1
375 0x00A1E, // Swamp Rotation Advanced 2
376 0x00C2E, // Swamp Rotation Advanced 3
377 0x00E3A, // Swamp Rotation Advanced 4
378 0x009A6, // Swamp Purple Tetris
379 0x00002, // Swamp Teal Underwater 1
380 0x00004, // Swamp Teal Underwater 2
381 0x00005, // Swamp Teal Underwater 3
382 0x013E6, // Swamp Teal Underwater 4
383 0x00596, // Swamp Teal Underwater 5
384 0x00001, // Swamp Red Underwater 1
385 0x014D2, // Swamp Red Underwater 2
386 0x014D4, // Swamp Red Underwater 3
387 0x014D1, // Swamp Red Underwater 4
388 0x17C05, // Swamp Laser Shortcut 1
389 0x17C02, // Swamp Laser Shortcut 2
390 0x17F9B, // Jungle Discard
391 0x09E73, // Mountain 1 Orange 1
392 0x09E75, // Mountain 1 Orange 2
393 0x09E78, // Mountain 1 Orange 3
394 0x09E79, // Mountain 1 Orange 4
395 0x09E6C, // Mountain 1 Orange 5
396 0x09E6F, // Mountain 1 Orange 6
397 0x09E6B, // Mountain 1 Orange 7
398 0x09EAD, // Mountain 1 Purple 1
399 0x09EAF, // Mountain 1 Purple 2
400 0x09E7A, // Mountain 1 Green 1
401 0x09E71, // Mountain 1 Green 2
402 0x09E72, // Mountain 1 Green 3
403 0x09E69, // Mountain 1 Green 4
404 0x09E7B, // Mountain 1 Green 5
405 0x09FD3, // Mountain 2 Rainbow 1
406 0x09FD4, // Mountain 2 Rainbow 2
407 0x09FD6, // Mountain 2 Rainbow 3
408 0x09FD7, // Mountain 2 Rainbow 4
409 0x17F93, // Mountain 2 Discard
410 0x17FA2, // Mountain 3 Secret Door
411 0x17C42, // Mountainside Discard
412 0x002A6, // Mountainside Vault
413 0x0042D, // Mountaintop River
414 0x00FF8, // UTM Entrance Door
415 0x0A16B, // UTM Green Dots 1
416 0x0A2CE, // UTM Green Dots 2
417 0x0A2D7, // UTM Green Dots 3
418 0x0A2DD, // UTM Green Dots 4
419 0x0A2EA, // UTM Green Dots 5
420 0x17FB9, // UTM Green Dots 6
421 0x0008F, // UTM Invisible Dots 1
422 0x0006B, // UTM Invisible Dots 2
423 0x0008B, // UTM Invisible Dots 3
424 0x0008C, // UTM Invisible Dots 4
425 0x0008A, // UTM Invisible Dots 5
426 0x00089, // UTM Invisible Dots 6
427 0x0006A, // UTM Invisible Dots 7
428 0x0006C, // UTM Invisible Dots 8
429 0x00027, // UTM Invisible Dots Symmetry 1
430 0x00028, // UTM Invisible Dots Symmetry 2
431 0x00029, // UTM Invisible Dots Symmetry 3
432 0x021D7, // UTM Mountainside Shortcut
433 0x00B71, // UTM Quarry
434 0x01A31, // UTM Rainbow
435 0x32962, // UTM Swamp
436 0x32966, // UTM Treehouse
437 0x17CF2, // UTM Waterfall Shortcut
438 0x00A72, // UTM Blue Cave In
439 0x009A4, // UTM Blue Discontinuous
440 0x018A0, // UTM Blue Easy Symmetry
441 0x01A0D, // UTM Blue Hard Symmetry
442 0x008B8, // UTM Blue Left 1
443 0x00973, // UTM Blue Left 2
444 0x0097B, // UTM Blue Left 3
445 0x0097D, // UTM Blue Left 4
446 0x0097E, // UTM Blue Left 5
447 0x00994, // UTM Blue Right Far 1
448 0x334D5, // UTM Blue Right Far 2
449 0x00995, // UTM Blue Right Far 3
450 0x00996, // UTM Blue Right Far 4
451 0x00998, // UTM Blue Right Far 5
452 0x00190, // UTM Blue Right Near 1
453 0x00558, // UTM Blue Right Near 2
454 0x00567, // UTM Blue Right Near 3
455 0x006FE, // UTM Blue Right Near 4
456 0x0A16E, // UTM Challenge Entrance
457 0x039B4, // Tunnels Theater Catwalk
458 0x09E85, // Tunnels Town Shortcut
459};
460
461std::vector<int> shadowsPanels = {
462 0x198B5, // Shadows Tutorial 1
463 0x198BD, // Shadows Tutorial 2
464 0x198BF, // Shadows Tutorial 3
465 0x19771, // Shadows Tutorial 4
466 0x0A8DC, // Shadows Tutorial 5
467 0x0AC74, // Shadows Tutorial 6
468 0x0AC7A, // Shadows Tutorial 7
469 0x0A8E0, // Shadows Tutorial 8
470 0x386FA, // Shadows Avoid 1
471 0x1C33F, // Shadows Avoid 2
472 0x196E2, // Shadows Avoid 3
473 0x1972A, // Shadows Avoid 4
474 0x19809, // Shadows Avoid 5
475 0x19806, // Shadows Avoid 6
476 0x196F8, // Shadows Avoid 7
477 0x1972F, // Shadows Avoid 8
478 0x19797, // Shadows Follow 1
479 0x1979A, // Shadows Follow 2
480 0x197E0, // Shadows Follow 3
481 0x197E8, // Shadows Follow 4
482 0x197E5, // Shadows Follow 5
483 0x19650, // Shadows Laser
484};
485
486std::vector<int> monasteryPanels = {
487 0x00B10, // Monastery Left Door
488 0x00290, // Monastery Exterior 1
489 0x00C92, // Monastery Right Door
490 0x00038, // Monastery Exterior 2
491 0x00037, // Monastery Exterior 3
492// 0x09D9B, // Monastery Bonsai
493 0x193A7, // Monastery Interior 1
494 0x193AA, // Monastery Interior 2
495 0x193AB, // Monastery Interior 3
496 0x193A6, // Monastery Interior 4
497// 0x03713, // Monastery Shortcut
498 0x17CA4, // Monastery Laser
499};
500
501std::vector<int> bunkerPanels = {
502 0x09F7D, // Bunker Tutorial 1
503 0x09FDC, // Bunker Tutorial 2
504 0x09FF7, // Bunker Tutorial 3
505 0x09F82, // Bunker Tutorial 4
506 0x09FF8, // Bunker Tutorial 5
507 0x09D9F, // Bunker Advanced 1
508 0x09DA1, // Bunker Advanced 2
509 0x09DA2, // Bunker Advanced 3
510 0x09DAF, // Bunker Advanced 4
511// 0x0A099, // Bunker Glass Door
512 0x0A010, // Bunker Glass 1
513 0x0A01B, // Bunker Glass 2
514 0x0A01F, // Bunker Glass 3
515 0x17E63, // Bunker Ultraviolet 1
516 0x17E67, // Bunker Ultraviolet 2
517 0x34BC5, // Bunker Open Ultraviolet
518 0x34BC6, // Bunker Close Ultraviolet
519 0x0A079, // Bunker Elevator
520};
521
522std::vector<int> junglePanels = {
523 0x002C4, // Jungle Waves 1
524 0x00767, // Jungle Waves 2
525 0x002C6, // Jungle Waves 3
526 0x0070E, // Jungle Waves 4
527 0x0070F, // Jungle Waves 5
528 0x0087D, // Jungle Waves 6
529 0x002C7, // Jungle Waves 7
530// 0x17CAB, // Jungle Pop-up Wall
531 0x0026D, // Jungle Dots 1
532 0x0026E, // Jungle Dots 2
533 0x0026F, // Jungle Dots 3
534 0x00C3F, // Jungle Dots 4
535 0x00C41, // Jungle Dots 5
536 0x014B2, // Jungle Dots 6
537 0x03616, // Jungle Laser
538};
539
540// There might be something to do with these, I haven't decided yet.
541std::vector<int> nothingPanels = {
542// Doors & Shortcuts & Shortcut doors & Door controls
543 0x0C339, // Desert Surface Door
544 0x0A249, // Desert Pond Exit Door
545 0x275ED, // Mill EP Door
546 0x17CAC, // Mill Stairs Shortcut Door
547 0x38663, // Boathouse Shortcut
548 0x09E49, // Keep Shadows Shortcut
549 0x0361B, // Keep Tower Shortcut
550 0x334DC, // Shadows Inner Door Control
551 0x334DB, // Shadows Outer Door Control
552 0x2700B, // Treehouse Exterior Door Control
553 0x17CBC, // Treehouse Interior Door Control
554 0x337FA, // Jungle Shortcut
555
556// Controls (?)
557 0x09FA0, // Desert Surface 3 Control
558 0x09F86, // Desert Surface 8 Control
559 0x1C2DF, // Desert Flood Control Lower Far Left
560 0x1831E, // Desert Flood Control Lower Far Right
561 0x1C260, // Desert Flood Control Lower Near Left
562 0x1831C, // Desert Flood Control Lower Near Right
563 0x1C2F3, // Desert Flood Control Raise Far Left
564 0x1831D, // Desert Flood Control Raise Far Right
565 0x1C2B1, // Desert Flood Control Raise Near Left
566 0x1831B, // Desert Flood Control Raise Near Right
567 0x0A015, // Desert Final Far Control
568 0x03678, // Mill Lower Ramp Contol
569 0x03679, // Mill Lower Lift Control
570 0x03675, // Mill Upper Lift Control
571 0x03676, // Mill Upper Ramp Control
572 0x03852, // Boathouse Ramp Angle Control
573 0x03858, // Boathouse Ramp Position Control
574 0x275FA, // Boathouse Hook Control
575 0x037FF, // Treehouse Drawbridge Control
576 0x09F98, // Town Laser Redirect Control
577 0x334D8, // Town RGB Light Control
578 0x17E2B, // Swamp Flood Gate Control
579 0x00609, // Swamp Surface Sliding Bridge Control
580 0x18488, // Swamp Underwater Sliding Bridge Control
581 0x17C0A, // Swamp Island Control 1
582 0x17E07, // Swamp Island Control 2
583 0x181F5, // Swamp Rotating Bridge Control
584
585// Vault Boxes
586 0x03481, // Outside Tutorial Vault Box
587 0x0339E, // Desert Vault Box
588 0x03535, // Shipwreck Vault Box
589 0x03702, // Jungle Vault Box
590 0x03542, // Mountainside Vault Box
591 0x2FAF6, // Tunnels Vault Box
592
593// Boat Summons
594 0x17CC8, // Glass Factory Summon Boat
595 0x17CA6, // Boathouse Summon Boat
596 0x17C95, // Treehouse Summon Boat
597 0x0A054, // Town Summon Boat
598 0x09DB8, // Swamp Summon Boat
599 0x17CDF, // Jungle Summon Boat
600
601// Identical sets
602 0x00143, // Orchard Apple Tree 1
603 0x0003B, // Orchard Apple Tree 2
604 0x00055, // Orchard Apple Tree 3
605 0x032F7, // Orchard Apple Tree 4
606 0x032FF, // Orchard Apple Tree 5
607 0x009B8, // Symmetry Island Transparent 1
608 0x003E8, // Symmetry Island Transparent 2
609 0x00A15, // Symmetry Island Transparent 3
610 0x00B53, // Symmetry Island Transparent 4
611 0x00B8D, // Symmetry Island Transparent 5
612
613// Misc
614 0x03629, // Tutorial Gate Open
615 0x09FAA, // Desert Lightswitch
616 0x0C335, // Tutorial Pillar
617 0x0C373, // Tutorial Patio floor
618 0x1C349, // Symmetry Island Door 2 - Collision fails here, sadly
619 0x18076, // Desert Flood Exit - I am doing something with this -- but it's a very unique panel.
620 0x0A15C, // Desert Final Left Convex
621 0x09FFF, // Desert Final Left Concave
622 0x0A15F, // Desert Final Near
623 0x033EA, // Keep Yellow Pressure Plates
624 0x0A3A8, // Keep Yellow Reset
625 0x01BE9, // Keep Purple Pressure Plates
626 0x0A3B9, // Keep Purple Reset
627 0x01CD3, // Keep Green Pressure Plates
628 0x0A3BB, // Keep Green Reset
629 0x01D3F, // Keep Blue Pressure Plates
630 0x0A3AD, // Keep Blue Reset
631 0x2896A, // Town Bridge
632 0x28A69, // Town Lattice
633 0x28A79, // Town Maze
634 0x28B39, // Town Red Hexagonal
635 0x034E3, // Town Soundproof Dots
636 0x034E4, // Town Soundproof Waves
637 0x079DF, // Town Triple
638 0x00815, // Theater Video Input
639 0x03553, // Theater Tutorial Video
640 0x03552, // Theater Desert Video
641 0x0354E, // Theater Jungle Video
642 0x03549, // Theater Challenge Video
643 0x0354F, // Theater Shipwreck Video
644 0x03545, // Theater Mountain Video
645 0x18590, // Town Transparent
646 0x28AE3, // Town Wire
647
648
649 0x09E39, // Mountain 1 Purple Pathway
650// 0x33AF5, // Mountain 1 Blue 1
651// 0x33AF7, // Mountain 1 Blue 2
652// 0x09F6E, // Mountain 1 Blue 3
653// 0x09FD8, // Mountain 2 Rainbow 5
654 0x09E86, // Mountain 2 Blue Pathway
655 0x09ED8, // Mountain 2 Orange Pathway
656 0x09F8E, // Mountain 3 Near Right Floor
657 0x09FC1, // Mountain 3 Near Left Floor
658 0x09F01, // Mountain 3 Far Right Floor
659 0x09EFF, // Mountain 3 Far Left Floor
660 0x09FDA, // Mountain 3 Giant Floor
661// 0x01983, // Mountain 3 Left Peekaboo
662// 0x01987, // Mountain 3 Right Peekaboo
663// 0x3D9A6, // Mountain 3 Left Close Door
664// 0x3D9A7, // Mountain 3 Right Close Door
665// 0x3D9AA, // Mountain 3 Left Activate Elevator
666// 0x3D9A8, // Mountain 3 Right Activate Elevator
667// 0x3D9A9, // Mountain 3 Launch Elevator
668// 0x3C113, // Mountain 3 Left Open Door
669// 0x3C114, // Mountain 3 Right Open Door
670 0x09F7F, // Mountaintop Laser Box
671 0x17C34, // Mountaintop Perspective
672// 0x334E1, // UTM Secret Door Control
673// 0x2773D, // Tunnels Desert Shortcut
674// 0x27732, // Tunnels Theater Shortcut
675// 0x0A099, // Bunker Glass Door
676// 0x15ADD, // Jungle Vault
677// 0x17CAA, // Jungle Courtyard Gate
678 0x0005C, // Glass Factory Vertical Symmetry 5
679 0x17C31, // Desert Final Transparent
680 0x19650, // Shadows Laser
681};
diff --git a/WitnessRandomizer/WitnessRandomizer.cpp b/WitnessRandomizer/WitnessRandomizer.cpp deleted file mode 100644 index cf98a3a..0000000 --- a/WitnessRandomizer/WitnessRandomizer.cpp +++ /dev/null
@@ -1,251 +0,0 @@
1/*
2 * TODO: Split out main() logic into another file, and move into separate functions for easier testing. Then write tests.
3 * BUGS:
4 * Shipwreck vault fails, possibly because of dot_reflection? Sometimes?
5 * Treehouse pivots *should* work, but I need to not copy style_flags.
6 This seems to cause crashes when pivots appear elsewhere in the world.
7 * Some panels are impossible casually: (idc, I think)
8 ** Town Stars, Invisible dots
9 * Shadows burn marks are not appearing
10 * Something is wrong with jungle re: softlocks
11 * FEATURES:
12 * SWAP_TARGETS should still require the full panel sequence (and have ways to prevent softlocks?)
13 ** Think about: Jungle
14 ** Hard: Monastery
15 ** Do: Challenge
16 * Randomize audio logs
17 * Swap sounds in jungle (along with panels) -- maybe impossible
18 * Make orange 7 (all of oranges?) hard. Like big = hard.
19 * Start the game if it isn't running?
20 * UI for the randomizer :(
21 * Increase odds of mountain oranges garbage on other panels?
22*/
23#include "Memory.h"
24#include "WitnessRandomizer.h"
25#include "Panels.h"
26#include <string>
27#include <iostream>
28#include <numeric>
29#include <chrono>
30
31template <class T>
32size_t find(const std::vector<T> &data, T search, size_t startIndex = 0) {
33 for (size_t i=startIndex ; i<data.size(); i++) {
34 if (data[i] == search) return i;
35 }
36 std::cout << "Couldn't find " << search << " in data!" << std::endl;
37 exit(-1);
38}
39
40int main(int argc, char** argv)
41{
42 WitnessRandomizer randomizer = WitnessRandomizer();
43
44 if (argc == 2) {
45 srand(atoi(argv[1])); // Seed from the command line
46 } else {
47 srand(static_cast<unsigned int>(time(nullptr)));
48 int seed = rand() % (1 << 16); // Seed from the time in milliseconds
49 std::cout << "Selected seed: " << seed << std::endl;
50 srand(seed);
51 }
52
53 // Content swaps -- must happen before squarePanels
54 randomizer.Randomize(tallUpDownPanels, SWAP_LINES | SWAP_STYLE);
55 randomizer.Randomize(upDownPanels, SWAP_LINES | SWAP_STYLE);
56 randomizer.Randomize(leftForwardRightPanels, SWAP_LINES);
57
58 randomizer.Randomize(squarePanels, SWAP_LINES | SWAP_STYLE);
59
60 // Frame swaps -- must happen after squarePanels
61 randomizer.Randomize(burnablePanels, SWAP_LINES | SWAP_STYLE);
62
63 // Target swaps, can happen whenever
64 randomizer.Randomize(lasers, SWAP_TARGETS);
65 // Read the target of keep front laser, and write it to keep back laser.
66 std::vector<int> keepFrontLaserTarget = randomizer.ReadPanelData<int>(0x0360E, TARGET, 1);
67 randomizer.WritePanelData<int>(0x03317, TARGET, keepFrontLaserTarget);
68
69 std::vector<int> randomOrder;
70
71 /* Jungle
72 randomOrder = std::vector(junglePanels.size(), 0);
73 std::iota(randomOrder.begin(), randomOrder.end(), 0);
74 // Randomize Waves 2-7
75 // Waves 1 cannot be randomized, since no other panel can start on
76 randomizer.RandomizeRange(randomOrder, SWAP_NONE, 1, 7);
77 // Randomize Pitches 1-6 onto themselves
78 randomizer.RandomizeRange(randomOrder, SWAP_NONE, 7, 13);
79 randomizer.ReassignTargets(junglePanels, randomOrder);
80 */
81
82 /* Bunker */
83 randomOrder = std::vector(bunkerPanels.size(), 0);
84 std::iota(randomOrder.begin(), randomOrder.end(), 0);
85 // Randomize Tutorial 2-Advanced Tutorial 4 + Glass 1
86 // Tutorial 1 cannot be randomized, since no other panel can start on
87 // Glass 1 will become door + glass 1, due to the targetting system
88 randomizer.RandomizeRange(randomOrder, SWAP_NONE, 1, 10);
89 // Randomize Glass 1-3 into everything after the door
90 const size_t glassDoorIndex = find(randomOrder, 9) + 1;
91 randomizer.RandomizeRange(randomOrder, SWAP_NONE, glassDoorIndex, 12);
92 randomizer.ReassignTargets(bunkerPanels, randomOrder);
93
94 /* Shadows */
95 randomOrder = std::vector(shadowsPanels.size(), 0);
96 std::iota(randomOrder.begin(), randomOrder.end(), 0);
97 randomizer.RandomizeRange(randomOrder, SWAP_NONE, 0, 8); // Tutorial
98 randomizer.RandomizeRange(randomOrder, SWAP_NONE, 8, 16); // Avoid
99 randomizer.RandomizeRange(randomOrder, SWAP_NONE, 16, 21); // Follow
100 randomizer.ReassignTargets(shadowsPanels, randomOrder);
101 // Turn off original starting panel
102 randomizer.WritePanelData<float>(shadowsPanels[0], POWER, {0.0f, 0.0f});
103 // Turn on new starting panel
104 randomizer.WritePanelData<float>(shadowsPanels[randomOrder[0]], POWER, {1.0f, 1.0f});
105
106 /* Monastery
107 randomOrder = std::vector(monasteryPanels.size(), 0);
108 std::iota(randomOrder.begin(), randomOrder.end(), 0);
109 randomizer.RandomizeRange(randomOrder, SWAP_NONE, 2, 6); // outer 2 & 3, inner 1
110 // Once outer 3 and right door are solved, inner 2-4 are accessible
111 int innerPanelsIndex = max(find(randomOrder, 2), find(randomOrder, 4));
112 randomizer.RandomizeRange(randomOrder, SWAP_NONE, innerPanelsIndex, 9); // Inner 2-4
113
114 randomizer.ReassignTargets(monasteryPanels, randomOrder);
115 */
116}
117
118WitnessRandomizer::WitnessRandomizer()
119{
120 // Turn off desert surface 8
121 WritePanelData<float>(0x09F94, POWER, {0.0, 0.0});
122 // Turn off desert flood final
123 WritePanelData<float>(0x18076, POWER, {0.0, 0.0});
124 // Change desert floating target to desert flood final
125 WritePanelData<int>(0x17ECA, TARGET, {0x18077});
126
127 // Distance-gate shadows laser to prevent sniping through the bars
128 WritePanelData<float>(0x19650, MAX_BROADCAST_DISTANCE, {2.5});
129 // Change the shadows tutorial cable to only activate avoid
130 WritePanelData<int>(0x319A8, CABLE_TARGET_2, {0});
131 // Change shadows avoid 8 to power shadows follow
132 WritePanelData<int>(0x1972F, TARGET, {0x1C34C});
133
134 // Distance-gate swamp snipe 1 to prevent RNG swamp snipe
135 WritePanelData<float>(0x17C05, MAX_BROADCAST_DISTANCE, {5.0});
136
137 // Disable tutorial cursor speed modifications (not working?)
138 WritePanelData<float>(0x00295, CURSOR_SPEED_SCALE, {1.0});
139 WritePanelData<float>(0x0C373, CURSOR_SPEED_SCALE, {1.0});
140 WritePanelData<float>(0x00293, CURSOR_SPEED_SCALE, {1.0});
141 WritePanelData<float>(0x002C2, CURSOR_SPEED_SCALE, {1.0});
142}
143
144void WitnessRandomizer::Randomize(std::vector<int>& panels, int flags) {
145 return RandomizeRange(panels, flags, 0, panels.size());
146}
147
148// Range is [start, end)
149void WitnessRandomizer::RandomizeRange(std::vector<int> &panels, int flags, size_t startIndex, size_t endIndex) {
150 if (panels.size() == 0) return;
151 if (startIndex >= endIndex) return;
152 if (endIndex >= panels.size()) endIndex = panels.size();
153 for (size_t i = endIndex-1; i > startIndex+1; i--) {
154 const size_t target = rand() % (i - startIndex) + startIndex;
155 if (i != target) {
156 // std::cout << "Swapping panels " << std::hex << panels[i] << " and " << std::hex << panels[target] << std::endl;
157 SwapPanels(panels[i], panels[target], flags);
158 std::swap(panels[i], panels[target]); // Panel indices in the array
159 }
160 }
161}
162
163void WitnessRandomizer::SwapPanels(int panel1, int panel2, int flags) {
164 std::map<int, int> offsets;
165
166 if (flags & SWAP_TARGETS) {
167 offsets[TARGET] = sizeof(int);
168 }
169 if (flags & SWAP_STYLE) {
170 offsets[STYLE_FLAGS] = sizeof(int);
171 }
172 if (flags & SWAP_LINES) {
173 offsets[PATH_COLOR] = 16;
174 offsets[REFLECTION_PATH_COLOR] = 16;
175 offsets[DOT_COLOR] = 16;
176 offsets[ACTIVE_COLOR] = 16;
177 offsets[BACKGROUND_REGION_COLOR] = 16;
178 offsets[SUCCESS_COLOR_A] = 16;
179 offsets[SUCCESS_COLOR_B] = 16;
180 offsets[STROBE_COLOR_A] = 16;
181 offsets[STROBE_COLOR_B] = 16;
182 offsets[ERROR_COLOR] = 16;
183 offsets[PATTERN_POINT_COLOR] = 16;
184 offsets[PATTERN_POINT_COLOR_A] = 16;
185 offsets[PATTERN_POINT_COLOR_B] = 16;
186 offsets[SYMBOL_A] = 16;
187 offsets[SYMBOL_B] = 16;
188 offsets[SYMBOL_C] = 16;
189 offsets[SYMBOL_D] = 16;
190 offsets[SYMBOL_E] = 16;
191 offsets[PUSH_SYMBOL_COLORS] = sizeof(int);
192 offsets[OUTER_BACKGROUND] = 16;
193 offsets[OUTER_BACKGROUND_MODE] = sizeof(int);
194 offsets[TRACED_EDGES] = 16;
195 offsets[AUDIO_PREFIX] = sizeof(void*);
196// offsets[IS_CYLINDER] = sizeof(int);
197// offsets[CYLINDER_Z0] = sizeof(float);
198// offsets[CYLINDER_Z1] = sizeof(float);
199// offsets[CYLINDER_RADIUS] = sizeof(float);
200 offsets[SPECULAR_ADD] = sizeof(float);
201 offsets[SPECULAR_POWER] = sizeof(int);
202 offsets[PATH_WIDTH_SCALE] = sizeof(float);
203 offsets[STARTPOINT_SCALE] = sizeof(float);
204 offsets[NUM_DOTS] = sizeof(int);
205 offsets[NUM_CONNECTIONS] = sizeof(int);
206 offsets[DOT_POSITIONS] = sizeof(void*);
207 offsets[DOT_FLAGS] = sizeof(void*);
208 offsets[DOT_CONNECTION_A] = sizeof(void*);
209 offsets[DOT_CONNECTION_B] = sizeof(void*);
210 offsets[DECORATIONS] = sizeof(void*);
211 offsets[DECORATION_FLAGS] = sizeof(void*);
212 offsets[DECORATION_COLORS] = sizeof(void*);
213 offsets[NUM_DECORATIONS] = sizeof(int);
214 offsets[REFLECTION_DATA] = sizeof(void*);
215 offsets[GRID_SIZE_X] = sizeof(int);
216 offsets[GRID_SIZE_Y] = sizeof(int);
217 offsets[SEQUENCE_LEN] = sizeof(int);
218 offsets[SEQUENCE] = sizeof(void*);
219 offsets[DOT_SEQUENCE_LEN] = sizeof(int);
220 offsets[DOT_SEQUENCE] = sizeof(void*);
221 offsets[DOT_SEQUENCE_LEN_REFLECTION] = sizeof(int);
222 offsets[DOT_SEQUENCE_REFLECTION] = sizeof(void*);
223 offsets[NUM_COLORED_REGIONS] = sizeof(int);
224 offsets[COLORED_REGIONS] = sizeof(void*);
225 offsets[PANEL_TARGET] = sizeof(void*);
226 offsets[SPECULAR_TEXTURE] = sizeof(void*);
227 }
228
229 for (auto const& [offset, size] : offsets) {
230 std::vector<byte> panel1data = ReadPanelData<byte>(panel1, offset, size);
231 std::vector<byte> panel2data = ReadPanelData<byte>(panel2, offset, size);
232 WritePanelData<byte>(panel2, offset, panel1data);
233 WritePanelData<byte>(panel1, offset, panel2data);
234 }
235}
236
237void WitnessRandomizer::ReassignTargets(const std::vector<int>& panels, const std::vector<int>& order) {
238 // This list is offset by 1, so the target of the Nth panel is in position N (aka the N+1th element)
239 // The first panel may not have a wire to power it, so we use the panel ID itself.
240 std::vector<int> targetToActivatePanel = {panels[0] + 1};
241 for (const int panel : panels) {
242 int target = ReadPanelData<int>(panel, TARGET, 1)[0];
243 targetToActivatePanel.push_back(target);
244 }
245
246 for (size_t i=0; i<order.size() - 1; i++) {
247 // Set the target of order[i] to order[i+1], using the "real" target as determined above.
248 const int panelTarget = targetToActivatePanel[order[i+1]];
249 WritePanelData<int>(panels[order[i]], TARGET, {panelTarget});
250 }
251}
diff --git a/WitnessRandomizer/WitnessRandomizer.h b/WitnessRandomizer/WitnessRandomizer.h deleted file mode 100644 index d65cce3..0000000 --- a/WitnessRandomizer/WitnessRandomizer.h +++ /dev/null
@@ -1,156 +0,0 @@
1#pragma once
2
3// #define GLOBALS 0x5B28C0
4#define GLOBALS 0x62A080
5
6int SWAP_NONE = 0x0;
7int SWAP_TARGETS = 0x1;
8int SWAP_LINES = 0x2;
9int SWAP_STYLE = 0x4;
10
11class WitnessRandomizer {
12public:
13 WitnessRandomizer();
14
15 void Randomize(std::vector<int>& panels, int flags);
16 void RandomizeRange(std::vector<int> &panels, int flags, size_t startIndex, size_t endIndex);
17 void SwapPanels(int panel1, int panel2, int flags);
18 void ReassignTargets(const std::vector<int>& panels, const std::vector<int>& order);
19
20 template <class T>
21 std::vector<T> ReadPanelData(int panel, int offset, size_t size) {
22 return _memory.ReadData<T>({GLOBALS, 0x18, panel*8, offset}, size);
23 }
24
25 template <class T>
26 void WritePanelData(int panel, int offset, const std::vector<T>& data) {
27 _memory.WriteData<T>({GLOBALS, 0x18, panel*8, offset}, data);
28 }
29
30private:
31 Memory _memory = Memory("witness64_d3d11.exe");
32};
33
34#if GLOBALS == 0x5B28C0
35#define PATH_COLOR 0xC8
36#define REFLECTION_PATH_COLOR 0xD8
37#define DOT_COLOR 0xF8
38#define ACTIVE_COLOR 0x108
39#define BACKGROUND_REGION_COLOR 0x118
40#define SUCCESS_COLOR_A 0x128
41#define SUCCESS_COLOR_B 0x138
42#define STROBE_COLOR_A 0x148
43#define STROBE_COLOR_B 0x158
44#define ERROR_COLOR 0x168
45#define PATTERN_POINT_COLOR 0x188
46#define PATTERN_POINT_COLOR_A 0x198
47#define PATTERN_POINT_COLOR_B 0x1A8
48#define SYMBOL_A 0x1B8
49#define SYMBOL_B 0x1C8
50#define SYMBOL_C 0x1D8
51#define SYMBOL_D 0x1E8
52#define SYMBOL_E 0x1F8
53#define PUSH_SYMBOL_COLORS 0x208
54#define OUTER_BACKGROUND 0x20C
55#define OUTER_BACKGROUND_MODE 0x21C
56#define TRACED_EDGES 0x230
57#define AUDIO_PREFIX 0x278
58#define POWER 0x2A8
59#define TARGET 0x2BC
60#define IS_CYLINDER 0x2FC
61#define CYLINDER_Z0 0x300
62#define CYLINDER_Z1 0x304
63#define CYLINDER_RADIUS 0x308
64#define CURSOR_SPEED_SCALE 0x358
65#define SPECULAR_ADD 0x398
66#define SPECULAR_POWER 0x39C
67#define PATH_WIDTH_SCALE 0x3A4
68#define STARTPOINT_SCALE 0x3A8
69#define NUM_DOTS 0x3B8
70#define NUM_CONNECTIONS 0x3BC
71#define MAX_BROADCAST_DISTANCE 0x3C0
72#define DOT_POSITIONS 0x3C8
73#define DOT_FLAGS 0x3D0
74#define DOT_CONNECTION_A 0x3D8
75#define DOT_CONNECTION_B 0x3E0
76#define DECORATIONS 0x420
77#define DECORATION_FLAGS 0x428
78#define DECORATION_COLORS 0x430
79#define NUM_DECORATIONS 0x438
80#define REFLECTION_DATA 0x440
81#define GRID_SIZE_X 0x448
82#define GRID_SIZE_Y 0x44C
83#define STYLE_FLAGS 0x450
84#define SEQUENCE_LEN 0x45C
85#define SEQUENCE 0x460
86#define DOT_SEQUENCE_LEN 0x468
87#define DOT_SEQUENCE 0x470
88#define DOT_SEQUENCE_LEN_REFLECTION 0x478
89#define DOT_SEQUENCE_REFLECTION 0x480
90#define NUM_COLORED_REGIONS 0x4A0
91#define COLORED_REGIONS 0x4A8
92#define PANEL_TARGET 0x4B0
93#define SPECULAR_TEXTURE 0x4D8
94#define CABLE_TARGET_2 0xD8
95#elif GLOBALS == 0x62A080
96#define PATH_COLOR 0xC0
97#define REFLECTION_PATH_COLOR 0xD0
98#define DOT_COLOR 0xF0
99#define ACTIVE_COLOR 0x100
100#define BACKGROUND_REGION_COLOR 0x110
101#define SUCCESS_COLOR_A 0x120
102#define SUCCESS_COLOR_B 0x130
103#define STROBE_COLOR_A 0x140
104#define STROBE_COLOR_B 0x150
105#define ERROR_COLOR 0x160
106#define PATTERN_POINT_COLOR 0x180
107#define PATTERN_POINT_COLOR_A 0x190
108#define PATTERN_POINT_COLOR_B 0x1A0
109#define SYMBOL_A 0x1B0
110#define SYMBOL_B 0x1C0
111#define SYMBOL_C 0x1D0
112#define SYMBOL_D 0x1E0
113#define SYMBOL_E 0x1F0
114#define PUSH_SYMBOL_COLORS 0x200
115#define OUTER_BACKGROUND 0x204
116#define OUTER_BACKGROUND_MODE 0x214
117#define TRACED_EDGES 0x228
118#define AUDIO_PREFIX 0x270
119#define POWER 0x2A0
120#define TARGET 0x2B4
121#define IS_CYLINDER 0x2F4
122#define CYLINDER_Z0 0x2F8
123#define CYLINDER_Z1 0x2FC
124#define CYLINDER_RADIUS 0x300
125#define CURSOR_SPEED_SCALE 0x350
126#define SPECULAR_ADD 0x38C
127#define SPECULAR_POWER 0x390
128#define PATH_WIDTH_SCALE 0x39C
129#define STARTPOINT_SCALE 0x3A0
130#define NUM_DOTS 0x3B4
131#define NUM_CONNECTIONS 0x3B8
132#define MAX_BROADCAST_DISTANCE 0x3BC
133#define DOT_POSITIONS 0x3C0
134#define DOT_FLAGS 0x3C8
135#define DOT_CONNECTION_A 0x3D0
136#define DOT_CONNECTION_B 0x3D8
137#define DECORATIONS 0x418
138#define DECORATION_FLAGS 0x420
139#define DECORATION_COLORS 0x428
140#define NUM_DECORATIONS 0x430
141#define REFLECTION_DATA 0x438
142#define GRID_SIZE_X 0x440
143#define GRID_SIZE_Y 0x444
144#define STYLE_FLAGS 0x448
145#define SEQUENCE_LEN 0x454
146#define SEQUENCE 0x458
147#define DOT_SEQUENCE_LEN 0x460
148#define DOT_SEQUENCE 0x468
149#define DOT_SEQUENCE_LEN_REFLECTION 0x470
150#define DOT_SEQUENCE_REFLECTION 0x478
151#define NUM_COLORED_REGIONS 0x498
152#define COLORED_REGIONS 0x4A0
153#define PANEL_TARGET 0x4A8
154#define SPECULAR_TEXTURE 0x4D0
155#define CABLE_TARGET_2 0xD0
156#endif \ No newline at end of file
diff --git a/WitnessRandomizer/WitnessRandomizer.vcxproj b/WitnessRandomizer/WitnessRandomizer.vcxproj deleted file mode 100644 index 80a7f0c..0000000 --- a/WitnessRandomizer/WitnessRandomizer.vcxproj +++ /dev/null
@@ -1,173 +0,0 @@
1<?xml version="1.0" encoding="utf-8"?>
2<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 <ItemGroup Label="ProjectConfigurations">
4 <ProjectConfiguration Include="Debug|Win32">
5 <Configuration>Debug</Configuration>
6 <Platform>Win32</Platform>
7 </ProjectConfiguration>
8 <ProjectConfiguration Include="Release|Win32">
9 <Configuration>Release</Configuration>
10 <Platform>Win32</Platform>
11 </ProjectConfiguration>
12 <ProjectConfiguration Include="Debug|x64">
13 <Configuration>Debug</Configuration>
14 <Platform>x64</Platform>
15 </ProjectConfiguration>
16 <ProjectConfiguration Include="Release|x64">
17 <Configuration>Release</Configuration>
18 <Platform>x64</Platform>
19 </ProjectConfiguration>
20 </ItemGroup>
21 <PropertyGroup Label="Globals">
22 <VCProjectVersion>15.0</VCProjectVersion>
23 <ProjectGuid>{1563D1E2-0A18-4AFC-8D6F-9F8D9A433F31}</ProjectGuid>
24 <Keyword>Win32Proj</Keyword>
25 <RootNamespace>WitnessRandomizer</RootNamespace>
26 <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
27 </PropertyGroup>
28 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30 <ConfigurationType>Application</ConfigurationType>
31 <UseDebugLibraries>true</UseDebugLibraries>
32 <PlatformToolset>v141</PlatformToolset>
33 <CharacterSet>Unicode</CharacterSet>
34 </PropertyGroup>
35 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36 <ConfigurationType>Application</ConfigurationType>
37 <UseDebugLibraries>false</UseDebugLibraries>
38 <PlatformToolset>v141</PlatformToolset>
39 <WholeProgramOptimization>true</WholeProgramOptimization>
40 <CharacterSet>Unicode</CharacterSet>
41 </PropertyGroup>
42 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43 <ConfigurationType>Application</ConfigurationType>
44 <UseDebugLibraries>true</UseDebugLibraries>
45 <PlatformToolset>v141</PlatformToolset>
46 <CharacterSet>Unicode</CharacterSet>
47 </PropertyGroup>
48 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49 <ConfigurationType>Application</ConfigurationType>
50 <UseDebugLibraries>false</UseDebugLibraries>
51 <PlatformToolset>v141</PlatformToolset>
52 <WholeProgramOptimization>true</WholeProgramOptimization>
53 <CharacterSet>Unicode</CharacterSet>
54 </PropertyGroup>
55 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56 <ImportGroup Label="ExtensionSettings">
57 </ImportGroup>
58 <ImportGroup Label="Shared">
59 </ImportGroup>
60 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62 </ImportGroup>
63 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65 </ImportGroup>
66 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68 </ImportGroup>
69 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
70 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71 </ImportGroup>
72 <PropertyGroup Label="UserMacros" />
73 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74 <LinkIncremental>true</LinkIncremental>
75 </PropertyGroup>
76 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
77 <LinkIncremental>true</LinkIncremental>
78 </PropertyGroup>
79 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
80 <LinkIncremental>false</LinkIncremental>
81 </PropertyGroup>
82 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
83 <LinkIncremental>false</LinkIncremental>
84 <CodeAnalysisRuleSet>NativeRecommendedRules.ruleset</CodeAnalysisRuleSet>
85 <RunCodeAnalysis>true</RunCodeAnalysis>
86 </PropertyGroup>
87 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
88 <ClCompile>
89 <PrecompiledHeader>Use</PrecompiledHeader>
90 <WarningLevel>Level3</WarningLevel>
91 <Optimization>Disabled</Optimization>
92 <SDLCheck>true</SDLCheck>
93 <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
94 <ConformanceMode>true</ConformanceMode>
95 <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
96 </ClCompile>
97 <Link>
98 <SubSystem>Console</SubSystem>
99 <GenerateDebugInformation>true</GenerateDebugInformation>
100 </Link>
101 </ItemDefinitionGroup>
102 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
103 <ClCompile>
104 <PrecompiledHeader>NotUsing</PrecompiledHeader>
105 <WarningLevel>Level3</WarningLevel>
106 <Optimization>Disabled</Optimization>
107 <SDLCheck>true</SDLCheck>
108 <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
109 <ConformanceMode>true</ConformanceMode>
110 <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
111 <LanguageStandard>stdcpp17</LanguageStandard>
112 </ClCompile>
113 <Link>
114 <SubSystem>Console</SubSystem>
115 <GenerateDebugInformation>true</GenerateDebugInformation>
116 </Link>
117 </ItemDefinitionGroup>
118 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
119 <ClCompile>
120 <PrecompiledHeader>Use</PrecompiledHeader>
121 <WarningLevel>Level3</WarningLevel>
122 <Optimization>MaxSpeed</Optimization>
123 <FunctionLevelLinking>true</FunctionLevelLinking>
124 <IntrinsicFunctions>true</IntrinsicFunctions>
125 <SDLCheck>true</SDLCheck>
126 <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
127 <ConformanceMode>true</ConformanceMode>
128 <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
129 </ClCompile>
130 <Link>
131 <SubSystem>Console</SubSystem>
132 <EnableCOMDATFolding>true</EnableCOMDATFolding>
133 <OptimizeReferences>true</OptimizeReferences>
134 <GenerateDebugInformation>true</GenerateDebugInformation>
135 </Link>
136 </ItemDefinitionGroup>
137 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
138 <ClCompile>
139 <PrecompiledHeader>NotUsing</PrecompiledHeader>
140 <WarningLevel>Level3</WarningLevel>
141 <Optimization>MaxSpeed</Optimization>
142 <FunctionLevelLinking>true</FunctionLevelLinking>
143 <IntrinsicFunctions>true</IntrinsicFunctions>
144 <SDLCheck>true</SDLCheck>
145 <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
146 <ConformanceMode>true</ConformanceMode>
147 <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
148 <LanguageStandard>stdcpp17</LanguageStandard>
149 <EnablePREfast>true</EnablePREfast>
150 <TreatWarningAsError>true</TreatWarningAsError>
151 <DisableSpecificWarnings>26451</DisableSpecificWarnings>
152 <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
153 </ClCompile>
154 <Link>
155 <SubSystem>Console</SubSystem>
156 <EnableCOMDATFolding>true</EnableCOMDATFolding>
157 <OptimizeReferences>true</OptimizeReferences>
158 <GenerateDebugInformation>true</GenerateDebugInformation>
159 </Link>
160 </ItemDefinitionGroup>
161 <ItemGroup>
162 <ClInclude Include="Memory.h" />
163 <ClInclude Include="Panels.h" />
164 <ClInclude Include="WitnessRandomizer.h" />
165 </ItemGroup>
166 <ItemGroup>
167 <ClCompile Include="Memory.cpp" />
168 <ClCompile Include="WitnessRandomizer.cpp" />
169 </ItemGroup>
170 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
171 <ImportGroup Label="ExtensionTargets">
172 </ImportGroup>
173</Project> \ No newline at end of file
diff --git a/WitnessRandomizer/WitnessRandomizer.vcxproj.filters b/WitnessRandomizer/WitnessRandomizer.vcxproj.filters deleted file mode 100644 index 30ef78f..0000000 --- a/WitnessRandomizer/WitnessRandomizer.vcxproj.filters +++ /dev/null
@@ -1,36 +0,0 @@
1<?xml version="1.0" encoding="utf-8"?>
2<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 <ItemGroup>
4 <Filter Include="Source Files">
5 <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6 <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7 </Filter>
8 <Filter Include="Header Files">
9 <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10 <Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
11 </Filter>
12 <Filter Include="Resource Files">
13 <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14 <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15 </Filter>
16 </ItemGroup>
17 <ItemGroup>
18 <ClInclude Include="Memory.h">
19 <Filter>Header Files</Filter>
20 </ClInclude>
21 <ClInclude Include="WitnessRandomizer.h">
22 <Filter>Header Files</Filter>
23 </ClInclude>
24 <ClInclude Include="Panels.h">
25 <Filter>Header Files</Filter>
26 </ClInclude>
27 </ItemGroup>
28 <ItemGroup>
29 <ClCompile Include="WitnessRandomizer.cpp">
30 <Filter>Source Files</Filter>
31 </ClCompile>
32 <ClCompile Include="Memory.cpp">
33 <Filter>Source Files</Filter>
34 </ClCompile>
35 </ItemGroup>
36</Project> \ No newline at end of file