Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
remove vmc saves
import vmc saves from usb/hdd
vmc save details
  • Loading branch information
bucanero committed Apr 8, 2024
1 parent 219d9a3 commit 06b2fe0
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 85 deletions.
2 changes: 1 addition & 1 deletion include/ps1card.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ uint8_t* getSaveBytes(int slotNumber, uint32_t* saveLen);
void toggleDeleteSave(int slotNumber);

//Format save
void formatSave(int slotNumber);
int formatSave(int slotNumber);

//Get Memory Card data
ps1mcData_t* getMemoryCardData(void);
14 changes: 8 additions & 6 deletions include/saves.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ enum cmd_code_enum
CMD_COPY_DUMMY_PSV,
CMD_IMPORT_DATA_FILE,
CMD_HEX_EDIT_FILE,
CMD_DELETE_VMCSAVE,

// Bulk commands
CMD_RESIGN_SAVES,
Expand All @@ -105,10 +106,8 @@ enum cmd_code_enum
CMD_COPY_ALL_SAVES_HDD,
CMD_SAVE_WEB_SERVER,
CMD_RESIGN_VMP,
CMD_EXP_SAVES_VMC1,
CMD_EXP_ALL_SAVES_VMC1,
CMD_EXP_SAVES_VMC2,
CMD_EXP_ALL_SAVES_VMC2,
CMD_EXP_SAVES_VMC,
CMD_EXP_ALL_SAVES_VMC,

// Export commands
CMD_EXP_EXDATA_USB,
Expand Down Expand Up @@ -156,11 +155,13 @@ enum cmd_code_enum
#define SAVE_FLAG_ONLINE 256
#define SAVE_FLAG_SELECTED 512
#define SAVE_FLAG_VMC 1024
#define SAVE_FLAG_UPDATED 2048

enum save_type_enum
{
FILE_TYPE_NULL,
FILE_TYPE_MENU,
FILE_TYPE_PS3,
FILE_TYPE_PSV,
FILE_TYPE_TRP,
FILE_TYPE_VMC,
Expand Down Expand Up @@ -204,10 +205,10 @@ enum char_flag_enum
CHAR_TAG_LOCKED,
CHAR_TAG_NET,
CHAR_RES_LF,
CHAR_TAG_TRANSFER,
CHAR_TAG_VMC,
CHAR_TAG_ZIP,
CHAR_RES_CR,
CHAR_TAG_VMC,
CHAR_TAG_TRANSFER,
CHAR_TAG_WARNING,
CHAR_BTN_X,
CHAR_BTN_S,
Expand Down Expand Up @@ -335,6 +336,7 @@ int vmc_export_psv(const char* save, const char* out_path);
int vmc_export_psu(const char* path, const char* output);
int vmc_import_psv(const char *input);
int vmc_import_psu(const char *input);
int vmc_delete_save(const char* path);

char* sjis2utf8(char* input);
uint8_t* getIconPS2(const char* folder, const char* iconfile);
49 changes: 31 additions & 18 deletions source/exec_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ static void exportAllSavesVMC(const save_entry_t* save, int dev, int all)
continue;

if (item->type == FILE_TYPE_PS1)
(saveSingleSave(outPath, save->path[strlen(save->path)+1], PS1SAVE_PSV) ? done++ : err_count++);
(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 @@ -695,7 +695,7 @@ 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, PS1_IMP_PATH_USB);
_set_dest_path(outPath, dst_id, (type == PS1SAVE_PSV) ? PSV_SAVES_PATH_USB : PS1_IMP_PATH_USB);
mkdirs(outPath);
if (type != PS1SAVE_PSV)
{
Expand All @@ -706,7 +706,7 @@ static void exportVmcSave(const save_entry_t* save, int type, int dst_id)
(type == PS1SAVE_MCS) ? "mcs" : "psx");
}

if (saveSingleSave(outPath, save->path[strlen(save->path)+1], type))
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);
Expand Down Expand Up @@ -1543,16 +1543,27 @@ static void downloadLink(const char* path)
show_message("Error! File couldn't be downloaded");
}

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]) : 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);
}

static void import_mcr2vmp(const save_entry_t* save, const char* src)
{
char mcrPath[256];
uint8_t *data = NULL;
size_t size = 0;

snprintf(mcrPath, sizeof(mcrPath), VMC_PS2_PATH_HDD "%s/%s", save->title_id, src);
snprintf(mcrPath, sizeof(mcrPath), "%s%s", VMC_PS2_PATH_HDD, src);
read_buffer(mcrPath, &data, &size);

if (openMemoryCardStream(data, size, 0) && saveMemoryCard(save->path, 0, 0))
if (openMemoryCardStream(data, size, 0))
show_message("Memory card successfully imported to:\n%s", save->path);
else
show_message("Error importing memory card:\n%s", mcrPath);
Expand All @@ -1562,8 +1573,8 @@ static void export_vmp2mcr(const save_entry_t* save)
{
char mcrPath[256];

snprintf(mcrPath, sizeof(mcrPath), VMC_PS2_PATH_HDD "%s/%s", save->title_id, strrchr(save->path, '/') + 1);
strcpy(strrchr(mcrPath, '.'), ".MCR");
snprintf(mcrPath, sizeof(mcrPath), "%s%s", VMC_PS2_PATH_HDD, strrchr(save->path, '/') + 1);
strcpy(strrchr(mcrPath, '.'), ".VM1");
mkdirs(mcrPath);

if (saveMemoryCard(mcrPath, PS1CARD_RAW, 0))
Expand Down Expand Up @@ -1802,9 +1813,9 @@ void execCodeCommand(code_entry_t* code, const char* codecmd)
code->activated = 0;
break;

case CMD_EXP_SAVES_VMC1:
case CMD_EXP_ALL_SAVES_VMC1:
exportAllSavesVMC(selected_entry, codecmd[1], codecmd[0] == CMD_EXP_ALL_SAVES_VMC1);
case CMD_EXP_SAVES_VMC:
case CMD_EXP_ALL_SAVES_VMC:
exportAllSavesVMC(selected_entry, codecmd[1], codecmd[0] == CMD_EXP_ALL_SAVES_VMC);
code->activated = 0;
break;

Expand All @@ -1815,18 +1826,11 @@ void execCodeCommand(code_entry_t* code, const char* codecmd)

case CMD_IMP_VMC1SAVE:
if (openSingleSave(code->file, (int*) host_buf))
{
saveMemoryCard(selected_entry->dir_name, 0, 0);
show_message("Save successfully imported:\n%s", code->file);
}
else
show_message("Error! Couldn't import save:\n%s", code->file);
code->activated = 0;
break;

case CMD_EXP_SAVES_VMC2:
case CMD_EXP_ALL_SAVES_VMC2:
exportAllSavesVMC(selected_entry, codecmd[1], codecmd[0] == CMD_EXP_ALL_SAVES_VMC2);
selected_entry->flags |= SAVE_FLAG_UPDATED;
code->activated = 0;
break;

Expand All @@ -1837,16 +1841,25 @@ void execCodeCommand(code_entry_t* code, const char* codecmd)

case CMD_IMP_VMC2SAVE:
import_save2vmc(code->file, codecmd[1]);
selected_entry->flags |= SAVE_FLAG_UPDATED;
code->activated = 0;
break;

case CMD_IMP_MCR2VMP:
import_mcr2vmp(selected_entry, code->options[0].name[code->options[0].sel]);
selected_entry->flags |= SAVE_FLAG_UPDATED;
code->activated = 0;
break;

case CMD_IMP_PS2VMC_USB:
importPS2VMC(selected_entry->path, code->file);
selected_entry->flags |= SAVE_FLAG_UPDATED;
code->activated = 0;
break;

case CMD_DELETE_VMCSAVE:
deleteVmcSave(selected_entry);
selected_entry->flags |= SAVE_FLAG_UPDATED;
code->activated = 0;
break;

Expand Down
7 changes: 3 additions & 4 deletions source/mcio.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static const char SUPERBLOCK_MAGIC[] = "Sony PS2 Memory Card Format ";
static const char SUPERBLOCK_VERSION[] = "1.2.0.0\0\0\0\0";

static FILE *vmc_fp = NULL;
static char vmcpath[256];
static char vmcpath[256] = "";

struct MCDevInfo { /* size = 384 */
uint8_t magic[28]; /* Superblock magic, on PS2 MC : "Sony PS2 Memory Card Format " */
Expand Down Expand Up @@ -2980,10 +2980,8 @@ static int Card_FileWrite(int fd, void *buffer, int nbyte)
int mcio_vmcInit(const char* vmc)
{
int r;
vmcpath[0] = 0;

if (vmc_fp)
fclose(vmc_fp);
mcio_vmcFinish();

// decrypt ps2classic format
if (strcmp(".VME", strrchr(vmc, '.')) == 0)
Expand Down Expand Up @@ -3022,6 +3020,7 @@ void mcio_vmcFinish(void)
unlink_secure(vmcpath);
}

vmcpath[0] = 0;
vmc_fp = NULL;
}

Expand Down
84 changes: 67 additions & 17 deletions source/menu_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,59 @@ static code_entry_t* LoadRawPatch(void)
return centry;
}

static code_entry_t* LoadSaveDetails(void)
static code_entry_t* LoadSaveDetails(const save_entry_t* save)
{
char sfoPath[256];
code_entry_t* centry = calloc(1, sizeof(code_entry_t));

centry->name = strdup(selected_entry->title_id);
centry->name = strdup(save->title_id);

if(save->type == FILE_TYPE_PS1)
{
asprintf(&centry->codes, "%s\n\n----- PS1 Save -----\n"
"Game: %s\n"
"Title ID: %s\n"
"File: %s\n",
save->path,
save->name,
save->title_id,
save->dir_name+1);
return(centry);
}

if(save->type == FILE_TYPE_PS2)
{
asprintf(&centry->codes, "%s\n\n----- PS2 Save -----\n"
"Game: %s\n"
"Title ID: %s\n"
"Folder: %s\n"
"Icon: %s\n",
save->path,
save->name,
save->title_id,
save->dir_name,
strrchr(save->path, '\n')+1);
return(centry);
}

if (!(selected_entry->flags & SAVE_FLAG_PS3))
if(save->type == FILE_TYPE_VMC)
{
asprintf(&centry->codes, "%s\n\nTitle: %s\n", selected_entry->path, selected_entry->name);
asprintf(&centry->codes, "%s\n\n----- Virtual Memory Card -----\n"
"File: %s\n"
"Folder: %s\n",
save->path,
strrchr(save->path, '/')+1,
save->dir_name);
return(centry);
}

snprintf(sfoPath, sizeof(sfoPath), "%s" "PARAM.SFO", selected_entry->path);
if (!(save->flags & SAVE_FLAG_PS3))
{
asprintf(&centry->codes, "%s\n\nTitle: %s\n", save->path, save->name);
return(centry);
}

snprintf(sfoPath, sizeof(sfoPath), "%s" "PARAM.SFO", save->path);
LOG("Save Details :: Reading %s...", sfoPath);

sfo_context_t* sfo = sfo_alloc();
Expand All @@ -148,13 +187,13 @@ static code_entry_t* LoadSaveDetails(void)
return centry;
}

if (selected_entry->flags & SAVE_FLAG_TROPHY)
if (save->flags & SAVE_FLAG_TROPHY)
{
char* account = (char*) sfo_get_param_value(sfo, "ACCOUNTID");
asprintf(&centry->codes, "%s\n\n"
"Title: %s\n"
"NP Comm ID: %s\n"
"Account ID: %.16s\n", selected_entry->path, selected_entry->name, selected_entry->title_id, account);
"Account ID: %.16s\n", save->path, save->name, save->title_id, account);
LOG(centry->codes);

sfo_free(sfo);
Expand All @@ -172,11 +211,11 @@ static code_entry_t* LoadSaveDetails(void)
"Lock: %s\n\n"
"User ID: %08d\n"
"Account ID: %.16s (%s)\n"
"PSID: %016lX %016lX\n", selected_entry->path, selected_entry->name, subtitle,
selected_entry->dir_name,
(selected_entry->flags & SAVE_FLAG_LOCKED ? "Copying Prohibited" : "Unlocked"),
"PSID: %016lX %016lX\n", save->path, save->name, subtitle,
save->dir_name,
(save->flags & SAVE_FLAG_LOCKED ? "Copying Prohibited" : "Unlocked"),
param_ids->user_id, param_ids->account_id,
(selected_entry->flags & SAVE_FLAG_OWNER ? "Owner" : "Not Owner"),
(save->flags & SAVE_FLAG_OWNER ? "Owner" : "Not Owner"),
param_ids->psid[0], param_ids->psid[1]);
LOG(centry->codes);

Expand All @@ -191,11 +230,8 @@ static void SetMenu(int id)
case MENU_PS1VMC_SAVES:
if (id == MENU_MAIN_SCREEN)
{
init_loading_screen("Saving PS1 Memory Card...");
UnloadGameList(vmc1_saves.list);
vmc1_saves.list = NULL;
saveMemoryCard(vmc1_saves.path, 0, 0);
stop_loading_screen();
}
break;

Expand All @@ -221,7 +257,21 @@ static void SetMenu(int id)

case MENU_SETTINGS: //Options Menu
case MENU_CREDITS: //About Menu
break;

case MENU_PATCHES: //Cheat Selection Menu
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);
}

else if (selected_entry->flags & SAVE_FLAG_UPDATED && id == MENU_PS2VMC_SAVES)
{
selected_entry->flags ^= SAVE_FLAG_UPDATED;
ReloadUserSaves(&vmc2_saves);
}
break;

case MENU_SAVE_DETAILS:
Expand Down Expand Up @@ -334,7 +384,7 @@ static void SetMenu(int id)
}

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

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));
Expand Down Expand Up @@ -480,7 +530,7 @@ static void doSaveMenu(save_list_t * save_list)
selected_entry = list_get_item(save_list->list, menu_sel);
if (selected_entry->type != FILE_TYPE_MENU)
{
selected_centry = LoadSaveDetails();
selected_centry = LoadSaveDetails(selected_entry);
SetMenu(MENU_SAVE_DETAILS);
return;
}
Expand Down Expand Up @@ -877,7 +927,7 @@ static void doPatchMenu(void)
if (selected_centry->codes[0] == CMD_VIEW_DETAILS)
{
selected_centry->activated = 0;
selected_centry = LoadSaveDetails();
selected_centry = LoadSaveDetails(selected_entry);
SetMenu(MENU_SAVE_DETAILS);
return;
}
Expand Down
Loading

0 comments on commit 06b2fe0

Please sign in to comment.