From 10c41ad8b9346a8b78e3de8885425dd21632693a Mon Sep 17 00:00:00 2001 From: bucanero Date: Fri, 20 Dec 2024 20:57:44 -0300 Subject: [PATCH] update groups --- include/saves.h | 4 ++-- source/exec_cmd.c | 10 +++++----- source/saves.c | 26 +++++++++++++++++--------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/include/saves.h b/include/saves.h index 9dd8912..31c75c6 100644 --- a/include/saves.h +++ b/include/saves.h @@ -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); diff --git a/source/exec_cmd.c b/source/exec_cmd.c index 0e72390..93287b6 100644 --- a/source/exec_cmd.c +++ b/source/exec_cmd.c @@ -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; @@ -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; } diff --git a/source/saves.c b/source/saves.c index 8b2bd20..5be82de 100644 --- a/source/saves.c +++ b/source/saves.c @@ -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; @@ -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) { @@ -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; @@ -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) { @@ -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) { @@ -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;