Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
119 lines (96 loc) · 4.4 KB
/
Copy pathmain.cpp
File metadata and controls
119 lines (96 loc) · 4.4 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
#include <TiltedOnlineApp.h>
#include <TiltedOnlinePCH.h>
#include <ScriptExtender.h>
#include <VRAddressMap.h>
#include <Commctrl.h>
#include <Windows.h>
#include <base/dialogues/win/TaskDialog.h>
// 1 - Steam, 2 - GOG
#if TP_SKYRIMVR
// SkyrimVR is Steam only and has had a single build for years, so both entries are the same. The
// generated VR address table is version independent, so this check is the only thing enforcing it.
inline constexpr std::string_view kSupportedGameVersions[2] = {"1.4.15.0", "1.4.15.0"};
inline constexpr std::string_view kGameName = "Skyrim VR";
#else
inline constexpr std::string_view kSupportedGameVersions[2] = {"1.7.104.0", "1.7.104.0"};
inline constexpr std::string_view kGameName = "Skyrim SE";
#endif
std::unique_ptr<TiltedOnlineApp> g_appInstance{nullptr};
extern HICON g_SharedWindowIcon;
static void ShowAddressLibraryError(const wchar_t* apGamePath)
{
#if TP_SKYRIMVR
auto errorDetail = fmt::format(L"Game path: {}", apGamePath);
#else
auto errorDetail = fmt::format(L"Looking for it here: {}\\Data\\SKSE\\Plugins", apGamePath);
#endif
#if TP_SKYRIMVR
// VR carries its address table in the binary, so there is nothing for the user to install.
// Reaching this means the game version string could not be read.
Base::TaskDialog dia(g_SharedWindowIcon, L"Error", L"Failed to read the Skyrim VR version", L"Skyrim Together VR expects SkyrimVR.exe 1.4.15.0", errorDetail.c_str());
dia.Show();
#else
Base::TaskDialog dia(g_SharedWindowIcon, L"Error", L"Failed to load Skyrim Address Library", L"Make sure to use \"All in one\"", errorDetail.c_str());
dia.AppendButton(0xBEED, L"Visit troubleshooting page on wiki.tiltedphoques.com");
dia.AppendButton(0xBEEF, L"Visit Address Library modpage on nexusmods.com");
const int result = dia.Show();
if (result == 0xBEEF)
{
ShellExecuteW(nullptr, L"open", LR"(https://www.nexusmods.com/skyrimspecialedition/mods/32444?tab=files)", nullptr, nullptr, SW_SHOWNORMAL);
}
else if (result == 0xBEED)
{
ShellExecuteW(nullptr, L"open", LR"(https://wiki.tiltedphoques.com/tilted-online/guides/troubleshooting/address-library-error)", nullptr, nullptr, SW_SHOWNORMAL);
}
#endif
exit(4);
}
static void ShowIncompatibleVersionError(const char* apDetectedGameVersion, const wchar_t* apGamePath)
{
constexpr wchar_t kModPageUrl[] = LR"(https://www.nexusmods.com/skyrimspecialedition/mods/69993?tab=files)";
const auto [steamVer, gogVer] = kSupportedGameVersions;
std::string supportedVersions = steamVer != gogVer ? fmt::format("{} (or {} if GOG)", steamVer, gogVer) : std::string{steamVer};
std::string message = fmt::format("Skyrim Together {} requires {} {}, but your installed version is {}\n\nUpdate or downgrade to match, then relaunch", BUILD_COMMIT + 1, kGameName, supportedVersions, apDetectedGameVersion);
std::wstring wideMessage(message.begin(), message.end());
const auto optionalDetails = fmt::format(L"Installed here: {}", apGamePath);
Base::TaskDialog dia(g_SharedWindowIcon, L"Error", L"Incompatible game version", wideMessage.c_str(), optionalDetails.c_str());
#if TP_SKYRIMVR
// The nexus page that button opens is the Skyrim SE build, which is not this one.
dia.Show();
#else
dia.AppendButton(0xBEEF, L"Visit Skyrim Together mod page on nexusmods.com");
if (dia.Show() == 0xBEEF)
{
ShellExecuteW(nullptr, L"open", kModPageUrl, nullptr, nullptr, SW_SHOWNORMAL);
}
#endif
exit(4);
}
void RunTiltedInit(const std::filesystem::path& acGamePath, const String& aExeVersion)
{
if (!VersionDb::Get().Load(acGamePath, aExeVersion))
{
ShowAddressLibraryError(acGamePath.c_str());
}
auto [steamVer, gogVer] = kSupportedGameVersions;
if (aExeVersion != steamVer && aExeVersion != gogVer)
{
ShowIncompatibleVersionError(aExeVersion.c_str(), acGamePath.c_str());
}
g_appInstance = std::make_unique<TiltedOnlineApp>();
#if TP_SKYRIMVR
// Constructing the app is what creates the tp_client.log sink, so the address table summary
// has to be written from here to end up in the log file rather than only on the console.
VRAddresses::LogSummary();
#endif
TiltedOnlineApp::InstallHooks2();
TP_HOOK_COMMIT;
#if !TP_SKYRIMVR
// VR starts SKSE from TiltedOnlineApp::BeginMain instead, see the note there.
LoadScriptExtender();
#endif
}
void RunTiltedApp()
{
g_appInstance->BeginMain();
}