Merge pull request #9756 from Techjar/memcard-size-config

Replace MemoryCard251 setting with generic MemoryCardSize
This commit is contained in:
Léo Lam 2021-06-13 16:09:54 +02:00 committed by GitHub
commit d536a50878
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 48 additions and 23 deletions

View File

@ -4,7 +4,7 @@
# Values set here will override the main Dolphin settings.
# This game does not work properly with large memorycards, use a 251 block card
# see https://www.nintendo.com/consumer/memorycard1019.jsp
MemoryCard251 = True
MemoryCardSize = 2
[OnLoad]
# Add memory patches to be loaded once on boot here.

View File

@ -4,7 +4,7 @@
# Values set here will override the main Dolphin settings.
# This game does not work properly with large memorycards, use a 251 block card
# see https://www.nintendo.com/consumer/memorycard1019.jsp
MemoryCard251 = True
MemoryCardSize = 2
[OnLoad]
# Add memory patches to be loaded once on boot here.

View File

@ -2,4 +2,4 @@
[Core]
# Values set here will override the main Dolphin settings.
MemoryCard251 = True
MemoryCardSize = 2

View File

@ -0,0 +1,4 @@
# GPXJ01 - Pokémon Box: Ruby & Sapphire (JAP)
[Core]
MemoryCardSize = 0

View File

@ -2,7 +2,7 @@
[Core]
# Values set here will override the main Dolphin settings.
MemoryCard251 = True
MemoryCardSize = 2
[OnLoad]
# Add memory patches to be loaded once on boot here.
@ -14,4 +14,4 @@ MemoryCard251 = True
# Add action replay cheats here.
[Video_Hacks]
ImmediateXFBEnable = False
ImmediateXFBEnable = False

View File

@ -4,7 +4,7 @@
# Values set here will override the main Dolphin settings.
# This game does not work properly with large memorycards, use a 251 block card
# see https://www.nintendo.com/consumer/memorycard1019.jsp
MemoryCard251 = True
MemoryCardSize = 2
CPUThread = False
[OnLoad]

View File

@ -75,11 +75,12 @@ void Init()
CEXIMemoryCard::Init();
{
bool use_memcard_251;
u16 size_mbits = Memcard::MBIT_SIZE_MEMORY_CARD_2043;
int size_override;
IniFile gameIni = SConfig::GetInstance().LoadGameIni();
gameIni.GetOrCreateSection("Core")->Get("MemoryCard251", &use_memcard_251, false);
const u16 size_mbits =
use_memcard_251 ? Memcard::MBIT_SIZE_MEMORY_CARD_251 : Memcard::MBIT_SIZE_MEMORY_CARD_2043;
gameIni.GetOrCreateSection("Core")->Get("MemoryCardSize", &size_override, -1);
if (size_override >= 0 && size_override <= 4)
size_mbits = Memcard::MBIT_SIZE_MEMORY_CARD_59 << size_override;
const bool shift_jis =
SConfig::ToGameCubeRegion(SConfig::GetInstance().m_region) == DiscIO::Region::NTSC_J;
const CardFlashId& flash_id = g_SRAM.settings_ex.flash_id[Memcard::SLOT_A];

View File

@ -236,8 +236,11 @@ void CEXIMemoryCard::SetupRawMemcard(u16 size_mb)
SConfig::GetDirectoryForRegion(SConfig::ToGameCubeRegion(SConfig::GetInstance().m_region));
MemoryCard::CheckPath(filename, region_dir, is_slot_a);
if (size_mb == Memcard::MBIT_SIZE_MEMORY_CARD_251)
filename.insert(filename.find_last_of('.'), ".251");
if (size_mb < Memcard::MBIT_SIZE_MEMORY_CARD_2043)
{
filename.insert(filename.find_last_of('.'),
fmt::format(".{}", Memcard::MbitToFreeBlocks(size_mb)));
}
m_memory_card = std::make_unique<MemoryCard>(filename, m_card_index, size_mb);
}

View File

@ -673,7 +673,7 @@ std::optional<DEntry> GCMemcard::GetDEntry(u8 index) const
BlockAlloc::BlockAlloc(u16 size_mbits)
{
memset(this, 0, BLOCK_SIZE);
m_free_blocks = (size_mbits * MBIT_TO_BLOCKS) - MC_FST_BLOCKS;
m_free_blocks = MbitToFreeBlocks(size_mbits);
m_last_allocated_block = 4;
FixChecksums();
}

View File

@ -141,6 +141,11 @@ constexpr u8 MEMORY_CARD_ICON_FORMAT_CI8_UNIQUE_PALETTE = 3;
// each palette entry is 16 bits in RGB5A3 format
constexpr u32 MEMORY_CARD_CI8_PALETTE_ENTRIES = 256;
constexpr u32 MbitToFreeBlocks(u16 size_mb)
{
return size_mb * MBIT_TO_BLOCKS - MC_FST_BLOCKS;
}
struct GCMBlock
{
GCMBlock();

View File

@ -204,8 +204,7 @@ GCMemcardDirectory::GCMemcardDirectory(const std::string& directory, int slot,
}
// leave about 10% of free space on the card if possible
const int total_blocks =
m_hdr.m_data.m_size_mb * Memcard::MBIT_TO_BLOCKS - Memcard::MC_FST_BLOCKS;
const int total_blocks = Memcard::MbitToFreeBlocks(m_hdr.m_data.m_size_mb);
const int reserved_blocks = total_blocks / 10;
// load files for other games

View File

@ -41,6 +41,7 @@
#include "Core/ConfigManager.h"
#include "Core/GeckoCode.h"
#include "Core/HW/EXI/EXI_DeviceIPL.h"
#include "Core/HW/GCMemcard/GCMemcard.h"
#include "Core/HW/SI/SI.h"
#include "Core/HW/SI/SI_Device.h"
#include "Core/HW/SI/SI_DeviceGCController.h"
@ -861,8 +862,8 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
bool is_slot_a;
std::string region;
bool mc251;
packet >> is_slot_a >> region >> mc251;
int size_override;
packet >> is_slot_a >> region >> size_override;
// This check is mainly intended to filter out characters which have special meanings in paths
if (region != JAP_DIR && region != USA_DIR && region != EUR_DIR)
@ -871,8 +872,15 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
return 0;
}
std::string size_suffix;
if (size_override >= 0 && size_override <= 4)
{
size_suffix = fmt::format(
".{}", Memcard::MbitToFreeBlocks(Memcard::MBIT_SIZE_MEMORY_CARD_59 << size_override));
}
const std::string path = File::GetUserPath(D_GCUSER_IDX) + GC_MEMCARD_NETPLAY +
(is_slot_a ? "A." : "B.") + region + (mc251 ? ".251" : "") + ".raw";
(is_slot_a ? "A." : "B.") + region + size_suffix + ".raw";
if (File::Exists(path) && !File::Delete(path))
{
PanicAlertFmtT("Failed to delete NetPlay memory card. Verify your write permissions.");

View File

@ -43,6 +43,7 @@
#include "Core/ConfigManager.h"
#include "Core/GeckoCode.h"
#include "Core/GeckoCodeConfig.h"
#include "Core/HW/GCMemcard/GCMemcard.h"
#include "Core/HW/GCMemcard/GCMemcardDirectory.h"
#include "Core/HW/GCMemcard/GCMemcardRaw.h"
#include "Core/HW/Sram.h"
@ -1584,17 +1585,21 @@ bool NetPlayServer::SyncSaveData()
MemoryCard::CheckPath(path, region, is_slot_a);
bool mc251;
int size_override;
IniFile gameIni = SConfig::LoadGameIni(game->GetGameID(), game->GetRevision());
gameIni.GetOrCreateSection("Core")->Get("MemoryCard251", &mc251, false);
gameIni.GetOrCreateSection("Core")->Get("MemoryCardSize", &size_override, -1);
if (mc251)
path.insert(path.find_last_of('.'), ".251");
if (size_override >= 0 && size_override <= 4)
{
path.insert(path.find_last_of('.'),
fmt::format(".{}", Memcard::MbitToFreeBlocks(Memcard::MBIT_SIZE_MEMORY_CARD_59
<< size_override)));
}
sf::Packet pac;
pac << static_cast<MessageId>(NP_MSG_SYNC_SAVE_DATA);
pac << static_cast<MessageId>(SYNC_SAVE_DATA_RAW);
pac << is_slot_a << region << mc251;
pac << is_slot_a << region << size_override;
if (File::Exists(path))
{