plugin-main.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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, const char *config_path);
  14. extern bool load_graphics_offsets(bool is32bit, const char *config_path);
  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 param)
  24. {
  25. char *config_path = param;
  26. if (USE_HOOK_ADDRESS_CACHE &&
  27. cached_versions_match() &&
  28. load_cached_graphics_offsets(IS32BIT, config_path)) {
  29. load_cached_graphics_offsets(!IS32BIT, config_path);
  30. obs_register_source(&game_capture_info);
  31. } else if (load_graphics_offsets(IS32BIT, config_path)) {
  32. load_graphics_offsets(!IS32BIT, config_path);
  33. }
  34. bfree(config_path);
  35. return 0;
  36. }
  37. void wait_for_hook_initialization(void)
  38. {
  39. static bool initialized = false;
  40. if (!initialized) {
  41. if (init_hooks_thread) {
  42. WaitForSingleObject(init_hooks_thread, INFINITE);
  43. CloseHandle(init_hooks_thread);
  44. init_hooks_thread = NULL;
  45. }
  46. initialized = true;
  47. }
  48. }
  49. bool obs_module_load(void)
  50. {
  51. struct win_version_info ver;
  52. bool win8_or_above = false;
  53. char *config_dir;
  54. config_dir = obs_module_config_path(NULL);
  55. if (config_dir) {
  56. os_mkdirs(config_dir);
  57. bfree(config_dir);
  58. }
  59. get_win_ver(&ver);
  60. win8_or_above = ver.major > 6 || (ver.major == 6 && ver.minor >= 2);
  61. obs_enter_graphics();
  62. if (win8_or_above && gs_get_device_type() == GS_DEVICE_DIRECT3D_11)
  63. obs_register_source(&duplicator_capture_info);
  64. else
  65. obs_register_source(&monitor_capture_info);
  66. obs_leave_graphics();
  67. obs_register_source(&window_capture_info);
  68. char *config_path = obs_module_config_path(NULL);
  69. init_hooks_thread = CreateThread(NULL, 0, init_hooks, config_path, 0, NULL);
  70. obs_register_source(&game_capture_info);
  71. return true;
  72. }
  73. void obs_module_unload(void)
  74. {
  75. wait_for_hook_initialization();
  76. }