mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-06-08 05:53:28 +00:00
Fix memcard path CVars and add menu notifying player when they've been reset
This commit is contained in:
parent
561e54527b
commit
c6db983c41
@ -336,6 +336,9 @@ ECardResult CMemoryCardSys::CCardFileInfo::WriteFile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ECardResult CMemoryCardSys::CCardFileInfo::CloseFile() { return CMemoryCardSys::CloseFile(m_handle); }
|
ECardResult CMemoryCardSys::CCardFileInfo::CloseFile() { return CMemoryCardSys::CloseFile(m_handle); }
|
||||||
|
kabufuda::SystemString CMemoryCardSys::_GetDolphinCardPath(kabufuda::ECardSlot slot) {
|
||||||
|
return g_CardImagePaths[static_cast<u32>(slot)];
|
||||||
|
}
|
||||||
|
|
||||||
void CMemoryCardSys::_ResolveDolphinCardPath(const hecl::CVar* cv, kabufuda::ECardSlot slot) {
|
void CMemoryCardSys::_ResolveDolphinCardPath(const hecl::CVar* cv, kabufuda::ECardSlot slot) {
|
||||||
#if CARD_UCS2
|
#if CARD_UCS2
|
||||||
@ -559,19 +562,31 @@ void CMemoryCardSys::CommitToDisk(kabufuda::ECardSlot port) {
|
|||||||
card.commit();
|
card.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
kabufuda::SystemString CMemoryCardSys::CreateDolphinCard(kabufuda::ECardSlot slot) {
|
bool CMemoryCardSys::CreateDolphinCard(kabufuda::ECardSlot slot) {
|
||||||
kabufuda::SystemString path = _CreateDolphinCard(slot);
|
kabufuda::SystemString path =
|
||||||
|
_CreateDolphinCard(slot, slot == kabufuda::ECardSlot::SlotA ? mc_dolphinAPath->hasDefaultValue()
|
||||||
|
: mc_dolphinBPath->hasDefaultValue());
|
||||||
if (CardProbe(slot).x0_error != ECardResult::READY) {
|
if (CardProbe(slot).x0_error != ECardResult::READY) {
|
||||||
return {};
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
MountCard(slot);
|
MountCard(slot);
|
||||||
FormatCard(slot);
|
FormatCard(slot);
|
||||||
kabufuda::Card& card = g_CardStates[int(slot)];
|
kabufuda::Card& card = g_CardStates[int(slot)];
|
||||||
card.waitForCompletion();
|
card.waitForCompletion();
|
||||||
return path;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CMemoryCardSys::_ResetCVar(kabufuda::ECardSlot slot) {
|
||||||
|
switch(slot) {
|
||||||
|
case kabufuda::ECardSlot::SlotA:
|
||||||
|
mc_dolphinAPath->fromLiteral("");
|
||||||
|
break;
|
||||||
|
case kabufuda::ECardSlot::SlotB:
|
||||||
|
mc_dolphinBPath->fromLiteral("");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
void CMemoryCardSys::Shutdown() {
|
void CMemoryCardSys::Shutdown() {
|
||||||
UnmountCard(kabufuda::ECardSlot::SlotA);
|
UnmountCard(kabufuda::ECardSlot::SlotA);
|
||||||
UnmountCard(kabufuda::ECardSlot::SlotB);
|
UnmountCard(kabufuda::ECardSlot::SlotB);
|
||||||
|
@ -67,10 +67,12 @@ class CMemoryCardSys {
|
|||||||
rstl::reserved_vector<u32, 6> x30_scanCategoryCounts;
|
rstl::reserved_vector<u32, 6> x30_scanCategoryCounts;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static void _ResetCVar(kabufuda::ECardSlot slot);
|
||||||
static void _ResolveDolphinCardPath(const hecl::CVar* cv, kabufuda::ECardSlot slot);
|
static void _ResolveDolphinCardPath(const hecl::CVar* cv, kabufuda::ECardSlot slot);
|
||||||
static kabufuda::SystemString ResolveDolphinCardPath(kabufuda::ECardSlot slot);
|
static kabufuda::SystemString ResolveDolphinCardPath(kabufuda::ECardSlot slot);
|
||||||
static kabufuda::SystemString CreateDolphinCard(kabufuda::ECardSlot slot);
|
static bool CreateDolphinCard(kabufuda::ECardSlot slot);
|
||||||
static kabufuda::SystemString _CreateDolphinCard(kabufuda::ECardSlot slot);
|
static kabufuda::SystemString _GetDolphinCardPath(kabufuda::ECardSlot slot);
|
||||||
|
static kabufuda::SystemString _CreateDolphinCard(kabufuda::ECardSlot slot, bool dolphin);
|
||||||
|
|
||||||
using ECardResult = kabufuda::ECardResult;
|
using ECardResult = kabufuda::ECardResult;
|
||||||
struct CardResult {
|
struct CardResult {
|
||||||
|
@ -31,8 +31,9 @@ kabufuda::SystemString CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlo
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot slot) {
|
kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot slot, bool dolphin) {
|
||||||
if (g_Main->IsUSA() && !g_Main->IsTrilogy()) {
|
if (g_Main->IsUSA() && !g_Main->IsTrilogy()) {
|
||||||
|
if (dolphin) {
|
||||||
const char* home = getenv("HOME");
|
const char* home = getenv("HOME");
|
||||||
if (!home || home[0] != '/')
|
if (!home || home[0] != '/')
|
||||||
return {};
|
return {};
|
||||||
@ -47,12 +48,23 @@ kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot sl
|
|||||||
|
|
||||||
path += fmt::format(FMT_STRING("/MemoryCard{:c}.USA.raw"), slot == kabufuda::ECardSlot::SlotA ? 'A' : 'B');
|
path += fmt::format(FMT_STRING("/MemoryCard{:c}.USA.raw"), slot == kabufuda::ECardSlot::SlotA ? 'A' : 'B');
|
||||||
const auto fp = hecl::FopenUnique(path.c_str(), "wb");
|
const auto fp = hecl::FopenUnique(path.c_str(), "wb");
|
||||||
if (fp == nullptr) {
|
if (fp != nullptr) {
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
kabufuda::SystemString path = _GetDolphinCardPath(slot);
|
||||||
|
hecl::SanitizePath(path);
|
||||||
|
if (path.find('/') == kabufuda::SystemString::npos) {
|
||||||
|
path = hecl::GetcwdStr() + _SYS_STR("/") + _GetDolphinCardPath(slot);
|
||||||
|
}
|
||||||
|
hecl::SystemString tmpPath = path.substr(0, path.find_last_of(_SYS_STR("/")));
|
||||||
|
hecl::RecursiveMakeDir(tmpPath.c_str());
|
||||||
|
const auto fp = hecl::FopenUnique(path.c_str(), "wb");
|
||||||
|
if (fp) {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,8 +22,9 @@ kabufuda::SystemString CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlo
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot slot) {
|
kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot slot, bool dolphin) {
|
||||||
if (g_Main->IsUSA() && !g_Main->IsTrilogy()) {
|
if (g_Main->IsUSA() && !g_Main->IsTrilogy()) {
|
||||||
|
if (dolphin) {
|
||||||
const char* home = getenv("HOME");
|
const char* home = getenv("HOME");
|
||||||
if (!home)
|
if (!home)
|
||||||
return {};
|
return {};
|
||||||
@ -40,6 +41,19 @@ kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot sl
|
|||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
|
} else {
|
||||||
|
kabufuda::SystemString path = _GetDolphinCardPath(slot);
|
||||||
|
hecl::SanitizePath(path);
|
||||||
|
if (path.find('/') == kabufuda::SystemString::npos) {
|
||||||
|
path = hecl::GetcwdStr() + _SYS_STR("/") + _GetDolphinCardPath(slot);
|
||||||
|
}
|
||||||
|
hecl::SystemString tmpPath = path.substr(0, path.find_last_of(_SYS_STR("/")));
|
||||||
|
hecl::RecursiveMakeDir(tmpPath.c_str());
|
||||||
|
const auto fp = hecl::FopenUnique(path.c_str(), "wb");
|
||||||
|
if (fp) {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,9 @@ using namespace Windows::Storage;
|
|||||||
/* Partial path-selection logic from
|
/* Partial path-selection logic from
|
||||||
* https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/UICommon/UICommon.cpp
|
* https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/UICommon/UICommon.cpp
|
||||||
* Modified to not use dolphin-binary-relative paths. */
|
* Modified to not use dolphin-binary-relative paths. */
|
||||||
kabufuda::SystemString CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlot slot) {
|
kabufuda::SystemString CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlot slot, bool dolphin) {
|
||||||
if (g_Main->IsUSA() && !g_Main->IsTrilogy()) {
|
if (g_Main->IsUSA() && !g_Main->IsTrilogy()) {
|
||||||
|
if (dolphin) {
|
||||||
#if !WINDOWS_STORE
|
#if !WINDOWS_STORE
|
||||||
/* Detect where the User directory is. There are two different cases
|
/* Detect where the User directory is. There are two different cases
|
||||||
* 1. HKCU\Software\Dolphin Emulator\UserConfigPath exists
|
* 1. HKCU\Software\Dolphin Emulator\UserConfigPath exists
|
||||||
@ -61,6 +62,19 @@ kabufuda::SystemString CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlo
|
|||||||
return {};
|
return {};
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
|
} else {
|
||||||
|
kabufuda::SystemString path = _GetDolphinCardPath(slot);
|
||||||
|
hecl::SanitizePath(path);
|
||||||
|
if (path.find('/') == kabufuda::SystemString::npos) {
|
||||||
|
path = hecl::GetcwdStr() + _SYS_STR("/") + _GetDolphinCardPath(slot);
|
||||||
|
}
|
||||||
|
hecl::SystemString tmpPath = path.substr(0, path.find_last_of(_SYS_STR("/")));
|
||||||
|
hecl::RecursiveMakeDir(tmpPath.c_str());
|
||||||
|
const auto fp = hecl::FopenUnique(path.c_str(), "wb");
|
||||||
|
if (fp) {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -131,6 +131,9 @@ bool CSaveGameScreen::PumpLoad() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CSaveGameScreen::EUIType CSaveGameScreen::SelectUIType() const {
|
CSaveGameScreen::EUIType CSaveGameScreen::SelectUIType() const {
|
||||||
|
if (x10_uiType == EUIType::CreateDolphinCardFailed) {
|
||||||
|
return x10_uiType;
|
||||||
|
}
|
||||||
if (x6c_cardDriver->x10_state == EState::NoCard) {
|
if (x6c_cardDriver->x10_state == EState::NoCard) {
|
||||||
return EUIType::NoCardFound;
|
return EUIType::NoCardFound;
|
||||||
}
|
}
|
||||||
@ -312,6 +315,12 @@ void CSaveGameScreen::SetUIText() {
|
|||||||
opt1 = 15; // No
|
opt1 = 15; // No
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case EUIType::CreateDolphinCardFailed:
|
||||||
|
msgAStr = u"Attempt to create Dolphin Card failed!\n";
|
||||||
|
msgBStr = u"CVars have been reset to defaults.\nMetaforce will use Dolphin's memory cards if available\n";
|
||||||
|
opt0 = -2;
|
||||||
|
opt0Str = u"Press &image=SI,1.0,0.68,05AF9CAA; to proceed.\n";
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -392,7 +401,12 @@ void CSaveGameScreen::DoAdvance([[maybe_unused]] CGuiTableGroup* caller) {
|
|||||||
sfx = x84_navConfirmSfx;
|
sfx = x84_navConfirmSfx;
|
||||||
} else if (userSel == 2 && x10_uiType == EUIType::NoCardFound) {
|
} else if (userSel == 2 && x10_uiType == EUIType::NoCardFound) {
|
||||||
/* Create Dolphin Card */
|
/* Create Dolphin Card */
|
||||||
CMemoryCardSys::CreateDolphinCard(kabufuda::ECardSlot::SlotA);
|
if (!CMemoryCardSys::CreateDolphinCard(kabufuda::ECardSlot::SlotA)) {
|
||||||
|
x10_uiType = EUIType::CreateDolphinCardFailed;
|
||||||
|
sfx = x8c_navBackSfx;
|
||||||
|
x91_uiTextDirty = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
ResetCardDriver();
|
ResetCardDriver();
|
||||||
sfx = x84_navConfirmSfx;
|
sfx = x84_navConfirmSfx;
|
||||||
}
|
}
|
||||||
@ -556,6 +570,15 @@ void CSaveGameScreen::DoAdvance([[maybe_unused]] CGuiTableGroup* caller) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case EUIType::CreateDolphinCardFailed: {
|
||||||
|
if (userSel == 0) {
|
||||||
|
CMemoryCardSys::_ResetCVar(kabufuda::ECardSlot::SlotA);
|
||||||
|
CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlot::SlotA);
|
||||||
|
ResetCardDriver();
|
||||||
|
x10_uiType = EUIType::Empty;
|
||||||
|
sfx = x84_navConfirmSfx;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -41,7 +41,9 @@ public:
|
|||||||
ProgressWillBeLost = 13,
|
ProgressWillBeLost = 13,
|
||||||
NotOriginalCard = 14,
|
NotOriginalCard = 14,
|
||||||
AllDataWillBeLost = 15,
|
AllDataWillBeLost = 15,
|
||||||
SaveReady = 16
|
SaveReady = 16,
|
||||||
|
// Metaforce Addition
|
||||||
|
CreateDolphinCardFailed
|
||||||
};
|
};
|
||||||
|
|
||||||
bool IsHiddenFromFrontEnd() const {
|
bool IsHiddenFromFrontEnd() const {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user