forked from Dniel97/segatools
Add dvd hook to allow hiding connected dvd drives
This commit is contained in:
parent
7123a9feff
commit
56a32fd80a
@ -6,6 +6,7 @@
|
||||
|
||||
#include "hooklib/config.h"
|
||||
#include "hooklib/gfx.h"
|
||||
#include "hooklib/dvd.h"
|
||||
|
||||
void gfx_config_load(struct gfx_config *cfg, const wchar_t *filename)
|
||||
{
|
||||
@ -17,3 +18,11 @@ void gfx_config_load(struct gfx_config *cfg, const wchar_t *filename)
|
||||
cfg->framed = GetPrivateProfileIntW(L"gfx", L"framed", 1, filename);
|
||||
cfg->monitor = GetPrivateProfileIntW(L"gfx", L"monitor", 0, filename);
|
||||
}
|
||||
|
||||
void dvd_config_load(struct dvd_config *cfg, const wchar_t *filename)
|
||||
{
|
||||
assert(cfg != NULL);
|
||||
assert(filename != NULL);
|
||||
|
||||
cfg->enable = GetPrivateProfileIntW(L"dvd", L"enable", 1, filename);
|
||||
}
|
||||
|
@ -4,5 +4,7 @@
|
||||
#include <stddef.h>
|
||||
|
||||
#include "hooklib/gfx.h"
|
||||
#include "hooklib/dvd.h"
|
||||
|
||||
void gfx_config_load(struct gfx_config *cfg, const wchar_t *filename);
|
||||
void dvd_config_load(struct dvd_config *cfg, const wchar_t *filename);
|
||||
|
85
hooklib/dvd.c
Normal file
85
hooklib/dvd.c
Normal file
@ -0,0 +1,85 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
/* Init is not thread safe because API hook init is not thread safe blah
|
||||
blah blah you know the drill by now. */
|
||||
|
||||
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;
|
||||
}
|
11
hooklib/dvd.h
Normal file
11
hooklib/dvd.h
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
struct dvd_config {
|
||||
bool enable;
|
||||
};
|
||||
|
||||
void dvd_hook_init(const struct dvd_config *cfg, HINSTANCE self);
|
@ -13,6 +13,8 @@ hooklib_lib = static_library(
|
||||
'dll.h',
|
||||
'dns.c',
|
||||
'dns.h',
|
||||
'dvd.c',
|
||||
'dvd.h',
|
||||
'fdshark.c',
|
||||
'fdshark.h',
|
||||
'gfx.c',
|
||||
|
@ -7,6 +7,9 @@
|
||||
#include "board/config.h"
|
||||
#include "board/sg-reader.h"
|
||||
|
||||
#include "hooklib/config.h"
|
||||
#include "hooklib/dvd.h"
|
||||
|
||||
#include "idzhook/config.h"
|
||||
#include "idzhook/idz-dll.h"
|
||||
|
||||
@ -41,6 +44,7 @@ void idz_hook_config_load(
|
||||
aime_config_load(&cfg->aime, filename);
|
||||
idz_dll_config_load(&cfg->dll, filename);
|
||||
zinput_config_load(&cfg->zinput, filename);
|
||||
dvd_config_load(&cfg->dvd, filename);
|
||||
}
|
||||
|
||||
void zinput_config_load(struct zinput_config *cfg, const wchar_t *filename)
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
#include "board/sg-reader.h"
|
||||
|
||||
#include "hooklib/dvd.h"
|
||||
|
||||
#include "idzhook/idz-dll.h"
|
||||
#include "idzhook/zinput.h"
|
||||
|
||||
@ -16,6 +18,7 @@ struct idz_hook_config {
|
||||
struct platform_config platform;
|
||||
struct amex_config amex;
|
||||
struct aime_config aime;
|
||||
struct dvd_config dvd;
|
||||
struct idz_dll_config dll;
|
||||
struct zinput_config zinput;
|
||||
};
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
#include "hook/process.h"
|
||||
|
||||
#include "hooklib/gfx.h"
|
||||
#include "hooklib/dvd.h"
|
||||
#include "hooklib/serial.h"
|
||||
#include "hooklib/spike.h"
|
||||
|
||||
@ -39,6 +39,7 @@ static DWORD CALLBACK idz_pre_startup(void)
|
||||
|
||||
serial_hook_init();
|
||||
zinput_hook_init(&idz_hook_cfg.zinput);
|
||||
dvd_hook_init(&idz_hook_cfg.dvd, idz_hook_mod);
|
||||
|
||||
/* Initialize emulation hooks */
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "board/config.h"
|
||||
|
||||
#include "hooklib/config.h"
|
||||
#include "hooklib/dvd.h"
|
||||
#include "hooklib/gfx.h"
|
||||
|
||||
#include "mu3hook/config.h"
|
||||
@ -35,6 +36,7 @@ void mu3_hook_config_load(
|
||||
|
||||
platform_config_load(&cfg->platform, filename);
|
||||
aime_config_load(&cfg->aime, filename);
|
||||
dvd_config_load(&cfg->dvd, filename);
|
||||
gfx_config_load(&cfg->gfx, filename);
|
||||
mu3_dll_config_load(&cfg->dll, filename);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "board/config.h"
|
||||
|
||||
#include "hooklib/dvd.h"
|
||||
#include "hooklib/gfx.h"
|
||||
|
||||
#include "mu3hook/mu3-dll.h"
|
||||
@ -13,6 +14,7 @@
|
||||
struct mu3_hook_config {
|
||||
struct platform_config platform;
|
||||
struct aime_config aime;
|
||||
struct dvd_config dvd;
|
||||
struct gfx_config gfx;
|
||||
struct mu3_dll_config dll;
|
||||
};
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "hook/process.h"
|
||||
|
||||
#include "hooklib/dvd.h"
|
||||
#include "hooklib/serial.h"
|
||||
#include "hooklib/spike.h"
|
||||
|
||||
@ -36,6 +37,7 @@ static DWORD CALLBACK mu3_pre_startup(void)
|
||||
|
||||
/* Hook Win32 APIs */
|
||||
|
||||
dvd_hook_init(&mu3_hook_cfg.dvd, mu3_hook_mod);
|
||||
gfx_hook_init(&mu3_hook_cfg.gfx, mu3_hook_mod);
|
||||
serial_hook_init();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user