From fa5c27c9b5991f2daf526eb5fdd3e41200afa63e Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Sun, 17 Jan 2021 16:15:37 -0800 Subject: Try adding app2 --- App2/App2.vcxproj | 168 +++++++++++++++++++++++++ App2/App2.vcxproj.filters | 27 ++++ App2/Main.cpp | 313 ++++++++++++++++++++++++++++++++++++++++++++++ App2/Version.h | 14 +++ WitnessRandomizer.sln | 14 +++ 5 files changed, 536 insertions(+) create mode 100644 App2/App2.vcxproj create mode 100644 App2/App2.vcxproj.filters create mode 100644 App2/Main.cpp create mode 100644 App2/Version.h diff --git a/App2/App2.vcxproj b/App2/App2.vcxproj new file mode 100644 index 0000000..5b8923a --- /dev/null +++ b/App2/App2.vcxproj @@ -0,0 +1,168 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {5a4e859a-9756-463e-86e6-6eadbba23021} + App2 + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + ChallengeRandomizer + + + false + ChallengeRandomizer + + + true + ChallengeRandomizer + + + false + ChallengeRandomizer + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp17 + ..\Source;%(AdditionalIncludeDirectories) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp17 + ..\Source;%(AdditionalIncludeDirectories) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp17 + ..\Source;%(AdditionalIncludeDirectories) + true + MultiThreadedDebug + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp17 + ..\Source;%(AdditionalIncludeDirectories) + true + MultiThreaded + + + Console + true + true + true + + + + + + + + + + + + \ No newline at end of file diff --git a/App2/App2.vcxproj.filters b/App2/App2.vcxproj.filters new file mode 100644 index 0000000..a121d06 --- /dev/null +++ b/App2/App2.vcxproj.filters @@ -0,0 +1,27 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + + + Source Files + + + \ No newline at end of file diff --git a/App2/Main.cpp b/App2/Main.cpp new file mode 100644 index 0000000..30deff2 --- /dev/null +++ b/App2/Main.cpp @@ -0,0 +1,313 @@ +#include "pch.h" +#include "Richedit.h" +#include "Version.h" + +#include "Memory.h" +#include "Random.h" +#include "Randomizer.h" +#include "Randomizer2.h" +#include "Panels_.h" + +#define HEARTBEAT 0x401 +#define RANDOMIZE_READY 0x402 +#define RANDOMIZING 0403 +#define RANDOMIZE_DONE 0x404 +#define RANDOMIZE_CHALLENGE_DONE 0x405 +#define CHALLENGE_ONLY 0x406 +#define DISABLE_SNIPES 0x407 +#define SPEED_UP_AUTOSCROLLERS 0x408 + +/* ------- Temp ------- */ +#include "Solver.h" +#include "PuzzleSerializer.h" +#include +#include + +#define TMP1 0x501 +#define TMP2 0x502 +#define TMP3 0x503 +#define TMP4 0x504 + +HWND g_panelId; +Puzzle g_puzzle; + +HWND g_rngDebug; +#define TMP5 0x505 +/* ------- Temp ------- */ + +// Globals +HWND g_hwnd; +HWND g_seed; +HWND g_randomizerStatus; +HINSTANCE g_hInstance; +auto g_witnessProc = std::make_shared(L"witness64_d3d11.exe"); +std::shared_ptr g_randomizer; +std::shared_ptr g_randomizer2; +void SetRandomSeed(); + +LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { + if (message == WM_DESTROY) { + PostQuitMessage(0); + } else if (message == WM_NOTIFY) { + MSGFILTER* m = (MSGFILTER *)lParam; + if (m->msg == WM_KEYDOWN && m->wParam == VK_RETURN) { + if (IsWindowEnabled(g_randomizerStatus) == TRUE) { + PostMessage(g_hwnd, WM_COMMAND, RANDOMIZING, NULL); + return 1; // Non-zero to indicate that message was handled + } + } + } else if (message == WM_COMMAND || message == WM_TIMER || message == WM_NOTIFY) { + switch (LOWORD(wParam)) { + case HEARTBEAT: + switch ((ProcStatus)lParam) { + case ProcStatus::NotRunning: + // Shut down randomizer, wait for startup + if (g_randomizer) { + g_randomizer = nullptr; + g_randomizer2 = nullptr; + EnableWindow(g_randomizerStatus, FALSE); + } + break; + case ProcStatus::Running: + if (!g_randomizer) { + g_randomizer = std::make_shared(g_witnessProc); + g_randomizer2 = std::make_shared(g_witnessProc); + PostMessage(g_hwnd, WM_COMMAND, RANDOMIZE_READY, NULL); + } + break; + case ProcStatus::NewGame: // This status will fire only once per new game + SetWindowText(g_seed, L""); + PostMessage(g_hwnd, WM_COMMAND, RANDOMIZE_READY, NULL); + break; + } + break; + case RANDOMIZE_READY: + EnableWindow(g_randomizerStatus, TRUE); + if (IsDlgButtonChecked(hwnd, CHALLENGE_ONLY)) { + SetWindowText(g_randomizerStatus, L"Randomize Challenge"); + } else { + SetWindowText(g_randomizerStatus, L"Randomize"); + } + break; + case RANDOMIZING: + if (!g_randomizer) break; // E.g. an enter press at the wrong time + EnableWindow(g_randomizerStatus, FALSE); + + SetRandomSeed(); + std::thread([]{ + if (IsDlgButtonChecked(g_hwnd, DISABLE_SNIPES)) { + MEMORY_CATCH(g_randomizer->PreventSnipes()); + } + if (IsDlgButtonChecked(g_hwnd, SPEED_UP_AUTOSCROLLERS)) { + MEMORY_CATCH(g_randomizer->AdjustSpeed()); + } + if (IsDlgButtonChecked(g_hwnd, CHALLENGE_ONLY)) { + SetWindowText(g_randomizerStatus, L"Randomizing Challenge..."); + MEMORY_CATCH(g_randomizer->RandomizeChallenge()); + PostMessage(g_hwnd, WM_COMMAND, RANDOMIZE_CHALLENGE_DONE, NULL); + } else { + SetWindowText(g_randomizerStatus, L"Randomizing..."); + MEMORY_CATCH(g_randomizer->Randomize()); + PostMessage(g_hwnd, WM_COMMAND, RANDOMIZE_DONE, NULL); + } + }).detach(); + break; + case RANDOMIZE_DONE: + EnableWindow(g_randomizerStatus, FALSE); + SetWindowText(g_randomizerStatus, L"Randomized!"); + break; + case RANDOMIZE_CHALLENGE_DONE: + EnableWindow(g_randomizerStatus, FALSE); + SetWindowText(g_randomizerStatus, L"Randomized Challenge!"); + std::thread([]{ + // Allow re-randomization for challenge -- it doesn't break the rest of the game. + std::this_thread::sleep_for(std::chrono::seconds(10)); + PostMessage(g_hwnd, WM_COMMAND, RANDOMIZE_READY, NULL); + }).detach(); + break; + case CHALLENGE_ONLY: + CheckDlgButton(hwnd, CHALLENGE_ONLY, !IsDlgButtonChecked(hwnd, CHALLENGE_ONLY)); + if (IsWindowEnabled(g_randomizerStatus)) { + PostMessage(g_hwnd, WM_COMMAND, RANDOMIZE_READY, NULL); + } + break; + case DISABLE_SNIPES: + CheckDlgButton(hwnd, DISABLE_SNIPES, !IsDlgButtonChecked(hwnd, DISABLE_SNIPES)); + break; + case SPEED_UP_AUTOSCROLLERS: + CheckDlgButton(hwnd, SPEED_UP_AUTOSCROLLERS, !IsDlgButtonChecked(hwnd, SPEED_UP_AUTOSCROLLERS)); + break; + case TMP1: + { + std::wstring text(128, L'\0'); + int length = GetWindowText(g_panelId, text.data(), static_cast(text.size())); + text.resize(length); + std::wstringstream s; + int panelId; + s << text; + s >> std::hex >> panelId; + g_puzzle = PuzzleSerializer(g_witnessProc).ReadPuzzle(panelId); + } + break; + case TMP2: + { + std::wstring text(128, L'\0'); + int length = GetWindowText(g_panelId, text.data(), static_cast(text.size())); + text.resize(length); + std::wstringstream s; + int panelId; + s << text; + s >> std::hex >> panelId; + PuzzleSerializer(g_witnessProc).WritePuzzle(g_puzzle, panelId); + } + break; + case TMP3: + { + for (auto [key, value] : PANELS) { + std::stringstream out; + std::string name(value); + out << " {'id': 0x" << std::hex << std::uppercase << std::setfill('0') << std::setw(5) << key << ", 'area':'"; + int k; + for (k=0; name[k] != ' '; k++) out << name[k]; + if (name[k+2] == ' ') { + out << name[k] << name[k+1]; + k += 2; + } + out << "', 'name':'"; + k++; + for (k; k < name.size(); k++) out << name[k]; + out << "', 'data':'"; + auto puzzle = PuzzleSerializer(g_witnessProc).ReadPuzzle(key); + out << puzzle.Serialize(); + out << "'},\r\n"; + DebugPrint(out.str()); + } + } + + // Solver::Solve(g_puzzle); + break; + case TMP4: + SetRandomSeed(); + g_randomizer2->Randomize(); + case TMP5: + { + std::wstring text; + for (int i=0; i<10; i++) { + Random::SetSeed(i); + int rng = Random::RandInt(0, 999999); + text += std::to_wstring(rng) + L"\n"; + } + SetWindowText(g_rngDebug, text.c_str()); + } + } + } + return DefWindowProc(hwnd, message, wParam, lParam); +} + +void SetRandomSeed() { + std::wstring text(128, L'\0'); + int length = GetWindowText(g_seed, text.data(), static_cast(text.size())); + if (length > 0) { // Set seed + text.resize(length); + Random::SetSeed(_wtoi(text.c_str())); + } else { // Random seed + int seed = Random::RandInt(0, 999999); + + text = std::to_wstring(seed); + SetWindowText(g_seed, text.c_str()); + CHARRANGE range = {0, static_cast(text.length())}; + PostMessage(g_seed, EM_EXSETSEL, NULL, (LPARAM)&range); + SetFocus(g_seed); + + Random::SetSeed(seed); + } +} + +HWND CreateLabel(int x, int y, int width, LPCWSTR text) { + return CreateWindow(L"STATIC", text, + WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, + x, y, width, 16, g_hwnd, NULL, g_hInstance, NULL); +} + +HWND CreateText(int x, int y, int width, LPCWSTR defaultText = L"") { + return CreateWindow(MSFTEDIT_CLASS, defaultText, + WS_TABSTOP | WS_VISIBLE | WS_CHILD | WS_BORDER, + x, y, width, 26, g_hwnd, NULL, g_hInstance, NULL); +} + +#pragma warning(push) +#pragma warning(disable: 4312) +HWND CreateButton(int x, int y, int width, LPCWSTR text, int message) { + return CreateWindow(L"BUTTON", text, + WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, + x, y, width, 26, g_hwnd, (HMENU)message, g_hInstance, NULL); +} + +HWND CreateCheckbox(int x, int y, int message) { + return CreateWindow(L"BUTTON", L"", + WS_VISIBLE | WS_CHILD | BS_CHECKBOX, + x, y, 12, 12, g_hwnd, (HMENU)message, g_hInstance, NULL); +} +#pragma warning(pop) + +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, + 0, + 0, + hInstance, + NULL, + LoadCursor(nullptr, IDC_ARROW), + (HBRUSH)(COLOR_WINDOW+1), + WINDOW_CLASS, + WINDOW_CLASS, + }; + RegisterClassW(&wndClass); + + g_hInstance = hInstance; + + RECT rect; + GetClientRect(GetDesktopWindow(), &rect); + g_hwnd = CreateWindow(WINDOW_CLASS, PRODUCT_NAME, WS_OVERLAPPEDWINDOW, + rect.right - 550, 200, 500, 500, nullptr, nullptr, hInstance, nullptr); + + CreateLabel(390, 15, 90, L"Version: " VERSION_STR); + g_seed = CreateText(10, 10, 100, L"21581"); + PostMessage(g_seed, EM_SETEVENTMASK, 0, ENM_KEYEVENTS); + g_randomizerStatus = CreateButton(120, 10, 180, L"Randomize", RANDOMIZING); + EnableWindow(g_randomizerStatus, FALSE); + CreateCheckbox(10, 300, CHALLENGE_ONLY); + CreateLabel(30, 300, 200, L"Randomize the challenge only"); + CreateCheckbox(10, 320, DISABLE_SNIPES); + CheckDlgButton(g_hwnd, DISABLE_SNIPES, TRUE); + CreateLabel(30, 320, 240, L"Disable Swamp and Shadows snipes"); + CreateCheckbox(10, 340, SPEED_UP_AUTOSCROLLERS); + CreateLabel(30, 340, 205, L"Speed up various autoscrollers"); + + // CreateButton(200, 50, 200, L"Test RNG", TMP5); + // g_rngDebug = CreateWindow(L"STATIC", L"", + // WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, + // 200, 80, 200, 200, g_hwnd, NULL, g_hInstance, NULL); +//#ifndef NDEBUG +// g_panelId = CreateText(200, 100, 100, L"59"); +// CreateButton(200, 130, 100, L"Read", TMP1); +// CreateButton(200, 160, 100, L"Write", TMP2); + CreateButton(200, 190, 100, L"Solve", TMP3); +// CreateButton(200, 220, 100, L"Randomize2", TMP4); +//#endif + + g_witnessProc->StartHeartbeat(g_hwnd, HEARTBEAT); + + ShowWindow(g_hwnd, nCmdShow); + UpdateWindow(g_hwnd); + + MSG msg; + while (GetMessage(&msg, nullptr, 0, 0) == TRUE) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + return (int) msg.wParam; +} diff --git a/App2/Version.h b/App2/Version.h new file mode 100644 index 0000000..0afb03f --- /dev/null +++ b/App2/Version.h @@ -0,0 +1,14 @@ +#pragma once + +#define TO_STRING2(s) L#s +#define TO_STRING(s) TO_STRING2(s) + +#define MAJOR 0 +#define MINOR 0 +#define PATCH 1 + +#define VERSION_STR TO_STRING(MAJOR) L"." TO_STRING(MINOR) L"." TO_STRING(PATCH) +#define VERSION MAJOR, MINOR, PATCH + +#define PRODUCT_NAME L"Witness Challenge Randomizer" +#define WINDOW_CLASS L"WitnessChallengeRandomizer" diff --git a/WitnessRandomizer.sln b/WitnessRandomizer.sln index 9017978..ef31a4e 100644 --- a/WitnessRandomizer.sln +++ b/WitnessRandomizer.sln @@ -15,9 +15,15 @@ EndProject Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "Installer", "Installer\Installer.vdproj", "{F1B9D251-3DCC-4B19-A5C9-CA23AFD38632}" ProjectSection(ProjectDependencies) = postProject {6B5DF051-A51A-48CB-8ACD-C6FAD726019F} = {6B5DF051-A51A-48CB-8ACD-C6FAD726019F} + {5A4E859A-9756-463E-86E6-6EADBBA23021} = {5A4E859A-9756-463E-86E6-6EADBBA23021} {235D27F1-9907-489B-8D58-636A0C5CD079} = {235D27F1-9907-489B-8D58-636A0C5CD079} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "App2", "App2\App2.vcxproj", "{5A4E859A-9756-463E-86E6-6EADBBA23021}" + ProjectSection(ProjectDependencies) = postProject + {6B5DF051-A51A-48CB-8ACD-C6FAD726019F} = {6B5DF051-A51A-48CB-8ACD-C6FAD726019F} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -55,6 +61,14 @@ Global {F1B9D251-3DCC-4B19-A5C9-CA23AFD38632}.Debug|x86.ActiveCfg = Debug {F1B9D251-3DCC-4B19-A5C9-CA23AFD38632}.Release|x64.ActiveCfg = Release {F1B9D251-3DCC-4B19-A5C9-CA23AFD38632}.Release|x86.ActiveCfg = Release + {5A4E859A-9756-463E-86E6-6EADBBA23021}.Debug|x64.ActiveCfg = Debug|x64 + {5A4E859A-9756-463E-86E6-6EADBBA23021}.Debug|x64.Build.0 = Debug|x64 + {5A4E859A-9756-463E-86E6-6EADBBA23021}.Debug|x86.ActiveCfg = Debug|Win32 + {5A4E859A-9756-463E-86E6-6EADBBA23021}.Debug|x86.Build.0 = Debug|Win32 + {5A4E859A-9756-463E-86E6-6EADBBA23021}.Release|x64.ActiveCfg = Release|x64 + {5A4E859A-9756-463E-86E6-6EADBBA23021}.Release|x64.Build.0 = Release|x64 + {5A4E859A-9756-463E-86E6-6EADBBA23021}.Release|x86.ActiveCfg = Release|Win32 + {5A4E859A-9756-463E-86E6-6EADBBA23021}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- cgit 1.4.1