Skip to content

Commit a16a84d

Browse files
author
Matt
committed
working for sp/mp, save last fov in configfile in appdata, change fov with +/-
1 parent 1501a98 commit a16a84d

File tree

4 files changed

+92
-101
lines changed

4 files changed

+92
-101
lines changed

MW3FovChanger/MW3FovChanger.vcxproj.filters

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
</Filter>
1515
</ItemGroup>
1616
<ItemGroup>
17-
<ClCompile Include="src\main.cpp">
18-
<Filter>main</Filter>
19-
</ClCompile>
2017
<ClCompile Include="src\processhook.cpp">
2118
<Filter>process/mem</Filter>
2219
</ClCompile>
2320
<ClCompile Include="src\fovchanger.cpp">
2421
<Filter>fovchanger</Filter>
2522
</ClCompile>
23+
<ClCompile Include="src\main.cpp">
24+
<Filter>main</Filter>
25+
</ClCompile>
2626
</ItemGroup>
2727
<ItemGroup>
2828
<ClInclude Include="src\processhook.h">

MW3FovChanger/src/fovchanger.cpp

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,39 @@
44
#include <ShlObj.h>
55
#include <Shlwapi.h>
66
#include <string>
7-
#include <sstream>
87

98
fov::Changer::Changer(float fov)
109
:fov(fov)
1110
{
11+
CHAR szPath[MAX_PATH];
12+
13+
if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_APPDATA, NULL, 0, szPath))) {
14+
15+
strcat_s(szPath, "\\mw3fovchanger\\config.cfg");
16+
17+
OFSTRUCT reopenbuff;
18+
HFILE hfile = OpenFile(szPath, &reopenbuff, OF_READ);
19+
20+
if (hfile != HFILE_ERROR) {
21+
22+
char buf[64];
23+
DWORD bytesread;
24+
if (ReadFile((HANDLE)hfile, buf, 64, &bytesread, NULL)) {
25+
26+
buf[bytesread] = '\0';
27+
float configFov = std::strtof(buf, nullptr);
28+
29+
this->fov = configFov;
30+
}
31+
32+
CloseHandle((HANDLE)hfile);
33+
}
34+
}
35+
}
36+
37+
fov::Changer::~Changer()
38+
{
39+
fov::updateConfig(fov);
1240
}
1341

1442
void fov::Changer::setfov_sp(const HANDLE hProc) const
@@ -43,23 +71,21 @@ void fov::Changer::setfov_mp(const HANDLE hProc) const
4371
while (WriteProcessMemory(hProc, (LPVOID)fovmemaddress, &fov, sizeof(float), NULL)) Sleep(100);
4472
}
4573

46-
fov::SettingsManager::SettingsManager(Changer * const pchanger)
47-
{
48-
}
49-
50-
void fov::SettingsManager::safeDefaultFov(float newfov)
74+
void fov::updateConfig(float fov)
5175
{
5276
TCHAR szPath[MAX_PATH];
5377

5478
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szPath))) {
5579

56-
wcscat_s(szPath, L"\\mw3fovchanger\\config.cfg");
80+
wcscat_s(szPath, L"\\mw3fovchanger");
81+
CreateDirectory(szPath, NULL);
82+
83+
wcscat_s(szPath, L"\\config.cfg");
5784
HANDLE hFile = CreateFile(szPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
5885

59-
std::stringstream ss;
60-
ss << newfov;
86+
if (hFile == INVALID_HANDLE_VALUE) return;
6187

62-
std::string s = ss.str();
88+
std::string s = std::to_string(fov);
6389

6490
WriteFile(hFile, s.c_str(), s.length(), NULL, NULL);
6591

MW3FovChanger/src/fovchanger.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ namespace fov {
66

77
class Changer {
88

9-
friend class SettingsManager;
10-
119
public:
1210
Changer(float fov = 90.f);
13-
virtual ~Changer() = default;
11+
virtual ~Changer();
1412

1513
/*fov changing functions for singleplayer, this method blocks execution*/
1614
void setfov_sp(const HANDLE hProc) const;
@@ -32,15 +30,6 @@ namespace fov {
3230
float fov;
3331
};
3432

35-
class SettingsManager {
36-
37-
public:
38-
39-
SettingsManager(Changer* const pchanger);
40-
virtual ~SettingsManager() = default;
41-
42-
void safeDefaultFov(float newfov);
43-
};
44-
33+
void updateConfig(float fov);
4534
}
4635

MW3FovChanger/src/main.cpp

Lines changed: 51 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -2,111 +2,87 @@
22
#include <iostream>
33
#include "processhook.h"
44
#include "FovChanger.h"
5-
#include <thread>
5+
#include <future>
6+
#include <memory>
67

78
#define VK_KEY_1 0x31
89

9-
/*this method blocks execution*/
10-
void userInputForFovChanger(fov::Changer* const pchanger);
11-
1210
int main(int argc, char** argv) {
1311

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;
2415

25-
//Singleplayer
26-
pid = processhook::GetProcessId("Call of Duty®: Modern Warfare® 3");
27-
if (pid) {
16+
std::cout << "Please start MW3..." << std::endl;
2817

29-
hProc = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
18+
while (true) {
3019

31-
if (hProc) {
20+
fov::Changer fovchanger;
3221

33-
std::cout << "Attached to MW3" << std::endl;
22+
/*Connect to process*/
23+
DWORD pid = 0;
24+
HANDLE hProc = NULL;
3425

35-
MessageBeep(MB_OKCANCEL);
36-
fovchanger.setfov_sp(hProc);
37-
}
26+
std::unique_ptr<std::future<void>> worker;
3827

39-
break;
40-
}
28+
/*Connect to either, MP or SP*/
29+
while (!pid) {
4130

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) {
4534

46-
hProc = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
35+
hProc = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
4736

48-
if (hProc) {
37+
if (hProc) {
4938

50-
std::cout << "Attached to MW3" << std::endl;
39+
std::cout << "Attached to MW3" << std::endl;
5140

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+
}
5445
}
5546

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) {
6650

67-
return EXIT_SUCCESS;
68-
}
51+
hProc = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
6952

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) {
7654

77-
std::cout << "Please start MW3..." << std::endl;
55+
std::cout << "Attached to MW3" << std::endl;
7856

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+
}
8262

83-
if (GetAsyncKeyState(VK_KEY_1)) {
63+
Sleep(100);
64+
}
8465

85-
std::cout << "Enter new fov[0 - 180]: ";
66+
while (worker->wait_for(std::chrono::milliseconds(25)) != std::future_status::ready) {
8667

87-
float fov;
88-
std::cin >> fov;
68+
if (GetAsyncKeyState(VK_ADD)) {
8969

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);
9373
}
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);
9779
}
9880
}
99-
else if (GetAsyncKeyState(VK_ADD)) {
10081

101-
float oldfov = pchanger->getFov();
102-
pchanger->changeFov(oldfov + 5.f);
103-
}
104-
else if (GetAsyncKeyState(VK_SUBTRACT)) {
82+
CloseHandle(hProc);
10583

106-
float oldfov = pchanger->getFov();
107-
pchanger->changeFov(oldfov - 5.f);
108-
}
109-
110-
Sleep(100);
84+
std::cout << "Detached from MW3" << std::endl;
11185
}
86+
87+
return EXIT_SUCCESS;
11288
}

0 commit comments

Comments
 (0)