Decompiled source of Drag0 BareBones v1.0.1

BepInEx/plugins/x753-More_Suits/MoreSuits.dll

Decompiled 8 months 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.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.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0")]
[assembly: AssemblyProduct("MoreSuits")]
[assembly: AssemblyTitle("MoreSuits")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.0.0")]
[module: UnverifiableCode]
namespace MoreSuits;

[BepInPlugin("x753.More_Suits", "More Suits", "1.2.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_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Expected O, but got Unknown
			//IL_02b9: 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;
						val2.unlockableName = Path.GetFileNameWithoutExtension(path);
						try
						{
							string path2 = Path.Combine(SuitsFolder, "advanced", val2.unlockableName + ".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)
									{
										continue;
									}
									string text4 = array5[0].Trim('"', ' ', ',');
									string text5 = array5[1].Trim('"', ' ', ',');
									float result2;
									Vector4 vector;
									if (text4 == "PRICE" && int.TryParse(text5, out var result))
									{
										try
										{
											AddToRotatingShop(val2, result, __instance.unlockablesList.unlockables.Count);
										}
										catch (Exception ex)
										{
											Debug.Log((object)("Something went wrong with More Suits! Could not add a suit to the rotating shop. Error: " + ex));
										}
									}
									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);
										ImageConversion.LoadImage(val5, array6);
										val3.SetTexture(text4, (Texture)(object)val5);
									}
									else if (float.TryParse(text5, out result2))
									{
										val3.SetFloat(text4, result2);
									}
									else if (TryParseVector4(text5, out vector))
									{
										val3.SetVector(text4, vector);
									}
								}
							}
						}
						catch (Exception ex2)
						{
							Debug.Log((object)("Something went wrong with More Suits! Error: " + ex2));
						}
						val2.suitMaterial = val3;
						if (val2.unlockableName != "Default")
						{
							__instance.unlockablesList.unlockables.Add(val2);
						}
					}
					SuitsAdded = true;
					break;
				}
			}
			catch (Exception ex3)
			{
				Debug.Log((object)("Something went wrong with More Suits! Error: " + ex3));
			}
		}
	}

	private const string modGUID = "x753.More_Suits";

	private const string modName = "More Suits";

	private const string modVersion = "1.2.0";

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

	private static MoreSuitsMod Instance;

	public static string SuitsFolder;

	public static bool SuitsAdded;

	private static TerminalNode cancelPurchase;

	private static TerminalKeyword buyKeyword;

	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!");
	}

	private static void AddToRotatingShop(UnlockableItem newSuit, int price, int unlockableID)
	{
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Expected O, but got Unknown
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Expected O, but got Unknown
		//IL_0293: Unknown result type (might be due to invalid IL or missing references)
		//IL_029a: Expected O, but got Unknown
		Terminal val = Object.FindObjectOfType<Terminal>();
		for (int i = 0; i < val.terminalNodes.allKeywords.Length; i++)
		{
			if (((Object)val.terminalNodes.allKeywords[i]).name == "Buy")
			{
				buyKeyword = val.terminalNodes.allKeywords[i];
				break;
			}
		}
		newSuit.alreadyUnlocked = false;
		newSuit.shopSelectionNode = ScriptableObject.CreateInstance<TerminalNode>();
		((Object)newSuit.shopSelectionNode).name = newSuit.unlockableName + "SuitBuy1";
		newSuit.shopSelectionNode.creatureName = newSuit.unlockableName + " suit";
		newSuit.shopSelectionNode.displayText = "You have requested to order " + newSuit.unlockableName + " suits.\nTotal cost of item: [totalCost].\n\nPlease CONFIRM or DENY.\n\n";
		newSuit.shopSelectionNode.clearPreviousText = true;
		newSuit.shopSelectionNode.shipUnlockableID = unlockableID;
		newSuit.shopSelectionNode.itemCost = price;
		newSuit.shopSelectionNode.overrideOptions = true;
		CompatibleNoun val2 = new CompatibleNoun();
		val2.noun = ScriptableObject.CreateInstance<TerminalKeyword>();
		val2.noun.word = "confirm";
		val2.noun.isVerb = true;
		val2.result = ScriptableObject.CreateInstance<TerminalNode>();
		((Object)val2.result).name = newSuit.unlockableName + "SuitBuyConfirm";
		val2.result.creatureName = "";
		val2.result.displayText = "Ordered " + newSuit.unlockableName + " suits! Your new balance is [playerCredits].\n\n";
		val2.result.clearPreviousText = true;
		val2.result.shipUnlockableID = unlockableID;
		val2.result.buyUnlockable = true;
		val2.result.itemCost = price;
		val2.result.terminalEvent = "";
		CompatibleNoun val3 = new CompatibleNoun();
		val3.noun = ScriptableObject.CreateInstance<TerminalKeyword>();
		val3.noun.word = "deny";
		val3.noun.isVerb = true;
		if ((Object)(object)cancelPurchase == (Object)null)
		{
			cancelPurchase = ScriptableObject.CreateInstance<TerminalNode>();
		}
		val3.result = cancelPurchase;
		((Object)val3.result).name = "MoreSuitsCancelPurchase";
		val3.result.displayText = "Cancelled order.\n";
		newSuit.shopSelectionNode.terminalOptions = (CompatibleNoun[])(object)new CompatibleNoun[2] { val2, val3 };
		TerminalKeyword val4 = ScriptableObject.CreateInstance<TerminalKeyword>();
		((Object)val4).name = newSuit.unlockableName + "Suit";
		val4.word = newSuit.unlockableName.ToLower() + " suit";
		val4.defaultVerb = buyKeyword;
		CompatibleNoun val5 = new CompatibleNoun();
		val5.noun = val4;
		val5.result = newSuit.shopSelectionNode;
		List<CompatibleNoun> list = buyKeyword.compatibleNouns.ToList();
		list.Add(val5);
		buyKeyword.compatibleNouns = list.ToArray();
		List<TerminalKeyword> list2 = val.terminalNodes.allKeywords.ToList();
		list2.Add(val4);
		list2.Add(val2.noun);
		list2.Add(val3.noun);
		val.terminalNodes.allKeywords = list2.ToArray();
	}

	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;
	}
}