diff --git a/Riders.Tweakbox/Controllers/Direct3DController.cs b/Riders.Tweakbox/Controllers/Direct3DController.cs index 7e2aa992..9ce55cbf 100644 --- a/Riders.Tweakbox/Controllers/Direct3DController.cs +++ b/Riders.Tweakbox/Controllers/Direct3DController.cs @@ -64,7 +64,6 @@ public Direct3DController(TweakboxConfig config, IReloadedHooks hooks) _config = config; var dx9Hook = Sewer56.SonicRiders.API.Misc.DX9Hook.Value; _createDeviceHook = dx9Hook.Direct3D9VTable.CreateFunctionHook((int)IDirect3D9.CreateDevice, CreateDeviceHook).Activate(); - _createTextureHook = dx9Hook.DeviceVTable.CreateFunctionHook((int)IDirect3DDevice9.CreateTexture, CreateTextureHook).Activate(); _createVertexBufferHook = dx9Hook.DeviceVTable.CreateFunctionHook((int)IDirect3DDevice9.CreateVertexBuffer, CreateVertexBufferHook).Activate(); _createIndexBufferHook = dx9Hook.DeviceVTable.CreateFunctionHook((int)IDirect3DDevice9.CreateIndexBuffer, CreateIndexBufferHook).Activate(); @@ -100,7 +99,10 @@ private IntPtr CreateDeviceHook(IntPtr direct3dpointer, uint adapter, DeviceType { // Do not edit if does not belong to Riders. if (D3dEx == null || direct3dpointer != D3dEx.NativePointer) + { + Log.WriteLine($"[{nameof(CreateDeviceHook)}] Not Riders Device, Ignoring"); return _createDeviceHook.OriginalFunction(direct3dpointer, adapter, deviceType, hFocusWindow, behaviorFlags, ref presentParameters, ppReturnedDeviceInterface); + } if (_config.Data.D3DDeviceFlags) { @@ -152,7 +154,10 @@ private IntPtr CreateDeviceHook(IntPtr direct3dpointer, uint adapter, DeviceType private IntPtr ResetHook(IntPtr device, ref PresentParameters presentparameters) { if (D3dDeviceEx == null || D3dDeviceEx.NativePointer != device) + { + Log.WriteLine($"[{nameof(ResetHook)}] Not Riders Device, Ignoring"); return _resetHook.OriginalFunction(device, ref presentparameters); + } SetPresentParameters(ref presentparameters); LastPresentParameters = presentparameters; @@ -187,9 +192,6 @@ private void SetPresentParameters(ref PresentParameters presentParameters) #region Hooks for D3D9Ex Support private IntPtr CreateTextureHook(IntPtr devicePointer, int width, int height, int miplevels, Usage usage, Format format, Pool pool, void** pptexture, void* sharedhandle) { - if (D3dDeviceEx == null || D3dDeviceEx.NativePointer != devicePointer) - return _createTextureHook.OriginalFunction(devicePointer, width, height, miplevels, usage, format, pool, pptexture, sharedhandle); - usage |= (pool == Pool.Managed ? Usage.Dynamic : 0); pool = (pool == Pool.Managed) ? Pool.Default : pool; return _createTextureHook.OriginalFunction(devicePointer, width, height, miplevels, usage, format, pool, pptexture, sharedhandle); @@ -197,9 +199,6 @@ private IntPtr CreateTextureHook(IntPtr devicePointer, int width, int height, in private IntPtr CreateVertexBufferHook(IntPtr devicePointer, uint length, Usage usage, VertexFormat format, Pool pool, void** ppvertexbuffer, void* psharedhandle) { - if (D3dDeviceEx == null || D3dDeviceEx.NativePointer != devicePointer) - return _createVertexBufferHook.OriginalFunction(devicePointer, length, usage, format, pool, ppvertexbuffer, psharedhandle); - usage |= (pool == Pool.Managed ? Usage.Dynamic : 0); pool = (pool == Pool.Managed) ? Pool.Default : pool; return _createVertexBufferHook.OriginalFunction(devicePointer, length, usage, format, pool, ppvertexbuffer, psharedhandle); @@ -207,34 +206,23 @@ private IntPtr CreateVertexBufferHook(IntPtr devicePointer, uint length, Usage u private IntPtr CreateIndexBufferHook(IntPtr devicePointer, uint length, Usage usage, Format format, Pool pool, void** ppindexbuffer, void* psharedhandle) { - if (D3dDeviceEx == null || D3dDeviceEx.NativePointer != devicePointer) - return _createIndexBufferHook.OriginalFunction(devicePointer, length, usage, format, pool, ppindexbuffer, psharedhandle); - usage |= (pool == Pool.Managed ? Usage.Dynamic : 0); pool = (pool == Pool.Managed) ? Pool.Default : pool; return _createIndexBufferHook.OriginalFunction(devicePointer, length, usage, format, pool, ppindexbuffer, psharedhandle); } - - #endregion #region D3D9Ex: These APIs aren't used but just in case!! private IntPtr CreateVolumeTextureHook(IntPtr devicepointer, int width, int height, int depth, int miplevels, Usage usage, Format format, Pool pool, void** pptexture, void* sharedhandle) { - if (D3dDeviceEx == null || D3dDeviceEx.NativePointer != devicepointer) - return _createVolumeTextureHook.OriginalFunction(devicepointer, width, height, depth, miplevels, usage, format, pool, pptexture, sharedhandle); - usage |= (pool == Pool.Managed ? Usage.Dynamic : 0); pool = (pool == Pool.Managed) ? Pool.Default : pool; return _createVolumeTextureHook.OriginalFunction(devicepointer, width, height, depth, miplevels, usage, format, pool, pptexture, sharedhandle); } private IntPtr CreateCubeTextureHook(IntPtr devicepointer, int edgelength, int levels, Usage usage, Format format, Pool pool, void** pptexture, void* sharedhandle) - { - if (D3dDeviceEx == null || D3dDeviceEx.NativePointer != devicepointer) - return _createCubeTextureHook.OriginalFunction(devicepointer, edgelength, levels, usage, format, pool, pptexture, sharedhandle); - + { usage |= (pool == Pool.Managed ? Usage.Dynamic : 0); pool = (pool == Pool.Managed) ? Pool.Default : pool; return _createCubeTextureHook.OriginalFunction(devicepointer, edgelength, levels, usage, format, pool, pptexture, sharedhandle); @@ -242,9 +230,6 @@ private IntPtr CreateCubeTextureHook(IntPtr devicepointer, int edgelength, int l private IntPtr CreateOffscreenPlainSurfaceHook(IntPtr devicepointer, int width, int height, Format format, Pool pool, void** ppsurface, void* sharedhandle) { - if (D3dDeviceEx == null || D3dDeviceEx.NativePointer != devicepointer) - return _createOffscreenPlainSurfaceHook.OriginalFunction(devicepointer, width, height, format, pool, ppsurface, sharedhandle); - pool = (pool == Pool.Managed) ? Pool.Default : pool; return _createOffscreenPlainSurfaceHook.OriginalFunction(devicepointer, width, height, format, pool, ppsurface, sharedhandle); } @@ -270,6 +255,5 @@ private IntPtr CreateOffscreenPlainSurfaceHook(IntPtr devicepointer, int width, [Function(CallingConventions.Stdcall)] public unsafe delegate IntPtr CreateOffscreenPlainSurface(IntPtr devicePointer, int width, int height, Format format, Pool pool, void** ppSurface, void* sharedHandle); - } }