From 616fb965878997e4225afa651c5a4206a504fb61 Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Thu, 7 Nov 2019 10:15:29 -0800 Subject: Design for new version -- will still have to do conversions. --- Source/Memory.h | 4 +- Source/Panel.cpp | 16 +-- Source/Panel.h | 323 +++++++++++++++++++++++++++++--------------------- Source/Source.vcxproj | 3 + 4 files changed, 195 insertions(+), 151 deletions(-) (limited to 'Source') diff --git a/Source/Memory.h b/Source/Memory.h index c19d92b..6e0c7b1 100644 --- a/Source/Memory.h +++ b/Source/Memory.h @@ -5,8 +5,8 @@ #include #include -// #define GLOBALS 0x5B28C0 -#define GLOBALS 0x62D0A0 +#define GLOBALS 0x5B28C0 +// #define GLOBALS 0x62D0A0 #define HEARTBEAT 0x401 enum class ProcStatus { diff --git a/Source/Panel.cpp b/Source/Panel.cpp index c0fb7ec..ea65142 100644 --- a/Source/Panel.cpp +++ b/Source/Panel.cpp @@ -12,8 +12,7 @@ int find(const std::vector &data, T search, size_t startIndex = 0) { return -1; } -Panel::Panel(int id) { - _memory = std::make_shared("witness64_d3d11.exe"); +Panel::Panel(const std::shared_ptr& memory, int id) : _memory(memory) { _width = 2 * _memory->ReadPanelData(id, GRID_SIZE_X, 1)[0] - 1; _height = 2 * _memory->ReadPanelData(id, GRID_SIZE_Y, 1)[0] - 1; _grid.resize(_width); @@ -45,7 +44,7 @@ nlohmann::json Panel::Serialize() { for (int x=0; x<_width; x++) { for (int y=0; y<_height; y++) { if (x%2 == 1 && y%2 == 1) { - puzzle["grid"][x][y] = Decoration::to_json(_grid[x][y]); + puzzle["grid"][x][y] = Decoration_to_json(_grid[x][y]); } else { if (_grid[x][y] & IntersectionFlags::HAS_DOT) { puzzle["dots"].emplace_back(nlohmann::json({{"x", x}, {"y", y}})); @@ -69,17 +68,6 @@ nlohmann::json Panel::Serialize() { return puzzle; } -void Panel::Random() { -/* - for (auto& row : _decorations) { - for (auto& cell : row) { - cell.SetShape(cell.GetShape() & 0xFFFFFFF0); - cell.SetShape(cell.GetShape() | Random::RandInt(1, 10)); - } - } -*/ -} - void Panel::ReadDecorations(int id) { int numDecorations = _memory->ReadPanelData(id, NUM_DECORATIONS, 1)[0]; std::vector decorations = _memory->ReadArray(id, DECORATIONS, numDecorations); diff --git a/Source/Panel.h b/Source/Panel.h index 1f2b8c6..0d1af14 100644 --- a/Source/Panel.h +++ b/Source/Panel.h @@ -2,166 +2,219 @@ #include "json.hpp" #include "Memory.h" -class Decoration -{ -public: - enum Shape { - Stone = 0x100, - Star = 0x200, - Poly = 0x400, - Eraser = 0x500, - Triangle = 0x600, - }; - enum Color { - Black = 0x1, - White = 0x2, - Red = 0x3, - Blue = 0x4, - Green = 0x5, - }; - - static nlohmann::json to_json(int decoration) { - nlohmann::json json = {}; - int shape = decoration & 0x00000F00; - if (shape == Shape::Stone) json["type"] = "square"; - if (shape == Shape::Star) json["type"] = "star"; - if (shape == Shape::Poly) json["type"] = "poly"; - if (shape == Shape::Eraser) json["type"] = "eraser"; - if (shape == Shape::Triangle) json["type"] = "triangle"; - - int color = decoration & 0x0000000F; - if (color == Color::Black) json["color"] = "black"; - if (color == Color::White) json["color"] = "white"; - if (color == Color::Red) json["color"] = "red"; - if (color == Color::Blue) json["color"] = "blue"; - if (color == Color::Green) json["color"] = "green"; - - if (json.empty()) return false; - return json; - } -}; - enum IntersectionFlags { - IS_ENDPOINT = 0x1, - IS_STARTPOINT = 0x2, - IS_GAP = 0x10000, - HAS_DOT = 0x40020, - DOT_IS_BLUE = 0x100, - DOT_IS_ORANGE = 0x200, - DOT_IS_INVISIBLE = 0x1000, + IS_ENDPOINT = 0x1, + IS_STARTPOINT = 0x2, + IS_GAP = 0x10000, + HAS_DOT = 0x40020, + DOT_IS_BLUE = 0x100, + DOT_IS_ORANGE = 0x200, + DOT_IS_INVISIBLE = 0x1000, }; +/* + enum Style { + SYMMETRICAL = 0x2, + IS_2COLOR = 0x10, + HAS_DOTS = 0x4, + HAS_STARS = 0x40, + HAS_STONES = 0x100, + HAS_ERASERS = 0x1000, + HAS_SHAPERS = 0x2000, + }; +*/ + class Endpoint { public: - enum class Direction { - LEFT, - RIGHT, - UP, - DOWN - }; - - Endpoint(int x, int y, Direction dir) { - _x = x; - _y = y; - _dir = dir; - } - - int GetX() {return _x;} - void SetX(int x) {_x = x;} - int GetY() {return _y;} - void SetY(int y) {_y = y;} - Direction GetDir() {return _dir;} - void SetDir(Direction dir) {_dir = dir;} - - nlohmann::json to_json() { - nlohmann::json json = {{"x", _x}, {"y", _y}}; - if (_dir == LEFT) json["dir"] = "left"; - if (_dir == RIGHT) json["dir"] = "right"; - if (_dir == UP) json["dir"] = "up"; - if (_dir == DOWN) json["dir"] = "down"; - return json; - } + enum class Direction { + LEFT, + RIGHT, + UP, + DOWN + }; + + Endpoint(int x, int y, Direction dir) { + _x = x; + _y = y; + _dir = dir; + } + + int GetX() {return _x;} + void SetX(int x) {_x = x;} + int GetY() {return _y;} + void SetY(int y) {_y = y;} + Direction GetDir() {return _dir;} + void SetDir(Direction dir) {_dir = dir;} + + nlohmann::json to_json() { + nlohmann::json json = {{"x", _x}, {"y", _y}}; + if (_dir == Direction::LEFT) json["dir"] = "left"; + if (_dir == Direction::RIGHT) json["dir"] = "right"; + if (_dir == Direction::UP) json["dir"] = "up"; + if (_dir == Direction::DOWN) json["dir"] = "down"; + return json; + } private: - int _x, _y; - Direction _dir; + int _x, _y; + Direction _dir; }; -class Panel -{ +class Panel { public: - Panel(int id); - // explicit Panel(nlohmann::json json); + Panel(const std::shared_ptr& memory, int id); + // explicit Panel(nlohmann::json json); - void Write(int id); - nlohmann::json Serialize(); + void Write(int id); + nlohmann::json Serialize(); - void Random(); +private: + // For testing + Panel() = default; - enum Style { - SYMMETRICAL = 0x2, - IS_2COLOR = 0x10, - HAS_DOTS = 0x4, - HAS_STARS = 0x40, - HAS_STONES = 0x100, - HAS_ERASERS = 0x1000, - HAS_SHAPERS = 0x2000, - }; + void ReadIntersections(int id); + void WriteIntersections(int id); + void ReadDecorations(int id); + void WriteDecorations(int id); -private: - // For testing - Panel() = default; + // TODO: Reflection data + // TODO: Decoration colors + + std::tuple loc_to_xy(int location) { + int height2 = (_height - 1) / 2; + int width2 = (_width + 1) / 2; + + int x = 2 * (location % width2); + int y = 2 * (height2 - location / width2); + return {x, y}; + } - void ReadIntersections(int id); - void WriteIntersections(int id); - void ReadDecorations(int id); - void WriteDecorations(int id); + int xy_to_loc(int x, int y) { + int height2 = (_height - 1) / 2; + int width2 = (_width + 1) / 2; - // TODO: Reflection data - // TODO: Decoration colors + int rowsFromBottom = height2 - y/2; + return rowsFromBottom * width2 + x/2; + } - std::tuple loc_to_xy(int location) { - int height2 = (_height - 1) / 2; - int width2 = (_width + 1) / 2; + std::tuple dloc_to_xy(int location) { + int height2 = (_height - 3) / 2; + int width2 = (_width - 1) / 2; - int x = 2 * (location % width2); - int y = 2 * (height2 - location / width2); - return {x, y}; - } + int x = 2 * (location % width2) + 1; + int y = 2 * (height2 - location / width2) + 1; + return {x, y}; + } - int xy_to_loc(int x, int y) { - int height2 = (_height - 1) / 2; - int width2 = (_width + 1) / 2; + int xy_to_dloc(int x, int y) { + int height2 = (_height - 3) / 2; + int width2 = (_width - 1) / 2; - int rowsFromBottom = height2 - y/2; - return rowsFromBottom * width2 + x/2; - } + int rowsFromBottom = height2 - (y - 1)/2; + return rowsFromBottom * width2 + (x - 1)/2; + } - std::tuple dloc_to_xy(int location) { - int height2 = (_height - 3) / 2; - int width2 = (_width - 1) / 2; + std::shared_ptr _memory; - int x = 2 * (location % width2) + 1; - int y = 2 * (height2 - location / width2) + 1; - return {x, y}; - } + int _width, _height; - int xy_to_dloc(int x, int y) { - int height2 = (_height - 3) / 2; - int width2 = (_width - 1) / 2; + std::vector> _grid; + std::vector _endpoints; + std::vector> _startpoints; + int _style; - int rowsFromBottom = height2 - (y - 1)/2; - return rowsFromBottom * width2 + (x - 1)/2; - } + friend class PanelExtractionTests; +}; + +// V2 stuff here +struct Decoration { + enum class Type {STONE, STAR, POLY, ERASER, TRIANGLE, RPOLY, YLOP}; + Type type; + // TODO: Color color; + uint32_t polyshape; + int count; // For triangles +}; + +struct Cell { + bool start; + enum class Dir {NONE, LEFT, RIGHT, UP, DOWN}; + Dir end; + Decoration* decoration; + enum class Dot {NONE, BLACK, BLUE, YELLOW, INVISIBLE}; + Dot dot; + enum class Gap {NONE, BREAK, FULL}; + Gap gap; +}; - std::shared_ptr _memory; +struct Puzzle { + int16_t height; + int16_t width; + Cell** grid; - int _width, _height; + enum class Symmetry {NONE, X, Y, XY}; + Symmetry sym; + bool pillar; +}; - std::vector> _grid; - std::vector _endpoints; - std::vector> _startpoints; - int _style; +class PuzzleSerializer { +public: + PuzzleSerializer(const std::shared_ptr& memory); + Puzzle ReadPuzzle(int panelId); + void WritePuzzle(int panelId, const Puzzle& puzzle); + +//private: + enum Shape { + Stone = 0x100, + Star = 0x200, + Poly = 0x400, + Eraser = 0x500, + Triangle = 0x600, + RPoly = 0x1000, + Ylop = 0x2000, + }; + + enum Color { + Black = 0x1, + White = 0x2, + Gray = 0x3, + Purple = 0x4, + Green = 0x5, + Cyan = 0x6, + Pink = 0x7, + Yellow = 0x8, + Blue = 0x9, + Orange = 0xA, + }; + + enum Flags { + IS_ENDPOINT = 0x1, + IS_STARTPOINT = 0x2, + DOT_IS_BLUE = 0x100, + DOT_IS_ORANGE = 0x200, + DOT_IS_INVISIBLE = 0x1000, + IS_GAP = 0x10000, + HAS_DOT = 0x40020, + }; + + std::shared_ptr _memory; +}; - friend class PanelExtractionTests; -}; \ No newline at end of file +static nlohmann::json Decoration_to_json(int decoration) { + nlohmann::json json = {}; + int shape = decoration & 0x00000F00; + if (shape == PuzzleSerializer::Shape::Stone) json["type"] = "square"; + if (shape == PuzzleSerializer::Shape::Star) json["type"] = "star"; + if (shape == PuzzleSerializer::Shape::Poly) json["type"] = "poly"; + if (shape == PuzzleSerializer::Shape::Eraser) json["type"] = "eraser"; + if (shape == PuzzleSerializer::Shape::Triangle) json["type"] = "triangle"; + + int color = decoration & 0x0000000F; + if (color == PuzzleSerializer::Color::Black) json["color"] = "black"; + if (color == PuzzleSerializer::Color::White) json["color"] = "white"; + if (color == PuzzleSerializer::Color::Gray) json["color"] = "gray"; + if (color == PuzzleSerializer::Color::Blue) json["color"] = "blue"; + if (color == PuzzleSerializer::Color::Green) json["color"] = "green"; + + if (json.empty()) return false; + return json; +} diff --git a/Source/Source.vcxproj b/Source/Source.vcxproj index b60349c..0fed93c 100644 --- a/Source/Source.vcxproj +++ b/Source/Source.vcxproj @@ -158,7 +158,9 @@ + + @@ -166,6 +168,7 @@ + -- cgit 1.4.1