Commit Graph

67 Commits (3786a203c7b4008d51e19681f9d3eeca8d490ca5)

Author SHA1 Message Date
jp9000 1ca9f8872e win-capture: Add IDXGISwapChain1::Present1 hook support
Allows capturing games/programs that may be using Present1 instead of
the regular Present call for rendering.
2017-06-19 15:45:00 -07:00
jp9000 c4036b18bb win-capture/graphics-hook: Fix D3D10/D3D11 detection
When hooking DXGI-based graphics programs in the hook, the first hook
point is IDXGISwapChain::Present.  To be able to initiate a capture, a
pointer to the device context that created the swap chain is required,
which can be retrieved via IDXGISwapChain::GetDevice.  Determining
whether the device context was D3D10 or D3D11 has always been somewhat
of an issue due to D3D10 and D3D11 being nearly identical, as well as
their interoperability/interchangeability.  The GetDevice function would
first be called with the UUID of ID3D10Device, then if that failed,
the UUID of ID3D11Device.

However, with certain specific D3D11 games, GetDevice would for some
unknown reason succeed with the UUID of ID3D10Device, which would cause
capture to fail.  (Conversely, attempting to call GetDevice with the
UUID of ID3D11Device on a device that's actually ID3D10Device would
always succeed, so reversing the order of the test was not an option).
There were originally three known D3D11 games that would erroneously
succeed when querying a D3D10 device interface:  Call of Duty: Ghosts,
Just Cause 3, and theHunter: Call of the Wild.  All other known D3D11
games would work correctly.  Because it was only these three games, a
hack was originally implemented in the form of an executable exception
list that would force them to capture D3D11.

Unfortunately, Oculus games are now failing under the same circumstance
as well, so a simple hack will no longer work.  To fix this, a more
reliable method of detecting which context it is had to be discovered:
simply check the feature level using ID3D11Device::GetFeatureLevel.  If
the feature level is D3D_FEATURE_LEVEL_11_0 or D3D_FEATURE_LEVEL_11_1,
the device is definitely a D3D11 device.  Otherwise, continue the tests
as they were before.  Successfully tested with many D3D10 games, many
D3D11 games, and especially those three D3D11 games that previously were
detected as D3D10 erroneously.
2017-06-15 03:48:43 -07:00
Richard Stanway 9e95b2eb6f
Various: Don't use boolean bitfields
Using bitfields causes less optimized code generation and the memory
savings are minimal as none of the objects are instantiated enough
times to be worth it.

See https://blogs.msdn.microsoft.com/oldnewthing/20081126-00/?p=20073
2017-05-10 23:28:46 +02:00
Ryan Foster be98cee2a0 Fix various typos across multiple modules 2017-04-25 22:39:42 -04:00
Richard Stanway d2e9e47bb4 graphics-hook: Account for sizeof(wchar_t) in len 2017-02-25 17:18:55 +01:00
Cam 8a6491c9bf win-capture: Add hook exception for theHunter: COTW
Adds an exception to skip d3d10 checks for theHunter: Call of the Wild,
which fixes incompatibility with game capture.

Closes jp9000/obs-studio#801
2017-02-25 06:42:36 -08:00
jp9000 21d70fa207 win-capture: Don't use FindWindow for game capture keepalive
Using and creating a window can use issues in game capture if multiple
game captures are active, so revert back to using a mutex, and just
ignore the keepalive check failure if injected inside a UWP program
(only check to see if GetLastError reports that it's not found -- if it
returns access denied or any other error, assume it's in a UWP program,
and ignore the keepalive check).
2017-01-15 09:15:45 -08:00
jp9000 21be33805d win-capture: Release backbuffers immediately upon init
There's no need to keep a reference to the backbuffers.  That and the
backbuffer references weren't being released anyway, so that fixes that
bug.
2016-12-23 08:07:26 -08:00
jp9000 74a5bdf993 win-capture: If backbuffer count is 1, disable dxgi 1.4 use
Executing the dxgi 1.4 code causes it to cycle through backbuffers,
backbuffers which may not exist if in discard mode.
2016-12-23 08:02:35 -08:00
jp9000 414ff5ba14 win-capture: Refactor DX12 backbuffer code
It was undesirable to pass arrays via function parameters, so a
structure should be used instead.

Also increases total allowable backbuffers to 8.
2016-12-23 08:02:30 -08:00
jp9000 a4143be052 win-capture: Fix possible access of array beyond size
If the backbuffer count is larger than 3, it could still try to assign
backbuffers to pointers beyond the variable's array size when calling
swap->GetBuffer.
2016-12-23 07:49:13 -08:00
jp9000 3b5a30ce97 win-capture: Capture all D3D12 backbuffers
D3D12 capture does not take in to account when multiple backbuffers are
in used.  With previous versions of Direct3D there was no need to do
this, but with D3D12 you must explicitly capture each specific
backbuffer currently in use.
2016-12-23 01:53:15 -08:00
jp9000 d4a99e062b win-capture: Output hook debug messages if addresses missing 2016-12-16 14:05:57 -08:00
jp9000 b5f216ef88 win-capture: Use wide strings for named objects
Prevents from having to mix ansi/wide string usage for opening UWP
programs.
2016-12-16 02:21:10 -08:00
jp9000 ab9bda52e0 win-capture: Create all named objects within hook
All named objects (including file mapped shared memory) need to be
created within the hook itself due to the fact that UWP programs cannot
access named objects outside of the UWP process.

Because shared memory needs to be created within the hook, the capture
loop cannot start until the shared memory has been filled with valid
data.  Creating an additional "initialize" event fixes this issue.

Additionally, changed the way that named kernel objects are
opened/created.  Before, there were functions that would first try to
open named objects and then implicitly create them if opening failed
(assuming that if the hook didn't create it first, game capture would),
now it's been changed so that you can only either explicitly open or
create.
2016-12-16 02:21:07 -08:00
jp9000 d19342442f win-capture: Use window for keepalive check
To check to make sure game capture is still active in the capture
program, it currently uses a named event, and then it checks to see if
that named event exists.  However with UWP programs, you can't open a
named event outside of the UWP process.  FindWindow on the other hand
does work, so instead of checking to see if a named kernel object
exists, create a window and check to see if that window exists.
2016-12-16 02:21:06 -08:00
jp9000 4ec1033741 win-capture: Do not require pipe/mutex within hook
Named pipes cannot be used within UWP programs, so make them optional.
2016-12-15 13:03:44 -08:00
jp9000 746061fb3a win-capture: Always use minimal access rights within hook
This prevents issues with opening handles to objects within UWP
programs, which have increased security limitations.
2016-12-15 13:03:42 -08:00
jp9000 e148087636 win-capture: Only duplicate to get cur thread handle
Instead of calling OpenThread, use DuplicateHandle with the minimal
access rights (SYNCHRONIZE) to be able to get the current thread handle
within a UWP program.
2016-12-12 08:10:06 -08:00
jp9000 ca607f8b35 cmake: Add _CRT_SECURE_NO_WARNINGS to all projects
This prevents issues with using standard C functions, where microsoft
would otherwise spit out pointless warnings to encourage using
microsoft-specific functions instead.
2016-12-08 03:27:36 -08:00
jp9000 2f305cb550 win-capture: Use static runtimes for hooks/helpers
(Note: This commit also modifies the ipc-util/seg-service modules)

When compiling the final project, always compile
ipc-util/get-graphics-offsets/graphics-hook/inject-helper/seg-service
with static MSVC runtimes to prevent the need of requiring the MSVC
runtimes for both architectures.
2016-11-23 06:03:00 -08:00
jp9000 0b27b51294 win-capture: Add D3D12 capture support
Currently only supports shared texture capture, and doesn't support
rescaling.
2016-11-03 12:13:42 -07:00
jp9000 f49065b1e6 win-capture: Use IUnknown for getting swap backbuffers
Using IDXGIResource doesn't work with D3D12.  D3D12 textures are not a
subclass of that class.
2016-11-03 09:28:32 -07:00
jp9000 6d33f7e091 win-capture: Add trick to ensure game cap. shared tex support
This new trick forgoes the use of patches and allows the ability to use
shared GPU resources despite being a Direct3D 9.0c context.
2016-08-12 18:44:54 -07:00
jp9000 571c3a6859 win-capture: Update D3D9 patches
Fixes performance issues with windows 10.0.14393.0
2016-08-06 15:27:33 -07:00
jp9000 183ee11e24 win-capture: Fix lookup order for d3d9 patch
It's supposed to look for patch segments in ascending order, from the
smallest offset to the largest offset.  Patch type/comparison is
identical to the one it's being swapped with, so only the offsets need
to be swapped.
2016-08-06 15:27:33 -07:00
jp9000 7feb21572f win-capture: Update D3D9 shared texture patches 2016-07-15 13:00:21 -07:00
jp9000 d7ed0f1976 Revert "win-capture: Track gl "swap" invocations to prevent duplicate work"
This reverts commit 4c505e7030.

Reverting this for the time being due to issues with quakelive.  This
will be more thoroughly tested and hopefully added again.
2016-07-10 00:38:15 -07:00
Palana 4c505e7030 win-capture: Track gl "swap" invocations to prevent duplicate work
Tested using FTL (steam): SwapBuffers ultimately calls wgl_swap_buffers
causing an additional copy which just isn't necessary

This also causes game capture to sometimes capture overlays even when
not intended
2016-07-03 13:18:23 -07:00
jp9000 b012c7280a win-capture/graphics-hook: Fix vs2015 internal compiler error
Removing this union fixes the internal compile error that would occur on
visual studio 2015 update 2 and above when these variables were all in a
union.
2016-06-22 14:40:54 -07:00
jp9000 d32424e5ad win-capture: Reset d3d9 capture if device recreated
Fixes a bug where if a D3D9 program recreates its device the capture
would become invalid.  Certain games (especially blizzard games) will
completely recreate their Direct3D device if a critical D3D9 error
occurs.
2016-06-11 12:27:06 -07:00
jp9000 6ca3cd3504 win-capture: Fix VS2015 update 2 compiler error
Having volatile variables inside of a union causes a C1001 compiler
error in visual studio 2015 update 2.

Closes jp9000/obs-studio#544
2016-05-28 09:40:49 -07:00
jp9000 2591f24594 win-capture: Add game capture fix for darkest dungeon
Darkest dungeon uses an unusual technique for drawing its frames: a
fixed 1920x1080 frame buffer used in place of the backbuffer, which is
then stretched to fit the size of the screen (whether the screen is
bigger or smaller than the actual texture).

The custom frame would cause glReadBuffer to initially fail with an
error.  When this happens, their custom frame buffer is in use, so all
that needs to be done is simply reset the capture and force the current
output size to 1920x1080 while that custom frame is in use.

They presumably did this in order to ensure the game looks the same at
any resolution.  Instead of having to use power-of-two sprites and
mipmaps for every single game sprite and stretch/skew each of them
(which would risk the final output "not looking quite right" at
different resolutions), they simply use non-pow-2 sprites with no
mipmaps and render them all on to one texture of a fixed size and then
stretch that final output texture.  That ensures that the actual
composite of the game still looks the same at any resolution, while
reducing texture memory by not requiring each sprite to use a
power-of-two texture and mipmaps.
2016-01-26 11:49:28 -08:00
jp9000 2c8edb8a8a win-capture: Clear GL error flag before initializing capture
Some games don't catch GL errors via glGetError, so there's a
possibility that an error will pass through to the capture calls,
causing a false failure.

The most simple solution is to just clear the error flag on each capture
call.
2015-12-10 15:54:30 -08:00
jp9000 deca80531e win-capture: Add hook exception for Just Cause 3 2015-12-03 17:19:35 -08:00
jp9000 50c61898d0 win-capture: Fall back to creating d3d contexts if offsets bad 2015-11-20 14:07:14 -08:00
jp9000 1755511b2f win-capture: Hook Reset/ResetEx in Present* funcs
The virtual address table values for Reset/ResetEx can sometimes point
to functions that are in libraries outside of D3D8.dll and D3D9.dll, and
will cause a crash if used.  Instead, just hook Reset/ResetEx when one
of the Present* functions are called.
2015-11-20 14:06:37 -08:00
jp9000 7634d1099c win-capture: Add new game capture patches 2015-11-14 14:25:17 -08:00
jp9000 b4597218f0 win-capture: Use GetSytemDirectory instead of SH*
Instead of using shell functions to get the windows system directory,
use the kernel32 functions (GetSystemDirectory and
GetSystemWow64Directory).  Reduces a bit of unnecessary overhead.
2015-10-05 14:00:52 -07:00
jp9000 e57aa3cab2 win-capture: Do not reset GL capture if cx/cy is 0
It is not necessary to reset the capture when cx or cy is at 0 because 0
means the application is minimized.
2015-09-22 18:08:20 -07:00
jp9000 51c4480697 win-capture: Fix infinite GL reacquire loop
If the GL capture part of the game capture hook fails to initialized for
whatever reason, it will go in to an infinite reacquire loop.  If it
fails to initialize shared texture capture, try shared memory capture
instead.
2015-09-21 21:40:01 -07:00
jp9000 13d22645e4 win-capture: Use correct variable for system modules
..This is rather embarrassing.  I used the parameter variable and the
actual variable that I wanted to used went completely unused.  Would
static analysis catch something like this, I wonder?  Would probably
have to be really good static analysis.
2015-08-29 21:03:54 -07:00
jp9000 96dc5f796e win-capture: Add more d3d9 exceptions for win 10
Adds exceptions for D3D9 version 10.0.10240.16412.
2015-08-07 21:27:35 -07:00
jp9000 77b7a83249 win-capture: Add D3D9 exceptions for win10 RTM 2015-07-16 15:45:33 -07:00
jp9000 3ef3ce29e4 win-capture: Update d3d9 hooks for win10 preview 2015-07-08 12:50:27 -07:00
jp9000 104415d5c3 win-capture: Fix hook bug that could cause crashes
I had this issue where IDXGISwapChain::ResizeBuffers would fail in the
hooks, causing games to crash when they resized their backbuffers
because ResizeBuffers would return an 'invalid call' HRESULT value.  In
the ResizeBuffers documentation it says that it will only happen if a
backbuffer currently has any outstanding references, but there's no way
this would happen unless ResizeBuffers internally calls Present or vise
versa.

After ResizeBuffers has been called, the very first call to Present will
somehow seemingly invalidate and/or destroy the current backbuffer.
It's very strange, but that seems to be what's going on, at least for
the game I was testing.  So if you are performing a post-overlay
capture, then you must ignore the capture on the very first call to
Present.

It's Microsoft's code so you can't really know what's going on, you just
have to work around these strange issues seemingly in the dark.
2015-02-14 09:12:24 -08:00
jp9000 8b59b606c5 win-capture: Use right call type for hook funcs
Although STDMETHODCALLTYPE is technically WINAPI (__stdcall), it's best
not to make any assumptions.
2015-02-14 07:48:36 -08:00
jp9000 ae931b32cf win-capture: Fix debug function strings
These had an older name of what the function used to be named
2015-02-14 07:48:35 -08:00
Bl00drav3n 74042fff96 win-capture: Implement D3D8 game capture support 2015-02-09 05:02:48 -08:00
jp9000 372a23de68 win-capture: Use inline define with VC only
mingw already supports the regular inline keyword in C; VC does not.
2015-02-09 03:55:17 -08:00