diff --git a/Source/Core/Core/CMakeLists.txt b/Source/Core/Core/CMakeLists.txt index f72a43861d..498b430d71 100644 --- a/Source/Core/Core/CMakeLists.txt +++ b/Source/Core/Core/CMakeLists.txt @@ -107,6 +107,7 @@ add_library(core HW/EXI/EXI_DeviceMic.cpp HW/GCKeyboard.cpp HW/GCKeyboardEmu.cpp + HW/GCMemcard/GCIFile.cpp HW/GCMemcard/GCMemcard.cpp HW/GCMemcard/GCMemcardDirectory.cpp HW/GCMemcard/GCMemcardRaw.cpp diff --git a/Source/Core/Core/Core.vcxproj b/Source/Core/Core/Core.vcxproj index 82709080f4..62b00d0f70 100644 --- a/Source/Core/Core/Core.vcxproj +++ b/Source/Core/Core/Core.vcxproj @@ -146,6 +146,7 @@ + @@ -414,6 +415,7 @@ + diff --git a/Source/Core/Core/Core.vcxproj.filters b/Source/Core/Core/Core.vcxproj.filters index 62091ccacd..68a8141f87 100644 --- a/Source/Core/Core/Core.vcxproj.filters +++ b/Source/Core/Core/Core.vcxproj.filters @@ -462,6 +462,9 @@ HW %28Flipper/Hollywood%29\EXI - Expansion Interface + + HW %28Flipper/Hollywood%29\GCMemcard + HW %28Flipper/Hollywood%29\GCMemcard @@ -1173,6 +1176,9 @@ HW %28Flipper/Hollywood%29\EXI - Expansion Interface + + HW %28Flipper/Hollywood%29\GCMemcard + HW %28Flipper/Hollywood%29\GCMemcard diff --git a/Source/Core/Core/HW/GCMemcard/GCIFile.cpp b/Source/Core/Core/HW/GCMemcard/GCIFile.cpp new file mode 100644 index 0000000000..77ddad34d4 --- /dev/null +++ b/Source/Core/Core/HW/GCMemcard/GCIFile.cpp @@ -0,0 +1,70 @@ +// Copyright 2019 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "Core/HW/GCMemcard/GCIFile.h" + +#include "Common/ChunkFile.h" +#include "Common/CommonTypes.h" +#include "Common/File.h" +#include "Common/Logging/Log.h" +#include "Common/MsgHandler.h" + +bool GCIFile::LoadSaveBlocks() +{ + if (m_save_data.empty()) + { + if (m_filename.empty()) + return false; + + File::IOFile save_file(m_filename, "rb"); + if (!save_file) + return false; + + INFO_LOG(EXPANSIONINTERFACE, "Reading savedata from disk for %s", m_filename.c_str()); + save_file.Seek(DENTRY_SIZE, SEEK_SET); + u16 num_blocks = m_gci_header.m_block_count; + m_save_data.resize(num_blocks); + if (!save_file.ReadBytes(m_save_data.data(), num_blocks * BLOCK_SIZE)) + { + PanicAlertT("Failed to read data from GCI file %s", m_filename.c_str()); + m_save_data.clear(); + return false; + } + } + return true; +} + +bool GCIFile::HasCopyProtection() const +{ + if ((strcmp(reinterpret_cast(m_gci_header.m_filename.data()), "PSO_SYSTEM") == 0) || + (strcmp(reinterpret_cast(m_gci_header.m_filename.data()), "PSO3_SYSTEM") == 0) || + (strcmp(reinterpret_cast(m_gci_header.m_filename.data()), "f_zero.dat") == 0)) + return true; + return false; +} + +int GCIFile::UsesBlock(u16 block_num) +{ + for (u16 i = 0; i < m_used_blocks.size(); ++i) + { + if (m_used_blocks[i] == block_num) + return i; + } + return -1; +} + +void GCIFile::DoState(PointerWrap& p) +{ + p.DoPOD(m_gci_header); + p.Do(m_dirty); + p.Do(m_filename); + int num_blocks = (int)m_save_data.size(); + p.Do(num_blocks); + m_save_data.resize(num_blocks); + for (auto itr = m_save_data.begin(); itr != m_save_data.end(); ++itr) + { + p.DoPOD(*itr); + } + p.Do(m_used_blocks); +} diff --git a/Source/Core/Core/HW/GCMemcard/GCIFile.h b/Source/Core/Core/HW/GCMemcard/GCIFile.h new file mode 100644 index 0000000000..b118330d34 --- /dev/null +++ b/Source/Core/Core/HW/GCMemcard/GCIFile.h @@ -0,0 +1,28 @@ +// Copyright 2019 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include +#include + +#include "Common/CommonTypes.h" +#include "Core/HW/GCMemcard/GCMemcard.h" + +class PointerWrap; + +class GCIFile +{ +public: + bool LoadSaveBlocks(); + bool HasCopyProtection() const; + void DoState(PointerWrap& p); + int UsesBlock(u16 blocknum); + + DEntry m_gci_header; + std::vector m_save_data; + std::vector m_used_blocks; + bool m_dirty; + std::string m_filename; +}; diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcard.h b/Source/Core/Core/HW/GCMemcard/GCMemcard.h index 75017fe28b..8d735ced1f 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcard.h +++ b/Source/Core/Core/HW/GCMemcard/GCMemcard.h @@ -337,30 +337,6 @@ struct BlockAlloc static_assert(sizeof(BlockAlloc) == BLOCK_SIZE); #pragma pack(pop) -class GCIFile -{ -public: - bool LoadSaveBlocks(); - bool HasCopyProtection() const - { - if ((strcmp(reinterpret_cast(m_gci_header.m_filename.data()), "PSO_SYSTEM") == - 0) || - (strcmp(reinterpret_cast(m_gci_header.m_filename.data()), "PSO3_SYSTEM") == - 0) || - (strcmp(reinterpret_cast(m_gci_header.m_filename.data()), "f_zero.dat") == 0)) - return true; - return false; - } - - void DoState(PointerWrap& p); - DEntry m_gci_header; - std::vector m_save_data; - std::vector m_used_blocks; - int UsesBlock(u16 blocknum); - bool m_dirty; - std::string m_filename; -}; - class GCMemcard { private: diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp b/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp index 0353e9e4b8..f99012aa0f 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp +++ b/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp @@ -693,56 +693,6 @@ void GCMemcardDirectory::DoState(PointerWrap& p) } } -bool GCIFile::LoadSaveBlocks() -{ - if (m_save_data.empty()) - { - if (m_filename.empty()) - return false; - - File::IOFile save_file(m_filename, "rb"); - if (!save_file) - return false; - - INFO_LOG(EXPANSIONINTERFACE, "Reading savedata from disk for %s", m_filename.c_str()); - save_file.Seek(DENTRY_SIZE, SEEK_SET); - u16 num_blocks = m_gci_header.m_block_count; - m_save_data.resize(num_blocks); - if (!save_file.ReadBytes(m_save_data.data(), num_blocks * BLOCK_SIZE)) - { - PanicAlertT("Failed to read data from GCI file %s", m_filename.c_str()); - m_save_data.clear(); - return false; - } - } - return true; -} - -int GCIFile::UsesBlock(u16 block_num) -{ - for (u16 i = 0; i < m_used_blocks.size(); ++i) - { - if (m_used_blocks[i] == block_num) - return i; - } - return -1; -} - -void GCIFile::DoState(PointerWrap& p) -{ - p.DoPOD(m_gci_header); - p.Do(m_dirty); - p.Do(m_filename); - int num_blocks = (int)m_save_data.size(); - p.Do(num_blocks); - m_save_data.resize(num_blocks); - for (auto itr = m_save_data.begin(); itr != m_save_data.end(); ++itr) - { - p.DoPOD(*itr); - } - p.Do(m_used_blocks); -} - void MigrateFromMemcardFile(const std::string& directory_name, int card_index) { File::CreateFullPath(directory_name); diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.h b/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.h index ce784b8101..04e5e908ef 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.h +++ b/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.h @@ -10,6 +10,7 @@ #include #include "Common/Event.h" +#include "Core/HW/GCMemcard/GCIFile.h" #include "Core/HW/GCMemcard/GCMemcard.h" // Uncomment this to write the system data of the memorycard from directory to disc