More crash prevention measures

This commit is contained in:
cdozdil
2026-01-06 01:31:38 +03:00
parent f83a5e5ac7
commit 21fa96b7e3
2 changed files with 85 additions and 85 deletions
+72 -72
View File
@@ -670,6 +670,78 @@ static void CheckWorkingMode()
Config::Instance()->OverlayMenu.set_volatile_value(!State::Instance().isWorkingAsNvngx &&
Config::Instance()->OverlayMenu.value_or_default());
// For Agility SDK Upgrade
if (Config::Instance()->FsrAgilitySDKUpgrade.value_or_default())
{
RunAgilityUpgrade(GetDllNameWModule(&dx12NamesW));
}
// Intel Extension Framework
if (Config::Instance()->UESpoofIntelAtomics64.value_or_default())
{
HMODULE igdext = NtdllProxy::LoadLibraryExW_Ldr(L"igdext64.dll", NULL, 0);
if (igdext == nullptr)
{
auto paths = GetDriverStore();
for (size_t i = 0; i < paths.size(); i++)
{
auto dllPath = paths[i] / L"igdext64.dll";
LOG_DEBUG("Trying to load: {}", wstring_to_string(dllPath.c_str()));
igdext = NtdllProxy::LoadLibraryExW_Ldr(dllPath.c_str(), NULL, 0);
if (igdext != nullptr)
{
LOG_INFO(L"igdext64.dll loaded from {}", dllPath.wstring());
break;
}
}
}
else
{
LOG_INFO("igdext64.dll loaded from game folder");
}
if (igdext != nullptr)
IGDExtProxy::Init(igdext);
else
LOG_ERROR("Failed to load igdext64.dll");
}
// SpecialK
if (skModule == nullptr && Config::Instance()->LoadSpecialK.value_or_default())
{
auto skFile = Util::ExePath().parent_path() / L"SpecialK64.dll";
SetEnvironmentVariableW(L"RESHADE_DISABLE_GRAPHICS_HOOK", L"1");
State::EnableServeOriginal(200);
skModule = NtdllProxy::LoadLibraryExW_Ldr(skFile.c_str(), NULL, 0);
State::DisableServeOriginal(200);
LOG_INFO("Loading SpecialK64.dll, result: {0:X}", (UINT64) skModule);
}
// ReShade
// Do not load Reshade here is Luma is active and we will create D3D12 device for it
// We will load Reshade after D3D12 device creation in that case
if (reshadeModule == nullptr && Config::Instance()->LoadReShade.value_or_default() &&
(!(State::Instance().gameQuirks & GameQuirk::CreateD3D12DeviceForLuma) ||
Config::Instance()->DontCreateD3D12DeviceForLuma.value_or_default()))
{
auto rsFile = Util::ExePath().parent_path() / L"ReShade64.dll";
SetEnvironmentVariableW(L"RESHADE_DISABLE_LOADING_CHECK", L"1");
if (skModule != nullptr)
SetEnvironmentVariableW(L"RESHADE_DISABLE_GRAPHICS_HOOK", L"1");
State::EnableServeOriginal(201);
reshadeModule = NtdllProxy::LoadLibraryExW_Ldr(rsFile.c_str(), NULL, 0);
State::DisableServeOriginal(201);
LOG_INFO("Loading ReShade64.dll, result: {0:X}", (size_t) reshadeModule);
}
// DXGI
if (DxgiProxy::Module() == nullptr)
{
@@ -885,39 +957,6 @@ static void CheckWorkingMode()
FfxApiProxy::InitFfxVk(ffxVkModule);
}
// SpecialK
if (skModule == nullptr && Config::Instance()->LoadSpecialK.value_or_default())
{
auto skFile = Util::ExePath().parent_path() / L"SpecialK64.dll";
SetEnvironmentVariableW(L"RESHADE_DISABLE_GRAPHICS_HOOK", L"1");
State::EnableServeOriginal(200);
skModule = NtdllProxy::LoadLibraryExW_Ldr(skFile.c_str(), NULL, 0);
State::DisableServeOriginal(200);
LOG_INFO("Loading SpecialK64.dll, result: {0:X}", (UINT64) skModule);
}
// ReShade
// Do not load Reshade here is Luma is active and we will create D3D12 device for it
// We will load Reshade after D3D12 device creation in that case
if (reshadeModule == nullptr && Config::Instance()->LoadReShade.value_or_default() &&
(!(State::Instance().gameQuirks & GameQuirk::CreateD3D12DeviceForLuma) ||
Config::Instance()->DontCreateD3D12DeviceForLuma.value_or_default()))
{
auto rsFile = Util::ExePath().parent_path() / L"ReShade64.dll";
SetEnvironmentVariableW(L"RESHADE_DISABLE_LOADING_CHECK", L"1");
if (skModule != nullptr)
SetEnvironmentVariableW(L"RESHADE_DISABLE_GRAPHICS_HOOK", L"1");
State::EnableServeOriginal(201);
reshadeModule = NtdllProxy::LoadLibraryExW_Ldr(rsFile.c_str(), NULL, 0);
State::DisableServeOriginal(201);
LOG_INFO("Loading ReShade64.dll, result: {0:X}", (size_t) reshadeModule);
}
// Hook kernel32 methods
if (!Config::Instance()->EarlyHooking.value_or_default())
{
@@ -925,45 +964,6 @@ static void CheckWorkingMode()
KernelHooks::Hook();
}
// For Agility SDK Upgrade
if (Config::Instance()->FsrAgilitySDKUpgrade.value_or_default())
{
RunAgilityUpgrade(GetDllNameWModule(&dx12NamesW));
}
// Intel Extension Framework
if (Config::Instance()->UESpoofIntelAtomics64.value_or_default())
{
HMODULE igdext = NtdllProxy::LoadLibraryExW_Ldr(L"igdext64.dll", NULL, 0);
if (igdext == nullptr)
{
auto paths = GetDriverStore();
for (size_t i = 0; i < paths.size(); i++)
{
auto dllPath = paths[i] / L"igdext64.dll";
LOG_DEBUG("Trying to load: {}", wstring_to_string(dllPath.c_str()));
igdext = NtdllProxy::LoadLibraryExW_Ldr(dllPath.c_str(), NULL, 0);
if (igdext != nullptr)
{
LOG_INFO(L"igdext64.dll loaded from {}", dllPath.wstring());
break;
}
}
}
else
{
LOG_INFO("igdext64.dll loaded from game folder");
}
if (igdext != nullptr)
IGDExtProxy::Init(igdext);
else
LOG_ERROR("Failed to load igdext64.dll");
}
if (Config::Instance()->CheckForUpdate.value_or_default())
VersionCheck::Start();
}
+13 -13
View File
@@ -861,22 +861,22 @@ static ULONG STDMETHODCALLTYPE hkHeapRelease(ID3D12DescriptorHeap* This)
if (State::Instance().isShuttingDown)
return o_HeapRelease(This);
This->AddRef();
if (o_HeapRelease(This) <= 1)
{
#ifdef USE_ATOMIC_INDEX
UINT count = fgHeapIndex.load(std::memory_order_relaxed);
UINT count = fgHeapIndex.load(std::memory_order_relaxed);
#else
UINT count = fgHeapIndex;
UINT count = fgHeapIndex;
#endif
for (UINT i = 0; i < count; ++i)
for (UINT i = 0; i < count; ++i)
{
auto& up = fgHeaps[i];
if (up == nullptr || up->heap != This || !up->active)
continue;
This->AddRef();
if (o_HeapRelease(This) <= 1)
{
auto& up = fgHeaps[i];
if (up == nullptr || up->heap != This)
continue;
up->active = false;
LOG_INFO("Heap released: {:X}", (size_t) This);
@@ -906,9 +906,9 @@ static ULONG STDMETHODCALLTYPE hkHeapRelease(ID3D12DescriptorHeap* This)
}
gHeapGeneration.fetch_add(1, std::memory_order_relaxed); // invalidate caches
break;
}
break;
}
return o_HeapRelease(This);