diff options
Diffstat (limited to 'Source')
| -rw-r--r-- | Source/Memory.cpp | 35 | ||||
| -rw-r--r-- | Source/Memory.h | 8 | ||||
| -rw-r--r-- | Source/Panel.h | 2 | ||||
| -rw-r--r-- | Source/Randomizer.cpp | 19 | ||||
| -rw-r--r-- | Source/Randomizer.h | 2 |
5 files changed, 31 insertions, 35 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) { | |||
| 18 | } | 18 | } |
| 19 | } | 19 | } |
| 20 | if (!_handle) { | 20 | if (!_handle) { |
| 21 | std::cout << "Couldn't find " << processName.c_str() << ", is it open?" << std::endl; | 21 | std::cerr << "Couldn't find " << processName.c_str() << ", is it open?" << std::endl; |
| 22 | exit(EXIT_FAILURE); | 22 | throw std::exception("Unable to find process!"); |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | // Next, get the process base address | 25 | // Next, get the process base address |
| @@ -27,19 +27,17 @@ Memory::Memory(const std::string& processName) { | |||
| 27 | std::vector<HMODULE> moduleList(1024); | 27 | std::vector<HMODULE> moduleList(1024); |
| 28 | EnumProcessModulesEx(_handle, &moduleList[0], static_cast<DWORD>(moduleList.size()), &numModules, 3); | 28 | EnumProcessModulesEx(_handle, &moduleList[0], static_cast<DWORD>(moduleList.size()), &numModules, 3); |
| 29 | 29 | ||
| 30 | std::string name(64, 0); | 30 | std::string name(64, '\0'); |
| 31 | for (DWORD i = 0; i < numModules / sizeof(HMODULE); i++) { | 31 | for (DWORD i = 0; i < numModules / sizeof(HMODULE); i++) { |
| 32 | GetModuleBaseNameA(_handle, moduleList[i], &name[0], sizeof(name)); | 32 | int length = GetModuleBaseNameA(_handle, moduleList[i], &name[0], static_cast<DWORD>(name.size())); |
| 33 | 33 | name.resize(length); | |
| 34 | // TODO: Filling with 0s still yeilds name.size() == 64... | 34 | if (processName == name) { |
| 35 | if (strcmp(processName.c_str(), name.c_str()) == 0) { | ||
| 36 | _baseAddress = (uintptr_t)moduleList[i]; | 35 | _baseAddress = (uintptr_t)moduleList[i]; |
| 37 | break; | 36 | break; |
| 38 | } | 37 | } |
| 39 | } | 38 | } |
| 40 | if (_baseAddress == 0) { | 39 | if (_baseAddress == 0) { |
| 41 | std::cout << "Couldn't find the base process address!" << std::endl; | 40 | throw std::exception("Couldn't find the base process address!"); |
| 42 | exit(EXIT_FAILURE); | ||
| 43 | } | 41 | } |
| 44 | } | 42 | } |
| 45 | 43 | ||
| @@ -47,11 +45,24 @@ Memory::~Memory() { | |||
| 47 | CloseHandle(_handle); | 45 | CloseHandle(_handle); |
| 48 | } | 46 | } |
| 49 | 47 | ||
| 48 | int Memory::GetCurrentFrame() | ||
| 49 | { | ||
| 50 | int SCRIPT_FRAMES; | ||
| 51 | if (GLOBALS == 0x5B28C0) { | ||
| 52 | SCRIPT_FRAMES = 0x5BE3B0; | ||
| 53 | } else if (GLOBALS == 0x62A080) { | ||
| 54 | SCRIPT_FRAMES = 0x63651C; | ||
| 55 | } else { | ||
| 56 | throw std::exception("Unknown value for Globals!"); | ||
| 57 | } | ||
| 58 | return ReadData<int>({SCRIPT_FRAMES}, 1)[0]; | ||
| 59 | } | ||
| 60 | |||
| 50 | void Memory::ThrowError() { | 61 | void Memory::ThrowError() { |
| 51 | std::string message(256, '\0'); | 62 | std::string message(256, '\0'); |
| 52 | FormatMessageA(4096, nullptr, GetLastError(), 1024, &message[0], static_cast<DWORD>(message.length()), nullptr); | 63 | int length = FormatMessageA(4096, nullptr, GetLastError(), 1024, &message[0], static_cast<DWORD>(message.size()), nullptr); |
| 53 | std::cout << message.c_str() << std::endl; | 64 | message.resize(length); |
| 54 | exit(EXIT_FAILURE); | 65 | throw std::exception(message.c_str()); |
| 55 | } | 66 | } |
| 56 | 67 | ||
| 57 | void* Memory::ComputeOffset(std::vector<int> offsets) | 68 | void* Memory::ComputeOffset(std::vector<int> 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: | |||
| 19 | Memory(const Memory& memory) = delete; | 19 | Memory(const Memory& memory) = delete; |
| 20 | Memory& operator=(const Memory& other) = delete; | 20 | Memory& operator=(const Memory& other) = delete; |
| 21 | 21 | ||
| 22 | int GetCurrentFrame(); | ||
| 22 | 23 | ||
| 23 | template <class T> | 24 | template <class T> |
| 24 | std::vector<T> ReadArray(int panel, int offset, int size) { | 25 | std::vector<T> ReadArray(int panel, int offset, int size) { |
| @@ -40,6 +41,9 @@ public: | |||
| 40 | WriteData<T>({GLOBALS, 0x18, panel*8, offset}, data); | 41 | WriteData<T>({GLOBALS, 0x18, panel*8, offset}, data); |
| 41 | } | 42 | } |
| 42 | 43 | ||
| 44 | void ClearOffsets() {_computedAddresses = std::map<uintptr_t, uintptr_t>();} | ||
| 45 | |||
| 46 | private: | ||
| 43 | template<class T> | 47 | template<class T> |
| 44 | std::vector<T> ReadData(const std::vector<int>& offsets, size_t numItems) { | 48 | std::vector<T> ReadData(const std::vector<int>& offsets, size_t numItems) { |
| 45 | std::vector<T> data; | 49 | std::vector<T> data; |
| @@ -64,10 +68,6 @@ public: | |||
| 64 | ThrowError(); | 68 | ThrowError(); |
| 65 | } | 69 | } |
| 66 | 70 | ||
| 67 | void ClearOffsets() {_computedAddresses = std::map<uintptr_t, uintptr_t>();} | ||
| 68 | |||
| 69 | private: | ||
| 70 | |||
| 71 | void ThrowError(); | 71 | void ThrowError(); |
| 72 | 72 | ||
| 73 | void* ComputeOffset(std::vector<int> offsets); | 73 | void* ComputeOffset(std::vector<int> 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 { | |||
| 45 | IS_ENDPOINT = 0x1, | 45 | IS_ENDPOINT = 0x1, |
| 46 | IS_STARTPOINT = 0x2, | 46 | IS_STARTPOINT = 0x2, |
| 47 | IS_GAP = 0x10000, | 47 | IS_GAP = 0x10000, |
| 48 | HAS_DOT = 0x8, | 48 | HAS_DOT = 0x20, |
| 49 | DOT_IS_BLUE = 0x100, | 49 | DOT_IS_BLUE = 0x100, |
| 50 | DOT_IS_ORANGE = 0x200, | 50 | DOT_IS_ORANGE = 0x200, |
| 51 | DOT_IS_INVISIBLE = 0x1000, | 51 | 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 @@ | |||
| 5 | * FEATURES: | 5 | * FEATURES: |
| 6 | * Start the game if it isn't running? | 6 | * Start the game if it isn't running? |
| 7 | * Stop swapping colors in desert | 7 | * Stop swapping colors in desert |
| 8 | * Look into valid panel swaps for keep walk-ons. | ||
| 9 | * Randomize audio logs -- Hard, seem to be unloaded some times? | 8 | * Randomize audio logs -- Hard, seem to be unloaded some times? |
| 10 | * Swap sounds in jungle (along with panels) -- maybe impossible | 9 | * Swap sounds in jungle (along with panels) -- maybe impossible |
| 11 | * Make orange 7 (all of oranges?) hard. Like big = hard. (See: HARD_MODE) | 10 | * Make orange 7 (all of oranges?) hard. Like big = hard. (See: HARD_MODE) |
| @@ -24,11 +23,11 @@ int find(const std::vector<T> &data, T search, size_t startIndex = 0) { | |||
| 24 | if (data[i] == search) return static_cast<int>(i); | 23 | if (data[i] == search) return static_cast<int>(i); |
| 25 | } | 24 | } |
| 26 | std::cout << "Couldn't find " << search << " in data!" << std::endl; | 25 | std::cout << "Couldn't find " << search << " in data!" << std::endl; |
| 27 | exit(-1); | 26 | throw std::exception("Couldn't find value in data!"); |
| 28 | } | 27 | } |
| 29 | 28 | ||
| 30 | bool Randomizer::GameIsRandomized() { | 29 | bool Randomizer::GameIsRandomized() { |
| 31 | int currentFrame = GetCurrentFrame(); | 30 | int currentFrame = _memory->GetCurrentFrame(); |
| 32 | if (currentFrame >= _lastRandomizedFrame) { | 31 | if (currentFrame >= _lastRandomizedFrame) { |
| 33 | // Time went forwards, presumably we're still on the same save | 32 | // Time went forwards, presumably we're still on the same save |
| 34 | _lastRandomizedFrame = currentFrame; | 33 | _lastRandomizedFrame = currentFrame; |
| @@ -41,7 +40,7 @@ bool Randomizer::GameIsRandomized() { | |||
| 41 | void Randomizer::Randomize() | 40 | void Randomizer::Randomize() |
| 42 | { | 41 | { |
| 43 | if (GameIsRandomized()) return; // Nice sanity check, but should be unnecessary (since Main checks anyways) | 42 | if (GameIsRandomized()) return; // Nice sanity check, but should be unnecessary (since Main checks anyways) |
| 44 | _lastRandomizedFrame = GetCurrentFrame(); | 43 | _lastRandomizedFrame = _memory->GetCurrentFrame(); |
| 45 | 44 | ||
| 46 | // Content swaps -- must happen before squarePanels | 45 | // Content swaps -- must happen before squarePanels |
| 47 | Randomize(upDownPanels, SWAP::LINES); | 46 | Randomize(upDownPanels, SWAP::LINES); |
| @@ -345,15 +344,3 @@ void Randomizer::ReassignNames(const std::vector<int>& panels, const std::vector | |||
| 345 | _memory->WritePanelData<int64_t>(panels[i], AUDIO_LOG_NAME, {names[order[i]]}); | 344 | _memory->WritePanelData<int64_t>(panels[i], AUDIO_LOG_NAME, {names[order[i]]}); |
| 346 | } | 345 | } |
| 347 | } | 346 | } |
| 348 | |||
| 349 | short Randomizer::ReadMetadata() { | ||
| 350 | return _memory->ReadData<short>({GLOBALS + METADATA}, 1)[0]; | ||
| 351 | } | ||
| 352 | |||
| 353 | void Randomizer::WriteMetadata(short metadata) { | ||
| 354 | return _memory->WriteData<short>({GLOBALS + METADATA}, {metadata}); | ||
| 355 | } | ||
| 356 | |||
| 357 | int Randomizer::GetCurrentFrame() { | ||
| 358 | return _memory->ReadData<int>({SCRIPT_FRAMES}, 1)[0]; | ||
| 359 | } | ||
| 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: | |||
| 117 | #define AUDIO_LOG_NAME 0xC8 | 117 | #define AUDIO_LOG_NAME 0xC8 |
| 118 | #define OPEN_RATE 0xE8 | 118 | #define OPEN_RATE 0xE8 |
| 119 | #define METADATA 0xF2 // sizeof(short) | 119 | #define METADATA 0xF2 // sizeof(short) |
| 120 | #define SCRIPT_FRAMES 0x5BE3B0 | ||
| 121 | #elif GLOBALS == 0x62A080 | 120 | #elif GLOBALS == 0x62A080 |
| 122 | #define PATH_COLOR 0xC0 | 121 | #define PATH_COLOR 0xC0 |
| 123 | #define REFLECTION_PATH_COLOR 0xD0 | 122 | #define REFLECTION_PATH_COLOR 0xD0 |
| @@ -183,5 +182,4 @@ private: | |||
| 183 | #define AUDIO_LOG_NAME 0x0 | 182 | #define AUDIO_LOG_NAME 0x0 |
| 184 | #define OPEN_RATE 0xE0 | 183 | #define OPEN_RATE 0xE0 |
| 185 | #define METADATA 0x13A // sizeof(short) | 184 | #define METADATA 0x13A // sizeof(short) |
| 186 | #define SCRIPT_FRAMES 0x63651C | ||
| 187 | #endif \ No newline at end of file | 185 | #endif \ No newline at end of file |
