From 133975b5a2ceca273182829f2f11042a5276c2f0 Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Sat, 16 Nov 2019 21:17:48 -0800 Subject: Tabs -> spaces everywhere --- Source/Randomizer.cpp | 534 +++++++++++++++++++++++++------------------------- 1 file changed, 267 insertions(+), 267 deletions(-) (limited to 'Source/Randomizer.cpp') diff --git a/Source/Randomizer.cpp b/Source/Randomizer.cpp index 2545c8f..13f381a 100644 --- a/Source/Randomizer.cpp +++ b/Source/Randomizer.cpp @@ -102,356 +102,356 @@ Things to do for V2: template 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; - throw std::exception("Couldn't find value in data!"); + for (size_t i=startIndex ; i(i); + } + std::cout << "Couldn't find " << search << " in data!" << std::endl; + throw std::exception("Couldn't find value in data!"); } Randomizer::Randomizer(const std::shared_ptr& memory) : _memory(memory) {} void Randomizer::Randomize() { - // reveal_exit_hall - Prevent actually ending the game (EEE) - _memory->AddSigScan({0x45, 0x8B, 0xF7, 0x48, 0x8B, 0x4D}, [&](int index){ - _memory->WriteData({index + 0x15}, {0xEB}); // jz -> jmp - }); - - // begin_endgame_1 - Prevent actually ending the game (Wonkavator) - _memory->AddSigScan({0x83, 0x7C, 0x01, 0xD0, 0x04}, [&](int index){ - if (GLOBALS == 0x5B28C0) { // Version differences. - index += 0x75; - } else if (GLOBALS == 0x62D0A0) { - index += 0x86; - } - _memory->WriteData({index}, {0xEB}); // jz -> jmp - }); + // reveal_exit_hall - Prevent actually ending the game (EEE) + _memory->AddSigScan({0x45, 0x8B, 0xF7, 0x48, 0x8B, 0x4D}, [&](int index){ + _memory->WriteData({index + 0x15}, {0xEB}); // jz -> jmp + }); + + // begin_endgame_1 - Prevent actually ending the game (Wonkavator) + _memory->AddSigScan({0x83, 0x7C, 0x01, 0xD0, 0x04}, [&](int index){ + if (GLOBALS == 0x5B28C0) { // Version differences. + index += 0x75; + } else if (GLOBALS == 0x62D0A0) { + index += 0x86; + } + _memory->WriteData({index}, {0xEB}); // jz -> jmp + }); // Sig scans will be run during challenge randomization. - // Seed challenge first for future-proofing - RandomizeChallenge(); - - // Content swaps -- must happen before squarePanels - Randomize(upDownPanels, SWAP::LINES | SWAP::COLORS); - Randomize(leftForwardRightPanels, SWAP::LINES | SWAP::COLORS); - - Randomize(squarePanels, SWAP::LINES | SWAP::COLORS); - - // Individual area modifications - RandomizeTutorial(); - RandomizeDesert(); - RandomizeQuarry(); - RandomizeTreehouse(); - RandomizeKeep(); - RandomizeShadows(); - RandomizeMonastery(); - RandomizeBunker(); - RandomizeJungle(); - RandomizeSwamp(); - RandomizeMountain(); - RandomizeTown(); - RandomizeSymmetry(); - // RandomizeAudioLogs(); + // Seed challenge first for future-proofing + RandomizeChallenge(); + + // Content swaps -- must happen before squarePanels + Randomize(upDownPanels, SWAP::LINES | SWAP::COLORS); + Randomize(leftForwardRightPanels, SWAP::LINES | SWAP::COLORS); + + Randomize(squarePanels, SWAP::LINES | SWAP::COLORS); + + // Individual area modifications + RandomizeTutorial(); + RandomizeDesert(); + RandomizeQuarry(); + RandomizeTreehouse(); + RandomizeKeep(); + RandomizeShadows(); + RandomizeMonastery(); + RandomizeBunker(); + RandomizeJungle(); + RandomizeSwamp(); + RandomizeMountain(); + RandomizeTown(); + RandomizeSymmetry(); + // RandomizeAudioLogs(); } void Randomizer::AdjustSpeed() { - // Desert Surface Final Control - _memory->WriteEntityData(0x09F95, OPEN_RATE, {0.04f}); // 4x - // Swamp Sliding Bridge - _memory->WriteEntityData(0x0061A, OPEN_RATE, {0.1f}); // 4x - // Mountain 2 Elevator - _memory->WriteEntityData(0x09EEC, OPEN_RATE, {0.075f}); // 3x + // Desert Surface Final Control + _memory->WriteEntityData(0x09F95, OPEN_RATE, {0.04f}); // 4x + // Swamp Sliding Bridge + _memory->WriteEntityData(0x0061A, OPEN_RATE, {0.1f}); // 4x + // Mountain 2 Elevator + _memory->WriteEntityData(0x09EEC, OPEN_RATE, {0.075f}); // 3x } void Randomizer::RandomizeLasers() { - Randomize(lasers, SWAP::TARGETS); - // Read the target of keep front laser, and write it to keep back laser. - std::vector keepFrontLaserTarget = _memory->ReadEntityData(0x0360E, TARGET, 1); - _memory->WriteEntityData(0x03317, TARGET, keepFrontLaserTarget); + Randomize(lasers, SWAP::TARGETS); + // Read the target of keep front laser, and write it to keep back laser. + std::vector keepFrontLaserTarget = _memory->ReadEntityData(0x0360E, TARGET, 1); + _memory->WriteEntityData(0x03317, TARGET, keepFrontLaserTarget); } void Randomizer::PreventSnipes() { - // Distance-gate swamp snipe 1 to prevent RNG swamp snipe - _memory->WriteEntityData(0x17C05, MAX_BROADCAST_DISTANCE, {15.0}); - // Distance-gate shadows laser to prevent sniping through the bars - _memory->WriteEntityData(0x19650, MAX_BROADCAST_DISTANCE, {2.5}); + // Distance-gate swamp snipe 1 to prevent RNG swamp snipe + _memory->WriteEntityData(0x17C05, MAX_BROADCAST_DISTANCE, {15.0}); + // Distance-gate shadows laser to prevent sniping through the bars + _memory->WriteEntityData(0x19650, MAX_BROADCAST_DISTANCE, {2.5}); } // Private methods void Randomizer::RandomizeTutorial() { - // Disable tutorial cursor speed modifications (not working?) - _memory->WriteEntityData(0x00295, CURSOR_SPEED_SCALE, {1.0}); - _memory->WriteEntityData(0x0C373, CURSOR_SPEED_SCALE, {1.0}); - _memory->WriteEntityData(0x00293, CURSOR_SPEED_SCALE, {1.0}); - _memory->WriteEntityData(0x002C2, CURSOR_SPEED_SCALE, {1.0}); + // Disable tutorial cursor speed modifications (not working?) + _memory->WriteEntityData(0x00295, CURSOR_SPEED_SCALE, {1.0}); + _memory->WriteEntityData(0x0C373, CURSOR_SPEED_SCALE, {1.0}); + _memory->WriteEntityData(0x00293, CURSOR_SPEED_SCALE, {1.0}); + _memory->WriteEntityData(0x002C2, CURSOR_SPEED_SCALE, {1.0}); } void Randomizer::RandomizeSymmetry() { - std::vector randomOrder(transparent.size(), 0); - std::iota(randomOrder.begin(), randomOrder.end(), 0); - RandomizeRange(randomOrder, SWAP::NONE, 1, 5); - ReassignTargets(transparent, randomOrder); + std::vector randomOrder(transparent.size(), 0); + std::iota(randomOrder.begin(), randomOrder.end(), 0); + RandomizeRange(randomOrder, SWAP::NONE, 1, 5); + ReassignTargets(transparent, randomOrder); } void Randomizer::RandomizeDesert() { - Randomize(desertPanels, SWAP::LINES); - - // Turn off desert surface 8 - _memory->WriteEntityData(0x09F94, POWER, {0.0, 0.0}); - // Turn off desert flood final - _memory->WriteEntityData(0x18076, POWER, {0.0, 0.0}); - // Change desert floating target to desert flood final - _memory->WriteEntityData(0x17ECA, TARGET, {0x18077}); + Randomize(desertPanels, SWAP::LINES); + + // Turn off desert surface 8 + _memory->WriteEntityData(0x09F94, POWER, {0.0, 0.0}); + // Turn off desert flood final + _memory->WriteEntityData(0x18076, POWER, {0.0, 0.0}); + // Change desert floating target to desert flood final + _memory->WriteEntityData(0x17ECA, TARGET, {0x18077}); } void Randomizer::RandomizeQuarry() { } void Randomizer::RandomizeTreehouse() { - // Ensure that whatever pivot panels we have are flagged as "pivotable" - int panelFlags = _memory->ReadEntityData(0x17DD1, STYLE_FLAGS, 1)[0]; - _memory->WriteEntityData(0x17DD1, STYLE_FLAGS, {panelFlags | 0x8000}); - panelFlags = _memory->ReadEntityData(0x17CE3, STYLE_FLAGS, 1)[0]; - _memory->WriteEntityData(0x17CE3, STYLE_FLAGS, {panelFlags | 0x8000}); - panelFlags = _memory->ReadEntityData(0x17DB7, STYLE_FLAGS, 1)[0]; - _memory->WriteEntityData(0x17DB7, STYLE_FLAGS, {panelFlags | 0x8000}); - panelFlags = _memory->ReadEntityData(0x17E52, STYLE_FLAGS, 1)[0]; - _memory->WriteEntityData(0x17E52, STYLE_FLAGS, {panelFlags | 0x8000}); + // Ensure that whatever pivot panels we have are flagged as "pivotable" + int panelFlags = _memory->ReadEntityData(0x17DD1, STYLE_FLAGS, 1)[0]; + _memory->WriteEntityData(0x17DD1, STYLE_FLAGS, {panelFlags | 0x8000}); + panelFlags = _memory->ReadEntityData(0x17CE3, STYLE_FLAGS, 1)[0]; + _memory->WriteEntityData(0x17CE3, STYLE_FLAGS, {panelFlags | 0x8000}); + panelFlags = _memory->ReadEntityData(0x17DB7, STYLE_FLAGS, 1)[0]; + _memory->WriteEntityData(0x17DB7, STYLE_FLAGS, {panelFlags | 0x8000}); + panelFlags = _memory->ReadEntityData(0x17E52, STYLE_FLAGS, 1)[0]; + _memory->WriteEntityData(0x17E52, STYLE_FLAGS, {panelFlags | 0x8000}); } void Randomizer::RandomizeKeep() { } void Randomizer::RandomizeShadows() { - // Change the shadows tutorial cable to only activate avoid - _memory->WriteEntityData(0x319A8, CABLE_TARGET_2, {0}); - // Change shadows avoid 8 to power shadows follow - _memory->WriteEntityData(0x1972F, TARGET, {0x1C34C}); - - std::vector randomOrder(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 - _memory->WriteEntityData(shadowsPanels[0], POWER, {0.0f, 0.0f}); - // Turn on new starting panel - _memory->WriteEntityData(shadowsPanels[randomOrder[0]], POWER, {1.0f, 1.0f}); + // Change the shadows tutorial cable to only activate avoid + _memory->WriteEntityData(0x319A8, CABLE_TARGET_2, {0}); + // Change shadows avoid 8 to power shadows follow + _memory->WriteEntityData(0x1972F, TARGET, {0x1C34C}); + + std::vector randomOrder(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 + _memory->WriteEntityData(shadowsPanels[0], POWER, {0.0f, 0.0f}); + // Turn on new starting panel + _memory->WriteEntityData(shadowsPanels[randomOrder[0]], POWER, {1.0f, 1.0f}); } void Randomizer::RandomizeTown() { // @Hack...? To open the gate at the end - std::vector randomOrder(orchard.size() + 1, 0); - std::iota(randomOrder.begin(), randomOrder.end(), 0); - RandomizeRange(randomOrder, SWAP::NONE, 1, 5); + std::vector randomOrder(orchard.size() + 1, 0); + std::iota(randomOrder.begin(), randomOrder.end(), 0); + RandomizeRange(randomOrder, SWAP::NONE, 1, 5); // Ensure that we open the gate before the final puzzle (by swapping) int panel3Index = find(randomOrder, 3); int panel4Index = find(randomOrder, 4); randomOrder[min(panel3Index, panel4Index)] = 3; randomOrder[max(panel3Index, panel4Index)] = 4; - ReassignTargets(orchard, randomOrder); + ReassignTargets(orchard, randomOrder); } void Randomizer::RandomizeMonastery() { - std::vector randomOrder(monasteryPanels.size(), 0); - std::iota(randomOrder.begin(), randomOrder.end(), 0); - RandomizeRange(randomOrder, SWAP::NONE, 3, 9); // Outer 2 & 3, Inner 1-4 - ReassignTargets(monasteryPanels, randomOrder); + std::vector randomOrder(monasteryPanels.size(), 0); + std::iota(randomOrder.begin(), randomOrder.end(), 0); + RandomizeRange(randomOrder, SWAP::NONE, 3, 9); // Outer 2 & 3, Inner 1-4 + ReassignTargets(monasteryPanels, randomOrder); } 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 - RandomizeRange(randomOrder, SWAP::NONE, 1, 10); - // Randomize Glass 1-3 into everything after the door/glass 1 - const size_t glass1Index = find(randomOrder, 9); - RandomizeRange(randomOrder, SWAP::NONE, glass1Index + 1, 12); - ReassignTargets(bunkerPanels, randomOrder); + 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 + RandomizeRange(randomOrder, SWAP::NONE, 1, 10); + // Randomize Glass 1-3 into everything after the door/glass 1 + const size_t glass1Index = find(randomOrder, 9); + 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 - RandomizeRange(randomOrder, SWAP::NONE, 1, 7); // Waves 2-7 - RandomizeRange(randomOrder, SWAP::NONE, 8, 13); // Pitches 1-6 - ReassignTargets(junglePanels, randomOrder); - - // Fix the wall's target to point back to the cable, and the cable to point to the pitches panel. - // auto wallTarget = _memory->ReadPanelData(junglePanels[7], TARGET, 1); - // _memory->WritePanelData(junglePanels[7], TARGET, {0x3C113}); - // _memory->WritePanelData(0x3C112, CABLE_TARGET_1, wallTarget); + 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 + RandomizeRange(randomOrder, SWAP::NONE, 1, 7); // Waves 2-7 + RandomizeRange(randomOrder, SWAP::NONE, 8, 13); // Pitches 1-6 + ReassignTargets(junglePanels, randomOrder); + + // Fix the wall's target to point back to the cable, and the cable to point to the pitches panel. + // auto wallTarget = _memory->ReadPanelData(junglePanels[7], TARGET, 1); + // _memory->WritePanelData(junglePanels[7], TARGET, {0x3C113}); + // _memory->WritePanelData(0x3C112, CABLE_TARGET_1, wallTarget); } void Randomizer::RandomizeSwamp() { } void Randomizer::RandomizeMountain() { - // Randomize multipanel - Randomize(mountainMultipanel, SWAP::LINES | SWAP::COLORS); - - // Randomize final pillars order - std::vector targets = {pillars[0] + 1}; - for (const int pillar : pillars) { - int target = _memory->ReadEntityData(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); - 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 - _memory->WriteEntityData(pillars[0], POWER, {0.0f, 0.0f}); - _memory->WriteEntityData(pillars[5], POWER, {0.0f, 0.0f}); - // Turn on new starting panels - _memory->WriteEntityData(pillars[randomOrder[0]], POWER, {1.0f, 1.0f}); - _memory->WriteEntityData(pillars[randomOrder[5]], POWER, {1.0f, 1.0f}); + // Randomize multipanel + Randomize(mountainMultipanel, SWAP::LINES | SWAP::COLORS); + + // Randomize final pillars order + std::vector targets = {pillars[0] + 1}; + for (const int pillar : pillars) { + int target = _memory->ReadEntityData(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); + 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 + _memory->WriteEntityData(pillars[0], POWER, {0.0f, 0.0f}); + _memory->WriteEntityData(pillars[5], POWER, {0.0f, 0.0f}); + // Turn on new starting panels + _memory->WriteEntityData(pillars[randomOrder[0]], POWER, {1.0f, 1.0f}); + _memory->WriteEntityData(pillars[randomOrder[5]], POWER, {1.0f, 1.0f}); } void Randomizer::RandomizeChallenge() { - ChallengeRandomizer cr(_memory, Random::RandInt(1, 0x7FFFFFFF)); // 0 will trigger an "RNG not initialized" block - for (int panel : challengePanels) { - _memory->WriteEntityData(panel, POWER_OFF_ON_FAIL, {0}); - } + ChallengeRandomizer cr(_memory, Random::RandInt(1, 0x7FFFFFFF)); // 0 will trigger an "RNG not initialized" block + for (int panel : challengePanels) { + _memory->WriteEntityData(panel, POWER_OFF_ON_FAIL, {0}); + } } void Randomizer::RandomizeAudioLogs() { - std::vector randomOrder(audiologs.size(), 0); - std::iota(randomOrder.begin(), randomOrder.end(), 0); - Randomize(randomOrder, SWAP::NONE); - ReassignNames(audiologs, randomOrder); + std::vector randomOrder(audiologs.size(), 0); + std::iota(randomOrder.begin(), randomOrder.end(), 0); + Randomize(randomOrder, SWAP::NONE); + ReassignNames(audiologs, randomOrder); } void Randomizer::Randomize(std::vector& panels, int flags) { - return RandomizeRange(panels, flags, 0, panels.size()); + 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 = static_cast(panels.size()); - for (size_t i = endIndex-1; i > startIndex; i--) { - const int target = Random::RandInt(static_cast(startIndex), static_cast(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 - } - } + if (panels.size() == 0) return; + if (startIndex >= endIndex) return; + if (endIndex >= panels.size()) endIndex = static_cast(panels.size()); + for (size_t i = endIndex-1; i > startIndex; i--) { + const int target = Random::RandInt(static_cast(startIndex), static_cast(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::COLORS) { - 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); - // These two control the "burn intensity", but I can't swap out burn marks in new ver, so they should probably stay tied to each frame. - // offsets[SPECULAR_ADD] = sizeof(float); - // offsets[SPECULAR_POWER] = sizeof(int); - offsets[NUM_COLORED_REGIONS] = sizeof(int); - offsets[COLORED_REGIONS] = sizeof(void*); - } - if (flags & SWAP::LINES) { - 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[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[PANEL_TARGET] = sizeof(void*); - offsets[SPECULAR_TEXTURE] = sizeof(void*); - } - - for (auto const& [offset, size] : offsets) { - std::vector panel1data = _memory->ReadEntityData(panel1, offset, size); - std::vector panel2data = _memory->ReadEntityData(panel2, offset, size); - _memory->WriteEntityData(panel2, offset, panel1data); - _memory->WriteEntityData(panel1, offset, panel2data); - } + 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::COLORS) { + 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); + // These two control the "burn intensity", but I can't swap out burn marks in new ver, so they should probably stay tied to each frame. + // offsets[SPECULAR_ADD] = sizeof(float); + // offsets[SPECULAR_POWER] = sizeof(int); + offsets[NUM_COLORED_REGIONS] = sizeof(int); + offsets[COLORED_REGIONS] = sizeof(void*); + } + if (flags & SWAP::LINES) { + 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[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[PANEL_TARGET] = sizeof(void*); + offsets[SPECULAR_TEXTURE] = sizeof(void*); + } + + for (auto const& [offset, size] : offsets) { + std::vector panel1data = _memory->ReadEntityData(panel1, offset, size); + std::vector panel2data = _memory->ReadEntityData(panel2, offset, size); + _memory->WriteEntityData(panel2, offset, panel1data); + _memory->WriteEntityData(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->ReadEntityData(panel, TARGET, 1)[0]; - targets.push_back(target); - } - } - - for (size_t i=0; iWriteEntityData(panels[order[i]], TARGET, {panelTarget}); - } + 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->ReadEntityData(panel, TARGET, 1)[0]; + targets.push_back(target); + } + } + + for (size_t i=0; iWriteEntityData(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->ReadEntityData(panel, AUDIO_LOG_NAME, 1)[0]); - } - - for (int i=0; iWriteEntityData(panels[i], AUDIO_LOG_NAME, {names[order[i]]}); - } + std::vector names; + for (const int panel : panels) { + names.push_back(_memory->ReadEntityData(panel, AUDIO_LOG_NAME, 1)[0]); + } + + for (int i=0; iWriteEntityData(panels[i], AUDIO_LOG_NAME, {names[order[i]]}); + } } -- cgit 1.4.1