Bemanitools v5.26 release

This commit is contained in:
icex2
2019-09-27 22:36:50 +02:00
commit cbd7720349
718 changed files with 62731 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
avsdlls += jbhook
deplibs_jbhook := \
avs \
ldflags_jbhook := \
-lws2_32 \
libs_jbhook := \
acioemu \
eamio \
jbio \
p4ioemu \
hook \
hooklib \
util \
src_jbhook := \
acio.c \
dllmain.c \
eamuse.c \
gfx.c \
options.c \
io.c
+95
View File
@@ -0,0 +1,95 @@
#include <windows.h>
#include <ntdef.h>
#include <devioctl.h>
#include <ntddser.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include "acioemu/addr.h"
#include "acioemu/emu.h"
#include "acioemu/h44b.h"
#include "acioemu/iccb.h"
#include "hook/iohook.h"
#include "jbhook/acio.h"
#include "imports/avs.h"
#include "util/defs.h"
#include "util/hex.h"
#include "util/iobuf.h"
#include "util/log.h"
#include "util/str.h"
static struct ac_io_emu ac_io_emu;
static struct ac_io_emu_iccb ac_io_emu_iccb;
static struct ac_io_emu_h44b ac_io_emu_h44b;
void ac_io_port_init(void)
{
ac_io_emu_init(&ac_io_emu, L"COM2");
ac_io_emu_iccb_init(&ac_io_emu_iccb, &ac_io_emu, 0);
ac_io_emu_h44b_init(&ac_io_emu_h44b, &ac_io_emu, 1);
}
void ac_io_port_fini(void)
{
ac_io_emu_fini(&ac_io_emu);
}
HRESULT ac_io_port_dispatch_irp(struct irp *irp)
{
const struct ac_io_message *msg;
HRESULT hr;
log_assert(irp != NULL);
if (!ac_io_emu_match_irp(&ac_io_emu, irp)) {
return irp_invoke_next(irp);
}
for (;;) {
hr = ac_io_emu_dispatch_irp(&ac_io_emu, irp);
if (hr != S_OK) {
return hr;
}
msg = ac_io_emu_request_peek(&ac_io_emu);
switch (msg->addr) {
case 0:
ac_io_emu_cmd_assign_addrs(&ac_io_emu, msg, 2);
break;
case 1:
ac_io_emu_iccb_dispatch_request(&ac_io_emu_iccb, msg);
break;
case 2:
ac_io_emu_h44b_dispatch_request(&ac_io_emu_h44b, msg);
break;
case AC_IO_BROADCAST:
log_warning("Broadcast(?) message on jubeat ACIO bus?");
break;
default:
log_warning("ACIO message on unhandled bus address: %d",
msg->addr);
break;
}
ac_io_emu_request_pop(&ac_io_emu);
}
}
+8
View File
@@ -0,0 +1,8 @@
#ifndef JBHOOK_ACIO_H
#define JBHOOK_ACIO_H
void ac_io_port_init(void);
void ac_io_port_fini(void);
HRESULT ac_io_port_dispatch_irp(struct irp *irp);
#endif
+162
View File
@@ -0,0 +1,162 @@
#include <windows.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include "bemanitools/eamio.h"
#include "bemanitools/jbio.h"
#include "hook/iohook.h"
#include "hooklib/app.h"
#include "hooklib/rs232.h"
#include "hooklib/setupapi.h"
#include "imports/avs.h"
#include "jbhook/acio.h"
#include "jbhook/eamuse.h"
#include "jbhook/gfx.h"
#include "jbhook/io.h"
#include "jbhook/options.h"
#include "p4ioemu/device.h"
#include "p4ioemu/setupapi.h"
#include "util/defs.h"
#include "util/log.h"
#include "util/thread.h"
static struct options options;
static const irp_handler_t jbhook_handlers[] = {
p4ioemu_dispatch_irp,
ac_io_port_dispatch_irp,
};
static bool my_dll_entry_init(char *sidcode, struct property_node *param)
{
bool eam_io_ok;
bool jb_io_ok;
eam_io_ok = false;
jb_io_ok = false;
log_info("--- Begin jbhook dll_entry_init ---");
if (!options.disable_p4ioemu) {
p4ioemu_init(jbhook_io_init());
log_info("Starting up jubeat IO backend");
jb_io_set_loggers(
log_impl_misc,
log_impl_info,
log_impl_warning,
log_impl_fatal);
jb_io_ok = jb_io_init(
avs_thread_create,
avs_thread_join,
avs_thread_destroy);
if (!jb_io_ok) {
goto fail;
}
}
if (!options.disable_cardemu) {
ac_io_port_init();
log_info("Starting up card reader backend");
eam_io_set_loggers(
log_impl_misc,
log_impl_info,
log_impl_warning,
log_impl_fatal);
eam_io_ok = eam_io_init(
avs_thread_create,
avs_thread_join,
avs_thread_destroy);
if (!eam_io_ok) {
goto fail;
}
}
log_info("--- End jbhook dll_entry_init ---");
return app_hook_invoke_init(sidcode, param);
fail:
if (eam_io_ok) {
eam_io_fini();
}
if (jb_io_ok) {
jb_io_fini();
}
return false;
}
static bool my_dll_entry_main(void)
{
bool result;
result = app_hook_invoke_main();
log_info("Shutting down card reader backend");
eam_io_fini();
log_info("Shutting down Jubeat IO backend");
jb_io_fini();
if (!options.disable_cardemu) {
ac_io_port_fini();
}
if (!options.disable_p4ioemu) {
p4ioemu_fini();
}
options_fini(&options);
return result;
}
BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
{
if (reason != DLL_PROCESS_ATTACH) {
return TRUE;
}
log_to_external(
log_body_misc,
log_body_info,
log_body_warning,
log_body_fatal);
options_init_from_cmdline(&options);
app_hook_init(my_dll_entry_init, my_dll_entry_main);
iohook_init(jbhook_handlers, lengthof(jbhook_handlers));
if (!options.disable_cardemu) {
rs232_hook_init();
}
if (!options.disable_p4ioemu) {
hook_setupapi_init(&p4ioemu_setupapi_data);
}
gfx_hook_init();
jbhook_eamuse_hook_init();
return TRUE;
}
+59
View File
@@ -0,0 +1,59 @@
#define LOG_MODULE "eamuse-hook"
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "hook/table.h"
#include "util/defs.h"
#include "util/log.h"
#include "util/str.h"
static const char* jbhook_eamuse_konami_url = "eamuse.konami.";
static int (STDCALL *real_getaddrinfo)(PCSTR pNodeName, PCSTR pServiceName,
const ADDRINFOA *pHints, PADDRINFOA *ppResult);
static int STDCALL my_getaddrinfo(PCSTR pNodeName, PCSTR pServiceName,
const ADDRINFOA *pHints, PADDRINFOA *ppResult);
static const struct hook_symbol eamuse_hook_syms[] = {
{
.name = "getaddrinfo",
.ordinal = 176,
.patch = my_getaddrinfo,
.link = (void **) &real_getaddrinfo,
},
};
static int STDCALL my_getaddrinfo(PCSTR pNodeName, PCSTR pServiceName,
const ADDRINFOA *pHints, PADDRINFOA *ppResult)
{
log_misc("my_getaddrinfo: %s, %s", pNodeName, pServiceName);
/* resolve eamuse.konami.fun/com to 127.0.0.1 to avoid lag spikes every
150 seconds which might happen in-game as well */
if (!strncmp(pNodeName, jbhook_eamuse_konami_url,
strlen(jbhook_eamuse_konami_url))) {
log_info("Resolve konami.eamuse.XXX -> localhost");
pNodeName = "localhost";
}
return real_getaddrinfo(pNodeName, pServiceName, pHints, ppResult);
}
void jbhook_eamuse_hook_init(void)
{
hook_table_apply(
NULL,
"ws2_32.dll",
eamuse_hook_syms,
lengthof(eamuse_hook_syms));
log_info("Inserted eamuse hooks");
}
+6
View File
@@ -0,0 +1,6 @@
#ifndef JBHOOK_EAMUSE_H
#define JBHOOK_EAMUSE_H
void jbhook_eamuse_hook_init(void);
#endif
+74
View File
@@ -0,0 +1,74 @@
#define LOG_MODULE "jbhook-gfx"
#include <windows.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "hook/com-proxy.h"
#include "hook/table.h"
#include "jbhook/gfx.h"
#include "util/defs.h"
#include "util/log.h"
#include "util/str.h"
#include "util/time.h"
static DWORD STDCALL my_GetGlyphOutline(HDC hdc, UINT uChar, UINT uFormat,
LPGLYPHMETRICS lpgm, DWORD cbBuffer, LPVOID lpvBuffer,
const MAT2* lpmat2);
static DWORD (STDCALL* real_GetGlyphOutline)(HDC hdc, UINT uChar, UINT uFormat,
LPGLYPHMETRICS lpgm, DWORD cbBuffer, LPVOID lpvBuffer,
const MAT2* lpmat2);
static const struct hook_symbol gfx_hook_syms[] = {
{
.name = "GetGlyphOutlineA",
.patch = my_GetGlyphOutline,
.link = (void **) &real_GetGlyphOutline
},
{
.name = "IsDBCSLeadByteEx",
.patch = my_GetGlyphOutline, // !??
.link = (void **) &real_GetGlyphOutline // !??
},
};
static DWORD STDCALL my_GetGlyphOutline(HDC hdc, UINT uChar, UINT uFormat,
LPGLYPHMETRICS lpgm, DWORD cbBuffer, LPVOID lpvBuffer,
const MAT2* lpmat2)
{
if (IsDBCSLeadByteEx(CP_ACP, uChar & 0xFF)) {
log_warning("!!!!!!!!");
char tmp[2];
tmp[0] = uChar & 0xFF;
tmp[1] = (uChar >> 8) & 0xFF;
MultiByteToWideChar(CP_ACP, MB_USEGLYPHCHARS, tmp, 2, lpvBuffer, cbBuffer);
}
return real_GetGlyphOutline(hdc, uChar, uFormat, lpgm, cbBuffer, lpvBuffer,
lpmat2);
}
void gfx_hook_init(void)
{
hook_table_apply(
NULL,
"gdi32.dll",
gfx_hook_syms,
lengthof(gfx_hook_syms));
log_info("Inserted gfx hooks");
}
void gfx_set_windowed(bool framed)
{
}
+20
View File
@@ -0,0 +1,20 @@
#ifndef JBHOOK_D3D8_H
#define JBHOOK_D3D8_H
#include <stdbool.h>
/**
* Hook some gfx related functions to patch gfx related stuff
* like enabling window mode.
*/
void gfx_hook_init(void);
/**
* Set the game to window mode.
*
* @param framed True to add a window frame and make the window
* movable, resizable, minizable. False for no frame.
*/
void gfx_set_windowed(bool framed);
#endif
+149
View File
@@ -0,0 +1,149 @@
#define LOG_MODULE "jbhook-io"
#include <string.h>
#include "bemanitools/jbio.h"
#include "imports/avs.h"
#include "jbhook/io.h"
#include "util/log.h"
enum jbhook_io_p4io_command {
JUHOOK_IO_P4IO_CMD_OUTPUTS = 0x18,
};
struct jbhook_io_p4io_outputs {
uint32_t outputs;
};
static void jbhook_io_jamma2_read(void* resp, uint32_t nbytes);
static uint32_t jbhook_command_handle(uint8_t cmd, const void* payload,
uint32_t payload_len, void* resp, uint32_t resp_max_len);
static const struct p4ioemu_device_msg_hook jbhook_io_msg = {
.jamma2_read = jbhook_io_jamma2_read,
.command_handle = jbhook_command_handle,
.roundplug_read_id = NULL,
.roundplug_read_mem = NULL
};
/*
0:0 ???
0:1 b2
0:2 b6
0:3 b10
0:4 b14
0:5 b1
0:6 b5
0:7 b9
1:0 ???
1:1 b4
1:2 b8
1:3 b12
1:4 b16
1:5 b3
1:6 b7
1:7 b11
2:0 b13
2:1 ???
2:2 ???
2:3 ???
2:4 b15
2:5 ???
2:6 ???
2:7 ???
3:0 coin
3:1 service
3:2 ???
3:3 ???
3:4 test
3:5 ???
3:6 ???
3:7 ???
*/
static const uint32_t jbhook_io_panel_mappings[] = {
(1 << 5),
(1 << 1),
(1 << 13),
(1 << 9),
(1 << 6),
(1 << 2),
(1 << 14),
(1 << 10),
(1 << 7),
(1 << 3),
(1 << 15),
(1 << 11),
(1 << 16),
(1 << 4),
(1 << 20),
(1 << 12),
};
static const uint32_t jbhook_io_sys_button_mappings[] = {
(1 << 28),
(1 << 25),
};
static void jbhook_io_jamma2_read(void* resp, uint32_t nbytes)
{
uint32_t* inputs = (uint32_t*) resp;
uint16_t panels;
uint8_t buttons;
/* lower three bytes low active, highest byte high active */
*inputs = 0x00FFFFFF;
if (!jb_io_read_inputs()) {
log_warning("Reading inputs from jbio failed");
return;
}
panels = jb_io_get_panel_inputs();
buttons = jb_io_get_sys_inputs();
for (uint8_t i = 0; i < 16; i++) {
if (panels & (1 << i)) {
*inputs &= ~jbhook_io_panel_mappings[i];
}
}
for (uint8_t i = 0; i < 2; i++) {
if (buttons & (1 << i)) {
*inputs |= jbhook_io_sys_button_mappings[i];
}
}
}
static uint32_t jbhook_command_handle(uint8_t cmd, const void* payload,
uint32_t payload_len, void* resp, uint32_t resp_max_len)
{
switch (cmd) {
case JUHOOK_IO_P4IO_CMD_OUTPUTS:
{
// const struct jbhook_io_p4io_outputs* req =
// (const struct jbhook_io_p4io_outputs*) payload;
//log_misc("JUHOOK_IO_P4IO_CMD_OUTPUTS: 0x%X", req->outputs);
/* coin blocker: off 0x20, on 0x00 */
memset(resp, 0, 4);
return 4;
}
default:
return 0xFFFFFFFF;
}
}
const struct p4ioemu_device_msg_hook* jbhook_io_init(void)
{
return &jbhook_io_msg;
}
+8
View File
@@ -0,0 +1,8 @@
#ifndef JBHOOK_IO_H
#define JBHOOK_IO_H
#include "p4ioemu/device.h"
const struct p4ioemu_device_msg_hook* jbhook_io_init(void);
#endif
+4
View File
@@ -0,0 +1,4 @@
LIBRARY jbhook
EXPORTS
DllMain@12 @1 NONAME
+109
View File
@@ -0,0 +1,109 @@
#include "jbhook/options.h"
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "util/cmdline.h"
#include "util/defs.h"
#include "util/hex.h"
#include "util/log.h"
#include "util/str.h"
void options_init_from_cmdline(struct options* options)
{
int argc;
char **argv;
bool ok;
args_recover(&argc, &argv);
options_init(options);
ok = options_read_cmdline(options, argc, (const char**) argv);
args_free(argc, argv);
if (!ok) {
exit(0);
}
}
void options_init(struct options* options)
{
options->windowed = false;
options->window_framed = false;
options->disable_p4ioemu = false;
options->disable_cardemu = false;
}
bool options_read_cmdline(struct options* options, int argc,
const char **argv)
{
int i;
for (i = 0; i < argc; i++) {
if (argv[i][0] != '-') {
continue;
}
switch (argv[i][1]) {
case 'h':
{
options_print_usage();
return false;
}
case 'w':
{
options->windowed = true;
break;
}
case 'f':
{
options->window_framed = true;
break;
}
case 'c':
{
options->disable_cardemu = true;
break;
}
case 'p':
{
options->disable_p4ioemu = true;
break;
}
}
}
return true;
}
void options_print_usage(void)
{
OutputDebugStringA(
"jbhook for jubeat, build " __DATE__ " " __TIME__ ", gitrev "
STRINGIFY(GITREV) "\n"
"Usage: launcher.exe -K jbhook.dll [game exec] <options> \n"
"\n"
" The following options can be specified after the game exec path:\n"
"\n"
" -h Print this usage message\n"
" -w Run the game windowed\n"
" -f Run the game in a framed window (needs -w option)\n"
" -c Disable card emulation (e.g. when running on a real cab)\n"
" -p Disable p4io emulation (e.g. when running on a real cab or on a bare p4io)\n"
);
}
void options_fini(struct options* options)
{
}
+22
View File
@@ -0,0 +1,22 @@
#ifndef JBHOOK_OPTIONS_H
#define JBHOOK_OPTIONS_H
#include <stdbool.h>
#include <stdint.h>
struct options {
bool windowed;
bool window_framed;
bool disable_p4ioemu;
bool disable_cardemu;
};
void options_init_from_cmdline(struct options* options);
void options_init(struct options* options);
bool options_read_cmdline(struct options* options,
int argc, const char** argv);
void options_print_usage(void);
void options_fini(struct options* options);
#endif