From 2270169041973370d171347e534071d34b88714e Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Fri, 26 Oct 2018 19:34:45 -0700 Subject: Major cleanup. --- WitnessRandomizer/WitnessRandomizer.cpp | 153 +++++++++++--------------------- WitnessRandomizer/WitnessRandomizer.h | 17 ++-- 2 files changed, 60 insertions(+), 110 deletions(-) (limited to 'WitnessRandomizer') 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) // Target swaps, can happen whenever randomizer.Randomize(lasers, SWAP_TARGETS); // Read the target of keep front laser, and write it to keep back laser. - randomizer.Overwrite(0x0360E, 0x03317, 0x2BC, sizeof(int)); + std::vector keepFrontLaserTarget = randomizer.ReadPanelData(0x0360E, 0x2BC, 1); + randomizer.WritePanelData(0x03317, 0x2BC, keepFrontLaserTarget); std::vector randomOrder = std::vector(junglePanels.size(), 0); std::iota(randomOrder.begin(), randomOrder.end(), 0); @@ -76,34 +77,32 @@ int main(int argc, char** argv) randomizer.RandomizeRange(randomOrder, SWAP_NONE, 8, 16); // Avoid randomizer.RandomizeRange(randomOrder, SWAP_NONE, 16, 21); // Follow randomizer.ReassignTargets(shadowsPanels, randomOrder); - randomizer.TurnOff(shadowsPanels[0]); - randomizer.TurnOn(shadowsPanels[randomOrder[0]]); + + // Turn off original starting panel + randomizer.WritePanelData(shadowsPanels[0], 0x2A8, {0.0f, 0.0f}); + // Turn on new starting panel + randomizer.WritePanelData(shadowsPanels[randomOrder[0]], 0x2A8, {1.0f, 1.0f}); } WitnessRandomizer::WitnessRandomizer() : _memory("witness64_d3d11.exe") { // Turn off desert flood final - TurnOff(0x18076); + WritePanelData(0x18076, 0x2A8, {0.0f, 0.0f}); // Change desert floating target to desert flood final - _memory.WriteData({0x5B28C0, 0x18, 0x17ECA*8, 0x2BC}, {0x18077}); + WritePanelData(0x17ECA, 0x2BC, {0x18077}); + // Distance-gate shadows laser to prevent sniping through the bars - _memory.WriteData({0x5B28C0, 0x18, 0x19650*8, 0x3C0}, {2.5f}); + WritePanelData(0x19650, 0x3C0, {2.5f}); // Change the shadows tutorial cable to only activate avoid - _memory.WriteData({0x5B28C0, 0x18, 0x319A8*8, 0xD8}, {0}); + WritePanelData(0x319A8, 0xD8, {0}); // Change shadows avoid 8 to power shadows follow - _memory.WriteData({0x5B28C0, 0x18, 0x1972F*8, 0x2BC}, {0x1C34C}); - // Disable tutorial cursor speed modifications - _memory.WriteData({0x5B28C0, 0x18, 0x00295*8, 0x358}, {1.0}); - _memory.WriteData({0x5B28C0, 0x18, 0x0C373*8, 0x358}, {1.0}); - _memory.WriteData({0x5B28C0, 0x18, 0x00293*8, 0x358}, {1.0}); - _memory.WriteData({0x5B28C0, 0x18, 0x002C2*8, 0x358}, {1.0}); - - + WritePanelData(0x1972F, 0x2BC, {0x1C34C}); - // Explicitly set back-off distance for the challenge entry & final 2 pillars -// _memory.WriteData({0x5B28C0, 0x18, 0x9DD5*8, 0x22C}, {2.5f}); -// _memory.WriteData({0x5B28C0, 0x18, 0x1C31A*8, 0x22C}, {3.0f}); -// _memory.WriteData({0x5B28C0, 0x18, 0x1C319*8, 0x22C}, {3.0f}); + // Disable tutorial cursor speed modifications + WritePanelData(0x00295, 0x358, {1.0}); + WritePanelData(0x0C373, 0x358, {1.0}); + WritePanelData(0x00293, 0x358, {1.0}); + WritePanelData(0x002C2, 0x358, {1.0}); } void WitnessRandomizer::Randomize(std::vector &panels, int flags) { @@ -131,17 +130,37 @@ void WitnessRandomizer::SwapPanels(int panel1, int panel2, int flags) { if (flags & SWAP_TARGETS) { offsets[0x2BC] = sizeof(int); } + if (flags & SWAP_STYLE) { + offsets[0x450] = sizeof(int); // style_flags + } if (flags & SWAP_LINES) { + offsets[0xC8] = 16; // path_color + offsets[0xD8] = 16; // reflection_path_color + offsets[0xF8] = 16; // dot_color + offsets[0x108] = 16; // active_color + offsets[0x118] = 16; // background_region_color + offsets[0x128] = 16; // success_color_a + offsets[0x138] = 16; // success_color_b + offsets[0x148] = 16; // strobe_color_a + offsets[0x158] = 16; // strobe_color_b + offsets[0x168] = 16; // error_color + offsets[0x188] = 16; // pattern_point_color + offsets[0x198] = 16; // pattern_point_color_a + offsets[0x1A8] = 16; // pattern_point_color_b + offsets[0x1B8] = 16; // symbol_a + offsets[0x1C8] = 16; // symbol_b + offsets[0x1D8] = 16; // symbol_c + offsets[0x1E8] = 16; // symbol_d + offsets[0x1F8] = 16; // symbol_e + offsets[0x208] = sizeof(int); // push_symbol_colors + offsets[0x20C] = 16; // outer_background + offsets[0x21C] = sizeof(int); // outer_background_mode offsets[0x230] = 16; // traced_edges -// offsets[0x220] = sizeof(void*); // *pattern_name -// offsets[0x240] = sizeof(void*); // *mesh_name + offsets[0x278] = sizeof(void*); // *audio_prefix offsets[0x2FC] = sizeof(int); // is_cylinder offsets[0x300] = sizeof(float); // cylinder_z0 offsets[0x304] = sizeof(float); // cylinder_z1 offsets[0x308] = sizeof(float); // cylinder_radius -// offsets[0x35C] = sizeof(int); // solvable_from_behind - -// offsets[0x30C] = sizeof(float); // uv_to_world_scale offsets[0x398] = sizeof(float); // specular_add offsets[0x39C] = sizeof(int); // specular_power offsets[0x3A4] = sizeof(float); // path_width_scale @@ -152,9 +171,9 @@ void WitnessRandomizer::SwapPanels(int panel1, int panel2, int flags) { offsets[0x3D0] = sizeof(void*); // *dot_flags offsets[0x3D8] = sizeof(void*); // *dot_connection_a offsets[0x3E0] = sizeof(void*); // *dot_connection_b -// offsets[0x3E8] = sizeof(int); // randomize_on_power_on offsets[0x420] = sizeof(void*); // *decorations offsets[0x428] = sizeof(void*); // *decoration_flags + offsets[0x430] = sizeof(void*); // *decoration_colors offsets[0x438] = sizeof(int); // num_decorations offsets[0x440] = sizeof(void*); // *reflection_data offsets[0x448] = sizeof(int); // grid_size_x @@ -165,69 +184,22 @@ void WitnessRandomizer::SwapPanels(int panel1, int panel2, int flags) { offsets[0x470] = sizeof(void*); // *dot_sequence offsets[0x478] = sizeof(int); // dot_sequence_len_reflection offsets[0x480] = sizeof(void*); // *dot_sequence_reflection - offsets[0x4B0] = sizeof(void*); // *panel_target - offsets[0x4D8] = sizeof(void*); // *specular_texture - offsets[0xC8] = 16; // path_color - offsets[0xD8] = 16; // reflection_path_color -// offsets[0xE8] = 16; // deprecated_finished_path_color - offsets[0xF8] = 16; // dot_color - offsets[0x108] = 16; // active_color - offsets[0x118] = 16; // background_region_color - offsets[0x128] = 16; // success_color_a - offsets[0x138] = 16; // success_color_b - offsets[0x148] = 16; // strobe_color_a - offsets[0x158] = 16; // strobe_color_b - offsets[0x168] = 16; // error_color -// offsets[0x178] = 16; // video_status_color - offsets[0x188] = 16; // pattern_point_color - offsets[0x198] = 16; // pattern_point_color_a - offsets[0x1A8] = 16; // pattern_point_color_b - offsets[0x1B8] = 16; // symbol_a - offsets[0x1C8] = 16; // symbol_b - offsets[0x1D8] = 16; // symbol_c - offsets[0x1E8] = 16; // symbol_d - offsets[0x1F8] = 16; // symbol_e - offsets[0x208] = sizeof(int); // push_symbol_colors - offsets[0x20C] = 16; // outer_background - offsets[0x21C] = sizeof(int); // outer_background_mode - offsets[0x278] = sizeof(void*); // *audio_prefix - offsets[0x430] = sizeof(void*); // *decoration_colors offsets[0x4A0] = sizeof(int); // num_colored_regions offsets[0x4A8] = sizeof(void*); // *colored_regions -// offsets[0x4B8] = sizeof(void*); // *backing_texture - } - if (flags & SWAP_STYLE) { - offsets[0x450] = sizeof(int); // style_flags - } - /* - if (flags & SWAP_BACK_DISTANCE) { - offsets[0x22C] = sizeof(float); // extra_back_distance + offsets[0x4B0] = sizeof(void*); // *panel_target + offsets[0x4D8] = sizeof(void*); // *specular_texture } - */ for (auto const& [offset, size] : offsets) { - SwapPanelData(panel1, panel2, offset, size); - } -} - -/* -void WitnessRandomizer::SwapTargetList(const std::vector& initialOrder, const std::vector& randomizedOrder) { - std::vector> randomizedTargets; - for (int panel : randomizedOrder) { - randomizedTargets.push_back(_memory.ReadData({0x5B28C0, 0x18, panel*8, 0x2BC}, 1)); - } - for (int i=0; i target = randomizedTargets[i]; - _memory.WriteData({0x5B28C0, 0x18, panel*8, 0x2BC}, target); + std::vector data = ReadPanelData(panel1, offset, size); + WritePanelData(panel2, offset, data); } } -*/ void WitnessRandomizer::ReassignTargets(const std::vector& panels, const std::vector& order) { std::vector targetToActivatePanel = {panels[0] + 1}; for (int panel : panels) { - int target = _memory.ReadData({0x5B28C0, 0x18, panel*8, 0x2BC}, 1)[0]; + int target = ReadPanelData(panel, 0x2BC, 1)[0]; targetToActivatePanel.push_back(target); } @@ -236,31 +208,6 @@ void WitnessRandomizer::ReassignTargets(const std::vector& panels, const st // order[i+1] - 1 is the (real) panel before the target panel // targets[order[i+1] - 1] is the (real) target which will activate the target panel int panelTarget = targetToActivatePanel[order[i+1]]; - _memory.WriteData({0x5B28C0, 0x18, panels[order[i]]*8, 0x2BC}, {panelTarget}); + WritePanelData(panels[order[i]], 0x2BC, {panelTarget}); } } - -void WitnessRandomizer::SwapPanelData(int panel1, int panel2, int finalOffset, int dataSize) { - // Currently wired for old version - std::vector panel1Offset = {0x5B28C0, 0x18, panel1*8, finalOffset}; - std::vector panel2Offset = {0x5B28C0, 0x18, panel2*8, finalOffset}; - - std::vector panel1Data = _memory.ReadData(panel1Offset, dataSize); - std::vector panel2Data = _memory.ReadData(panel2Offset, dataSize); - - _memory.WriteData(panel2Offset, panel1Data); - _memory.WriteData(panel1Offset, panel2Data); -} - -void WitnessRandomizer::TurnOn(int panel) { - _memory.WriteData({0x5B28C0, 0x18, panel*8, 0x2A8}, {1.0f, 1.0f}); -} - -void WitnessRandomizer::TurnOff(int panel) { - _memory.WriteData({0x5B28C0, 0x18, panel*8, 0x2A8}, {0.0f, 0.0f}); -} - -void WitnessRandomizer::Overwrite(int panel1, int panel2, int offset, int size) { - std::vector data = _memory.ReadData({0x5B28C0, 0x18, panel1*8, offset}, size); - _memory.WriteData({0x5B28C0, 0x18, panel2*8, offset}, data); -} \ 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; int SWAP_TARGETS = 0x1; int SWAP_LINES = 0x2; int SWAP_STYLE = 0x4; -int SWAP_BACK_DISTANCE = 0x8; class WitnessRandomizer { public: - WitnessRandomizer(); void Randomize(std::vector &panels, int flags); void RandomizeRange(std::vector &panels, int flags, size_t startIndex, size_t endIndex); void SwapPanels(int panel1, int panel2, int flags); void ReassignTargets(const std::vector& panels, const std::vector& order); - void Overwrite(int panel1, int panel2, int offset, int size); -//private: - void TurnOn(int panel); - void TurnOff(int panel); + template + std::vector ReadPanelData(int panel, int offset, int size) { + return _memory.ReadData({_globals, 0x18, panel*8, offset}, size); + } - void SwapPanelData(int panel1, int panel2, int finalOffset, int dataSize); + template + void WritePanelData(int panel, int offset, const std::vector& data) { + _memory.WriteData({_globals, 0x18, panel*8, offset}, data); + } +private: Memory _memory; + int _globals = 0x5B28C0; }; \ No newline at end of file -- cgit 1.4.1