From d99313f4e4fdf5103c5f149e2d54dbf6e4fcc3f2 Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Sun, 28 Oct 2018 15:44:50 -0700 Subject: Fix treehouse pivots, jungle + monastery randomization, add final pillars randomization --- Source/Panels.h | 87 ++++++-------- Source/Randomizer.cpp | 286 +++++++++++++++++----------------------------- Source/Randomizer.h | 168 +++------------------------ Source/RandomizerCore.cpp | 119 +++++++++++++++++++ Source/RandomizerCore.h | 155 +++++++++++++++++++++++++ 5 files changed, 428 insertions(+), 387 deletions(-) create mode 100644 Source/RandomizerCore.cpp create mode 100644 Source/RandomizerCore.h (limited to 'Source') diff --git a/Source/Panels.h b/Source/Panels.h index e070005..b3a7791 100644 --- a/Source/Panels.h +++ b/Source/Panels.h @@ -17,50 +17,6 @@ std::vector lasers = { 0x19650, // Shadows }; -// Note: Some of these (non-desert) are duplicated elsewhere -std::vector burnablePanels = { - 0x17D9C, // Treehouse Yellow 7 - 0x17DC2, // Treehouse Yellow 8 - 0x17DC4, // Treehouse Yellow 9 - 0x00999, // Swamp Discontinuous 1 - 0x0099D, // Swamp Discontinuous 2 - 0x009A0, // Swamp Discontinuous 3 - 0x009A1, // Swamp Discontinuous 4 - 0x00007, // Swamp Rotation Tutorial 1 - 0x00008, // Swamp Rotation Tutorial 2 - 0x00009, // Swamp Rotation Tutorial 3 - 0x0000A, // Swamp Rotation Tutorial 4 - 0x28AC7, // Town Blue 1 - 0x28AC8, // Town Blue 2 - 0x28ACA, // Town Blue 3 - 0x28ACB, // Town Blue 4 - 0x28ACC, // Town Blue 5 - 0x17CF0, // Mill Discard - - 0x00698, // Desert Surface 1 - 0x0048F, // Desert Surface 2 - 0x09F92, // Desert Surface 3 - 0x0A036, // Desert Surface 4 - 0x09DA6, // Desert Surface 5 - 0x0A049, // Desert Surface 6 - 0x0A053, // Desert Surface 7 - 0x09F94, // Desert Surface 8 - 0x00422, // Desert Light 1 - 0x006E3, // Desert Light 2 - 0x0A02D, // Desert Light 3 - 0x00C72, // Desert Pond 1 - 0x0129D, // Desert Pond 2 - 0x008BB, // Desert Pond 3 - 0x0078D, // Desert Pond 4 - 0x18313, // Desert Pond 5 - 0x04D18, // Desert Flood 1 - 0x01205, // Desert Flood 2 - 0x181AB, // Desert Flood 3 - 0x0117A, // Desert Flood 4 - 0x17ECA, // Desert Flood 5 - 0x012D7, // Desert Final Far -}; - // Note: Some of these (non-controls) are duplicated elsewhere // TODO: Gave up std::vector leftRightPanels = { @@ -105,10 +61,10 @@ std::vector upDownPanels = { // Note: Some of these (non-controls) are duplicated elsewhere std::vector leftForwardRightPanels = { -// 0x00075, // Symmetry Island Colored Dots 3 -// 0x288EA, // UTM Perspective 1 -// 0x288FC, // UTM Perspective 2 -// 0x289E7, // UTM Perspective 3 + 0x00075, // Symmetry Island Colored Dots 3 + 0x288EA, // UTM Perspective 1 + 0x288FC, // UTM Perspective 2 + 0x289E7, // UTM Perspective 3 0x17DD1, // Treehouse Left Orange 9 0x17CE3, // Treehouse Right Orange 4 @@ -458,6 +414,35 @@ std::vector squarePanels = { 0x09E85, // Tunnels Town Shortcut }; +std::vector desertPanels = { + 0x00698, // Desert Surface 1 + 0x0048F, // Desert Surface 2 + 0x09F92, // Desert Surface 3 + 0x0A036, // Desert Surface 4 + 0x09DA6, // Desert Surface 5 + 0x0A049, // Desert Surface 6 + 0x0A053, // Desert Surface 7 + 0x09F94, // Desert Surface 8 + 0x00422, // Desert Light 1 + 0x006E3, // Desert Light 2 + 0x0A02D, // Desert Light 3 + 0x00C72, // Desert Pond 1 + 0x0129D, // Desert Pond 2 + 0x008BB, // Desert Pond 3 + 0x0078D, // Desert Pond 4 + 0x18313, // Desert Pond 5 + 0x04D18, // Desert Flood 1 + 0x01205, // Desert Flood 2 + 0x181AB, // Desert Flood 3 + 0x0117A, // Desert Flood 4 + 0x17ECA, // Desert Flood 5 +// 0x18076, // Desert Flood Exit +// 0x0A15C, // Desert Final Left Convex +// 0x09FFF, // Desert Final Left Concave +// 0x0A15F, // Desert Final Near + 0x012D7, // Desert Final Far +}; + std::vector shadowsPanels = { 0x198B5, // Shadows Tutorial 1 0x198BD, // Shadows Tutorial 2 @@ -485,8 +470,8 @@ std::vector shadowsPanels = { std::vector monasteryPanels = { 0x00B10, // Monastery Left Door - 0x00290, // Monastery Exterior 1 0x00C92, // Monastery Right Door + 0x00290, // Monastery Exterior 1 0x00038, // Monastery Exterior 2 0x00037, // Monastery Exterior 3 // 0x09D9B, // Monastery Bonsai @@ -616,10 +601,6 @@ std::vector nothingPanels = { 0x0C335, // Tutorial Pillar 0x0C373, // Tutorial Patio floor 0x1C349, // Symmetry Island Door 2 - Collision fails here, sadly - 0x18076, // Desert Flood Exit - I am doing something with this -- but it's a very unique panel. - 0x0A15C, // Desert Final Left Convex - 0x09FFF, // Desert Final Left Concave - 0x0A15F, // Desert Final Near 0x033EA, // Keep Yellow Pressure Plates 0x0A3A8, // Keep Yellow Reset 0x01BE9, // Keep Purple Pressure Plates diff --git a/Source/Randomizer.cpp b/Source/Randomizer.cpp index b8462e5..8c4297d 100644 --- a/Source/Randomizer.cpp +++ b/Source/Randomizer.cpp @@ -2,15 +2,10 @@ * TODO: Split out main() logic into another file, and move into separate functions for easier testing. Then write tests. * BUGS: * Shipwreck vault fails, possibly because of dot_reflection? Sometimes? - * Treehouse pivots *should* work, but I need to not copy style_flags. - This seems to cause crashes when pivots appear elsewhere in the world. * Some panels are impossible casually: (idc, I think) ** Town Stars, Invisible dots - * Something is wrong with jungle re: softlocks * FEATURES: * SWAP_TARGETS should still require the full panel sequence (and have ways to prevent softlocks?) - ** Think about: Jungle - ** Hard: Monastery ** Do: Challenge * Randomize audio logs * Swap sounds in jungle (along with panels) -- maybe impossible @@ -28,212 +23,139 @@ #include template -size_t find(const std::vector &data, T search, size_t startIndex = 0) { +int find(const std::vector &data, T search, size_t startIndex = 0) { for (size_t i=startIndex ; i(i); } std::cout << "Couldn't find " << search << " in data!" << std::endl; exit(-1); } -void Randomizer::Randomize(int seed) +void Randomizer::Randomize() { // Content swaps -- must happen before squarePanels - Randomize(tallUpDownPanels, SWAP_LINES | SWAP_STYLE); - Randomize(upDownPanels, SWAP_LINES | SWAP_STYLE); - Randomize(leftForwardRightPanels, SWAP_LINES); - - Randomize(squarePanels, SWAP_LINES | SWAP_STYLE); - - // Frame swaps -- must happen after squarePanels - Randomize(burnablePanels, SWAP_LINES | SWAP_STYLE); + _core.Randomize(tallUpDownPanels, SWAP_LINES|SWAP_LINES); + _core.Randomize(upDownPanels, SWAP_LINES|SWAP_LINES); + _core.Randomize(leftForwardRightPanels, SWAP_LINES|SWAP_LINES); + + _core.Randomize(squarePanels, SWAP_LINES|SWAP_LINES); + + // Individual area modifications + RandomizeTutorial(); + RandomizeSymmetry(); + RandomizeDesert(); + RandomizeQuarry(); + RandomizeTreehouse(); + RandomizeKeep(); + RandomizeShadows(); + RandomizeTown(); + RandomizeMonastery(); + RandomizeBunker(); + RandomizeJungle(); + RandomizeSwamp(); + RandomizeMountain(); +} - // Target swaps, can happen whenever - Randomize(lasers, SWAP_TARGETS); - // Read the target of keep front laser, and write it to keep back laser. - std::vector keepFrontLaserTarget = ReadPanelData(0x0360E, TARGET, 1); - WritePanelData(0x03317, TARGET, keepFrontLaserTarget); +void Randomizer::RandomizeTutorial() { + // Disable tutorial cursor speed modifications (not working?) + _core.WritePanelData(0x00295, CURSOR_SPEED_SCALE, {1.0}); + _core.WritePanelData(0x0C373, CURSOR_SPEED_SCALE, {1.0}); + _core.WritePanelData(0x00293, CURSOR_SPEED_SCALE, {1.0}); + _core.WritePanelData(0x002C2, CURSOR_SPEED_SCALE, {1.0}); +} - std::vector randomOrder; +void Randomizer::RandomizeSymmetry() { +} - /* Jungle - randomOrder = std::vector(junglePanels.size(), 0); - std::iota(randomOrder.begin(), randomOrder.end(), 0); - // Randomize Waves 2-7 - // Waves 1 cannot be randomized, since no other panel can start on - randomizer.RandomizeRange(randomOrder, SWAP_NONE, 1, 7); - // Randomize Pitches 1-6 onto themselves - randomizer.RandomizeRange(randomOrder, SWAP_NONE, 7, 13); - randomizer.ReassignTargets(junglePanels, randomOrder); - */ +void Randomizer::RandomizeDesert() { + _core.Randomize(desertPanels, SWAP_LINES|SWAP_LINES); - /* Bunker */ - randomOrder = std::vector(bunkerPanels.size(), 0); - std::iota(randomOrder.begin(), randomOrder.end(), 0); - // Randomize Tutorial 2-Advanced Tutorial 4 + Glass 1 - // Tutorial 1 cannot be randomized, since no other panel can start on - // Glass 1 will become door + glass 1, due to the targetting system - RandomizeRange(randomOrder, SWAP_NONE, 1, 10); - // Randomize Glass 1-3 into everything after the door - const size_t glassDoorIndex = find(randomOrder, 9) + 1; - RandomizeRange(randomOrder, SWAP_NONE, glassDoorIndex, 12); - ReassignTargets(bunkerPanels, randomOrder); - - /* Shadows */ - randomOrder = std::vector(shadowsPanels.size(), 0); - std::iota(randomOrder.begin(), randomOrder.end(), 0); - RandomizeRange(randomOrder, SWAP_NONE, 0, 8); // Tutorial - RandomizeRange(randomOrder, SWAP_NONE, 8, 16); // Avoid - RandomizeRange(randomOrder, SWAP_NONE, 16, 21); // Follow - ReassignTargets(shadowsPanels, randomOrder); - // Turn off original starting panel - WritePanelData(shadowsPanels[0], POWER, {0.0f, 0.0f}); - // Turn on new starting panel - WritePanelData(shadowsPanels[randomOrder[0]], POWER, {1.0f, 1.0f}); + // Turn off desert surface 8 + _core.WritePanelData(0x09F94, POWER, {0.0, 0.0}); + // Turn off desert flood final + _core.WritePanelData(0x18076, POWER, {0.0, 0.0}); + // Change desert floating target to desert flood final + _core.WritePanelData(0x17ECA, TARGET, {0x18077}); +} - /* Monastery - randomOrder = std::vector(monasteryPanels.size(), 0); - std::iota(randomOrder.begin(), randomOrder.end(), 0); - randomizer.RandomizeRange(randomOrder, SWAP_NONE, 2, 6); // outer 2 & 3, inner 1 - // Once outer 3 and right door are solved, inner 2-4 are accessible - int innerPanelsIndex = max(find(randomOrder, 2), find(randomOrder, 4)); - randomizer.RandomizeRange(randomOrder, SWAP_NONE, innerPanelsIndex, 9); // Inner 2-4 +void Randomizer::RandomizeQuarry() { +} - randomizer.ReassignTargets(monasteryPanels, randomOrder); - */ +void Randomizer::RandomizeTreehouse() { + // Ensure that whatever pivot panels we have are flagged as "pivotable" + _core.WritePanelData(0x17DD1, STYLE_FLAGS, {0x8000}); + _core.WritePanelData(0x17CE3, STYLE_FLAGS, {0x8000}); + _core.WritePanelData(0x17DB7, STYLE_FLAGS, {0x8000}); + _core.WritePanelData(0x17E52, STYLE_FLAGS, {0x8000}); } -Randomizer::Randomizer() -{ - // Turn off desert surface 8 - WritePanelData(0x09F94, POWER, {0.0, 0.0}); - // Turn off desert flood final - WritePanelData(0x18076, POWER, {0.0, 0.0}); - // Change desert floating target to desert flood final - WritePanelData(0x17ECA, TARGET, {0x18077}); +void Randomizer::RandomizeKeep() { +} +void Randomizer::RandomizeShadows() { // Distance-gate shadows laser to prevent sniping through the bars - WritePanelData(0x19650, MAX_BROADCAST_DISTANCE, {2.5}); + _core.WritePanelData(0x19650, MAX_BROADCAST_DISTANCE, {2.5}); // Change the shadows tutorial cable to only activate avoid - WritePanelData(0x319A8, CABLE_TARGET_2, {0}); + _core.WritePanelData(0x319A8, CABLE_TARGET_2, {0}); // Change shadows avoid 8 to power shadows follow - WritePanelData(0x1972F, TARGET, {0x1C34C}); - - // Distance-gate swamp snipe 1 to prevent RNG swamp snipe - WritePanelData(0x17C05, MAX_BROADCAST_DISTANCE, {5.0}); + _core.WritePanelData(0x1972F, TARGET, {0x1C34C}); - // Disable tutorial cursor speed modifications (not working?) - WritePanelData(0x00295, CURSOR_SPEED_SCALE, {1.0}); - WritePanelData(0x0C373, CURSOR_SPEED_SCALE, {1.0}); - WritePanelData(0x00293, CURSOR_SPEED_SCALE, {1.0}); - WritePanelData(0x002C2, CURSOR_SPEED_SCALE, {1.0}); + std::vector randomOrder(shadowsPanels.size(), 0); + std::iota(randomOrder.begin(), randomOrder.end(), 0); + _core.RandomizeRange(randomOrder, SWAP_NONE, 0, 8); // Tutorial + _core.RandomizeRange(randomOrder, SWAP_NONE, 8, 16); // Avoid + _core.RandomizeRange(randomOrder, SWAP_NONE, 16, 21); // Follow + _core.ReassignTargets(shadowsPanels, randomOrder); + // Turn off original starting panel + _core.WritePanelData(shadowsPanels[0], POWER, {0.0f, 0.0f}); + // Turn on new starting panel + _core.WritePanelData(shadowsPanels[randomOrder[0]], POWER, {1.0f, 1.0f}); } -void Randomizer::Randomize(std::vector& panels, int flags) { - return RandomizeRange(panels, flags, 0, panels.size()); +void Randomizer::RandomizeTown() { } -// Range is [start, end) -void Randomizer::RandomizeRange(std::vector &panels, int flags, size_t startIndex, size_t endIndex) { - if (panels.size() == 0) return; - if (startIndex >= endIndex) return; - if (endIndex >= panels.size()) endIndex = panels.size(); - for (size_t i = endIndex-1; i > startIndex+1; i--) { - const size_t target = rand() % (i - startIndex) + startIndex; - if (i != target) { - // std::cout << "Swapping panels " << std::hex << panels[i] << " and " << std::hex << panels[target] << std::endl; - SwapPanels(panels[i], panels[target], flags); - std::swap(panels[i], panels[target]); // Panel indices in the array - } - } +void Randomizer::RandomizeMonastery() { + std::vector randomOrder(monasteryPanels.size(), 0); + std::iota(randomOrder.begin(), randomOrder.end(), 0); + _core.RandomizeRange(randomOrder, SWAP_NONE, 3, 9); // Outer 2 & 3, Inner 1-4 + _core.ReassignTargets(monasteryPanels, randomOrder); } -void Randomizer::SwapPanels(int panel1, int panel2, int flags) { - std::map offsets; +void Randomizer::RandomizeBunker() { + std::vector randomOrder(bunkerPanels.size(), 0); + std::iota(randomOrder.begin(), randomOrder.end(), 0); + // Randomize Tutorial 2-Advanced Tutorial 4 + Glass 1 + // Tutorial 1 cannot be randomized, since no other panel can start on + // Glass 1 will become door + glass 1, due to the targetting system + _core.RandomizeRange(randomOrder, SWAP_NONE, 1, 10); + // Randomize Glass 1-3 into everything after the door/glass 1 + const size_t glass1Index = find(randomOrder, 9); + _core.RandomizeRange(randomOrder, SWAP_NONE, glass1Index + 1, 12); + _core.ReassignTargets(bunkerPanels, randomOrder); +} - if (flags & SWAP_TARGETS) { - offsets[TARGET] = sizeof(int); - } - if (flags & SWAP_STYLE) { - offsets[STYLE_FLAGS] = sizeof(int); - } - if (flags & SWAP_LINES) { - offsets[PATH_COLOR] = 16; - offsets[REFLECTION_PATH_COLOR] = 16; - offsets[DOT_COLOR] = 16; - offsets[ACTIVE_COLOR] = 16; - offsets[BACKGROUND_REGION_COLOR] = 16; - offsets[SUCCESS_COLOR_A] = 16; - offsets[SUCCESS_COLOR_B] = 16; - offsets[STROBE_COLOR_A] = 16; - offsets[STROBE_COLOR_B] = 16; - offsets[ERROR_COLOR] = 16; - offsets[PATTERN_POINT_COLOR] = 16; - offsets[PATTERN_POINT_COLOR_A] = 16; - offsets[PATTERN_POINT_COLOR_B] = 16; - offsets[SYMBOL_A] = 16; - offsets[SYMBOL_B] = 16; - offsets[SYMBOL_C] = 16; - offsets[SYMBOL_D] = 16; - offsets[SYMBOL_E] = 16; - offsets[PUSH_SYMBOL_COLORS] = sizeof(int); - offsets[OUTER_BACKGROUND] = 16; - offsets[OUTER_BACKGROUND_MODE] = sizeof(int); - offsets[TRACED_EDGES] = 16; - offsets[AUDIO_PREFIX] = sizeof(void*); -// offsets[IS_CYLINDER] = sizeof(int); -// offsets[CYLINDER_Z0] = sizeof(float); -// offsets[CYLINDER_Z1] = sizeof(float); -// offsets[CYLINDER_RADIUS] = sizeof(float); - offsets[SPECULAR_ADD] = sizeof(float); - offsets[SPECULAR_POWER] = sizeof(int); - offsets[PATH_WIDTH_SCALE] = sizeof(float); - offsets[STARTPOINT_SCALE] = sizeof(float); - offsets[NUM_DOTS] = sizeof(int); - offsets[NUM_CONNECTIONS] = sizeof(int); - offsets[DOT_POSITIONS] = sizeof(void*); - offsets[DOT_FLAGS] = sizeof(void*); - offsets[DOT_CONNECTION_A] = sizeof(void*); - offsets[DOT_CONNECTION_B] = sizeof(void*); - offsets[DECORATIONS] = sizeof(void*); - offsets[DECORATION_FLAGS] = sizeof(void*); - offsets[DECORATION_COLORS] = sizeof(void*); - offsets[NUM_DECORATIONS] = sizeof(int); - offsets[REFLECTION_DATA] = sizeof(void*); - offsets[GRID_SIZE_X] = sizeof(int); - offsets[GRID_SIZE_Y] = sizeof(int); - offsets[SEQUENCE_LEN] = sizeof(int); - offsets[SEQUENCE] = sizeof(void*); - offsets[DOT_SEQUENCE_LEN] = sizeof(int); - offsets[DOT_SEQUENCE] = sizeof(void*); - offsets[DOT_SEQUENCE_LEN_REFLECTION] = sizeof(int); - offsets[DOT_SEQUENCE_REFLECTION] = sizeof(void*); - offsets[NUM_COLORED_REGIONS] = sizeof(int); - offsets[COLORED_REGIONS] = sizeof(void*); - offsets[PANEL_TARGET] = sizeof(void*); - offsets[SPECULAR_TEXTURE] = sizeof(void*); - } +void Randomizer::RandomizeJungle() { + std::vector randomOrder(junglePanels.size(), 0); + std::iota(randomOrder.begin(), randomOrder.end(), 0); + // Randomize Waves 2-7 + // Waves 1 cannot be randomized, since no other panel can start on + _core.RandomizeRange(randomOrder, SWAP_NONE, 1, 7); + // Randomize Pitches 1-6 onto themselves + _core.RandomizeRange(randomOrder, SWAP_NONE, 8, 13); + _core.ReassignTargets(junglePanels, randomOrder); +} - for (auto const& [offset, size] : offsets) { - std::vector panel1data = ReadPanelData(panel1, offset, size); - std::vector panel2data = ReadPanelData(panel2, offset, size); - WritePanelData(panel2, offset, panel1data); - WritePanelData(panel1, offset, panel2data); - } +void Randomizer::RandomizeSwamp() { + // Distance-gate swamp snipe 1 to prevent RNG swamp snipe + _core.WritePanelData(0x17C05, MAX_BROADCAST_DISTANCE, {15.0}); } -void Randomizer::ReassignTargets(const std::vector& panels, const std::vector& order) { - // This list is offset by 1, so the target of the Nth panel is in position N (aka the N+1th element) - // The first panel may not have a wire to power it, so we use the panel ID itself. - std::vector targetToActivatePanel = {panels[0] + 1}; - for (const int panel : panels) { - int target = ReadPanelData(panel, TARGET, 1)[0]; - targetToActivatePanel.push_back(target); - } +void Randomizer::RandomizeMountain() { + _core.Randomize(lasers, SWAP_TARGETS); + _core.Randomize(pillars, SWAP_LINES|SWAP_LINES); - for (size_t i=0; i(panels[order[i]], TARGET, {panelTarget}); - } -} + // Read the target of keep front laser, and write it to keep back laser. + std::vector keepFrontLaserTarget = _core.ReadPanelData(0x0360E, TARGET, 1); + _core.WritePanelData(0x03317, TARGET, keepFrontLaserTarget); +} \ No newline at end of file diff --git a/Source/Randomizer.h b/Source/Randomizer.h index 6615e31..861f5a2 100644 --- a/Source/Randomizer.h +++ b/Source/Randomizer.h @@ -1,159 +1,23 @@ #pragma once -#include "Memory.h" - -// #define GLOBALS 0x5B28C0 -#define GLOBALS 0x62A080 - -__declspec(selectany) int SWAP_NONE = 0x0; -__declspec(selectany) int SWAP_TARGETS = 0x1; -__declspec(selectany) int SWAP_LINES = 0x2; -__declspec(selectany) int SWAP_STYLE = 0x4; +#include "RandomizerCore.h" class Randomizer { public: - Randomizer(); - - void Randomize(int seed); - - 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); - - template - std::vector ReadPanelData(int panel, int offset, size_t size) { - return _memory.ReadData({GLOBALS, 0x18, panel*8, offset}, size); - } - - template - void WritePanelData(int panel, int offset, const std::vector& data) { - _memory.WriteData({GLOBALS, 0x18, panel*8, offset}, data); - } + void Randomize(); private: - Memory _memory = Memory("witness64_d3d11.exe"); + RandomizerCore _core; + void RandomizeTutorial(); + void RandomizeSymmetry(); + void RandomizeDesert(); + void RandomizeQuarry(); + void RandomizeTreehouse(); + void RandomizeKeep(); + void RandomizeShadows(); + void RandomizeTown(); + void RandomizeMonastery(); + void RandomizeBunker(); + void RandomizeJungle(); + void RandomizeSwamp(); + void RandomizeMountain(); }; - -#if GLOBALS == 0x5B28C0 -#define PATH_COLOR 0xC8 -#define REFLECTION_PATH_COLOR 0xD8 -#define DOT_COLOR 0xF8 -#define ACTIVE_COLOR 0x108 -#define BACKGROUND_REGION_COLOR 0x118 -#define SUCCESS_COLOR_A 0x128 -#define SUCCESS_COLOR_B 0x138 -#define STROBE_COLOR_A 0x148 -#define STROBE_COLOR_B 0x158 -#define ERROR_COLOR 0x168 -#define PATTERN_POINT_COLOR 0x188 -#define PATTERN_POINT_COLOR_A 0x198 -#define PATTERN_POINT_COLOR_B 0x1A8 -#define SYMBOL_A 0x1B8 -#define SYMBOL_B 0x1C8 -#define SYMBOL_C 0x1D8 -#define SYMBOL_D 0x1E8 -#define SYMBOL_E 0x1F8 -#define PUSH_SYMBOL_COLORS 0x208 -#define OUTER_BACKGROUND 0x20C -#define OUTER_BACKGROUND_MODE 0x21C -#define TRACED_EDGES 0x230 -#define AUDIO_PREFIX 0x278 -#define POWER 0x2A8 -#define TARGET 0x2BC -#define IS_CYLINDER 0x2FC -#define CYLINDER_Z0 0x300 -#define CYLINDER_Z1 0x304 -#define CYLINDER_RADIUS 0x308 -#define CURSOR_SPEED_SCALE 0x358 -#define SPECULAR_ADD 0x398 -#define SPECULAR_POWER 0x39C -#define PATH_WIDTH_SCALE 0x3A4 -#define STARTPOINT_SCALE 0x3A8 -#define NUM_DOTS 0x3B8 -#define NUM_CONNECTIONS 0x3BC -#define MAX_BROADCAST_DISTANCE 0x3C0 -#define DOT_POSITIONS 0x3C8 -#define DOT_FLAGS 0x3D0 -#define DOT_CONNECTION_A 0x3D8 -#define DOT_CONNECTION_B 0x3E0 -#define DECORATIONS 0x420 -#define DECORATION_FLAGS 0x428 -#define DECORATION_COLORS 0x430 -#define NUM_DECORATIONS 0x438 -#define REFLECTION_DATA 0x440 -#define GRID_SIZE_X 0x448 -#define GRID_SIZE_Y 0x44C -#define STYLE_FLAGS 0x450 -#define SEQUENCE_LEN 0x45C -#define SEQUENCE 0x460 -#define DOT_SEQUENCE_LEN 0x468 -#define DOT_SEQUENCE 0x470 -#define DOT_SEQUENCE_LEN_REFLECTION 0x478 -#define DOT_SEQUENCE_REFLECTION 0x480 -#define NUM_COLORED_REGIONS 0x4A0 -#define COLORED_REGIONS 0x4A8 -#define PANEL_TARGET 0x4B0 -#define SPECULAR_TEXTURE 0x4D8 -#define CABLE_TARGET_2 0xD8 -#elif GLOBALS == 0x62A080 -#define PATH_COLOR 0xC0 -#define REFLECTION_PATH_COLOR 0xD0 -#define DOT_COLOR 0xF0 -#define ACTIVE_COLOR 0x100 -#define BACKGROUND_REGION_COLOR 0x110 -#define SUCCESS_COLOR_A 0x120 -#define SUCCESS_COLOR_B 0x130 -#define STROBE_COLOR_A 0x140 -#define STROBE_COLOR_B 0x150 -#define ERROR_COLOR 0x160 -#define PATTERN_POINT_COLOR 0x180 -#define PATTERN_POINT_COLOR_A 0x190 -#define PATTERN_POINT_COLOR_B 0x1A0 -#define SYMBOL_A 0x1B0 -#define SYMBOL_B 0x1C0 -#define SYMBOL_C 0x1D0 -#define SYMBOL_D 0x1E0 -#define SYMBOL_E 0x1F0 -#define PUSH_SYMBOL_COLORS 0x200 -#define OUTER_BACKGROUND 0x204 -#define OUTER_BACKGROUND_MODE 0x214 -#define TRACED_EDGES 0x228 -#define AUDIO_PREFIX 0x270 -#define POWER 0x2A0 -#define TARGET 0x2B4 -#define IS_CYLINDER 0x2F4 -#define CYLINDER_Z0 0x2F8 -#define CYLINDER_Z1 0x2FC -#define CYLINDER_RADIUS 0x300 -#define CURSOR_SPEED_SCALE 0x350 -#define SPECULAR_ADD 0x38C -#define SPECULAR_POWER 0x390 -#define PATH_WIDTH_SCALE 0x39C -#define STARTPOINT_SCALE 0x3A0 -#define NUM_DOTS 0x3B4 -#define NUM_CONNECTIONS 0x3B8 -#define MAX_BROADCAST_DISTANCE 0x3BC -#define DOT_POSITIONS 0x3C0 -#define DOT_FLAGS 0x3C8 -#define DOT_CONNECTION_A 0x3D0 -#define DOT_CONNECTION_B 0x3D8 -#define DECORATIONS 0x418 -#define DECORATION_FLAGS 0x420 -#define DECORATION_COLORS 0x428 -#define NUM_DECORATIONS 0x430 -#define REFLECTION_DATA 0x438 -#define GRID_SIZE_X 0x440 -#define GRID_SIZE_Y 0x444 -#define STYLE_FLAGS 0x448 -#define SEQUENCE_LEN 0x454 -#define SEQUENCE 0x458 -#define DOT_SEQUENCE_LEN 0x460 -#define DOT_SEQUENCE 0x468 -#define DOT_SEQUENCE_LEN_REFLECTION 0x470 -#define DOT_SEQUENCE_REFLECTION 0x478 -#define NUM_COLORED_REGIONS 0x498 -#define COLORED_REGIONS 0x4A0 -#define PANEL_TARGET 0x4A8 -#define SPECULAR_TEXTURE 0x4D0 -#define CABLE_TARGET_2 0xD0 -#endif \ No newline at end of file diff --git a/Source/RandomizerCore.cpp b/Source/RandomizerCore.cpp new file mode 100644 index 0000000..ef0e6e6 --- /dev/null +++ b/Source/RandomizerCore.cpp @@ -0,0 +1,119 @@ +#include "RandomizerCore.h" +#include "Memory.h" +#include + +void RandomizerCore::Randomize(std::vector& panels, int flags) { + return RandomizeRange(panels, flags, 0, panels.size()); +} + +// Range is [start, end) +void RandomizerCore::RandomizeRange(std::vector &panels, int flags, size_t startIndex, size_t endIndex) { + if (panels.size() == 0) return; + if (startIndex >= endIndex) return; + if (endIndex >= panels.size()) endIndex = panels.size(); + for (size_t i = endIndex-1; i > startIndex; i--) { + const size_t target = rand() % (i - startIndex) + startIndex; + if (i != target) { + // std::cout << "Swapping panels " << std::hex << panels[i] << " and " << std::hex << panels[target] << std::endl; + SwapPanels(panels[i], panels[target], flags); + std::swap(panels[i], panels[target]); // Panel indices in the array + } + } +} + +void RandomizerCore::SwapPanels(int panel1, int panel2, int flags) { + std::map offsets; + + if (flags & SWAP_TARGETS) { + offsets[TARGET] = sizeof(int); + } + if (flags & SWAP_LINES) { + offsets[PATH_COLOR] = 16; + offsets[REFLECTION_PATH_COLOR] = 16; + offsets[DOT_COLOR] = 16; + offsets[ACTIVE_COLOR] = 16; + offsets[BACKGROUND_REGION_COLOR] = 16; + offsets[SUCCESS_COLOR_A] = 16; + offsets[SUCCESS_COLOR_B] = 16; + offsets[STROBE_COLOR_A] = 16; + offsets[STROBE_COLOR_B] = 16; + offsets[ERROR_COLOR] = 16; + offsets[PATTERN_POINT_COLOR] = 16; + offsets[PATTERN_POINT_COLOR_A] = 16; + offsets[PATTERN_POINT_COLOR_B] = 16; + offsets[SYMBOL_A] = 16; + offsets[SYMBOL_B] = 16; + offsets[SYMBOL_C] = 16; + offsets[SYMBOL_D] = 16; + offsets[SYMBOL_E] = 16; + offsets[PUSH_SYMBOL_COLORS] = sizeof(int); + offsets[OUTER_BACKGROUND] = 16; + offsets[OUTER_BACKGROUND_MODE] = sizeof(int); + offsets[TRACED_EDGES] = 16; + offsets[AUDIO_PREFIX] = sizeof(void*); +// offsets[IS_CYLINDER] = sizeof(int); +// offsets[CYLINDER_Z0] = sizeof(float); +// offsets[CYLINDER_Z1] = sizeof(float); +// offsets[CYLINDER_RADIUS] = sizeof(float); + offsets[SPECULAR_ADD] = sizeof(float); + offsets[SPECULAR_POWER] = sizeof(int); + offsets[PATH_WIDTH_SCALE] = sizeof(float); + offsets[STARTPOINT_SCALE] = sizeof(float); + offsets[NUM_DOTS] = sizeof(int); + offsets[NUM_CONNECTIONS] = sizeof(int); + offsets[DOT_POSITIONS] = sizeof(void*); + offsets[DOT_FLAGS] = sizeof(void*); + offsets[DOT_CONNECTION_A] = sizeof(void*); + offsets[DOT_CONNECTION_B] = sizeof(void*); + offsets[DECORATIONS] = sizeof(void*); + offsets[DECORATION_FLAGS] = sizeof(void*); + offsets[DECORATION_COLORS] = sizeof(void*); + offsets[NUM_DECORATIONS] = sizeof(int); + offsets[REFLECTION_DATA] = sizeof(void*); + offsets[GRID_SIZE_X] = sizeof(int); + offsets[GRID_SIZE_Y] = sizeof(int); + offsets[STYLE_FLAGS] = sizeof(int); + offsets[SEQUENCE_LEN] = sizeof(int); + offsets[SEQUENCE] = sizeof(void*); + offsets[DOT_SEQUENCE_LEN] = sizeof(int); + offsets[DOT_SEQUENCE] = sizeof(void*); + offsets[DOT_SEQUENCE_LEN_REFLECTION] = sizeof(int); + offsets[DOT_SEQUENCE_REFLECTION] = sizeof(void*); + offsets[NUM_COLORED_REGIONS] = sizeof(int); + offsets[COLORED_REGIONS] = sizeof(void*); + offsets[PANEL_TARGET] = sizeof(void*); + offsets[SPECULAR_TEXTURE] = sizeof(void*); + } + + for (auto const& [offset, size] : offsets) { + std::vector panel1data = ReadPanelData(panel1, offset, size); + std::vector panel2data = ReadPanelData(panel2, offset, size); + WritePanelData(panel2, offset, panel1data); + WritePanelData(panel1, offset, panel2data); + } +} + +void RandomizerCore::ReassignTargets(const std::vector& panels, const std::vector& order) { + // This list is offset by 1, so the target of the Nth panel is in position N (aka the N+1th element) + // The first panel may not have a wire to power it, so we use the panel ID itself. + std::vector targetToActivatePanel = {panels[0] + 1}; + for (const int panel : panels) { + int target = ReadPanelData(panel, TARGET, 1)[0]; + targetToActivatePanel.push_back(target); + } + + for (size_t i=0; i(panels[order[i]], TARGET, {panelTarget}); + } +} diff --git a/Source/RandomizerCore.h b/Source/RandomizerCore.h new file mode 100644 index 0000000..4002611 --- /dev/null +++ b/Source/RandomizerCore.h @@ -0,0 +1,155 @@ +#pragma once +#include "Memory.h" + +// #define GLOBALS 0x5B28C0 +#define GLOBALS 0x62A080 + +__declspec(selectany) int SWAP_NONE = 0x0; +__declspec(selectany) int SWAP_TARGETS = 0x1; +__declspec(selectany) int SWAP_LINES = 0x2; + +class RandomizerCore +{ +public: + 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); + + template + std::vector ReadPanelData(int panel, int offset, size_t size) { + return _memory.ReadData({GLOBALS, 0x18, panel*8, offset}, size); + } + + template + void WritePanelData(int panel, int offset, const std::vector& data) { + _memory.WriteData({GLOBALS, 0x18, panel*8, offset}, data); + } + +private: + Memory _memory = Memory("witness64_d3d11.exe"); +}; + +#if GLOBALS == 0x5B28C0 +#define PATH_COLOR 0xC8 +#define REFLECTION_PATH_COLOR 0xD8 +#define DOT_COLOR 0xF8 +#define ACTIVE_COLOR 0x108 +#define BACKGROUND_REGION_COLOR 0x118 +#define SUCCESS_COLOR_A 0x128 +#define SUCCESS_COLOR_B 0x138 +#define STROBE_COLOR_A 0x148 +#define STROBE_COLOR_B 0x158 +#define ERROR_COLOR 0x168 +#define PATTERN_POINT_COLOR 0x188 +#define PATTERN_POINT_COLOR_A 0x198 +#define PATTERN_POINT_COLOR_B 0x1A8 +#define SYMBOL_A 0x1B8 +#define SYMBOL_B 0x1C8 +#define SYMBOL_C 0x1D8 +#define SYMBOL_D 0x1E8 +#define SYMBOL_E 0x1F8 +#define PUSH_SYMBOL_COLORS 0x208 +#define OUTER_BACKGROUND 0x20C +#define OUTER_BACKGROUND_MODE 0x21C +#define TRACED_EDGES 0x230 +#define AUDIO_PREFIX 0x278 +#define POWER 0x2A8 +#define TARGET 0x2BC +#define IS_CYLINDER 0x2FC +#define CYLINDER_Z0 0x300 +#define CYLINDER_Z1 0x304 +#define CYLINDER_RADIUS 0x308 +#define CURSOR_SPEED_SCALE 0x358 +#define SPECULAR_ADD 0x398 +#define SPECULAR_POWER 0x39C +#define PATH_WIDTH_SCALE 0x3A4 +#define STARTPOINT_SCALE 0x3A8 +#define NUM_DOTS 0x3B8 +#define NUM_CONNECTIONS 0x3BC +#define MAX_BROADCAST_DISTANCE 0x3C0 +#define DOT_POSITIONS 0x3C8 +#define DOT_FLAGS 0x3D0 +#define DOT_CONNECTION_A 0x3D8 +#define DOT_CONNECTION_B 0x3E0 +#define DECORATIONS 0x420 +#define DECORATION_FLAGS 0x428 +#define DECORATION_COLORS 0x430 +#define NUM_DECORATIONS 0x438 +#define REFLECTION_DATA 0x440 +#define GRID_SIZE_X 0x448 +#define GRID_SIZE_Y 0x44C +#define STYLE_FLAGS 0x450 +#define SEQUENCE_LEN 0x45C +#define SEQUENCE 0x460 +#define DOT_SEQUENCE_LEN 0x468 +#define DOT_SEQUENCE 0x470 +#define DOT_SEQUENCE_LEN_REFLECTION 0x478 +#define DOT_SEQUENCE_REFLECTION 0x480 +#define NUM_COLORED_REGIONS 0x4A0 +#define COLORED_REGIONS 0x4A8 +#define PANEL_TARGET 0x4B0 +#define SPECULAR_TEXTURE 0x4D8 +#define CABLE_TARGET_2 0xD8 +#elif GLOBALS == 0x62A080 +#define PATH_COLOR 0xC0 +#define REFLECTION_PATH_COLOR 0xD0 +#define DOT_COLOR 0xF0 +#define ACTIVE_COLOR 0x100 +#define BACKGROUND_REGION_COLOR 0x110 +#define SUCCESS_COLOR_A 0x120 +#define SUCCESS_COLOR_B 0x130 +#define STROBE_COLOR_A 0x140 +#define STROBE_COLOR_B 0x150 +#define ERROR_COLOR 0x160 +#define PATTERN_POINT_COLOR 0x180 +#define PATTERN_POINT_COLOR_A 0x190 +#define PATTERN_POINT_COLOR_B 0x1A0 +#define SYMBOL_A 0x1B0 +#define SYMBOL_B 0x1C0 +#define SYMBOL_C 0x1D0 +#define SYMBOL_D 0x1E0 +#define SYMBOL_E 0x1F0 +#define PUSH_SYMBOL_COLORS 0x200 +#define OUTER_BACKGROUND 0x204 +#define OUTER_BACKGROUND_MODE 0x214 +#define TRACED_EDGES 0x228 +#define AUDIO_PREFIX 0x270 +#define POWER 0x2A0 +#define TARGET 0x2B4 +#define IS_CYLINDER 0x2F4 +#define CYLINDER_Z0 0x2F8 +#define CYLINDER_Z1 0x2FC +#define CYLINDER_RADIUS 0x300 +#define CURSOR_SPEED_SCALE 0x350 +#define SPECULAR_ADD 0x38C +#define SPECULAR_POWER 0x390 +#define PATH_WIDTH_SCALE 0x39C +#define STARTPOINT_SCALE 0x3A0 +#define NUM_DOTS 0x3B4 +#define NUM_CONNECTIONS 0x3B8 +#define MAX_BROADCAST_DISTANCE 0x3BC +#define DOT_POSITIONS 0x3C0 +#define DOT_FLAGS 0x3C8 +#define DOT_CONNECTION_A 0x3D0 +#define DOT_CONNECTION_B 0x3D8 +#define DECORATIONS 0x418 +#define DECORATION_FLAGS 0x420 +#define DECORATION_COLORS 0x428 +#define NUM_DECORATIONS 0x430 +#define REFLECTION_DATA 0x438 +#define GRID_SIZE_X 0x440 +#define GRID_SIZE_Y 0x444 +#define STYLE_FLAGS 0x448 +#define SEQUENCE_LEN 0x454 +#define SEQUENCE 0x458 +#define DOT_SEQUENCE_LEN 0x460 +#define DOT_SEQUENCE 0x468 +#define DOT_SEQUENCE_LEN_REFLECTION 0x470 +#define DOT_SEQUENCE_REFLECTION 0x478 +#define NUM_COLORED_REGIONS 0x498 +#define COLORED_REGIONS 0x4A0 +#define PANEL_TARGET 0x4A8 +#define SPECULAR_TEXTURE 0x4D0 +#define CABLE_TARGET_2 0xD0 +#endif \ No newline at end of file -- cgit 1.4.1