├── 7.data ├── 7.png ├── 8_1.data ├── 8_1.png ├── LICENSE ├── README.md ├── baseball.cpp ├── baseball.exe └── game2.cpp /7.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cznull/pcrgames/b080486e2ae3cfde6d7d48bbfb3ee2047d26ab05/7.data -------------------------------------------------------------------------------- /7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cznull/pcrgames/b080486e2ae3cfde6d7d48bbfb3ee2047d26ab05/7.png -------------------------------------------------------------------------------- /8_1.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cznull/pcrgames/b080486e2ae3cfde6d7d48bbfb3ee2047d26ab05/8_1.data -------------------------------------------------------------------------------- /8_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cznull/pcrgames/b080486e2ae3cfde6d7d48bbfb3ee2047d26ab05/8_1.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 cznull 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # baseball 2 | 3 | 到这里下opencv windows库 https://sourceforge.net/projects/opencvlibrary/files/4.5.4/opencv-4.5.4-vc14_vc15.exe/download 4 | 在opencv\build\x64\vc15\bin下找到opencv_world454.dll 5 | 6 | 将baseball.exe,7.png,8_1.png和opencv_world454.dll放到同一个文件夹下。 7 | 屏幕至少要2k,仅支持雷电模拟器9,模拟器分辨率设置为1920*1080,不要调整模拟器窗口大小,模拟器名称必须是雷电模拟器。在挥棒的位置设一个按键映射Q。 8 | ![image](https://user-images.githubusercontent.com/32773496/182867092-5d9e9a6b-0493-473c-83c1-4f2fd1cd3adc.png) 9 | 10 | 开始棒球小游戏后运行程序。 11 | -------------------------------------------------------------------------------- /baseball.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | #include "Eigen/Eigen" 7 | 8 | #ifdef _DEBUG 9 | #pragma comment(lib,"opencv_world454d.lib") 10 | #else 11 | #pragma comment(lib,"opencv_world454.lib") 12 | #endif 13 | 14 | #define MAX_LOADSTRING 100 15 | 16 | struct target_t { 17 | float* data; 18 | float* alpha; 19 | int w, h; 20 | }; 21 | 22 | struct snake_t { 23 | int region; 24 | int pos; 25 | int count; 26 | int point; 27 | }; 28 | 29 | struct color_t { 30 | int r, g, b; 31 | }; 32 | 33 | float inf = 1.0f / 0.0f; 34 | 35 | ULONGLONG ts = 0; 36 | HDC hdc1, hdc2; 37 | HGLRC m_hrc; 38 | int mx, my, cx, cy; 39 | double ang1, ang2, len, cenx, ceny, cenz; 40 | 41 | HWND bbhwnd; 42 | HWND bbhwndmessage; 43 | HDC bbhdc, bbhdcc; 44 | HBITMAP hbitmap; 45 | BITMAP bmp; 46 | RECT bbrect; 47 | unsigned char* data; 48 | int* tempdata; 49 | unsigned char* record; 50 | int recordi = 0; 51 | 52 | cv::Mat img, alpha; 53 | target_t screen, flag, cursor; 54 | target_t screenr, flagr, cursorr; 55 | target_t corner1, corner2, corner3, corner4, cornerr; 56 | 57 | int start = 0; 58 | uint64_t tc = 0, tl = 0; 59 | 60 | int lastcursorx = 0; 61 | uint64_t lastcursort = 0, lastclicktime = 0; 62 | double speed = 0; 63 | 64 | 65 | int reduce(target_t src, target_t dst) { 66 | if (dst.alpha) { 67 | for (int i = 0; i < dst.h; i++) { 68 | for (int j = 0; j < dst.w; j++) { 69 | dst.data[(i * dst.w + j) * 3] = src.data[(i * 2 * src.w + j * 2) * 3] + src.data[(i * 2 * src.w + j * 2 + 1) * 3] + src.data[((i * 2 + 1) * src.w + j * 2) * 3] + src.data[((i * 2 + 1) * src.w + j * 2 + 1) * 3]; 70 | dst.data[(i * dst.w + j) * 3 + 1] = src.data[(i * 2 * src.w + j * 2) * 3 + 1] + src.data[(i * 2 * src.w + j * 2 + 1) * 3 + 1] + src.data[((i * 2 + 1) * src.w + j * 2) * 3 + 1] + src.data[((i * 2 + 1) * src.w + j * 2 + 1) * 3 + 1]; 71 | dst.data[(i * dst.w + j) * 3 + 2] = src.data[(i * 2 * src.w + j * 2) * 3 + 2] + src.data[(i * 2 * src.w + j * 2 + 1) * 3 + 2] + src.data[((i * 2 + 1) * src.w + j * 2) * 3 + 2] + src.data[((i * 2 + 1) * src.w + j * 2 + 1) * 3 + 2]; 72 | 73 | dst.alpha[(i * dst.w + j) * 3] = src.alpha[(i * 2 * src.w + j * 2) * 3] + src.alpha[(i * 2 * src.w + j * 2 + 1) * 3] + src.alpha[((i * 2 + 1) * src.w + j * 2) * 3] + src.alpha[((i * 2 + 1) * src.w + j * 2 + 1) * 3]; 74 | dst.alpha[(i * dst.w + j) * 3 + 1] = src.alpha[(i * 2 * src.w + j * 2) * 3 + 1] + src.alpha[(i * 2 * src.w + j * 2 + 1) * 3 + 1] + src.alpha[((i * 2 + 1) * src.w + j * 2) * 3 + 1] + src.alpha[((i * 2 + 1) * src.w + j * 2 + 1) * 3 + 1]; 75 | dst.alpha[(i * dst.w + j) * 3 + 2] = src.alpha[(i * 2 * src.w + j * 2) * 3 + 2] + src.alpha[(i * 2 * src.w + j * 2 + 1) * 3 + 2] + src.alpha[((i * 2 + 1) * src.w + j * 2) * 3 + 2] + src.alpha[((i * 2 + 1) * src.w + j * 2 + 1) * 3 + 2]; 76 | } 77 | } 78 | } 79 | else { 80 | for (int i = 0; i < dst.h; i++) { 81 | for (int j = 0; j < dst.w; j++) { 82 | dst.data[(i * dst.w + j) * 3] = src.data[(i * 2 * src.w + j * 2) * 3] + src.data[(i * 2 * src.w + j * 2 + 1) * 3] + src.data[((i * 2 + 1) * src.w + j * 2) * 3] + src.data[((i * 2 + 1) * src.w + j * 2 + 1) * 3]; 83 | dst.data[(i * dst.w + j) * 3 + 1] = src.data[(i * 2 * src.w + j * 2) * 3 + 1] + src.data[(i * 2 * src.w + j * 2 + 1) * 3 + 1] + src.data[((i * 2 + 1) * src.w + j * 2) * 3 + 1] + src.data[((i * 2 + 1) * src.w + j * 2 + 1) * 3 + 1]; 84 | dst.data[(i * dst.w + j) * 3 + 2] = src.data[(i * 2 * src.w + j * 2) * 3 + 2] + src.data[(i * 2 * src.w + j * 2 + 1) * 3 + 2] + src.data[((i * 2 + 1) * src.w + j * 2) * 3 + 2] + src.data[((i * 2 + 1) * src.w + j * 2 + 1) * 3 + 2]; 85 | } 86 | } 87 | } 88 | return 0; 89 | } 90 | 91 | int fliph(target_t& src, target_t& dst) { 92 | dst.w = src.w; 93 | dst.h = src.h; 94 | dst.data = (float*)malloc(dst.w * dst.h * 3 * sizeof(float)); 95 | dst.alpha = (float*)malloc(dst.w * dst.h * 3 * sizeof(float)); 96 | for (int i = 0; i < dst.h; i++) { 97 | for (int j = 0; j < dst.w; j++) { 98 | dst.data[(i * dst.w + j) * 3] = src.data[(i * src.w + (dst.w - j - 1)) * 3]; 99 | dst.data[(i * dst.w + j) * 3 + 1] = src.data[(i * src.w + (dst.w - j - 1)) * 3 + 1]; 100 | dst.data[(i * dst.w + j) * 3 + 2] = src.data[(i * src.w + (dst.w - j - 1)) * 3 + 2]; 101 | dst.alpha[(i * dst.w + j) * 3] = src.alpha[(i * src.w + (dst.w - j - 1)) * 3]; 102 | dst.alpha[(i * dst.w + j) * 3 + 1] = src.alpha[(i * src.w + (dst.w - j - 1)) * 3 + 1]; 103 | dst.alpha[(i * dst.w + j) * 3 + 2] = src.alpha[(i * src.w + (dst.w - j - 1)) * 3 + 2]; 104 | } 105 | } 106 | return 0; 107 | } 108 | 109 | int flipv(target_t& src, target_t& dst) { 110 | dst.w = src.w; 111 | dst.h = src.h; 112 | dst.data = (float*)malloc(dst.w * dst.h * 3 * sizeof(float)); 113 | dst.alpha = (float*)malloc(dst.w * dst.h * 3 * sizeof(float)); 114 | for (int i = 0; i < dst.h; i++) { 115 | for (int j = 0; j < dst.w; j++) { 116 | dst.data[(i * dst.w + j) * 3] = src.data[((dst.h - i - 1) * src.w + j) * 3]; 117 | dst.data[(i * dst.w + j) * 3 + 1] = src.data[((dst.h - i - 1) * src.w + j) * 3 + 1]; 118 | dst.data[(i * dst.w + j) * 3 + 2] = src.data[((dst.h - i - 1) * src.w + j) * 3 + 2]; 119 | dst.alpha[(i * dst.w + j) * 3] = src.alpha[((dst.h - i - 1) * src.w + j) * 3]; 120 | dst.alpha[(i * dst.w + j) * 3 + 1] = src.alpha[((dst.h - i - 1) * src.w + j) * 3 + 1]; 121 | dst.alpha[(i * dst.w + j) * 3 + 2] = src.alpha[((dst.h - i - 1) * src.w + j) * 3 + 2]; 122 | } 123 | } 124 | return 0; 125 | } 126 | 127 | float geterror(target_t img, target_t target, int x, int y) { 128 | __m256 sum = _mm256_set1_ps(0.0f); 129 | for (int j = 0; j < target.h; j++) { 130 | for (int i = 0; i < target.w * 3; i += 8) { 131 | __m256 x1, x2; 132 | x1 = _mm256_loadu_ps(img.data + (j + y) * 3 * img.w + (i + x * 3)); 133 | x2 = _mm256_loadu_ps(target.data + j * 3 * target.w + i); 134 | x1 = _mm256_sub_ps(x1, x2); 135 | x1 = _mm256_mul_ps(x1, x1); 136 | x2 = _mm256_loadu_ps(target.alpha + j * 3 * target.w + i); 137 | x1 = _mm256_mul_ps(x1, x2); 138 | sum = _mm256_add_ps(sum, x1); 139 | } 140 | } 141 | return sum.m256_f32[0] + sum.m256_f32[1] + sum.m256_f32[2] + sum.m256_f32[3] + sum.m256_f32[4] + sum.m256_f32[5] + sum.m256_f32[6] + sum.m256_f32[7]; 142 | } 143 | 144 | int match(target_t img, target_t target, int x1, int x2, int y1, int y2, int& mx, int& my, float& value) { 145 | value = inf; 146 | for (int y = y1; y < y2; y++) { 147 | for (int x = x1; x < x2; x++) { 148 | float error = geterror(img, target, x, y); 149 | if (error < value) { 150 | value = error; 151 | mx = x; 152 | my = y; 153 | } 154 | } 155 | } 156 | return 0; 157 | } 158 | 159 | int loadimg(const char* fn, target_t& target, target_t& targetr) { 160 | img = cv::imread(fn); 161 | target.w = img.cols; 162 | target.h = img.rows; 163 | target.data = (float*)malloc(target.w * target.h * 3 * sizeof(float)); 164 | target.alpha = (float*)malloc(target.w * target.h * 3 * sizeof(float)); 165 | for (int i = 0; i < target.w * target.h; i++) { 166 | target.data[i * 3] = img.data[i * 3]; 167 | target.data[i * 3 + 1] = img.data[i * 3 + 1]; 168 | target.data[i * 3 + 2] = img.data[i * 3 + 2]; 169 | target.alpha[i * 3] = 1.0; 170 | target.alpha[i * 3 + 1] = 1.0; 171 | target.alpha[i * 3 + 2] = 1.0; 172 | } 173 | targetr.w = target.w / 2; 174 | targetr.h = target.h / 2; 175 | targetr.data = (float*)malloc(targetr.w * targetr.h * 3 * sizeof(float)); 176 | targetr.alpha = (float*)malloc(targetr.w * targetr.h * 3 * sizeof(float)); 177 | reduce(target, targetr); 178 | return 0; 179 | } 180 | 181 | int loadimg(const char* fn, const char* fna, target_t& target, target_t& targetr) { 182 | img = cv::imread(fn); 183 | alpha = cv::imread(fna); 184 | target.w = img.cols; 185 | target.h = img.rows; 186 | target.data = (float*)malloc(target.w * target.h * 3 * sizeof(float)); 187 | target.alpha = (float*)malloc(target.w * target.h * 3 * sizeof(float)); 188 | for (int i = 0; i < target.w * target.h; i++) { 189 | target.data[i * 3] = img.data[i * 3]; 190 | target.data[i * 3 + 1] = img.data[i * 3 + 1]; 191 | target.data[i * 3 + 2] = img.data[i * 3 + 2]; 192 | target.alpha[i * 3] = (1.0f / 255.0f) * alpha.data[i * 3]; 193 | target.alpha[i * 3 + 1] = (1.0f / 255.0f) * alpha.data[i * 3]; 194 | target.alpha[i * 3 + 2] = (1.0f / 255.0f) * alpha.data[i * 3]; 195 | } 196 | targetr.w = target.w / 2; 197 | targetr.h = target.h / 2; 198 | targetr.data = (float*)malloc(targetr.w * targetr.h * 3 * sizeof(float)); 199 | targetr.alpha = (float*)malloc(targetr.w * targetr.h * 3 * sizeof(float)); 200 | reduce(target, targetr); 201 | return 0; 202 | } 203 | 204 | struct size_t3 { 205 | size_t x, y, z; 206 | }; 207 | 208 | template 209 | struct area_t { 210 | size_t3 index; 211 | T value; 212 | }; 213 | 214 | template 215 | int getonearea(T* data, size_t sizex, size_t sizey, size_t sizez, size_t x, size_t y, size_t z, std::vector>& area) { 216 | area.push_back({ x,y,z,data[(z * sizey + y) * sizex + x] }); 217 | data[(z * sizey + y) * sizex + x] = 0; 218 | int cur = 0; 219 | size_t3 p; 220 | while (cur < area.size()) { 221 | p = area[cur].index; 222 | if (p.x > 0 && data[(p.z * sizey + p.y) * sizex + p.x - 1]) { 223 | area.push_back({ p.x - 1, p.y,p.z, data[(p.z * sizey + p.y) * sizex + p.x - 1] }); 224 | data[(p.z * sizey + p.y) * sizex + p.x - 1] = 0; 225 | } 226 | if (p.y > 0 && data[(p.z * sizey + p.y - 1) * sizex + p.x]) { 227 | area.push_back({ p.x, p.y - 1,p.z,data[(p.z * sizey + p.y - 1) * sizex + p.x] }); 228 | data[(p.z * sizey + p.y - 1) * sizex + p.x] = 0; 229 | } 230 | if (p.z > 0 && data[((p.z - 1) * sizey + p.y) * sizex + p.x]) { 231 | area.push_back({ p.x, p.y,p.z - 1,data[((p.z - 1) * sizey + p.y) * sizex + p.x] }); 232 | data[((p.z - 1) * sizey + p.y) * sizex + p.x] = 0; 233 | } 234 | if (p.x < sizex - 1 && data[(p.z * sizey + p.y) * sizex + p.x + 1]) { 235 | area.push_back({ p.x + 1, p.y,p.z,data[(p.z * sizey + p.y) * sizex + p.x + 1] }); 236 | data[(p.z * sizey + p.y) * sizex + p.x + 1] = 0; 237 | } 238 | if (p.y < sizey - 1 && data[(p.z * sizey + p.y + 1) * sizex + p.x]) { 239 | area.push_back({ p.x, p.y + 1,p.z,data[(p.z * sizey + p.y + 1) * sizex + p.x] }); 240 | data[(p.z * sizey + p.y + 1) * sizex + p.x] = 0; 241 | } 242 | if (p.z < sizez - 1 && data[((p.z + 1) * sizey + p.y) * sizex + p.x]) { 243 | area.push_back({ p.x, p.y,p.z + 1,data[((p.z + 1) * sizey + p.y) * sizex + p.x] }); 244 | data[((p.z + 1) * sizey + p.y) * sizex + p.x] = 0; 245 | } 246 | cur++; 247 | } 248 | return 0; 249 | } 250 | 251 | template 252 | int getareas(T* data, size_t sizex, size_t sizey, size_t sizez, std::vector>>& areas) { 253 | for (size_t z = 0; z < sizez; z++) { 254 | for (size_t y = 0; y < sizey; y++) { 255 | for (size_t x = 0; x < sizex; x++) { 256 | if (data[(z * sizey + y) * sizex + x]) { 257 | std::vector> area; 258 | getonearea(data, sizex, sizey, sizez, x, y, z, area); 259 | areas.push_back(area); 260 | } 261 | } 262 | } 263 | } 264 | return 0; 265 | } 266 | 267 | struct peakadv_t { 268 | double area;//0 269 | double xc, yc, zc;//1 270 | double maxintensity;//4 271 | double totalintensity;//5 272 | double type;//6 273 | double xx, yy, zz, xy, xz, yz;//7 274 | }; 275 | 276 | template 277 | void getpeakparaadv(std::vector>& area, peakadv_t& peak) { 278 | peak.area = area.size(); 279 | 280 | peak.maxintensity = area[0].value; 281 | peak.totalintensity = 0; 282 | peak.xc = 0; 283 | peak.yc = 0; 284 | peak.zc = 0; 285 | for (int i = 0; i < area.size(); i++) { 286 | peak.xc += area[i].index.x * area[i].value; 287 | peak.yc += area[i].index.y * area[i].value; 288 | peak.zc += area[i].index.z * area[i].value; 289 | peak.totalintensity += area[i].value; 290 | if (area[i].value > peak.maxintensity) { 291 | peak.maxintensity = area[i].value; 292 | } 293 | } 294 | 295 | double weight = 1.0 / peak.totalintensity; 296 | 297 | peak.xc *= weight; 298 | peak.yc *= weight; 299 | peak.zc *= weight; 300 | 301 | 302 | for (int i = 0; i < area.size(); i++) { 303 | double dx = area[i].index.x - peak.xc; 304 | double dy = area[i].index.y - peak.yc; 305 | double dz = area[i].index.z - peak.zc; 306 | peak.xx += dx * dx * area[i].value; 307 | peak.yy += dx * dy * area[i].value; 308 | peak.zz += dx * dz * area[i].value; 309 | peak.xy += dy * dy * area[i].value; 310 | peak.xz += dy * dz * area[i].value; 311 | peak.yz += dz * dz * area[i].value; 312 | } 313 | peak.xx *= weight; 314 | peak.yy *= weight; 315 | peak.zz *= weight; 316 | peak.xy *= weight; 317 | peak.xz *= weight; 318 | peak.yz *= weight; 319 | } 320 | 321 | 322 | int findedge(float* data, int n, float& x1, float& x2) { 323 | float r, g, b; 324 | int e, et; 325 | e = 0; 326 | et = 0; 327 | for (int i = 0; i < n; i++) { 328 | b = data[i * 3]; 329 | g = data[i * 3 + 1]; 330 | r = data[i * 3 + 2]; 331 | if (r < 100 && g < 100 && b < 50) { 332 | if (!e) { 333 | et++; 334 | } 335 | e++; 336 | } 337 | else { 338 | if (e) { 339 | if (et == 1) { 340 | x1 = i - 0.5f * e; 341 | } 342 | else if (et == 2) { 343 | x2 = i - 0.5f * e; 344 | } 345 | } 346 | e = 0; 347 | } 348 | } 349 | return et; 350 | } 351 | 352 | int game3findball(target_t& screen, float& x, float& y) { 353 | const int xa = 820, xb = 1100, ya = 330, yb = 640; 354 | int mx, my; 355 | float error; 356 | 357 | int et = 0; 358 | float x1, x2; 359 | std::vector x1v, x2v; 360 | for (int j = ya; j < yb; j++) { 361 | if (findedge(screen.data + j * screen.w * 3 + xa * 3, xb - xa, x1, x2) == 2) { 362 | x1v.emplace_back(x1); 363 | x2v.emplace_back(x2); 364 | et++; 365 | } 366 | else { 367 | if (et >= 4) { 368 | std::sort(x1v.begin(), x1v.end()); 369 | std::sort(x2v.begin(), x2v.end()); 370 | x = 0.5f * (x1v[x1v.size() / 2] + x2v[x2v.size() / 2]) + xa; 371 | y = j - 0.5f * et; 372 | return 1; 373 | } 374 | x1v.clear(); 375 | x2v.clear(); 376 | et = 0; 377 | } 378 | } 379 | //match(screen, corner1, xa, xb - 7, ya, yb - 7, mx, my, error); 380 | //printf("corner:%d,%d,%f\n", mx, my, error); 381 | //match(screen, corner2, xa, xb - 7, ya, yb - 7, mx, my, error); 382 | //printf("corner:%d,%d,%f\n", mx, my, error); 383 | //match(screen, corner3, xa, xb - 7, ya, yb - 7, mx, my, error); 384 | ///printf("corner:%d,%d,%f\n", mx, my, error); 385 | //match(screen, corner4, xa, xb - 7, ya, yb - 7, mx, my, error); 386 | //printf("corner:%d,%d,%f\n", mx, my, error); 387 | return 0; 388 | } 389 | 390 | int game3findfire(target_t& screen, float& x, float& y) { 391 | 392 | const int xa = 860, xb = 1060, ya = 300, yb = 500; 393 | 394 | for (int j = ya; j < yb; j++) { 395 | for (int i = xa; i < xb; i++) { 396 | tempdata[j * screen.w + i] = 0; 397 | float r, g, b; 398 | b = screen.data[(j * screen.w + i) * 3]; 399 | g = screen.data[(j * screen.w + i) * 3 + 1]; 400 | r = screen.data[(j * screen.w + i) * 3 + 2]; 401 | if (r > 250.0f && g > 250.0f && b < 100.0f) { 402 | tempdata[j * screen.w + i] = 1; 403 | } 404 | } 405 | } 406 | 407 | std::vector>> area; 408 | getareas(tempdata, screen.w, screen.h, 1, area); 409 | 410 | int mi, mv; 411 | if (area.size()) { 412 | mv = area[0].size(); 413 | mi = 0; 414 | for (int i = 0; i < area.size(); i++) { 415 | if (area[i].size() > mv) { 416 | mv = area[i].size(); 417 | mi = i; 418 | } 419 | } 420 | peakadv_t peak; 421 | getpeakparaadv(area[mi], peak); 422 | //printf("fire:%f\n", peak.area); 423 | 424 | if (peak.area > 2000.0f) { 425 | x = peak.xc; 426 | y = peak.yc; 427 | return 1; 428 | } 429 | } 430 | return 0; 431 | } 432 | 433 | int game3move(float x, float y) { 434 | int clickpos = 65536 * (844 + int(y)) + 332 + int(x); 435 | PostMessage(bbhwndmessage, WM_MOUSEMOVE, 1, clickpos); 436 | //PostMessage(bbhwndmessage, WM_LBUTTONUP, 1, clickpos); 437 | return 0; 438 | } 439 | 440 | int game3attack(float x) { 441 | 442 | int clickpos = 65536 * 844 + 332 + int(x); 443 | //PostMessage(bbhwndmessage, WM_LBUTTONUP, 1, clickpos); 444 | clickpos = 65536 * 900 + 1500; 445 | //SendMessage(bbhwndmessage, WM_LBUTTONDOWN, 1, clickpos); 446 | //SendMessage(bbhwndmessage, WM_LBUTTONUP, 1, clickpos); 447 | 448 | 449 | PostMessage(bbhwndmessage, WM_KEYDOWN, 'Q', 4128769); 450 | //keybd_event('5', 0, 0, 0); 451 | return 0; 452 | } 453 | 454 | float getshift(std::vector& xv, std::vector& yv, float& yt,float &yshift) { 455 | 456 | if (xv[1] > 995.0f) { 457 | yt = 550.0f; 458 | return 1.4f * (xv[1] + xv[2] + xv[3] + xv[4] - 3858); 459 | } 460 | 461 | Eigen::MatrixXf ym, xm; 462 | 463 | int n = 5; 464 | if (yv.size() < 5) { 465 | n = yv.size(); 466 | } 467 | 468 | ym.resize(n, 2); 469 | xm.resize(n, 1); 470 | for (int i = 0; i < n; i++) { 471 | xm(i) = xv[i]; 472 | ym(i, 0) = 1.0; 473 | ym(i, 1) = yv[i]; 474 | //ym(i, 2) = yv[i] * yv[i]; 475 | //ym(i, 3) = yv[i] * yv[i] * yv[i]; 476 | } 477 | Eigen::MatrixXf cm; 478 | cm = (ym.transpose() * ym).inverse() * (ym.transpose() * xm); 479 | 480 | float shift; 481 | shift = cm(0) + 833.0f * cm(1) - 959.0f; 482 | 483 | if (shift > 150.0f) { 484 | yshift = -20.0f; 485 | printf("shift:%f\n", shift); 486 | shift = 20.0f * (xv[5] - xv[4] - 10.0f); 487 | } 488 | else if (shift < -150.0f) { 489 | yshift = -20.0f; 490 | printf("shift:%f\n", shift); 491 | shift = 20.0f * (xv[5] - xv[4] + 10.0f); 492 | } 493 | 494 | return shift; 495 | } 496 | 497 | int ingame; 498 | float lasty; 499 | std::vector xv, yv; 500 | float yt; 501 | 502 | int game3(uchar* data) { 503 | tc = GetTickCount64(); 504 | 505 | for (int i = 300; i < bmp.bmHeight - 1; i++) { 506 | uchar* sl = data + i * bmp.bmWidth * 4; 507 | float* dl = screen.data + i * bmp.bmWidth * 3; 508 | for (int j = 800; j < bmp.bmWidth; j++) { 509 | dl[j * 3] = sl[j * 4]; 510 | dl[j * 3 + 1] = sl[j * 4 + 1]; 511 | dl[j * 3 + 2] = sl[j * 4 + 2]; 512 | } 513 | } 514 | reduce(screen, screenr); 515 | 516 | 517 | int cursorx, cursory; 518 | float error; 519 | 520 | error = geterror(screenr, flagr, 738, 484); 521 | 522 | if (error < 1000000) { 523 | 524 | if (!ingame) { 525 | Sleep(1500); 526 | 527 | PostMessage(bbhwndmessage, WM_LBUTTONDOWN, 1, 65536 * 844 + 332); 528 | printf("down\n"); 529 | ingame = 1; 530 | yt = 520.0f; 531 | 532 | xv.clear(); 533 | yv.clear(); 534 | return 0; 535 | } 536 | 537 | 538 | error = geterror(screenr, cursorr, 468, 157); 539 | if (error < 2.0e7f) { 540 | if (!xv.size()) { 541 | xv.emplace_back(952.0f); 542 | yv.emplace_back(330.0f); 543 | printf("fb:\n"); 544 | } 545 | lasty = 330.0f; 546 | } 547 | else { 548 | float x, y; 549 | if (xv.size()) { 550 | if (game3findfire(screen, x, y)) { 551 | printf("firepos:%f\n", x); 552 | game3move((x - 950.5f) * 9.0f, 80.0f); 553 | if (yv[4] > 376.5f) { 554 | Sleep(90); 555 | } 556 | else { 557 | Sleep(120); 558 | } 559 | game3attack(0.0f); 560 | return 0; 561 | } 562 | 563 | //recordimage(data); 564 | game3findball(screen, x, y); 565 | 566 | if (y != yv[yv.size() - 1]) { 567 | xv.emplace_back(x); 568 | yv.emplace_back(y); 569 | printf("pos:%f,%f\n", x, y); 570 | 571 | float yshift = 0.0f; 572 | if (yv.size() >= 4 && yv[3] > 460.0f) { 573 | float shift = getshift(xv, yv, yt, yshift); 574 | printf("%f\n", shift); 575 | game3move(shift * 1.6f, 80.0f); 576 | } 577 | else if (y > 455.0f) { 578 | float shift = getshift(xv, yv, yt, yshift); 579 | printf("%f\n", shift); 580 | game3move(shift * 1.5f, yshift); 581 | } 582 | 583 | if (y > yt) { 584 | game3attack(0.0f); 585 | } 586 | } 587 | } 588 | } 589 | 590 | //Sleep(8); 591 | //recordimage(data); 592 | 593 | } 594 | else { 595 | if (ingame) { 596 | PostMessage(bbhwndmessage, WM_LBUTTONUP, 1, 65536 * 844 + 332); 597 | ingame = 0; 598 | PostMessage(bbhwndmessage, WM_KEYUP, 'Q', 0); 599 | } 600 | } 601 | 602 | tl = tc; 603 | return 0; 604 | } 605 | 606 | BOOL CALLBACK quitfullscreenProc(HWND hwnd, LPARAM lParam) 607 | { 608 | char szTitle[MAX_PATH] = { 0 }; 609 | char szClass[MAX_PATH] = { 0 }; 610 | int nMaxCount = MAX_PATH; 611 | 612 | LPSTR lpClassName = szClass; 613 | LPSTR lpWindowName = szTitle; 614 | 615 | GetWindowTextA(hwnd, lpWindowName, nMaxCount); 616 | GetClassNameA(hwnd, lpClassName, nMaxCount); 617 | RECT rcClient; 618 | GetClientRect(hwnd, &rcClient); 619 | 620 | if (lpWindowName[0] == 'T') { 621 | bbhwndmessage = hwnd; 622 | bbhwnd = bbhwndmessage; 623 | } 624 | return true; 625 | } 626 | 627 | int main(int argc, char** argv) { 628 | 629 | SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE); 630 | 631 | bbhwnd = FindWindowA(NULL, "雷电模拟器"); 632 | printf("hwnd:%d\n", bbhwnd); 633 | EnumChildWindows(bbhwnd, quitfullscreenProc, 0); 634 | printf("chwnd:%d\n", bbhwnd); 635 | bbhdc = GetDC(bbhwnd); 636 | bbhdcc = CreateCompatibleDC(bbhdc); 637 | GetClientRect(bbhwnd, &bbrect); 638 | hbitmap = CreateCompatibleBitmap(bbhdc, bbrect.right - bbrect.left, bbrect.bottom - bbrect.top); 639 | SelectObject(bbhdcc, hbitmap); 640 | PrintWindow(bbhwnd, bbhdcc, PW_CLIENTONLY); 641 | GetObject(hbitmap, sizeof(BITMAP), &bmp); 642 | 643 | data = (unsigned char*)malloc(bmp.bmHeight * bmp.bmWidth * 4); 644 | tempdata = (int*)malloc(bmp.bmHeight * bmp.bmWidth * 4); 645 | 646 | record = (unsigned char*)malloc(1920 * 1080 * 4 * 256); 647 | recordi = 0; 648 | 649 | 650 | GetBitmapBits(hbitmap, bmp.bmHeight * bmp.bmWidthBytes, data); 651 | 652 | loadimg("./7.png", flag, flagr); 653 | loadimg("./8_1.png", cursor, cursorr); 654 | 655 | screen.w = bmp.bmWidth; 656 | screen.h = bmp.bmHeight; 657 | screen.data = (float*)malloc(screen.w * screen.h * 3 * sizeof(float)); 658 | screen.alpha = nullptr; 659 | 660 | screenr.w = bmp.bmWidth / 2; 661 | screenr.h = bmp.bmHeight / 2; 662 | screenr.data = (float*)malloc(screenr.w * screenr.h * 3 * sizeof(float)); 663 | screenr.alpha = nullptr; 664 | 665 | 666 | ts = GetTickCount64(); 667 | for (;;) { 668 | BitBlt(bbhdcc, 0, 0, bbrect.right - bbrect.left, bbrect.bottom - bbrect.top, bbhdc, 0, 0, SRCCOPY); 669 | //PrintWindow(bbhwnd, bbhdcc, PW_RENDERFULLCONTENT); 670 | GetBitmapBits(hbitmap, bmp.bmHeight * bmp.bmWidthBytes, data); 671 | //game2(data); 672 | game3(data); 673 | } 674 | return 0; 675 | } 676 | -------------------------------------------------------------------------------- /baseball.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cznull/pcrgames/b080486e2ae3cfde6d7d48bbfb3ee2047d26ab05/baseball.exe -------------------------------------------------------------------------------- /game2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #ifdef _DEBUG 11 | #pragma comment(lib,"opencv_world401d.lib") 12 | #else 13 | #pragma comment(lib,"opencv_world401.lib") 14 | #endif 15 | 16 | #pragma comment(lib,"opengl32.lib") 17 | #pragma comment(lib,"glu32.lib") 18 | #pragma comment(lib,"glew32.lib") 19 | 20 | #define MAX_LOADSTRING 100 21 | 22 | struct target_t { 23 | float* data; 24 | float* alpha; 25 | int w, h; 26 | }; 27 | 28 | struct snake_t { 29 | int region; 30 | int pos; 31 | int count; 32 | int point; 33 | }; 34 | 35 | struct color_t { 36 | int r, g, b; 37 | }; 38 | 39 | // Global Variables: 40 | HINSTANCE hInst; // current instance 41 | WCHAR szTitle[MAX_LOADSTRING]; // The title bar text 42 | WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name 43 | 44 | float inf = 1.0f / 0.0f; 45 | 46 | ULONGLONG ts = 0; 47 | HDC hdc1, hdc2; 48 | HGLRC m_hrc; 49 | int mx, my, cx, cy; 50 | double ang1, ang2, len, cenx, ceny, cenz; 51 | GLuint imgtex; 52 | 53 | HWND bbhwnd; 54 | HWND bbhwndmessage; 55 | HDC bbhdc, bbhdcc; 56 | HBITMAP hbitmap; 57 | BITMAP bmp; 58 | RECT bbrect; 59 | unsigned char* data; 60 | 61 | cv::Mat img, alpha; 62 | target_t screen, flag, cursor; 63 | target_t screenr, flagr, cursorr; 64 | 65 | int start = 0; 66 | uint64_t tc = 0, tl = 0; 67 | 68 | int lastcursorx=0; 69 | uint64_t lastcursort = 0, lastclicktime = 0; 70 | double speed=0; 71 | 72 | // Forward declarations of functions included in this code module: 73 | ATOM MyRegisterClass(HINSTANCE hInstance); 74 | BOOL InitInstance(HINSTANCE, int); 75 | LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 76 | INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); 77 | 78 | void draw(void) { 79 | 80 | glMatrixMode(GL_PROJECTION); 81 | glLoadIdentity(); 82 | glMatrixMode(GL_MODELVIEW); 83 | glLoadIdentity(); 84 | 85 | glClear(0x00004100); 86 | 87 | glBindTexture(GL_TEXTURE_2D, imgtex); 88 | glBegin(GL_QUADS); 89 | glColor3f(1.0f, 1.0f, 1.0f); 90 | glTexCoord2f(0.0f, 0.0f); 91 | glVertex3f(-1.0, 1.0f, 0.0f); 92 | glTexCoord2f(1.0f, 0.0f); 93 | glVertex3f(1.0, 1.0f, 0.0f); 94 | glTexCoord2f(1.0f, 1.0f); 95 | glVertex3f(1.0, -1.0f, 0.0f); 96 | glTexCoord2f(0.0f, 1.0f); 97 | glVertex3f(-1.0, -1.0f, 0.0f); 98 | glEnd(); 99 | 100 | SwapBuffers(hdc1); 101 | } 102 | 103 | int feverpoint = 0; 104 | int colordistance(color_t a, color_t b) { 105 | return (a.r - b.r) * (a.r - b.r) + (a.g - b.g) * (a.g - b.g) + (a.b - b.b) * (a.b - b.b); 106 | } 107 | 108 | int colortosnaketype(uchar* data) { 109 | color_t c; 110 | c.b = data[0]; 111 | c.g = data[1]; 112 | c.r = data[2]; 113 | 114 | if (colordistance(c, { 90,97,49 }) < 20) { 115 | return 1; 116 | } 117 | if (colordistance(c, { 66,77,165 }) < 20) { 118 | return 2; 119 | } 120 | if (colordistance(c, { 123,48,57 }) < 20) { 121 | return 3; 122 | } 123 | return 0; 124 | } 125 | 126 | int checksnakepoint(uchar* data, int x) { 127 | for (int i = 750; i < 765; i++) { 128 | color_t light; 129 | light.r = data[(i * bmp.bmWidth + x) * 4 + 2]; 130 | light.g = data[(i * bmp.bmWidth + x) * 4 + 1]; 131 | light.b = data[(i * bmp.bmWidth + x) * 4 + 0]; 132 | if (light.r > 230 && light.g > 230 && light.b < 50) { 133 | return 1; 134 | } 135 | } 136 | return 0; 137 | } 138 | 139 | int getsnakeseq(uchar* data,std::vector &ss) { 140 | int lastlaftpos=-1; 141 | int lastrightpos = -1; 142 | 143 | for (int i = 100; i < 960; i++) { 144 | int type; 145 | type = colortosnaketype(data + (730 * bmp.bmWidth + 959 - i) * 4); 146 | if (type && (lastlaftpos < 0 || i - lastlaftpos>180)) { 147 | snake_t snake; 148 | snake.count = type; 149 | snake.pos = i; 150 | snake.region = 0; 151 | snake.point = 0; 152 | snake.point = checksnakepoint(data, 959 - i); 153 | ss.push_back(snake); 154 | lastlaftpos = i; 155 | } 156 | 157 | type = colortosnaketype(data + (730 * bmp.bmWidth + 960 + i) * 4); 158 | if (type && (lastlaftpos < 0 || i - lastlaftpos>180)) { 159 | snake_t snake; 160 | snake.count = type; 161 | snake.pos = i; 162 | snake.region = 1; 163 | snake.point = 0; 164 | snake.point = checksnakepoint(data, 960 + i); 165 | ss.push_back(snake); 166 | lastlaftpos = i; 167 | } 168 | } 169 | return 0; 170 | } 171 | 172 | int execclick(std::vector& ss) { 173 | tl = GetTickCount64(); 174 | for (int i = 0; i < ss.size(); i++) { 175 | int clickpos = 65536 * 500 + 480 + 960 * ss[i].region; 176 | for (int j = 0; j < ss[i].count; j++) { 177 | PostMessage(bbhwndmessage, WM_LBUTTONDOWN, 1, clickpos); 178 | PostMessage(bbhwndmessage, WM_LBUTTONUP, 1, clickpos); 179 | Sleep(35); 180 | while ((tc = GetTickCount64()) < tl + 60); 181 | tl = tc; 182 | //printf("%d,", GetTickCount64() - ts); 183 | } 184 | feverpoint += ss[i].point; 185 | //printf("\n%d\n", feverpoint); 186 | 187 | if (feverpoint == 4) { 188 | tl = GetTickCount64(); 189 | Sleep(500); 190 | while (GetTickCount64() - tl < 7000) { 191 | PostMessage(bbhwndmessage, WM_LBUTTONDOWN, 1, clickpos); 192 | PostMessage(bbhwndmessage, WM_LBUTTONUP, 1, clickpos); 193 | Sleep(10); 194 | } 195 | Sleep(1300); 196 | printf("resume\n"); 197 | feverpoint = 0; 198 | break; 199 | } 200 | } 201 | return 0; 202 | } 203 | 204 | int game2(uchar* data) { 205 | std::vector ss; 206 | getsnakeseq(data, ss); 207 | execclick(ss); 208 | 209 | 210 | Sleep(350); 211 | return 0; 212 | } 213 | 214 | int main(int argc,char** argv){ 215 | 216 | HINSTANCE hInstance = ::GetModuleHandle(NULL); 217 | int nCmdShow = SW_SHOW; 218 | 219 | // TODO: Place code here. 220 | 221 | // Initialize global strings 222 | LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); 223 | LoadStringW(hInstance, IDC_PCRCLICK, szWindowClass, MAX_LOADSTRING); 224 | MyRegisterClass(hInstance); 225 | 226 | // Perform application initialization: 227 | if (!InitInstance (hInstance, nCmdShow)) 228 | { 229 | return FALSE; 230 | } 231 | 232 | HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_PCRCLICK)); 233 | 234 | MSG msg; 235 | 236 | ts = GetTickCount64(); 237 | // Main message loop: 238 | for (;;) { 239 | if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 240 | { 241 | if (msg.message == WM_QUIT) 242 | break; 243 | if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 244 | { 245 | TranslateMessage(&msg); 246 | DispatchMessage(&msg); 247 | } 248 | } 249 | else { 250 | if (bbhwnd) { 251 | //BitBlt(bbhdcc, 0, 0, bbrect.right - bbrect.left, bbrect.bottom - bbrect.top, bbhdc, 0, 0, SRCCOPY); 252 | PrintWindow(bbhwnd, bbhdcc, PW_CLIENTONLY); 253 | GetBitmapBits(hbitmap, bmp.bmHeight * bmp.bmWidthBytes, data); 254 | game2(data); 255 | } 256 | } 257 | } 258 | return (int) msg.wParam; 259 | } 260 | 261 | 262 | 263 | // 264 | // FUNCTION: MyRegisterClass() 265 | // 266 | // PURPOSE: Registers the window class. 267 | // 268 | ATOM MyRegisterClass(HINSTANCE hInstance) 269 | { 270 | WNDCLASSEXW wcex; 271 | 272 | wcex.cbSize = sizeof(WNDCLASSEX); 273 | 274 | wcex.style = CS_HREDRAW | CS_VREDRAW; 275 | wcex.lpfnWndProc = WndProc; 276 | wcex.cbClsExtra = 0; 277 | wcex.cbWndExtra = 0; 278 | wcex.hInstance = hInstance; 279 | wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_PCRCLICK)); 280 | wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); 281 | wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); 282 | wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_PCRCLICK); 283 | wcex.lpszClassName = szWindowClass; 284 | wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); 285 | 286 | return RegisterClassExW(&wcex); 287 | } 288 | 289 | // 290 | // FUNCTION: InitInstance(HINSTANCE, int) 291 | // 292 | // PURPOSE: Saves instance handle and creates main window 293 | // 294 | // COMMENTS: 295 | // 296 | // In this function, we save the instance handle in a global variable and 297 | // create and display the main program window. 298 | // 299 | BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) 300 | { 301 | hInst = hInstance; // Store instance handle in our global variable 302 | 303 | HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, 304 | CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr); 305 | 306 | if (!hWnd) 307 | { 308 | return FALSE; 309 | } 310 | 311 | ShowWindow(hWnd, nCmdShow); 312 | UpdateWindow(hWnd); 313 | 314 | return TRUE; 315 | } 316 | 317 | // 318 | // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) 319 | // 320 | // PURPOSE: Processes messages for the main window. 321 | // 322 | // WM_COMMAND - process the application menu 323 | // WM_PAINT - Paint the main window 324 | // WM_DESTROY - post a quit message and return 325 | // 326 | // 327 | 328 | BOOL CALLBACK quitfullscreenProc(HWND hwnd, LPARAM lParam) 329 | { 330 | char szTitle[MAX_PATH] = { 0 }; 331 | char szClass[MAX_PATH] = { 0 }; 332 | int nMaxCount = MAX_PATH; 333 | 334 | LPSTR lpClassName = szClass; 335 | LPSTR lpWindowName = szTitle; 336 | 337 | GetWindowTextA(hwnd, lpWindowName, nMaxCount); 338 | GetClassNameA(hwnd, lpClassName, nMaxCount); 339 | RECT rcClient; 340 | GetClientRect(hwnd, &rcClient); 341 | 342 | if (lpWindowName[0] == 'T') { 343 | bbhwndmessage = hwnd; 344 | } 345 | return true; 346 | } 347 | 348 | LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 349 | { 350 | switch (message) 351 | { 352 | case WM_COMMAND: 353 | { 354 | int wmId = LOWORD(wParam); 355 | // Parse the menu selections: 356 | switch (wmId) 357 | { 358 | case IDM_ABOUT: 359 | DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); 360 | break; 361 | case IDM_EXIT: 362 | DestroyWindow(hWnd); 363 | break; 364 | default: 365 | return DefWindowProc(hWnd, message, wParam, lParam); 366 | } 367 | } 368 | break; 369 | case WM_PAINT: 370 | { 371 | PAINTSTRUCT ps; 372 | HDC hdc = BeginPaint(hWnd, &ps); 373 | // TODO: Add any drawing code that uses hdc here... 374 | EndPaint(hWnd, &ps); 375 | } 376 | break; 377 | case WM_CREATE: { 378 | int i, j; 379 | PIXELFORMATDESCRIPTOR pfd = { 380 | sizeof(PIXELFORMATDESCRIPTOR), 381 | 1, 382 | PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_STEREO, 383 | PFD_TYPE_RGBA, 384 | 24, 385 | 0,0,0,0,0,0,0,0, 386 | 0, 387 | 0,0,0,0, 388 | 32, 389 | 0,0, 390 | PFD_MAIN_PLANE, 391 | 0,0,0,0 392 | }; 393 | hdc1 = GetDC(hWnd); 394 | hdc2 = GetDC(NULL); 395 | int uds = ::ChoosePixelFormat(hdc1, &pfd); 396 | ::SetPixelFormat(hdc1, uds, &pfd); 397 | m_hrc = ::wglCreateContext(hdc1); 398 | ::wglMakeCurrent(hdc1, m_hrc); 399 | //glewInit(); 400 | glDisable(GL_CULL_FACE); 401 | glDisable(GL_DEPTH_TEST); 402 | glEnable(GL_TEXTURE_2D); 403 | glEnableClientState(GL_VERTEX_ARRAY); 404 | 405 | glGenTextures(1, &imgtex); 406 | glBindTexture(GL_TEXTURE_2D, imgtex); 407 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 408 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 409 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 410 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 411 | 412 | bbhwnd = FindWindowA(NULL, "雷电模拟器"); 413 | EnumChildWindows(bbhwnd, quitfullscreenProc, 0); 414 | bbhdc = GetDC(bbhwnd); 415 | bbhdcc = CreateCompatibleDC(bbhdc); 416 | GetClientRect(bbhwnd, &bbrect); 417 | hbitmap = CreateCompatibleBitmap(bbhdc, bbrect.right - bbrect.left, bbrect.bottom - bbrect.top); 418 | SelectObject(bbhdcc, hbitmap); 419 | //BitBlt(bbhdcc, 0, 0, bbrect.right - bbrect.left, bbrect.bottom - bbrect.top, bbhdc, 0, 0, SRCCOPY); 420 | PrintWindow(bbhwnd, bbhdcc, PW_CLIENTONLY); 421 | GetObject(hbitmap, sizeof(BITMAP), &bmp); 422 | //frame = new cv::Mat(bmp.bmHeight, bmp.bmWidth, CV_8UC4, cv::Scalar(0, 0, 0, 0)); 423 | data = (unsigned char*)malloc(bmp.bmHeight * bmp.bmWidth * 4); 424 | 425 | 426 | GetBitmapBits(hbitmap, bmp.bmHeight * bmp.bmWidthBytes, data); 427 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bmp.bmWidth, bmp.bmHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, data); 428 | RECT ra, rb; 429 | GetClientRect(hWnd, &ra); 430 | GetWindowRect(hWnd, &rb); 431 | MoveWindow(hWnd, 1000, 0, bmp.bmWidth / 4 + rb.right - ra.right + ra.left - rb.left, bmp.bmHeight / 4 + rb.bottom - ra.bottom + ra.top - rb.top, true); 432 | 433 | break; 434 | } 435 | case WM_SIZE: { 436 | cx = lParam & 0xffff; 437 | cy = (lParam & 0xffff0000) >> 16; 438 | glViewport(0, 0, cx, cy); 439 | break; 440 | } 441 | case WM_LBUTTONDOWN: { 442 | for(int i=0;i<1000;i++){ 443 | PostMessage(bbhwndmessage, WM_LBUTTONDOWN, 1, 10223939); 444 | PostMessage(bbhwndmessage, WM_LBUTTONUP, 1, 10223939); 445 | } 446 | break; 447 | } 448 | case WM_KEYDOWN: { 449 | break; 450 | } 451 | case WM_DESTROY: 452 | PostQuitMessage(0); 453 | break; 454 | default: 455 | return DefWindowProc(hWnd, message, wParam, lParam); 456 | } 457 | return 0; 458 | } 459 | 460 | // Message handler for about box. 461 | INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 462 | { 463 | UNREFERENCED_PARAMETER(lParam); 464 | switch (message) 465 | { 466 | case WM_INITDIALOG: 467 | return (INT_PTR)TRUE; 468 | 469 | case WM_COMMAND: 470 | if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 471 | { 472 | EndDialog(hDlg, LOWORD(wParam)); 473 | return (INT_PTR)TRUE; 474 | } 475 | break; 476 | } 477 | return (INT_PTR)FALSE; 478 | } 479 | --------------------------------------------------------------------------------