Decompiled source of DresserMod v1.2.1

UMM/Mods/DresserMod/DresserMod.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using HarmonyLib;
using Newtonsoft.Json;
using RocketLib.Utils;
using TFBGames.Systems;
using UnityEngine;
using UnityModManagerNet;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ReskinMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ReskinMod")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ea375633-adfb-482d-94e8-69ddb72f1a41")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace DresserMod
{
	public class AttireCollection
	{
		public FuturisticAttire[] Attires = new FuturisticAttire[0];

		public static AttireCollection TryLoadFromJson(string file)
		{
			if (!File.Exists(file))
			{
				throw new FileNotFoundException(file);
			}
			string text = File.ReadAllText(file);
			if (IEnumerableExtensions.IsNullOrEmpty<char>((IEnumerable<char>)text))
			{
				throw new Exception(file + " is empty");
			}
			AttireCollection attireCollection = JsonConvert.DeserializeObject<AttireCollection>(text);
			FuturisticAttire[] attires = attireCollection.Attires;
			foreach (FuturisticAttire futuristicAttire in attires)
			{
				futuristicAttire.Directory = Path.GetDirectoryName(file);
			}
			return attireCollection;
		}
	}
	public class FuturisticAttire : IAttire
	{
		public string Name { get; set; } = string.Empty;


		public string Wearer { get; set; } = string.Empty;


		[JsonIgnore]
		public string Directory { get; set; } = string.Empty;


		[JsonIgnore]
		public bool Enabled { get; set; } = true;


		[JsonIgnore]
		public string Id => Wearer + "-" + Name;

		public Dictionary<string, string> Clothes { get; set; } = new Dictionary<string, string>();


		public Dictionary<string, object> Stats { get; set; } = new Dictionary<string, object>();


		public FuturisticAttire(string name, string directory)
		{
			Name = name;
			Directory = directory;
			Enabled = !Main.settings.unactiveFiles.Contains(Id);
		}

		public static FuturisticAttire TryLoadFromJson(string file)
		{
			if (!File.Exists(file))
			{
				throw new FileNotFoundException(file);
			}
			string text = File.ReadAllText(file);
			if (IEnumerableExtensions.IsNullOrEmpty<char>((IEnumerable<char>)text))
			{
				throw new Exception(file + " is empty");
			}
			FuturisticAttire futuristicAttire = JsonConvert.DeserializeObject<FuturisticAttire>(text);
			if (IEnumerableExtensions.IsNullOrEmpty<char>((IEnumerable<char>)futuristicAttire.Wearer))
			{
				throw new MissingFieldException("Wearer field is null or empty");
			}
			if (IEnumerableExtensions.IsNullOrEmpty<char>((IEnumerable<char>)futuristicAttire.Name))
			{
				futuristicAttire.Name = Path.GetFileName(file);
			}
			futuristicAttire.Directory = Path.GetDirectoryName(file);
			return futuristicAttire;
		}

		public void SuitUp(object obj)
		{
			Traverse traverse = HarmonyExtensions.GetTraverse(obj);
			string[] array = Clothes.Keys.ToArray();
			try
			{
				if (Main.settings.useStats)
				{
					VariableSetter.Dynamic(obj, Stats, TweakWearer);
				}
				VariableSetter.Dynamic(obj, ((IEnumerable<KeyValuePair<string, string>>)Clothes).ToDictionary((Func<KeyValuePair<string, string>, string>)((KeyValuePair<string, string> p) => p.Key), (Func<KeyValuePair<string, string>, object>)((KeyValuePair<string, string> p) => p.Value)), PutOnCloth);
			}
			catch (Exception msg)
			{
				Main.Log(msg);
			}
		}

		private void PutOnCloth(Traverse field, string key, object value)
		{
			string text = (string)value;
			if (string.IsNullOrEmpty(text))
			{
				return;
			}
			Type valueType = field.GetValueType();
			if ((object)valueType == typeof(SpriteSM))
			{
				SpriteSM value2 = field.GetValue<SpriteSM>();
				Texture2D texture = ResourcesController.GetTexture(Directory, text);
				if ((Object)(object)texture != (Object)null)
				{
					SpriteSMExtensions.SetTexture(value2, texture);
					((SpriteBase)value2).RecalcTexture();
					((SpriteBase)value2).CalcUVs();
					((SpriteBase)value2).UpdateUVs();
					field.SetValue((object)value2);
				}
				return;
			}
			if ((object)valueType == typeof(Material))
			{
				Material value3 = field.GetValue<Material>();
				Texture2D texture2 = ResourcesController.GetTexture(Directory, text);
				if ((Object)(object)texture2 != (Object)null)
				{
					value3.mainTexture = (Texture)(object)texture2;
					field.SetValue((object)value3);
				}
				return;
			}
			if ((object)valueType == typeof(Texture))
			{
				Texture2D texture3 = ResourcesController.GetTexture(Directory, text);
				if ((Object)(object)texture3 != (Object)null)
				{
					field.SetValue((object)texture3);
				}
				return;
			}
			if ((object)valueType == typeof(Texture2D))
			{
				Texture2D texture4 = ResourcesController.GetTexture(Directory, text);
				if ((Object)(object)texture4 != (Object)null)
				{
					field.SetValue((object)texture4);
				}
				return;
			}
			if (typeof(Component).IsAssignableFrom(valueType))
			{
				Renderer component = field.GetValue<Component>().GetComponent<Renderer>();
				if (!((Object)(object)component != (Object)null))
				{
					return;
				}
				Material material = component.material;
				if ((Object)(object)material != (Object)null)
				{
					Texture2D texture5 = ResourcesController.GetTexture(Directory, text);
					if ((Object)(object)texture5 != (Object)null)
					{
						material.mainTexture = (Texture)(object)texture5;
					}
				}
				return;
			}
			if (typeof(GameObject).IsAssignableFrom(valueType))
			{
				Renderer component2 = field.GetValue<GameObject>().GetComponent<Renderer>();
				if (!((Object)(object)component2 != (Object)null))
				{
					return;
				}
				Material material2 = component2.material;
				if ((Object)(object)material2 != (Object)null)
				{
					Texture2D texture6 = ResourcesController.GetTexture(Directory, text);
					if ((Object)(object)texture6 != (Object)null)
					{
						material2.mainTexture = (Texture)(object)texture6;
					}
				}
				return;
			}
			throw new Exception(string.Format("Variable is type of {0}, try to place it in {1}.", valueType, "Stats"));
		}

		private void TweakWearer(Traverse field, string key, object value)
		{
			try
			{
				Type valueType = field.GetValueType();
				if ((object)valueType == typeof(Enum))
				{
					if (value is string)
					{
						field.SetValue(Enum.Parse(valueType, (string)value));
					}
					field.SetValue((object)(int)value);
				}
				else if ((object)valueType == typeof(float))
				{
					if (value is double)
					{
						value = Convert.ToSingle(value);
					}
					field.SetValue(value);
				}
				else if ((object)valueType == typeof(int))
				{
					value = Convert.ToInt32(value);
					field.SetValue(value);
				}
				else if ((object)valueType == typeof(Projectile) || valueType.IsAssignableFrom(typeof(Projectile)))
				{
					string name = (string)value;
					Projectile val = ResourcesController.LoadAssetSync<Projectile>(name);
					if ((Object)(object)val != (Object)null)
					{
						field.SetValue((object)val);
					}
				}
				else if ((object)valueType == typeof(Grenade) || valueType.IsAssignableFrom(typeof(Grenade)))
				{
					string name2 = (string)value;
					Grenade val2 = ResourcesController.LoadAssetSync<Grenade>(name2);
					if ((Object)(object)val2 != (Object)null)
					{
						field.SetValue((object)val2);
					}
				}
				else
				{
					field.SetValue(value);
				}
			}
			catch (Exception ex)
			{
				Main.Log($"Key: {key} ; Value: {value}\n" + ex);
			}
		}
	}
	public interface IAttire
	{
		string Name { get; set; }

		string Wearer { get; set; }

		string Directory { get; set; }

		bool Enabled { get; set; }

		string Id { get; }

		Dictionary<string, string> Clothes { get; set; }

		void SuitUp(object obj);
	}
	internal static class ModUI
	{
		private static Vector2 _scrollViewVectorWardrobes = Vector2.zero;

		private static Vector2 _scrollViewVectorAttires = Vector2.zero;

		private static Vector2 _scrollViewVectorClothes = Vector2.zero;

		private static int _selectedTab = 0;

		private static string[] _tabs;

		private static Action[] _tabsAction;

		private static Wardrobe _selectedWardrobe = null;

		private static IAttire _selectedAttire = null;

		private static bool _wardrobeError = false;

		private static bool _attireError = false;

		private static bool _clothesError = false;

		private static string _fileName = string.Empty;

		private static Settings Settings => Main.settings;

		public static void Initialize()
		{
			_tabs = new string[2] { "Storage Browser", "Settings" };
			_tabsAction = new Action[2] { StorageBrowser, SettingGUI };
			if (StorageRoom.Wardrobes.Count > 0)
			{
				_selectedWardrobe = StorageRoom.Wardrobes.First().Value;
				_selectedAttire = _selectedWardrobe[0];
			}
			_wardrobeError = false;
			_attireError = false;
			_clothesError = false;
		}

		public static void MainGUI()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			if (GUILayout.Button(new GUIContent("Reload Mod"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) }))
			{
				StorageRoom.Initialize();
				Initialize();
			}
			GUILayout.Space(15f);
			if (_selectedWardrobe == null)
			{
				GUILayout.Label(new GUIContent("No skin in assets folder."), (GUILayoutOption[])(object)new GUILayoutOption[0]);
				return;
			}
			_selectedTab = GUILayout.SelectionGrid(_selectedTab, _tabs, 6, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(1000f) });
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
			_tabsAction[_selectedTab]();
			GUILayout.EndHorizontal();
		}

		private static void StorageBrowser()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (_wardrobeError)
				{
					return;
				}
				GUILayout.BeginVertical("Wardrobes", GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(300f),
					GUILayout.Height(250f)
				});
				GUILayout.Space(15f);
				_scrollViewVectorWardrobes = GUILayout.BeginScrollView(_scrollViewVectorWardrobes, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(250f) });
				foreach (KeyValuePair<string, Wardrobe> wardrobe in StorageRoom.Wardrobes)
				{
					if (GUILayout.Button(wardrobe.Key, (GUILayoutOption[])(object)new GUILayoutOption[0]))
					{
						_selectedWardrobe = wardrobe.Value;
						_selectedAttire = _selectedWardrobe[0];
					}
				}
				GUILayout.EndScrollView();
				GUILayout.EndVertical();
			}
			catch (Exception ex)
			{
				Main.Log("Wardrobes\n" + ex);
				_wardrobeError = true;
			}
			try
			{
				if (_attireError || _selectedWardrobe == null)
				{
					return;
				}
				GUILayout.Space(20f);
				GUILayout.BeginVertical(_selectedWardrobe.wearers, GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(300f),
					GUILayout.Height(250f)
				});
				GUILayout.Space(15f);
				_scrollViewVectorAttires = GUILayout.BeginScrollView(_scrollViewVectorAttires, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(250f) });
				foreach (IAttire attire in _selectedWardrobe.attires)
				{
					if (GUILayout.Button(attire.Name, (GUILayoutOption[])(object)new GUILayoutOption[0]))
					{
						_selectedAttire = attire;
					}
				}
				GUILayout.EndScrollView();
				GUILayout.EndVertical();
			}
			catch (Exception ex2)
			{
				Main.Log("Attires\n" + ex2);
				_attireError = true;
			}
			try
			{
				if (_clothesError || _selectedAttire == null)
				{
					return;
				}
				GUILayout.Space(20f);
				GUILayout.BeginVertical(_selectedAttire.Name, GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(500f),
					GUILayout.Height(250f)
				});
				GUILayout.Space(15f);
				_scrollViewVectorClothes = GUILayout.BeginScrollView(_scrollViewVectorClothes, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(250f) });
				if (GUILayout.Button(_selectedAttire.Enabled ? "Enabled" : "Disabled", (GUILayoutOption[])(object)new GUILayoutOption[0]))
				{
					_selectedAttire.Enabled = !_selectedAttire.Enabled;
					if (!_selectedAttire.Enabled)
					{
						Main.settings.unactiveFiles.Add(_selectedAttire.Id);
					}
					else if (Main.settings.unactiveFiles.Contains(_selectedAttire.Id))
					{
						Main.settings.unactiveFiles.Remove(_selectedAttire.Id);
					}
				}
				GUILayout.Label("Path: \n" + PathWithBroforceAtFirst(_selectedAttire.Directory), (GUILayoutOption[])(object)new GUILayoutOption[0]);
				GUILayout.Space(10f);
				foreach (KeyValuePair<string, string> clothe in _selectedAttire.Clothes)
				{
					GUILayout.Label("\"" + clothe.Key + "\": \"" + clothe.Value + "\"", (GUILayoutOption[])(object)new GUILayoutOption[0]);
				}
				GUILayout.EndScrollView();
				GUILayout.EndVertical();
			}
			catch (Exception ex3)
			{
				Main.Log("Clothes\n" + ex3);
				_clothesError = true;
			}
		}

		private static void SettingGUI()
		{
			GUILayout.BeginVertical(GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(1000f),
				GUILayout.Height(100f)
			});
			Settings.canUseDefaultSkin = GUILayout.Toggle(Settings.canUseDefaultSkin, "Can have default skin", (GUILayoutOption[])(object)new GUILayoutOption[0]);
			Settings.useStats = GUILayout.Toggle(Settings.useStats, "Use Attires Stats", (GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUILayout.Space(20f);
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
			_fileName = GUILayout.TextField(_fileName, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(300f),
				GUILayout.ExpandWidth(false)
			});
			if (GUILayout.Button("Create 'Attire' JSON File", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) }))
			{
				StorageRoom.CreateFuturisticAttireJsonFile(_fileName, StorageRoom.WardrobesDirectory);
			}
			if (GUILayout.Button("Create 'Attire Collection' JSON File", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) }))
			{
				StorageRoom.CreateAttireCollectionJsonFile(_fileName, StorageRoom.WardrobesDirectory);
			}
			GUILayout.EndHorizontal();
			GUILayout.EndVertical();
		}

		public static string PathWithBroforceAtFirst(string path)
		{
			int length = Directory.GetParent(RocketLibUtils.GetRootDirectory()).FullName.Length;
			return path.Substring(length, path.Length - length);
		}
	}
	public static class ResourcesController
	{
		private static Dictionary<string, Texture2D> textures = new Dictionary<string, Texture2D>();

		public static Texture2D GetTexture(string path, string fileName)
		{
			Texture2D value = null;
			textures.TryGetValue(fileName, out value);
			if ((Object)(object)value != (Object)null)
			{
				return value;
			}
			if (fileName.Contains(":"))
			{
				try
				{
					value = ResourcesController.LoadAssetSync<Texture2D>(fileName);
				}
				catch (Exception msg)
				{
					Main.Log(msg);
				}
			}
			else
			{
				value = CreateTexture(path, fileName);
			}
			if ((Object)(object)value != (Object)null)
			{
				textures.Add(fileName, value);
			}
			return value;
		}

		public static Texture2D CreateTexture(string path, string fileName)
		{
			return CreateTexture(Path.Combine(path, fileName));
		}

		public static Texture2D CreateTexture(string filePath)
		{
			if (!File.Exists(filePath))
			{
				throw new FileNotFoundException("File not found", filePath);
			}
			return CreateTexture(File.ReadAllBytes(filePath));
		}

		public static Texture2D CreateTexture(byte[] imageBytes)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			if (IEnumerableExtensions.IsNullOrEmpty<byte>((IEnumerable<byte>)imageBytes))
			{
				throw new ArgumentException("Is null or empty", "imageBytes");
			}
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			ImageConversion.LoadImage(val, imageBytes);
			((Texture)val).filterMode = (FilterMode)0;
			((Texture)val).anisoLevel = 1;
			((Texture)val).mipMapBias = 0f;
			((Texture)val).wrapMode = (TextureWrapMode)1;
			return val;
		}

		public static T LoadAssetSync<T>(string name) where T : Object
		{
			return GameSystems.ResourceManager.LoadAssetSync<T>(name);
		}
	}
	public static class VariableSetter
	{
		public const char PATH_SEPARATOR = '.';

		public static void Dynamic(object obj, Dictionary<string, object> map, Action<Traverse, string, object> setter)
		{
			if (setter == null)
			{
				setter = delegate(Traverse t, string s, object o)
				{
					t.SetValue(o);
				};
			}
			Traverse traverse = HarmonyExtensions.GetTraverse(obj);
			Traverse val = traverse;
			foreach (KeyValuePair<string, object> item in map)
			{
				try
				{
					val = FindFieldWithPath(traverse, item.Key);
					setter(val, item.Key, item.Value);
				}
				catch (NullReferenceException)
				{
				}
				catch (Exception ex2)
				{
					Main.Log($"Key: {item.Key} ; Value: {item.Value}\nAt type field {val.GetValueType()}\n" + ex2);
				}
			}
		}

		public static Traverse FindFieldWithPath(Traverse traverse, string fieldPath)
		{
			if (IEnumerableExtensions.IsNullOrEmpty<char>((IEnumerable<char>)fieldPath))
			{
				throw new ArgumentNullException("fieldPath");
			}
			Traverse val = traverse;
			string[] array = fieldPath.Split(new char[1] { '.' });
			string[] array2 = array;
			foreach (string text in array2)
			{
				if (text.StartsWith("__C_"))
				{
					object value = val.GetValue();
					string text2 = text.Substring(3, text.Length - 3);
					Component val2 = null;
					if (Object.op_Implicit((Object)(object)ObjectExtensions.As<Component>(value)))
					{
						val2 = ObjectExtensions.As<Component>(value).GetComponent(text2);
					}
					if (Object.op_Implicit((Object)(object)ObjectExtensions.As<GameObject>(value)))
					{
						val2 = ObjectExtensions.As<GameObject>(value).GetComponent(text2);
					}
					if (!((Object)(object)val2 != (Object)null))
					{
						throw new ArgumentException("Can't get Component " + text2 + " from " + ((object)val).ToString());
					}
					val = Traverse.Create((object)val2);
				}
				val = val.Field(text);
			}
			return val;
		}
	}
	public class Wardrobe : IEquatable<Wardrobe>
	{
		public string wearers = string.Empty;

		public List<IAttire> attires = new List<IAttire>();

		public IAttire this[int index]
		{
			get
			{
				if (index < 0 || index > attires.Count)
				{
					throw new ArgumentOutOfRangeException();
				}
				return attires[index];
			}
		}

		public Wardrobe(string wearers)
		{
			this.wearers = wearers;
		}

		public void AddAttire(IAttire attire)
		{
			attires.Add(attire);
		}

		public bool Equals(Wardrobe other)
		{
			if (other == null)
			{
				return false;
			}
			return other.wearers == wearers;
		}

		public IAttire RandomAttire()
		{
			IAttire[] array = attires.Where((IAttire a) => a.Enabled).ToArray();
			if (array.Length == 0)
			{
				return null;
			}
			if (Main.settings.canUseDefaultSkin)
			{
				int num = Random.Range(0, array.Length + 1);
				if (num >= array.Length)
				{
					return null;
				}
				return array[num];
			}
			return Extensions.RandomElement<IAttire>(array);
		}

		public void SetRandomAttire(object obj)
		{
			if (attires.Count == 0)
			{
				return;
			}
			try
			{
				RandomAttire()?.SuitUp(obj);
			}
			catch (Exception msg)
			{
				Main.Log(msg);
			}
		}
	}
	public static class Wearers
	{
		public const string SCIENTIST = "Scientist";

		private const string SCIENTIST_GAMEOBJECT = "ZMookScientist";

		public const string ALARMIST = "Alarmist";

		private const string ALARMIST_GAMEOBJECT = "ZMook Alarmist";

		public const string MOOK_STRONG = "MookStrong";

		private const string MOOK_STRONG_GAMEOBJECT = "ZMook Strong";

		public const string MOOK_TREASURE = "MookTreasure";

		private const string MOOK_TREASURE_GAMEOBJECT = "ZMookTreasure";

		public const string BRUISER_STRONG = "BruiserStrong";

		private const string BRUISER_STRONG_GAMEOBJECT = "ZMookBigGuyStrong";

		public const string MECH_BROWN = "MechBrown";

		private const string MECH_BROWN_GAMEOBJECT = "ZMookArmouredGuy Brown";

		public const string SUICIDE_BRUISER = "SuicideBruiser";

		private const string SUICIDE_BRUISER_GAMEOBJECT = "ZMookSuicideBigGuy";

		public const string SNAKE = "Snake";

		private const string SNAKE_GAMEOBJECT = "ZSnake";

		public const string XENOMORPHE_BRAINBOX = "XenomorpheBrainbox";

		private const string XENOMORPHE_BRAINBOX_GAMEOBJECT = "ZAlienXenomorphBrainBox";

		public const string PRESIDANT_US = "PresidantUS";

		private const string PRESIDANT_US_GAMEOBJECT = "Presidant_BillClinton";

		public const string DENIZEN = "Denizen";

		public const string AGENT = "AgentCIA";

		private const string AGENT_GAMEOBJECT = "Agent";

		public const string SICK_PIG = "SickPig";

		private const string SICK_PIG_GAMEOBJECT = "Pig Rotten";

		public static string GetWearerName(object obj)
		{
			if (obj is Citizen)
			{
				Citizen val = (Citizen)((obj is Citizen) ? obj : null);
				if (((Object)((Component)val).gameObject).name.Contains("Presidant_BillClinton"))
				{
					return "PresidantUS";
				}
			}
			else if (obj is MookTrooper)
			{
				MookTrooper val2 = (MookTrooper)((obj is MookTrooper) ? obj : null);
				if (((Object)((Component)val2).gameObject).name.Contains("ZMookScientist"))
				{
					return "Scientist";
				}
				if (((Object)((Component)val2).gameObject).name.Contains("ZMook Strong"))
				{
					return "MookStrong";
				}
				if (((Object)((Component)val2).gameObject).name.Contains("Agent"))
				{
					return "AgentCIA";
				}
			}
			else if (obj is AlienXenomorph)
			{
				AlienXenomorph val3 = (AlienXenomorph)((obj is AlienXenomorph) ? obj : null);
				if (((Object)((Component)val3).gameObject).name.Contains("ZAlienXenomorphBrainBox"))
				{
					return "XenomorpheBrainbox";
				}
			}
			else if (obj is MookGeneral)
			{
				MookGeneral val4 = (MookGeneral)((obj is MookGeneral) ? obj : null);
				if (((Object)((Component)val4).gameObject).name.Contains("ZMook Alarmist"))
				{
					return "Alarmist";
				}
			}
			else if (obj is ScoutMook)
			{
				ScoutMook val5 = (ScoutMook)((obj is ScoutMook) ? obj : null);
				if (((Object)((Component)val5).gameObject).name.Contains("ZMookTreasure"))
				{
					return "MookTreasure";
				}
			}
			else if (obj is MookBigGuy)
			{
				MookBigGuy val6 = (MookBigGuy)((obj is MookBigGuy) ? obj : null);
				if (((Object)((Component)val6).gameObject).name.Contains("ZMookBigGuyStrong"))
				{
					return "BruiserStrong";
				}
			}
			else if (obj is MookArmouredGuy)
			{
				MookArmouredGuy val7 = (MookArmouredGuy)((obj is MookArmouredGuy) ? obj : null);
				if (((Object)((Component)val7).gameObject).name.Contains("ZMookArmouredGuy Brown"))
				{
					return "MechBrown";
				}
			}
			else if (obj is MookSuicide)
			{
				MookSuicide val8 = (MookSuicide)((obj is MookSuicide) ? obj : null);
				if (((Object)((Component)val8).gameObject).name.Contains("ZMookSuicideBigGuy"))
				{
					return "SuicideBruiser";
				}
			}
			else if (obj is Animal)
			{
				Animal val9 = (Animal)((obj is Animal) ? obj : null);
				if (((Object)((Component)val9).gameObject).name.Contains("Pig Rotten"))
				{
					return "SickPig";
				}
			}
			else if (obj is AlienFaceHugger)
			{
				AlienFaceHugger val10 = (AlienFaceHugger)((obj is AlienFaceHugger) ? obj : null);
				if (((Object)((Component)val10).gameObject).name.Contains("ZSnake"))
				{
					return "Snake";
				}
			}
			else if (obj is Villager)
			{
				Villager val11 = (Villager)((obj is Villager) ? obj : null);
				if (((Object)((Component)val11).gameObject).name.Contains("Denizen"))
				{
					return "Denizen";
				}
			}
			return obj.GetType().Name;
		}
	}
	[Obsolete("Use FuturisticAttire")]
	public class Attire : IAttire
	{
		public const string WEARER_KEY = "Wearer";

		public const string NAME_KEY = "Name";

		public string Name { get; set; }

		public string Wearer { get; set; }

		[JsonIgnore]
		public string Directory { get; set; }

		[JsonIgnore]
		public bool Enabled { get; set; }

		[JsonIgnore]
		public string Id => Wearer + "-" + Name;

		public Dictionary<string, string> Clothes { get; set; } = new Dictionary<string, string>();


		public Attire(string name, string directory)
		{
			Name = name;
			Directory = directory;
			Enabled = !Main.settings.unactiveFiles.Contains(Id);
		}

		public static Attire TryReadJson(string file)
		{
			string text = File.ReadAllText(file);
			Dictionary<string, string> dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(text);
			if (dictionary == null || dictionary.Count == 0)
			{
				throw new Exception("Json is empty");
			}
			if (!dictionary.ContainsKey("Wearer"))
			{
				throw new Exception("Wearer field is missing");
			}
			string name = Path.GetFileName(file);
			if (dictionary.ContainsKey("Name"))
			{
				name = dictionary["Name"];
			}
			return new Attire(name, Path.GetDirectoryName(file))
			{
				Clothes = dictionary,
				Wearer = dictionary["Wearer"]
			};
		}

		public void SuitUp(object obj)
		{
			Traverse traverse = HarmonyExtensions.GetTraverse(obj);
			string[] array = Clothes.Keys.ToArray();
			HarmonyExtensions.DynamicFieldsValueSetter(obj, ((IEnumerable<KeyValuePair<string, string>>)Clothes).ToDictionary((Func<KeyValuePair<string, string>, string>)((KeyValuePair<string, string> p) => p.Key), (Func<KeyValuePair<string, string>, object>)((KeyValuePair<string, string> p) => p.Value)), new string[2] { "Wearer", "Name" }, (Action<Traverse, string, object>)PutOn);
		}

		private void PutOn(Traverse field, string key, object value)
		{
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			string text = (string)value;
			if (string.IsNullOrEmpty(text))
			{
				return;
			}
			Type valueType = field.GetValueType();
			if ((object)valueType == typeof(SpriteSM))
			{
				SpriteSM value2 = field.GetValue<SpriteSM>();
				SpriteSMExtensions.SetTexture(value2, CreateTexture(text));
				field.SetValue((object)value2);
				return;
			}
			if ((object)valueType == typeof(Material))
			{
				Material value3 = field.GetValue<Material>();
				value3.mainTexture = CreateTexture(text);
				field.SetValue((object)value3);
				return;
			}
			if ((object)valueType == typeof(Texture))
			{
				field.SetValue((object)CreateTexture(text));
				return;
			}
			if ((object)valueType == typeof(Texture2D))
			{
				field.SetValue((object)(Texture2D)CreateTexture(text));
				return;
			}
			throw new Exception("Field value type is:" + valueType.Name);
		}

		private Texture CreateTexture(string path)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			ImageConversion.LoadImage(val, File.ReadAllBytes(Path.Combine(Directory, path)));
			((Texture)val).filterMode = (FilterMode)0;
			((Texture)val).anisoLevel = 1;
			((Texture)val).mipMapBias = 0f;
			((Texture)val).wrapMode = (TextureWrapMode)0;
			return (Texture)(object)val;
		}
	}
	public static class StorageRoom
	{
		public static readonly string WardrobesDirectory;

		[Obsolete("Not use since 'FuturisticAttires")]
		public static readonly Dictionary<string, string> defaultJson;

		private static Dictionary<string, Wardrobe> _wardrobes;

		private static List<string> subscribers;

		public static Dictionary<string, Wardrobe> Wardrobes => _wardrobes;

		static StorageRoom()
		{
			defaultJson = new Dictionary<string, string>
			{
				{ "Wearer", "" },
				{ "sprite", "" }
			};
			_wardrobes = new Dictionary<string, Wardrobe>();
			subscribers = new List<string>();
			WardrobesDirectory = Path.Combine(RocketLibUtils.GetRootDirectory(), "DM_Wardrobes");
			subscribers = new List<string>();
			subscribers.Add(WardrobesDirectory);
		}

		public static void Initialize()
		{
			_wardrobes.Clear();
			CheckDirectory();
			foreach (string subscriber in subscribers)
			{
				ReadFiles(subscriber);
			}
		}

		public static void ReadFiles(string directory, SearchOption searchOption = SearchOption.AllDirectories)
		{
			string[] files = Directory.GetFiles(directory, "*.json", searchOption);
			string[] array = files;
			foreach (string text in array)
			{
				if (Path.GetFileName(text).ToLower() == "info.json")
				{
					continue;
				}
				IAttire attire = null;
				try
				{
					if (text.EndsWith(".fa.json"))
					{
						attire = FuturisticAttire.TryLoadFromJson(text);
					}
					else if (text.EndsWith(".ac.json"))
					{
						AttireCollection attireCollection = AttireCollection.TryLoadFromJson(text);
						if (attireCollection != null)
						{
							LoadAttiresFromCollection(attireCollection);
						}
					}
					else
					{
						attire = Attire.TryReadJson(text);
					}
				}
				catch (Exception ex)
				{
					Main.Log(text + ":\n" + ex);
				}
				if (attire != null)
				{
					RegisterAttire(attire);
				}
			}
		}

		private static void RegisterAttire(IAttire attire)
		{
			if (!_wardrobes.ContainsKey(attire.Wearer))
			{
				_wardrobes.Add(attire.Wearer, new Wardrobe(attire.Wearer));
			}
			_wardrobes[attire.Wearer].AddAttire(attire);
		}

		private static void LoadAttiresFromCollection(AttireCollection attireCollection)
		{
			FuturisticAttire[] attires = attireCollection.Attires;
			foreach (FuturisticAttire attire in attires)
			{
				RegisterAttire(attire);
			}
		}

		public static void CreateJsonFile(string fileName, string directory)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			JsonSerializerSettings val = new JsonSerializerSettings
			{
				ReferenceLoopHandling = (ReferenceLoopHandling)1
			};
			File.WriteAllText(Path.Combine(directory, fileName + ".json"), JsonConvert.SerializeObject((object)defaultJson, val));
		}

		public static void CreateFuturisticAttireJsonFile(string fileName, string directory)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			JsonSerializerSettings val = new JsonSerializerSettings
			{
				ReferenceLoopHandling = (ReferenceLoopHandling)1
			};
			File.WriteAllText(Path.Combine(directory, fileName + ".fa.json"), JsonConvert.SerializeObject((object)new FuturisticAttire(fileName, directory), (Formatting)1, val));
		}

		public static void CreateAttireCollectionJsonFile(string fileName, string directory)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			JsonSerializerSettings val = new JsonSerializerSettings
			{
				ReferenceLoopHandling = (ReferenceLoopHandling)1
			};
			File.WriteAllText(Path.Combine(directory, fileName + ".ac.json"), JsonConvert.SerializeObject((object)new AttireCollection(), (Formatting)1, val));
		}

		public static void AddSubscriber(string path)
		{
			if (!subscribers.Contains(path))
			{
				subscribers.Add(path);
				ReadFiles(path);
			}
		}

		public static void RemoveSubscriber(string path)
		{
			if (subscribers.Contains(path))
			{
				subscribers.Remove(path);
				Initialize();
			}
		}

		private static void CheckDirectory()
		{
			if (!Directory.Exists(WardrobesDirectory))
			{
				Directory.CreateDirectory(WardrobesDirectory);
			}
		}
	}
	internal static class Main
	{
		public static ModEntry mod;

		public static bool enabled;

		public static Settings settings;

		public static bool CanPatch => enabled;

		private static bool Load(ModEntry modEntry)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			modEntry.OnGUI = OnGUI;
			modEntry.OnSaveGUI = OnSaveGUI;
			modEntry.OnToggle = OnToggle;
			settings = ModSettings.Load<Settings>(modEntry);
			mod = modEntry;
			Harmony val = new Harmony(modEntry.Info.Id);
			try
			{
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				val.PatchAll(executingAssembly);
			}
			catch (Exception ex)
			{
				mod.Logger.Log("Failed to Patch Harmony !\n" + ex.ToString());
			}
			Start();
			return true;
		}

		private static void Start()
		{
			StorageRoom.Initialize();
			ModUI.Initialize();
		}

		private static void OnGUI(ModEntry modEntry)
		{
			try
			{
				ModUI.MainGUI();
			}
			catch (Exception ex)
			{
				Log(ex.ToString());
			}
		}

		private static void OnSaveGUI(ModEntry modEntry)
		{
			((ModSettings)settings).Save(modEntry);
		}

		private static bool OnToggle(ModEntry modEntry, bool value)
		{
			enabled = value;
			return true;
		}

		public static void Log(object msg)
		{
			mod.Logger.Log(msg.ToString());
		}
	}
	public class Settings : ModSettings
	{
		public bool canUseDefaultSkin;

		public List<string> unactiveFiles = new List<string>();

		public bool useStats = false;

		public override void Save(ModEntry modEntry)
		{
			ModSettings.Save<Settings>(this, modEntry);
		}
	}
}
namespace DresserMod.Patches.NetworkedUnits
{
	[HarmonyPatch(typeof(NetworkedUnit), "Awake")]
	internal static class NetworkedUnit_Awake_Patch
	{
		private static void Postfix(NetworkedUnit __instance)
		{
			if (!Main.CanPatch || Object.op_Implicit((Object)(object)((__instance is TestVanDammeAnim) ? __instance : null)))
			{
				return;
			}
			string wearerName = Wearers.GetWearerName(__instance);
			if (!StorageRoom.Wardrobes.ContainsKey(wearerName))
			{
				return;
			}
			try
			{
				StorageRoom.Wardrobes[wearerName].SetRandomAttire(__instance);
			}
			catch (Exception msg)
			{
				Main.Log(msg);
			}
		}
	}
	[HarmonyPatch(typeof(TestVanDammeAnim), "Start")]
	internal static class TestVanDammeAnim_Start_Patch
	{
		private static void Prefix(NetworkedUnit __instance)
		{
			if (!Main.CanPatch)
			{
				return;
			}
			string wearerName = Wearers.GetWearerName(__instance);
			if (!StorageRoom.Wardrobes.ContainsKey(wearerName))
			{
				return;
			}
			try
			{
				StorageRoom.Wardrobes[wearerName].SetRandomAttire(__instance);
			}
			catch (Exception msg)
			{
				Main.Log(msg);
			}
		}
	}
}
namespace DresserMod.Patches.NetworkObjects
{
	[HarmonyPatch(typeof(HeroTransport), "Awake")]
	internal static class HeroTransport_Start_Patch
	{
		private static void Postfix(HeroTransport __instance)
		{
			if (!Main.CanPatch)
			{
				return;
			}
			string wearerName = Wearers.GetWearerName(__instance);
			if (!StorageRoom.Wardrobes.ContainsKey(wearerName))
			{
				return;
			}
			try
			{
				StorageRoom.Wardrobes[wearerName].SetRandomAttire(__instance);
			}
			catch (Exception msg)
			{
				Main.Log(msg);
			}
		}
	}
	[HarmonyPatch(typeof(AlarmSystem), "Start")]
	internal static class AlarmSystem_Start_Patch
	{
		private static void Postfix(AlarmSystem __instance)
		{
			if (!Main.CanPatch)
			{
				return;
			}
			string wearerName = Wearers.GetWearerName(__instance);
			if (!StorageRoom.Wardrobes.ContainsKey(wearerName))
			{
				return;
			}
			try
			{
				StorageRoom.Wardrobes[wearerName].SetRandomAttire(__instance);
			}
			catch (Exception msg)
			{
				Main.Log(msg);
			}
		}
	}
}
namespace DresserMod.Patches.BroforceObjects
{
	[HarmonyPatch(typeof(CheckPoint), "Awake")]
	internal static class CheckPoint_Awake_Patch
	{
		private static void Postfix(CheckPoint __instance)
		{
			if (!Main.CanPatch)
			{
				return;
			}
			string wearerName = Wearers.GetWearerName(__instance);
			if (!StorageRoom.Wardrobes.ContainsKey(wearerName))
			{
				return;
			}
			try
			{
				StorageRoom.Wardrobes[wearerName].SetRandomAttire(__instance);
			}
			catch (Exception msg)
			{
				Main.Log(msg);
			}
		}
	}
	[HarmonyPatch(typeof(Block), "FirstFrame")]
	internal static class Block_FirstFrame_Patch
	{
		private static void Postfix(Block __instance)
		{
			if (!Main.CanPatch || HarmonyExtensions.GetBool((object)__instance, "hasDoneFirstFrame"))
			{
				return;
			}
			string wearerName = Wearers.GetWearerName(__instance);
			if (!StorageRoom.Wardrobes.ContainsKey(wearerName))
			{
				return;
			}
			try
			{
				StorageRoom.Wardrobes[wearerName].SetRandomAttire(__instance);
			}
			catch (Exception msg)
			{
				Main.Log(msg);
			}
		}
	}
	[HarmonyPatch(typeof(Doodad), "Start")]
	internal static class Doodad_Start_Patch
	{
		private static void Postfix(Doodad __instance)
		{
			if (!Main.CanPatch)
			{
				return;
			}
			string wearerName = Wearers.GetWearerName(__instance);
			if (!StorageRoom.Wardrobes.ContainsKey(wearerName))
			{
				return;
			}
			try
			{
				StorageRoom.Wardrobes[wearerName].SetRandomAttire(__instance);
			}
			catch (Exception msg)
			{
				Main.Log(msg);
			}
		}
	}
	[HarmonyPatch(typeof(FollowingObject), "Start")]
	internal static class FollowingObject_Start_Patch
	{
		private static void Postfix(FollowingObject __instance)
		{
			if (!Main.CanPatch)
			{
				return;
			}
			string wearerName = Wearers.GetWearerName(__instance);
			if (!StorageRoom.Wardrobes.ContainsKey(wearerName))
			{
				return;
			}
			try
			{
				StorageRoom.Wardrobes[wearerName].SetRandomAttire(__instance);
			}
			catch (Exception msg)
			{
				Main.Log(msg);
			}
		}
	}
	[HarmonyPatch(typeof(Helicopter), "Start")]
	internal static class Helicopter_Start_Patch
	{
		private static void Postfix(Helicopter __instance)
		{
			if (!Main.CanPatch)
			{
				return;
			}
			string wearerName = Wearers.GetWearerName(__instance);
			if (!StorageRoom.Wardrobes.ContainsKey(wearerName))
			{
				return;
			}
			try
			{
				StorageRoom.Wardrobes[wearerName].SetRandomAttire(__instance);
			}
			catch (Exception msg)
			{
				Main.Log(msg);
			}
		}
	}
	[HarmonyPatch(typeof(Mine), "Start")]
	internal static class Mine_Start_Patch
	{
		private static void Postfix(Mine __instance)
		{
			if (!Main.CanPatch)
			{
				return;
			}
			string wearerName = Wearers.GetWearerName(__instance);
			if (!StorageRoom.Wardrobes.ContainsKey(wearerName))
			{
				return;
			}
			try
			{
				StorageRoom.Wardrobes[wearerName].SetRandomAttire(__instance);
			}
			catch (Exception msg)
			{
				Main.Log(msg);
			}
		}
	}
	[HarmonyPatch(typeof(Projectile), "Start")]
	internal static class Projectile_Start_Patch
	{
		private static void Postfix(Projectile __instance)
		{
			if (!Main.CanPatch)
			{
				return;
			}
			string wearerName = Wearers.GetWearerName(__instance);
			if (!StorageRoom.Wardrobes.ContainsKey(wearerName))
			{
				return;
			}
			try
			{
				StorageRoom.Wardrobes[wearerName].SetRandomAttire(__instance);
			}
			catch (Exception msg)
			{
				Main.Log(msg);
			}
		}
	}
	[HarmonyPatch(typeof(Shrapnel), "Start")]
	internal static class Shrapnel_Start_Patch
	{
		private static void Postfix(Shrapnel __instance)
		{
			if (!Main.CanPatch)
			{
				return;
			}
			string wearerName = Wearers.GetWearerName(__instance);
			if (!StorageRoom.Wardrobes.ContainsKey(wearerName))
			{
				return;
			}
			try
			{
				StorageRoom.Wardrobes[wearerName].SetRandomAttire(__instance);
			}
			catch (Exception msg)
			{
				Main.Log(msg);
			}
		}
	}
	[HarmonyPatch(typeof(Parachute), "Start")]
	internal static class Parachute_Start_Patch
	{
		private static void Postfix(Parachute __instance)
		{
			if (!Main.CanPatch)
			{
				return;
			}
			string wearerName = Wearers.GetWearerName(__instance);
			if (!StorageRoom.Wardrobes.ContainsKey(wearerName))
			{
				return;
			}
			try
			{
				StorageRoom.Wardrobes[wearerName].SetRandomAttire(__instance);
			}
			catch (Exception msg)
			{
				Main.Log(msg);
			}
		}
	}
}