The new code:
internal static class Settings
{
private static InitializationFile iniFile;
#region User Settings
public static Keys OpenMenuKey = Keys.U;
public static Keys ModOpenMenuKey = Keys.None;
#endregion
#region System Settings
public static float PercentageIncrementExpNeeded = .35f;
#endregion
static KeysConverter kc = new KeysConverter();
public static void Load()
{
Common.Log("Loading config.");
Common.Log(GetIniString("Keybindings", "MenuKey"));
Common.Log(GetIniString("Keybindings", "MenuKeyModifier"));
OpenMenuKey = (Keys)kc.ConvertFromString(GetIniString("Keybindings", "MenuKey", "U"));
ModOpenMenuKey = (Keys)kc.ConvertFromString(GetIniString("Keybindings", "MenuKeyModifier", "None"));
}
private static InitializationFile initialiseFile()
{
if (iniFile != null && iniFile.Exists())
return iniFile;
iniFile = new InitializationFile(@"Plugins\LSPDFR\LevelSystem.ini");
iniFile.Create();
if (iniFile.Exists())
return iniFile;
else
throw new Exception("Ini doesn't exist.");
}
private static string GetIniString(string section, string key, string defaultVal = "")
{
try
{
Common.Log($"[Requesting INI String] Section: {section}, Key: {key}, FileLocation: {initialiseFile().FileName}, IniValidation: {ValidateIni(section, key).ToString()}");
if (ValidateIni(section, key))
{
return initialiseFile().ReadString(section, key, defaultVal);
}
else
{
Common.Log("Ini file doesn't exist.");
Game.DisplayNotification("mprpsymbol", "rp", "~b~LSPDFR Level System", "~r~Ini file error", $"Ini File doesnt exist!");
return defaultVal;
}
}
catch(Exception e)
{
Common.Log($"[ERROR] {e.Message}");
return defaultVal;
}
}
private static bool ValidateIni(string section, string key)
{
return initialiseFile().DoesSectionExist(section) && initialiseFile().DoesKeyExist(section, key);
}
}
This results to this being said in the logs:
So your solution doesn't work.
I will try some stuff today myself and you will hear from me if I found the solution.