1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
#include "windows.h"
#include <Richedit.h>
#include <string>
#include <sstream>
#include "Version.h"
#include "Random.h"
#include "Randomizer.h"
#include "Panel.h"
#define IDC_RANDOMIZE 0x401
#define IDC_TOGGLESPEED 0x402
#define IDC_SPEEDRUNNER 0x403
#define IDC_HARDMODE 0x404
#define IDC_READ 0x405
#define IDC_RANDOM 0x406
#define IDC_WRITE 0x407
#define IDC_DUMP 0x408
#define IDT_RANDOMIZED 0x409
HWND hwndSeed, hwndRandomize, hwndDebug;
// int panel = 0x18AF;
int panel = 0x33D4;
std::shared_ptr<Panel> _panel;
std::shared_ptr<Randomizer> randomizer = std::make_shared<Randomizer>();
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static bool seedIsRNG = false;
if (message == WM_DESTROY) {
PostQuitMessage(0);
} else if (message == WM_COMMAND || message == WM_TIMER) {
switch (HIWORD(wParam)) {
// Seed contents changed
case EN_CHANGE:
seedIsRNG = false;
}
switch (LOWORD(wParam)) {
// Speed checkbox
case IDC_TOGGLESPEED:
if (IsDlgButtonChecked(hwnd, IDC_TOGGLESPEED)) {
CheckDlgButton(hwnd, IDC_TOGGLESPEED, BST_UNCHECKED);
} else {
CheckDlgButton(hwnd, IDC_TOGGLESPEED, BST_CHECKED);
}
break;
// Randomize button
case IDC_RANDOMIZE:
{
std::wstring text;
text.reserve(100);
GetWindowText(hwndSeed, &text[0], 100);
int seed = _wtoi(text.c_str());
// TODO: text needs to be resized!
if (seedIsRNG || wcslen(text.c_str()) == 0) {
seed = Random::RandInt(0, 100000);
seedIsRNG = true;
}
randomizer->ClearOffsets();
/* TODO:
if (!randomizer->GameIsRunning()) {
randomizer->StartGame(); // Try: CreateProcess(L"/path/to/TW.exe", ...);
}
*/
if (randomizer->GameIsRandomized()) break;
Random::SetSeed(seed);
std::wstringstream debug;
std::wstring seedString = std::to_wstring(seed);
SetWindowText(hwndRandomize, L"Randomizing...");
SetWindowText(hwndSeed, seedString.c_str());
RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW);
randomizer->Randomize();
debug << Random::RandInt(0, 1000) << " ";
debug << Random::RandInt(0, 1000) << "\n";
debug << Random::RandInt(0, 1000) << " ";
debug << Random::RandInt(0, 1000);
SetWindowText(hwndDebug, debug.str().c_str());
if (IsDlgButtonChecked(hwnd, IDC_TOGGLESPEED)) {
randomizer->AdjustSpeed();
}
SetWindowText(hwndRandomize, L"Randomized!");
SetTimer(hwnd, IDT_RANDOMIZED, 10000, NULL);
break;
}
case IDT_RANDOMIZED:
SetWindowText(hwndRandomize, L"Randomize");
break;
case IDC_READ:
_panel = std::make_shared<Panel>(panel);
break;
case IDC_RANDOM:
_panel->Random();
break;
case IDC_WRITE:
_panel->Write(panel);
break;
case IDC_DUMP:
_panel->Serialize();
break;
}
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
{
LoadLibrary(L"Msftedit.dll");
WNDCLASSW wndClass = {
CS_HREDRAW | CS_VREDRAW,
WndProc,
0,
0,
hInstance,
NULL,
LoadCursor(nullptr, IDC_ARROW),
(HBRUSH)(COLOR_WINDOW+1),
WINDOW_CLASS,
WINDOW_CLASS,
};
RegisterClassW(&wndClass);
RECT rect;
GetClientRect(GetDesktopWindow(), &rect);
HWND hwnd = CreateWindow(WINDOW_CLASS, PRODUCT_NAME, WS_OVERLAPPEDWINDOW,
rect.right - 550, 200, 500, 500, nullptr, nullptr, hInstance, nullptr);
CreateWindow(L"STATIC", L"Version: " VERSION_STR,
WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT,
390, 15, 90, 16, hwnd, NULL, hInstance, NULL);
CreateWindow(L"STATIC", L"Enter a seed:",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT,
10, 15, 90, 16, hwnd, NULL, hInstance, NULL);
hwndSeed = CreateWindow(MSFTEDIT_CLASS, L"",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | WS_BORDER,
100, 10, 50, 26, hwnd, NULL, hInstance, NULL);
SendMessage(hwndSeed, EM_SETEVENTMASK, NULL, ENM_CHANGE); // Notify on text change
hwndRandomize = CreateWindow(L"BUTTON", L"Randomize",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
160, 10, 110, 26, hwnd, (HMENU)IDC_RANDOMIZE, hInstance, NULL);
#if GLOBALS == 0x5B28C0
CreateWindow(L"BUTTON", L"READ",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
160, 100, 100, 26, hwnd, (HMENU)IDC_READ, hInstance, NULL);
CreateWindow(L"BUTTON", L"RANDOM",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
160, 130, 100, 26, hwnd, (HMENU)IDC_RANDOM, hInstance, NULL);
CreateWindow(L"BUTTON", L"WRITE",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
160, 160, 100, 26, hwnd, (HMENU)IDC_WRITE, hInstance, NULL);
CreateWindow(L"BUTTON", L"DUMP",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
160, 190, 100, 26, hwnd, (HMENU)IDC_DUMP, hInstance, NULL);
#endif
CreateWindow(L"BUTTON", L"",
WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
10, 52, 12, 12, hwnd, (HMENU)IDC_TOGGLESPEED, hInstance, NULL);
CreateWindow(L"STATIC", L"Speed up various autoscrollers",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT,
27, 50, 205, 16, hwnd, NULL, hInstance, NULL);
hwndDebug = CreateWindow(L"STATIC", L"",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT,
200, 200, 100, 100, hwnd, NULL, hInstance, NULL);
/*
CreateWindow(L"BUTTON", L"",
WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
10, 52, 12, 12, hwnd, (HMENU)IDC_SPEEDRUNNER, hInstance, NULL);
CreateWindow(L"STATIC", L"Allow hard-to-identify panels to be shuffled",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT,
27, 50, 205, 16, hwnd, NULL, hInstance, NULL);
CreateWindow(L"BUTTON", L"",
WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
10, 52, 12, 12, hwnd, (HMENU)IDC_HARDMODE, hInstance, NULL);
CreateWindow(L"STATIC", L"Place harder puzzles in annoying spots",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT,
27, 50, 205, 16, hwnd, NULL, hInstance, NULL);
CreateWindow(L"BUTTON", L"",
WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
10, 52, 12, 12, hwnd, (HMENU)IDC_NORANDOMIZE, hInstance, NULL);
CreateWindow(L"STATIC", L"Do not randomize any puzzles",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT,
27, 50, 205, 16, hwnd, NULL, hInstance, NULL);
CreateWindow(L"BUTTON", L"",
WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
10, 52, 12, 12, hwnd, (HMENU)IDC_CASUAL, hInstance, NULL);
CreateWindow(L"STATIC", L"Don't randomize context-based puzzles",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT,
27, 50, 205, 16, hwnd, NULL, hInstance, NULL);
CreateWindow(L"BUTTON", L"",
WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
10, 52, 12, 12, hwnd, (HMENU)IDC_BANSNIPES, hInstance, NULL);
CreateWindow(L"STATIC", L"Prevent sniping certain puzzles",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT,
27, 50, 205, 16, hwnd, NULL, hInstance, NULL);
*/
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
MSG msg;
while (!GetMessage(&msg, nullptr, 0, 0) == 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
|