-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapplication.cpp
More file actions
654 lines (613 loc) · 22.9 KB
/
Copy pathapplication.cpp
File metadata and controls
654 lines (613 loc) · 22.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
#include "application.hpp"
#include <GLFW/glfw3.h>
#include "macro_lib_impl.hpp"
#include "utils.hpp"
#include <cmath>
#include <filesystem>
#include <fstream>
#include <nlohmann/detail/meta/type_traits.hpp>
#include <string>
#include <unordered_map>
namespace fs = std::filesystem;
APPLICATION *application_pointer = nullptr;
void create_settings() {
const fs::path path = "_macro_cache_/macro_settings.json";
fs::create_directories(path.parent_path());
json defaults = json::parse(json_macro_settings_default);
json current;
if (fs::exists(path)) {
std::ifstream in(path);
try {
in >> current;
} catch (...) {
current = defaults;
}
} else {
std::ofstream out(path);
out << defaults.dump(2);
return;
}
bool changed = false;
for (auto &[key, value] : defaults.items()) {
if (!current.contains(key)) {
current[key] = value;
changed = true;
}
}
if (changed) {
std::ofstream out(path);
out << current.dump(2);
}
}
APPLICATION::APPLICATION() {
if (!glfwInit())
exit(1);
create_settings();
json json_settings =
json::parse(std::ifstream("_macro_cache_/macro_settings.json"));
this->settings = new SETTINGS();
this->settings->walk_to_hive = json_settings["walk to hive"];
this->settings->convert_every = json_settings["convert every"];
this->settings->selected_field = json_settings["field"];
this->settings->selected_pattern = json_settings["pattern"];
this->settings->selected_hive = json_settings["hive"];
this->settings->base_walkspeed = json_settings["base walkspeed"];
this->settings->start_key = json_settings["start key"];
this->settings->stop_key = json_settings["stop key"];
this->settings->discord_webhook = json_settings["webhook"];
this->settings->selected_theme = json_settings["selected theme"];
this->settings->width = json_settings["width"];
this->settings->length = json_settings["length"];
this->settings->drift_comp = json_settings["drift_comp"];
this->settings->direction = json_settings["direction"];
this->settings->mondo = json_settings["mondo"];
this->settings->mondo_wait = json_settings["mondo_wait"];
this->settings->slot_2 = json_settings["slot_2"];
this->settings->slot_3 = json_settings["slot_3"];
this->settings->slot_4 = json_settings["slot_4"];
this->settings->slot_5 = json_settings["slot_5"];
this->settings->slot_6 = json_settings["slot_6"];
this->settings->slot_7 = json_settings["slot_7"];
this->settings->clock = json_settings["clock"];
std::map<std::string, json> fields_data;
std::map<std::string, json> patterns_data;
std::vector<std::string> fields_display;
std::vector<std::string> patterns_display;
for (const auto &entry : fs::directory_iterator("_macro_cache_/fields")) {
if (entry.is_regular_file()) {
json entry_data = json::parse(std::ifstream(entry.path()));
fields_data[entry_data["display"]] = entry_data;
fields_display.push_back(entry_data["display"]);
}
}
for (const auto &entry : fs::directory_iterator("_macro_cache_/patterns")) {
if (entry.is_regular_file()) {
json entry_data = json::parse(std::ifstream(entry.path()));
patterns_data[entry_data["display"]] = entry_data;
patterns_display.push_back(entry_data["display"]);
}
}
this->raw_data = new RAW_DATA;
this->machine_state = new STATE;
this->input = new X11_INPUT();
this->output = new X11_OUTPUT();
this->interface = new INTERFACE(fields_display, patterns_display);
this->interface->REHOOK_KEY_EVENT =
new SIGNAL<void(const std::string &, REHOOK_KEY_EVENT_TYPE)>;
this->interface->settings = this->settings;
this->raw_data->RAW_FIELDS_DATA = fields_data;
this->raw_data->RAW_PATTERNS_DATA = patterns_data;
strcpy(this->interface->DISCORD_WEBHOOK_URL,
this->settings->discord_webhook.c_str());
init_create_bitmaps();
application_pointer = this;
std::thread application_thread([this]() { this->main(); });
while (!glfwWindowShouldClose(this->interface->window)) {
this->interface->render();
}
glfwDestroyWindow(this->interface->window);
glfwTerminate();
this->input->stop();
application_thread.join();
}
static const std::vector<float> pattern_size_options = {0.25, 0.5, 1, 1.5, 2};
void APPLICATION::action_collect() {
json pattern_data =
this->raw_data->RAW_PATTERNS_DATA
[this->interface->PATTERN_OPTIONS[this->settings->selected_pattern]];
const std::string pattern_name = pattern_data["name"];
auto it = patterns_impl().find(pattern_name);
if (it != patterns_impl().end()) {
this->output->mouse_down();
it->second(this->settings->width,
pattern_size_options[this->settings->length]);
this->output->mouse_up();
}
}
static std::unordered_map<std::string, BITMAP> bitmaps = {
{"pBMSupremeSaturator",
bitmap_from_base64("iVBORw0KGgoAAAANSUhEUgAAAAoAAAAUCAIAAAA7jDsBAAAACXBIWX"
"MAAA7EAAAOxAGVKw4bAAAAGElEQVQokWNk/"
"P+fATdgwiM3Kj0qTZI0AAO/Aid65Bz+AAAAAElFTkSuQmCC")},
{"pBMSprinklerSlot_Day",
bitmap_from_base64(
"iVBORw0KGgoAAAANSUhEUgAAADoAAAAfCAIAAAA5uEn6AAAACXBIWXMAAA7EAAAOxAGVK"
"w4bAAADgElEQVRYhe1XzUojSxQ+9Zd0fjBxLtzJjEJUsslCvMiAwmXAnU/hE/"
"hCLn0C38CNgoLgWnCRRMyv9sXuJph0p6rOXRynbZL5MTOaGcFv1Tl1+tRXp7/6qsL29/"
"d935+fn9/"
"Z2YEp4fv+"
"3t5eo9HY3NwsFArJIcYYPXied3JyUi6Xd3d3x3KegoODA8dxtNaDwcBay5Ol/"
"0wgIiLSM/+9VKbF66Abd1cmf0wLxhjnHBG11pw/rjz+fEoppRTl/"
"DJnAABJpdPpdLLiVGp2Xffy8vLm5mZyCBEHg8FgMHAc5+"
"k1k0xyuVwURcYYay1QdwEgCALP84rF4tNZAoBSanV1tVardbtd13XjuBBCKQUANFM+"
"n69WqxSZCp7n+b7vOA5xBQAppczn81LKfr8/"
"Ld1MJrO9vV2pVIIgSMY551JKADDGIGI2m11aWvoJuvf391IIY0zcbkmdiKKo2WwuLi5OW"
"5ExVqlUpn3rhz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NM/FN0M40s73Lx39nWEu8LCz9X5gx/s9m8T7iQ/RjpnZPBu95qi+vOYDB3GdN4YydKW1S5F21+pLCtvoTc7ER3KQ/3ufmebB0gcw+bqTfvIv7eeSBntKdXhuRfK3OK4bVsXs9+ztN/cXd0EYWMQL5rzvidi1fJvyW7GXxsMLPn/wcUsnq/pXlrdQAAAABJRU5ErkJggg=="
)},
{"pBMButtonE",
bitmap_from_base64(
"iVBORw0KGgoAAAANSUhEUgAAAB4AAAAuCAIAAACwKD5YAAAACXBIWXMAAA7EAAAOxA"
"GVK"
"w4bAAAAf0lEQVRYhWN89+4TA20AE43MHTUaE7DAWXfu3unp6yTPFDk5+"
"aryGjTBoRkgdAlrNFBX3SAlJU2J0UMzQEaNHjV61GiSAM4ypKm1gRj9ifHJ5mYWWKW"
"GWY"
"CMFqqjRo8aPWo0EYDSQhUO0lIyjAyNkUWGZoDQ0GjG0X7jqNF4AQDPzBYvH6p8QQAA"
"AAB"
"JRU5ErkJggg==")}};
void APPLICATION::check_hive() {
this->output->key_press("Escape");
sleep(50);
this->output->key_press("r");
sleep(50);
this->output->key_press("Return");
this->machine_state->facing = FACES::Forward;
this->machine_state->placed_sprinkler = false;
sleep(5 * 1000);
loop(5) {
this->output->key_press("i");
sleep(50);
}
sleep(50);
this->output->key_press("comma");
sleep(10);
this->output->key_press("comma");
sleep(10);
this->output->key_press("comma");
sleep(10);
this->machine_state->facing = FACES::Forward;
BITMAP pBMArea = this->input->capture_display(670, 970, 120, 100);
bool found_hive_rotated =
image_search(pBMArea, bitmaps["pBMSprinklerSlot_Day"], nullptr, nullptr,
0, 0, pBMArea.width, pBMArea.height, 30) ||
image_search(pBMArea, bitmaps["pBMSprinklerSlot_Night"], nullptr, nullptr,
0, 0, pBMArea.width, pBMArea.height, 70);
sleep(50);
sleep(50);
pBMArea = this->input->capture_display(670, 970, 120, 100);
if (found_hive_rotated &&
(image_search(pBMArea, bitmaps["pBMSprinklerSlot_Day"], nullptr, nullptr,
0, 0, pBMArea.width, pBMArea.height, 30) ||
image_search(pBMArea, bitmaps["pBMSprinklerSlot_Night"], nullptr,
nullptr, 0, 0, pBMArea.width, pBMArea.height, 70))) {
this->machine_state->at_hive = true;
this->use_hotbar(HOTBAR_USE_METHOD::At_Hive);
this->output->key_press("period");
sleep(10);
this->output->key_press("period");
sleep(10);
this->output->key_press("period");
sleep(10);
#ifdef DEBUG
std::cout << "FOUND HIVE" << std::endl;
#endif
loop(5) {
this->output->key_press("o");
sleep(50);
}
return;
}
this->machine_state->at_hive = false;
}
bool APPLICATION::collect_timer_check() {
return (since_boot() - this->machine_state->collecting_begin) <
(this->settings->convert_every * 60);
}
void APPLICATION::action_drift_comp() {
BITMAP pBMArea = this->input->capture_display(
148, 98, this->input->width - 148, this->input->height - 148);
u64 center_x = pBMArea.width / 2;
u64 center_y = pBMArea.height / 2;
u64 area_x_left_bound = center_x - 128;
u64 area_y_top_bound = center_y - 128;
u64 area_x_right_bound = center_x + 128;
u64 area_y_bottom_bound = center_y + 128;
if (image_search(pBMArea, bitmaps["pBMSupremeSaturator"], nullptr, nullptr,
area_x_left_bound, area_y_top_bound, area_x_right_bound,
area_y_bottom_bound, 60))
return;
int search_area_negate_x = 600;
int search_area_negate_y = 300;
int tolerance = 30;
do {
pBMArea = this->input->capture_display(148, 98, this->input->width - 148,
this->input->height - 148);
u64 x = 0;
u64 y = 0;
if (search_area_negate_x < 0 && search_area_negate_y < 0) {
if (this->running) {
this->machine_state->placed_sprinkler = false;
this->place_sprinkler();
}
// this->output->key_up("w");
// this->output->key_up("a");
// this->output->key_up("s");
// this->output->key_up("d");
#ifdef DEBUG
std::cout << "FAIL_SAFE" << std::endl;
#endif
return;
}
if (image_search(pBMArea, bitmaps["pBMSupremeSaturator"], &x, &y,
search_area_negate_x, search_area_negate_y,
pBMArea.width - search_area_negate_x,
pBMArea.height - search_area_negate_y, tolerance)) {
u64 distance = std::sqrt(std::pow(int(x) - int(center_x), 2) +
std::pow(int(y) - int(center_y), 2));
u64 flower_distance = std::max<u64>(1, distance / 50);
#ifdef DEBUG
std::cout << "Raw Distance: " << distance
<< " | Approximated Tiles: " << flower_distance << std::endl;
#endif
if (x <= area_x_left_bound && area_x_right_bound >= x &&
y <= area_y_top_bound && area_y_bottom_bound >= y) {
walk(flower_distance, forwards_left);
continue;
}
if (x >= area_x_left_bound && area_x_right_bound <= x &&
y <= area_y_top_bound && area_y_bottom_bound >= y) {
walk(flower_distance, forwards_right);
continue;
}
if (x <= area_x_left_bound && area_x_right_bound >= x &&
y >= area_y_top_bound && area_y_bottom_bound <= y) {
walk(flower_distance, backwards_left);
continue;
}
if (x >= area_x_left_bound && area_x_right_bound <= x &&
y >= area_y_top_bound && area_y_bottom_bound <= y) {
walk(flower_distance, backwards_right);
continue;
}
if (x <= area_x_left_bound && area_x_right_bound >= x) {
walk(flower_distance, left);
continue;
}
if (x >= area_x_left_bound && area_x_right_bound <= x) {
walk(flower_distance, right);
continue;
}
if (y <= area_y_top_bound && area_y_bottom_bound >= y) {
walk(flower_distance, forwards);
continue;
}
if (y >= area_y_top_bound && area_y_bottom_bound <= y) {
walk(flower_distance, backwards);
continue;
}
} else {
if (search_area_negate_x > 0) {
search_area_negate_x -= 100;
}
if (search_area_negate_y > 0) {
search_area_negate_y -= 50;
}
tolerance += 3;
if (search_area_negate_x < 0 && search_area_negate_y < 0) {
if (this->running) {
this->machine_state->placed_sprinkler = false;
this->place_sprinkler();
}
// this->output->key_up("w");
// this->output->key_up("a");
// this->output->key_up("s");
// this->output->key_up("d");
#ifdef DEBUG
std::cout << "FAIL_SAFE" << std::endl;
#endif
return;
}
}
sleep(20);
} while (this->running && collect_timer_check() &&
(search_area_negate_x >= 0 || search_area_negate_y >= 0) &&
!image_search(pBMArea, bitmaps["pBMSupremeSaturator"], nullptr,
nullptr, area_x_left_bound, area_y_top_bound,
area_x_right_bound, area_y_bottom_bound, tolerance));
// if (this->running) {
// this->machine_state->placed_sprinkler = false;
// this->place_sprinkler();
// }
// this->output->key_up("w");
// this->output->key_up("a");
// this->output->key_up("s");
// this->output->key_up("d");
}
void APPLICATION::to_field() {
#ifdef DEBUG
std::cout << "GOING TO FIELD" << std::endl;
#endif
json field_data =
this->raw_data->RAW_FIELDS_DATA
[this->interface->FIELD_OPTIONS[this->settings->selected_field]];
const std::string field_name = field_data["name"];
auto it = fields_impl().find(field_name);
if (it != fields_impl().end()) {
it->second(false);
}
}
void APPLICATION::to_red_cannon() {
auto it = sub_macros().find("red_cannon");
if (it != sub_macros().end()) {
it->second();
}
}
void APPLICATION::align_in_field() {
const std::string position_name =
this->interface->DIRECTION_OPTIONS[this->settings->direction];
auto it = sub_macros().find(position_name);
if (it != sub_macros().end()) {
it->second();
}
}
void APPLICATION::place_sprinkler() {
this->output->key_press("1");
this->machine_state->placed_sprinkler = true;
}
void APPLICATION::convert() {
BITMAP pBMArea = this->input->capture_display(790, 70, 60, 60);
#ifdef DEBUG
pBMArea.save_png("captured_E.png", 4);
#endif
if (this->running && this->machine_state->at_hive) {
if (!image_search(pBMArea, bitmaps["pBMButtonE"], nullptr, nullptr, 0, 0,
pBMArea.width, pBMArea.width, 12)) {
this->machine_state->converting = false;
return;
}
}
this->machine_state->converting = true;
this->output->key_press("e");
this->use_hotbar(HOTBAR_USE_METHOD::On_Convert);
while (this->running && this->machine_state->at_hive &&
this->machine_state->converting) {
sleep(1000);
if (image_search(pBMArea, bitmaps["pBMButtonE"], nullptr, nullptr, 0, 0,
pBMArea.width, pBMArea.width, 12)) {
this->machine_state->converting = true;
pBMArea = this->input->capture_display(790, 70, 60, 60);
#ifdef DEBUG
pBMArea.save_png("captured_E.png", 4);
#endif
continue;
} else {
this->machine_state->converting = false;
break;
}
}
}
void APPLICATION::finish_collect() {
if (this->running && this->machine_state->collecting == false) {
this->machine_state->at_hive = false;
this->machine_state->converting = false;
this->machine_state->collecting = false;
this->machine_state->placed_sprinkler = false;
this->machine_state->checked_mondo = false;
this->machine_state->drift_comp_collection_tick = 0;
if (this->settings->walk_to_hive == false) {
this->output->key_press("Escape");
sleep(50);
this->output->key_press("r");
sleep(50);
this->output->key_press("Return");
sleep(5 * 1000);
} else {
return;
}
}
}
void APPLICATION::align_mouse() { this->output->mouse_move(348, 128); }
bool APPLICATION::mondo() {
if (this->running && this->settings->mondo) {
if (get_utc_minute() > 15) {
this->machine_state->checked_mondo = false;
return false;
}
if (this->machine_state->checked_mondo) {
return false;
}
this->machine_state->checked_mondo = true;
this->machine_state->collecting = false;
auto it = sub_macros().find("mondo");
if (it != sub_macros().end()) {
it->second();
return true;
}
return false;
}
return false;
}
void APPLICATION::use_hotbar(HOTBAR_USE_METHOD method) {
if (static_cast<HOTBAR_USE_METHOD>(this->settings->slot_2) == method) {
this->output->key_press("2");
}
if (static_cast<HOTBAR_USE_METHOD>(this->settings->slot_3) == method) {
this->output->key_press("3");
}
if (static_cast<HOTBAR_USE_METHOD>(this->settings->slot_4) == method) {
this->output->key_press("4");
}
if (static_cast<HOTBAR_USE_METHOD>(this->settings->slot_5) == method) {
this->output->key_press("5");
}
if (static_cast<HOTBAR_USE_METHOD>(this->settings->slot_6) == method) {
this->output->key_press("6");
}
if (static_cast<HOTBAR_USE_METHOD>(this->settings->slot_7) == method) {
this->output->key_press("7");
}
}
bool APPLICATION::clock() {
if (!this->settings->clock) {
return false;
}
bool can_collect =
(since_boot() - this->machine_state->last_clock_check) >= (60 * 60);
if (can_collect || this->machine_state->last_clock_check == 0) {
this->machine_state->last_clock_check = since_boot();
auto it = sub_macros().find("clock");
if (it != sub_macros().end()) {
it->second();
}
return true;
}
return false;
}
void APPLICATION::step() {
this->align_mouse();
while (this->running && !this->machine_state->at_hive) {
this->check_hive();
wait_for(1000);
}
wait_for(1000);
this->convert();
this->align_mouse();
wait_for(3000);
this->machine_state->converting = false;
this->machine_state->at_hive = false;
this->to_red_cannon();
this->align_mouse();
if (this->clock()) {
return;
}
if (this->mondo()) {
this->use_hotbar(HOTBAR_USE_METHOD::On_Mondo);
sleep(1000 * application_pointer->settings->mondo_wait);
return;
}
this->to_field();
this->align_mouse();
wait_for(1000);
this->align_in_field();
this->align_mouse();
wait_for(1000);
if (!this->machine_state->collecting) {
#ifdef DEBUG
std::cout << "COLLECTING" << std::endl;
#endif
this->machine_state->collecting_begin = since_boot();
this->machine_state->collecting = true;
if (!this->machine_state->placed_sprinkler) {
this->place_sprinkler();
}
this->use_hotbar(HOTBAR_USE_METHOD::Gather_Start);
while (this->running && this->machine_state->collecting &&
this->collect_timer_check()) {
this->action_collect();
this->align_mouse();
if (this->mondo()) {
this->use_hotbar(HOTBAR_USE_METHOD::On_Mondo);
sleep(1000 * application_pointer->settings->mondo_wait);
return;
}
if (this->settings->drift_comp) {
this->machine_state->drift_comp_collection_tick++;
if (this->machine_state->drift_comp_collection_tick >= 2) {
this->machine_state->drift_comp_collection_tick = 0;
this->action_drift_comp();
}
}
wait_for(20);
}
this->machine_state->collecting = false;
#ifdef DEBUG
std::cout << "COLLECTION ENDED" << std::endl;
#endif
}
this->align_mouse();
this->finish_collect();
sleep(1000);
}
void APPLICATION::start() {
if (this->interface->is_waiting_for_start_key ||
this->interface->is_waiting_for_stop_key) {
return;
}
if (this->running)
return;
this->running = true;
this->machine_state->at_hive = false;
this->machine_state->converting = false;
this->machine_state->collecting = false;
this->machine_state->placed_sprinkler = false;
this->machine_state->checked_mondo = false;
std::thread([this]() {
while (this->running) {
this->step();
wait_for(20);
}
}).detach();
}
void APPLICATION::stop() {
if (this->interface->is_waiting_for_start_key ||
this->interface->is_waiting_for_stop_key) {
return;
}
for (int keycode = 8; keycode < 256; ++keycode) {
XTestFakeKeyEvent(this->output->display, keycode, False, 0);
}
for (int button = 1; button <= 5; ++button) {
XTestFakeButtonEvent(this->output->display, button, False, 0);
}
XFlush(this->output->display);
this->running = false;
}
void APPLICATION::main() {
this->interface->REHOOK_KEY_EVENT->connect(
[this](const std::string &key, REHOOK_KEY_EVENT_TYPE kind) {
switch (kind) {
case REHOOK_KEY_EVENT_TYPE::START_KEY:
this->input->unregister_hotkey(this->settings->start_key);
this->input->register_hotkey(key,
[this]() -> void { this->start(); });
break;
case REHOOK_KEY_EVENT_TYPE::STOP_KEY:
this->input->unregister_hotkey(this->settings->stop_key);
this->input->register_hotkey(key, [this]() -> void { this->stop(); });
break;
default:
break;
}
});
this->input->register_hotkey(this->settings->start_key,
[this]() -> void { this->start(); });
this->input->register_hotkey(this->settings->stop_key,
[this]() -> void { this->stop(); });
this->input->start();
}