diff options
author | jbzdarkid <jbzdarkid@gmail.com> | 2019-11-04 08:43:31 -0800 |
---|---|---|
committer | jbzdarkid <jbzdarkid@gmail.com> | 2019-11-04 08:43:31 -0800 |
commit | 0cb49374a6d86100cd6f3bf838e79bdbac242a8e (patch) | |
tree | cab3a985cd5a7c8a448d3c0a67ff7588faed9c24 /Source | |
parent | edef920a2d7d753f93cd716052d8f2104bfdfa62 (diff) | |
download | witness-tutorializer-0cb49374a6d86100cd6f3bf838e79bdbac242a8e.tar.gz witness-tutorializer-0cb49374a6d86100cd6f3bf838e79bdbac242a8e.tar.bz2 witness-tutorializer-0cb49374a6d86100cd6f3bf838e79bdbac242a8e.zip |
Starting to clean up...
Diffstat (limited to 'Source')
-rw-r--r-- | Source/Memory.cpp | 24 | ||||
-rw-r--r-- | Source/Memory.h | 3 | ||||
-rw-r--r-- | Source/Randomizer.cpp | 63 | ||||
-rw-r--r-- | Source/Randomizer.h | 2 | ||||
-rw-r--r-- | Source/Source.vcxproj | 20 |
5 files changed, 87 insertions, 25 deletions
diff --git a/Source/Memory.cpp b/Source/Memory.cpp index 7bc3b2f..1f1ae0a 100644 --- a/Source/Memory.cpp +++ b/Source/Memory.cpp | |||
@@ -6,12 +6,16 @@ | |||
6 | #undef PROCESSENTRY32 | 6 | #undef PROCESSENTRY32 |
7 | #undef Process32Next | 7 | #undef Process32Next |
8 | 8 | ||
9 | Memory::Memory(const std::string& processName) { | 9 | Memory::Memory() { |
10 | } | ||
11 | |||
12 | [[nodiscard]] | ||
13 | bool Memory::Initialize(const std::wstring& processName) { | ||
10 | // First, get the handle of the process | 14 | // First, get the handle of the process |
11 | PROCESSENTRY32 entry; | 15 | PROCESSENTRY32W entry; |
12 | entry.dwSize = sizeof(entry); | 16 | entry.dwSize = sizeof(entry); |
13 | HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); | 17 | HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
14 | while (Process32Next(snapshot, &entry)) { | 18 | while (Process32NextW(snapshot, &entry)) { |
15 | if (processName == entry.szExeFile) { | 19 | if (processName == entry.szExeFile) { |
16 | _handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID); | 20 | _handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID); |
17 | break; | 21 | break; |
@@ -19,7 +23,7 @@ Memory::Memory(const std::string& processName) { | |||
19 | } | 23 | } |
20 | if (!_handle) { | 24 | if (!_handle) { |
21 | std::cerr << "Couldn't find " << processName.c_str() << ", is it open?" << std::endl; | 25 | std::cerr << "Couldn't find " << processName.c_str() << ", is it open?" << std::endl; |
22 | throw std::exception("Unable to find process!"); | 26 | return false; |
23 | } | 27 | } |
24 | 28 | ||
25 | // Next, get the process base address | 29 | // Next, get the process base address |
@@ -27,9 +31,9 @@ Memory::Memory(const std::string& processName) { | |||
27 | std::vector<HMODULE> moduleList(1024); | 31 | std::vector<HMODULE> moduleList(1024); |
28 | EnumProcessModulesEx(_handle, &moduleList[0], static_cast<DWORD>(moduleList.size()), &numModules, 3); | 32 | EnumProcessModulesEx(_handle, &moduleList[0], static_cast<DWORD>(moduleList.size()), &numModules, 3); |
29 | 33 | ||
30 | std::string name(64, '\0'); | 34 | std::wstring name(64, '\0'); |
31 | for (DWORD i = 0; i < numModules / sizeof(HMODULE); i++) { | 35 | for (DWORD i = 0; i < numModules / sizeof(HMODULE); i++) { |
32 | int length = GetModuleBaseNameA(_handle, moduleList[i], &name[0], static_cast<DWORD>(name.size())); | 36 | int length = GetModuleBaseNameW(_handle, moduleList[i], &name[0], static_cast<DWORD>(name.size())); |
33 | name.resize(length); | 37 | name.resize(length); |
34 | if (processName == name) { | 38 | if (processName == name) { |
35 | _baseAddress = (uintptr_t)moduleList[i]; | 39 | _baseAddress = (uintptr_t)moduleList[i]; |
@@ -37,12 +41,16 @@ Memory::Memory(const std::string& processName) { | |||
37 | } | 41 | } |
38 | } | 42 | } |
39 | if (_baseAddress == 0) { | 43 | if (_baseAddress == 0) { |
40 | throw std::exception("Couldn't find the base process address!"); | 44 | std::cerr << "Couldn't locate base address" << std::endl; |
45 | return false; | ||
41 | } | 46 | } |
47 | return true; | ||
42 | } | 48 | } |
43 | 49 | ||
44 | Memory::~Memory() { | 50 | Memory::~Memory() { |
45 | CloseHandle(_handle); | 51 | if (_handle != nullptr) { |
52 | CloseHandle(_handle); | ||
53 | } | ||
46 | } | 54 | } |
47 | 55 | ||
48 | int Memory::GetCurrentFrame() | 56 | int Memory::GetCurrentFrame() |
diff --git a/Source/Memory.h b/Source/Memory.h index cce06ba..9c00dab 100644 --- a/Source/Memory.h +++ b/Source/Memory.h | |||
@@ -14,7 +14,8 @@ | |||
14 | class Memory | 14 | class Memory |
15 | { | 15 | { |
16 | public: | 16 | public: |
17 | Memory(const std::string& processName); | 17 | Memory(); |
18 | bool Initialize(const std::wstring& processName); | ||
18 | ~Memory(); | 19 | ~Memory(); |
19 | 20 | ||
20 | Memory(const Memory& memory) = delete; | 21 | Memory(const Memory& memory) = delete; |
diff --git a/Source/Randomizer.cpp b/Source/Randomizer.cpp index 5e57ca3..71ec89b 100644 --- a/Source/Randomizer.cpp +++ b/Source/Randomizer.cpp | |||
@@ -1,4 +1,67 @@ | |||
1 | /* | 1 | /* |
2 | Things to do for V2: | ||
3 | - Better interface design. It's way too simplistic, take (some) notes from talos. | ||
4 | - Seed: [ ] (Randomize) | ||
5 | ?? Challenge | ||
6 | |||
7 | - [] Prevent speedrun snipes // Shadows, Swamp, Town, Quarry stairs | ||
8 | - [] Speed up various autoscrollers // Swamp platforms, Desert/Mountain elevators, Desert rotating panels | ||
9 | |||
10 | (Additional required panels) | ||
11 | - [] Desert 8 | ||
12 | - [] Pond 5 | ||
13 | - [] Both keep halves | ||
14 | - [] Town lattice requires stars door // and stars door will be randomized | ||
15 | |||
16 | (Debug version only) | ||
17 | - [] Noclip | ||
18 | - [] Noclip speed | ||
19 | |||
20 | |||
21 | - Really randomize panels. Sorted by ROI | ||
22 | - Random with style | ||
23 | - Tutorial | ||
24 | - Mountain 1 orange, green, blue, purple | ||
25 | - Mountain 2 multipanel | ||
26 | - Mountain 3 pillars | ||
27 | - Laser areas (Glass Factory, Symmetry, Quarry, Treehouse, Swamp, Keep pressure plates, Town 25 dots) | ||
28 | - (low) Discarded panels | ||
29 | - (low) Tutorials // Dots, Stones, Swamp | ||
30 | |||
31 | - Keep Hedges become like hedges 4, intersection between path and panel | ||
32 | - Keep Pressure plates: Random with style | ||
33 | |||
34 | - No idea how to randomize: | ||
35 | - Symmetry transparent | ||
36 | - Desert | ||
37 | - Shadows | ||
38 | - Town (lattice, RGB area, snipes, triple) | ||
39 | - Monastery | ||
40 | - Jungle | ||
41 | - Bunker | ||
42 | - UTM | ||
43 | - Mountain 2 rainbow | ||
44 | - Challenge | ||
45 | |||
46 | - Any RNG rerolls should be based on previous seed so that everyone can go to next seed easily | ||
47 | |||
48 | - Stability. Duh. I need to clearly define the ownership between the randomizer and the game. | ||
49 | |||
50 | - Challenge should have some way to 'reroll every run' | ||
51 | - Challenge should not turn off after time limit? | ||
52 | - Challenge triangles should not turn off | ||
53 | |||
54 | |||
55 | |||
56 | |||
57 | */ | ||
58 | |||
59 | |||
60 | |||
61 | |||
62 | |||
63 | |||
64 | /* | ||
2 | * Try to wire up both keep halves | 65 | * Try to wire up both keep halves |
3 | * Wire up both halves of symmetry laser | 66 | * Wire up both halves of symmetry laser |
4 | * Turn off floating panel in desert | 67 | * Turn off floating panel in desert |
diff --git a/Source/Randomizer.h b/Source/Randomizer.h index 6029513..020851b 100644 --- a/Source/Randomizer.h +++ b/Source/Randomizer.h | |||
@@ -45,7 +45,7 @@ private: | |||
45 | void ReassignTargets(const std::vector<int>& panels, const std::vector<int>& order, std::vector<int> targets = {}); | 45 | void ReassignTargets(const std::vector<int>& panels, const std::vector<int>& order, std::vector<int> targets = {}); |
46 | void ReassignNames(const std::vector<int>& panels, const std::vector<int>& order); | 46 | void ReassignNames(const std::vector<int>& panels, const std::vector<int>& order); |
47 | 47 | ||
48 | std::shared_ptr<Memory> _memory = std::make_shared<Memory>("witness64_d3d11.exe"); | 48 | std::shared_ptr<Memory> _memory = std::make_shared<Memory>(L"witness64_d3d11.exe"); |
49 | 49 | ||
50 | friend class SwapTests_Shipwreck_Test; | 50 | friend class SwapTests_Shipwreck_Test; |
51 | }; | 51 | }; |
diff --git a/Source/Source.vcxproj b/Source/Source.vcxproj index cf6756a..3e66f83 100644 --- a/Source/Source.vcxproj +++ b/Source/Source.vcxproj | |||
@@ -23,32 +23,32 @@ | |||
23 | <ProjectGuid>{6B5DF051-A51A-48CB-8ACD-C6FAD726019F}</ProjectGuid> | 23 | <ProjectGuid>{6B5DF051-A51A-48CB-8ACD-C6FAD726019F}</ProjectGuid> |
24 | <Keyword>Win32Proj</Keyword> | 24 | <Keyword>Win32Proj</Keyword> |
25 | <RootNamespace>Source</RootNamespace> | 25 | <RootNamespace>Source</RootNamespace> |
26 | <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion> | 26 | <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> |
27 | </PropertyGroup> | 27 | </PropertyGroup> |
28 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | 28 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> |
29 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | 29 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> |
30 | <ConfigurationType>StaticLibrary</ConfigurationType> | 30 | <ConfigurationType>StaticLibrary</ConfigurationType> |
31 | <UseDebugLibraries>true</UseDebugLibraries> | 31 | <UseDebugLibraries>true</UseDebugLibraries> |
32 | <PlatformToolset>v141</PlatformToolset> | 32 | <PlatformToolset>v142</PlatformToolset> |
33 | <CharacterSet>Unicode</CharacterSet> | 33 | <CharacterSet>Unicode</CharacterSet> |
34 | </PropertyGroup> | 34 | </PropertyGroup> |
35 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | 35 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> |
36 | <ConfigurationType>StaticLibrary</ConfigurationType> | 36 | <ConfigurationType>StaticLibrary</ConfigurationType> |
37 | <UseDebugLibraries>false</UseDebugLibraries> | 37 | <UseDebugLibraries>false</UseDebugLibraries> |
38 | <PlatformToolset>v141</PlatformToolset> | 38 | <PlatformToolset>v142</PlatformToolset> |
39 | <WholeProgramOptimization>true</WholeProgramOptimization> | 39 | <WholeProgramOptimization>true</WholeProgramOptimization> |
40 | <CharacterSet>Unicode</CharacterSet> | 40 | <CharacterSet>Unicode</CharacterSet> |
41 | </PropertyGroup> | 41 | </PropertyGroup> |
42 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | 42 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> |
43 | <ConfigurationType>StaticLibrary</ConfigurationType> | 43 | <ConfigurationType>StaticLibrary</ConfigurationType> |
44 | <UseDebugLibraries>true</UseDebugLibraries> | 44 | <UseDebugLibraries>true</UseDebugLibraries> |
45 | <PlatformToolset>v141</PlatformToolset> | 45 | <PlatformToolset>v142</PlatformToolset> |
46 | <CharacterSet>Unicode</CharacterSet> | 46 | <CharacterSet>Unicode</CharacterSet> |
47 | </PropertyGroup> | 47 | </PropertyGroup> |
48 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | 48 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> |
49 | <ConfigurationType>StaticLibrary</ConfigurationType> | 49 | <ConfigurationType>StaticLibrary</ConfigurationType> |
50 | <UseDebugLibraries>false</UseDebugLibraries> | 50 | <UseDebugLibraries>false</UseDebugLibraries> |
51 | <PlatformToolset>v141</PlatformToolset> | 51 | <PlatformToolset>v142</PlatformToolset> |
52 | <WholeProgramOptimization>true</WholeProgramOptimization> | 52 | <WholeProgramOptimization>true</WholeProgramOptimization> |
53 | <CharacterSet>Unicode</CharacterSet> | 53 | <CharacterSet>Unicode</CharacterSet> |
54 | </PropertyGroup> | 54 | </PropertyGroup> |
@@ -157,20 +157,10 @@ | |||
157 | </Link> | 157 | </Link> |
158 | </ItemDefinitionGroup> | 158 | </ItemDefinitionGroup> |
159 | <ItemGroup> | 159 | <ItemGroup> |
160 | <ClInclude Include="ChallengeRandomizer.h" /> | ||
161 | <ClInclude Include="json.hpp" /> | ||
162 | <ClInclude Include="Memory.h" /> | 160 | <ClInclude Include="Memory.h" /> |
163 | <ClInclude Include="Panel.h" /> | ||
164 | <ClInclude Include="Panels.h" /> | ||
165 | <ClInclude Include="Random.h" /> | ||
166 | <ClInclude Include="Randomizer.h" /> | ||
167 | </ItemGroup> | 161 | </ItemGroup> |
168 | <ItemGroup> | 162 | <ItemGroup> |
169 | <ClCompile Include="ChallengeRandomizer.cpp" /> | ||
170 | <ClCompile Include="Memory.cpp" /> | 163 | <ClCompile Include="Memory.cpp" /> |
171 | <ClCompile Include="Panel.cpp" /> | ||
172 | <ClCompile Include="Random.cpp" /> | ||
173 | <ClCompile Include="Randomizer.cpp" /> | ||
174 | </ItemGroup> | 164 | </ItemGroup> |
175 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | 165 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> |
176 | <ImportGroup Label="ExtensionTargets"> | 166 | <ImportGroup Label="ExtensionTargets"> |