BaboMod.dll

Decompiled a day 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 Photon.Pun;
using REPOLib.Modules;
using UnityEngine;
using UnityEngine.Events;

[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: AssemblyCompany("AntAptive")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BaboMod")]
[assembly: AssemblyTitle("BaboMod")]
[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.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;
		}
	}
	[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 BaboMod
{
	[BepInPlugin("AntAptive.BaboMod", "BaboMod", "1.2.6")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class BaboMod : BaseUnityPlugin
	{
		internal static ConfigEntry<bool>? DeathOnBreakEnabled;

		internal static BaboMod Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
			Logger.LogInfo((object)("\n...:....::::-=====--===-::....:...\r\n....::::::-::.....::::---:::::....\r\n..::::::--:..............::::::...\r\n:::::---:....BABO MOD......::::::.\r\n::::--:....By AntAptive....:-:-:::\r\n::--.:.......................:--::\r\n:-=*#%*##*-............-*#**%#+=-:\r\n-#***%#***-:..........:**##%**+**-\r\n+:--=#*-:-:...........:--=*#=-=::+\r\n+::::=-::...............::==:.:.:+\r\n=======-:...............:--=====+=\r\n-................................-\r\n:...............::...............:\r\n:::............:++:.............::\r\n.----:......................:----.\r\n..=-.......:..........:.......-=:.\r\n..:---:....::.::::::.::....:---:..\r\n...:--==-:..............:-==---...\r\n" + $"             v{((BaseUnityPlugin)this).Info.Metadata.Version}"));
			DeathOnBreakEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Features", "DeathOnBreak", true, "If enabled, players holding the babo when it breaks will be killed.");
			SpawnBaboCommand.Register();
		}

		internal void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	[HarmonyPatch(typeof(PlayerController))]
	internal static class ExamplePlayerControllerPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("Start")]
		private static void Start_Prefix(PlayerController __instance)
		{
			BaboMod.Logger.LogDebug((object)$"{__instance} Start Prefix");
		}

		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void Start_Postfix(PlayerController __instance)
		{
			BaboMod.Logger.LogDebug((object)$"{__instance} Start Postfix");
		}
	}
	public static class SpawnBaboCommand
	{
		private const string ValuableName = "Babo";

		public static void Register()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			Debug.Log((object)"[Babo] Registering /babo command...");
			ChatCommand val = new ChatCommand("babo", "spawns the babo", (Action<bool, string[]>)Execute, (Func<bool, string, string[], List<string>>)null, (Func<bool>)null, false);
			Commands.RegisterCommand(val);
		}

		private static void Execute(bool isDebugConsole, string[] args)
		{
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: 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)
			Debug.Log((object)"[Babo] Running /babo command...");
			if (!SemiFunc.IsMasterClientOrSingleplayer())
			{
				Debug.Log((object)"[Babo] Player tried to run the spawn command but is not the host and therefore nuh uh.");
				DebugCommandHandler instance = DebugCommandHandler.instance;
				if (instance != null)
				{
					instance.CommandFailedEffect();
				}
				if (BaboMod.DeathOnBreakEnabled != null && BaboMod.DeathOnBreakEnabled.Value)
				{
					Debug.Log((object)"[Babo] bai bai :gladge::hi:");
					PlayerAvatar.instance.playerHealth.Hurt(9999, false, -1, false);
				}
				return;
			}
			PrefabRef val = null;
			foreach (PrefabRef allValuable in Valuables.AllValuables)
			{
				if (allValuable.PrefabName.Equals("Babo", StringComparison.OrdinalIgnoreCase))
				{
					val = allValuable;
					break;
				}
			}
			if (val == null)
			{
				Debug.LogError((object)"[Babo] Could not find valuable: Babo");
				DebugCommandHandler instance2 = DebugCommandHandler.instance;
				if (instance2 != null)
				{
					instance2.CommandFailedEffect();
				}
				string text = "[Babo] Available valuables: " + string.Join("\n", Valuables.AllValuables.Select((PrefabRef v) => v.PrefabName));
				Debug.Log((object)text);
			}
			else
			{
				Transform transform = ((Component)PlayerAvatar.instance).transform;
				Vector3 val2 = transform.position + transform.forward * 2f;
				Quaternion rotation = transform.rotation;
				Valuables.SpawnValuable(val, val2, rotation);
				DebugCommandHandler instance3 = DebugCommandHandler.instance;
				if (instance3 != null)
				{
					instance3.CommandSuccessEffect();
				}
			}
		}
	}
	public class ValuableBabo : MonoBehaviour
	{
		private ValuableObject? _obj;

		private PhysGrabObject? _physGrab;

		private PhotonView? _photonView;

		private bool _triggered = false;

		private float cooldown = 0.5f;

		private bool chatDebounce = false;

		[SerializeField]
		private AudioSource? squeaky;

		[SerializeField]
		private AudioSource? shuttyuppy;

		private bool squeakyHasPlayed = false;

		private void Awake()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			_obj = ((Component)this).GetComponent<ValuableObject>();
			_physGrab = ((Component)this).GetComponent<PhysGrabObject>();
			_photonView = ((Component)this).GetComponent<PhotonView>();
			ValuableObject? obj = _obj;
			PhysGrabObjectImpactDetector val = ((obj != null) ? ((Component)obj).GetComponent<PhysGrabObjectImpactDetector>() : null);
			if ((Object)(object)val != (Object)null)
			{
				val.onAllBreaks.AddListener(new UnityAction(OnAllBreaks));
			}
		}

		private void Update()
		{
			if (SemiFunc.IsMultiplayer())
			{
				SayBabo();
			}
			if ((Object)(object)squeaky == (Object)null || (Object)(object)_physGrab == (Object)null)
			{
				return;
			}
			bool flag = Object.op_Implicit((Object)(object)PhysGrabber.instance) && PhysGrabber.instance.grabbed && (Object)(object)PhysGrabber.instance.grabbedPhysGrabObject == (Object)(object)_physGrab;
			if (flag && !squeakyHasPlayed)
			{
				squeakyHasPlayed = true;
				PlayBaboSound(1);
				if (Random.Range(0, 50) == 0 && (Object)(object)shuttyuppy != (Object)null)
				{
					PlayBaboSound(2);
				}
			}
			else if (!flag)
			{
				squeakyHasPlayed = false;
			}
		}

		private void PlayBaboSound(int i)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.IsMultiplayer() && (Object)(object)_photonView != (Object)null)
			{
				_photonView.RPC("PlayBaboSoundRPC", (RpcTarget)0, new object[2]
				{
					i,
					((Component)this).transform.position
				});
			}
			else
			{
				PlayBaboSoundRPC(i, ((Component)this).transform.position);
			}
		}

		[PunRPC]
		private void PlayBaboSoundRPC(int i, Vector3 position)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (1 == 0)
			{
			}
			AudioSource val = (AudioSource)(i switch
			{
				1 => squeaky, 
				2 => shuttyuppy, 
				_ => squeaky, 
			});
			if (1 == 0)
			{
			}
			AudioSource val2 = val;
			if ((Object)(object)val2 != (Object)null)
			{
				AudioSource.PlayClipAtPoint(val2.clip, position);
			}
		}

		private void SayBabo()
		{
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			if (cooldown > 0f && (Object)(object)_physGrab != (Object)null && _physGrab.grabbed)
			{
				cooldown -= Time.deltaTime;
				chatDebounce = false;
			}
			else if (Object.op_Implicit((Object)(object)PhysGrabber.instance) && PhysGrabber.instance.grabbed && Object.op_Implicit((Object)(object)PhysGrabber.instance.grabbedPhysGrabObject) && (Object)(object)PhysGrabber.instance.grabbedPhysGrabObject == (Object)(object)_physGrab && !chatDebounce)
			{
				chatDebounce = true;
				string text = ((Random.Range(0, 100) == 0) ? "smash hard smash" : "babo");
				Color val = default(Color);
				((Color)(ref val))..ctor(1f, 0.3f, 0.6f, 1f);
				ChatManager.instance.PossessChatScheduleStart(10);
				ChatManager.instance.PossessChat((PossessChatID)0, text, 3f, val, 0f, false, 0, (UnityEvent)null);
				ChatManager.instance.PossessChatScheduleEnd();
				if (text == "smash hard smash")
				{
					cooldown = 1.25f;
				}
				else
				{
					cooldown = 0.5f;
				}
			}
		}

		private void OnDestroy()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			ValuableObject? obj = _obj;
			PhysGrabObjectImpactDetector val = ((obj != null) ? ((Component)obj).GetComponent<PhysGrabObjectImpactDetector>() : null);
			if ((Object)(object)val != (Object)null)
			{
				val.onAllBreaks.RemoveListener(new UnityAction(OnAllBreaks));
			}
		}

		private void OnAllBreaks()
		{
			if (_triggered)
			{
				return;
			}
			_triggered = true;
			if (!SemiFunc.IsMasterClientOrSingleplayer() || (BaboMod.DeathOnBreakEnabled != null && !BaboMod.DeathOnBreakEnabled.Value))
			{
				return;
			}
			List<PlayerAvatar> list = (from p in _physGrab?.playerGrabbing?.Select((PhysGrabber h) => h.playerAvatar)
				where (Object)(object)p != (Object)null
				select p).ToList();
			if (list == null || !list.Any())
			{
				return;
			}
			foreach (PlayerAvatar item in list)
			{
				item.playerHealth.Hurt(9999, false, -1, false);
			}
			Debug.Log((object)$"Babo has exploded and killed {list.Count} players. muahahaha");
		}
	}
}