Skip to content

Commit

Permalink
Infinite amounts of cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jbzdarkid committed Oct 31, 2018
1 parent e66a408 commit 3557f0b
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 76 deletions.
6 changes: 3 additions & 3 deletions Installer/Installer.vdproj
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@
{
"Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:Witness Randomizer"
"ProductCode" = "8:{03F86460-1996-4804-B316-2D403F37CADE}"
"PackageCode" = "8:{4F55E8DA-1DC7-4319-9DC7-91D8F1BBC605}"
"ProductCode" = "8:{332FC406-9528-47A7-9BCE-6EA315BDB863}"
"PackageCode" = "8:{41851CA8-50AA-4E86-B041-9664C9777480}"
"UpgradeCode" = "8:{4CB5496B-A47E-41D3-B4A7-677E29AB7513}"
"AspNetVersion" = "8:2.0.50727.0"
"RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:FALSE"
"ProductVersion" = "8:3.0.0"
"ProductVersion" = "8:3.0.3"
"Manufacturer" = "8:jbzdarkid"
"ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:https://www.github.com/jbzdarkid/witness-randomizer/issues"
Expand Down
13 changes: 6 additions & 7 deletions Source/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "windows.h"
#include "resource.h"
#include <Richedit.h>

#include <ctime>
#include <string>

#include "Randomizer.h"
Expand Down Expand Up @@ -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();
}
Expand Down
3 changes: 2 additions & 1 deletion Source/Random.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <chrono>

static int s_seed;
static int s_seed = time(nullptr); // Seed from the time in milliseconds

class Random
{
Expand Down
17 changes: 13 additions & 4 deletions Source/Randomizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string>
#include <iostream>
#include <numeric>
#include <chrono>

template <class T>
int find(const std::vector<T> &data, T search, size_t startIndex = 0) {
Expand All @@ -29,8 +29,16 @@ int find(const std::vector<T> &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);
Expand All @@ -53,6 +61,7 @@ void Randomizer::Randomize()
RandomizeMountain();
// RandomizeChallenge();
// RandomizeAudioLogs();
return metadata;
}

void Randomizer::AdjustSpeed() {
Expand Down
2 changes: 1 addition & 1 deletion Source/Randomizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Randomizer {
public:
void Randomize();
short Randomize(int seed);
void AdjustSpeed();

private:
Expand Down
19 changes: 19 additions & 0 deletions Source/RandomizerCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
#include "Random.h"
#include <sstream>

static int lastKnownFrame = 1 << 30;

RandomizerCore::RandomizerCore() {
int currentFrame = _memory.ReadData<int>({SCRIPT_FRAMES}, 1)[0];
if (currentFrame < lastKnownFrame) {
// Time went backwards, indicates new game
WriteMetadata(0);
}
lastKnownFrame = currentFrame;
}

void RandomizerCore::Randomize(std::vector<int>& panels, int flags) {
return RandomizeRange(panels, flags, 0, panels.size());
}
Expand Down Expand Up @@ -125,3 +136,11 @@ void RandomizerCore::ReassignNames(const std::vector<int>& panels, const std::ve
WritePanelData<int64_t>(panels[i], AUDIO_LOG_NAME, {names[order[i]]});
}
}

short RandomizerCore::ReadMetadata() {
return _memory.ReadData<short>({GLOBALS + METADATA}, 1)[0];
}

void RandomizerCore::WriteMetadata(short metadata) {
return _memory.WriteData<short>({GLOBALS + METADATA}, {metadata});
}
9 changes: 9 additions & 0 deletions Source/RandomizerCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ __declspec(selectany) int SWAP_AUDIO_NAMES = 0x4;
class RandomizerCore
{
public:
RandomizerCore();

void Randomize(std::vector<int>& panels, int flags);
void RandomizeRange(std::vector<int> &panels, int flags, size_t startIndex, size_t endIndex);
void SwapPanels(int panel1, int panel2, int flags);
Expand All @@ -28,6 +30,9 @@ class RandomizerCore
_memory.WriteData<T>({GLOBALS, 0x18, panel*8, offset}, data);
}

short ReadMetadata();
void WriteMetadata(short metadata);

private:
Memory _memory = Memory("witness64_d3d11.exe");
};
Expand Down Expand Up @@ -95,6 +100,8 @@ class RandomizerCore
#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
Expand Down Expand Up @@ -158,4 +165,6 @@ class RandomizerCore
#define CABLE_TARGET_2 0xD0
#define AUDIO_LOG_NAME 0x0
#define OPEN_RATE 0xE0
#define METADATA 0x13A // sizeof(short)
#define SCRIPT_FRAMES 0x63651C
#endif
26 changes: 0 additions & 26 deletions Source/Resource.h

This file was deleted.

5 changes: 2 additions & 3 deletions Source/Source.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<WarningLevel>Level2</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand Down Expand Up @@ -142,7 +142,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level1</WarningLevel>
<WarningLevel>Level2</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
Expand All @@ -167,7 +167,6 @@
<ClInclude Include="Random.h" />
<ClInclude Include="Randomizer.h" />
<ClInclude Include="RandomizerCore.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="Version.h" />
</ItemGroup>
<ItemGroup>
Expand Down
3 changes: 0 additions & 3 deletions Source/Source.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Memory.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down
10 changes: 5 additions & 5 deletions Source/Version.h
Original file line number Diff line number Diff line change
@@ -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"
24 changes: 1 addition & 23 deletions Source/Version.rc
Original file line number Diff line number Diff line change
@@ -1,28 +1,6 @@
#include "version.h"
#include "resource.h"
#include <SDKDDKVer.h>
#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
2 changes: 2 additions & 0 deletions WitnessRandomizer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ Global
{CED79182-F36B-4D07-AD0E-249C15BFAD73}.Release|x86.ActiveCfg = Release|Win32
{CED79182-F36B-4D07-AD0E-249C15BFAD73}.Release|x86.Build.0 = Release|Win32
{90113AEC-8765-4A8D-B7A1-6C9BE730E5D5}.Debug|x64.ActiveCfg = Debug
{90113AEC-8765-4A8D-B7A1-6C9BE730E5D5}.Debug|x64.Build.0 = Debug
{90113AEC-8765-4A8D-B7A1-6C9BE730E5D5}.Debug|x86.ActiveCfg = Release
{90113AEC-8765-4A8D-B7A1-6C9BE730E5D5}.Release|x64.ActiveCfg = Release
{90113AEC-8765-4A8D-B7A1-6C9BE730E5D5}.Release|x64.Build.0 = Release
{90113AEC-8765-4A8D-B7A1-6C9BE730E5D5}.Release|x86.ActiveCfg = Release
{98BC35B9-EE1A-4D77-85F2-ADAA72DB16F7}.Debug|x64.ActiveCfg = Debug|x64
{98BC35B9-EE1A-4D77-85F2-ADAA72DB16F7}.Debug|x64.Build.0 = Debug|x64
Expand Down

0 comments on commit 3557f0b

Please sign in to comment.