From 9503fc300e1c2d9fcddcf5b8ecc009cd4429337a Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Fri, 26 Oct 2018 21:09:12 -0700 Subject: Change offsets to #defines, support new version --- WitnessRandomizer/Memory.cpp | 6 +- WitnessRandomizer/WitnessRandomizer.cpp | 153 ++++++++++++++++---------------- WitnessRandomizer/WitnessRandomizer.h | 134 ++++++++++++++++++++++++++-- 3 files changed, 209 insertions(+), 84 deletions(-) (limited to 'WitnessRandomizer') diff --git a/WitnessRandomizer/Memory.cpp b/WitnessRandomizer/Memory.cpp index 8ad5452..92a5136 100644 --- a/WitnessRandomizer/Memory.cpp +++ b/WitnessRandomizer/Memory.cpp @@ -18,7 +18,7 @@ Memory::Memory(const std::string& processName) { } } if (!_handle) { - OutputDebugStringA("Process is not open!\n"); + std::cout << "Couldn't find " << processName.c_str() << ", is it open?" << std::endl; exit(EXIT_FAILURE); } @@ -38,7 +38,7 @@ Memory::Memory(const std::string& processName) { } } if (_baseAddress == 0) { - OutputDebugStringA("Couldn't find base address!\n"); + std::cout << "Couldn't find the base process address!" << std::endl; exit(EXIT_FAILURE); } } @@ -52,7 +52,7 @@ Memory::~Memory() { void Memory::ThrowError() { std::string message(256, '\0'); FormatMessageA(4096, NULL, GetLastError(), 1024, &message[0], static_cast(message.length()), NULL); - OutputDebugStringA(message.c_str()); + std::cout << message.c_str() << std::endl; exit(EXIT_FAILURE); } diff --git a/WitnessRandomizer/WitnessRandomizer.cpp b/WitnessRandomizer/WitnessRandomizer.cpp index fcce107..dacb8fe 100644 --- a/WitnessRandomizer/WitnessRandomizer.cpp +++ b/WitnessRandomizer/WitnessRandomizer.cpp @@ -30,12 +30,11 @@ int main(int argc, char** argv) if (argc == 2) { srand(atoi(argv[1])); // Seed with RNG from command line } else { - int seed = rand() % 1 << 16; - std::cout << "Selected seed:" << seed << std::endl; + int seed = rand() % (1 << 16); + std::cout << "Selected seed: " << seed << std::endl; srand(seed); } - // Content swaps -- must happen before squarePanels randomizer.Randomize(upDownPanels, SWAP_LINES | SWAP_STYLE); randomizer.Randomize(leftForwardRightPanels, SWAP_LINES); @@ -48,8 +47,8 @@ int main(int argc, char** argv) // Target swaps, can happen whenever randomizer.Randomize(lasers, SWAP_TARGETS); // Read the target of keep front laser, and write it to keep back laser. - std::vector keepFrontLaserTarget = randomizer.ReadPanelData(0x0360E, 0x2BC, 1); - randomizer.WritePanelData(0x03317, 0x2BC, keepFrontLaserTarget); + std::vector keepFrontLaserTarget = randomizer.ReadPanelData(0x0360E, TARGET, 1); + randomizer.WritePanelData(0x03317, TARGET, keepFrontLaserTarget); std::vector randomOrder = std::vector(junglePanels.size(), 0); std::iota(randomOrder.begin(), randomOrder.end(), 0); @@ -79,30 +78,30 @@ int main(int argc, char** argv) randomizer.ReassignTargets(shadowsPanels, randomOrder); // Turn off original starting panel - randomizer.WritePanelData(shadowsPanels[0], 0x2A8, {0.0f, 0.0f}); + randomizer.WritePanelData(shadowsPanels[0], POWER, {0.0f, 0.0f}); // Turn on new starting panel - randomizer.WritePanelData(shadowsPanels[randomOrder[0]], 0x2A8, {1.0f, 1.0f}); + randomizer.WritePanelData(shadowsPanels[randomOrder[0]], POWER, {1.0f, 1.0f}); } -WitnessRandomizer::WitnessRandomizer() : _memory("witness64_d3d11.exe") +WitnessRandomizer::WitnessRandomizer() { // Turn off desert flood final - WritePanelData(0x18076, 0x2A8, {0.0f, 0.0f}); + WritePanelData(0x18076, POWER, {0.0f, 0.0f}); // Change desert floating target to desert flood final - WritePanelData(0x17ECA, 0x2BC, {0x18077}); + WritePanelData(0x17ECA, TARGET, {0x18077}); // Distance-gate shadows laser to prevent sniping through the bars - WritePanelData(0x19650, 0x3C0, {2.5f}); + WritePanelData(0x19650, MAX_BROADCAST_DISTANCE, {2.5f}); // Change the shadows tutorial cable to only activate avoid WritePanelData(0x319A8, 0xD8, {0}); // Change shadows avoid 8 to power shadows follow - WritePanelData(0x1972F, 0x2BC, {0x1C34C}); + WritePanelData(0x1972F, TARGET, {0x1C34C}); // Disable tutorial cursor speed modifications - WritePanelData(0x00295, 0x358, {1.0}); - WritePanelData(0x0C373, 0x358, {1.0}); - WritePanelData(0x00293, 0x358, {1.0}); - WritePanelData(0x002C2, 0x358, {1.0}); + WritePanelData(0x00295, CURSOR_SPEED_SCALE, {1.0}); + WritePanelData(0x0C373, CURSOR_SPEED_SCALE, {1.0}); + WritePanelData(0x00293, CURSOR_SPEED_SCALE, {1.0}); + WritePanelData(0x002C2, CURSOR_SPEED_SCALE, {1.0}); } void WitnessRandomizer::Randomize(std::vector &panels, int flags) { @@ -128,78 +127,80 @@ void WitnessRandomizer::SwapPanels(int panel1, int panel2, int flags) { std::map offsets; if (flags & SWAP_TARGETS) { - offsets[0x2BC] = sizeof(int); + offsets[TARGET] = sizeof(int); } if (flags & SWAP_STYLE) { - offsets[0x450] = sizeof(int); // style_flags + offsets[STYLE_FLAGS] = sizeof(int); } if (flags & SWAP_LINES) { - offsets[0xC8] = 16; // path_color - offsets[0xD8] = 16; // reflection_path_color - offsets[0xF8] = 16; // dot_color - offsets[0x108] = 16; // active_color - offsets[0x118] = 16; // background_region_color - offsets[0x128] = 16; // success_color_a - offsets[0x138] = 16; // success_color_b - offsets[0x148] = 16; // strobe_color_a - offsets[0x158] = 16; // strobe_color_b - offsets[0x168] = 16; // error_color - offsets[0x188] = 16; // pattern_point_color - offsets[0x198] = 16; // pattern_point_color_a - offsets[0x1A8] = 16; // pattern_point_color_b - offsets[0x1B8] = 16; // symbol_a - offsets[0x1C8] = 16; // symbol_b - offsets[0x1D8] = 16; // symbol_c - offsets[0x1E8] = 16; // symbol_d - offsets[0x1F8] = 16; // symbol_e - offsets[0x208] = sizeof(int); // push_symbol_colors - offsets[0x20C] = 16; // outer_background - offsets[0x21C] = sizeof(int); // outer_background_mode - offsets[0x230] = 16; // traced_edges - offsets[0x278] = sizeof(void*); // *audio_prefix - offsets[0x2FC] = sizeof(int); // is_cylinder - offsets[0x300] = sizeof(float); // cylinder_z0 - offsets[0x304] = sizeof(float); // cylinder_z1 - offsets[0x308] = sizeof(float); // cylinder_radius - offsets[0x398] = sizeof(float); // specular_add - offsets[0x39C] = sizeof(int); // specular_power - offsets[0x3A4] = sizeof(float); // path_width_scale - offsets[0x3A8] = sizeof(float); // startpoint_scale - offsets[0x3B8] = sizeof(int); // num_dots - offsets[0x3BC] = sizeof(int); // num_connections - offsets[0x3C8] = sizeof(void*); // *dot_positions - offsets[0x3D0] = sizeof(void*); // *dot_flags - offsets[0x3D8] = sizeof(void*); // *dot_connection_a - offsets[0x3E0] = sizeof(void*); // *dot_connection_b - offsets[0x420] = sizeof(void*); // *decorations - offsets[0x428] = sizeof(void*); // *decoration_flags - offsets[0x430] = sizeof(void*); // *decoration_colors - offsets[0x438] = sizeof(int); // num_decorations - offsets[0x440] = sizeof(void*); // *reflection_data - offsets[0x448] = sizeof(int); // grid_size_x - offsets[0x44C] = sizeof(int); // grid_size_y - offsets[0x45C] = sizeof(int); // sequence_len - offsets[0x460] = sizeof(void*); // *sequence - offsets[0x468] = sizeof(int); // dot_sequence_len - offsets[0x470] = sizeof(void*); // *dot_sequence - offsets[0x478] = sizeof(int); // dot_sequence_len_reflection - offsets[0x480] = sizeof(void*); // *dot_sequence_reflection - offsets[0x4A0] = sizeof(int); // num_colored_regions - offsets[0x4A8] = sizeof(void*); // *colored_regions - offsets[0x4B0] = sizeof(void*); // *panel_target - offsets[0x4D8] = sizeof(void*); // *specular_texture + offsets[PATH_COLOR] = 16; + offsets[REFLECTION_PATH_COLOR] = 16; + offsets[DOT_COLOR] = 16; + offsets[ACTIVE_COLOR] = 16; + offsets[BACKGROUND_REGION_COLOR] = 16; + offsets[SUCCESS_COLOR_A] = 16; + offsets[SUCCESS_COLOR_B] = 16; + offsets[STROBE_COLOR_A] = 16; + offsets[STROBE_COLOR_B] = 16; + offsets[ERROR_COLOR] = 16; + offsets[PATTERN_POINT_COLOR] = 16; + offsets[PATTERN_POINT_COLOR_A] = 16; + offsets[PATTERN_POINT_COLOR_B] = 16; + offsets[SYMBOL_A] = 16; + offsets[SYMBOL_B] = 16; + offsets[SYMBOL_C] = 16; + offsets[SYMBOL_D] = 16; + offsets[SYMBOL_E] = 16; + offsets[PUSH_SYMBOL_COLORS] = sizeof(int); + offsets[OUTER_BACKGROUND] = 16; + offsets[OUTER_BACKGROUND_MODE] = sizeof(int); + offsets[TRACED_EDGES] = 16; + offsets[AUDIO_PREFIX] = sizeof(void*); +// offsets[IS_CYLINDER] = sizeof(int); +// offsets[CYLINDER_Z0] = sizeof(float); +// offsets[CYLINDER_Z1] = sizeof(float); +// offsets[CYLINDER_RADIUS] = sizeof(float); + offsets[SPECULAR_ADD] = sizeof(float); + offsets[SPECULAR_POWER] = sizeof(int); + offsets[PATH_WIDTH_SCALE] = sizeof(float); + offsets[STARTPOINT_SCALE] = sizeof(float); + offsets[NUM_DOTS] = sizeof(int); + offsets[NUM_CONNECTIONS] = sizeof(int); + offsets[DOT_POSITIONS] = sizeof(void*); + offsets[DOT_FLAGS] = sizeof(void*); + offsets[DOT_CONNECTION_A] = sizeof(void*); + offsets[DOT_CONNECTION_B] = sizeof(void*); + offsets[DECORATIONS] = sizeof(void*); + offsets[DECORATION_FLAGS] = sizeof(void*); + offsets[DECORATION_COLORS] = sizeof(void*); + offsets[NUM_DECORATIONS] = sizeof(int); + offsets[REFLECTION_DATA] = sizeof(void*); + offsets[GRID_SIZE_X] = sizeof(int); + offsets[GRID_SIZE_Y] = sizeof(int); + offsets[SEQUENCE_LEN] = sizeof(int); + offsets[SEQUENCE] = sizeof(void*); + offsets[DOT_SEQUENCE_LEN] = sizeof(int); + offsets[DOT_SEQUENCE] = sizeof(void*); + offsets[DOT_SEQUENCE_LEN_REFLECTION] = sizeof(int); + offsets[DOT_SEQUENCE_REFLECTION] = sizeof(void*); + offsets[NUM_COLORED_REGIONS] = sizeof(int); + offsets[COLORED_REGIONS] = sizeof(void*); + offsets[PANEL_TARGET] = sizeof(void*); + offsets[SPECULAR_TEXTURE] = sizeof(void*); } for (auto const& [offset, size] : offsets) { - std::vector data = ReadPanelData(panel1, offset, size); - WritePanelData(panel2, offset, data); + std::vector panel1data = ReadPanelData(panel1, offset, size); + std::vector panel2data = ReadPanelData(panel2, offset, size); + WritePanelData(panel2, offset, panel1data); + WritePanelData(panel1, offset, panel2data); } } void WitnessRandomizer::ReassignTargets(const std::vector& panels, const std::vector& order) { std::vector targetToActivatePanel = {panels[0] + 1}; for (int panel : panels) { - int target = ReadPanelData(panel, 0x2BC, 1)[0]; + int target = ReadPanelData(panel, TARGET, 1)[0]; targetToActivatePanel.push_back(target); } @@ -208,6 +209,6 @@ void WitnessRandomizer::ReassignTargets(const std::vector& panels, const st // order[i+1] - 1 is the (real) panel before the target panel // targets[order[i+1] - 1] is the (real) target which will activate the target panel int panelTarget = targetToActivatePanel[order[i+1]]; - WritePanelData(panels[order[i]], 0x2BC, {panelTarget}); + WritePanelData(panels[order[i]], TARGET, {panelTarget}); } } diff --git a/WitnessRandomizer/WitnessRandomizer.h b/WitnessRandomizer/WitnessRandomizer.h index a824fba..0e88cee 100644 --- a/WitnessRandomizer/WitnessRandomizer.h +++ b/WitnessRandomizer/WitnessRandomizer.h @@ -1,5 +1,8 @@ #pragma once +//#define GLOBALS 0x5B28C0 +#define GLOBALS 0x62A080 + int SWAP_NONE = 0x0; int SWAP_TARGETS = 0x1; int SWAP_LINES = 0x2; @@ -16,15 +19,136 @@ public: template std::vector ReadPanelData(int panel, int offset, int size) { - return _memory.ReadData({_globals, 0x18, panel*8, offset}, size); + return _memory.ReadData({GLOBALS, 0x18, panel*8, offset}, size); } template void WritePanelData(int panel, int offset, const std::vector& data) { - _memory.WriteData({_globals, 0x18, panel*8, offset}, data); + _memory.WriteData({GLOBALS, 0x18, panel*8, offset}, data); } private: - Memory _memory; - int _globals = 0x5B28C0; -}; \ No newline at end of file + Memory _memory = Memory("witness64_d3d11.exe"); +}; + +#if GLOBALS == 0x5B28C0 +#define PATH_COLOR 0xC8 +#define REFLECTION_PATH_COLOR 0xD8 +#define DOT_COLOR 0xF8 +#define ACTIVE_COLOR 0x108 +#define BACKGROUND_REGION_COLOR 0x118 +#define SUCCESS_COLOR_A 0x128 +#define SUCCESS_COLOR_B 0x138 +#define STROBE_COLOR_A 0x148 +#define STROBE_COLOR_B 0x158 +#define ERROR_COLOR 0x168 +#define PATTERN_POINT_COLOR 0x188 +#define PATTERN_POINT_COLOR_A 0x198 +#define PATTERN_POINT_COLOR_B 0x1A8 +#define SYMBOL_A 0x1B8 +#define SYMBOL_B 0x1C8 +#define SYMBOL_C 0x1D8 +#define SYMBOL_D 0x1E8 +#define SYMBOL_E 0x1F8 +#define PUSH_SYMBOL_COLORS 0x208 +#define OUTER_BACKGROUND 0x20C +#define OUTER_BACKGROUND_MODE 0x21C +#define TRACED_EDGES 0x230 +#define AUDIO_PREFIX 0x278 +#define POWER 0x2A8 +#define TARGET 0x2BC +#define IS_CYLINDER 0x2FC +#define CYLINDER_Z0 0x300 +#define CYLINDER_Z1 0x304 +#define CYLINDER_RADIUS 0x308 +#define CURSOR_SPEED_SCALE 0x358 +#define SPECULAR_ADD 0x398 +#define SPECULAR_POWER 0x39C +#define PATH_WIDTH_SCALE 0x3A4 +#define STARTPOINT_SCALE 0x3A8 +#define NUM_DOTS 0x3B8 +#define NUM_CONNECTIONS 0x3BC +#define MAX_BROADCAST_DISTANCE 0x3C0 +#define DOT_POSITIONS 0x3C8 +#define DOT_FLAGS 0x3D0 +#define DOT_CONNECTION_A 0x3D8 +#define DOT_CONNECTION_B 0x3E0 +#define DECORATIONS 0x420 +#define DECORATION_FLAGS 0x428 +#define DECORATION_COLORS 0x430 +#define NUM_DECORATIONS 0x438 +#define REFLECTION_DATA 0x440 +#define GRID_SIZE_X 0x448 +#define GRID_SIZE_Y 0x44C +#define STYLE_FLAGS 0x450 +#define SEQUENCE_LEN 0x45C +#define SEQUENCE 0x460 +#define DOT_SEQUENCE_LEN 0x468 +#define DOT_SEQUENCE 0x470 +#define DOT_SEQUENCE_LEN_REFLECTION 0x478 +#define DOT_SEQUENCE_REFLECTION 0x480 +#define NUM_COLORED_REGIONS 0x4A0 +#define COLORED_REGIONS 0x4A8 +#define PANEL_TARGET 0x4B0 +#define SPECULAR_TEXTURE 0x4D8 +#elif GLOBALS == 0x62A080 +#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 0x200 +#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 AUDIO_PREFIX 0x270 +#define POWER 0x2A0 +#define TARGET 0x2B4 +#define IS_CYLINDER 0x2F4 +#define CYLINDER_Z0 0x2F8 +#define CYLINDER_Z1 0x2FC +#define CYLINDER_RADIUS 0x300 +#define CURSOR_SPEED_SCALE 0x350 +#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 +#endif \ No newline at end of file -- cgit 1.4.1