diff --git a/assets/images/tag_lock.png b/assets/images/tag_lock.png new file mode 100644 index 0000000..1e81d91 Binary files /dev/null and b/assets/images/tag_lock.png differ diff --git a/include/cheats.h b/include/cheats.h index 43a57d8..d42a4fd 100644 --- a/include/cheats.h +++ b/include/cheats.h @@ -46,8 +46,7 @@ enum cmd_code_enum // Code commands CMD_TOGGLE_PATCH, - CMD_VIEW_RAW_PATCH, - CMD_VIEW_DETAILS, + CMD_TOGGLE_CHEAT, CMD_DECRYPT_MC4, // Remove commands @@ -161,7 +160,6 @@ typedef struct list_t* (*ReadList)(const char*); } game_list_t; -list_t * ReadUsbList(const char* userPath); list_t * ReadUserList(const char* userPath); list_t * ReadOnlineList(const char* urlPath); list_t * ReadBackupList(const char* userPath); @@ -199,7 +197,6 @@ void execCodeCommand(code_entry_t* code, const char* codecmd); uint64_t patch_hash_calc(const game_entry_t* game, const code_entry_t* code); char* mc4_decrypt(const char* data); -int get_save_details(const game_entry_t *save, char** details); int orbis_SaveUmount(const char* mountPath); int orbis_UpdateSaveParams(const char* mountPath, const char* title, const char* subtitle, const char* details); diff --git a/include/menu.h b/include/menu.h index ab0c969..9ef7381 100644 --- a/include/menu.h +++ b/include/menu.h @@ -72,6 +72,7 @@ enum texture_index tag_shn_png_index, tag_mc4_png_index, tag_json_png_index, + tag_lock_png_index, TOTAL_MENU_TEXTURES }; @@ -152,11 +153,9 @@ void drawEndLogo(); int load_app_settings(app_config_t* config); int save_app_settings(app_config_t* config); -int reset_app_settings(app_config_t* config); int initialize_jbc(); void terminate_jbc(); -int patch_save_libraries(); void initMenuOptions(); #endif diff --git a/source/cheats.c b/source/cheats.c index ab2900d..611dc60 100644 --- a/source/cheats.c +++ b/source/cheats.c @@ -243,10 +243,6 @@ static game_entry_t* createGameEntry(uint16_t flag, const char* name) int set_json_codes(game_entry_t* item) { code_entry_t* cmd; - item->codes = list_alloc(); - -// cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_USER " View Save Details", CMD_VIEW_DETAILS); -// list_append(item->codes, cmd); LOG("Parsing \"%s\"...", item->path); @@ -331,13 +327,22 @@ char* mc4_decrypt(const char* data) aes_setkey_dec(&aes_ctx, (uint8_t*) MC4_AES256CBC_KEY, 256); aes_crypt_cbc(&aes_ctx, AES_DECRYPT, enc_size, iv, enc_data, enc_data); + // replace html entities in the decrypted XML data + for (size_t i = 0; i < (enc_size - 3); i++) + { + if (strncmp((char*) &enc_data[i], "<", 4) == 0) + memcpy(enc_data + i, "< ", 4); + + else if (strncmp((char*) &enc_data[i], ">", 4) == 0) + memcpy(enc_data + i, "> ", 4); + } + return (char*) enc_data; } int set_shn_codes(game_entry_t* item) { code_entry_t* cmd; - item->codes = list_alloc(); LOG("Parsing %s...", item->path); char *buffer = readTextFile(item->path, NULL); @@ -415,6 +420,11 @@ int set_shn_codes(game_entry_t* item) */ int ReadCodes(game_entry_t * save) { + save->codes = list_alloc(); + list_append(save->codes, _createCmdCode(PATCH_COMMAND, + (save->flags & CHEAT_FLAG_LOCKED) ? CHAR_ICON_LOCK " Enable Cheat File" : CHAR_ICON_LOCK "Disable Cheat File", + CMD_TOGGLE_CHEAT)); + if (save->flags & CHEAT_FLAG_JSON) return set_json_codes(save); @@ -458,6 +468,7 @@ int ReadOnlineCodes(game_entry_t * game) char *tmp = game->path; game->path = path; + game->codes = list_alloc(); if (game->flags & CHEAT_FLAG_JSON) set_json_codes(game); @@ -913,7 +924,7 @@ static void read_shn_games(const char* userPath, list_t *list) while ((dir = readdir(d)) != NULL) { - if (!endsWith(dir->d_name, ".shn")) + if (!endsWith(dir->d_name, ".shn") && !endsWith(dir->d_name, ".shn-disabled")) continue; snprintf(fullPath, sizeof(fullPath), "%s%s", userPath, dir->d_name); @@ -951,6 +962,9 @@ static void read_shn_games(const char* userPath, list_t *list) mxmlDelete(tree); free(buffer); + if (endsWith(dir->d_name, ".shn-disabled")) + item->flags |= CHEAT_FLAG_LOCKED; + LOG("[%s] F(%d) '%s'", item->title_id, item->flags, item->name); list_append(list, item); } @@ -972,7 +986,7 @@ static void read_mc4_games(const char* userPath, list_t *list) while ((dir = readdir(d)) != NULL) { - if (!endsWith(dir->d_name, ".mc4")) + if (!endsWith(dir->d_name, ".mc4") && !endsWith(dir->d_name, ".mc4-disabled")) continue; snprintf(fullPath, sizeof(fullPath), "%s%s", userPath, dir->d_name); @@ -1027,6 +1041,9 @@ static void read_mc4_games(const char* userPath, list_t *list) mxmlDelete(tree); free(buffer); + if (endsWith(dir->d_name, ".mc4-disabled")) + item->flags |= CHEAT_FLAG_LOCKED; + LOG("[%s] F(%d) '%s'", item->title_id, item->flags, item->name); list_append(list, item); } @@ -1049,7 +1066,7 @@ static void read_json_games(const char* userPath, list_t *list) while ((dir = readdir(d)) != NULL) { - if (!endsWith(dir->d_name, ".json")) + if (!endsWith(dir->d_name, ".json") && !endsWith(dir->d_name, ".json-disabled")) continue; snprintf(fullPath, sizeof(fullPath), "%s%s", userPath, dir->d_name); @@ -1082,6 +1099,9 @@ static void read_json_games(const char* userPath, list_t *list) cJSON_Delete(cheat); free(buffer); + if (endsWith(dir->d_name, ".json-disabled")) + item->flags |= CHEAT_FLAG_LOCKED; + LOG("[%s] F(%d) '%s'", item->title_id, item->flags, item->name); list_append(list, item); } @@ -1111,26 +1131,6 @@ list_t * ReadUserList(const char* userPath) list = list_alloc(); -/* - item = createGameEntry(CHEAT_FLAG_PS4, CHAR_ICON_COPY " Bulk Cheats Management"); - item->type = FILE_TYPE_MENU; - item->codes = list_alloc(); - item->path = strdup(userPath); -// item->path = (void*) list; //bulk management hack - - cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_SIGN " Resign & Unlock all Saves", CMD_RESIGN_ALL_SAVES); - list_append(item->codes, cmd); - - cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_COPY " Copy all Saves to USB", CMD_CODE_NULL); - cmd->options_count = 1; - cmd->options = _createOptions(2, "Copy Saves to USB", CMD_COPY_SAVES_USB); - list_append(item->codes, cmd); - - cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_LOCK " Dump all Save Fingerprints", CMD_DUMP_FINGERPRINTS); - list_append(item->codes, cmd); - list_append(list, item); -*/ - LOG("Loading JSON files..."); snprintf(fullPath, sizeof(fullPath), "%sjson/", userPath); read_json_games(fullPath, list); @@ -1251,151 +1251,3 @@ list_t * ReadOnlineList(const char* urlPath) check_game_appdb(list); return list; } - -int get_save_details(const game_entry_t* save, char **details) -{ -/* - char sfoPath[256]; - sqlite3 *db; - sqlite3_stmt *res; - - - if (!(save->flags & CHEAT_FLAG_PS4)) - { - asprintf(details, "%s\n\nTitle: %s\n", save->path, save->name); - return 1; - } - - if (save->flags & CHEAT_FLAG_TROPHY) - { - if ((db = open_sqlite_db(save->path)) == NULL) - return 0; - - char* query = sqlite3_mprintf("SELECT id, description, trophy_num, unlocked_trophy_num, progress," - "platinum_num, unlocked_platinum_num, gold_num, unlocked_gold_num, silver_num, unlocked_silver_num," - "bronze_num, unlocked_bronze_num FROM tbl_trophy_title WHERE id = %d", save->blocks); - - if (sqlite3_prepare_v2(db, query, -1, &res, NULL) != SQLITE_OK || sqlite3_step(res) != SQLITE_ROW) - { - LOG("Failed to fetch data: %s", sqlite3_errmsg(db)); - sqlite3_free(query); - sqlite3_close(db); - return 0; - } - - asprintf(details, "Trophy-Set Details\n\n" - "Title: %s\n" - "Description: %s\n" - "NP Comm ID: %s\n" - "Progress: %d/%d - %d%%\n" - "%c Platinum: %d/%d\n" - "%c Gold: %d/%d\n" - "%c Silver: %d/%d\n" - "%c Bronze: %d/%d\n", - save->name, sqlite3_column_text(res, 1), save->title_id, - sqlite3_column_int(res, 3), sqlite3_column_int(res, 2), sqlite3_column_int(res, 4), - CHAR_TRP_PLATINUM, sqlite3_column_int(res, 6), sqlite3_column_int(res, 5), - CHAR_TRP_GOLD, sqlite3_column_int(res, 8), sqlite3_column_int(res, 7), - CHAR_TRP_SILVER, sqlite3_column_int(res, 10), sqlite3_column_int(res, 9), - CHAR_TRP_BRONZE, sqlite3_column_int(res, 12), sqlite3_column_int(res, 11)); - - sqlite3_free(query); - sqlite3_finalize(res); - sqlite3_close(db); - - return 1; - } - - if(save->flags & CHEAT_FLAG_LOCKED) - { - asprintf(details, "%s\n\n" - "Title ID: %s\n" - "Dir Name: %s\n" - "Blocks: %d\n" - "Account ID: %.16s\n", - save->path, - save->title_id, - save->version, - save->blocks, - save->path + 23); - - return 1; - } - - if(save->flags & CHEAT_FLAG_HDD) - { - if ((db = open_sqlite_db(save->path)) == NULL) - return 0; - - char* query = sqlite3_mprintf("SELECT sub_title, detail, free_blocks, size_kib, user_id, account_id FROM savedata " - " WHERE title_id = %Q AND dir_name = %Q", save->title_id, save->version); - - if (sqlite3_prepare_v2(db, query, -1, &res, NULL) != SQLITE_OK || sqlite3_step(res) != SQLITE_ROW) - { - LOG("Failed to fetch data: %s", sqlite3_errmsg(db)); - sqlite3_free(query); - sqlite3_close(db); - return 0; - } - - asprintf(details, "%s\n\n" - "Title: %s\n" - "Subtitle: %s\n" - "Detail: %s\n" - "Dir Name: %s\n" - "Blocks: %d (%d Free)\n" - "Size: %d Kb\n" - "User ID: %08x\n" - "Account ID: %016llx\n", - save->path, save->name, - sqlite3_column_text(res, 0), - sqlite3_column_text(res, 1), - save->version, - save->blocks, sqlite3_column_int(res, 2), - sqlite3_column_int(res, 3), - sqlite3_column_int(res, 4), - sqlite3_column_int64(res, 5)); - - sqlite3_free(query); - sqlite3_finalize(res); - sqlite3_close(db); - - return 1; - } - - snprintf(sfoPath, sizeof(sfoPath), "%s" "sce_sys/param.sfo", save->path); - LOG("Save Details :: Reading %s...", sfoPath); - - sfo_context_t* sfo = sfo_alloc(); - if (sfo_read(sfo, sfoPath) < 0) { - LOG("Unable to read from '%s'", sfoPath); - sfo_free(sfo); - return 0; - } - - char* subtitle = (char*) sfo_get_param_value(sfo, "SUBTITLE"); - char* detail = (char*) sfo_get_param_value(sfo, "DETAIL"); - uint64_t* account_id = (uint64_t*) sfo_get_param_value(sfo, "ACCOUNT_ID"); - sfo_params_ids_t* param_ids = (sfo_params_ids_t*) sfo_get_param_value(sfo, "PARAMS"); - - asprintf(details, "%s\n\n" - "Title: %s\n" - "Subtitle: %s\n" - "Detail: %s\n" - "Dir Name: %s\n" - "Blocks: %d\n" - "User ID: %08x\n" - "Account ID: %016lx\n", - save->path, save->name, - subtitle, - detail, - save->version, - save->blocks, - param_ids->user_id, - *account_id); - - sfo_free(sfo); -*/ - asprintf(details, "%s\n", save->path); - return 1; -} diff --git a/source/exec_cmd.c b/source/exec_cmd.c index 84e5d41..81c88fd 100644 --- a/source/exec_cmd.c +++ b/source/exec_cmd.c @@ -49,6 +49,32 @@ static void togglePatch(const game_entry_t* game, const code_entry_t* code) show_message("Patch \"%s\" %s", code->name, code->activated ? "Enabled" : "Disabled"); } +static void toggleCheatFile(game_entry_t* game, code_entry_t* code) +{ + char file_path[256]; + + LOG("Toggle cheat file: %s", game->path); + if (game->flags & CHEAT_FLAG_LOCKED) + { + snprintf(file_path, sizeof(file_path), "%s", game->path); + *strrchr(file_path, '-') = 0; + } + else + snprintf(file_path, sizeof(file_path), "%s-disabled", game->path); + + if (rename(game->path, file_path) < 0) + { + LOG("Failed to rename cheat file %s", file_path); + return; + } + game->flags ^= CHEAT_FLAG_LOCKED; + free(game->path); + asprintf(&game->path, "%s", file_path); + memcpy(code->name +1, (game->flags & CHEAT_FLAG_LOCKED) ? "Dis" : " En", 3); + + show_message("Cheat File %s:\n%s", (game->flags & CHEAT_FLAG_LOCKED) ? "Disabled" : "Enabled", game->path); +} + static void updNetCheats(void) { if (!http_download(gcm_config.url_cheats, GOLDCHEATS_FILE, CHEATSMGR_LOCAL_CACHE LOCAL_TEMP_ZIP, 1)) @@ -366,6 +392,10 @@ void execCodeCommand(code_entry_t* code, const char* codecmd) removePlugins(); break; + case CMD_TOGGLE_CHEAT: + toggleCheatFile(selected_entry, code); + return; + case CMD_TOGGLE_PATCH: togglePatch(selected_entry, code); return; diff --git a/source/main.c b/source/main.c index 62ecd97..8302e48 100644 --- a/source/main.c +++ b/source/main.c @@ -200,6 +200,7 @@ static int LoadTextures_Menu(void) load_menu_texture(tag_shn, png); load_menu_texture(tag_mc4, png); load_menu_texture(tag_json, png); + load_menu_texture(tag_lock, png); load_menu_texture(circle_error_dark, png); load_menu_texture(circle_error_light, png); load_menu_texture(circle_loading_bg, png); @@ -303,6 +304,7 @@ static void registerSpecialChars(void) RegisterSpecialCharacter(CHAR_TAG_MC4, 0, 1.0, &menu_textures[tag_mc4_png_index]); RegisterSpecialCharacter(CHAR_TAG_SHN, 0, 1.0, &menu_textures[tag_shn_png_index]); RegisterSpecialCharacter(CHAR_TAG_JSON, 0, 1.0, &menu_textures[tag_json_png_index]); + RegisterSpecialCharacter(CHAR_TAG_LOCKED, 0, 1.0, &menu_textures[tag_lock_png_index]); } static void helpFooter(int id) diff --git a/source/menu_cheats.c b/source/menu_cheats.c index 5053f0b..84a75a8 100644 --- a/source/menu_cheats.c +++ b/source/menu_cheats.c @@ -350,10 +350,8 @@ void DrawGameList(int selIndex, list_t * games, u8 alpha) if (item->flags & CHEAT_FLAG_SHN) tmp[0] = CHAR_TAG_SHN; if (item->flags & CHEAT_FLAG_MC4) tmp[0] = CHAR_TAG_MC4; if (item->flags & CHEAT_FLAG_JSON) tmp[0] = CHAR_TAG_JSON; -/* - tmp[1] = (item->flags & CHEAT_FLAG_OWNER) ? CHAR_TAG_OWNER : ' '; - tmp[2] = (item->flags & CHEAT_FLAG_LOCKED) ? CHAR_TAG_LOCKED : ' '; -*/ + if (item->flags & CHEAT_FLAG_LOCKED) tmp[0] = CHAR_TAG_LOCKED; + DrawString(SCREEN_WIDTH - (MENU_ICON_OFF * 2), game_y, tmp); if (item->flags & CHEAT_FLAG_OWNER) diff --git a/source/menu_main.c b/source/menu_main.c index ce73e6e..541cb0f 100644 --- a/source/menu_main.c +++ b/source/menu_main.c @@ -79,32 +79,6 @@ static int ReloadUserGames(game_list_t* save_list, const char* message) return list_count(save_list->list); } -static code_entry_t* LoadRawPatch(void) -{ - size_t len; - char patchPath[256]; - code_entry_t* centry = calloc(1, sizeof(code_entry_t)); - - centry->name = strdup(selected_entry->title_id); - snprintf(patchPath, sizeof(patchPath), GOLDCHEATS_DATA_PATH "%s.savepatch", selected_entry->title_id); - read_buffer(patchPath, (u8**) ¢ry->codes, &len); - centry->codes[len] = 0; - - return centry; -} - -static code_entry_t* LoadSaveDetails(void) -{ - code_entry_t* centry = calloc(1, sizeof(code_entry_t)); - centry->name = strdup(selected_entry->title_id); - - if (!get_save_details(selected_entry, ¢ry->codes)) - asprintf(¢ry->codes, "Error getting details (%s)", selected_entry->name); - - LOG("%s", centry->codes); - return (centry); -} - static void SetMenu(int id) { switch (menu_id) //Leaving menu @@ -195,25 +169,7 @@ static void SetMenu(int id) //if entering from game list, don't keep index, otherwise keep if (menu_id == MENU_HDD_CHEATS || menu_id == MENU_ONLINE_DB || menu_id == MENU_HDD_PATCHES || menu_id == MENU_UPDATE_CHEATS) menu_old_sel[MENU_PATCHES] = 0; -/* - char iconfile[256]; - snprintf(iconfile, sizeof(iconfile), "%s" "sce_sys/icon0.png", selected_entry->path); - - if (selected_entry->flags & CHEAT_FLAG_ONLINE) - { - snprintf(iconfile, sizeof(iconfile), CHEATSMGR_LOCAL_CACHE "%s.PNG", selected_entry->title_id); - if (file_exists(iconfile) != SUCCESS) - http_download(selected_entry->path, "icon0.png", iconfile, 0); - } - else if (selected_entry->flags & CHEAT_FLAG_HDD) - snprintf(iconfile, sizeof(iconfile), PS4_SAVES_PATH_HDD "%s/%s_icon0.png", gcm_config.user_id, selected_entry->title_id, selected_entry->version); - - if (file_exists(iconfile) == SUCCESS) - LoadFileTexture(iconfile, icon_png_file_index); - else - menu_textures[icon_png_file_index].size = 0; -*/ if (gcm_config.doAni && menu_id != MENU_PATCH_VIEW && menu_id != MENU_CODE_OPTIONS) Draw_CheatsMenu_Selection_Ani(); break; @@ -611,22 +567,6 @@ static void doPatchMenu(void) SetMenu(MENU_CODE_OPTIONS); return; } - - if (selected_centry->codes[0] == CMD_VIEW_RAW_PATCH) - { - selected_centry->activated = 0; - selected_centry = LoadRawPatch(); - SetMenu(MENU_SAVE_DETAILS); - return; - } - - if (selected_centry->codes[0] == CMD_VIEW_DETAILS) - { - selected_centry->activated = 0; - selected_centry = LoadSaveDetails(); - SetMenu(MENU_SAVE_DETAILS); - return; - } } } else if (orbisPadGetButtonPressed(ORBIS_PAD_BUTTON_TRIANGLE))