From 3557f0ba80942397a9d963208695b4fa80290cb0 Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Tue, 30 Oct 2018 21:58:46 -0700 Subject: Infinite amounts of cleanup --- Source/Main.cpp | 13 ++++++------- Source/Random.h | 3 ++- Source/Randomizer.cpp | 17 +++++++++++++---- Source/Randomizer.h | 2 +- Source/RandomizerCore.cpp | 19 +++++++++++++++++++ Source/RandomizerCore.h | 9 +++++++++ Source/Resource.h | 26 -------------------------- Source/Source.vcxproj | 5 ++--- Source/Source.vcxproj.filters | 3 --- Source/Version.h | 10 +++++----- Source/Version.rc | 24 +----------------------- 11 files changed, 58 insertions(+), 73 deletions(-) delete mode 100644 Source/Resource.h (limited to 'Source') diff --git a/Source/Main.cpp b/Source/Main.cpp index 28bc472..8336c77 100644 --- a/Source/Main.cpp +++ b/Source/Main.cpp @@ -1,8 +1,6 @@ #include "windows.h" -#include "resource.h" #include -#include #include #include "Randomizer.h" @@ -40,18 +38,19 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) GetWindowText(hwndSeed, &text[0], 100); int seed = 0; if (wasSeedRandomlyGenerated || wcslen(text.c_str()) == 0) { - Random::SetSeed(time(nullptr)); // Seed from the time in milliseconds seed = Random::RandInt(0, 100000); - std::wstring seedString = std::to_wstring(seed); - SetWindowText(hwndSeed, seedString.c_str()); wasSeedRandomlyGenerated = true; } else { seed = _wtoi(text.c_str()); wasSeedRandomlyGenerated = false; } - Random::SetSeed(seed); + Randomizer randomizer; - randomizer.Randomize(); + short metadata = randomizer.Randomize(seed); + if (metadata & 0x1) break; // Was already randomized + + std::wstring seedString = std::to_wstring(seed); + SetWindowText(hwndSeed, seedString.c_str()); if (IsDlgButtonChecked(hwnd, IDC_TOGGLESPEED)) { randomizer.AdjustSpeed(); } diff --git a/Source/Random.h b/Source/Random.h index e4700f3..40998de 100644 --- a/Source/Random.h +++ b/Source/Random.h @@ -1,6 +1,7 @@ #pragma once +#include -static int s_seed; +static int s_seed = time(nullptr); // Seed from the time in milliseconds class Random { diff --git a/Source/Randomizer.cpp b/Source/Randomizer.cpp index 83f5571..9622601 100644 --- a/Source/Randomizer.cpp +++ b/Source/Randomizer.cpp @@ -4,21 +4,21 @@ * Swamp <-> symmetry has non-invisible background * Tutorial sounds don't always play * FEATURES: - * Prevent re-randomization (?) - * Clear "Randomized" state on NG (?) -- Or on a short delay + * Clear "Randomized" button after 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. * Start the game if it isn't running? * Stop swapping colors in desert + * Allow users to enter seed after randomly generating seed (aka detect user input in the text box) */ #include "Memory.h" #include "Randomizer.h" #include "Panels.h" +#include "Random.h" #include #include #include -#include template int find(const std::vector &data, T search, size_t startIndex = 0) { @@ -29,8 +29,16 @@ int find(const std::vector &data, T search, size_t startIndex = 0) { exit(-1); } -void Randomizer::Randomize() +short Randomizer::Randomize(int seed) { + short metadata = _core.ReadMetadata(); + if (metadata & 0x1) { + // Already randomized -- exit. + return metadata; + } + _core.WriteMetadata(metadata | 0x1); + Random::SetSeed(seed); + // Content swaps -- must happen before squarePanels _core.Randomize(upDownPanels, SWAP_LINES); _core.Randomize(leftForwardRightPanels, SWAP_LINES); @@ -53,6 +61,7 @@ void Randomizer::Randomize() RandomizeMountain(); // RandomizeChallenge(); // RandomizeAudioLogs(); + return metadata; } void Randomizer::AdjustSpeed() { diff --git a/Source/Randomizer.h b/Source/Randomizer.h index b0da4fe..8c332b0 100644 --- a/Source/Randomizer.h +++ b/Source/Randomizer.h @@ -3,7 +3,7 @@ class Randomizer { public: - void Randomize(); + short Randomize(int seed); void AdjustSpeed(); private: diff --git a/Source/RandomizerCore.cpp b/Source/RandomizerCore.cpp index 684e19d..f14a76f 100644 --- a/Source/RandomizerCore.cpp +++ b/Source/RandomizerCore.cpp @@ -3,6 +3,17 @@ #include "Random.h" #include +static int lastKnownFrame = 1 << 30; + +RandomizerCore::RandomizerCore() { + int currentFrame = _memory.ReadData({SCRIPT_FRAMES}, 1)[0]; + if (currentFrame < lastKnownFrame) { + // Time went backwards, indicates new game + WriteMetadata(0); + } + lastKnownFrame = currentFrame; +} + void RandomizerCore::Randomize(std::vector& panels, int flags) { return RandomizeRange(panels, flags, 0, panels.size()); } @@ -125,3 +136,11 @@ void RandomizerCore::ReassignNames(const std::vector& panels, const std::ve WritePanelData(panels[i], AUDIO_LOG_NAME, {names[order[i]]}); } } + +short RandomizerCore::ReadMetadata() { + return _memory.ReadData({GLOBALS + METADATA}, 1)[0]; +} + +void RandomizerCore::WriteMetadata(short metadata) { + return _memory.WriteData({GLOBALS + METADATA}, {metadata}); +} \ No newline at end of file diff --git a/Source/RandomizerCore.h b/Source/RandomizerCore.h index e8d3661..7ec8e33 100644 --- a/Source/RandomizerCore.h +++ b/Source/RandomizerCore.h @@ -12,6 +12,8 @@ __declspec(selectany) int SWAP_AUDIO_NAMES = 0x4; class RandomizerCore { public: + RandomizerCore(); + 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); @@ -28,6 +30,9 @@ public: _memory.WriteData({GLOBALS, 0x18, panel*8, offset}, data); } + short ReadMetadata(); + void WriteMetadata(short metadata); + private: Memory _memory = Memory("witness64_d3d11.exe"); }; @@ -95,6 +100,8 @@ private: #define CABLE_TARGET_2 0xD8 #define AUDIO_LOG_NAME 0xC8 #define OPEN_RATE 0xE8 +#define METADATA 0xF2 // sizeof(short) +#define SCRIPT_FRAMES 0x5BE3B0 #elif GLOBALS == 0x62A080 #define PATH_COLOR 0xC0 #define REFLECTION_PATH_COLOR 0xD0 @@ -158,4 +165,6 @@ private: #define CABLE_TARGET_2 0xD0 #define AUDIO_LOG_NAME 0x0 #define OPEN_RATE 0xE0 +#define METADATA 0x13A // sizeof(short) +#define SCRIPT_FRAMES 0x63651C #endif \ No newline at end of file diff --git a/Source/Resource.h b/Source/Resource.h deleted file mode 100644 index 426abc1..0000000 --- a/Source/Resource.h +++ /dev/null @@ -1,26 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by Source.rc -// -#define IDC_MYICON 2 -#define IDD_SOURCE_DIALOG 102 -#define IDS_APP_TITLE 103 -#define IDM_ABOUT 104 -#define IDM_EXIT 105 -#define IDI_SOURCE 107 -#define IDI_SMALL 108 -#define IDC_SOURCE 109 -#define IDR_MAINFRAME 128 -#define IDC_STATIC -1 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NO_MFC 1 -#define _APS_NEXT_RESOURCE_VALUE 129 -#define _APS_NEXT_COMMAND_VALUE 32771 -#define _APS_NEXT_CONTROL_VALUE 1000 -#define _APS_NEXT_SYMED_VALUE 110 -#endif -#endif diff --git a/Source/Source.vcxproj b/Source/Source.vcxproj index afd4fd3..38914a6 100644 --- a/Source/Source.vcxproj +++ b/Source/Source.vcxproj @@ -103,7 +103,7 @@ NotUsing - Level3 + Level2 Disabled true _DEBUG;_WINDOWS;%(PreprocessorDefinitions) @@ -142,7 +142,7 @@ NotUsing - Level1 + Level2 MaxSpeed true true @@ -167,7 +167,6 @@ - diff --git a/Source/Source.vcxproj.filters b/Source/Source.vcxproj.filters index dbb50f9..2f8f60b 100644 --- a/Source/Source.vcxproj.filters +++ b/Source/Source.vcxproj.filters @@ -15,9 +15,6 @@ - - Header Files - Header Files diff --git a/Source/Version.h b/Source/Version.h index ed79ee5..5aac53d 100644 --- a/Source/Version.h +++ b/Source/Version.h @@ -1,14 +1,14 @@ #pragma once +#define TO_STRING2(s) L#s +#define TO_STRING(s) TO_STRING2(s) + #define MAJOR 3 #define MINOR 0 -#define PATCH 1 - -#define VERSION MAJOR, MINOR, PATCH +#define PATCH 3 -#define TO_STRING2(s) L#s -#define TO_STRING(s) TO_STRING2(s) #define VERSION_STR TO_STRING(MAJOR) L"." TO_STRING(MINOR) L"." TO_STRING(PATCH) +#define VERSION MAJOR, MINOR, PATCH #define PRODUCT_NAME L"Witness Randomizer" #define WINDOW_CLASS L"WitnessRandomizer" diff --git a/Source/Version.rc b/Source/Version.rc index fe44a47..9b90884 100644 --- a/Source/Version.rc +++ b/Source/Version.rc @@ -1,28 +1,6 @@ #include "version.h" -#include "resource.h" -#include -#include "windows.h" - -STRINGTABLE -BEGIN - IDC_SOURCE "SOURCE" -END VS_VERSION_INFO VERSIONINFO - FILEVERSION VERSION - PRODUCTVERSION VERSION + FILEVERSION VERSION BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904b0" - BEGIN - VALUE "FileDescription", "Randomizer for The Witness" - VALUE "FileVersion", VERSION_STR - VALUE "InternalName", "Source.exe" - VALUE "LegalCopyright", "Copyright (C) 2018" - VALUE "OriginalFilename", "Source.exe" - VALUE "ProductName", PRODUCT_NAME - VALUE "ProductVersion", VERSION_STR - END - END END -- cgit 1.4.1