From 5ad08f6611c8c777c43cfa0d2380b6ad6554a54d Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Wed, 7 Nov 2018 09:26:42 -0800 Subject: Not sure what other feature work is valuable -- I'd rather work on exporting. --- Source/Memory.cpp | 35 +++++++++++++++++++++++------------ Source/Memory.h | 8 ++++---- Source/Panel.h | 2 +- Source/Randomizer.cpp | 19 +++---------------- Source/Randomizer.h | 2 -- Test/RandomTests.cpp | 1 - Test/Temp.cpp | 7 ++++++- WitnessRandomizer.sln | 44 ++++++++++++++++++++++++-------------------- 8 files changed, 61 insertions(+), 57 deletions(-) diff --git a/Source/Memory.cpp b/Source/Memory.cpp index 0afeded..825346a 100644 --- a/Source/Memory.cpp +++ b/Source/Memory.cpp @@ -18,8 +18,8 @@ Memory::Memory(const std::string& processName) { } } if (!_handle) { - std::cout << "Couldn't find " << processName.c_str() << ", is it open?" << std::endl; - exit(EXIT_FAILURE); + std::cerr << "Couldn't find " << processName.c_str() << ", is it open?" << std::endl; + throw std::exception("Unable to find process!"); } // Next, get the process base address @@ -27,19 +27,17 @@ Memory::Memory(const std::string& processName) { std::vector moduleList(1024); EnumProcessModulesEx(_handle, &moduleList[0], static_cast(moduleList.size()), &numModules, 3); - std::string name(64, 0); + std::string name(64, '\0'); for (DWORD i = 0; i < numModules / sizeof(HMODULE); i++) { - GetModuleBaseNameA(_handle, moduleList[i], &name[0], sizeof(name)); - - // TODO: Filling with 0s still yeilds name.size() == 64... - if (strcmp(processName.c_str(), name.c_str()) == 0) { + int length = GetModuleBaseNameA(_handle, moduleList[i], &name[0], static_cast(name.size())); + name.resize(length); + if (processName == name) { _baseAddress = (uintptr_t)moduleList[i]; break; } } if (_baseAddress == 0) { - std::cout << "Couldn't find the base process address!" << std::endl; - exit(EXIT_FAILURE); + throw std::exception("Couldn't find the base process address!"); } } @@ -47,11 +45,24 @@ Memory::~Memory() { CloseHandle(_handle); } +int Memory::GetCurrentFrame() +{ + int SCRIPT_FRAMES; + if (GLOBALS == 0x5B28C0) { + SCRIPT_FRAMES = 0x5BE3B0; + } else if (GLOBALS == 0x62A080) { + SCRIPT_FRAMES = 0x63651C; + } else { + throw std::exception("Unknown value for Globals!"); + } + return ReadData({SCRIPT_FRAMES}, 1)[0]; +} + void Memory::ThrowError() { std::string message(256, '\0'); - FormatMessageA(4096, nullptr, GetLastError(), 1024, &message[0], static_cast(message.length()), nullptr); - std::cout << message.c_str() << std::endl; - exit(EXIT_FAILURE); + int length = FormatMessageA(4096, nullptr, GetLastError(), 1024, &message[0], static_cast(message.size()), nullptr); + message.resize(length); + throw std::exception(message.c_str()); } void* Memory::ComputeOffset(std::vector offsets) diff --git a/Source/Memory.h b/Source/Memory.h index 4c79d7c..e7f8ff3 100644 --- a/Source/Memory.h +++ b/Source/Memory.h @@ -19,6 +19,7 @@ public: Memory(const Memory& memory) = delete; Memory& operator=(const Memory& other) = delete; + int GetCurrentFrame(); template std::vector ReadArray(int panel, int offset, int size) { @@ -40,6 +41,9 @@ public: WriteData({GLOBALS, 0x18, panel*8, offset}, data); } + void ClearOffsets() {_computedAddresses = std::map();} + +private: template std::vector ReadData(const std::vector& offsets, size_t numItems) { std::vector data; @@ -64,10 +68,6 @@ public: ThrowError(); } - void ClearOffsets() {_computedAddresses = std::map();} - -private: - void ThrowError(); void* ComputeOffset(std::vector offsets); diff --git a/Source/Panel.h b/Source/Panel.h index f4f4080..c9b4910 100644 --- a/Source/Panel.h +++ b/Source/Panel.h @@ -45,7 +45,7 @@ enum IntersectionFlags { IS_ENDPOINT = 0x1, IS_STARTPOINT = 0x2, IS_GAP = 0x10000, - HAS_DOT = 0x8, + HAS_DOT = 0x20, DOT_IS_BLUE = 0x100, DOT_IS_ORANGE = 0x200, DOT_IS_INVISIBLE = 0x1000, diff --git a/Source/Randomizer.cpp b/Source/Randomizer.cpp index ce784be..a21b928 100644 --- a/Source/Randomizer.cpp +++ b/Source/Randomizer.cpp @@ -5,7 +5,6 @@ * FEATURES: * Start the game if it isn't running? * Stop swapping colors in desert - * Look into valid panel swaps for keep walk-ons. * Randomize audio logs -- Hard, seem to be unloaded some times? * Swap sounds in jungle (along with panels) -- maybe impossible * Make orange 7 (all of oranges?) hard. Like big = hard. (See: HARD_MODE) @@ -24,11 +23,11 @@ int find(const std::vector &data, T search, size_t startIndex = 0) { if (data[i] == search) return static_cast(i); } std::cout << "Couldn't find " << search << " in data!" << std::endl; - exit(-1); + throw std::exception("Couldn't find value in data!"); } bool Randomizer::GameIsRandomized() { - int currentFrame = GetCurrentFrame(); + int currentFrame = _memory->GetCurrentFrame(); if (currentFrame >= _lastRandomizedFrame) { // Time went forwards, presumably we're still on the same save _lastRandomizedFrame = currentFrame; @@ -41,7 +40,7 @@ bool Randomizer::GameIsRandomized() { void Randomizer::Randomize() { if (GameIsRandomized()) return; // Nice sanity check, but should be unnecessary (since Main checks anyways) - _lastRandomizedFrame = GetCurrentFrame(); + _lastRandomizedFrame = _memory->GetCurrentFrame(); // Content swaps -- must happen before squarePanels Randomize(upDownPanels, SWAP::LINES); @@ -345,15 +344,3 @@ void Randomizer::ReassignNames(const std::vector& panels, const std::vector _memory->WritePanelData(panels[i], AUDIO_LOG_NAME, {names[order[i]]}); } } - -short Randomizer::ReadMetadata() { - return _memory->ReadData({GLOBALS + METADATA}, 1)[0]; -} - -void Randomizer::WriteMetadata(short metadata) { - return _memory->WriteData({GLOBALS + METADATA}, {metadata}); -} - -int Randomizer::GetCurrentFrame() { - return _memory->ReadData({SCRIPT_FRAMES}, 1)[0]; -} diff --git a/Source/Randomizer.h b/Source/Randomizer.h index fa7bc4c..1180d43 100644 --- a/Source/Randomizer.h +++ b/Source/Randomizer.h @@ -117,7 +117,6 @@ private: #define AUDIO_LOG_NAME 0xC8 #define OPEN_RATE 0xE8 #define METADATA 0xF2 // sizeof(short) -#define SCRIPT_FRAMES 0x5BE3B0 #elif GLOBALS == 0x62A080 #define PATH_COLOR 0xC0 #define REFLECTION_PATH_COLOR 0xD0 @@ -183,5 +182,4 @@ private: #define AUDIO_LOG_NAME 0x0 #define OPEN_RATE 0xE0 #define METADATA 0x13A // sizeof(short) -#define SCRIPT_FRAMES 0x63651C #endif \ No newline at end of file diff --git a/Test/RandomTests.cpp b/Test/RandomTests.cpp index a322752..a4fd410 100644 --- a/Test/RandomTests.cpp +++ b/Test/RandomTests.cpp @@ -7,7 +7,6 @@ TEST(RandomTests, RandomInRange) { ASSERT_NE(random1, random2); if (random1 > random2) std::swap(random1, random2); int random3 = Random::RandInt(random1, random2); - std::cout << random1 << " " << random2 << " " << random3 << std::endl; ASSERT_GE(random3, random1); ASSERT_LE(random3, random2); } diff --git a/Test/Temp.cpp b/Test/Temp.cpp index 14f3bbf..c847c6b 100644 --- a/Test/Temp.cpp +++ b/Test/Temp.cpp @@ -8,7 +8,12 @@ GTEST_TEST(SwapTests, Shipwreck) { int si1 = 0x00000022; int bu1 = 0x6; int td1 = 0x5D; + int ypp = 0x33EA; + int ramp_activation_shapers = 0x21D5; + int mill_upper_5 = 0x146C; + int mill_entry_left = 0x1E5A; + int mill_upper_7 = 0x03686; - randomizer.SwapPanels(si1, td1, Randomizer::SWAP::LINES); + randomizer.SwapPanels(ypp, mill_upper_7, Randomizer::SWAP::LINES); } diff --git a/WitnessRandomizer.sln b/WitnessRandomizer.sln index 7821549..a06af41 100644 --- a/WitnessRandomizer.sln +++ b/WitnessRandomizer.sln @@ -24,32 +24,36 @@ Global GlobalSection(ProjectConfigurationPlatforms) = postSolution {235D27F1-9907-489B-8D58-636A0C5CD079}.Debug|x64.ActiveCfg = Debug|x64 {235D27F1-9907-489B-8D58-636A0C5CD079}.Debug|x64.Build.0 = Debug|x64 - {235D27F1-9907-489B-8D58-636A0C5CD079}.Debug|x86.ActiveCfg = Debug|Win32 - {235D27F1-9907-489B-8D58-636A0C5CD079}.Debug|x86.Build.0 = Debug|Win32 - {235D27F1-9907-489B-8D58-636A0C5CD079}.Release|x64.ActiveCfg = Release|x64 - {235D27F1-9907-489B-8D58-636A0C5CD079}.Release|x64.Build.0 = Release|x64 - {235D27F1-9907-489B-8D58-636A0C5CD079}.Release|x86.ActiveCfg = Release|Win32 - {235D27F1-9907-489B-8D58-636A0C5CD079}.Release|x86.Build.0 = Release|Win32 + {235D27F1-9907-489B-8D58-636A0C5CD079}.Debug|x86.ActiveCfg = Debug|x64 + {235D27F1-9907-489B-8D58-636A0C5CD079}.Debug|x86.Build.0 = Debug|x64 + {235D27F1-9907-489B-8D58-636A0C5CD079}.Release|x64.ActiveCfg = Debug|x64 + {235D27F1-9907-489B-8D58-636A0C5CD079}.Release|x64.Build.0 = Debug|x64 + {235D27F1-9907-489B-8D58-636A0C5CD079}.Release|x86.ActiveCfg = Debug|x64 + {235D27F1-9907-489B-8D58-636A0C5CD079}.Release|x86.Build.0 = Debug|x64 {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Debug|x64.ActiveCfg = Debug|x64 {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Debug|x64.Build.0 = Debug|x64 - {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Debug|x86.ActiveCfg = Debug|Win32 - {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Debug|x86.Build.0 = Debug|Win32 - {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Release|x64.ActiveCfg = Release|x64 - {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Release|x64.Build.0 = Release|x64 - {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Release|x86.ActiveCfg = Release|Win32 - {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Release|x86.Build.0 = Release|Win32 + {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Debug|x86.ActiveCfg = Debug|x64 + {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Debug|x86.Build.0 = Debug|x64 + {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Release|x64.ActiveCfg = Debug|x64 + {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Release|x64.Build.0 = Debug|x64 + {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Release|x86.ActiveCfg = Debug|x64 + {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Release|x86.Build.0 = Debug|x64 {78DEDBBE-AC84-496D-8907-40089B464A5B}.Debug|x64.ActiveCfg = Debug + {78DEDBBE-AC84-496D-8907-40089B464A5B}.Debug|x64.Build.0 = Debug {78DEDBBE-AC84-496D-8907-40089B464A5B}.Debug|x86.ActiveCfg = Debug - {78DEDBBE-AC84-496D-8907-40089B464A5B}.Release|x64.ActiveCfg = Release - {78DEDBBE-AC84-496D-8907-40089B464A5B}.Release|x86.ActiveCfg = Release + {78DEDBBE-AC84-496D-8907-40089B464A5B}.Debug|x86.Build.0 = Debug + {78DEDBBE-AC84-496D-8907-40089B464A5B}.Release|x64.ActiveCfg = Debug + {78DEDBBE-AC84-496D-8907-40089B464A5B}.Release|x64.Build.0 = Debug + {78DEDBBE-AC84-496D-8907-40089B464A5B}.Release|x86.ActiveCfg = Debug + {78DEDBBE-AC84-496D-8907-40089B464A5B}.Release|x86.Build.0 = Debug {128784C2-9157-4291-8FD6-44637BE162FB}.Debug|x64.ActiveCfg = Debug|x64 {128784C2-9157-4291-8FD6-44637BE162FB}.Debug|x64.Build.0 = Debug|x64 - {128784C2-9157-4291-8FD6-44637BE162FB}.Debug|x86.ActiveCfg = Debug|Win32 - {128784C2-9157-4291-8FD6-44637BE162FB}.Debug|x86.Build.0 = Debug|Win32 - {128784C2-9157-4291-8FD6-44637BE162FB}.Release|x64.ActiveCfg = Release|x64 - {128784C2-9157-4291-8FD6-44637BE162FB}.Release|x64.Build.0 = Release|x64 - {128784C2-9157-4291-8FD6-44637BE162FB}.Release|x86.ActiveCfg = Release|Win32 - {128784C2-9157-4291-8FD6-44637BE162FB}.Release|x86.Build.0 = Release|Win32 + {128784C2-9157-4291-8FD6-44637BE162FB}.Debug|x86.ActiveCfg = Debug|x64 + {128784C2-9157-4291-8FD6-44637BE162FB}.Debug|x86.Build.0 = Debug|x64 + {128784C2-9157-4291-8FD6-44637BE162FB}.Release|x64.ActiveCfg = Debug|x64 + {128784C2-9157-4291-8FD6-44637BE162FB}.Release|x64.Build.0 = Debug|x64 + {128784C2-9157-4291-8FD6-44637BE162FB}.Release|x86.ActiveCfg = Debug|x64 + {128784C2-9157-4291-8FD6-44637BE162FB}.Release|x86.Build.0 = Debug|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- cgit 1.4.1