Skip to content

Commit

Permalink
Unify the way of setting game ID, title ID, revision
Browse files Browse the repository at this point in the history
The existing code from ConfigManager, ES and MIOS is merged
into a new set of functions called SetRunningGameMetadata.
  • Loading branch information
JosJuice committed Mar 9, 2017
1 parent 883bec8 commit ced1614
Show file tree
Hide file tree
Showing 21 changed files with 126 additions and 117 deletions.
3 changes: 1 addition & 2 deletions Source/Core/Core/BootManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,7 @@ void Stop()
void RestoreConfig()
{
SConfig::GetInstance().LoadSettingsFromSysconf();
SConfig::GetInstance().m_strGameID = "00000000";
SConfig::GetInstance().m_title_id = 0;
SConfig::GetInstance().ResetRunningGameMetadata();
config_cache.RestoreConfig(&SConfig::GetInstance());
}

Expand Down
108 changes: 74 additions & 34 deletions Source/Core/Core/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@
#include "Core/Boot/Boot.h"
#include "Core/Boot/Boot_DOL.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h" // for bWii
#include "Core/Core.h"
#include "Core/FifoPlayer/FifoDataFile.h"
#include "Core/HLE/HLE.h"
#include "Core/HW/SI/SI.h"
#include "Core/IOS/ES/Formats.h"
#include "Core/IOS/USB/Bluetooth/BTBase.h"
#include "Core/PatchEngine.h"
#include "Core/PowerPC/PPCSymbolDB.h"
#include "Core/PowerPC/PowerPC.h"
#include "VideoCommon/HiresTextures.h"

#include "DiscIO/Enums.h"
#include "DiscIO/NANDContentLoader.h"
Expand Down Expand Up @@ -726,6 +731,67 @@ void SConfig::LoadSettingsFromSysconf()
bPAL60 = sysconf.GetData<u8>("IPL.E60") != 0;
}

void SConfig::ResetRunningGameMetadata()
{
SetRunningGameMetadata("00000000", 0, 0);
}

void SConfig::SetRunningGameMetadata(const DiscIO::IVolume& volume)
{
u64 title_id = 0;
volume.GetTitleID(&title_id);
SetRunningGameMetadata(volume.GetGameID(), title_id, volume.GetRevision());
}

void SConfig::SetRunningGameMetadata(const IOS::ES::TMDReader& tmd)
{
const u64 title_id = tmd.GetTitleId();
std::string game_id;

if (IOS::ES::IsDiscTitle(title_id))
{
const u32 title_identifier = Common::swap32(static_cast<u32>(title_id));
const u16 group_id = Common::swap16(tmd.GetGroupId());

char ascii_game_id[6];
std::memcpy(ascii_game_id, &title_identifier, sizeof(title_identifier));
std::memcpy(ascii_game_id + sizeof(title_identifier), &group_id, sizeof(group_id));

game_id = ascii_game_id;
}
else
{
game_id = StringFromFormat("%016" PRIX64, title_id);
}

SetRunningGameMetadata(game_id, title_id, tmd.GetTitleVersion());
}

void SConfig::SetRunningGameMetadata(const std::string& game_id, u64 title_id, u16 revision)
{
const bool was_changed = m_game_id != game_id || m_title_id != title_id || m_revision != revision;
m_game_id = game_id;
m_title_id = title_id;
m_revision = revision;

if (was_changed)
{
NOTICE_LOG(BOOT, "Game ID set to %s", game_id.c_str());

if (Core::IsRunning())
{
// TODO: have a callback mechanism for title changes?
g_symbolDB.Clear();
CBoot::LoadMapFromFilename();
HLE::Clear();
HLE::PatchFunctions();
PatchEngine::Shutdown();
PatchEngine::LoadPatches();
HiresTexture::Update();
}
}
}

void SConfig::LoadDefaults()
{
bEnableDebugging = false;
Expand Down Expand Up @@ -783,9 +849,7 @@ void SConfig::LoadDefaults()
bJITSystemRegistersOff = false;
bJITBranchOff = false;

m_strGameID = "00000000";
m_title_id = 0;
m_revision = 0;
ResetRunningGameMetadata();
}

bool SConfig::IsUSBDeviceWhitelisted(const std::pair<u16, u16> vid_pid) const
Expand Down Expand Up @@ -870,9 +934,7 @@ bool SConfig::AutoSetup(EBootBS2 _BootBS2)
m_strFilename.c_str());
return false;
}
m_strGameID = pVolume->GetGameID();
pVolume->GetTitleID(&m_title_id);
m_revision = pVolume->GetRevision();
SetRunningGameMetadata(*pVolume);

// Check if we have a Wii disc
bWii = pVolume->GetVolumeType() == DiscIO::Platform::WII_DISC;
Expand Down Expand Up @@ -916,11 +978,11 @@ bool SConfig::AutoSetup(EBootBS2 _BootBS2)
}
else if (DiscIO::CNANDContentManager::Access().GetNANDLoader(m_strFilename).IsValid())
{
std::unique_ptr<DiscIO::IVolume> pVolume(DiscIO::CreateVolumeFromFilename(m_strFilename));
const DiscIO::CNANDContentLoader& ContentLoader =
const DiscIO::CNANDContentLoader& content_loader =
DiscIO::CNANDContentManager::Access().GetNANDLoader(m_strFilename);
const IOS::ES::TMDReader& tmd = content_loader.GetTMD();

if (ContentLoader.GetContentByIndex(ContentLoader.GetTMD().GetBootIndex()) == nullptr)
if (content_loader.GetContentByIndex(tmd.GetBootIndex()) == nullptr)
{
// WAD is valid yet cannot be booted. Install instead.
u64 installed = DiscIO::CNANDContentManager::Access().Install_WiiWAD(m_strFilename);
Expand All @@ -929,33 +991,11 @@ bool SConfig::AutoSetup(EBootBS2 _BootBS2)
return false; // do not boot
}

SetRegion(ContentLoader.GetTMD().GetRegion(), &set_region_dir);
SetRegion(tmd.GetRegion(), &set_region_dir);
SetRunningGameMetadata(tmd);

bWii = true;
m_BootType = BOOT_WII_NAND;

if (pVolume)
{
m_strGameID = pVolume->GetGameID();
pVolume->GetTitleID(&m_title_id);
}
else
{
// null pVolume means that we are loading from nand folder (Most Likely Wii Menu)
// if this is the second boot we would be using the Name and id of the last title
m_strGameID.clear();
m_title_id = 0;
}

// Use the TitleIDhex for name and/or game ID if launching
// from nand folder or if it is not ascii characters
// (specifically sysmenu could potentially apply to other things)
std::string titleidstr = StringFromFormat("%016" PRIx64, m_title_id);

if (m_strGameID.empty())
{
m_strGameID = titleidstr;
}
}
else
{
Expand Down
24 changes: 20 additions & 4 deletions Source/Core/Core/ConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ namespace DiscIO
{
enum class Language;
enum class Region;
class IVolume;
}
namespace IOS
{
namespace ES
{
class TMDReader;
}
}

// DSP Backend Types
Expand Down Expand Up @@ -209,17 +217,20 @@ struct SConfig : NonCopyable
std::string m_strDefaultISO;
std::string m_strDVDRoot;
std::string m_strApploader;
std::string m_strGameID;
u64 m_title_id;
std::string m_strWiiSDCardPath;
u16 m_revision;

std::string m_perfDir;

const std::string& GetGameID() const { return m_game_id; }
u64 GetTitleID() const { return m_title_id; }
u16 GetRevision() const { return m_revision; }
void ResetRunningGameMetadata();
void SetRunningGameMetadata(const DiscIO::IVolume& volume);
void SetRunningGameMetadata(const IOS::ES::TMDReader& tmd);

void LoadDefaults();
static const char* GetDirectoryForRegion(DiscIO::Region region);
bool AutoSetup(EBootBS2 _BootBS2);
const std::string& GetGameID() const { return m_strGameID; }
void CheckMemcardPath(std::string& memcardPath, const std::string& gameRegion, bool isSlotA);
DiscIO::Language GetCurrentLanguage(bool wii) const;

Expand Down Expand Up @@ -373,7 +384,12 @@ struct SConfig : NonCopyable
void LoadUSBPassthroughSettings(IniFile& ini);
void LoadSysconfSettings(IniFile& ini);

void SetRunningGameMetadata(const std::string& game_id, u64 title_id, u16 revision);
bool SetRegion(DiscIO::Region region, std::string* directory_name);

static SConfig* m_Instance;

std::string m_game_id;
u64 m_title_id;
u16 m_revision;
};
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void CEXIMemoryCard::SetupGciFolder(u16 sizeMb)
{
DiscIO::Region region = SConfig::GetInstance().m_region;

std::string game_id = SConfig::GetInstance().m_strGameID;
const std::string& game_id = SConfig::GetInstance().GetGameID();
u32 CurrentGameId = 0;
if (game_id.length() >= 4 && game_id != "00000000" && game_id != TITLEID_SYSMENU_STRING)
CurrentGameId = BE32((u8*)game_id.c_str());
Expand Down
49 changes: 3 additions & 46 deletions Source/Core/Core/IOS/ES/ES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,12 @@
#include "Common/MsgHandler.h"
#include "Common/NandPaths.h"
#include "Common/Swap.h"
#include "Core/Boot/Boot.h"
#include "Core/ConfigManager.h"
#include "Core/HLE/HLE.h"
#include "Core/HW/Memmap.h"
#include "Core/IOS/ES/Formats.h"
#include "Core/PatchEngine.h"
#include "Core/PowerPC/PPCSymbolDB.h"
#include "Core/ec_wii.h"
#include "DiscIO/NANDContentLoader.h"
#include "DiscIO/Volume.h"
#include "VideoCommon/HiresTextures.h"

namespace IOS
{
Expand All @@ -48,7 +43,6 @@ struct TitleContext
void DoState(PointerWrap& p);
void Update(const DiscIO::CNANDContentLoader& content_loader);
void Update(const IOS::ES::TMDReader& tmd_, const IOS::ES::TicketReader& ticket_);
void UpdateRunningGame() const;

IOS::ES::TicketReader ticket;
IOS::ES::TMDReader tmd;
Expand Down Expand Up @@ -86,12 +80,6 @@ constexpr const u8* s_key_table[11] = {
s_key_empty, // Unknown
};

static bool IsDiscTitle(u64 title_id)
{
return IsTitleType(title_id, IOS::ES::TitleType::Game) ||
IsTitleType(title_id, IOS::ES::TitleType::GameWithChannel);
}

ES::ES(u32 device_id, const std::string& device_name) : Device(device_id, device_name)
{
}
Expand Down Expand Up @@ -145,43 +133,11 @@ void TitleContext::Update(const IOS::ES::TMDReader& tmd_, const IOS::ES::TicketR
// Interesting title changes (channel or disc game launch) always happen after an IOS reload.
if (first_change)
{
UpdateRunningGame();
SConfig::GetInstance().SetRunningGameMetadata(tmd);
first_change = false;
}
}

void TitleContext::UpdateRunningGame() const
{
if (IsDiscTitle(tmd.GetTitleId()))
{
const u32 title_identifier = Common::swap32(static_cast<u32>(tmd.GetTitleId()));
const u16 group_id = Common::swap16(tmd.GetGroupId());

char ascii_game_id[6];
std::memcpy(ascii_game_id, &title_identifier, sizeof(title_identifier));
std::memcpy(ascii_game_id + sizeof(title_identifier), &group_id, sizeof(group_id));

SConfig::GetInstance().m_strGameID = ascii_game_id;
}
else
{
SConfig::GetInstance().m_strGameID = StringFromFormat("%016" PRIX64, tmd.GetTitleId());
}

SConfig::GetInstance().m_title_id = tmd.GetTitleId();

// TODO: have a callback mechanism for title changes?
g_symbolDB.Clear();
CBoot::LoadMapFromFilename();
::HLE::Clear();
::HLE::PatchFunctions();
PatchEngine::Shutdown();
PatchEngine::LoadPatches();
HiresTexture::Update();

NOTICE_LOG(IOS_ES, "Active title: %016" PRIx64, tmd.GetTitleId());
}

void ES::LoadWAD(const std::string& _rContentFile)
{
s_content_file = _rContentFile;
Expand Down Expand Up @@ -1040,7 +996,8 @@ IPCCommandResult ES::GetTitles(const IOCtlVRequest& request)
static bool ShouldReturnFakeViewsForIOSes(u64 title_id)
{
const bool ios = IsTitleType(title_id, IOS::ES::TitleType::System) && title_id != TITLEID_SYSMENU;
const bool disc_title = s_title_context.active && IsDiscTitle(s_title_context.tmd.GetTitleId());
const bool disc_title =
s_title_context.active && IOS::ES::IsDiscTitle(s_title_context.tmd.GetTitleId());
return ios && SConfig::GetInstance().m_BootType == SConfig::BOOT_ISO && disc_title;
}

Expand Down
6 changes: 6 additions & 0 deletions Source/Core/Core/IOS/ES/Formats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ bool IsTitleType(u64 title_id, TitleType title_type)
return static_cast<u32>(title_id >> 32) == static_cast<u32>(title_type);
}

bool IsDiscTitle(u64 title_id)
{
return IsTitleType(title_id, TitleType::Game) ||
IsTitleType(title_id, TitleType::GameWithChannel);
}

bool Content::IsShared() const
{
return (type & 0x8000) != 0;
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Core/IOS/ES/Formats.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum class TitleType : u32
};

bool IsTitleType(u64 title_id, TitleType title_type);
bool IsDiscTitle(u64 title_id);

#pragma pack(push, 4)
struct TMDHeader
Expand Down
12 changes: 1 addition & 11 deletions Source/Core/Core/IOS/MIOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "Common/MsgHandler.h"
#include "Common/NandPaths.h"
#include "Common/Swap.h"
#include "Core/Boot/Boot.h"
#include "Core/Boot/ElfReader.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
Expand Down Expand Up @@ -124,17 +123,8 @@ static void ReinitHardware()
static void UpdateRunningGame()
{
DVDThread::WaitUntilIdle();
const DiscIO::IVolume& volume = DVDInterface::GetVolume();
SConfig::GetInstance().m_BootType = SConfig::BOOT_MIOS;
SConfig::GetInstance().m_strGameID = volume.GetGameID();
SConfig::GetInstance().m_revision = volume.GetRevision();

g_symbolDB.Clear();
CBoot::LoadMapFromFilename();
::HLE::Clear();
::HLE::PatchFunctions();

NOTICE_LOG(IOS, "Running game: %s", SConfig::GetInstance().m_strGameID.c_str());
SConfig::GetInstance().SetRunningGameMetadata(DVDInterface::GetVolume());
}

constexpr u32 ADDRESS_INIT_SEMAPHORE = 0x30f8;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/Movie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,7 @@ void GetSettings()
s_bNetPlay = NetPlay::IsNetPlayRunning();
if (SConfig::GetInstance().bWii)
{
u64 title_id = SConfig::GetInstance().m_title_id;
u64 title_id = SConfig::GetInstance().GetTitleID();
s_bClearSave =
!File::Exists(Common::GetTitleDataPath(title_id, Common::FROM_SESSION_ROOT) + "banner.bin");
s_language = SConfig::GetInstance().m_wii_language;
Expand Down

0 comments on commit ced1614

Please sign in to comment.