Add card emulation
This commit is contained in:
parent
ac341fb0aa
commit
d25a3743f2
4
dist/keyconfig.toml
vendored
4
dist/keyconfig.toml
vendored
@ -7,7 +7,9 @@ DEBUG_DOWN = ["DOWNARROW"]
|
|||||||
DEBUG_ENTER = ["ENTER"]
|
DEBUG_ENTER = ["ENTER"]
|
||||||
|
|
||||||
COIN_ADD = ["ENTER", "SDL_START"]
|
COIN_ADD = ["ENTER", "SDL_START"]
|
||||||
QR_CARD_READ = ["P"]
|
CARD_INSERT_1 = ["P"]
|
||||||
|
CARD_INSERT_2 = []
|
||||||
|
QR_CARD_READ = ["O"]
|
||||||
QR_DATA_READ = ["Q"]
|
QR_DATA_READ = ["Q"]
|
||||||
|
|
||||||
P1_LEFT_BLUE = ["D", "SDL_LTRIGGER"]
|
P1_LEFT_BLUE = ["D", "SDL_LTRIGGER"]
|
||||||
|
@ -1,15 +1,26 @@
|
|||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "poll.h"
|
#include "poll.h"
|
||||||
#include "patches/patches.h"
|
#include "patches/patches.h"
|
||||||
#include <xxhash.h>
|
|
||||||
#include "keyconfig.h"
|
#include "keyconfig.h"
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
|
|
||||||
extern std::vector<HMODULE> plugins;
|
extern std::vector<HMODULE> plugins;
|
||||||
extern char accessCode[21];
|
extern char accessCode1[21];
|
||||||
extern char chipId[33];
|
extern char chipId1[33];
|
||||||
|
extern char accessCode2[21];
|
||||||
|
extern char chipId2[33];
|
||||||
extern GameVersion version;
|
extern GameVersion version;
|
||||||
|
|
||||||
|
typedef i32 (*callbackAttach) (i32, i32, i32 *);
|
||||||
|
typedef void (*callbackTouch) (i32, i32, u8[168], u64);
|
||||||
|
typedef void event ();
|
||||||
|
typedef void waitTouchEvent (callbackTouch, u64);
|
||||||
|
bool waitingForTouch = false;
|
||||||
|
callbackTouch touchCallback;
|
||||||
|
u64 touchData;
|
||||||
|
callbackAttach attachCallback;
|
||||||
|
i32 *attachData;
|
||||||
|
|
||||||
namespace bnusio {
|
namespace bnusio {
|
||||||
#define RETURN_FALSE(returnType, functionName, ...) \
|
#define RETURN_FALSE(returnType, functionName, ...) \
|
||||||
returnType functionName (__VA_ARGS__) { return 0; }
|
returnType functionName (__VA_ARGS__) { return 0; }
|
||||||
@ -55,7 +66,6 @@ RETURN_FALSE (i64, bnusio_SramRead, i32 a1, u8 a2, i32 a3, u16 a4);
|
|||||||
RETURN_FALSE (i64, bnusio_SramWrite, i32 a1, u8 a2, i32 a3, u16 a4);
|
RETURN_FALSE (i64, bnusio_SramWrite, i32 a1, u8 a2, i32 a3, u16 a4);
|
||||||
RETURN_FALSE (i64, bnusio_ResetCoin);
|
RETURN_FALSE (i64, bnusio_ResetCoin);
|
||||||
RETURN_FALSE (i64, bnusio_DecCoin, i32 a1, u16 a2);
|
RETURN_FALSE (i64, bnusio_DecCoin, i32 a1, u16 a2);
|
||||||
RETURN_FALSE (i64, bnusio_Close);
|
|
||||||
size_t
|
size_t
|
||||||
bnusio_GetFirmwareVersion () {
|
bnusio_GetFirmwareVersion () {
|
||||||
return 126;
|
return 126;
|
||||||
@ -68,6 +78,8 @@ extern Keybindings DEBUG_UP;
|
|||||||
extern Keybindings DEBUG_DOWN;
|
extern Keybindings DEBUG_DOWN;
|
||||||
extern Keybindings DEBUG_ENTER;
|
extern Keybindings DEBUG_ENTER;
|
||||||
extern Keybindings COIN_ADD;
|
extern Keybindings COIN_ADD;
|
||||||
|
extern Keybindings CARD_INSERT_1;
|
||||||
|
extern Keybindings CARD_INSERT_2;
|
||||||
extern Keybindings P1_LEFT_BLUE;
|
extern Keybindings P1_LEFT_BLUE;
|
||||||
extern Keybindings P1_LEFT_RED;
|
extern Keybindings P1_LEFT_RED;
|
||||||
extern Keybindings P1_RIGHT_RED;
|
extern Keybindings P1_RIGHT_RED;
|
||||||
@ -158,6 +170,53 @@ u16 __fastcall bnusio_GetCoin (i32 a1) {
|
|||||||
if (IsButtonTapped (COIN_ADD) && !testEnabled) coin_count++;
|
if (IsButtonTapped (COIN_ADD) && !testEnabled) coin_count++;
|
||||||
if (IsButtonTapped (TEST)) testEnabled = !testEnabled;
|
if (IsButtonTapped (TEST)) testEnabled = !testEnabled;
|
||||||
if (IsButtonTapped (EXIT)) ExitProcess (0);
|
if (IsButtonTapped (EXIT)) ExitProcess (0);
|
||||||
|
if (waitingForTouch) {
|
||||||
|
static u8 cardData[168]
|
||||||
|
= { 0x01, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x92, 0x2E, 0x58, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x5C, 0x97, 0x44, 0xF0, 0x88, 0x04, 0x00, 0x43, 0x26, 0x2C, 0x33, 0x00, 0x04,
|
||||||
|
0x06, 0x10, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x30,
|
||||||
|
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4E, 0x42, 0x47, 0x49, 0x43, 0x36,
|
||||||
|
0x00, 0x00, 0xFA, 0xE9, 0x69, 0x00, 0xF6, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
bool hasInserted = false;
|
||||||
|
if (IsButtonTapped (CARD_INSERT_1)) {
|
||||||
|
for (auto plugin : plugins) {
|
||||||
|
FARPROC insertEvent = GetProcAddress (plugin, "BeforeCard1Insert");
|
||||||
|
if (insertEvent) ((event *)insertEvent) ();
|
||||||
|
}
|
||||||
|
for (auto plugin : plugins) {
|
||||||
|
FARPROC insertEvent = GetProcAddress (plugin, "Card1Insert");
|
||||||
|
if (insertEvent) {
|
||||||
|
((event *)insertEvent) ();
|
||||||
|
hasInserted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!hasInserted) {
|
||||||
|
memcpy (cardData + 0x2C, chipId1, 33);
|
||||||
|
memcpy (cardData + 0x50, accessCode1, 21);
|
||||||
|
touchCallback (0, 0, cardData, touchData);
|
||||||
|
}
|
||||||
|
} else if (IsButtonTapped (CARD_INSERT_2)) {
|
||||||
|
for (auto plugin : plugins) {
|
||||||
|
FARPROC insertEvent = GetProcAddress (plugin, "BeforeCard2Insert");
|
||||||
|
if (insertEvent) ((event *)insertEvent) ();
|
||||||
|
}
|
||||||
|
for (auto plugin : plugins) {
|
||||||
|
FARPROC insertEvent = GetProcAddress (plugin, "Card2Insert");
|
||||||
|
if (insertEvent) {
|
||||||
|
((event *)insertEvent) ();
|
||||||
|
hasInserted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!hasInserted) {
|
||||||
|
memcpy (cardData + 0x2C, chipId2, 33);
|
||||||
|
memcpy (cardData + 0x50, accessCode2, 21);
|
||||||
|
touchCallback (0, 0, cardData, touchData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (auto plugin : plugins) {
|
for (auto plugin : plugins) {
|
||||||
auto updateEvent = GetProcAddress (plugin, "Update");
|
auto updateEvent = GetProcAddress (plugin, "Update");
|
||||||
@ -179,6 +238,15 @@ bnusio_GetSwIn () {
|
|||||||
sw |= (u32)IsButtonDown (SERVICE) << 14;
|
sw |= (u32)IsButtonDown (SERVICE) << 14;
|
||||||
return sw;
|
return sw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i64
|
||||||
|
bnusio_Close () {
|
||||||
|
for (auto plugin : plugins) {
|
||||||
|
FARPROC exitEvent = GetProcAddress (plugin, "Exit");
|
||||||
|
if (exitEvent) ((event *)exitEvent) ();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HOOK (u64, bngrw_DevReset, PROC_ADDRESS ("bngrw.dll", "BngRwDevReset")) { return 1; }
|
HOOK (u64, bngrw_DevReset, PROC_ADDRESS ("bngrw.dll", "BngRwDevReset")) { return 1; }
|
||||||
@ -200,8 +268,22 @@ HOOK (i32, bngrw_ReqSendUrl, PROC_ADDRESS ("bngrw.dll", "BngRwReqSendUrlTo")) {
|
|||||||
HOOK (u64, bngrw_ReqSetLedPower, PROC_ADDRESS ("bngrw.dll", "BngRwReqSetLedPower")) { return 0; }
|
HOOK (u64, bngrw_ReqSetLedPower, PROC_ADDRESS ("bngrw.dll", "BngRwReqSetLedPower")) { return 0; }
|
||||||
HOOK (i32, bngrw_reqCancel, PROC_ADDRESS ("bngrw.dll", "BngRwReqCancel")) { return 1; }
|
HOOK (i32, bngrw_reqCancel, PROC_ADDRESS ("bngrw.dll", "BngRwReqCancel")) { return 1; }
|
||||||
HOOK (u64, bngrw_Init, PROC_ADDRESS ("bngrw.dll", "BngRwInit")) { return 0; }
|
HOOK (u64, bngrw_Init, PROC_ADDRESS ("bngrw.dll", "BngRwInit")) { return 0; }
|
||||||
HOOK (u64, bngrw_attach, PROC_ADDRESS ("bngrw.dll", "BngRwAttach"), i32 a1, char *a2, i32 a3, i32 a4, i32 (*callback) (i32, i32, i32 *), i32 *a6) { return 1; }
|
HOOK (u64, bngrw_attach, PROC_ADDRESS ("bngrw.dll", "BngRwAttach"), i32 a1, char *a2, i32 a3, i32 a4, i32 (*callback) (i32, i32, i32 *), i32 *a6) {
|
||||||
HOOK (u64, bngrw_reqWaitTouch, PROC_ADDRESS ("bngrw.dll", "BngRwReqWaitTouch"), u32 a1, i32 a2, u32 a3, void (*callback) (i32, i32, u8[168], u64), u64 a5) { return 1; }
|
// This is way too fucking jank
|
||||||
|
attachCallback = callback;
|
||||||
|
attachData = a6;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
HOOK (u64, bngrw_reqWaitTouch, PROC_ADDRESS ("bngrw.dll", "BngRwReqWaitTouch"), u32 a1, i32 a2, u32 a3, void (*callback) (i32, i32, u8[168], u64), u64 a5) {
|
||||||
|
waitingForTouch = true;
|
||||||
|
touchCallback = callback;
|
||||||
|
touchData = a5;
|
||||||
|
for (auto plugin : plugins) {
|
||||||
|
FARPROC touchEvent = GetProcAddress (plugin, "WaitTouch");
|
||||||
|
if (touchEvent) ((waitTouchEvent *)touchEvent) (callback, a5);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Init () {
|
Init () {
|
||||||
@ -224,6 +306,8 @@ Init () {
|
|||||||
INSTALL_HOOK (bngrw_ReqSetLedPower);
|
INSTALL_HOOK (bngrw_ReqSetLedPower);
|
||||||
INSTALL_HOOK (bngrw_reqCancel);
|
INSTALL_HOOK (bngrw_reqCancel);
|
||||||
INSTALL_HOOK (bngrw_Init)
|
INSTALL_HOOK (bngrw_Init)
|
||||||
|
INSTALL_HOOK (bngrw_attach);
|
||||||
|
INSTALL_HOOK (bngrw_reqWaitTouch);
|
||||||
|
|
||||||
KeyConfig::Init();
|
KeyConfig::Init();
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,10 @@ GameVersion version = GameVersion::UNKNOWN;
|
|||||||
std::vector<HMODULE> plugins;
|
std::vector<HMODULE> plugins;
|
||||||
|
|
||||||
const char *server = "127.0.0.1";
|
const char *server = "127.0.0.1";
|
||||||
char accessCode[21] = "00000000000000000000";
|
char accessCode1[21] = "00000000000000000001";
|
||||||
char chipId[33] = "00000000000000000000000000000000";
|
char accessCode2[21] = "00000000000000000002";
|
||||||
|
char chipId1[33] = "00000000000000000000000000000001";
|
||||||
|
char chipId2[33] = "00000000000000000000000000000002";
|
||||||
|
|
||||||
HOOK (i32, ShowMouse, PROC_ADDRESS ("user32.dll", "ShowCursor"), bool) { return originalShowMouse (true); }
|
HOOK (i32, ShowMouse, PROC_ADDRESS ("user32.dll", "ShowCursor"), bool) { return originalShowMouse (true); }
|
||||||
HOOK (i32, ExitWindows, PROC_ADDRESS ("user32.dll", "ExitWindowsEx")) {
|
HOOK (i32, ExitWindows, PROC_ADDRESS ("user32.dll", "ExitWindowsEx")) {
|
||||||
@ -75,9 +77,13 @@ createCard () {
|
|||||||
srand (time (0));
|
srand (time (0));
|
||||||
|
|
||||||
std::generate (buf, buf + 20, [&] () { return hexCharacterTable[rand () % 10]; });
|
std::generate (buf, buf + 20, [&] () { return hexCharacterTable[rand () % 10]; });
|
||||||
WritePrivateProfileStringA ("card", "accessCode", buf, ".\\card.ini");
|
WritePrivateProfileStringA ("card", "accessCode1", buf, ".\\card.ini");
|
||||||
std::generate (buf, buf + 32, [&] () { return hexCharacterTable[rand () % 16]; });
|
std::generate (buf, buf + 32, [&] () { return hexCharacterTable[rand () % 16]; });
|
||||||
WritePrivateProfileStringA ("card", "chipId", buf, ".\\card.ini");
|
WritePrivateProfileStringA ("card", "chipId1", buf, ".\\card.ini");
|
||||||
|
std::generate (buf, buf + 20, [&] () { return hexCharacterTable[rand () % 10]; });
|
||||||
|
WritePrivateProfileStringA ("card", "accessCode2", buf, ".\\card.ini");
|
||||||
|
std::generate (buf, buf + 32, [&] () { return hexCharacterTable[rand () % 16]; });
|
||||||
|
WritePrivateProfileStringA ("card", "chipId2", buf, ".\\card.ini");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL
|
BOOL
|
||||||
@ -113,8 +119,10 @@ DllMain (HMODULE module, DWORD reason, LPVOID reserved) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!std::filesystem::exists (".\\card.ini")) createCard ();
|
if (!std::filesystem::exists (".\\card.ini")) createCard ();
|
||||||
GetPrivateProfileStringA ("card", "accessCode", accessCode, accessCode, 21, ".\\card.ini");
|
GetPrivateProfileStringA ("card", "accessCode1", accessCode1, accessCode1, 21, ".\\card.ini");
|
||||||
GetPrivateProfileStringA ("card", "chipId", chipId, chipId, 33, ".\\card.ini");
|
GetPrivateProfileStringA ("card", "chipId1", chipId1, chipId1, 33, ".\\card.ini");
|
||||||
|
GetPrivateProfileStringA ("card", "accessCode2", accessCode2, accessCode2, 21, ".\\card.ini");
|
||||||
|
GetPrivateProfileStringA ("card", "chipId2", chipId2, chipId2, 33, ".\\card.ini");
|
||||||
|
|
||||||
INSTALL_HOOK (ShowMouse);
|
INSTALL_HOOK (ShowMouse);
|
||||||
INSTALL_HOOK (ExitWindows);
|
INSTALL_HOOK (ExitWindows);
|
||||||
|
@ -9,7 +9,9 @@ Keybindings DEBUG_UP = {.keycodes = {VK_UP}};
|
|||||||
Keybindings DEBUG_DOWN = {.keycodes = {VK_DOWN}};
|
Keybindings DEBUG_DOWN = {.keycodes = {VK_DOWN}};
|
||||||
Keybindings DEBUG_ENTER = {.keycodes = {VK_RETURN}};
|
Keybindings DEBUG_ENTER = {.keycodes = {VK_RETURN}};
|
||||||
Keybindings COIN_ADD = {.keycodes = {VK_RETURN}, .buttons = {SDL_CONTROLLER_BUTTON_START}};
|
Keybindings COIN_ADD = {.keycodes = {VK_RETURN}, .buttons = {SDL_CONTROLLER_BUTTON_START}};
|
||||||
Keybindings QR_CARD_READ = {.keycodes = {'P'}};
|
Keybindings CARD_INSERT_1 = {.keycodes = {'P'}};
|
||||||
|
Keybindings CARD_INSERT_2 = {};
|
||||||
|
Keybindings QR_CARD_READ = {.keycodes = {'O'}};
|
||||||
Keybindings QR_DATA_READ = {.keycodes = {'Q'}};
|
Keybindings QR_DATA_READ = {.keycodes = {'Q'}};
|
||||||
Keybindings P1_LEFT_BLUE = {.keycodes = {'D'}, .axis = {SDL_AXIS_LTRIGGER_DOWN}};
|
Keybindings P1_LEFT_BLUE = {.keycodes = {'D'}, .axis = {SDL_AXIS_LTRIGGER_DOWN}};
|
||||||
Keybindings P1_LEFT_RED = {.keycodes = {'F'}, .buttons = {SDL_CONTROLLER_BUTTON_LEFTSTICK}};
|
Keybindings P1_LEFT_RED = {.keycodes = {'F'}, .buttons = {SDL_CONTROLLER_BUTTON_LEFTSTICK}};
|
||||||
@ -36,6 +38,8 @@ Init() {
|
|||||||
SetConfigValue (config, "DEBUG_ENTER", &DEBUG_ENTER);
|
SetConfigValue (config, "DEBUG_ENTER", &DEBUG_ENTER);
|
||||||
|
|
||||||
SetConfigValue (config, "COIN_ADD", &COIN_ADD);
|
SetConfigValue (config, "COIN_ADD", &COIN_ADD);
|
||||||
|
SetConfigValue (config, "CARD_INSERT_1", &CARD_INSERT_1);
|
||||||
|
SetConfigValue (config, "CARD_INSERT_2", &CARD_INSERT_2);
|
||||||
SetConfigValue (config, "QR_CARD_READ", &QR_CARD_READ);
|
SetConfigValue (config, "QR_CARD_READ", &QR_CARD_READ);
|
||||||
SetConfigValue (config, "QR_DATA_READ", &QR_DATA_READ);
|
SetConfigValue (config, "QR_DATA_READ", &QR_DATA_READ);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user