Skip to content

Commit

Permalink
add ps1 commands
Browse files Browse the repository at this point in the history
  • Loading branch information
bucanero committed Oct 26, 2024
1 parent ea8030b commit e1cfd81
Show file tree
Hide file tree
Showing 5 changed files with 337 additions and 12 deletions.
21 changes: 17 additions & 4 deletions include/saves.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#define EXP_PSV_PATH_USB1 USB1_PATH PSV_SAVES_PATH_USB

#define VMC_PS2_PATH_USB "PS2/VMC/"
#define VMC_PS2_PATH_HDD "/dev_hdd0/savedata/vmc/"
#define VMC_PS1_PATH_USB "PS1/VMC/"

#define IMP_PS2VMC_PATH_USB USB_PATH "PS2/VMC/"
#define IMPORT_RAP_PATH_USB USB_PATH PS3_LICENSE_PATH
Expand Down Expand Up @@ -115,8 +115,11 @@ enum cmd_code_enum
// Export commands
CMD_EXP_KEYSTONE,
CMD_EXP_PS2_VM2,
CMD_EXP_PS2_RAW,
CMD_EXP_VMC2SAVE,
CMD_EXP_VM2_RAW,
CMD_EXP_VMC1SAVE,
CMD_EXP_PS1_VMP,
CMD_EXP_PS1_VM1,
CMD_EXP_DATABASE,
CMD_DB_REBUILD,
CMD_DB_DEL_FIX,
Expand All @@ -126,6 +129,7 @@ enum cmd_code_enum
CMD_IMP_KEYSTONE,
CMD_IMP_DATABASE,
CMD_IMP_VMC2SAVE,
CMD_IMP_VMC1SAVE,
CMD_CREATE_ACT_DAT,
CMD_EXTRACT_ARCHIVE,
CMD_URL_DOWNLOAD,
Expand Down Expand Up @@ -159,11 +163,15 @@ enum save_type_enum
FILE_TYPE_NULL,
FILE_TYPE_MENU,
FILE_TYPE_PS4,
FILE_TYPE_PSV,
FILE_TYPE_TRP,
FILE_TYPE_VMC,

// PS1 File Types
FILE_TYPE_PS1,
FILE_TYPE_PSX,
FILE_TYPE_MCS,

// Misc
FILE_TYPE_ZIP,
FILE_TYPE_SQL,
FILE_TYPE_NET,
Expand All @@ -179,7 +187,7 @@ enum save_type_enum
FILE_TYPE_MAX,
FILE_TYPE_CBS,
FILE_TYPE_XPS,
FILE_TYPE_VM2,
FILE_TYPE_PSV,
};

enum char_flag_enum
Expand Down Expand Up @@ -259,6 +267,7 @@ list_t * ReadUserList(const char* userPath);
list_t * ReadOnlineList(const char* urlPath);
list_t * ReadBackupList(const char* userPath);
list_t * ReadTrophyList(const char* userPath);
list_t * ReadVmc1List(const char* userPath);
list_t * ReadVmc2List(const char* userPath);
void UnloadGameList(list_t * list);
char * readTextFile(const char * path, long* size);
Expand All @@ -270,6 +279,7 @@ int ReadCodes(save_entry_t * save);
int ReadTrophies(save_entry_t * game);
int ReadOnlineSaves(save_entry_t * game);
int ReadBackupCodes(save_entry_t * bup);
int ReadVmc1Codes(save_entry_t * save);
int ReadVmc2Codes(save_entry_t * save);

int http_init(void);
Expand Down Expand Up @@ -319,5 +329,8 @@ int ps2_xps2psv(const char *save, const char *psv_path);
int ps2_cbs2psv(const char *save, const char *psv_path);
int ps2_max2psv(const char *save, const char *psv_path);

int psv_resign(const char *src_psv);
int vmp_resign(const char *src_vmp);

char* sjis2utf8(char* input);
uint8_t* getIconPS2(const char* folder, const char* iconfile);
46 changes: 42 additions & 4 deletions source/exec_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "util.h"
#include "sfo.h"
#include "mcio.h"
#include "ps1card.h"

static char host_buf[256];

Expand Down Expand Up @@ -760,8 +761,8 @@ static void exportAllSavesVMC(const save_entry_t* save, int dev, int all)
if (!all && !(item->flags & SAVE_FLAG_SELECTED))
continue;

// if (item->type == FILE_TYPE_PS1)
// (saveSingleSave(outPath, save->dir_name[0], PS1SAVE_PSV) ? done++ : err_count++);
if (item->type == FILE_TYPE_PS1)
(saveSingleSave(outPath, save->dir_name[0], PS1SAVE_PSV) ? done++ : err_count++);

if (item->type == FILE_TYPE_PS2)
(vmc_export_psv(item->dir_name, outPath) ? done++ : err_count++);
Expand All @@ -772,6 +773,28 @@ static void exportAllSavesVMC(const save_entry_t* save, int dev, int all)
show_message("%d/%d Saves exported to\n%s", done, done+err_count, outPath);
}

static void exportVmcSave(const save_entry_t* save, int type, int dst_id)
{
char outPath[256];
struct tm t;

_set_dest_path(outPath, dst_id, (type == PS1SAVE_PSV) ? PSV_SAVES_PATH_USB : PS1_IMP_PATH_USB);
mkdirs(outPath);
if (type != PS1SAVE_PSV)
{
// build file path
gmtime_r(&(time_t){time(NULL)}, &t);
sprintf(strrchr(outPath, '/'), "/%s_%d-%02d-%02d_%02d%02d%02d.%s", save->title_id,
t.tm_year+1900, t.tm_mon+1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec,
(type == PS1SAVE_MCS) ? "mcs" : "psx");
}

if (saveSingleSave(outPath, save->dir_name[0], type))
show_message("Save successfully exported to:\n%s", outPath);
else
show_message("Error exporting save:\n%s", save->path);
}

static void export_vmc2save(const save_entry_t* save, int type, int dst_id)
{
int ret = 0;
Expand Down Expand Up @@ -851,7 +874,7 @@ static void deleteVmcSave(const save_entry_t* save)
if (!show_dialog(DIALOG_TYPE_YESNO, "Do you want to delete %s?", save->dir_name))
return;

if ((save->flags & SAVE_FLAG_PS1) ? /*formatSave(save->dir_name[0])*/0 : vmc_delete_save(save->dir_name))
if ((save->flags & SAVE_FLAG_PS1) ? formatSave(save->dir_name[0]) : vmc_delete_save(save->dir_name))
show_message("Save successfully deleted:\n%s", save->dir_name);
else
show_message("Error! Couldn't delete save:\n%s", save->dir_name);
Expand Down Expand Up @@ -1444,11 +1467,26 @@ void execCodeCommand(code_entry_t* code, const char* codecmd)
break;

case CMD_EXP_PS2_VM2:
case CMD_EXP_VM2_RAW:
case CMD_EXP_PS2_RAW:
exportVM2raw(code->file, codecmd[1], codecmd[0] == CMD_EXP_PS2_VM2);
code->activated = 0;
break;

case CMD_EXP_VMC1SAVE:
exportVmcSave(selected_entry, code->options[0].id, codecmd[1]);
code->activated = 0;
break;

case CMD_IMP_VMC1SAVE:
if (openSingleSave(code->file, (int*) host_buf))
show_message("Save successfully imported:\n%s", code->file);
else
show_message("Error! Couldn't import save:\n%s", code->file);

selected_entry->flags |= SAVE_FLAG_UPDATED;
code->activated = 0;
break;

default:
break;
}
Expand Down
13 changes: 13 additions & 0 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ save_list_t user_backup = {
.UpdatePath = NULL,
};

/*
* PS1 VMC list
*/
save_list_t vmc1_saves = {
.icon_id = cat_usb_png_index,
.title = "PS1 Virtual Memory Card",
.list = NULL,
.path = "",
.ReadList = &ReadVmc1List,
.ReadCodes = &ReadVmc1Codes,
.UpdatePath = &update_vmc_path,
};

/*
* PS2 VMC list
*/
Expand Down
35 changes: 33 additions & 2 deletions source/menu_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
#include "ttf_render.h"
#include "common.h"
#include "mcio.h"
#include "ps1card.h"

extern save_list_t hdd_saves;
extern save_list_t usb_saves;
extern save_list_t trophies;
extern save_list_t online_saves;
extern save_list_t user_backup;
extern save_list_t vmc1_saves;
extern save_list_t vmc2_saves;

extern int close_app;
Expand Down Expand Up @@ -113,6 +115,14 @@ static void SetMenu(int id)
{
switch (menu_id) //Leaving menu
{
case MENU_PS1VMC_SAVES:
if (id == MENU_MAIN_SCREEN)
{
UnloadGameList(vmc1_saves.list);
vmc1_saves.list = NULL;
}
break;

case MENU_PS2VMC_SAVES:
if (id == MENU_MAIN_SCREEN)
{
Expand Down Expand Up @@ -150,6 +160,12 @@ static void SetMenu(int id)
selected_entry->flags ^= SAVE_FLAG_UPDATED;
ReloadUserSaves(&vmc2_saves);
}
else if (selected_entry->flags & SAVE_FLAG_UPDATED && id == MENU_PS1VMC_SAVES)
{
selected_entry->flags ^= SAVE_FLAG_UPDATED;
saveMemoryCard(vmc1_saves.path, 0, 0);
ReloadUserSaves(&vmc1_saves);
}
break;

case MENU_SAVE_DETAILS:
Expand Down Expand Up @@ -209,6 +225,14 @@ static void SetMenu(int id)
Draw_UserCheatsMenu_Ani(&online_saves);
break;

case MENU_PS1VMC_SAVES: //VMC Menu
if (!vmc1_saves.list && !ReloadUserSaves(&vmc1_saves))
return;

if (apollo_config.doAni)
Draw_UserCheatsMenu_Ani(&vmc1_saves);
break;

case MENU_PS2VMC_SAVES: //Trophies Menu
if (!vmc2_saves.list && !ReloadUserSaves(&vmc2_saves))
return;
Expand Down Expand Up @@ -238,7 +262,7 @@ static void SetMenu(int id)
case MENU_PATCHES: //Cheat Selection Menu
//if entering from game list, don't keep index, otherwise keep
if (menu_id == MENU_USB_SAVES || menu_id == MENU_HDD_SAVES || menu_id == MENU_ONLINE_DB ||
menu_id == MENU_TROPHIES || menu_id == MENU_PS2VMC_SAVES)
menu_id == MENU_TROPHIES || menu_id == MENU_PS1VMC_SAVES || menu_id == MENU_PS2VMC_SAVES)
menu_old_sel[MENU_PATCHES] = 0;

char iconfile[256];
Expand All @@ -255,6 +279,9 @@ static void SetMenu(int id)
else if (selected_entry->flags & SAVE_FLAG_VMC && selected_entry->type == FILE_TYPE_PS2)
LoadVmcTexture(128, 128, getIconPS2(selected_entry->dir_name, strrchr(selected_entry->path, '\n')+1));

else if (selected_entry->flags & SAVE_FLAG_VMC && selected_entry->type == FILE_TYPE_PS1)
LoadVmcTexture(16, 16, getIconRGBA(selected_entry->dir_name[0], 0));

else if (selected_entry->flags & SAVE_FLAG_HDD)
snprintf(iconfile, sizeof(iconfile), PS4_SAVES_PATH_HDD "%s/%s_icon0.png", apollo_config.user_id, selected_entry->title_id, selected_entry->dir_name);

Expand Down Expand Up @@ -381,7 +408,7 @@ static void doSaveMenu(save_list_t * save_list)

if (selected_entry->flags & SAVE_FLAG_PS1)
{
// strncpy(vmc1_saves.path, selected_entry->path, sizeof(vmc1_saves.path));
strncpy(vmc1_saves.path, selected_entry->path, sizeof(vmc1_saves.path));
SetMenu(MENU_PS1VMC_SAVES);
}
else
Expand Down Expand Up @@ -865,6 +892,10 @@ void drawScene(void)
doHexEditor();
break;

case MENU_PS1VMC_SAVES: //PS1 VMC Menu
doSaveMenu(&vmc1_saves);
break;

case MENU_PS2VMC_SAVES: //PS2 VMC Menu
doSaveMenu(&vmc2_saves);
break;
Expand Down
Loading

0 comments on commit e1cfd81

Please sign in to comment.