mirror of
https://github.com/djhackersdev/bemanitools.git
synced 2026-08-05 09:58:17 -05:00
Be more careful about USB memory errors
This commit is contained in:
parent
58d297458c
commit
75583897c1
3
dist/ddr/ddr-11-us.conf
vendored
3
dist/ddr/ddr-11-us.conf
vendored
|
|
@ -19,6 +19,9 @@ ddrhook1.standard_def=false
|
|||
# Use 15 kHz monitor mode
|
||||
ddrhook1.use_15khz=false
|
||||
|
||||
# Enable USB memory data emulation
|
||||
ddrhook1.usbmem_enabled=false
|
||||
|
||||
# Specify path for USB memory data
|
||||
ddrhook1.usbmem_path=usbmem
|
||||
|
||||
|
|
|
|||
3
dist/ddr/ddr-11.conf
vendored
3
dist/ddr/ddr-11.conf
vendored
|
|
@ -19,6 +19,9 @@ ddrhook1.standard_def=false
|
|||
# Use 15 kHz monitor mode
|
||||
ddrhook1.use_15khz=false
|
||||
|
||||
# Enable USB memory data emulation
|
||||
ddrhook1.usbmem_enabled=false
|
||||
|
||||
# Specify path for USB memory data
|
||||
ddrhook1.usbmem_path=usbmem
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ static HANDLE usbmem_fd;
|
|||
static char usbmem_response[USBMEM_DATA_BUF_SIZE];
|
||||
static bool usbmem_pending;
|
||||
static size_t usbmem_response_length;
|
||||
static bool usbmem_enabled;
|
||||
|
||||
static HRESULT usbmem_open(struct irp *irp);
|
||||
static HRESULT usbmem_close(struct irp *irp);
|
||||
|
|
@ -44,6 +45,7 @@ typedef enum {
|
|||
struct USBMEM_STATE {
|
||||
bool connected;
|
||||
bool opened;
|
||||
bool errored;
|
||||
USBMEM_FILE_TYPE file_type;
|
||||
|
||||
char path[MAX_PATH];
|
||||
|
|
@ -73,7 +75,7 @@ static void usbmem_reset_file_state(int port)
|
|||
usbmem_state[port].file_type = USBMEM_FILE_TYPE_NONE;
|
||||
}
|
||||
|
||||
void usbmem_init(const char *path)
|
||||
void usbmem_init(const char *path, const bool enabled)
|
||||
{
|
||||
log_assert(usbmem_fd == NULL);
|
||||
|
||||
|
|
@ -85,20 +87,24 @@ void usbmem_init(const char *path)
|
|||
log_fatal("Opening nul fd failed: %08lx", hr);
|
||||
}
|
||||
|
||||
usbmem_enabled = enabled;
|
||||
|
||||
GetFullPathNameA(path, sizeof(usb_data_path), usb_data_path, NULL);
|
||||
log_misc("USB memory data path: %s", usb_data_path);
|
||||
|
||||
if (!path_exists(usb_data_path)) {
|
||||
log_warning("USB memory data path does not exist, disabling");
|
||||
usbmem_enabled = false;
|
||||
}
|
||||
|
||||
target_device_id = -1;
|
||||
for (int i = 0; i < USBMEM_DEVICE_COUNT; i++) {
|
||||
char subpath[MAX_PATH];
|
||||
snprintf(subpath, sizeof(subpath), "%s\\p%d", usb_data_path, i + 1);
|
||||
|
||||
if (!path_exists(subpath)) {
|
||||
path_mkdir(subpath);
|
||||
}
|
||||
|
||||
usbmem_state[i].connected = false;
|
||||
usbmem_state[i].opened = false;
|
||||
usbmem_state[i].errored = false;
|
||||
memset(usbmem_state[i].path, 0, sizeof(usbmem_state[i].path));
|
||||
memset(usbmem_state[i].filename, 0, sizeof(usbmem_state[i].filename));
|
||||
usbmem_reset_file_state(i);
|
||||
|
|
@ -231,6 +237,13 @@ static HRESULT usbmem_write(struct irp *irp)
|
|||
str_cpy(usbmem_response, sizeof(usbmem_response), "done");
|
||||
} else if (target_device_id < 0 || target_device_id >= USBMEM_DEVICE_COUNT) {
|
||||
str_cpy(usbmem_response, sizeof(usbmem_response), "fail");
|
||||
} else if ((target_device_val == 'a' || target_device_val == 'b') && usbmem_state[target_device_id].errored) {
|
||||
// If the device went through the entire process once and the file didn't exist
|
||||
// then just force it to be disabled because otherwise it'll get stuck in a loop.
|
||||
str_cpy(usbmem_response, sizeof(usbmem_response), "not connected");
|
||||
} else if (!usbmem_enabled) {
|
||||
// Ignore all other USB device specific commands and pretend a device isn't plugged in.
|
||||
str_cpy(usbmem_response, sizeof(usbmem_response), "not connected");
|
||||
} else if (str_eq(request, "on_a") || str_eq(request, "on_b")) {
|
||||
usbmem_state[target_device_id].connected = true;
|
||||
usbmem_reset_file_state(target_device_id);
|
||||
|
|
@ -282,7 +295,7 @@ static HRESULT usbmem_write(struct irp *irp)
|
|||
|
||||
if (!path_exists(temp)) {
|
||||
log_warning("Couldn't find path %s\n", temp);
|
||||
str_cpy(usbmem_response, sizeof(usbmem_response), "not exist");
|
||||
str_cpy(usbmem_response, sizeof(usbmem_response), "done");
|
||||
} else {
|
||||
log_misc("Changing path to %s\n", temp);
|
||||
str_cpy(usbmem_state[target_device_id].path, sizeof(usbmem_state[target_device_id].path), temp);
|
||||
|
|
@ -316,6 +329,9 @@ static HRESULT usbmem_write(struct irp *irp)
|
|||
if (!path_exists(temp)) {
|
||||
log_warning("Couldn't find file %s\n", temp);
|
||||
str_cpy(usbmem_response, sizeof(usbmem_response), "not exist");
|
||||
usbmem_state[target_device_id].connected = false;
|
||||
usbmem_state[target_device_id].opened = false;
|
||||
usbmem_state[target_device_id].errored = true;
|
||||
} else {
|
||||
bool loaded = file_load(temp, (void**)&usbmem_state[target_device_id].buffer,
|
||||
&usbmem_state[target_device_id].buffer_len, false);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef DDRHOOK_UTIL_USBMEM_H
|
||||
#define DDRHOOK_UTIL_USBMEM_H
|
||||
|
||||
void usbmem_init(const char *path);
|
||||
void usbmem_init(const char *path, const bool enabled);
|
||||
void usbmem_fini(void);
|
||||
HRESULT usbmem_dispatch_irp(struct irp *irp);
|
||||
|
||||
|
|
|
|||
|
|
@ -10,10 +10,12 @@
|
|||
#define DDRHOOK1_CONFIG_DDRHOOK1_STANDARD_DEF_KEY "ddrhook1.standard_def"
|
||||
#define DDRHOOK1_CONFIG_DDRHOOK1_USE_15KHZ_KEY "ddrhook1.use_15khz"
|
||||
#define DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_PATH "ddrhook1.usbmem_path"
|
||||
#define DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_ENABLED "ddrhook1.usbmem_enabled"
|
||||
|
||||
#define DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USE_COM4_EMU_VALUE true
|
||||
#define DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_STANDARD_DEF_VALUE false
|
||||
#define DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USE_15KHZ_VALUE false
|
||||
#define DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_ENABLED false
|
||||
#define DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_PATH "usbmem"
|
||||
|
||||
void ddrhook1_config_ddrhook1_init(struct cconfig *config)
|
||||
|
|
@ -33,6 +35,11 @@ void ddrhook1_config_ddrhook1_init(struct cconfig *config)
|
|||
DDRHOOK1_CONFIG_DDRHOOK1_USE_15KHZ_KEY,
|
||||
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USE_15KHZ_VALUE,
|
||||
"Use 15 kHz monitor mode");
|
||||
cconfig_util_set_bool(
|
||||
config,
|
||||
DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_ENABLED,
|
||||
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_ENABLED,
|
||||
"Enable USB memory data emulation");
|
||||
cconfig_util_set_str(
|
||||
config,
|
||||
DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_PATH,
|
||||
|
|
@ -76,6 +83,17 @@ void ddrhook1_config_ddrhook1_get(
|
|||
DDRHOOK1_CONFIG_DDRHOOK1_USE_15KHZ_KEY,
|
||||
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USE_15KHZ_VALUE);
|
||||
}
|
||||
if (!cconfig_util_get_bool(
|
||||
config,
|
||||
DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_ENABLED,
|
||||
&config_ddrhook1->usbmem_enabled,
|
||||
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_ENABLED)) {
|
||||
log_warning(
|
||||
"Invalid value for key '%s' specified, fallback "
|
||||
"to default '%d'",
|
||||
DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_ENABLED,
|
||||
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_ENABLED);
|
||||
}
|
||||
if (!cconfig_util_get_str(
|
||||
config,
|
||||
DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_PATH,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ struct ddrhook1_config_ddrhook1 {
|
|||
bool use_com4_emu;
|
||||
bool standard_def;
|
||||
bool use_15khz;
|
||||
bool usbmem_enabled;
|
||||
char usbmem_path[MAX_PATH];
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ static DWORD STDCALL my_main()
|
|||
&security_rp_sign_key_black_ddrx,
|
||||
&security_rp_sign_key_white_eamuse);
|
||||
extio_init();
|
||||
usbmem_init(config_ddrhook1.usbmem_path);
|
||||
usbmem_init(config_ddrhook1.usbmem_path, config_ddrhook1.usbmem_enabled);
|
||||
spike_init();
|
||||
com4_init();
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
|
|||
bool com4;
|
||||
bool ok;
|
||||
int i;
|
||||
char usbmem_data_path[MAX_PATH] = "usbmem";
|
||||
char usbmem_data_path[MAX_PATH] = "";
|
||||
bool usbmem_enabled = false;
|
||||
|
||||
log_info("--- Begin ddrhook dll_entry_init ---");
|
||||
|
||||
|
|
@ -74,6 +75,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
|
|||
/* Specify a USB memory path */
|
||||
if (i + 1 < argc) {
|
||||
strcpy(usbmem_data_path, argv[i+1]);
|
||||
usbmem_enabled = true;
|
||||
i++; // Move forward one to skip the path parameter
|
||||
}
|
||||
|
||||
|
|
@ -102,7 +104,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
|
|||
ddrhook2_master_insert_hooks(NULL);
|
||||
p3io_ddr_init();
|
||||
extio_init();
|
||||
usbmem_init(usbmem_data_path);
|
||||
usbmem_init(usbmem_data_path, usbmem_enabled);
|
||||
spike_init();
|
||||
com4_init();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user