2023-08-27 02:44:35 -04:00
|
|
|
|
using I2.Loc.SimpleJSON;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace CustomCosmeticLoader
|
|
|
|
|
{
|
|
|
|
|
public class Config
|
|
|
|
|
{
|
|
|
|
|
public const string CONFIG_FILE_NAME = "config.json";
|
|
|
|
|
public const string SKINS_DIR_NAME = "skins";
|
|
|
|
|
|
2023-09-03 00:06:26 -04:00
|
|
|
|
public const string PROPERTY_ENABLED = "enabled";
|
|
|
|
|
public const string PROPERTY_CURRENT_SKIN = "currentSkin";
|
|
|
|
|
public const string PROPERTY_SKIN_TO_HIJACK = "skinToHijack";
|
|
|
|
|
|
2023-08-27 02:44:35 -04:00
|
|
|
|
public static bool enabled = true;
|
|
|
|
|
public static string currentSkin;
|
|
|
|
|
public static string skinToHijack = "Swirl_M"; // Mirage, simple skin with nice properties
|
|
|
|
|
|
|
|
|
|
public static Dictionary<string, Texture2D> skins = new Dictionary<string, Texture2D>();
|
|
|
|
|
|
|
|
|
|
public static void Init()
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(GetConfigPath()))
|
|
|
|
|
ReadConfig();
|
|
|
|
|
else
|
|
|
|
|
SaveConfig();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetConfigPath()
|
|
|
|
|
{
|
|
|
|
|
return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), CONFIG_FILE_NAME);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void ReadConfig()
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists(GetConfigPath()))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
JSONNode data;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
data = JSON.Parse(File.ReadAllText(GetConfigPath()));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("Couldn't load CustomCosmeticLoader config!");
|
|
|
|
|
Debug.LogException(e);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-03 00:06:26 -04:00
|
|
|
|
if (data[PROPERTY_ENABLED] != null)
|
|
|
|
|
enabled = data[PROPERTY_ENABLED].AsBool;
|
2023-08-27 02:44:35 -04:00
|
|
|
|
|
2023-09-03 00:06:26 -04:00
|
|
|
|
if (data[PROPERTY_CURRENT_SKIN] != null)
|
|
|
|
|
currentSkin = data[PROPERTY_CURRENT_SKIN].Value;
|
2023-08-27 02:44:35 -04:00
|
|
|
|
if (currentSkin == null || !skins.ContainsKey(currentSkin))
|
|
|
|
|
{
|
|
|
|
|
if (skins.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogWarning("No custom skins found, disabling");
|
|
|
|
|
enabled = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
currentSkin = skins.Keys.ToList()[0];
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-03 00:06:26 -04:00
|
|
|
|
if (data[PROPERTY_SKIN_TO_HIJACK] != null)
|
|
|
|
|
skinToHijack = data[PROPERTY_SKIN_TO_HIJACK].Value;
|
2023-08-27 02:44:35 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void SaveConfig()
|
|
|
|
|
{
|
|
|
|
|
JSONNode node = new JSONClass
|
|
|
|
|
{
|
2023-09-03 00:06:26 -04:00
|
|
|
|
{ PROPERTY_ENABLED, enabled ? "true" : "false" },
|
|
|
|
|
{ PROPERTY_CURRENT_SKIN, currentSkin },
|
|
|
|
|
{ PROPERTY_SKIN_TO_HIJACK, skinToHijack }
|
2023-08-27 02:44:35 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
File.WriteAllText(GetConfigPath(), node.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|