Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback Region Option #9254

Merged
merged 1 commit into from
Nov 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions Source/Core/Core/Config/MainSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "Core/HW/Memmap.h"
#include "Core/HW/SI/SI_Device.h"
#include "Core/PowerPC/PowerPC.h"
#include "DiscIO/Enums.h"
#include "VideoCommon/VideoBackendBase.h"

namespace Config
Expand Down Expand Up @@ -106,6 +107,8 @@ const Info<std::string> MAIN_PERF_MAP_DIR{{System::Main, "Core", "PerfMapDir"},
const Info<bool> MAIN_CUSTOM_RTC_ENABLE{{System::Main, "Core", "EnableCustomRTC"}, false};
// Default to seconds between 1.1.1970 and 1.1.2000
const Info<u32> MAIN_CUSTOM_RTC_VALUE{{System::Main, "Core", "CustomRTCValue"}, 946684800};
const Info<DiscIO::Region> MAIN_FALLBACK_REGION{{System::Main, "Core", "FallbackRegion"},
DiscIO::Region::NTSC_J};
const Info<bool> MAIN_AUTO_DISC_CHANGE{{System::Main, "Core", "AutoDiscChange"}, false};
const Info<bool> MAIN_ALLOW_SD_WRITES{{System::Main, "Core", "WiiSDCardAllowWrites"}, true};
const Info<bool> MAIN_ENABLE_SAVESTATES{{System::Main, "Core", "EnableSaveStates"}, false};
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/Config/MainSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string>

#include "Common/Config/Config.h"
#include "DiscIO/Enums.h"

namespace PowerPC
{
Expand Down Expand Up @@ -88,6 +89,7 @@ extern const Info<u32> MAIN_CUSTOM_RTC_VALUE;
extern const Info<bool> MAIN_AUTO_DISC_CHANGE;
extern const Info<bool> MAIN_ALLOW_SD_WRITES;
extern const Info<bool> MAIN_ENABLE_SAVESTATES;
extern const Info<DiscIO::Region> MAIN_FALLBACK_REGION;

// Main.DSP

Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bool IsSettingSaveable(const Config::Location& config_location)
}
}

static constexpr std::array<const Config::Location*, 16> s_setting_saveable = {
static constexpr std::array<const Config::Location*, 17> s_setting_saveable = {
// Main.Core

&Config::MAIN_DEFAULT_ISO.location,
Expand All @@ -48,6 +48,7 @@ bool IsSettingSaveable(const Config::Location& config_location)
&Config::MAIN_MEM2_SIZE.location,
&Config::MAIN_GFX_BACKEND.location,
&Config::MAIN_ENABLE_SAVESTATES.location,
&Config::MAIN_FALLBACK_REGION.location,

// Main.Interface

Expand Down
14 changes: 2 additions & 12 deletions Source/Core/Core/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "Core/Analytics.h"
#include "Core/Boot/Boot.h"
#include "Core/CommonTitles.h"
#include "Core/Config/MainSettings.h"
#include "Core/Config/SYSCONFSettings.h"
#include "Core/ConfigLoaders/GameConfigLoader.h"
#include "Core/Core.h"
Expand Down Expand Up @@ -929,18 +930,7 @@ bool SConfig::SetPathsAndGameMetadata(const BootParameters& boot)

DiscIO::Region SConfig::GetFallbackRegion()
JosJuice marked this conversation as resolved.
Show resolved Hide resolved
{
// Fall back to the system menu region, if possible.
IOS::HLE::Kernel ios;
const IOS::ES::TMDReader system_menu_tmd = ios.GetES()->FindInstalledTMD(Titles::SYSTEM_MENU);
if (system_menu_tmd.IsValid())
{
const DiscIO::Region region = system_menu_tmd.GetRegion();
if (region != DiscIO::Region::Unknown)
return region;
}

// Fall back to PAL.
return DiscIO::Region::PAL;
return Config::Get(Config::MAIN_FALLBACK_REGION);
}

DiscIO::Language SConfig::GetCurrentLanguage(bool wii) const
Expand Down
15 changes: 15 additions & 0 deletions Source/Core/DolphinQt/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,21 @@ QString Settings::GetAutoUpdateTrack() const
return QString::fromStdString(SConfig::GetInstance().m_auto_update_track);
}

void Settings::SetFallbackRegion(const DiscIO::Region& region)
{
if (region == GetFallbackRegion())
return;

Config::SetBase(Config::MAIN_FALLBACK_REGION, region);

emit FallbackRegionChanged(region);
}

DiscIO::Region Settings::GetFallbackRegion() const
{
return Config::Get(Config::MAIN_FALLBACK_REGION);
}

void Settings::SetAnalyticsEnabled(bool enabled)
{
if (enabled == IsAnalyticsEnabled())
Expand Down
7 changes: 7 additions & 0 deletions Source/Core/DolphinQt/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <QObject>
#include <QSettings>

#include "DiscIO/Enums.h"

namespace Core
{
enum class State;
Expand Down Expand Up @@ -139,6 +141,10 @@ class Settings final : public QObject
QString GetAutoUpdateTrack() const;
void SetAutoUpdateTrack(const QString& mode);

// Fallback Region
DiscIO::Region GetFallbackRegion() const;
void SetFallbackRegion(const DiscIO::Region& region);

// Analytics
bool IsAnalyticsEnabled() const;
void SetAnalyticsEnabled(bool enabled);
Expand Down Expand Up @@ -177,6 +183,7 @@ class Settings final : public QObject
void DebugModeToggled(bool enabled);
void DebugFontChanged(QFont font);
void AutoUpdateTrackChanged(const QString& mode);
void FallbackRegionChanged(const DiscIO::Region& region);
void AnalyticsToggled(bool enabled);
void DevicesChanged();
void SDCardInsertionChanged(bool inserted);
Expand Down
79 changes: 79 additions & 0 deletions Source/Core/DolphinQt/Settings/GeneralPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ constexpr const char* AUTO_UPDATE_STABLE_STRING = "stable";
constexpr const char* AUTO_UPDATE_BETA_STRING = "beta";
constexpr const char* AUTO_UPDATE_DEV_STRING = "dev";

constexpr int FALLBACK_REGION_NTSCJ_INDEX = 0;
constexpr int FALLBACK_REGION_NTSCU_INDEX = 1;
constexpr int FALLBACK_REGION_PAL_INDEX = 2;
constexpr int FALLBACK_REGION_NTSCK_INDEX = 3;

GeneralPane::GeneralPane(QWidget* parent) : QWidget(parent)
{
CreateLayout();
Expand All @@ -63,6 +68,8 @@ void GeneralPane::CreateLayout()
if (AutoUpdateChecker::SystemSupportsAutoUpdates())
CreateAutoUpdate();

CreateFallbackRegion();

#if defined(USE_ANALYTICS) && USE_ANALYTICS
CreateAnalytics();
#endif
Expand All @@ -81,6 +88,7 @@ void GeneralPane::OnEmulationStateChanged(Core::State state)
#ifdef USE_DISCORD_PRESENCE
m_checkbox_discord_presence->setEnabled(!running);
#endif
m_combobox_fallback_region->setEnabled(!running);
}

void GeneralPane::ConnectLayout()
Expand All @@ -106,6 +114,10 @@ void GeneralPane::ConnectLayout()
connect(m_combobox_speedlimit, qOverload<int>(&QComboBox::currentIndexChanged),
[this]() { OnSaveConfig(); });

connect(m_combobox_fallback_region, qOverload<int>(&QComboBox::currentIndexChanged), this,
&GeneralPane::OnSaveConfig);
connect(&Settings::Instance(), &Settings::FallbackRegionChanged, this, &GeneralPane::LoadConfig);

#if defined(USE_ANALYTICS) && USE_ANALYTICS
connect(&Settings::Instance(), &Settings::AnalyticsToggled, this, &GeneralPane::LoadConfig);
connect(m_checkbox_enable_analytics, &QCheckBox::toggled, this, &GeneralPane::OnSaveConfig);
Expand Down Expand Up @@ -179,6 +191,33 @@ void GeneralPane::CreateAutoUpdate()
m_combobox_update_track->addItem(option);
}

void GeneralPane::CreateFallbackRegion()
{
auto* fallback_region_group = new QGroupBox(tr("Fallback Region"));
auto* layout = new QVBoxLayout;
fallback_region_group->setLayout(layout);
m_main_layout->addWidget(fallback_region_group);

m_combobox_fallback_region = new QComboBox(this);

auto* form_widget = new QWidget;
auto* form_layout = new QFormLayout;
form_widget->setLayout(form_layout);
form_layout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
form_layout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
form_layout->addRow(tr("Fallback Region:"), m_combobox_fallback_region);
layout->addWidget(form_widget);

auto* fallback_region_description =
new QLabel(tr("Dolphin will use this for titles whose region cannot be determined "
"automatically."));
fallback_region_description->setWordWrap(true);
layout->addWidget(fallback_region_description);

for (const QString& option : {tr("NTSC-J"), tr("NTSC-U"), tr("PAL"), tr("NTSC-K")})
m_combobox_fallback_region->addItem(option);
}

#if defined(USE_ANALYTICS) && USE_ANALYTICS
void GeneralPane::CreateAnalytics()
{
Expand Down Expand Up @@ -224,6 +263,19 @@ void GeneralPane::LoadConfig()
if (selection < m_combobox_speedlimit->count())
m_combobox_speedlimit->setCurrentIndex(selection);
m_checkbox_dualcore->setChecked(SConfig::GetInstance().bCPUThread);

const auto fallback = Settings::Instance().GetFallbackRegion();

if (fallback == DiscIO::Region::NTSC_J)
m_combobox_fallback_region->setCurrentIndex(FALLBACK_REGION_NTSCJ_INDEX);
else if (fallback == DiscIO::Region::NTSC_U)
m_combobox_fallback_region->setCurrentIndex(FALLBACK_REGION_NTSCU_INDEX);
else if (fallback == DiscIO::Region::PAL)
m_combobox_fallback_region->setCurrentIndex(FALLBACK_REGION_PAL_INDEX);
else if (fallback == DiscIO::Region::NTSC_K)
m_combobox_fallback_region->setCurrentIndex(FALLBACK_REGION_NTSCK_INDEX);
else
m_combobox_fallback_region->setCurrentIndex(FALLBACK_REGION_NTSCJ_INDEX);
}

static QString UpdateTrackFromIndex(int index)
Expand All @@ -249,6 +301,31 @@ static QString UpdateTrackFromIndex(int index)
return value;
}

static DiscIO::Region UpdateFallbackRegionFromIndex(int index)
{
DiscIO::Region value = DiscIO::Region::Unknown;

switch (index)
{
case FALLBACK_REGION_NTSCJ_INDEX:
value = DiscIO::Region::NTSC_J;
break;
case FALLBACK_REGION_NTSCU_INDEX:
value = DiscIO::Region::NTSC_U;
break;
case FALLBACK_REGION_PAL_INDEX:
value = DiscIO::Region::PAL;
break;
case FALLBACK_REGION_NTSCK_INDEX:
value = DiscIO::Region::NTSC_K;
break;
default:
value = DiscIO::Region::NTSC_J;
}

return value;
}

void GeneralPane::OnSaveConfig()
{
Config::ConfigChangeCallbackGuard config_guard;
Expand Down Expand Up @@ -277,6 +354,8 @@ void GeneralPane::OnSaveConfig()
Config::SetBase(Config::MAIN_AUTO_DISC_CHANGE, m_checkbox_auto_disc_change->isChecked());
Config::SetBaseOrCurrent(Config::MAIN_ENABLE_CHEATS, m_checkbox_cheats->isChecked());
settings.m_EmulationSpeed = m_combobox_speedlimit->currentIndex() * 0.1f;
Settings::Instance().SetFallbackRegion(
UpdateFallbackRegionFromIndex(m_combobox_fallback_region->currentIndex()));

settings.SaveSettings();
}
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/DolphinQt/Settings/GeneralPane.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class GeneralPane final : public QWidget
void ConnectLayout();
void CreateBasic();
void CreateAutoUpdate();
void CreateFallbackRegion();

void LoadConfig();
void OnSaveConfig();
Expand All @@ -39,6 +40,7 @@ class GeneralPane final : public QWidget
QVBoxLayout* m_main_layout;
QComboBox* m_combobox_speedlimit;
QComboBox* m_combobox_update_track;
QComboBox* m_combobox_fallback_region;
QCheckBox* m_checkbox_dualcore;
QCheckBox* m_checkbox_cheats;
QCheckBox* m_checkbox_override_region_settings;
Expand Down