summary refs log tree commit diff stats
path: root/App
diff options
context:
space:
mode:
authorjbzdarkid <jbzdarkid@gmail.com>2019-11-04 08:43:31 -0800
committerjbzdarkid <jbzdarkid@gmail.com>2019-11-04 08:43:31 -0800
commit0cb49374a6d86100cd6f3bf838e79bdbac242a8e (patch)
treecab3a985cd5a7c8a448d3c0a67ff7588faed9c24 /App
parentedef920a2d7d753f93cd716052d8f2104bfdfa62 (diff)
downloadwitness-tutorializer-0cb49374a6d86100cd6f3bf838e79bdbac242a8e.tar.gz
witness-tutorializer-0cb49374a6d86100cd6f3bf838e79bdbac242a8e.tar.bz2
witness-tutorializer-0cb49374a6d86100cd6f3bf838e79bdbac242a8e.zip
Starting to clean up...
Diffstat (limited to 'App')
-rw-r--r--App/App.vcxproj10
-rw-r--r--App/Main.cpp247
2 files changed, 66 insertions, 191 deletions
diff --git a/App/App.vcxproj b/App/App.vcxproj index 9b10e92..698d364 100644 --- a/App/App.vcxproj +++ b/App/App.vcxproj
@@ -23,32 +23,32 @@
23 <ProjectGuid>{235D27F1-9907-489B-8D58-636A0C5CD079}</ProjectGuid> 23 <ProjectGuid>{235D27F1-9907-489B-8D58-636A0C5CD079}</ProjectGuid>
24 <Keyword>Win32Proj</Keyword> 24 <Keyword>Win32Proj</Keyword>
25 <RootNamespace>App</RootNamespace> 25 <RootNamespace>App</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>Application</ConfigurationType> 30 <ConfigurationType>Application</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>Application</ConfigurationType> 36 <ConfigurationType>Application</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>Application</ConfigurationType> 43 <ConfigurationType>Application</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>Application</ConfigurationType> 49 <ConfigurationType>Application</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>
diff --git a/App/Main.cpp b/App/Main.cpp index 82600bf..2484577 100644 --- a/App/Main.cpp +++ b/App/Main.cpp
@@ -1,15 +1,15 @@
1#include "windows.h" 1#include "Windows.h"
2#include <Richedit.h> 2#include "Richedit.h"
3#include "Version.h"
3 4
4#include <string> 5#include <cassert>
5#include <sstream> 6#include <iostream>
6 7
7#include "Version.h" 8#include "Memory.h"
8#include "Random.h" 9
9#include "Randomizer.h" 10#define EXE_NAME L"witness64_d3d11.exe"
10#include "Panel.h"
11 11
12#define IDC_RANDOMIZE 0x401 12#define PROC_ATTACH 0x401
13#define IDC_TOGGLESPEED 0x402 13#define IDC_TOGGLESPEED 0x402
14#define IDC_SPEEDRUNNER 0x403 14#define IDC_SPEEDRUNNER 0x403
15#define IDC_HARDMODE 0x404 15#define IDC_HARDMODE 0x404
@@ -21,102 +21,56 @@
21#define IDC_TOGGLELASERS 0x410 21#define IDC_TOGGLELASERS 0x410
22#define IDC_TOGGLESNIPES 0x411 22#define IDC_TOGGLESNIPES 0x411
23 23
24HWND hwndSeed, hwndRandomize; 24// Globals
25// int panel = 0x18AF; 25HWND g_hwnd;
26int panel = 0x33D4; 26HINSTANCE g_hInstance;
27std::shared_ptr<Panel> _panel; 27auto g_witnessProc = std::make_shared<Memory>();
28std::shared_ptr<Randomizer> randomizer = std::make_shared<Randomizer>();
29
30LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
31{
32 static bool seedIsRNG = false;
33 28
29LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
34 if (message == WM_DESTROY) { 30 if (message == WM_DESTROY) {
35 PostQuitMessage(0); 31 PostQuitMessage(0);
36 } else if (message == WM_COMMAND || message == WM_TIMER) { 32 } else if (message == WM_COMMAND) {
37 switch (HIWORD(wParam)) { 33 switch (LOWORD(wParam)) {
38 // Seed contents changed 34 case PROC_ATTACH:
39 case EN_CHANGE: 35 if (!g_witnessProc->Initialize(EXE_NAME)) {
40 seedIsRNG = false; 36 OutputDebugString(L"Failed to initialize, trying again in 5 seconds");
41 } 37 SetTimer(g_hwnd, PROC_ATTACH, 5000, NULL); // Re-attach in 10s
42 switch (LOWORD(wParam)) { 38 }
43 // Checkboxes 39 break;
44 case IDC_TOGGLESPEED: 40 case IDC_TOGGLELASERS:
45 CheckDlgButton(hwnd, IDC_TOGGLESPEED, !IsDlgButtonChecked(hwnd, IDC_TOGGLESPEED)); 41 OutputDebugString(L"Hello, world!");
46 break; 42 break;
47 case IDC_TOGGLELASERS: 43 default:
48 CheckDlgButton(hwnd, IDC_TOGGLELASERS, !IsDlgButtonChecked(hwnd, IDC_TOGGLELASERS)); 44 assert(false);
49 break; 45 break;
50 case IDC_TOGGLESNIPES: 46 }
51 CheckDlgButton(hwnd, IDC_TOGGLESNIPES, !IsDlgButtonChecked(hwnd, IDC_TOGGLESNIPES)); 47 }
52 break;
53
54 // Randomize button
55 case IDC_RANDOMIZE:
56 {
57 std::wstring text;
58 text.reserve(100);
59 GetWindowText(hwndSeed, &text[0], 100);
60 int seed = _wtoi(text.c_str());
61
62 // TODO: text needs to be resized!
63 if (seedIsRNG || wcslen(text.c_str()) == 0) {
64 seed = Random::RandInt(0, 100000);
65 seedIsRNG = true;
66 }
67
68 randomizer->ClearOffsets();
69 /* TODO:
70 if (!randomizer->GameIsRunning()) {
71 randomizer->StartGame(); // Try: CreateProcess(L"/path/to/TW.exe", ...);
72 }
73 */
74 if (randomizer->GameIsRandomized()) break;
75 Random::SetSeed(seed);
76
77 // Show seed and force redraw
78 std::wstring seedString = std::to_wstring(seed);
79 SetWindowText(hwndRandomize, L"Randomizing...");
80 SetWindowText(hwndSeed, seedString.c_str());
81 RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW);
82
83 // Randomize, then apply settings
84 randomizer->Randomize();
85 if (IsDlgButtonChecked(hwnd, IDC_TOGGLESPEED)) randomizer->AdjustSpeed();
86 if (IsDlgButtonChecked(hwnd, IDC_TOGGLELASERS)) randomizer->RandomizeLasers();
87 if (IsDlgButtonChecked(hwnd, IDC_TOGGLESNIPES)) randomizer->PreventSnipes();
88
89 // Cleanup, and set timer for "randomization done"
90 SetWindowText(hwndRandomize, L"Randomized!");
91 SetTimer(hwnd, IDT_RANDOMIZED, 10000, NULL);
92 break;
93 }
94
95 case IDT_RANDOMIZED:
96 SetWindowText(hwndRandomize, L"Randomize");
97 randomizer->GameIsRandomized(); // "Check" if the game is randomized to update the last known safe frame.
98 break;
99 case IDC_READ:
100 _panel = std::make_shared<Panel>(panel);
101 break;
102 case IDC_RANDOM:
103 _panel->Random();
104 break;
105 case IDC_WRITE:
106 _panel->Write(panel);
107 break;
108 case IDC_DUMP:
109 _panel->Serialize();
110 break;
111 }
112 }
113 return DefWindowProc(hwnd, message, wParam, lParam); 48 return DefWindowProc(hwnd, message, wParam, lParam);
114} 49}
115 50
116int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) 51void CreateLabel(int x, int y, int width, LPCWSTR text) {
117{ 52 CreateWindow(L"STATIC", text,
118 LoadLibrary(L"Msftedit.dll"); 53 WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT,
54 x, y, width, 16, g_hwnd, NULL, g_hInstance, NULL);
55}
56
57void CreateButton(int x, int y, int width, LPCWSTR text, int message) {
58#pragma warning(push)
59#pragma warning(disable: 4312)
60 CreateWindow(L"BUTTON", text,
61 WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
62 x, y, width, 26, g_hwnd, (HMENU)message, g_hInstance, NULL);
63#pragma warning(pop)
64}
65
66/*
67 hwndSeed = CreateWindow(MSFTEDIT_CLASS, L"",
68 WS_TABSTOP | WS_VISIBLE | WS_CHILD | WS_BORDER,
69 100, 10, 50, 26, hwnd, NULL, hInstance, NULL);
70*/
119 71
72int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) {
73 LoadLibrary(L"Msftedit.dll");
120 WNDCLASSW wndClass = { 74 WNDCLASSW wndClass = {
121 CS_HREDRAW | CS_VREDRAW, 75 CS_HREDRAW | CS_VREDRAW,
122 WndProc, 76 WndProc,
@@ -131,101 +85,22 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
131 }; 85 };
132 RegisterClassW(&wndClass); 86 RegisterClassW(&wndClass);
133 87
88 g_hInstance = hInstance;
89
134 RECT rect; 90 RECT rect;
135 GetClientRect(GetDesktopWindow(), &rect); 91 GetClientRect(GetDesktopWindow(), &rect);
136 HWND hwnd = CreateWindow(WINDOW_CLASS, PRODUCT_NAME, WS_OVERLAPPEDWINDOW, 92 g_hwnd = CreateWindow(WINDOW_CLASS, PRODUCT_NAME, WS_OVERLAPPEDWINDOW,
137 rect.right - 550, 200, 500, 500, nullptr, nullptr, hInstance, nullptr); 93 rect.right - 550, 200, 500, 500, nullptr, nullptr, hInstance, nullptr);
138 94
139 CreateWindow(L"STATIC", L"Version: " VERSION_STR, 95 CreateLabel(390, 15, 90, L"Version: " VERSION_STR);
140 WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, 96 CreateButton(10, 72, 100, L"Button text", IDC_TOGGLELASERS);
141 390, 15, 90, 16, hwnd, NULL, hInstance, NULL); 97 PostMessage(g_hwnd, WM_COMMAND, PROC_ATTACH, NULL);
142
143 CreateWindow(L"STATIC", L"Enter a seed:",
144 WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT,
145 10, 15, 90, 16, hwnd, NULL, hInstance, NULL);
146 hwndSeed = CreateWindow(MSFTEDIT_CLASS, L"",
147 WS_TABSTOP | WS_VISIBLE | WS_CHILD | WS_BORDER,
148 100, 10, 50, 26, hwnd, NULL, hInstance, NULL);
149 SendMessage(hwndSeed, EM_SETEVENTMASK, NULL, ENM_CHANGE); // Notify on text change
150
151 hwndRandomize = CreateWindow(L"BUTTON", L"Randomize",
152 WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
153 160, 10, 110, 26, hwnd, (HMENU)IDC_RANDOMIZE, hInstance, NULL);
154
155#if GLOBALS == 0x5B28C0
156 CreateWindow(L"BUTTON", L"READ",
157 WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
158 160, 100, 100, 26, hwnd, (HMENU)IDC_READ, hInstance, NULL);
159 CreateWindow(L"BUTTON", L"RANDOM",
160 WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
161 160, 130, 100, 26, hwnd, (HMENU)IDC_RANDOM, hInstance, NULL);
162 CreateWindow(L"BUTTON", L"WRITE",
163 WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
164 160, 160, 100, 26, hwnd, (HMENU)IDC_WRITE, hInstance, NULL);
165 CreateWindow(L"BUTTON", L"DUMP",
166 WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
167 160, 190, 100, 26, hwnd, (HMENU)IDC_DUMP, hInstance, NULL);
168#endif
169
170 CreateWindow(L"BUTTON", L"",
171 WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
172 10, 52, 12, 12, hwnd, (HMENU)IDC_TOGGLESPEED, hInstance, NULL);
173 CreateWindow(L"STATIC", L"Speed up various autoscrollers",
174 WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT,
175 27, 50, 210, 16, hwnd, NULL, hInstance, NULL);
176
177 CreateWindow(L"BUTTON", L"",
178 WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
179 10, 72, 12, 12, hwnd, (HMENU)IDC_TOGGLELASERS, hInstance, NULL);
180 CreateWindow(L"STATIC", L"Randomize laser activations",
181 WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT,
182 27, 70, 210, 16, hwnd, NULL, hInstance, NULL);
183
184 CreateWindow(L"BUTTON", L"",
185 WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
186 10, 92, 12, 12, hwnd, (HMENU)IDC_TOGGLESNIPES, hInstance, NULL);
187 CheckDlgButton(hwnd, IDC_TOGGLESNIPES, TRUE);
188 CreateWindow(L"STATIC", L"Prevent sniping certain puzzles",
189 WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT,
190 27, 90, 210, 16, hwnd, NULL, hInstance, NULL);
191
192 /*
193 CreateWindow(L"BUTTON", L"",
194 WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
195 10, 52, 12, 12, hwnd, (HMENU)IDC_SPEEDRUNNER, hInstance, NULL);
196 CreateWindow(L"STATIC", L"Allow hard-to-identify panels to be shuffled",
197 WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT,
198 27, 50, 205, 16, hwnd, NULL, hInstance, NULL);
199
200 CreateWindow(L"BUTTON", L"",
201 WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
202 10, 52, 12, 12, hwnd, (HMENU)IDC_HARDMODE, hInstance, NULL);
203 CreateWindow(L"STATIC", L"Place harder puzzles in annoying spots",
204 WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT,
205 27, 50, 205, 16, hwnd, NULL, hInstance, NULL);
206
207 CreateWindow(L"BUTTON", L"",
208 WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
209 10, 52, 12, 12, hwnd, (HMENU)IDC_NORANDOMIZE, hInstance, NULL);
210 CreateWindow(L"STATIC", L"Do not randomize any puzzles",
211 WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT,
212 27, 50, 205, 16, hwnd, NULL, hInstance, NULL);
213
214 CreateWindow(L"BUTTON", L"",
215 WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
216 10, 52, 12, 12, hwnd, (HMENU)IDC_CASUAL, hInstance, NULL);
217 CreateWindow(L"STATIC", L"Don't randomize context-based puzzles",
218 WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT,
219 27, 50, 205, 16, hwnd, NULL, hInstance, NULL);
220
221*/
222 98
223 ShowWindow(hwnd, nCmdShow); 99 ShowWindow(g_hwnd, nCmdShow);
224 UpdateWindow(hwnd); 100 UpdateWindow(g_hwnd);
225 101
226 MSG msg; 102 MSG msg;
227 while (!GetMessage(&msg, nullptr, 0, 0) == 0) 103 while (GetMessage(&msg, nullptr, 0, 0) == TRUE) {
228 {
229 TranslateMessage(&msg); 104 TranslateMessage(&msg);
230 DispatchMessage(&msg); 105 DispatchMessage(&msg);
231 } 106 }