Decompiled source of Halloweenie Spooktacular Trick or Treating v1.0.0

plugins/TrickOrTreat.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("TrickOrTreat")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TrickOrTreat")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5d0825bc-9ef3-4479-836f-3fd2d5bfd0c1")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[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 TrickOrTreat
{
	[BepInPlugin("com.VentureBucket.TrickOrTreat", "TrickOrTreat", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	internal class TrickOrTreatPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Character), "OnDeath")]
		public static class Patch_Character_OnDeath
		{
			private static void Postfix(Character __instance)
			{
				//IL_0089: Unknown result type (might be due to invalid IL or missing references)
				//IL_0094: Unknown result type (might be due to invalid IL or missing references)
				GameObject val = null;
				int num = Random.Range(0, 8);
				val = ((num == 0) ? Candy1 : ((num == 1) ? Candy2 : ((num == 2) ? Candy3 : ((num == 3) ? Candy4 : ((num >= 6) ? Ghost : Bat)))));
				if ((Object)(object)val != (Object)null && Utils.GetPrefabName(((Object)__instance).name) != "Bat" && Utils.GetPrefabName(((Object)__instance).name) != "Ghost")
				{
					Object.Instantiate<GameObject>(val, ((Component)__instance).transform.position, ((Component)__instance).transform.rotation);
				}
			}
		}

		public const string PluginGUID = "com.VentureBucket.TrickOrTreat";

		public const string PluginName = "TrickOrTreat";

		public const string PluginVersion = "1.0.0";

		private readonly Harmony HarmonyInstance = new Harmony("com.VentureBucket.TrickOrTreat");

		public static GameObject Candy1;

		public static GameObject Candy2;

		public static GameObject Candy3;

		public static GameObject Candy4;

		public static GameObject Bat;

		public static GameObject Ghost;

		public void Awake()
		{
			AddItems();
			PrefabManager.OnPrefabsRegistered += AssignPrefabs;
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			HarmonyInstance.PatchAll(executingAssembly);
			Logger.LogInfo((object)"Trick Or Treat!");
		}

		private void AddItems()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected O, but got Unknown
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Expected O, but got Unknown
			AssetBundle obj = AssetUtils.LoadAssetBundleFromResources("trick_or_treat", Assembly.GetExecutingAssembly());
			GameObject val = obj.LoadAsset<GameObject>("VB_Candy1");
			ItemConfig val2 = new ItemConfig();
			val2.Name = "Turnip Candy";
			val2.Description = "A suspiciously sour Turnip candy.";
			ItemManager.Instance.AddItem(new CustomItem(val, true, val2));
			GameObject val3 = obj.LoadAsset<GameObject>("VB_Candy2");
			ItemConfig val4 = new ItemConfig();
			val4.Name = "Candy Carrot";
			val4.Description = "A sweet carrot, it's kinda yellow.";
			ItemManager.Instance.AddItem(new CustomItem(val3, true, val4));
			GameObject val5 = obj.LoadAsset<GameObject>("VB_Candy3");
			ItemConfig val6 = new ItemConfig();
			val6.Name = "Dipped Greydwarf Eye";
			val6.Description = "Who knew their eyes were so crunchy?";
			ItemManager.Instance.AddItem(new CustomItem(val5, true, val6));
			GameObject val7 = obj.LoadAsset<GameObject>("VB_Candy4");
			ItemConfig val8 = new ItemConfig();
			val8.Name = "Gummy Axe";
			val8.Description = "Harmless, except for the cavities.";
			ItemManager.Instance.AddItem(new CustomItem(val7, true, val8));
		}

		public void AssignPrefabs()
		{
			Candy1 = GetItem("VB_Candy1");
			Candy2 = GetItem("VB_Candy2");
			Candy3 = GetItem("VB_Candy3");
			Candy4 = GetItem("VB_Candy4");
			Bat = GetCreature("Bat");
			Ghost = GetCreature("Ghost");
			PrefabManager.OnPrefabsRegistered -= AssignPrefabs;
		}

		public static GameObject GetItem(string name)
		{
			if (!Utility.IsNullOrWhiteSpace(name))
			{
				try
				{
					return ObjectDB.instance.GetItemPrefab(StringExtensionMethods.GetStableHashCode(name));
				}
				catch
				{
					return ObjectDB.instance.GetItemPrefab(name);
				}
			}
			return null;
		}

		public static GameObject GetCreature(string name)
		{
			if (!Utility.IsNullOrWhiteSpace(name))
			{
				try
				{
					return ZNetScene.instance.m_namedPrefabs[StringExtensionMethods.GetStableHashCode(name)];
				}
				catch
				{
					List<GameObject> prefabs = ZNetScene.instance.m_prefabs;
					for (int i = 0; i < prefabs.Count; i++)
					{
						if (((Object)prefabs[i]).name.Equals(name))
						{
							return prefabs[i];
						}
					}
				}
			}
			return null;
		}
	}
}