Decompiled source of 89SQUAD v5.4.2100

BepInEx/plugins/MoreSuits.dll

Decompiled a year ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("MoreSuits")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A mod that adds more suit options to Lethal Company")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("MoreSuits")]
[assembly: AssemblyTitle("MoreSuits")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
namespace MoreSuits;

[BepInPlugin("x753.More_Suits", "More Suits", "1.1.0")]
public class MoreSuitsMod : BaseUnityPlugin
{
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void StartPatch(ref StartOfRound __instance)
		{
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Expected O, but got Unknown
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Expected O, but got Unknown
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (SuitsAdded)
				{
					return;
				}
				for (int i = 0; i < __instance.unlockablesList.unlockables.Count; i++)
				{
					UnlockableItem val = __instance.unlockablesList.unlockables[i];
					if (!((Object)(object)val.suitMaterial != (Object)null) || !val.alreadyUnlocked)
					{
						continue;
					}
					string[] files = Directory.GetFiles(SuitsFolder, "*.png");
					string[] array = files;
					foreach (string text in array)
					{
						UnlockableItem val2;
						Material val3;
						if (Path.GetFileNameWithoutExtension(text) == "default")
						{
							val2 = val;
							val3 = val2.suitMaterial;
						}
						else
						{
							string text2 = JsonUtility.ToJson((object)val);
							val2 = JsonUtility.FromJson<UnlockableItem>(text2);
							val3 = Object.Instantiate<Material>(val2.suitMaterial);
						}
						string path = Path.Combine(SuitsFolder, text);
						byte[] array2 = File.ReadAllBytes(path);
						Texture2D val4 = new Texture2D(2, 2);
						ImageConversion.LoadImage(val4, array2);
						val3.mainTexture = (Texture)(object)val4;
						try
						{
							string path2 = Path.Combine(SuitsFolder, "advanced", Path.GetFileNameWithoutExtension(text) + ".json");
							if (File.Exists(path2))
							{
								string[] array3 = File.ReadAllLines(path2);
								string[] array4 = array3;
								foreach (string text3 in array4)
								{
									string[] array5 = text3.Trim().Split(':');
									if (array5.Length == 2)
									{
										string text4 = array5[0].Trim('"', ' ', ',');
										string text5 = array5[1].Trim('"', ' ', ',');
										Vector4 vector;
										if (float.TryParse(text5, out var result))
										{
											val3.SetFloat(text4, result);
										}
										else if (text5 == "KEYWORD")
										{
											val3.EnableKeyword(text4);
										}
										else if (text5.Contains(".png"))
										{
											string path3 = Path.Combine(SuitsFolder, "advanced", text5);
											byte[] array6 = File.ReadAllBytes(path3);
											Texture2D val5 = new Texture2D(2, 2, (TextureFormat)4, true, true);
											ImageConversion.LoadImage(val5, array6);
											val3.SetTexture(text4, (Texture)(object)val5);
										}
										else if (TryParseVector4(text5, out vector))
										{
											val3.SetVector(text4, vector);
										}
									}
								}
							}
						}
						catch (Exception ex)
						{
							Debug.Log((object)("Something went wrong with More Suits! Error: " + ex));
						}
						val2.suitMaterial = val3;
						val2.unlockableName = Path.GetFileNameWithoutExtension(path);
						if (Path.GetFileNameWithoutExtension(text) != "default")
						{
							__instance.unlockablesList.unlockables.Add(val2);
						}
					}
					SuitsAdded = true;
					break;
				}
			}
			catch (Exception ex2)
			{
				Debug.Log((object)("Something went wrong with More Suits! Error: " + ex2));
			}
		}
	}

	private const string modGUID = "x753.More_Suits";

	private const string modName = "More Suits";

	private const string modVersion = "1.1.0";

	private readonly Harmony harmony = new Harmony("x753.More_Suits");

	private static MoreSuitsMod Instance;

	public static string SuitsFolder;

	public static bool SuitsAdded;

	private void Awake()
	{
		SuitsFolder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "suits");
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
		}
		harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin More Suits is loaded!");
	}

	public static bool TryParseVector4(string input, out Vector4 vector)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		vector = Vector4.zero;
		string[] array = input.Split(',');
		if (array.Length == 4 && float.TryParse(array[0], out var result) && float.TryParse(array[1], out var result2) && float.TryParse(array[2], out var result3) && float.TryParse(array[3], out var result4))
		{
			vector = new Vector4(result, result2, result3, result4);
			return true;
		}
		return false;
	}
}