1
0
mirror of https://github.com/djhackersdev/bemanitools.git synced 2024-11-28 00:10:51 +01:00

chore: Apply code formatting on entire codebase for consistent style

This commit is contained in:
icex2 2023-03-21 23:37:01 +01:00 committed by icex2
parent a1a849aef3
commit 031836ef0e
186 changed files with 2446 additions and 1979 deletions

View File

@ -38,5 +38,4 @@ struct ac_io_panb_poll_out {
};
#pragma pack(pop)
#endif

View File

@ -5,8 +5,8 @@
#include "aciodrv/device.h"
#include "aciodrv/panb.h"
#include "util/thread.h"
#include "util/log.h"
#include "util/thread.h"
static int auto_poll_proc(void *auto_poll_param);
static int auto_poll_threadid;
@ -49,7 +49,8 @@ bool aciodrv_proc_panb_init(struct aciodrv_device_ctx *device)
auto_poll_stop = false;
InitializeCriticalSection(&keypair_lock);
InitializeCriticalSection(&auto_poll_stop_lock);
auto_poll_threadid = thread_create(auto_poll_proc, (void *)device, 0x4000, 0);
auto_poll_threadid =
thread_create(auto_poll_proc, (void *) device, 0x4000, 0);
return true;
}

View File

@ -4,14 +4,15 @@
#include "aciodrv/panb.h"
/**
* Initialize a PANB device. This will take care of setting up the auto-poll and processing
* the poll messages in a separate thread (this is necessary as failing to process messages
* fast enough will cause the device to malfunction).
* Initialize a PANB device. This will take care of setting up the auto-poll and
* processing the poll messages in a separate thread (this is necessary as
* failing to process messages fast enough will cause the device to
* malfunction).
*
* @param device Context of opened device
* @return True if successful, false on error.
* @note This function spawns a thread. Caller must call aciodrv_proc_panb_fini to properly
* terminate.
* @note This function spawns a thread. Caller must call aciodrv_proc_panb_fini
* to properly terminate.
*/
bool aciodrv_proc_panb_init(struct aciodrv_device_ctx *device);
@ -19,13 +20,15 @@ bool aciodrv_proc_panb_init(struct aciodrv_device_ctx *device);
* Retrieve latest known button state from the PANB device.
*
* @param button_state 28 cell array to store button state
* (mandatory, upon calling the array contains values between 0 to 15 indicating the keys velocity).
* (mandatory, upon calling the array contains values between 0 to 15
* indicating the keys velocity).
* @return True on success, false on error.
*/
bool aciodrv_proc_panb_get_state(uint8_t *button_state);
/**
* Properly terminate the thread and reset the device (this is the only way to stop the auto polling).
* Properly terminate the thread and reset the device (this is the only way to
* stop the auto polling).
*/
void aciodrv_proc_panb_fini(struct aciodrv_device_ctx *device);

View File

@ -87,8 +87,11 @@ static bool aciodrv_device_init(struct aciodrv_device_ctx *device)
}
#ifdef AC_IO_MSG_LOG
static void
aciodrv_device_log_buffer(struct aciodrv_device_ctx *device, const char *msg, const uint8_t *buffer, int length)
static void aciodrv_device_log_buffer(
struct aciodrv_device_ctx *device,
const char *msg,
const uint8_t *buffer,
int length)
{
char str[4096];
@ -97,7 +100,8 @@ aciodrv_device_log_buffer(struct aciodrv_device_ctx *device, const char *msg, co
}
#endif
static bool aciodrv_device_send(struct aciodrv_device_ctx *device, const uint8_t *buffer, int length)
static bool aciodrv_device_send(
struct aciodrv_device_ctx *device, const uint8_t *buffer, int length)
{
uint8_t send_buf[512];
int send_buf_pos = 0;
@ -138,15 +142,20 @@ static bool aciodrv_device_send(struct aciodrv_device_ctx *device, const uint8_t
aciodrv_device_log_buffer(device, "Send (2)", send_buf, send_buf_pos);
#endif
if (aciodrv_port_write(device->fd, send_buf, send_buf_pos) != send_buf_pos) {
log_warning("[%p] Sending data with length %d failed", device->fd, send_buf_pos);
if (aciodrv_port_write(device->fd, send_buf, send_buf_pos) !=
send_buf_pos) {
log_warning(
"[%p] Sending data with length %d failed",
device->fd,
send_buf_pos);
return false;
}
return true;
}
static int aciodrv_device_receive(struct aciodrv_device_ctx *device, uint8_t *buffer, int max_resp_size)
static int aciodrv_device_receive(
struct aciodrv_device_ctx *device, uint8_t *buffer, int max_resp_size)
{
uint8_t recv_buf[512];
int recv_size = 0;
@ -161,7 +170,6 @@ static int aciodrv_device_receive(struct aciodrv_device_ctx *device, uint8_t *bu
read = aciodrv_port_read(device->fd, recv_buf, 1);
} while (recv_buf[0] == AC_IO_SOF);
if (read > 0) {
/* recv_buf[0] is already the first byte of the message.
now read until nothing's left */
@ -189,8 +197,8 @@ static int aciodrv_device_receive(struct aciodrv_device_ctx *device, uint8_t *bu
/* next byte is our real data
overwrite escape byte */
do {
read = aciodrv_port_read(
device->fd, recv_buf + recv_size, 1);
read =
aciodrv_port_read(device->fd, recv_buf + recv_size, 1);
} while (read == 0);
if (read < 0) {
@ -204,7 +212,8 @@ static int aciodrv_device_receive(struct aciodrv_device_ctx *device, uint8_t *bu
if (recv_size > offsetof(struct ac_io_message, cmd.nbytes)) {
// header + data + checksum
expected_size = offsetof(struct ac_io_message, cmd.raw) + ((struct ac_io_message*)recv_buf)->cmd.nbytes + 1;
expected_size = offsetof(struct ac_io_message, cmd.raw) +
((struct ac_io_message *) recv_buf)->cmd.nbytes + 1;
}
}
@ -215,7 +224,11 @@ static int aciodrv_device_receive(struct aciodrv_device_ctx *device, uint8_t *bu
/* recv_size - 1: omit checksum for checksum calc */
if ((recv_size - 1) > max_resp_size) {
log_warning("[%p] Expected %d got %d", device->fd, max_resp_size - 6, recv_buf[4]);
log_warning(
"[%p] Expected %d got %d",
device->fd,
max_resp_size - 6,
recv_buf[4]);
return -1;
}
for (int i = 0; i < recv_size - 1; i++) {
@ -254,9 +267,7 @@ static uint8_t aciodrv_device_enum_nodes(struct aciodrv_device_ctx *device)
msg.cmd.count = 0;
if (!aciodrv_send_and_recv(
device,
&msg,
offsetof(struct ac_io_message, cmd.raw) + 1)) {
device, &msg, offsetof(struct ac_io_message, cmd.raw) + 1)) {
log_warning("Enumerating nodes failed");
return 0;
}
@ -266,7 +277,10 @@ static uint8_t aciodrv_device_enum_nodes(struct aciodrv_device_ctx *device)
return msg.cmd.count;
}
static bool aciodrv_device_get_version(struct aciodrv_device_ctx *device, uint8_t node_id, struct aciodrv_device_node_version *version)
static bool aciodrv_device_get_version(
struct aciodrv_device_ctx *device,
uint8_t node_id,
struct aciodrv_device_node_version *version)
{
struct ac_io_message msg;
@ -299,7 +313,10 @@ static bool aciodrv_device_get_version(struct aciodrv_device_ctx *device, uint8_
msg.cmd.version.date,
msg.cmd.version.time);
memcpy(version->product, msg.cmd.version.product_code, ACIO_NODE_PRODUCT_CODE_LEN);
memcpy(
version->product,
msg.cmd.version.product_code,
ACIO_NODE_PRODUCT_CODE_LEN);
version->type = ac_io_u32(msg.cmd.version.type);
version->major = msg.cmd.version.major;
version->minor = msg.cmd.version.minor;
@ -308,7 +325,8 @@ static bool aciodrv_device_get_version(struct aciodrv_device_ctx *device, uint8_
return true;
}
static bool aciodrv_device_start_node(struct aciodrv_device_ctx *device, uint8_t node_id)
static bool
aciodrv_device_start_node(struct aciodrv_device_ctx *device, uint8_t node_id)
{
struct ac_io_message msg;
@ -317,9 +335,7 @@ static bool aciodrv_device_start_node(struct aciodrv_device_ctx *device, uint8_t
msg.cmd.nbytes = 0;
if (!aciodrv_send_and_recv(
device,
&msg,
offsetof(struct ac_io_message, cmd.raw) + 1)) {
device, &msg, offsetof(struct ac_io_message, cmd.raw) + 1)) {
log_warning("Starting node %d failed", node_id);
return false;
}
@ -334,7 +350,8 @@ struct aciodrv_device_ctx *aciodrv_device_open(const char *port_path, int baud)
return aciodrv_device_open_path(port_path, baud);
}
struct aciodrv_device_ctx *aciodrv_device_open_path(const char *port_path, int baud)
struct aciodrv_device_ctx *
aciodrv_device_open_path(const char *port_path, int baud)
{
HANDLE port = aciodrv_port_open(port_path, baud);
@ -342,7 +359,8 @@ struct aciodrv_device_ctx *aciodrv_device_open_path(const char *port_path, int b
return NULL;
}
struct aciodrv_device_ctx *device = xmalloc(sizeof(struct aciodrv_device_ctx));
struct aciodrv_device_ctx *device =
xmalloc(sizeof(struct aciodrv_device_ctx));
memset(device, 0, sizeof(struct aciodrv_device_ctx));
device->fd = port;
@ -384,16 +402,23 @@ uint8_t aciodrv_device_get_node_count(struct aciodrv_device_ctx *device)
return device->node_count;
}
bool aciodrv_device_get_node_product_ident(struct aciodrv_device_ctx *device, uint8_t node_id, char product[ACIO_NODE_PRODUCT_CODE_LEN])
bool aciodrv_device_get_node_product_ident(
struct aciodrv_device_ctx *device,
uint8_t node_id,
char product[ACIO_NODE_PRODUCT_CODE_LEN])
{
if (device->node_count == 0 || node_id > device->node_count) {
return false;
}
memcpy(product, device->node_versions[node_id].product, ACIO_NODE_PRODUCT_CODE_LEN);
memcpy(
product,
device->node_versions[node_id].product,
ACIO_NODE_PRODUCT_CODE_LEN);
return true;
}
uint32_t aciodrv_device_get_node_product_type(struct aciodrv_device_ctx *device, uint8_t node_id)
uint32_t aciodrv_device_get_node_product_type(
struct aciodrv_device_ctx *device, uint8_t node_id)
{
if (device->node_count == 0 || node_id > device->node_count) {
return 0;
@ -402,7 +427,9 @@ uint32_t aciodrv_device_get_node_product_type(struct aciodrv_device_ctx *device,
return device->node_versions[node_id].type;
}
const struct aciodrv_device_node_version *aciodrv_device_get_node_product_version(struct aciodrv_device_ctx *device, uint8_t node_id)
const struct aciodrv_device_node_version *
aciodrv_device_get_node_product_version(
struct aciodrv_device_ctx *device, uint8_t node_id)
{
if (device->node_count == 0 || node_id > device->node_count) {
return NULL;
@ -430,7 +457,10 @@ bool aciodrv_send(struct aciodrv_device_ctx *device, struct ac_io_message *msg)
return true;
}
bool aciodrv_recv(struct aciodrv_device_ctx *device, struct ac_io_message *msg, int max_resp_size)
bool aciodrv_recv(
struct aciodrv_device_ctx *device,
struct ac_io_message *msg,
int max_resp_size)
{
#ifdef AC_IO_MSG_LOG
log_info("[%p] Beginning recv: (%d b)", device->fd, max_resp_size);
@ -441,7 +471,10 @@ bool aciodrv_recv(struct aciodrv_device_ctx *device, struct ac_io_message *msg,
return true;
}
bool aciodrv_send_and_recv(struct aciodrv_device_ctx *device, struct ac_io_message *msg, int max_resp_size)
bool aciodrv_send_and_recv(
struct aciodrv_device_ctx *device,
struct ac_io_message *msg,
int max_resp_size)
{
if (!aciodrv_send(device, msg)) {
return false;

View File

@ -28,11 +28,13 @@ struct aciodrv_device_node_version {
*/
struct aciodrv_device_ctx *aciodrv_device_open(const char *port_path, int baud)
#ifdef __GNUC__
__attribute__((deprecated("Use aciomgr instead if device is shareable, else aciodrv_device_open_path")))
__attribute__((deprecated("Use aciomgr instead if device is shareable, "
"else aciodrv_device_open_path")))
#endif
;
struct aciodrv_device_ctx *aciodrv_device_open_path(const char *port_path, int baud);
struct aciodrv_device_ctx *
aciodrv_device_open_path(const char *port_path, int baud);
/**
* Get the node count on the opened device.
@ -51,7 +53,10 @@ uint8_t aciodrv_device_get_node_count(struct aciodrv_device_ctx *device);
* @return True on success, false on error. If True the variable product
* contains the identifier of the queried node.
*/
bool aciodrv_device_get_node_product_ident(struct aciodrv_device_ctx *device, uint8_t node_id, char product[ACIO_NODE_PRODUCT_CODE_LEN]);
bool aciodrv_device_get_node_product_ident(
struct aciodrv_device_ctx *device,
uint8_t node_id,
char product[ACIO_NODE_PRODUCT_CODE_LEN]);
/**
* Get the product identifier of an enumerated node.
@ -60,7 +65,8 @@ bool aciodrv_device_get_node_product_ident(struct aciodrv_device_ctx *device, ui
* @param node_id Id of the node. Needs to be in range of the total node count.
* @return product type ID on success, or 0 on failure
*/
uint32_t aciodrv_device_get_node_product_type(struct aciodrv_device_ctx *device, uint8_t node_id);
uint32_t aciodrv_device_get_node_product_type(
struct aciodrv_device_ctx *device, uint8_t node_id);
/**
* Get the product version of an enumerated node.
@ -69,7 +75,9 @@ uint32_t aciodrv_device_get_node_product_type(struct aciodrv_device_ctx *device,
* @param node_id Id of the node. Needs to be in range of the total node count.
* @return Pointer to the version struct
*/
const struct aciodrv_device_node_version *aciodrv_device_get_node_product_version(struct aciodrv_device_ctx *device, uint8_t node_id);
const struct aciodrv_device_node_version *
aciodrv_device_get_node_product_version(
struct aciodrv_device_ctx *device, uint8_t node_id);
/**
* Send a message to the ACIO bus and receive an answer.
@ -82,7 +90,10 @@ const struct aciodrv_device_node_version *aciodrv_device_get_node_product_versio
* @param resp_size Size of the expecting response.
* @return True on success, false on error.
*/
bool aciodrv_send_and_recv(struct aciodrv_device_ctx *device, struct ac_io_message *msg, int max_resp_size);
bool aciodrv_send_and_recv(
struct aciodrv_device_ctx *device,
struct ac_io_message *msg,
int max_resp_size);
/**
* Send a message to the ACIO bus.
@ -90,7 +101,8 @@ bool aciodrv_send_and_recv(struct aciodrv_device_ctx *device, struct ac_io_messa
* @param device Context of opened device
* @param msg Msg to send to the bus.
* @return True on success, false on error.
* @note Prefer the use of aciodrv_send_and_recv when possible. This is for commands which don't trigger a reply.
* @note Prefer the use of aciodrv_send_and_recv when possible. This is for
* commands which don't trigger a reply.
*/
bool aciodrv_send(struct aciodrv_device_ctx *device, struct ac_io_message *msg);
@ -101,9 +113,13 @@ bool aciodrv_send(struct aciodrv_device_ctx *device, struct ac_io_message *msg);
* @param msg Msg to send to the bus. Make sure that the buffer
* is big enough to receive the response.
* @return True on success, false on error.
* @note Prefer the use of aciodrv_send_and_recv when possible. This is for unsollicited incoming messages.
* @note Prefer the use of aciodrv_send_and_recv when possible. This is for
* unsollicited incoming messages.
*/
bool aciodrv_recv(struct aciodrv_device_ctx *device, struct ac_io_message *msg, int max_resp_size);
bool aciodrv_recv(
struct aciodrv_device_ctx *device,
struct ac_io_message *msg,
int max_resp_size);
/**
* Reset an opened device.

View File

@ -9,9 +9,7 @@
#include "util/log.h"
bool aciodrv_h44b_init(
struct aciodrv_device_ctx *device,
uint8_t node_id)
bool aciodrv_h44b_init(struct aciodrv_device_ctx *device, uint8_t node_id)
{
// unlike input devices like KFCA, H44B has no watchdog or special init code
// requirements - shared ACIO node initialisation is enough
@ -34,9 +32,7 @@ bool aciodrv_h44b_lights(
msg.cmd.h44b_output = *lights;
if (!aciodrv_send_and_recv(
device,
&msg,
offsetof(struct ac_io_message, cmd.raw) + 1)) {
device, &msg, offsetof(struct ac_io_message, cmd.raw) + 1)) {
log_warning("Polling of node %d failed", node_id + 1);
return false;
}

View File

@ -1,8 +1,8 @@
#ifndef ACIODRV_H44B_H
#define ACIODRV_H44B_H
#include "aciodrv/device.h"
#include "acio/h44b.h"
#include "aciodrv/device.h"
/**
* Initialize an H44B node.

View File

@ -8,8 +8,7 @@
#include "util/log.h"
static bool aciodrv_icca_queue_loop_start(
struct aciodrv_device_ctx *device,
uint8_t node_id)
struct aciodrv_device_ctx *device, uint8_t node_id)
{
struct ac_io_message msg;
@ -21,9 +20,7 @@ static bool aciodrv_icca_queue_loop_start(
msg.cmd.status = 0;
if (!aciodrv_send_and_recv(
device,
&msg,
offsetof(struct ac_io_message, cmd.raw) + 1)) {
device, &msg, offsetof(struct ac_io_message, cmd.raw) + 1)) {
log_warning("Starting queue loop failed");
return false;
}
@ -137,9 +134,7 @@ bool aciodrv_icca_read_card(
return true;
}
bool aciodrv_icca_is_slotted(
struct aciodrv_device_ctx *device,
uint8_t node_id)
bool aciodrv_icca_is_slotted(struct aciodrv_device_ctx *device, uint8_t node_id)
{
const struct aciodrv_device_node_version *version;
version = aciodrv_device_get_node_product_version(device, node_id);
@ -157,8 +152,7 @@ bool aciodrv_icca_is_slotted(
}
bool aciodrv_icca_poll_felica(
struct aciodrv_device_ctx *device,
uint8_t node_id)
struct aciodrv_device_ctx *device, uint8_t node_id)
{
struct ac_io_message msg;

View File

@ -85,8 +85,7 @@ bool aciodrv_icca_read_card(
* @see driver.h
*/
bool aciodrv_icca_is_slotted(
struct aciodrv_device_ctx *device,
uint8_t node_id);
struct aciodrv_device_ctx *device, uint8_t node_id);
/**
* Polls the felica chip on wavepass readers. This will cause the state of the
@ -105,7 +104,6 @@ bool aciodrv_icca_is_slotted(
* @see driver.h
*/
bool aciodrv_icca_poll_felica(
struct aciodrv_device_ctx *device,
uint8_t node_id);
struct aciodrv_device_ctx *device, uint8_t node_id);
#endif

View File

@ -7,9 +7,8 @@
#include "util/log.h"
static bool aciodrv_kfca_watchdog_start(
struct aciodrv_device_ctx *device,
uint8_t node_id)
static bool
aciodrv_kfca_watchdog_start(struct aciodrv_device_ctx *device, uint8_t node_id)
{
struct ac_io_message msg;
@ -25,11 +24,15 @@ static bool aciodrv_kfca_watchdog_start(
if (!aciodrv_send_and_recv(
device, &msg, offsetof(struct ac_io_message, cmd.raw) + 2)) {
log_warning("Starting watchdog failed"); return false;
log_warning("Starting watchdog failed");
return false;
}
log_warning("Started watchdog of node %d, sz: %d, status: %d",
node_id, msg.cmd.nbytes, msg.cmd.status);
log_warning(
"Started watchdog of node %d, sz: %d, status: %d",
node_id,
msg.cmd.nbytes,
msg.cmd.status);
return true;
}
@ -56,9 +59,7 @@ bool aciodrv_kfca_amp(
msg.cmd.raw[3] = subwoofer;
if (!aciodrv_send_and_recv(
device,
&msg,
offsetof(struct ac_io_message, cmd.raw) + 1)) {
device, &msg, offsetof(struct ac_io_message, cmd.raw) + 1)) {
log_warning("Setting AMP failed");
return false;
}
@ -68,9 +69,7 @@ bool aciodrv_kfca_amp(
return true;
}
bool aciodrv_kfca_init(
struct aciodrv_device_ctx *device,
uint8_t node_id)
bool aciodrv_kfca_init(struct aciodrv_device_ctx *device, uint8_t node_id)
{
log_assert(device);

View File

@ -5,10 +5,11 @@
#include "aciodrv/device.h"
#include "aciodrv/panb.h"
#include "util/thread.h"
#include "util/log.h"
#include "util/thread.h"
bool aciodrv_panb_start_auto_input(struct aciodrv_device_ctx *device, uint8_t node_id, uint8_t node_count)
bool aciodrv_panb_start_auto_input(
struct aciodrv_device_ctx *device, uint8_t node_id, uint8_t node_count)
{
log_assert(device);
struct ac_io_message msg;
@ -33,17 +34,21 @@ bool aciodrv_panb_start_auto_input(struct aciodrv_device_ctx *device, uint8_t no
return true;
}
bool aciodrv_panb_recv_poll(struct aciodrv_device_ctx *device, struct ac_io_panb_poll_in *poll_in)
bool aciodrv_panb_recv_poll(
struct aciodrv_device_ctx *device, struct ac_io_panb_poll_in *poll_in)
{
log_assert(device);
struct ac_io_message msg;
struct ac_io_panb_poll_in *poll_res = (struct ac_io_panb_poll_in *) &msg.cmd.raw;
struct ac_io_panb_poll_in *poll_res =
(struct ac_io_panb_poll_in *) &msg.cmd.raw;
msg.cmd.code = ac_io_u16(AC_IO_CMD_PANB_POLL_REPLY);
msg.cmd.nbytes = sizeof(struct ac_io_panb_poll_in);
if (!aciodrv_recv(device,
&msg, offsetof(struct ac_io_message, cmd.raw) + msg.cmd.nbytes + 1)) {
if (!aciodrv_recv(
device,
&msg,
offsetof(struct ac_io_message, cmd.raw) + msg.cmd.nbytes + 1)) {
log_warning("Getting state failed");
return false;
}
@ -55,8 +60,10 @@ bool aciodrv_panb_recv_poll(struct aciodrv_device_ctx *device, struct ac_io_panb
return true;
}
bool aciodrv_panb_send_lamp(struct aciodrv_device_ctx *device,
uint8_t node_id, struct ac_io_panb_poll_out *state)
bool aciodrv_panb_send_lamp(
struct aciodrv_device_ctx *device,
uint8_t node_id,
struct ac_io_panb_poll_out *state)
{
log_assert(device);
struct ac_io_message msg;

View File

@ -11,33 +11,37 @@
* @param node_count The number of nodes to poll.
* @return True if successful, false on error.
* @note node_id should be 0, PANB internally manages the other nodes.
* @note Upon calling, the device will stop replying to commands and just keep sending
* AC_IO_CMD_PANB_POLL_REPLY messages indefinitely. Failure to retrieve them fast enough
* will cause the device to malfunction. It is thus advised to make use of the aciodrv-proc
* module to spawn a thread that will handle these messages and provide an easy access to the
* latest input state.
* @note This module is supposed to be used in combination with the common
* device driver foundation.
* @see driver.h
*/
bool aciodrv_panb_start_auto_input(struct aciodrv_device_ctx *device, uint8_t node_id, uint8_t node_count);
/**
* Retrieve a AC_IO_CMD_PANB_POLL_REPLY message from a PANB device. This assumes that there
* is such message incoming (ie. that start_auto_input has been called prior).
*
* @param device Context of opened device.
* @param poll_in Buffer to hold the received message, or NULL.
* @return True if successful, false on error.
* @note node_id should be 0, PANB internally manages the other nodes.
* @note Failure to retrieve the incoming messages fast enough will cause the device to malfunction.
* It is thus advised to make use of the aciodrv-proc module to spawn a thread that will handle these
* @note Upon calling, the device will stop replying to commands and just keep
* sending AC_IO_CMD_PANB_POLL_REPLY messages indefinitely. Failure to retrieve
* them fast enough will cause the device to malfunction. It is thus advised to
* make use of the aciodrv-proc module to spawn a thread that will handle these
* messages and provide an easy access to the latest input state.
* @note This module is supposed to be used in combination with the common
* device driver foundation.
* @see driver.h
*/
bool aciodrv_panb_recv_poll(struct aciodrv_device_ctx *device, struct ac_io_panb_poll_in *poll_in);
bool aciodrv_panb_start_auto_input(
struct aciodrv_device_ctx *device, uint8_t node_id, uint8_t node_count);
/**
* Retrieve a AC_IO_CMD_PANB_POLL_REPLY message from a PANB device. This assumes
* that there is such message incoming (ie. that start_auto_input has been
* called prior).
*
* @param device Context of opened device.
* @param poll_in Buffer to hold the received message, or NULL.
* @return True if successful, false on error.
* @note node_id should be 0, PANB internally manages the other nodes.
* @note Failure to retrieve the incoming messages fast enough will cause the
* device to malfunction. It is thus advised to make use of the aciodrv-proc
* module to spawn a thread that will handle these messages and provide an easy
* access to the latest input state.
* @note This module is supposed to be used in combination with the common
* device driver foundation.
* @see driver.h
*/
bool aciodrv_panb_recv_poll(
struct aciodrv_device_ctx *device, struct ac_io_panb_poll_in *poll_in);
/**
* Light lamps on a PANB device.
@ -51,6 +55,9 @@ bool aciodrv_panb_recv_poll(struct aciodrv_device_ctx *device, struct ac_io_panb
* device driver foundation.
* @see driver.h
*/
bool aciodrv_panb_send_lamp(struct aciodrv_device_ctx *device, uint8_t node_id, struct ac_io_panb_poll_out *state);
bool aciodrv_panb_send_lamp(
struct aciodrv_device_ctx *device,
uint8_t node_id,
struct ac_io_panb_poll_out *state);
#endif

View File

@ -148,7 +148,8 @@ int aciodrv_port_write(HANDLE port_fd, const void *bytes, int nbytes)
}
if (!WriteFile(port_fd, bytes, nbytes, &nwrit, NULL)) {
log_warning("[%p] WriteFile failed: err = %lu", port_fd, GetLastError());
log_warning(
"[%p] WriteFile failed: err = %lu", port_fd, GetLastError());
return -1;
}

View File

@ -8,9 +8,7 @@
#include "util/log.h"
static bool aciodrv_rvol_change_expand_mode(
struct aciodrv_device_ctx *device,
uint8_t node_id,
uint8_t mode)
struct aciodrv_device_ctx *device, uint8_t node_id, uint8_t mode)
{
struct ac_io_message msg;
@ -28,15 +26,12 @@ static bool aciodrv_rvol_change_expand_mode(
return false;
}
log_info("I/O expand mode set %d, mode: %d",
node_id, mode);
log_info("I/O expand mode set %d, mode: %d", node_id, mode);
return true;
}
bool aciodrv_rvol_init(
struct aciodrv_device_ctx *device,
uint8_t node_id)
bool aciodrv_rvol_init(struct aciodrv_device_ctx *device, uint8_t node_id)
{
log_assert(device);

View File

@ -267,8 +267,7 @@ static void ac_io_emu_icca_cmd_send_version(
} else {
// probably log invalid version here
log_warning(
"Unknown ICCA version: %d emulation requested",
icca->version);
"Unknown ICCA version: %d emulation requested", icca->version);
}
resp.cmd.version.revision = 0x00;

View File

@ -105,7 +105,6 @@ struct aciomgr_port_dispatcher *aciomgr_port_init(const char *path, int baud)
return NULL;
}
struct aciomgr_port_dispatcher *entry;
EnterCriticalSection(&mgr_cs);

View File

@ -29,7 +29,6 @@ bool aciotest_bi2a_sdvx_handler_update(
return false;
}
pin.raw[0] = ac_io_u16(pin.raw[0]);
pin.raw[1] = ac_io_u16(pin.raw[1]);

View File

@ -5,7 +5,6 @@
#include "aciodrv/icca.h"
#define IDLE_RESPONSES_BETWEEN_FELICA_POLLS 5
struct icca_handler_ctx {

View File

@ -85,8 +85,8 @@ int main(int argc, char **argv)
log_to_writer(log_writer_stdout, NULL);
struct aciodrv_device_ctx *device = aciodrv_device_open_path(argv[1], atoi(argv[2]));
struct aciodrv_device_ctx *device =
aciodrv_device_open_path(argv[1], atoi(argv[2]));
if (!device) {
printf("Opening acio device failed\n");

View File

@ -3,14 +3,15 @@
#include <stdio.h>
#include <stdlib.h>
#include "aciodrv/panb.h"
#include "aciodrv-proc/panb.h"
#include "aciodrv/panb.h"
struct panb_handler_ctx {
bool running;
};
bool aciotest_panb_handler_init(struct aciodrv_device_ctx *device, uint8_t node_id, void **ctx)
bool aciotest_panb_handler_init(
struct aciodrv_device_ctx *device, uint8_t node_id, void **ctx)
{
if (node_id != 0) {
return true;
@ -23,7 +24,8 @@ bool aciotest_panb_handler_init(struct aciodrv_device_ctx *device, uint8_t node_
return aciodrv_proc_panb_init(device);
}
bool aciotest_panb_handler_update(struct aciodrv_device_ctx *device, uint8_t node_id, void *ctx)
bool aciotest_panb_handler_update(
struct aciodrv_device_ctx *device, uint8_t node_id, void *ctx)
{
uint8_t button[AC_IO_PANB_MAX_KEYS];
struct ac_io_panb_poll_out state;

View File

@ -6,7 +6,9 @@
#include "aciodrv/device.h"
bool aciotest_panb_handler_init(struct aciodrv_device_ctx *device, uint8_t node_id, void **ctx);
bool aciotest_panb_handler_update(struct aciodrv_device_ctx *device, uint8_t node_id, void *ctx);
bool aciotest_panb_handler_init(
struct aciodrv_device_ctx *device, uint8_t node_id, void **ctx);
bool aciotest_panb_handler_update(
struct aciodrv_device_ctx *device, uint8_t node_id, void *ctx);
#endif

View File

@ -54,8 +54,7 @@ bool aciotest_rvol_handler_update(
selected_light,
pin.spinners[2] / 2,
pin.spinners[3] / 2,
pin.spinners[4] / 2
);
pin.spinners[4] / 2);
memset(&pout, 0, sizeof(pout));

View File

@ -10,8 +10,7 @@
#define ASIOHOOK_CONFIG_IO_DEFAULT_FORCE_ASIO_VALUE false
#define ASIOHOOK_CONFIG_IO_DEFAULT_FORCE_WASAPI_VALUE false
#define ASIOHOOK_CONFIG_IO_DEFAULT_ASIO_DEVICE_NAME_VALUE \
"XONAR SOUND CARD(64)"
#define ASIOHOOK_CONFIG_IO_DEFAULT_ASIO_DEVICE_NAME_VALUE "XONAR SOUND CARD(64)"
void asiohook_config_init(struct cconfig *config)
{

View File

@ -105,7 +105,6 @@ bool ddr_io_init(
thread_join_t thread_join,
thread_destroy_t thread_destroy);
/* used to poll the IO for input, note that this is also where lights are
flushed to the device for geninput */
uint32_t ddr_io_read_pad(void);

View File

@ -70,7 +70,8 @@ enum iidx_io_panel_light {
IIDX_IO_PANEL_LIGHT_EFFECT = 3,
};
/* Bit mapping for the top lamps from left to right when facing cabinet screen */
/* Bit mapping for the top lamps from left to right when facing cabinet screen
*/
enum iidx_io_top_lamp {
IIDX_IO_TOP_LAMP_LEFT_BLUE = 0,

View File

@ -106,7 +106,8 @@ void jb_io_set_rgb_led(
bool jb_io_write_lights(void);
/* Select operating mode for the panel. Should be immediately sent to the IOPCB */
/* Select operating mode for the panel. Should be immediately sent to the IOPCB
*/
bool jb_io_set_panel_mode(enum jb_io_panel_mode mode);

View File

@ -103,8 +103,6 @@ uint16_t sdvx_io_get_spinner_pos(uint8_t spinner_no);
Range is between 0-96, where 0 is MAX and 96 is LOW. */
bool sdvx_io_set_amp_volume(
uint8_t primary,
uint8_t headphone,
uint8_t subwoofer);
uint8_t primary, uint8_t headphone, uint8_t subwoofer);
#endif

View File

@ -14,9 +14,8 @@
// in all inputs and outputs (over sub IO) other than 14 keys to not work.
static const uint8_t _BIO2DR_BI2A_IIDX_INIT_DATA = 0x2D;
static bool bio2drv_bi2a_iidx_init_io(
struct aciodrv_device_ctx *device,
uint8_t node_id)
static bool
bio2drv_bi2a_iidx_init_io(struct aciodrv_device_ctx *device, uint8_t node_id)
{
struct ac_io_message msg;
@ -28,9 +27,7 @@ static bool bio2drv_bi2a_iidx_init_io(
msg.cmd.param = _BIO2DR_BI2A_IIDX_INIT_DATA;
if (!aciodrv_send_and_recv(
device,
&msg,
offsetof(struct ac_io_message, cmd.raw) + 1)) {
device, &msg, offsetof(struct ac_io_message, cmd.raw) + 1)) {
log_warning("Init node failed");
return 0;
}
@ -41,8 +38,7 @@ static bool bio2drv_bi2a_iidx_init_io(
}
static bool bio2drv_bi2a_iidx_watchdog_start(
struct aciodrv_device_ctx *device,
uint8_t node_id)
struct aciodrv_device_ctx *device, uint8_t node_id)
{
log_assert(device);

View File

@ -15,9 +15,7 @@
* device driver foundation.
* @see driver.h
*/
bool bio2drv_bi2a_iidx_init(
struct aciodrv_device_ctx *device,
uint8_t node_id);
bool bio2drv_bi2a_iidx_init(struct aciodrv_device_ctx *device, uint8_t node_id);
/**
* Poll the BI2A board

View File

@ -12,7 +12,8 @@
static const uint8_t _BIO2DR_BI2A_SDVX_INIT_DATA = 0x3B;
// this is probably InitIO
static bool bio2drv_bi2a_sdvx_init_io(struct aciodrv_device_ctx *device, uint8_t node_id)
static bool
bio2drv_bi2a_sdvx_init_io(struct aciodrv_device_ctx *device, uint8_t node_id)
{
struct ac_io_message msg;
@ -24,9 +25,7 @@ static bool bio2drv_bi2a_sdvx_init_io(struct aciodrv_device_ctx *device, uint8_t
msg.cmd.param = _BIO2DR_BI2A_SDVX_INIT_DATA;
if (!aciodrv_send_and_recv(
device,
&msg,
offsetof(struct ac_io_message, cmd.raw) + 1)) {
device, &msg, offsetof(struct ac_io_message, cmd.raw) + 1)) {
log_warning("Init node failed");
return 0;
}
@ -36,7 +35,8 @@ static bool bio2drv_bi2a_sdvx_init_io(struct aciodrv_device_ctx *device, uint8_t
return 1;
}
static bool bio2drv_bi2a_sdvx_watchdog_start(struct aciodrv_device_ctx *device, uint8_t node_id)
static bool bio2drv_bi2a_sdvx_watchdog_start(
struct aciodrv_device_ctx *device, uint8_t node_id)
{
log_assert(device);
@ -95,9 +95,7 @@ bool bio2drv_bi2a_sdvx_amp(
msg.cmd.raw[3] = right;
if (!aciodrv_send_and_recv(
device,
&msg,
offsetof(struct ac_io_message, cmd.raw) + 1)) {
device, &msg, offsetof(struct ac_io_message, cmd.raw) + 1)) {
log_warning("Setting AMP failed");
return false;
}

View File

@ -15,9 +15,7 @@
* device driver foundation.
* @see driver.h
*/
bool bio2drv_bi2a_sdvx_init(
struct aciodrv_device_ctx *device,
uint8_t node_id);
bool bio2drv_bi2a_sdvx_init(struct aciodrv_device_ctx *device, uint8_t node_id);
/**
* Poll the board

View File

@ -50,10 +50,10 @@ static bool check_property(
return false;
}
static bool check_id(
HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA PDeviceInfoData)
static bool check_id(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA PDeviceInfoData)
{
if (CM_Get_Device_IDA(PDeviceInfoData->DevInst, work_buffer, sizeof(work_buffer), 0)) {
if (CM_Get_Device_IDA(
PDeviceInfoData->DevInst, work_buffer, sizeof(work_buffer), 0)) {
return false;
}

View File

@ -175,7 +175,8 @@ static void bio2_emu_bi2a_send_status(
ac_io_emu_response_push(emu, &resp, 0);
}
static int16_t tt_mult_delta(size_t tt_no) {
static int16_t tt_mult_delta(size_t tt_no)
{
int16_t current_tt = iidx_io_ep2_get_turntable(tt_no);
int16_t delta = get_wrapped_delta_s16(current_tt, tt_last[tt_no], 256);

View File

@ -382,8 +382,8 @@ static INT_PTR lights_handle_pulse_tick(HWND hwnd)
}
bias = (float) (ui->lights[light_no].value_min);
scale =
(float) (ui->lights[light_no].value_max - ui->lights[light_no].value_min);
scale = (float) (ui->lights[light_no].value_max -
ui->lights[light_no].value_min);
/* Intensity perception is non-linear. Pulse quadratically. */

View File

@ -18,8 +18,10 @@
#define D3D9EXHOOK_CONFIG_GFX_FORCED_REFRESHRATE_KEY "gfx.forced_refresh_rate"
#define D3D9EXHOOK_CONFIG_GFX_DEVICE_ADAPTER_KEY "gfx.device_adapter"
#define D3D9EXHOOK_CONFIG_GFX_FORCE_ORIENTATION_KEY "gfx.force_orientation"
#define D3D9EXHOOK_CONFIG_GFX_FORCE_SCREEN_RES_WIDTH_KEY "gfx.force_screen_res.width"
#define D3D9EXHOOK_CONFIG_GFX_FORCE_SCREEN_RES_HEIGHT_KEY "gfx.force_screen_res.height"
#define D3D9EXHOOK_CONFIG_GFX_FORCE_SCREEN_RES_WIDTH_KEY \
"gfx.force_screen_res.width"
#define D3D9EXHOOK_CONFIG_GFX_FORCE_SCREEN_RES_HEIGHT_KEY \
"gfx.force_screen_res.height"
#define D3D9EXHOOK_CONFIG_GFX_DEFAULT_FRAMED_VALUE false
#define D3D9EXHOOK_CONFIG_GFX_DEFAULT_WINDOWED_VALUE false
@ -103,15 +105,19 @@ void d3d9exhook_config_gfx_init(struct cconfig *config)
config,
D3D9EXHOOK_CONFIG_GFX_FORCE_SCREEN_RES_WIDTH_KEY,
D3D9EXHOOK_CONFIG_GFX_DEFAULT_FORCE_SCREEN_RES_WIDTH_VALUE,
"Force a screen resolution (width), -1 to disable. Use this if the game does not auto "
"detect your monitor's resolution properly, e.g. 1368x768 instead of 1280x720.");
"Force a screen resolution (width), -1 to disable. Use this if the "
"game does not auto "
"detect your monitor's resolution properly, e.g. 1368x768 instead of "
"1280x720.");
cconfig_util_set_int(
config,
D3D9EXHOOK_CONFIG_GFX_FORCE_SCREEN_RES_HEIGHT_KEY,
D3D9EXHOOK_CONFIG_GFX_DEFAULT_FORCE_SCREEN_RES_HEIGHT_VALUE,
"Force a screen resolution (height), -1 to disable. Use this if the game does not auto "
"detect your monitor's resolution properly, e.g. 1368x768 instead of 1280x720.");
"Force a screen resolution (height), -1 to disable. Use this if the "
"game does not auto "
"detect your monitor's resolution properly, e.g. 1368x768 instead of "
"1280x720.");
}
void d3d9exhook_config_gfx_get(

View File

@ -52,10 +52,8 @@ static HRESULT STDCALL my_EnumAdapterModes(
UINT Mode,
D3DDISPLAYMODE *pMode);
static UINT STDCALL my_GetAdapterModeCount(
IDirect3D9Ex *self,
UINT Adapter,
D3DFORMAT Format);
static UINT STDCALL
my_GetAdapterModeCount(IDirect3D9Ex *self, UINT Adapter, D3DFORMAT Format);
static HRESULT STDCALL my_Direct3DCreate9Ex(UINT sdk_ver, IDirect3D9Ex **api);
@ -305,7 +303,8 @@ static HRESULT STDCALL my_CreateDeviceEx(
if (fdm) {
log_misc(
"CreateDeviceEx display mode: size %d, width %d, height %d, refresh rate %d, format %d, "
"CreateDeviceEx display mode: size %d, width %d, height %d, "
"refresh rate %d, format %d, "
"scan line ordering %d",
fdm->Size,
fdm->Width,
@ -318,7 +317,8 @@ static HRESULT STDCALL my_CreateDeviceEx(
log_misc(
"D3D9EX presenter parameters: BackBufferWidth %d, BackBufferHeight "
"%d, BackBufferFormat %d, "
"BackBufferCount %d, MultiSampleType %d, MultiSampleQuality %ld, SwapEffect %d, "
"BackBufferCount %d, MultiSampleType %d, MultiSampleQuality %ld, "
"SwapEffect %d, "
"hDeviceWindow %p, Windowed %d, "
"EnableAutoDepthStencil "
"%d, AutoDepthStencilFormat %d, Flags %lX, "
@ -343,8 +343,10 @@ static HRESULT STDCALL my_CreateDeviceEx(
adapter = d3d9ex_device_adapter;
}
if (d3d9ex_force_screen_res_width > 0 && d3d9ex_force_screen_res_height > 0) {
log_info("Overriding screen resolution/back buffer of %dx%d -> %dx%d",
if (d3d9ex_force_screen_res_width > 0 &&
d3d9ex_force_screen_res_height > 0) {
log_info(
"Overriding screen resolution/back buffer of %dx%d -> %dx%d",
pp->BackBufferWidth,
pp->BackBufferHeight,
d3d9ex_force_screen_res_width,
@ -461,10 +463,8 @@ static HRESULT STDCALL my_EnumAdapterModes(
return hr;
}
static UINT STDCALL my_GetAdapterModeCount(
IDirect3D9Ex *self,
UINT Adapter,
D3DFORMAT Format)
static UINT STDCALL
my_GetAdapterModeCount(IDirect3D9Ex *self, UINT Adapter, D3DFORMAT Format)
{
IDirect3D9Ex *real = com_proxy_downcast(self)->real;
UINT res;
@ -555,7 +555,8 @@ void d3d9ex_configure(struct d3d9exhook_config_gfx *gfx_config)
d3d9ex_force_screen_res_height = gfx_config->force_screen_res.height;
if (d3d9ex_force_screen_res_width * d3d9ex_force_screen_res_height > 0) {
log_warning("Force screen res: Only one, either width or height, is > 0."
log_warning(
"Force screen res: Only one, either width or height, is > 0."
" Force screen res not activate");
}
}

View File

@ -34,9 +34,7 @@ static struct ac_io_emu_hdxs com4_hdxs;
static struct ac_io_emu_icca com4_icca[2];
static uint32_t check_panel_light(
const struct ac_io_hdxs_output *output,
uint8_t panel_idx,
uint8_t out_idx)
const struct ac_io_hdxs_output *output, uint8_t panel_idx, uint8_t out_idx)
{
if (output->lights[panel_idx].bit) {
return 1 << out_idx;
@ -45,7 +43,8 @@ static uint32_t check_panel_light(
}
}
static uint8_t upscale_light(uint8_t in_7bit) {
static uint8_t upscale_light(uint8_t in_7bit)
{
if (in_7bit < 0x10) {
return in_7bit * 2;
} else {
@ -54,18 +53,24 @@ static uint8_t upscale_light(uint8_t in_7bit) {
}
}
static void lights_dispatcher(
struct ac_io_emu_hdxs *emu, const struct ac_io_message *req)
static void
lights_dispatcher(struct ac_io_emu_hdxs *emu, const struct ac_io_message *req)
{
const struct ac_io_hdxs_output *output = &req->cmd.hdxs_output;
uint32_t lights = 0;
lights |= check_panel_light(output, AC_IO_HDXS_OUT_P1_START, LIGHT_HD_P1_START);
lights |= check_panel_light(output, AC_IO_HDXS_OUT_P1_UP_DOWN, LIGHT_HD_P1_UP_DOWN);
lights |= check_panel_light(output, AC_IO_HDXS_OUT_P1_LEFT_RIGHT, LIGHT_HD_P1_LEFT_RIGHT);
lights |= check_panel_light(output, AC_IO_HDXS_OUT_P2_START, LIGHT_HD_P2_START);
lights |= check_panel_light(output, AC_IO_HDXS_OUT_P2_UP_DOWN, LIGHT_HD_P2_UP_DOWN);
lights |= check_panel_light(output, AC_IO_HDXS_OUT_P2_LEFT_RIGHT, LIGHT_HD_P2_LEFT_RIGHT);
lights |=
check_panel_light(output, AC_IO_HDXS_OUT_P1_START, LIGHT_HD_P1_START);
lights |= check_panel_light(
output, AC_IO_HDXS_OUT_P1_UP_DOWN, LIGHT_HD_P1_UP_DOWN);
lights |= check_panel_light(
output, AC_IO_HDXS_OUT_P1_LEFT_RIGHT, LIGHT_HD_P1_LEFT_RIGHT);
lights |=
check_panel_light(output, AC_IO_HDXS_OUT_P2_START, LIGHT_HD_P2_START);
lights |= check_panel_light(
output, AC_IO_HDXS_OUT_P2_UP_DOWN, LIGHT_HD_P2_UP_DOWN);
lights |= check_panel_light(
output, AC_IO_HDXS_OUT_P2_LEFT_RIGHT, LIGHT_HD_P2_LEFT_RIGHT);
ddr_io_set_lights_hdxs_panel(lights);
@ -73,9 +78,12 @@ static void lights_dispatcher(
size_t light_idx = i * 3;
// these are 7 bit, upscale them to 8 bit
uint8_t r = upscale_light(output->lights[light_idx + AC_IO_HDXS_RED].analog);
uint8_t g = upscale_light(output->lights[light_idx + AC_IO_HDXS_GREEN].analog);
uint8_t b = upscale_light(output->lights[light_idx + AC_IO_HDXS_BLUE].analog);
uint8_t r =
upscale_light(output->lights[light_idx + AC_IO_HDXS_RED].analog);
uint8_t g =
upscale_light(output->lights[light_idx + AC_IO_HDXS_GREEN].analog);
uint8_t b =
upscale_light(output->lights[light_idx + AC_IO_HDXS_BLUE].analog);
ddr_io_set_lights_hdxs_rgb(i, r, g, b);
}

View File

@ -185,8 +185,7 @@ static void gfx_d3d9_patch_window(struct hook_d3d9_irp *irp)
}
}
static void
gfx_d3d9_fix_window_size_and_pos(struct hook_d3d9_irp *irp)
static void gfx_d3d9_fix_window_size_and_pos(struct hook_d3d9_irp *irp)
{
log_assert(irp);
log_assert(irp->op == HOOK_D3D9_IRP_OP_CREATE_WINDOW_EX);
@ -215,8 +214,7 @@ gfx_d3d9_fix_window_size_and_pos(struct hook_d3d9_irp *irp)
}
}
static void gfx_d3d9_create_device_apply_window_mode(
struct hook_d3d9_irp *irp)
static void gfx_d3d9_create_device_apply_window_mode(struct hook_d3d9_irp *irp)
{
log_assert(irp);
log_assert(irp->op == HOOK_D3D9_IRP_OP_CTX_CREATE_DEVICE);
@ -231,8 +229,7 @@ static void gfx_d3d9_create_device_apply_window_mode(
}
}
static void gfx_d3d9_reset_apply_window_mode(
struct hook_d3d9_irp *irp)
static void gfx_d3d9_reset_apply_window_mode(struct hook_d3d9_irp *irp)
{
log_assert(irp);
log_assert(irp->op == HOOK_D3D9_IRP_OP_DEV_RESET);

View File

@ -64,8 +64,14 @@ void p3io_ddr_init_with_plugs(
memcpy(&p3io_ddr_mcode, mcode, sizeof(struct security_mcode));
memcpy(&p3io_ddr_pcbid, pcbid, sizeof(struct security_id));
memcpy(&p3io_ddr_eamid, eamid, sizeof(struct security_id));
memcpy(&p3io_black_sign_key, black_sign_key, sizeof(struct security_rp_sign_key));
memcpy(&p3io_white_sign_key, white_sign_key, sizeof(struct security_rp_sign_key));
memcpy(
&p3io_black_sign_key,
black_sign_key,
sizeof(struct security_rp_sign_key));
memcpy(
&p3io_white_sign_key,
white_sign_key,
sizeof(struct security_rp_sign_key));
/* COM4 isn't a real COM port, we configure the core P3IO emulator code to
generate IRPs addressed to COM4 and then we possibly intercept them in

View File

@ -15,9 +15,9 @@
#include "hook/iohook.h"
#include "util/crc.h"
#include "util/fs.h"
#include "util/iobuf.h"
#include "util/log.h"
#include "util/fs.h"
#include "util/str.h"
#define USBMEM_DEVICE_COUNT 2
@ -95,7 +95,8 @@ void usbmem_init(const char *path_p1, const char *path_p2, const bool enabled)
GetFullPathNameA(path_p2, sizeof(usb_data_path[1]), usb_data_path[1], NULL);
log_misc("USB memory data path (P2): %s", usb_data_path[1]);
if (enabled && !path_exists(usb_data_path[0]) && !path_exists(usb_data_path[1])) {
if (enabled && !path_exists(usb_data_path[0]) &&
!path_exists(usb_data_path[1])) {
log_warning("USB memory data path does not exist, disabling");
usbmem_enabled = false;
}
@ -177,16 +178,22 @@ static HRESULT usbmem_write(struct irp *irp)
log_assert(irp->write.bytes != NULL);
src = &irp->write;
nbytes = src->nbytes > USBMEM_COMMAND_BUF_SIZE ? USBMEM_COMMAND_BUF_SIZE : src->nbytes;
nbytes = src->nbytes > USBMEM_COMMAND_BUF_SIZE ? USBMEM_COMMAND_BUF_SIZE :
src->nbytes;
memcpy(request, src->bytes, nbytes);
request[nbytes - 1] = '\0'; /* This is always a CR. */
if (!usbmem_pending && target_device_id >= 0 && target_device_id < USBMEM_DEVICE_COUNT && usbmem_state[target_device_id].file_type == USBMEM_FILE_TYPE_READ) {
if (!usbmem_pending && target_device_id >= 0 &&
target_device_id < USBMEM_DEVICE_COUNT &&
usbmem_state[target_device_id].file_type == USBMEM_FILE_TYPE_READ) {
memset(usbmem_response, 0, sizeof(usbmem_response));
// log_misc("Read progress %08x/%08x bytes", usbmem_state[target_device_id].buffer_index, usbmem_state[target_device_id].buffer_len);
// log_misc("Read progress %08x/%08x bytes",
// usbmem_state[target_device_id].buffer_index,
// usbmem_state[target_device_id].buffer_len);
if (usbmem_state[target_device_id].buffer_index < usbmem_state[target_device_id].buffer_len) {
if (usbmem_state[target_device_id].buffer_index <
usbmem_state[target_device_id].buffer_len) {
usbmem_response_length = sizeof(usbmem_response);
usbmem_response[0] = 0x02; // 1 = 0x80 buffer, 2 = 0x400 buffer
usbmem_response[1] = usbmem_state[target_device_id].buffer_frame;
@ -201,16 +208,23 @@ static HRESULT usbmem_write(struct irp *irp)
} else {
size_t len = sizeof(usbmem_response) - 5;
if (usbmem_state[target_device_id].buffer_index + len > usbmem_state[target_device_id].buffer_len)
len = usbmem_state[target_device_id].buffer_len - usbmem_state[target_device_id].buffer_index;
if (usbmem_state[target_device_id].buffer_index + len >
usbmem_state[target_device_id].buffer_len)
len = usbmem_state[target_device_id].buffer_len -
usbmem_state[target_device_id].buffer_index;
memcpy(usbmem_response + 3, usbmem_state[target_device_id].buffer + usbmem_state[target_device_id].buffer_index, len);
memcpy(
usbmem_response + 3,
usbmem_state[target_device_id].buffer +
usbmem_state[target_device_id].buffer_index,
len);
usbmem_state[target_device_id].buffer_index += len;
}
usbmem_state[target_device_id].buffer_frame++;
uint16_t crc = crc16_msb(usbmem_response + 3, sizeof(usbmem_response) - 5, 0);
uint16_t crc =
crc16_msb(usbmem_response + 3, sizeof(usbmem_response) - 5, 0);
usbmem_response[sizeof(usbmem_response) - 2] = crc >> 8;
usbmem_response[sizeof(usbmem_response) - 1] = crc & 0xff;
} else {
@ -221,7 +235,8 @@ static HRESULT usbmem_write(struct irp *irp)
log_misc(">%s", request);
// Try to detect device ID
// The only commands without a device ID are "sver", "start", and "init".
// The only commands without a device ID are "sver", "start", and
// "init".
char target_device_val = request[strlen(request) - 1];
char *target_device_id_ptr = strstr(request, " ");
if (target_device_id_ptr != NULL) {
@ -241,18 +256,22 @@ static HRESULT usbmem_write(struct irp *irp)
target_device_id = target_device_val == 'b' ? 0 : 1;
if (!usbmem_enabled) {
// Ignore all other USB device specific commands and pretend a device isn't plugged in
// when USB memory emulation is disabled.
// Ignore all other USB device specific commands and pretend a
// device isn't plugged in when USB memory emulation is
// disabled.
str_cpy(usbmem_response, sizeof(usbmem_response), "fail");
} else if (usbmem_state[target_device_id].errored) {
// If the device went through the entire process once and the file didn't exist
// then just force it to be disabled until the game is restarted because otherwise
// it'll get stuck in a loop.
// TODO: This could be better emulated by using a keybind to simulate inserting and
// ejecting the USB drive to additionally clear the error flag.
// If the device went through the entire process once and the
// file didn't exist then just force it to be disabled until the
// game is restarted because otherwise it'll get stuck in a
// loop.
// TODO: This could be better emulated by using a keybind to
// simulate inserting and ejecting the USB drive to additionally
// clear the error flag.
str_cpy(usbmem_response, sizeof(usbmem_response), "fail");
} else if (str_eq(request, "on_a") || str_eq(request, "on_b")) {
usbmem_state[target_device_id].connected = path_exists(usbmem_state[target_device_id].basepath);
usbmem_state[target_device_id].connected =
path_exists(usbmem_state[target_device_id].basepath);
usbmem_state[target_device_id].errored = false;
usbmem_reset_file_state(target_device_id);
@ -260,21 +279,32 @@ static HRESULT usbmem_write(struct irp *irp)
if (usbmem_state[target_device_id].connected)
str_cpy(usbmem_response, sizeof(usbmem_response), "done");
else
str_cpy(usbmem_response, sizeof(usbmem_response), "not connected");
str_cpy(
usbmem_response,
sizeof(usbmem_response),
"not connected");
} else if (str_eq(request, "offa") || str_eq(request, "offb")) {
if (usbmem_state[target_device_id].connected)
str_cpy(usbmem_response, sizeof(usbmem_response), "done");
else
str_cpy(usbmem_response, sizeof(usbmem_response), "not connected");
str_cpy(
usbmem_response,
sizeof(usbmem_response),
"not connected");
usbmem_state[target_device_id].connected = false;
usbmem_reset_file_state(target_device_id);
} else if (str_eq(request, "opna") || str_eq(request, "opnb")) {
bool basepath_exists = path_exists(usbmem_state[target_device_id].basepath);
bool basepath_exists =
path_exists(usbmem_state[target_device_id].basepath);
if (!usbmem_state[target_device_id].connected || !basepath_exists) {
if (!usbmem_state[target_device_id].connected ||
!basepath_exists) {
usbmem_state[target_device_id].opened = false;
str_cpy(usbmem_response, sizeof(usbmem_response), "not connected");
str_cpy(
usbmem_response,
sizeof(usbmem_response),
"not connected");
} else {
usbmem_state[target_device_id].opened = true;
str_cpy(usbmem_response, sizeof(usbmem_response), "done");
@ -283,82 +313,132 @@ static HRESULT usbmem_write(struct irp *irp)
if (usbmem_state[target_device_id].opened)
str_cpy(usbmem_response, sizeof(usbmem_response), "done");
else
str_cpy(usbmem_response, sizeof(usbmem_response), "not connected");
str_cpy(
usbmem_response,
sizeof(usbmem_response),
"not connected");
usbmem_state[target_device_id].opened = false;
usbmem_reset_file_state(target_device_id);
} else if (strncmp(request, "cda ", 4) == 0 || strncmp(request, "cdb ", 4) == 0) {
} else if (
strncmp(request, "cda ", 4) == 0 ||
strncmp(request, "cdb ", 4) == 0) {
char *path = request + 4;
if (!usbmem_state[target_device_id].connected || !usbmem_state[target_device_id].opened) {
if (!usbmem_state[target_device_id].connected ||
!usbmem_state[target_device_id].opened) {
str_cpy(usbmem_response, sizeof(usbmem_response), "done");
} else if (path[1] == ':') {
// Absolute path
char temp[MAX_PATH];
snprintf(temp, sizeof(temp), "%s\\%s", usbmem_state[target_device_id].basepath, path + 3);
snprintf(
temp,
sizeof(temp),
"%s\\%s",
usbmem_state[target_device_id].basepath,
path + 3);
if (!path_exists(temp)) {
log_warning("Couldn't find path %s", temp);
str_cpy(usbmem_response, sizeof(usbmem_response), "done");
str_cpy(
usbmem_response, sizeof(usbmem_response), "done");
} else {
log_misc("Changing path to %s", temp);
str_cpy(usbmem_state[target_device_id].path, sizeof(usbmem_state[target_device_id].path), temp);
str_cpy(usbmem_response, sizeof(usbmem_response), "done");
str_cpy(
usbmem_state[target_device_id].path,
sizeof(usbmem_state[target_device_id].path),
temp);
str_cpy(
usbmem_response, sizeof(usbmem_response), "done");
}
} else {
str_cpy(usbmem_response, sizeof(usbmem_response), "fail");
}
} else if (strncmp(request, "rda ", 4) == 0 || strncmp(request, "rdb ", 4) == 0) {
} else if (
strncmp(request, "rda ", 4) == 0 ||
strncmp(request, "rdb ", 4) == 0) {
usbmem_reset_file_state(target_device_id);
if (!usbmem_state[target_device_id].connected || !usbmem_state[target_device_id].opened) {
if (!usbmem_state[target_device_id].connected ||
!usbmem_state[target_device_id].opened) {
str_cpy(usbmem_response, sizeof(usbmem_response), "fail");
} else {
char temp[MAX_PATH] = {0};
char *filename = request + 4;
snprintf(temp, sizeof(temp), "%s\\%s", usbmem_state[target_device_id].path, filename);
snprintf(
temp,
sizeof(temp),
"%s\\%s",
usbmem_state[target_device_id].path,
filename);
if (usbmem_state[target_device_id].buffer) {
free(usbmem_state[target_device_id].buffer);
usbmem_state[target_device_id].buffer = NULL;
}
usbmem_state[target_device_id].file_type = USBMEM_FILE_TYPE_NONE;
usbmem_state[target_device_id].file_type =
USBMEM_FILE_TYPE_NONE;
usbmem_state[target_device_id].buffer_len = 0;
usbmem_state[target_device_id].buffer_index = 0;
usbmem_state[target_device_id].buffer_frame = 0;
memset(usbmem_state[target_device_id].filename, 0, sizeof(usbmem_state[target_device_id].filename));
memset(
usbmem_state[target_device_id].filename,
0,
sizeof(usbmem_state[target_device_id].filename));
if (!path_exists(temp)) {
log_warning("Couldn't find file %s", temp);
str_cpy(usbmem_response, sizeof(usbmem_response), "fail");
str_cpy(
usbmem_response, sizeof(usbmem_response), "fail");
usbmem_state[target_device_id].errored = true;
} else {
bool loaded = file_load(temp, (void**)&usbmem_state[target_device_id].buffer,
&usbmem_state[target_device_id].buffer_len, false);
bool loaded = file_load(
temp,
(void **) &usbmem_state[target_device_id].buffer,
&usbmem_state[target_device_id].buffer_len,
false);
if (loaded) {
log_misc("Reading file %s", temp);
usbmem_state[target_device_id].file_type = USBMEM_FILE_TYPE_READ;
usbmem_state[target_device_id].file_type =
USBMEM_FILE_TYPE_READ;
str_cpy(usbmem_state[target_device_id].filename, sizeof(usbmem_state[target_device_id].filename), filename);
str_cpy(usbmem_response, sizeof(usbmem_response), "start");
str_cpy(
usbmem_state[target_device_id].filename,
sizeof(usbmem_state[target_device_id].filename),
filename);
str_cpy(
usbmem_response,
sizeof(usbmem_response),
"start");
} else {
log_warning("Couldn't read file %s", temp);
str_cpy(usbmem_response, sizeof(usbmem_response), "fail");
str_cpy(
usbmem_response,
sizeof(usbmem_response),
"fail");
usbmem_state[target_device_id].errored = true;
}
}
}
} else if (strncmp(request, "wra ", 4) == 0 || strncmp(request, "wrb ", 4) == 0) {
} else if (
strncmp(request, "wra ", 4) == 0 ||
strncmp(request, "wrb ", 4) == 0) {
// Open file for writing
usbmem_reset_file_state(target_device_id);
str_cpy(usbmem_response, sizeof(usbmem_response), "not supported");
} else if (strncmp(request, "wha ", 4) == 0 || strncmp(request, "whb ", 4) == 0) {
str_cpy(
usbmem_response, sizeof(usbmem_response), "not supported");
} else if (
strncmp(request, "wha ", 4) == 0 ||
strncmp(request, "whb ", 4) == 0) {
// Something relating to writing?
str_cpy(usbmem_response, sizeof(usbmem_response), "not supported");
} else if (strncmp(request, "lma ", 4) == 0 || strncmp(request, "lmb ", 4) == 0) {
str_cpy(
usbmem_response, sizeof(usbmem_response), "not supported");
} else if (
strncmp(request, "lma ", 4) == 0 ||
strncmp(request, "lmb ", 4) == 0) {
// What is "lm"?
str_cpy(usbmem_response, sizeof(usbmem_response), "done");
} else {

View File

@ -84,8 +84,9 @@ static void my_avs_boot(
char nvram_path[MAX_PATH] = {0};
char raw_path[MAX_PATH] = {0};
// Using the full path as part of the AVS paths seems to break on long paths.
// So instead, just take the launcher folder relative to the main game directory.
// Using the full path as part of the AVS paths seems to break on long
// paths. So instead, just take the launcher folder relative to the main
// game directory.
char *launcher_folder;
ddrhook1_get_launcher_path_parts(NULL, &launcher_folder);
@ -104,10 +105,8 @@ static void my_avs_boot(
log_misc("avs paths: %s %s\n", nvram_path, raw_path);
avs_boot_replace_property_str(
config, "/fs/nvram/device", nvram_path);
avs_boot_replace_property_str(
config, "/fs/raw/device", raw_path);
avs_boot_replace_property_str(config, "/fs/nvram/device", nvram_path);
avs_boot_replace_property_str(config, "/fs/raw/device", raw_path);
#endif
real_avs_boot(

View File

@ -26,7 +26,8 @@ void ddrhook1_config_ddrhook1_init(struct cconfig *config)
config,
DDRHOOK1_CONFIG_DDRHOOK1_USE_COM4_EMU_KEY,
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USE_COM4_EMU_VALUE,
"Don't emulate P3IO COM4 and its downstream devices, use the Windows COM4 port instead");
"Don't emulate P3IO COM4 and its downstream devices, use the Windows "
"COM4 port instead");
cconfig_util_set_bool(
config,
DDRHOOK1_CONFIG_DDRHOOK1_STANDARD_DEF_KEY,

View File

@ -41,8 +41,7 @@ void ddrhook1_config_security_get(
char *tmp_default;
char mcode[9];
tmp_default =
security_mcode_to_str(&security_mcode_ddr_x);
tmp_default = security_mcode_to_str(&security_mcode_ddr_x);
if (!cconfig_util_get_str(
config,

View File

@ -53,8 +53,10 @@ static const hook_d3d9_irp_handler_t ddrhook1_d3d9_handlers[] = {
gfx_d3d9_irp_handler,
};
static DWORD STDCALL my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize);
static DWORD(STDCALL *real_GetModuleFileNameA)(HMODULE hModule, LPSTR lpFilename, DWORD nSize);
static DWORD STDCALL
my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize);
static DWORD(STDCALL *real_GetModuleFileNameA)(
HMODULE hModule, LPSTR lpFilename, DWORD nSize);
static bool ddrhook1_init_check = false;
@ -144,7 +146,9 @@ my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
#endif
&security_rp_sign_key_white_eamuse);
extio_init();
usbmem_init(config_ddrhook1.usbmem_path_p1, config_ddrhook1.usbmem_path_p2,
usbmem_init(
config_ddrhook1.usbmem_path_p1,
config_ddrhook1.usbmem_path_p2,
config_ddrhook1.usbmem_enabled);
spike_init();
com4_init();
@ -189,7 +193,8 @@ BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx)
ddrhook1_master_insert_hooks(NULL);
ddrhook1_filesystem_hook_init();
hook_d3d9_init(ddrhook1_d3d9_handlers, lengthof(ddrhook1_d3d9_handlers));
hook_d3d9_init(
ddrhook1_d3d9_handlers, lengthof(ddrhook1_d3d9_handlers));
}
return TRUE;

View File

@ -1,8 +1,8 @@
#include <windows.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -14,9 +14,8 @@
#include "util/str.h"
static BOOL STDCALL my_SetCurrentDirectoryA(LPCSTR lpPathName);
static HANDLE STDCALL my_FindFirstFileW(
LPCWSTR lpFileName,
LPWIN32_FIND_DATAA lpFindFileData);
static HANDLE STDCALL
my_FindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData);
static HANDLE STDCALL my_CreateFileW(
LPCWSTR lpFileName,
DWORD dwDesiredAccess,
@ -30,8 +29,7 @@ static BOOL WINAPI my_CreateDirectoryW(
static BOOL(STDCALL *real_SetCurrentDirectoryA)(LPCSTR lpPathName);
static HANDLE(STDCALL *real_FindFirstFileW)(
LPCWSTR lpFileName,
LPWIN32_FIND_DATAA lpFindFileData);
LPCWSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData);
static HANDLE(STDCALL *real_CreateFileW)(
LPCWSTR lpFileName,
DWORD dwDesiredAccess,
@ -44,29 +42,25 @@ static BOOL(WINAPI *real_CreateDirectoryW)(
LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
static const struct hook_symbol filesystem_hook_syms[] = {
{
.name = "CreateFileW",
{.name = "CreateFileW",
.patch = my_CreateFileW,
.link = (void **) &real_CreateFileW
},
.link = (void **) &real_CreateFileW},
{
.name = "SetCurrentDirectoryA",
.patch = my_SetCurrentDirectoryA,
.link = (void **) &real_SetCurrentDirectoryA,
},
{
.name = "FindFirstFileW",
{.name = "FindFirstFileW",
.patch = my_FindFirstFileW,
.link = (void **) &real_FindFirstFileW
},
{
.name = "CreateDirectoryW",
.link = (void **) &real_FindFirstFileW},
{.name = "CreateDirectoryW",
.patch = my_CreateDirectoryW,
.link = (void **) &real_CreateDirectoryW
},
.link = (void **) &real_CreateDirectoryW},
};
void ddrhook1_get_launcher_path_parts(char **output_path, char **output_foldername) {
void ddrhook1_get_launcher_path_parts(
char **output_path, char **output_foldername)
{
char module_path[MAX_PATH];
char launcher_path[MAX_PATH];
@ -82,7 +76,9 @@ void ddrhook1_get_launcher_path_parts(char **output_path, char **output_folderna
return;
char *filename_ptr = NULL;
if (GetFullPathNameA(module_path, sizeof(launcher_path), launcher_path, &filename_ptr) == 0)
if (GetFullPathNameA(
module_path, sizeof(launcher_path), launcher_path, &filename_ptr) ==
0)
return;
if (filename_ptr != NULL)
@ -98,7 +94,8 @@ void ddrhook1_get_launcher_path_parts(char **output_path, char **output_folderna
int idx_folder = 0;
for (idx_folder = strlen(launcher_path); idx_folder - 1 > 0; idx_folder--) {
if (launcher_path[idx_folder - 1] == '\\' || launcher_path[idx_folder - 1] == '/') {
if (launcher_path[idx_folder - 1] == '\\' ||
launcher_path[idx_folder - 1] == '/') {
break;
}
}
@ -135,9 +132,12 @@ static wchar_t *ddrhook1_filesystem_get_path(LPCWSTR path)
// log_misc("path: %s", tmp);
// free(tmp);
// Deal with hardcoded paths: D:/HDX, E:/conf, E:/conf/nvram, E:/conf/raw, F:/update, ...
if (wstr_insensitive_eq(path, L"D:/HDX") || wstr_insensitive_eq(path, L"D:\\HDX")
|| wstr_insensitive_eq(path, L"D:/JDX") || wstr_insensitive_eq(path, L"D:\\JDX")) {
// Deal with hardcoded paths: D:/HDX, E:/conf, E:/conf/nvram, E:/conf/raw,
// F:/update, ...
if (wstr_insensitive_eq(path, L"D:/HDX") ||
wstr_insensitive_eq(path, L"D:\\HDX") ||
wstr_insensitive_eq(path, L"D:/JDX") ||
wstr_insensitive_eq(path, L"D:\\JDX")) {
char *_new_path;
ddrhook1_get_launcher_path_parts(&_new_path, NULL);
@ -145,8 +145,10 @@ static wchar_t *ddrhook1_filesystem_get_path(LPCWSTR path)
new_path = str_widen(_new_path);
return new_path;
}
} else if (wcslen(path) >= 7 && (wcsnicmp(path, L"E:/conf", 7) == 0
|| wcsnicmp(path, L"E:\\conf", 7) == 0)) {
} else if (
wcslen(path) >= 7 &&
(wcsnicmp(path, L"E:/conf", 7) == 0 ||
wcsnicmp(path, L"E:\\conf", 7) == 0)) {
char *launcher_folder;
wchar_t *sub_path;
@ -156,14 +158,16 @@ static wchar_t *ddrhook1_filesystem_get_path(LPCWSTR path)
if (sub_path && launcher_folder) {
wchar_t *launcher_folder_w = str_widen(launcher_folder);
new_path = (wchar_t *) xmalloc(MAX_PATH * sizeof(wchar_t));
swprintf(new_path, MAX_PATH, L"%s\\%s", launcher_folder_w, sub_path);
swprintf(
new_path, MAX_PATH, L"%s\\%s", launcher_folder_w, sub_path);
free(launcher_folder_w);
return new_path;
}
} else if (wstr_insensitive_eq(path, L"F:/update")
|| wstr_insensitive_eq(path, L"F:\\update")
|| wstr_insensitive_eq(path, L".\\F:/update")
|| wstr_insensitive_eq(path, L".\\F:\\update")) {
} else if (
wstr_insensitive_eq(path, L"F:/update") ||
wstr_insensitive_eq(path, L"F:\\update") ||
wstr_insensitive_eq(path, L".\\F:/update") ||
wstr_insensitive_eq(path, L".\\F:\\update")) {
char *launcher_folder;
wchar_t *sub_path;
@ -173,12 +177,15 @@ static wchar_t *ddrhook1_filesystem_get_path(LPCWSTR path)
if (sub_path && launcher_folder) {
wchar_t *launcher_folder_w = str_widen(launcher_folder);
new_path = (wchar_t *) xmalloc(MAX_PATH * sizeof(wchar_t));
swprintf(new_path, MAX_PATH, L"%s\\%s", launcher_folder_w, sub_path);
swprintf(
new_path, MAX_PATH, L"%s\\%s", launcher_folder_w, sub_path);
free(launcher_folder_w);
return new_path;
}
} else if (wcslen(path) >= 24 && (wcsnicmp(path, L"D:/JDX/JDX-001/contents/", 24) == 0
|| wcsnicmp(path, L"D:\\JDX\\JDX-001\\contents\\", 24) == 0)) {
} else if (
wcslen(path) >= 24 &&
(wcsnicmp(path, L"D:/JDX/JDX-001/contents/", 24) == 0 ||
wcsnicmp(path, L"D:\\JDX\\JDX-001\\contents\\", 24) == 0)) {
char *content_path;
ddrhook1_get_launcher_path_parts(&content_path, NULL);
@ -190,8 +197,12 @@ static wchar_t *ddrhook1_filesystem_get_path(LPCWSTR path)
free(content_path_w);
return new_path;
}
} else if (wcslen(path) >= 7 && (wcsnicmp(path, L"D:/HDX/", 7) == 0 || wcsnicmp(path, L"D:\\HDX\\", 7) == 0
|| wcsnicmp(path, L"D:/JDX/", 7) == 0 || wcsnicmp(path, L"D:\\JDX\\", 7) == 0)) {
} else if (
wcslen(path) >= 7 &&
(wcsnicmp(path, L"D:/HDX/", 7) == 0 ||
wcsnicmp(path, L"D:\\HDX\\", 7) == 0 ||
wcsnicmp(path, L"D:/JDX/", 7) == 0 ||
wcsnicmp(path, L"D:\\JDX\\", 7) == 0)) {
char *content_path;
ddrhook1_get_launcher_path_parts(&content_path, NULL);
@ -225,7 +236,10 @@ static BOOL STDCALL my_SetCurrentDirectoryA(LPCSTR lpPathName)
if (new_path != NULL) {
bool r = real_SetCurrentDirectoryA(new_path);
log_misc("SetCurrentDirectoryA remapped path %s -> %s", lpPathName, new_path);
log_misc(
"SetCurrentDirectoryA remapped path %s -> %s",
lpPathName,
new_path);
free(new_path);
return r;
}
@ -233,16 +247,13 @@ static BOOL STDCALL my_SetCurrentDirectoryA(LPCSTR lpPathName)
return real_SetCurrentDirectoryA(lpPathName);
}
static HANDLE STDCALL my_FindFirstFileW(
LPCWSTR lpFileName,
LPWIN32_FIND_DATAA lpFindFileData)
static HANDLE STDCALL
my_FindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData)
{
wchar_t *new_path = ddrhook1_filesystem_get_path(lpFileName);
if (new_path) {
HANDLE r = real_FindFirstFileW(
new_path,
lpFindFileData);
HANDLE r = real_FindFirstFileW(new_path, lpFindFileData);
char *tmp;
wstr_narrow(new_path, &tmp);
@ -253,9 +264,7 @@ static HANDLE STDCALL my_FindFirstFileW(
return r;
}
return real_FindFirstFileW(
lpFileName,
lpFindFileData);
return real_FindFirstFileW(lpFileName, lpFindFileData);
}
static HANDLE STDCALL my_CreateFileW(
@ -321,7 +330,10 @@ BOOL WINAPI my_CreateDirectoryW(
void ddrhook1_filesystem_hook_init()
{
hook_table_apply(
NULL, "kernel32.dll", filesystem_hook_syms, lengthof(filesystem_hook_syms));
NULL,
"kernel32.dll",
filesystem_hook_syms,
lengthof(filesystem_hook_syms));
log_info("Inserted filesystem hooks");
}

View File

@ -134,7 +134,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
eam_io_set_loggers(
log_body_misc, log_body_info, log_body_warning, log_body_fatal);
ok = eam_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy);
ok =
eam_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy);
if (!ok) {
return false;

View File

@ -16,7 +16,6 @@ static HMODULE(STDCALL *real_LoadLibraryA)(const char *name);
static HMODULE STDCALL my_LoadLibraryA(const char *name);
static const hook_d3d9_irp_handler_t ddrhook2_d3d9_handlers[] = {
gfx_d3d9_irp_handler,
};

View File

@ -43,20 +43,49 @@ static const struct ddr_io_smx_pad_map ddr_io_smx_pad_map[] = {
#define DDR_IO_SMX_LIGHT_VALUES_PER_PANEL 75
#define DDR_IO_SMX_NUMBER_OF_PANELS 18
#define DDR_IO_SMX_TOTAL_LIGHT_VALUES DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * DDR_IO_SMX_NUMBER_OF_PANELS
#define DDR_IO_SMX_TOTAL_LIGHT_VALUES \
DDR_IO_SMX_LIGHT_VALUES_PER_PANEL *DDR_IO_SMX_NUMBER_OF_PANELS
static const struct ddr_io_smx_light_map ddr_io_smx_light_map[] = {
/* Light L/R blue and U/D red to match DDR pad color scheme */
{1 << LIGHT_P1_UP, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 1, 0xFF, 0x00, 0x00},
{1 << LIGHT_P1_LEFT, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 3, 0x00, 0x00, 0xFF},
{1 << LIGHT_P1_RIGHT, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 5, 0x00, 0x00, 0xFF},
{1 << LIGHT_P1_DOWN, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 7, 0xFF, 0x00, 0x00},
{1 << LIGHT_P1_LEFT,
DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 3,
0x00,
0x00,
0xFF},
{1 << LIGHT_P1_RIGHT,
DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 5,
0x00,
0x00,
0xFF},
{1 << LIGHT_P1_DOWN,
DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 7,
0xFF,
0x00,
0x00},
{1 << LIGHT_P2_UP, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 10, 0xFF, 0x00, 0x00},
{1 << LIGHT_P2_LEFT, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 12, 0x00, 0x00, 0xFF},
{1 << LIGHT_P2_RIGHT, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 14, 0x00, 0x00, 0xFF},
{1 << LIGHT_P2_DOWN, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 16, 0xFF, 0x00, 0x00},
{1 << LIGHT_P2_UP,
DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 10,
0xFF,
0x00,
0x00},
{1 << LIGHT_P2_LEFT,
DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 12,
0x00,
0x00,
0xFF},
{1 << LIGHT_P2_RIGHT,
DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 14,
0x00,
0x00,
0xFF},
{1 << LIGHT_P2_DOWN,
DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 16,
0xFF,
0x00,
0x00},
};
static _Atomic uint32_t ddr_io_smx_pad_state[2];

View File

@ -8,9 +8,9 @@
#include <stdint.h>
#include <stdio.h>
#include "aciomgr/manager.h"
#include "aciodrv/device.h"
#include "aciodrv/icca.h"
#include "aciomgr/manager.h"
#include "bemanitools/eamio.h"
@ -23,7 +23,8 @@
#define NUMBER_OF_EMULATED_READERS 2
#define INVALID_NODE_ID -1
static const uint8_t eam_io_keypad_mappings[16] = {EAM_IO_KEYPAD_DECIMAL,
static const uint8_t eam_io_keypad_mappings[16] = {
EAM_IO_KEYPAD_DECIMAL,
EAM_IO_KEYPAD_3,
EAM_IO_KEYPAD_6,
EAM_IO_KEYPAD_9,
@ -119,7 +120,8 @@ bool eam_io_init(
for (uint8_t i = 0; i < NUMBER_OF_EMULATED_READERS; i++) {
icca_node_id[i] = INVALID_NODE_ID;
for (uint8_t nid = 0; nid < aciomgr_get_node_count(acio_manager_ctx); ++nid) {
for (uint8_t nid = 0; nid < aciomgr_get_node_count(acio_manager_ctx);
++nid) {
if (check_if_icca(nid)) {
bool existing_reader = false;
@ -139,7 +141,8 @@ bool eam_io_init(
icca_is_slotted[i] = aciodrv_icca_is_slotted(device, nid);
icca_last_nonbusy_state[i] = 0;
log_misc("ICC reader %d is_slotted: %d", nid, icca_is_slotted[i]);
log_misc(
"ICC reader %d is_slotted: %d", nid, icca_is_slotted[i]);
if (!aciodrv_icca_init(device, icca_node_id[i])) {
log_warning("Initializing icca %d failed", i);
@ -195,17 +198,20 @@ uint8_t eam_io_get_sensor_state(uint8_t unit_no)
sensors |= (1 << EAM_IO_SENSOR_FRONT);
}
} else {
// wavepass readers always report (EAM_IO_SENSOR_BACK + EAM_IO_SENSOR_FRONT) + type
// but because we can't report status_code back directly
// and libacio actually just ignores the sensor_state other then the type
// we just return this state like we're a slotted reader so the emulation takes card of it
if (eam_io_icca_state[unit_no].status_code == AC_IO_ICCA_STATUS_GOT_UID) {
// wavepass readers always report (EAM_IO_SENSOR_BACK +
// EAM_IO_SENSOR_FRONT) + type but because we can't report status_code
// back directly and libacio actually just ignores the sensor_state
// other then the type we just return this state like we're a slotted
// reader so the emulation takes card of it
if (eam_io_icca_state[unit_no].status_code ==
AC_IO_ICCA_STATUS_GOT_UID) {
sensors |= (1 << EAM_IO_SENSOR_BACK);
sensors |= (1 << EAM_IO_SENSOR_FRONT);
}
// continue reporting last state during busy
if (eam_io_icca_state[unit_no].status_code == AC_IO_ICCA_STATUS_BUSY_NEW) {
if (eam_io_icca_state[unit_no].status_code ==
AC_IO_ICCA_STATUS_BUSY_NEW) {
sensors = icca_last_nonbusy_state[unit_no];
} else {
icca_last_nonbusy_state[unit_no] = sensors;
@ -243,18 +249,28 @@ bool eam_io_card_slot_cmd(uint8_t unit_no, uint8_t cmd)
switch (cmd) {
case EAM_IO_CARD_SLOT_CMD_CLOSE:
response = aciodrv_icca_set_state(
device, icca_node_id[unit_no], AC_IO_ICCA_SLOT_STATE_CLOSE, NULL);
device,
icca_node_id[unit_no],
AC_IO_ICCA_SLOT_STATE_CLOSE,
NULL);
case EAM_IO_CARD_SLOT_CMD_OPEN:
response = aciodrv_icca_set_state(
device, icca_node_id[unit_no], AC_IO_ICCA_SLOT_STATE_OPEN, NULL);
device,
icca_node_id[unit_no],
AC_IO_ICCA_SLOT_STATE_OPEN,
NULL);
case EAM_IO_CARD_SLOT_CMD_EJECT:
response = aciodrv_icca_set_state(
device, icca_node_id[unit_no], AC_IO_ICCA_SLOT_STATE_EJECT, NULL);
device,
icca_node_id[unit_no],
AC_IO_ICCA_SLOT_STATE_EJECT,
NULL);
case EAM_IO_CARD_SLOT_CMD_READ:
response = aciodrv_icca_read_card(device, icca_node_id[unit_no], NULL) &&
response =
aciodrv_icca_read_card(device, icca_node_id[unit_no], NULL) &&
aciodrv_icca_get_state(
device, icca_node_id[unit_no], &eam_io_icca_state[unit_no]);
@ -281,17 +297,18 @@ bool eam_io_poll(uint8_t unit_no)
if (response && !icca_is_slotted[unit_no]) {
// we handle wavepass a bit differently to handle polling felica
if (eam_io_icca_state[unit_no].status_code != AC_IO_ICCA_STATUS_BUSY_NEW) {
if (eam_io_icca_state[unit_no].status_code !=
AC_IO_ICCA_STATUS_BUSY_NEW) {
++icca_poll_counter[unit_no];
}
// we must manually call this every few polls to actually update the felica state
// we don't do it every poll, since card polling isn't that time sensitive of an operation
// libacio does it every 5ish polls after the last AC_IO_ICCA_STATUS_BUSY_NEW message
// we must manually call this every few polls to actually update the
// felica state we don't do it every poll, since card polling isn't that
// time sensitive of an operation libacio does it every 5ish polls after
// the last AC_IO_ICCA_STATUS_BUSY_NEW message
if (icca_poll_counter[unit_no] >= IDLE_RESPONSES_BETWEEN_FELICA_POLLS) {
response = aciodrv_icca_poll_felica(
aciomgr_port_checkout(acio_manager_ctx),
icca_node_id[unit_no]);
aciomgr_port_checkout(acio_manager_ctx), icca_node_id[unit_no]);
aciomgr_port_checkin(acio_manager_ctx);
icca_poll_counter[unit_no] = 0;

View File

@ -2,7 +2,8 @@
const struct ezusb_emu_desc_device ezusb_emu_desc_device = {
.setupapi =
{.device_guid = {0xAE18AA60,
{.device_guid =
{0xAE18AA60,
0x7F6A,
0x11D4,
{0x97, 0xDD, 0x00, 0x01, 0x02, 0x29, 0xB9, 0x59}},

View File

@ -16,8 +16,10 @@
static struct security_mcode ezusb_iidx_emu_node_security_plug_boot_version;
static uint32_t ezusb_iidx_emu_node_security_plug_boot_seeds[3];
static struct security_rp_sign_key ezusb_iidx_emu_node_security_plug_black_sign_key;
static struct security_rp_sign_key ezusb_iidx_emu_node_security_plug_white_sign_key;
static struct security_rp_sign_key
ezusb_iidx_emu_node_security_plug_black_sign_key;
static struct security_rp_sign_key
ezusb_iidx_emu_node_security_plug_white_sign_key;
static struct security_mcode ezusb_iidx_emu_node_security_plug_black_mcode;
static struct security_mcode ezusb_iidx_emu_node_security_plug_white_mcode;
@ -223,8 +225,9 @@ uint8_t ezusb_iidx_emu_node_security_plug_process_cmd_v2(
// pop'n music only ever uses slot 2 (white) and slot 4 (black).
// If the configuration does not match then it will error out.
// IIDX uses slots 2 and 3 and detects what is plugged into each slot so ordering isn't important.
// IIDX also reads slot 1's data section but doesn't care what dongle it is?
// IIDX uses slots 2 and 3 and detects what is plugged into each slot so
// ordering isn't important. IIDX also reads slot 1's data section but
// doesn't care what dongle it is?
case EZUSB_IIDX_SECPLUG_CMD_V2_SELECT_DONGLE_1:
log_misc("EZUSB_IIDX_SECPLUG_CMD_V2_SELECT_DONGLE_1");
ezusb_iidx_emu_node_security_plug_active_dongle_slot =

View File

@ -12,8 +12,8 @@
#include "ezusb-emu/node-security-plug.h"
#include "ezusb-emu/node-sram.h"
#include "ezusb-emu/node-wdt.h"
#include "ezusb-emu/nodes.h"
#include "ezusb-emu/node.h"
#include "ezusb-emu/nodes.h"
/* All IIDX games */
const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_coin = {

View File

@ -9,8 +9,8 @@
#include "hook/iohook.h"
#include "ezusb-emu/msg.h"
#include "ezusb-emu/nodes.h"
#include "ezusb-emu/node-coin.h"
#include "ezusb-emu/nodes.h"
#include "ezusb-iidx/msg.h"

View File

@ -59,10 +59,9 @@ struct ezusb_iidx_msg_interrupt_read_packet {
1: Not used
2: Not used
3: Not used
4: C02/D01 board identifier, 1 = C02, 0 = D01 (on active low). This defines how the game has
to flash the FPGA board since D01 needs a different firmware (see result of FPGA CHECK on
game bootup)
5: Not used
4: C02/D01 board identifier, 1 = C02, 0 = D01 (on active low). This
defines how the game has to flash the FPGA board since D01 needs a
different firmware (see result of FPGA CHECK on game bootup) 5: Not used
6: usb mute?
7: Not used

View File

@ -2,7 +2,8 @@
const struct ezusb_emu_desc_device ezusb2_emu_desc_device = {
.setupapi =
{.device_guid = {0xAE18AA60,
{.device_guid =
{0xAE18AA60,
0x7F6A,
0x11D4,
{0x97, 0xDD, 0x00, 0x01, 0x02, 0x29, 0xB9, 0x59}},

View File

@ -10,11 +10,11 @@
#include "ezusb-emu/msg.h"
#include "ezusb-emu/nodes.h"
#include "ezusb-emu/node-none.h"
#include "ezusb-emu/node-coin.h"
#include "ezusb-emu/node-none.h"
#include "ezusb-emu/node-security-mem.h"
#include "ezusb-emu/node-security-plug.h"
#include "ezusb-emu/nodes.h"
#include "ezusb2-popn/msg.h"
@ -66,7 +66,10 @@ struct ezusb_emu_msg_hook *ezusb2_popn_emu_msg_init(void)
}
}
memset(&ezusb2_popn_emu_msg_history[0], 0xff, sizeof(ezusb2_popn_emu_msg_history));
memset(
&ezusb2_popn_emu_msg_history[0],
0xff,
sizeof(ezusb2_popn_emu_msg_history));
return &ezusb2_popn_emu_msg_hook;
}
@ -94,11 +97,17 @@ static HRESULT ezusb2_popn_emu_msg_interrupt_read(struct iobuf *read)
msg_resp->unk7 = 0xdf;
msg_resp->unk8 = ezusb2_popn_emu_msg_seq_no;
memcpy(&msg_resp->button_history[0], &ezusb2_popn_emu_msg_history[0], sizeof(uint16_t) * 10);
memcpy(
&msg_resp->button_history[0],
&ezusb2_popn_emu_msg_history[0],
sizeof(uint16_t) * 10);
read->pos = sizeof(*msg_resp);
memmove(&ezusb2_popn_emu_msg_history[1], &ezusb2_popn_emu_msg_history[0], sizeof(uint16_t) * 9);
memmove(
&ezusb2_popn_emu_msg_history[1],
&ezusb2_popn_emu_msg_history[0],
sizeof(uint16_t) * 9);
ezusb2_popn_emu_msg_history[0] = msg_resp->io.button;
return S_OK;
@ -126,7 +135,8 @@ static HRESULT ezusb2_popn_emu_msg_interrupt_write(struct const_iobuf *write)
popn_io_set_top_lights(msg_req->lamp & 0x1f);
popn_io_set_side_lights((msg_req->lamp >> 8) & 0xf);
popn_io_set_button_lights((msg_req->lamp >> 20) & 0xfff);
popn_io_set_coin_counter_light(((msg_req->lamp >> 12) & 0xf) == 0); // Active low
popn_io_set_coin_counter_light(
((msg_req->lamp >> 12) & 0xf) == 0); // Active low
popn_io_set_coin_blocker_light(((msg_req->lamp >> 16) & 0xf) == 0xf);
/* Remember node for next bulk read */

View File

@ -1,6 +1,6 @@
#include <windows.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdint.h>
#include <windows.h>
#include <setupapi.h>
@ -23,8 +23,7 @@ static HMODULE real_pe = NULL;
BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx)
{
if (reason == DLL_PROCESS_ATTACH && real_pe == NULL)
{
if (reason == DLL_PROCESS_ATTACH && real_pe == NULL) {
pe_hijack_entrypoint(EZUSB_REAL_DLL_FILENAME, &real_entrypoint);
real_pe = GetModuleHandleA(EZUSB_REAL_DLL_FILENAME);

View File

@ -1,17 +1,21 @@
#include <windows.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdint.h>
#include <windows.h>
#include "util/log.h"
struct CoinParam;
struct EEP_HISTORY;
typedef int32_t (*usb_boot_security_t)(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4);
typedef int32_t (*usb_boot_security_all_t)(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4);
typedef int32_t (*usb_boot_security_all_r_t)(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4);
typedef int32_t (*usb_boot_security_t)(
uint8_t *param1, int32_t param2, int32_t param3, int32_t param4);
typedef int32_t (*usb_boot_security_all_t)(
uint8_t *param1, int32_t param2, int32_t param3, int32_t param4);
typedef int32_t (*usb_boot_security_all_r_t)(
uint8_t *param1, int32_t param2, int32_t param3, int32_t param4);
typedef int32_t (*usb_check_alive_t)();
typedef int32_t (*usb_check_security_t)(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4);
typedef int32_t (*usb_check_security_t)(
uint8_t *param1, int32_t param2, int32_t param3, int32_t param4);
typedef int32_t (*usb_check_security_eep_t)(int32_t param1);
typedef int32_t (*usb_check_security_new_t)(int32_t param1);
typedef int32_t (*usb_coin_blocker_t)(int32_t param1);
@ -54,12 +58,30 @@ typedef int32_t (*usb_security_test_t)(int32_t param1);
typedef int32_t (*usb_security_write_t)(uint8_t *param1);
typedef int32_t (*usb_security_write_done_t)();
typedef int32_t (*usb_set_ext_io_t)(int32_t param1);
typedef int32_t (*usb_setup_eeprom_t)(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4);
typedef int32_t (*usb_setup_eeprom_new_t)(int32_t param1, uint8_t *param2, int32_t param3, int32_t param4, int32_t param5);
typedef int32_t (*usb_setup_security_t)(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4);
typedef int32_t (*usb_setup_security_complete_t)(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4);
typedef int32_t (*usb_setup_security_complete_new_t)(int32_t param1, uint8_t *param2, int32_t param3, int32_t param4, int32_t param5);
typedef int32_t (*usb_setup_security_new_t)(int32_t param1, uint8_t *param2, int32_t param3, int32_t param4, int32_t param5);
typedef int32_t (*usb_setup_eeprom_t)(
uint8_t *param1, int32_t param2, int32_t param3, int32_t param4);
typedef int32_t (*usb_setup_eeprom_new_t)(
int32_t param1,
uint8_t *param2,
int32_t param3,
int32_t param4,
int32_t param5);
typedef int32_t (*usb_setup_security_t)(
uint8_t *param1, int32_t param2, int32_t param3, int32_t param4);
typedef int32_t (*usb_setup_security_complete_t)(
uint8_t *param1, int32_t param2, int32_t param3, int32_t param4);
typedef int32_t (*usb_setup_security_complete_new_t)(
int32_t param1,
uint8_t *param2,
int32_t param3,
int32_t param4,
int32_t param5);
typedef int32_t (*usb_setup_security_new_t)(
int32_t param1,
uint8_t *param2,
int32_t param3,
int32_t param4,
int32_t param5);
typedef int32_t (*usb_start_t)(int32_t param1);
typedef int32_t (*usb_start_with_file_t)(char *param1);
typedef int32_t (*usb_wdt_reset_t)();
@ -138,88 +160,114 @@ void ezusb2_proxy_initialize(HMODULE pe)
proxy_is_initialized = true;
real_usb_boot_security = (usb_boot_security_t)GetProcAddress(pe, "?usbBootSecurity@@YAHPAEHHH@Z");
real_usb_boot_security = (usb_boot_security_t) GetProcAddress(
pe, "?usbBootSecurity@@YAHPAEHHH@Z");
log_assert(real_usb_boot_security);
real_usb_boot_security_all = (usb_boot_security_all_t)GetProcAddress(pe, "?usbBootSecurityAll@@YAHPAEHHH@Z");
real_usb_boot_security_all = (usb_boot_security_all_t) GetProcAddress(
pe, "?usbBootSecurityAll@@YAHPAEHHH@Z");
log_assert(real_usb_boot_security_all);
real_usb_boot_security_all_r = (usb_boot_security_all_r_t)GetProcAddress(pe, "?usbBootSecurityAllR@@YAHPAEHHH@Z");
real_usb_boot_security_all_r = (usb_boot_security_all_r_t) GetProcAddress(
pe, "?usbBootSecurityAllR@@YAHPAEHHH@Z");
log_assert(real_usb_boot_security_all_r);
real_usb_check_alive = (usb_check_alive_t)GetProcAddress(pe, "?usbCheckAlive@@YAHXZ");
real_usb_check_alive =
(usb_check_alive_t) GetProcAddress(pe, "?usbCheckAlive@@YAHXZ");
log_assert(real_usb_check_alive);
real_usb_check_security = (usb_check_security_t)GetProcAddress(pe, "?usbCheckSecurity@@YAHPAEHHH@Z");
real_usb_check_security = (usb_check_security_t) GetProcAddress(
pe, "?usbCheckSecurity@@YAHPAEHHH@Z");
log_assert(real_usb_check_security);
real_usb_check_security_eep = (usb_check_security_eep_t)GetProcAddress(pe, "?usbCheckSecurityEep@@YAHH@Z");
real_usb_check_security_eep = (usb_check_security_eep_t) GetProcAddress(
pe, "?usbCheckSecurityEep@@YAHH@Z");
log_assert(real_usb_check_security_eep);
real_usb_check_security_new = (usb_check_security_new_t)GetProcAddress(pe, "?usbCheckSecurityNew@@YAHH@Z");
real_usb_check_security_new = (usb_check_security_new_t) GetProcAddress(
pe, "?usbCheckSecurityNew@@YAHH@Z");
log_assert(real_usb_check_security_new);
real_usb_coin_blocker = (usb_coin_blocker_t)GetProcAddress(pe, "?usbCoinBlocker@@YAHH@Z");
real_usb_coin_blocker =
(usb_coin_blocker_t) GetProcAddress(pe, "?usbCoinBlocker@@YAHH@Z");
log_assert(real_usb_coin_blocker);
real_usb_coin_get2 = (usb_coin_get2_t)GetProcAddress(pe, "?usbCoinGet2@@YAHPAUCoinParam@@@Z");
real_usb_coin_get2 = (usb_coin_get2_t) GetProcAddress(
pe, "?usbCoinGet2@@YAHPAUCoinParam@@@Z");
log_assert(real_usb_coin_get2);
real_usb_coin_get = (usb_coin_get_t)GetProcAddress(pe, "?usbCoinGet@@YAHH@Z");
real_usb_coin_get =
(usb_coin_get_t) GetProcAddress(pe, "?usbCoinGet@@YAHH@Z");
log_assert(real_usb_coin_get);
real_usb_coin_meter_down = (usb_coin_meter_down_t)GetProcAddress(pe, "?usbCoinMeterDown@@YAHH@Z");
real_usb_coin_meter_down =
(usb_coin_meter_down_t) GetProcAddress(pe, "?usbCoinMeterDown@@YAHH@Z");
log_assert(real_usb_coin_meter_down);
real_usb_coin_meter_up = (usb_coin_meter_up_t)GetProcAddress(pe, "?usbCoinMeterUp@@YAHH@Z");
real_usb_coin_meter_up =
(usb_coin_meter_up_t) GetProcAddress(pe, "?usbCoinMeterUp@@YAHH@Z");
log_assert(real_usb_coin_meter_up);
real_usb_coin_mode = (usb_coin_mode_t)GetProcAddress(pe, "?usbCoinMode@@YAHH@Z");
real_usb_coin_mode =
(usb_coin_mode_t) GetProcAddress(pe, "?usbCoinMode@@YAHH@Z");
log_assert(real_usb_coin_mode);
real_usb_coin_up = (usb_coin_up_t) GetProcAddress(pe, "?usbCoinUp@@YAHH@Z");
log_assert(real_usb_coin_up);
real_usb_eep_read = (usb_eep_read_t)GetProcAddress(pe, "?usbEepRead@@YAHXZ");
real_usb_eep_read =
(usb_eep_read_t) GetProcAddress(pe, "?usbEepRead@@YAHXZ");
log_assert(real_usb_eep_read);
real_usb_eep_read_done = (usb_eep_read_done_t)GetProcAddress(pe, "?usbEepReadDone@@YAHPAE@Z");
real_usb_eep_read_done =
(usb_eep_read_done_t) GetProcAddress(pe, "?usbEepReadDone@@YAHPAE@Z");
log_assert(real_usb_eep_read_done);
real_usb_eep_test = (usb_eep_test_t)GetProcAddress(pe, "?usbEepTest@@YAHXZ");
real_usb_eep_test =
(usb_eep_test_t) GetProcAddress(pe, "?usbEepTest@@YAHXZ");
log_assert(real_usb_eep_test);
real_usb_eep_write = (usb_eep_write_t)GetProcAddress(pe, "?usbEepWrite@@YAHPAE@Z");
real_usb_eep_write =
(usb_eep_write_t) GetProcAddress(pe, "?usbEepWrite@@YAHPAE@Z");
log_assert(real_usb_eep_write);
real_usb_eep_write_done = (usb_eep_write_done_t)GetProcAddress(pe, "?usbEepWriteDone@@YAHXZ");
real_usb_eep_write_done =
(usb_eep_write_done_t) GetProcAddress(pe, "?usbEepWriteDone@@YAHXZ");
log_assert(real_usb_eep_write_done);
real_usb_end = (usb_end_t) GetProcAddress(pe, "?usbEnd@@YAHXZ");
log_assert(real_usb_end);
real_usb_factory_mode_init = (usb_factory_mode_init_t)GetProcAddress(pe, "?usbFactoryModeInit@@YAHPAE@Z");
real_usb_factory_mode_init = (usb_factory_mode_init_t) GetProcAddress(
pe, "?usbFactoryModeInit@@YAHPAE@Z");
log_assert(real_usb_factory_mode_init);
real_usb_firm_result = (usb_firm_result_t)GetProcAddress(pe, "?usbFirmResult@@YAHXZ");
real_usb_firm_result =
(usb_firm_result_t) GetProcAddress(pe, "?usbFirmResult@@YAHXZ");
log_assert(real_usb_firm_result);
real_usb_get_error = (usb_get_error_t)GetProcAddress(pe, "?usbGetError@@YAHPAD@Z");
real_usb_get_error =
(usb_get_error_t) GetProcAddress(pe, "?usbGetError@@YAHPAD@Z");
log_assert(real_usb_get_error);
real_usb_get_keyid = (usb_get_keyid_t)GetProcAddress(pe, "?usbGetKEYID@@YAHPAEH@Z");
real_usb_get_keyid =
(usb_get_keyid_t) GetProcAddress(pe, "?usbGetKEYID@@YAHPAEH@Z");
log_assert(real_usb_get_keyid);
real_usb_get_mute = (usb_get_mute_t)GetProcAddress(pe, "?usbGetMute@@YAHXZ");
real_usb_get_mute =
(usb_get_mute_t) GetProcAddress(pe, "?usbGetMute@@YAHXZ");
log_assert(real_usb_get_mute);
real_usb_get_pcbid = (usb_get_pcbid_t)GetProcAddress(pe, "?usbGetPCBID@@YAHPAE@Z");
real_usb_get_pcbid =
(usb_get_pcbid_t) GetProcAddress(pe, "?usbGetPCBID@@YAHPAE@Z");
log_assert(real_usb_get_pcbid);
real_usb_get_security = (usb_get_security_t)GetProcAddress(pe, "?usbGetSecurity@@YAHHPAE@Z");
real_usb_get_security =
(usb_get_security_t) GetProcAddress(pe, "?usbGetSecurity@@YAHHPAE@Z");
log_assert(real_usb_get_security);
real_usb_is_hi_speed = (usb_is_hi_speed_t)GetProcAddress(pe, "?usbIsHiSpeed@@YAHXZ");
real_usb_is_hi_speed =
(usb_is_hi_speed_t) GetProcAddress(pe, "?usbIsHiSpeed@@YAHXZ");
log_assert(real_usb_is_hi_speed);
real_usb_lamp = (usb_lamp_t) GetProcAddress(pe, "?usbLamp@@YAHH@Z");
@ -228,105 +276,138 @@ void ezusb2_proxy_initialize(HMODULE pe)
real_usb_mute = (usb_mute_t) GetProcAddress(pe, "?usbMute@@YAHH@Z");
log_assert(real_usb_mute);
real_usb_pad_read = (usb_pad_read_t)GetProcAddress(pe, "?usbPadRead@@YAHPAK@Z");
real_usb_pad_read =
(usb_pad_read_t) GetProcAddress(pe, "?usbPadRead@@YAHPAK@Z");
log_assert(real_usb_pad_read);
real_usb_pad_read_last = (usb_pad_read_last_t)GetProcAddress(pe, "?usbPadReadLast@@YAHPAE@Z");
real_usb_pad_read_last =
(usb_pad_read_last_t) GetProcAddress(pe, "?usbPadReadLast@@YAHPAE@Z");
log_assert(real_usb_pad_read_last);
real_usb_read_eep_history = (usb_read_eep_history_t)GetProcAddress(pe, "?usbReadEepHistory@@YAHPAUEEP_HISTORY@@@Z");
real_usb_read_eep_history = (usb_read_eep_history_t) GetProcAddress(
pe, "?usbReadEepHistory@@YAHPAUEEP_HISTORY@@@Z");
log_assert(real_usb_read_eep_history);
real_usb_security_get_id = (usb_security_get_id_t)GetProcAddress(pe, "?usbSecurityGetId@@YAHXZ");
real_usb_security_get_id =
(usb_security_get_id_t) GetProcAddress(pe, "?usbSecurityGetId@@YAHXZ");
log_assert(real_usb_security_get_id);
real_usb_security_get_id_done = (usb_security_get_id_done_t)GetProcAddress(pe, "?usbSecurityGetIdDone@@YAHPAE@Z");
real_usb_security_get_id_done = (usb_security_get_id_done_t) GetProcAddress(
pe, "?usbSecurityGetIdDone@@YAHPAE@Z");
log_assert(real_usb_security_get_id_done);
real_usb_security_init = (usb_security_init_t)GetProcAddress(pe, "?usbSecurityInit@@YAHXZ");
real_usb_security_init =
(usb_security_init_t) GetProcAddress(pe, "?usbSecurityInit@@YAHXZ");
log_assert(real_usb_security_init);
real_usb_security_init_done = (usb_security_init_done_t)GetProcAddress(pe, "?usbSecurityInitDone@@YAHXZ");
real_usb_security_init_done = (usb_security_init_done_t) GetProcAddress(
pe, "?usbSecurityInitDone@@YAHXZ");
log_assert(real_usb_security_init_done);
real_usb_security_read = (usb_security_read_t)GetProcAddress(pe, "?usbSecurityRead@@YAHXZ");
real_usb_security_read =
(usb_security_read_t) GetProcAddress(pe, "?usbSecurityRead@@YAHXZ");
log_assert(real_usb_security_read);
real_usb_security_read_done = (usb_security_read_done_t)GetProcAddress(pe, "?usbSecurityReadDone@@YAHPAE@Z");
real_usb_security_read_done = (usb_security_read_done_t) GetProcAddress(
pe, "?usbSecurityReadDone@@YAHPAE@Z");
log_assert(real_usb_security_read_done);
real_usb_security_search = (usb_security_search_t)GetProcAddress(pe, "?usbSecuritySearch@@YAHXZ");
real_usb_security_search =
(usb_security_search_t) GetProcAddress(pe, "?usbSecuritySearch@@YAHXZ");
log_assert(real_usb_security_search);
real_usb_security_search_done = (usb_security_search_done_t)GetProcAddress(pe, "?usbSecuritySearchDone@@YAHXZ");
real_usb_security_search_done = (usb_security_search_done_t) GetProcAddress(
pe, "?usbSecuritySearchDone@@YAHXZ");
log_assert(real_usb_security_search_done);
real_usb_security_select = (usb_security_select_t)GetProcAddress(pe, "?usbSecuritySelect@@YAHH@Z");
real_usb_security_select = (usb_security_select_t) GetProcAddress(
pe, "?usbSecuritySelect@@YAHH@Z");
log_assert(real_usb_security_select);
real_usb_security_select_done = (usb_security_select_done_t)GetProcAddress(pe, "?usbSecuritySelectDone@@YAHXZ");
real_usb_security_select_done = (usb_security_select_done_t) GetProcAddress(
pe, "?usbSecuritySelectDone@@YAHXZ");
log_assert(real_usb_security_select_done);
real_usb_security_test = (usb_security_test_t)GetProcAddress(pe, "?usbSecurityTest@@YAHH@Z");
real_usb_security_test =
(usb_security_test_t) GetProcAddress(pe, "?usbSecurityTest@@YAHH@Z");
log_assert(real_usb_security_test);
real_usb_security_write = (usb_security_write_t)GetProcAddress(pe, "?usbSecurityWrite@@YAHPAE@Z");
real_usb_security_write = (usb_security_write_t) GetProcAddress(
pe, "?usbSecurityWrite@@YAHPAE@Z");
log_assert(real_usb_security_write);
real_usb_security_write_done = (usb_security_write_done_t)GetProcAddress(pe, "?usbSecurityWriteDone@@YAHXZ");
real_usb_security_write_done = (usb_security_write_done_t) GetProcAddress(
pe, "?usbSecurityWriteDone@@YAHXZ");
log_assert(real_usb_security_write_done);
real_usb_set_ext_io = (usb_set_ext_io_t)GetProcAddress(pe, "?usbSetExtIo@@YAHH@Z");
real_usb_set_ext_io =
(usb_set_ext_io_t) GetProcAddress(pe, "?usbSetExtIo@@YAHH@Z");
log_assert(real_usb_set_ext_io);
real_usb_setup_eeprom = (usb_setup_eeprom_t)GetProcAddress(pe, "?usbSetupEeprom@@YAHPAEHHH@Z");
real_usb_setup_eeprom =
(usb_setup_eeprom_t) GetProcAddress(pe, "?usbSetupEeprom@@YAHPAEHHH@Z");
log_assert(real_usb_setup_eeprom);
real_usb_setup_eeprom_new = (usb_setup_eeprom_new_t)GetProcAddress(pe, "?usbSetupEepromNew@@YAHHPAEHHH@Z");
real_usb_setup_eeprom_new = (usb_setup_eeprom_new_t) GetProcAddress(
pe, "?usbSetupEepromNew@@YAHHPAEHHH@Z");
log_assert(real_usb_setup_eeprom_new);
real_usb_setup_security = (usb_setup_security_t)GetProcAddress(pe, "?usbSetupSecurity@@YAHPAEHHH@Z");
real_usb_setup_security = (usb_setup_security_t) GetProcAddress(
pe, "?usbSetupSecurity@@YAHPAEHHH@Z");
log_assert(real_usb_setup_security);
real_usb_setup_security_complete = (usb_setup_security_complete_t)GetProcAddress(pe, "?usbSetupSecurityComplete@@YAHPAEHHH@Z");
real_usb_setup_security_complete =
(usb_setup_security_complete_t) GetProcAddress(
pe, "?usbSetupSecurityComplete@@YAHPAEHHH@Z");
log_assert(real_usb_setup_security_complete);
real_usb_setup_security_complete_new = (usb_setup_security_complete_new_t)GetProcAddress(pe, "?usbSetupSecurityCompleteNew@@YAHHPAEHHH@Z");
real_usb_setup_security_complete_new =
(usb_setup_security_complete_new_t) GetProcAddress(
pe, "?usbSetupSecurityCompleteNew@@YAHHPAEHHH@Z");
log_assert(real_usb_setup_security_complete_new);
real_usb_setup_security_new = (usb_setup_security_new_t)GetProcAddress(pe, "?usbSetupSecurityNew@@YAHHPAEHHH@Z");
real_usb_setup_security_new = (usb_setup_security_new_t) GetProcAddress(
pe, "?usbSetupSecurityNew@@YAHHPAEHHH@Z");
log_assert(real_usb_setup_security_new);
real_usb_start = (usb_start_t) GetProcAddress(pe, "?usbStart@@YAHH@Z");
log_assert(real_usb_start);
real_usb_start_with_file = (usb_start_with_file_t)GetProcAddress(pe, "?usbStartWithFile@@YAHPAD@Z");
real_usb_start_with_file = (usb_start_with_file_t) GetProcAddress(
pe, "?usbStartWithFile@@YAHPAD@Z");
log_assert(real_usb_start_with_file);
real_usb_wdt_reset = (usb_wdt_reset_t)GetProcAddress(pe, "?usbWdtReset@@YAHXZ");
real_usb_wdt_reset =
(usb_wdt_reset_t) GetProcAddress(pe, "?usbWdtReset@@YAHXZ");
log_assert(real_usb_wdt_reset);
real_usb_wdt_start = (usb_wdt_start_t)GetProcAddress(pe, "?usbWdtStart@@YAHH@Z");
real_usb_wdt_start =
(usb_wdt_start_t) GetProcAddress(pe, "?usbWdtStart@@YAHH@Z");
log_assert(real_usb_wdt_start);
real_usb_wdt_start_done = (usb_wdt_start_done_t)GetProcAddress(pe, "?usbWdtStartDone@@YAHXZ");
real_usb_wdt_start_done =
(usb_wdt_start_done_t) GetProcAddress(pe, "?usbWdtStartDone@@YAHXZ");
log_assert(real_usb_wdt_start_done);
real_usb_wdt_stop = (usb_wdt_stop_t)GetProcAddress(pe, "?usbWdtStop@@YAHXZ");
real_usb_wdt_stop =
(usb_wdt_stop_t) GetProcAddress(pe, "?usbWdtStop@@YAHXZ");
log_assert(real_usb_wdt_stop);
}
int32_t proxy_usb_boot_security(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4)
int32_t proxy_usb_boot_security(
uint8_t *param1, int32_t param2, int32_t param3, int32_t param4)
{
return real_usb_boot_security(param1, param2, param3, param4);
}
int32_t proxy_usb_boot_security_all(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4)
int32_t proxy_usb_boot_security_all(
uint8_t *param1, int32_t param2, int32_t param3, int32_t param4)
{
return real_usb_boot_security_all(param1, param2, param3, param4);
}
int32_t proxy_usb_boot_security_all_r(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4)
int32_t proxy_usb_boot_security_all_r(
uint8_t *param1, int32_t param2, int32_t param3, int32_t param4)
{
return real_usb_boot_security_all_r(param1, param2, param3, param4);
}
@ -336,7 +417,8 @@ int32_t proxy_usb_check_alive()
return real_usb_check_alive();
}
int32_t proxy_usb_check_security(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4)
int32_t proxy_usb_check_security(
uint8_t *param1, int32_t param2, int32_t param3, int32_t param4)
{
return real_usb_check_security(param1, param2, param3, param4);
}
@ -551,32 +633,51 @@ int32_t proxy_usb_set_ext_io(int32_t param1)
return real_usb_set_ext_io(param1);
}
int32_t proxy_usb_setup_eeprom(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4)
int32_t proxy_usb_setup_eeprom(
uint8_t *param1, int32_t param2, int32_t param3, int32_t param4)
{
return real_usb_setup_eeprom(param1, param2, param3, param4);
}
int32_t proxy_usb_setup_eeprom_new(int32_t param1, uint8_t *param2, int32_t param3, int32_t param4, int32_t param5)
int32_t proxy_usb_setup_eeprom_new(
int32_t param1,
uint8_t *param2,
int32_t param3,
int32_t param4,
int32_t param5)
{
return real_usb_setup_eeprom_new(param1, param2, param3, param4, param5);
}
int32_t proxy_usb_setup_security(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4)
int32_t proxy_usb_setup_security(
uint8_t *param1, int32_t param2, int32_t param3, int32_t param4)
{
return real_usb_setup_security(param1, param2, param3, param4);
}
int32_t proxy_usb_setup_security_complete(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4)
int32_t proxy_usb_setup_security_complete(
uint8_t *param1, int32_t param2, int32_t param3, int32_t param4)
{
return real_usb_setup_security_complete(param1, param2, param3, param4);
}
int32_t proxy_usb_setup_security_complete_new(int32_t param1, uint8_t *param2, int32_t param3, int32_t param4, int32_t param5)
int32_t proxy_usb_setup_security_complete_new(
int32_t param1,
uint8_t *param2,
int32_t param3,
int32_t param4,
int32_t param5)
{
return real_usb_setup_security_complete_new(param1, param2, param3, param4, param5);
return real_usb_setup_security_complete_new(
param1, param2, param3, param4, param5);
}
int32_t proxy_usb_setup_security_new(int32_t param1, uint8_t *param2, int32_t param3, int32_t param4, int32_t param5)
int32_t proxy_usb_setup_security_new(
int32_t param1,
uint8_t *param2,
int32_t param3,
int32_t param4,
int32_t param5)
{
return real_usb_setup_security_new(param1, param2, param3, param4, param5);
}

View File

@ -127,7 +127,8 @@ typedef struct _SET_TRANSFER_SIZE_INFO {
#define DEVICE_TYPE_FROM_CTL_CODE(ctrlCode) \
(((ULONG) (ctrlCode & 0xffff0000)) >> 16)
#endif
#define FUNCTION_FROM_CTL_CODE(ctrlCode) (((ULONG)(ctrlCode & 0x00003FFC)) >> 2)
#define FUNCTION_FROM_CTL_CODE(ctrlCode) \
(((ULONG) (ctrlCode & 0x00003FFC)) >> 2)
#define ACCESS_FROM_CTL_CODE(ctrlCode) (((ULONG) (ctrlCode & 0x000C0000)) >> 14)
// #define METHOD_FROM_CTL_CODE(ctrlCode) (((ULONG)(ctrlCode &
// 0x00000003)))

View File

@ -10,11 +10,8 @@
/* This does not handle escaped double quotes inside args correctly yet */
static HRESULT args_push(
int *argc,
char ***argv,
const char *begin,
const char *end)
static HRESULT
args_push(int *argc, char ***argv, const char *begin, const char *end)
{
int tmp_argc;
char **tmp_argv;

View File

@ -1,5 +1,5 @@
#include <windows.h>
#include <unknwn.h>
#include <windows.h>
#include <assert.h>
#include <stdint.h>
@ -8,10 +8,8 @@
#include "hook/com-proxy.h"
static void com_proxy_free(struct com_proxy *proxy);
static HRESULT STDMETHODCALLTYPE com_proxy_query_interface(
IUnknown *unk,
REFIID iid,
void **iface);
static HRESULT STDMETHODCALLTYPE
com_proxy_query_interface(IUnknown *unk, REFIID iid, void **iface);
static ULONG STDMETHODCALLTYPE com_proxy_addref(IUnknown *unk);
static ULONG STDMETHODCALLTYPE com_proxy_release(IUnknown *unk);
@ -22,16 +20,28 @@ static ULONG STDMETHODCALLTYPE com_proxy_release(IUnknown *unk);
#define SLOT_OFFSET 0x0A
static const uint8_t com_proxy_tramp[] = {
/* mov rcx, [rcx+8] ; Get this->real */
0x48, 0x8B, 0x49, 0x08,
0x48,
0x8B,
0x49,
0x08,
/* mov rax, [rcx] ; Get this->vtbl */
0x48, 0x8B, 0x01,
0x48,
0x8B,
0x01,
/* mov rax, [rax+XX] ; Get vtbl->slot_XX */
0x48, 0x8B, 0x80, -1, -1, -1, -1,
0x48,
0x8B,
0x80,
-1,
-1,
-1,
-1,
/* jmp rax ; Continue to slot_XX */
0xFF, 0xE0,
0xFF,
0xE0,
};
#else
@ -41,30 +51,41 @@ static const uint8_t com_proxy_tramp[] = {
#define SLOT_OFFSET 0x0F
static const uint8_t com_proxy_tramp[] = {
/* mov eax, [esp+4] ; Get this */
0x8B, 0x44, 0x24, 0x04,
0x8B,
0x44,
0x24,
0x04,
/* mov eax, [eax+4] ; Get this->real */
0x8B, 0x40, 0x04,
0x8B,
0x40,
0x04,
/* mov [esp+4], eax ; Replace this with this->real on stack */
0x89, 0x44, 0x24, 0x04,
0x89,
0x44,
0x24,
0x04,
/* mov ecx, [eax] ; Get this->vtbl */
0x8B, 0x08,
0x8B,
0x08,
/* mov ecx, [ecx+XX] ; Get vtbl->slot_XX */
0x8B, 0x89, -1, -1, -1, -1,
0x8B,
0x89,
-1,
-1,
-1,
-1,
/* jmp ecx ; Continue to slot_XX */
0xFF, 0xE1
};
0xFF,
0xE1};
#endif
HRESULT com_proxy_wrap(
struct com_proxy **out,
void *real,
size_t vtbl_size)
HRESULT com_proxy_wrap(struct com_proxy **out, void *real, size_t vtbl_size)
{
struct com_proxy *proxy;
void **vtbl;
@ -160,10 +181,8 @@ static void com_proxy_free(struct com_proxy *proxy)
free(proxy);
}
static HRESULT STDMETHODCALLTYPE com_proxy_query_interface(
IUnknown *unk,
REFIID iid,
void **iface)
static HRESULT STDMETHODCALLTYPE
com_proxy_query_interface(IUnknown *unk, REFIID iid, void **iface)
{
struct com_proxy *proxy;
IUnknown *obj;

View File

@ -49,7 +49,4 @@ struct com_proxy {
unless you provide a custom QueryInterface implementation to prevent them
from doing so. */
HRESULT com_proxy_wrap(
struct com_proxy **out,
void *real,
size_t vtbl_size);
HRESULT com_proxy_wrap(struct com_proxy **out, void *real, size_t vtbl_size);

View File

@ -72,8 +72,7 @@ static HRESULT(STDCALL *real_DrawPrimitiveUP)(
UINT stride);
static HRESULT(STDCALL *real_Reset)(
IDirect3DDevice9 *self,
D3DPRESENT_PARAMETERS *pp);
IDirect3DDevice9 *self, D3DPRESENT_PARAMETERS *pp);
static HRESULT(STDCALL *real_SetViewport)(
IDirect3DDevice9 *self, const D3DVIEWPORT9 *pViewport);
@ -146,15 +145,14 @@ static HRESULT STDCALL my_DrawPrimitiveUP(
const void *data,
UINT stride);
static HRESULT STDCALL my_Reset(
IDirect3DDevice9 *self,
D3DPRESENT_PARAMETERS *pp);
static HRESULT STDCALL
my_Reset(IDirect3DDevice9 *self, D3DPRESENT_PARAMETERS *pp);
static HRESULT STDCALL my_SetViewport(
IDirect3DDevice9 *self, const D3DVIEWPORT9 *pViewport);
static HRESULT STDCALL
my_SetViewport(IDirect3DDevice9 *self, const D3DVIEWPORT9 *pViewport);
static HRESULT STDCALL my_SetVertexShader(
IDirect3DDevice9 *self, IDirect3DVertexShader9 *pShader);
static HRESULT STDCALL
my_SetVertexShader(IDirect3DDevice9 *self, IDirect3DVertexShader9 *pShader);
/* ------------------------------------------------------------------------------------------------------------------
*/
@ -214,8 +212,7 @@ hook_d3d9_irp_handler_real_dev_set_render_state(struct hook_d3d9_irp *irp);
static HRESULT
hook_d3d9_irp_handler_real_dev_draw_primitive_up(struct hook_d3d9_irp *irp);
static HRESULT
hook_d3d9_irp_handler_real_dev_reset(struct hook_d3d9_irp *irp);
static HRESULT hook_d3d9_irp_handler_real_dev_reset(struct hook_d3d9_irp *irp);
static HRESULT
hook_d3d9_irp_handler_real_dev_set_viewport(struct hook_d3d9_irp *irp);
@ -247,8 +244,7 @@ static const hook_d3d9_irp_handler_t hook_d3d9_irp_real_handlers[] = {
hook_d3d9_irp_handler_real_dev_set_render_state,
[HOOK_D3D9_IRP_OP_DEV_DRAW_PRIMITIVE_UP] =
hook_d3d9_irp_handler_real_dev_draw_primitive_up,
[HOOK_D3D9_IRP_OP_DEV_RESET] =
hook_d3d9_irp_handler_real_dev_reset,
[HOOK_D3D9_IRP_OP_DEV_RESET] = hook_d3d9_irp_handler_real_dev_reset,
[HOOK_D3D9_IRP_OP_DEV_SET_VIEWPORT] =
hook_d3d9_irp_handler_real_dev_set_viewport,
[HOOK_D3D9_IRP_OP_DEV_SET_VERTEX_SHADER] =
@ -523,8 +519,8 @@ static HRESULT STDCALL my_DrawPrimitiveUP(
return hr;
}
static HRESULT STDCALL my_SetViewport(
IDirect3DDevice9 *self, const D3DVIEWPORT9 *pViewport)
static HRESULT STDCALL
my_SetViewport(IDirect3DDevice9 *self, const D3DVIEWPORT9 *pViewport)
{
struct hook_d3d9_irp irp;
HRESULT hr;
@ -540,8 +536,8 @@ static HRESULT STDCALL my_SetViewport(
return hr;
}
static HRESULT STDCALL my_SetVertexShader(
IDirect3DDevice9 *self, IDirect3DVertexShader9 *pShader)
static HRESULT STDCALL
my_SetVertexShader(IDirect3DDevice9 *self, IDirect3DVertexShader9 *pShader)
{
struct hook_d3d9_irp irp;
HRESULT hr;
@ -557,9 +553,8 @@ static HRESULT STDCALL my_SetVertexShader(
return hr;
}
static HRESULT STDCALL my_Reset(
IDirect3DDevice9 *self,
D3DPRESENT_PARAMETERS *pp)
static HRESULT STDCALL
my_Reset(IDirect3DDevice9 *self, D3DPRESENT_PARAMETERS *pp)
{
struct hook_d3d9_irp irp;
HRESULT hr;
@ -827,14 +822,11 @@ hook_d3d9_irp_handler_real_dev_draw_primitive_up(struct hook_d3d9_irp *irp)
irp->args.dev_draw_primitive_up.stride);
}
static HRESULT
hook_d3d9_irp_handler_real_dev_reset(struct hook_d3d9_irp *irp)
static HRESULT hook_d3d9_irp_handler_real_dev_reset(struct hook_d3d9_irp *irp)
{
log_assert(irp);
return real_Reset(
irp->args.dev_reset.self,
irp->args.dev_reset.pp);
return real_Reset(irp->args.dev_reset.self, irp->args.dev_reset.pp);
}
static HRESULT
@ -843,8 +835,7 @@ hook_d3d9_irp_handler_real_dev_set_viewport(struct hook_d3d9_irp *irp)
log_assert(irp);
return real_SetViewport(
irp->args.dev_set_viewport.self,
irp->args.dev_set_viewport.pViewport);
irp->args.dev_set_viewport.self, irp->args.dev_set_viewport.pViewport);
}
static HRESULT

View File

@ -12,17 +12,28 @@ uint32_t hr_to_win32_error(HRESULT hr)
return HRESULT_CODE(hr);
} else {
switch (hr) {
case E_ABORT: return ERROR_OPERATION_ABORTED;
case E_ACCESSDENIED: return ERROR_ACCESS_DENIED;
case E_FAIL: return ERROR_GEN_FAILURE;
case E_HANDLE: return ERROR_INVALID_HANDLE;
case E_INVALIDARG: return ERROR_INVALID_PARAMETER;
case E_NOINTERFACE: return ERROR_INVALID_FUNCTION;
case E_NOTIMPL: return ERROR_NOT_SUPPORTED;
case E_OUTOFMEMORY: return ERROR_OUTOFMEMORY;
case E_POINTER: return ERROR_INVALID_ADDRESS;
case E_UNEXPECTED: return ERROR_INTERNAL_ERROR;
default: return ERROR_INTERNAL_ERROR;
case E_ABORT:
return ERROR_OPERATION_ABORTED;
case E_ACCESSDENIED:
return ERROR_ACCESS_DENIED;
case E_FAIL:
return ERROR_GEN_FAILURE;
case E_HANDLE:
return ERROR_INVALID_HANDLE;
case E_INVALIDARG:
return ERROR_INVALID_PARAMETER;
case E_NOINTERFACE:
return ERROR_INVALID_FUNCTION;
case E_NOTIMPL:
return ERROR_NOT_SUPPORTED;
case E_OUTOFMEMORY:
return ERROR_OUTOFMEMORY;
case E_POINTER:
return ERROR_INVALID_ADDRESS;
case E_UNEXPECTED:
return ERROR_INTERNAL_ERROR;
default:
return ERROR_INTERNAL_ERROR;
}
}
}

View File

@ -4,9 +4,9 @@
#undef WIN32_NO_STATUS
#include <winternl.h>
#include <winnt.h>
#include <devioctl.h>
#include <ntstatus.h>
#include <winnt.h>
#include <assert.h>
#include <stdbool.h>
@ -21,10 +21,8 @@
/* Helpers */
static void iohook_init(void);
static BOOL iohook_overlapped_result(
uint32_t *syncout,
OVERLAPPED *ovl,
uint32_t value);
static BOOL
iohook_overlapped_result(uint32_t *syncout, OVERLAPPED *ovl, uint32_t value);
static HRESULT iohook_invoke_real(struct irp *irp);
static HRESULT iohook_invoke_real_open(struct irp *irp);
@ -129,11 +127,7 @@ static BOOL (WINAPI *next_DeviceIoControl)(
OVERLAPPED *ovl);
static BOOL(WINAPI *next_ReadFile)(
HANDLE fd,
void *buf,
uint32_t nbytes,
uint32_t *nread,
OVERLAPPED *ovl);
HANDLE fd, void *buf, uint32_t nbytes, uint32_t *nread, OVERLAPPED *ovl);
static BOOL(WINAPI *next_WriteFile)(
HANDLE fd,
@ -163,35 +157,43 @@ static const struct hook_symbol iohook_kernel32_syms[] = {
.name = "CloseHandle",
.patch = iohook_CloseHandle,
.link = (void *) &next_CloseHandle,
}, {
},
{
.name = "CreateFileA",
.patch = iohook_CreateFileA,
.link = (void *) &next_CreateFileA,
}, {
},
{
.name = "CreateFileW",
.patch = iohook_CreateFileW,
.link = (void *) &next_CreateFileW,
}, {
},
{
.name = "DeviceIoControl",
.patch = iohook_DeviceIoControl,
.link = (void *) &next_DeviceIoControl,
}, {
},
{
.name = "ReadFile",
.patch = iohook_ReadFile,
.link = (void *) &next_ReadFile,
}, {
},
{
.name = "WriteFile",
.patch = iohook_WriteFile,
.link = (void *) &next_WriteFile,
}, {
},
{
.name = "SetFilePointer",
.patch = iohook_SetFilePointer,
.link = (void *) &next_SetFilePointer,
}, {
},
{
.name = "SetFilePointerEx",
.patch = iohook_SetFilePointerEx,
.link = (void *) &next_SetFilePointerEx,
}, {
},
{
.name = "FlushFileBuffers",
.patch = iohook_FlushFileBuffers,
.link = (void *) &next_FlushFileBuffers,
@ -268,15 +270,12 @@ static void iohook_init(void)
kernel32 = GetModuleHandleW(L"kernel32.dll");
if (next_CreateFileW == NULL) {
next_CreateFileW = (void *) GetProcAddress(
kernel32,
"CreateFileW");
next_CreateFileW = (void *) GetProcAddress(kernel32, "CreateFileW");
}
if (next_SetFilePointerEx == NULL) {
next_SetFilePointerEx = (void *) GetProcAddress(
kernel32,
"SetFilePointerEx");
next_SetFilePointerEx =
(void *) GetProcAddress(kernel32, "SetFilePointerEx");
}
LeaveCriticalSection(&iohook_lock);
@ -351,10 +350,8 @@ HRESULT iohook_push_handler(iohook_fn_t fn)
return hr;
}
static BOOL iohook_overlapped_result(
uint32_t *syncout,
OVERLAPPED *ovl,
uint32_t value)
static BOOL
iohook_overlapped_result(uint32_t *syncout, OVERLAPPED *ovl, uint32_t value)
{
if (ovl != NULL) {
ovl->Internal = STATUS_SUCCESS;
@ -514,10 +511,7 @@ static HRESULT iohook_invoke_real_seek(struct irp *irp)
assert(irp != NULL);
ok = next_SetFilePointerEx(
irp->fd,
irp->seek_offset,
&irp->seek_pos,
irp->seek_origin);
irp->fd, irp->seek_offset, &irp->seek_pos, irp->seek_origin);
if (!ok) {
return HRESULT_FROM_WIN32(GetLastError());
@ -620,7 +614,8 @@ static HANDLE WINAPI iohook_CreateFileA(
dwDesiredAccess,
dwShareMode,
lpSecurityAttributes,
dwCreationDisposition, dwFlagsAndAttributes,
dwCreationDisposition,
dwFlagsAndAttributes,
hTemplateFile);
end:
@ -738,9 +733,7 @@ static BOOL WINAPI iohook_ReadFile(
assert(irp.read.pos <= irp.read.nbytes);
return iohook_overlapped_result(
lpNumberOfBytesRead,
lpOverlapped,
irp.read.pos);
lpNumberOfBytesRead, lpOverlapped, irp.read.pos);
}
static BOOL WINAPI iohook_WriteFile(
@ -786,9 +779,7 @@ static BOOL WINAPI iohook_WriteFile(
assert(irp.write.pos <= irp.write.nbytes);
return iohook_overlapped_result(
lpNumberOfBytesWritten,
lpOverlapped,
irp.write.pos);
lpNumberOfBytesWritten, lpOverlapped, irp.write.pos);
}
static DWORD WINAPI iohook_SetFilePointer(
@ -963,7 +954,5 @@ static BOOL WINAPI iohook_DeviceIoControl(
}
return iohook_overlapped_result(
lpBytesReturned,
lpOverlapped,
irp.read.pos);
lpBytesReturned, lpOverlapped, irp.read.pos);
}

View File

@ -94,10 +94,7 @@ const pe_iid_t *pe_iid_get_next(HMODULE pe, const pe_iid_t *iid)
}
HRESULT pe_iid_get_iat_entry(
HMODULE pe,
const pe_iid_t *iid,
size_t n,
struct pe_iat_entry *entry)
HMODULE pe, const pe_iid_t *iid, size_t n, struct pe_iat_entry *entry)
{
const IMAGE_IMPORT_BY_NAME *import;
intptr_t *import_rvas;
@ -196,11 +193,7 @@ HRESULT pe_patch(void *dest, const void *src, size_t nbytes)
assert(dest != NULL);
assert(src != NULL);
ok = VirtualProtect(
dest,
nbytes,
PAGE_EXECUTE_READWRITE,
&old_protect);
ok = VirtualProtect(dest, nbytes, PAGE_EXECUTE_READWRITE, &old_protect);
if (!ok) {
return HRESULT_FROM_WIN32(GetLastError());
@ -208,11 +201,7 @@ HRESULT pe_patch(void *dest, const void *src, size_t nbytes)
memcpy(dest, src, nbytes);
ok = VirtualProtect(
dest,
nbytes,
old_protect,
&old_protect);
ok = VirtualProtect(dest, nbytes, old_protect, &old_protect);
if (!ok) {
return HRESULT_FROM_WIN32(GetLastError());
@ -252,7 +241,8 @@ const pe_thunk_t *pe_thunk_get_next(const pe_thunk_t *thunk)
return thunk_next;
}
void *pe_thunk_get_resolved_function(HMODULE target_pe, HMODULE import_pe, const pe_thunk_t *thunk)
void *pe_thunk_get_resolved_function(
HMODULE target_pe, HMODULE import_pe, const pe_thunk_t *thunk)
{
void *addr;
@ -265,7 +255,8 @@ void *pe_thunk_get_resolved_function(HMODULE target_pe, HMODULE import_pe, const
LPCSTR functionOrdinal = (LPCSTR) IMAGE_ORDINAL(thunk->u1.Ordinal);
addr = (void *) GetProcAddress(import_pe, functionOrdinal);
} else {
PIMAGE_IMPORT_BY_NAME functionName = pe_offset(target_pe, thunk->u1.AddressOfData);
PIMAGE_IMPORT_BY_NAME functionName =
pe_offset(target_pe, thunk->u1.AddressOfData);
addr = (void *) GetProcAddress(import_pe, functionName->Name);
}
} else {
@ -277,7 +268,8 @@ void *pe_thunk_get_resolved_function(HMODULE target_pe, HMODULE import_pe, const
void pe_resolve_imports(HMODULE target_pe)
{
for (const pe_iid_t *iid = pe_iid_get_first(target_pe); iid != NULL; iid = pe_iid_get_next(target_pe, iid)) {
for (const pe_iid_t *iid = pe_iid_get_first(target_pe); iid != NULL;
iid = pe_iid_get_next(target_pe, iid)) {
const char *iid_name;
HMODULE imported_pe;
@ -285,10 +277,13 @@ void pe_resolve_imports(HMODULE target_pe)
imported_pe = LoadLibraryA(iid_name);
assert(imported_pe != NULL);
for (const pe_thunk_t *thunk = pe_thunk_get_first(target_pe, iid); thunk != NULL; thunk = pe_thunk_get_next(thunk)) {
for (const pe_thunk_t *thunk = pe_thunk_get_first(target_pe, iid);
thunk != NULL;
thunk = pe_thunk_get_next(thunk)) {
void *addr;
addr = pe_thunk_get_resolved_function(target_pe, imported_pe, thunk);
addr =
pe_thunk_get_resolved_function(target_pe, imported_pe, thunk);
if (addr != NULL) {
pe_patch((void *) &thunk->u1.Function, &addr, sizeof(PDWORD));

View File

@ -21,10 +21,7 @@ const pe_iid_t *pe_iid_get_first(HMODULE pe);
const char *pe_iid_get_name(HMODULE pe, const pe_iid_t *iid);
const pe_iid_t *pe_iid_get_next(HMODULE pe, const pe_iid_t *iid);
HRESULT pe_iid_get_iat_entry(
HMODULE pe,
const pe_iid_t *iid,
size_t n,
struct pe_iat_entry *entry);
HMODULE pe, const pe_iid_t *iid, size_t n, struct pe_iat_entry *entry);
void *pe_get_export(HMODULE pe, const char *name, uint16_t ord);
void *pe_get_entry_point(HMODULE pe);
HRESULT pe_patch(void *dest, const void *src, size_t nbytes);

View File

@ -12,24 +12,18 @@
#include "hook/pe.h"
#include "hook/process.h"
static bool thread_match_startup(
const CONTEXT *ctx,
void *ntstart,
void *exe_entry)
static bool
thread_match_startup(const CONTEXT *ctx, void *ntstart, void *exe_entry)
{
#ifdef _M_AMD64
return ctx->Rip == (DWORD64) ntstart &&
ctx->Rcx == (DWORD64) exe_entry;
return ctx->Rip == (DWORD64) ntstart && ctx->Rcx == (DWORD64) exe_entry;
#else
return ctx->Eip == (DWORD) ntstart &&
ctx->Eax == (DWORD) exe_entry;
return ctx->Eip == (DWORD) ntstart && ctx->Eax == (DWORD) exe_entry;
#endif
}
static void thread_patch_startup(
process_entry_t new_entry,
process_entry_t *orig_entry,
CONTEXT *ctx)
process_entry_t new_entry, process_entry_t *orig_entry, CONTEXT *ctx)
{
#ifdef _M_AMD64
*orig_entry = (void *) ctx->Rcx;
@ -41,9 +35,7 @@ static void thread_patch_startup(
}
static HRESULT process_hijack_try_thread(
process_entry_t new_entry,
process_entry_t *orig_entry,
DWORD thread_id)
process_entry_t new_entry, process_entry_t *orig_entry, DWORD thread_id)
{
CONTEXT ctx;
HMODULE exe;
@ -85,10 +77,8 @@ static HRESULT process_hijack_try_thread(
goto end;
}
thread = OpenThread(
THREAD_GET_CONTEXT | THREAD_SET_CONTEXT,
FALSE,
thread_id);
thread =
OpenThread(THREAD_GET_CONTEXT | THREAD_SET_CONTEXT, FALSE, thread_id);
if (thread == NULL) {
hr = HRESULT_FROM_WIN32(GetLastError());
@ -134,9 +124,8 @@ end:
return hr;
}
HRESULT process_hijack_startup(
process_entry_t new_entry,
process_entry_t *orig_entry)
HRESULT
process_hijack_startup(process_entry_t new_entry, process_entry_t *orig_entry)
{
THREADENTRY32 thread;
HANDLE snap;
@ -175,9 +164,7 @@ HRESULT process_hijack_startup(
}
hr = process_hijack_try_thread(
new_entry,
orig_entry,
thread.th32ThreadID);
new_entry, orig_entry, thread.th32ThreadID);
if (hr == S_OK) {
/* Main thread successfully hijacked, finish up */

View File

@ -4,6 +4,5 @@
typedef DWORD(CALLBACK *process_entry_t)(void);
HRESULT process_hijack_startup(
process_entry_t new_entry,
process_entry_t *orig_entry);
HRESULT
process_hijack_startup(process_entry_t new_entry, process_entry_t *orig_entry);

View File

@ -13,9 +13,7 @@ static const char apiset_prefix[] = "api-ms-win-core-";
static const size_t apiset_prefix_len = sizeof(apiset_prefix) - 1;
static void hook_table_apply_to_all(
const char *depname,
const struct hook_symbol *syms,
size_t nsyms);
const char *depname, const struct hook_symbol *syms, size_t nsyms);
static void hook_table_apply_to_iid(
HMODULE target,
@ -24,25 +22,18 @@ static void hook_table_apply_to_iid(
size_t nsyms);
static bool hook_table_match_module(
HMODULE target,
const char *iid_name,
const char *depname);
HMODULE target, const char *iid_name, const char *depname);
static bool hook_table_match_proc(
const struct pe_iat_entry *iate,
const struct hook_symbol *sym);
const struct pe_iat_entry *iate, const struct hook_symbol *sym);
static void hook_table_apply_to_all(
const char *depname,
const struct hook_symbol *syms,
size_t nsyms)
const char *depname, const struct hook_symbol *syms, size_t nsyms)
{
const peb_dll_t *dll;
HMODULE pe;
for ( dll = peb_dll_get_first() ;
dll != NULL ;
dll = peb_dll_get_next(dll)) {
for (dll = peb_dll_get_first(); dll != NULL; dll = peb_dll_get_next(dll)) {
pe = peb_dll_get_base(dll);
if (pe == NULL) {
@ -71,8 +62,7 @@ void hook_table_apply(
hook_table_apply_to_all(depname, syms, nsyms);
} else {
for ( iid = pe_iid_get_first(target) ;
iid != NULL ;
for (iid = pe_iid_get_first(target); iid != NULL;
iid = pe_iid_get_next(target, iid)) {
iid_name = pe_iid_get_name(target, iid);
@ -112,9 +102,7 @@ static void hook_table_apply_to_iid(
}
static bool hook_table_match_module(
HMODULE target,
const char *iid_name,
const char *depname)
HMODULE target, const char *iid_name, const char *depname)
{
HMODULE kernel32;
int result;
@ -163,11 +151,9 @@ static bool hook_table_match_module(
}
static bool hook_table_match_proc(
const struct pe_iat_entry *iate,
const struct hook_symbol *sym)
const struct pe_iat_entry *iate, const struct hook_symbol *sym)
{
if ( sym->name != NULL &&
iate->name != NULL &&
if (sym->name != NULL && iate->name != NULL &&
strcmp(sym->name, iate->name) == 0) {
return true;
}

View File

@ -128,62 +128,74 @@ static HRESULT _iohook_handler(struct irp *irp)
return result;
case IRP_OP_WRITE:
// Use write as a trigger to evaluate buffered data of previous reads.
// Good enough to check for some button press combincation to exit the game
// Not implementing a full acio stack for performance reasons
// and to keep the complexity of this rather low for such crude feature.
// Use write as a trigger to evaluate buffered data of previous
// reads. Good enough to check for some button press
// combincation to exit the game Not implementing a full acio
// stack for performance reasons and to keep the complexity of
// this rather low for such crude feature.
// Un-escape the buffer to prepare it for further evaluation
_buffer_unescaped.pos = 0;
_unescape_acio_buffer(&_buffer, &_buffer_unescaped);
struct ac_io_message *msg = (struct ac_io_message*) _buffer_unescaped.bytes;
struct ac_io_message *msg =
(struct ac_io_message *) _buffer_unescaped.bytes;
if (msg->addr == (AC_IO_RESPONSE_FLAG | _ACIO_NODE_BIO2) &&
ac_io_u16(msg->cmd.code) == BIO2_BI2A_CMD_POLL) {
struct bi2a_iidx_state_in *state_in = (struct bi2a_iidx_state_in*) msg->cmd.raw;
struct bi2a_iidx_state_in *state_in =
(struct bi2a_iidx_state_in *) msg->cmd.raw;
if (state_in->PANEL.y_start1 && state_in->PANEL.y_start2 &&
state_in->PANEL.y_vefx && state_in->PANEL.y_effect) {
log_info("Exit hook triggered");
// Last opportunity to write some output data to switch off lights
// Hacky, since we don't have an acio stack but some checks to
// protect from bad things happening
// Last opportunity to write some output data to switch
// off lights Hacky, since we don't have an acio stack
// but some checks to protect from bad things happening
if (irp->write.nbytes >=
_SIZE_ACIO_WRITE_SOF +
if (irp->write.nbytes >= _SIZE_ACIO_WRITE_SOF +
_SIZE_ACIO_WRITE_MSG_HEADER +
sizeof(struct bi2a_iidx_state_out)) {
log_misc("Switching off lights");
// +_SIZE_ACIO_WRITE_SOF: Skip leading 0xAA
struct ac_io_message *msg_out =
(struct ac_io_message*) (irp->write.bytes + _SIZE_ACIO_WRITE_SOF);
(struct ac_io_message *) (irp->write.bytes +
_SIZE_ACIO_WRITE_SOF);
// Guard assumption that reading poll is always followed by a writing
// poll (according to traffic dumps from iidx 27, that's the case)
// Guard assumption that reading poll is always
// followed by a writing poll (according to traffic
// dumps from iidx 27, that's the case)
if (msg_out->addr == _ACIO_NODE_BIO2 &&
ac_io_u16(msg_out->cmd.code) == BIO2_BI2A_CMD_POLL &&
msg_out->cmd.count == sizeof(struct bi2a_iidx_state_out)) {
ac_io_u16(msg_out->cmd.code) ==
BIO2_BI2A_CMD_POLL &&
msg_out->cmd.count ==
sizeof(struct bi2a_iidx_state_out)) {
struct bi2a_iidx_state_out *state_out =
(struct bi2a_iidx_state_out*) msg_out->cmd.raw;
(struct bi2a_iidx_state_out *)
msg_out->cmd.raw;
_switch_off_all_lights(state_out);
result = iohook_invoke_next(irp);
if (result != S_OK) {
log_warning("Writing output to switch lights off failed: %lX",
log_warning(
"Writing output to switch lights off "
"failed: %lX",
result);
}
} else {
log_warning("Skipping switching off lights, write output not "
log_warning(
"Skipping switching off lights, write "
"output not "
"identified as a poll message");
}
} else {
log_warning(
"Skipped switching off lights due to insufficient buffer size");
"Skipped switching off lights due to "
"insufficient buffer size");
}
Sleep(1000);
@ -222,11 +234,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
char buffer[MAX_PATH];
if (!bio2drv_detect(
DETECT_DEVICEID,
0,
buffer,
sizeof(buffer))) {
if (!bio2drv_detect(DETECT_DEVICEID, 0, buffer, sizeof(buffer))) {
log_warning("Autodetecting IIDX BIO2 failed, disabling exit hook");
return TRUE;
}

View File

@ -33,7 +33,6 @@ static struct ac_io_emu_icca iidxhook_util_acio_emu_icca[2];
static bool iidxhook_util_icca_override_version;
static enum ac_io_emu_icca_version iidxhook_util_icca_override_version_value;
void iidxhook_util_acio_override_version(enum ac_io_emu_icca_version version)
{
iidxhook_util_icca_override_version = true;
@ -56,8 +55,7 @@ void iidxhook_util_acio_init(bool legacy_mode)
if (iidxhook_util_icca_override_version) {
ac_io_emu_icca_set_version(
&iidxhook_util_acio_emu_icca[i],
iidxhook_util_icca_override_version_value
);
iidxhook_util_icca_override_version_value);
}
}

View File

@ -20,7 +20,6 @@
*/
void iidxhook_util_acio_init(bool legacy_mode);
/**
* Use the specified ICCA emulation version
*/

View File

@ -24,7 +24,8 @@ void iidxhook_config_io_init(struct cconfig *config)
config,
IIDXHOOK_UTIL_CONFIG_IO_DISABLE_IO_EMU_KEY,
IIDXHOOK_UTIL_CONFIG_IO_DEFAULT_DISABLE_IO_EMU_VALUE,
"Disable ezusb IO emulation and enable usage of real ezusb1/2 IO hardware");
"Disable ezusb IO emulation and enable usage of real ezusb1/2 IO "
"hardware");
}
void iidxhook_config_io_get(

View File

@ -30,7 +30,8 @@ void iidxhook_config_misc_init(struct cconfig *config)
config,
IIDXHOOK_CONFIG_MISC_SETTINGS_PATH_STUB_KEY,
IIDXHOOK_CONFIG_MISC_DEFAULT_SETTINGS_PATH_STUB_VALUE,
"Path to store the settings, e.g. bookkeeping, operator settings. d:, e: and f: drive configuration/settings data");
"Path to store the settings, e.g. bookkeeping, operator settings. d:, "
"e: and f: drive configuration/settings data");
}
void iidxhook_config_misc_get(

View File

@ -679,8 +679,8 @@ iidxhook_util_d3d9_iidx11_to_17_fix_uvs_bg_videos(struct hook_d3d9_irp *irp)
(vertices[3].x >= 493.0f && vertices[3].x <= 494.0f &&
vertices[3].y >= 404.0f && vertices[3].y <= 408.0f))) {
/* fix UVs
1.0f / 512 fixes the diagonal seam connecting the two triangles
which is visible on some GPUs (why? idk)
1.0f / 512 fixes the diagonal seam connecting the two
triangles which is visible on some GPUs (why? idk)
*/
vertices[0].tu = 0.0f + 1.0f / 512;
vertices[0].tv = 1.0f;
@ -910,28 +910,36 @@ iidxhook_util_d3d9_iidx18_and_19_fix_diagonal_tearing(struct hook_d3d9_irp *irp)
HRESULT hr;
log_assert(irp);
log_assert(irp->op == HOOK_D3D9_IRP_OP_DEV_SET_VIEWPORT || irp->op == HOOK_D3D9_IRP_OP_DEV_SET_VERTEX_SHADER);
log_assert(
irp->op == HOOK_D3D9_IRP_OP_DEV_SET_VIEWPORT ||
irp->op == HOOK_D3D9_IRP_OP_DEV_SET_VERTEX_SHADER);
if (!iidxhook_util_d3d9_config.iidx18_and_19_diagonal_tearing_fix)
{
if (!iidxhook_util_d3d9_config.iidx18_and_19_diagonal_tearing_fix) {
return;
}
if (irp->op == HOOK_D3D9_IRP_OP_DEV_SET_VIEWPORT)
{
if (irp->op == HOOK_D3D9_IRP_OP_DEV_SET_VIEWPORT) {
const D3DVIEWPORT9 *pViewport = irp->args.dev_set_viewport.pViewport;
const float fix_offset[2] = {-1.0F / (float)pViewport->Width, -1.0F / (float)pViewport->Height};
const float fix_offset[2] = {
-1.0F / (float) pViewport->Width,
-1.0F / (float) pViewport->Height};
hr = IDirect3DDevice9_SetVertexShaderConstantF(irp->args.dev_set_viewport.self, 63, fix_offset, lengthof(fix_offset));
hr = IDirect3DDevice9_SetVertexShaderConstantF(
irp->args.dev_set_viewport.self,
63,
fix_offset,
lengthof(fix_offset));
if (hr != S_OK) {
log_warning("SetVertexShaderConstantF failed: %lX", hr);
}
}
if (irp->op == HOOK_D3D9_IRP_OP_DEV_SET_VERTEX_SHADER)
{
if (irp->op == HOOK_D3D9_IRP_OP_DEV_SET_VERTEX_SHADER) {
if (!vertex_shader) {
hr = IDirect3DDevice9_CreateVertexShader(irp->args.dev_set_vertex_shader.self, (const DWORD*) g_vs11_vs_main, &vertex_shader);
hr = IDirect3DDevice9_CreateVertexShader(
irp->args.dev_set_vertex_shader.self,
(const DWORD *) g_vs11_vs_main,
&vertex_shader);
if (hr != S_OK) {
log_fatal("CreateVertexShader failed: %lX", hr);
}

View File

@ -161,7 +161,8 @@ settings_hook_dispatch_irp(struct irp *irp)
new_path_folder[settings_path_len + 2] = '\0';
if (!path_exists(new_path_folder)) {
log_misc("Creating local settings folder %s", new_path_folder);
log_misc(
"Creating local settings folder %s", new_path_folder);
CreateDirectoryA(new_path_folder, NULL);
}
}

View File

@ -34,74 +34,32 @@
// approximately 8 instruction slots used
#endif
const BYTE g_vs11_vs_main[] =
{
1, 1, 254, 255, 254, 255,
59, 0, 67, 84, 65, 66,
28, 0, 0, 0, 191, 0,
0, 0, 1, 1, 254, 255,
3, 0, 0, 0, 28, 0,
0, 0, 0, 1, 0, 0,
184, 0, 0, 0, 88, 0,
0, 0, 2, 0, 4, 0,
1, 0, 18, 0, 104, 0,
0, 0, 0, 0, 0, 0,
120, 0, 0, 0, 2, 0,
63, 0, 1, 0, 254, 0,
132, 0, 0, 0, 0, 0,
0, 0, 148, 0, 0, 0,
2, 0, 0, 0, 4, 0,
2, 0, 168, 0, 0, 0,
0, 0, 0, 0, 67, 111,
108, 111, 114, 77, 117, 108,
116, 105, 112, 108, 121, 0,
171, 171, 1, 0, 3, 0,
1, 0, 4, 0, 1, 0,
0, 0, 0, 0, 0, 0,
70, 105, 120, 79, 102, 102,
115, 101, 116, 0, 171, 171,
1, 0, 3, 0, 1, 0,
2, 0, 1, 0, 0, 0,
0, 0, 0, 0, 87, 111,
114, 108, 100, 86, 105, 101,
119, 80, 114, 111, 106, 101,
99, 116, 105, 111, 110, 0,
3, 0, 3, 0, 4, 0,
4, 0, 1, 0, 0, 0,
0, 0, 0, 0, 118, 115,
95, 49, 95, 49, 0, 77,
105, 99, 114, 111, 115, 111,
102, 116, 32, 40, 82, 41,
32, 72, 76, 83, 76, 32,
83, 104, 97, 100, 101, 114,
32, 67, 111, 109, 112, 105,
108, 101, 114, 32, 49, 48,
46, 49, 0, 171, 31, 0,
0, 0, 0, 0, 0, 128,
0, 0, 15, 144, 31, 0,
0, 0, 10, 0, 0, 128,
1, 0, 15, 144, 31, 0,
0, 0, 5, 0, 0, 128,
2, 0, 15, 144, 9, 0,
0, 0, 0, 0, 4, 192,
0, 0, 228, 144, 2, 0,
228, 160, 5, 0, 0, 0,
0, 0, 15, 208, 1, 0,
228, 144, 4, 0, 228, 160,
9, 0, 0, 0, 0, 0,
1, 128, 0, 0, 228, 144,
0, 0, 228, 160, 9, 0,
0, 0, 0, 0, 2, 128,
0, 0, 228, 144, 1, 0,
228, 160, 9, 0, 0, 0,
0, 0, 4, 128, 0, 0,
228, 144, 3, 0, 228, 160,
4, 0, 0, 0, 0, 0,
3, 192, 63, 0, 228, 160,
0, 0, 170, 128, 0, 0,
228, 128, 1, 0, 0, 0,
0, 0, 8, 192, 0, 0,
170, 128, 1, 0, 0, 0,
0, 0, 3, 224, 2, 0,
228, 144, 255, 255, 0, 0
};
const BYTE g_vs11_vs_main[] = {
1, 1, 254, 255, 254, 255, 59, 0, 67, 84, 65, 66, 28, 0, 0,
0, 191, 0, 0, 0, 1, 1, 254, 255, 3, 0, 0, 0, 28, 0,
0, 0, 0, 1, 0, 0, 184, 0, 0, 0, 88, 0, 0, 0, 2,
0, 4, 0, 1, 0, 18, 0, 104, 0, 0, 0, 0, 0, 0, 0,
120, 0, 0, 0, 2, 0, 63, 0, 1, 0, 254, 0, 132, 0, 0,
0, 0, 0, 0, 0, 148, 0, 0, 0, 2, 0, 0, 0, 4, 0,
2, 0, 168, 0, 0, 0, 0, 0, 0, 0, 67, 111, 108, 111, 114,
77, 117, 108, 116, 105, 112, 108, 121, 0, 171, 171, 1, 0, 3, 0,
1, 0, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 70, 105, 120,
79, 102, 102, 115, 101, 116, 0, 171, 171, 1, 0, 3, 0, 1, 0,
2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 87, 111, 114, 108, 100,
86, 105, 101, 119, 80, 114, 111, 106, 101, 99, 116, 105, 111, 110, 0,
3, 0, 3, 0, 4, 0, 4, 0, 1, 0, 0, 0, 0, 0, 0,
0, 118, 115, 95, 49, 95, 49, 0, 77, 105, 99, 114, 111, 115, 111,
102, 116, 32, 40, 82, 41, 32, 72, 76, 83, 76, 32, 83, 104, 97,
100, 101, 114, 32, 67, 111, 109, 112, 105, 108, 101, 114, 32, 49, 48,
46, 49, 0, 171, 31, 0, 0, 0, 0, 0, 0, 128, 0, 0, 15,
144, 31, 0, 0, 0, 10, 0, 0, 128, 1, 0, 15, 144, 31, 0,
0, 0, 5, 0, 0, 128, 2, 0, 15, 144, 9, 0, 0, 0, 0,
0, 4, 192, 0, 0, 228, 144, 2, 0, 228, 160, 5, 0, 0, 0,
0, 0, 15, 208, 1, 0, 228, 144, 4, 0, 228, 160, 9, 0, 0,
0, 0, 0, 1, 128, 0, 0, 228, 144, 0, 0, 228, 160, 9, 0,
0, 0, 0, 0, 2, 128, 0, 0, 228, 144, 1, 0, 228, 160, 9,
0, 0, 0, 0, 0, 4, 128, 0, 0, 228, 144, 3, 0, 228, 160,
4, 0, 0, 0, 0, 0, 3, 192, 63, 0, 228, 160, 0, 0, 170,
128, 0, 0, 228, 128, 1, 0, 0, 0, 0, 0, 8, 192, 0, 0,
170, 128, 1, 0, 0, 0, 0, 0, 3, 224, 2, 0, 228, 144, 255,
255, 0, 0};

View File

@ -28,8 +28,8 @@
#include "iidxhook-util/config-eamuse.h"
#include "iidxhook-util/config-gfx.h"
#include "iidxhook-util/config-io.h"
#include "iidxhook-util/config-sec.h"
#include "iidxhook-util/config-misc.h"
#include "iidxhook-util/config-sec.h"
#include "iidxhook-util/d3d9.h"
#include "iidxhook-util/settings.h"
@ -80,9 +80,11 @@ iidxhook4_cn_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx)
d3d9_config.scale_back_buffer_filter = config_gfx->scale_back_buffer_filter;
d3d9_config.forced_refresh_rate = config_gfx->forced_refresh_rate;
d3d9_config.device_adapter = config_gfx->device_adapter;
d3d9_config.iidx18_and_19_diagonal_tearing_fix = config_gfx->diagonal_tearing_fix;
d3d9_config.iidx18_and_19_diagonal_tearing_fix =
config_gfx->diagonal_tearing_fix;
d3d9_config.iidx14_to_19_nvidia_fix = true;
d3d9_config.iidx18_and_19_diagonal_tearing_fix = config_gfx->diagonal_tearing_fix;
d3d9_config.iidx18_and_19_diagonal_tearing_fix =
config_gfx->diagonal_tearing_fix;
if (config_gfx->monitor_check == 0) {
log_info("Auto monitor check enabled");
@ -158,9 +160,10 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId)
log_info("Initializing iidxhook...");
/**
* This game is using a black round plug for game license management instead of a black usb dongle.
* No white dongle hooks applies since the game does not have network functionality.
* Also, card readers are not used/checked; no card reader hooks required.
* This game is using a black round plug for game license management instead
* of a black usb dongle. No white dongle hooks applies since the game does
* not have network functionality. Also, card readers are not used/checked;
* no card reader hooks required.
*/
ezusb_iidx_emu_node_security_plug_set_boot_version(
&config_sec.boot_version);

View File

@ -1,8 +1,8 @@
#define LOG_MODULE "path"
#include <windows.h>
#include <stdint.h>
#include <string.h>
#include <windows.h>
#include "hook/table.h"
@ -48,12 +48,10 @@ static HANDLE(WINAPI *real_CreateFileW)(
DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile);
static HANDLE WINAPI my_FindFirstFileA(
LPCSTR lpFileName,
LPWIN32_FIND_DATAA lpFindFileData);
static HANDLE WINAPI
my_FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData);
static HANDLE(WINAPI *real_FindFirstFileA)(
LPCSTR lpFileName,
LPWIN32_FIND_DATAA lpFindFileData);
LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData);
static const struct hook_symbol iidxhook4_cn_path_hook_syms[] = {
{.name = "CreateFileA",
@ -131,9 +129,8 @@ static HANDLE WINAPI my_CreateFileW(
hTemplateFile);
}
static HANDLE WINAPI my_FindFirstFileA(
LPCSTR lpFileName,
LPWIN32_FIND_DATAA lpFindFileData)
static HANDLE WINAPI
my_FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData)
{
if (lpFileName != NULL && strstr(lpFileName, PATH_A) == lpFileName) {
char relative_path[MAX_PATH] = ".";

View File

@ -72,7 +72,8 @@ iidxhook4_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx)
d3d9_config.forced_refresh_rate = config_gfx->forced_refresh_rate;
d3d9_config.device_adapter = config_gfx->device_adapter;
d3d9_config.iidx14_to_19_nvidia_fix = true;
d3d9_config.iidx18_and_19_diagonal_tearing_fix = config_gfx->diagonal_tearing_fix;
d3d9_config.iidx18_and_19_diagonal_tearing_fix =
config_gfx->diagonal_tearing_fix;
if (config_gfx->monitor_check == 0) {
log_info("Auto monitor check enabled");
@ -144,7 +145,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
iidx_io_set_loggers(
log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
if (!iidx_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy)) {
if (!iidx_io_init(
avs_thread_create, avs_thread_join, avs_thread_destroy)) {
log_fatal("Initializing IIDX IO backend failed");
}
} else {
@ -157,7 +159,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
eam_io_set_loggers(
log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
if (!eam_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy)) {
if (!eam_io_init(
avs_thread_create, avs_thread_join, avs_thread_destroy)) {
log_fatal("Initializing card reader backend failed");
}
} else {

View File

@ -28,8 +28,8 @@
#include "iidxhook-util/config-eamuse.h"
#include "iidxhook-util/config-gfx.h"
#include "iidxhook-util/config-io.h"
#include "iidxhook-util/config-sec.h"
#include "iidxhook-util/config-misc.h"
#include "iidxhook-util/config-sec.h"
#include "iidxhook-util/d3d9.h"
#include "iidxhook-util/settings.h"
@ -81,7 +81,8 @@ iidxhook5_cn_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx)
d3d9_config.forced_refresh_rate = config_gfx->forced_refresh_rate;
d3d9_config.device_adapter = config_gfx->device_adapter;
d3d9_config.iidx14_to_19_nvidia_fix = true;
d3d9_config.iidx18_and_19_diagonal_tearing_fix = config_gfx->diagonal_tearing_fix;
d3d9_config.iidx18_and_19_diagonal_tearing_fix =
config_gfx->diagonal_tearing_fix;
iidxhook_util_d3d9_configure(&d3d9_config);
@ -139,9 +140,10 @@ static ATOM WINAPI my_RegisterClassA(const WNDCLASSA *lpWndClass)
log_info("Initializing iidxhook...");
/**
* This game is using a black round plug for game license management instead of a black usb dongle.
* No white dongle hooks applies since the game does not have network functionality.
* Also, card readers are not used/checked; no card reader hooks required.
* This game is using a black round plug for game license management instead
* of a black usb dongle. No white dongle hooks applies since the game does
* not have network functionality. Also, card readers are not used/checked;
* no card reader hooks required.
*/
ezusb_iidx_emu_node_security_plug_set_boot_version(
&config_sec.boot_version);

View File

@ -1,8 +1,8 @@
#define LOG_MODULE "path"
#include <windows.h>
#include <stdint.h>
#include <string.h>
#include <windows.h>
#include "hook/table.h"
@ -31,12 +31,10 @@ static HANDLE(WINAPI *real_CreateFileW)(
DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile);
static HANDLE WINAPI my_FindFirstFileA(
LPCSTR lpFileName,
LPWIN32_FIND_DATAA lpFindFileData);
static HANDLE WINAPI
my_FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData);
static HANDLE(WINAPI *real_FindFirstFileA)(
LPCSTR lpFileName,
LPWIN32_FIND_DATAA lpFindFileData);
LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData);
static const struct hook_symbol iidxhook5_cn_path_hook_syms[] = {
{.name = "CreateFileW",
@ -79,9 +77,8 @@ static HANDLE WINAPI my_CreateFileW(
hTemplateFile);
}
static HANDLE WINAPI my_FindFirstFileA(
LPCSTR lpFileName,
LPWIN32_FIND_DATAA lpFindFileData)
static HANDLE WINAPI
my_FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData)
{
if (lpFileName != NULL && strstr(lpFileName, PATH_A) == lpFileName) {
char relative[MAX_PATH] = ".";

View File

@ -72,7 +72,8 @@ iidxhook5_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx)
d3d9_config.forced_refresh_rate = config_gfx->forced_refresh_rate;
d3d9_config.device_adapter = config_gfx->device_adapter;
d3d9_config.iidx14_to_19_nvidia_fix = true;
d3d9_config.iidx18_and_19_diagonal_tearing_fix = config_gfx->diagonal_tearing_fix;
d3d9_config.iidx18_and_19_diagonal_tearing_fix =
config_gfx->diagonal_tearing_fix;
if (config_gfx->monitor_check == 0) {
log_info("Auto monitor check enabled");
@ -144,7 +145,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
iidx_io_set_loggers(
log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
if (!iidx_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy)) {
if (!iidx_io_init(
avs_thread_create, avs_thread_join, avs_thread_destroy)) {
log_fatal("Initializing IIDX IO backend failed");
}
} else {
@ -157,7 +159,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
eam_io_set_loggers(
log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
if (!eam_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy)) {
if (!eam_io_init(
avs_thread_create, avs_thread_join, avs_thread_destroy)) {
log_fatal("Initializing card reader backend failed");
}
} else {

View File

@ -115,7 +115,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
iidx_io_set_loggers(
log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
if (!iidx_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy)) {
if (!iidx_io_init(
avs_thread_create, avs_thread_join, avs_thread_destroy)) {
log_fatal("Initializing IIDX IO backend failed");
}
} else {
@ -128,7 +129,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
eam_io_set_loggers(
log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
if (!eam_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy)) {
if (!eam_io_init(
avs_thread_create, avs_thread_join, avs_thread_destroy)) {
log_fatal("Initializing card reader backend failed");
}
} else {

View File

@ -115,7 +115,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
iidx_io_set_loggers(
log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
if (!iidx_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy)) {
if (!iidx_io_init(
avs_thread_create, avs_thread_join, avs_thread_destroy)) {
log_fatal("Initializing IIDX IO backend failed");
}
} else {
@ -128,7 +129,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
eam_io_set_loggers(
log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
if (!eam_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy)) {
if (!eam_io_init(
avs_thread_create, avs_thread_join, avs_thread_destroy)) {
log_fatal("Initializing card reader backend failed");
}
} else {

View File

@ -23,8 +23,8 @@
#include "iidxhook-util/d3d9.h"
#include "iidxhook-util/log-server.h"
#include "bio2emu/emu.h"
#include "bio2emu-iidx/bi2a.h"
#include "bio2emu/emu.h"
#include "camhook/cam.h"
#include "camhook/config-cam.h"

View File

@ -61,7 +61,8 @@ static struct bio2emu_port bio2_emu = {
.dispatcher = bio2_emu_bi2a_dispatch_request,
};
static bool load_configs() {
static bool load_configs()
{
struct cconfig *config;
config = cconfig_init();
@ -167,7 +168,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
if (!iidxhook9_config_io.lightning_mode) {
bio2emu_init();
bio2_emu_bi2a_set_tt_multiplier(iidxhook9_config_io.tt_multiplier);
bio2_emu_bi2a_init(&bio2_emu, iidxhook9_config_io.disable_poll_limiter);
bio2_emu_bi2a_init(
&bio2_emu, iidxhook9_config_io.disable_poll_limiter);
}
}
@ -265,7 +267,6 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
goto end;
}
if (avs_is_active()) {
// if AVS is loaded, we're likely too late to be a prehook
// so we warn the user

View File

@ -171,8 +171,9 @@ bool iidx_io_init(
void iidx_io_fini(void)
{
// Pushing some final state before closing the IO to the actual outputs, e.g. lights on/off
// can be a bit finicky. Do a few polls to "enforce"/flush this final state
// Pushing some final state before closing the IO to the actual outputs,
// e.g. lights on/off can be a bit finicky. Do a few polls to
// "enforce"/flush this final state
for (uint8_t i = 0; i < 3; i++) {
iidx_io_ep1_send();
iidx_io_ep2_recv();

View File

@ -78,9 +78,8 @@ bool iidx_io_init(
}
}
// Random data returned by device, likely not properly initalized on device side
// Triggers random inputs and lights
// Flush that by execute a few polls
// Random data returned by device, likely not properly initalized on device
// side Triggers random inputs and lights Flush that by execute a few polls
for (int i = 0; i < 10; i++) {
iidx_io_ep2_recv();
}
@ -90,8 +89,9 @@ bool iidx_io_init(
void iidx_io_fini(void)
{
// Pushing some final state before closing the IO to the actual outputs, e.g. lights on/off
// can be a bit finicky. Do a few polls to "enforce"/flush this final state
// Pushing some final state before closing the IO to the actual outputs,
// e.g. lights on/off can be a bit finicky. Do a few polls to
// "enforce"/flush this final state
for (uint8_t i = 0; i < 5; i++) {
iidx_io_ep1_send();
iidx_io_ep2_recv();

View File

@ -23,7 +23,8 @@ static uint8_t _fix_top_lamps_order(uint8_t top_lamps)
out |= ((1 << 4) & top_lamps) > 0 ? (1 << IIDX_IO_TOP_LAMP_RIGHT_BLUE) : 0;
out |= ((1 << 5) & top_lamps) > 0 ? (1 << IIDX_IO_TOP_LAMP_RIGHT_GREEN) : 0;
out |= ((1 << 6) & top_lamps) > 0 ? (1 << IIDX_IO_TOP_LAMP_RIGHT_YELLOW) : 0;
out |=
((1 << 6) & top_lamps) > 0 ? (1 << IIDX_IO_TOP_LAMP_RIGHT_YELLOW) : 0;
out |= ((1 << 7) & top_lamps) > 0 ? (1 << IIDX_IO_TOP_LAMP_RIGHT_RED) : 0;
return out;
@ -36,11 +37,12 @@ static void _all_lights_off_shutdown()
iidx_io_ep1_set_top_lamps(0);
iidx_io_ep1_set_top_neons(false);
// Depending on the IO, pushing the state to the actual outputs, e.g. lights on/off
// can be a bit finicky. Do a few times to "enforce" the state
// Depending on the IO, pushing the state to the actual outputs, e.g. lights
// on/off can be a bit finicky. Do a few times to "enforce" the state
for (uint8_t i = 0; i < 3; i++) {
iidx_io_ep1_send();
// Required to handle iidxio-ezusb specific quirks with flushing 16seg text
// Required to handle iidxio-ezusb specific quirks with flushing 16seg
// text
iidx_io_ep2_recv();
iidx_io_ep3_write_16seg(" ");

View File

@ -30,13 +30,11 @@ static HANDLE debugger_ready_event;
static PROCESS_INFORMATION pi;
static PVOID load_nt_header_from_process(HANDLE hProcess,
HMODULE hModule,
PIMAGE_NT_HEADERS32 pNtHeader);
static PVOID load_nt_header_from_process(
HANDLE hProcess, HMODULE hModule, PIMAGE_NT_HEADERS32 pNtHeader);
static HMODULE enumerate_modules_in_process(HANDLE hProcess,
HMODULE hModuleLast,
PIMAGE_NT_HEADERS32 pNtHeader);
static HMODULE enumerate_modules_in_process(
HANDLE hProcess, HMODULE hModuleLast, PIMAGE_NT_HEADERS32 pNtHeader);
// Source:
// https://docs.microsoft.com/en-us/windows/win32/memory/obtaining-a-file-name-from-a-file-handle
@ -233,7 +231,8 @@ static bool debugger_create_process(
if (!ok) {
log_warning(
"ERROR: Failed to launch hooked EXE: %08x", (unsigned int) GetLastError());
"ERROR: Failed to launch hooked EXE: %08x",
(unsigned int) GetLastError());
free(cmd_line);
@ -272,7 +271,8 @@ static uint32_t debugger_loop()
"EXCEPTION_DEBUG_EVENT(pid %ld, tid %ld): x%s 0x%p",
de.dwProcessId,
de.dwThreadId,
signal_exception_code_to_str(de.u.Exception.ExceptionRecord.ExceptionCode),
signal_exception_code_to_str(
de.u.Exception.ExceptionRecord.ExceptionCode),
de.u.Exception.ExceptionRecord.ExceptionAddress);
if (de.u.Exception.ExceptionRecord.ExceptionCode ==
@ -518,7 +518,9 @@ bool debugger_inject_dll(const char *path_dll)
PAGE_READWRITE);
if (!remote_addr) {
log_warning("ERROR: VirtualAllocEx failed: %08x", (unsigned int) GetLastError());
log_warning(
"ERROR: VirtualAllocEx failed: %08x",
(unsigned int) GetLastError());
goto alloc_fail;
}
@ -528,7 +530,8 @@ bool debugger_inject_dll(const char *path_dll)
if (!ok) {
log_warning(
"ERROR: WriteProcessMemory failed: %08x", (unsigned int) GetLastError());
"ERROR: WriteProcessMemory failed: %08x",
(unsigned int) GetLastError());
goto write_fail;
}
@ -544,7 +547,8 @@ bool debugger_inject_dll(const char *path_dll)
if (remote_thread == NULL) {
log_warning(
"ERROR: CreateRemoteThread failed: %08x", (unsigned int) GetLastError());
"ERROR: CreateRemoteThread failed: %08x",
(unsigned int) GetLastError());
goto inject_fail;
}
@ -556,7 +560,8 @@ bool debugger_inject_dll(const char *path_dll)
remote_addr = NULL;
if (!ok) {
log_warning("ERROR: VirtualFreeEx failed: %08x", (unsigned int) GetLastError());
log_warning(
"ERROR: VirtualFreeEx failed: %08x", (unsigned int) GetLastError());
}
return true;
@ -571,7 +576,8 @@ alloc_fail:
return false;
}
HRESULT debugger_pe_patch_remote(HANDLE hProcess, void *dest, const void *src, size_t nbytes)
HRESULT debugger_pe_patch_remote(
HANDLE hProcess, void *dest, const void *src, size_t nbytes)
{
DWORD old_protect;
BOOL ok;
@ -580,29 +586,19 @@ HRESULT debugger_pe_patch_remote(HANDLE hProcess, void *dest, const void *src, s
log_assert(src != NULL);
ok = VirtualProtectEx(
hProcess,
dest,
nbytes,
PAGE_EXECUTE_READWRITE,
&old_protect);
hProcess, dest, nbytes, PAGE_EXECUTE_READWRITE, &old_protect);
if (!ok) {
return HRESULT_FROM_WIN32(GetLastError());
}
ok = WriteProcessMemory(
hProcess, dest, src, nbytes, NULL);
ok = WriteProcessMemory(hProcess, dest, src, nbytes, NULL);
if (!ok) {
return HRESULT_FROM_WIN32(GetLastError());
}
ok = VirtualProtectEx(
hProcess,
dest,
nbytes,
old_protect,
&old_protect);
ok = VirtualProtectEx(hProcess, dest, nbytes, old_protect, &old_protect);
if (!ok) {
return HRESULT_FROM_WIN32(GetLastError());
@ -611,7 +607,8 @@ HRESULT debugger_pe_patch_remote(HANDLE hProcess, void *dest, const void *src, s
return S_OK;
}
bool debugger_replace_dll_iat(const char *expected_dll, const char *replacement_path_dll)
bool debugger_replace_dll_iat(
const char *expected_dll, const char *replacement_path_dll)
{
log_assert(expected_dll);
log_assert(replacement_path_dll);
@ -625,7 +622,8 @@ bool debugger_replace_dll_iat(const char *expected_dll, const char *replacement_
for (;;) {
memset(&inh, 0, sizeof(IMAGE_NT_HEADERS));
if ((hLast = enumerate_modules_in_process(pi.hProcess, hLast, &inh)) == NULL) {
if ((hLast = enumerate_modules_in_process(pi.hProcess, hLast, &inh)) ==
NULL) {
break;
}
@ -640,18 +638,23 @@ bool debugger_replace_dll_iat(const char *expected_dll, const char *replacement_
goto inject_fail;
}
// Search through import table if it exists and replace the target DLL with our DLL filename
// Search through import table if it exists and replace the target DLL with
// our DLL filename
PBYTE pbModule = (PBYTE) hModule;
PIMAGE_SECTION_HEADER pRemoteSectionHeaders
= (PIMAGE_SECTION_HEADER)((PBYTE)pbModule
+ sizeof(inh.Signature)
+ sizeof(inh.FileHeader)
+ inh.FileHeader.SizeOfOptionalHeader);
PIMAGE_SECTION_HEADER pRemoteSectionHeaders =
(PIMAGE_SECTION_HEADER) ((PBYTE) pbModule + sizeof(inh.Signature) +
sizeof(inh.FileHeader) +
inh.FileHeader.SizeOfOptionalHeader);
size_t total_size = inh.OptionalHeader.SizeOfHeaders;
IMAGE_SECTION_HEADER header;
for (DWORD n = 0; n < inh.FileHeader.NumberOfSections; ++n) {
if (!ReadProcessMemory(pi.hProcess, pRemoteSectionHeaders + n, &header, sizeof(header), NULL)) {
if (!ReadProcessMemory(
pi.hProcess,
pRemoteSectionHeaders + n,
&header,
sizeof(header),
NULL)) {
log_warning("Couldn't read section header: %lu", GetLastError());
goto inject_fail;
}
@ -671,17 +674,33 @@ bool debugger_replace_dll_iat(const char *expected_dll, const char *replacement_
log_assert(remote_addr != NULL);
debugger_pe_patch_remote(
pi.hProcess, remote_addr, replacement_path_dll, strlen(replacement_path_dll));
pi.hProcess,
remote_addr,
replacement_path_dll,
strlen(replacement_path_dll));
if (inh.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress != 0) {
PIMAGE_IMPORT_DESCRIPTOR pImageImport = (PIMAGE_IMPORT_DESCRIPTOR)(pbModule
+ inh.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress);
if (inh.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT]
.VirtualAddress != 0) {
PIMAGE_IMPORT_DESCRIPTOR pImageImport =
(PIMAGE_IMPORT_DESCRIPTOR) (pbModule +
inh.OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_IMPORT]
.VirtualAddress);
DWORD size = 0;
while (inh.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size == 0
|| size < inh.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size) {
while (inh.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT]
.Size == 0 ||
size < inh.OptionalHeader
.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT]
.Size) {
IMAGE_IMPORT_DESCRIPTOR ImageImport;
if (!ReadProcessMemory(pi.hProcess, pImageImport, &ImageImport, sizeof(ImageImport), NULL)) {
if (!ReadProcessMemory(
pi.hProcess,
pImageImport,
&ImageImport,
sizeof(ImageImport),
NULL)) {
log_warning("Couldn't read import: %lu", GetLastError());
goto inject_fail;
}
@ -691,11 +710,17 @@ bool debugger_replace_dll_iat(const char *expected_dll, const char *replacement_
}
char name[MAX_PATH] = {0};
if (ReadProcessMemory(pi.hProcess, pbModule + ImageImport.Name, name, sizeof(name), NULL)) {
if (ReadProcessMemory(
pi.hProcess,
pbModule + ImageImport.Name,
name,
sizeof(name),
NULL)) {
// log_misc("\tImport DLL: %ld %s", ImageImport.Name, name);
if (strcmp(name, expected_dll) == 0) {
//log_misc("Replacing %s with %s", name, replacement_path_dll, (void*)pImageImport);
// log_misc("Replacing %s with %s", name,
// replacement_path_dll, (void*)pImageImport);
ImageImport.Name = (DWORD) ((PBYTE) remote_addr - pbModule);
@ -768,9 +793,8 @@ void debugger_finit(bool failure)
}
// Helper functions based on Microsoft Detours
static PVOID load_nt_header_from_process(HANDLE hProcess,
HMODULE hModule,
PIMAGE_NT_HEADERS32 pNtHeader)
static PVOID load_nt_header_from_process(
HANDLE hProcess, HMODULE hModule, PIMAGE_NT_HEADERS32 pNtHeader)
{
PBYTE pbModule = (PBYTE) hModule;
@ -800,8 +824,12 @@ static PVOID load_nt_header_from_process(HANDLE hProcess,
return NULL;
}
if (!ReadProcessMemory(hProcess, pbModule + idh.e_lfanew,
pNtHeader, sizeof(*pNtHeader), NULL)) {
if (!ReadProcessMemory(
hProcess,
pbModule + idh.e_lfanew,
pNtHeader,
sizeof(*pNtHeader),
NULL)) {
log_warning("Could not read NT header: %lu", GetLastError());
return NULL;
}
@ -813,9 +841,8 @@ static PVOID load_nt_header_from_process(HANDLE hProcess,
return pbModule + idh.e_lfanew;
}
static HMODULE enumerate_modules_in_process(HANDLE hProcess,
HMODULE hModuleLast,
PIMAGE_NT_HEADERS32 pNtHeader)
static HMODULE enumerate_modules_in_process(
HANDLE hProcess, HMODULE hModuleLast, PIMAGE_NT_HEADERS32 pNtHeader)
{
PBYTE pbLast = (PBYTE) hModuleLast + MM_ALLOCATION_GRANULARITY;
@ -830,8 +857,8 @@ static HMODULE enumerate_modules_in_process(HANDLE hProcess,
break;
}
// Usermode address space has such an unaligned region size always at the
// end and only at the end.
// Usermode address space has such an unaligned region size always at
// the end and only at the end.
if ((mbi.RegionSize & 0xfff) == 0xfff) {
break;
}
@ -846,7 +873,8 @@ static HMODULE enumerate_modules_in_process(HANDLE hProcess,
continue;
}
if (load_nt_header_from_process(hProcess, (HMODULE)pbLast, pNtHeader)) {
if (load_nt_header_from_process(
hProcess, (HMODULE) pbLast, pNtHeader)) {
return (HMODULE) pbLast;
}
}

View File

@ -2,7 +2,6 @@
#include <stdbool.h>
/**
* Initialize inject's logger backend.
*
@ -14,7 +13,6 @@
* disable.
*/
/**
* Initialize the debugger.
*
@ -58,7 +56,8 @@ bool debugger_inject_dll(const char *path_dll);
* @param replacement_path_dll Name of dll to inject.
* @return true if sucessful, false on error.
*/
bool debugger_replace_dll_iat(const char *expected_dll, const char *replacement_path_dll);
bool debugger_replace_dll_iat(
const char *expected_dll, const char *replacement_path_dll);
/**
* Wait/block for a remote debugger to attach to the remote process.

View File

@ -94,7 +94,8 @@ static size_t logger_msg_coloring_len(const char *str)
return 0;
}
static void logger_console(void *ctx, const char *chars, size_t nchars, const char* timestamp_str)
static void logger_console(
void *ctx, const char *chars, size_t nchars, const char *timestamp_str)
{
char color;
size_t color_len;
@ -128,7 +129,8 @@ static void logger_console(void *ctx, const char *chars, size_t nchars, const ch
}
}
static void logger_file(void *ctx, const char *chars, size_t nchars, const char* timestamp_str)
static void logger_file(
void *ctx, const char *chars, size_t nchars, const char *timestamp_str)
{
if (ctx) {
fwrite(timestamp_str, 1, strlen(timestamp_str), (FILE *) ctx);

View File

@ -92,7 +92,8 @@ verify_hook_dlls_exist(int argc, char **argv, uint32_t hook_dll_count)
if (dll_path_length == 0) {
log_warning(
"ERROR: Hook DLL not found: %08x", (unsigned int) GetLastError());
"ERROR: Hook DLL not found: %08x",
(unsigned int) GetLastError());
return false;
}

View File

@ -2,12 +2,12 @@
#include <windows.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include "hook/com-proxy.h"
#include "hook/table.h"
@ -30,9 +30,7 @@ static void (*real_glBindFramebufferEXT)(GLenum target, GLuint framebuffer);
static void hook_infodispcore_set_angle(void *this, int angle);
static const struct hook_symbol jbhook1_opengl_hook_syms[] = {
{.name = "glFlush",
.patch = hook_glFlush,
.link = (void **) &real_glFlush},
{.name = "glFlush", .patch = hook_glFlush, .link = (void **) &real_glFlush},
};
static const struct hook_symbol jbhook1_glhelper_hook_syms[] = {
@ -47,7 +45,8 @@ static const struct hook_symbol jbhook_infodisp_hook_syms[] = {
.patch = hook_infodispcore_set_angle},
};
void jbhook_util_gfx_install_vertical_hooks(void) {
void jbhook_util_gfx_install_vertical_hooks(void)
{
hook_table_apply(
NULL,
"opengl32.dll",
@ -69,7 +68,8 @@ void jbhook_util_gfx_install_vertical_hooks(void) {
log_info("Inserted vertical display hooks");
}
static void hook_infodispcore_set_angle(void* this, int angle) {
static void hook_infodispcore_set_angle(void *this, int angle)
{
// ignore
}
@ -84,7 +84,8 @@ static void hook_infodispcore_set_angle(void* this, int angle) {
static GLuint fb;
static GLuint color;
static void fb_init(void) {
static void fb_init(void)
{
static bool init_done = false;
if (init_done) {
@ -97,7 +98,8 @@ static void fb_init(void) {
glGenTextures(1, &color);
}
static void __stdcall hook_glFlush(void) {
static void __stdcall hook_glFlush(void)
{
// 3 bytes per RGB pixel
// these could really be stack variables but they are too big for gcc's
// default stack size, and it's no problem for 6MiB of data to hang around
@ -110,7 +112,10 @@ static void __stdcall hook_glFlush(void) {
// speed is not a huge concern.
for (size_t x = 0; x < W; x++) {
for (size_t y = 0; y < H; y++) {
memcpy(&pixels_rot[3*(y*W + x)], &pixels_raw[3*((W-x)*H + y)], 3);
memcpy(
&pixels_rot[3 * (y * W + x)],
&pixels_raw[3 * ((W - x) * H + y)],
3);
}
}
@ -129,11 +134,13 @@ static void __stdcall hook_glFlush(void) {
fb_init();
real_glBindFramebufferEXT(GL_FRAMEBUFFER, fb);
glBindTexture(GL_TEXTURE_2D, color);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, H, W, 0, GL_RGBA,GL_UNSIGNED_BYTE, NULL);
glTexImage2D(
GL_TEXTURE_2D, 0, GL_RGBA, H, W, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0);
glFramebufferTexture2DEXT(
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0);
}
// hooking something in glhelper.dll (a jubeat supplied DLL) might seem
@ -141,7 +148,8 @@ static void __stdcall hook_glFlush(void) {
// loop of the game makes it very difficult to "catch" the rendering at the
// right place otherwise. This works with all horizontal jubeats, and they
// stopped needing rotation fixes starting with saucer.
static void hook_glBindFramebufferEXT(GLenum target, GLuint framebuffer) {
static void hook_glBindFramebufferEXT(GLenum target, GLuint framebuffer)
{
fb_init();
// check this is actually the screen - the game also uses internal

View File

@ -11,29 +11,32 @@
#include "util/defs.h"
#include "util/log.h"
MMRESULT STDCALL hook_mixerGetLineControlsA(HMIXEROBJ hmxobj, LPMIXERLINECONTROLSA pmxlc, DWORD fdwControls);
MMRESULT STDCALL hook_mixerGetDevCapsA(UINT_PTR uMxId, LPMIXERCAPSA pmxcaps, UINT cbmxcaps);
MMRESULT STDCALL hook_mixerOpen(LPHMIXER phmx, UINT uMxId, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen);
MMRESULT STDCALL hook_mixerSetControlDetails(HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails);
MMRESULT STDCALL hook_mixerGetControlDetailsA(HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails);
MMRESULT STDCALL hook_mixerGetLineControlsA(
HMIXEROBJ hmxobj, LPMIXERLINECONTROLSA pmxlc, DWORD fdwControls);
MMRESULT STDCALL
hook_mixerGetDevCapsA(UINT_PTR uMxId, LPMIXERCAPSA pmxcaps, UINT cbmxcaps);
MMRESULT STDCALL hook_mixerOpen(
LPHMIXER phmx,
UINT uMxId,
DWORD_PTR dwCallback,
DWORD_PTR dwInstance,
DWORD fdwOpen);
MMRESULT STDCALL hook_mixerSetControlDetails(
HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails);
MMRESULT STDCALL hook_mixerGetControlDetailsA(
HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails);
MMRESULT STDCALL hook_mixerClose(HMIXER hmx);
MMRESULT STDCALL hook_mixerGetLineInfoA(HMIXEROBJ hmxobj, LPMIXERLINEA pmxl, DWORD fdwInfo);
MMRESULT STDCALL
hook_mixerGetLineInfoA(HMIXEROBJ hmxobj, LPMIXERLINEA pmxl, DWORD fdwInfo);
static const struct hook_symbol mixer_hook_syms[] = {
{.name = "mixerGetLineControlsA",
.patch = hook_mixerGetLineControlsA},
{.name = "mixerGetDevCapsA",
.patch = hook_mixerGetDevCapsA},
{.name = "mixerOpen",
.patch = hook_mixerOpen},
{.name = "mixerSetControlDetails",
.patch = hook_mixerSetControlDetails},
{.name = "mixerGetControlDetailsA",
.patch = hook_mixerGetControlDetailsA},
{.name = "mixerClose",
.patch = hook_mixerClose},
{.name = "mixerGetLineInfoA",
.patch = hook_mixerGetLineInfoA},
{.name = "mixerGetLineControlsA", .patch = hook_mixerGetLineControlsA},
{.name = "mixerGetDevCapsA", .patch = hook_mixerGetDevCapsA},
{.name = "mixerOpen", .patch = hook_mixerOpen},
{.name = "mixerSetControlDetails", .patch = hook_mixerSetControlDetails},
{.name = "mixerGetControlDetailsA", .patch = hook_mixerGetControlDetailsA},
{.name = "mixerClose", .patch = hook_mixerClose},
{.name = "mixerGetLineInfoA", .patch = hook_mixerGetLineInfoA},
};
/*
@ -43,40 +46,57 @@ static const struct hook_symbol mixer_hook_syms[] = {
to not set any of the returning data.
*/
MMRESULT STDCALL hook_mixerOpen(LPHMIXER phmx, UINT uMxId, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen) {
MMRESULT STDCALL hook_mixerOpen(
LPHMIXER phmx,
UINT uMxId,
DWORD_PTR dwCallback,
DWORD_PTR dwInstance,
DWORD fdwOpen)
{
*(DWORD *) phmx = 1234; // any non-zero value is fine
return MMSYSERR_NOERROR;
}
MMRESULT STDCALL hook_mixerClose(HMIXER hmx) {
MMRESULT STDCALL hook_mixerClose(HMIXER hmx)
{
return MMSYSERR_NOERROR;
}
MMRESULT STDCALL hook_mixerGetLineControlsA(HMIXEROBJ hmxobj, LPMIXERLINECONTROLSA pmxlc, DWORD fdwControls) {
MMRESULT STDCALL hook_mixerGetLineControlsA(
HMIXEROBJ hmxobj, LPMIXERLINECONTROLSA pmxlc, DWORD fdwControls)
{
return MMSYSERR_NOERROR;
}
MMRESULT STDCALL hook_mixerGetDevCapsA(UINT_PTR uMxId, LPMIXERCAPSA pmxcaps, UINT cbmxcaps) {
MMRESULT STDCALL
hook_mixerGetDevCapsA(UINT_PTR uMxId, LPMIXERCAPSA pmxcaps, UINT cbmxcaps)
{
return MMSYSERR_NOERROR;
}
MMRESULT STDCALL hook_mixerGetControlDetailsA(HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails) {
MMRESULT STDCALL hook_mixerGetControlDetailsA(
HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails)
{
return MMSYSERR_NOERROR;
}
MMRESULT STDCALL hook_mixerGetLineInfoA(HMIXEROBJ hmxobj, LPMIXERLINEA pmxl, DWORD fdwInfo) {
MMRESULT STDCALL
hook_mixerGetLineInfoA(HMIXEROBJ hmxobj, LPMIXERLINEA pmxl, DWORD fdwInfo)
{
return MMSYSERR_NOERROR;
}
MMRESULT STDCALL hook_mixerSetControlDetails(HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails) {
MMRESULT STDCALL hook_mixerSetControlDetails(
HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails)
{
return MMSYSERR_NOERROR;
}
void jbhook_util_mixer_hook_init(void)
{
hook_table_apply(NULL, "winmm.dll", mixer_hook_syms, lengthof(mixer_hook_syms));
hook_table_apply(
NULL, "winmm.dll", mixer_hook_syms, lengthof(mixer_hook_syms));
log_info("Inserted mixer hooks");
}

View File

@ -173,7 +173,8 @@ static HRESULT jbhook_p3io_get_roundplug(
return S_OK;
}
static HRESULT jbhook_p3io_set_outputs(void *ctx, uint32_t state) {
static HRESULT jbhook_p3io_set_outputs(void *ctx, uint32_t state)
{
uint8_t p3io_panel = (state & 0x00FF00) >> 8;
uint8_t p3io_coinblocker = (state & 0xFF0000) >> 16;

View File

@ -44,7 +44,8 @@ void jbhook_util_ac_io_port_fini(void)
ac_io_emu_fini(&ac_io_emu);
}
void jbhook_util_ac_io_set_iccb(void) {
void jbhook_util_ac_io_set_iccb(void)
{
ac_io_emu_icca_set_version(&ac_io_emu_icca, v150);
ac_io_emu_icca_set_product_code(&ac_io_emu_icca, AC_IO_EMU_PROD_CODE_ICCB);
}

View File

@ -1,9 +1,9 @@
#define LOG_MODULE "eamuse-hook"
#include <iphlpapi.h>
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iphlpapi.h>
#include <stdbool.h>
#include <stdint.h>
@ -30,11 +30,8 @@ static int STDCALL my_getaddrinfo(
const ADDRINFOA *pHints,
PADDRINFOA *ppResult);
static DWORD WINAPI my_GetIpAddrTable(
PMIB_IPADDRTABLE pIpAddrTable,
PULONG pdwSize,
BOOL bOrder
);
static DWORD WINAPI
my_GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder);
static const struct hook_symbol eamuse_hook_syms[] = {
{
@ -73,7 +70,8 @@ static int STDCALL my_getaddrinfo(
return real_getaddrinfo(pNodeName, pServiceName, pHints, ppResult);
}
static DWORD get_best_ip(void) {
static DWORD get_best_ip(void)
{
PIP_ADAPTER_INFO info = NULL;
struct net_addr addr;
// fallback to a very obviously wrong value
@ -114,11 +112,9 @@ CLEANUP:
* check. By also hooking this function, the IP addresses of the two calls will
* agree.
*/
static DWORD WINAPI my_GetIpAddrTable(
PMIB_IPADDRTABLE pIpAddrTable,
PULONG pdwSize,
BOOL bOrder
) {
static DWORD WINAPI
my_GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder)
{
ULONG in = *pdwSize;
// 1 element return table
*pdwSize = sizeof(MIB_IPADDRTABLE) + sizeof(MIB_IPADDRROW);

Some files were not shown because too many files have changed in this diff Show More