about summary refs log tree commit diff stats
path: root/WitnessRandomizer/WitnessRandomizer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WitnessRandomizer/WitnessRandomizer.cpp')
-rw-r--r--WitnessRandomizer/WitnessRandomizer.cpp153
1 files changed, 77 insertions, 76 deletions
diff --git a/WitnessRandomizer/WitnessRandomizer.cpp b/WitnessRandomizer/WitnessRandomizer.cpp index fcce107..dacb8fe 100644 --- a/WitnessRandomizer/WitnessRandomizer.cpp +++ b/WitnessRandomizer/WitnessRandomizer.cpp
@@ -30,12 +30,11 @@ int main(int argc, char** argv)
30 if (argc == 2) { 30 if (argc == 2) {
31 srand(atoi(argv[1])); // Seed with RNG from command line 31 srand(atoi(argv[1])); // Seed with RNG from command line
32 } else { 32 } else {
33 int seed = rand() % 1 << 16; 33 int seed = rand() % (1 << 16);
34 std::cout << "Selected seed:" << seed << std::endl; 34 std::cout << "Selected seed: " << seed << std::endl;
35 srand(seed); 35 srand(seed);
36 } 36 }
37 37
38
39 // Content swaps -- must happen before squarePanels 38 // Content swaps -- must happen before squarePanels
40 randomizer.Randomize(upDownPanels, SWAP_LINES | SWAP_STYLE); 39 randomizer.Randomize(upDownPanels, SWAP_LINES | SWAP_STYLE);
41 randomizer.Randomize(leftForwardRightPanels, SWAP_LINES); 40 randomizer.Randomize(leftForwardRightPanels, SWAP_LINES);
@@ -48,8 +47,8 @@ int main(int argc, char** argv)
48 // Target swaps, can happen whenever 47 // Target swaps, can happen whenever
49 randomizer.Randomize(lasers, SWAP_TARGETS); 48 randomizer.Randomize(lasers, SWAP_TARGETS);
50 // Read the target of keep front laser, and write it to keep back laser. 49 // Read the target of keep front laser, and write it to keep back laser.
51 std::vector<int> keepFrontLaserTarget = randomizer.ReadPanelData<int>(0x0360E, 0x2BC, 1); 50 std::vector<int> keepFrontLaserTarget = randomizer.ReadPanelData<int>(0x0360E, TARGET, 1);
52 randomizer.WritePanelData<int>(0x03317, 0x2BC, keepFrontLaserTarget); 51 randomizer.WritePanelData<int>(0x03317, TARGET, keepFrontLaserTarget);
53 52
54 std::vector<int> randomOrder = std::vector(junglePanels.size(), 0); 53 std::vector<int> randomOrder = std::vector(junglePanels.size(), 0);
55 std::iota(randomOrder.begin(), randomOrder.end(), 0); 54 std::iota(randomOrder.begin(), randomOrder.end(), 0);
@@ -79,30 +78,30 @@ int main(int argc, char** argv)
79 randomizer.ReassignTargets(shadowsPanels, randomOrder); 78 randomizer.ReassignTargets(shadowsPanels, randomOrder);
80 79
81 // Turn off original starting panel 80 // Turn off original starting panel
82 randomizer.WritePanelData<float>(shadowsPanels[0], 0x2A8, {0.0f, 0.0f}); 81 randomizer.WritePanelData<float>(shadowsPanels[0], POWER, {0.0f, 0.0f});
83 // Turn on new starting panel 82 // Turn on new starting panel
84 randomizer.WritePanelData<float>(shadowsPanels[randomOrder[0]], 0x2A8, {1.0f, 1.0f}); 83 randomizer.WritePanelData<float>(shadowsPanels[randomOrder[0]], POWER, {1.0f, 1.0f});
85} 84}
86 85
87WitnessRandomizer::WitnessRandomizer() : _memory("witness64_d3d11.exe") 86WitnessRandomizer::WitnessRandomizer()
88{ 87{
89 // Turn off desert flood final 88 // Turn off desert flood final
90 WritePanelData<float>(0x18076, 0x2A8, {0.0f, 0.0f}); 89 WritePanelData<float>(0x18076, POWER, {0.0f, 0.0f});
91 // Change desert floating target to desert flood final 90 // Change desert floating target to desert flood final
92 WritePanelData<int>(0x17ECA, 0x2BC, {0x18077}); 91 WritePanelData<int>(0x17ECA, TARGET, {0x18077});
93 92
94 // Distance-gate shadows laser to prevent sniping through the bars 93 // Distance-gate shadows laser to prevent sniping through the bars
95 WritePanelData<float>(0x19650, 0x3C0, {2.5f}); 94 WritePanelData<float>(0x19650, MAX_BROADCAST_DISTANCE, {2.5f});
96 // Change the shadows tutorial cable to only activate avoid 95 // Change the shadows tutorial cable to only activate avoid
97 WritePanelData<int>(0x319A8, 0xD8, {0}); 96 WritePanelData<int>(0x319A8, 0xD8, {0});
98 // Change shadows avoid 8 to power shadows follow 97 // Change shadows avoid 8 to power shadows follow
99 WritePanelData<int>(0x1972F, 0x2BC, {0x1C34C}); 98 WritePanelData<int>(0x1972F, TARGET, {0x1C34C});
100 99
101 // Disable tutorial cursor speed modifications 100 // Disable tutorial cursor speed modifications
102 WritePanelData<float>(0x00295, 0x358, {1.0}); 101 WritePanelData<float>(0x00295, CURSOR_SPEED_SCALE, {1.0});
103 WritePanelData<float>(0x0C373, 0x358, {1.0}); 102 WritePanelData<float>(0x0C373, CURSOR_SPEED_SCALE, {1.0});
104 WritePanelData<float>(0x00293, 0x358, {1.0}); 103 WritePanelData<float>(0x00293, CURSOR_SPEED_SCALE, {1.0});
105 WritePanelData<float>(0x002C2, 0x358, {1.0}); 104 WritePanelData<float>(0x002C2, CURSOR_SPEED_SCALE, {1.0});
106} 105}
107 106
108void WitnessRandomizer::Randomize(std::vector<int> &panels, int flags) { 107void WitnessRandomizer::Randomize(std::vector<int> &panels, int flags) {
@@ -128,78 +127,80 @@ void WitnessRandomizer::SwapPanels(int panel1, int panel2, int flags) {
128 std::map<int, int> offsets; 127 std::map<int, int> offsets;
129 128
130 if (flags & SWAP_TARGETS) { 129 if (flags & SWAP_TARGETS) {
131 offsets[0x2BC] = sizeof(int); 130 offsets[TARGET] = sizeof(int);
132 } 131 }
133 if (flags & SWAP_STYLE) { 132 if (flags & SWAP_STYLE) {
134 offsets[0x450] = sizeof(int); // style_flags 133 offsets[STYLE_FLAGS] = sizeof(int);
135 } 134 }
136 if (flags & SWAP_LINES) { 135 if (flags & SWAP_LINES) {
137 offsets[0xC8] = 16; // path_color 136 offsets[PATH_COLOR] = 16;
138 offsets[0xD8] = 16; // reflection_path_color 137 offsets[REFLECTION_PATH_COLOR] = 16;
139 offsets[0xF8] = 16; // dot_color 138 offsets[DOT_COLOR] = 16;
140 offsets[0x108] = 16; // active_color 139 offsets[ACTIVE_COLOR] = 16;
141 offsets[0x118] = 16; // background_region_color 140 offsets[BACKGROUND_REGION_COLOR] = 16;
142 offsets[0x128] = 16; // success_color_a 141 offsets[SUCCESS_COLOR_A] = 16;
143 offsets[0x138] = 16; // success_color_b 142 offsets[SUCCESS_COLOR_B] = 16;
144 offsets[0x148] = 16; // strobe_color_a 143 offsets[STROBE_COLOR_A] = 16;
145 offsets[0x158] = 16; // strobe_color_b 144 offsets[STROBE_COLOR_B] = 16;
146 offsets[0x168] = 16; // error_color 145 offsets[ERROR_COLOR] = 16;
147 offsets[0x188] = 16; // pattern_point_color 146 offsets[PATTERN_POINT_COLOR] = 16;
148 offsets[0x198] = 16; // pattern_point_color_a 147 offsets[PATTERN_POINT_COLOR_A] = 16;
149 offsets[0x1A8] = 16; // pattern_point_color_b 148 offsets[PATTERN_POINT_COLOR_B] = 16;
150 offsets[0x1B8] = 16; // symbol_a 149 offsets[SYMBOL_A] = 16;
151 offsets[0x1C8] = 16; // symbol_b 150 offsets[SYMBOL_B] = 16;
152 offsets[0x1D8] = 16; // symbol_c 151 offsets[SYMBOL_C] = 16;
153 offsets[0x1E8] = 16; // symbol_d 152 offsets[SYMBOL_D] = 16;
154 offsets[0x1F8] = 16; // symbol_e 153 offsets[SYMBOL_E] = 16;
155 offsets[0x208] = sizeof(int); // push_symbol_colors 154 offsets[PUSH_SYMBOL_COLORS] = sizeof(int);
156 offsets[0x20C] = 16; // outer_background 155 offsets[OUTER_BACKGROUND] = 16;
157 offsets[0x21C] = sizeof(int); // outer_background_mode 156 offsets[OUTER_BACKGROUND_MODE] = sizeof(int);
158 offsets[0x230] = 16; // traced_edges 157 offsets[TRACED_EDGES] = 16;
159 offsets[0x278] = sizeof(void*); // *audio_prefix 158 offsets[AUDIO_PREFIX] = sizeof(void*);
160 offsets[0x2FC] = sizeof(int); // is_cylinder 159// offsets[IS_CYLINDER] = sizeof(int);
161 offsets[0x300] = sizeof(float); // cylinder_z0 160// offsets[CYLINDER_Z0] = sizeof(float);
162 offsets[0x304] = sizeof(float); // cylinder_z1 161// offsets[CYLINDER_Z1] = sizeof(float);
163 offsets[0x308] = sizeof(float); // cylinder_radius 162// offsets[CYLINDER_RADIUS] = sizeof(float);
164 offsets[0x398] = sizeof(float); // specular_add 163 offsets[SPECULAR_ADD] = sizeof(float);
165 offsets[0x39C] = sizeof(int); // specular_power 164 offsets[SPECULAR_POWER] = sizeof(int);
166 offsets[0x3A4] = sizeof(float); // path_width_scale 165 offsets[PATH_WIDTH_SCALE] = sizeof(float);
167 offsets[0x3A8] = sizeof(float); // startpoint_scale 166 offsets[STARTPOINT_SCALE] = sizeof(float);
168 offsets[0x3B8] = sizeof(int); // num_dots 167 offsets[NUM_DOTS] = sizeof(int);
169 offsets[0x3BC] = sizeof(int); // num_connections 168 offsets[NUM_CONNECTIONS] = sizeof(int);
170 offsets[0x3C8] = sizeof(void*); // *dot_positions 169 offsets[DOT_POSITIONS] = sizeof(void*);
171 offsets[0x3D0] = sizeof(void*); // *dot_flags 170 offsets[DOT_FLAGS] = sizeof(void*);
172 offsets[0x3D8] = sizeof(void*); // *dot_connection_a 171 offsets[DOT_CONNECTION_A] = sizeof(void*);
173 offsets[0x3E0] = sizeof(void*); // *dot_connection_b 172 offsets[DOT_CONNECTION_B] = sizeof(void*);
174 offsets[0x420] = sizeof(void*); // *decorations 173 offsets[DECORATIONS] = sizeof(void*);
175 offsets[0x428] = sizeof(void*); // *decoration_flags 174 offsets[DECORATION_FLAGS] = sizeof(void*);
176 offsets[0x430] = sizeof(void*); // *decoration_colors 175 offsets[DECORATION_COLORS] = sizeof(void*);
177 offsets[0x438] = sizeof(int); // num_decorations 176 offsets[NUM_DECORATIONS] = sizeof(int);
178 offsets[0x440] = sizeof(void*); // *reflection_data 177 offsets[REFLECTION_DATA] = sizeof(void*);
179 offsets[0x448] = sizeof(int); // grid_size_x 178 offsets[GRID_SIZE_X] = sizeof(int);
180 offsets[0x44C] = sizeof(int); // grid_size_y 179 offsets[GRID_SIZE_Y] = sizeof(int);
181 offsets[0x45C] = sizeof(int); // sequence_len 180 offsets[SEQUENCE_LEN] = sizeof(int);
182 offsets[0x460] = sizeof(void*); // *sequence 181 offsets[SEQUENCE] = sizeof(void*);
183 offsets[0x468] = sizeof(int); // dot_sequence_len 182 offsets[DOT_SEQUENCE_LEN] = sizeof(int);
184 offsets[0x470] = sizeof(void*); // *dot_sequence 183 offsets[DOT_SEQUENCE] = sizeof(void*);
185 offsets[0x478] = sizeof(int); // dot_sequence_len_reflection 184 offsets[DOT_SEQUENCE_LEN_REFLECTION] = sizeof(int);
186 offsets[0x480] = sizeof(void*); // *dot_sequence_reflection 185 offsets[DOT_SEQUENCE_REFLECTION] = sizeof(void*);
187 offsets[0x4A0] = sizeof(int); // num_colored_regions 186 offsets[NUM_COLORED_REGIONS] = sizeof(int);
188 offsets[0x4A8] = sizeof(void*); // *colored_regions 187 offsets[COLORED_REGIONS] = sizeof(void*);
189 offsets[0x4B0] = sizeof(void*); // *panel_target 188 offsets[PANEL_TARGET] = sizeof(void*);
190 offsets[0x4D8] = sizeof(void*); // *specular_texture 189 offsets[SPECULAR_TEXTURE] = sizeof(void*);
191 } 190 }
192 191
193 for (auto const& [offset, size] : offsets) { 192 for (auto const& [offset, size] : offsets) {
194 std::vector<byte> data = ReadPanelData<byte>(panel1, offset, size); 193 std::vector<byte> panel1data = ReadPanelData<byte>(panel1, offset, size);
195 WritePanelData<byte>(panel2, offset, data); 194 std::vector<byte> panel2data = ReadPanelData<byte>(panel2, offset, size);
195 WritePanelData<byte>(panel2, offset, panel1data);
196 WritePanelData<byte>(panel1, offset, panel2data);
196 } 197 }
197} 198}
198 199
199void WitnessRandomizer::ReassignTargets(const std::vector<int>& panels, const std::vector<int>& order) { 200void WitnessRandomizer::ReassignTargets(const std::vector<int>& panels, const std::vector<int>& order) {
200 std::vector<int> targetToActivatePanel = {panels[0] + 1}; 201 std::vector<int> targetToActivatePanel = {panels[0] + 1};
201 for (int panel : panels) { 202 for (int panel : panels) {
202 int target = ReadPanelData<int>(panel, 0x2BC, 1)[0]; 203 int target = ReadPanelData<int>(panel, TARGET, 1)[0];
203 targetToActivatePanel.push_back(target); 204 targetToActivatePanel.push_back(target);
204 } 205 }
205 206
@@ -208,6 +209,6 @@ void WitnessRandomizer::ReassignTargets(const std::vector<int>& panels, const st
208 // order[i+1] - 1 is the (real) panel before the target panel 209 // order[i+1] - 1 is the (real) panel before the target panel
209 // targets[order[i+1] - 1] is the (real) target which will activate the target panel 210 // targets[order[i+1] - 1] is the (real) target which will activate the target panel
210 int panelTarget = targetToActivatePanel[order[i+1]]; 211 int panelTarget = targetToActivatePanel[order[i+1]];
211 WritePanelData<int>(panels[order[i]], 0x2BC, {panelTarget}); 212 WritePanelData<int>(panels[order[i]], TARGET, {panelTarget});
212 } 213 }
213} 214}