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+46c7251a35da0849ee6402af732997b6ac7f220e")]
[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 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;
}
[PunRPC]
private async Task PlayMonkeyAudio(AudioSource source, Vector3 position)
{
//IL_0020: 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)
source = Object.Instantiate<AudioSource>(source, position, Quaternion.identity);
source.Play();
await Task.Delay(5000);
Object.Destroy((Object)(object)source);
}
private void ThrowItem()
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
if (throwTimeout <= 0f)
{
if ((Object)(object)monkeySound != (Object)null)
{
PlayMonkeyAudio(monkeySound, ((Component)this).gameObject.transform.position);
}
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 IdleMovement()
{
//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_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: 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)
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);
}
}
namespace BananaMonkey
{
[BepInPlugin("BananaMonkey", "Banana Monkey", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Logger;
internal static Harmony _harmony;
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));
AssetBundle assetBundle = val.assetBundle;
GameObject val2 = assetBundle.LoadAsset<GameObject>("Assets/Monkey.prefab");
val2.AddComponent<BananaThrower>();
val2.AddComponent<PhotonView>();
AudioSource componentInChildren = val2.GetComponentInChildren<AudioSource>();
componentInChildren.playOnAwake = false;
val2.GetComponent<BananaThrower>().monkeySound = componentInChildren;
Logger.LogInfo((object)$"{assetBundle} AssetBundle Loaded");
IPunPrefabPool prefabPool = PhotonNetwork.PrefabPool;
((DefaultPool)((prefabPool is DefaultPool) ? prefabPool : null)).ResourceCache.Add("Monkey", val2);
Logger.LogInfo((object)"Monkey added to prefab pool");
}
}
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_0024: Unknown result type (might be due to invalid IL or missing references)
GameObject val = PhotonNetwork.Instantiate("Monkey", position, Quaternion.identity, (byte)0, (object[])null);
Plugin.Logger.LogInfo((object)$"Monkey added at position {val.transform.position}");
}
[HarmonyPostfix]
[HarmonyPatch(typeof(AirportCheckInKiosk), "Awake")]
private static async void SpawnMonkeyInAirport(AirportCheckInKiosk __instance)
{
await Task.Delay(TimeSpan.FromSeconds(20.0));
if (PhotonNetwork.IsMasterClient)
{
Vector3 kiosk_pos = ((Component)__instance).gameObject.transform.position;
kiosk_pos.y += 5.8f;
kiosk_pos.x -= 4.8f;
kiosk_pos.z += 6.4f;
CreateMonkey(kiosk_pos);
}
}
[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) > 7)
{
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 MyPluginInfo
{
public const string PLUGIN_GUID = "BananaMonkey";
public const string PLUGIN_NAME = "Banana Monkey";
public const string PLUGIN_VERSION = "1.0.0";
}
}