Decompiled source of GiantsEatMasked v1.2.0

GiantsEatMasked.dll

Decompiled 4 hours ago
using System;
using System.Collections;
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 BepInEx;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Animations.Rigging;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 GiantsEatMasked
{
	[DefaultExecutionOrder(10000)]
	public class Hunter : MonoBehaviour
	{
		public static HashSet<EnemyAI> held = new HashSet<EnemyAI>();

		public bool eating;

		private ForestGiantAI giant;

		private MaskedPlayerEnemy target;

		private MaskedPlayerEnemy prey;

		private float lostTime;

		private float startTime;

		private float frame;

		private float lastFrame;

		private bool vanished;

		private Transform[] bones;

		private PlayAudioAnimationEvent events;

		private Vector3[] oldPositions;

		private Quaternion[] oldRotations;

		private void Awake()
		{
			giant = ((Component)this).GetComponent<ForestGiantAI>();
		}

		public void SetTarget(MaskedPlayerEnemy masked)
		{
			target = masked;
			lostTime = 0f;
			if ((Object)(object)masked == (Object)null && !eating)
			{
				giant.lookingAtTarget = false;
			}
		}

		public bool Think()
		{
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			if (eating)
			{
				((EnemyAI)giant).SyncPositionToClients();
				return true;
			}
			if (!((NetworkBehaviour)giant).IsServer || ((EnemyAI)giant).isEnemyDead || StartOfRound.Instance.livingPlayers == 0)
			{
				return GiveUp();
			}
			PlayerControllerB[] allPlayersInLineOfSight = ((EnemyAI)giant).GetAllPlayersInLineOfSight(50f, 70, ((EnemyAI)giant).eye, 3f, StartOfRound.Instance.collidersRoomDefaultAndFoliage);
			bool flag = allPlayersInLineOfSight != null && allPlayersInLineOfSight.Length != 0;
			if (((EnemyAI)giant).currentBehaviourStateIndex == 1)
			{
				MaskedPlayerEnemy val = ((!flag && giant.lostPlayerInChase) ? FindMasked() : null);
				if ((Object)(object)val == (Object)null)
				{
					return GiveUp();
				}
				((EnemyAI)giant).SwitchToBehaviourState(0);
				Plugin.Send(giant, val);
			}
			if (((EnemyAI)giant).currentBehaviourStateIndex != 0 || flag)
			{
				return GiveUp();
			}
			if ((Object)(object)target != (Object)null && !CanHunt(target))
			{
				Plugin.Send(giant, null);
			}
			if ((Object)(object)target == (Object)null)
			{
				MaskedPlayerEnemy val2 = FindMasked();
				if ((Object)(object)val2 == (Object)null)
				{
					return false;
				}
				Plugin.Send(giant, val2);
			}
			if (giant.roamPlanet.inProgress)
			{
				((EnemyAI)giant).StopSearch(giant.roamPlanet, false);
			}
			if (giant.searchForPlayers.inProgress)
			{
				((EnemyAI)giant).StopSearch(giant.searchForPlayers, true);
			}
			giant.investigating = false;
			lostTime = (CanSee(target) ? 0f : (lostTime + ((EnemyAI)giant).AIIntervalTime));
			if (lostTime > 8f)
			{
				Plugin.Send(giant, null);
				return false;
			}
			if (TryGrab())
			{
				return true;
			}
			((EnemyAI)giant).SetDestinationToPosition(((Component)target).transform.position, false);
			if (((EnemyAI)giant).moveTowardsDestination)
			{
				((EnemyAI)giant).agent.SetDestination(((EnemyAI)giant).destination);
			}
			((EnemyAI)giant).SyncPositionToClients();
			return true;
		}

		private bool GiveUp()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)target != (Object)null && ((NetworkBehaviour)giant).IsServer)
			{
				Plugin.Send(giant, null);
			}
			return false;
		}

		private bool CanHunt(MaskedPlayerEnemy masked)
		{
			if (!((EnemyAI)masked).isEnemyDead && ((NetworkBehaviour)masked).NetworkObject.IsSpawned && ((EnemyAI)masked).isOutside == ((EnemyAI)giant).isOutside && !((EnemyAI)masked).isInsidePlayerShip && !((EnemyAI)masked).inSpecialAnimation)
			{
				return !held.Contains((EnemyAI)(object)masked);
			}
			return false;
		}

		private bool CanSee(MaskedPlayerEnemy masked)
		{
			//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_001b: 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)
			return ((EnemyAI)giant).CheckLineOfSightForPosition(((Component)masked).transform.position + Vector3.up * 1.6f, 50f, 50, 3f, (Transform)null);
		}

		private MaskedPlayerEnemy FindMasked()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			MaskedPlayerEnemy result = null;
			float num = 50f;
			foreach (EnemyAI spawnedEnemy in RoundManager.Instance.SpawnedEnemies)
			{
				MaskedPlayerEnemy val = (MaskedPlayerEnemy)(object)((spawnedEnemy is MaskedPlayerEnemy) ? spawnedEnemy : null);
				if (val != null && CanHunt(val))
				{
					float num2 = Vector3.Distance(((EnemyAI)giant).eye.position, ((Component)val).transform.position);
					if (num2 < num && CanSee(val))
					{
						result = val;
						num = num2;
					}
				}
			}
			return result;
		}

		private bool TryGrab()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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_0021: 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_0032: 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)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)giant).transform.position;
			Vector3 position2 = ((Component)target).transform.position;
			Vector3 position3 = giant.centerPosition.position;
			int collidersAndRoomMaskAndDefault = StartOfRound.Instance.collidersAndRoomMaskAndDefault;
			if (((EnemyAI)giant).stunNormalizedTimer >= 0f)
			{
				return false;
			}
			if (Vector2.Distance(new Vector2(position.x, position.z), new Vector2(position2.x, position2.z)) > 4.5f)
			{
				return false;
			}
			if (Mathf.Abs(position2.y - position.y) > 4f)
			{
				return false;
			}
			if (Physics.Linecast(position3, position2 + Vector3.up * 1.5f, collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
			{
				return false;
			}
			int rotation = (int)((Component)giant).transform.eulerAngles.y;
			if (Physics.Raycast(position3, giant.centerPosition.forward, 6f, collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
			{
				rotation = (int)RoundManager.Instance.YRotationThatFacesTheFarthestFromPosition(position, 20f, 5);
			}
			Plugin.Send(giant, target, eat: true, position, rotation);
			return true;
		}

		public void Chase(float reachWeight)
		{
			//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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: 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_0160: 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_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			if (eating)
			{
				if (((NetworkBehaviour)giant).IsOwner)
				{
					((EnemyAI)giant).agent.speed = 0f;
				}
				giant.lookingAtTarget = false;
			}
			else if (!((Object)(object)target == (Object)null) && !((EnemyAI)giant).isEnemyDead && ((EnemyAI)giant).currentBehaviourStateIndex == 0)
			{
				Vector3 position = ((Component)target).transform.position;
				giant.lookTarget.position = position;
				giant.lookingAtTarget = true;
				if (((NetworkBehaviour)giant).IsOwner)
				{
					giant.stopAndLookTimer = 0f;
					((EnemyAI)giant).agent.speed = ((((EnemyAI)giant).stunNormalizedTimer > 0f) ? 0f : 7f);
				}
				bool num = Vector3.Distance(((Component)giant).transform.position, position) < 8f;
				bool flag = Physics.Linecast(((EnemyAI)giant).eye.position, position, StartOfRound.Instance.collidersAndRoomMaskAndDefault);
				if (num && !flag && ((EnemyAI)giant).stunNormalizedTimer <= 0f)
				{
					((RigConstraint<TwoBoneIKConstraintJob, TwoBoneIKConstraintData, TwoBoneIKConstraintJobBinder<TwoBoneIKConstraintData>>)(object)giant.reachForPlayerRig).weight = Mathf.Lerp(reachWeight, 0.9f, Time.deltaTime * 6f);
					giant.reachForPlayerTarget.position = position + Vector3.up * 0.5f + Random.insideUnitSphere * 0.2f;
				}
			}
		}

		public void Eat(MaskedPlayerEnemy masked, Vector3 position, int rotation)
		{
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			if (!eating)
			{
				eating = true;
				target = null;
				prey = masked;
				held.Add((EnemyAI)(object)masked);
				startTime = Time.time;
				lastFrame = -1f;
				vanished = false;
				giant.inEatingPlayerAnimation = true;
				giant.lookingAtTarget = false;
				bones = ((Component)this).GetComponentsInChildren<Transform>();
				oldPositions = (Vector3[])(object)new Vector3[bones.Length];
				oldRotations = (Quaternion[])(object)new Quaternion[bones.Length];
				events = ((Component)giant.animationContainer).GetComponentInChildren<PlayAudioAnimationEvent>();
				((EnemyAI)masked).inSpecialAnimation = true;
				((EnemyAI)masked).movingTowardsTargetPlayer = false;
				((EnemyAI)masked).SetClientCalculatingAI(false);
				if (((NetworkBehaviour)masked).IsOwner && ((EnemyAI)masked).currentSearch != null && ((EnemyAI)masked).currentSearch.inProgress)
				{
					((EnemyAI)masked).StopSearch(((EnemyAI)masked).currentSearch, true);
				}
				((Behaviour)((EnemyAI)masked).agent).enabled = false;
				((MonoBehaviour)this).StartCoroutine(TurnTo(position, rotation));
			}
		}

		private IEnumerator TurnTo(Vector3 position, int rotation)
		{
			//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)
			((EnemyAI)giant).inSpecialAnimation = true;
			Vector3 startPos = ((Component)this).transform.position;
			Quaternion startRot = ((Component)this).transform.rotation;
			Quaternion endRot = Quaternion.Euler(((Component)this).transform.eulerAngles.x, (float)rotation, ((Component)this).transform.eulerAngles.z);
			for (int i = 0; i < 10; i++)
			{
				((Component)this).transform.position = Vector3.Lerp(startPos, position, (float)i / 10f);
				((Component)this).transform.rotation = Quaternion.Lerp(startRot, endRot, (float)i / 10f);
				yield return (object)new WaitForSeconds(0.01f);
			}
			((Component)this).transform.position = position;
			((Component)this).transform.rotation = endRot;
			((EnemyAI)giant).serverRotation = ((Component)this).transform.eulerAngles;
			yield return (object)new WaitForSeconds(0.2f);
			((EnemyAI)giant).inSpecialAnimation = false;
		}

		private void LateUpdate()
		{
			//IL_00b3: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: 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_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			if (!eating)
			{
				return;
			}
			if (((EnemyAI)giant).isEnemyDead || ((EnemyAI)giant).currentBehaviourStateIndex == 2 || ((EnemyAI)giant).stunNormalizedTimer > 0f)
			{
				StopEating(dropMasked: true);
				return;
			}
			AnimationClip giantEat = Plugin.GiantEat;
			float num = Time.time - startTime;
			frame = num * giantEat.frameRate;
			float num2 = Mathf.Clamp01(num / 0.25f);
			float num3 = 1f - Mathf.Clamp01((num - giantEat.length) / 0.4f);
			float num4 = Mathf.Min(num2, num3);
			for (int i = 0; i < bones.Length; i++)
			{
				if (!((Object)(object)bones[i] == (Object)null))
				{
					oldPositions[i] = bones[i].localPosition;
					oldRotations[i] = bones[i].localRotation;
				}
			}
			giantEat.SampleAnimation(((Component)this).gameObject, Mathf.Min(num, giantEat.length));
			for (int j = 0; j < bones.Length; j++)
			{
				if (!((Object)(object)bones[j] == (Object)null))
				{
					bones[j].localPosition = Vector3.Lerp(oldPositions[j], bones[j].localPosition, num4);
					bones[j].localRotation = Quaternion.Slerp(oldRotations[j], bones[j].localRotation, num4);
				}
			}
			if (!vanished && (Object)(object)prey != (Object)null)
			{
				((Component)prey).transform.position = giant.holdPlayerPoint.position;
				((Component)prey).transform.rotation = giant.holdPlayerPoint.rotation;
				Plugin.MaskedHeld.SampleAnimation(((Component)prey).gameObject, Mathf.Min(num, Plugin.MaskedHeld.length));
			}
			if ((Object)(object)events != (Object)null)
			{
				if (Reached(46))
				{
					events.PlayAudio1();
				}
				if (Reached(420))
				{
					events.PlayAudio2();
				}
				if (Reached(430))
				{
					events.PlayParticle();
				}
			}
			if (Reached(450))
			{
				Vanish();
			}
			lastFrame = frame;
			if (num3 <= 0f)
			{
				StopEating(dropMasked: false);
			}
		}

		private bool Reached(int at)
		{
			if (lastFrame < (float)at)
			{
				return frame >= (float)at;
			}
			return false;
		}

		private void Vanish()
		{
			vanished = true;
			((Behaviour)giant.bloodOnFaceDecal).enabled = true;
			if (!((Object)(object)prey == (Object)null))
			{
				((EnemyAI)prey).EnableEnemyMesh(false, true, false);
				Renderer[] componentsInChildren = ((Component)prey).GetComponentsInChildren<Renderer>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					componentsInChildren[i].enabled = false;
				}
				Light[] componentsInChildren2 = ((Component)prey).GetComponentsInChildren<Light>(true);
				for (int i = 0; i < componentsInChildren2.Length; i++)
				{
					((Behaviour)componentsInChildren2[i]).enabled = false;
				}
				((EnemyAI)prey).creatureVoice.Stop();
				if (((NetworkBehaviour)giant).IsServer && ((NetworkBehaviour)prey).NetworkObject.IsSpawned)
				{
					RoundManager.Instance.DespawnEnemyOnServer(((NetworkBehaviour)prey).NetworkObject);
				}
			}
		}

		private void StopEating(bool dropMasked)
		{
			((MonoBehaviour)this).StopAllCoroutines();
			if ((Object)(object)prey != (Object)null)
			{
				held.Remove((EnemyAI)(object)prey);
				if (dropMasked && !vanished)
				{
					Drop(prey);
				}
			}
			prey = null;
			eating = false;
			giant.inEatingPlayerAnimation = false;
			((EnemyAI)giant).inSpecialAnimation = false;
		}

		private static void Drop(MaskedPlayerEnemy masked)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			Vector3 navMeshPosition = RoundManager.Instance.GetNavMeshPosition(((Component)masked).transform.position, RoundManager.Instance.navHit, 12f, -1);
			((Component)masked).transform.position = navMeshPosition;
			((Component)masked).transform.rotation = Quaternion.Euler(0f, ((Component)masked).transform.eulerAngles.y, 0f);
			((EnemyAI)masked).serverPosition = navMeshPosition;
			((EnemyAI)masked).inSpecialAnimation = false;
			if (((NetworkBehaviour)masked).IsOwner && !((EnemyAI)masked).isEnemyDead)
			{
				((Behaviour)((EnemyAI)masked).agent).enabled = true;
				((EnemyAI)masked).agent.Warp(navMeshPosition);
			}
		}

		private void OnDestroy()
		{
			if (eating)
			{
				StopEating(dropMasked: true);
			}
		}
	}
	[BepInPlugin("CoddingCat.GiantsEatMasked", "GiantsEatMasked", "1.1.0")]
	[HarmonyPatch]
	public class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__Receive;
		}

		public static AnimationClip GiantEat;

		public static AnimationClip MaskedHeld;

		private void Awake()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			AssetBundle obj = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "giantseatmasked"));
			GiantEat = obj.LoadAsset<AnimationClip>("GiantEat");
			MaskedHeld = obj.LoadAsset<AnimationClip>("MaskedHeld");
			new Harmony("CoddingCat.GiantsEatMasked").PatchAll();
		}

		public unsafe static void Send(ForestGiantAI giant, MaskedPlayerEnemy masked, bool eat = false, Vector3 position = default(Vector3), int rotation = 0)
		{
			//IL_001e: 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)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			ulong networkObjectId = ((NetworkBehaviour)giant).NetworkObjectId;
			ulong maskedId = (((Object)(object)masked != (Object)null) ? ((NetworkBehaviour)masked).NetworkObjectId : ulong.MaxValue);
			Run(networkObjectId, maskedId, eat, position, rotation);
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(64, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref networkObjectId, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref maskedId, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref eat, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe(ref position);
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref rotation, default(ForPrimitives));
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("GiantsEatMasked", val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private static void Receive(ulong sender, FastBufferReader message)
		{
			//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)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_0055: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkManager.Singleton.IsServer)
			{
				ulong giantId = default(ulong);
				((FastBufferReader)(ref message)).ReadValueSafe<ulong>(ref giantId, default(ForPrimitives));
				ulong maskedId = default(ulong);
				((FastBufferReader)(ref message)).ReadValueSafe<ulong>(ref maskedId, default(ForPrimitives));
				bool eat = default(bool);
				((FastBufferReader)(ref message)).ReadValueSafe<bool>(ref eat, default(ForPrimitives));
				Vector3 position = default(Vector3);
				((FastBufferReader)(ref message)).ReadValueSafe(ref position);
				int rotation = default(int);
				((FastBufferReader)(ref message)).ReadValueSafe<int>(ref rotation, default(ForPrimitives));
				Run(giantId, maskedId, eat, position, rotation);
			}
		}

		private static void Run(ulong giantId, ulong maskedId, bool eat, Vector3 position, int rotation)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<ulong, NetworkObject> spawnedObjects = NetworkManager.Singleton.SpawnManager.SpawnedObjects;
			if (spawnedObjects.TryGetValue(giantId, out var value))
			{
				Hunter component = ((Component)value).GetComponent<Hunter>();
				NetworkObject value2;
				MaskedPlayerEnemy val = (spawnedObjects.TryGetValue(maskedId, out value2) ? ((Component)value2).GetComponent<MaskedPlayerEnemy>() : null);
				if (!eat)
				{
					component.SetTarget(val);
				}
				else if ((Object)(object)val != (Object)null)
				{
					component.Eat(val, position, rotation);
				}
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "Start")]
		[HarmonyPostfix]
		private static void RoundStart()
		{
			//IL_0029: 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_0034: Expected O, but got Unknown
			Hunter.held.Clear();
			CustomMessagingManager customMessagingManager = NetworkManager.Singleton.CustomMessagingManager;
			object obj = <>O.<0>__Receive;
			if (obj == null)
			{
				HandleNamedMessageDelegate val = Receive;
				<>O.<0>__Receive = val;
				obj = (object)val;
			}
			customMessagingManager.RegisterNamedMessageHandler("GiantsEatMasked", (HandleNamedMessageDelegate)obj);
		}

		[HarmonyPatch(typeof(ForestGiantAI), "Start")]
		[HarmonyPostfix]
		private static void GiantStart(ForestGiantAI __instance)
		{
			((Component)__instance).gameObject.AddComponent<Hunter>();
		}

		[HarmonyPatch(typeof(ForestGiantAI), "DoAIInterval")]
		[HarmonyPrefix]
		private static bool GiantAI(ForestGiantAI __instance)
		{
			return !((Component)__instance).GetComponent<Hunter>().Think();
		}

		[HarmonyPatch(typeof(ForestGiantAI), "LookForPlayers")]
		[HarmonyPrefix]
		private static bool GiantLook(ForestGiantAI __instance)
		{
			return !((Component)__instance).GetComponent<Hunter>().eating;
		}

		[HarmonyPatch(typeof(ForestGiantAI), "Update")]
		[HarmonyPrefix]
		private static void GiantUpdateBefore(ForestGiantAI __instance, out float __state)
		{
			__state = ((RigConstraint<TwoBoneIKConstraintJob, TwoBoneIKConstraintData, TwoBoneIKConstraintJobBinder<TwoBoneIKConstraintData>>)(object)__instance.reachForPlayerRig).weight;
		}

		[HarmonyPatch(typeof(ForestGiantAI), "Update")]
		[HarmonyPostfix]
		private static void GiantUpdate(ForestGiantAI __instance, float __state)
		{
			((Component)__instance).GetComponent<Hunter>().Chase(__state);
		}

		[HarmonyPatch(typeof(MaskedPlayerEnemy), "DoAIInterval")]
		[HarmonyPrefix]
		private static bool MaskedAI(MaskedPlayerEnemy __instance)
		{
			return !Hunter.held.Contains((EnemyAI)(object)__instance);
		}

		[HarmonyPatch(typeof(MaskedPlayerEnemy), "OnCollideWithPlayer")]
		[HarmonyPrefix]
		private static bool MaskedTouch(MaskedPlayerEnemy __instance)
		{
			return !Hunter.held.Contains((EnemyAI)(object)__instance);
		}

		[HarmonyPatch(typeof(MaskedPlayerEnemy), "FinishKillAnimation")]
		[HarmonyPrefix]
		private static bool MaskedKill(MaskedPlayerEnemy __instance)
		{
			return !Hunter.held.Contains((EnemyAI)(object)__instance);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}