Skip to content

Commit

Permalink
Add option to disable/enable cheat files (#115)
Browse files Browse the repository at this point in the history
* add cheat file disable option

* clean-up
  • Loading branch information
bucanero authored Jun 11, 2024
1 parent 6fa1b42 commit 5d75f5d
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 246 deletions.
Binary file added assets/images/tag_lock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 1 addition & 4 deletions include/cheats.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions include/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down Expand Up @@ -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
204 changes: 28 additions & 176 deletions source/cheats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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], "&lt;", 4) == 0)
memcpy(enc_data + i, "< ", 4);

else if (strncmp((char*) &enc_data[i], "&gt;", 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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
30 changes: 30 additions & 0 deletions source/exec_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 5d75f5d

Please sign in to comment.