From 1cad9871174728c15abbdb71ee5cbe2cf03ccf0c Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Wed, 7 Nov 2018 08:27:09 -0800 Subject: Cleanup before I dive further --- App/App.vcxproj | 1 - Source/Randomizer.cpp | 270 ++++++++++++++++++++++++++++++++++------------ Source/Randomizer.h | 16 ++- Source/RandomizerCore.cpp | 139 ------------------------ Source/RandomizerCore.h | 14 --- Test/Temp.cpp | 14 +++ Test/Test.vcxproj | 1 - 7 files changed, 231 insertions(+), 224 deletions(-) create mode 100644 Test/Temp.cpp diff --git a/App/App.vcxproj b/App/App.vcxproj index e9bc419..e5d0f94 100644 --- a/App/App.vcxproj +++ b/App/App.vcxproj @@ -156,7 +156,6 @@ - diff --git a/Source/Randomizer.cpp b/Source/Randomizer.cpp index 3cc2712..aaddf21 100644 --- a/Source/Randomizer.cpp +++ b/Source/Randomizer.cpp @@ -3,11 +3,12 @@ * Shipwreck vault is solved reversed? -> Not reversed, just "half", you can normally solve orange. Seems to need pattern name. * Tutorial sounds don't always play -> Unsure. Not controlled by pattern name. * FEATURES: + * Start the game if it isn't running? + * Stop swapping colors in desert + * Look into valid panel swaps for keep walk-ons. * Randomize audio logs -- Hard, seem to be unloaded some times? * Swap sounds in jungle (along with panels) -- maybe impossible * Make orange 7 (all of oranges?) hard. Like big = hard. (See: HARD_MODE) - * Start the game if it isn't running? - * Stop swapping colors in desert */ #include "Memory.h" #include "Randomizer.h" @@ -27,7 +28,7 @@ int find(const std::vector &data, T search, size_t startIndex = 0) { } bool Randomizer::GameIsRandomized() { - int currentFrame = _core.GetCurrentFrame(); + int currentFrame = GetCurrentFrame(); if (currentFrame >= _lastRandomizedFrame) { // Time went forwards, presumably we're still on the same save _lastRandomizedFrame = currentFrame; @@ -40,13 +41,13 @@ bool Randomizer::GameIsRandomized() { void Randomizer::Randomize() { if (GameIsRandomized()) return; // Nice sanity check, but should be unnecessary (since Main checks anyways) - _lastRandomizedFrame = _core.GetCurrentFrame(); + _lastRandomizedFrame = GetCurrentFrame(); // Content swaps -- must happen before squarePanels - _core.Randomize(upDownPanels, SWAP_LINES); - _core.Randomize(leftForwardRightPanels, SWAP_LINES); + Randomize(upDownPanels, SWAP_LINES); + Randomize(leftForwardRightPanels, SWAP_LINES); - _core.Randomize(squarePanels, SWAP_LINES); + Randomize(squarePanels, SWAP_LINES); // Individual area modifications RandomizeTutorial(); @@ -68,33 +69,33 @@ void Randomizer::Randomize() void Randomizer::AdjustSpeed() { // Desert Surface Final Control - _core._memory->WritePanelData(0x09F95, OPEN_RATE, {0.04f}); // 4x + _memory->WritePanelData(0x09F95, OPEN_RATE, {0.04f}); // 4x // Swamp Sliding Bridge - _core._memory->WritePanelData(0x0061A, OPEN_RATE, {0.1f}); // 4x + _memory->WritePanelData(0x0061A, OPEN_RATE, {0.1f}); // 4x // Mountain 2 Elevator - _core._memory->WritePanelData(0x09EEC, OPEN_RATE, {0.075f}); // 3x + _memory->WritePanelData(0x09EEC, OPEN_RATE, {0.075f}); // 3x } void Randomizer::RandomizeTutorial() { // Disable tutorial cursor speed modifications (not working?) - _core._memory->WritePanelData(0x00295, CURSOR_SPEED_SCALE, {1.0}); - _core._memory->WritePanelData(0x0C373, CURSOR_SPEED_SCALE, {1.0}); - _core._memory->WritePanelData(0x00293, CURSOR_SPEED_SCALE, {1.0}); - _core._memory->WritePanelData(0x002C2, CURSOR_SPEED_SCALE, {1.0}); + _memory->WritePanelData(0x00295, CURSOR_SPEED_SCALE, {1.0}); + _memory->WritePanelData(0x0C373, CURSOR_SPEED_SCALE, {1.0}); + _memory->WritePanelData(0x00293, CURSOR_SPEED_SCALE, {1.0}); + _memory->WritePanelData(0x002C2, CURSOR_SPEED_SCALE, {1.0}); } void Randomizer::RandomizeSymmetry() { } void Randomizer::RandomizeDesert() { - _core.Randomize(desertPanels, SWAP_LINES); + Randomize(desertPanels, SWAP_LINES); // Turn off desert surface 8 - _core._memory->WritePanelData(0x09F94, POWER, {0.0, 0.0}); + _memory->WritePanelData(0x09F94, POWER, {0.0, 0.0}); // Turn off desert flood final - _core._memory->WritePanelData(0x18076, POWER, {0.0, 0.0}); + _memory->WritePanelData(0x18076, POWER, {0.0, 0.0}); // Change desert floating target to desert flood final - _core._memory->WritePanelData(0x17ECA, TARGET, {0x18077}); + _memory->WritePanelData(0x17ECA, TARGET, {0x18077}); } void Randomizer::RandomizeQuarry() { @@ -102,14 +103,14 @@ void Randomizer::RandomizeQuarry() { void Randomizer::RandomizeTreehouse() { // Ensure that whatever pivot panels we have are flagged as "pivotable" - int panelFlags = _core._memory->ReadPanelData(0x17DD1, STYLE_FLAGS, 1)[0]; - _core._memory->WritePanelData(0x17DD1, STYLE_FLAGS, {panelFlags | 0x8000}); - panelFlags = _core._memory->ReadPanelData(0x17CE3, STYLE_FLAGS, 1)[0]; - _core._memory->WritePanelData(0x17CE3, STYLE_FLAGS, {panelFlags | 0x8000}); - panelFlags = _core._memory->ReadPanelData(0x17DB7, STYLE_FLAGS, 1)[0]; - _core._memory->WritePanelData(0x17DB7, STYLE_FLAGS, {panelFlags | 0x8000}); - panelFlags = _core._memory->ReadPanelData(0x17E52, STYLE_FLAGS, 1)[0]; - _core._memory->WritePanelData(0x17E52, STYLE_FLAGS, {panelFlags | 0x8000}); + int panelFlags = _memory->ReadPanelData(0x17DD1, STYLE_FLAGS, 1)[0]; + _memory->WritePanelData(0x17DD1, STYLE_FLAGS, {panelFlags | 0x8000}); + panelFlags = _memory->ReadPanelData(0x17CE3, STYLE_FLAGS, 1)[0]; + _memory->WritePanelData(0x17CE3, STYLE_FLAGS, {panelFlags | 0x8000}); + panelFlags = _memory->ReadPanelData(0x17DB7, STYLE_FLAGS, 1)[0]; + _memory->WritePanelData(0x17DB7, STYLE_FLAGS, {panelFlags | 0x8000}); + panelFlags = _memory->ReadPanelData(0x17E52, STYLE_FLAGS, 1)[0]; + _memory->WritePanelData(0x17E52, STYLE_FLAGS, {panelFlags | 0x8000}); } void Randomizer::RandomizeKeep() { @@ -117,22 +118,22 @@ void Randomizer::RandomizeKeep() { void Randomizer::RandomizeShadows() { // Distance-gate shadows laser to prevent sniping through the bars - _core._memory->WritePanelData(0x19650, MAX_BROADCAST_DISTANCE, {2.5}); + _memory->WritePanelData(0x19650, MAX_BROADCAST_DISTANCE, {2.5}); // Change the shadows tutorial cable to only activate avoid - _core._memory->WritePanelData(0x319A8, CABLE_TARGET_2, {0}); + _memory->WritePanelData(0x319A8, CABLE_TARGET_2, {0}); // Change shadows avoid 8 to power shadows follow - _core._memory->WritePanelData(0x1972F, TARGET, {0x1C34C}); + _memory->WritePanelData(0x1972F, TARGET, {0x1C34C}); 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); + 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 - _core._memory->WritePanelData(shadowsPanels[0], POWER, {0.0f, 0.0f}); + _memory->WritePanelData(shadowsPanels[0], POWER, {0.0f, 0.0f}); // Turn on new starting panel - _core._memory->WritePanelData(shadowsPanels[randomOrder[0]], POWER, {1.0f, 1.0f}); + _memory->WritePanelData(shadowsPanels[randomOrder[0]], POWER, {1.0f, 1.0f}); } void Randomizer::RandomizeTown() { @@ -141,8 +142,8 @@ void Randomizer::RandomizeTown() { 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); + RandomizeRange(randomOrder, SWAP_NONE, 3, 9); // Outer 2 & 3, Inner 1-4 + ReassignTargets(monasteryPanels, randomOrder); } void Randomizer::RandomizeBunker() { @@ -151,73 +152,208 @@ void Randomizer::RandomizeBunker() { // 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); + 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); + RandomizeRange(randomOrder, SWAP_NONE, glass1Index + 1, 12); + ReassignTargets(bunkerPanels, randomOrder); } void Randomizer::RandomizeJungle() { std::vector randomOrder(junglePanels.size(), 0); std::iota(randomOrder.begin(), randomOrder.end(), 0); // Waves 1 cannot be randomized, since no other panel can start on - _core.RandomizeRange(randomOrder, SWAP_NONE, 1, 7); // Waves 2-7 - _core.RandomizeRange(randomOrder, SWAP_NONE, 8, 13); // Pitches 1-6 - _core.ReassignTargets(junglePanels, randomOrder); + RandomizeRange(randomOrder, SWAP_NONE, 1, 7); // Waves 2-7 + RandomizeRange(randomOrder, SWAP_NONE, 8, 13); // Pitches 1-6 + ReassignTargets(junglePanels, randomOrder); } void Randomizer::RandomizeSwamp() { // Distance-gate swamp snipe 1 to prevent RNG swamp snipe - _core._memory->WritePanelData(0x17C05, MAX_BROADCAST_DISTANCE, {15.0}); + _memory->WritePanelData(0x17C05, MAX_BROADCAST_DISTANCE, {15.0}); } void Randomizer::RandomizeMountain() { // Randomize lasers & some of mountain - _core.Randomize(lasers, SWAP_TARGETS); - _core.Randomize(mountainMultipanel, SWAP_LINES); + Randomize(lasers, SWAP_TARGETS); + Randomize(mountainMultipanel, SWAP_LINES); // Randomize final pillars order std::vector targets = {pillars[0] + 1}; for (const int pillar : pillars) { - int target = _core._memory->ReadPanelData(pillar, TARGET, 1)[0]; + int target = _memory->ReadPanelData(pillar, TARGET, 1)[0]; targets.push_back(target); } targets[5] = pillars[5] + 1; std::vector randomOrder(pillars.size(), 0); std::iota(randomOrder.begin(), randomOrder.end(), 0); - _core.RandomizeRange(randomOrder, SWAP_NONE, 0, 4); // Left Pillars 1-4 - _core.RandomizeRange(randomOrder, SWAP_NONE, 5, 9); // Right Pillars 1-4 - _core.ReassignTargets(pillars, randomOrder, targets); + RandomizeRange(randomOrder, SWAP_NONE, 0, 4); // Left Pillars 1-4 + RandomizeRange(randomOrder, SWAP_NONE, 5, 9); // Right Pillars 1-4 + ReassignTargets(pillars, randomOrder, targets); // Turn off original starting panels - _core._memory->WritePanelData(pillars[0], POWER, {0.0f, 0.0f}); - _core._memory->WritePanelData(pillars[5], POWER, {0.0f, 0.0f}); + _memory->WritePanelData(pillars[0], POWER, {0.0f, 0.0f}); + _memory->WritePanelData(pillars[5], POWER, {0.0f, 0.0f}); // Turn on new starting panels - _core._memory->WritePanelData(pillars[randomOrder[0]], POWER, {1.0f, 1.0f}); - _core._memory->WritePanelData(pillars[randomOrder[5]], POWER, {1.0f, 1.0f}); + _memory->WritePanelData(pillars[randomOrder[0]], POWER, {1.0f, 1.0f}); + _memory->WritePanelData(pillars[randomOrder[5]], POWER, {1.0f, 1.0f}); // Read the target of keep front laser, and write it to keep back laser. - std::vector keepFrontLaserTarget = _core._memory->ReadPanelData(0x0360E, TARGET, 1); - _core._memory->WritePanelData(0x03317, TARGET, keepFrontLaserTarget); + std::vector keepFrontLaserTarget = _memory->ReadPanelData(0x0360E, TARGET, 1); + _memory->WritePanelData(0x03317, TARGET, keepFrontLaserTarget); } void Randomizer::RandomizeChallenge() { std::vector randomOrder(challengePanels.size(), 0); std::iota(randomOrder.begin(), randomOrder.end(), 0); - _core.RandomizeRange(randomOrder, SWAP_NONE, 1, 9); // Easy maze - Triple 2 - std::vector triple1Target = _core._memory->ReadPanelData(0x00C80, TARGET, 1); - _core._memory->WritePanelData(0x00CA1, TARGET, triple1Target); - _core._memory->WritePanelData(0x00CB9, TARGET, triple1Target); - std::vector triple2Target = _core._memory->ReadPanelData(0x00C22, TARGET, 1); - _core._memory->WritePanelData(0x00C59, TARGET, triple2Target); - _core._memory->WritePanelData(0x00C68, TARGET, triple2Target); - _core.ReassignTargets(challengePanels, randomOrder); + RandomizeRange(randomOrder, SWAP_NONE, 1, 9); // Easy maze - Triple 2 + std::vector triple1Target = _memory->ReadPanelData(0x00C80, TARGET, 1); + _memory->WritePanelData(0x00CA1, TARGET, triple1Target); + _memory->WritePanelData(0x00CB9, TARGET, triple1Target); + std::vector triple2Target = _memory->ReadPanelData(0x00C22, TARGET, 1); + _memory->WritePanelData(0x00C59, TARGET, triple2Target); + _memory->WritePanelData(0x00C68, TARGET, triple2Target); + ReassignTargets(challengePanels, randomOrder); } void Randomizer::RandomizeAudioLogs() { std::vector randomOrder(audiologs.size(), 0); std::iota(randomOrder.begin(), randomOrder.end(), 0); - _core.Randomize(randomOrder, SWAP_NONE); - _core.ReassignNames(audiologs, randomOrder); -} \ No newline at end of file + Randomize(randomOrder, SWAP_NONE); + ReassignNames(audiologs, randomOrder); +} + +void Randomizer::Randomize(std::vector& panels, int flags) { + return RandomizeRange(panels, flags, 0, panels.size()); +} + +// 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; i--) { + const size_t target = Random::RandInt(startIndex, i); + 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::SwapPanels(int panel1, int panel2, int flags) { + std::map offsets; + + if (flags & SWAP_TARGETS) { + offsets[TARGET] = sizeof(int); + } + if (flags & SWAP_AUDIO_NAMES) { + offsets[AUDIO_LOG_NAME] = sizeof(void*); + } + 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] = 12; // Not copying alpha to preserve transparency. + 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 = _memory->ReadPanelData(panel1, offset, size); + std::vector panel2data = _memory->ReadPanelData(panel2, offset, size); + _memory->WritePanelData(panel2, offset, panel1data); + _memory->WritePanelData(panel1, offset, panel2data); + } +} + +void Randomizer::ReassignTargets(const std::vector& panels, const std::vector& order, std::vector targets) { + if (targets.empty()) { + // 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. + targets = {panels[0] + 1}; + for (const int panel : panels) { + int target = _memory->ReadPanelData(panel, TARGET, 1)[0]; + targets.push_back(target); + } + } + + for (size_t i=0; iWritePanelData(panels[order[i]], TARGET, {panelTarget}); + } +} + +void Randomizer::ReassignNames(const std::vector& panels, const std::vector& order) { + std::vector names; + for (const int panel : panels) { + names.push_back(_memory->ReadPanelData(panel, AUDIO_LOG_NAME, 1)[0]); + } + + for (int i=0; iWritePanelData(panels[i], AUDIO_LOG_NAME, {names[order[i]]}); + } +} + +short Randomizer::ReadMetadata() { + return _memory->ReadData({GLOBALS + METADATA}, 1)[0]; +} + +void Randomizer::WriteMetadata(short metadata) { + return _memory->WriteData({GLOBALS + METADATA}, {metadata}); +} + +int Randomizer::GetCurrentFrame() { + return _memory->ReadData({SCRIPT_FRAMES}, 1)[0]; +} diff --git a/Source/Randomizer.h b/Source/Randomizer.h index ea05975..c9603ac 100644 --- a/Source/Randomizer.h +++ b/Source/Randomizer.h @@ -8,7 +8,7 @@ public: void AdjustSpeed(); - void ClearOffsets() {_core.ClearOffsets();} + void ClearOffsets() {_memory->ClearOffsets();} private: @@ -29,5 +29,17 @@ private: void RandomizeChallenge(); void RandomizeAudioLogs(); - RandomizerCore _core; + 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, std::vector targets = {}); + void ReassignNames(const std::vector& panels, const std::vector& order); + + short ReadMetadata(); + void WriteMetadata(short metadata); + int GetCurrentFrame(); + + std::shared_ptr _memory = std::make_shared("witness64_d3d11.exe"); + + friend class SwapTests_Shipwreck_Test; }; diff --git a/Source/RandomizerCore.cpp b/Source/RandomizerCore.cpp index f00dacd..e69de29 100644 --- a/Source/RandomizerCore.cpp +++ b/Source/RandomizerCore.cpp @@ -1,139 +0,0 @@ -#include "RandomizerCore.h" -#include "Memory.h" -#include "Random.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 = Random::RandInt(startIndex, i); - 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_AUDIO_NAMES) { - offsets[AUDIO_LOG_NAME] = sizeof(void*); - } - 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] = 12; // Not copying alpha to preserve transparency. - 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 = _memory->ReadPanelData(panel1, offset, size); - std::vector panel2data = _memory->ReadPanelData(panel2, offset, size); - _memory->WritePanelData(panel2, offset, panel1data); - _memory->WritePanelData(panel1, offset, panel2data); - } -} - -void RandomizerCore::ReassignTargets(const std::vector& panels, const std::vector& order, std::vector targets) { - if (targets.empty()) { - // 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. - targets = {panels[0] + 1}; - for (const int panel : panels) { - int target = _memory->ReadPanelData(panel, TARGET, 1)[0]; - targets.push_back(target); - } - } - - for (size_t i=0; iWritePanelData(panels[order[i]], TARGET, {panelTarget}); - } -} - -void RandomizerCore::ReassignNames(const std::vector& panels, const std::vector& order) { - std::vector names; - for (const int panel : panels) { - names.push_back(_memory->ReadPanelData(panel, AUDIO_LOG_NAME, 1)[0]); - } - - for (int i=0; iWritePanelData(panels[i], AUDIO_LOG_NAME, {names[order[i]]}); - } -} - -short RandomizerCore::ReadMetadata() { - return _memory->ReadData({GLOBALS + METADATA}, 1)[0]; -} - -void RandomizerCore::WriteMetadata(short metadata) { - return _memory->WriteData({GLOBALS + METADATA}, {metadata}); -} - -int RandomizerCore::GetCurrentFrame() { - return _memory->ReadData({SCRIPT_FRAMES}, 1)[0]; -} diff --git a/Source/RandomizerCore.h b/Source/RandomizerCore.h index 7555de2..89560b6 100644 --- a/Source/RandomizerCore.h +++ b/Source/RandomizerCore.h @@ -10,20 +10,6 @@ __declspec(selectany) int SWAP_AUDIO_NAMES = 0x4; 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, std::vector targets = {}); - void ReassignNames(const std::vector& panels, const std::vector& order); - - short ReadMetadata(); - void WriteMetadata(short metadata); - int GetCurrentFrame(); - - void ClearOffsets() {_memory->ClearOffsets();} - -// private: - std::shared_ptr _memory = std::make_shared("witness64_d3d11.exe"); }; #if GLOBALS == 0x5B28C0 diff --git a/Test/Temp.cpp b/Test/Temp.cpp new file mode 100644 index 0000000..3d589c1 --- /dev/null +++ b/Test/Temp.cpp @@ -0,0 +1,14 @@ +#include "gtest/gtest.h" +#include "Randomizer.h" + +GTEST_TEST(SwapTests, Shipwreck) { + Randomizer randomizer; + int shipwreck = 0xAFB; + int thEntry = 0x288C; + int si1 = 0x00000022; + int bu1 = 0x6; + int td1 = 0x5D; + + randomizer.SwapPanels(si1, td1, SWAP_LINES); + +} diff --git a/Test/Test.vcxproj b/Test/Test.vcxproj index 15843f3..75e22a9 100644 --- a/Test/Test.vcxproj +++ b/Test/Test.vcxproj @@ -35,7 +35,6 @@ - -- cgit 1.4.1