From 1d4763bc94c9887bc4171374202a5d12be1fc10f Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Fri, 26 Oct 2018 21:43:17 -0700 Subject: Way better caching. --- WitnessRandomizer/Memory.cpp | 19 +++++++++++-------- WitnessRandomizer/Memory.h | 2 +- WitnessRandomizer/Panels.h | 8 ++++---- WitnessRandomizer/WitnessRandomizer.cpp | 3 +++ 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/WitnessRandomizer/Memory.cpp b/WitnessRandomizer/Memory.cpp index 92a5136..6077691 100644 --- a/WitnessRandomizer/Memory.cpp +++ b/WitnessRandomizer/Memory.cpp @@ -62,18 +62,21 @@ uintptr_t Memory::ComputeOffset(std::vector offsets) int final_offset = offsets.back(); offsets.pop_back(); - auto search = _computedOffsets.find(offsets); - if (search != std::end(_computedOffsets)) { - return search->second + final_offset; - } - uintptr_t cumulativeAddress = _baseAddress; for (int offset : offsets) { cumulativeAddress += offset; - if (!ReadProcessMemory(_handle, (LPVOID)cumulativeAddress, &cumulativeAddress, sizeof(uintptr_t), NULL)) { - ThrowError(); + + auto search = _computedAddresses.find(cumulativeAddress); + if (search == std::end(_computedAddresses)) { + // If the address is not yet computed, then compute it. + uintptr_t computedAddress = 0; + if (!ReadProcessMemory(_handle, (LPVOID)cumulativeAddress, &computedAddress, sizeof(uintptr_t), NULL)) { + ThrowError(); + } + _computedAddresses[cumulativeAddress] = computedAddress; } + + cumulativeAddress = _computedAddresses[cumulativeAddress]; } - _computedOffsets[offsets] = cumulativeAddress; return cumulativeAddress + final_offset; } diff --git a/WitnessRandomizer/Memory.h b/WitnessRandomizer/Memory.h index 390269c..6f5b8b7 100644 --- a/WitnessRandomizer/Memory.h +++ b/WitnessRandomizer/Memory.h @@ -47,7 +47,7 @@ private: uintptr_t ComputeOffset(std::vector offsets); - std::map, uintptr_t> _computedOffsets; + std::map _computedAddresses; uintptr_t _baseAddress; HANDLE _handle; }; \ No newline at end of file diff --git a/WitnessRandomizer/Panels.h b/WitnessRandomizer/Panels.h index 9589ace..4f7ff2d 100644 --- a/WitnessRandomizer/Panels.h +++ b/WitnessRandomizer/Panels.h @@ -101,10 +101,10 @@ std::vector upDownPanels = { // Note: Some of these (non-controls) are duplicated elsewhere std::vector leftForwardRightPanels = { - 0x00075, // Symmetry Island Colored Dots 3 - 0x288EA, // UTM Perspective 1 - 0x288FC, // UTM Perspective 2 - 0x289E7, // UTM Perspective 3 +// 0x00075, // Symmetry Island Colored Dots 3 +// 0x288EA, // UTM Perspective 1 +// 0x288FC, // UTM Perspective 2 +// 0x289E7, // UTM Perspective 3 0x17DD1, // Treehouse Left Orange 9 0x17CE3, // Treehouse Right Orange 4 diff --git a/WitnessRandomizer/WitnessRandomizer.cpp b/WitnessRandomizer/WitnessRandomizer.cpp index dacb8fe..c5cf0bb 100644 --- a/WitnessRandomizer/WitnessRandomizer.cpp +++ b/WitnessRandomizer/WitnessRandomizer.cpp @@ -1,4 +1,7 @@ /* + * BUGS: + * Treehouse pivots *should* work, but I need to not copy style_flags. + This seems to cause crashes when pivots appear elsewhere in the world. * FEATURES: * SWAP_TARGETS should still require the full panel sequence (and have ways to prevent softlocks?) ** Think about: Jungle -- cgit 1.4.1