hooklib/spike.c: Add a measure of configurability

This commit is contained in:
Tau 2019-10-19 16:15:14 -04:00
parent 5ed6eaa203
commit dfcf3d8bd1
8 changed files with 53 additions and 13 deletions

View File

@ -25,13 +25,12 @@ static DWORD CALLBACK app_pre_startup(void)
aime_config_load(&app_aime_config, L".\\segatools.ini"); aime_config_load(&app_aime_config, L".\\segatools.ini");
dns_config_load(&app_dns_config, L".\\segatools.ini"); dns_config_load(&app_dns_config, L".\\segatools.ini");
spike_hook_init(L".\\segatools.ini");
serial_hook_init(); serial_hook_init();
sg_reader_hook_init(&app_aime_config, 12); sg_reader_hook_init(&app_aime_config, 12);
dns_platform_hook_init(&app_dns_config); dns_platform_hook_init(&app_dns_config);
spike_hook_init("cardspike.txt");
dprintf("--- End %s ---\n", __func__); dprintf("--- End %s ---\n", __func__);
return app_startup(); return app_startup();

View File

@ -63,7 +63,7 @@ static DWORD CALLBACK chuni_pre_startup(void)
/* Initialize debug helpers */ /* Initialize debug helpers */
spike_hook_init("chunispike.txt"); spike_hook_init(L".\\segatools.ini");
gfx_set_windowed(); gfx_set_windowed();
dprintf("--- End chuni_pre_startup ---\n"); dprintf("--- End chuni_pre_startup ---\n");

View File

@ -51,7 +51,7 @@ static DWORD CALLBACK diva_pre_startup(void)
/* Initialize debug helpers */ /* Initialize debug helpers */
spike_hook_init("divaspike.txt"); spike_hook_init(L".\\segatools.ini");
dprintf("--- End diva_pre_startup ---\n"); dprintf("--- End diva_pre_startup ---\n");

View File

@ -4,6 +4,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <wchar.h>
#include "hook/pe.h" #include "hook/pe.h"
@ -11,6 +12,8 @@
#include "util/dprintf.h" #include "util/dprintf.h"
static void spike_hook_read_config(const wchar_t *spike_file);
/* Spike functions. Their "style" is named after the libc function they bear /* Spike functions. Their "style" is named after the libc function they bear
the closest resemblance to. */ the closest resemblance to. */
@ -133,7 +136,44 @@ static void spike_insert_log_levels(ptrdiff_t rva, size_t count)
/* Config reader */ /* Config reader */
void spike_hook_init(const char *path) void spike_hook_init(const wchar_t *ini_file)
{
wchar_t module[MAX_PATH];
wchar_t path[MAX_PATH];
const wchar_t *basename;
const wchar_t *slash;
assert(ini_file != NULL);
/* Get the filename (strip path) of the host EXE */
GetModuleFileNameW(NULL, module, _countof(module));
slash = wcsrchr(module, L'\\');
if (slash != NULL) {
basename = slash + 1;
} else {
basename = module;
}
/* Check our INI file to see if any spikes are configured for this EXE.
Normally we separate out config reading into a separate module... */
GetPrivateProfileStringW(
L"spike",
basename,
L"",
path,
_countof(path),
ini_file);
if (path[0] != L'\0') {
dprintf("Spiking %S using config from %S\n", basename, path);
spike_hook_read_config(path);
}
}
static void spike_hook_read_config(const wchar_t *spike_file)
{ {
int match; int match;
int count; int count;
@ -142,14 +182,14 @@ void spike_hook_init(const char *path)
char *ret; char *ret;
FILE *f; FILE *f;
f = fopen(path, "r"); f = _wfopen(spike_file, L"r");
if (f == NULL) { if (f == NULL) {
dprintf("Error opening spike file %S\n", spike_file);
return; return;
} }
dprintf("Found spike config, inserting spikes\n");
for (;;) { for (;;) {
ret = fgets(line, sizeof(line), f); ret = fgets(line, sizeof(line), f);

View File

@ -1,3 +1,5 @@
#pragma once #pragma once
void spike_hook_init(const char *path); #include <stddef.h>
void spike_hook_init(const wchar_t *ini_file);

View File

@ -49,7 +49,7 @@ static DWORD CALLBACK idz_pre_startup(void)
/* Initialize debug helpers */ /* Initialize debug helpers */
spike_hook_init("idzspike.txt"); spike_hook_init(L".\\segatools.ini");
dprintf("--- End idz_pre_startup ---\n"); dprintf("--- End idz_pre_startup ---\n");

View File

@ -26,13 +26,12 @@ static DWORD CALLBACK app_pre_startup(void)
clock_config_load(&clock_cfg, L".\\segatools.ini"); clock_config_load(&clock_cfg, L".\\segatools.ini");
ds_config_load(&ds_cfg, L".\\segatools.ini"); ds_config_load(&ds_cfg, L".\\segatools.ini");
nusec_config_load(&nusec_cfg, L".\\segatools.ini"); nusec_config_load(&nusec_cfg, L".\\segatools.ini");
spike_hook_init(L".\\segatools.ini");
clock_hook_init(&clock_cfg); clock_hook_init(&clock_cfg);
nusec_hook_init(&nusec_cfg, "SSSS", "AAV0"); nusec_hook_init(&nusec_cfg, "SSSS", "AAV0");
ds_hook_init(&ds_cfg); ds_hook_init(&ds_cfg);
spike_hook_init("minispike.txt");
dprintf("--- End %s ---\n", __func__); dprintf("--- End %s ---\n", __func__);
return app_startup(); return app_startup();

View File

@ -41,7 +41,7 @@ static DWORD CALLBACK mu3_pre_startup(void)
/* Initialize debug helpers */ /* Initialize debug helpers */
spike_hook_init("mu3spike.txt"); spike_hook_init(L".\\segatools.ini");
dprintf("--- End mu3_pre_startup ---\n"); dprintf("--- End mu3_pre_startup ---\n");