diff options
Diffstat (limited to 'App/Main.cpp')
-rw-r--r-- | App/Main.cpp | 93 |
1 files changed, 52 insertions, 41 deletions
diff --git a/App/Main.cpp b/App/Main.cpp index 6946168..39dd517 100644 --- a/App/Main.cpp +++ b/App/Main.cpp | |||
@@ -40,11 +40,20 @@ HWND g_randomizerStatus; | |||
40 | HINSTANCE g_hInstance; | 40 | HINSTANCE g_hInstance; |
41 | auto g_witnessProc = std::make_shared<Memory>(L"witness64_d3d11.exe"); | 41 | auto g_witnessProc = std::make_shared<Memory>(L"witness64_d3d11.exe"); |
42 | std::shared_ptr<Randomizer> g_randomizer; | 42 | std::shared_ptr<Randomizer> g_randomizer; |
43 | void SetRandomSeed(); | ||
43 | 44 | ||
44 | LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { | 45 | LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { |
45 | if (message == WM_DESTROY) { | 46 | if (message == WM_DESTROY) { |
46 | PostQuitMessage(0); | 47 | PostQuitMessage(0); |
47 | } else if (message == WM_COMMAND || message == WM_TIMER) { | 48 | } else if (message == WM_NOTIFY) { |
49 | MSGFILTER* m = (MSGFILTER *)lParam; | ||
50 | if (m->msg == WM_KEYDOWN && m->wParam == VK_RETURN) { | ||
51 | if (IsWindowEnabled(g_randomizerStatus) == TRUE) { | ||
52 | PostMessage(g_hwnd, WM_COMMAND, RANDOMIZING, NULL); | ||
53 | return 1; // Non-zero to indicate that message was handled | ||
54 | } | ||
55 | } | ||
56 | } else if (message == WM_COMMAND || message == WM_TIMER || message == WM_NOTIFY) { | ||
48 | switch (LOWORD(wParam)) { | 57 | switch (LOWORD(wParam)) { |
49 | case HEARTBEAT: | 58 | case HEARTBEAT: |
50 | switch ((ProcStatus)lParam) { | 59 | switch ((ProcStatus)lParam) { |
@@ -76,42 +85,27 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) | |||
76 | } | 85 | } |
77 | break; | 86 | break; |
78 | case RANDOMIZING: | 87 | case RANDOMIZING: |
79 | if (!g_randomizer) { | 88 | if (!g_randomizer) break; // E.g. an enter press at the wrong time |
80 | assert(false); | ||
81 | break; | ||
82 | } | ||
83 | EnableWindow(g_randomizerStatus, FALSE); | 89 | EnableWindow(g_randomizerStatus, FALSE); |
84 | 90 | ||
85 | { | 91 | SetRandomSeed(); |
86 | int seed = 0; | 92 | std::thread([]{ |
87 | std::wstring text(128, L'\0'); | 93 | if (IsDlgButtonChecked(g_hwnd, DISABLE_SNIPES)) { |
88 | int size = GetWindowText(g_seed, text.data(), static_cast<int>(text.size())); | 94 | g_randomizer->PreventSnipes(); |
89 | if (size > 0) { // Set seed | ||
90 | seed = _wtoi(text.c_str()); | ||
91 | } else { // Random seed | ||
92 | seed = Random::RandInt(0, 999999); | ||
93 | SetWindowText(g_seed, std::to_wstring(seed).c_str()); | ||
94 | RedrawWindow(g_seed, NULL, NULL, RDW_UPDATENOW); | ||
95 | } | 95 | } |
96 | Random::SetSeed(seed); | 96 | if (IsDlgButtonChecked(g_hwnd, SPEED_UP_AUTOSCROLLERS)) { |
97 | std::thread([]{ | 97 | g_randomizer->AdjustSpeed(); |
98 | if (IsDlgButtonChecked(g_hwnd, DISABLE_SNIPES)) { | 98 | } |
99 | g_randomizer->PreventSnipes(); | 99 | if (IsDlgButtonChecked(g_hwnd, CHALLENGE_ONLY)) { |
100 | } | 100 | SetWindowText(g_randomizerStatus, L"Randomizing Challenge..."); |
101 | if (IsDlgButtonChecked(g_hwnd, SPEED_UP_AUTOSCROLLERS)) { | 101 | g_randomizer->RandomizeChallenge(); |
102 | g_randomizer->AdjustSpeed(); | 102 | PostMessage(g_hwnd, WM_COMMAND, RANDOMIZE_CHALLENGE_DONE, NULL); |
103 | } | 103 | } else { |
104 | if (IsDlgButtonChecked(g_hwnd, CHALLENGE_ONLY)) { | 104 | SetWindowText(g_randomizerStatus, L"Randomizing..."); |
105 | SetWindowText(g_randomizerStatus, L"Randomizing Challenge..."); | 105 | g_randomizer->Randomize(); |
106 | g_randomizer->RandomizeChallenge(); | 106 | PostMessage(g_hwnd, WM_COMMAND, RANDOMIZE_DONE, NULL); |
107 | PostMessage(g_hwnd, WM_COMMAND, RANDOMIZE_CHALLENGE_DONE, NULL); | 107 | } |
108 | } else { | 108 | }).detach(); |
109 | SetWindowText(g_randomizerStatus, L"Randomizing..."); | ||
110 | g_randomizer->Randomize(); | ||
111 | PostMessage(g_hwnd, WM_COMMAND, RANDOMIZE_DONE, NULL); | ||
112 | } | ||
113 | }).detach(); | ||
114 | } | ||
115 | break; | 109 | break; |
116 | case RANDOMIZE_DONE: | 110 | case RANDOMIZE_DONE: |
117 | EnableWindow(g_randomizerStatus, FALSE); | 111 | EnableWindow(g_randomizerStatus, FALSE); |
@@ -120,6 +114,11 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) | |||
120 | case RANDOMIZE_CHALLENGE_DONE: | 114 | case RANDOMIZE_CHALLENGE_DONE: |
121 | EnableWindow(g_randomizerStatus, FALSE); | 115 | EnableWindow(g_randomizerStatus, FALSE); |
122 | SetWindowText(g_randomizerStatus, L"Randomized Challenge!"); | 116 | SetWindowText(g_randomizerStatus, L"Randomized Challenge!"); |
117 | std::thread([]{ | ||
118 | // Allow re-randomization for challenge -- it doesn't break the rest of the game. | ||
119 | std::this_thread::sleep_for(std::chrono::seconds(10)); | ||
120 | PostMessage(g_hwnd, WM_COMMAND, RANDOMIZE_READY, NULL); | ||
121 | }).detach(); | ||
123 | break; | 122 | break; |
124 | case CHALLENGE_ONLY: | 123 | case CHALLENGE_ONLY: |
125 | CheckDlgButton(hwnd, CHALLENGE_ONLY, !IsDlgButtonChecked(hwnd, CHALLENGE_ONLY)); | 124 | CheckDlgButton(hwnd, CHALLENGE_ONLY, !IsDlgButtonChecked(hwnd, CHALLENGE_ONLY)); |
@@ -139,9 +138,6 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) | |||
139 | case TMP2: | 138 | case TMP2: |
140 | if(g_panel) g_panel->Write(panel); | 139 | if(g_panel) g_panel->Write(panel); |
141 | break; | 140 | break; |
142 | case TMP3: | ||
143 | if(g_panel) g_panel->Random(); | ||
144 | break; | ||
145 | case TMP4: | 141 | case TMP4: |
146 | if(g_panel) g_panel->Serialize(); | 142 | if(g_panel) g_panel->Serialize(); |
147 | break; | 143 | break; |
@@ -150,6 +146,20 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) | |||
150 | return DefWindowProc(hwnd, message, wParam, lParam); | 146 | return DefWindowProc(hwnd, message, wParam, lParam); |
151 | } | 147 | } |
152 | 148 | ||
149 | void SetRandomSeed() { | ||
150 | std::wstring text(128, L'\0'); | ||
151 | int length = GetWindowText(g_seed, text.data(), static_cast<int>(text.size())); | ||
152 | if (length > 0) { // Set seed | ||
153 | text.resize(length); | ||
154 | Random::SetSeed(_wtoi(text.c_str())); | ||
155 | } else { // Random seed | ||
156 | int seed = Random::RandInt(0, 999999); | ||
157 | SetWindowText(g_seed, std::to_wstring(seed).c_str()); | ||
158 | RedrawWindow(g_seed, NULL, NULL, RDW_UPDATENOW); | ||
159 | Random::SetSeed(seed); | ||
160 | } | ||
161 | } | ||
162 | |||
153 | HWND CreateLabel(int x, int y, int width, LPCWSTR text) { | 163 | HWND CreateLabel(int x, int y, int width, LPCWSTR text) { |
154 | return CreateWindow(L"STATIC", text, | 164 | return CreateWindow(L"STATIC", text, |
155 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, | 165 | WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, |
@@ -202,6 +212,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance | |||
202 | 212 | ||
203 | CreateLabel(390, 15, 90, L"Version: " VERSION_STR); | 213 | CreateLabel(390, 15, 90, L"Version: " VERSION_STR); |
204 | g_seed = CreateText(10, 10, 100); | 214 | g_seed = CreateText(10, 10, 100); |
215 | PostMessage(g_seed, EM_SETEVENTMASK, 0, ENM_KEYEVENTS); | ||
205 | g_randomizerStatus = CreateButton(120, 10, 180, L"Randomize", RANDOMIZING); | 216 | g_randomizerStatus = CreateButton(120, 10, 180, L"Randomize", RANDOMIZING); |
206 | EnableWindow(g_randomizerStatus, FALSE); | 217 | EnableWindow(g_randomizerStatus, FALSE); |
207 | CreateCheckbox(10, 300, CHALLENGE_ONLY); | 218 | CreateCheckbox(10, 300, CHALLENGE_ONLY); |
@@ -212,10 +223,10 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance | |||
212 | CreateCheckbox(10, 340, SPEED_UP_AUTOSCROLLERS); | 223 | CreateCheckbox(10, 340, SPEED_UP_AUTOSCROLLERS); |
213 | CreateLabel(30, 340, 205, L"Speed up various autoscrollers"); | 224 | CreateLabel(30, 340, 205, L"Speed up various autoscrollers"); |
214 | 225 | ||
215 | CreateButton(200, 100, 100, L"Read", TMP1); | 226 | // CreateButton(200, 100, 100, L"Read", TMP1); |
216 | CreateButton(200, 130, 100, L"Write", TMP2); | 227 | // CreateButton(200, 130, 100, L"Write", TMP2); |
217 | CreateButton(200, 160, 100, L"Random", TMP3); | 228 | // CreateButton(200, 160, 100, L"Random", TMP3); |
218 | CreateButton(200, 190, 100, L"Dump", TMP4); | 229 | // CreateButton(200, 190, 100, L"Dump", TMP4); |
219 | 230 | ||
220 | g_witnessProc->StartHeartbeat(g_hwnd); | 231 | g_witnessProc->StartHeartbeat(g_hwnd); |
221 | 232 | ||