Decompiled source of 45x Suit Variants v1.0.1

45x Suit Variants.dll

Decompiled 6 hours 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.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using Microsoft.CodeAnalysis;
using ModelReplacement;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;

[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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("45x Suit Variants")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("45x Suit Variants")]
[assembly: AssemblyTitle("45x Suit Variants")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace ffxsuitvariants
{
	[BepInPlugin("dev.45x.45xsuitvariants", "45x Suit Variants", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class FFXSuitVariants : BaseUnityPlugin
	{
		public static ManualLogSource PluginLogger = Logger.CreateLogSource("dev.45x.45xsuitvariants");

		private readonly Harmony Harmony = new Harmony("dev.45x.45xsuitvariants");

		public static Dictionary<string, List<Suit>> RegisteredSuits = new Dictionary<string, List<Suit>>();

		private void Awake()
		{
			PluginLogger.LogInfo((object)"Loading Plugin: dev.45x.45xsuitvariants");
			Stopwatch stopwatch = Stopwatch.StartNew();
			Harmony.PatchAll();
			stopwatch.Stop();
			PluginLogger.LogInfo((object)string.Format("Plugin {0} is loaded! Took {1}ms", "dev.45x.45xsuitvariants", stopwatch.ElapsedMilliseconds));
		}

		public static void AddSuit(string SuitName, string ParentSuitName, Type type)
		{
			Suit suit = new Suit(SuitName, type, IsVariant: true, IsActive: false);
			if (RegisteredSuits.ContainsKey(ParentSuitName))
			{
				RegisteredSuits[ParentSuitName].Add(suit);
				ModelReplacementAPI.RegisterModelReplacementException(suit.Type);
				PluginLogger.LogInfo((object)("Registered " + SuitName + " as variant of " + ParentSuitName));
				return;
			}
			suit.SetIsActive(IsActive: true);
			suit.SetIsVariant(IsVariant: false);
			RegisteredSuits.Add(ParentSuitName, new List<Suit>());
			RegisteredSuits[ParentSuitName].Add(suit);
			ModelReplacementAPI.RegisterSuitModelReplacement(suit.Name, suit.Type);
			PluginLogger.LogInfo((object)("Registered " + SuitName + " as parent suit"));
		}
	}
	public class Suit
	{
		public string Name;

		public Type Type;

		public bool IsVariant;

		public bool IsActive;

		public Suit(string Name, Type Type, bool IsVariant, bool IsActive)
		{
			this.Name = Name;
			this.Type = Type;
			this.IsVariant = IsVariant;
			this.IsActive = IsActive;
		}

		public void SetIsActive(bool IsActive)
		{
			this.IsActive = IsActive;
		}

		public void SetIsVariant(bool IsVariant)
		{
			this.IsVariant = IsVariant;
		}
	}
	public class VariantSwitchInput : LcInputActions
	{
		public static VariantSwitchInput Instance = new VariantSwitchInput();

		[InputAction("<Keyboard>/t", Name = "Switch Suit Variant")]
		public InputAction SwitchSuitVariantKey { get; set; }
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	public class VariantSwitchInputListener
	{
		public static PlayerControllerB PInstance;

		[HarmonyPatch("Awake")]
		[HarmonyPrefix]
		private static void Awake(PlayerControllerB __instance)
		{
			PlayerControllerB[] array = Object.FindObjectsOfType<PlayerControllerB>();
			for (int i = 0; i < array.Length; i++)
			{
				if (((NetworkBehaviour)array[i]).IsOwner)
				{
					PInstance = array[i];
				}
			}
			VariantSwitchInput.Instance.SwitchSuitVariantKey.performed += OnSuitSwitchKeyPressed;
		}

		public static void OnSuitSwitchKeyPressed(CallbackContext ctx)
		{
			if (((CallbackContext)(ref ctx)).performed && !PInstance.isPlayerDead)
			{
				SwitchSuitVariant();
			}
		}

		public static void SwitchSuitVariant()
		{
			BodyReplacementBase component = ((Component)PInstance).gameObject.GetComponent<BodyReplacementBase>();
			if ((Object)(object)component == (Object)null || !FFXSuitVariants.RegisteredSuits.ContainsKey(component.suitName))
			{
				return;
			}
			List<Suit> list = FFXSuitVariants.RegisteredSuits[component.suitName];
			if (list.Count <= 1)
			{
				return;
			}
			int num = 0;
			foreach (Suit item in list)
			{
				num++;
				if (item.IsActive)
				{
					break;
				}
			}
			if (num > list.Count - 1)
			{
				num = 0;
			}
			Suit suit = list[num];
			ModelReplacementAPI.SetPlayerModelReplacement(PInstance, suit.Type);
			FFXSuitVariants.RegisteredSuits[component.suitName].ForEach(delegate(Suit Suit)
			{
				Suit.SetIsActive(IsActive: false);
			});
			suit.SetIsActive(IsActive: true);
		}
	}
	[HarmonyPatch(typeof(UnlockableSuit))]
	public class SuitSwitchListener
	{
		[HarmonyPatch("SwitchSuitToThis")]
		[HarmonyPostfix]
		public static void SwitchSuitToThis(PlayerControllerB playerWhoTriggered)
		{
			BodyReplacementBase val = default(BodyReplacementBase);
			ModelReplacementAPI.GetPlayerModelReplacement(playerWhoTriggered, ref val);
			if ((Object)(object)val != (Object)null)
			{
				FFXSuitVariants.RegisteredSuits[val.suitName].ForEach(delegate(Suit Suit)
				{
					Suit.SetIsActive(IsActive: false);
				});
				FFXSuitVariants.RegisteredSuits[val.suitName].First().SetIsActive(IsActive: true);
				ModelReplacementAPI.RemovePlayerModelReplacement(playerWhoTriggered);
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}