From ebb7cc59da3c925681303eb906f4a4a28b47400c Mon Sep 17 00:00:00 2001 From: bucanero Date: Wed, 8 Dec 2021 22:24:11 -0300 Subject: [PATCH] added MsgDialog --- Makefile | 5 +- include/backend.h | 88 ------------------------ include/ttf_render.h | 2 - source/common.c | 34 +++++----- source/dialog.c | 158 ++++++++++++------------------------------- source/menu_cheats.c | 26 ++++--- source/settings.c | 2 +- 7 files changed, 80 insertions(+), 235 deletions(-) delete mode 100644 include/backend.h diff --git a/Makefile b/Makefile index e579a59..62129cf 100644 --- a/Makefile +++ b/Makefile @@ -6,10 +6,11 @@ CONTENT_ID := IV0000-APOL00004_00-APOLLO0000000PS4 # Libraries linked into the ELF. LIBS := -lc -lkernel -lc++ -lSceAudioOut -lSceUserService -lSceVideoOut -lSceGnmDriver -lSceSysmodule -lSceFreeType \ - -lScePad -lSceSystemService -lSceSaveData -lSDL2 -lapollo -ldbglogger -lpolarssl -lz -lzip + -lScePad -lSceSystemService -lSceSaveData -lSceCommonDialog -lSceMsgDialog \ + -lSDL2 -lapollo -ldbglogger -lpolarssl -lz -lzip # Additional compile flags. -EXTRAFLAGS := -DAPOLLO_ENABLE_LOGGING +EXTRAFLAGS := -DAPOLLO_ENABLE_LOGGING -fcolor-diagnostics # Asset and module directories. ASSETS := $(wildcard assets/**/*) diff --git a/include/backend.h b/include/backend.h deleted file mode 100644 index 0aabb7e..0000000 --- a/include/backend.h +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef _PFD__BACKEND_H_ -#define _PFD__BACKEND_H_ - -#include "types.h" -#include "list.h" -#include "pfd.h" - -#define PFDTOOL_VERSION_BASE "0.2.3" -#define PFDTOOL_VERSION PFDTOOL_VERSION_BASE - -#define PFDTOOL_CONFIG_GLOBAL "global.conf" -#define PFDTOOL_CONFIG_GAMES "games.conf" - -#ifdef __cplusplus -extern "C" { -#endif - -#define BACKEND_UPDATE_FLAG_NONE (0) -#define BACKEND_UPDATE_FLAG_PARTIAL (1U << 0) - -#define BACKEND_VALIDATE_FLAG_NONE (0) -#define BACKEND_VALIDATE_FLAG_PARTIAL (1U << 0) - -typedef struct secure_file_id_s { - char file_path[MAX_PATH]; - char file_name[PFD_ENTRY_NAME_SIZE]; - u8 secure_file_id[PFD_PARAM_SFO_KEY_SIZE]; - u8 real_hash[PFD_HASH_SIZE]; - u8 *data; - u64 data_size; - int found; -} secure_file_id_t; - -typedef struct structure_status_s { - int top; - int bottom; -} structure_status_t; - -typedef struct entry_status_s { - int signature; -} entry_status_t; - -typedef struct file_status_s { - char *file_name; - int file; - int cid; - int dhk_cid2; - int aid_uid; -} file_status_t; - -typedef struct entry_info_s { - u64 index; - char *file_name; - u64 file_size; -} entry_info_t; - -typedef struct backend_s { - pfd_config_t *config; - list_t *secure_file_ids; - pfd_context_t *pfd; - - union { - struct { - list_t *entries; - } list; - struct { - structure_status_t structure; - entry_status_t *entries; - file_status_t *files; - } validate; - } storage; -} backend_t; - -backend_t * backend_initialize(pfd_config_t *config, list_t *secure_file_ids, const char *directory_path); -int backend_shutdown(backend_t *ctx); - -int backend_cmd_list(backend_t *ctx); -int backend_cmd_check(backend_t *ctx, u32 options); -int backend_cmd_update(backend_t *ctx, u32 options); -int backend_cmd_encrypt(backend_t *ctx, list_t *file_names); -int backend_cmd_decrypt(backend_t *ctx, list_t *file_names); -int backend_cmd_brute(backend_t *ctx, const char *file_path, u64 file_offset, s64 advance_offset, list_t *secure_file_ids); - -#ifdef __cplusplus -} -#endif - -#endif /* !_PFD__BACKEND_H_ */ diff --git a/include/ttf_render.h b/include/ttf_render.h index dd418fc..0aead49 100644 --- a/include/ttf_render.h +++ b/include/ttf_render.h @@ -1,8 +1,6 @@ #ifndef TTF_RENDER_H #define TTF_RENDER_H -//#include - int TTFLoadFont(int set, const char * path, void * from_memory, int size_from_memory); void TTFUnloadFont(); diff --git a/source/common.c b/source/common.c index fe91c7c..99b1c32 100644 --- a/source/common.c +++ b/source/common.c @@ -36,8 +36,7 @@ int is_char_letter(char c) int file_exists(const char *path) { - struct stat sb; - if ((stat(path, &sb) == 0) && S_ISREG(sb.st_mode)) { + if (access(path, F_OK) == 0) { return SUCCESS; } @@ -47,7 +46,7 @@ int file_exists(const char *path) int dir_exists(const char *path) { struct stat sb; - if ((stat(path, &sb) == 0) && S_ISDIR(sb.st_mode)) { + if ((stat(path, &sb) == 0) && sb.st_mode & S_IFDIR) { return SUCCESS; } return FAILED; @@ -57,9 +56,8 @@ int unlink_secure(const char *path) { if(file_exists(path)==SUCCESS) { -// sysLv2FsChmod(path, S_IFMT | 0777); - return unlink(path); - //return remove(path); + chmod(path, 0777); + return remove(path); } return FAILED; } @@ -105,18 +103,18 @@ int mkdirs(const char* dir) int copy_file(const char* input, const char* output) { - u64 read, written; - s32 fd, fd2; + size_t read, written; + FILE *fd, *fd2; if (mkdirs(output) != SUCCESS) return FAILED; -/* - if(sysLv2FsOpen(input, 0, &fd, SYS_O_RDONLY, NULL, 0) != SUCCESS) + + if((fd = fopen(input, "rb")) == NULL) return FAILED; - if(sysLv2FsOpen(output, SYS_O_WRONLY | SYS_O_CREAT | SYS_O_TRUNC, &fd2, 0777, NULL, 0) != SUCCESS) + if((fd2 = fopen(output, "wb")) == NULL) { - sysLv2FsClose(fd); + fclose(fd); return FAILED; } @@ -127,16 +125,16 @@ int copy_file(const char* input, const char* output) do { - sysLv2FsRead(fd, buffer, TMP_BUFF_SIZE, &read); - sysLv2FsWrite(fd2, buffer, read, &written); + read = fread(buffer, 1, TMP_BUFF_SIZE, fd); + written = fwrite(buffer, 1, read, fd2); } while ((read == written) && (read == TMP_BUFF_SIZE)); free(buffer); - sysLv2FsClose(fd); - sysLv2FsClose(fd2); - sysLv2FsChmod(output, S_IFMT | 0777); -*/ + fclose(fd); + fclose(fd2); + chmod(output, 0777); + return (read - written); } diff --git a/source/dialog.c b/source/dialog.c index bcf54d6..6b2e4a1 100644 --- a/source/dialog.c +++ b/source/dialog.c @@ -1,6 +1,10 @@ #include #include -#include +#include +#include + +#include +#include #define MDIALOG_OK 0 #define MDIALOG_YESNO 1 @@ -8,51 +12,59 @@ void drawDialogBackground(); static float bar1_countparts; -volatile int msg_dialog_action = 0; -/* -void msg_dialog_event(msgButton button, void *userdata) + +static inline void _orbisCommonDialogSetMagicNumber(uint32_t* magic, const OrbisCommonDialogBaseParam* param) +{ + *magic = (uint32_t)(ORBIS_COMMON_DIALOG_MAGIC_NUMBER + (uint64_t)param); +} + +static inline void _orbisCommonDialogBaseParamInit(OrbisCommonDialogBaseParam *param) +{ + memset(param, 0x0, sizeof(OrbisCommonDialogBaseParam)); + param->size = (uint32_t)sizeof(OrbisCommonDialogBaseParam); + _orbisCommonDialogSetMagicNumber(&(param->magic), param); +} + +static inline void orbisMsgDialogParamInitialize(OrbisMsgDialogParam *param) { - switch(button) { - - case MSG_DIALOG_BTN_YES: - msg_dialog_action = 1; - break; - case MSG_DIALOG_BTN_NO: - case MSG_DIALOG_BTN_ESCAPE: - case MSG_DIALOG_BTN_NONE: - msg_dialog_action = 2; - break; - default: - break; - } + memset(param, 0x0, sizeof(OrbisMsgDialogParam)); + _orbisCommonDialogBaseParamInit(¶m->baseParam); + param->size = sizeof(OrbisMsgDialogParam); } -*/ + int show_dialog(int tdialog, const char * format, ...) { -/* - msg_dialog_action = 0; + OrbisMsgDialogParam param; + OrbisMsgDialogUserMessageParam userMsgParam; + OrbisMsgDialogResult result; char str[0x800]; va_list opt; + memset(str, 0, sizeof(str)); va_start(opt, format); vsprintf((void*) str, format, opt); va_end(opt); - msgType mtype = MSG_DIALOG_BKG_INVISIBLE | MSG_DIALOG_NORMAL; - mtype |= (tdialog ? (MSG_DIALOG_BTN_TYPE_YESNO | MSG_DIALOG_DEFAULT_CURSOR_NO) : MSG_DIALOG_BTN_TYPE_OK); + sceMsgDialogInitialize(); + orbisMsgDialogParamInitialize(¶m); + param.mode = ORBIS_MSG_DIALOG_MODE_USER_MSG; - msgDialogOpen2(mtype, str, msg_dialog_event, NULL, NULL); + memset(&userMsgParam, 0, sizeof(userMsgParam)); + userMsgParam.msg = str; + userMsgParam.buttonType = (tdialog ? ORBIS_MSG_DIALOG_BUTTON_TYPE_YESNO_FOCUS_NO : ORBIS_MSG_DIALOG_BUTTON_TYPE_OK); + param.userMsgParam = &userMsgParam; - while(!msg_dialog_action) - { - drawDialogBackground(); - } - msgDialogAbort(); - usleep(100 *1000); + if (sceMsgDialogOpen(¶m) < 0) + return 0; + + do { } while (sceMsgDialogUpdateStatus() != ORBIS_COMMON_DIALOG_STATUS_FINISHED); + sceMsgDialogClose(); - return (msg_dialog_action == 1); -*/ - return 0; + memset(&result, 0, sizeof(result)); + sceMsgDialogGetResult(&result); + sceMsgDialogTerminate(); + + return (result.buttonId == 1); } /* @@ -89,86 +101,4 @@ void update_progress_bar(uint64_t* progress, const uint64_t total_size, const ch drawDialogBackground(); } -/ * -#define TOTAL_OPT 3 - -void Xmsg_dialog_event(msgButton button, void *userdata) -{ - uint32_t* bits = (uint32_t*) userdata; - - switch(button) { - - case MSG_DIALOG_BTN_YES: - *bits |= (1 << 31); - *bits ^= (1 << msg_dialog_action); - - if (msg_dialog_action == TOTAL_OPT) - msg_dialog_action = -msg_dialog_action; - break; - - case MSG_DIALOG_BTN_NO: - case MSG_DIALOG_BTN_ESCAPE: - case MSG_DIALOG_BTN_NONE: - *bits |= (1 << 31); - msg_dialog_action++; - - if (msg_dialog_action > TOTAL_OPT) - msg_dialog_action = 1; - break; - - default: - break; - } -} - -#include -//#include - -int Xshow_dialog() -{ - uint32_t enabled = 0; - char str[1024]; - const char text_options[4][32] = { - "--- MENU ---", - "Option 1", - "Option 2", - "Exit", - }; - - msg_dialog_action = 1; - msgType mtype = MSG_DIALOG_BKG_INVISIBLE | MSG_DIALOG_NORMAL | MSG_DIALOG_BTN_TYPE_OK; - - while(msg_dialog_action >= 0) - { - strcpy(str, text_options[0]); - strcat(str, "\n\n"); - - for (int i = 1; i <= TOTAL_OPT; i++) - { - strcat(str, (i == msg_dialog_action) ? "> " : " "); - strcat(str, text_options[i]); - - if (i < TOTAL_OPT) - strcat(str, (enabled & (1 << i)) ? ": ON" : ": OFF"); - - if (i == msg_dialog_action) - strcat(str, " <"); - - strcat(str, "\n"); - } - - msgDialogOpen2(mtype, str, Xmsg_dialog_event, &enabled, NULL); - - while (!(enabled & (1 << 31))) - { - drawDialogBackground(); - } - - enabled ^= (1 << 31); - } - msgDialogAbort(); - usleep(100 *1000); - - return (msg_dialog_action == 1); -} */ \ No newline at end of file diff --git a/source/menu_cheats.c b/source/menu_cheats.c index 7a37f23..820461e 100644 --- a/source/menu_cheats.c +++ b/source/menu_cheats.c @@ -59,7 +59,7 @@ void DrawOptions(option_entry_t* option, u8 alpha, int y_inc, int selIndex) int startDrawX = selIndex - (maxPerPage / 2); int max = maxPerPage + startDrawX; - SetFontSize(y_inc-6, y_inc-4); + SetFontSize(APP_FONT_SIZE_SELECTION); for (c = startDrawX; c < max; c++) { @@ -182,8 +182,8 @@ int DrawCodes(code_entry_t* code, u8 alpha, int y_inc, int xOff, int selIndex) if (!code->name || !code->codes) return 0; - int numOfLines = 0, c = 0, yOff = 80, cIndex = 0; - int maxPerPage = (SCREEN_HEIGHT - (yOff * 2)) / y_inc; + int numOfLines = 0, c = 0, yOff = 120, cIndex = 0; + int maxPerPage = (SCREEN_HEIGHT - (yOff * 2) - 30) / y_inc; int startDrawX = selIndex - (maxPerPage / 2); int max = maxPerPage + startDrawX; int len = strlen(code->codes); @@ -213,12 +213,12 @@ int DrawCodes(code_entry_t* code, u8 alpha, int y_inc, int xOff, int selIndex) lines[c] = (char*)(&splitCodes[cIndex + 1]); } - SetFontSize(y_inc-6, y_inc-4); + SetFontSize(APP_FONT_SIZE_SELECTION); //SetCurrentFont(font_comfortaa_regular); //SetExtraSpace(0); - if (code->file) - DrawFormatString(xOff + MENU_ICON_OFF + 20, 434, "Target File: %s", code->file); + if (code->file && (code->type == PATCH_BSD || code->type == PATCH_GAMEGENIE)) + DrawFormatString(xOff + MENU_ICON_OFF + 20, 585, "Target File: %s", code->file); for (c = startDrawX; c < max; c++) { @@ -347,8 +347,8 @@ void DrawGameList(int selIndex, list_t * games, u8 alpha) list_node_t *node; save_entry_t *item; char tmp[4] = " "; - int game_y = 160, y_inc = 20; - int maxPerPage = (SCREEN_HEIGHT - (game_y * 2)) / y_inc; + int game_y = 120, y_inc = 20; + int maxPerPage = (SCREEN_HEIGHT - (game_y * 2) - 30) / y_inc; int x = selIndex - (maxPerPage / 2); int max = maxPerPage + selIndex; @@ -388,6 +388,7 @@ void DrawGameList(int selIndex, list_t * games, u8 alpha) if (item->flags & SAVE_FLAG_PS2) tmp[0] = CHAR_TAG_PS2; if (item->flags & SAVE_FLAG_PSP) tmp[0] = CHAR_TAG_PSP; if (item->flags & SAVE_FLAG_PS3) tmp[0] = CHAR_TAG_PS3; + if (item->flags & SAVE_FLAG_PS4) tmp[0] = CHAR_TAG_PS4; tmp[1] = (item->flags & SAVE_FLAG_OWNER) ? CHAR_TAG_OWNER : ' '; tmp[2] = (item->flags & SAVE_FLAG_LOCKED) ? CHAR_TAG_LOCKED : ' '; if (item->flags & SAVE_FLAG_PSV) tmp[1] = CHAR_TAG_PSV; @@ -418,8 +419,8 @@ void DrawCheatsList(int selIndex, save_entry_t* game, u8 alpha) list_node_t *node; code_entry_t *code; - int game_y = 80, y_inc = 20; - int maxPerPage = (SCREEN_HEIGHT - (game_y * 2)) / y_inc; + int game_y = 120, y_inc = 20; + int maxPerPage = (SCREEN_HEIGHT - (game_y * 2) - 30) / y_inc; int x = selIndex - (maxPerPage / 2); int max = maxPerPage + selIndex; @@ -440,6 +441,10 @@ void DrawCheatsList(int selIndex, save_entry_t* game, u8 alpha) code = list_get(node); //u32 color = game.codes[x].activated ? 0x4040C000 : 0x00000000; u8 a = (u8)((alpha * CalculateAlphaList(x, selIndex, maxPerPage)) / 0xFF); + + if (!a) + goto skip_code; + SetFontColor(APP_FONT_COLOR | a, 0); //printf ("Drawing code name %d\n", x); float dx = DrawString(MENU_ICON_OFF + (MENU_TITLE_OFF * 3) - xo, game_y, code->name); @@ -480,6 +485,7 @@ void DrawCheatsList(int selIndex, save_entry_t* game, u8 alpha) } } } +skip_code: node = list_next(node); } diff --git a/source/settings.c b/source/settings.c index 1a7494b..4df243e 100644 --- a/source/settings.c +++ b/source/settings.c @@ -150,7 +150,7 @@ if(1) char *buffer; long size = 0; - buffer = readFile(APOLLO_LOCAL_CACHE "ver.check", &size); + buffer = readTextFile(APOLLO_LOCAL_CACHE "ver.check", &size); if (!buffer) return;