forked from Dniel97/segatools
hooklib/spike.c: Add a measure of configurability
This commit is contained in:
parent
5ed6eaa203
commit
dfcf3d8bd1
@ -25,13 +25,12 @@ static DWORD CALLBACK app_pre_startup(void)
|
||||
|
||||
aime_config_load(&app_aime_config, L".\\segatools.ini");
|
||||
dns_config_load(&app_dns_config, L".\\segatools.ini");
|
||||
spike_hook_init(L".\\segatools.ini");
|
||||
|
||||
serial_hook_init();
|
||||
sg_reader_hook_init(&app_aime_config, 12);
|
||||
dns_platform_hook_init(&app_dns_config);
|
||||
|
||||
spike_hook_init("cardspike.txt");
|
||||
|
||||
dprintf("--- End %s ---\n", __func__);
|
||||
|
||||
return app_startup();
|
||||
|
@ -63,7 +63,7 @@ static DWORD CALLBACK chuni_pre_startup(void)
|
||||
|
||||
/* Initialize debug helpers */
|
||||
|
||||
spike_hook_init("chunispike.txt");
|
||||
spike_hook_init(L".\\segatools.ini");
|
||||
gfx_set_windowed();
|
||||
|
||||
dprintf("--- End chuni_pre_startup ---\n");
|
||||
|
@ -51,7 +51,7 @@ static DWORD CALLBACK diva_pre_startup(void)
|
||||
|
||||
/* Initialize debug helpers */
|
||||
|
||||
spike_hook_init("divaspike.txt");
|
||||
spike_hook_init(L".\\segatools.ini");
|
||||
|
||||
dprintf("--- End diva_pre_startup ---\n");
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#include "hook/pe.h"
|
||||
|
||||
@ -11,6 +12,8 @@
|
||||
|
||||
#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
|
||||
the closest resemblance to. */
|
||||
|
||||
@ -133,7 +136,44 @@ static void spike_insert_log_levels(ptrdiff_t rva, size_t count)
|
||||
|
||||
/* 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 count;
|
||||
@ -142,14 +182,14 @@ void spike_hook_init(const char *path)
|
||||
char *ret;
|
||||
FILE *f;
|
||||
|
||||
f = fopen(path, "r");
|
||||
f = _wfopen(spike_file, L"r");
|
||||
|
||||
if (f == NULL) {
|
||||
dprintf("Error opening spike file %S\n", spike_file);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
dprintf("Found spike config, inserting spikes\n");
|
||||
|
||||
for (;;) {
|
||||
ret = fgets(line, sizeof(line), f);
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
void spike_hook_init(const char *path);
|
||||
#include <stddef.h>
|
||||
|
||||
void spike_hook_init(const wchar_t *ini_file);
|
||||
|
@ -49,7 +49,7 @@ static DWORD CALLBACK idz_pre_startup(void)
|
||||
|
||||
/* Initialize debug helpers */
|
||||
|
||||
spike_hook_init("idzspike.txt");
|
||||
spike_hook_init(L".\\segatools.ini");
|
||||
|
||||
dprintf("--- End idz_pre_startup ---\n");
|
||||
|
||||
|
@ -26,13 +26,12 @@ static DWORD CALLBACK app_pre_startup(void)
|
||||
clock_config_load(&clock_cfg, L".\\segatools.ini");
|
||||
ds_config_load(&ds_cfg, L".\\segatools.ini");
|
||||
nusec_config_load(&nusec_cfg, L".\\segatools.ini");
|
||||
spike_hook_init(L".\\segatools.ini");
|
||||
|
||||
clock_hook_init(&clock_cfg);
|
||||
nusec_hook_init(&nusec_cfg, "SSSS", "AAV0");
|
||||
ds_hook_init(&ds_cfg);
|
||||
|
||||
spike_hook_init("minispike.txt");
|
||||
|
||||
dprintf("--- End %s ---\n", __func__);
|
||||
|
||||
return app_startup();
|
||||
|
@ -41,7 +41,7 @@ static DWORD CALLBACK mu3_pre_startup(void)
|
||||
|
||||
/* Initialize debug helpers */
|
||||
|
||||
spike_hook_init("mu3spike.txt");
|
||||
spike_hook_init(L".\\segatools.ini");
|
||||
|
||||
dprintf("--- End mu3_pre_startup ---\n");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user