From c388759ed67b792201b99bf7d73d036c34b47d87 Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Wed, 7 Nov 2018 10:09:47 -0800 Subject: Working on some consistency --- Source/Memory.h | 4 ++-- Source/Panel.cpp | 16 +++++++++------- Source/Panel.h | 21 ++++++++++++++++++++- 3 files changed, 31 insertions(+), 10 deletions(-) (limited to 'Source') diff --git a/Source/Memory.h b/Source/Memory.h index e7f8ff3..d14d58d 100644 --- a/Source/Memory.h +++ b/Source/Memory.h @@ -3,8 +3,8 @@ #include #include -// #define GLOBALS 0x5B28C0 -#define GLOBALS 0x62A080 +#define GLOBALS 0x5B28C0 +// #define GLOBALS 0x62A080 // https://github.com/erayarslan/WriteProcessMemory-Example // http://stackoverflow.com/q/32798185 diff --git a/Source/Panel.cpp b/Source/Panel.cpp index 8642461..b6aa504 100644 --- a/Source/Panel.cpp +++ b/Source/Panel.cpp @@ -22,6 +22,9 @@ Panel::Panel(int id) { ReadDecorations(id); } +// For testing +Panel::Panel() {} + void Panel::Write(int id) { WriteIntersections(id); WriteDecorations(id); @@ -147,8 +150,7 @@ void Panel::ReadIntersections(int id) { } else { dir = Endpoint::Direction::DOWN; } - int x = 2 * (location % ((_width + 1) / 2)); - int y = (_height - 1) - 2 * (location / ((_width + 1) / 2)); + auto [x, y] = loc_to_xy(location); _endpoints.push_back(Endpoint(x, y, dir)); } } @@ -163,15 +165,15 @@ void Panel::WriteIntersections(int id) { double min = 0.1; double max = 0.9; - double width_interval = (max - min) / (_width - 1); - double height_interval = (max - min) / (_height - 1); + double width_interval = (max - min) / (_width/2); + double height_interval = (max - min) / (_height/2); - for (int y=0; y<_height; y++) { - for (int x=0; x<_width; x++) { + for (int y=0; y<_height/2; y++) { + for (int x=0; x<_width/2; x++) { intersections.push_back(static_cast(min + x * width_interval)); intersections.push_back(static_cast(min + y * height_interval)); int flags = 0; - if (find(_startpoints, {x, y}) != -1) flags |= IntersectionFlags::IS_STARTPOINT; + if (find(_startpoints, {2*x, 2*y}) != -1) flags |= IntersectionFlags::IS_STARTPOINT; intersectionFlags.push_back(flags); if (y > 0) { connections.first.push_back(y * _width + x); diff --git a/Source/Panel.h b/Source/Panel.h index c9b4910..565b4c3 100644 --- a/Source/Panel.h +++ b/Source/Panel.h @@ -90,7 +90,7 @@ private: class Panel { public: - explicit Panel(int id); + Panel(int id); // explicit Panel(nlohmann::json json); void Write(int id); @@ -109,6 +109,9 @@ public: }; private: + // For testing + Panel(); + void ReadIntersections(int id); void WriteIntersections(int id); void ReadDecorations(int id); @@ -117,6 +120,20 @@ private: // TODO: Reflection data // TODO: Decoration colors + std::tuple loc_to_xy(int location) { + int x = 2 * (location % ((_width + 1) / 2)); + int y = (_height - 1) - 2 * (location / ((_width + 1) / 2)); + return {x, y}; + } + + int xy_to_loc(int x, int y) { + int height2 = (_height - 1) / 2; + int width2 = (_width + 1) / 2; + + int rowsFromBottom = height2 - y/2; + return rowsFromBottom * width2 + x/2; + } + Memory _memory = Memory("witness64_d3d11.exe"); int _width, _height; @@ -125,4 +142,6 @@ private: std::vector _endpoints; std::vector> _startpoints; int _style; + + friend class PanelExtractionTests; }; \ No newline at end of file -- cgit 1.4.1