From e9507c7d8c831f14afb119aa95ab26ec1c023526 Mon Sep 17 00:00:00 2001 From: R2DLiu Date: Wed, 8 Jul 2020 22:08:44 -0400 Subject: [PATCH] Fixes #22, #16, and possibly 7: Rewrite file read function to actually pull proper files from filesystem of iso volume --- Source/Core/Core/ConfigManager.cpp | 1 + Source/Core/Core/ConfigManager.h | 1 + Source/Core/Core/HW/DVD/DVDThread.cpp | 16 ++++++++++++ Source/Core/Core/HW/DVD/DVDThread.h | 4 ++- .../Core/Core/Slippi/SlippiGameFileLoader.cpp | 26 ++++--------------- Source/Core/Core/Slippi/SlippiUser.cpp | 2 +- 6 files changed, 27 insertions(+), 23 deletions(-) diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index b773b9e7a8..4de5137039 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -969,6 +969,7 @@ bool SConfig::SetPathsAndGameMetadata(const BootParameters& boot) const std::string region_dir = GetDirectoryForRegion(ToGameCubeRegion(m_region)); m_strSRAM = File::GetUserPath(F_GCSRAM_IDX); m_strBootROM = GetBootROMPath(region_dir); + m_strIsoPath = (boot.parameters.index() == 0) ? std::get(boot.parameters).path : ""; return true; } diff --git a/Source/Core/Core/ConfigManager.h b/Source/Core/Core/ConfigManager.h index 35d503bd75..774051e067 100644 --- a/Source/Core/Core/ConfigManager.h +++ b/Source/Core/Core/ConfigManager.h @@ -196,6 +196,7 @@ struct SConfig // files std::string m_strBootROM; + std::string m_strIsoPath; std::string m_strSRAM; std::string m_perfDir; diff --git a/Source/Core/Core/HW/DVD/DVDThread.cpp b/Source/Core/Core/HW/DVD/DVDThread.cpp index 00279c5df4..7cbfbaddd3 100644 --- a/Source/Core/Core/HW/DVD/DVDThread.cpp +++ b/Source/Core/Core/HW/DVD/DVDThread.cpp @@ -32,7 +32,9 @@ #include "Core/HW/SystemTimers.h" #include "Core/IOS/ES/Formats.h" +#include "DiscIO/DiscExtractor.h" #include "DiscIO/Enums.h" +#include "DiscIO/Filesystem.h" #include "DiscIO/Volume.h" namespace DVDThread @@ -393,4 +395,18 @@ static void DVDThread() } } } + +void ReadFile(std::string& fileName, std::vector& buf) { + if (HasDisc()) { + const DiscIO::FileSystem* filesystem = s_disc->GetFileSystem(DiscIO::PARTITION_NONE); + auto fileInfo = filesystem->FindFileInfo(fileName); + auto fileSize = fileInfo->GetSize(); + WaitUntilIdle(); + buf.resize(fileSize); + DiscIO::ReadFile(*s_disc, DiscIO::PARTITION_NONE, fileInfo.get(), buf.data(), fileSize); + } + else { + INFO_LOG(SLIPPI, "Failed to open file: %s", fileName.c_str()); + } +} } // namespace DVDThread diff --git a/Source/Core/Core/HW/DVD/DVDThread.h b/Source/Core/Core/HW/DVD/DVDThread.h index 548d4b7b33..5168e3c812 100644 --- a/Source/Core/Core/HW/DVD/DVDThread.h +++ b/Source/Core/Core/HW/DVD/DVDThread.h @@ -7,7 +7,7 @@ #include #include #include - +#include #include "Common/CommonTypes.h" class PointerWrap; @@ -60,4 +60,6 @@ void StartRead(u64 dvd_offset, u32 length, const DiscIO::Partition& partition, void StartReadToEmulatedRAM(u32 output_address, u64 dvd_offset, u32 length, const DiscIO::Partition& partition, DVDInterface::ReplyType reply_type, s64 ticks_until_completion); + +void ReadFile(std::string& fileName, std::vector& buf); } // namespace DVDThread diff --git a/Source/Core/Core/Slippi/SlippiGameFileLoader.cpp b/Source/Core/Core/Slippi/SlippiGameFileLoader.cpp index 4eb8a38711..e1ce3fc849 100644 --- a/Source/Core/Core/Slippi/SlippiGameFileLoader.cpp +++ b/Source/Core/Core/Slippi/SlippiGameFileLoader.cpp @@ -3,6 +3,7 @@ #include "Common/Logging/Log.h" #include "Common/FileUtil.h" #include "Common/File.h" +#include "Core/HW/DVD/DVDThread.h" #include "Core/Boot/Boot.h" #include "Core/Core.h" #include "Core/ConfigManager.h" @@ -10,6 +11,7 @@ std::string getFilePath(std::string fileName) { std::string dirPath = File::GetSysDirectory(); + std::string filePath = dirPath + "GameFiles/GALE01/" + fileName; // TODO: Handle other games? if (File::Exists(filePath)) @@ -26,23 +28,6 @@ std::string getFilePath(std::string fileName) return ""; } -// SLIPPITODO: Revisit. Modified this function a bit, unsure of functionality -void ReadFileToBuffer(std::string& fileName, std::vector& buf) -{ - // Clear anything that was in the buffer - buf.clear(); - - // Don't do anything if a game is not running - if (Core::GetState() != Core::State::Running) - return; - - File::IOFile file(fileName, "rb"); - auto fileSize = file.GetSize(); - buf.resize(fileSize); - size_t bytes_read; - file.ReadArray(buf.data(), std::min(file.GetSize(), buf.size()), &bytes_read); -} - u32 SlippiGameFileLoader::LoadFile(std::string fileName, std::string& data) { if (fileCache.count(fileName)) @@ -64,14 +49,13 @@ u32 SlippiGameFileLoader::LoadFile(std::string fileName, std::string& data) std::string fileContents; File::ReadFileToString(gameFilePath, fileContents); - if (gameFilePath.substr(gameFilePath.length() - 5) == ".diff") + // If the file was a diff file and the game is running, load the main file from ISO and apply patch + if (gameFilePath.substr(gameFilePath.length() - 5) == ".diff" && Core::GetState() == Core::State::Running) { - // If the file was a diff file, load the main file from ISO and apply patch std::vector buf; INFO_LOG(SLIPPI, "Will process diff"); - ReadFileToBuffer(fileName, buf); + DVDThread::ReadFile(fileName, buf); std::string diffContents = fileContents; - decoder.Decode((char*)buf.data(), buf.size(), diffContents, &fileContents); } diff --git a/Source/Core/Core/Slippi/SlippiUser.cpp b/Source/Core/Core/Slippi/SlippiUser.cpp index 479717cf44..4d53760ead 100644 --- a/Source/Core/Core/Slippi/SlippiUser.cpp +++ b/Source/Core/Core/Slippi/SlippiUser.cpp @@ -149,7 +149,7 @@ void SlippiUser::UpdateFile() void SlippiUser::UpdateApp() { #ifdef _WIN32 - auto isoPath = SConfig::GetInstance().m_strBootROM; + auto isoPath = SConfig::GetInstance().m_strIsoPath; std::string path = File::GetExeDirectory() + "/dolphin-slippi-tools.exe"; std::string echoMsg = "echo Starting update process. If nothing happen after a few "