diff --git a/src/imports/SMX.h b/src/imports/SMX.h index 3e4459e..a478b50 100644 --- a/src/imports/SMX.h +++ b/src/imports/SMX.h @@ -25,27 +25,33 @@ enum SensorTestMode; enum SMXUpdateCallbackReason; struct SMXSensorTestModeData; -// All functions are nonblocking. Getters will return the most recent state. Setters will -// return immediately and do their work in the background. No functions return errors, and -// setting data on a pad which isn't connected will have no effect. +// All functions are nonblocking. Getters will return the most recent state. +// Setters will return immediately and do their work in the background. No +// functions return errors, and setting data on a pad which isn't connected will +// have no effect. // Initialize, and start searching for devices. // -// UpdateCallback will be called when something happens: connection or disconnection, inputs -// changed, configuration updated, test data updated, etc. It doesn't specify what's changed, -// and the user should check all state that it's interested in. +// UpdateCallback will be called when something happens: connection or +// disconnection, inputs changed, configuration updated, test data updated, etc. +// It doesn't specify what's changed, and the user should check all state that +// it's interested in. // -// This is called asynchronously from a helper thread, so the receiver must be thread-safe. -typedef void SMXUpdateCallback(int pad, enum SMXUpdateCallbackReason reason, void *pUser); -SMX_EXTERN_C SMX_API void SMX_Start(SMXUpdateCallback UpdateCallback, void *pUser); +// This is called asynchronously from a helper thread, so the receiver must be +// thread-safe. +typedef void +SMXUpdateCallback(int pad, enum SMXUpdateCallbackReason reason, void *pUser); +SMX_EXTERN_C SMX_API void +SMX_Start(SMXUpdateCallback UpdateCallback, void *pUser); -// Shut down and disconnect from all devices. This will wait for any user callbacks to complete, -// and no user callbacks will be called after this returns. This must not be called from within -// the update callback. +// Shut down and disconnect from all devices. This will wait for any user +// callbacks to complete, and no user callbacks will be called after this +// returns. This must not be called from within the update callback. SMX_EXTERN_C SMX_API void SMX_Stop(); -// Set a function to receive diagnostic logs. By default, logs are written to stdout. -// This can be called before SMX_Start, so it affects any logs sent during initialization. +// Set a function to receive diagnostic logs. By default, logs are written to +// stdout. This can be called before SMX_Start, so it affects any logs sent +// during initialization. typedef void SMXLogCallback(const char *log); SMX_EXTERN_C SMX_API void SMX_SetLogCallback(SMXLogCallback callback); @@ -55,8 +61,9 @@ SMX_EXTERN_C SMX_API void SMX_GetInfo(int pad, struct SMXInfo *info); // Get a mask of the currently pressed panels. SMX_EXTERN_C SMX_API uint16_t SMX_GetInputState(int pad); -// Update the lights. Both pads are always updated together. lightsData is a list of 8-bit RGB -// colors, one for each LED. Each panel has lights in the following order: +// Update the lights. Both pads are always updated together. lightsData is a +// list of 8-bit RGB colors, one for each LED. Each panel has lights in the +// following order: // // 0123 // 4567 @@ -69,61 +76,70 @@ SMX_EXTERN_C SMX_API uint16_t SMX_GetInputState(int pad); // 345 CDE // 678 F01 // -// With 18 panels, 16 LEDs per panel and 3 bytes per LED, each light update has 864 bytes of data. +// With 18 panels, 16 LEDs per panel and 3 bytes per LED, each light update has +// 864 bytes of data. // -// Lights will update at up to 30 FPS. If lights data is sent more quickly, a best effort will be -// made to send the most recent lights data available, but the panels won't update more quickly. +// Lights will update at up to 30 FPS. If lights data is sent more quickly, a +// best effort will be made to send the most recent lights data available, but +// the panels won't update more quickly. // -// The panels will return to automatic lighting if no lights are received for a while, so applications -// controlling lights should send light updates continually, even if the lights aren't changing. +// The panels will return to automatic lighting if no lights are received for a +// while, so applications controlling lights should send light updates +// continually, even if the lights aren't changing. SMX_EXTERN_C SMX_API void SMX_SetLights(const char lightsData[864]); -// By default, the panels light automatically when stepped on. If a lights command is sent by -// the application, this stops happening to allow the application to fully control lighting. -// If no lights update is received for a few seconds, automatic lighting is reenabled by the -// panels. +// By default, the panels light automatically when stepped on. If a lights +// command is sent by the application, this stops happening to allow the +// application to fully control lighting. If no lights update is received for a +// few seconds, automatic lighting is reenabled by the panels. // -// SMX_ReenableAutoLights can be called to immediately reenable auto-lighting, without waiting -// for the timeout period to elapse. Games don't need to call this, since the panels will return -// to auto-lighting mode automatically after a brief period of no updates. +// SMX_ReenableAutoLights can be called to immediately reenable auto-lighting, +// without waiting for the timeout period to elapse. Games don't need to call +// this, since the panels will return to auto-lighting mode automatically after +// a brief period of no updates. SMX_EXTERN_C SMX_API void SMX_ReenableAutoLights(); // Get the current controller's configuration. // -// Return true if a configuration is available. If false is returned, no panel is connected -// and no data will be set. +// Return true if a configuration is available. If false is returned, no panel +// is connected and no data will be set. SMX_EXTERN_C SMX_API bool SMX_GetConfig(int pad, struct SMXConfig *config); -// Update the current controller's configuration. This doesn't block, and the new configuration will -// be sent in the background. SMX_GetConfig will return the new configuration as soon as this call -// returns, without waiting for it to actually be sent to the controller. -SMX_EXTERN_C SMX_API void SMX_SetConfig(int pad, const struct SMXConfig *config); +// Update the current controller's configuration. This doesn't block, and the +// new configuration will be sent in the background. SMX_GetConfig will return +// the new configuration as soon as this call returns, without waiting for it to +// actually be sent to the controller. +SMX_EXTERN_C SMX_API void +SMX_SetConfig(int pad, const struct SMXConfig *config); // Reset a pad to its original configuration. SMX_EXTERN_C SMX_API void SMX_FactoryReset(int pad); -// Request an immediate panel recalibration. This is normally not necessary, but can be helpful -// for diagnostics. +// Request an immediate panel recalibration. This is normally not necessary, +// but can be helpful for diagnostics. SMX_EXTERN_C SMX_API void SMX_ForceRecalibration(int pad); -// Set a panel test mode and request test data. This is used by the configuration tool. +// Set a panel test mode and request test data. This is used by the +// configuration tool. SMX_EXTERN_C SMX_API void SMX_SetTestMode(int pad, enum SensorTestMode mode); -SMX_EXTERN_C SMX_API bool SMX_GetTestData(int pad, struct SMXSensorTestModeData *data); +SMX_EXTERN_C SMX_API bool +SMX_GetTestData(int pad, struct SMXSensorTestModeData *data); -// Return the build version of the DLL, which is based on the git tag at build time. This -// is only intended for diagnostic logging, and it's also the version we show in SMXConfig. +// Return the build version of the DLL, which is based on the git tag at build +// time. This is only intended for diagnostic logging, and it's also the +// version we show in SMXConfig. SMX_EXTERN_C SMX_API const char *SMX_Version(); -// General info about a connected controller. This can be retrieved with SMX_GetInfo. -struct SMXInfo -{ - // True if we're fully connected to this controller. If this is false, the other - // fields won't be set. +// General info about a connected controller. This can be retrieved with +// SMX_GetInfo. +struct SMXInfo { + // True if we're fully connected to this controller. If this is false, the + // other fields won't be set. bool m_bConnected; - // This device's serial number. This can be used to distinguish devices from each - // other if more than one is connected. This is a null-terminated string instead - // of a C++ string for C# marshalling. + // This device's serial number. This can be used to distinguish devices + // from each other if more than one is connected. This is a null-terminated + // string instead of a C++ string for C# marshalling. char m_Serial[33]; // This device's firmware version. @@ -131,22 +147,24 @@ struct SMXInfo }; enum SMXUpdateCallbackReason { - // This is called when a generic state change happens: connection or disconnection, inputs changed, - // test data updated, etc. It doesn't specify what's changed. We simply check the whole state. + // This is called when a generic state change happens: connection or + // disconnection, inputs changed, + // test data updated, etc. It doesn't specify what's changed. We simply + // check the whole state. SMXUpdateCallback_Updated, - // This is called when SMX_FactoryReset completes, indicating that SMX_GetConfig will now return + // This is called when SMX_FactoryReset completes, indicating that + // SMX_GetConfig will now return // the reset configuration. SMXUpdateCallback_FactoryResetCommandComplete }; -// The configuration for a connected controller. This can be retrieved with SMX_GetConfig -// and modified with SMX_SetConfig. +// The configuration for a connected controller. This can be retrieved with +// SMX_GetConfig and modified with SMX_SetConfig. // -// The order and packing of this struct corresponds to the configuration packet sent to -// the master controller, so it must not be changed. -struct SMXConfig -{ +// The order and packing of this struct corresponds to the configuration packet +// sent to the master controller, so it must not be changed. +struct SMXConfig { #if 0 // These fields are unused and must be left at their existing values. uint8_t unused1 = 0xFF, unused2 = 0xFF; @@ -228,9 +246,10 @@ struct SMXConfig uint8_t panelThreshold8Low, panelThreshold8High; #endif }; -//static_assert(sizeof(SMXConfig) == 84, "Expected 84 bytes"); +// static_assert(sizeof(SMXConfig) == 84, "Expected 84 bytes"); -// The values (except for Off) correspond with the protocol and must not be changed. +// The values (except for Off) correspond with the protocol and must not be +// changed. enum SensorTestMode { SensorTestMode_Off = 0, // Return the raw, uncalibrated value of each sensor. @@ -246,10 +265,11 @@ enum SensorTestMode { SensorTestMode_Tare = '3', }; -// Data for the current SensorTestMode. The interpretation of sensorLevel depends on the mode. -struct SMXSensorTestModeData -{ - // If false, sensorLevel[n][*] is zero because we didn't receive a response from that panel. +// Data for the current SensorTestMode. The interpretation of sensorLevel +// depends on the mode. +struct SMXSensorTestModeData { + // If false, sensorLevel[n][*] is zero because we didn't receive a response + // from that panel. bool bHaveDataFromPanel[9]; int16_t sensorLevel[9][4]; diff --git a/src/imports/avs.h b/src/imports/avs.h index 589863a..3847b45 100644 --- a/src/imports/avs.h +++ b/src/imports/avs.h @@ -74,45 +74,44 @@ struct property_psmap { intptr_t xdefault; }; -#define PSMAP_BEGIN(name) \ - struct property_psmap name[] = { - +#define PSMAP_BEGIN(name) struct property_psmap name[] = { #define PSMAP_REQUIRED(type, xstruct, field, path) \ - { \ - type, \ - 0, \ - offsetof(xstruct, field), \ - sizeof( ((xstruct *) 0)->field ), \ - path, \ - 0, \ - }, \ + { \ + type, \ + 0, \ + offsetof(xstruct, field), \ + sizeof(((xstruct *) 0)->field), \ + path, \ + 0, \ + }, #define PSMAP_OPTIONAL(type, xstruct, field, path, xdefault) \ - { \ - type, \ - PSMAP_FLAG_HAVE_DEFAULT, \ - offsetof(xstruct, field), \ - sizeof( ((xstruct *) 0)->field ), \ - path, \ - (intptr_t) xdefault, \ - }, \ + { \ + type, \ + PSMAP_FLAG_HAVE_DEFAULT, \ + offsetof(xstruct, field), \ + sizeof(((xstruct *) 0)->field), \ + path, \ + (intptr_t) xdefault, \ + }, -#define PSMAP_END \ - { 0xFF, 0, 0, 0, NULL, 0 } \ - }; +#define PSMAP_END \ + { \ + 0xFF, 0, 0, 0, NULL, 0 \ + } \ + } \ + ; #if AVS_VERSION >= 1500 -# define AVS_LOG_WRITER(name, chars, nchars, ctx) \ - void name(const char * chars , uint32_t nchars , void * ctx ) +#define AVS_LOG_WRITER(name, chars, nchars, ctx) \ + void name(const char *chars, uint32_t nchars, void *ctx) - typedef void (*avs_log_writer_t)(const char *chars, uint32_t nchars, - void *ctx); +typedef void (*avs_log_writer_t)(const char *chars, uint32_t nchars, void *ctx); #else -# define AVS_LOG_WRITER(name, chars, nchars, ctx) \ - void name(void * ctx , const char * chars , uint32_t nchars ) +#define AVS_LOG_WRITER(name, chars, nchars, ctx) \ + void name(void *ctx, const char *chars, uint32_t nchars) - typedef void (*avs_log_writer_t)(void *ctx, const char *chars, - uint32_t nchars); +typedef void (*avs_log_writer_t)(void *ctx, const char *chars, uint32_t nchars); #endif typedef int (*avs_reader_t)(uint32_t context, void *bytes, size_t nbytes); @@ -120,22 +119,38 @@ typedef int (*avs_reader_t)(uint32_t context, void *bytes, size_t nbytes); #if AVS_VERSION >= 1600 /* "avs" and "std" heaps have been unified */ typedef void (*avs_boot_t)( - struct property_node *config, void *com_heap, size_t sz_com_heap, - void *reserved, avs_log_writer_t log_writer, void *log_context); + struct property_node *config, + void *com_heap, + size_t sz_com_heap, + void *reserved, + avs_log_writer_t log_writer, + void *log_context); void avs_boot( - struct property_node *config, void *com_heap, size_t sz_com_heap, - void *reserved, avs_log_writer_t log_writer, void *log_context); + struct property_node *config, + void *com_heap, + size_t sz_com_heap, + void *reserved, + avs_log_writer_t log_writer, + void *log_context); #else typedef void (*avs_boot_t)( - struct property_node *config, void *std_heap, size_t sz_std_heap, - void *avs_heap, size_t sz_avs_heap, avs_log_writer_t log_writer, - void* log_context); + struct property_node *config, + void *std_heap, + size_t sz_std_heap, + void *avs_heap, + size_t sz_avs_heap, + avs_log_writer_t log_writer, + void *log_context); void avs_boot( - struct property_node *config, void *std_heap, size_t sz_std_heap, - void *avs_heap, size_t sz_avs_heap, avs_log_writer_t log_writer, - void *log_context); + struct property_node *config, + void *std_heap, + size_t sz_std_heap, + void *avs_heap, + size_t sz_avs_heap, + avs_log_writer_t log_writer, + void *log_context); #endif void avs_shutdown(void); @@ -149,54 +164,68 @@ void log_change_level(int level); int avs_net_ctrl(int ioctl, void *bytes, uint32_t nbytes); -int avs_thread_create(int (*proc)(void *), void *ctx, uint32_t sz_stack, - unsigned int priority); +int avs_thread_create( + int (*proc)(void *), void *ctx, uint32_t sz_stack, unsigned int priority); void avs_thread_destroy(int thread_id); void avs_thread_exit(int result); void avs_thread_join(int thread_id, int *result); uint32_t property_read_query_memsize( - avs_reader_t reader, uint32_t context, int unk0, int unk1); -struct property *property_create( - int flags, void *buffer, uint32_t buffer_size); + avs_reader_t reader, uint32_t context, int unk0, int unk1); +struct property *property_create(int flags, void *buffer, uint32_t buffer_size); struct property_node *property_search( - struct property *prop, struct property_node *root, const char *path); + struct property *prop, struct property_node *root, const char *path); int property_insert_read( - struct property *prop, struct property_node *root, avs_reader_t reader, - uint32_t context); + struct property *prop, + struct property_node *root, + avs_reader_t reader, + uint32_t context); int property_mem_write(struct property *prop, void *bytes, int nbytes); void *property_desc_to_buffer(struct property *prop); void property_file_write(struct property *prop, const char *path); int property_set_flag(struct property *prop, int flags, int mask); void property_destroy(struct property *prop); -int property_psmap_import(struct property *prop, struct property_node *root, - void *dest, const struct property_psmap *psmap); -int property_psmap_export(struct property *prop, struct property_node *root, - const void *src, const struct property_psmap *psmap); +int property_psmap_import( + struct property *prop, + struct property_node *root, + void *dest, + const struct property_psmap *psmap); +int property_psmap_export( + struct property *prop, + struct property_node *root, + const void *src, + const struct property_psmap *psmap); struct property_node *property_node_clone( - struct property *new_parent, int unk0, - struct property_node *src, bool deep); + struct property *new_parent, + int unk0, + struct property_node *src, + bool deep); struct property_node *property_node_create( - struct property *prop, struct property_node *parent, int type, - const char *key, ...); -void property_node_name( - struct property_node *node, char *chars, int nchars); + struct property *prop, + struct property_node *parent, + int type, + const char *key, + ...); +void property_node_name(struct property_node *node, char *chars, int nchars); const char *property_node_refdata(struct property_node *node); -int property_node_refer(struct property *prop, - struct property_node *node, const char *name, - enum property_type type, void *bytes, uint32_t nbytes); +int property_node_refer( + struct property *prop, + struct property_node *node, + const char *name, + enum property_type type, + void *bytes, + uint32_t nbytes); void property_node_remove(struct property_node *node); -enum property_type property_node_type( - struct property_node *node); +enum property_type property_node_type(struct property_node *node); struct property_node *property_node_traversal( - struct property_node *node, enum property_node_traversal direction); -void property_node_datasize(struct property_node* node); + struct property_node *node, enum property_node_traversal direction); +void property_node_datasize(struct property_node *node); bool std_getenv(const char *key, char *val, uint32_t nbytes); void std_setenv(const char *key, const char *val); -void *avs_fs_mount (char* mountpoint, char* fsroot, void* fstype, int flags); +void *avs_fs_mount(char *mountpoint, char *fsroot, void *fstype, int flags); #endif diff --git a/src/main/acio/acio.h b/src/main/acio/acio.h index dbfe434..0247ebb 100644 --- a/src/main/acio/acio.h +++ b/src/main/acio/acio.h @@ -8,33 +8,33 @@ #include "acio/icca.h" #include "acio/kfca.h" -#define AC_IO_SOF 0xAA -#define AC_IO_ESCAPE 0xFF -#define AC_IO_RESPONSE_FLAG 0x80 -#define AC_IO_BROADCAST 0x70 +#define AC_IO_SOF 0xAA +#define AC_IO_ESCAPE 0xFF +#define AC_IO_RESPONSE_FLAG 0x80 +#define AC_IO_BROADCAST 0x70 -#define ac_io_u16(x) _byteswap_ushort(x) -#define ac_io_u32(x) _byteswap_ulong(x) +#define ac_io_u16(x) _byteswap_ushort(x) +#define ac_io_u32(x) _byteswap_ulong(x) enum ac_io_cmd { - AC_IO_CMD_ASSIGN_ADDRS = 0x0001, - AC_IO_CMD_GET_VERSION = 0x0002, - AC_IO_CMD_START_UP = 0x0003, - AC_IO_CMD_KEEPALIVE = 0x0080, + AC_IO_CMD_ASSIGN_ADDRS = 0x0001, + AC_IO_CMD_GET_VERSION = 0x0002, + AC_IO_CMD_START_UP = 0x0003, + AC_IO_CMD_KEEPALIVE = 0x0080, /* Yet unknown command encountered first on jubeat (1) */ - AC_IO_CMD_UNKN_00FF = 0x00FF, - AC_IO_CMD_CLEAR = 0x0100, + AC_IO_CMD_UNKN_00FF = 0x00FF, + AC_IO_CMD_CLEAR = 0x0100, }; enum ac_io_node_type { - AC_IO_NODE_TYPE_H44B = 0x04010000, - AC_IO_NODE_TYPE_ICCA = 0x03000000, + AC_IO_NODE_TYPE_H44B = 0x04010000, + AC_IO_NODE_TYPE_ICCA = 0x03000000, /* same as ICCA */ - AC_IO_NODE_TYPE_ICCB = 0x03000000, - AC_IO_NODE_TYPE_LED_STRIP = 0x04020000, - AC_IO_NODE_TYPE_LED_SPIKE = 0x05010000, - AC_IO_NODE_TYPE_KFCA = 0x09060000, - AC_IO_NODE_TYPE_BI2A = 0x0d060000, + AC_IO_NODE_TYPE_ICCB = 0x03000000, + AC_IO_NODE_TYPE_LED_STRIP = 0x04020000, + AC_IO_NODE_TYPE_LED_SPIKE = 0x05010000, + AC_IO_NODE_TYPE_KFCA = 0x09060000, + AC_IO_NODE_TYPE_BI2A = 0x0d060000, }; #pragma pack(push, 1) @@ -52,7 +52,7 @@ struct ac_io_version { }; struct ac_io_message { - uint8_t addr; /* High bit: clear = req, set = resp */ + uint8_t addr; /* High bit: clear = req, set = resp */ union { struct { @@ -76,7 +76,7 @@ struct ac_io_message { struct { uint8_t nbytes; - uint8_t raw[0xFF]; /* 0xFFucked if I know */ + uint8_t raw[0xFF]; /* 0xFFucked if I know */ } bcast; }; }; diff --git a/src/main/acio/icca.h b/src/main/acio/icca.h index f95a686..50519ca 100644 --- a/src/main/acio/icca.h +++ b/src/main/acio/icca.h @@ -5,13 +5,13 @@ enum ac_io_icca_cmd { /* Yet unknown command encountered first on jubeat (1) */ - AC_IO_ICCA_CMD_UNKN_0120 = 0x0120, + AC_IO_ICCA_CMD_UNKN_0120 = 0x0120, AC_IO_ICCA_CMD_QUEUE_LOOP_START = 0x0130, - AC_IO_ICCA_CMD_ENGAGE = 0x0131, - AC_IO_ICCA_CMD_POLL = 0x0134, - AC_IO_ICCA_CMD_SET_SLOT_STATE = 0x0135, - AC_IO_ICCA_CMD_BEGIN_KEYPAD = 0x013A, - AC_IO_ICCA_CMD_POLL_FELICA = 0x0161, + AC_IO_ICCA_CMD_ENGAGE = 0x0131, + AC_IO_ICCA_CMD_POLL = 0x0134, + AC_IO_ICCA_CMD_SET_SLOT_STATE = 0x0135, + AC_IO_ICCA_CMD_BEGIN_KEYPAD = 0x013A, + AC_IO_ICCA_CMD_POLL_FELICA = 0x0161, }; enum ac_io_icca_slot_state { diff --git a/src/main/acio/iccb.h b/src/main/acio/iccb.h index c35a46a..4928054 100644 --- a/src/main/acio/iccb.h +++ b/src/main/acio/iccb.h @@ -5,16 +5,16 @@ enum ac_io_iccb_cmd { /* found on jubeat prop, sent after acio init req, maybe fw update? */ - AC_IO_ICCB_CMD_UNK_0100 = 0x0100, + AC_IO_ICCB_CMD_UNK_0100 = 0x0100, /* found on jubeat prop, sent right after queue loop start */ - AC_IO_ICCB_CMD_UNK_0116 = 0x0116, + AC_IO_ICCB_CMD_UNK_0116 = 0x0116, /* found on jubeat prop, sent after 0100 req */ - AC_IO_ICCB_CMD_UNK_0120 = 0x0120, + AC_IO_ICCB_CMD_UNK_0120 = 0x0120, AC_IO_ICCB_CMD_QUEUE_LOOP_START = 0x0130, - AC_IO_ICCB_CMD_POLL = 0x0134, - AC_IO_ICCB_CMD_UNK_135 = 0x0135, - AC_IO_ICCB_CMD_SLEEP = 0x013A, - AC_IO_ICCB_CMD_READ_CARD = 0x0161 + AC_IO_ICCB_CMD_POLL = 0x0134, + AC_IO_ICCB_CMD_UNK_135 = 0x0135, + AC_IO_ICCB_CMD_SLEEP = 0x013A, + AC_IO_ICCB_CMD_READ_CARD = 0x0161 }; enum ac_io_iccb_sensor_state { diff --git a/src/main/acio/kfca.h b/src/main/acio/kfca.h index 1132603..d8b31c3 100644 --- a/src/main/acio/kfca.h +++ b/src/main/acio/kfca.h @@ -1,25 +1,25 @@ #ifndef AC_IO_KFCA_H #define AC_IO_KFCA_H -#define AC_IO_CMD_KFCA_POLL 0x0113 -#define AC_IO_CMD_KFCA_WATCHDOG 0x0120 -#define AC_IO_CMD_KFCA_AMP_CONTROL 0x0128 +#define AC_IO_CMD_KFCA_POLL 0x0113 +#define AC_IO_CMD_KFCA_WATCHDOG 0x0120 +#define AC_IO_CMD_KFCA_AMP_CONTROL 0x0128 -#define AC_IO_KFCA_IN_GPIO_SYS_COIN 0x04 +#define AC_IO_KFCA_IN_GPIO_SYS_COIN 0x04 /* ... AC_IO_KFCA_IN_GPIO_SYS_COIN2 0x08 (maybe?) */ -#define AC_IO_KFCA_IN_GPIO_SYS_TEST 0x10 -#define AC_IO_KFCA_IN_GPIO_SYS_SERVICE 0x20 +#define AC_IO_KFCA_IN_GPIO_SYS_TEST 0x10 +#define AC_IO_KFCA_IN_GPIO_SYS_SERVICE 0x20 -#define AC_IO_KFCA_IN_GPIO_0_C 0x0001 -#define AC_IO_KFCA_IN_GPIO_0_B 0x0002 -#define AC_IO_KFCA_IN_GPIO_0_A 0x0004 -#define AC_IO_KFCA_IN_GPIO_0_START 0x0008 -#define AC_IO_KFCA_IN_GPIO_0_RECORDER 0x0010 -#define AC_IO_KFCA_IN_GPIO_0_HEADPHONE 0x0020 +#define AC_IO_KFCA_IN_GPIO_0_C 0x0001 +#define AC_IO_KFCA_IN_GPIO_0_B 0x0002 +#define AC_IO_KFCA_IN_GPIO_0_A 0x0004 +#define AC_IO_KFCA_IN_GPIO_0_START 0x0008 +#define AC_IO_KFCA_IN_GPIO_0_RECORDER 0x0010 +#define AC_IO_KFCA_IN_GPIO_0_HEADPHONE 0x0020 -#define AC_IO_KFCA_IN_GPIO_1_FX_R 0x0008 -#define AC_IO_KFCA_IN_GPIO_1_FX_L 0x0010 -#define AC_IO_KFCA_IN_GPIO_1_D 0x0020 +#define AC_IO_KFCA_IN_GPIO_1_FX_R 0x0008 +#define AC_IO_KFCA_IN_GPIO_1_FX_L 0x0010 +#define AC_IO_KFCA_IN_GPIO_1_D 0x0020 #pragma pack(push, 1) diff --git a/src/main/aciodrv/device.c b/src/main/aciodrv/device.c index 533735b..ee42e6a 100644 --- a/src/main/aciodrv/device.c +++ b/src/main/aciodrv/device.c @@ -43,17 +43,17 @@ static bool aciodrv_device_init(void) } #ifdef AC_IO_MSG_LOG -static void aciodrv_device_log_buffer(const char* msg, const uint8_t* buffer, - int length) +static void +aciodrv_device_log_buffer(const char *msg, const uint8_t *buffer, int length) { char str[4096]; - hex_encode_uc((const void*) buffer, length, str, sizeof(str)); + hex_encode_uc((const void *) buffer, length, str, sizeof(str)); log_misc("%s, length %d: %s", msg, length, str); } #endif -static bool aciodrv_device_send(const uint8_t* buffer, int length) +static bool aciodrv_device_send(const uint8_t *buffer, int length) { uint8_t send_buf[512]; int send_buf_pos = 0; @@ -102,7 +102,7 @@ static bool aciodrv_device_send(const uint8_t* buffer, int length) return true; } -static int aciodrv_device_receive(uint8_t* buffer, int size) +static int aciodrv_device_receive(uint8_t *buffer, int size) { uint8_t recv_buf[512]; int recv_size = 0; @@ -142,8 +142,7 @@ static int aciodrv_device_receive(uint8_t* buffer, int size) /* check for escape byte. these don't count towards the size we expect! */ - if (recv_buf[recv_size] == AC_IO_ESCAPE) - { + if (recv_buf[recv_size] == AC_IO_ESCAPE) { /* next byte is our real data overwrite escape byte */ do { @@ -162,7 +161,7 @@ static int aciodrv_device_receive(uint8_t* buffer, int size) } #ifdef AC_IO_MSG_LOG - aciodrv_device_log_buffer("Recv (1)", recv_buf, recv_size); + aciodrv_device_log_buffer("Recv (1)", recv_buf, recv_size); #endif /* recv_size - 1: omit checksum for checksum calc */ @@ -174,12 +173,14 @@ static int aciodrv_device_receive(uint8_t* buffer, int size) result_size = recv_size - 1; #ifdef AC_IO_MSG_LOG - aciodrv_device_log_buffer("Recv (2)", buffer, result_size); + aciodrv_device_log_buffer("Recv (2)", buffer, result_size); #endif if (checksum != recv_buf[recv_size - 1]) { - log_warning("Invalid message checksum: %02X != %02X", - checksum, recv_buf[recv_size - 1]); + log_warning( + "Invalid message checksum: %02X != %02X", + checksum, + recv_buf[recv_size - 1]); return -1; } @@ -198,7 +199,8 @@ static uint8_t aciodrv_device_enum_nodes(void) msg.cmd.nbytes = 1; msg.cmd.count = 0; - if (!aciodrv_send_and_recv(&msg, offsetof(struct ac_io_message, cmd.raw) + 1)) { + if (!aciodrv_send_and_recv( + &msg, offsetof(struct ac_io_message, cmd.raw) + 1)) { log_warning("Enumerating nodes failed"); return 0; } @@ -216,13 +218,16 @@ static bool aciodrv_device_get_version(uint8_t node_id, char product[4]) msg.cmd.code = ac_io_u16(AC_IO_CMD_GET_VERSION); msg.cmd.nbytes = 0; - if ( !aciodrv_send_and_recv(&msg, offsetof(struct ac_io_message, cmd.raw) + - sizeof(struct ac_io_version))) { + if (!aciodrv_send_and_recv( + &msg, + offsetof(struct ac_io_message, cmd.raw) + + sizeof(struct ac_io_version))) { log_warning("Get version of node %d failed", node_id); return false; } - log_info("Node %d: type %d, flag %d, version %d.%d.%d, product %c%c%c%c, " + log_info( + "Node %d: type %d, flag %d, version %d.%d.%d, product %c%c%c%c, " "build date: %s %s", node_id, msg.cmd.version.type, @@ -250,7 +255,8 @@ static bool aciodrv_device_start_node(uint8_t node_id) msg.cmd.code = ac_io_u16(AC_IO_CMD_START_UP); msg.cmd.nbytes = 0; - if (!aciodrv_send_and_recv(&msg, offsetof(struct ac_io_message, cmd.raw) + 1)) { + if (!aciodrv_send_and_recv( + &msg, offsetof(struct ac_io_message, cmd.raw) + 1)) { log_warning("Starting node %d failed", node_id); return false; } @@ -259,7 +265,7 @@ static bool aciodrv_device_start_node(uint8_t node_id) return true; } -bool aciodrv_device_open(const char* port, int baud) +bool aciodrv_device_open(const char *port, int baud) { if (!aciodrv_port_open(port, baud)) { return false; @@ -275,7 +281,8 @@ bool aciodrv_device_open(const char* port, int baud) } for (uint8_t i = 0; i < aciodrv_device_node_count; i++) { - if (!aciodrv_device_get_version(i + 1, aviodrv_device_node_products[i])) { + if (!aciodrv_device_get_version( + i + 1, aviodrv_device_node_products[i])) { return false; } } @@ -304,25 +311,27 @@ bool aciodrv_device_get_node_product_ident(uint8_t node_id, char product[4]) return true; } -bool aciodrv_send_and_recv(struct ac_io_message* msg, int resp_size) +bool aciodrv_send_and_recv(struct ac_io_message *msg, int resp_size) { msg->cmd.seq_no = aciodrv_device_msg_counter++; - if (aciodrv_device_send((uint8_t*) msg, + if (aciodrv_device_send( + (uint8_t *) msg, offsetof(struct ac_io_message, cmd.raw) + msg->cmd.nbytes) <= 0) { return false; } uint16_t req_code = msg->cmd.code; - if (aciodrv_device_receive((uint8_t*) msg, - resp_size) <= 0) { + if (aciodrv_device_receive((uint8_t *) msg, resp_size) <= 0) { return false; } if (req_code != msg->cmd.code) { - log_warning("Received invalid response %04X for request %04X", - msg->cmd.code, req_code); + log_warning( + "Received invalid response %04X for request %04X", + msg->cmd.code, + req_code); return false; } diff --git a/src/main/aciodrv/device.h b/src/main/aciodrv/device.h index 9b5df18..62f544b 100644 --- a/src/main/aciodrv/device.h +++ b/src/main/aciodrv/device.h @@ -13,7 +13,7 @@ * @return True if opening the port and resetting the device was successful, * false on error. */ -bool aciodrv_device_open(const char* port, int baud); +bool aciodrv_device_open(const char *port, int baud); /** * Get the node count on the opened device. @@ -27,8 +27,8 @@ uint8_t aciodrv_device_get_node_count(void); * * @param node_id Id of the node. Needs to be in range of the total node count. * @param product Buffer to return the product id to. - * @return True on success, false on error. If True the variable product contains - * the identifier of the queried node. + * @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(uint8_t node_id, char product[4]); @@ -42,7 +42,7 @@ bool aciodrv_device_get_node_product_ident(uint8_t node_id, char product[4]); * @param resp_size Size of the expecting response. * @return True on success, false on error. */ -bool aciodrv_send_and_recv(struct ac_io_message* msg, int resp_size); +bool aciodrv_send_and_recv(struct ac_io_message *msg, int resp_size); /** * Close the previously opened ACIO device. diff --git a/src/main/aciodrv/icca.c b/src/main/aciodrv/icca.c index 6029e0c..52a63a0 100644 --- a/src/main/aciodrv/icca.c +++ b/src/main/aciodrv/icca.c @@ -15,13 +15,14 @@ static bool aciodrv_icca_queue_loop_start(uint8_t node_id) msg.cmd.nbytes = 1; msg.cmd.status = 0; - if (!aciodrv_send_and_recv(&msg, offsetof(struct ac_io_message, cmd.raw) + 1)) { + if (!aciodrv_send_and_recv( + &msg, offsetof(struct ac_io_message, cmd.raw) + 1)) { log_warning("Starting queue loop failed"); return false; } - log_info("Started queue loop of node %d, status: %d", - node_id, msg.cmd.status); + log_info( + "Started queue loop of node %d, status: %d", node_id, msg.cmd.status); return true; } @@ -35,8 +36,8 @@ bool aciodrv_icca_init(uint8_t node_id) return true; } -bool aciodrv_icca_set_state(uint8_t node_id, int slot_state, - struct ac_io_icca_state* state) +bool aciodrv_icca_set_state( + uint8_t node_id, int slot_state, struct ac_io_icca_state *state) { struct ac_io_message msg; @@ -47,8 +48,8 @@ bool aciodrv_icca_set_state(uint8_t node_id, int slot_state, msg.cmd.raw[0] = sizeof(struct ac_io_icca_state); msg.cmd.raw[1] = slot_state; - if ( !aciodrv_send_and_recv(&msg, offsetof(struct ac_io_message, cmd.raw) + - msg.cmd.raw[0])) { + if (!aciodrv_send_and_recv( + &msg, offsetof(struct ac_io_message, cmd.raw) + msg.cmd.raw[0])) { log_warning("Setting state of node %d failed", node_id + 1); return false; } @@ -60,7 +61,7 @@ bool aciodrv_icca_set_state(uint8_t node_id, int slot_state, return true; } -bool aciodrv_icca_get_state(uint8_t node_id, struct ac_io_icca_state* state) +bool aciodrv_icca_get_state(uint8_t node_id, struct ac_io_icca_state *state) { struct ac_io_message msg; @@ -70,8 +71,8 @@ bool aciodrv_icca_get_state(uint8_t node_id, struct ac_io_icca_state* state) /* buffer size of data we expect */ msg.cmd.count = sizeof(struct ac_io_icca_state); - if ( !aciodrv_send_and_recv(&msg, offsetof(struct ac_io_message, cmd.raw) + - msg.cmd.count)) { + if (!aciodrv_send_and_recv( + &msg, offsetof(struct ac_io_message, cmd.raw) + msg.cmd.count)) { log_warning("Getting state of node %d failed", node_id + 1); return false; } @@ -83,7 +84,7 @@ bool aciodrv_icca_get_state(uint8_t node_id, struct ac_io_icca_state* state) return true; } -bool aciodrv_icca_read_card(uint8_t node_id, struct ac_io_icca_state* state) +bool aciodrv_icca_read_card(uint8_t node_id, struct ac_io_icca_state *state) { struct ac_io_message msg; @@ -93,8 +94,8 @@ bool aciodrv_icca_read_card(uint8_t node_id, struct ac_io_icca_state* state) /* buffer size of data we expect */ msg.cmd.count = sizeof(struct ac_io_icca_state); - if ( !aciodrv_send_and_recv(&msg, offsetof(struct ac_io_message, cmd.raw) + - msg.cmd.count)) { + if (!aciodrv_send_and_recv( + &msg, offsetof(struct ac_io_message, cmd.raw) + msg.cmd.count)) { log_warning("Reading card of node %d failed", node_id + 1); return false; } diff --git a/src/main/aciodrv/icca.h b/src/main/aciodrv/icca.h index b75afc6..ddae29e 100644 --- a/src/main/aciodrv/icca.h +++ b/src/main/aciodrv/icca.h @@ -26,7 +26,8 @@ bool aciodrv_icca_init(uint8_t node_id); * device driver foundation. * @see driver.h */ -bool aciodrv_icca_set_state(uint8_t node_id, int slot_state, struct ac_io_icca_state* state); +bool aciodrv_icca_set_state( + uint8_t node_id, int slot_state, struct ac_io_icca_state *state); /** * Get the current state of an ICCA node. @@ -39,7 +40,7 @@ bool aciodrv_icca_set_state(uint8_t node_id, int slot_state, struct ac_io_icca_s * device driver foundation. * @see driver.h */ -bool aciodrv_icca_get_state(uint8_t node_id, struct ac_io_icca_state* state); +bool aciodrv_icca_get_state(uint8_t node_id, struct ac_io_icca_state *state); /** * Trigger a card read action on the ICCA reader. Make sure to call this @@ -55,6 +56,6 @@ bool aciodrv_icca_get_state(uint8_t node_id, struct ac_io_icca_state* state); * device driver foundation. * @see driver.h */ -bool aciodrv_icca_read_card(uint8_t node_id, struct ac_io_icca_state* state); +bool aciodrv_icca_read_card(uint8_t node_id, struct ac_io_icca_state *state); #endif \ No newline at end of file diff --git a/src/main/aciodrv/kfca.c b/src/main/aciodrv/kfca.c index ef0599d..0149d11 100644 --- a/src/main/aciodrv/kfca.c +++ b/src/main/aciodrv/kfca.c @@ -1,7 +1,7 @@ #define LOG_MODULE "aciodrv-kfca" -#include #include +#include #include "aciodrv/device.h" @@ -9,10 +9,9 @@ static bool aciodrv_kfca_watchdog_start(uint8_t node_id) { - // exit early and don't actually call watchdog - // the watchdog call actually returns different sized packets depending on the state - // this results in an issue during packet processing (see: #68) + // the watchdog call actually returns different sized packets depending on + // the state this results in an issue during packet processing (see: #68) return true; /* @@ -27,9 +26,8 @@ static bool aciodrv_kfca_watchdog_start(uint8_t node_id) msg.cmd.raw[0] = 23; msg.cmd.raw[1] = 112; - if (!aciodrv_send_and_recv(&msg, offsetof(struct ac_io_message, cmd.raw) + 2)) { - log_warning("Starting watchdog failed"); - return false; + if (!aciodrv_send_and_recv(&msg, offsetof(struct ac_io_message, cmd.raw) + + 2)) { log_warning("Starting watchdog failed"); return false; } log_warning("Started watchdog of node %d, status: %d", @@ -54,7 +52,8 @@ static bool aciodrv_kfca_amp(uint8_t node_id) msg.cmd.raw[2] = 0; msg.cmd.raw[3] = 0; - if (!aciodrv_send_and_recv(&msg, offsetof(struct ac_io_message, cmd.raw) + 1)) { + if (!aciodrv_send_and_recv( + &msg, offsetof(struct ac_io_message, cmd.raw) + 1)) { log_warning("Setting AMP failed"); return false; } @@ -77,17 +76,21 @@ bool aciodrv_kfca_init(uint8_t node_id) return true; } -bool aciodrv_kfca_poll(uint8_t node_id, const struct ac_io_kfca_poll_out* pout, struct ac_io_kfca_poll_in* pin) +bool aciodrv_kfca_poll( + uint8_t node_id, + const struct ac_io_kfca_poll_out *pout, + struct ac_io_kfca_poll_in *pin) { struct ac_io_message msg; - msg.addr = node_id + 1; + msg.addr = node_id + 1; msg.cmd.code = ac_io_u16(AC_IO_CMD_KFCA_POLL); msg.cmd.nbytes = sizeof(*pout); /* buffer size of data we expect */ msg.cmd.kfca_poll_out = *pout; - if (!aciodrv_send_and_recv(&msg, offsetof(struct ac_io_message, cmd.raw) + sizeof(*pin))) { + if (!aciodrv_send_and_recv( + &msg, offsetof(struct ac_io_message, cmd.raw) + sizeof(*pin))) { log_warning("Polling of node %d failed", node_id + 1); return false; } diff --git a/src/main/aciodrv/kfca.h b/src/main/aciodrv/kfca.h index b2d7319..7722f42 100644 --- a/src/main/aciodrv/kfca.h +++ b/src/main/aciodrv/kfca.h @@ -25,6 +25,9 @@ bool aciodrv_kfca_init(uint8_t node_id); * device driver foundation. * @see driver.h */ -bool aciodrv_kfca_poll(uint8_t node_id, const struct ac_io_kfca_poll_out* pout, struct ac_io_kfca_poll_in* pin); +bool aciodrv_kfca_poll( + uint8_t node_id, + const struct ac_io_kfca_poll_out *pout, + struct ac_io_kfca_poll_in *pin); #endif diff --git a/src/main/aciodrv/port.c b/src/main/aciodrv/port.c index c227a86..29c28b5 100644 --- a/src/main/aciodrv/port.c +++ b/src/main/aciodrv/port.c @@ -9,15 +9,21 @@ static HANDLE aciodrv_port_fd; -bool aciodrv_port_open(const char* port, int baud) +bool aciodrv_port_open(const char *port, int baud) { COMMTIMEOUTS ct; DCB dcb; log_info("Opening ACIO on %s at %d baud", port, baud); - aciodrv_port_fd = CreateFile(port, GENERIC_READ | GENERIC_WRITE, 0, NULL, - OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH | FILE_ATTRIBUTE_NORMAL, NULL); + aciodrv_port_fd = CreateFile( + port, + GENERIC_READ | GENERIC_WRITE, + 0, + NULL, + OPEN_EXISTING, + FILE_FLAG_WRITE_THROUGH | FILE_ATTRIBUTE_NORMAL, + NULL); if (aciodrv_port_fd == INVALID_HANDLE_VALUE) { log_warning("Failed to open %s", port); @@ -37,9 +43,9 @@ bool aciodrv_port_open(const char* port, int baud) goto fail; } - if (!PurgeComm(aciodrv_port_fd, - PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR)) { - + if (!PurgeComm( + aciodrv_port_fd, + PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR)) { log_warning("PurgeComm failed"); goto fail; @@ -143,7 +149,7 @@ int aciodrv_port_write(const void *bytes, int nbytes) log_warning("WriteFile failed: err = %lu", GetLastError()); return -1; - } + } return nwrit; } @@ -154,4 +160,3 @@ void aciodrv_port_close(void) CloseHandle(aciodrv_port_fd); } } - diff --git a/src/main/aciodrv/port.h b/src/main/aciodrv/port.h index 97b502d..f9a423f 100644 --- a/src/main/aciodrv/port.h +++ b/src/main/aciodrv/port.h @@ -1,8 +1,8 @@ #ifndef ACIODRV_PORT_H #define ACIODRV_PORT_H -#include #include +#include /** * Open a serial port for communication with a ACIO device. @@ -12,7 +12,7 @@ * @return True if opening the com port was successful, false on error. * @note This will open and setup the com port, only. */ -bool aciodrv_port_open(const char* port, int baud); +bool aciodrv_port_open(const char *port, int baud); /** * Read data from the opened com port. diff --git a/src/main/acioemu/addr.c b/src/main/acioemu/addr.c index 90bae14..8d85487 100644 --- a/src/main/acioemu/addr.c +++ b/src/main/acioemu/addr.c @@ -8,9 +8,7 @@ #include "util/log.h" void ac_io_emu_cmd_assign_addrs( - struct ac_io_emu *emu, - const struct ac_io_message *req, - uint8_t node_count) + struct ac_io_emu *emu, const struct ac_io_message *req, uint8_t node_count) { struct ac_io_message resp; uint16_t cmd; @@ -21,9 +19,7 @@ void ac_io_emu_cmd_assign_addrs( cmd = ac_io_u16(req->cmd.code); if (cmd != AC_IO_CMD_ASSIGN_ADDRS) { - log_warning( - "Address 0 expects address assignment cmd, got %04x", - cmd); + log_warning("Address 0 expects address assignment cmd, got %04x", cmd); return; } diff --git a/src/main/acioemu/addr.h b/src/main/acioemu/addr.h index 108e6ac..434e429 100644 --- a/src/main/acioemu/addr.h +++ b/src/main/acioemu/addr.h @@ -8,8 +8,6 @@ #include void ac_io_emu_cmd_assign_addrs( - struct ac_io_emu *emu, - const struct ac_io_message *req, - uint8_t node_count); + struct ac_io_emu *emu, const struct ac_io_message *req, uint8_t node_count); #endif diff --git a/src/main/acioemu/emu.c b/src/main/acioemu/emu.c index dd22471..cbd277f 100644 --- a/src/main/acioemu/emu.c +++ b/src/main/acioemu/emu.c @@ -1,8 +1,8 @@ -#include /* Usermode API */ +#include /* Usermode API */ -#include /* Kernel-mode API for ioctls */ #include #include +#include /* Kernel-mode API for ioctls */ #include #include @@ -61,18 +61,26 @@ bool ac_io_emu_match_irp(const struct ac_io_emu *emu, const struct irp *irp) } } -HRESULT ac_io_emu_dispatch_irp(struct ac_io_emu *emu, struct irp *irp) +HRESULT +ac_io_emu_dispatch_irp(struct ac_io_emu *emu, struct irp *irp) { log_assert(irp != NULL); switch (irp->op) { - case IRP_OP_OPEN: return ac_io_emu_open(emu, irp); - case IRP_OP_CLOSE: return ac_io_emu_close(emu, irp); - case IRP_OP_READ: return ac_io_emu_read(emu, irp); - case IRP_OP_WRITE: return ac_io_emu_write(emu, irp); - case IRP_OP_IOCTL: return ac_io_emu_ioctl(emu, irp); - case IRP_OP_FSYNC: return S_FALSE; - default: return E_NOTIMPL; + case IRP_OP_OPEN: + return ac_io_emu_open(emu, irp); + case IRP_OP_CLOSE: + return ac_io_emu_close(emu, irp); + case IRP_OP_READ: + return ac_io_emu_read(emu, irp); + case IRP_OP_WRITE: + return ac_io_emu_write(emu, irp); + case IRP_OP_IOCTL: + return ac_io_emu_ioctl(emu, irp); + case IRP_OP_FSYNC: + return S_FALSE; + default: + return E_NOTIMPL; } } @@ -129,29 +137,30 @@ static HRESULT ac_io_emu_ioctl(struct ac_io_emu *emu, struct irp *irp) log_assert(irp != NULL); switch (irp->ioctl) { - case IOCTL_SERIAL_GET_COMMSTATUS: - if (irp->read.bytes == NULL) { - log_warning("IOCTL_SERIAL_GET_COMMSTATUS: Output buffer is NULL"); + case IOCTL_SERIAL_GET_COMMSTATUS: + if (irp->read.bytes == NULL) { + log_warning( + "IOCTL_SERIAL_GET_COMMSTATUS: Output buffer is NULL"); - return E_INVALIDARG; - } + return E_INVALIDARG; + } - if (irp->read.nbytes < sizeof(*status)) { - log_warning("IOCTL_SERIAL_GET_COMMSTATUS: Buffer is too small"); + if (irp->read.nbytes < sizeof(*status)) { + log_warning("IOCTL_SERIAL_GET_COMMSTATUS: Buffer is too small"); - return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); - } + return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); + } - status = (SERIAL_STATUS *) irp->read.bytes; - status->Errors = 0; - status->AmountInInQueue = ac_io_in_is_msg_pending(&emu->in); + status = (SERIAL_STATUS *) irp->read.bytes; + status->Errors = 0; + status->AmountInInQueue = ac_io_in_is_msg_pending(&emu->in); - irp->read.pos = sizeof(*status); + irp->read.pos = sizeof(*status); - return S_FALSE; + return S_FALSE; - default: - return S_FALSE; + default: + return S_FALSE; } } @@ -170,9 +179,7 @@ void ac_io_emu_request_pop(struct ac_io_emu *emu) } void ac_io_emu_response_push( - struct ac_io_emu *emu, - const struct ac_io_message *resp, - uint64_t delay_us) + struct ac_io_emu *emu, const struct ac_io_message *resp, uint64_t delay_us) { log_assert(emu != NULL); log_assert(resp != NULL); @@ -181,14 +188,10 @@ void ac_io_emu_response_push( } void ac_io_emu_response_push_thunk( - struct ac_io_emu *emu, - ac_io_in_thunk_t thunk, - void *ctx, - uint64_t delay_us) + struct ac_io_emu *emu, ac_io_in_thunk_t thunk, void *ctx, uint64_t delay_us) { log_assert(emu != NULL); log_assert(thunk != NULL); ac_io_in_supply_thunk(&emu->in, thunk, ctx, delay_us); } - diff --git a/src/main/acioemu/emu.h b/src/main/acioemu/emu.h index 2ee538a..1b3c654 100644 --- a/src/main/acioemu/emu.h +++ b/src/main/acioemu/emu.h @@ -27,13 +27,11 @@ HRESULT ac_io_emu_dispatch_irp(struct ac_io_emu *emu, struct irp *irp); const struct ac_io_message *ac_io_emu_request_peek(const struct ac_io_emu *emu); void ac_io_emu_request_pop(struct ac_io_emu *emu); void ac_io_emu_response_push( - struct ac_io_emu *emu, - const struct ac_io_message *resp, - uint64_t delay_ms); + struct ac_io_emu *emu, const struct ac_io_message *resp, uint64_t delay_ms); void ac_io_emu_response_push_thunk( - struct ac_io_emu *emu, - ac_io_in_thunk_t thunk, - void *ctx, - uint64_t delay_ms); + struct ac_io_emu *emu, + ac_io_in_thunk_t thunk, + void *ctx, + uint64_t delay_ms); #endif diff --git a/src/main/acioemu/h44b.c b/src/main/acioemu/h44b.c index e4f68cd..3e3240d 100644 --- a/src/main/acioemu/h44b.c +++ b/src/main/acioemu/h44b.c @@ -16,18 +16,15 @@ #include "util/hex.h" static void ac_io_emu_h44b_cmd_send_version( - struct ac_io_emu_h44b *h44b, - const struct ac_io_message *req); + struct ac_io_emu_h44b *h44b, const struct ac_io_message *req); static void ac_io_emu_h44b_send_status( - struct ac_io_emu_h44b *h44b, - const struct ac_io_message *req, - uint8_t status); + struct ac_io_emu_h44b *h44b, + const struct ac_io_message *req, + uint8_t status); void ac_io_emu_h44b_init( - struct ac_io_emu_h44b *h44b, - struct ac_io_emu *emu, - uint8_t unit_no) + struct ac_io_emu_h44b *h44b, struct ac_io_emu *emu, uint8_t unit_no) { memset(h44b, 0, sizeof(*h44b)); h44b->emu = emu; @@ -35,8 +32,7 @@ void ac_io_emu_h44b_init( } void ac_io_emu_h44b_dispatch_request( - struct ac_io_emu_h44b *h44b, - const struct ac_io_message *req) + struct ac_io_emu_h44b *h44b, const struct ac_io_message *req) { uint16_t cmd_code; @@ -58,7 +54,8 @@ void ac_io_emu_h44b_dispatch_request( case AC_IO_H44B_CMD_SET_OUTPUTS: /* Not using the struct ac_io_h44b_output here */ for (int i = 0; i < 6; i++) { - jb_io_set_rgb_led((enum jb_io_rgb_led) i, + jb_io_set_rgb_led( + (enum jb_io_rgb_led) i, req->cmd.raw[i * 3], req->cmd.raw[i * 3 + 1], req->cmd.raw[i * 3 + 2]); @@ -71,16 +68,17 @@ void ac_io_emu_h44b_dispatch_request( break; default: - log_warning("Unknown ACIO message %04x on h44b node, addr=%d", - cmd_code, req->addr); + log_warning( + "Unknown ACIO message %04x on h44b node, addr=%d", + cmd_code, + req->addr); break; } } static void ac_io_emu_h44b_cmd_send_version( - struct ac_io_emu_h44b *h44b, - const struct ac_io_message *req) + struct ac_io_emu_h44b *h44b, const struct ac_io_message *req) { struct ac_io_message resp; @@ -93,8 +91,10 @@ static void ac_io_emu_h44b_cmd_send_version( resp.cmd.version.major = 0x01; resp.cmd.version.minor = 0x00; resp.cmd.version.revision = 0x02; - memcpy(resp.cmd.version.product_code, "H44B", - sizeof(resp.cmd.version.product_code)); + memcpy( + resp.cmd.version.product_code, + "H44B", + sizeof(resp.cmd.version.product_code)); strncpy(resp.cmd.version.date, __DATE__, sizeof(resp.cmd.version.date)); strncpy(resp.cmd.version.time, __TIME__, sizeof(resp.cmd.version.time)); @@ -102,9 +102,9 @@ static void ac_io_emu_h44b_cmd_send_version( } static void ac_io_emu_h44b_send_status( - struct ac_io_emu_h44b *h44b, - const struct ac_io_message *req, - uint8_t status) + struct ac_io_emu_h44b *h44b, + const struct ac_io_message *req, + uint8_t status) { struct ac_io_message resp; diff --git a/src/main/acioemu/h44b.h b/src/main/acioemu/h44b.h index 81c4fad..cfaafcc 100644 --- a/src/main/acioemu/h44b.h +++ b/src/main/acioemu/h44b.h @@ -15,12 +15,9 @@ struct ac_io_emu_h44b { void acioemu_h44b_init(void); void ac_io_emu_h44b_init( - struct ac_io_emu_h44b *h44b, - struct ac_io_emu *emu, - uint8_t unit_no); + struct ac_io_emu_h44b *h44b, struct ac_io_emu *emu, uint8_t unit_no); void ac_io_emu_h44b_dispatch_request( - struct ac_io_emu_h44b *h44b, - const struct ac_io_message *req); + struct ac_io_emu_h44b *h44b, const struct ac_io_message *req); #endif diff --git a/src/main/acioemu/hdxs.c b/src/main/acioemu/hdxs.c index e3aca70..0e68aa0 100644 --- a/src/main/acioemu/hdxs.c +++ b/src/main/acioemu/hdxs.c @@ -8,21 +8,17 @@ #include "util/log.h" static void ac_io_emu_hdxs_cmd_send_version( - struct ac_io_emu_hdxs *hdxs, - const struct ac_io_message *req); + struct ac_io_emu_hdxs *hdxs, const struct ac_io_message *req); static void ac_io_emu_hdxs_send_empty( - struct ac_io_emu_hdxs *hdxs, - const struct ac_io_message *req); + struct ac_io_emu_hdxs *hdxs, const struct ac_io_message *req); static void ac_io_emu_hdxs_send_status( - struct ac_io_emu_hdxs *hdxs, - const struct ac_io_message *req, - uint8_t status); + struct ac_io_emu_hdxs *hdxs, + const struct ac_io_message *req, + uint8_t status); -void ac_io_emu_hdxs_init( - struct ac_io_emu_hdxs *hdxs, - struct ac_io_emu *emu) +void ac_io_emu_hdxs_init(struct ac_io_emu_hdxs *hdxs, struct ac_io_emu *emu) { log_assert(hdxs != NULL); log_assert(emu != NULL); @@ -31,8 +27,7 @@ void ac_io_emu_hdxs_init( } void ac_io_emu_hdxs_dispatch_request( - struct ac_io_emu_hdxs *hdxs, - const struct ac_io_message *req) + struct ac_io_emu_hdxs *hdxs, const struct ac_io_message *req) { uint16_t cmd_code; @@ -42,46 +37,45 @@ void ac_io_emu_hdxs_dispatch_request( cmd_code = ac_io_u16(req->cmd.code); switch (cmd_code) { - case AC_IO_CMD_GET_VERSION: - log_misc("AC_IO_CMD_GET_VERSION(%d)", req->addr); - ac_io_emu_hdxs_cmd_send_version(hdxs, req); + case AC_IO_CMD_GET_VERSION: + log_misc("AC_IO_CMD_GET_VERSION(%d)", req->addr); + ac_io_emu_hdxs_cmd_send_version(hdxs, req); - break; + break; - case AC_IO_CMD_START_UP: - log_misc("AC_IO_CMD_START_UP(%d)", req->addr); - ac_io_emu_hdxs_send_status(hdxs, req, 0x00); + case AC_IO_CMD_START_UP: + log_misc("AC_IO_CMD_START_UP(%d)", req->addr); + ac_io_emu_hdxs_send_status(hdxs, req, 0x00); - break; + break; - case AC_IO_CMD_CLEAR: - log_misc("AC_IO_CMD_CLEAR(%d)", req->addr); + case AC_IO_CMD_CLEAR: + log_misc("AC_IO_CMD_CLEAR(%d)", req->addr); - case 0x110: - case 0x112: - case 0x128: - ac_io_emu_hdxs_send_status(hdxs, req, 0x00); + case 0x110: + case 0x112: + case 0x128: + ac_io_emu_hdxs_send_status(hdxs, req, 0x00); - break; + break; - case AC_IO_CMD_KEEPALIVE: - ac_io_emu_hdxs_send_empty(hdxs, req); + case AC_IO_CMD_KEEPALIVE: + ac_io_emu_hdxs_send_empty(hdxs, req); - break; + break; - default: - log_warning( + default: + log_warning( "Unknown ACIO message %04x on HDXS node, addr=%d", cmd_code, req->addr); - break; + break; } } static void ac_io_emu_hdxs_cmd_send_version( - struct ac_io_emu_hdxs *hdxs, - const struct ac_io_message *req) + struct ac_io_emu_hdxs *hdxs, const struct ac_io_message *req) { struct ac_io_message resp; @@ -94,8 +88,10 @@ static void ac_io_emu_hdxs_cmd_send_version( resp.cmd.version.major = 0x01; resp.cmd.version.minor = 0x06; resp.cmd.version.revision = 0x00; - memcpy(resp.cmd.version.product_code, "HDXS", - sizeof(resp.cmd.version.product_code)); + memcpy( + resp.cmd.version.product_code, + "HDXS", + sizeof(resp.cmd.version.product_code)); strncpy(resp.cmd.version.date, __DATE__, sizeof(resp.cmd.version.date)); strncpy(resp.cmd.version.time, __TIME__, sizeof(resp.cmd.version.time)); @@ -103,8 +99,7 @@ static void ac_io_emu_hdxs_cmd_send_version( } static void ac_io_emu_hdxs_send_empty( - struct ac_io_emu_hdxs *hdxs, - const struct ac_io_message *req) + struct ac_io_emu_hdxs *hdxs, const struct ac_io_message *req) { struct ac_io_message resp; @@ -117,9 +112,9 @@ static void ac_io_emu_hdxs_send_empty( } static void ac_io_emu_hdxs_send_status( - struct ac_io_emu_hdxs *hdxs, - const struct ac_io_message *req, - uint8_t status) + struct ac_io_emu_hdxs *hdxs, + const struct ac_io_message *req, + uint8_t status) { struct ac_io_message resp; diff --git a/src/main/acioemu/hdxs.h b/src/main/acioemu/hdxs.h index 08e2e13..1016258 100644 --- a/src/main/acioemu/hdxs.h +++ b/src/main/acioemu/hdxs.h @@ -10,12 +10,9 @@ struct ac_io_emu_hdxs { // TODO ops vtbl }; -void ac_io_emu_hdxs_init( - struct ac_io_emu_hdxs *hdxs, - struct ac_io_emu *emu); +void ac_io_emu_hdxs_init(struct ac_io_emu_hdxs *hdxs, struct ac_io_emu *emu); void ac_io_emu_hdxs_dispatch_request( - struct ac_io_emu_hdxs *hdxs, - const struct ac_io_message *req); + struct ac_io_emu_hdxs *hdxs, const struct ac_io_message *req); #endif diff --git a/src/main/acioemu/icca.c b/src/main/acioemu/icca.c index 1bc6d36..8dfe0bd 100644 --- a/src/main/acioemu/icca.c +++ b/src/main/acioemu/icca.c @@ -23,39 +23,35 @@ enum ac_io_icca_subcmd { }; enum ac_io_icca_flag { - AC_IO_ICCA_FLAG_FRONT_SENSOR = 0x10, - AC_IO_ICCA_FLAG_REAR_SENSOR = 0x20, - AC_IO_ICCA_FLAG_SOLENOID = 0x40 + AC_IO_ICCA_FLAG_FRONT_SENSOR = 0x10, + AC_IO_ICCA_FLAG_REAR_SENSOR = 0x20, + AC_IO_ICCA_FLAG_SOLENOID = 0x40 }; enum ac_io_icca_status_code { - AC_IO_ICCA_STATUS_FAULT = 0x00, - AC_IO_ICCA_STATUS_IDLE = 0x01, - AC_IO_ICCA_STATUS_GOT_UID = 0x02 + AC_IO_ICCA_STATUS_FAULT = 0x00, + AC_IO_ICCA_STATUS_IDLE = 0x01, + AC_IO_ICCA_STATUS_GOT_UID = 0x02 }; static void ac_io_emu_icca_cmd_send_version( - struct ac_io_emu_icca *icca, - const struct ac_io_message *req); + struct ac_io_emu_icca *icca, const struct ac_io_message *req); static void ac_io_emu_icca_send_state( - struct ac_io_emu_icca *icca, - const struct ac_io_message *req, - uint64_t delay_us); + struct ac_io_emu_icca *icca, + const struct ac_io_message *req, + uint64_t delay_us); static void ac_io_emu_icca_send_empty( - struct ac_io_emu_icca *icca, - const struct ac_io_message *req); + struct ac_io_emu_icca *icca, const struct ac_io_message *req); static void ac_io_emu_icca_send_status( - struct ac_io_emu_icca *icca, - const struct ac_io_message *req, - uint8_t status); + struct ac_io_emu_icca *icca, + const struct ac_io_message *req, + uint8_t status); void ac_io_emu_icca_init( - struct ac_io_emu_icca *icca, - struct ac_io_emu *emu, - uint8_t unit_no) + struct ac_io_emu_icca *icca, struct ac_io_emu *emu, uint8_t unit_no) { memset(icca, 0, sizeof(*icca)); icca->emu = emu; @@ -65,8 +61,7 @@ void ac_io_emu_icca_init( } void ac_io_emu_icca_dispatch_request( - struct ac_io_emu_icca *icca, - const struct ac_io_message *req) + struct ac_io_emu_icca *icca, const struct ac_io_message *req) { uint16_t cmd_code; uint64_t delay_us; @@ -131,10 +126,9 @@ void ac_io_emu_icca_dispatch_request( break; - case AC_IO_ICCA_CMD_SET_SLOT_STATE: - { - struct ac_io_icca_misc* misc = - (struct ac_io_icca_misc*) &req->cmd.raw; + case AC_IO_ICCA_CMD_SET_SLOT_STATE: { + struct ac_io_icca_misc *misc = + (struct ac_io_icca_misc *) &req->cmd.raw; uint8_t cmd; switch (misc->subcmd) { @@ -157,15 +151,19 @@ void ac_io_emu_icca_dispatch_request( default: cmd = 0xFF; - log_warning("Unhandled slot command %X, node %d", - misc->subcmd, icca->unit_no); + log_warning( + "Unhandled slot command %X, node %d", + misc->subcmd, + icca->unit_no); break; } if (cmd != 0xFF) { if (!eam_io_card_slot_cmd(icca->unit_no, cmd)) { - log_warning("Eamio failed to handle slot cmd %d for node %d", - cmd, icca->unit_no); + log_warning( + "Eamio failed to handle slot cmd %d for node %d", + cmd, + icca->unit_no); } } @@ -176,9 +174,11 @@ void ac_io_emu_icca_dispatch_request( } case AC_IO_ICCA_CMD_POLL: - delay_us = time_get_elapsed_us(time_get_counter() - icca->time_counter_last_poll); + delay_us = time_get_elapsed_us( + time_get_counter() - icca->time_counter_last_poll); - /* emulating delay implemented by hardware. do not delay messages that exceed a certain threshold. */ + /* emulating delay implemented by hardware. do not delay messages + * that exceed a certain threshold. */ if (delay_us > 16000) { delay_us = 0; } @@ -195,16 +195,17 @@ void ac_io_emu_icca_dispatch_request( break; default: - log_warning("Unknown ACIO message %04x on ICCA node, addr=%d", - cmd_code, req->addr); + log_warning( + "Unknown ACIO message %04x on ICCA node, addr=%d", + cmd_code, + req->addr); break; } } static void ac_io_emu_icca_cmd_send_version( - struct ac_io_emu_icca *icca, - const struct ac_io_message *req) + struct ac_io_emu_icca *icca, const struct ac_io_message *req) { struct ac_io_message resp; @@ -217,8 +218,10 @@ static void ac_io_emu_icca_cmd_send_version( resp.cmd.version.major = 0x01; resp.cmd.version.minor = 0x06; resp.cmd.version.revision = 0x00; - memcpy(resp.cmd.version.product_code, "ICCA", - sizeof(resp.cmd.version.product_code)); + memcpy( + resp.cmd.version.product_code, + "ICCA", + sizeof(resp.cmd.version.product_code)); strncpy(resp.cmd.version.date, __DATE__, sizeof(resp.cmd.version.date)); strncpy(resp.cmd.version.time, __TIME__, sizeof(resp.cmd.version.time)); @@ -226,8 +229,7 @@ static void ac_io_emu_icca_cmd_send_version( } static void ac_io_emu_icca_send_empty( - struct ac_io_emu_icca *icca, - const struct ac_io_message *req) + struct ac_io_emu_icca *icca, const struct ac_io_message *req) { struct ac_io_message resp; @@ -240,9 +242,9 @@ static void ac_io_emu_icca_send_empty( } static void ac_io_emu_icca_send_status( - struct ac_io_emu_icca *icca, - const struct ac_io_message *req, - uint8_t status) + struct ac_io_emu_icca *icca, + const struct ac_io_message *req, + uint8_t status) { struct ac_io_message resp; @@ -256,9 +258,9 @@ static void ac_io_emu_icca_send_status( } static void ac_io_emu_icca_send_state( - struct ac_io_emu_icca *icca, - const struct ac_io_message *req, - uint64_t delay_us) + struct ac_io_emu_icca *icca, + const struct ac_io_message *req, + uint64_t delay_us) { struct ac_io_message resp; struct ac_io_icca_state *body; @@ -277,25 +279,22 @@ static void ac_io_emu_icca_send_state( keypad = eam_io_get_keypad_state(icca->unit_no); sensor_state = eam_io_get_sensor_state(icca->unit_no); - + keypad_rise = keypad & (icca->last_keypad ^ keypad); card_full_insert = sensor_state & (1 << EAM_IO_SENSOR_FRONT) && sensor_state & (1 << EAM_IO_SENSOR_BACK); if (sensor_state != icca->last_sensor) { - if (card_full_insert) { - - if (!eam_io_card_slot_cmd(icca->unit_no, - EAM_IO_CARD_SLOT_CMD_READ)) { - log_warning("EAM_IO_CARD_SLOT_CMD_READ to unit %d failed", + if (!eam_io_card_slot_cmd( + icca->unit_no, EAM_IO_CARD_SLOT_CMD_READ)) { + log_warning( + "EAM_IO_CARD_SLOT_CMD_READ to unit %d failed", icca->unit_no); } - icca->card_result = eam_io_read_card( - icca->unit_no, - icca->uid, - sizeof(icca->uid)); + icca->card_result = + eam_io_read_card(icca->unit_no, icca->uid, sizeof(icca->uid)); // fault if sensor says to read but we got no card icca->fault = (icca->card_result == EAM_IO_CARD_NONE); @@ -338,8 +337,8 @@ static void ac_io_emu_icca_send_state( memcpy(body->uid, icca->uid, sizeof(body->uid)); body->card_type = 0; - if (body->status_code == AC_IO_ICCA_STATUS_GOT_UID){ - if (icca->detected_new_reader){ + if (body->status_code == AC_IO_ICCA_STATUS_GOT_UID) { + if (icca->detected_new_reader) { // sensor_state actually refers to cardtype for wavepass readers // EAM_IO_CARD_ISO15696 = 1 -> 0 // EAM_IO_CARD_FELICA = 2 -> 1 @@ -349,7 +348,6 @@ static void ac_io_emu_icca_send_state( } if (keypad_rise) { - if (icca->key_events[0]) { event = (icca->key_events[0] + 0x10) & 0xF0; } else { @@ -382,4 +380,3 @@ static void ac_io_emu_icca_send_state( ac_io_emu_response_push(icca->emu, &resp, delay_us); } - diff --git a/src/main/acioemu/icca.h b/src/main/acioemu/icca.h index 4da21d2..72be967 100644 --- a/src/main/acioemu/icca.h +++ b/src/main/acioemu/icca.h @@ -23,12 +23,9 @@ struct ac_io_emu_icca { }; void ac_io_emu_icca_init( - struct ac_io_emu_icca *icca, - struct ac_io_emu *emu, - uint8_t unit_no); + struct ac_io_emu_icca *icca, struct ac_io_emu *emu, uint8_t unit_no); void ac_io_emu_icca_dispatch_request( - struct ac_io_emu_icca *icca, - const struct ac_io_message *req); + struct ac_io_emu_icca *icca, const struct ac_io_message *req); #endif diff --git a/src/main/acioemu/iccb.c b/src/main/acioemu/iccb.c index af5f382..811a110 100644 --- a/src/main/acioemu/iccb.c +++ b/src/main/acioemu/iccb.c @@ -14,26 +14,21 @@ #include "bemanitools/eamio.h" static void ac_io_emu_iccb_cmd_send_version( - struct ac_io_emu_iccb *iccb, - const struct ac_io_message *req); + struct ac_io_emu_iccb *iccb, const struct ac_io_message *req); static void ac_io_emu_iccb_send_state( - struct ac_io_emu_iccb *iccb, - const struct ac_io_message *req); + struct ac_io_emu_iccb *iccb, const struct ac_io_message *req); static void ac_io_emu_iccb_send_empty( - struct ac_io_emu_iccb *iccb, - const struct ac_io_message *req); + struct ac_io_emu_iccb *iccb, const struct ac_io_message *req); static void ac_io_emu_iccb_send_status( - struct ac_io_emu_iccb *iccb, - const struct ac_io_message *req, - uint8_t status); + struct ac_io_emu_iccb *iccb, + const struct ac_io_message *req, + uint8_t status); void ac_io_emu_iccb_init( - struct ac_io_emu_iccb *iccb, - struct ac_io_emu *emu, - uint8_t unit_no) + struct ac_io_emu_iccb *iccb, struct ac_io_emu *emu, uint8_t unit_no) { memset(iccb, 0, sizeof(*iccb)); iccb->emu = emu; @@ -41,8 +36,7 @@ void ac_io_emu_iccb_init( } void ac_io_emu_iccb_dispatch_request( - struct ac_io_emu_iccb *iccb, - const struct ac_io_message *req) + struct ac_io_emu_iccb *iccb, const struct ac_io_message *req) { uint16_t cmd_code; @@ -104,16 +98,17 @@ void ac_io_emu_iccb_dispatch_request( break; default: - log_warning("Unknown ACIO message %04x on ICCB node, addr=%d", - cmd_code, req->addr); + log_warning( + "Unknown ACIO message %04x on ICCB node, addr=%d", + cmd_code, + req->addr); break; } } static void ac_io_emu_iccb_cmd_send_version( - struct ac_io_emu_iccb *iccb, - const struct ac_io_message *req) + struct ac_io_emu_iccb *iccb, const struct ac_io_message *req) { struct ac_io_message resp; @@ -126,8 +121,10 @@ static void ac_io_emu_iccb_cmd_send_version( resp.cmd.version.major = 0x01; resp.cmd.version.minor = 0x05; resp.cmd.version.revision = 0x01; - memcpy(resp.cmd.version.product_code, "ICCB", - sizeof(resp.cmd.version.product_code)); + memcpy( + resp.cmd.version.product_code, + "ICCB", + sizeof(resp.cmd.version.product_code)); strncpy(resp.cmd.version.date, __DATE__, sizeof(resp.cmd.version.date)); strncpy(resp.cmd.version.time, __TIME__, sizeof(resp.cmd.version.time)); @@ -135,8 +132,7 @@ static void ac_io_emu_iccb_cmd_send_version( } static void ac_io_emu_iccb_send_empty( - struct ac_io_emu_iccb *iccb, - const struct ac_io_message *req) + struct ac_io_emu_iccb *iccb, const struct ac_io_message *req) { struct ac_io_message resp; @@ -149,9 +145,9 @@ static void ac_io_emu_iccb_send_empty( } static void ac_io_emu_iccb_send_status( - struct ac_io_emu_iccb *iccb, - const struct ac_io_message *req, - uint8_t status) + struct ac_io_emu_iccb *iccb, + const struct ac_io_message *req, + uint8_t status) { struct ac_io_message resp; @@ -165,8 +161,7 @@ static void ac_io_emu_iccb_send_status( } static void ac_io_emu_iccb_send_state( - struct ac_io_emu_iccb *iccb, - const struct ac_io_message *req) + struct ac_io_emu_iccb *iccb, const struct ac_io_message *req) { struct ac_io_message resp; struct ac_io_iccb_state *body; @@ -178,10 +173,8 @@ static void ac_io_emu_iccb_send_state( if (sensor != iccb->last_sensor) { if (sensor) { - iccb->card_result = eam_io_read_card( - iccb->unit_no, - iccb->uid, - sizeof(iccb->uid)); + iccb->card_result = + eam_io_read_card(iccb->unit_no, iccb->uid, sizeof(iccb->uid)); // fault if sensor says to read but we got no card iccb->fault = (iccb->card_result == EAM_IO_CARD_NONE); @@ -224,4 +217,3 @@ static void ac_io_emu_iccb_send_state( ac_io_emu_response_push(iccb->emu, &resp, 0); } - diff --git a/src/main/acioemu/iccb.h b/src/main/acioemu/iccb.h index 31b60d8..762068f 100644 --- a/src/main/acioemu/iccb.h +++ b/src/main/acioemu/iccb.h @@ -16,12 +16,9 @@ struct ac_io_emu_iccb { }; void ac_io_emu_iccb_init( - struct ac_io_emu_iccb *iccb, - struct ac_io_emu *emu, - uint8_t unit_no); + struct ac_io_emu_iccb *iccb, struct ac_io_emu *emu, uint8_t unit_no); void ac_io_emu_iccb_dispatch_request( - struct ac_io_emu_iccb *iccb, - const struct ac_io_message *req); + struct ac_io_emu_iccb *iccb, const struct ac_io_message *req); #endif diff --git a/src/main/acioemu/pipe.c b/src/main/acioemu/pipe.c index 357ad61..8b96b98 100644 --- a/src/main/acioemu/pipe.c +++ b/src/main/acioemu/pipe.c @@ -13,11 +13,10 @@ #include "util/mem.h" #include "util/time.h" -static struct ac_io_in_queued *ac_io_in_queued_alloc(struct ac_io_in *in, - uint64_t delay_us); +static struct ac_io_in_queued * +ac_io_in_queued_alloc(struct ac_io_in *in, uint64_t delay_us); static void ac_io_in_queued_populate( - struct ac_io_in_queued *iq, - const struct ac_io_message *msg); + struct ac_io_in_queued *iq, const struct ac_io_message *msg); static void ac_io_in_queued_putc(struct ac_io_in_queued *iq, uint8_t b); static bool ac_io_out_supply_byte(struct ac_io_out *out, uint8_t b); @@ -30,8 +29,8 @@ static bool ac_io_out_reject_message(struct ac_io_out *out); static bool ac_io_enable_legacy_mode = false; -static struct ac_io_in_queued *ac_io_in_queued_alloc(struct ac_io_in *in, - uint64_t delay_us) +static struct ac_io_in_queued * +ac_io_in_queued_alloc(struct ac_io_in *in, uint64_t delay_us) { struct ac_io_in_queued *iq; @@ -51,8 +50,7 @@ static struct ac_io_in_queued *ac_io_in_queued_alloc(struct ac_io_in *in, } static void ac_io_in_queued_populate( - struct ac_io_in_queued *iq, - const struct ac_io_message *msg) + struct ac_io_in_queued *iq, const struct ac_io_message *msg) { uint8_t checksum; const uint8_t *src; @@ -68,7 +66,7 @@ static void ac_io_in_queued_populate( src = (const uint8_t *) msg; checksum = 0; - for (i = 0 ; i < nbytes ; i++) { + for (i = 0; i < nbytes; i++) { ac_io_in_queued_putc(iq, src[i]); checksum += src[i]; } @@ -97,8 +95,8 @@ void ac_io_in_init(struct ac_io_in *in) list_init(&in->queue); } -void ac_io_in_supply(struct ac_io_in *in, const struct ac_io_message *msg, - uint64_t delay_us) +void ac_io_in_supply( + struct ac_io_in *in, const struct ac_io_message *msg, uint64_t delay_us) { struct ac_io_in_queued *dest; @@ -113,10 +111,7 @@ void ac_io_in_supply(struct ac_io_in *in, const struct ac_io_message *msg, } void ac_io_in_supply_thunk( - struct ac_io_in *in, - ac_io_in_thunk_t thunk, - void *ctx, - uint64_t delay_us) + struct ac_io_in *in, ac_io_in_thunk_t thunk, void *ctx, uint64_t delay_us) { struct ac_io_in_queued *dest; @@ -177,7 +172,7 @@ void ac_io_in_drain(struct ac_io_in *in, struct iobuf *dest) if (ac_io_enable_legacy_mode) { break; } - } while (nmoved > 0); + } while (nmoved > 0); } bool ac_io_in_is_msg_pending(const struct ac_io_in *in) @@ -209,7 +204,6 @@ static bool ac_io_out_supply_byte(struct ac_io_out *out, uint8_t b) if (out->in_frame) { return ac_io_out_supply_frame_byte(out, b); } else { - if (b == AC_IO_SOF) { out->in_frame = true; } else if (b == AC_IO_ESCAPE) { @@ -235,7 +229,6 @@ static bool ac_io_out_supply_frame_byte(struct ac_io_out *out, uint8_t b) return true; } else if (b == AC_IO_SOF) { - if (out->pos == 0) { /* Got autobaud/empty message */ out->have_message = true; @@ -247,7 +240,6 @@ static bool ac_io_out_supply_frame_byte(struct ac_io_out *out, uint8_t b) return true; } - } /* Payload byte */ @@ -257,13 +249,11 @@ static bool ac_io_out_supply_frame_byte(struct ac_io_out *out, uint8_t b) /* Handle contextually-implied end-of-packet events */ if (out->pos > offsetof(struct ac_io_message, addr)) { - if (out->msg.addr == AC_IO_BROADCAST) { return ac_io_out_detect_broadcast_eof(out); } else { return ac_io_out_detect_command_eof(out); } - } return true; @@ -274,9 +264,8 @@ static bool ac_io_out_detect_broadcast_eof(struct ac_io_out *out) size_t end; if (out->pos > offsetof(struct ac_io_message, bcast.nbytes)) { - end = offsetof(struct ac_io_message,bcast.raw) - + out->msg.bcast.nbytes - + 1; + end = offsetof(struct ac_io_message, bcast.raw) + + out->msg.bcast.nbytes + 1; if (out->pos == end) { return ac_io_out_check_sum(out); @@ -291,9 +280,7 @@ static bool ac_io_out_detect_command_eof(struct ac_io_out *out) size_t end; if (out->pos > offsetof(struct ac_io_message, cmd.nbytes)) { - end = offsetof(struct ac_io_message, cmd.raw) - + out->msg.cmd.nbytes - + 1; + end = offsetof(struct ac_io_message, cmd.raw) + out->msg.cmd.nbytes + 1; if (out->pos == end) { return ac_io_out_check_sum(out); @@ -310,15 +297,17 @@ static bool ac_io_out_check_sum(struct ac_io_out *out) checksum = 0; - for (i = 0 ; i < out->pos - 1 ; i++) { + for (i = 0; i < out->pos - 1; i++) { checksum += out->bytes[i]; } if (checksum == out->bytes[out->pos - 1]) { return ac_io_out_accept_message(out); } else { - log_warning("Checksum bad: expected %02x got %02x", - checksum, out->bytes[out->pos - 1]); + log_warning( + "Checksum bad: expected %02x got %02x", + checksum, + out->bytes[out->pos - 1]); return ac_io_out_reject_message(out); } @@ -363,4 +352,3 @@ void ac_io_out_consume_message(struct ac_io_out *out) out->have_message = false; out->escape = false; } - diff --git a/src/main/acioemu/pipe.h b/src/main/acioemu/pipe.h index 5605460..ad442fc 100644 --- a/src/main/acioemu/pipe.h +++ b/src/main/acioemu/pipe.h @@ -47,13 +47,10 @@ struct ac_io_out { void ac_io_legacy_mode(void); void ac_io_in_init(struct ac_io_in *in); -void ac_io_in_supply(struct ac_io_in *in, const struct ac_io_message *msg, - uint64_t delay); +void ac_io_in_supply( + struct ac_io_in *in, const struct ac_io_message *msg, uint64_t delay); void ac_io_in_supply_thunk( - struct ac_io_in *in, - ac_io_in_thunk_t thunk, - void *ctx, - uint64_t delay); + struct ac_io_in *in, ac_io_in_thunk_t thunk, void *ctx, uint64_t delay); void ac_io_in_drain(struct ac_io_in *in, struct iobuf *dest); bool ac_io_in_is_msg_pending(const struct ac_io_in *in); diff --git a/src/main/aciotest/handler.h b/src/main/aciotest/handler.h index 8bf0cb3..b4e46cf 100644 --- a/src/main/aciotest/handler.h +++ b/src/main/aciotest/handler.h @@ -6,11 +6,10 @@ static const uint8_t aciotest_handler_max = 16; /** * Handler interface for an ACIO device. */ -struct aciotest_handler_node_handler -{ - void* ctx; - bool (*init)(uint8_t node_id, void** ctx); - bool (*update)(uint8_t node_id, void* ctx); +struct aciotest_handler_node_handler { + void *ctx; + bool (*init)(uint8_t node_id, void **ctx); + bool (*update)(uint8_t node_id, void *ctx); }; #endif \ No newline at end of file diff --git a/src/main/aciotest/icca.c b/src/main/aciotest/icca.c index e465ece..ad00359 100644 --- a/src/main/aciotest/icca.c +++ b/src/main/aciotest/icca.c @@ -1,28 +1,28 @@ #include "aciotest/icca.h" -#include #include +#include #include "aciodrv/icca.h" -bool aciotest_icca_handler_init(uint8_t node_id, void** ctx) +bool aciotest_icca_handler_init(uint8_t node_id, void **ctx) { *ctx = malloc(sizeof(uint32_t)); - *((uint32_t*) *ctx) = 0; + *((uint32_t *) *ctx) = 0; return aciodrv_icca_init(node_id); } -bool aciotest_icca_handler_update(uint8_t node_id, void* ctx) +bool aciotest_icca_handler_update(uint8_t node_id, void *ctx) { - if (*((uint32_t*) ctx) == 0) { - *((uint32_t*) ctx) = 1; + if (*((uint32_t *) ctx) == 0) { + *((uint32_t *) ctx) = 1; /* eject cards that were left in the reader */ - if (!aciodrv_icca_set_state(node_id, AC_IO_ICCA_SLOT_STATE_EJECT, NULL)) { + if (!aciodrv_icca_set_state( + node_id, AC_IO_ICCA_SLOT_STATE_EJECT, NULL)) { return false; } - } struct ac_io_icca_state state; @@ -31,7 +31,8 @@ bool aciotest_icca_handler_update(uint8_t node_id, void* ctx) return false; } - printf(">>> ICCA %d:\n" + printf( + ">>> ICCA %d:\n" "status_code: %d\n" "sensor_state: %d\n" "keypad_started: %d\n" @@ -40,43 +41,51 @@ bool aciotest_icca_handler_update(uint8_t node_id, void* ctx) "key_state: %04X\n" "key_events[0]: %02X\n" "key_events[1]: %02X\n", - node_id, state.status_code, state.sensor_state, state.keypad_started, - state.card_type, - state.uid[0], state.uid[1], state.uid[2], state.uid[3], - state.uid[4], state.uid[5], state.uid[6], state.uid[7], - state.key_state, state.key_events[0], state.key_events[1]); + node_id, + state.status_code, + state.sensor_state, + state.keypad_started, + state.card_type, + state.uid[0], + state.uid[1], + state.uid[2], + state.uid[3], + state.uid[4], + state.uid[5], + state.uid[6], + state.uid[7], + state.key_state, + state.key_events[0], + state.key_events[1]); /* eject card with "empty" key */ if (state.key_state & AC_IO_ICCA_KEYPAD_MASK_EMPTY) { - - if (!aciodrv_icca_set_state(node_id, AC_IO_ICCA_SLOT_STATE_EJECT, NULL)) { + if (!aciodrv_icca_set_state( + node_id, AC_IO_ICCA_SLOT_STATE_EJECT, NULL)) { return false; } - } /* allow new card to be inserted when slot is clear */ - if ( !(state.sensor_state & AC_IO_ICCA_SENSOR_MASK_BACK_ON) && - !(state.sensor_state & AC_IO_ICCA_SENSOR_MASK_FRONT_ON)) { - - if (!aciodrv_icca_set_state(node_id, AC_IO_ICCA_SLOT_STATE_OPEN, NULL)) { + if (!(state.sensor_state & AC_IO_ICCA_SENSOR_MASK_BACK_ON) && + !(state.sensor_state & AC_IO_ICCA_SENSOR_MASK_FRONT_ON)) { + if (!aciodrv_icca_set_state( + node_id, AC_IO_ICCA_SLOT_STATE_OPEN, NULL)) { return false; } - } /* lock the card when fully inserted */ - if ( (state.sensor_state & AC_IO_ICCA_SENSOR_MASK_BACK_ON) && - (state.sensor_state & AC_IO_ICCA_SENSOR_MASK_FRONT_ON)) { - - if (!aciodrv_icca_set_state(node_id, AC_IO_ICCA_SLOT_STATE_CLOSE, NULL)) { + if ((state.sensor_state & AC_IO_ICCA_SENSOR_MASK_BACK_ON) && + (state.sensor_state & AC_IO_ICCA_SENSOR_MASK_FRONT_ON)) { + if (!aciodrv_icca_set_state( + node_id, AC_IO_ICCA_SLOT_STATE_CLOSE, NULL)) { return false; } if (!aciodrv_icca_read_card(node_id, NULL)) { return false; } - } return true; diff --git a/src/main/aciotest/icca.h b/src/main/aciotest/icca.h index 0b14d20..f91fae5 100644 --- a/src/main/aciotest/icca.h +++ b/src/main/aciotest/icca.h @@ -1,10 +1,10 @@ #ifndef ACIOTEST_ICCA_H #define ACIOTEST_ICCA_H -#include #include +#include -bool aciotest_icca_handler_init(uint8_t node_id, void** ctx); -bool aciotest_icca_handler_update(uint8_t node_id, void* ctx); +bool aciotest_icca_handler_init(uint8_t node_id, void **ctx); +bool aciotest_icca_handler_update(uint8_t node_id, void *ctx); #endif \ No newline at end of file diff --git a/src/main/aciotest/kfca.c b/src/main/aciotest/kfca.c index e024578..e9f0ba9 100644 --- a/src/main/aciotest/kfca.c +++ b/src/main/aciotest/kfca.c @@ -1,22 +1,22 @@ - #include "aciotest/kfca.h" +#include "aciotest/kfca.h" #include "acio/acio.h" -#include #include +#include #include #include "aciodrv/kfca.h" -bool aciotest_kfca_handler_init(uint8_t node_id, void** ctx) +bool aciotest_kfca_handler_init(uint8_t node_id, void **ctx) { *ctx = malloc(sizeof(uint32_t)); - *((uint32_t*) *ctx) = 0; + *((uint32_t *) *ctx) = 0; return aciodrv_kfca_init(node_id); } -bool aciotest_kfca_handler_update(uint8_t node_id, void* ctx) +bool aciotest_kfca_handler_update(uint8_t node_id, void *ctx) { struct ac_io_kfca_poll_in pin; struct ac_io_kfca_poll_out pout; @@ -38,28 +38,29 @@ bool aciotest_kfca_handler_update(uint8_t node_id, void* ctx) pin.gpio[0] = ac_io_u16(pin.gpio[0]); pin.gpio[1] = ac_io_u16(pin.gpio[1]); - printf(">>> KFCA %d: GPIO ON %d\n" + printf( + ">>> KFCA %d: GPIO ON %d\n" "BTN A B C D: %d %d %d %d\n" "FX-L R: %d %d\n" "VOL L: %d\n" "VOL R: %d\n" "START COIN TEST SERV REC HP: %d %d %d %d %d %d\n", - node_id, gpio_test_pin, - pin.gpio[0] & AC_IO_KFCA_IN_GPIO_0_A, - pin.gpio[0] & AC_IO_KFCA_IN_GPIO_0_B, - pin.gpio[0] & AC_IO_KFCA_IN_GPIO_0_C, - pin.gpio[1] & AC_IO_KFCA_IN_GPIO_1_D, - pin.gpio[1] & AC_IO_KFCA_IN_GPIO_1_FX_L, - pin.gpio[1] & AC_IO_KFCA_IN_GPIO_1_FX_R, - (pin.adc[0] >> 6) & 0x3FF, - (pin.adc[1] >> 6) & 0x3FF, - pin.gpio[0] & AC_IO_KFCA_IN_GPIO_0_START, - (pin.gpio_sys) & AC_IO_KFCA_IN_GPIO_SYS_COIN, - (pin.gpio_sys) & AC_IO_KFCA_IN_GPIO_SYS_TEST, - (pin.gpio_sys) & AC_IO_KFCA_IN_GPIO_SYS_SERVICE, - pin.gpio[0] & AC_IO_KFCA_IN_GPIO_0_RECORDER, - pin.gpio[0] & AC_IO_KFCA_IN_GPIO_0_HEADPHONE - ); + node_id, + gpio_test_pin, + pin.gpio[0] & AC_IO_KFCA_IN_GPIO_0_A, + pin.gpio[0] & AC_IO_KFCA_IN_GPIO_0_B, + pin.gpio[0] & AC_IO_KFCA_IN_GPIO_0_C, + pin.gpio[1] & AC_IO_KFCA_IN_GPIO_1_D, + pin.gpio[1] & AC_IO_KFCA_IN_GPIO_1_FX_L, + pin.gpio[1] & AC_IO_KFCA_IN_GPIO_1_FX_R, + (pin.adc[0] >> 6) & 0x3FF, + (pin.adc[1] >> 6) & 0x3FF, + pin.gpio[0] & AC_IO_KFCA_IN_GPIO_0_START, + (pin.gpio_sys) & AC_IO_KFCA_IN_GPIO_SYS_COIN, + (pin.gpio_sys) & AC_IO_KFCA_IN_GPIO_SYS_TEST, + (pin.gpio_sys) & AC_IO_KFCA_IN_GPIO_SYS_SERVICE, + pin.gpio[0] & AC_IO_KFCA_IN_GPIO_0_RECORDER, + pin.gpio[0] & AC_IO_KFCA_IN_GPIO_0_HEADPHONE); ++gpio_test_counter; if (gpio_test_counter >= 4) { diff --git a/src/main/aciotest/kfca.h b/src/main/aciotest/kfca.h index 215ab67..30c3d73 100644 --- a/src/main/aciotest/kfca.h +++ b/src/main/aciotest/kfca.h @@ -1,10 +1,10 @@ #ifndef ACIOTEST_KFCA_H #define ACIOTEST_KFCA_H -#include #include +#include -bool aciotest_kfca_handler_init(uint8_t node_id, void** ctx); -bool aciotest_kfca_handler_update(uint8_t node_id, void* ctx); +bool aciotest_kfca_handler_init(uint8_t node_id, void **ctx); +bool aciotest_kfca_handler_update(uint8_t node_id, void *ctx); #endif diff --git a/src/main/aciotest/main.c b/src/main/aciotest/main.c index 8bce23d..38396cf 100644 --- a/src/main/aciotest/main.c +++ b/src/main/aciotest/main.c @@ -1,6 +1,6 @@ -#include #include #include +#include #include @@ -17,20 +17,18 @@ static uint8_t aciotest_cnt = 0; /** * Enumerate supported ACIO nodes based on their product id. */ -static bool aciotest_assign_handler(char product[4], - struct aciotest_handler_node_handler* handler) +static bool aciotest_assign_handler( + char product[4], struct aciotest_handler_node_handler *handler) { - if (!memcmp(product, "ICCA", 4) - || !memcmp(product, "ICCB", 4) - || !memcmp(product, "ICCC", 4) - ){ + if (!memcmp(product, "ICCA", 4) || !memcmp(product, "ICCB", 4) || + !memcmp(product, "ICCC", 4)) { handler->init = aciotest_icca_handler_init; handler->update = aciotest_icca_handler_update; return true; } - if (!memcmp(product, "KFCA", 4)){ + if (!memcmp(product, "KFCA", 4)) { handler->init = aciotest_kfca_handler_init; handler->update = aciotest_kfca_handler_update; @@ -43,14 +41,17 @@ static bool aciotest_assign_handler(char product[4], /** * Tool to test real ACIO hardware. */ -int main(int argc, char** argv) +int main(int argc, char **argv) { if (argc < 3) { printf( - "aciotest, build "__DATE__ " " __TIME__ "\n" + "aciotest, build "__DATE__ + " " __TIME__ + "\n" "Usage: %s \n" "Example for two slotted readers: %s COM1 57600\n", - argv[0], argv[0]); + argv[0], + argv[0]); return -1; } @@ -67,33 +68,40 @@ int main(int argc, char** argv) printf("Enumerated %d nodes\n", node_count); struct aciotest_handler_node_handler handler[aciotest_handler_max]; - memset(&handler, 0, + memset( + &handler, + 0, sizeof(struct aciotest_handler_node_handler) * aciotest_handler_max); for (uint8_t i = 0; i < node_count; i++) { char product[4]; aciodrv_device_get_node_product_ident(i, product); - printf("> %d: %c%c%c%c\n", i + 1, - product[0], product[1], product[2], product[3]); + printf( + "> %d: %c%c%c%c\n", + i + 1, + product[0], + product[1], + product[2], + product[3]); if (!aciotest_assign_handler(product, &handler[i])) { - printf("ERROR: Unsupported acio node product %c%c%c%c on node %d\n", - product[0], product[1], product[2], product[3], i); + printf( + "ERROR: Unsupported acio node product %c%c%c%c on node %d\n", + product[0], + product[1], + product[2], + product[3], + i); } - } for (uint8_t i = 0; i < aciotest_handler_max; i++) { - if (handler[i].init != NULL) { - if (!handler[i].init(i, &handler[i].ctx)) { printf("ERROR: Initializing node %d failed\n", i); handler[i].update = NULL; } - } - } printf(">>> Initializing done, press enter to start update loop <<<\n"); @@ -107,17 +115,13 @@ int main(int argc, char** argv) printf("%d\n", aciotest_cnt++); for (uint8_t i = 0; i < aciotest_handler_max; i++) { - if (handler[i].update != NULL) { - if (!handler[i].update(i, handler[i].ctx)) { printf("ERROR: Updating node %d, removed from loop\n", i); handler[i].update = NULL; Sleep(5000); } - } - } /* avoid cpu banging */ diff --git a/src/main/bemanitools/bstio.h b/src/main/bemanitools/bstio.h index 65c967e..162e230 100644 --- a/src/main/bemanitools/bstio.h +++ b/src/main/bemanitools/bstio.h @@ -18,8 +18,11 @@ enum bst_io_in_gpio_sys_bit { with four function pointers that may be used to log messages to the game's log file. See comments in glue.h for further information. */ -void bst_io_set_loggers(log_formatter_t misc, log_formatter_t info, - log_formatter_t warning, log_formatter_t fatal); +void bst_io_set_loggers( + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal); /* Initialize your BST IO emulation DLL. Thread management functions are provided to you; you must use these functions to create your own threads if @@ -29,8 +32,10 @@ void bst_io_set_loggers(log_formatter_t misc, log_formatter_t info, See glue.h and geninput.h for further details. */ -bool bst_io_init(thread_create_t thread_create, thread_join_t thread_join, - thread_destroy_t thread_destroy); +bool bst_io_init( + thread_create_t thread_create, + thread_join_t thread_join, + thread_destroy_t thread_destroy); /* Shut down your SDVX IO emulation DLL */ diff --git a/src/main/bemanitools/ddrio.h b/src/main/bemanitools/ddrio.h index 1fb72b5..9f00b90 100644 --- a/src/main/bemanitools/ddrio.h +++ b/src/main/bemanitools/ddrio.h @@ -62,8 +62,11 @@ enum extio_light_bit { with four function pointers that may be used to log messages to the game's log file. See comments in glue.h for further information. */ -void ddr_io_set_loggers(log_formatter_t misc, log_formatter_t info, - log_formatter_t warning, log_formatter_t fatal); +void ddr_io_set_loggers( + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal); /* Initialize your DDR IO emulation DLL. Thread management functions are provided to you; you must use these functions to create your own threads if @@ -73,8 +76,10 @@ void ddr_io_set_loggers(log_formatter_t misc, log_formatter_t info, See glue.h and geninput.h for further details. */ -bool ddr_io_init(thread_create_t thread_create, thread_join_t thread_join, - thread_destroy_t thread_destroy); +bool ddr_io_init( + thread_create_t thread_create, + thread_join_t thread_join, + thread_destroy_t thread_destroy); uint32_t ddr_io_read_pad(void); void ddr_io_set_lights_extio(uint32_t extio_lights); diff --git a/src/main/bemanitools/eamio.h b/src/main/bemanitools/eamio.h index 520b1fd..1c5d9b8 100644 --- a/src/main/bemanitools/eamio.h +++ b/src/main/bemanitools/eamio.h @@ -15,20 +15,20 @@ return from eam_io_get_keypad_state(). */ enum eam_io_keypad_scan_code { - EAM_IO_KEYPAD_0 = 0, - EAM_IO_KEYPAD_1 = 1, - EAM_IO_KEYPAD_4 = 2, - EAM_IO_KEYPAD_7 = 3, - EAM_IO_KEYPAD_00 = 4, - EAM_IO_KEYPAD_2 = 5, - EAM_IO_KEYPAD_5 = 6, - EAM_IO_KEYPAD_8 = 7, - EAM_IO_KEYPAD_DECIMAL = 8, - EAM_IO_KEYPAD_3 = 9, - EAM_IO_KEYPAD_6 = 10, - EAM_IO_KEYPAD_9 = 11, + EAM_IO_KEYPAD_0 = 0, + EAM_IO_KEYPAD_1 = 1, + EAM_IO_KEYPAD_4 = 2, + EAM_IO_KEYPAD_7 = 3, + EAM_IO_KEYPAD_00 = 4, + EAM_IO_KEYPAD_2 = 5, + EAM_IO_KEYPAD_5 = 6, + EAM_IO_KEYPAD_8 = 7, + EAM_IO_KEYPAD_DECIMAL = 8, + EAM_IO_KEYPAD_3 = 9, + EAM_IO_KEYPAD_6 = 10, + EAM_IO_KEYPAD_9 = 11, - EAM_IO_KEYPAD_COUNT = 12, /* Not an actual scan code */ + EAM_IO_KEYPAD_COUNT = 12, /* Not an actual scan code */ }; /* Emulating the sensors of a slotted card reader. The reader has one @@ -70,8 +70,11 @@ struct eam_io_config_api; with four function pointers that may be used to log messages to the game's log file. See comments in glue.h for further information. */ -void eam_io_set_loggers(log_formatter_t misc, log_formatter_t info, - log_formatter_t warning, log_formatter_t fatal); +void eam_io_set_loggers( + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal); /* Initialize your card reader emulation DLL. Thread management functions are provided to you; you must use these functions to create your own threads if @@ -81,8 +84,10 @@ void eam_io_set_loggers(log_formatter_t misc, log_formatter_t info, See glue.h and geninput.h for further details. */ -bool eam_io_init(thread_create_t thread_create, thread_join_t thread_join, - thread_destroy_t thread_destroy); +bool eam_io_init( + thread_create_t thread_create, + thread_join_t thread_join, + thread_destroy_t thread_destroy); /* Shut down your card reader emulation DLL. */ diff --git a/src/main/bemanitools/glue.h b/src/main/bemanitools/glue.h index 50d7d8f..7c9906d 100644 --- a/src/main/bemanitools/glue.h +++ b/src/main/bemanitools/glue.h @@ -7,7 +7,7 @@ #ifdef __GNUC__ /* Bemanitools is compiled with GCC (MinGW, specifically) as of version 5 */ -#define LOG_CHECK_FMT __attribute__(( format(printf, 2, 3) )) +#define LOG_CHECK_FMT __attribute__((format(printf, 2, 3))) #else /* Compile it out for MSVC plebs */ #define LOG_CHECK_FMT @@ -28,7 +28,7 @@ proprietary extensions), so don't use any overly exotic formats. */ typedef void (*log_formatter_t)(const char *module, const char *fmt, ...) - LOG_CHECK_FMT; + LOG_CHECK_FMT; /* An API for spawning threads. This API is defined by libavs, although Bemanitools itself may supply compatible implementations of these functions @@ -39,8 +39,8 @@ typedef void (*log_formatter_t)(const char *module, const char *fmt, ...) this restriction will cause the process to crash. This is a limitation of libavs itself, not Bemanitools. */ -typedef int (*thread_create_t)(int (*proc)(void *), void *ctx, - uint32_t stack_sz, unsigned int priority); +typedef int (*thread_create_t)( + int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority); typedef void (*thread_join_t)(int thread_id, int *result); typedef void (*thread_destroy_t)(int thread_id); diff --git a/src/main/bemanitools/iidxio.h b/src/main/bemanitools/iidxio.h index f85ba50..95d42b6 100644 --- a/src/main/bemanitools/iidxio.h +++ b/src/main/bemanitools/iidxio.h @@ -44,16 +44,16 @@ enum iidx_io_key_bit { /* Bit mapping for the P1 and P2 deck lights */ enum iidx_io_deck_light { - IIDX_IO_DECK_LIGHT_P1_1 = 0, - IIDX_IO_DECK_LIGHT_P1_2 = 1, - IIDX_IO_DECK_LIGHT_P1_3 = 2, - IIDX_IO_DECK_LIGHT_P1_4 = 3, - IIDX_IO_DECK_LIGHT_P1_5 = 4, - IIDX_IO_DECK_LIGHT_P1_6 = 5, - IIDX_IO_DECK_LIGHT_P1_7 = 6, + IIDX_IO_DECK_LIGHT_P1_1 = 0, + IIDX_IO_DECK_LIGHT_P1_2 = 1, + IIDX_IO_DECK_LIGHT_P1_3 = 2, + IIDX_IO_DECK_LIGHT_P1_4 = 3, + IIDX_IO_DECK_LIGHT_P1_5 = 4, + IIDX_IO_DECK_LIGHT_P1_6 = 5, + IIDX_IO_DECK_LIGHT_P1_7 = 6, - IIDX_IO_DECK_LIGHT_P2_1 = 8, - IIDX_IO_DECK_LIGHT_P2_2 = 9, + IIDX_IO_DECK_LIGHT_P2_1 = 8, + IIDX_IO_DECK_LIGHT_P2_2 = 9, IIDX_IO_DECK_LIGHT_P2_3 = 10, IIDX_IO_DECK_LIGHT_P2_4 = 11, IIDX_IO_DECK_LIGHT_P2_5 = 12, @@ -66,16 +66,19 @@ enum iidx_io_deck_light { enum iidx_io_panel_light { IIDX_IO_PANEL_LIGHT_P1_START = 0, IIDX_IO_PANEL_LIGHT_P2_START = 1, - IIDX_IO_PANEL_LIGHT_VEFX = 2, - IIDX_IO_PANEL_LIGHT_EFFECT = 3, + IIDX_IO_PANEL_LIGHT_VEFX = 2, + IIDX_IO_PANEL_LIGHT_EFFECT = 3, }; /* The first function that will be called on your DLL. You will be supplied with four function pointers that may be used to log messages to the game's log file. See comments in glue.h for further information. */ -void iidx_io_set_loggers(log_formatter_t misc, log_formatter_t info, - log_formatter_t warning, log_formatter_t fatal); +void iidx_io_set_loggers( + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal); /* Initialize your IIDX IO emulation DLL. Thread management functions are provided to you; you must use these functions to create your own threads if @@ -85,8 +88,10 @@ void iidx_io_set_loggers(log_formatter_t misc, log_formatter_t info, See glue.h and geninput.h for further details. */ -bool iidx_io_init(thread_create_t thread_create, thread_join_t thread_join, - thread_destroy_t thread_destroy); +bool iidx_io_init( + thread_create_t thread_create, + thread_join_t thread_join, + thread_destroy_t thread_destroy); /* Shut down your IIDX IO emulation DLL */ diff --git a/src/main/bemanitools/input.h b/src/main/bemanitools/input.h index 9c31d92..df80903 100644 --- a/src/main/bemanitools/input.h +++ b/src/main/bemanitools/input.h @@ -22,8 +22,11 @@ This is the only function that can safely be called before input_init(). */ -void input_set_loggers(log_formatter_t misc, log_formatter_t info, - log_formatter_t warning, log_formatter_t fatal); +void input_set_loggers( + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal); /* Initialize the generic input subsystem. You must pass on the thread management functions that have been supplied to your DLL. @@ -35,8 +38,10 @@ void input_set_loggers(log_formatter_t misc, log_formatter_t info, game_type parameter, otherwise you will not receive any input, and any attempts to set a light output level will have no effect. */ -void input_init(thread_create_t thread_create, thread_join_t thread_join, - thread_destroy_t thread_destroy); +void input_init( + thread_create_t thread_create, + thread_join_t thread_join, + thread_destroy_t thread_destroy); /* Shut down the generic input subsystem. After calling this function, no geninput functions other than input_set_loggers() or input_init() may be diff --git a/src/main/bemanitools/jbio.h b/src/main/bemanitools/jbio.h index c717cc4..806d70e 100644 --- a/src/main/bemanitools/jbio.h +++ b/src/main/bemanitools/jbio.h @@ -50,8 +50,11 @@ enum jb_io_rgb_led { with four function pointers that may be used to log messages to the game's log file. See comments in glue.h for further information. */ -void jb_io_set_loggers(log_formatter_t misc, log_formatter_t info, - log_formatter_t warning, log_formatter_t fatal); +void jb_io_set_loggers( + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal); /* Initialize your JB IO emulation DLL. Thread management functions are provided to you; you must use these functions to create your own threads if @@ -61,8 +64,10 @@ void jb_io_set_loggers(log_formatter_t misc, log_formatter_t info, See glue.h and geninput.h for further details. */ -bool jb_io_init(thread_create_t thread_create, thread_join_t thread_join, - thread_destroy_t thread_destroy); +bool jb_io_init( + thread_create_t thread_create, + thread_join_t thread_join, + thread_destroy_t thread_destroy); /* Shut down your JB IO emulation DLL */ @@ -78,6 +83,7 @@ uint8_t jb_io_get_sys_inputs(void); uint16_t jb_io_get_panel_inputs(void); -void jb_io_set_rgb_led(enum jb_io_rgb_led unit, uint8_t r, uint8_t g, uint8_t b); +void jb_io_set_rgb_led( + enum jb_io_rgb_led unit, uint8_t r, uint8_t g, uint8_t b); #endif diff --git a/src/main/bemanitools/sdvxio.h b/src/main/bemanitools/sdvxio.h index 7518a2d..5778e0d 100644 --- a/src/main/bemanitools/sdvxio.h +++ b/src/main/bemanitools/sdvxio.h @@ -43,8 +43,11 @@ enum sdvx_io_out_gpio_bit { with four function pointers that may be used to log messages to the game's log file. See comments in glue.h for further information. */ -void sdvx_io_set_loggers(log_formatter_t misc, log_formatter_t info, - log_formatter_t warning, log_formatter_t fatal); +void sdvx_io_set_loggers( + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal); /* Initialize your SDVX IO emulation DLL. Thread management functions are provided to you; you must use these functions to create your own threads if @@ -54,8 +57,10 @@ void sdvx_io_set_loggers(log_formatter_t misc, log_formatter_t info, See glue.h and geninput.h for further details. */ -bool sdvx_io_init(thread_create_t thread_create, thread_join_t thread_join, - thread_destroy_t thread_destroy); +bool sdvx_io_init( + thread_create_t thread_create, + thread_join_t thread_join, + thread_destroy_t thread_destroy); /* Shut down your SDVX IO emulation DLL */ diff --git a/src/main/bemanitools/vefxio.h b/src/main/bemanitools/vefxio.h index 246d942..9bf170e 100644 --- a/src/main/bemanitools/vefxio.h +++ b/src/main/bemanitools/vefxio.h @@ -12,8 +12,11 @@ with four function pointers that may be used to log messages to the game's log file. See comments in glue.h for further information. */ -void vefx_io_set_loggers(log_formatter_t misc, log_formatter_t info, - log_formatter_t warning, log_formatter_t fatal); +void vefx_io_set_loggers( + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal); /* Initialize your IIDX IO emulation DLL. Thread management functions are provided to you; you must use these functions to create your own threads if @@ -23,8 +26,10 @@ void vefx_io_set_loggers(log_formatter_t misc, log_formatter_t info, See glue.h and geninput.h for further details. */ -bool vefx_io_init(thread_create_t thread_create, thread_join_t thread_join, - thread_destroy_t thread_destroy); +bool vefx_io_init( + thread_create_t thread_create, + thread_join_t thread_join, + thread_destroy_t thread_destroy); /* Shut down your IIDX IO emulation DLL */ @@ -40,7 +45,7 @@ void vefx_io_fini(void); See iidxio.c for mappings. */ -bool vefx_io_recv(uint64_t* ppad); +bool vefx_io_recv(uint64_t *ppad); /* Get slider position, where 0 is the bottom position and 15 is the topmost position. slider_no is a number between 0 (leftmost) and 4 (rightmost). */ diff --git a/src/main/bio2emu/emu.c b/src/main/bio2emu/emu.c index c7f3604..c17664a 100644 --- a/src/main/bio2emu/emu.c +++ b/src/main/bio2emu/emu.c @@ -1,8 +1,8 @@ #include -#include #include #include +#include #include #include @@ -20,11 +20,11 @@ #include "imports/avs.h" +#include "util/array.h" #include "util/defs.h" #include "util/iobuf.h" #include "util/log.h" #include "util/str.h" -#include "util/array.h" static struct array bio2_active_ports; @@ -34,32 +34,33 @@ void bio2emu_init() bio2emu_setupapi_hook_init(&bio2_active_ports); } -void bio2emu_port_init(struct bio2emu_port* bio2_emu) +void bio2emu_port_init(struct bio2emu_port *bio2_emu) { // BIO2 seems like ACIO with just 1 device ac_io_emu_init(&bio2_emu->acio, bio2_emu->wport); rs232_hook_add_fd(bio2_emu->acio.fd); - *array_append(struct bio2emu_port*, &bio2_active_ports) = bio2_emu; + *array_append(struct bio2emu_port *, &bio2_active_ports) = bio2_emu; } -void bio2emu_port_fini(struct bio2emu_port* bio2_emu) +void bio2emu_port_fini(struct bio2emu_port *bio2_emu) { ac_io_emu_fini(&bio2_emu->acio); } -HRESULT bio2emu_port_dispatch_irp(struct irp *irp) +HRESULT +bio2emu_port_dispatch_irp(struct irp *irp) { const struct ac_io_message *msg; HRESULT hr; log_assert(irp != NULL); - struct bio2emu_port* check = NULL; - struct bio2emu_port* selected_emu = NULL; + struct bio2emu_port *check = NULL; + struct bio2emu_port *selected_emu = NULL; - for (size_t i = 0 ; i < bio2_active_ports.nitems ; i++) { - check = *array_item(struct bio2emu_port*, &bio2_active_ports, i); + for (size_t i = 0; i < bio2_active_ports.nitems; i++) { + check = *array_item(struct bio2emu_port *, &bio2_active_ports, i); if (ac_io_emu_match_irp(&check->acio, irp)) { selected_emu = check; } @@ -69,7 +70,7 @@ HRESULT bio2emu_port_dispatch_irp(struct irp *irp) return irp_invoke_next(irp); } - struct ac_io_emu* emu = &selected_emu->acio; + struct ac_io_emu *emu = &selected_emu->acio; for (;;) { hr = ac_io_emu_dispatch_irp(emu, irp); @@ -81,21 +82,22 @@ HRESULT bio2emu_port_dispatch_irp(struct irp *irp) msg = ac_io_emu_request_peek(emu); switch (msg->addr) { - case 0: - ac_io_emu_cmd_assign_addrs(emu, msg, 1); - break; + case 0: + ac_io_emu_cmd_assign_addrs(emu, msg, 1); + break; - case 1: - selected_emu->dispatcher(selected_emu, msg); - break; + case 1: + selected_emu->dispatcher(selected_emu, msg); + break; - case AC_IO_BROADCAST: - log_warning("Broadcast(?) message on BIO2 bus?"); - break; + case AC_IO_BROADCAST: + log_warning("Broadcast(?) message on BIO2 bus?"); + break; - default: - log_warning("BIO2 message on unhandled bus address: %d", msg->addr); - break; + default: + log_warning( + "BIO2 message on unhandled bus address: %d", msg->addr); + break; } ac_io_emu_request_pop(emu); diff --git a/src/main/bio2emu/emu.h b/src/main/bio2emu/emu.h index 68f8dc8..2b5fca7 100644 --- a/src/main/bio2emu/emu.h +++ b/src/main/bio2emu/emu.h @@ -1,26 +1,26 @@ #ifndef BIO2EMU_EMU_H #define BIO2EMU_EMU_H -#include "hook/iohook.h" #include "acioemu/emu.h" +#include "hook/iohook.h" struct bio2emu_port; struct ac_io_message; -typedef void (*bio2_bi2a_dispatcher)(struct bio2emu_port *emu, const struct ac_io_message *req); +typedef void (*bio2_bi2a_dispatcher)( + struct bio2emu_port *emu, const struct ac_io_message *req); struct bio2emu_port { struct ac_io_emu acio; - const char* port; - const wchar_t* wport; + const char *port; + const wchar_t *wport; bio2_bi2a_dispatcher dispatcher; }; - void bio2emu_init(); -void bio2emu_port_init(struct bio2emu_port* bio2emu_emu); -void bio2emu_port_fini(struct bio2emu_port* bio2emu_emu); +void bio2emu_port_init(struct bio2emu_port *bio2emu_emu); +void bio2emu_port_fini(struct bio2emu_port *bio2emu_emu); HRESULT bio2emu_port_dispatch_irp(struct irp *irp); diff --git a/src/main/bio2emu/setupapi.c b/src/main/bio2emu/setupapi.c index c1f78fc..ac33ec8 100644 --- a/src/main/bio2emu/setupapi.c +++ b/src/main/bio2emu/setupapi.c @@ -1,32 +1,43 @@ #define LOG_MODULE "setupapi-hook" -#include #include +#include -#include #include +#include #include "hook/table.h" -#include "bio2emu/setupapi.h" #include "bio2emu/emu.h" +#include "bio2emu/setupapi.h" #include "util/defs.h" #include "util/log.h" #include "util/str.h" #include "util/time.h" -static struct array* bio2_assigned_ports = NULL; +static struct array *bio2_assigned_ports = NULL; -DEFINE_GUID(GUID_COM_BUS_ENUMERATOR, - 0x4D36E978, 0xE325, 0x11CE, 0xBF, 0xC1, 0x08, 0x00, 0x2B, 0xE1, 0x03, 0x18); +DEFINE_GUID( + GUID_COM_BUS_ENUMERATOR, + 0x4D36E978, + 0xE325, + 0x11CE, + 0xBF, + 0xC1, + 0x08, + 0x00, + 0x2B, + 0xE1, + 0x03, + 0x18); #define MAX_INSTANCES_HOOKED 16 #define CUSTOM_DEVICE_INSTANCE 0x3113ca70 #define CUSTOM_DEVICE_INSTANCE_MASK 0xfffffff0 #define CUSTOM_DEVICE_INSTANCE_IDXMASK 0x0000000f -static void* CUSTOM_DEVICE_HANDLE; +static void *CUSTOM_DEVICE_HANDLE; static struct HKEY__ CUSTOM_REGISTRY_HANDLE[MAX_INSTANCES_HOOKED]; @@ -37,14 +48,15 @@ static const size_t DEVICE_PROPERTY_LENGTH = 12; static const char devpath[] = "USB\\VID_5730&PID_804C&MI_00\\000"; static const size_t devpathsize = 32; - // check if HKEY handle is one of ours -static BOOL check_if_match(HKEY ptr, HKEY base) { +static BOOL check_if_match(HKEY ptr, HKEY base) +{ return (ptr >= &base[0]) && (ptr <= &base[MAX_INSTANCES_HOOKED - 1]); } // turn HKEY handle back into idx -static size_t get_match_index(HKEY ptr, HKEY base) { +static size_t get_match_index(HKEY ptr, HKEY base) +{ for (size_t i = 0; i < MAX_INSTANCES_HOOKED; ++i) { if (ptr == &base[i]) { return i; @@ -54,7 +66,8 @@ static size_t get_match_index(HKEY ptr, HKEY base) { } // check if devinst is on of ours (can't use pointer since this is a DWORD) -static BOOL check_instances_limit(DWORD devinst) { +static BOOL check_instances_limit(DWORD devinst) +{ if ((devinst & CUSTOM_DEVICE_INSTANCE_MASK) != CUSTOM_DEVICE_INSTANCE) { return false; } @@ -75,169 +88,118 @@ static BOOL check_instances_limit(DWORD devinst) { // hooked functions // -static BOOL my_SetupDiDestroyDeviceInfoList( - HDEVINFO DeviceInfoSet -); +static BOOL my_SetupDiDestroyDeviceInfoList(HDEVINFO DeviceInfoSet); -static BOOL (*real_SetupDiDestroyDeviceInfoList)( - HDEVINFO DeviceInfoSet -); +static BOOL (*real_SetupDiDestroyDeviceInfoList)(HDEVINFO DeviceInfoSet); static BOOL my_SetupDiEnumDeviceInfo( - HDEVINFO DeviceInfoSet, - DWORD MemberIndex, - PSP_DEVINFO_DATA DeviceInfoData -); + HDEVINFO DeviceInfoSet, DWORD MemberIndex, PSP_DEVINFO_DATA DeviceInfoData); static BOOL (*real_SetupDiEnumDeviceInfo)( - HDEVINFO DeviceInfoSet, - DWORD MemberIndex, - PSP_DEVINFO_DATA DeviceInfoData -); + HDEVINFO DeviceInfoSet, DWORD MemberIndex, PSP_DEVINFO_DATA DeviceInfoData); static HKEY my_SetupDiOpenDevRegKey( - HDEVINFO DeviceInfoSet, + HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, - DWORD Scope, - DWORD HwProfile, - DWORD KeyType, - REGSAM samDesired -); + DWORD Scope, + DWORD HwProfile, + DWORD KeyType, + REGSAM samDesired); static HKEY (*real_SetupDiOpenDevRegKey)( - HDEVINFO DeviceInfoSet, + HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, - DWORD Scope, - DWORD HwProfile, - DWORD KeyType, - REGSAM samDesired -); + DWORD Scope, + DWORD HwProfile, + DWORD KeyType, + REGSAM samDesired); static BOOL my_SetupDiGetDeviceRegistryPropertyA( - HDEVINFO DeviceInfoSet, + HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, - DWORD Property, - PDWORD PropertyRegDataType, - PBYTE PropertyBuffer, - DWORD PropertyBufferSize, - PDWORD RequiredSize -); + DWORD Property, + PDWORD PropertyRegDataType, + PBYTE PropertyBuffer, + DWORD PropertyBufferSize, + PDWORD RequiredSize); static BOOL (*real_SetupDiGetDeviceRegistryPropertyA)( - HDEVINFO DeviceInfoSet, + HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, - DWORD Property, - PDWORD PropertyRegDataType, - PBYTE PropertyBuffer, - DWORD PropertyBufferSize, - PDWORD RequiredSize -); + DWORD Property, + PDWORD PropertyRegDataType, + PBYTE PropertyBuffer, + DWORD PropertyBufferSize, + PDWORD RequiredSize); static BOOL my_SetupDiGetDeviceInfoListDetailA( - HDEVINFO DeviceInfoSet, - PSP_DEVINFO_LIST_DETAIL_DATA_A DeviceInfoSetDetailData -); + HDEVINFO DeviceInfoSet, + PSP_DEVINFO_LIST_DETAIL_DATA_A DeviceInfoSetDetailData); static BOOL (*real_SetupDiGetDeviceInfoListDetailA)( - HDEVINFO DeviceInfoSet, - PSP_DEVINFO_LIST_DETAIL_DATA_A DeviceInfoSetDetailData -); + HDEVINFO DeviceInfoSet, + PSP_DEVINFO_LIST_DETAIL_DATA_A DeviceInfoSetDetailData); static HDEVINFO my_SetupDiGetClassDevsA( - CONST GUID *ClassGuid, - PCSTR Enumerator, - HWND hwndParent, - DWORD Flags -); + CONST GUID *ClassGuid, PCSTR Enumerator, HWND hwndParent, DWORD Flags); -static HDEVINFO(*real_SetupDiGetClassDevsA)( - CONST GUID *ClassGuid, - PCSTR Enumerator, - HWND hwndParent, - DWORD Flags -); +static HDEVINFO (*real_SetupDiGetClassDevsA)( + CONST GUID *ClassGuid, PCSTR Enumerator, HWND hwndParent, DWORD Flags); static CONFIGRET my_CM_Get_Device_IDA( - DEVINST dnDevInst, - PSTR Buffer, - ULONG BufferLen, - ULONG ulFlags -); + DEVINST dnDevInst, PSTR Buffer, ULONG BufferLen, ULONG ulFlags); -static CONFIGRET(*real_CM_Get_Device_IDA)( - DEVINST dnDevInst, - PSTR Buffer, - ULONG BufferLen, - ULONG ulFlags -); +static CONFIGRET (*real_CM_Get_Device_IDA)( + DEVINST dnDevInst, PSTR Buffer, ULONG BufferLen, ULONG ulFlags); static const struct hook_symbol bio2emu_setupapi_syms[] = { - { - .name = "SetupDiDestroyDeviceInfoList", - .patch = my_SetupDiDestroyDeviceInfoList, - .link = (void **) &real_SetupDiDestroyDeviceInfoList - }, - { - .name = "SetupDiEnumDeviceInfo", - .patch = my_SetupDiEnumDeviceInfo, - .link = (void **) &real_SetupDiEnumDeviceInfo - }, - { - .name = "SetupDiOpenDevRegKey", - .patch = my_SetupDiOpenDevRegKey, - .link = (void **) &real_SetupDiOpenDevRegKey - }, - { - .name = "SetupDiGetDeviceRegistryPropertyA", - .patch = my_SetupDiGetDeviceRegistryPropertyA, - .link = (void **) &real_SetupDiGetDeviceRegistryPropertyA - }, - { - .name = "SetupDiGetDeviceInfoListDetailA", - .patch = my_SetupDiGetDeviceInfoListDetailA, - .link = (void **) &real_SetupDiGetDeviceInfoListDetailA - }, - { - .name = "SetupDiGetClassDevsA", - .patch = my_SetupDiGetClassDevsA, - .link = (void **) &real_SetupDiGetClassDevsA - }, - { - .name = "CM_Get_Device_IDA", - .patch = my_CM_Get_Device_IDA, - .link = (void **) &real_CM_Get_Device_IDA - }, + {.name = "SetupDiDestroyDeviceInfoList", + .patch = my_SetupDiDestroyDeviceInfoList, + .link = (void **) &real_SetupDiDestroyDeviceInfoList}, + {.name = "SetupDiEnumDeviceInfo", + .patch = my_SetupDiEnumDeviceInfo, + .link = (void **) &real_SetupDiEnumDeviceInfo}, + {.name = "SetupDiOpenDevRegKey", + .patch = my_SetupDiOpenDevRegKey, + .link = (void **) &real_SetupDiOpenDevRegKey}, + {.name = "SetupDiGetDeviceRegistryPropertyA", + .patch = my_SetupDiGetDeviceRegistryPropertyA, + .link = (void **) &real_SetupDiGetDeviceRegistryPropertyA}, + {.name = "SetupDiGetDeviceInfoListDetailA", + .patch = my_SetupDiGetDeviceInfoListDetailA, + .link = (void **) &real_SetupDiGetDeviceInfoListDetailA}, + {.name = "SetupDiGetClassDevsA", + .patch = my_SetupDiGetClassDevsA, + .link = (void **) &real_SetupDiGetClassDevsA}, + {.name = "CM_Get_Device_IDA", + .patch = my_CM_Get_Device_IDA, + .link = (void **) &real_CM_Get_Device_IDA}, }; static LSTATUS my_RegQueryValueExA( - HKEY hKey, - LPCSTR lpValueName, - LPDWORD lpReserved, - LPDWORD lpType, - LPBYTE lpData, - LPDWORD lpcbData -); + HKEY hKey, + LPCSTR lpValueName, + LPDWORD lpReserved, + LPDWORD lpType, + LPBYTE lpData, + LPDWORD lpcbData); static LSTATUS (*real_RegQueryValueExA)( - HKEY hKey, - LPCSTR lpValueName, - LPDWORD lpReserved, - LPDWORD lpType, - LPBYTE lpData, - LPDWORD lpcbData -); + HKEY hKey, + LPCSTR lpValueName, + LPDWORD lpReserved, + LPDWORD lpType, + LPBYTE lpData, + LPDWORD lpcbData); static const struct hook_symbol bio2emu_Advapi32_syms[] = { - { - .name = "RegQueryValueExA", - .patch = my_RegQueryValueExA, - .link = (void **) &real_RegQueryValueExA - }, + {.name = "RegQueryValueExA", + .patch = my_RegQueryValueExA, + .link = (void **) &real_RegQueryValueExA}, }; -static BOOL my_SetupDiDestroyDeviceInfoList( - HDEVINFO DeviceInfoSet -){ - if (DeviceInfoSet == &CUSTOM_DEVICE_HANDLE){ +static BOOL my_SetupDiDestroyDeviceInfoList(HDEVINFO DeviceInfoSet) +{ + if (DeviceInfoSet == &CUSTOM_DEVICE_HANDLE) { log_info("Inside: %s", __FUNCTION__); return true; } @@ -246,11 +208,9 @@ static BOOL my_SetupDiDestroyDeviceInfoList( } static BOOL my_SetupDiEnumDeviceInfo( - HDEVINFO DeviceInfoSet, - DWORD MemberIndex, - PSP_DEVINFO_DATA DeviceInfoData -){ - if (DeviceInfoSet == &CUSTOM_DEVICE_HANDLE){ + HDEVINFO DeviceInfoSet, DWORD MemberIndex, PSP_DEVINFO_DATA DeviceInfoData) +{ + if (DeviceInfoSet == &CUSTOM_DEVICE_HANDLE) { log_info("%s: Loaded idx %ld", __FUNCTION__, MemberIndex); if (MemberIndex < bio2_assigned_ports->nitems) { DeviceInfoData->DevInst = CUSTOM_DEVICE_INSTANCE | MemberIndex; @@ -258,49 +218,62 @@ static BOOL my_SetupDiEnumDeviceInfo( } return false; } - return real_SetupDiEnumDeviceInfo(DeviceInfoSet, MemberIndex, DeviceInfoData); + return real_SetupDiEnumDeviceInfo( + DeviceInfoSet, MemberIndex, DeviceInfoData); } static HKEY my_SetupDiOpenDevRegKey( - HDEVINFO DeviceInfoSet, + HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, - DWORD Scope, - DWORD HwProfile, - DWORD KeyType, - REGSAM samDesired -){ - if (DeviceInfoSet == &CUSTOM_DEVICE_HANDLE){ - if (check_instances_limit(DeviceInfoData->DevInst)){ + DWORD Scope, + DWORD HwProfile, + DWORD KeyType, + REGSAM samDesired) +{ + if (DeviceInfoSet == &CUSTOM_DEVICE_HANDLE) { + if (check_instances_limit(DeviceInfoData->DevInst)) { log_info("%s: matched instance", __FUNCTION__); - return &CUSTOM_REGISTRY_HANDLE[DeviceInfoData->DevInst & CUSTOM_DEVICE_INSTANCE_IDXMASK]; + return &CUSTOM_REGISTRY_HANDLE + [DeviceInfoData->DevInst & CUSTOM_DEVICE_INSTANCE_IDXMASK]; } } - return real_SetupDiOpenDevRegKey(DeviceInfoSet, DeviceInfoData, Scope, HwProfile, KeyType, samDesired); + return real_SetupDiOpenDevRegKey( + DeviceInfoSet, DeviceInfoData, Scope, HwProfile, KeyType, samDesired); } static BOOL my_SetupDiGetDeviceRegistryPropertyA( - HDEVINFO DeviceInfoSet, + HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, - DWORD Property, - PDWORD PropertyRegDataType, - PBYTE PropertyBuffer, - DWORD PropertyBufferSize, - PDWORD RequiredSize -){ - if (DeviceInfoSet == &CUSTOM_DEVICE_HANDLE){ - if (check_instances_limit(DeviceInfoData->DevInst)){ - struct bio2emu_port* selected_port = *array_item(struct bio2emu_port*, bio2_assigned_ports, DeviceInfoData->DevInst & CUSTOM_DEVICE_INSTANCE_IDXMASK); + DWORD Property, + PDWORD PropertyRegDataType, + PBYTE PropertyBuffer, + DWORD PropertyBufferSize, + PDWORD RequiredSize) +{ + if (DeviceInfoSet == &CUSTOM_DEVICE_HANDLE) { + if (check_instances_limit(DeviceInfoData->DevInst)) { + struct bio2emu_port *selected_port = *array_item( + struct bio2emu_port *, + bio2_assigned_ports, + DeviceInfoData->DevInst & CUSTOM_DEVICE_INSTANCE_IDXMASK); size_t portname_len = strlen(selected_port->port); - size_t required_size = (DEVICE_PROPERTY_LENGTH + portname_len + 1 + 1); // + 1 for ')', + 1 for NULL + size_t required_size = + (DEVICE_PROPERTY_LENGTH + portname_len + 1 + + 1); // + 1 for ')', + 1 for NULL - if (PropertyBuffer && (PropertyBufferSize >= required_size)){ - char* PropBuffStr = (char*)PropertyBuffer; + if (PropertyBuffer && (PropertyBufferSize >= required_size)) { + char *PropBuffStr = (char *) PropertyBuffer; strcpy(PropBuffStr, DEVICE_PROPERTY_VALUE); - strcpy(PropBuffStr + DEVICE_PROPERTY_LENGTH, selected_port->port); - strcpy(PropBuffStr + DEVICE_PROPERTY_LENGTH + portname_len, ")"); + strcpy( + PropBuffStr + DEVICE_PROPERTY_LENGTH, selected_port->port); + strcpy( + PropBuffStr + DEVICE_PROPERTY_LENGTH + portname_len, ")"); - log_info("%s: Done copying property name [%s]", __FUNCTION__, PropBuffStr); + log_info( + "%s: Done copying property name [%s]", + __FUNCTION__, + PropBuffStr); } else { log_info("%s: Returning size", __FUNCTION__); *RequiredSize = required_size; @@ -309,28 +282,33 @@ static BOOL my_SetupDiGetDeviceRegistryPropertyA( log_info("%s: STUB RETURN", __FUNCTION__); return true; } - return real_SetupDiGetDeviceRegistryPropertyA(DeviceInfoSet, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize); + return real_SetupDiGetDeviceRegistryPropertyA( + DeviceInfoSet, + DeviceInfoData, + Property, + PropertyRegDataType, + PropertyBuffer, + PropertyBufferSize, + RequiredSize); } static BOOL my_SetupDiGetDeviceInfoListDetailA( - HDEVINFO DeviceInfoSet, - PSP_DEVINFO_LIST_DETAIL_DATA_A DeviceInfoSetDetailData -){ - if (DeviceInfoSet == &CUSTOM_DEVICE_HANDLE){ + HDEVINFO DeviceInfoSet, + PSP_DEVINFO_LIST_DETAIL_DATA_A DeviceInfoSetDetailData) +{ + if (DeviceInfoSet == &CUSTOM_DEVICE_HANDLE) { log_info("Inside: %s", __FUNCTION__); return true; } - return real_SetupDiGetDeviceInfoListDetailA(DeviceInfoSet, DeviceInfoSetDetailData); + return real_SetupDiGetDeviceInfoListDetailA( + DeviceInfoSet, DeviceInfoSetDetailData); } static HDEVINFO my_SetupDiGetClassDevsA( - CONST GUID *ClassGuid, - PCSTR Enumerator, - HWND hwndParent, - DWORD Flags -){ + CONST GUID *ClassGuid, PCSTR Enumerator, HWND hwndParent, DWORD Flags) +{ if (ClassGuid) { - if (IsEqualGUID(ClassGuid, &GUID_COM_BUS_ENUMERATOR)){ + if (IsEqualGUID(ClassGuid, &GUID_COM_BUS_ENUMERATOR)) { log_info("Inside: %s", __FUNCTION__); return &CUSTOM_DEVICE_HANDLE; } @@ -339,19 +317,20 @@ static HDEVINFO my_SetupDiGetClassDevsA( } static LSTATUS my_RegQueryValueExA( - HKEY hKey, - LPCSTR lpValueName, - LPDWORD lpReserved, - LPDWORD lpType, - LPBYTE lpData, - LPDWORD lpcbData -){ - if (check_if_match(hKey, CUSTOM_REGISTRY_HANDLE)){ + HKEY hKey, + LPCSTR lpValueName, + LPDWORD lpReserved, + LPDWORD lpType, + LPBYTE lpData, + LPDWORD lpcbData) +{ + if (check_if_match(hKey, CUSTOM_REGISTRY_HANDLE)) { if (strcmp(lpValueName, "PortName") == 0) { - if (lpData){ + if (lpData) { size_t portidx = get_match_index(hKey, CUSTOM_REGISTRY_HANDLE); - struct bio2emu_port* selected_port = *array_item(struct bio2emu_port*, bio2_assigned_ports, portidx); - strncpy((char*)lpData, selected_port->port, *lpcbData); + struct bio2emu_port *selected_port = *array_item( + struct bio2emu_port *, bio2_assigned_ports, portidx); + strncpy((char *) lpData, selected_port->port, *lpcbData); log_info("%s: Queried %s", __FUNCTION__, selected_port->port); return ERROR_SUCCESS; @@ -359,21 +338,20 @@ static LSTATUS my_RegQueryValueExA( return ERROR_MORE_DATA; } } - return real_RegQueryValueExA(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData); + return real_RegQueryValueExA( + hKey, lpValueName, lpReserved, lpType, lpData, lpcbData); } static CONFIGRET my_CM_Get_Device_IDA( - DEVINST dnDevInst, - PSTR Buffer, - ULONG BufferLen, - ULONG ulFlags -){ + DEVINST dnDevInst, PSTR Buffer, ULONG BufferLen, ULONG ulFlags) +{ if (Buffer && BufferLen > devpathsize) { if (check_instances_limit(dnDevInst)) { log_info("%s: Injecting custom parent ID for BIO2", __FUNCTION__); strcpy(Buffer, devpath); - Buffer[devpathsize - 1] = '\0' + (dnDevInst & CUSTOM_DEVICE_INSTANCE_IDXMASK); + Buffer[devpathsize - 1] = + '\0' + (dnDevInst & CUSTOM_DEVICE_INSTANCE_IDXMASK); log_info("%s: %s", __FUNCTION__, Buffer); return CR_SUCCESS; } @@ -381,21 +359,21 @@ static CONFIGRET my_CM_Get_Device_IDA( return real_CM_Get_Device_IDA(dnDevInst, Buffer, BufferLen, ulFlags); } -void bio2emu_setupapi_hook_init(struct array* bio2_ports) +void bio2emu_setupapi_hook_init(struct array *bio2_ports) { bio2_assigned_ports = bio2_ports; hook_table_apply( - NULL, - "setupapi.dll", - bio2emu_setupapi_syms, - lengthof(bio2emu_setupapi_syms)); + NULL, + "setupapi.dll", + bio2emu_setupapi_syms, + lengthof(bio2emu_setupapi_syms)); hook_table_apply( - NULL, - "Advapi32.dll", - bio2emu_Advapi32_syms, - lengthof(bio2emu_Advapi32_syms)); + NULL, + "Advapi32.dll", + bio2emu_Advapi32_syms, + lengthof(bio2emu_Advapi32_syms)); log_info("Inserted setupapi hooks"); } diff --git a/src/main/bio2emu/setupapi.h b/src/main/bio2emu/setupapi.h index ac72c7d..e2f554f 100644 --- a/src/main/bio2emu/setupapi.h +++ b/src/main/bio2emu/setupapi.h @@ -3,6 +3,6 @@ #include "util/array.h" -void bio2emu_setupapi_hook_init(struct array* bio2_ports); +void bio2emu_setupapi_hook_init(struct array *bio2_ports); #endif diff --git a/src/main/bsthook/acio.c b/src/main/bsthook/acio.c index 7041456..c7fb07b 100644 --- a/src/main/bsthook/acio.c +++ b/src/main/bsthook/acio.c @@ -1,8 +1,8 @@ #include -#include #include #include +#include #include #include @@ -40,7 +40,8 @@ void ac_io_bus_fini(void) ac_io_emu_fini(&ac_io_emu); } -HRESULT ac_io_bus_dispatch_irp(struct irp *irp) +HRESULT +ac_io_bus_dispatch_irp(struct irp *irp) { const struct ac_io_message *msg; HRESULT hr; @@ -82,8 +83,8 @@ HRESULT ac_io_bus_dispatch_irp(struct irp *irp) break; default: - log_warning("ACIO message on unhandled bus address: %d", - msg->addr); + log_warning( + "ACIO message on unhandled bus address: %d", msg->addr); break; } diff --git a/src/main/bsthook/dllmain.c b/src/main/bsthook/dllmain.c index 71bc87e..cdc28c0 100644 --- a/src/main/bsthook/dllmain.c +++ b/src/main/bsthook/dllmain.c @@ -38,10 +38,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *config) log_info("Starting up BeatStream IO backend"); bst_io_set_loggers( - log_body_misc, - log_body_info, - log_body_warning, - log_body_fatal); + log_body_misc, log_body_info, log_body_warning, log_body_fatal); ok = bst_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy); @@ -50,10 +47,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *config) } eam_io_set_loggers( - log_body_misc, - log_body_info, - log_body_warning, - log_body_fatal); + 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); @@ -102,14 +96,11 @@ BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx) } log_to_external( - log_body_misc, - log_body_info, - log_body_warning, - log_body_fatal); + log_body_misc, log_body_info, log_body_warning, log_body_fatal); args_recover(&argc, &argv); - for (i = 1 ; i < argc ; i++) { + for (i = 1; i < argc; i++) { if (argv[i][0] != '-') { continue; } @@ -133,4 +124,3 @@ BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx) return TRUE; } - diff --git a/src/main/bsthook/gfx.c b/src/main/bsthook/gfx.c index 1da96a1..c22c805 100644 --- a/src/main/bsthook/gfx.c +++ b/src/main/bsthook/gfx.c @@ -1,5 +1,5 @@ -#include #include +#include #include @@ -13,25 +13,33 @@ #include "util/log.h" static HRESULT STDCALL my_CreateDevice( - IDirect3D9 *self, UINT adapter, D3DDEVTYPE type, HWND hwnd, DWORD flags, - D3DPRESENT_PARAMETERS *pp, IDirect3DDevice9 **pdev); + IDirect3D9 *self, + UINT adapter, + D3DDEVTYPE type, + HWND hwnd, + DWORD flags, + D3DPRESENT_PARAMETERS *pp, + IDirect3DDevice9 **pdev); static IDirect3D9 *STDCALL my_Direct3DCreate9(UINT sdk_ver); -static IDirect3D9 * (STDCALL *real_Direct3DCreate9)(UINT sdk_ver); +static IDirect3D9 *(STDCALL *real_Direct3DCreate9)(UINT sdk_ver); static const struct hook_symbol gfx_hook_syms[] = { - { - .name = "Direct3DCreate9", - .patch = my_Direct3DCreate9, - .link = (void **) &real_Direct3DCreate9 - }, + {.name = "Direct3DCreate9", + .patch = my_Direct3DCreate9, + .link = (void **) &real_Direct3DCreate9}, }; static bool gfx_windowed; static HRESULT STDCALL my_CreateDevice( - IDirect3D9 *self, UINT adapter, D3DDEVTYPE type, HWND hwnd, DWORD flags, - D3DPRESENT_PARAMETERS *pp, IDirect3DDevice9 **pdev) + IDirect3D9 *self, + UINT adapter, + D3DDEVTYPE type, + HWND hwnd, + DWORD flags, + D3DPRESENT_PARAMETERS *pp, + IDirect3DDevice9 **pdev) { IDirect3D9 *real = COM_PROXY_UNWRAP(self); HRESULT hr; @@ -67,11 +75,7 @@ static IDirect3D9 *STDCALL my_Direct3DCreate9(UINT sdk_ver) void gfx_init(void) { - hook_table_apply( - NULL, - "d3d9.dll", - gfx_hook_syms, - lengthof(gfx_hook_syms)); + hook_table_apply(NULL, "d3d9.dll", gfx_hook_syms, lengthof(gfx_hook_syms)); log_info("Inserted graphics hooks"); } @@ -80,4 +84,3 @@ void gfx_set_windowed(void) { gfx_windowed = true; } - diff --git a/src/main/bsthook/kfca.c b/src/main/bsthook/kfca.c index f6ce753..0e3ff02 100644 --- a/src/main/bsthook/kfca.c +++ b/src/main/bsthook/kfca.c @@ -30,40 +30,42 @@ void kfca_dispatch_request(const struct ac_io_message *req) cmd_code = ac_io_u16(req->cmd.code); switch (cmd_code) { - case AC_IO_CMD_GET_VERSION: - log_misc("AC_IO_CMD_GET_VERSION(%d)", req->addr); - kfca_send_version(req); + case AC_IO_CMD_GET_VERSION: + log_misc("AC_IO_CMD_GET_VERSION(%d)", req->addr); + kfca_send_version(req); - break; + break; - case AC_IO_CMD_START_UP: - log_misc("AC_IO_CMD_START_UP(%d)", req->addr); - kfca_report_status(req, 0x00); + case AC_IO_CMD_START_UP: + log_misc("AC_IO_CMD_START_UP(%d)", req->addr); + kfca_report_status(req, 0x00); - break; + break; - case AC_IO_CMD_KFCA_POLL: - kfca_poll(req); + case AC_IO_CMD_KFCA_POLL: + kfca_poll(req); - break; + break; - case AC_IO_CMD_KFCA_WATCHDOG: - log_misc("AC_IO_CMD_KFCA_WATCHDOG(%d)", req->addr); - kfca_report_status(req, 0x00); + case AC_IO_CMD_KFCA_WATCHDOG: + log_misc("AC_IO_CMD_KFCA_WATCHDOG(%d)", req->addr); + kfca_report_status(req, 0x00); - break; + break; - case AC_IO_CMD_KFCA_AMP_CONTROL: - log_misc("AC_IO_CMD_KFCA_AMP_CONTROL(%d)", req->addr); - kfca_report_nil(req); + case AC_IO_CMD_KFCA_AMP_CONTROL: + log_misc("AC_IO_CMD_KFCA_AMP_CONTROL(%d)", req->addr); + kfca_report_nil(req); - break; + break; - default: - log_warning("Unknown ACIO message %04x on KFCA mode, addr=%d", - cmd_code, req->addr); + default: + log_warning( + "Unknown ACIO message %04x on KFCA mode, addr=%d", + cmd_code, + req->addr); - break; + break; } } @@ -80,8 +82,10 @@ static void kfca_send_version(const struct ac_io_message *req) resp.cmd.version.major = 0x01; resp.cmd.version.minor = 0x01; resp.cmd.version.revision = 0x00; - memcpy(resp.cmd.version.product_code, "KFCA", - sizeof(resp.cmd.version.product_code)); + memcpy( + resp.cmd.version.product_code, + "KFCA", + sizeof(resp.cmd.version.product_code)); strncpy(resp.cmd.version.date, __DATE__, sizeof(resp.cmd.version.date)); strncpy(resp.cmd.version.time, __TIME__, sizeof(resp.cmd.version.time)); @@ -133,4 +137,3 @@ static void kfca_poll(const struct ac_io_message *req) ac_io_emu_response_push(kfca_ac_io_emu, &resp, 0); } - diff --git a/src/main/bsthook/settings.c b/src/main/bsthook/settings.c index d4282fa..8f48ea8 100644 --- a/src/main/bsthook/settings.c +++ b/src/main/bsthook/settings.c @@ -16,47 +16,43 @@ /* ------------------------------------------------------------------------- */ static HANDLE STDCALL my_CreateFileA( - LPCSTR lpFileName, - DWORD dwDesiredAccess, - DWORD dwShareMode, - LPSECURITY_ATTRIBUTES lpSecurityAttributes, - DWORD dwCreationDisposition, - DWORD dwFlagsAndAttributes, - HANDLE hTemplateFile); + LPCSTR lpFileName, + DWORD dwDesiredAccess, + DWORD dwShareMode, + LPSECURITY_ATTRIBUTES lpSecurityAttributes, + DWORD dwCreationDisposition, + DWORD dwFlagsAndAttributes, + HANDLE hTemplateFile); -static HANDLE (STDCALL *real_CreateFileA)( - LPCSTR lpFileName, - DWORD dwDesiredAccess, - DWORD dwShareMode, - LPSECURITY_ATTRIBUTES lpSecurityAttributes, - DWORD dwCreationDisposition, - DWORD dwFlagsAndAttributes, - HANDLE hTemplateFile); +static HANDLE(STDCALL *real_CreateFileA)( + LPCSTR lpFileName, + DWORD dwDesiredAccess, + DWORD dwShareMode, + LPSECURITY_ATTRIBUTES lpSecurityAttributes, + DWORD dwCreationDisposition, + DWORD dwFlagsAndAttributes, + HANDLE hTemplateFile); /* ------------------------------------------------------------------------- */ static const struct hook_symbol settings_hook_syms[] = { - { - .name = "CreateFileA", - .patch = my_CreateFileA, - .link = (void **) &real_CreateFileA - }, + {.name = "CreateFileA", + .patch = my_CreateFileA, + .link = (void **) &real_CreateFileA}, }; /* ------------------------------------------------------------------------- */ static HANDLE STDCALL my_CreateFileA( - LPCSTR lpFileName, - DWORD dwDesiredAccess, - DWORD dwShareMode, - LPSECURITY_ATTRIBUTES lpSecurityAttributes, - DWORD dwCreationDisposition, - DWORD dwFlagsAndAttributes, - HANDLE hTemplateFile) + LPCSTR lpFileName, + DWORD dwDesiredAccess, + DWORD dwShareMode, + LPSECURITY_ATTRIBUTES lpSecurityAttributes, + DWORD dwCreationDisposition, + DWORD dwFlagsAndAttributes, + HANDLE hTemplateFile) { - if ( lpFileName != NULL && - lpFileName[0] == 'e' && - lpFileName[1] == ':') { + if (lpFileName != NULL && lpFileName[0] == 'e' && lpFileName[1] == ':') { HANDLE handle; char new_path[MAX_PATH]; @@ -64,28 +60,34 @@ static HANDLE STDCALL my_CreateFileA( new_path[1] = '\\'; log_misc("Remapped settings path %s", new_path); - handle = real_CreateFileA(new_path, dwDesiredAccess, dwShareMode, - lpSecurityAttributes, dwCreationDisposition, - dwFlagsAndAttributes, hTemplateFile); + handle = real_CreateFileA( + new_path, + dwDesiredAccess, + dwShareMode, + lpSecurityAttributes, + dwCreationDisposition, + dwFlagsAndAttributes, + hTemplateFile); return handle; } - return real_CreateFileA(lpFileName, dwDesiredAccess, dwShareMode, - lpSecurityAttributes, dwCreationDisposition, - dwFlagsAndAttributes, hTemplateFile); + return real_CreateFileA( + lpFileName, + dwDesiredAccess, + dwShareMode, + lpSecurityAttributes, + dwCreationDisposition, + dwFlagsAndAttributes, + hTemplateFile); } - /* ------------------------------------------------------------------------- */ void settings_hook_init(void) { hook_table_apply( - NULL, - "kernel32.dll", - settings_hook_syms, - lengthof(settings_hook_syms)); + NULL, "kernel32.dll", settings_hook_syms, lengthof(settings_hook_syms)); log_info("Inserted settings hooks"); } diff --git a/src/main/bstio/bstio.c b/src/main/bstio/bstio.c index 63b9feb..c719074 100644 --- a/src/main/bstio/bstio.c +++ b/src/main/bstio/bstio.c @@ -8,14 +8,19 @@ static uint8_t bst_io_gpio_sys; -void bst_io_set_loggers(log_formatter_t misc, log_formatter_t info, - log_formatter_t warning, log_formatter_t fatal) +void bst_io_set_loggers( + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal) { input_set_loggers(misc, info, warning, fatal); } -bool bst_io_init(thread_create_t thread_create, thread_join_t thread_join, - thread_destroy_t thread_destroy) +bool bst_io_init( + thread_create_t thread_create, + thread_join_t thread_join, + thread_destroy_t thread_destroy) { input_init(thread_create, thread_join, thread_destroy); mapper_config_load("bst"); @@ -39,4 +44,3 @@ uint8_t bst_io_get_input(void) { return bst_io_gpio_sys; } - diff --git a/src/main/cconfig/cconfig-hook.c b/src/main/cconfig/cconfig-hook.c index f8634cc..c0703b3 100644 --- a/src/main/cconfig/cconfig-hook.c +++ b/src/main/cconfig/cconfig-hook.c @@ -9,14 +9,16 @@ #include "util/cmdline.h" #include "util/log.h" -bool cconfig_hook_config_init(struct cconfig* config, const char* usage_header, - enum cconfig_cmd_usage_out cmd_usage_out) +bool cconfig_hook_config_init( + struct cconfig *config, + const char *usage_header, + enum cconfig_cmd_usage_out cmd_usage_out) { bool success; int argc; char **argv; enum cconfig_conf_error conf_error; - char* config_path; + char *config_path; success = true; @@ -33,36 +35,39 @@ bool cconfig_hook_config_init(struct cconfig* config, const char* usage_header, for (int i = 0; i < argc; i++) { if (!strcmp(argv[i], "--config")) { if (i + 1 >= argc) { - log_fatal("--config parameter not followed by a config file " + log_fatal( + "--config parameter not followed by a config file " "path param"); goto failure; - } + } config_path = argv[i + 1]; break; } } - + if (config_path) { log_misc("Loading config file: %s", config_path); conf_error = cconfig_conf_load_from_file(config, config_path, false); if (conf_error == CCONFIG_CONF_ERROR_NO_SUCH_FILE) { /* Create default config */ - if (cconfig_conf_save_to_file(config, config_path) != - CCONFIG_CONF_SUCCESS) { - log_fatal("Creating default config file '%s' failed", - config_path); + if (cconfig_conf_save_to_file(config, config_path) != + CCONFIG_CONF_SUCCESS) { + log_fatal( + "Creating default config file '%s' failed", config_path); goto failure; } else { - log_info("Default configuration '%s' created. Restart " - "application", config_path); + log_info( + "Default configuration '%s' created. Restart " + "application", + config_path); goto failure; } } else if (conf_error != CCONFIG_CONF_SUCCESS) { - log_fatal("Error loading config file '%s': %d", config_path, - conf_error); + log_fatal( + "Error loading config file '%s': %d", config_path, conf_error); goto failure; } diff --git a/src/main/cconfig/cconfig-hook.h b/src/main/cconfig/cconfig-hook.h index aa9fa41..fd19756 100644 --- a/src/main/cconfig/cconfig-hook.h +++ b/src/main/cconfig/cconfig-hook.h @@ -4,7 +4,9 @@ #include "cconfig/cconfig.h" #include "cconfig/cmd.h" -bool cconfig_hook_config_init(struct cconfig* config, const char* usage_header, - enum cconfig_cmd_usage_out cmd_usage_out); +bool cconfig_hook_config_init( + struct cconfig *config, + const char *usage_header, + enum cconfig_cmd_usage_out cmd_usage_out); #endif \ No newline at end of file diff --git a/src/main/cconfig/cconfig-util.c b/src/main/cconfig/cconfig-util.c index 2c30f65..f4ce05f 100644 --- a/src/main/cconfig/cconfig-util.c +++ b/src/main/cconfig/cconfig-util.c @@ -9,10 +9,13 @@ #include "util/log.h" #include "util/mem.h" -bool cconfig_util_get_int(struct cconfig* config, const char* key, int32_t* ret, - int32_t default_value) +bool cconfig_util_get_int( + struct cconfig *config, + const char *key, + int32_t *ret, + int32_t default_value) { - struct cconfig_entry* entry; + struct cconfig_entry *entry; log_assert(config); log_assert(key); @@ -29,10 +32,10 @@ bool cconfig_util_get_int(struct cconfig* config, const char* key, int32_t* ret, return false; } -bool cconfig_util_get_float(struct cconfig* config, const char* key, float* ret, - float default_value) +bool cconfig_util_get_float( + struct cconfig *config, const char *key, float *ret, float default_value) { - struct cconfig_entry* entry; + struct cconfig_entry *entry; log_assert(config); log_assert(key); @@ -49,10 +52,10 @@ bool cconfig_util_get_float(struct cconfig* config, const char* key, float* ret, return false; } -bool cconfig_util_get_bool(struct cconfig* config, const char* key, bool* ret, - bool default_value) +bool cconfig_util_get_bool( + struct cconfig *config, const char *key, bool *ret, bool default_value) { - struct cconfig_entry* entry; + struct cconfig_entry *entry; log_assert(config); log_assert(key); @@ -73,10 +76,14 @@ bool cconfig_util_get_bool(struct cconfig* config, const char* key, bool* ret, return false; } -bool cconfig_util_get_str(struct cconfig* config, const char* key, - char* buffer, size_t len, const char* default_value) +bool cconfig_util_get_str( + struct cconfig *config, + const char *key, + char *buffer, + size_t len, + const char *default_value) { - struct cconfig_entry* entry; + struct cconfig_entry *entry; size_t str_len; log_assert(config); @@ -97,11 +104,15 @@ bool cconfig_util_get_str(struct cconfig* config, const char* key, return false; } -bool cconfig_util_get_data(struct cconfig* config, const char* key, - uint8_t* buffer, size_t len, const uint8_t* default_value) +bool cconfig_util_get_data( + struct cconfig *config, + const char *key, + uint8_t *buffer, + size_t len, + const uint8_t *default_value) { size_t res_len; - struct cconfig_entry* entry; + struct cconfig_entry *entry; log_assert(config); log_assert(key); @@ -124,10 +135,10 @@ bool cconfig_util_get_data(struct cconfig* config, const char* key, return false; } -void cconfig_util_set_int(struct cconfig* config, const char* key, - int32_t value, const char* desc) +void cconfig_util_set_int( + struct cconfig *config, const char *key, int32_t value, const char *desc) { - char* str; + char *str; size_t str_len; log_assert(config); @@ -143,10 +154,10 @@ void cconfig_util_set_int(struct cconfig* config, const char* key, free(str); } -void cconfig_util_set_float(struct cconfig* config, const char* key, - float value, const char* desc) +void cconfig_util_set_float( + struct cconfig *config, const char *key, float value, const char *desc) { - char* str; + char *str; size_t str_len; log_assert(config); @@ -162,8 +173,8 @@ void cconfig_util_set_float(struct cconfig* config, const char* key, free(str); } -void cconfig_util_set_bool(struct cconfig* config, const char* key, bool value, - const char* desc) +void cconfig_util_set_bool( + struct cconfig *config, const char *key, bool value, const char *desc) { log_assert(config); log_assert(key); @@ -172,8 +183,11 @@ void cconfig_util_set_bool(struct cconfig* config, const char* key, bool value, cconfig_set(config, key, value ? "true" : "false", desc); } -void cconfig_util_set_str(struct cconfig* config, const char* key, - const char* value, const char* desc) +void cconfig_util_set_str( + struct cconfig *config, + const char *key, + const char *value, + const char *desc) { log_assert(config); log_assert(key); @@ -183,10 +197,14 @@ void cconfig_util_set_str(struct cconfig* config, const char* key, cconfig_set(config, key, value, desc); } -void cconfig_util_set_data(struct cconfig* config, const char* key, - const uint8_t* value, size_t len, const char* desc) +void cconfig_util_set_data( + struct cconfig *config, + const char *key, + const uint8_t *value, + size_t len, + const char *desc) { - char* str; + char *str; size_t str_len; log_assert(config); @@ -202,10 +220,13 @@ void cconfig_util_set_data(struct cconfig* config, const char* key, free(str); } -void cconfig_util_log(struct cconfig* config, log_formatter_t log_formatter) +void cconfig_util_log(struct cconfig *config, log_formatter_t log_formatter) { for (uint32_t i = 0; i < config->nentries; i++) { - log_formatter(LOG_MODULE, "%s=%s", config->entries[i].key, + log_formatter( + LOG_MODULE, + "%s=%s", + config->entries[i].key, config->entries[i].value); } } \ No newline at end of file diff --git a/src/main/cconfig/cconfig-util.h b/src/main/cconfig/cconfig-util.h index a8404b5..aa9b500 100644 --- a/src/main/cconfig/cconfig-util.h +++ b/src/main/cconfig/cconfig-util.h @@ -9,36 +9,54 @@ #include "util/log.h" -bool cconfig_util_get_int(struct cconfig* config, const char* key, int32_t* ret, - int32_t default_value); +bool cconfig_util_get_int( + struct cconfig *config, + const char *key, + int32_t *ret, + int32_t default_value); -bool cconfig_util_get_float(struct cconfig* config, const char* key, float* ret, - float default_value); +bool cconfig_util_get_float( + struct cconfig *config, const char *key, float *ret, float default_value); -bool cconfig_util_get_bool(struct cconfig* config, const char* key, bool* ret, - bool default_value); +bool cconfig_util_get_bool( + struct cconfig *config, const char *key, bool *ret, bool default_value); -bool cconfig_util_get_str(struct cconfig* config, const char* key, - char* buffer, size_t len, const char* default_value); +bool cconfig_util_get_str( + struct cconfig *config, + const char *key, + char *buffer, + size_t len, + const char *default_value); -bool cconfig_util_get_data(struct cconfig* config, const char* key, - uint8_t* buffer, size_t len, const uint8_t* default_value); +bool cconfig_util_get_data( + struct cconfig *config, + const char *key, + uint8_t *buffer, + size_t len, + const uint8_t *default_value); -void cconfig_util_set_int(struct cconfig* config, const char* key, - int32_t value, const char* desc); +void cconfig_util_set_int( + struct cconfig *config, const char *key, int32_t value, const char *desc); -void cconfig_util_set_float(struct cconfig* config, const char* key, - float value, const char* desc); +void cconfig_util_set_float( + struct cconfig *config, const char *key, float value, const char *desc); -void cconfig_util_set_bool(struct cconfig* config, const char* key, bool value, - const char* desc); +void cconfig_util_set_bool( + struct cconfig *config, const char *key, bool value, const char *desc); -void cconfig_util_set_str(struct cconfig* config, const char* key, - const char* value, const char* desc); +void cconfig_util_set_str( + struct cconfig *config, + const char *key, + const char *value, + const char *desc); -void cconfig_util_set_data(struct cconfig* config, const char* key, - const uint8_t* value, size_t len, const char* desc); +void cconfig_util_set_data( + struct cconfig *config, + const char *key, + const uint8_t *value, + size_t len, + const char *desc); -void cconfig_util_log(struct cconfig* config, log_formatter_t log_formatter); +void cconfig_util_log(struct cconfig *config, log_formatter_t log_formatter); #endif \ No newline at end of file diff --git a/src/main/cconfig/cconfig.c b/src/main/cconfig/cconfig.c index a29f182..1cfcbed 100644 --- a/src/main/cconfig/cconfig.c +++ b/src/main/cconfig/cconfig.c @@ -6,21 +6,23 @@ #include "util/mem.h" #include "util/str.h" -static struct cconfig_entry* cconfig_extend_config(struct cconfig* config) +static struct cconfig_entry *cconfig_extend_config(struct cconfig *config) { config->nentries++; - config->entries = xrealloc(config->entries, - config->nentries * sizeof(struct cconfig_entry)); - memset(&config->entries[config->nentries - 1], 0, + config->entries = xrealloc( + config->entries, config->nentries * sizeof(struct cconfig_entry)); + memset( + &config->entries[config->nentries - 1], + 0, sizeof(struct cconfig_entry)); - + return &config->entries[config->nentries - 1]; } -struct cconfig* cconfig_init() +struct cconfig *cconfig_init() { - struct cconfig* config; + struct cconfig *config; config = xmalloc(sizeof(struct cconfig)); memset(config, 0, sizeof(struct cconfig)); @@ -28,7 +30,7 @@ struct cconfig* cconfig_init() return config; } -struct cconfig_entry* cconfig_get(struct cconfig* config, const char* key) +struct cconfig_entry *cconfig_get(struct cconfig *config, const char *key) { log_assert(config); log_assert(key); @@ -42,10 +44,13 @@ struct cconfig_entry* cconfig_get(struct cconfig* config, const char* key) return NULL; } -void cconfig_set(struct cconfig* config, const char* key, const char* value, - const char* desc) +void cconfig_set( + struct cconfig *config, + const char *key, + const char *value, + const char *desc) { - struct cconfig_entry* entry; + struct cconfig_entry *entry; log_assert(config); log_assert(key); @@ -69,9 +74,9 @@ void cconfig_set(struct cconfig* config, const char* key, const char* value, entry->value = str_dup(value); } -void cconfig_set2(struct cconfig* config, const char* key, const char* value) +void cconfig_set2(struct cconfig *config, const char *key, const char *value) { - struct cconfig_entry* entry; + struct cconfig_entry *entry; log_assert(config); log_assert(key); @@ -89,14 +94,14 @@ void cconfig_set2(struct cconfig* config, const char* key, const char* value) entry->key = str_dup(key); entry->value = str_dup(value); - /* Description optional, but do not wipe previous description if + /* Description optional, but do not wipe previous description if available */ if (!entry->desc) { entry->desc = ""; } } -void cconfig_finit(struct cconfig* config) +void cconfig_finit(struct cconfig *config) { for (uint32_t i = 0; i < config->nentries; i++) { free(config->entries[i].key); diff --git a/src/main/cconfig/cconfig.h b/src/main/cconfig/cconfig.h index 0dfa108..4372deb 100644 --- a/src/main/cconfig/cconfig.h +++ b/src/main/cconfig/cconfig.h @@ -6,26 +6,28 @@ #include struct cconfig_entry { - char* key; - char* value; - char* desc; + char *key; + char *value; + char *desc; }; struct cconfig { uint32_t nentries; - struct cconfig_entry* entries; + struct cconfig_entry *entries; }; -struct cconfig* cconfig_init(); +struct cconfig *cconfig_init(); -struct cconfig_entry* cconfig_get(struct cconfig* config, - const char* key); +struct cconfig_entry *cconfig_get(struct cconfig *config, const char *key); -void cconfig_set(struct cconfig* config, const char* key, const char* value, - const char* desc); +void cconfig_set( + struct cconfig *config, + const char *key, + const char *value, + const char *desc); -void cconfig_set2(struct cconfig* config, const char* key, const char* value); +void cconfig_set2(struct cconfig *config, const char *key, const char *value); -void cconfig_finit(struct cconfig* config); +void cconfig_finit(struct cconfig *config); #endif \ No newline at end of file diff --git a/src/main/cconfig/cmd.c b/src/main/cconfig/cmd.c index 62fbd73..3d4f32f 100644 --- a/src/main/cconfig/cmd.c +++ b/src/main/cconfig/cmd.c @@ -11,8 +11,8 @@ #include "util/log.h" #include "util/str.h" -static void cconfig_cmd_usage_print(enum cconfig_cmd_usage_out output, - const char* fmt, ...) +static void +cconfig_cmd_usage_print(enum cconfig_cmd_usage_out output, const char *fmt, ...) { char buffer[32768]; va_list ap; @@ -46,15 +46,19 @@ static void cconfig_cmd_usage_print(enum cconfig_cmd_usage_out output, va_end(ap); } -bool cconfig_cmd_parse(struct cconfig* config, const char* key_ident, int argc, - char** argv, bool add_params_if_absent) +bool cconfig_cmd_parse( + struct cconfig *config, + const char *key_ident, + int argc, + char **argv, + bool add_params_if_absent) { bool no_error; - struct cconfig_entry* entry; - char* tmp; - char* cur_tok; + struct cconfig_entry *entry; + char *tmp; + char *cur_tok; int ntok; - char* toks[2]; + char *toks[2]; no_error = true; @@ -105,8 +109,10 @@ bool cconfig_cmd_parse(struct cconfig* config, const char* key_ident, int argc, cconfig_set2(config, toks[0], toks[1]); } else { /* Ignore cmd params that are not found in config */ - log_warning("Could not find cmd parameter with key '%s' in " - "config, ignored", toks[0]); + log_warning( + "Could not find cmd parameter with key '%s' in " + "config, ignored", + toks[0]); } free(tmp); @@ -116,13 +122,16 @@ bool cconfig_cmd_parse(struct cconfig* config, const char* key_ident, int argc, return no_error; } -void cconfig_cmd_print_usage(struct cconfig* config, const char* usage_header, - enum cconfig_cmd_usage_out output) +void cconfig_cmd_print_usage( + struct cconfig *config, + const char *usage_header, + enum cconfig_cmd_usage_out output) { cconfig_cmd_usage_print(output, "%s\n", usage_header); for (uint32_t i = 0; i < config->nentries; i++) { - cconfig_cmd_usage_print(output, + cconfig_cmd_usage_print( + output, " %s: %s\n" " default: %s\n", config->entries[i].key, diff --git a/src/main/cconfig/cmd.h b/src/main/cconfig/cmd.h index 299f398..fec39e4 100644 --- a/src/main/cconfig/cmd.h +++ b/src/main/cconfig/cmd.h @@ -12,10 +12,16 @@ enum cconfig_cmd_usage_out { CCONFIG_CMD_USAGE_OUT_LOG, }; -bool cconfig_cmd_parse(struct cconfig* config, const char* key_ident, int argc, - char** argv, bool add_params_if_absent); +bool cconfig_cmd_parse( + struct cconfig *config, + const char *key_ident, + int argc, + char **argv, + bool add_params_if_absent); -void cconfig_cmd_print_usage(struct cconfig* config, const char* usage_header, - enum cconfig_cmd_usage_out output); +void cconfig_cmd_print_usage( + struct cconfig *config, + const char *usage_header, + enum cconfig_cmd_usage_out output); #endif \ No newline at end of file diff --git a/src/main/cconfig/conf.c b/src/main/cconfig/conf.c index 47937c2..d9d8c87 100644 --- a/src/main/cconfig/conf.c +++ b/src/main/cconfig/conf.c @@ -10,17 +10,17 @@ #include "util/log.h" #include "util/str.h" -enum cconfig_conf_error cconfig_conf_load_from_file(struct cconfig* config, - const char* path, bool add_params_if_absent) +enum cconfig_conf_error cconfig_conf_load_from_file( + struct cconfig *config, const char *path, bool add_params_if_absent) { - char* pos_lines; - char* pos_key_val; - char* ctx_lines; - char* ctx_key_val; - char* data; + char *pos_lines; + char *pos_key_val; + char *ctx_lines; + char *ctx_key_val; + char *data; size_t len; - if (!file_load(path, (void**) &data, &len, true)) { + if (!file_load(path, (void **) &data, &len, true)) { /* If file does not exist, create one with default configuration values */ if (path_exists(path)) { @@ -33,11 +33,11 @@ enum cconfig_conf_error cconfig_conf_load_from_file(struct cconfig* config, pos_lines = strtok_r(data, "\n", &ctx_lines); while (pos_lines != NULL) { - char* pos_line_dup; - char* key = NULL; - char* val = NULL; + char *pos_line_dup; + char *key = NULL; + char *val = NULL; int cnt = 0; - struct cconfig_entry* entry; + struct cconfig_entry *entry; /* ignore comments and empty lines */ if (strlen(pos_lines) > 0 && pos_lines[0] != '#') { @@ -47,7 +47,6 @@ enum cconfig_conf_error cconfig_conf_load_from_file(struct cconfig* config, log_misc("Line: %s", pos_lines); while (pos_key_val != NULL) { - if (cnt == 0) { key = pos_key_val; } else if (cnt == 1) { @@ -60,8 +59,10 @@ enum cconfig_conf_error cconfig_conf_load_from_file(struct cconfig* config, /* Key requiured, value can be NULL */ if (cnt != 1 && cnt != 2) { - log_warning("Invalid options line %s in options file %s", - pos_lines, path); + log_warning( + "Invalid options line %s in options file %s", + pos_lines, + path); free(pos_line_dup); free(data); return CCONFIG_CONF_ERROR_PARSING; @@ -80,8 +81,10 @@ enum cconfig_conf_error cconfig_conf_load_from_file(struct cconfig* config, cconfig_set2(config, key, val); } else { /* Ignore cmd params that are not found in config */ - log_warning("Could not find parameter with key '%s' in " - "config, ignored", key); + log_warning( + "Could not find parameter with key '%s' in " + "config, ignored", + key); } free(pos_line_dup); @@ -92,13 +95,13 @@ enum cconfig_conf_error cconfig_conf_load_from_file(struct cconfig* config, free(data); - return CCONFIG_CONF_SUCCESS; + return CCONFIG_CONF_SUCCESS; } -enum cconfig_conf_error cconfig_conf_save_to_file(struct cconfig* config, - const char* path) +enum cconfig_conf_error +cconfig_conf_save_to_file(struct cconfig *config, const char *path) { - FILE* file; + FILE *file; file = fopen(path, "wb+"); @@ -108,7 +111,10 @@ enum cconfig_conf_error cconfig_conf_save_to_file(struct cconfig* config, for (uint32_t i = 0; i < config->nentries; i++) { fprintf(file, "# %s\n", config->entries[i].desc); - fprintf(file, "%s=%s\n\n", config->entries[i].key, + fprintf( + file, + "%s=%s\n\n", + config->entries[i].key, config->entries[i].value); } diff --git a/src/main/cconfig/conf.h b/src/main/cconfig/conf.h index be71365..6fd194c 100644 --- a/src/main/cconfig/conf.h +++ b/src/main/cconfig/conf.h @@ -9,8 +9,8 @@ enum cconfig_conf_error { CCONFIG_CONF_ERROR_PARSING = 3, }; -enum cconfig_conf_error cconfig_conf_load_from_file(struct cconfig* config, - const char* path, bool add_params_if_absent); +enum cconfig_conf_error cconfig_conf_load_from_file( + struct cconfig *config, const char *path, bool add_params_if_absent); -enum cconfig_conf_error cconfig_conf_save_to_file(struct cconfig* config, - const char* path); \ No newline at end of file +enum cconfig_conf_error +cconfig_conf_save_to_file(struct cconfig *config, const char *path); \ No newline at end of file diff --git a/src/main/config/analogs.c b/src/main/config/analogs.c index b639094..6d83416 100644 --- a/src/main/config/analogs.c +++ b/src/main/config/analogs.c @@ -1,5 +1,5 @@ -#include #include +#include #include #include @@ -18,7 +18,7 @@ #include "util/mem.h" #include "util/str.h" -#define SENSITIVITY_SCALE 4 +#define SENSITIVITY_SCALE 4 struct analogs_ui { struct array children; @@ -32,16 +32,16 @@ struct analog_ui { uint8_t pos; }; -static INT_PTR CALLBACK analogs_ui_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam); +static INT_PTR CALLBACK +analogs_ui_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); static INT_PTR analogs_ui_handle_init(HWND hwnd, const PROPSHEETPAGE *psp); static INT_PTR analogs_ui_handle_activate(HWND hwnd); static INT_PTR analogs_ui_handle_passivate(HWND hwnd); static INT_PTR analogs_ui_handle_tick(HWND hwnd); static INT_PTR analogs_ui_handle_fini(HWND hwnd); -static INT_PTR CALLBACK analog_ui_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam); +static INT_PTR CALLBACK +analog_ui_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); static INT_PTR analog_ui_handle_init(HWND hwnd, struct analog_def *def); static void analog_ui_handle_init_label(HWND hwnd); static void analog_ui_handle_init_dev(HWND hwnd); @@ -54,8 +54,8 @@ static INT_PTR analog_ui_handle_sensitivity_change(HWND hwnd); static INT_PTR analog_ui_handle_tick(HWND hwnd); static INT_PTR analog_ui_handle_fini(HWND hwnd); -HPROPSHEETPAGE analogs_ui_tab_create(HINSTANCE inst, - const struct schema *schema) +HPROPSHEETPAGE +analogs_ui_tab_create(HINSTANCE inst, const struct schema *schema) { PROPSHEETPAGE psp; @@ -70,8 +70,8 @@ HPROPSHEETPAGE analogs_ui_tab_create(HINSTANCE inst, return CreatePropertySheetPage(&psp); } -static INT_PTR CALLBACK analogs_ui_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam) +static INT_PTR CALLBACK +analogs_ui_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { const NMHDR *n; @@ -122,13 +122,17 @@ static INT_PTR analogs_ui_handle_init(HWND hwnd, const PROPSHEETPAGE *psp) ypos = 0; - for (i = 0 ; i < schema->nanalogs ; i++) { - child = CreateDialogParam(inst, MAKEINTRESOURCE(IDD_ANALOG), hwnd, - analog_ui_dlg_proc, (LPARAM) &schema->analogs[i]); + for (i = 0; i < schema->nanalogs; i++) { + child = CreateDialogParam( + inst, + MAKEINTRESOURCE(IDD_ANALOG), + hwnd, + analog_ui_dlg_proc, + (LPARAM) &schema->analogs[i]); GetWindowRect(child, &r); - SetWindowPos(child, HWND_BOTTOM, 0, ypos, 0, 0, - SWP_NOSIZE | SWP_SHOWWINDOW); + SetWindowPos( + child, HWND_BOTTOM, 0, ypos, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); ypos += r.bottom - r.top; @@ -162,7 +166,7 @@ static INT_PTR analogs_ui_handle_tick(HWND hwnd) ui = (struct analogs_ui *) GetWindowLongPtr(hwnd, GWLP_USERDATA); - for (i = 0 ; i < ui->children.nitems ; i++) { + for (i = 0; i < ui->children.nitems; i++) { child = *array_item(HWND, &ui->children, i); SendMessage(child, WM_USER, 0, 0); } @@ -182,8 +186,8 @@ static INT_PTR analogs_ui_handle_fini(HWND hwnd) return TRUE; } -static INT_PTR CALLBACK analog_ui_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam) +static INT_PTR CALLBACK +analog_ui_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { switch (msg) { case WM_INITDIALOG: @@ -280,9 +284,8 @@ static void analog_ui_handle_init_dev(HWND hwnd) ma.hid = NULL; mapper_get_analog_map(ui->def->tag, &ma); - for (hid = hid_mgr_get_first_stub() - ; hid != NULL - ; hid = hid_mgr_get_next_stub(hid)) { + for (hid = hid_mgr_get_first_stub(); hid != NULL; + hid = hid_mgr_get_next_stub(hid)) { if (!analog_ui_match_device(hid)) { continue; } @@ -327,8 +330,11 @@ static void analog_ui_handle_init_sensitivity(HWND hwnd) pos = 256 * SENSITIVITY_SCALE + mapper_get_analog_sensitivity(ui->def->tag); SendMessage(slider, TBM_SETTICFREQ, 256, 0); - SendMessage(slider, TBM_SETRANGE, FALSE, - MAKELPARAM(0, SENSITIVITY_SCALE * 256 * 2)); + SendMessage( + slider, + TBM_SETRANGE, + FALSE, + MAKELPARAM(0, SENSITIVITY_SCALE * 256 * 2)); SendMessage(slider, TBM_SETPOS, TRUE, (LPARAM) pos); EnableWindow(slider, !mapper_is_analog_absolute(ui->def->tag)); @@ -350,7 +356,7 @@ static bool analog_ui_match_device(struct hid_stub *hid) goto content_fail; } - for (i = 0 ; i < ncontrols ; i++) { + for (i = 0; i < ncontrols; i++) { if (controls[i].value_max - controls[i].value_min > 1) { break; } @@ -386,7 +392,7 @@ static void analog_ui_populate_controls(HWND hwnd) InvalidateRect(controls_ctl, NULL, TRUE); - for (index = nitems ; index >= 0 ; index--) { + for (index = nitems; index >= 0; index--) { SendMessage(controls_ctl, CB_DELETESTRING, index, 0); } @@ -411,7 +417,7 @@ static void analog_ui_populate_controls(HWND hwnd) mapper_get_analog_map(ui->def->tag, &ma); - for (i = 0 ; i < ncontrols ; i++) { + for (i = 0; i < ncontrols; i++) { if (controls[i].value_max - controls[i].value_min <= 1) { continue; } @@ -537,4 +543,3 @@ static INT_PTR analog_ui_handle_fini(HWND hwnd) return TRUE; } - diff --git a/src/main/config/bind-adv.c b/src/main/config/bind-adv.c index 539bf77..ecac4a0 100644 --- a/src/main/config/bind-adv.c +++ b/src/main/config/bind-adv.c @@ -26,8 +26,8 @@ struct bind_adv_state { bool was_valid; }; -static INT_PTR CALLBACK bind_adv_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam); +static INT_PTR CALLBACK +bind_adv_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); static INT_PTR bind_adv_handle_init(HWND hwnd, struct bind_adv_state *state); static void bind_adv_handle_init_devs(HWND hwnd); static void bind_adv_handle_init_insert_dev(HWND hwnd, struct hid_stub *hid); @@ -47,8 +47,8 @@ static void bind_adv_select_dev(HWND hwnd, size_t dev_no); static void bind_adv_select_ctl(HWND hwnd, size_t ctl_no); static void bind_adv_set_range(HWND hwnd, int32_t range_min, int32_t range_max); -bool bind_adv(HINSTANCE inst, HWND hwnd, struct mapped_action *ma, - bool was_valid) +bool bind_adv( + HINSTANCE inst, HWND hwnd, struct mapped_action *ma, bool was_valid) { struct bind_adv_state state; INT_PTR ok; @@ -58,8 +58,12 @@ bool bind_adv(HINSTANCE inst, HWND hwnd, struct mapped_action *ma, state.ma = *ma; state.was_valid = was_valid; - ok = DialogBoxParam(inst, MAKEINTRESOURCE(IDD_BIND_ADV), hwnd, - bind_adv_dlg_proc, (LPARAM) &state) != 0; + ok = DialogBoxParam( + inst, + MAKEINTRESOURCE(IDD_BIND_ADV), + hwnd, + bind_adv_dlg_proc, + (LPARAM) &state) != 0; if (ok) { *ma = state.ma; @@ -68,8 +72,8 @@ bool bind_adv(HINSTANCE inst, HWND hwnd, struct mapped_action *ma, return ok != 0; } -static INT_PTR CALLBACK bind_adv_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam) +static INT_PTR CALLBACK +bind_adv_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { switch (msg) { case WM_INITDIALOG: @@ -148,14 +152,13 @@ static INT_PTR bind_adv_handle_init(HWND hwnd, struct bind_adv_state *state) return TRUE; } - for (i = 0 ; i < state->devs.nitems ; i++) { + for (i = 0; i < state->devs.nitems; i++) { hid = *array_item(struct hid_stub *, &state->devs, i); if (hid == state->ma.hid) { bind_adv_select_dev(hwnd, (int) i); bind_adv_select_ctl(hwnd, state->ma.control_no); - bind_adv_set_range(hwnd, state->ma.value_min, - state->ma.value_max); + bind_adv_set_range(hwnd, state->ma.value_min, state->ma.value_max); } } @@ -168,9 +171,8 @@ static void bind_adv_handle_init_devs(HWND hwnd) hid_mgr_lock(); - for (hid = hid_mgr_get_first_stub() - ; hid != NULL - ; hid = hid_mgr_get_next_stub(hid)) { + for (hid = hid_mgr_get_first_stub(); hid != NULL; + hid = hid_mgr_get_next_stub(hid)) { bind_adv_handle_init_insert_dev(hwnd, hid); } @@ -204,8 +206,7 @@ static void bind_adv_handle_init_insert_dev(HWND hwnd, struct hid_stub *hid) name_fail: free(name); -size_fail: - ; +size_fail:; } static INT_PTR bind_adv_handle_change_ctl(HWND hwnd) @@ -366,8 +367,8 @@ static bool bind_adv_get_range(HWND hwnd, int32_t *out_min, int32_t *out_max) wnd_min = GetDlgItem(hwnd, IDC_BINDING_MIN); wnd_max = GetDlgItem(hwnd, IDC_BINDING_MAX); - return bind_adv_get_int(wnd_min, out_min) - && bind_adv_get_int(wnd_max, out_max); + return bind_adv_get_int(wnd_min, out_min) && + bind_adv_get_int(wnd_max, out_max); } static bool bind_adv_get_int(HWND control, int32_t *out) @@ -452,7 +453,7 @@ static void bind_adv_select_dev(HWND hwnd, size_t dev_no) goto data_fail; } - for (i = 0 ; i < state->nctls ; i++) { + for (i = 0; i < state->nctls; i++) { wchars[0] = L'\0'; usages_get(chars, lengthof(chars), state->ctls[i].usage); @@ -527,4 +528,3 @@ static void bind_adv_set_range(HWND hwnd, int32_t range_min, int32_t range_max) bind_adv_validate(hwnd); } - diff --git a/src/main/config/bind-adv.h b/src/main/config/bind-adv.h index 5d00723..4ae0e5e 100644 --- a/src/main/config/bind-adv.h +++ b/src/main/config/bind-adv.h @@ -9,7 +9,7 @@ #include "geninput/input-config.h" -bool bind_adv(HINSTANCE inst, HWND hwnd, struct mapped_action *ma, - bool was_valid); +bool bind_adv( + HINSTANCE inst, HWND hwnd, struct mapped_action *ma, bool was_valid); #endif diff --git a/src/main/config/bind-light.c b/src/main/config/bind-light.c index aab9999..b98c981 100644 --- a/src/main/config/bind-light.c +++ b/src/main/config/bind-light.c @@ -22,14 +22,19 @@ struct bind_light_state { bool *bound; }; -static INT_PTR CALLBACK bind_light_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam); -static INT_PTR bind_light_handle_init(HWND hwnd, - struct bind_light_state *state); +static INT_PTR CALLBACK +bind_light_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); +static INT_PTR +bind_light_handle_init(HWND hwnd, struct bind_light_state *state); static INT_PTR bind_light_handle_ok(HWND hwnd); -bool bind_light(HINSTANCE inst, HWND hwnd, const struct schema *schema, - const struct mapped_light *ml, uint8_t *game_light, bool *bound) +bool bind_light( + HINSTANCE inst, + HWND hwnd, + const struct schema *schema, + const struct mapped_light *ml, + uint8_t *game_light, + bool *bound) { struct bind_light_state state; @@ -38,17 +43,21 @@ bool bind_light(HINSTANCE inst, HWND hwnd, const struct schema *schema, state.game_light = game_light; state.bound = bound; - return DialogBoxParam(inst, MAKEINTRESOURCE(IDD_BIND_LIGHT), hwnd, - bind_light_dlg_proc, (LPARAM) &state) != 0; + return DialogBoxParam( + inst, + MAKEINTRESOURCE(IDD_BIND_LIGHT), + hwnd, + bind_light_dlg_proc, + (LPARAM) &state) != 0; } -static INT_PTR CALLBACK bind_light_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam) +static INT_PTR CALLBACK +bind_light_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { switch (msg) { case WM_INITDIALOG: - return bind_light_handle_init(hwnd, - (struct bind_light_state *) lparam); + return bind_light_handle_init( + hwnd, (struct bind_light_state *) lparam); case WM_COMMAND: switch (LOWORD(wparam)) { @@ -75,8 +84,7 @@ static INT_PTR CALLBACK bind_light_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, return FALSE; } -static INT_PTR bind_light_handle_init(HWND hwnd, - struct bind_light_state *state) +static INT_PTR bind_light_handle_init(HWND hwnd, struct bind_light_state *state) { char chars[256]; wchar_t wchars[256]; @@ -94,13 +102,13 @@ static INT_PTR bind_light_handle_init(HWND hwnd, ComboBox_AddString(game_light_ctl, L""); - for (i = 0 ; i < state->schema->nlights ; i++) { - LoadString(inst, state->schema->lights[i].name_rsrc, - wchars, lengthof(wchars)); + for (i = 0; i < state->schema->nlights; i++) { + LoadString( + inst, state->schema->lights[i].name_rsrc, wchars, lengthof(wchars)); ComboBox_AddString(game_light_ctl, wchars); - if (state->bound - && state->schema->lights[i].bit == *state->game_light) { + if (state->bound && + state->schema->lights[i].bit == *state->game_light) { ComboBox_SetCurSel(game_light_ctl, i + 1); } } @@ -159,4 +167,3 @@ static INT_PTR bind_light_handle_ok(HWND hwnd) return TRUE; } - diff --git a/src/main/config/bind-light.h b/src/main/config/bind-light.h index f96fd01..7060603 100644 --- a/src/main/config/bind-light.h +++ b/src/main/config/bind-light.h @@ -10,7 +10,12 @@ #include "geninput/mapper.h" -bool bind_light(HINSTANCE inst, HWND hwnd, const struct schema *schema, - const struct mapped_light *ml, uint8_t *game_light, bool *bound); +bool bind_light( + HINSTANCE inst, + HWND hwnd, + const struct schema *schema, + const struct mapped_light *ml, + uint8_t *game_light, + bool *bound); #endif diff --git a/src/main/config/bind.c b/src/main/config/bind.c index 255f14d..9b6875a 100644 --- a/src/main/config/bind.c +++ b/src/main/config/bind.c @@ -1,5 +1,5 @@ -#include #include +#include #include "config/bind.h" #include "config/resource.h" @@ -16,15 +16,18 @@ struct bind_state { uintptr_t timer_id; }; -static INT_PTR CALLBACK bind_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam); +static INT_PTR CALLBACK +bind_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); static INT_PTR bind_handle_init(HWND hwnd, struct bind_state *self); static INT_PTR bind_handle_tick(HWND hwnd); static INT_PTR bind_handle_cancel(HWND hwnd); static INT_PTR bind_handle_destroy(HWND hwnd); -bool bind_control(HINSTANCE inst, HWND hwnd, const struct action_def *action, - struct mapped_action *ma) +bool bind_control( + HINSTANCE inst, + HWND hwnd, + const struct action_def *action, + struct mapped_action *ma) { struct bind_state self; bool result; @@ -36,8 +39,12 @@ bool bind_control(HINSTANCE inst, HWND hwnd, const struct action_def *action, snap_init(&self.snaps[1]); snap_init(&self.snaps[0]); - result = DialogBoxParam(inst, MAKEINTRESOURCE(IDD_BIND), hwnd, - bind_dlg_proc, (LPARAM) &self) != 0; + result = DialogBoxParam( + inst, + MAKEINTRESOURCE(IDD_BIND), + hwnd, + bind_dlg_proc, + (LPARAM) &self) != 0; snap_fini(&self.snaps[0]); snap_fini(&self.snaps[1]); @@ -45,8 +52,8 @@ bool bind_control(HINSTANCE inst, HWND hwnd, const struct action_def *action, return result; } -static INT_PTR CALLBACK bind_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam) +static INT_PTR CALLBACK +bind_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { switch (msg) { case WM_INITDIALOG: @@ -99,8 +106,10 @@ static INT_PTR bind_handle_tick(HWND hwnd) snap_fini(&self->snaps[self->cur_snap]); snap_init(&self->snaps[self->cur_snap]); - if (snap_find_edge(&self->snaps[self->cur_snap], - &self->snaps[!self->cur_snap], self->ma)) { + if (snap_find_edge( + &self->snaps[self->cur_snap], + &self->snaps[!self->cur_snap], + self->ma)) { EndDialog(hwnd, 1); } @@ -124,4 +133,3 @@ static INT_PTR bind_handle_destroy(HWND hwnd) return TRUE; } - diff --git a/src/main/config/bind.h b/src/main/config/bind.h index 579adf9..f839eaa 100644 --- a/src/main/config/bind.h +++ b/src/main/config/bind.h @@ -9,7 +9,10 @@ #include "geninput/mapper.h" -bool bind_control(HINSTANCE inst, HWND hwnd, const struct action_def *action, - struct mapped_action *ma); +bool bind_control( + HINSTANCE inst, + HWND hwnd, + const struct action_def *action, + struct mapped_action *ma); #endif diff --git a/src/main/config/buttons.c b/src/main/config/buttons.c index 9ce0b0e..3aec4e3 100644 --- a/src/main/config/buttons.c +++ b/src/main/config/buttons.c @@ -1,13 +1,13 @@ -#include #include #include +#include #include #include #include -#include "config/bind.h" #include "config/bind-adv.h" +#include "config/bind.h" #include "config/resource.h" #include "config/schema.h" #include "config/usages.h" @@ -20,10 +20,10 @@ #include "util/mem.h" #include "util/winres.h" -static INT_PTR CALLBACK buttons_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam); -static bool buttons_get_control_name(const struct mapped_action *ma, - wchar_t *str, size_t nchars); +static INT_PTR CALLBACK +buttons_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); +static bool buttons_get_control_name( + const struct mapped_action *ma, wchar_t *str, size_t nchars); static INT_PTR buttons_handle_init(HWND hwnd, const PROPSHEETPAGE *psp); static INT_PTR buttons_handle_binding_adv(HWND hwnd); static INT_PTR buttons_handle_binding_clear(HWND hwnd); @@ -40,7 +40,8 @@ struct buttons_tab { uint8_t npages; }; -HPROPSHEETPAGE buttons_tab_create(HINSTANCE inst, const struct schema *schema) +HPROPSHEETPAGE +buttons_tab_create(HINSTANCE inst, const struct schema *schema) { PROPSHEETPAGE psp; @@ -55,8 +56,8 @@ HPROPSHEETPAGE buttons_tab_create(HINSTANCE inst, const struct schema *schema) return CreatePropertySheetPage(&psp); } -static INT_PTR CALLBACK buttons_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam) +static INT_PTR CALLBACK +buttons_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { NMHDR *n; @@ -71,8 +72,8 @@ static INT_PTR CALLBACK buttons_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, case IDC_PAGE: switch (n->code) { case UDN_DELTAPOS: - return buttons_handle_switch_page(hwnd, - (NMUPDOWN *) n); + return buttons_handle_switch_page( + hwnd, (NMUPDOWN *) n); default: return FALSE; @@ -101,7 +102,7 @@ static INT_PTR CALLBACK buttons_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, case IDC_BINDING_EDIT: return buttons_handle_binding_edit(hwnd, FALSE); - + case IDC_BINDING_EDIT_MANY: return buttons_handle_binding_edit(hwnd, TRUE); @@ -136,8 +137,8 @@ static INT_PTR buttons_handle_init(HWND hwnd, const PROPSHEETPAGE *psp) inst = (HINSTANCE) GetWindowLongPtr(hwnd, GWLP_HINSTANCE); bindings_ctl = GetDlgItem(hwnd, IDC_BINDINGS); - ListView_SetExtendedListViewStyle(bindings_ctl, - LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); + ListView_SetExtendedListViewStyle( + bindings_ctl, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); LoadString(inst, IDS_COL_ACTION, str, lengthof(str)); @@ -157,11 +158,11 @@ static INT_PTR buttons_handle_init(HWND hwnd, const PROPSHEETPAGE *psp) ListView_InsertColumn(bindings_ctl, 1, &col); - for (i = 0 ; i < self->schema->nactions ; i++) { + for (i = 0; i < self->schema->nactions; i++) { memset(&item, 0, sizeof(item)); - LoadString(inst, self->schema->actions[i].name_rsrc, str, - lengthof(str)); + LoadString( + inst, self->schema->actions[i].name_rsrc, str, lengthof(str)); item.mask = LVIF_TEXT; item.iItem = (int) i; @@ -197,8 +198,8 @@ static void buttons_update_pager(HWND hwnd) self->npages = mapper_get_npages() + 1; - rswprintf(str, lengthof(str), inst, IDS_PAGE, self->page_no + 1, - self->npages); + rswprintf( + str, lengthof(str), inst, IDS_PAGE, self->page_no + 1, self->npages); SetWindowText(GetDlgItem(hwnd, IDC_PAGE_TEXT), str); } @@ -219,7 +220,7 @@ static void buttons_update_bindings(HWND hwnd) /* Clear binding cell text */ - for (i = 0 ; i < self->schema->nactions ; i++) { + for (i = 0; i < self->schema->nactions; i++) { memset(&item, 0, sizeof(item)); item.mask = LVIF_TEXT; @@ -234,9 +235,8 @@ static void buttons_update_bindings(HWND hwnd) hid_mgr_lock(); - for (pos = mapper_iterate_actions() - ; action_iter_is_valid(pos) - ; action_iter_next(pos)) { + for (pos = mapper_iterate_actions(); action_iter_is_valid(pos); + action_iter_next(pos)) { if (action_iter_get_page(pos) != self->page_no) { continue; } @@ -262,8 +262,8 @@ static void buttons_update_bindings(HWND hwnd) hid_mgr_unlock(); } -static bool buttons_get_control_name(const struct mapped_action *ma, - wchar_t *str, size_t nchars) +static bool buttons_get_control_name( + const struct mapped_action *ma, wchar_t *str, size_t nchars) { char chars[128]; struct hid_control *controls; @@ -367,11 +367,11 @@ static INT_PTR buttons_handle_binding_edit(HWND hwnd, BOOL bind_many) return TRUE; } - for(action_no = action_start; - action_no < self->schema->nactions; - action_no++) { + for (action_no = action_start; action_no < self->schema->nactions; + action_no++) { // Make sure the next listview item is visible - ListView_SetItemState (listview, action_no, LVIS_FOCUSED | LVIS_SELECTED, 0x000F); + ListView_SetItemState( + listview, action_no, LVIS_FOCUSED | LVIS_SELECTED, 0x000F); ListView_EnsureVisible(listview, action_no, FALSE); bit = self->schema->actions[action_no].bit; @@ -380,14 +380,18 @@ static INT_PTR buttons_handle_binding_edit(HWND hwnd, BOOL bind_many) mapper_set_action_map((uint8_t) action_no, self->page_no, bit, &ma); buttons_update(hwnd); - log_misc("Bind act %d -> dev %p ctl %u range [%d, %d]", - self->schema->actions[action_no].bit, ma.hid, - (unsigned int) ma.control_no, ma.value_min, ma.value_max); + log_misc( + "Bind act %d -> dev %p ctl %u range [%d, %d]", + self->schema->actions[action_no].bit, + ma.hid, + (unsigned int) ma.control_no, + ma.value_min, + ma.value_max); } else { break; } - if(!bind_many) { + if (!bind_many) { break; } } @@ -423,4 +427,3 @@ static INT_PTR buttons_handle_fini(HWND hwnd) return TRUE; } - diff --git a/src/main/config/eam.c b/src/main/config/eam.c index f134b4c..d1d15d9 100644 --- a/src/main/config/eam.c +++ b/src/main/config/eam.c @@ -1,6 +1,6 @@ -#include #include #include +#include #include #include @@ -47,8 +47,8 @@ struct eam_unit_ui { struct array devs; }; -static INT_PTR CALLBACK eam_ui_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam); +static INT_PTR CALLBACK +eam_ui_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); static INT_PTR eam_ui_handle_init(HWND hwnd, const PROPSHEETPAGE *psp); static INT_PTR eam_ui_handle_activate(HWND hwnd); static INT_PTR eam_ui_handle_passivate(HWND hwnd); @@ -57,10 +57,10 @@ static INT_PTR eam_ui_handle_change_alt_10k(HWND hwnd); static INT_PTR eam_ui_handle_change_autogen(HWND hwnd); static INT_PTR eam_ui_handle_fini(HWND hwnd); -static INT_PTR CALLBACK eam_unit_ui_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam); -static INT_PTR eam_unit_ui_handle_init(HWND hwnd, - const struct eam_unit_def *def); +static INT_PTR CALLBACK +eam_unit_ui_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); +static INT_PTR +eam_unit_ui_handle_init(HWND hwnd, const struct eam_unit_def *def); static void eam_unit_ui_handle_init_devs(HWND hwnd); static void eam_unit_ui_handle_init_path(HWND hwnd); static INT_PTR eam_unit_ui_handle_browse(HWND hwnd); @@ -70,8 +70,11 @@ static INT_PTR eam_unit_ui_handle_fini(HWND hwnd); static const struct eam_io_config_api *eam_io_config_api; -HPROPSHEETPAGE eam_ui_tab_create(HINSTANCE inst, const struct schema *schema, - const struct eam_io_config_api *api) +HPROPSHEETPAGE +eam_ui_tab_create( + HINSTANCE inst, + const struct schema *schema, + const struct eam_io_config_api *api) { PROPSHEETPAGE psp; @@ -88,8 +91,8 @@ HPROPSHEETPAGE eam_ui_tab_create(HINSTANCE inst, const struct schema *schema, return CreatePropertySheetPage(&psp); } -static INT_PTR CALLBACK eam_ui_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam) +static INT_PTR CALLBACK +eam_ui_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { const NMHDR *n; @@ -159,13 +162,17 @@ static INT_PTR eam_ui_handle_init(HWND hwnd, const PROPSHEETPAGE *psp) ypos = 0; - for (i = 0 ; i < schema->nunits ; i++) { - child = CreateDialogParam(inst, MAKEINTRESOURCE(IDD_READER), hwnd, - eam_unit_ui_dlg_proc, (LPARAM) &schema->units[i]); + for (i = 0; i < schema->nunits; i++) { + child = CreateDialogParam( + inst, + MAKEINTRESOURCE(IDD_READER), + hwnd, + eam_unit_ui_dlg_proc, + (LPARAM) &schema->units[i]); GetWindowRect(child, &r); - SetWindowPos(child, HWND_BOTTOM, 0, ypos, 0, 0, - SWP_NOSIZE | SWP_SHOWWINDOW); + SetWindowPos( + child, HWND_BOTTOM, 0, ypos, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW); ypos += r.bottom - r.top; @@ -207,7 +214,7 @@ static INT_PTR eam_ui_handle_tick(HWND hwnd) mapper_update(); - for (i = 0 ; i < ui->children.nitems ; i++) { + for (i = 0; i < ui->children.nitems; i++) { child = *array_item(HWND, &ui->children, i); SendMessage(child, WM_USER, 0, 0); } @@ -253,13 +260,13 @@ static INT_PTR eam_ui_handle_fini(HWND hwnd) return TRUE; } -static INT_PTR CALLBACK eam_unit_ui_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam) +static INT_PTR CALLBACK +eam_unit_ui_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { switch (msg) { case WM_INITDIALOG: - return eam_unit_ui_handle_init(hwnd, - (struct eam_unit_def *) lparam); + return eam_unit_ui_handle_init( + hwnd, (struct eam_unit_def *) lparam); case WM_USER: return eam_unit_ui_handle_tick(hwnd); @@ -296,8 +303,8 @@ static INT_PTR CALLBACK eam_unit_ui_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, } } -static INT_PTR eam_unit_ui_handle_init(HWND hwnd, - const struct eam_unit_def *def) +static INT_PTR +eam_unit_ui_handle_init(HWND hwnd, const struct eam_unit_def *def) { struct eam_unit_ui *ui; wchar_t str[128]; @@ -338,15 +345,14 @@ static void eam_unit_ui_handle_init_devs(HWND hwnd) hid_mgr_lock(); - for (hid = hid_mgr_get_first_stub() - ; hid != NULL - ; hid = hid_mgr_get_next_stub(hid)) { + for (hid = hid_mgr_get_first_stub(); hid != NULL; + hid = hid_mgr_get_next_stub(hid)) { if (!hid_stub_get_device_usage(hid, &dev_usage)) { continue; } - if (dev_usage != KBD_DEVICE_USAGE_KEYBOARD - && dev_usage != KBD_DEVICE_USAGE_KEYPAD) { + if (dev_usage != KBD_DEVICE_USAGE_KEYBOARD && + dev_usage != KBD_DEVICE_USAGE_KEYPAD) { continue; } @@ -486,4 +492,3 @@ static INT_PTR eam_unit_ui_handle_fini(HWND hwnd) return TRUE; } - diff --git a/src/main/config/gametype.c b/src/main/config/gametype.c index 212fdc6..e7e7353 100644 --- a/src/main/config/gametype.c +++ b/src/main/config/gametype.c @@ -9,8 +9,8 @@ #include "util/defs.h" #include "util/log.h" -static INT_PTR CALLBACK game_type_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam); +static INT_PTR CALLBACK +game_type_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); static INT_PTR game_type_handle_init(HWND hwnd); static INT_PTR game_type_handle_ok(HWND hwnd); static INT_PTR game_type_handle_cancel(HWND hwnd); @@ -19,7 +19,7 @@ const struct schema *game_type_from_str(const char *name) { size_t i; - for (i = 0 ; i < nschemas ; i++) { + for (i = 0; i < nschemas; i++) { if (_stricmp(schemas[i].name, name) == 0) { return &schemas[i]; } @@ -30,12 +30,12 @@ const struct schema *game_type_from_str(const char *name) const struct schema *game_type_from_dialog(HINSTANCE inst) { - return (struct schema *) DialogBoxParam(inst, - MAKEINTRESOURCE(IDD_GAME_TYPE), NULL, game_type_dlg_proc, 0); + return (struct schema *) DialogBoxParam( + inst, MAKEINTRESOURCE(IDD_GAME_TYPE), NULL, game_type_dlg_proc, 0); } -static INT_PTR CALLBACK game_type_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam) +static INT_PTR CALLBACK +game_type_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { switch (msg) { case WM_INITDIALOG: @@ -68,7 +68,7 @@ static INT_PTR game_type_handle_init(HWND hwnd) inst = (HINSTANCE) GetWindowLongPtr(hwnd, GWLP_HINSTANCE); ctl = GetDlgItem(hwnd, IDC_GAME_TYPE); - for (i = 0 ; i < nschemas ; i++) { + for (i = 0; i < nschemas; i++) { LoadString(inst, schemas[i].label, text, lengthof(text)); SendMessage(ctl, CB_ADDSTRING, 0, (LPARAM) text); } @@ -99,4 +99,3 @@ static INT_PTR game_type_handle_cancel(HWND hwnd) return TRUE; } - diff --git a/src/main/config/lights.c b/src/main/config/lights.c index c7cb1e9..ef5a0af 100644 --- a/src/main/config/lights.c +++ b/src/main/config/lights.c @@ -1,7 +1,7 @@ -#include -#include #include #include +#include +#include #include #include @@ -32,8 +32,8 @@ struct lights_ui { float pulse_coeff; }; -static INT_PTR CALLBACK lights_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam); +static INT_PTR CALLBACK +lights_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); static INT_PTR lights_handle_init(HWND hwnd, const PROPSHEETPAGE *psp); static void lights_handle_init_devices(HWND hwnd); static void lights_handle_init_device(HWND hwnd, struct hid_stub *hid); @@ -47,7 +47,8 @@ static void lights_pulse_start(HWND hwnd, size_t light_no); static void lights_pulse_stop(HWND hwnd); static INT_PTR lights_handle_fini(HWND hwnd); -HPROPSHEETPAGE lights_tab_create(HINSTANCE inst, const struct schema *schema) +HPROPSHEETPAGE +lights_tab_create(HINSTANCE inst, const struct schema *schema) { PROPSHEETPAGE psp; @@ -62,8 +63,8 @@ HPROPSHEETPAGE lights_tab_create(HINSTANCE inst, const struct schema *schema) return CreatePropertySheetPage(&psp); } -static INT_PTR CALLBACK lights_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam) +static INT_PTR CALLBACK +lights_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { NMHDR *n; @@ -91,8 +92,8 @@ static INT_PTR CALLBACK lights_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, case IDC_LIGHT: switch (n->code) { case LVN_ITEMCHANGED: - return lights_handle_highlight_light(hwnd, - (NMLISTVIEW *) n); + return lights_handle_highlight_light( + hwnd, (NMLISTVIEW *) n); case NM_DBLCLK: return lights_handle_bind_light(hwnd); @@ -137,9 +138,8 @@ static void lights_handle_init_devices(HWND hwnd) hid_mgr_lock(); - for (hid = hid_mgr_get_first_stub() - ; hid != NULL - ; hid = hid_mgr_get_next_stub(hid)) { + for (hid = hid_mgr_get_first_stub(); hid != NULL; + hid = hid_mgr_get_next_stub(hid)) { lights_handle_init_device(hwnd, hid); } @@ -194,8 +194,8 @@ static void lights_handle_init_lights(HWND hwnd) inst = (HINSTANCE) GetWindowLongPtr(hwnd, GWLP_HINSTANCE); lights = GetDlgItem(hwnd, IDC_LIGHT); - ListView_SetExtendedListViewStyle(lights, - LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); + ListView_SetExtendedListViewStyle( + lights, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); LoadString(inst, IDS_COL_LIGHT_HID, str, lengthof(str)); @@ -258,15 +258,15 @@ static INT_PTR lights_handle_change_dev(HWND hwnd) goto locked_fail; } - for (i = 0 ; i < ui->nlights ; i++) { - if(ui->lights[i].name[0] != L'\0') { + for (i = 0; i < ui->nlights; i++) { + if (ui->lights[i].name[0] != L'\0') { item.pszText = ui->lights[i].name; } else { wchars[0] = L'\0'; usages_get(chars, lengthof(chars), ui->lights[i].usage); - MultiByteToWideChar(CP_UTF8, 0, chars, lengthof(chars), wchars, - lengthof(wchars)); + MultiByteToWideChar( + CP_UTF8, 0, chars, lengthof(chars), wchars, lengthof(wchars)); item.pszText = wchars; } @@ -379,8 +379,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. */ @@ -408,13 +408,12 @@ static void lights_update_bindings(HWND hwnd) inst = (HINSTANCE) GetWindowLongPtr(hwnd, GWLP_HINSTANCE); lights_ctl = GetDlgItem(hwnd, IDC_LIGHT); - for (i = 0 ; i < ui->nlights ; i++) { + for (i = 0; i < ui->nlights; i++) { ListView_SetItemText(lights_ctl, i, 1, NULL); } - for (pos = mapper_iterate_lights() - ; light_iter_is_valid(pos) - ; light_iter_next(pos)) { + for (pos = mapper_iterate_lights(); light_iter_is_valid(pos); + light_iter_next(pos)) { light_iter_get_mapping(pos, &ml); if (ml.hid != ui->hid) { @@ -430,10 +429,13 @@ static void lights_update_bindings(HWND hwnd) game_light = light_iter_get_game_light(pos); - for (i = 0 ; i < ui->schema->nlights ; i++) { + for (i = 0; i < ui->schema->nlights; i++) { if (ui->schema->lights[i].bit == game_light) { - LoadString(inst, ui->schema->lights[i].name_rsrc, wchars, - lengthof(wchars)); + LoadString( + inst, + ui->schema->lights[i].name_rsrc, + wchars, + lengthof(wchars)); ListView_SetItemText(lights_ctl, ml.light_no, 1, wchars); } } @@ -510,4 +512,3 @@ static INT_PTR lights_handle_fini(HWND hwnd) return TRUE; } - diff --git a/src/main/config/main.c b/src/main/config/main.c index eb91bde..ff4c855 100644 --- a/src/main/config/main.c +++ b/src/main/config/main.c @@ -1,5 +1,5 @@ -#include #include +#include #include #include @@ -21,12 +21,15 @@ #include "util/thread.h" #include "util/winres.h" -HPROPSHEETPAGE analogs_ui_tab_create(HINSTANCE inst, - const struct schema *schema); +HPROPSHEETPAGE +analogs_ui_tab_create(HINSTANCE inst, const struct schema *schema); HPROPSHEETPAGE buttons_tab_create(HINSTANCE inst, const struct schema *schema); HPROPSHEETPAGE lights_tab_create(HINSTANCE inst, const struct schema *schema); -HPROPSHEETPAGE eam_ui_tab_create(HINSTANCE inst, const struct schema *schema, - const struct eam_io_config_api *eam_io_config_api); +HPROPSHEETPAGE +eam_ui_tab_create( + HINSTANCE inst, + const struct schema *schema, + const struct eam_io_config_api *eam_io_config_api); static void my_fatal(const char *module, const char *fmt, ...) { @@ -90,12 +93,12 @@ int main(int argc, char **argv) } } - input_set_loggers(log_impl_misc, log_impl_info, log_impl_warning, - log_impl_fatal); + input_set_loggers( + log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); input_init(crt_thread_create, crt_thread_join, crt_thread_destroy); - eam_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning, - log_impl_fatal); + eam_io_set_loggers( + log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); eam_io_init(crt_thread_create, crt_thread_join, crt_thread_destroy); eam_io_config_api = eam_io_get_config_api(); @@ -104,13 +107,13 @@ int main(int argc, char **argv) max_light = -1; - for (i = 0 ; i < schema->nlights ; i++) { + for (i = 0; i < schema->nlights; i++) { if (max_light < schema->lights[i].bit) { max_light = schema->lights[i].bit; } } - mapper_set_nlights((uint8_t) (max_light + 1)); + mapper_set_nlights((uint8_t)(max_light + 1)); mapper_set_nanalogs((uint8_t) schema->nanalogs); } @@ -155,4 +158,3 @@ int main(int argc, char **argv) return EXIT_SUCCESS; } - diff --git a/src/main/config/resource.h b/src/main/config/resource.h index de69f6d..d131909 100644 --- a/src/main/config/resource.h +++ b/src/main/config/resource.h @@ -2,244 +2,244 @@ #define IDC_STATIC (-1) #endif -#define IDR_USAGES 101 -#define IDD_TAB_BUTTONS 102 -#define IDD_TAB_NETWORK 103 -#define IDD_BIND 104 -#define IDD_READER 105 -#define IDD_GAME_TYPE 107 -#define IDD_ANALOG 109 -#define IDD_TAB_ANALOGS 111 -#define IDD_BIND_ADV 113 -#define IDD_TAB_LIGHTS 115 -#define IDD_BIND_LIGHT 117 -#define IDC_GAME_LIGHT 1000 -#define IDC_KBD_DEVICE 1000 -#define IDC_AUTOGEN 1001 -#define IDC_CARD_PATH 1001 -#define IDC_LIGHT 1001 -#define IDC_SENSITIVITY 1001 -#define IDC_ACTION_NAME 1002 -#define IDC_ALT_10K 1002 -#define IDC_KEYPAD_STATE 1002 -#define IDC_GAME_TYPE 1003 -#define IDC_GROUP 1003 -#define IDC_LIMIT_MIN 1003 -#define IDC_BROWSE 1004 -#define IDC_BINDINGS 1005 -#define IDC_DEVICE 1005 -#define IDC_BINDING_EDIT 1006 -#define IDC_CONTROL 1006 -#define IDC_BINDING_CLEAR 1007 -#define IDC_BINDING_MIN 1008 -#define IDC_PAGE_TEXT 1008 -#define IDC_POSITION 1008 -#define IDC_PAGE 1009 -#define IDC_BINDING_MAX 1010 -#define IDC_LIMIT_MAX 1011 -#define IDC_CURRENT 1013 -#define IDC_BINDING_EDIT_MANY 40000 -#define IDS_APPNAME 40000 -#define IDS_BAD_GAME_TYPE 40001 -#define IDS_PAGE 40002 -#define IDS_COL_BUTTON 40003 -#define IDS_COL_ACTION 40004 -#define IDS_NOT_PRESENT 40005 -#define IDS_READER_P1 40006 -#define IDS_READER_P2 40007 -#define IDS_MUXED_TITLE 40008 -#define IDS_MUXED_MSG 40009 -#define IDS_COL_LIGHT_HID 40010 -#define IDS_COL_LIGHT_GAME 40011 -#define IDS_GENERIC_TEST 40012 -#define IDS_GENERIC_SERVICE 40013 -#define IDS_IIDX_SCHEMA 40014 -#define IDS_IIDX_P1_1 40015 -#define IDS_IIDX_P1_2 40016 -#define IDS_IIDX_P1_3 40017 -#define IDS_IIDX_P1_4 40018 -#define IDS_IIDX_P1_5 40019 -#define IDS_IIDX_P1_6 40020 -#define IDS_IIDX_P1_7 40021 -#define IDS_IIDX_P2_1 40022 -#define IDS_IIDX_P2_2 40023 -#define IDS_IIDX_P2_3 40024 -#define IDS_IIDX_P2_4 40025 -#define IDS_IIDX_P2_5 40026 -#define IDS_IIDX_P2_6 40027 -#define IDS_IIDX_P2_7 40028 -#define IDS_IIDX_P1_START 40029 -#define IDS_IIDX_P2_START 40030 -#define IDS_IIDX_VEFX 40031 -#define IDS_IIDX_EFFECT 40032 -#define IDS_IIDX_P1_TT_UP 40033 -#define IDS_IIDX_P1_TT_DOWN 40034 -#define IDS_IIDX_P1_TT_STAB 40035 -#define IDS_IIDX_P2_TT_UP 40036 -#define IDS_IIDX_P2_TT_DOWN 40037 -#define IDS_IIDX_P2_TT_STAB 40038 -#define IDS_IIDX_P1_TT 40039 -#define IDS_IIDX_P2_TT 40040 -#define IDS_IIDX_SPOT_1_LIGHT 40041 -#define IDS_IIDX_SPOT_2_LIGHT 40042 -#define IDS_IIDX_SPOT_3_LIGHT 40043 -#define IDS_IIDX_SPOT_4_LIGHT 40044 -#define IDS_IIDX_SPOT_5_LIGHT 40045 -#define IDS_IIDX_SPOT_6_LIGHT 40046 -#define IDS_IIDX_SPOT_7_LIGHT 40047 -#define IDS_IIDX_SPOT_8_LIGHT 40048 -#define IDS_IIDX_NEON_LIGHT 40049 -#define IDS_DDR_SCHEMA 40050 -#define IDS_DDR_P1_START 40051 -#define IDS_DDR_P1_MENU_UP 40052 -#define IDS_DDR_P1_MENU_DOWN 40053 -#define IDS_DDR_P1_MENU_LEFT 40054 -#define IDS_DDR_P1_MENU_RIGHT 40055 -#define IDS_DDR_P1_UP 40056 -#define IDS_DDR_P1_DOWN 40057 -#define IDS_DDR_P1_LEFT 40058 -#define IDS_DDR_P1_RIGHT 40059 -#define IDS_DDR_P2_START 40060 -#define IDS_DDR_P2_MENU_UP 40061 -#define IDS_DDR_P2_MENU_DOWN 40062 -#define IDS_DDR_P2_MENU_LEFT 40063 -#define IDS_DDR_P2_MENU_RIGHT 40064 -#define IDS_DDR_P2_UP 40065 -#define IDS_DDR_P2_DOWN 40066 -#define IDS_DDR_P2_LEFT 40067 -#define IDS_DDR_P2_RIGHT 40068 -#define IDS_DDR_P1_MENU_LIGHT 40069 -#define IDS_DDR_P1_TOP_LIGHT 40070 -#define IDS_DDR_P1_BOTTOM_LIGHT 40071 -#define IDS_DDR_P2_MENU_LIGHT 40072 -#define IDS_DDR_P2_TOP_LIGHT 40073 -#define IDS_DDR_P2_BOTTOM_LIGHT 40074 -#define IDS_DDR_BASS_LIGHT 40075 -#define IDS_PNM_SCHEMA 40076 -#define IDS_PNM_BTN1 40077 -#define IDS_PNM_BTN2 40078 -#define IDS_PNM_BTN3 40079 -#define IDS_PNM_BTN4 40080 -#define IDS_PNM_BTN5 40081 -#define IDS_PNM_BTN6 40082 -#define IDS_PNM_BTN7 40083 -#define IDS_PNM_BTN8 40084 -#define IDS_PNM_BTN9 40085 -#define IDS_JB_SCHEMA 40086 -#define IDS_JB_PANEL1 40087 -#define IDS_JB_PANEL2 40088 -#define IDS_JB_PANEL3 40089 -#define IDS_JB_PANEL4 40090 -#define IDS_JB_PANEL5 40091 -#define IDS_JB_PANEL6 40092 -#define IDS_JB_PANEL7 40093 -#define IDS_JB_PANEL8 40094 -#define IDC_BINDING_ADV 40095 -#define IDS_JB_PANEL9 40095 -#define IDS_JB_PANEL10 40096 -#define IDS_JB_PANEL11 40097 -#define IDS_JB_PANEL12 40098 -#define IDS_JB_PANEL13 40099 -#define IDS_JB_PANEL14 40100 -#define IDS_JB_PANEL15 40101 -#define IDS_JB_PANEL16 40102 -#define IDS_SDVX_SCHEMA 40103 -#define IDS_SDVX_START 40104 -#define IDS_SDVX_BTN_A 40105 -#define IDS_SDVX_BTN_B 40106 -#define IDS_SDVX_BTN_C 40107 -#define IDS_SDVX_BTN_D 40108 -#define IDS_SDVX_FX_L 40109 -#define IDS_SDVX_FX_R 40110 -#define IDS_SDVX_VOL_L 40111 -#define IDS_SDVX_VOL_R 40112 -#define IDS_DM_SCHEMA 40113 -#define IDS_DM_START 40114 -#define IDS_DM_MENU_LEFT 40115 -#define IDS_DM_MENU_RIGHT 40116 -#define IDS_DM_HI_HAT 40117 -#define IDS_DM_SNARE 40118 -#define IDS_DM_HIGH_TOM 40119 -#define IDS_DM_LOW_TOM 40120 -#define IDS_DM_CYMBAL 40121 -#define IDS_DM_BASS 40122 -#define IDS_DM_SPEAKER_LIGHT 40123 -#define IDS_DM_SPOT_LIGHT 40124 -#define IDS_DM_START_LIGHT 40125 -#define IDS_DM_MENU_LIGHT 40126 -#define IDS_GF_SCHEMA 40127 -#define IDS_GF_P1_START 40128 -#define IDS_GF_P1_PICK 40129 -#define IDS_GF_P1_PICK_A 40130 -#define IDS_GF_P1_PICK_B 40131 -#define IDS_GF_P1_WAIL 40132 -#define IDS_GF_P1_EFFECT 40133 -#define IDS_GF_P1_RED 40134 -#define IDS_GF_P1_GREEN 40135 -#define IDS_GF_P1_BLUE 40136 -#define IDS_GF_P2_START 40137 -#define IDS_GF_P2_PICK 40138 -#define IDS_GF_P2_PICK_A 40139 -#define IDS_GF_P2_PICK_B 40140 -#define IDS_GF_P2_WAIL 40141 -#define IDS_GF_P2_EFFECT 40142 -#define IDS_GF_P2_RED 40143 -#define IDS_GF_P2_GREEN 40144 -#define IDS_GF_P2_BLUE 40145 -#define IDS_GF_P1_SPOT_LIGHT 40146 -#define IDS_GF_P2_SPOT_LIGHT 40147 -#define IDS_RB_SCHEMA 40148 -#define IDS_SDVX_RGB1_R 40149 -#define IDS_SDVX_RGB1_G 40150 -#define IDS_SDVX_RGB1_B 40151 -#define IDS_SDVX_RGB2_R 40152 -#define IDS_SDVX_RGB2_G 40153 -#define IDS_SDVX_RGB2_B 40154 -#define IDS_SDVX_RGB3_R 40155 -#define IDS_SDVX_RGB3_G 40156 -#define IDS_SDVX_RGB3_B 40157 -#define IDS_SDVX_RGB4_R 40158 -#define IDS_SDVX_RGB4_G 40159 -#define IDS_SDVX_RGB4_B 40160 -#define IDS_SDVX_RGB5_R 40161 -#define IDS_SDVX_RGB5_G 40162 -#define IDS_SDVX_RGB5_B 40163 -#define IDS_SDVX_RGB6_R 40164 -#define IDS_SDVX_RGB6_G 40165 -#define IDS_SDVX_RGB6_B 40166 -#define IDS_JU5_SCHEMA 40167 -#define IDS_JB_RGB_FRONT_R 40168 -#define IDS_JB_RGB_FRONT_G 40169 -#define IDS_JB_RGB_FRONT_B 40170 -#define IDS_JB_RGB_TOP_R 40171 -#define IDS_JB_RGB_TOP_G 40172 -#define IDS_JB_RGB_TOP_B 40173 -#define IDS_JB_RGB_LEFT_R 40174 -#define IDS_JB_RGB_LEFT_G 40175 -#define IDS_JB_RGB_LEFT_B 40176 -#define IDS_JB_RGB_RIGHT_R 40177 -#define IDS_JB_RGB_RIGHT_G 40178 -#define IDS_JB_RGB_RIGHT_B 40179 -#define IDS_JB_RGB_TITLE_R 40180 -#define IDS_JB_RGB_TITLE_G 40181 -#define IDS_JB_RGB_TITLE_B 40182 -#define IDS_JB_RGB_WOOFER_R 40183 -#define IDS_JB_RGB_WOOFER_G 40184 -#define IDS_JB_RGB_WOOFER_B 40185 -#define IDS_BST_SCHEMA 40186 -#define IDS_IIDX_PANEL_SCHEMA 40187 -#define IDS_IIDX_PANEL_S1_UP 40188 -#define IDS_IIDX_PANEL_S1_DOWN 40189 -#define IDS_IIDX_PANEL_S2_UP 40190 -#define IDS_IIDX_PANEL_S2_DOWN 40191 -#define IDS_IIDX_PANEL_S3_UP 40192 -#define IDS_IIDX_PANEL_S3_DOWN 40193 -#define IDS_IIDX_PANEL_S4_UP 40194 -#define IDS_IIDX_PANEL_S4_DOWN 40195 -#define IDS_IIDX_PANEL_S5_UP 40196 -#define IDS_IIDX_PANEL_S5_DOWN 40197 -#define IDS_IIDX_PANEL_S1 40198 -#define IDS_IIDX_PANEL_S2 40199 -#define IDS_IIDX_PANEL_S3 40200 -#define IDS_IIDX_PANEL_S4 40201 -#define IDS_IIDX_PANEL_S5 40202 +#define IDR_USAGES 101 +#define IDD_TAB_BUTTONS 102 +#define IDD_TAB_NETWORK 103 +#define IDD_BIND 104 +#define IDD_READER 105 +#define IDD_GAME_TYPE 107 +#define IDD_ANALOG 109 +#define IDD_TAB_ANALOGS 111 +#define IDD_BIND_ADV 113 +#define IDD_TAB_LIGHTS 115 +#define IDD_BIND_LIGHT 117 +#define IDC_GAME_LIGHT 1000 +#define IDC_KBD_DEVICE 1000 +#define IDC_AUTOGEN 1001 +#define IDC_CARD_PATH 1001 +#define IDC_LIGHT 1001 +#define IDC_SENSITIVITY 1001 +#define IDC_ACTION_NAME 1002 +#define IDC_ALT_10K 1002 +#define IDC_KEYPAD_STATE 1002 +#define IDC_GAME_TYPE 1003 +#define IDC_GROUP 1003 +#define IDC_LIMIT_MIN 1003 +#define IDC_BROWSE 1004 +#define IDC_BINDINGS 1005 +#define IDC_DEVICE 1005 +#define IDC_BINDING_EDIT 1006 +#define IDC_CONTROL 1006 +#define IDC_BINDING_CLEAR 1007 +#define IDC_BINDING_MIN 1008 +#define IDC_PAGE_TEXT 1008 +#define IDC_POSITION 1008 +#define IDC_PAGE 1009 +#define IDC_BINDING_MAX 1010 +#define IDC_LIMIT_MAX 1011 +#define IDC_CURRENT 1013 +#define IDC_BINDING_EDIT_MANY 40000 +#define IDS_APPNAME 40000 +#define IDS_BAD_GAME_TYPE 40001 +#define IDS_PAGE 40002 +#define IDS_COL_BUTTON 40003 +#define IDS_COL_ACTION 40004 +#define IDS_NOT_PRESENT 40005 +#define IDS_READER_P1 40006 +#define IDS_READER_P2 40007 +#define IDS_MUXED_TITLE 40008 +#define IDS_MUXED_MSG 40009 +#define IDS_COL_LIGHT_HID 40010 +#define IDS_COL_LIGHT_GAME 40011 +#define IDS_GENERIC_TEST 40012 +#define IDS_GENERIC_SERVICE 40013 +#define IDS_IIDX_SCHEMA 40014 +#define IDS_IIDX_P1_1 40015 +#define IDS_IIDX_P1_2 40016 +#define IDS_IIDX_P1_3 40017 +#define IDS_IIDX_P1_4 40018 +#define IDS_IIDX_P1_5 40019 +#define IDS_IIDX_P1_6 40020 +#define IDS_IIDX_P1_7 40021 +#define IDS_IIDX_P2_1 40022 +#define IDS_IIDX_P2_2 40023 +#define IDS_IIDX_P2_3 40024 +#define IDS_IIDX_P2_4 40025 +#define IDS_IIDX_P2_5 40026 +#define IDS_IIDX_P2_6 40027 +#define IDS_IIDX_P2_7 40028 +#define IDS_IIDX_P1_START 40029 +#define IDS_IIDX_P2_START 40030 +#define IDS_IIDX_VEFX 40031 +#define IDS_IIDX_EFFECT 40032 +#define IDS_IIDX_P1_TT_UP 40033 +#define IDS_IIDX_P1_TT_DOWN 40034 +#define IDS_IIDX_P1_TT_STAB 40035 +#define IDS_IIDX_P2_TT_UP 40036 +#define IDS_IIDX_P2_TT_DOWN 40037 +#define IDS_IIDX_P2_TT_STAB 40038 +#define IDS_IIDX_P1_TT 40039 +#define IDS_IIDX_P2_TT 40040 +#define IDS_IIDX_SPOT_1_LIGHT 40041 +#define IDS_IIDX_SPOT_2_LIGHT 40042 +#define IDS_IIDX_SPOT_3_LIGHT 40043 +#define IDS_IIDX_SPOT_4_LIGHT 40044 +#define IDS_IIDX_SPOT_5_LIGHT 40045 +#define IDS_IIDX_SPOT_6_LIGHT 40046 +#define IDS_IIDX_SPOT_7_LIGHT 40047 +#define IDS_IIDX_SPOT_8_LIGHT 40048 +#define IDS_IIDX_NEON_LIGHT 40049 +#define IDS_DDR_SCHEMA 40050 +#define IDS_DDR_P1_START 40051 +#define IDS_DDR_P1_MENU_UP 40052 +#define IDS_DDR_P1_MENU_DOWN 40053 +#define IDS_DDR_P1_MENU_LEFT 40054 +#define IDS_DDR_P1_MENU_RIGHT 40055 +#define IDS_DDR_P1_UP 40056 +#define IDS_DDR_P1_DOWN 40057 +#define IDS_DDR_P1_LEFT 40058 +#define IDS_DDR_P1_RIGHT 40059 +#define IDS_DDR_P2_START 40060 +#define IDS_DDR_P2_MENU_UP 40061 +#define IDS_DDR_P2_MENU_DOWN 40062 +#define IDS_DDR_P2_MENU_LEFT 40063 +#define IDS_DDR_P2_MENU_RIGHT 40064 +#define IDS_DDR_P2_UP 40065 +#define IDS_DDR_P2_DOWN 40066 +#define IDS_DDR_P2_LEFT 40067 +#define IDS_DDR_P2_RIGHT 40068 +#define IDS_DDR_P1_MENU_LIGHT 40069 +#define IDS_DDR_P1_TOP_LIGHT 40070 +#define IDS_DDR_P1_BOTTOM_LIGHT 40071 +#define IDS_DDR_P2_MENU_LIGHT 40072 +#define IDS_DDR_P2_TOP_LIGHT 40073 +#define IDS_DDR_P2_BOTTOM_LIGHT 40074 +#define IDS_DDR_BASS_LIGHT 40075 +#define IDS_PNM_SCHEMA 40076 +#define IDS_PNM_BTN1 40077 +#define IDS_PNM_BTN2 40078 +#define IDS_PNM_BTN3 40079 +#define IDS_PNM_BTN4 40080 +#define IDS_PNM_BTN5 40081 +#define IDS_PNM_BTN6 40082 +#define IDS_PNM_BTN7 40083 +#define IDS_PNM_BTN8 40084 +#define IDS_PNM_BTN9 40085 +#define IDS_JB_SCHEMA 40086 +#define IDS_JB_PANEL1 40087 +#define IDS_JB_PANEL2 40088 +#define IDS_JB_PANEL3 40089 +#define IDS_JB_PANEL4 40090 +#define IDS_JB_PANEL5 40091 +#define IDS_JB_PANEL6 40092 +#define IDS_JB_PANEL7 40093 +#define IDS_JB_PANEL8 40094 +#define IDC_BINDING_ADV 40095 +#define IDS_JB_PANEL9 40095 +#define IDS_JB_PANEL10 40096 +#define IDS_JB_PANEL11 40097 +#define IDS_JB_PANEL12 40098 +#define IDS_JB_PANEL13 40099 +#define IDS_JB_PANEL14 40100 +#define IDS_JB_PANEL15 40101 +#define IDS_JB_PANEL16 40102 +#define IDS_SDVX_SCHEMA 40103 +#define IDS_SDVX_START 40104 +#define IDS_SDVX_BTN_A 40105 +#define IDS_SDVX_BTN_B 40106 +#define IDS_SDVX_BTN_C 40107 +#define IDS_SDVX_BTN_D 40108 +#define IDS_SDVX_FX_L 40109 +#define IDS_SDVX_FX_R 40110 +#define IDS_SDVX_VOL_L 40111 +#define IDS_SDVX_VOL_R 40112 +#define IDS_DM_SCHEMA 40113 +#define IDS_DM_START 40114 +#define IDS_DM_MENU_LEFT 40115 +#define IDS_DM_MENU_RIGHT 40116 +#define IDS_DM_HI_HAT 40117 +#define IDS_DM_SNARE 40118 +#define IDS_DM_HIGH_TOM 40119 +#define IDS_DM_LOW_TOM 40120 +#define IDS_DM_CYMBAL 40121 +#define IDS_DM_BASS 40122 +#define IDS_DM_SPEAKER_LIGHT 40123 +#define IDS_DM_SPOT_LIGHT 40124 +#define IDS_DM_START_LIGHT 40125 +#define IDS_DM_MENU_LIGHT 40126 +#define IDS_GF_SCHEMA 40127 +#define IDS_GF_P1_START 40128 +#define IDS_GF_P1_PICK 40129 +#define IDS_GF_P1_PICK_A 40130 +#define IDS_GF_P1_PICK_B 40131 +#define IDS_GF_P1_WAIL 40132 +#define IDS_GF_P1_EFFECT 40133 +#define IDS_GF_P1_RED 40134 +#define IDS_GF_P1_GREEN 40135 +#define IDS_GF_P1_BLUE 40136 +#define IDS_GF_P2_START 40137 +#define IDS_GF_P2_PICK 40138 +#define IDS_GF_P2_PICK_A 40139 +#define IDS_GF_P2_PICK_B 40140 +#define IDS_GF_P2_WAIL 40141 +#define IDS_GF_P2_EFFECT 40142 +#define IDS_GF_P2_RED 40143 +#define IDS_GF_P2_GREEN 40144 +#define IDS_GF_P2_BLUE 40145 +#define IDS_GF_P1_SPOT_LIGHT 40146 +#define IDS_GF_P2_SPOT_LIGHT 40147 +#define IDS_RB_SCHEMA 40148 +#define IDS_SDVX_RGB1_R 40149 +#define IDS_SDVX_RGB1_G 40150 +#define IDS_SDVX_RGB1_B 40151 +#define IDS_SDVX_RGB2_R 40152 +#define IDS_SDVX_RGB2_G 40153 +#define IDS_SDVX_RGB2_B 40154 +#define IDS_SDVX_RGB3_R 40155 +#define IDS_SDVX_RGB3_G 40156 +#define IDS_SDVX_RGB3_B 40157 +#define IDS_SDVX_RGB4_R 40158 +#define IDS_SDVX_RGB4_G 40159 +#define IDS_SDVX_RGB4_B 40160 +#define IDS_SDVX_RGB5_R 40161 +#define IDS_SDVX_RGB5_G 40162 +#define IDS_SDVX_RGB5_B 40163 +#define IDS_SDVX_RGB6_R 40164 +#define IDS_SDVX_RGB6_G 40165 +#define IDS_SDVX_RGB6_B 40166 +#define IDS_JU5_SCHEMA 40167 +#define IDS_JB_RGB_FRONT_R 40168 +#define IDS_JB_RGB_FRONT_G 40169 +#define IDS_JB_RGB_FRONT_B 40170 +#define IDS_JB_RGB_TOP_R 40171 +#define IDS_JB_RGB_TOP_G 40172 +#define IDS_JB_RGB_TOP_B 40173 +#define IDS_JB_RGB_LEFT_R 40174 +#define IDS_JB_RGB_LEFT_G 40175 +#define IDS_JB_RGB_LEFT_B 40176 +#define IDS_JB_RGB_RIGHT_R 40177 +#define IDS_JB_RGB_RIGHT_G 40178 +#define IDS_JB_RGB_RIGHT_B 40179 +#define IDS_JB_RGB_TITLE_R 40180 +#define IDS_JB_RGB_TITLE_G 40181 +#define IDS_JB_RGB_TITLE_B 40182 +#define IDS_JB_RGB_WOOFER_R 40183 +#define IDS_JB_RGB_WOOFER_G 40184 +#define IDS_JB_RGB_WOOFER_B 40185 +#define IDS_BST_SCHEMA 40186 +#define IDS_IIDX_PANEL_SCHEMA 40187 +#define IDS_IIDX_PANEL_S1_UP 40188 +#define IDS_IIDX_PANEL_S1_DOWN 40189 +#define IDS_IIDX_PANEL_S2_UP 40190 +#define IDS_IIDX_PANEL_S2_DOWN 40191 +#define IDS_IIDX_PANEL_S3_UP 40192 +#define IDS_IIDX_PANEL_S3_DOWN 40193 +#define IDS_IIDX_PANEL_S4_UP 40194 +#define IDS_IIDX_PANEL_S4_DOWN 40195 +#define IDS_IIDX_PANEL_S5_UP 40196 +#define IDS_IIDX_PANEL_S5_DOWN 40197 +#define IDS_IIDX_PANEL_S1 40198 +#define IDS_IIDX_PANEL_S2 40199 +#define IDS_IIDX_PANEL_S3 40200 +#define IDS_IIDX_PANEL_S4 40201 +#define IDS_IIDX_PANEL_S5 40202 diff --git a/src/main/config/schema.c b/src/main/config/schema.c index 2c621a5..53630d0 100644 --- a/src/main/config/schema.c +++ b/src/main/config/schema.c @@ -1,391 +1,347 @@ -#include "config/resource.h" #include "config/schema.h" +#include "config/resource.h" #include "util/defs.h" -static const struct action_def dm_actions[] = { - { 0x01, IDS_GENERIC_TEST }, - { 0x00, IDS_GENERIC_SERVICE }, +static const struct action_def dm_actions[] = {{0x01, IDS_GENERIC_TEST}, + {0x00, IDS_GENERIC_SERVICE}, - { 0x08, IDS_DM_START }, - { 0x0F, IDS_DM_MENU_LEFT }, - { 0x11, IDS_DM_MENU_RIGHT }, + {0x08, IDS_DM_START}, + {0x0F, IDS_DM_MENU_LEFT}, + {0x11, IDS_DM_MENU_RIGHT}, - { 0x0A, IDS_DM_HI_HAT }, - { 0x0C, IDS_DM_SNARE }, - { 0x0E, IDS_DM_HIGH_TOM }, - { 0x10, IDS_DM_LOW_TOM }, - { 0x12, IDS_DM_CYMBAL }, - { 0x16, IDS_DM_BASS } -}; + {0x0A, IDS_DM_HI_HAT}, + {0x0C, IDS_DM_SNARE}, + {0x0E, IDS_DM_HIGH_TOM}, + {0x10, IDS_DM_LOW_TOM}, + {0x12, IDS_DM_CYMBAL}, + {0x16, IDS_DM_BASS}}; -static const struct light_def dm_lights[] = { - { 0x00, IDS_DM_HI_HAT }, - { 0x01, IDS_DM_SNARE }, - { 0x02, IDS_DM_HIGH_TOM }, - { 0x03, IDS_DM_LOW_TOM }, - { 0x04, IDS_DM_CYMBAL }, - { 0x09, IDS_DM_BASS }, - { 0x0A, IDS_DM_SPEAKER_LIGHT }, - { 0x08, IDS_DM_SPOT_LIGHT }, - { 0x06, IDS_DM_START_LIGHT }, - { 0x07, IDS_DM_MENU_LIGHT } -}; +static const struct light_def dm_lights[] = {{0x00, IDS_DM_HI_HAT}, + {0x01, IDS_DM_SNARE}, + {0x02, IDS_DM_HIGH_TOM}, + {0x03, IDS_DM_LOW_TOM}, + {0x04, IDS_DM_CYMBAL}, + {0x09, IDS_DM_BASS}, + {0x0A, IDS_DM_SPEAKER_LIGHT}, + {0x08, IDS_DM_SPOT_LIGHT}, + {0x06, IDS_DM_START_LIGHT}, + {0x07, IDS_DM_MENU_LIGHT}}; static const struct action_def gf_actions[] = { - { 0x01, IDS_GENERIC_TEST }, - { 0x00, IDS_GENERIC_SERVICE }, + {0x01, IDS_GENERIC_TEST}, {0x00, IDS_GENERIC_SERVICE}, - { 0x08, IDS_GF_P1_START }, - { 0x0A, IDS_GF_P1_PICK }, - { 0x18, IDS_GF_P1_PICK_A }, - { 0x19, IDS_GF_P1_PICK_B }, - { 0x1C, IDS_GF_P1_EFFECT }, - { 0x0C, IDS_GF_P1_WAIL }, - { 0x12, IDS_GF_P1_RED }, - { 0x14, IDS_GF_P1_GREEN }, - { 0x16, IDS_GF_P1_BLUE }, + {0x08, IDS_GF_P1_START}, {0x0A, IDS_GF_P1_PICK}, + {0x18, IDS_GF_P1_PICK_A}, {0x19, IDS_GF_P1_PICK_B}, + {0x1C, IDS_GF_P1_EFFECT}, {0x0C, IDS_GF_P1_WAIL}, + {0x12, IDS_GF_P1_RED}, {0x14, IDS_GF_P1_GREEN}, + {0x16, IDS_GF_P1_BLUE}, - { 0x09, IDS_GF_P2_START }, - { 0x0B, IDS_GF_P2_PICK }, - { 0x1A, IDS_GF_P2_PICK_A }, - { 0x1B, IDS_GF_P2_PICK_B }, - { 0x1D, IDS_GF_P2_EFFECT }, - { 0x0D, IDS_GF_P2_WAIL }, - { 0x13, IDS_GF_P2_RED }, - { 0x15, IDS_GF_P2_GREEN }, - { 0x17, IDS_GF_P2_BLUE } -}; + {0x09, IDS_GF_P2_START}, {0x0B, IDS_GF_P2_PICK}, + {0x1A, IDS_GF_P2_PICK_A}, {0x1B, IDS_GF_P2_PICK_B}, + {0x1D, IDS_GF_P2_EFFECT}, {0x0D, IDS_GF_P2_WAIL}, + {0x13, IDS_GF_P2_RED}, {0x15, IDS_GF_P2_GREEN}, + {0x17, IDS_GF_P2_BLUE}}; -static const struct light_def gf_lights[] = { - { 0x08, IDS_GF_P1_SPOT_LIGHT }, - { 0x09, IDS_GF_P2_SPOT_LIGHT }, - { 0x0A, IDS_GF_P1_START }, - { 0x0B, IDS_GF_P2_START } -}; +static const struct light_def gf_lights[] = {{0x08, IDS_GF_P1_SPOT_LIGHT}, + {0x09, IDS_GF_P2_SPOT_LIGHT}, + {0x0A, IDS_GF_P1_START}, + {0x0B, IDS_GF_P2_START}}; static const struct action_def iidx_actions[] = { - { 0x1C, IDS_GENERIC_TEST }, - { 0x1D, IDS_GENERIC_SERVICE }, + {0x1C, IDS_GENERIC_TEST}, {0x1D, IDS_GENERIC_SERVICE}, - { 0x08, IDS_IIDX_P1_1 }, - { 0x09, IDS_IIDX_P1_2 }, - { 0x0A, IDS_IIDX_P1_3 }, - { 0x0B, IDS_IIDX_P1_4 }, - { 0x0C, IDS_IIDX_P1_5 }, - { 0x0D, IDS_IIDX_P1_6 }, - { 0x0E, IDS_IIDX_P1_7 }, + {0x08, IDS_IIDX_P1_1}, {0x09, IDS_IIDX_P1_2}, + {0x0A, IDS_IIDX_P1_3}, {0x0B, IDS_IIDX_P1_4}, + {0x0C, IDS_IIDX_P1_5}, {0x0D, IDS_IIDX_P1_6}, + {0x0E, IDS_IIDX_P1_7}, - { 0x0F, IDS_IIDX_P2_1 }, - { 0x10, IDS_IIDX_P2_2 }, - { 0x11, IDS_IIDX_P2_3 }, - { 0x12, IDS_IIDX_P2_4 }, - { 0x13, IDS_IIDX_P2_5 }, - { 0x14, IDS_IIDX_P2_6 }, - { 0x15, IDS_IIDX_P2_7 }, + {0x0F, IDS_IIDX_P2_1}, {0x10, IDS_IIDX_P2_2}, + {0x11, IDS_IIDX_P2_3}, {0x12, IDS_IIDX_P2_4}, + {0x13, IDS_IIDX_P2_5}, {0x14, IDS_IIDX_P2_6}, + {0x15, IDS_IIDX_P2_7}, - { 0x18, IDS_IIDX_P1_START }, - { 0x19, IDS_IIDX_P2_START }, - { 0x1A, IDS_IIDX_VEFX }, - { 0x1B, IDS_IIDX_EFFECT }, + {0x18, IDS_IIDX_P1_START}, {0x19, IDS_IIDX_P2_START}, + {0x1A, IDS_IIDX_VEFX}, {0x1B, IDS_IIDX_EFFECT}, - { 0x00, IDS_IIDX_P1_TT_UP }, - { 0x01, IDS_IIDX_P1_TT_DOWN }, - { 0x02, IDS_IIDX_P1_TT_STAB }, + {0x00, IDS_IIDX_P1_TT_UP}, {0x01, IDS_IIDX_P1_TT_DOWN}, + {0x02, IDS_IIDX_P1_TT_STAB}, - { 0x03, IDS_IIDX_P2_TT_UP }, - { 0x04, IDS_IIDX_P2_TT_DOWN }, - { 0x05, IDS_IIDX_P2_TT_STAB }, + {0x03, IDS_IIDX_P2_TT_UP}, {0x04, IDS_IIDX_P2_TT_DOWN}, + {0x05, IDS_IIDX_P2_TT_STAB}, - { 0x20, IDS_IIDX_PANEL_S1_UP }, - { 0x21, IDS_IIDX_PANEL_S1_DOWN }, + {0x20, IDS_IIDX_PANEL_S1_UP}, {0x21, IDS_IIDX_PANEL_S1_DOWN}, - { 0x22, IDS_IIDX_PANEL_S2_UP }, - { 0x23, IDS_IIDX_PANEL_S2_DOWN }, + {0x22, IDS_IIDX_PANEL_S2_UP}, {0x23, IDS_IIDX_PANEL_S2_DOWN}, - { 0x24, IDS_IIDX_PANEL_S3_UP }, - { 0x25, IDS_IIDX_PANEL_S3_DOWN }, + {0x24, IDS_IIDX_PANEL_S3_UP}, {0x25, IDS_IIDX_PANEL_S3_DOWN}, - { 0x26, IDS_IIDX_PANEL_S4_UP }, - { 0x27, IDS_IIDX_PANEL_S4_DOWN }, + {0x26, IDS_IIDX_PANEL_S4_UP}, {0x27, IDS_IIDX_PANEL_S4_DOWN}, - { 0x28, IDS_IIDX_PANEL_S5_UP }, - { 0x29, IDS_IIDX_PANEL_S5_DOWN } -}; + {0x28, IDS_IIDX_PANEL_S5_UP}, {0x29, IDS_IIDX_PANEL_S5_DOWN}}; static const struct light_def iidx_lights[] = { - { 0x00, IDS_IIDX_P1_1 }, - { 0x01, IDS_IIDX_P1_2 }, - { 0x02, IDS_IIDX_P1_3 }, - { 0x03, IDS_IIDX_P1_4 }, - { 0x04, IDS_IIDX_P1_5 }, - { 0x05, IDS_IIDX_P1_6 }, - { 0x06, IDS_IIDX_P1_7 }, + {0x00, IDS_IIDX_P1_1}, {0x01, IDS_IIDX_P1_2}, + {0x02, IDS_IIDX_P1_3}, {0x03, IDS_IIDX_P1_4}, + {0x04, IDS_IIDX_P1_5}, {0x05, IDS_IIDX_P1_6}, + {0x06, IDS_IIDX_P1_7}, - { 0x07, IDS_IIDX_P2_1 }, - { 0x08, IDS_IIDX_P2_2 }, - { 0x09, IDS_IIDX_P2_3 }, - { 0x0A, IDS_IIDX_P2_4 }, - { 0x0B, IDS_IIDX_P2_5 }, - { 0x0C, IDS_IIDX_P2_6 }, - { 0x0D, IDS_IIDX_P2_7 }, + {0x07, IDS_IIDX_P2_1}, {0x08, IDS_IIDX_P2_2}, + {0x09, IDS_IIDX_P2_3}, {0x0A, IDS_IIDX_P2_4}, + {0x0B, IDS_IIDX_P2_5}, {0x0C, IDS_IIDX_P2_6}, + {0x0D, IDS_IIDX_P2_7}, - { 0x18, IDS_IIDX_P1_START }, - { 0x19, IDS_IIDX_P2_START }, - { 0x1A, IDS_IIDX_VEFX }, - { 0x1B, IDS_IIDX_EFFECT }, + {0x18, IDS_IIDX_P1_START}, {0x19, IDS_IIDX_P2_START}, + {0x1A, IDS_IIDX_VEFX}, {0x1B, IDS_IIDX_EFFECT}, - { 0x10, IDS_IIDX_SPOT_1_LIGHT }, - { 0x11, IDS_IIDX_SPOT_2_LIGHT }, - { 0x12, IDS_IIDX_SPOT_3_LIGHT }, - { 0x13, IDS_IIDX_SPOT_4_LIGHT }, - { 0x14, IDS_IIDX_SPOT_5_LIGHT }, - { 0x15, IDS_IIDX_SPOT_6_LIGHT }, - { 0x16, IDS_IIDX_SPOT_7_LIGHT }, - { 0x17, IDS_IIDX_SPOT_8_LIGHT }, + {0x10, IDS_IIDX_SPOT_1_LIGHT}, {0x11, IDS_IIDX_SPOT_2_LIGHT}, + {0x12, IDS_IIDX_SPOT_3_LIGHT}, {0x13, IDS_IIDX_SPOT_4_LIGHT}, + {0x14, IDS_IIDX_SPOT_5_LIGHT}, {0x15, IDS_IIDX_SPOT_6_LIGHT}, + {0x16, IDS_IIDX_SPOT_7_LIGHT}, {0x17, IDS_IIDX_SPOT_8_LIGHT}, - { 0x1F, IDS_IIDX_NEON_LIGHT } -}; + {0x1F, IDS_IIDX_NEON_LIGHT}}; -static const struct analog_def iidx_analogs[] = { - { 0, IDS_IIDX_P1_TT }, - { 1, IDS_IIDX_P2_TT } -}; +static const struct analog_def iidx_analogs[] = {{0, IDS_IIDX_P1_TT}, + {1, IDS_IIDX_P2_TT}}; static const struct action_def ddr_actions[] = { - { 0x04, IDS_GENERIC_TEST }, - { 0x06, IDS_GENERIC_SERVICE }, + {0x04, IDS_GENERIC_TEST}, {0x06, IDS_GENERIC_SERVICE}, - { 0x10, IDS_DDR_P1_START }, - { 0x00, IDS_DDR_P1_MENU_UP }, - { 0x01, IDS_DDR_P1_MENU_DOWN }, - { 0x16, IDS_DDR_P1_MENU_LEFT }, - { 0x17, IDS_DDR_P1_MENU_RIGHT }, - { 0x11, IDS_DDR_P1_UP }, - { 0x12, IDS_DDR_P1_DOWN }, - { 0x13, IDS_DDR_P1_LEFT }, - { 0x14, IDS_DDR_P1_RIGHT }, + {0x10, IDS_DDR_P1_START}, {0x00, IDS_DDR_P1_MENU_UP}, + {0x01, IDS_DDR_P1_MENU_DOWN}, {0x16, IDS_DDR_P1_MENU_LEFT}, + {0x17, IDS_DDR_P1_MENU_RIGHT}, {0x11, IDS_DDR_P1_UP}, + {0x12, IDS_DDR_P1_DOWN}, {0x13, IDS_DDR_P1_LEFT}, + {0x14, IDS_DDR_P1_RIGHT}, - { 0x08, IDS_DDR_P2_START }, - { 0x02, IDS_DDR_P2_MENU_UP }, - { 0x03, IDS_DDR_P2_MENU_DOWN }, - { 0x0E, IDS_DDR_P2_MENU_LEFT }, - { 0x0F, IDS_DDR_P2_MENU_RIGHT }, - { 0x09, IDS_DDR_P2_UP }, - { 0x0A, IDS_DDR_P2_DOWN }, - { 0x0B, IDS_DDR_P2_LEFT }, - { 0x0C, IDS_DDR_P2_RIGHT } -}; + {0x08, IDS_DDR_P2_START}, {0x02, IDS_DDR_P2_MENU_UP}, + {0x03, IDS_DDR_P2_MENU_DOWN}, {0x0E, IDS_DDR_P2_MENU_LEFT}, + {0x0F, IDS_DDR_P2_MENU_RIGHT}, {0x09, IDS_DDR_P2_UP}, + {0x0A, IDS_DDR_P2_DOWN}, {0x0B, IDS_DDR_P2_LEFT}, + {0x0C, IDS_DDR_P2_RIGHT}}; static const struct light_def ddr_lights[] = { /* These are split between non-overlapping P3IO and EXTIO state words */ - { 0x00, IDS_DDR_P1_MENU_LIGHT }, - { 0x07, IDS_DDR_P1_TOP_LIGHT }, - { 0x07, IDS_DDR_P1_BOTTOM_LIGHT }, + {0x00, IDS_DDR_P1_MENU_LIGHT}, + {0x07, IDS_DDR_P1_TOP_LIGHT}, + {0x07, IDS_DDR_P1_BOTTOM_LIGHT}, - { 0x1E, IDS_DDR_P1_UP }, - { 0x1D, IDS_DDR_P1_DOWN }, - { 0x1C, IDS_DDR_P1_LEFT }, - { 0x1B, IDS_DDR_P1_RIGHT }, + {0x1E, IDS_DDR_P1_UP}, + {0x1D, IDS_DDR_P1_DOWN}, + {0x1C, IDS_DDR_P1_LEFT}, + {0x1B, IDS_DDR_P1_RIGHT}, - { 0x01, IDS_DDR_P2_MENU_LIGHT }, - { 0x05, IDS_DDR_P2_TOP_LIGHT }, - { 0x04, IDS_DDR_P2_BOTTOM_LIGHT }, + {0x01, IDS_DDR_P2_MENU_LIGHT}, + {0x05, IDS_DDR_P2_TOP_LIGHT}, + {0x04, IDS_DDR_P2_BOTTOM_LIGHT}, - { 0x16, IDS_DDR_P2_UP }, - { 0x15, IDS_DDR_P2_DOWN }, - { 0x14, IDS_DDR_P2_LEFT }, - { 0x13, IDS_DDR_P2_RIGHT }, + {0x16, IDS_DDR_P2_UP}, + {0x15, IDS_DDR_P2_DOWN}, + {0x14, IDS_DDR_P2_LEFT}, + {0x13, IDS_DDR_P2_RIGHT}, - { 0x0E, IDS_DDR_BASS_LIGHT } -}; + {0x0E, IDS_DDR_BASS_LIGHT}}; -static const struct action_def pnm_actions[] = { - { 0x07, IDS_GENERIC_TEST }, - { 0x06, IDS_GENERIC_SERVICE }, +static const struct action_def pnm_actions[] = {{0x07, IDS_GENERIC_TEST}, + {0x06, IDS_GENERIC_SERVICE}, - { 0x08, IDS_PNM_BTN1 }, - { 0x09, IDS_PNM_BTN2 }, - { 0x0A, IDS_PNM_BTN3 }, - { 0x0B, IDS_PNM_BTN4 }, - { 0x0C, IDS_PNM_BTN5 }, - { 0x0D, IDS_PNM_BTN6 }, - { 0x0E, IDS_PNM_BTN7 }, - { 0x0F, IDS_PNM_BTN8 }, - { 0x10, IDS_PNM_BTN9 } -}; + {0x08, IDS_PNM_BTN1}, + {0x09, IDS_PNM_BTN2}, + {0x0A, IDS_PNM_BTN3}, + {0x0B, IDS_PNM_BTN4}, + {0x0C, IDS_PNM_BTN5}, + {0x0D, IDS_PNM_BTN6}, + {0x0E, IDS_PNM_BTN7}, + {0x0F, IDS_PNM_BTN8}, + {0x10, IDS_PNM_BTN9}}; static const struct light_def pnm_lights[] = { - { 0x17, IDS_PNM_BTN1 }, - { 0x18, IDS_PNM_BTN2 }, - { 0x19, IDS_PNM_BTN3 }, - { 0x1A, IDS_PNM_BTN4 }, - { 0x1B, IDS_PNM_BTN5 }, - { 0x1C, IDS_PNM_BTN6 }, - { 0x1D, IDS_PNM_BTN7 }, - { 0x1E, IDS_PNM_BTN8 }, - { 0x1F, IDS_PNM_BTN9 }, + {0x17, IDS_PNM_BTN1}, + {0x18, IDS_PNM_BTN2}, + {0x19, IDS_PNM_BTN3}, + {0x1A, IDS_PNM_BTN4}, + {0x1B, IDS_PNM_BTN5}, + {0x1C, IDS_PNM_BTN6}, + {0x1D, IDS_PNM_BTN7}, + {0x1E, IDS_PNM_BTN8}, + {0x1F, IDS_PNM_BTN9}, }; -static const struct action_def jb_actions[] = { - { 0x10, IDS_GENERIC_TEST }, - { 0x11, IDS_GENERIC_SERVICE }, +static const struct action_def jb_actions[] = {{0x10, IDS_GENERIC_TEST}, + {0x11, IDS_GENERIC_SERVICE}, - { 0x00, IDS_JB_PANEL1 }, - { 0x01, IDS_JB_PANEL2 }, - { 0x02, IDS_JB_PANEL3 }, - { 0x03, IDS_JB_PANEL4 }, - { 0x04, IDS_JB_PANEL5 }, - { 0x05, IDS_JB_PANEL6 }, - { 0x06, IDS_JB_PANEL7 }, - { 0x07, IDS_JB_PANEL8 }, - { 0x08, IDS_JB_PANEL9 }, - { 0x09, IDS_JB_PANEL10 }, - { 0x0A, IDS_JB_PANEL11 }, - { 0x0B, IDS_JB_PANEL12 }, - { 0x0C, IDS_JB_PANEL13 }, - { 0x0D, IDS_JB_PANEL14 }, - { 0x0E, IDS_JB_PANEL15 }, - { 0x0F, IDS_JB_PANEL16 } -}; + {0x00, IDS_JB_PANEL1}, + {0x01, IDS_JB_PANEL2}, + {0x02, IDS_JB_PANEL3}, + {0x03, IDS_JB_PANEL4}, + {0x04, IDS_JB_PANEL5}, + {0x05, IDS_JB_PANEL6}, + {0x06, IDS_JB_PANEL7}, + {0x07, IDS_JB_PANEL8}, + {0x08, IDS_JB_PANEL9}, + {0x09, IDS_JB_PANEL10}, + {0x0A, IDS_JB_PANEL11}, + {0x0B, IDS_JB_PANEL12}, + {0x0C, IDS_JB_PANEL13}, + {0x0D, IDS_JB_PANEL14}, + {0x0E, IDS_JB_PANEL15}, + {0x0F, IDS_JB_PANEL16}}; static const struct light_def jb_lights[] = { - { 0x00, IDS_JB_RGB_FRONT_R }, - { 0x01, IDS_JB_RGB_FRONT_G }, - { 0x02, IDS_JB_RGB_FRONT_B }, - { 0x03, IDS_JB_RGB_TOP_R }, - { 0x04, IDS_JB_RGB_TOP_G }, - { 0x05, IDS_JB_RGB_TOP_B }, - { 0x06, IDS_JB_RGB_LEFT_R }, - { 0x07, IDS_JB_RGB_LEFT_G }, - { 0x08, IDS_JB_RGB_LEFT_B }, - { 0x09, IDS_JB_RGB_RIGHT_R }, - { 0x0A, IDS_JB_RGB_RIGHT_G }, - { 0x0B, IDS_JB_RGB_RIGHT_B }, - { 0x0C, IDS_JB_RGB_TITLE_R }, - { 0x0D, IDS_JB_RGB_TITLE_G }, - { 0x0E, IDS_JB_RGB_TITLE_B }, - { 0x0F, IDS_JB_RGB_WOOFER_R }, - { 0x10, IDS_JB_RGB_WOOFER_G }, - { 0x11, IDS_JB_RGB_WOOFER_B }, + {0x00, IDS_JB_RGB_FRONT_R}, + {0x01, IDS_JB_RGB_FRONT_G}, + {0x02, IDS_JB_RGB_FRONT_B}, + {0x03, IDS_JB_RGB_TOP_R}, + {0x04, IDS_JB_RGB_TOP_G}, + {0x05, IDS_JB_RGB_TOP_B}, + {0x06, IDS_JB_RGB_LEFT_R}, + {0x07, IDS_JB_RGB_LEFT_G}, + {0x08, IDS_JB_RGB_LEFT_B}, + {0x09, IDS_JB_RGB_RIGHT_R}, + {0x0A, IDS_JB_RGB_RIGHT_G}, + {0x0B, IDS_JB_RGB_RIGHT_B}, + {0x0C, IDS_JB_RGB_TITLE_R}, + {0x0D, IDS_JB_RGB_TITLE_G}, + {0x0E, IDS_JB_RGB_TITLE_B}, + {0x0F, IDS_JB_RGB_WOOFER_R}, + {0x10, IDS_JB_RGB_WOOFER_G}, + {0x11, IDS_JB_RGB_WOOFER_B}, }; -static const struct action_def sdvx_actions[] = { - { 0x05, IDS_GENERIC_TEST }, - { 0x04, IDS_GENERIC_SERVICE }, - { 0x0B, IDS_SDVX_START }, - { 0x0A, IDS_SDVX_BTN_A }, - { 0x09, IDS_SDVX_BTN_B }, - { 0x08, IDS_SDVX_BTN_C }, - { 0x15, IDS_SDVX_BTN_D }, - { 0x14, IDS_SDVX_FX_L }, - { 0x13, IDS_SDVX_FX_R } -}; +static const struct action_def sdvx_actions[] = {{0x05, IDS_GENERIC_TEST}, + {0x04, IDS_GENERIC_SERVICE}, + {0x0B, IDS_SDVX_START}, + {0x0A, IDS_SDVX_BTN_A}, + {0x09, IDS_SDVX_BTN_B}, + {0x08, IDS_SDVX_BTN_C}, + {0x15, IDS_SDVX_BTN_D}, + {0x14, IDS_SDVX_FX_L}, + {0x13, IDS_SDVX_FX_R}}; static const struct light_def sdvx_lights[] = { - { 0x0D, IDS_SDVX_BTN_A }, - { 0x0E, IDS_SDVX_BTN_B }, - { 0x0F, IDS_SDVX_BTN_C }, - { 0x00, IDS_SDVX_BTN_D }, - { 0x01, IDS_SDVX_FX_L }, - { 0x02, IDS_SDVX_FX_R }, - { 0x0C, IDS_SDVX_START }, - { 0x10, IDS_SDVX_RGB1_R }, - { 0x11, IDS_SDVX_RGB1_G }, - { 0x12, IDS_SDVX_RGB1_B }, - { 0x13, IDS_SDVX_RGB2_R }, - { 0x14, IDS_SDVX_RGB2_G }, - { 0x15, IDS_SDVX_RGB2_B }, - { 0x16, IDS_SDVX_RGB3_R }, - { 0x17, IDS_SDVX_RGB3_G }, - { 0x18, IDS_SDVX_RGB3_B }, - { 0x19, IDS_SDVX_RGB4_R }, - { 0x1A, IDS_SDVX_RGB4_G }, - { 0x1B, IDS_SDVX_RGB4_B }, - { 0x1C, IDS_SDVX_RGB5_R }, - { 0x1D, IDS_SDVX_RGB5_G }, - { 0x1E, IDS_SDVX_RGB5_B }, - { 0x1F, IDS_SDVX_RGB6_R }, - { 0x20, IDS_SDVX_RGB6_G }, - { 0x21, IDS_SDVX_RGB6_B } -}; + {0x0D, IDS_SDVX_BTN_A}, {0x0E, IDS_SDVX_BTN_B}, {0x0F, IDS_SDVX_BTN_C}, + {0x00, IDS_SDVX_BTN_D}, {0x01, IDS_SDVX_FX_L}, {0x02, IDS_SDVX_FX_R}, + {0x0C, IDS_SDVX_START}, {0x10, IDS_SDVX_RGB1_R}, {0x11, IDS_SDVX_RGB1_G}, + {0x12, IDS_SDVX_RGB1_B}, {0x13, IDS_SDVX_RGB2_R}, {0x14, IDS_SDVX_RGB2_G}, + {0x15, IDS_SDVX_RGB2_B}, {0x16, IDS_SDVX_RGB3_R}, {0x17, IDS_SDVX_RGB3_G}, + {0x18, IDS_SDVX_RGB3_B}, {0x19, IDS_SDVX_RGB4_R}, {0x1A, IDS_SDVX_RGB4_G}, + {0x1B, IDS_SDVX_RGB4_B}, {0x1C, IDS_SDVX_RGB5_R}, {0x1D, IDS_SDVX_RGB5_G}, + {0x1E, IDS_SDVX_RGB5_B}, {0x1F, IDS_SDVX_RGB6_R}, {0x20, IDS_SDVX_RGB6_G}, + {0x21, IDS_SDVX_RGB6_B}}; -static const struct analog_def sdvx_analogs[] = { - { 0, IDS_SDVX_VOL_L }, - { 1, IDS_SDVX_VOL_R } -}; +static const struct analog_def sdvx_analogs[] = {{0, IDS_SDVX_VOL_L}, + {1, IDS_SDVX_VOL_R}}; -static const struct action_def rb_actions[] = { - { 0x00, IDS_GENERIC_TEST }, - { 0x01, IDS_GENERIC_SERVICE } -}; +static const struct action_def rb_actions[] = {{0x00, IDS_GENERIC_TEST}, + {0x01, IDS_GENERIC_SERVICE}}; static const struct action_def bst_actions[] = { - { 0x05, IDS_GENERIC_TEST }, - { 0x04, IDS_GENERIC_SERVICE }, + {0x05, IDS_GENERIC_TEST}, + {0x04, IDS_GENERIC_SERVICE}, }; -static const struct eam_unit_def schema_eam_unit_defs[] = { - { IDS_READER_P1, 0 }, - { IDS_READER_P2, 1 } -}; +static const struct eam_unit_def schema_eam_unit_defs[] = {{IDS_READER_P1, 0}, + {IDS_READER_P2, 1}}; -const struct schema schemas[] = { - { "iidx", IDS_IIDX_SCHEMA, - iidx_actions, lengthof(iidx_actions), - iidx_lights, lengthof(iidx_lights), - iidx_analogs, lengthof(iidx_analogs), - schema_eam_unit_defs, 2 }, +const struct schema schemas[] = { + {"iidx", + IDS_IIDX_SCHEMA, + iidx_actions, + lengthof(iidx_actions), + iidx_lights, + lengthof(iidx_lights), + iidx_analogs, + lengthof(iidx_analogs), + schema_eam_unit_defs, + 2}, - { "pnm", IDS_PNM_SCHEMA, - pnm_actions, lengthof(pnm_actions), - pnm_lights, lengthof(pnm_lights), - NULL, 0, - schema_eam_unit_defs, 1 }, + {"pnm", + IDS_PNM_SCHEMA, + pnm_actions, + lengthof(pnm_actions), + pnm_lights, + lengthof(pnm_lights), + NULL, + 0, + schema_eam_unit_defs, + 1}, - { "gf", IDS_GF_SCHEMA, - gf_actions, lengthof(gf_actions), - gf_lights, lengthof(gf_lights), - NULL, 0, - schema_eam_unit_defs, 2 }, + {"gf", + IDS_GF_SCHEMA, + gf_actions, + lengthof(gf_actions), + gf_lights, + lengthof(gf_lights), + NULL, + 0, + schema_eam_unit_defs, + 2}, - { "dm", IDS_DM_SCHEMA, - dm_actions, lengthof(dm_actions), - dm_lights, lengthof(dm_lights), - NULL, 0, - schema_eam_unit_defs, 1 }, + {"dm", + IDS_DM_SCHEMA, + dm_actions, + lengthof(dm_actions), + dm_lights, + lengthof(dm_lights), + NULL, + 0, + schema_eam_unit_defs, + 1}, - { "ddr", IDS_DDR_SCHEMA, - ddr_actions, lengthof(ddr_actions), - ddr_lights, lengthof(ddr_lights), - NULL, 0, - schema_eam_unit_defs, 2 }, + {"ddr", + IDS_DDR_SCHEMA, + ddr_actions, + lengthof(ddr_actions), + ddr_lights, + lengthof(ddr_lights), + NULL, + 0, + schema_eam_unit_defs, + 2}, - { "jb", IDS_JB_SCHEMA, - jb_actions, lengthof(jb_actions), - jb_lights, lengthof(jb_lights), - NULL, 0, - schema_eam_unit_defs, 1 }, + {"jb", + IDS_JB_SCHEMA, + jb_actions, + lengthof(jb_actions), + jb_lights, + lengthof(jb_lights), + NULL, + 0, + schema_eam_unit_defs, + 1}, - { "sdvx", IDS_SDVX_SCHEMA, - sdvx_actions, lengthof(sdvx_actions), - sdvx_lights, lengthof(sdvx_lights), - sdvx_analogs, lengthof(sdvx_analogs), - schema_eam_unit_defs, 1 }, + {"sdvx", + IDS_SDVX_SCHEMA, + sdvx_actions, + lengthof(sdvx_actions), + sdvx_lights, + lengthof(sdvx_lights), + sdvx_analogs, + lengthof(sdvx_analogs), + schema_eam_unit_defs, + 1}, - { "rb", IDS_RB_SCHEMA, - rb_actions, lengthof(rb_actions), - NULL, 0, - NULL, 0, - schema_eam_unit_defs, 1 }, + {"rb", + IDS_RB_SCHEMA, + rb_actions, + lengthof(rb_actions), + NULL, + 0, + NULL, + 0, + schema_eam_unit_defs, + 1}, - { "bst", IDS_BST_SCHEMA, - bst_actions, lengthof(bst_actions), - NULL, 0, - NULL, 0, - schema_eam_unit_defs, 1 }, + {"bst", + IDS_BST_SCHEMA, + bst_actions, + lengthof(bst_actions), + NULL, + 0, + NULL, + 0, + schema_eam_unit_defs, + 1}, }; const size_t nschemas = lengthof(schemas); - diff --git a/src/main/config/snap.c b/src/main/config/snap.c index b86bf6f..8981c68 100644 --- a/src/main/config/snap.c +++ b/src/main/config/snap.c @@ -12,10 +12,7 @@ #include "util/log.h" #include "util/mem.h" -enum snap_control_heuristic { - CONTROL_CENTERING_AXIS, - CONTROL_MULTISWITCH -}; +enum snap_control_heuristic { CONTROL_CENTERING_AXIS, CONTROL_MULTISWITCH }; struct snap_known_control { uint32_t usage; @@ -24,32 +21,34 @@ struct snap_known_control { static struct snap_known_control snap_known_controls[] = { /* X axis */ - { 0x00010030, CONTROL_CENTERING_AXIS }, + {0x00010030, CONTROL_CENTERING_AXIS}, /* Y axis */ - { 0x00010031, CONTROL_CENTERING_AXIS }, + {0x00010031, CONTROL_CENTERING_AXIS}, /* Z axis */ - { 0x00010032, CONTROL_CENTERING_AXIS }, + {0x00010032, CONTROL_CENTERING_AXIS}, /* X rotation */ - { 0x00010033, CONTROL_CENTERING_AXIS }, + {0x00010033, CONTROL_CENTERING_AXIS}, /* Y rotation */ - { 0x00010034, CONTROL_CENTERING_AXIS }, + {0x00010034, CONTROL_CENTERING_AXIS}, /* Z rotation */ - { 0x00010035, CONTROL_CENTERING_AXIS }, + {0x00010035, CONTROL_CENTERING_AXIS}, /* I don't have an adapter that presents a slider/dial/wheel so I don't know how to deal with those things right now */ /* Hat switch */ - { 0x00010039, CONTROL_MULTISWITCH } -}; + {0x00010039, CONTROL_MULTISWITCH}}; -static bool snap_check_for_edge(const struct hid_control *ctl, int32_t val, - int32_t other_val, struct mapped_action *ma); +static bool snap_check_for_edge( + const struct hid_control *ctl, + int32_t val, + int32_t other_val, + struct mapped_action *ma); void snap_init(struct snap *snap) { @@ -63,10 +62,8 @@ void snap_init(struct snap *snap) ndevs = 0; - for (pos = hid_mgr_get_first_stub() - ; pos != NULL - ; pos = hid_mgr_get_next_stub(pos)) { - + for (pos = hid_mgr_get_first_stub(); pos != NULL; + pos = hid_mgr_get_next_stub(pos)) { ndevs++; } @@ -75,10 +72,8 @@ void snap_init(struct snap *snap) i = 0; - for (pos = hid_mgr_get_first_stub(), i = 0 - ; pos != NULL && i < ndevs - ; pos = hid_mgr_get_next_stub(pos), i++) { - + for (pos = hid_mgr_get_first_stub(), i = 0; pos != NULL && i < ndevs; + pos = hid_mgr_get_next_stub(pos), i++) { if (!hid_stub_is_attached(pos)) { continue; } @@ -89,13 +84,13 @@ void snap_init(struct snap *snap) snap->devs[i].hid = pos; snap->devs[i].ncontrols = ncontrols; - snap->devs[i].controls = xcalloc(ncontrols - * sizeof(struct hid_control)); + snap->devs[i].controls = + xcalloc(ncontrols * sizeof(struct hid_control)); snap->devs[i].states = xcalloc(ncontrols * sizeof(int32_t)); hid_stub_get_controls(pos, snap->devs[i].controls, &ncontrols); - for (j = 0 ; j < ncontrols ; j++) { + for (j = 0; j < ncontrols; j++) { hid_stub_get_value(pos, j, &snap->devs[i].states[j]); } } @@ -103,8 +98,10 @@ void snap_init(struct snap *snap) hid_mgr_unlock(); } -bool snap_find_edge(const struct snap *snap, const struct snap *other_snap, - struct mapped_action *ma) +bool snap_find_edge( + const struct snap *snap, + const struct snap *other_snap, + struct mapped_action *ma) { const struct hid_control *ctl; int32_t val; @@ -125,7 +122,7 @@ bool snap_find_edge(const struct snap *snap, const struct snap *other_snap, return false; } - for (i = 0 ; i < snap->ndevs ; i++) { + for (i = 0; i < snap->ndevs; i++) { if (snap->devs[i].hid != other_snap->devs[i].hid) { return false; } @@ -134,12 +131,14 @@ bool snap_find_edge(const struct snap *snap, const struct snap *other_snap, return false; } - if (memcmp(snap->devs[i].controls, other_snap->devs[i].controls, + if (memcmp( + snap->devs[i].controls, + other_snap->devs[i].controls, snap->devs[i].ncontrols * sizeof(struct hid_control)) != 0) { return false; } - for (j = 0 ; j < snap->devs[i].ncontrols ; j++) { + for (j = 0; j < snap->devs[i].ncontrols; j++) { ctl = &snap->devs[i].controls[j]; val = snap->devs[i].states[j]; other_val = other_snap->devs[i].states[j]; @@ -156,8 +155,11 @@ bool snap_find_edge(const struct snap *snap, const struct snap *other_snap, return false; } -static bool snap_check_for_edge(const struct hid_control *ctl, int32_t val, - int32_t other_val, struct mapped_action *ma) +static bool snap_check_for_edge( + const struct hid_control *ctl, + int32_t val, + int32_t other_val, + struct mapped_action *ma) { size_t i; int32_t range; @@ -179,7 +181,7 @@ static bool snap_check_for_edge(const struct hid_control *ctl, int32_t val, } else { /* Here we kinda have to take things on a case by case basis */ - for (i = 0 ; i < lengthof(snap_known_controls) ; i++) { + for (i = 0; i < lengthof(snap_known_controls); i++) { if (snap_known_controls[i].usage != ctl->usage) { continue; } @@ -213,8 +215,8 @@ static bool snap_check_for_edge(const struct hid_control *ctl, int32_t val, /* Assume positions are discrete. Precisely match any transitioned-to value that isn't a null state. */ - if (val >= ctl->value_min && val <= ctl->value_max - && val != other_val) { + if (val >= ctl->value_min && val <= ctl->value_max && + val != other_val) { ma->value_min = val; ma->value_max = val; @@ -237,11 +239,10 @@ void snap_fini(struct snap *snap) { size_t i; - for (i = 0 ; i < snap->ndevs ; i++) { + for (i = 0; i < snap->ndevs; i++) { free(snap->devs[i].states); free(snap->devs[i].controls); } free(snap->devs); } - diff --git a/src/main/config/snap.h b/src/main/config/snap.h index cb95f12..c5a9ab9 100644 --- a/src/main/config/snap.h +++ b/src/main/config/snap.h @@ -20,8 +20,10 @@ struct snap { }; void snap_init(struct snap *snap); -bool snap_find_edge(const struct snap *snap, const struct snap *other_snap, - struct mapped_action *ma); +bool snap_find_edge( + const struct snap *snap, + const struct snap *other_snap, + struct mapped_action *ma); void snap_fini(struct snap *snap); #endif diff --git a/src/main/config/spinner.c b/src/main/config/spinner.c index 64f1747..a45c988 100644 --- a/src/main/config/spinner.c +++ b/src/main/config/spinner.c @@ -4,15 +4,15 @@ #include #include -#define METRIC_COLOR RGB(0, 0, 0) -#define METRIC_RADIUS_CIRCLE 0.8f -#define METRIC_RADIUS_NOTCH 0.2f -#define METRIC_THICKNESS 3 +#define METRIC_COLOR RGB(0, 0, 0) +#define METRIC_RADIUS_CIRCLE 0.8f +#define METRIC_RADIUS_NOTCH 0.2f +#define METRIC_THICKNESS 3 static const wchar_t spinner_cls[] = L"spinner"; -static LRESULT CALLBACK spinner_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam); +static LRESULT CALLBACK +spinner_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); static LRESULT spinner_handle_paint(HWND hwnd); static LRESULT spinner_handle_update(HWND hwnd, uint8_t pos); @@ -24,14 +24,14 @@ void spinner_init(HINSTANCE inst) wcx.cbSize = sizeof(wcx); wcx.lpfnWndProc = spinner_wnd_proc; wcx.hInstance = inst; - wcx.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); + wcx.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wcx.lpszClassName = spinner_cls; RegisterClassEx(&wcx); } -static LRESULT CALLBACK spinner_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam) +static LRESULT CALLBACK +spinner_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { switch (msg) { case WM_CREATE: @@ -80,22 +80,26 @@ static LRESULT spinner_handle_paint(HWND hwnd) SelectObject(dc, pen); SelectObject(dc, GetStockObject(WHITE_BRUSH)); - Ellipse(dc, - (int) (cx * (1.0f - METRIC_RADIUS_CIRCLE)), - (int) (cy * (1.0f - METRIC_RADIUS_CIRCLE)), - (int) (cx * (1.0f + METRIC_RADIUS_CIRCLE)), - (int) (cy * (1.0f + METRIC_RADIUS_CIRCLE))); + Ellipse( + dc, + (int) (cx * (1.0f - METRIC_RADIUS_CIRCLE)), + (int) (cy * (1.0f - METRIC_RADIUS_CIRCLE)), + (int) (cx * (1.0f + METRIC_RADIUS_CIRCLE)), + (int) (cy * (1.0f + METRIC_RADIUS_CIRCLE))); - dx = sinf(theta); + dx = sinf(theta); dy = -cosf(theta); - MoveToEx(dc, - (int) (cx * (1.0f + dx * METRIC_RADIUS_NOTCH)), - (int) (cy * (1.0f + dy * METRIC_RADIUS_NOTCH)), NULL); + MoveToEx( + dc, + (int) (cx * (1.0f + dx * METRIC_RADIUS_NOTCH)), + (int) (cy * (1.0f + dy * METRIC_RADIUS_NOTCH)), + NULL); - LineTo(dc, - (int) (cx * (1.0f + dx * METRIC_RADIUS_CIRCLE)), - (int) (cy * (1.0f + dy * METRIC_RADIUS_CIRCLE))); + LineTo( + dc, + (int) (cx * (1.0f + dx * METRIC_RADIUS_CIRCLE)), + (int) (cy * (1.0f + dy * METRIC_RADIUS_CIRCLE))); DeleteObject(pen); EndPaint(hwnd, &ps); @@ -115,4 +119,3 @@ void spinner_fini(HINSTANCE inst) { UnregisterClass(spinner_cls, inst); } - diff --git a/src/main/config/usages.c b/src/main/config/usages.c index 1d84057..5e28ad9 100644 --- a/src/main/config/usages.c +++ b/src/main/config/usages.c @@ -50,8 +50,8 @@ void usages_init(HINSTANCE inst) nchars = strlen(line); - if (nchars == 0 || line[0] == '#' - || strspn(line, " \t\r\n") == nchars) { + if (nchars == 0 || line[0] == '#' || + strspn(line, " \t\r\n") == nchars) { continue; } @@ -59,8 +59,9 @@ void usages_init(HINSTANCE inst) if (!isspace(line[0])) { if (!usages_begin_page(line, &tmp_page)) { - log_fatal("IDR_USAGES:%u: Invalid usage page", - (unsigned int) line_no); + log_fatal( + "IDR_USAGES:%u: Invalid usage page", + (unsigned int) line_no); break; } @@ -69,15 +70,16 @@ void usages_init(HINSTANCE inst) memcpy(cur_page, &tmp_page, sizeof(tmp_page)); } else { if (cur_page == NULL) { - log_fatal("IDR_USAGES:%u: Usage before first page", - (unsigned int) line_no); + log_fatal( + "IDR_USAGES:%u: Usage before first page", + (unsigned int) line_no); break; } if (!usages_read_usage(line, cur_page)) { - log_fatal("IDR_USAGES:%u: Invalid usage", - (unsigned int) line_no); + log_fatal( + "IDR_USAGES:%u: Invalid usage", (unsigned int) line_no); break; } @@ -134,16 +136,16 @@ void usages_get(char *chars, size_t nchars, uint32_t usage_id) size_t j; hi = ((usage_id >> 16) & 0xFFFF); - lo = ((usage_id >> 0) & 0xFFFF); + lo = ((usage_id >> 0) & 0xFFFF); - for (i = 0 ; i < usages.nitems ; i++) { + for (i = 0; i < usages.nitems; i++) { page = array_item(struct usage_page, &usages, i); if (page->id != hi) { continue; } - for (j = 0 ; j < page->usages.nitems ; j++) { + for (j = 0; j < page->usages.nitems; j++) { usage = array_item(struct usage, &page->usages, j); if (usage->id == lo) { @@ -168,10 +170,9 @@ void usages_fini(void) { size_t i; - for (i = 0 ; i < usages.nitems ; i++) { + for (i = 0; i < usages.nitems; i++) { array_fini(&array_item(struct usage_page, &usages, i)->usages); } array_fini(&usages); } - diff --git a/src/main/ddrhook/_com4.c b/src/main/ddrhook/_com4.c index fc1b23c..14ce182 100644 --- a/src/main/ddrhook/_com4.c +++ b/src/main/ddrhook/_com4.c @@ -1,8 +1,8 @@ #include -#include #include #include +#include #include #include @@ -38,7 +38,7 @@ void com4_init(void) ac_io_emu_init(&com4_ac_io_emu, L"COM4"); ac_io_emu_hdxs_init(&com4_hdxs, &com4_ac_io_emu); - for (i = 0 ; i < lengthof(com4_icca) ; i++) { + for (i = 0; i < lengthof(com4_icca); i++) { ac_io_emu_icca_init(&com4_icca[i], &com4_ac_io_emu, i); } } @@ -48,7 +48,8 @@ void com4_fini(void) ac_io_emu_fini(&com4_ac_io_emu); } -HRESULT com4_dispatch_irp(struct irp *irp) +HRESULT +com4_dispatch_irp(struct irp *irp) { const struct ac_io_message *msg; HRESULT hr; @@ -69,36 +70,37 @@ HRESULT com4_dispatch_irp(struct irp *irp) msg = ac_io_emu_request_peek(&com4_ac_io_emu); switch (msg->addr) { - case 0: - ac_io_emu_cmd_assign_addrs(&com4_ac_io_emu, msg, 3); + case 0: + ac_io_emu_cmd_assign_addrs(&com4_ac_io_emu, msg, 3); - break; + break; - case 1: - ac_io_emu_icca_dispatch_request(&com4_icca[0], msg); + case 1: + ac_io_emu_icca_dispatch_request(&com4_icca[0], msg); - break; + break; - case 2: - ac_io_emu_icca_dispatch_request(&com4_icca[1], msg); + case 2: + ac_io_emu_icca_dispatch_request(&com4_icca[1], msg); - break; + break; - case 3: - ac_io_emu_hdxs_dispatch_request(&com4_hdxs, msg); + case 3: + ac_io_emu_hdxs_dispatch_request(&com4_hdxs, msg); - break; + break; - case AC_IO_BROADCAST: - log_warning("Broadcast(?) message on p3io ACIO bus?"); + case AC_IO_BROADCAST: + log_warning("Broadcast(?) message on p3io ACIO bus?"); - break; + break; - default: - log_warning("p3io ACIO message on unhandled bus address: %d", + default: + log_warning( + "p3io ACIO message on unhandled bus address: %d", msg->addr); - break; + break; } ac_io_emu_request_pop(&com4_ac_io_emu); diff --git a/src/main/ddrhook/dinput.c b/src/main/ddrhook/dinput.c index 14a5543..8098453 100644 --- a/src/main/ddrhook/dinput.c +++ b/src/main/ddrhook/dinput.c @@ -12,44 +12,56 @@ #include "util/defs.h" #include "util/log.h" -static HRESULT STDCALL my_DirectInput8Create( HINSTANCE hinst, DWORD dwVersion, - REFIID riidltf, LPVOID * ppvOut, LPVOID punkOuter); +static HRESULT STDCALL my_DirectInput8Create( + HINSTANCE hinst, + DWORD dwVersion, + REFIID riidltf, + LPVOID *ppvOut, + LPVOID punkOuter); -static HRESULT (STDCALL *real_DirectInput8Create)( HINSTANCE hinst, DWORD dwVersion, - REFIID riidltf, LPVOID * ppvOut, LPVOID punkOuter); +static HRESULT(STDCALL *real_DirectInput8Create)( + HINSTANCE hinst, + DWORD dwVersion, + REFIID riidltf, + LPVOID *ppvOut, + LPVOID punkOuter); static const struct hook_symbol dinput_syms[] = { { - .name = "DirectInput8Create", - .patch = my_DirectInput8Create, - .link = (void **) &real_DirectInput8Create, + .name = "DirectInput8Create", + .patch = my_DirectInput8Create, + .link = (void **) &real_DirectInput8Create, }, }; static HRESULT STDCALL my_CreateDevice( - IDirectInput8W *self, - REFGUID rguid, - LPDIRECTINPUTDEVICE8W * lplpDirectInputDevice, - LPUNKNOWN pUnkOuter -) { + IDirectInput8W *self, + REFGUID rguid, + LPDIRECTINPUTDEVICE8W *lplpDirectInputDevice, + LPUNKNOWN pUnkOuter) +{ log_misc("IDirectInput8::CreateDevice hook hit"); return DIERR_NOINTERFACE; } static HRESULT STDCALL my_EnumDevices( - IDirectInput8W *self, - DWORD dwDevType, - LPDIENUMDEVICESCALLBACKW lpCallback, - LPVOID pvRef, - DWORD dwFlags -) { + IDirectInput8W *self, + DWORD dwDevType, + LPDIENUMDEVICESCALLBACKW lpCallback, + LPVOID pvRef, + DWORD dwFlags) +{ log_misc("IDirectInput8::EnumDevices hook hit"); return DI_OK; } -static HRESULT STDCALL my_DirectInput8Create( HINSTANCE hinst, DWORD dwVersion, - REFIID riidltf, LPVOID * ppvOut, LPVOID punkOuter) +static HRESULT STDCALL my_DirectInput8Create( + HINSTANCE hinst, + DWORD dwVersion, + REFIID riidltf, + LPVOID *ppvOut, + LPVOID punkOuter) { IDirectInput8W *api; IDirectInput8WVtbl *api_vtbl; @@ -58,8 +70,9 @@ static HRESULT STDCALL my_DirectInput8Create( HINSTANCE hinst, DWORD dwVersion, log_info("DirectInput8Create hook hit"); - res = real_DirectInput8Create(hinst, dwVersion, riidltf, (LPVOID *)&api, punkOuter); - if(res != DI_OK) { + res = real_DirectInput8Create( + hinst, dwVersion, riidltf, (LPVOID *) &api, punkOuter); + if (res != DI_OK) { return res; } api_proxy = com_proxy_wrap(api, sizeof(*api->lpVtbl)); @@ -68,18 +81,14 @@ static HRESULT STDCALL my_DirectInput8Create( HINSTANCE hinst, DWORD dwVersion, api_vtbl->EnumDevices = my_EnumDevices; api_vtbl->CreateDevice = my_CreateDevice; - *(IDirectInput8W**)ppvOut = (IDirectInput8W *)api_proxy; + *(IDirectInput8W **) ppvOut = (IDirectInput8W *) api_proxy; return res; } void dinput_init(HMODULE target) { - hook_table_apply( - target, - "dinput8.dll", - dinput_syms, - lengthof(dinput_syms)); + hook_table_apply(target, "dinput8.dll", dinput_syms, lengthof(dinput_syms)); log_info("Inserted dinput hooks into %p", target); } diff --git a/src/main/ddrhook/dllmain.c b/src/main/ddrhook/dllmain.c index f9ce666..5971fb9 100644 --- a/src/main/ddrhook/dllmain.c +++ b/src/main/ddrhook/dllmain.c @@ -51,7 +51,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) args_recover(&argc, &argv); - for (i = 1 ; i < argc ; i++) { + for (i = 1; i < argc; i++) { if (argv[i][0] != '-') { continue; } @@ -84,10 +84,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) log_info("Initializing DDR IO backend"); ddr_io_set_loggers( - log_body_misc, - log_body_info, - log_body_warning, - log_body_fatal); + log_body_misc, log_body_info, log_body_warning, log_body_fatal); ok = ddr_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy); @@ -98,10 +95,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) log_info("Initializing card reader backend"); eam_io_set_loggers( - log_body_misc, - log_body_info, - log_body_warning, - log_body_fatal); + 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); @@ -142,10 +136,7 @@ BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx) } log_to_external( - log_body_misc, - log_body_info, - log_body_warning, - log_body_fatal); + log_body_misc, log_body_info, log_body_warning, log_body_fatal); app_hook_init(my_dll_entry_init, my_dll_entry_main); diff --git a/src/main/ddrhook/extio.c b/src/main/ddrhook/extio.c index eed44af..2d99d35 100644 --- a/src/main/ddrhook/extio.c +++ b/src/main/ddrhook/extio.c @@ -1,8 +1,8 @@ #include -#include #include #include +#include #include #include @@ -43,7 +43,8 @@ void extio_fini(void) extio_fd = NULL; } -HRESULT extio_dispatch_irp(struct irp *irp) +HRESULT +extio_dispatch_irp(struct irp *irp) { log_assert(irp != NULL); @@ -52,12 +53,18 @@ HRESULT extio_dispatch_irp(struct irp *irp) } switch (irp->op) { - case IRP_OP_OPEN: return extio_open(irp); - case IRP_OP_CLOSE: return extio_close(irp); - case IRP_OP_READ: return extio_read(irp); - case IRP_OP_WRITE: return extio_write(irp); - case IRP_OP_IOCTL: return extio_ioctl(irp); - default: return E_NOTIMPL; + case IRP_OP_OPEN: + return extio_open(irp); + case IRP_OP_CLOSE: + return extio_close(irp); + case IRP_OP_READ: + return extio_read(irp); + case IRP_OP_WRITE: + return extio_write(irp); + case IRP_OP_IOCTL: + return extio_ioctl(irp); + default: + return E_NOTIMPL; } } @@ -126,31 +133,31 @@ static HRESULT extio_ioctl(struct irp *irp) log_assert(irp != NULL); switch (irp->ioctl) { - case IOCTL_SERIAL_GET_COMMSTATUS: - if (irp->read.bytes == NULL) { - log_warning("IOCTL_SERIAL_GET_COMMSTATUS: Output buffer is NULL"); + case IOCTL_SERIAL_GET_COMMSTATUS: + if (irp->read.bytes == NULL) { + log_warning( + "IOCTL_SERIAL_GET_COMMSTATUS: Output buffer is NULL"); - return E_INVALIDARG; - } + return E_INVALIDARG; + } - if (irp->read.nbytes < sizeof(*status)) { - log_warning("IOCTL_SERIAL_GET_COMMSTATUS: Buffer is too small"); + if (irp->read.nbytes < sizeof(*status)) { + log_warning("IOCTL_SERIAL_GET_COMMSTATUS: Buffer is too small"); - return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); - } + return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); + } - status = (SERIAL_STATUS *) irp->read.bytes; - status->Errors = 0; - status->AmountInInQueue = extio_pending ? 1 : 0; + status = (SERIAL_STATUS *) irp->read.bytes; + status->Errors = 0; + status->AmountInInQueue = extio_pending ? 1 : 0; - irp->read.pos = sizeof(*status); + irp->read.pos = sizeof(*status); - break; + break; - default: - break; + default: + break; } return S_OK; } - diff --git a/src/main/ddrhook/gfx.c b/src/main/ddrhook/gfx.c index d442f54..2e6727a 100644 --- a/src/main/ddrhook/gfx.c +++ b/src/main/ddrhook/gfx.c @@ -1,5 +1,5 @@ -#include #include +#include #include @@ -10,32 +10,36 @@ #include "util/log.h" static HRESULT STDCALL my_CreateDevice( - IDirect3D9 *self, UINT adapter, D3DDEVTYPE type, HWND hwnd, - DWORD flags, D3DPRESENT_PARAMETERS *pp, IDirect3DDevice9 **pdev); + IDirect3D9 *self, + UINT adapter, + D3DDEVTYPE type, + HWND hwnd, + DWORD flags, + D3DPRESENT_PARAMETERS *pp, + IDirect3DDevice9 **pdev); static IDirect3D9 *STDCALL my_Direct3DCreate9(UINT sdk_ver); -static IDirect3D9 * (STDCALL *real_Direct3DCreate9)( - UINT sdk_ver); +static IDirect3D9 *(STDCALL *real_Direct3DCreate9)(UINT sdk_ver); static bool gfx_windowed; static const struct hook_symbol gfx_d3d9_hook_syms[] = { { - .name = "Direct3DCreate9", - .patch = my_Direct3DCreate9, - .link = (void **) &real_Direct3DCreate9, + .name = "Direct3DCreate9", + .patch = my_Direct3DCreate9, + .link = (void **) &real_Direct3DCreate9, }, }; static HRESULT STDCALL my_CreateDevice( - IDirect3D9 *self, - UINT adapter, - D3DDEVTYPE type, - HWND hwnd, - DWORD flags, - D3DPRESENT_PARAMETERS *pp, - IDirect3DDevice9 **pdev) + IDirect3D9 *self, + UINT adapter, + D3DDEVTYPE type, + HWND hwnd, + DWORD flags, + D3DPRESENT_PARAMETERS *pp, + IDirect3DDevice9 **pdev) { IDirect3D9 *real; @@ -69,10 +73,7 @@ static IDirect3D9 *STDCALL my_Direct3DCreate9(UINT sdk_ver) void gfx_insert_hooks(HMODULE target) { hook_table_apply( - target, - "d3d9.dll", - gfx_d3d9_hook_syms, - lengthof(gfx_d3d9_hook_syms)); + target, "d3d9.dll", gfx_d3d9_hook_syms, lengthof(gfx_d3d9_hook_syms)); log_info("Inserted graphics hooks"); } @@ -86,4 +87,3 @@ void gfx_set_windowed(void) { gfx_windowed = true; } - diff --git a/src/main/ddrhook/guid.c b/src/main/ddrhook/guid.c index c0096d2..5ae4393 100644 --- a/src/main/ddrhook/guid.c +++ b/src/main/ddrhook/guid.c @@ -1,4 +1,4 @@ -#include #include +#include #include "ddrhook/monitor.h" diff --git a/src/main/ddrhook/master.c b/src/main/ddrhook/master.c index b817265..b63bdf7 100644 --- a/src/main/ddrhook/master.c +++ b/src/main/ddrhook/master.c @@ -1,6 +1,6 @@ +#include "ddrhook/master.h" #include "ddrhook/dinput.h" #include "ddrhook/gfx.h" -#include "ddrhook/master.h" #include "ddrhook/misc.h" #include "ddrhook/monitor.h" @@ -11,15 +11,15 @@ #include "util/defs.h" #include "util/log.h" -static HMODULE (STDCALL *real_LoadLibraryA)(const char *name); +static HMODULE(STDCALL *real_LoadLibraryA)(const char *name); static HMODULE STDCALL my_LoadLibraryA(const char *name); static const struct hook_symbol master_kernel32_syms[] = { { - .name = "LoadLibraryA", - .patch = my_LoadLibraryA, - .link = (void **) &real_LoadLibraryA, + .name = "LoadLibraryA", + .patch = my_LoadLibraryA, + .link = (void **) &real_LoadLibraryA, }, }; @@ -60,10 +60,10 @@ void master_insert_hooks(HMODULE target) /* Insert dynamic loader hooks so that we can hook late-loaded modules */ hook_table_apply( - target, - "kernel32.dll", - master_kernel32_syms, - lengthof(master_kernel32_syms)); + target, + "kernel32.dll", + master_kernel32_syms, + lengthof(master_kernel32_syms)); log_info("Inserted dynamic loader hooks into %p", target); } diff --git a/src/main/ddrhook/misc.c b/src/main/ddrhook/misc.c index 2b3facf..ffe50ec 100644 --- a/src/main/ddrhook/misc.c +++ b/src/main/ddrhook/misc.c @@ -11,95 +11,125 @@ #include "util/log.h" #include "util/str.h" -static LONG (STDCALL *real_ChangeDisplaySettingsExA)( - char *dev_name, DEVMODE *dev_mode, HWND hwnd, DWORD flags, void *param); -static LRESULT (STDCALL *real_SendMessageW)( - HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); -static HWND (STDCALL *real_CreateWindowExW)(DWORD dwExStyle, LPCWSTR lpClassName, - LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, - int nHeight, HWND hWndParent, HMENU hMenu, - HINSTANCE hInstance, LPVOID lpParam); -static LONG (STDCALL *real_SetWindowLongW)(HWND hWnd, int nIndex, LONG dwNewLong); -static BOOL (STDCALL *real_SetWindowPos)(HWND hWnd, HWND hWndInsertAfter, - int X, int Y, int cx, int cy, UINT uFlags); +static LONG(STDCALL *real_ChangeDisplaySettingsExA)( + char *dev_name, DEVMODE *dev_mode, HWND hwnd, DWORD flags, void *param); +static LRESULT(STDCALL *real_SendMessageW)( + HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); +static HWND(STDCALL *real_CreateWindowExW)( + DWORD dwExStyle, + LPCWSTR lpClassName, + LPCWSTR lpWindowName, + DWORD dwStyle, + int X, + int Y, + int nWidth, + int nHeight, + HWND hWndParent, + HMENU hMenu, + HINSTANCE hInstance, + LPVOID lpParam); +static LONG(STDCALL *real_SetWindowLongW)( + HWND hWnd, int nIndex, LONG dwNewLong); +static BOOL(STDCALL *real_SetWindowPos)( + HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags); static LONG STDCALL my_ChangeDisplaySettingsExA( - char *dev_name, DEVMODE *dev_mode, HWND hwnd, DWORD flags, void *param); + char *dev_name, DEVMODE *dev_mode, HWND hwnd, DWORD flags, void *param); static SHORT STDCALL my_GetKeyState(int vk); -static LRESULT STDCALL my_SendMessageW( - HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); +static LRESULT STDCALL +my_SendMessageW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); static HWND STDCALL my_CreateWindowExA( - DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, - int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, - HINSTANCE hInstance, LPVOID lpParam); -static HWND STDCALL my_CreateWindowExW(DWORD dwExStyle, LPCWSTR lpClassName, - LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, - int nHeight, HWND hWndParent, HMENU hMenu, - HINSTANCE hInstance, LPVOID lpParam); + DWORD dwExStyle, + LPCSTR lpClassName, + LPCSTR lpWindowName, + DWORD dwStyle, + int X, + int Y, + int nWidth, + int nHeight, + HWND hWndParent, + HMENU hMenu, + HINSTANCE hInstance, + LPVOID lpParam); +static HWND STDCALL my_CreateWindowExW( + DWORD dwExStyle, + LPCWSTR lpClassName, + LPCWSTR lpWindowName, + DWORD dwStyle, + int X, + int Y, + int nWidth, + int nHeight, + HWND hWndParent, + HMENU hMenu, + HINSTANCE hInstance, + LPVOID lpParam); static LONG STDCALL my_SetWindowLongW(HWND hWnd, int nIndex, LONG dwNewLong); -static BOOL STDCALL my_SetWindowPos(HWND hWnd, HWND hWndInsertAfter, - int X, int Y, int cx, int cy, UINT uFlags); +static BOOL STDCALL my_SetWindowPos( + HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags); static const struct hook_symbol misc_user32_syms[] = { { - .name = "ChangeDisplaySettingsExA", - .patch = my_ChangeDisplaySettingsExA, - .link = (void **) &real_ChangeDisplaySettingsExA, + .name = "ChangeDisplaySettingsExA", + .patch = my_ChangeDisplaySettingsExA, + .link = (void **) &real_ChangeDisplaySettingsExA, }, { - .name = "SendMessageW", - .patch = my_SendMessageW, - .link = (void **) &real_SendMessageW, + .name = "SendMessageW", + .patch = my_SendMessageW, + .link = (void **) &real_SendMessageW, }, { - .name = "GetKeyState", - .patch = my_GetKeyState, + .name = "GetKeyState", + .patch = my_GetKeyState, }, { - .name = "CreateWindowExA", - .patch = my_CreateWindowExA, + .name = "CreateWindowExA", + .patch = my_CreateWindowExA, }, { - .name = "CreateWindowExW", - .patch = my_CreateWindowExW, - .link = (void **) &real_CreateWindowExW, + .name = "CreateWindowExW", + .patch = my_CreateWindowExW, + .link = (void **) &real_CreateWindowExW, }, { - .name = "SetWindowLongW", - .patch = my_SetWindowLongW, - .link = (void **) &real_SetWindowLongW, + .name = "SetWindowLongW", + .patch = my_SetWindowLongW, + .link = (void **) &real_SetWindowLongW, }, { - .name = "SetWindowPos", - .patch = my_SetWindowPos, - .link = (void **) &real_SetWindowPos, + .name = "SetWindowPos", + .patch = my_SetWindowPos, + .link = (void **) &real_SetWindowPos, }, }; -static LONG STDCALL my_SetWindowLongW(HWND hWnd, int nIndex, LONG dwNewLong) { - if(nIndex == GWL_STYLE) +static LONG STDCALL my_SetWindowLongW(HWND hWnd, int nIndex, LONG dwNewLong) +{ + if (nIndex == GWL_STYLE) dwNewLong |= WS_OVERLAPPEDWINDOW; return real_SetWindowLongW(hWnd, nIndex, dwNewLong); } -static BOOL STDCALL my_SetWindowPos(HWND hWnd, HWND hWndInsertAfter, - int X, int Y, int cx, int cy, UINT uFlags) { +static BOOL STDCALL my_SetWindowPos( + HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags) +{ return true; } static LONG STDCALL my_ChangeDisplaySettingsExA( - char *dev_name, DEVMODE *dev_mode, HWND hwnd, DWORD flags, void *param) + char *dev_name, DEVMODE *dev_mode, HWND hwnd, DWORD flags, void *param) { if (gfx_get_windowed()) { return DISP_CHANGE_SUCCESSFUL; } else { - return real_ChangeDisplaySettingsExA(dev_name, dev_mode, hwnd, flags, - param); + return real_ChangeDisplaySettingsExA( + dev_name, dev_mode, hwnd, flags, param); } } -static void calc_win_size_with_framed(HWND hwnd, DWORD x, DWORD y, DWORD width, - DWORD height, LPWINDOWPOS wp) +static void calc_win_size_with_framed( + HWND hwnd, DWORD x, DWORD y, DWORD width, DWORD height, LPWINDOWPOS wp) { /* taken from dxwnd */ RECT rect; @@ -138,10 +168,19 @@ static void calc_win_size_with_framed(HWND hwnd, DWORD x, DWORD y, DWORD width, wp->cy = rect.bottom - rect.top; } -static HWND STDCALL my_CreateWindowExW(DWORD dwExStyle, LPCWSTR lpClassName, - LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, - int nHeight, HWND hWndParent, HMENU hMenu, - HINSTANCE hInstance, LPVOID lpParam) +static HWND STDCALL my_CreateWindowExW( + DWORD dwExStyle, + LPCWSTR lpClassName, + LPCWSTR lpWindowName, + DWORD dwStyle, + int X, + int Y, + int nWidth, + int nHeight, + HWND hWndParent, + HMENU hMenu, + HINSTANCE hInstance, + LPVOID lpParam) { if (gfx_get_windowed()) { /* use a different style */ @@ -150,12 +189,22 @@ static HWND STDCALL my_CreateWindowExW(DWORD dwExStyle, LPCWSTR lpClassName, ShowCursor(TRUE); } - if(!lpWindowName) + if (!lpWindowName) lpWindowName = L"Dance Dance Revolution"; - HWND hwnd = real_CreateWindowExW(dwExStyle, lpClassName, lpWindowName, - dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, - lpParam); + HWND hwnd = real_CreateWindowExW( + dwExStyle, + lpClassName, + lpWindowName, + dwStyle, + X, + Y, + nWidth, + nHeight, + hWndParent, + hMenu, + hInstance, + lpParam); if (hwnd == INVALID_HANDLE_VALUE) { return hwnd; @@ -178,23 +227,43 @@ static HWND STDCALL my_CreateWindowExW(DWORD dwExStyle, LPCWSTR lpClassName, } static HWND STDCALL my_CreateWindowExA( - DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, - int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, - HINSTANCE hInstance, LPVOID lpParam) + DWORD dwExStyle, + LPCSTR lpClassName, + LPCSTR lpWindowName, + DWORD dwStyle, + int X, + int Y, + int nWidth, + int nHeight, + HWND hWndParent, + HMENU hMenu, + HINSTANCE hInstance, + LPVOID lpParam) { LPWSTR longWindowName = NULL; LPWSTR longClassName = NULL; - if(lpWindowName) + if (lpWindowName) longWindowName = str_widen(lpWindowName); - if(lpClassName) + if (lpClassName) longClassName = str_widen(lpClassName); - HWND ret = my_CreateWindowExW(dwExStyle, longClassName, longWindowName, - dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam); + HWND ret = my_CreateWindowExW( + dwExStyle, + longClassName, + longWindowName, + dwStyle, + X, + Y, + nWidth, + nHeight, + hWndParent, + hMenu, + hInstance, + lpParam); - if(longWindowName) + if (longWindowName) free(longWindowName); - if(longClassName) + if (longClassName) free(longClassName); return ret; @@ -206,8 +275,8 @@ static SHORT STDCALL my_GetKeyState(int vk) return 0; } -static LRESULT STDCALL my_SendMessageW( - HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) +static LRESULT STDCALL +my_SendMessageW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { if (hwnd == HWND_BROADCAST) { /* OK COOL STORY BRO */ @@ -222,11 +291,7 @@ static LRESULT STDCALL my_SendMessageW( void misc_insert_hooks(HMODULE target) { hook_table_apply( - target, - "user32.dll", - misc_user32_syms, - lengthof(misc_user32_syms)); + target, "user32.dll", misc_user32_syms, lengthof(misc_user32_syms)); log_info("Inserted miscellaneous hooks into %p", target); } - diff --git a/src/main/ddrhook/monitor.c b/src/main/ddrhook/monitor.c index 9e664b9..3eb72c5 100644 --- a/src/main/ddrhook/monitor.c +++ b/src/main/ddrhook/monitor.c @@ -1,5 +1,5 @@ -#include #include +#include #include #include @@ -14,69 +14,62 @@ /* Link pointers */ -static HDEVINFO (WINAPI *next_SetupDiGetClassDevsW)( - const GUID *class_guid, - const wchar_t *enumerator, - HWND hwnd, - DWORD flags); +static HDEVINFO(WINAPI *next_SetupDiGetClassDevsW)( + const GUID *class_guid, const wchar_t *enumerator, HWND hwnd, DWORD flags); -static BOOL (WINAPI *next_SetupDiEnumDeviceInfo)( - HDEVINFO dev_info, - DWORD index, - SP_DEVINFO_DATA *info_data); +static BOOL(WINAPI *next_SetupDiEnumDeviceInfo)( + HDEVINFO dev_info, DWORD index, SP_DEVINFO_DATA *info_data); -static BOOL (WINAPI *next_SetupDiGetDeviceRegistryPropertyA)( - HDEVINFO dev_info, - SP_DEVINFO_DATA *info_data, - DWORD prop, - DWORD *reg_type, - BYTE *bytes, - DWORD nbytes, - DWORD *need_nbytes); +static BOOL(WINAPI *next_SetupDiGetDeviceRegistryPropertyA)( + HDEVINFO dev_info, + SP_DEVINFO_DATA *info_data, + DWORD prop, + DWORD *reg_type, + BYTE *bytes, + DWORD nbytes, + DWORD *need_nbytes); -static BOOL (WINAPI *next_SetupDiDestroyDeviceInfoList)(HDEVINFO dev_info); +static BOOL(WINAPI *next_SetupDiDestroyDeviceInfoList)(HDEVINFO dev_info); /* API hooks */ static HDEVINFO WINAPI my_SetupDiGetClassDevsW( - const GUID *class_guid, - const wchar_t *enumerator, - HWND hwnd, - DWORD flags); + const GUID *class_guid, const wchar_t *enumerator, HWND hwnd, DWORD flags); static BOOL WINAPI my_SetupDiEnumDeviceInfo( - HDEVINFO dev_info, - DWORD index, - SP_DEVINFO_DATA *info_data); + HDEVINFO dev_info, DWORD index, SP_DEVINFO_DATA *info_data); static BOOL WINAPI my_SetupDiGetDeviceRegistryPropertyA( - HDEVINFO dev_info, - SP_DEVINFO_DATA *info_data, - DWORD prop, - DWORD *reg_type, - BYTE *bytes, - DWORD nbytes, - DWORD *need_nbytes); + HDEVINFO dev_info, + SP_DEVINFO_DATA *info_data, + DWORD prop, + DWORD *reg_type, + BYTE *bytes, + DWORD nbytes, + DWORD *need_nbytes); static BOOL WINAPI my_SetupDiDestroyDeviceInfoList(HDEVINFO dev_info); static const struct hook_symbol monitor_setupapi_syms[] = { { - .name = "SetupDiGetClassDevsW", - .patch = my_SetupDiGetClassDevsW, - .link = (void **) &next_SetupDiGetClassDevsW, - }, { - .name = "SetupDiEnumDeviceInfo", - .patch = my_SetupDiEnumDeviceInfo, - .link = (void **) &next_SetupDiEnumDeviceInfo, - }, { - .name = "SetupDiGetDeviceRegistryPropertyA", - .patch = my_SetupDiGetDeviceRegistryPropertyA, - .link = (void **) &next_SetupDiGetDeviceRegistryPropertyA, - }, { - .name = "SetupDiDestroyDeviceInfoList", - .patch = my_SetupDiDestroyDeviceInfoList, - .link = (void **) &next_SetupDiDestroyDeviceInfoList, + .name = "SetupDiGetClassDevsW", + .patch = my_SetupDiGetClassDevsW, + .link = (void **) &next_SetupDiGetClassDevsW, + }, + { + .name = "SetupDiEnumDeviceInfo", + .patch = my_SetupDiEnumDeviceInfo, + .link = (void **) &next_SetupDiEnumDeviceInfo, + }, + { + .name = "SetupDiGetDeviceRegistryPropertyA", + .patch = my_SetupDiGetDeviceRegistryPropertyA, + .link = (void **) &next_SetupDiGetDeviceRegistryPropertyA, + }, + { + .name = "SetupDiDestroyDeviceInfoList", + .patch = my_SetupDiDestroyDeviceInfoList, + .link = (void **) &next_SetupDiDestroyDeviceInfoList, }, }; @@ -84,17 +77,14 @@ extern bool standard_def; static HDEVINFO monitor_hdevinfo; static HDEVINFO WINAPI my_SetupDiGetClassDevsW( - const GUID *class_guid, - const wchar_t *enumerator, - HWND hwnd, - DWORD flags) + const GUID *class_guid, const wchar_t *enumerator, HWND hwnd, DWORD flags) { HDEVINFO result; result = next_SetupDiGetClassDevsW(class_guid, enumerator, hwnd, flags); - if ( result != INVALID_HANDLE_VALUE && - IsEqualGUID(class_guid, &monitor_guid)) { + if (result != INVALID_HANDLE_VALUE && + IsEqualGUID(class_guid, &monitor_guid)) { monitor_hdevinfo = result; } @@ -102,9 +92,7 @@ static HDEVINFO WINAPI my_SetupDiGetClassDevsW( } static BOOL WINAPI my_SetupDiEnumDeviceInfo( - HDEVINFO dev_info, - DWORD index, - SP_DEVINFO_DATA *info_data) + HDEVINFO dev_info, DWORD index, SP_DEVINFO_DATA *info_data) { if (dev_info != monitor_hdevinfo) { return next_SetupDiEnumDeviceInfo(dev_info, index, info_data); @@ -128,26 +116,20 @@ static BOOL WINAPI my_SetupDiEnumDeviceInfo( } static BOOL WINAPI my_SetupDiGetDeviceRegistryPropertyA( - HDEVINFO dev_info, - SP_DEVINFO_DATA *info_data, - DWORD prop, - DWORD *reg_type, - BYTE *bytes, - DWORD nbytes, - DWORD *nbytes_out) + HDEVINFO dev_info, + SP_DEVINFO_DATA *info_data, + DWORD prop, + DWORD *reg_type, + BYTE *bytes, + DWORD nbytes, + DWORD *nbytes_out) { const char *txt; size_t txt_nbytes; if (dev_info != monitor_hdevinfo) { return next_SetupDiGetDeviceRegistryPropertyA( - dev_info, - info_data, - prop, - reg_type, - bytes, - nbytes, - nbytes_out); + dev_info, info_data, prop, reg_type, bytes, nbytes, nbytes_out); } /* The only implemented property */ @@ -199,10 +181,10 @@ static BOOL WINAPI my_SetupDiDestroyDeviceInfoList(HDEVINFO dev_info) void monitor_setupapi_insert_hooks(HMODULE target) { hook_table_apply( - target, - "setupapi.dll", - monitor_setupapi_syms, - lengthof(monitor_setupapi_syms)); + target, + "setupapi.dll", + monitor_setupapi_syms, + lengthof(monitor_setupapi_syms)); log_info("Inserted monitor setupapi hooks into %p", target); } diff --git a/src/main/ddrhook/monitor.h b/src/main/ddrhook/monitor.h index 0a597a5..10acee2 100644 --- a/src/main/ddrhook/monitor.h +++ b/src/main/ddrhook/monitor.h @@ -4,11 +4,18 @@ #include DEFINE_GUID( - monitor_guid, - 0x4D36E96E, - 0xE325, - 0x11CE, - 0xBF, 0xC1, 0x08, 0x00, 0x2B, 0xE1, 0x03, 0x18); + monitor_guid, + 0x4D36E96E, + 0xE325, + 0x11CE, + 0xBF, + 0xC1, + 0x08, + 0x00, + 0x2B, + 0xE1, + 0x03, + 0x18); void monitor_setupapi_insert_hooks(HMODULE target); diff --git a/src/main/ddrhook/p3io.c b/src/main/ddrhook/p3io.c index a87f5bd..41186bd 100644 --- a/src/main/ddrhook/p3io.c +++ b/src/main/ddrhook/p3io.c @@ -21,9 +21,9 @@ static HRESULT p3io_ddr_get_cab_type(void *ctx, enum p3io_cab_type *type); static HRESULT p3io_ddr_get_video_freq(void *ctx, enum p3io_video_freq *freq); static const struct p3io_ops p3io_ddr_ops = { - .read_jamma = p3io_ddr_read_jamma, - .set_outputs = p3io_ddr_set_outputs, - .get_cab_type = p3io_ddr_get_cab_type, + .read_jamma = p3io_ddr_read_jamma, + .set_outputs = p3io_ddr_set_outputs, + .get_cab_type = p3io_ddr_get_cab_type, .get_video_freq = p3io_ddr_get_video_freq, }; diff --git a/src/main/ddrhook/spike.c b/src/main/ddrhook/spike.c index d1c1191..c6364eb 100644 --- a/src/main/ddrhook/spike.c +++ b/src/main/ddrhook/spike.c @@ -2,9 +2,9 @@ #include -#include #include #include +#include #include #include @@ -36,7 +36,8 @@ void spike_fini(void) ac_io_emu_fini(&spike_ac_io_emu); } -HRESULT spike_dispatch_irp(struct irp *irp) +HRESULT +spike_dispatch_irp(struct irp *irp) { const struct ac_io_message *msg; HRESULT hr; @@ -57,60 +58,61 @@ HRESULT spike_dispatch_irp(struct irp *irp) msg = ac_io_emu_request_peek(&spike_ac_io_emu); switch (msg->addr) { - case 0: - ac_io_emu_cmd_assign_addrs(&spike_ac_io_emu, msg, 7); - - break; - - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - switch (ac_io_u16(msg->cmd.code)) { - case AC_IO_CMD_GET_VERSION: - spike_handle_get_version(msg); + case 0: + ac_io_emu_cmd_assign_addrs(&spike_ac_io_emu, msg, 7); break; - case AC_IO_CMD_START_UP: - spike_handle_status(msg); + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + switch (ac_io_u16(msg->cmd.code)) { + case AC_IO_CMD_GET_VERSION: + spike_handle_get_version(msg); + + break; + + case AC_IO_CMD_START_UP: + spike_handle_status(msg); + + break; + + case AC_IO_CMD_KEEPALIVE: + spike_send_empty(msg); + + break; + + case 0x100: + case 0x110: + case 0x112: + case 0x128: + spike_handle_status(msg); + + break; + + default: + log_warning( + "Spike ACIO unhandled cmd: %04X", + ac_io_u16(msg->cmd.code)); + } break; - case AC_IO_CMD_KEEPALIVE: - spike_send_empty(msg); - - break; - - case 0x100: - case 0x110: - case 0x112: - case 0x128: - spike_handle_status(msg); + case AC_IO_BROADCAST: + spike_handle_broadcast(msg); break; default: - log_warning("Spike ACIO unhandled cmd: %04X", - ac_io_u16(msg->cmd.code)); - } - - break; - - case AC_IO_BROADCAST: - spike_handle_broadcast(msg); - - break; - - default: - log_warning( + log_warning( "Spike ACIO message on unhandled bus address: %d", msg->addr); - break; + break; } ac_io_emu_request_pop(&spike_ac_io_emu); @@ -138,8 +140,10 @@ static void spike_handle_get_version(const struct ac_io_message *req) resp.cmd.version.major = 0x01; resp.cmd.version.minor = 0x01; resp.cmd.version.revision = 0x00; - memcpy(resp.cmd.version.product_code, "DDRS", - sizeof(resp.cmd.version.product_code)); + memcpy( + resp.cmd.version.product_code, + "DDRS", + sizeof(resp.cmd.version.product_code)); strncpy(resp.cmd.version.date, __DATE__, sizeof(resp.cmd.version.date)); strncpy(resp.cmd.version.time, __TIME__, sizeof(resp.cmd.version.time)); diff --git a/src/main/ddrhook/usbmem.c b/src/main/ddrhook/usbmem.c index 1e5ac5c..8108dc7 100644 --- a/src/main/ddrhook/usbmem.c +++ b/src/main/ddrhook/usbmem.c @@ -2,9 +2,9 @@ #include -#include #include #include +#include #include #include @@ -12,8 +12,8 @@ #include "hook/iohook.h" -#include "util/log.h" #include "util/iobuf.h" +#include "util/log.h" #include "util/str.h" #define USBMEM_BUF_SIZE 128 @@ -44,7 +44,8 @@ void usbmem_fini(void) usbmem_fd = NULL; } -HRESULT usbmem_dispatch_irp(struct irp *irp) +HRESULT +usbmem_dispatch_irp(struct irp *irp) { log_assert(irp != NULL); @@ -53,12 +54,18 @@ HRESULT usbmem_dispatch_irp(struct irp *irp) } switch (irp->op) { - case IRP_OP_OPEN: return usbmem_open(irp); - case IRP_OP_CLOSE: return usbmem_close(irp); - case IRP_OP_READ: return usbmem_read(irp); - case IRP_OP_WRITE: return usbmem_write(irp); - case IRP_OP_IOCTL: return usbmem_ioctl(irp); - default: return E_NOTIMPL; + case IRP_OP_OPEN: + return usbmem_open(irp); + case IRP_OP_CLOSE: + return usbmem_close(irp); + case IRP_OP_READ: + return usbmem_read(irp); + case IRP_OP_WRITE: + return usbmem_write(irp); + case IRP_OP_IOCTL: + return usbmem_ioctl(irp); + default: + return E_NOTIMPL; } } @@ -101,18 +108,17 @@ static HRESULT usbmem_write(struct irp *irp) if (strlen(request) > 0) { if (str_eq(request, "sver")) { - str_cpy(usbmem_response, - sizeof(usbmem_response), - "done GQHDXJAA DJHACKRS"); + str_cpy( + usbmem_response, + sizeof(usbmem_response), + "done GQHDXJAA DJHACKRS"); } else if ( - str_eq(request, "on_a") || - str_eq(request, "on_b") || - str_eq(request, "offa") || - str_eq(request, "offb") ) { + str_eq(request, "on_a") || str_eq(request, "on_b") || + str_eq(request, "offa") || str_eq(request, "offb")) { str_cpy(usbmem_response, sizeof(usbmem_response), "done"); } else if ( - strncmp(request, "lma ", 4) == 0 || - strncmp(request, "lmb ", 4) == 0) { + strncmp(request, "lma ", 4) == 0 || + strncmp(request, "lmb ", 4) == 0) { str_cpy(usbmem_response, sizeof(usbmem_response), "done"); } else { str_cpy(usbmem_response, sizeof(usbmem_response), "not connected"); @@ -160,31 +166,31 @@ static HRESULT usbmem_ioctl(struct irp *irp) log_assert(irp != NULL); switch (irp->ioctl) { - case IOCTL_SERIAL_GET_COMMSTATUS: - if (irp->read.bytes == NULL) { - log_warning("IOCTL_SERIAL_GET_COMMSTATUS: Output buffer is NULL"); + case IOCTL_SERIAL_GET_COMMSTATUS: + if (irp->read.bytes == NULL) { + log_warning( + "IOCTL_SERIAL_GET_COMMSTATUS: Output buffer is NULL"); - return E_INVALIDARG; - } + return E_INVALIDARG; + } - if (irp->read.nbytes < sizeof(*status)) { - log_warning("IOCTL_SERIAL_GET_COMMSTATUS: Buffer is too small"); + if (irp->read.nbytes < sizeof(*status)) { + log_warning("IOCTL_SERIAL_GET_COMMSTATUS: Buffer is too small"); - return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); - } + return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); + } - status = (SERIAL_STATUS *) irp->read.bytes; - status->Errors = 0; - status->AmountInInQueue = usbmem_pending ? 1 : 0; + status = (SERIAL_STATUS *) irp->read.bytes; + status->Errors = 0; + status->AmountInInQueue = usbmem_pending ? 1 : 0; - irp->read.pos = sizeof(*status); + irp->read.pos = sizeof(*status); - break; + break; - default: - break; + default: + break; } return S_OK; } - diff --git a/src/main/ddrio-mm/ddrio.c b/src/main/ddrio-mm/ddrio.c index 4be7402..defcb23 100644 --- a/src/main/ddrio-mm/ddrio.c +++ b/src/main/ddrio-mm/ddrio.c @@ -20,49 +20,49 @@ struct ddr_bittrans { }; static const struct ddr_bittrans input_map[] = { - { 0x00000001, 1 << DDR_SERVICE }, - { 0x00000002, 1 << DDR_TEST }, - { 0x00100000, 1 << DDR_P1_MENU_LEFT }, - { 0x00400000, 1 << DDR_P1_MENU_RIGHT }, - { 0x00000100, 1 << DDR_P1_START }, - { 0x00200000, 1 << DDR_P2_MENU_LEFT }, - { 0x00800000, 1 << DDR_P2_MENU_RIGHT }, - { 0x00000200, 1 << DDR_P2_START }, - { 0x00004000, 1 << DDR_P1_LEFT }, - { 0x00010000, 1 << DDR_P1_RIGHT }, - { 0x00000400, 1 << DDR_P1_UP }, - { 0x00001000, 1 << DDR_P1_DOWN }, - { 0x00008000, 1 << DDR_P2_LEFT }, - { 0x00020000, 1 << DDR_P2_RIGHT }, - { 0x00000800, 1 << DDR_P2_UP }, - { 0x00002000, 1 << DDR_P2_DOWN }, + {0x00000001, 1 << DDR_SERVICE}, + {0x00000002, 1 << DDR_TEST}, + {0x00100000, 1 << DDR_P1_MENU_LEFT}, + {0x00400000, 1 << DDR_P1_MENU_RIGHT}, + {0x00000100, 1 << DDR_P1_START}, + {0x00200000, 1 << DDR_P2_MENU_LEFT}, + {0x00800000, 1 << DDR_P2_MENU_RIGHT}, + {0x00000200, 1 << DDR_P2_START}, + {0x00004000, 1 << DDR_P1_LEFT}, + {0x00010000, 1 << DDR_P1_RIGHT}, + {0x00000400, 1 << DDR_P1_UP}, + {0x00001000, 1 << DDR_P1_DOWN}, + {0x00008000, 1 << DDR_P2_LEFT}, + {0x00020000, 1 << DDR_P2_RIGHT}, + {0x00000800, 1 << DDR_P2_UP}, + {0x00002000, 1 << DDR_P2_DOWN}, /* Nonstandard */ - { 0x01000000, 1 << DDR_P1_MENU_UP }, - { 0x04000000, 1 << DDR_P1_MENU_DOWN }, - { 0x02000000, 1 << DDR_P2_MENU_UP }, - { 0x08000000, 1 << DDR_P2_MENU_DOWN }, + {0x01000000, 1 << DDR_P1_MENU_UP}, + {0x04000000, 1 << DDR_P1_MENU_DOWN}, + {0x02000000, 1 << DDR_P2_MENU_UP}, + {0x08000000, 1 << DDR_P2_MENU_DOWN}, }; static const struct ddr_bittrans extio_light_map[] = { - { 0x00000100, 1 << LIGHT_P1_UP }, - { 0x00000200, 1 << LIGHT_P1_DOWN }, - { 0x00000400, 1 << LIGHT_P1_LEFT }, - { 0x00000800, 1 << LIGHT_P1_RIGHT }, - { 0x00010000, 1 << LIGHT_P2_UP }, - { 0x00020000, 1 << LIGHT_P2_DOWN }, - { 0x00040000, 1 << LIGHT_P2_LEFT }, - { 0x00080000, 1 << LIGHT_P2_RIGHT }, - { 0x01000000, 1 << LIGHT_NEONS }, + {0x00000100, 1 << LIGHT_P1_UP}, + {0x00000200, 1 << LIGHT_P1_DOWN}, + {0x00000400, 1 << LIGHT_P1_LEFT}, + {0x00000800, 1 << LIGHT_P1_RIGHT}, + {0x00010000, 1 << LIGHT_P2_UP}, + {0x00020000, 1 << LIGHT_P2_DOWN}, + {0x00040000, 1 << LIGHT_P2_LEFT}, + {0x00080000, 1 << LIGHT_P2_RIGHT}, + {0x01000000, 1 << LIGHT_NEONS}, }; static const struct ddr_bittrans p3io_light_map[] = { - { 0x00000004, 1 << LIGHT_P1_MENU }, - { 0x00000008, 1 << LIGHT_P2_MENU }, - { 0x00000010, 1 << LIGHT_P2_LOWER_LAMP }, - { 0x00000020, 1 << LIGHT_P2_UPPER_LAMP }, - { 0x00000040, 1 << LIGHT_P1_LOWER_LAMP }, - { 0x00000080, 1 << LIGHT_P1_UPPER_LAMP }, + {0x00000004, 1 << LIGHT_P1_MENU}, + {0x00000008, 1 << LIGHT_P2_MENU}, + {0x00000010, 1 << LIGHT_P2_LOWER_LAMP}, + {0x00000020, 1 << LIGHT_P2_UPPER_LAMP}, + {0x00000040, 1 << LIGHT_P1_LOWER_LAMP}, + {0x00000080, 1 << LIGHT_P1_UPPER_LAMP}, }; static bool initted; @@ -80,7 +80,7 @@ static int ddr_io_get_lag_param(void) args_recover(&argc, &argv); - for (i = 1 ; i < argc ; i++) { + for (i = 1; i < argc; i++) { if (argv[i][0] != '-') { continue; } @@ -101,8 +101,9 @@ static int ddr_io_get_lag_param(void) if (result < 0) { /* snark snark */ - log_warning("This PCB is incapable of seeing into the future. " - "Defaulting to 0 injected lag samples"); + log_warning( + "This PCB is incapable of seeing into the future. " + "Defaulting to 0 injected lag samples"); result = 0; } @@ -111,18 +112,18 @@ static int ddr_io_get_lag_param(void) } void ddr_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal) { log_to_external(misc, info, warning, fatal); } bool ddr_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy) + thread_create_t thread_create, + thread_join_t thread_join, + thread_destroy_t thread_destroy) { bool ok; @@ -153,7 +154,7 @@ uint32_t ddr_io_read_pad(void) mm_update(&out, &in); pad = 0; - for (i = 0 ; i < lengthof(input_map) ; i++) { + for (i = 0; i < lengthof(input_map); i++) { if (in.jamma & input_map[i].mm) { pad |= input_map[i].p3io; } @@ -173,7 +174,7 @@ void ddr_io_set_lights_extio(uint32_t extio_lights) clr = 0; set = 0; - for (i = 0 ; i < lengthof(extio_light_map) ; i++) { + for (i = 0; i < lengthof(extio_light_map); i++) { if (extio_lights & extio_light_map[i].p3io /* misnomer but w/e */) { set |= extio_light_map[i].mm; } else { @@ -194,7 +195,7 @@ void ddr_io_set_lights_p3io(uint32_t p3io_lights) clr = 0; set = 0; - for (i = 0 ; i < lengthof(p3io_light_map) ; i++) { + for (i = 0; i < lengthof(p3io_light_map); i++) { if (p3io_lights & p3io_light_map[i].p3io) { set |= p3io_light_map[i].mm; } else { @@ -214,4 +215,3 @@ void ddr_io_fini(void) initted = false; } } - diff --git a/src/main/ddrio-smx/ddrio.c b/src/main/ddrio-smx/ddrio.c index cd7d426..f909216 100644 --- a/src/main/ddrio-smx/ddrio.c +++ b/src/main/ddrio-smx/ddrio.c @@ -6,8 +6,8 @@ #include "bemanitools/ddrio.h" #include "bemanitools/input.h" -#include "imports/avs.h" #include "imports/SMX.h" +#include "imports/avs.h" #include "util/defs.h" #include "util/log.h" @@ -26,35 +26,33 @@ struct ddr_io_smx_light_map { unsigned char b; }; -static void ddr_io_smx_callback( - int pad_no, - enum SMXUpdateCallbackReason reason, - void *ctx); +static void +ddr_io_smx_callback(int pad_no, enum SMXUpdateCallbackReason reason, void *ctx); static const struct ddr_io_smx_pad_map ddr_io_smx_pad_map[] = { - { 0, 1 << 1, 1 << DDR_P1_UP }, - { 0, 1 << 3, 1 << DDR_P1_LEFT }, - { 0, 1 << 5, 1 << DDR_P1_RIGHT }, - { 0, 1 << 7, 1 << DDR_P1_DOWN }, + {0, 1 << 1, 1 << DDR_P1_UP}, + {0, 1 << 3, 1 << DDR_P1_LEFT}, + {0, 1 << 5, 1 << DDR_P1_RIGHT}, + {0, 1 << 7, 1 << DDR_P1_DOWN}, - { 1, 1 << 1, 1 << DDR_P2_UP }, - { 1, 1 << 3, 1 << DDR_P2_LEFT }, - { 1, 1 << 5, 1 << DDR_P2_RIGHT }, - { 1, 1 << 7, 1 << DDR_P2_DOWN }, + {1, 1 << 1, 1 << DDR_P2_UP}, + {1, 1 << 3, 1 << DDR_P2_LEFT}, + {1, 1 << 5, 1 << DDR_P2_RIGHT}, + {1, 1 << 7, 1 << DDR_P2_DOWN}, }; 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, 48 * 1, 0xFF, 0x00, 0x00 }, - { 1 << LIGHT_P1_LEFT, 48 * 3, 0x00, 0x00, 0xFF }, - { 1 << LIGHT_P1_RIGHT, 48 * 5, 0x00, 0x00, 0xFF }, - { 1 << LIGHT_P1_DOWN, 48 * 7, 0xFF, 0x00, 0x00 }, + {1 << LIGHT_P1_UP, 48 * 1, 0xFF, 0x00, 0x00}, + {1 << LIGHT_P1_LEFT, 48 * 3, 0x00, 0x00, 0xFF}, + {1 << LIGHT_P1_RIGHT, 48 * 5, 0x00, 0x00, 0xFF}, + {1 << LIGHT_P1_DOWN, 48 * 7, 0xFF, 0x00, 0x00}, - { 1 << LIGHT_P2_UP, 48 * 10, 0xFF, 0x00, 0x00 }, - { 1 << LIGHT_P2_LEFT, 48 * 12, 0x00, 0x00, 0xFF }, - { 1 << LIGHT_P2_RIGHT, 48 * 14, 0x00, 0x00, 0xFF }, - { 1 << LIGHT_P2_DOWN, 48 * 16, 0xFF, 0x00, 0x00 }, + {1 << LIGHT_P2_UP, 48 * 10, 0xFF, 0x00, 0x00}, + {1 << LIGHT_P2_LEFT, 48 * 12, 0x00, 0x00, 0xFF}, + {1 << LIGHT_P2_RIGHT, 48 * 14, 0x00, 0x00, 0xFF}, + {1 << LIGHT_P2_DOWN, 48 * 16, 0xFF, 0x00, 0x00}, }; static _Atomic uint32_t ddr_io_smx_pad_state[2]; @@ -63,10 +61,10 @@ static uint8_t ddr_io_smx_lights_counter; static char ddr_io_smx_lights[864]; void ddr_io_set_loggers( - log_formatter_t misc, - log_formatter_t info, - log_formatter_t warning, - log_formatter_t fatal) + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal) { log_to_external(misc, info, warning, fatal); input_set_loggers(misc, info, warning, fatal); @@ -77,9 +75,9 @@ void ddr_io_set_loggers( } bool ddr_io_init( - thread_create_t thread_create, - thread_join_t thread_join, - thread_destroy_t thread_destroy) + thread_create_t thread_create, + thread_join_t thread_join, + thread_destroy_t thread_destroy) { /* Use geninput for menu/operator btns */ @@ -129,9 +127,8 @@ uint32_t ddr_io_read_pad(void) /* We don't atomically read both pads, but they are separate USB devices so they don't update in lockstep anyway. */ - return mapper_update() | - atomic_load(&ddr_io_smx_pad_state[0]) | - atomic_load(&ddr_io_smx_pad_state[1]) ; + return mapper_update() | atomic_load(&ddr_io_smx_pad_state[0]) | + atomic_load(&ddr_io_smx_pad_state[1]); } void ddr_io_set_lights_extio(uint32_t lights) @@ -146,14 +143,14 @@ void ddr_io_set_lights_extio(uint32_t lights) ddr_io_smx_lights_counter = 0; memset(ddr_io_smx_lights, 0, sizeof(ddr_io_smx_lights)); - for (i = 0 ; i < lengthof(ddr_io_smx_light_map) ; i++) { + for (i = 0; i < lengthof(ddr_io_smx_light_map); i++) { map = &ddr_io_smx_light_map[i]; if (lights & map->extio_bit) { offset = map->smx_light_offset; - for (j = 0 ; j < 48 ; j += 3) { - ddr_io_smx_lights[offset + j ] = map->r; + for (j = 0; j < 48; j += 3) { + ddr_io_smx_lights[offset + j] = map->r; ddr_io_smx_lights[offset + j + 1] = map->g; ddr_io_smx_lights[offset + j + 2] = map->b; } @@ -182,10 +179,8 @@ void ddr_io_fini(void) input_fini(); } -static void ddr_io_smx_callback( - int pad_no, - enum SMXUpdateCallbackReason reason, - void *ctx) +static void +ddr_io_smx_callback(int pad_no, enum SMXUpdateCallbackReason reason, void *ctx) { const struct ddr_io_smx_pad_map *map; uint16_t smx_state; @@ -199,7 +194,7 @@ static void ddr_io_smx_callback( smx_state = SMX_GetInputState(pad_no); ddr_state = 0; - for (i = 0 ; i < lengthof(ddr_io_smx_pad_map) ; i++) { + for (i = 0; i < lengthof(ddr_io_smx_pad_map); i++) { map = &ddr_io_smx_pad_map[i]; if (pad_no == map->pad_no && (smx_state & map->smx_bit) != 0) { @@ -209,4 +204,3 @@ static void ddr_io_smx_callback( atomic_store(&ddr_io_smx_pad_state[pad_no], ddr_state); } - diff --git a/src/main/ddrio/ddrio.c b/src/main/ddrio/ddrio.c index a0c6721..b83e791 100644 --- a/src/main/ddrio/ddrio.c +++ b/src/main/ddrio/ddrio.c @@ -6,14 +6,19 @@ #include "util/log.h" -void ddr_io_set_loggers(log_formatter_t misc, log_formatter_t info, - log_formatter_t warning, log_formatter_t fatal) +void ddr_io_set_loggers( + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal) { input_set_loggers(misc, info, warning, fatal); } -bool ddr_io_init(thread_create_t thread_create, thread_join_t thread_join, - thread_destroy_t thread_destroy) +bool ddr_io_init( + thread_create_t thread_create, + thread_join_t thread_join, + thread_destroy_t thread_destroy) { input_init(thread_create, thread_join, thread_destroy); mapper_config_load("ddr"); @@ -56,4 +61,3 @@ void ddr_io_fini(void) { input_fini(); } - diff --git a/src/main/eamio-icca/eamio-icca.c b/src/main/eamio-icca/eamio-icca.c index 82a03ed..33f3827 100644 --- a/src/main/eamio-icca/eamio-icca.c +++ b/src/main/eamio-icca/eamio-icca.c @@ -1,5 +1,5 @@ -#include #include +#include #include #include @@ -12,35 +12,36 @@ #include "util/log.h" -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, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - EAM_IO_KEYPAD_0, - EAM_IO_KEYPAD_1, - EAM_IO_KEYPAD_4, - EAM_IO_KEYPAD_7, - EAM_IO_KEYPAD_00, - EAM_IO_KEYPAD_2, - EAM_IO_KEYPAD_5, - EAM_IO_KEYPAD_8 -}; +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, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + EAM_IO_KEYPAD_0, + EAM_IO_KEYPAD_1, + EAM_IO_KEYPAD_4, + EAM_IO_KEYPAD_7, + EAM_IO_KEYPAD_00, + EAM_IO_KEYPAD_2, + EAM_IO_KEYPAD_5, + EAM_IO_KEYPAD_8}; static struct ac_io_icca_state eam_io_icca_state[2]; -void eam_io_set_loggers(log_formatter_t misc, log_formatter_t info, - log_formatter_t warning, log_formatter_t fatal) +void eam_io_set_loggers( + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal) { log_to_external(misc, info, warning, fatal); } -bool eam_io_init(thread_create_t create, thread_join_t join, - thread_destroy_t destroy) +bool eam_io_init( + thread_create_t create, thread_join_t join, thread_destroy_t destroy) { if (!aciodrv_device_open("COM1", 57600)) { log_warning("Opening acio device on COM1 failed"); @@ -48,7 +49,6 @@ bool eam_io_init(thread_create_t create, thread_join_t join, } for (uint8_t i = 0; i < 2; i++) { - if (!aciodrv_icca_init(i)) { log_warning("Initializing icca %d failed", i); return false; @@ -83,11 +83,11 @@ uint8_t eam_io_get_sensor_state(uint8_t unit_no) uint8_t sensors = 0; if ((eam_io_icca_state[unit_no].sensor_state & - AC_IO_ICCA_SENSOR_MASK_BACK_ON) > 0) { + AC_IO_ICCA_SENSOR_MASK_BACK_ON) > 0) { sensors |= (1 << EAM_IO_SENSOR_BACK); } if ((eam_io_icca_state[unit_no].sensor_state & - AC_IO_ICCA_SENSOR_MASK_FRONT_ON) > 0) { + AC_IO_ICCA_SENSOR_MASK_FRONT_ON) > 0) { sensors |= (1 << EAM_IO_SENSOR_FRONT); } @@ -108,16 +108,16 @@ bool eam_io_card_slot_cmd(uint8_t unit_no, uint8_t cmd) { switch (cmd) { case EAM_IO_CARD_SLOT_CMD_CLOSE: - return aciodrv_icca_set_state(unit_no, - AC_IO_ICCA_SLOT_STATE_CLOSE, NULL); + return aciodrv_icca_set_state( + unit_no, AC_IO_ICCA_SLOT_STATE_CLOSE, NULL); case EAM_IO_CARD_SLOT_CMD_OPEN: - return aciodrv_icca_set_state(unit_no, - AC_IO_ICCA_SLOT_STATE_OPEN, NULL); + return aciodrv_icca_set_state( + unit_no, AC_IO_ICCA_SLOT_STATE_OPEN, NULL); case EAM_IO_CARD_SLOT_CMD_EJECT: - return aciodrv_icca_set_state(unit_no, - AC_IO_ICCA_SLOT_STATE_EJECT, NULL); + return aciodrv_icca_set_state( + unit_no, AC_IO_ICCA_SLOT_STATE_EJECT, NULL); case EAM_IO_CARD_SLOT_CMD_READ: return aciodrv_icca_read_card(unit_no, NULL) && @@ -144,4 +144,3 @@ BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, void *ctx) { return TRUE; } - diff --git a/src/main/eamio/eam-api.c b/src/main/eamio/eam-api.c index 648af44..532b160 100644 --- a/src/main/eamio/eam-api.c +++ b/src/main/eamio/eam-api.c @@ -1,5 +1,5 @@ -#include #include +#include #include #include @@ -17,8 +17,7 @@ #include "util/msg-thread.h" #include "util/thread.h" -static void eam_handle_hotplug_msg(WPARAM wparam, - const DEV_BROADCAST_HDR *hdr); +static void eam_handle_hotplug_msg(WPARAM wparam, const DEV_BROADCAST_HDR *hdr); static FILE *eam_io_config_open(const char *mode); static void eam_io_config_load(void); static void eam_io_config_save(void); @@ -35,25 +34,26 @@ static HANDLE eam_hinst; static struct eam *eam_inst; static const struct eam_io_config_api eam_io_config_api = { - .config_save = eam_io_config_save, - .get_autogen = eam_io_get_autogen, - .set_autogen = eam_io_set_autogen, - .get_alt_10k = eam_io_get_alt_10k, - .set_alt_10k = eam_io_set_alt_10k, - .get_keypad_device = eam_io_get_keypad_device, - .set_keypad_device = eam_io_set_keypad_device, - .get_card_path = eam_io_get_card_path, - .set_card_path = eam_io_set_card_path, + .config_save = eam_io_config_save, + .get_autogen = eam_io_get_autogen, + .set_autogen = eam_io_set_autogen, + .get_alt_10k = eam_io_get_alt_10k, + .set_alt_10k = eam_io_set_alt_10k, + .get_keypad_device = eam_io_get_keypad_device, + .set_keypad_device = eam_io_set_keypad_device, + .get_card_path = eam_io_get_card_path, + .set_card_path = eam_io_set_card_path, }; void msg_window_setup(HWND hwnd) { - log_info("Drive insertion listener ready, thread id = %d", - (int) GetCurrentThreadId()); + log_info( + "Drive insertion listener ready, thread id = %d", + (int) GetCurrentThreadId()); } -LRESULT WINAPI msg_window_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam) +LRESULT WINAPI +msg_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { switch (msg) { case WM_DEVICECHANGE: @@ -99,14 +99,17 @@ static FILE *eam_io_config_open(const char *mode) return fopen_appdata("DJHACKERS", "eam_v4_22.bin", mode); } -void eam_io_set_loggers(log_formatter_t misc, log_formatter_t info, - log_formatter_t warning, log_formatter_t fatal) +void eam_io_set_loggers( + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal) { log_to_external(misc, info, warning, fatal); } -bool eam_io_init(thread_create_t create, thread_join_t join, - thread_destroy_t destroy) +bool eam_io_init( + thread_create_t create, thread_join_t join, thread_destroy_t destroy) { input_init(create, join, destroy); thread_api_init(create, join, destroy); @@ -255,4 +258,3 @@ BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, void *ctx) return TRUE; } - diff --git a/src/main/eamio/eam-impl.c b/src/main/eamio/eam-impl.c index b4d8097..4ddb2c3 100644 --- a/src/main/eamio/eam-impl.c +++ b/src/main/eamio/eam-impl.c @@ -20,7 +20,7 @@ #include "util/mem.h" #include "util/str.h" -#define EAM_SENSOR_COOLDOWN 1000 +#define EAM_SENSOR_COOLDOWN 1000 struct eam_unit { char *card_path; @@ -50,7 +50,7 @@ static const uint32_t eam_keypad_usages[EAM_IO_KEYPAD_COUNT + 1] = { /* [EAM_KEYPAD_1] = */ 0x00070059, /* [EAM_KEYPAD_4] = */ 0x0007005C, /* [EAM_KEYPAD_7] = */ 0x0007005F, - /* [EAM_KEYPAD_00] = */ 0x00070058, /* Keypad ENTER */ + /* [EAM_KEYPAD_00] = */ 0x00070058, /* Keypad ENTER */ /* [EAM_KEYPAD_2] = */ 0x0007005A, /* [EAM_KEYPAD_5] = */ 0x0007005D, /* [EAM_KEYPAD_8] = */ 0x00070060, @@ -58,23 +58,22 @@ static const uint32_t eam_keypad_usages[EAM_IO_KEYPAD_COUNT + 1] = { /* [EAM_KEYPAD_3] = */ 0x0007005B, /* [EAM_KEYPAD_6] = */ 0x0007005E, /* [EAM_KEYPAD_9] = */ 0x00070061, - /* Sensor = */ 0x00070057 -}; + /* Sensor = */ 0x00070057}; static const uint32_t eam_keypad_usages_alt[EAM_IO_KEYPAD_COUNT + 1] = { /* [EAM_KEYPAD_0] = */ 0x00070027, /* [EAM_KEYPAD_1] = */ 0x0007001E, /* [EAM_KEYPAD_4] = */ 0x00070021, /* [EAM_KEYPAD_7] = */ 0x00070024, - /* [EAM_KEYPAD_00] = */ 0x0007002D, /* - and _ */ + /* [EAM_KEYPAD_00] = */ 0x0007002D, /* - and _ */ /* [EAM_KEYPAD_2] = */ 0x0007001F, /* [EAM_KEYPAD_5] = */ 0x00070022, /* [EAM_KEYPAD_8] = */ 0x00070025, - /* [EAM_KEYPAD_DECIMAL] = */ 0x0007002E, /* + and = */ + /* [EAM_KEYPAD_DECIMAL] = */ 0x0007002E, /* + and = */ /* [EAM_KEYPAD_3] = */ 0x00070020, /* [EAM_KEYPAD_6] = */ 0x00070023, /* [EAM_KEYPAD_9] = */ 0x00070026, - /* Sensor = */ 0x0007002A /* Backspace */ + /* Sensor = */ 0x0007002A /* Backspace */ }; static uint8_t eam_impl_get_active_unit(void); @@ -92,13 +91,13 @@ struct eam *eam_impl_create(void) InitializeCriticalSection(&eam->lock); - for (unit_no = 0 ; unit_no < lengthof(eam->units) ; unit_no++) { + for (unit_no = 0; unit_no < lengthof(eam->units); unit_no++) { unit = &eam->units[unit_no]; unit->card_path = NULL; unit->hid = NULL; - for (btn_no = 0 ; btn_no < lengthof(unit->keypad_ctls) ; btn_no++) { + for (btn_no = 0; btn_no < lengthof(unit->keypad_ctls); btn_no++) { unit->keypad_ctls[btn_no] = (size_t) -1; } @@ -139,7 +138,7 @@ void eam_impl_set_alt_10k(struct eam *eam, bool alt_10k) { int i; - for (i = 0 ; i < lengthof(eam->units) ; i++) { + for (i = 0; i < lengthof(eam->units); i++) { eam->units[i].bound_ctls = false; } @@ -153,8 +152,8 @@ struct hid_stub *eam_impl_get_keypad_device(struct eam *eam, uint8_t unit_no) return eam->units[unit_no].hid; } -void eam_impl_set_keypad_device(struct eam *eam, uint8_t unit_no, - struct hid_stub *hid) +void eam_impl_set_keypad_device( + struct eam *eam, uint8_t unit_no, struct hid_stub *hid) { log_assert(unit_no < lengthof(eam->units)); @@ -171,8 +170,7 @@ const char *eam_impl_get_card_path(struct eam *eam, uint8_t unit_no) return eam->units[unit_no].card_path; } -void eam_impl_set_card_path(struct eam *eam, uint8_t unit_no, - const char *path) +void eam_impl_set_card_path(struct eam *eam, uint8_t unit_no, const char *path) { log_assert(unit_no < lengthof(eam->units)); @@ -215,7 +213,7 @@ uint16_t eam_impl_get_keypad_state(struct eam *eam, uint8_t unit_no) result = 0; if (unit->bound_ctls) { - for (i = 0 ; i < lengthof(unit->keypad_ctls) ; i++) { + for (i = 0; i < lengthof(unit->keypad_ctls); i++) { if (unit->keypad_ctls[i] == (size_t) -1) { continue; } @@ -244,9 +242,8 @@ static void eam_impl_bind_keypad(struct eam *eam, uint8_t unit_no) unit = &eam->units[unit_no]; - if (unit->bound_ctls - || unit->hid == NULL - || !hid_stub_is_attached(unit->hid)) { + if (unit->bound_ctls || unit->hid == NULL || + !hid_stub_is_attached(unit->hid)) { return; } @@ -272,8 +269,8 @@ static void eam_impl_bind_keypad(struct eam *eam, uint8_t unit_no) goto content_fail; } - for (control_no = 0 ; control_no < ncontrols ; control_no++) { - for (btn_no = 0 ; btn_no < EAM_IO_KEYPAD_COUNT ; btn_no++) { + for (control_no = 0; control_no < ncontrols; control_no++) { + for (btn_no = 0; btn_no < EAM_IO_KEYPAD_COUNT; btn_no++) { if (controls[control_no].usage == usages[btn_no]) { unit->keypad_ctls[btn_no] = control_no; } @@ -336,7 +333,7 @@ bool eam_impl_get_sensor_state(struct eam *eam, uint8_t unit_no) } if (unit->sensor_hot) { - if ((int32_t) (unit->sensor_time - now) > 0) { + if ((int32_t)(unit->sensor_time - now) > 0) { result = true; } else { unit->sensor_time = 0; @@ -351,8 +348,8 @@ bool eam_impl_get_sensor_state(struct eam *eam, uint8_t unit_no) return result; } -uint8_t eam_impl_read_card(struct eam *eam, uint8_t unit_no, uint8_t *card_id, - uint8_t nbytes) +uint8_t eam_impl_read_card( + struct eam *eam, uint8_t unit_no, uint8_t *card_id, uint8_t nbytes) { char line[128]; struct eam_unit *unit; @@ -374,16 +371,20 @@ uint8_t eam_impl_read_card(struct eam *eam, uint8_t unit_no, uint8_t *card_id, if (f == NULL) { if (eam->autogen) { if (!eam_impl_autogen(unit, card_id)) { - log_warning("Unit %d: Failed to generate card ID into %s", - unit_no, unit->card_path); + log_warning( + "Unit %d: Failed to generate card ID into %s", + unit_no, + unit->card_path); goto fopen_fail; } return true; } else { - log_warning("Unit %d: Card file at %s not present", - unit_no, unit->card_path); + log_warning( + "Unit %d: Card file at %s not present", + unit_no, + unit->card_path); goto fopen_fail; } @@ -399,8 +400,11 @@ uint8_t eam_impl_read_card(struct eam *eam, uint8_t unit_no, uint8_t *card_id, len = strlen(line); if (len != 2 * EAM_CARD_NBYTES) { - log_warning("%s: Expected %u chars (got %u)", - unit->card_path, 2 * EAM_CARD_NBYTES, (unsigned int) len); + log_warning( + "%s: Expected %u chars (got %u)", + unit->card_path, + 2 * EAM_CARD_NBYTES, + (unsigned int) len); goto len_fail; } @@ -411,8 +415,11 @@ uint8_t eam_impl_read_card(struct eam *eam, uint8_t unit_no, uint8_t *card_id, goto decode_fail; } - log_misc("Unit %d: Loaded card ID [%s] from file %s", - unit_no, line, unit->card_path); + log_misc( + "Unit %d: Loaded card ID [%s] from file %s", + unit_no, + line, + unit->card_path); fclose(f); @@ -451,7 +458,7 @@ static bool eam_impl_autogen(struct eam_unit *unit, uint8_t *card_id) card_id[2] = 0x01; card_id[3] = 0x00; - for (i = 4 ; i < 8 ; i++) { + for (i = 4; i < 8; i++) { /* LSBit entropy of typical LFSR RNGs is usually poor */ card_id[i] = rand() >> 7; } @@ -461,8 +468,8 @@ static bool eam_impl_autogen(struct eam_unit *unit, uint8_t *card_id) fclose(f); - log_info("Generated random card ID [%s] into file %s", - hex, unit->card_path); + log_info( + "Generated random card ID [%s] into file %s", hex, unit->card_path); return true; } @@ -474,7 +481,7 @@ void eam_impl_notify_hotplug(struct eam *eam, uint8_t drive_no) EnterCriticalSection(&eam->lock); - for (unit_no = 0 ; unit_no < lengthof(eam->units) ; unit_no++) { + for (unit_no = 0; unit_no < lengthof(eam->units); unit_no++) { if (eam->units[unit_no].drive_no == drive_no) { /* MMSYSTEM timeGetTime() is overkill, we don't exactly need super accurate timestamps here. */ @@ -493,7 +500,7 @@ void eam_impl_destroy(struct eam *eam) { int8_t unit_no; - for (unit_no = lengthof(eam->units) - 1 ; unit_no >= 0 ; unit_no--) { + for (unit_no = lengthof(eam->units) - 1; unit_no >= 0; unit_no--) { free(eam->units[unit_no].card_path); } @@ -501,4 +508,3 @@ void eam_impl_destroy(struct eam *eam) free(eam); } - diff --git a/src/main/eamio/eam-impl.h b/src/main/eamio/eam-impl.h index 075aade..486314d 100644 --- a/src/main/eamio/eam-impl.h +++ b/src/main/eamio/eam-impl.h @@ -9,8 +9,8 @@ #include "geninput/hid-mgr.h" -#define EAM_CARD_NBYTES 8 -#define EAM_UNIT_COUNT 2 +#define EAM_CARD_NBYTES 8 +#define EAM_UNIT_COUNT 2 struct eam; @@ -20,15 +20,14 @@ void eam_impl_set_autogen(struct eam *eam, bool autogen); bool eam_impl_get_alt_10k(struct eam *eam); void eam_impl_set_alt_10k(struct eam *eam, bool alt_10k); struct hid_stub *eam_impl_get_keypad_device(struct eam *eam, uint8_t unit_no); -void eam_impl_set_keypad_device(struct eam *eam, uint8_t unit_no, - struct hid_stub *hid); +void eam_impl_set_keypad_device( + struct eam *eam, uint8_t unit_no, struct hid_stub *hid); const char *eam_impl_get_card_path(struct eam *eam, uint8_t unit_no); -void eam_impl_set_card_path(struct eam *eam, uint8_t unit_no, - const char *path); +void eam_impl_set_card_path(struct eam *eam, uint8_t unit_no, const char *path); uint16_t eam_impl_get_keypad_state(struct eam *eam, uint8_t unit_no); bool eam_impl_get_sensor_state(struct eam *eam, uint8_t unit_no); -uint8_t eam_impl_read_card(struct eam *eam, uint8_t unit_no, uint8_t *card_id, - uint8_t nbytes); +uint8_t eam_impl_read_card( + struct eam *eam, uint8_t unit_no, uint8_t *card_id, uint8_t nbytes); void eam_impl_notify_hotplug(struct eam *eam, uint8_t drive_no); void eam_impl_destroy(struct eam *eam); diff --git a/src/main/eamio/eam-s11n.c b/src/main/eamio/eam-s11n.c index a611db9..fd20e70 100644 --- a/src/main/eamio/eam-s11n.c +++ b/src/main/eamio/eam-s11n.c @@ -38,7 +38,7 @@ struct eam *eam_impl_config_load(FILE *f) hid_mgr_lock(); - for (unit_no = 0 ; unit_no < EAM_UNIT_COUNT ; unit_no++) { + for (unit_no = 0; unit_no < EAM_UNIT_COUNT; unit_no++) { if (!read_u8(f, &has_card_path)) { goto late_fail; } @@ -100,7 +100,7 @@ void eam_impl_config_save(struct eam *eam, FILE *f) write_u8(f, &alt_10k); write_u8(f, &nunits); - for (unit_no = 0 ; unit_no < EAM_UNIT_COUNT ; unit_no++) { + for (unit_no = 0; unit_no < EAM_UNIT_COUNT; unit_no++) { card_path = eam_impl_get_card_path(eam, unit_no); hid = eam_impl_get_keypad_device(eam, unit_no); @@ -119,4 +119,3 @@ void eam_impl_config_save(struct eam *eam, FILE *f) } } } - diff --git a/src/main/eamiotest/main.c b/src/main/eamiotest/main.c index 559e6bf..48dd211 100644 --- a/src/main/eamiotest/main.c +++ b/src/main/eamiotest/main.c @@ -1,6 +1,6 @@ -#include #include #include +#include #include #include @@ -13,10 +13,10 @@ /** * Tool to test your implementations of eamio. */ -int main(int argc, char** argv) +int main(int argc, char **argv) { - eam_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning, - log_impl_fatal); + eam_io_set_loggers( + log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); if (!eam_io_init(crt_thread_create, crt_thread_join, crt_thread_destroy)) { printf("Initializing eamio failed\n"); @@ -43,7 +43,6 @@ int main(int argc, char** argv) } for (uint8_t node = 0; node < 2; ++node) { - if (!eam_io_poll(node)) { printf("ERROR: Polling node %d failed", node); return -2; @@ -55,35 +54,41 @@ int main(int argc, char** argv) uint8_t sensors = eam_io_get_sensor_state(node); printf( - "Press escape to quit\n" - "Reader %d\n" - "------------------\n" - " |7: %d|8: %d|9: %d|\n" - " |4: %d|5: %d|6: %d|\n" - " |1: %d|2: %d|3: %d|\n" - " |0: %d|O: %d|_: %d|\n" - "------------------\n" - "|front: %d back: %d|\n" - "------------------\n" - "|%02X%02X%02X%02X%02X%02X%02X%02X|\n" - "------------------\n", - node, - (keypad & (1 << EAM_IO_KEYPAD_7)) > 0, - (keypad & (1 << EAM_IO_KEYPAD_8)) > 0, - (keypad & (1 << EAM_IO_KEYPAD_9)) > 0, - (keypad & (1 << EAM_IO_KEYPAD_4)) > 0, - (keypad & (1 << EAM_IO_KEYPAD_5)) > 0, - (keypad & (1 << EAM_IO_KEYPAD_6)) > 0, - (keypad & (1 << EAM_IO_KEYPAD_1)) > 0, - (keypad & (1 << EAM_IO_KEYPAD_2)) > 0, - (keypad & (1 << EAM_IO_KEYPAD_3)) > 0, - (keypad & (1 << EAM_IO_KEYPAD_0)) > 0, - (keypad & (1 << EAM_IO_KEYPAD_00)) > 0, - (keypad & (1 << EAM_IO_KEYPAD_DECIMAL)) > 0, - (sensors & (1 << EAM_IO_SENSOR_FRONT)) > 0, - (sensors & (1 << EAM_IO_SENSOR_BACK)) > 0, - card[node][0], card[node][1], card[node][2], card[node][3], - card[node][4], card[node][5], card[node][6], card[node][7]); + "Press escape to quit\n" + "Reader %d\n" + "------------------\n" + " |7: %d|8: %d|9: %d|\n" + " |4: %d|5: %d|6: %d|\n" + " |1: %d|2: %d|3: %d|\n" + " |0: %d|O: %d|_: %d|\n" + "------------------\n" + "|front: %d back: %d|\n" + "------------------\n" + "|%02X%02X%02X%02X%02X%02X%02X%02X|\n" + "------------------\n", + node, + (keypad & (1 << EAM_IO_KEYPAD_7)) > 0, + (keypad & (1 << EAM_IO_KEYPAD_8)) > 0, + (keypad & (1 << EAM_IO_KEYPAD_9)) > 0, + (keypad & (1 << EAM_IO_KEYPAD_4)) > 0, + (keypad & (1 << EAM_IO_KEYPAD_5)) > 0, + (keypad & (1 << EAM_IO_KEYPAD_6)) > 0, + (keypad & (1 << EAM_IO_KEYPAD_1)) > 0, + (keypad & (1 << EAM_IO_KEYPAD_2)) > 0, + (keypad & (1 << EAM_IO_KEYPAD_3)) > 0, + (keypad & (1 << EAM_IO_KEYPAD_0)) > 0, + (keypad & (1 << EAM_IO_KEYPAD_00)) > 0, + (keypad & (1 << EAM_IO_KEYPAD_DECIMAL)) > 0, + (sensors & (1 << EAM_IO_SENSOR_FRONT)) > 0, + (sensors & (1 << EAM_IO_SENSOR_BACK)) > 0, + card[node][0], + card[node][1], + card[node][2], + card[node][3], + card[node][4], + card[node][5], + card[node][6], + card[node][7]); if (sensors & (1 << EAM_IO_SENSOR_BACK)) { eam_io_card_slot_cmd(node, EAM_IO_CARD_SLOT_CMD_CLOSE); diff --git a/src/main/ezusb-emu/desc.c b/src/main/ezusb-emu/desc.c index 61ba229..f4ef050 100644 --- a/src/main/ezusb-emu/desc.c +++ b/src/main/ezusb-emu/desc.c @@ -1,16 +1,13 @@ #include "ezusb-emu/desc.h" const struct ezusb_emu_desc_device ezusb_emu_desc_device = { - .setupapi = { - .device_guid = { - 0xAE18AA60, - 0x7F6A, - 0x11D4, - { 0x97, 0xDD, 0x00, 0x01, 0x02, 0x29, 0xB9, 0x59 } - }, - .device_desc = "Cypress EZ-USB (2235) - EEPROM missing", - .device_path = "\\\\.\\Ezusb-0" - }, + .setupapi = + {.device_guid = {0xAE18AA60, + 0x7F6A, + 0x11D4, + {0x97, 0xDD, 0x00, 0x01, 0x02, 0x29, 0xB9, 0x59}}, + .device_desc = "Cypress EZ-USB (2235) - EEPROM missing", + .device_path = "\\\\.\\Ezusb-0"}, .vid = 0x0547, .pid = 0x2235, }; \ No newline at end of file diff --git a/src/main/ezusb-emu/device.c b/src/main/ezusb-emu/device.c index fb90308..b857716 100644 --- a/src/main/ezusb-emu/device.c +++ b/src/main/ezusb-emu/device.c @@ -1,8 +1,8 @@ #define LOG_MODULE "ezusb-emu-device" -#include #include #include +#include #include @@ -43,10 +43,10 @@ enum ezusb_pipe { }; static HANDLE ezusb_emu_fd; -static struct ezusb_firmware* ezusb_emu_firmware; -static struct ezusb_emu_msg_hook* ezusb_emu_dev_fx_msg_hook; +static struct ezusb_firmware *ezusb_emu_firmware; +static struct ezusb_emu_msg_hook *ezusb_emu_dev_fx_msg_hook; -void ezusb_emu_device_hook_init(struct ezusb_emu_msg_hook* msg_hook) +void ezusb_emu_device_hook_init(struct ezusb_emu_msg_hook *msg_hook) { log_assert(ezusb_emu_fd == NULL); @@ -63,7 +63,8 @@ void ezusb_emu_device_hook_fini(void) ezusb_emu_fd = NULL; } -HRESULT ezusb_emu_device_dispatch_irp(struct irp *irp) +HRESULT +ezusb_emu_device_dispatch_irp(struct irp *irp) { if (irp->op != IRP_OP_OPEN && irp->fd != ezusb_emu_fd) { return irp_invoke_next(irp); @@ -74,10 +75,14 @@ HRESULT ezusb_emu_device_dispatch_irp(struct irp *irp) CloseHandle calls and don't even log them). */ switch (irp->op) { - case IRP_OP_OPEN: return ezusb_open(irp); - case IRP_OP_CLOSE: return S_OK; - case IRP_OP_IOCTL: return ezusb_ioctl(irp); - default: return E_NOTIMPL; + case IRP_OP_OPEN: + return ezusb_open(irp); + case IRP_OP_CLOSE: + return S_OK; + case IRP_OP_IOCTL: + return ezusb_ioctl(irp); + default: + return E_NOTIMPL; } } @@ -103,8 +108,14 @@ static HRESULT ezusb_ioctl(struct irp *irp) /* For debugging */ #ifdef EZUSB_EMU_DEBUG_DUMP /* For debugging */ - ezusb_emu_util_log_usb_msg("BEFORE", irp->ioctl, irp->read.bytes, - irp->read.nbytes, irp->read.bytes, irp->read.nbytes, irp->write.bytes, + ezusb_emu_util_log_usb_msg( + "BEFORE", + irp->ioctl, + irp->read.bytes, + irp->read.nbytes, + irp->read.bytes, + irp->read.nbytes, + irp->write.bytes, irp->write.nbytes); #endif @@ -135,8 +146,14 @@ static HRESULT ezusb_ioctl(struct irp *irp) #ifdef EZUSB_EMU_DEBUG_DUMP /* For debugging */ - ezusb_emu_util_log_usb_msg("AFTER", irp->ioctl, irp->read.bytes, - irp->read.nbytes, irp->read.bytes, irp->read.nbytes, irp->write.bytes, + ezusb_emu_util_log_usb_msg( + "AFTER", + irp->ioctl, + irp->read.bytes, + irp->read.nbytes, + irp->read.bytes, + irp->read.nbytes, + irp->write.bytes, irp->write.nbytes); #endif } @@ -164,9 +181,9 @@ static HRESULT ezusb_get_device_descriptor(struct irp *irp) irp->read.pos = sizeof(*desc); log_misc( - "get_device_descriptor: vid %02x, pid %02x", - desc->idVendor, - desc->idProduct); + "get_device_descriptor: vid %02x, pid %02x", + desc->idVendor, + desc->idProduct); return S_OK; } @@ -186,15 +203,16 @@ static HRESULT ezusb_vendor_req(struct irp *irp) vc = (VENDOR_OR_CLASS_REQUEST_CONTROL *) irp->write.bytes; log_misc( - "vendor req %02x, value %04x, index %04x", - vc->request, - vc->value, - vc->index); + "vendor req %02x, value %04x, index %04x", + vc->request, + vc->value, + vc->index); if (vc->request == 0x00 && vc->value == 0x0001 && vc->index == 0x0100) { log_misc("vendor req: reset hold, starting fw download..."); ezusb_emu_firmware = ezusb_firmware_alloc(); - } else if (vc->request == 0x00 && vc->value == 0x0001 && vc->index == 0x0000) { + } else if ( + vc->request == 0x00 && vc->value == 0x0001 && vc->index == 0x0000) { log_misc("vendor req: reset release, finished fw download"); /* FW download finished, reset 8051 and start the downloaded FW */ @@ -235,12 +253,11 @@ static HRESULT ezusb_upload_fw(struct irp *irp) supposed to receive data, not send it! */ log_misc( - "upload_fw: offset: %04x, nbytes: %04x", - hdr->Offset, - irp->read.nbytes); - ezusb_firmware_add_segment(ezusb_emu_firmware, - ezusb_firmware_segment_alloc(hdr->Offset, irp->read.nbytes, - (void*) irp->read.bytes)); + "upload_fw: offset: %04x, nbytes: %04x", hdr->Offset, irp->read.nbytes); + ezusb_firmware_add_segment( + ezusb_emu_firmware, + ezusb_firmware_segment_alloc( + hdr->Offset, irp->read.nbytes, (void *) irp->read.bytes)); return S_OK; } @@ -260,16 +277,16 @@ static HRESULT ezusb_pipe_read(struct irp *irp) ctl = (BULK_TRANSFER_CONTROL *) irp->write.bytes; switch (ctl->pipeNum) { - case EZUSB_PIPE_INTERRUPT_IN: - return ezusb_emu_dev_fx_msg_hook->interrupt_read(&irp->read); + case EZUSB_PIPE_INTERRUPT_IN: + return ezusb_emu_dev_fx_msg_hook->interrupt_read(&irp->read); - case EZUSB_PIPE_BULK_IN: - return ezusb_emu_dev_fx_msg_hook->bulk_read(&irp->read); + case EZUSB_PIPE_BULK_IN: + return ezusb_emu_dev_fx_msg_hook->bulk_read(&irp->read); - default: - log_warning("No such read pipe: %u", (unsigned int) ctl->pipeNum); + default: + log_warning("No such read pipe: %u", (unsigned int) ctl->pipeNum); - return E_INVALIDARG; + return E_INVALIDARG; } } @@ -292,17 +309,15 @@ static HRESULT ezusb_pipe_write(struct irp *irp) write.pos = 0; switch (ctl->pipeNum) { - case EZUSB_PIPE_INTERRUPT_OUT: - return ezusb_emu_dev_fx_msg_hook->interrupt_write(&write); + case EZUSB_PIPE_INTERRUPT_OUT: + return ezusb_emu_dev_fx_msg_hook->interrupt_write(&write); - case EZUSB_PIPE_BULK_OUT: - return ezusb_emu_dev_fx_msg_hook->bulk_write(&write); + case EZUSB_PIPE_BULK_OUT: + return ezusb_emu_dev_fx_msg_hook->bulk_write(&write); - default: - log_warning("No such write pipe: %u", (unsigned int) ctl->pipeNum); + default: + log_warning("No such write pipe: %u", (unsigned int) ctl->pipeNum); - return E_INVALIDARG; + return E_INVALIDARG; } } - - diff --git a/src/main/ezusb-emu/device.h b/src/main/ezusb-emu/device.h index 224a6de..95dab57 100644 --- a/src/main/ezusb-emu/device.h +++ b/src/main/ezusb-emu/device.h @@ -3,21 +3,21 @@ #include -#include #include +#include #include "ezusb-emu/msg.h" #include "hook/iohook.h" /** - * Hook IO functions to intercept with ezusb (IIDX C02) communication and + * Hook IO functions to intercept with ezusb (IIDX C02) communication and * detour to our emulation code. - * - * @param msg_hook Hook functions to dispatch ezusb interrupt and bulk device + * + * @param msg_hook Hook functions to dispatch ezusb interrupt and bulk device * messages to */ -void ezusb_emu_device_hook_init(struct ezusb_emu_msg_hook* msg_hook); +void ezusb_emu_device_hook_init(struct ezusb_emu_msg_hook *msg_hook); /** * Cleanup the hooked IO functions. diff --git a/src/main/ezusb-emu/util.c b/src/main/ezusb-emu/util.c index dea0b72..6e2798a 100644 --- a/src/main/ezusb-emu/util.c +++ b/src/main/ezusb-emu/util.c @@ -2,8 +2,8 @@ #include -#include #include +#include #include #include "ezusb-emu/util.h" @@ -19,13 +19,19 @@ enum ezusb_pipe { EZUSB_PIPE_BULK_IN = 3 }; -void ezusb_emu_util_log_usb_msg(const char* prefix, uint32_t ctl_code, - const BULK_TRANSFER_CONTROL *ctl, uint32_t ctl_size, void* header, - uint32_t header_bytes, void* data, uint32_t data_bytes) +void ezusb_emu_util_log_usb_msg( + const char *prefix, + uint32_t ctl_code, + const BULK_TRANSFER_CONTROL *ctl, + uint32_t ctl_size, + void *header, + uint32_t header_bytes, + void *data, + uint32_t data_bytes) { char header_str[4096]; char data_str[4096]; - const char* ctl_code_str; + const char *ctl_code_str; switch (ctl_code) { case IOCTL_Ezusb_GET_DEVICE_DESCRIPTOR: @@ -70,6 +76,12 @@ void ezusb_emu_util_log_usb_msg(const char* prefix, uint32_t ctl_code, hex_encode_uc(header, header_bytes, header_str, sizeof(header_str)); hex_encode_uc(data, data_bytes, data_str, sizeof(data_str)); - log_warning("[EZUSB DUMP %s][%s] header(%d) %s |||| data(%d) %s", - prefix, ctl_code_str, header_bytes, header_str, data_bytes, data_str); + log_warning( + "[EZUSB DUMP %s][%s] header(%d) %s |||| data(%d) %s", + prefix, + ctl_code_str, + header_bytes, + header_str, + data_bytes, + data_str); } \ No newline at end of file diff --git a/src/main/ezusb-emu/util.h b/src/main/ezusb-emu/util.h index e6d5a93..035aa82 100644 --- a/src/main/ezusb-emu/util.h +++ b/src/main/ezusb-emu/util.h @@ -3,16 +3,22 @@ #include -#include #include #include +#include #include "ezusb/ezusbsys2.h" #include "hook/iohook.h" -void ezusb_emu_util_log_usb_msg(const char* prefix, uint32_t ctl_code, - const BULK_TRANSFER_CONTROL *ctl, uint32_t ctl_size, void* header, - uint32_t header_bytes, void* data, uint32_t data_bytes); +void ezusb_emu_util_log_usb_msg( + const char *prefix, + uint32_t ctl_code, + const BULK_TRANSFER_CONTROL *ctl, + uint32_t ctl_size, + void *header, + uint32_t header_bytes, + void *data, + uint32_t data_bytes); #endif diff --git a/src/main/ezusb-iidx-emu/card-mag.c b/src/main/ezusb-iidx-emu/card-mag.c index cef7fb6..a210fd6 100644 --- a/src/main/ezusb-iidx-emu/card-mag.c +++ b/src/main/ezusb-iidx-emu/card-mag.c @@ -8,59 +8,65 @@ #include "util/log.h" static const uint16_t ezusb_iidx_emu_card_mag_checksum_table_payload[256] = { - 0x0, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF, 0x8C48, 0x9DC1, 0x0AF5A, - 0x0BED3, 0x0CA6C, 0x0DBE5, 0x0E97E, 0x0F8F7, 0x1081, 0x108, 0x3393, 0x221A, 0x56A5, - 0x472C, 0x75B7, 0x643E, 0x9CC9, 0x8D40, 0x0BFDB, 0x0AE52, 0x0DAED, 0x0CB64, 0x0F9FF, - 0x0E876, 0x2102, 0x308B, 0x210, 0x1399, 0x6726, 0x76AF, 0x4434, 0x55BD, 0x0AD4A, - 0x0BCC3, 0x8E58, 0x9FD1, 0x0EB6E, 0x0FAE7, 0x0C87C, 0x0D9F5, 0x3183, 0x200A, - 0x1291, 0x318, 0x77A7, 0x662E, 0x54B5, 0x453C, 0x0BDCB, 0x0AC42, 0x9ED9, 0x8F50, - 0x0FBEF, 0x0EA66, 0x0D8FD, 0x0C974, 0x4204, 0x538D, 0x6116, 0x709F, 0x420, 0x15A9, - 0x2732, 0x36BB, 0x0CE4C, 0x0DFC5, 0x0ED5E, 0x0FCD7, 0x8868, 0x99E1, 0x0AB7A, - 0x0BAF3, 0x5285, 0x430C, 0x7197, 0x601E, 0x14A1, 0x528, 0x37B3, 0x263A, 0x0DECD, - 0x0CF44, 0x0FDDF, 0x0EC56, 0x98E9, 0x8960, 0x0BBFB, 0x0AA72, 0x6306, 0x728F, - 0x4014, 0x519D, 0x2522, 0x34AB, 0x630, 0x17B9, 0x0EF4E, 0x0FEC7, 0x0CC5C, 0x0DDD5, - 0x0A96A, 0x0B8E3, 0x8A78, 0x9BF1, 0x7387, 0x620E, 0x5095, 0x411C, 0x35A3, 0x242A, - 0x16B1, 0x738, 0x0FFCF, 0x0EE46, 0x0DCDD, 0x0CD54, 0x0B9EB, 0x0A862, 0x9AF9, - 0x8B70, 0x8408, 0x9581, 0x0A71A, 0x0B693, 0x0C22C, 0x0D3A5, 0x0E13E, 0x0F0B7, - 0x840, 0x19C9, 0x2B52, 0x3ADB, 0x4E64, 0x5FED, 0x6D76, 0x7CFF, 0x9489, 0x8500, - 0x0B79B, 0x0A612, 0x0D2AD, 0x0C324, 0x0F1BF, 0x0E036, 0x18C1, 0x948, 0x3BD3, - 0x2A5A, 0x5EE5, 0x4F6C, 0x7DF7, 0x6C7E, 0x0A50A, 0x0B483, 0x8618, 0x9791, 0x0E32E, - 0x0F2A7, 0x0C03C, 0x0D1B5, 0x2942, 0x38CB, 0x0A50, 0x1BD9, 0x6F66, 0x7EEF, 0x4C74, - 0x5DFD, 0x0B58B, 0x0A402, 0x9699, 0x8710, 0x0F3AF, 0x0E226, 0x0D0BD, 0x0C134, - 0x39C3, 0x284A, 0x1AD1, 0x0B58, 0x7FE7, 0x6E6E, 0x5CF5, 0x4D7C, 0x0C60C, 0x0D785, - 0x0E51E, 0x0F497, 0x8028, 0x91A1, 0x0A33A, 0x0B2B3, 0x4A44, 0x5BCD, 0x6956, 0x78DF, - 0x0C60, 0x1DE9, 0x2F72, 0x3EFB, 0x0D68D, 0x0C704, 0x0F59F, 0x0E416, 0x90A9, 0x8120, - 0x0B3BB, 0x0A232, 0x5AC5, 0x4B4C, 0x79D7, 0x685E, 0x1CE1, 0x0D68, 0x3FF3, 0x2E7A, - 0x0E70E, 0x0F687, 0x0C41C, 0x0D595, 0x0A12A, 0x0B0A3, 0x8238, 0x93B1, 0x6B46, - 0x7ACF, 0x4854, 0x59DD, 0x2D62, 0x3CEB, 0x0E70, 0x1FF9, 0x0F78F, 0x0E606, 0x0D49D, - 0x0C514, 0x0B1AB, 0x0A022, 0x92B9, 0x8330, 0x7BC7, 0x6A4E, 0x58D5, 0x495C, 0x3DE3, - 0x2C6A, 0x1EF1, 0x0F78 -}; + 0x0, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF, + 0x8C48, 0x9DC1, 0x0AF5A, 0x0BED3, 0x0CA6C, 0x0DBE5, 0x0E97E, 0x0F8F7, + 0x1081, 0x108, 0x3393, 0x221A, 0x56A5, 0x472C, 0x75B7, 0x643E, + 0x9CC9, 0x8D40, 0x0BFDB, 0x0AE52, 0x0DAED, 0x0CB64, 0x0F9FF, 0x0E876, + 0x2102, 0x308B, 0x210, 0x1399, 0x6726, 0x76AF, 0x4434, 0x55BD, + 0x0AD4A, 0x0BCC3, 0x8E58, 0x9FD1, 0x0EB6E, 0x0FAE7, 0x0C87C, 0x0D9F5, + 0x3183, 0x200A, 0x1291, 0x318, 0x77A7, 0x662E, 0x54B5, 0x453C, + 0x0BDCB, 0x0AC42, 0x9ED9, 0x8F50, 0x0FBEF, 0x0EA66, 0x0D8FD, 0x0C974, + 0x4204, 0x538D, 0x6116, 0x709F, 0x420, 0x15A9, 0x2732, 0x36BB, + 0x0CE4C, 0x0DFC5, 0x0ED5E, 0x0FCD7, 0x8868, 0x99E1, 0x0AB7A, 0x0BAF3, + 0x5285, 0x430C, 0x7197, 0x601E, 0x14A1, 0x528, 0x37B3, 0x263A, + 0x0DECD, 0x0CF44, 0x0FDDF, 0x0EC56, 0x98E9, 0x8960, 0x0BBFB, 0x0AA72, + 0x6306, 0x728F, 0x4014, 0x519D, 0x2522, 0x34AB, 0x630, 0x17B9, + 0x0EF4E, 0x0FEC7, 0x0CC5C, 0x0DDD5, 0x0A96A, 0x0B8E3, 0x8A78, 0x9BF1, + 0x7387, 0x620E, 0x5095, 0x411C, 0x35A3, 0x242A, 0x16B1, 0x738, + 0x0FFCF, 0x0EE46, 0x0DCDD, 0x0CD54, 0x0B9EB, 0x0A862, 0x9AF9, 0x8B70, + 0x8408, 0x9581, 0x0A71A, 0x0B693, 0x0C22C, 0x0D3A5, 0x0E13E, 0x0F0B7, + 0x840, 0x19C9, 0x2B52, 0x3ADB, 0x4E64, 0x5FED, 0x6D76, 0x7CFF, + 0x9489, 0x8500, 0x0B79B, 0x0A612, 0x0D2AD, 0x0C324, 0x0F1BF, 0x0E036, + 0x18C1, 0x948, 0x3BD3, 0x2A5A, 0x5EE5, 0x4F6C, 0x7DF7, 0x6C7E, + 0x0A50A, 0x0B483, 0x8618, 0x9791, 0x0E32E, 0x0F2A7, 0x0C03C, 0x0D1B5, + 0x2942, 0x38CB, 0x0A50, 0x1BD9, 0x6F66, 0x7EEF, 0x4C74, 0x5DFD, + 0x0B58B, 0x0A402, 0x9699, 0x8710, 0x0F3AF, 0x0E226, 0x0D0BD, 0x0C134, + 0x39C3, 0x284A, 0x1AD1, 0x0B58, 0x7FE7, 0x6E6E, 0x5CF5, 0x4D7C, + 0x0C60C, 0x0D785, 0x0E51E, 0x0F497, 0x8028, 0x91A1, 0x0A33A, 0x0B2B3, + 0x4A44, 0x5BCD, 0x6956, 0x78DF, 0x0C60, 0x1DE9, 0x2F72, 0x3EFB, + 0x0D68D, 0x0C704, 0x0F59F, 0x0E416, 0x90A9, 0x8120, 0x0B3BB, 0x0A232, + 0x5AC5, 0x4B4C, 0x79D7, 0x685E, 0x1CE1, 0x0D68, 0x3FF3, 0x2E7A, + 0x0E70E, 0x0F687, 0x0C41C, 0x0D595, 0x0A12A, 0x0B0A3, 0x8238, 0x93B1, + 0x6B46, 0x7ACF, 0x4854, 0x59DD, 0x2D62, 0x3CEB, 0x0E70, 0x1FF9, + 0x0F78F, 0x0E606, 0x0D49D, 0x0C514, 0x0B1AB, 0x0A022, 0x92B9, 0x8330, + 0x7BC7, 0x6A4E, 0x58D5, 0x495C, 0x3DE3, 0x2C6A, 0x1EF1, 0x0F78}; /* ------------------------------------------------------------------ */ -// static void target_form_8_digit_to_long(const uint8_t* in_buf, uint8_t* out_buf) +// static void target_form_8_digit_to_long(const uint8_t* in_buf, uint8_t* +// out_buf) // { // out_buf[0] = (in_buf[0] & 0x3F) + 0x20; // out_buf[1] = ((in_buf[1] >> 2) & 0x3F) + 0x20; -// out_buf[2] = (((in_buf[1] & 0x03) << 4) | ((in_buf[2] >> 4) & 0x0F)) + 0x20; +// out_buf[2] = (((in_buf[1] & 0x03) << 4) | ((in_buf[2] >> 4) & 0x0F)) + +// 0x20; // } static void ezusb_iidx_emu_card_mag_target_form_8_digit_to_short( - const uint8_t* in_buf, uint8_t* out_buf) + const uint8_t *in_buf, uint8_t *out_buf) { out_buf[0] = (out_buf[0] & 0xC0) | ((in_buf[0] - 0x20) & 0x3F); - out_buf[1] = (((in_buf[1] - 0x20) & 0x3F) << 2) | - (((in_buf[2] - 0x20) >> 4) & 0x03); + out_buf[1] = + (((in_buf[1] - 0x20) & 0x3F) << 2) | (((in_buf[2] - 0x20) >> 4) & 0x03); out_buf[2] = (((in_buf[2] - 0x20) & 0x0F) << 4) | (out_buf[2] & 0x0F); } static uint16_t ezusb_iidx_emu_card_mag_calc_checksum_payload( - const uint8_t* buffer, size_t length) + const uint8_t *buffer, size_t length) { unsigned int result; // eax@1 int v3; // esi@2 - const uint8_t* v4; // ecx@2 + const uint8_t *v4; // ecx@2 result = 0xFFFF; @@ -68,8 +74,9 @@ static uint16_t ezusb_iidx_emu_card_mag_calc_checksum_payload( v4 = buffer; do { - result = ezusb_iidx_emu_card_mag_checksum_table_payload[*v4++ ^ - (unsigned __int8) result] ^ (result >> 8); + result = ezusb_iidx_emu_card_mag_checksum_table_payload + [*v4++ ^ (unsigned __int8) result] ^ + (result >> 8); --v3; } while (v3); @@ -77,7 +84,7 @@ static uint16_t ezusb_iidx_emu_card_mag_calc_checksum_payload( } static void ezusb_iidx_emu_card_mag_update_checksums( - struct ezusb_iidx_emu_card_mag_data* card, const char* card_version) + struct ezusb_iidx_emu_card_mag_data *card, const char *card_version) { /* at least the header checksum and the checksums for the data sectors are the same for all games...*/ @@ -88,35 +95,46 @@ static void ezusb_iidx_emu_card_mag_update_checksums( /* checksum the actual payload of the payload */ for (uint8_t i = 0; i < MAG_CARD_NUM_DATA_SECTORS; i++) { /* seed is hardcoded to 0 */ - card->data_sector[i].checksum = crc8( - (uint8_t*) &card->data_sector[i], 9, 0); + card->data_sector[i].checksum = + crc8((uint8_t *) &card->data_sector[i], 9, 0); } /* but the checksum for all data sectors differs... */ - if ( !memcmp(card_version, SECURITY_MCODE_GAME_IIDX_9, - SECURITY_MCODE_GAME_LEN) || - !memcmp(card_version, SECURITY_MCODE_GAME_IIDX_11, - SECURITY_MCODE_GAME_LEN) || - !memcmp(card_version, SECURITY_MCODE_GAME_IIDX_12, - SECURITY_MCODE_GAME_LEN) ) { + if (!memcmp( + card_version, + SECURITY_MCODE_GAME_IIDX_9, + SECURITY_MCODE_GAME_LEN) || + !memcmp( + card_version, + SECURITY_MCODE_GAME_IIDX_11, + SECURITY_MCODE_GAME_LEN) || + !memcmp( + card_version, + SECURITY_MCODE_GAME_IIDX_12, + SECURITY_MCODE_GAME_LEN)) { /* checksum the whole payload with the unused part (padding) big endian or mistake by konami dev... */ - uint16_t crc = crc16((const uint8_t*) &card->data_sector[0], - MAG_CARD_NUM_DATA_SECTORS * 10 + sizeof(card->padding), 0); - uint16_t* ptr = (uint16_t*) card->checksum; + uint16_t crc = crc16( + (const uint8_t *) &card->data_sector[0], + MAG_CARD_NUM_DATA_SECTORS * 10 + sizeof(card->padding), + 0); + uint16_t *ptr = (uint16_t *) card->checksum; *ptr = crc; } else { /* 10th style */ - uint16_t* ptr = (uint16_t*) card->checksum; + uint16_t *ptr = (uint16_t *) card->checksum; *ptr = ezusb_iidx_emu_card_mag_calc_checksum_payload( - (const uint8_t*) &card->data_sector[0], + (const uint8_t *) &card->data_sector[0], MAG_CARD_NUM_DATA_SECTORS * 10 + sizeof(card->padding)); } } void ezusb_iidx_emu_card_mag_generate_data( - struct ezusb_iidx_emu_card_mag_data* card, uint8_t* card_id, - uint8_t card_type, bool card_used, const char* card_version) + struct ezusb_iidx_emu_card_mag_data *card, + uint8_t *card_id, + uint8_t card_type, + bool card_used, + const char *card_version) { memset(card, 0, sizeof(struct ezusb_iidx_emu_card_mag_data)); @@ -140,7 +158,7 @@ void ezusb_iidx_emu_card_mag_generate_data( card->header.card_version[2] = 1; ezusb_iidx_emu_card_mag_target_form_8_digit_to_short( - (const uint8_t*) card_version, card->header.card_version); + (const uint8_t *) card_version, card->header.card_version); if (card_used) { /* the first one is checked if the card is already formated @@ -150,7 +168,7 @@ void ezusb_iidx_emu_card_mag_generate_data( a specific game version, but a generic eamuse card don't use this, because it will interfere on 9th style on the card check */ - //card->header.flags |= (1 << 7); + // card->header.flags |= (1 << 7); } else { card->header.flags &= ~(1 << 6); card->header.flags &= ~(1 << 7); @@ -159,8 +177,9 @@ void ezusb_iidx_emu_card_mag_generate_data( /* the game flips this back to little endian so we have to give it big endian ordering here */ for (uint8_t i = 0; i < MAG_CARD_NUM_DATA_SECTORS; i++) { - - if (!memcmp(card_version, SECURITY_MCODE_GAME_IIDX_9, + if (!memcmp( + card_version, + SECURITY_MCODE_GAME_IIDX_9, SECURITY_MCODE_GAME_LEN)) { memcpy(card->data_sector_9th[i].card_id, card_id, 8); card->data_sector_9th[i].card_type = card_type; @@ -168,7 +187,6 @@ void ezusb_iidx_emu_card_mag_generate_data( memcpy(card->data_sector[i].card_id, card_id, 8); card->data_sector[i].card_type = card_type; } - } ezusb_iidx_emu_card_mag_update_checksums(card, card_version); diff --git a/src/main/ezusb-iidx-emu/card-mag.h b/src/main/ezusb-iidx-emu/card-mag.h index ad9b98c..caceac6 100644 --- a/src/main/ezusb-iidx-emu/card-mag.h +++ b/src/main/ezusb-iidx-emu/card-mag.h @@ -1,8 +1,8 @@ #ifndef EZUSB_IIDX_EMU_CARD_MAG_H #define EZUSB_IIDX_EMU_CARD_MAG_H -#include #include +#include #define MAG_CARD_NUM_DATA_SECTORS 5 @@ -65,7 +65,10 @@ struct ezusb_iidx_emu_card_mag_data { * @see struct magnetic_card */ void ezusb_iidx_emu_card_mag_generate_data( - struct ezusb_iidx_emu_card_mag_data* card, uint8_t* card_id, - uint8_t card_type, bool card_used, const char* card_version); + struct ezusb_iidx_emu_card_mag_data *card, + uint8_t *card_id, + uint8_t card_type, + bool card_used, + const char *card_version); #endif diff --git a/src/main/ezusb-iidx-emu/msg.c b/src/main/ezusb-iidx-emu/msg.c index 442b8b2..c7dafcb 100644 --- a/src/main/ezusb-iidx-emu/msg.c +++ b/src/main/ezusb-iidx-emu/msg.c @@ -13,9 +13,9 @@ #include "ezusb-iidx/msg.h" #include "ezusb-iidx-emu/msg.h" -#include "ezusb-iidx-emu/nodes.h" #include "ezusb-iidx-emu/node-coin.h" #include "ezusb-iidx-emu/node-serial.h" +#include "ezusb-iidx-emu/nodes.h" #include "util/hex.h" #include "util/log.h" @@ -33,13 +33,11 @@ static struct ezusb_emu_msg_hook ezusb_iidx_emu_msg_hook = { .interrupt_read = ezusb_iidx_emu_msg_interrupt_read, .interrupt_write = ezusb_iidx_emu_msg_interrupt_write, .bulk_read = ezusb_iidx_emu_msg_bulk_read, - .bulk_write = ezusb_iidx_emu_msg_bulk_write -}; + .bulk_write = ezusb_iidx_emu_msg_bulk_write}; /* ------------------------------------------------------------------------ */ -static const struct ezusb_iidx_emu_node* ezusb_iidx_emu_msg_nodes[256] = -{ +static const struct ezusb_iidx_emu_node *ezusb_iidx_emu_msg_nodes[256] = { [EZUSB_IIDX_MSG_NODE_16SEG] = &ezusb_iidx_emu_node_16seg, [EZUSB_IIDX_MSG_NODE_COIN] = &ezusb_iidx_emu_node_coin, [EZUSB_IIDX_MSG_NODE_EEPROM] = &ezusb_iidx_emu_node_eeprom_v1, @@ -52,8 +50,7 @@ static const struct ezusb_iidx_emu_node* ezusb_iidx_emu_msg_nodes[256] = [EZUSB_IIDX_MSG_NODE_WDT] = &ezusb_iidx_emu_node_wdt, }; -static const struct ezusb_iidx_emu_node* ezusb_iidx_emu_msg_v2_nodes[256] = -{ +static const struct ezusb_iidx_emu_node *ezusb_iidx_emu_msg_v2_nodes[256] = { [EZUSB_IIDX_MSG_NODE_16SEG] = &ezusb_iidx_emu_node_16seg, [EZUSB_IIDX_MSG_NODE_COIN] = &ezusb_iidx_emu_node_coin, [EZUSB_IIDX_MSG_NODE_EEPROM] = &ezusb_iidx_emu_node_eeprom_v2, @@ -65,21 +62,20 @@ static const struct ezusb_iidx_emu_node* ezusb_iidx_emu_msg_v2_nodes[256] = [EZUSB_IIDX_MSG_NODE_WDT] = &ezusb_iidx_emu_node_wdt, }; -static const struct ezusb_iidx_emu_node** ezusb_iidx_emu_node_handler; +static const struct ezusb_iidx_emu_node **ezusb_iidx_emu_node_handler; static uint8_t ezusb_iidx_emu_msg_status = 0; static uint8_t ezusb_iidx_emu_msg_seq_no = 0; static uint8_t ezusb_iidx_emu_msg_read_cur_node = 0; /* ------------------------------------------------------------------------ */ -struct ezusb_emu_msg_hook* ezusb_iidx_emu_msg_init(void) +struct ezusb_emu_msg_hook *ezusb_iidx_emu_msg_init(void) { /* Init all nodes */ for (uint32_t i = 0; i < 256; i++) { - /* "Constructor" optional */ if (ezusb_iidx_emu_msg_nodes[i] && - ezusb_iidx_emu_msg_nodes[i]->init_node) { + ezusb_iidx_emu_msg_nodes[i]->init_node) { ezusb_iidx_emu_msg_nodes[i]->init_node(); } } @@ -89,14 +85,13 @@ struct ezusb_emu_msg_hook* ezusb_iidx_emu_msg_init(void) return &ezusb_iidx_emu_msg_hook; } -struct ezusb_emu_msg_hook* ezusb_iidx_emu_msg_v2_init(void) +struct ezusb_emu_msg_hook *ezusb_iidx_emu_msg_v2_init(void) { /* Init all nodes */ for (uint32_t i = 0; i < 256; i++) { - /* "Constructor" optional */ if (ezusb_iidx_emu_msg_v2_nodes[i] && - ezusb_iidx_emu_msg_v2_nodes[i]->init_node) { + ezusb_iidx_emu_msg_v2_nodes[i]->init_node) { ezusb_iidx_emu_msg_v2_nodes[i]->init_node(); } } @@ -108,8 +103,8 @@ struct ezusb_emu_msg_hook* ezusb_iidx_emu_msg_v2_init(void) static HRESULT ezusb_iidx_emu_msg_interrupt_read(struct iobuf *read) { - struct ezusb_iidx_msg_interrupt_read_packet* msg_resp = - (struct ezusb_iidx_msg_interrupt_read_packet*) read->bytes; + struct ezusb_iidx_msg_interrupt_read_packet *msg_resp = + (struct ezusb_iidx_msg_interrupt_read_packet *) read->bytes; if (!iidx_io_ep2_recv()) { return E_FAIL; @@ -118,13 +113,13 @@ static HRESULT ezusb_iidx_emu_msg_interrupt_read(struct iobuf *read) msg_resp->p1_turntable = iidx_io_ep2_get_turntable(0); msg_resp->p2_turntable = iidx_io_ep2_get_turntable(1); - msg_resp->sliders[0] = iidx_io_ep2_get_slider(0) | - (iidx_io_ep2_get_slider(1) << 4); + msg_resp->sliders[0] = + iidx_io_ep2_get_slider(0) | (iidx_io_ep2_get_slider(1) << 4); - msg_resp->sliders[1] = iidx_io_ep2_get_slider(2) | - (iidx_io_ep2_get_slider(3) << 4); + msg_resp->sliders[1] = + iidx_io_ep2_get_slider(2) | (iidx_io_ep2_get_slider(3) << 4); - msg_resp->sliders[2] = iidx_io_ep2_get_slider(4); + msg_resp->sliders[2] = iidx_io_ep2_get_slider(4); msg_resp->inverted_pad = ((iidx_io_ep2_get_keys() & 0x3FFF) << 8) | ((iidx_io_ep2_get_panel() & 0x0F) << 24) | @@ -172,8 +167,8 @@ static HRESULT ezusb_iidx_emu_msg_interrupt_read(struct iobuf *read) static HRESULT ezusb_iidx_emu_msg_interrupt_write(struct const_iobuf *write) { - const struct ezusb_iidx_msg_interrupt_write_packet* msg_req = - (const struct ezusb_iidx_msg_interrupt_write_packet*) write->bytes; + const struct ezusb_iidx_msg_interrupt_write_packet *msg_req = + (const struct ezusb_iidx_msg_interrupt_write_packet *) write->bytes; if (write->nbytes < sizeof(*msg_req)) { log_warning("Interrupt write message too small"); @@ -192,25 +187,25 @@ static HRESULT ezusb_iidx_emu_msg_interrupt_write(struct const_iobuf *write) if (!ezusb_iidx_emu_node_handler[msg_req->node]) { ezusb_iidx_emu_msg_read_cur_node = 0; - log_warning("Unrecognised node in interrupt message: %02x", - msg_req->node); + log_warning( + "Unrecognised node in interrupt message: %02x", msg_req->node); return E_INVALIDARG; } /* Remember node for next bulk read */ ezusb_iidx_emu_msg_read_cur_node = msg_req->node; - ezusb_iidx_emu_msg_status = ezusb_iidx_emu_node_handler[msg_req->node]-> - process_cmd(msg_req->cmd, msg_req->cmd_detail[0], - msg_req->cmd_detail[1]); + ezusb_iidx_emu_msg_status = + ezusb_iidx_emu_node_handler[msg_req->node]->process_cmd( + msg_req->cmd, msg_req->cmd_detail[0], msg_req->cmd_detail[1]); return S_OK; } static HRESULT ezusb_iidx_emu_msg_bulk_read(struct iobuf *read) { - struct ezusb_iidx_msg_bulk_packet* pkt = - (struct ezusb_iidx_msg_bulk_packet*) read->bytes; + struct ezusb_iidx_msg_bulk_packet *pkt = + (struct ezusb_iidx_msg_bulk_packet *) read->bytes; if (read->nbytes < sizeof(*pkt)) { log_warning("Bulk read buffer too small"); @@ -220,14 +215,14 @@ static HRESULT ezusb_iidx_emu_msg_bulk_read(struct iobuf *read) if (!ezusb_iidx_emu_node_handler[ezusb_iidx_emu_msg_read_cur_node]) { log_warning( - "Bulk read unsupported on cur_node = %d", - ezusb_iidx_emu_msg_read_cur_node); + "Bulk read unsupported on cur_node = %d", + ezusb_iidx_emu_msg_read_cur_node); return E_FAIL; } - if (!ezusb_iidx_emu_node_handler[ezusb_iidx_emu_msg_read_cur_node]-> - read_packet(pkt)) { + if (!ezusb_iidx_emu_node_handler[ezusb_iidx_emu_msg_read_cur_node] + ->read_packet(pkt)) { return E_FAIL; } @@ -238,8 +233,8 @@ static HRESULT ezusb_iidx_emu_msg_bulk_read(struct iobuf *read) static HRESULT ezusb_iidx_emu_msg_bulk_write(struct const_iobuf *write) { - const struct ezusb_iidx_msg_bulk_packet* pkt = - (const struct ezusb_iidx_msg_bulk_packet*) write->bytes; + const struct ezusb_iidx_msg_bulk_packet *pkt = + (const struct ezusb_iidx_msg_bulk_packet *) write->bytes; if (write->nbytes < sizeof(*pkt)) { log_warning("Bulk write packet too small"); diff --git a/src/main/ezusb-iidx-emu/msg.h b/src/main/ezusb-iidx-emu/msg.h index deec155..83d2bd6 100644 --- a/src/main/ezusb-iidx-emu/msg.h +++ b/src/main/ezusb-iidx-emu/msg.h @@ -9,25 +9,25 @@ #include "ezusb-emu/msg.h" /** - * Init the fully emulated IIDX msg backend for a EZUSB (C02) board. This + * Init the fully emulated IIDX msg backend for a EZUSB (C02) board. This * activates the "old" V1 node handling backend which was used on iidx 09 to 13. * On iidx14, the firmware was updated and removed nodes that were not used * anymore, e.g. serial card reader handling. - * - * @return ezusb_emu_msg_hook structure with hook calls for ezusb msg + * + * @return ezusb_emu_msg_hook structure with hook calls for ezusb msg * dispatching */ -struct ezusb_emu_msg_hook* ezusb_iidx_emu_msg_init(void); +struct ezusb_emu_msg_hook *ezusb_iidx_emu_msg_init(void); /** - * Init the fully emulated IIDX msg backend for a EZUSB (C02) board. This + * Init the fully emulated IIDX msg backend for a EZUSB (C02) board. This * activates the "newer" V2 node handling backend which was used from iidx 14 * onwards. The firmware was updated and removed nodes that were not used * anymore, e.g. serial card reader handling. - * - * @return ezusb_emu_msg_hook structure with hook calls for ezusb msg + * + * @return ezusb_emu_msg_hook structure with hook calls for ezusb msg * dispatching */ -struct ezusb_emu_msg_hook* ezusb_iidx_emu_msg_v2_init(void); +struct ezusb_emu_msg_hook *ezusb_iidx_emu_msg_v2_init(void); #endif diff --git a/src/main/ezusb-iidx-emu/node-16seg.c b/src/main/ezusb-iidx-emu/node-16seg.c index bc6b51a..64cf4b4 100644 --- a/src/main/ezusb-iidx-emu/node-16seg.c +++ b/src/main/ezusb-iidx-emu/node-16seg.c @@ -10,11 +10,10 @@ #include "util/log.h" -uint8_t ezusb_iidx_emu_node_16seg_process_cmd(uint8_t cmd_id, uint8_t cmd_data, - uint8_t cmd_data2) +uint8_t ezusb_iidx_emu_node_16seg_process_cmd( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2) { - switch (cmd_id) - { + switch (cmd_id) { case EZUSB_IIDX_16SEG_CMD_WRITE: return EZUSB_IIDX_16SEG_CMD_STATUS_OK; @@ -24,13 +23,15 @@ uint8_t ezusb_iidx_emu_node_16seg_process_cmd(uint8_t cmd_id, uint8_t cmd_data, } } -bool ezusb_iidx_emu_node_16seg_read_packet(struct ezusb_iidx_msg_bulk_packet* pkg) +bool ezusb_iidx_emu_node_16seg_read_packet( + struct ezusb_iidx_msg_bulk_packet *pkg) { log_fatal("Read packet not supported on 16seg node"); return false; } -bool ezusb_iidx_emu_node_16seg_write_packet(const struct ezusb_iidx_msg_bulk_packet* pkg) +bool ezusb_iidx_emu_node_16seg_write_packet( + const struct ezusb_iidx_msg_bulk_packet *pkg) { char _16seg[10]; diff --git a/src/main/ezusb-iidx-emu/node-16seg.h b/src/main/ezusb-iidx-emu/node-16seg.h index 2586c25..ea128c8 100644 --- a/src/main/ezusb-iidx-emu/node-16seg.h +++ b/src/main/ezusb-iidx-emu/node-16seg.h @@ -3,11 +3,13 @@ #include "ezusb-iidx-emu/node.h" -uint8_t ezusb_iidx_emu_node_16seg_process_cmd(uint8_t cmd_id, uint8_t cmd_data, - uint8_t cmd_data2); +uint8_t ezusb_iidx_emu_node_16seg_process_cmd( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2); -bool ezusb_iidx_emu_node_16seg_read_packet(struct ezusb_iidx_msg_bulk_packet* pkg); +bool ezusb_iidx_emu_node_16seg_read_packet( + struct ezusb_iidx_msg_bulk_packet *pkg); -bool ezusb_iidx_emu_node_16seg_write_packet(const struct ezusb_iidx_msg_bulk_packet* pkg); +bool ezusb_iidx_emu_node_16seg_write_packet( + const struct ezusb_iidx_msg_bulk_packet *pkg); #endif \ No newline at end of file diff --git a/src/main/ezusb-iidx-emu/node-coin.c b/src/main/ezusb-iidx-emu/node-coin.c index c42d3fb..b6c1fcc 100644 --- a/src/main/ezusb-iidx-emu/node-coin.c +++ b/src/main/ezusb-iidx-emu/node-coin.c @@ -8,8 +8,8 @@ static uint8_t ezusb_iidx_emu_node_coin_mode = 0; -uint8_t ezusb_iidx_emu_node_coin_process_cmd(uint8_t cmd_id, uint8_t cmd_data, - uint8_t cmd_data2) +uint8_t ezusb_iidx_emu_node_coin_process_cmd( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2) { switch (cmd_id) { case EZUSB_IIDX_COIN_CMD_SET_COIN_MODE_1: @@ -26,13 +26,15 @@ uint8_t ezusb_iidx_emu_node_coin_process_cmd(uint8_t cmd_id, uint8_t cmd_data, } } -bool ezusb_iidx_emu_node_coin_read_packet(struct ezusb_iidx_msg_bulk_packet* pkg) +bool ezusb_iidx_emu_node_coin_read_packet( + struct ezusb_iidx_msg_bulk_packet *pkg) { log_fatal("Read packet not supported on coin node"); return false; } -bool ezusb_iidx_emu_node_coin_write_packet(const struct ezusb_iidx_msg_bulk_packet* pkg) +bool ezusb_iidx_emu_node_coin_write_packet( + const struct ezusb_iidx_msg_bulk_packet *pkg) { log_fatal("Write packet not supported on coin node"); return false; diff --git a/src/main/ezusb-iidx-emu/node-coin.h b/src/main/ezusb-iidx-emu/node-coin.h index 97cce87..126dbcc 100644 --- a/src/main/ezusb-iidx-emu/node-coin.h +++ b/src/main/ezusb-iidx-emu/node-coin.h @@ -3,12 +3,14 @@ #include "ezusb-iidx-emu/node.h" -uint8_t ezusb_iidx_emu_node_coin_process_cmd(uint8_t cmd_id, uint8_t cmd_data, - uint8_t cmd_data2); +uint8_t ezusb_iidx_emu_node_coin_process_cmd( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2); -bool ezusb_iidx_emu_node_coin_read_packet(struct ezusb_iidx_msg_bulk_packet* pkg); +bool ezusb_iidx_emu_node_coin_read_packet( + struct ezusb_iidx_msg_bulk_packet *pkg); -bool ezusb_iidx_emu_node_coin_write_packet(const struct ezusb_iidx_msg_bulk_packet* pkg); +bool ezusb_iidx_emu_node_coin_write_packet( + const struct ezusb_iidx_msg_bulk_packet *pkg); uint8_t ezusb_iidx_emu_node_coin_get_mode(void); diff --git a/src/main/ezusb-iidx-emu/node-eeprom.c b/src/main/ezusb-iidx-emu/node-eeprom.c index 551c6d0..3754dea 100644 --- a/src/main/ezusb-iidx-emu/node-eeprom.c +++ b/src/main/ezusb-iidx-emu/node-eeprom.c @@ -17,11 +17,14 @@ static uint8_t ezusb_iidx_emu_node_eeprom_mem[EZUSB_PAGESIZE * EEPROM_NPAGES]; void ezusb_iidx_emu_node_eeprom_init(void) { ezusb_iidx_emu_node_eeprom_read_page_pos = 0; - memset(ezusb_iidx_emu_node_eeprom_mem, 0xFF, sizeof(ezusb_iidx_emu_node_eeprom_mem)); + memset( + ezusb_iidx_emu_node_eeprom_mem, + 0xFF, + sizeof(ezusb_iidx_emu_node_eeprom_mem)); } -uint8_t ezusb_iidx_emu_node_eeprom_process_cmd_v1(uint8_t cmd_id, uint8_t cmd_data, - uint8_t cmd_data2) +uint8_t ezusb_iidx_emu_node_eeprom_process_cmd_v1( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2) { switch (cmd_id) { case EZUSB_IIDX_EEPROM_CMD_READ: @@ -39,8 +42,8 @@ uint8_t ezusb_iidx_emu_node_eeprom_process_cmd_v1(uint8_t cmd_id, uint8_t cmd_da } } -uint8_t ezusb_iidx_emu_node_eeprom_process_cmd_v2(uint8_t cmd_id, uint8_t cmd_data, - uint8_t cmd_data2) +uint8_t ezusb_iidx_emu_node_eeprom_process_cmd_v2( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2) { switch (cmd_id) { case EZUSB_IIDX_EEPROM_CMD_READ: @@ -58,9 +61,11 @@ uint8_t ezusb_iidx_emu_node_eeprom_process_cmd_v2(uint8_t cmd_id, uint8_t cmd_da } } -bool ezusb_iidx_emu_node_eeprom_read_packet(struct ezusb_iidx_msg_bulk_packet* pkg) +bool ezusb_iidx_emu_node_eeprom_read_packet( + struct ezusb_iidx_msg_bulk_packet *pkg) { - log_misc("Reading EEPROM page 0x%02X", ezusb_iidx_emu_node_eeprom_read_page_pos); + log_misc( + "Reading EEPROM page 0x%02X", ezusb_iidx_emu_node_eeprom_read_page_pos); if (ezusb_iidx_emu_node_eeprom_read_page_pos >= EEPROM_NPAGES) { log_warning("Reading EEPROM ezusb_iidx_emu_node_eeprom_mem overrun"); @@ -71,14 +76,18 @@ bool ezusb_iidx_emu_node_eeprom_read_packet(struct ezusb_iidx_msg_bulk_packet* p pkg->node = 0x22; pkg->page = ezusb_iidx_emu_node_eeprom_read_page_pos; memset(pkg->payload, 0, EZUSB_PAGESIZE); - memcpy(pkg->payload, ezusb_iidx_emu_node_eeprom_mem + - ezusb_iidx_emu_node_eeprom_read_page_pos * EZUSB_PAGESIZE, EZUSB_PAGESIZE); + memcpy( + pkg->payload, + ezusb_iidx_emu_node_eeprom_mem + + ezusb_iidx_emu_node_eeprom_read_page_pos * EZUSB_PAGESIZE, + EZUSB_PAGESIZE); ezusb_iidx_emu_node_eeprom_read_page_pos++; return true; } -bool ezusb_iidx_emu_node_eeprom_write_packet(const struct ezusb_iidx_msg_bulk_packet* pkg) +bool ezusb_iidx_emu_node_eeprom_write_packet( + const struct ezusb_iidx_msg_bulk_packet *pkg) { log_misc("Writing EEPROM page 0x%02X", pkg->page); @@ -87,18 +96,22 @@ bool ezusb_iidx_emu_node_eeprom_write_packet(const struct ezusb_iidx_msg_bulk_pa return false; } - memcpy(ezusb_iidx_emu_node_eeprom_mem + pkg->page * - EZUSB_PAGESIZE, pkg->payload, EZUSB_PAGESIZE); + memcpy( + ezusb_iidx_emu_node_eeprom_mem + pkg->page * EZUSB_PAGESIZE, + pkg->payload, + EZUSB_PAGESIZE); return true; } /* ------------------------------------------------------------------------- */ -size_t ezusb_iidx_emu_node_eeprom_write_memory(const uint8_t* buffer, size_t offset, - size_t length) +size_t ezusb_iidx_emu_node_eeprom_write_memory( + const uint8_t *buffer, size_t offset, size_t length) { if (offset + length > sizeof(ezusb_iidx_emu_node_eeprom_mem)) { - log_warning("Writing eeprom ezusb_iidx_emu_node_eeprom_mem overrun, truncated"); + log_warning( + "Writing eeprom ezusb_iidx_emu_node_eeprom_mem overrun, " + "truncated"); length = sizeof(ezusb_iidx_emu_node_eeprom_mem) - offset; } diff --git a/src/main/ezusb-iidx-emu/node-eeprom.h b/src/main/ezusb-iidx-emu/node-eeprom.h index cd16fd8..e249984 100644 --- a/src/main/ezusb-iidx-emu/node-eeprom.h +++ b/src/main/ezusb-iidx-emu/node-eeprom.h @@ -5,19 +5,21 @@ void ezusb_iidx_emu_node_eeprom_init(void); /* Used on 9th to DistorteD */ -uint8_t ezusb_iidx_emu_node_eeprom_process_cmd_v1(uint8_t cmd_id, uint8_t cmd_data, - uint8_t cmd_data2); +uint8_t ezusb_iidx_emu_node_eeprom_process_cmd_v1( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2); /* Used on Gold to Sirius */ -uint8_t ezusb_iidx_emu_node_eeprom_process_cmd_v2(uint8_t cmd_id, uint8_t cmd_data, - uint8_t cmd_data2); +uint8_t ezusb_iidx_emu_node_eeprom_process_cmd_v2( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2); -bool ezusb_iidx_emu_node_eeprom_read_packet(struct ezusb_iidx_msg_bulk_packet* pkg); +bool ezusb_iidx_emu_node_eeprom_read_packet( + struct ezusb_iidx_msg_bulk_packet *pkg); -bool ezusb_iidx_emu_node_eeprom_write_packet(const struct ezusb_iidx_msg_bulk_packet* pkg); +bool ezusb_iidx_emu_node_eeprom_write_packet( + const struct ezusb_iidx_msg_bulk_packet *pkg); /* Used by the security plug to write security related data */ -size_t ezusb_iidx_emu_node_eeprom_write_memory(const uint8_t* buffer, size_t offset, - size_t length); +size_t ezusb_iidx_emu_node_eeprom_write_memory( + const uint8_t *buffer, size_t offset, size_t length); #endif \ No newline at end of file diff --git a/src/main/ezusb-iidx-emu/node-fpga.c b/src/main/ezusb-iidx-emu/node-fpga.c index 13f00f6..d66c440 100644 --- a/src/main/ezusb-iidx-emu/node-fpga.c +++ b/src/main/ezusb-iidx-emu/node-fpga.c @@ -2,21 +2,19 @@ #include -#include "ezusb-iidx/fpga-cmd.h" #include "ezusb-iidx-emu/conf.h" #include "ezusb-iidx-emu/node-fpga.h" +#include "ezusb-iidx/fpga-cmd.h" #include "util/fs.h" #include "util/log.h" - static uint16_t ezusb_iidx_emu_node_fpga_write_ptr; static uint16_t ezusb_iidx_emu_node_fpga_prog_size; static uint8_t ezusb_iidx_emu_node_fpga_mem[0xFFFF]; - -uint8_t ezusb_iidx_emu_node_fpga_v1_process_cmd(uint8_t cmd_id, uint8_t cmd_data, - uint8_t cmd_data2) +uint8_t ezusb_iidx_emu_node_fpga_v1_process_cmd( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2) { switch (cmd_id) { case EZUSB_IIDX_FPGA_CMD_V1_INIT: @@ -33,17 +31,22 @@ uint8_t ezusb_iidx_emu_node_fpga_v1_process_cmd(uint8_t cmd_id, uint8_t cmd_data case EZUSB_IIDX_FPGA_CMD_V1_WRITE: ezusb_iidx_emu_node_fpga_prog_size = (cmd_data << 8) | cmd_data2; - log_misc("EZUSB_IIDX_FPGA_CMD_V1_WRITE (prog size %04X bytes)", + log_misc( + "EZUSB_IIDX_FPGA_CMD_V1_WRITE (prog size %04X bytes)", ezusb_iidx_emu_node_fpga_prog_size); ezusb_iidx_emu_node_fpga_write_ptr = 0; - memset(ezusb_iidx_emu_node_fpga_mem, 0xFF, + memset( + ezusb_iidx_emu_node_fpga_mem, + 0xFF, sizeof(ezusb_iidx_emu_node_fpga_mem)); return EZUSB_IIDX_FPGA_CMD_STATUS_V1_OK; case EZUSB_IIDX_FPGA_CMD_V1_WRITE_DONE: log_misc("EZUSB_IIDX_FPGA_CMD_V1_WRITE_DONE"); #ifdef EZUSB_IIDX_EMU_NODE_FPGA_DUMP - file_save("fpga.bin", ezusb_iidx_emu_node_fpga_mem, + file_save( + "fpga.bin", + ezusb_iidx_emu_node_fpga_mem, ezusb_iidx_emu_node_fpga_prog_size); log_info("Dumped fpga firmware to fpga.bin"); @@ -56,8 +59,8 @@ uint8_t ezusb_iidx_emu_node_fpga_v1_process_cmd(uint8_t cmd_id, uint8_t cmd_data } } -uint8_t ezusb_iidx_emu_node_fpga_v2_process_cmd(uint8_t cmd_id, uint8_t cmd_data, - uint8_t cmd_data2) +uint8_t ezusb_iidx_emu_node_fpga_v2_process_cmd( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2) { switch (cmd_id) { case EZUSB_IIDX_FPGA_CMD_V2_INIT: @@ -70,17 +73,22 @@ uint8_t ezusb_iidx_emu_node_fpga_v2_process_cmd(uint8_t cmd_id, uint8_t cmd_data case EZUSB_IIDX_FPGA_CMD_V2_WRITE: ezusb_iidx_emu_node_fpga_prog_size = (cmd_data << 8) | cmd_data2; - log_misc("EZUSB_IIDX_FPGA_CMD_V2_WRITE (%04X bytes)", + log_misc( + "EZUSB_IIDX_FPGA_CMD_V2_WRITE (%04X bytes)", ezusb_iidx_emu_node_fpga_prog_size); ezusb_iidx_emu_node_fpga_write_ptr = 0; - memset(ezusb_iidx_emu_node_fpga_mem, 0xFF, + memset( + ezusb_iidx_emu_node_fpga_mem, + 0xFF, sizeof(ezusb_iidx_emu_node_fpga_mem)); return EZUSB_IIDX_FPGA_CMD_STATUS_V2_WRITE_OK; case EZUSB_IIDX_FPGA_CMD_V2_WRITE_DONE: log_misc("EZUSB_IIDX_FPGA_CMD_V2_WRITE_DONE"); #ifdef EZUSB_IIDX_EMU_NODE_FPGA_DUMP - file_save("fpga.bin", ezusb_iidx_emu_node_fpga_mem, + file_save( + "fpga.bin", + ezusb_iidx_emu_node_fpga_mem, ezusb_iidx_emu_node_fpga_prog_size); log_info("Dumped fpga firmware to fpga.bin"); @@ -93,7 +101,8 @@ uint8_t ezusb_iidx_emu_node_fpga_v2_process_cmd(uint8_t cmd_id, uint8_t cmd_data } } -bool ezusb_iidx_emu_node_fpga_read_packet(struct ezusb_iidx_msg_bulk_packet* pkg) +bool ezusb_iidx_emu_node_fpga_read_packet( + struct ezusb_iidx_msg_bulk_packet *pkg) { log_misc("FPGA read packet"); @@ -105,11 +114,14 @@ bool ezusb_iidx_emu_node_fpga_read_packet(struct ezusb_iidx_msg_bulk_packet* pkg return true; } -bool ezusb_iidx_emu_node_fpga_write_packet(const struct ezusb_iidx_msg_bulk_packet* pkg) +bool ezusb_iidx_emu_node_fpga_write_packet( + const struct ezusb_iidx_msg_bulk_packet *pkg) { log_misc("FPGA write packet: %02X %02X", pkg->node, pkg->page); - memcpy(ezusb_iidx_emu_node_fpga_mem + ezusb_iidx_emu_node_fpga_write_ptr, pkg->payload, + memcpy( + ezusb_iidx_emu_node_fpga_mem + ezusb_iidx_emu_node_fpga_write_ptr, + pkg->payload, EZUSB_PAGESIZE); ezusb_iidx_emu_node_fpga_write_ptr += EZUSB_PAGESIZE; diff --git a/src/main/ezusb-iidx-emu/node-fpga.h b/src/main/ezusb-iidx-emu/node-fpga.h index fe56805..21a0192 100644 --- a/src/main/ezusb-iidx-emu/node-fpga.h +++ b/src/main/ezusb-iidx-emu/node-fpga.h @@ -4,15 +4,17 @@ #include "ezusb-iidx-emu/node.h" /* Used on 9th to DistorteD */ -uint8_t ezusb_iidx_emu_node_fpga_v1_process_cmd(uint8_t cmd_id, uint8_t cmd_data, - uint8_t cmd_data2); +uint8_t ezusb_iidx_emu_node_fpga_v1_process_cmd( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2); /* Used on Gold onwards */ -uint8_t ezusb_iidx_emu_node_fpga_v2_process_cmd(uint8_t cmd_id, uint8_t cmd_data, - uint8_t cmd_data2); +uint8_t ezusb_iidx_emu_node_fpga_v2_process_cmd( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2); -bool ezusb_iidx_emu_node_fpga_read_packet(struct ezusb_iidx_msg_bulk_packet* pkg); +bool ezusb_iidx_emu_node_fpga_read_packet( + struct ezusb_iidx_msg_bulk_packet *pkg); -bool ezusb_iidx_emu_node_fpga_write_packet(const struct ezusb_iidx_msg_bulk_packet* pkg); +bool ezusb_iidx_emu_node_fpga_write_packet( + const struct ezusb_iidx_msg_bulk_packet *pkg); #endif \ No newline at end of file diff --git a/src/main/ezusb-iidx-emu/node-none.c b/src/main/ezusb-iidx-emu/node-none.c index 7f0bfcc..caeb1fa 100644 --- a/src/main/ezusb-iidx-emu/node-none.c +++ b/src/main/ezusb-iidx-emu/node-none.c @@ -1,17 +1,19 @@ #include "ezusb-iidx-emu/node-none.h" -uint8_t ezusb_iidx_emu_node_none_process_cmd(uint8_t cmd_id, uint8_t cmd_data, - uint8_t cmd_data2) +uint8_t ezusb_iidx_emu_node_none_process_cmd( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2) { return 0; } -bool ezusb_iidx_emu_node_none_read_packet(struct ezusb_iidx_msg_bulk_packet* pkg) +bool ezusb_iidx_emu_node_none_read_packet( + struct ezusb_iidx_msg_bulk_packet *pkg) { return true; } -bool ezusb_iidx_emu_node_none_write_packet(const struct ezusb_iidx_msg_bulk_packet* pkg) +bool ezusb_iidx_emu_node_none_write_packet( + const struct ezusb_iidx_msg_bulk_packet *pkg) { return true; } \ No newline at end of file diff --git a/src/main/ezusb-iidx-emu/node-none.h b/src/main/ezusb-iidx-emu/node-none.h index f20ec97..02e5f37 100644 --- a/src/main/ezusb-iidx-emu/node-none.h +++ b/src/main/ezusb-iidx-emu/node-none.h @@ -3,11 +3,13 @@ #include "ezusb-iidx-emu/node.h" -uint8_t ezusb_iidx_emu_node_none_process_cmd(uint8_t cmd_id, uint8_t cmd_data, - uint8_t cmd_data2); +uint8_t ezusb_iidx_emu_node_none_process_cmd( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2); -bool ezusb_iidx_emu_node_none_read_packet(struct ezusb_iidx_msg_bulk_packet* pkg); +bool ezusb_iidx_emu_node_none_read_packet( + struct ezusb_iidx_msg_bulk_packet *pkg); -bool ezusb_iidx_emu_node_none_write_packet(const struct ezusb_iidx_msg_bulk_packet* pkg); +bool ezusb_iidx_emu_node_none_write_packet( + const struct ezusb_iidx_msg_bulk_packet *pkg); #endif \ No newline at end of file diff --git a/src/main/ezusb-iidx-emu/node-security-mem.c b/src/main/ezusb-iidx-emu/node-security-mem.c index 61cf87e..397dc74 100644 --- a/src/main/ezusb-iidx-emu/node-security-mem.c +++ b/src/main/ezusb-iidx-emu/node-security-mem.c @@ -2,8 +2,8 @@ #include -#include "ezusb-iidx/secmem-cmd.h" #include "ezusb-iidx-emu/node-security-mem.h" +#include "ezusb-iidx/secmem-cmd.h" #include "util/log.h" @@ -15,40 +15,30 @@ page of data is sent to the board to store. The following dump was taken from the GOLD exec 2007022101 */ -static uint8_t ezusb_iidx_emu_node_security_mem_mem - [EZUSB_PAGESIZE * SECURITY2_NPAGES] = { - 0x00, 0x90, 0x31, 0xCF, 0x95, 0x7A, 0x59, 0xE5, - 0xD2, 0xBF, 0x2C, 0xDB, 0xB5, 0x83, 0x4D, 0x03, - 0x17, 0x5D, 0x25, 0x2A, 0xFD, 0x72, 0x1E, 0x01, - 0x02, 0x60, 0x88, 0x92, 0x9A, 0x9B, 0x2A, 0xA9, - 0x73, 0x5A, 0x0E, 0x9B, 0xC8, 0xCD, 0x85, 0x4D, - 0xE0, 0xBA, 0xF4, 0xEC, 0x8A, 0x24, 0x76, 0x3C, - 0xDC, 0x35, 0xC7, 0xD7, 0xFF, 0xFF, 0x9C, 0x64, - 0x44, 0x4C, 0xD7, 0x06, 0x60, 0x17, 0xAD, 0x0E, - 0x02, 0xEB, 0x46, 0x45, 0x96, 0xB0, 0xD6, 0xB9, - 0x7C, 0x34, 0xBE, 0x77, 0x75, 0xF2, 0xBE, 0x1B, - 0x99, 0x62, 0xBC, 0x9B, 0x92, 0x5C, 0x26, 0x39, - 0x6C, 0xCD, 0x84, 0xFD, 0xC0, 0x58, 0x2B, 0xA8, - 0x7D, 0x10, 0xB3, 0x81, 0x25, 0xF3, 0x24, 0xE7, - 0xB1, 0x4D, 0x6D, 0x12, 0xF7, 0xAE, 0x27, 0xE0, - 0xD2, 0x95, 0x30, 0x2D, 0xD1, 0x79, 0x27, 0x81, - 0xBB, 0x67, 0x47, 0x91, 0xAE, 0xC1, 0xB8, 0x79, - 0x1F, 0x5E, 0xD5, 0x08, 0x84, 0xA9, 0x6D, 0x1A, - 0xF3, 0xEB, 0x8C, 0x58, 0x78, 0x5F, 0xD8, 0x51, - 0x74, 0x45, 0xFB, 0x4C, 0xBD, 0x91, 0x32, 0xC2, - 0xD6, 0x65, 0x80, 0xE3, 0x07, 0xFE, 0x92, 0x0C, - 0x88, 0x31, 0xD7, 0xA0, 0xA8, 0x32, 0xD7, 0x1F, - 0x1C, 0xBE, 0x50, 0xF0, 0x49, 0x56, 0x23, 0xBB, - 0xD5, 0xB5, 0x99, 0xBF, 0x40, 0x24, 0x00, 0x0F, - 0xCE, 0xDA, 0x35, 0x1D, 0x8D, 0x03, 0x1D, 0x74, - 0xC0, 0xAF, 0x8B, 0x12, 0x6F, 0x33, 0xB2, 0x4A, - 0x6F, 0x3B, 0x93, 0x88, 0xA0, 0x29, 0x81, 0xF6, - 0xB2, 0xEC, 0x30, 0x56, 0x2D, 0xFE, 0x75, 0xFF, - 0x18, 0xA0, 0x18, 0x70, 0xEE, 0x0C, 0xE5, 0x4A, - 0x3A, 0xC4, 0x69, 0x33, 0xA0, 0x9A, 0x73, 0x77, - 0x99, 0xA2, 0xDA, 0xD4, 0x9F, 0xB8, 0x90, 0x60, - 0x2F, 0xBC, 0x8E, 0xE7, 0x3E, 0x30, 0x9A, 0xB2, - 0x95, 0x59, 0x7E, 0x14, 0xBD, 0x9C, 0x9E, 0xB0}; +static uint8_t + ezusb_iidx_emu_node_security_mem_mem[EZUSB_PAGESIZE * SECURITY2_NPAGES] = { + 0x00, 0x90, 0x31, 0xCF, 0x95, 0x7A, 0x59, 0xE5, 0xD2, 0xBF, 0x2C, 0xDB, + 0xB5, 0x83, 0x4D, 0x03, 0x17, 0x5D, 0x25, 0x2A, 0xFD, 0x72, 0x1E, 0x01, + 0x02, 0x60, 0x88, 0x92, 0x9A, 0x9B, 0x2A, 0xA9, 0x73, 0x5A, 0x0E, 0x9B, + 0xC8, 0xCD, 0x85, 0x4D, 0xE0, 0xBA, 0xF4, 0xEC, 0x8A, 0x24, 0x76, 0x3C, + 0xDC, 0x35, 0xC7, 0xD7, 0xFF, 0xFF, 0x9C, 0x64, 0x44, 0x4C, 0xD7, 0x06, + 0x60, 0x17, 0xAD, 0x0E, 0x02, 0xEB, 0x46, 0x45, 0x96, 0xB0, 0xD6, 0xB9, + 0x7C, 0x34, 0xBE, 0x77, 0x75, 0xF2, 0xBE, 0x1B, 0x99, 0x62, 0xBC, 0x9B, + 0x92, 0x5C, 0x26, 0x39, 0x6C, 0xCD, 0x84, 0xFD, 0xC0, 0x58, 0x2B, 0xA8, + 0x7D, 0x10, 0xB3, 0x81, 0x25, 0xF3, 0x24, 0xE7, 0xB1, 0x4D, 0x6D, 0x12, + 0xF7, 0xAE, 0x27, 0xE0, 0xD2, 0x95, 0x30, 0x2D, 0xD1, 0x79, 0x27, 0x81, + 0xBB, 0x67, 0x47, 0x91, 0xAE, 0xC1, 0xB8, 0x79, 0x1F, 0x5E, 0xD5, 0x08, + 0x84, 0xA9, 0x6D, 0x1A, 0xF3, 0xEB, 0x8C, 0x58, 0x78, 0x5F, 0xD8, 0x51, + 0x74, 0x45, 0xFB, 0x4C, 0xBD, 0x91, 0x32, 0xC2, 0xD6, 0x65, 0x80, 0xE3, + 0x07, 0xFE, 0x92, 0x0C, 0x88, 0x31, 0xD7, 0xA0, 0xA8, 0x32, 0xD7, 0x1F, + 0x1C, 0xBE, 0x50, 0xF0, 0x49, 0x56, 0x23, 0xBB, 0xD5, 0xB5, 0x99, 0xBF, + 0x40, 0x24, 0x00, 0x0F, 0xCE, 0xDA, 0x35, 0x1D, 0x8D, 0x03, 0x1D, 0x74, + 0xC0, 0xAF, 0x8B, 0x12, 0x6F, 0x33, 0xB2, 0x4A, 0x6F, 0x3B, 0x93, 0x88, + 0xA0, 0x29, 0x81, 0xF6, 0xB2, 0xEC, 0x30, 0x56, 0x2D, 0xFE, 0x75, 0xFF, + 0x18, 0xA0, 0x18, 0x70, 0xEE, 0x0C, 0xE5, 0x4A, 0x3A, 0xC4, 0x69, 0x33, + 0xA0, 0x9A, 0x73, 0x77, 0x99, 0xA2, 0xDA, 0xD4, 0x9F, 0xB8, 0x90, 0x60, + 0x2F, 0xBC, 0x8E, 0xE7, 0x3E, 0x30, 0x9A, 0xB2, 0x95, 0x59, 0x7E, 0x14, + 0xBD, 0x9C, 0x9E, 0xB0}; void ezusb_iidx_emu_node_security_mem_init(void) { @@ -60,8 +50,8 @@ void ezusb_iidx_emu_node_security_mem_init(void) */ } -uint8_t ezusb_iidx_emu_node_security_mem_v1_process_cmd(uint8_t cmd_id, - uint8_t cmd_data, uint8_t cmd_data2) +uint8_t ezusb_iidx_emu_node_security_mem_v1_process_cmd( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2) { switch (cmd_id) { case EZUSB_IIDX_SECMEM_CMD_WRITE: @@ -69,13 +59,14 @@ uint8_t ezusb_iidx_emu_node_security_mem_v1_process_cmd(uint8_t cmd_id, return EZUSB_IIDX_SECMEM_CMD_STATUS_V1_WRITE_OK; default: - log_warning("Unrecognised security memory v1 command: %02x", cmd_id); + log_warning( + "Unrecognised security memory v1 command: %02x", cmd_id); return EZUSB_IIDX_SECMEM_CMD_STATUS_V1_FAULT; } } -uint8_t ezusb_iidx_emu_node_security_mem_v2_process_cmd(uint8_t cmd_id, - uint8_t cmd_data, uint8_t cmd_data2) +uint8_t ezusb_iidx_emu_node_security_mem_v2_process_cmd( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2) { switch (cmd_id) { case EZUSB_IIDX_SECMEM_CMD_WRITE: @@ -83,18 +74,21 @@ uint8_t ezusb_iidx_emu_node_security_mem_v2_process_cmd(uint8_t cmd_id, return EZUSB_IIDX_SECMEM_CMD_STATUS_V2_WRITE_OK; default: - log_warning("Unrecognised security memory v2 command: %02x", cmd_id); + log_warning( + "Unrecognised security memory v2 command: %02x", cmd_id); return EZUSB_IIDX_SECMEM_CMD_STATUS_V2_FAULT; } } -bool ezusb_iidx_emu_node_security_mem_read_packet(struct ezusb_iidx_msg_bulk_packet* pkg) +bool ezusb_iidx_emu_node_security_mem_read_packet( + struct ezusb_iidx_msg_bulk_packet *pkg) { log_misc("Reading security memory"); return true; } -bool ezusb_iidx_emu_node_security_mem_write_packet(const struct ezusb_iidx_msg_bulk_packet* pkg) +bool ezusb_iidx_emu_node_security_mem_write_packet( + const struct ezusb_iidx_msg_bulk_packet *pkg) { log_misc("Writing security memory 0x%02X", pkg->page); @@ -103,7 +97,10 @@ bool ezusb_iidx_emu_node_security_mem_write_packet(const struct ezusb_iidx_msg_b return false; } - memcpy(ezusb_iidx_emu_node_security_mem_mem + pkg->page * EZUSB_PAGESIZE, pkg->payload, EZUSB_PAGESIZE); + memcpy( + ezusb_iidx_emu_node_security_mem_mem + pkg->page * EZUSB_PAGESIZE, + pkg->payload, + EZUSB_PAGESIZE); return true; } diff --git a/src/main/ezusb-iidx-emu/node-security-mem.h b/src/main/ezusb-iidx-emu/node-security-mem.h index 226424f..48e27ea 100644 --- a/src/main/ezusb-iidx-emu/node-security-mem.h +++ b/src/main/ezusb-iidx-emu/node-security-mem.h @@ -6,16 +6,18 @@ void ezusb_iidx_emu_node_security_mem_init(void); /* Used on 9th to DistorteD */ -uint8_t ezusb_iidx_emu_node_security_mem_v1_process_cmd(uint8_t cmd_id, - uint8_t cmd_data, uint8_t cmd_data2); +uint8_t ezusb_iidx_emu_node_security_mem_v1_process_cmd( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2); /* Used on Gold to Sirius */ -uint8_t ezusb_iidx_emu_node_security_mem_v2_process_cmd(uint8_t cmd_id, - uint8_t cmd_data, uint8_t cmd_data2); +uint8_t ezusb_iidx_emu_node_security_mem_v2_process_cmd( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2); -bool ezusb_iidx_emu_node_security_mem_read_packet(struct ezusb_iidx_msg_bulk_packet* pkg); +bool ezusb_iidx_emu_node_security_mem_read_packet( + struct ezusb_iidx_msg_bulk_packet *pkg); -bool ezusb_iidx_emu_node_security_mem_write_packet(const struct ezusb_iidx_msg_bulk_packet* pkg); +bool ezusb_iidx_emu_node_security_mem_write_packet( + const struct ezusb_iidx_msg_bulk_packet *pkg); /* Used by the security plug to read from security memory to encrypt data sent to the host */ diff --git a/src/main/ezusb-iidx-emu/node-security-plug.c b/src/main/ezusb-iidx-emu/node-security-plug.c index 56faf0a..f3fe843 100644 --- a/src/main/ezusb-iidx-emu/node-security-plug.c +++ b/src/main/ezusb-iidx-emu/node-security-plug.c @@ -2,10 +2,10 @@ #include -#include "ezusb-iidx/secplug-cmd.h" #include "ezusb-iidx-emu/node-eeprom.h" #include "ezusb-iidx-emu/node-security-mem.h" #include "ezusb-iidx-emu/node-security-plug.h" +#include "ezusb-iidx/secplug-cmd.h" #include "security/rp.h" #include "security/rp2.h" @@ -28,14 +28,14 @@ static enum ezusb_iidx_secplug_dongle_memory ezusb_iidx_emu_node_security_plug_active_dongle_mem; static uint8_t ezusb_iidx_emu_node_security_plug_enc_rom_data_seed; -static void ezusb_iidx_emu_node_security_plug_encrypt_rom_data(uint8_t* buffer, - uint8_t length); +static void ezusb_iidx_emu_node_security_plug_encrypt_rom_data( + uint8_t *buffer, uint8_t length); /* ------------------------------------------------------------------------- */ void ezusb_iidx_emu_node_security_plug_set_boot_version( - const struct security_mcode* boot_version) + const struct security_mcode *boot_version) { - char* tmp; + char *tmp; log_assert(boot_version); @@ -44,24 +44,28 @@ void ezusb_iidx_emu_node_security_plug_set_boot_version( log_misc("boot version: %s", tmp); free(tmp); - memcpy(&ezusb_iidx_emu_node_security_plug_boot_version, boot_version, + memcpy( + &ezusb_iidx_emu_node_security_plug_boot_version, + boot_version, sizeof(struct security_mcode)); } -void ezusb_iidx_emu_node_security_plug_set_boot_seeds(const uint32_t* seeds) +void ezusb_iidx_emu_node_security_plug_set_boot_seeds(const uint32_t *seeds) { log_assert(seeds); log_misc("boot seeds: %d %d %d", seeds[0], seeds[1], seeds[2]); - memcpy(&ezusb_iidx_emu_node_security_plug_boot_seeds, seeds, + memcpy( + &ezusb_iidx_emu_node_security_plug_boot_seeds, + seeds, sizeof(ezusb_iidx_emu_node_security_plug_boot_seeds)); } void ezusb_iidx_emu_node_security_plug_set_plug_black_mcode( - const struct security_mcode* mcode) + const struct security_mcode *mcode) { - char* tmp; + char *tmp; log_assert(mcode); @@ -70,14 +74,16 @@ void ezusb_iidx_emu_node_security_plug_set_plug_black_mcode( log_misc("black mcode: %s", tmp); free(tmp); - memcpy(&ezusb_iidx_emu_node_security_plug_black_mcode, mcode, + memcpy( + &ezusb_iidx_emu_node_security_plug_black_mcode, + mcode, sizeof(struct security_mcode)); } void ezusb_iidx_emu_node_security_plug_set_plug_white_mcode( - const struct security_mcode* mcode) + const struct security_mcode *mcode) { - char* tmp; + char *tmp; log_assert(mcode); @@ -86,42 +92,48 @@ void ezusb_iidx_emu_node_security_plug_set_plug_white_mcode( log_misc("white mcode: %s", tmp); free(tmp); - memcpy(&ezusb_iidx_emu_node_security_plug_white_mcode, mcode, + memcpy( + &ezusb_iidx_emu_node_security_plug_white_mcode, + mcode, sizeof(struct security_mcode)); } void ezusb_iidx_emu_node_security_plug_set_pcbid( - const struct security_id* pcbid) + const struct security_id *pcbid) { - char* tmp; + char *tmp; tmp = security_id_to_str(pcbid, false); - + log_misc("PCBID: %s", tmp); free(tmp); - memcpy(&ezusb_iidx_emu_node_security_plug_pcbid, pcbid, + memcpy( + &ezusb_iidx_emu_node_security_plug_pcbid, + pcbid, sizeof(struct security_id)); } void ezusb_iidx_emu_node_security_plug_set_eamid( - const struct security_id* eamid) + const struct security_id *eamid) { - char* tmp; + char *tmp; tmp = security_id_to_str(eamid, false); - + log_misc("EAMID: %s", tmp); free(tmp); - memcpy(&ezusb_iidx_emu_node_security_plug_eamid, eamid, + memcpy( + &ezusb_iidx_emu_node_security_plug_eamid, + eamid, sizeof(struct security_id)); } /* ------------------------------------------------------------- */ -uint8_t ezusb_iidx_emu_node_security_plug_process_cmd_v1(uint8_t cmd_id, - uint8_t cmd_data, uint8_t cmd_data2) +uint8_t ezusb_iidx_emu_node_security_plug_process_cmd_v1( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2) { switch (cmd_id) { case EZUSB_IIDX_SECPLUG_CMD_V1_READ_ROM: @@ -160,10 +172,10 @@ uint8_t ezusb_iidx_emu_node_security_plug_process_cmd_v1(uint8_t cmd_id, } } -uint8_t ezusb_iidx_emu_node_security_plug_process_cmd_v2(uint8_t cmd_id, - uint8_t cmd_data, uint8_t cmd_data2) +uint8_t ezusb_iidx_emu_node_security_plug_process_cmd_v2( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2) { - switch (cmd_id) { + switch (cmd_id) { case EZUSB_IIDX_SECPLUG_CMD_V2_INIT: log_misc("EZUSB_IIDX_SECPLUG_CMD_V2_INIT"); ezusb_iidx_emu_node_security_plug_active_dongle_mem = @@ -205,23 +217,22 @@ uint8_t ezusb_iidx_emu_node_security_plug_process_cmd_v2(uint8_t cmd_id, default: log_warning("Unrecognised security plug v2 command: %02x", cmd_id); return EZUSB_IIDX_SECPLUG_CMD_STATUS_V2_FAIL; - } + } } bool ezusb_iidx_emu_node_security_plug_read_packet_v1( - struct ezusb_iidx_msg_bulk_packet* pkg) + struct ezusb_iidx_msg_bulk_packet *pkg) { - char* tmp; + char *tmp; memset(pkg, 0x00, sizeof(struct ezusb_iidx_msg_bulk_packet)); - if ( ezusb_iidx_emu_node_security_plug_active_dongle_slot == + if (ezusb_iidx_emu_node_security_plug_active_dongle_slot == EZUSB_IIDX_SECPLUG_DONGLE_SLOT_BLACK && - ezusb_iidx_emu_node_security_plug_active_dongle_mem == - EZUSB_IIDX_SECPLUG_DONGLE_MEM_ROM) - { - tmp = security_id_to_str(&ezusb_iidx_emu_node_security_plug_pcbid, - false); + ezusb_iidx_emu_node_security_plug_active_dongle_mem == + EZUSB_IIDX_SECPLUG_DONGLE_MEM_ROM) { + tmp = + security_id_to_str(&ezusb_iidx_emu_node_security_plug_pcbid, false); log_misc("Reading security plug v1 black rom, PCBID %s", tmp); @@ -235,16 +246,17 @@ bool ezusb_iidx_emu_node_security_plug_read_packet_v1( pkg->node = 0x11; pkg->page = 0x00; - memcpy(pkg->payload, &ezusb_iidx_emu_node_security_plug_pcbid, + memcpy( + pkg->payload, + &ezusb_iidx_emu_node_security_plug_pcbid, sizeof(struct security_id)); ezusb_iidx_emu_node_security_plug_encrypt_rom_data(pkg->payload, 10); - } - else if ( ezusb_iidx_emu_node_security_plug_active_dongle_slot == - EZUSB_IIDX_SECPLUG_DONGLE_SLOT_BLACK && - ezusb_iidx_emu_node_security_plug_active_dongle_mem == - EZUSB_IIDX_SECPLUG_DONGLE_MEM_DATA) - { + } else if ( + ezusb_iidx_emu_node_security_plug_active_dongle_slot == + EZUSB_IIDX_SECPLUG_DONGLE_SLOT_BLACK && + ezusb_iidx_emu_node_security_plug_active_dongle_mem == + EZUSB_IIDX_SECPLUG_DONGLE_MEM_DATA) { log_misc("Reading security plug v1 black data"); pkg->node = 0x12; @@ -254,20 +266,19 @@ bool ezusb_iidx_emu_node_security_plug_read_packet_v1( &ezusb_iidx_emu_node_security_plug_boot_version, ezusb_iidx_emu_node_security_plug_boot_seeds, &ezusb_iidx_emu_node_security_plug_black_mcode, - &ezusb_iidx_emu_node_security_plug_pcbid, - (struct security_rp_eeprom*) pkg->payload); + &ezusb_iidx_emu_node_security_plug_pcbid, + (struct security_rp_eeprom *) pkg->payload); /* the signed test vector will be compared to the eeprom contents write test vector to eeprom to pass checks */ ezusb_iidx_emu_node_eeprom_write_memory(pkg->payload, 6, 6); - } - else if ( ezusb_iidx_emu_node_security_plug_active_dongle_slot == - EZUSB_IIDX_SECPLUG_DONGLE_SLOT_WHITE && - ezusb_iidx_emu_node_security_plug_active_dongle_mem == - EZUSB_IIDX_SECPLUG_DONGLE_MEM_ROM) - { - tmp = security_id_to_str(&ezusb_iidx_emu_node_security_plug_eamid, - false); + } else if ( + ezusb_iidx_emu_node_security_plug_active_dongle_slot == + EZUSB_IIDX_SECPLUG_DONGLE_SLOT_WHITE && + ezusb_iidx_emu_node_security_plug_active_dongle_mem == + EZUSB_IIDX_SECPLUG_DONGLE_MEM_ROM) { + tmp = + security_id_to_str(&ezusb_iidx_emu_node_security_plug_eamid, false); log_misc("Reading security plug v1 white rom, EAMID %s", tmp); @@ -281,16 +292,17 @@ bool ezusb_iidx_emu_node_security_plug_read_packet_v1( pkg->node = 0x11; pkg->page = 0x00; - memcpy(pkg->payload, &ezusb_iidx_emu_node_security_plug_eamid, + memcpy( + pkg->payload, + &ezusb_iidx_emu_node_security_plug_eamid, sizeof(struct security_id)); ezusb_iidx_emu_node_security_plug_encrypt_rom_data(pkg->payload, 10); - } - else if ( ezusb_iidx_emu_node_security_plug_active_dongle_slot == - EZUSB_IIDX_SECPLUG_DONGLE_SLOT_WHITE && - ezusb_iidx_emu_node_security_plug_active_dongle_mem == - EZUSB_IIDX_SECPLUG_DONGLE_MEM_DATA) - { + } else if ( + ezusb_iidx_emu_node_security_plug_active_dongle_slot == + EZUSB_IIDX_SECPLUG_DONGLE_SLOT_WHITE && + ezusb_iidx_emu_node_security_plug_active_dongle_mem == + EZUSB_IIDX_SECPLUG_DONGLE_MEM_DATA) { log_misc("Reading security plug v1 white data"); pkg->node = 0x12; @@ -300,16 +312,14 @@ bool ezusb_iidx_emu_node_security_plug_read_packet_v1( &ezusb_iidx_emu_node_security_plug_boot_version, ezusb_iidx_emu_node_security_plug_boot_seeds, &ezusb_iidx_emu_node_security_plug_white_mcode, - &ezusb_iidx_emu_node_security_plug_eamid, - (struct security_rp_eeprom*) pkg->payload); + &ezusb_iidx_emu_node_security_plug_eamid, + (struct security_rp_eeprom *) pkg->payload); /* XXX position 0 not verified, guess the test vector will be compared against eeprom contents write test vector to eeprom to pass checks */ ezusb_iidx_emu_node_eeprom_write_memory(pkg->payload, 0, 6); - } - else - { + } else { log_warning("Invalid security plug v1 read"); return false; } @@ -318,21 +328,20 @@ bool ezusb_iidx_emu_node_security_plug_read_packet_v1( } bool ezusb_iidx_emu_node_security_plug_read_packet_v2( - struct ezusb_iidx_msg_bulk_packet* pkg) + struct ezusb_iidx_msg_bulk_packet *pkg) { - char* tmp; + char *tmp; log_misc("Reading security plug v2 packet"); memset(pkg, 0x00, sizeof(struct ezusb_iidx_msg_bulk_packet)); - if ( ezusb_iidx_emu_node_security_plug_active_dongle_slot == + if (ezusb_iidx_emu_node_security_plug_active_dongle_slot == EZUSB_IIDX_SECPLUG_DONGLE_SLOT_BLACK && - ezusb_iidx_emu_node_security_plug_active_dongle_mem == - EZUSB_IIDX_SECPLUG_DONGLE_MEM_ROM) - { - tmp = security_id_to_str(&ezusb_iidx_emu_node_security_plug_pcbid, - false); + ezusb_iidx_emu_node_security_plug_active_dongle_mem == + EZUSB_IIDX_SECPLUG_DONGLE_MEM_ROM) { + tmp = + security_id_to_str(&ezusb_iidx_emu_node_security_plug_pcbid, false); log_misc("Reading security plug v2 black rom, PCBID %s", tmp); @@ -346,34 +355,35 @@ bool ezusb_iidx_emu_node_security_plug_read_packet_v2( pkg->node = 0x11; pkg->page = 0x00; - memcpy(pkg->payload, &ezusb_iidx_emu_node_security_plug_pcbid, + memcpy( + pkg->payload, + &ezusb_iidx_emu_node_security_plug_pcbid, sizeof(struct security_id)); ezusb_iidx_emu_node_security_plug_encrypt_rom_data(pkg->payload, 10); - } - else if ( ezusb_iidx_emu_node_security_plug_active_dongle_slot == - EZUSB_IIDX_SECPLUG_DONGLE_SLOT_BLACK && - ezusb_iidx_emu_node_security_plug_active_dongle_mem == - EZUSB_IIDX_SECPLUG_DONGLE_MEM_DATA) - { + } else if ( + ezusb_iidx_emu_node_security_plug_active_dongle_slot == + EZUSB_IIDX_SECPLUG_DONGLE_SLOT_BLACK && + ezusb_iidx_emu_node_security_plug_active_dongle_mem == + EZUSB_IIDX_SECPLUG_DONGLE_MEM_DATA) { log_misc("Reading security plug v2 black data"); pkg->node = 0x12; pkg->page = 0x00; - security_rp2_generate_signed_eeprom_data(SECURITY_RP_UTIL_RP_TYPE_BLACK, + security_rp2_generate_signed_eeprom_data( + SECURITY_RP_UTIL_RP_TYPE_BLACK, &ezusb_iidx_emu_node_security_plug_boot_version, &ezusb_iidx_emu_node_security_plug_black_mcode, - &ezusb_iidx_emu_node_security_plug_pcbid, - (struct security_rp2_eeprom*) pkg->payload); - } - else if ( ezusb_iidx_emu_node_security_plug_active_dongle_slot == - EZUSB_IIDX_SECPLUG_DONGLE_SLOT_WHITE && - ezusb_iidx_emu_node_security_plug_active_dongle_mem == - EZUSB_IIDX_SECPLUG_DONGLE_MEM_ROM) - { - tmp = security_id_to_str(&ezusb_iidx_emu_node_security_plug_eamid, - false); + &ezusb_iidx_emu_node_security_plug_pcbid, + (struct security_rp2_eeprom *) pkg->payload); + } else if ( + ezusb_iidx_emu_node_security_plug_active_dongle_slot == + EZUSB_IIDX_SECPLUG_DONGLE_SLOT_WHITE && + ezusb_iidx_emu_node_security_plug_active_dongle_mem == + EZUSB_IIDX_SECPLUG_DONGLE_MEM_ROM) { + tmp = + security_id_to_str(&ezusb_iidx_emu_node_security_plug_eamid, false); log_misc("Reading security plug v2 white rom, EAMID %s", tmp); @@ -387,33 +397,35 @@ bool ezusb_iidx_emu_node_security_plug_read_packet_v2( pkg->node = 0x11; pkg->page = 0x00; - memcpy(pkg->payload, &ezusb_iidx_emu_node_security_plug_eamid, + memcpy( + pkg->payload, + &ezusb_iidx_emu_node_security_plug_eamid, sizeof(struct security_id)); ezusb_iidx_emu_node_security_plug_encrypt_rom_data(pkg->payload, 10); - } - else if ( ezusb_iidx_emu_node_security_plug_active_dongle_slot == - EZUSB_IIDX_SECPLUG_DONGLE_SLOT_WHITE && - ezusb_iidx_emu_node_security_plug_active_dongle_mem == - EZUSB_IIDX_SECPLUG_DONGLE_MEM_DATA) - { + } else if ( + ezusb_iidx_emu_node_security_plug_active_dongle_slot == + EZUSB_IIDX_SECPLUG_DONGLE_SLOT_WHITE && + ezusb_iidx_emu_node_security_plug_active_dongle_mem == + EZUSB_IIDX_SECPLUG_DONGLE_MEM_DATA) { log_misc("Reading security plug v2 white data"); pkg->node = 0x12; pkg->page = 0x00; - security_rp2_generate_signed_eeprom_data(SECURITY_RP_UTIL_RP_TYPE_WHITE, + security_rp2_generate_signed_eeprom_data( + SECURITY_RP_UTIL_RP_TYPE_WHITE, &ezusb_iidx_emu_node_security_plug_boot_version, &ezusb_iidx_emu_node_security_plug_white_mcode, - &ezusb_iidx_emu_node_security_plug_eamid, - (struct security_rp2_eeprom*) pkg->payload); + &ezusb_iidx_emu_node_security_plug_eamid, + (struct security_rp2_eeprom *) pkg->payload); } return true; } bool ezusb_iidx_emu_node_security_plug_write_packet( - const struct ezusb_iidx_msg_bulk_packet* pkg) + const struct ezusb_iidx_msg_bulk_packet *pkg) { log_misc("Writing security plug packet"); return true; @@ -421,8 +433,8 @@ bool ezusb_iidx_emu_node_security_plug_write_packet( /* ------------------------------------------------------------- */ -static void ezusb_iidx_emu_node_security_plug_encrypt_rom_data(uint8_t* buffer, - uint8_t length) +static void ezusb_iidx_emu_node_security_plug_encrypt_rom_data( + uint8_t *buffer, uint8_t length) { uint8_t data; diff --git a/src/main/ezusb-iidx-emu/node-security-plug.h b/src/main/ezusb-iidx-emu/node-security-plug.h index 65ea8fc..7c1cf6a 100644 --- a/src/main/ezusb-iidx-emu/node-security-plug.h +++ b/src/main/ezusb-iidx-emu/node-security-plug.h @@ -9,47 +9,47 @@ /** * Set the boot version of the game. The boot version mcode is used for * bootstrapping the security backend (of the ezusb.dll). - * + * * @param boot_version Pointer to the boot version to set. */ void ezusb_iidx_emu_node_security_plug_set_boot_version( - const struct security_mcode* boot_version); + const struct security_mcode *boot_version); /** * Set the boot seeds. The boot seeds (three numbers >= 0) are used for * bootstrapping the security backend (of the ezusb.dll). - * + * * @param seeds Pointer to an array of three boot seeds to set. */ -void ezusb_iidx_emu_node_security_plug_set_boot_seeds(const uint32_t* seeds); +void ezusb_iidx_emu_node_security_plug_set_boot_seeds(const uint32_t *seeds); /** * The mcode of the target game to boot. This mcode is typically printed onto * the black plug corresponding to the game to boot. - * + * * @param mcode Pointer to the mcode to set. */ void ezusb_iidx_emu_node_security_plug_set_plug_black_mcode( - const struct security_mcode* mcode); + const struct security_mcode *mcode); /** * The mcode of the target game to boot. This is not an actual mcode but to our * knowledge is always the string "@@@@@@@@" which is used to identify the * white plug. - * + * * @param mcode Pointer to the mcode to set. */ void ezusb_iidx_emu_node_security_plug_set_plug_white_mcode( - const struct security_mcode* mcode); + const struct security_mcode *mcode); /** * Set the PCBID. This ID is stored in the ROM of the black plug and is * basically the serial number for the copy of the game. - * + * * @param pcbid Pointer to the PCBID to set. */ void ezusb_iidx_emu_node_security_plug_set_pcbid( - const struct security_id* pcbid); + const struct security_id *pcbid); /** * Set the EAMID. This ID is stored in the ROM of the white plug and is @@ -58,67 +58,67 @@ void ezusb_iidx_emu_node_security_plug_set_pcbid( * (and a bunch of other games). I assume the idea was to have the same EAMID * accross multiple games (e.g. same arcade) but different PCBIDs still * identifying the copies of the games running. - * + * * @param eamid Pointer to the EAMID to set. */ void ezusb_iidx_emu_node_security_plug_set_eamid( - const struct security_id* eamid); + const struct security_id *eamid); /** * Trigger a command on the security node. This call is used on IIDX 9 to 13. - * + * * @param cmd_id Id of the command (see enums). * @param cmd_data Additional data for command (used/unused depending on cmd). * @param cmd_data2 Additional data for command (used/unused depending on cmd). * @return Status value of the executed operation. */ -uint8_t ezusb_iidx_emu_node_security_plug_process_cmd_v1(uint8_t cmd_id, - uint8_t cmd_data, uint8_t cmd_data2); +uint8_t ezusb_iidx_emu_node_security_plug_process_cmd_v1( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2); /** * Trigger a command on the security node. This call is used on IIDX 14 to 17. - * + * * @param cmd_id Id of the command (see enums). * @param cmd_data Additional data for command (used/unused depending on cmd). * @param cmd_data2 Additional data for command (used/unused depending on cmd). * @return Status value of the executed operation. */ -uint8_t ezusb_iidx_emu_node_security_plug_process_cmd_v2(uint8_t cmd_id, - uint8_t cmd_data, uint8_t cmd_data2); +uint8_t ezusb_iidx_emu_node_security_plug_process_cmd_v2( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2); /** * Bulk endpoint to read data from the security node. This is preceeded by * calling a sepcific command (see process cmd functions and enums of cmds). - * + * * This version is used on IIDX 9 to 13. - * + * * @param pkg Pointer to a bulk package to read the data into. * @return True on success, false on error. */ bool ezusb_iidx_emu_node_security_plug_read_packet_v1( - struct ezusb_iidx_msg_bulk_packet* pkg); + struct ezusb_iidx_msg_bulk_packet *pkg); /** * Bulk endpoint to read data from the security node. This is preceeded by * calling a sepcific command (see process cmd functions and enums of cmds). - * + * * This version is used on IIDX 14 to 17. - * + * * @param pkg Pointer to a bulk package to read the data into. * @return True on success, false on error. */ bool ezusb_iidx_emu_node_security_plug_read_packet_v2( - struct ezusb_iidx_msg_bulk_packet* pkg); + struct ezusb_iidx_msg_bulk_packet *pkg); /** * Bulk endpoint to provide data to write to the security node. This is * preceeded by calling a sepcific command (see process cmd functions and enums * of cmds). - * + * * @param pkg Pointer to a bulk package with data to write to the node. * @result True on success, false on error. */ bool ezusb_iidx_emu_node_security_plug_write_packet( - const struct ezusb_iidx_msg_bulk_packet* pkg); + const struct ezusb_iidx_msg_bulk_packet *pkg); #endif \ No newline at end of file diff --git a/src/main/ezusb-iidx-emu/node-serial.c b/src/main/ezusb-iidx-emu/node-serial.c index 767a0fa..a42632d 100644 --- a/src/main/ezusb-iidx-emu/node-serial.c +++ b/src/main/ezusb-iidx-emu/node-serial.c @@ -4,14 +4,14 @@ #include "bemanitools/eamio.h" -#include "ezusb-iidx/serial-cmd.h" #include "ezusb-iidx-emu/card-mag.c" #include "ezusb-iidx-emu/node-serial.h" +#include "ezusb-iidx/serial-cmd.h" #include "security/mcode.h" -#include "util/log.h" #include "util/hex.h" +#include "util/log.h" #include "util/thread.h" #define CARD_ID_LEN 8 @@ -64,8 +64,7 @@ enum ezusb_iidx_emu_node_serial_card_slot_state { #define MAG_CARD_DATA_SIZE 128 -struct ezusb_iidx_emu_node_serial_msg -{ +struct ezusb_iidx_emu_node_serial_msg { uint8_t msg_cmd; uint8_t node_id; uint8_t node_cmd; @@ -182,20 +181,9 @@ struct ezusb_iidx_emu_node_serial_emulation_state { /* ------------------------------------------------------------------------- */ -static const char ezusb_iidx_emu_node_serial_eamio_mapping[EAM_IO_KEYPAD_COUNT] = { - '0', - '1', - '4', - '7', - 'O', - '2', - '5', - '8', - 'E', - '3', - '6', - '9' -}; +static const char + ezusb_iidx_emu_node_serial_eamio_mapping[EAM_IO_KEYPAD_COUNT] = { + '0', '1', '4', '7', 'O', '2', '5', '8', 'E', '3', '6', '9'}; static const uint8_t HEADER_BYTE = 0xAA; @@ -210,21 +198,25 @@ static uint16_t ezusb_iidx_emu_node_serial_write_buf_data_len; static uint8_t ezusb_iidx_emu_node_serial_card_attr_type; static bool ezusb_iidx_emu_node_serial_card_attr_used = true; -static char ezusb_iidx_emu_node_serial_card_attr_version[3] = +static char ezusb_iidx_emu_node_serial_card_attr_version[3] = SECURITY_MCODE_GAME_IIDX_9; -static uint8_t* ezusb_iidx_emu_node_serial_write_loopback_card_buf[2]; +static uint8_t *ezusb_iidx_emu_node_serial_write_loopback_card_buf[2]; static int ezusb_iidx_emu_node_serial_emu_thread = -1; -static struct ezusb_iidx_emu_node_serial_emulation_state ezusb_iidx_emu_node_serial_emulation_state[2]; +static struct ezusb_iidx_emu_node_serial_emulation_state + ezusb_iidx_emu_node_serial_emulation_state[2]; -static void ezusb_iidx_emu_node_serial_dump_buf_log(const char* header_msg, - const uint8_t* buffer, uint16_t length); +static void ezusb_iidx_emu_node_serial_dump_buf_log( + const char *header_msg, const uint8_t *buffer, uint16_t length); -static void ezusb_iidx_emu_node_serial_exec_req_resp(const uint8_t* buffer_in, - uint16_t buffer_in_length, uint8_t* buffer_out, uint16_t* buffer_out_length); +static void ezusb_iidx_emu_node_serial_exec_req_resp( + const uint8_t *buffer_in, + uint16_t buffer_in_length, + uint8_t *buffer_out, + uint16_t *buffer_out_length); -static int ezusb_iidx_emu_node_serial_emu_thread_proc(void* ctx); +static int ezusb_iidx_emu_node_serial_emu_thread_proc(void *ctx); /* ------------------------------------------------------------------------- */ @@ -232,51 +224,60 @@ void ezusb_iidx_emu_node_serial_init(void) { ezusb_iidx_emu_node_serial_read_buf_busy = false; ezusb_iidx_emu_node_serial_write_buf_busy = false; - memset(ezusb_iidx_emu_node_serial_read_buf, 0xFF, sizeof(ezusb_iidx_emu_node_serial_read_buf)); + memset( + ezusb_iidx_emu_node_serial_read_buf, + 0xFF, + sizeof(ezusb_iidx_emu_node_serial_read_buf)); ezusb_iidx_emu_node_serial_read_buf_page = 0; ezusb_iidx_emu_node_serial_read_buf_data_len = 0; - memset(ezusb_iidx_emu_node_serial_write_buf, 0xFF, sizeof(ezusb_iidx_emu_node_serial_write_buf)); + memset( + ezusb_iidx_emu_node_serial_write_buf, + 0xFF, + sizeof(ezusb_iidx_emu_node_serial_write_buf)); ezusb_iidx_emu_node_serial_wrote_buf_page = 0; ezusb_iidx_emu_node_serial_write_buf_data_len = 0; - memset(ezusb_iidx_emu_node_serial_emulation_state, 0, + memset( + ezusb_iidx_emu_node_serial_emulation_state, + 0, sizeof(struct ezusb_iidx_emu_node_serial_emulation_state) * 2); for (uint8_t i = 0; i < 2; i++) { - InitializeCriticalSection(&ezusb_iidx_emu_node_serial_emulation_state[i].card_cs); + InitializeCriticalSection( + &ezusb_iidx_emu_node_serial_emulation_state[i].card_cs); } - ezusb_iidx_emu_node_serial_emu_thread = - thread_create(ezusb_iidx_emu_node_serial_emu_thread_proc, NULL, 0x4000, 0); + ezusb_iidx_emu_node_serial_emu_thread = thread_create( + ezusb_iidx_emu_node_serial_emu_thread_proc, NULL, 0x4000, 0); } -uint8_t ezusb_iidx_emu_node_serial_process_cmd(uint8_t cmd_id, uint8_t cmd_data, - uint8_t cmd_data2) +uint8_t ezusb_iidx_emu_node_serial_process_cmd( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2) { switch (cmd_id) { case EZUSB_IIDX_SERIAL_CMD_READ_BUFFER: - //log_misc("EZUSB_SERIAL_CMD_READ_BUFFER"); + // log_misc("EZUSB_SERIAL_CMD_READ_BUFFER"); ezusb_iidx_emu_node_serial_read_buf_busy = false; /* always reset page count on req */ ezusb_iidx_emu_node_serial_read_buf_page = 0; return EZUSB_IIDX_SERIAL_CMD_STATUS_OK; case EZUSB_IIDX_SERIAL_CMD_WRITE_BUFFER: - //log_misc("EZUSB_SERIAL_CMD_WRITE_BUFFER"); + // log_misc("EZUSB_SERIAL_CMD_WRITE_BUFFER"); ezusb_iidx_emu_node_serial_write_buf_busy = false; /* always reset page count on req */ ezusb_iidx_emu_node_serial_wrote_buf_page = 0; return EZUSB_IIDX_SERIAL_CMD_STATUS_OK; case EZUSB_IIDX_SERIAL_CMD_CLEAR_READ_BUFFER: - //log_misc("EZUSB_SERIAL_CMD_CLEAR_READ_BUFFER"); + // log_misc("EZUSB_SERIAL_CMD_CLEAR_READ_BUFFER"); ezusb_iidx_emu_node_serial_read_buf_busy = false; /* always reset page count on req */ ezusb_iidx_emu_node_serial_read_buf_page = 0; return EZUSB_IIDX_SERIAL_CMD_STATUS_OK; case EZUSB_IIDX_SERIAL_CMD_CLEAR_WRITE_BUFFER: - //log_misc("EZUSB_SERIAL_CMD_CLEAR_WRITE_BUFFER"); + // log_misc("EZUSB_SERIAL_CMD_CLEAR_WRITE_BUFFER"); ezusb_iidx_emu_node_serial_write_buf_busy = false; /* always reset page count on req */ ezusb_iidx_emu_node_serial_wrote_buf_page = 0; @@ -288,7 +289,8 @@ uint8_t ezusb_iidx_emu_node_serial_process_cmd(uint8_t cmd_id, uint8_t cmd_data, } } -bool ezusb_iidx_emu_node_serial_read_packet(struct ezusb_iidx_msg_bulk_packet* pkg) +bool ezusb_iidx_emu_node_serial_read_packet( + struct ezusb_iidx_msg_bulk_packet *pkg) { uint16_t buffer_offset = 0; uint16_t data_length = 0; @@ -300,7 +302,8 @@ bool ezusb_iidx_emu_node_serial_read_packet(struct ezusb_iidx_msg_bulk_packet* p memset(pkg->payload, 0xFF, sizeof(pkg->payload)); /* calc data size */ - buffer_offset = ezusb_iidx_emu_node_serial_read_buf_page * sizeof(pkg->payload); + buffer_offset = + ezusb_iidx_emu_node_serial_read_buf_page * sizeof(pkg->payload); if (ezusb_iidx_emu_node_serial_read_buf_data_len >= sizeof(pkg->payload)) { data_length = sizeof(pkg->payload); @@ -312,18 +315,23 @@ bool ezusb_iidx_emu_node_serial_read_packet(struct ezusb_iidx_msg_bulk_packet* p ezusb_iidx_emu_node_serial_read_buf_data_len = 0; } - memcpy(pkg->payload, ezusb_iidx_emu_node_serial_read_buf + buffer_offset, data_length); + memcpy( + pkg->payload, + ezusb_iidx_emu_node_serial_read_buf + buffer_offset, + data_length); return true; } -bool ezusb_iidx_emu_node_serial_write_packet(const struct ezusb_iidx_msg_bulk_packet* pkg) +bool ezusb_iidx_emu_node_serial_write_packet( + const struct ezusb_iidx_msg_bulk_packet *pkg) { bool execute = false; uint16_t buffer_offset = 0; uint16_t data_length = 0; - buffer_offset = ezusb_iidx_emu_node_serial_wrote_buf_page * sizeof(pkg->payload); + buffer_offset = + ezusb_iidx_emu_node_serial_wrote_buf_page * sizeof(pkg->payload); /* the stuff getting received here is a serial stream which is terminated by a size >= 0x42 @@ -339,14 +347,19 @@ bool ezusb_iidx_emu_node_serial_write_packet(const struct ezusb_iidx_msg_bulk_pa } ezusb_iidx_emu_node_serial_write_buf_data_len += data_length; - memcpy(ezusb_iidx_emu_node_serial_write_buf + buffer_offset, pkg->payload, data_length); + memcpy( + ezusb_iidx_emu_node_serial_write_buf + buffer_offset, + pkg->payload, + data_length); /* serial buffer is filled, execute request/response chain dunno if this is a good spot to do this... */ if (execute) { - ezusb_iidx_emu_node_serial_exec_req_resp(ezusb_iidx_emu_node_serial_write_buf, - ezusb_iidx_emu_node_serial_write_buf_data_len, ezusb_iidx_emu_node_serial_read_buf, + ezusb_iidx_emu_node_serial_exec_req_resp( + ezusb_iidx_emu_node_serial_write_buf, + ezusb_iidx_emu_node_serial_write_buf_data_len, + ezusb_iidx_emu_node_serial_read_buf, &ezusb_iidx_emu_node_serial_read_buf_data_len); /* not sure, but there seems to be a bug with the game @@ -371,19 +384,21 @@ bool ezusb_iidx_emu_node_serial_write_buffer_busy(void) return ezusb_iidx_emu_node_serial_write_buf_busy; } -void ezusb_iidx_emu_node_serial_set_card_attributes(uint8_t card_type, bool used_card, - const char* card_version) +void ezusb_iidx_emu_node_serial_set_card_attributes( + uint8_t card_type, bool used_card, const char *card_version) { ezusb_iidx_emu_node_serial_card_attr_type = card_type > 4 ? 4 : card_type; ezusb_iidx_emu_node_serial_card_attr_used = used_card; - memcpy(ezusb_iidx_emu_node_serial_card_attr_version, card_version, + memcpy( + ezusb_iidx_emu_node_serial_card_attr_version, + card_version, SECURITY_MCODE_GAME_LEN); } /* ------------------------------------------------------------------------- */ -static void ezusb_iidx_emu_node_serial_dump_buf_log(const char* header_msg, - const uint8_t* buffer, uint16_t length) +static void ezusb_iidx_emu_node_serial_dump_buf_log( + const char *header_msg, const uint8_t *buffer, uint16_t length) { char tmp[4096]; memset(tmp, 0, sizeof(tmp)); @@ -391,7 +406,8 @@ static void ezusb_iidx_emu_node_serial_dump_buf_log(const char* header_msg, log_misc(">>> Serial data dump, %s (%d): %s", header_msg, length, tmp); } -static uint8_t calc_serial_buffer_checksum(const uint8_t* buffer, uint16_t length) +static uint8_t +calc_serial_buffer_checksum(const uint8_t *buffer, uint16_t length) { uint8_t checksum = 0; for (size_t i = 0; i < length; i++) @@ -400,11 +416,11 @@ static uint8_t calc_serial_buffer_checksum(const uint8_t* buffer, uint16_t lengt return checksum; } -static struct ezusb_iidx_emu_node_serial_msg* create_generic_node_response_ok( - const struct ezusb_iidx_emu_node_serial_msg* msg_in, uint16_t* msg_out_len) +static struct ezusb_iidx_emu_node_serial_msg *create_generic_node_response_ok( + const struct ezusb_iidx_emu_node_serial_msg *msg_in, uint16_t *msg_out_len) { *msg_out_len = 4 + 1; - struct ezusb_iidx_emu_node_serial_msg* resp = malloc(*msg_out_len); + struct ezusb_iidx_emu_node_serial_msg *resp = malloc(*msg_out_len); resp->msg_cmd = CMD_NODE_RESP; resp->node_id = msg_in->node_id; resp->node_cmd = msg_in->node_cmd; @@ -413,25 +429,26 @@ static struct ezusb_iidx_emu_node_serial_msg* create_generic_node_response_ok( return resp; } -static struct ezusb_iidx_emu_node_serial_msg* process_serial_msg( - const struct ezusb_iidx_emu_node_serial_msg* msg_in, - uint16_t msg_in_len, uint16_t* msg_out_len) +static struct ezusb_iidx_emu_node_serial_msg *process_serial_msg( + const struct ezusb_iidx_emu_node_serial_msg *msg_in, + uint16_t msg_in_len, + uint16_t *msg_out_len) { - //log_misc("!!! Serial processing msg_cmd %02X, node_cmd %02X, node_id %02X", + // log_misc("!!! Serial processing msg_cmd %02X, node_cmd %02X, node_id + // %02X", // msg_in->msg_cmd, msg_in->node_cmd, msg_in->node_id); switch (msg_in->msg_cmd) { - case CMD_H8_REQ: - { - + case CMD_H8_REQ: { switch (msg_in->node_cmd) { - case H8_CMD_NODE_ENUM: - { + case H8_CMD_NODE_ENUM: { log_misc("H8_CMD_NODE_ENUM"); *msg_out_len = 4 + 1; - struct ezusb_iidx_emu_node_serial_msg* resp = malloc(*msg_out_len); + struct ezusb_iidx_emu_node_serial_msg *resp = + malloc(*msg_out_len); resp->msg_cmd = CMD_H8_RESP; - /* This response is not from a specific node, id needs to be 0 */ + /* This response is not from a specific node, id needs to be + * 0 */ resp->node_id = 0; resp->node_cmd = msg_in->node_cmd; resp->payload_len = 1; @@ -439,16 +456,16 @@ static struct ezusb_iidx_emu_node_serial_msg* process_serial_msg( return resp; } - case H8_CMD_GET_VERSION: - { + case H8_CMD_GET_VERSION: { log_misc("H8_CMD_GET_VERSION: %d", msg_in->node_id); *msg_out_len = 4 + 13; - struct ezusb_iidx_emu_node_serial_msg* resp = malloc(*msg_out_len); + struct ezusb_iidx_emu_node_serial_msg *resp = + malloc(*msg_out_len); resp->msg_cmd = CMD_H8_RESP; resp->node_id = msg_in->node_id; resp->node_cmd = msg_in->node_cmd; - /* Payload length is not 13 here, needs to 5 (comment length?) - Might be a bug in the ezusb code */ + /* Payload length is not 13 here, needs to 5 (comment + length?) Might be a bug in the ezusb code */ resp->payload_len = 5; resp->get_version_resp.type = 0x03; resp->get_version_resp.dup = 0x00; @@ -463,32 +480,34 @@ static struct ezusb_iidx_emu_node_serial_msg* process_serial_msg( return resp; } - case H8_CMD_PROG_EXEC: - { + case H8_CMD_PROG_EXEC: { log_misc("H8_CMD_PROG_EXEC: %d", msg_in->node_id); *msg_out_len = 4 + 1; - struct ezusb_iidx_emu_node_serial_msg* resp = malloc(*msg_out_len); + struct ezusb_iidx_emu_node_serial_msg *resp = + malloc(*msg_out_len); resp->msg_cmd = CMD_H8_RESP; resp->node_id = msg_in->node_id; resp->node_cmd = msg_in->node_cmd; resp->payload_len = 1; /* init reader emulation here if not initialized, yet */ - uint8_t state = - ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1] - .state_current; + uint8_t state = ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .state_current; if (state == EMU_STATE_UNINIT) { InterlockedExchange( - &ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1] - .state_current, EMU_STATE_INIT); + &ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .state_current, + EMU_STATE_INIT); /* this should not take too long, wait */ while (true) { - state = - ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1] - .state_current; + state = ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .state_current; if (state == EMU_STATE_LOOP) { resp->common_status_resp.status = 0; @@ -501,30 +520,27 @@ static struct ezusb_iidx_emu_node_serial_msg* process_serial_msg( Sleep(10); } } else { - if (state == EMU_STATE_ERROR) { resp->common_status_resp.status = 0xFF; } else { resp->common_status_resp.status = 0; } - } return resp; } default: - log_warning("Serial invalid node cmd on h8 req: %02X", - msg_in->node_cmd); - ezusb_iidx_emu_node_serial_dump_buf_log("", (const uint8_t*) msg_in, - msg_in_len); + log_warning( + "Serial invalid node cmd on h8 req: %02X", + msg_in->node_cmd); + ezusb_iidx_emu_node_serial_dump_buf_log( + "", (const uint8_t *) msg_in, msg_in_len); return NULL; } } - case CMD_NODE_REQ: - { - + case CMD_NODE_REQ: { switch (msg_in->node_cmd) { case NODE_CMD_CARD_INIT: log_misc("NODE_CMD_CARD_INIT: %d", msg_in->node_id); @@ -540,114 +556,131 @@ static struct ezusb_iidx_emu_node_serial_msg* process_serial_msg( case NODE_CMD_CARD_GET_STATUS: return create_generic_node_response_ok(msg_in, msg_out_len); - case NODE_CMD_CARD_RW_UNIT_GET_STATUS: - { + case NODE_CMD_CARD_RW_UNIT_GET_STATUS: { /* report front and back sensor states */ *msg_out_len = 4 + 1; - struct ezusb_iidx_emu_node_serial_msg* resp = malloc(*msg_out_len); + struct ezusb_iidx_emu_node_serial_msg *resp = + malloc(*msg_out_len); resp->msg_cmd = CMD_NODE_RESP; resp->node_id = msg_in->node_id; resp->node_cmd = msg_in->node_cmd; resp->payload_len = 1; resp->common_status_resp.status = 0; - if ( ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1] - .state_current == EMU_STATE_ERROR) { + if (ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .state_current == EMU_STATE_ERROR) { resp->common_status_resp.status = 0xFF; } else { - - if ( ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1] - .card_slot_sensor_back) { + if (ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .card_slot_sensor_back) { /* back, triggers card inserted */ resp->common_status_resp.status |= 128; - /* needs to be set if either front or back is triggered */ + /* needs to be set if either front or back is + * triggered */ resp->common_status_resp.status |= 2; } - if ( ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1] - .card_slot_sensor_front) { + if (ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .card_slot_sensor_front) { /* front */ resp->common_status_resp.status |= 64; - /* needs to be set if either front or back is triggered */ + /* needs to be set if either front or back is + * triggered */ resp->common_status_resp.status |= 2; } - } return resp; } - case NODE_CMD_CARD_SLOT_SET_STATE: - { - switch (msg_in->card_slot_state_req.ezusb_iidx_emu_node_serial_card_slot_state) { + case NODE_CMD_CARD_SLOT_SET_STATE: { + switch (msg_in->card_slot_state_req + .ezusb_iidx_emu_node_serial_card_slot_state) { case CARD_SLOT_STATE_CLOSE: - log_misc("CARD_SLOT_STATE_CLOSE, node %d", - msg_in->node_id); + log_misc( + "CARD_SLOT_STATE_CLOSE, node %d", + msg_in->node_id); - ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1] - .ezusb_iidx_emu_node_serial_card_slot_state = + ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .ezusb_iidx_emu_node_serial_card_slot_state = EMU_CARD_SLOT_STATE_CLOSE; break; case CARD_SLOT_STATE_OPEN: - log_misc("CARD_SLOT_STATE_OPEN, node %d", - msg_in->node_id); + log_misc( + "CARD_SLOT_STATE_OPEN, node %d", + msg_in->node_id); - ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1] - .ezusb_iidx_emu_node_serial_card_slot_state = + ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .ezusb_iidx_emu_node_serial_card_slot_state = EMU_CARD_SLOT_STATE_OPEN; break; case CARD_SLOT_STATE_EJECT: - log_misc("CARD_SLOT_STATE_EJECT, node %d", - msg_in->node_id); + log_misc( + "CARD_SLOT_STATE_EJECT, node %d", + msg_in->node_id); - ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1] - .ezusb_iidx_emu_node_serial_card_slot_state = + ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .ezusb_iidx_emu_node_serial_card_slot_state = EMU_CARD_SLOT_STATE_EJECT; break; case CARD_SLOT_STATE_FORMAT: - log_misc("CARD_SLOT_STATE_FORMAT, node %d", - msg_in->node_id); + log_misc( + "CARD_SLOT_STATE_FORMAT, node %d", + msg_in->node_id); break; case CARD_SLOT_STATE_READ: - log_misc("CARD_SLOT_STATE_READ, node %d", - msg_in->node_id); + log_misc( + "CARD_SLOT_STATE_READ, node %d", + msg_in->node_id); InterlockedExchange( - &ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1] - .state_current, EMU_STATE_REQ_CARD); + &ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .state_current, + EMU_STATE_REQ_CARD); - ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1] - .ezusb_iidx_emu_node_serial_card_slot_state = + ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .ezusb_iidx_emu_node_serial_card_slot_state = EMU_CARD_SLOT_STATE_READ; break; case CARD_SLOT_STATE_WRITE: - log_misc("CARD_SLOT_STATE_WRITE, node %d", - msg_in->node_id); + log_misc( + "CARD_SLOT_STATE_WRITE, node %d", + msg_in->node_id); break; default: - log_warning("Invalid card slot state %d for node %d", + log_warning( + "Invalid card slot state %d for node %d", msg_in->card_slot_state_req - .ezusb_iidx_emu_node_serial_card_slot_state, msg_in->node_id); + .ezusb_iidx_emu_node_serial_card_slot_state, + msg_in->node_id); } return create_generic_node_response_ok(msg_in, msg_out_len); } - case NODE_CMD_CARD_READ: - { + case NODE_CMD_CARD_READ: { *msg_out_len = 4 + 129; - struct ezusb_iidx_emu_node_serial_msg* resp = malloc(*msg_out_len); + struct ezusb_iidx_emu_node_serial_msg *resp = + malloc(*msg_out_len); resp->msg_cmd = CMD_NODE_RESP; resp->node_id = msg_in->node_id; resp->node_cmd = msg_in->node_cmd; @@ -659,20 +692,22 @@ static struct ezusb_iidx_emu_node_serial_msg* process_serial_msg( /* loop back read for write (see write) */ - if (ezusb_iidx_emu_node_serial_write_loopback_card_buf[msg_in->node_id - 1] == NULL) { - - struct ezusb_iidx_emu_card_mag_data* card = - (struct ezusb_iidx_emu_card_mag_data*) - resp->card_read_resp.data; + if (ezusb_iidx_emu_node_serial_write_loopback_card_buf + [msg_in->node_id - 1] == NULL) { + struct ezusb_iidx_emu_card_mag_data *card = + (struct ezusb_iidx_emu_card_mag_data *) + resp->card_read_resp.data; uint8_t state = - ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1] - .state_current; + ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .state_current; /* wait for card to get read */ while (state == EMU_STATE_REQ_CARD) { - state = ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1] - .state_current; + state = ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .state_current; Sleep(5); } @@ -680,43 +715,66 @@ static struct ezusb_iidx_emu_node_serial_msg* process_serial_msg( uint8_t card_invert[CARD_ID_LEN]; EnterCriticalSection( - &ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1] - .card_cs); + &ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .card_cs); - log_info("Read card %02X%02X%02X%02X%02X%02X%02X%02X", - ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1].card_id[0], - ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1].card_id[1], - ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1].card_id[2], - ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1].card_id[3], - ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1].card_id[4], - ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1].card_id[5], - ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1].card_id[6], - ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1].card_id[7]); + log_info( + "Read card %02X%02X%02X%02X%02X%02X%02X%02X", + ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .card_id[0], + ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .card_id[1], + ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .card_id[2], + ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .card_id[3], + ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .card_id[4], + ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .card_id[5], + ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .card_id[6], + ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .card_id[7]); /* game flips endianess */ for (uint8_t i = 0; i < CARD_ID_LEN; i++) { card_invert[7 - i] = - ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1] - .card_id[i]; + ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .card_id[i]; } - ezusb_iidx_emu_card_mag_generate_data(card, + ezusb_iidx_emu_card_mag_generate_data( + card, card_invert, ezusb_iidx_emu_node_serial_card_attr_type, ezusb_iidx_emu_node_serial_card_attr_used, ezusb_iidx_emu_node_serial_card_attr_version); - /* ezusb_iidx_emu_node_serial_dump_buf_log("card data", - resp->card_read_resp.data, - sizeof(struct ezusb_iidx_emu_card_mag_data)); */ + /* ezusb_iidx_emu_node_serial_dump_buf_log("card + data", resp->card_read_resp.data, sizeof(struct + ezusb_iidx_emu_card_mag_data)); */ InterlockedExchange( - &ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1] - .state_current, EMU_STATE_LOOP); + &ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .state_current, + EMU_STATE_LOOP); LeaveCriticalSection( - &ezusb_iidx_emu_node_serial_emulation_state[msg_in->node_id - 1] - .card_cs); + &ezusb_iidx_emu_node_serial_emulation_state + [msg_in->node_id - 1] + .card_cs); } else if (state == EMU_STATE_ERROR) { /* this indicates an error */ @@ -725,48 +783,56 @@ static struct ezusb_iidx_emu_node_serial_msg* process_serial_msg( } } else { log_misc("Reading loopback card buffer"); - memcpy(resp->card_read_resp.data, - ezusb_iidx_emu_node_serial_write_loopback_card_buf[msg_in->node_id - 1], - MAG_CARD_DATA_SIZE); + memcpy( + resp->card_read_resp.data, + ezusb_iidx_emu_node_serial_write_loopback_card_buf + [msg_in->node_id - 1], + MAG_CARD_DATA_SIZE); - free(ezusb_iidx_emu_node_serial_write_loopback_card_buf[msg_in->node_id - 1]); - ezusb_iidx_emu_node_serial_write_loopback_card_buf[msg_in->node_id - 1] = NULL; + free(ezusb_iidx_emu_node_serial_write_loopback_card_buf + [msg_in->node_id - 1]); + ezusb_iidx_emu_node_serial_write_loopback_card_buf + [msg_in->node_id - 1] = NULL; } return resp; } - case NODE_CMD_CARD_WRITE: - { + case NODE_CMD_CARD_WRITE: { /* i hate this solution, but it gets rid of the problem that we don't know the whole magnetic card spec and the game is ok with just a bunch of them when read only If a write occurs (for example if the card is registered for a new player) we will cashe the data which arrives on - the write and loop it back on the next read (next read only) */ + the write and loop it back on the next read (next read + only) */ - if (ezusb_iidx_emu_node_serial_write_loopback_card_buf[msg_in->node_id - 1] != NULL) { - free(ezusb_iidx_emu_node_serial_write_loopback_card_buf[msg_in->node_id - 1]); + if (ezusb_iidx_emu_node_serial_write_loopback_card_buf + [msg_in->node_id - 1] != NULL) { + free(ezusb_iidx_emu_node_serial_write_loopback_card_buf + [msg_in->node_id - 1]); } - ezusb_iidx_emu_node_serial_write_loopback_card_buf[msg_in->node_id - 1] = - malloc(MAG_CARD_DATA_SIZE); - memcpy(ezusb_iidx_emu_node_serial_write_loopback_card_buf[msg_in->node_id - 1], - msg_in->card_write_req.data, MAG_CARD_DATA_SIZE); + ezusb_iidx_emu_node_serial_write_loopback_card_buf + [msg_in->node_id - 1] = malloc(MAG_CARD_DATA_SIZE); + memcpy( + ezusb_iidx_emu_node_serial_write_loopback_card_buf + [msg_in->node_id - 1], + msg_in->card_write_req.data, + MAG_CARD_DATA_SIZE); return create_generic_node_response_ok(msg_in, msg_out_len); } - case NODE_CMD_CARD_FORMAT_COMPLETE: - { + case NODE_CMD_CARD_FORMAT_COMPLETE: { /* just reply, no handling of data necessary */ return create_generic_node_response_ok(msg_in, msg_out_len); } - case NODE_CMD_KEYBOARD_GET_BUFFER_SIZE: - { + case NODE_CMD_KEYBOARD_GET_BUFFER_SIZE: { *msg_out_len = 4 + 2; - struct ezusb_iidx_emu_node_serial_msg* resp = malloc(*msg_out_len); + struct ezusb_iidx_emu_node_serial_msg *resp = + malloc(*msg_out_len); resp->msg_cmd = CMD_NODE_RESP; resp->node_id = msg_in->node_id; resp->node_cmd = msg_in->node_cmd; @@ -791,7 +857,8 @@ static struct ezusb_iidx_emu_node_serial_msg* process_serial_msg( uint16_t bufferSize = 0; uint8_t node = msg_in->node_id - 1; - if (ezusb_iidx_emu_node_serial_emulation_state[node].keypad_buf != 0) { + if (ezusb_iidx_emu_node_serial_emulation_state[node] + .keypad_buf != 0) { bufferSize = 1; } @@ -802,65 +869,83 @@ static struct ezusb_iidx_emu_node_serial_msg* process_serial_msg( resp->keyboard_get_buffer_size_resp.buffer_size_type = bufferSize; } else if (bufferSize <= 4) { - resp->keyboard_get_buffer_size_resp.buffer_size_type = 3; + resp->keyboard_get_buffer_size_resp.buffer_size_type = + 3; } else if (bufferSize <= 8) { - resp->keyboard_get_buffer_size_resp.buffer_size_type = 4; + resp->keyboard_get_buffer_size_resp.buffer_size_type = + 4; } else if (bufferSize <= 16) { - resp->keyboard_get_buffer_size_resp.buffer_size_type = 5; + resp->keyboard_get_buffer_size_resp.buffer_size_type = + 5; } else if (bufferSize <= 32) { - resp->keyboard_get_buffer_size_resp.buffer_size_type = 6; + resp->keyboard_get_buffer_size_resp.buffer_size_type = + 6; } else { /* avoid overflow, clip everything else */ - resp->keyboard_get_buffer_size_resp.buffer_size_type = 7; + resp->keyboard_get_buffer_size_resp.buffer_size_type = + 7; } return resp; } - case NODE_CMD_KEYBOARD_READ_DATA: - { + case NODE_CMD_KEYBOARD_READ_DATA: { *msg_out_len = 4 + 2; - struct ezusb_iidx_emu_node_serial_msg* resp = malloc(*msg_out_len); + struct ezusb_iidx_emu_node_serial_msg *resp = + malloc(*msg_out_len); resp->msg_cmd = CMD_NODE_RESP; resp->node_id = msg_in->node_id; resp->node_cmd = msg_in->node_cmd; /* has to be the same as the size returned */ - resp->payload_len = msg_in->keyboard_read_data_req.buffer_size_type; + resp->payload_len = + msg_in->keyboard_read_data_req.buffer_size_type; uint8_t maxBufferSize = 0; /* convert back */ - switch (msg_in->keyboard_read_data_req.buffer_size_type) - { + switch (msg_in->keyboard_read_data_req.buffer_size_type) { case 0: - maxBufferSize = 0; break; + maxBufferSize = 0; + break; case 1: - maxBufferSize = 1; break; + maxBufferSize = 1; + break; case 2: - maxBufferSize = 2; break; + maxBufferSize = 2; + break; case 3: - maxBufferSize = 4; break; + maxBufferSize = 4; + break; case 4: - maxBufferSize = 8; break; + maxBufferSize = 8; + break; case 5: - maxBufferSize = 16; break; + maxBufferSize = 16; + break; case 6: - maxBufferSize = 32; break; + maxBufferSize = 32; + break; case 7: - maxBufferSize = 64; break; + maxBufferSize = 64; + break; default: - log_fatal("Invalid buffer size %d for reading keyboard data.", - msg_in->keyboard_read_data_req.buffer_size_type); + log_fatal( + "Invalid buffer size %d for reading keyboard " + "data.", + msg_in->keyboard_read_data_req + .buffer_size_type); break; } - memset(resp->keyboard_read_data_resp.data, 0, maxBufferSize); + memset( + resp->keyboard_read_data_resp.data, 0, maxBufferSize); if (maxBufferSize > 0) { uint8_t node = msg_in->node_id - 1; - resp->keyboard_read_data_resp.data[0] = - InterlockedExchange( - &ezusb_iidx_emu_node_serial_emulation_state[node].keypad_buf, + resp->keyboard_read_data_resp + .data[0] = InterlockedExchange( + &ezusb_iidx_emu_node_serial_emulation_state[node] + .keypad_buf, 0); } @@ -868,23 +953,28 @@ static struct ezusb_iidx_emu_node_serial_msg* process_serial_msg( } default: - log_warning("Serial invalid node cmd on node req: %02X", - msg_in->node_cmd); - ezusb_iidx_emu_node_serial_dump_buf_log("", (const uint8_t*) msg_in, - msg_in_len); + log_warning( + "Serial invalid node cmd on node req: %02X", + msg_in->node_cmd); + ezusb_iidx_emu_node_serial_dump_buf_log( + "", (const uint8_t *) msg_in, msg_in_len); return NULL; } } default: log_warning("Serial invalid msg cmd id %02X", msg_in->msg_cmd); - ezusb_iidx_emu_node_serial_dump_buf_log("", (const uint8_t*) msg_in, msg_in_len); + ezusb_iidx_emu_node_serial_dump_buf_log( + "", (const uint8_t *) msg_in, msg_in_len); return NULL; } } -static void ezusb_iidx_emu_node_serial_exec_req_resp(const uint8_t* buffer_in, - uint16_t buffer_in_length, uint8_t* buffer_out, uint16_t* buffer_out_length) +static void ezusb_iidx_emu_node_serial_exec_req_resp( + const uint8_t *buffer_in, + uint16_t buffer_in_length, + uint8_t *buffer_out, + uint16_t *buffer_out_length) { /* data layout index 0: 0xAA header byte always @@ -895,10 +985,11 @@ static void ezusb_iidx_emu_node_serial_exec_req_resp(const uint8_t* buffer_in, no escape byte like on newer readers here */ /* Before we do any processing: - Filter garbage/broken messages. Maybe caused by buggy code (?) some messages - during the uart init phase start with 0x00 and don't have a valid checksum. - However, the game wants a response for that but doesn't care about the contents - so we just throw the trash back where it came from */ + Filter garbage/broken messages. Maybe caused by buggy code (?) some + messages during the uart init phase start with 0x00 and don't have a + valid checksum. However, the game wants a response for that but doesn't + care about the contents so we just throw the trash back where it came + from */ /* ezusb_iidx_emu_node_serial_dump_buf_log("request packed", @@ -906,7 +997,8 @@ static void ezusb_iidx_emu_node_serial_exec_req_resp(const uint8_t* buffer_in, */ if ((buffer_in_length > 0 && buffer_in[0] == 0x00) || - /* That's some uart init/reset message. Response expected, same message */ + /* That's some uart init/reset message. Response expected, same message + */ (buffer_in_length == 4 && buffer_in[0] == 0xAA)) { *buffer_out_length = buffer_in_length; memcpy(buffer_out, buffer_in, buffer_in_length); @@ -917,7 +1009,8 @@ static void ezusb_iidx_emu_node_serial_exec_req_resp(const uint8_t* buffer_in, if (buffer_in_length > 0 && buffer_in[0] != HEADER_BYTE) { log_warning("Invalid serial message, not starting with header byte"); - ezusb_iidx_emu_node_serial_dump_buf_log("", (const uint8_t*) buffer_in, buffer_in_length); + ezusb_iidx_emu_node_serial_dump_buf_log( + "", (const uint8_t *) buffer_in, buffer_in_length); *buffer_out_length = 0; return; } @@ -925,16 +1018,16 @@ static void ezusb_iidx_emu_node_serial_exec_req_resp(const uint8_t* buffer_in, /* Checksum of each message is all data between header and checksum byte (last byte of msg) */ - if (buffer_in[buffer_in_length - 1] != calc_serial_buffer_checksum( - buffer_in + 1, buffer_in_length - 2)) { + if (buffer_in[buffer_in_length - 1] != + calc_serial_buffer_checksum(buffer_in + 1, buffer_in_length - 2)) { log_warning("Serial message invalid checksum"); - ezusb_iidx_emu_node_serial_dump_buf_log("", buffer_in, buffer_in_length); + ezusb_iidx_emu_node_serial_dump_buf_log( + "", buffer_in, buffer_in_length); *buffer_out_length = 0; return; } - - const uint8_t* msg_buf_in = &buffer_in[1]; + const uint8_t *msg_buf_in = &buffer_in[1]; uint16_t msg_buf_in_len = buffer_in_length - 2; /* Exception: catch uart init/reset message, game expects to respond with @@ -942,8 +1035,8 @@ static void ezusb_iidx_emu_node_serial_exec_req_resp(const uint8_t* buffer_in, back once only by the game */ if (msg_buf_in_len == 2 && msg_buf_in[0] == HEADER_BYTE && - msg_buf_in[1] == HEADER_BYTE) { - uint8_t* msg_buf_out = &buffer_out[1]; + msg_buf_in[1] == HEADER_BYTE) { + uint8_t *msg_buf_out = &buffer_out[1]; uint16_t msg_buf_out_len = 0; msg_buf_out[0] = HEADER_BYTE; @@ -951,22 +1044,24 @@ static void ezusb_iidx_emu_node_serial_exec_req_resp(const uint8_t* buffer_in, msg_buf_out_len = 2; buffer_out[0] = HEADER_BYTE; - buffer_out[msg_buf_out_len + 1] = calc_serial_buffer_checksum(msg_buf_out, - msg_buf_out_len); + buffer_out[msg_buf_out_len + 1] = + calc_serial_buffer_checksum(msg_buf_out, msg_buf_out_len); *buffer_out_length = msg_buf_out_len + 2; } else { /* Wtf, really? */ /* All messages except the uart init/reset and node enum message must send the request they respond to along... */ - const struct ezusb_iidx_emu_node_serial_msg* msg_in = - (const struct ezusb_iidx_emu_node_serial_msg*) msg_buf_in; + const struct ezusb_iidx_emu_node_serial_msg *msg_in = + (const struct ezusb_iidx_emu_node_serial_msg *) msg_buf_in; - if (msg_in->msg_cmd == CMD_H8_REQ && msg_in->node_cmd == H8_CMD_NODE_ENUM) { - uint8_t* msg_buf_out = &buffer_out[1]; + if (msg_in->msg_cmd == CMD_H8_REQ && + msg_in->node_cmd == H8_CMD_NODE_ENUM) { + uint8_t *msg_buf_out = &buffer_out[1]; uint16_t msg_buf_out_len = 0; - struct ezusb_iidx_emu_node_serial_msg* msg_out = - process_serial_msg((const struct ezusb_iidx_emu_node_serial_msg*) msg_buf_in, - msg_buf_in_len, &msg_buf_out_len); + struct ezusb_iidx_emu_node_serial_msg *msg_out = process_serial_msg( + (const struct ezusb_iidx_emu_node_serial_msg *) msg_buf_in, + msg_buf_in_len, + &msg_buf_out_len); if (msg_out == NULL) { *buffer_out_length = 0; @@ -978,16 +1073,17 @@ static void ezusb_iidx_emu_node_serial_exec_req_resp(const uint8_t* buffer_in, /* pack serial out data, add header and checksum */ buffer_out[0] = HEADER_BYTE; - buffer_out[msg_buf_out_len + 1] = calc_serial_buffer_checksum( - msg_buf_out, msg_buf_out_len); + buffer_out[msg_buf_out_len + 1] = + calc_serial_buffer_checksum(msg_buf_out, msg_buf_out_len); *buffer_out_length = msg_buf_out_len + 2; } else { /* everything else that's not fucked up */ - uint8_t* msg_buf_out = &buffer_out[buffer_in_length + 1]; + uint8_t *msg_buf_out = &buffer_out[buffer_in_length + 1]; uint16_t msg_buf_out_len = 0; - struct ezusb_iidx_emu_node_serial_msg* msg_out = - process_serial_msg((const struct ezusb_iidx_emu_node_serial_msg*) msg_buf_in, - msg_buf_in_len, &msg_buf_out_len); + struct ezusb_iidx_emu_node_serial_msg *msg_out = process_serial_msg( + (const struct ezusb_iidx_emu_node_serial_msg *) msg_buf_in, + msg_buf_in_len, + &msg_buf_out_len); if (msg_out == NULL) { *buffer_out_length = 0; @@ -1004,10 +1100,9 @@ static void ezusb_iidx_emu_node_serial_exec_req_resp(const uint8_t* buffer_in, of the full response buffer), add header and checksum */ buffer_out[buffer_in_length] = HEADER_BYTE; buffer_out[buffer_in_length + msg_buf_out_len + 1] = - calc_serial_buffer_checksum(msg_buf_out, msg_buf_out_len); + calc_serial_buffer_checksum(msg_buf_out, msg_buf_out_len); *buffer_out_length = buffer_in_length + msg_buf_out_len + 2; - } } @@ -1021,22 +1116,35 @@ static void ezusb_iidx_emu_node_serial_exec_req_resp(const uint8_t* buffer_in, static uint8_t convert_keyboard_char(char c) { - switch (c) { - case '0': return 0x70; - case '1': return 0x69; - case '2': return 0x72; - case '3': return 0x7A; - case '4': return 0x6B; - case '5': return 0x73; - case '6': return 0x74; - case '7': return 0x6C; - case '8': return 0x75; - case '9': return 0x7D; + switch (c) { + case '0': + return 0x70; + case '1': + return 0x69; + case '2': + return 0x72; + case '3': + return 0x7A; + case '4': + return 0x6B; + case '5': + return 0x73; + case '6': + return 0x74; + case '7': + return 0x6C; + case '8': + return 0x75; + case '9': + return 0x7D; /* seems like 00 is not supported, use 0 instead */ - case 'O': return 0x70; + case 'O': + return 0x70; /* that's deleting/backspace */ - case 'E': return 0x66; - default: return 0; + case 'E': + return 0x66; + default: + return 0; } /* more codes, don't seem to be used resp->m_data[10] = 0x77; @@ -1050,11 +1158,13 @@ static uint8_t convert_keyboard_char(char c) static void keyboard_add_key_press_to_buffer(uint8_t node, char key) { - InterlockedCompareExchange(&ezusb_iidx_emu_node_serial_emulation_state[node].keypad_buf, - convert_keyboard_char(key), 0); + InterlockedCompareExchange( + &ezusb_iidx_emu_node_serial_emulation_state[node].keypad_buf, + convert_keyboard_char(key), + 0); } -static int ezusb_iidx_emu_node_serial_emu_thread_proc(void* ctx) +static int ezusb_iidx_emu_node_serial_emu_thread_proc(void *ctx) { log_info("Started magnetic card reader emulation thread"); @@ -1062,10 +1172,12 @@ static int ezusb_iidx_emu_node_serial_emu_thread_proc(void* ctx) uint8_t init = 0; while (init < 2) { for (uint8_t i = 0; i < 2; i++) { - if (ezusb_iidx_emu_node_serial_emulation_state[i].state_current == EMU_STATE_INIT) { + if (ezusb_iidx_emu_node_serial_emulation_state[i].state_current == + EMU_STATE_INIT) { InterlockedExchange( - &ezusb_iidx_emu_node_serial_emulation_state[i].state_current, - EMU_STATE_LOOP); + &ezusb_iidx_emu_node_serial_emulation_state[i] + .state_current, + EMU_STATE_LOOP); init++; } } @@ -1076,7 +1188,6 @@ static int ezusb_iidx_emu_node_serial_emu_thread_proc(void* ctx) uint16_t keyboard_state_prev[2] = {0, 0}; while (true) { for (uint8_t node = 0; node < 2; node++) { - if (!eam_io_poll(node)) { log_warning("Polling eamio, node %d failed", node); continue; @@ -1106,10 +1217,12 @@ static int ezusb_iidx_emu_node_serial_emu_thread_proc(void* ctx) uint16_t keypad = eam_io_get_keypad_state(node); uint16_t keypad_rise = ~keyboard_state_prev[node] & keypad; - for (uint8_t i = 0; i < sizeof(ezusb_iidx_emu_node_serial_eamio_mapping); ++i) { + for (uint8_t i = 0; + i < sizeof(ezusb_iidx_emu_node_serial_eamio_mapping); + ++i) { if (keypad_rise & (1 << i)) { - keyboard_add_key_press_to_buffer(node, - ezusb_iidx_emu_node_serial_eamio_mapping[i]); + keyboard_add_key_press_to_buffer( + node, ezusb_iidx_emu_node_serial_eamio_mapping[i]); } } @@ -1117,7 +1230,7 @@ static int ezusb_iidx_emu_node_serial_emu_thread_proc(void* ctx) /* set card slot state */ switch (ezusb_iidx_emu_node_serial_emulation_state[node] - .ezusb_iidx_emu_node_serial_card_slot_state) { + .ezusb_iidx_emu_node_serial_card_slot_state) { case EMU_CARD_SLOT_STATE_CLOSE: eam_io_card_slot_cmd(node, EAM_IO_CARD_SLOT_CMD_CLOSE); break; @@ -1126,14 +1239,19 @@ static int ezusb_iidx_emu_node_serial_emu_thread_proc(void* ctx) eam_io_card_slot_cmd(node, EAM_IO_CARD_SLOT_CMD_EJECT); EnterCriticalSection( - &ezusb_iidx_emu_node_serial_emulation_state[node].card_cs); + &ezusb_iidx_emu_node_serial_emulation_state[node] + .card_cs); /* invalidate card id */ - memset(ezusb_iidx_emu_node_serial_emulation_state[node].card_id, 0, + memset( + ezusb_iidx_emu_node_serial_emulation_state[node] + .card_id, + 0, CARD_ID_LEN); LeaveCriticalSection( - &ezusb_iidx_emu_node_serial_emulation_state[node].card_cs); + &ezusb_iidx_emu_node_serial_emulation_state[node] + .card_cs); break; case EMU_CARD_SLOT_STATE_OPEN: @@ -1144,27 +1262,38 @@ static int ezusb_iidx_emu_node_serial_emu_thread_proc(void* ctx) eam_io_card_slot_cmd(node, EAM_IO_CARD_SLOT_CMD_READ); /* read once */ - if ( ezusb_iidx_emu_node_serial_emulation_state[node] + if (ezusb_iidx_emu_node_serial_emulation_state[node] .state_current == EMU_STATE_REQ_CARD) { EnterCriticalSection( - &ezusb_iidx_emu_node_serial_emulation_state[node].card_cs); + &ezusb_iidx_emu_node_serial_emulation_state[node] + .card_cs); - if ( !eam_io_read_card(node, - ezusb_iidx_emu_node_serial_emulation_state[node].card_id, + if (!eam_io_read_card( + node, + ezusb_iidx_emu_node_serial_emulation_state[node] + .card_id, CARD_ID_LEN)) { - memset(ezusb_iidx_emu_node_serial_emulation_state[node].card_id, - 0, CARD_ID_LEN); + memset( + ezusb_iidx_emu_node_serial_emulation_state[node] + .card_id, + 0, + CARD_ID_LEN); InterlockedExchange( - &ezusb_iidx_emu_node_serial_emulation_state[node].state_current, + &ezusb_iidx_emu_node_serial_emulation_state + [node] + .state_current, EMU_STATE_ERROR); } else { InterlockedExchange( - &ezusb_iidx_emu_node_serial_emulation_state[node].state_current, + &ezusb_iidx_emu_node_serial_emulation_state + [node] + .state_current, EMU_STATE_CARD_READ); } LeaveCriticalSection( - &ezusb_iidx_emu_node_serial_emulation_state[node].card_cs); + &ezusb_iidx_emu_node_serial_emulation_state[node] + .card_cs); } break; diff --git a/src/main/ezusb-iidx-emu/node-serial.h b/src/main/ezusb-iidx-emu/node-serial.h index cccf180..ad68d25 100644 --- a/src/main/ezusb-iidx-emu/node-serial.h +++ b/src/main/ezusb-iidx-emu/node-serial.h @@ -5,12 +5,14 @@ void ezusb_iidx_emu_node_serial_init(void); -uint8_t ezusb_iidx_emu_node_serial_process_cmd(uint8_t cmd_id, uint8_t cmd_data, - uint8_t cmd_data2); +uint8_t ezusb_iidx_emu_node_serial_process_cmd( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2); -bool ezusb_iidx_emu_node_serial_read_packet(struct ezusb_iidx_msg_bulk_packet* pkg); +bool ezusb_iidx_emu_node_serial_read_packet( + struct ezusb_iidx_msg_bulk_packet *pkg); -bool ezusb_iidx_emu_node_serial_write_packet(const struct ezusb_iidx_msg_bulk_packet* pkg); +bool ezusb_iidx_emu_node_serial_write_packet( + const struct ezusb_iidx_msg_bulk_packet *pkg); /** * Check if the uart read buffer is busy (refer to ezusb interrupt read) @@ -30,7 +32,7 @@ bool ezusb_iidx_emu_node_serial_write_buffer_busy(void); * @param card_version Version of the card to emulate (mcode of the game * that supports mag cards) */ -void ezusb_iidx_emu_node_serial_set_card_attributes(uint8_t card_type, - bool used_card, const char* card_version); +void ezusb_iidx_emu_node_serial_set_card_attributes( + uint8_t card_type, bool used_card, const char *card_version); #endif \ No newline at end of file diff --git a/src/main/ezusb-iidx-emu/node-sram.c b/src/main/ezusb-iidx-emu/node-sram.c index 8a5af87..72c6066 100644 --- a/src/main/ezusb-iidx-emu/node-sram.c +++ b/src/main/ezusb-iidx-emu/node-sram.c @@ -2,9 +2,9 @@ #include -#include "ezusb-iidx/sram-cmd.h" #include "ezusb-iidx-emu/conf.h" #include "ezusb-iidx-emu/node-sram.h" +#include "ezusb-iidx/sram-cmd.h" #include "util/fs.h" #include "util/log.h" @@ -15,8 +15,8 @@ static uint8_t ezusb_iidx_emu_node_sram_buf[EZUSB_PAGESIZE * SRAM_NPAGES]; static enum ezusb_iidx_sram_command ezusb_iidx_emu_node_sram_last_cmd; static int ezusb_iidx_emu_node_sram_read_page; -uint8_t ezusb_iidx_emu_node_sram_process_cmd(uint8_t cmd_id, uint8_t cmd_data, - uint8_t cmd_data2) +uint8_t ezusb_iidx_emu_node_sram_process_cmd( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2) { ezusb_iidx_emu_node_sram_last_cmd = cmd_id; @@ -35,7 +35,9 @@ uint8_t ezusb_iidx_emu_node_sram_process_cmd(uint8_t cmd_id, uint8_t cmd_data, log_misc("EZUSB_IIDX_SRAM_CMD_DONE"); #ifdef EZUSB_IIDX_EMU_NODE_SRAM_DUMP - file_save("sram.bin", ezusb_iidx_emu_node_sram_buf, + file_save( + "sram.bin", + ezusb_iidx_emu_node_sram_buf, EZUSB_PAGESIZE * SRAM_NPAGES); log_info("Dumped sram data to sram.bin"); @@ -51,10 +53,10 @@ uint8_t ezusb_iidx_emu_node_sram_process_cmd(uint8_t cmd_id, uint8_t cmd_data, return 0; } -bool ezusb_iidx_emu_node_sram_read_packet(struct ezusb_iidx_msg_bulk_packet* pkg) +bool ezusb_iidx_emu_node_sram_read_packet( + struct ezusb_iidx_msg_bulk_packet *pkg) { if (ezusb_iidx_emu_node_sram_last_cmd == EZUSB_IIDX_SRAM_CMD_READ) { - if (ezusb_iidx_emu_node_sram_read_page >= SRAM_NPAGES) { log_warning("SRAM read overrun"); @@ -66,22 +68,27 @@ bool ezusb_iidx_emu_node_sram_read_packet(struct ezusb_iidx_msg_bulk_packet* pkg /* Gold to Sirius must have this set to get accepted */ pkg->node = 0x40; pkg->page = (uint8_t) ezusb_iidx_emu_node_sram_read_page; - memcpy( pkg->payload, - ezusb_iidx_emu_node_sram_buf + ezusb_iidx_emu_node_sram_read_page * - EZUSB_PAGESIZE, EZUSB_PAGESIZE); + memcpy( + pkg->payload, + ezusb_iidx_emu_node_sram_buf + + ezusb_iidx_emu_node_sram_read_page * EZUSB_PAGESIZE, + EZUSB_PAGESIZE); ezusb_iidx_emu_node_sram_read_page++; return true; } else { - log_warning("Unexpected SRAM read: ezusb_iidx_emu_node_sram_last_cmd = %02x", - ezusb_iidx_emu_node_sram_last_cmd); + log_warning( + "Unexpected SRAM read: ezusb_iidx_emu_node_sram_last_cmd = " + "%02x", + ezusb_iidx_emu_node_sram_last_cmd); return false; } } -bool ezusb_iidx_emu_node_sram_write_packet(const struct ezusb_iidx_msg_bulk_packet* pkg) +bool ezusb_iidx_emu_node_sram_write_packet( + const struct ezusb_iidx_msg_bulk_packet *pkg) { if (pkg->page >= SRAM_NPAGES) { log_warning("SRAM write overrun"); @@ -90,8 +97,10 @@ bool ezusb_iidx_emu_node_sram_write_packet(const struct ezusb_iidx_msg_bulk_pack } log_misc("Writing SRAM page %02x", pkg->page); - memcpy(ezusb_iidx_emu_node_sram_buf + pkg->page * EZUSB_PAGESIZE, pkg->payload, - EZUSB_PAGESIZE); + memcpy( + ezusb_iidx_emu_node_sram_buf + pkg->page * EZUSB_PAGESIZE, + pkg->payload, + EZUSB_PAGESIZE); return true; } \ No newline at end of file diff --git a/src/main/ezusb-iidx-emu/node-sram.h b/src/main/ezusb-iidx-emu/node-sram.h index 9e451e6..ccfe4d0 100644 --- a/src/main/ezusb-iidx-emu/node-sram.h +++ b/src/main/ezusb-iidx-emu/node-sram.h @@ -3,11 +3,13 @@ #include "ezusb-iidx-emu/node.h" -uint8_t ezusb_iidx_emu_node_sram_process_cmd(uint8_t cmd_id, uint8_t cmd_data, - uint8_t cmd_data2); +uint8_t ezusb_iidx_emu_node_sram_process_cmd( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2); -bool ezusb_iidx_emu_node_sram_read_packet(struct ezusb_iidx_msg_bulk_packet* pkg); +bool ezusb_iidx_emu_node_sram_read_packet( + struct ezusb_iidx_msg_bulk_packet *pkg); -bool ezusb_iidx_emu_node_sram_write_packet(const struct ezusb_iidx_msg_bulk_packet* pkg); +bool ezusb_iidx_emu_node_sram_write_packet( + const struct ezusb_iidx_msg_bulk_packet *pkg); #endif \ No newline at end of file diff --git a/src/main/ezusb-iidx-emu/node-wdt.c b/src/main/ezusb-iidx-emu/node-wdt.c index 436a0bc..e86903a 100644 --- a/src/main/ezusb-iidx-emu/node-wdt.c +++ b/src/main/ezusb-iidx-emu/node-wdt.c @@ -1,12 +1,12 @@ #define LOG_MODULE "ezusb-iidx-emu-node-wdt" -#include "ezusb-iidx/wdt-cmd.h" #include "ezusb-iidx-emu/node-wdt.h" +#include "ezusb-iidx/wdt-cmd.h" #include "util/log.h" -uint8_t ezusb_iidx_emu_node_wdt_process_cmd(uint8_t cmd_id, uint8_t cmd_data, - uint8_t cmd_data2) +uint8_t ezusb_iidx_emu_node_wdt_process_cmd( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2) { switch (cmd_id) { case EZUSB_IIDX_WDT_CMD_INIT: @@ -19,12 +19,13 @@ uint8_t ezusb_iidx_emu_node_wdt_process_cmd(uint8_t cmd_id, uint8_t cmd_data, } } -bool ezusb_iidx_emu_node_wdt_read_packet(struct ezusb_iidx_msg_bulk_packet* pkg) +bool ezusb_iidx_emu_node_wdt_read_packet(struct ezusb_iidx_msg_bulk_packet *pkg) { return true; } -bool ezusb_iidx_emu_node_wdt_write_packet(const struct ezusb_iidx_msg_bulk_packet* pkg) +bool ezusb_iidx_emu_node_wdt_write_packet( + const struct ezusb_iidx_msg_bulk_packet *pkg) { return true; } \ No newline at end of file diff --git a/src/main/ezusb-iidx-emu/node-wdt.h b/src/main/ezusb-iidx-emu/node-wdt.h index f793cf3..781e409 100644 --- a/src/main/ezusb-iidx-emu/node-wdt.h +++ b/src/main/ezusb-iidx-emu/node-wdt.h @@ -3,10 +3,13 @@ #include "ezusb-iidx-emu/node.h" -uint8_t ezusb_iidx_emu_node_wdt_process_cmd(uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2); +uint8_t ezusb_iidx_emu_node_wdt_process_cmd( + uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2); -bool ezusb_iidx_emu_node_wdt_read_packet(struct ezusb_iidx_msg_bulk_packet* pkg); +bool ezusb_iidx_emu_node_wdt_read_packet( + struct ezusb_iidx_msg_bulk_packet *pkg); -bool ezusb_iidx_emu_node_wdt_write_packet(const struct ezusb_iidx_msg_bulk_packet* pkg); +bool ezusb_iidx_emu_node_wdt_write_packet( + const struct ezusb_iidx_msg_bulk_packet *pkg); #endif \ No newline at end of file diff --git a/src/main/ezusb-iidx-emu/node.h b/src/main/ezusb-iidx-emu/node.h index 9a91d3e..5eba123 100644 --- a/src/main/ezusb-iidx-emu/node.h +++ b/src/main/ezusb-iidx-emu/node.h @@ -1,8 +1,8 @@ #ifndef EZUSB_IIDX_EMU_NODE_H #define EZUSB_IIDX_EMU_NODE_H -#include #include +#include #include "ezusb-iidx/msg.h" @@ -20,10 +20,10 @@ struct ezusb_iidx_emu_node { uint8_t (*process_cmd)(uint8_t cmd_id, uint8_t cmd_data, uint8_t cmd_data2); /* Bulk read data from the node */ - bool (*read_packet)(struct ezusb_iidx_msg_bulk_packet* pkg); + bool (*read_packet)(struct ezusb_iidx_msg_bulk_packet *pkg); /* Bulk write data to the node */ - bool (*write_packet)(const struct ezusb_iidx_msg_bulk_packet* pkg); + bool (*write_packet)(const struct ezusb_iidx_msg_bulk_packet *pkg); }; #endif \ No newline at end of file diff --git a/src/main/ezusb-iidx-emu/nodes.c b/src/main/ezusb-iidx-emu/nodes.c index cd57ced..dcc9b2b 100644 --- a/src/main/ezusb-iidx-emu/nodes.c +++ b/src/main/ezusb-iidx-emu/nodes.c @@ -5,7 +5,6 @@ #include "ezusb-iidx/msg.h" -#include "ezusb-iidx-emu/node.h" #include "ezusb-iidx-emu/node-16seg.h" #include "ezusb-iidx-emu/node-coin.h" #include "ezusb-iidx-emu/node-eeprom.h" @@ -16,144 +15,117 @@ #include "ezusb-iidx-emu/node-serial.h" #include "ezusb-iidx-emu/node-sram.h" #include "ezusb-iidx-emu/node-wdt.h" +#include "ezusb-iidx-emu/node.h" #include "ezusb-iidx-emu/nodes.h" /* All IIDX games */ -const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_16seg = -{ +const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_16seg = { .node_id = EZUSB_IIDX_MSG_NODE_16SEG, .init_node = NULL, .process_cmd = ezusb_iidx_emu_node_16seg_process_cmd, .read_packet = ezusb_iidx_emu_node_16seg_read_packet, - .write_packet = ezusb_iidx_emu_node_16seg_write_packet -}; + .write_packet = ezusb_iidx_emu_node_16seg_write_packet}; /* All IIDX games */ -const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_coin = -{ +const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_coin = { .node_id = EZUSB_IIDX_MSG_NODE_COIN, .init_node = NULL, .process_cmd = ezusb_iidx_emu_node_coin_process_cmd, .read_packet = ezusb_iidx_emu_node_coin_read_packet, - .write_packet = ezusb_iidx_emu_node_coin_write_packet -}; + .write_packet = ezusb_iidx_emu_node_coin_write_packet}; /* Used on 9th to DistorteD */ -const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_eeprom_v1 = -{ +const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_eeprom_v1 = { .node_id = EZUSB_IIDX_MSG_NODE_EEPROM, .init_node = ezusb_iidx_emu_node_eeprom_init, .process_cmd = ezusb_iidx_emu_node_eeprom_process_cmd_v1, .read_packet = ezusb_iidx_emu_node_eeprom_read_packet, - .write_packet = ezusb_iidx_emu_node_eeprom_write_packet -}; + .write_packet = ezusb_iidx_emu_node_eeprom_write_packet}; /* Used on Gold to Sirius */ -const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_eeprom_v2 = -{ +const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_eeprom_v2 = { .node_id = EZUSB_IIDX_MSG_NODE_EEPROM, .init_node = ezusb_iidx_emu_node_eeprom_init, .process_cmd = ezusb_iidx_emu_node_eeprom_process_cmd_v2, .read_packet = ezusb_iidx_emu_node_eeprom_read_packet, - .write_packet = ezusb_iidx_emu_node_eeprom_write_packet -}; + .write_packet = ezusb_iidx_emu_node_eeprom_write_packet}; /* Used on 9th to DistorteD */ -const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_fpga_v1 = -{ +const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_fpga_v1 = { .node_id = EZUSB_IIDX_MSG_NODE_FPGA_V1, .init_node = NULL, .process_cmd = ezusb_iidx_emu_node_fpga_v1_process_cmd, .read_packet = ezusb_iidx_emu_node_fpga_read_packet, - .write_packet = ezusb_iidx_emu_node_fpga_write_packet -}; + .write_packet = ezusb_iidx_emu_node_fpga_write_packet}; /* Used on Gold onwards */ -const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_fpga_v2 = -{ +const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_fpga_v2 = { .node_id = EZUSB_IIDX_MSG_NODE_FPGA_V2, .init_node = NULL, .process_cmd = ezusb_iidx_emu_node_fpga_v2_process_cmd, .read_packet = ezusb_iidx_emu_node_fpga_read_packet, - .write_packet = ezusb_iidx_emu_node_fpga_write_packet -}; + .write_packet = ezusb_iidx_emu_node_fpga_write_packet}; /* All IIDX games */ -const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_none = -{ +const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_none = { .node_id = EZUSB_IIDX_MSG_NODE_NONE, .init_node = NULL, .process_cmd = ezusb_iidx_emu_node_none_process_cmd, .read_packet = ezusb_iidx_emu_node_none_read_packet, - .write_packet = ezusb_iidx_emu_node_none_write_packet -}; + .write_packet = ezusb_iidx_emu_node_none_write_packet}; /* Used on 9th to DistorteD */ -const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_security_mem_v1 = -{ +const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_security_mem_v1 = { .node_id = EZUSB_IIDX_MSG_NODE_SECURITY_MEM, .init_node = ezusb_iidx_emu_node_security_mem_init, .process_cmd = ezusb_iidx_emu_node_security_mem_v1_process_cmd, .read_packet = ezusb_iidx_emu_node_security_mem_read_packet, - .write_packet = ezusb_iidx_emu_node_security_mem_write_packet -}; + .write_packet = ezusb_iidx_emu_node_security_mem_write_packet}; /* Used on Gold to Sirius */ -const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_security_mem_v2 = -{ +const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_security_mem_v2 = { .node_id = EZUSB_IIDX_MSG_NODE_SECURITY_MEM, .init_node = ezusb_iidx_emu_node_security_mem_init, .process_cmd = ezusb_iidx_emu_node_security_mem_v2_process_cmd, .read_packet = ezusb_iidx_emu_node_security_mem_read_packet, - .write_packet = ezusb_iidx_emu_node_security_mem_write_packet -}; + .write_packet = ezusb_iidx_emu_node_security_mem_write_packet}; /* Used on 9th to DistorteD */ -const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_security_plug_v1 = -{ +const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_security_plug_v1 = { .node_id = EZUSB_IIDX_MSG_NODE_SECURITY_PLUG, .init_node = NULL, .process_cmd = ezusb_iidx_emu_node_security_plug_process_cmd_v1, .read_packet = ezusb_iidx_emu_node_security_plug_read_packet_v1, - .write_packet = ezusb_iidx_emu_node_security_plug_write_packet -}; + .write_packet = ezusb_iidx_emu_node_security_plug_write_packet}; /* Used on Gold to Sirius */ -const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_security_plug_v2 = -{ +const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_security_plug_v2 = { .node_id = EZUSB_IIDX_MSG_NODE_SECURITY_PLUG, .init_node = NULL, .process_cmd = ezusb_iidx_emu_node_security_plug_process_cmd_v2, .read_packet = ezusb_iidx_emu_node_security_plug_read_packet_v2, - .write_packet = ezusb_iidx_emu_node_security_plug_write_packet -}; + .write_packet = ezusb_iidx_emu_node_security_plug_write_packet}; /* Used on 9th to HappySky for magnetic readers */ -const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_serial = -{ +const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_serial = { .node_id = EZUSB_IIDX_MSG_NODE_SERIAL, .init_node = ezusb_iidx_emu_node_serial_init, .process_cmd = ezusb_iidx_emu_node_serial_process_cmd, .read_packet = ezusb_iidx_emu_node_serial_read_packet, - .write_packet = ezusb_iidx_emu_node_serial_write_packet -}; + .write_packet = ezusb_iidx_emu_node_serial_write_packet}; /* All IIDX games */ -const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_sram = -{ +const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_sram = { .node_id = EZUSB_IIDX_MSG_NODE_SRAM, .init_node = NULL, .process_cmd = ezusb_iidx_emu_node_sram_process_cmd, .read_packet = ezusb_iidx_emu_node_sram_read_packet, - .write_packet = ezusb_iidx_emu_node_sram_write_packet -}; + .write_packet = ezusb_iidx_emu_node_sram_write_packet}; /* Used on 9th to Sirius */ -const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_wdt = -{ +const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_wdt = { .node_id = EZUSB_IIDX_MSG_NODE_WDT, .init_node = NULL, .process_cmd = ezusb_iidx_emu_node_wdt_process_cmd, .read_packet = ezusb_iidx_emu_node_wdt_read_packet, - .write_packet = ezusb_iidx_emu_node_wdt_write_packet -}; + .write_packet = ezusb_iidx_emu_node_wdt_write_packet}; diff --git a/src/main/ezusb-iidx-fpga-flash/main.c b/src/main/ezusb-iidx-fpga-flash/main.c index c51c510..a8fb681 100644 --- a/src/main/ezusb-iidx-fpga-flash/main.c +++ b/src/main/ezusb-iidx-fpga-flash/main.c @@ -3,23 +3,24 @@ #include -#include "ezusb/ezusb.h" #include "ezusb-iidx/fpga.h" +#include "ezusb/ezusb.h" #include "util/fs.h" #include "util/log.h" -int main(int argc, char** argv) +int main(int argc, char **argv) { HANDLE handle; - void* buffer; + void *buffer; size_t size; bool res; if (argc < 3) { printf("ezusb-iidx-fpga-flash for EZUSB hardware, e.g. IIDX C02 IO, " - "build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) "\n" - "Usage: %s [v1/v2] [fpga fw bin]\n", argv[0]); + "build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) "\n" + "Usage: %s [v1/v2] [fpga fw bin]\n", + argv[0]); return -1; } diff --git a/src/main/ezusb-iidx-sram-flash/main.c b/src/main/ezusb-iidx-sram-flash/main.c index 43dbc16..d22464e 100644 --- a/src/main/ezusb-iidx-sram-flash/main.c +++ b/src/main/ezusb-iidx-sram-flash/main.c @@ -3,23 +3,24 @@ #include -#include "ezusb/ezusb.h" #include "ezusb-iidx/sram.h" +#include "ezusb/ezusb.h" #include "util/fs.h" #include "util/log.h" -int main(int argc, char** argv) +int main(int argc, char **argv) { HANDLE handle; - void* buffer; + void *buffer; size_t size; bool res; if (argc < 3) { printf("ezusb-iidx-sram-flash for EZUSB hardware, e.g. IIDX C02 IO, " - "build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) "\n" - "Usage: %s [ezusb dev path] [sram bin]\n", argv[0]); + "build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) "\n" + "Usage: %s [ezusb dev path] [sram bin]\n", + argv[0]); return -1; } diff --git a/src/main/ezusb-iidx/ezusb-iidx.c b/src/main/ezusb-iidx/ezusb-iidx.c index 91311e2..35962b7 100644 --- a/src/main/ezusb-iidx/ezusb-iidx.c +++ b/src/main/ezusb-iidx/ezusb-iidx.c @@ -14,13 +14,19 @@ /* For debugging */ #ifdef DEBUG_DUMP -static void ezusb_iidx_log_usb(const char* prefix, uint32_t ctl_code, - const BULK_TRANSFER_CONTROL *ctl, uint32_t ctl_size, void* header, - uint32_t header_bytes, void* data, uint32_t data_bytes) +static void ezusb_iidx_log_usb( + const char *prefix, + uint32_t ctl_code, + const BULK_TRANSFER_CONTROL *ctl, + uint32_t ctl_size, + void *header, + uint32_t header_bytes, + void *data, + uint32_t data_bytes) { char header_str[4096]; char data_str[4096]; - const char* ctl_code_str; + const char *ctl_code_str; switch (ctl_code) { case IOCTL_Ezusb_GET_DEVICE_DESCRIPTOR: @@ -65,44 +71,88 @@ static void ezusb_iidx_log_usb(const char* prefix, uint32_t ctl_code, hex_encode_uc(header, header_bytes, header_str, sizeof(header_str)); hex_encode_uc(data, data_bytes, data_str, sizeof(data_str)); - log_misc("[EZUSB DUMP %s][%s] header(%d) %s |||| data(%d) %s\n", - prefix, ctl_code_str, header_bytes, header_str, data_bytes, data_str); + log_misc( + "[EZUSB DUMP %s][%s] header(%d) %s |||| data(%d) %s\n", + prefix, + ctl_code_str, + header_bytes, + header_str, + data_bytes, + data_str); } #endif static BOOL ezusb_iidx_device_io_control_wrapper( - HANDLE fd, uint32_t code, void *in_bytes, uint32_t in_nbytes, - void *out_bytes, uint32_t out_nbytes, DWORD *out_returned, - OVERLAPPED *ovl) + HANDLE fd, + uint32_t code, + void *in_bytes, + uint32_t in_nbytes, + void *out_bytes, + uint32_t out_nbytes, + DWORD *out_returned, + OVERLAPPED *ovl) { BOOL ret; #ifdef DEBUG_DUMP - ezusb_iidx_log_usb("BEFORE", code, in_bytes, in_nbytes, in_bytes, in_nbytes, - out_bytes, out_nbytes); + ezusb_iidx_log_usb( + "BEFORE", + code, + in_bytes, + in_nbytes, + in_bytes, + in_nbytes, + out_bytes, + out_nbytes); #endif - ret = DeviceIoControl(fd, code, in_bytes, in_nbytes, out_bytes, - out_nbytes, out_returned, ovl); + ret = DeviceIoControl( + fd, + code, + in_bytes, + in_nbytes, + out_bytes, + out_nbytes, + out_returned, + ovl); #ifdef DEBUG_DUMP - ezusb_iidx_log_usb("AFTER", code, in_bytes, in_nbytes, in_bytes, in_nbytes, - out_bytes, out_nbytes); + ezusb_iidx_log_usb( + "AFTER", + code, + in_bytes, + in_nbytes, + in_bytes, + in_nbytes, + out_bytes, + out_nbytes); #endif return ret; } -bool ezusb_iidx_ioctl(HANDLE handle, uint32_t code, void* in_bytes, - uint32_t in_nbytes, void* out_bytes, uint32_t out_nbytes, - uint32_t* out_returned) +bool ezusb_iidx_ioctl( + HANDLE handle, + uint32_t code, + void *in_bytes, + uint32_t in_nbytes, + void *out_bytes, + uint32_t out_nbytes, + uint32_t *out_returned) { - return DeviceIoControl(handle, code, in_bytes, in_nbytes, out_bytes, - out_nbytes, (LPDWORD) out_returned, NULL); + return DeviceIoControl( + handle, + code, + in_bytes, + in_nbytes, + out_bytes, + out_nbytes, + (LPDWORD) out_returned, + NULL); } -bool ezusb_iidx_interrupt_read(HANDLE handle, - struct ezusb_iidx_msg_interrupt_read_packet* packet) +bool ezusb_iidx_interrupt_read( + HANDLE handle, struct ezusb_iidx_msg_interrupt_read_packet *packet) { BULK_TRANSFER_CONTROL transfer; DWORD outpkt; @@ -110,13 +160,18 @@ bool ezusb_iidx_interrupt_read(HANDLE handle, transfer.pipeNum = EZUSB_IIDX_MSG_PIPE_INTERRUPT_IN; return ezusb_iidx_device_io_control_wrapper( - handle, IOCTL_EZUSB_BULK_READ, &transfer, - sizeof(transfer), packet, - sizeof(struct ezusb_iidx_msg_interrupt_read_packet), &outpkt, NULL); + handle, + IOCTL_EZUSB_BULK_READ, + &transfer, + sizeof(transfer), + packet, + sizeof(struct ezusb_iidx_msg_interrupt_read_packet), + &outpkt, + NULL); } -bool ezusb_iidx_interrupt_write(HANDLE handle, - const struct ezusb_iidx_msg_interrupt_write_packet* packet) +bool ezusb_iidx_interrupt_write( + HANDLE handle, const struct ezusb_iidx_msg_interrupt_write_packet *packet) { BULK_TRANSFER_CONTROL transfer; DWORD outpkt; @@ -124,13 +179,18 @@ bool ezusb_iidx_interrupt_write(HANDLE handle, transfer.pipeNum = EZUSB_IIDX_MSG_PIPE_INTERRUPT_OUT; return ezusb_iidx_device_io_control_wrapper( - handle, IOCTL_EZUSB_BULK_WRITE, &transfer, - sizeof(transfer), (void*) packet, - sizeof(struct ezusb_iidx_msg_interrupt_write_packet), &outpkt, NULL); + handle, + IOCTL_EZUSB_BULK_WRITE, + &transfer, + sizeof(transfer), + (void *) packet, + sizeof(struct ezusb_iidx_msg_interrupt_write_packet), + &outpkt, + NULL); } -bool ezusb_iidx_bulk_read(HANDLE handle, - struct ezusb_iidx_msg_bulk_packet* packet) +bool ezusb_iidx_bulk_read( + HANDLE handle, struct ezusb_iidx_msg_bulk_packet *packet) { BULK_TRANSFER_CONTROL transfer; DWORD outpkt; @@ -138,13 +198,18 @@ bool ezusb_iidx_bulk_read(HANDLE handle, transfer.pipeNum = EZUSB_IIDX_MSG_PIPE_BULK_IN; return ezusb_iidx_device_io_control_wrapper( - handle, IOCTL_EZUSB_BULK_READ, &transfer, - sizeof(transfer), packet, - sizeof(struct ezusb_iidx_msg_bulk_packet), &outpkt, NULL); + handle, + IOCTL_EZUSB_BULK_READ, + &transfer, + sizeof(transfer), + packet, + sizeof(struct ezusb_iidx_msg_bulk_packet), + &outpkt, + NULL); } -bool ezusb_iidx_bulk_write(HANDLE handle, - const struct ezusb_iidx_msg_bulk_packet* packet) +bool ezusb_iidx_bulk_write( + HANDLE handle, const struct ezusb_iidx_msg_bulk_packet *packet) { BULK_TRANSFER_CONTROL transfer; DWORD outpkt; @@ -152,14 +217,23 @@ bool ezusb_iidx_bulk_write(HANDLE handle, transfer.pipeNum = EZUSB_IIDX_MSG_PIPE_BULK_OUT; return ezusb_iidx_device_io_control_wrapper( - handle, IOCTL_EZUSB_BULK_WRITE, &transfer, - sizeof(transfer), (void*) packet, - sizeof(struct ezusb_iidx_msg_bulk_packet), &outpkt, NULL); + handle, + IOCTL_EZUSB_BULK_WRITE, + &transfer, + sizeof(transfer), + (void *) packet, + sizeof(struct ezusb_iidx_msg_bulk_packet), + &outpkt, + NULL); } -bool ezusb_iidx_execute_cmd(HANDLE handle, uint8_t node, - uint8_t cmd, uint8_t cmd_detail, uint8_t cmd_detail2, - struct ezusb_iidx_msg_interrupt_read_packet* int_read_data) +bool ezusb_iidx_execute_cmd( + HANDLE handle, + uint8_t node, + uint8_t cmd, + uint8_t cmd_detail, + uint8_t cmd_detail2, + struct ezusb_iidx_msg_interrupt_read_packet *int_read_data) { struct ezusb_iidx_msg_interrupt_write_packet int_write; @@ -170,8 +244,8 @@ bool ezusb_iidx_execute_cmd(HANDLE handle, uint8_t node, int_write.cmd_detail[0] = cmd_detail; int_write.cmd_detail[1] = cmd_detail2; - log_misc("Execute cmd: %02X %02X %02X %02X", - node, cmd, cmd_detail, cmd_detail2); + log_misc( + "Execute cmd: %02X %02X %02X %02X", node, cmd, cmd_detail, cmd_detail2); if (!ezusb_iidx_interrupt_write(handle, &int_write)) { log_warning("Interrupt write failed"); @@ -190,8 +264,13 @@ bool ezusb_iidx_execute_cmd(HANDLE handle, uint8_t node, return true; } -uint8_t ezusb_iidx_execute_cmd_retry(HANDLE handle, uint8_t node, - uint8_t cmd, uint8_t cmd_detail, uint8_t cmd_detail2, uint8_t int_reads) +uint8_t ezusb_iidx_execute_cmd_retry( + HANDLE handle, + uint8_t node, + uint8_t cmd, + uint8_t cmd_detail, + uint8_t cmd_detail2, + uint8_t int_reads) { struct ezusb_iidx_msg_interrupt_read_packet int_read; struct ezusb_iidx_msg_interrupt_write_packet int_write; @@ -203,8 +282,8 @@ uint8_t ezusb_iidx_execute_cmd_retry(HANDLE handle, uint8_t node, int_write.cmd_detail[0] = cmd_detail; int_write.cmd_detail[1] = cmd_detail2; - log_misc("Execute cmd: %02X %02X %02X %02X", - node, cmd, cmd_detail, cmd_detail2); + log_misc( + "Execute cmd: %02X %02X %02X %02X", node, cmd, cmd_detail, cmd_detail2); if (!ezusb_iidx_interrupt_write(handle, &int_write)) { log_warning("Interrupt write failed"); @@ -225,9 +304,14 @@ uint8_t ezusb_iidx_execute_cmd_retry(HANDLE handle, uint8_t node, return int_read.status; } -bool ezusb_iidx_execute_cmd_timeout(HANDLE handle, uint8_t node, - uint8_t cmd, uint8_t cmd_detail, uint8_t cmd_detail2, - uint8_t expected_ret_code, uint32_t timeout_ms) +bool ezusb_iidx_execute_cmd_timeout( + HANDLE handle, + uint8_t node, + uint8_t cmd, + uint8_t cmd_detail, + uint8_t cmd_detail2, + uint8_t expected_ret_code, + uint32_t timeout_ms) { struct ezusb_iidx_msg_interrupt_read_packet int_read; struct ezusb_iidx_msg_interrupt_write_packet int_write; @@ -239,8 +323,8 @@ bool ezusb_iidx_execute_cmd_timeout(HANDLE handle, uint8_t node, int_write.cmd_detail[0] = cmd_detail; int_write.cmd_detail[1] = cmd_detail2; - log_misc("Execute cmd: %02X %02X %02X %02X", - node, cmd, cmd_detail, cmd_detail2); + log_misc( + "Execute cmd: %02X %02X %02X %02X", node, cmd, cmd_detail, cmd_detail2); if (!ezusb_iidx_interrupt_write(handle, &int_write)) { log_warning("Interrupt write failed"); @@ -252,8 +336,8 @@ bool ezusb_iidx_execute_cmd_timeout(HANDLE handle, uint8_t node, uint64_t start = time_get_counter(); while (time_get_elapsed_ms(time_get_counter() - start) < timeout_ms) { - if (!ezusb_iidx_interrupt_read(handle, &int_read)) { - log_warning("Interrupt read failed"); + if (!ezusb_iidx_interrupt_read(handle, &int_read)) { + log_warning("Interrupt read failed"); return false; } diff --git a/src/main/ezusb-iidx/ezusb-iidx.h b/src/main/ezusb-iidx/ezusb-iidx.h index 5c35c89..54aac96 100644 --- a/src/main/ezusb-iidx/ezusb-iidx.h +++ b/src/main/ezusb-iidx/ezusb-iidx.h @@ -7,31 +7,50 @@ #include "msg.h" -bool ezusb_iidx_ioctl(HANDLE handle, uint32_t code, void* in_bytes, - uint32_t in_nbytes, void* out_bytes, uint32_t out_nbytes, - uint32_t* out_returned); +bool ezusb_iidx_ioctl( + HANDLE handle, + uint32_t code, + void *in_bytes, + uint32_t in_nbytes, + void *out_bytes, + uint32_t out_nbytes, + uint32_t *out_returned); -bool ezusb_iidx_interrupt_read(HANDLE handle, - struct ezusb_iidx_msg_interrupt_read_packet* packet); +bool ezusb_iidx_interrupt_read( + HANDLE handle, struct ezusb_iidx_msg_interrupt_read_packet *packet); -bool ezusb_iidx_interrupt_write(HANDLE handle, - const struct ezusb_iidx_msg_interrupt_write_packet* packet); +bool ezusb_iidx_interrupt_write( + HANDLE handle, const struct ezusb_iidx_msg_interrupt_write_packet *packet); -bool ezusb_iidx_bulk_read(HANDLE handle, - struct ezusb_iidx_msg_bulk_packet* packet); +bool ezusb_iidx_bulk_read( + HANDLE handle, struct ezusb_iidx_msg_bulk_packet *packet); -bool ezusb_iidx_bulk_write(HANDLE handle, - const struct ezusb_iidx_msg_bulk_packet* packet); +bool ezusb_iidx_bulk_write( + HANDLE handle, const struct ezusb_iidx_msg_bulk_packet *packet); -bool ezusb_iidx_execute_cmd(HANDLE handle, uint8_t node, - uint8_t cmd, uint8_t cmd_detail, uint8_t cmd_detail2, - struct ezusb_iidx_msg_interrupt_read_packet* int_read_data); +bool ezusb_iidx_execute_cmd( + HANDLE handle, + uint8_t node, + uint8_t cmd, + uint8_t cmd_detail, + uint8_t cmd_detail2, + struct ezusb_iidx_msg_interrupt_read_packet *int_read_data); -uint8_t ezusb_iidx_execute_cmd_retry(HANDLE handle, uint8_t node, - uint8_t cmd, uint8_t cmd_detail, uint8_t cmd_detail2, uint8_t int_reads); +uint8_t ezusb_iidx_execute_cmd_retry( + HANDLE handle, + uint8_t node, + uint8_t cmd, + uint8_t cmd_detail, + uint8_t cmd_detail2, + uint8_t int_reads); -bool ezusb_iidx_execute_cmd_timeout(HANDLE handle, uint8_t node, - uint8_t cmd, uint8_t cmd_detail, uint8_t cmd_detail2, - uint8_t expected_ret_code, uint32_t timeout_ms); +bool ezusb_iidx_execute_cmd_timeout( + HANDLE handle, + uint8_t node, + uint8_t cmd, + uint8_t cmd_detail, + uint8_t cmd_detail2, + uint8_t expected_ret_code, + uint32_t timeout_ms); #endif \ No newline at end of file diff --git a/src/main/ezusb-iidx/fpga.c b/src/main/ezusb-iidx/fpga.c index e455726..23d5fd0 100644 --- a/src/main/ezusb-iidx/fpga.c +++ b/src/main/ezusb-iidx/fpga.c @@ -9,8 +9,8 @@ #include "ezusb-iidx.h" #include "fpga-cmd.h" -static bool ezusb_iidx_fpga_write_fw_page(HANDLE handle, uint8_t node, - const void* buffer, uint16_t size) +static bool ezusb_iidx_fpga_write_fw_page( + HANDLE handle, uint8_t node, const void *buffer, uint16_t size) { struct ezusb_iidx_msg_bulk_packet packet; @@ -23,15 +23,15 @@ static bool ezusb_iidx_fpga_write_fw_page(HANDLE handle, uint8_t node, size = 62; } - //log_misc("Writing fpga page, size %d", size); + // log_misc("Writing fpga page, size %d", size); memcpy(packet.payload, buffer, size); return ezusb_iidx_bulk_write(handle, &packet); } -static bool ezusb_iidx_fpga_write_fw(HANDLE handle, uint8_t node, - const void* buffer, uint16_t size) +static bool ezusb_iidx_fpga_write_fw( + HANDLE handle, uint8_t node, const void *buffer, uint16_t size) { uint16_t offset; @@ -41,8 +41,8 @@ static bool ezusb_iidx_fpga_write_fw(HANDLE handle, uint8_t node, /* Write in ezusb page sizes */ while (offset < size) { - if ( !ezusb_iidx_fpga_write_fw_page(handle, node, buffer + offset, - size - offset)) { + if (!ezusb_iidx_fpga_write_fw_page( + handle, node, buffer + offset, size - offset)) { return false; } @@ -58,8 +58,12 @@ static bool ezusb_iidx_fpga_v1_reset(HANDLE handle) { log_info("[v1] Reset"); - if ( !ezusb_iidx_execute_cmd_timeout(handle, EZUSB_IIDX_MSG_NODE_FPGA_V1, - EZUSB_IIDX_FPGA_CMD_V1_INIT, 0x41, 0, + if (!ezusb_iidx_execute_cmd_timeout( + handle, + EZUSB_IIDX_MSG_NODE_FPGA_V1, + EZUSB_IIDX_FPGA_CMD_V1_INIT, + 0x41, + 0, EZUSB_IIDX_FPGA_CMD_STATUS_V1_OK_2, 10000)) { log_warning("[v1] Reset failed"); @@ -69,15 +73,21 @@ static bool ezusb_iidx_fpga_v1_reset(HANDLE handle) return true; } -static bool ezusb_iidx_fpga_v1_write(HANDLE handle, const void* buffer, uint16_t size) +static bool +ezusb_iidx_fpga_v1_write(HANDLE handle, const void *buffer, uint16_t size) { log_info("[v1] Write firmware, size %d", size); - /* Have a bunch of sleep between each command. If we try to send commands as fast as possible, the - hardware fails executing commands and might also crash. */ + /* Have a bunch of sleep between each command. If we try to send commands as + fast as possible, the hardware fails executing commands and might also + crash. */ - if ( !ezusb_iidx_execute_cmd_timeout(handle, EZUSB_IIDX_MSG_NODE_FPGA_V1, - EZUSB_IIDX_FPGA_CMD_V1_CHECK, 0x41, 0, + if (!ezusb_iidx_execute_cmd_timeout( + handle, + EZUSB_IIDX_MSG_NODE_FPGA_V1, + EZUSB_IIDX_FPGA_CMD_V1_CHECK, + 0x41, + 0, EZUSB_IIDX_FPGA_CMD_STATUS_V1_OK, 10000)) { log_warning("[v1] Check failed"); @@ -86,8 +96,12 @@ static bool ezusb_iidx_fpga_v1_write(HANDLE handle, const void* buffer, uint16_t Sleep(10); - if ( !ezusb_iidx_execute_cmd_timeout(handle, EZUSB_IIDX_MSG_NODE_FPGA_V1, - EZUSB_IIDX_FPGA_CMD_V1_WRITE, size >> 8, size, + if (!ezusb_iidx_execute_cmd_timeout( + handle, + EZUSB_IIDX_MSG_NODE_FPGA_V1, + EZUSB_IIDX_FPGA_CMD_V1_WRITE, + size >> 8, + size, EZUSB_IIDX_FPGA_CMD_STATUS_V1_OK, 10000)) { log_warning("[v1] Write failed"); @@ -96,16 +110,20 @@ static bool ezusb_iidx_fpga_v1_write(HANDLE handle, const void* buffer, uint16_t Sleep(10); - if ( !ezusb_iidx_fpga_write_fw(handle, EZUSB_IIDX_MSG_NODE_FPGA_V1, - buffer, size)) { + if (!ezusb_iidx_fpga_write_fw( + handle, EZUSB_IIDX_MSG_NODE_FPGA_V1, buffer, size)) { log_warning("[v1] Writing fw failed"); return false; } Sleep(10); - if ( !ezusb_iidx_execute_cmd_timeout(handle, EZUSB_IIDX_MSG_NODE_FPGA_V1, - EZUSB_IIDX_FPGA_CMD_V1_WRITE_DONE, size >> 8, size, + if (!ezusb_iidx_execute_cmd_timeout( + handle, + EZUSB_IIDX_MSG_NODE_FPGA_V1, + EZUSB_IIDX_FPGA_CMD_V1_WRITE_DONE, + size >> 8, + size, EZUSB_IIDX_FPGA_CMD_STATUS_V1_OK_2, 10000)) { log_warning("[v1] Write done failed"); @@ -114,8 +132,12 @@ static bool ezusb_iidx_fpga_v1_write(HANDLE handle, const void* buffer, uint16_t Sleep(10); - if ( !ezusb_iidx_execute_cmd_timeout(handle, EZUSB_IIDX_MSG_NODE_FPGA_V1, - EZUSB_IIDX_FPGA_CMD_V1_CHECK, size >> 8, size, + if (!ezusb_iidx_execute_cmd_timeout( + handle, + EZUSB_IIDX_MSG_NODE_FPGA_V1, + EZUSB_IIDX_FPGA_CMD_V1_CHECK, + size >> 8, + size, EZUSB_IIDX_FPGA_CMD_STATUS_V1_OK, 10000)) { log_warning("[v1] Check failed"); @@ -124,8 +146,12 @@ static bool ezusb_iidx_fpga_v1_write(HANDLE handle, const void* buffer, uint16_t Sleep(10); - if ( !ezusb_iidx_execute_cmd_timeout(handle, EZUSB_IIDX_MSG_NODE_FPGA_V1, - EZUSB_IIDX_FPGA_CMD_V1_CHECK_2, size >> 8, size, + if (!ezusb_iidx_execute_cmd_timeout( + handle, + EZUSB_IIDX_MSG_NODE_FPGA_V1, + EZUSB_IIDX_FPGA_CMD_V1_CHECK_2, + size >> 8, + size, EZUSB_IIDX_FPGA_CMD_STATUS_V1_OK_2, 10000)) { log_warning("[v1] Start failed"); @@ -139,8 +165,12 @@ static bool ezusb_iidx_fpga_v2_reset(HANDLE handle) { log_info("[v2] Reset"); - if ( !ezusb_iidx_execute_cmd_timeout(handle, EZUSB_IIDX_MSG_NODE_FPGA_V2, - EZUSB_IIDX_FPGA_CMD_V2_INIT, 1, 0, + if (!ezusb_iidx_execute_cmd_timeout( + handle, + EZUSB_IIDX_MSG_NODE_FPGA_V2, + EZUSB_IIDX_FPGA_CMD_V2_INIT, + 1, + 0, EZUSB_IIDX_FPGA_CMD_STATUS_V2_INIT_OK, 10000)) { log_warning("[v2] Reset failed"); @@ -150,7 +180,8 @@ static bool ezusb_iidx_fpga_v2_reset(HANDLE handle) return true; } -static bool ezusb_iidx_fpga_v2_write(HANDLE handle, const void* buffer, uint16_t size) +static bool +ezusb_iidx_fpga_v2_write(HANDLE handle, const void *buffer, uint16_t size) { log_info("[v2] Waiting for fpga ready to write..."); @@ -158,8 +189,12 @@ static bool ezusb_iidx_fpga_v2_write(HANDLE handle, const void* buffer, uint16_t while (true) { struct ezusb_iidx_msg_interrupt_read_packet int_read_data; - if ( !ezusb_iidx_execute_cmd(handle, EZUSB_IIDX_MSG_NODE_FPGA_V2, - EZUSB_IIDX_FPGA_CMD_V2_WRITE, size >> 8, size, + if (!ezusb_iidx_execute_cmd( + handle, + EZUSB_IIDX_MSG_NODE_FPGA_V2, + EZUSB_IIDX_FPGA_CMD_V2_WRITE, + size >> 8, + size, &int_read_data)) { log_warning("[v2] Write failed"); return false; @@ -174,22 +209,30 @@ static bool ezusb_iidx_fpga_v2_write(HANDLE handle, const void* buffer, uint16_t log_info("[v2] Write firmware, size %d", size); - if ( !ezusb_iidx_fpga_write_fw(handle, EZUSB_IIDX_MSG_NODE_FPGA_V2, - buffer, size)) { + if (!ezusb_iidx_fpga_write_fw( + handle, EZUSB_IIDX_MSG_NODE_FPGA_V2, buffer, size)) { log_warning("[v2] Writing fw failed"); return false; } - if ( !ezusb_iidx_execute_cmd_timeout(handle, EZUSB_IIDX_MSG_NODE_FPGA_V2, - EZUSB_IIDX_FPGA_CMD_V2_WRITE_DONE, size >> 8, size, + if (!ezusb_iidx_execute_cmd_timeout( + handle, + EZUSB_IIDX_MSG_NODE_FPGA_V2, + EZUSB_IIDX_FPGA_CMD_V2_WRITE_DONE, + size >> 8, + size, EZUSB_IIDX_FPGA_CMD_STATUS_V2_WRITE_OK, 10000)) { log_warning("[v2] Write done failed"); return false; } - if ( !ezusb_iidx_execute_cmd_timeout(handle, EZUSB_IIDX_MSG_NODE_FPGA_V2, - EZUSB_IIDX_FPGA_CMD_V2_CHECK, size >> 8, size, + if (!ezusb_iidx_execute_cmd_timeout( + handle, + EZUSB_IIDX_MSG_NODE_FPGA_V2, + EZUSB_IIDX_FPGA_CMD_V2_CHECK, + size >> 8, + size, EZUSB_IIDX_FPGA_CMD_STATUS_V2_CHECK_OK, 10000)) { log_warning("[v2] Start failed"); @@ -215,7 +258,7 @@ static bool ezusb_iidx_fpga_run_prog(HANDLE handle) return true; } -bool ezusb_iidx_fpga_v1_init(HANDLE handle, const void* buffer, uint16_t size) +bool ezusb_iidx_fpga_v1_init(HANDLE handle, const void *buffer, uint16_t size) { if (!ezusb_iidx_fpga_v1_reset(handle)) { return false; @@ -236,7 +279,7 @@ bool ezusb_iidx_fpga_v1_init(HANDLE handle, const void* buffer, uint16_t size) return true; } -bool ezusb_iidx_fpga_v2_init(HANDLE handle, const void* buffer, uint16_t size) +bool ezusb_iidx_fpga_v2_init(HANDLE handle, const void *buffer, uint16_t size) { if (!ezusb_iidx_fpga_v2_reset(handle)) { return false; diff --git a/src/main/ezusb-iidx/fpga.h b/src/main/ezusb-iidx/fpga.h index 2fc86cc..27a5c59 100644 --- a/src/main/ezusb-iidx/fpga.h +++ b/src/main/ezusb-iidx/fpga.h @@ -5,8 +5,8 @@ #include #include -bool ezusb_iidx_fpga_v1_init(HANDLE handle, const void* buffer, uint16_t size); +bool ezusb_iidx_fpga_v1_init(HANDLE handle, const void *buffer, uint16_t size); -bool ezusb_iidx_fpga_v2_init(HANDLE handle, const void* buffer, uint16_t size); +bool ezusb_iidx_fpga_v2_init(HANDLE handle, const void *buffer, uint16_t size); #endif \ No newline at end of file diff --git a/src/main/ezusb-iidx/msg.h b/src/main/ezusb-iidx/msg.h index fa50828..718f149 100644 --- a/src/main/ezusb-iidx/msg.h +++ b/src/main/ezusb-iidx/msg.h @@ -1,8 +1,8 @@ #ifndef EZUSB_IIDX_MSG_H #define EZUSB_IIDX_MSG_H -#include #include +#include #define EZUSB_PAGESIZE 62 @@ -56,40 +56,40 @@ struct ezusb_iidx_msg_interrupt_read_packet { /* Dip switches somewhere here? 0: Not used - 1: Not used - 2: Not used - 3: Not used - 4: Not used - 5: Not used - 6: usb mute? - 7: Not used + 1: Not used + 2: Not used + 3: Not used + 4: Not used + 5: Not used + 6: usb mute? + 7: Not used - 8: P1_1 - 9: P1_2 - 10: P1_3 - 11: P1_4 - 12: P1_5 - 13: P1_6 - 14: P1_7 - 15: P2_1 + 8: P1_1 + 9: P1_2 + 10: P1_3 + 11: P1_4 + 12: P1_5 + 13: P1_6 + 14: P1_7 + 15: P2_1 - 16: P2_2 - 17: P2_3 - 18: P2_4 - 19: P2_5 - 20: P2_6 - 21: P2_7 - 22: Coin mech - 23: Not used - 24: P1_Start + 16: P2_2 + 17: P2_3 + 18: P2_4 + 19: P2_5 + 20: P2_6 + 21: P2_7 + 22: Coin mech + 23: Not used + 24: P1_Start - 25: P2_Start - 26: VEFX - 27: Effector - 28: Test - 29: Service - 30: unknown/not used - 31: coin mode state: this needs to be set according to the currently + 25: P2_Start + 26: VEFX + 27: Effector + 28: Test + 29: Service + 30: unknown/not used + 31: coin mode state: this needs to be set according to the currently active coin node (coin mode1 -> 0, coin mode 2 -> 1) */ uint32_t inverted_pad; diff --git a/src/main/ezusb-iidx/seg16-cmd.h b/src/main/ezusb-iidx/seg16-cmd.h index fe93c3a..1967f23 100644 --- a/src/main/ezusb-iidx/seg16-cmd.h +++ b/src/main/ezusb-iidx/seg16-cmd.h @@ -10,5 +10,4 @@ enum ezusb_iidx_16seg_command_status { EZUSB_IIDX_16SEG_CMD_STATUS_FAULT = 0xFE }; - #endif \ No newline at end of file diff --git a/src/main/ezusb-iidx/sram.c b/src/main/ezusb-iidx/sram.c index df0a44a..f816b38 100644 --- a/src/main/ezusb-iidx/sram.c +++ b/src/main/ezusb-iidx/sram.c @@ -7,8 +7,12 @@ #include "ezusb-iidx.h" #include "sram-cmd.h" -static bool ezusb_iidx_sram_write_page(HANDLE handle, uint8_t node, - uint8_t page, const void* buffer, uint16_t size) +static bool ezusb_iidx_sram_write_page( + HANDLE handle, + uint8_t node, + uint8_t page, + const void *buffer, + uint16_t size) { struct ezusb_iidx_msg_bulk_packet packet; @@ -21,7 +25,7 @@ static bool ezusb_iidx_sram_write_page(HANDLE handle, uint8_t node, size = 62; } - //log_misc("Writing sram page %d, size %d", page, size); + // log_misc("Writing sram page %d, size %d", page, size); memcpy(packet.payload, buffer, size); @@ -37,8 +41,12 @@ static bool ezusb_iidx_sram_read_page(HANDLE handle, uint8_t node) return ezusb_iidx_bulk_read(handle, &packet); } -static bool ezusb_iidx_sram_write(HANDLE handle, uint8_t node, - const void* buffer, uint16_t size, uint8_t* pages_written) +static bool ezusb_iidx_sram_write( + HANDLE handle, + uint8_t node, + const void *buffer, + uint16_t size, + uint8_t *pages_written) { uint8_t page; uint16_t offset; @@ -49,8 +57,8 @@ static bool ezusb_iidx_sram_write(HANDLE handle, uint8_t node, /* Write in ezusb page sizes */ while (offset < size) { - if ( !ezusb_iidx_sram_write_page(handle, node, page++, - buffer + offset, size - offset)) { + if (!ezusb_iidx_sram_write_page( + handle, node, page++, buffer + offset, size - offset)) { return false; } @@ -78,39 +86,54 @@ static bool ezusb_iidx_sram_read(HANDLE handle, uint8_t node, uint8_t pages) return true; } -bool ezusb_iidx_sram_init(HANDLE handle, const void* buffer, uint16_t size) +bool ezusb_iidx_sram_init(HANDLE handle, const void *buffer, uint16_t size) { uint8_t pages_written; struct ezusb_iidx_msg_interrupt_read_packet int_read_data; log_info("Init, size %d", size); - ezusb_iidx_execute_cmd(handle, EZUSB_IIDX_MSG_NODE_SRAM, - EZUSB_IIDX_SRAM_CMD_WRITE, 1, 0, &int_read_data); + ezusb_iidx_execute_cmd( + handle, + EZUSB_IIDX_MSG_NODE_SRAM, + EZUSB_IIDX_SRAM_CMD_WRITE, + 1, + 0, + &int_read_data); log_info("Writing..."); - if ( !ezusb_iidx_sram_write(handle, EZUSB_IIDX_MSG_NODE_SRAM, - buffer, size, &pages_written)) { - log_warning("Writing sram failed, pages written so far: %d", - pages_written); + if (!ezusb_iidx_sram_write( + handle, EZUSB_IIDX_MSG_NODE_SRAM, buffer, size, &pages_written)) { + log_warning( + "Writing sram failed, pages written so far: %d", pages_written); return false; } log_info("Data written, pages: %d", pages_written); log_info("Reading back..."); - ezusb_iidx_execute_cmd(handle, EZUSB_IIDX_MSG_NODE_SRAM, - EZUSB_IIDX_SRAM_CMD_READ, 1, 0, &int_read_data); + ezusb_iidx_execute_cmd( + handle, + EZUSB_IIDX_MSG_NODE_SRAM, + EZUSB_IIDX_SRAM_CMD_READ, + 1, + 0, + &int_read_data); - if (!ezusb_iidx_sram_read(handle, EZUSB_IIDX_MSG_NODE_SRAM, - pages_written)) { + if (!ezusb_iidx_sram_read( + handle, EZUSB_IIDX_MSG_NODE_SRAM, pages_written)) { log_warning("Reading back failed"); return false; } - ezusb_iidx_execute_cmd(handle, EZUSB_IIDX_MSG_NODE_SRAM, - EZUSB_IIDX_SRAM_CMD_DONE, 1, 0, &int_read_data); + ezusb_iidx_execute_cmd( + handle, + EZUSB_IIDX_MSG_NODE_SRAM, + EZUSB_IIDX_SRAM_CMD_DONE, + 1, + 0, + &int_read_data); return true; } \ No newline at end of file diff --git a/src/main/ezusb-iidx/sram.h b/src/main/ezusb-iidx/sram.h index 626ee47..3a4d1a5 100644 --- a/src/main/ezusb-iidx/sram.h +++ b/src/main/ezusb-iidx/sram.h @@ -5,6 +5,6 @@ #include #include -bool ezusb_iidx_sram_init(HANDLE handle, const void* buffer, uint16_t size); +bool ezusb_iidx_sram_init(HANDLE handle, const void *buffer, uint16_t size); #endif \ No newline at end of file diff --git a/src/main/ezusb-iidx/wdt-cmd.h b/src/main/ezusb-iidx/wdt-cmd.h index 4de3d51..016b970 100644 --- a/src/main/ezusb-iidx/wdt-cmd.h +++ b/src/main/ezusb-iidx/wdt-cmd.h @@ -1,9 +1,7 @@ #ifndef EZUSB_IIDX_WDT_CMD_H #define EZUSB_IIDX_WDT_CMD_H -enum ezusb_iidx_wdt_command { - EZUSB_IIDX_WDT_CMD_INIT = 0x3C -}; +enum ezusb_iidx_wdt_command { EZUSB_IIDX_WDT_CMD_INIT = 0x3C }; enum ezusb_iidx_wdt_command_status { EZUSB_IIDX_WDT_CMD_STATUS_OK = 0x00, diff --git a/src/main/ezusb-tool/main.c b/src/main/ezusb-tool/main.c index 31401ba..115f79c 100644 --- a/src/main/ezusb-tool/main.c +++ b/src/main/ezusb-tool/main.c @@ -3,8 +3,8 @@ #include #include -#include "ezusb/util.h" #include "ezusb/ezusb.h" +#include "ezusb/util.h" #include "util/log.h" @@ -35,10 +35,10 @@ static int info() return 0; } -static int flash(const char* fw_path) +static int flash(const char *fw_path) { HANDLE handle; - struct ezusb_firmware* fw; + struct ezusb_firmware *fw; fw = ezusb_firmware_load(fw_path); @@ -47,8 +47,8 @@ static int flash(const char* fw_path) return -5; } - log_misc("Loaded firmware, crc 0x%X, segments %d", fw->crc, - fw->segment_count); + log_misc( + "Loaded firmware, crc 0x%X, segments %d", fw->crc, fw->segment_count); if (ezusb_firmware_crc(fw) != fw->crc) { log_fatal("Firmware CRC check failed"); @@ -80,18 +80,19 @@ static int flash(const char* fw_path) return 0; } -static void usage(const char* argv0) +static void usage(const char *argv0) { - printf("ezusb-tool for EZUSB hardware, e.g. IIDX C02 IO, build " - __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) "\n" - "Usage: %s [cmd] ...\n" - "Available commands:\n" - " info: Get basic information (vid, pid, name) of a connected " - "device\n" - " flash: Flash a firmware binary\n", argv0); + printf("ezusb-tool for EZUSB hardware, e.g. IIDX C02 IO, build " __DATE__ " " __TIME__ + ", gitrev " STRINGIFY(GITREV) "\n" + "Usage: %s [cmd] ...\n" + "Available commands:\n" + " info: Get basic information (vid, pid, name) of a connected " + "device\n" + " flash: Flash a firmware binary\n", + argv0); } -int main(int argc, char** argv) +int main(int argc, char **argv) { int arg_pos; @@ -110,7 +111,8 @@ int main(int argc, char** argv) arg_pos++; if (arg_pos >= argc) { - printf("Usage: flash [fw_path]\n" + printf( + "Usage: flash [fw_path]\n" " fw_path: Path to firmware binary file to flash\n"); return -1; } diff --git a/src/main/ezusb/ezusb.c b/src/main/ezusb/ezusb.c index 64190ea..81ed191 100644 --- a/src/main/ezusb/ezusb.c +++ b/src/main/ezusb/ezusb.c @@ -1,5 +1,5 @@ -#include #include +#include #include "ezusb/ezusb.h" #include "ezusb/ezusbsys2.h" @@ -36,39 +36,54 @@ static bool ezusb_reset(HANDLE handle, bool hold) req.index = 0x0000; } - if (!DeviceIoControl(handle, IOCTL_Ezusb_VENDOR_REQUEST, &req, - sizeof(req), &req, sizeof(req), &outpkt, NULL)) { + if (!DeviceIoControl( + handle, + IOCTL_Ezusb_VENDOR_REQUEST, + &req, + sizeof(req), + &req, + sizeof(req), + &outpkt, + NULL)) { return false; } return true; } -static bool ezusb_write_firmware(HANDLE handle, const void* buffer, - uint16_t ram_offset, uint32_t size) +static bool ezusb_write_firmware( + HANDLE handle, const void *buffer, uint16_t ram_offset, uint32_t size) { ANCHOR_DOWNLOAD_CONTROL req; DWORD outpkt; req.Offset = ram_offset; - if (!DeviceIoControl(handle, IOCTL_EZUSB_ANCHOR_DOWNLOAD, &req, - sizeof(req), (void*) buffer, size, &outpkt, NULL)) { + if (!DeviceIoControl( + handle, + IOCTL_EZUSB_ANCHOR_DOWNLOAD, + &req, + sizeof(req), + (void *) buffer, + size, + &outpkt, + NULL)) { return false; } return true; } -HANDLE ezusb_open(const char* path) +HANDLE +ezusb_open(const char *path) { log_assert(path); - return CreateFileA(path, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, - OPEN_EXISTING, 0, NULL); + return CreateFileA( + path, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); } -bool ezusb_get_ident(HANDLE handle, struct ezusb_ident* ident) +bool ezusb_get_ident(HANDLE handle, struct ezusb_ident *ident) { USB_DEVICE_DESCRIPTOR desc; DWORD outpkt; @@ -77,8 +92,15 @@ bool ezusb_get_ident(HANDLE handle, struct ezusb_ident* ident) log_assert(handle != INVALID_HANDLE_VALUE); log_assert(ident); - if (!DeviceIoControl(handle, IOCTL_Ezusb_GET_DEVICE_DESCRIPTOR, &desc, - sizeof(desc), &desc, sizeof(desc), &outpkt, NULL)) { + if (!DeviceIoControl( + handle, + IOCTL_Ezusb_GET_DEVICE_DESCRIPTOR, + &desc, + sizeof(desc), + &desc, + sizeof(desc), + &outpkt, + NULL)) { return false; } @@ -89,7 +111,7 @@ bool ezusb_get_ident(HANDLE handle, struct ezusb_ident* ident) return true; } -bool ezusb_download_firmware(HANDLE handle, struct ezusb_firmware* fw) +bool ezusb_download_firmware(HANDLE handle, struct ezusb_firmware *fw) { log_assert(handle); log_assert(handle != INVALID_HANDLE_VALUE); @@ -100,8 +122,11 @@ bool ezusb_download_firmware(HANDLE handle, struct ezusb_firmware* fw) } for (uint16_t i = 0; i < fw->segment_count; i++) { - if (!ezusb_write_firmware(handle, fw->segments[i]->data, - fw->segments[i]->offset, fw->segments[i]->size)) { + if (!ezusb_write_firmware( + handle, + fw->segments[i]->data, + fw->segments[i]->offset, + fw->segments[i]->size)) { return false; } } diff --git a/src/main/ezusb/ezusb.h b/src/main/ezusb/ezusb.h index b1a9231..b12f4a0 100644 --- a/src/main/ezusb/ezusb.h +++ b/src/main/ezusb/ezusb.h @@ -1,17 +1,17 @@ /** * Module for fundamental communication with a legacy Ezusb board, e.g. * IIDX C02 IO. - * + * * This module does not implement any sort of higher level protocol which is * required by the games to exchange data with the device, e.g. getting input * states of keys and setting light outputs. Further modules are utilizing this * base layer to implement higher level communication. - * + * * Note: This module requires the old "cyusb" driver which is NOT compatible * with anything newer than WinXP and does not support 64-bit systems. The newer * "cyusb3" driver does NOT work with this. - * - * @author icex2 + * + * @author icex2 */ #ifndef EZUSB_H #define EZUSB_H @@ -23,7 +23,10 @@ #include "ezusb/util.h" -static const GUID EZUSB_GUID = {0xAE18AA60, 0x7F6A, 0x11D4, +static const GUID EZUSB_GUID = { + 0xAE18AA60, + 0x7F6A, + 0x11D4, {0x97, 0xDD, 0x00, 0x01, 0x02, 0x29, 0xB9, 0x59}}; /* Used by IIDX instead of scanning for the device */ @@ -47,38 +50,38 @@ static const GUID EZUSB_GUID = {0xAE18AA60, 0x7F6A, 0x11D4, * \\\\.\\Ezusb-3 * \\\\.\\Ezusb-4 * \\\\.\\Ezusb-5 - * + * * Where \\\\.\\Ezusb-X is used if slot X-1 is still occupied, e.g. when * flashing the device and after a usb re-enumerate. - * + * * @param device_path Path to the Ezusb device. - * @return A valid handle to the device on success, INVALID_HANDLE_VALUE on + * @return A valid handle to the device on success, INVALID_HANDLE_VALUE on * error. */ -HANDLE ezusb_open(const char* path); +HANDLE ezusb_open(const char *path); /** * Get identifier information of the device. - * + * * @param handle Valid device handle. * @param ident Pointer to memory to write the identifier information to. * @return True if successful and identifier information was written to the * the struct, false on error. */ -bool ezusb_get_ident(HANDLE handle, struct ezusb_ident* ident); +bool ezusb_get_ident(HANDLE handle, struct ezusb_ident *ident); /** * Download a firmware to the ezusb device. - * + * * @param handle Valid device handle. * @param fw Firmware to write to the target ezusb device. * @return True on success, false on failure. */ -bool ezusb_download_firmware(HANDLE handle, struct ezusb_firmware* fw); +bool ezusb_download_firmware(HANDLE handle, struct ezusb_firmware *fw); /** * Close an opened ezusb device handle. - * + * * @param handle Valid handle to close. */ void ezusb_close(HANDLE handle); diff --git a/src/main/ezusb/ezusbsys.h b/src/main/ezusb/ezusbsys.h index f2cebdf..b43466b 100644 --- a/src/main/ezusb/ezusbsys.h +++ b/src/main/ezusb/ezusbsys.h @@ -209,26 +209,25 @@ // // This one is implemented in the core // -#define ANCHOR_LOAD_INTERNAL 0xA0 +#define ANCHOR_LOAD_INTERNAL 0xA0 // // These commands are not implemented in the core. Requires firmware // -#define ANCHOR_LOAD_EXTERNAL 0xA3 -#define ANCHOR_ISFX2 0xAC +#define ANCHOR_LOAD_EXTERNAL 0xA3 +#define ANCHOR_ISFX2 0xAC // // This is the highest internal RAM address for the AN2131Q // -#define MAX_INTERNAL_ADDRESS 0x1B3F +#define MAX_INTERNAL_ADDRESS 0x1B3F #define INTERNAL_RAM(address) ((address <= MAX_INTERNAL_ADDRESS) ? 1 : 0) // // EZ-USB Control and Status Register. Bit 0 controls 8051 reset // -#define CPUCS_REG_EZUSB 0x7F92 -#define CPUCS_REG_FX2 0xE600 - +#define CPUCS_REG_EZUSB 0x7F92 +#define CPUCS_REG_FX2 0xE600 #ifndef _BYTE_DEFINED #define _BYTE_DEFINED @@ -240,14 +239,13 @@ typedef unsigned char BYTE; typedef unsigned short WORD; #endif // !_WORD_DEFINED -typedef struct _VENDOR_REQUEST_IN -{ - BYTE bRequest; - WORD wValue; - WORD wIndex; - WORD wLength; - BYTE direction; - BYTE bData; +typedef struct _VENDOR_REQUEST_IN { + BYTE bRequest; + WORD wValue; + WORD wIndex; + WORD wLength; + BYTE direction; + BYTE bData; } VENDOR_REQUEST_IN, *PVENDOR_REQUEST_IN; /////////////////////////////////////////////////////////// @@ -255,35 +253,31 @@ typedef struct _VENDOR_REQUEST_IN // control structure for bulk and interrupt data transfers // /////////////////////////////////////////////////////////// -typedef struct _BULK_TRANSFER_CONTROL -{ - ULONG pipeNum; +typedef struct _BULK_TRANSFER_CONTROL { + ULONG pipeNum; } BULK_TRANSFER_CONTROL, *PBULK_TRANSFER_CONTROL; -typedef struct _BULK_LATENCY_CONTROL -{ - ULONG bulkPipeNum; - ULONG intPipeNum; - ULONG loops; +typedef struct _BULK_LATENCY_CONTROL { + ULONG bulkPipeNum; + ULONG intPipeNum; + ULONG loops; } BULK_LATENCY_CONTROL, *PBULK_LATENCY_CONTROL; - /////////////////////////////////////////////////////////// // // control structure isochronous loopback test // /////////////////////////////////////////////////////////// -typedef struct _ISO_LOOPBACK_CONTROL -{ - // iso pipe to write to - ULONG outPipeNum; +typedef struct _ISO_LOOPBACK_CONTROL { + // iso pipe to write to + ULONG outPipeNum; - // iso pipe to read from - ULONG inPipeNum; + // iso pipe to read from + ULONG inPipeNum; - // amount of data to read/write from/to the pipe each frame. If not - // specified, the MaxPacketSize of the out pipe is used. - ULONG packetSize; + // amount of data to read/write from/to the pipe each frame. If not + // specified, the MaxPacketSize of the out pipe is used. + ULONG packetSize; } ISO_LOOPBACK_CONTROL, *PISO_LOOPBACK_CONTROL; @@ -293,30 +287,28 @@ typedef struct _ISO_LOOPBACK_CONTROL // to the control endpoint. // /////////////////////////////////////////////////////////// -typedef struct _VENDOR_OR_CLASS_REQUEST_CONTROL -{ - // transfer direction (0=host to device, 1=device to host) - UCHAR direction; +typedef struct _VENDOR_OR_CLASS_REQUEST_CONTROL { + // transfer direction (0=host to device, 1=device to host) + UCHAR direction; - // request type (1=class, 2=vendor) - UCHAR requestType; + // request type (1=class, 2=vendor) + UCHAR requestType; - // recipient (0=device,1=interface,2=endpoint,3=other) - UCHAR recepient; - // - // see the USB Specification for an explanation of the - // following paramaters. - // - UCHAR requestTypeReservedBits; - UCHAR request; - USHORT value; - USHORT index; + // recipient (0=device,1=interface,2=endpoint,3=other) + UCHAR recepient; + // + // see the USB Specification for an explanation of the + // following paramaters. + // + UCHAR requestTypeReservedBits; + UCHAR request; + USHORT value; + USHORT index; } VENDOR_OR_CLASS_REQUEST_CONTROL, *PVENDOR_OR_CLASS_REQUEST_CONTROL; -typedef struct _SET_FEATURE_CONTROL -{ - USHORT FeatureSelector; - USHORT Index; +typedef struct _SET_FEATURE_CONTROL { + USHORT FeatureSelector; + USHORT Index; } SET_FEATURE_CONTROL, *PSET_FEATURE_CONTROL; /////////////////////////////////////////////////////////// @@ -324,120 +316,100 @@ typedef struct _SET_FEATURE_CONTROL // control structure for isochronous data transfers // /////////////////////////////////////////////////////////// -typedef struct _ISO_TRANSFER_CONTROL -{ - // - // pipe number to perform the ISO transfer to/from. Direction is - // implied by the pipe number. - // - ULONG PipeNum; - // - // ISO packet size. Determines how much data is transferred each - // frame. Should be less than or equal to the maxpacketsize for - // the endpoint. - // - ULONG PacketSize; - // - // Total number of ISO packets to transfer. - // - ULONG PacketCount; - // - // The following two parameters detmine how buffers are managed for - // an ISO transfer. In order to maintain an ISO stream, the driver - // must create at least 2 transfer buffers and ping pong between them. - // BufferCount determines how many buffers the driver creates to ping - // pong between. FramesPerBuffer specifies how many USB frames of data - // are transferred by each buffer. - // - ULONG FramesPerBuffer; // 10 is a good value - ULONG BufferCount; // 2 is a good value +typedef struct _ISO_TRANSFER_CONTROL { + // + // pipe number to perform the ISO transfer to/from. Direction is + // implied by the pipe number. + // + ULONG PipeNum; + // + // ISO packet size. Determines how much data is transferred each + // frame. Should be less than or equal to the maxpacketsize for + // the endpoint. + // + ULONG PacketSize; + // + // Total number of ISO packets to transfer. + // + ULONG PacketCount; + // + // The following two parameters detmine how buffers are managed for + // an ISO transfer. In order to maintain an ISO stream, the driver + // must create at least 2 transfer buffers and ping pong between them. + // BufferCount determines how many buffers the driver creates to ping + // pong between. FramesPerBuffer specifies how many USB frames of data + // are transferred by each buffer. + // + ULONG FramesPerBuffer; // 10 is a good value + ULONG BufferCount; // 2 is a good value } ISO_TRANSFER_CONTROL, *PISO_TRANSFER_CONTROL; - /////////////////////////////////////////////////////////// // // control structure for Anchor Downloads // /////////////////////////////////////////////////////////// -typedef struct _ANCHOR_DOWNLOAD_CONTROL -{ - WORD Offset; +typedef struct _ANCHOR_DOWNLOAD_CONTROL { + WORD Offset; } ANCHOR_DOWNLOAD_CONTROL, *PANCHOR_DOWNLOAD_CONTROL; #define MAX_INTEL_HEX_RECORD_LENGTH 16 -typedef struct _INTEL_HEX_RECORD -{ - BYTE Length; - WORD Address; - BYTE Type; - BYTE Data[MAX_INTEL_HEX_RECORD_LENGTH]; +typedef struct _INTEL_HEX_RECORD { + BYTE Length; + WORD Address; + BYTE Type; + BYTE Data[MAX_INTEL_HEX_RECORD_LENGTH]; } INTEL_HEX_RECORD, *PINTEL_HEX_RECORD; -typedef struct _SET_INTERFACE_IN -{ - UCHAR interfaceNum; - UCHAR alternateSetting; +typedef struct _SET_INTERFACE_IN { + UCHAR interfaceNum; + UCHAR alternateSetting; } SET_INTERFACE_IN, *PSET_INTERFACE_IN; -typedef struct _GET_STRING_DESCRIPTOR_IN -{ - UCHAR Index; - USHORT LanguageId; +typedef struct _GET_STRING_DESCRIPTOR_IN { + UCHAR Index; + USHORT LanguageId; } GET_STRING_DESCRIPTOR_IN, *PGET_STRING_DESCRIPTOR_IN; -typedef struct _EZUSB_DRIVER_VERSION -{ - WORD MajorVersion; - WORD MinorVersion; - WORD BuildVersion; +typedef struct _EZUSB_DRIVER_VERSION { + WORD MajorVersion; + WORD MinorVersion; + WORD BuildVersion; } EZUSB_DRIVER_VERSION, *PEZUSB_DRIVER_VERSION; #ifdef DRIVER -typedef struct _RING_BUFFER -{ - PUCHAR inPtr; - PUCHAR outPtr; - ULONG totalSize; - ULONG currentSize; - KSPIN_LOCK spinLock; - PUCHAR buffer; +typedef struct _RING_BUFFER { + PUCHAR inPtr; + PUCHAR outPtr; + ULONG totalSize; + ULONG currentSize; + KSPIN_LOCK spinLock; + PUCHAR buffer; } RING_BUFFER, *PRING_BUFFER; PRING_BUFFER -AllocRingBuffer( - ULONG Size - ); +AllocRingBuffer(ULONG Size); -VOID -FreeRingBuffer( - PRING_BUFFER ringBuffer - ); +VOID FreeRingBuffer(PRING_BUFFER ringBuffer); ULONG ReadRingBuffer( - PRING_BUFFER ringBuffer, - PUCHAR readBuffer, - ULONG numberOfBytesToRead - ); + PRING_BUFFER ringBuffer, PUCHAR readBuffer, ULONG numberOfBytesToRead); ULONG WriteRingBuffer( - PRING_BUFFER ringBuffer, - PUCHAR writeBuffer, - ULONG numberOfBytesToWrite - ); + PRING_BUFFER ringBuffer, PUCHAR writeBuffer, ULONG numberOfBytesToWrite); -typedef struct _EZUSB_FIRMWARE -{ - // tag contains a string to identify the start of the firmware - // image in the driver binary. Another utilty can then be used - // to replace the firmware image inthe driver without requiring - // a recompile - UCHAR tag[10]; - ULONG size; - UCHAR firmware[]; +typedef struct _EZUSB_FIRMWARE { + // tag contains a string to identify the start of the firmware + // image in the driver binary. Another utilty can then be used + // to replace the firmware image inthe driver without requiring + // a recompile + UCHAR tag[10]; + ULONG size; + UCHAR firmware[]; } EZUSB_FIRMWARE, *PEZUSB_FIRMWARE; // @@ -454,37 +426,31 @@ typedef struct _EZUSB_FIRMWARE typedef struct _ISO_STREAM_OBJECT ISO_STREAM_OBJECT, *PISO_STREAM_OBJECT; -typedef struct _ISO_TRANSFER_OBJECT -{ - ULONG Frame; - PISO_STREAM_OBJECT StreamObject; - PURB Urb; - PIRP Irp; - KEVENT Done; +typedef struct _ISO_TRANSFER_OBJECT { + ULONG Frame; + PISO_STREAM_OBJECT StreamObject; + PURB Urb; + PIRP Irp; + KEVENT Done; } ISO_TRANSFER_OBJECT, *PISO_TRANSFER_OBJECT; -typedef struct _ISO_STREAM_OBJECT -{ - PDEVICE_OBJECT DeviceObject; - ULONG PacketSize; - ULONG NumPackets; - PUSBD_PIPE_INFORMATION PipeInfo; - PVOID TransferBuffer; - ULONG TransferBufferLength; - PVOID IsoDescriptorBuffer; - ULONG FramesPerBuffer; - ULONG BufferCount; - ULONG PendingTransfers; - PRING_BUFFER DataRingBuffer; - PRING_BUFFER DescriptorRingBuffer; - PISO_TRANSFER_OBJECT TransferObject; +typedef struct _ISO_STREAM_OBJECT { + PDEVICE_OBJECT DeviceObject; + ULONG PacketSize; + ULONG NumPackets; + PUSBD_PIPE_INFORMATION PipeInfo; + PVOID TransferBuffer; + ULONG TransferBufferLength; + PVOID IsoDescriptorBuffer; + ULONG FramesPerBuffer; + ULONG BufferCount; + ULONG PendingTransfers; + PRING_BUFFER DataRingBuffer; + PRING_BUFFER DescriptorRingBuffer; + PISO_TRANSFER_OBJECT TransferObject; } ISO_STREAM_OBJECT, *PISO_STREAM_OBJECT; - -#define Ezusb_NAME_MAX 64 - - - +#define Ezusb_NAME_MAX 64 // // This is an unused structure in this driver, but is provided here @@ -492,405 +458,269 @@ typedef struct _ISO_STREAM_OBJECT // to use this structure as an example or model. // typedef struct _EZUSB_PIPE { - ULONG Mode; - ULONG Option; - ULONG Param1; - ULONG Param2; - WCHAR Name[Ezusb_NAME_MAX]; - PUSBD_PIPE_INFORMATION PipeInfo; + ULONG Mode; + ULONG Option; + ULONG Param1; + ULONG Param2; + WCHAR Name[Ezusb_NAME_MAX]; + PUSBD_PIPE_INFORMATION PipeInfo; } EZUSB_PIPE, *PEZUSB_PIPE; - /* // The interface number on this device that this driver expects to use -// This would be in the bInterfaceNumber field of the Interface Descriptor, hence +// This would be in the bInterfaceNumber field of the Interface Descriptor, +hence // this device driver would need to know this value. */ #define SAMPLE_INTERFACE_NBR 0x00 - // // A structure representing the instance information associated with // this particular device. // -typedef struct _DEVICE_EXTENSION -{ +typedef struct _DEVICE_EXTENSION { + // physical device object + PDEVICE_OBJECT PhysicalDeviceObject; - // physical device object - PDEVICE_OBJECT PhysicalDeviceObject; + // Device object we call when submitting Urbs/Irps to the USB stack + PDEVICE_OBJECT StackDeviceObject; - // Device object we call when submitting Urbs/Irps to the USB stack - PDEVICE_OBJECT StackDeviceObject; + // Indicates that we have recieved a STOP message + BOOLEAN Stopped; - // Indicates that we have recieved a STOP message - BOOLEAN Stopped; + // Indicates that we are enumerated and configured. Used to hold + // of requests until we are ready for them + BOOLEAN Started; - // Indicates that we are enumerated and configured. Used to hold - // of requests until we are ready for them - BOOLEAN Started; + // Indicates the device needs to be cleaned up (ie., some configuration + // has occurred and needs to be torn down). + BOOLEAN NeedCleanup; - // Indicates the device needs to be cleaned up (ie., some configuration - // has occurred and needs to be torn down). - BOOLEAN NeedCleanup; + // configuration handle for the configuration the + // device is currently in + USBD_CONFIGURATION_HANDLE ConfigurationHandle; - // configuration handle for the configuration the - // device is currently in - USBD_CONFIGURATION_HANDLE ConfigurationHandle; + // ptr to the USB device descriptor + // for this device + PUSB_DEVICE_DESCRIPTOR DeviceDescriptor; - // ptr to the USB device descriptor - // for this device - PUSB_DEVICE_DESCRIPTOR DeviceDescriptor; + // we support up to one interface + PUSBD_INTERFACE_INFORMATION Interface; - // we support up to one interface - PUSBD_INTERFACE_INFORMATION Interface; + // the number of device handles currently open to the device object. + // Gets incremented by Create and decremented by Close + ULONG OpenHandles; - // the number of device handles currently open to the device object. - // Gets incremented by Create and decremented by Close - ULONG OpenHandles; + // Name buffer for our named Functional device object link + WCHAR DeviceLinkNameBuffer[Ezusb_NAME_MAX]; - // Name buffer for our named Functional device object link - WCHAR DeviceLinkNameBuffer[Ezusb_NAME_MAX]; + // This member is used to store the URB status of the + // most recently failed URB. If a USB transfer fails, a caller + // can use IOCTL_EZUSB_GET_LAST_ERROR to retrieve this value. + // There's only room for one, so you better get it quick (or at + // least before the next URB failure occurs). + USBD_STATUS LastFailedUrbStatus; - // This member is used to store the URB status of the - // most recently failed URB. If a USB transfer fails, a caller - // can use IOCTL_EZUSB_GET_LAST_ERROR to retrieve this value. - // There's only room for one, so you better get it quick (or at - // least before the next URB failure occurs). - USBD_STATUS LastFailedUrbStatus; + // use counter for the device. Gets incremented when the driver receives + // a request and gets decremented when a request s completed. + LONG usage; - // use counter for the device. Gets incremented when the driver receives - // a request and gets decremented when a request s completed. - LONG usage; - - // this ev gets set when it is ok to remove the device + // this ev gets set when it is ok to remove the device KEVENT evRemove; - // TRUE if we're trying to remove this device - BOOLEAN removing; + // TRUE if we're trying to remove this device + BOOLEAN removing; - BOOLEAN StopIsoStream; + BOOLEAN StopIsoStream; - PRING_BUFFER DataRingBuffer; - PRING_BUFFER DescriptorRingBuffer; + PRING_BUFFER DataRingBuffer; + PRING_BUFFER DescriptorRingBuffer; } DEVICE_EXTENSION, *PDEVICE_EXTENSION; - #if DBG -#define Ezusb_KdPrint(_x_) DbgPrint("Ezusb.SYS: "); \ - DbgPrint _x_ ; +#define Ezusb_KdPrint(_x_) \ + DbgPrint("Ezusb.SYS: "); \ + DbgPrint _x_; #define TRAP() DbgBreakPoint() #else #define Ezusb_KdPrint(_x_) #define TRAP() #endif +NTSTATUS +Ezusb_Dispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); + +VOID Ezusb_Unload(IN PDRIVER_OBJECT DriverObject); NTSTATUS -Ezusb_Dispatch( - IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp - ); - -VOID -Ezusb_Unload( - IN PDRIVER_OBJECT DriverObject - ); +Ezusb_StartDevice(IN PDEVICE_OBJECT DeviceObject); NTSTATUS -Ezusb_StartDevice( - IN PDEVICE_OBJECT DeviceObject - ); +Ezusb_StopDevice(IN PDEVICE_OBJECT DeviceObject); NTSTATUS -Ezusb_StopDevice( - IN PDEVICE_OBJECT DeviceObject - ); +Ezusb_RemoveDevice(IN PDEVICE_OBJECT DeviceObject); NTSTATUS -Ezusb_RemoveDevice( - IN PDEVICE_OBJECT DeviceObject - ); - -NTSTATUS -Ezusb_CallUSBD( - IN PDEVICE_OBJECT DeviceObject, - IN PURB Urb - ); +Ezusb_CallUSBD(IN PDEVICE_OBJECT DeviceObject, IN PURB Urb); NTSTATUS Ezusb_PnPAddDevice( - IN PDRIVER_OBJECT DriverObject, - IN PDEVICE_OBJECT PhysicalDeviceObject - ); + IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject); NTSTATUS Ezusb_CreateDeviceObject( IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT *DeviceObject, - LONG Instance - ); + LONG Instance); NTSTATUS -Ezusb_ConfigureDevice( - IN PDEVICE_OBJECT DeviceObject - ); +Ezusb_ConfigureDevice(IN PDEVICE_OBJECT DeviceObject); NTSTATUS -Ezusb_Create( - IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp - ); +Ezusb_Create(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); NTSTATUS -Ezusb_Close( - IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp - ); +Ezusb_Close(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); NTSTATUS -Ezusb_Read_Write( - IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp - ); +Ezusb_Read_Write(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); NTSTATUS -Ezusb_ProcessIOCTL( - IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp - ); +Ezusb_ProcessIOCTL(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); NTSTATUS Ezusb_SelectInterfaces( IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, - IN PUSBD_INTERFACE_INFORMATION Interface - ); + IN PUSBD_INTERFACE_INFORMATION Interface); NTSTATUS -Ezusb_ResetPipe( - IN PDEVICE_OBJECT DeviceObject, - IN ULONG PipeNum - ); +Ezusb_ResetPipe(IN PDEVICE_OBJECT DeviceObject, IN ULONG PipeNum); NTSTATUS -Ezusb_AbortPipe( - IN PDEVICE_OBJECT DeviceObject, - IN USBD_PIPE_HANDLE PipeHandle - ); +Ezusb_AbortPipe(IN PDEVICE_OBJECT DeviceObject, IN USBD_PIPE_HANDLE PipeHandle); ULONG -Ezusb_GetCurrentFrameNumber( - IN PDEVICE_OBJECT DeviceObject - ); +Ezusb_GetCurrentFrameNumber(IN PDEVICE_OBJECT DeviceObject); NTSTATUS Ezusb_Read_Write_Direct( - IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp, - IN BOOLEAN Read - ); + IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN BOOLEAN Read); ULONG Ezusb_DownloadTest( - IN PDEVICE_OBJECT DeviceObject, - IN PVENDOR_REQUEST_IN pVendorRequest - ); + IN PDEVICE_OBJECT DeviceObject, IN PVENDOR_REQUEST_IN pVendorRequest); NTSTATUS -Ezusb_ResetParentPort( - IN IN PDEVICE_OBJECT DeviceObject - ); +Ezusb_ResetParentPort(IN IN PDEVICE_OBJECT DeviceObject); -VOID -Ezusb_Cleanup( - PDEVICE_OBJECT DeviceObject - ); +VOID Ezusb_Cleanup(PDEVICE_OBJECT DeviceObject); ULONG Ezusb_GetDescriptor( IN PDEVICE_OBJECT fdo, - PVOID DescriptorBuffer, - ULONG BufferLength, - UCHAR DescriptorType - ); + PVOID DescriptorBuffer, + ULONG BufferLength, + UCHAR DescriptorType); ULONG -Ezusb_GetDeviceDescriptor( - IN PDEVICE_OBJECT DeviceObject, - PVOID pvOutputBuffer - ); +Ezusb_GetDeviceDescriptor(IN PDEVICE_OBJECT DeviceObject, PVOID pvOutputBuffer); ULONG Ezusb_GetConfigDescriptor( - IN PDEVICE_OBJECT DeviceObject, - PVOID pvOutputBuffer, - ULONG ulngth - ); + IN PDEVICE_OBJECT DeviceObject, PVOID pvOutputBuffer, ULONG ulngth); ULONG Ezusb_VendorRequest( - IN PDEVICE_OBJECT DeviceObject, - PVENDOR_REQUEST_IN pVendorRequest - ); + IN PDEVICE_OBJECT DeviceObject, PVENDOR_REQUEST_IN pVendorRequest); ULONG Ezusb_GetCurrentConfig( - IN PDEVICE_OBJECT DeviceObject, - IN PVENDOR_REQUEST_IN pVendorRequest - ); + IN PDEVICE_OBJECT DeviceObject, IN PVENDOR_REQUEST_IN pVendorRequest); ULONG Ezusb_GetCurrentInterface( - IN PDEVICE_OBJECT DeviceObject, - IN PVENDOR_REQUEST_IN pVendorRequest - ); + IN PDEVICE_OBJECT DeviceObject, IN PVENDOR_REQUEST_IN pVendorRequest); PUSB_CONFIGURATION_DESCRIPTOR -GetConfigDescriptor( - IN PDEVICE_OBJECT DeviceObject - ); +GetConfigDescriptor(IN PDEVICE_OBJECT DeviceObject); NTSTATUS -ConfigureDevice( - IN PDEVICE_OBJECT DeviceObject - ); +ConfigureDevice(IN PDEVICE_OBJECT DeviceObject); NTSTATUS SetInterface( - IN PDEVICE_OBJECT DeviceObject, - IN UCHAR InterfaceNumber, - IN UCHAR AlternateSetting - ); + IN PDEVICE_OBJECT DeviceObject, + IN UCHAR InterfaceNumber, + IN UCHAR AlternateSetting); ULONG Ezusb_GetStringDescriptor( IN PDEVICE_OBJECT DeviceObject, - UCHAR Index, - USHORT LanguageId, - PVOID pvOutputBuffer, - ULONG ulLength - ); + UCHAR Index, + USHORT LanguageId, + PVOID pvOutputBuffer, + ULONG ulLength); NTSTATUS -Ezusb_VendorRequest2( - IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp - ); - +Ezusb_VendorRequest2(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); NTSTATUS -ForwardAndWait( - IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp - ); - +ForwardAndWait(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); NTSTATUS -Ezusb_DefaultPnpHandler( - IN PDEVICE_OBJECT fdo, - IN PIRP Irp - ); - +Ezusb_DefaultPnpHandler(IN PDEVICE_OBJECT fdo, IN PIRP Irp); NTSTATUS -Ezusb_DispatchPnp( - IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp - ); +Ezusb_DispatchPnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); NTSTATUS -Ezusb_DispatchPower( - IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp - ); +Ezusb_DispatchPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); NTSTATUS -Ezusb_HandleStartDevice( - IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp - ); +Ezusb_HandleStartDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); NTSTATUS -Ezusb_HandleRemoveDevice( - IN PDEVICE_OBJECT fdo, - IN PIRP Irp - ); +Ezusb_HandleRemoveDevice(IN PDEVICE_OBJECT fdo, IN PIRP Irp); NTSTATUS -OnRequestComplete( - IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp, - IN PKEVENT pev - ); +OnRequestComplete(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PKEVENT pev); NTSTATUS -CompleteRequest( - IN PIRP Irp, - IN NTSTATUS status, - IN ULONG info - ); +CompleteRequest(IN PIRP Irp, IN NTSTATUS status, IN ULONG info); -BOOLEAN LockDevice( - IN PDEVICE_OBJECT fdo - ); +BOOLEAN LockDevice(IN PDEVICE_OBJECT fdo); -void UnlockDevice( - PDEVICE_OBJECT fdo - ); +void UnlockDevice(PDEVICE_OBJECT fdo); +NTSTATUS +InitTransferObject(IN OUT PISO_STREAM_OBJECT streamObject, IN ULONG index); -NTSTATUS InitTransferObject( - IN OUT PISO_STREAM_OBJECT streamObject, - IN ULONG index - ); +NTSTATUS Ezusb_StartIsoTransfer(IN PDEVICE_OBJECT fdo, IN PIRP Irp); -NTSTATUS Ezusb_StartIsoTransfer( - IN PDEVICE_OBJECT fdo, - IN PIRP Irp - ); +NTSTATUS +IsoTransferComplete(IN PDEVICE_OBJECT fdo, IN PIRP Irp, IN PVOID Context); -NTSTATUS IsoTransferComplete( - IN PDEVICE_OBJECT fdo, - IN PIRP Irp, - IN PVOID Context - ); +NTSTATUS +Ezusb_AnchorDownload( + PDEVICE_OBJECT fdo, WORD offset, PUCHAR downloadBuffer, ULONG downloadSize); +NTSTATUS +Ezusb_DownloadIntelHex(PDEVICE_OBJECT fdo, PINTEL_HEX_RECORD hexRecord); -NTSTATUS Ezusb_AnchorDownload( - PDEVICE_OBJECT fdo, - WORD offset, - PUCHAR downloadBuffer, - ULONG downloadSize - ); +NTSTATUS Ezusb_8051Reset(PDEVICE_OBJECT fdo, UCHAR resetBit); -NTSTATUS Ezusb_DownloadIntelHex( - PDEVICE_OBJECT fdo, - PINTEL_HEX_RECORD hexRecord - ); +NTSTATUS Ezusb_StartIsoStream(IN PDEVICE_OBJECT fdo, IN PIRP Irp); -NTSTATUS Ezusb_8051Reset( - PDEVICE_OBJECT fdo, - UCHAR resetBit - ); - -NTSTATUS Ezusb_StartIsoStream( - IN PDEVICE_OBJECT fdo, - IN PIRP Irp - ); - -BOOLEAN IsFx2( - IN PDEVICE_OBJECT fdo - ); +BOOLEAN IsFx2(IN PDEVICE_OBJECT fdo); NTSTATUS Ezusb_SetFeature( - IN PDEVICE_OBJECT fdo, - IN PSET_FEATURE_CONTROL setFeatureControl - ); - -#endif //DRIVER section + IN PDEVICE_OBJECT fdo, IN PSET_FEATURE_CONTROL setFeatureControl); +#endif // DRIVER section /////////////////////////////////////////////////////// // @@ -913,104 +743,132 @@ NTSTATUS Ezusb_SetFeature( // of IOCTL index codes before you choose a base index number. // -#define Ezusb_IOCTL_INDEX 0x0800 +#define Ezusb_IOCTL_INDEX 0x0800 +#define IOCTL_Ezusb_GET_PIPE_INFO \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 0, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define IOCTL_Ezusb_GET_PIPE_INFO CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+0,\ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define IOCTL_Ezusb_GET_DEVICE_DESCRIPTOR \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 1, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define IOCTL_Ezusb_GET_DEVICE_DESCRIPTOR CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+1,\ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define IOCTL_Ezusb_GET_CONFIGURATION_DESCRIPTOR \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 2, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define IOCTL_Ezusb_GET_CONFIGURATION_DESCRIPTOR CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+2,\ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define IOCTL_Ezusb_BULK_OR_INTERRUPT_WRITE \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 3, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define IOCTL_Ezusb_BULK_OR_INTERRUPT_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+3,\ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define IOCTL_Ezusb_BULK_OR_INTERRUPT_READ \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 4, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define IOCTL_Ezusb_BULK_OR_INTERRUPT_READ CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+4,\ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define IOCTL_Ezusb_VENDOR_REQUEST \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 5, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define IOCTL_Ezusb_VENDOR_REQUEST CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+5,\ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define IOCTL_Ezusb_GET_CURRENT_CONFIG \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 6, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define IOCTL_Ezusb_GET_CURRENT_CONFIG CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+6,\ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define IOCTL_Ezusb_ANCHOR_DOWNLOAD \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 7, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define IOCTL_Ezusb_ANCHOR_DOWNLOAD CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+7,\ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define IOCTL_Ezusb_RESET \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 12, \ + METHOD_IN_DIRECT, \ + FILE_ANY_ACCESS) -#define IOCTL_Ezusb_RESET CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+12,\ - METHOD_IN_DIRECT, \ - FILE_ANY_ACCESS) +#define IOCTL_Ezusb_RESETPIPE \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 13, \ + METHOD_IN_DIRECT, \ + FILE_ANY_ACCESS) -#define IOCTL_Ezusb_RESETPIPE CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+13,\ - METHOD_IN_DIRECT, \ - FILE_ANY_ACCESS) +#define IOCTL_Ezusb_ABORTPIPE \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 15, \ + METHOD_IN_DIRECT, \ + FILE_ANY_ACCESS) -#define IOCTL_Ezusb_ABORTPIPE CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+15,\ - METHOD_IN_DIRECT, \ - FILE_ANY_ACCESS) - -#define IOCTL_Ezusb_SETINTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+16,\ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define IOCTL_Ezusb_GET_STRING_DESCRIPTOR CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+17,\ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define IOCTL_Ezusb_SETINTERFACE \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 16, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) +#define IOCTL_Ezusb_GET_STRING_DESCRIPTOR \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 17, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) // // Perform an IN transfer over the specified bulk or interrupt pipe. // -// lpInBuffer: BULK_TRANSFER_CONTROL stucture specifying the pipe number to read from -// nInBufferSize: sizeof(BULK_TRANSFER_CONTROL) -// lpOutBuffer: Buffer to hold data read from the device. -// nOutputBufferSize: size of lpOutBuffer. This parameter determines +// lpInBuffer: BULK_TRANSFER_CONTROL stucture specifying the pipe number to read +// from nInBufferSize: sizeof(BULK_TRANSFER_CONTROL) lpOutBuffer: Buffer to hold +// data read from the device. nOutputBufferSize: size of lpOutBuffer. This +// parameter determines // the size of the USB transfer. // lpBytesReturned: actual number of bytes read // -#define IOCTL_EZUSB_BULK_READ CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+19,\ - METHOD_OUT_DIRECT, \ - FILE_ANY_ACCESS) +#define IOCTL_EZUSB_BULK_READ \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 19, \ + METHOD_OUT_DIRECT, \ + FILE_ANY_ACCESS) // // Perform an OUT transfer over the specified bulk or interrupt pipe. // -// lpInBuffer: BULK_TRANSFER_CONTROL stucture specifying the pipe number to write to -// nInBufferSize: sizeof(BULK_TRANSFER_CONTROL) -// lpOutBuffer: Buffer of data to write to the device -// nOutputBufferSize: size of lpOutBuffer. This parameter determines +// lpInBuffer: BULK_TRANSFER_CONTROL stucture specifying the pipe number to +// write to nInBufferSize: sizeof(BULK_TRANSFER_CONTROL) lpOutBuffer: Buffer of +// data to write to the device nOutputBufferSize: size of lpOutBuffer. This +// parameter determines // the size of the USB transfer. // lpBytesReturned: actual number of bytes written // -#define IOCTL_EZUSB_BULK_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+20,\ - METHOD_IN_DIRECT, \ - FILE_ANY_ACCESS) +#define IOCTL_EZUSB_BULK_WRITE \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 20, \ + METHOD_IN_DIRECT, \ + FILE_ANY_ACCESS) // // The following IOCTL's are defined as using METHOD_DIRECT_IN buffering. @@ -1032,11 +890,12 @@ NTSTATUS Ezusb_SetFeature( // lpOutBuffer: PULONG to hold current frame number // nOutputBufferSize: sizeof(PULONG) // -#define IOCTL_EZUSB_GET_CURRENT_FRAME_NUMBER CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+21,\ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - +#define IOCTL_EZUSB_GET_CURRENT_FRAME_NUMBER \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 21, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) // // Performs a vendor or class specific control transfer to EP0. The contents of @@ -1049,10 +908,12 @@ NTSTATUS Ezusb_SetFeature( // nOutputBufferSize: size of the transfer buffer (corresponds to the wLength // field of the USB setup packet) // -#define IOCTL_EZUSB_VENDOR_OR_CLASS_REQUEST CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+22,\ - METHOD_IN_DIRECT, \ - FILE_ANY_ACCESS) +#define IOCTL_EZUSB_VENDOR_OR_CLASS_REQUEST \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 22, \ + METHOD_IN_DIRECT, \ + FILE_ANY_ACCESS) // // Retrieves the actual USBD_STATUS code for the most recently failed @@ -1064,10 +925,12 @@ NTSTATUS Ezusb_SetFeature( // nOutputBufferSize: sizeof(ULONG) // -#define IOCTL_EZUSB_GET_LAST_ERROR CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+23,\ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define IOCTL_EZUSB_GET_LAST_ERROR \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 23, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) // // Reads from the specified ISO endpoint. (USB IN Transfer) @@ -1080,10 +943,12 @@ NTSTATUS Ezusb_SetFeature( // // -#define IOCTL_EZUSB_ISO_READ CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+25,\ - METHOD_OUT_DIRECT, \ - FILE_ANY_ACCESS) +#define IOCTL_EZUSB_ISO_READ \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 25, \ + METHOD_OUT_DIRECT, \ + FILE_ANY_ACCESS) // // Writes to the specified ISO endpoint. (USB OUT Transfer) @@ -1096,10 +961,12 @@ NTSTATUS Ezusb_SetFeature( // // -#define IOCTL_EZUSB_ISO_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+26,\ - METHOD_IN_DIRECT, \ - FILE_ANY_ACCESS) +#define IOCTL_EZUSB_ISO_WRITE \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 26, \ + METHOD_IN_DIRECT, \ + FILE_ANY_ACCESS) // // Performs and Anchor Download. @@ -1109,10 +976,12 @@ NTSTATUS Ezusb_SetFeature( // lpOutBuffer: pointer to a buffer of data to download to the device // nOutputBufferSize: size of the transfer buffer // -#define IOCTL_EZUSB_ANCHOR_DOWNLOAD CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+27,\ - METHOD_IN_DIRECT, \ - FILE_ANY_ACCESS) +#define IOCTL_EZUSB_ANCHOR_DOWNLOAD \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 27, \ + METHOD_IN_DIRECT, \ + FILE_ANY_ACCESS) // // Returns driver version information @@ -1122,27 +991,37 @@ NTSTATUS Ezusb_SetFeature( // lpOutBuffer: PEZUSB_DRIVER_VERSION // nOutputBufferSize: sizeof(EZUSB_DRIVER_VERSION) // -#define IOCTL_EZUSB_GET_DRIVER_VERSION CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+29,\ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define IOCTL_EZUSB_GET_DRIVER_VERSION \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 29, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define IOCTL_EZUSB_START_ISO_STREAM CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+30,\ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define IOCTL_EZUSB_START_ISO_STREAM \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 30, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define IOCTL_EZUSB_STOP_ISO_STREAM CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+31,\ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define IOCTL_EZUSB_STOP_ISO_STREAM \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 31, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -#define IOCTL_EZUSB_READ_ISO_BUFFER CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+32,\ - METHOD_OUT_DIRECT, \ - FILE_ANY_ACCESS) +#define IOCTL_EZUSB_READ_ISO_BUFFER \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 32, \ + METHOD_OUT_DIRECT, \ + FILE_ANY_ACCESS) -#define IOCTL_EZUSB_SET_FEATURE CTL_CODE(FILE_DEVICE_UNKNOWN, \ - Ezusb_IOCTL_INDEX+33,\ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) +#define IOCTL_EZUSB_SET_FEATURE \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + Ezusb_IOCTL_INDEX + 33, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) diff --git a/src/main/ezusb/ezusbsys2.h b/src/main/ezusb/ezusbsys2.h index a209675..bcc88ff 100644 --- a/src/main/ezusb/ezusbsys2.h +++ b/src/main/ezusb/ezusbsys2.h @@ -1,9 +1,9 @@ #ifndef EZUSB_EZUSBSYS2_H #define EZUSB_EZUSBSYS2_H -#include #include #include +#include #include "ezusbsys.h" @@ -11,29 +11,28 @@ so we have to redefine these macros here */ #ifndef CTL_CODE -#define CTL_CODE( DeviceType, Function, Method, Access ) ( \ - ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \ -) +#define CTL_CODE(DeviceType, Function, Method, Access) \ + (((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method)) #endif #ifndef FILE_DEVICE_UNKNOWN -#define FILE_DEVICE_UNKNOWN 0x00000022 +#define FILE_DEVICE_UNKNOWN 0x00000022 #endif #ifndef METHOD_BUFFERED -#define METHOD_BUFFERED 0 +#define METHOD_BUFFERED 0 #endif #ifndef METHOD_IN_DIRECT -#define METHOD_IN_DIRECT 1 +#define METHOD_IN_DIRECT 1 #endif #ifndef METHOD_OUT_DIRECT -#define METHOD_OUT_DIRECT 2 +#define METHOD_OUT_DIRECT 2 #endif #ifndef FILE_ANY_ACCESS -#define FILE_ANY_ACCESS 0 +#define FILE_ANY_ACCESS 0 #endif #endif \ No newline at end of file diff --git a/src/main/ezusb/util.c b/src/main/ezusb/util.c index 478e84b..efc2cd1 100644 --- a/src/main/ezusb/util.c +++ b/src/main/ezusb/util.c @@ -3,16 +3,16 @@ #include "ezusb/util.h" -#include "util/log.h" #include "util/crc.h" #include "util/fs.h" +#include "util/log.h" #include "util/mem.h" -struct ezusb_firmware* ezusb_firmware_load(const char* file) +struct ezusb_firmware *ezusb_firmware_load(const char *file) { - void* buffer; + void *buffer; size_t buffer_size; - struct ezusb_firmware* fw; + struct ezusb_firmware *fw; size_t pos; log_assert(file); @@ -25,19 +25,19 @@ struct ezusb_firmware* ezusb_firmware_load(const char* file) fw = xmalloc(sizeof(struct ezusb_firmware)); - fw->crc = ((struct ezusb_firmware*) buffer)->crc; - fw->segment_count = ((struct ezusb_firmware*) buffer)->segment_count; + fw->crc = ((struct ezusb_firmware *) buffer)->crc; + fw->segment_count = ((struct ezusb_firmware *) buffer)->segment_count; pos += sizeof(uint16_t) * 2; - fw->segments = xmalloc( - sizeof(struct ezusb_firmware_segment) * fw->segment_count); + fw->segments = + xmalloc(sizeof(struct ezusb_firmware_segment) * fw->segment_count); for (uint16_t i = 0; i < fw->segment_count; i++) { - uint16_t size = *((uint16_t*) (buffer + pos)); + uint16_t size = *((uint16_t *) (buffer + pos)); pos += sizeof(uint16_t); - uint16_t offset = *((uint16_t*) (buffer + pos)); + uint16_t offset = *((uint16_t *) (buffer + pos)); pos += sizeof(uint16_t); fw->segments[i] = xmalloc(sizeof(uint16_t) * 2 + size); @@ -51,10 +51,10 @@ struct ezusb_firmware* ezusb_firmware_load(const char* file) return fw; } -bool ezusb_firmware_save(const char* file, struct ezusb_firmware* fw) +bool ezusb_firmware_save(const char *file, struct ezusb_firmware *fw) { size_t size; - void* buffer; + void *buffer; size_t pos; bool res; @@ -72,13 +72,15 @@ bool ezusb_firmware_save(const char* file, struct ezusb_firmware* fw) buffer = xmalloc(size); - ((struct ezusb_firmware*) buffer)->crc = fw->crc; - ((struct ezusb_firmware*) buffer)->segment_count = fw->segment_count; + ((struct ezusb_firmware *) buffer)->crc = fw->crc; + ((struct ezusb_firmware *) buffer)->segment_count = fw->segment_count; pos += sizeof(uint16_t) * 2; for (uint16_t i = 0; i < fw->segment_count; i++) { - memcpy(buffer + pos, fw->segments[i], + memcpy( + buffer + pos, + fw->segments[i], sizeof(uint16_t) * 2 + fw->segments[i]->size); pos += sizeof(uint16_t) * 2 + fw->segments[i]->size; } @@ -89,9 +91,9 @@ bool ezusb_firmware_save(const char* file, struct ezusb_firmware* fw) return res; } -struct ezusb_firmware* ezusb_firmware_alloc() +struct ezusb_firmware *ezusb_firmware_alloc() { - struct ezusb_firmware* fw; + struct ezusb_firmware *fw; fw = xmalloc(sizeof(struct ezusb_firmware)); @@ -102,10 +104,10 @@ struct ezusb_firmware* ezusb_firmware_alloc() return fw; } -struct ezusb_firmware_segment* ezusb_firmware_segment_alloc(uint16_t offset, - uint16_t size, void* data) +struct ezusb_firmware_segment * +ezusb_firmware_segment_alloc(uint16_t offset, uint16_t size, void *data) { - struct ezusb_firmware_segment* seg; + struct ezusb_firmware_segment *seg; log_assert(size > 0); log_assert(data); @@ -119,18 +121,19 @@ struct ezusb_firmware_segment* ezusb_firmware_segment_alloc(uint16_t offset, return seg; } -void ezusb_firmware_add_segment(struct ezusb_firmware* fw, - struct ezusb_firmware_segment* segment) +void ezusb_firmware_add_segment( + struct ezusb_firmware *fw, struct ezusb_firmware_segment *segment) { - struct ezusb_firmware_segment** tmp; + struct ezusb_firmware_segment **tmp; log_assert(fw); log_assert(segment); fw->segment_count++; - tmp = xrealloc(fw->segments, - sizeof(struct ezusb_firmware_segment*) * fw->segment_count); + tmp = xrealloc( + fw->segments, + sizeof(struct ezusb_firmware_segment *) * fw->segment_count); if (tmp != NULL) { fw->segments = tmp; @@ -139,7 +142,7 @@ void ezusb_firmware_add_segment(struct ezusb_firmware* fw, fw->segments[fw->segment_count - 1] = segment; } -uint16_t ezusb_firmware_crc(struct ezusb_firmware* fw) +uint16_t ezusb_firmware_crc(struct ezusb_firmware *fw) { uint16_t crc; @@ -148,14 +151,14 @@ uint16_t ezusb_firmware_crc(struct ezusb_firmware* fw) crc = 0; for (uint16_t i = 0; i < fw->segment_count; i++) { - crc = crc16(fw->segments[i], - sizeof(uint16_t) * 2 + fw->segments[i]->size, crc); + crc = crc16( + fw->segments[i], sizeof(uint16_t) * 2 + fw->segments[i]->size, crc); } return crc; } -void ezusb_firmware_free(struct ezusb_firmware* fw) +void ezusb_firmware_free(struct ezusb_firmware *fw) { log_assert(fw); diff --git a/src/main/ezusb/util.h b/src/main/ezusb/util.h index af15593..dfb69aa 100644 --- a/src/main/ezusb/util.h +++ b/src/main/ezusb/util.h @@ -1,7 +1,7 @@ /** * Utility module for ezusb1 (legacy) and ezusb2 (FX2) device handling. - * - * @author icex2 + * + * @author icex2 */ #ifndef EZUSB_UTIL_H #define EZUSB_UTIL_H @@ -33,69 +33,69 @@ struct ezusb_firmware_segment { struct ezusb_firmware { uint16_t crc; uint16_t segment_count; - struct ezusb_firmware_segment** segments; + struct ezusb_firmware_segment **segments; }; /** * Load a firmware binary file into memory. - * + * * @oaram file Path to firmware binary file. * @return Valid firmware structure on success, NULL on failure. */ -struct ezusb_firmware* ezusb_firmware_load(const char* file); +struct ezusb_firmware *ezusb_firmware_load(const char *file); /** * Save the in-memory firmware to a file. - * + * * @param file Target file to save to. * @param fw Valid firmware structure to store to disk. * @return True on success, false on error. */ -bool ezusb_firmware_save(const char* file, struct ezusb_firmware* fw); +bool ezusb_firmware_save(const char *file, struct ezusb_firmware *fw); /** * Allocate and initialize a new (empty = no segments) ezusb firmware structure. - * + * * @return Allocated and initialized structure. */ -struct ezusb_firmware* ezusb_firmware_alloc(); +struct ezusb_firmware *ezusb_firmware_alloc(); /** * Allocate and initialize a new firmware segment. - * + * * @param offset Offset of the segment. * @param size Size of the segment - * @param data Pointer to a buffer with firmware data of at least the + * @param data Pointer to a buffer with firmware data of at least the * specified size. * @return Allocated and initialized structure. */ -struct ezusb_firmware_segment* ezusb_firmware_segment_alloc(uint16_t offset, - uint16_t size, void* data); +struct ezusb_firmware_segment * +ezusb_firmware_segment_alloc(uint16_t offset, uint16_t size, void *data); /** * Add a segment to a firmware structure. - * + * * @param fw Valid firmware structure to add the segment to. * @param segment Valid segment to add to the end of the segment list of the - * firmware. + * firmware. */ -void ezusb_firmware_add_segment(struct ezusb_firmware* fw, - struct ezusb_firmware_segment* segment); +void ezusb_firmware_add_segment( + struct ezusb_firmware *fw, struct ezusb_firmware_segment *segment); /** * Calculate the checksum of the provided firmware. - * + * * @param fw Firmware to checksum. * @return CRC16 of firmware. */ -uint16_t ezusb_firmware_crc(struct ezusb_firmware* fw); +uint16_t ezusb_firmware_crc(struct ezusb_firmware *fw); /** - * Free a previously allocated firmware structure (also cleans up all + * Free a previously allocated firmware structure (also cleans up all * referenced segments). - * + * * @param fw Firmware struct to free. */ -void ezusb_firmware_free(struct ezusb_firmware* fw); +void ezusb_firmware_free(struct ezusb_firmware *fw); #endif \ No newline at end of file diff --git a/src/main/ezusb2-dbg-hook/main.c b/src/main/ezusb2-dbg-hook/main.c index 415381d..ef05efb 100644 --- a/src/main/ezusb2-dbg-hook/main.c +++ b/src/main/ezusb2-dbg-hook/main.c @@ -1,7 +1,7 @@ #define LOG_MODULE "ezusb2-dbg" -#include #include +#include #include #include @@ -17,115 +17,131 @@ #include "util/str.h" static HANDLE STDCALL my_CreateFileW( - const wchar_t *lpFileName, - uint32_t dwDesiredAccess, - uint32_t dwShareMode, - SECURITY_ATTRIBUTES *lpSecurityAttributes, - uint32_t dwCreationDisposition, - uint32_t dwFlagsAndAttributes, - HANDLE hTemplateFile); + const wchar_t *lpFileName, + uint32_t dwDesiredAccess, + uint32_t dwShareMode, + SECURITY_ATTRIBUTES *lpSecurityAttributes, + uint32_t dwCreationDisposition, + uint32_t dwFlagsAndAttributes, + HANDLE hTemplateFile); static HANDLE STDCALL my_CreateFileA( - const char *lpFileName, - uint32_t dwDesiredAccess, - uint32_t dwShareMode, - SECURITY_ATTRIBUTES *lpSecurityAttributes, - uint32_t dwCreationDisposition, - uint32_t dwFlagsAndAttributes, - HANDLE hTemplateFile); + const char *lpFileName, + uint32_t dwDesiredAccess, + uint32_t dwShareMode, + SECURITY_ATTRIBUTES *lpSecurityAttributes, + uint32_t dwCreationDisposition, + uint32_t dwFlagsAndAttributes, + HANDLE hTemplateFile); static BOOL STDCALL my_DeviceIoControl( - HANDLE hFile, - uint32_t dwIoControlCode, - void *lpInBuffer, - uint32_t nInBufferSize, - void *lpOutBuffer, - uint32_t nOutBufferSize, - uint32_t *lpBytesReturned, - OVERLAPPED *lpOverlapped); + HANDLE hFile, + uint32_t dwIoControlCode, + void *lpInBuffer, + uint32_t nInBufferSize, + void *lpOutBuffer, + uint32_t nOutBufferSize, + uint32_t *lpBytesReturned, + OVERLAPPED *lpOverlapped); static BOOL STDCALL my_CloseHandle(HANDLE fd); -static HANDLE (STDCALL *real_CreateFileW)( - const wchar_t *filename, - uint32_t access, - uint32_t share, - SECURITY_ATTRIBUTES *sa, - uint32_t creation, - uint32_t flags, - HANDLE tmpl); +static HANDLE(STDCALL *real_CreateFileW)( + const wchar_t *filename, + uint32_t access, + uint32_t share, + SECURITY_ATTRIBUTES *sa, + uint32_t creation, + uint32_t flags, + HANDLE tmpl); -static BOOL (STDCALL *real_DeviceIoControl)( - HANDLE fd, - uint32_t code, - void *in_bytes, - uint32_t in_nbytes, - void *out_bytes, - uint32_t out_nbytes, - uint32_t *out_returned, - OVERLAPPED *ovl); +static BOOL(STDCALL *real_DeviceIoControl)( + HANDLE fd, + uint32_t code, + void *in_bytes, + uint32_t in_nbytes, + void *out_bytes, + uint32_t out_nbytes, + uint32_t *out_returned, + OVERLAPPED *ovl); -static BOOL (STDCALL *real_CloseHandle)(HANDLE fd); +static BOOL(STDCALL *real_CloseHandle)(HANDLE fd); static struct hook_symbol ezusb2_dbg_hook_syms[] = { { - .name = "CreateFileA", - .patch = my_CreateFileA, + .name = "CreateFileA", + .patch = my_CreateFileA, }, { - .name = "CreateFileW", - .patch = my_CreateFileW, - .link = (void *) &real_CreateFileW, + .name = "CreateFileW", + .patch = my_CreateFileW, + .link = (void *) &real_CreateFileW, }, + {.name = "DeviceIoControl", + .patch = my_DeviceIoControl, + .link = (void *) &real_DeviceIoControl}, { - .name = "DeviceIoControl", - .patch = my_DeviceIoControl, - .link = (void *) &real_DeviceIoControl - }, - { - .name = "CloseHandle", - .patch = my_CloseHandle, - .link = (void *) &real_CloseHandle, + .name = "CloseHandle", + .patch = my_CloseHandle, + .link = (void *) &real_CloseHandle, }, }; -typedef void (*ezusb2_dbg_hook_handle_ioctl_t)(BOOL* result, HANDLE hFile, - uint32_t dwIoControlCode, - void *lpInBuffer, - uint32_t nInBufferSize, - void *lpOutBuffer, - uint32_t nOutBufferSize, - uint32_t *lpBytesReturned, - OVERLAPPED *lpOverlapped); +typedef void (*ezusb2_dbg_hook_handle_ioctl_t)( + BOOL *result, + HANDLE hFile, + uint32_t dwIoControlCode, + void *lpInBuffer, + uint32_t nInBufferSize, + void *lpOutBuffer, + uint32_t nOutBufferSize, + uint32_t *lpBytesReturned, + OVERLAPPED *lpOverlapped); static wchar_t ezusb2_dbg_hook_path[MAX_PATH]; static HANDLE ezusb2_dbg_hook_handle = INVALID_HANDLE_VALUE; static ezusb2_dbg_hook_handle_ioctl_t ezusb2_dbg_hook_ioctl_handler; -static void ezusb2_dbg_hook_handle_ioctl_legacy(BOOL* result, HANDLE hFile, - uint32_t dwIoControlCode, void *lpInBuffer, uint32_t nInBufferSize, - void *lpOutBuffer, uint32_t nOutBufferSize, uint32_t *lpBytesReturned, - OVERLAPPED *lpOverlapped) +static void ezusb2_dbg_hook_handle_ioctl_legacy( + BOOL *result, + HANDLE hFile, + uint32_t dwIoControlCode, + void *lpInBuffer, + uint32_t nInBufferSize, + void *lpOutBuffer, + uint32_t nOutBufferSize, + uint32_t *lpBytesReturned, + OVERLAPPED *lpOverlapped) { log_warning("TODO NOT IMPLEMENTED"); } -static void ezusb2_dbg_hook_handle_ioctl_fx2(BOOL* result, HANDLE hFile, - uint32_t dwIoControlCode, void *lpInBuffer, uint32_t nInBufferSize, - void *lpOutBuffer, uint32_t nOutBufferSize, uint32_t *lpBytesReturned, - OVERLAPPED *lpOverlapped) +static void ezusb2_dbg_hook_handle_ioctl_fx2( + BOOL *result, + HANDLE hFile, + uint32_t dwIoControlCode, + void *lpInBuffer, + uint32_t nInBufferSize, + void *lpOutBuffer, + uint32_t nOutBufferSize, + uint32_t *lpBytesReturned, + OVERLAPPED *lpOverlapped) { char data_in[8192]; char data_out[8192]; if (nInBufferSize < sizeof(SINGLE_TRANSFER)) { - log_warning("In buffer size, ioctl_code 0x%X too small: %d", - dwIoControlCode, nInBufferSize); + log_warning( + "In buffer size, ioctl_code 0x%X too small: %d", + dwIoControlCode, + nInBufferSize); } if (nOutBufferSize < sizeof(SINGLE_TRANSFER)) { - log_warning("Out buffer size, ioctl_code 0x%X too small: %d", - dwIoControlCode, nOutBufferSize); + log_warning( + "Out buffer size, ioctl_code 0x%X too small: %d", + dwIoControlCode, + nOutBufferSize); } PSINGLE_TRANSFER trans_in = (PSINGLE_TRANSFER) lpInBuffer; @@ -134,12 +150,19 @@ static void ezusb2_dbg_hook_handle_ioctl_fx2(BOOL* result, HANDLE hFile, memset(data_in, 0, sizeof(data_in)); memset(data_out, 0, sizeof(data_out)); - hex_encode_uc(lpInBuffer + trans_in->BufferOffset, trans_in->BufferLength, - data_in, sizeof(data_in)); - hex_encode_uc(lpOutBuffer + trans_out->BufferOffset, - trans_out->BufferLength, data_out, sizeof(data_out)); + hex_encode_uc( + lpInBuffer + trans_in->BufferOffset, + trans_in->BufferLength, + data_in, + sizeof(data_in)); + hex_encode_uc( + lpOutBuffer + trans_out->BufferOffset, + trans_out->BufferLength, + data_out, + sizeof(data_out)); - log_info("[ioctl][res %d, bytes returned %d, overlapped %d][ctrl_code 0x%X]" + log_info( + "[ioctl][res %d, bytes returned %d, overlapped %d][ctrl_code 0x%X]" "[IN][bmRequest 0x%X, bRequest 0x%X, wValue 0x%X, wIndex 0x%X, " "wLength %d, ulTimeOut %ld][reserved 0x%X, ucEndpointAddress 0x%X, " "NtStatus 0x%lX, UsbdStatus 0x%lX, IsoPacketOffset %ld, " @@ -147,33 +170,51 @@ static void ezusb2_dbg_hook_handle_ioctl_fx2(BOOL* result, HANDLE hFile, "[OUT][bmRequest 0x%X, bRequest 0x%X, wValue 0x%X, wIndex 0x%X, " "wLength %d, ulTimeOut %ld][reserved 0x%X, ucEndpointAddress 0x%X, " "NtStatus 0x%lX, UsbdStatus 0x%lX, IsoPacketOffset %ld, " - "IsoPacketLength %ld, BufferOffset %ld, BufferLength %ld][%s]", - result ? *result : -1, result ? *lpBytesReturned : -1, - lpOverlapped ? 1 : 0, dwIoControlCode, - trans_in->SetupPacket.bmRequest, trans_in->SetupPacket.bRequest, - trans_in->SetupPacket.wValue, trans_in->SetupPacket.wIndex, - trans_in->SetupPacket.wLength, trans_in->SetupPacket.ulTimeOut, - trans_in->reserved, trans_in->ucEndpointAddress, trans_in->NtStatus, - trans_in->UsbdStatus, trans_in->IsoPacketOffset, - trans_in->IsoPacketLength, trans_in->BufferOffset, - trans_in->BufferLength, data_in, - trans_out->SetupPacket.bmRequest, trans_out->SetupPacket.bRequest, - trans_out->SetupPacket.wValue, trans_out->SetupPacket.wIndex, - trans_out->SetupPacket.wLength, trans_out->SetupPacket.ulTimeOut, - trans_out->reserved, trans_out->ucEndpointAddress, trans_out->NtStatus, - trans_out->UsbdStatus, trans_out->IsoPacketOffset, - trans_out->IsoPacketLength, trans_out->BufferOffset, - trans_out->BufferLength, data_out); + "IsoPacketLength %ld, BufferOffset %ld, BufferLength %ld][%s]", + result ? *result : -1, + result ? *lpBytesReturned : -1, + lpOverlapped ? 1 : 0, + dwIoControlCode, + trans_in->SetupPacket.bmRequest, + trans_in->SetupPacket.bRequest, + trans_in->SetupPacket.wValue, + trans_in->SetupPacket.wIndex, + trans_in->SetupPacket.wLength, + trans_in->SetupPacket.ulTimeOut, + trans_in->reserved, + trans_in->ucEndpointAddress, + trans_in->NtStatus, + trans_in->UsbdStatus, + trans_in->IsoPacketOffset, + trans_in->IsoPacketLength, + trans_in->BufferOffset, + trans_in->BufferLength, + data_in, + trans_out->SetupPacket.bmRequest, + trans_out->SetupPacket.bRequest, + trans_out->SetupPacket.wValue, + trans_out->SetupPacket.wIndex, + trans_out->SetupPacket.wLength, + trans_out->SetupPacket.ulTimeOut, + trans_out->reserved, + trans_out->ucEndpointAddress, + trans_out->NtStatus, + trans_out->UsbdStatus, + trans_out->IsoPacketOffset, + trans_out->IsoPacketLength, + trans_out->BufferOffset, + trans_out->BufferLength, + data_out); } static HANDLE STDCALL my_CreateFileA( - const char *lpFileName, - uint32_t dwDesiredAccess, - uint32_t dwShareMode, - SECURITY_ATTRIBUTES *lpSecurityAttributes, - uint32_t dwCreationDisposition, - uint32_t dwFlagsAndAttributes, - HANDLE hTemplateFile) + const char *lpFileName, + uint32_t dwDesiredAccess, + uint32_t dwShareMode, + SECURITY_ATTRIBUTES *lpSecurityAttributes, + uint32_t dwCreationDisposition, + uint32_t dwFlagsAndAttributes, + HANDLE hTemplateFile) { wchar_t *wfilename; HANDLE fd; @@ -187,27 +228,28 @@ static HANDLE STDCALL my_CreateFileA( wfilename = str_widen(lpFileName); fd = my_CreateFileW( - wfilename, - dwDesiredAccess, - dwShareMode, - lpSecurityAttributes, - dwCreationDisposition, dwFlagsAndAttributes, - hTemplateFile); + wfilename, + dwDesiredAccess, + dwShareMode, + lpSecurityAttributes, + dwCreationDisposition, + dwFlagsAndAttributes, + hTemplateFile); free(wfilename); return fd; } static HANDLE STDCALL my_CreateFileW( - const wchar_t *lpFileName, - uint32_t dwDesiredAccess, - uint32_t dwShareMode, - SECURITY_ATTRIBUTES *lpSecurityAttributes, - uint32_t dwCreationDisposition, - uint32_t dwFlagsAndAttributes, - HANDLE hTemplateFile) + const wchar_t *lpFileName, + uint32_t dwDesiredAccess, + uint32_t dwShareMode, + SECURITY_ATTRIBUTES *lpSecurityAttributes, + uint32_t dwCreationDisposition, + uint32_t dwFlagsAndAttributes, + HANDLE hTemplateFile) { - char* file_name; + char *file_name; HANDLE handle; if (lpFileName == NULL) { @@ -224,8 +266,13 @@ static HANDLE STDCALL my_CreateFileW( log_misc("Opening: %s", file_name); } - handle = real_CreateFileW(lpFileName, dwDesiredAccess, dwShareMode, - lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, + handle = real_CreateFileW( + lpFileName, + dwDesiredAccess, + dwShareMode, + lpSecurityAttributes, + dwCreationDisposition, + dwFlagsAndAttributes, hTemplateFile); if (!wcscmp(lpFileName, ezusb2_dbg_hook_path)) { @@ -242,32 +289,52 @@ static HANDLE STDCALL my_CreateFileW( } static BOOL STDCALL my_DeviceIoControl( - HANDLE hFile, - uint32_t dwIoControlCode, - void *lpInBuffer, - uint32_t nInBufferSize, - void *lpOutBuffer, - uint32_t nOutBufferSize, - uint32_t *lpBytesReturned, - OVERLAPPED *lpOverlapped) + HANDLE hFile, + uint32_t dwIoControlCode, + void *lpInBuffer, + uint32_t nInBufferSize, + void *lpOutBuffer, + uint32_t nOutBufferSize, + uint32_t *lpBytesReturned, + OVERLAPPED *lpOverlapped) { BOOL res; - if (ezusb2_dbg_hook_handle != INVALID_HANDLE_VALUE && - hFile == ezusb2_dbg_hook_handle) { - ezusb2_dbg_hook_ioctl_handler(NULL, hFile, dwIoControlCode, lpInBuffer, - nInBufferSize, lpOutBuffer, nOutBufferSize, lpBytesReturned, + if (ezusb2_dbg_hook_handle != INVALID_HANDLE_VALUE && + hFile == ezusb2_dbg_hook_handle) { + ezusb2_dbg_hook_ioctl_handler( + NULL, + hFile, + dwIoControlCode, + lpInBuffer, + nInBufferSize, + lpOutBuffer, + nOutBufferSize, + lpBytesReturned, lpOverlapped); } - res = real_DeviceIoControl(hFile, dwIoControlCode, lpInBuffer, - nInBufferSize, lpOutBuffer, nOutBufferSize, lpBytesReturned, + res = real_DeviceIoControl( + hFile, + dwIoControlCode, + lpInBuffer, + nInBufferSize, + lpOutBuffer, + nOutBufferSize, + lpBytesReturned, lpOverlapped); - if (ezusb2_dbg_hook_handle != INVALID_HANDLE_VALUE && - hFile == ezusb2_dbg_hook_handle) { - ezusb2_dbg_hook_ioctl_handler(&res, hFile, dwIoControlCode, lpInBuffer, - nInBufferSize, lpOutBuffer, nOutBufferSize, lpBytesReturned, + if (ezusb2_dbg_hook_handle != INVALID_HANDLE_VALUE && + hFile == ezusb2_dbg_hook_handle) { + ezusb2_dbg_hook_ioctl_handler( + &res, + hFile, + dwIoControlCode, + lpInBuffer, + nInBufferSize, + lpOutBuffer, + nOutBufferSize, + lpBytesReturned, lpOverlapped); } @@ -289,34 +356,33 @@ static void ezusb2_dbg_hook_terminate_process() /* Don't use ExitProcess. This might result in deadlocks on newer games which rely more on multi threading */ HANDLE hnd; - hnd = OpenProcess(SYNCHRONIZE | PROCESS_TERMINATE, TRUE, - GetCurrentProcessId()); + hnd = OpenProcess( + SYNCHRONIZE | PROCESS_TERMINATE, TRUE, GetCurrentProcessId()); TerminateProcess(hnd, 0); } BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { - FILE* file; + FILE *file; int argc; char **argv; - wchar_t* buffer; + wchar_t *buffer; uint32_t args_success; file = fopen("ezusb2_dbg.log", "w+"); log_to_writer(log_writer_file, file); hook_table_apply( - NULL, - "kernel32.dll", - ezusb2_dbg_hook_syms, - lengthof(ezusb2_dbg_hook_syms)); + NULL, + "kernel32.dll", + ezusb2_dbg_hook_syms, + lengthof(ezusb2_dbg_hook_syms)); if (real_CreateFileW == NULL) { /* my_CreateFileA requires this to be present */ real_CreateFileW = (void *) GetProcAddress( - GetModuleHandleA("kernel32.dll"), - "CreateFileW"); + GetModuleHandleA("kernel32.dll"), "CreateFileW"); } args_recover(&argc, &argv); @@ -344,11 +410,11 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) switch (type) { case 1: - ezusb2_dbg_hook_ioctl_handler = + ezusb2_dbg_hook_ioctl_handler = ezusb2_dbg_hook_handle_ioctl_legacy; break; case 2: - ezusb2_dbg_hook_ioctl_handler = + ezusb2_dbg_hook_ioctl_handler = ezusb2_dbg_hook_handle_ioctl_fx2; break; default: diff --git a/src/main/ezusb2-emu/desc.c b/src/main/ezusb2-emu/desc.c index 1a1ad43..68b0916 100644 --- a/src/main/ezusb2-emu/desc.c +++ b/src/main/ezusb2-emu/desc.c @@ -1,16 +1,13 @@ #include "ezusb2-emu/desc.h" const struct ezusb_emu_desc_device ezusb2_emu_desc_device = { - .setupapi = { - .device_guid = { - 0xAE18AA60, - 0x7F6A, - 0x11D4, - { 0x97, 0xDD, 0x00, 0x01, 0x02, 0x29, 0xB9, 0x59 } - }, - .device_desc = "Cypress EZ-USB FX2LP - EEPROM missing", - .device_path = "\\\\.\\Ezusb-0" - }, + .setupapi = + {.device_guid = {0xAE18AA60, + 0x7F6A, + 0x11D4, + {0x97, 0xDD, 0x00, 0x01, 0x02, 0x29, 0xB9, 0x59}}, + .device_desc = "Cypress EZ-USB FX2LP - EEPROM missing", + .device_path = "\\\\.\\Ezusb-0"}, .vid = 0x04B4, .pid = 0x8613, }; \ No newline at end of file diff --git a/src/main/ezusb2-emu/device.c b/src/main/ezusb2-emu/device.c index 6d38f0f..9c40c37 100644 --- a/src/main/ezusb2-emu/device.c +++ b/src/main/ezusb2-emu/device.c @@ -1,8 +1,8 @@ #define LOG_MODULE "ezusb2-emu-device" -#include #include #include +#include #include @@ -46,14 +46,10 @@ static HRESULT ezusb_open(struct irp *irp); static HRESULT ezusb_ioctl(struct irp *irp); static HRESULT ezusb_ioctl_ep0( - SINGLE_TRANSFER *usb_req, - struct const_iobuf *write, - struct iobuf *read); + SINGLE_TRANSFER *usb_req, struct const_iobuf *write, struct iobuf *read); static HRESULT ezusb_ioctl_epX( - SINGLE_TRANSFER *usb_req, - struct const_iobuf *write, - struct iobuf *read); + SINGLE_TRANSFER *usb_req, struct const_iobuf *write, struct iobuf *read); static HRESULT ezusb_get_device_descriptor(struct iobuf *read); static HRESULT ezusb_get_string_descriptor(struct iobuf *read); @@ -61,10 +57,10 @@ static HRESULT ezusb_reset(struct const_iobuf *write); static HRESULT ezusb_upload_fw(uint16_t offset, struct const_iobuf *write); static HANDLE ezusb_fd; -static struct ezusb_firmware* ezusb_emu_firmware; -static struct ezusb_emu_msg_hook* ezusb_emu_dev_fx2_msg_hook; +static struct ezusb_firmware *ezusb_emu_firmware; +static struct ezusb_emu_msg_hook *ezusb_emu_dev_fx2_msg_hook; -void ezusb2_emu_device_hook_init(struct ezusb_emu_msg_hook* msg_hook) +void ezusb2_emu_device_hook_init(struct ezusb_emu_msg_hook *msg_hook) { log_assert(ezusb_fd == NULL); @@ -85,7 +81,8 @@ void ezusb2_emu_device_hook_fini(void) * WIN32 I/O AND IOHOOK LAYER */ -HRESULT ezusb2_emu_device_dispatch_irp(struct irp *irp) +HRESULT +ezusb2_emu_device_dispatch_irp(struct irp *irp) { if (irp->op != IRP_OP_OPEN && irp->fd != ezusb_fd) { return irp_invoke_next(irp); @@ -96,10 +93,14 @@ HRESULT ezusb2_emu_device_dispatch_irp(struct irp *irp) CloseHandle calls and don't even log them). */ switch (irp->op) { - case IRP_OP_OPEN: return ezusb_open(irp); - case IRP_OP_CLOSE: return S_OK; - case IRP_OP_IOCTL: return ezusb_ioctl(irp); - default: return E_NOTIMPL; + case IRP_OP_OPEN: + return ezusb_open(irp); + case IRP_OP_CLOSE: + return S_OK; + case IRP_OP_IOCTL: + return ezusb_ioctl(irp); + default: + return E_NOTIMPL; } } @@ -154,21 +155,21 @@ static HRESULT ezusb_ioctl(struct irp *irp) usb_req = (SINGLE_TRANSFER *) irp->write.bytes; switch (irp->ioctl) { - case IOCTL_ADAPT_SEND_EP0_CONTROL_TRANSFER: - hr = ezusb_ioctl_ep0(usb_req, &write, &read); + case IOCTL_ADAPT_SEND_EP0_CONTROL_TRANSFER: + hr = ezusb_ioctl_ep0(usb_req, &write, &read); - break; + break; - case IOCTL_ADAPT_SEND_NON_EP0_TRANSFER: - hr = ezusb_ioctl_epX(usb_req, &write, &read); + case IOCTL_ADAPT_SEND_NON_EP0_TRANSFER: + hr = ezusb_ioctl_epX(usb_req, &write, &read); - break; + break; - default: - log_warning("Unknown ioctl %08x", irp->ioctl); - hr = E_INVALIDARG; + default: + log_warning("Unknown ioctl %08x", irp->ioctl); + hr = E_INVALIDARG; - break; + break; } if (FAILED(hr)) { @@ -190,9 +191,7 @@ static HRESULT ezusb_ioctl(struct irp *irp) */ static HRESULT ezusb_ioctl_ep0( - SINGLE_TRANSFER *usb_req, - struct const_iobuf *write, - struct iobuf *read) + SINGLE_TRANSFER *usb_req, struct const_iobuf *write, struct iobuf *read) { log_assert(usb_req != NULL); log_assert(write != NULL); @@ -203,28 +202,28 @@ static HRESULT ezusb_ioctl_ep0( 0x40: Host -> Device Request, Class, Recipient Device */ - if ( usb_req->SetupPacket.bmRequest == 0x80 && - usb_req->SetupPacket.bRequest == 0x06) { + if (usb_req->SetupPacket.bmRequest == 0x80 && + usb_req->SetupPacket.bRequest == 0x06) { switch (usb_req->SetupPacket.wValue) { - /* Get usb device descriptor */ - case 0x0100: - /* return data with USB_DEVICE_DESCRIPTOR struct */ - return ezusb_get_device_descriptor(read); + /* Get usb device descriptor */ + case 0x0100: + /* return data with USB_DEVICE_DESCRIPTOR struct */ + return ezusb_get_device_descriptor(read); - /* get usb string descriptor */ - case 0x0301: - return ezusb_get_string_descriptor(read); + /* get usb string descriptor */ + case 0x0301: + return ezusb_get_string_descriptor(read); - default: - log_warning( + default: + log_warning( "Unsupported standard req (dev->host) value: %04X", usb_req->SetupPacket.wValue); - return E_INVALIDARG; + return E_INVALIDARG; } } else if ( - usb_req->SetupPacket.bmRequest == 0x40 && - usb_req->SetupPacket.bRequest == 0xA0) { + usb_req->SetupPacket.bmRequest == 0x40 && + usb_req->SetupPacket.bRequest == 0xA0) { if (usb_req->SetupPacket.wValue == 0xE600) { /* reset */ return ezusb_reset(write); @@ -234,18 +233,16 @@ static HRESULT ezusb_ioctl_ep0( } } else { log_warning( - "Invalid standard req_type and/or request: %02X %02X", - usb_req->SetupPacket.bmRequest, - usb_req->SetupPacket.bRequest); + "Invalid standard req_type and/or request: %02X %02X", + usb_req->SetupPacket.bmRequest, + usb_req->SetupPacket.bRequest); return E_INVALIDARG; } } static HRESULT ezusb_ioctl_epX( - SINGLE_TRANSFER *usb_req, - struct const_iobuf *write, - struct iobuf *read) + SINGLE_TRANSFER *usb_req, struct const_iobuf *write, struct iobuf *read) { log_assert(usb_req != NULL); log_assert(write != NULL); @@ -253,22 +250,22 @@ static HRESULT ezusb_ioctl_epX( /* No reason to follow a standard, right? */ switch (usb_req->ucEndpointAddress) { - case PIPE_INT_OUT: - return ezusb_emu_dev_fx2_msg_hook->interrupt_write(write); + case PIPE_INT_OUT: + return ezusb_emu_dev_fx2_msg_hook->interrupt_write(write); - case PIPE_BULK_OUT: - return ezusb_emu_dev_fx2_msg_hook->bulk_write(write); + case PIPE_BULK_OUT: + return ezusb_emu_dev_fx2_msg_hook->bulk_write(write); - case PIPE_INT_IN: - return ezusb_emu_dev_fx2_msg_hook->interrupt_read(read); + case PIPE_INT_IN: + return ezusb_emu_dev_fx2_msg_hook->interrupt_read(read); - case PIPE_BULK_IN: - return ezusb_emu_dev_fx2_msg_hook->bulk_read(read); + case PIPE_BULK_IN: + return ezusb_emu_dev_fx2_msg_hook->bulk_read(read); - default: - log_warning("Unhandled endpoint %02X", usb_req->ucEndpointAddress); + default: + log_warning("Unhandled endpoint %02X", usb_req->ucEndpointAddress); - return E_INVALIDARG; + return E_INVALIDARG; } } @@ -291,9 +288,9 @@ static HRESULT ezusb_get_device_descriptor(struct iobuf *read) desc->idProduct = ezusb2_emu_desc_device.pid; log_misc( - "get_device_descriptor: vid %02x, pid %02x", - desc->idVendor, - desc->idProduct); + "get_device_descriptor: vid %02x, pid %02x", + desc->idVendor, + desc->idProduct); read->pos = sizeof(*desc); @@ -330,34 +327,34 @@ static HRESULT ezusb_reset(struct const_iobuf *write) log_assert(write != NULL); switch (write->bytes[0]) { - case 0x01: - log_misc("reset hold, starting fw download..."); - ezusb_emu_firmware = ezusb_firmware_alloc(); + case 0x01: + log_misc("reset hold, starting fw download..."); + ezusb_emu_firmware = ezusb_firmware_alloc(); - return S_OK; + return S_OK; - case 0x00: - log_misc("reset release, finished fw download"); + case 0x00: + log_misc("reset release, finished fw download"); - ezusb_emu_firmware->crc = ezusb_firmware_crc(ezusb_emu_firmware); + ezusb_emu_firmware->crc = ezusb_firmware_crc(ezusb_emu_firmware); #ifdef EZUSB_EMU_FW_DUMP - if (!ezusb_firmware_save("ezusb_fx2.bin", ezusb_emu_firmware)) { - log_fatal("Saving dumped firmware failed"); - } else { - log_misc("firmware dumped do ezusb_fx2.bin file"); - } + if (!ezusb_firmware_save("ezusb_fx2.bin", ezusb_emu_firmware)) { + log_fatal("Saving dumped firmware failed"); + } else { + log_misc("firmware dumped do ezusb_fx2.bin file"); + } - free(ezusb_emu_firmware); - ezusb_emu_firmware = NULL; + free(ezusb_emu_firmware); + ezusb_emu_firmware = NULL; #endif - return S_OK; + return S_OK; - default: - log_warning("Unknown reset cmd: %02X", write->bytes[0]); + default: + log_warning("Unknown reset cmd: %02X", write->bytes[0]); - return E_FAIL; + return E_FAIL; } } @@ -365,10 +362,10 @@ static HRESULT ezusb_upload_fw(uint16_t offset, struct const_iobuf *write) { log_misc("upload_fw, offset %04X, nbytes %04X", offset, write->nbytes); - ezusb_firmware_add_segment(ezusb_emu_firmware, - ezusb_firmware_segment_alloc(offset, write->nbytes, - (void*) write->bytes)); + ezusb_firmware_add_segment( + ezusb_emu_firmware, + ezusb_firmware_segment_alloc( + offset, write->nbytes, (void *) write->bytes)); return S_OK; } - diff --git a/src/main/ezusb2-emu/device.h b/src/main/ezusb2-emu/device.h index 3cacdd1..d0685c6 100644 --- a/src/main/ezusb2-emu/device.h +++ b/src/main/ezusb2-emu/device.h @@ -3,8 +3,8 @@ #include -#include #include +#include #include "ezusb-emu/msg.h" @@ -13,11 +13,11 @@ /** * Hook IO functions to intercept with EZUSB FX2 (IIDX/Pop'n IO2) communication * and detour to our emulation code. - * - * @param msg_hook Hook functions to dispatch ezusb interrupt and bulk device + * + * @param msg_hook Hook functions to dispatch ezusb interrupt and bulk device * messages to */ -void ezusb2_emu_device_hook_init(struct ezusb_emu_msg_hook* msg_hook); +void ezusb2_emu_device_hook_init(struct ezusb_emu_msg_hook *msg_hook); /** * Cleanup the hooked IO functions. diff --git a/src/main/ezusb2-emu/util.c b/src/main/ezusb2-emu/util.c index 3bb54d1..2abd513 100644 --- a/src/main/ezusb2-emu/util.c +++ b/src/main/ezusb2-emu/util.c @@ -2,8 +2,8 @@ #include -#include #include +#include #include #include "ezusb2/cyioctl.h" @@ -14,10 +14,10 @@ #include "util/hex.h" #include "util/log.h" -void ezusb2_emu_util_log_usb_msg(const char* prefix, const struct irp *irp) +void ezusb2_emu_util_log_usb_msg(const char *prefix, const struct irp *irp) { SINGLE_TRANSFER *usb_req; - const char* ctl_code_str; + const char *ctl_code_str; char setup_packet_str[4096]; char single_transfer_str[4096]; char read_data_str[4096]; @@ -40,27 +40,53 @@ void ezusb2_emu_util_log_usb_msg(const char* prefix, const struct irp *irp) usb_req = (SINGLE_TRANSFER *) irp->write.bytes; - sprintf(setup_packet_str, "bmRequest 0x%X, bRequest 0x%X, wValue 0x%X, " - "wIndex 0x%X, wLength %d, ulTimeOut %ld", - usb_req->SetupPacket.bmRequest, usb_req->SetupPacket.bRequest, - usb_req->SetupPacket.wValue, usb_req->SetupPacket.wIndex, - usb_req->SetupPacket.wLength, usb_req->SetupPacket.ulTimeOut); + sprintf( + setup_packet_str, + "bmRequest 0x%X, bRequest 0x%X, wValue 0x%X, " + "wIndex 0x%X, wLength %d, ulTimeOut %ld", + usb_req->SetupPacket.bmRequest, + usb_req->SetupPacket.bRequest, + usb_req->SetupPacket.wValue, + usb_req->SetupPacket.wIndex, + usb_req->SetupPacket.wLength, + usb_req->SetupPacket.ulTimeOut); - sprintf(single_transfer_str, "reserverd 0x%X, ucEndpointAddress 0x%X, " + sprintf( + single_transfer_str, + "reserverd 0x%X, ucEndpointAddress 0x%X, " "NtStatus 0x%lX, UsbdStatus 0x%lX, IsoPacketOffset %ld, " "IsoPacketLength %ld, BufferOffset %ld, BufferLength %ld", - usb_req->reserved, usb_req->ucEndpointAddress, usb_req->NtStatus, - usb_req->UsbdStatus, usb_req->IsoPacketOffset, usb_req->IsoPacketLength, - usb_req->BufferOffset, usb_req->BufferLength); + usb_req->reserved, + usb_req->ucEndpointAddress, + usb_req->NtStatus, + usb_req->UsbdStatus, + usb_req->IsoPacketOffset, + usb_req->IsoPacketLength, + usb_req->BufferOffset, + usb_req->BufferLength); - hex_encode_uc(irp->read.bytes, irp->read.nbytes, read_data_str, + hex_encode_uc( + irp->read.bytes, + irp->read.nbytes, + read_data_str, sizeof(read_data_str)); - hex_encode_uc(irp->write.bytes, irp->write.nbytes, write_data_str, + hex_encode_uc( + irp->write.bytes, + irp->write.nbytes, + write_data_str, sizeof(write_data_str)); - log_warning("[EZUSB DUMP %s][%s] ctl_code 0x%X, in_len %d, out_len %d ||| " + log_warning( + "[EZUSB DUMP %s][%s] ctl_code 0x%X, in_len %d, out_len %d ||| " "setup packet: %s ||| single transfer: %s ||| read data: %s ||| " - "write data: %s", prefix, ctl_code_str, irp->ioctl, irp->read.nbytes, - irp->write.nbytes, setup_packet_str, single_transfer_str, read_data_str, + "write data: %s", + prefix, + ctl_code_str, + irp->ioctl, + irp->read.nbytes, + irp->write.nbytes, + setup_packet_str, + single_transfer_str, + read_data_str, write_data_str); } \ No newline at end of file diff --git a/src/main/ezusb2-emu/util.h b/src/main/ezusb2-emu/util.h index 3a24a7b..02a5798 100644 --- a/src/main/ezusb2-emu/util.h +++ b/src/main/ezusb2-emu/util.h @@ -3,6 +3,6 @@ #include "hook/iohook.h" -void ezusb2_emu_util_log_usb_msg(const char* prefix, const struct irp *irp); +void ezusb2_emu_util_log_usb_msg(const char *prefix, const struct irp *irp); #endif diff --git a/src/main/ezusb2-iidx-emu/msg.c b/src/main/ezusb2-iidx-emu/msg.c index a0663ac..f1596ce 100644 --- a/src/main/ezusb2-iidx-emu/msg.c +++ b/src/main/ezusb2-iidx-emu/msg.c @@ -31,13 +31,11 @@ static struct ezusb_emu_msg_hook ezusb2_iidx_emu_msg_hook = { .interrupt_read = ezusb2_iidx_emu_msg_interrupt_read, .interrupt_write = ezusb2_iidx_emu_msg_interrupt_write, .bulk_read = ezusb2_iidx_emu_msg_bulk_read, - .bulk_write = ezusb2_iidx_emu_msg_bulk_write -}; + .bulk_write = ezusb2_iidx_emu_msg_bulk_write}; /* ------------------------------------------------------------------------ */ -static const struct ezusb_iidx_emu_node* ezusb2_iidx_emu_msg_nodes[256] = -{ +static const struct ezusb_iidx_emu_node *ezusb2_iidx_emu_msg_nodes[256] = { [EZUSB_IIDX_MSG_NODE_16SEG] = &ezusb_iidx_emu_node_16seg, [EZUSB_IIDX_MSG_NODE_COIN] = &ezusb_iidx_emu_node_coin, [EZUSB_IIDX_MSG_NODE_NONE] = &ezusb_iidx_emu_node_none, @@ -51,14 +49,13 @@ static uint8_t ezusb2_iidx_emu_msg_read_cur_node = 0; /* ------------------------------------------------------------------------ */ -struct ezusb_emu_msg_hook* ezusb2_iidx_emu_msg_init(void) +struct ezusb_emu_msg_hook *ezusb2_iidx_emu_msg_init(void) { /* Init all nodes */ for (uint32_t i = 0; i < 256; i++) { - /* "Constructor" optional */ if (ezusb2_iidx_emu_msg_nodes[i] && - ezusb2_iidx_emu_msg_nodes[i]->init_node) { + ezusb2_iidx_emu_msg_nodes[i]->init_node) { ezusb2_iidx_emu_msg_nodes[i]->init_node(); } } @@ -68,8 +65,8 @@ struct ezusb_emu_msg_hook* ezusb2_iidx_emu_msg_init(void) static HRESULT ezusb2_iidx_emu_msg_interrupt_read(struct iobuf *read) { - struct ezusb2_iidx_msg_interrupt_read_packet* msg_resp = - (struct ezusb2_iidx_msg_interrupt_read_packet*) read->bytes; + struct ezusb2_iidx_msg_interrupt_read_packet *msg_resp = + (struct ezusb2_iidx_msg_interrupt_read_packet *) read->bytes; if (!iidx_io_ep2_recv()) { return E_FAIL; @@ -78,13 +75,13 @@ static HRESULT ezusb2_iidx_emu_msg_interrupt_read(struct iobuf *read) msg_resp->p1_turntable = iidx_io_ep2_get_turntable(0); msg_resp->p2_turntable = iidx_io_ep2_get_turntable(1); - msg_resp->sliders[0] = iidx_io_ep2_get_slider(0) | - (iidx_io_ep2_get_slider(1) << 4); + msg_resp->sliders[0] = + iidx_io_ep2_get_slider(0) | (iidx_io_ep2_get_slider(1) << 4); - msg_resp->sliders[1] = iidx_io_ep2_get_slider(2) | - (iidx_io_ep2_get_slider(3) << 4); + msg_resp->sliders[1] = + iidx_io_ep2_get_slider(2) | (iidx_io_ep2_get_slider(3) << 4); - msg_resp->sliders[2] = iidx_io_ep2_get_slider(4); + msg_resp->sliders[2] = iidx_io_ep2_get_slider(4); msg_resp->inverted_pad = ((iidx_io_ep2_get_keys() & 0x3FFF) << 16) | (iidx_io_ep2_get_panel() & 0x0F) | @@ -106,8 +103,8 @@ static HRESULT ezusb2_iidx_emu_msg_interrupt_read(struct iobuf *read) static HRESULT ezusb2_iidx_emu_msg_interrupt_write(struct const_iobuf *write) { - const struct ezusb2_iidx_msg_interrupt_write_packet* msg_req = - (const struct ezusb2_iidx_msg_interrupt_write_packet*) write->bytes; + const struct ezusb2_iidx_msg_interrupt_write_packet *msg_req = + (const struct ezusb2_iidx_msg_interrupt_write_packet *) write->bytes; if (write->nbytes < sizeof(*msg_req)) { log_warning("Interrupt write message too small"); @@ -117,8 +114,8 @@ static HRESULT ezusb2_iidx_emu_msg_interrupt_write(struct const_iobuf *write) if (!ezusb2_iidx_emu_msg_nodes[msg_req->node]) { ezusb2_iidx_emu_msg_read_cur_node = 0; - log_warning("Unrecognised node in interrupt message: %02x", - msg_req->node); + log_warning( + "Unrecognised node in interrupt message: %02x", msg_req->node); return E_INVALIDARG; } @@ -135,24 +132,24 @@ static HRESULT ezusb2_iidx_emu_msg_interrupt_write(struct const_iobuf *write) /* 16seg data is provided with the request and not handled using a separate bulk endpoint like on the C02 IO board */ - if (!iidx_io_ep3_write_16seg((const char*) msg_req->seg16)) { + if (!iidx_io_ep3_write_16seg((const char *) msg_req->seg16)) { return E_FAIL; } /* Remember node for next bulk read */ ezusb2_iidx_emu_msg_read_cur_node = msg_req->node; - ezusb2_iidx_emu_msg_status = ezusb2_iidx_emu_msg_nodes[msg_req->node]-> - process_cmd(msg_req->cmd, msg_req->cmd_detail[0], - msg_req->cmd_detail[1]); + ezusb2_iidx_emu_msg_status = + ezusb2_iidx_emu_msg_nodes[msg_req->node]->process_cmd( + msg_req->cmd, msg_req->cmd_detail[0], msg_req->cmd_detail[1]); return S_OK; } static HRESULT ezusb2_iidx_emu_msg_bulk_read(struct iobuf *read) { - struct ezusb_iidx_msg_bulk_packet* pkt = - (struct ezusb_iidx_msg_bulk_packet*) read->bytes; + struct ezusb_iidx_msg_bulk_packet *pkt = + (struct ezusb_iidx_msg_bulk_packet *) read->bytes; if (read->nbytes < sizeof(*pkt)) { log_warning("Bulk read buffer too small"); @@ -161,14 +158,15 @@ static HRESULT ezusb2_iidx_emu_msg_bulk_read(struct iobuf *read) } if (!ezusb2_iidx_emu_msg_nodes[ezusb2_iidx_emu_msg_read_cur_node]) { - log_warning("Bulk read unsupported on cur_node = %d", + log_warning( + "Bulk read unsupported on cur_node = %d", ezusb2_iidx_emu_msg_read_cur_node); return E_NOTIMPL; } - if (!ezusb2_iidx_emu_msg_nodes[ezusb2_iidx_emu_msg_read_cur_node]-> - read_packet(pkt)) { + if (!ezusb2_iidx_emu_msg_nodes[ezusb2_iidx_emu_msg_read_cur_node] + ->read_packet(pkt)) { return E_FAIL; } @@ -179,8 +177,8 @@ static HRESULT ezusb2_iidx_emu_msg_bulk_read(struct iobuf *read) static HRESULT ezusb2_iidx_emu_msg_bulk_write(struct const_iobuf *write) { - const struct ezusb_iidx_msg_bulk_packet* pkt = - (const struct ezusb_iidx_msg_bulk_packet*) write->bytes; + const struct ezusb_iidx_msg_bulk_packet *pkt = + (const struct ezusb_iidx_msg_bulk_packet *) write->bytes; if (write->nbytes < sizeof(*pkt)) { log_warning("Bulk write packet too small"); diff --git a/src/main/ezusb2-iidx-emu/msg.h b/src/main/ezusb2-iidx-emu/msg.h index 8036096..012d4ba 100644 --- a/src/main/ezusb2-iidx-emu/msg.h +++ b/src/main/ezusb2-iidx-emu/msg.h @@ -10,10 +10,10 @@ /** * Init the fully emulated IIDX msg backend for a EZUSB FX2 (IO2) board - * - * @return ezusb_emu_msg_hook structure with hook calls for ezusb msg + * + * @return ezusb_emu_msg_hook structure with hook calls for ezusb msg * dispatching */ -struct ezusb_emu_msg_hook* ezusb2_iidx_emu_msg_init(void); +struct ezusb_emu_msg_hook *ezusb2_iidx_emu_msg_init(void); #endif diff --git a/src/main/ezusb2-iidx/ezusb2-iidx.c b/src/main/ezusb2-iidx/ezusb2-iidx.c index 43f96bd..8d8ede0 100644 --- a/src/main/ezusb2-iidx/ezusb2-iidx.c +++ b/src/main/ezusb2-iidx/ezusb2-iidx.c @@ -13,16 +13,22 @@ enum ezusb2_iidx_msg_pipe { EZUSB2_IIDX_MSG_PIPE_BULK_IN = 0x86 }; -bool ezusb2_iidx_interrupt_read(HANDLE handle, - struct ezusb2_iidx_msg_interrupt_read_packet* packet) +bool ezusb2_iidx_interrupt_read( + HANDLE handle, struct ezusb2_iidx_msg_interrupt_read_packet *packet) { - return ezusb2_endpoint_transfer(handle, EZUSB2_IIDX_MSG_PIPE_INTERRUPT_IN, - (void*) packet, sizeof(struct ezusb2_iidx_msg_interrupt_read_packet)); + return ezusb2_endpoint_transfer( + handle, + EZUSB2_IIDX_MSG_PIPE_INTERRUPT_IN, + (void *) packet, + sizeof(struct ezusb2_iidx_msg_interrupt_read_packet)); } -bool ezusb2_iidx_interrupt_write(HANDLE handle, - const struct ezusb2_iidx_msg_interrupt_write_packet* packet) +bool ezusb2_iidx_interrupt_write( + HANDLE handle, const struct ezusb2_iidx_msg_interrupt_write_packet *packet) { - return ezusb2_endpoint_transfer(handle, EZUSB2_IIDX_MSG_PIPE_INTERRUPT_OUT, - (void*) packet, sizeof(struct ezusb2_iidx_msg_interrupt_write_packet)); + return ezusb2_endpoint_transfer( + handle, + EZUSB2_IIDX_MSG_PIPE_INTERRUPT_OUT, + (void *) packet, + sizeof(struct ezusb2_iidx_msg_interrupt_write_packet)); } \ No newline at end of file diff --git a/src/main/ezusb2-iidx/ezusb2-iidx.h b/src/main/ezusb2-iidx/ezusb2-iidx.h index c8a8d31..3b802f6 100644 --- a/src/main/ezusb2-iidx/ezusb2-iidx.h +++ b/src/main/ezusb2-iidx/ezusb2-iidx.h @@ -7,10 +7,10 @@ #include "msg.h" -bool ezusb2_iidx_interrupt_read(HANDLE handle, - struct ezusb2_iidx_msg_interrupt_read_packet* packet); +bool ezusb2_iidx_interrupt_read( + HANDLE handle, struct ezusb2_iidx_msg_interrupt_read_packet *packet); -bool ezusb2_iidx_interrupt_write(HANDLE handle, - const struct ezusb2_iidx_msg_interrupt_write_packet* packet); +bool ezusb2_iidx_interrupt_write( + HANDLE handle, const struct ezusb2_iidx_msg_interrupt_write_packet *packet); #endif \ No newline at end of file diff --git a/src/main/ezusb2-iidx/msg.h b/src/main/ezusb2-iidx/msg.h index 58ccbb9..d16009d 100644 --- a/src/main/ezusb2-iidx/msg.h +++ b/src/main/ezusb2-iidx/msg.h @@ -1,8 +1,8 @@ #ifndef EZUSB2_IIDX_MSG_H #define EZUSB2_IIDX_MSG_H -#include #include +#include #pragma pack(push, 1) struct ezusb2_iidx_msg_interrupt_write_packet { @@ -28,55 +28,60 @@ struct ezusb2_iidx_msg_interrupt_write_packet { #pragma pack(pop) /* Some static asserts to ensure that lights are at correct offsets */ -_Static_assert(offsetof(struct ezusb2_iidx_msg_interrupt_write_packet, - panel_lights) == 8, "panel_lights is at wrong offset for fx2 packet"); -_Static_assert(offsetof(struct ezusb2_iidx_msg_interrupt_write_packet, - deck_lights) == 11, "deck_lights is at wrong offset for fx2 packet"); -_Static_assert(offsetof(struct ezusb2_iidx_msg_interrupt_write_packet, - top_lamps) == 14, "top_lamps is at wrong offset for fx2 packet"); -_Static_assert(offsetof(struct ezusb2_iidx_msg_interrupt_write_packet, - top_neons) == 15, "top_neons is at wrong offset for fx2 packet"); -_Static_assert(offsetof(struct ezusb2_iidx_msg_interrupt_write_packet, - padding[39]) == 64, "Last padding element is at wrong offset for fx2 write packet"); +_Static_assert( + offsetof(struct ezusb2_iidx_msg_interrupt_write_packet, panel_lights) == 8, + "panel_lights is at wrong offset for fx2 packet"); +_Static_assert( + offsetof(struct ezusb2_iidx_msg_interrupt_write_packet, deck_lights) == 11, + "deck_lights is at wrong offset for fx2 packet"); +_Static_assert( + offsetof(struct ezusb2_iidx_msg_interrupt_write_packet, top_lamps) == 14, + "top_lamps is at wrong offset for fx2 packet"); +_Static_assert( + offsetof(struct ezusb2_iidx_msg_interrupt_write_packet, top_neons) == 15, + "top_neons is at wrong offset for fx2 packet"); +_Static_assert( + offsetof(struct ezusb2_iidx_msg_interrupt_write_packet, padding[39]) == 64, + "Last padding element is at wrong offset for fx2 write packet"); struct ezusb2_iidx_msg_interrupt_read_packet { /* Pad mappings: 0: P1_Start - 1: P2_Start - 2: VEFX - 3: Effector - 4: Test - 5: Service - 6: unknown/not used - 7: unknown/not used + 1: P2_Start + 2: VEFX + 3: Effector + 4: Test + 5: Service + 6: unknown/not used + 7: unknown/not used 8: unknown/not used - 9: unknown/not used - 10: unknown/not used - 11: unknown/not used - 12: unknown/not used - 13: unknown/not used - 14: unknown/not used - 15: unknown/not used + 9: unknown/not used + 10: unknown/not used + 11: unknown/not used + 12: unknown/not used + 13: unknown/not used + 14: unknown/not used + 15: unknown/not used - 16: P1_1 - 17: P1_2 - 18: P1_3 - 19: P1_4 - 20: P1_5 - 21: P1_6 - 22: P1_7 - 23: P2_1 + 16: P1_1 + 17: P1_2 + 18: P1_3 + 19: P1_4 + 20: P1_5 + 21: P1_6 + 22: P1_7 + 23: P2_1 - 24: P2_2 - 25: P2_3 - 26: P2_4 - 27: P2_5 - 28: P2_6 - 29: P2_7 - 30: Coin mech - 31: Not used + 24: P2_2 + 25: P2_3 + 26: P2_4 + 27: P2_5 + 28: P2_6 + 29: P2_7 + 30: Coin mech + 31: Not used */ uint8_t unk0; uint8_t unk1; @@ -96,7 +101,8 @@ struct ezusb2_iidx_msg_interrupt_read_packet { uint8_t padding[46]; }; -_Static_assert(offsetof(struct ezusb2_iidx_msg_interrupt_read_packet, - padding[45]) == 63, "Last padding element is at wrong offset for fx2 read packet"); +_Static_assert( + offsetof(struct ezusb2_iidx_msg_interrupt_read_packet, padding[45]) == 63, + "Last padding element is at wrong offset for fx2 read packet"); #endif diff --git a/src/main/ezusb2-tool/main.c b/src/main/ezusb2-tool/main.c index 745acc9..cdfd179 100644 --- a/src/main/ezusb2-tool/main.c +++ b/src/main/ezusb2-tool/main.c @@ -10,7 +10,7 @@ static int scan() { - char* path; + char *path; log_misc("Scanning..."); @@ -25,7 +25,7 @@ static int scan() } } -static int info(const char* dev_path) +static int info(const char *dev_path) { HANDLE handle; struct ezusb_ident ident; @@ -52,10 +52,10 @@ static int info(const char* dev_path) return 0; } -static int flash(const char* dev_path, const char* fw_path) +static int flash(const char *dev_path, const char *fw_path) { HANDLE handle; - struct ezusb_firmware* fw; + struct ezusb_firmware *fw; fw = ezusb_firmware_load(fw_path); @@ -64,8 +64,8 @@ static int flash(const char* dev_path, const char* fw_path) return -5; } - log_misc("Loaded firmware, crc 0x%X, segments %d", fw->crc, - fw->segment_count); + log_misc( + "Loaded firmware, crc 0x%X, segments %d", fw->crc, fw->segment_count); if (ezusb_firmware_crc(fw) != fw->crc) { log_fatal("Firmware CRC check failed"); @@ -97,20 +97,21 @@ static int flash(const char* dev_path, const char* fw_path) return 0; } -static void usage(const char* argv0) +static void usage(const char *argv0) { - printf("ezusb2-tool for EZUSB FX2 hardware, e.g. IIDX/Pop'n IO2, build " - __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) "\n" - "Usage: %s [cmd] ...\n" - "Available commands:\n" - " scan: Scan for connected EZUSB FX2 devices and output the " - "device path\n" - " info: Get basic information (vid, pid, name) of a connected " - "device\n" - " flash: Flash a firmware binary\n", argv0); + printf("ezusb2-tool for EZUSB FX2 hardware, e.g. IIDX/Pop'n IO2, build " __DATE__ " " __TIME__ + ", gitrev " STRINGIFY(GITREV) "\n" + "Usage: %s [cmd] ...\n" + "Available commands:\n" + " scan: Scan for connected EZUSB FX2 devices and output the " + "device path\n" + " info: Get basic information (vid, pid, name) of a connected " + "device\n" + " flash: Flash a firmware binary\n", + argv0); } -int main(int argc, char** argv) +int main(int argc, char **argv) { int arg_pos; @@ -127,9 +128,10 @@ int main(int argc, char** argv) return scan(); } else if (!strcmp(argv[arg_pos], "info")) { arg_pos++; - + if (arg_pos >= argc) { - printf("Usage: info [dev_path]\n" + printf( + "Usage: info [dev_path]\n" " dev_path: Device path of device to query. Use the 'scan' " "command to aquire a device path of a connected device\n"); return -1; @@ -140,7 +142,8 @@ int main(int argc, char** argv) arg_pos++; if (arg_pos + 1 >= argc) { - printf("Usage: flash [dev_path] [fw_path]\n" + printf( + "Usage: flash [dev_path] [fw_path]\n" " dev_path: Device path of device to flash. Use the 'scan' " "command to aquire a device path of a connected device\n" " fw_path: Path to firmware binary file to flash\n"); diff --git a/src/main/ezusb2/cyioctl.h b/src/main/ezusb2/cyioctl.h index 386a85a..5a18ca1 100644 --- a/src/main/ezusb2/cyioctl.h +++ b/src/main/ezusb2/cyioctl.h @@ -17,23 +17,22 @@ Additional Notes: #ifndef __IOCTL_H__ #define __IOCTL_H__ - #ifndef DRIVER #ifndef CTL_CODE - #include +#include #endif #ifndef BM_REQUEST_TYPE - #include "usb200.h" +#include "usb200.h" #endif #define DIR_HOST_TO_DEVICE 0 #define DIR_DEVICE_TO_HOST 1 -#define DEVICE_SPEED_UNKNOWN 0x00000000 -#define DEVICE_SPEED_LOW_FULL 0x00000001 -#define DEVICE_SPEED_HIGH 0x00000002 +#define DEVICE_SPEED_UNKNOWN 0x00000000 +#define DEVICE_SPEED_LOW_FULL 0x00000001 +#define DEVICE_SPEED_HIGH 0x00000002 typedef struct _WORD_SPLIT { UCHAR lowByte; @@ -41,14 +40,13 @@ typedef struct _WORD_SPLIT { } WORD_SPLIT, *PWORD_SPLIT; typedef struct _BM_REQ_TYPE { - UCHAR Recipient:2; - UCHAR Reserved:3; - UCHAR Type:2; - UCHAR Direction:1; + UCHAR Recipient : 2; + UCHAR Reserved : 3; + UCHAR Type : 2; + UCHAR Direction : 1; } BM_REQ_TYPE, *PBM_REQ_TYPE; typedef struct _SETUP_PACKET { - union { BM_REQ_TYPE bmReqType; UCHAR bmRequest; @@ -75,13 +73,12 @@ typedef struct _SETUP_PACKET { } SETUP_PACKET, *PSETUP_PACKET; -#define USB_ISO_ID 0x4945 -#define USB_ISO_CMD_ASAP 0x8000 -#define USB_ISO_CMD_CURRENT_FRAME 0x8001 -#define USB_ISO_CMD_SET_FRAME 0x8002 +#define USB_ISO_ID 0x4945 +#define USB_ISO_CMD_ASAP 0x8000 +#define USB_ISO_CMD_CURRENT_FRAME 0x8001 +#define USB_ISO_CMD_SET_FRAME 0x8002 typedef struct _ISO_ADV_PARAMS { - USHORT isoId; USHORT isoCmd; @@ -123,84 +120,189 @@ typedef struct _SET_TRANSFER_SIZE_INFO { ULONG TransferSize; } SET_TRANSFER_SIZE_INFO, *PSET_TRANSFER_SIZE_INFO; - // // Macro to extract function out of the device io control code // #ifdef WIN_98_DDK -#define DEVICE_TYPE_FROM_CTL_CODE(ctrlCode) (((ULONG)(ctrlCode & 0xffff0000)) >> 16) +#define DEVICE_TYPE_FROM_CTL_CODE(ctrlCode) \ + (((ULONG)(ctrlCode & 0xffff0000)) >> 16) #endif -#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))) - +#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))) #define IOCTL_ADAPT_INDEX 0x0000 // Get the driver version -#define IOCTL_ADAPT_GET_DRIVER_VERSION CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTL_ADAPT_INDEX, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_ADAPT_GET_DRIVER_VERSION \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + IOCTL_ADAPT_INDEX, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) // Get the current USBDI version -#define IOCTL_ADAPT_GET_USBDI_VERSION CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTL_ADAPT_INDEX+1, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_ADAPT_GET_USBDI_VERSION \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + IOCTL_ADAPT_INDEX + 1, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) // Get the current device alt interface settings from driver -#define IOCTL_ADAPT_GET_ALT_INTERFACE_SETTING CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTL_ADAPT_INDEX+2, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_ADAPT_GET_ALT_INTERFACE_SETTING \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + IOCTL_ADAPT_INDEX + 2, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) // Set the device interface and alt interface setting -#define IOCTL_ADAPT_SELECT_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTL_ADAPT_INDEX+3, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_ADAPT_SELECT_INTERFACE \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + IOCTL_ADAPT_INDEX + 3, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) // Get device address from driver -#define IOCTL_ADAPT_GET_ADDRESS CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTL_ADAPT_INDEX+4, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_ADAPT_GET_ADDRESS \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + IOCTL_ADAPT_INDEX + 4, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) -// Get number of endpoints for current interface and alt interface setting from driver -#define IOCTL_ADAPT_GET_NUMBER_ENDPOINTS CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTL_ADAPT_INDEX+5, METHOD_BUFFERED, FILE_ANY_ACCESS) +// Get number of endpoints for current interface and alt interface setting from +// driver +#define IOCTL_ADAPT_GET_NUMBER_ENDPOINTS \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + IOCTL_ADAPT_INDEX + 5, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) // Get the current device power state -#define IOCTL_ADAPT_GET_DEVICE_POWER_STATE CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTL_ADAPT_INDEX+6, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_ADAPT_GET_DEVICE_POWER_STATE \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + IOCTL_ADAPT_INDEX + 6, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) // Set the device power state -#define IOCTL_ADAPT_SET_DEVICE_POWER_STATE CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTL_ADAPT_INDEX+7, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_ADAPT_SET_DEVICE_POWER_STATE \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + IOCTL_ADAPT_INDEX + 7, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) // Send a raw packet to endpoint 0 -#define IOCTL_ADAPT_SEND_EP0_CONTROL_TRANSFER CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTL_ADAPT_INDEX+8, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_ADAPT_SEND_EP0_CONTROL_TRANSFER \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + IOCTL_ADAPT_INDEX + 8, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) // Send/receive data to/from nonep0 -#define IOCTL_ADAPT_SEND_NON_EP0_TRANSFER CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTL_ADAPT_INDEX+9, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_ADAPT_SEND_NON_EP0_TRANSFER \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + IOCTL_ADAPT_INDEX + 9, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) // Simulate a disconnect/reconnect -#define IOCTL_ADAPT_CYCLE_PORT CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTL_ADAPT_INDEX+10, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_ADAPT_CYCLE_PORT \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + IOCTL_ADAPT_INDEX + 10, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) // Reset the pipe -#define IOCTL_ADAPT_RESET_PIPE CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTL_ADAPT_INDEX+11, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_ADAPT_RESET_PIPE \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + IOCTL_ADAPT_INDEX + 11, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) // Reset the device -#define IOCTL_ADAPT_RESET_PARENT_PORT CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTL_ADAPT_INDEX+12, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_ADAPT_RESET_PARENT_PORT \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + IOCTL_ADAPT_INDEX + 12, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) // Get the current transfer size of an endpoint (in number of bytes) -#define IOCTL_ADAPT_GET_TRANSFER_SIZE CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTL_ADAPT_INDEX+13, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_ADAPT_GET_TRANSFER_SIZE \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + IOCTL_ADAPT_INDEX + 13, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) // Set the transfer size of an endpoint (in number of bytes) -#define IOCTL_ADAPT_SET_TRANSFER_SIZE CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTL_ADAPT_INDEX+14, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_ADAPT_SET_TRANSFER_SIZE \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + IOCTL_ADAPT_INDEX + 14, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) // Return the name of the device -#define IOCTL_ADAPT_GET_DEVICE_NAME CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTL_ADAPT_INDEX+15, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_ADAPT_GET_DEVICE_NAME \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + IOCTL_ADAPT_INDEX + 15, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) // Return the "Friendly Name" of the device -#define IOCTL_ADAPT_GET_FRIENDLY_NAME CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTL_ADAPT_INDEX+16, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_ADAPT_GET_FRIENDLY_NAME \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + IOCTL_ADAPT_INDEX + 16, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) // Abort all outstanding transfers on the pipe -#define IOCTL_ADAPT_ABORT_PIPE CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTL_ADAPT_INDEX+17, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_ADAPT_ABORT_PIPE \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + IOCTL_ADAPT_INDEX + 17, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) // Send/receive data to/from nonep0 w/ direct buffer acccess (no buffering) -#define IOCTL_ADAPT_SEND_NON_EP0_DIRECT CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTL_ADAPT_INDEX+18, METHOD_NEITHER, FILE_ANY_ACCESS) +#define IOCTL_ADAPT_SEND_NON_EP0_DIRECT \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + IOCTL_ADAPT_INDEX + 18, \ + METHOD_NEITHER, \ + FILE_ANY_ACCESS) // Return device speed -#define IOCTL_ADAPT_GET_DEVICE_SPEED CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTL_ADAPT_INDEX+19, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_ADAPT_GET_DEVICE_SPEED \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + IOCTL_ADAPT_INDEX + 19, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) // Get the current USB frame number -#define IOCTL_ADAPT_GET_CURRENT_FRAME CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTL_ADAPT_INDEX+20, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_ADAPT_GET_CURRENT_FRAME \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + IOCTL_ADAPT_INDEX + 20, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) #define NUMBER_OF_ADAPT_IOCTLS 21 // Last IOCTL_ADAPT_INDEX + 1 - #endif // __IOCTL_H__ \ No newline at end of file diff --git a/src/main/ezusb2/ezusb2.c b/src/main/ezusb2/ezusb2.c index b181831..9e8685e 100644 --- a/src/main/ezusb2/ezusb2.c +++ b/src/main/ezusb2/ezusb2.c @@ -1,5 +1,5 @@ -#include #include +#include #include "ezusb/ezusb.h" @@ -27,9 +27,16 @@ #define EP0_EZUSB_RAM_CPU_RESET_ADDR 0xE600 -static int ezusb2_ctrl_transfer(HANDLE handle, uint32_t ioctl_code, - uint8_t endpoint, uint8_t req_type, uint8_t req, uint16_t value, - uint16_t index, void* buf, uint32_t buf_len) +static int ezusb2_ctrl_transfer( + HANDLE handle, + uint32_t ioctl_code, + uint8_t endpoint, + uint8_t req_type, + uint8_t req, + uint16_t value, + uint16_t index, + void *buf, + uint32_t buf_len) { int xmit_buf_size = sizeof(SINGLE_TRANSFER) + buf_len; char xmit_buf[xmit_buf_size]; @@ -57,8 +64,15 @@ static int ezusb2_ctrl_transfer(HANDLE handle, uint32_t ioctl_code, memcpy(xmit_buf + sizeof(SINGLE_TRANSFER), buf, buf_len); } - if (!DeviceIoControl(handle, ioctl_code, xmit_buf, xmit_buf_size, xmit_buf, - xmit_buf_size, &ret_len, NULL)) { + if (!DeviceIoControl( + handle, + ioctl_code, + xmit_buf, + xmit_buf_size, + xmit_buf, + xmit_buf_size, + &ret_len, + NULL)) { return -1; } @@ -69,23 +83,51 @@ static int ezusb2_ctrl_transfer(HANDLE handle, uint32_t ioctl_code, return ret_len - sizeof(SINGLE_TRANSFER); } -static int ezusb2_ep0_transfer(HANDLE handle, uint8_t req_type, uint8_t req, - uint16_t value, uint16_t index, void* buf, uint32_t buf_len) +static int ezusb2_ep0_transfer( + HANDLE handle, + uint8_t req_type, + uint8_t req, + uint16_t value, + uint16_t index, + void *buf, + uint32_t buf_len) { - return ezusb2_ctrl_transfer(handle, IOCTL_ADAPT_SEND_EP0_CONTROL_TRANSFER, - REQ_CODE_EP0, req_type, req, value, index, buf, buf_len); + return ezusb2_ctrl_transfer( + handle, + IOCTL_ADAPT_SEND_EP0_CONTROL_TRANSFER, + REQ_CODE_EP0, + req_type, + req, + value, + index, + buf, + buf_len); } /* Any other endpoint than 0 */ -static int ezusb2_epx_transfer(HANDLE handle, uint8_t endpoint, - uint8_t req_type, uint8_t req, uint16_t value, uint16_t index, - void* buf, uint32_t buf_len) +static int ezusb2_epx_transfer( + HANDLE handle, + uint8_t endpoint, + uint8_t req_type, + uint8_t req, + uint16_t value, + uint16_t index, + void *buf, + uint32_t buf_len) { - return ezusb2_ctrl_transfer(handle, IOCTL_ADAPT_SEND_NON_EP0_TRANSFER, - endpoint, req_type, req, value, index, buf, buf_len); + return ezusb2_ctrl_transfer( + handle, + IOCTL_ADAPT_SEND_NON_EP0_TRANSFER, + endpoint, + req_type, + req, + value, + index, + buf, + buf_len); } -static char* ezusb2_get_device_name(HANDLE handle) +static char *ezusb2_get_device_name(HANDLE handle) { const int len = 256; char buf[len]; @@ -93,24 +135,37 @@ static char* ezusb2_get_device_name(HANDLE handle) memset(&buf, 0, len); - if (!DeviceIoControl(handle, IOCTL_ADAPT_GET_FRIENDLY_NAME, &buf, len, &buf, - len, &received, NULL)) { + if (!DeviceIoControl( + handle, + IOCTL_ADAPT_GET_FRIENDLY_NAME, + &buf, + len, + &buf, + len, + &received, + NULL)) { return NULL; } - return str_dup((const char*) &buf); + return str_dup((const char *) &buf); } -static bool ezusb2_get_device_descriptor(HANDLE handle, - USB_DEVICE_DESCRIPTOR* desc) +static bool +ezusb2_get_device_descriptor(HANDLE handle, USB_DEVICE_DESCRIPTOR *desc) { int res; memset(desc, 0, sizeof(USB_DEVICE_DESCRIPTOR)); /* 0: not used */ - res = ezusb2_ep0_transfer(handle, REQ_TYPE_DEV_TO_HOST, EP0_GET_DESCRIPTOR, - EP0_DESCRIPTOR_TYPE_DEVICE, 0, desc, sizeof(USB_DEVICE_DESCRIPTOR)); + res = ezusb2_ep0_transfer( + handle, + REQ_TYPE_DEV_TO_HOST, + EP0_GET_DESCRIPTOR, + EP0_DESCRIPTOR_TYPE_DEVICE, + 0, + desc, + sizeof(USB_DEVICE_DESCRIPTOR)); if (res != sizeof(USB_DEVICE_DESCRIPTOR)) { return false; @@ -119,11 +174,17 @@ static bool ezusb2_get_device_descriptor(HANDLE handle, return true; } -static bool ezusb2_write_ram(HANDLE handle, const void* buffer, - uint16_t ram_offset, uint32_t size) +static bool ezusb2_write_ram( + HANDLE handle, const void *buffer, uint16_t ram_offset, uint32_t size) { - return ezusb2_ep0_transfer(handle, REQ_TYPE_HOST_TO_DEV, EP0_EZUSB_WRITE_RAM, - ram_offset, 0, (void*) buffer, size) == size; + return ezusb2_ep0_transfer( + handle, + REQ_TYPE_HOST_TO_DEV, + EP0_EZUSB_WRITE_RAM, + ram_offset, + 0, + (void *) buffer, + size) == size; } static bool ezusb2_reset(HANDLE handle, bool hold) @@ -133,32 +194,32 @@ static bool ezusb2_reset(HANDLE handle, bool hold) /* Write CPU state */ flag = hold ? 1 : 0; - return ezusb2_write_ram(handle, &flag, EP0_EZUSB_RAM_CPU_RESET_ADDR, - sizeof(uint8_t)); + return ezusb2_write_ram( + handle, &flag, EP0_EZUSB_RAM_CPU_RESET_ADDR, sizeof(uint8_t)); } -char* ezusb2_find(const GUID* guid) +char *ezusb2_find(const GUID *guid) { HDEVINFO info; SP_DEVICE_INTERFACE_DATA iface; BOOL result; ULONG required_len; - PSP_DEVICE_INTERFACE_DETAIL_DATA detail; - ULONG length; - char* res; + PSP_DEVICE_INTERFACE_DETAIL_DATA detail; + ULONG length; + char *res; log_assert(guid); result = FALSE; required_len = 0; - detail = NULL; + detail = NULL; - info = SetupDiGetClassDevs(guid, NULL, NULL, - DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); + info = SetupDiGetClassDevs( + guid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); if (info == INVALID_HANDLE_VALUE) { - return NULL; - } + return NULL; + } /* Enum devices that support the GUID, get first only */ memset(&iface, 0, sizeof(iface)); @@ -175,17 +236,17 @@ char* ezusb2_find(const GUID* guid) know how much memory to allocate to get this information, so we will ask by passing in a null buffer and location to receive the size of the buffer needed. */ - result = SetupDiGetDeviceInterfaceDetail(info, &iface, NULL, 0, - &required_len, NULL); + result = SetupDiGetDeviceInterfaceDetail( + info, &iface, NULL, 0, &required_len, NULL); if (!required_len) { return NULL; } - /* Okay, we got a size back, so let's allocate memory + /* Okay, we got a size back, so let's allocate memory for the interface detail information we want. */ - detail = (PSP_DEVICE_INTERFACE_DETAIL_DATA) LocalAlloc(LMEM_FIXED, - required_len); + detail = + (PSP_DEVICE_INTERFACE_DETAIL_DATA) LocalAlloc(LMEM_FIXED, required_len); if (detail == NULL) { SetupDiDestroyDeviceInfoList(info); @@ -195,8 +256,8 @@ char* ezusb2_find(const GUID* guid) detail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); length = required_len; - result = SetupDiGetDeviceInterfaceDetail(info, &iface, detail, - length, &required_len, NULL); + result = SetupDiGetDeviceInterfaceDetail( + info, &iface, detail, length, &required_len, NULL); if (!result) { SetupDiDestroyDeviceInfoList(info); @@ -204,7 +265,7 @@ char* ezusb2_find(const GUID* guid) return NULL; } - res = str_dup((const char*) &detail->DevicePath); + res = str_dup((const char *) &detail->DevicePath); LocalFree(detail); SetupDiDestroyDeviceInfoList(info); @@ -212,17 +273,24 @@ char* ezusb2_find(const GUID* guid) return res; } -HANDLE ezusb2_open(const char* device_path) +HANDLE +ezusb2_open(const char *device_path) { log_assert(device_path); - return CreateFileA(device_path, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, - OPEN_EXISTING, 0, NULL); + return CreateFileA( + device_path, + GENERIC_WRITE, + FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + 0, + NULL); } -bool ezusb2_get_ident(HANDLE handle, struct ezusb_ident* ident) +bool ezusb2_get_ident(HANDLE handle, struct ezusb_ident *ident) { - char* name; + char *name; USB_DEVICE_DESCRIPTOR desc; log_assert(handle != INVALID_HANDLE_VALUE); @@ -250,7 +318,7 @@ bool ezusb2_get_ident(HANDLE handle, struct ezusb_ident* ident) return true; } -bool ezusb2_download_firmware(HANDLE handle, struct ezusb_firmware* fw) +bool ezusb2_download_firmware(HANDLE handle, struct ezusb_firmware *fw) { log_assert(handle != INVALID_HANDLE_VALUE); log_assert(handle); @@ -263,8 +331,11 @@ bool ezusb2_download_firmware(HANDLE handle, struct ezusb_firmware* fw) for (uint16_t i = 0; i < fw->segment_count; i++) { /* Important: Writing the full binary does NOT work on the FX2 device compared to the legacy ezusb device */ - if (!ezusb2_write_ram(handle, fw->segments[i]->data, - fw->segments[i]->offset, fw->segments[i]->size)) { + if (!ezusb2_write_ram( + handle, + fw->segments[i]->data, + fw->segments[i]->offset, + fw->segments[i]->size)) { return false; } } @@ -276,8 +347,8 @@ bool ezusb2_download_firmware(HANDLE handle, struct ezusb_firmware* fw) return true; } -bool ezusb2_endpoint_transfer(HANDLE handle, uint8_t endpoint, void* data, - uint32_t size) +bool ezusb2_endpoint_transfer( + HANDLE handle, uint8_t endpoint, void *data, uint32_t size) { if (endpoint == 0) { return false; diff --git a/src/main/ezusb2/ezusb2.h b/src/main/ezusb2/ezusb2.h index c559266..5b090a0 100644 --- a/src/main/ezusb2/ezusb2.h +++ b/src/main/ezusb2/ezusb2.h @@ -2,17 +2,17 @@ * Module for fundamental communication with an Ezusb FX2 board, e.g. * IIDX/Pop'n IO2. Credit also goes to willxinc for his initial implemention * which, for some unknown reason, did not work on my machines. - * + * * This module does not implement any sort of higher level protocol which is * required by the games to exchange data with the device, e.g. getting input * states of keys and setting light outputs. Further modules are utilizing this * base layer to implement higher level communication. - * + * * Note: This module requires the newer "cyusb3" driver which is compatible * with WinXP, Win7, Win8 and Win10 (both 32 and 64-bit). The old "cyusb" driver * does NOT work with this. - * - * @author icex2, willxinc + * + * @author icex2, willxinc */ #ifndef EZUSB2_H #define EZUSB2_H @@ -27,62 +27,65 @@ /** * GUID of Ezusb FX2 board */ -static const GUID EZUSB2_GUID = {0xAE18AA60L, 0x7F6A, 0x11D4, +static const GUID EZUSB2_GUID = { + 0xAE18AA60L, + 0x7F6A, + 0x11D4, {0x97, 0xDD, 0x00, 0x01, 0x02, 0x29, 0xB9, 0x59}}; /** * Scan for connected devices which match the provided GUID. - * + * * @param guid GUID of device to find. * @return Allocated device path string of first device found matching the GUID * provided. Caller has to free buffer. */ -char* ezusb2_find(const GUID* guid); +char *ezusb2_find(const GUID *guid); /** * Open a connected Ezusb FX2 device. - * - * @param device_path Path to the Ezusb FX2 device obtained by using + * + * @param device_path Path to the Ezusb FX2 device obtained by using * the ezusb2_find function. - * @return A valid handle to the device on success, INVALID_HANDLE_VALUE on + * @return A valid handle to the device on success, INVALID_HANDLE_VALUE on * error. */ -HANDLE ezusb2_open(const char* device_path); +HANDLE ezusb2_open(const char *device_path); /** * Get identifier information of the device. - * + * * @param handle Valid device handle. * @param ident Pointer to memory to write the identifier information to. * @return True if successful and identifier information was written to the * the struct, false on error. */ -bool ezusb2_get_ident(HANDLE handle, struct ezusb_ident* ident); +bool ezusb2_get_ident(HANDLE handle, struct ezusb_ident *ident); /** * Download a firmware to the ezusb device. - * + * * @param handle Valid device handle. * @param fw Firmware to write to the target ezusb device. * @return True on success, false on failure. */ -bool ezusb2_download_firmware(HANDLE handle, struct ezusb_firmware* fw); +bool ezusb2_download_firmware(HANDLE handle, struct ezusb_firmware *fw); /** * Execute a data transfer to a specific endpoint other than endpoint 0. - * + * * @param handle Valid device handle. * @param endpoint Target endpoint, in and out valid but not 0. * @param data Buffer with data to transfer or for data to receive. * @param size Size of buffer. * @return True on success, false on failure. */ -bool ezusb2_endpoint_transfer(HANDLE handle, uint8_t endpoint, void* data, - uint32_t size); +bool ezusb2_endpoint_transfer( + HANDLE handle, uint8_t endpoint, void *data, uint32_t size); /** * Close an opened ezusb device handle. - * + * * @param handle Valid handle to close. */ void ezusb2_close(HANDLE handle); diff --git a/src/main/geninput/dev-list.c b/src/main/geninput/dev-list.c index ad657e1..82efa6f 100644 --- a/src/main/geninput/dev-list.c +++ b/src/main/geninput/dev-list.c @@ -1,6 +1,6 @@ -#include -#include #include +#include +#include #include #include @@ -14,12 +14,12 @@ void dev_list_init(struct dev_list *devs, const GUID *class_guid) { devs->class_guid = (GUID *) class_guid; - devs->infolist = SetupDiGetClassDevs(devs->class_guid, NULL, NULL, - DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); + devs->infolist = SetupDiGetClassDevs( + devs->class_guid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); if (devs->infolist == NULL) { - log_fatal("SetupDiGetClassDevs failed: %08x", - (unsigned int) GetLastError()); + log_fatal( + "SetupDiGetClassDevs failed: %08x", (unsigned int) GetLastError()); } devs->dev_no = 0; @@ -50,23 +50,29 @@ bool dev_list_next(struct dev_list *devs) if (GetLastError() == ERROR_NO_MORE_ITEMS) { return false; } else { - log_fatal("SetupDiEnumDeviceInfo failed: %08x", - (unsigned int) GetLastError()); + log_fatal( + "SetupDiEnumDeviceInfo failed: %08x", + (unsigned int) GetLastError()); } } devs->iface.cbSize = sizeof(devs->iface); - if (!SetupDiEnumDeviceInterfaces(devs->infolist, &devs->dev, - devs->class_guid, devs->iface_no, &devs->iface)) { + if (!SetupDiEnumDeviceInterfaces( + devs->infolist, + &devs->dev, + devs->class_guid, + devs->iface_no, + &devs->iface)) { if (GetLastError() == ERROR_NO_MORE_ITEMS) { devs->dev_no++; devs->iface_no = 0; continue; } else { - log_fatal("SetupDiEnumDeviceInterfaces failed: %08x", - (unsigned int) GetLastError()); + log_fatal( + "SetupDiEnumDeviceInterfaces failed: %08x", + (unsigned int) GetLastError()); } } @@ -84,20 +90,27 @@ const char *dev_list_get_dev_node(struct dev_list *devs) return devs->detail->DevicePath; } - if (SetupDiGetDeviceInterfaceDetail(devs->infolist, &devs->iface, NULL, 0, - &detail_size, NULL) - || GetLastError() != ERROR_INSUFFICIENT_BUFFER) { - log_fatal("SetupDiGetDeviceInterfaceDetail sizing failed: %08x", - (unsigned int) GetLastError()); + if (SetupDiGetDeviceInterfaceDetail( + devs->infolist, &devs->iface, NULL, 0, &detail_size, NULL) || + GetLastError() != ERROR_INSUFFICIENT_BUFFER) { + log_fatal( + "SetupDiGetDeviceInterfaceDetail sizing failed: %08x", + (unsigned int) GetLastError()); } devs->detail = xmalloc(detail_size); devs->detail->cbSize = sizeof(*devs->detail); - if (!SetupDiGetDeviceInterfaceDetail(devs->infolist, &devs->iface, - devs->detail, detail_size, NULL, NULL)) { - log_fatal("SetupDiGetDeviceInterfaceDetail content failed: %08x", - (unsigned int) GetLastError()); + if (!SetupDiGetDeviceInterfaceDetail( + devs->infolist, + &devs->iface, + devs->detail, + detail_size, + NULL, + NULL)) { + log_fatal( + "SetupDiGetDeviceInterfaceDetail content failed: %08x", + (unsigned int) GetLastError()); } return devs->detail->DevicePath; @@ -106,7 +119,7 @@ const char *dev_list_get_dev_node(struct dev_list *devs) const wchar_t *dev_list_get_dev_name(struct dev_list *devs) { DWORD name_size; - const char* dev_path; + const char *dev_path; // largest possible product string according to WinAPI docs wchar_t product_string[126]; DWORD product_size; @@ -116,11 +129,19 @@ const wchar_t *dev_list_get_dev_name(struct dev_list *devs) return devs->name; } - if (SetupDiGetDeviceRegistryPropertyW(devs->infolist, &devs->dev, - SPDRP_DEVICEDESC, NULL, NULL, 0, &name_size) - || GetLastError() != ERROR_INSUFFICIENT_BUFFER) { - log_fatal("SetupDiGetDeviceRegistryPropertyW(SPDRP_DEVICEDESC) sizing " - "failed: %08x", (unsigned int) GetLastError()); + if (SetupDiGetDeviceRegistryPropertyW( + devs->infolist, + &devs->dev, + SPDRP_DEVICEDESC, + NULL, + NULL, + 0, + &name_size) || + GetLastError() != ERROR_INSUFFICIENT_BUFFER) { + log_fatal( + "SetupDiGetDeviceRegistryPropertyW(SPDRP_DEVICEDESC) sizing " + "failed: %08x", + (unsigned int) GetLastError()); } /* This function returns arbitrary data, not just strings. Therefore, we @@ -128,23 +149,40 @@ const wchar_t *dev_list_get_dev_name(struct dev_list *devs) devs->name = xmalloc(name_size); - if (!SetupDiGetDeviceRegistryPropertyW(devs->infolist, &devs->dev, - SPDRP_DEVICEDESC, NULL, (void *) devs->name, name_size, 0)) { - log_fatal("SetupDiGetDeviceRegistryPropertyW(SPDRP_DEVICEDESC) content " - "failed: %08x", (unsigned int) GetLastError()); + if (!SetupDiGetDeviceRegistryPropertyW( + devs->infolist, + &devs->dev, + SPDRP_DEVICEDESC, + NULL, + (void *) devs->name, + name_size, + 0)) { + log_fatal( + "SetupDiGetDeviceRegistryPropertyW(SPDRP_DEVICEDESC) content " + "failed: %08x", + (unsigned int) GetLastError()); } /* Also, try and get the product string - this is usually far more human readable than the registry value, which is often "HID Compliant Thing". We then append this in parentheses */ dev_path = dev_list_get_dev_node(devs); - HANDLE hid_hnd = CreateFile(dev_path, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); - if(hid_hnd) { - product_success = HidD_GetProductString(hid_hnd, product_string, sizeof(product_string)); + HANDLE hid_hnd = CreateFile( + dev_path, + 0, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + 0, + NULL); + if (hid_hnd) { + product_success = HidD_GetProductString( + hid_hnd, product_string, sizeof(product_string)); CloseHandle(hid_hnd); - if(product_success && wcslen(product_string) > 0 && wcscmp(product_string, devs->name)) { + if (product_success && wcslen(product_string) > 0 && + wcscmp(product_string, devs->name)) { // len + null + 2*parentheses + space separator - product_size = (wcslen(product_string)+4) * sizeof(wchar_t); + product_size = (wcslen(product_string) + 4) * sizeof(wchar_t); devs->name = xrealloc(devs->name, name_size + product_size); wcscat(devs->name, L" ("); wcscat(devs->name, product_string); @@ -166,8 +204,8 @@ void dev_list_fini(struct dev_list *devs) } if (!SetupDiDestroyDeviceInfoList(devs->infolist)) { - log_fatal("SetupDiDestroyDeviceList failed: %08x", - (unsigned int) GetLastError()); + log_fatal( + "SetupDiDestroyDeviceList failed: %08x", + (unsigned int) GetLastError()); } } - diff --git a/src/main/geninput/dev-list.h b/src/main/geninput/dev-list.h index feca672..612c363 100644 --- a/src/main/geninput/dev-list.h +++ b/src/main/geninput/dev-list.h @@ -1,8 +1,8 @@ #ifndef GENINPUT_DEV_LIST_H #define GENINPUT_DEV_LIST_H -#include #include +#include #include #include diff --git a/src/main/geninput/guid.c b/src/main/geninput/guid.c index b4f2dac..c8a1849 100644 --- a/src/main/geninput/guid.c +++ b/src/main/geninput/guid.c @@ -1,4 +1,4 @@ -#include #include +#include #include "geninput/hid.h" diff --git a/src/main/geninput/hid-generic-strings.c b/src/main/geninput/hid-generic-strings.c index cf2bd6f..4424041 100644 --- a/src/main/geninput/hid-generic-strings.c +++ b/src/main/geninput/hid-generic-strings.c @@ -1,5 +1,5 @@ -#include #include +#include #include @@ -46,4 +46,3 @@ void hid_generic_strings_fini(struct hid_generic_strings *strings) free(strings->str_prod); free(strings->wstr_prod); } - diff --git a/src/main/geninput/hid-generic-strings.h b/src/main/geninput/hid-generic-strings.h index 92ed12f..3734c59 100644 --- a/src/main/geninput/hid-generic-strings.h +++ b/src/main/geninput/hid-generic-strings.h @@ -13,5 +13,4 @@ const char *hid_generic_strings_get_manf(struct hid_generic_strings *strings); const char *hid_generic_strings_get_prod(struct hid_generic_strings *strings); void hid_generic_strings_fini(struct hid_generic_strings *strings); - #endif diff --git a/src/main/geninput/hid-generic.c b/src/main/geninput/hid-generic.c index 467445e..bb5bfc0 100644 --- a/src/main/geninput/hid-generic.c +++ b/src/main/geninput/hid-generic.c @@ -6,14 +6,14 @@ #include #include -#include #include +#include -#include "geninput/hid.h" -#include "geninput/hid-generic.h" #include "geninput/hid-generic-strings.h" +#include "geninput/hid-generic.h" #include "geninput/hid-meta-in.h" #include "geninput/hid-meta-out.h" +#include "geninput/hid.h" #include "util/defs.h" #include "util/log.h" @@ -44,44 +44,48 @@ struct hid_generic { bool out_faulty; }; -static bool hid_generic_get_device_usage(const struct hid *hid, - uint32_t *usage); -static bool hid_generic_get_name(const struct hid *hid, wchar_t *chars, - size_t *nchars); -static bool hid_generic_get_controls(const struct hid *hid, - struct hid_control *controls, size_t *ncontrols); -static bool hid_generic_get_lights(const struct hid *hid, - struct hid_light *lights, size_t *nlights); -static bool hid_generic_get_value(struct hid *hid, size_t control_no, - int32_t *out_value); -static bool hid_generic_set_light(struct hid *hid, size_t light_no, - uint32_t intensity); -static bool hid_generic_handle_event(struct hid_fd *super, OVERLAPPED *ovl, - size_t nbytes); +static bool +hid_generic_get_device_usage(const struct hid *hid, uint32_t *usage); +static bool +hid_generic_get_name(const struct hid *hid, wchar_t *chars, size_t *nchars); +static bool hid_generic_get_controls( + const struct hid *hid, struct hid_control *controls, size_t *ncontrols); +static bool hid_generic_get_lights( + const struct hid *hid, struct hid_light *lights, size_t *nlights); +static bool +hid_generic_get_value(struct hid *hid, size_t control_no, int32_t *out_value); +static bool +hid_generic_set_light(struct hid *hid, size_t light_no, uint32_t intensity); +static bool +hid_generic_handle_event(struct hid_fd *super, OVERLAPPED *ovl, size_t nbytes); static void hid_generic_close(struct hid *hid); -static struct hid_fd_vtbl hid_generic_vtbl = {{ - /* .close = */ hid_generic_close, - /* .get_device_usage = */ hid_generic_get_device_usage, - /* .get_name = */ hid_generic_get_name, - /* .get_controls = */ hid_generic_get_controls, - /* .get_lights = */ hid_generic_get_lights, - /* .get_value = */ hid_generic_get_value, - /* .set_light = */ hid_generic_set_light }, - /* .handle_event = */ hid_generic_handle_event -}; +static struct hid_fd_vtbl hid_generic_vtbl = { + {/* .close = */ hid_generic_close, + /* .get_device_usage = */ hid_generic_get_device_usage, + /* .get_name = */ hid_generic_get_name, + /* .get_controls = */ hid_generic_get_controls, + /* .get_lights = */ hid_generic_get_lights, + /* .get_value = */ hid_generic_get_value, + /* .set_light = */ hid_generic_set_light}, + /* .handle_event = */ hid_generic_handle_event}; -bool hid_generic_open(struct hid_fd **out, const char *dev_node, HANDLE iocp, - uintptr_t iocp_ctx) +bool hid_generic_open( + struct hid_fd **out, const char *dev_node, HANDLE iocp, uintptr_t iocp_ctx) { struct hid_generic *hg; uint32_t tlc_usage; hg = xmalloc(sizeof(*hg)); - hg->fd = CreateFile(dev_node, GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, - OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); + hg->fd = CreateFile( + dev_node, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_FLAG_OVERLAPPED, + NULL); if (hg->fd == INVALID_HANDLE_VALUE) { /* Probably a keyboard that's locked by the OS */ @@ -117,12 +121,13 @@ bool hid_generic_open(struct hid_fd **out, const char *dev_node, HANDLE iocp, log_misc("Initializing generic HID on dev node %s:", dev_node); log_misc("... Product: %s", hg->strings.str_prod); log_misc("... Manufacturer: %s", hg->strings.str_manf); - log_misc("... Device usage: %08x", - hid_meta_in_get_tlc_usage(&hg->meta_in)); - log_misc("... Number of controls: %u", - (unsigned int) hid_meta_in_get_ncontrols(&hg->meta_in)); - log_misc("... Number of \"lights\": %u", - (unsigned int) hid_meta_out_get_nlights(&hg->meta_out)); + log_misc("... Device usage: %08x", hid_meta_in_get_tlc_usage(&hg->meta_in)); + log_misc( + "... Number of controls: %u", + (unsigned int) hid_meta_in_get_ncontrols(&hg->meta_in)); + log_misc( + "... Number of \"lights\": %u", + (unsigned int) hid_meta_out_get_nlights(&hg->meta_out)); /* Start up input double-buffer chain by reading a report. We bind to the IO completion port here. */ @@ -134,11 +139,12 @@ bool hid_generic_open(struct hid_fd **out, const char *dev_node, HANDLE iocp, memset(&hg->in_ovl, 0, sizeof(hg->in_ovl)); - if (!ReadFile(hg->fd, hg->in_buf, hg->in_nbytes, NULL, - &hg->in_ovl)) { + if (!ReadFile(hg->fd, hg->in_buf, hg->in_nbytes, NULL, &hg->in_ovl)) { if (GetLastError() != ERROR_IO_PENDING) { - log_warning("Initial ReadFile failed: %08x: %s", - (unsigned int) GetLastError(), dev_node); + log_warning( + "Initial ReadFile failed: %08x: %s", + (unsigned int) GetLastError(), + dev_node); goto read_fail; } @@ -189,8 +195,7 @@ open_fail: return false; } -static bool hid_generic_get_device_usage(const struct hid *hid, - uint32_t *usage) +static bool hid_generic_get_device_usage(const struct hid *hid, uint32_t *usage) { const struct hid_generic *hg = containerof(hid, struct hid_generic, super); @@ -199,8 +204,8 @@ static bool hid_generic_get_device_usage(const struct hid *hid, return true; } -static bool hid_generic_get_name(const struct hid *hid, wchar_t *chars, - size_t *nchars) +static bool +hid_generic_get_name(const struct hid *hid, wchar_t *chars, size_t *nchars) { const struct hid_generic *hg = containerof(hid, struct hid_generic, super); size_t len; @@ -222,8 +227,8 @@ static bool hid_generic_get_name(const struct hid *hid, wchar_t *chars, } } -static bool hid_generic_get_controls(const struct hid *hid, - struct hid_control *controls, size_t *ncontrols) +static bool hid_generic_get_controls( + const struct hid *hid, struct hid_control *controls, size_t *ncontrols) { const struct hid_generic *hg = containerof(hid, struct hid_generic, super); @@ -251,11 +256,11 @@ static bool hid_generic_get_controls(const struct hid *hid, } } -static bool hid_generic_get_lights(const struct hid *hid, - struct hid_light *lights, size_t *nlights) +static bool hid_generic_get_lights( + const struct hid *hid, struct hid_light *lights, size_t *nlights) { - const struct hid_generic *hg = containerof(hid, const struct hid_generic, - super); + const struct hid_generic *hg = + containerof(hid, const struct hid_generic, super); const struct hid_light *meta_lights; size_t meta_nlights; @@ -279,16 +284,16 @@ static bool hid_generic_get_lights(const struct hid *hid, } } -static bool hid_generic_get_value(struct hid *hid, size_t control_no, - int32_t *out_value) +static bool +hid_generic_get_value(struct hid *hid, size_t control_no, int32_t *out_value) { struct hid_generic *hg = containerof(hid, struct hid_generic, super); return hid_meta_in_get_value(&hg->meta_in, control_no, out_value); } -static bool hid_generic_set_light(struct hid *hid, size_t light_no, - uint32_t intensity) +static bool +hid_generic_set_light(struct hid *hid, size_t light_no, uint32_t intensity) { struct hid_generic *hg = containerof(hid, struct hid_generic, super); @@ -306,11 +311,13 @@ static bool hid_generic_set_light(struct hid *hid, size_t light_no, log_misc("Starting light output to %s", hg->dev_node); hid_meta_out_get_next_report(&hg->meta_out, hg->out_buf); - if (!WriteFile(hg->fd, hg->out_buf, hg->out_nbytes, NULL, - &hg->out_ovl)) { + if (!WriteFile( + hg->fd, hg->out_buf, hg->out_nbytes, NULL, &hg->out_ovl)) { if (GetLastError() != ERROR_IO_PENDING) { - log_warning("Initial WriteFile failed: %08x: %s", - (unsigned int) GetLastError(), hg->dev_node); + log_warning( + "Initial WriteFile failed: %08x: %s", + (unsigned int) GetLastError(), + hg->dev_node); hg->out_faulty = true; return false; @@ -323,8 +330,8 @@ static bool hid_generic_set_light(struct hid *hid, size_t light_no, return hid_meta_out_set_light(&hg->meta_out, light_no, intensity); } -static bool hid_generic_handle_event(struct hid_fd *hid_fd, OVERLAPPED *ovl, - size_t nbytes) +static bool +hid_generic_handle_event(struct hid_fd *hid_fd, OVERLAPPED *ovl, size_t nbytes) { struct hid_generic *hg = containerof(hid_fd, struct hid_generic, super); @@ -334,11 +341,14 @@ static bool hid_generic_handle_event(struct hid_fd *hid_fd, OVERLAPPED *ovl, hid_meta_out_get_next_report(&hg->meta_out, hg->out_buf); memset(&hg->out_ovl, 0, sizeof(hg->out_ovl)); - if (!WriteFile(hg->fd, hg->out_buf, hg->out_nbytes, NULL, - &hg->out_ovl) && GetLastError() != ERROR_IO_PENDING) { - log_warning("Write error %08x from \"%s\" device on dev node %s", - (unsigned int) GetLastError(), hg->strings.str_prod, - hg->dev_node); + if (!WriteFile( + hg->fd, hg->out_buf, hg->out_nbytes, NULL, &hg->out_ovl) && + GetLastError() != ERROR_IO_PENDING) { + log_warning( + "Write error %08x from \"%s\" device on dev node %s", + (unsigned int) GetLastError(), + hg->strings.str_prod, + hg->dev_node); return false; } @@ -351,8 +361,11 @@ static bool hid_generic_handle_event(struct hid_fd *hid_fd, OVERLAPPED *ovl, with a pointer to a fresh buffer we can use for subsequent I/O */ if (!hid_meta_in_dispatch(&hg->meta_in, &hg->in_buf, nbytes)) { - log_warning("Failed to process input report from \"%s\" device" - " on dev node %s", hg->strings.str_prod, hg->dev_node); + log_warning( + "Failed to process input report from \"%s\" device" + " on dev node %s", + hg->strings.str_prod, + hg->dev_node); return false; } @@ -371,11 +384,13 @@ static bool hid_generic_handle_event(struct hid_fd *hid_fd, OVERLAPPED *ovl, memset(&hg->in_ovl, 0, sizeof(hg->in_ovl)); - if (!ReadFile(hg->fd, hg->in_buf, hg->in_nbytes, NULL, - &hg->in_ovl) && GetLastError() != ERROR_IO_PENDING) { - log_warning("Read error %08x from \"%s\" device on dev node %s", - (unsigned int) GetLastError(), hg->strings.str_prod, - hg->dev_node); + if (!ReadFile(hg->fd, hg->in_buf, hg->in_nbytes, NULL, &hg->in_ovl) && + GetLastError() != ERROR_IO_PENDING) { + log_warning( + "Read error %08x from \"%s\" device on dev node %s", + (unsigned int) GetLastError(), + hg->strings.str_prod, + hg->dev_node); return false; } @@ -405,4 +420,3 @@ static void hid_generic_close(struct hid *hid) free(hid); } - diff --git a/src/main/geninput/hid-generic.h b/src/main/geninput/hid-generic.h index e695dc8..2160584 100644 --- a/src/main/geninput/hid-generic.h +++ b/src/main/geninput/hid-generic.h @@ -8,7 +8,7 @@ #include "geninput/hid.h" -bool hid_generic_open(struct hid_fd **hid, const char *dev_node, - HANDLE iocp, uintptr_t iocp_ctx); +bool hid_generic_open( + struct hid_fd **hid, const char *dev_node, HANDLE iocp, uintptr_t iocp_ctx); #endif diff --git a/src/main/geninput/hid-meta-in.c b/src/main/geninput/hid-meta-in.c index 88d5bf4..5fa4ad8 100644 --- a/src/main/geninput/hid-meta-in.c +++ b/src/main/geninput/hid-meta-in.c @@ -1,7 +1,7 @@ #define LOG_MODULE "hid-generic" -#include #include +#include #include #include @@ -14,13 +14,13 @@ #include "util/log.h" #include "util/mem.h" -static bool hid_meta_in_init_caps(struct hid_meta_in *meta, - PHIDP_PREPARSED_DATA ppd); +static bool +hid_meta_in_init_caps(struct hid_meta_in *meta, PHIDP_PREPARSED_DATA ppd); static void hid_meta_in_init_arrays(struct hid_meta_in *meta); static void hid_meta_in_init_buttons(struct hid_meta_in *meta); static void hid_meta_in_init_values(struct hid_meta_in *meta); -static struct hid_report_in *hid_meta_in_lookup_report( - struct hid_meta_in *meta, uint8_t report_id); +static struct hid_report_in * +hid_meta_in_lookup_report(struct hid_meta_in *meta, uint8_t report_id); static void hid_meta_in_fini_arrays(struct hid_meta_in *meta); static void hid_meta_in_fini_caps(struct hid_meta_in *meta); @@ -37,8 +37,8 @@ bool hid_meta_in_init(struct hid_meta_in *meta, PHIDP_PREPARSED_DATA ppd) return true; } -static bool hid_meta_in_init_caps(struct hid_meta_in *meta, - PHIDP_PREPARSED_DATA ppd) +static bool +hid_meta_in_init_caps(struct hid_meta_in *meta, PHIDP_PREPARSED_DATA ppd) { uint16_t len; NTSTATUS status; @@ -57,7 +57,8 @@ static bool hid_meta_in_init_caps(struct hid_meta_in *meta, meta->caps_btn = xmalloc(sizeof(*meta->caps_btn) * len); if (len > 0) { - status = HidP_GetButtonCaps(HidP_Input, meta->caps_btn, &len,meta->ppd); + status = + HidP_GetButtonCaps(HidP_Input, meta->caps_btn, &len, meta->ppd); if (status != HIDP_STATUS_SUCCESS) { log_warning("Error getting button caps"); @@ -118,7 +119,7 @@ static void hid_meta_in_init_arrays(struct hid_meta_in *meta) /* Count up buttons, globally and per-report */ - for (i = 0 ; i < meta->caps_tlc.NumberInputButtonCaps ; i++) { + for (i = 0; i < meta->caps_tlc.NumberInputButtonCaps; i++) { bc = &meta->caps_btn[i]; if (bc->IsRange) { @@ -139,7 +140,7 @@ static void hid_meta_in_init_arrays(struct hid_meta_in *meta) /* Count up values, note all reports that have values */ - for (i = 0 ; i < meta->caps_tlc.NumberInputValueCaps ; i++) { + for (i = 0; i < meta->caps_tlc.NumberInputValueCaps; i++) { vc = &meta->caps_val[i]; if (vc->IsRange) { @@ -159,7 +160,7 @@ static void hid_meta_in_init_arrays(struct hid_meta_in *meta) /* Count up total number of reports and initialize them */ - for (i = 0 ; i < 0x100 ; i++) { + for (i = 0; i < 0x100; i++) { if (report_btns[i] || report_presence[i]) { meta->nreports++; } @@ -168,21 +169,25 @@ static void hid_meta_in_init_arrays(struct hid_meta_in *meta) j = 0; meta->reports = xmalloc(sizeof(*meta->reports) * meta->nreports); - for (i = 0 ; i < 0x100 ; i++) { + for (i = 0; i < 0x100; i++) { if (report_btns[i] || report_presence[i]) { report_buf = xmalloc(meta->caps_tlc.InputReportByteLength); - hid_report_in_init(&meta->reports[j++], (uint8_t) i, - report_btns[i], report_buf, - meta->caps_tlc.InputReportByteLength, meta->ppd); + hid_report_in_init( + &meta->reports[j++], + (uint8_t) i, + report_btns[i], + report_buf, + meta->caps_tlc.InputReportByteLength, + meta->ppd); } } /* Init control arrays */ meta->controls = xmalloc(sizeof(*meta->controls) * meta->ncontrols); - meta->priv_controls = xmalloc(sizeof(*meta->priv_controls) - * meta->ncontrols); + meta->priv_controls = + xmalloc(sizeof(*meta->priv_controls) * meta->ncontrols); /* Clean up our scratch space */ @@ -201,11 +206,11 @@ static void hid_meta_in_init_buttons(struct hid_meta_in *meta) pos = 0; - for (i = 0 ; i < meta->caps_tlc.NumberInputButtonCaps ; i++) { + for (i = 0; i < meta->caps_tlc.NumberInputButtonCaps; i++) { bc = &meta->caps_btn[i]; if (bc->IsRange) { - for (j = 0 ; j <= bc->Range.UsageMax - bc->Range.UsageMin ; j++) { + for (j = 0; j <= bc->Range.UsageMax - bc->Range.UsageMin; j++) { priv = &meta->priv_controls[pos]; priv->report = hid_meta_in_lookup_report(meta, bc->ReportID); @@ -249,11 +254,11 @@ static void hid_meta_in_init_values(struct hid_meta_in *meta) pos = meta->nbuttons; - for (i = 0 ; i < meta->caps_tlc.NumberInputValueCaps ; i++) { + for (i = 0; i < meta->caps_tlc.NumberInputValueCaps; i++) { vc = &meta->caps_val[i]; if (vc->IsRange) { - for (j = 0 ; j <= vc->Range.UsageMax - vc->Range.UsageMin ; j++) { + for (j = 0; j <= vc->Range.UsageMax - vc->Range.UsageMin; j++) { priv = &meta->priv_controls[pos]; priv->report = hid_meta_in_lookup_report(meta, vc->ReportID); @@ -276,7 +281,7 @@ static void hid_meta_in_init_values(struct hid_meta_in *meta) pos++; } - } else { + } else { priv = &meta->priv_controls[pos]; priv->report = hid_meta_in_lookup_report(meta, vc->ReportID); @@ -302,12 +307,12 @@ static void hid_meta_in_init_values(struct hid_meta_in *meta) } } -static struct hid_report_in *hid_meta_in_lookup_report( - struct hid_meta_in *meta, uint8_t report_id) +static struct hid_report_in * +hid_meta_in_lookup_report(struct hid_meta_in *meta, uint8_t report_id) { unsigned int i; - for (i = 0 ; i < meta->nreports ; i++) { + for (i = 0; i < meta->nreports; i++) { if (meta->reports[i].id == report_id) { return &meta->reports[i]; } @@ -316,8 +321,8 @@ static struct hid_report_in *hid_meta_in_lookup_report( return NULL; } -bool hid_meta_in_dispatch(struct hid_meta_in *meta, uint8_t **bytes, - size_t nbytes) +bool hid_meta_in_dispatch( + struct hid_meta_in *meta, uint8_t **bytes, size_t nbytes) { struct hid_report_in *r; uint8_t report_id; @@ -344,8 +349,8 @@ size_t hid_meta_in_get_buffer_size(const struct hid_meta_in *meta) return meta->caps_tlc.InputReportByteLength; } -const struct hid_control *hid_meta_in_get_controls( - const struct hid_meta_in *meta) +const struct hid_control * +hid_meta_in_get_controls(const struct hid_meta_in *meta) { return meta->controls; } @@ -360,8 +365,8 @@ uint32_t hid_meta_in_get_tlc_usage(const struct hid_meta_in *meta) return (meta->caps_tlc.UsagePage << 16) | meta->caps_tlc.Usage; } -bool hid_meta_in_get_value(struct hid_meta_in *meta, - size_t control_no, int32_t *value) +bool hid_meta_in_get_value( + struct hid_meta_in *meta, size_t control_no, int32_t *value) { struct hid_control_in *priv; uint32_t usage; @@ -374,11 +379,11 @@ bool hid_meta_in_get_value(struct hid_meta_in *meta, usage = meta->controls[control_no].usage; if (control_no < meta->nbuttons) { - return hid_report_in_get_bit(priv->report, meta->ppd, - priv->collection_id, usage, value); + return hid_report_in_get_bit( + priv->report, meta->ppd, priv->collection_id, usage, value); } else { - return hid_report_in_get_value(priv->report, meta->ppd, - priv->collection_id, usage, value); + return hid_report_in_get_value( + priv->report, meta->ppd, priv->collection_id, usage, value); } } @@ -395,7 +400,7 @@ static void hid_meta_in_fini_arrays(struct hid_meta_in *meta) free(meta->priv_controls); free(meta->controls); - for (i = 0 ; i < meta->nreports ; i++) { + for (i = 0; i < meta->nreports; i++) { hid_report_in_fini(&meta->reports[i]); } @@ -407,4 +412,3 @@ static void hid_meta_in_fini_caps(struct hid_meta_in *meta) free(meta->caps_val); free(meta->caps_btn); } - diff --git a/src/main/geninput/hid-meta-in.h b/src/main/geninput/hid-meta-in.h index ca9f8c5..acbd3c9 100644 --- a/src/main/geninput/hid-meta-in.h +++ b/src/main/geninput/hid-meta-in.h @@ -1,14 +1,14 @@ #ifndef GENINPUT_HID_META_IN_H #define GENINPUT_HID_META_IN_H -#include #include +#include #include #include -#include "geninput/hid.h" #include "geninput/hid-report-in.h" +#include "geninput/hid.h" struct hid_control_in { struct hid_report_in *report; @@ -32,15 +32,15 @@ struct hid_meta_in { }; bool hid_meta_in_init(struct hid_meta_in *meta, PHIDP_PREPARSED_DATA ppd); -bool hid_meta_in_dispatch(struct hid_meta_in *meta, uint8_t **bytes, - size_t nbytes); +bool hid_meta_in_dispatch( + struct hid_meta_in *meta, uint8_t **bytes, size_t nbytes); size_t hid_meta_in_get_buffer_size(const struct hid_meta_in *meta); -const struct hid_control *hid_meta_in_get_controls( - const struct hid_meta_in *meta); +const struct hid_control * +hid_meta_in_get_controls(const struct hid_meta_in *meta); size_t hid_meta_in_get_ncontrols(const struct hid_meta_in *meta); uint32_t hid_meta_in_get_tlc_usage(const struct hid_meta_in *meta); -bool hid_meta_in_get_value(struct hid_meta_in *meta, - size_t control_no, int32_t *value); +bool hid_meta_in_get_value( + struct hid_meta_in *meta, size_t control_no, int32_t *value); void hid_meta_in_fini(struct hid_meta_in *meta); #endif diff --git a/src/main/geninput/hid-meta-out.c b/src/main/geninput/hid-meta-out.c index 6a5a7f0..e74e989 100644 --- a/src/main/geninput/hid-meta-out.c +++ b/src/main/geninput/hid-meta-out.c @@ -1,7 +1,7 @@ #define LOG_MODULE "hid-generic" -#include #include +#include #include #include @@ -15,16 +15,17 @@ #include "util/log.h" #include "util/mem.h" -static bool hid_meta_out_init_caps(struct hid_meta_out *meta, - PHIDP_PREPARSED_DATA ppd); +static bool +hid_meta_out_init_caps(struct hid_meta_out *meta, PHIDP_PREPARSED_DATA ppd); static bool hid_meta_out_init_arrays(struct hid_meta_out *meta); static void hid_meta_out_init_lights(struct hid_meta_out *meta, HANDLE fd); -static struct hid_report_out *hid_meta_out_lookup_report( - struct hid_meta_out *meta, uint8_t report_id); +static struct hid_report_out * +hid_meta_out_lookup_report(struct hid_meta_out *meta, uint8_t report_id); static void hid_meta_out_fini_arrays(struct hid_meta_out *meta); static void hid_meta_out_fini_caps(struct hid_meta_out *meta); -bool hid_meta_out_init(struct hid_meta_out *meta, PHIDP_PREPARSED_DATA ppd, HANDLE fd) +bool hid_meta_out_init( + struct hid_meta_out *meta, PHIDP_PREPARSED_DATA ppd, HANDLE fd) { if (!hid_meta_out_init_caps(meta, ppd)) { goto caps_fail; @@ -47,8 +48,8 @@ caps_fail: return false; } -static bool hid_meta_out_init_caps(struct hid_meta_out *meta, - PHIDP_PREPARSED_DATA ppd) +static bool +hid_meta_out_init_caps(struct hid_meta_out *meta, PHIDP_PREPARSED_DATA ppd) { uint16_t len; NTSTATUS status; @@ -67,8 +68,8 @@ static bool hid_meta_out_init_caps(struct hid_meta_out *meta, meta->caps_btn = xmalloc(sizeof(*meta->caps_btn) * len); if (len > 0) { - status = HidP_GetButtonCaps(HidP_Output, meta->caps_btn, &len, - meta->ppd); + status = + HidP_GetButtonCaps(HidP_Output, meta->caps_btn, &len, meta->ppd); if (status != HIDP_STATUS_SUCCESS) { log_warning("Error getting button caps"); @@ -81,8 +82,8 @@ static bool hid_meta_out_init_caps(struct hid_meta_out *meta, meta->caps_val = xmalloc(sizeof(*meta->caps_val) * len); if (len > 0) { - status = HidP_GetValueCaps(HidP_Output, meta->caps_val, &len, - meta->ppd); + status = + HidP_GetValueCaps(HidP_Output, meta->caps_val, &len, meta->ppd); if (status != HIDP_STATUS_SUCCESS) { log_warning("Error getting value caps"); @@ -127,7 +128,7 @@ static bool hid_meta_out_init_arrays(struct hid_meta_out *meta) /* Count up buttons, globally and per-report */ - for (i = 0 ; i < meta->caps_tlc.NumberOutputButtonCaps ; i++) { + for (i = 0; i < meta->caps_tlc.NumberOutputButtonCaps; i++) { bc = &meta->caps_btn[i]; if (bc->IsRange) { @@ -142,7 +143,7 @@ static bool hid_meta_out_init_arrays(struct hid_meta_out *meta) report_presence[bc->ReportID] = true; } - for (i = 0 ; i < meta->caps_tlc.NumberOutputValueCaps ; i++) { + for (i = 0; i < meta->caps_tlc.NumberOutputValueCaps; i++) { vc = &meta->caps_val[i]; if (vc->IsRange) { @@ -156,10 +157,10 @@ static bool hid_meta_out_init_arrays(struct hid_meta_out *meta) /* Count up total number of reports and initialize them */ - nreports = 0; /* Allocated */ - meta->nreports = 0; /* Initialized so far (see unwind below) */ + nreports = 0; /* Allocated */ + meta->nreports = 0; /* Initialized so far (see unwind below) */ - for (i = 0 ; i < 0x100 ; i++) { + for (i = 0; i < 0x100; i++) { if (report_presence[i]) { nreports++; } @@ -167,13 +168,16 @@ static bool hid_meta_out_init_arrays(struct hid_meta_out *meta) meta->reports = xmalloc(sizeof(*meta->reports) * nreports); - for (i = 0 ; i < 0x100 ; i++) { + for (i = 0; i < 0x100; i++) { if (report_presence[i]) { nbytes = meta->caps_tlc.OutputReportByteLength; bytes = xmalloc(meta->caps_tlc.OutputReportByteLength); - if (!hid_report_out_init(&meta->reports[meta->nreports], - meta->ppd, (uint8_t) i, nbytes)) { + if (!hid_report_out_init( + &meta->reports[meta->nreports], + meta->ppd, + (uint8_t) i, + nbytes)) { goto r_init_fail; } @@ -193,7 +197,7 @@ static bool hid_meta_out_init_arrays(struct hid_meta_out *meta) r_init_fail: free(bytes); - for (i = meta->nreports ; i > 0 ; i--) { + for (i = meta->nreports; i > 0; i--) { hid_report_out_fini(&meta->reports[i - 1]); } @@ -215,11 +219,11 @@ static void hid_meta_out_init_lights(struct hid_meta_out *meta, HANDLE fd) pos = 0; - for (i = 0 ; i < meta->caps_tlc.NumberOutputButtonCaps ; i++) { + for (i = 0; i < meta->caps_tlc.NumberOutputButtonCaps; i++) { bc = &meta->caps_btn[i]; if (bc->IsRange) { - for (j = 0 ; j <= bc->Range.UsageMax - bc->Range.UsageMin ; j++) { + for (j = 0; j <= bc->Range.UsageMax - bc->Range.UsageMin; j++) { priv = &meta->priv_lights[pos]; priv->report = hid_meta_out_lookup_report(meta, bc->ReportID); @@ -233,10 +237,19 @@ static void hid_meta_out_init_lights(struct hid_meta_out *meta, HANDLE fd) light->value_max = 1; // Devices may specify their own strings for lights - if(bc->IsStringRange && bc->Range.StringMin != 0) { - HidD_GetIndexedString(fd, bc->Range.StringMin + j, light->name, sizeof(light->name)); - } else if(!bc->IsStringRange && bc->NotRange.StringIndex != 0) { - HidD_GetIndexedString(fd, bc->NotRange.StringIndex, light->name, sizeof(light->name)); + if (bc->IsStringRange && bc->Range.StringMin != 0) { + HidD_GetIndexedString( + fd, + bc->Range.StringMin + j, + light->name, + sizeof(light->name)); + } else if ( + !bc->IsStringRange && bc->NotRange.StringIndex != 0) { + HidD_GetIndexedString( + fd, + bc->NotRange.StringIndex, + light->name, + sizeof(light->name)); } pos++; @@ -254,19 +267,23 @@ static void hid_meta_out_init_lights(struct hid_meta_out *meta, HANDLE fd) light->value_min = 0; light->value_max = 1; - if(!bc->IsStringRange && bc->NotRange.StringIndex != 0) { - HidD_GetIndexedString(fd, bc->NotRange.StringIndex, light->name, sizeof(light->name)); + if (!bc->IsStringRange && bc->NotRange.StringIndex != 0) { + HidD_GetIndexedString( + fd, + bc->NotRange.StringIndex, + light->name, + sizeof(light->name)); } pos++; } } - for (i = 0 ; i < meta->caps_tlc.NumberOutputValueCaps ; i++) { + for (i = 0; i < meta->caps_tlc.NumberOutputValueCaps; i++) { vc = &meta->caps_val[i]; if (vc->IsRange) { - for (j = 0 ; j <= vc->Range.UsageMax - vc->Range.UsageMin ; j++) { + for (j = 0; j <= vc->Range.UsageMax - vc->Range.UsageMin; j++) { priv = &meta->priv_lights[pos]; priv->report = hid_meta_out_lookup_report(meta, vc->ReportID); @@ -280,10 +297,19 @@ static void hid_meta_out_init_lights(struct hid_meta_out *meta, HANDLE fd) light->value_max = vc->LogicalMax; // Devices may specify their own strings for lights - if(vc->IsStringRange && vc->Range.StringMin != 0) { - HidD_GetIndexedString(fd, vc->Range.StringMin + j, light->name, sizeof(light->name)); - } else if(!vc->IsStringRange && vc->NotRange.StringIndex != 0) { - HidD_GetIndexedString(fd, vc->NotRange.StringIndex, light->name, sizeof(light->name)); + if (vc->IsStringRange && vc->Range.StringMin != 0) { + HidD_GetIndexedString( + fd, + vc->Range.StringMin + j, + light->name, + sizeof(light->name)); + } else if ( + !vc->IsStringRange && vc->NotRange.StringIndex != 0) { + HidD_GetIndexedString( + fd, + vc->NotRange.StringIndex, + light->name, + sizeof(light->name)); } pos++; @@ -301,8 +327,12 @@ static void hid_meta_out_init_lights(struct hid_meta_out *meta, HANDLE fd) light->value_min = vc->LogicalMin; light->value_max = vc->LogicalMax; - if(!vc->IsStringRange && vc->NotRange.StringIndex != 0) { - HidD_GetIndexedString(fd, vc->NotRange.StringIndex, light->name, sizeof(light->name)); + if (!vc->IsStringRange && vc->NotRange.StringIndex != 0) { + HidD_GetIndexedString( + fd, + vc->NotRange.StringIndex, + light->name, + sizeof(light->name)); } pos++; @@ -310,12 +340,12 @@ static void hid_meta_out_init_lights(struct hid_meta_out *meta, HANDLE fd) } } -static struct hid_report_out *hid_meta_out_lookup_report( - struct hid_meta_out *meta, uint8_t report_id) +static struct hid_report_out * +hid_meta_out_lookup_report(struct hid_meta_out *meta, uint8_t report_id) { unsigned int i; - for (i = 0 ; i < meta->nreports ; i++) { + for (i = 0; i < meta->nreports; i++) { if (meta->reports[i].id == report_id) { return &meta->reports[i]; } @@ -329,8 +359,7 @@ size_t hid_meta_out_get_buffer_size(const struct hid_meta_out *meta) return meta->caps_tlc.OutputReportByteLength; } -const struct hid_light *hid_meta_out_get_lights( - const struct hid_meta_out *meta) +const struct hid_light *hid_meta_out_get_lights(const struct hid_meta_out *meta) { return meta->lights; } @@ -340,8 +369,8 @@ size_t hid_meta_out_get_nlights(const struct hid_meta_out *meta) return meta->nlights; } -bool hid_meta_out_set_light(struct hid_meta_out *meta, - size_t light_no, uint32_t intensity) +bool hid_meta_out_set_light( + struct hid_meta_out *meta, size_t light_no, uint32_t intensity) { struct hid_out_light *priv; uint32_t usage; @@ -354,11 +383,15 @@ bool hid_meta_out_set_light(struct hid_meta_out *meta, usage = meta->lights[light_no].usage; if (light_no < meta->nbuttons) { - return hid_report_out_set_bit(priv->report, meta->ppd, - priv->collection_id, usage, intensity != 0); + return hid_report_out_set_bit( + priv->report, + meta->ppd, + priv->collection_id, + usage, + intensity != 0); } else { - return hid_report_out_set_value(priv->report, meta->ppd, - priv->collection_id, usage, intensity); + return hid_report_out_set_value( + priv->report, meta->ppd, priv->collection_id, usage, intensity); } } @@ -387,7 +420,7 @@ static void hid_meta_out_fini_arrays(struct hid_meta_out *meta) free(meta->priv_lights); free(meta->lights); - for (i = 0 ; i < meta->nreports ; i++) { + for (i = 0; i < meta->nreports; i++) { hid_report_out_fini(&meta->reports[i]); } @@ -399,4 +432,3 @@ static void hid_meta_out_fini_caps(struct hid_meta_out *meta) free(meta->caps_btn); free(meta->caps_val); } - diff --git a/src/main/geninput/hid-meta-out.h b/src/main/geninput/hid-meta-out.h index b92be00..4e77f9c 100644 --- a/src/main/geninput/hid-meta-out.h +++ b/src/main/geninput/hid-meta-out.h @@ -1,15 +1,15 @@ #ifndef GENINPUT_HID_META_OUT_H #define GENINPUT_HID_META_OUT_H -#include #include +#include #include #include #include -#include "geninput/hid.h" #include "geninput/hid-report-out.h" +#include "geninput/hid.h" struct hid_out_light { struct hid_report_out *report; @@ -33,14 +33,15 @@ struct hid_meta_out { uint8_t next_report; }; -bool hid_meta_out_init(struct hid_meta_out *meta, PHIDP_PREPARSED_DATA ppd, HANDLE fd); +bool hid_meta_out_init( + struct hid_meta_out *meta, PHIDP_PREPARSED_DATA ppd, HANDLE fd); void hid_meta_out_get_next_report(struct hid_meta_out *meta, uint8_t *bytes); size_t hid_meta_out_get_buffer_size(const struct hid_meta_out *meta); -const struct hid_light *hid_meta_out_get_lights( - const struct hid_meta_out *meta); +const struct hid_light * +hid_meta_out_get_lights(const struct hid_meta_out *meta); size_t hid_meta_out_get_nlights(const struct hid_meta_out *meta); -bool hid_meta_out_set_light(struct hid_meta_out *meta, - size_t light_no, uint32_t intensity); +bool hid_meta_out_set_light( + struct hid_meta_out *meta, size_t light_no, uint32_t intensity); void hid_meta_out_fini(struct hid_meta_out *meta); #endif diff --git a/src/main/geninput/hid-mgr.c b/src/main/geninput/hid-mgr.c index aecd5df..f22d3a7 100644 --- a/src/main/geninput/hid-mgr.c +++ b/src/main/geninput/hid-mgr.c @@ -39,7 +39,7 @@ struct hid_stub *hid_mgr_get_named_stub(const char *dev_node) { struct hid_stub *pos; - for (pos = hid_stubs ; pos != NULL ; pos = pos->next) { + for (pos = hid_stubs; pos != NULL; pos = pos->next) { if (_stricmp(pos->dev_node, dev_node) == 0) { return pos; } @@ -71,7 +71,7 @@ void hid_mgr_fini(void) struct hid_stub *next; struct hid_stub *pos; - for (pos = hid_stubs ; pos != NULL ; pos = next) { + for (pos = hid_stubs; pos != NULL; pos = next) { next = pos->next; if (pos->hid != NULL) { @@ -124,30 +124,28 @@ bool hid_stub_get_device_usage(struct hid_stub *stub, uint32_t *usage) return false; } - return hid_stub_check(stub, - hid_get_device_usage(stub->hid, usage)); + return hid_stub_check(stub, hid_get_device_usage(stub->hid, usage)); } -bool hid_stub_get_controls(struct hid_stub *stub, struct hid_control *controls, - size_t *ncontrols) +bool hid_stub_get_controls( + struct hid_stub *stub, struct hid_control *controls, size_t *ncontrols) { if (stub->hid == NULL) { return false; } - return hid_stub_check(stub, - hid_get_controls(stub->hid, controls, ncontrols)); + return hid_stub_check( + stub, hid_get_controls(stub->hid, controls, ncontrols)); } -bool hid_stub_get_lights(struct hid_stub *stub, struct hid_light *lights, - size_t *nlights) +bool hid_stub_get_lights( + struct hid_stub *stub, struct hid_light *lights, size_t *nlights) { if (stub->hid == NULL) { return false; } - return hid_stub_check(stub, - hid_get_lights(stub->hid, lights, nlights)); + return hid_stub_check(stub, hid_get_lights(stub->hid, lights, nlights)); } const char *hid_stub_get_dev_node(struct hid_stub *stub) @@ -161,40 +159,38 @@ bool hid_stub_get_name(struct hid_stub *stub, wchar_t *chars, size_t *nchars) return false; } - return hid_stub_check(stub, - hid_get_name(stub->hid, chars, nchars)); + return hid_stub_check(stub, hid_get_name(stub->hid, chars, nchars)); } -bool hid_stub_get_value(struct hid_stub *stub, size_t control_no, - int32_t *out_value) +bool hid_stub_get_value( + struct hid_stub *stub, size_t control_no, int32_t *out_value) { if (stub->hid == NULL) { return false; } - return hid_stub_check(stub, - hid_get_value(stub->hid, control_no, out_value)); + return hid_stub_check( + stub, hid_get_value(stub->hid, control_no, out_value)); } -bool hid_stub_set_light(struct hid_stub *stub, size_t light_no, - uint32_t intensity) +bool hid_stub_set_light( + struct hid_stub *stub, size_t light_no, uint32_t intensity) { if (stub->hid == NULL) { return false; } - return hid_stub_check(stub, - hid_set_light(stub->hid, light_no, intensity)); + return hid_stub_check(stub, hid_set_light(stub->hid, light_no, intensity)); } -bool hid_stub_handle_completion(struct hid_stub *stub, OVERLAPPED *ovl, - size_t nbytes) +bool hid_stub_handle_completion( + struct hid_stub *stub, OVERLAPPED *ovl, size_t nbytes) { if (stub->hid == NULL) { return false; } - return hid_stub_check(stub, - hid_fd_handle_completion((struct hid_fd *) stub->hid, ovl, nbytes)); + return hid_stub_check( + stub, + hid_fd_handle_completion((struct hid_fd *) stub->hid, ovl, nbytes)); } - diff --git a/src/main/geninput/hid-mgr.h b/src/main/geninput/hid-mgr.h index 17afa0c..5410652 100644 --- a/src/main/geninput/hid-mgr.h +++ b/src/main/geninput/hid-mgr.h @@ -3,8 +3,8 @@ #include -#include #include +#include #include #include "geninput/hid.h" @@ -23,15 +23,15 @@ void hid_stub_detach(struct hid_stub *stub); bool hid_stub_get_name(struct hid_stub *stub, wchar_t *name, size_t *nchars); bool hid_stub_is_attached(struct hid_stub *stub); bool hid_stub_get_device_usage(struct hid_stub *stub, uint32_t *usage); -bool hid_stub_get_controls(struct hid_stub *stub, struct hid_control *controls, - size_t *ncontrols); -bool hid_stub_get_lights(struct hid_stub *stub, struct hid_light *lights, - size_t *nlights); -bool hid_stub_get_value(struct hid_stub *stub, size_t control_no, - int32_t *out_value); -bool hid_stub_set_light(struct hid_stub *stub, size_t light_no, - uint32_t intensity); -bool hid_stub_handle_completion(struct hid_stub *stub, OVERLAPPED *ovl, - size_t nbytes); +bool hid_stub_get_controls( + struct hid_stub *stub, struct hid_control *controls, size_t *ncontrols); +bool hid_stub_get_lights( + struct hid_stub *stub, struct hid_light *lights, size_t *nlights); +bool hid_stub_get_value( + struct hid_stub *stub, size_t control_no, int32_t *out_value); +bool hid_stub_set_light( + struct hid_stub *stub, size_t light_no, uint32_t intensity); +bool hid_stub_handle_completion( + struct hid_stub *stub, OVERLAPPED *ovl, size_t nbytes); #endif diff --git a/src/main/geninput/hid-report-in.c b/src/main/geninput/hid-report-in.c index 7efb387..f8e57a2 100644 --- a/src/main/geninput/hid-report-in.c +++ b/src/main/geninput/hid-report-in.c @@ -1,7 +1,7 @@ #define LOG_MODULE "hid-generic" -#include #include +#include #include #include @@ -12,9 +12,13 @@ #include "util/log.h" #include "util/mem.h" -void hid_report_in_init(struct hid_report_in *r, uint8_t report_id, - uint32_t nbuttons, void *bytes, size_t nbytes, - PHIDP_PREPARSED_DATA ppd) +void hid_report_in_init( + struct hid_report_in *r, + uint8_t report_id, + uint32_t nbuttons, + void *bytes, + size_t nbytes, + PHIDP_PREPARSED_DATA ppd) { r->id = report_id; r->nbuttons = nbuttons; @@ -22,8 +26,8 @@ void hid_report_in_init(struct hid_report_in *r, uint8_t report_id, r->bytes = bytes; r->nbytes = nbytes; - if (HidP_InitializeReportForID(HidP_Input, report_id, ppd, bytes, nbytes) - != HIDP_STATUS_SUCCESS) { + if (HidP_InitializeReportForID(HidP_Input, report_id, ppd, bytes, nbytes) != + HIDP_STATUS_SUCCESS) { log_warning("Error initializing IN report %02X", report_id); } } @@ -33,8 +37,8 @@ uint8_t hid_report_in_get_id(struct hid_report_in *r) return r->id; } -bool hid_report_in_exchange(struct hid_report_in *r, uint8_t **bytes, - uint32_t nbytes) +bool hid_report_in_exchange( + struct hid_report_in *r, uint8_t **bytes, uint32_t nbytes) { uint8_t *last_bytes; @@ -48,28 +52,39 @@ bool hid_report_in_exchange(struct hid_report_in *r, uint8_t **bytes, return true; } -bool hid_report_in_get_bit(struct hid_report_in *r, PHIDP_PREPARSED_DATA ppd, - uint16_t collection_id, uint32_t usage, int32_t *value) +bool hid_report_in_get_bit( + struct hid_report_in *r, + PHIDP_PREPARSED_DATA ppd, + uint16_t collection_id, + uint32_t usage, + int32_t *value) { unsigned long i; unsigned long nbuttons; NTSTATUS result; nbuttons = r->nbuttons; - result = HidP_GetUsagesEx(HidP_Input, collection_id, - (USAGE_AND_PAGE *) r->buttons, &nbuttons, ppd, (PCHAR) r->bytes, - (unsigned long) r->nbytes); + result = HidP_GetUsagesEx( + HidP_Input, + collection_id, + (USAGE_AND_PAGE *) r->buttons, + &nbuttons, + ppd, + (PCHAR) r->bytes, + (unsigned long) r->nbytes); if (result != HIDP_STATUS_SUCCESS) { - log_warning("HidP_GetUsagesEx failed for report %02X: %08x", - r->id, (unsigned int) result); + log_warning( + "HidP_GetUsagesEx failed for report %02X: %08x", + r->id, + (unsigned int) result); return false; } *value = 0; - for (i = 0 ; i < nbuttons ; i++) { + for (i = 0; i < nbuttons; i++) { if (r->buttons[i] == usage) { *value = 1; } @@ -78,8 +93,12 @@ bool hid_report_in_get_bit(struct hid_report_in *r, PHIDP_PREPARSED_DATA ppd, return true; } -bool hid_report_in_get_value(struct hid_report_in *r, PHIDP_PREPARSED_DATA ppd, - uint16_t collection_id, uint32_t usage, int32_t *value) +bool hid_report_in_get_value( + struct hid_report_in *r, + PHIDP_PREPARSED_DATA ppd, + uint16_t collection_id, + uint32_t usage, + int32_t *value) { NTSTATUS result; @@ -89,12 +108,22 @@ bool hid_report_in_get_value(struct hid_report_in *r, PHIDP_PREPARSED_DATA ppd, return false; } - result = HidP_GetUsageValue(HidP_Input, usage >> 16, 0, (uint16_t) usage, - (unsigned long *) value, ppd, (PCHAR) r->bytes, r->nbytes); + result = HidP_GetUsageValue( + HidP_Input, + usage >> 16, + 0, + (uint16_t) usage, + (unsigned long *) value, + ppd, + (PCHAR) r->bytes, + r->nbytes); if (result != HIDP_STATUS_SUCCESS) { - log_warning("HidP_GetUsageValue(%08x) failed for report %02X: %08x", - usage, r->id, (unsigned int) result); + log_warning( + "HidP_GetUsageValue(%08x) failed for report %02X: %08x", + usage, + r->id, + (unsigned int) result); return false; } @@ -107,4 +136,3 @@ void hid_report_in_fini(struct hid_report_in *r) free(r->buttons); free(r->bytes); } - diff --git a/src/main/geninput/hid-report-in.h b/src/main/geninput/hid-report-in.h index 1630c12..d19c60f 100644 --- a/src/main/geninput/hid-report-in.h +++ b/src/main/geninput/hid-report-in.h @@ -1,9 +1,9 @@ #ifndef GENINPUT_HID_REPORT_IN_H #define GENINPUT_HID_REPORT_IN_H -#include #include #include +#include #include @@ -15,16 +15,28 @@ struct hid_report_in { uint32_t nbytes; }; -void hid_report_in_init(struct hid_report_in *r, uint8_t report_id, - uint32_t nbuttons, void *bytes, size_t nbytes, - PHIDP_PREPARSED_DATA ppd); +void hid_report_in_init( + struct hid_report_in *r, + uint8_t report_id, + uint32_t nbuttons, + void *bytes, + size_t nbytes, + PHIDP_PREPARSED_DATA ppd); uint8_t hid_report_in_get_id(struct hid_report_in *r); -bool hid_report_in_exchange(struct hid_report_in *r, uint8_t **bytes, - uint32_t nbytes); -bool hid_report_in_get_bit(struct hid_report_in *r, PHIDP_PREPARSED_DATA ppd, - uint16_t collection_id, uint32_t usage, int32_t *value); -bool hid_report_in_get_value(struct hid_report_in *r, PHIDP_PREPARSED_DATA ppd, - uint16_t collection_id, uint32_t usage, int32_t *value); +bool hid_report_in_exchange( + struct hid_report_in *r, uint8_t **bytes, uint32_t nbytes); +bool hid_report_in_get_bit( + struct hid_report_in *r, + PHIDP_PREPARSED_DATA ppd, + uint16_t collection_id, + uint32_t usage, + int32_t *value); +bool hid_report_in_get_value( + struct hid_report_in *r, + PHIDP_PREPARSED_DATA ppd, + uint16_t collection_id, + uint32_t usage, + int32_t *value); void hid_report_in_fini(struct hid_report_in *r); #endif diff --git a/src/main/geninput/hid-report-out.c b/src/main/geninput/hid-report-out.c index a9b7602..13d3ca2 100644 --- a/src/main/geninput/hid-report-out.c +++ b/src/main/geninput/hid-report-out.c @@ -1,7 +1,7 @@ #define LOG_MODULE "hid-generic" -#include #include +#include #include #include @@ -13,8 +13,11 @@ #include "util/log.h" #include "util/mem.h" -bool hid_report_out_init(struct hid_report_out *r, PHIDP_PREPARSED_DATA ppd, - uint8_t id, size_t nbytes) +bool hid_report_out_init( + struct hid_report_out *r, + PHIDP_PREPARSED_DATA ppd, + uint8_t id, + size_t nbytes) { NTSTATUS status; @@ -22,12 +25,14 @@ bool hid_report_out_init(struct hid_report_out *r, PHIDP_PREPARSED_DATA ppd, r->nbytes = nbytes; r->bytes = xmalloc(nbytes); - status = HidP_InitializeReportForID(HidP_Output, r->id, ppd, - (PCHAR) r->bytes, r->nbytes); + status = HidP_InitializeReportForID( + HidP_Output, r->id, ppd, (PCHAR) r->bytes, r->nbytes); if (status != HIDP_STATUS_SUCCESS) { - log_warning("Report %02X: HidP_InitializeReportForID failed: %08x", - id, (unsigned int) status); + log_warning( + "Report %02X: HidP_InitializeReportForID failed: %08x", + id, + (unsigned int) status); goto fail; } @@ -45,22 +50,32 @@ void hid_report_out_get_bytes(const struct hid_report_out *r, uint8_t *bytes) memcpy(bytes, r->bytes, r->nbytes); } -bool hid_report_out_set_bit(struct hid_report_out *r, - PHIDP_PREPARSED_DATA ppd, uint16_t collection_id, uint32_t usage, - bool value) +bool hid_report_out_set_bit( + struct hid_report_out *r, + PHIDP_PREPARSED_DATA ppd, + uint16_t collection_id, + uint32_t usage, + bool value) { NTSTATUS status; unsigned long count; uint16_t usage_hi; uint16_t usage_lo; - usage_hi = (uint16_t) (usage >> 16); - usage_lo = (uint16_t) (usage >> 0); + usage_hi = (uint16_t)(usage >> 16); + usage_lo = (uint16_t)(usage >> 0); count = 1; - if (value) { - status = HidP_SetUsages(HidP_Output, usage_hi, collection_id, - &usage_lo, &count, ppd, (PCHAR) r->bytes, r->nbytes); + if (value) { + status = HidP_SetUsages( + HidP_Output, + usage_hi, + collection_id, + &usage_lo, + &count, + ppd, + (PCHAR) r->bytes, + r->nbytes); if (status != HIDP_STATUS_SUCCESS) { log_warning("HidP_SetUsages failed: %08x", (unsigned int) status); @@ -68,11 +83,18 @@ bool hid_report_out_set_bit(struct hid_report_out *r, return false; } } else { - status = HidP_UnsetUsages(HidP_Output, usage_hi, collection_id, - &usage_lo, &count, ppd, (PCHAR) r->bytes, r->nbytes); + status = HidP_UnsetUsages( + HidP_Output, + usage_hi, + collection_id, + &usage_lo, + &count, + ppd, + (PCHAR) r->bytes, + r->nbytes); - if (status != HIDP_STATUS_SUCCESS - && status != HIDP_STATUS_BUTTON_NOT_PRESSED /* jfc */) { + if (status != HIDP_STATUS_SUCCESS && + status != HIDP_STATUS_BUTTON_NOT_PRESSED /* jfc */) { log_warning("HidP_UnsetUsages failed: %08x", (unsigned int) status); return false; @@ -82,19 +104,29 @@ bool hid_report_out_set_bit(struct hid_report_out *r, return true; } -bool hid_report_out_set_value(struct hid_report_out *r, - PHIDP_PREPARSED_DATA ppd, uint16_t collection_id, uint32_t usage, - uint32_t value) +bool hid_report_out_set_value( + struct hid_report_out *r, + PHIDP_PREPARSED_DATA ppd, + uint16_t collection_id, + uint32_t usage, + uint32_t value) { NTSTATUS status; uint16_t usage_hi; uint16_t usage_lo; - usage_hi = (uint16_t) (usage >> 16); - usage_lo = (uint16_t) (usage >> 0); + usage_hi = (uint16_t)(usage >> 16); + usage_lo = (uint16_t)(usage >> 0); - status = HidP_SetUsageValue(HidP_Output, usage_hi, collection_id, - usage_lo, value, ppd, (PCHAR) r->bytes, r->nbytes); + status = HidP_SetUsageValue( + HidP_Output, + usage_hi, + collection_id, + usage_lo, + value, + ppd, + (PCHAR) r->bytes, + r->nbytes); if (status != HIDP_STATUS_SUCCESS) { log_warning("HidP_SetUsages failed: %08x", (unsigned int) status); @@ -109,4 +141,3 @@ void hid_report_out_fini(struct hid_report_out *r) { free(r->bytes); } - diff --git a/src/main/geninput/hid-report-out.h b/src/main/geninput/hid-report-out.h index f25dbb0..1ba1e1f 100644 --- a/src/main/geninput/hid-report-out.h +++ b/src/main/geninput/hid-report-out.h @@ -1,8 +1,8 @@ #ifndef GENINPUT_HID_REPORT_OUT_H #define GENINPUT_HID_REPORT_OUT_H -#include #include +#include #include #include @@ -13,15 +13,24 @@ struct hid_report_out { size_t nbytes; }; -bool hid_report_out_init(struct hid_report_out *r, PHIDP_PREPARSED_DATA ppd, - uint8_t id, size_t nbytes); +bool hid_report_out_init( + struct hid_report_out *r, + PHIDP_PREPARSED_DATA ppd, + uint8_t id, + size_t nbytes); void hid_report_out_get_bytes(const struct hid_report_out *r, uint8_t *bytes); -bool hid_report_out_set_bit(struct hid_report_out *r, - PHIDP_PREPARSED_DATA ppd, uint16_t collection_id, uint32_t usage, - bool value); -bool hid_report_out_set_value(struct hid_report_out *r, - PHIDP_PREPARSED_DATA ppd, uint16_t collection_id, uint32_t usage, - uint32_t value); +bool hid_report_out_set_bit( + struct hid_report_out *r, + PHIDP_PREPARSED_DATA ppd, + uint16_t collection_id, + uint32_t usage, + bool value); +bool hid_report_out_set_value( + struct hid_report_out *r, + PHIDP_PREPARSED_DATA ppd, + uint16_t collection_id, + uint32_t usage, + uint32_t value); void hid_report_out_fini(struct hid_report_out *r); #endif diff --git a/src/main/geninput/hid.c b/src/main/geninput/hid.c index e51a6ee..57685b0 100644 --- a/src/main/geninput/hid.c +++ b/src/main/geninput/hid.c @@ -55,8 +55,11 @@ bool hid_ri_get_name(wchar_t *chars, size_t *nchars, const wchar_t *src_chars) } } -bool hid_ri_get_controls(struct hid_control *controls, size_t *ncontrols, - const struct hid_control *src_controls, size_t src_ncontrols) +bool hid_ri_get_controls( + struct hid_control *controls, + size_t *ncontrols, + const struct hid_control *src_controls, + size_t src_ncontrols) { log_assert(ncontrols != NULL); @@ -74,4 +77,3 @@ bool hid_ri_get_controls(struct hid_control *controls, size_t *ncontrols, return false; } } - diff --git a/src/main/geninput/hid.h b/src/main/geninput/hid.h index 371122d..36996cb 100644 --- a/src/main/geninput/hid.h +++ b/src/main/geninput/hid.h @@ -8,11 +8,22 @@ #include -#define HID_FLAG_NULLABLE 0x01 -#define HID_FLAG_RELATIVE 0x02 +#define HID_FLAG_NULLABLE 0x01 +#define HID_FLAG_RELATIVE 0x02 -DEFINE_GUID(hid_guid, 0x4D1E55B2L, 0xF16F, 0x11CF, 0x88, 0xCB, 0x00, \ - 0x11, 0x11, 0x00, 0x00, 0x30); +DEFINE_GUID( + hid_guid, + 0x4D1E55B2L, + 0xF16F, + 0x11CF, + 0x88, + 0xCB, + 0x00, + 0x11, + 0x11, + 0x00, + 0x00, + 0x30); /* Alright, I'd take the vtable stuff from C++, because this is just gross. But you can keep everything else from that trainwreck of a language. */ @@ -44,10 +55,10 @@ struct hid_vtbl { void (*close)(struct hid *hid); bool (*get_device_usage)(const struct hid *hid, uint32_t *usage); bool (*get_name)(const struct hid *hid, wchar_t *chars, size_t *nchars); - bool (*get_controls)(const struct hid *hid, struct hid_control *controls, - size_t *ncontrols); - bool (*get_lights)(const struct hid *hid, struct hid_light *lights, - size_t *nlights); + bool (*get_controls)( + const struct hid *hid, struct hid_control *controls, size_t *ncontrols); + bool (*get_lights)( + const struct hid *hid, struct hid_light *lights, size_t *nlights); bool (*get_value)(struct hid *hid, size_t control_no, int32_t *out_value); bool (*set_light)(struct hid *hid, size_t light_no, uint32_t intensity); }; @@ -56,8 +67,7 @@ struct hid { const struct hid_vtbl *vptr; }; -#define hid_close(hid) \ - (hid)->vptr->close(hid) +#define hid_close(hid) (hid)->vptr->close(hid) #define hid_get_device_usage(hid, usage) \ (hid)->vptr->get_device_usage(hid, usage) @@ -89,20 +99,21 @@ struct hid_ri { }; wchar_t *hid_ri_init_name(const GUID *class_guid, const char *dev_node); -bool hid_ri_get_name(wchar_t *chars, size_t *nchars, - const wchar_t *src_chars); -bool hid_ri_get_controls(struct hid_control *controls, size_t *ncontrols, - const struct hid_control *src_controls, size_t src_ncontrols); +bool hid_ri_get_name(wchar_t *chars, size_t *nchars, const wchar_t *src_chars); +bool hid_ri_get_controls( + struct hid_control *controls, + size_t *ncontrols, + const struct hid_control *src_controls, + size_t src_ncontrols); -#define hid_ri_handle_event(hid_ri, ri) \ - (hid_ri)->vptr->handle_event(hid_ri, ri) +#define hid_ri_handle_event(hid_ri, ri) (hid_ri)->vptr->handle_event(hid_ri, ri) struct hid_fd; struct hid_fd_vtbl { struct hid_vtbl super; - bool (*handle_completion)(struct hid_fd *hid, OVERLAPPED *ovl, - size_t nbytes); + bool (*handle_completion)( + struct hid_fd *hid, OVERLAPPED *ovl, size_t nbytes); }; struct hid_fd { @@ -110,6 +121,6 @@ struct hid_fd { }; #define hid_fd_handle_completion(hid_fd, ovl, nbytes) \ - (hid_fd)->vptr->handle_completion(hid_fd, ovl, nbytes) + (hid_fd)->vptr->handle_completion(hid_fd, ovl, nbytes) #endif diff --git a/src/main/geninput/hotplug.c b/src/main/geninput/hotplug.c index f466a2c..5a32f65 100644 --- a/src/main/geninput/hotplug.c +++ b/src/main/geninput/hotplug.c @@ -1,5 +1,5 @@ -#include #include +#include #include @@ -21,12 +21,13 @@ void hotplug_init(HWND wnd) filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; filter.dbcc_classguid = hid_guid; - hotplug_handle = RegisterDeviceNotification(wnd, &filter, - DEVICE_NOTIFY_WINDOW_HANDLE); + hotplug_handle = + RegisterDeviceNotification(wnd, &filter, DEVICE_NOTIFY_WINDOW_HANDLE); if (hotplug_handle == NULL) { - log_fatal("Failed to register for HID hotplug notifications: %08x", - (unsigned int) GetLastError()); + log_fatal( + "Failed to register for HID hotplug notifications: %08x", + (unsigned int) GetLastError()); } } @@ -60,8 +61,8 @@ void hotplug_fini(void) ok = UnregisterDeviceNotification(hotplug_handle); if (!ok) { - log_warning("Failed to unregister HID hotplug notifications: %08x", - (unsigned int) GetLastError()); + log_warning( + "Failed to unregister HID hotplug notifications: %08x", + (unsigned int) GetLastError()); } } - diff --git a/src/main/geninput/hotplug.h b/src/main/geninput/hotplug.h index db09c21..e0aa137 100644 --- a/src/main/geninput/hotplug.h +++ b/src/main/geninput/hotplug.h @@ -1,8 +1,8 @@ #ifndef GENINPUT_HOTPLUG_H #define GENINPUT_HOTPLUG_H -#include #include +#include void hotplug_init(HWND wnd); void hotplug_handle_msg(WPARAM wparam, const DEV_BROADCAST_HDR *hdr); diff --git a/src/main/geninput/input-config.h b/src/main/geninput/input-config.h index b9c7536..aabd712 100644 --- a/src/main/geninput/input-config.h +++ b/src/main/geninput/input-config.h @@ -11,8 +11,8 @@ void mapper_config_save(const char *game_type); void mapper_clear_action_map(uint8_t action, uint8_t page); void mapper_clear_light_map(const struct mapped_light *ml); -bool mapper_get_action_map(uint8_t action, uint8_t page, - struct mapped_action *ma); +bool mapper_get_action_map( + uint8_t action, uint8_t page, struct mapped_action *ma); bool mapper_get_analog_map(uint8_t analog, struct mapped_analog *ma); int32_t mapper_get_analog_sensitivity(uint8_t analog); uint8_t mapper_get_nanalogs(void); @@ -20,8 +20,8 @@ uint8_t mapper_get_npages(void); bool mapper_is_analog_absolute(uint8_t analog); action_iter_t mapper_iterate_actions(void); light_iter_t mapper_iterate_lights(void); -void mapper_set_action_map(uint8_t action, uint8_t page, uint8_t bit, - const struct mapped_action *ma); +void mapper_set_action_map( + uint8_t action, uint8_t page, uint8_t bit, const struct mapped_action *ma); bool mapper_set_analog_map(uint8_t analog, const struct mapped_analog *ma); bool mapper_set_analog_sensitivity(uint8_t analog, int32_t sensitivity); void mapper_set_nanalogs(uint8_t nanalogs); diff --git a/src/main/geninput/input.c b/src/main/geninput/input.c index 8f855a1..c051e74 100644 --- a/src/main/geninput/input.c +++ b/src/main/geninput/input.c @@ -7,11 +7,11 @@ #include "bemanitools/glue.h" #include "bemanitools/input.h" -#include "geninput/hid.h" #include "geninput/hid-mgr.h" +#include "geninput/hid.h" #include "geninput/io-thread.h" -#include "geninput/mapper.h" #include "geninput/mapper-s11n.h" +#include "geninput/mapper.h" #include "util/fs.h" #include "util/log.h" @@ -31,14 +31,17 @@ static FILE *mapper_config_open(const char *game_type, const char *mode) return fopen_appdata("DJHACKERS", path, mode); } -void input_set_loggers(log_formatter_t misc, log_formatter_t info, - log_formatter_t warning, log_formatter_t fatal) +void input_set_loggers( + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal) { log_to_external(misc, info, warning, fatal); } -void input_init(thread_create_t create, thread_join_t join, - thread_destroy_t destroy) +void input_init( + thread_create_t create, thread_join_t join, thread_destroy_t destroy) { if (InterlockedIncrement(&input_init_count) != 1) { return; @@ -125,8 +128,8 @@ void mapper_clear_light_map(const struct mapped_light *ml) mapper_impl_clear_light_map(mapper_inst, ml); } -bool mapper_get_action_map(uint8_t action, uint8_t page, - struct mapped_action *ma) +bool mapper_get_action_map( + uint8_t action, uint8_t page, struct mapped_action *ma) { return mapper_impl_get_action_map(mapper_inst, action, page, ma); } @@ -166,8 +169,8 @@ light_iter_t mapper_iterate_lights(void) return mapper_impl_iterate_lights(mapper_inst); } -void mapper_set_action_map(uint8_t action, uint8_t page, uint8_t bit, - const struct mapped_action *ma) +void mapper_set_action_map( + uint8_t action, uint8_t page, uint8_t bit, const struct mapped_action *ma) { mapper_impl_set_action_map(mapper_inst, action, page, bit, ma); } @@ -220,4 +223,3 @@ BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, void *ctx) return TRUE; } - diff --git a/src/main/geninput/io-thread.c b/src/main/geninput/io-thread.c index 51ad52b..ca663ff 100644 --- a/src/main/geninput/io-thread.c +++ b/src/main/geninput/io-thread.c @@ -3,9 +3,9 @@ #include #include "geninput/dev-list.h" -#include "geninput/hid.h" #include "geninput/hid-generic.h" #include "geninput/hid-mgr.h" +#include "geninput/hid.h" #include "geninput/io-thread.h" #include "geninput/pacdrive.h" @@ -47,8 +47,8 @@ static void io_thread_proc_add_device(const char *dev_node) if (!hid_stub_is_attached(stub)) { ctx = (uintptr_t) stub; - if (pac_open(&hid_fd, dev_node, io_thread_cp, ctx) - || hid_generic_open(&hid_fd, dev_node, io_thread_cp, ctx)) { + if (pac_open(&hid_fd, dev_node, io_thread_cp, ctx) || + hid_generic_open(&hid_fd, dev_node, io_thread_cp, ctx)) { hid_stub_attach(stub, (struct hid *) hid_fd); } } @@ -74,8 +74,9 @@ static void io_thread_proc_init(void) SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); - log_info("USB I/O thread ready, thread id = %d", - (unsigned int) GetCurrentThreadId()); + log_info( + "USB I/O thread ready, thread id = %d", + (unsigned int) GetCurrentThreadId()); } static void io_thread_proc_main_loop(void) @@ -88,8 +89,8 @@ static void io_thread_proc_main_loop(void) BOOL ok; for (;;) { - ok = GetQueuedCompletionStatus(io_thread_cp, &nbytes, - (ULONG_PTR *) &ctx, &p_ovl, 0); + ok = GetQueuedCompletionStatus( + io_thread_cp, &nbytes, (ULONG_PTR *) &ctx, &p_ovl, 0); if (p_ovl != NULL) { /* An I/O completed (depending on the value of `ok' either @@ -100,8 +101,9 @@ static void io_thread_proc_main_loop(void) hid_mgr_lock(); if (!ok) { - log_warning("Async IO returned failure: %08x", - (unsigned int) GetLastError()); + log_warning( + "Async IO returned failure: %08x", + (unsigned int) GetLastError()); hid_stub_detach(stub); } else { ok = hid_stub_handle_completion(stub, p_ovl, nbytes); @@ -133,8 +135,9 @@ static void io_thread_proc_main_loop(void) } else { /* Otherwise idk what's going on */ - log_warning("Spurious wakeup in I/O mux: %08x", - (unsigned int) GetLastError()); + log_warning( + "Spurious wakeup in I/O mux: %08x", + (unsigned int) GetLastError()); } } } @@ -169,8 +172,7 @@ void io_thread_init(void) barrier = CreateEvent(NULL, TRUE, FALSE, NULL); - io_thread_id = thread_create(io_thread_proc, barrier, - 16384, 0); + io_thread_id = thread_create(io_thread_proc, barrier, 16384, 0); WaitForSingleObject(barrier, INFINITE); CloseHandle(barrier); @@ -201,4 +203,3 @@ void io_thread_fini(void) thread_join(io_thread_id, NULL); thread_destroy(io_thread_id); } - diff --git a/src/main/geninput/kbd-data.c b/src/main/geninput/kbd-data.c index ecaf0e9..aaec24e 100644 --- a/src/main/geninput/kbd-data.c +++ b/src/main/geninput/kbd-data.c @@ -5,51 +5,37 @@ const size_t kbd_basic_nusages = 243; const size_t kbd_ext_nusages = 100; const uint8_t kbd_basic_usages[] = { - 0x00, 0x29, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, - 0x24, 0x25, 0x26, 0x27, 0x2d, 0x2e, 0x2a, 0x2b, - 0x14, 0x1a, 0x08, 0x15, 0x17, 0x1c, 0x18, 0x0c, - 0x12, 0x13, 0x2f, 0x30, 0x28, 0xe0, 0x04, 0x16, - 0x07, 0x09, 0x0a, 0x0b, 0x0d, 0x0e, 0x0f, 0x33, - 0x34, 0x35, 0xe1, 0x32, 0x1d, 0x1b, 0x06, 0x19, - 0x05, 0x11, 0x10, 0x36, 0x37, 0x38, 0xe5, 0x55, - 0xe2, 0x2c, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, - 0x3f, 0x40, 0x41, 0x42, 0x43, 0x53, 0x47, 0x5f, - 0x60, 0x61, 0x56, 0x5c, 0x5d, 0x5e, 0x57, 0x59, - 0x5a, 0x5b, 0x62, 0x63, 0x00, 0x00, 0x64, 0x44, - 0x45, 0x67, 0x00, 0x00, 0x8c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x68, 0x69, 0x6a, 0x6b, - 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x00, - 0x88, 0x00, 0x00, 0x87, 0x00, 0x00, 0x94, 0x93, - 0x92, 0x8a, 0x00, 0x8b, 0x00, 0x89, 0x85, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x29, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x2d, 0x2e, 0x2a, 0x2b, 0x14, 0x1a, 0x08, 0x15, 0x17, 0x1c, 0x18, 0x0c, + 0x12, 0x13, 0x2f, 0x30, 0x28, 0xe0, 0x04, 0x16, 0x07, 0x09, 0x0a, 0x0b, + 0x0d, 0x0e, 0x0f, 0x33, 0x34, 0x35, 0xe1, 0x32, 0x1d, 0x1b, 0x06, 0x19, + 0x05, 0x11, 0x10, 0x36, 0x37, 0x38, 0xe5, 0x55, 0xe2, 0x2c, 0x39, 0x3a, + 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x53, 0x47, 0x5f, + 0x60, 0x61, 0x56, 0x5c, 0x5d, 0x5e, 0x57, 0x59, 0x5a, 0x5b, 0x62, 0x63, + 0x00, 0x00, 0x64, 0x44, 0x45, 0x67, 0x00, 0x00, 0x8c, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, + 0x70, 0x71, 0x72, 0x00, 0x88, 0x00, 0x00, 0x87, 0x00, 0x00, 0x94, 0x93, + 0x92, 0x8a, 0x00, 0x8b, 0x00, 0x89, 0x85, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x91, 0x90, }; const uint8_t kbd_ext_usages[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x58, 0xe4, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x00, 0x46, - 0xe6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, - 0x52, 0x4b, 0x00, 0x50, 0x00, 0x4f, 0x00, 0x4d, - 0x51, 0x4e, 0x49, 0x4c, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xe3, 0xe7, 0x65, 0xe9, 0xea, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x58, 0xe4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x00, 0x46, 0xe6, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, + 0x52, 0x4b, 0x00, 0x50, 0x00, 0x4f, 0x00, 0x4d, 0x51, 0x4e, 0x49, 0x4c, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe3, 0xe7, 0x65, 0xe9, 0xea, 0x00, 0x00, 0x00, 0xeb, }; diff --git a/src/main/geninput/kbd.c b/src/main/geninput/kbd.c index ebb82bf..8d7dc04 100644 --- a/src/main/geninput/kbd.c +++ b/src/main/geninput/kbd.c @@ -1,56 +1,61 @@ #define LOG_MODULE "kbd" -#include #include #include +#include #include #include #include #include "geninput/hid.h" -#include "geninput/kbd.h" #include "geninput/kbd-data.h" +#include "geninput/kbd.h" #include "util/defs.h" #include "util/log.h" #include "util/mem.h" #include "util/str.h" -DEFINE_GUID(kbd_guid, - 0x884B96C3, - 0x56EF, - 0x11D1, - 0xBC, 0x8C, 0x00, 0xA0, 0xC9, 0x14, 0x05, 0xDD); +DEFINE_GUID( + kbd_guid, + 0x884B96C3, + 0x56EF, + 0x11D1, + 0xBC, + 0x8C, + 0x00, + 0xA0, + 0xC9, + 0x14, + 0x05, + 0xDD); static struct hid_control kbd_controls[512]; static size_t kbd_ncontrols; static void kbd_static_init(void); static bool kbd_get_device_usage(const struct hid *hid, uint32_t *usage); -static bool kbd_get_name(const struct hid *hid, wchar_t *chars, - size_t *nchars); -static bool kbd_get_controls(const struct hid *hid, - struct hid_control *controls, size_t *ncontrols); -static bool kbd_get_lights(const struct hid *hid, - struct hid_light *lights, size_t *nlights); -static bool kbd_get_value(struct hid *hid, size_t control_no, - int32_t *out_value); -static bool kbd_set_light(struct hid *hid, size_t light_no, - uint32_t intensity); +static bool kbd_get_name(const struct hid *hid, wchar_t *chars, size_t *nchars); +static bool kbd_get_controls( + const struct hid *hid, struct hid_control *controls, size_t *ncontrols); +static bool kbd_get_lights( + const struct hid *hid, struct hid_light *lights, size_t *nlights); +static bool +kbd_get_value(struct hid *hid, size_t control_no, int32_t *out_value); +static bool kbd_set_light(struct hid *hid, size_t light_no, uint32_t intensity); static void kbd_handle_event(struct hid_ri *hid_ri, const RAWINPUT *ri); static void kbd_free(struct hid *hid); -static const struct hid_ri_vtbl kbd_vtbl = {{ - /* .free = */ kbd_free, - /* .get_device_usage = */ kbd_get_device_usage, - /* .get_name = */ kbd_get_name, - /* .get_controls = */ kbd_get_controls, - /* .get_lights = */ kbd_get_lights, - /* .get_value = */ kbd_get_value, - /* .set_light = */ kbd_set_light }, - /* .handle_event = */ kbd_handle_event -}; +static const struct hid_ri_vtbl kbd_vtbl = { + {/* .free = */ kbd_free, + /* .get_device_usage = */ kbd_get_device_usage, + /* .get_name = */ kbd_get_name, + /* .get_controls = */ kbd_get_controls, + /* .get_lights = */ kbd_get_lights, + /* .get_value = */ kbd_get_value, + /* .set_light = */ kbd_set_light}, + /* .handle_event = */ kbd_handle_event}; struct kbd { struct hid_ri super; @@ -66,7 +71,7 @@ static void kbd_static_init(void) if (kbd_ncontrols == 0) { kbd_ncontrols = kbd_basic_nusages + kbd_ext_nusages; - for (i = 0 ; i < kbd_ncontrols ; i++) { + for (i = 0; i < kbd_ncontrols; i++) { if (i < kbd_basic_nusages) { code = kbd_basic_usages[i]; } else { @@ -113,23 +118,22 @@ static bool kbd_get_device_usage(const struct hid *hid, uint32_t *usage) return true; } -static bool kbd_get_name(const struct hid *hid, wchar_t *chars, - size_t *nchars) +static bool kbd_get_name(const struct hid *hid, wchar_t *chars, size_t *nchars) { struct kbd *kbd = containerof(hid, struct kbd, super); return hid_ri_get_name(chars, nchars, kbd->name); } -static bool kbd_get_controls(const struct hid *hid, - struct hid_control *controls, size_t *ncontrols) +static bool kbd_get_controls( + const struct hid *hid, struct hid_control *controls, size_t *ncontrols) { - return hid_ri_get_controls(controls, ncontrols, kbd_controls, - kbd_ncontrols); + return hid_ri_get_controls( + controls, ncontrols, kbd_controls, kbd_ncontrols); } -static bool kbd_get_lights(const struct hid *hid, - struct hid_light *lights, size_t *nlights) +static bool +kbd_get_lights(const struct hid *hid, struct hid_light *lights, size_t *nlights) { log_assert(nlights != NULL); @@ -138,8 +142,8 @@ static bool kbd_get_lights(const struct hid *hid, return true; } -static bool kbd_get_value(struct hid *hid, size_t control_no, - int32_t *out_value) +static bool +kbd_get_value(struct hid *hid, size_t control_no, int32_t *out_value) { struct kbd *kbd = containerof(hid, struct kbd, super); @@ -150,8 +154,7 @@ static bool kbd_get_value(struct hid *hid, size_t control_no, return true; } -static bool kbd_set_light(struct hid *hid, size_t light_no, - uint32_t intensity) +static bool kbd_set_light(struct hid *hid, size_t light_no, uint32_t intensity) { return false; } @@ -181,4 +184,3 @@ static void kbd_free(struct hid *hid) free(kbd->name); free(kbd); } - diff --git a/src/main/geninput/kbd.h b/src/main/geninput/kbd.h index 56d13dd..f54f26d 100644 --- a/src/main/geninput/kbd.h +++ b/src/main/geninput/kbd.h @@ -3,8 +3,8 @@ #include "geninput/hid.h" -#define KBD_DEVICE_USAGE_KEYBOARD 0x00010006 -#define KBD_DEVICE_USAGE_KEYPAD 0x00010007 +#define KBD_DEVICE_USAGE_KEYBOARD 0x00010006 +#define KBD_DEVICE_USAGE_KEYPAD 0x00010007 void kbd_create(struct hid_ri **hid_ri, const char *dev_node); diff --git a/src/main/geninput/mapper-s11n.c b/src/main/geninput/mapper-s11n.c index 611a7fe..06b5d39 100644 --- a/src/main/geninput/mapper-s11n.c +++ b/src/main/geninput/mapper-s11n.c @@ -1,7 +1,7 @@ #include -#include "geninput/mapper.h" #include "geninput/mapper-s11n.h" +#include "geninput/mapper.h" #include "util/fs.h" #include "util/mem.h" @@ -21,9 +21,9 @@ struct mapper *mapper_impl_config_load(FILE *f) m = mapper_impl_create(); - if ( !mapper_impl_config_load_actions(m, f) || - !mapper_impl_config_load_analogs(m, f) || - !mapper_impl_config_load_lights(m, f)) { + if (!mapper_impl_config_load_actions(m, f) || + !mapper_impl_config_load_analogs(m, f) || + !mapper_impl_config_load_lights(m, f)) { mapper_impl_destroy(m); m = NULL; } @@ -47,7 +47,7 @@ static bool mapper_impl_config_load_actions(struct mapper *m, FILE *f) return false; } - for (i = 0 ; i < count ; i++) { + for (i = 0; i < count; i++) { memset(&ma, 0, sizeof(ma)); if (!read_str(f, &dev_node)) { @@ -57,12 +57,9 @@ static bool mapper_impl_config_load_actions(struct mapper *m, FILE *f) ma.hid = hid_mgr_get_named_stub(dev_node); free(dev_node); - if ( !read_u32(f, &ma.control_no) || - !read_u32(f, &ma.value_min) || - !read_u32(f, &ma.value_max) || - !read_u8(f, &action) || - !read_u8(f, &page) || - !read_u8(f, &bit)) { + if (!read_u32(f, &ma.control_no) || !read_u32(f, &ma.value_min) || + !read_u32(f, &ma.value_max) || !read_u8(f, &action) || + !read_u8(f, &page) || !read_u8(f, &bit)) { return false; } @@ -86,7 +83,7 @@ static bool mapper_impl_config_load_analogs(struct mapper *m, FILE *f) mapper_impl_set_nanalogs(m, nanalogs); - for (i = 0 ; i < nanalogs ; i++) { + for (i = 0; i < nanalogs; i++) { memset(&ma, 0, sizeof(ma)); if (!read_str(f, &dev_node)) { @@ -133,7 +130,7 @@ static bool mapper_impl_config_load_lights(struct mapper *m, FILE *f) return false; } - for (i = 0 ; i < count ; i++) { + for (i = 0; i < count; i++) { memset(&ml, 0, sizeof(ml)); if (!read_str(f, &dev_node)) { @@ -181,9 +178,8 @@ static void mapper_impl_config_save_actions(struct mapper *m, FILE *f) count = 0; - for (pos = mapper_impl_iterate_actions(m) - ; action_iter_is_valid(pos) - ; action_iter_next(pos)) { + for (pos = mapper_impl_iterate_actions(m); action_iter_is_valid(pos); + action_iter_next(pos)) { count++; } @@ -192,9 +188,8 @@ static void mapper_impl_config_save_actions(struct mapper *m, FILE *f) /* Write out bindings */ - for (pos = mapper_impl_iterate_actions(m) - ; action_iter_is_valid(pos) - ; action_iter_next(pos)) { + for (pos = mapper_impl_iterate_actions(m); action_iter_is_valid(pos); + action_iter_next(pos)) { action_iter_get_mapping(pos, &ma); action = action_iter_get_action(pos); page = action_iter_get_page(pos); @@ -222,7 +217,7 @@ static void mapper_impl_config_save_analogs(struct mapper *m, FILE *f) nanalogs = mapper_impl_get_nanalogs(m); write_u8(f, &nanalogs); - for (i = 0 ; i < nanalogs ; i++) { + for (i = 0; i < nanalogs; i++) { mapper_impl_get_analog_map(m, i, &ma); if (ma.hid == NULL) { @@ -250,18 +245,16 @@ static void mapper_impl_config_save_lights(struct mapper *m, FILE *f) count = 0; - for (pos = mapper_impl_iterate_lights(m) - ; light_iter_is_valid(pos) - ; light_iter_next(pos)) { + for (pos = mapper_impl_iterate_lights(m); light_iter_is_valid(pos); + light_iter_next(pos)) { count++; } write_u32(f, &count); light_iter_free(pos); - for (pos = mapper_impl_iterate_lights(m) - ; light_iter_is_valid(pos) - ; light_iter_next(pos)) { + for (pos = mapper_impl_iterate_lights(m); light_iter_is_valid(pos); + light_iter_next(pos)) { light_iter_get_mapping(pos, &ml); game_light = light_iter_get_game_light(pos); @@ -272,4 +265,3 @@ static void mapper_impl_config_save_lights(struct mapper *m, FILE *f) light_iter_free(pos); } - diff --git a/src/main/geninput/mapper.c b/src/main/geninput/mapper.c index 94071fa..9d11585 100644 --- a/src/main/geninput/mapper.c +++ b/src/main/geninput/mapper.c @@ -58,8 +58,8 @@ static uint64_t action_mapping_update(struct action_mapping *am); static void analog_mapping_bind(struct analog_mapping *am); static void analog_mapping_update(struct analog_mapping *am); static void light_mapping_bind(struct light_mapping *lm); -static void light_mapping_send(struct light_mapping *lm, - const struct mapper *m); +static void +light_mapping_send(struct light_mapping *lm, const struct mapper *m); struct mapper *mapper_inst; @@ -202,9 +202,9 @@ static void analog_mapping_update(struct analog_mapping *am) if (am->absolute) { tmp = (value - am->affine_bias) / am->affine_scale; - am->pos = (uint8_t) ((tmp + 0.5) * 256.0); + am->pos = (uint8_t)((tmp + 0.5) * 256.0); } else { - am->pos += (int8_t) (value * exp(am->sensitivity / 256.0)); + am->pos += (int8_t)(value * exp(am->sensitivity / 256.0)); } } @@ -286,8 +286,7 @@ unbound_fail: return; } -static void light_mapping_send(struct light_mapping *lm, - const struct mapper *m) +static void light_mapping_send(struct light_mapping *lm, const struct mapper *m) { double tmp; uint32_t value; @@ -307,7 +306,7 @@ static void light_mapping_send(struct light_mapping *lm, intensity = m->lights[lm->game_light]; tmp = (intensity / 256.0) * lm->affine_scale; - value = (int32_t) (tmp + 0.5) + lm->affine_bias; + value = (int32_t)(tmp + 0.5) + lm->affine_bias; hid_stub_set_light(lm->dest.hid, lm->dest.light_no, value); } @@ -331,13 +330,13 @@ struct mapper *mapper_impl_create(void) return m; } -void mapper_impl_clear_action_map(struct mapper *m, uint8_t action, - uint8_t page) +void mapper_impl_clear_action_map( + struct mapper *m, uint8_t action, uint8_t page) { struct action_mapping *am; size_t i; - for (i = 0 ; i < m->actions.nitems ; i++) { + for (i = 0; i < m->actions.nitems; i++) { am = array_item(struct action_mapping, &m->actions, i); if (am->action == action && am->page == page) { @@ -348,13 +347,13 @@ void mapper_impl_clear_action_map(struct mapper *m, uint8_t action, } } -void mapper_impl_clear_light_map(struct mapper *m, - const struct mapped_light *ml) +void mapper_impl_clear_light_map( + struct mapper *m, const struct mapped_light *ml) { struct light_mapping *lm; size_t i; - for (i = 0 ; i < m->light_maps.nitems ; ) { + for (i = 0; i < m->light_maps.nitems;) { lm = array_item(struct light_mapping, &m->light_maps, i); if (memcmp(&lm->dest, ml, sizeof(*ml)) == 0) { @@ -365,13 +364,13 @@ void mapper_impl_clear_light_map(struct mapper *m, } } -bool mapper_impl_get_action_map(struct mapper *m, uint8_t action, uint8_t page, - struct mapped_action *ma) +bool mapper_impl_get_action_map( + struct mapper *m, uint8_t action, uint8_t page, struct mapped_action *ma) { const struct action_mapping *am; size_t i; - for (i = 0 ; i < m->actions.nitems ; i++) { + for (i = 0; i < m->actions.nitems; i++) { am = array_item(struct action_mapping, &m->actions, i); if (am->action == action && am->page == page) { @@ -384,8 +383,8 @@ bool mapper_impl_get_action_map(struct mapper *m, uint8_t action, uint8_t page, return false; } -bool mapper_impl_get_analog_map(struct mapper *m, uint8_t analog, - struct mapped_analog *ma) +bool mapper_impl_get_analog_map( + struct mapper *m, uint8_t analog, struct mapped_analog *ma) { memset(ma, 0, sizeof(*ma)); @@ -425,7 +424,7 @@ uint8_t mapper_impl_get_npages(struct mapper *m) max_page = -1; - for (i = 0 ; i < m->actions.nitems ; i++) { + for (i = 0; i < m->actions.nitems; i++) { am = array_item(struct action_mapping, &m->actions, i); if (max_page < am->page) { @@ -433,7 +432,7 @@ uint8_t mapper_impl_get_npages(struct mapper *m) } } - return (uint8_t) (max_page + 1); + return (uint8_t)(max_page + 1); } action_iter_t mapper_impl_iterate_actions(struct mapper *m) @@ -475,13 +474,17 @@ bool mapper_impl_is_analog_absolute(struct mapper *m, uint8_t analog) return m->analogs[analog].absolute; } -void mapper_impl_set_action_map(struct mapper *m, uint8_t action, uint8_t page, - uint8_t bit, const struct mapped_action *ma) +void mapper_impl_set_action_map( + struct mapper *m, + uint8_t action, + uint8_t page, + uint8_t bit, + const struct mapped_action *ma) { struct action_mapping *am; size_t i; - for (i = 0 ; i < m->actions.nitems ; i++) { + for (i = 0; i < m->actions.nitems; i++) { am = array_item(struct action_mapping, &m->actions, i); if (am->action == action && am->page == page) { @@ -499,8 +502,8 @@ void mapper_impl_set_action_map(struct mapper *m, uint8_t action, uint8_t page, am->bit = bit; } -bool mapper_impl_set_analog_map(struct mapper *m, uint8_t analog, - const struct mapped_analog *ma) +bool mapper_impl_set_analog_map( + struct mapper *m, uint8_t analog, const struct mapped_analog *ma) { struct analog_mapping *am; @@ -516,8 +519,8 @@ bool mapper_impl_set_analog_map(struct mapper *m, uint8_t analog, return true; } -bool mapper_impl_set_analog_sensitivity(struct mapper *m, uint8_t analog, - int32_t sensitivity) +bool mapper_impl_set_analog_sensitivity( + struct mapper *m, uint8_t analog, int32_t sensitivity) { if (analog >= m->nanalogs) { return false; @@ -528,13 +531,13 @@ bool mapper_impl_set_analog_sensitivity(struct mapper *m, uint8_t analog, return true; } -void mapper_impl_set_light_map(struct mapper *m, const struct mapped_light *ml, - uint8_t game_light) +void mapper_impl_set_light_map( + struct mapper *m, const struct mapped_light *ml, uint8_t game_light) { struct light_mapping *lm; size_t i; - for (i = 0 ; i < m->light_maps.nitems ; i++) { + for (i = 0; i < m->light_maps.nitems; i++) { lm = array_item(struct light_mapping, &m->light_maps, i); if (memcmp(&lm->dest, ml, sizeof(*ml)) == 0) { @@ -584,18 +587,18 @@ uint64_t mapper_impl_update(struct mapper *m) hid_mgr_lock(); - for (i = 0 ; i < m->light_maps.nitems ; i++) { + for (i = 0; i < m->light_maps.nitems; i++) { lm = array_item(struct light_mapping, &m->light_maps, i); light_mapping_send(lm, m); } - for (i = 0 ; i < m->nanalogs ; i++) { + for (i = 0; i < m->nanalogs; i++) { analog_mapping_update(&m->analogs[i]); } result = 0; - for (i = 0 ; i < m->actions.nitems ; i++) { + for (i = 0; i < m->actions.nitems; i++) { am = array_item(struct action_mapping, &m->actions, i); result |= action_mapping_update(am); } @@ -605,8 +608,7 @@ uint64_t mapper_impl_update(struct mapper *m) return result; } -void mapper_impl_write_light(struct mapper *m, uint8_t light, - uint8_t intensity) +void mapper_impl_write_light(struct mapper *m, uint8_t light, uint8_t intensity) { if (light >= m->nlights) { return; @@ -623,4 +625,3 @@ void mapper_impl_destroy(struct mapper *m) array_fini(&m->actions); free(m); } - diff --git a/src/main/geninput/mapper.h b/src/main/geninput/mapper.h index 6d51462..c560507 100644 --- a/src/main/geninput/mapper.h +++ b/src/main/geninput/mapper.h @@ -48,14 +48,14 @@ void light_iter_next(light_iter_t iter); void light_iter_free(light_iter_t iter); struct mapper *mapper_impl_create(void); -void mapper_impl_clear_action_map(struct mapper *m, uint8_t action, - uint8_t page); -void mapper_impl_clear_light_map(struct mapper *m, - const struct mapped_light *ml); -bool mapper_impl_get_analog_map(struct mapper *m, uint8_t analog, - struct mapped_analog *ma); -bool mapper_impl_get_action_map(struct mapper *m, uint8_t action, uint8_t page, - struct mapped_action *ma); +void mapper_impl_clear_action_map( + struct mapper *m, uint8_t action, uint8_t page); +void mapper_impl_clear_light_map( + struct mapper *m, const struct mapped_light *ml); +bool mapper_impl_get_analog_map( + struct mapper *m, uint8_t analog, struct mapped_analog *ma); +bool mapper_impl_get_action_map( + struct mapper *m, uint8_t action, uint8_t page, struct mapped_action *ma); int32_t mapper_impl_get_analog_sensitivity(struct mapper *m, uint8_t analog); uint8_t mapper_impl_get_nanalogs(struct mapper *m); uint8_t mapper_impl_get_nlights(struct mapper *m); @@ -63,20 +63,24 @@ uint8_t mapper_impl_get_npages(struct mapper *m); bool mapper_impl_is_analog_absolute(struct mapper *m, uint8_t analog); action_iter_t mapper_impl_iterate_actions(struct mapper *m); light_iter_t mapper_impl_iterate_lights(struct mapper *m); -void mapper_impl_set_action_map(struct mapper *m, uint8_t action, uint8_t page, - uint8_t bit, const struct mapped_action *ma); -bool mapper_impl_set_analog_map(struct mapper *m, uint8_t analog, - const struct mapped_analog *ma); -bool mapper_impl_set_analog_sensitivity(struct mapper *m, uint8_t analog, - int32_t sensitivity); -void mapper_impl_set_light_map(struct mapper *m, const struct mapped_light *ml, - uint8_t game_light); +void mapper_impl_set_action_map( + struct mapper *m, + uint8_t action, + uint8_t page, + uint8_t bit, + const struct mapped_action *ma); +bool mapper_impl_set_analog_map( + struct mapper *m, uint8_t analog, const struct mapped_analog *ma); +bool mapper_impl_set_analog_sensitivity( + struct mapper *m, uint8_t analog, int32_t sensitivity); +void mapper_impl_set_light_map( + struct mapper *m, const struct mapped_light *ml, uint8_t game_light); void mapper_impl_set_nanalogs(struct mapper *m, uint8_t nanalogs); void mapper_impl_set_nlights(struct mapper *m, uint8_t nlights); uint8_t mapper_impl_read_analog(struct mapper *m, uint8_t analog); uint64_t mapper_impl_update(struct mapper *m); -void mapper_impl_write_light(struct mapper *m, uint8_t light, - uint8_t intensity); +void mapper_impl_write_light( + struct mapper *m, uint8_t light, uint8_t intensity); void mapper_impl_destroy(struct mapper *m); #endif diff --git a/src/main/geninput/mouse.c b/src/main/geninput/mouse.c index f03e75a..9f0b373 100644 --- a/src/main/geninput/mouse.c +++ b/src/main/geninput/mouse.c @@ -1,7 +1,7 @@ #define LOG_MODULE "mouse" -#include #include +#include #include #include @@ -40,20 +40,20 @@ struct mouse { static const struct hid_control mouse_controls[MOUSE_CTL_COUNT] = { /* Left, right, middle, AUX1, AUX2 buttons */ - { 0x00090001, 0x00000000, 0x00000001, 0 }, - { 0x00090002, 0x00000000, 0x00000001, 0 }, - { 0x00090003, 0x00000000, 0x00000001, 0 }, - { 0x00090004, 0x00000000, 0x00000001, 0 }, - { 0x00090005, 0x00000000, 0x00000001, 0 }, + {0x00090001, 0x00000000, 0x00000001, 0}, + {0x00090002, 0x00000000, 0x00000001, 0}, + {0x00090003, 0x00000000, 0x00000001, 0}, + {0x00090004, 0x00000000, 0x00000001, 0}, + {0x00090005, 0x00000000, 0x00000001, 0}, /* X axis */ - { 0x00010030, 0xC0000000, 0x3FFFFFFF, HID_FLAG_RELATIVE }, + {0x00010030, 0xC0000000, 0x3FFFFFFF, HID_FLAG_RELATIVE}, /* Y axis */ - { 0x00010031, 0xC0000000, 0x3FFFFFFF, HID_FLAG_RELATIVE }, + {0x00010031, 0xC0000000, 0x3FFFFFFF, HID_FLAG_RELATIVE}, /* Mouse wheel */ - { 0x00010038, 0xFFFF8000, 0x00007FFF, HID_FLAG_RELATIVE }, + {0x00010038, 0xFFFF8000, 0x00007FFF, HID_FLAG_RELATIVE}, }; static const uint16_t mouse_down_flg[] = { @@ -72,33 +72,43 @@ static const uint16_t mouse_up_flg[] = { RI_MOUSE_BUTTON_5_UP, }; -DEFINE_GUID(mouse_guid, 0x378DE44C, 0x56EF, 0x11D1, 0xBC, 0x8C, \ - 0x00, 0xA0, 0xC9, 0x14, 0x05, 0xDD); +DEFINE_GUID( + mouse_guid, + 0x378DE44C, + 0x56EF, + 0x11D1, + 0xBC, + 0x8C, + 0x00, + 0xA0, + 0xC9, + 0x14, + 0x05, + 0xDD); static bool mouse_get_device_usage(const struct hid *hid, uint32_t *usage); -static bool mouse_get_name(const struct hid *hid, wchar_t *chars, - size_t *nchars); -static bool mouse_get_controls(const struct hid *hid, - struct hid_control *controls, size_t *ncontrols); -static bool mouse_get_lights(const struct hid *hid, struct hid_light *lights, - size_t *nlights); -static bool mouse_get_value(struct hid *hid, size_t control_no, - int32_t *out_value); -static bool mouse_set_light(struct hid *hid, size_t light_no, - uint32_t intensity); +static bool +mouse_get_name(const struct hid *hid, wchar_t *chars, size_t *nchars); +static bool mouse_get_controls( + const struct hid *hid, struct hid_control *controls, size_t *ncontrols); +static bool mouse_get_lights( + const struct hid *hid, struct hid_light *lights, size_t *nlights); +static bool +mouse_get_value(struct hid *hid, size_t control_no, int32_t *out_value); +static bool +mouse_set_light(struct hid *hid, size_t light_no, uint32_t intensity); static void mouse_handle_event(struct hid_ri *hid_ri, const RAWINPUT *ri); static void mouse_close(struct hid *hid); -static const struct hid_ri_vtbl mouse_vtbl = {{ - /* .close = */ mouse_close, - /* .get_device_usage = */ mouse_get_device_usage, - /* .get_name = */ mouse_get_name, - /* .get_controls = */ mouse_get_controls, - /* .get_lights = */ mouse_get_lights, - /* .get_value = */ mouse_get_value, - /* .set_light = */ mouse_set_light }, - /* .handle_event = */ mouse_handle_event -}; +static const struct hid_ri_vtbl mouse_vtbl = { + {/* .close = */ mouse_close, + /* .get_device_usage = */ mouse_get_device_usage, + /* .get_name = */ mouse_get_name, + /* .get_controls = */ mouse_get_controls, + /* .get_lights = */ mouse_get_lights, + /* .get_value = */ mouse_get_value, + /* .set_light = */ mouse_set_light}, + /* .handle_event = */ mouse_handle_event}; void mouse_create(struct hid_ri **hid_ri, const char *dev_node) { @@ -128,23 +138,23 @@ static bool mouse_get_device_usage(const struct hid *hid, uint32_t *usage) return true; } -static bool mouse_get_name(const struct hid *hid, wchar_t *chars, - size_t *nchars) +static bool +mouse_get_name(const struct hid *hid, wchar_t *chars, size_t *nchars) { struct mouse *m = containerof(hid, struct mouse, super); return hid_ri_get_name(chars, nchars, m->name); } -static bool mouse_get_controls(const struct hid *hid, - struct hid_control *controls, size_t *ncontrols) +static bool mouse_get_controls( + const struct hid *hid, struct hid_control *controls, size_t *ncontrols) { - return hid_ri_get_controls(controls, ncontrols, mouse_controls, - MOUSE_CTL_COUNT); + return hid_ri_get_controls( + controls, ncontrols, mouse_controls, MOUSE_CTL_COUNT); } -static bool mouse_get_lights(const struct hid *hid, - struct hid_light *lights, size_t *nlights) +static bool mouse_get_lights( + const struct hid *hid, struct hid_light *lights, size_t *nlights) { log_assert(nlights != NULL); @@ -155,8 +165,8 @@ static bool mouse_get_lights(const struct hid *hid, return true; } -static bool mouse_get_value(struct hid *hid, size_t control_no, - int32_t *out_value) +static bool +mouse_get_value(struct hid *hid, size_t control_no, int32_t *out_value) { struct mouse *m = containerof(hid, struct mouse, super); long tmp; @@ -179,7 +189,7 @@ static bool mouse_get_value(struct hid *hid, size_t control_no, do { tmp = m->values[control_no]; } while (InterlockedCompareExchange( - &m->values[control_no], 0, tmp) != tmp); + &m->values[control_no], 0, tmp) != tmp); *out_value = tmp; @@ -190,8 +200,8 @@ static bool mouse_get_value(struct hid *hid, size_t control_no, } } -static bool mouse_set_light(struct hid *hid, size_t light_no, - uint32_t intensity) +static bool +mouse_set_light(struct hid *hid, size_t light_no, uint32_t intensity) { return false; } @@ -222,12 +232,12 @@ static void mouse_handle_event(struct hid_ri *hid_ri, const RAWINPUT *ri) do { tmp = m->values[MOUSE_CTL_X]; } while (InterlockedCompareExchange( - &m->values[MOUSE_CTL_X], tmp + dx, tmp) != tmp); + &m->values[MOUSE_CTL_X], tmp + dx, tmp) != tmp); do { tmp = m->values[MOUSE_CTL_Y]; } while (InterlockedCompareExchange( - &m->values[MOUSE_CTL_Y], tmp + dy, tmp) != tmp); + &m->values[MOUSE_CTL_Y], tmp + dy, tmp) != tmp); if (ri->data.mouse.usButtonFlags & RI_MOUSE_WHEEL) { dwheel = ri->data.mouse.usButtonData; @@ -235,10 +245,10 @@ static void mouse_handle_event(struct hid_ri *hid_ri, const RAWINPUT *ri) do { tmp = m->values[MOUSE_CTL_WHEEL]; } while (InterlockedCompareExchange( - &m->values[MOUSE_CTL_WHEEL], tmp + dwheel, tmp) != tmp); + &m->values[MOUSE_CTL_WHEEL], tmp + dwheel, tmp) != tmp); } - for (i = 0 ; i < 5 ; i++) { + for (i = 0; i < 5; i++) { if (ri->data.mouse.usButtonFlags & mouse_down_flg[i]) { m->values[i] = 1; } else if (ri->data.mouse.usButtonFlags & mouse_up_flg[i]) { @@ -254,4 +264,3 @@ static void mouse_close(struct hid *hid) free(m->name); free(m); } - diff --git a/src/main/geninput/mouse.h b/src/main/geninput/mouse.h index 2138baa..13c09ec 100644 --- a/src/main/geninput/mouse.h +++ b/src/main/geninput/mouse.h @@ -3,7 +3,7 @@ #include "geninput/hid.h" -#define MOUSE_DEVICE_USAGE 0x00010002 +#define MOUSE_DEVICE_USAGE 0x00010002 void mouse_create(struct hid_ri **hid_ri, const char *dev_node); diff --git a/src/main/geninput/msg-thread.c b/src/main/geninput/msg-thread.c index cad36be..81b5dbf 100644 --- a/src/main/geninput/msg-thread.c +++ b/src/main/geninput/msg-thread.c @@ -1,5 +1,5 @@ -#include #include +#include #include @@ -14,14 +14,15 @@ void msg_window_setup(HWND hwnd) ri_init(hwnd); hotplug_init(hwnd); - log_info("Message pump thread ready, thread id = %d", - (unsigned int) GetCurrentThreadId()); + log_info( + "Message pump thread ready, thread id = %d", + (unsigned int) GetCurrentThreadId()); SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); } -LRESULT WINAPI msg_window_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam) +LRESULT WINAPI +msg_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { switch (msg) { case WM_INPUT: @@ -48,4 +49,3 @@ void msg_window_teardown(HWND hwnd) hotplug_fini(); ri_fini(); } - diff --git a/src/main/geninput/pacdrive.c b/src/main/geninput/pacdrive.c index c7fe5c4..30667f9 100644 --- a/src/main/geninput/pacdrive.c +++ b/src/main/geninput/pacdrive.c @@ -1,7 +1,7 @@ #define LOG_MODULE "pacdrive" -#include #include +#include #include #include @@ -40,41 +40,46 @@ static struct hid_light pac_lights[16]; static const wchar_t pac_name[] = L"PacDrive Shim"; static bool pac_get_device_usage(const struct hid *hid, uint32_t *usage); -static bool pac_get_name(const struct hid *hid, wchar_t *chars, - size_t *nchars); -static bool pac_get_controls(const struct hid *hid, - struct hid_control *controls, size_t *ncontrols); -static bool pac_get_lights(const struct hid *hid, struct hid_light *lights, - size_t *nlights); +static bool pac_get_name(const struct hid *hid, wchar_t *chars, size_t *nchars); +static bool pac_get_controls( + const struct hid *hid, struct hid_control *controls, size_t *ncontrols); +static bool pac_get_lights( + const struct hid *hid, struct hid_light *lights, size_t *nlights); static bool pac_get_value(struct hid *hid, size_t control_no, int32_t *value); -static bool pac_set_light(struct hid *hid, size_t light_no, - uint32_t intensity); -static bool pac_handle_event(struct hid_fd *hid_fd, OVERLAPPED *ovl, - size_t nbytes); +static bool pac_set_light(struct hid *hid, size_t light_no, uint32_t intensity); +static bool +pac_handle_event(struct hid_fd *hid_fd, OVERLAPPED *ovl, size_t nbytes); static void pac_close(struct hid *hid); -static const struct hid_fd_vtbl pac_vtbl = {{ - /* .close = */ pac_close, - /* .get_device_usage = */ pac_get_device_usage, - /* .get_name = */ pac_get_name, - /* .get_controls = */ pac_get_controls, - /* .get_lights = */ pac_get_lights, - /* .get_value = */ pac_get_value, - /* .set_light = */ pac_set_light }, - /* .handle_event = */ pac_handle_event -}; +static const struct hid_fd_vtbl pac_vtbl = { + {/* .close = */ pac_close, + /* .get_device_usage = */ pac_get_device_usage, + /* .get_name = */ pac_get_name, + /* .get_controls = */ pac_get_controls, + /* .get_lights = */ pac_get_lights, + /* .get_value = */ pac_get_value, + /* .set_light = */ pac_set_light}, + /* .handle_event = */ pac_handle_event}; -bool pac_open(struct hid_fd **hid_out, const char *dev_node, HANDLE iocp, - uintptr_t iocp_ctx) +bool pac_open( + struct hid_fd **hid_out, + const char *dev_node, + HANDLE iocp, + uintptr_t iocp_ctx) { HIDD_ATTRIBUTES attrs; HANDLE fd; struct pac *pac; int i; - fd = CreateFile(dev_node, GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, - FILE_FLAG_OVERLAPPED, NULL); + fd = CreateFile( + dev_node, + GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_FLAG_OVERLAPPED, + NULL); if (fd == INVALID_HANDLE_VALUE) { goto open_fail; @@ -95,16 +100,18 @@ bool pac_open(struct hid_fd **hid_out, const char *dev_node, HANDLE iocp, CreateIoCompletionPort(fd, iocp, iocp_ctx, 0); - if (!WriteFile(fd, &pac->io_buf, sizeof(pac->io_buf), NULL, &pac->ovl) - && GetLastError() != ERROR_IO_PENDING) { - log_warning("%s: Initial WriteFile failed: %08x", - dev_node, (unsigned int) GetLastError()); + if (!WriteFile(fd, &pac->io_buf, sizeof(pac->io_buf), NULL, &pac->ovl) && + GetLastError() != ERROR_IO_PENDING) { + log_warning( + "%s: Initial WriteFile failed: %08x", + dev_node, + (unsigned int) GetLastError()); goto write_fail; } - for (i = 0 ; i < lengthof(pac_lights) ; i++) { - pac_lights[i].usage = 0x0008004B; /* LED, Generic Indicator */ + for (i = 0; i < lengthof(pac_lights); i++) { + pac_lights[i].usage = 0x0008004B; /* LED, Generic Indicator */ pac_lights[i].value_min = 0; pac_lights[i].value_max = 1; } @@ -133,8 +140,7 @@ static bool pac_get_device_usage(const struct hid *hid, uint32_t *usage) return true; } -static bool pac_get_name(const struct hid *hid, wchar_t *chars, - size_t *nchars) +static bool pac_get_name(const struct hid *hid, wchar_t *chars, size_t *nchars) { log_assert(nchars != NULL); @@ -151,8 +157,8 @@ static bool pac_get_name(const struct hid *hid, wchar_t *chars, return true; } -static bool pac_get_controls(const struct hid *hid, - struct hid_control *controls, size_t *ncontrols) +static bool pac_get_controls( + const struct hid *hid, struct hid_control *controls, size_t *ncontrols) { log_assert(ncontrols != NULL); @@ -161,8 +167,8 @@ static bool pac_get_controls(const struct hid *hid, return true; } -static bool pac_get_lights(const struct hid *hid, struct hid_light *lights, - size_t *nlights) +static bool +pac_get_lights(const struct hid *hid, struct hid_light *lights, size_t *nlights) { log_assert(nlights != NULL); @@ -184,8 +190,7 @@ static bool pac_get_value(struct hid *hid, size_t control_no, int32_t *value) return false; } -static bool pac_set_light(struct hid *hid, size_t light_no, - uint32_t intensity) +static bool pac_set_light(struct hid *hid, size_t light_no, uint32_t intensity) { struct pac *pac = containerof(hid, struct pac, super); @@ -194,7 +199,7 @@ static bool pac_set_light(struct hid *hid, size_t light_no, } if (intensity != 0) { - pac->leds |= (1 << light_no); + pac->leds |= (1 << light_no); } else { pac->leds &= ~(1 << light_no); } @@ -202,8 +207,8 @@ static bool pac_set_light(struct hid *hid, size_t light_no, return true; } -static bool pac_handle_event(struct hid_fd *hid_fd, OVERLAPPED *ovl, - size_t nbytes) +static bool +pac_handle_event(struct hid_fd *hid_fd, OVERLAPPED *ovl, size_t nbytes) { struct pac *pac = containerof(hid_fd, struct pac, super); @@ -214,8 +219,9 @@ static bool pac_handle_event(struct hid_fd *hid_fd, OVERLAPPED *ovl, memset(&pac->ovl, 0, sizeof(pac->ovl)); - if (!WriteFile(pac->fd, &pac->io_buf, sizeof(pac->io_buf), NULL, - &pac->ovl) && GetLastError() != ERROR_IO_PENDING) { + if (!WriteFile( + pac->fd, &pac->io_buf, sizeof(pac->io_buf), NULL, &pac->ovl) && + GetLastError() != ERROR_IO_PENDING) { log_warning("WriteFile failed: %08x", (unsigned int) GetLastError()); return false; @@ -232,4 +238,3 @@ static void pac_close(struct hid *hid) free(pac); } - diff --git a/src/main/geninput/pacdrive.h b/src/main/geninput/pacdrive.h index f5cb321..8edb478 100644 --- a/src/main/geninput/pacdrive.h +++ b/src/main/geninput/pacdrive.h @@ -6,7 +6,10 @@ #include "geninput/io-thread.h" -bool pac_open(struct hid_fd **hid_out, const char *dev_node, HANDLE iocp, - uintptr_t iocp_ctx); +bool pac_open( + struct hid_fd **hid_out, + const char *dev_node, + HANDLE iocp, + uintptr_t iocp_ctx); #endif diff --git a/src/main/geninput/ri.c b/src/main/geninput/ri.c index c78b36a..b3befee 100644 --- a/src/main/geninput/ri.c +++ b/src/main/geninput/ri.c @@ -1,7 +1,7 @@ #include -#include "geninput/hid.h" #include "geninput/hid-mgr.h" +#include "geninput/hid.h" #include "geninput/kbd.h" #include "geninput/mouse.h" #include "geninput/ri.h" @@ -40,8 +40,9 @@ void ri_init(HWND hwnd) filter[2].hwndTarget = hwnd; if (!RegisterRawInputDevices(filter, lengthof(filter), sizeof(filter[0]))) { - log_fatal("RegisterRawInputDevices failed: %x", - (unsigned int) GetLastError()); + log_fatal( + "RegisterRawInputDevices failed: %x", + (unsigned int) GetLastError()); } ri_scan_devices(); @@ -72,7 +73,7 @@ void ri_scan_devices(void) ri_handles = xrealloc(ri_handles, sizeof(*ri_handles) * ri_ndevs); - for (i = 0 ; i < ri_ndevs ; i++) { + for (i = 0; i < ri_ndevs; i++) { ri_handles[i].fake_fd = NULL; ri_handles[i].hid_ri = NULL; @@ -81,8 +82,8 @@ void ri_scan_devices(void) dev_node = xmalloc(size); - if (GetRawInputDeviceInfo(ridl[i].hDevice, RIDI_DEVICENAME, dev_node, - &size) == -1) { + if (GetRawInputDeviceInfo( + ridl[i].hDevice, RIDI_DEVICENAME, dev_node, &size) == -1) { log_warning("GetRawInputDeviceInfo(RIDI_DEVICENAME) data failed"); goto skip; @@ -113,7 +114,7 @@ void ri_scan_devices(void) hid_stub_attach(stub, (struct hid *) ri_handles[i].hid_ri); } -skip: + skip: free(dev_node); } @@ -130,10 +131,10 @@ void ri_handle_msg(HRAWINPUT msg) nbytes = sizeof(ri); - if (GetRawInputData(msg, RID_INPUT, &ri, &nbytes, sizeof(ri.header)) - == (UINT) -1) { - log_warning("GetRawInputData failed: %x", - (unsigned int) GetLastError()); + if (GetRawInputData(msg, RID_INPUT, &ri, &nbytes, sizeof(ri.header)) == + (UINT) -1) { + log_warning( + "GetRawInputData failed: %x", (unsigned int) GetLastError()); return; } @@ -147,7 +148,7 @@ void ri_handle_msg(HRAWINPUT msg) return; } - for (i = 0 ; i < ri_ndevs ; i++) { + for (i = 0; i < ri_ndevs; i++) { if (ri_handles[i].fake_fd == ri.header.hDevice) { hid_ri_handle_event(ri_handles[i].hid_ri, &ri); @@ -180,8 +181,8 @@ void ri_fini(void) filter[2].hwndTarget = NULL; if (!RegisterRawInputDevices(filter, lengthof(filter), sizeof(filter[0]))) { - log_warning("RegisterRawInputDevices(RIDEV_REMOVE) failed: %x", - (unsigned int) GetLastError()); + log_warning( + "RegisterRawInputDevices(RIDEV_REMOVE) failed: %x", + (unsigned int) GetLastError()); } } - diff --git a/src/main/hook/com-proxy.c b/src/main/hook/com-proxy.c index 186402f..c67d123 100644 --- a/src/main/hook/com-proxy.c +++ b/src/main/hook/com-proxy.c @@ -1,5 +1,5 @@ -#include #include +#include #include @@ -10,52 +10,78 @@ #ifdef _WIN64 - /***** 64-BIT TRAMPOLINE *****/ +/***** 64-BIT TRAMPOLINE *****/ #define SLOT_OFFSET 0x0A static const uint8_t com_proxy_tramp[] = { /* mov rcx, [rcx+8] ; Replace this with this->real */ - 0x48, 0x8B, 0x49, 0x08, + 0x48, + 0x8B, + 0x49, + 0x08, /* mov rax, [rcx] ; Get real->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 - /***** 32-BIT TRAMPOLINE *****/ +/***** 32-BIT TRAMPOLINE *****/ #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 real->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 -static HRESULT STDCALL com_proxy_query_interface(IUnknown *ptr, REFIID iid, - void **iface) +static HRESULT STDCALL +com_proxy_query_interface(IUnknown *ptr, REFIID iid, void **iface) { struct com_proxy *self = (struct com_proxy *) ptr; IUnknown *obj = self->real; /* Not necessarily the real IUnknown* */ @@ -117,8 +143,11 @@ struct com_proxy *com_proxy_wrap(void *iface, size_t vtbl_size) self = xmalloc(sizeof(*self)); self->vptr = xmalloc(vtbl_size); self->real = iface; - self->tramps = VirtualAlloc(NULL, sizeof(com_proxy_tramp) * nslots, - MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE); + self->tramps = VirtualAlloc( + NULL, + sizeof(com_proxy_tramp) * nslots, + MEM_RESERVE | MEM_COMMIT, + PAGE_EXECUTE_READWRITE); /* Set up proxied IUnknown impl */ vtbl = self->vptr; @@ -127,7 +156,7 @@ struct com_proxy *com_proxy_wrap(void *iface, size_t vtbl_size) vtbl[2] = com_proxy_release; /* Populate trampoline code for remaining vtbl entries */ - for (i = 3 /* Skip IUnknown */ ; i < nslots ; i++) { + for (i = 3 /* Skip IUnknown */; i < nslots; i++) { cur_tramp = self->tramps + i * sizeof(com_proxy_tramp); /* Copy template */ @@ -142,4 +171,3 @@ struct com_proxy *com_proxy_wrap(void *iface, size_t vtbl_size) return self; } - diff --git a/src/main/hook/d3d9.c b/src/main/hook/d3d9.c index c70c375..dd8c31f 100644 --- a/src/main/hook/d3d9.c +++ b/src/main/hook/d3d9.c @@ -1,158 +1,232 @@ #define LOG_MODULE "hook-d3d9" -#include "hook/com-proxy.h" #include "hook/d3d9.h" +#include "hook/com-proxy.h" #include "hook/table.h" #include "util/log.h" -/* ------------------------------------------------------------------------------------------------------------------ */ +/* ------------------------------------------------------------------------------------------------------------------ + */ -static IDirect3D9* (STDCALL* real_Direct3DCreate9)(UINT sdk_ver); +static IDirect3D9 *(STDCALL *real_Direct3DCreate9)(UINT sdk_ver); -static BOOL (STDCALL *real_EnumDisplayDevicesA)( - const char *dev_name, DWORD dev_num, DISPLAY_DEVICEA *info, - DWORD flags); +static BOOL(STDCALL *real_EnumDisplayDevicesA)( + const char *dev_name, DWORD dev_num, DISPLAY_DEVICEA *info, DWORD flags); -static HWND (STDCALL *real_CreateWindowExA)( - DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, - int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, - HINSTANCE hInstance, LPVOID lpParam); +static HWND(STDCALL *real_CreateWindowExA)( + DWORD dwExStyle, + LPCSTR lpClassName, + LPCSTR lpWindowName, + DWORD dwStyle, + int X, + int Y, + int nWidth, + int nHeight, + HWND hWndParent, + HMENU hMenu, + HINSTANCE hInstance, + LPVOID lpParam); -static BOOL (STDCALL* real_GetClientRect)(HWND hWnd, LPRECT lpRect); +static BOOL(STDCALL *real_GetClientRect)(HWND hWnd, LPRECT lpRect); -static HRESULT (STDCALL* real_CreateDevice)(IDirect3D9 *self, UINT adapter, D3DDEVTYPE type, HWND hwnd, DWORD flags, - D3DPRESENT_PARAMETERS *pp, IDirect3DDevice9 **pdev); +static HRESULT(STDCALL *real_CreateDevice)( + IDirect3D9 *self, + UINT adapter, + D3DDEVTYPE type, + HWND hwnd, + DWORD flags, + D3DPRESENT_PARAMETERS *pp, + IDirect3DDevice9 **pdev); -static HRESULT (STDCALL* real_CreateTexture)(IDirect3DDevice9* self, UINT width, UINT height, UINT levels, DWORD usage, - D3DFORMAT format, D3DPOOL pool, IDirect3DTexture9** texture, HANDLE* shared_handle); +static HRESULT(STDCALL *real_CreateTexture)( + IDirect3DDevice9 *self, + UINT width, + UINT height, + UINT levels, + DWORD usage, + D3DFORMAT format, + D3DPOOL pool, + IDirect3DTexture9 **texture, + HANDLE *shared_handle); -static HRESULT (STDCALL* real_BeginScene)(IDirect3DDevice9* self); +static HRESULT(STDCALL *real_BeginScene)(IDirect3DDevice9 *self); -static HRESULT (STDCALL* real_EndScene)(IDirect3DDevice9* self); +static HRESULT(STDCALL *real_EndScene)(IDirect3DDevice9 *self); -static HRESULT (STDCALL* real_Present)(IDirect3DDevice9* self, - CONST RECT *pSourceRect, CONST RECT *pDestRect, - HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion); +static HRESULT(STDCALL *real_Present)( + IDirect3DDevice9 *self, + CONST RECT *pSourceRect, + CONST RECT *pDestRect, + HWND hDestWindowOverride, + CONST RGNDATA *pDirtyRegion); -static HRESULT (STDCALL* real_SetRenderState)(IDirect3DDevice9* self, - D3DRENDERSTATETYPE State, DWORD Value); +static HRESULT(STDCALL *real_SetRenderState)( + IDirect3DDevice9 *self, D3DRENDERSTATETYPE State, DWORD Value); -static HRESULT (STDCALL *real_DrawPrimitiveUP)( - IDirect3DDevice9* self, D3DPRIMITIVETYPE primitive_type, - UINT primitive_count, const void *data, UINT stride); +static HRESULT(STDCALL *real_DrawPrimitiveUP)( + IDirect3DDevice9 *self, + D3DPRIMITIVETYPE primitive_type, + UINT primitive_count, + const void *data, + UINT stride); -/* ------------------------------------------------------------------------------------------------------------------ */ +/* ------------------------------------------------------------------------------------------------------------------ + */ -static IDirect3D9* STDCALL my_Direct3DCreate9(UINT sdk_ver); +static IDirect3D9 *STDCALL my_Direct3DCreate9(UINT sdk_ver); -static BOOL STDCALL my_EnumDisplayDevicesA(const char *dev_name, DWORD dev_num, DISPLAY_DEVICEA *info, DWORD flags); +static BOOL STDCALL my_EnumDisplayDevicesA( + const char *dev_name, DWORD dev_num, DISPLAY_DEVICEA *info, DWORD flags); static HWND STDCALL my_CreateWindowExA( - DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, - int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, - HINSTANCE hInstance, LPVOID lpParam); + DWORD dwExStyle, + LPCSTR lpClassName, + LPCSTR lpWindowName, + DWORD dwStyle, + int X, + int Y, + int nWidth, + int nHeight, + HWND hWndParent, + HMENU hMenu, + HINSTANCE hInstance, + LPVOID lpParam); static BOOL STDCALL my_GetClientRect(HWND hWnd, LPRECT lpRect); -static HRESULT STDCALL my_CreateDevice(IDirect3D9 *self, UINT adapter, D3DDEVTYPE type, HWND hwnd, DWORD flags, - D3DPRESENT_PARAMETERS *pp, IDirect3DDevice9 **pdev); +static HRESULT STDCALL my_CreateDevice( + IDirect3D9 *self, + UINT adapter, + D3DDEVTYPE type, + HWND hwnd, + DWORD flags, + D3DPRESENT_PARAMETERS *pp, + IDirect3DDevice9 **pdev); -static HRESULT STDCALL my_CreateTexture(IDirect3DDevice9* self, UINT width, UINT height, UINT levels, DWORD usage, - D3DFORMAT format, D3DPOOL pool, IDirect3DTexture9** texture, HANDLE* shared_handle); +static HRESULT STDCALL my_CreateTexture( + IDirect3DDevice9 *self, + UINT width, + UINT height, + UINT levels, + DWORD usage, + D3DFORMAT format, + D3DPOOL pool, + IDirect3DTexture9 **texture, + HANDLE *shared_handle); -static HRESULT STDCALL my_BeginScene(IDirect3DDevice9* self); +static HRESULT STDCALL my_BeginScene(IDirect3DDevice9 *self); -static HRESULT STDCALL my_EndScene(IDirect3DDevice9* self); +static HRESULT STDCALL my_EndScene(IDirect3DDevice9 *self); -static HRESULT STDCALL my_Present(IDirect3DDevice9* self, - CONST RECT *pSourceRect, CONST RECT *pDestRect, - HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion); +static HRESULT STDCALL my_Present( + IDirect3DDevice9 *self, + CONST RECT *pSourceRect, + CONST RECT *pDestRect, + HWND hDestWindowOverride, + CONST RGNDATA *pDirtyRegion); -static HRESULT STDCALL my_SetRenderState(IDirect3DDevice9* self, - D3DRENDERSTATETYPE State, DWORD Value); +static HRESULT STDCALL my_SetRenderState( + IDirect3DDevice9 *self, D3DRENDERSTATETYPE State, DWORD Value); static HRESULT STDCALL my_DrawPrimitiveUP( - IDirect3DDevice9* self, D3DPRIMITIVETYPE primitive_type, - UINT primitive_count, const void *data, UINT stride); + IDirect3DDevice9 *self, + D3DPRIMITIVETYPE primitive_type, + UINT primitive_count, + const void *data, + UINT stride); -/* ------------------------------------------------------------------------------------------------------------------ */ +/* ------------------------------------------------------------------------------------------------------------------ + */ static const struct hook_symbol hook_d3d9_hook_syms[] = { - { - .name = "Direct3DCreate9", - .patch = my_Direct3DCreate9, - .link = (void **) &real_Direct3DCreate9 - }, + {.name = "Direct3DCreate9", + .patch = my_Direct3DCreate9, + .link = (void **) &real_Direct3DCreate9}, }; static const struct hook_symbol hook_d3d9_hook_user32_syms[] = { - { - .name = "EnumDisplayDevicesA", - .patch = my_EnumDisplayDevicesA, - .link = (void **) &real_EnumDisplayDevicesA - }, - { - .name = "CreateWindowExA", - .patch = my_CreateWindowExA, - .link = (void **) &real_CreateWindowExA - }, - { - .name = "GetClientRect", - .patch = my_GetClientRect, - .link = (void **) &real_GetClientRect - }, + {.name = "EnumDisplayDevicesA", + .patch = my_EnumDisplayDevicesA, + .link = (void **) &real_EnumDisplayDevicesA}, + {.name = "CreateWindowExA", + .patch = my_CreateWindowExA, + .link = (void **) &real_CreateWindowExA}, + {.name = "GetClientRect", + .patch = my_GetClientRect, + .link = (void **) &real_GetClientRect}, }; -/* ------------------------------------------------------------------------------------------------------------------ */ +/* ------------------------------------------------------------------------------------------------------------------ + */ -static HRESULT hook_d3d9_irp_handler_real_invalid(struct hook_d3d9_irp* irp); +static HRESULT hook_d3d9_irp_handler_real_invalid(struct hook_d3d9_irp *irp); -static HRESULT hook_d3d9_irp_handler_real_ctx_create(struct hook_d3d9_irp* irp); +static HRESULT hook_d3d9_irp_handler_real_ctx_create(struct hook_d3d9_irp *irp); -static HRESULT hook_d3d9_irp_handler_real_enum_display_devices(struct hook_d3d9_irp* irp); +static HRESULT +hook_d3d9_irp_handler_real_enum_display_devices(struct hook_d3d9_irp *irp); -static HRESULT hook_d3d9_irp_handler_real_create_window_ex(struct hook_d3d9_irp* irp); +static HRESULT +hook_d3d9_irp_handler_real_create_window_ex(struct hook_d3d9_irp *irp); -static HRESULT hook_d3d9_irp_handler_real_get_client_rect(struct hook_d3d9_irp* irp); +static HRESULT +hook_d3d9_irp_handler_real_get_client_rect(struct hook_d3d9_irp *irp); -static HRESULT hook_d3d9_irp_handler_real_dev_create_device(struct hook_d3d9_irp* irp); +static HRESULT +hook_d3d9_irp_handler_real_dev_create_device(struct hook_d3d9_irp *irp); -static HRESULT hook_d3d9_irp_handler_real_dev_create_texture(struct hook_d3d9_irp* irp); +static HRESULT +hook_d3d9_irp_handler_real_dev_create_texture(struct hook_d3d9_irp *irp); -static HRESULT hook_d3d9_irp_handler_real_dev_begin_scene(struct hook_d3d9_irp* irp); +static HRESULT +hook_d3d9_irp_handler_real_dev_begin_scene(struct hook_d3d9_irp *irp); -static HRESULT hook_d3d9_irp_handler_real_dev_end_scene(struct hook_d3d9_irp* irp); +static HRESULT +hook_d3d9_irp_handler_real_dev_end_scene(struct hook_d3d9_irp *irp); -static HRESULT hook_d3d9_irp_handler_real_dev_present(struct hook_d3d9_irp* irp); +static HRESULT +hook_d3d9_irp_handler_real_dev_present(struct hook_d3d9_irp *irp); -static HRESULT hook_d3d9_irp_handler_real_dev_set_render_state(struct hook_d3d9_irp* irp); +static HRESULT +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_draw_primitive_up(struct hook_d3d9_irp *irp); -/* ------------------------------------------------------------------------------------------------------------------ */ +/* ------------------------------------------------------------------------------------------------------------------ + */ static const hook_d3d9_irp_handler_t hook_d3d9_irp_real_handlers[] = { [HOOK_D3D9_IRP_OP_INVALID] = hook_d3d9_irp_handler_real_invalid, [HOOK_D3D9_IRP_OP_CTX_CREATE] = hook_d3d9_irp_handler_real_ctx_create, - [HOOK_D3D9_IRP_OP_ENUM_DISPLAY_DEVICES] = hook_d3d9_irp_handler_real_enum_display_devices, - [HOOK_D3D9_IRP_OP_CREATE_WINDOW_EX] = hook_d3d9_irp_handler_real_create_window_ex, - [HOOK_D3D9_IRP_OP_GET_CLIENT_RECT] = hook_d3d9_irp_handler_real_get_client_rect, - [HOOK_D3D9_IRP_OP_CTX_CREATE_DEVICE] = hook_d3d9_irp_handler_real_dev_create_device, - [HOOK_D3D9_IRP_OP_DEV_CREATE_TEXTURE] = hook_d3d9_irp_handler_real_dev_create_texture, - [HOOK_D3D9_IRP_OP_DEV_BEGIN_SCENE] = hook_d3d9_irp_handler_real_dev_begin_scene, + [HOOK_D3D9_IRP_OP_ENUM_DISPLAY_DEVICES] = + hook_d3d9_irp_handler_real_enum_display_devices, + [HOOK_D3D9_IRP_OP_CREATE_WINDOW_EX] = + hook_d3d9_irp_handler_real_create_window_ex, + [HOOK_D3D9_IRP_OP_GET_CLIENT_RECT] = + hook_d3d9_irp_handler_real_get_client_rect, + [HOOK_D3D9_IRP_OP_CTX_CREATE_DEVICE] = + hook_d3d9_irp_handler_real_dev_create_device, + [HOOK_D3D9_IRP_OP_DEV_CREATE_TEXTURE] = + hook_d3d9_irp_handler_real_dev_create_texture, + [HOOK_D3D9_IRP_OP_DEV_BEGIN_SCENE] = + hook_d3d9_irp_handler_real_dev_begin_scene, [HOOK_D3D9_IRP_OP_DEV_END_SCENE] = hook_d3d9_irp_handler_real_dev_end_scene, [HOOK_D3D9_IRP_OP_DEV_PRESENT] = hook_d3d9_irp_handler_real_dev_present, - [HOOK_D3D9_IRP_OP_DEV_SET_RENDER_STATE] = 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_SET_RENDER_STATE] = + 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, }; -static const hook_d3d9_irp_handler_t* hook_d3d9_handlers; +static const hook_d3d9_irp_handler_t *hook_d3d9_handlers; static size_t hook_d3d9_nhandlers; -/* ------------------------------------------------------------------------------------------------------------------ */ +/* ------------------------------------------------------------------------------------------------------------------ + */ -static IDirect3D9* STDCALL my_Direct3DCreate9(UINT sdk_ver) +static IDirect3D9 *STDCALL my_Direct3DCreate9(UINT sdk_ver) { struct hook_d3d9_irp irp; HRESULT hr; @@ -172,7 +246,8 @@ static IDirect3D9* STDCALL my_Direct3DCreate9(UINT sdk_ver) } } -static BOOL STDCALL my_EnumDisplayDevicesA(const char *dev_name, DWORD dev_num, DISPLAY_DEVICEA *info, DWORD flags) +static BOOL STDCALL my_EnumDisplayDevicesA( + const char *dev_name, DWORD dev_num, DISPLAY_DEVICEA *info, DWORD flags) { struct hook_d3d9_irp irp; HRESULT hr; @@ -195,9 +270,18 @@ static BOOL STDCALL my_EnumDisplayDevicesA(const char *dev_name, DWORD dev_num, } static HWND STDCALL my_CreateWindowExA( - DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, - int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, - HINSTANCE hInstance, LPVOID lpParam) + DWORD dwExStyle, + LPCSTR lpClassName, + LPCSTR lpWindowName, + DWORD dwStyle, + int X, + int Y, + int nWidth, + int nHeight, + HWND hWndParent, + HMENU hMenu, + HINSTANCE hInstance, + LPVOID lpParam) { struct hook_d3d9_irp irp; HRESULT hr; @@ -225,7 +309,7 @@ static HWND STDCALL my_CreateWindowExA( return irp.args.create_window_ex.result; } else { return NULL; - } + } } static BOOL STDCALL my_GetClientRect(HWND hWnd, LPRECT lpRect) @@ -249,8 +333,13 @@ static BOOL STDCALL my_GetClientRect(HWND hWnd, LPRECT lpRect) } static HRESULT STDCALL my_CreateDevice( - IDirect3D9 *self, UINT adapter, D3DDEVTYPE type, HWND hwnd, DWORD flags, - D3DPRESENT_PARAMETERS *pp, IDirect3DDevice9 **pdev) + IDirect3D9 *self, + UINT adapter, + D3DDEVTYPE type, + HWND hwnd, + DWORD flags, + D3DPRESENT_PARAMETERS *pp, + IDirect3DDevice9 **pdev) { struct hook_d3d9_irp irp; HRESULT hr; @@ -271,8 +360,16 @@ static HRESULT STDCALL my_CreateDevice( return hr; } -static HRESULT STDCALL my_CreateTexture(IDirect3DDevice9* self, UINT width, UINT height, UINT levels, DWORD usage, - D3DFORMAT format, D3DPOOL pool, IDirect3DTexture9** texture, HANDLE* shared_handle) +static HRESULT STDCALL my_CreateTexture( + IDirect3DDevice9 *self, + UINT width, + UINT height, + UINT levels, + DWORD usage, + D3DFORMAT format, + D3DPOOL pool, + IDirect3DTexture9 **texture, + HANDLE *shared_handle) { struct hook_d3d9_irp irp; HRESULT hr; @@ -295,7 +392,7 @@ static HRESULT STDCALL my_CreateTexture(IDirect3DDevice9* self, UINT width, UINT return hr; } -static HRESULT STDCALL my_BeginScene(IDirect3DDevice9* self) +static HRESULT STDCALL my_BeginScene(IDirect3DDevice9 *self) { struct hook_d3d9_irp irp; HRESULT hr; @@ -310,7 +407,7 @@ static HRESULT STDCALL my_BeginScene(IDirect3DDevice9* self) return hr; } -static HRESULT STDCALL my_EndScene(IDirect3DDevice9* self) +static HRESULT STDCALL my_EndScene(IDirect3DDevice9 *self) { struct hook_d3d9_irp irp; HRESULT hr; @@ -325,9 +422,12 @@ static HRESULT STDCALL my_EndScene(IDirect3DDevice9* self) return hr; } -static HRESULT STDCALL my_Present(IDirect3DDevice9* self, - CONST RECT *pSourceRect, CONST RECT *pDestRect, - HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion) +static HRESULT STDCALL my_Present( + IDirect3DDevice9 *self, + CONST RECT *pSourceRect, + CONST RECT *pDestRect, + HWND hDestWindowOverride, + CONST RGNDATA *pDirtyRegion) { struct hook_d3d9_irp irp; HRESULT hr; @@ -346,8 +446,8 @@ static HRESULT STDCALL my_Present(IDirect3DDevice9* self, return hr; } -static HRESULT STDCALL my_SetRenderState(IDirect3DDevice9* self, - D3DRENDERSTATETYPE State, DWORD Value) +static HRESULT STDCALL +my_SetRenderState(IDirect3DDevice9 *self, D3DRENDERSTATETYPE State, DWORD Value) { struct hook_d3d9_irp irp; HRESULT hr; @@ -361,12 +461,15 @@ static HRESULT STDCALL my_SetRenderState(IDirect3DDevice9* self, hr = hook_d3d9_irp_invoke_next(&irp); - return hr; + return hr; } static HRESULT STDCALL my_DrawPrimitiveUP( - IDirect3DDevice9* self, D3DPRIMITIVETYPE primitive_type, - UINT primitive_count, const void *data, UINT stride) + IDirect3DDevice9 *self, + D3DPRIMITIVETYPE primitive_type, + UINT primitive_count, + const void *data, + UINT stride) { struct hook_d3d9_irp irp; HRESULT hr; @@ -382,12 +485,13 @@ static HRESULT STDCALL my_DrawPrimitiveUP( hr = hook_d3d9_irp_invoke_next(&irp); - return hr; + return hr; } -/* ------------------------------------------------------------------------------------------------------------------ */ +/* ------------------------------------------------------------------------------------------------------------------ + */ -static HRESULT hook_d3d9_irp_handler_invoke_real(struct hook_d3d9_irp* irp) +static HRESULT hook_d3d9_irp_handler_invoke_real(struct hook_d3d9_irp *irp) { hook_d3d9_irp_handler_t handler; @@ -401,18 +505,18 @@ static HRESULT hook_d3d9_irp_handler_invoke_real(struct hook_d3d9_irp* irp) return handler(irp); } -static HRESULT hook_d3d9_irp_handler_real_invalid(struct hook_d3d9_irp* irp) +static HRESULT hook_d3d9_irp_handler_real_invalid(struct hook_d3d9_irp *irp) { log_fatal("Called invalid handler"); return E_FAIL; } -static HRESULT hook_d3d9_irp_handler_real_ctx_create(struct hook_d3d9_irp* irp) +static HRESULT hook_d3d9_irp_handler_real_ctx_create(struct hook_d3d9_irp *irp) { - IDirect3D9* api; - IDirect3D9Vtbl* api_vtbl; - struct com_proxy* api_proxy; + IDirect3D9 *api; + IDirect3D9Vtbl *api_vtbl; + struct com_proxy *api_proxy; log_assert(irp); @@ -428,22 +532,23 @@ static HRESULT hook_d3d9_irp_handler_real_ctx_create(struct hook_d3d9_irp* irp) real_CreateDevice = api_vtbl->CreateDevice; api_vtbl->CreateDevice = my_CreateDevice; - irp->args.ctx_create.ctx = (IDirect3D9*) api_proxy; + irp->args.ctx_create.ctx = (IDirect3D9 *) api_proxy; - return S_OK; + return S_OK; } -static HRESULT hook_d3d9_irp_handler_real_enum_display_devices(struct hook_d3d9_irp* irp) +static HRESULT +hook_d3d9_irp_handler_real_enum_display_devices(struct hook_d3d9_irp *irp) { BOOL res; log_assert(irp); res = real_EnumDisplayDevicesA( - irp->args.enum_display_devices.dev_name, - irp->args.enum_display_devices.dev_num, - irp->args.enum_display_devices.info, - irp->args.enum_display_devices.flags); + irp->args.enum_display_devices.dev_name, + irp->args.enum_display_devices.dev_num, + irp->args.enum_display_devices.info, + irp->args.enum_display_devices.flags); if (res == TRUE) { return S_OK; @@ -452,23 +557,24 @@ static HRESULT hook_d3d9_irp_handler_real_enum_display_devices(struct hook_d3d9_ } } -static HRESULT hook_d3d9_irp_handler_real_create_window_ex(struct hook_d3d9_irp* irp) +static HRESULT +hook_d3d9_irp_handler_real_create_window_ex(struct hook_d3d9_irp *irp) { log_assert(irp); irp->args.create_window_ex.result = real_CreateWindowExA( - irp->args.create_window_ex.ex_style, - irp->args.create_window_ex.class_name, - irp->args.create_window_ex.window_name, - irp->args.create_window_ex.style, - irp->args.create_window_ex.x, - irp->args.create_window_ex.y, - irp->args.create_window_ex.width, - irp->args.create_window_ex.height, - irp->args.create_window_ex.wnd_parent, - irp->args.create_window_ex.menu, - irp->args.create_window_ex.instance, - irp->args.create_window_ex.param); + irp->args.create_window_ex.ex_style, + irp->args.create_window_ex.class_name, + irp->args.create_window_ex.window_name, + irp->args.create_window_ex.style, + irp->args.create_window_ex.x, + irp->args.create_window_ex.y, + irp->args.create_window_ex.width, + irp->args.create_window_ex.height, + irp->args.create_window_ex.wnd_parent, + irp->args.create_window_ex.menu, + irp->args.create_window_ex.instance, + irp->args.create_window_ex.param); if (irp->args.create_window_ex.result) { return S_OK; @@ -477,15 +583,15 @@ static HRESULT hook_d3d9_irp_handler_real_create_window_ex(struct hook_d3d9_irp* } } -static HRESULT hook_d3d9_irp_handler_real_get_client_rect(struct hook_d3d9_irp* irp) +static HRESULT +hook_d3d9_irp_handler_real_get_client_rect(struct hook_d3d9_irp *irp) { BOOL res; log_assert(irp); res = real_GetClientRect( - irp->args.get_client_rect.wnd, - irp->args.get_client_rect.rect); + irp->args.get_client_rect.wnd, irp->args.get_client_rect.rect); if (res == TRUE) { return S_OK; @@ -494,23 +600,24 @@ static HRESULT hook_d3d9_irp_handler_real_get_client_rect(struct hook_d3d9_irp* } } -static HRESULT hook_d3d9_irp_handler_real_dev_create_device(struct hook_d3d9_irp* irp) +static HRESULT +hook_d3d9_irp_handler_real_dev_create_device(struct hook_d3d9_irp *irp) { HRESULT hr; - IDirect3DDevice9* api; - IDirect3DDevice9Vtbl* api_vtbl; + IDirect3DDevice9 *api; + IDirect3DDevice9Vtbl *api_vtbl; struct com_proxy *api_proxy; log_assert(irp); hr = real_CreateDevice( - irp->args.ctx_create_device.self, - irp->args.ctx_create_device.adapter, - irp->args.ctx_create_device.type, - irp->args.ctx_create_device.hwnd, - irp->args.ctx_create_device.flags, - irp->args.ctx_create_device.pp, - irp->args.ctx_create_device.pdev); + irp->args.ctx_create_device.self, + irp->args.ctx_create_device.adapter, + irp->args.ctx_create_device.type, + irp->args.ctx_create_device.hwnd, + irp->args.ctx_create_device.flags, + irp->args.ctx_create_device.pp, + irp->args.ctx_create_device.pdev); if (hr != S_OK) { return hr; @@ -538,76 +645,82 @@ static HRESULT hook_d3d9_irp_handler_real_dev_create_device(struct hook_d3d9_irp real_DrawPrimitiveUP = api_vtbl->DrawPrimitiveUP; api_vtbl->DrawPrimitiveUP = my_DrawPrimitiveUP; - *irp->args.ctx_create_device.pdev = (IDirect3DDevice9*) api_proxy; + *irp->args.ctx_create_device.pdev = (IDirect3DDevice9 *) api_proxy; return hr; } -static HRESULT hook_d3d9_irp_handler_real_dev_create_texture(struct hook_d3d9_irp* irp) +static HRESULT +hook_d3d9_irp_handler_real_dev_create_texture(struct hook_d3d9_irp *irp) { log_assert(irp); return real_CreateTexture( - irp->args.dev_create_texture.self, - irp->args.dev_create_texture.width, - irp->args.dev_create_texture.height, - irp->args.dev_create_texture.levels, - irp->args.dev_create_texture.usage, - irp->args.dev_create_texture.format, - irp->args.dev_create_texture.pool, - irp->args.dev_create_texture.texture, - irp->args.dev_create_texture.shared_handle); + irp->args.dev_create_texture.self, + irp->args.dev_create_texture.width, + irp->args.dev_create_texture.height, + irp->args.dev_create_texture.levels, + irp->args.dev_create_texture.usage, + irp->args.dev_create_texture.format, + irp->args.dev_create_texture.pool, + irp->args.dev_create_texture.texture, + irp->args.dev_create_texture.shared_handle); } -static HRESULT hook_d3d9_irp_handler_real_dev_begin_scene(struct hook_d3d9_irp* irp) +static HRESULT +hook_d3d9_irp_handler_real_dev_begin_scene(struct hook_d3d9_irp *irp) { log_assert(irp); return real_BeginScene(irp->args.dev_begin_scene.self); } -static HRESULT hook_d3d9_irp_handler_real_dev_end_scene(struct hook_d3d9_irp* irp) +static HRESULT +hook_d3d9_irp_handler_real_dev_end_scene(struct hook_d3d9_irp *irp) { log_assert(irp); return real_EndScene(irp->args.dev_end_scene.self); } -static HRESULT hook_d3d9_irp_handler_real_dev_present(struct hook_d3d9_irp* irp) +static HRESULT hook_d3d9_irp_handler_real_dev_present(struct hook_d3d9_irp *irp) { log_assert(irp); return real_Present( - irp->args.dev_present.self, - irp->args.dev_present.source_rect, - irp->args.dev_present.dest_rect, - irp->args.dev_present.dest_window_override, - irp->args.dev_present.dirty_region); + irp->args.dev_present.self, + irp->args.dev_present.source_rect, + irp->args.dev_present.dest_rect, + irp->args.dev_present.dest_window_override, + irp->args.dev_present.dirty_region); } -static HRESULT hook_d3d9_irp_handler_real_dev_set_render_state(struct hook_d3d9_irp* irp) +static HRESULT +hook_d3d9_irp_handler_real_dev_set_render_state(struct hook_d3d9_irp *irp) { log_assert(irp); return real_SetRenderState( - irp->args.dev_set_render_state.self, - irp->args.dev_set_render_state.state, - irp->args.dev_set_render_state.value); + irp->args.dev_set_render_state.self, + irp->args.dev_set_render_state.state, + irp->args.dev_set_render_state.value); } -static HRESULT hook_d3d9_irp_handler_real_dev_draw_primitive_up(struct hook_d3d9_irp* irp) +static HRESULT +hook_d3d9_irp_handler_real_dev_draw_primitive_up(struct hook_d3d9_irp *irp) { log_assert(irp); return real_DrawPrimitiveUP( - irp->args.dev_draw_primitive_up.self, - irp->args.dev_draw_primitive_up.primitive_type, - irp->args.dev_draw_primitive_up.primitive_count, - irp->args.dev_draw_primitive_up.data, - irp->args.dev_draw_primitive_up.stride); + irp->args.dev_draw_primitive_up.self, + irp->args.dev_draw_primitive_up.primitive_type, + irp->args.dev_draw_primitive_up.primitive_count, + irp->args.dev_draw_primitive_up.data, + irp->args.dev_draw_primitive_up.stride); } -/* ------------------------------------------------------------------------------------------------------------------ */ +/* ------------------------------------------------------------------------------------------------------------------ + */ void hook_d3d9_init(const hook_d3d9_irp_handler_t *handlers, size_t nhandlers) { @@ -618,19 +731,17 @@ void hook_d3d9_init(const hook_d3d9_irp_handler_t *handlers, size_t nhandlers) hook_d3d9_nhandlers = nhandlers; hook_table_apply( - NULL, - "d3d9.dll", - hook_d3d9_hook_syms, - lengthof(hook_d3d9_hook_syms)); + NULL, "d3d9.dll", hook_d3d9_hook_syms, lengthof(hook_d3d9_hook_syms)); hook_table_apply( - NULL, - "user32.dll", - hook_d3d9_hook_user32_syms, - lengthof(hook_d3d9_hook_user32_syms)); + NULL, + "user32.dll", + hook_d3d9_hook_user32_syms, + lengthof(hook_d3d9_hook_user32_syms)); } -HRESULT hook_d3d9_irp_invoke_next(struct hook_d3d9_irp* irp) +HRESULT +hook_d3d9_irp_invoke_next(struct hook_d3d9_irp *irp) { hook_d3d9_irp_handler_t handler; HRESULT hr; diff --git a/src/main/hook/d3d9.h b/src/main/hook/d3d9.h index 1cf3881..6a89fbe 100644 --- a/src/main/hook/d3d9.h +++ b/src/main/hook/d3d9.h @@ -3,10 +3,11 @@ /** * This module hooks the d3d9 API and abstracts it using IRPs (like iohook). - * It allows hiding the COM stuff which is required to be handled when interacting with d3d9. - * Furthermore, this module supports chaining of multiple handlers and more flexible and structured - * dispatching on the available operations (more can be added when required, obviously). - * + * It allows hiding the COM stuff which is required to be handled when + * interacting with d3d9. Furthermore, this module supports chaining of multiple + * handlers and more flexible and structured dispatching on the available + * operations (more can be added when required, obviously). + * * @author icex2 */ @@ -48,16 +49,16 @@ struct hook_d3d9_irp { struct { UINT sdk_ver; // Return value of call - IDirect3D9* ctx; + IDirect3D9 *ctx; } ctx_create; /** * Params of EnumDisplayDevicesA. */ struct { - const char* dev_name; + const char *dev_name; DWORD dev_num; - DISPLAY_DEVICEA* info; + DISPLAY_DEVICEA *info; DWORD flags; } enum_display_devices; @@ -92,60 +93,60 @@ struct hook_d3d9_irp { * Params of IDirect3D9_CreateDevice. */ struct { - IDirect3D9* self; + IDirect3D9 *self; UINT adapter; D3DDEVTYPE type; HWND hwnd; DWORD flags; - D3DPRESENT_PARAMETERS* pp; - IDirect3DDevice9** pdev; + D3DPRESENT_PARAMETERS *pp; + IDirect3DDevice9 **pdev; } ctx_create_device; /** * Params of IDirect3DDevice9_CreateTexture. */ struct { - IDirect3DDevice9* self; + IDirect3DDevice9 *self; UINT width; UINT height; UINT levels; DWORD usage; D3DFORMAT format; D3DPOOL pool; - IDirect3DTexture9** texture; - HANDLE* shared_handle; + IDirect3DTexture9 **texture; + HANDLE *shared_handle; } dev_create_texture; /** * Params of IDirect3DDevice9_BeginScene. */ struct { - IDirect3DDevice9* self; + IDirect3DDevice9 *self; } dev_begin_scene; /** * Params of IDirect3DDevice9_EndScene. */ struct { - IDirect3DDevice9* self; + IDirect3DDevice9 *self; } dev_end_scene; /** * Params of IDirect3DDevice9_Present. */ struct { - IDirect3DDevice9* self; - CONST RECT* source_rect; - CONST RECT* dest_rect; + IDirect3DDevice9 *self; + CONST RECT *source_rect; + CONST RECT *dest_rect; HWND dest_window_override; - CONST RGNDATA* dirty_region; + CONST RGNDATA *dirty_region; } dev_present; /** * Params of IDirect3DDevice9_SetRenderState. */ struct { - IDirect3DDevice9* self; + IDirect3DDevice9 *self; D3DRENDERSTATETYPE state; DWORD value; } dev_set_render_state; @@ -154,9 +155,9 @@ struct hook_d3d9_irp { * Params of IDirect3DDevice9_DrawPrimitiveUP. */ struct { - IDirect3DDevice9* self; + IDirect3DDevice9 *self; D3DPRIMITIVETYPE primitive_type; - UINT primitive_count; + UINT primitive_count; const void *data; UINT stride; } dev_draw_primitive_up; @@ -168,25 +169,28 @@ struct hook_d3d9_irp { /** * D3D9 IRP handler function typedef. */ -typedef HRESULT (*hook_d3d9_irp_handler_t)(struct hook_d3d9_irp* irp); +typedef HRESULT (*hook_d3d9_irp_handler_t)(struct hook_d3d9_irp *irp); /** * Initialize the d3d9 hook module. - * - * @param handlers The handlers to install which will be called once one of the hooked functions is called. - * @param nhandlers Number of handlers to install (length of provided array above). + * + * @param handlers The handlers to install which will be called once one of the + * hooked functions is called. + * @param nhandlers Number of handlers to install (length of provided array + * above). */ void hook_d3d9_init(const hook_d3d9_irp_handler_t *handlers, size_t nhandlers); /** * Main invoke next function. - * - * Call this from your handlers if you are done handling and to pass on the IRP to the further installed IRP handlers. - * At the end of the chain, calls the real function. - * + * + * Call this from your handlers if you are done handling and to pass on the IRP + * to the further installed IRP handlers. At the end of the chain, calls the + * real function. + * * @param irp Pointer to a valid IRP. * @return S_OK on success, error otherwise (depending on the irp op). */ -HRESULT hook_d3d9_irp_invoke_next(struct hook_d3d9_irp* irp); +HRESULT hook_d3d9_irp_invoke_next(struct hook_d3d9_irp *irp); #endif \ No newline at end of file diff --git a/src/main/hook/iohook.c b/src/main/hook/iohook.c index a0fee58..9a76e34 100644 --- a/src/main/hook/iohook.c +++ b/src/main/hook/iohook.c @@ -14,10 +14,8 @@ /* Helpers */ -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 irp_invoke_real(struct irp *irp); static HRESULT irp_invoke_real_open(struct irp *irp); @@ -33,99 +31,95 @@ static HRESULT irp_invoke_real_ioctl(struct irp *irp); static BOOL STDCALL my_CloseHandle(HANDLE fd); static HANDLE STDCALL my_CreateFileW( - const wchar_t *lpFileName, - uint32_t dwDesiredAccess, - uint32_t dwShareMode, - SECURITY_ATTRIBUTES *lpSecurityAttributes, - uint32_t dwCreationDisposition, - uint32_t dwFlagsAndAttributes, - HANDLE hTemplateFile); + const wchar_t *lpFileName, + uint32_t dwDesiredAccess, + uint32_t dwShareMode, + SECURITY_ATTRIBUTES *lpSecurityAttributes, + uint32_t dwCreationDisposition, + uint32_t dwFlagsAndAttributes, + HANDLE hTemplateFile); static HANDLE STDCALL my_CreateFileA( - const char *lpFileName, - uint32_t dwDesiredAccess, - uint32_t dwShareMode, - SECURITY_ATTRIBUTES *lpSecurityAttributes, - uint32_t dwCreationDisposition, - uint32_t dwFlagsAndAttributes, - HANDLE hTemplateFile); + const char *lpFileName, + uint32_t dwDesiredAccess, + uint32_t dwShareMode, + SECURITY_ATTRIBUTES *lpSecurityAttributes, + uint32_t dwCreationDisposition, + uint32_t dwFlagsAndAttributes, + HANDLE hTemplateFile); static BOOL STDCALL my_ReadFile( - HANDLE hFile, - void *lpBuffer, - uint32_t nNumberOfBytesToRead, - uint32_t *lpNumberOfBytesRead, - OVERLAPPED *lpOverlapped); + HANDLE hFile, + void *lpBuffer, + uint32_t nNumberOfBytesToRead, + uint32_t *lpNumberOfBytesRead, + OVERLAPPED *lpOverlapped); static BOOL STDCALL my_WriteFile( - HANDLE hFile, - const void *lpBuffer, - uint32_t nNumberOfBytesToWrite, - uint32_t *lpNumberOfBytesWritten, - OVERLAPPED *lpOverlapped); + HANDLE hFile, + const void *lpBuffer, + uint32_t nNumberOfBytesToWrite, + uint32_t *lpNumberOfBytesWritten, + OVERLAPPED *lpOverlapped); static DWORD STDCALL my_SetFilePointer( - HANDLE hFile, - int32_t lDistanceToMove, - int32_t *lpDistanceToMoveHigh, - uint32_t dwMoveMethod); + HANDLE hFile, + int32_t lDistanceToMove, + int32_t *lpDistanceToMoveHigh, + uint32_t dwMoveMethod); static BOOL STDCALL my_FlushFileBuffers(HANDLE hFile); static BOOL STDCALL my_DeviceIoControl( - HANDLE hFile, - uint32_t dwIoControlCode, - void *lpInBuffer, - uint32_t nInBufferSize, - void *lpOutBuffer, - uint32_t nOutBufferSize, - uint32_t *lpBytesReturned, - OVERLAPPED *lpOverlapped); + HANDLE hFile, + uint32_t dwIoControlCode, + void *lpInBuffer, + uint32_t nInBufferSize, + void *lpOutBuffer, + uint32_t nOutBufferSize, + uint32_t *lpBytesReturned, + OVERLAPPED *lpOverlapped); /* Links */ -static BOOL (STDCALL *real_CloseHandle)(HANDLE fd); +static BOOL(STDCALL *real_CloseHandle)(HANDLE fd); -static HANDLE (STDCALL *real_CreateFileW)( - const wchar_t *filename, - uint32_t access, - uint32_t share, - SECURITY_ATTRIBUTES *sa, - uint32_t creation, - uint32_t flags, - HANDLE tmpl); +static HANDLE(STDCALL *real_CreateFileW)( + const wchar_t *filename, + uint32_t access, + uint32_t share, + SECURITY_ATTRIBUTES *sa, + uint32_t creation, + uint32_t flags, + HANDLE tmpl); -static BOOL (STDCALL *real_DeviceIoControl)( - HANDLE fd, - uint32_t code, - void *in_bytes, - uint32_t in_nbytes, - void *out_bytes, - uint32_t out_nbytes, - uint32_t *out_returned, - OVERLAPPED *ovl); +static BOOL(STDCALL *real_DeviceIoControl)( + HANDLE fd, + uint32_t code, + void *in_bytes, + uint32_t in_nbytes, + void *out_bytes, + uint32_t out_nbytes, + uint32_t *out_returned, + OVERLAPPED *ovl); -static BOOL (STDCALL *real_ReadFile)( - HANDLE fd, - void *buf, - uint32_t nbytes, - uint32_t *nread, - OVERLAPPED *ovl); +static BOOL(STDCALL *real_ReadFile)( + HANDLE fd, void *buf, uint32_t nbytes, uint32_t *nread, OVERLAPPED *ovl); -static BOOL (STDCALL *real_WriteFile)( - HANDLE fd, - const void *buf, - uint32_t nbytes, - uint32_t *nwrit, - OVERLAPPED *ovl); +static BOOL(STDCALL *real_WriteFile)( + HANDLE fd, + const void *buf, + uint32_t nbytes, + uint32_t *nwrit, + OVERLAPPED *ovl); -static DWORD (STDCALL *real_SetFilePointer)( - HANDLE hFile, - int32_t lDistanceToMove, - int32_t *lpDistanceToMoveHigh, - uint32_t dwMoveMethod); +static DWORD(STDCALL *real_SetFilePointer)( + HANDLE hFile, + int32_t lDistanceToMove, + int32_t *lpDistanceToMoveHigh, + uint32_t dwMoveMethod); -static BOOL (STDCALL *real_FlushFileBuffers)(HANDLE fd); +static BOOL(STDCALL *real_FlushFileBuffers)(HANDLE fd); /* Hook table */ @@ -133,54 +127,54 @@ static struct hook_symbol iohook_kernel32_syms[] = { /* Basic IO */ { - .name = "CloseHandle", - .patch = my_CloseHandle, - .link = (void *) &real_CloseHandle, + .name = "CloseHandle", + .patch = my_CloseHandle, + .link = (void *) &real_CloseHandle, }, { - .name = "CreateFileA", - .patch = my_CreateFileA, + .name = "CreateFileA", + .patch = my_CreateFileA, }, { - .name = "CreateFileW", - .patch = my_CreateFileW, - .link = (void *) &real_CreateFileW, + .name = "CreateFileW", + .patch = my_CreateFileW, + .link = (void *) &real_CreateFileW, }, { - .name = "DeviceIoControl", - .patch = my_DeviceIoControl, - .link = (void *) &real_DeviceIoControl, + .name = "DeviceIoControl", + .patch = my_DeviceIoControl, + .link = (void *) &real_DeviceIoControl, }, { - .name = "ReadFile", - .patch = my_ReadFile, - .link = (void *) &real_ReadFile, + .name = "ReadFile", + .patch = my_ReadFile, + .link = (void *) &real_ReadFile, }, { - .name = "WriteFile", - .patch = my_WriteFile, - .link = (void *) &real_WriteFile, + .name = "WriteFile", + .patch = my_WriteFile, + .link = (void *) &real_WriteFile, }, { - .name = "SetFilePointer", - .patch = my_SetFilePointer, - .link = (void *) &real_SetFilePointer, + .name = "SetFilePointer", + .patch = my_SetFilePointer, + .link = (void *) &real_SetFilePointer, }, { - .name = "FlushFileBuffers", - .patch = my_FlushFileBuffers, - .link = (void *) &real_FlushFileBuffers, + .name = "FlushFileBuffers", + .patch = my_FlushFileBuffers, + .link = (void *) &real_FlushFileBuffers, }, }; static const irp_handler_t irp_real_handlers[] = { - [IRP_OP_OPEN] = irp_invoke_real_open, - [IRP_OP_CLOSE] = irp_invoke_real_close, - [IRP_OP_READ] = irp_invoke_real_read, - [IRP_OP_WRITE] = irp_invoke_real_write, - [IRP_OP_SEEK] = irp_invoke_real_seek, - [IRP_OP_FSYNC] = irp_invoke_real_fsync, - [IRP_OP_IOCTL] = irp_invoke_real_ioctl, + [IRP_OP_OPEN] = irp_invoke_real_open, + [IRP_OP_CLOSE] = irp_invoke_real_close, + [IRP_OP_READ] = irp_invoke_real_read, + [IRP_OP_WRITE] = irp_invoke_real_write, + [IRP_OP_SEEK] = irp_invoke_real_seek, + [IRP_OP_FSYNC] = irp_invoke_real_fsync, + [IRP_OP_IOCTL] = irp_invoke_real_ioctl, }; static const irp_handler_t *iohook_handlers; @@ -195,33 +189,33 @@ void iohook_init(const irp_handler_t *handlers, size_t nhandlers) iohook_nhandlers = nhandlers; hook_table_apply( - NULL, - "kernel32.dll", - iohook_kernel32_syms, - lengthof(iohook_kernel32_syms)); + NULL, + "kernel32.dll", + iohook_kernel32_syms, + lengthof(iohook_kernel32_syms)); if (real_CreateFileW == NULL) { /* my_CreateFileA requires this to be present */ real_CreateFileW = (void *) GetProcAddress( - GetModuleHandleA("kernel32.dll"), - "CreateFileW"); + GetModuleHandleA("kernel32.dll"), "CreateFileW"); } log_info("IO Hook subsystem initialized"); } -HANDLE iohook_open_dummy_fd(void) +HANDLE +iohook_open_dummy_fd(void) { HANDLE fd; fd = real_CreateFileW( - L"NUL", - GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_FLAG_OVERLAPPED, - NULL); + L"NUL", + GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_FLAG_OVERLAPPED, + NULL); if (fd == INVALID_HANDLE_VALUE) { log_fatal("Failed to open dummy fd: %08x", (uint32_t) GetLastError()); @@ -230,10 +224,8 @@ HANDLE iohook_open_dummy_fd(void) return fd; } -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 = 0; // (NTSTATUS) STATUS_SUCCESS @@ -256,7 +248,8 @@ static BOOL iohook_overlapped_result( } } -HRESULT irp_invoke_next(struct irp *irp) +HRESULT +irp_invoke_next(struct irp *irp) { irp_handler_t handler; HRESULT hr; @@ -300,13 +293,13 @@ static HRESULT irp_invoke_real_open(struct irp *irp) log_assert(irp != NULL); fd = real_CreateFileW( - irp->open_filename, - irp->open_access, - irp->open_share, - irp->open_sa, - irp->open_creation, - irp->open_flags, - irp->open_tmpl); + irp->open_filename, + irp->open_access, + irp->open_share, + irp->open_sa, + irp->open_creation, + irp->open_flags, + irp->open_tmpl); if (fd == INVALID_HANDLE_VALUE) { return hr_from_win32(); @@ -340,11 +333,11 @@ static HRESULT irp_invoke_real_read(struct irp *irp) log_assert(irp != NULL); ok = real_ReadFile( - irp->fd, - &irp->read.bytes[irp->read.pos], - irp->read.nbytes - irp->read.pos, - &nread, - irp->ovl); + irp->fd, + &irp->read.bytes[irp->read.pos], + irp->read.nbytes - irp->read.pos, + &nread, + irp->ovl); if (!ok) { return hr_from_win32(); @@ -363,11 +356,11 @@ static HRESULT irp_invoke_real_write(struct irp *irp) log_assert(irp != NULL); ok = real_WriteFile( - irp->fd, - &irp->write.bytes[irp->write.pos], - irp->write.nbytes - irp->write.pos, - &nwrit, - irp->ovl); + irp->fd, + &irp->write.bytes[irp->write.pos], + irp->write.nbytes - irp->write.pos, + &nwrit, + irp->ovl); if (!ok) { return hr_from_win32(); @@ -386,11 +379,11 @@ static HRESULT irp_invoke_real_seek(struct irp *irp) log_assert(irp != NULL); - hi = (uint32_t) (irp->seek_offset >> 32); - lo = (uint32_t) (irp->seek_offset ); + hi = (uint32_t)(irp->seek_offset >> 32); + lo = (uint32_t)(irp->seek_offset); - lo = real_SetFilePointer(irp->fd, (int32_t) lo, hi == 0 ? NULL : &hi, - irp->seek_origin); + lo = real_SetFilePointer( + irp->fd, (int32_t) lo, hi == 0 ? NULL : &hi, irp->seek_origin); if (lo == INVALID_SET_FILE_POINTER) { hr = hr_from_win32(); @@ -435,14 +428,14 @@ static HRESULT irp_invoke_real_ioctl(struct irp *irp) log_assert(irp->read.pos == 0); ok = real_DeviceIoControl( - irp->fd, - irp->ioctl, - (void *) irp->write.bytes, // Cast off const - irp->write.nbytes, - irp->read.bytes, - irp->read.nbytes, - &nread, - irp->ovl); + irp->fd, + irp->ioctl, + (void *) irp->write.bytes, // Cast off const + irp->write.nbytes, + irp->read.bytes, + irp->read.nbytes, + &nread, + irp->ovl); if (!ok) { return hr_from_win32(); @@ -454,13 +447,13 @@ static HRESULT irp_invoke_real_ioctl(struct irp *irp) } static HANDLE STDCALL my_CreateFileA( - const char *lpFileName, - uint32_t dwDesiredAccess, - uint32_t dwShareMode, - SECURITY_ATTRIBUTES *lpSecurityAttributes, - uint32_t dwCreationDisposition, - uint32_t dwFlagsAndAttributes, - HANDLE hTemplateFile) + const char *lpFileName, + uint32_t dwDesiredAccess, + uint32_t dwShareMode, + SECURITY_ATTRIBUTES *lpSecurityAttributes, + uint32_t dwCreationDisposition, + uint32_t dwFlagsAndAttributes, + HANDLE hTemplateFile) { wchar_t *wfilename; HANDLE fd; @@ -474,25 +467,26 @@ static HANDLE STDCALL my_CreateFileA( wfilename = str_widen(lpFileName); fd = my_CreateFileW( - wfilename, - dwDesiredAccess, - dwShareMode, - lpSecurityAttributes, - dwCreationDisposition, dwFlagsAndAttributes, - hTemplateFile); + wfilename, + dwDesiredAccess, + dwShareMode, + lpSecurityAttributes, + dwCreationDisposition, + dwFlagsAndAttributes, + hTemplateFile); free(wfilename); return fd; } static HANDLE STDCALL my_CreateFileW( - const wchar_t *lpFileName, - uint32_t dwDesiredAccess, - uint32_t dwShareMode, - SECURITY_ATTRIBUTES *lpSecurityAttributes, - uint32_t dwCreationDisposition, - uint32_t dwFlagsAndAttributes, - HANDLE hTemplateFile) + const wchar_t *lpFileName, + uint32_t dwDesiredAccess, + uint32_t dwShareMode, + SECURITY_ATTRIBUTES *lpSecurityAttributes, + uint32_t dwCreationDisposition, + uint32_t dwFlagsAndAttributes, + HANDLE hTemplateFile) { struct irp irp; HRESULT hr; @@ -554,11 +548,11 @@ static BOOL STDCALL my_CloseHandle(HANDLE hFile) } static BOOL STDCALL my_ReadFile( - HANDLE hFile, - void *lpBuffer, - uint32_t nNumberOfBytesToRead, - uint32_t *lpNumberOfBytesRead, - OVERLAPPED *lpOverlapped) + HANDLE hFile, + void *lpBuffer, + uint32_t nNumberOfBytesToRead, + uint32_t *lpNumberOfBytesRead, + OVERLAPPED *lpOverlapped) { struct irp irp; HRESULT hr; @@ -579,9 +573,10 @@ static BOOL STDCALL my_ReadFile( if (lpOverlapped == NULL) { if (lpNumberOfBytesRead == NULL) { - log_warning( "%s: lpNumberOfBytesRead must be supplied in " - "synchronous mode", - __func__); + log_warning( + "%s: lpNumberOfBytesRead must be supplied in " + "synchronous mode", + __func__); SetLastError(ERROR_INVALID_PARAMETER); return FALSE; @@ -607,17 +602,15 @@ static BOOL STDCALL my_ReadFile( log_assert(irp.read.pos <= irp.read.nbytes); return iohook_overlapped_result( - lpNumberOfBytesRead, - lpOverlapped, - irp.read.pos); + lpNumberOfBytesRead, lpOverlapped, irp.read.pos); } static BOOL STDCALL my_WriteFile( - HANDLE hFile, - const void *lpBuffer, - uint32_t nNumberOfBytesToWrite, - uint32_t *lpNumberOfBytesWritten, - OVERLAPPED *lpOverlapped) + HANDLE hFile, + const void *lpBuffer, + uint32_t nNumberOfBytesToWrite, + uint32_t *lpNumberOfBytesWritten, + OVERLAPPED *lpOverlapped) { struct irp irp; HRESULT hr; @@ -639,9 +632,10 @@ static BOOL STDCALL my_WriteFile( if (lpOverlapped == NULL) { if (lpNumberOfBytesWritten == NULL) { - log_warning( "%s: lpNumberOfBytesWritten must be supplied in " - "synchronous mode", - __func__); + log_warning( + "%s: lpNumberOfBytesWritten must be supplied in " + "synchronous mode", + __func__); SetLastError(ERROR_INVALID_PARAMETER); return FALSE; @@ -667,16 +661,14 @@ static BOOL STDCALL my_WriteFile( log_assert(irp.write.pos <= irp.write.nbytes); return iohook_overlapped_result( - lpNumberOfBytesWritten, - lpOverlapped, - irp.write.pos); + lpNumberOfBytesWritten, lpOverlapped, irp.write.pos); } static DWORD STDCALL my_SetFilePointer( - HANDLE hFile, - int32_t lDistanceToMove, - int32_t *lpDistanceToMoveHigh, - uint32_t dwMoveMethod) + HANDLE hFile, + int32_t lDistanceToMove, + int32_t *lpDistanceToMoveHigh, + uint32_t dwMoveMethod) { struct irp irp; HRESULT hr; @@ -698,8 +690,8 @@ static DWORD STDCALL my_SetFilePointer( with sign-extension vs zero-extension here. */ if (lpDistanceToMoveHigh != NULL) { - irp.seek_offset = ((( int64_t) *lpDistanceToMoveHigh) << 32) - | ((uint64_t) lDistanceToMove); + irp.seek_offset = (((int64_t) *lpDistanceToMoveHigh) << 32) | + ((uint64_t) lDistanceToMove); } else { irp.seek_offset = (int64_t) lDistanceToMove; } @@ -751,14 +743,14 @@ static BOOL STDCALL my_FlushFileBuffers(HANDLE hFile) } static BOOL STDCALL my_DeviceIoControl( - HANDLE hFile, - uint32_t dwIoControlCode, - void *lpInBuffer, - uint32_t nInBufferSize, - void *lpOutBuffer, - uint32_t nOutBufferSize, - uint32_t *lpBytesReturned, - OVERLAPPED *lpOverlapped) + HANDLE hFile, + uint32_t dwIoControlCode, + void *lpInBuffer, + uint32_t nInBufferSize, + void *lpOutBuffer, + uint32_t nOutBufferSize, + uint32_t *lpBytesReturned, + OVERLAPPED *lpOverlapped) { struct irp irp; HRESULT hr; @@ -773,8 +765,8 @@ static BOOL STDCALL my_DeviceIoControl( if (lpOverlapped == NULL) { if (lpBytesReturned == NULL) { log_warning( - "%s: lpBytesReturned must be supplied in synchronous mode", - __func__); + "%s: lpBytesReturned must be supplied in synchronous mode", + __func__); SetLastError(ERROR_INVALID_PARAMETER); return FALSE; @@ -809,8 +801,5 @@ static BOOL STDCALL my_DeviceIoControl( log_assert(irp.read.pos <= irp.read.nbytes); return iohook_overlapped_result( - lpBytesReturned, - lpOverlapped, - irp.read.pos); + lpBytesReturned, lpOverlapped, irp.read.pos); } - diff --git a/src/main/hook/pe.c b/src/main/hook/pe.c index f20ca74..91d6ca2 100644 --- a/src/main/hook/pe.c +++ b/src/main/hook/pe.c @@ -8,11 +8,11 @@ #include "util/log.h" -typedef BOOL (WINAPI *dll_main_t)(HMODULE, uint32_t, void *); +typedef BOOL(WINAPI *dll_main_t)(HMODULE, uint32_t, void *); static const IMAGE_NT_HEADERS *pe_get_nt_header(HMODULE pe); -static uint32_t pe_get_virtual_size(const IMAGE_SECTION_HEADER *sh, - int nsections); +static uint32_t +pe_get_virtual_size(const IMAGE_SECTION_HEADER *sh, int nsections); static void *pe_offset(void *ptr, size_t off); static const void *pe_offsetc(const void *ptr, size_t off); @@ -42,8 +42,8 @@ static const void *pe_offsetc(const void *ptr, size_t off) return base + off; } -static uint32_t pe_get_virtual_size(const IMAGE_SECTION_HEADER *sh, - int nsections) +static uint32_t +pe_get_virtual_size(const IMAGE_SECTION_HEADER *sh, int nsections) { uint32_t sec_end; uint32_t size; @@ -51,7 +51,7 @@ static uint32_t pe_get_virtual_size(const IMAGE_SECTION_HEADER *sh, size = 0; - for (i = 0 ; i < nsections ; i++) { + for (i = 0; i < nsections; i++) { sec_end = sh[i].VirtualAddress + sh[i].Misc.VirtualSize; if (size < sec_end) { @@ -79,8 +79,10 @@ const pe_iid_t *pe_iid_get_first(HMODULE pe) const IMAGE_IMPORT_DESCRIPTOR *iid; nth = pe_get_nt_header(pe); - iid = pe_offsetc(pe, nth->OptionalHeader - .DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress); + iid = pe_offsetc( + pe, + nth->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] + .VirtualAddress); if (iid == NULL || iid->Name == 0) { return NULL; @@ -107,8 +109,8 @@ const pe_iid_t *pe_iid_get_next(HMODULE pe, const pe_iid_t *iid) } } -bool pe_iid_get_iat_entry(HMODULE pe, const pe_iid_t *iid, size_t n, - struct pe_iat_entry *entry) +bool pe_iid_get_iat_entry( + HMODULE pe, const pe_iid_t *iid, size_t n, struct pe_iat_entry *entry) { const IMAGE_IMPORT_BY_NAME *import; uintptr_t *import_rvas; @@ -148,12 +150,14 @@ void pe_patch_pointer(void **ppointer, void *new_value) { DWORD old_protect; - VirtualProtect(ppointer, sizeof(void*), PAGE_EXECUTE_READWRITE, &old_protect); + VirtualProtect( + ppointer, sizeof(void *), PAGE_EXECUTE_READWRITE, &old_protect); *ppointer = new_value; - VirtualProtect(ppointer, sizeof(void*), old_protect, &old_protect); + VirtualProtect(ppointer, sizeof(void *), old_protect, &old_protect); } -HMODULE pe_explode(const uint8_t *bytes, uint32_t nbytes) +HMODULE +pe_explode(const uint8_t *bytes, uint32_t nbytes) { HMODULE base; const IMAGE_DOS_HEADER *dh; @@ -168,47 +172,58 @@ HMODULE pe_explode(const uint8_t *bytes, uint32_t nbytes) sh = pe_offsetc(bytes, dh->e_lfanew + sizeof(*nth)); virtual_size = pe_get_virtual_size(sh, nth->FileHeader.NumberOfSections); - base = (HMODULE) VirtualAlloc((void *) nth->OptionalHeader.ImageBase, - virtual_size, MEM_RESERVE, PAGE_NOACCESS); + base = (HMODULE) VirtualAlloc( + (void *) nth->OptionalHeader.ImageBase, + virtual_size, + MEM_RESERVE, + PAGE_NOACCESS); if (base == NULL) { /* Try again, allowing any base address */ - base = (HMODULE) VirtualAlloc(NULL, virtual_size, MEM_RESERVE, - PAGE_NOACCESS); + base = (HMODULE) VirtualAlloc( + NULL, virtual_size, MEM_RESERVE, PAGE_NOACCESS); if (base == NULL) { /* Aargh */ - log_fatal("Failed to VirtualAlloc %#x bytes of address space", - virtual_size); + log_fatal( + "Failed to VirtualAlloc %#x bytes of address space", + virtual_size); } } - log_misc("Exploding PE, base %p actual %p", - (void *) nth->OptionalHeader.ImageBase, - base); + log_misc( + "Exploding PE, base %p actual %p", + (void *) nth->OptionalHeader.ImageBase, + base); /* Commit header region */ - VirtualAlloc((void *) base, nth->OptionalHeader.SizeOfHeaders, MEM_COMMIT, - PAGE_READWRITE); + VirtualAlloc( + (void *) base, + nth->OptionalHeader.SizeOfHeaders, + MEM_COMMIT, + PAGE_READWRITE); memcpy(base, dh, sizeof(*dh)); memcpy(pe_offset(base, dh->e_lfanew), nth, sizeof(*nth)); - memcpy(pe_offset(base, dh->e_lfanew + sizeof(*nth)), sh, - sizeof(*sh) * nth->FileHeader.NumberOfSections); + memcpy( + pe_offset(base, dh->e_lfanew + sizeof(*nth)), + sh, + sizeof(*sh) * nth->FileHeader.NumberOfSections); - for (i = 0 ; i < nth->FileHeader.NumberOfSections ; i++) { - vflags = sh[i].Characteristics & 0x20000000 - ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; + for (i = 0; i < nth->FileHeader.NumberOfSections; i++) { + vflags = sh[i].Characteristics & 0x20000000 ? PAGE_EXECUTE_READWRITE : + PAGE_READWRITE; VirtualAlloc( - pe_offset(base, sh[i].VirtualAddress), - sh[i].Misc.VirtualSize, - MEM_COMMIT, - vflags); + pe_offset(base, sh[i].VirtualAddress), + sh[i].Misc.VirtualSize, + MEM_COMMIT, + vflags); - memcpy( pe_offset(base, sh[i].VirtualAddress), - pe_offsetc(bytes, sh[i].PointerToRawData), - sh[i].SizeOfRawData); + memcpy( + pe_offset(base, sh[i].VirtualAddress), + pe_offsetc(bytes, sh[i].PointerToRawData), + sh[i].SizeOfRawData); } return base; @@ -227,16 +242,15 @@ void pe_relocate(HMODULE pe) delta_va = (intptr_t) pe - nth->OptionalHeader.ImageBase; dde = nth->OptionalHeader.DataDirectory + IMAGE_DIRECTORY_ENTRY_BASERELOC; - for (chunk = pe_offsetc(pe, dde->VirtualAddress) - ; (void *) chunk < pe_offsetc(pe, dde->VirtualAddress + dde->Size) - ; chunk = pe_offsetc(chunk, chunk->SizeOfBlock)) { - for (reloc = (uint16_t *) (chunk + 1) - ; (void *) reloc < pe_offsetc(chunk, chunk->SizeOfBlock) - ; reloc++) { + for (chunk = pe_offsetc(pe, dde->VirtualAddress); + (void *) chunk < pe_offsetc(pe, dde->VirtualAddress + dde->Size); + chunk = pe_offsetc(chunk, chunk->SizeOfBlock)) { + for (reloc = (uint16_t *) (chunk + 1); + (void *) reloc < pe_offsetc(chunk, chunk->SizeOfBlock); + reloc++) { if (*reloc >> 12 == IMAGE_REL_BASED_HIGHLOW) { - addr_ptr = pe_offset( - pe, - chunk->VirtualAddress + (*reloc & 0x0FFF)); + addr_ptr = + pe_offset(pe, chunk->VirtualAddress + (*reloc & 0x0FFF)); *addr_ptr += delta_va; } } @@ -252,16 +266,18 @@ void *pe_get_export(HMODULE pe, const char *name, uint16_t ord) DWORD i; nth = pe_get_nt_header(pe); - ied = pe_offsetc(pe, nth->OptionalHeader - .DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress); + ied = pe_offsetc( + pe, + nth->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT] + .VirtualAddress); name_rvas = pe_offsetc(pe, ied->AddressOfNames); target_rvas = pe_offsetc(pe, ied->AddressOfFunctions); if (name != NULL) { - for (i = 0 ; i < ied->NumberOfNames ; i++) { - if (name_rvas[i] != 0 - && strcmp(pe_offsetc(pe, name_rvas[i]), name) == 0) { + for (i = 0; i < ied->NumberOfNames; i++) { + if (name_rvas[i] != 0 && + strcmp(pe_offsetc(pe, name_rvas[i]), name) == 0) { return pe_offset(pe, target_rvas[i]); } } diff --git a/src/main/hook/pe.h b/src/main/hook/pe.h index 45eb080..5fa27bf 100644 --- a/src/main/hook/pe.h +++ b/src/main/hook/pe.h @@ -17,8 +17,8 @@ struct pe_iat_entry { 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); -bool pe_iid_get_iat_entry(HMODULE pe, const pe_iid_t *iid, size_t n, - struct pe_iat_entry *entry); +bool pe_iid_get_iat_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); BOOL pe_call_dll_main(HMODULE pe, uint32_t reason, void *ctx); diff --git a/src/main/hook/peb.c b/src/main/hook/peb.c index 1f18b7b..8da6477 100644 --- a/src/main/hook/peb.c +++ b/src/main/hook/peb.c @@ -13,7 +13,6 @@ static const PEB *peb_get(void) #else return (const PEB *) __readfsdword(0x30); #endif - } const peb_dll_t *peb_dll_get_first(void) @@ -42,7 +41,8 @@ const peb_dll_t *peb_dll_get_next(const peb_dll_t *dll) return containerof(node, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks); } -HMODULE peb_dll_get_base(const peb_dll_t *dll) +HMODULE +peb_dll_get_base(const peb_dll_t *dll) { return dll->DllBase; } @@ -55,7 +55,7 @@ char *peb_dll_dup_name(const peb_dll_t *dll) wstr = &dll->FullDllName; - for (i = wstr->Length / 2 - 1 ; i > 0 ; i--) { + for (i = wstr->Length / 2 - 1; i > 0; i--) { if (wstr->Buffer[i] == L'\\') { wstr_narrow(&wstr->Buffer[i + 1], &name); @@ -65,4 +65,3 @@ char *peb_dll_dup_name(const peb_dll_t *dll) return NULL; } - diff --git a/src/main/hook/table.c b/src/main/hook/table.c index 861723b..d5d9e69 100644 --- a/src/main/hook/table.c +++ b/src/main/hook/table.c @@ -11,31 +11,24 @@ #include "util/mem.h" 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, - const pe_iid_t *iid, - const struct hook_symbol *syms, - size_t nsyms); + HMODULE target, + const pe_iid_t *iid, + const struct hook_symbol *syms, + size_t nsyms); 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) { @@ -48,10 +41,10 @@ static void hook_table_apply_to_all( } void hook_table_apply( - HMODULE target, - const char *depname, - const struct hook_symbol *syms, - size_t nsyms) + HMODULE target, + const char *depname, + const struct hook_symbol *syms, + size_t nsyms) { const pe_iid_t *iid; const char *iid_name; @@ -62,9 +55,8 @@ void hook_table_apply( hook_table_apply_to_all(depname, syms, nsyms); } else { - for ( iid = pe_iid_get_first(target) ; - iid != NULL ; - iid = pe_iid_get_next(target, iid)) { + for (iid = pe_iid_get_first(target); iid != NULL; + iid = pe_iid_get_next(target, iid)) { iid_name = pe_iid_get_name(target, iid); if (_stricmp(iid_name, depname) == 0) { @@ -75,10 +67,10 @@ void hook_table_apply( } static void hook_table_apply_to_iid( - HMODULE target, - const pe_iid_t *iid, - const struct hook_symbol *syms, - size_t nsyms) + HMODULE target, + const pe_iid_t *iid, + const struct hook_symbol *syms, + size_t nsyms) { struct pe_iat_entry iate; size_t i; @@ -88,7 +80,7 @@ static void hook_table_apply_to_iid( i = 0; while (pe_iid_get_iat_entry(target, iid, i++, &iate)) { - for (j = 0 ; j < nsyms ; j++) { + for (j = 0; j < nsyms; j++) { sym = &syms[j]; if (hook_table_match_proc(&iate, sym)) { @@ -103,12 +95,10 @@ static void hook_table_apply_to_iid( } 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 && - strcmp(sym->name, iate->name) == 0) { + if (sym->name != NULL && iate->name != NULL && + strcmp(sym->name, iate->name) == 0) { return true; } @@ -118,4 +108,3 @@ static bool hook_table_match_proc( return false; } - diff --git a/src/main/hook/table.h b/src/main/hook/table.h index 90dbc4f..6b377de 100644 --- a/src/main/hook/table.h +++ b/src/main/hook/table.h @@ -14,9 +14,9 @@ struct hook_symbol { }; void hook_table_apply( - HMODULE target, - const char *depname, - const struct hook_symbol *syms, - size_t nsyms); + HMODULE target, + const char *depname, + const struct hook_symbol *syms, + size_t nsyms); #endif diff --git a/src/main/hooklib/acp.c b/src/main/hooklib/acp.c index c07a91a..52675b2 100644 --- a/src/main/hooklib/acp.c +++ b/src/main/hooklib/acp.c @@ -10,24 +10,30 @@ #include "hooklib/acp.h" -#include "util/defs.h" #include "util/codepage.h" +#include "util/defs.h" #include "util/log.h" static NTSTATUS NTAPI my_RtlMultiByteToUnicodeN( - wchar_t *dest, unsigned long destsz, unsigned long *out_destsz, - const char *src, unsigned long srcsz); + wchar_t *dest, + unsigned long destsz, + unsigned long *out_destsz, + const char *src, + unsigned long srcsz); static const struct hook_symbol acp_hook_syms[] = { { - .name = "RtlMultiByteToUnicodeN", - .patch = my_RtlMultiByteToUnicodeN, + .name = "RtlMultiByteToUnicodeN", + .patch = my_RtlMultiByteToUnicodeN, }, }; static NTSTATUS NTAPI my_RtlMultiByteToUnicodeN( - wchar_t *dest, unsigned long destsz, unsigned long *out_destsz, - const char *src, unsigned long srcsz) + wchar_t *dest, + unsigned long destsz, + unsigned long *out_destsz, + const char *src, + unsigned long srcsz) { unsigned long result; @@ -59,4 +65,3 @@ void acp_hook_init(void) hook_table_apply(NULL, "ntdll.dll", acp_hook_syms, lengthof(acp_hook_syms)); log_info("ACP Hook enabled"); } - diff --git a/src/main/hooklib/adapter.c b/src/main/hooklib/adapter.c index 4daf1fb..082d698 100644 --- a/src/main/hooklib/adapter.c +++ b/src/main/hooklib/adapter.c @@ -1,32 +1,29 @@ -#include -#include -#include /* Required by mingw for some reason */ #include +#include /* Required by mingw for some reason */ +#include +#include #include "hook/table.h" #include "hooklib/adapter.h" -#include "util/defs.h" #include "util/codepage.h" +#include "util/defs.h" -static DWORD WINAPI my_GetAdaptersInfo( - PIP_ADAPTER_INFO adapter_info, - PULONG out_buf_len); +static DWORD WINAPI +my_GetAdaptersInfo(PIP_ADAPTER_INFO adapter_info, PULONG out_buf_len); -static DWORD(WINAPI *real_GetAdaptersInfo)(PIP_ADAPTER_INFO adapter_info, PULONG out_buf_len); +static DWORD(WINAPI *real_GetAdaptersInfo)( + PIP_ADAPTER_INFO adapter_info, PULONG out_buf_len); static const struct hook_symbol adapter_hook_syms[] = { - { - .name = "GetAdaptersInfo", - .patch = my_GetAdaptersInfo, - .link = (void *)&real_GetAdaptersInfo - }, + {.name = "GetAdaptersInfo", + .patch = my_GetAdaptersInfo, + .link = (void *) &real_GetAdaptersInfo}, }; -static DWORD WINAPI my_GetAdaptersInfo( - PIP_ADAPTER_INFO adapter_info, - PULONG out_buf_len) +static DWORD WINAPI +my_GetAdaptersInfo(PIP_ADAPTER_INFO adapter_info, PULONG out_buf_len) { DWORD ret; PMIB_IPFORWARDTABLE ip_fwd_table; @@ -40,13 +37,13 @@ static DWORD WINAPI my_GetAdaptersInfo( return ret; } - ip_fwd_table = (MIB_IPFORWARDTABLE *)malloc(sizeof(MIB_IPFORWARDTABLE)); + ip_fwd_table = (MIB_IPFORWARDTABLE *) malloc(sizeof(MIB_IPFORWARDTABLE)); table_size = 0; if (GetIpForwardTable(ip_fwd_table, &table_size, 1) == ERROR_INSUFFICIENT_BUFFER) { free(ip_fwd_table); - ip_fwd_table = (MIB_IPFORWARDTABLE *)malloc(table_size); + ip_fwd_table = (MIB_IPFORWARDTABLE *) malloc(table_size); } if (GetIpForwardTable(ip_fwd_table, &table_size, 1) != NO_ERROR || @@ -74,8 +71,5 @@ static DWORD WINAPI my_GetAdaptersInfo( void adapter_hook_init(void) { hook_table_apply( - NULL, - "iphlpapi.dll", - adapter_hook_syms, - lengthof(adapter_hook_syms)); + NULL, "iphlpapi.dll", adapter_hook_syms, lengthof(adapter_hook_syms)); } diff --git a/src/main/hooklib/app.c b/src/main/hooklib/app.c index 3a2a1a0..7ccd441 100644 --- a/src/main/hooklib/app.c +++ b/src/main/hooklib/app.c @@ -16,17 +16,17 @@ static dll_entry_init_t next_dll_entry_init; static dll_entry_main_t next_dll_entry_main; static void *(STDCALL *next_GetProcAddress)(HMODULE mod, const char *sym); -static void * STDCALL my_GetProcAddress(HMODULE mod, const char *sym); +static void *STDCALL my_GetProcAddress(HMODULE mod, const char *sym); static const struct hook_symbol mod_hooks[] = { { - .name = "GetProcAddress", - .patch = my_GetProcAddress, - .link = (void **) &next_GetProcAddress, + .name = "GetProcAddress", + .patch = my_GetProcAddress, + .link = (void **) &next_GetProcAddress, }, }; -static void * STDCALL my_GetProcAddress(HMODULE mod, const char *sym) +static void *STDCALL my_GetProcAddress(HMODULE mod, const char *sym) { void *next; @@ -76,4 +76,3 @@ bool app_hook_invoke_main(void) { return next_dll_entry_main(); } - diff --git a/src/main/hooklib/rs232.c b/src/main/hooklib/rs232.c index 3ad5148..51d0567 100644 --- a/src/main/hooklib/rs232.c +++ b/src/main/hooklib/rs232.c @@ -1,8 +1,8 @@ -#include /* Usermode API */ +#include /* Usermode API */ -#include /* Kernel-mode API for ioctls */ #include #include +#include /* Kernel-mode API for ioctls */ #include #include @@ -10,16 +10,14 @@ #include "hook/iohook.h" #include "hook/table.h" +#include "util/array.h" #include "util/hr.h" #include "util/log.h" -#include "util/array.h" /* RS232 API hooks */ -static BOOL STDCALL my_ClearCommError( - HANDLE fd, - uint32_t *errors, - COMSTAT *status); +static BOOL STDCALL +my_ClearCommError(HANDLE fd, uint32_t *errors, COMSTAT *status); static BOOL STDCALL my_EscapeCommFunction(HANDLE fd, uint32_t func); static BOOL STDCALL my_GetCommState(HANDLE fd, DCB *dcb); @@ -31,71 +29,69 @@ static BOOL STDCALL my_SetupComm(HANDLE fd, uint32_t in_q, uint32_t out_q); static BOOL STDCALL my_SetCommBreak(HANDLE fd); static BOOL STDCALL my_ClearCommBreak(HANDLE fd); -static BOOL (STDCALL *real_ClearCommError)( - HANDLE fd, - uint32_t *errors, - COMSTAT *status); +static BOOL(STDCALL *real_ClearCommError)( + HANDLE fd, uint32_t *errors, COMSTAT *status); -static BOOL (STDCALL *real_EscapeCommFunction)(HANDLE fd, uint32_t func); -static BOOL (STDCALL *real_GetCommState)(HANDLE fd, DCB *dcb); -static BOOL (STDCALL *real_PurgeComm)(HANDLE fd, uint32_t flags); -static BOOL (STDCALL *real_SetCommMask)(HANDLE fd, uint32_t mask); -static BOOL (STDCALL *real_SetCommState)(HANDLE fd, const DCB *dcb); -static BOOL (STDCALL *real_SetCommTimeouts)(HANDLE fd, COMMTIMEOUTS *timeouts); -static BOOL (STDCALL *real_SetupComm)(HANDLE fd, uint32_t in_q, uint32_t out_q); -static BOOL (STDCALL *real_SetCommBreak)(HANDLE fd); -static BOOL (STDCALL *real_ClearCommBreak)(HANDLE fd); +static BOOL(STDCALL *real_EscapeCommFunction)(HANDLE fd, uint32_t func); +static BOOL(STDCALL *real_GetCommState)(HANDLE fd, DCB *dcb); +static BOOL(STDCALL *real_PurgeComm)(HANDLE fd, uint32_t flags); +static BOOL(STDCALL *real_SetCommMask)(HANDLE fd, uint32_t mask); +static BOOL(STDCALL *real_SetCommState)(HANDLE fd, const DCB *dcb); +static BOOL(STDCALL *real_SetCommTimeouts)(HANDLE fd, COMMTIMEOUTS *timeouts); +static BOOL(STDCALL *real_SetupComm)(HANDLE fd, uint32_t in_q, uint32_t out_q); +static BOOL(STDCALL *real_SetCommBreak)(HANDLE fd); +static BOOL(STDCALL *real_ClearCommBreak)(HANDLE fd); static struct hook_symbol rs232_syms[] = { { - .name = "ClearCommError", - .patch = my_ClearCommError, - .link = (void*) &real_ClearCommError, + .name = "ClearCommError", + .patch = my_ClearCommError, + .link = (void *) &real_ClearCommError, }, { - .name = "EscapeCommFunction", - .patch = my_EscapeCommFunction, - .link = (void*) &real_EscapeCommFunction, + .name = "EscapeCommFunction", + .patch = my_EscapeCommFunction, + .link = (void *) &real_EscapeCommFunction, }, { - .name = "GetCommState", - .patch = my_GetCommState, - .link = (void*) &real_GetCommState, + .name = "GetCommState", + .patch = my_GetCommState, + .link = (void *) &real_GetCommState, }, { - .name = "PurgeComm", - .patch = my_PurgeComm, - .link = (void*) &real_PurgeComm, + .name = "PurgeComm", + .patch = my_PurgeComm, + .link = (void *) &real_PurgeComm, }, { - .name = "SetCommMask", - .patch = my_SetCommMask, - .link = (void*) &real_SetCommMask, + .name = "SetCommMask", + .patch = my_SetCommMask, + .link = (void *) &real_SetCommMask, }, { - .name = "SetCommState", - .patch = my_SetCommState, - .link = (void*) &real_SetCommState, + .name = "SetCommState", + .patch = my_SetCommState, + .link = (void *) &real_SetCommState, }, { - .name = "SetCommTimeouts", - .patch = my_SetCommTimeouts, - .link = (void*) &real_SetCommTimeouts, + .name = "SetCommTimeouts", + .patch = my_SetCommTimeouts, + .link = (void *) &real_SetCommTimeouts, }, { - .name = "SetupComm", - .patch = my_SetupComm, - .link = (void*) &real_SetupComm, + .name = "SetupComm", + .patch = my_SetupComm, + .link = (void *) &real_SetupComm, }, { - .name = "SetCommBreak", - .patch = my_SetCommBreak, - .link = (void*) &real_SetCommBreak, + .name = "SetCommBreak", + .patch = my_SetCommBreak, + .link = (void *) &real_SetCommBreak, }, { - .name = "ClearCommBreak", - .patch = my_ClearCommBreak, - .link = (void*) &real_ClearCommBreak, + .name = "ClearCommBreak", + .patch = my_ClearCommBreak, + .link = (void *) &real_ClearCommBreak, }, }; @@ -105,13 +101,14 @@ static CRITICAL_SECTION hooked_port_fds_cs; /** * Some notes: - * - * The point of this, is to allow rs232 hooks for only the descriptors that we hook. - * This is because the emulation here is incomplete. - * Although the IOCTL's do end up being passed to the real hardware, the game rejects some of the responses and hangs. - * By short circuiting out, and calling the real Comm functions instead, it works. - * And hence, card-reader passthrough works on IIDX25+/SDVX5+ finally without eamio-real - * + * + * The point of this, is to allow rs232 hooks for only the descriptors that we + * hook. This is because the emulation here is incomplete. Although the IOCTL's + * do end up being passed to the real hardware, the game rejects some of the + * responses and hangs. By short circuiting out, and calling the real Comm + * functions instead, it works. And hence, card-reader passthrough works on + * IIDX25+/SDVX5+ finally without eamio-real + * */ void rs232_hook_init(void) @@ -128,12 +125,13 @@ void rs232_hook_limit_hooks(void) rs232_limit_hooks = true; } -static BOOL rs232_check_fd(HANDLE fd) { +static BOOL rs232_check_fd(HANDLE fd) +{ HANDLE check; - if (rs232_limit_hooks){ + if (rs232_limit_hooks) { EnterCriticalSection(&hooked_port_fds_cs); - for (size_t i = 0 ; i < hooked_port_fds.nitems ; i++) { + for (size_t i = 0; i < hooked_port_fds.nitems; i++) { check = *array_item(HANDLE, &hooked_port_fds, i); if (check == fd) { LeaveCriticalSection(&hooked_port_fds_cs); @@ -155,10 +153,8 @@ void rs232_hook_add_fd(HANDLE fd) LeaveCriticalSection(&hooked_port_fds_cs); } -static BOOL STDCALL my_ClearCommError( - HANDLE fd, - uint32_t *errors, - COMSTAT *status) +static BOOL STDCALL +my_ClearCommError(HANDLE fd, uint32_t *errors, COMSTAT *status) { struct irp irp; SERIAL_STATUS llstatus; @@ -179,9 +175,7 @@ static BOOL STDCALL my_ClearCommError( if (FAILED(hr)) { log_warning( - "%s: IOCTL_SERIAL_GET_COMMSTATUS failed: %lx", - __func__, - hr); + "%s: IOCTL_SERIAL_GET_COMMSTATUS failed: %lx", __func__, hr); return hr_propagate_win32(hr, FALSE); } @@ -266,19 +260,35 @@ static BOOL STDCALL my_EscapeCommFunction(HANDLE fd, uint32_t cmd) } switch (cmd) { - case CLRBREAK: ioctl = IOCTL_SERIAL_SET_BREAK_OFF; break; - case CLRDTR: ioctl = IOCTL_SERIAL_CLR_DTR; break; - case CLRRTS: ioctl = IOCTL_SERIAL_CLR_RTS; break; - case SETBREAK: ioctl = IOCTL_SERIAL_SET_BREAK_ON; break; - case SETDTR: ioctl = IOCTL_SERIAL_SET_RTS; break; - case SETRTS: ioctl = IOCTL_SERIAL_SET_RTS; break; - case SETXOFF: ioctl = IOCTL_SERIAL_SET_XOFF; break; - case SETXON: ioctl = IOCTL_SERIAL_SET_XON; break; - default: - log_warning("%s: Invalid comm function %08x", __func__, cmd); - SetLastError(ERROR_INVALID_PARAMETER); + case CLRBREAK: + ioctl = IOCTL_SERIAL_SET_BREAK_OFF; + break; + case CLRDTR: + ioctl = IOCTL_SERIAL_CLR_DTR; + break; + case CLRRTS: + ioctl = IOCTL_SERIAL_CLR_RTS; + break; + case SETBREAK: + ioctl = IOCTL_SERIAL_SET_BREAK_ON; + break; + case SETDTR: + ioctl = IOCTL_SERIAL_SET_RTS; + break; + case SETRTS: + ioctl = IOCTL_SERIAL_SET_RTS; + break; + case SETXOFF: + ioctl = IOCTL_SERIAL_SET_XOFF; + break; + case SETXON: + ioctl = IOCTL_SERIAL_SET_XON; + break; + default: + log_warning("%s: Invalid comm function %08x", __func__, cmd); + SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; + return FALSE; } memset(&irp, 0, sizeof(irp)); @@ -326,10 +336,10 @@ static BOOL STDCALL my_GetCommState(HANDLE fd, DCB *dcb) days. So we only support the latest size of this struct. */ log_warning( - "%s: dcb->DCBlength = %d, expected %d", - __func__, - (int) dcb->DCBlength, - (unsigned int) sizeof(*dcb)); + "%s: dcb->DCBlength = %d, expected %d", + __func__, + (int) dcb->DCBlength, + (unsigned int) sizeof(*dcb)); SetLastError(ERROR_INVALID_PARAMETER); return FALSE; @@ -383,9 +393,7 @@ static BOOL STDCALL my_GetCommState(HANDLE fd, DCB *dcb) if (FAILED(hr)) { log_warning( - "%s: IOCTL_SERIAL_GET_LINE_CONTROL failed: %lx", - __func__, - hr); + "%s: IOCTL_SERIAL_GET_LINE_CONTROL failed: %lx", __func__, hr); return hr_propagate_win32(hr, FALSE); } @@ -502,7 +510,6 @@ static BOOL STDCALL my_PurgeComm(HANDLE fd, uint32_t flags) return hr_propagate_win32(hr, SUCCEEDED(hr)); } - static BOOL STDCALL my_SetCommMask(HANDLE fd, uint32_t mask) { struct irp irp; @@ -553,10 +560,10 @@ static BOOL STDCALL my_SetCommState(HANDLE fd, const DCB *dcb) days. So we only support the latest size of this struct. */ log_warning( - "%s: dcb->DCBlength = %d, expected %d", - __func__, - (int) dcb->DCBlength, - (unsigned int) sizeof(*dcb)); + "%s: dcb->DCBlength = %d, expected %d", + __func__, + (int) dcb->DCBlength, + (unsigned int) sizeof(*dcb)); SetLastError(ERROR_INVALID_PARAMETER); return FALSE; @@ -590,8 +597,10 @@ static BOOL STDCALL my_SetCommState(HANDLE fd, const DCB *dcb) break; default: - log_warning("%s: dcb->fDtrControl value %d is invalid", - __func__, dcb->fDtrControl); + log_warning( + "%s: dcb->fDtrControl value %d is invalid", + __func__, + dcb->fDtrControl); SetLastError(ERROR_INVALID_PARAMETER); return FALSE; @@ -621,9 +630,9 @@ static BOOL STDCALL my_SetCommState(HANDLE fd, const DCB *dcb) default: log_warning( - "%s: dcb->fRtsControl value %d is invalid", - __func__, - dcb->fRtsControl); + "%s: dcb->fRtsControl value %d is invalid", + __func__, + dcb->fRtsControl); SetLastError(ERROR_INVALID_PARAMETER); return FALSE; @@ -684,9 +693,7 @@ static BOOL STDCALL my_SetCommState(HANDLE fd, const DCB *dcb) if (FAILED(hr)) { log_warning( - "%s: IOCTL_SERIAL_SET_LINE_CONTROL failed: %lx", - __func__, - hr); + "%s: IOCTL_SERIAL_SET_LINE_CONTROL failed: %lx", __func__, hr); return hr_propagate_win32(hr, FALSE); } @@ -721,11 +728,11 @@ static BOOL STDCALL my_SetCommTimeouts(HANDLE fd, COMMTIMEOUTS *src) return real_SetCommTimeouts(fd, src); } - dest.ReadIntervalTimeout = src->ReadIntervalTimeout; - dest.ReadTotalTimeoutMultiplier = src->ReadTotalTimeoutMultiplier; - dest.ReadTotalTimeoutConstant = src->ReadTotalTimeoutConstant; - dest.WriteTotalTimeoutMultiplier = src->WriteTotalTimeoutMultiplier; - dest.WriteTotalTimeoutConstant = src->WriteTotalTimeoutConstant; + dest.ReadIntervalTimeout = src->ReadIntervalTimeout; + dest.ReadTotalTimeoutMultiplier = src->ReadTotalTimeoutMultiplier; + dest.ReadTotalTimeoutConstant = src->ReadTotalTimeoutConstant; + dest.WriteTotalTimeoutMultiplier = src->WriteTotalTimeoutMultiplier; + dest.WriteTotalTimeoutConstant = src->WriteTotalTimeoutConstant; memset(&irp, 0, sizeof(irp)); irp.op = IRP_OP_IOCTL; @@ -766,7 +773,8 @@ static BOOL STDCALL my_SetupComm(HANDLE fd, uint32_t in_q, uint32_t out_q) hr = irp_invoke_next(&irp); if (FAILED(hr)) { - log_warning("%s: IOCTL_SERIAL_SET_QUEUE_SIZE failed: %lx",__func__, hr); + log_warning( + "%s: IOCTL_SERIAL_SET_QUEUE_SIZE failed: %lx", __func__, hr); } return hr_propagate_win32(hr, SUCCEEDED(hr)); @@ -817,4 +825,3 @@ static BOOL STDCALL my_ClearCommBreak(HANDLE fd) return hr_propagate_win32(hr, SUCCEEDED(hr)); } - diff --git a/src/main/hooklib/setupapi.c b/src/main/hooklib/setupapi.c index 0eed34d..07dc72c 100644 --- a/src/main/hooklib/setupapi.c +++ b/src/main/hooklib/setupapi.c @@ -17,117 +17,123 @@ static BOOL STDCALL my_SetupDiDestroyDeviceInfoList(HDEVINFO dev_info); static BOOL STDCALL my_SetupDiEnumDeviceInfo( - HDEVINFO dev_info, DWORD index, SP_DEVINFO_DATA *info_data); + HDEVINFO dev_info, DWORD index, SP_DEVINFO_DATA *info_data); static BOOL STDCALL my_SetupDiEnumDeviceInterfaces( - HDEVINFO dev_info, SP_DEVINFO_DATA *info_data, const GUID *iface_guid, - DWORD index, SP_DEVICE_INTERFACE_DATA *ifd); + HDEVINFO dev_info, + SP_DEVINFO_DATA *info_data, + const GUID *iface_guid, + DWORD index, + SP_DEVICE_INTERFACE_DATA *ifd); static HDEVINFO STDCALL my_SetupDiGetClassDevsA( - const GUID *class_guid, const char *enumerator, HWND hwnd, - DWORD flags); + const GUID *class_guid, const char *enumerator, HWND hwnd, DWORD flags); static HDEVINFO STDCALL my_SetupDiGetClassDevsW( - const GUID *class_guid, PCWSTR enumerator, HWND hwnd, - DWORD flags); + const GUID *class_guid, PCWSTR enumerator, HWND hwnd, DWORD flags); static BOOL STDCALL my_SetupDiGetDeviceInterfaceDetailA( - HDEVINFO dev_info, SP_DEVICE_INTERFACE_DATA *ifd, - SP_DEVICE_INTERFACE_DETAIL_DATA_A *detail, DWORD size, - DWORD *required_size, SP_DEVINFO_DATA *info_data); + HDEVINFO dev_info, + SP_DEVICE_INTERFACE_DATA *ifd, + SP_DEVICE_INTERFACE_DETAIL_DATA_A *detail, + DWORD size, + DWORD *required_size, + SP_DEVINFO_DATA *info_data); static BOOL STDCALL my_SetupDiGetDeviceInterfaceDetailW( - HDEVINFO dev_info, SP_DEVICE_INTERFACE_DATA *ifd, - SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail, DWORD size, - DWORD *required_size, SP_DEVINFO_DATA *info_data); + HDEVINFO dev_info, + SP_DEVICE_INTERFACE_DATA *ifd, + SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail, + DWORD size, + DWORD *required_size, + SP_DEVINFO_DATA *info_data); static BOOL STDCALL my_SetupDiGetDeviceRegistryPropertyA( - HDEVINFO dev_info, SP_DEVINFO_DATA *info_data, DWORD prop_id, - DWORD *prop_type, void *bytes, DWORD nbytes, DWORD *required_nbytes); + HDEVINFO dev_info, + SP_DEVINFO_DATA *info_data, + DWORD prop_id, + DWORD *prop_type, + void *bytes, + DWORD nbytes, + DWORD *required_nbytes); /* real calls */ -static BOOL (STDCALL *real_SetupDiDestroyDeviceInfoList)( - HDEVINFO dev_info); +static BOOL(STDCALL *real_SetupDiDestroyDeviceInfoList)(HDEVINFO dev_info); -static BOOL (STDCALL *real_SetupDiEnumDeviceInfo)( - HDEVINFO dev_info, DWORD index, SP_DEVINFO_DATA *info_data); +static BOOL(STDCALL *real_SetupDiEnumDeviceInfo)( + HDEVINFO dev_info, DWORD index, SP_DEVINFO_DATA *info_data); -static BOOL (STDCALL *real_SetupDiEnumDeviceInterfaces)( - HDEVINFO dev_info, SP_DEVINFO_DATA *info_data, const GUID *iface_guid, - DWORD index, SP_DEVICE_INTERFACE_DATA *ifd); +static BOOL(STDCALL *real_SetupDiEnumDeviceInterfaces)( + HDEVINFO dev_info, + SP_DEVINFO_DATA *info_data, + const GUID *iface_guid, + DWORD index, + SP_DEVICE_INTERFACE_DATA *ifd); -static HDEVINFO (STDCALL *real_SetupDiGetClassDevsA)( - const GUID *class_guid, const char *enumerator, HWND hwnd, - DWORD flags); +static HDEVINFO(STDCALL *real_SetupDiGetClassDevsA)( + const GUID *class_guid, const char *enumerator, HWND hwnd, DWORD flags); -static HDEVINFO (STDCALL *real_SetupDiGetClassDevsW)( - const GUID *class_guid, PCWSTR enumerator, HWND hwnd, - DWORD flags); +static HDEVINFO(STDCALL *real_SetupDiGetClassDevsW)( + const GUID *class_guid, PCWSTR enumerator, HWND hwnd, DWORD flags); -static BOOL (STDCALL *real_SetupDiGetDeviceInterfaceDetailA)( - HDEVINFO dev_info, SP_DEVICE_INTERFACE_DATA *ifd, - SP_DEVICE_INTERFACE_DETAIL_DATA_A *detail, DWORD size, - DWORD *required_size, SP_DEVINFO_DATA *info_data); +static BOOL(STDCALL *real_SetupDiGetDeviceInterfaceDetailA)( + HDEVINFO dev_info, + SP_DEVICE_INTERFACE_DATA *ifd, + SP_DEVICE_INTERFACE_DETAIL_DATA_A *detail, + DWORD size, + DWORD *required_size, + SP_DEVINFO_DATA *info_data); -static BOOL (STDCALL *real_SetupDiGetDeviceInterfaceDetailW)( - HDEVINFO dev_info, SP_DEVICE_INTERFACE_DATA *ifd, - SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail, DWORD size, - DWORD *required_size, SP_DEVINFO_DATA *info_data); +static BOOL(STDCALL *real_SetupDiGetDeviceInterfaceDetailW)( + HDEVINFO dev_info, + SP_DEVICE_INTERFACE_DATA *ifd, + SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail, + DWORD size, + DWORD *required_size, + SP_DEVINFO_DATA *info_data); -static BOOL (STDCALL *real_SetupDiGetDeviceRegistryPropertyA)( - HDEVINFO dev_info, SP_DEVINFO_DATA *info_data, DWORD prop_id, - DWORD *prop_type, void *bytes, DWORD nbytes, DWORD *required_nbytes); +static BOOL(STDCALL *real_SetupDiGetDeviceRegistryPropertyA)( + HDEVINFO dev_info, + SP_DEVINFO_DATA *info_data, + DWORD prop_id, + DWORD *prop_type, + void *bytes, + DWORD nbytes, + DWORD *required_nbytes); static const struct hook_symbol setupapi_hook_syms[] = { - { - .name = "SetupDiDestroyDeviceInfoList", - .patch = my_SetupDiDestroyDeviceInfoList, - .link = (void **) &real_SetupDiDestroyDeviceInfoList - }, - { - .name = "SetupDiEnumDeviceInfo", - .patch = my_SetupDiEnumDeviceInfo, - .link = (void **) &real_SetupDiEnumDeviceInfo - }, - { - .name = "SetupDiEnumDeviceInterfaces", - .patch = my_SetupDiEnumDeviceInterfaces, - .link = (void **) &real_SetupDiEnumDeviceInterfaces - }, - { - .name = "SetupDiGetClassDevsA", - .patch = my_SetupDiGetClassDevsA, - .link = (void **) &real_SetupDiGetClassDevsA - }, - { - .name = "SetupDiGetClassDevsW", - .patch = my_SetupDiGetClassDevsW, - .link = (void **) &real_SetupDiGetClassDevsW - }, - { - .name = "SetupDiGetDeviceInterfaceDetailA", - .patch = my_SetupDiGetDeviceInterfaceDetailA, - .link = (void **) &real_SetupDiGetDeviceInterfaceDetailA - }, - { - .name = "SetupDiGetDeviceInterfaceDetailW", - .patch = my_SetupDiGetDeviceInterfaceDetailW, - .link = (void **) &real_SetupDiGetDeviceInterfaceDetailW - }, - { - .name = "SetupDiGetDeviceRegistryPropertyA", - .patch = my_SetupDiGetDeviceRegistryPropertyA, - .link = (void **) &real_SetupDiGetDeviceRegistryPropertyA - }, + {.name = "SetupDiDestroyDeviceInfoList", + .patch = my_SetupDiDestroyDeviceInfoList, + .link = (void **) &real_SetupDiDestroyDeviceInfoList}, + {.name = "SetupDiEnumDeviceInfo", + .patch = my_SetupDiEnumDeviceInfo, + .link = (void **) &real_SetupDiEnumDeviceInfo}, + {.name = "SetupDiEnumDeviceInterfaces", + .patch = my_SetupDiEnumDeviceInterfaces, + .link = (void **) &real_SetupDiEnumDeviceInterfaces}, + {.name = "SetupDiGetClassDevsA", + .patch = my_SetupDiGetClassDevsA, + .link = (void **) &real_SetupDiGetClassDevsA}, + {.name = "SetupDiGetClassDevsW", + .patch = my_SetupDiGetClassDevsW, + .link = (void **) &real_SetupDiGetClassDevsW}, + {.name = "SetupDiGetDeviceInterfaceDetailA", + .patch = my_SetupDiGetDeviceInterfaceDetailA, + .link = (void **) &real_SetupDiGetDeviceInterfaceDetailA}, + {.name = "SetupDiGetDeviceInterfaceDetailW", + .patch = my_SetupDiGetDeviceInterfaceDetailW, + .link = (void **) &real_SetupDiGetDeviceInterfaceDetailW}, + {.name = "SetupDiGetDeviceRegistryPropertyA", + .patch = my_SetupDiGetDeviceRegistryPropertyA, + .link = (void **) &real_SetupDiGetDeviceRegistryPropertyA}, }; static int hook_setupapi_fake_handle; -static const struct hook_setupapi_data* hook_setupapi_data; +static const struct hook_setupapi_data *hook_setupapi_data; static HDEVINFO STDCALL my_SetupDiGetClassDevsA( - const GUID *class_guid, const char *enumerator, HWND hwnd, - DWORD flags) + const GUID *class_guid, const char *enumerator, HWND hwnd, DWORD flags) { /* That's how iidx 9-13 detected the old C02 IO. That doesn't work on iidx 14 anymore... */ @@ -136,10 +142,12 @@ static HDEVINFO STDCALL my_SetupDiGetClassDevsA( && memcmp(class_guid, &hook_setupapi_data->device_guid, sizeof(hook_setupapi_data->device_guid)) == 0) { */ - if ((class_guid != NULL - && !memcmp(class_guid, &hook_setupapi_data->device_guid, - sizeof(hook_setupapi_data->device_guid))) || - (enumerator != NULL && !strcmp(enumerator, "USB"))) { + if ((class_guid != NULL && + !memcmp( + class_guid, + &hook_setupapi_data->device_guid, + sizeof(hook_setupapi_data->device_guid))) || + (enumerator != NULL && !strcmp(enumerator, "USB"))) { SetLastError(ERROR_SUCCESS); log_misc("SetupDiGetClassDevsA: %s", hook_setupapi_data->device_path); @@ -151,11 +159,12 @@ static HDEVINFO STDCALL my_SetupDiGetClassDevsA( } static HDEVINFO STDCALL my_SetupDiGetClassDevsW( - const GUID *class_guid, PCWSTR enumerator, HWND hwnd, - DWORD flags) + const GUID *class_guid, PCWSTR enumerator, HWND hwnd, DWORD flags) { - if (class_guid != NULL - && memcmp(class_guid, &hook_setupapi_data->device_guid, + if (class_guid != NULL && + memcmp( + class_guid, + &hook_setupapi_data->device_guid, sizeof(hook_setupapi_data->device_guid)) == 0) { SetLastError(ERROR_SUCCESS); @@ -168,7 +177,7 @@ static HDEVINFO STDCALL my_SetupDiGetClassDevsW( } static BOOL STDCALL my_SetupDiEnumDeviceInfo( - HDEVINFO dev_info, DWORD index, SP_DEVINFO_DATA *info_data) + HDEVINFO dev_info, DWORD index, SP_DEVINFO_DATA *info_data) { if (dev_info == &hook_setupapi_fake_handle) { if (index == 0) { @@ -188,8 +197,11 @@ static BOOL STDCALL my_SetupDiEnumDeviceInfo( } static BOOL STDCALL my_SetupDiEnumDeviceInterfaces( - HDEVINFO dev_info, SP_DEVINFO_DATA *info_data, const GUID *iface_guid, - DWORD index, SP_DEVICE_INTERFACE_DATA *ifd) + HDEVINFO dev_info, + SP_DEVINFO_DATA *info_data, + const GUID *iface_guid, + DWORD index, + SP_DEVICE_INTERFACE_DATA *ifd) { if (dev_info == &hook_setupapi_fake_handle) { SetLastError(ERROR_SUCCESS); @@ -198,14 +210,19 @@ static BOOL STDCALL my_SetupDiEnumDeviceInterfaces( return index == 0; } else { - return real_SetupDiEnumDeviceInterfaces(dev_info, info_data, - iface_guid, index, ifd); + return real_SetupDiEnumDeviceInterfaces( + dev_info, info_data, iface_guid, index, ifd); } } static BOOL STDCALL my_SetupDiGetDeviceRegistryPropertyA( - HDEVINFO dev_info, SP_DEVINFO_DATA *info_data, DWORD prop_id, - DWORD *prop_type, void *bytes, DWORD nbytes, DWORD *required_nbytes) + HDEVINFO dev_info, + SP_DEVINFO_DATA *info_data, + DWORD prop_id, + DWORD *prop_type, + void *bytes, + DWORD nbytes, + DWORD *required_nbytes) { if (dev_info == &hook_setupapi_fake_handle) { if (prop_id != SPDRP_DEVICEDESC) { @@ -225,7 +242,8 @@ static BOOL STDCALL my_SetupDiGetDeviceRegistryPropertyA( *prop_type = REG_SZ; if (hook_setupapi_data->device_desc) { - log_misc("SetupDiGetDeviceRegistryPropertyA: %s", + log_misc( + "SetupDiGetDeviceRegistryPropertyA: %s", hook_setupapi_data->device_desc); str_cpy(bytes, nbytes, hook_setupapi_data->device_desc); } @@ -235,15 +253,23 @@ static BOOL STDCALL my_SetupDiGetDeviceRegistryPropertyA( } else { return real_SetupDiGetDeviceRegistryPropertyA( - dev_info, info_data, prop_id, prop_type, bytes, nbytes, - required_nbytes); + dev_info, + info_data, + prop_id, + prop_type, + bytes, + nbytes, + required_nbytes); } } static BOOL STDCALL my_SetupDiGetDeviceInterfaceDetailA( - HDEVINFO dev_info, SP_DEVICE_INTERFACE_DATA *ifd, - SP_DEVICE_INTERFACE_DETAIL_DATA_A *detail, DWORD size, - DWORD *required_size, SP_DEVINFO_DATA *info_data) + HDEVINFO dev_info, + SP_DEVICE_INTERFACE_DATA *ifd, + SP_DEVICE_INTERFACE_DETAIL_DATA_A *detail, + DWORD size, + DWORD *required_size, + SP_DEVINFO_DATA *info_data) { if (dev_info == &hook_setupapi_fake_handle) { if (size == 0) { @@ -254,26 +280,32 @@ static BOOL STDCALL my_SetupDiGetDeviceInterfaceDetailA( } else { SetLastError(ERROR_SUCCESS); - log_misc("SetupDiGetDeviceInterfaceDetailA: %s", + log_misc( + "SetupDiGetDeviceInterfaceDetailA: %s", hook_setupapi_data->device_path); detail->cbSize = strlen(hook_setupapi_data->device_path); - memcpy(detail->DevicePath, hook_setupapi_data->device_path, + memcpy( + detail->DevicePath, + hook_setupapi_data->device_path, detail->cbSize); detail->DevicePath[detail->cbSize] = '\0'; return TRUE; } } else { - return real_SetupDiGetDeviceInterfaceDetailA(dev_info, ifd, detail, - size, required_size, info_data); + return real_SetupDiGetDeviceInterfaceDetailA( + dev_info, ifd, detail, size, required_size, info_data); } } static BOOL STDCALL my_SetupDiGetDeviceInterfaceDetailW( - HDEVINFO dev_info, SP_DEVICE_INTERFACE_DATA *ifd, - SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail, DWORD size, - DWORD *required_size, SP_DEVINFO_DATA *info_data) + HDEVINFO dev_info, + SP_DEVICE_INTERFACE_DATA *ifd, + SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail, + DWORD size, + DWORD *required_size, + SP_DEVINFO_DATA *info_data) { if (dev_info == &hook_setupapi_fake_handle) { if (size == 0) { @@ -284,14 +316,17 @@ static BOOL STDCALL my_SetupDiGetDeviceInterfaceDetailW( } else { SetLastError(ERROR_SUCCESS); - log_misc("SetupDiGetDeviceInterfaceDetailW: %s", + log_misc( + "SetupDiGetDeviceInterfaceDetailW: %s", hook_setupapi_data->device_path); - wchar_t* wstr_path = str_widen(hook_setupapi_data->device_path); + wchar_t *wstr_path = str_widen(hook_setupapi_data->device_path); detail->cbSize = strlen(hook_setupapi_data->device_path); - memcpy(detail->DevicePath, wstr_path, (wcslen(wstr_path) + 1) * - sizeof(wchar_t)); + memcpy( + detail->DevicePath, + wstr_path, + (wcslen(wstr_path) + 1) * sizeof(wchar_t)); detail->DevicePath[detail->cbSize] = '\0'; free(wstr_path); @@ -300,8 +335,8 @@ static BOOL STDCALL my_SetupDiGetDeviceInterfaceDetailW( } } else { - return real_SetupDiGetDeviceInterfaceDetailW(dev_info, ifd, detail, - size, required_size, info_data); + return real_SetupDiGetDeviceInterfaceDetailW( + dev_info, ifd, detail, size, required_size, info_data); } } @@ -316,15 +351,12 @@ static BOOL STDCALL my_SetupDiDestroyDeviceInfoList(HDEVINFO dev_info) } } -void hook_setupapi_init(const struct hook_setupapi_data* data) +void hook_setupapi_init(const struct hook_setupapi_data *data) { hook_table_apply( - NULL, - "setupapi.dll", - setupapi_hook_syms, - lengthof(setupapi_hook_syms)); + NULL, "setupapi.dll", setupapi_hook_syms, lengthof(setupapi_hook_syms)); hook_setupapi_data = data; - log_info("Hooked setupapi for %s, %s", data->device_path, - data->device_desc); + log_info( + "Hooked setupapi for %s, %s", data->device_path, data->device_desc); } diff --git a/src/main/hooklib/setupapi.h b/src/main/hooklib/setupapi.h index 44b9fd9..9b526f8 100644 --- a/src/main/hooklib/setupapi.h +++ b/src/main/hooklib/setupapi.h @@ -1,15 +1,15 @@ #ifndef HOOKLIB_SETUPAPI_H #define HOOKLIB_SETUPAPI_H -#include #include +#include struct hook_setupapi_data { GUID device_guid; - const char* device_desc; - const char* device_path; + const char *device_desc; + const char *device_path; }; -void hook_setupapi_init(const struct hook_setupapi_data* data); +void hook_setupapi_init(const struct hook_setupapi_data *data); #endif diff --git a/src/main/iidx-ezusb-exit-hook/main.c b/src/main/iidx-ezusb-exit-hook/main.c index a4b7c3e..a2a2177 100644 --- a/src/main/iidx-ezusb-exit-hook/main.c +++ b/src/main/iidx-ezusb-exit-hook/main.c @@ -1,5 +1,5 @@ -#include #include +#include #include #include @@ -14,25 +14,33 @@ #include "util/defs.h" static BOOL STDCALL my_DeviceIoControl( - HANDLE fd, uint32_t code, void *in_bytes, uint32_t in_nbytes, - void *out_bytes, uint32_t out_nbytes, uint32_t *out_returned, - OVERLAPPED *ovl); + HANDLE fd, + uint32_t code, + void *in_bytes, + uint32_t in_nbytes, + void *out_bytes, + uint32_t out_nbytes, + uint32_t *out_returned, + OVERLAPPED *ovl); -static BOOL (STDCALL *real_DeviceIoControl)( - HANDLE fd, uint32_t code, void *in_bytes, uint32_t in_nbytes, - void *out_bytes, uint32_t out_nbytes, uint32_t *out_returned, - OVERLAPPED *ovl); +static BOOL(STDCALL *real_DeviceIoControl)( + HANDLE fd, + uint32_t code, + void *in_bytes, + uint32_t in_nbytes, + void *out_bytes, + uint32_t out_nbytes, + uint32_t *out_returned, + OVERLAPPED *ovl); static struct hook_symbol iidxfx_hook_syms[] = { - { - .name = "DeviceIoControl", - .patch = my_DeviceIoControl, - .link = (void *) &real_DeviceIoControl - }, + {.name = "DeviceIoControl", + .patch = my_DeviceIoControl, + .link = (void *) &real_DeviceIoControl}, }; -static bool interrupt_write(HANDLE handle, - const struct ezusb_iidx_msg_interrupt_write_packet* packet) +static bool interrupt_write( + HANDLE handle, const struct ezusb_iidx_msg_interrupt_write_packet *packet) { BULK_TRANSFER_CONTROL transfer; uint32_t outpkt; @@ -40,13 +48,18 @@ static bool interrupt_write(HANDLE handle, transfer.pipeNum = EZUSB_IIDX_MSG_PIPE_INTERRUPT_OUT; return real_DeviceIoControl( - handle, IOCTL_EZUSB_BULK_WRITE, &transfer, - sizeof(transfer), (void*) packet, - sizeof(struct ezusb_iidx_msg_interrupt_write_packet), &outpkt, NULL); + handle, + IOCTL_EZUSB_BULK_WRITE, + &transfer, + sizeof(transfer), + (void *) packet, + sizeof(struct ezusb_iidx_msg_interrupt_write_packet), + &outpkt, + NULL); } -static bool bulk_write(HANDLE handle, - const struct ezusb_iidx_msg_bulk_packet* packet) +static bool +bulk_write(HANDLE handle, const struct ezusb_iidx_msg_bulk_packet *packet) { BULK_TRANSFER_CONTROL transfer; uint32_t outpkt; @@ -54,9 +67,14 @@ static bool bulk_write(HANDLE handle, transfer.pipeNum = EZUSB_IIDX_MSG_PIPE_BULK_OUT; return real_DeviceIoControl( - handle, IOCTL_EZUSB_BULK_WRITE, &transfer, - sizeof(transfer), (void*) packet, - sizeof(struct ezusb_iidx_msg_bulk_packet), &outpkt, NULL); + handle, + IOCTL_EZUSB_BULK_WRITE, + &transfer, + sizeof(transfer), + (void *) packet, + sizeof(struct ezusb_iidx_msg_bulk_packet), + &outpkt, + NULL); } static void turn_off_lights(HANDLE fd) @@ -95,30 +113,41 @@ static void turn_off_lights(HANDLE fd) } static BOOL STDCALL my_DeviceIoControl( - HANDLE fd, uint32_t code, void *in_bytes, uint32_t in_nbytes, - void *out_bytes, uint32_t out_nbytes, uint32_t *out_returned, - OVERLAPPED *ovl) + HANDLE fd, + uint32_t code, + void *in_bytes, + uint32_t in_nbytes, + void *out_bytes, + uint32_t out_nbytes, + uint32_t *out_returned, + OVERLAPPED *ovl) { BOOL result; /* Call real first to get the input data */ - result = real_DeviceIoControl(fd, code, in_bytes, in_nbytes, out_bytes, - out_nbytes, out_returned, ovl); + result = real_DeviceIoControl( + fd, + code, + in_bytes, + in_nbytes, + out_bytes, + out_nbytes, + out_returned, + ovl); if (code == IOCTL_EZUSB_BULK_READ) { const BULK_TRANSFER_CONTROL *ctl = in_bytes; /* Pipe Interrupt In */ if (ctl->pipeNum == 1) { - struct ezusb_iidx_msg_interrupt_read_packet* msg_resp = - (struct ezusb_iidx_msg_interrupt_read_packet*) out_bytes; + struct ezusb_iidx_msg_interrupt_read_packet *msg_resp = + (struct ezusb_iidx_msg_interrupt_read_packet *) out_bytes; uint32_t pad = ~msg_resp->inverted_pad; /* First (invalid) data we get from a real C02 IO board. Must be filtered to avoid instant exit trigger on boot */ if (pad != 0xFFFFFF00) { - /* Start P1 + Start P2 + VEFX + Effect */ if (((pad >> 24) & 0x0F) == 0x0F) { OutputDebugString("Triggered exit hook\n"); @@ -132,7 +161,9 @@ static BOOL STDCALL my_DeviceIoControl( /* Don't use ExitProcess. This might result in deadlocks on newer games which rely more on multi threading */ HANDLE hnd; - hnd = OpenProcess(SYNCHRONIZE | PROCESS_TERMINATE, TRUE, + hnd = OpenProcess( + SYNCHRONIZE | PROCESS_TERMINATE, + TRUE, GetCurrentProcessId()); TerminateProcess(hnd, 0); } @@ -147,11 +178,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { hook_table_apply( - NULL, - "kernel32.dll", - iidxfx_hook_syms, - lengthof(iidxfx_hook_syms)); - + NULL, "kernel32.dll", iidxfx_hook_syms, lengthof(iidxfx_hook_syms)); } return TRUE; diff --git a/src/main/iidx-ezusb2-exit-hook/main.c b/src/main/iidx-ezusb2-exit-hook/main.c index 8efc654..6af84bd 100644 --- a/src/main/iidx-ezusb2-exit-hook/main.c +++ b/src/main/iidx-ezusb2-exit-hook/main.c @@ -1,5 +1,5 @@ -#include #include +#include #include #include @@ -15,25 +15,33 @@ #define IOCTL_VEND_USB_REQ 0x220024 static BOOL STDCALL my_DeviceIoControl( - HANDLE fd, uint32_t code, void *in_bytes, uint32_t in_nbytes, - void *out_bytes, uint32_t out_nbytes, uint32_t *out_returned, - OVERLAPPED *ovl); + HANDLE fd, + uint32_t code, + void *in_bytes, + uint32_t in_nbytes, + void *out_bytes, + uint32_t out_nbytes, + uint32_t *out_returned, + OVERLAPPED *ovl); -static BOOL (STDCALL *real_DeviceIoControl)( - HANDLE fd, uint32_t code, void *in_bytes, uint32_t in_nbytes, - void *out_bytes, uint32_t out_nbytes, uint32_t *out_returned, - OVERLAPPED *ovl); +static BOOL(STDCALL *real_DeviceIoControl)( + HANDLE fd, + uint32_t code, + void *in_bytes, + uint32_t in_nbytes, + void *out_bytes, + uint32_t out_nbytes, + uint32_t *out_returned, + OVERLAPPED *ovl); static struct hook_symbol exit_hook_syms[] = { - { - .name = "DeviceIoControl", - .patch = my_DeviceIoControl, - .link = (void *) &real_DeviceIoControl - }, + {.name = "DeviceIoControl", + .patch = my_DeviceIoControl, + .link = (void *) &real_DeviceIoControl}, }; -static bool interrupt_write(HANDLE handle, - const struct ezusb2_iidx_msg_interrupt_write_packet* packet) +static bool interrupt_write( + HANDLE handle, const struct ezusb2_iidx_msg_interrupt_write_packet *packet) { SINGLE_TRANSFER usb_req; uint32_t outpkt; @@ -42,9 +50,14 @@ static bool interrupt_write(HANDLE handle, usb_req.SetupPacket.bmRequest = 0x01; return real_DeviceIoControl( - handle, IOCTL_VEND_USB_REQ, &usb_req, - sizeof(usb_req), (void*) packet, - sizeof(struct ezusb2_iidx_msg_interrupt_write_packet), &outpkt, NULL); + handle, + IOCTL_VEND_USB_REQ, + &usb_req, + sizeof(usb_req), + (void *) packet, + sizeof(struct ezusb2_iidx_msg_interrupt_write_packet), + &outpkt, + NULL); } static void turn_off_lights(HANDLE fd) @@ -65,24 +78,36 @@ static void turn_off_lights(HANDLE fd) } static BOOL STDCALL my_DeviceIoControl( - HANDLE fd, uint32_t code, void *in_bytes, uint32_t in_nbytes, - void *out_bytes, uint32_t out_nbytes, uint32_t *out_returned, - OVERLAPPED *ovl) + HANDLE fd, + uint32_t code, + void *in_bytes, + uint32_t in_nbytes, + void *out_bytes, + uint32_t out_nbytes, + uint32_t *out_returned, + OVERLAPPED *ovl) { BOOL result; /* Call real first to get the input data */ - result = real_DeviceIoControl(fd, code, in_bytes, in_nbytes, out_bytes, - out_nbytes, out_returned, ovl); + result = real_DeviceIoControl( + fd, + code, + in_bytes, + in_nbytes, + out_bytes, + out_nbytes, + out_returned, + ovl); if (code == IOCTL_VEND_USB_REQ) { PSINGLE_TRANSFER usb_req = in_bytes; /* Interrupt in endpoint */ if (usb_req->SetupPacket.bmRequest == 0x81) { - struct ezusb2_iidx_msg_interrupt_read_packet* msg_resp = - (struct ezusb2_iidx_msg_interrupt_read_packet*) - (out_bytes + sizeof(SINGLE_TRANSFER)); + struct ezusb2_iidx_msg_interrupt_read_packet *msg_resp = + (struct ezusb2_iidx_msg_interrupt_read_packet + *) (out_bytes + sizeof(SINGLE_TRANSFER)); uint32_t pad = ~msg_resp->inverted_pad; @@ -97,7 +122,9 @@ static BOOL STDCALL my_DeviceIoControl( /* Don't use ExitProcess. This might result in deadlocks on newer games which rely more on multi threading */ HANDLE hnd; - hnd = OpenProcess(SYNCHRONIZE | PROCESS_TERMINATE, TRUE, + hnd = OpenProcess( + SYNCHRONIZE | PROCESS_TERMINATE, + TRUE, GetCurrentProcessId()); TerminateProcess(hnd, 0); } @@ -111,10 +138,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { hook_table_apply( - NULL, - "kernel32.dll", - exit_hook_syms, - lengthof(exit_hook_syms)); + NULL, "kernel32.dll", exit_hook_syms, lengthof(exit_hook_syms)); } return TRUE; diff --git a/src/main/iidx-irbeat-patch/main.c b/src/main/iidx-irbeat-patch/main.c index 4a932b2..9c2f58a 100644 --- a/src/main/iidx-irbeat-patch/main.c +++ b/src/main/iidx-irbeat-patch/main.c @@ -1,7 +1,7 @@ #include -#include #include +#include #include "util/fs.h" @@ -11,197 +11,199 @@ static const uint32_t offset_data_area = 12; static const uint32_t offset_file_header_checksum = 0; static const uint32_t size_file_header = 8; -static uint32_t checksum_settings_data_09(const uint8_t* buffer) +static uint32_t checksum_settings_data_09(const uint8_t *buffer) { - uint32_t sum = 0; + uint32_t sum = 0; - for (uint32_t i = 0; i < 10; i++) { - sum += ((uint8_t) i) ^ buffer[i]; - } - sum += 10; + for (uint32_t i = 0; i < 10; i++) { + sum += ((uint8_t) i) ^ buffer[i]; + } + sum += 10; - for (uint32_t i = 0; i < 0x34; i++) { - sum += ((uint8_t) i) ^ buffer[12 + i]; - } - sum += 0x34; + for (uint32_t i = 0; i < 0x34; i++) { + sum += ((uint8_t) i) ^ buffer[12 + i]; + } + sum += 0x34; - for (uint32_t i = 0; i < 4; i++) { - sum += ((uint8_t) i) ^ buffer[64 + i]; - } - sum += 4; + for (uint32_t i = 0; i < 4; i++) { + sum += ((uint8_t) i) ^ buffer[64 + i]; + } + sum += 4; - for (uint32_t i = 0; i < 0x1E; i++) { - sum += ((uint8_t) i) ^ buffer[68 + i]; - } - sum += 0x1E; + for (uint32_t i = 0; i < 0x1E; i++) { + sum += ((uint8_t) i) ^ buffer[68 + i]; + } + sum += 0x1E; - for (uint32_t i = 0; i < 4; i++) { - sum += ((uint8_t) i) ^ buffer[100 + i]; - } - sum += 4; + for (uint32_t i = 0; i < 4; i++) { + sum += ((uint8_t) i) ^ buffer[100 + i]; + } + sum += 4; - for (uint32_t i = 0; i < 0xA; i++) { - sum += ((uint8_t) i) ^ buffer[108 + i]; - } - sum += 0xA; + for (uint32_t i = 0; i < 0xA; i++) { + sum += ((uint8_t) i) ^ buffer[108 + i]; + } + sum += 0xA; - for (uint32_t i = 0; i < 0x438; i++) { - sum += ((uint8_t) i) ^ buffer[120 + i]; - } - sum += 0x438; + for (uint32_t i = 0; i < 0x438; i++) { + sum += ((uint8_t) i) ^ buffer[120 + i]; + } + sum += 0x438; - for (uint32_t i = 0; i < 0x690; i++) { - sum += ((uint8_t) i) ^ buffer[1200 + i]; - } - sum += 0x690; + for (uint32_t i = 0; i < 0x690; i++) { + sum += ((uint8_t) i) ^ buffer[1200 + i]; + } + sum += 0x690; - return sum; + return sum; } -static uint32_t checksum_settings_data_10(const uint8_t* buffer) +static uint32_t checksum_settings_data_10(const uint8_t *buffer) { - uint32_t sum = 0; + uint32_t sum = 0; - for (uint32_t i = 0; i < 10; i++) { - sum += ((uint8_t) i) ^ buffer[i]; - } - sum += 10; + for (uint32_t i = 0; i < 10; i++) { + sum += ((uint8_t) i) ^ buffer[i]; + } + sum += 10; - for (uint32_t i = 0; i < 0x34; i++) { - sum += ((uint8_t) i) ^ buffer[12 + i]; - } - sum += 0x34; + for (uint32_t i = 0; i < 0x34; i++) { + sum += ((uint8_t) i) ^ buffer[12 + i]; + } + sum += 0x34; - for (uint32_t i = 0; i < 4; i++) { - sum += ((uint8_t) i) ^ buffer[64 + i]; - } - sum += 4; + for (uint32_t i = 0; i < 4; i++) { + sum += ((uint8_t) i) ^ buffer[64 + i]; + } + sum += 4; - for (uint32_t i = 0; i < 0x1E; i++) { - sum += ((uint8_t) i) ^ buffer[68 + i]; - } - sum += 0x1E; + for (uint32_t i = 0; i < 0x1E; i++) { + sum += ((uint8_t) i) ^ buffer[68 + i]; + } + sum += 0x1E; - for (uint32_t i = 0; i < 4; i++) { - sum += ((uint8_t) i) ^ buffer[100 + i]; - } - sum += 4; + for (uint32_t i = 0; i < 4; i++) { + sum += ((uint8_t) i) ^ buffer[100 + i]; + } + sum += 4; - for (uint32_t i = 0; i < 0xA; i++) { - sum += ((uint8_t) i) ^ buffer[108 + i]; - } - sum += 0xA; + for (uint32_t i = 0; i < 0xA; i++) { + sum += ((uint8_t) i) ^ buffer[108 + i]; + } + sum += 0xA; - for (uint32_t i = 0; i < 0x49C; i++) { - sum += ((uint8_t) i) ^ buffer[120 + i]; - } - sum += 0x49C; + for (uint32_t i = 0; i < 0x49C; i++) { + sum += ((uint8_t) i) ^ buffer[120 + i]; + } + sum += 0x49C; - for (uint32_t i = 0; i < 0x690; i++) { - sum += ((uint8_t) i) ^ buffer[1300 + i]; - } - sum += 0x690; + for (uint32_t i = 0; i < 0x690; i++) { + sum += ((uint8_t) i) ^ buffer[1300 + i]; + } + sum += 0x690; - return sum; + return sum; } -uint32_t checksum(const uint8_t* buffer, size_t length) +uint32_t checksum(const uint8_t *buffer, size_t length) { - uint32_t sum = 0; - const uint32_t* ptr = (const uint32_t*) buffer; + uint32_t sum = 0; + const uint32_t *ptr = (const uint32_t *) buffer; - for (uint32_t i = 0; i < length / 4; i++) { + for (uint32_t i = 0; i < length / 4; i++) { sum += *ptr ^ i; - ptr++; - } + ptr++; + } - return sum; + return sum; } -static void patch_09(uint8_t* buffer, uint32_t size_data_area, uint8_t irbeat) -{ - /* patch beat phase */ - buffer[0x49] = irbeat; - - // settings data checksum */ - *((uint32_t*) &buffer[0x74]) = - checksum_settings_data_09(&buffer[offset_data_area]); - - /* update data area checksum */ - *((uint32_t*) &buffer[offset_data_area_checksum]) = - checksum(&buffer[offset_data_area], size_data_area); - - /* update file checksum */ - *((uint32_t*) &buffer[offset_file_header_checksum]) = - checksum(&buffer[offset_size_data_area], size_file_header); -} - -static void patch_10(uint8_t* buffer, uint32_t size_data_area, uint8_t irbeat) +static void patch_09(uint8_t *buffer, uint32_t size_data_area, uint8_t irbeat) { /* patch beat phase */ buffer[0x49] = irbeat; - // settings data checksum */ - *((uint32_t*) &buffer[0x74]) = - checksum_settings_data_10(&buffer[offset_data_area]); + // settings data checksum */ + *((uint32_t *) &buffer[0x74]) = + checksum_settings_data_09(&buffer[offset_data_area]); /* update data area checksum */ - *((uint32_t*) &buffer[offset_data_area_checksum]) = + *((uint32_t *) &buffer[offset_data_area_checksum]) = checksum(&buffer[offset_data_area], size_data_area); - /* update file checksum */ - *((uint32_t*) &buffer[offset_file_header_checksum]) = + /* update file checksum */ + *((uint32_t *) &buffer[offset_file_header_checksum]) = + checksum(&buffer[offset_size_data_area], size_file_header); +} + +static void patch_10(uint8_t *buffer, uint32_t size_data_area, uint8_t irbeat) +{ + /* patch beat phase */ + buffer[0x49] = irbeat; + + // settings data checksum */ + *((uint32_t *) &buffer[0x74]) = + checksum_settings_data_10(&buffer[offset_data_area]); + + /* update data area checksum */ + *((uint32_t *) &buffer[offset_data_area_checksum]) = + checksum(&buffer[offset_data_area], size_data_area); + + /* update file checksum */ + *((uint32_t *) &buffer[offset_file_header_checksum]) = checksum(&buffer[offset_size_data_area], size_file_header); } int main(int argc, char **argv) { - uint8_t version; + uint8_t version; uint8_t irbeat; - const char* settings; - uint8_t* buffer; + const char *settings; + uint8_t *buffer; size_t size; uint32_t size_data_area; if (argc < 4) { - printf("Patches the IRBeat phase of 9th or 10th Style\n"); - fprintf(stderr, "Usage: %s \n", argv[0]); + printf("Patches the IRBeat phase of 9th or 10th Style\n"); + fprintf( + stderr, "Usage: %s \n", argv[0]); return -1; } - version = atoi(argv[1]); + version = atoi(argv[1]); irbeat = atoi(argv[2]); settings = argv[3]; - if (version != 9 && version != 10) { - fprintf(stderr, "Invalid game version %d\n", version); + if (version != 9 && version != 10) { + fprintf(stderr, "Invalid game version %d\n", version); return -2; - } + } if (irbeat > 2) { fprintf(stderr, "Invalid IR beat phase %d\n", irbeat); return -3; } - printf("Setting IRBeat phase %d on settings file %s\n", irbeat + 1, settings); + printf( + "Setting IRBeat phase %d on settings file %s\n", irbeat + 1, settings); - if (!file_load(settings, (void**) &buffer, &size, false)) { + if (!file_load(settings, (void **) &buffer, &size, false)) { fprintf(stderr, "Loading file %s failed\n", settings); return -4; } - size_data_area = *((uint32_t*) &buffer[offset_size_data_area]); + size_data_area = *((uint32_t *) &buffer[offset_size_data_area]); - switch (version) { - case 9: - patch_09(buffer, size_data_area, irbeat); - break; - case 10: - patch_10(buffer, size_data_area, irbeat); - break; - default: - break; - } + switch (version) { + case 9: + patch_09(buffer, size_data_area, irbeat); + break; + case 10: + patch_10(buffer, size_data_area, irbeat); + break; + default: + break; + } if (!file_save(settings, buffer, size)) { fprintf(stderr, "Saving to file %s failed\n", settings); diff --git a/src/main/iidxhook-util/acio.c b/src/main/iidxhook-util/acio.c index 0ca919c..1f0796f 100644 --- a/src/main/iidxhook-util/acio.c +++ b/src/main/iidxhook-util/acio.c @@ -1,8 +1,8 @@ #include -#include #include #include +#include #include #include @@ -38,9 +38,9 @@ void iidxhook_util_acio_init(bool legacy_mode) ac_io_emu_init(&iidxhook_util_acio_emu, L"COM1"); - for (i = 0 ; i < lengthof(iidxhook_util_acio_emu_icca) ; i++) { - ac_io_emu_icca_init(&iidxhook_util_acio_emu_icca[i], - &iidxhook_util_acio_emu, i); + for (i = 0; i < lengthof(iidxhook_util_acio_emu_icca); i++) { + ac_io_emu_icca_init( + &iidxhook_util_acio_emu_icca[i], &iidxhook_util_acio_emu, i); } rs232_hook_add_fd(iidxhook_util_acio_emu.fd); @@ -51,7 +51,8 @@ void iidxhook_util_acio_fini(void) ac_io_emu_fini(&iidxhook_util_acio_emu); } -HRESULT iidxhook_util_acio_dispatch_irp(struct irp *irp) +HRESULT +iidxhook_util_acio_dispatch_irp(struct irp *irp) { const struct ac_io_message *msg; HRESULT hr; @@ -72,33 +73,33 @@ HRESULT iidxhook_util_acio_dispatch_irp(struct irp *irp) msg = ac_io_emu_request_peek(&iidxhook_util_acio_emu); switch (msg->addr) { - case 0: - ac_io_emu_cmd_assign_addrs(&iidxhook_util_acio_emu, msg, 2); + case 0: + ac_io_emu_cmd_assign_addrs(&iidxhook_util_acio_emu, msg, 2); - break; + break; - case 1: - ac_io_emu_icca_dispatch_request(&iidxhook_util_acio_emu_icca[0], - msg); + case 1: + ac_io_emu_icca_dispatch_request( + &iidxhook_util_acio_emu_icca[0], msg); - break; + break; - case 2: - ac_io_emu_icca_dispatch_request(&iidxhook_util_acio_emu_icca[1], - msg); + case 2: + ac_io_emu_icca_dispatch_request( + &iidxhook_util_acio_emu_icca[1], msg); - break; + break; - case AC_IO_BROADCAST: - log_warning("Broadcast(?) message on IIDX ACIO bus?"); + case AC_IO_BROADCAST: + log_warning("Broadcast(?) message on IIDX ACIO bus?"); - break; + break; - default: - log_warning("ACIO message on unhandled bus address: %d", - msg->addr); + default: + log_warning( + "ACIO message on unhandled bus address: %d", msg->addr); - break; + break; } ac_io_emu_request_pop(&iidxhook_util_acio_emu); diff --git a/src/main/iidxhook-util/acio.h b/src/main/iidxhook-util/acio.h index fa6db73..bfcd900 100644 --- a/src/main/iidxhook-util/acio.h +++ b/src/main/iidxhook-util/acio.h @@ -9,7 +9,7 @@ /** * Initialize an emulated ACIO on COM1 for IIDX. - * + * * @param legacy_mode Set to true if running on slotted readers on iidx 13-18. * Old games using slotted readers might use an old libacio version that * does not support handling of multi messages per package. Instead, diff --git a/src/main/iidxhook-util/chart-patch.c b/src/main/iidxhook-util/chart-patch.c index 6014b73..22e8fdc 100644 --- a/src/main/iidxhook-util/chart-patch.c +++ b/src/main/iidxhook-util/chart-patch.c @@ -61,15 +61,15 @@ static struct chart_patch_file chart_patch_file_1; static struct chart_patch_file chart_patch_file_checksum; static CRITICAL_SECTION chart_patch_lock; -static bool chart_patch_file_load(struct irp* irp_open, - struct chart_patch_file *file, const wchar_t* path) +static bool chart_patch_file_load( + struct irp *irp_open, struct chart_patch_file *file, const wchar_t *path) { struct irp irp; void *bytes; size_t nbytes; HANDLE fd; HRESULT hr; - char* tmp; + char *tmp; /* Reset file to ensure consistent not-available state */ memset(file, 0, sizeof(struct chart_patch_file)); @@ -158,7 +158,7 @@ static bool chart_patch_file_load(struct irp* irp_open, return true; } -static bool chart_patch_is_chart_id(const wchar_t* str) +static bool chart_patch_is_chart_id(const wchar_t *str) { for (int i = 0; i < 4; i++) { if (!(str[i] >= L'0' && str[i] <= L'9')) { @@ -184,24 +184,27 @@ static void chart_patch_execute_patch_1() factor = chart_patch_hz / chart_patch_timebase; toc = (struct chart_toc_entry *) chart_patch_file_1.state.bytes; - log_misc("Patching chart: orig %f, target %f, factor %f", - chart_patch_timebase, chart_patch_hz, factor); + log_misc( + "Patching chart: orig %f, target %f, factor %f", + chart_patch_timebase, + chart_patch_hz, + factor); - for (i = 0 ; i < 12 ; i++) { + for (i = 0; i < 12; i++) { if (toc[i].offset == 0) { continue; /* No such chart */ } - for ( chart_offset = toc[i].offset ; - chart_offset < toc[i].offset + toc[i].length ; - chart_offset += sizeof(struct chart_event)) { - event = (struct chart_event *) - &chart_patch_file_1.state.bytes[chart_offset]; + for (chart_offset = toc[i].offset; + chart_offset < toc[i].offset + toc[i].length; + chart_offset += sizeof(struct chart_event)) { + event = (struct chart_event *) &chart_patch_file_1.state + .bytes[chart_offset]; /* Don't clobber the end-of-chart marker */ if (event->time != 0x7FFFFFFF) { - event->time = (uint32_t) round(event->time * factor); + event->time = (uint32_t) round(event->time * factor); } } } @@ -218,18 +221,17 @@ static void chart_patch_execute_patch_checksum() size_t i; header = (struct ospreybin *) &chart_patch_file_checksum.state.bytes[0]; - entries = (struct ospreybin_entry *) - &chart_patch_file_checksum.state.bytes[sizeof(*header)]; + entries = (struct ospreybin_entry *) &chart_patch_file_checksum.state + .bytes[sizeof(*header)]; - for (i = 0 ; i < header->num_entries ; i++) { + for (i = 0; i < header->num_entries; i++) { entry = &entries[i]; if (!str_eq(chart_patch_file_1_name, entry->filename)) { continue; } - span_start = - &chart_patch_file_1.state.bytes[entry->offset_in_file]; + span_start = &chart_patch_file_1.state.bytes[entry->offset_in_file]; span_len = entry->checksum_length; checksum = crc32(span_start, span_len, 0); @@ -242,7 +244,7 @@ static void chart_patch_execute_patch_checksum() log_warning("Could not find checksum row for %s", chart_patch_file_1_name); } -static bool chart_patch_file_trap(struct irp* irp) +static bool chart_patch_file_trap(struct irp *irp) { wchar_t buffer_1_path[1024]; wchar_t buffer_checksum_path[1024]; @@ -250,7 +252,7 @@ static bool chart_patch_file_trap(struct irp* irp) wchar_t chart_file[7]; bool is_1_file; bool is_checksum_file; - char* tmp; + char *tmp; /* This has to trap three different scenarios: 1. open .1 chart file only @@ -259,9 +261,14 @@ static bool chart_patch_file_trap(struct irp* irp) In the end, we have to serve either just the .1 file or both the .1 and checksum file from memory until the application closes one or both files */ - if (swscanf(irp->open_filename, L"..\\data\\sd_data%*[\\/]%c%c%c%c%*[\\/]", - &chart_id[0], &chart_id[1], &chart_id[2], &chart_id[3]) == 4 && - chart_patch_is_chart_id(chart_id)) { + if (swscanf( + irp->open_filename, + L"..\\data\\sd_data%*[\\/]%c%c%c%c%*[\\/]", + &chart_id[0], + &chart_id[1], + &chart_id[2], + &chart_id[3]) == 4 && + chart_patch_is_chart_id(chart_id)) { chart_id[4] = '\0'; wstr_narrow(irp->open_filename, &tmp); @@ -300,13 +307,18 @@ static bool chart_patch_file_trap(struct irp* irp) log_misc("Preparing in-memory chart %s...", tmp); free(tmp); - wsprintfW(buffer_1_path, L"..\\data\\sd_data\\\\%s\\%s.1", chart_id, + wsprintfW( + buffer_1_path, + L"..\\data\\sd_data\\\\%s\\%s.1", + chart_id, + chart_id); + wsprintfW( + buffer_checksum_path, + L"..\\data\\sd_data\\%s\\osprey.bin", chart_id); - wsprintfW(buffer_checksum_path, - L"..\\data\\sd_data\\%s\\osprey.bin", chart_id); - if (!chart_patch_file_load(irp, &chart_patch_file_1, - buffer_1_path)) { + if (!chart_patch_file_load( + irp, &chart_patch_file_1, buffer_1_path)) { wstr_narrow(buffer_1_path, &tmp); log_fatal("Cannot load .1 file %s", tmp); free(tmp); @@ -315,13 +327,13 @@ static bool chart_patch_file_trap(struct irp* irp) chart_patch_execute_patch_1(); wstr_narrow(chart_file, &tmp); - memcpy(chart_patch_file_1_name, tmp, - sizeof(chart_patch_file_1_name)); + memcpy( + chart_patch_file_1_name, tmp, sizeof(chart_patch_file_1_name)); free(tmp); /* Optional on some games */ - if (chart_patch_file_load(irp, &chart_patch_file_checksum, - buffer_checksum_path)) { + if (chart_patch_file_load( + irp, &chart_patch_file_checksum, buffer_checksum_path)) { chart_patch_execute_patch_checksum(); } @@ -349,16 +361,15 @@ static bool chart_patch_file_trap(struct irp* irp) return false; } -static HRESULT chart_patch_file_close_irp( - struct chart_patch_file *file, - struct irp *irp_close) +static HRESULT +chart_patch_file_close_irp(struct chart_patch_file *file, struct irp *irp_close) { HRESULT hr; struct irp irp; file->active = false; - // log_misc("chart_patch_file_close_irp %d %p %d %p", + // log_misc("chart_patch_file_close_irp %d %p %d %p", // chart_patch_file_1.active, // chart_patch_file_1.fd, // chart_patch_file_checksum.active, @@ -373,12 +384,12 @@ static HRESULT chart_patch_file_close_irp( irp.fd = chart_patch_file_1.fd; hr = irp_invoke_next(&irp); - + if (hr != S_OK) { log_warning("Closing dummy .1 file handle failed"); } - - free((void*) chart_patch_file_1.state.bytes); + + free((void *) chart_patch_file_1.state.bytes); memset(&chart_patch_file_1, 0, sizeof(struct chart_patch_file)); } @@ -392,9 +403,9 @@ static HRESULT chart_patch_file_close_irp( log_warning("Closing dummy checksum file handle failed"); } - free((void*) chart_patch_file_checksum.state.bytes); - memset(&chart_patch_file_checksum, 0, - sizeof(struct chart_patch_file)); + free((void *) chart_patch_file_checksum.state.bytes); + memset( + &chart_patch_file_checksum, 0, sizeof(struct chart_patch_file)); } chart_patch_file_detour = false; @@ -405,9 +416,8 @@ static HRESULT chart_patch_file_close_irp( return S_OK; } -static HRESULT chart_patch_file_read( - struct chart_patch_file *file, - struct irp *irp) +static HRESULT +chart_patch_file_read(struct chart_patch_file *file, struct irp *irp) { // log_misc("chart_patch_file_read %p", file->fd); @@ -416,30 +426,29 @@ static HRESULT chart_patch_file_read( return S_OK; } -static HRESULT chart_patch_file_seek( - struct chart_patch_file *file, - struct irp *irp) +static HRESULT +chart_patch_file_seek(struct chart_patch_file *file, struct irp *irp) { ssize_t pos; switch (irp->seek_origin) { - case FILE_BEGIN: - pos = irp->seek_offset; + case FILE_BEGIN: + pos = irp->seek_offset; - break; + break; - case FILE_CURRENT: - pos = irp->seek_offset + file->state.pos; + case FILE_CURRENT: + pos = irp->seek_offset + file->state.pos; - break; + break; - case FILE_END: - pos = irp->seek_offset + file->state.nbytes; + case FILE_END: + pos = irp->seek_offset + file->state.nbytes; - break; + break; - default: - return E_INVALIDARG; + default: + return E_INVALIDARG; } file->state.pos = max(0, min(pos, file->state.nbytes)); @@ -448,18 +457,22 @@ static HRESULT chart_patch_file_seek( return S_OK; } -static HRESULT chart_patch_file_dispatch_irp( - struct chart_patch_file *file, - struct irp *irp) +static HRESULT +chart_patch_file_dispatch_irp(struct chart_patch_file *file, struct irp *irp) { // log_misc("chart_patch_file_dispatch_irp %p", file->fd); switch (irp->op) { - case IRP_OP_CLOSE: return chart_patch_file_close_irp(file, irp); - case IRP_OP_READ: return chart_patch_file_read(file, irp); - case IRP_OP_WRITE: return HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED); - case IRP_OP_SEEK: return chart_patch_file_seek(file, irp); - default: return E_NOTIMPL; + case IRP_OP_CLOSE: + return chart_patch_file_close_irp(file, irp); + case IRP_OP_READ: + return chart_patch_file_read(file, irp); + case IRP_OP_WRITE: + return HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED); + case IRP_OP_SEEK: + return chart_patch_file_seek(file, irp); + default: + return E_NOTIMPL; } } @@ -498,7 +511,8 @@ void iidxhook_util_chart_patch_set_refresh_rate(double hz) log_info("Set target refresh rate %f", chart_patch_hz); } -HRESULT iidxhook_util_chart_patch_dispatch_irp(struct irp *irp) +HRESULT +iidxhook_util_chart_patch_dispatch_irp(struct irp *irp) { HRESULT hr; @@ -516,8 +530,8 @@ HRESULT iidxhook_util_chart_patch_dispatch_irp(struct irp *irp) } else { if (irp->fd != INVALID_HANDLE_VALUE && irp->fd != NULL) { if (irp->fd == chart_patch_file_1.fd) { - hr = chart_patch_file_dispatch_irp(&chart_patch_file_1, - irp); + hr = + chart_patch_file_dispatch_irp(&chart_patch_file_1, irp); } else if (irp->fd == chart_patch_file_checksum.fd) { hr = chart_patch_file_dispatch_irp( &chart_patch_file_checksum, irp); diff --git a/src/main/iidxhook-util/chart-patch.h b/src/main/iidxhook-util/chart-patch.h index 1812190..84e009f 100644 --- a/src/main/iidxhook-util/chart-patch.h +++ b/src/main/iidxhook-util/chart-patch.h @@ -15,7 +15,7 @@ * the charts in-memory to modify their timestamps and making the game run * on-sync on non-stock setups with different display refresh rates than * 59.94 or 60.04 (depending on game version). - * + * * @param orig_timebase The original refresh rate (timebase value) of the game. * Use one of the defined macros. */ @@ -30,8 +30,8 @@ void iidxhook_util_chart_patch_fini(void); * Set the target refresh rate of the display. Determine this value either * by using the d3d8 or d3d9 monitor check of bemanitools or get it from another * source (e.g. one of the newer games in-built monitor checks). - * - * @param hz Refresh rate of the display. Ensure your display provides a + * + * @param hz Refresh rate of the display. Ensure your display provides a * constant value. */ void iidxhook_util_chart_patch_set_refresh_rate(double hz); diff --git a/src/main/iidxhook-util/clock.c b/src/main/iidxhook-util/clock.c index e489e89..8c870ff 100644 --- a/src/main/iidxhook-util/clock.c +++ b/src/main/iidxhook-util/clock.c @@ -7,18 +7,16 @@ #include "util/defs.h" #include "util/log.h" -static BOOL STDCALL my_SetLocalTime(const SYSTEMTIME* lpSystemTime); -static BOOL (STDCALL *real_SetLocalTime)(const SYSTEMTIME* lpSystemTime); +static BOOL STDCALL my_SetLocalTime(const SYSTEMTIME *lpSystemTime); +static BOOL(STDCALL *real_SetLocalTime)(const SYSTEMTIME *lpSystemTime); static const struct hook_symbol clock_hook_syms[] = { - { - .name = "SetLocalTime", - .patch = my_SetLocalTime, - .link = (void **) &real_SetLocalTime - }, + {.name = "SetLocalTime", + .patch = my_SetLocalTime, + .link = (void **) &real_SetLocalTime}, }; -static BOOL STDCALL my_SetLocalTime(const SYSTEMTIME* lpSystemTime) +static BOOL STDCALL my_SetLocalTime(const SYSTEMTIME *lpSystemTime) { /* Stub, don't mess with system clock */ log_misc("Blocked setting system clock time"); @@ -28,10 +26,7 @@ static BOOL STDCALL my_SetLocalTime(const SYSTEMTIME* lpSystemTime) void iidxhook_util_clock_hook_init(void) { hook_table_apply( - NULL, - "kernel32.dll", - clock_hook_syms, - lengthof(clock_hook_syms)); + NULL, "kernel32.dll", clock_hook_syms, lengthof(clock_hook_syms)); log_info("Inserted clock hooks"); } diff --git a/src/main/iidxhook-util/config-eamuse.c b/src/main/iidxhook-util/config-eamuse.c index 5b950b7..f59b03e 100644 --- a/src/main/iidxhook-util/config-eamuse.c +++ b/src/main/iidxhook-util/config-eamuse.c @@ -13,12 +13,15 @@ #define IIDXHOOK_CONFIG_EAMUSE_PCBID_KEY "eamuse.pcbid" #define IIDXHOOK_CONFIG_EAMUSE_EAMID_KEY "eamuse.eamid" -#define IIDXHOOK_CONFIG_EAMUSE_DEFAULT_CARD_TYPE_VALUE SECURITY_MCODE_GAME_IIDX_9 +#define IIDXHOOK_CONFIG_EAMUSE_DEFAULT_CARD_TYPE_VALUE \ + SECURITY_MCODE_GAME_IIDX_9 #define IIDXHOOK_CONFIG_EAMUSE_DEFAULT_SERVER_VALUE "localhost:80" #define IIDXHOOK_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE security_id_default -#define IIDXHOOK_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE_LEN sizeof(security_id_default) +#define IIDXHOOK_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE_LEN \ + sizeof(security_id_default) #define IIDXHOOK_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE security_id_default -#define IIDXHOOK_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE_LEN sizeof(security_id_default) +#define IIDXHOOK_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE_LEN \ + sizeof(security_id_default) const struct net_addr iidxhook_eamuse_default_server = { .type = NET_ADDR_TYPE_HOSTNAME, @@ -26,103 +29,140 @@ const struct net_addr iidxhook_eamuse_default_server = { .hostname.port = 80, }; -void iidxhook_util_config_eamuse_init(struct cconfig* config) +void iidxhook_util_config_eamuse_init(struct cconfig *config) { - cconfig_util_set_str(config, + cconfig_util_set_str( + config, IIDXHOOK_CONFIG_EAMUSE_CARD_TYPE_KEY, IIDXHOOK_CONFIG_EAMUSE_DEFAULT_CARD_TYPE_VALUE, - "Magnetic card type, format XXX, 3 digit string (supports: C02, D01, " + "Magnetic card type, format XXX, 3 digit string (supports: C02, " + "D01, " "E11, ECO)"); - cconfig_util_set_str(config, + cconfig_util_set_str( + config, IIDXHOOK_CONFIG_EAMUSE_SERVER_KEY, IIDXHOOK_CONFIG_EAMUSE_DEFAULT_SERVER_VALUE, "URL (e.g. http://my.eamuse.server:80/whatever) or IPV4 " - "(e.g. 127.0.0.1:80) of the target eamuse server. The port is optional " + "(e.g. 127.0.0.1:80) of the target eamuse server. The port is " + "optional " "but defaults to 80."); - cconfig_util_set_data(config, IIDXHOOK_CONFIG_EAMUSE_PCBID_KEY, - (uint8_t*) &IIDXHOOK_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE, - IIDXHOOK_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE_LEN, "PCBID"); + cconfig_util_set_data( + config, + IIDXHOOK_CONFIG_EAMUSE_PCBID_KEY, + (uint8_t *) &IIDXHOOK_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE, + IIDXHOOK_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE_LEN, + "PCBID"); - cconfig_util_set_data(config, IIDXHOOK_CONFIG_EAMUSE_EAMID_KEY, - (uint8_t*) &IIDXHOOK_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE, - IIDXHOOK_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE_LEN, "EAMID"); + cconfig_util_set_data( + config, + IIDXHOOK_CONFIG_EAMUSE_EAMID_KEY, + (uint8_t *) &IIDXHOOK_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE, + IIDXHOOK_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE_LEN, + "EAMID"); } void iidxhook_util_config_eamuse_get( - struct iidxhook_util_config_eamuse* config_eamuse, - struct cconfig* config) + struct iidxhook_util_config_eamuse *config_eamuse, struct cconfig *config) { char server_url[1024]; - char* tmp; - char* tmp2; + char *tmp; + char *tmp2; memset(config_eamuse, 0, sizeof(struct iidxhook_util_config_eamuse)); - if (!cconfig_util_get_str(config, IIDXHOOK_CONFIG_EAMUSE_CARD_TYPE_KEY, - config_eamuse->card_type, sizeof(config_eamuse->card_type) - 1, + if (!cconfig_util_get_str( + config, + IIDXHOOK_CONFIG_EAMUSE_CARD_TYPE_KEY, + config_eamuse->card_type, + sizeof(config_eamuse->card_type) - 1, IIDXHOOK_CONFIG_EAMUSE_DEFAULT_CARD_TYPE_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%s'", IIDXHOOK_CONFIG_EAMUSE_CARD_TYPE_KEY, + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%s'", + IIDXHOOK_CONFIG_EAMUSE_CARD_TYPE_KEY, IIDXHOOK_CONFIG_EAMUSE_DEFAULT_CARD_TYPE_VALUE); } - if (!cconfig_util_get_str(config, IIDXHOOK_CONFIG_EAMUSE_SERVER_KEY, - server_url, sizeof(server_url), + if (!cconfig_util_get_str( + config, + IIDXHOOK_CONFIG_EAMUSE_SERVER_KEY, + server_url, + sizeof(server_url), IIDXHOOK_CONFIG_EAMUSE_DEFAULT_SERVER_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%s'", IIDXHOOK_CONFIG_EAMUSE_SERVER_KEY, + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%s'", + IIDXHOOK_CONFIG_EAMUSE_SERVER_KEY, IIDXHOOK_CONFIG_EAMUSE_DEFAULT_SERVER_VALUE); } if (!net_str_parse(server_url, &config_eamuse->server)) { - memcpy(&config_eamuse->server, &iidxhook_eamuse_default_server, + memcpy( + &config_eamuse->server, + &iidxhook_eamuse_default_server, sizeof(config_eamuse->server)); tmp = net_addr_to_str(&config_eamuse->server); - log_warning("Invalid value for key '%s' specified, fallback " - "to default", tmp); + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default", + tmp); free(tmp); } - if (!cconfig_util_get_data(config, IIDXHOOK_CONFIG_EAMUSE_PCBID_KEY, - (uint8_t*) &config_eamuse->pcbid, + if (!cconfig_util_get_data( + config, + IIDXHOOK_CONFIG_EAMUSE_PCBID_KEY, + (uint8_t *) &config_eamuse->pcbid, IIDXHOOK_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE_LEN, - (uint8_t*) &IIDXHOOK_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE)) { - tmp = security_id_to_str(&IIDXHOOK_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE, - false); - log_warning("Invalid value for key '%s' specified, fallback " - "to default", tmp); + (uint8_t *) &IIDXHOOK_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE)) { + tmp = security_id_to_str( + &IIDXHOOK_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE, false); + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default", + tmp); free(tmp); } if (!security_id_verify(&config_eamuse->pcbid)) { - tmp = security_id_to_str(&IIDXHOOK_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE, - false); + tmp = security_id_to_str( + &IIDXHOOK_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE, false); tmp2 = security_id_to_str(&config_eamuse->pcbid, false); - log_warning("PCBID verification of '%s' failed, fallback to default " - "PCBID '%s'", tmp2, tmp); + log_warning( + "PCBID verification of '%s' failed, fallback to default " + "PCBID '%s'", + tmp2, + tmp); free(tmp); free(tmp2); } - - if (!cconfig_util_get_data(config, IIDXHOOK_CONFIG_EAMUSE_EAMID_KEY, - (uint8_t*) &config_eamuse->eamid, + + if (!cconfig_util_get_data( + config, + IIDXHOOK_CONFIG_EAMUSE_EAMID_KEY, + (uint8_t *) &config_eamuse->eamid, IIDXHOOK_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE_LEN, - (uint8_t*) &IIDXHOOK_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE)) { - tmp = security_id_to_str(&IIDXHOOK_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE, - false); - log_warning("Invalid value for key '%s' specified, fallback " - "to default", tmp); + (uint8_t *) &IIDXHOOK_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE)) { + tmp = security_id_to_str( + &IIDXHOOK_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE, false); + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default", + tmp); free(tmp); } if (!security_id_verify(&config_eamuse->eamid)) { - tmp = security_id_to_str(&IIDXHOOK_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE, - false); + tmp = security_id_to_str( + &IIDXHOOK_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE, false); tmp2 = security_id_to_str(&config_eamuse->eamid, false); - log_warning("EAMID verification of '%s' failed, fallback to default " - "EAMID '%s'", tmp2, tmp); + log_warning( + "EAMID verification of '%s' failed, fallback to default " + "EAMID '%s'", + tmp2, + tmp); free(tmp); free(tmp2); } diff --git a/src/main/iidxhook-util/config-eamuse.h b/src/main/iidxhook-util/config-eamuse.h index 589a882..b6b1d40 100644 --- a/src/main/iidxhook-util/config-eamuse.h +++ b/src/main/iidxhook-util/config-eamuse.h @@ -14,10 +14,9 @@ struct iidxhook_util_config_eamuse { struct security_id eamid; }; -void iidxhook_util_config_eamuse_init(struct cconfig* config); +void iidxhook_util_config_eamuse_init(struct cconfig *config); void iidxhook_util_config_eamuse_get( - struct iidxhook_util_config_eamuse* config_eamuse, - struct cconfig* config); + struct iidxhook_util_config_eamuse *config_eamuse, struct cconfig *config); #endif \ No newline at end of file diff --git a/src/main/iidxhook-util/config-gfx.c b/src/main/iidxhook-util/config-gfx.c index 02fbd6d..a74b2ac 100644 --- a/src/main/iidxhook-util/config-gfx.c +++ b/src/main/iidxhook-util/config-gfx.c @@ -14,9 +14,12 @@ #define IIDXHOOK_CONFIG_GFX_WINDOWED_KEY "gfx.windowed" #define IIDXHOOK_CONFIG_GFX_WINDOW_WIDTH_KEY "gfx.window_width" #define IIDXHOOK_CONFIG_GFX_WINDOW_HEIGHT_KEY "gfx.window_height" -#define IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_WIDTH_KEY "gfx.scale_back_buffer_width" -#define IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_HEIGHT_KEY "gfx.scale_back_buffer_height" -#define IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_FILTER_KEY "gfx.scale_back_buffer_filter" +#define IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_WIDTH_KEY \ + "gfx.scale_back_buffer_width" +#define IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_HEIGHT_KEY \ + "gfx.scale_back_buffer_height" +#define IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_FILTER_KEY \ + "gfx.scale_back_buffer_filter" #define IIDXHOOK_CONFIG_GFX_DEFAULT_BGVIDEO_UV_FIX_VALUE false #define IIDXHOOK_CONFIG_GFX_DEFAULT_FRAMED_VALUE false @@ -30,36 +33,48 @@ #define IIDXHOOK_CONFIG_GFX_DEFAULT_SCALE_BACK_BUFFER_HEIGHT_VALUE 0 #define IIDXHOOK_CONFIG_GFX_DEFAULT_SCALE_BACK_BUFFER_FILTER_VALUE "none" -void iidxhook_config_gfx_init(struct cconfig* config) +void iidxhook_config_gfx_init(struct cconfig *config) { - cconfig_util_set_bool(config, - IIDXHOOK_CONFIG_GFX_BGVIDEO_UV_FIX_KEY, + cconfig_util_set_bool( + config, + IIDXHOOK_CONFIG_GFX_BGVIDEO_UV_FIX_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_BGVIDEO_UV_FIX_VALUE, - "Fix stretched BG videos on newer GPUs. Might appear on Red and newer"); + "Fix stretched BG videos on newer GPUs. Might appear on Red and " + "newer"); - cconfig_util_set_bool(config, + cconfig_util_set_bool( + config, IIDXHOOK_CONFIG_GFX_FRAMED_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_FRAMED_VALUE, "Run the game in a framed window (requires windowed option)"); - cconfig_util_set_float(config, + cconfig_util_set_float( + config, IIDXHOOK_CONFIG_GFX_FRAME_RATE_LIMIT_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_FRAME_RATE_LIMIT_VALUE, - "Software limit the frame rate of the rendering loop in hz, e.g. 60 or 59.95 (0.0 = no software limit)"); + "Software limit the frame rate of the rendering loop in hz, e.g. " + "60 or 59.95 (0.0 = no software limit)"); - cconfig_util_set_float(config, + cconfig_util_set_float( + config, IIDXHOOK_CONFIG_GFX_MONITOR_CHECK_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_MONITOR_CHECK_VALUE, "Enable/disable software monitor check/auto timebase or set " - "a pre-determined refresh value. -1 disables this feature. 0 enables " + "a pre-determined refresh value. -1 disables this feature. 0 " + "enables " "auto detecting the current refresh rate on startup. Setting any " - "positive value > 0 allows you to set a pre-determined refresh rate " - "(e.g. retrieved from the monitor check on newer IIDX games). Either " - "the auto detected value or pre-determined value is used to patch any " - "chart files in-memory to fix song synchronization issues. Requires " + "positive value > 0 allows you to set a pre-determined refresh " + "rate " + "(e.g. retrieved from the monitor check on newer IIDX games). " + "Either " + "the auto detected value or pre-determined value is used to patch " + "any " + "chart files in-memory to fix song synchronization issues. " + "Requires " "constant refresh rate!!!"); - cconfig_util_set_str(config, + cconfig_util_set_str( + config, IIDXHOOK_CONFIG_GFX_PCI_ID_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_PCI_ID_VALUE, "Patch the GPU device ID detection (leave empty to" @@ -67,96 +82,141 @@ void iidxhook_config_gfx_init(struct cconfig* config) " Examples: 1002:7146 (RV515, Radeon X1300), 1002:95C5 (RV620 LE," " Radeon HD3450)"); - cconfig_util_set_bool(config, + cconfig_util_set_bool( + config, IIDXHOOK_CONFIG_GFX_WINDOWED_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_WINDOWED_VALUE, "Run the game windowed"); - cconfig_util_set_int(config, + cconfig_util_set_int( + config, IIDXHOOK_CONFIG_GFX_WINDOW_WIDTH_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_WINDOW_WIDTH_VALUE, "Windowed width, -1 for default size"); - cconfig_util_set_int(config, + cconfig_util_set_int( + config, IIDXHOOK_CONFIG_GFX_WINDOW_HEIGHT_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_WINDOW_HEIGHT_VALUE, "Windowed height, -1 for default size"); - cconfig_util_set_int(config, + cconfig_util_set_int( + config, IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_WIDTH_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_SCALE_BACK_BUFFER_WIDTH_VALUE, - "Up-/downscale the back buffer's width. This does not change the game's rendering resolution but scales the " - "final frame. Use this to target the native resolution of your monitor/TV, e.g. to avoid over-/underscan, bad " - "image quality or latency caused by the monitors internal upscaler. 0 to disable this feature. Must be set in " + "Up-/downscale the back buffer's width. This does not change the " + "game's rendering resolution but scales " + "the " + "final frame. Use this to target the native resolution of your " + "monitor/TV, e.g. to avoid over-/underscan, " + "bad " + "image quality or latency caused by the monitors internal " + "upscaler. 0 to disable this feature. Must be set " + "in " "combination with the corresponding height parameter."); - cconfig_util_set_int(config, + cconfig_util_set_int( + config, IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_HEIGHT_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_SCALE_BACK_BUFFER_HEIGHT_VALUE, - "Up-/downscale the back buffer's height. This does not change the game's rendering resolution but scales the " - "final frame. Use this to target the native resolution of your monitor/TV, e.g. to avoid over-/underscan, bad " - "image quality or latency caused by the monitors internal upscaler. 0 to disable this feature. Must be set in " + "Up-/downscale the back buffer's height. This does not change the " + "game's rendering resolution but scales " + "the " + "final frame. Use this to target the native resolution of your " + "monitor/TV, e.g. to avoid over-/underscan, " + "bad " + "image quality or latency caused by the monitors internal " + "upscaler. 0 to disable this feature. Must be set " + "in " "combination with the corresponding width parameter."); - cconfig_util_set_str(config, + cconfig_util_set_str( + config, IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_FILTER_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_SCALE_BACK_BUFFER_FILTER_VALUE, - "Filter type to use for up-/downscaling the back buffer. Only used if scaling feature was enabled by setting " - "the scaling width and height parameters. Available types: none, linear, point (refer to D3DTEXTUREFILTERTYPE " + "Filter type to use for up-/downscaling the back buffer. Only used " + "if scaling feature was enabled by " + "setting " + "the scaling width and height parameters. Available types: none, " + "linear, point (refer to " + "D3DTEXTUREFILTERTYPE " " for explanation)."); } -void iidxhook_config_gfx_get(struct iidxhook_config_gfx* config_gfx, - struct cconfig* config) +void iidxhook_config_gfx_get( + struct iidxhook_config_gfx *config_gfx, struct cconfig *config) { char tmp[10]; - char* vid; - char* pid; + char *vid; + char *pid; int32_t tmp_int; - if (!cconfig_util_get_bool(config, IIDXHOOK_CONFIG_GFX_BGVIDEO_UV_FIX_KEY, + if (!cconfig_util_get_bool( + config, + IIDXHOOK_CONFIG_GFX_BGVIDEO_UV_FIX_KEY, &config_gfx->bgvideo_uv_fix, IIDXHOOK_CONFIG_GFX_DEFAULT_BGVIDEO_UV_FIX_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%d'", IIDXHOOK_CONFIG_GFX_BGVIDEO_UV_FIX_KEY, + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%d'", + IIDXHOOK_CONFIG_GFX_BGVIDEO_UV_FIX_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_BGVIDEO_UV_FIX_VALUE); } - if (!cconfig_util_get_bool(config, IIDXHOOK_CONFIG_GFX_FRAMED_KEY, + if (!cconfig_util_get_bool( + config, + IIDXHOOK_CONFIG_GFX_FRAMED_KEY, &config_gfx->framed, IIDXHOOK_CONFIG_GFX_DEFAULT_FRAMED_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%d'", IIDXHOOK_CONFIG_GFX_FRAMED_KEY, + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%d'", + IIDXHOOK_CONFIG_GFX_FRAMED_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_FRAMED_VALUE); } - if (!cconfig_util_get_float(config, IIDXHOOK_CONFIG_GFX_FRAME_RATE_LIMIT_KEY, + if (!cconfig_util_get_float( + config, + IIDXHOOK_CONFIG_GFX_FRAME_RATE_LIMIT_KEY, &config_gfx->frame_rate_limit, IIDXHOOK_CONFIG_GFX_DEFAULT_FRAME_RATE_LIMIT_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%f'", IIDXHOOK_CONFIG_GFX_FRAME_RATE_LIMIT_KEY, + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%f'", + IIDXHOOK_CONFIG_GFX_FRAME_RATE_LIMIT_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_FRAME_RATE_LIMIT_VALUE); } - if (!cconfig_util_get_float(config, IIDXHOOK_CONFIG_GFX_MONITOR_CHECK_KEY, + if (!cconfig_util_get_float( + config, + IIDXHOOK_CONFIG_GFX_MONITOR_CHECK_KEY, &config_gfx->monitor_check, IIDXHOOK_CONFIG_GFX_DEFAULT_MONITOR_CHECK_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%f'", IIDXHOOK_CONFIG_GFX_MONITOR_CHECK_KEY, + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%f'", + IIDXHOOK_CONFIG_GFX_MONITOR_CHECK_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_MONITOR_CHECK_VALUE); } - if (!cconfig_util_get_str(config, IIDXHOOK_CONFIG_GFX_PCI_ID_KEY, - tmp, sizeof(tmp) - 1, + if (!cconfig_util_get_str( + config, + IIDXHOOK_CONFIG_GFX_PCI_ID_KEY, + tmp, + sizeof(tmp) - 1, IIDXHOOK_CONFIG_GFX_DEFAULT_PCI_ID_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%s'", IIDXHOOK_CONFIG_GFX_PCI_ID_KEY, + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%s'", + IIDXHOOK_CONFIG_GFX_PCI_ID_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_PCI_ID_VALUE); } if (tmp[4] != ':') { - log_warning("Invalid format for value for key '%s' specified, fallback " - "to default '%s'", IIDXHOOK_CONFIG_GFX_PCI_ID_KEY, + log_warning( + "Invalid format for value for key '%s' specified, fallback " + "to default '%s'", + IIDXHOOK_CONFIG_GFX_PCI_ID_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_PCI_ID_VALUE); strcpy(tmp, IIDXHOOK_CONFIG_GFX_DEFAULT_PCI_ID_VALUE); } @@ -167,69 +227,102 @@ void iidxhook_config_gfx_get(struct iidxhook_config_gfx* config_gfx, config_gfx->pci_id_vid = strtol(vid, NULL, 16); config_gfx->pci_id_pid = strtol(pid, NULL, 16); - if (!cconfig_util_get_bool(config, IIDXHOOK_CONFIG_GFX_WINDOWED_KEY, + if (!cconfig_util_get_bool( + config, + IIDXHOOK_CONFIG_GFX_WINDOWED_KEY, &config_gfx->windowed, IIDXHOOK_CONFIG_GFX_DEFAULT_WINDOWED_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%d'", IIDXHOOK_CONFIG_GFX_WINDOWED_KEY, + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%d'", + IIDXHOOK_CONFIG_GFX_WINDOWED_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_WINDOWED_VALUE); } - if (!cconfig_util_get_int(config, IIDXHOOK_CONFIG_GFX_WINDOW_WIDTH_KEY, - &config_gfx->window_width, IIDXHOOK_CONFIG_GFX_DEFAULT_WINDOW_WIDTH_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%d'", IIDXHOOK_CONFIG_GFX_WINDOW_WIDTH_KEY, + if (!cconfig_util_get_int( + config, + IIDXHOOK_CONFIG_GFX_WINDOW_WIDTH_KEY, + &config_gfx->window_width, + IIDXHOOK_CONFIG_GFX_DEFAULT_WINDOW_WIDTH_VALUE)) { + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%d'", + IIDXHOOK_CONFIG_GFX_WINDOW_WIDTH_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_WINDOW_WIDTH_VALUE); } - if (!cconfig_util_get_int(config, IIDXHOOK_CONFIG_GFX_WINDOW_HEIGHT_KEY, - &config_gfx->window_height, IIDXHOOK_CONFIG_GFX_DEFAULT_WINDOW_HEIGHT_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%d'", IIDXHOOK_CONFIG_GFX_WINDOW_HEIGHT_KEY, + if (!cconfig_util_get_int( + config, + IIDXHOOK_CONFIG_GFX_WINDOW_HEIGHT_KEY, + &config_gfx->window_height, + IIDXHOOK_CONFIG_GFX_DEFAULT_WINDOW_HEIGHT_VALUE)) { + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%d'", + IIDXHOOK_CONFIG_GFX_WINDOW_HEIGHT_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_WINDOW_HEIGHT_VALUE); } - if (!cconfig_util_get_int(config, IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_WIDTH_KEY, + if (!cconfig_util_get_int( + config, + IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_WIDTH_KEY, &tmp_int, IIDXHOOK_CONFIG_GFX_DEFAULT_SCALE_BACK_BUFFER_WIDTH_VALUE) || - tmp_int < 0 || tmp_int > 0xFFFF) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%d'", IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_WIDTH_KEY, + tmp_int < 0 || tmp_int > 0xFFFF) { + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%d'", + IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_WIDTH_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_SCALE_BACK_BUFFER_WIDTH_VALUE); } config_gfx->scale_back_buffer_width = (uint16_t) tmp_int; - if (!cconfig_util_get_int(config, IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_HEIGHT_KEY, + if (!cconfig_util_get_int( + config, + IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_HEIGHT_KEY, &tmp_int, IIDXHOOK_CONFIG_GFX_DEFAULT_SCALE_BACK_BUFFER_HEIGHT_VALUE) || - tmp_int < 0 || tmp_int > 0xFFFF) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%d'", IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_HEIGHT_KEY, + tmp_int < 0 || tmp_int > 0xFFFF) { + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%d'", + IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_HEIGHT_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_SCALE_BACK_BUFFER_HEIGHT_VALUE); } config_gfx->scale_back_buffer_height = (uint16_t) tmp_int; - if (!cconfig_util_get_str(config, IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_FILTER_KEY, - tmp, sizeof(tmp) - 1, + if (!cconfig_util_get_str( + config, + IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_FILTER_KEY, + tmp, + sizeof(tmp) - 1, IIDXHOOK_CONFIG_GFX_DEFAULT_SCALE_BACK_BUFFER_FILTER_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%s'", IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_FILTER_KEY, + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%s'", + IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_FILTER_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_SCALE_BACK_BUFFER_FILTER_VALUE); } if (!strcmp(tmp, "none")) { - config_gfx->scale_back_buffer_filter = IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_NONE; + config_gfx->scale_back_buffer_filter = + IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_NONE; } else if (!strcmp(tmp, "linear")) { - config_gfx->scale_back_buffer_filter = IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_LINEAR; + config_gfx->scale_back_buffer_filter = + IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_LINEAR; } else if (!strcmp(tmp, "point")) { - config_gfx->scale_back_buffer_filter = IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_POINT; + config_gfx->scale_back_buffer_filter = + IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_POINT; } else { - config_gfx->scale_back_buffer_filter = IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_NONE; + config_gfx->scale_back_buffer_filter = + IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_NONE; - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%s'", IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_FILTER_KEY, + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%s'", + IIDXHOOK_CONFIG_GFX_SCALE_BACK_BUFFER_FILTER_KEY, IIDXHOOK_CONFIG_GFX_DEFAULT_SCALE_BACK_BUFFER_FILTER_VALUE); } } diff --git a/src/main/iidxhook-util/config-gfx.h b/src/main/iidxhook-util/config-gfx.h index c71895f..d3af449 100644 --- a/src/main/iidxhook-util/config-gfx.h +++ b/src/main/iidxhook-util/config-gfx.h @@ -20,9 +20,9 @@ struct iidxhook_config_gfx { enum iidxhook_util_d3d9_back_buffer_scale_filter scale_back_buffer_filter; }; -void iidxhook_config_gfx_init(struct cconfig* config); +void iidxhook_config_gfx_init(struct cconfig *config); -void iidxhook_config_gfx_get(struct iidxhook_config_gfx* config_gfx, - struct cconfig* config); +void iidxhook_config_gfx_get( + struct iidxhook_config_gfx *config_gfx, struct cconfig *config); #endif \ No newline at end of file diff --git a/src/main/iidxhook-util/config-misc.c b/src/main/iidxhook-util/config-misc.c index 4267a43..56a15dc 100644 --- a/src/main/iidxhook-util/config-misc.c +++ b/src/main/iidxhook-util/config-misc.c @@ -10,36 +10,45 @@ #define IIDXHOOK_CONFIG_MISC_DEFAULT_DISABLE_CLOCK_SET_VALUE false #define IIDXHOOK_CONFIG_MISC_DEFAULT_RTEFFECT_STUB_VALUE false -void iidxhook_config_misc_init(struct cconfig* config) +void iidxhook_config_misc_init(struct cconfig *config) { - cconfig_util_set_bool(config, - IIDXHOOK_CONFIG_MISC_DISABLE_CLOCK_SET_KEY, + cconfig_util_set_bool( + config, + IIDXHOOK_CONFIG_MISC_DISABLE_CLOCK_SET_KEY, IIDXHOOK_CONFIG_MISC_DEFAULT_DISABLE_CLOCK_SET_VALUE, "Disable operator clock setting system clock time"); - cconfig_util_set_bool(config, - IIDXHOOK_CONFIG_MISC_RTEFFECT_STUB_KEY, + cconfig_util_set_bool( + config, + IIDXHOOK_CONFIG_MISC_RTEFFECT_STUB_KEY, IIDXHOOK_CONFIG_MISC_DEFAULT_RTEFFECT_STUB_VALUE, "Stub calls to rteffect.dll (10th to DistorteD)"); } -void iidxhook_config_misc_get(struct iidxhook_config_misc* config_misc, - struct cconfig* config) +void iidxhook_config_misc_get( + struct iidxhook_config_misc *config_misc, struct cconfig *config) { - if (!cconfig_util_get_bool(config, + if (!cconfig_util_get_bool( + config, IIDXHOOK_CONFIG_MISC_DISABLE_CLOCK_SET_KEY, &config_misc->disable_clock_set, IIDXHOOK_CONFIG_MISC_DEFAULT_DISABLE_CLOCK_SET_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%d'", IIDXHOOK_CONFIG_MISC_DISABLE_CLOCK_SET_KEY, + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%d'", + IIDXHOOK_CONFIG_MISC_DISABLE_CLOCK_SET_KEY, IIDXHOOK_CONFIG_MISC_DEFAULT_DISABLE_CLOCK_SET_VALUE); } - if (!cconfig_util_get_bool(config, IIDXHOOK_CONFIG_MISC_RTEFFECT_STUB_KEY, + if (!cconfig_util_get_bool( + config, + IIDXHOOK_CONFIG_MISC_RTEFFECT_STUB_KEY, &config_misc->rteffect_stub, IIDXHOOK_CONFIG_MISC_DEFAULT_RTEFFECT_STUB_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%d'", IIDXHOOK_CONFIG_MISC_RTEFFECT_STUB_KEY, + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%d'", + IIDXHOOK_CONFIG_MISC_RTEFFECT_STUB_KEY, IIDXHOOK_CONFIG_MISC_DEFAULT_RTEFFECT_STUB_VALUE); } } diff --git a/src/main/iidxhook-util/config-misc.h b/src/main/iidxhook-util/config-misc.h index 2a312c3..7391ac0 100644 --- a/src/main/iidxhook-util/config-misc.h +++ b/src/main/iidxhook-util/config-misc.h @@ -8,9 +8,9 @@ struct iidxhook_config_misc { bool rteffect_stub; }; -void iidxhook_config_misc_init(struct cconfig* config); +void iidxhook_config_misc_init(struct cconfig *config); -void iidxhook_config_misc_get(struct iidxhook_config_misc* config_misc, - struct cconfig* config); +void iidxhook_config_misc_get( + struct iidxhook_config_misc *config_misc, struct cconfig *config); #endif \ No newline at end of file diff --git a/src/main/iidxhook-util/config-sec.c b/src/main/iidxhook-util/config-sec.c index 4414816..54cb0ee 100644 --- a/src/main/iidxhook-util/config-sec.c +++ b/src/main/iidxhook-util/config-sec.c @@ -16,9 +16,12 @@ #define IIDXHOOK_CONFIG_SEC_BLACK_PLUG_MCODE_KEY "sec.black_plug_mcode" /* Use C02 defaults */ -#define IIDXHOOK_CONFIG_SEC_DEFAULT_BOOT_VERSION_VALUE iidxhook_security_default_boot_version -#define IIDXHOOK_CONFIG_SEC_DEFAULT_BOOT_SEEDS_VALUE iidxhook_security_default_boot_seeds -#define IIDXHOOK_CONFIG_SEC_DEFAULT_BLACK_PLUG_MCODE_VALUE iidxhook_security_default_black_plug_mcode +#define IIDXHOOK_CONFIG_SEC_DEFAULT_BOOT_VERSION_VALUE \ + iidxhook_security_default_boot_version +#define IIDXHOOK_CONFIG_SEC_DEFAULT_BOOT_SEEDS_VALUE \ + iidxhook_security_default_boot_seeds +#define IIDXHOOK_CONFIG_SEC_DEFAULT_BLACK_PLUG_MCODE_VALUE \ + iidxhook_security_default_black_plug_mcode /* IIDX 09 default */ static const struct security_mcode iidxhook_security_default_boot_version = { @@ -34,18 +37,19 @@ static const struct security_mcode iidxhook_security_default_boot_version = { static const uint32_t iidxhook_security_default_boot_seeds[3] = {0, 0, 0}; /* IIDX 09 default */ -static const struct security_mcode iidxhook_security_default_black_plug_mcode = { - .header = SECURITY_MCODE_HEADER, - .unkn = SECURITY_MCODE_UNKN_Q, - .game = SECURITY_MCODE_GAME_IIDX_9, - .region = SECURITY_MCODE_REGION_JAPAN, - .cabinet = SECURITY_MCODE_CABINET_A, - .revision = SECURITY_MCODE_REVISION_A, +static const struct security_mcode iidxhook_security_default_black_plug_mcode = + { + .header = SECURITY_MCODE_HEADER, + .unkn = SECURITY_MCODE_UNKN_Q, + .game = SECURITY_MCODE_GAME_IIDX_9, + .region = SECURITY_MCODE_REGION_JAPAN, + .cabinet = SECURITY_MCODE_CABINET_A, + .revision = SECURITY_MCODE_REVISION_A, }; -static char* iidxhook_config_boot_seeds_to_str(const uint32_t* seeds) +static char *iidxhook_config_boot_seeds_to_str(const uint32_t *seeds) { - char* res; + char *res; size_t len; len = snprintf(NULL, 0, "%d:%d:%d", seeds[0], seeds[1], seeds[2]); @@ -55,7 +59,7 @@ static char* iidxhook_config_boot_seeds_to_str(const uint32_t* seeds) return res; } -static bool iidxhook_config_boot_seeds_parse(const char* str, uint32_t* seeds) +static bool iidxhook_config_boot_seeds_parse(const char *str, uint32_t *seeds) { if (strlen(str) < 5) { return false; @@ -71,25 +75,30 @@ static bool iidxhook_config_boot_seeds_parse(const char* str, uint32_t* seeds) } } -void iidxhook_config_sec_init(struct cconfig* config) +void iidxhook_config_sec_init(struct cconfig *config) { - char* tmp; + char *tmp; - tmp = security_mcode_to_str( - &IIDXHOOK_CONFIG_SEC_DEFAULT_BOOT_VERSION_VALUE); + tmp = + security_mcode_to_str(&IIDXHOOK_CONFIG_SEC_DEFAULT_BOOT_VERSION_VALUE); - cconfig_util_set_str(config, - IIDXHOOK_CONFIG_SEC_BOOT_VERSION_KEY, tmp, + cconfig_util_set_str( + config, + IIDXHOOK_CONFIG_SEC_BOOT_VERSION_KEY, + tmp, "Security boot version (e.g. GEC02)."); free(tmp); - + tmp = iidxhook_config_boot_seeds_to_str( IIDXHOOK_CONFIG_SEC_DEFAULT_BOOT_SEEDS_VALUE); - cconfig_util_set_str(config, - IIDXHOOK_CONFIG_SEC_BOOT_SEEDS_KEY, tmp, - "Security boot seeds for ezusb, format: X:X:X where X is a number of " + cconfig_util_set_str( + config, + IIDXHOOK_CONFIG_SEC_BOOT_SEEDS_KEY, + tmp, + "Security boot seeds for ezusb, format: X:X:X where X is a number " + "of " "0-9 (e.g. 0:0:0)."); free(tmp); @@ -97,33 +106,46 @@ void iidxhook_config_sec_init(struct cconfig* config) tmp = security_mcode_to_str( &IIDXHOOK_CONFIG_SEC_DEFAULT_BLACK_PLUG_MCODE_VALUE); - cconfig_util_set_str(config, - IIDXHOOK_CONFIG_SEC_BLACK_PLUG_MCODE_KEY, tmp, + cconfig_util_set_str( + config, + IIDXHOOK_CONFIG_SEC_BLACK_PLUG_MCODE_KEY, + tmp, "Security black plug mcode id string (e.g. GQC02JAA)."); free(tmp); } -void iidxhook_config_sec_get(struct iidxhook_config_sec* config_sec, - struct cconfig* config) +void iidxhook_config_sec_get( + struct iidxhook_config_sec *config_sec, struct cconfig *config) { char tmp_seeds[6]; char tmp_mcode[sizeof(struct security_mcode) + 1]; - char* tmp_str; + char *tmp_str; - tmp_str = security_mcode_to_str( - &IIDXHOOK_CONFIG_SEC_DEFAULT_BOOT_VERSION_VALUE); + tmp_str = + security_mcode_to_str(&IIDXHOOK_CONFIG_SEC_DEFAULT_BOOT_VERSION_VALUE); - if (!cconfig_util_get_str(config, IIDXHOOK_CONFIG_SEC_BOOT_VERSION_KEY, - tmp_mcode, sizeof(tmp_mcode) - 1, tmp_str)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%s'", IIDXHOOK_CONFIG_SEC_BOOT_VERSION_KEY, tmp_str); + if (!cconfig_util_get_str( + config, + IIDXHOOK_CONFIG_SEC_BOOT_VERSION_KEY, + tmp_mcode, + sizeof(tmp_mcode) - 1, + tmp_str)) { + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%s'", + IIDXHOOK_CONFIG_SEC_BOOT_VERSION_KEY, + tmp_str); } if (!security_mcode_parse(tmp_mcode, &config_sec->boot_version)) { - log_warning("Invalid format for value of key '%s' specified, fallback " - "to default '%s'", IIDXHOOK_CONFIG_SEC_BOOT_VERSION_KEY, tmp_str); - memcpy(&config_sec->boot_version, + log_warning( + "Invalid format for value of key '%s' specified, fallback " + "to default '%s'", + IIDXHOOK_CONFIG_SEC_BOOT_VERSION_KEY, + tmp_str); + memcpy( + &config_sec->boot_version, &IIDXHOOK_CONFIG_SEC_DEFAULT_BOOT_VERSION_VALUE, sizeof(IIDXHOOK_CONFIG_SEC_DEFAULT_BOOT_VERSION_VALUE)); } @@ -133,16 +155,27 @@ void iidxhook_config_sec_get(struct iidxhook_config_sec* config_sec, tmp_str = iidxhook_config_boot_seeds_to_str( IIDXHOOK_CONFIG_SEC_DEFAULT_BOOT_SEEDS_VALUE); - if (!cconfig_util_get_str(config, IIDXHOOK_CONFIG_SEC_BOOT_SEEDS_KEY, - tmp_seeds, sizeof(tmp_seeds) - 1, tmp_str)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%s'", IIDXHOOK_CONFIG_SEC_BOOT_SEEDS_KEY, tmp_str); + if (!cconfig_util_get_str( + config, + IIDXHOOK_CONFIG_SEC_BOOT_SEEDS_KEY, + tmp_seeds, + sizeof(tmp_seeds) - 1, + tmp_str)) { + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%s'", + IIDXHOOK_CONFIG_SEC_BOOT_SEEDS_KEY, + tmp_str); } if (!iidxhook_config_boot_seeds_parse(tmp_seeds, config_sec->boot_seeds)) { - log_warning("Invalid format for value of key '%s' specified, fallback " - "to default '%s'", IIDXHOOK_CONFIG_SEC_BOOT_SEEDS_KEY, tmp_str); - memcpy(config_sec->boot_seeds, + log_warning( + "Invalid format for value of key '%s' specified, fallback " + "to default '%s'", + IIDXHOOK_CONFIG_SEC_BOOT_SEEDS_KEY, + tmp_str); + memcpy( + config_sec->boot_seeds, IIDXHOOK_CONFIG_SEC_DEFAULT_BOOT_SEEDS_VALUE, sizeof(IIDXHOOK_CONFIG_SEC_DEFAULT_BOOT_SEEDS_VALUE)); } @@ -152,18 +185,27 @@ void iidxhook_config_sec_get(struct iidxhook_config_sec* config_sec, tmp_str = security_mcode_to_str( &IIDXHOOK_CONFIG_SEC_DEFAULT_BLACK_PLUG_MCODE_VALUE); - if (!cconfig_util_get_str(config, IIDXHOOK_CONFIG_SEC_BLACK_PLUG_MCODE_KEY, - tmp_mcode, sizeof(tmp_mcode) - 1, tmp_str)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%s'", IIDXHOOK_CONFIG_SEC_BLACK_PLUG_MCODE_KEY, + if (!cconfig_util_get_str( + config, + IIDXHOOK_CONFIG_SEC_BLACK_PLUG_MCODE_KEY, + tmp_mcode, + sizeof(tmp_mcode) - 1, + tmp_str)) { + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%s'", + IIDXHOOK_CONFIG_SEC_BLACK_PLUG_MCODE_KEY, tmp_str); } if (!security_mcode_parse(tmp_mcode, &config_sec->black_plug_mcode)) { - log_warning("Invalid format for value of key '%s' specified, fallback " - "to default '%s'", IIDXHOOK_CONFIG_SEC_BLACK_PLUG_MCODE_KEY, + log_warning( + "Invalid format for value of key '%s' specified, fallback " + "to default '%s'", + IIDXHOOK_CONFIG_SEC_BLACK_PLUG_MCODE_KEY, tmp_str); - memcpy(&config_sec->black_plug_mcode, + memcpy( + &config_sec->black_plug_mcode, &IIDXHOOK_CONFIG_SEC_DEFAULT_BLACK_PLUG_MCODE_VALUE, sizeof(IIDXHOOK_CONFIG_SEC_DEFAULT_BLACK_PLUG_MCODE_VALUE)); } diff --git a/src/main/iidxhook-util/config-sec.h b/src/main/iidxhook-util/config-sec.h index 0827ba3..314940d 100644 --- a/src/main/iidxhook-util/config-sec.h +++ b/src/main/iidxhook-util/config-sec.h @@ -11,9 +11,9 @@ struct iidxhook_config_sec { struct security_mcode black_plug_mcode; }; -void iidxhook_config_sec_init(struct cconfig* config); +void iidxhook_config_sec_init(struct cconfig *config); -void iidxhook_config_sec_get(struct iidxhook_config_sec* config_sec, - struct cconfig* config); +void iidxhook_config_sec_get( + struct iidxhook_config_sec *config_sec, struct cconfig *config); #endif \ No newline at end of file diff --git a/src/main/iidxhook-util/d3d9.c b/src/main/iidxhook-util/d3d9.c index 028537e..b33b1c4 100644 --- a/src/main/iidxhook-util/d3d9.c +++ b/src/main/iidxhook-util/d3d9.c @@ -1,8 +1,8 @@ #define LOG_MODULE "d3d9-hook" -#include #include #include +#include #include #include @@ -33,10 +33,19 @@ struct d3d9_vertex { /* ------------------------------------------------------------------------- */ -typedef HRESULT WINAPI (*func_D3DXCreateFontA)(struct IDirect3DDevice9 *device, - INT height, UINT width, UINT weight, UINT miplevels, BOOL italic, - DWORD charset, DWORD precision, DWORD quality, DWORD pitchandfamily, - const char *facename, struct ID3DXFont **font); +typedef HRESULT WINAPI (*func_D3DXCreateFontA)( + struct IDirect3DDevice9 *device, + INT height, + UINT width, + UINT weight, + UINT miplevels, + BOOL italic, + DWORD charset, + DWORD precision, + DWORD quality, + DWORD pitchandfamily, + const char *facename, + struct ID3DXFont **font); /* ------------------------------------------------------------------------- */ @@ -48,22 +57,23 @@ static struct { uint16_t original_back_buffer_width; uint16_t original_back_buffer_height; - IDirect3DTexture9* rt_texture; - IDirect3DSurface9* rt_surface; - IDirect3DSurface9* rt_orig_surface; + IDirect3DTexture9 *rt_texture; + IDirect3DSurface9 *rt_surface; + IDirect3DSurface9 *rt_orig_surface; D3DTEXTUREFILTERTYPE filter; } iidxhook_util_d3d9_back_buffer_scaling; -/* ------------------------------------------------------------------------------------------------------------------ */ +/* ------------------------------------------------------------------------------------------------------------------ + */ static bool iidxhook_util_d3d9_float_equal(float a, float b, float eps) { return fabs(a - b) < eps; } -static void iidxhook_util_d3d9_calc_win_size_with_framed(HWND hwnd, DWORD x, DWORD y, DWORD width, DWORD height, - LPWINDOWPOS wp) +static void iidxhook_util_d3d9_calc_win_size_with_framed( + HWND hwnd, DWORD x, DWORD y, DWORD width, DWORD height, LPWINDOWPOS wp) { /* taken from dxwnd */ RECT rect; @@ -102,35 +112,47 @@ static void iidxhook_util_d3d9_calc_win_size_with_framed(HWND hwnd, DWORD x, DWO wp->cy = rect.bottom - rect.top; } -/* ------------------------------------------------------------------------------------------------------------------ */ +/* ------------------------------------------------------------------------------------------------------------------ + */ -static void iidxhook_util_d3d9_patch_gpu_vid_pid(struct hook_d3d9_irp* irp) +static void iidxhook_util_d3d9_patch_gpu_vid_pid(struct hook_d3d9_irp *irp) { char pci_id[32]; log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_ENUM_DISPLAY_DEVICES); - if (iidxhook_util_d3d9_config.pci_vid > 0 && iidxhook_util_d3d9_config.pci_pid > 0) { - str_format(pci_id, sizeof(pci_id), "PCI\\VEN_%04X&DEV_%04X", iidxhook_util_d3d9_config.pci_vid, + if (iidxhook_util_d3d9_config.pci_vid > 0 && + iidxhook_util_d3d9_config.pci_pid > 0) { + + str_format( + pci_id, + sizeof(pci_id), + "PCI\\VEN_%04X&DEV_%04X", + iidxhook_util_d3d9_config.pci_vid, iidxhook_util_d3d9_config.pci_pid); /* Apparently Konami didn't read the "Not Used" message in the MSDN docs for DISPLAY_DEVICE */ - log_misc("Replacing device ID %s with %s", irp->args.enum_display_devices.info->DeviceID, pci_id); + log_misc( + "Replacing device ID %s with %s", + irp->args.enum_display_devices.info->DeviceID, + pci_id); - str_cpy(irp->args.enum_display_devices.info->DeviceID, - sizeof(irp->args.enum_display_devices.info->DeviceID), - pci_id); + str_cpy( + irp->args.enum_display_devices.info->DeviceID, + sizeof(irp->args.enum_display_devices.info->DeviceID), + pci_id); } } -static void iidxhook_util_d3d9_patch_window(struct hook_d3d9_irp* irp) +static void iidxhook_util_d3d9_patch_window(struct hook_d3d9_irp *irp) { log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_CREATE_WINDOW_EX); - if (iidxhook_util_d3d9_config.windowed && iidxhook_util_d3d9_config.framed) { + if (iidxhook_util_d3d9_config.windowed && + iidxhook_util_d3d9_config.framed) { /* use a different style */ irp->args.create_window_ex.style |= WS_OVERLAPPEDWINDOW; @@ -138,24 +160,30 @@ static void iidxhook_util_d3d9_patch_window(struct hook_d3d9_irp* irp) ShowCursor(TRUE); } - if (iidxhook_util_d3d9_config.override_window_width > 0 && iidxhook_util_d3d9_config.override_window_height) { - log_misc("Overriding window size from %dx%d with %dx%d", - irp->args.create_window_ex.width, - irp->args.create_window_ex.height, + if (iidxhook_util_d3d9_config.override_window_width > 0 && + iidxhook_util_d3d9_config.override_window_height) { + log_misc( + "Overriding window size from %dx%d with %dx%d", + irp->args.create_window_ex.width, + irp->args.create_window_ex.height, iidxhook_util_d3d9_config.override_window_width, iidxhook_util_d3d9_config.override_window_height); - irp->args.create_window_ex.width = iidxhook_util_d3d9_config.override_window_width; - irp->args.create_window_ex.height = iidxhook_util_d3d9_config.override_window_height; + irp->args.create_window_ex.width = + iidxhook_util_d3d9_config.override_window_width; + irp->args.create_window_ex.height = + iidxhook_util_d3d9_config.override_window_height; } } -static void iidxhook_util_d3d9_fix_window_size_and_pos(struct hook_d3d9_irp* irp) +static void +iidxhook_util_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); - if (iidxhook_util_d3d9_config.windowed && iidxhook_util_d3d9_config.framed) { + if (iidxhook_util_d3d9_config.windowed && + iidxhook_util_d3d9_config.framed) { /* we have to adjust the window size, because the window needs to be a slightly bigger than the rendering resolution (window caption and stuff is included in the window size) */ @@ -168,8 +196,9 @@ static void iidxhook_util_d3d9_fix_window_size_and_pos(struct hook_d3d9_irp* irp irp->args.create_window_ex.width, irp->args.create_window_ex.height, &wp); - - SetWindowPos(irp->args.create_window_ex.result, 0, wp.x, wp.y, wp.cx, wp.cy, 0); + + SetWindowPos( + irp->args.create_window_ex.result, 0, wp.x, wp.y, wp.cx, wp.cy, 0); irp->args.create_window_ex.x = wp.x; irp->args.create_window_ex.y = wp.y; @@ -178,47 +207,58 @@ static void iidxhook_util_d3d9_fix_window_size_and_pos(struct hook_d3d9_irp* irp } } -static void iidxhook_util_d3d9_log_create_device_params(struct hook_d3d9_irp* irp) +static void +iidxhook_util_d3d9_log_create_device_params(struct hook_d3d9_irp *irp) { log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_CTX_CREATE_DEVICE); - log_misc("CreateDevice parameters: adapter %d, type %d, hwnd %p, flags %lX, pdev %p", - irp->args.ctx_create_device.adapter, - irp->args.ctx_create_device.type, - irp->args.ctx_create_device.hwnd, - irp->args.ctx_create_device.flags, - irp->args.ctx_create_device.pdev); + log_misc( + "CreateDevice parameters: adapter %d, type %d, hwnd %p, flags %lX, " + "pdev %p", + irp->args.ctx_create_device.adapter, + irp->args.ctx_create_device.type, + irp->args.ctx_create_device.hwnd, + irp->args.ctx_create_device.flags, + irp->args.ctx_create_device.pdev); - log_misc("D3D9 presenter parameters: BackBufferWidth %d, BackBufferHeight %d, BackBufferFormat %d, " - "BackBufferCount %d, MultiSampleType %d, SwapEffect %d, hDeviceWindow %p, Windowed %d, EnableAutoDepthStencil " - "%d, AutoDepthStencilFormat %d, Flags %lX, FullScreen_RefreshRateInHz %d", - irp->args.ctx_create_device.pp->BackBufferWidth, - irp->args.ctx_create_device.pp->BackBufferHeight, - irp->args.ctx_create_device.pp->BackBufferFormat, - irp->args.ctx_create_device.pp->BackBufferCount, - irp->args.ctx_create_device.pp->MultiSampleType, - irp->args.ctx_create_device.pp->SwapEffect, - irp->args.ctx_create_device.pp->hDeviceWindow, - irp->args.ctx_create_device.pp->Windowed, - irp->args.ctx_create_device.pp->EnableAutoDepthStencil, - irp->args.ctx_create_device.pp->AutoDepthStencilFormat, - irp->args.ctx_create_device.pp->Flags, - irp->args.ctx_create_device.pp->FullScreen_RefreshRateInHz); + log_misc( + "D3D9 presenter parameters: BackBufferWidth %d, BackBufferHeight " + "%d, BackBufferFormat %d, " + "BackBufferCount %d, MultiSampleType %d, SwapEffect %d, " + "hDeviceWindow %p, Windowed %d, " + "EnableAutoDepthStencil " + "%d, AutoDepthStencilFormat %d, Flags %lX, " + "FullScreen_RefreshRateInHz %d", + irp->args.ctx_create_device.pp->BackBufferWidth, + irp->args.ctx_create_device.pp->BackBufferHeight, + irp->args.ctx_create_device.pp->BackBufferFormat, + irp->args.ctx_create_device.pp->BackBufferCount, + irp->args.ctx_create_device.pp->MultiSampleType, + irp->args.ctx_create_device.pp->SwapEffect, + irp->args.ctx_create_device.pp->hDeviceWindow, + irp->args.ctx_create_device.pp->Windowed, + irp->args.ctx_create_device.pp->EnableAutoDepthStencil, + irp->args.ctx_create_device.pp->AutoDepthStencilFormat, + irp->args.ctx_create_device.pp->Flags, + irp->args.ctx_create_device.pp->FullScreen_RefreshRateInHz); } -static void iidxhook_util_d3d9_fix_iidx_bug_software_processing(struct hook_d3d9_irp* irp) +static void +iidxhook_util_d3d9_fix_iidx_bug_software_processing(struct hook_d3d9_irp *irp) { log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_CTX_CREATE_DEVICE); /* Fix a long-standing bug in IIDX */ - if (irp->args.ctx_create_device.flags & D3DCREATE_SOFTWARE_VERTEXPROCESSING) { + if (irp->args.ctx_create_device.flags & + D3DCREATE_SOFTWARE_VERTEXPROCESSING) { irp->args.ctx_create_device.flags &= ~D3DCREATE_PUREDEVICE; } } -static void iidxhook_util_d3d9_fix_create_device_apply_window_mode(struct hook_d3d9_irp* irp) +static void iidxhook_util_d3d9_fix_create_device_apply_window_mode( + struct hook_d3d9_irp *irp) { log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_CTX_CREATE_DEVICE); @@ -229,46 +269,62 @@ static void iidxhook_util_d3d9_fix_create_device_apply_window_mode(struct hook_d } } -static void iidxhook_util_d3d9_fix_back_buffer_format(struct hook_d3d9_irp* irp) +static void iidxhook_util_d3d9_fix_back_buffer_format(struct hook_d3d9_irp *irp) { log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_CTX_CREATE_DEVICE); /* Same fix as on D3D8, orz... - If we don't do this, some games one certain platforms (e.g. iidx 14/15 on Windows 10). - CreateDevice fails with an "invalid call" on either fullscreen or windowed or even both. - Also, further reports about textures with green glowing borders are gone as well when applying this */ + If we don't do this, some games one certain platforms (e.g. iidx 14/15 on + Windows 10). CreateDevice fails with an "invalid call" on either + fullscreen or windowed or even both. + Also, further reports about textures with green glowing borders are gone + as well when applying this */ D3DDISPLAYMODE mode; IDirect3D9_GetAdapterDisplayMode( - irp->args.ctx_create_device.self, - irp->args.ctx_create_device.adapter, + irp->args.ctx_create_device.self, + irp->args.ctx_create_device.adapter, &mode); irp->args.ctx_create_device.pp->BackBufferFormat = mode.Format; } -static ID3DXFont* iidxhook_util_d3d9_load_and_create_font(IDirect3DDevice9* dev) +static ID3DXFont *iidxhook_util_d3d9_load_and_create_font(IDirect3DDevice9 *dev) { HMODULE d3d9_24; HRESULT hr; - ID3DXFont* font; - + ID3DXFont *font; + d3d9_24 = GetModuleHandleA("d3dx9_24.dll"); if (d3d9_24 == NULL) { - log_warning("Failed to load d3dx9_24.dll to create a font for displaying framerate on monitor check."); + log_warning( + "Failed to load d3dx9_24.dll to create a font for displaying " + "framerate on monitor check."); return NULL; } - func_D3DXCreateFontA d3dxCreateFontA =(func_D3DXCreateFontA) GetProcAddress(d3d9_24, "D3DXCreateFontA"); + func_D3DXCreateFontA d3dxCreateFontA = + (func_D3DXCreateFontA) GetProcAddress(d3d9_24, "D3DXCreateFontA"); if (d3dxCreateFontA == NULL) { log_warning("Failed to find function D3DXCreateFontA"); return NULL; } - hr = d3dxCreateFontA(dev, 22, 0, FW_NORMAL, 1, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, - FF_DONTCARE, "Arial", &font); + hr = d3dxCreateFontA( + dev, + 22, + 0, + FW_NORMAL, + 1, + false, + DEFAULT_CHARSET, + OUT_DEFAULT_PRECIS, + ANTIALIASED_QUALITY, + FF_DONTCARE, + "Arial", + &font); if (hr != S_OK) { log_warning("Failed to load font for monitor check: %lX", hr); @@ -278,7 +334,7 @@ static ID3DXFont* iidxhook_util_d3d9_load_and_create_font(IDirect3DDevice9* dev) return font; } -static void iidxhook_util_d3d9_execute_monitor_check(struct hook_d3d9_irp* irp) +static void iidxhook_util_d3d9_execute_monitor_check(struct hook_d3d9_irp *irp) { const uint32_t max_iterations = 60 * 30; const uint32_t skip_frames = 60 * 1; @@ -289,7 +345,7 @@ static void iidxhook_util_d3d9_execute_monitor_check(struct hook_d3d9_irp* irp) uint64_t start; char text_buffer[256]; - ID3DXFont* font; + ID3DXFont *font; RECT font_rect; log_assert(irp); @@ -303,10 +359,13 @@ static void iidxhook_util_d3d9_execute_monitor_check(struct hook_d3d9_irp* irp) result = 0; iterations = 0; - font = iidxhook_util_d3d9_load_and_create_font(*irp->args.ctx_create_device.pdev); + font = iidxhook_util_d3d9_load_and_create_font( + *irp->args.ctx_create_device.pdev); if (font == NULL) { - log_info("Monitor check without on-screen text showing current refresh rate."); + log_info( + "Monitor check without on-screen text showing current " + "refresh rate."); } else { SetRect(&font_rect, 20, 20, 640, 480); } @@ -318,8 +377,8 @@ static void iidxhook_util_d3d9_execute_monitor_check(struct hook_d3d9_irp* irp) "Monitor check...\n" "Elapsed iterations: %d/%d\n" "Refresh rate: %f", - iterations + 1, - max_iterations, + iterations + 1, + max_iterations, result); } @@ -328,16 +387,30 @@ static void iidxhook_util_d3d9_execute_monitor_check(struct hook_d3d9_irp* irp) IDirect3DDevice9_BeginScene(*irp->args.ctx_create_device.pdev); - IDirect3DDevice9_Clear(*irp->args.ctx_create_device.pdev, 0, NULL, D3DCLEAR_TARGET, - D3DCOLOR_XRGB(0xFF, 0xFF, 0xFF), 0.0f, 0); + IDirect3DDevice9_Clear( + *irp->args.ctx_create_device.pdev, + 0, + NULL, + D3DCLEAR_TARGET, + D3DCOLOR_XRGB(0xFF, 0xFF, 0xFF), + 0.0f, + 0); if (font) { - ID3DXFont_DrawTextA(font, NULL, text_buffer, -1, &font_rect, DT_LEFT, D3DCOLOR_XRGB(0xFF, 0xFF, 0xFF)); + ID3DXFont_DrawTextA( + font, + NULL, + text_buffer, + -1, + &font_rect, + DT_LEFT, + D3DCOLOR_XRGB(0xFF, 0xFF, 0xFF)); } IDirect3DDevice9_EndScene(*irp->args.ctx_create_device.pdev); - IDirect3DDevice9_Present(*irp->args.ctx_create_device.pdev, NULL, NULL, NULL, NULL); + IDirect3DDevice9_Present( + *irp->args.ctx_create_device.pdev, NULL, NULL, NULL, NULL); /* Skip the first inaccurate values */ if (iterations > skip_frames) { @@ -348,15 +421,20 @@ static void iidxhook_util_d3d9_execute_monitor_check(struct hook_d3d9_irp* irp) } } - log_info("Monitor check done (total iterations %d), refesh rate: %f hz", - iterations, result); - + log_info( + "Monitor check done (total iterations %d), refesh rate: %f hz", + iterations, + result); + /* Sanity check to ensure people notice that their current refresh rate is way off. */ if (result < 55 || result > 65) { - log_warning("Monitor check result (%f hz) is not even near the " - "intended refresh rate of 60 hz. Fix your setup to ensure a " - "constant and as close to as possible 60 hz refresh rate.", result); + log_warning( + "Monitor check result (%f hz) is not even near the " + "intended refresh rate of 60 hz. Fix your setup to ensure " + "a " + "constant and as close to as possible 60 hz refresh rate.", + result); } /* Leave results of monitor check on screen for a moment */ @@ -370,7 +448,7 @@ static void iidxhook_util_d3d9_execute_monitor_check(struct hook_d3d9_irp* irp) static void iidxhook_util_d3d9_log_result_create_device(HRESULT hr) { - char* error; + char *error; if (hr != S_OK) { switch (hr) { @@ -399,32 +477,33 @@ static void iidxhook_util_d3d9_log_result_create_device(HRESULT hr) } } -static void iidxhook_util_d3d9_nvidia_fix_iidx14_to_19(struct hook_d3d9_irp* irp) +static void +iidxhook_util_d3d9_nvidia_fix_iidx14_to_19(struct hook_d3d9_irp *irp) { log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_DEV_CREATE_TEXTURE); /* Fix non ATI cards not working on Gold (and DJT?). There is a check that creates textures when starting the game. This check fails which results - in a message box being shown mentioning something about an aep-lib error. - Seems like a combination of parameters is not supported by - non ATI cards and throws an error - (Fix taken from old Gold cracks by ahnada and tau) + in a message box being shown mentioning something about an aep-lib + error. Seems like a combination of parameters is not supported by non ATI + cards and throws an error (Fix taken from old Gold cracks by ahnada and + tau) */ - if (iidxhook_util_d3d9_config.iidx14_to_19_nvidia_fix && - irp->args.dev_create_texture.width == 256 && - irp->args.dev_create_texture.height == 256 && - irp->args.dev_create_texture.levels == 1 && - irp->args.dev_create_texture.usage == D3DUSAGE_RENDERTARGET && - irp->args.dev_create_texture.format == D3DFMT_A1R5G5B5 && - irp->args.dev_create_texture.pool == D3DPOOL_DEFAULT && - irp->args.dev_create_texture.shared_handle == NULL) { + if (iidxhook_util_d3d9_config.iidx14_to_19_nvidia_fix && + irp->args.dev_create_texture.width == 256 && + irp->args.dev_create_texture.height == 256 && + irp->args.dev_create_texture.levels == 1 && + irp->args.dev_create_texture.usage == D3DUSAGE_RENDERTARGET && + irp->args.dev_create_texture.format == D3DFMT_A1R5G5B5 && + irp->args.dev_create_texture.pool == D3DPOOL_DEFAULT && + irp->args.dev_create_texture.shared_handle == NULL) { irp->args.dev_create_texture.format = D3DFMT_A8R8G8B8; } } -static void iidxhook_util_d3d9_framerate_limiter(struct hook_d3d9_irp* irp) +static void iidxhook_util_d3d9_framerate_limiter(struct hook_d3d9_irp *irp) { log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_DEV_PRESENT); @@ -433,14 +512,18 @@ static void iidxhook_util_d3d9_framerate_limiter(struct hook_d3d9_irp* irp) if (iidxhook_util_d3d9_present_current_time == 0) { iidxhook_util_d3d9_present_current_time = time_get_counter(); } else { - uint64_t frame_time = 1000000 / iidxhook_util_d3d9_config.framerate_limit; + uint64_t frame_time = + 1000000 / iidxhook_util_d3d9_config.framerate_limit; - uint64_t dt = time_get_elapsed_us(time_get_counter() - iidxhook_util_d3d9_present_current_time); + uint64_t dt = time_get_elapsed_us( + time_get_counter() - iidxhook_util_d3d9_present_current_time); while (dt < frame_time) { /* waste some cpu time by polling because we can't sleep for X us */ - dt = time_get_elapsed_us(time_get_counter() - iidxhook_util_d3d9_present_current_time); + dt = time_get_elapsed_us( + time_get_counter() - + iidxhook_util_d3d9_present_current_time); } iidxhook_util_d3d9_present_current_time = time_get_counter(); @@ -448,7 +531,8 @@ static void iidxhook_util_d3d9_framerate_limiter(struct hook_d3d9_irp* irp) } } -static void iidxhook_util_d3d9_iidx12_fix_song_select_bg(struct hook_d3d9_irp* irp) +static void +iidxhook_util_d3d9_iidx12_fix_song_select_bg(struct hook_d3d9_irp *irp) { log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_DEV_SET_RENDER_STATE); @@ -460,7 +544,8 @@ static void iidxhook_util_d3d9_iidx12_fix_song_select_bg(struct hook_d3d9_irp* i } } -static void iidxhook_util_d3d9_iidx13_fix_song_select_bg(struct hook_d3d9_irp* irp) +static void +iidxhook_util_d3d9_iidx13_fix_song_select_bg(struct hook_d3d9_irp *irp) { log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_DEV_SET_RENDER_STATE); @@ -472,18 +557,21 @@ static void iidxhook_util_d3d9_iidx13_fix_song_select_bg(struct hook_d3d9_irp* i } } -static void iidxhook_util_d3d9_iidx11_to_17_fix_uvs_bg_videos(struct hook_d3d9_irp* irp) +static void +iidxhook_util_d3d9_iidx11_to_17_fix_uvs_bg_videos(struct hook_d3d9_irp *irp) { log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_DEV_DRAW_PRIMITIVE_UP); /* same code taken from the d3d8 module. but, this just fixes the quad seam issue as there are no reports of streched bg videos */ - if (iidxhook_util_d3d9_config.iidx11_to_17_fix_uvs_bg_videos && - irp->args.dev_draw_primitive_up.primitive_type == D3DPT_TRIANGLEFAN && - irp->args.dev_draw_primitive_up.primitive_count == 2 && - irp->args.dev_draw_primitive_up.stride == 28) { - struct d3d9_vertex* vertices = (struct d3d9_vertex*) irp->args.dev_draw_primitive_up.data; + if (iidxhook_util_d3d9_config.iidx11_to_17_fix_uvs_bg_videos && + irp->args.dev_draw_primitive_up.primitive_type == D3DPT_TRIANGLEFAN && + irp->args.dev_draw_primitive_up.primitive_count == 2 && + irp->args.dev_draw_primitive_up.stride == 28) { + + struct d3d9_vertex *vertices = + (struct d3d9_vertex *) irp->args.dev_draw_primitive_up.data; /* log_info("Video Tex: %f/%f %f/%f %f/%f %f/%f", @@ -494,14 +582,14 @@ static void iidxhook_util_d3d9_iidx11_to_17_fix_uvs_bg_videos(struct hook_d3d9_i */ /* Fix full screen background videos (e.g. DistorteD intro sequence) */ - if ( vertices[0].x >= 0.0f && vertices[0].x < 1.0f && - vertices[0].y >= 0.0f && vertices[0].y < 1.0f && - vertices[1].x > 639.0f && vertices[1].x < 641.0f && - vertices[1].y >= 0.0f && vertices[1].y < 1.0f && - vertices[2].x > 639.0f && vertices[2].x < 641.0f && - vertices[2].y > 479.0f && vertices[2].y < 481.0f && - vertices[3].x >= 0.0f && vertices[3].x < 1.0f && - vertices[3].y > 479.0f && vertices[3].y < 481.0f) { + if (vertices[0].x >= 0.0f && vertices[0].x < 1.0f && + vertices[0].y >= 0.0f && vertices[0].y < 1.0f && + vertices[1].x > 639.0f && vertices[1].x < 641.0f && + vertices[1].y >= 0.0f && vertices[1].y < 1.0f && + vertices[2].x > 639.0f && vertices[2].x < 641.0f && + vertices[2].y > 479.0f && vertices[2].y < 481.0f && + vertices[3].x >= 0.0f && vertices[3].x < 1.0f && + vertices[3].y > 479.0f && vertices[3].y < 481.0f) { /* fix UVs 1.0f / 640 or 480 fixes the diagonal seam connecting the two triangles which is visible on some GPUs (why? idk) @@ -516,56 +604,58 @@ static void iidxhook_util_d3d9_iidx11_to_17_fix_uvs_bg_videos(struct hook_d3d9_i vertices[3].tv = 0.0f + 1.0f / 480; } else - /* another identifier, because there are other textures with 512x512 size - make sure we got the bg video only to not mess up anything else */ - /* different versions have different themes and position the bg video - on slightly different positions (good job...) */ - if ( /* single */ + /* another identifier, because there are other textures with + 512x512 size make sure we got the bg video only to not mess + up anything else */ + /* different versions have different themes and position the bg + video on slightly different positions (good job...) */ + if (/* single */ ((vertices[0].x >= 164.0f && vertices[0].x <= 168.0f && - iidxhook_util_d3d9_float_equal(vertices[0].y, 0.0f, 0.1f)) && - (vertices[1].x >= 472.0f && vertices[1].x <= 476.0f && - iidxhook_util_d3d9_float_equal(vertices[1].y, 0.0f, 0.1f)) && - (vertices[2].x >= 472.0f && vertices[2].x <= 476.0f && - iidxhook_util_d3d9_float_equal(vertices[2].y, 416.0f, 0.1f)) && - (vertices[3].x >= 164.0f && vertices[3].x <= 168.0f && - iidxhook_util_d3d9_float_equal(vertices[3].y, 416.0f, 0.1f))) || + iidxhook_util_d3d9_float_equal(vertices[0].y, 0.0f, 0.1f)) && + (vertices[1].x >= 472.0f && vertices[1].x <= 476.0f && + iidxhook_util_d3d9_float_equal(vertices[1].y, 0.0f, 0.1f)) && + (vertices[2].x >= 472.0f && vertices[2].x <= 476.0f && + iidxhook_util_d3d9_float_equal( + vertices[2].y, 416.0f, 0.1f)) && + (vertices[3].x >= 164.0f && vertices[3].x <= 168.0f && + iidxhook_util_d3d9_float_equal( + vertices[3].y, 416.0f, 0.1f))) || /* double top left */ ((iidxhook_util_d3d9_float_equal(vertices[0].x, 6.0f, 0.1f) && - vertices[0].y >= 24.0f && vertices[0].y <= 28.0f) && - (iidxhook_util_d3d9_float_equal(vertices[1].x, 147.0f, 0.1f) && - vertices[1].y >= 24.0f && vertices[1].y <= 28.0f) && - (iidxhook_util_d3d9_float_equal(vertices[2].x, 147.0f, 0.1f) && - vertices[2].y >= 212.0f && vertices[2].y <= 216.0f) && - (iidxhook_util_d3d9_float_equal(vertices[3].x, 6.0f, 0.1f) && - vertices[3].y >= 212.0f && vertices[3].y <= 216.0f)) || + vertices[0].y >= 24.0f && vertices[0].y <= 28.0f) && + (iidxhook_util_d3d9_float_equal(vertices[1].x, 147.0f, 0.1f) && + vertices[1].y >= 24.0f && vertices[1].y <= 28.0f) && + (iidxhook_util_d3d9_float_equal(vertices[2].x, 147.0f, 0.1f) && + vertices[2].y >= 212.0f && vertices[2].y <= 216.0f) && + (iidxhook_util_d3d9_float_equal(vertices[3].x, 6.0f, 0.1f) && + vertices[3].y >= 212.0f && vertices[3].y <= 216.0f)) || /* double bottom left */ ((iidxhook_util_d3d9_float_equal(vertices[0].x, 6.0f, 0.1f) && - vertices[0].y >= 216.0f && vertices[0].y <= 220.0f) && - (iidxhook_util_d3d9_float_equal(vertices[1].x, 147.0f, 0.1f) && - vertices[1].y >= 216.0f && vertices[1].y <= 220.0f) && - (iidxhook_util_d3d9_float_equal(vertices[2].x, 147.0f, 0.1) && - vertices[2].y >= 404.0f && vertices[2].y <= 408.0f) && - (iidxhook_util_d3d9_float_equal(vertices[3].x, 6.0f, 0.1f) && - vertices[3].y >= 404.0f && vertices[3].y <= 408.0f)) || + vertices[0].y >= 216.0f && vertices[0].y <= 220.0f) && + (iidxhook_util_d3d9_float_equal(vertices[1].x, 147.0f, 0.1f) && + vertices[1].y >= 216.0f && vertices[1].y <= 220.0f) && + (iidxhook_util_d3d9_float_equal(vertices[2].x, 147.0f, 0.1) && + vertices[2].y >= 404.0f && vertices[2].y <= 408.0f) && + (iidxhook_util_d3d9_float_equal(vertices[3].x, 6.0f, 0.1f) && + vertices[3].y >= 404.0f && vertices[3].y <= 408.0f)) || /* double top right */ ((vertices[0].x >= 493.0f && vertices[0].x <= 494.0f && - vertices[0].y >= 24.0f && vertices[0].y <= 28.0f) && - (vertices[1].x >= 634.0f && vertices[1].x <= 635.0f && - vertices[1].y >= 24.0f && vertices[1].y <= 28.0f) && - (vertices[2].x >= 634.0f && vertices[2].x <= 635.0f && - vertices[2].y >= 212.0f && vertices[2].y <= 216.0f) && - (vertices[3].x >= 493.0f && vertices[3].x <= 494.0f && - vertices[3].y >= 212.0f && vertices[3].y <= 216.0f)) || + vertices[0].y >= 24.0f && vertices[0].y <= 28.0f) && + (vertices[1].x >= 634.0f && vertices[1].x <= 635.0f && + vertices[1].y >= 24.0f && vertices[1].y <= 28.0f) && + (vertices[2].x >= 634.0f && vertices[2].x <= 635.0f && + vertices[2].y >= 212.0f && vertices[2].y <= 216.0f) && + (vertices[3].x >= 493.0f && vertices[3].x <= 494.0f && + vertices[3].y >= 212.0f && vertices[3].y <= 216.0f)) || /* double bottom right */ ((vertices[0].x >= 493.0f && vertices[0].x <= 494.0f && - vertices[0].y >= 216.0f && vertices[0].y <= 220.0f) && - (vertices[1].x >= 634.0f && vertices[1].x <= 635.0f && - vertices[1].y >= 216.0f && vertices[1].y <= 220.0f) && - (vertices[2].x >= 634.0f && vertices[2].x <= 635.0f && - vertices[2].y >= 404.0f && vertices[2].y <= 408.0f) && - (vertices[3].x >= 493.0f && vertices[3].x <= 494.0f && - vertices[3].y >= 404.0f && vertices[3].y <= 408.0f))) - { + vertices[0].y >= 216.0f && vertices[0].y <= 220.0f) && + (vertices[1].x >= 634.0f && vertices[1].x <= 635.0f && + vertices[1].y >= 216.0f && vertices[1].y <= 220.0f) && + (vertices[2].x >= 634.0f && vertices[2].x <= 635.0f && + vertices[2].y >= 404.0f && vertices[2].y <= 408.0f) && + (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) @@ -582,32 +672,39 @@ static void iidxhook_util_d3d9_iidx11_to_17_fix_uvs_bg_videos(struct hook_d3d9_i } } -static void iidxhook_uti_d3d9_fix_iidx9_to_13_viewport_size(struct hook_d3d9_irp* irp) +static void +iidxhook_uti_d3d9_fix_iidx9_to_13_viewport_size(struct hook_d3d9_irp *irp) { log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_GET_CLIENT_RECT); - /* IIDX 9-13 (at least) use this call to get the size of rectangle for setting the viewport size... */ + /* IIDX 9-13 (at least) use this call to get the size of rectangle for + * setting the viewport size... */ - /* Always use the original requested back buffer size. If scaling is active, using the scaled - values leads to (3D) scenes getting render to a viewport with incorrect sized. */ + /* Always use the original requested back buffer size. If scaling is active, + using the scaled + values leads to (3D) scenes getting render to a viewport with incorrect + sized. */ irp->args.get_client_rect.rect->left = 0; irp->args.get_client_rect.rect->top = 0; - irp->args.get_client_rect.rect->right = iidxhook_util_d3d9_back_buffer_scaling.original_back_buffer_width; - irp->args.get_client_rect.rect->bottom = iidxhook_util_d3d9_back_buffer_scaling.original_back_buffer_height; + irp->args.get_client_rect.rect->right = + iidxhook_util_d3d9_back_buffer_scaling.original_back_buffer_width; + irp->args.get_client_rect.rect->bottom = + iidxhook_util_d3d9_back_buffer_scaling.original_back_buffer_height; } -static void iidxhook_util_d3d9_setup_back_buffer_scaling_pre(struct hook_d3d9_irp* irp) +static void +iidxhook_util_d3d9_setup_back_buffer_scaling_pre(struct hook_d3d9_irp *irp) { log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_CTX_CREATE_DEVICE); /* Store these so we can apply scaling further down */ - iidxhook_util_d3d9_back_buffer_scaling.original_back_buffer_width = + iidxhook_util_d3d9_back_buffer_scaling.original_back_buffer_width = irp->args.ctx_create_device.pp->BackBufferWidth; - iidxhook_util_d3d9_back_buffer_scaling.original_back_buffer_height = + iidxhook_util_d3d9_back_buffer_scaling.original_back_buffer_height = irp->args.ctx_create_device.pp->BackBufferHeight; - + switch (iidxhook_util_d3d9_config.scale_back_buffer_filter) { case IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_NONE: iidxhook_util_d3d9_back_buffer_scaling.filter = D3DTEXF_NONE; @@ -622,40 +719,47 @@ static void iidxhook_util_d3d9_setup_back_buffer_scaling_pre(struct hook_d3d9_ir break; default: - log_fatal("Unhandled case, illegal state: %d", iidxhook_util_d3d9_config.scale_back_buffer_filter); + log_fatal( + "Unhandled case, illegal state: %d", + iidxhook_util_d3d9_config.scale_back_buffer_filter); break; } - if (iidxhook_util_d3d9_config.scale_back_buffer_width > 0 && - iidxhook_util_d3d9_config.scale_back_buffer_height > 0) { - log_misc("Scale back buffer from %dx%d -> %dx%d", + if (iidxhook_util_d3d9_config.scale_back_buffer_width > 0 && + iidxhook_util_d3d9_config.scale_back_buffer_height > 0) { + + log_misc( + "Scale back buffer from %dx%d -> %dx%d", iidxhook_util_d3d9_back_buffer_scaling.original_back_buffer_width, iidxhook_util_d3d9_back_buffer_scaling.original_back_buffer_height, iidxhook_util_d3d9_config.scale_back_buffer_width, iidxhook_util_d3d9_config.scale_back_buffer_height); - - irp->args.ctx_create_device.pp->BackBufferWidth = + + irp->args.ctx_create_device.pp->BackBufferWidth = iidxhook_util_d3d9_config.scale_back_buffer_width; - irp->args.ctx_create_device.pp->BackBufferHeight = + irp->args.ctx_create_device.pp->BackBufferHeight = iidxhook_util_d3d9_config.scale_back_buffer_height; } } -static void iidxhook_util_d3d9_setup_back_buffer_scaling_post(struct hook_d3d9_irp* irp) +static void +iidxhook_util_d3d9_setup_back_buffer_scaling_post(struct hook_d3d9_irp *irp) { HRESULT hr; log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_CTX_CREATE_DEVICE); - if (iidxhook_util_d3d9_config.scale_back_buffer_width > 0 && - iidxhook_util_d3d9_config.scale_back_buffer_height > 0) { + if (iidxhook_util_d3d9_config.scale_back_buffer_width > 0 && + iidxhook_util_d3d9_config.scale_back_buffer_height > 0) { - log_misc("Creating intermediate render target texture: %dx%d", + log_misc( + "Creating intermediate render target texture: %dx%d", iidxhook_util_d3d9_back_buffer_scaling.original_back_buffer_width, iidxhook_util_d3d9_back_buffer_scaling.original_back_buffer_height); - /* This is our new render target. Let the game render to this in its native res instead of the back buffer */ + /* This is our new render target. Let the game render to this in its + * native res instead of the back buffer */ hr = IDirect3DDevice9_CreateTexture( *irp->args.ctx_create_device.pdev, iidxhook_util_d3d9_back_buffer_scaling.original_back_buffer_width, @@ -677,41 +781,42 @@ static void iidxhook_util_d3d9_setup_back_buffer_scaling_post(struct hook_d3d9_i &iidxhook_util_d3d9_back_buffer_scaling.rt_surface); if (hr != S_OK) { - log_fatal("Getting surface of render target texture failed: %lX", hr); + log_fatal( + "Getting surface of render target texture failed: %lX", hr); } /* Save surface of original render target */ hr = IDirect3DDevice9_GetRenderTarget( - *irp->args.ctx_create_device.pdev, - 0, + *irp->args.ctx_create_device.pdev, + 0, &iidxhook_util_d3d9_back_buffer_scaling.rt_orig_surface); if (hr != S_OK) { log_fatal("Getting original render target failed: %lX", hr); } - /* Avoid returning our scaled values because the application might use them, e.g. calculate - sprite positions. */ - irp->args.ctx_create_device.pp->BackBufferWidth = + /* Avoid returning our scaled values because the application might use + them, e.g. calculate sprite positions. */ + irp->args.ctx_create_device.pp->BackBufferWidth = iidxhook_util_d3d9_back_buffer_scaling.original_back_buffer_width; - irp->args.ctx_create_device.pp->BackBufferHeight = + irp->args.ctx_create_device.pp->BackBufferHeight = iidxhook_util_d3d9_back_buffer_scaling.original_back_buffer_height; } } -static void iidxhook_util_d3d9_set_intermediate_rt(struct hook_d3d9_irp* irp) +static void iidxhook_util_d3d9_set_intermediate_rt(struct hook_d3d9_irp *irp) { HRESULT hr; log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_DEV_BEGIN_SCENE); - if (iidxhook_util_d3d9_config.scale_back_buffer_width > 0 && - iidxhook_util_d3d9_config.scale_back_buffer_height > 0) { + if (iidxhook_util_d3d9_config.scale_back_buffer_width > 0 && + iidxhook_util_d3d9_config.scale_back_buffer_height > 0) { /* Set our intermediate render texture as render target */ hr = IDirect3DDevice9_SetRenderTarget( - irp->args.dev_begin_scene.self, - 0, + irp->args.dev_begin_scene.self, + 0, iidxhook_util_d3d9_back_buffer_scaling.rt_surface); if (hr != S_OK) { @@ -720,19 +825,19 @@ static void iidxhook_util_d3d9_set_intermediate_rt(struct hook_d3d9_irp* irp) } } -static void iidxhook_util_d3d9_set_back_buffer_rt(struct hook_d3d9_irp* irp) +static void iidxhook_util_d3d9_set_back_buffer_rt(struct hook_d3d9_irp *irp) { HRESULT hr; log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_DEV_PRESENT); - if (iidxhook_util_d3d9_config.scale_back_buffer_width > 0 && - iidxhook_util_d3d9_config.scale_back_buffer_height > 0) { + if (iidxhook_util_d3d9_config.scale_back_buffer_width > 0 && + iidxhook_util_d3d9_config.scale_back_buffer_height > 0) { /* Set our original surface/back buffer as rt */ hr = IDirect3DDevice9_SetRenderTarget( - irp->args.dev_present.self, - 0, + irp->args.dev_present.self, + 0, iidxhook_util_d3d9_back_buffer_scaling.rt_orig_surface); if (hr != S_OK) { @@ -741,7 +846,8 @@ static void iidxhook_util_d3d9_set_back_buffer_rt(struct hook_d3d9_irp* irp) } } -static void iidxhook_util_d3d9_scale_render_target_to_back_buffer(struct hook_d3d9_irp* irp) +static void +iidxhook_util_d3d9_scale_render_target_to_back_buffer(struct hook_d3d9_irp *irp) { HRESULT hr; RECT src_rect; @@ -749,12 +855,15 @@ static void iidxhook_util_d3d9_scale_render_target_to_back_buffer(struct hook_d3 log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_DEV_PRESENT); - if (iidxhook_util_d3d9_config.scale_back_buffer_width > 0 && - iidxhook_util_d3d9_config.scale_back_buffer_height > 0) { + if (iidxhook_util_d3d9_config.scale_back_buffer_width > 0 && + iidxhook_util_d3d9_config.scale_back_buffer_height > 0) { + src_rect.left = 0; src_rect.top = 0; - src_rect.right = iidxhook_util_d3d9_back_buffer_scaling.original_back_buffer_width; - src_rect.bottom = iidxhook_util_d3d9_back_buffer_scaling.original_back_buffer_height; + src_rect.right = + iidxhook_util_d3d9_back_buffer_scaling.original_back_buffer_width; + src_rect.bottom = + iidxhook_util_d3d9_back_buffer_scaling.original_back_buffer_height; hr = IDirect3DDevice9_StretchRect( irp->args.dev_present.self, @@ -765,14 +874,19 @@ static void iidxhook_util_d3d9_scale_render_target_to_back_buffer(struct hook_d3 iidxhook_util_d3d9_back_buffer_scaling.filter); if (hr != S_OK) { - log_fatal("Scaling intermediate render target to back buffer failed: %lX", hr); + log_fatal( + "Scaling intermediate render target to back buffer failed: " + "%lX", + hr); } } } -/* ------------------------------------------------------------------------------------------------------------------ */ +/* ------------------------------------------------------------------------------------------------------------------ + */ -static void iidxhook_util_d3d9_log_config(const struct iidxhook_util_d3d9_config* config) +static void +iidxhook_util_d3d9_log_config(const struct iidxhook_util_d3d9_config *config) { log_misc( "iidxhook_util_d3d9_config\n" @@ -808,31 +922,41 @@ static void iidxhook_util_d3d9_log_config(const struct iidxhook_util_d3d9_config config->scale_back_buffer_filter); } -static void iidxhook_util_d3d9_validate_config(const struct iidxhook_util_d3d9_config* config) +static void iidxhook_util_d3d9_validate_config( + const struct iidxhook_util_d3d9_config *config) { if (!config->windowed && config->framed) { log_warning("Option framed does not have an effect without windowed"); } if (config->override_window_width == -1) { - log_fatal("Invalid value for override_window_width: %d", config->override_window_width); + log_fatal( + "Invalid value for override_window_width: %d", + config->override_window_width); } if (config->override_window_height == -1) { - log_fatal("Invalid value for override_window_height: %d", config->override_window_height); + log_fatal( + "Invalid value for override_window_height: %d", + config->override_window_height); } - if (!config->windowed && - (config->override_window_width > 0 || config->override_window_height > 0)) { - log_warning("Overriding window size does not have an effect without windowed"); + if (!config->windowed && + (config->override_window_width > 0 || + config->override_window_height > 0)) { + log_warning( + "Overriding window size does not have an effect without " + "windowed"); } if (config->framerate_limit < 0.0f) { - log_fatal("Invalid value for framerate_limit: %f", config->framerate_limit); + log_fatal( + "Invalid value for framerate_limit: %f", config->framerate_limit); } } -/* ------------------------------------------------------------------------------------------------------------------ */ +/* ------------------------------------------------------------------------------------------------------------------ + */ void iidxhook_util_d3d9_hook_init(void) { @@ -841,7 +965,7 @@ void iidxhook_util_d3d9_hook_init(void) log_info("Initialized"); } -void iidxhook_util_d3d9_init_config(struct iidxhook_util_d3d9_config* config) +void iidxhook_util_d3d9_init_config(struct iidxhook_util_d3d9_config *config) { config->windowed = false; config->framed = false; @@ -857,20 +981,26 @@ void iidxhook_util_d3d9_init_config(struct iidxhook_util_d3d9_config* config) config->iidx14_to_19_nvidia_fix = false; config->scale_back_buffer_width = 0; config->scale_back_buffer_height = 0; - config->scale_back_buffer_filter = IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_NONE; + config->scale_back_buffer_filter = + IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_NONE; } -void iidxhook_util_d3d9_configure(const struct iidxhook_util_d3d9_config* config) +void iidxhook_util_d3d9_configure( + const struct iidxhook_util_d3d9_config *config) { log_assert(config); iidxhook_util_d3d9_log_config(config); iidxhook_util_d3d9_validate_config(config); - memcpy(&iidxhook_util_d3d9_config, config, sizeof(struct iidxhook_util_d3d9_config)); + memcpy( + &iidxhook_util_d3d9_config, + config, + sizeof(struct iidxhook_util_d3d9_config)); } -HRESULT iidxhook_util_d3d9_irp_handler(struct hook_d3d9_irp* irp) +HRESULT +iidxhook_util_d3d9_irp_handler(struct hook_d3d9_irp *irp) { HRESULT hr; @@ -912,7 +1042,7 @@ HRESULT iidxhook_util_d3d9_irp_handler(struct hook_d3d9_irp* irp) iidxhook_util_d3d9_fix_create_device_apply_window_mode(irp); iidxhook_util_d3d9_fix_back_buffer_format(irp); iidxhook_util_d3d9_setup_back_buffer_scaling_pre(irp); - + hr = hook_d3d9_irp_invoke_next(irp); if (hr == S_OK) { diff --git a/src/main/iidxhook-util/d3d9.h b/src/main/iidxhook-util/d3d9.h index 0ef3240..c581ed8 100644 --- a/src/main/iidxhook-util/d3d9.h +++ b/src/main/iidxhook-util/d3d9.h @@ -2,9 +2,10 @@ #define IIDXHOOK_D3D9_H /** - * This module hooks into various D3D9 calls implementing a large set of features for IIDX games such as: - * window mode, frame buffer up-/downscaling, software rate limiting, software monitor check,... - * + * This module hooks into various D3D9 calls implementing a large set of + * features for IIDX games such as: window mode, frame buffer up-/downscaling, + * software rate limiting, software monitor check,... + * * @author icex2 */ @@ -14,7 +15,8 @@ #include "hook/d3d9.h" /** - * Filter types for scaling back buffer, e.g. upscaling for higher resolution monitors. + * Filter types for scaling back buffer, e.g. upscaling for higher resolution + * monitors. */ enum iidxhook_util_d3d9_back_buffer_scale_filter { IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_NONE = 0, @@ -25,7 +27,8 @@ enum iidxhook_util_d3d9_back_buffer_scale_filter { /** * Callback function to receive resulting refresh rate of monitor check. */ -typedef void (*iidxhook_util_d3d9_monitor_check_result_callback_t)(double refresh_rate); +typedef void (*iidxhook_util_d3d9_monitor_check_result_callback_t)( + double refresh_rate); /** * Config structure for this module. Enable/disable supported features. @@ -35,35 +38,36 @@ struct iidxhook_util_d3d9_config { * Enable/disable window mode. Consider combining with framed. */ bool windowed; - + /** * Enable a window frame and make the window movable, resizable, minizable. */ bool framed; /** - * Override the default window height which is determined by the frame buffer size. - * Set this to 0 to disable the override. + * Override the default window height which is determined by the frame + * buffer size. Set this to 0 to disable the override. */ uint16_t override_window_width; /** - * Override the default window width which is determined by the frame buffer size. - * Set this to 0 to disable the override. + * Override the default window width which is determined by the frame buffer + * size. Set this to 0 to disable the override. */ uint16_t override_window_height; /** - * Set a software driven framerate limit for the rendering loop and lock to the specified refresh rate, e.g. 59.94. - * Use this if the game won't sync up properly with vsync enabled. + * Set a software driven framerate limit for the rendering loop and lock to + * the specified refresh rate, e.g. 59.94. Use this if the game won't sync + * up properly with vsync enabled. */ float framerate_limit; /** - * Override the GPU vendor ID identifier on display device enumeration. + * Override the GPU vendor ID identifier on display device enumeration. * Use this to disable locking to specific GPU cards. - * Combine with the pci_pid parameter. - * + * Combine with the pci_pid parameter. + * * Vendor ATI: 1002 */ uint16_t pci_vid; @@ -72,34 +76,37 @@ struct iidxhook_util_d3d9_config { * Override the GPU product ID identifier on display device enumeration. * Use this to disable locking to specific GPU cards. * Combine with the pci_pid parameter. - * + * * PIDs: * 7146: RV515 [Radeon X1300] - * 95C5: RV620 LE [Radeon HD 3450] + * 95C5: RV620 LE [Radeon HD 3450] */ uint16_t pci_pid; /** - * Enable a software "monitor check" which determines the (avg.) refresh rate - * of the game. Ensure that your GPU is outputting a stable refresh rate to - * your monitor. Otherwise, the resulting values fluctuate a lot. - * - * Callback to a function that receives the result of the monitor check once it completed. + * Enable a software "monitor check" which determines the (avg.) refresh + * rate of the game. Ensure that your GPU is outputting a stable refresh + * rate to your monitor. Otherwise, the resulting values fluctuate a lot. + * + * Callback to a function that receives the result of the monitor check once + * it completed. */ - iidxhook_util_d3d9_monitor_check_result_callback_t iidx09_to_19_monitor_check_cb; + iidxhook_util_d3d9_monitor_check_result_callback_t + iidx09_to_19_monitor_check_cb; /** * Ported from d3d8 module to enable this when using d3d8to9. - * - * Fixes UV coordinates for background videos on IIDX Red to DD and a quad seam issue for 14 to 17. - * Use this if you experience the game stretching the background videos or seeing a quad seam - * (see implementation for further details). + * + * Fixes UV coordinates for background videos on IIDX Red to DD and a quad + * seam issue for 14 to 17. Use this if you experience the game stretching + * the background videos or seeing a quad seam (see implementation for + * further details). */ bool iidx11_to_17_fix_uvs_bg_videos; /** * Ported from d3d8 module to enable this when using d3d8to9. - * + * * Fixes the 3D background displayed during song select by disabling fog. * On some machines/GPUs the background is rendered completely white which * is caused by buggy fog rendering. Fog is used to hide the rings appearing @@ -109,11 +116,12 @@ struct iidxhook_util_d3d9_config { /** * Ported from d3d8 module to enable this when using d3d8to9. - * - * Fixes the 3D background displayed during song select by disabling lighting. - * On some machines/GPUs the background is rendered completely black which - * is caused by buggy lighting. Disabling (dynamic) lighting sets the whole - * scene to ambient lighting which displays everything properly. + * + * Fixes the 3D background displayed during song select by disabling + * lighting. On some machines/GPUs the background is rendered completely + * black which is caused by buggy lighting. Disabling (dynamic) lighting + * sets the whole scene to ambient lighting which displays everything + * properly. */ bool iidx13_fix_song_select_bg; @@ -124,57 +132,67 @@ struct iidxhook_util_d3d9_config { bool iidx14_to_19_nvidia_fix; /** - * Scale the back buffer after a frame got rendered. This allows you to up-/downscale the final frame to display - * arbitrary resolutions, e.g. 640x480 -> 1920x1080 to allow displaying the game in the monitor's native resolution. - * This avoids over-/underscan (yes, that's still a thing with todays TVs) or leaving the upscaling to monitors/TVs - * that are doing a terrible job regarding picture quality or latency wise. - * - * @param width Target width to scale the frame to. 0 disables scaling entirely. - * @param height Target height to scale the frame to. 0 disables scaling entirely. - * @param filter Filtering method to use for scaling. Depending on how you scale, this can have an impact on the - * final image quality. + * Scale the back buffer after a frame got rendered. This allows you to + * up-/downscale the final frame to display arbitrary resolutions, e.g. + * 640x480 -> 1920x1080 to allow displaying the game in the monitor's native + * resolution. This avoids over-/underscan (yes, that's still a thing with + * todays TVs) or leaving the upscaling to monitors/TVs that are doing a + * terrible job regarding picture quality or latency wise. + * + * @param width Target width to scale the frame to. 0 disables scaling + * entirely. + * @param height Target height to scale the frame to. 0 disables scaling + * entirely. + * @param filter Filtering method to use for scaling. Depending on how you + * scale, this can have an impact on the final image quality. */ uint16_t scale_back_buffer_width; /** - * Back buffer scale height, see parameter scale_back_buffer_width for full doc. + * Back buffer scale height, see parameter scale_back_buffer_width for full + * doc. */ uint16_t scale_back_buffer_height; /** - * Back buffer scale filter to apply, see parameter scale_back_buffer_width for full doc. + * Back buffer scale filter to apply, see parameter scale_back_buffer_width + * for full doc. */ enum iidxhook_util_d3d9_back_buffer_scale_filter scale_back_buffer_filter; }; /** - * Initialize this hook module. Must be called before any other function of this module. - * + * Initialize this hook module. Must be called before any other function of this + * module. + * * Games using d3d9: IIDX 14 (Gold) to IIDX 27 (Rootage) - * For d3d8 based games (IIDX 9 to 13): use d3d8to9 wrapper to allow usage of this module. + * For d3d8 based games (IIDX 9 to 13): use d3d8to9 wrapper to allow usage of + * this module. */ void iidxhook_util_d3d9_hook_init(void); /** * Initialize the provided config struct with default values. - * + * * @param config Pointer to an initialized struct to write default values to. */ -void iidxhook_util_d3d9_init_config(struct iidxhook_util_d3d9_config* config); +void iidxhook_util_d3d9_init_config(struct iidxhook_util_d3d9_config *config); /** * Configure this module by applying the provided config. - * + * * @param config Config to apply. */ -void iidxhook_util_d3d9_configure(const struct iidxhook_util_d3d9_config* config); +void iidxhook_util_d3d9_configure( + const struct iidxhook_util_d3d9_config *config); /** - * Main IRP handler call for this module. Must be set up with the hook/d3d9 module to receive calls from d3d9. - * + * Main IRP handler call for this module. Must be set up with the hook/d3d9 + * module to receive calls from d3d9. + * * @param irp Pointer to a valid IRP. * @return S_OK on success, error otherwise (depending on the irp op). */ -HRESULT iidxhook_util_d3d9_irp_handler(struct hook_d3d9_irp* irp); +HRESULT iidxhook_util_d3d9_irp_handler(struct hook_d3d9_irp *irp); #endif diff --git a/src/main/iidxhook-util/eamuse.c b/src/main/iidxhook-util/eamuse.c index b8c9afc..ff1891a 100644 --- a/src/main/iidxhook-util/eamuse.c +++ b/src/main/iidxhook-util/eamuse.c @@ -19,38 +19,32 @@ /* ------------------------------------------------------------------------- */ static unsigned long STDCALL my_inet_addr(const char *cp); -static int STDCALL my_connect(SOCKET s, const struct sockaddr* addr, - int addrlen); -static struct hostent FAR* STDCALL my_gethostbyname(const char *nameB); +static int STDCALL +my_connect(SOCKET s, const struct sockaddr *addr, int addrlen); +static struct hostent FAR *STDCALL my_gethostbyname(const char *nameB); -static unsigned long (STDCALL *real_inet_addr)(const char *cp); -static int (STDCALL *real_connect)(SOCKET s, const struct sockaddr* addr, - int addrlen); -static struct hostent FAR* (STDCALL *real_gethostbyname)(const char *nameB); +static unsigned long(STDCALL *real_inet_addr)(const char *cp); +static int(STDCALL *real_connect)( + SOCKET s, const struct sockaddr *addr, int addrlen); +static struct hostent FAR *(STDCALL *real_gethostbyname)(const char *nameB); /* ------------------------------------------------------------------------- */ static const struct hook_symbol eamuse_hook_syms[] = { - /* WS2_32.DLL's SDK import lib generates ordinal imports, so these ordinals - are a frozen aspect of the Win32 ABI. */ + /* WS2_32.DLL's SDK import lib generates ordinal imports, so these + ordinals are a frozen aspect of the Win32 ABI. */ - { - .name = "inet_addr", - .ordinal = 11, - .patch = my_inet_addr, - .link = (void **) &real_inet_addr - }, - { - .name = "connect", - .ordinal = 4, - .patch = my_connect, - .link = (void **) &real_connect - }, - { - .name = "gethostbyname", - .ordinal = 52, - .patch = my_gethostbyname, - .link = (void **) &real_gethostbyname - }, + {.name = "inet_addr", + .ordinal = 11, + .patch = my_inet_addr, + .link = (void **) &real_inet_addr}, + {.name = "connect", + .ordinal = 4, + .patch = my_connect, + .link = (void **) &real_connect}, + {.name = "gethostbyname", + .ordinal = 52, + .patch = my_gethostbyname, + .link = (void **) &real_gethostbyname}, }; /* ------------------------------------------------------------------------- */ @@ -62,7 +56,7 @@ static struct net_addr eamuse_server_addr_resolved; static unsigned long STDCALL my_inet_addr(const char *cp) { - char* tmp; + char *tmp; /* for a stock machine connected to the eamuse router, the game wants to connect to the standard domain @@ -80,19 +74,23 @@ static unsigned long STDCALL my_inet_addr(const char *cp) return eamuse_server_addr_resolved.ipv4.addr; } -static int STDCALL my_connect(SOCKET s, const struct sockaddr* addr, int addrlen) +static int STDCALL +my_connect(SOCKET s, const struct sockaddr *addr, int addrlen) { - char* tmp; + char *tmp; if (addr->sa_family == AF_INET) { /* check if we got our server's address */ - struct sockaddr_in* addr_in = (struct sockaddr_in*) addr; + struct sockaddr_in *addr_in = (struct sockaddr_in *) addr; - if (addr_in->sin_addr.S_un.S_addr == - eamuse_server_addr_resolved.ipv4.addr) { + if (addr_in->sin_addr.S_un.S_addr == + eamuse_server_addr_resolved.ipv4.addr) { tmp = net_addr_to_str(&eamuse_server_addr_resolved); - log_misc("Patching port '%d' of %s to %d", ntohs(addr_in->sin_port), - tmp, eamuse_server_addr_resolved.ipv4.port); + log_misc( + "Patching port '%d' of %s to %d", + ntohs(addr_in->sin_port), + tmp, + eamuse_server_addr_resolved.ipv4.port); free(tmp); addr_in->sin_port = htons(eamuse_server_addr_resolved.ipv4.port); @@ -102,9 +100,9 @@ static int STDCALL my_connect(SOCKET s, const struct sockaddr* addr, int addrlen return real_connect(s, addr, addrlen); } -static struct hostent FAR* STDCALL my_gethostbyname(const char* name) +static struct hostent FAR *STDCALL my_gethostbyname(const char *name) { - char* tmp; + char *tmp; /* for doc, checkout the other detour of inetaddr above this call is used starting GOLD (not used on pre GOLD) */ @@ -121,13 +119,13 @@ static struct hostent FAR* STDCALL my_gethostbyname(const char* name) just populate what's touched by the game */ static struct hostent ret; static uint32_t addr; - static char* arr[2]; + static char *arr[2]; static bool first = true; if (first) { ret.h_length = 4; - ret.h_addr_list = (char**) &arr; - ret.h_addr_list[0] = (char*) &addr; + ret.h_addr_list = (char **) &arr; + ret.h_addr_list[0] = (char *) &addr; ret.h_addr_list[1] = NULL; ret.h_aliases = NULL; ret.h_name = NULL; @@ -143,29 +141,26 @@ static struct hostent FAR* STDCALL my_gethostbyname(const char* name) void eamuse_hook_init(void) { hook_table_apply( - NULL, - "ws2_32.dll", - eamuse_hook_syms, - lengthof(eamuse_hook_syms)); + NULL, "ws2_32.dll", eamuse_hook_syms, lengthof(eamuse_hook_syms)); log_info("Inserted eamuse hooks"); } -void eamuse_set_addr(const struct net_addr* addr) +void eamuse_set_addr(const struct net_addr *addr) { - char* tmp_str; - char* tmp_str2; + char *tmp_str; + char *tmp_str2; log_assert(addr); memcpy(&eamuse_server_addr, addr, sizeof(struct net_addr)); tmp_str = net_addr_to_str(&eamuse_server_addr); - + eamuse_server_addr_resolved.type = NET_ADDR_TYPE_IPV4; - if (!net_resolve_hostname_net_addr(&eamuse_server_addr, - &eamuse_server_addr_resolved.ipv4)) { + if (!net_resolve_hostname_net_addr( + &eamuse_server_addr, &eamuse_server_addr_resolved.ipv4)) { log_fatal("Failed to resolve eamuse server address: %s", tmp_str); free(tmp_str); return; @@ -184,7 +179,8 @@ void eamuse_check_connection() if (!net_check_remote_connection(&eamuse_server_addr_resolved, 5000)) { log_info("Target eamuse server reachable."); } else { - log_warning("Target eamuse server is not reachable. Game might throw " + log_warning( + "Target eamuse server is not reachable. Game might throw " "network errors/warnings if eamuse is enabled."); } } \ No newline at end of file diff --git a/src/main/iidxhook-util/eamuse.h b/src/main/iidxhook-util/eamuse.h index 7cea97a..5929ed8 100644 --- a/src/main/iidxhook-util/eamuse.h +++ b/src/main/iidxhook-util/eamuse.h @@ -14,7 +14,7 @@ void eamuse_hook_init(void); * * @param addr net_addr struct with address to the server. */ -void eamuse_set_addr(const struct net_addr* addr); +void eamuse_set_addr(const struct net_addr *addr); /** * Check if the target eamuse server is reachable. Reports success/error using diff --git a/src/main/iidxhook-util/effector.c b/src/main/iidxhook-util/effector.c index 5dd9b8c..4f30e27 100644 --- a/src/main/iidxhook-util/effector.c +++ b/src/main/iidxhook-util/effector.c @@ -17,24 +17,24 @@ static BOOL my_SetSpeakerMode(int direct_sound_struct, int a2); static const struct hook_symbol effector_hook_syms[] = { { - .name = "EnableEqualizer", - .patch = my_EnableEqualizer, + .name = "EnableEqualizer", + .patch = my_EnableEqualizer, }, { - .name = "GetEqualizerStatus", - .patch = my_GetEqualizerStatus, + .name = "GetEqualizerStatus", + .patch = my_GetEqualizerStatus, }, { - .name = "SetEqualizerGain", - .patch = my_SetEqualizerGain, + .name = "SetEqualizerGain", + .patch = my_SetEqualizerGain, }, { - .name = "SetGlobalEnvironment", - .patch = my_SetGlobalEnvironment, + .name = "SetGlobalEnvironment", + .patch = my_SetGlobalEnvironment, }, { - .name = "SetSpeakerMode", - .patch = my_SetSpeakerMode, + .name = "SetSpeakerMode", + .patch = my_SetSpeakerMode, }, }; @@ -76,10 +76,7 @@ static BOOL my_SetSpeakerMode(int direct_sound_struct, int a2) void effector_hook_init(void) { hook_table_apply( - NULL, - "rteffect.dll", - effector_hook_syms, - lengthof(effector_hook_syms)); + NULL, "rteffect.dll", effector_hook_syms, lengthof(effector_hook_syms)); log_info("Inserted rteffect hooks"); } diff --git a/src/main/iidxhook-util/log-server.c b/src/main/iidxhook-util/log-server.c index 5e2866b..1a7f687 100644 --- a/src/main/iidxhook-util/log-server.c +++ b/src/main/iidxhook-util/log-server.c @@ -17,8 +17,8 @@ #include "util/thread.h" static int log_thread_proc(void *ctx); -static void log_post(char level, const char *module, const char *fmt, - va_list ap); +static void +log_post(char level, const char *module, const char *fmt, va_list ap); static void log_post_misc(const char *module, const char *fmt, ...); static void log_post_info(const char *module, const char *fmt, ...); static void log_post_warning(const char *module, const char *fmt, ...); @@ -39,17 +39,20 @@ void log_server_init(void) log_rv_consumer = CreateSemaphore(NULL, 0, 1, NULL); ready = CreateEvent(NULL, TRUE, FALSE, NULL); - log_to_external(log_post_misc, log_post_info, log_post_warning, - log_post_fatal); + log_to_external( + log_post_misc, log_post_info, log_post_warning, log_post_fatal); log_thread_id = avs_thread_create(log_thread_proc, ready, 16384, 0); if (WaitForSingleObject(ready, INFINITE)) { // can't do any logging here, yet. - fprintf(stderr, "ERROR log_server_init: WaitForSingleObject failed: %08x", (unsigned int) GetLastError()); + fprintf( + stderr, + "ERROR log_server_init: WaitForSingleObject failed: %08x", + (unsigned int) GetLastError()); return; } - + CloseHandle(ready); log_misc("Started log server thread"); @@ -66,10 +69,10 @@ static int log_thread_proc(void *ctx) log_body_misc(LOG_MODULE, "Log server thread is running"); while (run) { - if (WaitForSingleObject(log_rv_consumer, INFINITE)) { - log_fatal("WaitForSingleObject failed: %08x", - (unsigned int) GetLastError()); + log_fatal( + "WaitForSingleObject failed: %08x", + (unsigned int) GetLastError()); } switch (log_rv_level) { @@ -100,8 +103,8 @@ static int log_thread_proc(void *ctx) } if (!ReleaseSemaphore(log_rv_producer, 1, NULL)) { - log_fatal("ReleaseSemaphore failed: %08x", - (unsigned int) GetLastError()); + log_fatal( + "ReleaseSemaphore failed: %08x", (unsigned int) GetLastError()); } } @@ -110,8 +113,8 @@ static int log_thread_proc(void *ctx) return 0; } -static void log_post(char level, const char *module, const char *fmt, - va_list ap) +static void +log_post(char level, const char *module, const char *fmt, va_list ap) { if (WaitForSingleObject(log_rv_producer, INFINITE)) { return; @@ -124,14 +127,14 @@ static void log_post(char level, const char *module, const char *fmt, ReleaseSemaphore(log_rv_consumer, 1, NULL); } -#define LOG_POST_IMPL(name, level) \ +#define LOG_POST_IMPL(name, level) \ static void name(const char *module, const char *fmt, ...) \ - { \ - va_list ap; \ - \ - va_start(ap, fmt); \ - log_post(level, module, fmt, ap); \ - va_end(ap); \ + { \ + va_list ap; \ + \ + va_start(ap, fmt); \ + log_post(level, module, fmt, ap); \ + va_end(ap); \ } LOG_POST_IMPL(log_post_misc, 'M') @@ -158,4 +161,3 @@ void log_server_fini(void) log_rv_producer = NULL; log_rv_consumer = NULL; } - diff --git a/src/main/iidxhook-util/log-server.h b/src/main/iidxhook-util/log-server.h index 72ac49c..5984baa 100644 --- a/src/main/iidxhook-util/log-server.h +++ b/src/main/iidxhook-util/log-server.h @@ -2,12 +2,14 @@ #define IIDXHOOK_LOG_SERVER_H /** - * Initialize the log server which creates a dedicated thread and a log message queue. - * - * Log messages are posted to the queue by the application and the background thread writes them to the target output. - * Required for newer iidx and pop'n games using the avs log api (e.g. iidxhook4 to 7) due to a quirk of the ezusb - * driver. For a full breakdown about the logging on avs (and non avs) based konami games, - * see doc/logging-breadkdown-avs.md. + * Initialize the log server which creates a dedicated thread and a log message + * queue. + * + * Log messages are posted to the queue by the application and the background + * thread writes them to the target output. Required for newer iidx and pop'n + * games using the avs log api (e.g. iidxhook4 to 7) due to a quirk of the ezusb + * driver. For a full breakdown about the logging on avs (and non avs) based + * konami games, see doc/logging-breadkdown-avs.md. */ void log_server_init(void); diff --git a/src/main/iidxhook-util/settings.c b/src/main/iidxhook-util/settings.c index d893398..c92dc49 100644 --- a/src/main/iidxhook-util/settings.c +++ b/src/main/iidxhook-util/settings.c @@ -17,32 +17,31 @@ /* ------------------------------------------------------------------------- */ -static BOOL WINAPI my_CreateDirectoryA(LPCSTR lpPathName, - LPSECURITY_ATTRIBUTES lpSecurityAttributes); +static BOOL WINAPI my_CreateDirectoryA( + LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes); -static BOOL (WINAPI *real_CreateDirectoryA)(LPCSTR lpPathName, - LPSECURITY_ATTRIBUTES lpSecurityAttributes); +static BOOL(WINAPI *real_CreateDirectoryA)( + LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes); /* ------------------------------------------------------------------------- */ static const struct hook_symbol settings_hook_syms[] = { - { - .name = "CreateDirectoryA", - .patch = my_CreateDirectoryA, - .link = (void **) &real_CreateDirectoryA - }, + {.name = "CreateDirectoryA", + .patch = my_CreateDirectoryA, + .link = (void **) &real_CreateDirectoryA}, }; static bool settings_folders_checked; /* ------------------------------------------------------------------------- */ -BOOL WINAPI my_CreateDirectoryA(LPCSTR lpPathName, - LPSECURITY_ATTRIBUTES lpSecurityAttributes) +BOOL WINAPI my_CreateDirectoryA( + LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes) { - if ( lpPathName != NULL && - (lpPathName[0] == 'd' || lpPathName[0] == 'e' || lpPathName[0] == 'f') && - lpPathName[1] == ':') { + if (lpPathName != NULL && + (lpPathName[0] == 'd' || lpPathName[0] == 'e' || + lpPathName[0] == 'f') && + lpPathName[1] == ':') { char new_path[MAX_PATH]; strcpy(new_path, lpPathName); @@ -55,28 +54,26 @@ BOOL WINAPI my_CreateDirectoryA(LPCSTR lpPathName, return real_CreateDirectoryA(lpPathName, lpSecurityAttributes); } - /* ------------------------------------------------------------------------- */ void settings_hook_init(void) { hook_table_apply( - NULL, - "kernel32.dll", - settings_hook_syms, - lengthof(settings_hook_syms)); + NULL, "kernel32.dll", settings_hook_syms, lengthof(settings_hook_syms)); log_info("Inserted settings hooks"); } -HRESULT settings_hook_dispatch_irp(struct irp *irp) +HRESULT +settings_hook_dispatch_irp(struct irp *irp) { - if (irp->op == IRP_OP_OPEN && - (irp->open_filename[0] == L'd' || irp->open_filename[0] == L'e' || - irp->open_filename[0] == L'f') && irp->open_filename[1] == L':') { - char* log_str; + if (irp->op == IRP_OP_OPEN && + (irp->open_filename[0] == L'd' || irp->open_filename[0] == L'e' || + irp->open_filename[0] == L'f') && + irp->open_filename[1] == L':') { + char *log_str; - ((wchar_t*) irp->open_filename)[1] = L'\\'; + ((wchar_t *) irp->open_filename)[1] = L'\\'; wstr_narrow(irp->open_filename, &log_str); log_misc("Remapped settings path %s", log_str); diff --git a/src/main/iidxhook1/config-iidxhook1.c b/src/main/iidxhook1/config-iidxhook1.c index 8d68a50..5a02c95 100644 --- a/src/main/iidxhook1/config-iidxhook1.c +++ b/src/main/iidxhook1/config-iidxhook1.c @@ -8,25 +8,29 @@ #define IIDXHOOK_CONFIG_MISC_DEFAULT_HAPPY_SKY_MS_BG_FIX_VALUE false -void iidxhook_config_iidxhook1_init(struct cconfig* config) +void iidxhook_config_iidxhook1_init(struct cconfig *config) { - cconfig_util_set_bool(config, + cconfig_util_set_bool( + config, IIDXHOOK_CONFIG_MISC_HAPPY_SKY_MS_BG_FIX_KEY, IIDXHOOK_CONFIG_MISC_DEFAULT_HAPPY_SKY_MS_BG_FIX_VALUE, - "Fix broken 3D background on Happy Sky's music select (if appearing " + "Fix broken 3D background on Happy Sky's music select (if " + "appearing " "completely white)"); } void iidxhook_config_iidxhook1_get( - struct iidxhook_config_iidxhook1* config_iidxhook1, - struct cconfig* config) + struct iidxhook_config_iidxhook1 *config_iidxhook1, struct cconfig *config) { - if (!cconfig_util_get_bool(config, - IIDXHOOK_CONFIG_MISC_HAPPY_SKY_MS_BG_FIX_KEY, - &config_iidxhook1->happy_sky_ms_bg_fix, + if (!cconfig_util_get_bool( + config, + IIDXHOOK_CONFIG_MISC_HAPPY_SKY_MS_BG_FIX_KEY, + &config_iidxhook1->happy_sky_ms_bg_fix, IIDXHOOK_CONFIG_MISC_DEFAULT_HAPPY_SKY_MS_BG_FIX_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%d'", IIDXHOOK_CONFIG_MISC_HAPPY_SKY_MS_BG_FIX_KEY, + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%d'", + IIDXHOOK_CONFIG_MISC_HAPPY_SKY_MS_BG_FIX_KEY, IIDXHOOK_CONFIG_MISC_DEFAULT_HAPPY_SKY_MS_BG_FIX_VALUE); } } \ No newline at end of file diff --git a/src/main/iidxhook1/config-iidxhook1.h b/src/main/iidxhook1/config-iidxhook1.h index e90ce0f..bec1e48 100644 --- a/src/main/iidxhook1/config-iidxhook1.h +++ b/src/main/iidxhook1/config-iidxhook1.h @@ -7,10 +7,9 @@ struct iidxhook_config_iidxhook1 { bool happy_sky_ms_bg_fix; }; -void iidxhook_config_iidxhook1_init(struct cconfig* config); +void iidxhook_config_iidxhook1_init(struct cconfig *config); void iidxhook_config_iidxhook1_get( - struct iidxhook_config_iidxhook1* config_iidxhook1, - struct cconfig* config); + struct iidxhook_config_iidxhook1 *config_iidxhook1, struct cconfig *config); #endif \ No newline at end of file diff --git a/src/main/iidxhook1/dllmain.c b/src/main/iidxhook1/dllmain.c index 97b2893..c94f410 100644 --- a/src/main/iidxhook1/dllmain.c +++ b/src/main/iidxhook1/dllmain.c @@ -1,8 +1,8 @@ #include #include -#include #include +#include #include "bemanitools/eamio.h" #include "bemanitools/iidxio.h" @@ -43,7 +43,7 @@ #include "util/log.h" #include "util/thread.h" -#define IIDXHOOK1_INFO_HEADER \ +#define IIDXHOOK1_INFO_HEADER \ "iidxhook for 9th Style, 10th Style, RED and HAPPY SKY" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) #define IIDXHOOK1_CMD_USAGE \ @@ -60,24 +60,27 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { }; static HANDLE STDCALL my_OpenProcess(DWORD, BOOL, DWORD); -static HANDLE (STDCALL *real_OpenProcess)(DWORD, BOOL, DWORD); +static HANDLE(STDCALL *real_OpenProcess)(DWORD, BOOL, DWORD); static bool iidxhook_init_check; static const struct hook_symbol init_hook_syms[] = { { - .name = "OpenProcess", - .patch = my_OpenProcess, - .link = (void **) &real_OpenProcess, + .name = "OpenProcess", + .patch = my_OpenProcess, + .link = (void **) &real_OpenProcess, }, }; -static void iidxhook1_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_gfx, - const struct iidxhook_config_iidxhook1* config_iidxhook1) +static void iidxhook1_setup_d3d9_hooks( + const struct iidxhook_config_gfx *config_gfx, + const struct iidxhook_config_iidxhook1 *config_iidxhook1) { struct iidxhook_util_d3d9_config d3d9_config; - log_warning("d3d8 hook module deprecated, using d3d9 hook modules requiring d3d8to9 to work!"); + log_warning( + "d3d8 hook module deprecated, using d3d9 hook modules requiring " + "d3d8to9 to work!"); iidxhook_util_d3d9_init_config(&d3d9_config); @@ -86,7 +89,8 @@ static void iidxhook1_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_ d3d9_config.override_window_width = config_gfx->window_width; d3d9_config.override_window_height = config_gfx->window_height; d3d9_config.framerate_limit = config_gfx->frame_rate_limit; - d3d9_config.iidx12_fix_song_select_bg = config_iidxhook1->happy_sky_ms_bg_fix; + d3d9_config.iidx12_fix_song_select_bg = + config_iidxhook1->happy_sky_ms_bg_fix; d3d9_config.iidx11_to_17_fix_uvs_bg_videos = config_gfx->bgvideo_uv_fix; d3d9_config.scale_back_buffer_width = config_gfx->scale_back_buffer_width; d3d9_config.scale_back_buffer_height = config_gfx->scale_back_buffer_height; @@ -95,12 +99,17 @@ static void iidxhook1_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_ if (config_gfx->monitor_check == 0) { log_info("Auto monitor check enabled"); - d3d9_config.iidx09_to_19_monitor_check_cb = iidxhook_util_chart_patch_set_refresh_rate; - iidxhook_util_chart_patch_init(IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_9_TO_13); + d3d9_config.iidx09_to_19_monitor_check_cb = + iidxhook_util_chart_patch_set_refresh_rate; + iidxhook_util_chart_patch_init( + IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_9_TO_13); } else if (config_gfx->monitor_check > 0) { - log_info("Manual monitor check, resulting refresh rate: %f", config_gfx->monitor_check); + log_info( + "Manual monitor check, resulting refresh rate: %f", + config_gfx->monitor_check); - iidxhook_util_chart_patch_init(IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_9_TO_13); + iidxhook_util_chart_patch_init( + IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_9_TO_13); iidxhook_util_chart_patch_set_refresh_rate(config_gfx->monitor_check); } @@ -113,10 +122,10 @@ static void iidxhook1_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_ * This seems to be a good entry point to intercept * before the game calls anything important */ -static HANDLE STDCALL my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, - DWORD dwProcessId) +static HANDLE STDCALL +my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) { - struct cconfig* config; + struct cconfig *config; struct iidxhook_util_config_eamuse config_eamuse; struct iidxhook_config_gfx config_gfx; @@ -142,7 +151,10 @@ static HANDLE STDCALL my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, iidxhook_config_misc_init(config); iidxhook_config_sec_init(config); - if (!cconfig_hook_config_init(config, IIDXHOOK1_INFO_HEADER "\n" IIDXHOOK1_CMD_USAGE, CCONFIG_CMD_USAGE_OUT_DBG)) { + if (!cconfig_hook_config_init( + config, + IIDXHOOK1_INFO_HEADER "\n" IIDXHOOK1_CMD_USAGE, + CCONFIG_CMD_USAGE_OUT_DBG)) { cconfig_finit(config); exit(EXIT_FAILURE); } @@ -169,8 +181,8 @@ static HANDLE STDCALL my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, /* Magnetic card reader (9th to HS) */ - ezusb_iidx_emu_node_serial_set_card_attributes(0, true, - config_eamuse.card_type); + ezusb_iidx_emu_node_serial_set_card_attributes( + 0, true, config_eamuse.card_type); /* eAmusement server IP */ @@ -196,8 +208,8 @@ static HANDLE STDCALL my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, /* Start up IIDXIO.DLL */ log_info("Starting IIDX IO backend"); - iidx_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning, - log_impl_fatal); + iidx_io_set_loggers( + log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); if (!iidx_io_init(thread_create, thread_join, thread_destroy)) { log_fatal("Initializing IIDX IO backend failed"); @@ -206,8 +218,8 @@ static HANDLE STDCALL my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, /* Start up EAMIO.DLL */ log_misc("Initializing card reader backend"); - eam_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning, - log_impl_fatal); + eam_io_set_loggers( + log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); if (!eam_io_init(thread_create, thread_join, thread_destroy)) { log_fatal("Initializing card reader backend failed"); @@ -235,7 +247,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { #ifdef DEBUG_HOOKING - FILE* file = fopen("iidxhook.dllmain.log", "w+"); + FILE *file = fopen("iidxhook.dllmain.log", "w+"); log_to_writer(log_writer_file, file); #else log_to_writer(log_writer_null, NULL); @@ -244,10 +256,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) /* Bootstrap hook for further init tasks (see above) */ hook_table_apply( - NULL, - "kernel32.dll", - init_hook_syms, - lengthof(init_hook_syms)); + NULL, "kernel32.dll", init_hook_syms, lengthof(init_hook_syms)); /* Actual hooks for game specific stuff */ @@ -267,4 +276,3 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) return TRUE; } - diff --git a/src/main/iidxhook1/log-ezusb.c b/src/main/iidxhook1/log-ezusb.c index 49dc3ad..60f71d8 100644 --- a/src/main/iidxhook1/log-ezusb.c +++ b/src/main/iidxhook1/log-ezusb.c @@ -18,16 +18,14 @@ static int STDCALL my_wvsprintfA(LPSTR lpOut, LPCSTR lpFmt, va_list args); -static int (STDCALL *real_wvsprintfA)(LPSTR lpOut, LPCSTR lpFmt, va_list args); +static int(STDCALL *real_wvsprintfA)(LPSTR lpOut, LPCSTR lpFmt, va_list args); /* ------------------------------------------------------------------------- */ static const struct hook_symbol ezusb_log_hook_syms[] = { - { - .name = "wvsprintfA", - .patch = my_wvsprintfA, - .link = (void **) &real_wvsprintfA - }, + {.name = "wvsprintfA", + .patch = my_wvsprintfA, + .link = (void **) &real_wvsprintfA}, }; /* ------------------------------------------------------------------------- */ @@ -46,10 +44,7 @@ static int STDCALL my_wvsprintfA(LPSTR lpOut, LPCSTR lpFmt, va_list args) void ezusb_log_hook_init(void) { hook_table_apply( - NULL, - "user32.dll", - ezusb_log_hook_syms, - lengthof(ezusb_log_hook_syms)); + NULL, "user32.dll", ezusb_log_hook_syms, lengthof(ezusb_log_hook_syms)); log_info("Inserted ezusb log hooks"); } diff --git a/src/main/iidxhook2/config-iidxhook2.c b/src/main/iidxhook2/config-iidxhook2.c index 7ab33a7..6e3ac6b 100644 --- a/src/main/iidxhook2/config-iidxhook2.c +++ b/src/main/iidxhook2/config-iidxhook2.c @@ -8,25 +8,29 @@ #define IIDXHOOK_CONFIG_MISC_DEFAULT_DISTORTED_MS_BG_FIX_VALUE false -void iidxhook_config_iidxhook2_init(struct cconfig* config) +void iidxhook_config_iidxhook2_init(struct cconfig *config) { - cconfig_util_set_bool(config, + cconfig_util_set_bool( + config, IIDXHOOK_CONFIG_MISC_DISTORTED_MS_BG_FIX_KEY, IIDXHOOK_CONFIG_MISC_DEFAULT_DISTORTED_MS_BG_FIX_VALUE, - "Fix broken 3D background on DistorteD's music select (if appearing " + "Fix broken 3D background on DistorteD's music select (if " + "appearing " "completely black)"); } void iidxhook_config_iidxhook2_get( - struct iidxhook_config_iidxhook2* config_iidxhook2, - struct cconfig* config) + struct iidxhook_config_iidxhook2 *config_iidxhook2, struct cconfig *config) { - if (!cconfig_util_get_bool(config, - IIDXHOOK_CONFIG_MISC_DISTORTED_MS_BG_FIX_KEY, - &config_iidxhook2->distorted_ms_bg_fix, + if (!cconfig_util_get_bool( + config, + IIDXHOOK_CONFIG_MISC_DISTORTED_MS_BG_FIX_KEY, + &config_iidxhook2->distorted_ms_bg_fix, IIDXHOOK_CONFIG_MISC_DEFAULT_DISTORTED_MS_BG_FIX_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%d'", IIDXHOOK_CONFIG_MISC_DISTORTED_MS_BG_FIX_KEY, + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%d'", + IIDXHOOK_CONFIG_MISC_DISTORTED_MS_BG_FIX_KEY, IIDXHOOK_CONFIG_MISC_DEFAULT_DISTORTED_MS_BG_FIX_VALUE); } } \ No newline at end of file diff --git a/src/main/iidxhook2/config-iidxhook2.h b/src/main/iidxhook2/config-iidxhook2.h index be828ed..50c85e1 100644 --- a/src/main/iidxhook2/config-iidxhook2.h +++ b/src/main/iidxhook2/config-iidxhook2.h @@ -7,10 +7,9 @@ struct iidxhook_config_iidxhook2 { bool distorted_ms_bg_fix; }; -void iidxhook_config_iidxhook2_init(struct cconfig* config); +void iidxhook_config_iidxhook2_init(struct cconfig *config); void iidxhook_config_iidxhook2_get( - struct iidxhook_config_iidxhook2* config_iidxhook2, - struct cconfig* config); + struct iidxhook_config_iidxhook2 *config_iidxhook2, struct cconfig *config); #endif \ No newline at end of file diff --git a/src/main/iidxhook2/dllmain.c b/src/main/iidxhook2/dllmain.c index e3bddbd..2fb2ff3 100644 --- a/src/main/iidxhook2/dllmain.c +++ b/src/main/iidxhook2/dllmain.c @@ -1,8 +1,8 @@ #include #include -#include #include +#include #include "bemanitools/eamio.h" #include "bemanitools/iidxio.h" @@ -21,8 +21,8 @@ #include "hook/iohook.h" #include "hook/table.h" -#include "hooklib/adapter.h" #include "hooklib/acp.h" +#include "hooklib/adapter.h" #include "hooklib/rs232.h" #include "hooklib/setupapi.h" @@ -44,7 +44,7 @@ #include "util/thread.h" #define IIDXHOOK2_INFO_HEADER \ - "iidxhook for DistorteD" \ + "iidxhook for DistorteD" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) #define IIDXHOOK2_CMD_USAGE \ "Usage: inject.exe iidxhook2.dll [options...]" @@ -61,24 +61,25 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { }; static HANDLE STDCALL my_OpenProcess(DWORD, BOOL, DWORD); -static HANDLE (STDCALL *real_OpenProcess)(DWORD, BOOL, DWORD); +static HANDLE(STDCALL *real_OpenProcess)(DWORD, BOOL, DWORD); static bool iidxhook_init_check; static const struct hook_symbol init_hook_syms[] = { - { - .name = "OpenProcess", - .patch = my_OpenProcess, - .link = (void **) &real_OpenProcess - }, + {.name = "OpenProcess", + .patch = my_OpenProcess, + .link = (void **) &real_OpenProcess}, }; -static void iidxhook2_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_gfx, - const struct iidxhook_config_iidxhook2* config_iidxhook2) +static void iidxhook2_setup_d3d9_hooks( + const struct iidxhook_config_gfx *config_gfx, + const struct iidxhook_config_iidxhook2 *config_iidxhook2) { struct iidxhook_util_d3d9_config d3d9_config; - log_warning("d3d8 hook module deprecated, using d3d9 hook modules requiring d3d8to9 to work!"); + log_warning( + "d3d8 hook module deprecated, using d3d9 hook modules requiring " + "d3d8to9 to work!"); iidxhook_util_d3d9_init_config(&d3d9_config); @@ -87,7 +88,8 @@ static void iidxhook2_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_ d3d9_config.override_window_width = config_gfx->window_width; d3d9_config.override_window_height = config_gfx->window_height; d3d9_config.framerate_limit = config_gfx->frame_rate_limit; - d3d9_config.iidx13_fix_song_select_bg = config_iidxhook2->distorted_ms_bg_fix; + d3d9_config.iidx13_fix_song_select_bg = + config_iidxhook2->distorted_ms_bg_fix; d3d9_config.iidx11_to_17_fix_uvs_bg_videos = config_gfx->bgvideo_uv_fix; d3d9_config.scale_back_buffer_width = config_gfx->scale_back_buffer_width; d3d9_config.scale_back_buffer_height = config_gfx->scale_back_buffer_height; @@ -96,12 +98,17 @@ static void iidxhook2_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_ if (config_gfx->monitor_check == 0) { log_info("Auto monitor check enabled"); - d3d9_config.iidx09_to_19_monitor_check_cb = iidxhook_util_chart_patch_set_refresh_rate; - iidxhook_util_chart_patch_init(IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_9_TO_13); + d3d9_config.iidx09_to_19_monitor_check_cb = + iidxhook_util_chart_patch_set_refresh_rate; + iidxhook_util_chart_patch_init( + IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_9_TO_13); } else if (config_gfx->monitor_check > 0) { - log_info("Manual monitor check, resulting refresh rate: %f", config_gfx->monitor_check); + log_info( + "Manual monitor check, resulting refresh rate: %f", + config_gfx->monitor_check); - iidxhook_util_chart_patch_init(IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_9_TO_13); + iidxhook_util_chart_patch_init( + IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_9_TO_13); iidxhook_util_chart_patch_set_refresh_rate(config_gfx->monitor_check); } @@ -114,10 +121,10 @@ static void iidxhook2_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_ * This seems to be a good entry point to intercept * before the game calls anything important */ -HANDLE STDCALL my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, - DWORD dwProcessId) +HANDLE STDCALL +my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) { - struct cconfig* config; + struct cconfig *config; struct iidxhook_util_config_eamuse config_eamuse; struct iidxhook_config_gfx config_gfx; @@ -143,7 +150,10 @@ HANDLE STDCALL my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, iidxhook_config_misc_init(config); iidxhook_config_sec_init(config); - if (!cconfig_hook_config_init(config, IIDXHOOK2_INFO_HEADER "\n" IIDXHOOK2_CMD_USAGE, CCONFIG_CMD_USAGE_OUT_DBG)) { + if (!cconfig_hook_config_init( + config, + IIDXHOOK2_INFO_HEADER "\n" IIDXHOOK2_CMD_USAGE, + CCONFIG_CMD_USAGE_OUT_DBG)) { cconfig_finit(config); exit(EXIT_FAILURE); } @@ -192,8 +202,8 @@ HANDLE STDCALL my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, /* Start up IIDXIO.DLL */ log_info("Starting IIDX IO backend"); - iidx_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning, - log_impl_fatal); + iidx_io_set_loggers( + log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); if (!iidx_io_init(thread_create, thread_join, thread_destroy)) { log_fatal("Initializing IIDX IO backend failed"); @@ -202,8 +212,8 @@ HANDLE STDCALL my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, /* Start up EAMIO.DLL */ log_misc("Initializing card reader backend"); - eam_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning, - log_impl_fatal); + eam_io_set_loggers( + log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); if (!eam_io_init(thread_create, thread_join, thread_destroy)) { log_fatal("Initializing card reader backend failed"); @@ -236,7 +246,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { #ifdef DEBUG_HOOKING - FILE* file = fopen("iidxhook.dllmain.log", "w+"); + FILE *file = fopen("iidxhook.dllmain.log", "w+"); log_to_writer(log_writer_file, file); #else log_to_writer(log_writer_null, NULL); @@ -245,10 +255,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) /* Bootstrap hook for further init tasks (see above) */ hook_table_apply( - NULL, - "kernel32.dll", - init_hook_syms, - lengthof(init_hook_syms)); + NULL, "kernel32.dll", init_hook_syms, lengthof(init_hook_syms)); /* Actual hooks for game specific stuff */ @@ -268,4 +275,3 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) return TRUE; } - diff --git a/src/main/iidxhook3/dllmain.c b/src/main/iidxhook3/dllmain.c index 2048131..ea0cb12 100644 --- a/src/main/iidxhook3/dllmain.c +++ b/src/main/iidxhook3/dllmain.c @@ -1,8 +1,8 @@ #include #include -#include #include +#include #include "bemanitools/eamio.h" #include "bemanitools/iidxio.h" @@ -22,8 +22,8 @@ #include "hook/iohook.h" #include "hook/table.h" -#include "hooklib/adapter.h" #include "hooklib/acp.h" +#include "hooklib/adapter.h" #include "hooklib/rs232.h" #include "hooklib/setupapi.h" @@ -42,7 +42,7 @@ #include "util/str.h" #include "util/thread.h" -#define IIDXHOOK3_INFO_HEADER \ +#define IIDXHOOK3_INFO_HEADER \ "iidxhook for Gold, DJTroopers, Empress and Sirius" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) #define IIDXHOOK3_CMD_USAGE \ @@ -60,18 +60,17 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { }; static HANDLE STDCALL my_OpenProcess(DWORD, BOOL, DWORD); -static HANDLE (STDCALL *real_OpenProcess)(DWORD, BOOL, DWORD); +static HANDLE(STDCALL *real_OpenProcess)(DWORD, BOOL, DWORD); static bool iidxhook_init_check; static const struct hook_symbol init_hook_syms[] = { - { - .name = "OpenProcess", - .patch = my_OpenProcess, - .link = (void **) &real_OpenProcess - }, + {.name = "OpenProcess", + .patch = my_OpenProcess, + .link = (void **) &real_OpenProcess}, }; -static void iidxhook3_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_gfx) +static void +iidxhook3_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) { struct iidxhook_util_d3d9_config d3d9_config; @@ -96,12 +95,17 @@ static void iidxhook3_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_ if (config_gfx->monitor_check == 0) { log_info("Auto monitor check enabled"); - d3d9_config.iidx09_to_19_monitor_check_cb = iidxhook_util_chart_patch_set_refresh_rate; - iidxhook_util_chart_patch_init(IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_18_VGA); + d3d9_config.iidx09_to_19_monitor_check_cb = + iidxhook_util_chart_patch_set_refresh_rate; + iidxhook_util_chart_patch_init( + IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_18_VGA); } else if (config_gfx->monitor_check > 0) { - log_info("Manual monitor check, resulting refresh rate: %f", config_gfx->monitor_check); + log_info( + "Manual monitor check, resulting refresh rate: %f", + config_gfx->monitor_check); - iidxhook_util_chart_patch_init(IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_18_VGA); + iidxhook_util_chart_patch_init( + IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_18_VGA); iidxhook_util_chart_patch_set_refresh_rate(config_gfx->monitor_check); } @@ -114,10 +118,10 @@ static void iidxhook3_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_ * This seems to be a good entry point to intercept * before the game calls anything important */ -HANDLE STDCALL my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, - DWORD dwProcessId) +HANDLE STDCALL +my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) { - struct cconfig* config; + struct cconfig *config; struct iidxhook_util_config_eamuse config_eamuse; struct iidxhook_config_gfx config_gfx; @@ -141,7 +145,10 @@ HANDLE STDCALL my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, iidxhook_config_misc_init(config); iidxhook_config_sec_init(config); - if (!cconfig_hook_config_init(config, IIDXHOOK3_INFO_HEADER "\n" IIDXHOOK3_CMD_USAGE, CCONFIG_CMD_USAGE_OUT_DBG)) { + if (!cconfig_hook_config_init( + config, + IIDXHOOK3_INFO_HEADER "\n" IIDXHOOK3_CMD_USAGE, + CCONFIG_CMD_USAGE_OUT_DBG)) { cconfig_finit(config); exit(EXIT_FAILURE); } @@ -186,8 +193,8 @@ HANDLE STDCALL my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, /* Start up IIDXIO.DLL */ log_info("Starting IIDX IO backend"); - iidx_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning, - log_impl_fatal); + iidx_io_set_loggers( + log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); if (!iidx_io_init(thread_create, thread_join, thread_destroy)) { log_fatal("Initializing IIDX IO backend failed"); @@ -196,8 +203,8 @@ HANDLE STDCALL my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, /* Start up EAMIO.DLL */ log_misc("Initializing card reader backend"); - eam_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning, - log_impl_fatal); + eam_io_set_loggers( + log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); if (!eam_io_init(thread_create, thread_join, thread_destroy)) { log_fatal("Initializing card reader backend failed"); @@ -230,7 +237,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { #ifdef DEBUG_HOOKING - FILE* file = fopen("iidxhook.dllmain.log", "w+"); + FILE *file = fopen("iidxhook.dllmain.log", "w+"); log_to_writer(log_writer_file, file); #else log_to_writer(log_writer_null, NULL); @@ -238,10 +245,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) /* Bootstrap hook for further init tasks (see above) */ hook_table_apply( - NULL, - "kernel32.dll", - init_hook_syms, - lengthof(init_hook_syms)); + NULL, "kernel32.dll", init_hook_syms, lengthof(init_hook_syms)); /* Actual hooks for game specific stuff */ /* Some hooks are setting dependent and can only be applied later in @@ -263,4 +267,3 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) return TRUE; } - diff --git a/src/main/iidxhook4/dllmain.c b/src/main/iidxhook4/dllmain.c index d6b6a79..43ee469 100644 --- a/src/main/iidxhook4/dllmain.c +++ b/src/main/iidxhook4/dllmain.c @@ -1,8 +1,8 @@ #include #include -#include #include +#include #include #include "bemanitools/eamio.h" @@ -38,7 +38,7 @@ #include "util/str.h" #include "util/thread.h" -#define IIDXHOOK4_INFO_HEADER \ +#define IIDXHOOK4_INFO_HEADER \ "iidxhook for Resort Anthem" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) #define IIDXHOOK4_CMD_USAGE \ @@ -55,7 +55,8 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { iidxhook_util_d3d9_irp_handler, }; -static void iidxhook4_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_gfx) +static void +iidxhook4_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) { struct iidxhook_util_d3d9_config d3d9_config; @@ -75,12 +76,17 @@ static void iidxhook4_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_ if (config_gfx->monitor_check == 0) { log_info("Auto monitor check enabled"); - d3d9_config.iidx09_to_19_monitor_check_cb = iidxhook_util_chart_patch_set_refresh_rate; - iidxhook_util_chart_patch_init(IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_18_VGA); + d3d9_config.iidx09_to_19_monitor_check_cb = + iidxhook_util_chart_patch_set_refresh_rate; + iidxhook_util_chart_patch_init( + IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_18_VGA); } else if (config_gfx->monitor_check > 0) { - log_info("Manual monitor check, resulting refresh rate: %f", config_gfx->monitor_check); + log_info( + "Manual monitor check, resulting refresh rate: %f", + config_gfx->monitor_check); - iidxhook_util_chart_patch_init(IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_18_VGA); + iidxhook_util_chart_patch_init( + IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_18_VGA); iidxhook_util_chart_patch_set_refresh_rate(config_gfx->monitor_check); } @@ -91,8 +97,8 @@ static void iidxhook4_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_ static bool my_dll_entry_init(char *sidcode, struct property_node *param) { - struct cconfig* config; - + struct cconfig *config; + struct iidxhook_config_gfx config_gfx; log_server_init(); @@ -104,7 +110,10 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) iidxhook_config_gfx_init(config); - if (!cconfig_hook_config_init(config, IIDXHOOK4_INFO_HEADER "\n" IIDXHOOK4_CMD_USAGE, CCONFIG_CMD_USAGE_OUT_DBG)) { + if (!cconfig_hook_config_init( + config, + IIDXHOOK4_INFO_HEADER "\n" IIDXHOOK4_CMD_USAGE, + CCONFIG_CMD_USAGE_OUT_DBG)) { cconfig_finit(config); log_server_fini(); exit(EXIT_FAILURE); @@ -121,8 +130,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) /* Start up IIDXIO.DLL */ log_info("Starting IIDX IO backend"); - iidx_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning, - log_impl_fatal); + 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)) { log_fatal("Initializing IIDX IO backend failed"); @@ -130,8 +139,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) /* Start up EAMIO.DLL */ log_misc("Initializing card reader backend"); - eam_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning, - log_impl_fatal); + 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)) { log_fatal("Initializing card reader backend failed"); @@ -185,10 +194,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) } log_to_external( - log_body_misc, - log_body_info, - log_body_warning, - log_body_fatal); + log_body_misc, log_body_info, log_body_warning, log_body_fatal); app_hook_init(my_dll_entry_init, my_dll_entry_main); @@ -199,4 +205,3 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) end: return TRUE; } - diff --git a/src/main/iidxhook5/dllmain.c b/src/main/iidxhook5/dllmain.c index d00bd49..a091970 100644 --- a/src/main/iidxhook5/dllmain.c +++ b/src/main/iidxhook5/dllmain.c @@ -1,8 +1,8 @@ #include #include -#include #include +#include #include #include "bemanitools/eamio.h" @@ -38,7 +38,7 @@ #include "util/thread.h" #define IIDXHOOK5_INFO_HEADER \ - "iidxhook for Lincle" \ + "iidxhook for Lincle" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) #define IIDXHOOK5_CMD_USAGE \ "Usage: launcher.exe -K iidxhook5.dll [options...]" @@ -53,7 +53,8 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { iidxhook_util_d3d9_irp_handler, }; -static void iidxhook5_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_gfx) +static void +iidxhook5_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) { struct iidxhook_util_d3d9_config d3d9_config; @@ -77,8 +78,8 @@ static void iidxhook5_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_ static bool my_dll_entry_init(char *sidcode, struct property_node *param) { - struct cconfig* config; - + struct cconfig *config; + struct iidxhook_config_gfx config_gfx; log_server_init(); @@ -90,7 +91,10 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) iidxhook_config_gfx_init(config); - if (!cconfig_hook_config_init(config, IIDXHOOK5_INFO_HEADER "\n" IIDXHOOK5_CMD_USAGE, CCONFIG_CMD_USAGE_OUT_DBG)) { + if (!cconfig_hook_config_init( + config, + IIDXHOOK5_INFO_HEADER "\n" IIDXHOOK5_CMD_USAGE, + CCONFIG_CMD_USAGE_OUT_DBG)) { cconfig_finit(config); log_server_fini(); exit(EXIT_FAILURE); @@ -107,8 +111,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) /* Start up IIDXIO.DLL */ log_info("Starting IIDX IO backend"); - iidx_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning, - log_impl_fatal); + 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)) { log_fatal("Initializing IIDX IO backend failed"); @@ -116,8 +120,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) /* Start up EAMIO.DLL */ log_misc("Initializing card reader backend"); - eam_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning, - log_impl_fatal); + 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)) { log_fatal("Initializing card reader backend failed"); @@ -170,10 +174,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) } log_to_external( - log_body_misc, - log_body_info, - log_body_warning, - log_body_fatal); + log_body_misc, log_body_info, log_body_warning, log_body_fatal); app_hook_init(my_dll_entry_init, my_dll_entry_main); @@ -184,4 +185,3 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) end: return TRUE; } - diff --git a/src/main/iidxhook6/dllmain.c b/src/main/iidxhook6/dllmain.c index ccb162e..72a469f 100644 --- a/src/main/iidxhook6/dllmain.c +++ b/src/main/iidxhook6/dllmain.c @@ -1,8 +1,8 @@ #include #include -#include #include +#include #include #include "bemanitools/eamio.h" @@ -37,7 +37,7 @@ #include "util/thread.h" #define IIDXHOOK6_INFO_HEADER \ - "iidxhook for Tricoro" \ + "iidxhook for Tricoro" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) #define IIDXHOOK6_CMD_USAGE \ "Usage: launcher.exe -K iidxhook6.dll [options...]" @@ -51,7 +51,8 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { iidxhook_util_d3d9_irp_handler, }; -static void iidxhook6_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_gfx) +static void +iidxhook6_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) { struct iidxhook_util_d3d9_config d3d9_config; @@ -75,8 +76,8 @@ static void iidxhook6_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_ static bool my_dll_entry_init(char *sidcode, struct property_node *param) { - struct cconfig* config; - + struct cconfig *config; + struct iidxhook_config_gfx config_gfx; log_server_init(); @@ -88,7 +89,10 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) iidxhook_config_gfx_init(config); - if (!cconfig_hook_config_init(config, IIDXHOOK6_INFO_HEADER "\n" IIDXHOOK6_CMD_USAGE, CCONFIG_CMD_USAGE_OUT_DBG)) { + if (!cconfig_hook_config_init( + config, + IIDXHOOK6_INFO_HEADER "\n" IIDXHOOK6_CMD_USAGE, + CCONFIG_CMD_USAGE_OUT_DBG)) { cconfig_finit(config); log_server_fini(); exit(EXIT_FAILURE); @@ -105,8 +109,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) /* Start up IIDXIO.DLL */ log_info("Starting IIDX IO backend"); - iidx_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning, - log_impl_fatal); + 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)) { log_fatal("Initializing IIDX IO backend failed"); @@ -114,8 +118,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) /* Start up EAMIO.DLL */ log_misc("Initializing card reader backend"); - eam_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning, - log_impl_fatal); + 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)) { log_fatal("Initializing card reader backend failed"); @@ -168,10 +172,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) } log_to_external( - log_body_misc, - log_body_info, - log_body_warning, - log_body_fatal); + log_body_misc, log_body_info, log_body_warning, log_body_fatal); app_hook_init(my_dll_entry_init, my_dll_entry_main); @@ -181,4 +182,3 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) end: return TRUE; } - diff --git a/src/main/iidxhook7/dllmain.c b/src/main/iidxhook7/dllmain.c index cff64d6..1352628 100644 --- a/src/main/iidxhook7/dllmain.c +++ b/src/main/iidxhook7/dllmain.c @@ -1,8 +1,8 @@ #include #include -#include #include +#include #include #include "bemanitools/eamio.h" @@ -36,7 +36,7 @@ #include "util/str.h" #include "util/thread.h" -#define IIDXHOOK7_INFO_HEADER \ +#define IIDXHOOK7_INFO_HEADER \ "iidxhook for SPADA, PENDUAL, copula and SINOBUZ" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) #define IIDXHOOK7_CMD_USAGE \ @@ -51,7 +51,8 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { iidxhook_util_d3d9_irp_handler, }; -static void iidxhook7_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_gfx) +static void +iidxhook7_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) { struct iidxhook_util_d3d9_config d3d9_config; @@ -75,8 +76,8 @@ static void iidxhook7_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_ static bool my_dll_entry_init(char *sidcode, struct property_node *param) { - struct cconfig* config; - + struct cconfig *config; + struct iidxhook_config_gfx config_gfx; log_server_init(); @@ -88,7 +89,10 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) iidxhook_config_gfx_init(config); - if (!cconfig_hook_config_init(config, IIDXHOOK7_INFO_HEADER "\n" IIDXHOOK7_CMD_USAGE, CCONFIG_CMD_USAGE_OUT_DBG)) { + if (!cconfig_hook_config_init( + config, + IIDXHOOK7_INFO_HEADER "\n" IIDXHOOK7_CMD_USAGE, + CCONFIG_CMD_USAGE_OUT_DBG)) { cconfig_finit(config); log_server_fini(); exit(EXIT_FAILURE); @@ -105,8 +109,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) /* Start up IIDXIO.DLL */ log_info("Starting IIDX IO backend"); - iidx_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning, - log_impl_fatal); + 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)) { log_fatal("Initializing IIDX IO backend failed"); @@ -114,8 +118,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) /* Start up EAMIO.DLL */ log_misc("Initializing card reader backend"); - eam_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning, - log_impl_fatal); + 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)) { log_fatal("Initializing card reader backend failed"); @@ -168,10 +172,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) } log_to_external( - log_body_misc, - log_body_info, - log_body_warning, - log_body_fatal); + log_body_misc, log_body_info, log_body_warning, log_body_fatal); app_hook_init(my_dll_entry_init, my_dll_entry_main); @@ -181,4 +182,3 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) end: return TRUE; } - diff --git a/src/main/iidxhook8/bi2a.c b/src/main/iidxhook8/bi2a.c index 8242127..d419e2e 100644 --- a/src/main/iidxhook8/bi2a.c +++ b/src/main/iidxhook8/bi2a.c @@ -6,23 +6,28 @@ #include /* for _BitScanForward */ #include -#include #include +#include #include "acioemu/emu.h" #include "bemanitools/iidxio.h" static int get_default_slider_valid(size_t idx); -static void bio2_emu_bi2a_cmd_send_version(struct ac_io_emu *emu, const struct ac_io_message *req); -static void bio2_emu_bi2a_send_state(struct ac_io_emu *emu, const struct ac_io_message *req); -static void bio2_emu_bi2a_send_empty(struct ac_io_emu *emu, const struct ac_io_message *req); -static void bio2_emu_bi2a_send_status(struct ac_io_emu *emu, const struct ac_io_message *req, uint8_t status); +static void bio2_emu_bi2a_cmd_send_version( + struct ac_io_emu *emu, const struct ac_io_message *req); +static void bio2_emu_bi2a_send_state( + struct ac_io_emu *emu, const struct ac_io_message *req); +static void bio2_emu_bi2a_send_empty( + struct ac_io_emu *emu, const struct ac_io_message *req); +static void bio2_emu_bi2a_send_status( + struct ac_io_emu *emu, const struct ac_io_message *req, uint8_t status); static int default_sliders[5]; static bool poll_delay; -int get_default_slider_valid(size_t idx) { +int get_default_slider_valid(size_t idx) +{ if (default_sliders[idx] >= 0 && default_sliders[idx] <= 15) { return 1; } else { @@ -30,7 +35,8 @@ int get_default_slider_valid(size_t idx) { } } -void bio2_emu_bi2a_init(struct bio2emu_port *bio2_emu, bool disable_poll_limiter) +void bio2_emu_bi2a_init( + struct bio2emu_port *bio2_emu, bool disable_poll_limiter) { bio2emu_port_init(bio2_emu); @@ -43,15 +49,22 @@ void bio2_emu_bi2a_init(struct bio2emu_port *bio2_emu, bool disable_poll_limiter default_sliders[i] = -1; } - FILE* f = fopen("vefx.txt", "r"); + FILE *f = fopen("vefx.txt", "r"); if (f) { - fscanf(f, "%d %d %d %d %d", &default_sliders[0], &default_sliders[1], &default_sliders[2], &default_sliders[3], &default_sliders[4]); + fscanf( + f, + "%d %d %d %d %d", + &default_sliders[0], + &default_sliders[1], + &default_sliders[2], + &default_sliders[3], + &default_sliders[4]); fclose(f); } - } -void bio2_emu_bi2a_dispatch_request(struct bio2emu_port *bio2port, const struct ac_io_message *req) +void bio2_emu_bi2a_dispatch_request( + struct bio2emu_port *bio2port, const struct ac_io_message *req) { uint16_t cmd_code; @@ -85,12 +98,16 @@ void bio2_emu_bi2a_dispatch_request(struct bio2emu_port *bio2port, const struct break; default: - log_warning("Unknown BIO2 message %04x on BI2A node, addr=%d", cmd_code, req->addr); + log_warning( + "Unknown BIO2 message %04x on BI2A node, addr=%d", + cmd_code, + req->addr); break; } } -static void bio2_emu_bi2a_cmd_send_version(struct ac_io_emu *emu, const struct ac_io_message *req) +static void bio2_emu_bi2a_cmd_send_version( + struct ac_io_emu *emu, const struct ac_io_message *req) { struct ac_io_message resp; @@ -103,15 +120,18 @@ static void bio2_emu_bi2a_cmd_send_version(struct ac_io_emu *emu, const struct a resp.cmd.version.major = 0x04; resp.cmd.version.minor = 0x00; resp.cmd.version.revision = 0x04; - memcpy(resp.cmd.version.product_code, "BI2A", - sizeof(resp.cmd.version.product_code)); + memcpy( + resp.cmd.version.product_code, + "BI2A", + sizeof(resp.cmd.version.product_code)); strncpy(resp.cmd.version.date, __DATE__, sizeof(resp.cmd.version.date)); strncpy(resp.cmd.version.time, __TIME__, sizeof(resp.cmd.version.time)); ac_io_emu_response_push(emu, &resp, 0); } -static void bio2_emu_bi2a_send_empty(struct ac_io_emu *emu, const struct ac_io_message *req) +static void +bio2_emu_bi2a_send_empty(struct ac_io_emu *emu, const struct ac_io_message *req) { struct ac_io_message resp; @@ -123,7 +143,8 @@ static void bio2_emu_bi2a_send_empty(struct ac_io_emu *emu, const struct ac_io_m ac_io_emu_response_push(emu, &resp, 0); } -static void bio2_emu_bi2a_send_status(struct ac_io_emu *emu, const struct ac_io_message *req, uint8_t status) +static void bio2_emu_bi2a_send_status( + struct ac_io_emu *emu, const struct ac_io_message *req, uint8_t status) { struct ac_io_message resp; @@ -136,8 +157,8 @@ static void bio2_emu_bi2a_send_status(struct ac_io_emu *emu, const struct ac_io_ ac_io_emu_response_push(emu, &resp, 0); } - -static void bio2_emu_bi2a_send_state(struct ac_io_emu *emu, const struct ac_io_message *req) +static void +bio2_emu_bi2a_send_state(struct ac_io_emu *emu, const struct ac_io_message *req) { struct ac_io_message resp; struct bi2a_iidx_state_out *body; @@ -157,7 +178,7 @@ static void bio2_emu_bi2a_send_state(struct ac_io_emu *emu, const struct ac_io_m resp.cmd.code = req->cmd.code; resp.cmd.seq_no = req->cmd.seq_no; resp.cmd.nbytes = sizeof(struct bi2a_iidx_state_out); - req_bi2a = (struct bi2a_iidx_state_in*)req->cmd.raw; + req_bi2a = (struct bi2a_iidx_state_in *) req->cmd.raw; packed_lights.panel_lights = 0; for (size_t i = 0; i < 4; ++i) { @@ -193,12 +214,12 @@ static void bio2_emu_bi2a_send_state(struct ac_io_emu *emu, const struct ac_io_m return bio2_emu_bi2a_send_status(emu, req, 0); } - if (!iidx_io_ep3_write_16seg((const char*) req_bi2a->SEG16)) { + if (!iidx_io_ep3_write_16seg((const char *) req_bi2a->SEG16)) { log_warning("BIO2: iidx_io_ep3_write_16seg error"); return bio2_emu_bi2a_send_status(emu, req, 0); } - body = (struct bi2a_iidx_state_out *)&resp.cmd.raw; + body = (struct bi2a_iidx_state_out *) &resp.cmd.raw; memset(body, 0, sizeof(struct bi2a_iidx_state_out)); // IIDX25 polls really really fast, this limits it to 1000Hz @@ -214,11 +235,21 @@ static void bio2_emu_bi2a_send_state(struct ac_io_emu *emu, const struct ac_io_m body->TURNTABLE1 = iidx_io_ep2_get_turntable(0); body->TURNTABLE2 = iidx_io_ep2_get_turntable(1); - body->SLIDER1.s_val = get_default_slider_valid(0) ? default_sliders[0] : iidx_io_ep2_get_slider(0); - body->SLIDER2.s_val = get_default_slider_valid(1) ? default_sliders[1] : iidx_io_ep2_get_slider(1); - body->SLIDER3.s_val = get_default_slider_valid(2) ? default_sliders[2] : iidx_io_ep2_get_slider(2); - body->SLIDER4.s_val = get_default_slider_valid(3) ? default_sliders[3] : iidx_io_ep2_get_slider(3); - body->SLIDER5.s_val = get_default_slider_valid(4) ? default_sliders[4] : iidx_io_ep2_get_slider(4); + body->SLIDER1.s_val = get_default_slider_valid(0) ? + default_sliders[0] : + iidx_io_ep2_get_slider(0); + body->SLIDER2.s_val = get_default_slider_valid(1) ? + default_sliders[1] : + iidx_io_ep2_get_slider(1); + body->SLIDER3.s_val = get_default_slider_valid(2) ? + default_sliders[2] : + iidx_io_ep2_get_slider(2); + body->SLIDER4.s_val = get_default_slider_valid(3) ? + default_sliders[3] : + iidx_io_ep2_get_slider(3); + body->SLIDER5.s_val = get_default_slider_valid(4) ? + default_sliders[4] : + iidx_io_ep2_get_slider(4); input_keys = iidx_io_ep2_get_keys(); input_sys = iidx_io_ep2_get_sys(); diff --git a/src/main/iidxhook8/bi2a.h b/src/main/iidxhook8/bi2a.h index eb18b07..46a4d82 100644 --- a/src/main/iidxhook8/bi2a.h +++ b/src/main/iidxhook8/bi2a.h @@ -2,43 +2,43 @@ #define IIDXHOOK_BI2A_H #include -#include #include +#include #include "bio2emu/emu.h" enum bio2_iidx_cmd { // Custom Stuff - BIO2_BI2A_CMD_UNK_0100 = 0x0100, - BIO2_BI2A_CMD_UNK_0120 = 0x0120, - BIO2_BI2A_CMD_POLL = 0x0152, + BIO2_BI2A_CMD_UNK_0100 = 0x0100, + BIO2_BI2A_CMD_UNK_0120 = 0x0120, + BIO2_BI2A_CMD_POLL = 0x0152, }; #pragma pack(push, 1) struct bi2a_iidx_slider { - uint8_t s_unk : 4; - uint8_t s_val : 4; + uint8_t s_unk : 4; + uint8_t s_val : 4; }; struct bi2a_iidx_system { - uint8_t v_unk1 : 1; - uint8_t v_coin : 1; - uint8_t v_service : 1; - uint8_t v_test : 1; - uint8_t v_unk2 : 4; + uint8_t v_unk1 : 1; + uint8_t v_coin : 1; + uint8_t v_service : 1; + uint8_t v_test : 1; + uint8_t v_unk2 : 4; }; struct bi2a_iidx_button { - uint8_t b_unk : 7; - uint8_t b_val : 1; + uint8_t b_unk : 7; + uint8_t b_val : 1; }; struct bi2a_iidx_panel { - uint8_t y_unk : 4; - uint8_t y_effect : 1; - uint8_t y_vefx : 1; - uint8_t y_start2 : 1; - uint8_t y_start1 : 1; + uint8_t y_unk : 4; + uint8_t y_effect : 1; + uint8_t y_vefx : 1; + uint8_t y_start2 : 1; + uint8_t y_start1 : 1; }; struct bi2a_iidx_state_out { @@ -91,8 +91,8 @@ struct bi2a_iidx_state_out { }; struct bi2a_iidx_light { - uint8_t l_unk : 7; - uint8_t l_state : 1; + uint8_t l_unk : 7; + uint8_t l_state : 1; }; struct bi2a_iidx_state_in { @@ -106,11 +106,16 @@ struct bi2a_iidx_state_in { struct bi2a_iidx_light SPOTLIGHT2[4]; uint8_t UNK3[7]; }; -_Static_assert(sizeof(struct bi2a_iidx_state_in) == 48, "bi2a_iidx_state_in is the wrong size"); -_Static_assert(sizeof(struct bi2a_iidx_state_out) == 46, "bi2a_iidx_state_out is the wrong size"); +_Static_assert( + sizeof(struct bi2a_iidx_state_in) == 48, + "bi2a_iidx_state_in is the wrong size"); +_Static_assert( + sizeof(struct bi2a_iidx_state_out) == 46, + "bi2a_iidx_state_out is the wrong size"); #pragma pack(pop) void bio2_emu_bi2a_init(struct bio2emu_port *in, bool disable_poll_limiter); -void bio2_emu_bi2a_dispatch_request(struct bio2emu_port *bio2port, const struct ac_io_message *req); +void bio2_emu_bi2a_dispatch_request( + struct bio2emu_port *bio2port, const struct ac_io_message *req); #endif diff --git a/src/main/iidxhook8/cam.c b/src/main/iidxhook8/cam.c index 83f923b..fd2a707 100644 --- a/src/main/iidxhook8/cam.c +++ b/src/main/iidxhook8/cam.c @@ -3,12 +3,12 @@ #include #include -#include -#include #include +#include +#include -#include #include +#include #include @@ -24,9 +24,45 @@ #define CAMERA_DATA_STRING_SIZE 0x100 -EXTERN_GUID(MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, 0xc60ac5fe, 0x252a, 0x478f, 0xa0, 0xef, 0xbc, 0x8f, 0xa5, 0xf7, 0xca, 0xd3); -EXTERN_GUID(MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID, 0x8ac3587a, 0x4ae7, 0x42d8, 0x99, 0xe0, 0x0a, 0x60, 0x13, 0xee, 0xf9, 0x0f); -EXTERN_GUID(MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, 0x58f0aad8, 0x22bf, 0x4f8a, 0xbb, 0x3d, 0xd2, 0xc4, 0x97, 0x8c, 0x6e, 0x2f); +EXTERN_GUID( + MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, + 0xc60ac5fe, + 0x252a, + 0x478f, + 0xa0, + 0xef, + 0xbc, + 0x8f, + 0xa5, + 0xf7, + 0xca, + 0xd3); +EXTERN_GUID( + MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID, + 0x8ac3587a, + 0x4ae7, + 0x42d8, + 0x99, + 0xe0, + 0x0a, + 0x60, + 0x13, + 0xee, + 0xf9, + 0x0f); +EXTERN_GUID( + MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, + 0x58f0aad8, + 0x22bf, + 0x4f8a, + 0xbb, + 0x3d, + 0xd2, + 0xc4, + 0x97, + 0x8c, + 0x6e, + 0x2f); // define ourselves cause mingw has these wrong struct CameraData { @@ -43,155 +79,96 @@ struct CameraData { static struct CameraData camData[2]; - static CONFIGRET my_CM_Locate_DevNodeA( - PDEVINST pdnDevInst, - DEVINSTID_A pDeviceID, - ULONG ulFlags -); + PDEVINST pdnDevInst, DEVINSTID_A pDeviceID, ULONG ulFlags); -static CONFIGRET my_CM_Get_Parent( - PDEVINST pdnDevInst, - DEVINST dnDevInst, - ULONG ulFlags -); +static CONFIGRET +my_CM_Get_Parent(PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags); static CONFIGRET my_CM_Get_Device_IDA( - DEVINST dnDevInst, - PSTR Buffer, - ULONG BufferLen, - ULONG ulFlags -); + DEVINST dnDevInst, PSTR Buffer, ULONG BufferLen, ULONG ulFlags); -static CONFIGRET(*real_CM_Locate_DevNodeA)( - PDEVINST pdnDevInst, - DEVINSTID_A pDeviceID, - ULONG ulFlags -); +static CONFIGRET (*real_CM_Locate_DevNodeA)( + PDEVINST pdnDevInst, DEVINSTID_A pDeviceID, ULONG ulFlags); -static CONFIGRET(*real_CM_Get_Parent)( - PDEVINST pdnDevInst, - DEVINST dnDevInst, - ULONG ulFlags -); +static CONFIGRET (*real_CM_Get_Parent)( + PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags); -static CONFIGRET(*real_CM_Get_Device_IDA)( - DEVINST dnDevInst, - PSTR Buffer, - ULONG BufferLen, - ULONG ulFlags -); +static CONFIGRET (*real_CM_Get_Device_IDA)( + DEVINST dnDevInst, PSTR Buffer, ULONG BufferLen, ULONG ulFlags); static HRESULT my_MFEnumDeviceSources( - IMFAttributes *pAttributes, - IMFActivate ***pppSourceActivate, - UINT32 *pcSourceActivate -); + IMFAttributes *pAttributes, + IMFActivate ***pppSourceActivate, + UINT32 *pcSourceActivate); static HRESULT (*real_MFEnumDeviceSources)( - IMFAttributes *pAttributes, - IMFActivate ***pppSourceActivate, - UINT32 *pcSourceActivate -); + IMFAttributes *pAttributes, + IMFActivate ***pppSourceActivate, + UINT32 *pcSourceActivate); -static BOOL my_SetupDiDestroyDeviceInfoList( - HDEVINFO DeviceInfoSet -); +static BOOL my_SetupDiDestroyDeviceInfoList(HDEVINFO DeviceInfoSet); -static BOOL (*real_SetupDiDestroyDeviceInfoList)( - HDEVINFO DeviceInfoSet -); +static BOOL (*real_SetupDiDestroyDeviceInfoList)(HDEVINFO DeviceInfoSet); static BOOL my_SetupDiEnumDeviceInfo( - HDEVINFO DeviceInfoSet, - DWORD MemberIndex, - PSP_DEVINFO_DATA DeviceInfoData -); + HDEVINFO DeviceInfoSet, DWORD MemberIndex, PSP_DEVINFO_DATA DeviceInfoData); static BOOL (*real_SetupDiEnumDeviceInfo)( - HDEVINFO DeviceInfoSet, - DWORD MemberIndex, - PSP_DEVINFO_DATA DeviceInfoData -); + HDEVINFO DeviceInfoSet, DWORD MemberIndex, PSP_DEVINFO_DATA DeviceInfoData); static BOOL my_SetupDiGetDeviceRegistryPropertyA( - HDEVINFO DeviceInfoSet, - PSP_DEVINFO_DATA DeviceInfoData, - DWORD Property, - PDWORD PropertyRegDataType, - PBYTE PropertyBuffer, - DWORD PropertyBufferSize, - PDWORD RequiredSize -); + HDEVINFO DeviceInfoSet, + PSP_DEVINFO_DATA DeviceInfoData, + DWORD Property, + PDWORD PropertyRegDataType, + PBYTE PropertyBuffer, + DWORD PropertyBufferSize, + PDWORD RequiredSize); static BOOL (*real_SetupDiGetDeviceRegistryPropertyA)( - HDEVINFO DeviceInfoSet, - PSP_DEVINFO_DATA DeviceInfoData, - DWORD Property, - PDWORD PropertyRegDataType, - PBYTE PropertyBuffer, - DWORD PropertyBufferSize, - PDWORD RequiredSize -); + HDEVINFO DeviceInfoSet, + PSP_DEVINFO_DATA DeviceInfoData, + DWORD Property, + PDWORD PropertyRegDataType, + PBYTE PropertyBuffer, + DWORD PropertyBufferSize, + PDWORD RequiredSize); static HDEVINFO my_SetupDiGetClassDevsA( - CONST GUID *ClassGuid, - PCSTR Enumerator, - HWND hwndParent, - DWORD Flags -); + CONST GUID *ClassGuid, PCSTR Enumerator, HWND hwndParent, DWORD Flags); -static HDEVINFO(*real_SetupDiGetClassDevsA)( - CONST GUID *ClassGuid, - PCSTR Enumerator, - HWND hwndParent, - DWORD Flags -); +static HDEVINFO (*real_SetupDiGetClassDevsA)( + CONST GUID *ClassGuid, PCSTR Enumerator, HWND hwndParent, DWORD Flags); static const struct hook_symbol iidxhook5_cfgmgr32_syms[] = { - { - .name = "CM_Locate_DevNodeA", - .patch = my_CM_Locate_DevNodeA, - .link = (void **) &real_CM_Locate_DevNodeA - }, - { - .name = "CM_Get_Parent", - .patch = my_CM_Get_Parent, - .link = (void **) &real_CM_Get_Parent - }, - { - .name = "CM_Get_Device_IDA", - .patch = my_CM_Get_Device_IDA, - .link = (void **) &real_CM_Get_Device_IDA - }, - { - .name = "SetupDiDestroyDeviceInfoList", - .patch = my_SetupDiDestroyDeviceInfoList, - .link = (void **) &real_SetupDiDestroyDeviceInfoList - }, - { - .name = "SetupDiEnumDeviceInfo", - .patch = my_SetupDiEnumDeviceInfo, - .link = (void **) &real_SetupDiEnumDeviceInfo - }, - { - .name = "SetupDiGetDeviceRegistryPropertyA", - .patch = my_SetupDiGetDeviceRegistryPropertyA, - .link = (void **) &real_SetupDiGetDeviceRegistryPropertyA - }, - { - .name = "SetupDiGetClassDevsA", - .patch = my_SetupDiGetClassDevsA, - .link = (void **) &real_SetupDiGetClassDevsA - }, + {.name = "CM_Locate_DevNodeA", + .patch = my_CM_Locate_DevNodeA, + .link = (void **) &real_CM_Locate_DevNodeA}, + {.name = "CM_Get_Parent", + .patch = my_CM_Get_Parent, + .link = (void **) &real_CM_Get_Parent}, + {.name = "CM_Get_Device_IDA", + .patch = my_CM_Get_Device_IDA, + .link = (void **) &real_CM_Get_Device_IDA}, + {.name = "SetupDiDestroyDeviceInfoList", + .patch = my_SetupDiDestroyDeviceInfoList, + .link = (void **) &real_SetupDiDestroyDeviceInfoList}, + {.name = "SetupDiEnumDeviceInfo", + .patch = my_SetupDiEnumDeviceInfo, + .link = (void **) &real_SetupDiEnumDeviceInfo}, + {.name = "SetupDiGetDeviceRegistryPropertyA", + .patch = my_SetupDiGetDeviceRegistryPropertyA, + .link = (void **) &real_SetupDiGetDeviceRegistryPropertyA}, + {.name = "SetupDiGetClassDevsA", + .patch = my_SetupDiGetClassDevsA, + .link = (void **) &real_SetupDiGetClassDevsA}, }; static const struct hook_symbol iidxhook5_mf_syms[] = { - { - .name = "MFEnumDeviceSources", - .patch = my_MFEnumDeviceSources, - .link = (void **) &real_MFEnumDeviceSources - }, + {.name = "MFEnumDeviceSources", + .patch = my_MFEnumDeviceSources, + .link = (void **) &real_MFEnumDeviceSources}, }; #define CUSTOM_DEV_NODE1 0x04040004 @@ -200,22 +177,33 @@ static const struct hook_symbol iidxhook5_mf_syms[] = { #define CUSTOM_DEV_PARENT_NODE1 0x04040014 #define CUSTOM_DEV_PARENT_NODE2 0x04040018 -static CONFIGRET my_CM_Locate_DevNodeA( - PDEVINST pdnDevInst, - DEVINSTID_A pDeviceID, - ULONG ulFlags -){ +static CONFIGRET +my_CM_Locate_DevNodeA(PDEVINST pdnDevInst, DEVINSTID_A pDeviceID, ULONG ulFlags) +{ log_info("Inside: %s", __FUNCTION__); char builtString1[CAMERA_DATA_STRING_SIZE] = {0}; char builtString2[CAMERA_DATA_STRING_SIZE] = {0}; if (camData[0].setup) { - snprintf(builtString1, CAMERA_DATA_STRING_SIZE, "USB\\VID_288C&PID_0002&MI_00\\%s", camData[0].extra_upper); - if(camData[1].setup) { - snprintf(builtString2, CAMERA_DATA_STRING_SIZE, "USB\\VID_288C&PID_0002&MI_00\\%s", camData[1].extra_upper); + snprintf( + builtString1, + CAMERA_DATA_STRING_SIZE, + "USB\\VID_288C&PID_0002&MI_00\\%s", + camData[0].extra_upper); + + if (camData[1].setup) { + snprintf( + builtString2, + CAMERA_DATA_STRING_SIZE, + "USB\\VID_288C&PID_0002&MI_00\\%s", + camData[1].extra_upper); } - } else if(camData[1].setup) { - snprintf(builtString1, CAMERA_DATA_STRING_SIZE, "USB\\VID_288C&PID_0002&MI_00\\%s", camData[1].extra_upper); + } else if (camData[1].setup) { + snprintf( + builtString1, + CAMERA_DATA_STRING_SIZE, + "USB\\VID_288C&PID_0002&MI_00\\%s", + camData[1].extra_upper); } if (pdnDevInst) { @@ -224,6 +212,7 @@ static CONFIGRET my_CM_Locate_DevNodeA( *pdnDevInst = CUSTOM_DEV_NODE1; return CR_SUCCESS; } + if (strcmp(pDeviceID, builtString2) == 0) { log_info("Injecting custom device 2"); *pdnDevInst = CUSTOM_DEV_NODE2; @@ -233,11 +222,9 @@ static CONFIGRET my_CM_Locate_DevNodeA( return real_CM_Locate_DevNodeA(pdnDevInst, pDeviceID, ulFlags); } -static CONFIGRET my_CM_Get_Parent( - PDEVINST pdnDevInst, - DEVINST dnDevInst, - ULONG ulFlags -){ +static CONFIGRET +my_CM_Get_Parent(PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags) +{ log_info("Inside: %s", __FUNCTION__); if (pdnDevInst) { @@ -257,11 +244,8 @@ static CONFIGRET my_CM_Get_Parent( } static CONFIGRET my_CM_Get_Device_IDA( - DEVINST dnDevInst, - PSTR Buffer, - ULONG BufferLen, - ULONG ulFlags -){ + DEVINST dnDevInst, PSTR Buffer, ULONG BufferLen, ULONG ulFlags) +{ log_info("Inside: %s", __FUNCTION__); if (Buffer) { @@ -272,6 +256,7 @@ static CONFIGRET my_CM_Get_Device_IDA( log_info("%s", Buffer); return CR_SUCCESS; } + if (dnDevInst == CUSTOM_DEV_PARENT_NODE2) { log_info("Injecting custom parent 2 ID"); strncpy(Buffer, "USB\\VEN_1022&DEV_7914", BufferLen); @@ -283,19 +268,13 @@ static CONFIGRET my_CM_Get_Device_IDA( return real_CM_Get_Device_IDA(dnDevInst, Buffer, BufferLen, ulFlags); } +static HRESULT(STDCALL *real_GetAllocatedString)( + IMFActivate *self, REFGUID guidKey, LPWSTR *ppwszValue, UINT32 *pcchLength); -static HRESULT (STDCALL *real_GetAllocatedString)( - IMFActivate* self, - REFGUID guidKey, - LPWSTR *ppwszValue, - UINT32 *pcchLength); - -HRESULT my_GetAllocatedString( - IMFActivate* self, - REFGUID guidKey, - LPWSTR *ppwszValue, - UINT32 *pcchLength -){ +HRESULT +my_GetAllocatedString( + IMFActivate *self, REFGUID guidKey, LPWSTR *ppwszValue, UINT32 *pcchLength) +{ HRESULT ret; log_info("Inside: %s", __FUNCTION__); @@ -308,13 +287,14 @@ HRESULT my_GetAllocatedString( if (camData[0].setup) { pwc = wcsstr(*ppwszValue, camData[0].deviceSymbolicLink); } + if (camData[1].setup) { if (!pwc) { pwc = wcsstr(*ppwszValue, camData[1].deviceSymbolicLink); } } - if (pwc){ + if (pwc) { // \\?\usb#vid_288c&pid_0002&mi_00 pwc[12] = L'2'; pwc[13] = L'8'; @@ -332,14 +312,13 @@ HRESULT my_GetAllocatedString( } return ret; - } static HRESULT my_MFEnumDeviceSources( - IMFAttributes *pAttributes, - IMFActivate ***pppSourceActivate, - UINT32 *pcSourceActivate -){ + IMFAttributes *pAttributes, + IMFActivate ***pppSourceActivate, + UINT32 *pcSourceActivate) +{ IMFActivate *api; IMFActivateVtbl *api_vtbl; struct com_proxy *api_proxy; @@ -348,9 +327,9 @@ static HRESULT my_MFEnumDeviceSources( HRESULT ret; - log_info("Inside: %s", __FUNCTION__); - ret = real_MFEnumDeviceSources(pAttributes, pppSourceActivate, pcSourceActivate); + ret = real_MFEnumDeviceSources( + pAttributes, pppSourceActivate, pcSourceActivate); nsrcs = *pcSourceActivate; for (UINT32 i = 0; i < nsrcs; ++i) { @@ -361,88 +340,112 @@ static HRESULT my_MFEnumDeviceSources( real_GetAllocatedString = api_vtbl->GetAllocatedString; api_vtbl->GetAllocatedString = my_GetAllocatedString; - (*pppSourceActivate)[i] = (IMFActivate *)api_proxy; + (*pppSourceActivate)[i] = (IMFActivate *) api_proxy; } - return ret; } -#define CUSTOM_DEVICE_HANDLE (void*)0x04041110 +#define CUSTOM_DEVICE_HANDLE (void *) 0x04041110 static HDEVINFO RealReplacedHandle; -static BOOL my_SetupDiDestroyDeviceInfoList( - HDEVINFO DeviceInfoSet -){ - if (DeviceInfoSet == CUSTOM_DEVICE_HANDLE){ +static BOOL my_SetupDiDestroyDeviceInfoList(HDEVINFO DeviceInfoSet) +{ + if (DeviceInfoSet == CUSTOM_DEVICE_HANDLE) { log_info("Inside: %s", __FUNCTION__); DeviceInfoSet = RealReplacedHandle; RealReplacedHandle = NULL; return real_SetupDiDestroyDeviceInfoList(DeviceInfoSet); } + return real_SetupDiDestroyDeviceInfoList(DeviceInfoSet); } static BOOL my_SetupDiEnumDeviceInfo( - HDEVINFO DeviceInfoSet, - DWORD MemberIndex, - PSP_DEVINFO_DATA DeviceInfoData -){ + HDEVINFO DeviceInfoSet, DWORD MemberIndex, PSP_DEVINFO_DATA DeviceInfoData) +{ if (DeviceInfoSet == CUSTOM_DEVICE_HANDLE) { // log_info("Inside: %s", __FUNCTION__); - return real_SetupDiEnumDeviceInfo(RealReplacedHandle, MemberIndex, DeviceInfoData); + return real_SetupDiEnumDeviceInfo( + RealReplacedHandle, MemberIndex, DeviceInfoData); } - return real_SetupDiEnumDeviceInfo(DeviceInfoSet, MemberIndex, DeviceInfoData); + + return real_SetupDiEnumDeviceInfo( + DeviceInfoSet, MemberIndex, DeviceInfoData); } static BOOL my_SetupDiGetDeviceRegistryPropertyA( - HDEVINFO DeviceInfoSet, - PSP_DEVINFO_DATA DeviceInfoData, - DWORD Property, - PDWORD PropertyRegDataType, - PBYTE PropertyBuffer, - DWORD PropertyBufferSize, - PDWORD RequiredSize -){ + HDEVINFO DeviceInfoSet, + PSP_DEVINFO_DATA DeviceInfoData, + DWORD Property, + PDWORD PropertyRegDataType, + PBYTE PropertyBuffer, + DWORD PropertyBufferSize, + PDWORD RequiredSize) +{ if (DeviceInfoSet == CUSTOM_DEVICE_HANDLE) { - BOOL ret = real_SetupDiGetDeviceRegistryPropertyA(RealReplacedHandle, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize); + BOOL ret = real_SetupDiGetDeviceRegistryPropertyA( + RealReplacedHandle, + DeviceInfoData, + Property, + PropertyRegDataType, + PropertyBuffer, + PropertyBufferSize, + RequiredSize); if (Property == SPDRP_DEVICEDESC) { - if (PropertyBuffer){ + if (PropertyBuffer) { if (camData[0].setup) { - if (strcmp((char*)PropertyBuffer, camData[0].parent_name) == 0) { - log_info("%s: replacing %s", __FUNCTION__, camData[0].parent_name); - strncpy((char*)PropertyBuffer, "USB Composite Device", PropertyBufferSize); + if (strcmp( + (char *) PropertyBuffer, camData[0].parent_name) == + 0) { + log_info( + "%s: replacing %s", + __FUNCTION__, + camData[0].parent_name); + strncpy( + (char *) PropertyBuffer, + "USB Composite Device", + PropertyBufferSize); } } + if (camData[1].setup) { - if (strcmp((char*)PropertyBuffer, camData[1].parent_name) == 0) { - log_info("%s: replacing %s", __FUNCTION__, camData[1].parent_name); - strncpy((char*)PropertyBuffer, "USB Composite Device", PropertyBufferSize); + if (strcmp( + (char *) PropertyBuffer, camData[1].parent_name) == + 0) { + log_info( + "%s: replacing %s", + __FUNCTION__, + camData[1].parent_name); + strncpy( + (char *) PropertyBuffer, + "USB Composite Device", + PropertyBufferSize); } } } return ret; } else if (Property == SPDRP_ADDRESS) { - if (PropertyBuffer){ - int addr = *(int*)PropertyBuffer; + if (PropertyBuffer) { + int addr = *(int *) PropertyBuffer; if (camData[0].setup) { if (addr == camData[0].parent_address) { log_info("%s: replacing addr1", __FUNCTION__); - *(int*)PropertyBuffer = 1; + *(int *) PropertyBuffer = 1; } else if (camData[1].setup) { if (addr == camData[1].parent_address) { log_info("%s: replacing addr7", __FUNCTION__); - *(int*)PropertyBuffer = 7; + *(int *) PropertyBuffer = 7; } } } else if (camData[1].setup) { if (addr == camData[1].parent_address) { log_info("%s: replacing addr1 (alt)", __FUNCTION__); - *(int*)PropertyBuffer = 1; + *(int *) PropertyBuffer = 1; } } } @@ -450,36 +453,48 @@ static BOOL my_SetupDiGetDeviceRegistryPropertyA( return ret; } } - return real_SetupDiGetDeviceRegistryPropertyA(DeviceInfoSet, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize); + + return real_SetupDiGetDeviceRegistryPropertyA( + DeviceInfoSet, + DeviceInfoData, + Property, + PropertyRegDataType, + PropertyBuffer, + PropertyBufferSize, + RequiredSize); } static HDEVINFO my_SetupDiGetClassDevsA( - CONST GUID *ClassGuid, - PCSTR Enumerator, - HWND hwndParent, - DWORD Flags -){ - if (ClassGuid == NULL && Enumerator != NULL && hwndParent == NULL && Flags == (DIGCF_PRESENT | DIGCF_ALLCLASSES)) { + CONST GUID *ClassGuid, PCSTR Enumerator, HWND hwndParent, DWORD Flags) +{ + if (ClassGuid == NULL && Enumerator != NULL && hwndParent == NULL && + Flags == (DIGCF_PRESENT | DIGCF_ALLCLASSES)) { if (RealReplacedHandle) { log_info("Replacement handle is already set?"); } + if (strcmp(Enumerator, "USB") == 0) { log_info("Inside: %s", __FUNCTION__); - RealReplacedHandle = real_SetupDiGetClassDevsA(ClassGuid, Enumerator, hwndParent, Flags); + RealReplacedHandle = real_SetupDiGetClassDevsA( + ClassGuid, Enumerator, hwndParent, Flags); + if (RealReplacedHandle == INVALID_HANDLE_VALUE) { return INVALID_HANDLE_VALUE; } + return CUSTOM_DEVICE_HANDLE; } } return real_SetupDiGetClassDevsA(ClassGuid, Enumerator, hwndParent, Flags); } -bool check_four(const char inA[4], const char inB[4]) { - return (*(uint32_t*)inA == *(uint32_t*)inB); +bool check_four(const char inA[4], const char inB[4]) +{ + return (*(uint32_t *) inA == *(uint32_t *) inB); } -char* grab_next_camera_id(char* buffer, size_t bsz) { +char *grab_next_camera_id(char *buffer, size_t bsz) +{ static size_t gotten = 0; IMFAttributes *pAttributes = NULL; @@ -488,26 +503,32 @@ char* grab_next_camera_id(char* buffer, size_t bsz) { buffer[0] = '\0'; HRESULT hr = MFCreateAttributes(&pAttributes, 1); + if (FAILED(hr)) { log_info("MFCreateAttributes failed: %ld", hr); goto done; } - hr = pAttributes->lpVtbl->SetGUID(pAttributes, &MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, &MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID); - if (FAILED(hr)) { + hr = pAttributes->lpVtbl->SetGUID( + pAttributes, + &MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, + &MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID); + i f(FAILED(hr)) + { log_info("SetGUID failed: %ld", hr); goto done; } UINT32 count; hr = MFEnumDeviceSources(pAttributes, &ppDevices, &count); + if (FAILED(hr)) { log_info("MFEnumDeviceSources failed: %ld", hr); goto done; } if (count <= gotten) { - log_info("gotten failed: %d < %d", count, (int)gotten); + log_info("gotten failed: %d < %d", count, (int) gotten); // not enough remaining goto done; } @@ -515,11 +536,18 @@ char* grab_next_camera_id(char* buffer, size_t bsz) { wchar_t wSymLink[CAMERA_DATA_STRING_SIZE]; UINT32 sz; - hr = ppDevices[gotten]->lpVtbl->GetString(ppDevices[gotten], &MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, wSymLink, CAMERA_DATA_STRING_SIZE, &sz); + hr = ppDevices[gotten]->lpVtbl->GetString( + ppDevices[gotten], + &MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, + wSymLink, + CAMERA_DATA_STRING_SIZE, + &sz); + if (FAILED(hr)) { log_info("GetString failed: %ld", hr); goto done; } + log_info("Detected webcam: %s\n", buffer); wcstombs(buffer, wSymLink, bsz); ++gotten; @@ -534,13 +562,16 @@ done: ppDevices[i]->lpVtbl->Release(ppDevices[i]); } } + CoTaskMemFree(ppDevices); return buffer; } -bool convert_sym_to_path(const char* sym, char* path) { +bool convert_sym_to_path(const char *sym, char *path) +{ HDEVINFO DeviceInfoSet = SetupDiCreateDeviceInfoList(NULL, NULL); + if (DeviceInfoSet == INVALID_HANDLE_VALUE) { log_info("Could not open SetupDiCreateDeviceInfoList\n"); return 0; @@ -549,7 +580,8 @@ bool convert_sym_to_path(const char* sym, char* path) { SP_DEVICE_INTERFACE_DATA DeviceInterfaceData = {0}; DeviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); - if (!SetupDiOpenDeviceInterfaceA(DeviceInfoSet, sym, 0, &DeviceInterfaceData)) { + if (!SetupDiOpenDeviceInterfaceA( + DeviceInfoSet, sym, 0, &DeviceInterfaceData)) { log_info("Could not SetupDiOpenDeviceInterfaceA\n"); return 0; } @@ -557,7 +589,13 @@ bool convert_sym_to_path(const char* sym, char* path) { SP_DEVINFO_DATA DeviceInfoData = {0}; DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA); - if (!SetupDiGetDeviceInterfaceDetailA(DeviceInfoSet, &DeviceInterfaceData, NULL, 0, NULL, &DeviceInfoData)) { + if (!SetupDiGetDeviceInterfaceDetailA( + DeviceInfoSet, + &DeviceInterfaceData, + NULL, + 0, + NULL, + &DeviceInfoData)) { if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { log_info("Could not SetupDiGetDeviceInterfaceDetailA\n"); return 0; @@ -565,35 +603,52 @@ bool convert_sym_to_path(const char* sym, char* path) { } DWORD sz; - if (!SetupDiGetDeviceInstanceIdA(DeviceInfoSet, &DeviceInfoData, path, CAMERA_DATA_STRING_SIZE, &sz)){ + + if (!SetupDiGetDeviceInstanceIdA( + DeviceInfoSet, + &DeviceInfoData, + path, + CAMERA_DATA_STRING_SIZE, + &sz)) { log_info("Could not SetupDiGetDeviceInstanceIdA\n"); return 0; } - if (DeviceInfoSet != INVALID_HANDLE_VALUE){ - if (!SetupDiDeleteDeviceInterfaceData(DeviceInfoSet, &DeviceInterfaceData)){ + if (DeviceInfoSet != INVALID_HANDLE_VALUE) { + if (!SetupDiDeleteDeviceInterfaceData( + DeviceInfoSet, &DeviceInterfaceData)) { log_info("Could not SetupDiDeleteDeviceInterfaceData\n"); return 0; } + SetupDiDestroyDeviceInfoList(DeviceInfoSet); } return 1; } -void strtolower(char* str) { - for (size_t i = 0; str[i]; i++){ +void strtolower(char *str) +{ + for (size_t i = 0; str[i]; i++) { str[i] = tolower(str[i]); } } -bool convert_path_to_fakesym(const char* path, wchar_t* sym, char* extra_o) { +bool convert_path_to_fakesym(const char *path, wchar_t *sym, char *extra_o) +{ char root[16] = {0}; char vidstr[16] = {0}; char pidstr[16] = {0}; char mistr[16] = {0}; char extra[64] = {0}; - sscanf(path, "%[^\\]\\%[^&]&%[^&]&%[^\\]\\%s", root, vidstr, pidstr, mistr, extra); + sscanf( + path, + "%[^\\]\\%[^&]&%[^&]&%[^\\]\\%s", + root, + vidstr, + pidstr, + mistr, + extra); strcpy(extra_o, extra); strtolower(root); @@ -602,19 +657,29 @@ bool convert_path_to_fakesym(const char* path, wchar_t* sym, char* extra_o) { strtolower(mistr); strtolower(extra); - swprintf(sym, CAMERA_DATA_STRING_SIZE, L"\\\\?\\%S#%S&%S&%S#%S", root, vidstr, pidstr, mistr, extra); + swprintf( + sym, + CAMERA_DATA_STRING_SIZE, + L"\\\\?\\%S#%S&%S&%S#%S", + root, + vidstr, + pidstr, + mistr, + extra); return true; } -void fill_cam_struct(struct CameraData* data, const char* devid) +void fill_cam_struct(struct CameraData *data, const char *devid) { char buffer[CAMERA_DATA_STRING_SIZE]; data->setup = false; + if (!devid || strlen(devid) == 0) { devid = grab_next_camera_id(buffer, CAMERA_DATA_STRING_SIZE); } + if (!devid || strlen(devid) == 0) { // no more cameras remain? return; @@ -624,10 +689,11 @@ void fill_cam_struct(struct CameraData* data, const char* devid) // error probably log something? return; } + // detect input type if (check_four(devid, "\\\\?\\")) { // SYMBOLIC_LINK - if (!convert_sym_to_path(devid, data->deviceInstancePath)){ + if (!convert_sym_to_path(devid, data->deviceInstancePath)) { log_info("Could not convert %s to path", devid); return; } @@ -642,30 +708,38 @@ void fill_cam_struct(struct CameraData* data, const char* devid) return; } - if (!convert_path_to_fakesym(data->deviceInstancePath, data->deviceSymbolicLink, data->extra_upper)){ + if (!convert_path_to_fakesym( + data->deviceInstancePath, + data->deviceSymbolicLink, + data->extra_upper)) { log_info("Could not convert %s to sym", data->deviceInstancePath); return; } - log_info("dev path: %s", data->deviceInstancePath); + log_info("dev path: %s", data->deviceInstancePath); // locate device nodes DEVINST dnDevInst; DEVINST parentDev; CONFIGRET cmret; - cmret = CM_Locate_DevNodeA(&dnDevInst, data->deviceInstancePath, CM_LOCATE_DEVNODE_NORMAL); + cmret = CM_Locate_DevNodeA( + &dnDevInst, data->deviceInstancePath, CM_LOCATE_DEVNODE_NORMAL); + if (cmret != CR_SUCCESS) { log_info("CM_Locate_DevNodeA fail: %s", data->deviceInstancePath); return; } cmret = CM_Get_Parent(&parentDev, dnDevInst, 0); + if (cmret != CR_SUCCESS) { log_info("CM_Get_Parent fail: %s", data->deviceInstancePath); return; } - cmret = CM_Get_Device_IDA(parentDev, data->parent_deviceInstancePath, CAMERA_DATA_STRING_SIZE, 0); + cmret = CM_Get_Device_IDA( + parentDev, data->parent_deviceInstancePath, CAMERA_DATA_STRING_SIZE, 0); + if (cmret != CR_SUCCESS) { log_info("CM_Get_Device_IDA parent fail: %s", data->deviceInstancePath); return; @@ -676,27 +750,45 @@ void fill_cam_struct(struct CameraData* data, const char* devid) szAddr = 4; szDesc = CAMERA_DATA_STRING_SIZE; - cmret = CM_Get_DevNode_Registry_PropertyA(dnDevInst, CM_DRP_ADDRESS, NULL, &data->address, &szAddr, 0); + cmret = CM_Get_DevNode_Registry_PropertyA( + dnDevInst, CM_DRP_ADDRESS, NULL, &data->address, &szAddr, 0); + if (cmret != CR_SUCCESS) { - log_info("CM_Get_DevNode_Registry_PropertyA fail: %s", data->deviceInstancePath); + log_info( + "CM_Get_DevNode_Registry_PropertyA fail: %s", + data->deviceInstancePath); return; } - cmret = CM_Get_DevNode_Registry_PropertyA(dnDevInst, CM_DRP_DEVICEDESC, NULL, &data->name, &szDesc, 0); + + cmret = CM_Get_DevNode_Registry_PropertyA( + dnDevInst, CM_DRP_DEVICEDESC, NULL, &data->name, &szDesc, 0); + if (cmret != CR_SUCCESS) { - log_info("CM_Get_DevNode_Registry_PropertyA fail: %s", data->deviceInstancePath); + log_info( + "CM_Get_DevNode_Registry_PropertyA fail: %s", + data->deviceInstancePath); return; } szAddr = 4; szDesc = CAMERA_DATA_STRING_SIZE; - cmret = CM_Get_DevNode_Registry_PropertyA(parentDev, CM_DRP_ADDRESS, NULL, &data->parent_address, &szAddr, 0); + cmret = CM_Get_DevNode_Registry_PropertyA( + parentDev, CM_DRP_ADDRESS, NULL, &data->parent_address, &szAddr, 0); + if (cmret != CR_SUCCESS) { - log_info("CM_Get_DevNode_Registry_PropertyA parent fail: %s", data->deviceInstancePath); + log_info( + "CM_Get_DevNode_Registry_PropertyA parent fail: %s", + data->deviceInstancePath); return; } - cmret = CM_Get_DevNode_Registry_PropertyA(parentDev, CM_DRP_DEVICEDESC, NULL, &data->parent_name, &szDesc, 0); + + cmret = CM_Get_DevNode_Registry_PropertyA( + parentDev, CM_DRP_DEVICEDESC, NULL, &data->parent_name, &szDesc, 0); + if (cmret != CR_SUCCESS) { - log_info("CM_Get_DevNode_Registry_PropertyA parent fail: %s", data->deviceInstancePath); + log_info( + "CM_Get_DevNode_Registry_PropertyA parent fail: %s", + data->deviceInstancePath); return; } @@ -705,7 +797,7 @@ void fill_cam_struct(struct CameraData* data, const char* devid) data->setup = true; } -void cam_hook_init(const char* devID1, const char* devID2) +void cam_hook_init(const char *devID1, const char *devID2) { // fill before applying hooks fill_cam_struct(&camData[0], devID1); @@ -713,19 +805,15 @@ void cam_hook_init(const char* devID1, const char* devID2) if (camData[0].setup || camData[1].setup) { hook_table_apply( - NULL, - "setupapi.dll", - iidxhook5_cfgmgr32_syms, - lengthof(iidxhook5_cfgmgr32_syms)); + NULL, + "setupapi.dll", + iidxhook5_cfgmgr32_syms, + lengthof(iidxhook5_cfgmgr32_syms)); hook_table_apply( - NULL, - "Mf.dll", - iidxhook5_mf_syms, - lengthof(iidxhook5_mf_syms)); + NULL, "Mf.dll", iidxhook5_mf_syms, lengthof(iidxhook5_mf_syms)); log_info("Inserted cam hooks"); } else { log_info("No cams detected, not hooking"); } } - diff --git a/src/main/iidxhook8/cam.h b/src/main/iidxhook8/cam.h index a7d0e1e..1b74d73 100644 --- a/src/main/iidxhook8/cam.h +++ b/src/main/iidxhook8/cam.h @@ -1,6 +1,6 @@ #ifndef IIDXHOOK5_CAM_H #define IIDXHOOK5_CAM_H -void cam_hook_init(const char* devID1, const char* devID2); +void cam_hook_init(const char *devID1, const char *devID2); #endif diff --git a/src/main/iidxhook8/config-cam.c b/src/main/iidxhook8/config-cam.c index 10d2650..e570196 100644 --- a/src/main/iidxhook8/config-cam.c +++ b/src/main/iidxhook8/config-cam.c @@ -12,50 +12,67 @@ #define IIDXHOOK8_CONFIG_CAM_DEFAULT_DEVICE_ID1_VALUE "" #define IIDXHOOK8_CONFIG_CAM_DEFAULT_DEVICE_ID2_VALUE "" -void iidxhook8_config_cam_init(struct cconfig* config) +void iidxhook8_config_cam_init(struct cconfig *config) { - cconfig_util_set_bool(config, + cconfig_util_set_bool( + config, IIDXHOOK8_CONFIG_CAM_DISABLE_EMU_KEY, IIDXHOOK8_CONFIG_CAM_DEFAULT_DISABLE_EMU_VALUE, "Disables the camera emulation"); - cconfig_util_set_str(config, + cconfig_util_set_str( + config, IIDXHOOK8_CONFIG_CAM_DEVICE_ID1_KEY, IIDXHOOK8_CONFIG_CAM_DEFAULT_DEVICE_ID1_VALUE, - "Override camera device ID 1 detection (copy from device manager, do " - "not escape)"); + "Override camera device ID 1 detection (copy from device manager, " + "do not escape)"); - cconfig_util_set_str(config, + cconfig_util_set_str( + config, IIDXHOOK8_CONFIG_CAM_DEVICE_ID2_KEY, IIDXHOOK8_CONFIG_CAM_DEFAULT_DEVICE_ID2_VALUE, - "Override camera device ID 2 detection (copy from device manager, do " - "not escape)"); + "Override camera device ID 2 detection (copy from device manager, " + "do not escape)"); } -void iidxhook8_config_cam_get(struct iidxhook8_config_cam* config_cam, - struct cconfig* config) +void iidxhook8_config_cam_get( + struct iidxhook8_config_cam *config_cam, struct cconfig *config) { - if (!cconfig_util_get_bool(config, IIDXHOOK8_CONFIG_CAM_DISABLE_EMU_KEY, + if (!cconfig_util_get_bool( + config, + IIDXHOOK8_CONFIG_CAM_DISABLE_EMU_KEY, &config_cam->disable_emu, IIDXHOOK8_CONFIG_CAM_DEFAULT_DISABLE_EMU_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%d'", IIDXHOOK8_CONFIG_CAM_DISABLE_EMU_KEY, + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%d'", + IIDXHOOK8_CONFIG_CAM_DISABLE_EMU_KEY, IIDXHOOK8_CONFIG_CAM_DEFAULT_DISABLE_EMU_VALUE); } - if (!cconfig_util_get_str(config, IIDXHOOK8_CONFIG_CAM_DEVICE_ID1_KEY, - config_cam->device_id1, sizeof(config_cam->device_id1) - 1, + if (!cconfig_util_get_str( + config, + IIDXHOOK8_CONFIG_CAM_DEVICE_ID1_KEY, + config_cam->device_id1, + sizeof(config_cam->device_id1) - 1, IIDXHOOK8_CONFIG_CAM_DEFAULT_DEVICE_ID1_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%s'", IIDXHOOK8_CONFIG_CAM_DEVICE_ID1_KEY, + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%s'", + IIDXHOOK8_CONFIG_CAM_DEVICE_ID1_KEY, IIDXHOOK8_CONFIG_CAM_DEFAULT_DEVICE_ID1_VALUE); } - if (!cconfig_util_get_str(config, IIDXHOOK8_CONFIG_CAM_DEVICE_ID2_KEY, - config_cam->device_id2, sizeof(config_cam->device_id2) - 1, + if (!cconfig_util_get_str( + config, + IIDXHOOK8_CONFIG_CAM_DEVICE_ID2_KEY, + config_cam->device_id2, + sizeof(config_cam->device_id2) - 1, IIDXHOOK8_CONFIG_CAM_DEFAULT_DEVICE_ID2_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%s'", IIDXHOOK8_CONFIG_CAM_DEVICE_ID2_KEY, + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%s'", + IIDXHOOK8_CONFIG_CAM_DEVICE_ID2_KEY, IIDXHOOK8_CONFIG_CAM_DEFAULT_DEVICE_ID2_VALUE); } } diff --git a/src/main/iidxhook8/config-cam.h b/src/main/iidxhook8/config-cam.h index 7251aee..86eec2b 100644 --- a/src/main/iidxhook8/config-cam.h +++ b/src/main/iidxhook8/config-cam.h @@ -11,9 +11,9 @@ struct iidxhook8_config_cam { char device_id2[MAX_PATH]; }; -void iidxhook8_config_cam_init(struct cconfig* config); +void iidxhook8_config_cam_init(struct cconfig *config); -void iidxhook8_config_cam_get(struct iidxhook8_config_cam* config_cam, - struct cconfig* config); +void iidxhook8_config_cam_get( + struct iidxhook8_config_cam *config_cam, struct cconfig *config); #endif \ No newline at end of file diff --git a/src/main/iidxhook8/config-io.c b/src/main/iidxhook8/config-io.c index 3fc97cd..22dc704 100644 --- a/src/main/iidxhook8/config-io.c +++ b/src/main/iidxhook8/config-io.c @@ -4,60 +4,74 @@ #include "util/log.h" -#define IIDXHOOK8_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY "io.disable_card_reader_emu" +#define IIDXHOOK8_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY \ + "io.disable_card_reader_emu" #define IIDXHOOK8_CONFIG_IO_DISABLE_BIO2_EMU_KEY "io.disable_bio2_emu" #define IIDXHOOK8_CONFIG_IO_DISABLE_POLL_LIMITER_KEY "io.disable_poll_limiter" #define IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_CARD_READER_EMU_VALUE false -#define IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_BIO2_EMU_VALUE false +#define IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_BIO2_EMU_VALUE false #define IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_POLL_LIMITER_VALUE false -void iidxhook8_config_io_init(struct cconfig* config) +void iidxhook8_config_io_init(struct cconfig *config) { - cconfig_util_set_bool(config, + cconfig_util_set_bool( + config, IIDXHOOK8_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY, IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_CARD_READER_EMU_VALUE, - "Disable card reader emulation and enable usage of real card reader " + "Disable card reader emulation and enable usage of real card " + "reader " "hardware on COM0 (for games supporting slotted readers)"); - cconfig_util_set_bool(config, + cconfig_util_set_bool( + config, IIDXHOOK8_CONFIG_IO_DISABLE_BIO2_EMU_KEY, IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_BIO2_EMU_VALUE, "Disable BIO2 emulation and enable usage of real BIO2 hardware"); - cconfig_util_set_bool(config, + cconfig_util_set_bool( + config, IIDXHOOK8_CONFIG_IO_DISABLE_POLL_LIMITER_KEY, IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_POLL_LIMITER_VALUE, "Disables the poll limiter, warning very high CPU usage may arise"); } -void iidxhook8_config_io_get(struct iidxhook8_config_io* config_io, - struct cconfig* config) +void iidxhook8_config_io_get( + struct iidxhook8_config_io *config_io, struct cconfig *config) { - if (!cconfig_util_get_bool(config, + if (!cconfig_util_get_bool( + config, IIDXHOOK8_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY, &config_io->disable_card_reader_emu, IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_CARD_READER_EMU_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%d'", IIDXHOOK8_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY, + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%d'", + IIDXHOOK8_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY, IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_CARD_READER_EMU_VALUE); } - if (!cconfig_util_get_bool(config, + if (!cconfig_util_get_bool( + config, IIDXHOOK8_CONFIG_IO_DISABLE_BIO2_EMU_KEY, &config_io->disable_bio2_emu, IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_BIO2_EMU_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%d'", IIDXHOOK8_CONFIG_IO_DISABLE_BIO2_EMU_KEY, + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%d'", + IIDXHOOK8_CONFIG_IO_DISABLE_BIO2_EMU_KEY, IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_BIO2_EMU_VALUE); } - if (!cconfig_util_get_bool(config, + if (!cconfig_util_get_bool( + config, IIDXHOOK8_CONFIG_IO_DISABLE_POLL_LIMITER_KEY, &config_io->disable_poll_limiter, IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_POLL_LIMITER_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%d'", IIDXHOOK8_CONFIG_IO_DISABLE_POLL_LIMITER_KEY, + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%d'", + IIDXHOOK8_CONFIG_IO_DISABLE_POLL_LIMITER_KEY, IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_POLL_LIMITER_VALUE); } } diff --git a/src/main/iidxhook8/config-io.h b/src/main/iidxhook8/config-io.h index 52b8957..beaf6e4 100644 --- a/src/main/iidxhook8/config-io.h +++ b/src/main/iidxhook8/config-io.h @@ -11,9 +11,9 @@ struct iidxhook8_config_io { bool disable_poll_limiter; }; -void iidxhook8_config_io_init(struct cconfig* config); +void iidxhook8_config_io_init(struct cconfig *config); -void iidxhook8_config_io_get(struct iidxhook8_config_io* config_io, - struct cconfig* config); +void iidxhook8_config_io_get( + struct iidxhook8_config_io *config_io, struct cconfig *config); #endif \ No newline at end of file diff --git a/src/main/iidxhook8/dllmain.c b/src/main/iidxhook8/dllmain.c index dbbb526..7ff635b 100644 --- a/src/main/iidxhook8/dllmain.c +++ b/src/main/iidxhook8/dllmain.c @@ -1,8 +1,8 @@ #include #include -#include #include +#include #include #include "bemanitools/eamio.h" @@ -29,7 +29,6 @@ #include "iidxhook8/cam.h" #include "iidxhook8/config-cam.h" #include "iidxhook8/config-io.h" -#include "iidxhook8/cam.h" #include "imports/avs.h" @@ -37,7 +36,7 @@ #include "util/str.h" #include "util/thread.h" -#define IIDXHOOK8_INFO_HEADER \ +#define IIDXHOOK8_INFO_HEADER \ "iidxhook for Cannon Ballers" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) "\n" #define IIDXHOOK8_CMD_USAGE \ @@ -52,7 +51,8 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { iidxhook_util_d3d9_irp_handler, }; -static void iidxhook8_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_gfx) +static void +iidxhook8_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) { struct iidxhook_util_d3d9_config d3d9_config; @@ -84,8 +84,8 @@ static struct bio2emu_port bio2_emu = { static bool my_dll_entry_init(char *sidcode, struct property_node *param) { - struct cconfig* config; - + struct cconfig *config; + struct iidxhook_config_gfx config_gfx; struct iidxhook8_config_cam config_cam; @@ -102,7 +102,10 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) iidxhook8_config_cam_init(config); iidxhook8_config_io_init(config); - if (!cconfig_hook_config_init(config, IIDXHOOK8_INFO_HEADER "\n" IIDXHOOK8_CMD_USAGE, CCONFIG_CMD_USAGE_OUT_DBG)) { + if (!cconfig_hook_config_init( + config, + IIDXHOOK8_INFO_HEADER "\n" IIDXHOOK8_CMD_USAGE, + CCONFIG_CMD_USAGE_OUT_DBG)) { cconfig_finit(config); log_server_fini(); exit(EXIT_FAILURE); @@ -122,10 +125,11 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) /* Start up IIDXIO.DLL */ if (!iidxhook8_config_io.disable_bio2_emu) { log_info("Starting IIDX IO backend"); - iidx_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning, - log_impl_fatal); + 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"); } } @@ -133,15 +137,17 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) /* Start up EAMIO.DLL */ if (!iidxhook8_config_io.disable_card_reader_emu) { log_misc("Initializing card reader backend"); - eam_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning, - log_impl_fatal); + 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"); } } - /* iohooks are okay, even if emu is diabled since the fake handlers won't be used */ + /* iohooks are okay, even if emu is diabled since the fake handlers won't be + * used */ /* Set up IO emulation hooks _after_ IO API setup to allow API implementations with real IO devices */ iohook_init(iidxhook_handlers, lengthof(iidxhook_handlers)); @@ -200,10 +206,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) } log_to_external( - log_body_misc, - log_body_info, - log_body_warning, - log_body_fatal); + log_body_misc, log_body_info, log_body_warning, log_body_fatal); app_hook_init(my_dll_entry_init, my_dll_entry_main); @@ -213,4 +216,3 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) end: return TRUE; } - diff --git a/src/main/iidxio-ezusb/iidxio.c b/src/main/iidxio-ezusb/iidxio.c index 0b595dc..a029853 100644 --- a/src/main/iidxio-ezusb/iidxio.c +++ b/src/main/iidxio-ezusb/iidxio.c @@ -1,5 +1,5 @@ -#include #include +#include #include #include @@ -33,8 +33,11 @@ static struct ezusb_iidx_msg_interrupt_read_packet iidx_io_ezusb_read_packet; static struct ezusb_iidx_msg_interrupt_write_packet iidx_io_ezusb_write_packet; static bool iidxio_io_ezusb_16seg_rts; -void iidx_io_set_loggers(log_formatter_t misc, log_formatter_t info, - log_formatter_t warning, log_formatter_t fatal) +void iidx_io_set_loggers( + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal) { iidx_io_log_misc = misc; iidx_io_log_info = info; @@ -42,14 +45,17 @@ void iidx_io_set_loggers(log_formatter_t misc, log_formatter_t info, iidx_io_log_fatal = fatal; } -bool iidx_io_init(thread_create_t thread_create, thread_join_t thread_join, - thread_destroy_t thread_destroy) +bool iidx_io_init( + thread_create_t thread_create, + thread_join_t thread_join, + thread_destroy_t thread_destroy) { struct ezusb_ident ident; iidxio_io_ezusb_16seg_rts = false; - log_info("!!! IMPORTANT: Ensure that you have flashed the correct firmware " + log_info( + "!!! IMPORTANT: Ensure that you have flashed the correct firmware " "to your hardware and the FPGA BEFORE running this !!!"); log_misc("Opening device path %s...", EZUSB_DEVICE_PATH); @@ -64,8 +70,8 @@ bool iidx_io_init(thread_create_t thread_create, thread_join_t thread_join, log_fatal("Getting ezusb ident failed"); return false; } else { - log_info("Connected ezusb: vid 0x%X, pid 0x%X", ident.vid, - ident.pid); + log_info( + "Connected ezusb: vid 0x%X, pid 0x%X", ident.vid, ident.pid); return true; } } @@ -113,9 +119,14 @@ bool iidx_io_ep1_send(void) transfer.pipeNum = EZUSB_IIDX_MSG_PIPE_INTERRUPT_OUT; - if (!ezusb_iidx_ioctl(iidx_io_ezusb_handle, IOCTL_EZUSB_BULK_WRITE, - &transfer, sizeof(transfer), &iidx_io_ezusb_write_packet, - sizeof(iidx_io_ezusb_write_packet), &outpkt)) { + if (!ezusb_iidx_ioctl( + iidx_io_ezusb_handle, + IOCTL_EZUSB_BULK_WRITE, + &transfer, + sizeof(transfer), + &iidx_io_ezusb_write_packet, + sizeof(iidx_io_ezusb_write_packet), + &outpkt)) { log_fatal("Failed to write interrupt endpoint of ezusb"); return false; } else { @@ -125,17 +136,18 @@ bool iidx_io_ep1_send(void) bool iidx_io_ep2_recv(void) { - if (!ezusb_iidx_interrupt_read(iidx_io_ezusb_handle, - &iidx_io_ezusb_read_packet)) { + if (!ezusb_iidx_interrupt_read( + iidx_io_ezusb_handle, &iidx_io_ezusb_read_packet)) { log_fatal("Failed to read interrupt endpoints of ezusb"); return false; } // Wait for board to be ready to receive data on bulk endpoint - // On older Windows platforms, just writing the the 16seg bulk endpoint all the - // time was fine, probably because the driver was overall slower than on newer platforms, e.g. Windows 10. - // There, you crash the C02 firmware AND the kernel mode driver if you don't wait for the bulk endpoint - // to become ready before writing to it. + // On older Windows platforms, just writing the the 16seg bulk endpoint all + // the time was fine, probably because the driver was overall slower than on + // newer platforms, e.g. Windows 10. There, you crash the C02 firmware AND + // the kernel mode driver if you don't wait for the bulk endpoint to become + // ready before writing to it. if (iidx_io_ezusb_read_packet.status == EZUSB_IIDX_16SEG_CMD_STATUS_OK) { iidxio_io_ezusb_16seg_rts = true; } else { @@ -212,4 +224,3 @@ bool iidx_io_ep3_write_16seg(const char *text) return true; } - diff --git a/src/main/iidxio-ezusb2/iidxio.c b/src/main/iidxio-ezusb2/iidxio.c index f5aa698..e629272 100644 --- a/src/main/iidxio-ezusb2/iidxio.c +++ b/src/main/iidxio-ezusb2/iidxio.c @@ -27,10 +27,14 @@ static log_formatter_t iidx_io_log_fatal; static HANDLE iidx_io_ezusb2_handle; static struct ezusb2_iidx_msg_interrupt_read_packet iidx_io_ezusb2_read_packet; -static struct ezusb2_iidx_msg_interrupt_write_packet iidx_io_ezusb2_write_packet; +static struct ezusb2_iidx_msg_interrupt_write_packet + iidx_io_ezusb2_write_packet; -void iidx_io_set_loggers(log_formatter_t misc, log_formatter_t info, - log_formatter_t warning, log_formatter_t fatal) +void iidx_io_set_loggers( + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal) { iidx_io_log_misc = misc; iidx_io_log_info = info; @@ -38,14 +42,17 @@ void iidx_io_set_loggers(log_formatter_t misc, log_formatter_t info, iidx_io_log_fatal = fatal; } -bool iidx_io_init(thread_create_t thread_create, thread_join_t thread_join, - thread_destroy_t thread_destroy) +bool iidx_io_init( + thread_create_t thread_create, + thread_join_t thread_join, + thread_destroy_t thread_destroy) { struct ezusb_ident ident; - char* device_path; + char *device_path; uint64_t time_start; - log_info("!!! IMPORTANT: Ensure that you have flashed the correct firmware " + log_info( + "!!! IMPORTANT: Ensure that you have flashed the correct firmware " "to your hardware BEFORE running this !!!"); log_misc("Finding connected ezusb2..."); @@ -61,8 +68,8 @@ bool iidx_io_init(thread_create_t thread_create, thread_join_t thread_join, log_misc("Failed to find connected ezusb2 device, retry..."); Sleep(1000); - } while (time_get_elapsed_ms(time_get_counter() - time_start) < - EZUSB2_FIND_TIMEOUT_MS); + } while (time_get_elapsed_ms(time_get_counter() - time_start) < + EZUSB2_FIND_TIMEOUT_MS); if (!device_path) { log_fatal("Could not find a connected ezusb2 device"); @@ -83,8 +90,11 @@ bool iidx_io_init(thread_create_t thread_create, thread_join_t thread_join, log_fatal("Getting ezusb2 ident failed"); return false; } else { - log_info("Connected ezusb2: name %s, vid 0x%X, pid 0x%X", - ident.name, ident.vid, ident.pid); + log_info( + "Connected ezusb2: name %s, vid 0x%X, pid 0x%X", + ident.name, + ident.vid, + ident.pid); return true; } } @@ -122,8 +132,8 @@ void iidx_io_ep1_set_top_neons(bool top_neons) bool iidx_io_ep1_send(void) { - if (!ezusb2_iidx_interrupt_write(iidx_io_ezusb2_handle, - &iidx_io_ezusb2_write_packet)) { + if (!ezusb2_iidx_interrupt_write( + iidx_io_ezusb2_handle, &iidx_io_ezusb2_write_packet)) { log_fatal("Failed to write interrupt endpoint of ezusb"); return false; } else { @@ -133,8 +143,8 @@ bool iidx_io_ep1_send(void) bool iidx_io_ep2_recv(void) { - if (!ezusb2_iidx_interrupt_read(iidx_io_ezusb2_handle, - &iidx_io_ezusb2_read_packet)) { + if (!ezusb2_iidx_interrupt_read( + iidx_io_ezusb2_handle, &iidx_io_ezusb2_read_packet)) { log_fatal("Failed to read interrupt endpoint of ezusb"); return false; } else { @@ -174,7 +184,7 @@ uint8_t iidx_io_ep2_get_slider(uint8_t slider_no) uint8_t iidx_io_ep2_get_sys(void) { - return (((~iidx_io_ezusb2_read_packet.inverted_pad) >> 4) & 0x03) | + return (((~iidx_io_ezusb2_read_packet.inverted_pad) >> 4) & 0x03) | ((((~iidx_io_ezusb2_read_packet.inverted_pad) >> 30) & 1) << 2); } @@ -194,4 +204,3 @@ bool iidx_io_ep3_write_16seg(const char *text) memcpy(iidx_io_ezusb2_write_packet.seg16, text, 9); return true; } - diff --git a/src/main/iidxio/iidxio.c b/src/main/iidxio/iidxio.c index 90a637d..96e0e73 100644 --- a/src/main/iidxio/iidxio.c +++ b/src/main/iidxio/iidxio.c @@ -8,17 +8,17 @@ the "bemanitools" header files included by this source file for detailed information about the API you'll need to implement. */ -#include #include +#include #include #include #include "bemanitools/iidxio.h" -#include "bemanitools/vefxio.h" #include "bemanitools/input.h" +#include "bemanitools/vefxio.h" -#define MSEC_PER_NOTCH 8 +#define MSEC_PER_NOTCH 8 enum iidx_io_pad_bit { /* Synthetic inputs stuffed into unused bits in the pad word. @@ -79,8 +79,14 @@ struct iidx_io_tt { static void iidx_io_tt_update(uint32_t now, uint64_t pad, int i); static const struct iidx_io_tt_inputs iidx_io_tt_inputs[2] = { -{ IIDX_IO_P1_TT_UP, IIDX_IO_P1_TT_DOWN, IIDX_IO_P1_TT_STAB, IIDX_IO_P1_START }, -{ IIDX_IO_P2_TT_UP, IIDX_IO_P2_TT_DOWN, IIDX_IO_P2_TT_STAB, IIDX_IO_P2_START }, + {IIDX_IO_P1_TT_UP, + IIDX_IO_P1_TT_DOWN, + IIDX_IO_P1_TT_STAB, + IIDX_IO_P1_START}, + {IIDX_IO_P2_TT_UP, + IIDX_IO_P2_TT_DOWN, + IIDX_IO_P2_TT_STAB, + IIDX_IO_P2_START}, }; static struct iidx_io_tt iidx_io_tt[2]; @@ -97,8 +103,11 @@ static log_formatter_t iidx_io_log_warning; static log_formatter_t iidx_io_log_fatal; #endif -void iidx_io_set_loggers(log_formatter_t misc, log_formatter_t info, - log_formatter_t warning, log_formatter_t fatal) +void iidx_io_set_loggers( + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal) { /* Pass logger functions on to geninput so that it has somewhere to write its own log output. */ @@ -123,8 +132,10 @@ void iidx_io_set_loggers(log_formatter_t misc, log_formatter_t info, #endif } -bool iidx_io_init(thread_create_t thread_create, thread_join_t thread_join, - thread_destroy_t thread_destroy) +bool iidx_io_init( + thread_create_t thread_create, + thread_join_t thread_join, + thread_destroy_t thread_destroy) { vefx_io_init(thread_create, thread_join, thread_destroy); timeBeginPeriod(1); @@ -159,7 +170,7 @@ void iidx_io_ep1_set_deck_lights(uint16_t deck_lights) { uint8_t i; - for (i = 0x00 ; i < 0x0E ; i++) { + for (i = 0x00; i < 0x0E; i++) { mapper_write_light(i, deck_lights & (1 << i) ? 255 : 0); } } @@ -168,7 +179,7 @@ void iidx_io_ep1_set_panel_lights(uint8_t panel_lights) { uint8_t i; - for (i = 0x00 ; i < 0x04 ; i++) { + for (i = 0x00; i < 0x04; i++) { mapper_write_light(0x18 + i, panel_lights & (1 << i) ? 255 : 0); } } @@ -177,7 +188,7 @@ void iidx_io_ep1_set_top_lamps(uint8_t top_lamps) { uint8_t i; - for (i = 0x00 ; i < 0x08 ; i++) { + for (i = 0x00; i < 0x08; i++) { mapper_write_light(0x10 + i, top_lamps & (1 << i) ? 255 : 0); } } @@ -209,11 +220,10 @@ bool iidx_io_ep2_recv(void) pad = (uint64_t) mapper_update(); vefx_io_recv(&pad); - for (i = 0 ; i < 2 ; i++) { + for (i = 0; i < 2; i++) { iidx_io_tt_update(now, pad, i); } - /* Mask out the stuff provided by geninput and store the pad state for later retrieval via iidx_io_ep2_get_pad() */ @@ -315,4 +325,3 @@ bool iidx_io_ep3_write_16seg(const char *text) { return vefx_io_write_16seg(text); } - diff --git a/src/main/iidxiotest/main.c b/src/main/iidxiotest/main.c index 27858ff..45720eb 100644 --- a/src/main/iidxiotest/main.c +++ b/src/main/iidxiotest/main.c @@ -1,6 +1,6 @@ -#include #include #include +#include #include #include @@ -13,12 +13,12 @@ /** * Tool to test your implementations of iidxio. */ -int main(int argc, char** argv) +int main(int argc, char **argv) { log_to_writer(log_writer_stdout, NULL); - iidx_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning, - log_impl_fatal); + iidx_io_set_loggers( + log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); if (!iidx_io_init(crt_thread_create, crt_thread_join, crt_thread_destroy)) { printf("Initializing iidxio failed\n"); @@ -49,7 +49,6 @@ int main(int argc, char** argv) uint8_t cnt = 0; bool all_on = false; while (loop) { - if (!iidx_io_ep2_recv()) { printf("ERROR: Receive ep2 failed\n"); return -2; @@ -67,71 +66,78 @@ int main(int argc, char** argv) system("cls"); printf( - "Press escape to open menu\n" - "%d\n" - "|---------------------------------------|\n" - "| R Y G B Neons B G Y R |\n" - "| %d %d %d %d %d %d %d %d %d |\n" - "|---------------------------------------|\n" - "| NOW PLAYING: %c%c%c%c%c%c%c%c%c |\n" - "|---------------------------------------|\n" - "| Effect %d S1 S2 S3 S4 S5 Test %d|\n" - "|StartP1 %d %02d %02d %02d %02d %02d StartP2 %d|\n" - "| VEFX %d Service %d|\n" - "_________________________________________\n" - "| __ __ |\n" - "| / \\ _ / \\ |\n" - "| | %03d| %d %d %d |%d| %d %d %d | %03d| |\n" - "| \\___/ %d %d %d %d |_| %d %d %d %d \\___/ |\n" - "| |\n" - "|---------------------------------------|\n" - "|---------------------------------------|\n", - cnt, + "Press escape to open menu\n" + "%d\n" + "|---------------------------------------|\n" + "| R Y G B Neons B G Y R |\n" + "| %d %d %d %d %d %d %d %d %d |\n" + "|---------------------------------------|\n" + "| NOW PLAYING: %c%c%c%c%c%c%c%c%c |\n" + "|---------------------------------------|\n" + "| Effect %d S1 S2 S3 S4 S5 Test %d|\n" + "|StartP1 %d %02d %02d %02d %02d %02d StartP2 %d|\n" + "| VEFX %d Service %d|\n" + "_________________________________________\n" + "| __ __ |\n" + "| / \\ _ / \\ |\n" + "| | %03d| %d %d %d |%d| %d %d %d | %03d| |\n" + "| \\___/ %d %d %d %d |_| %d %d %d %d \\___/ |\n" + "| |\n" + "|---------------------------------------|\n" + "|---------------------------------------|\n", + cnt, - (top_lamps & (1 << 0)) > 0, - (top_lamps & (1 << 1)) > 0, - (top_lamps & (1 << 2)) > 0, - (top_lamps & (1 << 3)) > 0, - top_neons, - (top_lamps & (1 << 4)) > 0, - (top_lamps & (1 << 5)) > 0, - (top_lamps & (1 << 6)) > 0, - (top_lamps & (1 << 7)) > 0, + (top_lamps & (1 << 0)) > 0, + (top_lamps & (1 << 1)) > 0, + (top_lamps & (1 << 2)) > 0, + (top_lamps & (1 << 3)) > 0, + top_neons, + (top_lamps & (1 << 4)) > 0, + (top_lamps & (1 << 5)) > 0, + (top_lamps & (1 << 6)) > 0, + (top_lamps & (1 << 7)) > 0, - text_16seg[0], text_16seg[1], text_16seg[2], text_16seg[3], text_16seg[4], - text_16seg[5], text_16seg[6], text_16seg[7], text_16seg[8], - (input_panel >> IIDX_IO_PANEL_EFFECT) & 1, - (input_sys >> IIDX_IO_SYS_TEST) & 1, + text_16seg[0], + text_16seg[1], + text_16seg[2], + text_16seg[3], + text_16seg[4], + text_16seg[5], + text_16seg[6], + text_16seg[7], + text_16seg[8], + (input_panel >> IIDX_IO_PANEL_EFFECT) & 1, + (input_sys >> IIDX_IO_SYS_TEST) & 1, - (input_panel >> IIDX_IO_PANEL_P1_START) & 1, - slider[0], - slider[1], - slider[2], - slider[3], - slider[4], - (input_panel >> IIDX_IO_PANEL_P2_START) & 1, + (input_panel >> IIDX_IO_PANEL_P1_START) & 1, + slider[0], + slider[1], + slider[2], + slider[3], + slider[4], + (input_panel >> IIDX_IO_PANEL_P2_START) & 1, - (input_panel >> IIDX_IO_PANEL_VEFX) & 1, - (input_sys >> IIDX_IO_SYS_SERVICE) & 1, + (input_panel >> IIDX_IO_PANEL_VEFX) & 1, + (input_sys >> IIDX_IO_SYS_SERVICE) & 1, - turn_table[0], - (input_keys >> IIDX_IO_KEY_P1_2) & 1, - (input_keys >> IIDX_IO_KEY_P1_4) & 1, - (input_keys >> IIDX_IO_KEY_P1_6) & 1, - (input_sys >> IIDX_IO_SYS_COIN), - (input_keys >> IIDX_IO_KEY_P2_2) & 1, - (input_keys >> IIDX_IO_KEY_P2_4) & 1, - (input_keys >> IIDX_IO_KEY_P2_6) & 1, - turn_table[1], - (input_keys >> IIDX_IO_KEY_P1_1) & 1, - (input_keys >> IIDX_IO_KEY_P1_3) & 1, - (input_keys >> IIDX_IO_KEY_P1_5) & 1, - (input_keys >> IIDX_IO_KEY_P1_7) & 1, + turn_table[0], + (input_keys >> IIDX_IO_KEY_P1_2) & 1, + (input_keys >> IIDX_IO_KEY_P1_4) & 1, + (input_keys >> IIDX_IO_KEY_P1_6) & 1, + (input_sys >> IIDX_IO_SYS_COIN), + (input_keys >> IIDX_IO_KEY_P2_2) & 1, + (input_keys >> IIDX_IO_KEY_P2_4) & 1, + (input_keys >> IIDX_IO_KEY_P2_6) & 1, + turn_table[1], + (input_keys >> IIDX_IO_KEY_P1_1) & 1, + (input_keys >> IIDX_IO_KEY_P1_3) & 1, + (input_keys >> IIDX_IO_KEY_P1_5) & 1, + (input_keys >> IIDX_IO_KEY_P1_7) & 1, - (input_keys >> IIDX_IO_KEY_P2_1) & 1, - (input_keys >> IIDX_IO_KEY_P2_3) & 1, - (input_keys >> IIDX_IO_KEY_P2_5) & 1, - (input_keys >> IIDX_IO_KEY_P2_7) & 1); + (input_keys >> IIDX_IO_KEY_P2_1) & 1, + (input_keys >> IIDX_IO_KEY_P2_3) & 1, + (input_keys >> IIDX_IO_KEY_P2_5) & 1, + (input_keys >> IIDX_IO_KEY_P2_7) & 1); /* set outputs */ if (all_on) { @@ -152,7 +158,6 @@ int main(int argc, char** argv) deck_lights = input_keys; panel_lights = input_panel; } else { - /* disable all on when a single button is pressed */ if (input_keys || input_panel) { all_on = false; @@ -162,7 +167,6 @@ int main(int argc, char** argv) top_neons = false; memset(text_16seg, ' ', 9); } - } if (!iidx_io_ep1_send()) { @@ -190,22 +194,22 @@ int main(int argc, char** argv) " 2: Enter text for 16seg display\n" " 3: Set neon state\n" " 4: Set top lamp state\n" - " 5: Set all outputs on (cleared by pressing any IIDX button)\n" + " 5: Set all outputs on (cleared by pressing any IIDX " + "button)\n" " 6: Clear all outputs\n" "Waiting for input: "); char c = getchar(); switch (c) { - case '1': - { + case '1': { /* one last update to turn off the lights */ iidx_io_ep1_set_deck_lights(0); iidx_io_ep1_set_panel_lights(0); iidx_io_ep1_set_top_lamps(0); iidx_io_ep1_set_top_neons(false); - if (!iidx_io_ep3_write_16seg(" ")) { - printf("ERROR: Sending ep3 failed\n"); + if (!iidx_io_ep3_write_16seg(" ")) { + printf("ERROR: Sending ep3 failed\n"); return -3; } @@ -218,8 +222,7 @@ int main(int argc, char** argv) break; } - case '2': - { + case '2': { char buf[10]; printf("Enter 16seg text (max 9 chars): "); int n = scanf("%9s", buf); @@ -238,8 +241,7 @@ int main(int argc, char** argv) break; } - case '3': - { + case '3': { int state; printf("Enter neon state (0/1): "); int n = scanf("%d", &state); @@ -251,8 +253,7 @@ int main(int argc, char** argv) break; } - case '4': - { + case '4': { char buf[9]; printf("Enter top lamp state, chain of 0/1s: "); int n = scanf("%8s", buf); @@ -269,14 +270,12 @@ int main(int argc, char** argv) break; } - case '5': - { + case '5': { all_on = true; break; } - case '6': - { + case '6': { all_on = false; break; } diff --git a/src/main/inject/main.c b/src/main/inject/main.c index b5cea0d..1a03059 100644 --- a/src/main/inject/main.c +++ b/src/main/inject/main.c @@ -16,9 +16,9 @@ #include "util/mem.h" #include "util/str.h" -static FILE* log_file = NULL; +static FILE *log_file = NULL; -static bool inject_dll(PROCESS_INFORMATION pi, const char* arg_dll); +static bool inject_dll(PROCESS_INFORMATION pi, const char *arg_dll); static bool debug(HANDLE process, uint32_t pid); static bool debug_wstr(HANDLE process, const OUTPUT_DEBUG_STRING_INFO *odsi); static bool debug_str(HANDLE process, const OUTPUT_DEBUG_STRING_INFO *odsi); @@ -49,8 +49,11 @@ int main(int argc, char **argv) log_file = fopen(options.log_file, "w+"); if (!log_file) { - fprintf(stderr, "Opening log file %s failed: %s\n", - options.log_file, strerror(errno)); + fprintf( + stderr, + "Opening log file %s failed: %s\n", + options.log_file, + strerror(errno)); goto log_file_open_fail; } @@ -83,29 +86,41 @@ int main(int argc, char **argv) } for (int i = 0; i < hooks; i++) { - dll_path_length = SearchPath(NULL, argv[i + 1], NULL, MAX_PATH, - dll_path, NULL); + dll_path_length = + SearchPath(NULL, argv[i + 1], NULL, MAX_PATH, dll_path, NULL); if (dll_path_length == 0) { - fprintf(stderr, "Hook DLL not found: %08x\n", - (unsigned int) GetLastError()); + fprintf( + stderr, + "Hook DLL not found: %08x\n", + (unsigned int) GetLastError()); goto search_fail; } } - memset(&si, 0, sizeof(si)); si.cb = sizeof(si); cmd_line = args_join(argc - exec_arg_pos, argv + exec_arg_pos); - ok = CreateProcess(argv[exec_arg_pos], cmd_line, NULL, NULL, FALSE, - CREATE_SUSPENDED, NULL, NULL, &si, &pi); + ok = CreateProcess( + argv[exec_arg_pos], + cmd_line, + NULL, + NULL, + FALSE, + CREATE_SUSPENDED, + NULL, + NULL, + &si, + &pi); if (!ok) { - fprintf(stderr, "Failed to launch hooked EXE: %08x\n", - (unsigned int) GetLastError()); + fprintf( + stderr, + "Failed to launch hooked EXE: %08x\n", + (unsigned int) GetLastError()); goto start_fail; } @@ -125,8 +140,10 @@ int main(int argc, char **argv) debug_ok = DebugActiveProcess(pi.dwProcessId); if (!debug_ok) { - fprintf(stderr, "DebugActiveProcess failed: %08x\n", - (unsigned int) GetLastError()); + fprintf( + stderr, + "DebugActiveProcess failed: %08x\n", + (unsigned int) GetLastError()); } else { printf("Debug active process\n"); } @@ -139,7 +156,9 @@ int main(int argc, char **argv) BOOL res = FALSE; if (!CheckRemoteDebuggerPresent(pi.hProcess, &res)) { - fprintf(stderr, "CheckRemoteDebuggerPresent failed: %08x\n", + fprintf( + stderr, + "CheckRemoteDebuggerPresent failed: %08x\n", (unsigned int) GetLastError()); } @@ -155,8 +174,10 @@ int main(int argc, char **argv) printf("Resuming remote process...\n"); if (ResumeThread(pi.hThread) == -1) { - fprintf(stderr, "Error restarting hooked process: %08x\n", - (unsigned int) GetLastError()); + fprintf( + stderr, + "Error restarting hooked process: %08x\n", + (unsigned int) GetLastError()); goto restart_fail; } @@ -198,7 +219,7 @@ usage_fail: return EXIT_FAILURE; } -static bool inject_dll(PROCESS_INFORMATION pi, const char* arg_dll) +static bool inject_dll(PROCESS_INFORMATION pi, const char *arg_dll) { char dll_path[MAX_PATH]; DWORD dll_path_length; @@ -208,37 +229,52 @@ static bool inject_dll(PROCESS_INFORMATION pi, const char* arg_dll) printf("Injecting: %s\n", arg_dll); - dll_path_length = SearchPath(NULL, arg_dll, NULL, MAX_PATH, dll_path, - NULL); + dll_path_length = SearchPath(NULL, arg_dll, NULL, MAX_PATH, dll_path, NULL); dll_path_length++; - remote_addr = VirtualAllocEx(pi.hProcess, NULL, dll_path_length, - MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); + remote_addr = VirtualAllocEx( + pi.hProcess, + NULL, + dll_path_length, + MEM_RESERVE | MEM_COMMIT, + PAGE_READWRITE); if (!remote_addr) { - fprintf(stderr, "VirtualAllocEx failed: %08x\n", - (unsigned int) GetLastError()); + fprintf( + stderr, + "VirtualAllocEx failed: %08x\n", + (unsigned int) GetLastError()); goto alloc_fail; } - ok = WriteProcessMemory(pi.hProcess, remote_addr, dll_path, - dll_path_length, NULL); + ok = WriteProcessMemory( + pi.hProcess, remote_addr, dll_path, dll_path_length, NULL); if (!ok) { - fprintf(stderr, "WriteProcessMemory failed: %08x\n", - (unsigned int) GetLastError()); + fprintf( + stderr, + "WriteProcessMemory failed: %08x\n", + (unsigned int) GetLastError()); goto write_fail; } - remote_thread = CreateRemoteThread(pi.hProcess, NULL, 0, - (LPTHREAD_START_ROUTINE) LoadLibrary, remote_addr, 0, NULL); + remote_thread = CreateRemoteThread( + pi.hProcess, + NULL, + 0, + (LPTHREAD_START_ROUTINE) LoadLibrary, + remote_addr, + 0, + NULL); if (remote_thread == NULL) { - fprintf(stderr, "CreateRemoteThread failed: %08x\n", - (unsigned int) GetLastError()); + fprintf( + stderr, + "CreateRemoteThread failed: %08x\n", + (unsigned int) GetLastError()); goto inject_fail; } @@ -250,8 +286,10 @@ static bool inject_dll(PROCESS_INFORMATION pi, const char* arg_dll) remote_addr = NULL; if (!ok) { - fprintf(stderr, "VirtualFreeEx failed: %08x\n", - (unsigned int) GetLastError()); + fprintf( + stderr, + "VirtualFreeEx failed: %08x\n", + (unsigned int) GetLastError()); } return true; @@ -275,8 +313,10 @@ static bool debug(HANDLE process, uint32_t pid) ok = WaitForDebugEvent(&de, INFINITE); if (!ok) { - fprintf(stderr, "WaitForDebugEvent failed: %08x\n", - (unsigned int) GetLastError()); + fprintf( + stderr, + "WaitForDebugEvent failed: %08x\n", + (unsigned int) GetLastError()); return false; } @@ -316,23 +356,25 @@ static bool debug(HANDLE process, uint32_t pid) } if (de.dwDebugEventCode == OUTPUT_DEBUG_STRING_EVENT) { - ok = ContinueDebugEvent(de.dwProcessId, de.dwThreadId, - DBG_CONTINUE); + ok = + ContinueDebugEvent(de.dwProcessId, de.dwThreadId, DBG_CONTINUE); } else { - ok = ContinueDebugEvent(de.dwProcessId, de.dwThreadId, - DBG_EXCEPTION_NOT_HANDLED); + ok = ContinueDebugEvent( + de.dwProcessId, de.dwThreadId, DBG_EXCEPTION_NOT_HANDLED); } if (!ok) { - fprintf(stderr, "ContinueDebugEvent failed: %08x\n", - (unsigned int) GetLastError()); + fprintf( + stderr, + "ContinueDebugEvent failed: %08x\n", + (unsigned int) GetLastError()); return false; } } } -static char console_get_color(char* str) +static char console_get_color(char *str) { /* Add some color to make spotting warnings/errors easier. Based on debug output level identifier. */ @@ -371,15 +413,15 @@ static bool debug_wstr(HANDLE process, const OUTPUT_DEBUG_STRING_INFO *odsi) nbytes = odsi->nDebugStringLength * sizeof(wchar_t); wstr = xmalloc(nbytes); - ok = ReadProcessMemory(process, odsi->lpDebugStringData, wstr, nbytes, - NULL); + ok = + ReadProcessMemory(process, odsi->lpDebugStringData, wstr, nbytes, NULL); if (ok) { if (wstr_narrow(wstr, &str)) { str[odsi->nDebugStringLength - 1] = '\0'; - SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), - console_get_color(str)); + SetConsoleTextAttribute( + GetStdHandle(STD_OUTPUT_HANDLE), console_get_color(str)); printf("%s", str); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15); @@ -392,8 +434,10 @@ static bool debug_wstr(HANDLE process, const OUTPUT_DEBUG_STRING_INFO *odsi) fprintf(stderr, "OutputDebugStringW: UTF-16 conversion failed\n"); } } else { - fprintf(stderr, "ReadProcessMemory failed: %08x\n", - (unsigned int) GetLastError()); + fprintf( + stderr, + "ReadProcessMemory failed: %08x\n", + (unsigned int) GetLastError()); return false; } @@ -410,14 +454,14 @@ static bool debug_str(HANDLE process, const OUTPUT_DEBUG_STRING_INFO *odsi) str = xmalloc(odsi->nDebugStringLength); - ok = ReadProcessMemory(process, odsi->lpDebugStringData, str, - odsi->nDebugStringLength, NULL); + ok = ReadProcessMemory( + process, odsi->lpDebugStringData, str, odsi->nDebugStringLength, NULL); if (ok) { str[odsi->nDebugStringLength - 1] = '\0'; - SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), - console_get_color(str)); + SetConsoleTextAttribute( + GetStdHandle(STD_OUTPUT_HANDLE), console_get_color(str)); printf("%s", str); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15); @@ -425,12 +469,13 @@ static bool debug_str(HANDLE process, const OUTPUT_DEBUG_STRING_INFO *odsi) fprintf(log_file, "%s", str); } } else { - fprintf(stderr, "ReadProcessMemory failed: %08x\n", - (unsigned int) GetLastError()); + fprintf( + stderr, + "ReadProcessMemory failed: %08x\n", + (unsigned int) GetLastError()); } free(str); return (bool) ok; } - diff --git a/src/main/inject/options.c b/src/main/inject/options.c index 8abd615..39d7ebf 100644 --- a/src/main/inject/options.c +++ b/src/main/inject/options.c @@ -14,7 +14,7 @@ void options_init(struct options *options) bool options_read_cmdline(struct options *options, int argc, char **argv) { - for (int i = 1 ; i < argc ; i++) { + for (int i = 1; i < argc; i++) { if (argv[i][0] == '-') { switch (argv[i][1]) { case 'D': @@ -48,15 +48,15 @@ bool options_read_cmdline(struct options *options, int argc, char **argv) void options_print_usage(void) { fprintf(stderr, -"inject build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) "\n" -"Usage: inject hook.dll... app.exe [hooks options...]\n" -"You can specify one or multiple hook.dll files, e.g. inject.exe " -"hook1.dll hook2.dll app.exe" -"\n" -" The following options can be specified after the exe path:\n" -"\n" -" -D Enable debugging output\n" -" -R Halt the injected process until a debugger is attached\n" -" -Y [filename] Log to a file in addition to the console\n" - ); + "inject build " __DATE__ " " __TIME__ + ", gitrev " STRINGIFY(GITREV) "\n" + "Usage: inject hook.dll... app.exe [hooks options...]\n" + "You can specify one or multiple hook.dll files, e.g. inject.exe " + "hook1.dll hook2.dll app.exe" + "\n" + " The following options can be specified after the exe path:\n" + "\n" + " -D Enable debugging output\n" + " -R Halt the injected process until a debugger is attached\n" + " -Y [filename] Log to a file in addition to the console\n"); } diff --git a/src/main/jbhook/acio.c b/src/main/jbhook/acio.c index c4d8a5e..8e4ff2a 100644 --- a/src/main/jbhook/acio.c +++ b/src/main/jbhook/acio.c @@ -1,8 +1,8 @@ #include -#include #include #include +#include #include #include @@ -42,7 +42,8 @@ void ac_io_port_fini(void) ac_io_emu_fini(&ac_io_emu); } -HRESULT ac_io_port_dispatch_irp(struct irp *irp) +HRESULT +ac_io_port_dispatch_irp(struct irp *irp) { const struct ac_io_message *msg; HRESULT hr; @@ -63,31 +64,31 @@ HRESULT ac_io_port_dispatch_irp(struct irp *irp) msg = ac_io_emu_request_peek(&ac_io_emu); switch (msg->addr) { - case 0: - ac_io_emu_cmd_assign_addrs(&ac_io_emu, msg, 2); + case 0: + ac_io_emu_cmd_assign_addrs(&ac_io_emu, msg, 2); - break; + break; - case 1: - ac_io_emu_iccb_dispatch_request(&ac_io_emu_iccb, msg); + case 1: + ac_io_emu_iccb_dispatch_request(&ac_io_emu_iccb, msg); - break; + break; - case 2: - ac_io_emu_h44b_dispatch_request(&ac_io_emu_h44b, msg); + case 2: + ac_io_emu_h44b_dispatch_request(&ac_io_emu_h44b, msg); - break; + break; - case AC_IO_BROADCAST: - log_warning("Broadcast(?) message on jubeat ACIO bus?"); + case AC_IO_BROADCAST: + log_warning("Broadcast(?) message on jubeat ACIO bus?"); - break; + break; - default: - log_warning("ACIO message on unhandled bus address: %d", - msg->addr); + default: + log_warning( + "ACIO message on unhandled bus address: %d", msg->addr); - break; + break; } ac_io_emu_request_pop(&ac_io_emu); diff --git a/src/main/jbhook/dllmain.c b/src/main/jbhook/dllmain.c index a209926..13d4338 100644 --- a/src/main/jbhook/dllmain.c +++ b/src/main/jbhook/dllmain.c @@ -1,8 +1,8 @@ #include #include -#include #include +#include #include #include "bemanitools/eamio.h" @@ -52,15 +52,10 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) log_info("Starting up jubeat IO backend"); jb_io_set_loggers( - log_impl_misc, - log_impl_info, - log_impl_warning, - log_impl_fatal); + log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); - jb_io_ok = jb_io_init( - avs_thread_create, - avs_thread_join, - avs_thread_destroy); + jb_io_ok = + jb_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy); if (!jb_io_ok) { goto fail; @@ -73,15 +68,10 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) log_info("Starting up card reader backend"); eam_io_set_loggers( - log_impl_misc, - log_impl_info, - log_impl_warning, - log_impl_fatal); + log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); - eam_io_ok = eam_io_init( - avs_thread_create, - avs_thread_join, - avs_thread_destroy); + eam_io_ok = + eam_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy); if (!eam_io_ok) { goto fail; @@ -136,10 +126,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) } log_to_external( - log_body_misc, - log_body_info, - log_body_warning, - log_body_fatal); + log_body_misc, log_body_info, log_body_warning, log_body_fatal); options_init_from_cmdline(&options); @@ -159,4 +146,3 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) return TRUE; } - diff --git a/src/main/jbhook/eamuse.c b/src/main/jbhook/eamuse.c index 6543527..429c473 100644 --- a/src/main/jbhook/eamuse.c +++ b/src/main/jbhook/eamuse.c @@ -14,31 +14,42 @@ #include "util/log.h" #include "util/str.h" -static const char* jbhook_eamuse_konami_url = "eamuse.konami."; +static const char *jbhook_eamuse_konami_url = "eamuse.konami."; -static int (STDCALL *real_getaddrinfo)(PCSTR pNodeName, PCSTR pServiceName, - const ADDRINFOA *pHints, PADDRINFOA *ppResult); +static int(STDCALL *real_getaddrinfo)( + PCSTR pNodeName, + PCSTR pServiceName, + const ADDRINFOA *pHints, + PADDRINFOA *ppResult); -static int STDCALL my_getaddrinfo(PCSTR pNodeName, PCSTR pServiceName, - const ADDRINFOA *pHints, PADDRINFOA *ppResult); +static int STDCALL my_getaddrinfo( + PCSTR pNodeName, + PCSTR pServiceName, + const ADDRINFOA *pHints, + PADDRINFOA *ppResult); static const struct hook_symbol eamuse_hook_syms[] = { { - .name = "getaddrinfo", - .ordinal = 176, - .patch = my_getaddrinfo, - .link = (void **) &real_getaddrinfo, + .name = "getaddrinfo", + .ordinal = 176, + .patch = my_getaddrinfo, + .link = (void **) &real_getaddrinfo, }, }; -static int STDCALL my_getaddrinfo(PCSTR pNodeName, PCSTR pServiceName, - const ADDRINFOA *pHints, PADDRINFOA *ppResult) +static int STDCALL my_getaddrinfo( + PCSTR pNodeName, + PCSTR pServiceName, + const ADDRINFOA *pHints, + PADDRINFOA *ppResult) { log_misc("my_getaddrinfo: %s, %s", pNodeName, pServiceName); /* resolve eamuse.konami.fun/com to 127.0.0.1 to avoid lag spikes every 150 seconds which might happen in-game as well */ - if (!strncmp(pNodeName, jbhook_eamuse_konami_url, + if (!strncmp( + pNodeName, + jbhook_eamuse_konami_url, strlen(jbhook_eamuse_konami_url))) { log_info("Resolve konami.eamuse.XXX -> localhost"); pNodeName = "localhost"; @@ -50,10 +61,7 @@ static int STDCALL my_getaddrinfo(PCSTR pNodeName, PCSTR pServiceName, void jbhook_eamuse_hook_init(void) { hook_table_apply( - NULL, - "ws2_32.dll", - eamuse_hook_syms, - lengthof(eamuse_hook_syms)); + NULL, "ws2_32.dll", eamuse_hook_syms, lengthof(eamuse_hook_syms)); log_info("Inserted eamuse hooks"); } diff --git a/src/main/jbhook/gfx.c b/src/main/jbhook/gfx.c index b9ab965..270d947 100644 --- a/src/main/jbhook/gfx.c +++ b/src/main/jbhook/gfx.c @@ -17,30 +17,43 @@ #include "util/str.h" #include "util/time.h" -static DWORD STDCALL my_GetGlyphOutline(HDC hdc, UINT uChar, UINT uFormat, - LPGLYPHMETRICS lpgm, DWORD cbBuffer, LPVOID lpvBuffer, - const MAT2* lpmat2); +static DWORD STDCALL my_GetGlyphOutline( + HDC hdc, + UINT uChar, + UINT uFormat, + LPGLYPHMETRICS lpgm, + DWORD cbBuffer, + LPVOID lpvBuffer, + const MAT2 *lpmat2); -static DWORD (STDCALL* real_GetGlyphOutline)(HDC hdc, UINT uChar, UINT uFormat, - LPGLYPHMETRICS lpgm, DWORD cbBuffer, LPVOID lpvBuffer, - const MAT2* lpmat2); +static DWORD(STDCALL *real_GetGlyphOutline)( + HDC hdc, + UINT uChar, + UINT uFormat, + LPGLYPHMETRICS lpgm, + DWORD cbBuffer, + LPVOID lpvBuffer, + const MAT2 *lpmat2); static const struct hook_symbol gfx_hook_syms[] = { + {.name = "GetGlyphOutlineA", + .patch = my_GetGlyphOutline, + .link = (void **) &real_GetGlyphOutline}, { - .name = "GetGlyphOutlineA", - .patch = my_GetGlyphOutline, - .link = (void **) &real_GetGlyphOutline - }, - { - .name = "IsDBCSLeadByteEx", - .patch = my_GetGlyphOutline, // !?? - .link = (void **) &real_GetGlyphOutline // !?? + .name = "IsDBCSLeadByteEx", + .patch = my_GetGlyphOutline, // !?? + .link = (void **) &real_GetGlyphOutline // !?? }, }; -static DWORD STDCALL my_GetGlyphOutline(HDC hdc, UINT uChar, UINT uFormat, - LPGLYPHMETRICS lpgm, DWORD cbBuffer, LPVOID lpvBuffer, - const MAT2* lpmat2) +static DWORD STDCALL my_GetGlyphOutline( + HDC hdc, + UINT uChar, + UINT uFormat, + LPGLYPHMETRICS lpgm, + DWORD cbBuffer, + LPVOID lpvBuffer, + const MAT2 *lpmat2) { if (IsDBCSLeadByteEx(CP_ACP, uChar & 0xFF)) { log_warning("!!!!!!!!"); @@ -50,20 +63,17 @@ static DWORD STDCALL my_GetGlyphOutline(HDC hdc, UINT uChar, UINT uFormat, tmp[0] = uChar & 0xFF; tmp[1] = (uChar >> 8) & 0xFF; - MultiByteToWideChar(CP_ACP, MB_USEGLYPHCHARS, tmp, 2, lpvBuffer, cbBuffer); + MultiByteToWideChar( + CP_ACP, MB_USEGLYPHCHARS, tmp, 2, lpvBuffer, cbBuffer); } - return real_GetGlyphOutline(hdc, uChar, uFormat, lpgm, cbBuffer, lpvBuffer, - lpmat2); + return real_GetGlyphOutline( + hdc, uChar, uFormat, lpgm, cbBuffer, lpvBuffer, lpmat2); } void gfx_hook_init(void) { - hook_table_apply( - NULL, - "gdi32.dll", - gfx_hook_syms, - lengthof(gfx_hook_syms)); + hook_table_apply(NULL, "gdi32.dll", gfx_hook_syms, lengthof(gfx_hook_syms)); log_info("Inserted gfx hooks"); } @@ -71,4 +81,3 @@ void gfx_hook_init(void) void gfx_set_windowed(bool framed) { } - diff --git a/src/main/jbhook/io.c b/src/main/jbhook/io.c index f3d318c..65a4b36 100644 --- a/src/main/jbhook/io.c +++ b/src/main/jbhook/io.c @@ -18,16 +18,19 @@ struct jbhook_io_p4io_outputs { uint32_t outputs; }; -static void jbhook_io_jamma2_read(void* resp, uint32_t nbytes); -static uint32_t jbhook_command_handle(uint8_t cmd, const void* payload, - uint32_t payload_len, void* resp, uint32_t resp_max_len); +static void jbhook_io_jamma2_read(void *resp, uint32_t nbytes); +static uint32_t jbhook_command_handle( + uint8_t cmd, + const void *payload, + uint32_t payload_len, + void *resp, + uint32_t resp_max_len); static const struct p4ioemu_device_msg_hook jbhook_io_msg = { .jamma2_read = jbhook_io_jamma2_read, .command_handle = jbhook_command_handle, .roundplug_read_id = NULL, - .roundplug_read_mem = NULL -}; + .roundplug_read_mem = NULL}; /* 0:0 ??? @@ -90,9 +93,9 @@ static const uint32_t jbhook_io_sys_button_mappings[] = { (1 << 25), }; -static void jbhook_io_jamma2_read(void* resp, uint32_t nbytes) +static void jbhook_io_jamma2_read(void *resp, uint32_t nbytes) { - uint32_t* inputs = (uint32_t*) resp; + uint32_t *inputs = (uint32_t *) resp; uint16_t panels; uint8_t buttons; @@ -120,16 +123,19 @@ static void jbhook_io_jamma2_read(void* resp, uint32_t nbytes) } } -static uint32_t jbhook_command_handle(uint8_t cmd, const void* payload, - uint32_t payload_len, void* resp, uint32_t resp_max_len) +static uint32_t jbhook_command_handle( + uint8_t cmd, + const void *payload, + uint32_t payload_len, + void *resp, + uint32_t resp_max_len) { switch (cmd) { - case JUHOOK_IO_P4IO_CMD_OUTPUTS: - { + case JUHOOK_IO_P4IO_CMD_OUTPUTS: { // const struct jbhook_io_p4io_outputs* req = // (const struct jbhook_io_p4io_outputs*) payload; - //log_misc("JUHOOK_IO_P4IO_CMD_OUTPUTS: 0x%X", req->outputs); + // log_misc("JUHOOK_IO_P4IO_CMD_OUTPUTS: 0x%X", req->outputs); /* coin blocker: off 0x20, on 0x00 */ @@ -143,7 +149,7 @@ static uint32_t jbhook_command_handle(uint8_t cmd, const void* payload, } } -const struct p4ioemu_device_msg_hook* jbhook_io_init(void) +const struct p4ioemu_device_msg_hook *jbhook_io_init(void) { return &jbhook_io_msg; } diff --git a/src/main/jbhook/io.h b/src/main/jbhook/io.h index f944c3c..83e93f7 100644 --- a/src/main/jbhook/io.h +++ b/src/main/jbhook/io.h @@ -3,6 +3,6 @@ #include "p4ioemu/device.h" -const struct p4ioemu_device_msg_hook* jbhook_io_init(void); +const struct p4ioemu_device_msg_hook *jbhook_io_init(void); #endif \ No newline at end of file diff --git a/src/main/jbhook/options.c b/src/main/jbhook/options.c index 044cfef..06177b2 100644 --- a/src/main/jbhook/options.c +++ b/src/main/jbhook/options.c @@ -2,9 +2,9 @@ #include +#include #include #include -#include #include "util/cmdline.h" #include "util/defs.h" @@ -12,7 +12,7 @@ #include "util/log.h" #include "util/str.h" -void options_init_from_cmdline(struct options* options) +void options_init_from_cmdline(struct options *options) { int argc; char **argv; @@ -22,7 +22,7 @@ void options_init_from_cmdline(struct options* options) options_init(options); - ok = options_read_cmdline(options, argc, (const char**) argv); + ok = options_read_cmdline(options, argc, (const char **) argv); args_free(argc, argv); @@ -31,7 +31,7 @@ void options_init_from_cmdline(struct options* options) } } -void options_init(struct options* options) +void options_init(struct options *options) { options->windowed = false; options->window_framed = false; @@ -39,44 +39,37 @@ void options_init(struct options* options) options->disable_cardemu = false; } -bool options_read_cmdline(struct options* options, int argc, - const char **argv) +bool options_read_cmdline(struct options *options, int argc, const char **argv) { int i; for (i = 0; i < argc; i++) { - if (argv[i][0] != '-') { continue; } switch (argv[i][1]) { - case 'h': - { + case 'h': { options_print_usage(); return false; } - case 'w': - { + case 'w': { options->windowed = true; break; } - case 'f': - { + case 'f': { options->window_framed = true; break; } - case 'c': - { + case 'c': { options->disable_cardemu = true; break; } - case 'p': - { + case 'p': { options->disable_p4ioemu = true; break; } @@ -88,22 +81,22 @@ bool options_read_cmdline(struct options* options, int argc, void options_print_usage(void) { - OutputDebugStringA( -"jbhook for jubeat, build " __DATE__ " " __TIME__ ", gitrev " -STRINGIFY(GITREV) "\n" -"Usage: launcher.exe -K jbhook.dll [game exec] \n" -"\n" -" The following options can be specified after the game exec path:\n" -"\n" -" -h Print this usage message\n" -" -w Run the game windowed\n" -" -f Run the game in a framed window (needs -w option)\n" -" -c Disable card emulation (e.g. when running on a real cab)\n" -" -p Disable p4io emulation (e.g. when running on a real cab or on a bare p4io)\n" - ); + OutputDebugStringA("jbhook for jubeat, build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY( + GITREV) "\n" + "Usage: launcher.exe -K jbhook.dll [game exec] \n" + "\n" + " The following options can be specified after the game exec path:\n" + "\n" + " -h Print this usage message\n" + " -w Run the game windowed\n" + " -f Run the game in a framed window (needs -w option)\n" + " -c Disable card emulation (e.g. when running on a " + "real cab)\n" + " -p Disable p4io emulation (e.g. when running on a " + "real cab or on a bare " + "p4io)\n"); } -void options_fini(struct options* options) +void options_fini(struct options *options) { - } diff --git a/src/main/jbhook/options.h b/src/main/jbhook/options.h index 56317a0..4985d77 100644 --- a/src/main/jbhook/options.h +++ b/src/main/jbhook/options.h @@ -11,12 +11,11 @@ struct options { bool disable_cardemu; }; -void options_init_from_cmdline(struct options* options); +void options_init_from_cmdline(struct options *options); -void options_init(struct options* options); -bool options_read_cmdline(struct options* options, - int argc, const char** argv); +void options_init(struct options *options); +bool options_read_cmdline(struct options *options, int argc, const char **argv); void options_print_usage(void); -void options_fini(struct options* options); +void options_fini(struct options *options); #endif diff --git a/src/main/jbhook1/acio.c b/src/main/jbhook1/acio.c index 892ae72..6b758a8 100644 --- a/src/main/jbhook1/acio.c +++ b/src/main/jbhook1/acio.c @@ -1,8 +1,8 @@ #include -#include #include #include +#include #include #include @@ -42,7 +42,8 @@ void ac_io_port_fini(void) ac_io_emu_fini(&ac_io_emu); } -HRESULT ac_io_port_dispatch_irp(struct irp *irp) +HRESULT +ac_io_port_dispatch_irp(struct irp *irp) { const struct ac_io_message *msg; HRESULT hr; @@ -63,31 +64,31 @@ HRESULT ac_io_port_dispatch_irp(struct irp *irp) msg = ac_io_emu_request_peek(&ac_io_emu); switch (msg->addr) { - case 0: - ac_io_emu_cmd_assign_addrs(&ac_io_emu, msg, 2); + case 0: + ac_io_emu_cmd_assign_addrs(&ac_io_emu, msg, 2); - break; + break; - case 1: - ac_io_emu_icca_dispatch_request(&ac_io_emu_icca, msg); + case 1: + ac_io_emu_icca_dispatch_request(&ac_io_emu_icca, msg); - break; + break; - case 2: - ac_io_emu_h44b_dispatch_request(&ac_io_emu_h44b, msg); + case 2: + ac_io_emu_h44b_dispatch_request(&ac_io_emu_h44b, msg); - break; + break; - case AC_IO_BROADCAST: - log_warning("Broadcast(?) message on jubeat ACIO bus?"); + case AC_IO_BROADCAST: + log_warning("Broadcast(?) message on jubeat ACIO bus?"); - break; + break; - default: - log_warning("ACIO message on unhandled bus address: %d", - msg->addr); + default: + log_warning( + "ACIO message on unhandled bus address: %d", msg->addr); - break; + break; } ac_io_emu_request_pop(&ac_io_emu); diff --git a/src/main/jbhook1/avs-boot.c b/src/main/jbhook1/avs-boot.c index 24a907f..7084f70 100644 --- a/src/main/jbhook1/avs-boot.c +++ b/src/main/jbhook1/avs-boot.c @@ -14,47 +14,49 @@ #include "util/log.h" static void (*real_avs_boot)( - struct property_node *config, void *std_heap, size_t sz_std_heap, - void *avs_heap, size_t sz_avs_heap, avs_log_writer_t log_writer, - void *log_context); + struct property_node *config, + void *std_heap, + size_t sz_std_heap, + void *avs_heap, + size_t sz_avs_heap, + avs_log_writer_t log_writer, + void *log_context); static int (*real_log_change_level)(int level); static int (*real_ea3_boot)(struct property_node *config); static void my_avs_boot( - struct property_node *config, void *std_heap, size_t sz_std_heap, - void *avs_heap, size_t sz_avs_heap, avs_log_writer_t log_writer, - void *log_context); + struct property_node *config, + void *std_heap, + size_t sz_std_heap, + void *avs_heap, + size_t sz_avs_heap, + avs_log_writer_t log_writer, + void *log_context); static int my_log_change_level(int level); static int my_ea3_boot(struct property_node *config); static struct net_addr jbhook1_avs_boot_eamuse_server_addr; static const struct hook_symbol jbhook1_log_gftools_hook_syms[] = { - { - .name = "avs_boot", - .patch = my_avs_boot, - .link = (void **) &real_avs_boot - }, - { - .name = "log_change_level", - .patch = my_log_change_level, - .link = (void **) &real_log_change_level - }, + {.name = "avs_boot", + .patch = my_avs_boot, + .link = (void **) &real_avs_boot}, + {.name = "log_change_level", + .patch = my_log_change_level, + .link = (void **) &real_log_change_level}, }; static const struct hook_symbol jbhook1_log_gftools_hook_syms2[] = { - { - .name = "ea3_boot", - .patch = my_ea3_boot, - .link = (void **) &real_ea3_boot - }, + {.name = "ea3_boot", + .patch = my_ea3_boot, + .link = (void **) &real_ea3_boot}, }; -static void avs_boot_replace_property_uint32(struct property_node* node, - const char* name, uint32_t val) +static void avs_boot_replace_property_uint32( + struct property_node *node, const char *name, uint32_t val) { - struct property_node* tmp; - + struct property_node *tmp; + tmp = property_search(NULL, node, name); if (tmp) { @@ -64,11 +66,11 @@ static void avs_boot_replace_property_uint32(struct property_node* node, property_node_create(NULL, node, PSMAP_TYPE_U32, name, val); } -static void avs_boot_replace_property_str(struct property_node* node, - const char* name, const char* val) +static void avs_boot_replace_property_str( + struct property_node *node, const char *name, const char *val) { - struct property_node* tmp; - + struct property_node *tmp; + tmp = property_search(NULL, node, name); if (tmp) { @@ -83,25 +85,35 @@ static void avs_boot_replace_property_str(struct property_node* node, } static void my_avs_boot( - struct property_node *config, void *std_heap, size_t sz_std_heap, - void *avs_heap, size_t sz_avs_heap, avs_log_writer_t log_writer, - void *log_context) + struct property_node *config, + void *std_heap, + size_t sz_std_heap, + void *avs_heap, + size_t sz_avs_heap, + avs_log_writer_t log_writer, + void *log_context) { log_info("Called my_avs_boot"); avs_boot_replace_property_uint32(config, "log/level", 4); - avs_boot_replace_property_str(config, "/config/fs/nvram/device", - "./CONF/NVRAM"); - avs_boot_replace_property_str(config, "/config/fs/raw/device", - "./CONF/RAW"); - - real_avs_boot(config, std_heap, sz_std_heap, avs_heap, sz_avs_heap, - log_writer_debug, NULL); + avs_boot_replace_property_str( + config, "/config/fs/nvram/device", "./CONF/NVRAM"); + avs_boot_replace_property_str( + config, "/config/fs/raw/device", "./CONF/RAW"); + + real_avs_boot( + config, + std_heap, + sz_std_heap, + avs_heap, + sz_avs_heap, + log_writer_debug, + NULL); } static int my_ea3_boot(struct property_node *config) { - char* server_addr; + char *server_addr; log_info("Called my_ea3_boot"); @@ -128,30 +140,32 @@ static int my_log_change_level(int level) void jbhook1_avs_boot_init() { hook_table_apply( - NULL, - "libavs-win32.dll", - jbhook1_log_gftools_hook_syms, - lengthof(jbhook1_log_gftools_hook_syms)); + NULL, + "libavs-win32.dll", + jbhook1_log_gftools_hook_syms, + lengthof(jbhook1_log_gftools_hook_syms)); hook_table_apply( - NULL, - "libavs-win32-ea3.dll", - jbhook1_log_gftools_hook_syms2, - lengthof(jbhook1_log_gftools_hook_syms2)); + NULL, + "libavs-win32-ea3.dll", + jbhook1_log_gftools_hook_syms2, + lengthof(jbhook1_log_gftools_hook_syms2)); memset(&jbhook1_avs_boot_eamuse_server_addr, 0, sizeof(struct net_addr)); log_info("Inserted avs log hooks"); } -void jbhook1_avs_boot_set_eamuse_addr(const struct net_addr* server_addr) +void jbhook1_avs_boot_set_eamuse_addr(const struct net_addr *server_addr) { - char* str; + char *str; str = net_addr_to_str(server_addr); log_info("Setting eamuse server: %s", str); free(str); - memcpy(&jbhook1_avs_boot_eamuse_server_addr, server_addr, + memcpy( + &jbhook1_avs_boot_eamuse_server_addr, + server_addr, sizeof(struct net_addr)); } \ No newline at end of file diff --git a/src/main/jbhook1/avs-boot.h b/src/main/jbhook1/avs-boot.h index 464fc7f..a39a90b 100644 --- a/src/main/jbhook1/avs-boot.h +++ b/src/main/jbhook1/avs-boot.h @@ -11,9 +11,9 @@ void jbhook1_avs_boot_init(); /** * Set the target eamuse server address. - * + * * @param server_addr Address to target eamuse server. */ -void jbhook1_avs_boot_set_eamuse_addr(const struct net_addr* server_addr); +void jbhook1_avs_boot_set_eamuse_addr(const struct net_addr *server_addr); #endif diff --git a/src/main/jbhook1/config-eamuse.c b/src/main/jbhook1/config-eamuse.c index 61405e9..dba512e 100644 --- a/src/main/jbhook1/config-eamuse.c +++ b/src/main/jbhook1/config-eamuse.c @@ -13,9 +13,11 @@ #define JBHOOK1_CONFIG_EAMUSE_DEFAULT_SERVER_VALUE "localhost:80" #define JBHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE security_id_default -#define JBHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE_LEN sizeof(security_id_default) +#define JBHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE_LEN \ + sizeof(security_id_default) #define JBHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE security_id_default -#define JBHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE_LEN sizeof(security_id_default) +#define JBHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE_LEN \ + sizeof(security_id_default) const struct net_addr jbhook1_eamuse_default_server = { .type = NET_ADDR_TYPE_HOSTNAME, @@ -23,88 +25,119 @@ const struct net_addr jbhook1_eamuse_default_server = { .hostname.port = 80, }; -void jbhook1_config_eamuse_init(struct cconfig* config) +void jbhook1_config_eamuse_init(struct cconfig *config) { - cconfig_util_set_str(config, + cconfig_util_set_str( + config, JBHOOK1_CONFIG_EAMUSE_SERVER_KEY, JBHOOK1_CONFIG_EAMUSE_DEFAULT_SERVER_VALUE, "URL (e.g. http://my.eamuse.server:80/whatever) or IPV4 " - "(e.g. 127.0.0.1:80) of the target eamuse server. The port is optional " + "(e.g. 127.0.0.1:80) of the target eamuse server. The port is " + "optional " "but defaults to 80."); - cconfig_util_set_data(config, JBHOOK1_CONFIG_EAMUSE_PCBID_KEY, - (uint8_t*) &JBHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE, - JBHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE_LEN, "PCBID"); + cconfig_util_set_data( + config, + JBHOOK1_CONFIG_EAMUSE_PCBID_KEY, + (uint8_t *) &JBHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE, + JBHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE_LEN, + "PCBID"); - cconfig_util_set_data(config, JBHOOK1_CONFIG_EAMUSE_EAMID_KEY, - (uint8_t*) &JBHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE, - JBHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE_LEN, "EAMID"); + cconfig_util_set_data( + config, + JBHOOK1_CONFIG_EAMUSE_EAMID_KEY, + (uint8_t *) &JBHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE, + JBHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE_LEN, + "EAMID"); } -void jbhook1_config_eamuse_get(struct jbhook1_config_eamuse* config_eamuse, - struct cconfig* config) +void jbhook1_config_eamuse_get( + struct jbhook1_config_eamuse *config_eamuse, struct cconfig *config) { char server_url[1024]; - char* tmp; - char* tmp2; + char *tmp; + char *tmp2; memset(config_eamuse, 0, sizeof(struct jbhook1_config_eamuse)); - if (!cconfig_util_get_str(config, JBHOOK1_CONFIG_EAMUSE_SERVER_KEY, - server_url, sizeof(server_url), + if (!cconfig_util_get_str( + config, + JBHOOK1_CONFIG_EAMUSE_SERVER_KEY, + server_url, + sizeof(server_url), JBHOOK1_CONFIG_EAMUSE_DEFAULT_SERVER_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%s'", JBHOOK1_CONFIG_EAMUSE_SERVER_KEY, + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%s'", + JBHOOK1_CONFIG_EAMUSE_SERVER_KEY, JBHOOK1_CONFIG_EAMUSE_DEFAULT_SERVER_VALUE); } if (!net_str_parse(server_url, &config_eamuse->server)) { - memcpy(&config_eamuse->server, &jbhook1_eamuse_default_server, + memcpy( + &config_eamuse->server, + &jbhook1_eamuse_default_server, sizeof(config_eamuse->server)); tmp = net_addr_to_str(&config_eamuse->server); - log_warning("Invalid value for key '%s' specified, fallback " - "to default", tmp); + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default", + tmp); free(tmp); } - if (!cconfig_util_get_data(config, JBHOOK1_CONFIG_EAMUSE_PCBID_KEY, - (uint8_t*) &config_eamuse->pcbid, + if (!cconfig_util_get_data( + config, + JBHOOK1_CONFIG_EAMUSE_PCBID_KEY, + (uint8_t *) &config_eamuse->pcbid, JBHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE_LEN, - (uint8_t*) &JBHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE)) { - tmp = security_id_to_str(&JBHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE, - false); - log_warning("Invalid value for key '%s' specified, fallback " - "to default", tmp); + (uint8_t *) &JBHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE)) { + tmp = security_id_to_str( + &JBHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE, false); + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default", + tmp); free(tmp); } if (!security_id_verify(&config_eamuse->pcbid)) { - tmp = security_id_to_str(&JBHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE, - false); + tmp = security_id_to_str( + &JBHOOK1_CONFIG_EAMUSE_DEFAULT_PCBID_VALUE, false); tmp2 = security_id_to_str(&config_eamuse->pcbid, false); - log_warning("PCBID verification of '%s' failed, fallback to default " - "PCBID '%s'", tmp2, tmp); + log_warning( + "PCBID verification of '%s' failed, fallback to default " + "PCBID '%s'", + tmp2, + tmp); free(tmp); free(tmp2); } - - if (!cconfig_util_get_data(config, JBHOOK1_CONFIG_EAMUSE_EAMID_KEY, - (uint8_t*) &config_eamuse->eamid, + + if (!cconfig_util_get_data( + config, + JBHOOK1_CONFIG_EAMUSE_EAMID_KEY, + (uint8_t *) &config_eamuse->eamid, JBHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE_LEN, - (uint8_t*) &JBHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE)) { - tmp = security_id_to_str(&JBHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE, - false); - log_warning("Invalid value for key '%s' specified, fallback " - "to default", tmp); + (uint8_t *) &JBHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE)) { + tmp = security_id_to_str( + &JBHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE, false); + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default", + tmp); free(tmp); } if (!security_id_verify(&config_eamuse->eamid)) { - tmp = security_id_to_str(&JBHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE, - false); + tmp = security_id_to_str( + &JBHOOK1_CONFIG_EAMUSE_DEFAULT_EAMID_VALUE, false); tmp2 = security_id_to_str(&config_eamuse->eamid, false); - log_warning("EAMID verification of '%s' failed, fallback to default " - "EAMID '%s'", tmp2, tmp); + log_warning( + "EAMID verification of '%s' failed, fallback to default " + "EAMID '%s'", + tmp2, + tmp); free(tmp); free(tmp2); } diff --git a/src/main/jbhook1/config-eamuse.h b/src/main/jbhook1/config-eamuse.h index 42044e2..63df275 100644 --- a/src/main/jbhook1/config-eamuse.h +++ b/src/main/jbhook1/config-eamuse.h @@ -20,17 +20,17 @@ struct jbhook1_config_eamuse { * Initialize a cconfig structure with the basic structure and default values * of this configuration. */ -void jbhook1_config_eamuse_init(struct cconfig* config); +void jbhook1_config_eamuse_init(struct cconfig *config); /** * Read the module specific config struct values from the provided cconfig * struct. - * + * * @param config_eamuse Target module specific struct to read configuration * values to. * @param config cconfig struct holding the intermediate data to read from. */ -void jbhook1_config_eamuse_get(struct jbhook1_config_eamuse* config_eamuse, - struct cconfig* config); +void jbhook1_config_eamuse_get( + struct jbhook1_config_eamuse *config_eamuse, struct cconfig *config); #endif \ No newline at end of file diff --git a/src/main/jbhook1/config-gfx.c b/src/main/jbhook1/config-gfx.c index f9efbc8..cc426f2 100644 --- a/src/main/jbhook1/config-gfx.c +++ b/src/main/jbhook1/config-gfx.c @@ -10,22 +10,27 @@ #define JBHOOK1_CONFIG_GFX_DEFAULT_WINDOWED_VALUE false -void jbhook1_config_gfx_init(struct cconfig* config) +void jbhook1_config_gfx_init(struct cconfig *config) { - cconfig_util_set_bool(config, + cconfig_util_set_bool( + config, JBHOOK1_CONFIG_GFX_WINDOWED_KEY, JBHOOK1_CONFIG_GFX_DEFAULT_WINDOWED_VALUE, "Run the game windowed"); } -void jbhook1_config_gfx_get(struct jbhook1_config_gfx* config_gfx, - struct cconfig* config) +void jbhook1_config_gfx_get( + struct jbhook1_config_gfx *config_gfx, struct cconfig *config) { - if (!cconfig_util_get_bool(config, JBHOOK1_CONFIG_GFX_WINDOWED_KEY, + if (!cconfig_util_get_bool( + config, + JBHOOK1_CONFIG_GFX_WINDOWED_KEY, &config_gfx->windowed, JBHOOK1_CONFIG_GFX_DEFAULT_WINDOWED_VALUE)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%d'", JBHOOK1_CONFIG_GFX_WINDOWED_KEY, + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%d'", + JBHOOK1_CONFIG_GFX_WINDOWED_KEY, JBHOOK1_CONFIG_GFX_DEFAULT_WINDOWED_VALUE); } } diff --git a/src/main/jbhook1/config-gfx.h b/src/main/jbhook1/config-gfx.h index cc98dfe..73b27a8 100644 --- a/src/main/jbhook1/config-gfx.h +++ b/src/main/jbhook1/config-gfx.h @@ -14,17 +14,17 @@ struct jbhook1_config_gfx { * Initialize a cconfig structure with the basic structure and default values * of this configuration. */ -void jbhook1_config_gfx_init(struct cconfig* config); +void jbhook1_config_gfx_init(struct cconfig *config); /** * Read the module specific config struct values from the provided cconfig * struct. - * + * * @param config_gfx Target module specific struct to read configuration * values to. * @param config cconfig struct holding the intermediate data to read from. */ -void jbhook1_config_gfx_get(struct jbhook1_config_gfx* config_gfx, - struct cconfig* config); +void jbhook1_config_gfx_get( + struct jbhook1_config_gfx *config_gfx, struct cconfig *config); #endif \ No newline at end of file diff --git a/src/main/jbhook1/config-security.c b/src/main/jbhook1/config-security.c index 6a76841..6e0123e 100644 --- a/src/main/jbhook1/config-security.c +++ b/src/main/jbhook1/config-security.c @@ -11,7 +11,8 @@ #define JBHOOK1_CONFIG_SECURITY_MCODE_KEY "security.mcode" -#define JBHOOK1_CONFIG_SECURITY_DEFAULT_MCODE_VALUE jbhook1_config_security_default_mcode +#define JBHOOK1_CONFIG_SECURITY_DEFAULT_MCODE_VALUE \ + jbhook1_config_security_default_mcode static const struct security_mcode jbhook1_config_security_default_mcode = { .header = SECURITY_MCODE_HEADER, @@ -22,42 +23,53 @@ static const struct security_mcode jbhook1_config_security_default_mcode = { .revision = SECURITY_MCODE_REVISION_B, }; -void jbhook1_config_security_init(struct cconfig* config) +void jbhook1_config_security_init(struct cconfig *config) { - char* tmp; + char *tmp; tmp = security_mcode_to_str(&JBHOOK1_CONFIG_SECURITY_DEFAULT_MCODE_VALUE); - cconfig_util_set_str(config, + cconfig_util_set_str( + config, JBHOOK1_CONFIG_SECURITY_MCODE_KEY, - tmp, + tmp, "Mcode of the game to run."); free(tmp); } void jbhook1_config_security_get( - struct jbhook1_config_security* config_security, struct cconfig* config) + struct jbhook1_config_security *config_security, struct cconfig *config) { - char* tmp_default; + char *tmp_default; char mcode[9]; - tmp_default = + tmp_default = security_mcode_to_str(&JBHOOK1_CONFIG_SECURITY_DEFAULT_MCODE_VALUE); - if (!cconfig_util_get_str(config, JBHOOK1_CONFIG_SECURITY_MCODE_KEY, - mcode, sizeof(mcode) - 1, tmp_default)) { - log_warning("Invalid value for key '%s' specified, fallback " - "to default '%s'", JBHOOK1_CONFIG_SECURITY_MCODE_KEY, tmp_default); + if (!cconfig_util_get_str( + config, + JBHOOK1_CONFIG_SECURITY_MCODE_KEY, + mcode, + sizeof(mcode) - 1, + tmp_default)) { + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%s'", + JBHOOK1_CONFIG_SECURITY_MCODE_KEY, + tmp_default); } mcode[8] = '\0'; if (!security_mcode_parse(mcode, &config_security->mcode)) { - log_warning("Invalid mcode '%s' specified, fallback to default '%s'", - mcode, tmp_default); - - memcpy(&config_security->mcode, + log_warning( + "Invalid mcode '%s' specified, fallback to default '%s'", + mcode, + tmp_default); + + memcpy( + &config_security->mcode, &JBHOOK1_CONFIG_SECURITY_DEFAULT_MCODE_VALUE, sizeof(struct security_mcode)); } diff --git a/src/main/jbhook1/config-security.h b/src/main/jbhook1/config-security.h index 266b514..37e1b12 100644 --- a/src/main/jbhook1/config-security.h +++ b/src/main/jbhook1/config-security.h @@ -18,18 +18,17 @@ struct jbhook1_config_security { * Initialize a cconfig structure with the basic structure and default values * of this configuration. */ -void jbhook1_config_security_init(struct cconfig* config); +void jbhook1_config_security_init(struct cconfig *config); /** * Read the module specific config struct values from the provided cconfig * struct. - * + * * @param config_security Target module specific struct to read configuration * values to. * @param config cconfig struct holding the intermediate data to read from. */ void jbhook1_config_security_get( - struct jbhook1_config_security* config_security, - struct cconfig* config); + struct jbhook1_config_security *config_security, struct cconfig *config); #endif \ No newline at end of file diff --git a/src/main/jbhook1/dllmain.c b/src/main/jbhook1/dllmain.c index c836e00..0ce7a57 100644 --- a/src/main/jbhook1/dllmain.c +++ b/src/main/jbhook1/dllmain.c @@ -1,8 +1,8 @@ #include #include -#include #include +#include #include #include "bemanitools/eamio.h" @@ -12,14 +12,14 @@ #include "hook/table.h" -#include "hooklib/adapter.h" #include "hooklib/acp.h" +#include "hooklib/adapter.h" #include "hooklib/rs232.h" -#include "jbhook1/avs-boot.h" #include "jbhook1/acio.h" -#include "jbhook1/config-gfx.h" +#include "jbhook1/avs-boot.h" #include "jbhook1/config-eamuse.h" +#include "jbhook1/config-gfx.h" #include "jbhook1/config-security.h" #include "jbhook1/log-gftools.h" #include "jbhook1/p3io.h" @@ -32,7 +32,7 @@ #include "util/thread.h" #define JBHOOK1_INFO_HEADER \ - "jbhook1 for jubeat" \ + "jbhook1 for jubeat" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) #define JBHOOK1_CMD_USAGE \ "Usage: inject.exe jbhook1.dll [options...]" @@ -42,28 +42,32 @@ static const irp_handler_t jbhook1_handlers[] = { ac_io_port_dispatch_irp, }; -static HWND CDECL my_mwindow_create(HINSTANCE, void*, const char*, DWORD, - DWORD, BOOL); -static HWND (CDECL *real_mwindow_create)(HINSTANCE, void*, const char*, DWORD, - DWORD, BOOL); +static HWND CDECL +my_mwindow_create(HINSTANCE, void *, const char *, DWORD, DWORD, BOOL); +static HWND(CDECL *real_mwindow_create)( + HINSTANCE, void *, const char *, DWORD, DWORD, BOOL); static const struct hook_symbol init_hook_syms[] = { { - .name = "mwindow_create", - .patch = my_mwindow_create, - .link = (void **) &real_mwindow_create, + .name = "mwindow_create", + .patch = my_mwindow_create, + .link = (void **) &real_mwindow_create, }, }; /** - * This seems to be a good entry point to intercept before the game calls + * This seems to be a good entry point to intercept before the game calls * anything important (very close to the start of WinMain). */ -static HWND CDECL my_mwindow_create(HINSTANCE hinstance, void* callback, - const char* window_title, DWORD window_width, DWORD window_height, - BOOL fullscreen) +static HWND CDECL my_mwindow_create( + HINSTANCE hinstance, + void *callback, + const char *window_title, + DWORD window_width, + DWORD window_height, + BOOL fullscreen) { - struct cconfig* config; + struct cconfig *config; struct jbhook1_config_gfx config_gfx; struct jbhook1_config_eamuse config_eamuse; @@ -79,7 +83,10 @@ static HWND CDECL my_mwindow_create(HINSTANCE hinstance, void* callback, jbhook1_config_eamuse_init(config); jbhook1_config_security_init(config); - if (!cconfig_hook_config_init(config, JBHOOK1_INFO_HEADER "\n" JBHOOK1_CMD_USAGE, CCONFIG_CMD_USAGE_OUT_DBG)) { + if (!cconfig_hook_config_init( + config, + JBHOOK1_INFO_HEADER "\n" JBHOOK1_CMD_USAGE, + CCONFIG_CMD_USAGE_OUT_DBG)) { cconfig_finit(config); exit(EXIT_FAILURE); } @@ -101,8 +108,8 @@ static HWND CDECL my_mwindow_create(HINSTANCE hinstance, void* callback, log_info("Starting up jubeat IO backend"); - jb_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning, - log_impl_fatal); + jb_io_set_loggers( + log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); if (!jb_io_init(thread_create, thread_join, thread_destroy)) { log_fatal("Initializing jb IO backend failed"); @@ -110,8 +117,8 @@ static HWND CDECL my_mwindow_create(HINSTANCE hinstance, void* callback, log_info("Starting up card reader backend"); - eam_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning, - log_impl_fatal); + eam_io_set_loggers( + log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); if (!eam_io_init(thread_create, thread_join, thread_destroy)) { log_fatal("Initializing card reader backend failed"); @@ -123,15 +130,20 @@ static HWND CDECL my_mwindow_create(HINSTANCE hinstance, void* callback, ac_io_port_init(); p3io_setupapi_insert_hooks(NULL); - jbhook1_p3io_init(&config_security.mcode, &config_eamuse.pcbid, - &config_eamuse.eamid); + jbhook1_p3io_init( + &config_security.mcode, &config_eamuse.pcbid, &config_eamuse.eamid); log_info("-------------------------------------------------------------"); log_info("----------------- End jbhook mwindow_create -----------------"); log_info("-------------------------------------------------------------"); - return real_mwindow_create(hinstance, callback, window_title, window_width, - window_height, fullscreen); + return real_mwindow_create( + hinstance, + callback, + window_title, + window_width, + window_height, + fullscreen); } /** @@ -141,7 +153,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { #ifdef DEBUG_HOOKING - FILE* file = fopen("jbhook.dllmain.log", "w+"); + FILE *file = fopen("jbhook.dllmain.log", "w+"); log_to_writer(log_writer_file, file); #else log_to_writer(log_writer_null, NULL); @@ -150,11 +162,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) /* Bootstrap hook for further init tasks (see above) */ hook_table_apply( - NULL, - "mwindow.dll", - init_hook_syms, - lengthof(init_hook_syms)); - + NULL, "mwindow.dll", init_hook_syms, lengthof(init_hook_syms)); /* Actual hooks for game specific stuff */ @@ -172,4 +180,3 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) return TRUE; } - diff --git a/src/main/jbhook1/log-gftools.c b/src/main/jbhook1/log-gftools.c index 6974ef6..9772173 100644 --- a/src/main/jbhook1/log-gftools.c +++ b/src/main/jbhook1/log-gftools.c @@ -9,22 +9,32 @@ #include "util/log.h" -static int CDECL my_GFReportPuts(int level, const char* source_file, int a3, - const char* func, const char* msg); +static int CDECL my_GFReportPuts( + int level, + const char *source_file, + int a3, + const char *func, + const char *msg); -static int (CDECL *real_GFReportPuts)(int level, const char* source_file, - int a3, const char* func, const char* msg); +static int(CDECL *real_GFReportPuts)( + int level, + const char *source_file, + int a3, + const char *func, + const char *msg); static const struct hook_symbol jbhook1_log_gftools_hook_syms[] = { - { - .name = "GFReportPuts", - .patch = my_GFReportPuts, - .link = (void **) &real_GFReportPuts - }, + {.name = "GFReportPuts", + .patch = my_GFReportPuts, + .link = (void **) &real_GFReportPuts}, }; -static int CDECL my_GFReportPuts(int level, const char* source_file, int a3, - const char* func, const char* msg) +static int CDECL my_GFReportPuts( + int level, + const char *source_file, + int a3, + const char *func, + const char *msg) { log_misc("[%d][%s][%d][%s]: %s", level, source_file, a3, func, msg); @@ -34,10 +44,10 @@ static int CDECL my_GFReportPuts(int level, const char* source_file, int a3, void jbhook1_log_gftools_init(void) { hook_table_apply( - NULL, - "gftools.dll", - jbhook1_log_gftools_hook_syms, - lengthof(jbhook1_log_gftools_hook_syms)); + NULL, + "gftools.dll", + jbhook1_log_gftools_hook_syms, + lengthof(jbhook1_log_gftools_hook_syms)); log_info("Inserted gftools log hooks"); } \ No newline at end of file diff --git a/src/main/jbhook1/p3io.c b/src/main/jbhook1/p3io.c index 0c0838e..612732e 100644 --- a/src/main/jbhook1/p3io.c +++ b/src/main/jbhook1/p3io.c @@ -10,14 +10,14 @@ #include "p3ioemu/emu.h" #include "p3ioemu/uart.h" -#include "security/rp3.h" #include "security/rp-sign-key.h" +#include "security/rp3.h" #include "util/log.h" static HRESULT jbhook1_p3io_read_jamma(void *ctx, uint32_t *state); -static HRESULT jbhook1_p3io_get_roundplug(void *ctx, uint8_t plug_id, - uint8_t* rom, uint8_t* eeprom); +static HRESULT jbhook1_p3io_get_roundplug( + void *ctx, uint8_t plug_id, uint8_t *rom, uint8_t *eeprom); /* 0:0 b13 @@ -90,8 +90,10 @@ static const struct p3io_ops p3io_ddr_ops = { .get_roundplug = jbhook1_p3io_get_roundplug, }; -void jbhook1_p3io_init(const struct security_mcode* mcode, - const struct security_id* pcbid, const struct security_id* eamid) +void jbhook1_p3io_init( + const struct security_mcode *mcode, + const struct security_id *pcbid, + const struct security_id *eamid) { memcpy(&jbhook1_p3io_mcode, mcode, sizeof(struct security_mcode)); memcpy(&jbhook1_p3io_pcbid, pcbid, sizeof(struct security_id)); @@ -138,8 +140,8 @@ static HRESULT jbhook1_p3io_read_jamma(void *ctx, uint32_t *state) return S_OK; } -static HRESULT jbhook1_p3io_get_roundplug(void *ctx, uint8_t plug_id, - uint8_t* rom, uint8_t* eeprom) +static HRESULT jbhook1_p3io_get_roundplug( + void *ctx, uint8_t plug_id, uint8_t *rom, uint8_t *eeprom) { struct security_rp3_eeprom eeprom_out; @@ -147,14 +149,20 @@ static HRESULT jbhook1_p3io_get_roundplug(void *ctx, uint8_t plug_id, /* black */ memcpy(rom, jbhook1_p3io_pcbid.id, sizeof(jbhook1_p3io_pcbid.id)); security_rp3_generate_signed_eeprom_data( - SECURITY_RP_UTIL_RP_TYPE_BLACK, &security_rp_sign_key_black_gfdmv4, - &jbhook1_p3io_mcode, &jbhook1_p3io_pcbid, &eeprom_out); + SECURITY_RP_UTIL_RP_TYPE_BLACK, + &security_rp_sign_key_black_gfdmv4, + &jbhook1_p3io_mcode, + &jbhook1_p3io_pcbid, + &eeprom_out); } else { /* white */ memcpy(rom, jbhook1_p3io_eamid.id, sizeof(jbhook1_p3io_eamid.id)); security_rp3_generate_signed_eeprom_data( - SECURITY_RP_UTIL_RP_TYPE_WHITE, &security_rp_sign_key_white_eamuse, - &security_mcode_eamuse, &jbhook1_p3io_eamid, &eeprom_out); + SECURITY_RP_UTIL_RP_TYPE_WHITE, + &security_rp_sign_key_white_eamuse, + &security_mcode_eamuse, + &jbhook1_p3io_eamid, + &eeprom_out); } memcpy(eeprom, &eeprom_out, sizeof(struct security_rp3_eeprom)); diff --git a/src/main/jbhook1/p3io.h b/src/main/jbhook1/p3io.h index 383d261..3838969 100644 --- a/src/main/jbhook1/p3io.h +++ b/src/main/jbhook1/p3io.h @@ -10,13 +10,15 @@ /** * Initialize the jbhook1 specific p3io emulation backend. - * + * * @param mcode Mcode of the target game to run. Required for dongle emulation. * @param pcbid PCBDID * @param eamid EAMID */ -void jbhook1_p3io_init(const struct security_mcode* mcode, - const struct security_id* pcbid, const struct security_id* eamid); +void jbhook1_p3io_init( + const struct security_mcode *mcode, + const struct security_id *pcbid, + const struct security_id *eamid); /** * Shutdown the p3io emulation backend. diff --git a/src/main/jbio/jbio.c b/src/main/jbio/jbio.c index f793aba..b45905e 100644 --- a/src/main/jbio/jbio.c +++ b/src/main/jbio/jbio.c @@ -8,8 +8,8 @@ the "bemanitools" header files included by this source file for detailed information about the API you'll need to implement. */ -#include #include +#include #include "bemanitools/input.h" #include "bemanitools/jbio.h" @@ -26,8 +26,11 @@ static log_formatter_t jb_io_log_warning; static log_formatter_t jb_io_log_fatal; #endif -void jb_io_set_loggers(log_formatter_t misc, log_formatter_t info, - log_formatter_t warning, log_formatter_t fatal) +void jb_io_set_loggers( + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal) { /* Pass logger functions on to geninput so that it has somewhere to write its own log output. */ @@ -47,8 +50,10 @@ void jb_io_set_loggers(log_formatter_t misc, log_formatter_t info, #endif } -bool jb_io_init(thread_create_t thread_create, thread_join_t thread_join, - thread_destroy_t thread_destroy) +bool jb_io_init( + thread_create_t thread_create, + thread_join_t thread_join, + thread_destroy_t thread_destroy) { timeBeginPeriod(1); diff --git a/src/main/launcher/avs-context.c b/src/main/launcher/avs-context.c index 23ac331..1e391db 100644 --- a/src/main/launcher/avs-context.c +++ b/src/main/launcher/avs-context.c @@ -16,31 +16,44 @@ static void *avs_heap; static void *std_heap; #endif -void avs_context_init(struct property_node *config, - uint32_t avs_heap_size, uint32_t std_heap_size, - avs_log_writer_t log_writer, void *log_writer_ctx) +void avs_context_init( + struct property_node *config, + uint32_t avs_heap_size, + uint32_t std_heap_size, + avs_log_writer_t log_writer, + void *log_writer_ctx) { - avs_heap = VirtualAlloc(NULL, avs_heap_size, MEM_RESERVE | MEM_COMMIT, - PAGE_READWRITE); + avs_heap = VirtualAlloc( + NULL, avs_heap_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); if (avs_heap == NULL) { - log_fatal("Failed to VirtualAlloc %d byte AVS heap: %08x", - avs_heap_size, (unsigned int) GetLastError()); + log_fatal( + "Failed to VirtualAlloc %d byte AVS heap: %08x", + avs_heap_size, + (unsigned int) GetLastError()); } #ifdef AVS_HAS_STD_HEAP - std_heap = VirtualAlloc(NULL, std_heap_size, MEM_RESERVE | MEM_COMMIT, - PAGE_READWRITE); + std_heap = VirtualAlloc( + NULL, std_heap_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); if (std_heap == NULL) { - log_fatal("Failed to VirtualAlloc %d byte \"std\" heap: %08x", - std_heap_size, (unsigned int) GetLastError()); + log_fatal( + "Failed to VirtualAlloc %d byte \"std\" heap: %08x", + std_heap_size, + (unsigned int) GetLastError()); } #endif #ifdef AVS_HAS_STD_HEAP - avs_boot(config, std_heap, std_heap_size, avs_heap, avs_heap_size, - log_writer, log_writer_ctx); + avs_boot( + config, + std_heap, + std_heap_size, + avs_heap, + avs_heap_size, + log_writer, + log_writer_ctx); #else /* AVS v2.16.xx and I suppose onward uses a unified heap */ avs_boot(config, avs_heap, avs_heap_size, NULL, log_writer, log_writer_ctx); @@ -57,4 +70,3 @@ void avs_context_fini(void) VirtualFree(avs_heap, 0, MEM_RELEASE); } - diff --git a/src/main/launcher/avs-context.h b/src/main/launcher/avs-context.h index 551e324..d4532eb 100644 --- a/src/main/launcher/avs-context.h +++ b/src/main/launcher/avs-context.h @@ -9,9 +9,12 @@ #define AVS_HAS_STD_HEAP #endif -void avs_context_init(struct property_node *config, - uint32_t avs_heap_size, uint32_t std_heap_size, - avs_log_writer_t log_writer, void *log_writer_ctx); +void avs_context_init( + struct property_node *config, + uint32_t avs_heap_size, + uint32_t std_heap_size, + avs_log_writer_t log_writer, + void *log_writer_ctx); void avs_context_fini(void); #endif diff --git a/src/main/launcher/ea3-config.c b/src/main/launcher/ea3-config.c index 4ed31d3..c57fa77 100644 --- a/src/main/launcher/ea3-config.c +++ b/src/main/launcher/ea3-config.c @@ -11,14 +11,14 @@ #include "util/str.h" PSMAP_BEGIN(ea3_ident_psmap) -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct ea3_ident, softid,"/ea3/id/softid","") -PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct ea3_ident, hardid,"/ea3/id/hardid","") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct ea3_ident, softid, "/ea3/id/softid", "") +PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct ea3_ident, hardid, "/ea3/id/hardid", "") PSMAP_OPTIONAL(PSMAP_TYPE_STR, struct ea3_ident, pcbid, "/ea3/id/pcbid", "") PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident, model, "/ea3/soft/model") -PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident, dest, "/ea3/soft/dest") -PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident, spec, "/ea3/soft/spec") -PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident, rev, "/ea3/soft/rev") -PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident, ext, "/ea3/soft/ext") +PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident, dest, "/ea3/soft/dest") +PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident, spec, "/ea3/soft/spec") +PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident, rev, "/ea3/soft/rev") +PSMAP_REQUIRED(PSMAP_TYPE_STR, struct ea3_ident, ext, "/ea3/soft/ext") PSMAP_END void ea3_ident_init(struct ea3_ident *ident) @@ -26,8 +26,8 @@ void ea3_ident_init(struct ea3_ident *ident) memset(ident, 0, sizeof(*ident)); } -bool ea3_ident_from_property(struct ea3_ident *ident, - struct property *ea3_config) +bool ea3_ident_from_property( + struct ea3_ident *ident, struct property *ea3_config) { return property_psmap_import(ea3_config, NULL, ident, ea3_ident_psmap); } @@ -40,8 +40,8 @@ void ea3_ident_hardid_from_ethernet(struct ea3_ident *ident) result = avs_net_ctrl(1, &netif, sizeof(netif)); if (result < 0) { - log_fatal("avs_net_ctrl call to get MAC address returned error: %d", - result); + log_fatal( + "avs_net_ctrl call to get MAC address returned error: %d", result); } ident->hardid[0] = '0'; @@ -49,12 +49,17 @@ void ea3_ident_hardid_from_ethernet(struct ea3_ident *ident) ident->hardid[2] = '0'; ident->hardid[3] = '0'; - hex_encode_uc(netif.mac_addr, sizeof(netif.mac_addr), - ident->hardid + 4, sizeof(ident->hardid) - 4); + hex_encode_uc( + netif.mac_addr, + sizeof(netif.mac_addr), + ident->hardid + 4, + sizeof(ident->hardid) - 4); } -bool ea3_ident_invoke_module_init(struct ea3_ident *ident, - const struct module_context *module, struct property_node *app_config) +bool ea3_ident_invoke_module_init( + struct ea3_ident *ident, + const struct module_context *module, + struct property_node *app_config) { char sidcode_short[17]; char sidcode_long[21]; @@ -63,8 +68,14 @@ bool ea3_ident_invoke_module_init(struct ea3_ident *ident, /* Set up security env vars */ - str_format(security_code, lengthof(security_code), "G*%s%s%s%s", - ident->model, ident->dest, ident->spec, ident->rev); + str_format( + security_code, + lengthof(security_code), + "G*%s%s%s%s", + ident->model, + ident->dest, + ident->spec, + ident->rev); std_setenv("/env/boot/version", "0.0.0"); std_setenv("/env/profile/security_code", security_code); @@ -76,8 +87,15 @@ bool ea3_ident_invoke_module_init(struct ea3_ident *ident, /* Set up the short sidcode string, let dll_entry_init mangle it */ - str_format(sidcode_short, lengthof(sidcode_short), "%s%s%s%s%s", - ident->model, ident->dest, ident->spec, ident->rev, ident->ext); + str_format( + sidcode_short, + lengthof(sidcode_short), + "%s%s%s%s%s", + ident->model, + ident->dest, + ident->spec, + ident->rev, + ident->ext); ok = module_context_invoke_init(module, sidcode_short, app_config); @@ -95,21 +113,28 @@ bool ea3_ident_invoke_module_init(struct ea3_ident *ident, /* Set up long-form sidcode env var */ - str_format(sidcode_long, lengthof(sidcode_long), "%s:%s:%s:%s:%s", - ident->model, ident->dest, ident->spec, ident->rev, ident->ext); + str_format( + sidcode_long, + lengthof(sidcode_long), + "%s:%s:%s:%s:%s", + ident->model, + ident->dest, + ident->spec, + ident->rev, + ident->ext); std_setenv("/env/profile/soft_id_code", sidcode_long); return true; } -void ea3_ident_to_property(const struct ea3_ident *ident, - struct property *ea3_config) +void ea3_ident_to_property( + const struct ea3_ident *ident, struct property *ea3_config) { struct property_node *node; int i; - for (i = 0 ; ea3_ident_psmap[i].type != 0xFF ; i++) { + for (i = 0; ea3_ident_psmap[i].type != 0xFF; i++) { node = property_search(ea3_config, 0, ea3_ident_psmap[i].path); if (node != NULL) { @@ -119,4 +144,3 @@ void ea3_ident_to_property(const struct ea3_ident *ident, property_psmap_export(ea3_config, NULL, ident, ea3_ident_psmap); } - diff --git a/src/main/launcher/ea3-config.h b/src/main/launcher/ea3-config.h index 72a1775..ccc2835 100644 --- a/src/main/launcher/ea3-config.h +++ b/src/main/launcher/ea3-config.h @@ -29,12 +29,14 @@ struct ea3_ident { }; void ea3_ident_init(struct ea3_ident *ident); -bool ea3_ident_from_property(struct ea3_ident *ident, - struct property *ea3_config); +bool ea3_ident_from_property( + struct ea3_ident *ident, struct property *ea3_config); void ea3_ident_hardid_from_ethernet(struct ea3_ident *ident); -bool ea3_ident_invoke_module_init(struct ea3_ident *ident, - const struct module_context *module, struct property_node *app_config); -void ea3_ident_to_property(const struct ea3_ident *ident, - struct property *ea3_config); +bool ea3_ident_invoke_module_init( + struct ea3_ident *ident, + const struct module_context *module, + struct property_node *app_config); +void ea3_ident_to_property( + const struct ea3_ident *ident, struct property *ea3_config); #endif diff --git a/src/main/launcher/main.c b/src/main/launcher/main.c index 609a4f5..05cfb27 100644 --- a/src/main/launcher/main.c +++ b/src/main/launcher/main.c @@ -5,8 +5,8 @@ #include #include -#include "imports/avs.h" #include "imports/avs-ea3.h" +#include "imports/avs.h" #include "launcher/avs-context.h" #include "launcher/ea3-config.h" @@ -15,11 +15,11 @@ #include "launcher/property.h" #include "launcher/stubs.h" +#include "util/codepage.h" #include "util/defs.h" #include "util/log.h" #include "util/mem.h" #include "util/str.h" -#include "util/codepage.h" /* Gratuitous API changes orz */ static AVS_LOG_WRITER(log_callback, chars, nchars, ctx) @@ -46,23 +46,23 @@ static AVS_LOG_WRITER(log_callback, chars, nchars, ctx) } utf16 = xmalloc(sizeof(*utf16) * utf16_len); - result = MultiByteToWideChar(CP_SHIFT_JIS, 0, chars, nchars, utf16, - utf16_len); + result = + MultiByteToWideChar(CP_SHIFT_JIS, 0, chars, nchars, utf16, utf16_len); if (result == 0) { abort(); } - utf8_len = WideCharToMultiByte(CP_UTF8, 0, utf16, utf16_len, NULL, 0, - NULL, NULL); + utf8_len = + WideCharToMultiByte(CP_UTF8, 0, utf16, utf16_len, NULL, 0, NULL, NULL); if (utf8_len == 0) { abort(); } utf8 = xmalloc(utf8_len + 2); - result = WideCharToMultiByte(CP_UTF8, 0, utf16, utf16_len, utf8, utf8_len, - NULL, NULL); + result = WideCharToMultiByte( + CP_UTF8, 0, utf16, utf16_len, utf8, utf8_len, NULL, NULL); if (result == 0) { abort(); @@ -123,17 +123,18 @@ int main(int argc, const char **argv) return EXIT_FAILURE; } - /* If enabled, wait for a remote debugger to attach. Spawning launcher - with a debugger crashes it for some reason (e.g. on jubeat08). However, + /* If enabled, wait for a remote debugger to attach. Spawning launcher + with a debugger crashes it for some reason (e.g. on jubeat08). However, starting the launcher separately and attaching a remote debugger works */ if (options.remote_debugger) { log_info("Waiting until debugger attaches to remote process..."); - + while (true) { BOOL res = FALSE; if (!CheckRemoteDebuggerPresent(GetCurrentProcess(), &res)) { - log_fatal("CheckRemoteDebuggerPresent failed: %08x", + log_fatal( + "CheckRemoteDebuggerPresent failed: %08x", (unsigned int) GetLastError()); } @@ -149,8 +150,14 @@ int main(int argc, const char **argv) /* Start up AVS */ if (options.logfile != NULL) { - logfile = CreateFileA(options.logfile, GENERIC_WRITE, FILE_SHARE_READ, - NULL, CREATE_ALWAYS, 0, NULL); + logfile = CreateFileA( + options.logfile, + GENERIC_WRITE, + FILE_SHARE_READ, + NULL, + CREATE_ALWAYS, + 0, + NULL); } else { logfile = INVALID_HANDLE_VALUE; } @@ -162,14 +169,17 @@ int main(int argc, const char **argv) log_fatal("%s: /config missing", options.avs_config_path); } - avs_context_init(avs_config_root, - options.avs_heap_size, options.std_heap_size, - log_callback, logfile); + avs_context_init( + avs_config_root, + options.avs_heap_size, + options.std_heap_size, + log_callback, + logfile); boot_property_free(avs_config); - log_to_external(log_body_misc, log_body_info, log_body_warning, - log_body_fatal); + log_to_external( + log_body_misc, log_body_info, log_body_warning, log_body_fatal); /* Load game DLL */ @@ -177,14 +187,21 @@ int main(int argc, const char **argv) /* Load hook DLLs */ - for (i = 0 ; i < options.hook_dlls.nitems ; i++) { + for (i = 0; i < options.hook_dlls.nitems; i++) { hook_dll = *array_item(char *, &options.hook_dlls, i); if (LoadLibraryA(hook_dll) == NULL) { - LPSTR buffer; + LPSTR buffer; - FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR) &buffer, 0, NULL); + FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR) &buffer, + 0, + NULL); log_fatal("%s: Failed to load hook DLL: %s", hook_dll, buffer); @@ -208,8 +225,8 @@ int main(int argc, const char **argv) ea3_ident_init(&ea3); if (!ea3_ident_from_property(&ea3, ea3_config)) { - log_fatal("%s: Error reading IDs from config file", - options.ea3_config_path); + log_fatal( + "%s: Error reading IDs from config file", options.ea3_config_path); } if (options.softid != NULL) { @@ -273,4 +290,3 @@ int main(int argc, const char **argv) return EXIT_SUCCESS; } - diff --git a/src/main/launcher/module.c b/src/main/launcher/module.c index 8003fbb..521a301 100644 --- a/src/main/launcher/module.c +++ b/src/main/launcher/module.c @@ -18,8 +18,15 @@ void module_context_init(struct module_context *module, const char *path) if (module->dll == NULL) { LPSTR buffer; - FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR) &buffer, 0, NULL); + FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR) &buffer, + 0, + NULL); log_fatal("%s: Failed to load game DLL: %s", path, buffer); @@ -29,8 +36,10 @@ void module_context_init(struct module_context *module, const char *path) module->path = str_dup(path); } -bool module_context_invoke_init(const struct module_context *module, - char *sidcode, struct property_node *app_config) +bool module_context_invoke_init( + const struct module_context *module, + char *sidcode, + struct property_node *app_config) { dll_entry_init_t init; @@ -42,8 +51,7 @@ bool module_context_invoke_init(const struct module_context *module, if (init == NULL) { log_fatal( - "%s: dll_entry_init not found. Is this a game DLL?", - module->path); + "%s: dll_entry_init not found. Is this a game DLL?", module->path); } return init(sidcode, app_config); @@ -60,8 +68,7 @@ bool module_context_invoke_main(const struct module_context *module) if (main_ == NULL) { log_fatal( - "%s: dll_entry_main not found. Is this a game DLL?", - module->path); + "%s: dll_entry_main not found. Is this a game DLL?", module->path); } return main_(); @@ -79,4 +86,3 @@ void module_context_fini(struct module_context *module) FreeLibrary(module->dll); } } - diff --git a/src/main/launcher/module.h b/src/main/launcher/module.h index c93944b..978eab6 100644 --- a/src/main/launcher/module.h +++ b/src/main/launcher/module.h @@ -11,8 +11,10 @@ struct module_context { }; void module_context_init(struct module_context *module, const char *path); -bool module_context_invoke_init(const struct module_context *module, - char *sidcode, struct property_node *app_config); +bool module_context_invoke_init( + const struct module_context *module, + char *sidcode, + struct property_node *app_config); bool module_context_invoke_main(const struct module_context *module); void module_context_fini(struct module_context *module); diff --git a/src/main/launcher/options.c b/src/main/launcher/options.c index a0ee95e..11c1b51 100644 --- a/src/main/launcher/options.c +++ b/src/main/launcher/options.c @@ -27,7 +27,7 @@ void options_init(struct options *options) bool options_read_cmdline(struct options *options, int argc, const char **argv) { - for (int i = 1 ; i < argc ; i++) { + for (int i = 1; i < argc; i++) { if (argv[i][0] == '-') { switch (argv[i][1]) { case 'A': @@ -80,7 +80,8 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) return false; } - options->avs_heap_size = (size_t)strtol(argv[++i],NULL,0); + options->avs_heap_size = + (size_t) strtol(argv[++i], NULL, 0); if (options->avs_heap_size == 0) { return false; @@ -94,7 +95,8 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) return false; } - options->std_heap_size = (size_t)strtol(argv[++i],NULL,0); + options->std_heap_size = + (size_t) strtol(argv[++i], NULL, 0); if (options->std_heap_size == 0) { return false; @@ -108,7 +110,8 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) return false; } - *array_append(const char *,&options->hook_dlls)=argv[++i]; + *array_append(const char *, &options->hook_dlls) = + argv[++i]; break; @@ -145,29 +148,35 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) void options_print_usage(void) { - fprintf(stderr, -"Usage: launcher.exe [launcher options...] [hooks options...] \n" -"\n" -" The following options can be specified before the app DLL path:\n" -"\n" -" -A [filename] App configuration file (default: prop/app-config.xml)\n" -" -V [filename] AVS configuration file (default: prop/avs-config.xml)\n" -" -E [filename] ea3 configuration file (default: prop/ea3-config.xml)\n" -" -H [bytes] AVS heap size (default: 16777216)\n" + fprintf( + stderr, + "Usage: launcher.exe [launcher options...] [hooks " + "options...] \n" + "\n" + " The following options can be specified before the app DLL " + "path:\n" + "\n" + " -A [filename] App configuration file (default: " + "prop/app-config.xml)\n" + " -V [filename] AVS configuration file (default: " + "prop/avs-config.xml)\n" + " -E [filename] ea3 configuration file (default: " + "prop/ea3-config.xml)\n" + " -H [bytes] AVS heap size (default: 16777216)\n" #ifdef AVS_HAS_STD_HEAP -" -T [bytes] 'std' heap size (default 16777216)\n" + " -T [bytes] 'std' heap size (default 16777216)\n" #endif -" -P [pcbid] Specify PCBID (default: use ea3 config)\n" -" -R [pcbid] Specify Soft ID (default: use ea3 config)\n" -" -K [filename] Load hook DLL (can be specified multiple times)\n" -" -Y [filename] Log to a file in addition to the console\n" -" -D Halt the launcher before bootstrapping AVS until a" -" remote debugger is attached\n" - ); + " -P [pcbid] Specify PCBID (default: use ea3 config)\n" + " -R [pcbid] Specify Soft ID (default: use ea3 config)\n" + " -K [filename] Load hook DLL (can be specified multiple " + "times)\n" + " -Y [filename] Log to a file in addition to the console\n" + " -D Halt the launcher before bootstrapping AVS " + "until a" + " remote debugger is attached\n"); } void options_fini(struct options *options) { array_fini(&options->hook_dlls); } - diff --git a/src/main/launcher/property.c b/src/main/launcher/property.c index 6079158..9274e0f 100644 --- a/src/main/launcher/property.c +++ b/src/main/launcher/property.c @@ -49,12 +49,10 @@ struct property *boot_property_load(const char *filename) buffer = xmalloc(nbytes); prop = property_create( - PROPERTY_FLAG_READ | - PROPERTY_FLAG_WRITE | - PROPERTY_FLAG_CREATE | - PROPERTY_FLAG_APPEND, - buffer, - nbytes); + PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE | + PROPERTY_FLAG_APPEND, + buffer, + nbytes); rewind(f); if (!property_insert_read(prop, 0, boot_property_fread, f_keyhole)) { @@ -76,4 +74,3 @@ void boot_property_free(struct property *prop) property_destroy(prop); free(buffer); } - diff --git a/src/main/launcher/stubs.c b/src/main/launcher/stubs.c index ca269b1..08311c7 100644 --- a/src/main/launcher/stubs.c +++ b/src/main/launcher/stubs.c @@ -31,7 +31,7 @@ typedef void (*bt_get_fucked_t)(uint32_t /* even in 64-bit */ context); static HMODULE STDCALL my_GetModuleHandleA(const char *name); static HMODULE STDCALL my_GetModuleHandleW(const wchar_t *name); -static void * STDCALL my_GetProcAddress(HMODULE dll, const char *name); +static void *STDCALL my_GetProcAddress(HMODULE dll, const char *name); static void bt_get_ikey_status(struct ikey_status *ik); @@ -43,47 +43,40 @@ static void bt_fcheck_init(void); static void *bt_fcheck_main(void *unknown); static void bt_fcheck_finish(void); -static HMODULE (STDCALL *real_GetModuleHandleA)(const char *name); -static HMODULE (STDCALL *real_GetModuleHandleW)(const wchar_t *name); -static void * (STDCALL *real_GetProcAddress)(HMODULE dll, const char *name); +static HMODULE(STDCALL *real_GetModuleHandleA)(const char *name); +static HMODULE(STDCALL *real_GetModuleHandleW)(const wchar_t *name); +static void *(STDCALL *real_GetProcAddress)(HMODULE dll, const char *name); static struct stub stub_list[] = { #if AVS_VERSION >= 1600 - { "k_bt0001", bt_get_ikey_status }, - { "k_bt0002", bt_get_fucked }, + {"k_bt0001", bt_get_ikey_status}, + {"k_bt0002", bt_get_fucked}, #else - { "bt_get_ikey_status", bt_get_ikey_status }, + {"bt_get_ikey_status", bt_get_ikey_status}, #endif - { "bt_fcheck_init", bt_fcheck_init }, - { "bt_fcheck_main", bt_fcheck_main }, - { "bt_fcheck_finish", bt_fcheck_finish }, + {"bt_fcheck_init", bt_fcheck_init}, + {"bt_fcheck_main", bt_fcheck_main}, + {"bt_fcheck_finish", bt_fcheck_finish}, }; static struct hook_symbol stub_hook_syms[] = { - { - .name = "GetModuleHandleA", - .patch = my_GetModuleHandleA, - .link = (void *)&real_GetModuleHandleA - }, - { - .name = "GetModuleHandleW", - .patch = my_GetModuleHandleW, - .link = (void *)&real_GetModuleHandleW - }, - { - .name = "GetProcAddress", - .patch = my_GetProcAddress, - .link = (void *)&real_GetProcAddress - }, + {.name = "GetModuleHandleA", + .patch = my_GetModuleHandleA, + .link = (void *) &real_GetModuleHandleA}, + {.name = "GetModuleHandleW", + .patch = my_GetModuleHandleW, + .link = (void *) &real_GetModuleHandleW}, + {.name = "GetProcAddress", + .patch = my_GetProcAddress, + .link = (void *) &real_GetProcAddress}, }; static HMODULE STDCALL my_GetModuleHandleA(const char *name) { /* Check name for null because winio32 calls this with null parameters when the module is loaded on win xp (doesn't happen on win 7) */ - if ( name != NULL && - (_stricmp(name, "kbt.dll") == 0 || - _stricmp(name, "kld.dll") == 0)) { + if (name != NULL && + (_stricmp(name, "kbt.dll") == 0 || _stricmp(name, "kld.dll") == 0)) { name = NULL; } @@ -94,16 +87,15 @@ static HMODULE STDCALL my_GetModuleHandleW(const wchar_t *name) { /* Check name for null because winio32 calls this with null parameters when the module is loaded on win xp (doesn't happen on win 7) */ - if ( name != NULL && - (wcsicmp(name, L"kbt.dll") == 0 || - wcsicmp(name, L"kld.dll") == 0)) { + if (name != NULL && + (wcsicmp(name, L"kbt.dll") == 0 || wcsicmp(name, L"kld.dll") == 0)) { name = NULL; } return real_GetModuleHandleW(name); } -static void * STDCALL my_GetProcAddress(HMODULE dll, const char *name) +static void *STDCALL my_GetProcAddress(HMODULE dll, const char *name) { size_t i; @@ -111,7 +103,7 @@ static void * STDCALL my_GetProcAddress(HMODULE dll, const char *name) return real_GetProcAddress(dll, name); } - for (i = 0 ; i < lengthof(stub_list) ; i++) { + for (i = 0; i < lengthof(stub_list); i++) { if (strcmp(stub_list[i].name, name) == 0) { return stub_list[i].proc; } @@ -125,10 +117,7 @@ static void * STDCALL my_GetProcAddress(HMODULE dll, const char *name) void stubs_init(void) { hook_table_apply( - NULL, - "kernel32.dll", - stub_hook_syms, - lengthof(stub_hook_syms)); + NULL, "kernel32.dll", stub_hook_syms, lengthof(stub_hook_syms)); } static void bt_get_ikey_status(struct ikey_status *ik) @@ -155,7 +144,8 @@ static void bt_get_fucked(bt_get_fucked_t callback, uint32_t ctx) #endif static void bt_fcheck_init(void) -{} +{ +} static void *bt_fcheck_main(void *unknown) { @@ -163,5 +153,5 @@ static void *bt_fcheck_main(void *unknown) } static void bt_fcheck_finish(void) -{} - +{ +} diff --git a/src/main/mempatch-hook/main.c b/src/main/mempatch-hook/main.c index e395242..0eb5e98 100644 --- a/src/main/mempatch-hook/main.c +++ b/src/main/mempatch-hook/main.c @@ -8,17 +8,22 @@ #include "util/hex.h" #include "util/log.h" -static bool patch_memory_check_data(uint32_t base_address, uint32_t address, - uint8_t* data_expected, size_t len) +static bool patch_memory_check_data( + uint32_t base_address, uint32_t address, uint8_t *data_expected, size_t len) { - uint8_t* dest = (uint8_t*) (base_address + address); + uint8_t *dest = (uint8_t *) (base_address + address); bool success = true; for (size_t i = 0; i < len; i++) { if (dest[i] != data_expected[i]) { - log_warning("Memcheck error: base %X + address %X + offset %d: " - "expected %X, found %X", base_address, address, i, - data_expected[i], dest[i]); + log_warning( + "Memcheck error: base %X + address %X + offset %d: " + "expected %X, found %X", + base_address, + address, + i, + data_expected[i], + dest[i]); success = false; } } @@ -26,25 +31,34 @@ static bool patch_memory_check_data(uint32_t base_address, uint32_t address, return success; } -static bool patch_memory_data(uint32_t base_address, uint32_t address, - uint8_t* data, size_t len) +static bool patch_memory_data( + uint32_t base_address, uint32_t address, uint8_t *data, size_t len) { DWORD old_protect; uint32_t dest = base_address + address; - if (!VirtualProtect((void*) dest, sizeof(uint8_t) * len, - PAGE_EXECUTE_READWRITE, &old_protect)) { - log_warning("VirtualProtect %X (%d) failed: %d", dest, len, + if (!VirtualProtect( + (void *) dest, + sizeof(uint8_t) * len, + PAGE_EXECUTE_READWRITE, + &old_protect)) { + log_warning( + "VirtualProtect %X (%d) failed: %d", + dest, + len, (int) GetLastError()); return false; } - memcpy((void*) (base_address + address), data, len); + memcpy((void *) (base_address + address), data, len); - if (!VirtualProtect((void*) dest, sizeof(uint8_t) * len, old_protect, - &old_protect)) { - log_warning("VirtualProtect (2) %X (%d) failed: %d", dest, len, + if (!VirtualProtect( + (void *) dest, sizeof(uint8_t) * len, old_protect, &old_protect)) { + log_warning( + "VirtualProtect (2) %X (%d) failed: %d", + dest, + len, (int) GetLastError()); return false; } @@ -52,21 +66,21 @@ static bool patch_memory_data(uint32_t base_address, uint32_t address, return true; } -static bool patch_memory_apply(char* script) +static bool patch_memory_apply(char *script) { - char* pos_lines; - char* ctx_lines; + char *pos_lines; + char *ctx_lines; uint32_t line_cnt; - char* pos_line; - char* ctx_line; + char *pos_line; + char *ctx_line; uint32_t line_tokens; - char* module; - char* address_str = NULL; - char* data_str = NULL; + char *module; + char *address_str = NULL; + char *data_str = NULL; size_t data_str_len; - char* data_expected_str = NULL; + char *data_expected_str = NULL; size_t data_expected_str_len; uint32_t address; @@ -119,7 +133,10 @@ static bool patch_memory_apply(char* script) } if (line_tokens != 3 && line_tokens != 4) { - log_warning("[%d] Invalid number of elements in line '%s' skipping", line_cnt, pos_lines); + log_warning( + "[%d] Invalid number of elements in line '%s' skipping", + line_cnt, + pos_lines); goto error_next_line; } @@ -129,7 +146,8 @@ static bool patch_memory_apply(char* script) hmodule = GetModuleHandleA(module); if (hmodule == NULL) { - log_warning("[%d] Could not find module %s", line_cnt, module); + log_warning( + "[%d] Could not find module %s", line_cnt, module); goto error_next_line; } @@ -147,8 +165,11 @@ static bool patch_memory_apply(char* script) data_len = data_str_len; if (data_len % 2 != 0) { - log_warning("[%d] Data length %d mod 2 != 0: %s", line_cnt, - data_len, data_str); + log_warning( + "[%d] Data length %d mod 2 != 0: %s", + line_cnt, + data_len, + data_str); goto error_next_line; } @@ -159,8 +180,11 @@ static bool patch_memory_apply(char* script) data_expected_len = data_expected_str_len; if (data_expected_len % 2 != 0) { - log_warning("[%d] Data expected length %d mod 2 != 0: %s", - line_cnt, data_len, data_str); + log_warning( + "[%d] Data expected length %d mod 2 != 0: %s", + line_cnt, + data_len, + data_str); goto error_next_line; } } else { @@ -170,24 +194,33 @@ static bool patch_memory_apply(char* script) data_expected_len /= 2; if (!hex_decode(data, sizeof(data), data_str, data_str_len)) { - log_warning("[%d] Decoding data (item 3) failed: %s", line_cnt, + log_warning( + "[%d] Decoding data (item 3) failed: %s", + line_cnt, data_str); goto error_next_line; } if (line_tokens == 4) { - if (!hex_decode(data_expected, sizeof(data_expected), - data_expected_str, data_expected_str_len)) { + if (!hex_decode( + data_expected, + sizeof(data_expected), + data_expected_str, + data_expected_str_len)) { log_warning( "[%d] Decoding expected data (item 4) failed: %s", - line_cnt, data_expected_str); + line_cnt, + data_expected_str); goto error_next_line; } } if (data_expected_len) { - if (!patch_memory_check_data(address_base, address, - data_expected, data_expected_len)) { + if (!patch_memory_check_data( + address_base, + address, + data_expected, + data_expected_len)) { log_warning("[%d] Memcheck failed, skipping", line_cnt); goto error_next_line; } @@ -201,12 +234,12 @@ static bool patch_memory_apply(char* script) log_info("[%d] Patch ok", line_cnt); } - goto next_line; + goto next_line; -error_next_line: - error = true; + error_next_line: + error = true; -next_line: + next_line: pos_lines = strtok_r(NULL, "\n", &ctx_lines); line_cnt++; } @@ -214,16 +247,17 @@ next_line: return !error; } -static void patch_memory_from_file(const char* filepath) +static void patch_memory_from_file(const char *filepath) { - char* buffer; + char *buffer; size_t len; - if (!file_load(filepath, (void**) &buffer, &len, true)) { + if (!file_load(filepath, (void **) &buffer, &len, true)) { log_fatal("Load script file %s failed", filepath); } else { if (!patch_memory_apply(buffer)) { - log_fatal("Applying one or multiple patches failed, see log output " + log_fatal( + "Applying one or multiple patches failed, see log output " "for details"); } } @@ -235,9 +269,9 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) { if (reason == DLL_PROCESS_ATTACH) { int argc; - char** argv; - char* filepath; - FILE* logfile; + char **argv; + char *filepath; + FILE *logfile; bool patched; patched = false; @@ -261,10 +295,13 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) } if (!patched) { - log_info("No files specified for patching. Add the parameter " - "--mempatch to your application arguments. This can " + log_info( + "No files specified for patching. Add the parameter " + "--mempatch to your application arguments. This " + "can " "be specified multiple times, e.g. --mempatch file1.mph " - "--mempatch file2.mph. The patches are executed in the order " + "--mempatch file2.mph. The patches are executed in the " + "order " "they are specified."); } else { log_info("Patching done"); diff --git a/src/main/mm/mm.c b/src/main/mm/mm.c index 26bc8f6..8dd98d0 100644 --- a/src/main/mm/mm.c +++ b/src/main/mm/mm.c @@ -1,9 +1,9 @@ -#include -#include #include +#include +#include -#include #include +#include #include #include @@ -16,8 +16,19 @@ #include "util/log.h" #include "util/mem.h" -DEFINE_GUID(hid_guid, 0x4D1E55B2L, 0xF16F, 0x11CF, 0x88, 0xCB, 0x00, \ - 0x11, 0x11, 0x00, 0x00, 0x30); +DEFINE_GUID( + hid_guid, + 0x4D1E55B2L, + 0xF16F, + 0x11CF, + 0x88, + 0xCB, + 0x00, + 0x11, + 0x11, + 0x00, + 0x00, + 0x30); static HANDLE mm_fd; @@ -32,8 +43,8 @@ static OVERLAPPED mm_out_ovl; static bool mm_out_pending; static HANDLE mm_open_device(void); -static HANDLE mm_try_device(HDEVINFO dev_info, - SP_DEVICE_INTERFACE_DATA *iface_data); +static HANDLE +mm_try_device(HDEVINFO dev_info, SP_DEVICE_INTERFACE_DATA *iface_data); static HANDLE mm_open_device(void) { @@ -44,32 +55,25 @@ static HANDLE mm_open_device(void) BOOL ok; dev_info = SetupDiGetClassDevsW( - &hid_guid, - NULL, - NULL, - DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); + &hid_guid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); if (dev_info == NULL) { log_fatal("SetupDiGetClassDevs failed"); } - for (i = 0, cur_fd = NULL ; cur_fd == NULL ; i++) { + for (i = 0, cur_fd = NULL; cur_fd == NULL; i++) { iface_data.cbSize = sizeof(iface_data); ok = SetupDiEnumDeviceInterfaces( - dev_info, - NULL, - &hid_guid, - i, - &iface_data); + dev_info, NULL, &hid_guid, i, &iface_data); if (!ok) { if (GetLastError() == ERROR_NO_MORE_ITEMS) { break; } else { log_fatal( - "SetupDiEnumDeviceInterfaces failed: %#x", - (int) GetLastError()); + "SetupDiEnumDeviceInterfaces failed: %#x", + (int) GetLastError()); } } @@ -81,8 +85,8 @@ static HANDLE mm_open_device(void) return cur_fd; } -static HANDLE mm_try_device(HDEVINFO dev_info, - SP_DEVICE_INTERFACE_DATA *iface_data) +static HANDLE +mm_try_device(HDEVINFO dev_info, SP_DEVICE_INTERFACE_DATA *iface_data) { SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail; HIDD_ATTRIBUTES hid_attrs; @@ -91,44 +95,34 @@ static HANDLE mm_try_device(HDEVINFO dev_info, BOOL ok; ok = SetupDiGetDeviceInterfaceDetailW( - dev_info, - iface_data, - NULL, - 0, - &detail_size, - NULL); + dev_info, iface_data, NULL, 0, &detail_size, NULL); if (!ok && GetLastError() != ERROR_INSUFFICIENT_BUFFER) { log_fatal( - "SetupDiGetDeviceInterfaceDetail sizing failed: %#x", - (int) GetLastError()); + "SetupDiGetDeviceInterfaceDetail sizing failed: %#x", + (int) GetLastError()); } detail = xmalloc(detail_size); detail->cbSize = sizeof(*detail); ok = SetupDiGetDeviceInterfaceDetailW( - dev_info, - iface_data, - detail, - detail_size, - NULL, - NULL); + dev_info, iface_data, detail, detail_size, NULL, NULL); if (!ok) { log_fatal( - "SetupDiGetDeviceInterfaceDetail failed: %#x", - (int) GetLastError()); + "SetupDiGetDeviceInterfaceDetail failed: %#x", + (int) GetLastError()); } cur_fd = CreateFileW( - detail->DevicePath, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_FLAG_OVERLAPPED, - NULL); + detail->DevicePath, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_FLAG_OVERLAPPED, + NULL); free(detail); @@ -142,8 +136,8 @@ static HANDLE mm_try_device(HDEVINFO dev_info, log_fatal("HidD_GetAttributes failed"); } - if ( hid_attrs.VendorID != MM_VENDOR_ID || - hid_attrs.ProductID != MM_PRODUCT_ID) { + if (hid_attrs.VendorID != MM_VENDOR_ID || + hid_attrs.ProductID != MM_PRODUCT_ID) { goto id_fail; } @@ -190,8 +184,12 @@ bool mm_init(uint32_t in_buf_count) do { mm_in_buf_pos = (mm_in_buf_pos + 1) % mm_in_buf_count; - } while (ReadFile(mm_fd, &mm_in_bufs[mm_in_buf_pos], sizeof(*mm_in_bufs), - NULL, &mm_in_ovl)); + } while (ReadFile( + mm_fd, + &mm_in_bufs[mm_in_buf_pos], + sizeof(*mm_in_bufs), + NULL, + &mm_in_ovl)); if (GetLastError() != ERROR_IO_PENDING) { log_fatal("USB IN failed: %#x", (int) GetLastError()); @@ -218,8 +216,8 @@ void mm_update(const struct mm_output *out, struct mm_input *in) } else { if (GetLastError() != ERROR_IO_INCOMPLETE) { log_fatal( - "GetOverlappedResult[OUT] failed: %#x", - (int) GetLastError()); + "GetOverlappedResult[OUT] failed: %#x", + (int) GetLastError()); } } } @@ -232,8 +230,8 @@ void mm_update(const struct mm_output *out, struct mm_input *in) if (!mm_out_pending) { memcpy(&mm_out_buf, out, sizeof(*out)); - if (!WriteFile(mm_fd, &mm_out_buf, sizeof(mm_out_buf), NULL, - &mm_out_ovl)) { + if (!WriteFile( + mm_fd, &mm_out_buf, sizeof(mm_out_buf), NULL, &mm_out_ovl)) { if (GetLastError() != ERROR_IO_PENDING) { log_fatal("USB OUT failed: %#x", (int) GetLastError()); } @@ -252,8 +250,12 @@ void mm_update(const struct mm_output *out, struct mm_input *in) do { mm_in_buf_pos = (mm_in_buf_pos + 1) % mm_in_buf_count; - } while (ReadFile(mm_fd, &mm_in_bufs[mm_in_buf_pos], sizeof(*mm_in_bufs), - NULL, &mm_in_ovl)); + } while (ReadFile( + mm_fd, + &mm_in_bufs[mm_in_buf_pos], + sizeof(*mm_in_bufs), + NULL, + &mm_in_ovl)); /* (did we actually block or was there an IO error?) */ @@ -272,4 +274,3 @@ void mm_fini(void) log_info("Closed MiniMaid"); } - diff --git a/src/main/mm/mm.h b/src/main/mm/mm.h index 410989b..99868b0 100644 --- a/src/main/mm/mm.h +++ b/src/main/mm/mm.h @@ -4,8 +4,8 @@ #include #include -#define MM_VENDOR_ID 0xBEEF -#define MM_PRODUCT_ID 0x5730 +#define MM_VENDOR_ID 0xBEEF +#define MM_PRODUCT_ID 0x5730 #pragma pack(push, 1) diff --git a/src/main/p3io/cmd.c b/src/main/p3io/cmd.c index 13e022a..6a0a7ff 100644 --- a/src/main/p3io/cmd.c +++ b/src/main/p3io/cmd.c @@ -14,9 +14,7 @@ uint8_t p3io_req_cmd(const union p3io_req_any *src) } void p3io_resp_init( - struct p3io_hdr *dest, - size_t nbytes, - const struct p3io_hdr *req) + struct p3io_hdr *dest, size_t nbytes, const struct p3io_hdr *req) { log_assert(dest != NULL); log_assert(req != NULL); diff --git a/src/main/p3io/cmd.h b/src/main/p3io/cmd.h index 1df30dc..498b6e2 100644 --- a/src/main/p3io/cmd.h +++ b/src/main/p3io/cmd.h @@ -6,30 +6,30 @@ #include "p3io/frame.h" enum { - P3IO_CMD_GET_VERSION = 0x01, - P3IO_CMD_SET_WATCHDOG = 0x05, - P3IO_CMD_POWEROFF = 0x22, - P3IO_CMD_SET_OUTPUTS = 0x24, - P3IO_CMD_READ_PLUG = 0x25, - P3IO_CMD_GET_CAB_TYPE_OR_DIPSW = 0x27, - P3IO_CMD_GET_VIDEO_FREQ = 0x29, - P3IO_CMD_SET_MODE = 0x2F, - P3IO_CMD_GET_COINSTOCK = 0x31, - P3IO_CMD_SET_COINCOUNTER = 0x32, - P3IO_CMD_RS232_OPEN_CLOSE = 0x38, - P3IO_CMD_RS232_WRITE = 0x3A, - P3IO_CMD_RS232_READ = 0x3B, + P3IO_CMD_GET_VERSION = 0x01, + P3IO_CMD_SET_WATCHDOG = 0x05, + P3IO_CMD_POWEROFF = 0x22, + P3IO_CMD_SET_OUTPUTS = 0x24, + P3IO_CMD_READ_PLUG = 0x25, + P3IO_CMD_GET_CAB_TYPE_OR_DIPSW = 0x27, + P3IO_CMD_GET_VIDEO_FREQ = 0x29, + P3IO_CMD_SET_MODE = 0x2F, + P3IO_CMD_GET_COINSTOCK = 0x31, + P3IO_CMD_SET_COINCOUNTER = 0x32, + P3IO_CMD_RS232_OPEN_CLOSE = 0x38, + P3IO_CMD_RS232_WRITE = 0x3A, + P3IO_CMD_RS232_READ = 0x3B, }; enum { - P3IO_RS232_CMD_OPEN = 0x00, - P3IO_RS232_CMD_CLOSE = 0xFF, + P3IO_RS232_CMD_OPEN = 0x00, + P3IO_RS232_CMD_CLOSE = 0xFF, }; enum { - P3IO_RS232_BAUD_19200 = 0x02, - P3IO_RS232_BAUD_38400 = 0x03, - P3IO_RS232_BAUD_57600 = 0x04, + P3IO_RS232_BAUD_19200 = 0x02, + P3IO_RS232_BAUD_38400 = 0x03, + P3IO_RS232_BAUD_57600 = 0x04, }; #pragma pack(push, 1) @@ -170,8 +170,6 @@ union p3io_resp_any { uint8_t p3io_req_cmd(const union p3io_req_any *src); void p3io_resp_init( - struct p3io_hdr *dest, - size_t nbytes, - const struct p3io_hdr *req); + struct p3io_hdr *dest, size_t nbytes, const struct p3io_hdr *req); #endif diff --git a/src/main/p3io/frame.c b/src/main/p3io/frame.c index e32cfea..df00016 100644 --- a/src/main/p3io/frame.c +++ b/src/main/p3io/frame.c @@ -8,10 +8,8 @@ #include "util/iobuf.h" #include "util/log.h" -HRESULT p3io_frame_encode( - struct iobuf *dest, - const void *ptr, - size_t nbytes) +HRESULT +p3io_frame_encode(struct iobuf *dest, const void *ptr, size_t nbytes) { const uint8_t *bytes; uint8_t b; @@ -28,7 +26,7 @@ HRESULT p3io_frame_encode( dest->bytes[dest->pos++] = 0xAA; - for (i = 0 ; i < nbytes ; i++) { + for (i = 0; i < nbytes; i++) { b = bytes[i]; if (b == 0xAA || b == 0xFF) { @@ -57,9 +55,8 @@ trunc: return E_FAIL; } -HRESULT p3io_frame_decode( - struct iobuf *dest, - struct const_iobuf *src) +HRESULT +p3io_frame_decode(struct iobuf *dest, struct const_iobuf *src) { bool escape; uint8_t b; diff --git a/src/main/p3io/frame.h b/src/main/p3io/frame.h index 626d823..35f9b4a 100644 --- a/src/main/p3io/frame.h +++ b/src/main/p3io/frame.h @@ -7,13 +7,8 @@ #include "util/iobuf.h" -HRESULT p3io_frame_encode( - struct iobuf *dest, - const void *bytes, - size_t nbytes); +HRESULT p3io_frame_encode(struct iobuf *dest, const void *bytes, size_t nbytes); -HRESULT p3io_frame_decode( - struct iobuf *dest, - struct const_iobuf *src); +HRESULT p3io_frame_decode(struct iobuf *dest, struct const_iobuf *src); #endif diff --git a/src/main/p3io/guid.c b/src/main/p3io/guid.c index 4e131c1..9a64b10 100644 --- a/src/main/p3io/guid.c +++ b/src/main/p3io/guid.c @@ -1,4 +1,4 @@ -#include #include +#include #include "p3io/guid.h" diff --git a/src/main/p3io/guid.h b/src/main/p3io/guid.h index 9940c1e..c768405 100644 --- a/src/main/p3io/guid.h +++ b/src/main/p3io/guid.h @@ -4,10 +4,17 @@ #include DEFINE_GUID( - p3io_guid, - 0x1FA4A480, - 0xAC60, - 0x40C7, - 0xA7, 0xAC, 0x52, 0x79, 0x0F, 0x34, 0x57, 0x5A); + p3io_guid, + 0x1FA4A480, + 0xAC60, + 0x40C7, + 0xA7, + 0xAC, + 0x52, + 0x79, + 0x0F, + 0x34, + 0x57, + 0x5A); #endif diff --git a/src/main/p3io/ioctl.h b/src/main/p3io/ioctl.h index 2c70b01..b420fd1 100644 --- a/src/main/p3io/ioctl.h +++ b/src/main/p3io/ioctl.h @@ -2,7 +2,7 @@ #define P3IO_IOCTL_H enum { - P3IO_IOCTL_READ_JAMMA = 0x00222068, + P3IO_IOCTL_READ_JAMMA = 0x00222068, }; #endif diff --git a/src/main/p3ioemu/devmgr.c b/src/main/p3ioemu/devmgr.c index 07f71a1..cf18d87 100644 --- a/src/main/p3ioemu/devmgr.c +++ b/src/main/p3ioemu/devmgr.c @@ -1,5 +1,5 @@ -#include #include +#include #include #include @@ -16,93 +16,85 @@ /* Link pointers */ -static HDEVINFO (WINAPI * next_SetupDiGetClassDevsW)( - const GUID *class_guid, - const wchar_t *enumerator, - HWND hwnd, - DWORD flags); +static HDEVINFO(WINAPI *next_SetupDiGetClassDevsW)( + const GUID *class_guid, const wchar_t *enumerator, HWND hwnd, DWORD flags); -static HDEVINFO (WINAPI * next_SetupDiGetClassDevsA)( - const GUID *class_guid, - const char *enumerator, - HWND hwnd, - DWORD flags); +static HDEVINFO(WINAPI *next_SetupDiGetClassDevsA)( + const GUID *class_guid, const char *enumerator, HWND hwnd, DWORD flags); -static BOOL (WINAPI *next_SetupDiEnumDeviceInterfaces)( - HDEVINFO dev_info, - SP_DEVINFO_DATA *info_data, - const GUID *iface_guid, - DWORD index, - SP_DEVICE_INTERFACE_DATA *ifd); +static BOOL(WINAPI *next_SetupDiEnumDeviceInterfaces)( + HDEVINFO dev_info, + SP_DEVINFO_DATA *info_data, + const GUID *iface_guid, + DWORD index, + SP_DEVICE_INTERFACE_DATA *ifd); -static BOOL (WINAPI *next_SetupDiGetDeviceInterfaceDetailW)( - HDEVINFO dev_info, - SP_DEVICE_INTERFACE_DATA *ifd, - SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail, - DWORD size, - DWORD *required_size, - SP_DEVINFO_DATA *info_data); +static BOOL(WINAPI *next_SetupDiGetDeviceInterfaceDetailW)( + HDEVINFO dev_info, + SP_DEVICE_INTERFACE_DATA *ifd, + SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail, + DWORD size, + DWORD *required_size, + SP_DEVINFO_DATA *info_data); -static BOOL (WINAPI *next_SetupDiDestroyDeviceInfoList)(HDEVINFO dev_info); +static BOOL(WINAPI *next_SetupDiDestroyDeviceInfoList)(HDEVINFO dev_info); /* API hooks */ static HDEVINFO WINAPI my_SetupDiGetClassDevsW( - const GUID *class_guid, - const wchar_t *enumerator, - HWND hwnd, - DWORD flags); + const GUID *class_guid, const wchar_t *enumerator, HWND hwnd, DWORD flags); static HDEVINFO WINAPI my_SetupDiGetClassDevsA( - const GUID *class_guid, - const char *enumerator, - HWND hwnd, - DWORD flags); + const GUID *class_guid, const char *enumerator, HWND hwnd, DWORD flags); static BOOL WINAPI my_SetupDiEnumDeviceInterfaces( - HDEVINFO dev_info, - SP_DEVINFO_DATA *info_data, - const GUID *iface_guid, - DWORD index, - SP_DEVICE_INTERFACE_DATA *ifd); + HDEVINFO dev_info, + SP_DEVINFO_DATA *info_data, + const GUID *iface_guid, + DWORD index, + SP_DEVICE_INTERFACE_DATA *ifd); static BOOL WINAPI my_SetupDiGetDeviceInterfaceDetailW( - HDEVINFO dev_info, - SP_DEVICE_INTERFACE_DATA *ifd, - SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail, - DWORD size, - DWORD *required_size, - SP_DEVINFO_DATA *info_data); + HDEVINFO dev_info, + SP_DEVICE_INTERFACE_DATA *ifd, + SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail, + DWORD size, + DWORD *required_size, + SP_DEVINFO_DATA *info_data); static BOOL WINAPI my_SetupDiDestroyDeviceInfoList(HDEVINFO dev_info); static const struct hook_symbol p3io_setupapi_syms[] = { { - .name = "SetupDiGetClassDevsW", - .patch = my_SetupDiGetClassDevsW, - .link = (void **) &next_SetupDiGetClassDevsW, - }, { - .name = "SetupDiGetClassDevsA", - .patch = my_SetupDiGetClassDevsA, - .link = (void **) &next_SetupDiGetClassDevsA, - }, { + .name = "SetupDiGetClassDevsW", + .patch = my_SetupDiGetClassDevsW, + .link = (void **) &next_SetupDiGetClassDevsW, + }, + { + .name = "SetupDiGetClassDevsA", + .patch = my_SetupDiGetClassDevsA, + .link = (void **) &next_SetupDiGetClassDevsA, + }, + { #if 0 .name = "SetupDiEnumDeviceInfo", .patch = my_SetupDiEnumDeviceInfo, .link = (void **) &next_SetupDiEnumDeviceInfo, }, { #endif - .name = "SetupDiEnumDeviceInterfaces", - .patch = my_SetupDiEnumDeviceInterfaces, - .link = (void **) &next_SetupDiEnumDeviceInterfaces, - }, { - .name = "SetupDiGetDeviceInterfaceDetailW", - .patch = my_SetupDiGetDeviceInterfaceDetailW, - .link = (void **) &next_SetupDiGetDeviceInterfaceDetailW, - }, { - .name = "SetupDiDestroyDeviceInfoList", - .patch = my_SetupDiDestroyDeviceInfoList, - .link = (void **) &next_SetupDiDestroyDeviceInfoList, + .name = "SetupDiEnumDeviceInterfaces", + .patch = my_SetupDiEnumDeviceInterfaces, + .link = (void **) &next_SetupDiEnumDeviceInterfaces, + }, + { + .name = "SetupDiGetDeviceInterfaceDetailW", + .patch = my_SetupDiGetDeviceInterfaceDetailW, + .link = (void **) &next_SetupDiGetDeviceInterfaceDetailW, + }, + { + .name = "SetupDiDestroyDeviceInfoList", + .patch = my_SetupDiDestroyDeviceInfoList, + .link = (void **) &next_SetupDiDestroyDeviceInfoList, }, }; @@ -114,10 +106,7 @@ static const wchar_t p3io_path[] = L"$p3io\\p3io"; static HDEVINFO p3io_hdevinfo; static HDEVINFO WINAPI my_SetupDiGetClassDevsA( - const GUID *class_guid, - const char *enumerator, - HWND hwnd, - DWORD flags) + const GUID *class_guid, const char *enumerator, HWND hwnd, DWORD flags) { HDEVINFO result; @@ -131,10 +120,7 @@ static HDEVINFO WINAPI my_SetupDiGetClassDevsA( } static HDEVINFO WINAPI my_SetupDiGetClassDevsW( - const GUID *class_guid, - const wchar_t *enumerator, - HWND hwnd, - DWORD flags) + const GUID *class_guid, const wchar_t *enumerator, HWND hwnd, DWORD flags) { HDEVINFO result; @@ -148,19 +134,15 @@ static HDEVINFO WINAPI my_SetupDiGetClassDevsW( } static BOOL WINAPI my_SetupDiEnumDeviceInterfaces( - HDEVINFO dev_info, - SP_DEVINFO_DATA *info_data, - const GUID *iface_guid, - DWORD index, - SP_DEVICE_INTERFACE_DATA *ifd) + HDEVINFO dev_info, + SP_DEVINFO_DATA *info_data, + const GUID *iface_guid, + DWORD index, + SP_DEVICE_INTERFACE_DATA *ifd) { if (dev_info != p3io_hdevinfo) { return next_SetupDiEnumDeviceInterfaces( - dev_info, - info_data, - iface_guid, - index, - ifd); + dev_info, info_data, iface_guid, index, ifd); } /* Not implemented */ @@ -192,21 +174,16 @@ static BOOL WINAPI my_SetupDiEnumDeviceInterfaces( } static BOOL WINAPI my_SetupDiGetDeviceInterfaceDetailW( - HDEVINFO dev_info, - SP_DEVICE_INTERFACE_DATA *ifd, - SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail, - DWORD size, - DWORD *required_size, - SP_DEVINFO_DATA *info_data) + HDEVINFO dev_info, + SP_DEVICE_INTERFACE_DATA *ifd, + SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail, + DWORD size, + DWORD *required_size, + SP_DEVINFO_DATA *info_data) { if (dev_info != p3io_hdevinfo) { return next_SetupDiGetDeviceInterfaceDetailW( - dev_info, - ifd, - detail, - size, - required_size, - info_data); + dev_info, ifd, detail, size, required_size, info_data); } /* Not implemented */ @@ -230,9 +207,7 @@ static BOOL WINAPI my_SetupDiGetDeviceInterfaceDetailW( return FALSE; } - memcpy( detail->DevicePath, - p3io_path_prefix, - sizeof(p3io_path_prefix)); + memcpy(detail->DevicePath, p3io_path_prefix, sizeof(p3io_path_prefix)); } SetLastError(ERROR_SUCCESS); @@ -252,10 +227,10 @@ static BOOL WINAPI my_SetupDiDestroyDeviceInfoList(HDEVINFO dev_info) void p3io_setupapi_insert_hooks(HMODULE target) { hook_table_apply( - target, - "setupapi.dll", - p3io_setupapi_syms, - lengthof(p3io_setupapi_syms)); + target, + "setupapi.dll", + p3io_setupapi_syms, + lengthof(p3io_setupapi_syms)); log_info("Inserted P3IO setupapi hooks into %p", target); } diff --git a/src/main/p3ioemu/emu.c b/src/main/p3ioemu/emu.c index 0a3283d..d8299b2 100644 --- a/src/main/p3ioemu/emu.c +++ b/src/main/p3ioemu/emu.c @@ -2,9 +2,9 @@ #include #include +#include #include #include -#include #include #include "hook/iohook.h" @@ -35,44 +35,35 @@ static HRESULT p3io_emu_handle_write(struct irp *irp); static HRESULT p3io_cmd_dispatch(const union p3io_req_any *req); static void p3io_cmd_get_version( - const struct p3io_hdr *req, - struct p3io_resp_version *resp); + const struct p3io_hdr *req, struct p3io_resp_version *resp); -static void p3io_cmd_set_watchdog( - const struct p3io_req_u8 *req, - struct p3io_resp_u8 *resp); +static void +p3io_cmd_set_watchdog(const struct p3io_req_u8 *req, struct p3io_resp_u8 *resp); static void p3io_cmd_set_outputs( - const struct p3io_req_set_outputs *req, - struct p3io_resp_u8 *resp); + const struct p3io_req_set_outputs *req, struct p3io_resp_u8 *resp); static void p3io_cmd_read_plug( - const struct p3io_req_read_plug *req, - struct p3io_resp_read_plug *resp); + const struct p3io_req_read_plug *req, struct p3io_resp_read_plug *resp); static void p3io_cmd_get_cab_type_or_dipsw( - const struct p3io_req_get_cab_type_or_dipsw *req, - struct p3io_resp_get_cab_type_or_dipsw *resp); + const struct p3io_req_get_cab_type_or_dipsw *req, + struct p3io_resp_get_cab_type_or_dipsw *resp); static void p3io_cmd_get_video_freq( - const struct p3io_req_u8 *req, - struct p3io_resp_u8 *resp); + const struct p3io_req_u8 *req, struct p3io_resp_u8 *resp); -static void p3io_cmd_set_mode( - const struct p3io_req_u8 *req, - struct p3io_resp_u8 *resp); +static void +p3io_cmd_set_mode(const struct p3io_req_u8 *req, struct p3io_resp_u8 *resp); static void p3io_cmd_get_coinstock( - const struct p3io_req_u8 *req, - struct p3io_resp_coin_stock *resp); + const struct p3io_req_u8 *req, struct p3io_resp_coin_stock *resp); static void p3io_cmd_set_coin_counter( - const struct p3io_req_set_coin_counter *req, - struct p3io_resp_u8 *resp); + const struct p3io_req_set_coin_counter *req, struct p3io_resp_u8 *resp); -static void p3io_cmd_unknown( - const union p3io_req_any *req, - struct p3io_resp_u8 *resp); +static void +p3io_cmd_unknown(const union p3io_req_any *req, struct p3io_resp_u8 *resp); void p3io_emu_init(const struct p3io_ops *ops, void *ctx) { @@ -103,7 +94,8 @@ void p3io_emu_fini(void) } } -HRESULT p3io_emu_dispatch_irp(struct irp *irp) +HRESULT +p3io_emu_dispatch_irp(struct irp *irp) { log_assert(irp != NULL); @@ -112,12 +104,18 @@ HRESULT p3io_emu_dispatch_irp(struct irp *irp) } switch (irp->op) { - case IRP_OP_OPEN: return p3io_emu_handle_open(irp); - case IRP_OP_CLOSE: return p3io_emu_handle_close(irp); - case IRP_OP_READ: return p3io_emu_handle_read(irp); - case IRP_OP_WRITE: return p3io_emu_handle_write(irp); - case IRP_OP_IOCTL: return p3io_emu_handle_ioctl(irp); - default: return E_NOTIMPL; + case IRP_OP_OPEN: + return p3io_emu_handle_open(irp); + case IRP_OP_CLOSE: + return p3io_emu_handle_close(irp); + case IRP_OP_READ: + return p3io_emu_handle_read(irp); + case IRP_OP_WRITE: + return p3io_emu_handle_write(irp); + case IRP_OP_IOCTL: + return p3io_emu_handle_ioctl(irp); + default: + return E_NOTIMPL; } } @@ -222,71 +220,71 @@ static HRESULT p3io_cmd_dispatch(const union p3io_req_any *req) cmd = p3io_req_cmd(req); switch (cmd) { - case P3IO_CMD_GET_VERSION: - p3io_cmd_get_version(&req->hdr, &resp.version); + case P3IO_CMD_GET_VERSION: + p3io_cmd_get_version(&req->hdr, &resp.version); - break; + break; - case P3IO_CMD_SET_WATCHDOG: - p3io_cmd_set_watchdog(&req->u8, &resp.u8); + case P3IO_CMD_SET_WATCHDOG: + p3io_cmd_set_watchdog(&req->u8, &resp.u8); - break; + break; - case P3IO_CMD_SET_OUTPUTS: - p3io_cmd_set_outputs(&req->set_outputs, &resp.u8); + case P3IO_CMD_SET_OUTPUTS: + p3io_cmd_set_outputs(&req->set_outputs, &resp.u8); - break; + break; - case P3IO_CMD_READ_PLUG: - p3io_cmd_read_plug(&req->read_plug, &resp.read_plug); + case P3IO_CMD_READ_PLUG: + p3io_cmd_read_plug(&req->read_plug, &resp.read_plug); - break; + break; - case P3IO_CMD_GET_CAB_TYPE_OR_DIPSW: - p3io_cmd_get_cab_type_or_dipsw(&req->cab_type_or_dipsw, - &resp.cab_type_or_dipsw); + case P3IO_CMD_GET_CAB_TYPE_OR_DIPSW: + p3io_cmd_get_cab_type_or_dipsw( + &req->cab_type_or_dipsw, &resp.cab_type_or_dipsw); - break; + break; - case P3IO_CMD_GET_VIDEO_FREQ: - p3io_cmd_get_video_freq(&req->u8, &resp.u8); + case P3IO_CMD_GET_VIDEO_FREQ: + p3io_cmd_get_video_freq(&req->u8, &resp.u8); - break; + break; - case P3IO_CMD_SET_MODE: - p3io_cmd_set_mode(&req->u8, &resp.u8); + case P3IO_CMD_SET_MODE: + p3io_cmd_set_mode(&req->u8, &resp.u8); - break; + break; - case P3IO_CMD_GET_COINSTOCK: - p3io_cmd_get_coinstock(&req->u8, &resp.coin_stock); + case P3IO_CMD_GET_COINSTOCK: + p3io_cmd_get_coinstock(&req->u8, &resp.coin_stock); - break; + break; - case P3IO_CMD_SET_COINCOUNTER: - p3io_cmd_set_coin_counter(&req->set_coin_counter, &resp.u8); + case P3IO_CMD_SET_COINCOUNTER: + p3io_cmd_set_coin_counter(&req->set_coin_counter, &resp.u8); - break; + break; - case P3IO_CMD_RS232_OPEN_CLOSE: - p3io_uart_cmd_open_close(&req->rs232_open_close, &resp.u8); + case P3IO_CMD_RS232_OPEN_CLOSE: + p3io_uart_cmd_open_close(&req->rs232_open_close, &resp.u8); - break; + break; - case P3IO_CMD_RS232_READ: - p3io_uart_cmd_read(&req->rs232_read, &resp.rs232_read); + case P3IO_CMD_RS232_READ: + p3io_uart_cmd_read(&req->rs232_read, &resp.rs232_read); - break; + break; - case P3IO_CMD_RS232_WRITE: - p3io_uart_cmd_write(&req->rs232_write, &resp.rs232_write); + case P3IO_CMD_RS232_WRITE: + p3io_uart_cmd_write(&req->rs232_write, &resp.rs232_write); - break; + break; - default: - p3io_cmd_unknown(req, &resp.u8); + default: + p3io_cmd_unknown(req, &resp.u8); - break; + break; } p3io_frame_encode(&p3io_emu_resp, &resp, resp.hdr.nbytes + 1); @@ -294,9 +292,8 @@ static HRESULT p3io_cmd_dispatch(const union p3io_req_any *req) return S_OK; } -static void p3io_cmd_get_version( - const struct p3io_hdr *req, - struct p3io_resp_version *resp) +static void +p3io_cmd_get_version(const struct p3io_hdr *req, struct p3io_resp_version *resp) { log_misc("%s", __func__); @@ -311,9 +308,8 @@ static void p3io_cmd_get_version( resp->patch = 3; } -static void p3io_cmd_set_watchdog( - const struct p3io_req_u8 *req, - struct p3io_resp_u8 *resp) +static void +p3io_cmd_set_watchdog(const struct p3io_req_u8 *req, struct p3io_resp_u8 *resp) { log_misc("%s(%02x)", __func__, req->u8); @@ -323,8 +319,7 @@ static void p3io_cmd_set_watchdog( } static void p3io_cmd_set_outputs( - const struct p3io_req_set_outputs *req, - struct p3io_resp_u8 *resp) + const struct p3io_req_set_outputs *req, struct p3io_resp_u8 *resp) { uint32_t outputs; HRESULT hr; @@ -342,8 +337,7 @@ static void p3io_cmd_set_outputs( } static void p3io_cmd_read_plug( - const struct p3io_req_read_plug *req, - struct p3io_resp_read_plug *resp) + const struct p3io_req_read_plug *req, struct p3io_resp_read_plug *resp) { HRESULT hr; @@ -358,7 +352,7 @@ static void p3io_cmd_read_plug( * 0x12: black plug eeprom read * 0x00: white plug rom read * 0x02: white plug eeprom read - * + * * The structure of the buffer is the same for all flags set and the game * just grabs whatever it currently needs from the buffer. i.e. if we * send everything on every read (rom + eeprom) always, the game doesn't @@ -366,9 +360,9 @@ static void p3io_cmd_read_plug( */ if (req->flags & 0x10) { - if (p3io_ops->get_roundplug) { - hr = p3io_ops->get_roundplug(p3io_ops_ctx, 0, resp->rom, - resp->eeprom); + if (p3io_ops->get_roundplug) { + hr = p3io_ops->get_roundplug( + p3io_ops_ctx, 0, resp->rom, resp->eeprom); } else { log_warning("Reading black roundplug but no function available"); memset(resp->rom, 0, 8); @@ -376,9 +370,9 @@ static void p3io_cmd_read_plug( hr = S_OK; } } else { - if (p3io_ops->get_roundplug) { - hr = p3io_ops->get_roundplug(p3io_ops_ctx, 1, resp->rom, - resp->eeprom); + if (p3io_ops->get_roundplug) { + hr = p3io_ops->get_roundplug( + p3io_ops_ctx, 1, resp->rom, resp->eeprom); } else { log_warning("Reading white roundplug but no function available"); memset(resp->rom, 0, 8); @@ -387,19 +381,32 @@ static void p3io_cmd_read_plug( } } - log_misc("Reading %s roundplug, success 0x%lX, rom %02X%02X%02X%02X%02X%02X" + log_misc( + "Reading %s roundplug, success 0x%lX, rom %02X%02X%02X%02X%02X%02X" "%02X%02X, eeprom sig %X%X%X%X%X%X", - req->flags & 0x10 ? "black" : "white", hr, resp->rom[0], resp->rom[1], - resp->rom[2], resp->rom[3], resp->rom[4], resp->rom[5], resp->rom[6], - resp->rom[7], resp->eeprom[0], resp->eeprom[1], resp->eeprom[2], - resp->eeprom[3], resp->eeprom[4], resp->eeprom[5]); + req->flags & 0x10 ? "black" : "white", + hr, + resp->rom[0], + resp->rom[1], + resp->rom[2], + resp->rom[3], + resp->rom[4], + resp->rom[5], + resp->rom[6], + resp->rom[7], + resp->eeprom[0], + resp->eeprom[1], + resp->eeprom[2], + resp->eeprom[3], + resp->eeprom[4], + resp->eeprom[5]); resp->status = FAILED(hr); } static void p3io_cmd_get_cab_type_or_dipsw( - const struct p3io_req_get_cab_type_or_dipsw *req, - struct p3io_resp_get_cab_type_or_dipsw *resp) + const struct p3io_req_get_cab_type_or_dipsw *req, + struct p3io_resp_get_cab_type_or_dipsw *resp) { HRESULT hr; uint8_t dipsw; @@ -448,15 +455,14 @@ static void p3io_cmd_get_cab_type_or_dipsw( resp->status = 0; } } else { - log_warning("Unknown value for cab type or dipsw: %d", - req->cab_type_or_dipsw); + log_warning( + "Unknown value for cab type or dipsw: %d", req->cab_type_or_dipsw); resp->status = 0; } } static void p3io_cmd_get_video_freq( - const struct p3io_req_u8 *req, - struct p3io_resp_u8 *resp) + const struct p3io_req_u8 *req, struct p3io_resp_u8 *resp) { HRESULT hr; enum p3io_video_freq freq; @@ -472,23 +478,23 @@ static void p3io_cmd_get_video_freq( if (hr == S_OK) { switch (freq) { - case P3IO_VIDEO_FREQ_15KHZ: - log_misc("%s: Returning 15 kHz", __func__); - resp->status = 0; - resp->u8 = 0x00; + case P3IO_VIDEO_FREQ_15KHZ: + log_misc("%s: Returning 15 kHz", __func__); + resp->status = 0; + resp->u8 = 0x00; - break; + break; - case P3IO_VIDEO_FREQ_31KHZ: - log_misc("%s: Returning 31 kHz", __func__); - resp->status = 0; - resp->u8 = 0x80; + case P3IO_VIDEO_FREQ_31KHZ: + log_misc("%s: Returning 31 kHz", __func__); + resp->status = 0; + resp->u8 = 0x80; - break; + break; - default: - log_assert(false); - break; + default: + log_assert(false); + break; } } else { log_misc("%s: Returning error! (hr=%x)", __func__, (int) hr); @@ -497,9 +503,8 @@ static void p3io_cmd_get_video_freq( } } -static void p3io_cmd_set_mode( - const struct p3io_req_u8 *req, - struct p3io_resp_u8 *resp) +static void +p3io_cmd_set_mode(const struct p3io_req_u8 *req, struct p3io_resp_u8 *resp) { log_misc("%s(%02x)", __func__, req->u8); @@ -509,8 +514,7 @@ static void p3io_cmd_set_mode( } static void p3io_cmd_get_coinstock( - const struct p3io_req_u8 *req, - struct p3io_resp_coin_stock *resp) + const struct p3io_req_u8 *req, struct p3io_resp_coin_stock *resp) { uint16_t slots[2]; HRESULT hr; @@ -531,20 +535,18 @@ static void p3io_cmd_get_coinstock( } static void p3io_cmd_set_coin_counter( - const struct p3io_req_set_coin_counter *req, - struct p3io_resp_u8 *resp) + const struct p3io_req_set_coin_counter *req, struct p3io_resp_u8 *resp) { - log_misc("%s(%02x %02x)", __func__, req->coin_counter[0], - req->coin_counter[1]); + log_misc( + "%s(%02x %02x)", __func__, req->coin_counter[0], req->coin_counter[1]); p3io_resp_init(&resp->hdr, sizeof(*resp), &req->hdr); resp->status = 0; resp->u8 = 0; } -static void p3io_cmd_unknown( - const union p3io_req_any *req, - struct p3io_resp_u8 *resp) +static void +p3io_cmd_unknown(const union p3io_req_any *req, struct p3io_resp_u8 *resp) { log_warning("Unsupported P3IO command: %02x", p3io_req_cmd(req)); diff --git a/src/main/p3ioemu/emu.h b/src/main/p3ioemu/emu.h index a3183cd..a013986 100644 --- a/src/main/p3ioemu/emu.h +++ b/src/main/p3ioemu/emu.h @@ -39,13 +39,13 @@ struct p3io_ops { HRESULT (*get_cab_type)(void *ctx, enum p3io_cab_type *type); HRESULT (*get_video_freq)(void *ctx, enum p3io_video_freq *freq); HRESULT (*get_coinstock)(void *ctx, uint16_t *slots, size_t nslots); - HRESULT (*get_roundplug)(void *ctx, uint8_t plug_id, uint8_t* rom, - uint8_t* eeprom); + HRESULT(*get_roundplug) + (void *ctx, uint8_t plug_id, uint8_t *rom, uint8_t *eeprom); }; /** * Initialize the p3io emulation backend. - * + * * @param ops Dispatch table with operation hooks for your target game. * @param ctx A context which is passed along with every call to a function of * your provided dispatch table. diff --git a/src/main/p3ioemu/uart.c b/src/main/p3ioemu/uart.c index ccaffda..5f7f4e8 100644 --- a/src/main/p3ioemu/uart.c +++ b/src/main/p3ioemu/uart.c @@ -2,9 +2,9 @@ #include -#include #include #include +#include #include @@ -17,10 +17,8 @@ #include "util/iobuf.h" #include "util/log.h" -static HRESULT p3io_uart_open( - const wchar_t *path, - uint32_t baud_rate, - HANDLE *fd); +static HRESULT +p3io_uart_open(const wchar_t *path, uint32_t baud_rate, HANDLE *fd); static HRESULT p3io_uart_close(HANDLE fd); static HRESULT p3io_uart_read(HANDLE fd, struct iobuf *iobuf); static HRESULT p3io_uart_write(HANDLE fd, struct const_iobuf *iobuf); @@ -28,9 +26,7 @@ static HRESULT p3io_uart_write(HANDLE fd, struct const_iobuf *iobuf); static const wchar_t *p3io_uart_paths[2]; static HANDLE p3io_uart_fds[2]; -static const uint32_t p3io_uart_baud_codes[] = { - 0, 0, 19200, 38400, 57600 -}; +static const uint32_t p3io_uart_baud_codes[] = {0, 0, 19200, 38400, 57600}; void p3io_uart_set_path(size_t uart_no, const wchar_t *path) { @@ -40,8 +36,7 @@ void p3io_uart_set_path(size_t uart_no, const wchar_t *path) } void p3io_uart_cmd_open_close( - const struct p3io_req_rs232_open_close *req, - struct p3io_resp_u8 *resp) + const struct p3io_req_rs232_open_close *req, struct p3io_resp_u8 *resp) { const wchar_t *path; uint32_t baud_rate; @@ -58,52 +53,52 @@ void p3io_uart_cmd_open_close( } switch (req->subcmd) { - case P3IO_RS232_CMD_OPEN: - log_info("Opening remote RS232 port #%d", req->port_no); + case P3IO_RS232_CMD_OPEN: + log_info("Opening remote RS232 port #%d", req->port_no); - if (req->baud_code < lengthof(p3io_uart_baud_codes)) { - baud_rate = p3io_uart_baud_codes[req->baud_code]; - } else { - baud_rate = 0; - } + if (req->baud_code < lengthof(p3io_uart_baud_codes)) { + baud_rate = p3io_uart_baud_codes[req->baud_code]; + } else { + baud_rate = 0; + } - if (baud_rate == 0) { - log_warning("Invalid baud rate code: %02x", req->baud_code); + if (baud_rate == 0) { + log_warning("Invalid baud rate code: %02x", req->baud_code); + hr = E_FAIL; + + goto end; + } + + path = p3io_uart_paths[req->port_no]; + + if (path == NULL) { + log_warning("UART #%i: No downstream connection", req->port_no); + hr = E_FAIL; + + goto end; + } + + hr = p3io_uart_open(path, baud_rate, &p3io_uart_fds[req->port_no]); + + if (FAILED(hr)) { + log_warning("p3io_uart_open() failed: %x", (int) hr); + } + + break; + + case P3IO_RS232_CMD_CLOSE: + log_info("Closing remote RS232 port #%d", req->port_no); + + hr = p3io_uart_close(p3io_uart_fds[req->port_no]); + p3io_uart_fds[req->port_no] = NULL; + + break; + + default: + log_warning("Unknown subcommand %02x", req->subcmd); hr = E_FAIL; - goto end; - } - - path = p3io_uart_paths[req->port_no]; - - if (path == NULL) { - log_warning("UART #%i: No downstream connection", req->port_no); - hr = E_FAIL; - - goto end; - } - - hr = p3io_uart_open(path, baud_rate, &p3io_uart_fds[req->port_no]); - - if (FAILED(hr)) { - log_warning("p3io_uart_open() failed: %x", (int) hr); - } - - break; - - case P3IO_RS232_CMD_CLOSE: - log_info("Closing remote RS232 port #%d", req->port_no); - - hr = p3io_uart_close(p3io_uart_fds[req->port_no]); - p3io_uart_fds[req->port_no] = NULL; - - break; - - default: - log_warning("Unknown subcommand %02x", req->subcmd); - hr = E_FAIL; - - break; + break; } end: @@ -113,8 +108,7 @@ end: } void p3io_uart_cmd_read( - const struct p3io_req_rs232_read *req, - struct p3io_resp_rs232_read *resp) + const struct p3io_req_rs232_read *req, struct p3io_resp_rs232_read *resp) { struct iobuf iobuf; HRESULT hr; @@ -152,8 +146,7 @@ end: } void p3io_uart_cmd_write( - const struct p3io_req_rs232_write *req, - struct p3io_resp_rs232_write *resp) + const struct p3io_req_rs232_write *req, struct p3io_resp_rs232_write *resp) { struct const_iobuf iobuf; HRESULT hr; @@ -177,10 +170,8 @@ end: resp->nbytes = iobuf.pos; } -static HRESULT p3io_uart_open( - const wchar_t *path, - uint32_t baud_rate, - HANDLE *fd) +static HRESULT +p3io_uart_open(const wchar_t *path, uint32_t baud_rate, HANDLE *fd) { struct irp irp; uint32_t comm_mask; diff --git a/src/main/p3ioemu/uart.h b/src/main/p3ioemu/uart.h index a388ba4..e0d417b 100644 --- a/src/main/p3ioemu/uart.h +++ b/src/main/p3ioemu/uart.h @@ -6,15 +6,12 @@ void p3io_uart_set_path(size_t uart_no, const wchar_t *path); void p3io_uart_cmd_open_close( - const struct p3io_req_rs232_open_close *req, - struct p3io_resp_u8 *resp); + const struct p3io_req_rs232_open_close *req, struct p3io_resp_u8 *resp); void p3io_uart_cmd_read( - const struct p3io_req_rs232_read *req, - struct p3io_resp_rs232_read *resp); + const struct p3io_req_rs232_read *req, struct p3io_resp_rs232_read *resp); void p3io_uart_cmd_write( - const struct p3io_req_rs232_write *req, - struct p3io_resp_rs232_write *resp); + const struct p3io_req_rs232_write *req, struct p3io_resp_rs232_write *resp); #endif diff --git a/src/main/p4ioemu/device.c b/src/main/p4ioemu/device.c index d5912b8..37cd005 100644 --- a/src/main/p4ioemu/device.c +++ b/src/main/p4ioemu/device.c @@ -2,9 +2,9 @@ #include "p4ioemu/device.h" -#include #include #include +#include #include "hook/iohook.h" #include "util/hex.h" @@ -16,9 +16,8 @@ /* can't seem to #include the requisite DDK headers from usermode code, so we have to redefine these macros here */ -#define CTL_CODE( DeviceType, Function, Method, Access ) ( \ - ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \ -) +#define CTL_CODE(DeviceType, Function, Method, Access) \ + (((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method)) #define METHOD_BUFFERED 0 @@ -29,8 +28,18 @@ #define P4IO_FUNCTION_READ_JAMMA_2 0x801 #define P4IO_FUNCTION_GET_DEVICE_NAME 0x803 -#define IOCTL_P4IO_GET_DEVICE_NAME CTL_CODE(FILE_DEVICE_UNKNOWN, P4IO_FUNCTION_GET_DEVICE_NAME, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define IOCTL_P4IO_READ_JAMMA_2 CTL_CODE(FILE_DEVICE_UNKNOWN, P4IO_FUNCTION_READ_JAMMA_2, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_P4IO_GET_DEVICE_NAME \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + P4IO_FUNCTION_GET_DEVICE_NAME, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) +#define IOCTL_P4IO_READ_JAMMA_2 \ + CTL_CODE( \ + FILE_DEVICE_UNKNOWN, \ + P4IO_FUNCTION_READ_JAMMA_2, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) enum p4ioemu_p4io_command { P4IOEMU_P4IO_CMD_INIT = 0x00, @@ -70,7 +79,7 @@ struct p4ioemu_p4io_read_roundplug_req { uint8_t type; }; -static const struct p4ioemu_device_msg_hook* p4ioemu_device_msg_hook; +static const struct p4ioemu_device_msg_hook *p4ioemu_device_msg_hook; static HANDLE p4ioemu_p4io_fd; static uint8_t p4ioemu_p4io_cmd_read_buffer[4096]; @@ -78,12 +87,15 @@ static uint32_t p4ioemu_p4io_cmd_buffer_resp_len; static uint8_t p4ioemu_p4io_last_cmd; static uint8_t p4ioemu_p4io_last_seq_num; -static uint32_t p4ioemu_p4io_command_handle(uint8_t cmd, const void* payload, - uint32_t payload_len, void* resp, uint32_t resp_max_len) +static uint32_t p4ioemu_p4io_command_handle( + uint8_t cmd, + const void *payload, + uint32_t payload_len, + void *resp, + uint32_t resp_max_len) { switch (cmd) { - case P4IOEMU_P4IO_CMD_INIT: - { + case P4IOEMU_P4IO_CMD_INIT: { log_misc("P4IOEMU_P4IO_CMD_INIT"); /* no data to send to host */ @@ -92,12 +104,11 @@ static uint32_t p4ioemu_p4io_command_handle(uint8_t cmd, const void* payload, return 0; } - case P4IOEMU_P4IO_CMD_GET_DEVICE_INFO: - { + case P4IOEMU_P4IO_CMD_GET_DEVICE_INFO: { log_misc("P4IOEMU_P4IO_CMD_GET_DEVICE_INFO"); - struct p4ioemu_p4io_device_info_resp* info = - (struct p4ioemu_p4io_device_info_resp*) resp; + struct p4ioemu_p4io_device_info_resp *info = + (struct p4ioemu_p4io_device_info_resp *) resp; info->type = 0x37133713; info->version_major = 5; @@ -110,10 +121,9 @@ static uint32_t p4ioemu_p4io_command_handle(uint8_t cmd, const void* payload, return sizeof(struct p4ioemu_p4io_device_info_resp); } - case P4IOEMU_P4IO_CMD_DALLAS_READ_ID: - { - const struct p4ioemu_p4io_read_roundplug_req* req = - (const struct p4ioemu_p4io_read_roundplug_req*) payload; + case P4IOEMU_P4IO_CMD_DALLAS_READ_ID: { + const struct p4ioemu_p4io_read_roundplug_req *req = + (const struct p4ioemu_p4io_read_roundplug_req *) payload; log_misc("P4IOEMU_P4IO_CMD_DALLAS_READ_ID: %d", req->type); @@ -126,15 +136,15 @@ static uint32_t p4ioemu_p4io_command_handle(uint8_t cmd, const void* payload, return 8; } - case P4IOEMU_P4IO_CMD_DALLAS_READ_MEM: - { - const struct p4ioemu_p4io_read_roundplug_req* req = - (const struct p4ioemu_p4io_read_roundplug_req*) payload; + case P4IOEMU_P4IO_CMD_DALLAS_READ_MEM: { + const struct p4ioemu_p4io_read_roundplug_req *req = + (const struct p4ioemu_p4io_read_roundplug_req *) payload; log_misc("P4IOEMU_P4IO_CMD_DALLAS_READ_MEM: %d", req->type); if (p4ioemu_device_msg_hook->roundplug_read_mem) { - p4ioemu_device_msg_hook->roundplug_read_mem(req->type, resp, 32); + p4ioemu_device_msg_hook->roundplug_read_mem( + req->type, resp, 32); } else { memset(resp, 0, 32); } @@ -142,16 +152,14 @@ static uint32_t p4ioemu_p4io_command_handle(uint8_t cmd, const void* payload, return 32; } - case P4IOEMU_P4IO_CMD_UNKNOWN: - { + case P4IOEMU_P4IO_CMD_UNKNOWN: { log_misc("P4IOEMU_P4IO_CMD_UNKNOWN: %d", payload_len); return 0; } - case P4IOEMU_P4IO_CMD_SCI_UPDATE: - { - //log_misc("P4IOEMU_P4IO_CMD_SCI_UPDATE"); + case P4IOEMU_P4IO_CMD_SCI_UPDATE: { + // log_misc("P4IOEMU_P4IO_CMD_SCI_UPDATE"); // TODO we need a game which uses it memset(resp, 0, 61); @@ -159,9 +167,8 @@ static uint32_t p4ioemu_p4io_command_handle(uint8_t cmd, const void* payload, return 0; } - case P4IOEMU_P4IO_CMD_RESET_WTD: - { - //log_misc("P4IOEMU_P4IO_CMD_RESET_WTD"); + case P4IOEMU_P4IO_CMD_RESET_WTD: { + // log_misc("P4IOEMU_P4IO_CMD_RESET_WTD"); return 0; } @@ -172,17 +179,17 @@ static uint32_t p4ioemu_p4io_command_handle(uint8_t cmd, const void* payload, } } -static void p4ioemu_p4io_dump_buffer(const void* buffer, uint32_t len) +static void p4ioemu_p4io_dump_buffer(const void *buffer, uint32_t len) { char buffer_str[4096]; hex_encode_uc(buffer, len, buffer_str, sizeof(buffer_str)); log_warning("Package dump: %s", buffer_str); } -static HRESULT p4ioemu_p4io_bulk_read(void* resp, uint32_t nbytes) +static HRESULT p4ioemu_p4io_bulk_read(void *resp, uint32_t nbytes) { - struct p4ioemu_p4io_cmd_package* package; - void* payload; + struct p4ioemu_p4io_cmd_package *package; + void *payload; uint32_t max_payload_len; uint32_t payload_len; @@ -192,13 +199,15 @@ static HRESULT p4ioemu_p4io_bulk_read(void* resp, uint32_t nbytes) return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); } - package = (struct p4ioemu_p4io_cmd_package*) resp; + package = (struct p4ioemu_p4io_cmd_package *) resp; payload = resp + sizeof(struct p4ioemu_p4io_cmd_package); max_payload_len = nbytes - sizeof(struct p4ioemu_p4io_cmd_package); if (max_payload_len < p4ioemu_p4io_cmd_buffer_resp_len) { - log_warning("Too much response data (%d) for buffer (%d), truncated", - p4ioemu_p4io_cmd_buffer_resp_len, max_payload_len); + log_warning( + "Too much response data (%d) for buffer (%d), truncated", + p4ioemu_p4io_cmd_buffer_resp_len, + max_payload_len); payload_len = max_payload_len; } else { payload_len = p4ioemu_p4io_cmd_buffer_resp_len; @@ -214,10 +223,10 @@ static HRESULT p4ioemu_p4io_bulk_read(void* resp, uint32_t nbytes) return S_OK; } -static HRESULT p4ioemu_p4io_bulk_write(const void* req, uint32_t nbytes) +static HRESULT p4ioemu_p4io_bulk_write(const void *req, uint32_t nbytes) { - const struct p4ioemu_p4io_cmd_package* package; - const void* payload; + const struct p4ioemu_p4io_cmd_package *package; + const void *payload; if (nbytes < sizeof(struct p4ioemu_p4io_cmd_package)) { log_warning("Command on bulk write endpoint to short: %d", nbytes); @@ -226,7 +235,7 @@ static HRESULT p4ioemu_p4io_bulk_write(const void* req, uint32_t nbytes) return E_INVALIDARG; } - package = (struct p4ioemu_p4io_cmd_package*) req; + package = (struct p4ioemu_p4io_cmd_package *) req; payload = req + sizeof(struct p4ioemu_p4io_cmd_package); if (package->header_AA != 0xAA) { @@ -241,16 +250,22 @@ static HRESULT p4ioemu_p4io_bulk_write(const void* req, uint32_t nbytes) /* handle commands that are common p4io ones first */ p4ioemu_p4io_cmd_buffer_resp_len = p4ioemu_p4io_command_handle( - package->cmd, payload, package->payload_len, - p4ioemu_p4io_cmd_read_buffer, sizeof(p4ioemu_p4io_cmd_read_buffer)); + package->cmd, + payload, + package->payload_len, + p4ioemu_p4io_cmd_read_buffer, + sizeof(p4ioemu_p4io_cmd_read_buffer)); /* forward to game specific handlers */ if (p4ioemu_p4io_cmd_buffer_resp_len == 0xFFFFFFFF) { if (p4ioemu_device_msg_hook->command_handle) { p4ioemu_p4io_cmd_buffer_resp_len = - p4ioemu_device_msg_hook->command_handle(package->cmd, payload, - package->payload_len, p4ioemu_p4io_cmd_read_buffer, - sizeof(p4ioemu_p4io_cmd_read_buffer)); + p4ioemu_device_msg_hook->command_handle( + package->cmd, + payload, + package->payload_len, + p4ioemu_p4io_cmd_read_buffer, + sizeof(p4ioemu_p4io_cmd_read_buffer)); } } @@ -265,13 +280,19 @@ static HRESULT p4ioemu_p4io_bulk_write(const void* req, uint32_t nbytes) /* For debugging */ #ifdef P4IOEMU_DEBUG_DUMP -static void p4ioemu_device_log_ioctl_msg(const char* prefix, uint32_t ctl_code, - const void* ctl, uint32_t ctl_size, void* header, - uint32_t header_bytes, void* data, uint32_t data_bytes) +static void p4ioemu_device_log_ioctl_msg( + const char *prefix, + uint32_t ctl_code, + const void *ctl, + uint32_t ctl_size, + void *header, + uint32_t header_bytes, + void *data, + uint32_t data_bytes) { char header_str[4096]; char data_str[4096]; - const char* ctl_code_str; + const char *ctl_code_str; switch (ctl_code) { case IOCTL_P4IO_GET_DEVICE_NAME: @@ -290,19 +311,27 @@ static void p4ioemu_device_log_ioctl_msg(const char* prefix, uint32_t ctl_code, hex_encode_uc(header, header_bytes, header_str, sizeof(header_str)); hex_encode_uc(data, data_bytes, data_str, sizeof(data_str)); - log_warning("[P4IO IOCTL DUMP %s][%s] ctl_code 0x%X, ctl_size %d, header(%d) %s |||| data(%d) %s", - prefix, ctl_code_str, ctl_code, ctl_size, header_bytes, header_str, data_bytes, data_str); + log_warning( + "[P4IO IOCTL DUMP %s][%s] ctl_code 0x%X, ctl_size %d, header(%d) " + "%s |||| data(%d) %s", + prefix, + ctl_code_str, + ctl_code, + ctl_size, + header_bytes, + header_str, + data_bytes, + data_str); } -static void p4ioemu_device_log(const char* prefix, const void* data, - uint32_t data_bytes) +static void +p4ioemu_device_log(const char *prefix, const void *data, uint32_t data_bytes) { char data_str[4096]; hex_encode_uc(data, data_bytes, data_str, sizeof(data_str)); - log_warning("[P4IO DUMP %s] data(%d) %s", - prefix, data_bytes, data_str); + log_warning("[P4IO DUMP %s] data(%d) %s", prefix, data_bytes, data_str); } #endif @@ -371,14 +400,20 @@ static HRESULT p4ioemu_device_ioctl(struct irp *irp) /* For debugging */ #ifdef P4IOEMU_DEBUG_DUMP - p4ioemu_device_log_ioctl_msg("BEFORE", code, in_bytes, in_nbytes, in_bytes, - in_nbytes, out_bytes, out_nbytes); + p4ioemu_device_log_ioctl_msg( + "BEFORE", + code, + in_bytes, + in_nbytes, + in_bytes, + in_nbytes, + out_bytes, + out_nbytes); #endif /* Cases are listed in order of first receipt */ switch (irp->ioctl) { - case IOCTL_P4IO_GET_DEVICE_NAME: - { + case IOCTL_P4IO_GET_DEVICE_NAME: { const char dev_name[] = "kactools p4ioemu"; if (irp->read.nbytes < strlen(dev_name)) { @@ -392,9 +427,9 @@ static HRESULT p4ioemu_device_ioctl(struct irp *irp) return S_OK; } - case IOCTL_P4IO_READ_JAMMA_2: - { - p4ioemu_device_msg_hook->jamma2_read(irp->read.bytes, irp->read.nbytes); + case IOCTL_P4IO_READ_JAMMA_2: { + p4ioemu_device_msg_hook->jamma2_read( + irp->read.bytes, irp->read.nbytes); irp->read.pos = irp->read.nbytes; return S_OK; @@ -406,10 +441,17 @@ static HRESULT p4ioemu_device_ioctl(struct irp *irp) return E_INVALIDARG; } - /* For debugging */ + /* For debugging */ #ifdef P4IOEMU_DEBUG_DUMP - p4ioemu_device_log_ioctl_msg("AFTER", code, in_bytes, in_nbytes, in_bytes, - in_nbytes, out_bytes, out_nbytes); + p4ioemu_device_log_ioctl_msg( + "AFTER", + code, + in_bytes, + in_nbytes, + in_bytes, + in_nbytes, + out_bytes, + out_nbytes); #endif } @@ -420,7 +462,7 @@ static HRESULT p4ioemu_device_close(struct irp *irp) return S_OK; } -void p4ioemu_init(const struct p4ioemu_device_msg_hook* msg_hook) +void p4ioemu_init(const struct p4ioemu_device_msg_hook *msg_hook) { log_assert(p4ioemu_p4io_fd == NULL); @@ -437,7 +479,8 @@ void p4ioemu_fini(void) p4ioemu_p4io_fd = NULL; } -HRESULT p4ioemu_dispatch_irp(struct irp *irp) +HRESULT +p4ioemu_dispatch_irp(struct irp *irp) { log_assert(irp != NULL); @@ -446,12 +489,17 @@ HRESULT p4ioemu_dispatch_irp(struct irp *irp) } switch (irp->op) { - case IRP_OP_OPEN: return p4ioemu_device_open(irp); - case IRP_OP_CLOSE: return p4ioemu_device_close(irp); - case IRP_OP_READ: return p4ioemu_device_read(irp); - case IRP_OP_WRITE: return p4ioemu_device_write(irp); - case IRP_OP_IOCTL: return p4ioemu_device_ioctl(irp); - default: return E_NOTIMPL; + case IRP_OP_OPEN: + return p4ioemu_device_open(irp); + case IRP_OP_CLOSE: + return p4ioemu_device_close(irp); + case IRP_OP_READ: + return p4ioemu_device_read(irp); + case IRP_OP_WRITE: + return p4ioemu_device_write(irp); + case IRP_OP_IOCTL: + return p4ioemu_device_ioctl(irp); + default: + return E_NOTIMPL; } } - diff --git a/src/main/p4ioemu/device.h b/src/main/p4ioemu/device.h index 2e36ead..e9b1e98 100644 --- a/src/main/p4ioemu/device.h +++ b/src/main/p4ioemu/device.h @@ -3,20 +3,24 @@ #include -#include #include +#include #include "hook/iohook.h" struct p4ioemu_device_msg_hook { - void (*jamma2_read)(void* resp, uint32_t nbytes); - uint32_t (*command_handle)(uint8_t cmd, const void* payload, - uint32_t payload_len, void* resp, uint32_t resp_max_len); - void (*roundplug_read_id)(uint8_t type, void* buffer, uint32_t len); - void (*roundplug_read_mem)(uint8_t type, void* buffer, uint32_t len); + void (*jamma2_read)(void *resp, uint32_t nbytes); + uint32_t (*command_handle)( + uint8_t cmd, + const void *payload, + uint32_t payload_len, + void *resp, + uint32_t resp_max_len); + void (*roundplug_read_id)(uint8_t type, void *buffer, uint32_t len); + void (*roundplug_read_mem)(uint8_t type, void *buffer, uint32_t len); }; -void p4ioemu_init(const struct p4ioemu_device_msg_hook* msg_hook); +void p4ioemu_init(const struct p4ioemu_device_msg_hook *msg_hook); void p4ioemu_fini(void); HRESULT p4ioemu_dispatch_irp(struct irp *irp); diff --git a/src/main/p4ioemu/setupapi.c b/src/main/p4ioemu/setupapi.c index 3c4d01d..7642e9e 100644 --- a/src/main/p4ioemu/setupapi.c +++ b/src/main/p4ioemu/setupapi.c @@ -3,12 +3,10 @@ #include "p4ioemu/setupapi.h" const struct hook_setupapi_data p4ioemu_setupapi_data = { - .device_guid = { - 0x8B7250A5, - 0x4F61, - 0x46C9, - { 0x84, 0x3A, 0xE6, 0x68, 0x06, 0x47, 0x6A, 0x20 } - }, + .device_guid = {0x8B7250A5, + 0x4F61, + 0x46C9, + {0x84, 0x3A, 0xE6, 0x68, 0x06, 0x47, 0x6A, 0x20}}, .device_desc = NULL, .device_path = "\\p4io", }; \ No newline at end of file diff --git a/src/main/pcbidgen/main.c b/src/main/pcbidgen/main.c index ba67384..3e9182b 100644 --- a/src/main/pcbidgen/main.c +++ b/src/main/pcbidgen/main.c @@ -1,60 +1,63 @@ #include #include -#include #include +#include #include #include "security/id.h" #include "util/hex.h" -static void print_usage(char** argv) +static void print_usage(char **argv) { - fprintf(stderr, - "Usage: %s ...\n" - " gen: Generate a random pcbid\n" - " make <8 byte hex id>: Create a full pcbid (header + checksum) " - "of the provided id\n", - argv[0]); + fprintf( + stderr, + "Usage: %s ...\n" + " gen: Generate a random pcbid\n" + " make <8 byte hex id>: Create a full pcbid (header + checksum) " + "of the provided id\n", + argv[0]); } -int main(int argc, char** argv) +int main(int argc, char **argv) { - struct security_id id; - char* str; + struct security_id id; + char *str; - if (argc < 2) { - print_usage(argv); - return -1; - } + if (argc < 2) { + print_usage(argv); + return -1; + } - if (!strcmp(argv[1], "gen")) { - srand(time(NULL)); + if (!strcmp(argv[1], "gen")) { + srand(time(NULL)); - for (uint8_t i = 0; i < sizeof(id.id); i++) { - id.id[i] = rand(); - } - } else if (!strcmp(argv[1], "make")) { - if (argc < 3) { - print_usage(argv); - return -2; - } + for (uint8_t i = 0; i < sizeof(id.id); i++) { + id.id[i] = rand(); + } + } else if (!strcmp(argv[1], "make")) { + if (argc < 3) { + print_usage(argv); + return -2; + } - if (strlen(argv[2]) != 16) { - fprintf(stderr, "Invaild length %d for id, must be 16\n", - strlen(argv[2])); - return -3; - } + if (strlen(argv[2]) != 16) { + fprintf( + stderr, + "Invaild length %d for id, must be 16\n", + strlen(argv[2])); + return -3; + } - hex_decode(id.id, sizeof(id.id), argv[2], strlen(argv[2])); - } else { - fprintf(stderr, "Invaild command '%s'\n", argv[1]); - return -4; - } + hex_decode(id.id, sizeof(id.id), argv[2], strlen(argv[2])); + } else { + fprintf(stderr, "Invaild command '%s'\n", argv[1]); + return -4; + } - security_id_prepare(&id); - str = security_id_to_str(&id, false); - printf("%s\n", str); - free(str); + security_id_prepare(&id); + str = security_id_to_str(&id, false); + printf("%s\n", str); + free(str); } \ No newline at end of file diff --git a/src/main/sdvxhook/acio.c b/src/main/sdvxhook/acio.c index bb9ef1f..3be972b 100644 --- a/src/main/sdvxhook/acio.c +++ b/src/main/sdvxhook/acio.c @@ -1,8 +1,8 @@ #include -#include #include #include +#include #include #include @@ -40,7 +40,8 @@ void ac_io_bus_fini(void) ac_io_emu_fini(&ac_io_emu); } -HRESULT ac_io_bus_dispatch_irp(struct irp *irp) +HRESULT +ac_io_bus_dispatch_irp(struct irp *irp) { const struct ac_io_message *msg; HRESULT hr; @@ -61,32 +62,31 @@ HRESULT ac_io_bus_dispatch_irp(struct irp *irp) msg = ac_io_emu_request_peek(&ac_io_emu); switch (msg->addr) { - case 0: - ac_io_emu_cmd_assign_addrs(&ac_io_emu, msg, 2); + case 0: + ac_io_emu_cmd_assign_addrs(&ac_io_emu, msg, 2); - break; + break; - case 1: - ac_io_emu_icca_dispatch_request(&ac_io_emu_icca, msg); + case 1: + ac_io_emu_icca_dispatch_request(&ac_io_emu_icca, msg); - break; + break; - case 2: - kfca_dispatch_request(msg); + case 2: + kfca_dispatch_request(msg); - break; + break; - case AC_IO_BROADCAST: - log_warning("Broadcast(?) message on SDVX ACIO bus?"); + case AC_IO_BROADCAST: + log_warning("Broadcast(?) message on SDVX ACIO bus?"); - break; + break; - default: - log_warning( - "ACIO message on unhandled bus address: %d", - msg->addr); + default: + log_warning( + "ACIO message on unhandled bus address: %d", msg->addr); - break; + break; } ac_io_emu_request_pop(&ac_io_emu); diff --git a/src/main/sdvxhook/dllmain.c b/src/main/sdvxhook/dllmain.c index a46d524..47d4fdc 100644 --- a/src/main/sdvxhook/dllmain.c +++ b/src/main/sdvxhook/dllmain.c @@ -12,8 +12,8 @@ #include "hooklib/rs232.h" #include "sdvxhook/acio.h" -#include "sdvxhook/lcd.h" #include "sdvxhook/gfx.h" +#include "sdvxhook/lcd.h" #include "util/cmdline.h" #include "util/defs.h" @@ -38,10 +38,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *config) log_info("Starting up SDVX IO backend"); sdvx_io_set_loggers( - log_body_misc, - log_body_info, - log_body_warning, - log_body_fatal); + log_body_misc, log_body_info, log_body_warning, log_body_fatal); ok = sdvx_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy); @@ -52,10 +49,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *config) log_info("Starting up card reader backend"); eam_io_set_loggers( - log_body_misc, - log_body_info, - log_body_warning, - log_body_fatal); + 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); @@ -104,14 +98,11 @@ BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx) } log_to_external( - log_body_misc, - log_body_info, - log_body_warning, - log_body_fatal); + log_body_misc, log_body_info, log_body_warning, log_body_fatal); args_recover(&argc, &argv); - for (i = 1 ; i < argc ; i++) { + for (i = 1; i < argc; i++) { if (argv[i][0] != '-') { continue; } @@ -140,4 +131,3 @@ BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx) return TRUE; } - diff --git a/src/main/sdvxhook/gfx.c b/src/main/sdvxhook/gfx.c index 98fda9c..740f207 100644 --- a/src/main/sdvxhook/gfx.c +++ b/src/main/sdvxhook/gfx.c @@ -1,5 +1,5 @@ -#include #include +#include #include @@ -12,22 +12,25 @@ #include "util/defs.h" #include "util/log.h" -static LRESULT CALLBACK my_WndProc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam); +static LRESULT CALLBACK +my_WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); static HRESULT STDCALL my_CreateDevice( - IDirect3D9 *self, UINT adapter, D3DDEVTYPE type, HWND hwnd, DWORD flags, - D3DPRESENT_PARAMETERS *pp, IDirect3DDevice9 **pdev); + IDirect3D9 *self, + UINT adapter, + D3DDEVTYPE type, + HWND hwnd, + DWORD flags, + D3DPRESENT_PARAMETERS *pp, + IDirect3DDevice9 **pdev); static IDirect3D9 *STDCALL my_Direct3DCreate9(UINT sdk_ver); static WNDPROC real_WndProc; -static IDirect3D9 * (STDCALL *real_Direct3DCreate9)(UINT sdk_ver); +static IDirect3D9 *(STDCALL *real_Direct3DCreate9)(UINT sdk_ver); static const struct hook_symbol gfx_hooks[] = { - { - .name = "Direct3DCreate9", - .patch = my_Direct3DCreate9, - .link = (void **) &real_Direct3DCreate9 - }, + {.name = "Direct3DCreate9", + .patch = my_Direct3DCreate9, + .link = (void **) &real_Direct3DCreate9}, }; static bool gfx_confined; @@ -64,8 +67,8 @@ static LRESULT gfx_unconfine(HWND hwnd) return TRUE; } -static LRESULT CALLBACK my_WndProc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam) +static LRESULT CALLBACK +my_WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { switch (msg) { case WM_SETFOCUS: @@ -80,8 +83,13 @@ static LRESULT CALLBACK my_WndProc(HWND hwnd, UINT msg, WPARAM wparam, } static HRESULT STDCALL my_CreateDevice( - IDirect3D9 *self, UINT adapter, D3DDEVTYPE type, HWND hwnd, DWORD flags, - D3DPRESENT_PARAMETERS *pp, IDirect3DDevice9 **pdev) + IDirect3D9 *self, + UINT adapter, + D3DDEVTYPE type, + HWND hwnd, + DWORD flags, + D3DPRESENT_PARAMETERS *pp, + IDirect3DDevice9 **pdev) { IDirect3D9 *real = COM_PROXY_UNWRAP(self); HRESULT hr; @@ -136,4 +144,3 @@ void gfx_set_windowed(void) { gfx_windowed = true; } - diff --git a/src/main/sdvxhook/kfca.c b/src/main/sdvxhook/kfca.c index ea3ca53..f4d8894 100644 --- a/src/main/sdvxhook/kfca.c +++ b/src/main/sdvxhook/kfca.c @@ -35,40 +35,42 @@ void kfca_dispatch_request(const struct ac_io_message *req) cmd_code = ac_io_u16(req->cmd.code); switch (cmd_code) { - case AC_IO_CMD_GET_VERSION: - log_misc("AC_IO_CMD_GET_VERSION(%d)", req->addr); - kfca_send_version(req); + case AC_IO_CMD_GET_VERSION: + log_misc("AC_IO_CMD_GET_VERSION(%d)", req->addr); + kfca_send_version(req); - break; + break; - case AC_IO_CMD_START_UP: - log_misc("AC_IO_CMD_START_UP(%d)", req->addr); - kfca_report_status(req, 0x00); + case AC_IO_CMD_START_UP: + log_misc("AC_IO_CMD_START_UP(%d)", req->addr); + kfca_report_status(req, 0x00); - break; + break; - case AC_IO_CMD_KFCA_POLL: - kfca_poll(req); + case AC_IO_CMD_KFCA_POLL: + kfca_poll(req); - break; + break; - case AC_IO_CMD_KFCA_WATCHDOG: - log_misc("AC_IO_CMD_KFCA_WATCHDOG(%d)", req->addr); - kfca_report_status(req, 0x00); + case AC_IO_CMD_KFCA_WATCHDOG: + log_misc("AC_IO_CMD_KFCA_WATCHDOG(%d)", req->addr); + kfca_report_status(req, 0x00); - break; + break; - case AC_IO_CMD_KFCA_AMP_CONTROL: - log_misc("AC_IO_CMD_KFCA_AMP_CONTROL(%d)", req->addr); - kfca_report_0128(req); + case AC_IO_CMD_KFCA_AMP_CONTROL: + log_misc("AC_IO_CMD_KFCA_AMP_CONTROL(%d)", req->addr); + kfca_report_0128(req); - break; + break; - default: - log_warning("Unknown ACIO message %04x on KFCA mode, addr=%d", - cmd_code, req->addr); + default: + log_warning( + "Unknown ACIO message %04x on KFCA mode, addr=%d", + cmd_code, + req->addr); - break; + break; } } @@ -85,8 +87,10 @@ static void kfca_send_version(const struct ac_io_message *req) resp.cmd.version.major = 0x01; resp.cmd.version.minor = 0x01; resp.cmd.version.revision = 0x00; - memcpy(resp.cmd.version.product_code, "KFCA", - sizeof(resp.cmd.version.product_code)); + memcpy( + resp.cmd.version.product_code, + "KFCA", + sizeof(resp.cmd.version.product_code)); strncpy(resp.cmd.version.date, __DATE__, sizeof(resp.cmd.version.date)); strncpy(resp.cmd.version.time, __TIME__, sizeof(resp.cmd.version.time)); @@ -106,7 +110,8 @@ static void kfca_report_status(const struct ac_io_message *req, uint8_t status) ac_io_emu_response_push(kfca_ac_io_emu, &resp, 0); } -static void kfca_report_0128(const struct ac_io_message *req) { +static void kfca_report_0128(const struct ac_io_message *req) +{ struct ac_io_message resp; resp.addr = req->addr | AC_IO_RESPONSE_FLAG; @@ -132,7 +137,7 @@ static void kfca_poll(const struct ac_io_message *req) sdvx_io_set_gpio_lights(ac_io_u32(pout->gpio)); - for (i = 0 ; i < lengthof(pout->pwm) ; i++) { + for (i = 0; i < lengthof(pout->pwm); i++) { sdvx_io_set_pwm_light(i, pout->pwm[i]); } @@ -148,10 +153,7 @@ static void kfca_poll(const struct ac_io_message *req) ctx = req->addr | (req->cmd.code << 8) | (req->cmd.seq_no << 24); ac_io_emu_response_push_thunk( - kfca_ac_io_emu, - kfca_poll_thunk, - (void *) ctx, - delay); + kfca_ac_io_emu, kfca_poll_thunk, (void *) ctx, delay); } static void kfca_poll_thunk(void *ctx_ptr, struct ac_io_message *resp) @@ -192,4 +194,3 @@ static void kfca_poll_thunk(void *ctx_ptr, struct ac_io_message *resp) pin->gpio[0] = ac_io_u16(sdvx_io_get_input_gpio(0)); pin->gpio[1] = ac_io_u16(sdvx_io_get_input_gpio(1)); } - diff --git a/src/main/sdvxhook/lcd.c b/src/main/sdvxhook/lcd.c index 7296da9..176edee 100644 --- a/src/main/sdvxhook/lcd.c +++ b/src/main/sdvxhook/lcd.c @@ -2,9 +2,9 @@ #include -#include #include #include +#include #include #include @@ -41,7 +41,8 @@ void lcd_fini(void) lcd_fd = NULL; } -HRESULT lcd_dispatch_irp(struct irp *irp) +HRESULT +lcd_dispatch_irp(struct irp *irp) { log_assert(irp != NULL); @@ -50,12 +51,18 @@ HRESULT lcd_dispatch_irp(struct irp *irp) } switch (irp->op) { - case IRP_OP_OPEN: return lcd_open(irp); - case IRP_OP_CLOSE: return lcd_close(irp); - case IRP_OP_READ: return S_OK; - case IRP_OP_WRITE: return lcd_write(irp); - case IRP_OP_IOCTL: return S_OK; - default: return E_NOTIMPL; + case IRP_OP_OPEN: + return lcd_open(irp); + case IRP_OP_CLOSE: + return lcd_close(irp); + case IRP_OP_READ: + return S_OK; + case IRP_OP_WRITE: + return lcd_write(irp); + case IRP_OP_IOCTL: + return S_OK; + default: + return E_NOTIMPL; } } @@ -102,4 +109,3 @@ static HRESULT lcd_write(struct irp *irp) return S_OK; } - diff --git a/src/main/sdvxio-kfca/sdvxio.c b/src/main/sdvxio-kfca/sdvxio.c index b74dc6b..5f8736f 100644 --- a/src/main/sdvxio-kfca/sdvxio.c +++ b/src/main/sdvxio-kfca/sdvxio.c @@ -6,7 +6,6 @@ #include "bemanitools/glue.h" #include "bemanitools/sdvxio.h" - #include "aciodrv/device.h" #include "aciodrv/kfca.h" @@ -29,12 +28,14 @@ static uint16_t sdvx_io_analog[2]; static bool running; static bool processing_io; - struct ac_io_kfca_poll_out pout_staging; struct ac_io_kfca_poll_out pout_ready; -void sdvx_io_set_loggers(log_formatter_t misc, log_formatter_t info, - log_formatter_t warning, log_formatter_t fatal) +void sdvx_io_set_loggers( + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal) { sdvx_io_log_misc = misc; sdvx_io_log_info = info; @@ -42,10 +43,11 @@ void sdvx_io_set_loggers(log_formatter_t misc, log_formatter_t info, sdvx_io_log_fatal = fatal; } -bool sdvx_io_init(thread_create_t thread_create, thread_join_t thread_join, - thread_destroy_t thread_destroy) +bool sdvx_io_init( + thread_create_t thread_create, + thread_join_t thread_join, + thread_destroy_t thread_destroy) { - if (!aciodrv_device_open("COM3", 57600)) { log_info("Opening acio device failed\n"); return -1; @@ -66,8 +68,7 @@ bool sdvx_io_init(thread_create_t thread_create, thread_join_t thread_join, void sdvx_io_fini(void) { running = false; - while(processing_io) { - + while (processing_io) { } } @@ -143,4 +144,3 @@ uint16_t sdvx_io_get_spinner_pos(uint8_t spinner_no) } return sdvx_io_analog[spinner_no]; } - diff --git a/src/main/sdvxio/sdvxio.c b/src/main/sdvxio/sdvxio.c index e47ddc2..7aae8fe 100644 --- a/src/main/sdvxio/sdvxio.c +++ b/src/main/sdvxio/sdvxio.c @@ -9,14 +9,19 @@ static uint16_t sdvx_io_gpio[2]; static uint8_t sdvx_io_gpio_sys; -void sdvx_io_set_loggers(log_formatter_t misc, log_formatter_t info, - log_formatter_t warning, log_formatter_t fatal) +void sdvx_io_set_loggers( + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal) { input_set_loggers(misc, info, warning, fatal); } -bool sdvx_io_init(thread_create_t thread_create, thread_join_t thread_join, - thread_destroy_t thread_destroy) +bool sdvx_io_init( + thread_create_t thread_create, + thread_join_t thread_join, + thread_destroy_t thread_destroy) { input_init(thread_create, thread_join, thread_destroy); mapper_config_load("sdvx"); @@ -33,7 +38,7 @@ void sdvx_io_set_gpio_lights(uint32_t gpio_lights) { size_t i; - for (i = 0 ; i < 16 ; i++) { + for (i = 0; i < 16; i++) { if (gpio_lights & (1 << i)) { mapper_write_light(i, 255); } else { @@ -59,7 +64,7 @@ bool sdvx_io_read_input(void) pack = mapper_update(); sdvx_io_gpio_sys = pack & 0xFF; - sdvx_io_gpio[0] = (pack >> 8) & 0x00FF; + sdvx_io_gpio[0] = (pack >> 8) & 0x00FF; sdvx_io_gpio[1] = (pack >> 16) & 0x00FF; return 0; @@ -83,4 +88,3 @@ uint16_t sdvx_io_get_spinner_pos(uint8_t spinner_no) { return mapper_read_analog(spinner_no) * 4; } - diff --git a/src/main/security/id.c b/src/main/security/id.c index 570fc5b..e9fc593 100644 --- a/src/main/security/id.c +++ b/src/main/security/id.c @@ -12,8 +12,8 @@ const struct security_id security_id_default = { .checksum = 0x6F, }; -static uint8_t security_id_checksum_calc(uint8_t initseed, - const uint8_t* inbuf, size_t length) +static uint8_t +security_id_checksum_calc(uint8_t initseed, const uint8_t *inbuf, size_t length) { const uint8_t *v3; // edi@1 int v4; // ebp@2 @@ -41,28 +41,28 @@ static uint8_t security_id_checksum_calc(uint8_t initseed, v7 = 0; do { - v8 = (result ^ (uint8_t) (v6 >> v7)) & 1; + v8 = (result ^ (uint8_t)(v6 >> v7)) & 1; v9 = result >> 1; if (v8) { v9 ^= 0x8Cu; } - v10 = (v9 ^ (uint8_t) (v6 >> (v7 + 1))) & 1; + v10 = (v9 ^ (uint8_t)(v6 >> (v7 + 1))) & 1; v11 = v9 >> 1; if (v10) { v11 ^= 0x8Cu; } - v12 = (v11 ^ (uint8_t) (v6 >> (v7 + 2))) & 1; + v12 = (v11 ^ (uint8_t)(v6 >> (v7 + 2))) & 1; v13 = v11 >> 1; if (v12) { v13 ^= 0x8Cu; } - v14 = (v13 ^ (uint8_t) (v6 >> (v7 + 3))) & 1; + v14 = (v13 ^ (uint8_t)(v6 >> (v7 + 3))) & 1; result = v13 >> 1; if (v14) { @@ -74,13 +74,13 @@ static uint8_t security_id_checksum_calc(uint8_t initseed, v3 = (v3 + 1); --v4; - } while (v4); - } + } while (v4); + } return result; } -static uint8_t security_id_checksum_buffer(const uint8_t* inbuf) +static uint8_t security_id_checksum_buffer(const uint8_t *inbuf) { uint8_t bufcheck[7]; @@ -95,7 +95,7 @@ static uint8_t security_id_checksum_buffer(const uint8_t* inbuf) return security_id_checksum_calc(0, bufcheck, sizeof(bufcheck)); } -bool security_id_parse(const char* str, struct security_id* id) +bool security_id_parse(const char *str, struct security_id *id) { log_assert(str); log_assert(id); @@ -103,9 +103,9 @@ bool security_id_parse(const char* str, struct security_id* id) return hex_decode(id, sizeof(struct security_id), str, strlen(str)); } -char* security_id_to_str(const struct security_id* id, bool id_only) +char *security_id_to_str(const struct security_id *id, bool id_only) { - char* str; + char *str; size_t len; log_assert(id); @@ -125,7 +125,7 @@ char* security_id_to_str(const struct security_id* id, bool id_only) return str; } -void security_id_prepare(struct security_id* id) +void security_id_prepare(struct security_id *id) { log_assert(id); @@ -133,10 +133,10 @@ void security_id_prepare(struct security_id* id) id->checksum = security_id_checksum_buffer(id->id); } -bool security_id_verify(const struct security_id* id) +bool security_id_verify(const struct security_id *id) { log_assert(id); - + return id->header == SECURITY_ID_HEADER && id->checksum == security_id_checksum_buffer(id->id); } diff --git a/src/main/security/id.h b/src/main/security/id.h index 984b4c1..6043a44 100644 --- a/src/main/security/id.h +++ b/src/main/security/id.h @@ -22,37 +22,37 @@ extern const struct security_id security_id_default; /** * Parse a stringified security id, e.g. PCBID, EAMID. - * + * * @param str String representation of id. * @param id Pointer to a security_id struct to write the result to. * @return True on successf, false on parsing error. */ -bool security_id_parse(const char* str, struct security_id* id); +bool security_id_parse(const char *str, struct security_id *id); /** * Stringify a security_id struct. - * + * * @param id Id to stringify. * @param id_only True to stringify id only, false stringify header, id and * checksum. * @return Allocated string with stringified data. Caller must manage memory. */ -char* security_id_to_str(const struct security_id* id, bool id_only); +char *security_id_to_str(const struct security_id *id, bool id_only); /** * Prepare a security id, i.e. update header and checksum. - * + * * @param id Id to prepare. */ -void security_id_prepare(struct security_id* id); +void security_id_prepare(struct security_id *id); /** * Verify a provided security id, i.e. check header and checksum. - * + * * @param id Id to verify. * @return True if verification is successful, false on header or checksum * mismatch. */ -bool security_id_verify(const struct security_id* id); +bool security_id_verify(const struct security_id *id); #endif \ No newline at end of file diff --git a/src/main/security/mcode.c b/src/main/security/mcode.c index 73227c2..5bc93fa 100644 --- a/src/main/security/mcode.c +++ b/src/main/security/mcode.c @@ -14,7 +14,7 @@ const struct security_mcode security_mcode_eamuse = { .revision = '@', }; -bool security_mcode_parse(const char* str, struct security_mcode* mcode) +bool security_mcode_parse(const char *str, struct security_mcode *mcode) { size_t len; @@ -34,9 +34,9 @@ bool security_mcode_parse(const char* str, struct security_mcode* mcode) return true; } -char* security_mcode_to_str(const struct security_mcode* mcode) +char *security_mcode_to_str(const struct security_mcode *mcode) { - char* str; + char *str; log_assert(mcode); diff --git a/src/main/security/mcode.h b/src/main/security/mcode.h index bad201a..18ea491 100644 --- a/src/main/security/mcode.h +++ b/src/main/security/mcode.h @@ -21,39 +21,39 @@ #define SECURITY_MCODE_GAME_LEN 3 /* IIDX */ -#define SECURITY_MCODE_GAME_IIDX_1 "863" -#define SECURITY_MCODE_GAME_IIDX_1_CLUB "896" -#define SECURITY_MCODE_GAME_IIDX_SUB "983" -#define SECURITY_MCODE_GAME_IIDX_CLUB_2 "984" -#define SECURITY_MCODE_GAME_IIDX_2 "985" -#define SECURITY_MCODE_GAME_IIDX_3 "992" -#define SECURITY_MCODE_GAME_IIDX_4 "A03" -#define SECURITY_MCODE_GAME_IIDX_5 "A17" -#define SECURITY_MCODE_GAME_IIDX_6 "B4U" -#define SECURITY_MCODE_GAME_IIDX_7 "B44" -#define SECURITY_MCODE_GAME_IIDX_8 "C44" -#define SECURITY_MCODE_GAME_IIDX_9 "C02" -#define SECURITY_MCODE_GAME_IIDX_10 "D01" -#define SECURITY_MCODE_GAME_IIDX_11 "E11" -#define SECURITY_MCODE_GAME_IIDX_12 "ECO" -#define SECURITY_MCODE_GAME_IIDX_13 "FDD" -#define SECURITY_MCODE_GAME_IIDX_14 "GLD" -#define SECURITY_MCODE_GAME_IIDX_15 "HDD" -#define SECURITY_MCODE_GAME_IIDX_16 "I00" -#define SECURITY_MCODE_GAME_IIDX_17 "JDJ" -#define SECURITY_MCODE_GAME_IIDX_18 "JDZ" -#define SECURITY_MCODE_GAME_IIDX_19 "KDZ" -#define SECURITY_MCODE_GAME_IIDX_20 "LDJ" -#define SECURITY_MCODE_GAME_IIDX_21 "LDJ" -#define SECURITY_MCODE_GAME_IIDX_22 "LDJ" -#define SECURITY_MCODE_GAME_IIDX_23 "LDJ" -#define SECURITY_MCODE_GAME_IIDX_24 "LDJ" +#define SECURITY_MCODE_GAME_IIDX_1 "863" +#define SECURITY_MCODE_GAME_IIDX_1_CLUB "896" +#define SECURITY_MCODE_GAME_IIDX_SUB "983" +#define SECURITY_MCODE_GAME_IIDX_CLUB_2 "984" +#define SECURITY_MCODE_GAME_IIDX_2 "985" +#define SECURITY_MCODE_GAME_IIDX_3 "992" +#define SECURITY_MCODE_GAME_IIDX_4 "A03" +#define SECURITY_MCODE_GAME_IIDX_5 "A17" +#define SECURITY_MCODE_GAME_IIDX_6 "B4U" +#define SECURITY_MCODE_GAME_IIDX_7 "B44" +#define SECURITY_MCODE_GAME_IIDX_8 "C44" +#define SECURITY_MCODE_GAME_IIDX_9 "C02" +#define SECURITY_MCODE_GAME_IIDX_10 "D01" +#define SECURITY_MCODE_GAME_IIDX_11 "E11" +#define SECURITY_MCODE_GAME_IIDX_12 "ECO" +#define SECURITY_MCODE_GAME_IIDX_13 "FDD" +#define SECURITY_MCODE_GAME_IIDX_14 "GLD" +#define SECURITY_MCODE_GAME_IIDX_15 "HDD" +#define SECURITY_MCODE_GAME_IIDX_16 "I00" +#define SECURITY_MCODE_GAME_IIDX_17 "JDJ" +#define SECURITY_MCODE_GAME_IIDX_18 "JDZ" +#define SECURITY_MCODE_GAME_IIDX_19 "KDZ" +#define SECURITY_MCODE_GAME_IIDX_20 "LDJ" +#define SECURITY_MCODE_GAME_IIDX_21 "LDJ" +#define SECURITY_MCODE_GAME_IIDX_22 "LDJ" +#define SECURITY_MCODE_GAME_IIDX_23 "LDJ" +#define SECURITY_MCODE_GAME_IIDX_24 "LDJ" /* Jubeat */ -#define SECURITY_MCODE_GAME_JB_1 "H44" +#define SECURITY_MCODE_GAME_JB_1 "H44" /* Region */ -#define SECURITY_MCODE_REGION_ASIA 'A' +#define SECURITY_MCODE_REGION_ASIA 'A' #define SECURITY_MCODE_REGION_JAPAN 'J' /* Cabinet */ @@ -89,19 +89,19 @@ extern const struct security_mcode security_mcode_eamuse; /** * Parse an mcode from a string representation. - * + * * @param str String to parse. * @param mcode Pointer to a security_mcode struct to write the result to. * @return True on success, false on parsing error. */ -bool security_mcode_parse(const char* str, struct security_mcode* mcode); +bool security_mcode_parse(const char *str, struct security_mcode *mcode); /** * Stringify an mcode. - * + * * @param mcode Mcode to stringify. * @return String containing the stringified mcode. Caller has to manage memory. */ -char* security_mcode_to_str(const struct security_mcode* mcode); +char *security_mcode_to_str(const struct security_mcode *mcode); #endif \ No newline at end of file diff --git a/src/main/security/rp-blowfish-table.h b/src/main/security/rp-blowfish-table.h index 9db279e..fac7887 100644 --- a/src/main/security/rp-blowfish-table.h +++ b/src/main/security/rp-blowfish-table.h @@ -7,222 +7,199 @@ * Custom pbox for blowfish used by the roundplug module. */ static const uint32_t security_rp_blowfish_table_custom_pbox[16 + 2] = { - 0x79F4182B, 0x0B4B1751, 0x170170D8, 0x4C0F65E3, - 0x24F05558, 0x1E46FA6, 0x61E35AB, 0x579903BE, - 0x1E6D3235, 0x47D05ED6, 0x722F4F14, 0x53031912, - 0x2C4771B1, 0x56C43044, 0x4F8A5C95, 0x6A490262, - 0x176C1D7F, 0x64274C38 -}; + 0x79F4182B, + 0x0B4B1751, + 0x170170D8, + 0x4C0F65E3, + 0x24F05558, + 0x1E46FA6, + 0x61E35AB, + 0x579903BE, + 0x1E6D3235, + 0x47D05ED6, + 0x722F4F14, + 0x53031912, + 0x2C4771B1, + 0x56C43044, + 0x4F8A5C95, + 0x6A490262, + 0x176C1D7F, + 0x64274C38}; /** * Custom sbox for blowfish used by the roundplug module. */ static const uint32_t security_rp_blowfish_table_custom_sbox[4 * 256] = { - 0x4BD821B3, 0x6D5E005A, 0x0C5F6494, 0x45960A5D, 0x56956C75, - 0x1CA85246, 0x4BB809AD, 0x25601443, 0x79930BE9, 0x45826099, - 0x2AA261C7, 0x70A57DE, 0x17756A0, 0x2EB87768, 0x635C62A4, - 0x1BCC0A05, 0x763A412D, 0x550F10EC, 0x35BA414D, 0x671238F4, - 0x63A904A9, 0x77BA3004, 0x57A1208B, 0x32FC6ECB, 0x71E65532, - 0x74E64AB1, 0x358E4F6D, 0x54DF640D, 0x4DE52868, 0x762F4498, - 0x30F17C5, 0x41C24222, 0x61EF0BEE, 0x6D287983, 0x1B481CAA, - 0x72E175D5, 0x5E220BEF, 0x5FD857E0, 0x317048F8, 0x1A2D11D6, - 0x10EF2996, 0x5370B41, 0x51514DCB, 0x26CA4139, 0x0F9B6195, - 0x31B536DA, 0x2FCC3108, 0x198F49F5, 0x2EBF429F, 0x13B44006, - 0x4B526BD4, 0x298A1F66, 0x4AC813EE, 0x400928C2, 0x5C6C191B, - 0x387A04CC, 0x60770BBE, 0x0E7E7A30, 0x1634340A, 0x17533FCA, - 0x756215D0, 0x46533F16, 0x36DA6695, 0x1ABD5AE8, 0x507229E8, - 0x1AB80E5D, 0x682067F3, 0x7F957811, 0x263324F, 0x77552592, - 0x6FDE6B1D, 0x1F6B3315, 0x3E460252, 0x1CC31368, 0x307F1D52, - 0x75021428, 0x2025CC1, 0x0D107234, 0x79823495, 0x70D41261, - 0x0ECF0A70, 0x483E3270, 0x27FA0E2E, 0x1D8B263D, 0x31BA00B9, - 0x58C47538, 0x170E5D25, 0x14886C19, 0x5C2417F9, 0x300C76D0, - 0x607A68CA, 0x426056BB, 0x0C43520F, 0x52F4091C, 0x6D0C5B30, - 0x7B5A71CA, 0x59F30E0, 0x564D1E27, 0x55281FAD, 0x5FF33451, - 0x59961CD5, 0x2B5F629D, 0x1144515C, 0x115A6341, 0x3FD95B5B, - 0x3C636850, 0x7A6D399B, 0x35F403EC, 0x3EED1562, 0x590760B7, - 0x1AC05E8D, 0x4DD95E8A, 0x24AA6DDF, 0x72EE676A, 0x4DF12199, - 0x575510B7, 0x4EBF284B, 0x2A2D5CA7, 0x31C86DE9, 0x43682FF3, - 0x432C5F21, 0x29CF4FD0, 0x669F76EC, 0x3A467C21, 0x18C74A64, - 0x545279EB, 0x1FE506D5, 0x2FD82209, 0x2FB81616, 0x40284821, - 0x49F5D1A, 0x48390DD6, 0x39FD48C2, 0x436763F, 0x5FE11CF5, - 0x0C3A4D98, 0x13E739F3, 0x54593938, 0x21594BE6, 0x6DDF03C3, - 0x6C9A18BB, 0x6DDC79A1, 0x2DC5602F, 0x1CE069AF, 0x3E91022D, - 0x54031E34, 0x7F785F57, 0x2B286216, 0x181827E3, 0x5C83664E, - 0x16D90CA8, 0x1591B99, 0x33D00678, 0x0C075470, 0x3AE327B1, - 0x2346433B, 0x612E2C0F, 0x42AD28C2, 0x9A63AC4, 0x447846E4, - 0x3CFC0ECB, 0x38876B8B, 0x58C57979, 0x2CAA27DF, 0x39D77355, - 0x4A1B07BA, 0x65F62F29, 0x6C4C5D5C, 0x78B06359, 0x14E37561, - 0x57853D74, 0x610346F0, 0x714B3409, 0x63CE7434, 0x0CD12ABC, - 0x0A282F10, 0x6AC31C98, 0x6BBD560E, 0x3ECD40A7, 0x2D455D99, - 0x44035CC0, 0x5807596D, 0x70813AA1, 0x4A9B3A4B, 0x0C4E733E, - 0x26F513F1, 0x2F870458, 0x619F7F49, 0x6BB96450, 0x56466CE1, - 0x248E083E, 0x5787B9B, 0x5BAC103E, 0x5FAC27A6, 0x73DA0E0A, - 0x418365AC, 0x2F6419CE, 0x54D7E4D, 0x6DC12937, 0x4DCF3DCD, - 0x6C745CCD, 0x6E444C09, 0x0F303784, 0x13A140B0, 0x733F748D, - 0x131D47AF, 0x52256F72, 0x1F169ED, 0x77805262, 0x7A5C4E39, - 0x4E327ECA, 0x31EB0681, 0x48C26425, 0x44F73D44, 0x29003914, - 0x5B6F5749, 0x6AE84AB1, 0x0AD85D92, 0x56C95620, 0x1991438C, - 0x7EA72068, 0x75C5D88, 0x2ADD4081, 0x7F1A1B6E, 0x7A064FAF, - 0x15D65BB0, 0x381E740E, 0x7B056A7E, 0x30E5796D, 0x7E0C0139, - 0x1846C5F, 0x0D035A29, 0x2D736B90, 0x10B92C72, 0x7A9A2356, - 0x49F82444, 0x58B72788, 0x140A2B53, 0x57FF1F93, 0x307B1587, - 0x730878CA, 0x2105F4, 0x2FE612FE, 0x4D5A200C, 0x5C951B4F, - 0x0B955913, 0x6A970941, 0x30147DD4, 0x2DDD7213, 0x7F04093, - 0x2EB264C, 0x2F5D6342, 0x20384D96, 0x0E2F51F8, 0x16D374CF, - 0x7D9D419E, 0x464C425E, 0x7B4526EC, 0x47D244C3, 0x0D711994, - 0x14990F72, 0x3C9977BC, 0x6B7F19E2, 0x46295DB2, 0x39EE14E1, - 0x6C8345DB, 0x0C042A2A, 0x84864ED, 0x47F15A39, 0x3ED4165E, - 0x38A16C5E, 0x2076D1D, 0x2B9C2511, 0x3D4B3C7F, 0x262A3685, - 0x53D22D7C, 0x75BA1F80, 0x5420341B, 0x1F846C69, 0x4CA792B, - 0x736E0EA3, 0x2E7D0C34, 0x462C3E19, 0x474171AD, 0x16AC191A, - 0x62FF616F, 0x22B17668, 0x0D41496A, 0x2EBE1D8B, 0x703A6897, - 0x535596B, 0x6D06162D, 0x70C0191E, 0x9330918, 0x35F012FF, - 0x557F33A7, 0x50241E00, 0x31E30785, 0x75AD3541, 0x12D135EA, - 0x272F59E1, 0x2BBB4012, 0x4E4A4714, 0x22D46BEF, 0x2F7A2C75, - 0x321A711B, 0x333C629E, 0x59947210, 0x4A734DF6, 0x6D8159B, - 0x720963CB, 0x55D1548E, 0x19D905A1, 0x4EBF4FB6, 0x72CD26C9, - 0x457F420C, 0x68437035, 0x3E0D632F, 0x48B6568A, 0x7A474E12, - 0x619A5677, 0x14F43FF2, 0x12874B46, 0x4E04438C, 0x1B9A13B0, - 0x6C191C8C, 0x2B1978F6, 0x57470748, 0x6E550C2D, 0x511820AE, - 0x29D56DD9, 0x6DD40A7B, 0x1CB033BE, 0x32FF1FAF, 0x333B60F3, - 0x7F224D3D, 0x4CE42438, 0x1ECF6306, 0x195E5089, 0x32DF7108, - 0x50FF43F4, 0x4BFE04D3, 0x4C6630A7, 0x5F6A5B3D, 0x3F607C4D, - 0x78F75A57, 0x1B0D299B, 0x4E5767A0, 0x5B3E0025, 0x17986E78, - 0x43226677, 0x50EE2AD7, 0x4D222261, 0x49B30C3E, 0x52097392, - 0x24AC44EE, 0x2B683C68, 0x2D8E5959, 0x55392D07, 0x27C043D6, - 0x52C224A9, 0x7A630098, 0x5ABC3D35, 0x5D9015E1, 0x0EB53512, - 0x6CE06C73, 0x41B32B3D, 0x43320C48, 0x121A6199, 0x3A81182, - 0x5ACF7987, 0x73F36DA5, 0x3F9E5EB7, 0x0BD14904, 0x58D9543E, - 0x1DD31879, 0x424257E8, 0x7D643B59, 0x112B4FCF, 0x460735A7, - 0x75DC362C, 0x27E05A88, 0x0C35376E, 0x5D767AF7, 0x1F957689, - 0x2EB76CBA, 0x65FA6B91, 0x253D7D95, 0x76691087, 0x55CF26BD, - 0x7E905073, 0x632B148F, 0x7BAA6CB2, 0x1E025682, 0x7AA34C92, - 0x66454B5B, 0x237C6B1C, 0x319F1DA0, 0x13F25731, 0x5B43644E, - 0x4D5A79D9, 0x20E73BCE, 0x39D016D7, 0x71106B26, 0x0C903B81, - 0x6E91696D, 0x1A40FCE, 0x4D4E5781, 0x40C03DB1, 0x6C4641FC, - 0x676A62A5, 0x50D13F63, 0x7E5D3F89, 0x67253EA1, 0x5E301AAF, - 0x2C1F19B4, 0x47330830, 0x244140A7, 0x309A0C82, 0x43F710C0, - 0x12DD4D4C, 0x2D1E2BFA, 0x315E4478, 0x65C664B5, 0x274D298A, - 0x6C3711AD, 0x3BC80531, 0x4C335E29, 0x4147231C, 0x197B6A75, - 0x438560F, 0x73955091, 0x0CE64236, 0x76CB612B, 0x389F21B9, - 0x3E772CCB, 0x6E163790, 0x5C7E2D4E, 0x71066499, 0x6A1B2395, - 0x191812E8, 0x15DE7D7E, 0x70076B5E, 0x52F45813, 0x7B02097D, - 0x0DA87202, 0x3352217A, 0x92A224E, 0x723C4C94, 0x4A8F2743, - 0x54296FA5, 0x351A61AF, 0x57046FF7, 0x3BBA504F, 0x37E42A58, - 0x4BD35F88, 0x53EB6071, 0x55416157, 0x106E1053, 0x139B418B, - 0x0E556A53, 0x7CB44A32, 0x2CC55918, 0x78680C51, 0x1EFD4FF2, - 0x459540D8, 0x197E536D, 0x306735D4, 0x5A6F7027, 0x7DD91BE7, - 0x113F13DE, 0x307847F5, 0x698C7CCD, 0x0A6A3D21, 0x3D443339, - 0x70B012F8, 0x320A4147, 0x13A80BEB, 0x45DB1D10, 0x0D67003, - 0x0EF178F7, 0x1E37FD0, 0x32E76E3B, 0x6CE613A3, 0x591F35C8, - 0x49E33AFD, 0x1C616353, 0x71917046, 0x3FC456A5, 0x96134C2, - 0x2AD25737, 0x0BB28C2, 0x70E70E00, 0x738B7417, 0x67DA518B, - 0x15FC12CC, 0x11DF784C, 0x0D835A15, 0x5EAC2534, 0x5B204982, - 0x7DB4283, 0x3AE17C78, 0x0C901EDE, 0x1CA74FE2, 0x105B60A1, - 0x1A2C1024, 0x21604376, 0x0E454350, 0x29B55427, 0x3165639D, - 0x100B1EB0, 0x5F631E15, 0x4B910299, 0x6A7D698D, 0x6F152182, - 0x1F9C09DA, 0x6F6C1C00, 0x5FDA5342, 0x291510A7, 0x73414231, - 0x69191168, 0x78D53B2D, 0x7D35031E, 0x17D5070C, 0x0F3B1B63, - 0x563F5F65, 0x4FB670A8, 0x38921F44, 0x33CD5085, 0x0ED76C22, - 0x4A6A504D, 0x12E26B14, 0x6C9B4BE6, 0x3BD65642, 0x4D3846D7, - 0x6AE7069B, 0x2BC663A3, 0x556445C7, 0x2E9B6556, 0x4FF47C5D, - 0x28436F5D, 0x5F201057, 0x4C23779A, 0x311107C3, 0x165C1EB8, - 0x649B43BB, 0x6AF262BC, 0x417B6796, 0x302E5FDD, 0x45DD4060, - 0x68401396, 0x2D224088, 0x0E2955F9, 0x53DF63D9, 0x39D87D46, - 0x1D290FAB, 0x4F935FBC, 0x3D10435B, 0x3E9927AF, 0x0C692CF8, - 0x13062DDB, 0x49D1763F, 0x5EF64DF8, 0x6BEE5DCA, 0x3EED698F, - 0x68F87084, 0x7D770D0B, 0x17787760, 0x1A0B6B13, 0x0C506D4B, - 0x37352217, 0x19FC115F, 0x33F50029, 0x55176959, 0x7462390F, - 0x4221484D, 0x1D924296, 0x107F2D98, 0x48BE4B29, 0x6C31017, - 0x71A27EA1, 0x42E6996, 0x24230D5F, 0x3B73168B, 0x2D342998, - 0x0ABE5E05, 0x52FA6EF1, 0x14F535DF, 0x582E684C, 0x3E1739, - 0x4EC427E1, 0x7DC17728, 0x7DCA2590, 0x7EAF37AD, 0x5E925775, - 0x3A8324E4, 0x751338BE, 0x6A88527E, 0x78D32B9, 0x5E9B6D71, - 0x796C1C31, 0x4F3255EE, 0x4D6F42FB, 0x109D1594, 0x130933CC, - 0x0B8C05E3, 0x4308344E, 0x1ED23AF3, 0x4F742372, 0x4E680666, - 0x6ABA3407, 0x63B5269B, 0x4A09358C, 0x630C7624, 0x66FD5F42, - 0x7A772F7B, 0x47B5186, 0x4DB318F0, 0x7ADC415E, 0x437B2CE6, - 0x0F4D0252, 0x380A123F, 0x5A75627D, 0x38DB7915, 0x2590CE3, - 0x2DB32FAB, 0x4B7D6605, 0x12E103A3, 0x454C16B3, 0x28C44371, - 0x15BA3922, 0x3C8F740F, 0x28285C3E, 0x6E490EF2, 0x43885141, - 0x18185C3E, 0x4BC17785, 0x3ABE3D36, 0x32557A96, 0x13647AF6, - 0x5A41368C, 0x3E976D64, 0x73253698, 0x0C900E64, 0x0FA401DC, - 0x6AB84D4B, 0x7B0E2A80, 0x66B3697, 0x123C5302, 0x0CFC43DD, - 0x23BC1DCD, 0x2CFA6802, 0x1B2F3B0E, 0x3CB22BAE, 0x7BEE08C3, - 0x29F56DFE, 0x6EF47914, 0x171C1D79, 0x67F832E7, 0x49487D46, - 0x25D920AF, 0x4BEF4A9C, 0x123F6184, 0x6D945679, 0x44805079, - 0x79D56797, 0x2BC0162A, 0x54AB789C, 0x245D7894, 0x5AEE2690, - 0x7C8A5D2A, 0x2C176395, 0x2C393125, 0x414A41D2, 0x443F2C1B, - 0x75946AB1, 0x58B220D3, 0x6371164A, 0x6A965058, 0x3B91171F, - 0x14B9734C, 0x78DB4E09, 0x7FDC6D7F, 0x15B31A72, 0x62135FC0, - 0x26781AC5, 0x0D6F0BF3, 0x7D515123, 0x51D93F64, 0x3B2A0058, - 0x3641375B, 0x71F9550D, 0x4CF933F1, 0x3C462F3E, 0x275B2D21, - 0x6DEA1FEF, 0x2CB25E22, 0x42176F1B, 0x58581AF4, 0x2A983DEE, - 0x231B243A, 0x245A1934, 0x1BE56D47, 0x352C1010, 0x739D087B, - 0x76C322F1, 0x482DD0, 0x53011EC2, 0x7B740FB0, 0x55773861, - 0x7FD6720A, 0x36287C53, 0x0A3237A4, 0x18F66B6, 0x17B59B3, - 0x1E43776, 0x0A3C7DA9, 0x4D9C56C4, 0x29361D4E, 0x1F2F5DC4, - 0x794A7512, 0x5A1D1786, 0x789A2CA1, 0x61330E38, 0x30EC6DB9, - 0x220A789A, 0x3F4F5D38, 0x79D21BB2, 0x7F002A7A, 0x574D74C0, - 0x5B8E28E1, 0x3E1E3F74, 0x0E3D27B5, 0x0F442C5F, 0x4AA87C2F, - 0x3AE25BA8, 0x1EAB71D0, 0x3F417000, 0x98014F7, 0x19174DD7, - 0x0E280BB3, 0x90A5AD0, 0x450D70D6, 0x52705173, 0x30E5654B, - 0x57597D23, 0x5AD94BA9, 0x35CF724F, 0x79E76207, 0x4A5C16EC, - 0x29852E13, 0x3BCD0F22, 0x73876F5E, 0x74366245, 0x31420BFA, - 0x2B366C08, 0x7F22B47, 0x657C6DED, 0x459730A, 0x0D8A5500, - 0x19A91ABF, 0x9B907C5, 0x7A44931, 0x737E506F, 0x6C027047, - 0x53EB3752, 0x3131B21, 0x979619B, 0x5BA56263, 0x3B04483F, - 0x2287AD1, 0x7C175B31, 0x6710121D, 0x66A64D8, 0x47B6DFC, - 0x2CA941C0, 0x714017F, 0x6A774090, 0x7E376CA1, 0x35B33E3C, - 0x57561A1D, 0x74FA527B, 0x289B6F82, 0x3F6D207C, 0x0ECE4388, - 0x49B41FD4, 0x227A0EA5, 0x244371BC, 0x484B09DC, 0x2EDB1679, - 0x60BB2FD6, 0x6554171B, 0x1AED5433, 0x699B776A, 0x6ED94522, - 0x6EF7041E, 0x2AA2B2F, 0x6A90514E, 0x7F641B5D, 0x2D317D2B, - 0x18CA0F75, 0x4A4D0AEE, 0x4C7F389D, 0x70406A0F, 0x1C6B602C, - 0x15D87DB8, 0x48604ABD, 0x21143879, 0x4AFE5183, 0x6B2B203D, - 0x1DD425DC, 0x45D04E7D, 0x8C77328, 0x65B540B3, 0x0B852DB, - 0x564E0D12, 0x596146D1, 0x5AD74F74, 0x4E802DE2, 0x60986294, - 0x283866B7, 0x6668397D, 0x7EB414DB, 0x7D706D42, 0x610D3C15, - 0x473152F0, 0x636E25F6, 0x14C92DC1, 0x587645AE, 0x0B715192, - 0x39DD0E24, 0x724B4997, 0x45B6E45, 0x0D5B574E, 0x0AC5679B, - 0x29D25DB1, 0x47A7322, 0x3F930CB0, 0x5AFD2858, 0x4BF060DE, - 0x7AE35A94, 0x49B44B6B, 0x2BF02098, 0x6A671652, 0x347D7A69, - 0x74CD58D3, 0x4C1C095F, 0x6CB01024, 0x217F0E78, 0x67DF3064, - 0x779622F1, 0x347741D0, 0x1DF85F18, 0x34615E39, 0x4884635C, - 0x121C22B6, 0x0A4877A6, 0x32BD6996, 0x77A234EC, 0x9346098, - 0x33A46D03, 0x2ED04F5F, 0x6CBD44B4, 0x65062220, 0x0C963413, - 0x646E0C9E, 0x1F3B610C, 0x1D0E5958, 0x357B083F, 0x4BDB3900, - 0x4691680E, 0x97D2630, 0x550461F3, 0x36533159, 0x5ACB4617, - 0x67B748FC, 0x40B57D21, 0x3A83521C, 0x6508044C, 0x2ED324F3, - 0x75686FBD, 0x710D41E4, 0x1FFB6713, 0x341F52B1, 0x5FCB503F, - 0x1084BEE, 0x686C1C96, 0x1F9A42B5, 0x74DE6C24, 0x7C7E4A9C, - 0x7DB47B44, 0x30786FE4, 0x1A760E6E, 0x0CEC21F3, 0x1245504F, - 0x51A22204, 0x5FBD561F, 0x6FC64A1E, 0x2C203E2F, 0x7E334042, - 0x5B01CC1, 0x42F169E9, 0x555C2B1D, 0x75FB33AE, 0x579F6CE1, - 0x21460147, 0x1CA63F99, 0x420059B9, 0x53B1088F, 0x0F1523CC, - 0x65BB74E5, 0x8F806BD, 0x235D7FE0, 0x36A04334, 0x9F03387, - 0x33D11875, 0x63F2576D, 0x749C09DA, 0x48AA01CB, 0x62291881, - 0x3F0F3ED1, 0x34B44542, 0x7E7423E, 0x2ED66EE4, 0x532C572F, - 0x1E066090, 0x64B30234, 0x445F2485, 0x6C1009A9, 0x0FA46F0E, - 0x13B45844, 0x418135B1, 0x0B586DEA, 0x6D1346AA, 0x119F52C7, - 0x6DAB7498, 0x40F6409D, 0x3ACF2A75, 0x23BF765C, 0x3D827BCB, - 0x53B069F4, 0x0AC60525, 0x28754C67, 0x275E30C4, 0x399D1422, - 0x38D83394, 0x37B3018D, 0x47CB565F, 0x60AB51E1, 0x775E5F3F, - 0x1381143A, 0x56092F59, 0x471C54ED, 0x2BA068C8, 0x6878131B, - 0x688D30D8, 0x64043486, 0x1A5C6275, 0x5E496BA4, 0x97E44E3, - 0x5FCD43F2, 0x64461AAF, 0x7837488B, 0x1B381CE5, 0x1CB378F9, - 0x52833683, 0x4598004B, 0x0CCC142E, 0x0F496267, 0x732D5C24, - 0x625913A2, 0x5E7E2272, 0x66F22E8E, 0x5D36D67, 0x47773C13, - 0x76455E48, 0x66841C2, 0x37F65245, 0x6B860A65, 0x444F0FAC, - 0x4C385CDB, 0x318C535D, 0x332E1523, 0x377B527E, 0x2B4453B6, - 0x7180046F, 0x31A9371A, 0x1DD4900, 0x134053B4, 0x7A303EE2, - 0x39465DDE, 0x2D3D5E5C, 0x29363A39, 0x4DEE2C3F, 0x3BE96844, - 0x7F98191C, 0x50027B2E, 0x3B8060B4, 0x7B8914E9, 0x2F9E7DB0, - 0x0D61780, 0x7AA10593, 0x0AB100AA, 0x693300EC, 0x73B7239F, - 0x187D13D0, 0x1D00352A, 0x21EE0A87, 0x17FE5E00, 0x34381E86, - 0x27A84750, 0x3D9C079D, 0x5CD8559B, 0x0B682D72, 0x51F205C6, - 0x2BE0D2E, 0x49C7206E, 0x56962776, 0x35B9377B, 0x5F060A9D, - 0x671F21F8, 0x75C24D18, 0x6FEB6A22, 0x7BDF0C32 -}; + 0x4BD821B3, 0x6D5E005A, 0x0C5F6494, 0x45960A5D, 0x56956C75, 0x1CA85246, + 0x4BB809AD, 0x25601443, 0x79930BE9, 0x45826099, 0x2AA261C7, 0x70A57DE, + 0x17756A0, 0x2EB87768, 0x635C62A4, 0x1BCC0A05, 0x763A412D, 0x550F10EC, + 0x35BA414D, 0x671238F4, 0x63A904A9, 0x77BA3004, 0x57A1208B, 0x32FC6ECB, + 0x71E65532, 0x74E64AB1, 0x358E4F6D, 0x54DF640D, 0x4DE52868, 0x762F4498, + 0x30F17C5, 0x41C24222, 0x61EF0BEE, 0x6D287983, 0x1B481CAA, 0x72E175D5, + 0x5E220BEF, 0x5FD857E0, 0x317048F8, 0x1A2D11D6, 0x10EF2996, 0x5370B41, + 0x51514DCB, 0x26CA4139, 0x0F9B6195, 0x31B536DA, 0x2FCC3108, 0x198F49F5, + 0x2EBF429F, 0x13B44006, 0x4B526BD4, 0x298A1F66, 0x4AC813EE, 0x400928C2, + 0x5C6C191B, 0x387A04CC, 0x60770BBE, 0x0E7E7A30, 0x1634340A, 0x17533FCA, + 0x756215D0, 0x46533F16, 0x36DA6695, 0x1ABD5AE8, 0x507229E8, 0x1AB80E5D, + 0x682067F3, 0x7F957811, 0x263324F, 0x77552592, 0x6FDE6B1D, 0x1F6B3315, + 0x3E460252, 0x1CC31368, 0x307F1D52, 0x75021428, 0x2025CC1, 0x0D107234, + 0x79823495, 0x70D41261, 0x0ECF0A70, 0x483E3270, 0x27FA0E2E, 0x1D8B263D, + 0x31BA00B9, 0x58C47538, 0x170E5D25, 0x14886C19, 0x5C2417F9, 0x300C76D0, + 0x607A68CA, 0x426056BB, 0x0C43520F, 0x52F4091C, 0x6D0C5B30, 0x7B5A71CA, + 0x59F30E0, 0x564D1E27, 0x55281FAD, 0x5FF33451, 0x59961CD5, 0x2B5F629D, + 0x1144515C, 0x115A6341, 0x3FD95B5B, 0x3C636850, 0x7A6D399B, 0x35F403EC, + 0x3EED1562, 0x590760B7, 0x1AC05E8D, 0x4DD95E8A, 0x24AA6DDF, 0x72EE676A, + 0x4DF12199, 0x575510B7, 0x4EBF284B, 0x2A2D5CA7, 0x31C86DE9, 0x43682FF3, + 0x432C5F21, 0x29CF4FD0, 0x669F76EC, 0x3A467C21, 0x18C74A64, 0x545279EB, + 0x1FE506D5, 0x2FD82209, 0x2FB81616, 0x40284821, 0x49F5D1A, 0x48390DD6, + 0x39FD48C2, 0x436763F, 0x5FE11CF5, 0x0C3A4D98, 0x13E739F3, 0x54593938, + 0x21594BE6, 0x6DDF03C3, 0x6C9A18BB, 0x6DDC79A1, 0x2DC5602F, 0x1CE069AF, + 0x3E91022D, 0x54031E34, 0x7F785F57, 0x2B286216, 0x181827E3, 0x5C83664E, + 0x16D90CA8, 0x1591B99, 0x33D00678, 0x0C075470, 0x3AE327B1, 0x2346433B, + 0x612E2C0F, 0x42AD28C2, 0x9A63AC4, 0x447846E4, 0x3CFC0ECB, 0x38876B8B, + 0x58C57979, 0x2CAA27DF, 0x39D77355, 0x4A1B07BA, 0x65F62F29, 0x6C4C5D5C, + 0x78B06359, 0x14E37561, 0x57853D74, 0x610346F0, 0x714B3409, 0x63CE7434, + 0x0CD12ABC, 0x0A282F10, 0x6AC31C98, 0x6BBD560E, 0x3ECD40A7, 0x2D455D99, + 0x44035CC0, 0x5807596D, 0x70813AA1, 0x4A9B3A4B, 0x0C4E733E, 0x26F513F1, + 0x2F870458, 0x619F7F49, 0x6BB96450, 0x56466CE1, 0x248E083E, 0x5787B9B, + 0x5BAC103E, 0x5FAC27A6, 0x73DA0E0A, 0x418365AC, 0x2F6419CE, 0x54D7E4D, + 0x6DC12937, 0x4DCF3DCD, 0x6C745CCD, 0x6E444C09, 0x0F303784, 0x13A140B0, + 0x733F748D, 0x131D47AF, 0x52256F72, 0x1F169ED, 0x77805262, 0x7A5C4E39, + 0x4E327ECA, 0x31EB0681, 0x48C26425, 0x44F73D44, 0x29003914, 0x5B6F5749, + 0x6AE84AB1, 0x0AD85D92, 0x56C95620, 0x1991438C, 0x7EA72068, 0x75C5D88, + 0x2ADD4081, 0x7F1A1B6E, 0x7A064FAF, 0x15D65BB0, 0x381E740E, 0x7B056A7E, + 0x30E5796D, 0x7E0C0139, 0x1846C5F, 0x0D035A29, 0x2D736B90, 0x10B92C72, + 0x7A9A2356, 0x49F82444, 0x58B72788, 0x140A2B53, 0x57FF1F93, 0x307B1587, + 0x730878CA, 0x2105F4, 0x2FE612FE, 0x4D5A200C, 0x5C951B4F, 0x0B955913, + 0x6A970941, 0x30147DD4, 0x2DDD7213, 0x7F04093, 0x2EB264C, 0x2F5D6342, + 0x20384D96, 0x0E2F51F8, 0x16D374CF, 0x7D9D419E, 0x464C425E, 0x7B4526EC, + 0x47D244C3, 0x0D711994, 0x14990F72, 0x3C9977BC, 0x6B7F19E2, 0x46295DB2, + 0x39EE14E1, 0x6C8345DB, 0x0C042A2A, 0x84864ED, 0x47F15A39, 0x3ED4165E, + 0x38A16C5E, 0x2076D1D, 0x2B9C2511, 0x3D4B3C7F, 0x262A3685, 0x53D22D7C, + 0x75BA1F80, 0x5420341B, 0x1F846C69, 0x4CA792B, 0x736E0EA3, 0x2E7D0C34, + 0x462C3E19, 0x474171AD, 0x16AC191A, 0x62FF616F, 0x22B17668, 0x0D41496A, + 0x2EBE1D8B, 0x703A6897, 0x535596B, 0x6D06162D, 0x70C0191E, 0x9330918, + 0x35F012FF, 0x557F33A7, 0x50241E00, 0x31E30785, 0x75AD3541, 0x12D135EA, + 0x272F59E1, 0x2BBB4012, 0x4E4A4714, 0x22D46BEF, 0x2F7A2C75, 0x321A711B, + 0x333C629E, 0x59947210, 0x4A734DF6, 0x6D8159B, 0x720963CB, 0x55D1548E, + 0x19D905A1, 0x4EBF4FB6, 0x72CD26C9, 0x457F420C, 0x68437035, 0x3E0D632F, + 0x48B6568A, 0x7A474E12, 0x619A5677, 0x14F43FF2, 0x12874B46, 0x4E04438C, + 0x1B9A13B0, 0x6C191C8C, 0x2B1978F6, 0x57470748, 0x6E550C2D, 0x511820AE, + 0x29D56DD9, 0x6DD40A7B, 0x1CB033BE, 0x32FF1FAF, 0x333B60F3, 0x7F224D3D, + 0x4CE42438, 0x1ECF6306, 0x195E5089, 0x32DF7108, 0x50FF43F4, 0x4BFE04D3, + 0x4C6630A7, 0x5F6A5B3D, 0x3F607C4D, 0x78F75A57, 0x1B0D299B, 0x4E5767A0, + 0x5B3E0025, 0x17986E78, 0x43226677, 0x50EE2AD7, 0x4D222261, 0x49B30C3E, + 0x52097392, 0x24AC44EE, 0x2B683C68, 0x2D8E5959, 0x55392D07, 0x27C043D6, + 0x52C224A9, 0x7A630098, 0x5ABC3D35, 0x5D9015E1, 0x0EB53512, 0x6CE06C73, + 0x41B32B3D, 0x43320C48, 0x121A6199, 0x3A81182, 0x5ACF7987, 0x73F36DA5, + 0x3F9E5EB7, 0x0BD14904, 0x58D9543E, 0x1DD31879, 0x424257E8, 0x7D643B59, + 0x112B4FCF, 0x460735A7, 0x75DC362C, 0x27E05A88, 0x0C35376E, 0x5D767AF7, + 0x1F957689, 0x2EB76CBA, 0x65FA6B91, 0x253D7D95, 0x76691087, 0x55CF26BD, + 0x7E905073, 0x632B148F, 0x7BAA6CB2, 0x1E025682, 0x7AA34C92, 0x66454B5B, + 0x237C6B1C, 0x319F1DA0, 0x13F25731, 0x5B43644E, 0x4D5A79D9, 0x20E73BCE, + 0x39D016D7, 0x71106B26, 0x0C903B81, 0x6E91696D, 0x1A40FCE, 0x4D4E5781, + 0x40C03DB1, 0x6C4641FC, 0x676A62A5, 0x50D13F63, 0x7E5D3F89, 0x67253EA1, + 0x5E301AAF, 0x2C1F19B4, 0x47330830, 0x244140A7, 0x309A0C82, 0x43F710C0, + 0x12DD4D4C, 0x2D1E2BFA, 0x315E4478, 0x65C664B5, 0x274D298A, 0x6C3711AD, + 0x3BC80531, 0x4C335E29, 0x4147231C, 0x197B6A75, 0x438560F, 0x73955091, + 0x0CE64236, 0x76CB612B, 0x389F21B9, 0x3E772CCB, 0x6E163790, 0x5C7E2D4E, + 0x71066499, 0x6A1B2395, 0x191812E8, 0x15DE7D7E, 0x70076B5E, 0x52F45813, + 0x7B02097D, 0x0DA87202, 0x3352217A, 0x92A224E, 0x723C4C94, 0x4A8F2743, + 0x54296FA5, 0x351A61AF, 0x57046FF7, 0x3BBA504F, 0x37E42A58, 0x4BD35F88, + 0x53EB6071, 0x55416157, 0x106E1053, 0x139B418B, 0x0E556A53, 0x7CB44A32, + 0x2CC55918, 0x78680C51, 0x1EFD4FF2, 0x459540D8, 0x197E536D, 0x306735D4, + 0x5A6F7027, 0x7DD91BE7, 0x113F13DE, 0x307847F5, 0x698C7CCD, 0x0A6A3D21, + 0x3D443339, 0x70B012F8, 0x320A4147, 0x13A80BEB, 0x45DB1D10, 0x0D67003, + 0x0EF178F7, 0x1E37FD0, 0x32E76E3B, 0x6CE613A3, 0x591F35C8, 0x49E33AFD, + 0x1C616353, 0x71917046, 0x3FC456A5, 0x96134C2, 0x2AD25737, 0x0BB28C2, + 0x70E70E00, 0x738B7417, 0x67DA518B, 0x15FC12CC, 0x11DF784C, 0x0D835A15, + 0x5EAC2534, 0x5B204982, 0x7DB4283, 0x3AE17C78, 0x0C901EDE, 0x1CA74FE2, + 0x105B60A1, 0x1A2C1024, 0x21604376, 0x0E454350, 0x29B55427, 0x3165639D, + 0x100B1EB0, 0x5F631E15, 0x4B910299, 0x6A7D698D, 0x6F152182, 0x1F9C09DA, + 0x6F6C1C00, 0x5FDA5342, 0x291510A7, 0x73414231, 0x69191168, 0x78D53B2D, + 0x7D35031E, 0x17D5070C, 0x0F3B1B63, 0x563F5F65, 0x4FB670A8, 0x38921F44, + 0x33CD5085, 0x0ED76C22, 0x4A6A504D, 0x12E26B14, 0x6C9B4BE6, 0x3BD65642, + 0x4D3846D7, 0x6AE7069B, 0x2BC663A3, 0x556445C7, 0x2E9B6556, 0x4FF47C5D, + 0x28436F5D, 0x5F201057, 0x4C23779A, 0x311107C3, 0x165C1EB8, 0x649B43BB, + 0x6AF262BC, 0x417B6796, 0x302E5FDD, 0x45DD4060, 0x68401396, 0x2D224088, + 0x0E2955F9, 0x53DF63D9, 0x39D87D46, 0x1D290FAB, 0x4F935FBC, 0x3D10435B, + 0x3E9927AF, 0x0C692CF8, 0x13062DDB, 0x49D1763F, 0x5EF64DF8, 0x6BEE5DCA, + 0x3EED698F, 0x68F87084, 0x7D770D0B, 0x17787760, 0x1A0B6B13, 0x0C506D4B, + 0x37352217, 0x19FC115F, 0x33F50029, 0x55176959, 0x7462390F, 0x4221484D, + 0x1D924296, 0x107F2D98, 0x48BE4B29, 0x6C31017, 0x71A27EA1, 0x42E6996, + 0x24230D5F, 0x3B73168B, 0x2D342998, 0x0ABE5E05, 0x52FA6EF1, 0x14F535DF, + 0x582E684C, 0x3E1739, 0x4EC427E1, 0x7DC17728, 0x7DCA2590, 0x7EAF37AD, + 0x5E925775, 0x3A8324E4, 0x751338BE, 0x6A88527E, 0x78D32B9, 0x5E9B6D71, + 0x796C1C31, 0x4F3255EE, 0x4D6F42FB, 0x109D1594, 0x130933CC, 0x0B8C05E3, + 0x4308344E, 0x1ED23AF3, 0x4F742372, 0x4E680666, 0x6ABA3407, 0x63B5269B, + 0x4A09358C, 0x630C7624, 0x66FD5F42, 0x7A772F7B, 0x47B5186, 0x4DB318F0, + 0x7ADC415E, 0x437B2CE6, 0x0F4D0252, 0x380A123F, 0x5A75627D, 0x38DB7915, + 0x2590CE3, 0x2DB32FAB, 0x4B7D6605, 0x12E103A3, 0x454C16B3, 0x28C44371, + 0x15BA3922, 0x3C8F740F, 0x28285C3E, 0x6E490EF2, 0x43885141, 0x18185C3E, + 0x4BC17785, 0x3ABE3D36, 0x32557A96, 0x13647AF6, 0x5A41368C, 0x3E976D64, + 0x73253698, 0x0C900E64, 0x0FA401DC, 0x6AB84D4B, 0x7B0E2A80, 0x66B3697, + 0x123C5302, 0x0CFC43DD, 0x23BC1DCD, 0x2CFA6802, 0x1B2F3B0E, 0x3CB22BAE, + 0x7BEE08C3, 0x29F56DFE, 0x6EF47914, 0x171C1D79, 0x67F832E7, 0x49487D46, + 0x25D920AF, 0x4BEF4A9C, 0x123F6184, 0x6D945679, 0x44805079, 0x79D56797, + 0x2BC0162A, 0x54AB789C, 0x245D7894, 0x5AEE2690, 0x7C8A5D2A, 0x2C176395, + 0x2C393125, 0x414A41D2, 0x443F2C1B, 0x75946AB1, 0x58B220D3, 0x6371164A, + 0x6A965058, 0x3B91171F, 0x14B9734C, 0x78DB4E09, 0x7FDC6D7F, 0x15B31A72, + 0x62135FC0, 0x26781AC5, 0x0D6F0BF3, 0x7D515123, 0x51D93F64, 0x3B2A0058, + 0x3641375B, 0x71F9550D, 0x4CF933F1, 0x3C462F3E, 0x275B2D21, 0x6DEA1FEF, + 0x2CB25E22, 0x42176F1B, 0x58581AF4, 0x2A983DEE, 0x231B243A, 0x245A1934, + 0x1BE56D47, 0x352C1010, 0x739D087B, 0x76C322F1, 0x482DD0, 0x53011EC2, + 0x7B740FB0, 0x55773861, 0x7FD6720A, 0x36287C53, 0x0A3237A4, 0x18F66B6, + 0x17B59B3, 0x1E43776, 0x0A3C7DA9, 0x4D9C56C4, 0x29361D4E, 0x1F2F5DC4, + 0x794A7512, 0x5A1D1786, 0x789A2CA1, 0x61330E38, 0x30EC6DB9, 0x220A789A, + 0x3F4F5D38, 0x79D21BB2, 0x7F002A7A, 0x574D74C0, 0x5B8E28E1, 0x3E1E3F74, + 0x0E3D27B5, 0x0F442C5F, 0x4AA87C2F, 0x3AE25BA8, 0x1EAB71D0, 0x3F417000, + 0x98014F7, 0x19174DD7, 0x0E280BB3, 0x90A5AD0, 0x450D70D6, 0x52705173, + 0x30E5654B, 0x57597D23, 0x5AD94BA9, 0x35CF724F, 0x79E76207, 0x4A5C16EC, + 0x29852E13, 0x3BCD0F22, 0x73876F5E, 0x74366245, 0x31420BFA, 0x2B366C08, + 0x7F22B47, 0x657C6DED, 0x459730A, 0x0D8A5500, 0x19A91ABF, 0x9B907C5, + 0x7A44931, 0x737E506F, 0x6C027047, 0x53EB3752, 0x3131B21, 0x979619B, + 0x5BA56263, 0x3B04483F, 0x2287AD1, 0x7C175B31, 0x6710121D, 0x66A64D8, + 0x47B6DFC, 0x2CA941C0, 0x714017F, 0x6A774090, 0x7E376CA1, 0x35B33E3C, + 0x57561A1D, 0x74FA527B, 0x289B6F82, 0x3F6D207C, 0x0ECE4388, 0x49B41FD4, + 0x227A0EA5, 0x244371BC, 0x484B09DC, 0x2EDB1679, 0x60BB2FD6, 0x6554171B, + 0x1AED5433, 0x699B776A, 0x6ED94522, 0x6EF7041E, 0x2AA2B2F, 0x6A90514E, + 0x7F641B5D, 0x2D317D2B, 0x18CA0F75, 0x4A4D0AEE, 0x4C7F389D, 0x70406A0F, + 0x1C6B602C, 0x15D87DB8, 0x48604ABD, 0x21143879, 0x4AFE5183, 0x6B2B203D, + 0x1DD425DC, 0x45D04E7D, 0x8C77328, 0x65B540B3, 0x0B852DB, 0x564E0D12, + 0x596146D1, 0x5AD74F74, 0x4E802DE2, 0x60986294, 0x283866B7, 0x6668397D, + 0x7EB414DB, 0x7D706D42, 0x610D3C15, 0x473152F0, 0x636E25F6, 0x14C92DC1, + 0x587645AE, 0x0B715192, 0x39DD0E24, 0x724B4997, 0x45B6E45, 0x0D5B574E, + 0x0AC5679B, 0x29D25DB1, 0x47A7322, 0x3F930CB0, 0x5AFD2858, 0x4BF060DE, + 0x7AE35A94, 0x49B44B6B, 0x2BF02098, 0x6A671652, 0x347D7A69, 0x74CD58D3, + 0x4C1C095F, 0x6CB01024, 0x217F0E78, 0x67DF3064, 0x779622F1, 0x347741D0, + 0x1DF85F18, 0x34615E39, 0x4884635C, 0x121C22B6, 0x0A4877A6, 0x32BD6996, + 0x77A234EC, 0x9346098, 0x33A46D03, 0x2ED04F5F, 0x6CBD44B4, 0x65062220, + 0x0C963413, 0x646E0C9E, 0x1F3B610C, 0x1D0E5958, 0x357B083F, 0x4BDB3900, + 0x4691680E, 0x97D2630, 0x550461F3, 0x36533159, 0x5ACB4617, 0x67B748FC, + 0x40B57D21, 0x3A83521C, 0x6508044C, 0x2ED324F3, 0x75686FBD, 0x710D41E4, + 0x1FFB6713, 0x341F52B1, 0x5FCB503F, 0x1084BEE, 0x686C1C96, 0x1F9A42B5, + 0x74DE6C24, 0x7C7E4A9C, 0x7DB47B44, 0x30786FE4, 0x1A760E6E, 0x0CEC21F3, + 0x1245504F, 0x51A22204, 0x5FBD561F, 0x6FC64A1E, 0x2C203E2F, 0x7E334042, + 0x5B01CC1, 0x42F169E9, 0x555C2B1D, 0x75FB33AE, 0x579F6CE1, 0x21460147, + 0x1CA63F99, 0x420059B9, 0x53B1088F, 0x0F1523CC, 0x65BB74E5, 0x8F806BD, + 0x235D7FE0, 0x36A04334, 0x9F03387, 0x33D11875, 0x63F2576D, 0x749C09DA, + 0x48AA01CB, 0x62291881, 0x3F0F3ED1, 0x34B44542, 0x7E7423E, 0x2ED66EE4, + 0x532C572F, 0x1E066090, 0x64B30234, 0x445F2485, 0x6C1009A9, 0x0FA46F0E, + 0x13B45844, 0x418135B1, 0x0B586DEA, 0x6D1346AA, 0x119F52C7, 0x6DAB7498, + 0x40F6409D, 0x3ACF2A75, 0x23BF765C, 0x3D827BCB, 0x53B069F4, 0x0AC60525, + 0x28754C67, 0x275E30C4, 0x399D1422, 0x38D83394, 0x37B3018D, 0x47CB565F, + 0x60AB51E1, 0x775E5F3F, 0x1381143A, 0x56092F59, 0x471C54ED, 0x2BA068C8, + 0x6878131B, 0x688D30D8, 0x64043486, 0x1A5C6275, 0x5E496BA4, 0x97E44E3, + 0x5FCD43F2, 0x64461AAF, 0x7837488B, 0x1B381CE5, 0x1CB378F9, 0x52833683, + 0x4598004B, 0x0CCC142E, 0x0F496267, 0x732D5C24, 0x625913A2, 0x5E7E2272, + 0x66F22E8E, 0x5D36D67, 0x47773C13, 0x76455E48, 0x66841C2, 0x37F65245, + 0x6B860A65, 0x444F0FAC, 0x4C385CDB, 0x318C535D, 0x332E1523, 0x377B527E, + 0x2B4453B6, 0x7180046F, 0x31A9371A, 0x1DD4900, 0x134053B4, 0x7A303EE2, + 0x39465DDE, 0x2D3D5E5C, 0x29363A39, 0x4DEE2C3F, 0x3BE96844, 0x7F98191C, + 0x50027B2E, 0x3B8060B4, 0x7B8914E9, 0x2F9E7DB0, 0x0D61780, 0x7AA10593, + 0x0AB100AA, 0x693300EC, 0x73B7239F, 0x187D13D0, 0x1D00352A, 0x21EE0A87, + 0x17FE5E00, 0x34381E86, 0x27A84750, 0x3D9C079D, 0x5CD8559B, 0x0B682D72, + 0x51F205C6, 0x2BE0D2E, 0x49C7206E, 0x56962776, 0x35B9377B, 0x5F060A9D, + 0x671F21F8, 0x75C24D18, 0x6FEB6A22, 0x7BDF0C32}; #endif \ No newline at end of file diff --git a/src/main/security/rp-blowfish.c b/src/main/security/rp-blowfish.c index ace086e..9aeb696 100644 --- a/src/main/security/rp-blowfish.c +++ b/src/main/security/rp-blowfish.c @@ -1,7 +1,7 @@ #include -#include "security/rp-blowfish.h" #include "security/rp-blowfish-table.h" +#include "security/rp-blowfish.h" #include "util/log.h" @@ -11,15 +11,15 @@ static int security_rp_blowfish_enc_sub(int a1) result = a1; - if ( a1 & 7 ) { + if (a1 & 7) { result = a1 - (a1 & 7) + 8; } return result; } -void security_rp_blowfish_init(struct blowfish* ctx, const uint8_t* key, - size_t key_length, uint32_t seed) +void security_rp_blowfish_init( + struct blowfish *ctx, const uint8_t *key, size_t key_length, uint32_t seed) { log_assert(ctx); log_assert(key); @@ -30,8 +30,8 @@ void security_rp_blowfish_init(struct blowfish* ctx, const uint8_t* key, blowfish_init(ctx, &key[seed], 14); } -int security_rp_blowfish_enc(struct blowfish* ctx, const uint8_t* input, - uint8_t* output, int length) +int security_rp_blowfish_enc( + struct blowfish *ctx, const uint8_t *input, uint8_t *output, int length) { int v4; // ebx@1 int v5; // ebp@1 @@ -74,53 +74,52 @@ int security_rp_blowfish_enc(struct blowfish* ctx, const uint8_t* input, v10 = v4 - 7; if (v23) { - if ((unsigned int) v9 >= v10) { - - if ( result - v4 > 0 ) { - memset((void *)(v6 + v4), 0, result - v4); + if (result - v4 > 0) { + memset((void *) (v6 + v4), 0, result - v4); } - blowfish_encrypt(ctx, (uint32_t*) v6, (uint32_t*) v6 + 4); + blowfish_encrypt(ctx, (uint32_t *) v6, (uint32_t *) v6 + 4); v6 += 8; } else { - blowfish_encrypt(ctx, (uint32_t *)v6, (uint32_t *)v6 + 1); + blowfish_encrypt(ctx, (uint32_t *) v6, (uint32_t *) v6 + 1); v6 += 8; } } else { - if ((unsigned int) v9 >= v10) { - v13 = (void*) v5; + v13 = (void *) v5; v14 = v4 - (int) v9; v15 = 0; - if ( v14 <= 0 ) + if (v14 <= 0) goto LABEL_24; v16 = v14; v15 = v14; do { - *(uint8_t *)v13 = *(uint8_t *)v6; + *(uint8_t *) v13 = *(uint8_t *) v6; v13 = (char *) v13 + 1; ++v6; --v16; - } while ( v16 ); + } while (v16); - if ( v14 < 8 ) { -LABEL_24: - ((uint8_t*)v4)[0] = 8 - v15; - ((uint8_t*)v4)[1] = 8 - v15; + if (v14 < 8) { + LABEL_24: + ((uint8_t *) v4)[0] = 8 - v15; + ((uint8_t *) v4)[1] = 8 - v15; v17 = v4 << 16; - ((uint16_t*)v17)[0] = v4; - v18 = (unsigned int)(8 - v15) >> 2; + ((uint16_t *) v17)[0] = v4; + v18 = (unsigned int) (8 - v15) >> 2; // poor man's version of memset32 - //memset32(v13, v17, v18); - for (size_t i = 0; i < v18; i ++) { - *(((uint32_t*)v13) + i) = v17; + // memset32(v13, v17, v18); + for (size_t i = 0; i < v18; i++) { + *(((uint32_t *) v13) + i) = v17; } - memset((char *)v13 + 4 * v18, 8 - v15, - (8 - (uint8_t)v15) & 3); + memset( + (char *) v13 + 4 * v18, + 8 - v15, + (8 - (uint8_t) v15) & 3); } v4 = length; @@ -129,25 +128,24 @@ LABEL_24: v12 = 8; do { - *(uint8_t *)v11 = *(uint8_t *)(v6 - v5 + v11); + *(uint8_t *) v11 = *(uint8_t *) (v6 - v5 + v11); ++v11; --v12; - } while ( v12 ); - + } while (v12); } - blowfish_encrypt(ctx, (uint32_t*) v5, (uint32_t*) a2a); + blowfish_encrypt(ctx, (uint32_t *) v5, (uint32_t *) a2a); v6 += 8; v5 += 8; a2a += 8; } - v19 = (int)(outputa + 8); + v19 = (int) (outputa + 8); outputa = (unsigned __int8 *) v19; v20 = v19 < (unsigned int) v22; result = v22; - if ( !v20 ) { + if (!v20) { break; } diff --git a/src/main/security/rp-blowfish.h b/src/main/security/rp-blowfish.h index 245948c..d17b7a7 100644 --- a/src/main/security/rp-blowfish.h +++ b/src/main/security/rp-blowfish.h @@ -9,24 +9,24 @@ /** * Initializes a blowfish context for use with a modified version of the * algorithm used by the roundplug module. - * + * * @param ctx Pointer to a context to initialize. * @param key Key to use for encryption. * @param key_length Length of the key. * @param seed A seed value. */ -void security_rp_blowfish_init(struct blowfish* ctx, const uint8_t* key, - size_t key_length, uint32_t seed); +void security_rp_blowfish_init( + struct blowfish *ctx, const uint8_t *key, size_t key_length, uint32_t seed); /** * Encrypt some data with the modified version of blowfish. - * + * * @param ctx Initialized context to use for the operation. * @param input Buffer with input data to encrypt. * @param output Pointer to a buffer to write the encrypted output data to. * @param length Length of the input data (output buffer must have min size). */ -int security_rp_blowfish_enc(struct blowfish* ctx, const uint8_t* input, - uint8_t* output, int length); +int security_rp_blowfish_enc( + struct blowfish *ctx, const uint8_t *input, uint8_t *output, int length); #endif \ No newline at end of file diff --git a/src/main/security/rp-enc-table.h b/src/main/security/rp-enc-table.h index cd5e8b8..a302ea3 100644 --- a/src/main/security/rp-enc-table.h +++ b/src/main/security/rp-enc-table.h @@ -7,1030 +7,1029 @@ * Static table used to generate encryption key for roundplug module. */ static const uint32_t security_rp_enc_table_key_base[5120] = { - 0x31594308,0x0AC350F,0x0E92308F,0x1B10E167,0x470CADE7, - 0x0D461503F,0x2E2FC437,0x28746421,0x89E1510C,0x0C7E6153B, - 0x121086D6,0x9494EDDE,0x0F82C6866,0x29218D01,0x5CA95077, - 0x507427BC,0x0D4826C22,0x8B3702CD,0x0ECB13B67,0x8C59F916, - 0x0A0B814AB,0x0BD8DFC1D,0x0E31CA035,0x0BAC88E8A,0x1BE45BB0, - 0x0D2C745AD,0x0A31E17AC,0x8B874DF6,0x475B791D,0x1BCAE57A, - 0x0CC2E7ADA,0x0EE99E075,0x66B0E720,0x27BD26C3,0x3FFFE20C, - 0x17453165,0x0F6BB5E24,0x0C8039002,0x1E87A7CF,0x750E6764, - 0x0BB8ED8D8,0x0F41ECF7,0x0C9FB63EF,0x0BABBEC4D,0x0B5808D28, - 0x4D5E449C,0x0E1D0EF7B,0x0D650693E,0x2425F642,0x147DE131, - 0x48BB63BD,0x0FB12C795,0x8A53CC91,0x33034B30,0x1DB11945, - 0x99862FED,0x0A81E08C4,0x0BD964B59,0x0C4E7AADF,0x62720A25, - 0x7FDCE4C8,0x21BEBA7,0x0DBD1EF97,0x47D90158,0x4F20D8C8, - 0x92B77357,0x452600BB,0x7802FDE5,0x9BC29D33,0x40CE6DE7, - 0x23D937D8,0x67712667,0x22D42CB5,0x1C06A113,0x0D4202DBA, - 0x0C4EBE7BD,0x0E6ADBE3B,0x774319D9,0x0FB70BA6F,0x8175E802, - 0x28E2CDF3,0x0E2AB1D75,0x787EF844,0x0CF541295,0x69471148, - 0x2EA33665,0x6D3F40C6,0x1E0E8D11,0x6AF183EA,0x6DCF2E66, - 0x3AE82AC2,0x1F66C455,0x2B355CC3,0x0EE150E74,0x80EE9144, - 0x0C5635E7C,0x0EEA91502,0x439A1DCC,0x20058B9A,0x3E4946E5, - 0x34226812,0x3EC2E7EC,0x3C247451,0x0FE9DA32B,0x0BEB44DA3, - 0x0EE333391,0x357EE336,0x0B424E02D,0x8DB4FD9F,0x0A6D20AB7, - 0x0AA89B255,0x51E3A407,0x0E2B7F135,0x0F6C3B59B,0x7EFAFAFC, - 0x71FD915,0x3D93E2D1,0x0AE6CBFBB,0x0D1C613B8,0x475EA8F6, - 0x605DCA20,0x0E171EED4,0x5229856,0x0C1647B86,0x4C68E10F, - 0x0DFB84DE2,0x0BA835FE3,0x6735F9E1,0x424BA0CC,0x39662522, - 0x0D19E84AB,0x69180C66,0x0C3DBC0C3,0x0C0DFFE12,0x6B675E3C, - 0x3991DDB1,0x902C3BA1,0x85C9A16F,0x0EA158763,0x8866D59F, - 0x0A9934854,0x0DA091835,0x0EE1BD82C,0x469A9D4C,0x50A66208, - 0x4EC3ABA2,0x593069E6,0x0A5741E17,0x639412A,0x0B35DE432, - 0x4B47941C,0x1577819C,0x8C61DF67,0x1B7C8BA3,0x2596F29B, - 0x486A2FB8,0x0E37473AD,0x0D504AAF1,0x88925B72,0x2F51D088, - 0x4B067827,0x741B895A,0x56EFE9EC,0x0FA714F68,0x47EDA645, - 0x0C826B25A,0x0AFA4F598,0x1A4FD4F7,0x963DF6B1,0x0E1C9EDAF, - 0x0F5E51840,0x41B1C711,0x3A4CA15A,0x12E94355,0x0C7262AF4, - 0x609AD3D3,0x74AD206C,0x0EBADFE8A,0x81E4500,0x0A851E09A, - 0x0C4382D54,0x3D78A6CA,0x0D9C0C2F0,0x88591603,0x0EDFFC0BF, - 0x19F005D3,0x9A423992,0x0B479DFEB,0x0EE59129B,0x0D1F924A1, - 0x0EC1984F2,0x1BB5E56F,0x9DB9C14,0x0F4B94A72,0x0B0FABC5F, - 0x0EF530FEC,0x0BF581897,0x549503C2,0x8DA3964,0x0A0D688FF, - 0x0D1E77ED2,0x331154F,0x54EE96CF,0x0E004B785,0x40DD06B0, - 0x50738B15,0x35AAA9AD,0x9FE3469B,0x4CCE2C60,0x0CE7FAE52, - 0x8DC58E4B,0x0FB71E9E,0x778FA64F,0x4CBC0683,0x7C329C35, - 0x0A105682B,0x82366E28,0x0DDCD5C64,0x64276D39,0x5928D1F, - 0x6E17BEDA,0x0D197BAF2,0x0E41ADA64,0x2D633697,0x7CC80E91, - 0x0B940696B,0x0DFBEFB02,0x49BD4CF0,0x2D1C17BB,0x662DF04B, - 0x76092AA2,0x0CB26F8C7,0x412BD203,0x0E9021B50,0x92F000F, - 0x6361A3F9,0x0BA477958,0x93A5F077,0x39A75657,0x375F6A3, - 0x0D90784E6,0x0F53BBBFC,0x0E72544C7,0x0DCA6DA23,0x1F40AC1B, - 0x0E028025D,0x359D24EB,0x5E797814,0x4D06EAA3,0x66129056, - 0x83468E91,0x3BB33854,0x64AE776B,0x0D6DE6EE4,0x72935DC6, - 0x6359C500,0x0A4CECDA0,0x0C2B0E445,0x0E43AA8D7,0x8B10675, - 0x8F3AA3AF,0x0FCEE7BF6,0x0F930C950,0x9B3E2651,0x0E607F446, - 0x943DFDB3,0x12AA5800,0x0CCC78D6F,0x0AA8BF851,0x0DA81737A, - 0x0D11D2FF2,0x8C50E3ED,0x1C5A29FD,0x61E02487,0x163E6774, - 0x0D1E1228,0x0BC4A3EB8,0x0F9BE9C57,0x2025812,0x0C0B644BE, - 0x4D6E322E,0x0B3C1A1A9,0x0F79D9D9A,0x56DDE08A,0x0CE1E3D4C, - 0x0E0CE3F77,0x95850D1A,0x0BF9990AA,0x81EDD83F,0x1109BC00, - 0x0BD70C1DC,0x2C2D3E7C,0x0E7B0BD75,0x17D8A3C1,0x91511470, - 0x0F20119B,0x0C07CE39A,0x4E0BD76,0x705E9DA1,0x193673E5, - 0x0FA7859B,0x2705121D,0x0FE0C357E,0x3A740D78,0x13C51BA5, - 0x136DEBF2,0x1910F752,0x0A41FC8AF,0x4EAC5E26,0x977DD273, - 0x0E45F3AAA,0x0C8BCCD29,0x817048CA,0x0C6D9905D,0x0C02D9855, - 0x561185C1,0x0AD67107E,0x0EF672CAB,0x4CF1E95E,0x3F219995, - 0x13253170,0x0A54BF29D,0x6B5E4813,0x0B533F203,0x337F630B, - 0x0B8EB68AE,0x3D6B0C01,0x29CBB9A6,0x0D08B9FFE,0x39EC599B, - 0x244BCEF4,0x4BAE565D,0x0E99D1F36,0x7933CE62,0x0C07469FB, - 0x0DE17443,0x0C04A5ADE,0x9E40F3F,0x0F29BF461,0x0A0A9FBB7, - 0x0D5680B65,0x0BA64A6B0,0x0DCB5C9B3,0x748C1354,0x0EB0B2A77, - 0x9D5A5B72,0x0DEF780C0,0x3A4D27F9,0x189F001,0x4A93780, - 0x99D5F393,0x0E5F3DEC2,0x5A76D731,0x7E76841A,0x0EE063B7A, - 0x0A3C2230B,0x75A79673,0x0DD28CABB,0x0FF7DB102,0x0E83F1D73, - 0x14322874,0x3362D320,0x2C71EDF8,0x632F37D5,0x386BC522, - 0x0D009A747,0x1755C968,0x5971850,0x21E8E6A8,0x4443906D, - 0x0A0DF5EA1,0x0BCAA40,0x517C4575,0x6275160E,0x0E804042E, - 0x0C5241741,0x8A3FD935,0x3A4403E8,0x51F955DC,0x493C632, - 0x0CB84DDD6,0x1D945FF7,0x7A332ABA,0x0AF0D612F,0x56E0C984, - 0x9C8A7378,0x47679C13,0x0F7D9D194,0x0AB2857AC,0x888DC9E9, - 0x0D6890375,0x4C7B3F00,0x8D727EFB,0x0F2402A07,0x8AD0F9AD, - 0x5FB9144F,0x0FB12795E,0x2B899DCE,0x3AF56C7,0x2296F99E, - 0x389EBF03,0x0C58C6E7C,0x23DC3512,0x0C659D749,0x0C3EA0C56, - 0x8FAF248D,0x94CED19,0x0BB85D7EF,0x5D0C5605,0x9B9688BE, - 0x193418A9,0x0B3E1626C,0x957D7FB,0x3B28A30E,0x0F1098ED1, - 0x9F7120DD,0x7630967,0x0FF87C0B7,0x748069DC,0x0AF7AFC9F, - 0x0D702A4B5,0x0B71B6539,0x0C28E0259,0x54811E4F,0x3B4BA193, - 0x76875D4E,0x3C67F212,0x414CEEC9,0x349339EC,0x8CB1B1F6, - 0x84821117,0x64DE172C,0x36EE6EF,0x8ABDA96B,0x7A9279B4, - 0x0F17E81D4,0x29B15F08,0x4111CE2D,0x408E8275,0x57AF545E, - 0x66719FE5,0x0C252EAF6,0x36A9C728,0x4738FAA7,0x0BC04DE71, - 0x5E6505C6,0x0FD591FD9,0x0B31D1DCC,0x6DFF96DB,0x0A66E69D8, - 0x7653A4D7,0x0CCA4A42A,0x0F7357E90,0x6CD29EA9,0x0C38CAEAD, - 0x250BA5E,0x1EBE913B,0x0BF376EF7,0x4438D729,0x7E7C645, - 0x0E2EC07CB,0x0F282E1BE,0x9ACEF858,0x0CB6F72FC,0x8356596C, - 0x94D8403C,0x0A7012A87,0x802CA7E0,0x84D0408B,0x789D15EE, - 0x8BC8C542,0x97A38E8E,0x0A470B6D6,0x0AE77298F,0x0A8566357, - 0x0C09990E3,0x0E58AF239,0x864A841F,0x9D21DDD3,0x0ED1356FC, - 0x87B46FE1,0x933D6FD9,0x4DDE4B02,0x4E56C936,0x0DC2E53B, - 0x0A5B2743A,0x0D9820773,0x55E8122E,0x36C94EF5,0x0CD515B00, - 0x0A042AAF1,0x0B28C9AC2,0x51FE1FB,0x5CFD2E28,0x45930D8A, - 0x57490A0D,0x0B958197A,0x0E4DB35EE,0x0A92A488B,0x75634B6D, - 0x0D449AEDF,0x3452FACF,0x0ECFBB580,0x7C5F867F,0x160899D8, - 0x5E054589,0x6F3CEC37,0x1E022320,0x82E91351,0x0B4D91F19, - 0x0D363C8BD,0x4B51CD6D,0x57829677,0x0C5F5D2BB,0x0FA23605F, - 0x35926BC4,0x18A7DAB8,0x64BCE7ED,0x4720DA9,0x4D4828C0, - 0x846DD8C0,0x0A0D3266B,0x52856A6A,0x433A6C3F,0x9D2AC97C, - 0x0CC209832,0x86D14EAD,0x86CDF5E,0x0A3722619,0x78C88781, - 0x800BD3C0,0x0CF236B7B,0x191BA904,0x752F7BD2,0x6127512F, - 0x6E43A31,0x0BE3949EB,0x0D4FC3EE4,0x8B5C62C9,0x6174B35E, - 0x942141BA,0x0E611D8B4,0x9D1DDF99,0x0CFD98020,0x0DC690A9F, - 0x3C96937E,0x7B21E1EC,0x81568BD2,0x17E55B05,0x0A7EEF7C0, - 0x435BC051,0x0E972FB12,0x6AA2F9B,0x38BECD36,0x58011694, - 0x0B8F13ABE,0x0A90EBD4D,0x41ED1FDE,0x5B88BCC1,0x0DED8F1F1, - 0x43A68049,0x519E36F4,0x2BA5CB26,0x8D6C0909,0x534530FB, - 0x3B369AF6,0x0EB4C9B4F,0x3632ABA4,0x9B02C710,0x0E5B14A0, - 0x0FCB4C60B,0x89F0409D,0x1C327C75,0x1DF2AEF0,0x0FD512465, - 0x77A97113,0x1669CA57,0x0F820B023,0x0D1D7D0AB,0x32A42761, - 0x0C7C6924,0x7049A4B4,0x983C206A,0x2B658B26,0x0BD815288, - 0x95135263,0x0B4B6B06E,0x13B1053D,0x2BCCBF70,0x0BA62C42B, - 0x0C5B858C6,0x0D98D40C5,0x97F2270A,0x705C4249,0x0ACF830BD, - 0x0B13E2419,0x82C945C2,0x8666553B,0x8B6B91E0,0x0A4AD9D8, - 0x0AC651145,0x0E24C7BD,0x0C14516FE,0x9674CADD,0x181CC480, - 0x597CA1CD,0x0F2FD9622,0x45C39E47,0x582D8A1,0x0F9932AA8, - 0x0FC472B9B,0x497B4072,0x0F56C0514,0x0BDCDEECA,0x2172EF3, - 0x1221D7FA,0x0A9F04386,0x0B8D0B4F0,0x64A337FA,0x527ACEBE, - 0x2262CDE4,0x39818518,0x0C46120BB,0x0F98BCCD9,0x0A0581C5C, - 0x0D304AA7F,0x2040285,0x3A99BBAA,0x0A6A6E75A,0x56BFAEA1, - 0x3F8235E3,0x832AC5CD,0x0F361298B,0x0D256573B,0x0DC1053A2, - 0x8702511E,0x89DF1ADC,0x9AAFB04B,0x7B2335D1,0x372509BC, - 0x0A9B4337B,0x3EEF020E,0x0FD6FF3BB,0x0C4DAD603,0x0D4B52DD4, - 0x8F7AD500,0x81EBE8EE,0x9EA5E190,0x0CAF80194,0x9FF6F2DF, - 0x6ACAAB37,0x764C933F,0x8ED2E9A9,0x0BD4863A7,0x588315A2, - 0x3ED2952F,0x5FD65D3F,0x7B947095,0x2CC9417E,0x277DD0BC, - 0x0BFDB16C3,0x0AB40A328,0x8928656,0x0A2D36D83,0x6FF60DE2, - 0x5CF1C41A,0x4C137DF8,0x5E98D560,0x6F7B7C8A,0x0E18BDD6B, - 0x9AC10170,0x4FD1B072,0x2FFDAE7,0x0C9343655,0x0D251290D, - 0x0A4C3E915,0x0A758E266,0x0E7505957,0x15B84F5A,0x0CFF3A8E6, - 0x209A8CB4,0x4B860E2E,0x0C42A0B25,0x802655C2,0x6E1A11BF, - 0x46B85ED6,0x811E387A,0x0A8629BC6,0x0D26EEBB3,0x690E938D, - 0x2C47EDA8,0x7AEB624F,0x0CD6AD2FD,0x85EB35D0,0x0E79B833A, - 0x6545D2FA,0x1F24BE4A,0x0ABF50E5A,0x114F95FE,0x1A3755A3, - 0x0CBF0EB88,0x2C10272B,0x4ED9FA01,0x8BC59569,0x1063CFE3, - 0x9962C77D,0x7CEBCB8F,0x0E93579A8,0x705324C8,0x0C3507AD0, - 0x0BE7D6336,0x0A40A2CFD,0x0ACD4E4E5,0x0BC7E06DF,0x74C359C3, - 0x6E0A1545,0x0C43B4726,0x0D3D276A7,0x3F328743,0x383BDE9D, - 0x0FB1EC6B8,0x9B701366,0x17E0603,0x31E17062,0x0D0521A08, - 0x0E3BF6598,0x0DA9E2E8F,0x0CD81F431,0x5EA3DC4,0x0BE6135FB, - 0x2BC599B5,0x0BBE0D3E8,0x9B3D67D7,0x7C3E8D8C,0x96691F82, - 0x0ED03B6A2,0x0D3E01170,0x0AE79B687,0x0FB3FDB43,0x932F86BD, - 0x2DA7F4FC,0x25783869,0x7C3C2484,0x1FEA6CD6,0x6CA70926, - 0x0F2DFDCF0,0x78959413,0x41F7D1CA,0x8F3689DD,0x6694AC19, - 0x92BF03FD,0x0EC5D5EB6,0x0D8E8EE4E,0x12BCF020,0x0AB6E8B8F, - 0x4E60FCF7,0x0C892F0E4,0x0C7BB3182,0x0E2998555,0x0DA85D42A, - 0x204A884E,0x973739FD,0x9A738A1D,0x41914E2D,0x0E064F078, - 0x0D115118E,0x747272F4,0x7389151B,0x4B769F8F,0x8790171, - 0x4F4C5727,0x0A2B31052,0x0E0545000,0x0BC99224,0x4EF49243, - 0x3F926A6F,0x6113FB79,0x0EDAA8E63,0x0D2A0BB14,0x0FAED8B4F, - 0x0CF09D9E6,0x0FE00FE2B,0x7AC5ADA8,0x0C5C81B10,0x6BCA6375, - 0x0CFF02ABA,0x29177E4C,0x0D068040D,0x0B52C5391,0x30E19B8D, - 0x8D8A8C,0x8D5270E4,0x6F43A1E9,0x34761B60,0x5E5A6837, - 0x0AC4BC673,0x9B648669,0x2B95B231,0x0E6F5F258,0x1F59B0D5, - 0x78257B3E,0x0A762A93C,0x7911413D,0x16BF1868,0x885A39D6, - 0x77438AFF,0x36A4AD72,0x40425CA,0x8B19BADD,0x0ADDD1E36, - 0x80E4D0C6,0x97EC41D6,0x84B63640,0x9A146DDF,0x0F8448344, - 0x0C37C15AA,0x0B2C6262C,0x0D00EC036,0x7D79DE3A,0x0B6F98AA4, - 0x971F430F,0x1E30A1B9,0x327A3C34,0x0E4E8C95F,0x0F4D58695, - 0x971ED924,0x777B3301,0x0FC0F3BBA,0x0CA3D29AB,0x8BBE6F75, - 0x0EEF09FAC,0x0EF7189D0,0x5AEDA37F,0x8A34AFE8,0x77909783, - 0x0F0559C00,0x24B9AF7D,0x67E61FFB,0x334E7513,0x6D3F9DE5, - 0x0EAB74652,0x32798A6B,0x8460D228,0x1AF4F45E,0x0AD3B9FEB, - 0x3CD2F933,0x0A3B86D1,0x0E6794C86,0x0AEDA3575,0x1615B493, - 0x0A694AB59,0x2138DBC,0x6E6AC05E,0x91A74506,0x79609A4E, - 0x0E048DF9B,0x0AEFF3952,0x0BF2F7449,0x0E5D4EC7C,0x31DBAD02, - 0x6EEFD93F,0x0EF904A5A,0x8B6579F1,0x0E5D39E0C,0x0F1CE1950, - 0x0B3EF1176,0x4AC75BFB,0x2E749D18,0x0B671B3F4,0x0DDB35119, - 0x45F1EA24,0x7C43D1C1,0x7FEE9FD7,0x7C7ED400,0x0DC16C13C, - 0x8105A5E6,0x4C9916E7,0x0E338A229,0x0B1ACB74F,0x2EBFC0A3, - 0x6008914F,0x0A20405D1,0x0A469E5A9,0x0B3B60C54,0x3A0FC97E, - 0x89488574,0x0D640A6D8,0x8170B398,0x9DC3B820,0x0ABA8ECCF, - 0x0A86691A8,0x4BB11C4B,0x887A9623,0x580B42E0,0x0BC528028, - 0x0FF7DF189,0x3CC8DCB3,0x2193D0E4,0x0F2B88BA3,0x0D11B1BB1, - 0x3C83433D,0x0D7A82057,0x6C8D0CA7,0x300FC35F,0x48BEC56E, - 0x8BEDFBF7,0x8A059C01,0x0CD1F5270,0x60D19934,0x8F4768C0, - 0x0ED9614BD,0x9B4E7100,0x0C64E3ABA,0x72DDB3EF,0x76F68C2A, - 0x0C8E2096E,0x0FB0D606F,0x6126302,0x47185ED3,0x0C8614356, - 0x0C0200400,0x5D8B41B6,0x0C0322386,0x4A8F8895,0x16DE6058, - 0x0C62F5607,0x83B9B44F,0x3F718048,0x3DDBEBA6,0x0D420ED33, - 0x7062297D,0x0D94C16CB,0x0B8ED6056,0x57C68CB6,0x0A821DC9B, - 0x89A572BD,0x4628B716,0x5FC4FE4E,0x8C2D6577,0x0FF41FCFA, - 0x0E9E12AD1,0x3F004CF7,0x0BEF99E1D,0x2D265F9F,0x0E2AE30B6, - 0x879EBEEF,0x1E3CA0DC,0x43988309,0x0B1638431,0x804DDB2, - 0x0CEE9C43F,0x0B31B90D5,0x19161EF0,0x0D3D773FE,0x2D36A214, - 0x2D76F0E0,0x191B37DF,0x39FB88CF,0x0DE981468,0x0A4AD4D47, - 0x0F307482B,0x0CC966663,0x0C2C43387,0x46058E67,0x28B00B41, - 0x5B0D9537,0x0F9AF58FF,0x8604DEDD,0x792A77CE,0x0F804DF06, - 0x0E48E1B9D,0x156DA486,0x0E7CBC7C0,0x0F5614CD0,0x24D5566E, - 0x0E4478A7F,0x0B2277343,0x0E14925D0,0x9B3B21BF,0x23D67925, - 0x5C1335C5,0x8F20F483,0x69B3D71C,0x439F9A15,0x0A7A504F1, - 0x0F8C82A7,0x0EF730F53,0x0F667562C,0x91311BB6,0x0B271D739, - 0x0CFF1A271,0x2D335687,0x5E4CF240,0x9F53C75,0x0E9E0ABC3, - 0x18488383,0x8ECC42FC,0x0E47D3BD8,0x5E3681D5,0x292C06BD, - 0x0E1C50498,0x57AE9C20,0x9028BE75,0x11A24812,0x598D7200, - 0x0B06C6949,0x1F2A3AB0,0x0C0B1F29F,0x38B80361,0x81DCEA91, - 0x0EDF30FD3,0x679DEDC2,0x0FC1B7229,0x9B65A975,0x1976966A, - 0x78EB6216,0x69CCB803,0x0FAA6EB1,0x6EA6843,0x0A460B979, - 0x7F200CDE,0x2F904343,0x55C25D6B,0x0DC019D08,0x7EAAE8E6, - 0x8A3E7067,0x0E5B48F2F,0x4F14F520,0x0E8410689,0x0F3167E9A, - 0x0D9B5571C,0x711CEC5F,0x7EFA5E73,0x7AC0379A,0x92FA4DFE, - 0x0F1E0EAA0,0x41282991,0x6F1FA364,0x0AFF84BE3,0x0C1649701, - 0x7263E110,0x65590C34,0x13646A18,0x11EDDDDF,0x927D3D5E, - 0x2CD2FA88,0x0DF330329,0x5300E6D8,0x618D3826,0x0D530371C, - 0x7299AEE5,0x376219C7,0x0E1E70A58,0x0B158CBEE,0x6F0D4557, - 0x0AF1920CA,0x53212C1E,0x516F003A,0x0B742E1CD,0x0EC68E53F, - 0x380F57E7,0x86D95E7E,0x692EDAD3,0x5ED68FC1,0x51C7855E, - 0x623BAE76,0x0E806CA38,0x0B627882E,0x9E9DEE73,0x347CFA20, - 0x0D43F8A07,0x0E76079A4,0x61260B50,0x8EBF8BB8,0x0F8E328E, - 0x20C64B7E,0x1C389564,0x4269E9BC,0x0B9E81C59,0x0D2DE275B, - 0x8EE7855B,0x6020DDE8,0x3382E137,0x0AF6E7616,0x0B8881522, - 0x38C9713A,0x1FD05A33,0x0A879E1CD,0x0DDB1BDE6,0x5D89EDEE, - 0x5D899F9B,0x0ED4651DE,0x7C363615,0x9FC4DB82,0x0EA00AFC, - 0x0EF59EFE4,0x582D795B,0x0F2003B2,0x944B3422,0x617723BE, - 0x70EABFA5,0x0FE816F7C,0x8FFFF51C,0x32A59887,0x6038221, - 0x0FD0D671D,0x0E0716735,0x9328369E,0x9B4B7A3B,0x0DD297411, - 0x0A896E3FB,0x0F686259E,0x0EFDAA0A0,0x0AF796015,0x49A3013A, - 0x0C82D066,0x5022D3D,0x0C4E33427,0x630D9C01,0x0C523DE12, - 0x1C5A9A40,0x0AE8C3783,0x0D888CB9B,0x53AD3AFE,0x0B6B7A115, - 0x3CD8F5A7,0x0C80BE796,0x26A50BC9,0x942C3A69,0x816D3550, - 0x94C98ABE,0x0F0D0BC4E,0x0B7119E29,0x0CC2F007A,0x0DE388D22, - 0x0A233F4AC,0x5FF84683,0x0B0459F62,0x860D090D,0x6C139D3F, - 0x0FB8ECE3,0x0FD119D86,0x0AD3D570D,0x0C0F6E1A3,0x866587F6, - 0x0C43BC0A3,0x0B4FD0FEE,0x4E9F27B7,0x0C65552AA,0x56A613B5, - 0x3DC20ABF,0x8151997,0x101CC52A,0x4478DFFA,0x284163CB, - 0x1E9CA09F,0x0E59099E5,0x5F15ACEE,0x976E71A0,0x2B9E56E, - 0x5C5C888,0x0B823434E,0x0EA80CE0B,0x653251E0,0x721089FE, - 0x0A087AE18,0x0C2EA5319,0x370A8D12,0x6E075776,0x0A8653589, - 0x621816,0x0A9878260,0x787EEA5C,0x0A223621D,0x0C6DD7790, - 0x2E2F5969,0x528A3C5D,0x9D66FD92,0x74910954,0x75C67B09, - 0x0FC818467,0x0EC1210E4,0x0ACF0A66E,0x6F51905D,0x0B9F73DA6, - 0x1F4DE351,0x4EB2682D,0x4E1583C2,0x8C21F87,0x67B0055, - 0x7BCBA81C,0x83977CD5,0x0ABF623B7,0x0B4432FAE,0x9470FF09, - 0x0BE9CE372,0x0A3E88224,0x79877958,0x3B154500,0x0F12A63B8, - 0x312EB5FA,0x0E66F2891,0x50709450,0x4C85E403,0x0D69C76A6, - 0x0CC5EC5D5,0x0F4774584,0x41318EF0,0x5248BDD5,0x3CFA17E2, - 0x895DF06A,0x81F5CC5C,0x0A886C375,0x87272AB4,0x0AF986F0F, - 0x0FCD54564,0x17EB01B2,0x3E0B4489,0x48DDDBBF,0x0E316E365, - 0x214D31F9,0x330BF1DD,0x74218C08,0x0A93ED0FC,0x86C04BF8, - 0x75CBF76E,0x94981DB7,0x0FC107306,0x499A879B,0x57316139, - 0x49B964D9,0x0D09376A0,0x0AA6F610F,0x6861787A,0x75387DBB, - 0x540BC227,0x29148FC1,0x7BC1C4AE,0x3809BFE9,0x0F9FD8038, - 0x889F0B5F,0x0A0F60E93,0x0F362C431,0x712E19B0,0x0C8640FD5, - 0x27E56025,0x48B865A0,0x0ADA336AC,0x2AF81350,0x0A3B203A2, - 0x17C0BA83,0x0DDA1C089,0x2E31D03D,0x0E4C37F87,0x816F1E66, - 0x73AEE0E4,0x9724404A,0x0FBBC9D90,0x0E8FA2717,0x208DFF9B, - 0x64249A63,0x398367BA,0x0ECD6B1A3,0x0D445C6C9,0x0D7C859B5, - 0x2F3D2543,0x6EB8D357,0x0C01A1ECC,0x71E535AD,0x0AF4E60A8, - 0x9094E7BF,0x57913041,0x0F38F27F9,0x0C85CE2A5,0x0B2A186AA, - 0x476F6405,0x5D1B6885,0x0CD4CB437,0x76528822,0x84B96535, - 0x0F21E727E,0x4D421E9D,0x0BB5D0777,0x3DB51B2F,0x316EFC52, - 0x1BA4A951,0x0A4B75C35,0x0E3E6AE8E,0x0DC2001AC,0x46161F12, - 0x92951F28,0x28138930,0x0F488BA7B,0x217F89DD,0x246C2A5E, - 0x0FD405332,0x0B93B9EEC,0x3C012FEE,0x3DF19624,0x92B2F6F2, - 0x0AE0E676A,0x68049AC3,0x0FE18BC06,0x59EE9C0B,0x92170FA4, - 0x0B62B9418,0x0C61834D3,0x2B9AC5B,0x67ABCE86,0x775C25EB, - 0x3864D896,0x7F19D000,0x6E5D1D3E,0x3CBB9678,0x34B3C09D, - 0x151F255,0x2805B637,0x0D6AE713D,0x0DCF84774,0x0F8E839F8, - 0x56B59020,0x56DA7FF6,0x906904EA,0x16A20FC7,0x0F8C4E6E5, - 0x0E23C8A1,0x0F17BD00A,0x4B841DDD,0x51C630B4,0x8DAF957A, - 0x0E1E3C622,0x0C9D34C98,0x0E09127F8,0x0A6E370FF,0x80963DBF, - 0x14C596,0x6739C560,0x686322EC,0x2FC8CFAD,0x0A20DF1B2, - 0x0E71441D8,0x2615B23F,0x90F055FA,0x0A0C1790B,0x0A0B5168E, - 0x701D6C34,0x83C1E7F3,0x2A7746FC,0x15F4FCEE,0x16E1D649, - 0x2932DF25,0x0B2B38124,0x5E3ECA5,0x2B06BC3A,0x0E476D55D, - 0x0E83A925E,0x72D920A0,0x0FF702405,0x5303A4A7,0x0BE1124C9, - 0x9D6B0F0D,0x234659E7,0x5A8E6351,0x647D1FC0,0x76D7457, - 0x69EAE45B,0x170C6CE8,0x4C03ABE2,0x71F4472D,0x0E0048D21, - 0x0EDB25738,0x2769330A,0x0DB55C17C,0x0DA775D34,0x7CF4FE50, - 0x0E5B35E57,0x87265C6F,0x0E8689ED1,0x0A6897A7B,0x0B8261724, - 0x0F63CCF75,0x0DC3DD876,0x8B642447,0x10468510,0x0E9AB153A, - 0x0C59BD5E0,0x8CBC9480,0x9FDB13F7,0x61C866AC,0x0F6679D0B, - 0x4B04A435,0x56E768F5,0x9F283BF7,0x0FFC57A34,0x0A7F26DB1, - 0x65B06E69,0x23A14E87,0x0B11BF4D9,0x0C47B4782,0x3EBC4FEF, - 0x0AF48960C,0x1C0DD5B7,0x0D4CC75,0x91CE7263,0x44704E70, - 0x938125CA,0x0FE72D596,0x50ED81E4,0x23B0EEE2,0x0A69C2D4F, - 0x9E097B33,0x0AB5D65CE,0x0CDDD30CE,0x26C377C5,0x29016D9, - 0x14A347BE,0x20B0BE1,0x259ACCE6,0x8A3A4055,0x3C849090, - 0x0C58FBA09,0x0F20634B1,0x0D77ED2B4,0x1306E963,0x55FFB571, - 0x1F2EF863,0x0CA0FE442,0x0CB6C3B93,0x342FB589,0x7E75A278, - 0x85E3D08D,0x0D43DAFBD,0x2334B3FB,0x1E80FAAE,0x682F2F62, - 0x0E03DAEBD,0x2364E8B5,0x52350901,0x1568D9CD,0x0DF71E0B2, - 0x7454CEE5,0x0A9B91AAF,0x6B43E81D,0x31E30F8,0x98D71DF7, - 0x0F671B334,0x8EB5B5DD,0x0BDC9C62C,0x5104CE99,0x49019F4E, - 0x0DCF2D9DB,0x0BD370A2B,0x9E301AB6,0x0F34FE7F9,0x0F8712C23, - 0x0F56EA712,0x0C0EE7B7D,0x847FD373,0x0C2E5C804,0x95B1853E, - 0x3A16A85B,0x0CFF7EC38,0x5B440509,0x0F87CC4C,0x0CCBA9CFB, - 0x0E55CFC06,0x25C47E00,0x14B4E718,0x76318F4C,0x15920BD9, - 0x0C0D80AF6,0x943D7DC1,0x7A10FB7A,0x0F1BF63EF,0x0E36C337, - 0x0C06778A3,0x592A97F2,0x4A488CC4,0x2ED20152,0x0BB8025B, - 0x0D4965E62,0x32D15016,0x83E35E12,0x24F382C6,0x0EBA988B5, - 0x0F840B7E2,0x0AEDDB384,0x0FC1FA201,0x0E1F78E1A,0x2FBA0A63, - 0x8F7419F7,0x0C5804B69,0x355529FE,0x0A6A3D319,0x479FE8F6, - 0x0EF9AA69B,0x0A9D9530C,0x70A1DBBF,0x3791BA4F,0x2D351C74, - 0x3ED74333,0x0DD982A52,0x1C0680F,0x6D535612,0x35E5749F, - 0x7EAE0910,0x85E10A83,0x0E33A3DD0,0x0FD69EBE,0x24480276, - 0x0E4E9FA37,0x0FD6FFA4C,0x8CC2BB3B,0x0E00BDD40,0x800DD1F9, - 0x6FB8F663,0x0AEFB0205,0x3DBA46B,0x0F9C268D6,0x2819DA32, - 0x0B618EE48,0x1EDD9F35,0x30BCD71B,0x5AD78F16,0x25EE3772, - 0x278581B,0x47F27854,0x75773EAC,0x0BC91D62E,0x0C14F97D9, - 0x9E97E350,0x2ABE4FD2,0x7C56046B,0x0AA47666C,0x0D622F31A, - 0x6CB16DA3,0x0A5D33B56,0x50860D12,0x0D146BFFF,0x6A96807D, - 0x0B9DC335A,0x82711548,0x0AFF9A08E,0x95F0B0FD,0x7986E526, - 0x53AD48CA,0x0D1703192,0x9F866800,0x0E6278AA6,0x131EAE96, - 0x0D9204919,0x795C4FA4,0x41539B07,0x52EA91E8,0x0A7BD0270, - 0x53B74F44,0x0AE0D2B7,0x0E375793E,0x5C3EB424,0x9F1C927E, - 0x4E22762,0x0D6653054,0x5AD7FA01,0x0D507F30,0x2EAED2F5, - 0x7C9FBE27,0x41FCAA15,0x8F59C075,0x0CADA4F9D,0x66486DF6, - 0x0F263E0AD,0x567A3FAB,0x593A54C8,0x66C4C53B,0x8F02F355, - 0x0D23A2370,0x9BE3DC22,0x8BB88FB6,0x780C7EDC,0x0B55DD69F, - 0x932B1E98,0x270AD561,0x4EF7574D,0x0EFE80156,0x80A79557, - 0x0CCDFE07C,0x0F3779AF6,0x0B2208DF3,0x0E42AFACD,0x499C3881, - 0x87839E64,0x6E8AA311,0x80CB44A6,0x0B1E5A630,0x6B4FFD63, - 0x0D5ECAC8F,0x55DFAECF,0x54A03484,0x414F8F01,0x0D8495188, - 0x0A4FAAF76,0x0C2F22ABA,0x0E93A6F8B,0x0A7E87B5B,0x0EDF10206, - 0x0CE3F1250,0x8403F48E,0x0B44D53A3,0x0F3DA9F2E,0x882CB402, - 0x73E0B7D7,0x0AF3D413F,0x0B509C0DB,0x41A01ACE,0x58479372, - 0x8ABDF04A,0x7513DC38,0x8ABE8CF0,0x14EB9FAD,0x75124823, - 0x0B3CEAEB4,0x34EC93E6,0x0C6C13415,0x0E3C17165,0x324E2EFB, - 0x50CEF96D,0x0D100ED76,0x8290D6EF,0x0F1E996FA,0x304AC781, - 0x0D51CA1DF,0x45831EDC,0x33335DDF,0x6385445F,0x0B4C96A9B, - 0x5DDE348B,0x77013E16,0x0BCE3FC85,0x8EFEA138,0x3B283F97, - 0x7F69304C,0x4A0AB6B0,0x0C4EEDE82,0x8E26AADF,0x4BBF6E6E, - 0x60DE7BDC,0x0F710FB88,0x4ADB1C7F,0x1E9971AA,0x8D869546, - 0x9171195,0x9E8D7FD3,0x77CBF06C,0x0A4648C6C,0x1BF97837, - 0x0FCC2FD7A,0x196AE661,0x0B520290B,0x8CEBCA3B,0x143DFD50, - 0x3CC8B77,0x119D761F,0x0FF61E0AD,0x0D8052971,0x778558D9, - 0x4901BCE5,0x5412D3DB,0x785E6A3C,0x0F56A06F6,0x2EB083DB, - 0x0ADF2FB52,0x66CDE94D,0x40918E7B,0x0D15094BE,0x6935F2DF, - 0x53170F81,0x574E2A53,0x83C6F98A,0x2C52908F,0x2F4285F4, - 0x7C3752AD,0x0D636FA7D,0x0D4FCF0AE,0x2C913405,0x3020BFF5, - 0x99062113,0x842969CA,0x0BA8B4550,0x341F6AD8,0x0DFDB360A, - 0x9C0E94B0,0x8BF421B2,0x89878D44,0x0F799435E,0x0BE204C6C, - 0x8FD17048,0x70F09F65,0x7466904D,0x0C914A84D,0x0F8671D6E, - 0x692C5BA8,0x26A6A753,0x0E0DE02DE,0x373B50C3,0x3652B9BA, - 0x1DFF502E,0x64B5F2ED,0x0FC127123,0x0D8B7F289,0x0AC5694DA, - 0x0F50C5387,0x39F22BAB,0x90EF8041,0x63D0BD95,0x749A3CF8, - 0x1E1E66B8,0x0DFCF1B4F,0x13D154DB,0x25206CE,0x1D1D4AE7, - 0x856CBC61,0x0CDFE206A,0x16A4CD6,0x0E7B34215,0x841C9C62, - 0x0E23E2D3E,0x1157E51D,0x6CE5F55F,0x1D743481,0x0E4B4C195, - 0x14CEEAEF,0x0DEF84D22,0x0D1483D2B,0x0A2C568EB,0x29C4B6DB, - 0x0AD7274FB,0x61ADB10B,0x2E18E8FE,0x0B36EE0AC,0x8B16D1C7, - 0x0CEF8C810,0x0DA904CCA,0x5340426F,0x68EB0EA3,0x58BFFB66, - 0x3552DD8D,0x0E9F1F573,0x763514EC,0x82D6037A,0x12C423C4, - 0x96745143,0x26780C3F,0x0B53DAFA,0x818BE72B,0x0BB00F0AD, - 0x287B5F79,0x0F58AB8D2,0x0D38C33BF,0x0FA08ABBE,0x6D43B6B7, - 0x8011162F,0x98EB50BE,0x33429AC3,0x2813FA56,0x2FBCAD7E, - 0x0A30EC6A4,0x87A31748,0x0C87154F3,0x0C1A0766D,0x4995E2F, - 0x5860BB1B,0x0FE232D6B,0x3913ABE8,0x0D72225C,0x46ED5E49, - 0x0BC2D2EDB,0x0D6A9C31C,0x4DBE5A67,0x32011B1F,0x33D440A0, - 0x1A377976,0x96E18FCE,0x3E904829,0x0D39D8C58,0x0C5D3C5A4, - 0x0F9818C4D,0x0CACE8136,0x4E4D7ADE,0x0DAD1E192,0x0C88357E1, - 0x77319D51,0x94E9B550,0x98C7446D,0x920B3BC8,0x276EB6C7, - 0x0D7B7250B,0x8289A9A3,0x2A7FC17F,0x0FA7B2527,0x873AF2AD, - 0x572C08DF,0x0A083B0C2,0x518A833C,0x56398711,0x18069A11, - 0x44FD148F,0x0CE13A814,0x35B88B55,0x8ABD863,0x0A9123422, - 0x51CAAEFC,0x54FCE8D6,0x0A7F17C43,0x9F2799F8,0x0FBA4ED81, - 0x258AC832,0x0B5EC7E5F,0x37E00DD0,0x2ED5FF6F,0x59279244, - 0x34F117A3,0x0C22398A4,0x8AD4BDD4,0x0DFD9F02A,0x6596C03D, - 0x0D11483B3,0x0F05440FD,0x0EBE3CC42,0x0C9AF3298,0x3519587A, - 0x824BE077,0x0ECCC4D27,0x21516763,0x0D7E0B5,0x0A0EE370E, - 0x9458DDB7,0x6DD2978A,0x81322362,0x0EBB21ED0,0x0D38C2510, - 0x0F0C73B3B,0x4A506ABD,0x454CAD0A,0x0DBAD0E8D,0x29030CE1, - 0x2D953F44,0x0CEB13F49,0x1C40C1CD,0x0DA9D032B,0x3AA86BB4, - 0x0E7166B59,0x480BA7AB,0x4EA5A06,0x0C16CF508,0x32EF0A48, - 0x50116945,0x0E77E899D,0x55062980,0x8EF33663,0x6499F0F9, - 0x62E495F,0x0C6DC8D97,0x1F154837,0x0F6276562,0x201093F8, - 0x2593ED0A,0x438BD991,0x0B680305F,0x3778A055,0x0C30F4FD7, - 0x9DCAC17D,0x96A9FC0B,0x8CFBEAA4,0x3176FE3A,0x0D871A49, - 0x0C7E7B1C5,0x0A06F2951,0x402D83B1,0x0B5B73D82,0x0B9BF7728, - 0x33E85609,0x1D8A6F9,0x0F58FC3F4,0x1DF7B913,0x48BCAAB9, - 0x0C55D700D,0x6E8484AE,0x0E6931EA2,0x1E7F9E8F,0x1EE12B2D, - 0x24A9AFB,0x42D79131,0x3706ECF6,0x0DBC85FD4,0x0D1D85D69, - 0x0A54A395F,0x54678C9E,0x0FB8D6BF,0x3C6168C4,0x0BEB18107, - 0x76F6B771,0x99698EC,0x0E45B921B,0x7E0F1048,0x0DD49E69E, - 0x5C86EF98,0x0AB7BF4B9,0x17AAD07E,0x0C34D291,0x0D8EE633F, - 0x0B1B6E92C,0x0FA08EB45,0x0C2CC75F7,0x8E72BE9E,0x58410841, - 0x0D7ECC87C,0x16707BD,0x0CFF808B4,0x40912B04,0x0A05D113F, - 0x0A990111,0x2CA58ABB,0x4A5B6AC3,0x859FAFEA,0x5E371C5F, - 0x76DECE32,0x9793200B,0x0F837CB1C,0x0BD575254,0x0BE479DD6, - 0x8970E3A9,0x0AAEACEB1,0x2A4EDADE,0x55C5FFA3,0x0C0658FAA, - 0x8BBE61C6,0x0E4AF2F29,0x0CC7F3DD7,0x1E283B5A,0x0CDF66DB7, - 0x6D5109A2,0x0F5D7E1EE,0x0C3AF4147,0x0E0191B23,0x864961F6, - 0x0DF75B3A5,0x102D3A3E,0x76EBD4E6,0x2FEB7113,0x0DD3CBDFB, - 0x0A618FF4C,0x8071401D,0x0ABCCB124,0x7E52472A,0x6724A8BD, - 0x2EF04A25,0x79C2D999,0x951CDAB2,0x73488F1F,0x0F1ED1A9B, - 0x5BE1E41C,0x323E404D,0x2CB84C3F,0x7B2D185B,0x527E0B9C, - 0x0A69E82FB,0x32E8B92A,0x0BDB6EF84,0x9F2FC545,0x8260E8F6, - 0x668FEF2C,0x0E8CB8772,0x0C3C8CD84,0x97EAFBBE,0x0E9A047D3, - 0x6BF308C2,0x7E5F1B06,0x0F6E1850D,0x1D5159EC,0x0FAF2DD51, - 0x0D348E8B9,0x0F0298EE3,0x0A217FF84,0x84CDAD3C,0x118ADC9, - 0x16E8607B,0x59A752E7,0x3BC962E0,0x8AA524A3,0x3A838352, - 0x64F6ABA4,0x8F6C26DA,0x2F0344F5,0x6B9EC126,0x2339A286, - 0x32796007,0x0F08748AA,0x0FB1F22F3,0x38E4119B,0x14F7BA84, - 0x10C7A8F2,0x7C2BEFF7,0x82AE102F,0x67291DAE,0x0E981E37, - 0x0BE26B2AE,0x248AFAD0,0x9C96B222,0x0AC0DA127,0x0D1B634D6, - 0x7FAE664B,0x6302E2BD,0x0EB7D6CB0,0x8BF7D6C,0x338F2DAD, - 0x0AE73569C,0x0C7DF7FE,0x0F367D6AC,0x21E36A43,0x0AD2CF71C, - 0x8FE1FB7F,0x6313C913,0x6A9D7499,0x0D2B3EEDA,0x37BE71DE, - 0x69671E5F,0x70F2E57D,0x0CDCEA4B4,0x36A930A,0x564ADF8D, - 0x0D35995FC,0x9081C2C5,0x3579D92F,0x0BBDE54D9,0x74869E63, - 0x4C11316B,0x4EC0FBBB,0x6A8B07C0,0x756D593F,0x71031A43, - 0x0F55F55A,0x72F4C000,0x36455F5C,0x0B11CE52A,0x788CFDF9, - 0x25FE8996,0x588188C8,0x0FC613D3D,0x0CCFB8EC5,0x15CFAABE, - 0x0BDD7EECF,0x84180ADA,0x8A765F2B,0x12CCACF6,0x853CEA00, - 0x0BAC4749C,0x74126BD9,0x2C9A59FA,0x11E51426,0x4E2CE661, - 0x8B25EABB,0x0B61DB9C7,0x347464F,0x31540746,0x104356FE, - 0x407B169C,0x3B1799C8,0x9581C1A9,0x83426610,0x9B18F8F3, - 0x0DA49661E,0x0EB383E25,0x0A636159D,0x0D89A298B,0x4214451D, - 0x0E43EE598,0x7B749B92,0x48E6B161,0x13EB10D3,0x70996020, - 0x4192711C,0x7C20DAB1,0x2E85E08D,0x0C08C9918,0x796451A9, - 0x45AE2CF9,0x0B5D50DD8,0x469EB71E,0x0E60032E5,0x0B43571F5, - 0x8113180,0x0B3932410,0x88BA4FBD,0x1B99B0A3,0x0C8AE2593, - 0x0F7708909,0x9F27205E,0x900353F,0x0D761015E,0x447ACF67, - 0x0AD1D5E36,0x51CF8747,0x551F1F6E,0x0B361FC8,0x73B002F1, - 0x2AA6F77,0x0A31C188F,0x0FC6AE207,0x0F235467C,0x6F77F7CD, - 0x62CFC5CF,0x819C143,0x6B42A205,0x285A6786,0x74EB3E7B, - 0x618AA5D7,0x5EABCFF7,0x0FDBA491D,0x0FA67DD20,0x7841B762, - 0x8D86C601,0x1396552,0x53763B8B,0x0FD035FBF,0x0F927C010, - 0x84BFC520,0x228E30C8,0x0E2D5480D,0x0E323374F,0x176FB1C4, - 0x4764D625,0x58FC5AA7,0x0CC50E32D,0x8CAFB2BC,0x0E4ED862F, - 0x0CFFDBD2C,0x75C2BD56,0x0F22392C4,0x595ED8B3,0x0F89EDC77, - 0x0DECFFEB8,0x9BB15ADA,0x472BA7BD,0x0C6E35EA7,0x490B1F7E, - 0x187E523B,0x900B0A9B,0x67102E17,0x384BDA17,0x3BEE0363, - 0x53F15ADA,0x4FAC7366,0x69A5272F,0x13A7370F,0x0F4143147, - 0x2D7B9870,0x0E06D3FB4,0x0F38DF63D,0x11E768EE,0x0F2834451, - 0x0DD399BD1,0x6BC68A2A,0x8D20181D,0x0D0076168,0x0E0DDF5F5, - 0x4BB77B52,0x88B49A61,0x388E1951,0x0AB6E44CC,0x0A6059272, - 0x64D88687,0x0DADBD3E8,0x4042C344,0x0CC94D988,0x0C101B69B, - 0x0A8F5394C,0x0DDEDEA89,0x4E8A99D1,0x80E342EB,0x0D32034D9, - 0x6457208,0x0FD4B5AC9,0x0C2758405,0x0CBE1ED2B,0x7B5E556E, - 0x0EA7DE52E,0x0E9EB15B3,0x41FDCD21,0x3C8DCAA8,0x670544FC, - 0x95B9CE05,0x277A7DD7,0x8B674CE4,0x307BF70,0x0A895C746, - 0x0AE9BE6AA,0x0E9C3938E,0x90E9E009,0x42745A04,0x46E73137, - 0x17B39954,0x20506F81,0x0C48B200C,0x0A122C75A,0x168E9521, - 0x22076D7,0x0CF4FF16B,0x0B0515032,0x26E80224,0x0C97F3D48, - 0x4575E86D,0x0A3B9B71B,0x0CA9798C9,0x45D14E50,0x46F25BA0, - 0x0EBDF24B2,0x0C1AF50BE,0x87BC71AD,0x34FAE6D1,0x3B8800D4, - 0x0D8563EE,0x0DF25AF5B,0x0AE04600D,0x81BAF39E,0x0EFAF4B88, - 0x0E0315298,0x98C3E3A0,0x0F1B8E86D,0x0E701BFF8,0x5A44E3E0, - 0x102EC818,0x0FA0906DD,0x0B891BAEC,0x5E0329F1,0x7978A742, - 0x4D71B8CD,0x61B37450,0x3E5530C8,0x73175A2B,0x0DCF5A559, - 0x24FC6650,0x895D3EA0,0x0DFC0FA20,0x0D8DAB7DE,0x82424A5C, - 0x1180DFF9,0x0DF67DFAD,0x0B1A618F9,0x3C99181E,0x0E865D98E, - 0x0D343A4A0,0x191C2F87,0x53570985,0x5DEF375C,0x5DC82006, - 0x43A6A5,0x71096BD,0x34342A1,0x5CAA6C2B,0x985E66B0,0x0DA997833, - 0x0A9C782D9,0x0F3E0E29D,0x52F49845,0x8D08A895,0x6220C0C2, - 0x839D1B2A,0x0DEC9A541,0x21B160CF,0x7E330659,0x0AC57F0DC, - 0x2EE336C2,0x0D729180E,0x8E249DDA,0x4FC37903,0x72853423, - 0x304689BF,0x63590DC2,0x8DD6112A,0x1C35C802,0x0EC1CAD90, - 0x0E761FCF,0x0C8C54E20,0x0DCB95B3C,0x0D01BB6D,0x0E061DDFE, - 0x0A0050CEF,0x0A41596EE,0x0D5892E83,0x6A3F8F8B,0x0F64A62E7, - 0x0A58E6275,0x0C28ABE3F,0x7D74BEF3,0x0EC8BAA94,0x4FA9E86E, - 0x9817644F,0x2BA635F4,0x0E2FB7DC2,0x542B90B7,0x5788599F, - 0x0C3BAFA8B,0x7911B37F,0x0A419056B,0x3F6F175C,0x0D8D458F4, - 0x93806618,0x71B82FE8,0x0D2A356F4,0x395AD8AC,0x503EEF19, - 0x2C8E36CB,0x0D1390E13,0x0F9F04172,0x1180E650,0x855F85F1, - 0x3D847BA6,0x687C9F40,0x78BB25CA,0x6D30C378,0x571C13DA, - 0x16233955,0x65A4C5D4,0x1746DBBB,0x9FD3911D,0x0D64A982E, - 0x0F92F1FFB,0x0F126F458,0x0D8C0EC1A,0x0B8958687,0x9693CB0B, - 0x0AF95782D,0x1375FC0,0x0DE90B5E,0x0DC43A312,0x40991055, - 0x5CCE623C,0x666D70EF,0x0ACF5BF5D,0x0D575A62E,0x6A59AFF9, - 0x95843FB8,0x289F7A79,0x0E0B06156,0x0ECEE3DA6,0x0A9D44175, - 0x0B0746B32,0x120EABA8,0x0E2E14730,0x0F4417E24,0x0E5EA6C96, - 0x5B942D42,0x8EC745C2,0x8F13F01,0x0A9B695F2,0x0ED87D082, - 0x7276F0CB,0x0B4480E8A,0x1BCC40D3,0x396CBD03,0x4C0242F7, - 0x0BEDB47B,0x9F630605,0x0EF085DA4,0x20C07233,0x5CC238D2, - 0x0D3EFC097,0x615980,0x2E46FBAC,0x3AEFE6CB,0x9A2486D4, - 0x9EBB9AF6,0x0F66995D0,0x75D744E4,0x15F8B249,0x3A9B49A1, - 0x3B3C394B,0x1E201EDA,0x0A3A1DDC5,0x85C6CE5F,0x0FC16210A, - 0x86AE7AA8,0x0E792DF53,0x6E41D44E,0x7B8CC43B,0x3EA7A38E, - 0x0C181D241,0x295143CA,0x3971DD4A,0x17702207,0x53630F1C, - 0x257B436F,0x0F6DD64E4,0x22ADBFD0,0x0FD6C2EB1,0x14853F1C, - 0x0B52292F6,0x0B14483E7,0x6013090C,0x0E673DEEC,0x0B5D7E1AE, - 0x535AB889,0x5E0CB97B,0x0CD890B3E,0x78D10878,0x0DB53E632, - 0x164B978B,0x394EEDAD,0x0BF230201,0x58D5D79F,0x0EC063B09, - 0x0DC86EF18,0x8B250736,0x1DC593CE,0x7EB37F01,0x0A637B89B, - 0x1C699045,0x0B94764FC,0x0AF057CC1,0x0CAA43292,0x0F5C6579A, - 0x0FFC1D2A5,0x9FF28AD6,0x0B654879C,0x0D55054E2,0x0FFD7A786, - 0x0B0AF430D,0x1D0A1E95,0x0BE5DBF0A,0x0A6FEB9D,0x82B18072, - 0x0F0CDA199,0x0F1811340,0x0B1AEE727,0x0F6AC5A54,0x60E1F907, - 0x0EF9209F0,0x0C5F825A0,0x2D97293E,0x0DDCB4F7B,0x78A498C7, - 0x57F36EC6,0x89A587FD,0x18500CD2,0x8E0CFBB3,0x0B884CA95, - 0x0AA4D4DA0,0x376D928,0x7360AAE0,0x7ACF824A,0x72429372, - 0x0CF809FDC,0x0A6745EBB,0x6C3A2063,0x17AB301,0x0ECF5878A, - 0x0E95D10F1,0x0A16A6C9D,0x0B82A461A,0x0C99FA0F,0x3C71F970, - 0x684370F4,0x38C724CA,0x2071A088,0x0E2449364,0x54EB74A6, - 0x6306675D,0x58C26451,0x5AAC963A,0x34C7012F,0x59DB6861, - 0x25116E09,0x66BDFB9F,0x1B7BE14D,0x7C7DC0A3,0x3A23278C, - 0x7CCFB81,0x59ED1DFC,0x6B604730,0x85FE37F7,0x7E6F100C, - 0x7F41FD7A,0x9381754,0x3AE589A7,0x4C7AF1AD,0x5EDD0A43, - 0x77FB899D,0x0C85F4439,0x31039911,0x7660E15,0x15DE35D8, - 0x0E030D38A,0x305E4026,0x0CBC011EC,0x8456F512,0x745DDDB7, - 0x88206018,0x3C115D06,0x0A518E298,0x0B52B4C1D,0x0BB1FB054, - 0x29BE7AE0,0x9A1954F6,0x13204A59,0x896F2B88,0x0A46B3235, - 0x0C38EE5FA,0x40FF3E48,0x0F56609A0,0x0FFFE8D05,0x0C1EC6EB1, - 0x2CCFD207,0x3E98C3C9,0x0C99CD58B,0x76E70867,0x9D3EFF3, - 0x0E7DA1270,0x0D5A99244,0x2750BAB,0x4892BEA9,0x0AF42F043, - 0x33CB8DEE,0x0C7CC1148,0x99D0A806,0x9824942D,0x34E6D086, - 0x645FF34B,0x0EE935627,0x0E315795E,0x6820A347,0x0BCE4C903, - 0x771EB169,0x10EB5840,0x0A2DE90B1,0x0F050EDFB,0x0A6F7E269, - 0x0E2BB2882,0x0F2C45F7F,0x60D8F802,0x2BE45204,0x58D8230F, - 0x0A9B81AAE,0x0ADF0C323,0x0F9E9AA57,0x0B4D9C317,0x59DF097C, - 0x0B84F66AB,0x3E4BD3BF,0x7793C004,0x0D19DB666,0x0A3E93B29, - 0x6D8FF6DA,0x621A1385,0x2398E928,0x0CEF2DA68,0x377A7B83, - 0x75C3F586,0x0A1B5ACC0,0x0DAE01E76,0x8C110DD8,0x0F223E034, - 0x0DA18476A,0x0A9691EA0,0x9E999436,0x5B108CFC,0x0A12743A3, - 0x5B803372,0x0DE98383A,0x6F9FF28C,0x5876A29,0x515BF8BA, - 0x0FCD264C2,0x30244BD0,0x591CC4F9,0x2D6E4485,0x0EA4CBFE9, - 0x0DE3410F6,0x2D0C9B4F,0x0CF703120,0x0D84B340D,0x0FCA4FB69, - 0x52BB77A9,0x58551718,0x3854EACC,0x498A04D8,0x0D9CF22C3, - 0x2A519139,0x0BA2C4B01,0x0C73B642F,0x132DA49B,0x0E5DB7691, - 0x50D800CA,0x0B74A949B,0x91F9476D,0x6AA6DF6D,0x2A9EF385, - 0x9A8F4D8A,0x249993B7,0x0DBA8275A,0x0BB024BCD,0x311C89A8, - 0x0DEB25235,0x9816E524,0x0B1C97280,0x7C487FE2,0x0E288CE5, - 0x4265F2D9,0x0F811BC,0x0BEA7AA66,0x46218A03,0x0BA4A69C6, - 0x0D6D411DC,0x760FC39F,0x5802D60D,0x22BAA178,0x0A7E29B7E, - 0x6694C13C,0x536F38BF,0x0DBEA34BB,0x22E71880,0x8F8CDF29, - 0x8A4EBA17,0x844EFA9E,0x38E931FD,0x318A9494,0x8DC3A451, - 0x9D0E6C,0x1C2CCF54,0x0CF669BE9,0x2D3580EB,0x6FCAC7B2, - 0x3C351B20,0x2832EDD5,0x7B4616A1,0x330BBE3F,0x4CC87D40, - 0x3E45C145,0x0C8DE7071,0x0ECD5CE1E,0x3BEDA0CF,0x52349266, - 0x0A520D698,0x7BDD0E9D,0x3AE66C2C,0x0E5D317A6,0x0E371D192, - 0x218D849,0x0BB3909F2,0x0B8374BB1,0x93782B1C,0x0E1BBC4EF, - 0x6FACE200,0x0CBB56775,0x618ED34,0x0B93BAC9B,0x46429E72, - 0x60E3E21D,0x0CE765F16,0x6B4CA99B,0x724228A4,0x0F8967718, - 0x0BAF90A40,0x19E5147C,0x6330A735,0x54E21D12,0x0DD44B86F, - 0x2339850B,0x0CBD18600,0x751C0FF9,0x863C719F,0x2BBED654, - 0x9B2B6C24,0x9CD9C6F8,0x48077F0D,0x112920A5,0x38143FD, - 0x49EFF97E,0x0F30A6A37,0x0F66FBB8B,0x745A3527,0x3E73A338, - 0x98EAFBDA,0x3CC541D3,0x0A179A981,0x7CB8FC11,0x888B3CF2, - 0x82A08B89,0x78E54927,0x44567D38,0x541276BD,0x0ACB5B2FC, - 0x2DE2FE75,0x171FDF19,0x0CDE631B7,0x0D8F80EB7,0x2FF5F10A, - 0x0B52A1B61,0x4AA369D,0x69A03987,0x2FE38BC2,0x21CB6BFE, - 0x4A448F6D,0x0FF200B7B,0x20B275BA,0x9A98471B,0x30D88464, - 0x7C2F9FDE,0x30A5984E,0x0A2656827,0x88CC9FFE,0x0FFC04C3E, - 0x0D3431D1D,0x0FA47C7CF,0x61C4A8F9,0x0EC09AB68,0x0B8506D03, - 0x0A3949EFE,0x0EA7A951,0x0E17F9769,0x0D0D0301D,0x0DDE164E3, - 0x1E98EA44,0x0C1D6278D,0x4D0B51C8,0x2A01D4EA,0x64FCF54E, - 0x0AC05B562,0x0A083F8A1,0x4C0BE6C1,0x0F079922D,0x340D9B5, - 0x79FE8E84,0x4254D453,0x13F4CADD,0x68FB6E93,0x0CA82BB90, - 0x4D6F15CF,0x5E91E79C,0x0BBED8B48,0x0C3526A21,0x0F03464A1, - 0x0A2B772E6,0x1E098962,0x0D6F5C2D4,0x0EBB5B977,0x0F0083279, - 0x0F18503AE,0x0B32F2E86,0x3E494D3D,0x996C3351,0x0D5D6D039, - 0x4C055554,0x2B859920,0x2E06BBAC,0x0ABB10A50,0x0D2BC219B, - 0x333C568D,0x813B5606,0x950B097F,0x0B5D9BCF8,0x17857E31, - 0x0A1B2CA1D,0x0F3196794,0x0A7228D48,0x0D7B549FA,0x0E04D22EE, - 0x664FFD9C,0x999B3EA8,0x0B6603014,0x0D034A7B5,0x0D064E4E3, - 0x0BB88B875,0x335BEDED,0x41CAE1EF,0x514B74F8,0x7E70244C, - 0x10BC7730,0x43B59A5A,0x4B3A47A6,0x9417EB0A,0x4ED709CC, - 0x29DAD9F2,0x5DA736FB,0x0EE82B7CC,0x2E421BED,0x835DEAF5, - 0x6A455943,0x0BCF76EEF,0x31D06600,0x22A354E0,0x930A0A0D, - 0x70F93C10,0x1799E3B3,0x1753E06F,0x372AE224,0x0BB4F890D, - 0x0E2EFCCF2,0x0B350989F,0x0F91CB996,0x8DFDFE01,0x0D36998EA, - 0x87C0C4AE,0x0BA94AAAF,0x1747844A,0x6BDC0209,0x6507ED19, - 0x9A860CFE,0x0CBB44485,0x6B5C02FA,0x5CCBDE9C,0x0FA29784E, - 0x5A09A68F,0x0D33ED2AC,0x0BEF09D34,0x7BF0C8AD,0x0B5495585, - 0x0E618E94C,0x1D9D7520,0x0FF911568,0x0BBA39C5,0x23BE0245, - 0x4835EFDA,0x0A601B80B,0x0D0E27AEA,0x4C451546,0x525DD221, - 0x0D1754A64,0x0B38583D2,0x62035B3B,0x8BFB2AF2,0x2262A381, - 0x0A6A8FB9A,0x0A68C4E51,0x84343E89,0x797DDDAC,0x0D990CDA0, - 0x98B6A5F6,0x0E6D9764,0x0F7BB5075,0x0BEC2207F,0x0FB955BD6, - 0x3A4AFF3F,0x0FE5096A7,0x5035E15,0x0CE7EA8DE,0x59B07E18, - 0x2EB38850,0x0A0583180,0x5307053B,0x0FCC65D2B,0x68973FBD, - 0x0C007801B,0x0B042B5B,0x0F4EF27F5,0x0CDF2137B,0x0D5947584, - 0x0B68A14EA,0x52D0A235,0x0BFF99E56,0x90C47999,0x57EFF8D5, - 0x6850D9E5,0x0DF21B95C,0x0E49C3575,0x2DC85049,0x0C5921445, - 0x0C1F7DDA,0x619276,0x0BAE8D5B4,0x3BFBDDD0,0x69E8425D, - 0x5598B93A,0x0BF6680C2,0x0DC31FD43,0x57B0A2B1,0x9506139C, - 0x3D978B60,0x0F8197C9C,0x75EE75E5,0x0B1B149BB,0x750F6EBB, - 0x20D8A317,0x0A655D544,0x0D9DD44F2,0x0E7A3E241,0x24D2FB32, - 0x0ADC1B5B,0x7E0E2DE0,0x5569E09E,0x17AD4FA9,0x3B6E0F9, - 0x530B6C60,0x0C1B5A1BF,0x494DA57A,0x3159FC29,0x47D9AC91, - 0x6A1C9FD2,0x4BD848E1,0x757A8A39,0x8BBBD5CE,0x0D1749243, - 0x0EEB3C15C,0x0F10EE0B6,0x91370FB6,0x0B9D173BF,0x4482D8A8, - 0x54A9A6D,0x0A13C524,0x21897B33,0x9C2B96C1,0x52A28F6A, - 0x0E6529F37,0x4C3023CD,0x88D345E4,0x0B9CDD9FB,0x573B854A, - 0x0B99B25F9,0x0DADE6D8F,0x5CBED0AD,0x0CD52A1FC,0x2AE07964, - 0x0A1F2D87F,0x9BAC0F4D,0x0FA5C5D29,0x9F5358FB,0x30F48EB0, - 0x180A6DE7,0x0CF5F60ED,0x5B8A3BEC,0x1708D95F,0x0B38E03C9, - 0x7C9E94A7,0x0DD59DBA3,0x2694410A,0x8D2D2C80,0x739F23F3, - 0x0E8D532CD,0x703C906E,0x71C7FD9,0x642874AD,0x7B547858, - 0x45E6CE87,0x0C3D0D6E0,0x413D31F4,0x0D86A266F,0x36B74492, - 0x0A2FE49E4,0x3A234324,0x7FECF581,0x14137C0E,0x0C39A3370, - 0x0C15FD3D9,0x33F0DF3B,0x0F0A03FB5,0x89DB2A52,0x87B64AF2, - 0x0F3CA1B88,0x1C439586,0x94340A96,0x7C2E518B,0x1102497, - 0x2720C7BE,0x0C65BEA8A,0x0D10AD101,0x0DE96B2D4,0x0E39D5FD9, - 0x3E4524BB,0x0F9D1F3F1,0x4B72BEEC,0x625F2595,0x5F2751F6, - 0x0A3462037,0x49F782CD,0x0F34A23EE,0x0CA764A48,0x0C07001F2, - 0x19BD76A3,0x2984A122,0x5FE727FD,0x82937E7E,0x3B9652DB, - 0x0D47228AD,0x3F6F42A3,0x5A35C278,0x71991222,0x4B8824D, - 0x0CB423307,0x0F81935BD,0x0BC1BEC66,0x0C3BB8FE,0x0A5D7D436, - 0x4E467F6A,0x5DB05AD3,0x7C2212FE,0x0ADE13E7C,0x8CFF8BDC, - 0x0D42D16D6,0x25D019C9,0x557CA68,0x24CB80AF,0x0E4A7181D, - 0x18EB971D,0x0C6C10C5,0x0C76EC9C2,0x8C749993,0x0A75794F6, - 0x6696EBA0,0x65ED0D31,0x0E291267,0x613A5A92,0x0F18A7148, - 0x2F8D3659,0x0EB9A3D05,0x18F9716D,0x0D03DFE48,0x98D36ED7, - 0x0E4DC111B,0x0DE38A345,0x63E3296E,0x4E851C88,0x0FA44C995, - 0x2DDF817,0x4BF3CCC7,0x45A7EA89,0x6D68DDA0,0x170CBA1E, - 0x6A20FF9F,0x0AC7DC137,0x0C01C07A9,0x0EC2C71DA,0x0E0611D85, - 0x0F48ECA2F,0x0B2763E5E,0x94E0E606,0x0EE9BD44,0x0CF9E6E4E, - 0x45CABDAB,0x5F0D239F,0x962EB8EA,0x2EB257B2,0x0B9AEFCBD, - 0x0DED970E3,0x58E529C3,0x41106BB6,0x91F6B401,0x0E2A9574F, - 0x7603675E,0x7A3BD6F8,0x8CB7DE25,0x7C21A09F,0x4FBD0C86, - 0x8AFA0055,0x0AD47B415,0x0FD2755D0,0x8688F049,0x615192EA, - 0x333AAEFE,0x0F6E0BE20,0x0FC192DF3,0x30847514,0x0A065854D, - 0x38B0650C,0x0D0641C13,0x6A1AD270,0x0B4DE32B0,0x0D53D1250, - 0x659F5674,0x0BDD811DB,0x72F9EE13,0x1C6CCFE9,0x5C40B324, - 0x1DC1DD73,0x194C33A3,0x9F61E415,0x94FA4D70,0x0B91B1E93, - 0x2BABB8CE,0x3082DA51,0x30C37DE4,0x26CFCD9,0x6A2B783F, - 0x0DF747B59,0x91D0DB4F,0x0AA78E222,0x0D422ABE5,0x0FC1BCF2B, - 0x569642BC,0x0A244778C,0x0AD24CBED,0x1A9D2003,0x62CAC878, - 0x1A15A672,0x75078FC2,0x95EF65F,0x0D660C912,0x84709672, - 0x0ECDFF213,0x0DA041BFB,0x118FDC55,0x901AB16A,0x14012CCC, - 0x0DE7497D4,0x0B6CADB4F,0x3018A175,0x2E03B61B,0x0A6D2B429, - 0x0A6C8DF4D,0x95B04DF1,0x0BBB94A6B,0x484FA74,0x7C40DC, - 0x2F66DF7C,0x7C38DF6B,0x72F3375,0x271C98C8,0x0B0FFC0F1, - 0x71D6B007,0x1B76726,0x0BC1DC01F,0x880996E,0x0DD28356D, - 0x8442DFC7,0x9E34D02E,0x692E5351,0x3F012708,0x5F3525D2, - 0x0F0552282,0x438E1735,0x59798087,0x0A5340107,0x12B74FE8, - 0x48654EF9,0x2BE277D7,0x0A5257D60,0x0A6CE306C,0x69B9A1B8, - 0x0F8D38723,0x0F22CE11D,0x8C4EDD5C,0x0D6CEF9D0,0x402068DA, - 0x5CAFB7B9,0x0E52DB045,0x1287FDF,0x0C3DF13A8,0x0F453C7F1, - 0x13A142F3,0x9A8E9BC0,0x8364C17A,0x0BFD1BC3,0x0B61D6B74, - 0x9305F892,0x0C144EC7E,0x32D1FB6B,0x0AF574515,0x1CD07EB1, - 0x0FE554C1F,0x3A34F067,0x1F442963,0x0A77555B9,0x0FAABDA0D, - 0x34CDC474,0x6818B02B,0x0E5BAE889,0x0B89CCF32,0x727F808E, - 0x2B4AB279,0x0C6A2DF3C,0x77BCA5BC,0x836F6CF2,0x478E499B, - 0x7C742231,0x0B9E01319,0x3904111E,0x0DFD8CD1E,0x77B4DB03, - 0x3F1E14F5,0x0A6E139CF,0x535FD9CF,0x69277491,0x0ACAE03E, - 0x1AEBEC01,0x459644BA,0x43D394F7,0x5A7AF020,0x254874F1, - 0x9533272D,0x35FB2591,0x0B202FE07,0x9A5D591D,0x642BDDB5, - 0x0B12551FE,0x0D17701A3,0x89CF6442,0x13B3FD1F,0x67177F1A, - 0x0B92F34DE,0x43829F5C,0x44406178,0x49D55901,0x0ABBE0FE7, - 0x599B53A8,0x0D786210C,0x87A4C812,0x28F94B2A,0x9C8108A4, - 0x0EE7C9769,0x9309F5E9,0x0F0F6E254,0x1DD7870D,0x0E9555C5C, - 0x1EC94963,0x60A0C53,0x2D82DADF,0x698849F1,0x18EA6D9C, - 0x0A9C84153,0x5EA94958,0x4FC87676,0x0B3AF4AF3,0x5B073CC1, - 0x7FAF5EF4,0x0BD0B3D79,0x5F9F0904,0x0DDDCF64A,0x0A239E171, - 0x138637C4,0x0CE7D13AC,0x2F9BA6DB,0x192EDCCB,0x0F3AE3C67, - 0x0F0501108,0x94D9C7A2,0x74B09740,0x3D3867AD,0x0F75CEB74, - 0x8B6C110B,0x83279C4C,0x12190E24,0x5427CC8F,0x0D6687DC4, - 0x5936B3AC,0x0D385CD99,0x0B7741C35,0x762244B9,0x46C3E55F, - 0x22F37B19,0x12498383,0x0AC30E016,0x0DBF27C9F,0x0DF1632F0, - 0x95ECECD6,0x0F966084B,0x0E92901EC,0x2CE44BAD,0x0B2E17ECB, - 0x1DDAB702,0x810D3B01,0x68925E1B,0x1AEDA43F,0x1BE0252A, - 0x0F48336DB,0x36964547,0x0BD15054F,0x320DCCEF,0x0D3AF39B8, - 0x77A21980,0x0CC9E8B58,0x0E43763BE,0x0F0F6CD14,0x4BAE3351, - 0x0BA0D60F7,0x0F272E545,0x5AFEBBAD,0x13EE2B88,0x3628EB09, - 0x5C138A6F,0x64AC0D7F,0x70D7DB32,0x31F2D6AB,0x65B0CB6B, - 0x9D250CC8,0x441D5B9B,0x0DDB20A3A,0x8C1E61A6,0x0D8CD4005, - 0x0AFB70552,0x0AAECB053,0x937046CB,0x254A73F2,0x12D87222, - 0x4B6532D3,0x7BFDB1C9,0x0D480AC8C,0x0FF67B19,0x0AE2237D7, - 0x855A1DCC,0x78963711,0x86C63983,0x769A9BC,0x315B4242, - 0x0E1EE9BFD,0x993D04EF,0x0C4BDB01F,0x42151AD6,0x2030A10E, - 0x0A7907528,0x99E5B7DD,0x0B7DEDC77,0x863F5341,0x5334673C, - 0x75E46613,0x0D24A0351,0x0A540F9D2,0x7EDDF177,0x8A01A61E, - 0x142E47D2,0x4C9A1D3E,0x47826D68,0x48C0A09C,0x3EA0A1A5, - 0x8DF08744,0x115674DA,0x60E7BC68,0x50F44AB9,0x0BA2740DE, - 0x7DCFDEDB,0x0C579A5A0,0x8DC0BC3B,0x6266924B,0x6AA3C5B8, - 0x0A6BC43A1,0x74D8AF96,0x58100608,0x0FBC582FD,0x7436BE08, - 0x0C7511C79,0x0ABCA64D1,0x916BAD79,0x0E1AB81B3,0x87813CD0, - 0x0AE7AB5A4,0x0CB0A2037,0x0DE1F33BD,0x0F5FC88C8,0x0F14543BD, - 0x8C56F484,0x9BD9BF84,0x9198BACF,0x458F9699,0x0F54682EF, - 0x8A5E4CA6,0x1D69C991,0x0BBFF78F7,0x650E6243,0x5B7144FE, - 0x9BC4F0FB,0x0A477F1D1,0x7F226E8E,0x1851AA,0x4A3FA73A, - 0x911F4A66,0x2438BE1D,0x0AA995A08,0x0ABAEA8BC,0x535A0E33, - 0x7345AD7D,0x0C97889B3,0x8127EA2D,0x0FBCD03F4,0x0CF7FD27A, - 0x0F794789,0x0CCFEA87A,0x0DB5F34A7,0x0D8590723,0x6CA33DA8, - 0x0CCC85AD0,0x8233EA88,0x708864C2,0x123B546B,0x35BB99D, - 0x0C3AEAC15,0x0B70343E7,0x71C4B570,0x32CBBF8D,0x0AD76460A, - 0x0EFE3D5E,0x3B04C995,0x5A6DA38D,0x9370BF65,0x17ED2B33, - 0x610139F5,0x0BCD7E0CB,0x5C16063,0x0B28725B4,0x13FFEEEF, - 0x0D8DD2EB2,0x0D4CDB27F,0x0BF856E,0x0C382111E,0x709586F1, - 0x113A8079,0x63CBE42D,0x21510A61,0x85532275,0x0DECD04C, - 0x7B201AFF,0x1F7084D3,0x58AC7969,0x5909ED35,0x29744131, - 0x0ED2567D3,0x6A76463C,0x0C6F660B2,0x8EB9B250,0x0FEF3DBFC, - 0x7CC5819A,0x6557F17F,0x0C270529,0x0A14B2D,0x8EEF6370, - 0x8712A99A,0x443215C8,0x0E6325F82,0x0E28866EC,0x0BE4CD240, - 0x158EF87B,0x0E1EDFF57,0x0FA65417A,0x0D969F4ED,0x0A2320ACF, - 0x6256554B,0x949CEFC7,0x0EB0FD95E,0x4B51E291,0x1832CB39, - 0x0B481A8C0,0x43238991,0x0B2615ACD,0x0F7860840,0x9AAAE693, - 0x74C94EC3,0x0B7188BD2,0x2E98F6BC,0x0C6EB60AC,0x4E67B070, - 0x7B69CD2A,0x2FEBBF49,0x0FA5911B8,0x0E2A17955,0x5F8ABBA5, - 0x0AA46CAC6,0x374A30A5,0x805DB171,0x5EF2B4F,0x91ADC14F, - 0x0BE52389E,0x0BBC0A1FE,0x4D4F3974,0x14658D40,0x1047E212, - 0x642ED37B,0x599E3CA2,0x0A5F35738,0x0EE3D25AE,0x8A4D10A5, - 0x8910CEA6,0x0F51C8813,0x58893C5D,0x7F026078,0x7E1BC88C, - 0x0F4E5C9EE,0x90C19F4E,0x0D4710C32,0x197542A3,0x0D4940325, - 0x17B907ED,0x5B009E4F,0x7C119676,0x5AD5F57,0x0AE866DE7, - 0x2354DE8C,0x7255DD2,0x39F44660,0x567E0A2A,0x7F51D6E8, - 0x5C266FC6,0x6070615D,0x4F3558E2,0x0FE1DCE9D,0x5BC9E69D, - 0x0AC6598AB,0x1C810F7C,0x731C4F2B,0x25021BE6,0x8E5916E7, - 0x7C7628A5,0x0EEF5234C,0x1B08A76B,0x0B60F43ED,0x7169DC4B, - 0x0C08A5300,0x0DF4E623C,0x168DC7DC,0x3CF0A59A,0x7A032781, - 0x518B66A5,0x0DE198D10,0x5DDF3BFF,0x0EDC3284F,0x92B20C32, - 0x8037BC26,0x974C9628,0x2A702024,0x4F9ECB1,0x0ADACBFFB, - 0x0E98BF100,0x82EE1700,0x47D5E02E,0x557D3DAC,0x9531C5B6, - 0x8663571E,0x3DFB01F8,0x0AAEF2096,0x1C14C9B7,0x73468FB, - 0x660A79A,0x1C879256,0x3F48F8AE,0x17051455,0x3396CE2, - 0x5D0BFAC9,0x0FF238A8A,0x5BC6328,0x0D5FA29DD,0x5D7E020C, - 0x9C39F877,0x647D9FB2,0x5E5AF7D8,0x4E27937C,0x985FFBE2, - 0x4AF506F,0x0BE4C2E5F,0x0A18AD6B6,0x0B4AB8D79,0x0F5F43F1D, - 0x56076840,0x66C3597,0x0F171E628,0x8A3476B9,0x0C8FE7E88, - 0x6ED2573C,0x90467E1C,0x53923D7F,0x0F4E78883,0x0C022602, - 0x120011C2,0x21741EEC,0x0FBB7E0C0,0x4F7FCA86,0x37B395C8, - 0x57EE1BE,0x3FA31F0A,0x0E810AEA6,0x1B5441A,0x509690F2, - 0x601F1E6F,0x0C9B87A7D,0x0B19A98E5,0x93E173C4,0x40E2F53C, - 0x23BE1769,0x0C8384996,0x0A0C314B1,0x0FEDFFEFD,0x66A6AE07, - 0x7A250DB,0x86E23B77,0x0FD4DD180,0x4436A734,0x6F30E7A0, - 0x9723F213,0x0DE9F49D2,0x0AD71AD0D,0x40748512,0x65AA81C1, - 0x808B7D40,0x0D39DA8F0,0x0FC45E59F,0x0BFDD71FF,0x606C656, - 0x2640C078,0x64B8FFF3,0x0B8608C89,0x0D145BFE3,0x581E6083, - 0x79200CFB,0x0A01ADA5C,0x80BD3FF2,0x5A3B2F2E,0x7C1585E4, - 0x82DA5B7,0x0F62360D1,0x5CDE18D7,0x0ED69241B,0x0C0017514, - 0x546C7A0C,0x0D08C4219,0x8F33E14E,0x0DB391432,0x0F9CC2871, - 0x670817D2,0x61C7F569,0x0A9BB8A0E,0x88BA410E,0x10584120, - 0x0A5BBD99A,0x0BCAB21E4,0x0E1E9DE2D,0x0FFC2A75E,0x0DCE3464C, - 0x0E36F6132,0x264F5A5E,0x0A3CA732A,0x0C655362E,0x30AC14B4, - 0x0B7214C6C,0x0AE340E62,0x6665E02C,0x0F4464268,0x35D48D66, - 0x10072121,0x0FBA8BF74,0x0C163348A,0x821D3897,0x0FB8895C5, - 0x7F48C72,0x66687498,0x0BEF1A48C,0x0DF3A93EC,0x4B5D3ED2, - 0x0F6F9CA4E,0x4A856B14,0x6EE38471,0x0C8381084,0x0C1FC40AA, - 0x0C84D653A,0x99891173,0x0BF1B79B2,0x57951EE8,0x1800AD4C, - 0x906F234D,0x0B0DB34CB,0x8B2AEE86,0x5B919AD7,0x0C51CE39E, - 0x5E8B3A7B,0x6D607841,0x0F336C5A7,0x0E854B941,0x0C882C2AF, - 0x4E1CC615,0x7F6409CB,0x0EB1C5055,0x30554795,0x0BF82203F, - 0x0E3D07D8E,0x0FFBA9035,0x17D78099,0x91F70F3D,0x3D6F7B7D, - 0x94B1A180,0x3D206868,0x0D6225DCB,0x0F0769B67,0x5BC8EE11, - 0x0A58238EF,0x0DDE613E7,0x9C5AB757,0x47021F07,0x8E94675C, - 0x386879CE,0x23CFE89B,0x86A61CBD,0x7A2BB01A,0x0B90F18FC, - 0x0A5CC87C0,0x8C380FD2,0x2A5A0BD9,0x6F7DBA2E,0x83842C93, - 0x87D6222,0x9F79B183,0x0AD9A6762,0x5F6DB120,0x0EB7ABCC9, - 0x191A1B47,0x38969D5,0x183C2FB6,0x67750726,0x1B140291, - 0x41B04803,0x0D2E6FEE0,0x0EDF16DD5,0x647B600E,0x7AB3CDA9, - 0x0EBA0B86B,0x2DB555B2,0x0F6A56DAB,0x0FE7902C5,0x6DF3666, - 0x19C569DC,0x1226A296,0x5E243094,0x358911C,0x0E16692AF, - 0x38D4B83B,0x6B1CDF92,0x4FF211B,0x0F71DF9C7,0x2BC3A847, - 0x3604D87D,0x690B8030,0x0CAF0703,0x0EA48ACA8,0x11C12551, - 0x0D3EF8667,0x1021657F,0x0B8F93C8A,0x8B7A0E4B,0x23614E0F, - 0x35B9FC98,0x14AA115A,0x76921DEA,0x7B572FB3,0x0EBFBF5EB, - 0x0BF7024C5,0x0E4AE1AE8,0x3B04C321,0x0E4ABB954,0x0BCA1AFB9, - 0x24B40F44,0x5DDE265,0x11D0F1F2,0x4BD12962,0x0C9C9443B, - 0x0B899A6CD,0x0A2AE8521,0x0ECD64D2D,0x0A3524349,0x782C68E7, - 0x8CBA07E,0x61C413C7,0x0C2F3D42C,0x0A3CBC17E,0x0F5EAAAE6, - 0x0ABF0B51E,0x799200E0,0x0DCEA899F,0x5A114B76,0x0BF0AA5E, - 0x585311A3,0x33FDA99,0x68866E8B,0x298ADF4,0x309C90F1, - 0x39C00CF7,0x8ECD3AC1,0x50FEB68D,0x12124588,0x0E0A0BA87, - 0x80AB1AF7,0x0F776FE17,0x50993965,0x9855BB55,0x2D25B549, - 0x3995FEBE,0x7957B6C3,0x439429B0,0x0C780F514,0x953170EF, - 0x5FB14422,0x525C23,0x0BE4104F5,0x0CC5E4B58,0x134BAC3D, - 0x33C3EE7C,0x0C42E49C9,0x0E172CAE5,0x0E70BF911,0x7A5EB8C8, - 0x0C94A6EAD,0x130165C3,0x6B1671DC,0x0B8D7D354,0x0FFDC5CFE, - 0x0E5E0D65F,0x6FD09F1A,0x0D2297AC,0x0D7683C59,0x16251466, - 0x6DF4C89,0x0DA759E9E,0x1B3789B,0x0A8245AC6,0x80277F26, - 0x0C145C137,0x6FC2B7E2,0x0DC7220AB,0x6ECE842D,0x0A24718C3, - 0x51DBE389,0x32E51F83,0x0A139E21B,0x9E70FDD1,0x1981242E, - 0x6D9250F9,0x2A0D62AE,0x17F5092C,0x777BE5AE,0x8CCCEDFC, - 0x5A2E0EE3,0x0AD4B14E2,0x5DCCCE26,0x0D12A6DB9,0x0C2C12EF6, - 0x41273940,0x0FCBBC8F3,0x0BD818B9B,0x332D4C64,0x0F57DCFD2, - 0x0C4CCFCB2,0x10E53F51,0x0BE1530EB,0x29846F66,0x67C4D240, - 0x0CDABC3C7,0x0B55EE388,0x7EAFF409,0x0D5A9F5BB,0x33688E2A, - 0x0A72FAF77,0x0D6B47508,0x40BE4D7E,0x0C5F25BE7,0x67EA1D35, - 0x51884BF0,0x198A0227,0x425E22AC,0x537F581,0x5060118D, - 0x10D17F93,0x0AC001C65,0x0D1F94055,0x75B19EED,0x16976BE0, - 0x436DC33F,0x5E5648F0,0x0A0300C5D,0x5D23B169,0x8A7ACEA8, - 0x7CB295CF,0x0F2D1B369,0x56FA78CC,0x403D384C,0x3CB3F1AE, - 0x0CDCB2DE0,0x0B2DF2AE7,0x670B3918,0x0EF3E648B,0x0D19153CD, - 0x61D871D5,0x40774A39,0x267837A2,0x0DFDA3E7E,0x942B34F4, - 0x4C59241D,0x0B2C5F571,0x1999467F,0x0BD5C9DE2,0x4CC3C170, - 0x0A5CA64B4,0x0DF04059F,0x8D2F157A,0x400C591F,0x4E6E8F69, - 0x0D29054E9,0x0F4AB45DA,0x6BC86557,0x40D3BFCC,0x0D4F24CAB, - 0x24151660,0x4CCD9E86,0x4A617B5B,0x51F4571,0x8EF0B1A7, - 0x0A52FFD58,0x7FBB8FD2,0x0C64BD90A,0x0E2027F8E,0x7744BCBA, - 0x2EC7022F,0x0B9EDE081,0x11512930,0x29F53DA,0x0EAAA1DAE, - 0x0BEB87424,0x4D2098EB,0x0C9187B23,0x83C86ACD,0x0F6A3EE80, - 0x7F6F55D,0x8BC12D45,0x0AC7B149,0x0C2E1E761,0x0EF97A861, - 0x4AF1A22A,0x0D08BFB1D,0x0C4E837D6,0x0F7085C16,0x473D5400, - 0x663A9289,0x0DD6DF92A,0x508FF9D7,0x379FB35,0x9D39FF08, - 0x2C6583EA,0x6AAFA743,0x3FBA9075,0x862C0A57,0x140571E5, - 0x0F62FD136,0x0FB554CAE,0x73F9BC74,0x35C19A26,0x0E7121FCC, - 0x79E0A80B,0x0F3C55F9C,0x715018FC,0x6B9F7964,0x3A305EFB, - 0x0D8F47B4B,0x0E8A544F1,0x0F65A0999,0x0FF59662A,0x342CDA3E, - 0x0FBF7B6D5,0x3708394A,0x0C9B0F986,0x57518473,0x4BB948B3, - 0x1FAEB093,0x0D9CA903A,0x0D18AC327,0x0BAA113DA,0x0E09258D0, - 0x0AF7DE4B5,0x75391FD6,0x69A46FD5,0x0EB375BA0,0x0DDEEFA3, - 0x5306623D,0x0B7F7F671,0x0F06420DF,0x0F440E9F2,0x0BCD4945A, - 0x470F81BD,0x0E11D51A9,0x0A53B4BCE,0x41C9FE6A,0x0F9A02804, - 0x0EFA7D75D,0x0A1A1CEA4,0x0B3492AE9,0x0EFA146D4,0x8A87DB97, - 0x0A8896C21,0x23FAE194,0x884572FA,0x6382C634,0x0BD475C32, - 0x0E2C12B6A,0x68038582,0x6C9D4150,0x1F711905,0x82C251A5, - 0x6D8E9ABB,0x0D61E354A,0x50DB5B06,0x0D263DDC4,0x0BADC0830, - 0x1189CBBE,0x119A1CE3,0x0E4499784,0x0AF2268AF,0x0CFA26C89, - 0x63049387,0x0A5889E1,0x0EED59544,0x170C1C8,0x86AE3B21, - 0x0D4B6FB19,0x56AAA63E,0x0D737B2D7,0x0FC6BCC1D,0x12C776A8, - 0x0A96F528,0x0C27D6A55,0x87523F29,0x0D731C44C,0x6BCD1AD0, - 0x7505511E,0x26B8CD30,0x73D9EE01,0x19C6F042,0x0DED50F4F, - 0x1A30EF61,0x77E43C05,0x0F5348DCD,0x31338F45,0x0E6925F28, - 0x0B4B637D4,0x200D4DFC,0x0DDA3F89D,0x4AF01533,0x3BF5A92C, - 0x0FC87C89D,0x93EAB534,0x46A14A6E,0x5D859A09,0x2915D6BD, - 0x450D6D27,0x1C3A7706,0x0AB8C54A9,0x896D90A8,0x24510AD3, - 0x4D8E5668,0x0F76F5F89,0x3B8351EC,0x0A03BB6D5,0x9AB4DF41, - 0x50D28564,0x0A28EB056,0x6B91D80A,0x3014A7F,0x99BCE3A, - 0x5F0287F3,0x75561A8F,0x0CB09134E,0x0B1EE8446,0x5293EE10, - 0x0F0D165C1,0x71A1F01B,0x1B312F05,0x9C384039,0x4D86E23D, - 0x0B7DFDB94,0x57099835,0x9E24143C,0x3C3AFBE0,0x9E170EA5, - 0x0B55BC9D2,0x0FACD4326,0x0AFF257C7,0x67DF017B,0x0C84B0A1A, - 0x90E8E844,0x0D6F4E04F,0x930A6D83,0x603FE58A,0x816A5A22, - 0x23C3BE15,0x0E2B04B6B,0x8EDB22DE,0x2F88338E,0x46265CF6, - 0x5623D51F,0x0A305CB13,0x3AB74B95,0x3120620F,0x30FA83CC, - 0x31E22867,0x83ABBC84,0x15F8B9BD,0x0F10A0EE0,0x7D6C357, - 0x2C5BDFE7,0x62328A9E,0x5A676F06,0x3787649F,0x95FA4D8C, - 0x0CA933D8D,0x6B66DF2D,0x13DA153D,0x5FFFDE80,0x3D217DA8, - 0x679DD881,0x2AF31E6D,0x6C1DAC10,0x0ED1F324C,0x0CDE01170, - 0x4F3808AC,0x0DC4A10C9,0x4B148416,0x5F4485A6,0x914D9DB8, - 0x10BBA277,0x7C3DEE4,0x1E1F6C10,0x4319E58E,0x0AAE53D28, - 0x1233E7D1,0x4B0540DB,0x0F5BE2A6A,0x8A7CF729,0x9FA88A3B, - 0x66CCB875,0x78A4F4CA,0x0D1772C06,0x1CA7EEC0,0x3288CF89, - 0x0DD6E0D6A,0x0E10A738E,0x3DF67D3B,0x0AE8EBD07,0x75027D48, - 0x5AA9A6CC,0x0F198E1CA,0x1C74FB19,0x0D1848EA0,0x1D0ADE0E, - 0x69D401CB,0x0FD0E432E,0x0C25AC8F0,0x4C2373E0,0x172D07D9, - 0x11718CF1,0x5929F5F4,0x4727FF11,0x0AC6A5CD2,0x5BF31152, - 0x0E8D51DAA,0x0AF8C5BAC,0x188FA9D4,0x1A294A7B,0x0FE84894E, - 0x66079FFF,0x8DE1D73A,0x0D0E6F0DB,0x6E9BC35E,0x8C8C2696, - 0x7CE60FA2,0x3E41FD1E,0x47BE9396,0x82528640,0x9561BAEA, - 0x658FA831,0x0DCD303F4,0x0EACD9B08,0x0C959812D,0x86646C41, - 0x0BDFE5BB4,0x0A4B17C3C,0x4A114DCA,0x219501BC,0x0BBA52554, - 0x0D1F48369,0x8910475C,0x0F838604E,0x0E66D2990,0x0D2CB495B, - 0x361AD8C2,0x0DA1C3E4,0x913A7166,0x49ACA621,0x4334A817, - 0x9F65A1AC,0x4D334513,0x164AB406,0x0E1A4A2BA,0x2F5AB512, - 0x0E9BA2E13,0x5B9BCC98,0x80EDED46,0x8094F7C3,0x7777F623, - 0x78D387A3,0x0D2D6F49A,0x9169A0AC,0x484DA641,0x0E69BD35, - 0x0C7625FD2,0x0A56D2AFB,0x0EE6186A9,0x0FF11889C,0x91D8164A, - 0x3B754C1C,0x38191FD9,0x6BBF4062,0x0A0BC43A1,0x159701BC, - 0x391A3B8E,0x0B3A98057,0x0A6D350B2,0x332781C8,0x4049E2C4, - 0x78451F87,0x9322E49C,0x0D8BB456E,0x0E0CA5EB8,0x9C46363E, - 0x9AEFEABB,0x8327071A,0x0E90337E8,0x3FA2200A,0x29BD89AB, - 0x0F780BE79,0x6B983611,0x0C38E74B7,0x0F3532B4B,0x331CA578, - 0x0B96F652F,0x0C87E0C54,0x0E9B579B7,0x798F3445,0x63AD0D80, - 0x2F29002C,0x3C285C4B,0x49AE254C,0x3AB7B680,0x1983AACD, - 0x5C31FDA6,0x668F6F3A,0x503129EC,0x0E8C0A304,0x0FA95C5A4, - 0x0CF864DFD,0x0F40070C2,0x3C57C4DD,0x8595D62,0x0C62936C1, - 0x0B84BD33F,0x0F7FB25A7,0x0B7C3AE3C,0x0CC4CE6F3,0x6E75DCDF, - 0x39A220ED,0x7756E1D1,0x0A2055340,0x25235360,0x63814E7D, - 0x0FAD95FFD,0x49A8B796,0x303B42BE,0x160D8863,0x3150D1DD, - 0x1CA8C21,0x1EE2F137,0x34FBE6EE,0x4C001FCE,0x4D408A4E, - 0x0C27DEA47,0x0DD3FC1A9,0x0BC6E746D,0x0EC20AACA,0x2CB0F5AC, - 0x7310B462,0x34603896,0x0E0BF2583,0x0AD611B62,0x96E19625, - 0x0A2D91368,0x6AB175A5,0x0D5B4A6A7,0x27698141,0x3A20F03F, - 0x0ACB519D,0x780F1FF7,0x479BCE41,0x6BB9F6B8,0x8322B418, - 0x0A4174E10,0x58AD15F3,0x0E66990B0,0x0D40CD604,0x0ABB03CEE, - 0x0FA143064,0x9D356544,0x3F1E318D,0x1E0033CF,0x0E8538E0, - 0x0C1625FD1,0x452C7C20,0x0CE6CBB2F,0x0B6F586F5,0x0C275A8F4, - 0x0A74BB26B,0x0CD989DCC,0x5299B270,0x5234A78A,0x66D00B5A, - 0x6A6AE4A3,0x84E5965E,0x61A206B0,0x0C251001A,0x3807D6F0, - 0x2B904A0C,0x2106AEC3,0x3DA24A18,0x6D3FE30,0x6B8D2906, - 0x3E4C960,0x99D9E302,0x0E7742521,0x0A213CA1A,0x0B701BE64, - 0x0D54A02C3,0x2BCE53BF,0x73950655,0x2F6237EC,0x328B228B, - 0x6307D148,0x0BEC9F804,0x9B4C1D55,0x3370FBC4,0x60842939, - 0x0A4A4F7B3,0x6D45993C,0x970E871D,0x33EA234E,0x875B9C30, - 0x5511137E,0x61BBFD81,0x2D1DC984,0x762C288,0x45B43639, - 0x0D00BD820,0x0DF426319,0x5708008,0x6E75EAC8,0x66D3D064, - 0x1AC07B8A,0x0A379303C,0x40D858C9,0x0E329DEFC,0x0F03AD993, - 0x41B16BF2,0x6DA2E819,0x4A613BD4,0x0B0958631,0x808E0937, - 0x0E5D945D5,0x0DA116119,0x0EDF7CCA3,0x42C52458,0x0DAC0575B, - 0x150D0839,0x76C53463,0x0A74C15E2,0x0BDDE4646,0x0BC6A29DF, - 0x5EA48630,0x105674A1,0x3EF67D74,0x0D07EFDFA,0x0F578CB07, - 0x1F581BA3,0x4F0FA302,0x92DDFDB7,0x0CB674D24,0x0B4092335, - 0x206DA34E,0x835DE381,0x0B3D59405,0x0F05DE5E3,0x2395A4F3, - 0x6312A607,0x0BD686A66,0x3588F97C,0x84D10CF,0x34518135, - 0x3A05D745,0x2301390B,0x0C1989100,0x37B0ED38,0x0BCD025DE, - 0x9B7BBEDE,0x7EBD0EE1,0x0ED03A17E,0x1230DCAE,0x0BFECE081, - 0x0B23FB110,0x176098B3,0x4EC7C574,0x0EF8939C3,0x0BE5E36B, - 0x0B51A09C4,0x0C17CEA2A,0x0CCC7A2AF,0x7DB34D0D,0x9C96FDF, - 0x0FD749410,0x385B3393,0x36EED854,0x953F826F,0x0D1144AA1, - 0x533A46FB,0x0AA1CADDE,0x18943C23,0x5000D89A,0x7E9974B6, - 0x88003586,0x931AD4E7,0x0CA1E45F9,0x5AEC96CF,0x0C1A1196B, - 0x4968C5E9,0x0CF93DAFA,0x0C9EAC494,0x884242E8,0x0BA52C795, - 0x32C3211B,0x0EC865892,0x4B6AD99C,0x0A6EED398,0x353E218, - 0x22F6EB95,0x0BEDD4762,0x0F9023DF,0x932A26EF,0x0EAF55AC, - 0x0D0A03459,0x36CD2E97,0x736B37DC,0x9066B022,0x0B2F98BDC, - 0x9C7BAF2E,0x747C9E5D,0x0CA105585,0x0D66B748A,0x1AE9E50, - 0x0A801232F,0x1CE2DCA1,0x0EDBC573E,0x68BC34EB,0x5EE0CF4E, - 0x27512085,0x0E7F2DF17,0x1039EB2A,0x283EECF7,0x0CD11377C, - 0x0F651F370,0x7BFA7A7C,0x0D87F02A8,0x2E197D14,0x8A5EBEE8, - 0x6A15DC8D,0x7D49DB1E,0x0AB9C8919,0x55DEA75B,0x0DEDE494B, - 0x6A808055,0x0E510359A,0x48D658E5,0x17EB3BE1,0x2E4B388A, - 0x0BE2A9AE2,0x938CBBE5,0x981069BE,0x9C0C8E3B,0x56DF107F, - 0x0A783F7F7,0x2062CE8F,0x0C46B4B25,0x0F64323D,0x378276F7, - 0x0B137A13F,0x0F74B7744,0x892ED62B,0x318DE104,0x8C235EFD, - 0x0C6D25BD5,0x0A5F21894,0x0C9E9217A,0x32FBBB35,0x2648157, - 0x84A44F06,0x6E1B5FF5,0x63D5B294,0x0BCA7B284,0x887B154E, - 0x0D1E80454,0x22067D08,0x4580F65B,0x51EA4379,0x0E555B9B3, - 0x0AE2194BC,0x2F139619,0x0C1A7F1D3,0x0D8A8676F,0x89FDB01F, - 0x49C61C3A,0x0F8A879EA,0x1E643725,0x74AFCADE,0x0A63E507C, - 0x5720748B,0x655092B1,0x6F8B1CE4,0x955F3CDB,0x7F85BAC2, - 0x0A1702132,0x0BD261D60,0x0A94F2895,0x528B65DE,0x109CC04, - 0x0DD5688BE,0x0B2729D26,0x0F029CE6A,0x0F7A0BEC4,0x912F55AC, - 0x0C06E654C,0x0BB938E34,0x33FB5F4F,0x0DA06BD15,0x26288903, - 0x523D7D48,0x0A71D57C2,0x0F9713A28,0x74C55189,0x99DEB5F5, - 0x834D917A,0x6F448452,0x7BA9465A,0x0AE698FC6,0x390F3413, - 0x0FC95933E,0x4C793234,0x0F414A389,0x7928AB6C,0x0A3B8A3DB, - 0x381C1D13,0x0B54CB4B,0x359D9DA1,0x0A3422A55,0x0D1B55135, - 0x0D4DE2058,0x9EB3F40F,0x7E09E219,0x0E6A95616,0x71A7FA3E, - 0x24EFDA53,0x0F521C5D4,0x899FF674,0x42E4F4CB,0x7917B64A, - 0x8DF0B74,0x0C7A394B,0x0E909E409,0x8E2E3211,0x0FAD92D25, - 0x0FE5F69D9,0x45CDE648,0x937B3705,0x4AE4E455,0x32B40E9B, - 0x79235113,0x0F982EFC3,0x0BA132AAF,0x0B81EF14D,0x0E641BF38, - 0x7208C128,0x4BBE3722,0x0E1821CEC,0x2C9D09C4,0x0EF125751, - 0x3E7784DA,0x3E04D7B6,0x2CEA4704,0x0A0E59A9C,0x1315CA45, - 0x9F0AAC28,0x71ED384,0x0F707B3A4,0x8DAC020E,0x173864FE, - 0x1F6D4612,0x0A53C0A47,0x0AB926524,0x0F7740635,0x144E79BB, - 0x9A884AA2,0x0AF5B6DB3,0x0CEE3DD0B,0x0C77584CC,0x7325B12, - 0x1ADCD229,0x6EE972FD,0x5AD6C1D1,0x5EBE6634,0x0AD2B8D31, - 0x0E82C8DC7,0x2DA8C899,0x50F1D3E5,0x689CD8BA,0x8E913866, - 0x0E15E742E,0x0CED14D43,0x8EC52AF1,0x0EF3CBB18,0x58AEDCE0, - 0x7A1BCA9,0x9E7A3E41,0x0DE939F5A,0x0B28D5A3B,0x6FE848B5, - 0x5AD00C59,0x6B3AAEE8,0x5030860B,0x0B5695C44,0x0C31DCD25, - 0x0E617F0C0,0x0D40C3A5E,0x0CB2B9F74,0x19F5FAD2,0x0E24FAF1E, - 0x1ED68F81,0x0E172FCA0,0x0DF2E4DCE,0x2F47747F,0x4F82DD00, - 0x69C39A66,0x0D4DCBEC5,0x0DEA306A2,0x0C947BFAA,0x13E4E3A4, - 0x0FB5486A4,0x40497081,0x2C980C8A,0x0D1D88175,0x932C1E98, - 0x0E65DFB5C,0x592CDDEE,0x0D4E65B37,0x1D383F0F,0x0A1452FAD, - 0x72F68D62,0x8C919B88,0x5C8EE3B5,0x83A6D634,0x0D72CB3B5, - 0x0AAA0AA43,0x50824277,0x0DB64F8EB,0x294328F2,0x21173186, - 0x39A9D582,0x3BA5DE12,0x4AF00767,0x203B19AF,0x99D95544, - 0x75CD1223,0x5928A7A1,0x18928B59,0x3126BB69,0x99835CDE, - 0x0BA1FA26C,0x0BBDFF063,0x2E541DE,0x0F7AAC63D,0x0B4CD0D6, - 0x0FA29F1E8,0x4CAC5ED0,0x22679880,0x2F624C2C,0x5B37746, - 0x924FCDAD,0x0EA205C22,0x47586DFB,0x4D04AB1B,0x93E48721, - 0x607ADAE0,0x0B261CC10,0x85E0F642,0x51BFC31A,0x0D5591CB8, - 0x13F34477,0x9C4C00DA,0x0D75FCC3,0x0DAE36AE6,0x4AC3EC7E, - 0x0C38DB43E,0x48DCE98B,0x407D4DE8,0x79C61EB2,0x6C293A0D, - 0x0C309861E,0x18CB8F7B,0x3172DF,0x48E3FA23,0x7E4F0969, - 0x0B3B3399B,0x8078C214,0x47C29F9C,0x0BB45EC9A,0x0A35A9385, - 0x0DB52279C,0x9B0A10D7,0x0FBBFE91D,0x0B72426B7,0x30B2FA05, - 0x0B440786F,0x0FFD3F89F,0x2B7BCED,0x0E3CFD31B,0x44293E43, - 0x0C8D5520D,0x0D3F85D25,0x921C8CED,0x3CCA0C6F,0x975B7095, - 0x0BD0B539C,0x204F3EC6,0x0CC69CC4F,0x0EC390BA3,0x905626CE, - 0x0AD5D4134,0x6589A582,0x89841DE4,0x5D7D9F79,0x9B7B2F04, - 0x0BAF101E4,0x6F92DE46,0x7566C899,0x8A1EE142,0x0BAA58991, - 0x0DFF7C7F4,0x6936EA6B,0x5BFB703C,0x96EA26E8,0x5A89915D, - 0x0A528D6D,0x2F06347F,0x0C0450185,0x0A15C352E,0x695E7A5C, - 0x6876C7D8,0x0E97B8345,0x0B4C5ED52,0x0D73FBB34,0x0A6BE0154, - 0x1915544,0x0D55A31F8,0x0E51C9933,0x0CB94FD3F,0x39CD60E1, - 0x85EFBA8C,0x65579BD5,0x0F7ED1227,0x4B2CDB8,0x859981BB, - 0x66988DD8,0x8BFEDAD9,0x110705A6,0x0D6AEC073,0x3BC27538, - 0x283C2D61,0x51D0B1C7,0x0B8C2EEE0,0x73FB9E32,0x0B05C250E, - 0x0F652B97A,0x0AEABC66F,0x0E1A89145,0x43531B6B,0x7112485B, - 0x777D40CD,0x956D162B,0x4355A846,0x72D6C647,0x158D96E8, - 0x0E03036E4,0x4FD9A4AB,0x0EBA1DB5B,0x0C9713FEC,0x53153BAA, - 0x4A9229E9,0x0CBA72F4,0x13FDF646,0x0BF82AEFD,0x55778F8B, - 0x47A5B2AF,0x0B647B3A4,0x351C5798,0x0D0BB715F,0x4D270669, - 0x0B1A3AFF1,0x6C73F78,0x5CD4A672,0x0E45153F,0x46A6635C, - 0x0C3A9B0DB,0x0DA774810,0x0BB44C98E,0x0F6268952,0x3E27323D, - 0x6C99AFC8,0x0C7A94CF3,0x8237187E,0x86E58E5C,0x726E7565, - 0x0E03A054B,0x0EB2F4BCF,0x0EEC9CF34,0x8D6D73F4,0x0FAFA9EB3, - 0x71A29A71,0x5F83B03,0x9F49C2C4,0x44300088,0x9665BFD1, - 0x9ED65D46,0x0C8F9BA60,0x2F605567,0x1B8EB19D,0x0C809FEB9, - 0x6AB0F596,0x6D4F042D,0x171ABC1,0x0D6752659,0x24E44C73, - 0x0EF02B7F7,0x89A3256A,0x58401E64,0x0D94AD744,0x0E5BE5722, - 0x34FAD805,0x1FCF7056,0x0AAD7F095,0x0C1090D4B,0x0C28ABD40, - 0x3CC6E4ED,0x0F7C03034,0x34A6414F,0x35A90E07,0x0C8426, - 0x617A702E,0x2E9C9E4B,0x0CEEB4287,0x0FCC3983D,0x0C9B9C8D0, - 0x0E02F0C9C,0x0E26142D,0x253AAAF,0x517492A6,0x0BDE4B4E0, - 0x0B66D7DA7,0x215E823B,0x59DE667F,0x7380FEF2,0x0C718B4E1, - 0x0ABCC29DB,0x826E1F66,0x0F60995F0,0x81B93308,0x32C0E9CE, - 0x0AED7D4A8,0x75C26137,0x6627B48A,0x86A04B91,0x0FD0FDED4, - 0x61328A64,0x37772F12,0x0B71117E0,0x0D04BD8B5,0x6C1C7B55, - 0x0F5FCDD8F,0x18F756B9,0x0C9009959,0x8787DB25,0x0E14E382E, - 0x39785258,0x0C8E33B0D,0x0E2B79532,0x7B3FF75A,0x0EBF8933A, - 0x0EEE8165E,0x0EF31D01A,0x86E615C2,0x3F1DE31D,0x9D46C418, - 0x5EBBF6B8,0x198CA52,0x86CC4AFE,0x75701E49,0x2158B12A, - 0x2EE88F38,0x51291219,0x571C3D3E,0x694FE8CD,0x8EAD1DDF, - 0x719AC3EC,0x65407983,0x0A623C53F,0x0E1FC6EF6,0x0F7C42633, - 0x0FF0F6CE7,0x8A9BB15B,0x2A29BA69,0x358B45EC,0x0C6FFEF75, - 0x5BB5540,0x0A8C97A66,0x0BA156953,0x9BC51B7B,0x49C89A49, - 0x0DDB26758,0x59C719E6,0x0A0554886,0x0C648A914,0x8AF87AEE, - 0x21452161,0x36E61062,0x2EFEEB7F,0x0B0F0ED15,0x657588C2, - 0x0FCEC4B1D,0x72F109A5,0x903038F8,0x0B57B9746,0x0D51B1404, - 0x0C264ECE5,0x0AA8D1406,0x0E1BED868,0x0E169C2A4,0x90DEBDDA, - 0x0C11A7AEB,0x0FCE013E8,0x820CEECA,0x8C23E563,0x0D42EA394, - 0x56C951C1,0x58777382,0x0A8380C9B,0x255E092F,0x809CDC30, - 0x4460681A,0x14621DE1,0x347D6427,0x4CBF3DB3,0x68BC261F, - 0x422740D0,0x0C4A3AD2C,0x0C9D63C06,0x24BF485D,0x0E34ADD47, - 0x0D5221D28,0x49C7E227,0x19E0A5E3,0x0E7D29F61,0x0A7912D4A, - 0x5DB77953,0x28D357FC,0x80036D7D,0x0BCC597FD,0x0D70A8A06, - 0x738CB736,0x1E627237,0x0D5D153F1,0x0C666DCFD,0x5A415D5D, - 0x73B4156B,0x0F30D9A10,0x7DAF7B36,0x7F682380,0x70FE0038, - 0x560BE589,0x8C0BADEE,0x0C2B422EA,0x45861DFA,0x81A2EEC8, - 0x0C4DFFDA1,0x441BB229,0x64CF934D,0x33E6AC7A,0x35D0340C, - 0x67D26D0A,0x7DA0CC10,0x6E2D5A8C,0x32C25A2D,0x0CA4E2C99, - 0x82FD715F,0x730B702C,0x4BDBB941,0x51430724,0x0A32A6B96, - 0x0C256A7C6,0x517FD8C4,0x1AA85938,0x52AFE354,0x1E22F907, - 0x56548374,0x88B0B9A2,0x404E4275,0x86C49DDD,0x0A93FC14D, - 0x3BD2006F,0x5D0D3116,0x3DD20E74,0x0DC64DB8D,0x15C149EB, - 0x0DB329993,0x0C2200439,0x0C0295BB0,0x3573EBA4,0x2A40A38B, - 0x0D6C379D9,0x67330973,0x0FF1D7F67,0x0FCFEB8DA,0x7C11A442, - 0x2066EFD5,0x1134E040,0x4170819D,0x0F49E009F,0x7EE85510, - 0x4E6D257E,0x2BDBE631,0x0BE404560,0x511DC4A4,0x0D6BDA8AC, - 0x2BC41233,0x9C0B6C2F,0x0AAAB064B,0x0A580198,0x0F1F16D7F, - 0x8F54AEFB,0x0D9772405,0x8CB50B4F,0x6F659F34,0x0D8B184EF, - 0x71A6660C,0x3C87DD1D,0x0D56793AE,0x0F8F6A87B,0x429C55E0, - 0x3CC4D090,0x957B708A,0x0AF391249,0x5EFEBB3B,0x0ECA17F75, - 0x6065A1A5,0x0FFCEFB48,0x14B3A01D,0x0ED93C1D9,0x262DCD1C, - 0x2A4ADCA4,0x0F6DE4EC1,0x204FAF08,0x1815DE4C,0x0AF836FCA, - 0x0D5E44DA4,0x0A7CAA491,0x0A9A3FED2,0x4F8DAC68,0x0C36C6784, - 0x0E239373F,0x879D948B,0x0DBECB69,0x0F59A45D,0x7211421F, - 0x0A6064A94,0x28AA48FC,0x4CD04E6D,0x3906DE80,0x3525094A, - 0x2326D98E,0x4937ED30,0x570E63ED,0x0A57EFB4A,0x0BD4878CA, - 0x19334A64,0x2E5F6B34,0x0A9D68771,0x0F8645F9F,0x0CA96F06, - 0x5D6CCE62,0x2F3257DC,0x140F0639,0x0B3BDA452,0x0C7EBA7C4, - 0x6BD754E8,0x941F2606,0x0DFD573C5,0x8DD14DE6,0x0CB4BA732, - 0x37A9B8B1,0x0A195A51D,0x0E535A96,0x351B897,0x0F629, - 0x4AE34157,0x0EDE6A6E1,0x2F03235,0x2EBB589A,0x6BE492AF, - 0x0B3E4B14,0x0FA6CFD67,0x43AF9772,0x0D5FC21A2,0x8852A2BB, - 0x5B4A42CB,0x0FFF0AC5D,0x9AD1B6EE,0x0C55544A5,0x0D64F693E, - 0x65D3D048,0x9485B90,0x63BD09DD,0x5E811DDD -}; + 0x31594308, 0x0AC350F, 0x0E92308F, 0x1B10E167, 0x470CADE7, + 0x0D461503F, 0x2E2FC437, 0x28746421, 0x89E1510C, 0x0C7E6153B, + 0x121086D6, 0x9494EDDE, 0x0F82C6866, 0x29218D01, 0x5CA95077, + 0x507427BC, 0x0D4826C22, 0x8B3702CD, 0x0ECB13B67, 0x8C59F916, + 0x0A0B814AB, 0x0BD8DFC1D, 0x0E31CA035, 0x0BAC88E8A, 0x1BE45BB0, + 0x0D2C745AD, 0x0A31E17AC, 0x8B874DF6, 0x475B791D, 0x1BCAE57A, + 0x0CC2E7ADA, 0x0EE99E075, 0x66B0E720, 0x27BD26C3, 0x3FFFE20C, + 0x17453165, 0x0F6BB5E24, 0x0C8039002, 0x1E87A7CF, 0x750E6764, + 0x0BB8ED8D8, 0x0F41ECF7, 0x0C9FB63EF, 0x0BABBEC4D, 0x0B5808D28, + 0x4D5E449C, 0x0E1D0EF7B, 0x0D650693E, 0x2425F642, 0x147DE131, + 0x48BB63BD, 0x0FB12C795, 0x8A53CC91, 0x33034B30, 0x1DB11945, + 0x99862FED, 0x0A81E08C4, 0x0BD964B59, 0x0C4E7AADF, 0x62720A25, + 0x7FDCE4C8, 0x21BEBA7, 0x0DBD1EF97, 0x47D90158, 0x4F20D8C8, + 0x92B77357, 0x452600BB, 0x7802FDE5, 0x9BC29D33, 0x40CE6DE7, + 0x23D937D8, 0x67712667, 0x22D42CB5, 0x1C06A113, 0x0D4202DBA, + 0x0C4EBE7BD, 0x0E6ADBE3B, 0x774319D9, 0x0FB70BA6F, 0x8175E802, + 0x28E2CDF3, 0x0E2AB1D75, 0x787EF844, 0x0CF541295, 0x69471148, + 0x2EA33665, 0x6D3F40C6, 0x1E0E8D11, 0x6AF183EA, 0x6DCF2E66, + 0x3AE82AC2, 0x1F66C455, 0x2B355CC3, 0x0EE150E74, 0x80EE9144, + 0x0C5635E7C, 0x0EEA91502, 0x439A1DCC, 0x20058B9A, 0x3E4946E5, + 0x34226812, 0x3EC2E7EC, 0x3C247451, 0x0FE9DA32B, 0x0BEB44DA3, + 0x0EE333391, 0x357EE336, 0x0B424E02D, 0x8DB4FD9F, 0x0A6D20AB7, + 0x0AA89B255, 0x51E3A407, 0x0E2B7F135, 0x0F6C3B59B, 0x7EFAFAFC, + 0x71FD915, 0x3D93E2D1, 0x0AE6CBFBB, 0x0D1C613B8, 0x475EA8F6, + 0x605DCA20, 0x0E171EED4, 0x5229856, 0x0C1647B86, 0x4C68E10F, + 0x0DFB84DE2, 0x0BA835FE3, 0x6735F9E1, 0x424BA0CC, 0x39662522, + 0x0D19E84AB, 0x69180C66, 0x0C3DBC0C3, 0x0C0DFFE12, 0x6B675E3C, + 0x3991DDB1, 0x902C3BA1, 0x85C9A16F, 0x0EA158763, 0x8866D59F, + 0x0A9934854, 0x0DA091835, 0x0EE1BD82C, 0x469A9D4C, 0x50A66208, + 0x4EC3ABA2, 0x593069E6, 0x0A5741E17, 0x639412A, 0x0B35DE432, + 0x4B47941C, 0x1577819C, 0x8C61DF67, 0x1B7C8BA3, 0x2596F29B, + 0x486A2FB8, 0x0E37473AD, 0x0D504AAF1, 0x88925B72, 0x2F51D088, + 0x4B067827, 0x741B895A, 0x56EFE9EC, 0x0FA714F68, 0x47EDA645, + 0x0C826B25A, 0x0AFA4F598, 0x1A4FD4F7, 0x963DF6B1, 0x0E1C9EDAF, + 0x0F5E51840, 0x41B1C711, 0x3A4CA15A, 0x12E94355, 0x0C7262AF4, + 0x609AD3D3, 0x74AD206C, 0x0EBADFE8A, 0x81E4500, 0x0A851E09A, + 0x0C4382D54, 0x3D78A6CA, 0x0D9C0C2F0, 0x88591603, 0x0EDFFC0BF, + 0x19F005D3, 0x9A423992, 0x0B479DFEB, 0x0EE59129B, 0x0D1F924A1, + 0x0EC1984F2, 0x1BB5E56F, 0x9DB9C14, 0x0F4B94A72, 0x0B0FABC5F, + 0x0EF530FEC, 0x0BF581897, 0x549503C2, 0x8DA3964, 0x0A0D688FF, + 0x0D1E77ED2, 0x331154F, 0x54EE96CF, 0x0E004B785, 0x40DD06B0, + 0x50738B15, 0x35AAA9AD, 0x9FE3469B, 0x4CCE2C60, 0x0CE7FAE52, + 0x8DC58E4B, 0x0FB71E9E, 0x778FA64F, 0x4CBC0683, 0x7C329C35, + 0x0A105682B, 0x82366E28, 0x0DDCD5C64, 0x64276D39, 0x5928D1F, + 0x6E17BEDA, 0x0D197BAF2, 0x0E41ADA64, 0x2D633697, 0x7CC80E91, + 0x0B940696B, 0x0DFBEFB02, 0x49BD4CF0, 0x2D1C17BB, 0x662DF04B, + 0x76092AA2, 0x0CB26F8C7, 0x412BD203, 0x0E9021B50, 0x92F000F, + 0x6361A3F9, 0x0BA477958, 0x93A5F077, 0x39A75657, 0x375F6A3, + 0x0D90784E6, 0x0F53BBBFC, 0x0E72544C7, 0x0DCA6DA23, 0x1F40AC1B, + 0x0E028025D, 0x359D24EB, 0x5E797814, 0x4D06EAA3, 0x66129056, + 0x83468E91, 0x3BB33854, 0x64AE776B, 0x0D6DE6EE4, 0x72935DC6, + 0x6359C500, 0x0A4CECDA0, 0x0C2B0E445, 0x0E43AA8D7, 0x8B10675, + 0x8F3AA3AF, 0x0FCEE7BF6, 0x0F930C950, 0x9B3E2651, 0x0E607F446, + 0x943DFDB3, 0x12AA5800, 0x0CCC78D6F, 0x0AA8BF851, 0x0DA81737A, + 0x0D11D2FF2, 0x8C50E3ED, 0x1C5A29FD, 0x61E02487, 0x163E6774, + 0x0D1E1228, 0x0BC4A3EB8, 0x0F9BE9C57, 0x2025812, 0x0C0B644BE, + 0x4D6E322E, 0x0B3C1A1A9, 0x0F79D9D9A, 0x56DDE08A, 0x0CE1E3D4C, + 0x0E0CE3F77, 0x95850D1A, 0x0BF9990AA, 0x81EDD83F, 0x1109BC00, + 0x0BD70C1DC, 0x2C2D3E7C, 0x0E7B0BD75, 0x17D8A3C1, 0x91511470, + 0x0F20119B, 0x0C07CE39A, 0x4E0BD76, 0x705E9DA1, 0x193673E5, + 0x0FA7859B, 0x2705121D, 0x0FE0C357E, 0x3A740D78, 0x13C51BA5, + 0x136DEBF2, 0x1910F752, 0x0A41FC8AF, 0x4EAC5E26, 0x977DD273, + 0x0E45F3AAA, 0x0C8BCCD29, 0x817048CA, 0x0C6D9905D, 0x0C02D9855, + 0x561185C1, 0x0AD67107E, 0x0EF672CAB, 0x4CF1E95E, 0x3F219995, + 0x13253170, 0x0A54BF29D, 0x6B5E4813, 0x0B533F203, 0x337F630B, + 0x0B8EB68AE, 0x3D6B0C01, 0x29CBB9A6, 0x0D08B9FFE, 0x39EC599B, + 0x244BCEF4, 0x4BAE565D, 0x0E99D1F36, 0x7933CE62, 0x0C07469FB, + 0x0DE17443, 0x0C04A5ADE, 0x9E40F3F, 0x0F29BF461, 0x0A0A9FBB7, + 0x0D5680B65, 0x0BA64A6B0, 0x0DCB5C9B3, 0x748C1354, 0x0EB0B2A77, + 0x9D5A5B72, 0x0DEF780C0, 0x3A4D27F9, 0x189F001, 0x4A93780, + 0x99D5F393, 0x0E5F3DEC2, 0x5A76D731, 0x7E76841A, 0x0EE063B7A, + 0x0A3C2230B, 0x75A79673, 0x0DD28CABB, 0x0FF7DB102, 0x0E83F1D73, + 0x14322874, 0x3362D320, 0x2C71EDF8, 0x632F37D5, 0x386BC522, + 0x0D009A747, 0x1755C968, 0x5971850, 0x21E8E6A8, 0x4443906D, + 0x0A0DF5EA1, 0x0BCAA40, 0x517C4575, 0x6275160E, 0x0E804042E, + 0x0C5241741, 0x8A3FD935, 0x3A4403E8, 0x51F955DC, 0x493C632, + 0x0CB84DDD6, 0x1D945FF7, 0x7A332ABA, 0x0AF0D612F, 0x56E0C984, + 0x9C8A7378, 0x47679C13, 0x0F7D9D194, 0x0AB2857AC, 0x888DC9E9, + 0x0D6890375, 0x4C7B3F00, 0x8D727EFB, 0x0F2402A07, 0x8AD0F9AD, + 0x5FB9144F, 0x0FB12795E, 0x2B899DCE, 0x3AF56C7, 0x2296F99E, + 0x389EBF03, 0x0C58C6E7C, 0x23DC3512, 0x0C659D749, 0x0C3EA0C56, + 0x8FAF248D, 0x94CED19, 0x0BB85D7EF, 0x5D0C5605, 0x9B9688BE, + 0x193418A9, 0x0B3E1626C, 0x957D7FB, 0x3B28A30E, 0x0F1098ED1, + 0x9F7120DD, 0x7630967, 0x0FF87C0B7, 0x748069DC, 0x0AF7AFC9F, + 0x0D702A4B5, 0x0B71B6539, 0x0C28E0259, 0x54811E4F, 0x3B4BA193, + 0x76875D4E, 0x3C67F212, 0x414CEEC9, 0x349339EC, 0x8CB1B1F6, + 0x84821117, 0x64DE172C, 0x36EE6EF, 0x8ABDA96B, 0x7A9279B4, + 0x0F17E81D4, 0x29B15F08, 0x4111CE2D, 0x408E8275, 0x57AF545E, + 0x66719FE5, 0x0C252EAF6, 0x36A9C728, 0x4738FAA7, 0x0BC04DE71, + 0x5E6505C6, 0x0FD591FD9, 0x0B31D1DCC, 0x6DFF96DB, 0x0A66E69D8, + 0x7653A4D7, 0x0CCA4A42A, 0x0F7357E90, 0x6CD29EA9, 0x0C38CAEAD, + 0x250BA5E, 0x1EBE913B, 0x0BF376EF7, 0x4438D729, 0x7E7C645, + 0x0E2EC07CB, 0x0F282E1BE, 0x9ACEF858, 0x0CB6F72FC, 0x8356596C, + 0x94D8403C, 0x0A7012A87, 0x802CA7E0, 0x84D0408B, 0x789D15EE, + 0x8BC8C542, 0x97A38E8E, 0x0A470B6D6, 0x0AE77298F, 0x0A8566357, + 0x0C09990E3, 0x0E58AF239, 0x864A841F, 0x9D21DDD3, 0x0ED1356FC, + 0x87B46FE1, 0x933D6FD9, 0x4DDE4B02, 0x4E56C936, 0x0DC2E53B, + 0x0A5B2743A, 0x0D9820773, 0x55E8122E, 0x36C94EF5, 0x0CD515B00, + 0x0A042AAF1, 0x0B28C9AC2, 0x51FE1FB, 0x5CFD2E28, 0x45930D8A, + 0x57490A0D, 0x0B958197A, 0x0E4DB35EE, 0x0A92A488B, 0x75634B6D, + 0x0D449AEDF, 0x3452FACF, 0x0ECFBB580, 0x7C5F867F, 0x160899D8, + 0x5E054589, 0x6F3CEC37, 0x1E022320, 0x82E91351, 0x0B4D91F19, + 0x0D363C8BD, 0x4B51CD6D, 0x57829677, 0x0C5F5D2BB, 0x0FA23605F, + 0x35926BC4, 0x18A7DAB8, 0x64BCE7ED, 0x4720DA9, 0x4D4828C0, + 0x846DD8C0, 0x0A0D3266B, 0x52856A6A, 0x433A6C3F, 0x9D2AC97C, + 0x0CC209832, 0x86D14EAD, 0x86CDF5E, 0x0A3722619, 0x78C88781, + 0x800BD3C0, 0x0CF236B7B, 0x191BA904, 0x752F7BD2, 0x6127512F, + 0x6E43A31, 0x0BE3949EB, 0x0D4FC3EE4, 0x8B5C62C9, 0x6174B35E, + 0x942141BA, 0x0E611D8B4, 0x9D1DDF99, 0x0CFD98020, 0x0DC690A9F, + 0x3C96937E, 0x7B21E1EC, 0x81568BD2, 0x17E55B05, 0x0A7EEF7C0, + 0x435BC051, 0x0E972FB12, 0x6AA2F9B, 0x38BECD36, 0x58011694, + 0x0B8F13ABE, 0x0A90EBD4D, 0x41ED1FDE, 0x5B88BCC1, 0x0DED8F1F1, + 0x43A68049, 0x519E36F4, 0x2BA5CB26, 0x8D6C0909, 0x534530FB, + 0x3B369AF6, 0x0EB4C9B4F, 0x3632ABA4, 0x9B02C710, 0x0E5B14A0, + 0x0FCB4C60B, 0x89F0409D, 0x1C327C75, 0x1DF2AEF0, 0x0FD512465, + 0x77A97113, 0x1669CA57, 0x0F820B023, 0x0D1D7D0AB, 0x32A42761, + 0x0C7C6924, 0x7049A4B4, 0x983C206A, 0x2B658B26, 0x0BD815288, + 0x95135263, 0x0B4B6B06E, 0x13B1053D, 0x2BCCBF70, 0x0BA62C42B, + 0x0C5B858C6, 0x0D98D40C5, 0x97F2270A, 0x705C4249, 0x0ACF830BD, + 0x0B13E2419, 0x82C945C2, 0x8666553B, 0x8B6B91E0, 0x0A4AD9D8, + 0x0AC651145, 0x0E24C7BD, 0x0C14516FE, 0x9674CADD, 0x181CC480, + 0x597CA1CD, 0x0F2FD9622, 0x45C39E47, 0x582D8A1, 0x0F9932AA8, + 0x0FC472B9B, 0x497B4072, 0x0F56C0514, 0x0BDCDEECA, 0x2172EF3, + 0x1221D7FA, 0x0A9F04386, 0x0B8D0B4F0, 0x64A337FA, 0x527ACEBE, + 0x2262CDE4, 0x39818518, 0x0C46120BB, 0x0F98BCCD9, 0x0A0581C5C, + 0x0D304AA7F, 0x2040285, 0x3A99BBAA, 0x0A6A6E75A, 0x56BFAEA1, + 0x3F8235E3, 0x832AC5CD, 0x0F361298B, 0x0D256573B, 0x0DC1053A2, + 0x8702511E, 0x89DF1ADC, 0x9AAFB04B, 0x7B2335D1, 0x372509BC, + 0x0A9B4337B, 0x3EEF020E, 0x0FD6FF3BB, 0x0C4DAD603, 0x0D4B52DD4, + 0x8F7AD500, 0x81EBE8EE, 0x9EA5E190, 0x0CAF80194, 0x9FF6F2DF, + 0x6ACAAB37, 0x764C933F, 0x8ED2E9A9, 0x0BD4863A7, 0x588315A2, + 0x3ED2952F, 0x5FD65D3F, 0x7B947095, 0x2CC9417E, 0x277DD0BC, + 0x0BFDB16C3, 0x0AB40A328, 0x8928656, 0x0A2D36D83, 0x6FF60DE2, + 0x5CF1C41A, 0x4C137DF8, 0x5E98D560, 0x6F7B7C8A, 0x0E18BDD6B, + 0x9AC10170, 0x4FD1B072, 0x2FFDAE7, 0x0C9343655, 0x0D251290D, + 0x0A4C3E915, 0x0A758E266, 0x0E7505957, 0x15B84F5A, 0x0CFF3A8E6, + 0x209A8CB4, 0x4B860E2E, 0x0C42A0B25, 0x802655C2, 0x6E1A11BF, + 0x46B85ED6, 0x811E387A, 0x0A8629BC6, 0x0D26EEBB3, 0x690E938D, + 0x2C47EDA8, 0x7AEB624F, 0x0CD6AD2FD, 0x85EB35D0, 0x0E79B833A, + 0x6545D2FA, 0x1F24BE4A, 0x0ABF50E5A, 0x114F95FE, 0x1A3755A3, + 0x0CBF0EB88, 0x2C10272B, 0x4ED9FA01, 0x8BC59569, 0x1063CFE3, + 0x9962C77D, 0x7CEBCB8F, 0x0E93579A8, 0x705324C8, 0x0C3507AD0, + 0x0BE7D6336, 0x0A40A2CFD, 0x0ACD4E4E5, 0x0BC7E06DF, 0x74C359C3, + 0x6E0A1545, 0x0C43B4726, 0x0D3D276A7, 0x3F328743, 0x383BDE9D, + 0x0FB1EC6B8, 0x9B701366, 0x17E0603, 0x31E17062, 0x0D0521A08, + 0x0E3BF6598, 0x0DA9E2E8F, 0x0CD81F431, 0x5EA3DC4, 0x0BE6135FB, + 0x2BC599B5, 0x0BBE0D3E8, 0x9B3D67D7, 0x7C3E8D8C, 0x96691F82, + 0x0ED03B6A2, 0x0D3E01170, 0x0AE79B687, 0x0FB3FDB43, 0x932F86BD, + 0x2DA7F4FC, 0x25783869, 0x7C3C2484, 0x1FEA6CD6, 0x6CA70926, + 0x0F2DFDCF0, 0x78959413, 0x41F7D1CA, 0x8F3689DD, 0x6694AC19, + 0x92BF03FD, 0x0EC5D5EB6, 0x0D8E8EE4E, 0x12BCF020, 0x0AB6E8B8F, + 0x4E60FCF7, 0x0C892F0E4, 0x0C7BB3182, 0x0E2998555, 0x0DA85D42A, + 0x204A884E, 0x973739FD, 0x9A738A1D, 0x41914E2D, 0x0E064F078, + 0x0D115118E, 0x747272F4, 0x7389151B, 0x4B769F8F, 0x8790171, + 0x4F4C5727, 0x0A2B31052, 0x0E0545000, 0x0BC99224, 0x4EF49243, + 0x3F926A6F, 0x6113FB79, 0x0EDAA8E63, 0x0D2A0BB14, 0x0FAED8B4F, + 0x0CF09D9E6, 0x0FE00FE2B, 0x7AC5ADA8, 0x0C5C81B10, 0x6BCA6375, + 0x0CFF02ABA, 0x29177E4C, 0x0D068040D, 0x0B52C5391, 0x30E19B8D, + 0x8D8A8C, 0x8D5270E4, 0x6F43A1E9, 0x34761B60, 0x5E5A6837, + 0x0AC4BC673, 0x9B648669, 0x2B95B231, 0x0E6F5F258, 0x1F59B0D5, + 0x78257B3E, 0x0A762A93C, 0x7911413D, 0x16BF1868, 0x885A39D6, + 0x77438AFF, 0x36A4AD72, 0x40425CA, 0x8B19BADD, 0x0ADDD1E36, + 0x80E4D0C6, 0x97EC41D6, 0x84B63640, 0x9A146DDF, 0x0F8448344, + 0x0C37C15AA, 0x0B2C6262C, 0x0D00EC036, 0x7D79DE3A, 0x0B6F98AA4, + 0x971F430F, 0x1E30A1B9, 0x327A3C34, 0x0E4E8C95F, 0x0F4D58695, + 0x971ED924, 0x777B3301, 0x0FC0F3BBA, 0x0CA3D29AB, 0x8BBE6F75, + 0x0EEF09FAC, 0x0EF7189D0, 0x5AEDA37F, 0x8A34AFE8, 0x77909783, + 0x0F0559C00, 0x24B9AF7D, 0x67E61FFB, 0x334E7513, 0x6D3F9DE5, + 0x0EAB74652, 0x32798A6B, 0x8460D228, 0x1AF4F45E, 0x0AD3B9FEB, + 0x3CD2F933, 0x0A3B86D1, 0x0E6794C86, 0x0AEDA3575, 0x1615B493, + 0x0A694AB59, 0x2138DBC, 0x6E6AC05E, 0x91A74506, 0x79609A4E, + 0x0E048DF9B, 0x0AEFF3952, 0x0BF2F7449, 0x0E5D4EC7C, 0x31DBAD02, + 0x6EEFD93F, 0x0EF904A5A, 0x8B6579F1, 0x0E5D39E0C, 0x0F1CE1950, + 0x0B3EF1176, 0x4AC75BFB, 0x2E749D18, 0x0B671B3F4, 0x0DDB35119, + 0x45F1EA24, 0x7C43D1C1, 0x7FEE9FD7, 0x7C7ED400, 0x0DC16C13C, + 0x8105A5E6, 0x4C9916E7, 0x0E338A229, 0x0B1ACB74F, 0x2EBFC0A3, + 0x6008914F, 0x0A20405D1, 0x0A469E5A9, 0x0B3B60C54, 0x3A0FC97E, + 0x89488574, 0x0D640A6D8, 0x8170B398, 0x9DC3B820, 0x0ABA8ECCF, + 0x0A86691A8, 0x4BB11C4B, 0x887A9623, 0x580B42E0, 0x0BC528028, + 0x0FF7DF189, 0x3CC8DCB3, 0x2193D0E4, 0x0F2B88BA3, 0x0D11B1BB1, + 0x3C83433D, 0x0D7A82057, 0x6C8D0CA7, 0x300FC35F, 0x48BEC56E, + 0x8BEDFBF7, 0x8A059C01, 0x0CD1F5270, 0x60D19934, 0x8F4768C0, + 0x0ED9614BD, 0x9B4E7100, 0x0C64E3ABA, 0x72DDB3EF, 0x76F68C2A, + 0x0C8E2096E, 0x0FB0D606F, 0x6126302, 0x47185ED3, 0x0C8614356, + 0x0C0200400, 0x5D8B41B6, 0x0C0322386, 0x4A8F8895, 0x16DE6058, + 0x0C62F5607, 0x83B9B44F, 0x3F718048, 0x3DDBEBA6, 0x0D420ED33, + 0x7062297D, 0x0D94C16CB, 0x0B8ED6056, 0x57C68CB6, 0x0A821DC9B, + 0x89A572BD, 0x4628B716, 0x5FC4FE4E, 0x8C2D6577, 0x0FF41FCFA, + 0x0E9E12AD1, 0x3F004CF7, 0x0BEF99E1D, 0x2D265F9F, 0x0E2AE30B6, + 0x879EBEEF, 0x1E3CA0DC, 0x43988309, 0x0B1638431, 0x804DDB2, + 0x0CEE9C43F, 0x0B31B90D5, 0x19161EF0, 0x0D3D773FE, 0x2D36A214, + 0x2D76F0E0, 0x191B37DF, 0x39FB88CF, 0x0DE981468, 0x0A4AD4D47, + 0x0F307482B, 0x0CC966663, 0x0C2C43387, 0x46058E67, 0x28B00B41, + 0x5B0D9537, 0x0F9AF58FF, 0x8604DEDD, 0x792A77CE, 0x0F804DF06, + 0x0E48E1B9D, 0x156DA486, 0x0E7CBC7C0, 0x0F5614CD0, 0x24D5566E, + 0x0E4478A7F, 0x0B2277343, 0x0E14925D0, 0x9B3B21BF, 0x23D67925, + 0x5C1335C5, 0x8F20F483, 0x69B3D71C, 0x439F9A15, 0x0A7A504F1, + 0x0F8C82A7, 0x0EF730F53, 0x0F667562C, 0x91311BB6, 0x0B271D739, + 0x0CFF1A271, 0x2D335687, 0x5E4CF240, 0x9F53C75, 0x0E9E0ABC3, + 0x18488383, 0x8ECC42FC, 0x0E47D3BD8, 0x5E3681D5, 0x292C06BD, + 0x0E1C50498, 0x57AE9C20, 0x9028BE75, 0x11A24812, 0x598D7200, + 0x0B06C6949, 0x1F2A3AB0, 0x0C0B1F29F, 0x38B80361, 0x81DCEA91, + 0x0EDF30FD3, 0x679DEDC2, 0x0FC1B7229, 0x9B65A975, 0x1976966A, + 0x78EB6216, 0x69CCB803, 0x0FAA6EB1, 0x6EA6843, 0x0A460B979, + 0x7F200CDE, 0x2F904343, 0x55C25D6B, 0x0DC019D08, 0x7EAAE8E6, + 0x8A3E7067, 0x0E5B48F2F, 0x4F14F520, 0x0E8410689, 0x0F3167E9A, + 0x0D9B5571C, 0x711CEC5F, 0x7EFA5E73, 0x7AC0379A, 0x92FA4DFE, + 0x0F1E0EAA0, 0x41282991, 0x6F1FA364, 0x0AFF84BE3, 0x0C1649701, + 0x7263E110, 0x65590C34, 0x13646A18, 0x11EDDDDF, 0x927D3D5E, + 0x2CD2FA88, 0x0DF330329, 0x5300E6D8, 0x618D3826, 0x0D530371C, + 0x7299AEE5, 0x376219C7, 0x0E1E70A58, 0x0B158CBEE, 0x6F0D4557, + 0x0AF1920CA, 0x53212C1E, 0x516F003A, 0x0B742E1CD, 0x0EC68E53F, + 0x380F57E7, 0x86D95E7E, 0x692EDAD3, 0x5ED68FC1, 0x51C7855E, + 0x623BAE76, 0x0E806CA38, 0x0B627882E, 0x9E9DEE73, 0x347CFA20, + 0x0D43F8A07, 0x0E76079A4, 0x61260B50, 0x8EBF8BB8, 0x0F8E328E, + 0x20C64B7E, 0x1C389564, 0x4269E9BC, 0x0B9E81C59, 0x0D2DE275B, + 0x8EE7855B, 0x6020DDE8, 0x3382E137, 0x0AF6E7616, 0x0B8881522, + 0x38C9713A, 0x1FD05A33, 0x0A879E1CD, 0x0DDB1BDE6, 0x5D89EDEE, + 0x5D899F9B, 0x0ED4651DE, 0x7C363615, 0x9FC4DB82, 0x0EA00AFC, + 0x0EF59EFE4, 0x582D795B, 0x0F2003B2, 0x944B3422, 0x617723BE, + 0x70EABFA5, 0x0FE816F7C, 0x8FFFF51C, 0x32A59887, 0x6038221, + 0x0FD0D671D, 0x0E0716735, 0x9328369E, 0x9B4B7A3B, 0x0DD297411, + 0x0A896E3FB, 0x0F686259E, 0x0EFDAA0A0, 0x0AF796015, 0x49A3013A, + 0x0C82D066, 0x5022D3D, 0x0C4E33427, 0x630D9C01, 0x0C523DE12, + 0x1C5A9A40, 0x0AE8C3783, 0x0D888CB9B, 0x53AD3AFE, 0x0B6B7A115, + 0x3CD8F5A7, 0x0C80BE796, 0x26A50BC9, 0x942C3A69, 0x816D3550, + 0x94C98ABE, 0x0F0D0BC4E, 0x0B7119E29, 0x0CC2F007A, 0x0DE388D22, + 0x0A233F4AC, 0x5FF84683, 0x0B0459F62, 0x860D090D, 0x6C139D3F, + 0x0FB8ECE3, 0x0FD119D86, 0x0AD3D570D, 0x0C0F6E1A3, 0x866587F6, + 0x0C43BC0A3, 0x0B4FD0FEE, 0x4E9F27B7, 0x0C65552AA, 0x56A613B5, + 0x3DC20ABF, 0x8151997, 0x101CC52A, 0x4478DFFA, 0x284163CB, + 0x1E9CA09F, 0x0E59099E5, 0x5F15ACEE, 0x976E71A0, 0x2B9E56E, + 0x5C5C888, 0x0B823434E, 0x0EA80CE0B, 0x653251E0, 0x721089FE, + 0x0A087AE18, 0x0C2EA5319, 0x370A8D12, 0x6E075776, 0x0A8653589, + 0x621816, 0x0A9878260, 0x787EEA5C, 0x0A223621D, 0x0C6DD7790, + 0x2E2F5969, 0x528A3C5D, 0x9D66FD92, 0x74910954, 0x75C67B09, + 0x0FC818467, 0x0EC1210E4, 0x0ACF0A66E, 0x6F51905D, 0x0B9F73DA6, + 0x1F4DE351, 0x4EB2682D, 0x4E1583C2, 0x8C21F87, 0x67B0055, + 0x7BCBA81C, 0x83977CD5, 0x0ABF623B7, 0x0B4432FAE, 0x9470FF09, + 0x0BE9CE372, 0x0A3E88224, 0x79877958, 0x3B154500, 0x0F12A63B8, + 0x312EB5FA, 0x0E66F2891, 0x50709450, 0x4C85E403, 0x0D69C76A6, + 0x0CC5EC5D5, 0x0F4774584, 0x41318EF0, 0x5248BDD5, 0x3CFA17E2, + 0x895DF06A, 0x81F5CC5C, 0x0A886C375, 0x87272AB4, 0x0AF986F0F, + 0x0FCD54564, 0x17EB01B2, 0x3E0B4489, 0x48DDDBBF, 0x0E316E365, + 0x214D31F9, 0x330BF1DD, 0x74218C08, 0x0A93ED0FC, 0x86C04BF8, + 0x75CBF76E, 0x94981DB7, 0x0FC107306, 0x499A879B, 0x57316139, + 0x49B964D9, 0x0D09376A0, 0x0AA6F610F, 0x6861787A, 0x75387DBB, + 0x540BC227, 0x29148FC1, 0x7BC1C4AE, 0x3809BFE9, 0x0F9FD8038, + 0x889F0B5F, 0x0A0F60E93, 0x0F362C431, 0x712E19B0, 0x0C8640FD5, + 0x27E56025, 0x48B865A0, 0x0ADA336AC, 0x2AF81350, 0x0A3B203A2, + 0x17C0BA83, 0x0DDA1C089, 0x2E31D03D, 0x0E4C37F87, 0x816F1E66, + 0x73AEE0E4, 0x9724404A, 0x0FBBC9D90, 0x0E8FA2717, 0x208DFF9B, + 0x64249A63, 0x398367BA, 0x0ECD6B1A3, 0x0D445C6C9, 0x0D7C859B5, + 0x2F3D2543, 0x6EB8D357, 0x0C01A1ECC, 0x71E535AD, 0x0AF4E60A8, + 0x9094E7BF, 0x57913041, 0x0F38F27F9, 0x0C85CE2A5, 0x0B2A186AA, + 0x476F6405, 0x5D1B6885, 0x0CD4CB437, 0x76528822, 0x84B96535, + 0x0F21E727E, 0x4D421E9D, 0x0BB5D0777, 0x3DB51B2F, 0x316EFC52, + 0x1BA4A951, 0x0A4B75C35, 0x0E3E6AE8E, 0x0DC2001AC, 0x46161F12, + 0x92951F28, 0x28138930, 0x0F488BA7B, 0x217F89DD, 0x246C2A5E, + 0x0FD405332, 0x0B93B9EEC, 0x3C012FEE, 0x3DF19624, 0x92B2F6F2, + 0x0AE0E676A, 0x68049AC3, 0x0FE18BC06, 0x59EE9C0B, 0x92170FA4, + 0x0B62B9418, 0x0C61834D3, 0x2B9AC5B, 0x67ABCE86, 0x775C25EB, + 0x3864D896, 0x7F19D000, 0x6E5D1D3E, 0x3CBB9678, 0x34B3C09D, + 0x151F255, 0x2805B637, 0x0D6AE713D, 0x0DCF84774, 0x0F8E839F8, + 0x56B59020, 0x56DA7FF6, 0x906904EA, 0x16A20FC7, 0x0F8C4E6E5, + 0x0E23C8A1, 0x0F17BD00A, 0x4B841DDD, 0x51C630B4, 0x8DAF957A, + 0x0E1E3C622, 0x0C9D34C98, 0x0E09127F8, 0x0A6E370FF, 0x80963DBF, + 0x14C596, 0x6739C560, 0x686322EC, 0x2FC8CFAD, 0x0A20DF1B2, + 0x0E71441D8, 0x2615B23F, 0x90F055FA, 0x0A0C1790B, 0x0A0B5168E, + 0x701D6C34, 0x83C1E7F3, 0x2A7746FC, 0x15F4FCEE, 0x16E1D649, + 0x2932DF25, 0x0B2B38124, 0x5E3ECA5, 0x2B06BC3A, 0x0E476D55D, + 0x0E83A925E, 0x72D920A0, 0x0FF702405, 0x5303A4A7, 0x0BE1124C9, + 0x9D6B0F0D, 0x234659E7, 0x5A8E6351, 0x647D1FC0, 0x76D7457, + 0x69EAE45B, 0x170C6CE8, 0x4C03ABE2, 0x71F4472D, 0x0E0048D21, + 0x0EDB25738, 0x2769330A, 0x0DB55C17C, 0x0DA775D34, 0x7CF4FE50, + 0x0E5B35E57, 0x87265C6F, 0x0E8689ED1, 0x0A6897A7B, 0x0B8261724, + 0x0F63CCF75, 0x0DC3DD876, 0x8B642447, 0x10468510, 0x0E9AB153A, + 0x0C59BD5E0, 0x8CBC9480, 0x9FDB13F7, 0x61C866AC, 0x0F6679D0B, + 0x4B04A435, 0x56E768F5, 0x9F283BF7, 0x0FFC57A34, 0x0A7F26DB1, + 0x65B06E69, 0x23A14E87, 0x0B11BF4D9, 0x0C47B4782, 0x3EBC4FEF, + 0x0AF48960C, 0x1C0DD5B7, 0x0D4CC75, 0x91CE7263, 0x44704E70, + 0x938125CA, 0x0FE72D596, 0x50ED81E4, 0x23B0EEE2, 0x0A69C2D4F, + 0x9E097B33, 0x0AB5D65CE, 0x0CDDD30CE, 0x26C377C5, 0x29016D9, + 0x14A347BE, 0x20B0BE1, 0x259ACCE6, 0x8A3A4055, 0x3C849090, + 0x0C58FBA09, 0x0F20634B1, 0x0D77ED2B4, 0x1306E963, 0x55FFB571, + 0x1F2EF863, 0x0CA0FE442, 0x0CB6C3B93, 0x342FB589, 0x7E75A278, + 0x85E3D08D, 0x0D43DAFBD, 0x2334B3FB, 0x1E80FAAE, 0x682F2F62, + 0x0E03DAEBD, 0x2364E8B5, 0x52350901, 0x1568D9CD, 0x0DF71E0B2, + 0x7454CEE5, 0x0A9B91AAF, 0x6B43E81D, 0x31E30F8, 0x98D71DF7, + 0x0F671B334, 0x8EB5B5DD, 0x0BDC9C62C, 0x5104CE99, 0x49019F4E, + 0x0DCF2D9DB, 0x0BD370A2B, 0x9E301AB6, 0x0F34FE7F9, 0x0F8712C23, + 0x0F56EA712, 0x0C0EE7B7D, 0x847FD373, 0x0C2E5C804, 0x95B1853E, + 0x3A16A85B, 0x0CFF7EC38, 0x5B440509, 0x0F87CC4C, 0x0CCBA9CFB, + 0x0E55CFC06, 0x25C47E00, 0x14B4E718, 0x76318F4C, 0x15920BD9, + 0x0C0D80AF6, 0x943D7DC1, 0x7A10FB7A, 0x0F1BF63EF, 0x0E36C337, + 0x0C06778A3, 0x592A97F2, 0x4A488CC4, 0x2ED20152, 0x0BB8025B, + 0x0D4965E62, 0x32D15016, 0x83E35E12, 0x24F382C6, 0x0EBA988B5, + 0x0F840B7E2, 0x0AEDDB384, 0x0FC1FA201, 0x0E1F78E1A, 0x2FBA0A63, + 0x8F7419F7, 0x0C5804B69, 0x355529FE, 0x0A6A3D319, 0x479FE8F6, + 0x0EF9AA69B, 0x0A9D9530C, 0x70A1DBBF, 0x3791BA4F, 0x2D351C74, + 0x3ED74333, 0x0DD982A52, 0x1C0680F, 0x6D535612, 0x35E5749F, + 0x7EAE0910, 0x85E10A83, 0x0E33A3DD0, 0x0FD69EBE, 0x24480276, + 0x0E4E9FA37, 0x0FD6FFA4C, 0x8CC2BB3B, 0x0E00BDD40, 0x800DD1F9, + 0x6FB8F663, 0x0AEFB0205, 0x3DBA46B, 0x0F9C268D6, 0x2819DA32, + 0x0B618EE48, 0x1EDD9F35, 0x30BCD71B, 0x5AD78F16, 0x25EE3772, + 0x278581B, 0x47F27854, 0x75773EAC, 0x0BC91D62E, 0x0C14F97D9, + 0x9E97E350, 0x2ABE4FD2, 0x7C56046B, 0x0AA47666C, 0x0D622F31A, + 0x6CB16DA3, 0x0A5D33B56, 0x50860D12, 0x0D146BFFF, 0x6A96807D, + 0x0B9DC335A, 0x82711548, 0x0AFF9A08E, 0x95F0B0FD, 0x7986E526, + 0x53AD48CA, 0x0D1703192, 0x9F866800, 0x0E6278AA6, 0x131EAE96, + 0x0D9204919, 0x795C4FA4, 0x41539B07, 0x52EA91E8, 0x0A7BD0270, + 0x53B74F44, 0x0AE0D2B7, 0x0E375793E, 0x5C3EB424, 0x9F1C927E, + 0x4E22762, 0x0D6653054, 0x5AD7FA01, 0x0D507F30, 0x2EAED2F5, + 0x7C9FBE27, 0x41FCAA15, 0x8F59C075, 0x0CADA4F9D, 0x66486DF6, + 0x0F263E0AD, 0x567A3FAB, 0x593A54C8, 0x66C4C53B, 0x8F02F355, + 0x0D23A2370, 0x9BE3DC22, 0x8BB88FB6, 0x780C7EDC, 0x0B55DD69F, + 0x932B1E98, 0x270AD561, 0x4EF7574D, 0x0EFE80156, 0x80A79557, + 0x0CCDFE07C, 0x0F3779AF6, 0x0B2208DF3, 0x0E42AFACD, 0x499C3881, + 0x87839E64, 0x6E8AA311, 0x80CB44A6, 0x0B1E5A630, 0x6B4FFD63, + 0x0D5ECAC8F, 0x55DFAECF, 0x54A03484, 0x414F8F01, 0x0D8495188, + 0x0A4FAAF76, 0x0C2F22ABA, 0x0E93A6F8B, 0x0A7E87B5B, 0x0EDF10206, + 0x0CE3F1250, 0x8403F48E, 0x0B44D53A3, 0x0F3DA9F2E, 0x882CB402, + 0x73E0B7D7, 0x0AF3D413F, 0x0B509C0DB, 0x41A01ACE, 0x58479372, + 0x8ABDF04A, 0x7513DC38, 0x8ABE8CF0, 0x14EB9FAD, 0x75124823, + 0x0B3CEAEB4, 0x34EC93E6, 0x0C6C13415, 0x0E3C17165, 0x324E2EFB, + 0x50CEF96D, 0x0D100ED76, 0x8290D6EF, 0x0F1E996FA, 0x304AC781, + 0x0D51CA1DF, 0x45831EDC, 0x33335DDF, 0x6385445F, 0x0B4C96A9B, + 0x5DDE348B, 0x77013E16, 0x0BCE3FC85, 0x8EFEA138, 0x3B283F97, + 0x7F69304C, 0x4A0AB6B0, 0x0C4EEDE82, 0x8E26AADF, 0x4BBF6E6E, + 0x60DE7BDC, 0x0F710FB88, 0x4ADB1C7F, 0x1E9971AA, 0x8D869546, + 0x9171195, 0x9E8D7FD3, 0x77CBF06C, 0x0A4648C6C, 0x1BF97837, + 0x0FCC2FD7A, 0x196AE661, 0x0B520290B, 0x8CEBCA3B, 0x143DFD50, + 0x3CC8B77, 0x119D761F, 0x0FF61E0AD, 0x0D8052971, 0x778558D9, + 0x4901BCE5, 0x5412D3DB, 0x785E6A3C, 0x0F56A06F6, 0x2EB083DB, + 0x0ADF2FB52, 0x66CDE94D, 0x40918E7B, 0x0D15094BE, 0x6935F2DF, + 0x53170F81, 0x574E2A53, 0x83C6F98A, 0x2C52908F, 0x2F4285F4, + 0x7C3752AD, 0x0D636FA7D, 0x0D4FCF0AE, 0x2C913405, 0x3020BFF5, + 0x99062113, 0x842969CA, 0x0BA8B4550, 0x341F6AD8, 0x0DFDB360A, + 0x9C0E94B0, 0x8BF421B2, 0x89878D44, 0x0F799435E, 0x0BE204C6C, + 0x8FD17048, 0x70F09F65, 0x7466904D, 0x0C914A84D, 0x0F8671D6E, + 0x692C5BA8, 0x26A6A753, 0x0E0DE02DE, 0x373B50C3, 0x3652B9BA, + 0x1DFF502E, 0x64B5F2ED, 0x0FC127123, 0x0D8B7F289, 0x0AC5694DA, + 0x0F50C5387, 0x39F22BAB, 0x90EF8041, 0x63D0BD95, 0x749A3CF8, + 0x1E1E66B8, 0x0DFCF1B4F, 0x13D154DB, 0x25206CE, 0x1D1D4AE7, + 0x856CBC61, 0x0CDFE206A, 0x16A4CD6, 0x0E7B34215, 0x841C9C62, + 0x0E23E2D3E, 0x1157E51D, 0x6CE5F55F, 0x1D743481, 0x0E4B4C195, + 0x14CEEAEF, 0x0DEF84D22, 0x0D1483D2B, 0x0A2C568EB, 0x29C4B6DB, + 0x0AD7274FB, 0x61ADB10B, 0x2E18E8FE, 0x0B36EE0AC, 0x8B16D1C7, + 0x0CEF8C810, 0x0DA904CCA, 0x5340426F, 0x68EB0EA3, 0x58BFFB66, + 0x3552DD8D, 0x0E9F1F573, 0x763514EC, 0x82D6037A, 0x12C423C4, + 0x96745143, 0x26780C3F, 0x0B53DAFA, 0x818BE72B, 0x0BB00F0AD, + 0x287B5F79, 0x0F58AB8D2, 0x0D38C33BF, 0x0FA08ABBE, 0x6D43B6B7, + 0x8011162F, 0x98EB50BE, 0x33429AC3, 0x2813FA56, 0x2FBCAD7E, + 0x0A30EC6A4, 0x87A31748, 0x0C87154F3, 0x0C1A0766D, 0x4995E2F, + 0x5860BB1B, 0x0FE232D6B, 0x3913ABE8, 0x0D72225C, 0x46ED5E49, + 0x0BC2D2EDB, 0x0D6A9C31C, 0x4DBE5A67, 0x32011B1F, 0x33D440A0, + 0x1A377976, 0x96E18FCE, 0x3E904829, 0x0D39D8C58, 0x0C5D3C5A4, + 0x0F9818C4D, 0x0CACE8136, 0x4E4D7ADE, 0x0DAD1E192, 0x0C88357E1, + 0x77319D51, 0x94E9B550, 0x98C7446D, 0x920B3BC8, 0x276EB6C7, + 0x0D7B7250B, 0x8289A9A3, 0x2A7FC17F, 0x0FA7B2527, 0x873AF2AD, + 0x572C08DF, 0x0A083B0C2, 0x518A833C, 0x56398711, 0x18069A11, + 0x44FD148F, 0x0CE13A814, 0x35B88B55, 0x8ABD863, 0x0A9123422, + 0x51CAAEFC, 0x54FCE8D6, 0x0A7F17C43, 0x9F2799F8, 0x0FBA4ED81, + 0x258AC832, 0x0B5EC7E5F, 0x37E00DD0, 0x2ED5FF6F, 0x59279244, + 0x34F117A3, 0x0C22398A4, 0x8AD4BDD4, 0x0DFD9F02A, 0x6596C03D, + 0x0D11483B3, 0x0F05440FD, 0x0EBE3CC42, 0x0C9AF3298, 0x3519587A, + 0x824BE077, 0x0ECCC4D27, 0x21516763, 0x0D7E0B5, 0x0A0EE370E, + 0x9458DDB7, 0x6DD2978A, 0x81322362, 0x0EBB21ED0, 0x0D38C2510, + 0x0F0C73B3B, 0x4A506ABD, 0x454CAD0A, 0x0DBAD0E8D, 0x29030CE1, + 0x2D953F44, 0x0CEB13F49, 0x1C40C1CD, 0x0DA9D032B, 0x3AA86BB4, + 0x0E7166B59, 0x480BA7AB, 0x4EA5A06, 0x0C16CF508, 0x32EF0A48, + 0x50116945, 0x0E77E899D, 0x55062980, 0x8EF33663, 0x6499F0F9, + 0x62E495F, 0x0C6DC8D97, 0x1F154837, 0x0F6276562, 0x201093F8, + 0x2593ED0A, 0x438BD991, 0x0B680305F, 0x3778A055, 0x0C30F4FD7, + 0x9DCAC17D, 0x96A9FC0B, 0x8CFBEAA4, 0x3176FE3A, 0x0D871A49, + 0x0C7E7B1C5, 0x0A06F2951, 0x402D83B1, 0x0B5B73D82, 0x0B9BF7728, + 0x33E85609, 0x1D8A6F9, 0x0F58FC3F4, 0x1DF7B913, 0x48BCAAB9, + 0x0C55D700D, 0x6E8484AE, 0x0E6931EA2, 0x1E7F9E8F, 0x1EE12B2D, + 0x24A9AFB, 0x42D79131, 0x3706ECF6, 0x0DBC85FD4, 0x0D1D85D69, + 0x0A54A395F, 0x54678C9E, 0x0FB8D6BF, 0x3C6168C4, 0x0BEB18107, + 0x76F6B771, 0x99698EC, 0x0E45B921B, 0x7E0F1048, 0x0DD49E69E, + 0x5C86EF98, 0x0AB7BF4B9, 0x17AAD07E, 0x0C34D291, 0x0D8EE633F, + 0x0B1B6E92C, 0x0FA08EB45, 0x0C2CC75F7, 0x8E72BE9E, 0x58410841, + 0x0D7ECC87C, 0x16707BD, 0x0CFF808B4, 0x40912B04, 0x0A05D113F, + 0x0A990111, 0x2CA58ABB, 0x4A5B6AC3, 0x859FAFEA, 0x5E371C5F, + 0x76DECE32, 0x9793200B, 0x0F837CB1C, 0x0BD575254, 0x0BE479DD6, + 0x8970E3A9, 0x0AAEACEB1, 0x2A4EDADE, 0x55C5FFA3, 0x0C0658FAA, + 0x8BBE61C6, 0x0E4AF2F29, 0x0CC7F3DD7, 0x1E283B5A, 0x0CDF66DB7, + 0x6D5109A2, 0x0F5D7E1EE, 0x0C3AF4147, 0x0E0191B23, 0x864961F6, + 0x0DF75B3A5, 0x102D3A3E, 0x76EBD4E6, 0x2FEB7113, 0x0DD3CBDFB, + 0x0A618FF4C, 0x8071401D, 0x0ABCCB124, 0x7E52472A, 0x6724A8BD, + 0x2EF04A25, 0x79C2D999, 0x951CDAB2, 0x73488F1F, 0x0F1ED1A9B, + 0x5BE1E41C, 0x323E404D, 0x2CB84C3F, 0x7B2D185B, 0x527E0B9C, + 0x0A69E82FB, 0x32E8B92A, 0x0BDB6EF84, 0x9F2FC545, 0x8260E8F6, + 0x668FEF2C, 0x0E8CB8772, 0x0C3C8CD84, 0x97EAFBBE, 0x0E9A047D3, + 0x6BF308C2, 0x7E5F1B06, 0x0F6E1850D, 0x1D5159EC, 0x0FAF2DD51, + 0x0D348E8B9, 0x0F0298EE3, 0x0A217FF84, 0x84CDAD3C, 0x118ADC9, + 0x16E8607B, 0x59A752E7, 0x3BC962E0, 0x8AA524A3, 0x3A838352, + 0x64F6ABA4, 0x8F6C26DA, 0x2F0344F5, 0x6B9EC126, 0x2339A286, + 0x32796007, 0x0F08748AA, 0x0FB1F22F3, 0x38E4119B, 0x14F7BA84, + 0x10C7A8F2, 0x7C2BEFF7, 0x82AE102F, 0x67291DAE, 0x0E981E37, + 0x0BE26B2AE, 0x248AFAD0, 0x9C96B222, 0x0AC0DA127, 0x0D1B634D6, + 0x7FAE664B, 0x6302E2BD, 0x0EB7D6CB0, 0x8BF7D6C, 0x338F2DAD, + 0x0AE73569C, 0x0C7DF7FE, 0x0F367D6AC, 0x21E36A43, 0x0AD2CF71C, + 0x8FE1FB7F, 0x6313C913, 0x6A9D7499, 0x0D2B3EEDA, 0x37BE71DE, + 0x69671E5F, 0x70F2E57D, 0x0CDCEA4B4, 0x36A930A, 0x564ADF8D, + 0x0D35995FC, 0x9081C2C5, 0x3579D92F, 0x0BBDE54D9, 0x74869E63, + 0x4C11316B, 0x4EC0FBBB, 0x6A8B07C0, 0x756D593F, 0x71031A43, + 0x0F55F55A, 0x72F4C000, 0x36455F5C, 0x0B11CE52A, 0x788CFDF9, + 0x25FE8996, 0x588188C8, 0x0FC613D3D, 0x0CCFB8EC5, 0x15CFAABE, + 0x0BDD7EECF, 0x84180ADA, 0x8A765F2B, 0x12CCACF6, 0x853CEA00, + 0x0BAC4749C, 0x74126BD9, 0x2C9A59FA, 0x11E51426, 0x4E2CE661, + 0x8B25EABB, 0x0B61DB9C7, 0x347464F, 0x31540746, 0x104356FE, + 0x407B169C, 0x3B1799C8, 0x9581C1A9, 0x83426610, 0x9B18F8F3, + 0x0DA49661E, 0x0EB383E25, 0x0A636159D, 0x0D89A298B, 0x4214451D, + 0x0E43EE598, 0x7B749B92, 0x48E6B161, 0x13EB10D3, 0x70996020, + 0x4192711C, 0x7C20DAB1, 0x2E85E08D, 0x0C08C9918, 0x796451A9, + 0x45AE2CF9, 0x0B5D50DD8, 0x469EB71E, 0x0E60032E5, 0x0B43571F5, + 0x8113180, 0x0B3932410, 0x88BA4FBD, 0x1B99B0A3, 0x0C8AE2593, + 0x0F7708909, 0x9F27205E, 0x900353F, 0x0D761015E, 0x447ACF67, + 0x0AD1D5E36, 0x51CF8747, 0x551F1F6E, 0x0B361FC8, 0x73B002F1, + 0x2AA6F77, 0x0A31C188F, 0x0FC6AE207, 0x0F235467C, 0x6F77F7CD, + 0x62CFC5CF, 0x819C143, 0x6B42A205, 0x285A6786, 0x74EB3E7B, + 0x618AA5D7, 0x5EABCFF7, 0x0FDBA491D, 0x0FA67DD20, 0x7841B762, + 0x8D86C601, 0x1396552, 0x53763B8B, 0x0FD035FBF, 0x0F927C010, + 0x84BFC520, 0x228E30C8, 0x0E2D5480D, 0x0E323374F, 0x176FB1C4, + 0x4764D625, 0x58FC5AA7, 0x0CC50E32D, 0x8CAFB2BC, 0x0E4ED862F, + 0x0CFFDBD2C, 0x75C2BD56, 0x0F22392C4, 0x595ED8B3, 0x0F89EDC77, + 0x0DECFFEB8, 0x9BB15ADA, 0x472BA7BD, 0x0C6E35EA7, 0x490B1F7E, + 0x187E523B, 0x900B0A9B, 0x67102E17, 0x384BDA17, 0x3BEE0363, + 0x53F15ADA, 0x4FAC7366, 0x69A5272F, 0x13A7370F, 0x0F4143147, + 0x2D7B9870, 0x0E06D3FB4, 0x0F38DF63D, 0x11E768EE, 0x0F2834451, + 0x0DD399BD1, 0x6BC68A2A, 0x8D20181D, 0x0D0076168, 0x0E0DDF5F5, + 0x4BB77B52, 0x88B49A61, 0x388E1951, 0x0AB6E44CC, 0x0A6059272, + 0x64D88687, 0x0DADBD3E8, 0x4042C344, 0x0CC94D988, 0x0C101B69B, + 0x0A8F5394C, 0x0DDEDEA89, 0x4E8A99D1, 0x80E342EB, 0x0D32034D9, + 0x6457208, 0x0FD4B5AC9, 0x0C2758405, 0x0CBE1ED2B, 0x7B5E556E, + 0x0EA7DE52E, 0x0E9EB15B3, 0x41FDCD21, 0x3C8DCAA8, 0x670544FC, + 0x95B9CE05, 0x277A7DD7, 0x8B674CE4, 0x307BF70, 0x0A895C746, + 0x0AE9BE6AA, 0x0E9C3938E, 0x90E9E009, 0x42745A04, 0x46E73137, + 0x17B39954, 0x20506F81, 0x0C48B200C, 0x0A122C75A, 0x168E9521, + 0x22076D7, 0x0CF4FF16B, 0x0B0515032, 0x26E80224, 0x0C97F3D48, + 0x4575E86D, 0x0A3B9B71B, 0x0CA9798C9, 0x45D14E50, 0x46F25BA0, + 0x0EBDF24B2, 0x0C1AF50BE, 0x87BC71AD, 0x34FAE6D1, 0x3B8800D4, + 0x0D8563EE, 0x0DF25AF5B, 0x0AE04600D, 0x81BAF39E, 0x0EFAF4B88, + 0x0E0315298, 0x98C3E3A0, 0x0F1B8E86D, 0x0E701BFF8, 0x5A44E3E0, + 0x102EC818, 0x0FA0906DD, 0x0B891BAEC, 0x5E0329F1, 0x7978A742, + 0x4D71B8CD, 0x61B37450, 0x3E5530C8, 0x73175A2B, 0x0DCF5A559, + 0x24FC6650, 0x895D3EA0, 0x0DFC0FA20, 0x0D8DAB7DE, 0x82424A5C, + 0x1180DFF9, 0x0DF67DFAD, 0x0B1A618F9, 0x3C99181E, 0x0E865D98E, + 0x0D343A4A0, 0x191C2F87, 0x53570985, 0x5DEF375C, 0x5DC82006, + 0x43A6A5, 0x71096BD, 0x34342A1, 0x5CAA6C2B, 0x985E66B0, + 0x0DA997833, 0x0A9C782D9, 0x0F3E0E29D, 0x52F49845, 0x8D08A895, + 0x6220C0C2, 0x839D1B2A, 0x0DEC9A541, 0x21B160CF, 0x7E330659, + 0x0AC57F0DC, 0x2EE336C2, 0x0D729180E, 0x8E249DDA, 0x4FC37903, + 0x72853423, 0x304689BF, 0x63590DC2, 0x8DD6112A, 0x1C35C802, + 0x0EC1CAD90, 0x0E761FCF, 0x0C8C54E20, 0x0DCB95B3C, 0x0D01BB6D, + 0x0E061DDFE, 0x0A0050CEF, 0x0A41596EE, 0x0D5892E83, 0x6A3F8F8B, + 0x0F64A62E7, 0x0A58E6275, 0x0C28ABE3F, 0x7D74BEF3, 0x0EC8BAA94, + 0x4FA9E86E, 0x9817644F, 0x2BA635F4, 0x0E2FB7DC2, 0x542B90B7, + 0x5788599F, 0x0C3BAFA8B, 0x7911B37F, 0x0A419056B, 0x3F6F175C, + 0x0D8D458F4, 0x93806618, 0x71B82FE8, 0x0D2A356F4, 0x395AD8AC, + 0x503EEF19, 0x2C8E36CB, 0x0D1390E13, 0x0F9F04172, 0x1180E650, + 0x855F85F1, 0x3D847BA6, 0x687C9F40, 0x78BB25CA, 0x6D30C378, + 0x571C13DA, 0x16233955, 0x65A4C5D4, 0x1746DBBB, 0x9FD3911D, + 0x0D64A982E, 0x0F92F1FFB, 0x0F126F458, 0x0D8C0EC1A, 0x0B8958687, + 0x9693CB0B, 0x0AF95782D, 0x1375FC0, 0x0DE90B5E, 0x0DC43A312, + 0x40991055, 0x5CCE623C, 0x666D70EF, 0x0ACF5BF5D, 0x0D575A62E, + 0x6A59AFF9, 0x95843FB8, 0x289F7A79, 0x0E0B06156, 0x0ECEE3DA6, + 0x0A9D44175, 0x0B0746B32, 0x120EABA8, 0x0E2E14730, 0x0F4417E24, + 0x0E5EA6C96, 0x5B942D42, 0x8EC745C2, 0x8F13F01, 0x0A9B695F2, + 0x0ED87D082, 0x7276F0CB, 0x0B4480E8A, 0x1BCC40D3, 0x396CBD03, + 0x4C0242F7, 0x0BEDB47B, 0x9F630605, 0x0EF085DA4, 0x20C07233, + 0x5CC238D2, 0x0D3EFC097, 0x615980, 0x2E46FBAC, 0x3AEFE6CB, + 0x9A2486D4, 0x9EBB9AF6, 0x0F66995D0, 0x75D744E4, 0x15F8B249, + 0x3A9B49A1, 0x3B3C394B, 0x1E201EDA, 0x0A3A1DDC5, 0x85C6CE5F, + 0x0FC16210A, 0x86AE7AA8, 0x0E792DF53, 0x6E41D44E, 0x7B8CC43B, + 0x3EA7A38E, 0x0C181D241, 0x295143CA, 0x3971DD4A, 0x17702207, + 0x53630F1C, 0x257B436F, 0x0F6DD64E4, 0x22ADBFD0, 0x0FD6C2EB1, + 0x14853F1C, 0x0B52292F6, 0x0B14483E7, 0x6013090C, 0x0E673DEEC, + 0x0B5D7E1AE, 0x535AB889, 0x5E0CB97B, 0x0CD890B3E, 0x78D10878, + 0x0DB53E632, 0x164B978B, 0x394EEDAD, 0x0BF230201, 0x58D5D79F, + 0x0EC063B09, 0x0DC86EF18, 0x8B250736, 0x1DC593CE, 0x7EB37F01, + 0x0A637B89B, 0x1C699045, 0x0B94764FC, 0x0AF057CC1, 0x0CAA43292, + 0x0F5C6579A, 0x0FFC1D2A5, 0x9FF28AD6, 0x0B654879C, 0x0D55054E2, + 0x0FFD7A786, 0x0B0AF430D, 0x1D0A1E95, 0x0BE5DBF0A, 0x0A6FEB9D, + 0x82B18072, 0x0F0CDA199, 0x0F1811340, 0x0B1AEE727, 0x0F6AC5A54, + 0x60E1F907, 0x0EF9209F0, 0x0C5F825A0, 0x2D97293E, 0x0DDCB4F7B, + 0x78A498C7, 0x57F36EC6, 0x89A587FD, 0x18500CD2, 0x8E0CFBB3, + 0x0B884CA95, 0x0AA4D4DA0, 0x376D928, 0x7360AAE0, 0x7ACF824A, + 0x72429372, 0x0CF809FDC, 0x0A6745EBB, 0x6C3A2063, 0x17AB301, + 0x0ECF5878A, 0x0E95D10F1, 0x0A16A6C9D, 0x0B82A461A, 0x0C99FA0F, + 0x3C71F970, 0x684370F4, 0x38C724CA, 0x2071A088, 0x0E2449364, + 0x54EB74A6, 0x6306675D, 0x58C26451, 0x5AAC963A, 0x34C7012F, + 0x59DB6861, 0x25116E09, 0x66BDFB9F, 0x1B7BE14D, 0x7C7DC0A3, + 0x3A23278C, 0x7CCFB81, 0x59ED1DFC, 0x6B604730, 0x85FE37F7, + 0x7E6F100C, 0x7F41FD7A, 0x9381754, 0x3AE589A7, 0x4C7AF1AD, + 0x5EDD0A43, 0x77FB899D, 0x0C85F4439, 0x31039911, 0x7660E15, + 0x15DE35D8, 0x0E030D38A, 0x305E4026, 0x0CBC011EC, 0x8456F512, + 0x745DDDB7, 0x88206018, 0x3C115D06, 0x0A518E298, 0x0B52B4C1D, + 0x0BB1FB054, 0x29BE7AE0, 0x9A1954F6, 0x13204A59, 0x896F2B88, + 0x0A46B3235, 0x0C38EE5FA, 0x40FF3E48, 0x0F56609A0, 0x0FFFE8D05, + 0x0C1EC6EB1, 0x2CCFD207, 0x3E98C3C9, 0x0C99CD58B, 0x76E70867, + 0x9D3EFF3, 0x0E7DA1270, 0x0D5A99244, 0x2750BAB, 0x4892BEA9, + 0x0AF42F043, 0x33CB8DEE, 0x0C7CC1148, 0x99D0A806, 0x9824942D, + 0x34E6D086, 0x645FF34B, 0x0EE935627, 0x0E315795E, 0x6820A347, + 0x0BCE4C903, 0x771EB169, 0x10EB5840, 0x0A2DE90B1, 0x0F050EDFB, + 0x0A6F7E269, 0x0E2BB2882, 0x0F2C45F7F, 0x60D8F802, 0x2BE45204, + 0x58D8230F, 0x0A9B81AAE, 0x0ADF0C323, 0x0F9E9AA57, 0x0B4D9C317, + 0x59DF097C, 0x0B84F66AB, 0x3E4BD3BF, 0x7793C004, 0x0D19DB666, + 0x0A3E93B29, 0x6D8FF6DA, 0x621A1385, 0x2398E928, 0x0CEF2DA68, + 0x377A7B83, 0x75C3F586, 0x0A1B5ACC0, 0x0DAE01E76, 0x8C110DD8, + 0x0F223E034, 0x0DA18476A, 0x0A9691EA0, 0x9E999436, 0x5B108CFC, + 0x0A12743A3, 0x5B803372, 0x0DE98383A, 0x6F9FF28C, 0x5876A29, + 0x515BF8BA, 0x0FCD264C2, 0x30244BD0, 0x591CC4F9, 0x2D6E4485, + 0x0EA4CBFE9, 0x0DE3410F6, 0x2D0C9B4F, 0x0CF703120, 0x0D84B340D, + 0x0FCA4FB69, 0x52BB77A9, 0x58551718, 0x3854EACC, 0x498A04D8, + 0x0D9CF22C3, 0x2A519139, 0x0BA2C4B01, 0x0C73B642F, 0x132DA49B, + 0x0E5DB7691, 0x50D800CA, 0x0B74A949B, 0x91F9476D, 0x6AA6DF6D, + 0x2A9EF385, 0x9A8F4D8A, 0x249993B7, 0x0DBA8275A, 0x0BB024BCD, + 0x311C89A8, 0x0DEB25235, 0x9816E524, 0x0B1C97280, 0x7C487FE2, + 0x0E288CE5, 0x4265F2D9, 0x0F811BC, 0x0BEA7AA66, 0x46218A03, + 0x0BA4A69C6, 0x0D6D411DC, 0x760FC39F, 0x5802D60D, 0x22BAA178, + 0x0A7E29B7E, 0x6694C13C, 0x536F38BF, 0x0DBEA34BB, 0x22E71880, + 0x8F8CDF29, 0x8A4EBA17, 0x844EFA9E, 0x38E931FD, 0x318A9494, + 0x8DC3A451, 0x9D0E6C, 0x1C2CCF54, 0x0CF669BE9, 0x2D3580EB, + 0x6FCAC7B2, 0x3C351B20, 0x2832EDD5, 0x7B4616A1, 0x330BBE3F, + 0x4CC87D40, 0x3E45C145, 0x0C8DE7071, 0x0ECD5CE1E, 0x3BEDA0CF, + 0x52349266, 0x0A520D698, 0x7BDD0E9D, 0x3AE66C2C, 0x0E5D317A6, + 0x0E371D192, 0x218D849, 0x0BB3909F2, 0x0B8374BB1, 0x93782B1C, + 0x0E1BBC4EF, 0x6FACE200, 0x0CBB56775, 0x618ED34, 0x0B93BAC9B, + 0x46429E72, 0x60E3E21D, 0x0CE765F16, 0x6B4CA99B, 0x724228A4, + 0x0F8967718, 0x0BAF90A40, 0x19E5147C, 0x6330A735, 0x54E21D12, + 0x0DD44B86F, 0x2339850B, 0x0CBD18600, 0x751C0FF9, 0x863C719F, + 0x2BBED654, 0x9B2B6C24, 0x9CD9C6F8, 0x48077F0D, 0x112920A5, + 0x38143FD, 0x49EFF97E, 0x0F30A6A37, 0x0F66FBB8B, 0x745A3527, + 0x3E73A338, 0x98EAFBDA, 0x3CC541D3, 0x0A179A981, 0x7CB8FC11, + 0x888B3CF2, 0x82A08B89, 0x78E54927, 0x44567D38, 0x541276BD, + 0x0ACB5B2FC, 0x2DE2FE75, 0x171FDF19, 0x0CDE631B7, 0x0D8F80EB7, + 0x2FF5F10A, 0x0B52A1B61, 0x4AA369D, 0x69A03987, 0x2FE38BC2, + 0x21CB6BFE, 0x4A448F6D, 0x0FF200B7B, 0x20B275BA, 0x9A98471B, + 0x30D88464, 0x7C2F9FDE, 0x30A5984E, 0x0A2656827, 0x88CC9FFE, + 0x0FFC04C3E, 0x0D3431D1D, 0x0FA47C7CF, 0x61C4A8F9, 0x0EC09AB68, + 0x0B8506D03, 0x0A3949EFE, 0x0EA7A951, 0x0E17F9769, 0x0D0D0301D, + 0x0DDE164E3, 0x1E98EA44, 0x0C1D6278D, 0x4D0B51C8, 0x2A01D4EA, + 0x64FCF54E, 0x0AC05B562, 0x0A083F8A1, 0x4C0BE6C1, 0x0F079922D, + 0x340D9B5, 0x79FE8E84, 0x4254D453, 0x13F4CADD, 0x68FB6E93, + 0x0CA82BB90, 0x4D6F15CF, 0x5E91E79C, 0x0BBED8B48, 0x0C3526A21, + 0x0F03464A1, 0x0A2B772E6, 0x1E098962, 0x0D6F5C2D4, 0x0EBB5B977, + 0x0F0083279, 0x0F18503AE, 0x0B32F2E86, 0x3E494D3D, 0x996C3351, + 0x0D5D6D039, 0x4C055554, 0x2B859920, 0x2E06BBAC, 0x0ABB10A50, + 0x0D2BC219B, 0x333C568D, 0x813B5606, 0x950B097F, 0x0B5D9BCF8, + 0x17857E31, 0x0A1B2CA1D, 0x0F3196794, 0x0A7228D48, 0x0D7B549FA, + 0x0E04D22EE, 0x664FFD9C, 0x999B3EA8, 0x0B6603014, 0x0D034A7B5, + 0x0D064E4E3, 0x0BB88B875, 0x335BEDED, 0x41CAE1EF, 0x514B74F8, + 0x7E70244C, 0x10BC7730, 0x43B59A5A, 0x4B3A47A6, 0x9417EB0A, + 0x4ED709CC, 0x29DAD9F2, 0x5DA736FB, 0x0EE82B7CC, 0x2E421BED, + 0x835DEAF5, 0x6A455943, 0x0BCF76EEF, 0x31D06600, 0x22A354E0, + 0x930A0A0D, 0x70F93C10, 0x1799E3B3, 0x1753E06F, 0x372AE224, + 0x0BB4F890D, 0x0E2EFCCF2, 0x0B350989F, 0x0F91CB996, 0x8DFDFE01, + 0x0D36998EA, 0x87C0C4AE, 0x0BA94AAAF, 0x1747844A, 0x6BDC0209, + 0x6507ED19, 0x9A860CFE, 0x0CBB44485, 0x6B5C02FA, 0x5CCBDE9C, + 0x0FA29784E, 0x5A09A68F, 0x0D33ED2AC, 0x0BEF09D34, 0x7BF0C8AD, + 0x0B5495585, 0x0E618E94C, 0x1D9D7520, 0x0FF911568, 0x0BBA39C5, + 0x23BE0245, 0x4835EFDA, 0x0A601B80B, 0x0D0E27AEA, 0x4C451546, + 0x525DD221, 0x0D1754A64, 0x0B38583D2, 0x62035B3B, 0x8BFB2AF2, + 0x2262A381, 0x0A6A8FB9A, 0x0A68C4E51, 0x84343E89, 0x797DDDAC, + 0x0D990CDA0, 0x98B6A5F6, 0x0E6D9764, 0x0F7BB5075, 0x0BEC2207F, + 0x0FB955BD6, 0x3A4AFF3F, 0x0FE5096A7, 0x5035E15, 0x0CE7EA8DE, + 0x59B07E18, 0x2EB38850, 0x0A0583180, 0x5307053B, 0x0FCC65D2B, + 0x68973FBD, 0x0C007801B, 0x0B042B5B, 0x0F4EF27F5, 0x0CDF2137B, + 0x0D5947584, 0x0B68A14EA, 0x52D0A235, 0x0BFF99E56, 0x90C47999, + 0x57EFF8D5, 0x6850D9E5, 0x0DF21B95C, 0x0E49C3575, 0x2DC85049, + 0x0C5921445, 0x0C1F7DDA, 0x619276, 0x0BAE8D5B4, 0x3BFBDDD0, + 0x69E8425D, 0x5598B93A, 0x0BF6680C2, 0x0DC31FD43, 0x57B0A2B1, + 0x9506139C, 0x3D978B60, 0x0F8197C9C, 0x75EE75E5, 0x0B1B149BB, + 0x750F6EBB, 0x20D8A317, 0x0A655D544, 0x0D9DD44F2, 0x0E7A3E241, + 0x24D2FB32, 0x0ADC1B5B, 0x7E0E2DE0, 0x5569E09E, 0x17AD4FA9, + 0x3B6E0F9, 0x530B6C60, 0x0C1B5A1BF, 0x494DA57A, 0x3159FC29, + 0x47D9AC91, 0x6A1C9FD2, 0x4BD848E1, 0x757A8A39, 0x8BBBD5CE, + 0x0D1749243, 0x0EEB3C15C, 0x0F10EE0B6, 0x91370FB6, 0x0B9D173BF, + 0x4482D8A8, 0x54A9A6D, 0x0A13C524, 0x21897B33, 0x9C2B96C1, + 0x52A28F6A, 0x0E6529F37, 0x4C3023CD, 0x88D345E4, 0x0B9CDD9FB, + 0x573B854A, 0x0B99B25F9, 0x0DADE6D8F, 0x5CBED0AD, 0x0CD52A1FC, + 0x2AE07964, 0x0A1F2D87F, 0x9BAC0F4D, 0x0FA5C5D29, 0x9F5358FB, + 0x30F48EB0, 0x180A6DE7, 0x0CF5F60ED, 0x5B8A3BEC, 0x1708D95F, + 0x0B38E03C9, 0x7C9E94A7, 0x0DD59DBA3, 0x2694410A, 0x8D2D2C80, + 0x739F23F3, 0x0E8D532CD, 0x703C906E, 0x71C7FD9, 0x642874AD, + 0x7B547858, 0x45E6CE87, 0x0C3D0D6E0, 0x413D31F4, 0x0D86A266F, + 0x36B74492, 0x0A2FE49E4, 0x3A234324, 0x7FECF581, 0x14137C0E, + 0x0C39A3370, 0x0C15FD3D9, 0x33F0DF3B, 0x0F0A03FB5, 0x89DB2A52, + 0x87B64AF2, 0x0F3CA1B88, 0x1C439586, 0x94340A96, 0x7C2E518B, + 0x1102497, 0x2720C7BE, 0x0C65BEA8A, 0x0D10AD101, 0x0DE96B2D4, + 0x0E39D5FD9, 0x3E4524BB, 0x0F9D1F3F1, 0x4B72BEEC, 0x625F2595, + 0x5F2751F6, 0x0A3462037, 0x49F782CD, 0x0F34A23EE, 0x0CA764A48, + 0x0C07001F2, 0x19BD76A3, 0x2984A122, 0x5FE727FD, 0x82937E7E, + 0x3B9652DB, 0x0D47228AD, 0x3F6F42A3, 0x5A35C278, 0x71991222, + 0x4B8824D, 0x0CB423307, 0x0F81935BD, 0x0BC1BEC66, 0x0C3BB8FE, + 0x0A5D7D436, 0x4E467F6A, 0x5DB05AD3, 0x7C2212FE, 0x0ADE13E7C, + 0x8CFF8BDC, 0x0D42D16D6, 0x25D019C9, 0x557CA68, 0x24CB80AF, + 0x0E4A7181D, 0x18EB971D, 0x0C6C10C5, 0x0C76EC9C2, 0x8C749993, + 0x0A75794F6, 0x6696EBA0, 0x65ED0D31, 0x0E291267, 0x613A5A92, + 0x0F18A7148, 0x2F8D3659, 0x0EB9A3D05, 0x18F9716D, 0x0D03DFE48, + 0x98D36ED7, 0x0E4DC111B, 0x0DE38A345, 0x63E3296E, 0x4E851C88, + 0x0FA44C995, 0x2DDF817, 0x4BF3CCC7, 0x45A7EA89, 0x6D68DDA0, + 0x170CBA1E, 0x6A20FF9F, 0x0AC7DC137, 0x0C01C07A9, 0x0EC2C71DA, + 0x0E0611D85, 0x0F48ECA2F, 0x0B2763E5E, 0x94E0E606, 0x0EE9BD44, + 0x0CF9E6E4E, 0x45CABDAB, 0x5F0D239F, 0x962EB8EA, 0x2EB257B2, + 0x0B9AEFCBD, 0x0DED970E3, 0x58E529C3, 0x41106BB6, 0x91F6B401, + 0x0E2A9574F, 0x7603675E, 0x7A3BD6F8, 0x8CB7DE25, 0x7C21A09F, + 0x4FBD0C86, 0x8AFA0055, 0x0AD47B415, 0x0FD2755D0, 0x8688F049, + 0x615192EA, 0x333AAEFE, 0x0F6E0BE20, 0x0FC192DF3, 0x30847514, + 0x0A065854D, 0x38B0650C, 0x0D0641C13, 0x6A1AD270, 0x0B4DE32B0, + 0x0D53D1250, 0x659F5674, 0x0BDD811DB, 0x72F9EE13, 0x1C6CCFE9, + 0x5C40B324, 0x1DC1DD73, 0x194C33A3, 0x9F61E415, 0x94FA4D70, + 0x0B91B1E93, 0x2BABB8CE, 0x3082DA51, 0x30C37DE4, 0x26CFCD9, + 0x6A2B783F, 0x0DF747B59, 0x91D0DB4F, 0x0AA78E222, 0x0D422ABE5, + 0x0FC1BCF2B, 0x569642BC, 0x0A244778C, 0x0AD24CBED, 0x1A9D2003, + 0x62CAC878, 0x1A15A672, 0x75078FC2, 0x95EF65F, 0x0D660C912, + 0x84709672, 0x0ECDFF213, 0x0DA041BFB, 0x118FDC55, 0x901AB16A, + 0x14012CCC, 0x0DE7497D4, 0x0B6CADB4F, 0x3018A175, 0x2E03B61B, + 0x0A6D2B429, 0x0A6C8DF4D, 0x95B04DF1, 0x0BBB94A6B, 0x484FA74, + 0x7C40DC, 0x2F66DF7C, 0x7C38DF6B, 0x72F3375, 0x271C98C8, + 0x0B0FFC0F1, 0x71D6B007, 0x1B76726, 0x0BC1DC01F, 0x880996E, + 0x0DD28356D, 0x8442DFC7, 0x9E34D02E, 0x692E5351, 0x3F012708, + 0x5F3525D2, 0x0F0552282, 0x438E1735, 0x59798087, 0x0A5340107, + 0x12B74FE8, 0x48654EF9, 0x2BE277D7, 0x0A5257D60, 0x0A6CE306C, + 0x69B9A1B8, 0x0F8D38723, 0x0F22CE11D, 0x8C4EDD5C, 0x0D6CEF9D0, + 0x402068DA, 0x5CAFB7B9, 0x0E52DB045, 0x1287FDF, 0x0C3DF13A8, + 0x0F453C7F1, 0x13A142F3, 0x9A8E9BC0, 0x8364C17A, 0x0BFD1BC3, + 0x0B61D6B74, 0x9305F892, 0x0C144EC7E, 0x32D1FB6B, 0x0AF574515, + 0x1CD07EB1, 0x0FE554C1F, 0x3A34F067, 0x1F442963, 0x0A77555B9, + 0x0FAABDA0D, 0x34CDC474, 0x6818B02B, 0x0E5BAE889, 0x0B89CCF32, + 0x727F808E, 0x2B4AB279, 0x0C6A2DF3C, 0x77BCA5BC, 0x836F6CF2, + 0x478E499B, 0x7C742231, 0x0B9E01319, 0x3904111E, 0x0DFD8CD1E, + 0x77B4DB03, 0x3F1E14F5, 0x0A6E139CF, 0x535FD9CF, 0x69277491, + 0x0ACAE03E, 0x1AEBEC01, 0x459644BA, 0x43D394F7, 0x5A7AF020, + 0x254874F1, 0x9533272D, 0x35FB2591, 0x0B202FE07, 0x9A5D591D, + 0x642BDDB5, 0x0B12551FE, 0x0D17701A3, 0x89CF6442, 0x13B3FD1F, + 0x67177F1A, 0x0B92F34DE, 0x43829F5C, 0x44406178, 0x49D55901, + 0x0ABBE0FE7, 0x599B53A8, 0x0D786210C, 0x87A4C812, 0x28F94B2A, + 0x9C8108A4, 0x0EE7C9769, 0x9309F5E9, 0x0F0F6E254, 0x1DD7870D, + 0x0E9555C5C, 0x1EC94963, 0x60A0C53, 0x2D82DADF, 0x698849F1, + 0x18EA6D9C, 0x0A9C84153, 0x5EA94958, 0x4FC87676, 0x0B3AF4AF3, + 0x5B073CC1, 0x7FAF5EF4, 0x0BD0B3D79, 0x5F9F0904, 0x0DDDCF64A, + 0x0A239E171, 0x138637C4, 0x0CE7D13AC, 0x2F9BA6DB, 0x192EDCCB, + 0x0F3AE3C67, 0x0F0501108, 0x94D9C7A2, 0x74B09740, 0x3D3867AD, + 0x0F75CEB74, 0x8B6C110B, 0x83279C4C, 0x12190E24, 0x5427CC8F, + 0x0D6687DC4, 0x5936B3AC, 0x0D385CD99, 0x0B7741C35, 0x762244B9, + 0x46C3E55F, 0x22F37B19, 0x12498383, 0x0AC30E016, 0x0DBF27C9F, + 0x0DF1632F0, 0x95ECECD6, 0x0F966084B, 0x0E92901EC, 0x2CE44BAD, + 0x0B2E17ECB, 0x1DDAB702, 0x810D3B01, 0x68925E1B, 0x1AEDA43F, + 0x1BE0252A, 0x0F48336DB, 0x36964547, 0x0BD15054F, 0x320DCCEF, + 0x0D3AF39B8, 0x77A21980, 0x0CC9E8B58, 0x0E43763BE, 0x0F0F6CD14, + 0x4BAE3351, 0x0BA0D60F7, 0x0F272E545, 0x5AFEBBAD, 0x13EE2B88, + 0x3628EB09, 0x5C138A6F, 0x64AC0D7F, 0x70D7DB32, 0x31F2D6AB, + 0x65B0CB6B, 0x9D250CC8, 0x441D5B9B, 0x0DDB20A3A, 0x8C1E61A6, + 0x0D8CD4005, 0x0AFB70552, 0x0AAECB053, 0x937046CB, 0x254A73F2, + 0x12D87222, 0x4B6532D3, 0x7BFDB1C9, 0x0D480AC8C, 0x0FF67B19, + 0x0AE2237D7, 0x855A1DCC, 0x78963711, 0x86C63983, 0x769A9BC, + 0x315B4242, 0x0E1EE9BFD, 0x993D04EF, 0x0C4BDB01F, 0x42151AD6, + 0x2030A10E, 0x0A7907528, 0x99E5B7DD, 0x0B7DEDC77, 0x863F5341, + 0x5334673C, 0x75E46613, 0x0D24A0351, 0x0A540F9D2, 0x7EDDF177, + 0x8A01A61E, 0x142E47D2, 0x4C9A1D3E, 0x47826D68, 0x48C0A09C, + 0x3EA0A1A5, 0x8DF08744, 0x115674DA, 0x60E7BC68, 0x50F44AB9, + 0x0BA2740DE, 0x7DCFDEDB, 0x0C579A5A0, 0x8DC0BC3B, 0x6266924B, + 0x6AA3C5B8, 0x0A6BC43A1, 0x74D8AF96, 0x58100608, 0x0FBC582FD, + 0x7436BE08, 0x0C7511C79, 0x0ABCA64D1, 0x916BAD79, 0x0E1AB81B3, + 0x87813CD0, 0x0AE7AB5A4, 0x0CB0A2037, 0x0DE1F33BD, 0x0F5FC88C8, + 0x0F14543BD, 0x8C56F484, 0x9BD9BF84, 0x9198BACF, 0x458F9699, + 0x0F54682EF, 0x8A5E4CA6, 0x1D69C991, 0x0BBFF78F7, 0x650E6243, + 0x5B7144FE, 0x9BC4F0FB, 0x0A477F1D1, 0x7F226E8E, 0x1851AA, + 0x4A3FA73A, 0x911F4A66, 0x2438BE1D, 0x0AA995A08, 0x0ABAEA8BC, + 0x535A0E33, 0x7345AD7D, 0x0C97889B3, 0x8127EA2D, 0x0FBCD03F4, + 0x0CF7FD27A, 0x0F794789, 0x0CCFEA87A, 0x0DB5F34A7, 0x0D8590723, + 0x6CA33DA8, 0x0CCC85AD0, 0x8233EA88, 0x708864C2, 0x123B546B, + 0x35BB99D, 0x0C3AEAC15, 0x0B70343E7, 0x71C4B570, 0x32CBBF8D, + 0x0AD76460A, 0x0EFE3D5E, 0x3B04C995, 0x5A6DA38D, 0x9370BF65, + 0x17ED2B33, 0x610139F5, 0x0BCD7E0CB, 0x5C16063, 0x0B28725B4, + 0x13FFEEEF, 0x0D8DD2EB2, 0x0D4CDB27F, 0x0BF856E, 0x0C382111E, + 0x709586F1, 0x113A8079, 0x63CBE42D, 0x21510A61, 0x85532275, + 0x0DECD04C, 0x7B201AFF, 0x1F7084D3, 0x58AC7969, 0x5909ED35, + 0x29744131, 0x0ED2567D3, 0x6A76463C, 0x0C6F660B2, 0x8EB9B250, + 0x0FEF3DBFC, 0x7CC5819A, 0x6557F17F, 0x0C270529, 0x0A14B2D, + 0x8EEF6370, 0x8712A99A, 0x443215C8, 0x0E6325F82, 0x0E28866EC, + 0x0BE4CD240, 0x158EF87B, 0x0E1EDFF57, 0x0FA65417A, 0x0D969F4ED, + 0x0A2320ACF, 0x6256554B, 0x949CEFC7, 0x0EB0FD95E, 0x4B51E291, + 0x1832CB39, 0x0B481A8C0, 0x43238991, 0x0B2615ACD, 0x0F7860840, + 0x9AAAE693, 0x74C94EC3, 0x0B7188BD2, 0x2E98F6BC, 0x0C6EB60AC, + 0x4E67B070, 0x7B69CD2A, 0x2FEBBF49, 0x0FA5911B8, 0x0E2A17955, + 0x5F8ABBA5, 0x0AA46CAC6, 0x374A30A5, 0x805DB171, 0x5EF2B4F, + 0x91ADC14F, 0x0BE52389E, 0x0BBC0A1FE, 0x4D4F3974, 0x14658D40, + 0x1047E212, 0x642ED37B, 0x599E3CA2, 0x0A5F35738, 0x0EE3D25AE, + 0x8A4D10A5, 0x8910CEA6, 0x0F51C8813, 0x58893C5D, 0x7F026078, + 0x7E1BC88C, 0x0F4E5C9EE, 0x90C19F4E, 0x0D4710C32, 0x197542A3, + 0x0D4940325, 0x17B907ED, 0x5B009E4F, 0x7C119676, 0x5AD5F57, + 0x0AE866DE7, 0x2354DE8C, 0x7255DD2, 0x39F44660, 0x567E0A2A, + 0x7F51D6E8, 0x5C266FC6, 0x6070615D, 0x4F3558E2, 0x0FE1DCE9D, + 0x5BC9E69D, 0x0AC6598AB, 0x1C810F7C, 0x731C4F2B, 0x25021BE6, + 0x8E5916E7, 0x7C7628A5, 0x0EEF5234C, 0x1B08A76B, 0x0B60F43ED, + 0x7169DC4B, 0x0C08A5300, 0x0DF4E623C, 0x168DC7DC, 0x3CF0A59A, + 0x7A032781, 0x518B66A5, 0x0DE198D10, 0x5DDF3BFF, 0x0EDC3284F, + 0x92B20C32, 0x8037BC26, 0x974C9628, 0x2A702024, 0x4F9ECB1, + 0x0ADACBFFB, 0x0E98BF100, 0x82EE1700, 0x47D5E02E, 0x557D3DAC, + 0x9531C5B6, 0x8663571E, 0x3DFB01F8, 0x0AAEF2096, 0x1C14C9B7, + 0x73468FB, 0x660A79A, 0x1C879256, 0x3F48F8AE, 0x17051455, + 0x3396CE2, 0x5D0BFAC9, 0x0FF238A8A, 0x5BC6328, 0x0D5FA29DD, + 0x5D7E020C, 0x9C39F877, 0x647D9FB2, 0x5E5AF7D8, 0x4E27937C, + 0x985FFBE2, 0x4AF506F, 0x0BE4C2E5F, 0x0A18AD6B6, 0x0B4AB8D79, + 0x0F5F43F1D, 0x56076840, 0x66C3597, 0x0F171E628, 0x8A3476B9, + 0x0C8FE7E88, 0x6ED2573C, 0x90467E1C, 0x53923D7F, 0x0F4E78883, + 0x0C022602, 0x120011C2, 0x21741EEC, 0x0FBB7E0C0, 0x4F7FCA86, + 0x37B395C8, 0x57EE1BE, 0x3FA31F0A, 0x0E810AEA6, 0x1B5441A, + 0x509690F2, 0x601F1E6F, 0x0C9B87A7D, 0x0B19A98E5, 0x93E173C4, + 0x40E2F53C, 0x23BE1769, 0x0C8384996, 0x0A0C314B1, 0x0FEDFFEFD, + 0x66A6AE07, 0x7A250DB, 0x86E23B77, 0x0FD4DD180, 0x4436A734, + 0x6F30E7A0, 0x9723F213, 0x0DE9F49D2, 0x0AD71AD0D, 0x40748512, + 0x65AA81C1, 0x808B7D40, 0x0D39DA8F0, 0x0FC45E59F, 0x0BFDD71FF, + 0x606C656, 0x2640C078, 0x64B8FFF3, 0x0B8608C89, 0x0D145BFE3, + 0x581E6083, 0x79200CFB, 0x0A01ADA5C, 0x80BD3FF2, 0x5A3B2F2E, + 0x7C1585E4, 0x82DA5B7, 0x0F62360D1, 0x5CDE18D7, 0x0ED69241B, + 0x0C0017514, 0x546C7A0C, 0x0D08C4219, 0x8F33E14E, 0x0DB391432, + 0x0F9CC2871, 0x670817D2, 0x61C7F569, 0x0A9BB8A0E, 0x88BA410E, + 0x10584120, 0x0A5BBD99A, 0x0BCAB21E4, 0x0E1E9DE2D, 0x0FFC2A75E, + 0x0DCE3464C, 0x0E36F6132, 0x264F5A5E, 0x0A3CA732A, 0x0C655362E, + 0x30AC14B4, 0x0B7214C6C, 0x0AE340E62, 0x6665E02C, 0x0F4464268, + 0x35D48D66, 0x10072121, 0x0FBA8BF74, 0x0C163348A, 0x821D3897, + 0x0FB8895C5, 0x7F48C72, 0x66687498, 0x0BEF1A48C, 0x0DF3A93EC, + 0x4B5D3ED2, 0x0F6F9CA4E, 0x4A856B14, 0x6EE38471, 0x0C8381084, + 0x0C1FC40AA, 0x0C84D653A, 0x99891173, 0x0BF1B79B2, 0x57951EE8, + 0x1800AD4C, 0x906F234D, 0x0B0DB34CB, 0x8B2AEE86, 0x5B919AD7, + 0x0C51CE39E, 0x5E8B3A7B, 0x6D607841, 0x0F336C5A7, 0x0E854B941, + 0x0C882C2AF, 0x4E1CC615, 0x7F6409CB, 0x0EB1C5055, 0x30554795, + 0x0BF82203F, 0x0E3D07D8E, 0x0FFBA9035, 0x17D78099, 0x91F70F3D, + 0x3D6F7B7D, 0x94B1A180, 0x3D206868, 0x0D6225DCB, 0x0F0769B67, + 0x5BC8EE11, 0x0A58238EF, 0x0DDE613E7, 0x9C5AB757, 0x47021F07, + 0x8E94675C, 0x386879CE, 0x23CFE89B, 0x86A61CBD, 0x7A2BB01A, + 0x0B90F18FC, 0x0A5CC87C0, 0x8C380FD2, 0x2A5A0BD9, 0x6F7DBA2E, + 0x83842C93, 0x87D6222, 0x9F79B183, 0x0AD9A6762, 0x5F6DB120, + 0x0EB7ABCC9, 0x191A1B47, 0x38969D5, 0x183C2FB6, 0x67750726, + 0x1B140291, 0x41B04803, 0x0D2E6FEE0, 0x0EDF16DD5, 0x647B600E, + 0x7AB3CDA9, 0x0EBA0B86B, 0x2DB555B2, 0x0F6A56DAB, 0x0FE7902C5, + 0x6DF3666, 0x19C569DC, 0x1226A296, 0x5E243094, 0x358911C, + 0x0E16692AF, 0x38D4B83B, 0x6B1CDF92, 0x4FF211B, 0x0F71DF9C7, + 0x2BC3A847, 0x3604D87D, 0x690B8030, 0x0CAF0703, 0x0EA48ACA8, + 0x11C12551, 0x0D3EF8667, 0x1021657F, 0x0B8F93C8A, 0x8B7A0E4B, + 0x23614E0F, 0x35B9FC98, 0x14AA115A, 0x76921DEA, 0x7B572FB3, + 0x0EBFBF5EB, 0x0BF7024C5, 0x0E4AE1AE8, 0x3B04C321, 0x0E4ABB954, + 0x0BCA1AFB9, 0x24B40F44, 0x5DDE265, 0x11D0F1F2, 0x4BD12962, + 0x0C9C9443B, 0x0B899A6CD, 0x0A2AE8521, 0x0ECD64D2D, 0x0A3524349, + 0x782C68E7, 0x8CBA07E, 0x61C413C7, 0x0C2F3D42C, 0x0A3CBC17E, + 0x0F5EAAAE6, 0x0ABF0B51E, 0x799200E0, 0x0DCEA899F, 0x5A114B76, + 0x0BF0AA5E, 0x585311A3, 0x33FDA99, 0x68866E8B, 0x298ADF4, + 0x309C90F1, 0x39C00CF7, 0x8ECD3AC1, 0x50FEB68D, 0x12124588, + 0x0E0A0BA87, 0x80AB1AF7, 0x0F776FE17, 0x50993965, 0x9855BB55, + 0x2D25B549, 0x3995FEBE, 0x7957B6C3, 0x439429B0, 0x0C780F514, + 0x953170EF, 0x5FB14422, 0x525C23, 0x0BE4104F5, 0x0CC5E4B58, + 0x134BAC3D, 0x33C3EE7C, 0x0C42E49C9, 0x0E172CAE5, 0x0E70BF911, + 0x7A5EB8C8, 0x0C94A6EAD, 0x130165C3, 0x6B1671DC, 0x0B8D7D354, + 0x0FFDC5CFE, 0x0E5E0D65F, 0x6FD09F1A, 0x0D2297AC, 0x0D7683C59, + 0x16251466, 0x6DF4C89, 0x0DA759E9E, 0x1B3789B, 0x0A8245AC6, + 0x80277F26, 0x0C145C137, 0x6FC2B7E2, 0x0DC7220AB, 0x6ECE842D, + 0x0A24718C3, 0x51DBE389, 0x32E51F83, 0x0A139E21B, 0x9E70FDD1, + 0x1981242E, 0x6D9250F9, 0x2A0D62AE, 0x17F5092C, 0x777BE5AE, + 0x8CCCEDFC, 0x5A2E0EE3, 0x0AD4B14E2, 0x5DCCCE26, 0x0D12A6DB9, + 0x0C2C12EF6, 0x41273940, 0x0FCBBC8F3, 0x0BD818B9B, 0x332D4C64, + 0x0F57DCFD2, 0x0C4CCFCB2, 0x10E53F51, 0x0BE1530EB, 0x29846F66, + 0x67C4D240, 0x0CDABC3C7, 0x0B55EE388, 0x7EAFF409, 0x0D5A9F5BB, + 0x33688E2A, 0x0A72FAF77, 0x0D6B47508, 0x40BE4D7E, 0x0C5F25BE7, + 0x67EA1D35, 0x51884BF0, 0x198A0227, 0x425E22AC, 0x537F581, + 0x5060118D, 0x10D17F93, 0x0AC001C65, 0x0D1F94055, 0x75B19EED, + 0x16976BE0, 0x436DC33F, 0x5E5648F0, 0x0A0300C5D, 0x5D23B169, + 0x8A7ACEA8, 0x7CB295CF, 0x0F2D1B369, 0x56FA78CC, 0x403D384C, + 0x3CB3F1AE, 0x0CDCB2DE0, 0x0B2DF2AE7, 0x670B3918, 0x0EF3E648B, + 0x0D19153CD, 0x61D871D5, 0x40774A39, 0x267837A2, 0x0DFDA3E7E, + 0x942B34F4, 0x4C59241D, 0x0B2C5F571, 0x1999467F, 0x0BD5C9DE2, + 0x4CC3C170, 0x0A5CA64B4, 0x0DF04059F, 0x8D2F157A, 0x400C591F, + 0x4E6E8F69, 0x0D29054E9, 0x0F4AB45DA, 0x6BC86557, 0x40D3BFCC, + 0x0D4F24CAB, 0x24151660, 0x4CCD9E86, 0x4A617B5B, 0x51F4571, + 0x8EF0B1A7, 0x0A52FFD58, 0x7FBB8FD2, 0x0C64BD90A, 0x0E2027F8E, + 0x7744BCBA, 0x2EC7022F, 0x0B9EDE081, 0x11512930, 0x29F53DA, + 0x0EAAA1DAE, 0x0BEB87424, 0x4D2098EB, 0x0C9187B23, 0x83C86ACD, + 0x0F6A3EE80, 0x7F6F55D, 0x8BC12D45, 0x0AC7B149, 0x0C2E1E761, + 0x0EF97A861, 0x4AF1A22A, 0x0D08BFB1D, 0x0C4E837D6, 0x0F7085C16, + 0x473D5400, 0x663A9289, 0x0DD6DF92A, 0x508FF9D7, 0x379FB35, + 0x9D39FF08, 0x2C6583EA, 0x6AAFA743, 0x3FBA9075, 0x862C0A57, + 0x140571E5, 0x0F62FD136, 0x0FB554CAE, 0x73F9BC74, 0x35C19A26, + 0x0E7121FCC, 0x79E0A80B, 0x0F3C55F9C, 0x715018FC, 0x6B9F7964, + 0x3A305EFB, 0x0D8F47B4B, 0x0E8A544F1, 0x0F65A0999, 0x0FF59662A, + 0x342CDA3E, 0x0FBF7B6D5, 0x3708394A, 0x0C9B0F986, 0x57518473, + 0x4BB948B3, 0x1FAEB093, 0x0D9CA903A, 0x0D18AC327, 0x0BAA113DA, + 0x0E09258D0, 0x0AF7DE4B5, 0x75391FD6, 0x69A46FD5, 0x0EB375BA0, + 0x0DDEEFA3, 0x5306623D, 0x0B7F7F671, 0x0F06420DF, 0x0F440E9F2, + 0x0BCD4945A, 0x470F81BD, 0x0E11D51A9, 0x0A53B4BCE, 0x41C9FE6A, + 0x0F9A02804, 0x0EFA7D75D, 0x0A1A1CEA4, 0x0B3492AE9, 0x0EFA146D4, + 0x8A87DB97, 0x0A8896C21, 0x23FAE194, 0x884572FA, 0x6382C634, + 0x0BD475C32, 0x0E2C12B6A, 0x68038582, 0x6C9D4150, 0x1F711905, + 0x82C251A5, 0x6D8E9ABB, 0x0D61E354A, 0x50DB5B06, 0x0D263DDC4, + 0x0BADC0830, 0x1189CBBE, 0x119A1CE3, 0x0E4499784, 0x0AF2268AF, + 0x0CFA26C89, 0x63049387, 0x0A5889E1, 0x0EED59544, 0x170C1C8, + 0x86AE3B21, 0x0D4B6FB19, 0x56AAA63E, 0x0D737B2D7, 0x0FC6BCC1D, + 0x12C776A8, 0x0A96F528, 0x0C27D6A55, 0x87523F29, 0x0D731C44C, + 0x6BCD1AD0, 0x7505511E, 0x26B8CD30, 0x73D9EE01, 0x19C6F042, + 0x0DED50F4F, 0x1A30EF61, 0x77E43C05, 0x0F5348DCD, 0x31338F45, + 0x0E6925F28, 0x0B4B637D4, 0x200D4DFC, 0x0DDA3F89D, 0x4AF01533, + 0x3BF5A92C, 0x0FC87C89D, 0x93EAB534, 0x46A14A6E, 0x5D859A09, + 0x2915D6BD, 0x450D6D27, 0x1C3A7706, 0x0AB8C54A9, 0x896D90A8, + 0x24510AD3, 0x4D8E5668, 0x0F76F5F89, 0x3B8351EC, 0x0A03BB6D5, + 0x9AB4DF41, 0x50D28564, 0x0A28EB056, 0x6B91D80A, 0x3014A7F, + 0x99BCE3A, 0x5F0287F3, 0x75561A8F, 0x0CB09134E, 0x0B1EE8446, + 0x5293EE10, 0x0F0D165C1, 0x71A1F01B, 0x1B312F05, 0x9C384039, + 0x4D86E23D, 0x0B7DFDB94, 0x57099835, 0x9E24143C, 0x3C3AFBE0, + 0x9E170EA5, 0x0B55BC9D2, 0x0FACD4326, 0x0AFF257C7, 0x67DF017B, + 0x0C84B0A1A, 0x90E8E844, 0x0D6F4E04F, 0x930A6D83, 0x603FE58A, + 0x816A5A22, 0x23C3BE15, 0x0E2B04B6B, 0x8EDB22DE, 0x2F88338E, + 0x46265CF6, 0x5623D51F, 0x0A305CB13, 0x3AB74B95, 0x3120620F, + 0x30FA83CC, 0x31E22867, 0x83ABBC84, 0x15F8B9BD, 0x0F10A0EE0, + 0x7D6C357, 0x2C5BDFE7, 0x62328A9E, 0x5A676F06, 0x3787649F, + 0x95FA4D8C, 0x0CA933D8D, 0x6B66DF2D, 0x13DA153D, 0x5FFFDE80, + 0x3D217DA8, 0x679DD881, 0x2AF31E6D, 0x6C1DAC10, 0x0ED1F324C, + 0x0CDE01170, 0x4F3808AC, 0x0DC4A10C9, 0x4B148416, 0x5F4485A6, + 0x914D9DB8, 0x10BBA277, 0x7C3DEE4, 0x1E1F6C10, 0x4319E58E, + 0x0AAE53D28, 0x1233E7D1, 0x4B0540DB, 0x0F5BE2A6A, 0x8A7CF729, + 0x9FA88A3B, 0x66CCB875, 0x78A4F4CA, 0x0D1772C06, 0x1CA7EEC0, + 0x3288CF89, 0x0DD6E0D6A, 0x0E10A738E, 0x3DF67D3B, 0x0AE8EBD07, + 0x75027D48, 0x5AA9A6CC, 0x0F198E1CA, 0x1C74FB19, 0x0D1848EA0, + 0x1D0ADE0E, 0x69D401CB, 0x0FD0E432E, 0x0C25AC8F0, 0x4C2373E0, + 0x172D07D9, 0x11718CF1, 0x5929F5F4, 0x4727FF11, 0x0AC6A5CD2, + 0x5BF31152, 0x0E8D51DAA, 0x0AF8C5BAC, 0x188FA9D4, 0x1A294A7B, + 0x0FE84894E, 0x66079FFF, 0x8DE1D73A, 0x0D0E6F0DB, 0x6E9BC35E, + 0x8C8C2696, 0x7CE60FA2, 0x3E41FD1E, 0x47BE9396, 0x82528640, + 0x9561BAEA, 0x658FA831, 0x0DCD303F4, 0x0EACD9B08, 0x0C959812D, + 0x86646C41, 0x0BDFE5BB4, 0x0A4B17C3C, 0x4A114DCA, 0x219501BC, + 0x0BBA52554, 0x0D1F48369, 0x8910475C, 0x0F838604E, 0x0E66D2990, + 0x0D2CB495B, 0x361AD8C2, 0x0DA1C3E4, 0x913A7166, 0x49ACA621, + 0x4334A817, 0x9F65A1AC, 0x4D334513, 0x164AB406, 0x0E1A4A2BA, + 0x2F5AB512, 0x0E9BA2E13, 0x5B9BCC98, 0x80EDED46, 0x8094F7C3, + 0x7777F623, 0x78D387A3, 0x0D2D6F49A, 0x9169A0AC, 0x484DA641, + 0x0E69BD35, 0x0C7625FD2, 0x0A56D2AFB, 0x0EE6186A9, 0x0FF11889C, + 0x91D8164A, 0x3B754C1C, 0x38191FD9, 0x6BBF4062, 0x0A0BC43A1, + 0x159701BC, 0x391A3B8E, 0x0B3A98057, 0x0A6D350B2, 0x332781C8, + 0x4049E2C4, 0x78451F87, 0x9322E49C, 0x0D8BB456E, 0x0E0CA5EB8, + 0x9C46363E, 0x9AEFEABB, 0x8327071A, 0x0E90337E8, 0x3FA2200A, + 0x29BD89AB, 0x0F780BE79, 0x6B983611, 0x0C38E74B7, 0x0F3532B4B, + 0x331CA578, 0x0B96F652F, 0x0C87E0C54, 0x0E9B579B7, 0x798F3445, + 0x63AD0D80, 0x2F29002C, 0x3C285C4B, 0x49AE254C, 0x3AB7B680, + 0x1983AACD, 0x5C31FDA6, 0x668F6F3A, 0x503129EC, 0x0E8C0A304, + 0x0FA95C5A4, 0x0CF864DFD, 0x0F40070C2, 0x3C57C4DD, 0x8595D62, + 0x0C62936C1, 0x0B84BD33F, 0x0F7FB25A7, 0x0B7C3AE3C, 0x0CC4CE6F3, + 0x6E75DCDF, 0x39A220ED, 0x7756E1D1, 0x0A2055340, 0x25235360, + 0x63814E7D, 0x0FAD95FFD, 0x49A8B796, 0x303B42BE, 0x160D8863, + 0x3150D1DD, 0x1CA8C21, 0x1EE2F137, 0x34FBE6EE, 0x4C001FCE, + 0x4D408A4E, 0x0C27DEA47, 0x0DD3FC1A9, 0x0BC6E746D, 0x0EC20AACA, + 0x2CB0F5AC, 0x7310B462, 0x34603896, 0x0E0BF2583, 0x0AD611B62, + 0x96E19625, 0x0A2D91368, 0x6AB175A5, 0x0D5B4A6A7, 0x27698141, + 0x3A20F03F, 0x0ACB519D, 0x780F1FF7, 0x479BCE41, 0x6BB9F6B8, + 0x8322B418, 0x0A4174E10, 0x58AD15F3, 0x0E66990B0, 0x0D40CD604, + 0x0ABB03CEE, 0x0FA143064, 0x9D356544, 0x3F1E318D, 0x1E0033CF, + 0x0E8538E0, 0x0C1625FD1, 0x452C7C20, 0x0CE6CBB2F, 0x0B6F586F5, + 0x0C275A8F4, 0x0A74BB26B, 0x0CD989DCC, 0x5299B270, 0x5234A78A, + 0x66D00B5A, 0x6A6AE4A3, 0x84E5965E, 0x61A206B0, 0x0C251001A, + 0x3807D6F0, 0x2B904A0C, 0x2106AEC3, 0x3DA24A18, 0x6D3FE30, + 0x6B8D2906, 0x3E4C960, 0x99D9E302, 0x0E7742521, 0x0A213CA1A, + 0x0B701BE64, 0x0D54A02C3, 0x2BCE53BF, 0x73950655, 0x2F6237EC, + 0x328B228B, 0x6307D148, 0x0BEC9F804, 0x9B4C1D55, 0x3370FBC4, + 0x60842939, 0x0A4A4F7B3, 0x6D45993C, 0x970E871D, 0x33EA234E, + 0x875B9C30, 0x5511137E, 0x61BBFD81, 0x2D1DC984, 0x762C288, + 0x45B43639, 0x0D00BD820, 0x0DF426319, 0x5708008, 0x6E75EAC8, + 0x66D3D064, 0x1AC07B8A, 0x0A379303C, 0x40D858C9, 0x0E329DEFC, + 0x0F03AD993, 0x41B16BF2, 0x6DA2E819, 0x4A613BD4, 0x0B0958631, + 0x808E0937, 0x0E5D945D5, 0x0DA116119, 0x0EDF7CCA3, 0x42C52458, + 0x0DAC0575B, 0x150D0839, 0x76C53463, 0x0A74C15E2, 0x0BDDE4646, + 0x0BC6A29DF, 0x5EA48630, 0x105674A1, 0x3EF67D74, 0x0D07EFDFA, + 0x0F578CB07, 0x1F581BA3, 0x4F0FA302, 0x92DDFDB7, 0x0CB674D24, + 0x0B4092335, 0x206DA34E, 0x835DE381, 0x0B3D59405, 0x0F05DE5E3, + 0x2395A4F3, 0x6312A607, 0x0BD686A66, 0x3588F97C, 0x84D10CF, + 0x34518135, 0x3A05D745, 0x2301390B, 0x0C1989100, 0x37B0ED38, + 0x0BCD025DE, 0x9B7BBEDE, 0x7EBD0EE1, 0x0ED03A17E, 0x1230DCAE, + 0x0BFECE081, 0x0B23FB110, 0x176098B3, 0x4EC7C574, 0x0EF8939C3, + 0x0BE5E36B, 0x0B51A09C4, 0x0C17CEA2A, 0x0CCC7A2AF, 0x7DB34D0D, + 0x9C96FDF, 0x0FD749410, 0x385B3393, 0x36EED854, 0x953F826F, + 0x0D1144AA1, 0x533A46FB, 0x0AA1CADDE, 0x18943C23, 0x5000D89A, + 0x7E9974B6, 0x88003586, 0x931AD4E7, 0x0CA1E45F9, 0x5AEC96CF, + 0x0C1A1196B, 0x4968C5E9, 0x0CF93DAFA, 0x0C9EAC494, 0x884242E8, + 0x0BA52C795, 0x32C3211B, 0x0EC865892, 0x4B6AD99C, 0x0A6EED398, + 0x353E218, 0x22F6EB95, 0x0BEDD4762, 0x0F9023DF, 0x932A26EF, + 0x0EAF55AC, 0x0D0A03459, 0x36CD2E97, 0x736B37DC, 0x9066B022, + 0x0B2F98BDC, 0x9C7BAF2E, 0x747C9E5D, 0x0CA105585, 0x0D66B748A, + 0x1AE9E50, 0x0A801232F, 0x1CE2DCA1, 0x0EDBC573E, 0x68BC34EB, + 0x5EE0CF4E, 0x27512085, 0x0E7F2DF17, 0x1039EB2A, 0x283EECF7, + 0x0CD11377C, 0x0F651F370, 0x7BFA7A7C, 0x0D87F02A8, 0x2E197D14, + 0x8A5EBEE8, 0x6A15DC8D, 0x7D49DB1E, 0x0AB9C8919, 0x55DEA75B, + 0x0DEDE494B, 0x6A808055, 0x0E510359A, 0x48D658E5, 0x17EB3BE1, + 0x2E4B388A, 0x0BE2A9AE2, 0x938CBBE5, 0x981069BE, 0x9C0C8E3B, + 0x56DF107F, 0x0A783F7F7, 0x2062CE8F, 0x0C46B4B25, 0x0F64323D, + 0x378276F7, 0x0B137A13F, 0x0F74B7744, 0x892ED62B, 0x318DE104, + 0x8C235EFD, 0x0C6D25BD5, 0x0A5F21894, 0x0C9E9217A, 0x32FBBB35, + 0x2648157, 0x84A44F06, 0x6E1B5FF5, 0x63D5B294, 0x0BCA7B284, + 0x887B154E, 0x0D1E80454, 0x22067D08, 0x4580F65B, 0x51EA4379, + 0x0E555B9B3, 0x0AE2194BC, 0x2F139619, 0x0C1A7F1D3, 0x0D8A8676F, + 0x89FDB01F, 0x49C61C3A, 0x0F8A879EA, 0x1E643725, 0x74AFCADE, + 0x0A63E507C, 0x5720748B, 0x655092B1, 0x6F8B1CE4, 0x955F3CDB, + 0x7F85BAC2, 0x0A1702132, 0x0BD261D60, 0x0A94F2895, 0x528B65DE, + 0x109CC04, 0x0DD5688BE, 0x0B2729D26, 0x0F029CE6A, 0x0F7A0BEC4, + 0x912F55AC, 0x0C06E654C, 0x0BB938E34, 0x33FB5F4F, 0x0DA06BD15, + 0x26288903, 0x523D7D48, 0x0A71D57C2, 0x0F9713A28, 0x74C55189, + 0x99DEB5F5, 0x834D917A, 0x6F448452, 0x7BA9465A, 0x0AE698FC6, + 0x390F3413, 0x0FC95933E, 0x4C793234, 0x0F414A389, 0x7928AB6C, + 0x0A3B8A3DB, 0x381C1D13, 0x0B54CB4B, 0x359D9DA1, 0x0A3422A55, + 0x0D1B55135, 0x0D4DE2058, 0x9EB3F40F, 0x7E09E219, 0x0E6A95616, + 0x71A7FA3E, 0x24EFDA53, 0x0F521C5D4, 0x899FF674, 0x42E4F4CB, + 0x7917B64A, 0x8DF0B74, 0x0C7A394B, 0x0E909E409, 0x8E2E3211, + 0x0FAD92D25, 0x0FE5F69D9, 0x45CDE648, 0x937B3705, 0x4AE4E455, + 0x32B40E9B, 0x79235113, 0x0F982EFC3, 0x0BA132AAF, 0x0B81EF14D, + 0x0E641BF38, 0x7208C128, 0x4BBE3722, 0x0E1821CEC, 0x2C9D09C4, + 0x0EF125751, 0x3E7784DA, 0x3E04D7B6, 0x2CEA4704, 0x0A0E59A9C, + 0x1315CA45, 0x9F0AAC28, 0x71ED384, 0x0F707B3A4, 0x8DAC020E, + 0x173864FE, 0x1F6D4612, 0x0A53C0A47, 0x0AB926524, 0x0F7740635, + 0x144E79BB, 0x9A884AA2, 0x0AF5B6DB3, 0x0CEE3DD0B, 0x0C77584CC, + 0x7325B12, 0x1ADCD229, 0x6EE972FD, 0x5AD6C1D1, 0x5EBE6634, + 0x0AD2B8D31, 0x0E82C8DC7, 0x2DA8C899, 0x50F1D3E5, 0x689CD8BA, + 0x8E913866, 0x0E15E742E, 0x0CED14D43, 0x8EC52AF1, 0x0EF3CBB18, + 0x58AEDCE0, 0x7A1BCA9, 0x9E7A3E41, 0x0DE939F5A, 0x0B28D5A3B, + 0x6FE848B5, 0x5AD00C59, 0x6B3AAEE8, 0x5030860B, 0x0B5695C44, + 0x0C31DCD25, 0x0E617F0C0, 0x0D40C3A5E, 0x0CB2B9F74, 0x19F5FAD2, + 0x0E24FAF1E, 0x1ED68F81, 0x0E172FCA0, 0x0DF2E4DCE, 0x2F47747F, + 0x4F82DD00, 0x69C39A66, 0x0D4DCBEC5, 0x0DEA306A2, 0x0C947BFAA, + 0x13E4E3A4, 0x0FB5486A4, 0x40497081, 0x2C980C8A, 0x0D1D88175, + 0x932C1E98, 0x0E65DFB5C, 0x592CDDEE, 0x0D4E65B37, 0x1D383F0F, + 0x0A1452FAD, 0x72F68D62, 0x8C919B88, 0x5C8EE3B5, 0x83A6D634, + 0x0D72CB3B5, 0x0AAA0AA43, 0x50824277, 0x0DB64F8EB, 0x294328F2, + 0x21173186, 0x39A9D582, 0x3BA5DE12, 0x4AF00767, 0x203B19AF, + 0x99D95544, 0x75CD1223, 0x5928A7A1, 0x18928B59, 0x3126BB69, + 0x99835CDE, 0x0BA1FA26C, 0x0BBDFF063, 0x2E541DE, 0x0F7AAC63D, + 0x0B4CD0D6, 0x0FA29F1E8, 0x4CAC5ED0, 0x22679880, 0x2F624C2C, + 0x5B37746, 0x924FCDAD, 0x0EA205C22, 0x47586DFB, 0x4D04AB1B, + 0x93E48721, 0x607ADAE0, 0x0B261CC10, 0x85E0F642, 0x51BFC31A, + 0x0D5591CB8, 0x13F34477, 0x9C4C00DA, 0x0D75FCC3, 0x0DAE36AE6, + 0x4AC3EC7E, 0x0C38DB43E, 0x48DCE98B, 0x407D4DE8, 0x79C61EB2, + 0x6C293A0D, 0x0C309861E, 0x18CB8F7B, 0x3172DF, 0x48E3FA23, + 0x7E4F0969, 0x0B3B3399B, 0x8078C214, 0x47C29F9C, 0x0BB45EC9A, + 0x0A35A9385, 0x0DB52279C, 0x9B0A10D7, 0x0FBBFE91D, 0x0B72426B7, + 0x30B2FA05, 0x0B440786F, 0x0FFD3F89F, 0x2B7BCED, 0x0E3CFD31B, + 0x44293E43, 0x0C8D5520D, 0x0D3F85D25, 0x921C8CED, 0x3CCA0C6F, + 0x975B7095, 0x0BD0B539C, 0x204F3EC6, 0x0CC69CC4F, 0x0EC390BA3, + 0x905626CE, 0x0AD5D4134, 0x6589A582, 0x89841DE4, 0x5D7D9F79, + 0x9B7B2F04, 0x0BAF101E4, 0x6F92DE46, 0x7566C899, 0x8A1EE142, + 0x0BAA58991, 0x0DFF7C7F4, 0x6936EA6B, 0x5BFB703C, 0x96EA26E8, + 0x5A89915D, 0x0A528D6D, 0x2F06347F, 0x0C0450185, 0x0A15C352E, + 0x695E7A5C, 0x6876C7D8, 0x0E97B8345, 0x0B4C5ED52, 0x0D73FBB34, + 0x0A6BE0154, 0x1915544, 0x0D55A31F8, 0x0E51C9933, 0x0CB94FD3F, + 0x39CD60E1, 0x85EFBA8C, 0x65579BD5, 0x0F7ED1227, 0x4B2CDB8, + 0x859981BB, 0x66988DD8, 0x8BFEDAD9, 0x110705A6, 0x0D6AEC073, + 0x3BC27538, 0x283C2D61, 0x51D0B1C7, 0x0B8C2EEE0, 0x73FB9E32, + 0x0B05C250E, 0x0F652B97A, 0x0AEABC66F, 0x0E1A89145, 0x43531B6B, + 0x7112485B, 0x777D40CD, 0x956D162B, 0x4355A846, 0x72D6C647, + 0x158D96E8, 0x0E03036E4, 0x4FD9A4AB, 0x0EBA1DB5B, 0x0C9713FEC, + 0x53153BAA, 0x4A9229E9, 0x0CBA72F4, 0x13FDF646, 0x0BF82AEFD, + 0x55778F8B, 0x47A5B2AF, 0x0B647B3A4, 0x351C5798, 0x0D0BB715F, + 0x4D270669, 0x0B1A3AFF1, 0x6C73F78, 0x5CD4A672, 0x0E45153F, + 0x46A6635C, 0x0C3A9B0DB, 0x0DA774810, 0x0BB44C98E, 0x0F6268952, + 0x3E27323D, 0x6C99AFC8, 0x0C7A94CF3, 0x8237187E, 0x86E58E5C, + 0x726E7565, 0x0E03A054B, 0x0EB2F4BCF, 0x0EEC9CF34, 0x8D6D73F4, + 0x0FAFA9EB3, 0x71A29A71, 0x5F83B03, 0x9F49C2C4, 0x44300088, + 0x9665BFD1, 0x9ED65D46, 0x0C8F9BA60, 0x2F605567, 0x1B8EB19D, + 0x0C809FEB9, 0x6AB0F596, 0x6D4F042D, 0x171ABC1, 0x0D6752659, + 0x24E44C73, 0x0EF02B7F7, 0x89A3256A, 0x58401E64, 0x0D94AD744, + 0x0E5BE5722, 0x34FAD805, 0x1FCF7056, 0x0AAD7F095, 0x0C1090D4B, + 0x0C28ABD40, 0x3CC6E4ED, 0x0F7C03034, 0x34A6414F, 0x35A90E07, + 0x0C8426, 0x617A702E, 0x2E9C9E4B, 0x0CEEB4287, 0x0FCC3983D, + 0x0C9B9C8D0, 0x0E02F0C9C, 0x0E26142D, 0x253AAAF, 0x517492A6, + 0x0BDE4B4E0, 0x0B66D7DA7, 0x215E823B, 0x59DE667F, 0x7380FEF2, + 0x0C718B4E1, 0x0ABCC29DB, 0x826E1F66, 0x0F60995F0, 0x81B93308, + 0x32C0E9CE, 0x0AED7D4A8, 0x75C26137, 0x6627B48A, 0x86A04B91, + 0x0FD0FDED4, 0x61328A64, 0x37772F12, 0x0B71117E0, 0x0D04BD8B5, + 0x6C1C7B55, 0x0F5FCDD8F, 0x18F756B9, 0x0C9009959, 0x8787DB25, + 0x0E14E382E, 0x39785258, 0x0C8E33B0D, 0x0E2B79532, 0x7B3FF75A, + 0x0EBF8933A, 0x0EEE8165E, 0x0EF31D01A, 0x86E615C2, 0x3F1DE31D, + 0x9D46C418, 0x5EBBF6B8, 0x198CA52, 0x86CC4AFE, 0x75701E49, + 0x2158B12A, 0x2EE88F38, 0x51291219, 0x571C3D3E, 0x694FE8CD, + 0x8EAD1DDF, 0x719AC3EC, 0x65407983, 0x0A623C53F, 0x0E1FC6EF6, + 0x0F7C42633, 0x0FF0F6CE7, 0x8A9BB15B, 0x2A29BA69, 0x358B45EC, + 0x0C6FFEF75, 0x5BB5540, 0x0A8C97A66, 0x0BA156953, 0x9BC51B7B, + 0x49C89A49, 0x0DDB26758, 0x59C719E6, 0x0A0554886, 0x0C648A914, + 0x8AF87AEE, 0x21452161, 0x36E61062, 0x2EFEEB7F, 0x0B0F0ED15, + 0x657588C2, 0x0FCEC4B1D, 0x72F109A5, 0x903038F8, 0x0B57B9746, + 0x0D51B1404, 0x0C264ECE5, 0x0AA8D1406, 0x0E1BED868, 0x0E169C2A4, + 0x90DEBDDA, 0x0C11A7AEB, 0x0FCE013E8, 0x820CEECA, 0x8C23E563, + 0x0D42EA394, 0x56C951C1, 0x58777382, 0x0A8380C9B, 0x255E092F, + 0x809CDC30, 0x4460681A, 0x14621DE1, 0x347D6427, 0x4CBF3DB3, + 0x68BC261F, 0x422740D0, 0x0C4A3AD2C, 0x0C9D63C06, 0x24BF485D, + 0x0E34ADD47, 0x0D5221D28, 0x49C7E227, 0x19E0A5E3, 0x0E7D29F61, + 0x0A7912D4A, 0x5DB77953, 0x28D357FC, 0x80036D7D, 0x0BCC597FD, + 0x0D70A8A06, 0x738CB736, 0x1E627237, 0x0D5D153F1, 0x0C666DCFD, + 0x5A415D5D, 0x73B4156B, 0x0F30D9A10, 0x7DAF7B36, 0x7F682380, + 0x70FE0038, 0x560BE589, 0x8C0BADEE, 0x0C2B422EA, 0x45861DFA, + 0x81A2EEC8, 0x0C4DFFDA1, 0x441BB229, 0x64CF934D, 0x33E6AC7A, + 0x35D0340C, 0x67D26D0A, 0x7DA0CC10, 0x6E2D5A8C, 0x32C25A2D, + 0x0CA4E2C99, 0x82FD715F, 0x730B702C, 0x4BDBB941, 0x51430724, + 0x0A32A6B96, 0x0C256A7C6, 0x517FD8C4, 0x1AA85938, 0x52AFE354, + 0x1E22F907, 0x56548374, 0x88B0B9A2, 0x404E4275, 0x86C49DDD, + 0x0A93FC14D, 0x3BD2006F, 0x5D0D3116, 0x3DD20E74, 0x0DC64DB8D, + 0x15C149EB, 0x0DB329993, 0x0C2200439, 0x0C0295BB0, 0x3573EBA4, + 0x2A40A38B, 0x0D6C379D9, 0x67330973, 0x0FF1D7F67, 0x0FCFEB8DA, + 0x7C11A442, 0x2066EFD5, 0x1134E040, 0x4170819D, 0x0F49E009F, + 0x7EE85510, 0x4E6D257E, 0x2BDBE631, 0x0BE404560, 0x511DC4A4, + 0x0D6BDA8AC, 0x2BC41233, 0x9C0B6C2F, 0x0AAAB064B, 0x0A580198, + 0x0F1F16D7F, 0x8F54AEFB, 0x0D9772405, 0x8CB50B4F, 0x6F659F34, + 0x0D8B184EF, 0x71A6660C, 0x3C87DD1D, 0x0D56793AE, 0x0F8F6A87B, + 0x429C55E0, 0x3CC4D090, 0x957B708A, 0x0AF391249, 0x5EFEBB3B, + 0x0ECA17F75, 0x6065A1A5, 0x0FFCEFB48, 0x14B3A01D, 0x0ED93C1D9, + 0x262DCD1C, 0x2A4ADCA4, 0x0F6DE4EC1, 0x204FAF08, 0x1815DE4C, + 0x0AF836FCA, 0x0D5E44DA4, 0x0A7CAA491, 0x0A9A3FED2, 0x4F8DAC68, + 0x0C36C6784, 0x0E239373F, 0x879D948B, 0x0DBECB69, 0x0F59A45D, + 0x7211421F, 0x0A6064A94, 0x28AA48FC, 0x4CD04E6D, 0x3906DE80, + 0x3525094A, 0x2326D98E, 0x4937ED30, 0x570E63ED, 0x0A57EFB4A, + 0x0BD4878CA, 0x19334A64, 0x2E5F6B34, 0x0A9D68771, 0x0F8645F9F, + 0x0CA96F06, 0x5D6CCE62, 0x2F3257DC, 0x140F0639, 0x0B3BDA452, + 0x0C7EBA7C4, 0x6BD754E8, 0x941F2606, 0x0DFD573C5, 0x8DD14DE6, + 0x0CB4BA732, 0x37A9B8B1, 0x0A195A51D, 0x0E535A96, 0x351B897, + 0x0F629, 0x4AE34157, 0x0EDE6A6E1, 0x2F03235, 0x2EBB589A, + 0x6BE492AF, 0x0B3E4B14, 0x0FA6CFD67, 0x43AF9772, 0x0D5FC21A2, + 0x8852A2BB, 0x5B4A42CB, 0x0FFF0AC5D, 0x9AD1B6EE, 0x0C55544A5, + 0x0D64F693E, 0x65D3D048, 0x9485B90, 0x63BD09DD, 0x5E811DDD}; #endif \ No newline at end of file diff --git a/src/main/security/rp-sign-key.c b/src/main/security/rp-sign-key.c index dfa6c34..762412e 100644 --- a/src/main/security/rp-sign-key.c +++ b/src/main/security/rp-sign-key.c @@ -1,13 +1,10 @@ #include "security/rp-sign-key.h" const struct security_rp_sign_key security_rp_sign_key_white_eamuse = { - .data = "E-AMUSE3" -}; + .data = "E-AMUSE3"}; const struct security_rp_sign_key security_rp_sign_key_black_ps2 = { - .data = "GENTAKAH" -}; + .data = "GENTAKAH"}; const struct security_rp_sign_key security_rp_sign_key_black_gfdmv4 = { - .data = "UDONHRKI" -}; \ No newline at end of file + .data = "UDONHRKI"}; \ No newline at end of file diff --git a/src/main/security/rp-sign-key.h b/src/main/security/rp-sign-key.h index bcc317d..f54f795 100644 --- a/src/main/security/rp-sign-key.h +++ b/src/main/security/rp-sign-key.h @@ -5,7 +5,7 @@ /** * Sign keys used to sign roundplug data. - */ + */ struct security_rp_sign_key { char data[8]; }; @@ -24,7 +24,7 @@ extern const struct security_rp_sign_key security_rp_sign_key_black_ps2; /** * Signing key used to create eeprom signitures for all black dongles used * on the following games: - * + * * - GF & DM V4 to V8 (TODO needs verification) * - jubeat (1) */ diff --git a/src/main/security/rp.c b/src/main/security/rp.c index eb37216..ba82864 100644 --- a/src/main/security/rp.c +++ b/src/main/security/rp.c @@ -7,14 +7,14 @@ #include "util/crypto.h" #include "util/log.h" -static uint32_t security_rp_get_len_mcode(const struct security_mcode* mcode) +static uint32_t security_rp_get_len_mcode(const struct security_mcode *mcode) { uint32_t len; len = 0; - while (len < sizeof(struct security_mcode) && - ((const char*) mcode)[len] != ' ') { + while (len < sizeof(struct security_mcode) && + ((const char *) mcode)[len] != ' ') { len++; } @@ -22,16 +22,18 @@ static uint32_t security_rp_get_len_mcode(const struct security_mcode* mcode) } void security_rp_generate_signed_eeprom_data( - const struct security_mcode* boot_version, const uint32_t* boot_seeds, - const struct security_mcode* plug_mcode, - const struct security_id* plug_id, struct security_rp_eeprom* out) + const struct security_mcode *boot_version, + const uint32_t *boot_seeds, + const struct security_mcode *plug_mcode, + const struct security_id *plug_id, + struct security_rp_eeprom *out) { uint8_t encryption_key[sizeof(security_rp_enc_table_key_base)]; uint32_t boot_version_len; uint32_t idx; uint32_t seed; - uint8_t* enc_key_section1; - uint8_t* enc_key_section2; + uint8_t *enc_key_section1; + uint8_t *enc_key_section2; uint8_t data[32]; struct blowfish ctx; @@ -45,7 +47,9 @@ void security_rp_generate_signed_eeprom_data( log_assert(boot_seeds[1] <= 16); log_assert(boot_seeds[2] >= boot_seeds[1]); - memcpy(encryption_key, security_rp_enc_table_key_base, + memcpy( + encryption_key, + security_rp_enc_table_key_base, sizeof(security_rp_enc_table_key_base)); boot_version_len = security_rp_get_len_mcode(boot_version); @@ -53,13 +57,13 @@ void security_rp_generate_signed_eeprom_data( idx = 0; for (uint32_t i = 0; i < sizeof(encryption_key); i++) { - encryption_key[i] ^= ((const char*) boot_version)[idx]; + encryption_key[i] ^= ((const char *) boot_version)[idx]; idx = (idx + 1) % boot_version_len; } seed = 16 * (boot_seeds[2] + 16 * (boot_seeds[1] + 16 * boot_seeds[0])); - enc_key_section1 = (uint8_t*) encryption_key; - enc_key_section2 = (uint8_t*) (((uint8_t*) encryption_key) + 14); + enc_key_section1 = (uint8_t *) encryption_key; + enc_key_section2 = (uint8_t *) (((uint8_t *) encryption_key) + 14); memset(data, 0, sizeof(data)); @@ -79,6 +83,6 @@ void security_rp_generate_signed_eeprom_data( out->signature[i] = data[i + 16] ^ data[i + 22]; } - security_util_8_to_6_encode_reverse((const uint8_t*) plug_mcode, - out->packed_payload); + security_util_8_to_6_encode_reverse( + (const uint8_t *) plug_mcode, out->packed_payload); } \ No newline at end of file diff --git a/src/main/security/rp.h b/src/main/security/rp.h index 5922e2d..6e4cd49 100644 --- a/src/main/security/rp.h +++ b/src/main/security/rp.h @@ -21,24 +21,26 @@ struct security_rp_eeprom { /** * Generate signed eeprom data from non encrypted and unobfuscated data required * to pass security checks on games using black (game specific) roundplugs. - * + * * This implementation (rp (1)) is used by the following games * - iidx 09 to 13 - * + * * @param boot_version The boot version mcode that is used for bootstrapping * the security backend (of the ezusb.dll). * @param boot_seeds Boot seeds (three numbers >= 0) set when the game is * bootstrapping the security backend (of the ezusb.dll). * @param plug_mcode The mcode of the game to boot. Typically, this code is - * printed onto the housing of the black dongle. + * printed onto the housing of the black dongle. * @param plug_id The id stored of the plug. This data is normally stored in the * ROM area of the black dongle is is often refered to as the * "PCBID" or "EAMID" when stored on the white dongle. - * @param out Pointer to the eeprom data struct for the resulting data. + * @param out Pointer to the eeprom data struct for the resulting data. */ void security_rp_generate_signed_eeprom_data( - const struct security_mcode* boot_version, const uint32_t* boot_seeds, - const struct security_mcode* plug_mcode, - const struct security_id* plug_id, struct security_rp_eeprom* out); + const struct security_mcode *boot_version, + const uint32_t *boot_seeds, + const struct security_mcode *plug_mcode, + const struct security_id *plug_id, + struct security_rp_eeprom *out); #endif \ No newline at end of file diff --git a/src/main/security/rp2.c b/src/main/security/rp2.c index b3f1af5..008421e 100644 --- a/src/main/security/rp2.c +++ b/src/main/security/rp2.c @@ -5,22 +5,30 @@ #include "util/log.h" static const uint8_t security_rp2_sign_key_base_black[] = { - 0x32, 0x44, 0x58, 0x47, 0x4C, 0x44, 0x41, 0x43 -}; + 0x32, 0x44, 0x58, 0x47, 0x4C, 0x44, 0x41, 0x43}; static const uint8_t security_rp2_sign_key_base_white[] = { - 0x45, 0x2D, 0x41, 0x4D, 0x55, 0x53, 0x45, 0x33 -}; + 0x45, 0x2D, 0x41, 0x4D, 0x55, 0x53, 0x45, 0x33}; -static uint8_t security_rp2_signature_scramble_table[16] = { - 0x0C, 0x02, 0x0F, 0x01, - 0x07, 0x09, 0x04, 0x0A, - 0x00, 0x0E, 0x03, 0x0D, - 0x0B, 0x05, 0x08, 0x06 -}; +static uint8_t security_rp2_signature_scramble_table[16] = {0x0C, + 0x02, + 0x0F, + 0x01, + 0x07, + 0x09, + 0x04, + 0x0A, + 0x00, + 0x0E, + 0x03, + 0x0D, + 0x0B, + 0x05, + 0x08, + 0x06}; -static void security_rp2_create_signiture(const uint8_t *plug_id_enc, - const uint8_t *sign_key_packed, uint8_t *out) +static void security_rp2_create_signiture( + const uint8_t *plug_id_enc, const uint8_t *sign_key_packed, uint8_t *out) { uint8_t data[14]; uint8_t md5[16]; @@ -46,28 +54,29 @@ static void security_rp2_create_signiture(const uint8_t *plug_id_enc, } void security_rp2_generate_signed_eeprom_data( - enum security_rp_util_rp_type type, - const struct security_mcode* boot_version, - const struct security_mcode* plug_mcode, - const struct security_id* plug_id, struct security_rp2_eeprom* out) + enum security_rp_util_rp_type type, + const struct security_mcode *boot_version, + const struct security_mcode *plug_mcode, + const struct security_id *plug_id, + struct security_rp2_eeprom *out) { uint8_t sign_key[8]; uint8_t plug_id_enc[8]; - char* boot_version_str; + char *boot_version_str; log_assert(boot_version); log_assert(plug_mcode); log_assert(plug_id); log_assert(out); - boot_version_str = (char*) boot_version; - + boot_version_str = (char *) boot_version; + /* -------------------------------- */ switch (type) { case SECURITY_RP_UTIL_RP_TYPE_BLACK: - memcpy(sign_key, security_rp2_sign_key_base_black, - sizeof(sign_key)); + memcpy( + sign_key, security_rp2_sign_key_base_black, sizeof(sign_key)); sign_key[0] = boot_version_str[0] ^ sign_key[0]; sign_key[1] ^= boot_version_str[1]; @@ -81,9 +90,9 @@ void security_rp2_generate_signed_eeprom_data( break; case SECURITY_RP_UTIL_RP_TYPE_WHITE: - memcpy(sign_key, security_rp2_sign_key_base_white, - sizeof(sign_key)); - + memcpy( + sign_key, security_rp2_sign_key_base_white, sizeof(sign_key)); + break; default: @@ -106,8 +115,8 @@ void security_rp2_generate_signed_eeprom_data( plug_id_enc[6] = plug_id->id[7]; plug_id_enc[7] = plug_id->id[1]; - security_rp2_create_signiture(plug_id_enc, sign_key, (uint8_t*) out); + security_rp2_create_signiture(plug_id_enc, sign_key, (uint8_t *) out); - security_util_8_to_6_encode((const uint8_t*) plug_mcode, - out->packed_payload); + security_util_8_to_6_encode( + (const uint8_t *) plug_mcode, out->packed_payload); } \ No newline at end of file diff --git a/src/main/security/rp2.h b/src/main/security/rp2.h index 32f7837..0f49762 100644 --- a/src/main/security/rp2.h +++ b/src/main/security/rp2.h @@ -22,10 +22,10 @@ struct security_rp2_eeprom { * Generate signed eeprom data from non encrypted and unobfuscated data required * to pass security checks on games using black (game specific) and white * (eamuse) roundplugs. - * + * * This implementation (rp 2) is used by the following games * - iidx 14 to 17 - * + * * @param type Type of plug to sign eeprom data for (black or white). * @param boot_version The boot version mcode that is used for bootstrapping * the security backend (of the ezusb.dll). @@ -35,12 +35,13 @@ struct security_rp2_eeprom { * @param plug_id The id stored on the plug. This data is normally stored in the * ROM area of the black dongle is is often refered to as the * "PCBID" or "EAMID" when stored on the white dongle. - * @param out Pointer to the eeprom data struct for the resulting data. + * @param out Pointer to the eeprom data struct for the resulting data. */ void security_rp2_generate_signed_eeprom_data( - enum security_rp_util_rp_type type, - const struct security_mcode* boot_version, - const struct security_mcode* plug_mcode, - const struct security_id* plug_id, struct security_rp2_eeprom* out); + enum security_rp_util_rp_type type, + const struct security_mcode *boot_version, + const struct security_mcode *plug_mcode, + const struct security_id *plug_id, + struct security_rp2_eeprom *out); #endif \ No newline at end of file diff --git a/src/main/security/rp3.c b/src/main/security/rp3.c index b86e390..09b3d37 100644 --- a/src/main/security/rp3.c +++ b/src/main/security/rp3.c @@ -6,15 +6,25 @@ #include "util/crypto.h" #include "util/log.h" -static uint8_t security_rp3_signature_scramble_table[] = { - 0x0C, 0x02, 0x0F, 0x01, - 0x07, 0x09, 0x04, 0x0A, - 0x00, 0x0E, 0x03, 0x0D, - 0x0B, 0x05, 0x08, 0x06 -}; +static uint8_t security_rp3_signature_scramble_table[] = {0x0C, + 0x02, + 0x0F, + 0x01, + 0x07, + 0x09, + 0x04, + 0x0A, + 0x00, + 0x0E, + 0x03, + 0x0D, + 0x0B, + 0x05, + 0x08, + 0x06}; -static void security_rp3_create_signature(const uint8_t *plug_id, - const uint8_t *sign_key_packed, uint8_t *out) +static void security_rp3_create_signature( + const uint8_t *plug_id, const uint8_t *sign_key_packed, uint8_t *out) { uint8_t data[14]; uint8_t md5[16]; @@ -40,10 +50,11 @@ static void security_rp3_create_signature(const uint8_t *plug_id, } void security_rp3_generate_signed_eeprom_data( - enum security_rp_util_rp_type type, - const struct security_rp_sign_key* sign_key, - const struct security_mcode* plug_mcode, - const struct security_id* plug_id, struct security_rp3_eeprom* out) + enum security_rp_util_rp_type type, + const struct security_rp_sign_key *sign_key, + const struct security_mcode *plug_mcode, + const struct security_id *plug_id, + struct security_rp3_eeprom *out) { uint8_t sign_key_tmp[8]; uint8_t sign_key_packed[6]; @@ -57,8 +68,8 @@ void security_rp3_generate_signed_eeprom_data( memcpy(sign_key_tmp, sign_key, sizeof(sign_key_tmp)); if (type == SECURITY_RP_UTIL_RP_TYPE_BLACK) { - for (int i = 0 ; i < sizeof(sign_key_tmp); i++) { - sign_key_tmp[i] ^= ((const uint8_t*) plug_mcode)[i]; + for (int i = 0; i < sizeof(sign_key_tmp); i++) { + sign_key_tmp[i] ^= ((const uint8_t *) plug_mcode)[i]; } } @@ -68,11 +79,11 @@ void security_rp3_generate_signed_eeprom_data( plug_id_reversed[i] = plug_id->id[7 - i]; } - security_util_8_to_6_encode((const uint8_t*) plug_mcode, - out->packed_payload); - memset(out->zeros, 0, sizeof(out->zeros)); + security_util_8_to_6_encode( + (const uint8_t *) plug_mcode, out->packed_payload); + memset(out->zeros, 0, sizeof(out->zeros)); - security_rp3_create_signature(plug_id_reversed, sign_key_packed, - out->signature); + security_rp3_create_signature( + plug_id_reversed, sign_key_packed, out->signature); out->crc = crc8((uint8_t *) out, sizeof(*out) - 1, 0); } diff --git a/src/main/security/rp3.h b/src/main/security/rp3.h index 43fc5cc..424511f 100644 --- a/src/main/security/rp3.h +++ b/src/main/security/rp3.h @@ -23,12 +23,12 @@ struct security_rp3_eeprom { /** * Generate signed eeprom data from non encrypted and unobfuscated data required - * to pass security checks on games using black (game specific) and white + * to pass security checks on games using black (game specific) and white * (eamuse) roundplugs. - * + * * Used on the following games: * - jubeat - * + * * @param type Type of plug to sign eeprom data for (black or white). * @param sign_key The key to use for generating the signiture. * This key can be extracted from the executables of the games and might @@ -39,12 +39,13 @@ struct security_rp3_eeprom { * @param plug_id The id stored on the plug. This data is normally stored in the * ROM area of the black dongle is is often refered to as the * "PCBID" or "EAMID" when stored on the white dongle. - * @param out Pointer to the eeprom data struct for the resulting data. + * @param out Pointer to the eeprom data struct for the resulting data. */ void security_rp3_generate_signed_eeprom_data( - enum security_rp_util_rp_type type, - const struct security_rp_sign_key* sign_key, - const struct security_mcode* plug_mcode, - const struct security_id* plug_id, struct security_rp3_eeprom* out); + enum security_rp_util_rp_type type, + const struct security_rp_sign_key *sign_key, + const struct security_mcode *plug_mcode, + const struct security_id *plug_id, + struct security_rp3_eeprom *out); #endif \ No newline at end of file diff --git a/src/main/security/util.c b/src/main/security/util.c index e6e5add..aa7d038 100644 --- a/src/main/security/util.c +++ b/src/main/security/util.c @@ -5,7 +5,7 @@ void security_util_8_to_6_encode(const uint8_t *in, uint8_t *out) uint8_t tmp[8]; int i; - for (i = 0 ; i < 8 ; i++) { + for (i = 0; i < 8; i++) { tmp[i] = (in[i] - 0x20) & 0x3F; } @@ -32,7 +32,7 @@ void security_util_6_to_8_decode(const uint8_t *in, uint8_t *out) out[6] = ((in[4] >> 4) & 0x0F) | ((in[5] << 4) & 0x30); out[7] = ((in[5] >> 2) & 0x3F); - for (i = 0 ; i < 8 ; i++) { + for (i = 0; i < 8; i++) { out[i] += 0x20; } } diff --git a/src/main/security/util.h b/src/main/security/util.h index d5078dc..b920dd0 100644 --- a/src/main/security/util.h +++ b/src/main/security/util.h @@ -6,16 +6,16 @@ /** * Pack 8 bytes of input data into 6 bytes payload output data. This is used to * pack/encode mcodes from roundplug dongles, e.g. GCH44JAA. - * + * * @param in Input data of 8 bytes length, e.g. mcode. * @param out Target buffer for encoded data with at least 6 bytes capacity. */ void security_util_8_to_6_encode(const uint8_t *in, uint8_t *out); /** - * Decode/unpack 6 bytes of encoded roundplug data, e.g. encoded mcode, to + * Decode/unpack 6 bytes of encoded roundplug data, e.g. encoded mcode, to * the full 8 bytes width. - * + * * @param in Input encoded payload of 6 bytes length. * @param out Target buffer for decoded data with at least 8 bytes capacity. */ @@ -23,7 +23,7 @@ void security_util_6_to_8_decode(const uint8_t *in, uint8_t *out); /** * Same as security_util_8_to_6_encode but in reversed byte order. - * + * * @param in Input data of 8 bytes length, e.g. mcode. * @param out Target buffer for encoded data with at least 6 bytes capacity. */ @@ -31,7 +31,7 @@ void security_util_8_to_6_encode_reverse(const uint8_t *in, uint8_t *out); /** * Same as security_util_6_to_8_decode but in reversed byte order. - * + * * @param in Input encoded payload of 6 bytes length. * @param out Target buffer for decoded data with at least 8 bytes capacity. */ diff --git a/src/main/unicorntail/dllmain.c b/src/main/unicorntail/dllmain.c index 5c55ccc..8bef765 100644 --- a/src/main/unicorntail/dllmain.c +++ b/src/main/unicorntail/dllmain.c @@ -57,10 +57,7 @@ BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx) } log_to_external( - log_body_misc, - log_body_info, - log_body_warning, - log_body_fatal); + log_body_misc, log_body_info, log_body_warning, log_body_fatal); app_hook_init(my_dll_entry_init, my_dll_entry_main); diff --git a/src/main/unicorntail/p3io.c b/src/main/unicorntail/p3io.c index 8652188..3e88f7e 100644 --- a/src/main/unicorntail/p3io.c +++ b/src/main/unicorntail/p3io.c @@ -45,7 +45,8 @@ void p3io_filter_fini(void) DeleteCriticalSection(&p3io_handle_lock); } -HRESULT p3io_filter_dispatch_irp(struct irp *irp) +HRESULT +p3io_filter_dispatch_irp(struct irp *irp) { bool match; @@ -58,11 +59,16 @@ HRESULT p3io_filter_dispatch_irp(struct irp *irp) } switch (irp->op) { - case IRP_OP_OPEN: return p3io_handle_open(irp); - case IRP_OP_CLOSE: return p3io_handle_close(irp); - case IRP_OP_WRITE: return p3io_handle_write(irp); - case IRP_OP_READ: return p3io_handle_read(irp); - default: return irp_invoke_next(irp); + case IRP_OP_OPEN: + return p3io_handle_open(irp); + case IRP_OP_CLOSE: + return p3io_handle_close(irp); + case IRP_OP_WRITE: + return p3io_handle_write(irp); + case IRP_OP_READ: + return p3io_handle_read(irp); + default: + return irp_invoke_next(irp); } } @@ -73,7 +79,7 @@ static bool p3io_match_irp_locked(const struct irp *irp) if (irp->op == IRP_OP_OPEN) { return wstr_ends_with(irp->open_filename, L"\\p3io"); } else { - for (i = 0 ; i < p3io_handles.nitems ; i++) { + for (i = 0; i < p3io_handles.nitems; i++) { if (irp->fd == *array_item(HANDLE, &p3io_handles, i)) { return true; } @@ -110,7 +116,7 @@ static HRESULT p3io_handle_close(struct irp *irp) EnterCriticalSection(&p3io_handle_lock); - for (i = 0 ; i < p3io_handles.nitems ; i++) { + for (i = 0; i < p3io_handles.nitems; i++) { if (irp->fd == array_item(HANDLE, &p3io_handles, i)) { array_remove(HANDLE, &p3io_handles, i); @@ -141,29 +147,29 @@ static HRESULT p3io_handle_write(struct irp *irp) } switch (p3io_req_cmd(&req)) { - case P3IO_CMD_RS232_OPEN_CLOSE: - EnterCriticalSection(&p3io_cmd_lock); - p3io_uart_cmd_open_close(&req.rs232_open_close, &resp.u8); + case P3IO_CMD_RS232_OPEN_CLOSE: + EnterCriticalSection(&p3io_cmd_lock); + p3io_uart_cmd_open_close(&req.rs232_open_close, &resp.u8); - break; + break; - case P3IO_CMD_RS232_WRITE: - EnterCriticalSection(&p3io_cmd_lock); - p3io_uart_cmd_write(&req.rs232_write, &resp.rs232_write); + case P3IO_CMD_RS232_WRITE: + EnterCriticalSection(&p3io_cmd_lock); + p3io_uart_cmd_write(&req.rs232_write, &resp.rs232_write); - break; + break; - case P3IO_CMD_RS232_READ: - EnterCriticalSection(&p3io_cmd_lock); - p3io_uart_cmd_read(&req.rs232_read, &resp.rs232_read); + case P3IO_CMD_RS232_READ: + EnterCriticalSection(&p3io_cmd_lock); + p3io_uart_cmd_read(&req.rs232_read, &resp.rs232_read); - break; + break; - default: - /* Non-UART command, break out here. */ - irp->write.pos = 0; + default: + /* Non-UART command, break out here. */ + irp->write.pos = 0; - return irp_invoke_next(irp); + return irp_invoke_next(irp); } /* Frame up and queue a response packet */ diff --git a/src/main/unicorntail/usbmem.c b/src/main/unicorntail/usbmem.c index c760a94..6d7764e 100644 --- a/src/main/unicorntail/usbmem.c +++ b/src/main/unicorntail/usbmem.c @@ -41,7 +41,8 @@ void usbmem_fini(void) DeleteCriticalSection(&usbmem_lock); } -HRESULT usbmem_dispatch_irp(struct irp *irp) +HRESULT +usbmem_dispatch_irp(struct irp *irp) { HRESULT hr; @@ -76,11 +77,16 @@ static bool usbmem_match_irp(const struct irp *irp) static HRESULT usbmem_dispatch_irp_locked(struct irp *irp) { switch (irp->op) { - case IRP_OP_OPEN: return usbmem_handle_open(irp); - case IRP_OP_CLOSE: return usbmem_handle_close(irp); - case IRP_OP_WRITE: return usbmem_handle_write(irp); - case IRP_OP_READ: return usbmem_handle_read(irp); - default: return E_NOTIMPL; + case IRP_OP_OPEN: + return usbmem_handle_open(irp); + case IRP_OP_CLOSE: + return usbmem_handle_close(irp); + case IRP_OP_WRITE: + return usbmem_handle_write(irp); + case IRP_OP_READ: + return usbmem_handle_read(irp); + default: + return E_NOTIMPL; } } @@ -134,23 +140,22 @@ static HRESULT usbmem_handle_write(struct irp *irp) if (nbytes > 0) { request[nbytes - 1] = '\0'; /* This is always a CR. */ } else { - request[0] = '\0'; /* Shouldn't ever happen but w/e */ + request[0] = '\0'; /* Shouldn't ever happen but w/e */ } log_misc(">%s", request); if (request[0] != '\0') { if (str_eq(request, "sver")) { - str_cpy(usbmem_response, - sizeof(usbmem_response), - "done GQHDXJAA UNKNOWN"); + str_cpy( + usbmem_response, + sizeof(usbmem_response), + "done GQHDXJAA UNKNOWN"); } else if ( - str_eq(request, "on_a") || - str_eq(request, "on_b") || - str_eq(request, "offa") || - str_eq(request, "offb") || - strncmp(request, "lma ", 4) == 0 || - strncmp(request, "lmb ", 4) == 0 ) { + str_eq(request, "on_a") || str_eq(request, "on_b") || + str_eq(request, "offa") || str_eq(request, "offb") || + strncmp(request, "lma ", 4) == 0 || + strncmp(request, "lmb ", 4) == 0) { str_cpy(usbmem_response, sizeof(usbmem_response), "done"); } else { str_cpy(usbmem_response, sizeof(usbmem_response), "not connected"); diff --git a/src/main/util/array.c b/src/main/util/array.c index 2e07df7..900fba1 100644 --- a/src/main/util/array.c +++ b/src/main/util/array.c @@ -17,9 +17,10 @@ void array_remove_(size_t itemsz, struct array *array, size_t i) array->nitems--; - memmove(((uint8_t *) array->items) + i * itemsz, - ((uint8_t *) array->items) + (i + 1) * itemsz, - (array->nitems - i) * itemsz); + memmove( + ((uint8_t *) array->items) + i * itemsz, + ((uint8_t *) array->items) + (i + 1) * itemsz, + (array->nitems - i) * itemsz); } void *array_reserve_(size_t itemsz, struct array *array, size_t nitems) @@ -55,4 +56,3 @@ void array_fini(struct array *array) { free(array->items); } - diff --git a/src/main/util/array.h b/src/main/util/array.h index a9fe4a6..0a6589f 100644 --- a/src/main/util/array.h +++ b/src/main/util/array.h @@ -9,17 +9,14 @@ struct array { size_t nalloced; }; -#define array_item(type, array, i) \ - (&(((type *) (array)->items)[i])) +#define array_item(type, array, i) (&(((type *) (array)->items)[i])) #define array_reserve(type, array, nitems) \ - ((type *) array_reserve_(sizeof(type), array, nitems)) + ((type *) array_reserve_(sizeof(type), array, nitems)) -#define array_remove(type, array, i) \ - array_remove_(sizeof(type), array, i) +#define array_remove(type, array, i) array_remove_(sizeof(type), array, i) -#define array_append(type, array) \ - array_reserve(type, array, 1) +#define array_append(type, array) array_reserve(type, array, 1) void array_init(struct array *array); void *array_reserve_(size_t itemsz, struct array *array, size_t nitems); diff --git a/src/main/util/cmdline.c b/src/main/util/cmdline.c index 5eaa029..7386b0d 100644 --- a/src/main/util/cmdline.c +++ b/src/main/util/cmdline.c @@ -8,8 +8,8 @@ #include -static void push_argv(int *argc, char ***argv, const char *begin, - const char *end) +static void +push_argv(int *argc, char ***argv, const char *begin, const char *end) { size_t nchars; char *str; @@ -37,7 +37,7 @@ void args_recover(int *argc_out, char ***argv_out) argv = NULL; quote = false; - for (begin = pos = GetCommandLine() ; *pos ; pos++) { + for (begin = pos = GetCommandLine(); *pos; pos++) { switch (*pos) { case '"': if (!quote) { @@ -81,7 +81,7 @@ void args_free(int argc, char **argv) { int i; - for (i = 0 ; i < argc ; i++) { + for (i = 0; i < argc; i++) { free(argv[i]); } @@ -98,7 +98,7 @@ char *args_join(int argc, char **argv) nchars = 0; - for (i = 0 ; i < argc ; i++) { + for (i = 0; i < argc; i++) { /* 3 = leading space plus two surrounding quotes. The first element has no leading space, but this is counterbalanced by the fact that the string needs a NUL terminator. */ @@ -108,7 +108,7 @@ char *args_join(int argc, char **argv) str = xmalloc(nchars); pos = str; - for (i = 0 ; i < argc ; i++) { + for (i = 0; i < argc; i++) { if (i != 0) { *pos++ = ' '; } @@ -126,4 +126,3 @@ char *args_join(int argc, char **argv) return str; } - diff --git a/src/main/util/crc.c b/src/main/util/crc.c index 8ed0fc5..39b2fe0 100644 --- a/src/main/util/crc.c +++ b/src/main/util/crc.c @@ -8,15 +8,15 @@ uint8_t crc8(const void *ptr, size_t nbytes, uint8_t in) size_t i; size_t j; - //log_assert(ptr != NULL); + // log_assert(ptr != NULL); bytes = ptr; crc = ~in; - for (i = 0 ; i < nbytes ; i++) { + for (i = 0; i < nbytes; i++) { crc ^= bytes[i]; - for (j = 0 ; j < 8 ; j++) { + for (j = 0; j < 8; j++) { if (crc & 1) { crc = (crc >> 1) ^ 0x8C; } else { @@ -35,15 +35,15 @@ uint16_t crc16(const void *ptr, size_t nbytes, uint16_t in) size_t i; size_t j; - //log_assert(ptr != NULL); + // log_assert(ptr != NULL); bytes = ptr; crc = ~in; - for (i = 0 ; i < nbytes ; i++) { + for (i = 0; i < nbytes; i++) { crc ^= bytes[i]; - for (j = 0 ; j < 8 ; j++) { + for (j = 0; j < 8; j++) { if (crc & 1) { crc = (crc >> 1) ^ 0x8408; } else { @@ -62,15 +62,15 @@ uint32_t crc32(const void *ptr, size_t nbytes, uint32_t in) size_t i; size_t j; - //log_assert(ptr != NULL); + // log_assert(ptr != NULL); bytes = ptr; crc = ~in; - for (i = 0 ; i < nbytes ; i++) { + for (i = 0; i < nbytes; i++) { crc ^= bytes[i]; - for (j = 0 ; j < 8 ; j++) { + for (j = 0; j < 8; j++) { if (crc & 1) { crc = (crc >> 1) ^ 0xEDB88320; } else { diff --git a/src/main/util/crypto.c b/src/main/util/crypto.c index 62f412f..1940404 100644 --- a/src/main/util/crypto.c +++ b/src/main/util/crypto.c @@ -7,10 +7,10 @@ #include #include -static const char vista_prov[] - = "Microsoft Enhanced RSA and AES Cryptographic Provider"; -static const char winxp_prov[] - = "Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)"; +static const char vista_prov[] = + "Microsoft Enhanced RSA and AES Cryptographic Provider"; +static const char winxp_prov[] = + "Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)"; static int init_count; static HCRYPTPROV prov; @@ -36,10 +36,10 @@ void crypto_init(void) prov_name = vista_prov; } - if (!CryptAcquireContext(&prov, NULL, prov_name, PROV_RSA_AES, - CRYPT_VERIFYCONTEXT)) { - log_fatal("CryptAcquireContext failed: %08x", - (unsigned int) GetLastError()); + if (!CryptAcquireContext( + &prov, NULL, prov_name, PROV_RSA_AES, CRYPT_VERIFYCONTEXT)) { + log_fatal( + "CryptAcquireContext failed: %08x", (unsigned int) GetLastError()); } } @@ -57,13 +57,16 @@ void crypto_fini(void) log_misc("Shutting down win32 crypto wrappers"); if (!CryptReleaseContext(prov, 0)) { - log_fatal("CryptReleaseContext failed: %08x", - (unsigned int) GetLastError()); + log_fatal( + "CryptReleaseContext failed: %08x", (unsigned int) GetLastError()); } } -void md5_compute(const void *in_bytes, size_t in_nbytes, uint8_t *out_bytes, - size_t out_nbytes) +void md5_compute( + const void *in_bytes, + size_t in_nbytes, + uint8_t *out_bytes, + size_t out_nbytes) { struct md5 md5; @@ -75,16 +78,16 @@ void md5_compute(const void *in_bytes, size_t in_nbytes, uint8_t *out_bytes, void md5_init(struct md5 *md5) { if (!CryptCreateHash(prov, CALG_MD5, 0, 0, &md5->hash)) { - log_fatal("CryptCreateHash(CALG_MD5) failed: %08x", - (unsigned int) GetLastError()); + log_fatal( + "CryptCreateHash(CALG_MD5) failed: %08x", + (unsigned int) GetLastError()); } } void md5_append(struct md5 *md5, const void *bytes, size_t nbytes) { if (!CryptHashData(md5->hash, bytes, nbytes, 0)) { - log_fatal("CryptHashData failed: %08x", - (unsigned int) GetLastError()); + log_fatal("CryptHashData failed: %08x", (unsigned int) GetLastError()); } } @@ -98,18 +101,22 @@ void md5_fini(struct md5 *md5, uint8_t *output, size_t nbytes) if (output != NULL) { if (!CryptGetHashParam(md5->hash, HP_HASHVAL, output, &tmp, 0)) { - log_fatal("Error getting MD5 result: %08x", - (unsigned int) GetLastError()); + log_fatal( + "Error getting MD5 result: %08x", + (unsigned int) GetLastError()); } } if (!CryptDestroyHash(md5->hash)) { - log_fatal("CryptDestroyHash failed: %08x", - (unsigned int) GetLastError()); + log_fatal( + "CryptDestroyHash failed: %08x", (unsigned int) GetLastError()); } } -#define SWAP(x, y, tmp) tmp = x; x = y; y = tmp +#define SWAP(x, y, tmp) \ + tmp = x; \ + x = y; \ + y = tmp void arc4_init(struct arc4 *arc4, const uint8_t *key, size_t key_nbytes) { @@ -120,13 +127,13 @@ void arc4_init(struct arc4 *arc4, const uint8_t *key, size_t key_nbytes) arc4->i = 0; arc4->j = 0; - for (i = 0 ; i < 256 ; i++) { + for (i = 0; i < 256; i++) { arc4->S[i] = (uint8_t) i; } j = 0; - for (i = 0 ; i < 256 ; i++) { + for (i = 0; i < 256; i++) { j = j + arc4->S[i] + key[i % key_nbytes]; SWAP(arc4->S[i], arc4->S[j], tmp); } @@ -137,38 +144,37 @@ void arc4_apply(struct arc4 *arc4, uint8_t *bytes, size_t nbytes) size_t i; uint8_t tmp; - for (i = 0 ; i < nbytes ; i++) { + for (i = 0; i < nbytes; i++) { arc4->i += 1; arc4->j += arc4->S[arc4->i]; SWAP(arc4->S[arc4->i], arc4->S[arc4->j], tmp); - bytes[i] ^= arc4->S[(uint8_t) (arc4->S[arc4->i] + arc4->S[arc4->j])]; + bytes[i] ^= arc4->S[(uint8_t)(arc4->S[arc4->i] + arc4->S[arc4->j])]; } } - -static uint32_t blowfish_F(struct blowfish* blowfish, uint32_t x) +static uint32_t blowfish_F(struct blowfish *blowfish, uint32_t x) { - unsigned short a, b, c, d; - uint32_t y; + unsigned short a, b, c, d; + uint32_t y; - d = x & 0x00FF; - x >>= 8; - c = x & 0x00FF; - x >>= 8; - b = x & 0x00FF; - x >>= 8; - a = x & 0x00FF; + d = x & 0x00FF; + x >>= 8; + c = x & 0x00FF; + x >>= 8; + b = x & 0x00FF; + x >>= 8; + a = x & 0x00FF; - y = blowfish->S[0][a] + blowfish->S[1][b]; - y = y ^ blowfish->S[2][c]; - y = y + blowfish->S[3][d]; - return y; + y = blowfish->S[0][a] + blowfish->S[1][b]; + y = y ^ blowfish->S[2][c]; + y = y + blowfish->S[3][d]; + return y; } -void blowfish_init(struct blowfish* blowfish, const uint8_t* key, - size_t key_length) +void blowfish_init( + struct blowfish *blowfish, const uint8_t *key, size_t key_length) { int i, j, k; uint32_t data, datal, datar; @@ -205,12 +211,12 @@ void blowfish_init(struct blowfish* blowfish, const uint8_t* key, } } -void blowfish_encrypt(struct blowfish* blowfish, uint32_t* xl, uint32_t* xr) +void blowfish_encrypt(struct blowfish *blowfish, uint32_t *xl, uint32_t *xr) { - uint32_t Xl; - uint32_t Xr; - uint32_t temp; - short i; + uint32_t Xl; + uint32_t Xr; + uint32_t temp; + short i; Xl = *xl; Xr = *xr; @@ -232,12 +238,12 @@ void blowfish_encrypt(struct blowfish* blowfish, uint32_t* xl, uint32_t* xr) *xr = Xr; } -void blowfish_decrypt(struct blowfish* blowfish, uint32_t* xl, uint32_t* xr) +void blowfish_decrypt(struct blowfish *blowfish, uint32_t *xl, uint32_t *xr) { - uint32_t Xl; - uint32_t Xr; - uint32_t temp; - short i; + uint32_t Xl; + uint32_t Xr; + uint32_t temp; + short i; Xl = *xl; Xr = *xr; diff --git a/src/main/util/crypto.h b/src/main/util/crypto.h index 0701d66..ad6c83b 100644 --- a/src/main/util/crypto.h +++ b/src/main/util/crypto.h @@ -1,8 +1,8 @@ #ifndef UTIL_CRYPTO_H #define UTIL_CRYPTO_H -#include #include +#include #include #include @@ -26,8 +26,11 @@ void crypto_init(void); void crypto_gen_random(void *bytes, size_t nbytes); void crypto_fini(void); -void md5_compute(const void *in_bytes, size_t in_nbytes, uint8_t *out_bytes, - size_t out_nbytes); +void md5_compute( + const void *in_bytes, + size_t in_nbytes, + uint8_t *out_bytes, + size_t out_nbytes); void md5_init(struct md5 *md5); void md5_append(struct md5 *md5, const void *bytes, size_t nbytes); void md5_fini(struct md5 *md5, uint8_t *output, size_t nbytes); @@ -35,8 +38,9 @@ void md5_fini(struct md5 *md5, uint8_t *output, size_t nbytes); void arc4_init(struct arc4 *arc4, const uint8_t *key, size_t key_nbytes); void arc4_apply(struct arc4 *arc4, uint8_t *bytes, size_t nbytes); -void blowfish_init(struct blowfish* blowfish, const uint8_t* key, size_t key_length); -void blowfish_encrypt(struct blowfish* blowfish, uint32_t* xl, uint32_t* xr); -void blowfish_decrypt(struct blowfish* blowfish, uint32_t* xl, uint32_t* xr); +void blowfish_init( + struct blowfish *blowfish, const uint8_t *key, size_t key_length); +void blowfish_encrypt(struct blowfish *blowfish, uint32_t *xl, uint32_t *xr); +void blowfish_decrypt(struct blowfish *blowfish, uint32_t *xl, uint32_t *xr); #endif diff --git a/src/main/util/defs.h b/src/main/util/defs.h index f3f0586..eaa3778 100644 --- a/src/main/util/defs.h +++ b/src/main/util/defs.h @@ -13,6 +13,6 @@ #define lengthof(x) (sizeof(x) / sizeof(x[0])) #define containerof(ptr, outer_t, member) \ - ((void *) (((uint8_t *) ptr) - offsetof(outer_t, member))) + ((void *) (((uint8_t *) ptr) - offsetof(outer_t, member))) #endif diff --git a/src/main/util/fs.c b/src/main/util/fs.c index 7174b88..9af25cf 100644 --- a/src/main/util/fs.c +++ b/src/main/util/fs.c @@ -1,5 +1,5 @@ -#include #include +#include #include #include @@ -12,8 +12,8 @@ #include "util/mem.h" #include "util/str.h" -bool file_load(const char *filename, void **out_bytes, size_t *out_nbytes, - bool text_mode) +bool file_load( + const char *filename, void **out_bytes, size_t *out_nbytes, bool text_mode) { FILE *f; void *bytes; @@ -70,11 +70,11 @@ bool file_load(const char *filename, void **out_bytes, size_t *out_nbytes, /* Add null terminator */ if (text_mode) { - ((char*) bytes)[nbytes - 1] = '\0'; + ((char *) bytes)[nbytes - 1] = '\0'; } - log_misc("File loaded %s, size %lu", filename, - (long unsigned int) *out_nbytes); + log_misc( + "File loaded %s, size %lu", filename, (long unsigned int) *out_nbytes); return true; @@ -120,22 +120,21 @@ open_fail: return false; } -bool path_exists(const char* path) +bool path_exists(const char *path) { DWORD attrib = GetFileAttributes(path); return attrib != INVALID_FILE_ATTRIBUTES; } -bool path_exists_wstr(const wchar_t* path) +bool path_exists_wstr(const wchar_t *path) { DWORD attrib = GetFileAttributesW(path); return attrib != INVALID_FILE_ATTRIBUTES; } -FILE *fopen_appdata(const char *vendor, const char *filename, - const char *mode) +FILE *fopen_appdata(const char *vendor, const char *filename, const char *mode) { char root[MAX_PATH]; char path[MAX_PATH]; @@ -145,18 +144,17 @@ FILE *fopen_appdata(const char *vendor, const char *filename, hr = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, root); if (FAILED(hr)) { - log_warning("Failed to get AppData folder: hr=%08x", - (unsigned int) hr); + log_warning("Failed to get AppData folder: hr=%08x", (unsigned int) hr); return NULL; } str_format(path, sizeof(path), "%s\\%s", root, vendor); - if (!CreateDirectory(path, NULL) - && GetLastError() != ERROR_ALREADY_EXISTS) { - log_warning("Failed to create %s: %08x", - path, (unsigned int) GetLastError()); + if (!CreateDirectory(path, NULL) && + GetLastError() != ERROR_ALREADY_EXISTS) { + log_warning( + "Failed to create %s: %08x", path, (unsigned int) GetLastError()); return NULL; } @@ -165,8 +163,8 @@ FILE *fopen_appdata(const char *vendor, const char *filename, f = fopen(path, mode); if (f == NULL) { - log_warning("fopen(\"%s\", \"%s\") failed: %s", - path, mode, strerror(errno)); + log_warning( + "fopen(\"%s\", \"%s\") failed: %s", path, mode, strerror(errno)); } return f; @@ -179,17 +177,17 @@ bool path_mkdir(const char *path) str_cpy(buf, lengthof(buf), path); - for (pos = path_next_element(buf) - ; pos - ; pos = path_next_element(pos + 1)) { + for (pos = path_next_element(buf); pos; pos = path_next_element(pos + 1)) { *pos = '\0'; if (strlen(buf) != 2 || buf[1] != ':') { CreateDirectory(buf, NULL); if (GetLastError() != ERROR_ALREADY_EXISTS) { - log_warning("%s: Cannot create directory: %#x", - buf, (unsigned int) GetLastError()); + log_warning( + "%s: Cannot create directory: %#x", + buf, + (unsigned int) GetLastError()); return false; } @@ -201,8 +199,10 @@ bool path_mkdir(const char *path) CreateDirectory(buf, NULL); if (GetLastError() != ERROR_ALREADY_EXISTS) { - log_warning("%s: Cannot create directory: %#x", - buf, (unsigned int) GetLastError()); + log_warning( + "%s: Cannot create directory: %#x", + buf, + (unsigned int) GetLastError()); return false; } @@ -214,7 +214,7 @@ char *path_next_element(char *path) { char *c; - for (c = path ; *c ; c++) { + for (c = path; *c; c++) { if (*c == '/' || *c == '\\') { return c; } @@ -264,4 +264,3 @@ void write_str(FILE *f, const char *str) fwrite(&len, sizeof(len), 1, f); fwrite(str, len, 1, f); } - diff --git a/src/main/util/fs.h b/src/main/util/fs.h index b27ebcd..471779b 100644 --- a/src/main/util/fs.h +++ b/src/main/util/fs.h @@ -17,8 +17,8 @@ * false for binary mode * @return True on success, false on error */ -bool file_load(const char *filename, void **bytes, size_t *nbytes, - bool text_mode); +bool file_load( + const char *filename, void **bytes, size_t *nbytes, bool text_mode); /** * Save a buffer to a file (overwrite any existing files with the same name) @@ -36,7 +36,7 @@ bool file_save(const char *filename, const void *bytes, size_t nbytes); * @param path Path as c-string. * @return True if exists, false otherwise */ -bool path_exists(const char* path); +bool path_exists(const char *path); /** * Check if a normal file, folder, symlink, ... exists @@ -44,10 +44,9 @@ bool path_exists(const char* path); * @param path Path as w-string. * @return True if exists, false otherwise */ -bool path_exists_wstr(const wchar_t* path); +bool path_exists_wstr(const wchar_t *path); -FILE *fopen_appdata(const char *vendor, const char *filename, - const char *mode); +FILE *fopen_appdata(const char *vendor, const char *filename, const char *mode); /** * Create a new directory @@ -58,17 +57,17 @@ FILE *fopen_appdata(const char *vendor, const char *filename, bool path_mkdir(const char *path); char *path_next_element(char *path); -#define read_bin(f, val, size) (fread((val), (size), 1, (f)) == 1) -#define read_u8(f, val) (fread((val), 1, 1, (f)) == 1) -#define read_u16(f, val) (fread((val), 2, 1, (f)) == 1) -#define read_u32(f, val) (fread((val), 4, 1, (f)) == 1) +#define read_bin(f, val, size) (fread((val), (size), 1, (f)) == 1) +#define read_u8(f, val) (fread((val), 1, 1, (f)) == 1) +#define read_u16(f, val) (fread((val), 2, 1, (f)) == 1) +#define read_u32(f, val) (fread((val), 4, 1, (f)) == 1) bool read_str(FILE *f, char **str); #define write_bin(f, val, size) fwrite((val), (size), 1, (f)) -#define write_u8(f, val) fwrite((val), 1, 1, (f)) -#define write_u16(f, val) fwrite((val), 2, 1, (f)) -#define write_u32(f, val) fwrite((val), 4, 1, (f)) +#define write_u8(f, val) fwrite((val), 1, 1, (f)) +#define write_u16(f, val) fwrite((val), 2, 1, (f)) +#define write_u32(f, val) fwrite((val), 4, 1, (f)) void write_str(FILE *f, const char *str); diff --git a/src/main/util/hex.c b/src/main/util/hex.c index 4261db8..1ac6b4d 100644 --- a/src/main/util/hex.c +++ b/src/main/util/hex.c @@ -31,9 +31,9 @@ bool hex_decode(void *ptr, size_t nbytes, const char *chars, size_t nchars) log_assert(nchars <= 2 * nbytes); log_assert(nchars % 2 == 0); - for (i = 0 ; i < nchars / 2; i++) { - if ( !hex_decode_nibble(chars[2 * i + 0], &hi) || - !hex_decode_nibble(chars[2 * i + 1], &lo)) { + for (i = 0; i < nchars / 2; i++) { + if (!hex_decode_nibble(chars[2 * i + 0], &hi) || + !hex_decode_nibble(chars[2 * i + 1], &lo)) { return false; } @@ -43,8 +43,12 @@ bool hex_decode(void *ptr, size_t nbytes, const char *chars, size_t nchars) return true; } -static void hex_encode(const void *ptr, size_t nbytes, char *chars, - size_t nchars, const char *digits) +static void hex_encode( + const void *ptr, + size_t nbytes, + char *chars, + size_t nchars, + const char *digits) { const uint8_t *bytes = ptr; @@ -52,7 +56,7 @@ static void hex_encode(const void *ptr, size_t nbytes, char *chars, log_assert(nchars >= 2 * nbytes + 1); - for (i = 0 ; i < nbytes ; i++) { + for (i = 0; i < nbytes; i++) { chars[i * 2 + 0] = digits[bytes[i] >> 4]; chars[i * 2 + 1] = digits[bytes[i] & 15]; } @@ -69,4 +73,3 @@ void hex_encode_uc(const void *bytes, size_t nbytes, char *chars, size_t nchars) { hex_encode(bytes, nbytes, chars, nchars, "0123456789ABCDEF"); } - diff --git a/src/main/util/hex.h b/src/main/util/hex.h index bd48b90..c3c37c6 100644 --- a/src/main/util/hex.h +++ b/src/main/util/hex.h @@ -4,11 +4,10 @@ #include #include -bool hex_decode(void *bytes, size_t nbytes, const char *chars, - size_t nchars); -void hex_encode_uc(const void *bytes, size_t nbytes, char *chars, - size_t nchars); -void hex_encode_lc(const void *bytes, size_t nbytes, char *chars, - size_t nchars); +bool hex_decode(void *bytes, size_t nbytes, const char *chars, size_t nchars); +void hex_encode_uc( + const void *bytes, size_t nbytes, char *chars, size_t nchars); +void hex_encode_lc( + const void *bytes, size_t nbytes, char *chars, size_t nchars); #endif diff --git a/src/main/util/hr.c b/src/main/util/hr.c index 70c67c1..cdfb404 100644 --- a/src/main/util/hr.c +++ b/src/main/util/hr.c @@ -4,7 +4,8 @@ #include "util/hr.h" -HRESULT hr_from_win32(void) +HRESULT +hr_from_win32(void) { return HRESULT_FROM_WIN32(GetLastError()); } @@ -20,20 +21,41 @@ void hr_propagate_win32_(HRESULT hr) } else { // https://docs.microsoft.com/en-us/windows/desktop/seccrypto/common-hresult-values switch (hr) { - case E_ABORT: result = ERROR_OPERATION_ABORTED; break; - case E_ACCESSDENIED: result = ERROR_ACCESS_DENIED; break; - case E_FAIL: result = ERROR_GEN_FAILURE; break; - case E_HANDLE: result = ERROR_INVALID_HANDLE; break; - case E_INVALIDARG: result = ERROR_INVALID_PARAMETER; break; - case E_NOINTERFACE: result = ERROR_NOT_SUPPORTED; break; - case E_NOTIMPL: result = ERROR_NOT_SUPPORTED; break; - case E_OUTOFMEMORY: result = ERROR_OUTOFMEMORY; break; - case E_POINTER: result = ERROR_INVALID_ADDRESS; break; - case E_UNEXPECTED: result = ERROR_INTERNAL_ERROR; break; - default: result = ERROR_INTERNAL_ERROR; break; + case E_ABORT: + result = ERROR_OPERATION_ABORTED; + break; + case E_ACCESSDENIED: + result = ERROR_ACCESS_DENIED; + break; + case E_FAIL: + result = ERROR_GEN_FAILURE; + break; + case E_HANDLE: + result = ERROR_INVALID_HANDLE; + break; + case E_INVALIDARG: + result = ERROR_INVALID_PARAMETER; + break; + case E_NOINTERFACE: + result = ERROR_NOT_SUPPORTED; + break; + case E_NOTIMPL: + result = ERROR_NOT_SUPPORTED; + break; + case E_OUTOFMEMORY: + result = ERROR_OUTOFMEMORY; + break; + case E_POINTER: + result = ERROR_INVALID_ADDRESS; + break; + case E_UNEXPECTED: + result = ERROR_INTERNAL_ERROR; + break; + default: + result = ERROR_INTERNAL_ERROR; + break; } } SetLastError(result); } - diff --git a/src/main/util/iobuf.c b/src/main/util/iobuf.c index 721043e..95096db 100644 --- a/src/main/util/iobuf.c +++ b/src/main/util/iobuf.c @@ -35,16 +35,16 @@ void iobuf_flip(struct const_iobuf *dest, const struct iobuf *src) dest->nbytes = src->pos; } -void iobuf_log(struct iobuf* buffer, const char* tag) +void iobuf_log(struct iobuf *buffer, const char *tag) { - char* str; + char *str; size_t str_len; str_len = buffer->nbytes * 2 + 1; str = xmalloc(str_len); - log_misc("[%s] (%d %d)", tag, (uint32_t) buffer->nbytes, - (uint32_t) buffer->pos); + log_misc( + "[%s] (%d %d)", tag, (uint32_t) buffer->nbytes, (uint32_t) buffer->pos); hex_encode_uc(buffer->bytes, buffer->nbytes, str, str_len); @@ -53,16 +53,16 @@ void iobuf_log(struct iobuf* buffer, const char* tag) free(str); } -void iobuf_log_const(struct const_iobuf* buffer, const char* tag) +void iobuf_log_const(struct const_iobuf *buffer, const char *tag) { - char* str; + char *str; size_t str_len; str_len = buffer->nbytes * 2 + 1; str = xmalloc(str_len); - log_misc("[%s] (%d %d)", tag, (uint32_t) buffer->nbytes, - (uint32_t) buffer->pos); + log_misc( + "[%s] (%d %d)", tag, (uint32_t) buffer->nbytes, (uint32_t) buffer->pos); hex_encode_uc(buffer->bytes, buffer->nbytes, str, str_len); diff --git a/src/main/util/iobuf.h b/src/main/util/iobuf.h index a2f63f4..fbd9f70 100644 --- a/src/main/util/iobuf.h +++ b/src/main/util/iobuf.h @@ -20,8 +20,8 @@ size_t iobuf_move(struct iobuf *dest, struct const_iobuf *src); void iobuf_flip(struct const_iobuf *dest, const struct iobuf *src); -void iobuf_log(struct iobuf* buffer, const char* tag); +void iobuf_log(struct iobuf *buffer, const char *tag); -void iobuf_log_const(struct const_iobuf* buffer, const char* tag); +void iobuf_log_const(struct const_iobuf *buffer, const char *tag); #endif diff --git a/src/main/util/list.c b/src/main/util/list.c index 3ef3dfe..4029e8b 100644 --- a/src/main/util/list.c +++ b/src/main/util/list.c @@ -4,9 +4,8 @@ #include "util/list.h" extern inline struct list_node *list_peek_head(struct list *list); -extern inline const struct list_node *list_peek_head_const( - const struct list *list -); +extern inline const struct list_node * +list_peek_head_const(const struct list *list); void list_init(struct list *list) { @@ -30,7 +29,7 @@ bool list_contains(struct list *list, struct list_node *node) { struct list_node *pos; - for (pos = list->head ; pos != NULL ; pos = pos->next) { + for (pos = list->head; pos != NULL; pos = pos->next) { if (pos == node) { return true; } @@ -64,9 +63,8 @@ void list_remove(struct list *list, struct list_node *node) struct list_node *pos; struct list_node *prev; - for (prev = NULL, pos = list->head - ; pos != NULL - ; prev = pos, pos = pos->next) { + for (prev = NULL, pos = list->head; pos != NULL; + prev = pos, pos = pos->next) { if (pos == node) { if (prev != NULL) { prev->next = node->next; @@ -84,5 +82,3 @@ void list_remove(struct list *list, struct list_node *node) } } } - - diff --git a/src/main/util/log.c b/src/main/util/log.c index 59aab8b..925da9b 100644 --- a/src/main/util/log.c +++ b/src/main/util/log.c @@ -16,17 +16,17 @@ static void log_builtin_fatal(const char *module, const char *fmt, ...); static void log_builtin_info(const char *module, const char *fmt, ...); static void log_builtin_misc(const char *module, const char *fmt, ...); static void log_builtin_warning(const char *module, const char *fmt, ...); -static void log_builtin_format(unsigned int msg_level, const char *module, - const char *fmt, va_list ap); +static void log_builtin_format( + unsigned int msg_level, const char *module, const char *fmt, va_list ap); -#define IMPLEMENT_SINK(name, msg_level) \ +#define IMPLEMENT_SINK(name, msg_level) \ static void name(const char *module, const char *fmt, ...) \ - { \ - va_list ap; \ - \ - va_start(ap, fmt); \ - log_builtin_format(msg_level, module, fmt, ap); \ - va_end(ap); \ + { \ + va_list ap; \ + \ + va_start(ap, fmt); \ + log_builtin_format(msg_level, module, fmt, ap); \ + va_end(ap); \ } IMPLEMENT_SINK(log_builtin_info, 2) @@ -45,8 +45,8 @@ static void log_builtin_fatal(const char *module, const char *fmt, ...) ExitProcess(EXIT_FAILURE); } -static void log_builtin_format(unsigned int msg_level, const char *module, - const char *fmt, va_list ap) +static void log_builtin_format( + unsigned int msg_level, const char *module, const char *fmt, va_list ap) { static const char chars[] = "FWIM"; @@ -56,8 +56,8 @@ static void log_builtin_format(unsigned int msg_level, const char *module, int result; str_vformat(msg, sizeof(msg), fmt, ap); - result = str_format(line, sizeof(line), "%c:%s: %s\n", chars[msg_level], - module, msg); + result = str_format( + line, sizeof(line), "%c:%s: %s\n", chars[msg_level], module, msg); if (msg_level <= log_level) { log_writer(log_writer_ctx, line, result); @@ -69,8 +69,11 @@ void log_assert_body(const char *file, int line, const char *function) log_impl_fatal("assert", "%s:%d: function `%s'", file, line, function); } -void log_to_external(log_formatter_t misc, log_formatter_t info, - log_formatter_t warning, log_formatter_t fatal) +void log_to_external( + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal) { log_impl_misc = misc; log_impl_info = info; @@ -116,11 +119,12 @@ void log_writer_stderr(void *ctx, const char *chars, size_t nchars) void log_writer_file(void *ctx, const char *chars, size_t nchars) { fwrite(chars, 1, nchars, (FILE *) ctx); - fflush((FILE*) ctx); + fflush((FILE *) ctx); } void log_writer_null(void *ctx, const char *chars, size_t nchars) -{} +{ +} log_formatter_t log_impl_misc = log_builtin_misc; log_formatter_t log_impl_info = log_builtin_info; @@ -128,4 +132,3 @@ log_formatter_t log_impl_warning = log_builtin_warning; log_formatter_t log_impl_fatal = log_builtin_fatal; static log_writer_t log_writer = log_writer_null; static unsigned int log_level = 4; - diff --git a/src/main/util/log.h b/src/main/util/log.h index 9102226..a60cdb7 100644 --- a/src/main/util/log.h +++ b/src/main/util/log.h @@ -25,11 +25,11 @@ /* This doesn't really belong here, but it's what libavs does so w/e */ -#define log_assert(x) \ - do { \ - if (!(x)) { \ +#define log_assert(x) \ + do { \ + if (!(x)) { \ log_assert_body(__FILE__, __LINE__, __FUNCTION__); \ - } \ + } \ } while (0) #else @@ -37,14 +37,19 @@ #define log_misc(...) #define log_info(...) #define log_warning(...) -#define log_assert(x) do { if (!(x)) { abort(); } } while (0) +#define log_assert(x) \ + do { \ + if (!(x)) { \ + abort(); \ + } \ + } while (0) #endif -#define log_fatal(...) \ - do { \ +#define log_fatal(...) \ + do { \ log_impl_fatal(LOG_MODULE, __VA_ARGS__); \ - abort(); \ + abort(); \ } while (0) typedef void (*log_writer_t)(void *ctx, const char *chars, size_t nchars); @@ -55,8 +60,11 @@ extern log_formatter_t log_impl_warning; extern log_formatter_t log_impl_fatal; void log_assert_body(const char *file, int line, const char *function); -void log_to_external(log_formatter_t misc, log_formatter_t info, - log_formatter_t warning, log_formatter_t fatal); +void log_to_external( + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal); void log_to_writer(log_writer_t writer, void *ctx); void log_set_level(unsigned int new_level); diff --git a/src/main/util/mem.c b/src/main/util/mem.c index 64b49de..bf674dd 100644 --- a/src/main/util/mem.c +++ b/src/main/util/mem.c @@ -2,10 +2,10 @@ #include +#include #include #include #include -#include #include "util/log.h" @@ -58,32 +58,38 @@ bool mem_nop(size_t mem_offset, size_t length) { DWORD oldProt; - if (VirtualProtect((void*) (mem_offset), length, PAGE_EXECUTE_READWRITE, - &oldProt) == 0) { + if (VirtualProtect( + (void *) (mem_offset), length, PAGE_EXECUTE_READWRITE, &oldProt) == + 0) { return false; } for (size_t i = 0; i < length; i++) { - ((uint8_t*) mem_offset)[i] = 0x90; + ((uint8_t *) mem_offset)[i] = 0x90; } - if (VirtualProtect((void*) (mem_offset), length, oldProt, &oldProt) == 0) { + if (VirtualProtect((void *) (mem_offset), length, oldProt, &oldProt) == 0) { return false; } return true; } -void* mem_find_signiture(const uint8_t* sig, uint32_t sig_len, - int32_t sig_offset, void* start_addr, void* end_addr, int32_t alignment) +void *mem_find_signiture( + const uint8_t *sig, + uint32_t sig_len, + int32_t sig_offset, + void *start_addr, + void *end_addr, + int32_t alignment) { - size_t pos; + size_t pos; - for (pos = (size_t) start_addr; pos < (size_t) end_addr; pos += alignment) { - if (!memcmp((void*) pos, sig, sig_len)) { - return (void*) (pos + sig_offset); - } - } + for (pos = (size_t) start_addr; pos < (size_t) end_addr; pos += alignment) { + if (!memcmp((void *) pos, sig, sig_len)) { + return (void *) (pos + sig_offset); + } + } - return NULL; + return NULL; } \ No newline at end of file diff --git a/src/main/util/mem.h b/src/main/util/mem.h index 7ea9508..d805f70 100644 --- a/src/main/util/mem.h +++ b/src/main/util/mem.h @@ -1,8 +1,8 @@ #ifndef UTIL_MEM_H #define UTIL_MEM_H -#include #include +#include #include void *xcalloc(size_t nbytes); @@ -24,7 +24,12 @@ bool mem_nop(size_t mem_offset, size_t length); * @return If found, pointer to memory where the signiture was found (first * occurance) with the signiture offset added, NULL otherwise */ -void* mem_find_signiture(const uint8_t* sig, uint32_t sig_len, - int32_t sig_offset, void* start_addr, void* end_addr, int32_t alignment); +void *mem_find_signiture( + const uint8_t *sig, + uint32_t sig_len, + int32_t sig_offset, + void *start_addr, + void *end_addr, + int32_t alignment); #endif diff --git a/src/main/util/msg-thread.c b/src/main/util/msg-thread.c index d01da52..6b5623d 100644 --- a/src/main/util/msg-thread.c +++ b/src/main/util/msg-thread.c @@ -41,15 +41,16 @@ static int msg_thread_proc(void *param) Because THAT totally makes sense. */ - hwnd = CreateWindowEx(0, msg_wndclass_name, NULL, 0, 0, 0, 0, 0, - NULL, NULL, inst, NULL); + hwnd = CreateWindowEx( + 0, msg_wndclass_name, NULL, 0, 0, 0, 0, 0, NULL, NULL, inst, NULL); msg_window_setup(hwnd); /* callback */ PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); SetEvent(msg_thread_ready); - while (msg_thread_step(hwnd)); + while (msg_thread_step(hwnd)) + ; msg_window_teardown(hwnd); /* callback */ @@ -64,8 +65,8 @@ static bool msg_thread_step(HWND hwnd) MSG msg; DWORD result; - result = MsgWaitForMultipleObjectsEx(1, &msg_thread_stop, INFINITE, - QS_ALLINPUT, MWMO_ALERTABLE); + result = MsgWaitForMultipleObjectsEx( + 1, &msg_thread_stop, INFINITE, QS_ALLINPUT, MWMO_ALERTABLE); switch (result) { case WAIT_OBJECT_0: @@ -83,14 +84,15 @@ static bool msg_thread_step(HWND hwnd) return true; case WAIT_FAILED: - log_warning("MsgWaitForMultipleObjectsEx failed: %08x", - (unsigned int) GetLastError()); + log_warning( + "MsgWaitForMultipleObjectsEx failed: %08x", + (unsigned int) GetLastError()); return false; default: - log_warning("Spurious wakeup: result = %08x", - (unsigned int) result); + log_warning( + "Spurious wakeup: result = %08x", (unsigned int) result); return true; } @@ -115,4 +117,3 @@ void msg_thread_fini(void) CloseHandle(msg_thread_stop); } - diff --git a/src/main/util/msg-thread.h b/src/main/util/msg-thread.h index f14b975..7e526cb 100644 --- a/src/main/util/msg-thread.h +++ b/src/main/util/msg-thread.h @@ -7,8 +7,8 @@ void msg_thread_fini(void); /* Define these callbacks */ extern void msg_window_setup(HWND hwnd); -extern LRESULT WINAPI msg_window_proc(HWND hwnd, UINT msg, WPARAM wparam, - LPARAM lparam); +extern LRESULT WINAPI +msg_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); extern void msg_window_teardown(HWND hwnd); #endif diff --git a/src/main/util/net.c b/src/main/util/net.c index 556970a..492e3ef 100644 --- a/src/main/util/net.c +++ b/src/main/util/net.c @@ -13,7 +13,7 @@ #include -static bool net_parse_url(const char* str, struct net_addr* addr) +static bool net_parse_url(const char *str, struct net_addr *addr) { char host[NET_MAX_URL_HOSTNAME_LEN + 1]; char path[NET_MAX_URL_PATH_LEN + 1]; @@ -38,8 +38,8 @@ static bool net_parse_url(const char* str, struct net_addr* addr) /* Try url with IPV4 address */ - if (sscanf(str, "%d.%d.%d.%d", &ipv4[0], &ipv4[1], &ipv4[2], - &ipv4[3]) == 4) { + if (sscanf(str, "%d.%d.%d.%d", &ipv4[0], &ipv4[1], &ipv4[2], &ipv4[3]) == + 4) { addr->url.type = NET_ADDR_TYPE_IPV4; addr->url.ipv4.addr = (ipv4[0] & 0xFF) | ((ipv4[1] & 0xFF) << 8) | ((ipv4[2] & 0xFF) << 16) | ((ipv4[3] & 0xFF) << 24); @@ -48,8 +48,15 @@ static bool net_parse_url(const char* str, struct net_addr* addr) /* Port and trailing path are optional, check with and without */ - toks = sscanf(str, "%d.%d.%d.%d:%d/%s", &ipv4[0], &ipv4[1], - &ipv4[2], &ipv4[3], &port, path); + toks = sscanf( + str, + "%d.%d.%d.%d:%d/%s", + &ipv4[0], + &ipv4[1], + &ipv4[2], + &ipv4[3], + &port, + path); if (toks > 4) { if (toks >= 5) { @@ -61,8 +68,14 @@ static bool net_parse_url(const char* str, struct net_addr* addr) } } else { /* No port, but may have trailing path */ - toks = sscanf(str, "%d.%d.%d.%d/%s", &ipv4[0], &ipv4[1], - &ipv4[2], &ipv4[3], path); + toks = sscanf( + str, + "%d.%d.%d.%d/%s", + &ipv4[0], + &ipv4[1], + &ipv4[2], + &ipv4[3], + path); if (toks > 4) { strcpy(addr->url.path, path); @@ -93,7 +106,6 @@ static bool net_parse_url(const char* str, struct net_addr* addr) toks = sscanf(str, "%[^/]/%s", host, path); strcpy(addr->url.hostname.host, host); - if (toks > 1) { strcpy(addr->url.path, path); } @@ -103,7 +115,7 @@ static bool net_parse_url(const char* str, struct net_addr* addr) return true; } -static bool net_parse_ipv4_or_hostname(const char* str, struct net_addr* addr) +static bool net_parse_ipv4_or_hostname(const char *str, struct net_addr *addr) { char host[NET_MAX_URL_HOSTNAME_LEN + 1]; uint32_t ipv4[4]; @@ -112,15 +124,15 @@ static bool net_parse_ipv4_or_hostname(const char* str, struct net_addr* addr) memset(host, 0, sizeof(host)); - toks = sscanf(str, "%d.%d.%d.%d:%d", &ipv4[0], &ipv4[1], &ipv4[2], &ipv4[3], - &port); + toks = sscanf( + str, "%d.%d.%d.%d:%d", &ipv4[0], &ipv4[1], &ipv4[2], &ipv4[3], &port); if (toks >= 4) { addr->type = NET_ADDR_TYPE_IPV4; addr->ipv4.addr = (ipv4[0] & 0xFF) | ((ipv4[1] & 0xFF) << 8) | ((ipv4[2] & 0xFF) << 16) | ((ipv4[3] & 0xFF) << 24); addr->ipv4.port = NET_INVALID_PORT; - + if (toks == 5) { addr->ipv4.port = port; } @@ -146,37 +158,61 @@ static bool net_parse_ipv4_or_hostname(const char* str, struct net_addr* addr) return true; } -static char* net_ipv4_to_str(const struct net_addr_ipv4* addr) +static char *net_ipv4_to_str(const struct net_addr_ipv4 *addr) { size_t len; - uint8_t* addr_ipv4; - char* str; + uint8_t *addr_ipv4; + char *str; - addr_ipv4 = (uint8_t*) &addr->addr; + addr_ipv4 = (uint8_t *) &addr->addr; if (addr->port != NET_INVALID_PORT) { - len = snprintf(NULL, 0, "%d.%d.%d.%d:%d", addr_ipv4[0], - addr_ipv4[1], addr_ipv4[2], addr_ipv4[3], addr->port); + len = snprintf( + NULL, + 0, + "%d.%d.%d.%d:%d", + addr_ipv4[0], + addr_ipv4[1], + addr_ipv4[2], + addr_ipv4[3], + addr->port); str = xmalloc(len + 1); - sprintf(str, "%d.%d.%d.%d:%d", addr_ipv4[0], - addr_ipv4[1], addr_ipv4[2], addr_ipv4[3], addr->port); + sprintf( + str, + "%d.%d.%d.%d:%d", + addr_ipv4[0], + addr_ipv4[1], + addr_ipv4[2], + addr_ipv4[3], + addr->port); } else { - len = snprintf(NULL, 0, "%d.%d.%d.%d", addr_ipv4[0], addr_ipv4[1], - addr_ipv4[2], addr_ipv4[3]); + len = snprintf( + NULL, + 0, + "%d.%d.%d.%d", + addr_ipv4[0], + addr_ipv4[1], + addr_ipv4[2], + addr_ipv4[3]); str = xmalloc(len + 1); - sprintf(str, "%d.%d.%d.%d", addr_ipv4[0], addr_ipv4[1], - addr_ipv4[2], addr_ipv4[3]); + sprintf( + str, + "%d.%d.%d.%d", + addr_ipv4[0], + addr_ipv4[1], + addr_ipv4[2], + addr_ipv4[3]); } return str; } -static char* net_hostname_to_str(const struct net_addr_hostname* addr) +static char *net_hostname_to_str(const struct net_addr_hostname *addr) { size_t len; - char* str; + char *str; if (addr->port != NET_INVALID_PORT) { len = snprintf(NULL, 0, "%s:%d", addr->host, addr->port); @@ -190,12 +226,12 @@ static char* net_hostname_to_str(const struct net_addr_hostname* addr) return str; } -static char* net_url_to_str(const struct net_addr_url* addr) +static char *net_url_to_str(const struct net_addr_url *addr) { size_t len; size_t str_len; - char* tmp; - char* str; + char *tmp; + char *str; switch (addr->type) { case NET_ADDR_TYPE_IPV4: @@ -216,23 +252,34 @@ static char* net_url_to_str(const struct net_addr_url* addr) str_len = strlen(addr->path); - len = snprintf(NULL, 0, "http%s://%s%s%s", addr->is_https ? "s" : "", - tmp, str_len > 0 ? "/" : "", str_len > 0 ? addr->path : ""); + len = snprintf( + NULL, + 0, + "http%s://%s%s%s", + addr->is_https ? "s" : "", + tmp, + str_len > 0 ? "/" : "", + str_len > 0 ? addr->path : ""); str = xmalloc(len + 1); - sprintf(str, "http%s://%s%s%s", addr->is_https ? "s" : "", - tmp, str_len > 0 ? "/" : "", str_len > 0 ? addr->path : ""); + sprintf( + str, + "http%s://%s%s%s", + addr->is_https ? "s" : "", + tmp, + str_len > 0 ? "/" : "", + str_len > 0 ? addr->path : ""); free(tmp); - + return str; } -static bool net_resolve_hostname_str(const char* host, uint32_t* ipv4) +static bool net_resolve_hostname_str(const char *host, uint32_t *ipv4) { struct WSAData data; struct addrinfo hints; - struct addrinfo* res; + struct addrinfo *res; int err; log_assert(host); @@ -245,7 +292,7 @@ static bool net_resolve_hostname_str(const char* host, uint32_t* ipv4) /* Using gethostbyname seems to crash on certain setups...use getaddrinfo (which is not deprecated) */ - WSAStartup(MAKEWORD(2,0), &data); + WSAStartup(MAKEWORD(2, 0), &data); err = getaddrinfo(host, NULL, &hints, &res); @@ -254,17 +301,17 @@ static bool net_resolve_hostname_str(const char* host, uint32_t* ipv4) return false; } - *ipv4 = ((struct sockaddr_in *)(res->ai_addr))->sin_addr.S_un.S_addr; + *ipv4 = ((struct sockaddr_in *) (res->ai_addr))->sin_addr.S_un.S_addr; freeaddrinfo(res); - + WSACleanup(); return true; } -static bool net_resolve_hostname_ipv4(const struct net_addr_ipv4* addr, - struct net_addr_ipv4* res_addr) +static bool net_resolve_hostname_ipv4( + const struct net_addr_ipv4 *addr, struct net_addr_ipv4 *res_addr) { res_addr->addr = addr->addr; res_addr->port = addr->port; @@ -272,15 +319,15 @@ static bool net_resolve_hostname_ipv4(const struct net_addr_ipv4* addr, return true; } -static bool net_resolve_hostname_host(const struct net_addr_hostname* addr, - struct net_addr_ipv4* res_addr) +static bool net_resolve_hostname_host( + const struct net_addr_hostname *addr, struct net_addr_ipv4 *res_addr) { res_addr->port = addr->port; return net_resolve_hostname_str(addr->host, &res_addr->addr); } -static bool net_resolve_hostname_url(const struct net_addr_url* addr, - struct net_addr_ipv4* res_addr) +static bool net_resolve_hostname_url( + const struct net_addr_url *addr, struct net_addr_ipv4 *res_addr) { switch (addr->type) { case NET_ADDR_TYPE_IPV4: @@ -298,7 +345,7 @@ static bool net_resolve_hostname_url(const struct net_addr_url* addr, } } -bool net_str_parse(const char* str, struct net_addr* addr) +bool net_str_parse(const char *str, struct net_addr *addr) { log_assert(str); log_assert(addr); @@ -310,7 +357,7 @@ bool net_str_parse(const char* str, struct net_addr* addr) } } -char* net_addr_to_str(const struct net_addr* addr) +char *net_addr_to_str(const struct net_addr *addr) { log_assert(addr); @@ -331,13 +378,13 @@ char* net_addr_to_str(const struct net_addr* addr) } } -bool net_resolve_hostname(const char* hostname, struct net_addr_ipv4* res_addr) +bool net_resolve_hostname(const char *hostname, struct net_addr_ipv4 *res_addr) { return net_resolve_hostname_str(hostname, &res_addr->addr); } -bool net_resolve_hostname_net_addr(const struct net_addr* addr, - struct net_addr_ipv4* res_addr) +bool net_resolve_hostname_net_addr( + const struct net_addr *addr, struct net_addr_ipv4 *res_addr) { switch (addr->type) { case NET_ADDR_TYPE_IPV4: @@ -356,11 +403,11 @@ bool net_resolve_hostname_net_addr(const struct net_addr* addr, } } -bool net_check_remote_connection(const struct net_addr* addr, - uint32_t timeout_ms) +bool net_check_remote_connection( + const struct net_addr *addr, uint32_t timeout_ms) { struct net_addr_ipv4 target; - + if (!net_resolve_hostname_net_addr(addr, &target)) { return false; } @@ -368,8 +415,8 @@ bool net_check_remote_connection(const struct net_addr* addr, return net_check_remote_connection_ipv4(&target, timeout_ms); } -bool net_check_remote_connection_ipv4(const struct net_addr_ipv4* addr, - uint32_t timeout_ms) +bool net_check_remote_connection_ipv4( + const struct net_addr_ipv4 *addr, uint32_t timeout_ms) { struct WSAData data; SOCKET s; @@ -381,7 +428,7 @@ bool net_check_remote_connection_ipv4(const struct net_addr_ipv4* addr, bool success; struct sockaddr_in sockaddr; - WSAStartup(MAKEWORD(2,0), &data); + WSAStartup(MAKEWORD(2, 0), &data); err = 0; success = true; @@ -406,8 +453,8 @@ bool net_check_remote_connection_ipv4(const struct net_addr_ipv4* addr, sockaddr.sin_addr.s_addr = addr->addr; sockaddr.sin_port = htons(addr->port); - if (connect(s, (struct sockaddr*) &sockaddr, sizeof(sockaddr)) == - SOCKET_ERROR) { + if (connect(s, (struct sockaddr *) &sockaddr, sizeof(sockaddr)) == + SOCKET_ERROR) { if (WSAGetLastError() != WSAEWOULDBLOCK) { /* connection failed */; success = false; @@ -418,7 +465,7 @@ bool net_check_remote_connection_ipv4(const struct net_addr_ipv4* addr, FD_SET(s, &set_e); timeout.tv_sec = timeout_ms / 1000; - timeout.tv_usec = (timeout_ms % 1000) * 1000; + timeout.tv_usec = (timeout_ms % 1000) * 1000; err = select(0, NULL, &set_w, &set_e, &timeout); @@ -435,7 +482,7 @@ bool net_check_remote_connection_ipv4(const struct net_addr_ipv4* addr, } else { success = false; } - + closesocket(s); WSACleanup(); diff --git a/src/main/util/net.h b/src/main/util/net.h index b3dad62..b4f6fbf 100644 --- a/src/main/util/net.h +++ b/src/main/util/net.h @@ -74,64 +74,65 @@ struct net_addr { * - Plain hostname with port, e.g. localhost:1234 * - HTTP(s) URL, e.g. http://www.myremote.com * - HTTP(s) URL with port, e.g. http://www.myremote.com:1234 - * - HTTP(s) URL with or without port and path: http://www.myremote.com:1234/somewhere - * + * - HTTP(s) URL with or without port and path: + * http://www.myremote.com:1234/somewhere + * * @param str String to parse. * @param addr Pointer to a net_addr struct to write the result to. * @return True if parsing is successful, false on parse error. */ -bool net_str_parse(const char* str, struct net_addr* addr); +bool net_str_parse(const char *str, struct net_addr *addr); // port not printed if invalid /** * net_addr struct to string function. Create a single c-string representation. - * + * * @param addr Input net_addr. * @return c-string representation. Note: Invalid port values are omitted. */ -char* net_addr_to_str(const struct net_addr* addr); +char *net_addr_to_str(const struct net_addr *addr); /** * Resolve a hostname to an IPV4 address. - * + * * @param hostname Hostname to resolve, e.g. localhost. * @param res_addr Pointer to a net_addr_ipv4 struct to store the result to. * @return True if resolving was successful, false on error. */ -bool net_resolve_hostname(const char* hostname, struct net_addr_ipv4* res_addr); +bool net_resolve_hostname(const char *hostname, struct net_addr_ipv4 *res_addr); /** * Resolve a net_addr struct to an IPV4 address. If the net_addr struct is * actually of IPV4 type, the IPV4 address and port are simply copied to the * result struct. - * + * * @param addr net_addr struct to resolve. * @param res_addr Pointer to a net_addr_ipv4 struct to store the result to. * @return True if resolving was successful, false on error. */ -bool net_resolve_hostname_net_addr(const struct net_addr* addr, - struct net_addr_ipv4* res_addr); +bool net_resolve_hostname_net_addr( + const struct net_addr *addr, struct net_addr_ipv4 *res_addr); /** * Check if a remote server is reachable, i.e. it is possible to open a * connection to it. - * + * * @param addr net_addr struct of target server to check. * @param timeout_ms Timeout for the check in ms. * @return True if target server is reachable/connectable, false otherwise. */ -bool net_check_remote_connection(const struct net_addr* addr, - uint32_t timeout_ms); +bool net_check_remote_connection( + const struct net_addr *addr, uint32_t timeout_ms); /** * Check if a remote server is reachable, i.e. it is possible to open a * connection to it. - * + * * @param addr net_addr_ipv4 struct of target server to check. * @param timeout_ms Timeout for the check in ms. * @return True if target server is reachable/connectable, false otherwise. */ -bool net_check_remote_connection_ipv4(const struct net_addr_ipv4* addr, - uint32_t timeout_ms); +bool net_check_remote_connection_ipv4( + const struct net_addr_ipv4 *addr, uint32_t timeout_ms); #endif \ No newline at end of file diff --git a/src/main/util/str.c b/src/main/util/str.c index a01a968..8c520d7 100644 --- a/src/main/util/str.c +++ b/src/main/util/str.c @@ -38,9 +38,9 @@ bool wstr_ends_with(const wchar_t *haystack, const wchar_t *needle) } return !memcmp( - &haystack[haystack_len - needle_len], - needle, - needle_len * sizeof(wchar_t)); + &haystack[haystack_len - needle_len], + needle, + needle_len * sizeof(wchar_t)); } size_t str_format(char *buf, size_t nchars, const char *fmt, ...) @@ -80,8 +80,7 @@ size_t wstr_format(wchar_t *buf, size_t nchars, const wchar_t *fmt, ...) return result; } -size_t wstr_vformat(wchar_t *buf, size_t nchars, const wchar_t *fmt, - va_list ap) +size_t wstr_vformat(wchar_t *buf, size_t nchars, const wchar_t *fmt, va_list ap) { int result; @@ -166,7 +165,7 @@ void str_trim(char *str) { char *pos; - for (pos = str + strlen(str) - 1 ; pos > str ; pos--) { + for (pos = str + strlen(str) - 1; pos > str; pos--) { if (!isspace(*pos)) { return; } @@ -219,8 +218,8 @@ bool wstr_narrow(const wchar_t *src, char **dest) *dest = xmalloc(nbytes); - if (WideCharToMultiByte(CP_ACP, 0, src, -1, *dest, nbytes, NULL, NULL) - != nbytes) { + if (WideCharToMultiByte(CP_ACP, 0, src, -1, *dest, nbytes, NULL, NULL) != + nbytes) { goto conv_fail; } @@ -251,4 +250,3 @@ bool wstr_eq(const wchar_t *lhs, const wchar_t *rhs) return wcscmp(lhs, rhs) == 0; } } - diff --git a/src/main/util/str.h b/src/main/util/str.h index cd0ea64..49fbbd8 100644 --- a/src/main/util/str.h +++ b/src/main/util/str.h @@ -2,8 +2,8 @@ #define UTIL_STR_H #include -#include #include +#include #include void str_cat(char *dest, size_t dnchars, const char *src); @@ -23,7 +23,7 @@ bool wstr_ends_with(const wchar_t *haystack, const wchar_t *needle); bool wstr_eq(const wchar_t *lhs, const wchar_t *rhs); size_t wstr_format(wchar_t *buf, size_t nchars, const wchar_t *fmt, ...); bool wstr_narrow(const wchar_t *src, char **dest); -size_t wstr_vformat(wchar_t *buf, size_t nchars, const wchar_t *fmt, - va_list ap); +size_t +wstr_vformat(wchar_t *buf, size_t nchars, const wchar_t *fmt, va_list ap); #endif diff --git a/src/main/util/thread.c b/src/main/util/thread.c index ad6c6df..7d19ae5 100644 --- a/src/main/util/thread.c +++ b/src/main/util/thread.c @@ -1,5 +1,5 @@ -#include #include +#include #include #include @@ -31,8 +31,8 @@ static unsigned int STDCALL crt_thread_shim(void *outer_ctx) return proc(inner_ctx); } -int crt_thread_create(int (*proc)(void *), void *ctx, uint32_t stack_sz, - unsigned int priority) +int crt_thread_create( + int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority) { struct shim_ctx sctx; uintptr_t thread_id; @@ -51,20 +51,20 @@ int crt_thread_create(int (*proc)(void *), void *ctx, uint32_t stack_sz, void crt_thread_destroy(int thread_id) { - CloseHandle((HANDLE) (uintptr_t) thread_id); + CloseHandle((HANDLE)(uintptr_t) thread_id); } void crt_thread_join(int thread_id, int *result) { - WaitForSingleObject((HANDLE) (uintptr_t) thread_id, INFINITE); + WaitForSingleObject((HANDLE)(uintptr_t) thread_id, INFINITE); if (result) { - GetExitCodeThread((HANDLE) (uintptr_t) thread_id, (DWORD *) result); + GetExitCodeThread((HANDLE)(uintptr_t) thread_id, (DWORD *) result); } } -void thread_api_init(thread_create_t create, thread_join_t join, - thread_destroy_t destroy) +void thread_api_init( + thread_create_t create, thread_join_t join, thread_destroy_t destroy) { if (create == NULL || join == NULL || destroy == NULL) { abort(); @@ -75,8 +75,8 @@ void thread_api_init(thread_create_t create, thread_join_t join, thread_impl_destroy = destroy; } -int thread_create(int (*proc)(void *), void *ctx, uint32_t stack_sz, - unsigned int priority) +int thread_create( + int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority) { return thread_impl_create(proc, ctx, stack_sz, priority); } @@ -90,4 +90,3 @@ void thread_destroy(int thread_id) { thread_impl_destroy(thread_id); } - diff --git a/src/main/util/thread.h b/src/main/util/thread.h index 06cbc6a..dca396b 100644 --- a/src/main/util/thread.h +++ b/src/main/util/thread.h @@ -5,15 +5,15 @@ #include "bemanitools/glue.h" -int crt_thread_create(int (*proc)(void *), void *ctx, uint32_t stack_sz, - unsigned int priority); +int crt_thread_create( + int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority); void crt_thread_join(int thread_id, int *result); void crt_thread_destroy(int thread_id); -void thread_api_init(thread_create_t create, thread_join_t join, - thread_destroy_t destroy); -int thread_create(int (*proc)(void *), void *ctx, uint32_t stack_sz, - unsigned int priority); +void thread_api_init( + thread_create_t create, thread_join_t join, thread_destroy_t destroy); +int thread_create( + int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority); void thread_join(int thread_id, int *result); void thread_destroy(int thread_id); diff --git a/src/main/util/time.c b/src/main/util/time.c index 8ae95dd..0412b29 100644 --- a/src/main/util/time.c +++ b/src/main/util/time.c @@ -22,7 +22,7 @@ uint64_t time_get_counter(void) LARGE_INTEGER time; log_assert(QueryPerformanceCounter(&time) == TRUE); - + return (uint64_t) time.QuadPart; } diff --git a/src/main/util/winres.c b/src/main/util/winres.c index ae881da..2ccda43 100644 --- a/src/main/util/winres.c +++ b/src/main/util/winres.c @@ -4,8 +4,12 @@ #include "util/str.h" #include "util/winres.h" -void vrsprintf(char *dest, size_t nchars, HINSTANCE inst, - unsigned int fmt_resource, va_list ap) +void vrsprintf( + char *dest, + size_t nchars, + HINSTANCE inst, + unsigned int fmt_resource, + va_list ap) { char fmt_buffer[1024]; @@ -14,8 +18,8 @@ void vrsprintf(char *dest, size_t nchars, HINSTANCE inst, dest[nchars - 1] = '\0'; } -void rsprintf(char *dest, size_t nchars, HINSTANCE inst, - unsigned int fmt_resource, ...) +void rsprintf( + char *dest, size_t nchars, HINSTANCE inst, unsigned int fmt_resource, ...) { va_list ap; @@ -24,8 +28,12 @@ void rsprintf(char *dest, size_t nchars, HINSTANCE inst, va_end(ap); } -void vrswprintf(wchar_t *dest, size_t nchars, HINSTANCE inst, - unsigned int fmt_resource, va_list ap) +void vrswprintf( + wchar_t *dest, + size_t nchars, + HINSTANCE inst, + unsigned int fmt_resource, + va_list ap) { wchar_t fmt_buffer[1024]; @@ -34,8 +42,12 @@ void vrswprintf(wchar_t *dest, size_t nchars, HINSTANCE inst, dest[nchars - 1] = L'\0'; } -void rswprintf(wchar_t *dest, size_t nchars, HINSTANCE inst, - unsigned int fmt_resource, ...) +void rswprintf( + wchar_t *dest, + size_t nchars, + HINSTANCE inst, + unsigned int fmt_resource, + ...) { va_list ap; @@ -44,8 +56,8 @@ void rswprintf(wchar_t *dest, size_t nchars, HINSTANCE inst, va_end(ap); } -void resource_open(struct resource *res, HINSTANCE inst, const char *type, - unsigned int ord) +void resource_open( + struct resource *res, HINSTANCE inst, const char *type, unsigned int ord) { HRSRC h1; HGLOBAL h2; @@ -67,7 +79,7 @@ size_t resource_fgets(struct resource *res, char *chars, size_t nchars) c = '\0'; remain = res->nbytes - res->pos; - for (i = 0 ; i < remain ; i++) { + for (i = 0; i < remain; i++) { if (c == '\n') { break; } @@ -83,4 +95,3 @@ size_t resource_fgets(struct resource *res, char *chars, size_t nchars) return i > 0; } - diff --git a/src/main/util/winres.h b/src/main/util/winres.h index 5eacf80..ce8c443 100644 --- a/src/main/util/winres.h +++ b/src/main/util/winres.h @@ -22,18 +22,30 @@ struct resource { size_t pos; }; -void vrsprintf(char *dest, size_t nchars, HINSTANCE inst, - unsigned int fmt_resource, va_list ap); -void rsprintf(char *dest, size_t nchars, HINSTANCE inst, - unsigned int fmt_resource, ...); +void vrsprintf( + char *dest, + size_t nchars, + HINSTANCE inst, + unsigned int fmt_resource, + va_list ap); +void rsprintf( + char *dest, size_t nchars, HINSTANCE inst, unsigned int fmt_resource, ...); -void vrswprintf(wchar_t *dest, size_t nchars, HINSTANCE inst, - unsigned int fmt_resource, va_list ap); -void rswprintf(wchar_t *dest, size_t nchars, HINSTANCE inst, - unsigned int fmt_resource, ...); +void vrswprintf( + wchar_t *dest, + size_t nchars, + HINSTANCE inst, + unsigned int fmt_resource, + va_list ap); +void rswprintf( + wchar_t *dest, + size_t nchars, + HINSTANCE inst, + unsigned int fmt_resource, + ...); -void resource_open(struct resource *res, HINSTANCE inst, const char *type, - unsigned int ord); +void resource_open( + struct resource *res, HINSTANCE inst, const char *type, unsigned int ord); size_t resource_fgets(struct resource *res, char *chars, size_t nchars); #endif diff --git a/src/main/vefxio/vefxio.c b/src/main/vefxio/vefxio.c index 76b1529..548f951 100644 --- a/src/main/vefxio/vefxio.c +++ b/src/main/vefxio/vefxio.c @@ -9,31 +9,31 @@ provides all of the inputs for IIDX then you should replace IIDXIO.DLL instead and not call into this DLL at all. */ -#include #include +#include #include #include -#include "bemanitools/vefxio.h" #include "bemanitools/input.h" +#include "bemanitools/vefxio.h" -#define MSEC_PER_NOTCH 128 +#define MSEC_PER_NOTCH 128 enum iidx_slider_bits { - VEFX_IO_S1_UP = 0x20, + VEFX_IO_S1_UP = 0x20, VEFX_IO_S1_DOWN = 0x21, - VEFX_IO_S2_UP = 0x22, + VEFX_IO_S2_UP = 0x22, VEFX_IO_S2_DOWN = 0x23, - VEFX_IO_S3_UP = 0x24, + VEFX_IO_S3_UP = 0x24, VEFX_IO_S3_DOWN = 0x25, - VEFX_IO_S4_UP = 0x26, + VEFX_IO_S4_UP = 0x26, VEFX_IO_S4_DOWN = 0x27, - VEFX_IO_S5_UP = 0x28, + VEFX_IO_S5_UP = 0x28, VEFX_IO_S5_DOWN = 0x29, }; @@ -49,16 +49,16 @@ struct vefx_io_slider { }; static const struct vefx_io_slider_inputs vefx_io_slider_inputs[5] = { - { VEFX_IO_S1_UP, VEFX_IO_S1_DOWN }, - { VEFX_IO_S2_UP, VEFX_IO_S2_DOWN }, - { VEFX_IO_S3_UP, VEFX_IO_S3_DOWN }, - { VEFX_IO_S4_UP, VEFX_IO_S4_DOWN }, - { VEFX_IO_S5_UP, VEFX_IO_S5_DOWN }, + {VEFX_IO_S1_UP, VEFX_IO_S1_DOWN}, + {VEFX_IO_S2_UP, VEFX_IO_S2_DOWN}, + {VEFX_IO_S3_UP, VEFX_IO_S3_DOWN}, + {VEFX_IO_S4_UP, VEFX_IO_S4_DOWN}, + {VEFX_IO_S5_UP, VEFX_IO_S5_DOWN}, }; static struct vefx_io_slider vefx_io_slider[5]; -static void vefx_io_slider_update(uint64_t* ppad); +static void vefx_io_slider_update(uint64_t *ppad); /* Uncomment these if you need them. */ @@ -69,8 +69,11 @@ static log_formatter_t vefx_io_log_warning; static log_formatter_t vefx_io_log_fatal; #endif -void vefx_io_set_loggers(log_formatter_t misc, log_formatter_t info, - log_formatter_t warning, log_formatter_t fatal) +void vefx_io_set_loggers( + log_formatter_t misc, + log_formatter_t info, + log_formatter_t warning, + log_formatter_t fatal) { /* Uncomment this block if you have something you'd like to log. @@ -84,8 +87,10 @@ void vefx_io_set_loggers(log_formatter_t misc, log_formatter_t info, #endif } -bool vefx_io_init(thread_create_t thread_create, thread_join_t thread_join, - thread_destroy_t thread_destroy) +bool vefx_io_init( + thread_create_t thread_create, + thread_join_t thread_join, + thread_destroy_t thread_destroy) { /* geninput should have already been initted be now so we don't do it */ vefx_io_slider[0].pos = 8; @@ -100,7 +105,7 @@ bool vefx_io_init(thread_create_t thread_create, thread_join_t thread_join, return true; } -bool vefx_io_recv(uint64_t* ppad) +bool vefx_io_recv(uint64_t *ppad) { vefx_io_slider_update(ppad); @@ -113,7 +118,7 @@ void vefx_io_fini(void) connections to your IO devices here. */ } -static void vefx_io_slider_update(uint64_t* ppad) +static void vefx_io_slider_update(uint64_t *ppad) { uint32_t delta; int sno; @@ -124,7 +129,7 @@ static void vefx_io_slider_update(uint64_t* ppad) pad = *ppad; now = timeGetTime(); - for (sno = 0 ; sno < 5 ; sno++) { + for (sno = 0; sno < 5; sno++) { if (pad & (1ULL << vefx_io_slider_inputs[sno].slider_up)) { sdir = +1; } else if (pad & (1ULL << vefx_io_slider_inputs[sno].slider_down)) { @@ -136,14 +141,14 @@ static void vefx_io_slider_update(uint64_t* ppad) /* Update slider based on current direction */ if (sdir != vefx_io_slider[sno].last_dir) { - /* Just started (or stopped). Give the slider a big push to make sure - it begins to register straight from the first frame */ + /* Just started (or stopped). Give the slider a big push to make + sure it begins to register straight from the first frame */ vefx_io_slider[sno].pos += sdir; vefx_io_slider[sno].last_notch = now; } else if (sdir != 0) { - /* Roll slider forward by an appropriate number of notches, given the - elapsed time. Roll `last_notch' forward by an appropriate number + /* Roll slider forward by an appropriate number of notches, given + the elapsed time. Roll `last_notch' forward by an appropriate number of msec to ensure partial notches get counted properly */ delta = now - vefx_io_slider[sno].last_notch; @@ -178,4 +183,3 @@ bool vefx_io_write_16seg(const char *text) return true; } - diff --git a/src/test/cconfig/cconfig-cmd-test.c b/src/test/cconfig/cconfig-cmd-test.c index b3a3c13..3800fc5 100644 --- a/src/test/cconfig/cconfig-cmd-test.c +++ b/src/test/cconfig/cconfig-cmd-test.c @@ -1,14 +1,14 @@ -#include "cconfig/cmd.h" #include "cconfig/cconfig-util.h" +#include "cconfig/cmd.h" #include "test/check.h" #include "test/test.h" static void test_cmd() { - struct cconfig* config; + struct cconfig *config; int argc = 6; - char* argv[] = {"-P", "test=aaa", "-C", "asdf", "-P", "test2=123"}; + char *argv[] = {"-P", "test=aaa", "-C", "asdf", "-P", "test2=123"}; char str[32]; int32_t val; @@ -21,7 +21,8 @@ static void test_cmd() check_int_eq(config->nentries, 2); - check_bool_true(cconfig_util_get_str(config, "test", str, sizeof(str), "1")); + check_bool_true( + cconfig_util_get_str(config, "test", str, sizeof(str), "1")); check_str_eq(str, "aaa"); check_bool_true(cconfig_util_get_int(config, "test2", &val, 0)); @@ -32,9 +33,9 @@ static void test_cmd() static void test_cmd_absent_entries() { - struct cconfig* config; + struct cconfig *config; int argc = 6; - char* argv[] = {"-P", "test=aaa", "-C", "asdf", "-P", "test2=123"}; + char *argv[] = {"-P", "test=aaa", "-C", "asdf", "-P", "test2=123"}; char str[32]; int32_t val; @@ -49,7 +50,8 @@ static void test_cmd_absent_entries() check_int_eq(config->nentries, 1); - check_bool_true(cconfig_util_get_str(config, "test", str, sizeof(str), "1")); + check_bool_true( + cconfig_util_get_str(config, "test", str, sizeof(str), "1")); check_str_eq(str, "aaa"); check_bool_false(cconfig_util_get_int(config, "test2", &val, 0)); diff --git a/src/test/cconfig/cconfig-test.c b/src/test/cconfig/cconfig-test.c index e308ab3..4feb6d6 100644 --- a/src/test/cconfig/cconfig-test.c +++ b/src/test/cconfig/cconfig-test.c @@ -5,7 +5,7 @@ static void test_init() { - struct cconfig* config; + struct cconfig *config; config = cconfig_init(); @@ -17,7 +17,7 @@ static void test_init() static void test_get_empty() { - struct cconfig* config; + struct cconfig *config; config = cconfig_init(); @@ -31,8 +31,8 @@ static void test_get_empty() static void test_set_get_one_elem() { - struct cconfig* config; - struct cconfig_entry* entry; + struct cconfig *config; + struct cconfig_entry *entry; config = cconfig_init(); @@ -50,15 +50,15 @@ static void test_set_get_one_elem() check_str_eq(entry->key, "test"); check_str_eq(entry->value, "123"); - check_str_eq(entry->desc, "desc"); + check_str_eq(entry->desc, "desc"); cconfig_finit(config); } static void test_set_get_one_elem2() { - struct cconfig* config; - struct cconfig_entry* entry; + struct cconfig *config; + struct cconfig_entry *entry; config = cconfig_init(); @@ -76,15 +76,15 @@ static void test_set_get_one_elem2() check_str_eq(entry->key, "test"); check_str_eq(entry->value, "123"); - check_str_eq(entry->desc, ""); + check_str_eq(entry->desc, ""); cconfig_finit(config); } static void test_set_get_same_elem() { - struct cconfig* config; - struct cconfig_entry* entry; + struct cconfig *config; + struct cconfig_entry *entry; config = cconfig_init(); @@ -104,15 +104,15 @@ static void test_set_get_same_elem() check_str_eq(entry->key, "test"); check_str_eq(entry->value, "12345"); - check_str_eq(entry->desc, "aaa"); + check_str_eq(entry->desc, "aaa"); cconfig_finit(config); } static void test_set_get_many_elem() { - struct cconfig* config; - struct cconfig_entry* entry; + struct cconfig *config; + struct cconfig_entry *entry; char key[16]; config = cconfig_init(); @@ -140,7 +140,7 @@ static void test_set_get_many_elem() check_str_eq(entry->key, key); check_str_eq(entry->value, "123"); - check_str_eq(entry->desc, "desc"); + check_str_eq(entry->desc, "desc"); } cconfig_finit(config); diff --git a/src/test/cconfig/cconfig-util-test.c b/src/test/cconfig/cconfig-util-test.c index 4d61fde..78cf49c 100644 --- a/src/test/cconfig/cconfig-util-test.c +++ b/src/test/cconfig/cconfig-util-test.c @@ -6,7 +6,7 @@ static void test_set_get_int() { - struct cconfig* config; + struct cconfig *config; int32_t value; config = cconfig_init(); @@ -29,7 +29,7 @@ static void test_set_get_int() static void test_get_int_na() { - struct cconfig* config; + struct cconfig *config; int32_t value; config = cconfig_init(); @@ -45,7 +45,7 @@ static void test_get_int_na() static void test_set_get_float() { - struct cconfig* config; + struct cconfig *config; float value; config = cconfig_init(); @@ -67,7 +67,7 @@ static void test_set_get_float() static void test_get_float_na() { - struct cconfig* config; + struct cconfig *config; float value; config = cconfig_init(); @@ -83,7 +83,7 @@ static void test_get_float_na() static void test_set_get_bool() { - struct cconfig* config; + struct cconfig *config; bool value; config = cconfig_init(); @@ -105,7 +105,7 @@ static void test_set_get_bool() static void test_get_bool_na() { - struct cconfig* config; + struct cconfig *config; bool value; config = cconfig_init(); @@ -121,7 +121,7 @@ static void test_get_bool_na() static void test_set_get_str() { - struct cconfig* config; + struct cconfig *config; char value[1024]; config = cconfig_init(); @@ -135,8 +135,8 @@ static void test_set_get_str() check_str_eq(config->entries[0].key, "test"); check_str_eq(config->entries[0].desc, "desc"); - check_bool_true(cconfig_util_get_str(config, "test", value, sizeof(value), - "world hello")); + check_bool_true(cconfig_util_get_str( + config, "test", value, sizeof(value), "world hello")); check_str_eq(value, "hello world"); cconfig_finit(config); @@ -144,7 +144,7 @@ static void test_set_get_str() static void test_get_str_na() { - struct cconfig* config; + struct cconfig *config; char value[1024]; config = cconfig_init(); @@ -152,8 +152,8 @@ static void test_get_str_na() check_int_eq(config->nentries, 0); check_null(config->entries); - check_bool_false(cconfig_util_get_str(config, "test", value, sizeof(value), - "world hello")); + check_bool_false(cconfig_util_get_str( + config, "test", value, sizeof(value), "world hello")); check_str_eq(value, "world hello"); cconfig_finit(config); @@ -161,7 +161,7 @@ static void test_get_str_na() static void test_set_get_data() { - struct cconfig* config; + struct cconfig *config; uint8_t value[1024]; uint8_t value2[1024]; uint8_t value_default[] = {0x00}; @@ -181,8 +181,8 @@ static void test_set_get_data() check_str_eq(config->entries[0].key, "test"); check_str_eq(config->entries[0].desc, "desc"); - check_bool_true(cconfig_util_get_data(config, "test", value2, sizeof(value2), - value_default)); + check_bool_true(cconfig_util_get_data( + config, "test", value2, sizeof(value2), value_default)); check_data_eq(value2, sizeof(value2), value, sizeof(value)); cconfig_finit(config); @@ -190,7 +190,7 @@ static void test_set_get_data() static void test_get_data_na() { - struct cconfig* config; + struct cconfig *config; uint8_t value[1024]; uint8_t value_default[] = {0x01}; @@ -199,8 +199,8 @@ static void test_get_data_na() check_int_eq(config->nentries, 0); check_null(config->entries); - check_bool_false(cconfig_util_get_data(config, "test", value, sizeof(value), - value_default)); + check_bool_false(cconfig_util_get_data( + config, "test", value, sizeof(value), value_default)); check_data_eq(value, 1, value_default, sizeof(value_default)); cconfig_finit(config); diff --git a/src/test/d3d9hook/dllmain.c b/src/test/d3d9hook/dllmain.c index 54b9f73..88060bb 100644 --- a/src/test/d3d9hook/dllmain.c +++ b/src/test/d3d9hook/dllmain.c @@ -10,33 +10,32 @@ #define debug_print(...) fprintf(stderr, __VA_ARGS__) -static HRESULT my_d3d9_handler(struct hook_d3d9_irp* irp); +static HRESULT my_d3d9_handler(struct hook_d3d9_irp *irp); -static const hook_d3d9_irp_handler_t d3d9_handlers[] = { - my_d3d9_handler -}; +static const hook_d3d9_irp_handler_t d3d9_handlers[] = {my_d3d9_handler}; -static HRESULT my_d3d9_handler(struct hook_d3d9_irp* irp) +static HRESULT my_d3d9_handler(struct hook_d3d9_irp *irp) { HRESULT hr; enum hook_d3d9_irp_op pre_op; debug_print("my_d3d9_handler dispatch: %d\n", irp->op); - // Important: All parameter checks must align with the parameters from the test executable + // Important: All parameter checks must align with the parameters from the + // test executable // Pre-real invoke checks switch (irp->op) { case HOOK_D3D9_IRP_OP_INVALID: exit(EXIT_FAILURE); break; - + case HOOK_D3D9_IRP_OP_CTX_CREATE: debug_print("Pre HOOK_D3D9_IRP_OP_CTX_CREATE\n"); - + check_int_eq(irp->args.ctx_create.sdk_ver, D3D_SDK_VERSION); check_null(irp->args.ctx_create.ctx); - + break; case HOOK_D3D9_IRP_OP_ENUM_DISPLAY_DEVICES: @@ -45,20 +44,22 @@ static HRESULT my_d3d9_handler(struct hook_d3d9_irp* irp) check_null(irp->args.enum_display_devices.dev_name); check_int_eq(irp->args.enum_display_devices.dev_num, 0); check_non_null(irp->args.enum_display_devices.info); - check_int_eq(irp->args.enum_display_devices.flags, EDD_GET_DEVICE_INTERFACE_NAME); + check_int_eq( + irp->args.enum_display_devices.flags, + EDD_GET_DEVICE_INTERFACE_NAME); break; case HOOK_D3D9_IRP_OP_CREATE_WINDOW_EX: debug_print("Pre HOOK_D3D9_IRP_OP_CREATE_WINDOW_EX\n"); - // Cannot test because wine is also using this call causing the tests to fail - // check_int_eq(irp->args.create_window_ex.ex_style, 0); - // check_str_eq(irp->args.create_window_ex.class_name, "d3d9hook"); - // check_str_eq(irp->args.create_window_ex.window_name, "d3d9hook test"); - // check_int_eq(irp->args.create_window_ex.style, WS_OVERLAPPEDWINDOW); - // check_int_eq(irp->args.create_window_ex.x, 0); - // check_int_eq(irp->args.create_window_ex.y, 0); + // Cannot test because wine is also using this call causing the + // tests to fail check_int_eq(irp->args.create_window_ex.ex_style, + // 0); check_str_eq(irp->args.create_window_ex.class_name, + // "d3d9hook"); check_str_eq(irp->args.create_window_ex.window_name, + // "d3d9hook test"); check_int_eq(irp->args.create_window_ex.style, + // WS_OVERLAPPEDWINDOW); check_int_eq(irp->args.create_window_ex.x, + // 0); check_int_eq(irp->args.create_window_ex.y, 0); // check_int_eq(irp->args.create_window_ex.width, 640); // check_int_eq(irp->args.create_window_ex.height, 480); // check_null(irp->args.create_window_ex.wnd_parent); @@ -72,7 +73,8 @@ static HRESULT my_d3d9_handler(struct hook_d3d9_irp* irp) case HOOK_D3D9_IRP_OP_GET_CLIENT_RECT: debug_print("Pre HOOK_D3D9_IRP_OP_GET_CLIENT_RECT\n"); - // Cannot test because wine is also using this call causing the tests to fail + // Cannot test because wine is also using this call causing the + // tests to fail break; @@ -80,10 +82,13 @@ static HRESULT my_d3d9_handler(struct hook_d3d9_irp* irp) debug_print("Pre HOOK_D3D9_IRP_OP_CTX_CREATE_DEVICE\n"); check_non_null(irp->args.ctx_create_device.self); - check_int_eq(irp->args.ctx_create_device.adapter, D3DADAPTER_DEFAULT); + check_int_eq( + irp->args.ctx_create_device.adapter, D3DADAPTER_DEFAULT); check_int_eq(irp->args.ctx_create_device.type, D3DDEVTYPE_HAL); check_non_null(irp->args.ctx_create_device.hwnd); - check_int_eq(irp->args.ctx_create_device.flags, D3DCREATE_HARDWARE_VERTEXPROCESSING); + check_int_eq( + irp->args.ctx_create_device.flags, + D3DCREATE_HARDWARE_VERTEXPROCESSING); check_non_null(irp->args.ctx_create_device.pp); check_non_null(irp->args.ctx_create_device.pdev); @@ -158,13 +163,13 @@ static HRESULT my_d3d9_handler(struct hook_d3d9_irp* irp) case HOOK_D3D9_IRP_OP_INVALID: exit(EXIT_FAILURE); break; - + case HOOK_D3D9_IRP_OP_CTX_CREATE: debug_print("Post HOOK_D3D9_IRP_OP_CTX_CREATE\n"); - + check_int_eq(irp->args.ctx_create.sdk_ver, D3D_SDK_VERSION); check_non_null(irp->args.ctx_create.ctx); - + break; case HOOK_D3D9_IRP_OP_ENUM_DISPLAY_DEVICES: @@ -173,18 +178,24 @@ static HRESULT my_d3d9_handler(struct hook_d3d9_irp* irp) check_null(irp->args.enum_display_devices.dev_name); check_int_eq(irp->args.enum_display_devices.dev_num, 0); check_non_null(irp->args.enum_display_devices.info); - check_int_eq(irp->args.enum_display_devices.flags, EDD_GET_DEVICE_INTERFACE_NAME); + check_int_eq( + irp->args.enum_display_devices.flags, + EDD_GET_DEVICE_INTERFACE_NAME); break; case HOOK_D3D9_IRP_OP_CREATE_WINDOW_EX: debug_print("Post HOOK_D3D9_IRP_OP_CREATE_WINDOW_EX\n"); - // Cannot test because wine is also using this call causing the tests to fail + // Cannot test because wine is also using this call causing the + // tests to fail // check_int_eq(irp->args.create_window_ex.ex_style, 0); - // check_str_eq(irp->args.create_window_ex.class_name, "d3d9hook"); - // check_str_eq(irp->args.create_window_ex.window_name, "d3d9hook test"); - // check_int_eq(irp->args.create_window_ex.style, WS_OVERLAPPEDWINDOW); + // check_str_eq(irp->args.create_window_ex.class_name, + // "d3d9hook"); + // check_str_eq(irp->args.create_window_ex.window_name, + // "d3d9hook test"); + // check_int_eq(irp->args.create_window_ex.style, + // WS_OVERLAPPEDWINDOW); // check_int_eq(irp->args.create_window_ex.x, 0); // check_int_eq(irp->args.create_window_ex.y, 0); // check_int_eq(irp->args.create_window_ex.width, 640); @@ -200,7 +211,8 @@ static HRESULT my_d3d9_handler(struct hook_d3d9_irp* irp) case HOOK_D3D9_IRP_OP_GET_CLIENT_RECT: debug_print("Post HOOK_D3D9_IRP_OP_GET_CLIENT_RECT\n"); - // Cannot test because wine is also using this call causing the tests to fail + // Cannot test because wine is also using this call causing the + // tests to fail break; @@ -208,10 +220,13 @@ static HRESULT my_d3d9_handler(struct hook_d3d9_irp* irp) debug_print("Post HOOK_D3D9_IRP_OP_CTX_CREATE_DEVICE\n"); check_non_null(irp->args.ctx_create_device.self); - check_int_eq(irp->args.ctx_create_device.adapter, D3DADAPTER_DEFAULT); + check_int_eq( + irp->args.ctx_create_device.adapter, D3DADAPTER_DEFAULT); check_int_eq(irp->args.ctx_create_device.type, D3DDEVTYPE_HAL); check_non_null(irp->args.ctx_create_device.hwnd); - check_int_eq(irp->args.ctx_create_device.flags, D3DCREATE_HARDWARE_VERTEXPROCESSING); + check_int_eq( + irp->args.ctx_create_device.flags, + D3DCREATE_HARDWARE_VERTEXPROCESSING); check_non_null(irp->args.ctx_create_device.pp); check_non_null(irp->args.ctx_create_device.pdev); @@ -225,8 +240,10 @@ static HRESULT my_d3d9_handler(struct hook_d3d9_irp* irp) check_int_eq(irp->args.dev_create_texture.height, 240); check_int_eq(irp->args.dev_create_texture.levels, 0); check_int_eq(irp->args.dev_create_texture.usage, 0); - check_int_eq(irp->args.dev_create_texture.format, D3DFMT_A8R8G8B8); - check_int_eq(irp->args.dev_create_texture.pool, D3DPOOL_DEFAULT); + check_int_eq( + irp->args.dev_create_texture.format, D3DFMT_A8R8G8B8); + check_int_eq( + irp->args.dev_create_texture.pool, D3DPOOL_DEFAULT); check_non_null(irp->args.dev_create_texture.texture); check_null(irp->args.dev_create_texture.shared_handle); @@ -261,8 +278,10 @@ static HRESULT my_d3d9_handler(struct hook_d3d9_irp* irp) debug_print("Post HOOK_D3D9_IRP_OP_DEV_SET_RENDER_STATE\n"); check_non_null(irp->args.dev_set_render_state.self); - check_int_eq(irp->args.dev_set_render_state.state, D3DRS_FILLMODE); - check_int_eq(irp->args.dev_set_render_state.value, D3DFILL_POINT); + check_int_eq( + irp->args.dev_set_render_state.state, D3DRS_FILLMODE); + check_int_eq( + irp->args.dev_set_render_state.value, D3DFILL_POINT); break; diff --git a/src/test/d3d9hook/main.c b/src/test/d3d9hook/main.c index 53b852e..5d8769f 100644 --- a/src/test/d3d9hook/main.c +++ b/src/test/d3d9hook/main.c @@ -9,85 +9,99 @@ static const int render_loop_iterations = 100; -static LRESULT CALLBACK wnd_proc(HWND wnd, UINT msg, WPARAM w_param, LPARAM l_param); +static LRESULT CALLBACK +wnd_proc(HWND wnd, UINT msg, WPARAM w_param, LPARAM l_param); static HWND create_window() { - WNDCLASS wc; + WNDCLASS wc; HRESULT hr; - memset(&wc, 0, sizeof(WNDCLASS)); - - wc.style = CS_HREDRAW | CS_VREDRAW; - wc.hbrBackground = NULL; - wc.hCursor = LoadCursor(NULL, IDC_ARROW); - wc.lpfnWndProc = (WNDPROC) wnd_proc; - wc.hInstance = NULL; - wc.lpszClassName = "d3d9hook"; + memset(&wc, 0, sizeof(WNDCLASS)); + + wc.style = CS_HREDRAW | CS_VREDRAW; + wc.hbrBackground = NULL; + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.lpfnWndProc = (WNDPROC) wnd_proc; + wc.hInstance = NULL; + wc.lpszClassName = "d3d9hook"; hr = RegisterClass(&wc); check_int_neq(hr, 0); - return CreateWindow("d3d9hook", "d3d9hook test", WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, NULL, NULL, NULL, 0); + return CreateWindow( + "d3d9hook", + "d3d9hook test", + WS_OVERLAPPEDWINDOW, + 0, + 0, + 640, + 480, + NULL, + NULL, + NULL, + 0); } static D3DPRESENT_PARAMETERS create_presenter_params(HWND window) { D3DPRESENT_PARAMETERS pp; - memset(&pp, 0, sizeof(D3DPRESENT_PARAMETERS)); + memset(&pp, 0, sizeof(D3DPRESENT_PARAMETERS)); - pp.BackBufferWidth = 640; - pp.BackBufferHeight = 480; - pp.BackBufferFormat = D3DFMT_A8R8G8B8; - pp.BackBufferCount = 1; - pp.MultiSampleType = D3DMULTISAMPLE_NONE; - pp.MultiSampleQuality = 0; - pp.SwapEffect = D3DSWAPEFFECT_DISCARD; - pp.hDeviceWindow = window; - pp.Windowed = TRUE; - pp.EnableAutoDepthStencil = TRUE; - pp.AutoDepthStencilFormat = D3DFMT_D24S8; - pp.Flags = 0; - pp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; - pp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; + pp.BackBufferWidth = 640; + pp.BackBufferHeight = 480; + pp.BackBufferFormat = D3DFMT_A8R8G8B8; + pp.BackBufferCount = 1; + pp.MultiSampleType = D3DMULTISAMPLE_NONE; + pp.MultiSampleQuality = 0; + pp.SwapEffect = D3DSWAPEFFECT_DISCARD; + pp.hDeviceWindow = window; + pp.Windowed = TRUE; + pp.EnableAutoDepthStencil = TRUE; + pp.AutoDepthStencilFormat = D3DFMT_D24S8; + pp.Flags = 0; + pp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; + pp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; - return pp; + return pp; } -static IDirect3DTexture9* create_texture(IDirect3DDevice9* dev) +static IDirect3DTexture9 *create_texture(IDirect3DDevice9 *dev) { - HRESULT hr; - IDirect3DTexture9* texture; + HRESULT hr; + IDirect3DTexture9 *texture; - hr = IDirect3DDevice9_CreateTexture(dev, 320, 240, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture, NULL); - check_int_eq(hr, S_OK); + hr = IDirect3DDevice9_CreateTexture( + dev, 320, 240, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture, NULL); + check_int_eq(hr, S_OK); - return texture; + return texture; } -int main(int argc, char** argv) +int main(int argc, char **argv) { - DISPLAY_DEVICEA display_device; - BOOL res; - HWND window; - RECT rect; + DISPLAY_DEVICEA display_device; + BOOL res; + HWND window; + RECT rect; MSG msg; - IDirect3D9* d3d9; + IDirect3D9 *d3d9; HRESULT hr; D3DPRESENT_PARAMETERS pp; - IDirect3DDevice9* dev; + IDirect3DDevice9 *dev; int loop_count; - IDirect3DTexture9* texture; - - res = EnumDisplayDevicesA(NULL, 0, &display_device, EDD_GET_DEVICE_INTERFACE_NAME); - check_int_eq(res, TRUE); + IDirect3DTexture9 *texture; + + res = EnumDisplayDevicesA( + NULL, 0, &display_device, EDD_GET_DEVICE_INTERFACE_NAME); + check_int_eq(res, TRUE); window = create_window(); - check_non_null(window); + check_non_null(window); - res = GetClientRect(window, &rect); - check_int_eq(res, TRUE); + res = GetClientRect(window, &rect); + check_int_eq(res, TRUE); d3d9 = Direct3DCreate9(D3D_SDK_VERSION); check_non_null(d3d9); @@ -97,37 +111,45 @@ int main(int argc, char** argv) hr = IDirect3D9_CreateDevice( d3d9, D3DADAPTER_DEFAULT, - D3DDEVTYPE_HAL, - window, - D3DCREATE_HARDWARE_VERTEXPROCESSING, - &pp, - &dev); + D3DDEVTYPE_HAL, + window, + D3DCREATE_HARDWARE_VERTEXPROCESSING, + &pp, + &dev); check_int_eq(hr, S_OK); IDirect3DDevice9_Release(d3d9); d3d9 = NULL; - texture = create_texture(dev); + texture = create_texture(dev); - ShowWindow(window, SW_SHOW); - UpdateWindow(window); + ShowWindow(window, SW_SHOW); + UpdateWindow(window); - memset(&msg, 0, sizeof(MSG)); + memset(&msg, 0, sizeof(MSG)); loop_count = 0; - // TODO create vertex buffer, upload and render + // TODO create vertex buffer, upload and render - while (msg.message != WM_QUIT) { - if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } else { - hr = IDirect3DDevice9_Clear(dev, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0); + while (msg.message != WM_QUIT) { + if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } else { + hr = IDirect3DDevice9_Clear( + dev, + 0, + NULL, + D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, + 0xff0000ff, + 1.0f, + 0); check_int_eq(hr, S_OK); - hr = IDirect3DDevice9_SetRenderState(dev, D3DRS_FILLMODE, D3DFILL_POINT); - check_int_eq(hr, S_OK); + hr = IDirect3DDevice9_SetRenderState( + dev, D3DRS_FILLMODE, D3DFILL_POINT); + check_int_eq(hr, S_OK); hr = IDirect3DDevice9_BeginScene(dev); check_int_eq(hr, S_OK); @@ -143,25 +165,25 @@ int main(int argc, char** argv) if (loop_count > render_loop_iterations) { PostQuitMessage(0); } - } - } + } + } - IDirect3DTexture9_Release(texture); - IDirect3DDevice9_Release(dev); - - return 0; + IDirect3DTexture9_Release(texture); + IDirect3DDevice9_Release(dev); + + return 0; } LRESULT CALLBACK wnd_proc(HWND wnd, UINT msg, WPARAM w_param, LPARAM l_param) { - switch(msg) { + switch (msg) { case WM_CREATE: break; case WM_DESTROY: PostQuitMessage(0); break; - } + } - return DefWindowProc(wnd, msg, w_param, l_param); + return DefWindowProc(wnd, msg, w_param, l_param); } \ No newline at end of file diff --git a/src/test/iidxhook-util/iidxhook-util-config-eamuse-test.c b/src/test/iidxhook-util/iidxhook-util-config-eamuse-test.c index 77b87e0..ade73ff 100644 --- a/src/test/iidxhook-util/iidxhook-util-config-eamuse-test.c +++ b/src/test/iidxhook-util/iidxhook-util-config-eamuse-test.c @@ -8,7 +8,7 @@ static void test_config_eamuse_defaults() { - struct cconfig* config; + struct cconfig *config; struct iidxhook_util_config_eamuse config_eamuse; config = cconfig_init(); @@ -20,15 +20,17 @@ static void test_config_eamuse_defaults() check_str_eq(config_eamuse.card_type, "C02"); check_str_eq(net_addr_to_str(&config_eamuse.server), "localhost:80"); - check_str_eq(security_id_to_str(&config_eamuse.pcbid, false), + check_str_eq( + security_id_to_str(&config_eamuse.pcbid, false), "0101020304050607086F"); - check_str_eq(security_id_to_str(&config_eamuse.eamid, false), + check_str_eq( + security_id_to_str(&config_eamuse.eamid, false), "0101020304050607086F"); } static void test_config_eamuse() { - struct cconfig* config; + struct cconfig *config; struct iidxhook_util_config_eamuse config_eamuse; config = cconfig_init(); @@ -45,17 +47,19 @@ static void test_config_eamuse() cconfig_finit(config); check_str_eq(config_eamuse.card_type, "D01"); - check_str_eq(net_addr_to_str(&config_eamuse.server), - "http://myServer.com/legacy"); - check_str_eq(security_id_to_str(&config_eamuse.pcbid, false), + check_str_eq( + net_addr_to_str(&config_eamuse.server), "http://myServer.com/legacy"); + check_str_eq( + security_id_to_str(&config_eamuse.pcbid, false), "0101020304050607086F"); - check_str_eq(security_id_to_str(&config_eamuse.eamid, false), + check_str_eq( + security_id_to_str(&config_eamuse.eamid, false), "0101020304050607086F"); } static void test_config_eamuse_invalid_values() { - struct cconfig* config; + struct cconfig *config; struct iidxhook_util_config_eamuse config_eamuse; config = cconfig_init(); @@ -73,9 +77,11 @@ static void test_config_eamuse_invalid_values() check_str_eq(config_eamuse.card_type, "C02"); check_str_eq(net_addr_to_str(&config_eamuse.server), "asdf"); - check_str_eq(security_id_to_str(&config_eamuse.pcbid, false), + check_str_eq( + security_id_to_str(&config_eamuse.pcbid, false), "00000000000000000000"); - check_str_eq(security_id_to_str(&config_eamuse.eamid, false), + check_str_eq( + security_id_to_str(&config_eamuse.eamid, false), "00000000000000000000"); } diff --git a/src/test/iidxhook-util/iidxhook-util-config-gfx-test.c b/src/test/iidxhook-util/iidxhook-util-config-gfx-test.c index d107e92..3009df0 100644 --- a/src/test/iidxhook-util/iidxhook-util-config-gfx-test.c +++ b/src/test/iidxhook-util/iidxhook-util-config-gfx-test.c @@ -3,12 +3,12 @@ #include "test/check.h" #include "test/test.h" -/* We don't care about cleaning up some of the memory to avoid cluttering +/* We don't care about cleaning up some of the memory to avoid cluttering the tests */ static void test_config_gfx_defaults() { - struct cconfig* config; + struct cconfig *config; struct iidxhook_config_gfx config_gfx; config = cconfig_init(); @@ -27,12 +27,14 @@ static void test_config_gfx_defaults() check_bool_false(config_gfx.windowed); check_int_eq(config_gfx.scale_back_buffer_width, 0); check_int_eq(config_gfx.scale_back_buffer_height, 0); - check_int_eq(config_gfx.scale_back_buffer_width, IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_NONE); + check_int_eq( + config_gfx.scale_back_buffer_width, + IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_NONE); } static void test_config_gfx() { - struct cconfig* config; + struct cconfig *config; struct iidxhook_config_gfx config_gfx; config = cconfig_init(); @@ -62,12 +64,14 @@ static void test_config_gfx() check_bool_true(config_gfx.windowed); check_int_eq(config_gfx.scale_back_buffer_width, 1920); check_int_eq(config_gfx.scale_back_buffer_height, 1080); - check_int_eq(config_gfx.scale_back_buffer_filter, IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_LINEAR); + check_int_eq( + config_gfx.scale_back_buffer_filter, + IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_LINEAR); } static void test_config_gfx_invalid_values() { - struct cconfig* config; + struct cconfig *config; struct iidxhook_config_gfx config_gfx; config = cconfig_init(); @@ -97,7 +101,9 @@ static void test_config_gfx_invalid_values() check_bool_false(config_gfx.windowed); check_int_eq(config_gfx.scale_back_buffer_width, 0); check_int_eq(config_gfx.scale_back_buffer_height, 0); - check_int_eq(config_gfx.scale_back_buffer_width, IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_NONE); + check_int_eq( + config_gfx.scale_back_buffer_width, + IIDXHOOK_UTIL_D3D9_BACK_BUFFER_SCALE_FILTER_NONE); } TEST_MODULE_BEGIN("iidxhook-config-gfx") diff --git a/src/test/iidxhook-util/iidxhook-util-config-misc-test.c b/src/test/iidxhook-util/iidxhook-util-config-misc-test.c index 02a178a..6aa9d3e 100644 --- a/src/test/iidxhook-util/iidxhook-util-config-misc-test.c +++ b/src/test/iidxhook-util/iidxhook-util-config-misc-test.c @@ -3,11 +3,12 @@ #include "test/check.h" #include "test/test.h" -/* We don't care about cleaning up some of the memory to avoid cluttering the tests */ +/* We don't care about cleaning up some of the memory to avoid cluttering the + * tests */ static void test_config_misc_defaults() { - struct cconfig* config; + struct cconfig *config; struct iidxhook_config_misc config_misc; config = cconfig_init(); @@ -23,7 +24,7 @@ static void test_config_misc_defaults() static void test_config_misc() { - struct cconfig* config; + struct cconfig *config; struct iidxhook_config_misc config_misc; config = cconfig_init(); @@ -43,7 +44,7 @@ static void test_config_misc() static void test_config_misc_invalid_values() { - struct cconfig* config; + struct cconfig *config; struct iidxhook_config_misc config_misc; config = cconfig_init(); diff --git a/src/test/iidxhook-util/iidxhook-util-config-sec-test.c b/src/test/iidxhook-util/iidxhook-util-config-sec-test.c index 32bd92b..9c12aa4 100644 --- a/src/test/iidxhook-util/iidxhook-util-config-sec-test.c +++ b/src/test/iidxhook-util/iidxhook-util-config-sec-test.c @@ -3,11 +3,12 @@ #include "test/check.h" #include "test/test.h" -/* We don't care about cleaning up some of the memory to avoid cluttering the tests */ +/* We don't care about cleaning up some of the memory to avoid cluttering the + * tests */ static void test_config_sec_defaults() { - struct cconfig* config; + struct cconfig *config; struct iidxhook_config_sec config_sec; const uint32_t boot_seeds[3] = {0, 0, 0}; @@ -19,15 +20,18 @@ static void test_config_sec_defaults() cconfig_finit(config); check_str_eq(security_mcode_to_str(&config_sec.boot_version), "GEC02 "); - check_data_eq(config_sec.boot_seeds, sizeof(config_sec.boot_seeds), - (void*) boot_seeds, sizeof(boot_seeds)); - check_str_eq(security_mcode_to_str(&config_sec.black_plug_mcode), - "GQC02JAA"); + check_data_eq( + config_sec.boot_seeds, + sizeof(config_sec.boot_seeds), + (void *) boot_seeds, + sizeof(boot_seeds)); + check_str_eq( + security_mcode_to_str(&config_sec.black_plug_mcode), "GQC02JAA"); } static void test_config_sec() { - struct cconfig* config; + struct cconfig *config; struct iidxhook_config_sec config_sec; const uint32_t boot_seeds[3] = {1, 1, 1}; @@ -44,15 +48,18 @@ static void test_config_sec() cconfig_finit(config); check_str_eq(security_mcode_to_str(&config_sec.boot_version), "ASDFG "); - check_data_eq(config_sec.boot_seeds, sizeof(config_sec.boot_seeds), - (void*) boot_seeds, sizeof(boot_seeds)); - check_str_eq(security_mcode_to_str(&config_sec.black_plug_mcode), - "GQD01JAB"); + check_data_eq( + config_sec.boot_seeds, + sizeof(config_sec.boot_seeds), + (void *) boot_seeds, + sizeof(boot_seeds)); + check_str_eq( + security_mcode_to_str(&config_sec.black_plug_mcode), "GQD01JAB"); } static void test_config_sec_invalid_values() { - struct cconfig* config; + struct cconfig *config; struct iidxhook_config_sec config_sec; const uint32_t boot_seeds[3] = {0, 0, 0}; @@ -69,10 +76,13 @@ static void test_config_sec_invalid_values() cconfig_finit(config); check_str_eq(security_mcode_to_str(&config_sec.boot_version), "GEC02 "); - check_data_eq(config_sec.boot_seeds, sizeof(config_sec.boot_seeds), - (void*) boot_seeds, sizeof(boot_seeds)); - check_str_eq(security_mcode_to_str(&config_sec.black_plug_mcode), - "GQC02JAA"); + check_data_eq( + config_sec.boot_seeds, + sizeof(config_sec.boot_seeds), + (void *) boot_seeds, + sizeof(boot_seeds)); + check_str_eq( + security_mcode_to_str(&config_sec.black_plug_mcode), "GQC02JAA"); } TEST_MODULE_BEGIN("iidxhook-config-sec") diff --git a/src/test/iidxhook/iidxhook-config-iidxhook1-test.c b/src/test/iidxhook/iidxhook-config-iidxhook1-test.c index a3954ef..9825898 100644 --- a/src/test/iidxhook/iidxhook-config-iidxhook1-test.c +++ b/src/test/iidxhook/iidxhook-config-iidxhook1-test.c @@ -3,11 +3,12 @@ #include "test/check.h" #include "test/test.h" -/* We don't care about cleaning up some of the memory to avoid cluttering the tests */ +/* We don't care about cleaning up some of the memory to avoid cluttering the + * tests */ static void test_config_iidxhook1_defaults() { - struct cconfig* config; + struct cconfig *config; struct iidxhook_config_iidxhook1 config_iidxhook1; config = cconfig_init(); @@ -22,7 +23,7 @@ static void test_config_iidxhook1_defaults() static void test_config_iidxhook1() { - struct cconfig* config; + struct cconfig *config; struct iidxhook_config_iidxhook1 config_iidxhook1; config = cconfig_init(); @@ -40,7 +41,7 @@ static void test_config_iidxhook1() static void test_config_iidxhook1_invalid_values() { - struct cconfig* config; + struct cconfig *config; struct iidxhook_config_iidxhook1 config_iidxhook1; config = cconfig_init(); diff --git a/src/test/iidxhook/iidxhook-config-iidxhook2-test.c b/src/test/iidxhook/iidxhook-config-iidxhook2-test.c index 5a5f597..00f3e94 100644 --- a/src/test/iidxhook/iidxhook-config-iidxhook2-test.c +++ b/src/test/iidxhook/iidxhook-config-iidxhook2-test.c @@ -3,11 +3,12 @@ #include "test/check.h" #include "test/test.h" -/* We don't care about cleaning up some of the memory to avoid cluttering the tests */ +/* We don't care about cleaning up some of the memory to avoid cluttering the + * tests */ static void test_config_iidxhook2_defaults() { - struct cconfig* config; + struct cconfig *config; struct iidxhook_config_iidxhook2 config_iidxhook2; config = cconfig_init(); @@ -22,7 +23,7 @@ static void test_config_iidxhook2_defaults() static void test_config_iidxhook2() { - struct cconfig* config; + struct cconfig *config; struct iidxhook_config_iidxhook2 config_iidxhook2; config = cconfig_init(); @@ -40,7 +41,7 @@ static void test_config_iidxhook2() static void test_config_iidxhook2_invalid_values() { - struct cconfig* config; + struct cconfig *config; struct iidxhook_config_iidxhook2 config_iidxhook2; config = cconfig_init(); diff --git a/src/test/iidxhook8/iidxhook8-config-cam-test.c b/src/test/iidxhook8/iidxhook8-config-cam-test.c index a605187..8c2a88d 100644 --- a/src/test/iidxhook8/iidxhook8-config-cam-test.c +++ b/src/test/iidxhook8/iidxhook8-config-cam-test.c @@ -3,11 +3,12 @@ #include "test/check.h" #include "test/test.h" -/* We don't care about cleaning up some of the memory to avoid cluttering the tests */ +/* We don't care about cleaning up some of the memory to avoid cluttering the + * tests */ static void test_config_cam_defaults() { - struct cconfig* config; + struct cconfig *config; struct iidxhook8_config_cam config_cam; config = cconfig_init(); @@ -24,7 +25,7 @@ static void test_config_cam_defaults() static void test_config_cam() { - struct cconfig* config; + struct cconfig *config; struct iidxhook8_config_cam config_cam; config = cconfig_init(); @@ -46,7 +47,7 @@ static void test_config_cam() static void test_config_invalid_values() { - struct cconfig* config; + struct cconfig *config; struct iidxhook8_config_cam config_cam; config = cconfig_init(); diff --git a/src/test/iidxhook8/iidxhook8-config-io-test.c b/src/test/iidxhook8/iidxhook8-config-io-test.c index 293e8b9..a53ea8e 100644 --- a/src/test/iidxhook8/iidxhook8-config-io-test.c +++ b/src/test/iidxhook8/iidxhook8-config-io-test.c @@ -3,11 +3,12 @@ #include "test/check.h" #include "test/test.h" -/* We don't care about cleaning up some of the memory to avoid cluttering the tests */ +/* We don't care about cleaning up some of the memory to avoid cluttering the + * tests */ static void test_config_io_defaults() { - struct cconfig* config; + struct cconfig *config; struct iidxhook8_config_io config_io; config = cconfig_init(); @@ -24,7 +25,7 @@ static void test_config_io_defaults() static void test_config_io() { - struct cconfig* config; + struct cconfig *config; struct iidxhook8_config_io config_io; config = cconfig_init(); @@ -46,7 +47,7 @@ static void test_config_io() static void test_config_invalid_values() { - struct cconfig* config; + struct cconfig *config; struct iidxhook8_config_io config_io; config = cconfig_init(); diff --git a/src/test/security/security-id-test.c b/src/test/security/security-id-test.c index c40b6cd..fec8383 100644 --- a/src/test/security/security-id-test.c +++ b/src/test/security/security-id-test.c @@ -5,10 +5,11 @@ static void test_to_str() { - check_str_eq(security_id_to_str(&security_id_default, false), + check_str_eq( + security_id_to_str(&security_id_default, false), "0101020304050607086F"); - check_str_eq(security_id_to_str(&security_id_default, true), - "0102030405060708"); + check_str_eq( + security_id_to_str(&security_id_default, true), "0102030405060708"); } static void test_parse_valid() diff --git a/src/test/security/security-rp-test.c b/src/test/security/security-rp-test.c index a1e0a61..8bc7f82 100644 --- a/src/test/security/security-rp-test.c +++ b/src/test/security/security-rp-test.c @@ -93,12 +93,17 @@ static void test_encode_iidx_09_black_dongle() { struct security_rp_eeprom result; - security_rp_generate_signed_eeprom_data(&boot_version_iidx_09_to_13, - boot_seeds_iidx_09, &black_plug_mcode_iidx_09, &security_id_default, + security_rp_generate_signed_eeprom_data( + &boot_version_iidx_09_to_13, + boot_seeds_iidx_09, + &black_plug_mcode_iidx_09, + &security_id_default, &result); - check_data_eq((void*) &exp_iidx_09_black_eeprom, - sizeof(struct security_rp_eeprom), (void*) &result, + check_data_eq( + (void *) &exp_iidx_09_black_eeprom, + sizeof(struct security_rp_eeprom), + (void *) &result, sizeof(struct security_rp_eeprom)); } @@ -106,12 +111,17 @@ static void test_encode_iidx_10_black_dongle() { struct security_rp_eeprom result; - security_rp_generate_signed_eeprom_data(&boot_version_iidx_09_to_13, - boot_seeds_iidx_10, &black_plug_mcode_iidx_10, &security_id_default, + security_rp_generate_signed_eeprom_data( + &boot_version_iidx_09_to_13, + boot_seeds_iidx_10, + &black_plug_mcode_iidx_10, + &security_id_default, &result); - check_data_eq((void*) &exp_iidx_10_black_eeprom, - sizeof(struct security_rp_eeprom), (void*) &result, + check_data_eq( + (void *) &exp_iidx_10_black_eeprom, + sizeof(struct security_rp_eeprom), + (void *) &result, sizeof(struct security_rp_eeprom)); } @@ -119,12 +129,17 @@ static void test_encode_iidx_11_black_dongle() { struct security_rp_eeprom result; - security_rp_generate_signed_eeprom_data(&boot_version_iidx_09_to_13, - boot_seeds_iidx_11, &black_plug_mcode_iidx_11, &security_id_default, + security_rp_generate_signed_eeprom_data( + &boot_version_iidx_09_to_13, + boot_seeds_iidx_11, + &black_plug_mcode_iidx_11, + &security_id_default, &result); - check_data_eq((void*) &exp_iidx_11_black_eeprom, - sizeof(struct security_rp_eeprom), (void*) &result, + check_data_eq( + (void *) &exp_iidx_11_black_eeprom, + sizeof(struct security_rp_eeprom), + (void *) &result, sizeof(struct security_rp_eeprom)); } @@ -132,12 +147,17 @@ static void test_encode_iidx_12_black_dongle() { struct security_rp_eeprom result; - security_rp_generate_signed_eeprom_data(&boot_version_iidx_09_to_13, - boot_seeds_iidx_12, &black_plug_mcode_iidx_12, &security_id_default, + security_rp_generate_signed_eeprom_data( + &boot_version_iidx_09_to_13, + boot_seeds_iidx_12, + &black_plug_mcode_iidx_12, + &security_id_default, &result); - check_data_eq((void*) &exp_iidx_12_black_eeprom, - sizeof(struct security_rp_eeprom), (void*) &result, + check_data_eq( + (void *) &exp_iidx_12_black_eeprom, + sizeof(struct security_rp_eeprom), + (void *) &result, sizeof(struct security_rp_eeprom)); } @@ -145,12 +165,17 @@ static void test_encode_iidx_13_black_dongle() { struct security_rp_eeprom result; - security_rp_generate_signed_eeprom_data(&boot_version_iidx_09_to_13, - boot_seeds_iidx_13, &black_plug_mcode_iidx_13, &security_id_default, + security_rp_generate_signed_eeprom_data( + &boot_version_iidx_09_to_13, + boot_seeds_iidx_13, + &black_plug_mcode_iidx_13, + &security_id_default, &result); - check_data_eq((void*) &exp_iidx_13_black_eeprom, - sizeof(struct security_rp_eeprom), (void*) &result, + check_data_eq( + (void *) &exp_iidx_13_black_eeprom, + sizeof(struct security_rp_eeprom), + (void *) &result, sizeof(struct security_rp_eeprom)); } diff --git a/src/test/security/security-rp2-test.c b/src/test/security/security-rp2-test.c index e3495f6..274f250 100644 --- a/src/test/security/security-rp2-test.c +++ b/src/test/security/security-rp2-test.c @@ -120,96 +120,144 @@ static void test_encode_iidx_14_black_dongle() { struct security_rp2_eeprom result; - security_rp2_generate_signed_eeprom_data(SECURITY_RP_UTIL_RP_TYPE_BLACK, - &boot_version_iidx_14, &black_plug_mcode_iidx_14, &security_id_default, + security_rp2_generate_signed_eeprom_data( + SECURITY_RP_UTIL_RP_TYPE_BLACK, + &boot_version_iidx_14, + &black_plug_mcode_iidx_14, + &security_id_default, &result); - check_data_eq((void*) &result, sizeof(struct security_rp2_eeprom), - (void*) &exp_iidx_14_black_eeprom, sizeof(struct security_rp2_eeprom)); + check_data_eq( + (void *) &result, + sizeof(struct security_rp2_eeprom), + (void *) &exp_iidx_14_black_eeprom, + sizeof(struct security_rp2_eeprom)); } static void test_encode_iidx_14_white_dongle() { struct security_rp2_eeprom result; - security_rp2_generate_signed_eeprom_data(SECURITY_RP_UTIL_RP_TYPE_WHITE, - &boot_version_iidx_14, &security_mcode_eamuse, &security_id_default, + security_rp2_generate_signed_eeprom_data( + SECURITY_RP_UTIL_RP_TYPE_WHITE, + &boot_version_iidx_14, + &security_mcode_eamuse, + &security_id_default, &result); - check_data_eq((void*) &result, sizeof(struct security_rp2_eeprom), - (void*) &exp_iidx_14_white_eeprom, sizeof(struct security_rp2_eeprom)); + check_data_eq( + (void *) &result, + sizeof(struct security_rp2_eeprom), + (void *) &exp_iidx_14_white_eeprom, + sizeof(struct security_rp2_eeprom)); } static void test_encode_iidx_15_black_dongle() { struct security_rp2_eeprom result; - security_rp2_generate_signed_eeprom_data(SECURITY_RP_UTIL_RP_TYPE_BLACK, - &boot_version_iidx_15, &black_plug_mcode_iidx_15, &security_id_default, + security_rp2_generate_signed_eeprom_data( + SECURITY_RP_UTIL_RP_TYPE_BLACK, + &boot_version_iidx_15, + &black_plug_mcode_iidx_15, + &security_id_default, &result); - check_data_eq((void*) &result, sizeof(struct security_rp2_eeprom), - (void*) &exp_iidx_15_black_eeprom, sizeof(struct security_rp2_eeprom)); + check_data_eq( + (void *) &result, + sizeof(struct security_rp2_eeprom), + (void *) &exp_iidx_15_black_eeprom, + sizeof(struct security_rp2_eeprom)); } static void test_encode_iidx_15_white_dongle() { struct security_rp2_eeprom result; - security_rp2_generate_signed_eeprom_data(SECURITY_RP_UTIL_RP_TYPE_WHITE, - &boot_version_iidx_15, &security_mcode_eamuse, &security_id_default, + security_rp2_generate_signed_eeprom_data( + SECURITY_RP_UTIL_RP_TYPE_WHITE, + &boot_version_iidx_15, + &security_mcode_eamuse, + &security_id_default, &result); - check_data_eq((void*) &result, sizeof(struct security_rp2_eeprom), - (void*) &exp_iidx_15_white_eeprom, sizeof(struct security_rp2_eeprom)); + check_data_eq( + (void *) &result, + sizeof(struct security_rp2_eeprom), + (void *) &exp_iidx_15_white_eeprom, + sizeof(struct security_rp2_eeprom)); } static void test_encode_iidx_16_black_dongle() { struct security_rp2_eeprom result; - security_rp2_generate_signed_eeprom_data(SECURITY_RP_UTIL_RP_TYPE_BLACK, - &boot_version_iidx_16, &black_plug_mcode_iidx_16, &security_id_default, + security_rp2_generate_signed_eeprom_data( + SECURITY_RP_UTIL_RP_TYPE_BLACK, + &boot_version_iidx_16, + &black_plug_mcode_iidx_16, + &security_id_default, &result); - check_data_eq((void*) &result, sizeof(struct security_rp2_eeprom), - (void*) &exp_iidx_16_black_eeprom, sizeof(struct security_rp2_eeprom)); + check_data_eq( + (void *) &result, + sizeof(struct security_rp2_eeprom), + (void *) &exp_iidx_16_black_eeprom, + sizeof(struct security_rp2_eeprom)); } static void test_encode_iidx_16_white_dongle() { struct security_rp2_eeprom result; - security_rp2_generate_signed_eeprom_data(SECURITY_RP_UTIL_RP_TYPE_WHITE, - &boot_version_iidx_16, &security_mcode_eamuse, &security_id_default, + security_rp2_generate_signed_eeprom_data( + SECURITY_RP_UTIL_RP_TYPE_WHITE, + &boot_version_iidx_16, + &security_mcode_eamuse, + &security_id_default, &result); - check_data_eq((void*) &result, sizeof(struct security_rp2_eeprom), - (void*) &exp_iidx_16_white_eeprom, sizeof(struct security_rp2_eeprom)); + check_data_eq( + (void *) &result, + sizeof(struct security_rp2_eeprom), + (void *) &exp_iidx_16_white_eeprom, + sizeof(struct security_rp2_eeprom)); } static void test_encode_iidx_17_black_dongle() { struct security_rp2_eeprom result; - security_rp2_generate_signed_eeprom_data(SECURITY_RP_UTIL_RP_TYPE_BLACK, - &boot_version_iidx_17, &black_plug_mcode_iidx_17, &security_id_default, + security_rp2_generate_signed_eeprom_data( + SECURITY_RP_UTIL_RP_TYPE_BLACK, + &boot_version_iidx_17, + &black_plug_mcode_iidx_17, + &security_id_default, &result); - check_data_eq((void*) &result, sizeof(struct security_rp2_eeprom), - (void*) &exp_iidx_17_black_eeprom, sizeof(struct security_rp2_eeprom)); + check_data_eq( + (void *) &result, + sizeof(struct security_rp2_eeprom), + (void *) &exp_iidx_17_black_eeprom, + sizeof(struct security_rp2_eeprom)); } static void test_encode_iidx_17_white_dongle() { struct security_rp2_eeprom result; - security_rp2_generate_signed_eeprom_data(SECURITY_RP_UTIL_RP_TYPE_WHITE, - &boot_version_iidx_17, &security_mcode_eamuse, &security_id_default, + security_rp2_generate_signed_eeprom_data( + SECURITY_RP_UTIL_RP_TYPE_WHITE, + &boot_version_iidx_17, + &security_mcode_eamuse, + &security_id_default, &result); - check_data_eq((void*) &result, sizeof(struct security_rp2_eeprom), - (void*) &exp_iidx_17_white_eeprom, sizeof(struct security_rp2_eeprom)); + check_data_eq( + (void *) &result, + sizeof(struct security_rp2_eeprom), + (void *) &exp_iidx_17_white_eeprom, + sizeof(struct security_rp2_eeprom)); } TEST_MODULE_BEGIN("security-rp2") diff --git a/src/test/security/security-rp3-test.c b/src/test/security/security-rp3-test.c index a56dd91..6f3415a 100644 --- a/src/test/security/security-rp3-test.c +++ b/src/test/security/security-rp3-test.c @@ -1,5 +1,5 @@ -#include "security/rp3.h" #include "security/rp-sign-key.h" +#include "security/rp3.h" #include "test/check.h" #include "test/test.h" @@ -16,16 +16,50 @@ static const struct security_mcode black_plug_mcode_jubeat = { static const struct security_rp3_eeprom exp_jubeat_black_eeprom = { .signature = {0x73, 0x66, 0xBA, 0xBD, 0xDE, 0x36}, .packed_payload = {0xE7, 0x88, 0x52, 0x94, 0x1A, 0x8A}, - .zeros = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + .zeros = {0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00}, .crc = 0xA3, }; static const struct security_rp3_eeprom exp_jubeat_white_eeprom = { .signature = {0x43, 0x17, 0xB4, 0x2A, 0x3E, 0x87}, .packed_payload = {0x20, 0x08, 0x82, 0x20, 0x08, 0x82}, - .zeros = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + .zeros = {0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00}, .crc = 0x94, }; @@ -33,12 +67,17 @@ static void test_mcode_encode_black_dongle_jubeat() { struct security_rp3_eeprom result; - security_rp3_generate_signed_eeprom_data(SECURITY_RP_UTIL_RP_TYPE_BLACK, - &security_rp_sign_key_black_gfdmv4, &black_plug_mcode_jubeat, - &security_id_default, &result); + security_rp3_generate_signed_eeprom_data( + SECURITY_RP_UTIL_RP_TYPE_BLACK, + &security_rp_sign_key_black_gfdmv4, + &black_plug_mcode_jubeat, + &security_id_default, + &result); - check_data_eq((void*) &exp_jubeat_black_eeprom, - sizeof(struct security_rp3_eeprom), (void*) &result, + check_data_eq( + (void *) &exp_jubeat_black_eeprom, + sizeof(struct security_rp3_eeprom), + (void *) &result, sizeof(struct security_rp3_eeprom)); } @@ -46,12 +85,17 @@ static void test_mcode_encode_white_dongle_jubeat() { struct security_rp3_eeprom result; - security_rp3_generate_signed_eeprom_data(SECURITY_RP_UTIL_RP_TYPE_WHITE, - &security_rp_sign_key_white_eamuse, &security_mcode_eamuse, - &security_id_default, &result); + security_rp3_generate_signed_eeprom_data( + SECURITY_RP_UTIL_RP_TYPE_WHITE, + &security_rp_sign_key_white_eamuse, + &security_mcode_eamuse, + &security_id_default, + &result); - check_data_eq((void*) &exp_jubeat_white_eeprom, - sizeof(struct security_rp3_eeprom), (void*) &result, + check_data_eq( + (void *) &exp_jubeat_white_eeprom, + sizeof(struct security_rp3_eeprom), + (void *) &result, sizeof(struct security_rp3_eeprom)); } diff --git a/src/test/security/security-util-test.c b/src/test/security/security-util-test.c index 2aef06e..91b2d47 100644 --- a/src/test/security/security-util-test.c +++ b/src/test/security/security-util-test.c @@ -18,10 +18,14 @@ static void test_mcode_encode_decode_eamuse() uint8_t buffer[8]; uint8_t result[8]; - security_util_8_to_6_encode((const uint8_t*) &security_mcode_eamuse, buffer); + security_util_8_to_6_encode( + (const uint8_t *) &security_mcode_eamuse, buffer); security_util_6_to_8_decode(buffer, result); - check_data_eq(result, sizeof(result), &security_mcode_eamuse, + check_data_eq( + result, + sizeof(result), + &security_mcode_eamuse, sizeof(security_mcode_eamuse)); } @@ -30,11 +34,14 @@ static void test_mcode_encode_decode_jubeat() uint8_t buffer[8]; uint8_t result[8]; - security_util_8_to_6_encode((const uint8_t*) &black_plug_mcode_jubeat, - buffer); + security_util_8_to_6_encode( + (const uint8_t *) &black_plug_mcode_jubeat, buffer); security_util_6_to_8_decode(buffer, result); - check_data_eq(result, sizeof(result), &black_plug_mcode_jubeat, + check_data_eq( + result, + sizeof(result), + &black_plug_mcode_jubeat, sizeof(black_plug_mcode_jubeat)); } @@ -43,11 +50,14 @@ static void test_mcode_encode_decode_reverse_eamuse() uint8_t buffer[8]; uint8_t result[8]; - security_util_8_to_6_encode_reverse((const uint8_t*) &security_mcode_eamuse, - buffer); + security_util_8_to_6_encode_reverse( + (const uint8_t *) &security_mcode_eamuse, buffer); security_util_6_to_8_decode_reverse(buffer, result); - check_data_eq(result, sizeof(result), &security_mcode_eamuse, + check_data_eq( + result, + sizeof(result), + &security_mcode_eamuse, sizeof(security_mcode_eamuse)); } @@ -57,10 +67,13 @@ static void test_mcode_encode_decode_reverse_jubeat() uint8_t result[8]; security_util_8_to_6_encode_reverse( - (const uint8_t*) &black_plug_mcode_jubeat, buffer); + (const uint8_t *) &black_plug_mcode_jubeat, buffer); security_util_6_to_8_decode_reverse(buffer, result); - check_data_eq(result, sizeof(result), &black_plug_mcode_jubeat, + check_data_eq( + result, + sizeof(result), + &black_plug_mcode_jubeat, sizeof(black_plug_mcode_jubeat)); } diff --git a/src/test/test/check.c b/src/test/test/check.c index 8d6e9aa..d432c9f 100644 --- a/src/test/test/check.c +++ b/src/test/test/check.c @@ -8,8 +8,8 @@ #include "util/hex.h" -static void _Noreturn __attribute__((format (printf, 4, 5))) fail( - const char *file, int line, const char *func, const char *fmt, ...) +static void _Noreturn __attribute__((format(printf, 4, 5))) +fail(const char *file, int line, const char *func, const char *fmt, ...) { va_list ap; @@ -21,128 +21,228 @@ static void _Noreturn __attribute__((format (printf, 4, 5))) fail( abort(); } -void _Noreturn check_char_eq_failed(const char *file, int line, - const char *func, char *expr, char result, char expected) +void _Noreturn check_char_eq_failed( + const char *file, + int line, + const char *func, + char *expr, + char result, + char expected) { - fail(file, line, func, - "\tIncorrect result: %s\n" - "\tReturn value was %c\n" - "\tExpected %c\n\n", - expr, result, expected); + fail( + file, + line, + func, + "\tIncorrect result: %s\n" + "\tReturn value was %c\n" + "\tExpected %c\n\n", + expr, + result, + expected); } -void _Noreturn check_char_neq_failed(const char *file, int line, - const char *func, char *expr, char result, char expected) +void _Noreturn check_char_neq_failed( + const char *file, + int line, + const char *func, + char *expr, + char result, + char expected) { - fail(file, line, func, - "\tIncorrect result: %s\n" - "\tReturn value was %c\n" - "\tNot expected %c\n\n", - expr, result, expected); + fail( + file, + line, + func, + "\tIncorrect result: %s\n" + "\tReturn value was %c\n" + "\tNot expected %c\n\n", + expr, + result, + expected); } -void _Noreturn check_int_eq_failed(const char *file, int line, - const char *func, char *expr, int result, int expected) +void _Noreturn check_int_eq_failed( + const char *file, + int line, + const char *func, + char *expr, + int result, + int expected) { - fail(file, line, func, - "\tIncorrect result: %s\n" - "\tReturn value was %i\n" - "\tExpected %i\n\n", - expr, result, expected); + fail( + file, + line, + func, + "\tIncorrect result: %s\n" + "\tReturn value was %i\n" + "\tExpected %i\n\n", + expr, + result, + expected); } -void _Noreturn check_int_neq_failed(const char *file, int line, - const char *func, char *expr, int result, int expected) +void _Noreturn check_int_neq_failed( + const char *file, + int line, + const char *func, + char *expr, + int result, + int expected) { - fail(file, line, func, - "\tIncorrect result: %s\n" - "\tReturn value was %i\n" - "\tNot expected %i\n\n", - expr, result, expected); + fail( + file, + line, + func, + "\tIncorrect result: %s\n" + "\tReturn value was %i\n" + "\tNot expected %i\n\n", + expr, + result, + expected); } -void _Noreturn check_bool_eq_failed(const char *file, int line, - const char *func, char *expr, bool result, bool expected) +void _Noreturn check_bool_eq_failed( + const char *file, + int line, + const char *func, + char *expr, + bool result, + bool expected) { - fail(file, line, func, - "\tIncorrect result: %s\n" - "\tReturn value was %s\n" - "\tExpected %s\n\n", - expr, result ? "true" : "false", expected ? "true" : "false"); + fail( + file, + line, + func, + "\tIncorrect result: %s\n" + "\tReturn value was %s\n" + "\tExpected %s\n\n", + expr, + result ? "true" : "false", + expected ? "true" : "false"); } -void _Noreturn check_bool_neq_failed(const char *file, int line, - const char *func, char *expr, bool result, bool expected) +void _Noreturn check_bool_neq_failed( + const char *file, + int line, + const char *func, + char *expr, + bool result, + bool expected) { - fail(file, line, func, - "\tIncorrect result: %s\n" - "\tReturn value was %s\n" - "\tNot expected %s\n\n", - expr, result ? "true" : "false", expected ? "true" : "false"); + fail( + file, + line, + func, + "\tIncorrect result: %s\n" + "\tReturn value was %s\n" + "\tNot expected %s\n\n", + expr, + result ? "true" : "false", + expected ? "true" : "false"); } -void _Noreturn check_float_eq_failed(const char *file, int line, - const char *func, char *expr, float result, float expected, float delta) +void _Noreturn check_float_eq_failed( + const char *file, + int line, + const char *func, + char *expr, + float result, + float expected, + float delta) { - fail(file, line, func, - "\tIncorrect result: %s\n" - "\tReturn value was %f\n" - "\tDelta value %f\n" - "\tExpected %f\n\n", - expr, result, delta, expected); + fail( + file, + line, + func, + "\tIncorrect result: %s\n" + "\tReturn value was %f\n" + "\tDelta value %f\n" + "\tExpected %f\n\n", + expr, + result, + delta, + expected); } -void _Noreturn check_str_eq_failed(const char *file, int line, - const char *func, char *expr, const char *result, - const char *expected) +void _Noreturn check_str_eq_failed( + const char *file, + int line, + const char *func, + char *expr, + const char *result, + const char *expected) { - fail(file, line, func, - "\tIncorrect result: %s\n" - "\tReturn value was \"%s\"\n" - "\tExpected \"%s\"\n\n", - expr, result, expected); + fail( + file, + line, + func, + "\tIncorrect result: %s\n" + "\tReturn value was \"%s\"\n" + "\tExpected \"%s\"\n\n", + expr, + result, + expected); } -void _Noreturn check_data_eq_failed(const char *file, int line, - const char *func, char *expr, const void *result, const void *expected, - size_t result_size, size_t expected_size) +void _Noreturn check_data_eq_failed( + const char *file, + int line, + const char *func, + char *expr, + const void *result, + const void *expected, + size_t result_size, + size_t expected_size) { char result_data[result_size * 2 + 1]; char expected_data[expected_size * 2 + 1]; hex_encode_uc(result, result_size, result_data, sizeof(result_data)); - hex_encode_uc(expected, expected_size, expected_data, - sizeof(expected_data)); + hex_encode_uc( + expected, expected_size, expected_data, sizeof(expected_data)); - fail(file, line, func, - "\tIncorrect result: %s\n" - "\tReturn size was: %d\n" - "\tExected size: %d\n" - "\tReturn value was \"%s\"\n" - "\tExpected \"%s\"\n\n", - expr, result_size, expected_size, result_data, expected_data); + fail( + file, + line, + func, + "\tIncorrect result: %s\n" + "\tReturn size was: %d\n" + "\tExected size: %d\n" + "\tReturn value was \"%s\"\n" + "\tExpected \"%s\"\n\n", + expr, + result_size, + expected_size, + result_data, + expected_data); } -void _Noreturn check_non_null_failed(const char *file, int line, const char *func, - char *expr) +void _Noreturn check_non_null_failed( + const char *file, int line, const char *func, char *expr) { - fail(file, line, func, - "\tValue is not non-null: %s\n" - "\tExpected non-null value\n\n", - expr); + fail( + file, + line, + func, + "\tValue is not non-null: %s\n" + "\tExpected non-null value\n\n", + expr); } -void _Noreturn check_null_failed(const char *file, int line, const char *func, - char *expr) +void _Noreturn check_null_failed( + const char *file, int line, const char *func, char *expr) { - fail(file, line, func, - "\tValue is not null: %s\n" - "\tExpected null value\n\n", - expr); + fail( + file, + line, + func, + "\tValue is not null: %s\n" + "\tExpected null value\n\n", + expr); } -void _Noreturn check_failed(const char *file, int line, - const char *func, char *expr) +void _Noreturn check_failed( + const char *file, int line, const char *func, char *expr) { - fail(file, line, func, "\t%s\n", expr); + fail(file, line, func, "\t%s\n", expr); } \ No newline at end of file diff --git a/src/test/test/check.h b/src/test/test/check.h index ac88a92..8758e98 100644 --- a/src/test/test/check.h +++ b/src/test/test/check.h @@ -4,145 +4,198 @@ #include #include -#define check_char_eq(expr, expected) \ - { \ - char _result = expr; \ - \ - if (_result != expected) { \ - check_char_eq_failed(__FILE__, __LINE__, __func__, #expr, \ - _result, expected); \ - } \ - } \ +#define check_char_eq(expr, expected) \ + { \ + char _result = expr; \ + \ + if (_result != expected) { \ + check_char_eq_failed( \ + __FILE__, __LINE__, __func__, #expr, _result, expected); \ + } \ + } -#define check_char_neq(expr, expected) \ - { \ - char _result = expr; \ - \ - if (_result == expected) { \ - check_char_neq_failed(__FILE__, __LINE__, __func__, #expr, \ - _result, expected); \ - } \ - } \ +#define check_char_neq(expr, expected) \ + { \ + char _result = expr; \ + \ + if (_result == expected) { \ + check_char_neq_failed( \ + __FILE__, __LINE__, __func__, #expr, _result, expected); \ + } \ + } -#define check_int_eq(expr, expected) \ - { \ - int _result = expr; \ - \ - if (_result != expected) { \ - check_int_eq_failed(__FILE__, __LINE__, __func__, #expr, \ - _result, expected); \ - } \ - } \ +#define check_int_eq(expr, expected) \ + { \ + int _result = expr; \ + \ + if (_result != expected) { \ + check_int_eq_failed( \ + __FILE__, __LINE__, __func__, #expr, _result, expected); \ + } \ + } -#define check_int_neq(expr, expected) \ - { \ - int _result = expr; \ - \ - if (_result == expected) { \ - check_int_neq_failed(__FILE__, __LINE__, __func__, #expr, \ - _result, expected); \ - } \ - } \ +#define check_int_neq(expr, expected) \ + { \ + int _result = expr; \ + \ + if (_result == expected) { \ + check_int_neq_failed( \ + __FILE__, __LINE__, __func__, #expr, _result, expected); \ + } \ + } #define check_float_eq(expr, expected, delta) \ - { \ - float _result = expr; \ - \ - if (_result - expected > delta) { \ - check_float_eq_failed(__FILE__, __LINE__, __func__, #expr, \ - _result, expected, delta); \ - } \ - } \ + { \ + float _result = expr; \ + \ + if (_result - expected > delta) { \ + check_float_eq_failed( \ + __FILE__, \ + __LINE__, \ + __func__, \ + #expr, \ + _result, \ + expected, \ + delta); \ + } \ + } -#define check_bool_true(expr) \ - { \ - bool _result = expr; \ - \ - if (!_result) { \ - check_bool_eq_failed(__FILE__, __LINE__, __func__, #expr, \ - _result, true); \ - } \ - } \ +#define check_bool_true(expr) \ + { \ + bool _result = expr; \ + \ + if (!_result) { \ + check_bool_eq_failed( \ + __FILE__, __LINE__, __func__, #expr, _result, true); \ + } \ + } -#define check_bool_false(expr) \ - { \ - bool _result = expr; \ - \ - if (_result) { \ - check_bool_eq_failed(__FILE__, __LINE__, __func__, #expr, \ - _result, false); \ - } \ - } \ +#define check_bool_false(expr) \ + { \ + bool _result = expr; \ + \ + if (_result) { \ + check_bool_eq_failed( \ + __FILE__, __LINE__, __func__, #expr, _result, false); \ + } \ + } -#define check_str_eq(expr, expected) \ - { \ - const char *_result = expr; \ - \ - if (strcmp(_result, expected) != 0) { \ - check_str_eq_failed(__FILE__, __LINE__, __func__, #expr, \ - _result, expected); \ - } \ - } \ +#define check_str_eq(expr, expected) \ + { \ + const char *_result = expr; \ + \ + if (strcmp(_result, expected) != 0) { \ + check_str_eq_failed( \ + __FILE__, __LINE__, __func__, #expr, _result, expected); \ + } \ + } #define check_data_eq(expr, result_size, expected, expected_size) \ - { \ - const void *_result = expr; \ - \ - if (result_size != expected_size || memcmp(expr, expected, \ - expected_size)) { \ - check_data_eq_failed(__FILE__, __LINE__, __func__, #expr, \ - _result, expected, result_size, expected_size); \ - } \ - } \ + { \ + const void *_result = expr; \ + \ + if (result_size != expected_size || \ + memcmp(expr, expected, expected_size)) { \ + check_data_eq_failed( \ + __FILE__, \ + __LINE__, \ + __func__, \ + #expr, \ + _result, \ + expected, \ + result_size, \ + expected_size); \ + } \ + } -#define check_non_null(expr) \ - { \ - if (!expr) { \ +#define check_non_null(expr) \ + { \ + if (!expr) { \ check_non_null_failed(__FILE__, __LINE__, __func__, #expr); \ - } \ - } \ + } \ + } -#define check_null(expr) \ - { \ - if (expr) { \ +#define check_null(expr) \ + { \ + if (expr) { \ check_null_failed(__FILE__, __LINE__, __func__, #expr); \ - } \ - } \ + } \ + } -#define check_fail() \ - { \ +#define check_fail() \ + { \ check_failed(__FILE__, __LINE__, __func__, ""); \ - } \ + } -#define check_fail_msg(expr) \ - { \ +#define check_fail_msg(expr) \ + { \ check_failed(__FILE__, __LINE__, __func__, expr); \ - } \ + } -void _Noreturn check_char_eq_failed(const char *file, int line, - const char *func, char *expr, char result, char expected); -void _Noreturn check_char_neq_failed(const char *file, int line, - const char *func, char *expr, char result, char expected); -void _Noreturn check_int_eq_failed(const char *file, int line, - const char *func, char *expr, int result, int expected); -void _Noreturn check_int_neq_failed(const char *file, int line, - const char *func, char *expr, int result, int expected); -void _Noreturn check_bool_eq_failed(const char *file, int line, - const char *func, char *expr, bool result, bool expected); -void _Noreturn check_float_eq_failed(const char *file, int line, - const char *func, char *expr, float result, float expected, - float delta); -void _Noreturn check_str_eq_failed(const char *file, int line, - const char *func, char *expr, const char *result, - const char *expected); -void _Noreturn check_data_eq_failed(const char *file, int line, - const char *func, char *expr, const void *result, const void *expected, - size_t expr_size, size_t expected_size); -void _Noreturn check_non_null_failed(const char *file, int line, const char *func, - char *expr); -void _Noreturn check_null_failed(const char *file, int line, const char *func, - char *expr); -void _Noreturn check_failed(const char *file, int line, - const char *func, char *expr); +void _Noreturn check_char_eq_failed( + const char *file, + int line, + const char *func, + char *expr, + char result, + char expected); +void _Noreturn check_char_neq_failed( + const char *file, + int line, + const char *func, + char *expr, + char result, + char expected); +void _Noreturn check_int_eq_failed( + const char *file, + int line, + const char *func, + char *expr, + int result, + int expected); +void _Noreturn check_int_neq_failed( + const char *file, + int line, + const char *func, + char *expr, + int result, + int expected); +void _Noreturn check_bool_eq_failed( + const char *file, + int line, + const char *func, + char *expr, + bool result, + bool expected); +void _Noreturn check_float_eq_failed( + const char *file, + int line, + const char *func, + char *expr, + float result, + float expected, + float delta); +void _Noreturn check_str_eq_failed( + const char *file, + int line, + const char *func, + char *expr, + const char *result, + const char *expected); +void _Noreturn check_data_eq_failed( + const char *file, + int line, + const char *func, + char *expr, + const void *result, + const void *expected, + size_t expr_size, + size_t expected_size); +void _Noreturn check_non_null_failed( + const char *file, int line, const char *func, char *expr); +void _Noreturn check_null_failed( + const char *file, int line, const char *func, char *expr); +void _Noreturn check_failed( + const char *file, int line, const char *func, char *expr); #endif \ No newline at end of file diff --git a/src/test/test/test.h b/src/test/test/test.h index d8ce024..91fb01b 100644 --- a/src/test/test/test.h +++ b/src/test/test/test.h @@ -5,21 +5,21 @@ #include "util/log.h" -#define TEST_MODULE_BEGIN(name) \ - int main(int argc, char** argv) \ - { \ +#define TEST_MODULE_BEGIN(name) \ + int main(int argc, char **argv) \ + { \ log_to_writer(log_writer_stderr, NULL); \ - fprintf(stderr, "Executing test module '%s'...\n", #name); \ + fprintf(stderr, "Executing test module '%s'...\n", #name); -#define TEST_MODULE_TEST(func) \ - { \ +#define TEST_MODULE_TEST(func) \ + { \ fprintf(stderr, "\tRunning test '%s'...\n", #func); \ - func(); \ - } \ + func(); \ + } -#define TEST_MODULE_END() \ - fprintf(stderr, "Finished execution of test module\n"); \ - return 0; \ - } \ +#define TEST_MODULE_END() \ + fprintf(stderr, "Finished execution of test module\n"); \ + return 0; \ + } #endif \ No newline at end of file diff --git a/src/test/util/util-net-test.c b/src/test/util/util-net-test.c index 27120fa..c251b07 100644 --- a/src/test/util/util-net-test.c +++ b/src/test/util/util-net-test.c @@ -4,7 +4,7 @@ #include "util/net.h" /* Note: Don't care about cleaning up of returned strings to avoid code - * clutter + * clutter */ static void test_parse_invalid() @@ -183,7 +183,8 @@ static void test_parse_url_https_hostname() check_int_eq(addr.url.hostname.port, NET_INVALID_PORT); check_str_eq(addr.url.path, "somewhere"); - check_bool_true(net_str_parse("https://www.google.com:22/somewhere", &addr)); + check_bool_true( + net_str_parse("https://www.google.com:22/somewhere", &addr)); check_int_eq(addr.type, NET_ADDR_TYPE_URL); check_bool_true(addr.url.is_https); check_int_eq(addr.url.type, NET_ADDR_TYPE_HOSTNAME); @@ -346,7 +347,8 @@ static void test_net_addr_to_str_url_http_hostname() addr.url.hostname.port = 1234; strcpy(addr.url.path, "somewhere"); - check_str_eq(net_addr_to_str(&addr), "http://www.google.com:1234/somewhere"); + check_str_eq( + net_addr_to_str(&addr), "http://www.google.com:1234/somewhere"); } static void test_net_addr_to_str_url_https_hostname() @@ -387,7 +389,8 @@ static void test_net_addr_to_str_url_https_hostname() addr.url.hostname.port = 1234; strcpy(addr.url.path, "somewhere"); - check_str_eq(net_addr_to_str(&addr), "https://www.google.com:1234/somewhere"); + check_str_eq( + net_addr_to_str(&addr), "https://www.google.com:1234/somewhere"); } static void test_resolve_hostname_str()