using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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 GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("LCSpawnOnPlayerFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Ever got an Eyeless Dog or Forest Giant spawn directly on top of you? Yeah... This mod fixes that.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LCSpawnOnPlayerFix")]
[assembly: AssemblyTitle("LCSpawnOnPlayerFix")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[BepInPlugin("com.woah25.scaredbaboon", "Scared Baboon", "2.0.0")]
public class BaboonHawkFearMod : BaseUnityPlugin
{
[HarmonyPatch(typeof(BaboonBirdAI))]
public class BaboonBirdAI_Patches
{
[HarmonyPatch("DetectNoise")]
[HarmonyPrefix]
private static bool DetectNoisePrefix(BaboonBirdAI __instance, Vector3 noisePosition, float noiseLoudness, int noiseID)
{
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
if (!((NetworkBehaviour)__instance).IsOwner)
{
return true;
}
if (((EnemyAI)__instance).isEnemyDead || ((EnemyAI)__instance).stunNormalizedTimer > 0f || ((EnemyAI)__instance).inSpecialAnimation)
{
return true;
}
bool flag = false;
if (noiseID == 546)
{
flag = true;
}
else
{
PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
foreach (PlayerControllerB val in allPlayerScripts)
{
if ((Object)(object)val != (Object)null && val.isPlayerControlled && !val.isPlayerDead && Vector3.Distance(((Component)val).transform.position, noisePosition) < 2.5f)
{
flag = true;
break;
}
}
}
if (!flag)
{
return true;
}
float num = Vector3.Distance(((Component)__instance).transform.position, noisePosition);
if (num < 1f)
{
num = 1f;
}
if (noiseLoudness / num > screamLoudnessThreshold.Value)
{
Instance.StartEnemyFleeCoroutine(__instance, noisePosition);
return false;
}
return true;
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void UpdatePostfix(BaboonBirdAI __instance)
{
if (!((Object)(object)GameNetworkManager.Instance == (Object)null) && !((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null) && ((NetworkBehaviour)__instance).IsClient && ((NetworkBehaviour)__instance).OwnerClientId != GameNetworkManager.Instance.localPlayerController.actualClientId)
{
((EnemyAI)__instance).ChangeOwnershipOfEnemy(GameNetworkManager.Instance.localPlayerController.actualClientId);
}
}
}
[CompilerGenerated]
private sealed class <FleeFromNoiseCoroutine>d__6 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public BaboonBirdAI baboon;
public Vector3 noisePosition;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <FleeFromNoiseCoroutine>d__6(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: 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_0057: 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)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Expected O, but got Unknown
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
switch (<>1__state)
{
default:
return false;
case 0:
{
<>1__state = -1;
((EnemyAI)baboon).inSpecialAnimation = true;
((EnemyAI)baboon).creatureAnimator.SetBool("running", true);
Vector3 val = ((Component)baboon).transform.position - noisePosition;
Vector3 normalized = ((Vector3)(ref val)).normalized;
NavMeshHit val2 = default(NavMeshHit);
if (NavMesh.SamplePosition(((Component)baboon).transform.position + normalized * fleeDistance.Value, ref val2, 5f, -1))
{
((EnemyAI)baboon).SetDestinationToPosition(((NavMeshHit)(ref val2)).position, false);
}
<>2__current = (object)new WaitForSeconds(fleeDuration.Value);
<>1__state = 1;
return true;
}
case 1:
<>1__state = -1;
((EnemyAI)baboon).creatureAnimator.SetBool("running", false);
((EnemyAI)baboon).inSpecialAnimation = false;
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
private static ConfigEntry<float> screamLoudnessThreshold;
private static BaboonHawkFearMod Instance;
private static ConfigEntry<float> fleeDistance;
private static ConfigEntry<float> fleeDuration;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
fleeDistance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "FleeDistance", 5.5f, "How far the Baboon will try to run away when scared. (Default: 5.5)");
fleeDuration = ((BaseUnityPlugin)this).Config.Bind<float>("General", "FleeDuration", 2.5f, "How long (in seconds) the Baboon will remain in its 'fleeing' state. (Default: 2.5)");
screamLoudnessThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ScreamLoudnessThreshold", 0.8f, "Loudness threshold for a player's noise to scare a Baboon. The effect is determined by (Loudness / Distance). A higher value means you need to be louder or closer for it to trigger. Vanilla baboons get interested around 0.1-0.2 :). (Range: 0.0 to 1.0)");
Harmony.CreateAndPatchAll(typeof(BaboonBirdAI_Patches), (string)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Scared Baboon has been loaded and patched!");
}
public void StartEnemyFleeCoroutine(BaboonBirdAI ai, Vector3 noisePosition)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
((MonoBehaviour)this).StartCoroutine(FleeFromNoiseCoroutine(ai, noisePosition));
}
[IteratorStateMachine(typeof(<FleeFromNoiseCoroutine>d__6))]
private static IEnumerator FleeFromNoiseCoroutine(BaboonBirdAI baboon, Vector3 noisePosition)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <FleeFromNoiseCoroutine>d__6(0)
{
baboon = baboon,
noisePosition = noisePosition
};
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}
namespace ScaredBaboon
{
[BepInPlugin("com.woah25.scaredbaboon", "Scared Baboon", "2.0.0")]
internal class Plugin : BaseUnityPlugin
{
private const string PLUGIN_GUID = "com.woah25.scaredbaboon";
private const string PLUGIN_NAME = "Scared Baboon";
private const string PLUGIN_VERSION = "2.0.0";
private readonly Harmony _harmony;
internal static ManualLogSource Logger { get; private set; }
protected Plugin()
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
_harmony = new Harmony("com.woah25.scaredbaboon");
}
protected void Awake()
{
ManualLogSource logger = Logger;
if (logger != null)
{
logger.LogInfo((object)"Plugin Scared Baboon is loaded!");
}
ManualLogSource logger2 = Logger;
if (logger2 != null)
{
logger2.LogDebug((object)"Patching harmony...");
}
_harmony.PatchAll(Assembly.GetExecutingAssembly());
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "LCSpawnOnPlayerFix";
public const string PLUGIN_NAME = "LCSpawnOnPlayerFix";
public const string PLUGIN_VERSION = "1.0.0";
}
}