Merge pull request #12281 from eadmaster/multi_patch

added multi-softpatching support + OSD messages for patches (#9947)
This commit is contained in:
Autechre 2021-04-30 16:00:43 +02:00 committed by GitHub
commit 84ab14cb83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 143 additions and 8 deletions

View File

@ -866,6 +866,10 @@ static const bool audio_enable_menu_bgm = false;
* applied */
#define DEFAULT_NOTIFICATION_SHOW_CHEATS_APPLIED true
/* Display a notification when applying an
* IPS/BPS/UPS patch file */
#define DEFAULT_NOTIFICATION_SHOW_PATCH_APPLIED true
/* Display a notification when loading an
* input remap file */
#define DEFAULT_NOTIFICATION_SHOW_REMAP_LOAD true

View File

@ -1543,6 +1543,7 @@ static struct config_bool_setting *populate_settings_bool(
SETTING_BOOL("menu_show_load_content_animation", &settings->bools.menu_show_load_content_animation, true, DEFAULT_MENU_SHOW_LOAD_CONTENT_ANIMATION, false);
SETTING_BOOL("notification_show_autoconfig", &settings->bools.notification_show_autoconfig, true, DEFAULT_NOTIFICATION_SHOW_AUTOCONFIG, false);
SETTING_BOOL("notification_show_cheats_applied", &settings->bools.notification_show_cheats_applied, true, DEFAULT_NOTIFICATION_SHOW_CHEATS_APPLIED, false);
SETTING_BOOL("notification_show_patch_applied", &settings->bools.notification_show_patch_applied, true, DEFAULT_NOTIFICATION_SHOW_PATCH_APPLIED, false);
SETTING_BOOL("notification_show_remap_load", &settings->bools.notification_show_remap_load, true, DEFAULT_NOTIFICATION_SHOW_REMAP_LOAD, false);
SETTING_BOOL("notification_show_config_override_load", &settings->bools.notification_show_config_override_load, true, DEFAULT_NOTIFICATION_SHOW_CONFIG_OVERRIDE_LOAD, false);
SETTING_BOOL("notification_show_set_initial_disk", &settings->bools.notification_show_set_initial_disk, true, DEFAULT_NOTIFICATION_SHOW_SET_INITIAL_DISK, false);

View File

@ -559,6 +559,7 @@ typedef struct settings
bool menu_show_load_content_animation;
bool notification_show_autoconfig;
bool notification_show_cheats_applied;
bool notification_show_patch_applied;
bool notification_show_remap_load;
bool notification_show_config_override_load;
bool notification_show_set_initial_disk;

View File

@ -4626,6 +4626,10 @@ MSG_HASH(
MENU_ENUM_LABEL_NOTIFICATION_SHOW_CHEATS_APPLIED,
"notification_show_cheats_applied"
)
MSG_HASH(
MENU_ENUM_LABEL_NOTIFICATION_SHOW_PATCH_APPLIED,
"notification_show_patch_applied"
)
MSG_HASH(
MENU_ENUM_LABEL_NOTIFICATION_SHOW_REMAP_LOAD,
"notification_show_remap_load"

View File

@ -3718,6 +3718,14 @@ MSG_HASH(
MENU_ENUM_SUBLABEL_NOTIFICATION_SHOW_CHEATS_APPLIED,
"Display an on-screen message when cheat codes are applied."
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_NOTIFICATION_SHOW_PATCH_APPLIED,
"Patch Notifications"
)
MSG_HASH(
MENU_ENUM_SUBLABEL_NOTIFICATION_SHOW_PATCH_APPLIED,
"Display an on-screen message when soft-patching ROMs."
)
MSG_HASH(
MENU_ENUM_SUBLABEL_NOTIFICATION_SHOW_AUTOCONFIG,
"Display an on-screen message when connecting/disconnecting input devices."
@ -10690,6 +10698,10 @@ MSG_HASH(
MSG_APPLYING_CHEAT,
"Applying cheat changes."
)
MSG_HASH(
MSG_APPLYING_PATCH,
"Applying patch: %s"
)
MSG_HASH(
MSG_APPLYING_SHADER,
"Applying shader"

View File

@ -413,6 +413,9 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_notification_show_autoconfig, MENU_
#ifdef HAVE_CHEATS
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_notification_show_cheats_applied, MENU_ENUM_SUBLABEL_NOTIFICATION_SHOW_CHEATS_APPLIED)
#endif
#ifdef HAVE_PATCH
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_notification_show_patch_applied, MENU_ENUM_SUBLABEL_NOTIFICATION_SHOW_PATCH_APPLIED)
#endif
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_notification_show_remap_load, MENU_ENUM_SUBLABEL_NOTIFICATION_SHOW_REMAP_LOAD)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_notification_show_config_override_load, MENU_ENUM_SUBLABEL_NOTIFICATION_SHOW_CONFIG_OVERRIDE_LOAD)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_notification_show_set_initial_disk, MENU_ENUM_SUBLABEL_NOTIFICATION_SHOW_SET_INITIAL_DISK)
@ -3251,6 +3254,11 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
case MENU_ENUM_LABEL_NOTIFICATION_SHOW_CHEATS_APPLIED:
#ifdef HAVE_CHEATS
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_notification_show_cheats_applied);
#endif
break;
case MENU_ENUM_LABEL_NOTIFICATION_SHOW_PATCH_APPLIED:
#ifdef HAVE_PATCH
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_notification_show_patch_applied);
#endif
break;
case MENU_ENUM_LABEL_NOTIFICATION_SHOW_REMAP_LOAD:

View File

@ -8122,7 +8122,12 @@ unsigned menu_displaylist_build_list(
{MENU_ENUM_LABEL_MEMORY_UPDATE_INTERVAL, PARSE_ONLY_UINT, false },
{MENU_ENUM_LABEL_MENU_SHOW_LOAD_CONTENT_ANIMATION, PARSE_ONLY_BOOL, false },
{MENU_ENUM_LABEL_NOTIFICATION_SHOW_AUTOCONFIG, PARSE_ONLY_BOOL, false },
#ifdef HAVE_CHEATS
{MENU_ENUM_LABEL_NOTIFICATION_SHOW_CHEATS_APPLIED, PARSE_ONLY_BOOL, false },
#endif
#ifdef HAVE_PATCH
{MENU_ENUM_LABEL_NOTIFICATION_SHOW_PATCH_APPLIED, PARSE_ONLY_BOOL, true },
#endif
{MENU_ENUM_LABEL_NOTIFICATION_SHOW_REMAP_LOAD, PARSE_ONLY_BOOL, false },
{MENU_ENUM_LABEL_NOTIFICATION_SHOW_CONFIG_OVERRIDE_LOAD, PARSE_ONLY_BOOL, false },
{MENU_ENUM_LABEL_NOTIFICATION_SHOW_SET_INITIAL_DISK, PARSE_ONLY_BOOL, false },

View File

@ -13584,6 +13584,7 @@ static bool setting_append_list(
general_read_handler,
SD_FLAG_NONE);
#ifdef HAVE_CHEATS
CONFIG_BOOL(
list, list_info,
&settings->bools.notification_show_cheats_applied,
@ -13598,7 +13599,23 @@ static bool setting_append_list(
general_write_handler,
general_read_handler,
SD_FLAG_NONE);
#endif
#ifdef HAVE_PATCH
CONFIG_BOOL(
list, list_info,
&settings->bools.notification_show_patch_applied,
MENU_ENUM_LABEL_NOTIFICATION_SHOW_PATCH_APPLIED,
MENU_ENUM_LABEL_VALUE_NOTIFICATION_SHOW_PATCH_APPLIED,
DEFAULT_NOTIFICATION_SHOW_PATCH_APPLIED,
MENU_ENUM_LABEL_VALUE_OFF,
MENU_ENUM_LABEL_VALUE_ON,
&group_info,
&subgroup_info,
parent_group,
general_write_handler,
general_read_handler,
SD_FLAG_NONE);
#endif
CONFIG_BOOL(
list, list_info,
&settings->bools.notification_show_remap_load,

View File

@ -333,6 +333,7 @@ enum msg_hash_enums
MSG_REVERTING_SAVESTATE_DIRECTORY_TO,
MSG_DOWNLOAD_FAILED,
MSG_APPLYING_CHEAT,
MSG_APPLYING_PATCH,
MSG_INPUT_CHEAT,
MSG_INPUT_PRESET_FILENAME,
MSG_INPUT_CHEAT_FILENAME,
@ -2761,6 +2762,7 @@ enum msg_hash_enums
MENU_LABEL(NOTIFICATION_SHOW_AUTOCONFIG),
MENU_LABEL(NOTIFICATION_SHOW_CHEATS_APPLIED),
MENU_LABEL(NOTIFICATION_SHOW_PATCH_APPLIED),
MENU_LABEL(NOTIFICATION_SHOW_REMAP_LOAD),
MENU_LABEL(NOTIFICATION_SHOW_CONFIG_OVERRIDE_LOAD),
MENU_LABEL(NOTIFICATION_SHOW_SET_INITIAL_DISK),

View File

@ -31,8 +31,10 @@
#include <encodings/crc32.h>
#include "../retroarch.h"
#include "../msg_hash.h"
#include "../verbosity.h"
#include "../configuration.h"
enum bps_mode
{
@ -613,6 +615,9 @@ static bool apply_patch_content(uint8_t **buf,
ssize_t *size, const char *patch_desc, const char *patch_path,
patch_func_t func, void *patch_data, int64_t patch_size)
{
settings_t *settings = config_get_ptr();
bool show_notification = settings ?
settings->bools.notification_show_patch_applied : false;
enum patch_error err = PATCH_UNKNOWN;
ssize_t ret_size = *size;
uint8_t *ret_buf = *buf;
@ -628,6 +633,21 @@ static bool apply_patch_content(uint8_t **buf,
free(ret_buf);
*buf = patched_content;
*size = target_size;
/* Show an OSD message */
if (show_notification)
{
const char *patch_filename = path_basename(patch_path);
char msg[256];
msg[0] = '\0';
snprintf(msg, sizeof(msg), msg_hash_to_str(MSG_APPLYING_PATCH),
patch_filename ? patch_filename :
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_UNKNOWN));
runloop_msg_queue_push(msg, 1, 180, false, NULL,
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
}
}
else
RARCH_ERR("%s %s: %s #%u\n",
@ -740,6 +760,7 @@ bool patch_content(
bool allow_ups = !is_bps_pref && !is_ips_pref;
bool allow_ips = !is_ups_pref && !is_bps_pref;
bool allow_bps = !is_ups_pref && !is_ips_pref;
bool patch_found = false;
if ( (unsigned)is_ips_pref
+ (unsigned)is_bps_pref
@ -750,14 +771,74 @@ bool patch_content(
return false;
}
if ( !try_ips_patch(allow_ips, name_ips, buf, size)
&& !try_bps_patch(allow_bps, name_bps, buf, size)
&& !try_ups_patch(allow_ups, name_ups, buf, size))
/* Attempt to apply first (non-indexed) patch */
if ( try_ips_patch(allow_ips, name_ips, buf, size)
|| try_bps_patch(allow_bps, name_bps, buf, size)
|| try_ups_patch(allow_ups, name_ups, buf, size))
{
RARCH_LOG("%s\n",
msg_hash_to_str(MSG_DID_NOT_FIND_A_VALID_CONTENT_PATCH));
return false;
/* A patch has been found. Now attempt to apply
* any additional 'indexed' patch files */
size_t name_ips_len = strlen(name_ips);
size_t name_bps_len = strlen(name_bps);
size_t name_ups_len = strlen(name_ups);
char *name_ips_indexed = (char*)malloc((name_ips_len + 2) * sizeof(char));
char *name_bps_indexed = (char*)malloc((name_bps_len + 2) * sizeof(char));
char *name_ups_indexed = (char*)malloc((name_ups_len + 2) * sizeof(char));
/* First patch already applied -> index
* for subsequent patches starts at 1 */
size_t patch_index = 1;
name_ips_indexed[0] = '\0';
name_bps_indexed[0] = '\0';
name_ups_indexed[0] = '\0';
strlcpy(name_ips_indexed, name_ips, (name_ips_len + 1) * sizeof(char));
strlcpy(name_bps_indexed, name_bps, (name_bps_len + 1) * sizeof(char));
strlcpy(name_ups_indexed, name_ups, (name_ups_len + 1) * sizeof(char));
/* Ensure that we NUL terminate *after* the
* index character */
name_ips_indexed[name_ips_len + 1] = '\0';
name_bps_indexed[name_bps_len + 1] = '\0';
name_ups_indexed[name_ups_len + 1] = '\0';
/* try to patch "*.ipsX" */
while (patch_index < 10)
{
/* Add index character to end of patch
* file path string
* > Note: This technique only works for
* index values up to 9 (i.e. single
* digit numbers)
* > If we want to support more than 10
* patches in total, will have to replace
* this with an snprintf() implementation
* (which will have significantly higher
* performance overheads) */
char index_char = '0' + patch_index;
name_ips_indexed[name_ips_len] = index_char;
name_bps_indexed[name_bps_len] = index_char;
name_ups_indexed[name_ups_len] = index_char;
if ( !try_ips_patch(allow_ips, name_ips_indexed, buf, size)
&& !try_bps_patch(allow_bps, name_bps_indexed, buf, size)
&& !try_ups_patch(allow_ups, name_ups_indexed, buf, size))
break;
patch_index++;
}
free(name_ips_indexed);
free(name_bps_indexed);
free(name_ups_indexed);
patch_found = true;
}
return true;
if(!patch_found)
RARCH_LOG("%s\n",
msg_hash_to_str(MSG_DID_NOT_FIND_A_VALID_CONTENT_PATCH));
return patch_found;
}