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";
|
2023-09-03 02:06:53 -04:00
|
|
|
|
public const string PROPERTY_SKIN_NAME_TO_HIJACK = "skinNameToHijack";
|
|
|
|
|
public const string PROPERTY_IN_MAIN_MENU = "inMainMenu";
|
2023-09-03 00:21:15 -04:00
|
|
|
|
public const string PROPERTY_IN_COSMETIC_MENU = "inCosmeticMenu";
|
2023-09-04 02:30:54 -04:00
|
|
|
|
public const string PROPERTY_OTHER_PLAYERS = "otherPlayers";
|
2023-09-03 00:06:26 -04:00
|
|
|
|
|
2023-08-27 02:44:35 -04:00
|
|
|
|
public static bool enabled = true;
|
|
|
|
|
public static string currentSkin;
|
2023-09-03 02:06:53 -04:00
|
|
|
|
public static string skinNameToHijack = "Swirl_M"; // Mirage, simple skin with nice properties
|
|
|
|
|
public static bool inMainMenu = true;
|
2023-09-03 00:21:15 -04:00
|
|
|
|
public static bool inCosmeticMenu = false;
|
2023-09-04 02:30:54 -04:00
|
|
|
|
public static Dictionary<string, string> otherPlayers = new Dictionary<string, string>();
|
2023-08-27 02:44:35 -04:00
|
|
|
|
|
|
|
|
|
public static Dictionary<string, Texture2D> skins = new Dictionary<string, Texture2D>();
|
|
|
|
|
|
|
|
|
|
public static void Init()
|
|
|
|
|
{
|
2023-09-04 00:57:33 -04:00
|
|
|
|
bool configExists = File.Exists(GetConfigPath());
|
|
|
|
|
if (configExists)
|
2023-08-27 02:44:35 -04:00
|
|
|
|
ReadConfig();
|
2023-09-04 00:57:33 -04:00
|
|
|
|
|
|
|
|
|
ensureSkinSelected();
|
|
|
|
|
|
|
|
|
|
if (!configExists && enabled)
|
2023-08-27 02:44:35 -04:00
|
|
|
|
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)
|
|
|
|
|
{
|
2023-09-04 16:38:48 -04:00
|
|
|
|
Shared.Log("Couldn't load CustomCosmeticLoader config!");
|
2023-08-27 02:44:35 -04:00
|
|
|
|
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
|
|
|
|
|
2023-09-03 02:06:53 -04:00
|
|
|
|
if (data[PROPERTY_SKIN_NAME_TO_HIJACK] != null)
|
|
|
|
|
skinNameToHijack = data[PROPERTY_SKIN_NAME_TO_HIJACK].Value;
|
|
|
|
|
|
|
|
|
|
if (data[PROPERTY_IN_MAIN_MENU] != null)
|
|
|
|
|
inMainMenu = data[PROPERTY_IN_MAIN_MENU].AsBool;
|
2023-09-03 00:21:15 -04:00
|
|
|
|
|
|
|
|
|
if (data[PROPERTY_IN_COSMETIC_MENU] != null)
|
|
|
|
|
inCosmeticMenu = data[PROPERTY_IN_COSMETIC_MENU].AsBool;
|
2023-09-04 02:30:54 -04:00
|
|
|
|
|
|
|
|
|
if (data[PROPERTY_OTHER_PLAYERS] != null)
|
|
|
|
|
{
|
|
|
|
|
JSONClass otherPlayersData = data[PROPERTY_OTHER_PLAYERS].AsObject;
|
|
|
|
|
if (otherPlayersData != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (KeyValuePair<string, JSONNode> node in otherPlayersData)
|
|
|
|
|
{
|
|
|
|
|
string nickname = node.Key;
|
|
|
|
|
string skinName = node.Value.Value;
|
|
|
|
|
if (skins.ContainsKey(skinName))
|
|
|
|
|
{
|
2023-09-04 16:38:48 -04:00
|
|
|
|
Shared.Log("Adding other player: " + nickname + " -> " + skinName);
|
2023-09-04 02:30:54 -04:00
|
|
|
|
otherPlayers.Add(nickname, skinName);
|
|
|
|
|
}
|
2023-09-04 16:38:48 -04:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Shared.Log("NOT adding other player " + nickname + ", skin " + skinName + " not found");
|
|
|
|
|
}
|
2023-09-04 02:30:54 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
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 },
|
2023-09-03 02:06:53 -04:00
|
|
|
|
{ PROPERTY_SKIN_NAME_TO_HIJACK, skinNameToHijack },
|
|
|
|
|
{ PROPERTY_IN_MAIN_MENU, inMainMenu ? "true" : "false" },
|
2023-09-03 00:21:15 -04:00
|
|
|
|
{ PROPERTY_IN_COSMETIC_MENU, inCosmeticMenu ? "true" : "false" },
|
2023-08-27 02:44:35 -04:00
|
|
|
|
};
|
|
|
|
|
|
2023-09-04 02:30:54 -04:00
|
|
|
|
JSONNode otherPlayersData = new JSONClass();
|
|
|
|
|
foreach (KeyValuePair<string, string> otherPlayer in otherPlayers)
|
|
|
|
|
otherPlayersData.Add(otherPlayer.Key, otherPlayer.Value);
|
|
|
|
|
|
|
|
|
|
node.Add(PROPERTY_OTHER_PLAYERS, otherPlayersData);
|
|
|
|
|
|
2023-08-27 02:44:35 -04:00
|
|
|
|
File.WriteAllText(GetConfigPath(), node.ToString());
|
|
|
|
|
}
|
2023-09-04 00:57:33 -04:00
|
|
|
|
|
|
|
|
|
public static void ensureSkinSelected()
|
|
|
|
|
{
|
|
|
|
|
if (currentSkin == null || !skins.ContainsKey(currentSkin))
|
|
|
|
|
{
|
|
|
|
|
if (skins.Count == 0)
|
|
|
|
|
{
|
2023-09-04 16:38:48 -04:00
|
|
|
|
Shared.Log("No custom skins found, disabling mod");
|
2023-09-04 00:57:33 -04:00
|
|
|
|
enabled = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
currentSkin = skins.Keys.ToList()[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-27 02:44:35 -04:00
|
|
|
|
}
|
|
|
|
|
}
|