plugin-main.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include <windows.h>
  2. #include <obs-module.h>
  3. #include <util/windows/win-version.h>
  4. #include <util/platform.h>
  5. OBS_DECLARE_MODULE()
  6. OBS_MODULE_USE_DEFAULT_LOCALE("win-capture", "en-US")
  7. extern struct obs_source_info duplicator_capture_info;
  8. extern struct obs_source_info monitor_capture_info;
  9. extern struct obs_source_info window_capture_info;
  10. extern struct obs_source_info game_capture_info;
  11. static HANDLE init_hooks_thread = NULL;
  12. extern bool cached_versions_match(void);
  13. extern bool load_cached_graphics_offsets(bool is32bit);
  14. extern bool load_graphics_offsets(bool is32bit);
  15. /* temporary, will eventually be erased once we figure out how to create both
  16. * 32bit and 64bit versions of the helpers/hook */
  17. #ifdef _WIN64
  18. #define IS32BIT false
  19. #else
  20. #define IS32BIT true
  21. #endif
  22. #define USE_HOOK_ADDRESS_CACHE false
  23. static DWORD WINAPI init_hooks(LPVOID unused)
  24. {
  25. if (USE_HOOK_ADDRESS_CACHE &&
  26. cached_versions_match() &&
  27. load_cached_graphics_offsets(IS32BIT)) {
  28. load_cached_graphics_offsets(!IS32BIT);
  29. obs_register_source(&game_capture_info);
  30. } else if (load_graphics_offsets(IS32BIT)) {
  31. load_graphics_offsets(!IS32BIT);
  32. }
  33. UNUSED_PARAMETER(unused);
  34. return 0;
  35. }
  36. void wait_for_hook_initialization(void)
  37. {
  38. static bool initialized = false;
  39. if (!initialized) {
  40. if (init_hooks_thread) {
  41. WaitForSingleObject(init_hooks_thread, INFINITE);
  42. CloseHandle(init_hooks_thread);
  43. init_hooks_thread = NULL;
  44. }
  45. initialized = true;
  46. }
  47. }
  48. bool obs_module_load(void)
  49. {
  50. struct win_version_info ver;
  51. bool win8_or_above = false;
  52. char *config_dir;
  53. config_dir = obs_module_config_path(NULL);
  54. if (config_dir) {
  55. os_mkdirs(config_dir);
  56. bfree(config_dir);
  57. }
  58. get_win_ver(&ver);
  59. win8_or_above = ver.major > 6 || (ver.major == 6 && ver.minor >= 2);
  60. obs_enter_graphics();
  61. if (win8_or_above && gs_get_device_type() == GS_DEVICE_DIRECT3D_11)
  62. obs_register_source(&duplicator_capture_info);
  63. else
  64. obs_register_source(&monitor_capture_info);
  65. obs_leave_graphics();
  66. obs_register_source(&window_capture_info);
  67. init_hooks_thread = CreateThread(NULL, 0, init_hooks, NULL, 0, NULL);
  68. obs_register_source(&game_capture_info);
  69. return true;
  70. }
  71. void obs_module_unload(void)
  72. {
  73. wait_for_hook_initialization();
  74. }