forked from Dniel97/segatools
platform/misc.c: Add miscellaneous registry hooks
This commit is contained in:
parent
a74a5de128
commit
55062bf56b
@ -13,6 +13,8 @@ platform_lib = static_library(
|
||||
'config.h',
|
||||
'hwmon.c',
|
||||
'hwmon.h',
|
||||
'misc.c',
|
||||
'misc.h',
|
||||
'nusec.c',
|
||||
'nusec.h',
|
||||
'pcbid.c',
|
||||
|
134
platform/misc.c
Normal file
134
platform/misc.c
Normal file
@ -0,0 +1,134 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "hooklib/reg.h"
|
||||
|
||||
#include "platform/misc.h"
|
||||
|
||||
static HRESULT misc_read_os_version(void *bytes, uint32_t *nbytes);
|
||||
static HRESULT misc_read_app_loader_count(void *bytes, uint32_t *nbytes);
|
||||
static HRESULT misc_read_cpu_temp_error(void *bytes, uint32_t *nbytes);
|
||||
static HRESULT misc_read_cpu_temp_warning(void *bytes, uint32_t *nbytes);
|
||||
static HRESULT misc_read_platform_id(void *bytes, uint32_t *nbytes);
|
||||
|
||||
static const struct reg_hook_val misc_root_keys[] = {
|
||||
{
|
||||
.name = L"OSVersion",
|
||||
.read = misc_read_os_version,
|
||||
.type = REG_SZ,
|
||||
}
|
||||
};
|
||||
|
||||
static const struct reg_hook_val misc_master_keys[] = {
|
||||
{
|
||||
.name = L"AppLoaderCount",
|
||||
.read = misc_read_app_loader_count,
|
||||
.type = REG_DWORD,
|
||||
}, {
|
||||
/* Black-hole val, list it here so we don't get a warning msg */
|
||||
.name = L"NextProcess",
|
||||
.type = REG_SZ,
|
||||
}
|
||||
};
|
||||
|
||||
static const struct reg_hook_val misc_static_keys[] = {
|
||||
{
|
||||
.name = L"CpuTempError",
|
||||
.read = misc_read_cpu_temp_error,
|
||||
.type = REG_DWORD,
|
||||
}, {
|
||||
.name = L"CpuTempWarning",
|
||||
.read = misc_read_cpu_temp_warning,
|
||||
.type = REG_DWORD,
|
||||
}, {
|
||||
.name = L"PlatformId",
|
||||
.read = misc_read_platform_id,
|
||||
.type = REG_SZ,
|
||||
}
|
||||
};
|
||||
|
||||
static wchar_t misc_platform_id[5];
|
||||
|
||||
HRESULT misc_hook_init(const struct misc_config *cfg, const char *platform_id)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
assert(cfg != NULL);
|
||||
assert(platform_id != NULL && strlen(platform_id) == 4);
|
||||
|
||||
if (!cfg->enable) {
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
/* Set platform ID registry value */
|
||||
|
||||
mbstowcs_s(
|
||||
NULL,
|
||||
misc_platform_id,
|
||||
_countof(misc_platform_id),
|
||||
platform_id,
|
||||
_countof(misc_platform_id) - 1);
|
||||
|
||||
/* Add hardcoded dummy keys */
|
||||
|
||||
hr = reg_hook_push_key(
|
||||
HKEY_LOCAL_MACHINE,
|
||||
L"SYSTEM\\SEGA\\SystemProperty",
|
||||
misc_root_keys,
|
||||
_countof(misc_root_keys));
|
||||
|
||||
if (FAILED(hr)) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
hr = reg_hook_push_key(
|
||||
HKEY_LOCAL_MACHINE,
|
||||
L"SYSTEM\\SEGA\\SystemProperty\\static",
|
||||
misc_static_keys,
|
||||
_countof(misc_static_keys));
|
||||
|
||||
if (FAILED(hr)) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
hr = reg_hook_push_key(
|
||||
HKEY_LOCAL_MACHINE,
|
||||
L"SYSTEM\\SEGA\\SystemProperty\\Master",
|
||||
misc_master_keys,
|
||||
_countof(misc_master_keys));
|
||||
|
||||
if (FAILED(hr)) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT misc_read_os_version(void *bytes, uint32_t *nbytes)
|
||||
{
|
||||
return reg_hook_read_wstr(bytes, nbytes, L"0_0_0");
|
||||
}
|
||||
|
||||
static HRESULT misc_read_app_loader_count(void *bytes, uint32_t *nbytes)
|
||||
{
|
||||
return reg_hook_read_u32(bytes, nbytes, 1);
|
||||
}
|
||||
|
||||
static HRESULT misc_read_cpu_temp_error(void *bytes, uint32_t *nbytes)
|
||||
{
|
||||
return reg_hook_read_u32(bytes, nbytes, 100);
|
||||
}
|
||||
|
||||
static HRESULT misc_read_cpu_temp_warning(void *bytes, uint32_t *nbytes)
|
||||
{
|
||||
return reg_hook_read_u32(bytes, nbytes, 95);
|
||||
}
|
||||
|
||||
static HRESULT misc_read_platform_id(void *bytes, uint32_t *nbytes)
|
||||
{
|
||||
return reg_hook_read_wstr(bytes, nbytes, misc_platform_id);
|
||||
}
|
5
platform/misc.h
Normal file
5
platform/misc.h
Normal file
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "platform/config.h"
|
||||
|
||||
HRESULT misc_hook_init(const struct misc_config *cfg, const char *platform_id);
|
@ -5,6 +5,7 @@
|
||||
#include "platform/amvideo.h"
|
||||
#include "platform/config.h"
|
||||
#include "platform/hwmon.h"
|
||||
#include "platform/misc.h"
|
||||
#include "platform/nusec.h"
|
||||
#include "platform/platform.h"
|
||||
#include "platform/vfs.h"
|
||||
@ -34,6 +35,12 @@ HRESULT platform_hook_init_nu(
|
||||
return hr;
|
||||
}
|
||||
|
||||
hr = misc_hook_init(&cfg->misc, platform_id);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
hr = nusec_hook_init(&cfg->nusec, game_id, platform_id);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
|
Loading…
Reference in New Issue
Block a user