From 1f2077485e580b3b1d582298281ac6272df18d8d Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Sat, 27 Oct 2018 01:27:29 -0700 Subject: /W3 clean, add .msi installer project --- WitnessRandomizer/Memory.cpp | 14 ++++++------- WitnessRandomizer/Memory.h | 20 ++++++++---------- WitnessRandomizer/Panels.h | 26 +++++++++++------------ WitnessRandomizer/WitnessRandomizer.cpp | 32 ++++++++++++++++------------- WitnessRandomizer/WitnessRandomizer.h | 6 +++--- WitnessRandomizer/WitnessRandomizer.vcxproj | 8 +++++++- 6 files changed, 56 insertions(+), 50 deletions(-) (limited to 'WitnessRandomizer') diff --git a/WitnessRandomizer/Memory.cpp b/WitnessRandomizer/Memory.cpp index 6077691..0afeded 100644 --- a/WitnessRandomizer/Memory.cpp +++ b/WitnessRandomizer/Memory.cpp @@ -47,30 +47,28 @@ Memory::~Memory() { CloseHandle(_handle); } -// Private methods: - void Memory::ThrowError() { std::string message(256, '\0'); - FormatMessageA(4096, NULL, GetLastError(), 1024, &message[0], static_cast(message.length()), NULL); + FormatMessageA(4096, nullptr, GetLastError(), 1024, &message[0], static_cast(message.length()), nullptr); std::cout << message.c_str() << std::endl; exit(EXIT_FAILURE); } -uintptr_t Memory::ComputeOffset(std::vector offsets) +void* Memory::ComputeOffset(std::vector offsets) { // Leave off the last offset, since it will be either read/write, and may not be of type unitptr_t. int final_offset = offsets.back(); offsets.pop_back(); uintptr_t cumulativeAddress = _baseAddress; - for (int offset : offsets) { + for (const int offset : offsets) { cumulativeAddress += offset; - auto search = _computedAddresses.find(cumulativeAddress); + const 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)) { + if (!ReadProcessMemory(_handle, reinterpret_cast(cumulativeAddress), &computedAddress, sizeof(uintptr_t), NULL)) { ThrowError(); } _computedAddresses[cumulativeAddress] = computedAddress; @@ -78,5 +76,5 @@ uintptr_t Memory::ComputeOffset(std::vector offsets) cumulativeAddress = _computedAddresses[cumulativeAddress]; } - return cumulativeAddress + final_offset; + return reinterpret_cast(cumulativeAddress + final_offset); } diff --git a/WitnessRandomizer/Memory.h b/WitnessRandomizer/Memory.h index 6f5b8b7..8e8bbc3 100644 --- a/WitnessRandomizer/Memory.h +++ b/WitnessRandomizer/Memory.h @@ -2,9 +2,6 @@ #include #include #include -#include -#include -using namespace std::chrono_literals; // https://github.com/erayarslan/WriteProcessMemory-Example // http://stackoverflow.com/q/32798185 @@ -16,16 +13,18 @@ public: Memory(const std::string& processName); ~Memory(); + Memory(const Memory& memory) = delete; + Memory& operator=(const Memory& other) = delete; + template - std::vector ReadData(const std::vector& offsets, int numItems) { + std::vector ReadData(const std::vector& offsets, size_t numItems) { std::vector data; data.resize(numItems); for (int i=0; i<5; i++) { - if (ReadProcessMemory(_handle, (LPVOID)ComputeOffset(offsets), &data[0], sizeof(T) * numItems, NULL)) + if (ReadProcessMemory(_handle, ComputeOffset(offsets), &data[0], sizeof(T) * numItems, nullptr)) { return data; } - // std::this_thread::sleep_for(10ms); } ThrowError(); return {}; @@ -34,10 +33,9 @@ public: template void WriteData(const std::vector& offsets, const std::vector& data) { for (int i=0; i<5; i++) { - if (WriteProcessMemory(_handle, (LPVOID)ComputeOffset(offsets), &data[0], sizeof(T) * data.size(), NULL)) { + if (WriteProcessMemory(_handle, ComputeOffset(offsets), &data[0], sizeof(T) * data.size(), nullptr)) { return; } - // std::this_thread::sleep_for(10ms); } ThrowError(); } @@ -45,9 +43,9 @@ public: private: void ThrowError(); - uintptr_t ComputeOffset(std::vector offsets); + void* ComputeOffset(std::vector offsets); std::map _computedAddresses; - uintptr_t _baseAddress; - HANDLE _handle; + uintptr_t _baseAddress = 0; + HANDLE _handle = nullptr; }; \ No newline at end of file diff --git a/WitnessRandomizer/Panels.h b/WitnessRandomizer/Panels.h index cd815bc..2995170 100644 --- a/WitnessRandomizer/Panels.h +++ b/WitnessRandomizer/Panels.h @@ -2,7 +2,7 @@ #include // Some of these (the puzzle ones) are duplicated elsewhere -std::vector lasers = { +const std::vector lasers = { 0x0360D, // Symmetry 0x03615, // Swamp 0x09DE0, // Bunker @@ -18,7 +18,7 @@ std::vector lasers = { }; // Note: Some of these (non-desert) are duplicated elsewhere -std::vector burnablePanels = { +const std::vector burnablePanels = { 0x17D9C, // Treehouse Yellow 7 0x17DC2, // Treehouse Yellow 8 0x17DC4, // Treehouse Yellow 9 @@ -63,7 +63,7 @@ std::vector burnablePanels = { // Note: Some of these (non-controls) are duplicated elsewhere // TODO: Gave up -std::vector leftRightPanels = { +const std::vector leftRightPanels = { 0x01A54, // Glass Factory Entry 0x00086, // Glass Factory Vertical Symmetry 1 0x00087, // Glass Factory Vertical Symmetry 2 @@ -77,7 +77,7 @@ std::vector leftRightPanels = { }; // Note: Some of these (non-controls) are duplicated elsewhere -std::vector upDownPanels = { +const std::vector upDownPanels = { 0x0008D, // Glass Factory Rotational Symmetry 1 0x00081, // Glass Factory Rotational Symmetry 2 0x00083, // Glass Factory Rotational Symmetry 3 @@ -100,7 +100,7 @@ std::vector upDownPanels = { }; // Note: Some of these (non-controls) are duplicated elsewhere -std::vector leftForwardRightPanels = { +const std::vector leftForwardRightPanels = { // 0x00075, // Symmetry Island Colored Dots 3 // 0x288EA, // UTM Perspective 1 // 0x288FC, // UTM Perspective 2 @@ -112,7 +112,7 @@ std::vector leftForwardRightPanels = { 0x17E52, // Treehouse Green 4 }; -std::vector pillars = { +const std::vector pillars = { 0x0383D, // Mountain 3 Left Pillar 1 0x0383F, // Mountain 3 Left Pillar 2 0x03859, // Mountain 3 Left Pillar 3 @@ -126,7 +126,7 @@ std::vector pillars = { // 0x1C319, // Challenge Right Pillar }; -std::vector mountainMultipanel = { +const std::vector mountainMultipanel = { 0x09FCC, // Mountain 2 Multipanel 1 0x09FCE, // Mountain 2 Multipanel 2 0x09FCF, // Mountain 2 Multipanel 3 @@ -135,7 +135,7 @@ std::vector mountainMultipanel = { 0x09FD2, // Mountain 2 Multipanel 6 }; -std::vector squarePanels = { +const std::vector squarePanels = { 0x00064, // Tutorial Straight 0x00182, // Tutorial Bend 0x0A3B2, // Tutorial Back Right @@ -453,7 +453,7 @@ std::vector squarePanels = { 0x09E85, // Tunnels Town Shortcut }; -std::vector shadowsPanels = { +const std::vector shadowsPanels = { 0x198B5, // Shadows Tutorial 1 0x198BD, // Shadows Tutorial 2 0x198BF, // Shadows Tutorial 3 @@ -478,7 +478,7 @@ std::vector shadowsPanels = { 0x19650, // Shadows Laser }; -std::vector monasteryPanels = { +const std::vector monasteryPanels = { 0x00B10, // Monastery Left Door 0x00290, // Monastery Exterior 1 0x00C92, // Monastery Right Door @@ -493,7 +493,7 @@ std::vector monasteryPanels = { 0x17CA4, // Monastery Laser }; -std::vector bunkerPanels = { +const std::vector bunkerPanels = { 0x09F7D, // Bunker Tutorial 1 0x09FDC, // Bunker Tutorial 2 0x09FF7, // Bunker Tutorial 3 @@ -514,7 +514,7 @@ std::vector bunkerPanels = { 0x0A079, // Bunker Elevator }; -std::vector junglePanels = { +const std::vector junglePanels = { 0x002C4, // Jungle Waves 1 0x00767, // Jungle Waves 2 0x002C6, // Jungle Waves 3 @@ -533,7 +533,7 @@ std::vector junglePanels = { }; // There might be something to do with these, I haven't decided yet. -std::vector nothingPanels = { +const std::vector nothingPanels = { // Doors & Shortcuts & Shortcut doors & Door controls 0x0C339, // Desert Surface Door 0x0A249, // Desert Pond Exit Door diff --git a/WitnessRandomizer/WitnessRandomizer.cpp b/WitnessRandomizer/WitnessRandomizer.cpp index efe18b5..d71cc21 100644 --- a/WitnessRandomizer/WitnessRandomizer.cpp +++ b/WitnessRandomizer/WitnessRandomizer.cpp @@ -1,5 +1,6 @@ /* * BUGS: + * Shipwreck vault fails, possibly because of dot_reflection? * 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: @@ -17,23 +18,26 @@ #include #include #include +#include template -int find(const std::vector &data, T search, int startIndex = 0) { - for (int i=startIndex ; i &data, T search, size_t startIndex = 0) { + for (size_t i=startIndex ; i(0x002C2, CURSOR_SPEED_SCALE, {1.0}); } -void WitnessRandomizer::Randomize(std::vector &panels, int flags) { +void WitnessRandomizer::Randomize(const std::vector& panels, int flags) { return RandomizeRange(panels, flags, 0, panels.size()); } // Range is [start, end) -void WitnessRandomizer::RandomizeRange(std::vector &panels, int flags, size_t startIndex, size_t endIndex) { +void WitnessRandomizer::RandomizeRange(std::vector panels, int flags, size_t startIndex, size_t endIndex) { if (panels.size() == 0) return; if (startIndex >= endIndex) return; if (endIndex >= panels.size()) endIndex = panels.size(); for (size_t i = endIndex-1; i > startIndex+1; i--) { - size_t target = rand() % (i - startIndex) + startIndex; + const size_t target = rand() % (i - startIndex) + startIndex; if (i != target) { // std::cout << "Swapping panels " << std::hex << panels[i] << " and " << std::hex << panels[target] << std::endl; SwapPanels(panels[i], panels[target], flags); @@ -215,17 +219,17 @@ void WitnessRandomizer::SwapPanels(int panel1, int panel2, int flags) { } void WitnessRandomizer::ReassignTargets(const std::vector& panels, const std::vector& order) { + // This list is offset by 1, so the target of the Nth panel is in position N (aka the N+1th element) + // The first panel may not have a wire to power it, so we use the panel ID itself. std::vector targetToActivatePanel = {panels[0] + 1}; - for (int panel : panels) { + for (const int panel : panels) { int target = ReadPanelData(panel, TARGET, 1)[0]; targetToActivatePanel.push_back(target); } - for (int i=0; i(panels[order[i]], TARGET, {panelTarget}); } } diff --git a/WitnessRandomizer/WitnessRandomizer.h b/WitnessRandomizer/WitnessRandomizer.h index 0e88cee..3d748d1 100644 --- a/WitnessRandomizer/WitnessRandomizer.h +++ b/WitnessRandomizer/WitnessRandomizer.h @@ -12,13 +12,13 @@ class WitnessRandomizer { public: WitnessRandomizer(); - void Randomize(std::vector &panels, int flags); - void RandomizeRange(std::vector &panels, int flags, size_t startIndex, size_t endIndex); + void Randomize(const std::vector& panels, int flags); + void RandomizeRange(std::vector panels, int flags, size_t startIndex, size_t endIndex); void SwapPanels(int panel1, int panel2, int flags); void ReassignTargets(const std::vector& panels, const std::vector& order); template - std::vector ReadPanelData(int panel, int offset, int size) { + std::vector ReadPanelData(int panel, int offset, size_t size) { return _memory.ReadData({GLOBALS, 0x18, panel*8, offset}, size); } diff --git a/WitnessRandomizer/WitnessRandomizer.vcxproj b/WitnessRandomizer/WitnessRandomizer.vcxproj index 49bd186..a737dd3 100644 --- a/WitnessRandomizer/WitnessRandomizer.vcxproj +++ b/WitnessRandomizer/WitnessRandomizer.vcxproj @@ -81,6 +81,8 @@ false + NativeRecommendedRules.ruleset + true @@ -134,7 +136,7 @@ - Use + NotUsing Level3 MaxSpeed true @@ -143,6 +145,10 @@ NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true pch.h + stdcpp17 + true + true + 26451 Console -- cgit 1.4.1