From 3dcd90188536b94badfbaed40e87bebeb1d2664e Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 18 Sep 2022 19:38:16 +1000 Subject: [PATCH] MemoryCardImage: Support importing mem/psx and a few other formats Untested. --- src/core/memory_card_image.cpp | 54 ++++++++++++++++++- src/duckstation-qt/memorycardeditordialog.cpp | 4 +- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/core/memory_card_image.cpp b/src/core/memory_card_image.cpp index 1784ba8ff..f8b3da508 100644 --- a/src/core/memory_card_image.cpp +++ b/src/core/memory_card_image.cpp @@ -523,6 +523,48 @@ static bool ImportCardGME(DataArray* data, const char* filename, std::vector return true; } +static bool ImportCardVGS(DataArray* data, const char* filename, std::vector file_data) +{ + constexpr u32 HEADER_SIZE = 64; + + if (file_data.size() != (HEADER_SIZE + DATA_SIZE)) + { + Log_ErrorPrintf("Failed to import memory card from '%s': file is incorrect size.", filename); + return false; + } + + // Connectix Virtual Game Station format (.MEM): "VgsM", 64 bytes + if (file_data[0] != 'V' || file_data[1] != 'g' || file_data[2] != 's' || file_data[3] != 'M') + { + Log_ErrorPrintf("Failed to import memory card from '%s': incorrect header.", filename); + return false; + } + + std::memcpy(data->data(), &file_data[HEADER_SIZE], DATA_SIZE); + return true; +} + +static bool ImportCardPSX(DataArray* data, const char* filename, std::vector file_data) +{ + constexpr u32 HEADER_SIZE = 256; + + if (file_data.size() != (HEADER_SIZE + DATA_SIZE)) + { + Log_ErrorPrintf("Failed to import memory card from '%s': file is incorrect size.", filename); + return false; + } + + // Connectix Virtual Game Station format (.MEM): "VgsM", 64 bytes + if (file_data[0] != 'P' || file_data[1] != 'S' || file_data[2] != 'V') + { + Log_ErrorPrintf("Failed to import memory card from '%s': incorrect header.", filename); + return false; + } + + std::memcpy(data->data(), &file_data[HEADER_SIZE], DATA_SIZE); + return true; +} + bool ImportCard(DataArray* data, const char* filename, std::vector file_data) { const char* extension = std::strrchr(filename, '.'); @@ -533,7 +575,9 @@ bool ImportCard(DataArray* data, const char* filename, std::vector file_data } if (StringUtil::Strcasecmp(extension, ".mcd") == 0 || StringUtil::Strcasecmp(extension, ".mcr") == 0 || - StringUtil::Strcasecmp(extension, ".mc") == 0 || StringUtil::Strcasecmp(extension, ".srm") == 0) + StringUtil::Strcasecmp(extension, ".mc") == 0 || StringUtil::Strcasecmp(extension, ".srm") == 0 || + StringUtil::Strcasecmp(extension, ".psm") == 0 || StringUtil::Strcasecmp(extension, ".ps") == 0 || + StringUtil::Strcasecmp(extension, ".ddf") == 0) { return ImportCardMCD(data, filename, std::move(file_data)); } @@ -541,6 +585,14 @@ bool ImportCard(DataArray* data, const char* filename, std::vector file_data { return ImportCardGME(data, filename, std::move(file_data)); } + else if (StringUtil::Strcasecmp(extension, ".mem") == 0 || StringUtil::Strcasecmp(extension, ".vgs") == 0) + { + return ImportCardVGS(data, filename, std::move(file_data)); + } + else if (StringUtil::Strcasecmp(extension, ".psx") == 0) + { + return ImportCardPSX(data, filename, std::move(file_data)); + } else { Log_ErrorPrintf("Failed to import memory card from '%s': unknown extension?", filename); diff --git a/src/duckstation-qt/memorycardeditordialog.cpp b/src/duckstation-qt/memorycardeditordialog.cpp index a9b6f7f21..d2694919a 100644 --- a/src/duckstation-qt/memorycardeditordialog.cpp +++ b/src/duckstation-qt/memorycardeditordialog.cpp @@ -9,8 +9,8 @@ #include #include -static constexpr char MEMORY_CARD_IMAGE_FILTER[] = - QT_TRANSLATE_NOOP("MemoryCardEditorDialog", "All Memory Card Types (*.mcd *.mcr *.mc)"); +static constexpr char MEMORY_CARD_IMAGE_FILTER[] = QT_TRANSLATE_NOOP( + "MemoryCardEditorDialog", "All Memory Card Types (*.mcd *.mcr *.mc *.srm *.psm *.ps *.ddf *.mem *.vgs *.psx)"); static constexpr char MEMORY_CARD_IMPORT_FILTER[] = QT_TRANSLATE_NOOP("MemoryCardEditorDialog", "All Importable Memory Card Types (*.mcd *.mcr *.mc *.gme)"); static constexpr char SINGLE_SAVEFILE_FILTER[] =