summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--WitnessRandomizer/Memory.cpp19
-rw-r--r--WitnessRandomizer/Memory.h2
-rw-r--r--WitnessRandomizer/Panels.h8
-rw-r--r--WitnessRandomizer/WitnessRandomizer.cpp3
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<int> offsets)
62 int final_offset = offsets.back(); 62 int final_offset = offsets.back();
63 offsets.pop_back(); 63 offsets.pop_back();
64 64
65 auto search = _computedOffsets.find(offsets);
66 if (search != std::end(_computedOffsets)) {
67 return search->second + final_offset;
68 }
69
70 uintptr_t cumulativeAddress = _baseAddress; 65 uintptr_t cumulativeAddress = _baseAddress;
71 for (int offset : offsets) { 66 for (int offset : offsets) {
72 cumulativeAddress += offset; 67 cumulativeAddress += offset;
73 if (!ReadProcessMemory(_handle, (LPVOID)cumulativeAddress, &cumulativeAddress, sizeof(uintptr_t), NULL)) { 68
74 ThrowError(); 69 auto search = _computedAddresses.find(cumulativeAddress);
70 if (search == std::end(_computedAddresses)) {
71 // If the address is not yet computed, then compute it.
72 uintptr_t computedAddress = 0;
73 if (!ReadProcessMemory(_handle, (LPVOID)cumulativeAddress, &computedAddress, sizeof(uintptr_t), NULL)) {
74 ThrowError();
75 }
76 _computedAddresses[cumulativeAddress] = computedAddress;
75 } 77 }
78
79 cumulativeAddress = _computedAddresses[cumulativeAddress];
76 } 80 }
77 _computedOffsets[offsets] = cumulativeAddress;
78 return cumulativeAddress + final_offset; 81 return cumulativeAddress + final_offset;
79} 82}
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:
47 47
48 uintptr_t ComputeOffset(std::vector<int> offsets); 48 uintptr_t ComputeOffset(std::vector<int> offsets);
49 49
50 std::map<std::vector<int>, uintptr_t> _computedOffsets; 50 std::map<uintptr_t, uintptr_t> _computedAddresses;
51 uintptr_t _baseAddress; 51 uintptr_t _baseAddress;
52 HANDLE _handle; 52 HANDLE _handle;
53}; \ No newline at end of file 53}; \ 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<int> upDownPanels = {
101 101
102// Note: Some of these (non-controls) are duplicated elsewhere 102// Note: Some of these (non-controls) are duplicated elsewhere
103std::vector<int> leftForwardRightPanels = { 103std::vector<int> leftForwardRightPanels = {
104 0x00075, // Symmetry Island Colored Dots 3 104// 0x00075, // Symmetry Island Colored Dots 3
105 0x288EA, // UTM Perspective 1 105// 0x288EA, // UTM Perspective 1
106 0x288FC, // UTM Perspective 2 106// 0x288FC, // UTM Perspective 2
107 0x289E7, // UTM Perspective 3 107// 0x289E7, // UTM Perspective 3
108 108
109 0x17DD1, // Treehouse Left Orange 9 109 0x17DD1, // Treehouse Left Orange 9
110 0x17CE3, // Treehouse Right Orange 4 110 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 @@
1/* 1/*
2 * BUGS:
3 * Treehouse pivots *should* work, but I need to not copy style_flags.
4 This seems to cause crashes when pivots appear elsewhere in the world.
2 * FEATURES: 5 * FEATURES:
3 * SWAP_TARGETS should still require the full panel sequence (and have ways to prevent softlocks?) 6 * SWAP_TARGETS should still require the full panel sequence (and have ways to prevent softlocks?)
4 ** Think about: Jungle 7 ** Think about: Jungle