Skip to content

Commit

Permalink
problems with seek and read in detect_system
Browse files Browse the repository at this point in the history
  • Loading branch information
pkos committed Mar 21, 2020
1 parent f201889 commit 028b2e5
Showing 1 changed file with 0 additions and 202 deletions.
202 changes: 0 additions & 202 deletions tasks/task_database_cue.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,208 +849,6 @@ int detect_dc_game(intfstream_t *fd, char *game_id)
return false;
}

int detect_dc_game(intfstream_t *fd, char *game_id)
{
char hyphen = '-';
char hyphen_str[] = "-";
int total_hyphens;
int total_hyphens_recalc;
char pre_game_id[50];
char raw_game_id[50];
char check_prefix_t_hyp[10];
char check_prefix_t[10];
char check_prefix_hdr_hyp[10];
char check_prefix_mk_hyp[10];
int length;
int length_recalc;
int index;
size_t size_t_var;
char lgame_id[20];
char rgame_id[20];

if (intfstream_seek(fd, 0x0040, SEEK_SET) >= 0)
{

if (intfstream_read(fd, raw_game_id, 10) > 0)
{
raw_game_id[10] = '\0';
}
else
{
return false;
}
}
else
{
return false;
}

left_and_right_trim_spaces(raw_game_id);
replace_multi_space_with_single_space(raw_game_id);
replace_space_with_single_character(raw_game_id, hyphen);
length = strlen(raw_game_id);
raw_game_id[length] = '\0';
total_hyphens = count_occurances_single_character(raw_game_id, hyphen);

/** disect this raw serial into parts **/
strncpy(check_prefix_t_hyp, raw_game_id, 2);
check_prefix_t_hyp[2] = '\0';
strncpy(check_prefix_t, raw_game_id, 1);
check_prefix_t[1] = '\0';
strncpy(check_prefix_hdr_hyp, raw_game_id, 4);
check_prefix_hdr_hyp[4] = '\0';
strncpy(check_prefix_mk_hyp, raw_game_id, 3);
check_prefix_mk_hyp[3] = '\0';

/** redump serials are built differently for each prefix **/
if (!strcmp(check_prefix_t_hyp, "T-"))
{
if (total_hyphens >= 2)
{
index = index_last_occurance(raw_game_id, hyphen);
if (index < 0)
{
return false;
}
else
{
size_t_var = (size_t)index;
}
strncpy(lgame_id, &raw_game_id[0], size_t_var);
lgame_id[index] = '\0';
strncpy(rgame_id, &raw_game_id[index + 1], length - 1);
rgame_id[length - 1] = '\0';
strcat(game_id, lgame_id);
strcat(game_id, hyphen_str);
strcat(game_id, rgame_id);
return true;
}
else if (total_hyphens == 1)
{
if (length <= 7)
{
strncpy(game_id, raw_game_id, 7);
game_id[7] = '\0';
return true;
}
else if (length >= 8)
{
strncpy(lgame_id, raw_game_id, 7);
lgame_id[7] = '\0';
strncpy(rgame_id, &raw_game_id[length - 2], length - 1);
rgame_id[length - 1] = '\0';
strcat(game_id, lgame_id);
strcat(game_id, hyphen_str);
strcat(game_id, rgame_id);
return true;
}
}
} else if (!strcmp(check_prefix_t, "T"))
{
strncpy(lgame_id, raw_game_id, 1);
lgame_id[1] = '\0';
strncpy(rgame_id, &raw_game_id[1], length - 1);
rgame_id[length - 1] = '\0';
strcat(pre_game_id, lgame_id);
strcat(pre_game_id, hyphen_str);
strcat(pre_game_id, rgame_id);

total_hyphens_recalc = count_occurances_single_character(pre_game_id, hyphen);

if (total_hyphens_recalc >= 2)
{
index = index_last_occurance(pre_game_id, hyphen);
if (index < 0)
{
return false;
}
else
{
size_t_var = (size_t)index;
}
strncpy(lgame_id, pre_game_id, index);
lgame_id[index] = '\0';
length_recalc = strlen(pre_game_id);
strncpy(rgame_id, &pre_game_id[length_recalc - 2], length_recalc - 1);
rgame_id[length_recalc - 1] = '\0';
strcat(game_id, lgame_id);
strcat(game_id, hyphen_str);
strcat(game_id, rgame_id);
return true;
}
else if (total_hyphens_recalc == 1)
{
length_recalc = strlen(pre_game_id) - 1;
if (length_recalc <= 8)
{
strncpy(game_id, pre_game_id, 9);
game_id[9] = '\0';
return true;
}
else if (length_recalc >= 9)
{
strncpy(lgame_id, pre_game_id, 7);
lgame_id[7] = '\0';
strncpy(rgame_id, &pre_game_id[length_recalc - 2], length_recalc - 1);
rgame_id[length_recalc - 1] = '\0';
strcat(game_id, lgame_id);
strcat(game_id, hyphen_str);
strcat(game_id, rgame_id);
return true;
}
}
}
else if (!strcmp(check_prefix_hdr_hyp, "HDR-"))
{
if (total_hyphens >= 2)
{
index = index_last_occurance(raw_game_id, hyphen);
if (index < 0)
{
return false;
}
else
{
size_t_var = (size_t)index;
}
strncpy(lgame_id, raw_game_id, index - 1);
lgame_id[index - 1] = '\0';
strncpy(rgame_id, &raw_game_id[length - 4], length - 3);
rgame_id[length - 3] = '\0';
strcat(game_id, lgame_id);
strcat(game_id, hyphen_str);
strcat(game_id, rgame_id);
return true;
}
else
{
strcpy(game_id, raw_game_id);
return true;
}
}
else if (!strcmp(check_prefix_mk_hyp, "MK-"))
{
if (length <= 8)
{
strncpy(game_id, raw_game_id, 8);
game_id[8] = '\0';
return true;
}
else if (length >= 9)
{
strncpy(lgame_id, raw_game_id, 8);
lgame_id[8] = '\0';
strncpy(rgame_id, &raw_game_id[length - 2], length - 1);
rgame_id[length - 1] = '\0';
strcat(game_id, lgame_id);
strcat(game_id, hyphen_str);
strcat(game_id, rgame_id);
}
}

return false;
}

/**
* Check for an ASCII serial in the first few bits of the ISO (Wii).
*/
Expand Down

0 comments on commit 028b2e5

Please sign in to comment.