Skip to content

Commit 47be944

Browse files
committed
Fixes to AGS
1 parent 4dc6c61 commit 47be944

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

OptiScaler/hooks/HooksDx.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ static PFN_agsDriverExtensionsDX12_CreateDevice o_agsDriverExtensionsDX12_Create
437437
static PFN_agsDriverExtensionsDX12_DestroyDevice o_agsDriverExtensionsDX12_DestroyDevice = nullptr;
438438

439439
static bool _agsInited = false;
440+
static bool _agsSkip = false;
440441
static AGSContext* _agsContext = nullptr;
441442

442443
// Original method calls for device
@@ -3815,6 +3816,9 @@ static void CALLBACK D3D12DebugCallback(D3D12_MESSAGE_CATEGORY Category, D3D12_M
38153816

38163817
static void LoadAndInitAgs(IDXGIAdapter* pAdapter)
38173818
{
3819+
if (_agsInited)
3820+
return;
3821+
38183822
State::Instance().skipSpoofing = true;
38193823
DXGI_ADAPTER_DESC desc{};
38203824
if (pAdapter->GetDesc(&desc) != S_OK)
@@ -3883,9 +3887,11 @@ static HRESULT hkD3D12CreateDevice(IDXGIAdapter* pAdapter, D3D_FEATURE_LEVEL Min
38833887

38843888
HRESULT result = E_ABORT;
38853889

3890+
bool hookToDevice = false;
3891+
38863892
LoadAndInitAgs(pAdapter);
38873893

3888-
if (_agsInited)
3894+
if (_agsInited && !_agsSkip)
38893895
{
38903896
AGSDX12DeviceCreationParams creationParams = {};
38913897
creationParams.pAdapter = pAdapter;
@@ -3895,25 +3901,30 @@ static HRESULT hkD3D12CreateDevice(IDXGIAdapter* pAdapter, D3D_FEATURE_LEVEL Min
38953901
AGSDX12ExtensionParams extensionParams = {};
38963902
AGSDX12ReturnedParams returnedParams = {};
38973903

3904+
_agsSkip = true;
38983905
auto rc = o_agsDriverExtensionsDX12_CreateDevice(_agsContext, &creationParams, &extensionParams, &returnedParams);
3906+
_agsSkip = false;
38993907

39003908
if (rc == AGS_SUCCESS)
39013909
{
39023910
LOG_INFO("AGS D3D12 Device created");
3911+
*ppDevice = returnedParams.pDevice;
39033912
result = S_OK;
39043913
}
39053914
else
39063915
{
39073916
LOG_INFO("AGS D3D12 Device creation error: {:X}", (UINT)rc);
39083917
result = o_D3D12CreateDevice(pAdapter, minLevel, riid, ppDevice);
3918+
hookToDevice = true;
39093919
}
39103920
}
39113921
else
39123922
{
39133923
result = o_D3D12CreateDevice(pAdapter, minLevel, riid, ppDevice);
3924+
hookToDevice = true;
39143925
}
39153926

3916-
if (result == S_OK && ppDevice != nullptr && *ppDevice != nullptr)
3927+
if (result == S_OK && hookToDevice && ppDevice != nullptr && *ppDevice != nullptr)
39173928
{
39183929
LOG_DEBUG("Device captured: {0:X}", (size_t)*ppDevice);
39193930
g_pd3dDeviceParam = (ID3D12Device*)*ppDevice;

0 commit comments

Comments
 (0)