Skip to content

Commit

Permalink
ps1 vmc management
Browse files Browse the repository at this point in the history
fix #143
  • Loading branch information
bucanero committed Mar 10, 2024
1 parent 2e940fa commit 6117e22
Show file tree
Hide file tree
Showing 12 changed files with 477 additions and 30 deletions.
4 changes: 3 additions & 1 deletion include/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ enum menu_screen_ids
MENU_CODE_OPTIONS, /* 10 - Code Menu (View Cheat Options) */
MENU_SAVE_DETAILS,
MENU_HEX_EDITOR,
MENU_PS1VMC_SAVES, /* 13 - PS1 VMC Menu */
MENU_PS2VMC_SAVES, /* 14 - PS2 VMC Menu */
TOTAL_MENU_IDS
};

Expand Down Expand Up @@ -64,7 +66,7 @@ enum texture_index
cat_warning_png_index,
tag_lock_png_index,
tag_own_png_index,
tag_pce_png_index,
tag_vmc_png_index,
tag_ps1_png_index,
tag_ps2_png_index,
tag_ps3_png_index,
Expand Down
19 changes: 17 additions & 2 deletions include/saves.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#define EXPORT_RAP_PATH_USB USB_PATH PS3_LICENSE_PATH
#define EXPORT_RAP_PATH_HDD "/dev_hdd0/" PS3_LICENSE_PATH

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

Expand Down Expand Up @@ -105,6 +106,9 @@ enum cmd_code_enum
CMD_COPY_ALL_SAVES_USB,
CMD_COPY_ALL_SAVES_HDD,
CMD_SAVE_WEB_SERVER,
CMD_RESIGN_VMP,
CMD_EXP_SAVES_VMC1,
CMD_EXP_ALL_SAVES_VMC1,

// Export commands
CMD_EXP_EXDATA_USB,
Expand All @@ -114,12 +118,16 @@ enum cmd_code_enum
CMD_EXP_PSV_MCS,
CMD_EXP_PSV_PSU,
CMD_EXP_VM2_RAW,
CMD_EXP_VMC1SAVE,
CMD_EXP_VMP2MCR,

// Import commands
CMD_IMP_EXDATA_USB,
CMD_IMP_PS2_ISO,
CMD_IMP_PS2_CONFIG,
CMD_IMP_PS2VMC_USB,
CMD_IMP_VMC1SAVE,
CMD_IMP_MCR2VMP,
CMD_CREATE_ACT_DAT,
CMD_EXTRACT_ARCHIVE,
CMD_URL_DOWNLOAD,
Expand All @@ -143,15 +151,18 @@ enum cmd_code_enum
#define SAVE_FLAG_TROPHY 128
#define SAVE_FLAG_ONLINE 256
#define SAVE_FLAG_SELECTED 512
#define SAVE_FLAG_VMC 1024

enum save_type_enum
{
FILE_TYPE_NULL,
FILE_TYPE_MENU,
FILE_TYPE_PSV,
FILE_TYPE_TRP,
FILE_TYPE_MENU,
FILE_TYPE_VMC,

// PS1 File Types
FILE_TYPE_PS1,
FILE_TYPE_PSX,
FILE_TYPE_MCS,

Expand Down Expand Up @@ -191,7 +202,7 @@ enum char_flag_enum
CHAR_TAG_TRANSFER,
CHAR_TAG_ZIP,
CHAR_RES_CR,
CHAR_TAG_PCE,
CHAR_TAG_VMC,
CHAR_TAG_WARNING,
CHAR_BTN_X,
CHAR_BTN_S,
Expand Down Expand Up @@ -220,6 +231,7 @@ enum save_sort_enum
SORT_DISABLED,
SORT_BY_NAME,
SORT_BY_TITLE_ID,
SORT_BY_TYPE,
};

typedef struct save_entry
Expand Down Expand Up @@ -248,15 +260,18 @@ 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);
void UnloadGameList(list_t * list);
char * readTextFile(const char * path, long* size);
int sortSaveList_Compare(const void* A, const void* B);
int sortSaveList_Compare_Type(const void* A, const void* B);
int sortSaveList_Compare_TitleID(const void* A, const void* B);
int sortCodeList_Compare(const void* A, const void* B);
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 http_init(void);
void http_end(void);
Expand Down
2 changes: 1 addition & 1 deletion include/settings.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#define APOLLO_VERSION "1.8.7" //Apollo PS3 version (about menu)
#define APOLLO_VERSION "2.0.0" //Apollo PS3 version (about menu)

#define MENU_TITLE_OFF 30 //Offset of menu title text from menu mini icon
#define MENU_ICON_OFF 70 //X Offset to start printing menu mini icon
Expand Down
4 changes: 2 additions & 2 deletions sfo.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" ?>
<sfo>
<value name="APP_VER" type="string">
01.87
02.00
</value>
<value name="ATTRIBUTE" type="integer">
133
Expand Down Expand Up @@ -34,6 +34,6 @@
NP0APOLLO
</value>
<value name="VERSION" type="string">
01.87
02.00
</value>
</sfo>
121 changes: 121 additions & 0 deletions source/exec_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "util.h"
#include "pfd.h"
#include "sfo.h"
#include "ps1card.h"

static char host_buf[256];

Expand Down Expand Up @@ -656,6 +657,57 @@ static void importTrophy(const char* src_path)
free(tmp);
}

static void exportAllSavesVMC(const save_entry_t* save, int dev, int all)
{
char outPath[256];
int done = 0, err_count = 0;
list_node_t *node;
save_entry_t *item;
uint64_t progress = 0;
list_t *list = ((void**)save->dir_name)[0];

init_progress_bar("Exporting all VMC saves...", save->path);
_set_dest_path(outPath, dev, PS1_IMP_PATH_USB);
mkdirs(outPath);

LOG("Exporting all saves from '%s' to %s...", save->path, outPath);
for (node = list_head(list); (item = list_get(node)); node = list_next(node))
{
update_progress_bar(progress++, list_count(list), item->name);
if (!all && !(item->flags & SAVE_FLAG_SELECTED))
continue;

if (item->type & FILE_TYPE_PS1)
(saveSingleSave(outPath, save->path[strlen(save->path)+1], PS1SAVE_PSV) ? done++ : err_count++);
}

end_progress_bar();

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, 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->path[strlen(save->path)+1], type))
show_message("Save successfully exported to:\n%s", outPath);
else
show_message("Error exporting save:\n%s", save->path);
}

static void resignPSVfile(const char* psv_path)
{
init_loading_screen("Resigning PSV file...");
Expand Down Expand Up @@ -1509,6 +1561,35 @@ static void downloadLink(const char* path)
show_message("Error! File couldn't be downloaded");
}

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);
read_buffer(mcrPath, &data, &size);

if (openMemoryCardStream(data, size, 0) && saveMemoryCard(save->path, 0, 0))
show_message("Memory card successfully imported to:\n%s", save->path);
else
show_message("Error importing memory card:\n%s", mcrPath);
}

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");
mkdirs(mcrPath);

if (saveMemoryCard(mcrPath, PS1CARD_RAW, 0))
show_message("Memory card successfully exported to:\n%s", mcrPath);
else
show_message("Error exporting memory card:\n%s", save->path);
}

void execCodeCommand(code_entry_t* code, const char* codecmd)
{
switch (codecmd[0])
Expand Down Expand Up @@ -1668,6 +1749,46 @@ void execCodeCommand(code_entry_t* code, const char* codecmd)
code->activated = 0;
break;

case CMD_RESIGN_VMP:
if (vmp_resign(selected_entry->path))
show_message("Memory card successfully resigned:\n%s", selected_entry->path);
else
show_message("Error resigning memory card:\n%s", selected_entry->path);
code->activated = 0;
break;

case CMD_EXP_VMP2MCR:
export_vmp2mcr(selected_entry);
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);
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))
{
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_IMP_MCR2VMP:
import_mcr2vmp(selected_entry, code->options[0].name[code->options[0].sel]);
code->activated = 0;
break;

case CMD_IMP_PS2VMC_USB:
importPS2VMC(selected_entry->path, code->file);
code->activated = 0;
Expand Down
26 changes: 24 additions & 2 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void update_usb_path(char *p);
void update_hdd_path(char *p);
void update_trophy_path(char *p);
void update_db_path(char *p);
void update_vmc_path(char *p);

app_config_t apollo_config = {
.app_name = "APOLLO",
Expand Down Expand Up @@ -164,6 +165,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,
};

static void release_all(void)
{
if(inited & INITED_CALLBACK)
Expand Down Expand Up @@ -310,7 +324,7 @@ static void LoadTextures_Menu(void)
load_menu_texture(logo_text, png);
load_menu_texture(tag_lock, png);
load_menu_texture(tag_own, png);
load_menu_texture(tag_pce, png);
load_menu_texture(tag_vmc, png);
load_menu_texture(tag_ps1, png);
load_menu_texture(tag_ps2, png);
load_menu_texture(tag_ps3, png);
Expand Down Expand Up @@ -440,6 +454,14 @@ void update_db_path(char* path)
strcpy(path, apollo_config.save_db);
}

void update_vmc_path(char* path)
{
if (file_exists(path) == SUCCESS)
return;

path[0] = 0;
}

static void registerSpecialChars(void)
{
// Register save tags
Expand All @@ -448,7 +470,7 @@ static void registerSpecialChars(void)
RegisterSpecialCharacter(CHAR_TAG_PS3, 2, 1.5, &menu_textures[tag_ps3_png_index]);
RegisterSpecialCharacter(CHAR_TAG_PSP, 2, 1.5, &menu_textures[tag_psp_png_index]);
RegisterSpecialCharacter(CHAR_TAG_PSV, 2, 1.5, &menu_textures[tag_psv_png_index]);
RegisterSpecialCharacter(CHAR_TAG_PCE, 2, 1.5, &menu_textures[tag_pce_png_index]);
RegisterSpecialCharacter(CHAR_TAG_VMC, 2, 1.0, &menu_textures[tag_vmc_png_index]);
RegisterSpecialCharacter(CHAR_TAG_LOCKED, 0, 1.5, &menu_textures[tag_lock_png_index]);
RegisterSpecialCharacter(CHAR_TAG_OWNER, 0, 1.5, &menu_textures[tag_own_png_index]);
RegisterSpecialCharacter(CHAR_TAG_WARNING, 0, 1.5, &menu_textures[tag_warning_png_index]);
Expand Down
16 changes: 2 additions & 14 deletions source/menu_cheats.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,6 @@ void Draw_CheatsMenu_Options_Ani_Exit(void)

DrawTexture(&menu_textures[edit_shadow_png_index], left - menu_textures[edit_shadow_png_index].texture.width + 1, 0, 0, menu_textures[edit_shadow_png_index].texture.width, 512, icon_a);
DrawHeader(cat_cheats_png_index, left, selected_centry->name, "Options", APP_FONT_TITLE_COLOR | icon_a, 0xffffffff, 1);
/*
int _game_a = (int)(icon_a - (max / 2)) * 2;
if (_game_a > 0xFF)
_game_a = 0xFF;
u8 game_a = (u8)(_game_a < 0 ? 0 : _game_a);
*/
//DrawOptions(selected_centry->options[option_index], game_a, 18, menu_old_sel[7]);
//DrawScrollBar2(menu_old_sel[7], selected_centry->options[option_index].size, 18, 700, game_a);

tiny3d_Flip();

Expand Down Expand Up @@ -272,12 +264,7 @@ void Draw_CheatsMenu_View_Ani_Exit(void)

DrawTexture(&menu_textures[edit_shadow_png_index], left - menu_textures[edit_shadow_png_index].texture.width + 1, 0, 0, menu_textures[edit_shadow_png_index].texture.width, 512, icon_a);
DrawHeader(cat_cheats_png_index, left, "Details", selected_centry->name, APP_FONT_TITLE_COLOR | icon_a, 0xffffffff, 1);
/*
int _game_a = (int)(icon_a - (max / 2)) * 2;
if (_game_a > 0xFF)
_game_a = 0xFF;
u8 game_a = (u8)(_game_a < 0 ? 0 : _game_a);
*/

tiny3d_Flip();

if (left == 848)
Expand Down Expand Up @@ -391,6 +378,7 @@ void DrawGameList(int selIndex, list_t * games, u8 alpha)
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;
if (item->type == FILE_TYPE_VMC) tmp[2] = CHAR_TAG_VMC;

DrawString(800 - (MENU_ICON_OFF * 1), game_y, tmp);
node = list_next(node);
Expand Down
Loading

0 comments on commit 6117e22

Please sign in to comment.