load-graphics-offsets.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <obs-module.h>
  3. #include <util/platform.h>
  4. #include <util/dstr.h>
  5. #include <util/config-file.h>
  6. #include <util/pipe.h>
  7. #include <windows.h>
  8. #include "graphics-hook-info.h"
  9. extern struct graphics_offsets offsets32;
  10. extern struct graphics_offsets offsets64;
  11. static inline bool load_offsets_from_string(struct graphics_offsets *offsets,
  12. const char *str)
  13. {
  14. config_t *config;
  15. if (config_open_string(&config, str) != CONFIG_SUCCESS) {
  16. return false;
  17. }
  18. offsets->d3d8.present =
  19. (uint32_t)config_get_uint(config, "d3d8", "present");
  20. offsets->d3d8.reset =
  21. (uint32_t)config_get_uint(config, "d3d8", "reset");
  22. offsets->d3d9.present =
  23. (uint32_t)config_get_uint(config, "d3d9", "present");
  24. offsets->d3d9.present_ex =
  25. (uint32_t)config_get_uint(config, "d3d9", "present_ex");
  26. offsets->d3d9.present_swap =
  27. (uint32_t)config_get_uint(config, "d3d9", "present_swap");
  28. offsets->d3d9.reset =
  29. (uint32_t)config_get_uint(config, "d3d9", "reset");
  30. offsets->d3d9.reset_ex =
  31. (uint32_t)config_get_uint(config, "d3d9", "reset_ex");
  32. offsets->dxgi.present =
  33. (uint32_t)config_get_uint(config, "dxgi", "present");
  34. offsets->dxgi.resize =
  35. (uint32_t)config_get_uint(config, "dxgi", "resize");
  36. config_close(config);
  37. return true;
  38. }
  39. bool load_graphics_offsets(bool is32bit)
  40. {
  41. char *offset_exe_path = NULL;
  42. struct dstr offset_exe = {0};
  43. struct dstr str = {0};
  44. os_process_pipe_t *pp;
  45. bool success = false;
  46. char data[128];
  47. dstr_copy(&offset_exe, "get-graphics-offsets");
  48. dstr_cat(&offset_exe, is32bit ? "32.exe" : "64.exe");
  49. offset_exe_path = obs_module_file(offset_exe.array);
  50. pp = os_process_pipe_create(offset_exe_path, "r");
  51. if (!pp) {
  52. blog(LOG_INFO, "load_graphics_offsets: Failed to start '%s'",
  53. offset_exe.array);
  54. goto error;
  55. }
  56. for (;;) {
  57. size_t len = os_process_pipe_read(pp, (uint8_t*)data, 128);
  58. if (!len)
  59. break;
  60. dstr_ncat(&str, data, len);
  61. }
  62. success = load_offsets_from_string(is32bit ? &offsets32 : &offsets64,
  63. str.array);
  64. if (!success) {
  65. blog(LOG_INFO, "load_graphics_offsets: Failed to load string");
  66. }
  67. os_process_pipe_destroy(pp);
  68. error:
  69. bfree(offset_exe_path);
  70. dstr_free(&offset_exe);
  71. dstr_free(&str);
  72. return success;
  73. }