Skip to content

Commit

Permalink
Merge pull request ps2homebrew#35 from NimrodPSI/hide_games
Browse files Browse the repository at this point in the history
Hide games
  • Loading branch information
AKuHAK authored Jun 13, 2021
2 parents 1a7b29b + 58a2e99 commit d944b2c
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 71 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ Now `icon.sys` can be in any of 2 formats: Memory Card format or HDD format.
`boot.kirx` size limit - 1,044,480 bytes


### Hiding Games

You can hide games so that they are not visible in the HDD Browser by using the -hide switch with the 'install', 'inject_cd',
'inject_dvd' or 'modify' commands. A hidden game can be made visible again using the -unhide switch with the 'modify' command.


### Others

If you want to know more about these files (and their restrictions) you have to study official ps2sdk document called `hdd_rule_3.0.2.pdf`
Expand Down
2 changes: 1 addition & 1 deletion gui/gui_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ install(HWND dlg)
ddb_update(config_, game.startup, game.name, game.compat_flags);

pgs = get_progress(dlg);
result = hdl_inject(hio_, iin, &game, -1, pgs);
result = hdl_inject(hio_, iin, &game, -1, 0, pgs);
dispose_progress(pgs);

iin->close(iin);
Expand Down
45 changes: 39 additions & 6 deletions hdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ int hdd_inject_header(hio_t *hio,


/**************************************************************/
void hdl_pname(const char *startup_name, const char *name,
void hdl_pname(const char *startup_name, const char *name, const char part_prefix[3],
char partition_name[PS2_PART_IDMAX + 1])
{
u_int32_t game_name_len = 0;
Expand All @@ -724,7 +724,7 @@ void hdl_pname(const char *startup_name, const char *name,
game_name_len = strlen(name) < game_name_len ? strlen(name) : game_name_len;
if (name[0] != '_' && name[1] != '_') {
game_name_len = PS2_PART_IDMAX - 1 - 3 - 10 - 5; /* limit partition name length */
strcpy(partition_name, "PP.");
strcpy(partition_name, part_prefix);
memmove(partition_name + 3, "SLUS-00000", 10); /*if startup file name absent*/
if (startup_name != NULL) {
memmove(partition_name + 3, startup_name, 4); /*we will copy first 4 symbols*/
Expand Down Expand Up @@ -978,6 +978,7 @@ int hdl_inject(hio_t *hio,
iin_t *iin,
hdl_game_t *details,
int slice_index,
int is_hidden,
progress_t *pgs)
{
/*@only@*/ apa_toc_t *toc = NULL;
Expand All @@ -1001,7 +1002,13 @@ int hdl_inject(hio_t *hio,
*
* PP.XXXX-xxxxx.HDL.name
*/
hdl_pname(details->startup, details->name, details->partition_name);
char part_prefix[3];
if(is_hidden) /* partition will be hidden due to "+" as first char */
strncpy(part_prefix, HIDDEN_PART, 3);
else /* partition will be shown normally */
strncpy(part_prefix, VISIBLE_PART, 3);

hdl_pname(details->startup, details->name, part_prefix, details->partition_name);
}

result = apa_allocate_space(toc, details->partition_name,
Expand Down Expand Up @@ -1248,7 +1255,8 @@ int hdl_modify_game(hio_t *hio,
u_int32_t starting_partition_sector,
const char *new_name, /* or NULL */
compat_flags_t new_compat_flags, /* or COMPAT_FLAGS_INVALID */
unsigned short new_dma) /* or 0 */
unsigned short new_dma, /* or 0 */
int is_hidden)
{
apa_slice_t *slice = toc->slice + slice_index;
const u_int32_t SLICE_2_OFFS = 0x10000000; /* sectors */
Expand All @@ -1270,11 +1278,34 @@ int hdl_modify_game(hio_t *hio,
0x00101000 / 512 + slice_index * SLICE_2_OFFS);
result = hio->read(hio, sector, 2, hdl_hdr, &bytes);
if (result == RET_OK) {
if (new_name != NULL && !toc->is_toxic) { /* HD Loader partition naming: "PP.HDL.Game name" */
char part_prefix[3];

if(is_hidden == -1)
/* hidden switch was not specified, so make no changes */
strncpy(part_prefix, part->header.id, 3);
else if (is_hidden == 1)
/* partition will be hidden in HDDOSD due to "+" as first char */
strncpy(part_prefix, HIDDEN_PART, 3);
else
/* partition will be shown normally */
strncpy(part_prefix, VISIBLE_PART, 3);

if ((strncmp(part_prefix, part->header.id, 3) || new_name != NULL) && !toc->is_toxic) { /* HD Loader partition naming: "PP.HDL.Game name" */
char part_id[PS2_PART_IDMAX];
int tmp_slice_index = 0;
u_int32_t tmp_partition_index = 0;
hdl_pname(NULL, new_name, part_id);
char game_id[11];

/* Get the game ID from the partition header so it can be preserved */
strncpy(game_id, part->header.id + 3, 8);
game_id[8] = '.';
strncpy(game_id + 9, part->header.id + 11, 2);

if (new_name == NULL)
hdl_pname(game_id, part->header.id + 18, part_prefix, part_id);
else
hdl_pname(game_id, new_name, part_prefix, part_id);

result = apa_find_partition(toc, part_id, &tmp_slice_index,
&tmp_partition_index);
if (result == RET_NOT_FOUND) {
Expand All @@ -1288,6 +1319,8 @@ int hdl_modify_game(hio_t *hio,
result = RET_PART_EXISTS;
}

/* BUG: Renaming a game with hdl_dump modify may cause it to show as corrupted data in HDDOSD */
/* -hide or -unhide alone do not cause corruption */
if (result == RET_OK) {
if (new_name != NULL) {
memset(hdl_hdr + 0x08, 0, 0xa0);
Expand Down
8 changes: 6 additions & 2 deletions hdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
C_START

#define HDL_GAME_NAME_MAX 64
#define VISIBLE_PART "PP."
#define HIDDEN_PART "+P."

typedef struct hdl_game_type
{
Expand Down Expand Up @@ -70,7 +72,7 @@ typedef struct hdl_games_list_type
typedef /*@only@*/ /*@null@*/ /*@out@*/ hdl_games_list_t *hdl_games_list_p_t;


void hdl_pname(const char *startup_name, const char *name,
void hdl_pname(const char *startup_name, const char *name, const char part_prefix[3],
/*@out@*/ char partition_name[PS2_PART_IDMAX + 1]);

int hdl_extract_ex(hio_t *hio,
Expand All @@ -88,6 +90,7 @@ int hdl_inject(hio_t *hio,
iin_t *iin,
hdl_game_t *details,
int slice_index,
int is_hidden, /* is the game hidden? */
progress_t *pgs);


Expand Down Expand Up @@ -127,7 +130,8 @@ int hdl_modify_game(hio_t *hio,
u_int32_t starting_partition_sector,
const char *new_name, /* or NULL */
compat_flags_t new_compat_flags, /* or COMPAT_FLAGS_INVALID */
unsigned short new_dma); /* or 0 */
unsigned short new_dma, /* or 0 */
int is_hidden); /* is the game hidden? */

int hdd_inject_header(hio_t *hio,
apa_toc_t *toc,
Expand Down
Loading

0 comments on commit d944b2c

Please sign in to comment.