Decompiled source of BreakableSnowmen v1.0.0

BreakableSnowmen.dll

Decompiled 2 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using Breakables.Patches;
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: AssemblyTitle("Breakable Snowmen")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Breakable Snowmen")]
[assembly: AssemblyCopyright("Copyright Spookybuddy 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("28f2f16b-6471-4c7e-b0a4-007e3a2450d4")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Breakables
{
	public class BreakSnowman : MonoBehaviour
	{
		public List<GameObject> prefabs = new List<GameObject>();

		private void OnTriggerEnter(Collider other)
		{
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			VehicleController val = default(VehicleController);
			if (!((Component)other).TryGetComponent<VehicleController>(ref val) || !(((Vector3)(ref val.averageVelocity)).magnitude > 3f))
			{
				return;
			}
			if (prefabs.Count > 0)
			{
				int num = ((prefabs.Count > 1) ? ((int)(100f * Mathf.Abs(((Component)this).transform.position.y)) % prefabs.Count) : 0);
				if ((Object)(object)prefabs[num] != (Object)null && num < prefabs.Count && num > -1)
				{
					GameObject val2 = Object.Instantiate<GameObject>(prefabs[num], ((Component)this).transform.parent.position, default(Quaternion), RoundManager.Instance.mapPropsContainer.transform);
					if (((Object)((Component)this).transform.parent).name.Equals("SnowmanTall(Clone)"))
					{
						val2.transform.localScale = new Vector3(1f, 1.5f, 1f);
					}
				}
				else
				{
					BreakableSnowmenModBase.mls.LogError((object)$"{num} was either out of range or null!");
				}
			}
			Object.Destroy((Object)(object)((Component)((Component)this).transform.parent).gameObject);
			VehicleController obj = val;
			Vector3 val3 = val.mainRigidbody.position - ((Component)this).transform.position;
			obj.CarReactToObstacle(((Vector3)(ref val3)).normalized, ((Component)this).transform.position, Vector3.zero, (CarObstacleType)2, 1f, (EnemyAI)null, true);
		}
	}
	[BepInPlugin("BreakableSnowmen", "BreakableSnowmen", "1.0.0")]
	public class BreakableSnowmenModBase : BaseUnityPlugin
	{
		public const string modGUID = "BreakableSnowmen";

		private const string modName = "BreakableSnowmen";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("BreakableSnowmen");

		internal static BreakableSnowmenModBase Instance;

		internal static ManualLogSource mls;

		internal GameObject trigger;

		internal GameObject tallTrigger;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("BreakableSnowmen");
			string text = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location).ToString();
			string[] array = text.Split(new char[1] { '\\' });
			for (int num = array.Length - 1; num > 0; num--)
			{
				if (array[num].Equals("plugins"))
				{
					for (int i = 0; i < array.Length - num - 1; i++)
					{
						text = Directory.GetParent(text).ToString();
					}
					text = Directory.GetFiles(text, "breakablesnowmen.bundle", SearchOption.AllDirectories)[0];
					break;
				}
			}
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), text));
			if ((Object)(object)val != (Object)null)
			{
				GameObject[] array2 = val.LoadAllAssets<GameObject>();
				for (int j = 0; j < array2.Length; j++)
				{
					if (!array2[j].CompareTag("Puddle"))
					{
						BreakSnowman breakSnowman = array2[j].AddComponent<BreakSnowman>();
						for (int k = 0; k < array2.Length; k++)
						{
							breakSnowman.prefabs.Add(array2[k]);
						}
						if (((Object)array2[j]).name.Equals("SnowmanTrigger"))
						{
							trigger = array2[j];
						}
						if (((Object)array2[j]).name.Equals("TallSnowmanTrigger"))
						{
							tallTrigger = array2[j];
						}
					}
				}
			}
			else
			{
				mls.LogError((object)"Failed to load breakablesnowmen.bundle");
			}
			harmony.PatchAll(typeof(BreakableSnowmenModBase));
			harmony.PatchAll(typeof(RoundManagerPatch));
			mls.LogInfo((object)"Snowmen have become fragile :(");
		}
	}
}
namespace Breakables.Patches
{
	[HarmonyPatch(typeof(RoundManager))]
	internal class RoundManagerPatch
	{
		[HarmonyPatch("SpawnOutsideHazards")]
		[HarmonyPostfix]
		private static void AddTriggers()
		{
			GameObject[] array = GameObject.FindGameObjectsWithTag("Snowman");
			for (int i = 0; i < array.Length; i++)
			{
				if (((Object)array[i]).name.Contains("Snowman"))
				{
					BreakableSnowmenModBase.mls.LogInfo((object)(((Object)array[i]).name + " is now breakable"));
					if (((Object)array[i]).name.Equals("Snowman(Clone)"))
					{
						Object.Instantiate<GameObject>(BreakableSnowmenModBase.Instance.trigger, array[i].transform);
					}
					else
					{
						Object.Instantiate<GameObject>(BreakableSnowmenModBase.Instance.tallTrigger, array[i].transform);
					}
				}
			}
		}
	}
}