From b4328af638852e57ff2d75836266d887700bee1e Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 21 Aug 2021 23:29:29 -0400 Subject: Backported some of sigma's stuff --- App/Main.cpp | 58 +++++++++++++++ Source/Memory.cpp | 167 +++----------------------------------------- Source/Memory.h | 17 ++++- Source/PuzzleSerializer.cpp | 1 + Source/Randomizer.cpp | 6 +- Source/Randomizer.h | 68 ++++++++++++++++++ 6 files changed, 156 insertions(+), 161 deletions(-) diff --git a/App/Main.cpp b/App/Main.cpp index f0f770a..54d876d 100644 --- a/App/Main.cpp +++ b/App/Main.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include "Richedit.h" #include "Version.h" +#include #include "Memory.h" #include "Random.h" @@ -124,6 +125,29 @@ HWND CreateCheckbox(int x, int y, int message) { } #pragma warning(pop) +int findGlobals() { + int address = 0; + for (int i = 0x620000; i < 0x660000; i += 4) { + Memory::GLOBALS = i; + try { + if ((address = g_witnessProc->ReadPanelData(0x17E52, STYLE_FLAGS, 1)[0]) == 0x0000A040) { + return i; + } + } + catch (std::exception) {} + } + for (int i = 0x600000; i < 0x620000; i += 4) { + Memory::GLOBALS = i; + try { + if ((address = g_witnessProc->ReadPanelData(0x17E52, STYLE_FLAGS, 1)[0]) == 0x0000A040) { + return i; + } + } + catch (std::exception) {} + } + return 0; +} + int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { LoadLibrary(L"Msftedit.dll"); WNDCLASSW wndClass = { @@ -140,6 +164,40 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance }; RegisterClassW(&wndClass); + //Initialize memory globals constant depending on game version + for (int g : Memory::globalsTests) { + try { + Memory::GLOBALS = g; + if (g_witnessProc->ReadPanelData(0x17E52, STYLE_FLAGS) != 0xA040) throw std::exception(); + break; + } + catch (std::exception) { Memory::GLOBALS = 0; } + } + if (!Memory::GLOBALS) { + std::ifstream file("globals.txt"); + if (file.is_open()) { + file >> std::hex >> Memory::GLOBALS; + } + else { + std::string str = "Globals ptr not found. Press OK to search for globals ptr. It will probably take around 5 minutes. This popup will close and the calculation will run in the background. Please keep The Witness open during this time."; + if (MessageBox(GetActiveWindow(), std::wstring(str.begin(), str.end()).c_str(), NULL, MB_OK) != IDOK) return 0; + int address = findGlobals(); + if (address) { + std::stringstream ss; ss << std::hex << "Address found: 0x" << address << ". This address wil be automatically loaded next time. Please post an issue on Github with this address so that it can be added in the future."; + std::string str = ss.str(); + MessageBox(GetActiveWindow(), std::wstring(str.begin(), str.end()).c_str(), NULL, MB_OK); + std::ofstream ofile("globals.txt", std::ofstream::app); + ofile << std::hex << address << std::endl; + } + else { + str = "Address could not be found. Please post an issue on the Github page."; + MessageBox(GetActiveWindow(), std::wstring(str.begin(), str.end()).c_str(), NULL, MB_OK); + return 0; + } + } + } + + g_hInstance = hInstance; RECT rect; diff --git a/Source/Memory.cpp b/Source/Memory.cpp index 4a4cb63..8e755dd 100644 --- a/Source/Memory.cpp +++ b/Source/Memory.cpp @@ -6,7 +6,7 @@ #undef PROCESSENTRY32 #undef Process32Next -Memory::Memory(const std::wstring& processName) : _processName(processName) {} +Memory::Memory(const std::wstring& processName) : _processName(processName) { Initialize(); } Memory::~Memory() { if (_threadActive) { @@ -33,7 +33,7 @@ void Memory::StartHeartbeat(HWND window, WPARAM wParam, std::chrono::millisecond } void Memory::Heartbeat(HWND window, WPARAM wParam) { - if (!_handle && !Initialize()) { + if (!_handle) { // Couldn't initialize, definitely not running PostMessage(window, WM_COMMAND, wParam, (LPARAM)ProcStatus::NotRunning); return; @@ -110,7 +110,8 @@ bool Memory::Initialize() { return false; } - LoadPanelOffsets(); + ExecuteSigScans(); + return true; } @@ -187,157 +188,9 @@ void* Memory::ComputeOffset(std::vector offsets) { return reinterpret_cast(cumulativeAddress + final_offset); } -int GLOBALS, POSITION, ORIENTATION, PATH_COLOR, REFLECTION_PATH_COLOR, DOT_COLOR, ACTIVE_COLOR, BACKGROUND_REGION_COLOR, SUCCESS_COLOR_A, SUCCESS_COLOR_B, STROBE_COLOR_A, STROBE_COLOR_B, ERROR_COLOR, PATTERN_POINT_COLOR, PATTERN_POINT_COLOR_A, PATTERN_POINT_COLOR_B, SYMBOL_A, SYMBOL_B, SYMBOL_C, SYMBOL_D, SYMBOL_E, PUSH_SYMBOL_COLORS, OUTER_BACKGROUND, OUTER_BACKGROUND_MODE, TRACED_EDGES, AUDIO_PREFIX, POWER, TARGET, POWER_OFF_ON_FAIL, IS_CYLINDER, CYLINDER_Z0, CYLINDER_Z1, CYLINDER_RADIUS, CURSOR_SPEED_SCALE, NEEDS_REDRAW, SPECULAR_ADD, SPECULAR_POWER, PATH_WIDTH_SCALE, STARTPOINT_SCALE, NUM_DOTS, NUM_CONNECTIONS, MAX_BROADCAST_DISTANCE, DOT_POSITIONS, DOT_FLAGS, DOT_CONNECTION_A, DOT_CONNECTION_B, DECORATIONS, DECORATION_FLAGS, DECORATION_COLORS, NUM_DECORATIONS, REFLECTION_DATA, GRID_SIZE_X, GRID_SIZE_Y, STYLE_FLAGS, SEQUENCE_LEN, SEQUENCE, DOT_SEQUENCE_LEN, DOT_SEQUENCE, DOT_SEQUENCE_LEN_REFLECTION, DOT_SEQUENCE_REFLECTION, NUM_COLORED_REGIONS, COLORED_REGIONS, PANEL_TARGET, SPECULAR_TEXTURE, CABLE_TARGET_2, AUDIO_LOG_NAME, OPEN_RATE, METADATA, HOTEL_EP_NAME; - -void Memory::LoadPanelOffsets() { - AddSigScan({0x74, 0x41, 0x48, 0x85, 0xC0, 0x74, 0x04, 0x48, 0x8B, 0x48, 0x10}, [sharedThis = shared_from_this()](int index){ - // (address of next line) + (value at index) - GLOBALS = index + 0x14 + 0x4 + sharedThis->ReadData({index+0x14}, 1)[0]; - }); - ExecuteSigScans(); - - if (GLOBALS == 0x5B28C0) { - POSITION = 0x24; - ORIENTATION = 0x34; - PATH_COLOR = 0xC8; - REFLECTION_PATH_COLOR = 0xD8; - DOT_COLOR = 0xF8; - ACTIVE_COLOR = 0x108; - BACKGROUND_REGION_COLOR = 0x118; - SUCCESS_COLOR_A = 0x128; - SUCCESS_COLOR_B = 0x138; - STROBE_COLOR_A = 0x148; - STROBE_COLOR_B = 0x158; - ERROR_COLOR = 0x168; - PATTERN_POINT_COLOR = 0x188; - PATTERN_POINT_COLOR_A = 0x198; - PATTERN_POINT_COLOR_B = 0x1A8; - SYMBOL_A = 0x1B8; - SYMBOL_B = 0x1C8; - SYMBOL_C = 0x1D8; - SYMBOL_D = 0x1E8; - SYMBOL_E = 0x1F8; - PUSH_SYMBOL_COLORS = 0x208; - OUTER_BACKGROUND = 0x20C; - OUTER_BACKGROUND_MODE = 0x21C; - TRACED_EDGES = 0x230; - AUDIO_PREFIX = 0x278; - POWER = 0x2A8; - TARGET = 0x2BC; - POWER_OFF_ON_FAIL = 0x2C0; - IS_CYLINDER = 0x2FC; - CYLINDER_Z0 = 0x300; - CYLINDER_Z1 = 0x304; - CYLINDER_RADIUS = 0x308; - CURSOR_SPEED_SCALE = 0x358; - NEEDS_REDRAW = 0x384; - SPECULAR_ADD = 0x398; - SPECULAR_POWER = 0x39C; - PATH_WIDTH_SCALE = 0x3A4; - STARTPOINT_SCALE = 0x3A8; - NUM_DOTS = 0x3B8; - NUM_CONNECTIONS = 0x3BC; - MAX_BROADCAST_DISTANCE = 0x3C0; - DOT_POSITIONS = 0x3C8; - DOT_FLAGS = 0x3D0; - DOT_CONNECTION_A = 0x3D8; - DOT_CONNECTION_B = 0x3E0; - DECORATIONS = 0x420; - DECORATION_FLAGS = 0x428; - DECORATION_COLORS = 0x430; - NUM_DECORATIONS = 0x438; - REFLECTION_DATA = 0x440; - GRID_SIZE_X = 0x448; - GRID_SIZE_Y = 0x44C; - STYLE_FLAGS = 0x450; - SEQUENCE_LEN = 0x45C; - SEQUENCE = 0x460; - DOT_SEQUENCE_LEN = 0x468; - DOT_SEQUENCE = 0x470; - DOT_SEQUENCE_LEN_REFLECTION = 0x478; - DOT_SEQUENCE_REFLECTION = 0x480; - NUM_COLORED_REGIONS = 0x4A0; - COLORED_REGIONS = 0x4A8; - PANEL_TARGET = 0x4B0; - SPECULAR_TEXTURE = 0x4D8; - CABLE_TARGET_2 = 0xD8; - AUDIO_LOG_NAME = 0xC8; - OPEN_RATE = 0xE8; - METADATA = 0xF2; // sizeof(short) - HOTEL_EP_NAME = 0x4BC640; - } else if (GLOBALS == 0x62B0A0) { - // TODO: - } else if (GLOBALS == 0x62D0A0) { - POSITION = 0x24; - ORIENTATION = 0x34; - PATH_COLOR = 0xC0; - REFLECTION_PATH_COLOR = 0xD0; - DOT_COLOR = 0xF0; - ACTIVE_COLOR = 0x100; - BACKGROUND_REGION_COLOR = 0x110; - SUCCESS_COLOR_A = 0x120; - SUCCESS_COLOR_B = 0x130; - STROBE_COLOR_A = 0x140; - STROBE_COLOR_B = 0x150; - ERROR_COLOR = 0x160; - PATTERN_POINT_COLOR = 0x180; - PATTERN_POINT_COLOR_A = 0x190; - PATTERN_POINT_COLOR_B = 0x1A0; - SYMBOL_A = 0x1B0; - SYMBOL_B = 0x1C0; - SYMBOL_C = 0x1D0; - SYMBOL_D = 0x1E0; - SYMBOL_E = 0x1F0; - PUSH_SYMBOL_COLORS = 0x200; - OUTER_BACKGROUND = 0x204; - OUTER_BACKGROUND_MODE = 0x214; - TRACED_EDGES = 0x228; - AUDIO_PREFIX = 0x270; - POWER = 0x2A0; - TARGET = 0x2B4; - POWER_OFF_ON_FAIL = 0x2B8; - IS_CYLINDER = 0x2F4; - CYLINDER_Z0 = 0x2F8; - CYLINDER_Z1 = 0x2FC; - CYLINDER_RADIUS = 0x300; - CURSOR_SPEED_SCALE = 0x350; - NEEDS_REDRAW = 0x37C; - SPECULAR_ADD = 0x38C; - SPECULAR_POWER = 0x390; - PATH_WIDTH_SCALE = 0x39C; - STARTPOINT_SCALE = 0x3A0; - NUM_DOTS = 0x3B4; - NUM_CONNECTIONS = 0x3B8; - MAX_BROADCAST_DISTANCE = 0x3BC; - DOT_POSITIONS = 0x3C0; - DOT_FLAGS = 0x3C8; - DOT_CONNECTION_A = 0x3D0; - DOT_CONNECTION_B = 0x3D8; - DECORATIONS = 0x418; - DECORATION_FLAGS = 0x420; - DECORATION_COLORS = 0x428; - NUM_DECORATIONS = 0x430; - REFLECTION_DATA = 0x438; - GRID_SIZE_X = 0x440; - GRID_SIZE_Y = 0x444; - STYLE_FLAGS = 0x448; - SEQUENCE_LEN = 0x454; - SEQUENCE = 0x458; - DOT_SEQUENCE_LEN = 0x460; - DOT_SEQUENCE = 0x468; - DOT_SEQUENCE_LEN_REFLECTION = 0x470; - DOT_SEQUENCE_REFLECTION = 0x478; - NUM_COLORED_REGIONS = 0x498; - COLORED_REGIONS = 0x4A0; - PANEL_TARGET = 0x4A8; - SPECULAR_TEXTURE = 0x4D0; - CABLE_TARGET_2 = 0xD0; - AUDIO_LOG_NAME = 0x0; - OPEN_RATE = 0xE0; - METADATA = 0x13A; // sizeof(short) - HOTEL_EP_NAME = 0x51E340; - } else { - assert(false); - return; - } -} \ No newline at end of file +int Memory::GLOBALS = 0; +int Memory::globalsTests[3] = { + 0x62D0A0, //Steam and Epic Games + 0x62B0A0, //Good Old Games + 0x5B28C0 //Noclip version +}; \ No newline at end of file diff --git a/Source/Memory.h b/Source/Memory.h index e924bb9..fc67b4f 100644 --- a/Source/Memory.h +++ b/Source/Memory.h @@ -1,6 +1,6 @@ #pragma once -extern int GLOBALS, POSITION, ORIENTATION, PATH_COLOR, REFLECTION_PATH_COLOR, DOT_COLOR, ACTIVE_COLOR, BACKGROUND_REGION_COLOR, SUCCESS_COLOR_A, SUCCESS_COLOR_B, STROBE_COLOR_A, STROBE_COLOR_B, ERROR_COLOR, PATTERN_POINT_COLOR, PATTERN_POINT_COLOR_A, PATTERN_POINT_COLOR_B, SYMBOL_A, SYMBOL_B, SYMBOL_C, SYMBOL_D, SYMBOL_E, PUSH_SYMBOL_COLORS, OUTER_BACKGROUND, OUTER_BACKGROUND_MODE, TRACED_EDGES, AUDIO_PREFIX, POWER, TARGET, POWER_OFF_ON_FAIL, IS_CYLINDER, CYLINDER_Z0, CYLINDER_Z1, CYLINDER_RADIUS, CURSOR_SPEED_SCALE, NEEDS_REDRAW, SPECULAR_ADD, SPECULAR_POWER, PATH_WIDTH_SCALE, STARTPOINT_SCALE, NUM_DOTS, NUM_CONNECTIONS, MAX_BROADCAST_DISTANCE, DOT_POSITIONS, DOT_FLAGS, DOT_CONNECTION_A, DOT_CONNECTION_B, DECORATIONS, DECORATION_FLAGS, DECORATION_COLORS, NUM_DECORATIONS, REFLECTION_DATA, GRID_SIZE_X, GRID_SIZE_Y, STYLE_FLAGS, SEQUENCE_LEN, SEQUENCE, DOT_SEQUENCE_LEN, DOT_SEQUENCE, DOT_SEQUENCE_LEN_REFLECTION, DOT_SEQUENCE_REFLECTION, NUM_COLORED_REGIONS, COLORED_REGIONS, PANEL_TARGET, SPECULAR_TEXTURE, CABLE_TARGET_2, AUDIO_LOG_NAME, OPEN_RATE, METADATA, HOTEL_EP_NAME; +//extern int GLOBALS, POSITION, ORIENTATION, PATH_COLOR, REFLECTION_PATH_COLOR, DOT_COLOR, ACTIVE_COLOR, BACKGROUND_REGION_COLOR, SUCCESS_COLOR_A, SUCCESS_COLOR_B, STROBE_COLOR_A, STROBE_COLOR_B, ERROR_COLOR, PATTERN_POINT_COLOR, PATTERN_POINT_COLOR_A, PATTERN_POINT_COLOR_B, SYMBOL_A, SYMBOL_B, SYMBOL_C, SYMBOL_D, SYMBOL_E, PUSH_SYMBOL_COLORS, OUTER_BACKGROUND, OUTER_BACKGROUND_MODE, TRACED_EDGES, AUDIO_PREFIX, POWER, TARGET, POWER_OFF_ON_FAIL, IS_CYLINDER, CYLINDER_Z0, CYLINDER_Z1, CYLINDER_RADIUS, CURSOR_SPEED_SCALE, NEEDS_REDRAW, SPECULAR_ADD, SPECULAR_POWER, PATH_WIDTH_SCALE, STARTPOINT_SCALE, NUM_DOTS, NUM_CONNECTIONS, MAX_BROADCAST_DISTANCE, DOT_POSITIONS, DOT_FLAGS, DOT_CONNECTION_A, DOT_CONNECTION_B, DECORATIONS, DECORATION_FLAGS, DECORATION_COLORS, NUM_DECORATIONS, REFLECTION_DATA, GRID_SIZE_X, GRID_SIZE_Y, STYLE_FLAGS, SEQUENCE_LEN, SEQUENCE, DOT_SEQUENCE_LEN, DOT_SEQUENCE, DOT_SEQUENCE_LEN_REFLECTION, DOT_SEQUENCE_REFLECTION, NUM_COLORED_REGIONS, COLORED_REGIONS, PANEL_TARGET, SPECULAR_TEXTURE, CABLE_TARGET_2, AUDIO_LOG_NAME, OPEN_RATE, METADATA, HOTEL_EP_NAME; enum class ProcStatus { NotRunning, @@ -80,6 +80,20 @@ public: WriteData({ GLOBALS, 0x18, panel * 8, offset }, data); } + template + T ReadPanelData(int panel, int offset) { + return ReadData({ GLOBALS, 0x18, panel * 8, offset }, 1)[0]; + } + + template + std::vector ReadPanelData(int panel, int offset, size_t size) { + if (size == 0) return std::vector(); + return ReadData({ GLOBALS, 0x18, panel * 8, offset }, size); + } + + static int GLOBALS; + static int globalsTests[3]; + private: template std::vector ReadData(const std::vector& offsets, size_t numItems) { @@ -103,7 +117,6 @@ private: void Heartbeat(HWND window, WPARAM wParam); bool Initialize(); void* ComputeOffset(std::vector offsets); - void LoadPanelOffsets(); int _previousFrame = 0; bool _threadActive = false; diff --git a/Source/PuzzleSerializer.cpp b/Source/PuzzleSerializer.cpp index e316216..4a57313 100644 --- a/Source/PuzzleSerializer.cpp +++ b/Source/PuzzleSerializer.cpp @@ -1,5 +1,6 @@ #include "pch.h" #include "PuzzleSerializer.h" +#include "Randomizer.h" PuzzleSerializer::PuzzleSerializer(const std::shared_ptr& memory) : _memory(memory) {} diff --git a/Source/Randomizer.cpp b/Source/Randomizer.cpp index 5239cd6..8ded06e 100644 --- a/Source/Randomizer.cpp +++ b/Source/Randomizer.cpp @@ -116,14 +116,16 @@ void Randomizer::Randomize() { // begin_endgame_1 - Prevent actually ending the game (Wonkavator) _memory->AddSigScan({0x83, 0x7C, 0x01, 0xD0, 0x04}, [&](int index){ - if (GLOBALS == 0x5B28C0) { // Version differences. + if (Memory::GLOBALS == 0x5B28C0) { // Version differences. index += 0x75; - } else if (GLOBALS == 0x62D0A0) { + } else if (Memory::GLOBALS == 0x62D0A0) { index += 0x86; } _memory->WriteData({index}, {0xEB}); // jz -> jmp }); + //Tutorialise(0x33AF5, 0x0A3B2); + // Tutorial Bend for (int panel : utmPerspective) { Tutorialise(panel, 0x00182); diff --git a/Source/Randomizer.h b/Source/Randomizer.h index a26acab..4058280 100644 --- a/Source/Randomizer.h +++ b/Source/Randomizer.h @@ -14,3 +14,71 @@ private: friend class SwapTests_Shipwreck_Test; }; + +#define PATH_COLOR 0xC0 +#define REFLECTION_PATH_COLOR 0xD0 +#define DOT_COLOR 0xF0 +#define ACTIVE_COLOR 0x100 +#define BACKGROUND_REGION_COLOR 0x110 +#define SUCCESS_COLOR_A 0x120 +#define SUCCESS_COLOR_B 0x130 +#define STROBE_COLOR_A 0x140 +#define STROBE_COLOR_B 0x150 +#define ERROR_COLOR 0x160 +#define PATTERN_POINT_COLOR 0x180 +#define PATTERN_POINT_COLOR_A 0x190 +#define PATTERN_POINT_COLOR_B 0x1A0 +#define SYMBOL_A 0x1B0 +#define SYMBOL_B 0x1C0 +#define SYMBOL_C 0x1D0 +#define SYMBOL_D 0x1E0 +#define SYMBOL_E 0x1F0 +#define PUSH_SYMBOL_COLORS 0x200 +#define OUTER_BACKGROUND 0x204 +#define OUTER_BACKGROUND_MODE 0x214 +#define TRACED_EDGES 0x228 +#define TRACED_EDGE_DATA 0x230 +#define AUDIO_PREFIX 0x270 +#define POWER 0x2A0 +#define TARGET 0x2B4 +#define POWER_OFF_ON_FAIL 0x2B8 +#define IS_CYLINDER 0x2F4 +#define CYLINDER_Z0 0x2F8 +#define CYLINDER_Z1 0x2FC +#define CYLINDER_RADIUS 0x300 +#define CURSOR_SPEED_SCALE 0x350 +#define NEEDS_REDRAW 0x37C +#define SPECULAR_ADD 0x38C +#define SPECULAR_POWER 0x390 +#define PATH_WIDTH_SCALE 0x39C +#define STARTPOINT_SCALE 0x3A0 +#define NUM_DOTS 0x3B4 +#define NUM_CONNECTIONS 0x3B8 +#define MAX_BROADCAST_DISTANCE 0x3BC +#define DOT_POSITIONS 0x3C0 +#define DOT_FLAGS 0x3C8 +#define DOT_CONNECTION_A 0x3D0 +#define DOT_CONNECTION_B 0x3D8 +#define DECORATIONS 0x418 +#define DECORATION_FLAGS 0x420 +#define DECORATION_COLORS 0x428 +#define NUM_DECORATIONS 0x430 +#define REFLECTION_DATA 0x438 +#define GRID_SIZE_X 0x440 +#define GRID_SIZE_Y 0x444 +#define STYLE_FLAGS 0x448 +#define SEQUENCE_LEN 0x454 +#define SEQUENCE 0x458 +#define DOT_SEQUENCE_LEN 0x460 +#define DOT_SEQUENCE 0x468 +#define DOT_SEQUENCE_LEN_REFLECTION 0x470 +#define DOT_SEQUENCE_REFLECTION 0x478 +#define NUM_COLORED_REGIONS 0x498 +#define COLORED_REGIONS 0x4A0 +#define PANEL_TARGET 0x4A8 +#define SPECULAR_TEXTURE 0x4D0 +#define CABLE_TARGET_2 0xD0 +#define AUDIO_LOG_NAME 0x0 +#define OPEN_RATE 0xE0 +#define METADATA 0x13A // sizeof(short) +#define HOTEL_EP_NAME 0x51E340 -- cgit 1.4.1