@@ -437,6 +437,7 @@ static PFN_agsDriverExtensionsDX12_CreateDevice o_agsDriverExtensionsDX12_Create
437
437
static PFN_agsDriverExtensionsDX12_DestroyDevice o_agsDriverExtensionsDX12_DestroyDevice = nullptr ;
438
438
439
439
static bool _agsInited = false ;
440
+ static bool _agsSkip = false ;
440
441
static AGSContext* _agsContext = nullptr ;
441
442
442
443
// Original method calls for device
@@ -3815,6 +3816,9 @@ static void CALLBACK D3D12DebugCallback(D3D12_MESSAGE_CATEGORY Category, D3D12_M
3815
3816
3816
3817
static void LoadAndInitAgs (IDXGIAdapter* pAdapter)
3817
3818
{
3819
+ if (_agsInited)
3820
+ return ;
3821
+
3818
3822
State::Instance ().skipSpoofing = true ;
3819
3823
DXGI_ADAPTER_DESC desc{};
3820
3824
if (pAdapter->GetDesc (&desc) != S_OK)
@@ -3883,9 +3887,11 @@ static HRESULT hkD3D12CreateDevice(IDXGIAdapter* pAdapter, D3D_FEATURE_LEVEL Min
3883
3887
3884
3888
HRESULT result = E_ABORT;
3885
3889
3890
+ bool hookToDevice = false ;
3891
+
3886
3892
LoadAndInitAgs (pAdapter);
3887
3893
3888
- if (_agsInited)
3894
+ if (_agsInited && !_agsSkip )
3889
3895
{
3890
3896
AGSDX12DeviceCreationParams creationParams = {};
3891
3897
creationParams.pAdapter = pAdapter;
@@ -3895,25 +3901,30 @@ static HRESULT hkD3D12CreateDevice(IDXGIAdapter* pAdapter, D3D_FEATURE_LEVEL Min
3895
3901
AGSDX12ExtensionParams extensionParams = {};
3896
3902
AGSDX12ReturnedParams returnedParams = {};
3897
3903
3904
+ _agsSkip = true ;
3898
3905
auto rc = o_agsDriverExtensionsDX12_CreateDevice (_agsContext, &creationParams, &extensionParams, &returnedParams);
3906
+ _agsSkip = false ;
3899
3907
3900
3908
if (rc == AGS_SUCCESS)
3901
3909
{
3902
3910
LOG_INFO (" AGS D3D12 Device created" );
3911
+ *ppDevice = returnedParams.pDevice ;
3903
3912
result = S_OK;
3904
3913
}
3905
3914
else
3906
3915
{
3907
3916
LOG_INFO (" AGS D3D12 Device creation error: {:X}" , (UINT)rc);
3908
3917
result = o_D3D12CreateDevice (pAdapter, minLevel, riid, ppDevice);
3918
+ hookToDevice = true ;
3909
3919
}
3910
3920
}
3911
3921
else
3912
3922
{
3913
3923
result = o_D3D12CreateDevice (pAdapter, minLevel, riid, ppDevice);
3924
+ hookToDevice = true ;
3914
3925
}
3915
3926
3916
- if (result == S_OK && ppDevice != nullptr && *ppDevice != nullptr )
3927
+ if (result == S_OK && hookToDevice && ppDevice != nullptr && *ppDevice != nullptr )
3917
3928
{
3918
3929
LOG_DEBUG (" Device captured: {0:X}" , (size_t )*ppDevice);
3919
3930
g_pd3dDeviceParam = (ID3D12Device*)*ppDevice;
0 commit comments