1
0
mirror of synced 2024-11-23 22:51:02 +01:00

Move all the boring generic stuff to a single file

This commit is contained in:
BroGamer 2022-06-20 06:40:07 +12:00
parent aa3254f8ba
commit f473eaad5a
8 changed files with 194 additions and 363 deletions

View File

@ -3,4 +3,5 @@ IndentWidth: 4
TabWidth: 4
UseTab: Always
IndentCaseLabels: False
BreakBeforeBraces: Attach
BreakBeforeBraces: Attach
ColumnLimit: 150

103
src/boilerplate.c Normal file
View File

@ -0,0 +1,103 @@
#include "helpers.h"
// xinput stuff
HOOK_DYNAMIC (u32, __stdcall, XinputGetState, u32 index, void *state) { return ERROR_DEVICE_NOT_CONNECTED; }
HOOK_DYNAMIC (u32, __stdcall, XinputSetState, u32 index, void *state) { return ERROR_DEVICE_NOT_CONNECTED; }
HOOK_DYNAMIC (u32, __stdcall, XinputGetCapabilites, u32 index, u32 flags, void *state) { return ERROR_DEVICE_NOT_CONNECTED; }
// bnusio stuff
HOOK_DYNAMIC (i64, __stdcall, ClearSram) { return false; }
HOOK_DYNAMIC (i64, __stdcall, Close) { return false; }
HOOK_DYNAMIC (i64, __fastcall, Communication, i32 a1) { return false; }
HOOK_DYNAMIC (i64, __fastcall, DecService, i32 a1, u16 a2) { return false; }
HOOK_DYNAMIC (void *, __fastcall, GetBuffer, u16 a1, i64 a2, i16 a3) { return false; }
HOOK_DYNAMIC (i64, __fastcall, GetCDOut, u8 a1) { return false; }
HOOK_DYNAMIC (void *, __fastcall, GetCoinError, i32 a1) { return false; }
HOOK_DYNAMIC (i64, __fastcall, GetCoinLock, u8 a1) { return false; }
HOOK_DYNAMIC (u64, __stdcall, GetEncoder) { return false; }
HOOK_DYNAMIC (void *, __stdcall, GetExpansionMode) { return false; }
HOOK_DYNAMIC (void *, __stdcall, GetFirmwareVersion) { return (void *)(u16)126; }
HOOK_DYNAMIC (u8, __stdcall, GetGout, u8 a1) { return false; }
HOOK_DYNAMIC (i64, __stdcall, GetHopOut, u8 a1) { return false; }
HOOK_DYNAMIC (char *, __stdcall, GetIoBoardName) { return false; }
HOOK_DYNAMIC (u16, __fastcall, GetRegisterU16, i16 a1) { return false; }
HOOK_DYNAMIC (u8, __fastcall, GetRegisterU8, u16 a1) { return false; }
HOOK_DYNAMIC (void *, __fastcall, GetService, i32 a1) { return false; }
HOOK_DYNAMIC (void *, __fastcall, GetServiceError, i32 a1) { return false; }
HOOK_DYNAMIC (u16, __fastcall, GetStatusU16, u16 a1) { return false; }
HOOK_DYNAMIC (u8, __fastcall, GetStatusU8, u16 a1) { return false; }
HOOK_DYNAMIC (u64, __stdcall, GetSwIn64) { return false; }
HOOK_DYNAMIC (void *, __stdcall, GetSystemError) { return false; }
HOOK_DYNAMIC (u8, __stdcall, IsConnected) { return false; }
HOOK_DYNAMIC (u8, __stdcall, IsWideUsio) { return false; }
HOOK_DYNAMIC (i64, __stdcall, Open) { return false; }
HOOK_DYNAMIC (i32, __stdcall, ResetIoBoard) { return false; }
HOOK_DYNAMIC (i64, __fastcall, SetBuffer, u16 a1, i32 a2, i16 a3) { return false; }
HOOK_DYNAMIC (i64, __fastcall, SetCDOut, u8 a1, u8 a2) { return false; }
HOOK_DYNAMIC (i64, __fastcall, SetCoinLock, u8 a1, u8 a2) { return false; }
HOOK_DYNAMIC (i64, __fastcall, SetExpansionMode, i16 a1) { return false; }
HOOK_DYNAMIC (i64, __fastcall, SetGout, u8 a1, u8 a2) { return false; }
HOOK_DYNAMIC (i64, __fastcall, SetHopOut, u8 a1, u8 a2) { return false; }
HOOK_DYNAMIC (i64, __fastcall, SetHopperLimit, u16 a1, i16 a2) { return false; }
HOOK_DYNAMIC (i64, __fastcall, SetHopperRequest, u16 a1, i16 a2) { return false; }
HOOK_DYNAMIC (void *, __fastcall, SetPLCounter, i16 a1) { return false; }
HOOK_DYNAMIC (i64, __fastcall, SetRegisterU16, u16 a1, u16 a2) { return false; }
HOOK_DYNAMIC (i64, __fastcall, SetRegisterU8, u16 a1, u8 a2) { return false; }
HOOK_DYNAMIC (i64, __fastcall, SetSystemError, i16 a1) { return false; }
HOOK_DYNAMIC (i64, __fastcall, SramRead, i32 a1, u8 a2, i32 a3, u16 a4) { return false; }
HOOK_DYNAMIC (i64, __fastcall, SramWrite, i32 a1, u8 a2, i32 a3, u16 a4) { return false; }
HOOK_DYNAMIC (i64, __stdcall, UsbFinderInitialize) { return false; }
HOOK_DYNAMIC (i64, __stdcall, UsbFinderRelease) { return false; }
HOOK_DYNAMIC (i64, __fastcall, UsbFinderGetSerialNumber, i32 a1, i64 a2) { return true; }
void
init_boilerplate () {
INSTALL_HOOK_DYNAMIC (XinputGetState, PROC_ADDRESS ("xinput9_1_0.dll", "XInputGetState"));
INSTALL_HOOK_DYNAMIC (XinputSetState, PROC_ADDRESS ("xinput9_1_0.dll", "XInputSetState"));
INSTALL_HOOK_DYNAMIC (XinputGetCapabilites, PROC_ADDRESS ("xinput9_1_0.dll", "XInputGetCapabilities"));
INSTALL_HOOK_DYNAMIC (ClearSram, PROC_ADDRESS ("bnusio.dll", "bnusio_ClearSram"));
INSTALL_HOOK_DYNAMIC (Close, PROC_ADDRESS ("bnusio.dll", "bnusio_Close"));
INSTALL_HOOK_DYNAMIC (Communication, PROC_ADDRESS ("bnusio.dll", "bnusio_Communication"));
INSTALL_HOOK_DYNAMIC (DecService, PROC_ADDRESS ("bnusio.dll", "bnusio_DecService"));
INSTALL_HOOK_DYNAMIC (GetBuffer, PROC_ADDRESS ("bnusio.dll", "bnusio_GetBuffer"));
INSTALL_HOOK_DYNAMIC (GetCDOut, PROC_ADDRESS ("bnusio.dll", "bnusio_GetCDOut"));
INSTALL_HOOK_DYNAMIC (GetCoinError, PROC_ADDRESS ("bnusio.dll", "bnusio_GetCoinError"));
INSTALL_HOOK_DYNAMIC (GetCoinLock, PROC_ADDRESS ("bnusio.dll", "bnusio_GetCoinLock"));
INSTALL_HOOK_DYNAMIC (GetEncoder, PROC_ADDRESS ("bnusio.dll", "bnusio_GetEncoder"));
INSTALL_HOOK_DYNAMIC (GetExpansionMode, PROC_ADDRESS ("bnusio.dll", "bnusio_GetExpansionMode"));
INSTALL_HOOK_DYNAMIC (GetFirmwareVersion, PROC_ADDRESS ("bnusio.dll", "bnusio_GetFirmwareVersion"));
INSTALL_HOOK_DYNAMIC (GetGout, PROC_ADDRESS ("bnusio.dll", "bnusio_GetGout"));
INSTALL_HOOK_DYNAMIC (GetHopOut, PROC_ADDRESS ("bnusio.dll", "bnusio_GetHopOut"));
INSTALL_HOOK_DYNAMIC (GetIoBoardName, PROC_ADDRESS ("bnusio.dll", "bnusio_GetIoBoardName"));
INSTALL_HOOK_DYNAMIC (GetRegisterU16, PROC_ADDRESS ("bnusio.dll", "bnusio_GetRegisterU16"));
INSTALL_HOOK_DYNAMIC (GetRegisterU8, PROC_ADDRESS ("bnusio.dll", "bnusio_GetRegisterU8"));
INSTALL_HOOK_DYNAMIC (GetService, PROC_ADDRESS ("bnusio.dll", "bnusio_GetService"));
INSTALL_HOOK_DYNAMIC (GetServiceError, PROC_ADDRESS ("bnusio.dll", "bnusio_GetServiceError"));
INSTALL_HOOK_DYNAMIC (GetStatusU16, PROC_ADDRESS ("bnusio.dll", "bnusio_GetStatusU16"));
INSTALL_HOOK_DYNAMIC (GetStatusU8, PROC_ADDRESS ("bnusio.dll", "bnusio_GetStatusU8"));
INSTALL_HOOK_DYNAMIC (GetSwIn64, PROC_ADDRESS ("bnusio.dll", "bnusio_GetSwIn64"));
INSTALL_HOOK_DYNAMIC (GetSystemError, PROC_ADDRESS ("bnusio.dll", "bnusio_GetSystemError"));
INSTALL_HOOK_DYNAMIC (IsConnected, PROC_ADDRESS ("bnusio.dll", "bnusio_IsConnected"));
INSTALL_HOOK_DYNAMIC (IsWideUsio, PROC_ADDRESS ("bnusio.dll", "bnusio_IsWideUsio"));
INSTALL_HOOK_DYNAMIC (Open, PROC_ADDRESS ("bnusio.dll", "bnusio_Open"));
INSTALL_HOOK_DYNAMIC (ResetIoBoard, PROC_ADDRESS ("bnusio.dll", "bnusio_ResetIoBoard"));
INSTALL_HOOK_DYNAMIC (SetBuffer, PROC_ADDRESS ("bnusio.dll", "bnusio_SetBuffer"));
INSTALL_HOOK_DYNAMIC (SetCDOut, PROC_ADDRESS ("bnusio.dll", "bnusio_SetCDOut"));
INSTALL_HOOK_DYNAMIC (SetCoinLock, PROC_ADDRESS ("bnusio.dll", "bnusio_SetCoinLock"));
INSTALL_HOOK_DYNAMIC (SetExpansionMode, PROC_ADDRESS ("bnusio.dll", "bnusio_SetExpansionMode"));
INSTALL_HOOK_DYNAMIC (SetGout, PROC_ADDRESS ("bnusio.dll", "bnusio_SetGout"));
INSTALL_HOOK_DYNAMIC (SetHopOut, PROC_ADDRESS ("bnusio.dll", "bnusio_SetHopOut"));
INSTALL_HOOK_DYNAMIC (SetHopperLimit, PROC_ADDRESS ("bnusio.dll", "bnusio_SetHopperLimit"));
INSTALL_HOOK_DYNAMIC (SetHopperRequest, PROC_ADDRESS ("bnusio.dll", "bnusio_SetHopperRequest"));
INSTALL_HOOK_DYNAMIC (SetPLCounter, PROC_ADDRESS ("bnusio.dll", "bnusio_SetPLCounter"));
INSTALL_HOOK_DYNAMIC (SetRegisterU16, PROC_ADDRESS ("bnusio.dll", "bnusio_SetRegisterU16"));
INSTALL_HOOK_DYNAMIC (SetRegisterU8, PROC_ADDRESS ("bnusio.dll", "bnusio_SetRegisterU8"));
INSTALL_HOOK_DYNAMIC (SetSystemError, PROC_ADDRESS ("bnusio.dll", "bnusio_SetSystemError"));
INSTALL_HOOK_DYNAMIC (SramRead, PROC_ADDRESS ("bnusio.dll", "bnusio_SramRead"));
INSTALL_HOOK_DYNAMIC (SramWrite, PROC_ADDRESS ("bnusio.dll", "bnusio_SramWrite"));
INSTALL_HOOK_DYNAMIC (UsbFinderInitialize, PROC_ADDRESS ("nbamUsbFinder.dll", "nbamUsbFinderInitialize"));
INSTALL_HOOK_DYNAMIC (UsbFinderRelease, PROC_ADDRESS ("nbamUsbFinder.dll", "nbamUsbFinderRelease"));
INSTALL_HOOK_DYNAMIC (UsbFinderGetSerialNumber, PROC_ADDRESS ("nbamUsbFinderGetSerialNumber.dll", "nbamUsbFinderRelease"));
}

1
src/boilerplate.h Normal file
View File

@ -0,0 +1 @@
void init_boilerplate ();

View File

@ -1,6 +1,6 @@
#include "boilerplate.h"
#include "helpers.h"
#include "poll.h"
#include <math.h>
HWND windowHandle = 0;
@ -15,30 +15,13 @@ enumWindows (HWND handle, LPARAM param) {
return 1;
}
// show cursor
HOOK_DYNAMIC (i32, __stdcall, ShowMouse, i32 show) {
return originalShowMouse (true);
}
// xinput stuff
HOOK_DYNAMIC (u32, __stdcall, XinputGetState, u32 index, void *state) {
return ERROR_DEVICE_NOT_CONNECTED;
}
HOOK_DYNAMIC (u32, __stdcall, XinputSetState, u32 index, void *state) {
return ERROR_DEVICE_NOT_CONNECTED;
}
HOOK_DYNAMIC (u32, __stdcall, XinputGetCapabilites, u32 index, u32 flags,
void *state) {
return ERROR_DEVICE_NOT_CONNECTED;
}
// force show cursor
HOOK_DYNAMIC (i32, __stdcall, ShowMouse, i32 show) { return originalShowMouse (true); }
#define DRUM_HIT 20000
#define IF_HIT(bind) return IsButtonTapped (bind) ? DRUM_HIT : 0
struct Keybindings COIN_ADD = { .keycodes = { VK_RETURN },
.buttons = { SDL_CONTROLLER_BUTTON_START } };
struct Keybindings COIN_ADD = { .keycodes = { VK_RETURN }, .buttons = { SDL_CONTROLLER_BUTTON_START } };
struct Keybindings TEST = { .keycodes = { VK_F1 } };
struct Keybindings SERVICE = { .keycodes = { VK_F2 } };
struct Keybindings DEBUG_UP = { .keycodes = { VK_UP } };
@ -57,20 +40,11 @@ int coin_count = 0;
bool testEnabled = false;
bool inited = false;
// bnusio stuff
HOOK_DYNAMIC (i64, __stdcall, ClearSram) { return false; }
HOOK_DYNAMIC (i64, __stdcall, Close) { return false; }
HOOK_DYNAMIC (i64, __fastcall, Communication, i32 a1) { return false; }
HOOK_DYNAMIC (i64, __fastcall, DecCoin, i32 a1, u16 a2) {
coin_count -= a2;
return false;
}
HOOK_DYNAMIC (i64, __fastcall, DecService, i32 a1, u16 a2) { return false; }
HOOK_DYNAMIC (u16, __fastcall, GetAnalogIn, u8 which) {
switch (which) {
case 0: // Player 1 Left Blue
@ -94,12 +68,6 @@ HOOK_DYNAMIC (u16, __fastcall, GetAnalogIn, u8 which) {
}
}
HOOK_DYNAMIC (void *, __fastcall, GetBuffer, u16 a1, i64 a2, i16 a3) {
return false;
}
HOOK_DYNAMIC (i64, __fastcall, GetCDOut, u8 a1) { return false; }
HOOK_DYNAMIC (u16, __fastcall, GetCoin, i32 a1) {
if (a1 == 1) {
if (!inited) {
@ -141,36 +109,6 @@ HOOK_DYNAMIC (u16, __fastcall, GetCoin, i32 a1) {
return coin_count;
}
HOOK_DYNAMIC (void *, __fastcall, GetCoinError, i32 a1) { return false; }
HOOK_DYNAMIC (i64, __fastcall, GetCoinLock, u8 a1) { return false; }
HOOK_DYNAMIC (u64, __stdcall, GetEncoder) { return false; }
HOOK_DYNAMIC (void *, __stdcall, GetExpansionMode) { return false; }
HOOK_DYNAMIC (void *, __stdcall, GetFirmwareVersion) {
return (void *)(u16)126;
}
HOOK_DYNAMIC (u8, __stdcall, GetGout, u8 a1) { return false; }
HOOK_DYNAMIC (i64, __stdcall, GetHopOut, u8 a1) { return false; }
HOOK_DYNAMIC (char *, __stdcall, GetIoBoardName) { return false; }
HOOK_DYNAMIC (u16, __fastcall, GetRegisterU16, i16 a1) { return false; }
HOOK_DYNAMIC (u8, __fastcall, GetRegisterU8, u16 a1) { return false; }
HOOK_DYNAMIC (void *, __fastcall, GetService, i32 a1) { return false; }
HOOK_DYNAMIC (void *, __fastcall, GetServiceError, i32 a1) { return false; }
HOOK_DYNAMIC (u16, __fastcall, GetStatusU16, u16 a1) { return false; }
HOOK_DYNAMIC (u8, __fastcall, GetStatusU8, u16 a1) { return false; }
HOOK_DYNAMIC (u32, __stdcall, GetSwIn) {
u32 mask = 0;
mask |= (u32)testEnabled << 7;
@ -181,71 +119,11 @@ HOOK_DYNAMIC (u32, __stdcall, GetSwIn) {
return mask;
}
HOOK_DYNAMIC (u64, __stdcall, GetSwIn64) { return false; }
HOOK_DYNAMIC (void *, __stdcall, GetSystemError) { return false; }
HOOK_DYNAMIC (u8, __stdcall, IsConnected) { return false; }
HOOK_DYNAMIC (u8, __stdcall, IsWideUsio) { return false; }
HOOK_DYNAMIC (i64, __stdcall, Open) { return false; }
HOOK_DYNAMIC (i64, __stdcall, ResetCoin) {
coin_count = 0;
return false;
}
HOOK_DYNAMIC (i32, __stdcall, ResetIoBoard) { return false; }
HOOK_DYNAMIC (i64, __fastcall, SetBuffer, u16 a1, i32 a2, i16 a3) {
return false;
}
HOOK_DYNAMIC (i64, __fastcall, SetCDOut, u8 a1, u8 a2) { return false; }
HOOK_DYNAMIC (i64, __fastcall, SetCoinLock, u8 a1, u8 a2) { return false; }
HOOK_DYNAMIC (i64, __fastcall, SetExpansionMode, i16 a1) { return false; }
HOOK_DYNAMIC (i64, __fastcall, SetGout, u8 a1, u8 a2) { return false; }
HOOK_DYNAMIC (i64, __fastcall, SetHopOut, u8 a1, u8 a2) { return false; }
HOOK_DYNAMIC (i64, __fastcall, SetHopperLimit, u16 a1, i16 a2) {
return false;
}
HOOK_DYNAMIC (i64, __fastcall, SetHopperRequest, u16 a1, i16 a2) {
return false;
}
HOOK_DYNAMIC (void *, __fastcall, SetPLCounter, i16 a1) { return false; }
HOOK_DYNAMIC (i64, __fastcall, SetRegisterU16, u16 a1, u16 a2) {
return false;
}
HOOK_DYNAMIC (i64, __fastcall, SetRegisterU8, u16 a1, u8 a2) { return false; }
HOOK_DYNAMIC (i64, __fastcall, SetSystemError, i16 a1) { return false; }
HOOK_DYNAMIC (i64, __fastcall, SramRead, i32 a1, u8 a2, i32 a3, u16 a4) {
return false;
}
HOOK_DYNAMIC (i64, __fastcall, SramWrite, i32 a1, u8 a2, i32 a3, u16 a4) {
return false;
}
HOOK_DYNAMIC (i64, __stdcall, UsbFinderInitialize) { return false; }
HOOK_DYNAMIC (i64, __stdcall, UsbFinderRelease) { return false; }
HOOK_DYNAMIC (i64, __fastcall, UsbFinderGetSerialNumber, i32 a1, i64 a2) {
return true;
}
i32 __stdcall DllMain (HMODULE mod, DWORD cause, void *ctx) {
if (cause == DLL_PROCESS_DETACH)
DisposePoll ();
@ -253,128 +131,19 @@ i32 __stdcall DllMain (HMODULE mod, DWORD cause, void *ctx) {
return 1;
// Blatantly stolen patches from mon.im
WRITE_MEMORY ((void *)0x140000C00 + 0x22DC0, u8,
0xC3); // Actually get shit working
WRITE_MEMORY ((void *)0x140000C00 + 0x31428D, u8, 0xB0,
0x01); // Unlock songs
WRITE_MEMORY ((void *)0x140000C00 + 0x692217, u8, 0xEB); // Shared audio
WRITE_MEMORY ((void *)0x140000C00 + 0x516739, u8, 0xBA, 0x00, 0x00, 0x00,
0x00, 0x90); // Disable VSync
WRITE_MEMORY (0x1400239C0, u8, 0xC3); // Stop error
WRITE_MEMORY (0x140314E8D, u8, 0xB0, 0x01); // Unlock songs
WRITE_MEMORY (0x140692E17, u8, 0xEB); // Shared audio
WRITE_MEMORY (0x140517339, u8, 0xBA, 0x00, 0x00, 0x00, 0x00,
0x90); // Disable VSync
INSTALL_HOOK_DYNAMIC (ShowMouse,
PROC_ADDRESS ("user32.dll", "ShowCursor"));
INSTALL_HOOK_DYNAMIC (XinputGetState,
PROC_ADDRESS ("xinput9_1_0.dll", "XInputGetState"));
INSTALL_HOOK_DYNAMIC (XinputSetState,
PROC_ADDRESS ("xinput9_1_0.dll", "XInputSetState"));
INSTALL_HOOK_DYNAMIC (
XinputGetCapabilites,
PROC_ADDRESS ("xinput9_1_0.dll", "XInputGetCapabilities"));
INSTALL_HOOK_DYNAMIC (ClearSram,
PROC_ADDRESS ("bnusio.dll", "bnusio_ClearSram"));
INSTALL_HOOK_DYNAMIC (Close, PROC_ADDRESS ("bnusio.dll", "bnusio_Close"));
INSTALL_HOOK_DYNAMIC (Communication,
PROC_ADDRESS ("bnusio.dll", "bnusio_Communication"));
INSTALL_HOOK_DYNAMIC (DecCoin,
PROC_ADDRESS ("bnusio.dll", "bnusio_DecCoin"));
INSTALL_HOOK_DYNAMIC (DecService,
PROC_ADDRESS ("bnusio.dll", "bnusio_DecService"));
INSTALL_HOOK_DYNAMIC (GetAnalogIn,
PROC_ADDRESS ("bnusio.dll", "bnusio_GetAnalogIn"));
INSTALL_HOOK_DYNAMIC (GetBuffer,
PROC_ADDRESS ("bnusio.dll", "bnusio_GetBuffer"));
INSTALL_HOOK_DYNAMIC (GetCDOut,
PROC_ADDRESS ("bnusio.dll", "bnusio_GetCDOut"));
INSTALL_HOOK_DYNAMIC (GetCoin,
PROC_ADDRESS ("bnusio.dll", "bnusio_GetCoin"));
INSTALL_HOOK_DYNAMIC (GetCoinError,
PROC_ADDRESS ("bnusio.dll", "bnusio_GetCoinError"));
INSTALL_HOOK_DYNAMIC (GetCoinLock,
PROC_ADDRESS ("bnusio.dll", "bnusio_GetCoinLock"));
INSTALL_HOOK_DYNAMIC (GetEncoder,
PROC_ADDRESS ("bnusio.dll", "bnusio_GetEncoder"));
INSTALL_HOOK_DYNAMIC (
GetExpansionMode,
PROC_ADDRESS ("bnusio.dll", "bnusio_GetExpansionMode"));
INSTALL_HOOK_DYNAMIC (
GetFirmwareVersion,
PROC_ADDRESS ("bnusio.dll", "bnusio_GetFirmwareVersion"));
INSTALL_HOOK_DYNAMIC (GetGout,
PROC_ADDRESS ("bnusio.dll", "bnusio_GetGout"));
INSTALL_HOOK_DYNAMIC (GetHopOut,
PROC_ADDRESS ("bnusio.dll", "bnusio_GetHopOut"));
INSTALL_HOOK_DYNAMIC (
GetIoBoardName, PROC_ADDRESS ("bnusio.dll", "bnusio_GetIoBoardName"));
INSTALL_HOOK_DYNAMIC (
GetRegisterU16, PROC_ADDRESS ("bnusio.dll", "bnusio_GetRegisterU16"));
INSTALL_HOOK_DYNAMIC (GetRegisterU8,
PROC_ADDRESS ("bnusio.dll", "bnusio_GetRegisterU8"));
INSTALL_HOOK_DYNAMIC (GetService,
PROC_ADDRESS ("bnusio.dll", "bnusio_GetService"));
INSTALL_HOOK_DYNAMIC (
GetServiceError,
PROC_ADDRESS ("bnusio.dll", "bnusio_GetServiceError"));
INSTALL_HOOK_DYNAMIC (GetStatusU16,
PROC_ADDRESS ("bnusio.dll", "bnusio_GetStatusU16"));
INSTALL_HOOK_DYNAMIC (GetStatusU8,
PROC_ADDRESS ("bnusio.dll", "bnusio_GetStatusU8"));
INSTALL_HOOK_DYNAMIC (GetSwIn,
PROC_ADDRESS ("bnusio.dll", "bnusio_GetSwIn"));
INSTALL_HOOK_DYNAMIC (GetSwIn64,
PROC_ADDRESS ("bnusio.dll", "bnusio_GetSwIn64"));
INSTALL_HOOK_DYNAMIC (
GetSystemError, PROC_ADDRESS ("bnusio.dll", "bnusio_GetSystemError"));
INSTALL_HOOK_DYNAMIC (IsConnected,
PROC_ADDRESS ("bnusio.dll", "bnusio_IsConnected"));
INSTALL_HOOK_DYNAMIC (IsWideUsio,
PROC_ADDRESS ("bnusio.dll", "bnusio_IsWideUsio"));
INSTALL_HOOK_DYNAMIC (Open, PROC_ADDRESS ("bnusio.dll", "bnusio_Open"));
INSTALL_HOOK_DYNAMIC (ResetCoin,
PROC_ADDRESS ("bnusio.dll", "bnusio_ResetCoin"));
INSTALL_HOOK_DYNAMIC (ResetIoBoard,
PROC_ADDRESS ("bnusio.dll", "bnusio_ResetIoBoard"));
INSTALL_HOOK_DYNAMIC (SetBuffer,
PROC_ADDRESS ("bnusio.dll", "bnusio_SetBuffer"));
INSTALL_HOOK_DYNAMIC (SetCDOut,
PROC_ADDRESS ("bnusio.dll", "bnusio_SetCDOut"));
INSTALL_HOOK_DYNAMIC (SetCoinLock,
PROC_ADDRESS ("bnusio.dll", "bnusio_SetCoinLock"));
INSTALL_HOOK_DYNAMIC (
SetExpansionMode,
PROC_ADDRESS ("bnusio.dll", "bnusio_SetExpansionMode"));
INSTALL_HOOK_DYNAMIC (SetGout,
PROC_ADDRESS ("bnusio.dll", "bnusio_SetGout"));
INSTALL_HOOK_DYNAMIC (SetHopOut,
PROC_ADDRESS ("bnusio.dll", "bnusio_SetHopOut"));
INSTALL_HOOK_DYNAMIC (
SetHopperLimit, PROC_ADDRESS ("bnusio.dll", "bnusio_SetHopperLimit"));
INSTALL_HOOK_DYNAMIC (
SetHopperRequest,
PROC_ADDRESS ("bnusio.dll", "bnusio_SetHopperRequest"));
INSTALL_HOOK_DYNAMIC (SetPLCounter,
PROC_ADDRESS ("bnusio.dll", "bnusio_SetPLCounter"));
INSTALL_HOOK_DYNAMIC (
SetRegisterU16, PROC_ADDRESS ("bnusio.dll", "bnusio_SetRegisterU16"));
INSTALL_HOOK_DYNAMIC (SetRegisterU8,
PROC_ADDRESS ("bnusio.dll", "bnusio_SetRegisterU8"));
INSTALL_HOOK_DYNAMIC (
SetSystemError, PROC_ADDRESS ("bnusio.dll", "bnusio_SetSystemError"));
INSTALL_HOOK_DYNAMIC (SramRead,
PROC_ADDRESS ("bnusio.dll", "bnusio_SramRead"));
INSTALL_HOOK_DYNAMIC (SramWrite,
PROC_ADDRESS ("bnusio.dll", "bnusio_SramWrite"));
INSTALL_HOOK_DYNAMIC (
UsbFinderInitialize,
PROC_ADDRESS ("nbamUsbFinder.dll", "nbamUsbFinderInitialize"));
INSTALL_HOOK_DYNAMIC (
UsbFinderRelease,
PROC_ADDRESS ("nbamUsbFinder.dll", "nbamUsbFinderRelease"));
INSTALL_HOOK_DYNAMIC (UsbFinderGetSerialNumber,
PROC_ADDRESS ("nbamUsbFinderGetSerialNumber.dll",
"nbamUsbFinderRelease"));
INSTALL_HOOK_DYNAMIC (ShowMouse, PROC_ADDRESS ("user32.dll", "ShowCursor"));
INSTALL_HOOK_DYNAMIC (DecCoin, PROC_ADDRESS ("bnusio.dll", "bnusio_DecCoin"));
INSTALL_HOOK_DYNAMIC (GetAnalogIn, PROC_ADDRESS ("bnusio.dll", "bnusio_GetAnalogIn"));
INSTALL_HOOK_DYNAMIC (GetCoin, PROC_ADDRESS ("bnusio.dll", "bnusio_GetCoin"));
INSTALL_HOOK_DYNAMIC (GetSwIn, PROC_ADDRESS ("bnusio.dll", "bnusio_GetSwIn"));
INSTALL_HOOK_DYNAMIC (ResetCoin, PROC_ADDRESS ("bnusio.dll", "bnusio_ResetCoin"));
init_boilerplate ();
return true;
}

View File

@ -82,8 +82,7 @@ printColour (int colour, const char *format, ...) {
vsprintf (buffer, format, args);
SetConsoleTextAttribute (consoleHandle, colour);
printf (buffer);
SetConsoleTextAttribute (consoleHandle, FOREGROUND_BLUE | FOREGROUND_GREEN
| FOREGROUND_RED);
SetConsoleTextAttribute (consoleHandle, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
va_end (args);
}

View File

@ -15,90 +15,78 @@ typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
#define FUNCTION_PTR(returnType, callingConvention, function, location, ...) \
returnType (callingConvention *function) (__VA_ARGS__) \
= (returnType (callingConvention *) (__VA_ARGS__)) (location)
#define FUNCTION_PTR(returnType, callingConvention, function, location, ...) \
returnType (callingConvention *function) (__VA_ARGS__) = (returnType (callingConvention *) (__VA_ARGS__)) (location)
#define PROC_ADDRESS(libraryName, procName) \
GetProcAddress (LoadLibrary (TEXT (libraryName)), procName)
#define PROC_ADDRESS(libraryName, procName) GetProcAddress (LoadLibrary (TEXT (libraryName)), procName)
#define HOOK(returnType, callingConvention, functionName, location, ...) \
typedef returnType callingConvention (*functionName) (__VA_ARGS__); \
functionName original##functionName = NULL; \
void *where##functionName = (void *)location; \
#define HOOK(returnType, callingConvention, functionName, location, ...) \
typedef returnType callingConvention (*functionName) (__VA_ARGS__); \
functionName original##functionName = NULL; \
void *where##functionName = (void *)location; \
returnType callingConvention implOf##functionName (__VA_ARGS__)
#define HOOK_DYNAMIC(returnType, callingConvention, functionName, ...) \
typedef returnType callingConvention (*functionName) (__VA_ARGS__); \
functionName original##functionName = NULL; \
void *where##functionName = NULL; \
#define HOOK_DYNAMIC(returnType, callingConvention, functionName, ...) \
typedef returnType callingConvention (*functionName) (__VA_ARGS__); \
functionName original##functionName = NULL; \
void *where##functionName = NULL; \
returnType callingConvention implOf##functionName (__VA_ARGS__)
#define INSTALL_HOOK(functionName) \
{ \
MH_Initialize (); \
MH_CreateHook ((void *)where##functionName, \
(void *)implOf##functionName, \
(void **)(&original##functionName)); \
MH_EnableHook ((void *)where##functionName); \
#define INSTALL_HOOK(functionName) \
{ \
MH_Initialize (); \
MH_CreateHook ((void *)where##functionName, (void *)implOf##functionName, (void **)(&original##functionName)); \
MH_EnableHook ((void *)where##functionName); \
}
#define INSTALL_HOOK_DYNAMIC(functionName, location) \
{ \
where##functionName = location; \
INSTALL_HOOK (functionName); \
#define INSTALL_HOOK_DYNAMIC(functionName, location) \
{ \
where##functionName = location; \
INSTALL_HOOK (functionName); \
}
#define READ_MEMORY(location, type) *(type *)location
#define WRITE_MEMORY(location, type, ...) \
{ \
const type data[] = { __VA_ARGS__ }; \
DWORD oldProtect; \
VirtualProtect ((void *)(location), sizeof (data), \
PAGE_EXECUTE_READWRITE, &oldProtect); \
memcpy ((void *)(location), data, sizeof (data)); \
VirtualProtect ((void *)(location), sizeof (data), oldProtect, \
&oldProtect); \
#define WRITE_MEMORY(location, type, ...) \
{ \
const type data[] = { __VA_ARGS__ }; \
DWORD oldProtect; \
VirtualProtect ((void *)(location), sizeof (data), PAGE_EXECUTE_READWRITE, &oldProtect); \
memcpy ((void *)(location), data, sizeof (data)); \
VirtualProtect ((void *)(location), sizeof (data), oldProtect, &oldProtect); \
}
#define WRITE_MEMORY_STRING(location, data, length) \
{ \
DWORD oldProtect; \
VirtualProtect ((void *)(location), length, PAGE_EXECUTE_READWRITE, \
&oldProtect); \
memcpy ((void *)(location), data, length); \
VirtualProtect ((void *)(location), length, oldProtect, &oldProtect); \
#define WRITE_MEMORY_STRING(location, data, length) \
{ \
DWORD oldProtect; \
VirtualProtect ((void *)(location), length, PAGE_EXECUTE_READWRITE, &oldProtect); \
memcpy ((void *)(location), data, length); \
VirtualProtect ((void *)(location), length, oldProtect, &oldProtect); \
}
#define WRITE_NOP(location, count) \
{ \
DWORD oldProtect; \
VirtualProtect ((void *)(location), (size_t)(count), \
PAGE_EXECUTE_READWRITE, &oldProtect); \
for (size_t i = 0; i < (size_t)(count); i++) \
*((uint8_t *)(location) + i) = 0x90; \
VirtualProtect ((void *)(location), (size_t)(count), oldProtect, \
&oldProtect); \
#define WRITE_NOP(location, count) \
{ \
DWORD oldProtect; \
VirtualProtect ((void *)(location), (size_t)(count), PAGE_EXECUTE_READWRITE, &oldProtect); \
for (size_t i = 0; i < (size_t)(count); i++) \
*((uint8_t *)(location) + i) = 0x90; \
VirtualProtect ((void *)(location), (size_t)(count), oldProtect, &oldProtect); \
}
#define WRITE_NULL(location, count) \
{ \
DWORD oldProtect; \
VirtualProtect ((void *)(location), (size_t)(count), \
PAGE_EXECUTE_READWRITE, &oldProtect); \
for (size_t i = 0; i < (size_t)(count); i++) \
*((uint8_t *)(location) + i) = 0x00; \
VirtualProtect ((void *)(location), (size_t)(count), oldProtect, \
&oldProtect); \
#define WRITE_NULL(location, count) \
{ \
DWORD oldProtect; \
VirtualProtect ((void *)(location), (size_t)(count), PAGE_EXECUTE_READWRITE, &oldProtect); \
for (size_t i = 0; i < (size_t)(count); i++) \
*((uint8_t *)(location) + i) = 0x00; \
VirtualProtect ((void *)(location), (size_t)(count), oldProtect, &oldProtect); \
}
#define COUNTOFARR(arr) sizeof (arr) / sizeof (arr[0])
#define WARNING_COLOUR (FOREGROUND_RED | FOREGROUND_GREEN)
#define ERROR_COLOUR FOREGROUND_RED
#define printWarning(format, ...) \
printColour (WARNING_COLOUR, format, __VA_ARGS__)
#define printWarning(format, ...) printColour (WARNING_COLOUR, format, __VA_ARGS__)
#define printError(format, ...) printColour (ERROR_COLOUR, format, __VA_ARGS__)
char *configPath (char *name);

View File

@ -6,26 +6,16 @@ struct {
const char *string;
uint8_t keycode;
} ConfigKeyboardButtons[] = {
{ "F1", 0x70 }, { "F2", 0x71 }, { "F3", 0x72 },
{ "F4", 0x73 }, { "F5", 0x74 }, { "F6", 0x75 },
{ "F7", 0x76 }, { "F8", 0x77 }, { "F9", 0x78 },
{ "F10", 0x79 }, { "F11", 0x7A }, { "F12", 0x7B },
{ "NUM1", '1' }, { "NUM2", '2' }, { "NUM3", '3' },
{ "NUM4", '4' }, { "NUM5", '5' }, { "NUM6", '6' },
{ "NUM7", '7' }, { "NUM8", '8' }, { "NUM9", '9' },
{ "NUM0", '0' }, { "Q", 'Q' }, { "W", 'W' },
{ "E", 'E' }, { "R", 'R' }, { "T", 'T' },
{ "Y", 'Y' }, { "U", 'U' }, { "I", 'I' },
{ "O", 'O' }, { "P", 'P' }, { "A", 'A' },
{ "S", 'S' }, { "D", 'D' }, { "F", 'F' },
{ "G", 'G' }, { "H", 'H' }, { "J", 'J' },
{ "K", 'K' }, { "L", 'L' }, { "Z", 'Z' },
{ "X", 'X' }, { "C", 'C' }, { "V", 'V' },
{ "B", 'B' }, { "N", 'N' }, { "M", 'M' },
{ "UPARROW", 0x26 }, { "LEFTARROW", 0x25 }, { "DOWNARROW", 0x28 },
{ "RIGHTARROW", 0x27 }, { "ENTER", 0x0D }, { "SPACE", 0x20 },
{ "CONTROL", 0x11 }, { "SHIFT", 0x10 }, { "TAB", 0x09 },
{ "ESCAPE", 0x1B },
{ "F1", 0x70 }, { "F2", 0x71 }, { "F3", 0x72 }, { "F4", 0x73 }, { "F5", 0x74 }, { "F6", 0x75 },
{ "F7", 0x76 }, { "F8", 0x77 }, { "F9", 0x78 }, { "F10", 0x79 }, { "F11", 0x7A }, { "F12", 0x7B },
{ "NUM1", '1' }, { "NUM2", '2' }, { "NUM3", '3' }, { "NUM4", '4' }, { "NUM5", '5' }, { "NUM6", '6' },
{ "NUM7", '7' }, { "NUM8", '8' }, { "NUM9", '9' }, { "NUM0", '0' }, { "Q", 'Q' }, { "W", 'W' },
{ "E", 'E' }, { "R", 'R' }, { "T", 'T' }, { "Y", 'Y' }, { "U", 'U' }, { "I", 'I' },
{ "O", 'O' }, { "P", 'P' }, { "A", 'A' }, { "S", 'S' }, { "D", 'D' }, { "F", 'F' },
{ "G", 'G' }, { "H", 'H' }, { "J", 'J' }, { "K", 'K' }, { "L", 'L' }, { "Z", 'Z' },
{ "X", 'X' }, { "C", 'C' }, { "V", 'V' }, { "B", 'B' }, { "N", 'N' }, { "M", 'M' },
{ "UPARROW", 0x26 }, { "LEFTARROW", 0x25 }, { "DOWNARROW", 0x28 }, { "RIGHTARROW", 0x27 }, { "ENTER", 0x0D }, { "SPACE", 0x20 },
{ "CONTROL", 0x11 }, { "SHIFT", 0x10 }, { "TAB", 0x09 }, { "ESCAPE", 0x1B },
};
struct {
@ -59,15 +49,9 @@ struct {
const char *string;
enum SDLAxis axis;
} ConfigControllerAXIS[] = {
{ "SDL_LSTICK_LEFT", SDL_AXIS_LEFT_LEFT },
{ "SDL_LSTICK_UP", SDL_AXIS_LEFT_UP },
{ "SDL_LSTICK_DOWN", SDL_AXIS_LEFT_DOWN },
{ "SDL_LSTICK_RIGHT", SDL_AXIS_LEFT_RIGHT },
{ "SDL_RSTICK_LEFT", SDL_AXIS_RIGHT_LEFT },
{ "SDL_RSTICK_UP", SDL_AXIS_RIGHT_UP },
{ "SDL_RSTICK_DOWN", SDL_AXIS_RIGHT_DOWN },
{ "SDL_RSTICK_RIGHT", SDL_AXIS_RIGHT_RIGHT },
{ "SDL_LTRIGGER", SDL_AXIS_LTRIGGER_DOWN },
{ "SDL_LSTICK_LEFT", SDL_AXIS_LEFT_LEFT }, { "SDL_LSTICK_UP", SDL_AXIS_LEFT_UP }, { "SDL_LSTICK_DOWN", SDL_AXIS_LEFT_DOWN },
{ "SDL_LSTICK_RIGHT", SDL_AXIS_LEFT_RIGHT }, { "SDL_RSTICK_LEFT", SDL_AXIS_RIGHT_LEFT }, { "SDL_RSTICK_UP", SDL_AXIS_RIGHT_UP },
{ "SDL_RSTICK_DOWN", SDL_AXIS_RIGHT_DOWN }, { "SDL_RSTICK_RIGHT", SDL_AXIS_RIGHT_RIGHT }, { "SDL_LTRIGGER", SDL_AXIS_LTRIGGER_DOWN },
{ "SDL_RTRIGGER", SDL_AXIS_RTRIGGER_DOWN },
};
@ -164,12 +148,8 @@ InitializePoll (void *DivaWindowHandle) {
SDL_SetHint (SDL_HINT_JOYSTICK_HIDAPI_PS5, "1");
SDL_SetHint (SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1");
if (SDL_Init (SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER
| SDL_INIT_EVENTS | SDL_INIT_VIDEO)
!= 0) {
if (SDL_Init (SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER
| SDL_INIT_EVENTS | SDL_INIT_VIDEO)
== 0) {
if (SDL_Init (SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS | SDL_INIT_VIDEO) != 0) {
if (SDL_Init (SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS | SDL_INIT_VIDEO) == 0) {
hasRumble = false;
} else {
printError (
@ -182,9 +162,7 @@ InitializePoll (void *DivaWindowHandle) {
}
}
if (SDL_GameControllerAddMappingsFromFile (
configPath ("gamecontrollerdb.txt"))
== -1)
if (SDL_GameControllerAddMappingsFromFile (configPath ("gamecontrollerdb.txt")) == -1)
printError ("%s (): Cannot read "
"plugins/gamecontrollerdb.txt\n",
__func__);
@ -197,8 +175,7 @@ InitializePoll (void *DivaWindowHandle) {
SDL_GameController *controller = SDL_GameControllerOpen (i);
if (!controller) {
printWarning ("Could not open gamecontroller %s: %s\n",
SDL_GameControllerNameForIndex (i), SDL_GetError ());
printWarning ("Could not open gamecontroller %s: %s\n", SDL_GameControllerNameForIndex (i), SDL_GetError ());
continue;
}
@ -210,8 +187,7 @@ InitializePoll (void *DivaWindowHandle) {
if (window != NULL)
SDL_SetWindowResizable (window, true);
else
printError ("SDL_CreateWindowFrom (DivaWindowHandle): %s\n",
SDL_GetError ());
printError ("SDL_CreateWindowFrom (DivaWindowHandle): %s\n", SDL_GetError ());
return hasRumble;
}
@ -239,17 +215,14 @@ UpdatePoll (void *DivaWindowHandle) {
if (!SDL_IsGameController (event.cdevice.which))
break;
SDL_GameController *controller
= SDL_GameControllerOpen (event.cdevice.which);
SDL_GameController *controller = SDL_GameControllerOpen (event.cdevice.which);
if (!controller) {
printError (
"%s (): Could not open "
"gamecontroller %s: %s\n",
__func__,
SDL_GameControllerNameForIndex (event.cdevice.which),
SDL_GetError ());
__func__, SDL_GameControllerNameForIndex (event.cdevice.which), SDL_GetError ());
continue;
}
@ -269,8 +242,7 @@ UpdatePoll (void *DivaWindowHandle) {
break;
case SDL_CONTROLLERBUTTONUP:
case SDL_CONTROLLERBUTTONDOWN:
currentControllerButtonsState[event.cbutton.button]
= event.cbutton.state;
currentControllerButtonsState[event.cbutton.button] = event.cbutton.state;
break;
case SDL_CONTROLLERAXISMOTION:
if (event.caxis.value > 8000) {

View File

@ -62,10 +62,8 @@ void UpdatePoll (void *DivaWindowHandle);
void DisposePoll ();
struct ConfigValue StringToConfigEnum (char *value);
void SetConfigValue (toml_table_t *table, char *key,
struct Keybindings *keybind);
struct InternalButtonState
GetInternalButtonState (struct Keybindings bindings);
void SetConfigValue (toml_table_t *table, char *key, struct Keybindings *keybind);
struct InternalButtonState GetInternalButtonState (struct Keybindings bindings);
void SetRumble (int left, int right);
bool KeyboardIsDown (uint8_t keycode);