Skip to content

Commit

Permalink
add cheat file disable option
Browse files Browse the repository at this point in the history
  • Loading branch information
bucanero committed Jun 10, 2024
1 parent 6fa1b42 commit 63ee3ce
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 74 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.
3 changes: 1 addition & 2 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
1 change: 1 addition & 0 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
36 changes: 28 additions & 8 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
29 changes: 29 additions & 0 deletions source/exec_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,31 @@ 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)
{
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, '-')[1] = '\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);

show_message("Cheat File \"%s\" %s", game->name, (game->flags & CHEAT_FLAG_LOCKED) ? "Disabled" : "Enabled");
}

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 +391,10 @@ void execCodeCommand(code_entry_t* code, const char* codecmd)
removePlugins();
break;

case CMD_TOGGLE_CHEAT:
toggleCheatFile(selected_entry);
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
6 changes: 2 additions & 4 deletions source/menu_cheats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
60 changes: 0 additions & 60 deletions source/menu_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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**) &centry->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, &centry->codes))
asprintf(&centry->codes, "Error getting details (%s)", selected_entry->name);

LOG("%s", centry->codes);
return (centry);
}

static void SetMenu(int id)
{
switch (menu_id) //Leaving menu
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 63ee3ce

Please sign in to comment.