-
Notifications
You must be signed in to change notification settings - Fork 226
/
TiltedOnlineApp.cpp
126 lines (91 loc) · 3.1 KB
/
TiltedOnlineApp.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
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
#include <TiltedOnlinePCH.h>
#include <TiltedOnlineApp.h>
#include <DInputHook.hpp>
#include <WindowsHook.hpp>
#include <World.h>
#include <spdlog/spdlog.h>
#include <spdlog/sinks/rotating_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <Systems/RenderSystemD3D11.h>
#include <Services/OverlayService.h>
#include <Services/ImguiService.h>
#include <Services/DiscordService.h>
#include <ScriptExtender.h>
#include <NvidiaUtil.h>
using TiltedPhoques::Debug;
TiltedOnlineApp::TiltedOnlineApp()
{
// Set console code page to UTF-8 so console known how to interpret string data
SetConsoleOutputCP(CP_UTF8);
auto logPath = TiltedPhoques::GetPath() / "logs";
std::error_code ec;
create_directory(logPath, ec);
auto rotatingLogger = std::make_shared<spdlog::sinks::rotating_file_sink_mt>(logPath / "tp_client.log", 1048576 * 5, 3);
// rotatingLogger->set_level(spdlog::level::debug);
auto console = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
console->set_pattern("%^[%H:%M:%S.%e] [%l] [tid %t] %$ %v");
auto logger = std::make_shared<spdlog::logger>("", spdlog::sinks_init_list{console, rotatingLogger});
set_default_logger(logger);
}
TiltedOnlineApp::~TiltedOnlineApp() = default;
void* TiltedOnlineApp::GetMainAddress() const
{
POINTER_SKYRIMSE(void, winMain, 36544);
return winMain.GetPtr();
}
bool TiltedOnlineApp::BeginMain()
{
World::Create();
World::Get().ctx().at<DiscordService>().Init();
World::Get().ctx().emplace<RenderSystemD3D11>(World::Get().ctx().at<OverlayService>(), World::Get().ctx().at<ImguiService>());
LoadScriptExender();
// TODO: Figure out a way to un-blacklist NvCamera64.dll (see DllBlocklist.cpp). Then this hack can be removed
if (IsNvidiaOverlayLoaded())
ApplyNvidiaFix();
return true;
}
bool TiltedOnlineApp::EndMain()
{
UninstallHooks();
if (m_pDevice)
m_pDevice->Release();
return true;
}
void TiltedOnlineApp::Update()
{
// Every frame make sure we won't use preprocessed facegen
POINTER_SKYRIMSE(uint32_t, bUseFaceGenPreprocessedHeads, 378620);
*bUseFaceGenPreprocessedHeads = 0;
// Make sure the window stays active
POINTER_SKYRIMSE(uint32_t, bAlwaysActive, 380768);
*bAlwaysActive = 1;
World::Get().Update();
}
bool TiltedOnlineApp::Attach()
{
TiltedPhoques::Debug::OnAttach();
// TiltedPhoques::Nop(0x1405D3FA1, 6);
return true;
}
bool TiltedOnlineApp::Detach()
{
TiltedPhoques::Debug::OnDetach();
return true;
}
void TiltedOnlineApp::InstallHooks2()
{
TiltedPhoques::Initializer::RunAll();
TiltedPhoques::DInputHook::Install();
}
void TiltedOnlineApp::UninstallHooks()
{
}
void TiltedOnlineApp::ApplyNvidiaFix() noexcept
{
auto d3dFeatureLevelOut = D3D_FEATURE_LEVEL_11_0;
HRESULT hr = CreateEarlyDxDevice(&m_pDevice, &d3dFeatureLevelOut);
if (FAILED(hr))
spdlog::error("D3D11CreateDevice failed. Detected an NVIDIA GPU, error code={0:x}", hr);
if (d3dFeatureLevelOut < D3D_FEATURE_LEVEL_11_0)
spdlog::warn("Unexpected D3D11 feature level detected (< 11.0), may cause issues");
}