From 0d728e66b7bde350a6e5d9f0a467bba7a3433f16 Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Mon, 29 Oct 2018 19:57:02 -0700 Subject: should be working --- Source/Main.cpp | 187 ++++++++++++++++++++-------------------------- Source/Panels.h | 2 + Source/Randomizer.cpp | 29 ++++++- Source/Randomizer.h | 1 + Source/RandomizerCore.cpp | 21 +++--- Source/RandomizerCore.h | 5 +- 6 files changed, 119 insertions(+), 126 deletions(-) diff --git a/Source/Main.cpp b/Source/Main.cpp index 86a784b..b227e3d 100644 --- a/Source/Main.cpp +++ b/Source/Main.cpp @@ -1,49 +1,73 @@ // Source.cpp : Defines the entry point for the application. // -#include "stdafx.h" #include "resource.h" -#include "tchar.h" -#include "Randomizer.h" #include -#include #include #include +#include "Randomizer.h" +#include "windows.h" -#define MAX_LOADSTRING 100 -#define IDC_RANDOMIZE 0x464 - -HINSTANCE hInst; -WCHAR szWindowClass[MAX_LOADSTRING]; -HWND hwndSeed, hwndRandomize; +#define IDC_RANDOMIZE 0x401 +#define IDC_TOGGLESPEED 0x402 -// Forward declares -ATOM MyRegisterClass(HINSTANCE hInstance); -BOOL InitInstance(HINSTANCE, int); -LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); -INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); +HWND hwndSeed, hwndRandomize, hwndSpeedSetting; -int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) +LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { - LoadStringW(hInstance, IDC_SOURCE, szWindowClass, MAX_LOADSTRING); - MyRegisterClass(hInstance); - if (!InitInstance(hInstance, nCmdShow)) { - return FALSE; - } - - MSG msg; - while (!GetMessage(&msg, nullptr, 0, 0) == 0) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } + static bool wasSeedRandomlyGenerated; - return (int) msg.wParam; + if (message == WM_DESTROY) { + PostQuitMessage(0); + } else if (message == WM_COMMAND) { + switch (LOWORD(wParam)) { + // Speed checkbox + case IDC_TOGGLESPEED: + if (IsDlgButtonChecked(hwndSpeedSetting, 1)) { + CheckDlgButton(hwndSpeedSetting, 1, BST_UNCHECKED); + } else { + CheckDlgButton(hwndSpeedSetting, 1, BST_CHECKED); + } + break; + + // Randomize button + case IDC_RANDOMIZE: + { + std::wstring text(100, '\0'); + GetWindowText(hwndSeed, &text[0], 100); + int seed = 0; + if (wasSeedRandomlyGenerated || wcslen(text.c_str()) == 0) { + srand(static_cast(time(nullptr))); // Seed from the time in milliseconds + rand(); // Increment RNG so that RNG isn't still using the time + seed = rand() % 100000; + std::wstring seedString = std::to_wstring(seed); + SetWindowText(hwndSeed, seedString.c_str()); + wasSeedRandomlyGenerated = true; + } else { + seed = _wtoi(text.c_str()); + wasSeedRandomlyGenerated = false; + } + srand(seed); + Randomizer randomizer; + randomizer.Randomize(); + if (IsDlgButtonChecked(hwndSpeedSetting, 1)) { + randomizer.AdjustSpeed(); + } + SetWindowText(hwndRandomize, L"Randomized!"); + break; + } + } + } + return DefWindowProc(hwnd, message, wParam, lParam); } -ATOM MyRegisterClass(HINSTANCE hInstance) +int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) { - WNDCLASSEXW wcex = { + #define MAX_LOADSTRING 100 + WCHAR szWindowClass[MAX_LOADSTRING]; + LoadStringW(hInstance, IDC_SOURCE, szWindowClass, MAX_LOADSTRING); + + WNDCLASSEXW wcex = { sizeof(WNDCLASSEX), CS_HREDRAW | CS_VREDRAW, WndProc, @@ -57,95 +81,42 @@ ATOM MyRegisterClass(HINSTANCE hInstance) szWindowClass, LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)), }; - - return RegisterClassExW(&wcex); -} - -BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) -{ - hInst = hInstance; // Store instance handle in our global variable + RegisterClassExW(&wcex); WCHAR szTitle[MAX_LOADSTRING]; LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); - HWND hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, + HWND hwnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, 400, 200, 500, 500, nullptr, nullptr, hInstance, nullptr); - if (!hWnd) return FALSE; - LoadLibrary(L"Msftedit.dll"); - HWND label = CreateWindow(L"STATIC", L"Enter a seed:", - WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT, - 10, 15, 90, 16, hWnd, NULL, hInst, NULL); - hwndSeed = CreateWindowEx(0, MSFTEDIT_CLASS, L"", - WS_TABSTOP | WS_VISIBLE | WS_CHILD | WS_BORDER, - 100, 10, 50, 26, hWnd, NULL, hInst, 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); hwndRandomize = CreateWindow(L"BUTTON", L"Randomize", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, - 160, 10, 100, 26, hWnd, (HMENU)IDC_RANDOMIZE, hInst, NULL); - - HDC hdc = GetDC(hWnd); - RECT rect; - GetClientRect(hWnd, &rect); - LPCWSTR text = L"this Window cannot be used"; - DrawText(hdc, text, static_cast(wcslen(text)), &rect, DT_CENTER | DT_VCENTER); - ReleaseDC(hWnd, hdc); - - ShowWindow(hWnd, nCmdShow); - UpdateWindow(hWnd); - return TRUE; -} + 160, 10, 100, 26, hwnd, (HMENU)IDC_RANDOMIZE, hInstance, NULL); -LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - if (message == WM_DESTROY) { - PostQuitMessage(0); - } else if (message == WM_COMMAND) { - int wmId = LOWORD(wParam); - // Parse the menu selections: - if (wmId == IDC_RANDOMIZE) { - std::wstring text(100, '\0'); - GetWindowText(hwndSeed, &text[0], 100); - int seed = 0; - if (wcslen(text.c_str()) == 0) { - srand(static_cast(time(nullptr))); // Seed from the time in milliseconds - rand(); - seed = rand() % 100000; - std::wstring seedString = std::to_wstring(seed); - SetWindowText(hwndSeed, seedString.c_str()); - } else { - seed = _wtoi(text.c_str()); - } - srand(seed); - Randomizer randomizer; - randomizer.Randomize(); - /* - if (adjustSpeed.isChecked()) { - randomizer.AdjustSpeed(); - } - */ - SetWindowText(hwndRandomize, L"Randomized!"); - } - } - return DefWindowProc(hWnd, message, wParam, lParam); -} + hwndSpeedSetting = 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); -INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - UNREFERENCED_PARAMETER(lParam); - switch (message) + ShowWindow(hwnd, nCmdShow); + UpdateWindow(hwnd); + + MSG msg; + while (!GetMessage(&msg, nullptr, 0, 0) == 0) { - case WM_INITDIALOG: - return TRUE; - - case WM_COMMAND: - if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) - { - EndDialog(hDlg, LOWORD(wParam)); - return TRUE; - } - break; + TranslateMessage(&msg); + DispatchMessage(&msg); } - return FALSE; + + return (int) msg.wParam; } diff --git a/Source/Panels.h b/Source/Panels.h index 6aa0d47..85fa28b 100644 --- a/Source/Panels.h +++ b/Source/Panels.h @@ -72,10 +72,12 @@ std::vector pillars = { 0x0383F, // Mountain 3 Left Pillar 2 0x03859, // Mountain 3 Left Pillar 3 0x339BB, // Mountain 3 Left Pillar 4 + 0x3C113, // Mountain 3 Left Open Door 0x0383A, // Mountain 3 Right Pillar 1 0x09E56, // Mountain 3 Right Pillar 2 0x09E5A, // Mountain 3 Right Pillar 3 0x33961, // Mountain 3 Right Pillar 4 + 0x3C114, // Mountain 3 Right Open Door // 0x09DD5, // UTM Challenge Pillar }; diff --git a/Source/Randomizer.cpp b/Source/Randomizer.cpp index 4541512..406468c 100644 --- a/Source/Randomizer.cpp +++ b/Source/Randomizer.cpp @@ -5,9 +5,8 @@ * Tutorial sounds don't always play * FEATURES: * Speed up some of the slow things (like swamp) - * Determine if the user has entered the seed, and re-randomize it if not * Prevent re-randomization (?) - * Clear "Randomized" state on NG (?) + * Clear "Randomized" state on NG (?) -- Or on a short delay * Randomize audio logs -- Hard, seem to be unloaded some times? * Swap sounds in jungle (along with panels) -- maybe impossible * Make orange 7 (all of oranges?) hard. Like big = hard. @@ -60,6 +59,10 @@ void Randomizer::Randomize() // RandomizeAudioLogs(); } +void Randomizer::AdjustSpeed() { + +} + void Randomizer::RandomizeTutorial() { // Disable tutorial cursor speed modifications (not working?) _core.WritePanelData(0x00295, CURSOR_SPEED_SCALE, {1.0}); @@ -158,10 +161,30 @@ void Randomizer::RandomizeSwamp() { } void Randomizer::RandomizeMountain() { + // Randomize lasers & some of mountain _core.Randomize(lasers, SWAP_TARGETS); - _core.Randomize(pillars, SWAP_LINES | SWAP_BACK_DISTANCE); _core.Randomize(mountainMultipanel, SWAP_LINES); + // Randomize final pillars order + std::vector targets = {pillars[0] + 1}; + for (const int pillar : pillars) { + int target = _core.ReadPanelData(pillar, TARGET, 1)[0]; + targets.push_back(target); + } + targets[5] = pillars[5] + 1; + + std::vector randomOrder(pillars.size(), 0); + std::iota(randomOrder.begin(), randomOrder.end(), 0); + _core.RandomizeRange(randomOrder, SWAP_NONE, 0, 4); // Left Pillars 1-4 + _core.RandomizeRange(randomOrder, SWAP_NONE, 5, 9); // Right Pillars 1-4 + _core.ReassignTargets(pillars, randomOrder, targets); + // Turn off original starting panels + _core.WritePanelData(pillars[0], POWER, {0.0f, 0.0f}); + _core.WritePanelData(pillars[5], POWER, {0.0f, 0.0f}); + // Turn on new starting panels + _core.WritePanelData(pillars[randomOrder[0]], POWER, {1.0f, 1.0f}); + _core.WritePanelData(pillars[randomOrder[5]], POWER, {1.0f, 1.0f}); + // Read the target of keep front laser, and write it to keep back laser. std::vector keepFrontLaserTarget = _core.ReadPanelData(0x0360E, TARGET, 1); _core.WritePanelData(0x03317, TARGET, keepFrontLaserTarget); diff --git a/Source/Randomizer.h b/Source/Randomizer.h index 552e33d..b0da4fe 100644 --- a/Source/Randomizer.h +++ b/Source/Randomizer.h @@ -4,6 +4,7 @@ class Randomizer { public: void Randomize(); + void AdjustSpeed(); private: void RandomizeTutorial(); diff --git a/Source/RandomizerCore.cpp b/Source/RandomizerCore.cpp index c673e2d..77977c6 100644 --- a/Source/RandomizerCore.cpp +++ b/Source/RandomizerCore.cpp @@ -30,9 +30,6 @@ void RandomizerCore::SwapPanels(int panel1, int panel2, int flags) { if (flags & SWAP_AUDIO_NAMES) { offsets[AUDIO_LOG_NAME] = sizeof(void*); } - if (flags & SWAP_BACK_DISTANCE) { - offsets[EXTRA_BACK_DISTANCE] = sizeof(float); - } if (flags & SWAP_LINES) { offsets[PATH_COLOR] = 16; offsets[REFLECTION_PATH_COLOR] = 16; @@ -99,18 +96,20 @@ void RandomizerCore::SwapPanels(int panel1, int panel2, int flags) { } } -void RandomizerCore::ReassignTargets(const std::vector& panels, const std::vector& order) { - // This list is offset by 1, so the target of the Nth panel is in position N (aka the N+1th element) - // The first panel may not have a wire to power it, so we use the panel ID itself. - std::vector targetToActivatePanel = {panels[0] + 1}; - for (const int panel : panels) { - int target = ReadPanelData(panel, TARGET, 1)[0]; - targetToActivatePanel.push_back(target); +void RandomizerCore::ReassignTargets(const std::vector& panels, const std::vector& order, std::vector targets) { + if (targets.empty()) { + // This list is offset by 1, so the target of the Nth panel is in position N (aka the N+1th element) + // The first panel may not have a wire to power it, so we use the panel ID itself. + targets = {panels[0] + 1}; + for (const int panel : panels) { + int target = ReadPanelData(panel, TARGET, 1)[0]; + targets.push_back(target); + } } for (size_t i=0; i(panels[order[i]], TARGET, {panelTarget}); } } diff --git a/Source/RandomizerCore.h b/Source/RandomizerCore.h index 2a8e42e..711cc89 100644 --- a/Source/RandomizerCore.h +++ b/Source/RandomizerCore.h @@ -8,7 +8,6 @@ __declspec(selectany) int SWAP_NONE = 0x0; __declspec(selectany) int SWAP_TARGETS = 0x1; __declspec(selectany) int SWAP_LINES = 0x2; __declspec(selectany) int SWAP_AUDIO_NAMES = 0x4; -__declspec(selectany) int SWAP_BACK_DISTANCE = 0x8; class RandomizerCore { @@ -16,7 +15,7 @@ public: void Randomize(std::vector& panels, int flags); void RandomizeRange(std::vector &panels, int flags, size_t startIndex, size_t endIndex); void SwapPanels(int panel1, int panel2, int flags); - void ReassignTargets(const std::vector& panels, const std::vector& order); + void ReassignTargets(const std::vector& panels, const std::vector& order, std::vector targets = {}); void ReassignNames(const std::vector& panels, const std::vector& order); template @@ -55,7 +54,6 @@ private: #define PUSH_SYMBOL_COLORS 0x208 #define OUTER_BACKGROUND 0x20C #define OUTER_BACKGROUND_MODE 0x21C -#define EXTRA_BACK_DISTANCE 0x22C #define TRACED_EDGES 0x230 #define AUDIO_PREFIX 0x278 #define POWER 0x2A8 @@ -118,7 +116,6 @@ private: #define PUSH_SYMBOL_COLORS 0x200 #define OUTER_BACKGROUND 0x204 #define OUTER_BACKGROUND_MODE 0x214 -#define EXTRA_BACK_DISTANCE 0x224 #define TRACED_EDGES 0x228 #define AUDIO_PREFIX 0x270 #define POWER 0x2A0 -- cgit 1.4.1