about summary refs log tree commit diff stats
path: root/App
diff options
context:
space:
mode:
Diffstat (limited to 'App')
-rw-r--r--App/Main.cpp87
1 files changed, 61 insertions, 26 deletions
diff --git a/App/Main.cpp b/App/Main.cpp index 2484577..b018892 100644 --- a/App/Main.cpp +++ b/App/Main.cpp
@@ -4,70 +4,103 @@
4 4
5#include <cassert> 5#include <cassert>
6#include <iostream> 6#include <iostream>
7#include <string>
8#include <thread>
7 9
8#include "Memory.h" 10#include "Memory.h"
11class Randomizer {
12public:
13 Randomizer(const std::shared_ptr<Memory>&) {}
14 void Randomize() {
15 std::this_thread::sleep_for(std::chrono::milliseconds(1000));
16 }
17};
9 18
10#define EXE_NAME L"witness64_d3d11.exe" 19#define EXE_NAME L"witness64_d3d11.exe"
11
12#define PROC_ATTACH 0x401 20#define PROC_ATTACH 0x401
13#define IDC_TOGGLESPEED 0x402 21#define RANDOMIZE_READY 0x402
14#define IDC_SPEEDRUNNER 0x403 22#define RANDOMIZING 0403
15#define IDC_HARDMODE 0x404 23#define RANDOMIZE_DONE 0x404
16#define IDC_READ 0x405 24#define CHECK_NEWGAME 0x405
17#define IDC_RANDOM 0x406
18#define IDC_WRITE 0x407
19#define IDC_DUMP 0x408
20#define IDT_RANDOMIZED 0x409
21#define IDC_TOGGLELASERS 0x410
22#define IDC_TOGGLESNIPES 0x411
23 25
24// Globals 26// Globals
25HWND g_hwnd; 27HWND g_hwnd;
28HWND g_seed;
29HWND g_randomizerStatus;
26HINSTANCE g_hInstance; 30HINSTANCE g_hInstance;
27auto g_witnessProc = std::make_shared<Memory>(); 31auto g_witnessProc = std::make_shared<Memory>();
32std::shared_ptr<Randomizer> g_randomizer;
33
34// Notifications I need:
35// Game shutdown
36// Load game?
28 37
29LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { 38LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
30 if (message == WM_DESTROY) { 39 if (message == WM_DESTROY) {
31 PostQuitMessage(0); 40 PostQuitMessage(0);
32 } else if (message == WM_COMMAND) { 41 } else if (message == WM_COMMAND || message == WM_TIMER) {
33 switch (LOWORD(wParam)) { 42 switch (LOWORD(wParam)) {
34 case PROC_ATTACH: 43 case PROC_ATTACH:
35 if (!g_witnessProc->Initialize(EXE_NAME)) { 44 if (!g_witnessProc->Initialize(EXE_NAME)) {
36 OutputDebugString(L"Failed to initialize, trying again in 5 seconds"); 45 SetTimer(g_hwnd, PROC_ATTACH, 1000, NULL); // Retry in 1s
37 SetTimer(g_hwnd, PROC_ATTACH, 5000, NULL); // Re-attach in 10s 46 } else {
47 g_randomizer = std::make_shared<Randomizer>(g_witnessProc);
48 PostMessage(g_hwnd, WM_COMMAND, RANDOMIZE_READY, NULL);
49 SetTimer(g_hwnd, CHECK_NEWGAME, 1000, NULL); // Start checking for new game
50 }
51 break;
52 case CHECK_NEWGAME:
53 if (g_witnessProc) {
54 // It shouldn't be possible to pause earlier than this, so subsequent checks will fail.
55 if (g_witnessProc->GetCurrentFrame() < 80) { // New game
56 SetWindowText(g_seed, L"");
57 PostMessage(g_hwnd, WM_COMMAND, RANDOMIZE_READY, NULL);
58 }
59 SetTimer(g_hwnd, CHECK_NEWGAME, 1000, NULL); // Continue checking for new game
38 } 60 }
39 break; 61 break;
40 case IDC_TOGGLELASERS: 62 case RANDOMIZE_READY:
41 OutputDebugString(L"Hello, world!"); 63 SetWindowText(g_randomizerStatus, L"Randomize");
64 EnableWindow(g_randomizerStatus, TRUE);
65 break;
66 case RANDOMIZING:
67 if (!g_randomizer) break;
68 SetWindowText(g_randomizerStatus, L"Randomizing...");
69 std::thread([]{
70 g_randomizer->Randomize();
71 PostMessage(g_hwnd, WM_COMMAND, RANDOMIZE_DONE, NULL);
72 }).detach();
73 break;
74 case RANDOMIZE_DONE:
75 SetWindowText(g_randomizerStatus, L"Randomized!");
42 break; 76 break;
43 default: 77 default:
44 assert(false);
45 break; 78 break;
46 } 79 }
47 } 80 }
48 return DefWindowProc(hwnd, message, wParam, lParam); 81 return DefWindowProc(hwnd, message, wParam, lParam);
49} 82}
50 83
51void CreateLabel(int x, int y, int width, LPCWSTR text) { 84HWND CreateLabel(int x, int y, int width, LPCWSTR text) {
52 CreateWindow(L"STATIC", text, 85 return CreateWindow(L"STATIC", text,
53 WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, 86 WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT,
54 x, y, width, 16, g_hwnd, NULL, g_hInstance, NULL); 87 x, y, width, 16, g_hwnd, NULL, g_hInstance, NULL);
55} 88}
56 89
57void CreateButton(int x, int y, int width, LPCWSTR text, int message) { 90HWND CreateButton(int x, int y, int width, LPCWSTR text, int message) {
58#pragma warning(push) 91#pragma warning(push)
59#pragma warning(disable: 4312) 92#pragma warning(disable: 4312)
60 CreateWindow(L"BUTTON", text, 93 return CreateWindow(L"BUTTON", text,
61 WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 94 WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
62 x, y, width, 26, g_hwnd, (HMENU)message, g_hInstance, NULL); 95 x, y, width, 26, g_hwnd, (HMENU)message, g_hInstance, NULL);
63#pragma warning(pop) 96#pragma warning(pop)
64} 97}
65 98
66/* 99HWND CreateText(int x, int y, int width, LPCWSTR defaultText = L"") {
67 hwndSeed = CreateWindow(MSFTEDIT_CLASS, L"", 100 return CreateWindow(MSFTEDIT_CLASS, L"",
68 WS_TABSTOP | WS_VISIBLE | WS_CHILD | WS_BORDER, 101 WS_TABSTOP | WS_VISIBLE | WS_CHILD | WS_BORDER,
69 100, 10, 50, 26, hwnd, NULL, hInstance, NULL); 102 x, y, width, 26, g_hwnd, NULL, g_hInstance, NULL);
70*/ 103}
71 104
72int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { 105int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) {
73 LoadLibrary(L"Msftedit.dll"); 106 LoadLibrary(L"Msftedit.dll");
@@ -93,7 +126,9 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance
93 rect.right - 550, 200, 500, 500, nullptr, nullptr, hInstance, nullptr); 126 rect.right - 550, 200, 500, 500, nullptr, nullptr, hInstance, nullptr);
94 127
95 CreateLabel(390, 15, 90, L"Version: " VERSION_STR); 128 CreateLabel(390, 15, 90, L"Version: " VERSION_STR);
96 CreateButton(10, 72, 100, L"Button text", IDC_TOGGLELASERS); 129 g_seed = CreateText(10, 10, 100);
130 g_randomizerStatus = CreateButton(120, 10, 100, L"Randomize", RANDOMIZING);
131 EnableWindow(g_randomizerStatus, FALSE);
97 PostMessage(g_hwnd, WM_COMMAND, PROC_ATTACH, NULL); 132 PostMessage(g_hwnd, WM_COMMAND, PROC_ATTACH, NULL);
98 133
99 ShowWindow(g_hwnd, nCmdShow); 134 ShowWindow(g_hwnd, nCmdShow);