Decompiled source of BananaMonkeys v1.0.0

BananaMonkey.dll

Decompiled a year ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;

[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: AssemblyCompany("BananaMonkey")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+798f5d55f6081cfbf59559aaaa2230fe23c4fc85")]
[assembly: AssemblyProduct("Banana Monkey")]
[assembly: AssemblyTitle("BananaMonkey")]
[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;
		}
	}
}
public class BananaThrower : MonoBehaviour
{
	private Character currentTarget;

	public AudioSource monkeySound;

	private float throwTimeout;

	private float speed = 5f;

	private float height = 0.01f;

	private float agroRange = 25f;

	private bool throwingItBack = false;

	private bool CanSeeTarget(Character currentTarget)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		RaycastHit val = HelperFunctions.LineCheck(((Component)this).gameObject.transform.position, currentTarget.Center + Random.insideUnitSphere * 0.5f, (LayerType)1, 0f, (QueryTriggerInteraction)1);
		return (Object)(object)((RaycastHit)(ref val)).transform == (Object)null;
	}

	private void Update()
	{
		throwTimeout -= Time.deltaTime;
		if ((Object)(object)currentTarget != (Object)null && CanSeeTarget(currentTarget))
		{
			LookAtTarget();
			ThrowItem();
		}
		IdleMovement();
		VerifyTarget();
	}

	private void VerifyTarget()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		Character closestOther = GetClosestOther();
		float num = Vector3.Distance(((Component)this).gameObject.transform.position, closestOther.Center);
		if (num < agroRange && ((Object)(object)currentTarget == (Object)null || ((Object)currentTarget).GetInstanceID() != ((Object)closestOther).GetInstanceID()))
		{
			currentTarget = closestOther;
			Console.WriteLine($"Setting Monkey Target {currentTarget}");
		}
		else if ((Object)(object)currentTarget != (Object)null && num > agroRange)
		{
			Console.WriteLine("Clearing Monkey target");
			currentTarget = null;
		}
	}

	private Character GetClosestOther()
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		List<Character> allCharacters = Character.AllCharacters;
		float num = float.MaxValue;
		Character result = null;
		foreach (Character item in allCharacters)
		{
			if (!item.isBot)
			{
				float num2 = Vector3.Distance(item.Center, ((Component)this).gameObject.transform.position);
				if (num2 < num)
				{
					num = num2;
					result = item;
				}
			}
		}
		return result;
	}

	private void ThrowItem()
	{
		if (throwTimeout <= 0f)
		{
			if ((Object)(object)monkeySound != (Object)null)
			{
				monkeySound.Play();
			}
			Random random = new Random();
			if (random.Next(0, 50) > 46)
			{
				ThrowCoconut();
			}
			else
			{
				ThrowNanner();
			}
			throwTimeout = random.Next(10, 20);
		}
	}

	private void ThrowNanner()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: 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_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: 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_019b: Unknown result type (might be due to invalid IL or missing references)
		Random random = new Random();
		Vector3 gravity = Physics.gravity;
		float magnitude = ((Vector3)(ref gravity)).magnitude;
		Vector3 position = ((Component)this).gameObject.transform.position;
		position.y += 3f;
		float num = (float)((random.Next(0, 10) <= 5) ? 1 : (-1)) * (float)random.NextDouble();
		float num2 = (float)((random.Next(0, 10) <= 5) ? 1 : (-1)) * (float)random.NextDouble();
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(currentTarget.Head.x + num, currentTarget.Center.y, currentTarget.Head.z + num2);
		float num3 = 20f;
		float num4 = 0.5f;
		Vector3 val2 = val - position;
		gravity = Physics.gravity;
		float sqrMagnitude = ((Vector3)(ref gravity)).sqrMagnitude;
		float num5 = num3 * num3 + Vector3.Dot(val2, Physics.gravity);
		float num6 = num5 * num5 - sqrMagnitude * ((Vector3)(ref val2)).sqrMagnitude;
		if (num6 < 0f)
		{
			Debug.Log((object)"Target is out of range at this speed.");
			return;
		}
		float num7 = Mathf.Sqrt(num6);
		float num8 = Mathf.Sqrt((num5 - num7) * 2f / sqrMagnitude);
		float num9 = Mathf.Sqrt((num5 + num7) * 2f / sqrMagnitude);
		float num10 = Mathf.Lerp(num8, num9, num4);
		Vector3 val3 = val2 / num10 - Physics.gravity * num10 / 2f;
		GameObject val4 = PhotonNetwork.Instantiate("0_Items/Berrynana Peel Yellow", position, Quaternion.identity, (byte)0, (object[])null);
		Rigidbody component = val4.GetComponent<Rigidbody>();
		component.AddForce(val3, (ForceMode)2);
	}

	private void ThrowCoconut()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		Vector3 position = ((Component)this).gameObject.transform.position;
		position.y += 3f;
		Vector3 val = currentTarget.Head - position;
		Vector3 val2 = val * 4f;
		GameObject val3 = PhotonNetwork.Instantiate("0_Items/Item_Coconut", position, Quaternion.identity, (byte)0, (object[])null);
		Rigidbody component = val3.GetComponent<Rigidbody>();
		component.useGravity = false;
		Console.WriteLine($"Throwing coconut with force {val2}");
		component.linearVelocity = val2;
	}

	private void LookAtTarget()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = currentTarget.Head - ((Component)this).transform.position;
		Quaternion val2 = Quaternion.LookRotation(val);
		((Component)this).transform.rotation = Quaternion.Slerp(((Component)this).transform.rotation, val2 * Quaternion.Euler(0f, -90f, 0f), 5f * Time.deltaTime);
	}

	private void ThrowItBack()
	{
		throwingItBack = true;
	}

	private void IdleMovement()
	{
		//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_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		if (!throwingItBack)
		{
			Vector3 position = ((Component)this).gameObject.transform.position;
			float num = position.y + Mathf.Sin(Time.time * speed) * height;
			((Component)this).gameObject.transform.position = new Vector3(position.x, num, position.z);
		}
	}
}
public class JungleVineSpawnBehavior : MonoBehaviour
{
	public int spawn_attemp_count = 0;
}
namespace BananaMonkey
{
	[BepInPlugin("BananaMonkey", "Banana Monkey", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		internal static Harmony _harmony;

		internal static AssetBundle monkey_assets;

		internal static GameObject monkey_go;

		private void Awake()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			LoadMonkeyAssetBundle();
			_harmony = new Harmony("BananaMonkey");
			Logger.LogInfo((object)"Running Monkey patcher");
			_harmony.PatchAll(typeof(MonkeyPatcher));
			Logger.LogInfo((object)"Plugin BananaMonkey is loaded!");
		}

		public void LoadMonkeyAssetBundle()
		{
			Logger.LogInfo((object)"Loading BananaMonkeyAssets AssetBundle");
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			string path = Path.Combine(directoryName, "monkey");
			AssetBundleCreateRequest val = AssetBundle.LoadFromMemoryAsync(File.ReadAllBytes(path));
			monkey_assets = val.assetBundle;
			monkey_go = monkey_assets.LoadAsset<GameObject>("Assets/Monkey.prefab");
			monkey_go.AddComponent<BananaThrower>();
			monkey_go.GetComponent<BananaThrower>().monkeySound = monkey_go.GetComponentInChildren<AudioSource>();
			Logger.LogInfo((object)$"{monkey_assets} AssetBundle Loaded");
		}
	}
	public static class MonkeyPatcher
	{
		private static void CreateMonkey(Vector3 position)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(Plugin.monkey_go, position, Quaternion.identity);
			Plugin.Logger.LogInfo((object)$"Monkey added at position {val.transform.position}");
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(AirportCheckInKiosk), "Start")]
		private static void SpawnMonkeyInAirport(AirportCheckInKiosk __instance)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			if (PhotonNetwork.IsMasterClient)
			{
				Vector3 position = ((Component)__instance).gameObject.transform.position;
				position.y += 5.8f;
				position.x -= 4.8f;
				position.z += 6.4f;
				CreateMonkey(position);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MapHandler), "GoToSegment")]
		private static async void SpawnMonkeysOnSegmentChange(Segment s)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (!PhotonNetwork.IsMasterClient || (int)s != 1)
			{
				return;
			}
			await Task.Delay(TimeSpan.FromSeconds(20.0));
			JungleVine[] vines = Object.FindObjectsByType<JungleVine>((FindObjectsSortMode)0);
			Plugin.Logger.LogInfo((object)$"Vines {vines} {vines.Length}");
			JungleVine[] array = vines;
			foreach (JungleVine vine in array)
			{
				Plugin.Logger.LogInfo((object)"Attempting to add Monkey");
				Random rnd = new Random();
				if (rnd.Next(0, 10) > 6)
				{
					Vector3 spawn = vine.Center();
					if (Object.op_Implicit((Object)(object)vine.colliderRoot))
					{
						spawn = ((Component)((Component)vine.colliderRoot).transform.GetChild(rnd.Next(15, 35))).transform.position;
					}
					spawn.y += 0.8f;
					CreateMonkey(spawn);
				}
			}
		}
	}
	public static class BuglePatcher
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(BugleSFX), "RPC_StartToot")]
		private static void StartTootPostFix(BugleSFX __instance)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			int num = 20000;
			Item val = (Item)((Component)__instance).gameObject.GetComponent(typeof(Item));
			Rigidbody component = ((Component)val).gameObject.GetComponent<Rigidbody>();
			Plugin.Logger.LogInfo((object)$"Bugle location: {val.Center()}");
			Vector3 forward = ((Component)component).transform.forward;
			Vector3 position = ((Component)__instance).gameObject.transform.position;
			position.z += 1f;
			GameObject val2 = PhotonNetwork.Instantiate("0_Items/Berrynana Peel Yellow", position, Quaternion.identity, (byte)0, (object[])null);
			Rigidbody component2 = val2.GetComponent<Rigidbody>();
			component2.AddRelativeForce(new Vector3(forward.x * (float)num, forward.y * (float)num, forward.z * (float)num));
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(BugleSFX), "Update")]
		private static void UpdatetingTootPostFix(BugleSFX __instance)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			Item val = (Item)((Component)__instance).gameObject.GetComponent(typeof(Item));
			if ((Object)(object)val != (Object)null && (Object)(object)val.holderCharacter != (Object)null && __instance.hold)
			{
				int num = 100;
				Rigidbody component = ((Component)val).gameObject.GetComponent<Rigidbody>();
				Vector3 forward = ((Component)component).transform.forward;
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(forward.x * (float)(-num), forward.y * (float)(-num), forward.z * (float)(-num));
				Vector3 val3 = default(Vector3);
				((Vector3)(ref val3))..ctor(forward.x * (float)(-num), forward.y * (float)(-num), forward.z * (float)(-num));
				val.holderCharacter.RPCA_AddForceToBodyPart((BodypartType)4, val2, val3);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "BananaMonkey";

		public const string PLUGIN_NAME = "Banana Monkey";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}