上传文件至 Config
This commit is contained in:
107
Config/ConfigManager.cs
Normal file
107
Config/ConfigManager.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using MelonLoader;
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
using YamlDotNet.Serialization;
|
||||
using YamlDotNet.Serialization.NamingConventions;
|
||||
|
||||
namespace SinmaiAssist.Config
|
||||
{
|
||||
public class ConfigManager<T> where T : new()
|
||||
{
|
||||
private readonly string _configPath;
|
||||
private T _config;
|
||||
private readonly IYamlTypeConverter _customConverter;
|
||||
|
||||
public ConfigManager(string configPath = "config.yml", IYamlTypeConverter customConverter = null)
|
||||
{
|
||||
_configPath = configPath;
|
||||
_customConverter = customConverter;
|
||||
InitConfig();
|
||||
}
|
||||
|
||||
private void InitConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(_configPath))
|
||||
{
|
||||
_config = new T();
|
||||
SaveConfig();
|
||||
MelonLogger.Msg($"Create Default Config '{_configPath}' ");
|
||||
return;
|
||||
}
|
||||
|
||||
LoadConfig();
|
||||
}
|
||||
catch (YamlException ex)
|
||||
{
|
||||
MelonLogger.Error($"Load Config '{_configPath}' Failed: \n{ex.Message}");
|
||||
MelonLogger.Warning($"Your Config is not valid, please delete it and restart the game.");
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MelonLogger.Error($"Init Config '{_configPath}' Failed: \n{ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public T GetConfig()
|
||||
{
|
||||
if (_config == null)
|
||||
{
|
||||
throw new InvalidOperationException("Configuration is not initialized.");
|
||||
}
|
||||
return _config;
|
||||
}
|
||||
|
||||
private ISerializer CreateSerializer()
|
||||
{
|
||||
var builder = new SerializerBuilder()
|
||||
.WithNamingConvention(CamelCaseNamingConvention.Instance);
|
||||
|
||||
if (_customConverter != null)
|
||||
{
|
||||
builder = builder.WithTypeConverter(_customConverter);
|
||||
}
|
||||
|
||||
return builder.Build();
|
||||
}
|
||||
|
||||
private IDeserializer CreateDeserializer()
|
||||
{
|
||||
var builder = new DeserializerBuilder()
|
||||
.WithNamingConvention(CamelCaseNamingConvention.Instance);
|
||||
|
||||
if (_customConverter != null)
|
||||
{
|
||||
builder = builder.WithTypeConverter(_customConverter);
|
||||
}
|
||||
|
||||
return builder.Build();
|
||||
}
|
||||
|
||||
private void SaveConfig()
|
||||
{
|
||||
var directory = Path.GetDirectoryName(_configPath);
|
||||
if (!Directory.Exists(directory))
|
||||
Directory.CreateDirectory(directory);
|
||||
|
||||
var serializer = CreateSerializer();
|
||||
var yaml = serializer.Serialize(_config);
|
||||
File.WriteAllText(_configPath, yaml);
|
||||
}
|
||||
|
||||
|
||||
private void LoadConfig()
|
||||
{
|
||||
var deserializer = CreateDeserializer();
|
||||
var yaml = File.ReadAllText(_configPath);
|
||||
_config = deserializer.Deserialize<T>(yaml);
|
||||
}
|
||||
}
|
||||
}
|
||||
97
Config/KeyBindConfig.cs
Normal file
97
Config/KeyBindConfig.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using MelonLoader;
|
||||
using UnityEngine;
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Core.Events;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace SinmaiAssist.Config;
|
||||
|
||||
public class KeyBindConfig
|
||||
{
|
||||
public AutoPlayConfig AutoPlay { get; set; } = new AutoPlayConfig();
|
||||
public ChartControllerConfig ChartController { get; set; } = new ChartControllerConfig();
|
||||
public SinmaiAssistConfig SinmaiAssist { get; set; } = new SinmaiAssistConfig();
|
||||
|
||||
public class AutoPlayConfig
|
||||
{
|
||||
public Key None { get; set; } = "N";
|
||||
public Key Critical { get; set; } = "F";
|
||||
public Key Perfect { get; set; } = "None";
|
||||
public Key Great { get; set; } = "O";
|
||||
public Key Good { get; set; } = "P";
|
||||
public Key Random { get; set; } = "K";
|
||||
public Key RandomAllPerfect { get; set; } = "G";
|
||||
public Key RandomFullComboPlus { get; set; } = "H";
|
||||
public Key RandomFullCombo { get; set; } = "J";
|
||||
}
|
||||
|
||||
public class ChartControllerConfig
|
||||
{
|
||||
public Key Pause { get; set; } = "Enter";
|
||||
public Key Forward { get; set; } = "RightArrow";
|
||||
public Key Backward { get; set; } = "LeftArrow";
|
||||
public Key SetRecord { get; set; } = "DownArrow";
|
||||
public Key ReturnRecord { get; set; } = "UpArrow";
|
||||
}
|
||||
|
||||
public class SinmaiAssistConfig
|
||||
{
|
||||
public Key ShowUserPanel { get; set; } = "Backspace";
|
||||
}
|
||||
|
||||
public class Key
|
||||
{
|
||||
private string _keyCode;
|
||||
|
||||
public Key(string key)
|
||||
{
|
||||
_keyCode = key;
|
||||
}
|
||||
|
||||
public static implicit operator Key(string key) => new Key(key);
|
||||
public static implicit operator string(Key key) => key._keyCode;
|
||||
public new string ToString() => _keyCode;
|
||||
|
||||
public KeyCode KeyCode
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_keyCode == "None")
|
||||
return UnityEngine.KeyCode.None;
|
||||
if (Enum.TryParse<KeyCode>(_keyCode, out var code))
|
||||
return code;
|
||||
|
||||
return KeyCode.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Converter : IYamlTypeConverter
|
||||
{
|
||||
public bool Accepts(Type type)
|
||||
{
|
||||
return type == typeof(Key);
|
||||
}
|
||||
|
||||
public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
|
||||
{
|
||||
var scalar = (Scalar) parser.Current;
|
||||
var value = scalar.Value;
|
||||
parser.MoveNext();
|
||||
return new Key(value);
|
||||
}
|
||||
|
||||
public void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
|
||||
{
|
||||
if (value is Key key)
|
||||
{
|
||||
emitter.Emit(new Scalar(key.ToString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
emitter.Emit(new Scalar("None"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
153
Config/MainConfig.cs
Normal file
153
Config/MainConfig.cs
Normal file
@@ -0,0 +1,153 @@
|
||||
namespace SinmaiAssist.Config;
|
||||
|
||||
public class MainConfig
|
||||
{
|
||||
public CommonConfig Common { get; set; } = new CommonConfig();
|
||||
public CheatConfig Cheat { get; set; } = new CheatConfig();
|
||||
public FixConfig Fix { get; set; } = new FixConfig();
|
||||
public ModSettingConfig ModSetting { get; set; } = new ModSettingConfig();
|
||||
|
||||
public class CommonConfig
|
||||
{
|
||||
public UnityLoggerConfig UnityLogger { get; set; } = new UnityLoggerConfig();
|
||||
public bool AutoBackupData { get; set; } = false;
|
||||
public bool InfinityTimer { get; set; } = false;
|
||||
public bool InfinityTimerLegacy { get; set; } = false;
|
||||
public bool DisableMask { get; set; } = false;
|
||||
public bool DisableBackground { get; set; } = false;
|
||||
public bool ShowFPS { get; set; } = true;
|
||||
public bool ForceQuickRetry { get; set; } = false;
|
||||
public bool ForwardATouchRegionToButton { get; set; } = false;
|
||||
public bool SkipFade { get; set; } = false;
|
||||
public bool SkipWarningScreen { get; set; } = false;
|
||||
public bool QuickBoot { get; set; } = false;
|
||||
public bool BlockCoin { get; set; } = false;
|
||||
public bool IgnoreAnyGameInformation { get; set; } = false;
|
||||
public bool ChangeDefaultOption { get; set; } = false;
|
||||
public bool ChangeFadeStyle { get; set; } = false;
|
||||
public SinglePlayerConfig SinglePlayer { get; set; } = new SinglePlayerConfig();
|
||||
public NetworkLoggerConfig NetworkLogger { get; set; } = new NetworkLoggerConfig();
|
||||
public CustomVersionTextConfig CustomVersionText { get; set; } = new CustomVersionTextConfig();
|
||||
public DummyLoginConfig DummyLogin { get; set; } = new DummyLoginConfig();
|
||||
public CustomCameraIdConfig CustomCameraId { get; set; } = new CustomCameraIdConfig();
|
||||
public ChangeGameSettingsConfig ChangeGameSettings { get; set; } = new ChangeGameSettingsConfig();
|
||||
}
|
||||
|
||||
public class CheatConfig
|
||||
{
|
||||
public bool AutoPlay { get; set; } = false;
|
||||
public bool FastSkip { get; set; } = false;
|
||||
public bool ChartController { get; set; } = false;
|
||||
public bool AllCollection { get; set; } = false;
|
||||
public bool UnlockEvent { get; set; } = false;
|
||||
public bool UnlockMusic { get; set; } = false;
|
||||
public bool UnlockMaster { get; set; } = false;
|
||||
public UnlockUtageConfig UnlockUtage { get; set; } = new UnlockUtageConfig();
|
||||
public bool SaveUnlockMusic { get; set; } = false;
|
||||
public bool SaveUnlockMaster { get; set; } = false;
|
||||
public bool ResetLoginBonusRecord { get; set; } = false;
|
||||
public bool ForceCurrentIsBest { get; set; } = false;
|
||||
public bool SetAllCharacterAsSameAndLock { get; set; } = false;
|
||||
public RewriteLoginBonusStampConfig RewriteLoginBonusStamp { get; set; } = new RewriteLoginBonusStampConfig();
|
||||
}
|
||||
|
||||
public class FixConfig
|
||||
{
|
||||
public bool DisableEnvironmentCheck { get; set; } = true;
|
||||
public bool DisableEncryption { get; set; } = false;
|
||||
public bool DisableReboot { get; set; } = true;
|
||||
public bool DisableIniClear { get; set; } = true;
|
||||
public bool FixDebugInput { get; set; } = true;
|
||||
public bool FixCheckAuth { get; set; } = false;
|
||||
public bool ForceAsServer { get; set; } = false;
|
||||
public bool SkipCakeHashCheck { get; set; } = false;
|
||||
public bool SkipSpecialNumCheck { get; set; } = true;
|
||||
public bool SkipVersionCheck { get; set; } = false;
|
||||
public bool RestoreCertificateValidation { get; set; } = false;
|
||||
public RewriteNoteJudgeTimingConfig RewriteNoteJudgeTiming { get; set; } = new RewriteNoteJudgeTimingConfig();
|
||||
}
|
||||
|
||||
public class ModSettingConfig
|
||||
{
|
||||
public bool SafeMode { get; set; } = false;
|
||||
public bool ShowInfo { get; set; } = true;
|
||||
public bool ShowPanel { get; set; } = true;
|
||||
public WebServerConfig WebServer { get; set; } = new WebServerConfig();
|
||||
}
|
||||
|
||||
public class ChangeGameSettingsConfig
|
||||
{
|
||||
public bool Enable { get; set; } = false;
|
||||
public bool CodeRead { get; set; } = false;
|
||||
public bool IconPhoto { get; set; } = false;
|
||||
public bool UploadPhoto { get; set; } = false;
|
||||
public bool CharaSelect { get; set; } = false;
|
||||
}
|
||||
|
||||
public class SinglePlayerConfig
|
||||
{
|
||||
public bool Enable { get; set; } = false;
|
||||
public bool HideSubMonitor { get; set; } = false;
|
||||
}
|
||||
|
||||
public class NetworkLoggerConfig
|
||||
{
|
||||
public bool Enable { get; set; } = true;
|
||||
public bool PrintToConsole { get; set; } = false;
|
||||
}
|
||||
|
||||
public class CustomVersionTextConfig
|
||||
{
|
||||
public bool Enable { get; set; } = false;
|
||||
public string VersionText { get; set; } = "Sinmai-Assist";
|
||||
}
|
||||
|
||||
public class UnlockUtageConfig
|
||||
{
|
||||
public bool Enable { get; set; } = false;
|
||||
public bool UnlockDoublePlayerMusic { get; set; } = false;
|
||||
}
|
||||
|
||||
public class RewriteNoteJudgeTimingConfig
|
||||
{
|
||||
public bool Enable { get; set; } = false;
|
||||
public float AdjustTiming { get; set; } = 0;
|
||||
public float JudgeTiming { get; set; } = 0;
|
||||
}
|
||||
|
||||
public class DummyLoginConfig
|
||||
{
|
||||
public bool Enable { get; set; } = false;
|
||||
public int DefaultUserId { get; set; } = 0;
|
||||
}
|
||||
|
||||
public class CustomCameraIdConfig
|
||||
{
|
||||
public bool Enable { get; set; } = false;
|
||||
public int ChimeCameraId { get; set; } = 0;
|
||||
public int LeftQrCameraId { get; set; } = 0;
|
||||
public int RightQrCameraId { get; set; } = 0;
|
||||
public int PhotoCameraId { get; set; } = 0;
|
||||
}
|
||||
|
||||
public class RewriteLoginBonusStampConfig
|
||||
{
|
||||
public bool Enable { get; set; } = false;
|
||||
public uint Point { get; set; } = 0;
|
||||
}
|
||||
|
||||
public class UnityLoggerConfig
|
||||
{
|
||||
public bool Enable { get; set; } = true;
|
||||
public bool PrintToConsole { get; set; } = true;
|
||||
}
|
||||
|
||||
public class WebServerConfig
|
||||
{
|
||||
public bool Enable { get; set; } = false;
|
||||
public string Host { get; set; } = "127.0.0.1";
|
||||
public int Port { get; set; } = 8080;
|
||||
public string Token { get; set; } = "";
|
||||
public bool PrintDebugLog { get; set; } = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user