Decompiled source of BuyableHauntedMasks v1.1.0

BuyableHauntedMasks.dll

Decompiled 3 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 LethalLib.Modules;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("BuyableHauntedMasks")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyCopyright("Copyright © 2023 MegaPiggy")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+69f36b186802eacf4a706f85f966a0a1614dad30")]
[assembly: AssemblyProduct("BuyableHauntedMasks")]
[assembly: AssemblyTitle("BuyableHauntedMasks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 BuyableHauntedMasks
{
	[BepInDependency("evaisa.lethallib", "0.13.2")]
	[BepInPlugin("MegaPiggy.BuyableHauntedMasks", "Buyable Haunted Masks", "1.1.0")]
	public class BuyableHauntedMasks : BaseUnityPlugin
	{
		private const string modGUID = "MegaPiggy.BuyableHauntedMasks";

		private const string modName = "Buyable Haunted Masks";

		private const string modVersion = "1.1.0";

		private readonly Harmony harmony = new Harmony("MegaPiggy.BuyableHauntedMasks");

		private static BuyableHauntedMasks Instance;

		private static ConfigEntry<int> ComedyMaskPriceConfig;

		private static ConfigEntry<int> TragedyMaskPriceConfig;

		private static Dictionary<string, TerminalNode> infoNodes = new Dictionary<string, TerminalNode>();

		private static ManualLogSource LoggerInstance => ((BaseUnityPlugin)Instance).Logger;

		public static List<Item> AllItems => Resources.FindObjectsOfTypeAll<Item>().Concat(Object.FindObjectsByType<Item>((FindObjectsInactive)1, (FindObjectsSortMode)1)).ToList();

		public static Item Comedy => ((IEnumerable<Item>)AllItems).FirstOrDefault((Func<Item, bool>)((Item item) => ((Object)item).name.Equals("ComedyMask")));

		public static Item Tragedy => ((IEnumerable<Item>)AllItems).FirstOrDefault((Func<Item, bool>)((Item item) => ((Object)item).name.Equals("TragedyMask")));

		public static Item ComedyClone { get; private set; }

		public static GameObject ComedyObjectClone { get; private set; }

		public static Item TragedyClone { get; private set; }

		public static GameObject TragedyObjectClone { get; private set; }

		public static int ComedyMaskPrice => ComedyMaskPriceConfig.Value;

		public static int TragedyMaskPrice => TragedyMaskPriceConfig.Value;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Object.DontDestroyOnLoad((Object)(object)this);
				Instance = this;
			}
			harmony.PatchAll();
			ComedyMaskPriceConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Prices", "ComedyMaskPrice", 30, "Credits needed to buy comedy mask");
			TragedyMaskPriceConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Prices", "TragedyMaskPrice", 30, "Credits needed to buy tragedy mask");
			SceneManager.sceneLoaded += OnSceneLoaded;
			ComedyClone = MakeNonScrap(ComedyMaskPrice, "C");
			TragedyClone = MakeNonScrap(TragedyMaskPrice, "T");
			AddComedyToShop();
			AddTragedyToShop();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Buyable Haunted Masks is loaded with version 1.1.0!");
		}

		private static Item MakeNonScrap(int price, string name = "")
		{
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: 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_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			Item val = ScriptableObject.CreateInstance<Item>();
			Object.DontDestroyOnLoad((Object)(object)val);
			((Object)val).name = "Error";
			val.itemName = "Error";
			val.itemId = 6624;
			val.isScrap = false;
			val.creditsWorth = price;
			val.canBeGrabbedBeforeGameStart = true;
			val.automaticallySetUsingPower = false;
			val.batteryUsage = 300f;
			val.canBeInspected = false;
			val.isDefensiveWeapon = true;
			val.saveItemVariable = true;
			val.syncGrabFunction = false;
			val.twoHandedAnimation = true;
			val.verticalOffset = 0.25f;
			GameObject val2 = NetworkPrefabs.CreateNetworkPrefab("Cube" + name);
			GameObject val3 = GameObject.CreatePrimitive((PrimitiveType)3);
			val3.transform.SetParent(val2.transform, false);
			((Renderer)val3.GetComponent<MeshRenderer>()).sharedMaterial.shader = Shader.Find("HDRP/Lit");
			val2.AddComponent<BoxCollider>().size = Vector3.one * 2f;
			val2.AddComponent<AudioSource>();
			PhysicsProp val4 = val2.AddComponent<PhysicsProp>();
			((GrabbableObject)val4).itemProperties = val;
			((GrabbableObject)val4).grabbable = true;
			val.spawnPrefab = val2;
			val2.tag = "PhysicsProp";
			val2.layer = LayerMask.NameToLayer("Props");
			val3.layer = LayerMask.NameToLayer("Props");
			try
			{
				GameObject val5 = Object.Instantiate<GameObject>(Items.scanNodePrefab, val2.transform);
				((Object)val5).name = "ScanNode";
				val5.transform.localPosition = new Vector3(0f, 0f, 0f);
				Transform transform = val5.transform;
				transform.localScale *= 2f;
				ScanNodeProperties component = val5.GetComponent<ScanNodeProperties>();
				component.nodeType = 1;
				component.headerText = "Error";
				component.subText = "A mod is incompatible with Buyable Haunted Masks";
			}
			catch (Exception ex)
			{
				LoggerInstance.LogError((object)ex.ToString());
			}
			val2.transform.localScale = Vector3.one / 2f;
			return val;
		}

		private static GameObject CloneNonScrap(Item original, Item clone, int price)
		{
			GameObject val = NetworkPrefabs.CloneNetworkPrefab(original.spawnPrefab, (string)null);
			Object.DontDestroyOnLoad((Object)(object)val);
			CopyFields(original, clone);
			val.GetComponent<GrabbableObject>().itemProperties = clone;
			clone.spawnPrefab = val;
			((Object)clone).name = "Buyable" + ((Object)original).name;
			clone.creditsWorth = price;
			return val;
		}

		public static void CopyFields(Item source, Item destination)
		{
			FieldInfo[] fields = typeof(Item).GetFields();
			FieldInfo[] array = fields;
			foreach (FieldInfo fieldInfo in array)
			{
				fieldInfo.SetValue(destination, fieldInfo.GetValue(source));
			}
		}

		private static TerminalNode CreateInfoNode(string name, string description)
		{
			if (infoNodes.ContainsKey(name))
			{
				return infoNodes[name];
			}
			TerminalNode val = ScriptableObject.CreateInstance<TerminalNode>();
			val.clearPreviousText = true;
			((Object)val).name = name + "InfoNode";
			val.displayText = description + "\n\n";
			infoNodes.Add(name, val);
			return val;
		}

		private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			CloneComedy();
			CloneTragedy();
		}

		private static void CloneComedy()
		{
			if (!((Object)(object)Comedy == (Object)null) && !((Object)(object)ComedyObjectClone != (Object)null))
			{
				ComedyObjectClone = CloneNonScrap(Comedy, ComedyClone, ComedyMaskPrice);
			}
		}

		private static void AddComedyToShop()
		{
			Item comedyClone = ComedyClone;
			int comedyMaskPrice = ComedyMaskPrice;
			Items.RegisterShopItem(comedyClone, (TerminalNode)null, (TerminalNode)null, CreateInfoNode("ComedyMask", "Haunted mask. It has a 65% chance to turn you into zombie every 5 seconds."), comedyMaskPrice);
			LoggerInstance.LogInfo((object)$"Comedy Mask added to Shop for {ComedyMaskPrice} credits");
		}

		private static void CloneTragedy()
		{
			if (!((Object)(object)Tragedy == (Object)null) && !((Object)(object)TragedyObjectClone != (Object)null))
			{
				TragedyObjectClone = CloneNonScrap(Tragedy, TragedyClone, TragedyMaskPrice);
			}
		}

		private static void AddTragedyToShop()
		{
			Item tragedyClone = TragedyClone;
			int tragedyMaskPrice = TragedyMaskPrice;
			Items.RegisterShopItem(tragedyClone, (TerminalNode)null, (TerminalNode)null, CreateInfoNode("TragedyMask", "Haunted mask. It has a 65% chance to turn you into zombie every 5 seconds. You cannot take this off once you put it on."), tragedyMaskPrice);
			LoggerInstance.LogInfo((object)$"Tragedy Mask added to Shop for {TragedyMaskPrice} credits");
		}
	}
}