Add CDvdFile::SetRootDirectory; load proper DOL for Wii versions

This commit is contained in:
Luke Street 2022-02-23 02:04:31 -05:00
parent acb137c790
commit 049a7764b8
4 changed files with 47 additions and 9 deletions

View File

@ -94,6 +94,7 @@ std::condition_variable CDvdFile::m_WorkerCV;
std::mutex CDvdFile::m_WaitMutex;
std::atomic_bool CDvdFile::m_WorkerRun = {false};
std::vector<std::shared_ptr<IDvdRequest>> CDvdFile::m_RequestQueue;
std::string CDvdFile::m_rootDirectory;
CDvdFile::CDvdFile(std::string_view path) : x18_path(path) {
auto* node = ResolvePath(path);
@ -169,6 +170,13 @@ nod::Node* CDvdFile::ResolvePath(std::string_view path) {
if (path.starts_with('/')) {
path.remove_prefix(1);
}
std::string prefixedPath;
if (!m_rootDirectory.empty()) {
prefixedPath = m_rootDirectory;
prefixedPath += '/';
prefixedPath += path;
path = prefixedPath;
}
auto* node = &m_DvdRoot->getDataPartition()->getFSTRoot();
while (node != nullptr && !path.empty()) {
std::string component;
@ -232,4 +240,6 @@ SDiscInfo CDvdFile::DiscInfo() {
return out;
}
void CDvdFile::SetRootDirectory(const std::string_view& rootDir) { m_rootDirectory = rootDir; }
} // namespace metaforce

View File

@ -39,6 +39,7 @@ class CDvdFile {
static std::mutex m_WaitMutex;
static std::atomic_bool m_WorkerRun;
static std::vector<std::shared_ptr<IDvdRequest>> m_RequestQueue;
static std::string m_rootDirectory;
static void WorkerProc();
std::string x18_path;
@ -52,6 +53,7 @@ class CDvdFile {
public:
static bool Initialize(const std::string_view& path);
static SDiscInfo DiscInfo();
static void SetRootDirectory(const std::string_view& rootDir);
static void Shutdown();
CDvdFile(std::string_view path);

View File

@ -18,11 +18,16 @@ enum class EGame {
MetroidPrime3,
MetroidPrimeTrilogy,
};
enum class EPlatform {
GameCube,
Wii,
};
struct MetaforceVersionInfo {
std::string version;
ERegion region;
EGame game;
EPlatform platform;
std::string gameTitle;
};

View File

@ -589,14 +589,24 @@ void CMain::Init(const FileStoreManager& storeMgr, CVarManager* cvarMgr, boo::IA
if (discInfo.gameId[4] != '0' || discInfo.gameId[5] != '1') {
Log.report(logvisor::Fatal, FMT_STRING("Unknown game ID {}"), std::string_view{discInfo.gameId.data(), 6});
}
if (strncmp(discInfo.gameId.data(), "GM8", 3) == 0 || strncmp(discInfo.gameId.data(), "R3I", 3) == 0) {
if (strncmp(discInfo.gameId.data(), "GM8", 3) == 0) {
m_version.game = EGame::MetroidPrime1;
} else if (strncmp(discInfo.gameId.data(), "G2M", 3) == 0 || strncmp(discInfo.gameId.data(), "R32", 3) == 0) {
m_version.platform = EPlatform::GameCube;
} else if (strncmp(discInfo.gameId.data(), "R3I", 3) == 0) {
m_version.game = EGame::MetroidPrime1;
m_version.platform = EPlatform::Wii;
} else if (strncmp(discInfo.gameId.data(), "G2M", 3) == 0) {
m_version.game = EGame::MetroidPrime2;
} else if (strncmp(discInfo.gameId.data(), "R3M", 3) == 0) {
m_version.game = EGame::MetroidPrime3;
m_version.platform = EPlatform::GameCube;
} else if (strncmp(discInfo.gameId.data(), "R32", 3) == 0) {
m_version.game = EGame::MetroidPrime2;
m_version.platform = EPlatform::Wii;
} else if (strncmp(discInfo.gameId.data(), "RM3", 3) == 0) {
m_version.game = EGame::MetroidPrime3;
m_version.platform = EPlatform::Wii;
} else if (strncmp(discInfo.gameId.data(), "R3M", 3) == 0) {
m_version.game = EGame::MetroidPrimeTrilogy;
m_version.platform = EPlatform::Wii;
} else {
Log.report(logvisor::Fatal, FMT_STRING("Unknown game ID {}"), std::string_view{discInfo.gameId.data(), 6});
}
@ -625,9 +635,15 @@ void CMain::Init(const FileStoreManager& storeMgr, CVarManager* cvarMgr, boo::IA
}
{
CDvdFile file("default.dol");
std::string_view dolFile = "default.dol"sv;
if (m_version.game == EGame::MetroidPrimeTrilogy) {
dolFile = "rs5mp1_p.dol";
} else if (m_version.platform == EPlatform::Wii) {
dolFile = "rs5mp1jpn_p.dol";
}
CDvdFile file(dolFile);
if (!file) {
Log.report(logvisor::Fatal, FMT_STRING("Failed to open default.dol"));
Log.report(logvisor::Fatal, FMT_STRING("Failed to open {}"), dolFile);
}
std::unique_ptr<u8[]> buf = std::make_unique<u8[]>(file.Length());
u32 readLen = file.SyncRead(buf.get(), file.Length());
@ -638,6 +654,14 @@ void CMain::Init(const FileStoreManager& storeMgr, CVarManager* cvarMgr, boo::IA
m_version.version = buildInfo;
}
MainLog.report(logvisor::Level::Info, FMT_STRING("Loading data from {} {} ({})"), GetGameTitle(),
magic_enum::enum_name(GetRegion()), GetVersionString());
if (m_version.game == EGame::MetroidPrimeTrilogy) {
CDvdFile::SetRootDirectory("MP1");
} else if (m_version.platform == EPlatform::Wii) {
CDvdFile::SetRootDirectory("MP1JPN");
}
InitializeSubsystems();
AddOverridePaks();
x128_globalObjects->PostInitialize();
@ -645,9 +669,6 @@ void CMain::Init(const FileStoreManager& storeMgr, CVarManager* cvarMgr, boo::IA
x70_tweaks.RegisterResourceTweaks(m_cvarMgr);
AddWorldPaks();
MainLog.report(logvisor::Level::Info, FMT_STRING("Loading data from {} {} ({})"),
GetGameTitle(), magic_enum::enum_name(GetRegion()), GetVersionString());
auto args = aurora::get_args();
for (auto it = args.begin(); it != args.end(); ++it) {
if (*it == "--warp" && args.end() - it >= 3) {