about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Source/Memory.cpp35
-rw-r--r--Source/Memory.h8
-rw-r--r--Source/Panel.h2
-rw-r--r--Source/Randomizer.cpp19
-rw-r--r--Source/Randomizer.h2
-rw-r--r--Test/RandomTests.cpp1
-rw-r--r--Test/Temp.cpp7
-rw-r--r--WitnessRandomizer.sln44
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) {
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
48int 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
50void Memory::ThrowError() { 61void 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
57void* Memory::ComputeOffset(std::vector<int> offsets) 68void* 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
46private:
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
69private:
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
30bool Randomizer::GameIsRandomized() { 29bool 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() {
41void Randomizer::Randomize() 40void 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
349short Randomizer::ReadMetadata() {
350 return _memory->ReadData<short>({GLOBALS + METADATA}, 1)[0];
351}
352
353void Randomizer::WriteMetadata(short metadata) {
354 return _memory->WriteData<short>({GLOBALS + METADATA}, {metadata});
355}
356
357int 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
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) {
7 ASSERT_NE(random1, random2); 7 ASSERT_NE(random1, random2);
8 if (random1 > random2) std::swap(random1, random2); 8 if (random1 > random2) std::swap(random1, random2);
9 int random3 = Random::RandInt(random1, random2); 9 int random3 = Random::RandInt(random1, random2);
10 std::cout << random1 << " " << random2 << " " << random3 << std::endl;
11 ASSERT_GE(random3, random1); 10 ASSERT_GE(random3, random1);
12 ASSERT_LE(random3, random2); 11 ASSERT_LE(random3, random2);
13} 12}
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) {
8 int si1 = 0x00000022; 8 int si1 = 0x00000022;
9 int bu1 = 0x6; 9 int bu1 = 0x6;
10 int td1 = 0x5D; 10 int td1 = 0x5D;
11 int ypp = 0x33EA;
12 int ramp_activation_shapers = 0x21D5;
13 int mill_upper_5 = 0x146C;
14 int mill_entry_left = 0x1E5A;
15 int mill_upper_7 = 0x03686;
11 16
12 randomizer.SwapPanels(si1, td1, Randomizer::SWAP::LINES); 17 randomizer.SwapPanels(ypp, mill_upper_7, Randomizer::SWAP::LINES);
13 18
14} 19}
diff --git a/WitnessRandomizer.sln b/WitnessRandomizer.sln index 7821549..a06af41 100644 --- a/WitnessRandomizer.sln +++ b/WitnessRandomizer.sln
@@ -24,32 +24,36 @@ Global
24 GlobalSection(ProjectConfigurationPlatforms) = postSolution 24 GlobalSection(ProjectConfigurationPlatforms) = postSolution
25 {235D27F1-9907-489B-8D58-636A0C5CD079}.Debug|x64.ActiveCfg = Debug|x64 25 {235D27F1-9907-489B-8D58-636A0C5CD079}.Debug|x64.ActiveCfg = Debug|x64
26 {235D27F1-9907-489B-8D58-636A0C5CD079}.Debug|x64.Build.0 = Debug|x64 26 {235D27F1-9907-489B-8D58-636A0C5CD079}.Debug|x64.Build.0 = Debug|x64
27 {235D27F1-9907-489B-8D58-636A0C5CD079}.Debug|x86.ActiveCfg = Debug|Win32 27 {235D27F1-9907-489B-8D58-636A0C5CD079}.Debug|x86.ActiveCfg = Debug|x64
28 {235D27F1-9907-489B-8D58-636A0C5CD079}.Debug|x86.Build.0 = Debug|Win32 28 {235D27F1-9907-489B-8D58-636A0C5CD079}.Debug|x86.Build.0 = Debug|x64
29 {235D27F1-9907-489B-8D58-636A0C5CD079}.Release|x64.ActiveCfg = Release|x64 29 {235D27F1-9907-489B-8D58-636A0C5CD079}.Release|x64.ActiveCfg = Debug|x64
30 {235D27F1-9907-489B-8D58-636A0C5CD079}.Release|x64.Build.0 = Release|x64 30 {235D27F1-9907-489B-8D58-636A0C5CD079}.Release|x64.Build.0 = Debug|x64
31 {235D27F1-9907-489B-8D58-636A0C5CD079}.Release|x86.ActiveCfg = Release|Win32 31 {235D27F1-9907-489B-8D58-636A0C5CD079}.Release|x86.ActiveCfg = Debug|x64
32 {235D27F1-9907-489B-8D58-636A0C5CD079}.Release|x86.Build.0 = Release|Win32 32 {235D27F1-9907-489B-8D58-636A0C5CD079}.Release|x86.Build.0 = Debug|x64
33 {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Debug|x64.ActiveCfg = Debug|x64 33 {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Debug|x64.ActiveCfg = Debug|x64
34 {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Debug|x64.Build.0 = Debug|x64 34 {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Debug|x64.Build.0 = Debug|x64
35 {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Debug|x86.ActiveCfg = Debug|Win32 35 {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Debug|x86.ActiveCfg = Debug|x64
36 {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Debug|x86.Build.0 = Debug|Win32 36 {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Debug|x86.Build.0 = Debug|x64
37 {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Release|x64.ActiveCfg = Release|x64 37 {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Release|x64.ActiveCfg = Debug|x64
38 {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Release|x64.Build.0 = Release|x64 38 {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Release|x64.Build.0 = Debug|x64
39 {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Release|x86.ActiveCfg = Release|Win32 39 {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Release|x86.ActiveCfg = Debug|x64
40 {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Release|x86.Build.0 = Release|Win32 40 {6B5DF051-A51A-48CB-8ACD-C6FAD726019F}.Release|x86.Build.0 = Debug|x64
41 {78DEDBBE-AC84-496D-8907-40089B464A5B}.Debug|x64.ActiveCfg = Debug 41 {78DEDBBE-AC84-496D-8907-40089B464A5B}.Debug|x64.ActiveCfg = Debug
42 {78DEDBBE-AC84-496D-8907-40089B464A5B}.Debug|x64.Build.0 = Debug
42 {78DEDBBE-AC84-496D-8907-40089B464A5B}.Debug|x86.ActiveCfg = Debug 43 {78DEDBBE-AC84-496D-8907-40089B464A5B}.Debug|x86.ActiveCfg = Debug
43 {78DEDBBE-AC84-496D-8907-40089B464A5B}.Release|x64.ActiveCfg = Release 44 {78DEDBBE-AC84-496D-8907-40089B464A5B}.Debug|x86.Build.0 = Debug
44 {78DEDBBE-AC84-496D-8907-40089B464A5B}.Release|x86.ActiveCfg = Release 45 {78DEDBBE-AC84-496D-8907-40089B464A5B}.Release|x64.ActiveCfg = Debug
46 {78DEDBBE-AC84-496D-8907-40089B464A5B}.Release|x64.Build.0 = Debug
47 {78DEDBBE-AC84-496D-8907-40089B464A5B}.Release|x86.ActiveCfg = Debug
48 {78DEDBBE-AC84-496D-8907-40089B464A5B}.Release|x86.Build.0 = Debug
45 {128784C2-9157-4291-8FD6-44637BE162FB}.Debug|x64.ActiveCfg = Debug|x64 49 {128784C2-9157-4291-8FD6-44637BE162FB}.Debug|x64.ActiveCfg = Debug|x64
46 {128784C2-9157-4291-8FD6-44637BE162FB}.Debug|x64.Build.0 = Debug|x64 50 {128784C2-9157-4291-8FD6-44637BE162FB}.Debug|x64.Build.0 = Debug|x64
47 {128784C2-9157-4291-8FD6-44637BE162FB}.Debug|x86.ActiveCfg = Debug|Win32 51 {128784C2-9157-4291-8FD6-44637BE162FB}.Debug|x86.ActiveCfg = Debug|x64
48 {128784C2-9157-4291-8FD6-44637BE162FB}.Debug|x86.Build.0 = Debug|Win32 52 {128784C2-9157-4291-8FD6-44637BE162FB}.Debug|x86.Build.0 = Debug|x64
49 {128784C2-9157-4291-8FD6-44637BE162FB}.Release|x64.ActiveCfg = Release|x64 53 {128784C2-9157-4291-8FD6-44637BE162FB}.Release|x64.ActiveCfg = Debug|x64
50 {128784C2-9157-4291-8FD6-44637BE162FB}.Release|x64.Build.0 = Release|x64 54 {128784C2-9157-4291-8FD6-44637BE162FB}.Release|x64.Build.0 = Debug|x64
51 {128784C2-9157-4291-8FD6-44637BE162FB}.Release|x86.ActiveCfg = Release|Win32 55 {128784C2-9157-4291-8FD6-44637BE162FB}.Release|x86.ActiveCfg = Debug|x64
52 {128784C2-9157-4291-8FD6-44637BE162FB}.Release|x86.Build.0 = Release|Win32 56 {128784C2-9157-4291-8FD6-44637BE162FB}.Release|x86.Build.0 = Debug|x64
53 EndGlobalSection 57 EndGlobalSection
54 GlobalSection(SolutionProperties) = preSolution 58 GlobalSection(SolutionProperties) = preSolution
55 HideSolutionNode = FALSE 59 HideSolutionNode = FALSE