diff options
| -rw-r--r-- | Source/Memory.h | 4 | ||||
| -rw-r--r-- | Source/Panel.cpp | 16 | ||||
| -rw-r--r-- | Source/Panel.h | 21 | ||||
| -rw-r--r-- | Test/PanelExtractionTests.cpp | 63 | ||||
| -rw-r--r-- | Test/Test.vcxproj | 1 |
5 files changed, 95 insertions, 10 deletions
| 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 @@ | |||
| 3 | #include <map> | 3 | #include <map> |
| 4 | #include <windows.h> | 4 | #include <windows.h> |
| 5 | 5 | ||
| 6 | // #define GLOBALS 0x5B28C0 | 6 | #define GLOBALS 0x5B28C0 |
| 7 | #define GLOBALS 0x62A080 | 7 | // #define GLOBALS 0x62A080 |
| 8 | 8 | ||
| 9 | // https://github.com/erayarslan/WriteProcessMemory-Example | 9 | // https://github.com/erayarslan/WriteProcessMemory-Example |
| 10 | // http://stackoverflow.com/q/32798185 | 10 | // 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) { | |||
| 22 | ReadDecorations(id); | 22 | ReadDecorations(id); |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | // For testing | ||
| 26 | Panel::Panel() {} | ||
| 27 | |||
| 25 | void Panel::Write(int id) { | 28 | void Panel::Write(int id) { |
| 26 | WriteIntersections(id); | 29 | WriteIntersections(id); |
| 27 | WriteDecorations(id); | 30 | WriteDecorations(id); |
| @@ -147,8 +150,7 @@ void Panel::ReadIntersections(int id) { | |||
| 147 | } else { | 150 | } else { |
| 148 | dir = Endpoint::Direction::DOWN; | 151 | dir = Endpoint::Direction::DOWN; |
| 149 | } | 152 | } |
| 150 | int x = 2 * (location % ((_width + 1) / 2)); | 153 | auto [x, y] = loc_to_xy(location); |
| 151 | int y = (_height - 1) - 2 * (location / ((_width + 1) / 2)); | ||
| 152 | _endpoints.push_back(Endpoint(x, y, dir)); | 154 | _endpoints.push_back(Endpoint(x, y, dir)); |
| 153 | } | 155 | } |
| 154 | } | 156 | } |
| @@ -163,15 +165,15 @@ void Panel::WriteIntersections(int id) { | |||
| 163 | 165 | ||
| 164 | double min = 0.1; | 166 | double min = 0.1; |
| 165 | double max = 0.9; | 167 | double max = 0.9; |
| 166 | double width_interval = (max - min) / (_width - 1); | 168 | double width_interval = (max - min) / (_width/2); |
| 167 | double height_interval = (max - min) / (_height - 1); | 169 | double height_interval = (max - min) / (_height/2); |
| 168 | 170 | ||
| 169 | for (int y=0; y<_height; y++) { | 171 | for (int y=0; y<_height/2; y++) { |
| 170 | for (int x=0; x<_width; x++) { | 172 | for (int x=0; x<_width/2; x++) { |
| 171 | intersections.push_back(static_cast<float>(min + x * width_interval)); | 173 | intersections.push_back(static_cast<float>(min + x * width_interval)); |
| 172 | intersections.push_back(static_cast<float>(min + y * height_interval)); | 174 | intersections.push_back(static_cast<float>(min + y * height_interval)); |
| 173 | int flags = 0; | 175 | int flags = 0; |
| 174 | if (find(_startpoints, {x, y}) != -1) flags |= IntersectionFlags::IS_STARTPOINT; | 176 | if (find(_startpoints, {2*x, 2*y}) != -1) flags |= IntersectionFlags::IS_STARTPOINT; |
| 175 | intersectionFlags.push_back(flags); | 177 | intersectionFlags.push_back(flags); |
| 176 | if (y > 0) { | 178 | if (y > 0) { |
| 177 | connections.first.push_back(y * _width + x); | 179 | 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: | |||
| 90 | class Panel | 90 | class Panel |
| 91 | { | 91 | { |
| 92 | public: | 92 | public: |
| 93 | explicit Panel(int id); | 93 | Panel(int id); |
| 94 | // explicit Panel(nlohmann::json json); | 94 | // explicit Panel(nlohmann::json json); |
| 95 | 95 | ||
| 96 | void Write(int id); | 96 | void Write(int id); |
| @@ -109,6 +109,9 @@ public: | |||
| 109 | }; | 109 | }; |
| 110 | 110 | ||
| 111 | private: | 111 | private: |
| 112 | // For testing | ||
| 113 | Panel(); | ||
| 114 | |||
| 112 | void ReadIntersections(int id); | 115 | void ReadIntersections(int id); |
| 113 | void WriteIntersections(int id); | 116 | void WriteIntersections(int id); |
| 114 | void ReadDecorations(int id); | 117 | void ReadDecorations(int id); |
| @@ -117,6 +120,20 @@ private: | |||
| 117 | // TODO: Reflection data | 120 | // TODO: Reflection data |
| 118 | // TODO: Decoration colors | 121 | // TODO: Decoration colors |
| 119 | 122 | ||
| 123 | std::tuple<int, int> loc_to_xy(int location) { | ||
| 124 | int x = 2 * (location % ((_width + 1) / 2)); | ||
| 125 | int y = (_height - 1) - 2 * (location / ((_width + 1) / 2)); | ||
| 126 | return {x, y}; | ||
| 127 | } | ||
| 128 | |||
| 129 | int xy_to_loc(int x, int y) { | ||
| 130 | int height2 = (_height - 1) / 2; | ||
| 131 | int width2 = (_width + 1) / 2; | ||
| 132 | |||
| 133 | int rowsFromBottom = height2 - y/2; | ||
| 134 | return rowsFromBottom * width2 + x/2; | ||
| 135 | } | ||
| 136 | |||
| 120 | Memory _memory = Memory("witness64_d3d11.exe"); | 137 | Memory _memory = Memory("witness64_d3d11.exe"); |
| 121 | 138 | ||
| 122 | int _width, _height; | 139 | int _width, _height; |
| @@ -125,4 +142,6 @@ private: | |||
| 125 | std::vector<Endpoint> _endpoints; | 142 | std::vector<Endpoint> _endpoints; |
| 126 | std::vector<std::pair<int ,int>> _startpoints; | 143 | std::vector<std::pair<int ,int>> _startpoints; |
| 127 | int _style; | 144 | int _style; |
| 145 | |||
| 146 | friend class PanelExtractionTests; | ||
| 128 | }; \ No newline at end of file | 147 | }; \ No newline at end of file |
| diff --git a/Test/PanelExtractionTests.cpp b/Test/PanelExtractionTests.cpp new file mode 100644 index 0000000..dfb9b9e --- /dev/null +++ b/Test/PanelExtractionTests.cpp | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | #include "gtest/gtest.h" | ||
| 2 | #include "Panel.h" | ||
| 3 | |||
| 4 | class PanelExtractionTests : public testing::Test | ||
| 5 | { | ||
| 6 | protected: | ||
| 7 | Panel _panel; | ||
| 8 | // std::shared_ptr<Panel> _panel; | ||
| 9 | |||
| 10 | void SetPanelSize(int width, int height) { | ||
| 11 | // _panel = std::make_shared<Panel>(); | ||
| 12 | _panel._width = width; | ||
| 13 | _panel._height = height; | ||
| 14 | } | ||
| 15 | |||
| 16 | std::tuple<int, int> loc_to_xy(int location) { | ||
| 17 | return _panel.loc_to_xy(location); | ||
| 18 | } | ||
| 19 | |||
| 20 | int xy_to_loc(int x, int y) { | ||
| 21 | return _panel.xy_to_loc(x, y); | ||
| 22 | } | ||
| 23 | }; | ||
| 24 | |||
| 25 | TEST_F(PanelExtractionTests, LocToXY_7x5) { | ||
| 26 | SetPanelSize(7, 5); | ||
| 27 | /* Here's the panel, with the correct location order | ||
| 28 | 8 . 9 . 10. 11 (_width = 7) | ||
| 29 | . . . . . . . | ||
| 30 | 4 . 5 . 6 . 7 | ||
| 31 | . . . . . . . | ||
| 32 | 0 . 1 . 2 . 3 | ||
| 33 | (_height = 5) | ||
| 34 | */ | ||
| 35 | ASSERT_EQ(0, xy_to_loc(0, 4)); | ||
| 36 | ASSERT_EQ(1, xy_to_loc(2, 4)); | ||
| 37 | ASSERT_EQ(2, xy_to_loc(4, 4)); | ||
| 38 | ASSERT_EQ(3, xy_to_loc(6, 4)); | ||
| 39 | |||
| 40 | ASSERT_EQ(4, xy_to_loc(0, 2)); | ||
| 41 | ASSERT_EQ(5, xy_to_loc(2, 2)); | ||
| 42 | ASSERT_EQ(6, xy_to_loc(4, 2)); | ||
| 43 | ASSERT_EQ(7, xy_to_loc(6, 2)); | ||
| 44 | |||
| 45 | ASSERT_EQ(8, xy_to_loc(0, 0)); | ||
| 46 | ASSERT_EQ(9, xy_to_loc(2, 0)); | ||
| 47 | ASSERT_EQ(10, xy_to_loc(4, 0)); | ||
| 48 | ASSERT_EQ(11, xy_to_loc(6, 0)); | ||
| 49 | } | ||
| 50 | |||
| 51 | TEST_F(PanelExtractionTests, LocToXY_3x3) { | ||
| 52 | SetPanelSize(3, 3); | ||
| 53 | /* Here's the panel, with the correct location order | ||
| 54 | 2 . 3 (_width = 3) | ||
| 55 | . . . | ||
| 56 | 0 . 1 | ||
| 57 | (_height = 3) | ||
| 58 | */ | ||
| 59 | ASSERT_EQ(0, xy_to_loc(0, 2)); | ||
| 60 | ASSERT_EQ(1, xy_to_loc(2, 2)); | ||
| 61 | ASSERT_EQ(2, xy_to_loc(0, 0)); | ||
| 62 | ASSERT_EQ(3, xy_to_loc(2, 0)); | ||
| 63 | } \ No newline at end of file | ||
| diff --git a/Test/Test.vcxproj b/Test/Test.vcxproj index a6d8f75..55f3ce8 100644 --- a/Test/Test.vcxproj +++ b/Test/Test.vcxproj | |||
| @@ -33,6 +33,7 @@ | |||
| 33 | <ImportGroup Label="PropertySheets" /> | 33 | <ImportGroup Label="PropertySheets" /> |
| 34 | <PropertyGroup Label="UserMacros" /> | 34 | <PropertyGroup Label="UserMacros" /> |
| 35 | <ItemGroup> | 35 | <ItemGroup> |
| 36 | <ClCompile Include="PanelExtractionTests.cpp" /> | ||
| 36 | <ClCompile Include="Temp.cpp" /> | 37 | <ClCompile Include="Temp.cpp" /> |
| 37 | <ClCompile Include="RandomTests.cpp" /> | 38 | <ClCompile Include="RandomTests.cpp" /> |
| 38 | </ItemGroup> | 39 | </ItemGroup> |
