win-capture: Refactor inline functions
Apparently someone dumb (aka me) neglected to properly handle the inline graphics hook API functions. You're not supposed to 'extern' inline functions, they need to be defined for each file when ever they're used.
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
#include <windows.h>
|
||||
#include <shlobj.h>
|
||||
#include <psapi.h>
|
||||
#include <ipc-util/pipe.h>
|
||||
#include "graphics-hook.h"
|
||||
#include "../obfuscate.h"
|
||||
#include "../funchook.h"
|
||||
@@ -29,19 +28,19 @@ struct thread_data {
|
||||
volatile bool locked_textures[NUM_BUFFERS];
|
||||
};
|
||||
|
||||
static ipc_pipe_client_t pipe = {0};
|
||||
static HANDLE signal_restart = NULL;
|
||||
static HANDLE signal_stop = NULL;
|
||||
static HANDLE signal_ready = NULL;
|
||||
static HANDLE signal_exit = NULL;
|
||||
static HANDLE tex_mutexes[2] = {NULL, NULL};
|
||||
ipc_pipe_client_t pipe = {0};
|
||||
HANDLE signal_restart = NULL;
|
||||
HANDLE signal_stop = NULL;
|
||||
HANDLE signal_ready = NULL;
|
||||
HANDLE signal_exit = NULL;
|
||||
HANDLE tex_mutexes[2] = {NULL, NULL};
|
||||
static HANDLE filemap_hook_info = NULL;
|
||||
|
||||
static volatile bool stop_loop = false;
|
||||
static HANDLE capture_thread = NULL;
|
||||
static char system_path[MAX_PATH] = {0};
|
||||
static char process_name[MAX_PATH] = {0};
|
||||
static char keepalive_name[64] = {0};
|
||||
char system_path[MAX_PATH] = {0};
|
||||
char process_name[MAX_PATH] = {0};
|
||||
char keepalive_name[64] = {0};
|
||||
|
||||
static unsigned int shmem_id_counter = 0;
|
||||
static void *shmem_info = NULL;
|
||||
@@ -401,87 +400,6 @@ void hlog_hr(const char *text, HRESULT hr)
|
||||
}
|
||||
}
|
||||
|
||||
inline const char *get_process_name(void)
|
||||
{
|
||||
return process_name;
|
||||
}
|
||||
|
||||
inline HMODULE get_system_module(const char *module)
|
||||
{
|
||||
char base_path[MAX_PATH];
|
||||
|
||||
strcpy(base_path, system_path);
|
||||
strcat(base_path, "\\");
|
||||
strcat(base_path, module);
|
||||
return GetModuleHandleA(module);
|
||||
}
|
||||
|
||||
inline HMODULE load_system_library(const char *name)
|
||||
{
|
||||
char base_path[MAX_PATH];
|
||||
HMODULE module;
|
||||
|
||||
strcpy(base_path, system_path);
|
||||
strcat(base_path, "\\");
|
||||
strcat(base_path, name);
|
||||
|
||||
module = GetModuleHandleA(base_path);
|
||||
if (module)
|
||||
return module;
|
||||
|
||||
return LoadLibraryA(base_path);
|
||||
}
|
||||
|
||||
static inline bool capture_alive(void)
|
||||
{
|
||||
HANDLE event = OpenEventA(EVENT_ALL_ACCESS, false, keepalive_name);
|
||||
if (event) {
|
||||
CloseHandle(event);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool capture_active(void)
|
||||
{
|
||||
return active;
|
||||
}
|
||||
|
||||
static inline bool capture_stopped(void)
|
||||
{
|
||||
return WaitForSingleObject(signal_stop, 0) == WAIT_OBJECT_0;
|
||||
}
|
||||
|
||||
static inline bool capture_restarted(void)
|
||||
{
|
||||
return WaitForSingleObject(signal_restart, 0) == WAIT_OBJECT_0;
|
||||
}
|
||||
|
||||
inline bool capture_should_stop(void)
|
||||
{
|
||||
bool stop_requested = false;
|
||||
|
||||
if (capture_active())
|
||||
stop_requested = capture_stopped() || !capture_alive();
|
||||
|
||||
return stop_requested;
|
||||
}
|
||||
|
||||
inline bool capture_should_init(void)
|
||||
{
|
||||
if (!capture_active() && capture_restarted()) {
|
||||
if (capture_alive()) {
|
||||
if (!ipc_pipe_client_valid(&pipe)) {
|
||||
init_pipe();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline uint64_t get_clockfreq(void)
|
||||
{
|
||||
static bool have_clockfreq = false;
|
||||
@@ -508,7 +426,7 @@ uint64_t os_gettime_ns(void)
|
||||
return (uint64_t)time_val;
|
||||
}
|
||||
|
||||
inline int try_lock_shmem_tex(int id)
|
||||
static inline int try_lock_shmem_tex(int id)
|
||||
{
|
||||
int next = id == 0 ? 1 : 0;
|
||||
|
||||
@@ -521,40 +439,13 @@ inline int try_lock_shmem_tex(int id)
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline void unlock_shmem_tex(int id)
|
||||
static inline void unlock_shmem_tex(int id)
|
||||
{
|
||||
if (id != -1) {
|
||||
ReleaseMutex(tex_mutexes[id]);
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool frame_ready(uint64_t interval)
|
||||
{
|
||||
static uint64_t last_time = 0;
|
||||
uint64_t elapsed;
|
||||
uint64_t t;
|
||||
|
||||
if (!interval) {
|
||||
return true;
|
||||
}
|
||||
|
||||
t = os_gettime_ns();
|
||||
elapsed = t - last_time;
|
||||
|
||||
if (elapsed < interval) {
|
||||
return false;
|
||||
}
|
||||
|
||||
last_time = (elapsed > interval * 2) ? t : last_time + interval;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool capture_ready(void)
|
||||
{
|
||||
return capture_active() &&
|
||||
frame_ready(global_hook_info->frame_interval);
|
||||
}
|
||||
|
||||
static inline bool init_shared_info(size_t size)
|
||||
{
|
||||
char name[64];
|
||||
@@ -675,7 +566,7 @@ finish:
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline void shmem_copy_data(size_t idx, void *volatile data)
|
||||
void shmem_copy_data(size_t idx, void *volatile data)
|
||||
{
|
||||
EnterCriticalSection(&thread_data.data_mutex);
|
||||
thread_data.cur_tex = (int)idx;
|
||||
@@ -686,7 +577,7 @@ inline void shmem_copy_data(size_t idx, void *volatile data)
|
||||
SetEvent(thread_data.copy_event);
|
||||
}
|
||||
|
||||
inline bool shmem_texture_data_lock(int idx)
|
||||
bool shmem_texture_data_lock(int idx)
|
||||
{
|
||||
bool locked;
|
||||
|
||||
@@ -702,7 +593,7 @@ inline bool shmem_texture_data_lock(int idx)
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void shmem_texture_data_unlock(int idx)
|
||||
void shmem_texture_data_unlock(int idx)
|
||||
{
|
||||
EnterCriticalSection(&thread_data.data_mutex);
|
||||
thread_data.locked_textures[idx] = false;
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#endif
|
||||
|
||||
#include "../graphics-hook-info.h"
|
||||
#include <ipc-util/pipe.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -19,19 +20,19 @@ extern "C" {
|
||||
|
||||
extern void hlog(const char *format, ...);
|
||||
extern void hlog_hr(const char *text, HRESULT hr);
|
||||
extern inline const char *get_process_name(void);
|
||||
extern inline HMODULE get_system_module(const char *module);
|
||||
extern inline HMODULE load_system_library(const char *module);
|
||||
static inline const char *get_process_name(void);
|
||||
static inline HMODULE get_system_module(const char *module);
|
||||
static inline HMODULE load_system_library(const char *module);
|
||||
extern uint64_t os_gettime_ns(void);
|
||||
|
||||
extern inline bool capture_active(void);
|
||||
extern inline bool capture_ready(void);
|
||||
extern inline bool capture_should_stop(void);
|
||||
extern inline bool capture_should_init(void);
|
||||
static inline bool capture_active(void);
|
||||
static inline bool capture_ready(void);
|
||||
static inline bool capture_should_stop(void);
|
||||
static inline bool capture_should_init(void);
|
||||
|
||||
extern inline void shmem_copy_data(size_t idx, void *volatile data);
|
||||
extern inline bool shmem_texture_data_lock(int idx);
|
||||
extern inline void shmem_texture_data_unlock(int idx);
|
||||
extern void shmem_copy_data(size_t idx, void *volatile data);
|
||||
extern bool shmem_texture_data_lock(int idx);
|
||||
extern void shmem_texture_data_unlock(int idx);
|
||||
|
||||
extern bool hook_ddraw(void);
|
||||
extern bool hook_d3d8(void);
|
||||
@@ -79,6 +80,129 @@ static inline void *get_offset_addr(HMODULE module, uint32_t offset)
|
||||
return (void*)((uintptr_t)module + (uintptr_t)offset);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
extern ipc_pipe_client_t pipe;
|
||||
extern HANDLE signal_restart;
|
||||
extern HANDLE signal_stop;
|
||||
extern HANDLE signal_ready;
|
||||
extern HANDLE signal_exit;
|
||||
extern HANDLE tex_mutexes[2];
|
||||
extern char system_path[MAX_PATH];
|
||||
extern char process_name[MAX_PATH];
|
||||
extern char keepalive_name[64];
|
||||
extern volatile bool active;
|
||||
|
||||
static inline const char *get_process_name(void)
|
||||
{
|
||||
return process_name;
|
||||
}
|
||||
|
||||
static inline HMODULE get_system_module(const char *module)
|
||||
{
|
||||
char base_path[MAX_PATH];
|
||||
|
||||
strcpy(base_path, system_path);
|
||||
strcat(base_path, "\\");
|
||||
strcat(base_path, module);
|
||||
return GetModuleHandleA(module);
|
||||
}
|
||||
|
||||
static inline HMODULE load_system_library(const char *name)
|
||||
{
|
||||
char base_path[MAX_PATH];
|
||||
HMODULE module;
|
||||
|
||||
strcpy(base_path, system_path);
|
||||
strcat(base_path, "\\");
|
||||
strcat(base_path, name);
|
||||
|
||||
module = GetModuleHandleA(base_path);
|
||||
if (module)
|
||||
return module;
|
||||
|
||||
return LoadLibraryA(base_path);
|
||||
}
|
||||
|
||||
static inline bool capture_alive(void)
|
||||
{
|
||||
HANDLE event = OpenEventA(EVENT_ALL_ACCESS, false, keepalive_name);
|
||||
if (event) {
|
||||
CloseHandle(event);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool capture_active(void)
|
||||
{
|
||||
return active;
|
||||
}
|
||||
|
||||
static inline bool frame_ready(uint64_t interval)
|
||||
{
|
||||
static uint64_t last_time = 0;
|
||||
uint64_t elapsed;
|
||||
uint64_t t;
|
||||
|
||||
if (!interval) {
|
||||
return true;
|
||||
}
|
||||
|
||||
t = os_gettime_ns();
|
||||
elapsed = t - last_time;
|
||||
|
||||
if (elapsed < interval) {
|
||||
return false;
|
||||
}
|
||||
|
||||
last_time = (elapsed > interval * 2) ? t : last_time + interval;
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool capture_ready(void)
|
||||
{
|
||||
return capture_active() &&
|
||||
frame_ready(global_hook_info->frame_interval);
|
||||
}
|
||||
|
||||
static inline bool capture_stopped(void)
|
||||
{
|
||||
return WaitForSingleObject(signal_stop, 0) == WAIT_OBJECT_0;
|
||||
}
|
||||
|
||||
static inline bool capture_restarted(void)
|
||||
{
|
||||
return WaitForSingleObject(signal_restart, 0) == WAIT_OBJECT_0;
|
||||
}
|
||||
|
||||
static inline bool capture_should_stop(void)
|
||||
{
|
||||
bool stop_requested = false;
|
||||
|
||||
if (capture_active())
|
||||
stop_requested = capture_stopped() || !capture_alive();
|
||||
|
||||
return stop_requested;
|
||||
}
|
||||
|
||||
extern bool init_pipe(void);
|
||||
|
||||
static inline bool capture_should_init(void)
|
||||
{
|
||||
if (!capture_active() && capture_restarted()) {
|
||||
if (capture_alive()) {
|
||||
if (!ipc_pipe_client_valid(&pipe)) {
|
||||
init_pipe();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user