Skip to content

Commit

Permalink
update groups
Browse files Browse the repository at this point in the history
  • Loading branch information
bucanero committed Dec 20, 2024
1 parent d0d0179 commit 10c41ad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
4 changes: 2 additions & 2 deletions include/saves.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ int orbis_SaveMount(const save_entry_t *save, uint32_t mode, char* mountPath);
int orbis_SaveDelete(const save_entry_t *save);
int orbis_UpdateSaveParams(const save_entry_t* save, const char* title, const char* subtitle, const char* details, uint32_t up);

int trophy_lock(const save_entry_t* game, int trp_id, int type);
int trophy_unlock(const save_entry_t* game, int trp_id, int type);
int trophy_lock(const save_entry_t* game, int trp_id, int grp_id, int type);
int trophy_unlock(const save_entry_t* game, int trp_id, int grp_id, int type);

int vmc_export_psv(const char* save, const char* out_path);
int vmc_export_psu(const char* path, const char* output);
Expand Down
10 changes: 5 additions & 5 deletions source/exec_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ static void exportFingerprint(const save_entry_t* save, int silent)
static void toggleTrophy(const save_entry_t* entry)
{
int ret = 1;
uint32_t trophy_id;
int *trophy_id;
code_entry_t* code;
list_node_t* node;

Expand All @@ -351,18 +351,18 @@ static void toggleTrophy(const save_entry_t* entry)
if (!code->activated || (code->type != PATCH_TROP_UNLOCK && code->type != PATCH_TROP_LOCK))
continue;

trophy_id = *(uint32_t*)(code->file);
LOG("Active code: [%d] '%s'", trophy_id, code->name+2);
trophy_id = (int*)(code->file);
LOG("Active code: [%d] '%s'", trophy_id[0], code->name+2);

if (code->type == PATCH_TROP_UNLOCK)
{
ret &= trophy_unlock(entry, trophy_id, code->name[0]);
ret &= trophy_unlock(entry, trophy_id[0], trophy_id[1], code->name[0]);
code->type = PATCH_TROP_LOCK;
code->name[1] = ' ';
}
else
{
ret &= trophy_lock(entry, trophy_id, code->name[0]);
ret &= trophy_lock(entry, trophy_id[0], trophy_id[1], code->name[0]);
code->type = PATCH_TROP_UNLOCK;
code->name[1] = CHAR_TAG_LOCKED;
}
Expand Down
26 changes: 17 additions & 9 deletions source/saves.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ static const char* trophy_type_field(int type)
}
}

int trophy_unlock(const save_entry_t* game, int trp_id, int type)
int trophy_unlock(const save_entry_t* game, int trp_id, int grp_id, int type)
{
char dbpath[256];
sqlite3 *db;
Expand All @@ -420,9 +420,12 @@ int trophy_unlock(const save_entry_t* game, int trp_id, int type)
"(1, 1, strftime('%%Y-%%m-%%dT%%H:%%M:%%S.00Z', CURRENT_TIMESTAMP), strftime('%%Y-%%m-%%dT%%H:%%M:%%S.00Z', CURRENT_TIMESTAMP))"
"WHERE (title_id = %d AND trophyid = %d);\n"
"UPDATE tbl_trophy_title SET (progress, unlocked_trophy_num, %s) ="
"(((unlocked_trophy_num+1)*100)/trophy_num, unlocked_trophy_num+1, %s+1) WHERE (id=%d);",
"(((unlocked_trophy_num+1)*100)/trophy_num, unlocked_trophy_num+1, %s+1) WHERE (id=%d);\n"
"UPDATE tbl_trophy_group SET (progress, unlocked_trophy_num, %s) ="
"(((unlocked_trophy_num+1)*100)/trophy_num, unlocked_trophy_num+1, %s+1) WHERE (title_id=%d AND groupid=%d);",
game->blocks, trp_id,
field, field, game->blocks);
field, field, game->blocks,
field, field, game->blocks, grp_id);

if (sqlite3_exec(db, query, NULL, NULL, NULL) != SQLITE_OK)
{
Expand All @@ -440,7 +443,7 @@ int trophy_unlock(const save_entry_t* game, int trp_id, int type)
return 1;
}

int trophy_lock(const save_entry_t* game, int trp_id, int type)
int trophy_lock(const save_entry_t* game, int trp_id, int grp_id, int type)
{
char dbpath[256];
sqlite3 *db;
Expand All @@ -457,9 +460,12 @@ int trophy_lock(const save_entry_t* game, int trp_id, int type)
"((~(hidden&1))&(hidden|1), 0, '0001-01-01T00:00:00.00Z', '0001-01-01T00:00:00.00Z') "
"WHERE (title_id = %d AND trophyid = %d);\n"
"UPDATE tbl_trophy_title SET (progress, unlocked_trophy_num, %s) ="
"(((unlocked_trophy_num-1)*100)/trophy_num, unlocked_trophy_num-1, %s-1) WHERE (id=%d);",
"(((unlocked_trophy_num-1)*100)/trophy_num, unlocked_trophy_num-1, %s-1) WHERE (id=%d);\n"
"UPDATE tbl_trophy_group SET (progress, unlocked_trophy_num, %s) ="
"(((unlocked_trophy_num-1)*100)/trophy_num, unlocked_trophy_num-1, %s-1) WHERE (title_id=%d AND groupid=%d);",
game->blocks, trp_id,
field, field, game->blocks);
field, field, game->blocks,
field, field, game->blocks, grp_id);

if (sqlite3_exec(db, query, NULL, NULL, NULL) != SQLITE_OK)
{
Expand Down Expand Up @@ -1088,7 +1094,7 @@ int ReadTrophies(save_entry_t * game)
trophy = _createCmdCode(PATCH_NULL, "----- " UTF8_CHAR_STAR " Trophies " UTF8_CHAR_STAR " -----", CMD_CODE_NULL);
list_append(game->codes, trophy);

snprintf(query, sizeof(query), "SELECT trophyid, trophy_title_id, title, description, grade, unlocked FROM tbl_trophy_flag WHERE title_id = %d", game->blocks);
snprintf(query, sizeof(query), "SELECT trophyid, groupid, title, description, grade, unlocked FROM tbl_trophy_flag WHERE title_id = %d", game->blocks);

if (sqlite3_prepare_v2(db, query, -1, &res, NULL) != SQLITE_OK)
{
Expand Down Expand Up @@ -1127,8 +1133,10 @@ int ReadTrophies(save_entry_t * game)
}

trop_id = sqlite3_column_int(res, 0);
trophy->file = malloc(sizeof(trop_id));
memcpy(trophy->file, &trop_id, sizeof(trop_id));
trophy->file = malloc(sizeof(int)*2);
memcpy(trophy->file, &trop_id, sizeof(int));
trop_id = sqlite3_column_int(res, 1);
memcpy(trophy->file + sizeof(int), &trop_id, sizeof(int));

if (!sqlite3_column_int(res, 5))
trophy->name[1] = CHAR_TAG_LOCKED;
Expand Down

0 comments on commit 10c41ad

Please sign in to comment.