VideoTamperPatch, configurable outside of the BepInEx config

This commit is contained in:
2025-08-20 15:40:39 -04:00
parent 95cfd7ebb0
commit b796a6b075
7 changed files with 104 additions and 2 deletions

49
Core/Config/DediConfig.cs Normal file
View File

@@ -0,0 +1,49 @@
using System;
using System.IO;
using System.Text.Json;
namespace undead_universal_patch_il2cpp.Core.Config;
public class DediConfig<T>
{
private readonly string _default;
public readonly string _name;
public readonly string path;
private T? cached;
private bool loaded = false;
private readonly JsonSerializerOptions? _options;
public DediConfig(string name, string def, JsonSerializerOptions? options)
{
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Name cannot be invalid");
_name = name;
path = $"BepInEx/config/Undead.{name}.json";
_default = def;
_options = options;
}
private string GetAlways()
{
if (!File.Exists(path))
{
File.WriteAllText(path, _default);
return _default;
}
return File.ReadAllText(path);
}
public T Get()
{
if (loaded) return cached;
string data = GetAlways();
cached = JsonSerializer.Deserialize<T>(data, _options == null ? new JsonSerializerOptions()
{
PropertyNameCaseInsensitive = true,
AllowTrailingCommas = true
} : _options);
loaded = true;
return cached;
}
}