1
0
mirror of https://gitea.tendokyu.moe/Hay1tsme/segatools.git synced 2024-11-25 17:50:21 +01:00
segatools-hay1tsme/hooklib/dvd.c
6cb1008cabfc0d4485696f6df7431a5e27604e1b 031ccb154b dvd: move thread safety comment into header file
2021-06-17 04:13:50 +02:00

83 lines
1.6 KiB
C

#include <windows.h>
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include "hook/com-proxy.h"
#include "hook/table.h"
#include "hooklib/config.h"
#include "hooklib/dll.h"
#include "hooklib/dvd.h"
#include "util/dprintf.h"
/* API hooks */
static DWORD WINAPI hook_QueryDosDeviceW(
const wchar_t *lpDeviceName,
wchar_t *lpTargetPath,
DWORD ucchMax);
/* Link pointers */
static DWORD (WINAPI *next_QueryDosDeviceW)(
const wchar_t *lpDeviceName,
wchar_t *lpTargetPath,
DWORD ucchMax);
static bool dvd_hook_initted;
static struct dvd_config dvd_config;
static const struct hook_symbol dvd_hooks[] = {
{
.name = "QueryDosDeviceW",
.patch = hook_QueryDosDeviceW,
.link = (void **) &next_QueryDosDeviceW
},
};
void dvd_hook_init(const struct dvd_config *cfg, HINSTANCE self)
{
assert(cfg != NULL);
if (!cfg->enable) {
return;
}
if (dvd_hook_initted) {
return;
}
dvd_hook_initted = true;
memcpy(&dvd_config, cfg, sizeof(*cfg));
hook_table_apply(NULL, "kernel32.dll", dvd_hooks, _countof(dvd_hooks));
dprintf("DVD: hook enabled.\n");
}
DWORD WINAPI hook_QueryDosDeviceW(
const wchar_t *lpDeviceName,
wchar_t *lpTargetPath,
DWORD ucchMax)
{
DWORD ok;
wchar_t *p_dest;
wchar_t *dvd_string = L"CdRom";
ok = next_QueryDosDeviceW(
lpDeviceName,
lpTargetPath,
ucchMax);
p_dest = wcsstr (lpTargetPath, dvd_string);
if ( p_dest != NULL ) {
dprintf("DVD: Hiding DVD drive.\n");
return 0;
}
return ok;
}