Skip to content

Commit 84ab14c

Browse files
authored
Merge pull request #12281 from eadmaster/multi_patch
added multi-softpatching support + OSD messages for patches (#9947)
2 parents 9991736 + 0191302 commit 84ab14c

File tree

10 files changed

+142
-7
lines changed

10 files changed

+142
-7
lines changed

config.def.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,10 @@ static const bool audio_enable_menu_bgm = false;
866866
* applied */
867867
#define DEFAULT_NOTIFICATION_SHOW_CHEATS_APPLIED true
868868

869+
/* Display a notification when applying an
870+
* IPS/BPS/UPS patch file */
871+
#define DEFAULT_NOTIFICATION_SHOW_PATCH_APPLIED true
872+
869873
/* Display a notification when loading an
870874
* input remap file */
871875
#define DEFAULT_NOTIFICATION_SHOW_REMAP_LOAD true

configuration.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,6 +1543,7 @@ static struct config_bool_setting *populate_settings_bool(
15431543
SETTING_BOOL("menu_show_load_content_animation", &settings->bools.menu_show_load_content_animation, true, DEFAULT_MENU_SHOW_LOAD_CONTENT_ANIMATION, false);
15441544
SETTING_BOOL("notification_show_autoconfig", &settings->bools.notification_show_autoconfig, true, DEFAULT_NOTIFICATION_SHOW_AUTOCONFIG, false);
15451545
SETTING_BOOL("notification_show_cheats_applied", &settings->bools.notification_show_cheats_applied, true, DEFAULT_NOTIFICATION_SHOW_CHEATS_APPLIED, false);
1546+
SETTING_BOOL("notification_show_patch_applied", &settings->bools.notification_show_patch_applied, true, DEFAULT_NOTIFICATION_SHOW_PATCH_APPLIED, false);
15461547
SETTING_BOOL("notification_show_remap_load", &settings->bools.notification_show_remap_load, true, DEFAULT_NOTIFICATION_SHOW_REMAP_LOAD, false);
15471548
SETTING_BOOL("notification_show_config_override_load", &settings->bools.notification_show_config_override_load, true, DEFAULT_NOTIFICATION_SHOW_CONFIG_OVERRIDE_LOAD, false);
15481549
SETTING_BOOL("notification_show_set_initial_disk", &settings->bools.notification_show_set_initial_disk, true, DEFAULT_NOTIFICATION_SHOW_SET_INITIAL_DISK, false);

configuration.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ typedef struct settings
559559
bool menu_show_load_content_animation;
560560
bool notification_show_autoconfig;
561561
bool notification_show_cheats_applied;
562+
bool notification_show_patch_applied;
562563
bool notification_show_remap_load;
563564
bool notification_show_config_override_load;
564565
bool notification_show_set_initial_disk;

intl/msg_hash_lbl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4626,6 +4626,10 @@ MSG_HASH(
46264626
MENU_ENUM_LABEL_NOTIFICATION_SHOW_CHEATS_APPLIED,
46274627
"notification_show_cheats_applied"
46284628
)
4629+
MSG_HASH(
4630+
MENU_ENUM_LABEL_NOTIFICATION_SHOW_PATCH_APPLIED,
4631+
"notification_show_patch_applied"
4632+
)
46294633
MSG_HASH(
46304634
MENU_ENUM_LABEL_NOTIFICATION_SHOW_REMAP_LOAD,
46314635
"notification_show_remap_load"

intl/msg_hash_us.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3718,6 +3718,14 @@ MSG_HASH(
37183718
MENU_ENUM_SUBLABEL_NOTIFICATION_SHOW_CHEATS_APPLIED,
37193719
"Display an on-screen message when cheat codes are applied."
37203720
)
3721+
MSG_HASH(
3722+
MENU_ENUM_LABEL_VALUE_NOTIFICATION_SHOW_PATCH_APPLIED,
3723+
"Patch Notifications"
3724+
)
3725+
MSG_HASH(
3726+
MENU_ENUM_SUBLABEL_NOTIFICATION_SHOW_PATCH_APPLIED,
3727+
"Display an on-screen message when soft-patching ROMs."
3728+
)
37213729
MSG_HASH(
37223730
MENU_ENUM_SUBLABEL_NOTIFICATION_SHOW_AUTOCONFIG,
37233731
"Display an on-screen message when connecting/disconnecting input devices."
@@ -10690,6 +10698,10 @@ MSG_HASH(
1069010698
MSG_APPLYING_CHEAT,
1069110699
"Applying cheat changes."
1069210700
)
10701+
MSG_HASH(
10702+
MSG_APPLYING_PATCH,
10703+
"Applying patch: %s"
10704+
)
1069310705
MSG_HASH(
1069410706
MSG_APPLYING_SHADER,
1069510707
"Applying shader"

menu/cbs/menu_cbs_sublabel.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,9 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_notification_show_autoconfig, MENU_
413413
#ifdef HAVE_CHEATS
414414
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_notification_show_cheats_applied, MENU_ENUM_SUBLABEL_NOTIFICATION_SHOW_CHEATS_APPLIED)
415415
#endif
416+
#ifdef HAVE_PATCH
417+
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_notification_show_patch_applied, MENU_ENUM_SUBLABEL_NOTIFICATION_SHOW_PATCH_APPLIED)
418+
#endif
416419
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_notification_show_remap_load, MENU_ENUM_SUBLABEL_NOTIFICATION_SHOW_REMAP_LOAD)
417420
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_notification_show_config_override_load, MENU_ENUM_SUBLABEL_NOTIFICATION_SHOW_CONFIG_OVERRIDE_LOAD)
418421
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,
32513254
case MENU_ENUM_LABEL_NOTIFICATION_SHOW_CHEATS_APPLIED:
32523255
#ifdef HAVE_CHEATS
32533256
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_notification_show_cheats_applied);
3257+
#endif
3258+
break;
3259+
case MENU_ENUM_LABEL_NOTIFICATION_SHOW_PATCH_APPLIED:
3260+
#ifdef HAVE_PATCH
3261+
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_notification_show_patch_applied);
32543262
#endif
32553263
break;
32563264
case MENU_ENUM_LABEL_NOTIFICATION_SHOW_REMAP_LOAD:

menu/menu_displaylist.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8122,7 +8122,12 @@ unsigned menu_displaylist_build_list(
81228122
{MENU_ENUM_LABEL_MEMORY_UPDATE_INTERVAL, PARSE_ONLY_UINT, false },
81238123
{MENU_ENUM_LABEL_MENU_SHOW_LOAD_CONTENT_ANIMATION, PARSE_ONLY_BOOL, false },
81248124
{MENU_ENUM_LABEL_NOTIFICATION_SHOW_AUTOCONFIG, PARSE_ONLY_BOOL, false },
8125+
#ifdef HAVE_CHEATS
81258126
{MENU_ENUM_LABEL_NOTIFICATION_SHOW_CHEATS_APPLIED, PARSE_ONLY_BOOL, false },
8127+
#endif
8128+
#ifdef HAVE_PATCH
8129+
{MENU_ENUM_LABEL_NOTIFICATION_SHOW_PATCH_APPLIED, PARSE_ONLY_BOOL, true },
8130+
#endif
81268131
{MENU_ENUM_LABEL_NOTIFICATION_SHOW_REMAP_LOAD, PARSE_ONLY_BOOL, false },
81278132
{MENU_ENUM_LABEL_NOTIFICATION_SHOW_CONFIG_OVERRIDE_LOAD, PARSE_ONLY_BOOL, false },
81288133
{MENU_ENUM_LABEL_NOTIFICATION_SHOW_SET_INITIAL_DISK, PARSE_ONLY_BOOL, false },

menu/menu_setting.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13584,6 +13584,7 @@ static bool setting_append_list(
1358413584
general_read_handler,
1358513585
SD_FLAG_NONE);
1358613586

13587+
#ifdef HAVE_CHEATS
1358713588
CONFIG_BOOL(
1358813589
list, list_info,
1358913590
&settings->bools.notification_show_cheats_applied,
@@ -13598,7 +13599,23 @@ static bool setting_append_list(
1359813599
general_write_handler,
1359913600
general_read_handler,
1360013601
SD_FLAG_NONE);
13601-
13602+
#endif
13603+
#ifdef HAVE_PATCH
13604+
CONFIG_BOOL(
13605+
list, list_info,
13606+
&settings->bools.notification_show_patch_applied,
13607+
MENU_ENUM_LABEL_NOTIFICATION_SHOW_PATCH_APPLIED,
13608+
MENU_ENUM_LABEL_VALUE_NOTIFICATION_SHOW_PATCH_APPLIED,
13609+
DEFAULT_NOTIFICATION_SHOW_PATCH_APPLIED,
13610+
MENU_ENUM_LABEL_VALUE_OFF,
13611+
MENU_ENUM_LABEL_VALUE_ON,
13612+
&group_info,
13613+
&subgroup_info,
13614+
parent_group,
13615+
general_write_handler,
13616+
general_read_handler,
13617+
SD_FLAG_NONE);
13618+
#endif
1360213619
CONFIG_BOOL(
1360313620
list, list_info,
1360413621
&settings->bools.notification_show_remap_load,

msg_hash.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ enum msg_hash_enums
333333
MSG_REVERTING_SAVESTATE_DIRECTORY_TO,
334334
MSG_DOWNLOAD_FAILED,
335335
MSG_APPLYING_CHEAT,
336+
MSG_APPLYING_PATCH,
336337
MSG_INPUT_CHEAT,
337338
MSG_INPUT_PRESET_FILENAME,
338339
MSG_INPUT_CHEAT_FILENAME,
@@ -2761,6 +2762,7 @@ enum msg_hash_enums
27612762

27622763
MENU_LABEL(NOTIFICATION_SHOW_AUTOCONFIG),
27632764
MENU_LABEL(NOTIFICATION_SHOW_CHEATS_APPLIED),
2765+
MENU_LABEL(NOTIFICATION_SHOW_PATCH_APPLIED),
27642766
MENU_LABEL(NOTIFICATION_SHOW_REMAP_LOAD),
27652767
MENU_LABEL(NOTIFICATION_SHOW_CONFIG_OVERRIDE_LOAD),
27662768
MENU_LABEL(NOTIFICATION_SHOW_SET_INITIAL_DISK),

tasks/task_patch.c

Lines changed: 87 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131

3232
#include <encodings/crc32.h>
3333

34+
#include "../retroarch.h"
3435
#include "../msg_hash.h"
3536
#include "../verbosity.h"
37+
#include "../configuration.h"
3638

3739
enum bps_mode
3840
{
@@ -613,6 +615,9 @@ static bool apply_patch_content(uint8_t **buf,
613615
ssize_t *size, const char *patch_desc, const char *patch_path,
614616
patch_func_t func, void *patch_data, int64_t patch_size)
615617
{
618+
settings_t *settings = config_get_ptr();
619+
bool show_notification = settings ?
620+
settings->bools.notification_show_patch_applied : false;
616621
enum patch_error err = PATCH_UNKNOWN;
617622
ssize_t ret_size = *size;
618623
uint8_t *ret_buf = *buf;
@@ -628,6 +633,21 @@ static bool apply_patch_content(uint8_t **buf,
628633
free(ret_buf);
629634
*buf = patched_content;
630635
*size = target_size;
636+
637+
/* Show an OSD message */
638+
if (show_notification)
639+
{
640+
const char *patch_filename = path_basename(patch_path);
641+
char msg[256];
642+
643+
msg[0] = '\0';
644+
645+
snprintf(msg, sizeof(msg), msg_hash_to_str(MSG_APPLYING_PATCH),
646+
patch_filename ? patch_filename :
647+
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_UNKNOWN));
648+
runloop_msg_queue_push(msg, 1, 180, false, NULL,
649+
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
650+
}
631651
}
632652
else
633653
RARCH_ERR("%s %s: %s #%u\n",
@@ -740,6 +760,7 @@ bool patch_content(
740760
bool allow_ups = !is_bps_pref && !is_ips_pref;
741761
bool allow_ips = !is_ups_pref && !is_bps_pref;
742762
bool allow_bps = !is_ups_pref && !is_ips_pref;
763+
bool patch_found = false;
743764

744765
if ( (unsigned)is_ips_pref
745766
+ (unsigned)is_bps_pref
@@ -750,14 +771,74 @@ bool patch_content(
750771
return false;
751772
}
752773

753-
if ( !try_ips_patch(allow_ips, name_ips, buf, size)
754-
&& !try_bps_patch(allow_bps, name_bps, buf, size)
755-
&& !try_ups_patch(allow_ups, name_ups, buf, size))
774+
/* Attempt to apply first (non-indexed) patch */
775+
if ( try_ips_patch(allow_ips, name_ips, buf, size)
776+
|| try_bps_patch(allow_bps, name_bps, buf, size)
777+
|| try_ups_patch(allow_ups, name_ups, buf, size))
756778
{
779+
/* A patch has been found. Now attempt to apply
780+
* any additional 'indexed' patch files */
781+
size_t name_ips_len = strlen(name_ips);
782+
size_t name_bps_len = strlen(name_bps);
783+
size_t name_ups_len = strlen(name_ups);
784+
char *name_ips_indexed = (char*)malloc((name_ips_len + 2) * sizeof(char));
785+
char *name_bps_indexed = (char*)malloc((name_bps_len + 2) * sizeof(char));
786+
char *name_ups_indexed = (char*)malloc((name_ups_len + 2) * sizeof(char));
787+
/* First patch already applied -> index
788+
* for subsequent patches starts at 1 */
789+
size_t patch_index = 1;
790+
791+
name_ips_indexed[0] = '\0';
792+
name_bps_indexed[0] = '\0';
793+
name_ups_indexed[0] = '\0';
794+
795+
strlcpy(name_ips_indexed, name_ips, (name_ips_len + 1) * sizeof(char));
796+
strlcpy(name_bps_indexed, name_bps, (name_bps_len + 1) * sizeof(char));
797+
strlcpy(name_ups_indexed, name_ups, (name_ups_len + 1) * sizeof(char));
798+
799+
/* Ensure that we NUL terminate *after* the
800+
* index character */
801+
name_ips_indexed[name_ips_len + 1] = '\0';
802+
name_bps_indexed[name_bps_len + 1] = '\0';
803+
name_ups_indexed[name_ups_len + 1] = '\0';
804+
805+
/* try to patch "*.ipsX" */
806+
while (patch_index < 10)
807+
{
808+
/* Add index character to end of patch
809+
* file path string
810+
* > Note: This technique only works for
811+
* index values up to 9 (i.e. single
812+
* digit numbers)
813+
* > If we want to support more than 10
814+
* patches in total, will have to replace
815+
* this with an snprintf() implementation
816+
* (which will have significantly higher
817+
* performance overheads) */
818+
char index_char = '0' + patch_index;
819+
820+
name_ips_indexed[name_ips_len] = index_char;
821+
name_bps_indexed[name_bps_len] = index_char;
822+
name_ups_indexed[name_ups_len] = index_char;
823+
824+
if ( !try_ips_patch(allow_ips, name_ips_indexed, buf, size)
825+
&& !try_bps_patch(allow_bps, name_bps_indexed, buf, size)
826+
&& !try_ups_patch(allow_ups, name_ups_indexed, buf, size))
827+
break;
828+
829+
patch_index++;
830+
}
831+
832+
free(name_ips_indexed);
833+
free(name_bps_indexed);
834+
free(name_ups_indexed);
835+
836+
patch_found = true;
837+
}
838+
839+
if(!patch_found)
757840
RARCH_LOG("%s\n",
758841
msg_hash_to_str(MSG_DID_NOT_FIND_A_VALID_CONTENT_PATCH));
759-
return false;
760-
}
761842

762-
return true;
843+
return patch_found;
763844
}

0 commit comments

Comments
 (0)