Skip to content

Commit

Permalink
Add ps2 VME support
Browse files Browse the repository at this point in the history
show ps1 / ps2 save icons
  • Loading branch information
bucanero committed Mar 17, 2024
1 parent d241a30 commit 0368b44
Show file tree
Hide file tree
Showing 13 changed files with 533 additions and 292 deletions.
4 changes: 3 additions & 1 deletion include/mcio.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ struct io_dirent {
} __attribute__((packed));

int mcio_vmcInit(const char* vmc);
int mcio_vmcExportImage(const char *dst, int ecc);
int mcio_vmcImportImage(const char *src);
void mcio_vmcFinish(void);
int mcio_mcDetect(void);
int mcio_mcGetInfo(int *pagesize, int *blocksize, int *cardsize, int *cardflags);
Expand All @@ -77,7 +79,7 @@ int mcio_mcDopen(const char *dirname);
int mcio_mcDclose(int fd);
int mcio_mcDread(int fd, struct io_dirent *dirent);
int mcio_mcMkDir(const char *dirname);
int mcio_mcReadPage(int pagenum, void *buf);
int mcio_mcReadPage(int pagenum, void *buf, void *ecc);
int mcio_mcUnformat(void);
int mcio_mcFormat(void);
int mcio_mcRemove(const char *filename);
Expand Down
75 changes: 75 additions & 0 deletions include/ps2icon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
*
* Copyright (c) 2008 Andreas Weis (http://www.ghulbus-inc.de/)
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

//================================================================================================
// Typedefs and Defines
//================================================================================================

/** File header
*/
typedef struct Icon_Header_t {
unsigned int file_id; ///< reserved; should be: 0x010000 (but does not have to ;) )
unsigned int animation_shapes; ///< number of animation shapes per vertex
unsigned int texture_type; ///< texture type - 0x07: uncompressed, 0x06: uncompresses, 0x0f: RLE compression
unsigned int reserved; ///< reserved; should be: 0x3F800000 (but does not have to ;) )
unsigned int n_vertices; ///< number of vertices; must be a multiple of 3
} Icon_Header;
/** Set of vertex coordinates
* @note The f16_* fields indicate float16 data; divide by 4096.0f to convert to float32;
*/
typedef struct Vertex_Coord_t {
short f16_x; ///< vertex x coordinate in float16
short f16_y; ///< vertex y coordinate in float16
short f16_z; ///< vertex z coordinate in float16
short f16_unknown; ///< unknown; seems to influence lightning?
} Vertex_Coord;
/** Set of texture coordinates
* @note The f16_* fields indicate float16 data; divide by 4096.0f to convert to float32;
*/
typedef struct Texture_Data_t {
short f16_u; ///< vertex u texture coordinate in float16
short f16_v; ///< vertex v texture coordinate in float16
unsigned int color; ///< vertex color (32 bit RGBA)
} Texture_Data;
/** Animation header
*/
typedef struct Animation_Header_t {
unsigned int id_tag; ///< ???
unsigned int frame_length; ///< ???
float anim_speed; ///< ???
unsigned int play_offset; ///< ???
unsigned int n_frames; ///< number of frames in the animation
} Animation_Header;
/** Per-frame animation data
*/
typedef struct Frame_Data_t {
unsigned int shape_id; ///< shape used for this frame
unsigned int n_keys; ///< number of keys corresponding to this frame
} Frame_Data;
/** Per-key animation data
*/
typedef struct Frame_Key_t {
float time; ///< ???
float value; ///< ???
} Frame_Key;
7 changes: 4 additions & 3 deletions include/saves.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ enum cmd_code_enum
CMD_VIEW_DETAILS,
CMD_VIEW_RAW_PATCH,
CMD_RESIGN_PSV,
CMD_DECRYPT_PS2_VME,
CMD_ENCRYPT_PS2_VMC,
CMD_CONVERT_TO_PSV,
CMD_COPY_DUMMY_PSV,
CMD_IMPORT_DATA_FILE,
Expand All @@ -117,6 +115,7 @@ enum cmd_code_enum
CMD_EXP_LICS_RAPS,
CMD_EXP_FLASH2_USB,
CMD_EXP_PS2_BINENC,
CMD_EXP_PS2_VM2,
CMD_EXP_PSV_MCS,
CMD_EXP_PSV_PSU,
CMD_EXP_VM2_RAW,
Expand All @@ -126,6 +125,7 @@ enum cmd_code_enum

// Import commands
CMD_IMP_EXDATA_USB,
CMD_IMP_PS2_VM2,
CMD_IMP_PS2_ISO,
CMD_IMP_PS2_CONFIG,
CMD_IMP_PS2VMC_USB,
Expand Down Expand Up @@ -262,6 +262,7 @@ typedef struct
} save_list_t;

list_t * ReadUserList(const char* userPath);
list_t * ReadUsbList(const char* userPath);
list_t * ReadOnlineList(const char* urlPath);
list_t * ReadBackupList(const char* userPath);
list_t * ReadTrophyList(const char* userPath);
Expand Down Expand Up @@ -318,7 +319,6 @@ void ps2_encrypt_image(uint8_t cfg_file, const char* image_name, const char* dat
void ps2_decrypt_image(uint8_t dex_mode, const char* image_name, const char* data_file);
void ps2_crypt_vmc(uint8_t dex_mode, const char* vmc_path, const char* vmc_out, int crypt_mode);
int ps2_add_vmc_ecc(const char* src, const char* dst);
int ps2_remove_vmc_ecc(const char* src, const char* dst);
int psv_resign(const char *src_psv);
int vmp_resign(const char *src_vmp);

Expand All @@ -337,3 +337,4 @@ int vmc_import_psv(const char *input);
int vmc_import_psu(const char *input);

char* sjis2utf8(char* input);
uint8_t* getIconPS2(const char* folder, const char* iconfile);
5 changes: 3 additions & 2 deletions source/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ static void _drawListBackground(int off, int icon)

if (menu_textures[icon_png_file_index].size)
{
DrawTexture(&menu_textures[help_png_index], 624, help_png_y + 4, 0, 168, 98, 0xFFFFFF00 | 0xFF);
DrawTexture(&menu_textures[icon_png_file_index], 628, help_png_y + 8, 0, 160, 88, 0xFFFFFF00 | 0xFF);
int adj = (menu_textures[icon_png_file_index].texture.width == 16) ? 6 : 1; // resize PS1 icons
DrawTexture(&menu_textures[help_png_index], 624, help_png_y + 4, 0, (menu_textures[icon_png_file_index].texture.width / 2 * adj) + 8, (menu_textures[icon_png_file_index].texture.height / 2 * adj) + 10, 0xFFFFFF00 | 0xFF);
DrawTexture(&menu_textures[icon_png_file_index], 628, help_png_y + 8, 0, menu_textures[icon_png_file_index].texture.width / 2 * adj, menu_textures[icon_png_file_index].texture.height / 2 * adj, 0xFFFFFF00 | 0xFF);
}
break;

Expand Down
69 changes: 22 additions & 47 deletions source/exec_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "pfd.h"
#include "sfo.h"
#include "ps1card.h"
#include "mcio.h"

static char host_buf[256];

Expand Down Expand Up @@ -875,45 +876,21 @@ static void convertSavePSV(const save_entry_t* save, int dst)
show_message("File successfully saved to:\n%s", out_path);
}

static void decryptVMEfile(const char* vme_path, const char* vme_file, uint8_t dst)
static void importVM2file(const char* vme_file, const char* src_name)
{
char vmefile[256];
char outfile[256];
char path[256];

_set_dest_path(path, dst, VMC_PS2_PATH_USB);
if (dst == STORAGE_HDD)
snprintf(path, sizeof(path), VMC_PS2_PATH_HDD);

if (mkdirs(path) != SUCCESS)
{
show_message("Error! Export folder is not available:\n%s", path);
return;
}

snprintf(vmefile, sizeof(vmefile), "%s%s", vme_path, vme_file);
snprintf(outfile, sizeof(outfile), "%sAPOLLO%c.VM2", path, vme_file[6]);

init_loading_screen("Decrypting VME card...");
ps2_crypt_vmc(0, vmefile, outfile, 0);
stop_loading_screen();

show_message("File successfully saved to:\n%s", outfile);
}

static void encryptVM2file(const char* vme_path, const char* vme_file, const char* src_name)
{
char vmefile[256];
int ret;
char srcfile[256];

snprintf(vmefile, sizeof(vmefile), "%s%s", vme_path, vme_file);
snprintf(srcfile, sizeof(srcfile), "%s%s", VMC_PS2_PATH_HDD, src_name);

init_loading_screen("Encrypting VM2 card...");
ps2_crypt_vmc(0, srcfile, vmefile, 1);
init_loading_screen("Importing VM2 card...");
ret = mcio_vmcImportImage(srcfile);
stop_loading_screen();

show_message("File successfully saved to:\n%s", vmefile);
if (ret == sceMcResSucceed)
show_message("File successfully imported to:\n%s", vme_file);
else
show_message("Error! Failed to import PS2 memory card");
}

static void importPS2VMC(const char* vmc_path, const char* vmc_file)
Expand All @@ -932,9 +909,9 @@ static void importPS2VMC(const char* vmc_path, const char* vmc_file)
show_message("File successfully saved to:\n%s", vm2file);
}

static void exportVM2raw(const char* vm2_path, const char* vm2_file, int dst)
static void exportVM2raw(const char* vm2_file, int dst, int ecc)
{
char vm2file[256];
int ret;
char dstfile[256];
char dst_path[256];

Expand All @@ -945,15 +922,17 @@ static void exportVM2raw(const char* vm2_path, const char* vm2_file, int dst)
return;
}

snprintf(vm2file, sizeof(vm2file), "%s%s", vm2_path, vm2_file);
snprintf(dstfile, sizeof(dstfile), "%s%s.vmc", dst_path, vm2_file);
snprintf(dstfile, sizeof(dstfile), "%s%s.%s", dst_path, vm2_file, ecc ? "VM2" : "vmc");

init_loading_screen("Exporting PS2 .VM2 memory card...");
ps2_remove_vmc_ecc(vm2file, dstfile);
init_loading_screen("Exporting PS2 memory card...");
ret = mcio_vmcExportImage(dstfile, ecc);
file_chmod(dstfile);
stop_loading_screen();

show_message("File successfully saved to:\n%s", dstfile);
if (ret == sceMcResSucceed)
show_message("File successfully saved to:\n%s", dstfile);
else
show_message("Error! Failed to export PS2 memory card");
}

static void importPS2classicsCfg(const char* cfg_path, const char* cfg_file)
Expand Down Expand Up @@ -1762,13 +1741,8 @@ void execCodeCommand(code_entry_t* code, const char* codecmd)
code->activated = 0;
break;

case CMD_DECRYPT_PS2_VME:
decryptVMEfile(selected_entry->path, code->file, codecmd[1]);
code->activated = 0;
break;

case CMD_ENCRYPT_PS2_VMC:
encryptVM2file(selected_entry->path, code->file, code->options[0].name[code->options[0].sel]);
case CMD_IMP_PS2_VM2:
importVM2file(selected_entry->path, code->options[0].name[code->options[0].sel]);
code->activated = 0;
break;

Expand Down Expand Up @@ -1807,8 +1781,9 @@ void execCodeCommand(code_entry_t* code, const char* codecmd)
code->activated = 0;
break;

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

Expand Down
2 changes: 1 addition & 1 deletion source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ save_list_t usb_saves = {
.title = "USB Saves",
.list = NULL,
.path = "",
.ReadList = &ReadUserList,
.ReadList = &ReadUsbList,
.ReadCodes = &ReadCodes,
.UpdatePath = &update_usb_path,
};
Expand Down
Loading

0 comments on commit 0368b44

Please sign in to comment.