From 3a03f478e407f35bfafd192c22f82bc8c6e25a38 Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Wed, 6 Nov 2019 09:19:21 -0800 Subject: And... it works? --- Source/Randomizer.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'Source/Randomizer.cpp') diff --git a/Source/Randomizer.cpp b/Source/Randomizer.cpp index 71ec89b..9b877cd 100644 --- a/Source/Randomizer.cpp +++ b/Source/Randomizer.cpp @@ -109,23 +109,26 @@ int find(const std::vector &data, T search, size_t startIndex = 0) { throw std::exception("Couldn't find value in data!"); } -bool Randomizer::GameIsRandomized() { - int currentFrame = _memory->GetCurrentFrame(); - if (currentFrame >= _lastRandomizedFrame) { - // Time went forwards, presumably we're still on the same save - _lastRandomizedFrame = currentFrame; - return true; - } - // Otherwise, time has gone backwards, so assume new game - return false; -} - -void Randomizer::Randomize() -{ - if (GameIsRandomized()) return; // Nice sanity check, but should be unnecessary (since Main checks anyways) - _lastRandomizedFrame = _memory->GetCurrentFrame(); +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 + }); + // Sig scans will be run during challenge randomization. - // Seed challenge first for future-proofing (?) + // Seed challenge first for future-proofing RandomizeChallenge(); // Content swaps -- must happen before squarePanels -- cgit 1.4.1