summary refs log tree commit diff stats
path: root/App/Main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'App/Main.cpp')
-rw-r--r--App/Main.cpp53
1 files changed, 37 insertions, 16 deletions
diff --git a/App/Main.cpp b/App/Main.cpp index 48cb93d..ab3e88a 100644 --- a/App/Main.cpp +++ b/App/Main.cpp
@@ -16,19 +16,26 @@
16#define IDC_RANDOM 0x406 16#define IDC_RANDOM 0x406
17#define IDC_WRITE 0x407 17#define IDC_WRITE 0x407
18#define IDC_DUMP 0x408 18#define IDC_DUMP 0x408
19#define IDT_RANDOMIZED 0x409
19 20
20HWND hwndSeed, hwndRandomize; 21HWND hwndSeed, hwndRandomize;
21int panel = 0x18AF; 22int panel = 0x18AF;
22// int panel = 0x33D4; 23// int panel = 0x33D4;
23std::shared_ptr<Panel> _panel; 24std::shared_ptr<Panel> _panel;
25std::shared_ptr<Randomizer> randomizer = std::make_shared<Randomizer>();
24 26
25LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 27LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
26{ 28{
27 static bool wasSeedRandomlyGenerated; 29 static bool seedIsRNG = false;
28 30
29 if (message == WM_DESTROY) { 31 if (message == WM_DESTROY) {
30 PostQuitMessage(0); 32 PostQuitMessage(0);
31 } else if (message == WM_COMMAND) { 33 } else if (message == WM_COMMAND || message == WM_TIMER) {
34 switch (HIWORD(wParam)) {
35 // Seed contents changed
36 case EN_CHANGE:
37 seedIsRNG = false;
38 }
32 switch (LOWORD(wParam)) { 39 switch (LOWORD(wParam)) {
33 // Speed checkbox 40 // Speed checkbox
34 case IDC_TOGGLESPEED: 41 case IDC_TOGGLESPEED:
@@ -42,29 +49,41 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
42 // Randomize button 49 // Randomize button
43 case IDC_RANDOMIZE: 50 case IDC_RANDOMIZE:
44 { 51 {
45 std::wstring text(100, '\0'); 52 std::wstring text;
53 text.reserve(100);
46 GetWindowText(hwndSeed, &text[0], 100); 54 GetWindowText(hwndSeed, &text[0], 100);
47 int seed = 0; 55 int seed = _wtoi(text.c_str());
48 if (wasSeedRandomlyGenerated || wcslen(text.c_str()) == 0) { 56
57 if (seedIsRNG || text.empty()) {
49 seed = Random::RandInt(0, 100000); 58 seed = Random::RandInt(0, 100000);
50 wasSeedRandomlyGenerated = true; 59 seedIsRNG = true;
51 } else {
52 seed = _wtoi(text.c_str());
53 wasSeedRandomlyGenerated = false;
54 } 60 }
55 61
56 Randomizer randomizer; 62 randomizer->ClearOffsets();
57 short metadata = randomizer.Randomize(seed); 63 /* TODO:
58 if (metadata & 0x1) break; // Was already randomized 64 if (!randomizer->GameIsRunning()) {
59 65 randomizer->StartGame(); // Try: CreateProcess(L"/path/to/TW.exe", ...);
66 }
67 */
68 if (randomizer->GameIsRandomized()) break;
69 Random::SetSeed(seed);
60 std::wstring seedString = std::to_wstring(seed); 70 std::wstring seedString = std::to_wstring(seed);
71 SetWindowText(hwndRandomize, L"Randomizing...");
61 SetWindowText(hwndSeed, seedString.c_str()); 72 SetWindowText(hwndSeed, seedString.c_str());
62 if (IsDlgButtonChecked(hwnd, IDC_TOGGLESPEED)) { 73 RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW);
63 randomizer.AdjustSpeed(); 74
75 randomizer->Randomize();
76 if (IsDlgButtonChecked(hwnd, IDC_TOGGLESPEED)) {
77 randomizer->AdjustSpeed();
64 } 78 }
65 SetWindowText(hwndRandomize, L"Randomized!"); 79 SetWindowText(hwndRandomize, L"Randomized!");
80 SetTimer(hwnd, IDT_RANDOMIZED, 10000, NULL);
66 break; 81 break;
67 } 82 }
83
84 case IDT_RANDOMIZED:
85 SetWindowText(hwndRandomize, L"Randomize");
86 break;
68 case IDC_READ: 87 case IDC_READ:
69 _panel = std::make_shared<Panel>(panel); 88 _panel = std::make_shared<Panel>(panel);
70 break; 89 break;
@@ -115,9 +134,11 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
115 hwndSeed = CreateWindow(MSFTEDIT_CLASS, L"", 134 hwndSeed = CreateWindow(MSFTEDIT_CLASS, L"",
116 WS_TABSTOP | WS_VISIBLE | WS_CHILD | WS_BORDER, 135 WS_TABSTOP | WS_VISIBLE | WS_CHILD | WS_BORDER,
117 100, 10, 50, 26, hwnd, NULL, hInstance, NULL); 136 100, 10, 50, 26, hwnd, NULL, hInstance, NULL);
137 SendMessage(hwndSeed, EM_SETEVENTMASK, NULL, ENM_CHANGE); // Notify on text change
138
118 hwndRandomize = CreateWindow(L"BUTTON", L"Randomize", 139 hwndRandomize = CreateWindow(L"BUTTON", L"Randomize",
119 WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 140 WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
120 160, 10, 100, 26, hwnd, (HMENU)IDC_RANDOMIZE, hInstance, NULL); 141 160, 10, 110, 26, hwnd, (HMENU)IDC_RANDOMIZE, hInstance, NULL);
121 142
122#if GLOBALS == 0x5B28C0 143#if GLOBALS == 0x5B28C0
123 CreateWindow(L"BUTTON", L"READ", 144 CreateWindow(L"BUTTON", L"READ",