diff --git a/BepInEx.Core/Configuration/ConfigDefinition.cs b/BepInEx.Core/Configuration/ConfigDefinition.cs
index b646667..e16b6ff 100644
--- a/BepInEx.Core/Configuration/ConfigDefinition.cs
+++ b/BepInEx.Core/Configuration/ConfigDefinition.cs
@@ -1,5 +1,6 @@
using System;
using System.Linq;
+using HarmonyLib;
namespace BepInEx.Configuration
{
@@ -11,7 +12,7 @@ namespace BepInEx.Configuration
///
public class ConfigDefinition : IEquatable
{
- private static readonly char[] _invalidConfigChars = { '=', '\n', '\t', '\\', '"', '\'', '[', ']' };
+ private static readonly char[] _invalidConfigChars = { '=', '\n', '\t', '\\', '"', '\'', '[', ']', '.' };
///
/// Create a new definition. Definitions with same section and key are equal.
@@ -35,6 +36,8 @@ namespace BepInEx.Configuration
/// Name of the setting.
///
public string Key { get; }
+
+ internal string[] ConfigPath => Section.Split('.').AddItem(Key).ToArray();
///
/// Check if the definitions are the same.
@@ -50,12 +53,9 @@ namespace BepInEx.Configuration
private static void CheckInvalidConfigChars(string val, string name)
{
if (val == null) throw new ArgumentNullException(name);
- if (val != val.Trim())
- throw new ArgumentException("Cannot use whitespace characters at start or end of section and key names",
- name);
if (val.Any(c => _invalidConfigChars.Contains(c)))
throw new
- ArgumentException(@"Cannot use any of the following characters in section and key names: = \n \t \ "" ' [ ]",
+ ArgumentException(@"Cannot use any of the following characters in section and key names: = \n \t \ "" ' [ ] .",
name);
}
diff --git a/BepInEx.Core/Configuration/ConfigEntryBase.cs b/BepInEx.Core/Configuration/ConfigEntryBase.cs
index a5b822f..d12744e 100644
--- a/BepInEx.Core/Configuration/ConfigEntryBase.cs
+++ b/BepInEx.Core/Configuration/ConfigEntryBase.cs
@@ -1,7 +1,10 @@
using System;
+using System.Collections.Generic;
+using System.Globalization;
using System.IO;
using System.Linq;
using BepInEx.Logging;
+using HarmonyLib;
namespace BepInEx.Configuration
{
@@ -120,7 +123,7 @@ namespace BepInEx.Configuration
///
/// Get the serialized representation of the value.
///
- public string GetSerializedValue() => TomlTypeConverter.ConvertToString(BoxedValue, SettingType);
+ public string GetSerializedValue() => ConfigTypeConverter.ConvertToString(BoxedValue, SettingType);
///
/// Set the value by using its serialized form.
@@ -129,7 +132,7 @@ namespace BepInEx.Configuration
{
try
{
- var newValue = TomlTypeConverter.ConvertToValue(value, SettingType);
+ var newValue = ConfigTypeConverter.ConvertToValue(value, SettingType);
BoxedValue = newValue;
}
catch (Exception e)
@@ -164,7 +167,7 @@ namespace BepInEx.Configuration
writer.WriteLine("# Setting type: " + SettingType.Name);
- writer.WriteLine("# Default value: " + TomlTypeConverter.ConvertToString(DefaultValue, SettingType));
+ writer.WriteLine("# Default value: " + ConfigTypeConverter.ConvertToString(DefaultValue, SettingType));
if (Description.AcceptableValues != null)
{
diff --git a/BepInEx.Core/Configuration/ConfigFile.cs b/BepInEx.Core/Configuration/ConfigFile.cs
index d83d03f..e29e6e9 100644
--- a/BepInEx.Core/Configuration/ConfigFile.cs
+++ b/BepInEx.Core/Configuration/ConfigFile.cs
@@ -1,9 +1,11 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using System.Text;
using BepInEx.Logging;
+using HarmonyLib;
// TODO: Check if IDictionary implementation is reasonable
@@ -37,7 +39,7 @@ namespace BepInEx.Configuration
public static ConfigFile CoreConfig { get; } = new(Paths.BepInExConfigPath, true);
- public IConfigurationProvider ConfigurationProvider { get; set; }
+ public IConfigurationProvider ConfigurationProvider { get; }
///
/// All config entries inside
@@ -313,24 +315,15 @@ namespace BepInEx.Configuration
T defaultValue,
ConfigDescription configDescription = null)
{
- if (!TomlTypeConverter.CanConvert(typeof(T)))
- throw new
- ArgumentException($"Type {typeof(T)} is not supported by the config system. Supported types: {string.Join(", ", TomlTypeConverter.GetSupportedTypes().Select(x => x.Name).ToArray())}");
-
lock (_ioLock)
{
if (Entries.TryGetValue(configDefinition, out var rawEntry))
return (ConfigEntry) rawEntry;
var entry = new ConfigEntry(this, configDefinition, defaultValue, configDescription);
-
Entries[configDefinition] = entry;
- if (OrphanedEntries.TryGetValue(configDefinition, out var homelessValue))
- {
- entry.SetSerializedValue(homelessValue);
- OrphanedEntries.Remove(configDefinition);
- }
+ entry.BoxedValue = GetValue(configDefinition.ConfigPath, typeof(T)) ?? defaultValue;
if (SaveOnConfigSet)
Save();
@@ -338,6 +331,64 @@ namespace BepInEx.Configuration
return entry;
}
}
+
+ private object GetValue(string[] path, Type type)
+ {
+ // We have direct value; simply resolve it normally
+ if (ConfigTypeConverter.CanConvertDirectly(type))
+ {
+ var val = ConfigurationProvider.Get(path);
+ if (val != null)
+ return ConfigTypeConverter.ConvertToValue(val.Value, type);
+ return null;
+ }
+ else if (type.IsArray)
+ {
+ var elType = type.GetElementType();
+ var indexPath = path.AddItem("0").ToArray();
+ var values = new List