forked from Hal47/dsfix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
88 lines (77 loc) · 2.48 KB
/
main.cpp
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
#include "version.h"
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
#include "main.h"
#include "Detouring.h"
#include "FPS.h"
#include "Settings.h"
#include "util.h"
#include "dinput.h"
#include "ui.h"
#include "RenderstateManager.h"
#include "d3d9int.h"
#include "d3d9dev.h"
#include <filesystem>
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/spdlog.h>
#include <windows.h>
namespace fs = std::filesystem;
HMODULE g_hDll;
void loadOriginalDinput8dll() {
fs::path dinput8Filename = GetSystemDirectoryPath() / L"dinput8.dll";
HMODULE hMod = ::LoadLibraryW(dinput8Filename.c_str());
if (!hMod) {
spdlog::debug(L"Could not load original dinput8.dll");
spdlog::debug(L"ABORTING.");
std::exit(1);
}
oDirectInput8Create = (decltype(DirectInput8Create)*)::GetProcAddress(hMod, "DirectInput8Create");
}
void onDllProcessAttach() {
auto logger = spdlog::basic_logger_st("dsfix", GetModuleDirectoryPath() / L"dsfix.log", true);
spdlog::set_default_logger(logger);
spdlog::set_level(spdlog::level::debug);
Settings::get().load();
Settings::get().report();
loadOriginalDinput8dll();
startDetour();
spdlog::set_level(static_cast<spdlog::level::level_enum>(Settings::get().getLogLevel()));
spdlog::info("===== start DSfix {} = fn: {}", DXVK_VERSION, GetModuleFileNamePath(nullptr).string());
if (Settings::get().getSkipIntro())
ApplyDS1Patches();
}
void onDllProcessDetach() {
spdlog::info("shutting down");
Settings::get().shutdown();
removeFPSHook();
endDetour();
}
// here the dependency injection (DI) happens
void onD3DCreateDevice() {
static bool s_initialized = false;
if (s_initialized)
return;
RSManager* pRSManager = new RSManager(g_pDevice->getDevice());
g_pDevice->setRSManager(pRSManager);
Ui* pUi = new Ui(g_pDevice.Get(), pRSManager);
g_pDevice->setUi(pUi);
initFPSTimer();
if (Settings::get().getUnlockFPS())
applyFPSPatch();
s_initialized = true;
spdlog::debug("onDirect3D9Create finished");
}
DWORD WINAPI ThreadProc(LPVOID lpThreadParameter) {
onDllProcessAttach();
return ERROR_SUCCESS;
}
BOOL WINAPI DllMain(HMODULE hDll, DWORD dwReason, PVOID pvReserved) {
if (dwReason == DLL_PROCESS_ATTACH) {
g_hDll = hDll;
::DisableThreadLibraryCalls(hDll);
::CreateThread(nullptr, 0, ThreadProc, nullptr, 0, nullptr);
return TRUE;
} else if (dwReason == DLL_PROCESS_DETACH) {
// onDllProcessDetach();
}
return FALSE;
}