1
0
mirror of synced 2024-11-23 21:40:58 +01:00

sao: working USIO, add clock enable toggle

This commit is contained in:
Kevin Trocolli 2024-04-22 21:11:03 -04:00
parent db71d3a0f6
commit 28ab4c6e37
13 changed files with 121 additions and 66 deletions

View File

@ -250,6 +250,9 @@ static BOOL WINAPI my_AdjustTokenPrivileges(
HRESULT clock_hook_init(const struct clock_config *cfg)
{
assert(cfg != NULL);
if (!cfg->enable) {
return S_FALSE;
}
clock_time_warp = cfg->timewarp;

View File

@ -5,6 +5,7 @@
#include <stdbool.h>
struct clock_config {
bool enable;
bool timezone;
bool timewarp;
bool writeable;

View File

@ -84,6 +84,7 @@ void clock_config_load(struct clock_config *cfg, const wchar_t *filename)
assert(cfg != NULL);
assert(filename != NULL);
cfg->enable = GetPrivateProfileIntW(L"clock", L"enable", 1, filename);
cfg->timezone = GetPrivateProfileIntW(L"clock", L"timezone", 1, filename);
cfg->timewarp = GetPrivateProfileIntW(L"clock", L"timewarp", 0, filename);
cfg->writeable = GetPrivateProfileIntW(

View File

@ -19,8 +19,11 @@ const struct dll_bind_sym sao_dll_syms[] = {
.sym = "sao_io_get_opbtns",
.off = offsetof(struct sao_dll, get_opbtns),
}, {
.sym = "sao_io_get_drum_analog",
.off = offsetof(struct sao_dll, get_drum_analog),
.sym = "sao_io_get_analog",
.off = offsetof(struct sao_dll, get_analog),
}, {
.sym = "sao_io_get_gamebtns",
.off = offsetof(struct sao_dll, get_gamebtns),
}
};

View File

@ -10,7 +10,8 @@ struct sao_dll {
HRESULT (*poll)(void);
void (*read_coin_counter)(uint16_t *coins, uint16_t *services);
void (*get_opbtns)(uint8_t *opbtn);
void (*get_drum_analog)(uint8_t *gamebtn);
void (*get_gamebtns)(uint8_t *gamebtns);
void (*get_analog)(uint8_t *x, uint8_t *y);
};
struct sao_dll_config {

View File

@ -4,5 +4,6 @@ EXPORTS
sao_io_get_api_version
sao_io_init
sao_io_read_coin_counter
sao_io_get_drum_analog
sao_io_get_analog
sao_io_get_gamebtns
sao_io_get_opbtns

View File

@ -21,13 +21,19 @@ static void dll_hook_insert_hooks(HMODULE target);
static HMODULE WINAPI my_LoadLibraryW(const wchar_t *name);
static HMODULE (WINAPI *next_LoadLibraryW)(const wchar_t *name);
static HMODULE WINAPI my_LoadLibraryExW(const wchar_t *name, HANDLE hFile, DWORD dwFlags);
static HMODULE (WINAPI *next_LoadLibraryExW)(const wchar_t *name, HANDLE hFile, DWORD dwFlags);
static const struct hook_symbol unity_kernel32_syms[] = {
{
.name = "LoadLibraryW",
.patch = my_LoadLibraryW,
.link = (void **) &next_LoadLibraryW,
},
},{
.name = "LoadLibraryExW",
.patch = my_LoadLibraryExW,
.link = (void **) &next_LoadLibraryExW,
}
};
static const wchar_t *target_modules[] = {
@ -58,6 +64,12 @@ static void dll_hook_insert_hooks(HMODULE target)
_countof(unity_kernel32_syms));
}
static HMODULE WINAPI my_LoadLibraryExW(const wchar_t *name, HANDLE hFile, DWORD dwFlags)
{
//dprintf("Unity: LoadLibraryExW %ls\n", name);
return my_LoadLibraryW(name);
}
static HMODULE WINAPI my_LoadLibraryW(const wchar_t *name)
{
const wchar_t *name_end;

View File

@ -39,12 +39,16 @@ HRESULT sao_usio_hook_init(const struct usio_config *cfg)
static HRESULT sao_usio_poll(void *ctx, struct usio_state *state)
{
uint8_t opbtn_out = 0;
uint8_t analog_out = 0;
uint8_t gamebtn_out = 0;
uint8_t x = 128;
uint8_t y = 128;
uint16_t coin_ct = 0;
uint16_t service_ct = 0;
sao_dll.get_opbtns(&opbtn_out);
sao_dll.get_drum_analog(&analog_out);
sao_dll.get_analog(&x, &y);
sao_dll.read_coin_counter(&coin_ct, &service_ct);
sao_dll.get_gamebtns(&gamebtn_out);
state->op_btns = 0;
state->p1_btns = 0;
@ -66,17 +70,30 @@ static HRESULT sao_usio_poll(void *ctx, struct usio_state *state)
state->p1_btns |= 0x02; // Enter
}
for (int i = 0; i < _countof(state->analog); i++) {
if (analog_out & 1 << i) {
state->analog[i] = 0x3FFF;
} else {
state->analog[i] = 0x00;
}
if (gamebtn_out & 0x01) {
state->p1_btns |= 0x2000;
}
if (gamebtn_out & 0x02) {
state->p1_btns |= 0x1000;
}
if (gamebtn_out & 0x04) {
state->p1_btns |= 0x0800;
}
if (gamebtn_out & 0x08) {
state->p1_btns |= 0x4000;
}
if (gamebtn_out & 0x10) {
state->p1_btns |= 0x01;
}
if (gamebtn_out & 0x20) {
state->p1_btns |= 0x8000;
}
state->analog[0] = x << 8;
state->analog[1] = y << 8;
state->coins[0].current_coin_count = coin_ct;
state->service.current_coin_count = service_ct;
return S_OK;
}
}

View File

@ -15,13 +15,15 @@ void sao_io_config_load(struct sao_input_config *cfg, const wchar_t *filename)
cfg->down = GetPrivateProfileIntW(L"usio", L"down", VK_DOWN, filename);
cfg->enter = GetPrivateProfileIntW(L"usio", L"enter", VK_RETURN, filename);
cfg->p1_rim_l = GetPrivateProfileIntW(L"drum", L"p1_rim_l", 'Z', filename);
cfg->p1_center_l = GetPrivateProfileIntW(L"usio", L"p1_center_l", 'X', filename);
cfg->p1_center_r = GetPrivateProfileIntW(L"usio", L"p1_center_r", 'C', filename);
cfg->p1_rim_r = GetPrivateProfileIntW(L"usio", L"p1_rim_r", 'V', filename);
cfg->stick_up = GetPrivateProfileIntW(L"usio", L"stick_up", 'W', filename);
cfg->stick_left = GetPrivateProfileIntW(L"usio", L"stick_left", 'A', filename);
cfg->stick_down = GetPrivateProfileIntW(L"usio", L"stick_down", 'S', filename);
cfg->stick_right = GetPrivateProfileIntW(L"usio", L"stick_right", 'D', filename);
cfg->stick_btn1 = GetPrivateProfileIntW(L"usio", L"stick_btn1", 'R', filename);
cfg->stick_btn2 = GetPrivateProfileIntW(L"usio", L"stick_btn2", 'F', filename);
cfg->stick_btn3 = GetPrivateProfileIntW(L"usio", L"stick_btn3", 'V', filename);
cfg->p2_rim_l = GetPrivateProfileIntW(L"drum", L"p2_rim_l", 'U', filename);
cfg->p2_center_l = GetPrivateProfileIntW(L"usio", L"p2_center_l", 'I', filename);
cfg->p2_center_r = GetPrivateProfileIntW(L"usio", L"p2_center_r", 'O', filename);
cfg->p2_rim_r = GetPrivateProfileIntW(L"usio", L"p2_rim_r", 'P', filename);
cfg->btn1 = GetPrivateProfileIntW(L"usio", L"btn1", '1', filename);
cfg->btn2 = GetPrivateProfileIntW(L"usio", L"btn2", '2', filename);
cfg->btn3 = GetPrivateProfileIntW(L"usio", L"btn3", '3', filename);
}

View File

@ -12,14 +12,18 @@ struct sao_input_config {
uint8_t enter;
uint8_t coin;
uint8_t p1_rim_l;
uint8_t p1_center_l;
uint8_t p1_center_r;
uint8_t p1_rim_r;
uint8_t p2_rim_l;
uint8_t p2_center_l;
uint8_t p2_center_r;
uint8_t p2_rim_r;
uint8_t stick_up;
uint8_t stick_down;
uint8_t stick_left;
uint8_t stick_right;
uint8_t stick_btn1;
uint8_t stick_btn2;
uint8_t stick_btn3;
uint8_t btn1;
uint8_t btn2;
uint8_t btn3;
};
#pragma pack(pop)

View File

@ -62,38 +62,47 @@ void sao_io_get_opbtns(uint8_t *opbtn)
}
}
void sao_io_get_drum_analog(uint8_t *gamebtn)
void sao_io_get_gamebtns(uint8_t *gamebtns)
{
if (GetAsyncKeyState(cfg.p1_rim_l) & 0x8000) {
*gamebtn |= SAO_IO_P1_RIM_L;
*gamebtns = 0;
if (GetAsyncKeyState(cfg.btn1) & 0x8000) {
*gamebtns |= SAO_IO_GAMEBTN_1;
}
if (GetAsyncKeyState(cfg.btn2) & 0x8000) {
*gamebtns |= SAO_IO_GAMEBTN_2;
}
if (GetAsyncKeyState(cfg.btn3) & 0x8000) {
*gamebtns |= SAO_IO_GAMEBTN_3;
}
if (GetAsyncKeyState(cfg.stick_btn1) & 0x8000) {
*gamebtns |= SAO_IO_GAMEBTN_STICK1;
}
if (GetAsyncKeyState(cfg.stick_btn2) & 0x8000) {
*gamebtns |= SAO_IO_GAMEBTN_STICK2;
}
if (GetAsyncKeyState(cfg.stick_btn3) & 0x8000) {
*gamebtns |= SAO_IO_GAMEBTN_STICK3;
}
}
void sao_io_get_analog(uint8_t *x, uint8_t *y)
{
*x = 128;
*y = 128;
if (GetAsyncKeyState(cfg.stick_up) & 0x8000) {
*y += 127;
}
if (GetAsyncKeyState(cfg.p1_center_l) & 0x8000) {
*gamebtn |= SAO_IO_P1_CENTER_L;
if (GetAsyncKeyState(cfg.stick_down) & 0x8000) {
*y -= 128;
}
if (GetAsyncKeyState(cfg.p1_center_r) & 0x8000) {
*gamebtn |= SAO_IO_P1_CENTER_R;
if (GetAsyncKeyState(cfg.stick_right) & 0x8000) {
*x += 127;
}
if (GetAsyncKeyState(cfg.p1_rim_r) & 0x8000) {
*gamebtn |= SAO_IO_P1_RIM_R;
}
if (GetAsyncKeyState(cfg.p2_rim_l) & 0x8000) {
*gamebtn |= SAO_IO_P2_RIM_L;
}
if (GetAsyncKeyState(cfg.p2_center_l) & 0x8000) {
*gamebtn |= SAO_IO_P2_CENTER_L;
}
if (GetAsyncKeyState(cfg.p2_center_r) & 0x8000) {
*gamebtn |= SAO_IO_P2_CENTER_R;
}
if (GetAsyncKeyState(cfg.p2_rim_r) & 0x8000) {
*gamebtn |= SAO_IO_P2_RIM_R;
if (GetAsyncKeyState(cfg.stick_left) & 0x8000) {
*x -= 128;
}
}

View File

@ -4,5 +4,6 @@ EXPORTS
sao_io_get_api_version
sao_io_init
sao_io_read_coin_counter
sao_io_get_drum_analog
sao_io_get_analog
sao_io_get_gamebtns
sao_io_get_opbtns

View File

@ -15,14 +15,12 @@ enum {
};
enum {
SAO_IO_P1_RIM_L = 0x0001,
SAO_IO_P1_CENTER_L = 0x0002,
SAO_IO_P1_CENTER_R = 0x0004,
SAO_IO_P1_RIM_R = 0x0008,
SAO_IO_P2_RIM_L = 0x0100,
SAO_IO_P2_CENTER_L = 0x0200,
SAO_IO_P2_CENTER_R = 0x1000,
SAO_IO_P2_RIM_R = 0x2000,
SAO_IO_GAMEBTN_1 = 0x0001,
SAO_IO_GAMEBTN_2 = 0x0002,
SAO_IO_GAMEBTN_3 = 0x0004,
SAO_IO_GAMEBTN_STICK1 = 0x0008,
SAO_IO_GAMEBTN_STICK2 = 0x0010,
SAO_IO_GAMEBTN_STICK3 = 0x0020,
};
/* Get the version of the Pokken IO API that this DLL supports. This
@ -62,6 +60,8 @@ void sao_io_get_opbtns(uint8_t *opbtn);
Minimum API version: 0x0100 */
void sao_io_get_drum_analog(uint8_t *gamebtn);
void sao_io_get_analog(uint8_t *x, uint8_t *y);
void sao_io_get_gamebtns(uint8_t *gamebtns);
void sao_io_read_coin_counter(uint16_t *coins, uint16_t *services);