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

fix: ini settings saving to a random ini file #767

Merged
merged 3 commits into from
Nov 20, 2024
Merged
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
39 changes: 35 additions & 4 deletions src/Utils/GameSetting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Util
{
static constexpr std::string_view CS_SETTINGS_PATH{ "Data/SKSE/Plugins/CommunityShaders/SkyrimOverwrite.ini"sv };
doodlum marked this conversation as resolved.
Show resolved Hide resolved

void DumpSettingsOptions()
{
// List of INI setting collections to iterate over
Expand Down Expand Up @@ -357,11 +359,24 @@ namespace Util

void SaveGameSettings(const std::map<std::string, GameSetting>& settingsMap)
{
auto ini = RE::INISettingCollection::GetSingleton();

char subKeyBackup[0x104];
strcpy_s(subKeyBackup, 260, ini->subKey);
strcpy_s(ini->subKey, 260, CS_SETTINGS_PATH.data());

auto iniPref = RE::INIPrefSettingCollection::GetSingleton();

char subKeyPrefBackup[0x104];
strcpy_s(subKeyPrefBackup, 260, iniPref->subKey);
strcpy_s(iniPref->subKey, 260, CS_SETTINGS_PATH.data());

// Initialize collections
std::vector<std::pair<RE::INISettingCollection*, std::string>> iniCollections = {
{ RE::INISettingCollection::GetSingleton(), "INISettingCollection" },
{ RE::INIPrefSettingCollection::GetSingleton(), "INIPrefSettingCollection" }
{ ini, "INISettingCollection" },
{ iniPref, "INIPrefSettingCollection" }
};

auto gameSettingCollection = RE::GameSettingCollection::GetSingleton();

// Single iteration for settings
Expand Down Expand Up @@ -395,14 +410,28 @@ namespace Util
}
}
}
strcpy_s(ini->subKey, 260, subKeyBackup);
strcpy_s(iniPref->subKey, 260, subKeyPrefBackup);
}

void LoadGameSettings(const std::map<std::string, GameSetting>& settingsMap)
{
auto ini = RE::INISettingCollection::GetSingleton();

char subKeyBackup[0x104];
strcpy_s(subKeyBackup, 260, ini->subKey);
strcpy_s(ini->subKey, 260, CS_SETTINGS_PATH.data());

auto iniPref = RE::INIPrefSettingCollection::GetSingleton();

char subKeyPrefBackup[0x104];
strcpy_s(subKeyPrefBackup, 260, iniPref->subKey);
strcpy_s(iniPref->subKey, 260, CS_SETTINGS_PATH.data());
doodlum marked this conversation as resolved.
Show resolved Hide resolved

// Handle INI and Game settings in a single loop
std::vector<std::pair<RE::INISettingCollection*, std::string>> iniCollections = {
{ RE::INISettingCollection::GetSingleton(), "INISettingCollection" },
{ RE::INIPrefSettingCollection::GetSingleton(), "INIPrefSettingCollection" }
{ ini, "INISettingCollection" },
{ iniPref, "INIPrefSettingCollection" }
};

auto gameSettingCollection = RE::GameSettingCollection::GetSingleton();
Expand Down Expand Up @@ -438,5 +467,7 @@ namespace Util
}
}
}
strcpy_s(ini->subKey, 260, subKeyBackup);
strcpy_s(iniPref->subKey, 260, subKeyPrefBackup);
}
} // namespace Util