diff options
-rw-r--r-- | WitnessRandomizer/WitnessRandomizer.cpp | 153 | ||||
-rw-r--r-- | WitnessRandomizer/WitnessRandomizer.h | 17 |
2 files changed, 60 insertions, 110 deletions
diff --git a/WitnessRandomizer/WitnessRandomizer.cpp b/WitnessRandomizer/WitnessRandomizer.cpp index 47f9daa..fcce107 100644 --- a/WitnessRandomizer/WitnessRandomizer.cpp +++ b/WitnessRandomizer/WitnessRandomizer.cpp | |||
@@ -48,7 +48,8 @@ int main(int argc, char** argv) | |||
48 | // Target swaps, can happen whenever | 48 | // Target swaps, can happen whenever |
49 | randomizer.Randomize(lasers, SWAP_TARGETS); | 49 | randomizer.Randomize(lasers, SWAP_TARGETS); |
50 | // Read the target of keep front laser, and write it to keep back laser. | 50 | // Read the target of keep front laser, and write it to keep back laser. |
51 | randomizer.Overwrite(0x0360E, 0x03317, 0x2BC, sizeof(int)); | 51 | std::vector<int> keepFrontLaserTarget = randomizer.ReadPanelData<int>(0x0360E, 0x2BC, 1); |
52 | randomizer.WritePanelData<int>(0x03317, 0x2BC, keepFrontLaserTarget); | ||
52 | 53 | ||
53 | std::vector<int> randomOrder = std::vector(junglePanels.size(), 0); | 54 | std::vector<int> randomOrder = std::vector(junglePanels.size(), 0); |
54 | std::iota(randomOrder.begin(), randomOrder.end(), 0); | 55 | std::iota(randomOrder.begin(), randomOrder.end(), 0); |
@@ -76,34 +77,32 @@ int main(int argc, char** argv) | |||
76 | randomizer.RandomizeRange(randomOrder, SWAP_NONE, 8, 16); // Avoid | 77 | randomizer.RandomizeRange(randomOrder, SWAP_NONE, 8, 16); // Avoid |
77 | randomizer.RandomizeRange(randomOrder, SWAP_NONE, 16, 21); // Follow | 78 | randomizer.RandomizeRange(randomOrder, SWAP_NONE, 16, 21); // Follow |
78 | randomizer.ReassignTargets(shadowsPanels, randomOrder); | 79 | randomizer.ReassignTargets(shadowsPanels, randomOrder); |
79 | randomizer.TurnOff(shadowsPanels[0]); | 80 | |
80 | randomizer.TurnOn(shadowsPanels[randomOrder[0]]); | 81 | // Turn off original starting panel |
82 | randomizer.WritePanelData<float>(shadowsPanels[0], 0x2A8, {0.0f, 0.0f}); | ||
83 | // Turn on new starting panel | ||
84 | randomizer.WritePanelData<float>(shadowsPanels[randomOrder[0]], 0x2A8, {1.0f, 1.0f}); | ||
81 | } | 85 | } |
82 | 86 | ||
83 | WitnessRandomizer::WitnessRandomizer() : _memory("witness64_d3d11.exe") | 87 | WitnessRandomizer::WitnessRandomizer() : _memory("witness64_d3d11.exe") |
84 | { | 88 | { |
85 | // Turn off desert flood final | 89 | // Turn off desert flood final |
86 | TurnOff(0x18076); | 90 | WritePanelData<float>(0x18076, 0x2A8, {0.0f, 0.0f}); |
87 | // Change desert floating target to desert flood final | 91 | // Change desert floating target to desert flood final |
88 | _memory.WriteData<int>({0x5B28C0, 0x18, 0x17ECA*8, 0x2BC}, {0x18077}); | 92 | WritePanelData<int>(0x17ECA, 0x2BC, {0x18077}); |
93 | |||
89 | // Distance-gate shadows laser to prevent sniping through the bars | 94 | // Distance-gate shadows laser to prevent sniping through the bars |
90 | _memory.WriteData<float>({0x5B28C0, 0x18, 0x19650*8, 0x3C0}, {2.5f}); | 95 | WritePanelData<float>(0x19650, 0x3C0, {2.5f}); |
91 | // Change the shadows tutorial cable to only activate avoid | 96 | // Change the shadows tutorial cable to only activate avoid |
92 | _memory.WriteData<int>({0x5B28C0, 0x18, 0x319A8*8, 0xD8}, {0}); | 97 | WritePanelData<int>(0x319A8, 0xD8, {0}); |
93 | // Change shadows avoid 8 to power shadows follow | 98 | // Change shadows avoid 8 to power shadows follow |
94 | _memory.WriteData<int>({0x5B28C0, 0x18, 0x1972F*8, 0x2BC}, {0x1C34C}); | 99 | WritePanelData<int>(0x1972F, 0x2BC, {0x1C34C}); |
95 | // Disable tutorial cursor speed modifications | ||
96 | _memory.WriteData<float>({0x5B28C0, 0x18, 0x00295*8, 0x358}, {1.0}); | ||
97 | _memory.WriteData<float>({0x5B28C0, 0x18, 0x0C373*8, 0x358}, {1.0}); | ||
98 | _memory.WriteData<float>({0x5B28C0, 0x18, 0x00293*8, 0x358}, {1.0}); | ||
99 | _memory.WriteData<float>({0x5B28C0, 0x18, 0x002C2*8, 0x358}, {1.0}); | ||
100 | |||
101 | |||
102 | 100 | ||
103 | // Explicitly set back-off distance for the challenge entry & final 2 pillars | 101 | // Disable tutorial cursor speed modifications |
104 | // _memory.WriteData<float>({0x5B28C0, 0x18, 0x9DD5*8, 0x22C}, {2.5f}); | 102 | WritePanelData<float>(0x00295, 0x358, {1.0}); |
105 | // _memory.WriteData<float>({0x5B28C0, 0x18, 0x1C31A*8, 0x22C}, {3.0f}); | 103 | WritePanelData<float>(0x0C373, 0x358, {1.0}); |
106 | // _memory.WriteData<float>({0x5B28C0, 0x18, 0x1C319*8, 0x22C}, {3.0f}); | 104 | WritePanelData<float>(0x00293, 0x358, {1.0}); |
105 | WritePanelData<float>(0x002C2, 0x358, {1.0}); | ||
107 | } | 106 | } |
108 | 107 | ||
109 | void WitnessRandomizer::Randomize(std::vector<int> &panels, int flags) { | 108 | void WitnessRandomizer::Randomize(std::vector<int> &panels, int flags) { |
@@ -131,17 +130,37 @@ void WitnessRandomizer::SwapPanels(int panel1, int panel2, int flags) { | |||
131 | if (flags & SWAP_TARGETS) { | 130 | if (flags & SWAP_TARGETS) { |
132 | offsets[0x2BC] = sizeof(int); | 131 | offsets[0x2BC] = sizeof(int); |
133 | } | 132 | } |
133 | if (flags & SWAP_STYLE) { | ||
134 | offsets[0x450] = sizeof(int); // style_flags | ||
135 | } | ||
134 | if (flags & SWAP_LINES) { | 136 | if (flags & SWAP_LINES) { |
137 | offsets[0xC8] = 16; // path_color | ||
138 | offsets[0xD8] = 16; // reflection_path_color | ||
139 | offsets[0xF8] = 16; // dot_color | ||
140 | offsets[0x108] = 16; // active_color | ||
141 | offsets[0x118] = 16; // background_region_color | ||
142 | offsets[0x128] = 16; // success_color_a | ||
143 | offsets[0x138] = 16; // success_color_b | ||
144 | offsets[0x148] = 16; // strobe_color_a | ||
145 | offsets[0x158] = 16; // strobe_color_b | ||
146 | offsets[0x168] = 16; // error_color | ||
147 | offsets[0x188] = 16; // pattern_point_color | ||
148 | offsets[0x198] = 16; // pattern_point_color_a | ||
149 | offsets[0x1A8] = 16; // pattern_point_color_b | ||
150 | offsets[0x1B8] = 16; // symbol_a | ||
151 | offsets[0x1C8] = 16; // symbol_b | ||
152 | offsets[0x1D8] = 16; // symbol_c | ||
153 | offsets[0x1E8] = 16; // symbol_d | ||
154 | offsets[0x1F8] = 16; // symbol_e | ||
155 | offsets[0x208] = sizeof(int); // push_symbol_colors | ||
156 | offsets[0x20C] = 16; // outer_background | ||
157 | offsets[0x21C] = sizeof(int); // outer_background_mode | ||
135 | offsets[0x230] = 16; // traced_edges | 158 | offsets[0x230] = 16; // traced_edges |
136 | // offsets[0x220] = sizeof(void*); // *pattern_name | 159 | offsets[0x278] = sizeof(void*); // *audio_prefix |
137 | // offsets[0x240] = sizeof(void*); // *mesh_name | ||
138 | offsets[0x2FC] = sizeof(int); // is_cylinder | 160 | offsets[0x2FC] = sizeof(int); // is_cylinder |
139 | offsets[0x300] = sizeof(float); // cylinder_z0 | 161 | offsets[0x300] = sizeof(float); // cylinder_z0 |
140 | offsets[0x304] = sizeof(float); // cylinder_z1 | 162 | offsets[0x304] = sizeof(float); // cylinder_z1 |
141 | offsets[0x308] = sizeof(float); // cylinder_radius | 163 | offsets[0x308] = sizeof(float); // cylinder_radius |
142 | // offsets[0x35C] = sizeof(int); // solvable_from_behind | ||
143 | |||
144 | // offsets[0x30C] = sizeof(float); // uv_to_world_scale | ||
145 | offsets[0x398] = sizeof(float); // specular_add | 164 | offsets[0x398] = sizeof(float); // specular_add |
146 | offsets[0x39C] = sizeof(int); // specular_power | 165 | offsets[0x39C] = sizeof(int); // specular_power |
147 | offsets[0x3A4] = sizeof(float); // path_width_scale | 166 | offsets[0x3A4] = sizeof(float); // path_width_scale |
@@ -152,9 +171,9 @@ void WitnessRandomizer::SwapPanels(int panel1, int panel2, int flags) { | |||
152 | offsets[0x3D0] = sizeof(void*); // *dot_flags | 171 | offsets[0x3D0] = sizeof(void*); // *dot_flags |
153 | offsets[0x3D8] = sizeof(void*); // *dot_connection_a | 172 | offsets[0x3D8] = sizeof(void*); // *dot_connection_a |
154 | offsets[0x3E0] = sizeof(void*); // *dot_connection_b | 173 | offsets[0x3E0] = sizeof(void*); // *dot_connection_b |
155 | // offsets[0x3E8] = sizeof(int); // randomize_on_power_on | ||
156 | offsets[0x420] = sizeof(void*); // *decorations | 174 | offsets[0x420] = sizeof(void*); // *decorations |
157 | offsets[0x428] = sizeof(void*); // *decoration_flags | 175 | offsets[0x428] = sizeof(void*); // *decoration_flags |
176 | offsets[0x430] = sizeof(void*); // *decoration_colors | ||
158 | offsets[0x438] = sizeof(int); // num_decorations | 177 | offsets[0x438] = sizeof(int); // num_decorations |
159 | offsets[0x440] = sizeof(void*); // *reflection_data | 178 | offsets[0x440] = sizeof(void*); // *reflection_data |
160 | offsets[0x448] = sizeof(int); // grid_size_x | 179 | offsets[0x448] = sizeof(int); // grid_size_x |
@@ -165,69 +184,22 @@ void WitnessRandomizer::SwapPanels(int panel1, int panel2, int flags) { | |||
165 | offsets[0x470] = sizeof(void*); // *dot_sequence | 184 | offsets[0x470] = sizeof(void*); // *dot_sequence |
166 | offsets[0x478] = sizeof(int); // dot_sequence_len_reflection | 185 | offsets[0x478] = sizeof(int); // dot_sequence_len_reflection |
167 | offsets[0x480] = sizeof(void*); // *dot_sequence_reflection | 186 | offsets[0x480] = sizeof(void*); // *dot_sequence_reflection |
168 | offsets[0x4B0] = sizeof(void*); // *panel_target | ||
169 | offsets[0x4D8] = sizeof(void*); // *specular_texture | ||
170 | offsets[0xC8] = 16; // path_color | ||
171 | offsets[0xD8] = 16; // reflection_path_color | ||
172 | // offsets[0xE8] = 16; // deprecated_finished_path_color | ||
173 | offsets[0xF8] = 16; // dot_color | ||
174 | offsets[0x108] = 16; // active_color | ||
175 | offsets[0x118] = 16; // background_region_color | ||
176 | offsets[0x128] = 16; // success_color_a | ||
177 | offsets[0x138] = 16; // success_color_b | ||
178 | offsets[0x148] = 16; // strobe_color_a | ||
179 | offsets[0x158] = 16; // strobe_color_b | ||
180 | offsets[0x168] = 16; // error_color | ||
181 | // offsets[0x178] = 16; // video_status_color | ||
182 | offsets[0x188] = 16; // pattern_point_color | ||
183 | offsets[0x198] = 16; // pattern_point_color_a | ||
184 | offsets[0x1A8] = 16; // pattern_point_color_b | ||
185 | offsets[0x1B8] = 16; // symbol_a | ||
186 | offsets[0x1C8] = 16; // symbol_b | ||
187 | offsets[0x1D8] = 16; // symbol_c | ||
188 | offsets[0x1E8] = 16; // symbol_d | ||
189 | offsets[0x1F8] = 16; // symbol_e | ||
190 | offsets[0x208] = sizeof(int); // push_symbol_colors | ||
191 | offsets[0x20C] = 16; // outer_background | ||
192 | offsets[0x21C] = sizeof(int); // outer_background_mode | ||
193 | offsets[0x278] = sizeof(void*); // *audio_prefix | ||
194 | offsets[0x430] = sizeof(void*); // *decoration_colors | ||
195 | offsets[0x4A0] = sizeof(int); // num_colored_regions | 187 | offsets[0x4A0] = sizeof(int); // num_colored_regions |
196 | offsets[0x4A8] = sizeof(void*); // *colored_regions | 188 | offsets[0x4A8] = sizeof(void*); // *colored_regions |
197 | // offsets[0x4B8] = sizeof(void*); // *backing_texture | 189 | offsets[0x4B0] = sizeof(void*); // *panel_target |
198 | } | 190 | offsets[0x4D8] = sizeof(void*); // *specular_texture |
199 | if (flags & SWAP_STYLE) { | ||
200 | offsets[0x450] = sizeof(int); // style_flags | ||
201 | } | ||
202 | /* | ||
203 | if (flags & SWAP_BACK_DISTANCE) { | ||
204 | offsets[0x22C] = sizeof(float); // extra_back_distance | ||
205 | } | 191 | } |
206 | */ | ||
207 | 192 | ||
208 | for (auto const& [offset, size] : offsets) { | 193 | for (auto const& [offset, size] : offsets) { |
209 | SwapPanelData(panel1, panel2, offset, size); | 194 | std::vector<byte> data = ReadPanelData<byte>(panel1, offset, size); |
210 | } | 195 | WritePanelData<byte>(panel2, offset, data); |
211 | } | ||
212 | |||
213 | /* | ||
214 | void WitnessRandomizer::SwapTargetList(const std::vector<int>& initialOrder, const std::vector<int>& randomizedOrder) { | ||
215 | std::vector<std::vector<int>> randomizedTargets; | ||
216 | for (int panel : randomizedOrder) { | ||
217 | randomizedTargets.push_back(_memory.ReadData<int>({0x5B28C0, 0x18, panel*8, 0x2BC}, 1)); | ||
218 | } | ||
219 | for (int i=0; i<initialOrder.size(); i++) { | ||
220 | int panel = initialOrder[i]; | ||
221 | std::vector<int> target = randomizedTargets[i]; | ||
222 | _memory.WriteData<int>({0x5B28C0, 0x18, panel*8, 0x2BC}, target); | ||
223 | } | 196 | } |
224 | } | 197 | } |
225 | */ | ||
226 | 198 | ||
227 | void WitnessRandomizer::ReassignTargets(const std::vector<int>& panels, const std::vector<int>& order) { | 199 | void WitnessRandomizer::ReassignTargets(const std::vector<int>& panels, const std::vector<int>& order) { |
228 | std::vector<int> targetToActivatePanel = {panels[0] + 1}; | 200 | std::vector<int> targetToActivatePanel = {panels[0] + 1}; |
229 | for (int panel : panels) { | 201 | for (int panel : panels) { |
230 | int target = _memory.ReadData<int>({0x5B28C0, 0x18, panel*8, 0x2BC}, 1)[0]; | 202 | int target = ReadPanelData<int>(panel, 0x2BC, 1)[0]; |
231 | targetToActivatePanel.push_back(target); | 203 | targetToActivatePanel.push_back(target); |
232 | } | 204 | } |
233 | 205 | ||
@@ -236,31 +208,6 @@ void WitnessRandomizer::ReassignTargets(const std::vector<int>& panels, const st | |||
236 | // order[i+1] - 1 is the (real) panel before the target panel | 208 | // order[i+1] - 1 is the (real) panel before the target panel |
237 | // targets[order[i+1] - 1] is the (real) target which will activate the target panel | 209 | // targets[order[i+1] - 1] is the (real) target which will activate the target panel |
238 | int panelTarget = targetToActivatePanel[order[i+1]]; | 210 | int panelTarget = targetToActivatePanel[order[i+1]]; |
239 | _memory.WriteData<int>({0x5B28C0, 0x18, panels[order[i]]*8, 0x2BC}, {panelTarget}); | 211 | WritePanelData<int>(panels[order[i]], 0x2BC, {panelTarget}); |
240 | } | 212 | } |
241 | } | 213 | } |
242 | |||
243 | void WitnessRandomizer::SwapPanelData(int panel1, int panel2, int finalOffset, int dataSize) { | ||
244 | // Currently wired for old version | ||
245 | std::vector<int> panel1Offset = {0x5B28C0, 0x18, panel1*8, finalOffset}; | ||
246 | std::vector<int> panel2Offset = {0x5B28C0, 0x18, panel2*8, finalOffset}; | ||
247 | |||
248 | std::vector<byte> panel1Data = _memory.ReadData<byte>(panel1Offset, dataSize); | ||
249 | std::vector<byte> panel2Data = _memory.ReadData<byte>(panel2Offset, dataSize); | ||
250 | |||
251 | _memory.WriteData<byte>(panel2Offset, panel1Data); | ||
252 | _memory.WriteData<byte>(panel1Offset, panel2Data); | ||
253 | } | ||
254 | |||
255 | void WitnessRandomizer::TurnOn(int panel) { | ||
256 | _memory.WriteData<float>({0x5B28C0, 0x18, panel*8, 0x2A8}, {1.0f, 1.0f}); | ||
257 | } | ||
258 | |||
259 | void WitnessRandomizer::TurnOff(int panel) { | ||
260 | _memory.WriteData<float>({0x5B28C0, 0x18, panel*8, 0x2A8}, {0.0f, 0.0f}); | ||
261 | } | ||
262 | |||
263 | void WitnessRandomizer::Overwrite(int panel1, int panel2, int offset, int size) { | ||
264 | std::vector<byte> data = _memory.ReadData<int>({0x5B28C0, 0x18, panel1*8, offset}, size); | ||
265 | _memory.WriteData<byte>({0x5B28C0, 0x18, panel2*8, offset}, data); | ||
266 | } \ No newline at end of file | ||
diff --git a/WitnessRandomizer/WitnessRandomizer.h b/WitnessRandomizer/WitnessRandomizer.h index 527fe13..a824fba 100644 --- a/WitnessRandomizer/WitnessRandomizer.h +++ b/WitnessRandomizer/WitnessRandomizer.h | |||
@@ -4,24 +4,27 @@ int SWAP_NONE = 0x0; | |||
4 | int SWAP_TARGETS = 0x1; | 4 | int SWAP_TARGETS = 0x1; |
5 | int SWAP_LINES = 0x2; | 5 | int SWAP_LINES = 0x2; |
6 | int SWAP_STYLE = 0x4; | 6 | int SWAP_STYLE = 0x4; |
7 | int SWAP_BACK_DISTANCE = 0x8; | ||
8 | 7 | ||
9 | class WitnessRandomizer { | 8 | class WitnessRandomizer { |
10 | public: | 9 | public: |
11 | |||
12 | WitnessRandomizer(); | 10 | WitnessRandomizer(); |
13 | 11 | ||
14 | void Randomize(std::vector<int> &panels, int flags); | 12 | void Randomize(std::vector<int> &panels, int flags); |
15 | void RandomizeRange(std::vector<int> &panels, int flags, size_t startIndex, size_t endIndex); | 13 | void RandomizeRange(std::vector<int> &panels, int flags, size_t startIndex, size_t endIndex); |
16 | void SwapPanels(int panel1, int panel2, int flags); | 14 | void SwapPanels(int panel1, int panel2, int flags); |
17 | void ReassignTargets(const std::vector<int>& panels, const std::vector<int>& order); | 15 | void ReassignTargets(const std::vector<int>& panels, const std::vector<int>& order); |
18 | void Overwrite(int panel1, int panel2, int offset, int size); | ||
19 | 16 | ||
20 | //private: | 17 | template <class T> |
21 | void TurnOn(int panel); | 18 | std::vector<T> ReadPanelData(int panel, int offset, int size) { |
22 | void TurnOff(int panel); | 19 | return _memory.ReadData<T>({_globals, 0x18, panel*8, offset}, size); |
20 | } | ||
23 | 21 | ||
24 | void SwapPanelData(int panel1, int panel2, int finalOffset, int dataSize); | 22 | template <class T> |
23 | void WritePanelData(int panel, int offset, const std::vector<T>& data) { | ||
24 | _memory.WriteData<T>({_globals, 0x18, panel*8, offset}, data); | ||
25 | } | ||
25 | 26 | ||
27 | private: | ||
26 | Memory _memory; | 28 | Memory _memory; |
29 | int _globals = 0x5B28C0; | ||
27 | }; \ No newline at end of file | 30 | }; \ No newline at end of file |