Skip to content

Commit 5d75f5d

Browse files
authored
Add option to disable/enable cheat files (#115)
* add cheat file disable option * clean-up
1 parent 6fa1b42 commit 5d75f5d

File tree

8 files changed

+64
-246
lines changed

8 files changed

+64
-246
lines changed

assets/images/tag_lock.png

1007 Bytes
Loading

include/cheats.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ enum cmd_code_enum
4646

4747
// Code commands
4848
CMD_TOGGLE_PATCH,
49-
CMD_VIEW_RAW_PATCH,
50-
CMD_VIEW_DETAILS,
49+
CMD_TOGGLE_CHEAT,
5150
CMD_DECRYPT_MC4,
5251

5352
// Remove commands
@@ -161,7 +160,6 @@ typedef struct
161160
list_t* (*ReadList)(const char*);
162161
} game_list_t;
163162

164-
list_t * ReadUsbList(const char* userPath);
165163
list_t * ReadUserList(const char* userPath);
166164
list_t * ReadOnlineList(const char* urlPath);
167165
list_t * ReadBackupList(const char* userPath);
@@ -199,7 +197,6 @@ void execCodeCommand(code_entry_t* code, const char* codecmd);
199197
uint64_t patch_hash_calc(const game_entry_t* game, const code_entry_t* code);
200198
char* mc4_decrypt(const char* data);
201199

202-
int get_save_details(const game_entry_t *save, char** details);
203200
int orbis_SaveUmount(const char* mountPath);
204201
int orbis_UpdateSaveParams(const char* mountPath, const char* title, const char* subtitle, const char* details);
205202

include/menu.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ enum texture_index
7272
tag_shn_png_index,
7373
tag_mc4_png_index,
7474
tag_json_png_index,
75+
tag_lock_png_index,
7576

7677
TOTAL_MENU_TEXTURES
7778
};
@@ -152,11 +153,9 @@ void drawEndLogo();
152153

153154
int load_app_settings(app_config_t* config);
154155
int save_app_settings(app_config_t* config);
155-
int reset_app_settings(app_config_t* config);
156156

157157
int initialize_jbc();
158158
void terminate_jbc();
159-
int patch_save_libraries();
160159
void initMenuOptions();
161160

162161
#endif

source/cheats.c

+28-176
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,6 @@ static game_entry_t* createGameEntry(uint16_t flag, const char* name)
243243
int set_json_codes(game_entry_t* item)
244244
{
245245
code_entry_t* cmd;
246-
item->codes = list_alloc();
247-
248-
// cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_USER " View Save Details", CMD_VIEW_DETAILS);
249-
// list_append(item->codes, cmd);
250246

251247
LOG("Parsing \"%s\"...", item->path);
252248

@@ -331,13 +327,22 @@ char* mc4_decrypt(const char* data)
331327
aes_setkey_dec(&aes_ctx, (uint8_t*) MC4_AES256CBC_KEY, 256);
332328
aes_crypt_cbc(&aes_ctx, AES_DECRYPT, enc_size, iv, enc_data, enc_data);
333329

330+
// replace html entities in the decrypted XML data
331+
for (size_t i = 0; i < (enc_size - 3); i++)
332+
{
333+
if (strncmp((char*) &enc_data[i], "&lt;", 4) == 0)
334+
memcpy(enc_data + i, "< ", 4);
335+
336+
else if (strncmp((char*) &enc_data[i], "&gt;", 4) == 0)
337+
memcpy(enc_data + i, "> ", 4);
338+
}
339+
334340
return (char*) enc_data;
335341
}
336342

337343
int set_shn_codes(game_entry_t* item)
338344
{
339345
code_entry_t* cmd;
340-
item->codes = list_alloc();
341346

342347
LOG("Parsing %s...", item->path);
343348
char *buffer = readTextFile(item->path, NULL);
@@ -415,6 +420,11 @@ int set_shn_codes(game_entry_t* item)
415420
*/
416421
int ReadCodes(game_entry_t * save)
417422
{
423+
save->codes = list_alloc();
424+
list_append(save->codes, _createCmdCode(PATCH_COMMAND,
425+
(save->flags & CHEAT_FLAG_LOCKED) ? CHAR_ICON_LOCK " Enable Cheat File" : CHAR_ICON_LOCK "Disable Cheat File",
426+
CMD_TOGGLE_CHEAT));
427+
418428
if (save->flags & CHEAT_FLAG_JSON)
419429
return set_json_codes(save);
420430

@@ -458,6 +468,7 @@ int ReadOnlineCodes(game_entry_t * game)
458468

459469
char *tmp = game->path;
460470
game->path = path;
471+
game->codes = list_alloc();
461472

462473
if (game->flags & CHEAT_FLAG_JSON)
463474
set_json_codes(game);
@@ -913,7 +924,7 @@ static void read_shn_games(const char* userPath, list_t *list)
913924

914925
while ((dir = readdir(d)) != NULL)
915926
{
916-
if (!endsWith(dir->d_name, ".shn"))
927+
if (!endsWith(dir->d_name, ".shn") && !endsWith(dir->d_name, ".shn-disabled"))
917928
continue;
918929

919930
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)
951962
mxmlDelete(tree);
952963
free(buffer);
953964

965+
if (endsWith(dir->d_name, ".shn-disabled"))
966+
item->flags |= CHEAT_FLAG_LOCKED;
967+
954968
LOG("[%s] F(%d) '%s'", item->title_id, item->flags, item->name);
955969
list_append(list, item);
956970
}
@@ -972,7 +986,7 @@ static void read_mc4_games(const char* userPath, list_t *list)
972986

973987
while ((dir = readdir(d)) != NULL)
974988
{
975-
if (!endsWith(dir->d_name, ".mc4"))
989+
if (!endsWith(dir->d_name, ".mc4") && !endsWith(dir->d_name, ".mc4-disabled"))
976990
continue;
977991

978992
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)
10271041
mxmlDelete(tree);
10281042
free(buffer);
10291043

1044+
if (endsWith(dir->d_name, ".mc4-disabled"))
1045+
item->flags |= CHEAT_FLAG_LOCKED;
1046+
10301047
LOG("[%s] F(%d) '%s'", item->title_id, item->flags, item->name);
10311048
list_append(list, item);
10321049
}
@@ -1049,7 +1066,7 @@ static void read_json_games(const char* userPath, list_t *list)
10491066

10501067
while ((dir = readdir(d)) != NULL)
10511068
{
1052-
if (!endsWith(dir->d_name, ".json"))
1069+
if (!endsWith(dir->d_name, ".json") && !endsWith(dir->d_name, ".json-disabled"))
10531070
continue;
10541071

10551072
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)
10821099
cJSON_Delete(cheat);
10831100
free(buffer);
10841101

1102+
if (endsWith(dir->d_name, ".json-disabled"))
1103+
item->flags |= CHEAT_FLAG_LOCKED;
1104+
10851105
LOG("[%s] F(%d) '%s'", item->title_id, item->flags, item->name);
10861106
list_append(list, item);
10871107
}
@@ -1111,26 +1131,6 @@ list_t * ReadUserList(const char* userPath)
11111131

11121132
list = list_alloc();
11131133

1114-
/*
1115-
item = createGameEntry(CHEAT_FLAG_PS4, CHAR_ICON_COPY " Bulk Cheats Management");
1116-
item->type = FILE_TYPE_MENU;
1117-
item->codes = list_alloc();
1118-
item->path = strdup(userPath);
1119-
// item->path = (void*) list; //bulk management hack
1120-
1121-
cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_SIGN " Resign & Unlock all Saves", CMD_RESIGN_ALL_SAVES);
1122-
list_append(item->codes, cmd);
1123-
1124-
cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_COPY " Copy all Saves to USB", CMD_CODE_NULL);
1125-
cmd->options_count = 1;
1126-
cmd->options = _createOptions(2, "Copy Saves to USB", CMD_COPY_SAVES_USB);
1127-
list_append(item->codes, cmd);
1128-
1129-
cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_LOCK " Dump all Save Fingerprints", CMD_DUMP_FINGERPRINTS);
1130-
list_append(item->codes, cmd);
1131-
list_append(list, item);
1132-
*/
1133-
11341134
LOG("Loading JSON files...");
11351135
snprintf(fullPath, sizeof(fullPath), "%sjson/", userPath);
11361136
read_json_games(fullPath, list);
@@ -1251,151 +1251,3 @@ list_t * ReadOnlineList(const char* urlPath)
12511251
check_game_appdb(list);
12521252
return list;
12531253
}
1254-
1255-
int get_save_details(const game_entry_t* save, char **details)
1256-
{
1257-
/*
1258-
char sfoPath[256];
1259-
sqlite3 *db;
1260-
sqlite3_stmt *res;
1261-
1262-
1263-
if (!(save->flags & CHEAT_FLAG_PS4))
1264-
{
1265-
asprintf(details, "%s\n\nTitle: %s\n", save->path, save->name);
1266-
return 1;
1267-
}
1268-
1269-
if (save->flags & CHEAT_FLAG_TROPHY)
1270-
{
1271-
if ((db = open_sqlite_db(save->path)) == NULL)
1272-
return 0;
1273-
1274-
char* query = sqlite3_mprintf("SELECT id, description, trophy_num, unlocked_trophy_num, progress,"
1275-
"platinum_num, unlocked_platinum_num, gold_num, unlocked_gold_num, silver_num, unlocked_silver_num,"
1276-
"bronze_num, unlocked_bronze_num FROM tbl_trophy_title WHERE id = %d", save->blocks);
1277-
1278-
if (sqlite3_prepare_v2(db, query, -1, &res, NULL) != SQLITE_OK || sqlite3_step(res) != SQLITE_ROW)
1279-
{
1280-
LOG("Failed to fetch data: %s", sqlite3_errmsg(db));
1281-
sqlite3_free(query);
1282-
sqlite3_close(db);
1283-
return 0;
1284-
}
1285-
1286-
asprintf(details, "Trophy-Set Details\n\n"
1287-
"Title: %s\n"
1288-
"Description: %s\n"
1289-
"NP Comm ID: %s\n"
1290-
"Progress: %d/%d - %d%%\n"
1291-
"%c Platinum: %d/%d\n"
1292-
"%c Gold: %d/%d\n"
1293-
"%c Silver: %d/%d\n"
1294-
"%c Bronze: %d/%d\n",
1295-
save->name, sqlite3_column_text(res, 1), save->title_id,
1296-
sqlite3_column_int(res, 3), sqlite3_column_int(res, 2), sqlite3_column_int(res, 4),
1297-
CHAR_TRP_PLATINUM, sqlite3_column_int(res, 6), sqlite3_column_int(res, 5),
1298-
CHAR_TRP_GOLD, sqlite3_column_int(res, 8), sqlite3_column_int(res, 7),
1299-
CHAR_TRP_SILVER, sqlite3_column_int(res, 10), sqlite3_column_int(res, 9),
1300-
CHAR_TRP_BRONZE, sqlite3_column_int(res, 12), sqlite3_column_int(res, 11));
1301-
1302-
sqlite3_free(query);
1303-
sqlite3_finalize(res);
1304-
sqlite3_close(db);
1305-
1306-
return 1;
1307-
}
1308-
1309-
if(save->flags & CHEAT_FLAG_LOCKED)
1310-
{
1311-
asprintf(details, "%s\n\n"
1312-
"Title ID: %s\n"
1313-
"Dir Name: %s\n"
1314-
"Blocks: %d\n"
1315-
"Account ID: %.16s\n",
1316-
save->path,
1317-
save->title_id,
1318-
save->version,
1319-
save->blocks,
1320-
save->path + 23);
1321-
1322-
return 1;
1323-
}
1324-
1325-
if(save->flags & CHEAT_FLAG_HDD)
1326-
{
1327-
if ((db = open_sqlite_db(save->path)) == NULL)
1328-
return 0;
1329-
1330-
char* query = sqlite3_mprintf("SELECT sub_title, detail, free_blocks, size_kib, user_id, account_id FROM savedata "
1331-
" WHERE title_id = %Q AND dir_name = %Q", save->title_id, save->version);
1332-
1333-
if (sqlite3_prepare_v2(db, query, -1, &res, NULL) != SQLITE_OK || sqlite3_step(res) != SQLITE_ROW)
1334-
{
1335-
LOG("Failed to fetch data: %s", sqlite3_errmsg(db));
1336-
sqlite3_free(query);
1337-
sqlite3_close(db);
1338-
return 0;
1339-
}
1340-
1341-
asprintf(details, "%s\n\n"
1342-
"Title: %s\n"
1343-
"Subtitle: %s\n"
1344-
"Detail: %s\n"
1345-
"Dir Name: %s\n"
1346-
"Blocks: %d (%d Free)\n"
1347-
"Size: %d Kb\n"
1348-
"User ID: %08x\n"
1349-
"Account ID: %016llx\n",
1350-
save->path, save->name,
1351-
sqlite3_column_text(res, 0),
1352-
sqlite3_column_text(res, 1),
1353-
save->version,
1354-
save->blocks, sqlite3_column_int(res, 2),
1355-
sqlite3_column_int(res, 3),
1356-
sqlite3_column_int(res, 4),
1357-
sqlite3_column_int64(res, 5));
1358-
1359-
sqlite3_free(query);
1360-
sqlite3_finalize(res);
1361-
sqlite3_close(db);
1362-
1363-
return 1;
1364-
}
1365-
1366-
snprintf(sfoPath, sizeof(sfoPath), "%s" "sce_sys/param.sfo", save->path);
1367-
LOG("Save Details :: Reading %s...", sfoPath);
1368-
1369-
sfo_context_t* sfo = sfo_alloc();
1370-
if (sfo_read(sfo, sfoPath) < 0) {
1371-
LOG("Unable to read from '%s'", sfoPath);
1372-
sfo_free(sfo);
1373-
return 0;
1374-
}
1375-
1376-
char* subtitle = (char*) sfo_get_param_value(sfo, "SUBTITLE");
1377-
char* detail = (char*) sfo_get_param_value(sfo, "DETAIL");
1378-
uint64_t* account_id = (uint64_t*) sfo_get_param_value(sfo, "ACCOUNT_ID");
1379-
sfo_params_ids_t* param_ids = (sfo_params_ids_t*) sfo_get_param_value(sfo, "PARAMS");
1380-
1381-
asprintf(details, "%s\n\n"
1382-
"Title: %s\n"
1383-
"Subtitle: %s\n"
1384-
"Detail: %s\n"
1385-
"Dir Name: %s\n"
1386-
"Blocks: %d\n"
1387-
"User ID: %08x\n"
1388-
"Account ID: %016lx\n",
1389-
save->path, save->name,
1390-
subtitle,
1391-
detail,
1392-
save->version,
1393-
save->blocks,
1394-
param_ids->user_id,
1395-
*account_id);
1396-
1397-
sfo_free(sfo);
1398-
*/
1399-
asprintf(details, "%s\n", save->path);
1400-
return 1;
1401-
}

source/exec_cmd.c

+30
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,32 @@ static void togglePatch(const game_entry_t* game, const code_entry_t* code)
4949
show_message("Patch \"%s\" %s", code->name, code->activated ? "Enabled" : "Disabled");
5050
}
5151

52+
static void toggleCheatFile(game_entry_t* game, code_entry_t* code)
53+
{
54+
char file_path[256];
55+
56+
LOG("Toggle cheat file: %s", game->path);
57+
if (game->flags & CHEAT_FLAG_LOCKED)
58+
{
59+
snprintf(file_path, sizeof(file_path), "%s", game->path);
60+
*strrchr(file_path, '-') = 0;
61+
}
62+
else
63+
snprintf(file_path, sizeof(file_path), "%s-disabled", game->path);
64+
65+
if (rename(game->path, file_path) < 0)
66+
{
67+
LOG("Failed to rename cheat file %s", file_path);
68+
return;
69+
}
70+
game->flags ^= CHEAT_FLAG_LOCKED;
71+
free(game->path);
72+
asprintf(&game->path, "%s", file_path);
73+
memcpy(code->name +1, (game->flags & CHEAT_FLAG_LOCKED) ? "Dis" : " En", 3);
74+
75+
show_message("Cheat File %s:\n%s", (game->flags & CHEAT_FLAG_LOCKED) ? "Disabled" : "Enabled", game->path);
76+
}
77+
5278
static void updNetCheats(void)
5379
{
5480
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)
366392
removePlugins();
367393
break;
368394

395+
case CMD_TOGGLE_CHEAT:
396+
toggleCheatFile(selected_entry, code);
397+
return;
398+
369399
case CMD_TOGGLE_PATCH:
370400
togglePatch(selected_entry, code);
371401
return;

source/main.c

+2
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ static int LoadTextures_Menu(void)
200200
load_menu_texture(tag_shn, png);
201201
load_menu_texture(tag_mc4, png);
202202
load_menu_texture(tag_json, png);
203+
load_menu_texture(tag_lock, png);
203204
load_menu_texture(circle_error_dark, png);
204205
load_menu_texture(circle_error_light, png);
205206
load_menu_texture(circle_loading_bg, png);
@@ -303,6 +304,7 @@ static void registerSpecialChars(void)
303304
RegisterSpecialCharacter(CHAR_TAG_MC4, 0, 1.0, &menu_textures[tag_mc4_png_index]);
304305
RegisterSpecialCharacter(CHAR_TAG_SHN, 0, 1.0, &menu_textures[tag_shn_png_index]);
305306
RegisterSpecialCharacter(CHAR_TAG_JSON, 0, 1.0, &menu_textures[tag_json_png_index]);
307+
RegisterSpecialCharacter(CHAR_TAG_LOCKED, 0, 1.0, &menu_textures[tag_lock_png_index]);
306308
}
307309

308310
static void helpFooter(int id)

0 commit comments

Comments
 (0)