mercury: fix coin counter (thanks Raki!)

This commit is contained in:
Hay1tsme 2022-11-18 16:37:48 -05:00 committed by Hay1tsme
parent 929ea862ca
commit 5f51699c78
3 changed files with 108 additions and 1 deletions

View File

@ -89,6 +89,16 @@ static LSTATUS WINAPI hook_RegSetValueExW(
const void *bytes, const void *bytes,
uint32_t nbytes); uint32_t nbytes);
static LSTATUS WINAPI hook_RegGetValueW(
HKEY hkey,
LPCWSTR lpSubKey,
LPCWSTR lpValue,
uint32_t flags,
uint32_t *type,
void *pData,
uint32_t *numData
);
/* Link pointers */ /* Link pointers */
static LSTATUS (WINAPI *next_RegOpenKeyExW)( static LSTATUS (WINAPI *next_RegOpenKeyExW)(
@ -135,6 +145,16 @@ static LSTATUS (WINAPI *next_RegSetValueExW)(
const void *bytes, const void *bytes,
uint32_t nbytes); uint32_t nbytes);
static LSTATUS (WINAPI *next_RegGetValueW)(
HKEY hkey,
LPCWSTR lpSubKey,
LPCWSTR lpValue,
uint32_t flags,
uint32_t *type,
void *pData,
uint32_t *numData
);
static const struct hook_symbol reg_hook_syms[] = { static const struct hook_symbol reg_hook_syms[] = {
{ {
.name = "RegOpenKeyExW", .name = "RegOpenKeyExW",
@ -160,6 +180,10 @@ static const struct hook_symbol reg_hook_syms[] = {
.name = "RegSetValueExW", .name = "RegSetValueExW",
.patch = hook_RegSetValueExW, .patch = hook_RegSetValueExW,
.link = (void **) &next_RegSetValueExW, .link = (void **) &next_RegSetValueExW,
}, {
.name = "RegGetValueW",
.patch = hook_RegGetValueW,
.link = (void **) &next_RegGetValueW,
} }
}; };
@ -184,6 +208,12 @@ HRESULT reg_hook_push_key(
reg_hook_init(); reg_hook_init();
/*dprintf("Pushing reg key %ls:\n", name);
for (int i = 0; i < nvals; i++) {
dprintf("\t%ls\n", vals[i].name);
} */
EnterCriticalSection(&reg_hook_lock); EnterCriticalSection(&reg_hook_lock);
new_mem = realloc( new_mem = realloc(
@ -222,6 +252,7 @@ static void reg_hook_init(void)
reg_hook_initted = true; reg_hook_initted = true;
InitializeCriticalSection(&reg_hook_lock); InitializeCriticalSection(&reg_hook_lock);
dprintf("Reg hook init\n");
hook_table_apply( hook_table_apply(
NULL, NULL,
@ -727,6 +758,69 @@ static LSTATUS WINAPI hook_RegSetValueExW(
return err; return err;
} }
static LSTATUS WINAPI hook_RegGetValueW(
HKEY handle,
LPCWSTR subkey,
LPCWSTR name,
uint32_t flags,
uint32_t *type,
void *pData,
uint32_t *numData)
{
struct reg_hook_key *key;
HKEY tmp = NULL;
const struct reg_hook_val *val;
LSTATUS err;
EnterCriticalSection(&reg_hook_lock);
//dprintf("Registry: RegGetValueW lookup for %ls\\%ls\n", subkey, name);
if (subkey == NULL) {
key = reg_hook_match_key_locked(handle);
} else {
err = hook_RegOpenKeyExW(handle, subkey, flags, 1, &tmp);
key = reg_hook_match_key_locked(tmp);
}
//dprintf("Registry: RegGetValueW key is %ls", key->name);
if (key == NULL) {
LeaveCriticalSection(&reg_hook_lock);
dprintf("Registry: RegGetValueW Failed to find %ls\\%ls, passing on\n", subkey, name);
return next_RegGetValueW(
handle,
subkey,
name,
flags,
type,
pData,
numData);
}
val = reg_hook_match_val_locked(key, name);
if (val != NULL) {
//dprintf("Registry: RegGetValueW found %ls\\%ls!\n", subkey, name);
if (val->read != NULL) {
val->read(pData, numData);
if (tmp != NULL) {
hook_RegCloseKey(tmp);
}
LeaveCriticalSection(&reg_hook_lock);
err = ERROR_SUCCESS;
return err;
}
}
LeaveCriticalSection(&reg_hook_lock);
err = ERROR_NOT_FOUND;
return err;
}
HRESULT reg_hook_read_bin( HRESULT reg_hook_read_bin(
void *bytes, void *bytes,
uint32_t *nbytes, uint32_t *nbytes,

View File

@ -3,6 +3,7 @@
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdbool.h>
#include "board/io4.h" #include "board/io4.h"
@ -10,6 +11,9 @@
#include "util/dprintf.h" #include "util/dprintf.h"
bool mercury_io_coin = false;
uint16_t mercury_io_coins = 0;
static HRESULT mercury_io4_poll(void *ctx, struct io4_state *state); static HRESULT mercury_io4_poll(void *ctx, struct io4_state *state);
static const struct io4_ops mercury_io4_ops = { static const struct io4_ops mercury_io4_ops = {
@ -64,8 +68,16 @@ static HRESULT mercury_io4_poll(void *ctx, struct io4_state *state)
} }
if (opbtn & MERCURY_IO_OPBTN_COIN) { if (opbtn & MERCURY_IO_OPBTN_COIN) {
state->chutes[0] += 1 << 8; // FIXME: Inserts 1 credit on press, then 15 on release... if (!mercury_io_coin) {
mercury_io_coin = true;
mercury_io_coins++;
}
} }
else {
mercury_io_coin = false;
}
state->chutes[0] = 128 + 256 * mercury_io_coins;
if (gamebtn & MERCURY_IO_GAMEBTN_VOL_UP) { if (gamebtn & MERCURY_IO_GAMEBTN_VOL_UP) {
state->buttons[0] |= 1 << 1; state->buttons[0] |= 1 << 1;

View File

@ -3,6 +3,7 @@
#include <windows.h> #include <windows.h>
#include <stdint.h> #include <stdint.h>
#include <stdbool.h>
#include "mercuryhook/elisabeth.h" #include "mercuryhook/elisabeth.h"