Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/xenia/base/cvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class IConfigVar : virtual public ICommandVar {
virtual std::string config_value() const = 0;
virtual void LoadConfigValue(std::shared_ptr<cpptoml::base> result) = 0;
virtual void LoadGameConfigValue(std::shared_ptr<cpptoml::base> result) = 0;
virtual void ResetGameConfigValue() = 0;
virtual void ResetConfigValueToDefault() = 0;
};

Expand Down Expand Up @@ -95,6 +96,7 @@ class ConfigVar : public CommandVar<T>, virtual public IConfigVar {
// one that will be stored when the global config is written next time. After
// overriding, however, the next game config loaded may still change it.
void OverrideConfigValue(T val);
void ResetGameConfigValue() override;

private:
std::string category_;
Expand Down Expand Up @@ -278,6 +280,13 @@ void ConfigVar<T>::OverrideConfigValue(T val) {
this->commandline_value_.reset();
UpdateValue();
}

template <class T>
void ConfigVar<T>::ResetGameConfigValue() {
game_config_value_.reset();
UpdateValue();
}

template <class T>
void ConfigVar<T>::ResetConfigValueToDefault() {
SetConfigValue(this->default_value_);
Expand Down
12 changes: 12 additions & 0 deletions src/xenia/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ void ReadGameConfig(const std::filesystem::path& file_path) {
XELOGI("Loaded game config: {}", xe::path_to_utf8(file_path));
}

void ResetGameConfigValues() {
if (!cvar::ConfigVars) {
return;
}
for (auto& it : *cvar::ConfigVars) {
auto config_var = static_cast<cvar::IConfigVar*>(it.second);
config_var->ResetGameConfigValue();
}
}

void SaveConfig() {
if (config_path.empty()) {
return;
Expand Down Expand Up @@ -238,6 +248,8 @@ void SetupConfig(const std::filesystem::path& config_folder) {
}

void LoadGameConfig(const std::string_view title_id) {
ResetGameConfigValues();

const auto game_config_folder = config_folder / "config";
const auto game_config_path =
game_config_folder / (std::string(title_id) + game_config_suffix);
Expand Down