diff options
author | jbzdarkid <jbzdarkid@gmail.com> | 2018-10-27 01:27:29 -0700 |
---|---|---|
committer | jbzdarkid <jbzdarkid@gmail.com> | 2018-10-27 01:27:29 -0700 |
commit | 1f2077485e580b3b1d582298281ac6272df18d8d (patch) | |
tree | 6d1b151934137a34aa13c9bc6485581a540fc4a2 /WitnessRandomizer | |
parent | 223f7244fccfc67685fcefe889ea49414e32b715 (diff) | |
download | witness-tutorializer-1f2077485e580b3b1d582298281ac6272df18d8d.tar.gz witness-tutorializer-1f2077485e580b3b1d582298281ac6272df18d8d.tar.bz2 witness-tutorializer-1f2077485e580b3b1d582298281ac6272df18d8d.zip |
/W3 clean, add .msi installer project
Diffstat (limited to 'WitnessRandomizer')
-rw-r--r-- | WitnessRandomizer/Memory.cpp | 14 | ||||
-rw-r--r-- | WitnessRandomizer/Memory.h | 20 | ||||
-rw-r--r-- | WitnessRandomizer/Panels.h | 26 | ||||
-rw-r--r-- | WitnessRandomizer/WitnessRandomizer.cpp | 32 | ||||
-rw-r--r-- | WitnessRandomizer/WitnessRandomizer.h | 6 | ||||
-rw-r--r-- | WitnessRandomizer/WitnessRandomizer.vcxproj | 8 |
6 files changed, 56 insertions, 50 deletions
diff --git a/WitnessRandomizer/Memory.cpp b/WitnessRandomizer/Memory.cpp index 6077691..0afeded 100644 --- a/WitnessRandomizer/Memory.cpp +++ b/WitnessRandomizer/Memory.cpp | |||
@@ -47,30 +47,28 @@ Memory::~Memory() { | |||
47 | CloseHandle(_handle); | 47 | CloseHandle(_handle); |
48 | } | 48 | } |
49 | 49 | ||
50 | // Private methods: | ||
51 | |||
52 | void Memory::ThrowError() { | 50 | void Memory::ThrowError() { |
53 | std::string message(256, '\0'); | 51 | std::string message(256, '\0'); |
54 | FormatMessageA(4096, NULL, GetLastError(), 1024, &message[0], static_cast<DWORD>(message.length()), NULL); | 52 | FormatMessageA(4096, nullptr, GetLastError(), 1024, &message[0], static_cast<DWORD>(message.length()), nullptr); |
55 | std::cout << message.c_str() << std::endl; | 53 | std::cout << message.c_str() << std::endl; |
56 | exit(EXIT_FAILURE); | 54 | exit(EXIT_FAILURE); |
57 | } | 55 | } |
58 | 56 | ||
59 | uintptr_t Memory::ComputeOffset(std::vector<int> offsets) | 57 | void* Memory::ComputeOffset(std::vector<int> offsets) |
60 | { | 58 | { |
61 | // Leave off the last offset, since it will be either read/write, and may not be of type unitptr_t. | 59 | // Leave off the last offset, since it will be either read/write, and may not be of type unitptr_t. |
62 | int final_offset = offsets.back(); | 60 | int final_offset = offsets.back(); |
63 | offsets.pop_back(); | 61 | offsets.pop_back(); |
64 | 62 | ||
65 | uintptr_t cumulativeAddress = _baseAddress; | 63 | uintptr_t cumulativeAddress = _baseAddress; |
66 | for (int offset : offsets) { | 64 | for (const int offset : offsets) { |
67 | cumulativeAddress += offset; | 65 | cumulativeAddress += offset; |
68 | 66 | ||
69 | auto search = _computedAddresses.find(cumulativeAddress); | 67 | const auto search = _computedAddresses.find(cumulativeAddress); |
70 | if (search == std::end(_computedAddresses)) { | 68 | if (search == std::end(_computedAddresses)) { |
71 | // If the address is not yet computed, then compute it. | 69 | // If the address is not yet computed, then compute it. |
72 | uintptr_t computedAddress = 0; | 70 | uintptr_t computedAddress = 0; |
73 | if (!ReadProcessMemory(_handle, (LPVOID)cumulativeAddress, &computedAddress, sizeof(uintptr_t), NULL)) { | 71 | if (!ReadProcessMemory(_handle, reinterpret_cast<LPVOID>(cumulativeAddress), &computedAddress, sizeof(uintptr_t), NULL)) { |
74 | ThrowError(); | 72 | ThrowError(); |
75 | } | 73 | } |
76 | _computedAddresses[cumulativeAddress] = computedAddress; | 74 | _computedAddresses[cumulativeAddress] = computedAddress; |
@@ -78,5 +76,5 @@ uintptr_t Memory::ComputeOffset(std::vector<int> offsets) | |||
78 | 76 | ||
79 | cumulativeAddress = _computedAddresses[cumulativeAddress]; | 77 | cumulativeAddress = _computedAddresses[cumulativeAddress]; |
80 | } | 78 | } |
81 | return cumulativeAddress + final_offset; | 79 | return reinterpret_cast<void*>(cumulativeAddress + final_offset); |
82 | } | 80 | } |
diff --git a/WitnessRandomizer/Memory.h b/WitnessRandomizer/Memory.h index 6f5b8b7..8e8bbc3 100644 --- a/WitnessRandomizer/Memory.h +++ b/WitnessRandomizer/Memory.h | |||
@@ -2,9 +2,6 @@ | |||
2 | #include <vector> | 2 | #include <vector> |
3 | #include <map> | 3 | #include <map> |
4 | #include <windows.h> | 4 | #include <windows.h> |
5 | #include <thread> | ||
6 | #include <chrono> | ||
7 | using namespace std::chrono_literals; | ||
8 | 5 | ||
9 | // https://github.com/erayarslan/WriteProcessMemory-Example | 6 | // https://github.com/erayarslan/WriteProcessMemory-Example |
10 | // http://stackoverflow.com/q/32798185 | 7 | // http://stackoverflow.com/q/32798185 |
@@ -16,16 +13,18 @@ public: | |||
16 | Memory(const std::string& processName); | 13 | Memory(const std::string& processName); |
17 | ~Memory(); | 14 | ~Memory(); |
18 | 15 | ||
16 | Memory(const Memory& memory) = delete; | ||
17 | Memory& operator=(const Memory& other) = delete; | ||
18 | |||
19 | template<class T> | 19 | template<class T> |
20 | std::vector<T> ReadData(const std::vector<int>& offsets, int numItems) { | 20 | std::vector<T> ReadData(const std::vector<int>& offsets, size_t numItems) { |
21 | std::vector<T> data; | 21 | std::vector<T> data; |
22 | data.resize(numItems); | 22 | data.resize(numItems); |
23 | for (int i=0; i<5; i++) { | 23 | for (int i=0; i<5; i++) { |
24 | if (ReadProcessMemory(_handle, (LPVOID)ComputeOffset(offsets), &data[0], sizeof(T) * numItems, NULL)) | 24 | if (ReadProcessMemory(_handle, ComputeOffset(offsets), &data[0], sizeof(T) * numItems, nullptr)) |
25 | { | 25 | { |
26 | return data; | 26 | return data; |
27 | } | 27 | } |
28 | // std::this_thread::sleep_for(10ms); | ||
29 | } | 28 | } |
30 | ThrowError(); | 29 | ThrowError(); |
31 | return {}; | 30 | return {}; |
@@ -34,10 +33,9 @@ public: | |||
34 | template <class T> | 33 | template <class T> |
35 | void WriteData(const std::vector<int>& offsets, const std::vector<T>& data) { | 34 | void WriteData(const std::vector<int>& offsets, const std::vector<T>& data) { |
36 | for (int i=0; i<5; i++) { | 35 | for (int i=0; i<5; i++) { |
37 | if (WriteProcessMemory(_handle, (LPVOID)ComputeOffset(offsets), &data[0], sizeof(T) * data.size(), NULL)) { | 36 | if (WriteProcessMemory(_handle, ComputeOffset(offsets), &data[0], sizeof(T) * data.size(), nullptr)) { |
38 | return; | 37 | return; |
39 | } | 38 | } |
40 | // std::this_thread::sleep_for(10ms); | ||
41 | } | 39 | } |
42 | ThrowError(); | 40 | ThrowError(); |
43 | } | 41 | } |
@@ -45,9 +43,9 @@ public: | |||
45 | private: | 43 | private: |
46 | void ThrowError(); | 44 | void ThrowError(); |
47 | 45 | ||
48 | uintptr_t ComputeOffset(std::vector<int> offsets); | 46 | void* ComputeOffset(std::vector<int> offsets); |
49 | 47 | ||
50 | std::map<uintptr_t, uintptr_t> _computedAddresses; | 48 | std::map<uintptr_t, uintptr_t> _computedAddresses; |
51 | uintptr_t _baseAddress; | 49 | uintptr_t _baseAddress = 0; |
52 | HANDLE _handle; | 50 | HANDLE _handle = nullptr; |
53 | }; \ No newline at end of file | 51 | }; \ No newline at end of file |
diff --git a/WitnessRandomizer/Panels.h b/WitnessRandomizer/Panels.h index cd815bc..2995170 100644 --- a/WitnessRandomizer/Panels.h +++ b/WitnessRandomizer/Panels.h | |||
@@ -2,7 +2,7 @@ | |||
2 | #include <vector> | 2 | #include <vector> |
3 | 3 | ||
4 | // Some of these (the puzzle ones) are duplicated elsewhere | 4 | // Some of these (the puzzle ones) are duplicated elsewhere |
5 | std::vector<int> lasers = { | 5 | const std::vector<int> lasers = { |
6 | 0x0360D, // Symmetry | 6 | 0x0360D, // Symmetry |
7 | 0x03615, // Swamp | 7 | 0x03615, // Swamp |
8 | 0x09DE0, // Bunker | 8 | 0x09DE0, // Bunker |
@@ -18,7 +18,7 @@ std::vector<int> lasers = { | |||
18 | }; | 18 | }; |
19 | 19 | ||
20 | // Note: Some of these (non-desert) are duplicated elsewhere | 20 | // Note: Some of these (non-desert) are duplicated elsewhere |
21 | std::vector<int> burnablePanels = { | 21 | const std::vector<int> burnablePanels = { |
22 | 0x17D9C, // Treehouse Yellow 7 | 22 | 0x17D9C, // Treehouse Yellow 7 |
23 | 0x17DC2, // Treehouse Yellow 8 | 23 | 0x17DC2, // Treehouse Yellow 8 |
24 | 0x17DC4, // Treehouse Yellow 9 | 24 | 0x17DC4, // Treehouse Yellow 9 |
@@ -63,7 +63,7 @@ std::vector<int> burnablePanels = { | |||
63 | 63 | ||
64 | // Note: Some of these (non-controls) are duplicated elsewhere | 64 | // Note: Some of these (non-controls) are duplicated elsewhere |
65 | // TODO: Gave up | 65 | // TODO: Gave up |
66 | std::vector<int> leftRightPanels = { | 66 | const std::vector<int> leftRightPanels = { |
67 | 0x01A54, // Glass Factory Entry | 67 | 0x01A54, // Glass Factory Entry |
68 | 0x00086, // Glass Factory Vertical Symmetry 1 | 68 | 0x00086, // Glass Factory Vertical Symmetry 1 |
69 | 0x00087, // Glass Factory Vertical Symmetry 2 | 69 | 0x00087, // Glass Factory Vertical Symmetry 2 |
@@ -77,7 +77,7 @@ std::vector<int> leftRightPanels = { | |||
77 | }; | 77 | }; |
78 | 78 | ||
79 | // Note: Some of these (non-controls) are duplicated elsewhere | 79 | // Note: Some of these (non-controls) are duplicated elsewhere |
80 | std::vector<int> upDownPanels = { | 80 | const std::vector<int> upDownPanels = { |
81 | 0x0008D, // Glass Factory Rotational Symmetry 1 | 81 | 0x0008D, // Glass Factory Rotational Symmetry 1 |
82 | 0x00081, // Glass Factory Rotational Symmetry 2 | 82 | 0x00081, // Glass Factory Rotational Symmetry 2 |
83 | 0x00083, // Glass Factory Rotational Symmetry 3 | 83 | 0x00083, // Glass Factory Rotational Symmetry 3 |
@@ -100,7 +100,7 @@ std::vector<int> upDownPanels = { | |||
100 | }; | 100 | }; |
101 | 101 | ||
102 | // Note: Some of these (non-controls) are duplicated elsewhere | 102 | // Note: Some of these (non-controls) are duplicated elsewhere |
103 | std::vector<int> leftForwardRightPanels = { | 103 | const std::vector<int> leftForwardRightPanels = { |
104 | // 0x00075, // Symmetry Island Colored Dots 3 | 104 | // 0x00075, // Symmetry Island Colored Dots 3 |
105 | // 0x288EA, // UTM Perspective 1 | 105 | // 0x288EA, // UTM Perspective 1 |
106 | // 0x288FC, // UTM Perspective 2 | 106 | // 0x288FC, // UTM Perspective 2 |
@@ -112,7 +112,7 @@ std::vector<int> leftForwardRightPanels = { | |||
112 | 0x17E52, // Treehouse Green 4 | 112 | 0x17E52, // Treehouse Green 4 |
113 | }; | 113 | }; |
114 | 114 | ||
115 | std::vector<int> pillars = { | 115 | const std::vector<int> pillars = { |
116 | 0x0383D, // Mountain 3 Left Pillar 1 | 116 | 0x0383D, // Mountain 3 Left Pillar 1 |
117 | 0x0383F, // Mountain 3 Left Pillar 2 | 117 | 0x0383F, // Mountain 3 Left Pillar 2 |
118 | 0x03859, // Mountain 3 Left Pillar 3 | 118 | 0x03859, // Mountain 3 Left Pillar 3 |
@@ -126,7 +126,7 @@ std::vector<int> pillars = { | |||
126 | // 0x1C319, // Challenge Right Pillar | 126 | // 0x1C319, // Challenge Right Pillar |
127 | }; | 127 | }; |
128 | 128 | ||
129 | std::vector<int> mountainMultipanel = { | 129 | const std::vector<int> mountainMultipanel = { |
130 | 0x09FCC, // Mountain 2 Multipanel 1 | 130 | 0x09FCC, // Mountain 2 Multipanel 1 |
131 | 0x09FCE, // Mountain 2 Multipanel 2 | 131 | 0x09FCE, // Mountain 2 Multipanel 2 |
132 | 0x09FCF, // Mountain 2 Multipanel 3 | 132 | 0x09FCF, // Mountain 2 Multipanel 3 |
@@ -135,7 +135,7 @@ std::vector<int> mountainMultipanel = { | |||
135 | 0x09FD2, // Mountain 2 Multipanel 6 | 135 | 0x09FD2, // Mountain 2 Multipanel 6 |
136 | }; | 136 | }; |
137 | 137 | ||
138 | std::vector<int> squarePanels = { | 138 | const std::vector<int> squarePanels = { |
139 | 0x00064, // Tutorial Straight | 139 | 0x00064, // Tutorial Straight |
140 | 0x00182, // Tutorial Bend | 140 | 0x00182, // Tutorial Bend |
141 | 0x0A3B2, // Tutorial Back Right | 141 | 0x0A3B2, // Tutorial Back Right |
@@ -453,7 +453,7 @@ std::vector<int> squarePanels = { | |||
453 | 0x09E85, // Tunnels Town Shortcut | 453 | 0x09E85, // Tunnels Town Shortcut |
454 | }; | 454 | }; |
455 | 455 | ||
456 | std::vector<int> shadowsPanels = { | 456 | const std::vector<int> shadowsPanels = { |
457 | 0x198B5, // Shadows Tutorial 1 | 457 | 0x198B5, // Shadows Tutorial 1 |
458 | 0x198BD, // Shadows Tutorial 2 | 458 | 0x198BD, // Shadows Tutorial 2 |
459 | 0x198BF, // Shadows Tutorial 3 | 459 | 0x198BF, // Shadows Tutorial 3 |
@@ -478,7 +478,7 @@ std::vector<int> shadowsPanels = { | |||
478 | 0x19650, // Shadows Laser | 478 | 0x19650, // Shadows Laser |
479 | }; | 479 | }; |
480 | 480 | ||
481 | std::vector<int> monasteryPanels = { | 481 | const std::vector<int> monasteryPanels = { |
482 | 0x00B10, // Monastery Left Door | 482 | 0x00B10, // Monastery Left Door |
483 | 0x00290, // Monastery Exterior 1 | 483 | 0x00290, // Monastery Exterior 1 |
484 | 0x00C92, // Monastery Right Door | 484 | 0x00C92, // Monastery Right Door |
@@ -493,7 +493,7 @@ std::vector<int> monasteryPanels = { | |||
493 | 0x17CA4, // Monastery Laser | 493 | 0x17CA4, // Monastery Laser |
494 | }; | 494 | }; |
495 | 495 | ||
496 | std::vector<int> bunkerPanels = { | 496 | const std::vector<int> bunkerPanels = { |
497 | 0x09F7D, // Bunker Tutorial 1 | 497 | 0x09F7D, // Bunker Tutorial 1 |
498 | 0x09FDC, // Bunker Tutorial 2 | 498 | 0x09FDC, // Bunker Tutorial 2 |
499 | 0x09FF7, // Bunker Tutorial 3 | 499 | 0x09FF7, // Bunker Tutorial 3 |
@@ -514,7 +514,7 @@ std::vector<int> bunkerPanels = { | |||
514 | 0x0A079, // Bunker Elevator | 514 | 0x0A079, // Bunker Elevator |
515 | }; | 515 | }; |
516 | 516 | ||
517 | std::vector<int> junglePanels = { | 517 | const std::vector<int> junglePanels = { |
518 | 0x002C4, // Jungle Waves 1 | 518 | 0x002C4, // Jungle Waves 1 |
519 | 0x00767, // Jungle Waves 2 | 519 | 0x00767, // Jungle Waves 2 |
520 | 0x002C6, // Jungle Waves 3 | 520 | 0x002C6, // Jungle Waves 3 |
@@ -533,7 +533,7 @@ std::vector<int> junglePanels = { | |||
533 | }; | 533 | }; |
534 | 534 | ||
535 | // There might be something to do with these, I haven't decided yet. | 535 | // There might be something to do with these, I haven't decided yet. |
536 | std::vector<int> nothingPanels = { | 536 | const std::vector<int> nothingPanels = { |
537 | // Doors & Shortcuts & Shortcut doors & Door controls | 537 | // Doors & Shortcuts & Shortcut doors & Door controls |
538 | 0x0C339, // Desert Surface Door | 538 | 0x0C339, // Desert Surface Door |
539 | 0x0A249, // Desert Pond Exit Door | 539 | 0x0A249, // Desert Pond Exit Door |
diff --git a/WitnessRandomizer/WitnessRandomizer.cpp b/WitnessRandomizer/WitnessRandomizer.cpp index efe18b5..d71cc21 100644 --- a/WitnessRandomizer/WitnessRandomizer.cpp +++ b/WitnessRandomizer/WitnessRandomizer.cpp | |||
@@ -1,5 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * BUGS: | 2 | * BUGS: |
3 | * Shipwreck vault fails, possibly because of dot_reflection? | ||
3 | * Treehouse pivots *should* work, but I need to not copy style_flags. | 4 | * Treehouse pivots *should* work, but I need to not copy style_flags. |
4 | This seems to cause crashes when pivots appear elsewhere in the world. | 5 | This seems to cause crashes when pivots appear elsewhere in the world. |
5 | * FEATURES: | 6 | * FEATURES: |
@@ -17,23 +18,26 @@ | |||
17 | #include <string> | 18 | #include <string> |
18 | #include <iostream> | 19 | #include <iostream> |
19 | #include <numeric> | 20 | #include <numeric> |
21 | #include <chrono> | ||
20 | 22 | ||
21 | template <class T> | 23 | template <class T> |
22 | int find(const std::vector<T> &data, T search, int startIndex = 0) { | 24 | size_t find(const std::vector<T> &data, T search, size_t startIndex = 0) { |
23 | for (int i=startIndex ; i<data.size(); i++) { | 25 | for (size_t i=startIndex ; i<data.size(); i++) { |
24 | if (data[i] == search) return i; | 26 | if (data[i] == search) return i; |
25 | } | 27 | } |
26 | return -1; | 28 | std::cout << "Couldn't find " << search << " in data!" << std::endl; |
29 | exit(-1); | ||
27 | } | 30 | } |
28 | 31 | ||
29 | int main(int argc, char** argv) | 32 | int main(int argc, char** argv) |
30 | { | 33 | { |
34 | |||
31 | WitnessRandomizer randomizer = WitnessRandomizer(); | 35 | WitnessRandomizer randomizer = WitnessRandomizer(); |
32 | 36 | ||
33 | if (argc == 2) { | 37 | if (argc == 2) { |
34 | srand(atoi(argv[1])); // Seed from the command line | 38 | srand(atoi(argv[1])); // Seed from the command line |
35 | } else { | 39 | } else { |
36 | int seed = time(0) % (1 << 16); // Seed from the time in milliseconds | 40 | int seed = time(nullptr) % (1 << 16); // Seed from the time in milliseconds |
37 | std::cout << "Selected seed: " << seed << std::endl; | 41 | std::cout << "Selected seed: " << seed << std::endl; |
38 | srand(seed); | 42 | srand(seed); |
39 | } | 43 | } |
@@ -71,7 +75,7 @@ int main(int argc, char** argv) | |||
71 | // Glass 1 will become door + glass 1, due to the targetting system | 75 | // Glass 1 will become door + glass 1, due to the targetting system |
72 | randomizer.RandomizeRange(randomOrder, SWAP_NONE, 1, 10); | 76 | randomizer.RandomizeRange(randomOrder, SWAP_NONE, 1, 10); |
73 | // Randomize Glass 1-3 into everything after the door | 77 | // Randomize Glass 1-3 into everything after the door |
74 | int glassDoorIndex = find(randomOrder, 9) + 1; | 78 | const size_t glassDoorIndex = find(randomOrder, 9) + 1; |
75 | randomizer.RandomizeRange(randomOrder, SWAP_NONE, glassDoorIndex, 12); | 79 | randomizer.RandomizeRange(randomOrder, SWAP_NONE, glassDoorIndex, 12); |
76 | randomizer.ReassignTargets(bunkerPanels, randomOrder); | 80 | randomizer.ReassignTargets(bunkerPanels, randomOrder); |
77 | 81 | ||
@@ -121,17 +125,17 @@ WitnessRandomizer::WitnessRandomizer() | |||
121 | WritePanelData<float>(0x002C2, CURSOR_SPEED_SCALE, {1.0}); | 125 | WritePanelData<float>(0x002C2, CURSOR_SPEED_SCALE, {1.0}); |
122 | } | 126 | } |
123 | 127 | ||
124 | void WitnessRandomizer::Randomize(std::vector<int> &panels, int flags) { | 128 | void WitnessRandomizer::Randomize(const std::vector<int>& panels, int flags) { |
125 | return RandomizeRange(panels, flags, 0, panels.size()); | 129 | return RandomizeRange(panels, flags, 0, panels.size()); |
126 | } | 130 | } |
127 | 131 | ||
128 | // Range is [start, end) | 132 | // Range is [start, end) |
129 | void WitnessRandomizer::RandomizeRange(std::vector<int> &panels, int flags, size_t startIndex, size_t endIndex) { | 133 | void WitnessRandomizer::RandomizeRange(std::vector<int> panels, int flags, size_t startIndex, size_t endIndex) { |
130 | if (panels.size() == 0) return; | 134 | if (panels.size() == 0) return; |
131 | if (startIndex >= endIndex) return; | 135 | if (startIndex >= endIndex) return; |
132 | if (endIndex >= panels.size()) endIndex = panels.size(); | 136 | if (endIndex >= panels.size()) endIndex = panels.size(); |
133 | for (size_t i = endIndex-1; i > startIndex+1; i--) { | 137 | for (size_t i = endIndex-1; i > startIndex+1; i--) { |
134 | size_t target = rand() % (i - startIndex) + startIndex; | 138 | const size_t target = rand() % (i - startIndex) + startIndex; |
135 | if (i != target) { | 139 | if (i != target) { |
136 | // std::cout << "Swapping panels " << std::hex << panels[i] << " and " << std::hex << panels[target] << std::endl; | 140 | // std::cout << "Swapping panels " << std::hex << panels[i] << " and " << std::hex << panels[target] << std::endl; |
137 | SwapPanels(panels[i], panels[target], flags); | 141 | SwapPanels(panels[i], panels[target], flags); |
@@ -215,17 +219,17 @@ void WitnessRandomizer::SwapPanels(int panel1, int panel2, int flags) { | |||
215 | } | 219 | } |
216 | 220 | ||
217 | void WitnessRandomizer::ReassignTargets(const std::vector<int>& panels, const std::vector<int>& order) { | 221 | void WitnessRandomizer::ReassignTargets(const std::vector<int>& panels, const std::vector<int>& order) { |
222 | // This list is offset by 1, so the target of the Nth panel is in position N (aka the N+1th element) | ||
223 | // The first panel may not have a wire to power it, so we use the panel ID itself. | ||
218 | std::vector<int> targetToActivatePanel = {panels[0] + 1}; | 224 | std::vector<int> targetToActivatePanel = {panels[0] + 1}; |
219 | for (int panel : panels) { | 225 | for (const int panel : panels) { |
220 | int target = ReadPanelData<int>(panel, TARGET, 1)[0]; | 226 | int target = ReadPanelData<int>(panel, TARGET, 1)[0]; |
221 | targetToActivatePanel.push_back(target); | 227 | targetToActivatePanel.push_back(target); |
222 | } | 228 | } |
223 | 229 | ||
224 | for (int i=0; i<order.size() - 1; i++) { | 230 | for (size_t i=0; i<order.size() - 1; i++) { |
225 | // order[i+1] is the target panel | 231 | // Set the target of order[i] to order[i+1], using the "real" target as determined above. |
226 | // order[i+1] - 1 is the (real) panel before the target panel | 232 | const int panelTarget = targetToActivatePanel[order[i+1]]; |
227 | // targets[order[i+1] - 1] is the (real) target which will activate the target panel | ||
228 | int panelTarget = targetToActivatePanel[order[i+1]]; | ||
229 | WritePanelData<int>(panels[order[i]], TARGET, {panelTarget}); | 233 | WritePanelData<int>(panels[order[i]], TARGET, {panelTarget}); |
230 | } | 234 | } |
231 | } | 235 | } |
diff --git a/WitnessRandomizer/WitnessRandomizer.h b/WitnessRandomizer/WitnessRandomizer.h index 0e88cee..3d748d1 100644 --- a/WitnessRandomizer/WitnessRandomizer.h +++ b/WitnessRandomizer/WitnessRandomizer.h | |||
@@ -12,13 +12,13 @@ class WitnessRandomizer { | |||
12 | public: | 12 | public: |
13 | WitnessRandomizer(); | 13 | WitnessRandomizer(); |
14 | 14 | ||
15 | void Randomize(std::vector<int> &panels, int flags); | 15 | void Randomize(const std::vector<int>& panels, int flags); |
16 | void RandomizeRange(std::vector<int> &panels, int flags, size_t startIndex, size_t endIndex); | 16 | void RandomizeRange(std::vector<int> panels, int flags, size_t startIndex, size_t endIndex); |
17 | void SwapPanels(int panel1, int panel2, int flags); | 17 | void SwapPanels(int panel1, int panel2, int flags); |
18 | void ReassignTargets(const std::vector<int>& panels, const std::vector<int>& order); | 18 | void ReassignTargets(const std::vector<int>& panels, const std::vector<int>& order); |
19 | 19 | ||
20 | template <class T> | 20 | template <class T> |
21 | std::vector<T> ReadPanelData(int panel, int offset, int size) { | 21 | std::vector<T> ReadPanelData(int panel, int offset, size_t size) { |
22 | return _memory.ReadData<T>({GLOBALS, 0x18, panel*8, offset}, size); | 22 | return _memory.ReadData<T>({GLOBALS, 0x18, panel*8, offset}, size); |
23 | } | 23 | } |
24 | 24 | ||
diff --git a/WitnessRandomizer/WitnessRandomizer.vcxproj b/WitnessRandomizer/WitnessRandomizer.vcxproj index 49bd186..a737dd3 100644 --- a/WitnessRandomizer/WitnessRandomizer.vcxproj +++ b/WitnessRandomizer/WitnessRandomizer.vcxproj | |||
@@ -81,6 +81,8 @@ | |||
81 | </PropertyGroup> | 81 | </PropertyGroup> |
82 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | 82 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |
83 | <LinkIncremental>false</LinkIncremental> | 83 | <LinkIncremental>false</LinkIncremental> |
84 | <CodeAnalysisRuleSet>NativeRecommendedRules.ruleset</CodeAnalysisRuleSet> | ||
85 | <RunCodeAnalysis>true</RunCodeAnalysis> | ||
84 | </PropertyGroup> | 86 | </PropertyGroup> |
85 | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | 87 | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
86 | <ClCompile> | 88 | <ClCompile> |
@@ -134,7 +136,7 @@ | |||
134 | </ItemDefinitionGroup> | 136 | </ItemDefinitionGroup> |
135 | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | 137 | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |
136 | <ClCompile> | 138 | <ClCompile> |
137 | <PrecompiledHeader>Use</PrecompiledHeader> | 139 | <PrecompiledHeader>NotUsing</PrecompiledHeader> |
138 | <WarningLevel>Level3</WarningLevel> | 140 | <WarningLevel>Level3</WarningLevel> |
139 | <Optimization>MaxSpeed</Optimization> | 141 | <Optimization>MaxSpeed</Optimization> |
140 | <FunctionLevelLinking>true</FunctionLevelLinking> | 142 | <FunctionLevelLinking>true</FunctionLevelLinking> |
@@ -143,6 +145,10 @@ | |||
143 | <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | 145 | <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
144 | <ConformanceMode>true</ConformanceMode> | 146 | <ConformanceMode>true</ConformanceMode> |
145 | <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | 147 | <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> |
148 | <LanguageStandard>stdcpp17</LanguageStandard> | ||
149 | <EnablePREfast>true</EnablePREfast> | ||
150 | <TreatWarningAsError>true</TreatWarningAsError> | ||
151 | <DisableSpecificWarnings>26451</DisableSpecificWarnings> | ||
146 | </ClCompile> | 152 | </ClCompile> |
147 | <Link> | 153 | <Link> |
148 | <SubSystem>Console</SubSystem> | 154 | <SubSystem>Console</SubSystem> |