2021-05-11 20:23:52 +10:00
|
|
|
|
#if ML
|
2021-05-23 13:58:26 +10:00
|
|
|
|
|
|
|
|
|
#if !ML_LEGACY // ML 0.3.1+ config handler
|
|
|
|
|
|
2021-05-11 20:23:52 +10:00
|
|
|
|
using MelonLoader;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityExplorer.Core;
|
|
|
|
|
using UnityExplorer.Core.Config;
|
|
|
|
|
|
|
|
|
|
namespace UnityExplorer.Loader.ML
|
|
|
|
|
{
|
|
|
|
|
public class MelonLoaderConfigHandler : ConfigHandler
|
|
|
|
|
{
|
|
|
|
|
internal const string CTG_NAME = "UnityExplorer";
|
|
|
|
|
|
|
|
|
|
internal MelonPreferences_Category prefCategory;
|
|
|
|
|
|
|
|
|
|
public override void Init()
|
|
|
|
|
{
|
2021-05-13 23:02:46 +10:00
|
|
|
|
prefCategory = MelonPreferences.CreateCategory(CTG_NAME, $"{CTG_NAME} Settings", false, true);
|
2021-05-11 20:23:52 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void LoadConfig()
|
|
|
|
|
{
|
|
|
|
|
foreach (var entry in ConfigManager.ConfigElements)
|
|
|
|
|
{
|
|
|
|
|
var key = entry.Key;
|
|
|
|
|
if (prefCategory.GetEntry(key) is MelonPreferences_Entry)
|
|
|
|
|
{
|
|
|
|
|
var config = entry.Value;
|
|
|
|
|
config.BoxedValue = config.GetLoaderConfigValue();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void RegisterConfigElement<T>(ConfigElement<T> config)
|
|
|
|
|
{
|
2021-05-13 23:02:46 +10:00
|
|
|
|
var entry = prefCategory.CreateEntry(config.Name, config.Value, null, config.Description, config.IsInternal, false);
|
2021-05-11 20:23:52 +10:00
|
|
|
|
|
|
|
|
|
entry.OnValueChangedUntyped += () =>
|
|
|
|
|
{
|
|
|
|
|
if ((entry.Value == null && config.Value == null) || config.Value.Equals(entry.Value))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
config.Value = entry.Value;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void SetConfigValue<T>(ConfigElement<T> config, T value)
|
|
|
|
|
{
|
|
|
|
|
if (prefCategory.GetEntry<T>(config.Name) is MelonPreferences_Entry<T> entry)
|
|
|
|
|
{
|
|
|
|
|
entry.Value = value;
|
|
|
|
|
//entry.Save();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override T GetConfigValue<T>(ConfigElement<T> config)
|
|
|
|
|
{
|
|
|
|
|
if (prefCategory.GetEntry<T>(config.Name) is MelonPreferences_Entry<T> entry)
|
|
|
|
|
return entry.Value;
|
|
|
|
|
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnAnyConfigChanged()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void SaveConfig()
|
|
|
|
|
{
|
|
|
|
|
MelonPreferences.Save();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-23 13:58:26 +10:00
|
|
|
|
#else // ML 0.3.0 config handler
|
|
|
|
|
|
|
|
|
|
using MelonLoader;
|
|
|
|
|
using MelonLoader.Tomlyn.Model;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityExplorer.Core;
|
|
|
|
|
using UnityExplorer.Core.Config;
|
|
|
|
|
|
|
|
|
|
namespace UnityExplorer.Loader.ML
|
|
|
|
|
{
|
|
|
|
|
public class MelonLoaderConfigHandler : ConfigHandler
|
|
|
|
|
{
|
|
|
|
|
internal const string CTG_NAME = "UnityExplorer";
|
|
|
|
|
|
|
|
|
|
internal MelonPreferences_Category prefCategory;
|
|
|
|
|
|
|
|
|
|
public override void Init()
|
|
|
|
|
{
|
|
|
|
|
prefCategory = MelonPreferences.CreateCategory(CTG_NAME, $"{CTG_NAME} Settings");
|
|
|
|
|
|
|
|
|
|
try { MelonPreferences.Mapper.RegisterMapper(KeycodeReader, KeycodeWriter); } catch { }
|
|
|
|
|
try { MelonPreferences.Mapper.RegisterMapper(AnchorReader, AnchorWriter); } catch { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void LoadConfig()
|
|
|
|
|
{
|
|
|
|
|
foreach (var entry in ConfigManager.ConfigElements)
|
|
|
|
|
{
|
|
|
|
|
var key = entry.Key;
|
|
|
|
|
if (prefCategory.GetEntry(key) is MelonPreferences_Entry)
|
|
|
|
|
{
|
|
|
|
|
var config = entry.Value;
|
|
|
|
|
config.BoxedValue = config.GetLoaderConfigValue();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void RegisterConfigElement<T>(ConfigElement<T> config)
|
|
|
|
|
{
|
|
|
|
|
var entry = prefCategory.CreateEntry(config.Name, config.Value, null, config.IsInternal) as MelonPreferences_Entry<T>;
|
|
|
|
|
|
|
|
|
|
entry.OnValueChangedUntyped += () =>
|
|
|
|
|
{
|
|
|
|
|
if ((entry.Value == null && config.Value == null) || config.Value.Equals(entry.Value))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
config.Value = entry.Value;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void SetConfigValue<T>(ConfigElement<T> config, T value)
|
|
|
|
|
{
|
|
|
|
|
if (prefCategory.GetEntry<T>(config.Name) is MelonPreferences_Entry<T> entry)
|
|
|
|
|
{
|
|
|
|
|
entry.Value = value;
|
|
|
|
|
entry.Save();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override T GetConfigValue<T>(ConfigElement<T> config)
|
|
|
|
|
{
|
|
|
|
|
if (prefCategory.GetEntry<T>(config.Name) is MelonPreferences_Entry<T> entry)
|
|
|
|
|
return entry.Value;
|
|
|
|
|
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnAnyConfigChanged()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void SaveConfig()
|
|
|
|
|
{
|
|
|
|
|
MelonPreferences.Save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Enum config handlers
|
|
|
|
|
|
|
|
|
|
public static KeyCode KeycodeReader(TomlObject value)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
KeyCode kc = (KeyCode)Enum.Parse(typeof(KeyCode), (value as TomlString).Value);
|
|
|
|
|
|
|
|
|
|
if (kc == default)
|
|
|
|
|
throw new Exception();
|
|
|
|
|
|
|
|
|
|
return kc;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return KeyCode.F7;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TomlObject KeycodeWriter(KeyCode value)
|
|
|
|
|
{
|
|
|
|
|
return MelonPreferences.Mapper.ToToml(value.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static UI.UIManager.VerticalAnchor AnchorReader(TomlObject value)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return (UI.UIManager.VerticalAnchor)Enum.Parse(typeof(UI.UIManager.VerticalAnchor), (value as TomlString).Value);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return UI.UIManager.VerticalAnchor.Top;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TomlObject AnchorWriter(UI.UIManager.VerticalAnchor anchor)
|
|
|
|
|
{
|
|
|
|
|
return MelonPreferences.Mapper.ToToml(anchor.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
#endif
|