boot: don't link nethost.dll implicitly

Turns out this does not work if we are injecting, since ffxiv_dx11.exe does not have dalamud workdir in its DLL search path and can't link the nethost DLL. I definitely don't want to modify the search path in ffxiv_dx11.exe so this bodge will do for now.
This commit is contained in:
goat 2024-07-17 22:54:34 +02:00
parent 782df6ea6b
commit 30581d534a
3 changed files with 34 additions and 5 deletions

View file

@ -58,8 +58,8 @@
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>Version.lib;Shlwapi.lib;nethost.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\lib\CoreCLR\nethost;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>Version.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\lib\CoreCLR;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">

View file

@ -48,8 +48,7 @@
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalLibraryDirectories>..\lib\CoreCLR\nethost;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>nethost.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\lib\CoreCLR;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ProgramDatabaseFile>$(OutDir)$(TargetName).Boot.pdb</ProgramDatabaseFile>
</Link>
</ItemDefinitionGroup>

View file

@ -18,8 +18,38 @@ int CoreCLR::load_hostfxr()
return CoreCLR::load_hostfxr(nullptr);
}
// MS does not provide this typedef anymore in the header. They removed it since they want us to implicitly link nethost,
// but we don't want to do that since we don't want to change the dll search path in ffxix_dx11.exe.
// This is kind of a kludge but whatever. The static lib they ship is unusable. Fix it, goat.
typedef int (NETHOST_CALLTYPE *get_hostfxr_path_type)(
char_t * buffer,
size_t * buffer_size,
const struct get_hostfxr_parameters *parameters);
int CoreCLR::load_hostfxr(const struct get_hostfxr_parameters* parameters)
{
// Get the path to CoreCLR's hostfxr
std::wstring calling_module_path(MAX_PATH, L'\0');
do
{
calling_module_path.resize(GetModuleFileNameW(static_cast<HMODULE>(m_calling_module), &calling_module_path[0], static_cast<DWORD>(calling_module_path.size())));
}
while (!calling_module_path.empty() && GetLastError() == ERROR_INSUFFICIENT_BUFFER);
if (calling_module_path.empty())
return -1;
calling_module_path = (std::filesystem::path(calling_module_path).parent_path() / L"nethost.dll").wstring();
auto lib_nethost = reinterpret_cast<void*>(load_library(calling_module_path.c_str()));
if (!lib_nethost)
return -1;
auto get_hostfxr_path = reinterpret_cast<get_hostfxr_path_type>(
get_export(lib_nethost, "get_hostfxr_path"));
if (!get_hostfxr_path)
return -1;
wchar_t buffer[MAX_PATH]{};
size_t buffer_size = sizeof buffer / sizeof(wchar_t);
if (int rc = get_hostfxr_path(buffer, &buffer_size, parameters); rc != 0)