From 0cb49374a6d86100cd6f3bf838e79bdbac242a8e Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Mon, 4 Nov 2019 08:43:31 -0800 Subject: Starting to clean up... --- App/App.vcxproj | 10 +-- App/Main.cpp | 247 ++++++++++++++------------------------------------------ 2 files changed, 66 insertions(+), 191 deletions(-) (limited to 'App') 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 @@ {235D27F1-9907-489B-8D58-636A0C5CD079} Win32Proj App - 10.0.17134.0 + 10.0 Application true - v141 + v142 Unicode Application false - v141 + v142 true Unicode Application true - v141 + v142 Unicode Application false - v141 + v142 true Unicode 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 @@ -#include "windows.h" -#include +#include "Windows.h" +#include "Richedit.h" +#include "Version.h" -#include -#include +#include +#include -#include "Version.h" -#include "Random.h" -#include "Randomizer.h" -#include "Panel.h" +#include "Memory.h" + +#define EXE_NAME L"witness64_d3d11.exe" -#define IDC_RANDOMIZE 0x401 +#define PROC_ATTACH 0x401 #define IDC_TOGGLESPEED 0x402 #define IDC_SPEEDRUNNER 0x403 #define IDC_HARDMODE 0x404 @@ -21,102 +21,56 @@ #define IDC_TOGGLELASERS 0x410 #define IDC_TOGGLESNIPES 0x411 -HWND hwndSeed, hwndRandomize; -// int panel = 0x18AF; -int panel = 0x33D4; -std::shared_ptr _panel; -std::shared_ptr randomizer = std::make_shared(); - -LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - static bool seedIsRNG = false; +// Globals +HWND g_hwnd; +HINSTANCE g_hInstance; +auto g_witnessProc = std::make_shared(); +LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { 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)) { - // Checkboxes - case IDC_TOGGLESPEED: - CheckDlgButton(hwnd, IDC_TOGGLESPEED, !IsDlgButtonChecked(hwnd, IDC_TOGGLESPEED)); - break; - case IDC_TOGGLELASERS: - CheckDlgButton(hwnd, IDC_TOGGLELASERS, !IsDlgButtonChecked(hwnd, IDC_TOGGLELASERS)); - break; - case IDC_TOGGLESNIPES: - CheckDlgButton(hwnd, IDC_TOGGLESNIPES, !IsDlgButtonChecked(hwnd, IDC_TOGGLESNIPES)); - 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); - - // Show seed and force redraw - std::wstring seedString = std::to_wstring(seed); - SetWindowText(hwndRandomize, L"Randomizing..."); - SetWindowText(hwndSeed, seedString.c_str()); - RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW); - - // Randomize, then apply settings - randomizer->Randomize(); - if (IsDlgButtonChecked(hwnd, IDC_TOGGLESPEED)) randomizer->AdjustSpeed(); - if (IsDlgButtonChecked(hwnd, IDC_TOGGLELASERS)) randomizer->RandomizeLasers(); - if (IsDlgButtonChecked(hwnd, IDC_TOGGLESNIPES)) randomizer->PreventSnipes(); - - // Cleanup, and set timer for "randomization done" - SetWindowText(hwndRandomize, L"Randomized!"); - SetTimer(hwnd, IDT_RANDOMIZED, 10000, NULL); - break; - } - - case IDT_RANDOMIZED: - SetWindowText(hwndRandomize, L"Randomize"); - randomizer->GameIsRandomized(); // "Check" if the game is randomized to update the last known safe frame. - break; - case IDC_READ: - _panel = std::make_shared(panel); - break; - case IDC_RANDOM: - _panel->Random(); - break; - case IDC_WRITE: - _panel->Write(panel); - break; - case IDC_DUMP: - _panel->Serialize(); - break; - } - } + } else if (message == WM_COMMAND) { + switch (LOWORD(wParam)) { + case PROC_ATTACH: + if (!g_witnessProc->Initialize(EXE_NAME)) { + OutputDebugString(L"Failed to initialize, trying again in 5 seconds"); + SetTimer(g_hwnd, PROC_ATTACH, 5000, NULL); // Re-attach in 10s + } + break; + case IDC_TOGGLELASERS: + OutputDebugString(L"Hello, world!"); + break; + default: + assert(false); + break; + } + } return DefWindowProc(hwnd, message, wParam, lParam); } -int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) -{ - LoadLibrary(L"Msftedit.dll"); +void CreateLabel(int x, int y, int width, LPCWSTR text) { + CreateWindow(L"STATIC", text, + WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, + x, y, width, 16, g_hwnd, NULL, g_hInstance, NULL); +} + +void CreateButton(int x, int y, int width, LPCWSTR text, int message) { +#pragma warning(push) +#pragma warning(disable: 4312) + CreateWindow(L"BUTTON", text, + WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, + x, y, width, 26, g_hwnd, (HMENU)message, g_hInstance, NULL); +#pragma warning(pop) +} + +/* + hwndSeed = CreateWindow(MSFTEDIT_CLASS, L"", + WS_TABSTOP | WS_VISIBLE | WS_CHILD | WS_BORDER, + 100, 10, 50, 26, hwnd, NULL, hInstance, NULL); +*/ +int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { + LoadLibrary(L"Msftedit.dll"); WNDCLASSW wndClass = { CS_HREDRAW | CS_VREDRAW, WndProc, @@ -131,101 +85,22 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd }; RegisterClassW(&wndClass); + g_hInstance = hInstance; + RECT rect; GetClientRect(GetDesktopWindow(), &rect); - HWND hwnd = CreateWindow(WINDOW_CLASS, PRODUCT_NAME, WS_OVERLAPPEDWINDOW, + g_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, 210, 16, hwnd, NULL, hInstance, NULL); - - CreateWindow(L"BUTTON", L"", - WS_VISIBLE | WS_CHILD | BS_CHECKBOX, - 10, 72, 12, 12, hwnd, (HMENU)IDC_TOGGLELASERS, hInstance, NULL); - CreateWindow(L"STATIC", L"Randomize laser activations", - WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, - 27, 70, 210, 16, hwnd, NULL, hInstance, NULL); - - CreateWindow(L"BUTTON", L"", - WS_VISIBLE | WS_CHILD | BS_CHECKBOX, - 10, 92, 12, 12, hwnd, (HMENU)IDC_TOGGLESNIPES, hInstance, NULL); - CheckDlgButton(hwnd, IDC_TOGGLESNIPES, TRUE); - CreateWindow(L"STATIC", L"Prevent sniping certain puzzles", - WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, - 27, 90, 210, 16, 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); - -*/ + CreateLabel(390, 15, 90, L"Version: " VERSION_STR); + CreateButton(10, 72, 100, L"Button text", IDC_TOGGLELASERS); + PostMessage(g_hwnd, WM_COMMAND, PROC_ATTACH, NULL); - ShowWindow(hwnd, nCmdShow); - UpdateWindow(hwnd); + ShowWindow(g_hwnd, nCmdShow); + UpdateWindow(g_hwnd); MSG msg; - while (!GetMessage(&msg, nullptr, 0, 0) == 0) - { + while (GetMessage(&msg, nullptr, 0, 0) == TRUE) { TranslateMessage(&msg); DispatchMessage(&msg); } -- cgit 1.4.1