diff --git a/Package.mk b/Package.mk index 903d7cd..ea6a0d0 100644 --- a/Package.mk +++ b/Package.mk @@ -2,13 +2,6 @@ $(BUILD_DIR_ZIP)/siva.zip: $(V)echo ... $@ $(V)mkdir -p $(BUILD_DIR_ZIP)/siva $(V)mkdir -p $(BUILD_DIR_ZIP)/siva/cert - $(V)cp $(BUILD_DIR_32)/subprojects/capnhook/inject/inject.exe \ - $(BUILD_DIR_32)/sivahook/sivahook.dll \ - $(BUILD_DIR_ZIP)/siva - $(V)mv $(BUILD_DIR_ZIP)/siva/inject.exe \ - $(BUILD_DIR_ZIP)/siva/inject_32.exe - $(V)mv $(BUILD_DIR_ZIP)/siva/sivahook.dll \ - $(BUILD_DIR_ZIP)/siva/sivahook_32.dll $(V)cp $(BUILD_DIR_64)/subprojects/capnhook/inject/inject.exe \ $(BUILD_DIR_64)/sivahook/sivahook.dll \ $(BUILD_DIR_64)/idmac_stub/iDmacDrv.dll \ diff --git a/doc/config/common.md b/doc/config/common.md index 71b1356..00e29d8 100644 --- a/doc/config/common.md +++ b/doc/config/common.md @@ -172,8 +172,7 @@ The final octet of the default gateway's IP address on the virtualized subnet. Default: `01:02:03:04:05:06` -The MAC address of the virtualized Ethernet adapter. The exact value shouldn't -ever matter. +The MAC address of the virtualized Ethernet adapter. Used in nesica auth. ## `[vfs]` diff --git a/idmac/fastio.c b/idmac/fastio.c new file mode 100644 index 0000000..669f99e --- /dev/null +++ b/idmac/fastio.c @@ -0,0 +1,6 @@ +#include "idmac/fastio.h" + +HRESULT fastio_hook_init(fastio_provider_t main, fastio_provider_t sub) +{ + return S_OK; +} \ No newline at end of file diff --git a/idmac/fastio.h b/idmac/fastio.h new file mode 100644 index 0000000..41e89e0 --- /dev/null +++ b/idmac/fastio.h @@ -0,0 +1,20 @@ +#pragma once +#include +#include + +struct fastio_node { + struct fastio_node *next; + // Unlike JVS, FastIO comms are done on the game side through + // DMA register reads and writes, meaning we need to have + // indivitual functions here instead of just "transact" + void (*digital_in)(uint16_t *out); // Digital button inputs + void (*analog_in)(uint16_t *out); // Analog stick inputs (WIP) + void (*coins_in)(uint8_t slot, uint16_t *out); // Number of unprocessed coins + void (*digital_out)(uint16_t channel, uint16_t val); // Digital outputs + void (*analog_out)(uint16_t channel, uint16_t val); // Analog outputs (WIP) + void (*coins_out)(uint8_t slot, uint16_t removed); // Remove coins from the count +}; + +typedef HRESULT (*fastio_provider_t)(struct fastio_node **root); + +HRESULT fastio_hook_init(fastio_provider_t main, fastio_provider_t sub); diff --git a/idmac/idmac.c b/idmac/idmac.c index a5b8ad0..b0448fe 100644 --- a/idmac/idmac.c +++ b/idmac/idmac.c @@ -11,18 +11,18 @@ #include "util/dprintf.h" #include "util/str.h" -#define IDMAC_IOCTL_DMA_READ CTL_CODE(0xC350, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define IDMAC_IOCTL_DMA_WRITE CTL_CODE(0xC350, 0x801, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define IDMAC_IOCTL_REGISTER_READ CTL_CODE(0xC350, 0x802, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define IDMAC_IOCTL_REGISTER_WRITE CTL_CODE(0xC350, 0x803, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IDMAC_IOCTL_DMA_READ CTL_CODE(0xC350, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IDMAC_IOCTL_DMA_WRITE CTL_CODE(0xC350, 0x801, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IDMAC_IOCTL_REGISTER_READ CTL_CODE(0xC350, 0x802, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IDMAC_IOCTL_REGISTER_WRITE CTL_CODE(0xC350, 0x803, METHOD_BUFFERED, FILE_ANY_ACCESS) #define IDMAC_IOCTL_REGISTER_BUFFER_READ CTL_CODE(0xC350, 0x804, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) #define IDMAC_IOCTL_REGISTER_BUFFER_WRITE CTL_CODE(0xC350, 0x805, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) -#define IDMAC_IOCTL_MEMORY_READ CTL_CODE(0xC350, 0x806, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define IDMAC_IOCTL_MEMORY_WRITE CTL_CODE(0xC350, 0x807, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define IDMAC_IOCTL_MEMORY_BUFFER_READ CTL_CODE(0xC350, 0x808, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define IDMAC_IOCTL_MEMORY_BUFFER_WRITE CTL_CODE(0xC350, 0x809, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define IDMAC_IOCTL_MEMORY_READ_EXT CTL_CODE(0xC350, 0x820, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define IDMAC_IOCTL_MEMORY_WRITE_EXT CTL_CODE(0xC350, 0x821, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IDMAC_IOCTL_MEMORY_READ CTL_CODE(0xC350, 0x806, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IDMAC_IOCTL_MEMORY_WRITE CTL_CODE(0xC350, 0x807, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IDMAC_IOCTL_MEMORY_BUFFER_READ CTL_CODE(0xC350, 0x808, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IDMAC_IOCTL_MEMORY_BUFFER_WRITE CTL_CODE(0xC350, 0x809, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IDMAC_IOCTL_MEMORY_READ_EXT CTL_CODE(0xC350, 0x820, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IDMAC_IOCTL_MEMORY_WRITE_EXT CTL_CODE(0xC350, 0x821, METHOD_BUFFERED, FILE_ANY_ACCESS) static uint8_t dipsw = 0; static HANDLE idmac_fd; @@ -172,6 +172,8 @@ HRESULT idmac_hook_init(const struct idmac_config *cfg, struct idmac_hardware *h return hr; } + fastio_hook_init(hardware->fastio_main, hardware->fastio_sub); + idmac_hook_table_apply(NULL); hr = iohook_open_nul_fd(&idmac_fd); diff --git a/idmac/idmac.h b/idmac/idmac.h index e482b33..aab31b5 100644 --- a/idmac/idmac.h +++ b/idmac/idmac.h @@ -4,6 +4,7 @@ #include #include "idmac/jvs.h" +#include "idmac/fastio.h" #pragma pack(push,1) @@ -17,8 +18,8 @@ struct idmac_hardware { uint8_t dipsw; jvs_provider_t dongle; jvs_provider_t jvs; - jvs_provider_t fastio_main; - jvs_provider_t fastio_sub; + fastio_provider_t fastio_main; + fastio_provider_t fastio_sub; }; #pragma pack(pop) diff --git a/idmac/jvs.h b/idmac/jvs.h index 0bedb0f..dbbb6df 100644 --- a/idmac/jvs.h +++ b/idmac/jvs.h @@ -6,13 +6,6 @@ #include "jvs/jvs-bus.h" -DEFINE_GUID( - jvs_guid, - 0xDB6BBB45, - 0xCC96, - 0x4288, - 0xAA, 0x00, 0x6C, 0x00, 0xD7, 0x67, 0xBD, 0xBF); - struct jvs_config { bool enable; }; diff --git a/idmac/meson.build b/idmac/meson.build index 47c60d6..872d567 100644 --- a/idmac/meson.build +++ b/idmac/meson.build @@ -18,5 +18,7 @@ idmac_lib = static_library( 'guid.c', 'jvs.c', 'jvs.h', + 'fastio.c', + 'fastio.h', ], ) diff --git a/sivahook/config.c b/sivahook/config.c index f7f6d7a..c0de305 100644 --- a/sivahook/config.c +++ b/sivahook/config.c @@ -22,16 +22,6 @@ void siva_dll_config_load( filename); } -void touch_config_load( - struct touch_config *cfg, - const wchar_t *filename) -{ - assert(cfg != NULL); - assert(filename != NULL); - - cfg->enable = GetPrivateProfileIntW(L"touch", L"enable", 1, filename); -} - void siva_hook_config_load( struct siva_hook_config *cfg, const wchar_t *filename) @@ -43,5 +33,4 @@ void siva_hook_config_load( platform_config_load(&cfg->platform, filename); siva_dll_config_load(&cfg->dll, filename); gfx_config_load(&cfg->gfx, filename); - touch_config_load(&cfg->touch, filename); } \ No newline at end of file diff --git a/sivahook/config.h b/sivahook/config.h index c53bd60..93f890e 100644 --- a/sivahook/config.h +++ b/sivahook/config.h @@ -3,7 +3,6 @@ #include #include "sivahook/siva-dll.h" -#include "sivahook/touch.h" #include "idmac/config.h" #include "platform/config.h" @@ -15,7 +14,6 @@ struct siva_hook_config { struct platform_config platform; struct siva_dll_config dll; struct gfx_config gfx; - struct touch_config touch; }; void siva_hook_config_load( diff --git a/sivahook/dllmain.c b/sivahook/dllmain.c index 04667b6..4ff88df 100644 --- a/sivahook/dllmain.c +++ b/sivahook/dllmain.c @@ -20,7 +20,6 @@ #include "sivahook/reader.h" #include "sivahook/config.h" #include "sivahook/siva-dll.h" -#include "sivahook/touch.h" #include "sivahook/unity.h" #include "platform/platform.h" @@ -64,12 +63,6 @@ static DWORD CALLBACK siva_pre_startup(void) hr = siva_dll_init(&siva_hook_cfg.dll, siva_hook_mod); - if (FAILED(hr)) { - goto fail; - } - - hr = touch_hook_init(&siva_hook_cfg.touch); - if (FAILED(hr)) { goto fail; } diff --git a/sivahook/fastio.c b/sivahook/fastio.c index 5ee2eaf..4012f1b 100644 --- a/sivahook/fastio.c +++ b/sivahook/fastio.c @@ -2,7 +2,7 @@ #include #include "jvs/jvs-bus.h" -#include "idmac/jvs.h" +#include "idmac/fastio.h" #include "board/io3.h" #include "sivahook/fastio.h" @@ -10,20 +10,13 @@ #include "util/dprintf.h" -static void fastio_jvs_read_switches(void *ctx, struct io3_switch_state *out); -static void fastio_jvs_read_coin_counter( +static void fastio_digital_read(void *ctx, struct io3_switch_state *out); +static void fastio_coin_read( void *ctx, uint8_t slot_no, uint16_t *out); -static const struct io3_ops siva_jvs_fastio_ops = { - .read_switches = fastio_jvs_read_switches, - .read_coin_counter = fastio_jvs_read_coin_counter, -}; - -static struct io3 siva_jvs_fastio; - -HRESULT siva_fastio_init(struct jvs_node **out) +HRESULT siva_fastio_init(struct fastio_node **out) { HRESULT hr; @@ -31,14 +24,13 @@ HRESULT siva_fastio_init(struct jvs_node **out) dprintf("Siva Nesica Fastio: Init\n"); - io3_init(&siva_jvs_fastio, NULL, &siva_jvs_fastio_ops, NULL); - *out = io3_to_jvs_node(&siva_jvs_fastio); + siva_dll.init(); return S_OK; } -static void fastio_jvs_read_switches(void *ctx, struct io3_switch_state *out) {} -static void fastio_jvs_read_coin_counter( +static void fastio_digital_read(void *ctx, struct io3_switch_state *out) {} +static void fastio_coin_read( void *ctx, uint8_t slot_no, uint16_t *out) diff --git a/sivahook/fastio.h b/sivahook/fastio.h index 8124462..20e37e3 100644 --- a/sivahook/fastio.h +++ b/sivahook/fastio.h @@ -2,5 +2,24 @@ #include #include "jvs/jvs-bus.h" +#include "idmac/fastio.h" -HRESULT siva_fastio_init(struct jvs_node **out); +enum SIVA_SWITCH { + RIGHT_BUTTON = 0x000080, + RIGHT_UP = 0x010000, + RIGHT_DOWN = 0x040000, + RIGHT_LEFT = 0x100000, + RIGHT_RIGHT = 0x400000, + LEFT_BUTTON = 0x000020, + LEFT_UP = 0x000100, + LEFT_DOWN = 0x000400, + LEFT_LEFT = 0x001000, + LEFT_RIGHT = 0x004000, + SYS_SERVICE = 0x000004, + SYS_TEST = 0x000040, + SYS_SELECT = 0x000008, + SYS_ENTER = 0x000010, + SYS_COIN = 0x000001, +}; + +HRESULT siva_fastio_init(struct fastio_node **out); diff --git a/sivahook/meson.build b/sivahook/meson.build index 0239b0c..b1d97e7 100644 --- a/sivahook/meson.build +++ b/sivahook/meson.build @@ -26,8 +26,6 @@ shared_library( 'siva-dll.h', 'unity.c', 'unity.h', - 'touch.c', - 'touch.h', 'reader.c', 'reader.h', 'fastio.c', diff --git a/sivahook/touch.c b/sivahook/touch.c deleted file mode 100644 index a76f130..0000000 --- a/sivahook/touch.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -#include "sivahook/touch.h" -#include "hooklib/createprocess.h" - -#include "util/dprintf.h" - -HRESULT touch_hook_init(const struct touch_config *cfg) -{ - if (!cfg->enable) { - return S_FALSE; - } - - dprintf("Touch: hook init\n"); - return createprocess_push_hook_w(L"\"NanoTS_PTool_win8.exe\"", L"inject_32.exe -d -k sivahook_32.dll ", NULL, false); -} \ No newline at end of file diff --git a/sivahook/touch.h b/sivahook/touch.h deleted file mode 100644 index 8bdac47..0000000 --- a/sivahook/touch.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include -#include - -struct touch_config { - bool enable; -}; - -HRESULT touch_hook_init(const struct touch_config *cfg); \ No newline at end of file diff --git a/sivaio/sivaio.c b/sivaio/sivaio.c index 5c536e2..b31a9f3 100644 --- a/sivaio/sivaio.c +++ b/sivaio/sivaio.c @@ -3,6 +3,7 @@ #include #include +#include #include #include "sivaio/sivaio.h" @@ -15,6 +16,7 @@ static bool siva_io_service = false; static uint16_t siva_coin_ct = 0; static uint16_t siva_service_ct = 0; static struct siva_input_config cfg; +static HANDLE selected_ri_dev = (HANDLE)-1; uint16_t siva_io_get_api_version(void) { @@ -23,19 +25,69 @@ uint16_t siva_io_get_api_version(void) HRESULT siva_io_init(void) { + wchar_t ri_dev_name[PATH_MAX] = L"\0"; + UINT num_ri_devs = 0; + UINT len_ri_dev_name = 0; + DWORD err = 0; + PRAWINPUTDEVICELIST ri_devs = NULL; + dprintf("Siva IO: Init\n"); siva_io_config_load(&cfg, L".\\bananatools.ini"); + + if (GetRawInputDeviceList(NULL, &num_ri_devs, sizeof(RAWINPUTDEVICELIST)) != 0) { + err = GetLastError(); + dprintf("Siva IO: GetRawInputDeviceList failed to get number of devices %08lX\n", err); + return E_FAIL; + } + + ri_devs = malloc(sizeof(RAWINPUTDEVICELIST) * num_ri_devs); + GetRawInputDeviceList(ri_devs, &num_ri_devs, sizeof(RAWINPUTDEVICELIST)); + + if (num_ri_devs <= 0) { + err = GetLastError(); + dprintf("Siva IO: GetRawInputDeviceList failed to get devices info %08lX\n", err); + free(ri_devs); + return E_FAIL; + } + + dprintf("Siva IO: Raw Input device list (%d devices):\n", num_ri_devs); + for (int i = 0; i < num_ri_devs; i++) { + len_ri_dev_name = 0; + if (GetRawInputDeviceInfoW(ri_devs[i].hDevice, RIDI_DEVICENAME, NULL, &len_ri_dev_name) != 0) { + dprintf("Siva IO: GetRawInputDeviceInfoW #%d failed to get name size\n", i); + break; + } + + if (len_ri_dev_name <= 0) { + dprintf("Siva IO: GetRawInputDeviceInfoW #%d len_ri_dev_name <= 0\n", i); + break; + } + + if (len_ri_dev_name >= MAX_PATH) { + dprintf("\tDev #%d - (name too long, %d characters)\n", i, len_ri_dev_name); + continue; + } + + if (GetRawInputDeviceInfoW(ri_devs[i].hDevice, RIDI_DEVICENAME, ri_dev_name, &len_ri_dev_name) <= 0) { + dprintf("Siva IO: GetRawInputDeviceInfoW #%d failed to get name\n", i); + break; + } + + dprintf("\tDev #%d - %ls\n", i, ri_dev_name); + } + + free(ri_devs); return S_OK; } void siva_io_get_btns(uint8_t *btn, uint8_t *stick) { if (GetAsyncKeyState(cfg.test) & 0x8000) { - *btn |= SIVA_BTN_TEST; + *btn |= BTN_TEST; } if (GetAsyncKeyState(cfg.service) & 0x8000) { - *btn |= SIVA_BTN_SERVICE; + *btn |= BTN_SERVICE; } } diff --git a/sivaio/sivaio.h b/sivaio/sivaio.h index afa1376..ed84fec 100644 --- a/sivaio/sivaio.h +++ b/sivaio/sivaio.h @@ -5,22 +5,24 @@ #include enum { - SIVA_BTN_TEST = 0x01, - SIVA_BTN_SERVICE = 0x02, - SIVA_BTN_COIN = 0x03, - SIVA_BTN_LEFT = 0x04, - SIVA_BTN_RIGHT = 0x05, + BTN_LEFT = 0b00000001, + BTN_RIGHT = 0b00000010, + BTN_TEST = 0b00000100, + BTN_SERVICE = 0b00001000, + BTN_SELECT = 0b00010000, + BTN_ENTER = 0b00100000, + BTN_COIN = 0b01000000, }; enum { - SIVA_STICK_L_UP = 0x01, - SIVA_STICK_L_RIGHT = 0x02, - SIVA_STICK_L_DOWN = 0x03, - SIVA_STICK_L_LEFT = 0x04, - SIVA_STICK_R_UP = 0x05, - SIVA_STICK_R_RIGHT = 0x06, - SIVA_STICK_R_DOWN = 0x07, - SIVA_STICK_R_LEFT = 0x08, + STICK_LEFT_UP = 0b00000001, + STICK_LEFT_DOWN = 0b00000010, + STICK_LEFT_LEFT = 0b00000100, + STICK_LEFT_RIGHT = 0b00001000, + STICK_RIGHT_UP = 0b00010000, + STICK_RIGHT_DOWN = 0b00100000, + STICK_RIGHT_LEFT = 0b01000000, + STICK_RIGHT_RIGHT = 0b10000000, }; /* Get the version of the Theatrhythm IO API that this DLL supports. This