diff options
Diffstat (limited to 'Source/Randomizer.cpp')
-rw-r--r-- | Source/Randomizer.cpp | 35 |
1 files changed, 19 insertions, 16 deletions
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<T> &data, T search, size_t startIndex = 0) { | |||
109 | throw std::exception("Couldn't find value in data!"); | 109 | throw std::exception("Couldn't find value in data!"); |
110 | } | 110 | } |
111 | 111 | ||
112 | bool Randomizer::GameIsRandomized() { | 112 | Randomizer::Randomizer(const std::shared_ptr<Memory>& memory) : _memory(memory) {} |
113 | int currentFrame = _memory->GetCurrentFrame(); | 113 | |
114 | if (currentFrame >= _lastRandomizedFrame) { | 114 | void Randomizer::Randomize() { |
115 | // Time went forwards, presumably we're still on the same save | 115 | // reveal_exit_hall - Prevent actually ending the game (EEE) |
116 | _lastRandomizedFrame = currentFrame; | 116 | _memory->AddSigScan({0x45, 0x8B, 0xF7, 0x48, 0x8B, 0x4D}, [&](int index){ |
117 | return true; | 117 | _memory->WriteData<byte>({index + 0x15}, {0xEB}); // jz -> jmp |
118 | } | 118 | }); |
119 | // Otherwise, time has gone backwards, so assume new game | 119 | |
120 | return false; | 120 | // begin_endgame_1 - Prevent actually ending the game (Wonkavator) |
121 | } | 121 | _memory->AddSigScan({0x83, 0x7C, 0x01, 0xD0, 0x04}, [&](int index){ |
122 | 122 | if (GLOBALS == 0x5B28C0) { // Version differences. | |
123 | void Randomizer::Randomize() | 123 | index += 0x75; |
124 | { | 124 | } else if (GLOBALS == 0x62D0A0) { |
125 | if (GameIsRandomized()) return; // Nice sanity check, but should be unnecessary (since Main checks anyways) | 125 | index += 0x86; |
126 | _lastRandomizedFrame = _memory->GetCurrentFrame(); | 126 | } |
127 | _memory->WriteData<byte>({index}, {0xEB}); // jz -> jmp | ||
128 | }); | ||
129 | // Sig scans will be run during challenge randomization. | ||
127 | 130 | ||
128 | // Seed challenge first for future-proofing (?) | 131 | // Seed challenge first for future-proofing |
129 | RandomizeChallenge(); | 132 | RandomizeChallenge(); |
130 | 133 | ||
131 | // Content swaps -- must happen before squarePanels | 134 | // Content swaps -- must happen before squarePanels |