1
0
mirror of https://gitea.tendokyu.moe/Hay1tsme/segatools.git synced 2024-11-24 17:30:11 +01:00

platform/pcbid.c: Use pcbid_config

This commit is contained in:
Tau 2019-08-20 18:44:57 -04:00
parent 8774b83f9c
commit 65ccaf55f3
2 changed files with 18 additions and 19 deletions

View File

@ -1,18 +1,19 @@
#include <windows.h>
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hook/table.h"
#include "platform/pcbid.h"
#include "util/dprintf.h"
static BOOL WINAPI pcbid_GetComputerNameA(char *dest, uint32_t *len);
static const char pcbid_file[] = "DEVICE/pcbid.txt";
static char pcbid_str[16];
static struct pcbid_config pcbid_cfg;
static const struct hook_symbol pcbid_syms[] = {
{
@ -21,42 +22,38 @@ static const struct hook_symbol pcbid_syms[] = {
}
};
void pcbid_hook_init(void)
void pcbid_hook_init(const struct pcbid_config *cfg)
{
FILE *f;
assert(cfg != NULL);
f = fopen(pcbid_file, "r");
if (f != NULL) {
/* De-hyphenate the serial number. Game code will re-insert it. */
fscanf(f, "%4s-", &pcbid_str[0]);
fscanf(f, "%11s", &pcbid_str[4]);
fclose(f);
} else {
dprintf("Failed to open %s\n", pcbid_file);
if (!cfg->enable) {
return;
}
memcpy(&pcbid_cfg, cfg, sizeof(*cfg));
hook_table_apply(NULL, "kernel32.dll", pcbid_syms, _countof(pcbid_syms));
}
static BOOL WINAPI pcbid_GetComputerNameA(char *dest, uint32_t *len)
{
size_t required;
if (dest == NULL || len == NULL) {
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
if (*len < sizeof(pcbid_str)) {
wcstombs_s(&required, NULL, 0, pcbid_cfg.serial_no, 0);
if (required > *len) {
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}
dprintf("Pcbid: Get PCB serial\n");
memcpy(dest, pcbid_str, sizeof(pcbid_str));
*len = sizeof(pcbid_str) - 1;
wcstombs_s(NULL, dest, *len, pcbid_cfg.serial_no, *len - 1);
return TRUE;
}

View File

@ -1,3 +1,5 @@
#pragma once
void pcbid_hook_init(void);
#include "platform/config.h"
void pcbid_hook_init(const struct pcbid_config *cfg);