From c10b73f30280e5dd758b77e2ef8e5a622ff3c876 Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Sun, 18 Nov 2018 14:34:34 -0800 Subject: Works, on old version --- Source/ChallengeRandomizer.cpp | 145 +++++++++++++++++++++++++++++++++++++++++ Source/ChallengeRandomizer.h | 12 ++++ Source/Memory.h | 5 +- Source/Randomizer.cpp | 17 ++--- Source/Source.vcxproj | 2 + 5 files changed, 167 insertions(+), 14 deletions(-) create mode 100644 Source/ChallengeRandomizer.cpp create mode 100644 Source/ChallengeRandomizer.h (limited to 'Source') diff --git a/Source/ChallengeRandomizer.cpp b/Source/ChallengeRandomizer.cpp new file mode 100644 index 0000000..b9b54e0 --- /dev/null +++ b/Source/ChallengeRandomizer.cpp @@ -0,0 +1,145 @@ +#include "ChallengeRandomizer.h" +#include + +int find(const std::vector &data, const std::vector& search, size_t startIndex = 0) { + for (size_t i=startIndex; i(i); + } + return -1; +} + +void ChallengeRandomizer::AdjustRng(int offset) { + int currentRng = _memory->ReadData({offset}, 0x1)[0]; + _memory->WriteData({offset}, {currentRng + 0x20}); +} + +ChallengeRandomizer::ChallengeRandomizer(const std::shared_ptr& memory, int seed) : _memory(memory) +{ + int RNG_ADDR = _memory->ReadData({GLOBALS + 0x10}, 1)[0]; + int RNG2_ADDR = _memory->ReadData({GLOBALS + 0x30}, 1)[0]; + _memory->WriteData({GLOBALS + 0x30}, {RNG_ADDR + 4}); + if (RNG2_ADDR == RNG_ADDR + 4) return; // Already applied hack + + int shuffle_integers = -1; + int cut_random_edges = -1; + int get_empty_decoration_slot = -1; + int get_empty_dot_spot = -1; + int add_exactly_this_many_bisection_dots = -1; + int make_a_shaper = -1; + int init_pattern_data_lotus = -1; + int reroll_lotus_eater_stuff = -1; + int do_lotus_minutes = -1; + int do_lotus_eighths = -1; + int do_success_side_effects = -1; + + for (int i=0; i<0x200000; i+=0x1000) { + std::vector data = _memory->ReadData({i}, 0x1100); + std::cout << data.size() << std::endl; + + if (shuffle_integers == -1) { + int index = find(data, {0x48, 0x89, 0x5C, 0x24, 0x10, 0x56, 0x48, 0x83, 0xEC, 0x20, 0x48, 0x63, 0xDA, 0x48, 0x8B, 0xF1, 0x83, 0xFB, 0x01}); + if (index != -1) { + shuffle_integers = i + index; + AdjustRng(shuffle_integers + 0x23); + } + } + if (cut_random_edges == -1) { + int index = find(data, {0x8B, 0x80, 0xBC, 0x03, 0x00, 0x00, 0x89, 0x44, 0x24, 0x3C, 0x33, 0xC0}); + if (index != -1) { + cut_random_edges = i + index - 0x1C; + AdjustRng(cut_random_edges + 0x5D); + } + } + if (get_empty_decoration_slot == -1) { + int index = find(data, {0x57, 0x48, 0x83, 0xEC, 0x20, 0x8B, 0xB9, 0x38, 0x04}); + if (index != -1) { + get_empty_decoration_slot = i + index - 0x5; + AdjustRng(get_empty_decoration_slot + 0x16); + } + } + if (get_empty_dot_spot == -1) { + int index = find(data, {0xF7, 0xF3, 0x85, 0xD2, 0x74, 0xEC}); + if (index != -1) { + get_empty_dot_spot = i + index - 0x2E; + AdjustRng(get_empty_dot_spot + 0x23); + } + } + if (add_exactly_this_many_bisection_dots == -1) { + int index = find(data, {0x48, 0x8B, 0xB4, 0x24, 0xB8, 0x00, 0x00, 0x00, 0x48, 0x8B, 0xBC, 0x24, 0xB0, 0x00, 0x00, 0x00}); + if (index != -1) { + add_exactly_this_many_bisection_dots = i + index - 0x20; + AdjustRng(add_exactly_this_many_bisection_dots + 0x1C); + } + } + if (make_a_shaper == -1) { + int index = find(data, {0xF7, 0xE3, 0xD1, 0xEA, 0x8D, 0x0C, 0x52}); + if (index != -1) { + make_a_shaper = i + index - 0x19; + AdjustRng(make_a_shaper + 0x9); + AdjustRng(make_a_shaper + 0x35); + AdjustRng(make_a_shaper + 0x62); + } + } + if (/*Entity_Machine_Panel::*/init_pattern_data_lotus == -1) { + int index = find(data, {0x40, 0x55, 0x56, 0x48, 0x8D, 0x6C, 0x24, 0xB1}); + if (index != -1) { + init_pattern_data_lotus = i + index; + AdjustRng(init_pattern_data_lotus + 0x433); + AdjustRng(init_pattern_data_lotus + 0x45B); + AdjustRng(init_pattern_data_lotus + 0x5A7); + AdjustRng(init_pattern_data_lotus + 0x5D6); + AdjustRng(init_pattern_data_lotus + 0x6F6); + AdjustRng(init_pattern_data_lotus + 0xD17); + AdjustRng(init_pattern_data_lotus + 0xFDA); + } + } + if (/*Entity_Record_Player::*/reroll_lotus_eater_stuff == -1) { + int index = find(data, {0xB8, 0xAB, 0xAA, 0xAA, 0xAA, 0x41, 0xC1, 0xE8}); + if (index != -1) { + reroll_lotus_eater_stuff = i + index - 0x37; + AdjustRng(reroll_lotus_eater_stuff + 0x24); + AdjustRng(reroll_lotus_eater_stuff + 0x6B); + } + } + // These disable the random locations on timer panels, which would otherwise increment the RNG. + if (do_lotus_minutes == -1) { + int index = find(data, {0x0F, 0xBE, 0x6C, 0x08, 0xFF, 0x45}); + if (index != -1) { + do_lotus_minutes = i + index - 0x2B; + _memory->WriteData({do_lotus_minutes + 0x43B}, {0x31, 0xC0, 0x90, 0x90, 0x90}); // xor eax, eax ;RNG returns 0 + _memory->WriteData({do_lotus_minutes + 0x5B3}, {0x31, 0xC0, 0x90, 0x90, 0x90}); // xor eax, eax ;RNG returns 0 + } + } + if (do_lotus_eighths == -1) { + int index = find(data, {0x75, 0xF5, 0x0F, 0xBE, 0x44, 0x08, 0xFF}); + if (index != -1) { + do_lotus_eighths = i + index - 0x39; + _memory->WriteData({do_lotus_eighths + 0x1E7}, {0x31, 0xC0, 0x90, 0x90, 0x90}); // xor eax, eax ;RNG returns 0 + } + } + // This injection ensures that the seed is set every time the challenge is started. + if (do_success_side_effects == -1) { + int index = find(data, {0x85, 0xC0, 0x7E, 0x2C, 0x48, 0x6B, 0xC8, 0x34}); + if (index != -1) { + do_success_side_effects = i + index; + _memory->WriteData({do_success_side_effects}, { + 0x8B, 0x0D, 0x00, 0x00, 0x00, 0x00, // mov ecx, [] ;This is going to be the address of the custom RNG + 0x67, 0xC7, 0x01, 0x00, 0x00, 0x00, 0x00, // mov dword ptr ds:[ecx], 0x0 ;This is going to be the seed value + 0x48, 0x83, 0xF8, 0x02, // cmp rax, 0x2 ;This is the short solve on the record player (which turns it off) + 0x90, 0x90, 0x90 // nop nop nop + }); + int target = (GLOBALS + 0x30) - (do_success_side_effects + 0x6); // +6 is for the length of the line + _memory->WriteData({do_success_side_effects + 0x2}, {target}); + _memory->WriteData({do_success_side_effects + 0x9}, {seed}); + } + } + } +} diff --git a/Source/ChallengeRandomizer.h b/Source/ChallengeRandomizer.h new file mode 100644 index 0000000..267c5cb --- /dev/null +++ b/Source/ChallengeRandomizer.h @@ -0,0 +1,12 @@ +#pragma once +#include "Memory.h" +#include + +class ChallengeRandomizer { +public: + ChallengeRandomizer(const std::shared_ptr& memory, int seed); + +private: + void AdjustRng(int offset); + std::shared_ptr _memory; +}; diff --git a/Source/Memory.h b/Source/Memory.h index 23f6388..278ce36 100644 --- a/Source/Memory.h +++ b/Source/Memory.h @@ -3,8 +3,8 @@ #include #include -// #define GLOBALS 0x5B28C0 -#define GLOBALS 0x62A080 +#define GLOBALS 0x5B28C0 +// #define GLOBALS 0x62A080 // https://github.com/erayarslan/WriteProcessMemory-Example // http://stackoverflow.com/q/32798185 @@ -77,4 +77,5 @@ private: HANDLE _handle = nullptr; friend class Temp; + friend class ChallengeRandomizer; }; \ No newline at end of file diff --git a/Source/Randomizer.cpp b/Source/Randomizer.cpp index 1f2c0cc..2f3e72a 100644 --- a/Source/Randomizer.cpp +++ b/Source/Randomizer.cpp @@ -13,7 +13,6 @@ * Swap sounds in jungle (along with panels) -- maybe impossible * Make orange 7 (all of oranges?) hard. Like big = hard. (See: HARD_MODE) * Add a setting for "disable wonkavator and hotel", so that 100% runs are possible - * Try to stabilize challenge/doors RNG * I probably can randomize targets in bunker UV * Random *rotation* of desert laser redirect? * Add setting to disable laser randomization @@ -23,6 +22,7 @@ */ #include "Memory.h" #include "Randomizer.h" +#include "ChallengeRandomizer.h" #include "Panels.h" #include "Random.h" #include @@ -54,6 +54,9 @@ void Randomizer::Randomize() if (GameIsRandomized()) return; // Nice sanity check, but should be unnecessary (since Main checks anyways) _lastRandomizedFrame = _memory->GetCurrentFrame(); + // Seed challenge first for future-proofing (?) + RandomizeChallenge(); + // Content swaps -- must happen before squarePanels Randomize(upDownPanels, SWAP::LINES); Randomize(leftForwardRightPanels, SWAP::LINES); @@ -74,7 +77,6 @@ void Randomizer::Randomize() RandomizeJungle(); RandomizeSwamp(); RandomizeMountain(); - // RandomizeChallenge(); // RandomizeAudioLogs(); } @@ -215,16 +217,7 @@ void Randomizer::RandomizeMountain() { } void Randomizer::RandomizeChallenge() { - std::vector randomOrder(challengePanels.size(), 0); - std::iota(randomOrder.begin(), randomOrder.end(), 0); - 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); + ChallengeRandomizer cr(_memory, Random::RandInt(1, 0x1000)); } void Randomizer::RandomizeAudioLogs() { diff --git a/Source/Source.vcxproj b/Source/Source.vcxproj index 85ce6e1..cf6756a 100644 --- a/Source/Source.vcxproj +++ b/Source/Source.vcxproj @@ -157,6 +157,7 @@ + @@ -165,6 +166,7 @@ + -- cgit 1.4.1