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/ChallengeRandomizer.cpp | 18 +----------------- Source/Memory.cpp | 5 ++--- Source/Randomizer.cpp | 35 +++++++++++++++++++---------------- Source/Randomizer.h | 8 +++----- Source/Source.vcxproj | 5 +++++ 5 files changed, 30 insertions(+), 41 deletions(-) (limited to 'Source') diff --git a/Source/ChallengeRandomizer.cpp b/Source/ChallengeRandomizer.cpp index fa9a234..de08885 100644 --- a/Source/ChallengeRandomizer.cpp +++ b/Source/ChallengeRandomizer.cpp @@ -1,7 +1,7 @@ #include "ChallengeRandomizer.h" #include -// Reads the (relative!) address of the RNG, then shifts it to point at RNG2 +// Modify an opcode to use RNG2 instead of main RNG void ChallengeRandomizer::AdjustRng(int offset) { int currentRng = _memory->ReadData({offset}, 0x1)[0]; _memory->WriteData({offset}, {currentRng + 0x20}); @@ -39,22 +39,6 @@ ChallengeRandomizer::ChallengeRandomizer(const std::shared_ptr& memory, }); if (!alreadyInjected) { - // reveal_exit_hall - _memory->AddSigScan({0x45, 0x8B, 0xF7, 0x48, 0x8B, 0x4D}, [&](int index){ - _memory->WriteData({index + 0x15}, {0xEB}); - }); - - // begin_endgame_1 - _memory->AddSigScan({0x83, 0x7C, 0x01, 0xD0, 0x04}, [&](int index){ - if (GLOBALS == 0x5B28C0) { // Version differences. - index += 0x75; - } else if (GLOBALS == 0x62D0A0) { - index += 0x86; - } - // Overwriting a 74 12 opcode - _memory->WriteData({index}, {0xEB}); - }); - // shuffle_integers _memory->AddSigScan({0x48, 0x89, 0x5C, 0x24, 0x10, 0x56, 0x48, 0x83, 0xEC, 0x20, 0x48, 0x63, 0xDA, 0x48, 0x8B, 0xF1, 0x83, 0xFB, 0x01}, [&](int index) { AdjustRng(index + 0x23); diff --git a/Source/Memory.cpp b/Source/Memory.cpp index 7b4b9c7..c3b89d0 100644 --- a/Source/Memory.cpp +++ b/Source/Memory.cpp @@ -59,6 +59,8 @@ void Memory::Heartbeat(HWND window) { int frameDelta = currentFrame - _previousFrame; _previousFrame = currentFrame; if (frameDelta < 0 && currentFrame < 250) { + // Some addresses (e.g. Entity Manager) may get re-allocated on newgame. + _computedAddresses.clear(); PostMessage(window, WM_COMMAND, HEARTBEAT, (LPARAM)ProcStatus::NewGame); return; } @@ -171,9 +173,6 @@ void* Memory::ComputeOffset(std::vector offsets) { // If the address is not yet computed, then compute it. uintptr_t computedAddress = 0; if (bool result = !ReadProcessMemory(_handle, reinterpret_cast(cumulativeAddress), &computedAddress, sizeof(uintptr_t), NULL)) { - if (GetLastError() == ERROR_PARTIAL_COPY) { - int k = 1; - } ThrowError(); } _computedAddresses[cumulativeAddress] = computedAddress; 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 diff --git a/Source/Randomizer.h b/Source/Randomizer.h index 020851b..d9ea700 100644 --- a/Source/Randomizer.h +++ b/Source/Randomizer.h @@ -4,15 +4,14 @@ class Randomizer { public: + Randomizer(const std::shared_ptr& memory); void Randomize(); - bool GameIsRandomized(); + void RandomizeChallenge(); void AdjustSpeed(); void RandomizeLasers(); void PreventSnipes(); - void ClearOffsets() {_memory->ClearOffsets();} - enum SWAP { NONE = 0, TARGETS = 1, @@ -36,7 +35,6 @@ private: void RandomizeJungle(); void RandomizeSwamp(); void RandomizeMountain(); - void RandomizeChallenge(); void RandomizeAudioLogs(); void Randomize(std::vector& panels, int flags); @@ -45,7 +43,7 @@ private: void ReassignTargets(const std::vector& panels, const std::vector& order, std::vector targets = {}); void ReassignNames(const std::vector& panels, const std::vector& order); - std::shared_ptr _memory = std::make_shared(L"witness64_d3d11.exe"); + std::shared_ptr _memory; friend class SwapTests_Shipwreck_Test; }; diff --git a/Source/Source.vcxproj b/Source/Source.vcxproj index e7f716c..b60349c 100644 --- a/Source/Source.vcxproj +++ b/Source/Source.vcxproj @@ -157,12 +157,17 @@ + + + + + -- cgit 1.4.1