Decompiled source of LethalFashion v1.0.7

BepInEx/plugins/LethalFashion.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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 = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LethalFashion")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Unlocks all base game suits for free to use immediately.")]
[assembly: AssemblyFileVersion("1.0.6.0")]
[assembly: AssemblyInformationalVersion("1.0.6")]
[assembly: AssemblyProduct("LethalFashion")]
[assembly: AssemblyTitle("LethalFashion")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.6.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LethalFashion
{
	[BepInPlugin("LethalFashion", "LethalFashion", "1.0.6")]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource Log;

		private static Harmony harmonyInstance;

		public ConfigEntry<string> SuitUnlockConfig;

		public static Plugin Instance { get; private set; }

		private void Awake()
		{
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin LethalFashion is loaded!");
			SuitUnlockConfig = ((BaseUnityPlugin)this).Config.Bind<string>("General", "SuitUnlocks", "Green Suit, Hazard Suit, Pajama Suit, Purple Suit, Bee Suit, Bunny Suit", "Names of the suits to unlock. You can remove them off of this list to ignore unlocking them. This should work for future game updates and can be used to unlock suits from other mods if you know the suit name.");
			InitializeHarmony();
		}

		private void InitializeHarmony()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			if (harmonyInstance == null)
			{
				harmonyInstance = new Harmony("LethalFashion");
				try
				{
					harmonyInstance.PatchAll(typeof(SuitFashion));
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Patch applied successfully. You are now FASHIONABLE.");
				}
				catch (Exception ex)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)("Error applying patch: " + ex.Message));
				}
			}
		}
	}
	public class SuitFashion
	{
		private static readonly MethodInfo unlockItem;

		private static bool isHost;

		static SuitFashion()
		{
			unlockItem = typeof(StartOfRound).GetMethod("SpawnUnlockable", BindingFlags.Instance | BindingFlags.NonPublic);
			if (unlockItem == null)
			{
				Plugin.Log.LogError((object)"SpawnUnlockable method not found in StartOfRound. Please check game/plugin version.");
			}
			else
			{
				Plugin.Log.LogInfo((object)"SpawnUnlockable method found successfully.");
			}
		}

		public static void SpawnUnlockableDelegate(StartOfRound instance, int ID)
		{
			if (unlockItem == null)
			{
				Plugin.Log.LogError((object)"SpawnUnlockable method reference is null.");
			}
			else if (!instance.SpawnedShipUnlockables.ContainsKey(ID))
			{
				try
				{
					unlockItem.Invoke(instance, new object[1] { ID });
				}
				catch (Exception ex)
				{
					Plugin.Log.LogError((object)$"Error invoking SpawnUnlockable for ID {ID}: {ex.Message}");
				}
			}
		}

		public static void PositionSuitsOnRack(StartOfRound startOfRoundInstance)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			UnlockableSuit[] array = Object.FindObjectsOfType<UnlockableSuit>();
			for (int i = 0; i < array.Length; i++)
			{
				UnlockableSuit val = array[i];
				AutoParentToShip component = ((Component)val).gameObject.GetComponent<AutoParentToShip>();
				if ((Object)(object)component != (Object)null)
				{
					component.overrideOffset = true;
					component.positionOffset = new Vector3(-2.45f, 2.75f, -8.41f) + startOfRoundInstance.rightmostSuitPosition.forward * 0.18f * (float)i;
					component.rotationOffset = new Vector3(0f, 90f, 0f);
				}
			}
		}

		private static void UnlockAndSpawnSuits(StartOfRound startOfRoundInstance)
		{
			string value = Plugin.Instance.SuitUnlockConfig.Value;
			HashSet<string> hashSet = new HashSet<string>(from s in value.Split(',')
				select s.Trim(), StringComparer.OrdinalIgnoreCase);
			for (int i = 0; i < startOfRoundInstance.unlockablesList.unlockables.Count; i++)
			{
				UnlockableItem val = startOfRoundInstance.unlockablesList.unlockables[i];
				if (val != null && (Object)(object)val.suitMaterial != (Object)null && hashSet.Contains(val.unlockableName))
				{
					Plugin.Log.LogInfo((object)$"Unlocking suit: ID={i}, Name={val.unlockableName}");
					val.alreadyUnlocked = true;
					val.hasBeenUnlockedByPlayer = true;
					val.inStorage = false;
					SpawnUnlockableDelegate(startOfRoundInstance, i);
				}
			}
			Plugin.Log.LogInfo((object)"Finished unlocking and spawning suits.");
		}

		[HarmonyPatch(typeof(StartOfRound), "Start")]
		[HarmonyPostfix]
		public static void StartOfRoundSuitPatch(StartOfRound __instance)
		{
			isHost = GameNetworkManager.Instance.isHostingGame;
			if (isHost)
			{
				UnlockAndSpawnSuits(__instance);
				PositionSuitsOnRack(__instance);
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "ResetShip")]
		[HarmonyPostfix]
		public static void ResetShipSuitPatch(StartOfRound __instance)
		{
			if (isHost)
			{
				StartOfRoundSuitPatch(__instance);
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LethalFashion";

		public const string PLUGIN_NAME = "LethalFashion";

		public const string PLUGIN_VERSION = "1.0.6";
	}
}