diff options
author | jbzdarkid <jbzdarkid@gmail.com> | 2018-10-30 21:58:46 -0700 |
---|---|---|
committer | jbzdarkid <jbzdarkid@gmail.com> | 2018-10-30 21:58:46 -0700 |
commit | 3557f0ba80942397a9d963208695b4fa80290cb0 (patch) | |
tree | d754d0f1b56ca10c133804639882d12d6686f7ec /Source | |
parent | e66a408e38849107a3d35a317ff6f2b23dcaeead (diff) | |
download | witness-tutorializer-3557f0ba80942397a9d963208695b4fa80290cb0.tar.gz witness-tutorializer-3557f0ba80942397a9d963208695b4fa80290cb0.tar.bz2 witness-tutorializer-3557f0ba80942397a9d963208695b4fa80290cb0.zip |
Infinite amounts of cleanup
Diffstat (limited to 'Source')
-rw-r--r-- | Source/Main.cpp | 13 | ||||
-rw-r--r-- | Source/Random.h | 3 | ||||
-rw-r--r-- | Source/Randomizer.cpp | 17 | ||||
-rw-r--r-- | Source/Randomizer.h | 2 | ||||
-rw-r--r-- | Source/RandomizerCore.cpp | 19 | ||||
-rw-r--r-- | Source/RandomizerCore.h | 9 | ||||
-rw-r--r-- | Source/Resource.h | 26 | ||||
-rw-r--r-- | Source/Source.vcxproj | 5 | ||||
-rw-r--r-- | Source/Source.vcxproj.filters | 3 | ||||
-rw-r--r-- | Source/Version.h | 10 | ||||
-rw-r--r-- | Source/Version.rc | 24 |
11 files changed, 58 insertions, 73 deletions
diff --git a/Source/Main.cpp b/Source/Main.cpp index 28bc472..8336c77 100644 --- a/Source/Main.cpp +++ b/Source/Main.cpp | |||
@@ -1,8 +1,6 @@ | |||
1 | #include "windows.h" | 1 | #include "windows.h" |
2 | #include "resource.h" | ||
3 | #include <Richedit.h> | 2 | #include <Richedit.h> |
4 | 3 | ||
5 | #include <ctime> | ||
6 | #include <string> | 4 | #include <string> |
7 | 5 | ||
8 | #include "Randomizer.h" | 6 | #include "Randomizer.h" |
@@ -40,18 +38,19 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) | |||
40 | GetWindowText(hwndSeed, &text[0], 100); | 38 | GetWindowText(hwndSeed, &text[0], 100); |
41 | int seed = 0; | 39 | int seed = 0; |
42 | if (wasSeedRandomlyGenerated || wcslen(text.c_str()) == 0) { | 40 | if (wasSeedRandomlyGenerated || wcslen(text.c_str()) == 0) { |
43 | Random::SetSeed(time(nullptr)); // Seed from the time in milliseconds | ||
44 | seed = Random::RandInt(0, 100000); | 41 | seed = Random::RandInt(0, 100000); |
45 | std::wstring seedString = std::to_wstring(seed); | ||
46 | SetWindowText(hwndSeed, seedString.c_str()); | ||
47 | wasSeedRandomlyGenerated = true; | 42 | wasSeedRandomlyGenerated = true; |
48 | } else { | 43 | } else { |
49 | seed = _wtoi(text.c_str()); | 44 | seed = _wtoi(text.c_str()); |
50 | wasSeedRandomlyGenerated = false; | 45 | wasSeedRandomlyGenerated = false; |
51 | } | 46 | } |
52 | Random::SetSeed(seed); | 47 | |
53 | Randomizer randomizer; | 48 | Randomizer randomizer; |
54 | randomizer.Randomize(); | 49 | short metadata = randomizer.Randomize(seed); |
50 | if (metadata & 0x1) break; // Was already randomized | ||
51 | |||
52 | std::wstring seedString = std::to_wstring(seed); | ||
53 | SetWindowText(hwndSeed, seedString.c_str()); | ||
55 | if (IsDlgButtonChecked(hwnd, IDC_TOGGLESPEED)) { | 54 | if (IsDlgButtonChecked(hwnd, IDC_TOGGLESPEED)) { |
56 | randomizer.AdjustSpeed(); | 55 | randomizer.AdjustSpeed(); |
57 | } | 56 | } |
diff --git a/Source/Random.h b/Source/Random.h index e4700f3..40998de 100644 --- a/Source/Random.h +++ b/Source/Random.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #pragma once | 1 | #pragma once |
2 | #include <chrono> | ||
2 | 3 | ||
3 | static int s_seed; | 4 | static int s_seed = time(nullptr); // Seed from the time in milliseconds |
4 | 5 | ||
5 | class Random | 6 | class Random |
6 | { | 7 | { |
diff --git a/Source/Randomizer.cpp b/Source/Randomizer.cpp index 83f5571..9622601 100644 --- a/Source/Randomizer.cpp +++ b/Source/Randomizer.cpp | |||
@@ -4,21 +4,21 @@ | |||
4 | * Swamp <-> symmetry has non-invisible background | 4 | * Swamp <-> symmetry has non-invisible background |
5 | * Tutorial sounds don't always play | 5 | * Tutorial sounds don't always play |
6 | * FEATURES: | 6 | * FEATURES: |
7 | * Prevent re-randomization (?) | 7 | * Clear "Randomized" button after short delay |
8 | * Clear "Randomized" state on NG (?) -- Or on a short delay | ||
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. | 10 | * Make orange 7 (all of oranges?) hard. Like big = hard. |
12 | * Start the game if it isn't running? | 11 | * Start the game if it isn't running? |
13 | * Stop swapping colors in desert | 12 | * Stop swapping colors in desert |
13 | * Allow users to enter seed after randomly generating seed (aka detect user input in the text box) | ||
14 | */ | 14 | */ |
15 | #include "Memory.h" | 15 | #include "Memory.h" |
16 | #include "Randomizer.h" | 16 | #include "Randomizer.h" |
17 | #include "Panels.h" | 17 | #include "Panels.h" |
18 | #include "Random.h" | ||
18 | #include <string> | 19 | #include <string> |
19 | #include <iostream> | 20 | #include <iostream> |
20 | #include <numeric> | 21 | #include <numeric> |
21 | #include <chrono> | ||
22 | 22 | ||
23 | template <class T> | 23 | template <class T> |
24 | int find(const std::vector<T> &data, T search, size_t startIndex = 0) { | 24 | int find(const std::vector<T> &data, T search, size_t startIndex = 0) { |
@@ -29,8 +29,16 @@ int find(const std::vector<T> &data, T search, size_t startIndex = 0) { | |||
29 | exit(-1); | 29 | exit(-1); |
30 | } | 30 | } |
31 | 31 | ||
32 | void Randomizer::Randomize() | 32 | short Randomizer::Randomize(int seed) |
33 | { | 33 | { |
34 | short metadata = _core.ReadMetadata(); | ||
35 | if (metadata & 0x1) { | ||
36 | // Already randomized -- exit. | ||
37 | return metadata; | ||
38 | } | ||
39 | _core.WriteMetadata(metadata | 0x1); | ||
40 | Random::SetSeed(seed); | ||
41 | |||
34 | // Content swaps -- must happen before squarePanels | 42 | // Content swaps -- must happen before squarePanels |
35 | _core.Randomize(upDownPanels, SWAP_LINES); | 43 | _core.Randomize(upDownPanels, SWAP_LINES); |
36 | _core.Randomize(leftForwardRightPanels, SWAP_LINES); | 44 | _core.Randomize(leftForwardRightPanels, SWAP_LINES); |
@@ -53,6 +61,7 @@ void Randomizer::Randomize() | |||
53 | RandomizeMountain(); | 61 | RandomizeMountain(); |
54 | // RandomizeChallenge(); | 62 | // RandomizeChallenge(); |
55 | // RandomizeAudioLogs(); | 63 | // RandomizeAudioLogs(); |
64 | return metadata; | ||
56 | } | 65 | } |
57 | 66 | ||
58 | void Randomizer::AdjustSpeed() { | 67 | void Randomizer::AdjustSpeed() { |
diff --git a/Source/Randomizer.h b/Source/Randomizer.h index b0da4fe..8c332b0 100644 --- a/Source/Randomizer.h +++ b/Source/Randomizer.h | |||
@@ -3,7 +3,7 @@ | |||
3 | 3 | ||
4 | class Randomizer { | 4 | class Randomizer { |
5 | public: | 5 | public: |
6 | void Randomize(); | 6 | short Randomize(int seed); |
7 | void AdjustSpeed(); | 7 | void AdjustSpeed(); |
8 | 8 | ||
9 | private: | 9 | private: |
diff --git a/Source/RandomizerCore.cpp b/Source/RandomizerCore.cpp index 684e19d..f14a76f 100644 --- a/Source/RandomizerCore.cpp +++ b/Source/RandomizerCore.cpp | |||
@@ -3,6 +3,17 @@ | |||
3 | #include "Random.h" | 3 | #include "Random.h" |
4 | #include <sstream> | 4 | #include <sstream> |
5 | 5 | ||
6 | static int lastKnownFrame = 1 << 30; | ||
7 | |||
8 | RandomizerCore::RandomizerCore() { | ||
9 | int currentFrame = _memory.ReadData<int>({SCRIPT_FRAMES}, 1)[0]; | ||
10 | if (currentFrame < lastKnownFrame) { | ||
11 | // Time went backwards, indicates new game | ||
12 | WriteMetadata(0); | ||
13 | } | ||
14 | lastKnownFrame = currentFrame; | ||
15 | } | ||
16 | |||
6 | void RandomizerCore::Randomize(std::vector<int>& panels, int flags) { | 17 | void RandomizerCore::Randomize(std::vector<int>& panels, int flags) { |
7 | return RandomizeRange(panels, flags, 0, panels.size()); | 18 | return RandomizeRange(panels, flags, 0, panels.size()); |
8 | } | 19 | } |
@@ -125,3 +136,11 @@ void RandomizerCore::ReassignNames(const std::vector<int>& panels, const std::ve | |||
125 | WritePanelData<int64_t>(panels[i], AUDIO_LOG_NAME, {names[order[i]]}); | 136 | WritePanelData<int64_t>(panels[i], AUDIO_LOG_NAME, {names[order[i]]}); |
126 | } | 137 | } |
127 | } | 138 | } |
139 | |||
140 | short RandomizerCore::ReadMetadata() { | ||
141 | return _memory.ReadData<short>({GLOBALS + METADATA}, 1)[0]; | ||
142 | } | ||
143 | |||
144 | void RandomizerCore::WriteMetadata(short metadata) { | ||
145 | return _memory.WriteData<short>({GLOBALS + METADATA}, {metadata}); | ||
146 | } \ No newline at end of file | ||
diff --git a/Source/RandomizerCore.h b/Source/RandomizerCore.h index e8d3661..7ec8e33 100644 --- a/Source/RandomizerCore.h +++ b/Source/RandomizerCore.h | |||
@@ -12,6 +12,8 @@ __declspec(selectany) int SWAP_AUDIO_NAMES = 0x4; | |||
12 | class RandomizerCore | 12 | class RandomizerCore |
13 | { | 13 | { |
14 | public: | 14 | public: |
15 | RandomizerCore(); | ||
16 | |||
15 | void Randomize(std::vector<int>& panels, int flags); | 17 | void Randomize(std::vector<int>& panels, int flags); |
16 | void RandomizeRange(std::vector<int> &panels, int flags, size_t startIndex, size_t endIndex); | 18 | void RandomizeRange(std::vector<int> &panels, int flags, size_t startIndex, size_t endIndex); |
17 | void SwapPanels(int panel1, int panel2, int flags); | 19 | void SwapPanels(int panel1, int panel2, int flags); |
@@ -28,6 +30,9 @@ public: | |||
28 | _memory.WriteData<T>({GLOBALS, 0x18, panel*8, offset}, data); | 30 | _memory.WriteData<T>({GLOBALS, 0x18, panel*8, offset}, data); |
29 | } | 31 | } |
30 | 32 | ||
33 | short ReadMetadata(); | ||
34 | void WriteMetadata(short metadata); | ||
35 | |||
31 | private: | 36 | private: |
32 | Memory _memory = Memory("witness64_d3d11.exe"); | 37 | Memory _memory = Memory("witness64_d3d11.exe"); |
33 | }; | 38 | }; |
@@ -95,6 +100,8 @@ private: | |||
95 | #define CABLE_TARGET_2 0xD8 | 100 | #define CABLE_TARGET_2 0xD8 |
96 | #define AUDIO_LOG_NAME 0xC8 | 101 | #define AUDIO_LOG_NAME 0xC8 |
97 | #define OPEN_RATE 0xE8 | 102 | #define OPEN_RATE 0xE8 |
103 | #define METADATA 0xF2 // sizeof(short) | ||
104 | #define SCRIPT_FRAMES 0x5BE3B0 | ||
98 | #elif GLOBALS == 0x62A080 | 105 | #elif GLOBALS == 0x62A080 |
99 | #define PATH_COLOR 0xC0 | 106 | #define PATH_COLOR 0xC0 |
100 | #define REFLECTION_PATH_COLOR 0xD0 | 107 | #define REFLECTION_PATH_COLOR 0xD0 |
@@ -158,4 +165,6 @@ private: | |||
158 | #define CABLE_TARGET_2 0xD0 | 165 | #define CABLE_TARGET_2 0xD0 |
159 | #define AUDIO_LOG_NAME 0x0 | 166 | #define AUDIO_LOG_NAME 0x0 |
160 | #define OPEN_RATE 0xE0 | 167 | #define OPEN_RATE 0xE0 |
168 | #define METADATA 0x13A // sizeof(short) | ||
169 | #define SCRIPT_FRAMES 0x63651C | ||
161 | #endif \ No newline at end of file | 170 | #endif \ No newline at end of file |
diff --git a/Source/Resource.h b/Source/Resource.h deleted file mode 100644 index 426abc1..0000000 --- a/Source/Resource.h +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | //{{NO_DEPENDENCIES}} | ||
2 | // Microsoft Visual C++ generated include file. | ||
3 | // Used by Source.rc | ||
4 | // | ||
5 | #define IDC_MYICON 2 | ||
6 | #define IDD_SOURCE_DIALOG 102 | ||
7 | #define IDS_APP_TITLE 103 | ||
8 | #define IDM_ABOUT 104 | ||
9 | #define IDM_EXIT 105 | ||
10 | #define IDI_SOURCE 107 | ||
11 | #define IDI_SMALL 108 | ||
12 | #define IDC_SOURCE 109 | ||
13 | #define IDR_MAINFRAME 128 | ||
14 | #define IDC_STATIC -1 | ||
15 | |||
16 | // Next default values for new objects | ||
17 | // | ||
18 | #ifdef APSTUDIO_INVOKED | ||
19 | #ifndef APSTUDIO_READONLY_SYMBOLS | ||
20 | #define _APS_NO_MFC 1 | ||
21 | #define _APS_NEXT_RESOURCE_VALUE 129 | ||
22 | #define _APS_NEXT_COMMAND_VALUE 32771 | ||
23 | #define _APS_NEXT_CONTROL_VALUE 1000 | ||
24 | #define _APS_NEXT_SYMED_VALUE 110 | ||
25 | #endif | ||
26 | #endif | ||
diff --git a/Source/Source.vcxproj b/Source/Source.vcxproj index afd4fd3..38914a6 100644 --- a/Source/Source.vcxproj +++ b/Source/Source.vcxproj | |||
@@ -103,7 +103,7 @@ | |||
103 | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | 103 | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |
104 | <ClCompile> | 104 | <ClCompile> |
105 | <PrecompiledHeader>NotUsing</PrecompiledHeader> | 105 | <PrecompiledHeader>NotUsing</PrecompiledHeader> |
106 | <WarningLevel>Level3</WarningLevel> | 106 | <WarningLevel>Level2</WarningLevel> |
107 | <Optimization>Disabled</Optimization> | 107 | <Optimization>Disabled</Optimization> |
108 | <SDLCheck>true</SDLCheck> | 108 | <SDLCheck>true</SDLCheck> |
109 | <PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | 109 | <PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
@@ -142,7 +142,7 @@ | |||
142 | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | 142 | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |
143 | <ClCompile> | 143 | <ClCompile> |
144 | <PrecompiledHeader>NotUsing</PrecompiledHeader> | 144 | <PrecompiledHeader>NotUsing</PrecompiledHeader> |
145 | <WarningLevel>Level1</WarningLevel> | 145 | <WarningLevel>Level2</WarningLevel> |
146 | <Optimization>MaxSpeed</Optimization> | 146 | <Optimization>MaxSpeed</Optimization> |
147 | <FunctionLevelLinking>true</FunctionLevelLinking> | 147 | <FunctionLevelLinking>true</FunctionLevelLinking> |
148 | <IntrinsicFunctions>true</IntrinsicFunctions> | 148 | <IntrinsicFunctions>true</IntrinsicFunctions> |
@@ -167,7 +167,6 @@ | |||
167 | <ClInclude Include="Random.h" /> | 167 | <ClInclude Include="Random.h" /> |
168 | <ClInclude Include="Randomizer.h" /> | 168 | <ClInclude Include="Randomizer.h" /> |
169 | <ClInclude Include="RandomizerCore.h" /> | 169 | <ClInclude Include="RandomizerCore.h" /> |
170 | <ClInclude Include="Resource.h" /> | ||
171 | <ClInclude Include="Version.h" /> | 170 | <ClInclude Include="Version.h" /> |
172 | </ItemGroup> | 171 | </ItemGroup> |
173 | <ItemGroup> | 172 | <ItemGroup> |
diff --git a/Source/Source.vcxproj.filters b/Source/Source.vcxproj.filters index dbb50f9..2f8f60b 100644 --- a/Source/Source.vcxproj.filters +++ b/Source/Source.vcxproj.filters | |||
@@ -15,9 +15,6 @@ | |||
15 | </Filter> | 15 | </Filter> |
16 | </ItemGroup> | 16 | </ItemGroup> |
17 | <ItemGroup> | 17 | <ItemGroup> |
18 | <ClInclude Include="Resource.h"> | ||
19 | <Filter>Header Files</Filter> | ||
20 | </ClInclude> | ||
21 | <ClInclude Include="Memory.h"> | 18 | <ClInclude Include="Memory.h"> |
22 | <Filter>Header Files</Filter> | 19 | <Filter>Header Files</Filter> |
23 | </ClInclude> | 20 | </ClInclude> |
diff --git a/Source/Version.h b/Source/Version.h index ed79ee5..5aac53d 100644 --- a/Source/Version.h +++ b/Source/Version.h | |||
@@ -1,14 +1,14 @@ | |||
1 | #pragma once | 1 | #pragma once |
2 | 2 | ||
3 | #define TO_STRING2(s) L#s | ||
4 | #define TO_STRING(s) TO_STRING2(s) | ||
5 | |||
3 | #define MAJOR 3 | 6 | #define MAJOR 3 |
4 | #define MINOR 0 | 7 | #define MINOR 0 |
5 | #define PATCH 1 | 8 | #define PATCH 3 |
6 | |||
7 | #define VERSION MAJOR, MINOR, PATCH | ||
8 | 9 | ||
9 | #define TO_STRING2(s) L#s | ||
10 | #define TO_STRING(s) TO_STRING2(s) | ||
11 | #define VERSION_STR TO_STRING(MAJOR) L"." TO_STRING(MINOR) L"." TO_STRING(PATCH) | 10 | #define VERSION_STR TO_STRING(MAJOR) L"." TO_STRING(MINOR) L"." TO_STRING(PATCH) |
11 | #define VERSION MAJOR, MINOR, PATCH | ||
12 | 12 | ||
13 | #define PRODUCT_NAME L"Witness Randomizer" | 13 | #define PRODUCT_NAME L"Witness Randomizer" |
14 | #define WINDOW_CLASS L"WitnessRandomizer" | 14 | #define WINDOW_CLASS L"WitnessRandomizer" |
diff --git a/Source/Version.rc b/Source/Version.rc index fe44a47..9b90884 100644 --- a/Source/Version.rc +++ b/Source/Version.rc | |||
@@ -1,28 +1,6 @@ | |||
1 | #include "version.h" | 1 | #include "version.h" |
2 | #include "resource.h" | ||
3 | #include <SDKDDKVer.h> | ||
4 | #include "windows.h" | ||
5 | |||
6 | STRINGTABLE | ||
7 | BEGIN | ||
8 | IDC_SOURCE "SOURCE" | ||
9 | END | ||
10 | 2 | ||
11 | VS_VERSION_INFO VERSIONINFO | 3 | VS_VERSION_INFO VERSIONINFO |
12 | FILEVERSION VERSION | 4 | FILEVERSION VERSION |
13 | PRODUCTVERSION VERSION | ||
14 | BEGIN | 5 | BEGIN |
15 | BLOCK "StringFileInfo" | ||
16 | BEGIN | ||
17 | BLOCK "040904b0" | ||
18 | BEGIN | ||
19 | VALUE "FileDescription", "Randomizer for The Witness" | ||
20 | VALUE "FileVersion", VERSION_STR | ||
21 | VALUE "InternalName", "Source.exe" | ||
22 | VALUE "LegalCopyright", "Copyright (C) 2018" | ||
23 | VALUE "OriginalFilename", "Source.exe" | ||
24 | VALUE "ProductName", PRODUCT_NAME | ||
25 | VALUE "ProductVersion", VERSION_STR | ||
26 | END | ||
27 | END | ||
28 | END | 6 | END |