Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
尘离序散
obs-studio
提交
50c61898
O
obs-studio
项目概览
尘离序散
/
obs-studio
与 Fork 源项目一致
从无法访问的项目Fork
通知
30
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
obs-studio
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
50c61898
编写于
11月 20, 2015
作者:
J
jp9000
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
win-capture: Fall back to creating d3d contexts if offsets bad
上级
1755511b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
257 addition
and
22 deletion
+257
-22
plugins/win-capture/graphics-hook/d3d8-capture.cpp
plugins/win-capture/graphics-hook/d3d8-capture.cpp
+76
-4
plugins/win-capture/graphics-hook/d3d9-capture.cpp
plugins/win-capture/graphics-hook/d3d9-capture.cpp
+116
-18
plugins/win-capture/graphics-hook/graphics-hook.c
plugins/win-capture/graphics-hook/graphics-hook.c
+55
-0
plugins/win-capture/graphics-hook/graphics-hook.h
plugins/win-capture/graphics-hook/graphics-hook.h
+10
-0
未找到文件。
plugins/win-capture/graphics-hook/d3d8-capture.cpp
浏览文件 @
50c61898
...
...
@@ -289,17 +289,90 @@ static HRESULT STDMETHODCALLTYPE hook_present(IDirect3DDevice8 *device,
return
hr
;
}
typedef
IDirect3D8
*
(
WINAPI
*
d3d8create_t
)(
UINT
);
static
bool
manually_get_d3d8_present_addr
(
HMODULE
d3d8_module
,
void
**
present_addr
)
{
d3d8create_t
create
;
D3DPRESENT_PARAMETERS
pp
;
HRESULT
hr
;
IDirect3DDevice8
*
device
;
IDirect3D8
*
d3d8
;
hlog
(
"D3D8 value invalid, manually obtaining"
);
create
=
(
d3d8create_t
)
GetProcAddress
(
d3d8_module
,
"Direct3DCreate8"
);
if
(
!
create
)
{
hlog
(
"Failed to load Direct3DCreate8"
);
return
false
;
}
d3d8
=
create
(
D3D_SDK_VERSION
);
if
(
!
d3d8
)
{
hlog
(
"Failed to create D3D8 context"
);
return
false
;
}
memset
(
&
pp
,
0
,
sizeof
(
pp
));
pp
.
Windowed
=
true
;
pp
.
SwapEffect
=
D3DSWAPEFFECT_FLIP
;
pp
.
BackBufferFormat
=
D3DFMT_A8R8G8B8
;
pp
.
BackBufferWidth
=
2
;
pp
.
BackBufferHeight
=
2
;
pp
.
BackBufferCount
=
1
;
pp
.
hDeviceWindow
=
dummy_window
;
hr
=
d3d8
->
CreateDevice
(
D3DADAPTER_DEFAULT
,
D3DDEVTYPE_HAL
,
dummy_window
,
D3DCREATE_HARDWARE_VERTEXPROCESSING
,
&
pp
,
&
device
);
d3d8
->
Release
();
if
(
SUCCEEDED
(
hr
))
{
uintptr_t
*
vtable
=
*
(
uintptr_t
**
)
device
;
*
present_addr
=
(
void
*
)
vtable
[
15
];
device
->
Release
();
}
else
{
hlog
(
"Failed to create D3D8 device"
);
return
false
;
}
return
true
;
}
bool
hook_d3d8
(
void
)
{
HMODULE
d3d8_module
=
get_system_module
(
"d3d8.dll"
);
void
*
present_addr
;
uint32_t
d3d8_size
;
void
*
present_addr
=
nullptr
;
if
(
!
d3d8_module
)
{
return
false
;
}
present_addr
=
get_offset_addr
(
d3d8_module
,
global_hook_info
->
offsets
.
d3d8
.
present
);
d3d8_size
=
module_size
(
d3d8_module
);
if
(
global_hook_info
->
offsets
.
d3d8
.
present
<
d3d8_size
)
{
present_addr
=
get_offset_addr
(
d3d8_module
,
global_hook_info
->
offsets
.
d3d8
.
present
);
}
else
{
if
(
!
dummy_window
)
{
return
false
;
}
if
(
!
manually_get_d3d8_present_addr
(
d3d8_module
,
&
present_addr
))
{
hlog
(
"Failed to get D3D8 value"
);
return
true
;
}
}
if
(
!
present_addr
)
{
hlog
(
"Invalid D3D8 value"
);
return
true
;
}
hook_init
(
&
present
,
present_addr
,
(
void
*
)
hook_present
,
"IDirect3DDevice8::Present"
);
...
...
@@ -307,6 +380,5 @@ bool hook_d3d8(void)
rehook
(
&
present
);
hlog
(
"Hooked D3D8"
);
return
true
;
}
plugins/win-capture/graphics-hook/d3d9-capture.cpp
浏览文件 @
50c61898
...
...
@@ -785,34 +785,132 @@ static void setup_reset_hooks(IDirect3DDevice9 *device)
hooked_reset
=
true
;
}
typedef
HRESULT
(
WINAPI
*
d3d9create_ex_t
)(
UINT
,
IDirect3D9Ex
**
);
static
bool
manually_get_d3d9_addrs
(
HMODULE
d3d9_module
,
void
**
present_addr
,
void
**
present_ex_addr
,
void
**
present_swap_addr
)
{
d3d9create_ex_t
create_ex
;
D3DPRESENT_PARAMETERS
pp
;
HRESULT
hr
;
IDirect3DDevice9Ex
*
device
;
IDirect3D9Ex
*
d3d9ex
;
hlog
(
"D3D9 values invalid, manually obtaining"
);
create_ex
=
(
d3d9create_ex_t
)
GetProcAddress
(
d3d9_module
,
"Direct3DCreate9Ex"
);
if
(
!
create_ex
)
{
hlog
(
"Failed to load Direct3DCreate9Ex"
);
return
false
;
}
if
(
FAILED
(
create_ex
(
D3D_SDK_VERSION
,
&
d3d9ex
)))
{
hlog
(
"Failed to create D3D9 context"
);
return
false
;
}
memset
(
&
pp
,
0
,
sizeof
(
pp
));
pp
.
Windowed
=
1
;
pp
.
SwapEffect
=
D3DSWAPEFFECT_FLIP
;
pp
.
BackBufferFormat
=
D3DFMT_A8R8G8B8
;
pp
.
BackBufferCount
=
1
;
pp
.
hDeviceWindow
=
(
HWND
)
dummy_window
;
pp
.
PresentationInterval
=
D3DPRESENT_INTERVAL_IMMEDIATE
;
hr
=
d3d9ex
->
CreateDeviceEx
(
D3DADAPTER_DEFAULT
,
D3DDEVTYPE_HAL
,
dummy_window
,
D3DCREATE_HARDWARE_VERTEXPROCESSING
|
D3DCREATE_NOWINDOWCHANGES
,
&
pp
,
NULL
,
&
device
);
d3d9ex
->
Release
();
if
(
SUCCEEDED
(
hr
))
{
uintptr_t
*
vtable
=
*
(
uintptr_t
**
)
device
;
IDirect3DSwapChain9
*
swap
;
*
present_addr
=
(
void
*
)
vtable
[
17
];
*
present_ex_addr
=
(
void
*
)
vtable
[
121
];
hr
=
device
->
GetSwapChain
(
0
,
&
swap
);
if
(
SUCCEEDED
(
hr
))
{
vtable
=
*
(
uintptr_t
**
)
swap
;
*
present_swap_addr
=
(
void
*
)
vtable
[
3
];
swap
->
Release
();
}
device
->
Release
();
}
else
{
hlog
(
"Failed to create D3D9 device"
);
return
false
;
}
return
true
;
}
bool
hook_d3d9
(
void
)
{
HMODULE
d3d9_module
=
get_system_module
(
"d3d9.dll"
);
void
*
present_addr
;
void
*
present_ex_addr
;
void
*
present_swap_addr
;
uint32_t
d3d9_size
;
void
*
present_addr
=
nullptr
;
void
*
present_ex_addr
=
nullptr
;
void
*
present_swap_addr
=
nullptr
;
if
(
!
d3d9_module
)
{
return
false
;
}
present_addr
=
get_offset_addr
(
d3d9_module
,
global_hook_info
->
offsets
.
d3d9
.
present
);
present_ex_addr
=
get_offset_addr
(
d3d9_module
,
global_hook_info
->
offsets
.
d3d9
.
present_ex
);
present_swap_addr
=
get_offset_addr
(
d3d9_module
,
global_hook_info
->
offsets
.
d3d9
.
present_swap
);
d3d9_size
=
module_size
(
d3d9_module
);
hook_init
(
&
present
,
present_addr
,
(
void
*
)
hook_present
,
"IDirect3DDevice9::Present"
);
hook_init
(
&
present_ex
,
present_ex_addr
,
(
void
*
)
hook_present_ex
,
"IDirect3DDevice9Ex::PresentEx"
);
hook_init
(
&
present_swap
,
present_swap_addr
,
(
void
*
)
hook_present_swap
,
"IDirect3DSwapChain9::Present"
);
if
(
global_hook_info
->
offsets
.
d3d9
.
present
<
d3d9_size
&&
global_hook_info
->
offsets
.
d3d9
.
present_ex
<
d3d9_size
&&
global_hook_info
->
offsets
.
d3d9
.
present_swap
<
d3d9_size
)
{
rehook
(
&
present_swap
);
rehook
(
&
present_ex
);
rehook
(
&
present
);
present_addr
=
get_offset_addr
(
d3d9_module
,
global_hook_info
->
offsets
.
d3d9
.
present
);
present_ex_addr
=
get_offset_addr
(
d3d9_module
,
global_hook_info
->
offsets
.
d3d9
.
present_ex
);
present_swap_addr
=
get_offset_addr
(
d3d9_module
,
global_hook_info
->
offsets
.
d3d9
.
present_swap
);
}
else
{
if
(
!
dummy_window
)
{
return
false
;
}
if
(
!
manually_get_d3d9_addrs
(
d3d9_module
,
&
present_addr
,
&
present_ex_addr
,
&
present_swap_addr
))
{
hlog
(
"Failed to get D3D9 values"
);
return
true
;
}
}
if
(
!
present_addr
&&
!
present_ex_addr
&&
!
present_swap_addr
)
{
hlog
(
"Invalid D3D9 values"
);
return
true
;
}
if
(
present_swap_addr
)
{
hook_init
(
&
present_swap
,
present_swap_addr
,
(
void
*
)
hook_present_swap
,
"IDirect3DSwapChain9::Present"
);
rehook
(
&
present_swap
);
}
if
(
present_ex_addr
)
{
hook_init
(
&
present_ex
,
present_ex_addr
,
(
void
*
)
hook_present_ex
,
"IDirect3DDevice9Ex::PresentEx"
);
rehook
(
&
present_ex
);
}
if
(
present_addr
)
{
hook_init
(
&
present
,
present_addr
,
(
void
*
)
hook_present
,
"IDirect3DDevice9::Present"
);
rehook
(
&
present
);
}
hlog
(
"Hooked D3D9"
);
return
true
;
...
...
plugins/win-capture/graphics-hook/graphics-hook.c
浏览文件 @
50c61898
...
...
@@ -35,11 +35,13 @@ HANDLE signal_exit = NULL;
HANDLE
tex_mutexes
[
2
]
=
{
NULL
,
NULL
};
static
HANDLE
filemap_hook_info
=
NULL
;
static
HINSTANCE
dll_inst
=
NULL
;
static
volatile
bool
stop_loop
=
false
;
static
HANDLE
capture_thread
=
NULL
;
char
system_path
[
MAX_PATH
]
=
{
0
};
char
process_name
[
MAX_PATH
]
=
{
0
};
char
keepalive_name
[
64
]
=
{
0
};
HWND
dummy_window
=
NULL
;
static
unsigned
int
shmem_id_counter
=
0
;
static
void
*
shmem_info
=
NULL
;
...
...
@@ -50,6 +52,7 @@ static struct thread_data thread_data = {0};
volatile
bool
active
=
false
;
struct
hook_info
*
global_hook_info
=
NULL
;
static
inline
void
wait_for_dll_main_finish
(
HANDLE
thread_handle
)
{
if
(
thread_handle
)
{
...
...
@@ -179,6 +182,55 @@ static inline bool init_hook_info(void)
return
true
;
}
#define DEF_FLAGS (WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS)
static
DWORD
WINAPI
dummy_window_thread
(
LPVOID
*
unused
)
{
static
const
wchar_t
dummy_window_class
[]
=
L"temp_d3d_window_4039785"
;
WNDCLASSW
wc
;
MSG
msg
;
memset
(
&
wc
,
0
,
sizeof
(
wc
));
wc
.
style
=
CS_OWNDC
;
wc
.
hInstance
=
dll_inst
;
wc
.
lpfnWndProc
=
(
WNDPROC
)
DefWindowProc
;
wc
.
lpszClassName
=
dummy_window_class
;
if
(
!
RegisterClass
(
&
wc
))
{
hlog
(
"Failed to create temp D3D window class: %lu"
,
GetLastError
());
return
0
;
}
dummy_window
=
CreateWindowExW
(
0
,
dummy_window_class
,
L"Temp Window"
,
DEF_FLAGS
,
0
,
0
,
1
,
1
,
NULL
,
NULL
,
dll_inst
,
NULL
);
if
(
!
dummy_window
)
{
hlog
(
"Failed to create temp D3D window: %lu"
,
GetLastError
());
return
0
;
}
while
(
GetMessage
(
&
msg
,
NULL
,
0
,
0
))
{
TranslateMessage
(
&
msg
);
DispatchMessage
(
&
msg
);
}
(
void
)
unused
;
return
0
;
}
static
inline
void
init_dummy_window_thread
(
void
)
{
HANDLE
thread
=
CreateThread
(
NULL
,
0
,
dummy_window_thread
,
NULL
,
0
,
NULL
);
if
(
!
thread
)
{
hlog
(
"Failed to create temp D3D window thread: %lu"
,
GetLastError
());
return
;
}
CloseHandle
(
thread
);
}
static
inline
bool
init_hook
(
HANDLE
thread_handle
)
{
wait_for_dll_main_finish
(
thread_handle
);
...
...
@@ -202,6 +254,7 @@ static inline bool init_hook(HANDLE thread_handle)
return
false
;
}
init_dummy_window_thread
();
log_current_process
();
SetEvent
(
signal_restart
);
...
...
@@ -737,6 +790,8 @@ BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID unused1)
if
(
reason
==
DLL_PROCESS_ATTACH
)
{
wchar_t
name
[
MAX_PATH
];
dll_inst
=
hinst
;
HANDLE
cur_thread
=
OpenThread
(
THREAD_ALL_ACCESS
,
false
,
GetCurrentThreadId
());
...
...
plugins/win-capture/graphics-hook/graphics-hook.h
浏览文件 @
50c61898
...
...
@@ -7,6 +7,7 @@
#include "../graphics-hook-info.h"
#include <ipc-util/pipe.h>
#include <psapi.h>
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -91,6 +92,7 @@ extern HANDLE tex_mutexes[2];
extern
char
system_path
[
MAX_PATH
];
extern
char
process_name
[
MAX_PATH
];
extern
char
keepalive_name
[
64
];
extern
HWND
dummy_window
;
extern
volatile
bool
active
;
static
inline
const
char
*
get_process_name
(
void
)
...
...
@@ -108,6 +110,14 @@ static inline HMODULE get_system_module(const char *module)
return
GetModuleHandleA
(
base_path
);
}
static
inline
uint32_t
module_size
(
HMODULE
module
)
{
MODULEINFO
info
;
bool
success
=
!!
GetModuleInformation
(
GetCurrentProcess
(),
module
,
&
info
,
sizeof
(
info
));
return
success
?
info
.
SizeOfImage
:
0
;
}
static
inline
HMODULE
load_system_library
(
const
char
*
name
)
{
char
base_path
[
MAX_PATH
];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录