mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-09 17:44:38 +01:00
Implement xiv fixes into Dalamud.Boot (#857)
This commit is contained in:
parent
02dd1eddec
commit
75de126c9d
40 changed files with 41576 additions and 196 deletions
|
|
@ -1,86 +1,40 @@
|
|||
#include "pch.h"
|
||||
|
||||
#include "bootconfig.h"
|
||||
#include "logging.h"
|
||||
#include "veh.h"
|
||||
#include "xivfixes.h"
|
||||
|
||||
HMODULE g_hModule;
|
||||
HINSTANCE g_hGameInstance = GetModuleHandleW(nullptr);
|
||||
|
||||
bool check_env_var(std::string name)
|
||||
{
|
||||
size_t required_size;
|
||||
getenv_s(&required_size, nullptr, 0, name.c_str());
|
||||
if (required_size > 0)
|
||||
{
|
||||
if (char* is_no_veh = static_cast<char*>(malloc(required_size * sizeof(char))))
|
||||
{
|
||||
getenv_s(&required_size, is_no_veh, required_size, name.c_str());
|
||||
auto result = _stricmp(is_no_veh, "true");
|
||||
free(is_no_veh);
|
||||
if (result == 0)
|
||||
return true;
|
||||
}
|
||||
DllExport DWORD WINAPI Initialize(LPVOID lpParam, HANDLE hMainThreadContinue) {
|
||||
if (bootconfig::is_show_console())
|
||||
ConsoleSetup(L"Dalamud Boot");
|
||||
|
||||
if (bootconfig::is_wait_messagebox())
|
||||
MessageBoxW(nullptr, L"Press OK to continue", L"Dalamud Boot", MB_OK);
|
||||
|
||||
try {
|
||||
xivfixes::apply_all(true);
|
||||
} catch (const std::exception& e) {
|
||||
logging::print<logging::W>("Failed to do general fixups. Some things might not work.");
|
||||
logging::print<logging::W>("Error: {}", e.what());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
logging::print<logging::I>("Dalamud.Boot Injectable, (c) 2021 XIVLauncher Contributors");
|
||||
logging::print<logging::I>("Built at : " __DATE__ "@" __TIME__);
|
||||
|
||||
bool is_running_on_linux()
|
||||
{
|
||||
size_t required_size;
|
||||
getenv_s(&required_size, nullptr, 0, "XL_WINEONLINUX");
|
||||
if (required_size > 0)
|
||||
{
|
||||
if (char* is_wine_on_linux = static_cast<char*>(malloc(required_size * sizeof(char))))
|
||||
{
|
||||
getenv_s(&required_size, is_wine_on_linux, required_size, "XL_WINEONLINUX");
|
||||
auto result = _stricmp(is_wine_on_linux, "true");
|
||||
free(is_wine_on_linux);
|
||||
if (result == 0)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
HMODULE hntdll = GetModuleHandleW(L"ntdll.dll");
|
||||
if (!hntdll) // not running on NT
|
||||
return true;
|
||||
|
||||
FARPROC pwine_get_version = GetProcAddress(hntdll, "wine_get_version");
|
||||
FARPROC pwine_get_host_version = GetProcAddress(hntdll, "wine_get_host_version");
|
||||
|
||||
return pwine_get_version != nullptr || pwine_get_host_version != nullptr;
|
||||
}
|
||||
|
||||
bool is_veh_enabled()
|
||||
{
|
||||
return check_env_var("DALAMUD_IS_VEH");
|
||||
}
|
||||
|
||||
bool is_full_dumps()
|
||||
{
|
||||
return check_env_var("DALAMUD_IS_VEH_FULL");
|
||||
}
|
||||
|
||||
DllExport DWORD WINAPI Initialize(LPVOID lpParam, HANDLE hMainThreadContinue)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
ConsoleSetup(L"Dalamud Boot");
|
||||
#endif
|
||||
|
||||
printf("Dalamud.Boot Injectable, (c) 2021 XIVLauncher Contributors\nBuilt at: %s@%s\n\n", __DATE__, __TIME__);
|
||||
|
||||
if (check_env_var("DALAMUD_WAIT_DEBUGGER"))
|
||||
{
|
||||
printf("Waiting for debugger to attach...\n");
|
||||
if (bootconfig::is_wait_debugger()) {
|
||||
logging::print<logging::I>("Waiting for debugger to attach...");
|
||||
while (!IsDebuggerPresent())
|
||||
Sleep(100);
|
||||
printf("Debugger attached.\n");
|
||||
logging::print<logging::I>("Debugger attached.");
|
||||
}
|
||||
|
||||
wchar_t _module_path[MAX_PATH];
|
||||
GetModuleFileNameW(g_hModule, _module_path, sizeof _module_path / 2);
|
||||
std::filesystem::path fs_module_path(_module_path);
|
||||
|
||||
std::wstring runtimeconfig_path = _wcsdup(fs_module_path.replace_filename(L"Dalamud.runtimeconfig.json").c_str());
|
||||
std::wstring module_path = _wcsdup(fs_module_path.replace_filename(L"Dalamud.dll").c_str());
|
||||
const auto fs_module_path = utils::get_module_path(g_hModule);
|
||||
const auto runtimeconfig_path = std::filesystem::path(fs_module_path).replace_filename(L"Dalamud.runtimeconfig.json").wstring();
|
||||
const auto module_path = std::filesystem::path(fs_module_path).replace_filename(L"Dalamud.dll").wstring();
|
||||
|
||||
// ============================== CLR ========================================= //
|
||||
|
||||
|
|
@ -97,39 +51,28 @@ DllExport DWORD WINAPI Initialize(LPVOID lpParam, HANDLE hMainThreadContinue)
|
|||
if (result != 0)
|
||||
return result;
|
||||
|
||||
typedef void (CORECLR_DELEGATE_CALLTYPE* custom_component_entry_point_fn)(LPVOID, HANDLE);
|
||||
custom_component_entry_point_fn entrypoint_fn = reinterpret_cast<custom_component_entry_point_fn>(entrypoint_vfn);
|
||||
using custom_component_entry_point_fn = void (CORECLR_DELEGATE_CALLTYPE*)(LPVOID, HANDLE);
|
||||
const auto entrypoint_fn = reinterpret_cast<custom_component_entry_point_fn>(entrypoint_vfn);
|
||||
|
||||
// ============================== VEH ======================================== //
|
||||
|
||||
printf("Initializing VEH... ");
|
||||
if(is_running_on_linux())
|
||||
{
|
||||
printf("VEH was disabled, running on linux\n");
|
||||
}
|
||||
else if (is_veh_enabled())
|
||||
{
|
||||
if (veh::add_handler(is_full_dumps()))
|
||||
printf("Done!\n");
|
||||
else printf("Failed!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("VEH was disabled manually\n");
|
||||
logging::print<logging::I>("Initializing VEH...");
|
||||
if (utils::is_running_on_linux()) {
|
||||
logging::print<logging::I>("=> VEH was disabled, running on linux");
|
||||
} else if (bootconfig::is_veh_enabled()) {
|
||||
if (veh::add_handler(bootconfig::is_veh_full()))
|
||||
logging::print<logging::I>("=> Done!");
|
||||
else
|
||||
logging::print<logging::I>("=> Failed!");
|
||||
} else {
|
||||
logging::print<logging::I>("VEH was disabled manually");
|
||||
}
|
||||
|
||||
// ============================== Dalamud ==================================== //
|
||||
|
||||
printf("Initializing Dalamud... ");
|
||||
logging::print<logging::I>("Initializing Dalamud...");
|
||||
entrypoint_fn(lpParam, hMainThreadContinue);
|
||||
printf("Done!\n");
|
||||
|
||||
#ifndef NDEBUG
|
||||
fclose(stdin);
|
||||
fclose(stdout);
|
||||
fclose(stderr);
|
||||
FreeConsole();
|
||||
#endif
|
||||
logging::print<logging::I>("Done!");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -137,12 +80,12 @@ DllExport DWORD WINAPI Initialize(LPVOID lpParam, HANDLE hMainThreadContinue)
|
|||
BOOL APIENTRY DllMain(const HMODULE hModule, const DWORD dwReason, LPVOID lpReserved) {
|
||||
DisableThreadLibraryCalls(hModule);
|
||||
|
||||
switch (dwReason)
|
||||
{
|
||||
switch (dwReason) {
|
||||
case DLL_PROCESS_ATTACH:
|
||||
g_hModule = hModule;
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
xivfixes::apply_all(false);
|
||||
veh::remove_handler();
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue