1
0
mirror of synced 2024-12-18 07:05:52 +01:00
bananatools/platform/misc.c

127 lines
2.8 KiB
C
Raw Normal View History

2023-01-03 05:35:53 +01:00
#include <windows.h>
#include <winuser.h>
#include <assert.h>
#include <stdint.h>
#include "hook/table.h"
2023-09-18 09:56:15 +02:00
#include "hooklib/reg.h"
2023-01-03 05:35:53 +01:00
#include "platform/misc.h"
#include "util/dprintf.h"
// BlockInput
// ShowCursor
static BOOL WINAPI my_BlockInput(BOOL fBlockIt);
static int WINAPI my_ShowCursor(BOOL bShow);
static BOOL WINAPI my_GetCursorInfo(PCURSORINFO pci);
2023-09-18 09:56:15 +02:00
static HRESULT reg_read_sys_ver(void *bytes, uint32_t *nbytes);
2023-01-03 05:35:53 +01:00
static BOOL (WINAPI *next_BlockInput)(BOOL fBlockIt);
static int (WINAPI *next_ShowCursor)(BOOL bShow);
static BOOL (WINAPI *next_GetCursorInfo)(PCURSORINFO pci);
2023-09-18 09:56:15 +02:00
static struct misc_config config;
static int real_cursor_state = 0;
2023-01-03 05:35:53 +01:00
static const struct hook_symbol misc_hook_syms[] = {
{
.name = "BlockInput",
.patch = my_BlockInput,
.link = (void **) &next_BlockInput,
}, {
.name = "ShowCursor",
.patch = my_ShowCursor,
.link = (void **) &next_ShowCursor,
}, {
.name = "GetCursorInfo",
.patch = my_GetCursorInfo,
.link = (void **) &next_GetCursorInfo,
}
};
2023-09-18 09:56:15 +02:00
static const struct reg_hook_val nbgi_reg[] = {
{
.name = L"SystemVersion",
.type = REG_SZ,
.read = reg_read_sys_ver
}
};
2023-01-03 05:35:53 +01:00
HRESULT misc_hook_init(const struct misc_config *cfg)
{
assert(cfg != NULL);
2023-09-18 09:56:15 +02:00
memcpy(&config, cfg, sizeof(*cfg));
2023-01-03 05:35:53 +01:00
dprintf("Misc: init\n");
hook_table_apply(
NULL,
"User32.dll",
misc_hook_syms,
_countof(misc_hook_syms));
2023-09-18 09:56:15 +02:00
reg_hook_push_key(
HKEY_LOCAL_MACHINE,
L"SOFTWARE\\NBGI",
nbgi_reg,
_countof(nbgi_reg));
2023-01-03 05:35:53 +01:00
return S_OK;
}
static BOOL WINAPI my_BlockInput(BOOL fBlockIt)
{
2023-09-18 09:56:15 +02:00
if (!config.block_input_hook) {
2023-01-03 05:35:53 +01:00
return next_BlockInput(fBlockIt);
}
dprintf("Misc: Block BlockInput -> %d\n", fBlockIt);
return true;
}
static int WINAPI my_ShowCursor(BOOL bShow)
{
2023-09-18 09:56:15 +02:00
if (!config.show_cursor_hook) {
2023-01-03 05:35:53 +01:00
return next_ShowCursor(bShow);
}
dprintf("Misc: Block ShowCursor -> %d\n", bShow);
// Keep track for GetCursorInfo
if (bShow) {
return ++real_cursor_state;
} else {
return --real_cursor_state;
}
}
static BOOL WINAPI my_GetCursorInfo(PCURSORINFO pci)
{
2023-09-18 09:56:15 +02:00
if (!config.show_cursor_hook) {
2023-01-03 05:35:53 +01:00
return next_GetCursorInfo(pci);
}
// Game only seems to read the flags field,
// so that's all we'll mess with
dprintf("Misc: my_GetCursorInfo\n");
if (real_cursor_state >= 0) {
pci->flags = CURSOR_SHOWING;
} else {
pci->flags = 0;
}
return true;
2023-09-18 09:56:15 +02:00
}
static HRESULT reg_read_sys_ver(void *bytes, uint32_t *nbytes)
{
dprintf("Misc: Get system version\n");
return reg_hook_read_wstr(bytes, nbytes, config.system_version);
2023-01-03 05:35:53 +01:00
}