Skip to content

Commit

Permalink
ps1 vmc load fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bucanero committed Mar 26, 2024
1 parent 0368b44 commit 219d9a3
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 116 deletions.
88 changes: 0 additions & 88 deletions include/keys.h

This file was deleted.

2 changes: 2 additions & 0 deletions source/exec_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,7 @@ static void import_save2vmc(const char* src, int type)
{
int ret = 0;

init_loading_screen("Importing PS2 save...");
switch (type)
{
case FILE_TYPE_PSV:
Expand All @@ -1625,6 +1626,7 @@ static void import_save2vmc(const char* src, int type)
default:
break;
}
stop_loading_screen();

if (ret)
show_message("Successfully imported to VMC:\n%s", src);
Expand Down
1 change: 1 addition & 0 deletions source/mcio.c
Original file line number Diff line number Diff line change
Expand Up @@ -3645,6 +3645,7 @@ int mcio_vmcImportImage(const char *input)
}
while ((r == w) && (r == sizeof(tmpbuf)));

fflush(vmc_fp);
ftruncate(fileno(vmc_fp), size);
fclose(fh);

Expand Down
8 changes: 6 additions & 2 deletions source/menu_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,24 @@ static void SetMenu(int id)
case MENU_PS1VMC_SAVES:
if (id == MENU_MAIN_SCREEN)
{
LOG("Saving PS1 VMC changes...");
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;

case MENU_PS2VMC_SAVES:
if (id == MENU_MAIN_SCREEN)
{
LOG("Saving PS2 VMC changes...");
init_loading_screen("Saving PS2 Memory Card...");
UnloadGameList(vmc2_saves.list);
vmc2_saves.list = NULL;
mcio_vmcFinish();
stop_loading_screen();
}
break;

case MENU_MAIN_SCREEN: //Main Menu
case MENU_TROPHIES:
Expand Down
35 changes: 17 additions & 18 deletions source/ps1card.c
Original file line number Diff line number Diff line change
Expand Up @@ -1037,27 +1037,20 @@ int openMemoryCard(const char* fileName, int fixData)
//Check if the Memory Card should be opened or created
if (fileName != NULL)
{
uint8_t tempData[134976];
uint8_t *tempData;
int startOffset;
FILE* binReader;

//Check if the file is allowed to be opened
binReader = fopen(fileName, "rb");
size_t fileSize;

//File cannot be opened, return error message
if (!binReader)
if (read_buffer(fileName, &tempData, &fileSize) < 0)
return false;

//Put data into temp array
if (fread(tempData, 1, 134976, binReader) < PS1CARD_SIZE)
if (fileSize < PS1CARD_SIZE)
{
fclose(binReader);
free(tempData);
return false;
}

//File is sucesfully read, close the stream
fclose(binReader);

//Check the format of the card and if it's supported load it
//Standard raw Memory Card
if (memcmp(tempData, "MC", 2) == 0)
Expand All @@ -1066,7 +1059,7 @@ int openMemoryCard(const char* fileName, int fixData)
cardType = PS1CARD_RAW;
}
//DexDrive GME Memory Card
else if (memcmp(tempData, "123-456-STD", 11) == 0)
else if (fileSize == 0x20F40 && memcmp(tempData, "123-456-STD", 11) == 0)
{
startOffset = 3904;
cardType = PS1CARD_GME;
Expand All @@ -1076,27 +1069,33 @@ int openMemoryCard(const char* fileName, int fixData)
memcpy(saveComments[i], &tempData[64 + (256 * i)], 256);
}
//VGS Memory Card
else if (memcmp(tempData, "VgsM", 4) == 0)
else if (fileSize == 0x20040 && memcmp(tempData, "VgsM", 4) == 0)
{
startOffset = 64;
cardType = PS1CARD_VGS;
}
//PSP virtual Memory Card
else if (memcmp(tempData, "\0PMV", 4) == 0)
else if (fileSize == 0x20080 && memcmp(tempData, "\0PMV", 4) == 0)
{
startOffset = 128;
cardType = PS1CARD_VMP;
}
//File type is not supported or is MCX
else if (IsMcxCard(tempData))
//PS Vita MCX PocketStation Memory Card
else if (fileSize == 0x200A0 && IsMcxCard(tempData))
{
startOffset = 128;
cardType = PS1CARD_MCX;
}
else return false;
//File type is not supported
else
{
free(tempData);
return false;
}

//Copy data to rawMemoryCard array with offset from input data
memcpy(rawMemoryCard, tempData + startOffset, PS1CARD_SIZE);
free(tempData);

//Load Memory Card data from raw card
loadDataFromRawCard();
Expand Down
27 changes: 19 additions & 8 deletions source/saves.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,14 @@ static void add_vmc_import_saves(list_t* list, const char* path, const char* fol
!endsWith(dir->d_name, ".PS1") && !endsWith(dir->d_name, ".MCB") && !endsWith(dir->d_name, ".PDA"))
continue;

// check for PS1 PSV saves
if (endsWith(dir->d_name, ".PSV"))
{
snprintf(psvPath, sizeof(psvPath), "%s%s%s", path, folder, dir->d_name);
if (read_file(psvPath, (uint8_t*) psvPath, 0x40) < 0 || psvPath[0x3C] != 0x01)
continue;
}

snprintf(psvPath, sizeof(psvPath), "%s %s", CHAR_ICON_COPY, dir->d_name);
cmd = _createCmdCode(PATCH_COMMAND, psvPath, CMD_IMP_VMC1SAVE);
asprintf(&cmd->file, "%s%s%s", path, folder, dir->d_name);
Expand Down Expand Up @@ -753,6 +761,7 @@ int ReadVmc1Codes(save_entry_t * save)
if (save->type == FILE_TYPE_MENU)
{
add_vmc_import_saves(save->codes, save->path, PS1_IMP_PATH_USB);
add_vmc_import_saves(save->codes, save->path, PSV_SAVES_PATH_USB);
if (!list_count(save->codes))
{
list_free(save->codes);
Expand Down Expand Up @@ -819,8 +828,13 @@ static void add_vmc2_import_saves(list_t* list, const char* path, const char* fo
if (dir->d_type != DT_REG)
continue;

// check for PS2 PSV saves
if (endsWith(dir->d_name, ".PSV"))
{
snprintf(psvPath, sizeof(psvPath), "%s%s%s", path, folder, dir->d_name);
if (read_file(psvPath, (uint8_t*) psvPath, 0x40) < 0 || psvPath[0x3C] != 0x02)
continue;

// toff = 0x80;
type = FILE_TYPE_PSV;
}
Expand Down Expand Up @@ -1564,7 +1578,8 @@ static void read_vmc2_files(const char* userPath, list_t *list)

while ((dir = readdir(d)) != NULL)
{
if (dir->d_type != DT_REG || !(endsWith(dir->d_name, ".VMC") || endsWith(dir->d_name, ".VM2") || endsWith(dir->d_name, ".BIN") || endsWith(dir->d_name, ".PS2")))
if (dir->d_type != DT_REG || !(endsWith(dir->d_name, ".VMC") || endsWith(dir->d_name, ".VM2") ||
endsWith(dir->d_name, ".BIN") || endsWith(dir->d_name, ".PS2")|| endsWith(dir->d_name, ".VME")))
continue;

snprintf(psvPath, sizeof(psvPath), "%s%s", userPath, dir->d_name);
Expand Down Expand Up @@ -1943,7 +1958,6 @@ list_t * ReadOnlineList(const char* urlPath)

list_t * ReadVmc1List(const char* userPath)
{
char filePath[256];
save_entry_t *item;
code_entry_t *cmd;
list_t *list;
Expand All @@ -1964,15 +1978,12 @@ list_t * ReadVmc1List(const char* userPath)
item = _createSaveEntry(SAVE_FLAG_PS1, CHAR_ICON_VMC " Memory Card Management");
item->type = FILE_TYPE_MENU;
item->path = strdup(userPath);
item->title_id = strdup("VMC");
item->codes = list_alloc();
//bulk management hack
item->dir_name = malloc(sizeof(void**));
((void**)item->dir_name)[0] = list;

strncpy(filePath, userPath, sizeof(filePath));
strrchr(filePath, '/')[0] = 0;
item->title_id = strdup(strrchr(filePath, '/')+1);

cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_COPY " Export selected Saves to USB", CMD_CODE_NULL);
cmd->options_count = 1;
cmd->options = _createOptions(2, "Copy selected Saves to USB", CMD_EXP_SAVES_VMC1);
Expand All @@ -1985,9 +1996,9 @@ list_t * ReadVmc1List(const char* userPath)
list_append(list, item);

item = _createSaveEntry(SAVE_FLAG_PS1, CHAR_ICON_COPY " Import Saves to Virtual Card");
if (strncmp(filePath, USB_PATH, 8) == 0)
if (strncmp(userPath, USB_PATH, 8) == 0)
{
item->path = strdup(filePath);
item->path = strdup(userPath);
strchr(item->path + 1, '/')[1] = 0;
}
else
Expand Down

0 comments on commit 219d9a3

Please sign in to comment.