|
2 | 2 | #include <iostream> |
3 | 3 | #include "processhook.h" |
4 | 4 | #include "FovChanger.h" |
5 | | -#include <thread> |
| 5 | +#include <future> |
| 6 | +#include <memory> |
6 | 7 |
|
7 | 8 | #define VK_KEY_1 0x31 |
8 | 9 |
|
9 | | -/*this method blocks execution*/ |
10 | | -void userInputForFovChanger(fov::Changer* const pchanger); |
11 | | - |
12 | 10 | int main(int argc, char** argv) { |
13 | 11 |
|
14 | | - fov::Changer fovchanger; |
15 | | - |
16 | | - std::thread uithread(userInputForFovChanger, &fovchanger); |
17 | | - |
18 | | - /*Connect to process*/ |
19 | | - DWORD pid = 0; |
20 | | - HANDLE hProc = NULL; |
21 | | - |
22 | | - /*Connect to either, MP or SP*/ |
23 | | - while (!pid) { |
| 12 | + std::cout << "MW3 Fov Changer (Developed with love by Mesinger)" << std::endl; |
| 13 | + std::cout << "[+[NUMPAD]] Increase FOV by 5" << std::endl; |
| 14 | + std::cout << "[-[NUMPAD]] Decrease FOV by 5" << std::endl << std::endl; |
24 | 15 |
|
25 | | - //Singleplayer |
26 | | - pid = processhook::GetProcessId("Call of Duty®: Modern Warfare® 3"); |
27 | | - if (pid) { |
| 16 | + std::cout << "Please start MW3..." << std::endl; |
28 | 17 |
|
29 | | - hProc = OpenProcess(PROCESS_ALL_ACCESS, 0, pid); |
| 18 | + while (true) { |
30 | 19 |
|
31 | | - if (hProc) { |
| 20 | + fov::Changer fovchanger; |
32 | 21 |
|
33 | | - std::cout << "Attached to MW3" << std::endl; |
| 22 | + /*Connect to process*/ |
| 23 | + DWORD pid = 0; |
| 24 | + HANDLE hProc = NULL; |
34 | 25 |
|
35 | | - MessageBeep(MB_OKCANCEL); |
36 | | - fovchanger.setfov_sp(hProc); |
37 | | - } |
| 26 | + std::unique_ptr<std::future<void>> worker; |
38 | 27 |
|
39 | | - break; |
40 | | - } |
| 28 | + /*Connect to either, MP or SP*/ |
| 29 | + while (!pid) { |
41 | 30 |
|
42 | | - //Multiplayer |
43 | | - pid = processhook::GetProcessId("Call of Duty®: Modern Warfare® 3 Multiplayer"); |
44 | | - if (pid) { |
| 31 | + //Singleplayer |
| 32 | + pid = processhook::GetProcessId("Call of Duty®: Modern Warfare® 3"); |
| 33 | + if (pid) { |
45 | 34 |
|
46 | | - hProc = OpenProcess(PROCESS_ALL_ACCESS, 0, pid); |
| 35 | + hProc = OpenProcess(PROCESS_ALL_ACCESS, 0, pid); |
47 | 36 |
|
48 | | - if (hProc) { |
| 37 | + if (hProc) { |
49 | 38 |
|
50 | | - std::cout << "Attached to MW3" << std::endl; |
| 39 | + std::cout << "Attached to MW3" << std::endl; |
51 | 40 |
|
52 | | - MessageBeep(MB_OKCANCEL); |
53 | | - fovchanger.setfov_mp(hProc); |
| 41 | + MessageBeep(MB_OKCANCEL); |
| 42 | + worker = std::make_unique<std::future<void>>(std::async(&fov::Changer::setfov_sp, &fovchanger, hProc)); |
| 43 | + break; |
| 44 | + } |
54 | 45 | } |
55 | 46 |
|
56 | | - break; |
57 | | - } |
58 | | - |
59 | | - Sleep(100); |
60 | | - } |
61 | | - |
62 | | - CloseHandle(hProc); |
63 | | - uithread.join(); |
64 | | - |
65 | | - MessageBeep(MB_OKCANCEL); |
| 47 | + //Multiplayer |
| 48 | + pid = processhook::GetProcessId("Call of Duty®: Modern Warfare® 3 Multiplayer"); |
| 49 | + if (pid) { |
66 | 50 |
|
67 | | - return EXIT_SUCCESS; |
68 | | -} |
| 51 | + hProc = OpenProcess(PROCESS_ALL_ACCESS, 0, pid); |
69 | 52 |
|
70 | | -void userInputForFovChanger(fov::Changer* const pchanger) |
71 | | -{ |
72 | | - std::cout << "MW3 Fov Changer (Developed with love by Mesinger)" << std::endl; |
73 | | - std::cout << "[1] Set default FOV" << std::endl; |
74 | | - std::cout << "[+] Increase FOV by 5" << std::endl; |
75 | | - std::cout << "[-] Decrease FOV by 5" << std::endl << std::endl; |
| 53 | + if (hProc) { |
76 | 54 |
|
77 | | - std::cout << "Please start MW3..." << std::endl; |
| 55 | + std::cout << "Attached to MW3" << std::endl; |
78 | 56 |
|
79 | | - fov::SettingsManager fovmgr(pchanger); |
80 | | - |
81 | | - while (true) { |
| 57 | + MessageBeep(MB_OKCANCEL); |
| 58 | + worker = std::make_unique<std::future<void>>(std::async(&fov::Changer::setfov_mp, &fovchanger, hProc)); |
| 59 | + break; |
| 60 | + } |
| 61 | + } |
82 | 62 |
|
83 | | - if (GetAsyncKeyState(VK_KEY_1)) { |
| 63 | + Sleep(100); |
| 64 | + } |
84 | 65 |
|
85 | | - std::cout << "Enter new fov[0 - 180]: "; |
| 66 | + while (worker->wait_for(std::chrono::milliseconds(25)) != std::future_status::ready) { |
86 | 67 |
|
87 | | - float fov; |
88 | | - std::cin >> fov; |
| 68 | + if (GetAsyncKeyState(VK_ADD)) { |
89 | 69 |
|
90 | | - if (!std::cin.fail()) { |
91 | | - std::cout << std::endl << "Invalid input" << std::endl; |
92 | | - continue; |
| 70 | + float oldfov = fovchanger.getFov(); |
| 71 | + fovchanger.changeFov(oldfov + 5.f); |
| 72 | + Sleep(125); |
93 | 73 | } |
94 | | - |
95 | | - if (pchanger->changeFov(fov)) { |
96 | | - fovmgr.safeDefaultFov(fov); |
| 74 | + else if (GetAsyncKeyState(VK_SUBTRACT)) { |
| 75 | + |
| 76 | + float oldfov = fovchanger.getFov(); |
| 77 | + fovchanger.changeFov(oldfov - 5.f); |
| 78 | + Sleep(125); |
97 | 79 | } |
98 | 80 | } |
99 | | - else if (GetAsyncKeyState(VK_ADD)) { |
100 | 81 |
|
101 | | - float oldfov = pchanger->getFov(); |
102 | | - pchanger->changeFov(oldfov + 5.f); |
103 | | - } |
104 | | - else if (GetAsyncKeyState(VK_SUBTRACT)) { |
| 82 | + CloseHandle(hProc); |
105 | 83 |
|
106 | | - float oldfov = pchanger->getFov(); |
107 | | - pchanger->changeFov(oldfov - 5.f); |
108 | | - } |
109 | | - |
110 | | - Sleep(100); |
| 84 | + std::cout << "Detached from MW3" << std::endl; |
111 | 85 | } |
| 86 | + |
| 87 | + return EXIT_SUCCESS; |
112 | 88 | } |
0 commit comments