Decompiled source of NyanBot v1.0.0

Mods/NyanBot.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BoneLib;
using BoneLib.BoneMenu;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Marrow;
using LabFusion.Entities;
using LabFusion.Network;
using LabFusion.Network.Serialization;
using LabFusion.SDK.Modules;
using MelonLoader;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using NyanBotMod;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Mod), "NyanBot", "0.3.0", "PH", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: MelonOptionalDependencies(new string[] { "LabFusion" })]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[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 NyanBotMod
{
	public static class FusionBridge
	{
		public static void Register()
		{
			try
			{
				ModuleMessageManager.RegisterHandler<NyanStateMessage>();
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("NyanBot: message handler registration: " + ex.Message);
			}
		}

		public static bool HasServer()
		{
			return NetworkInfo.HasServer;
		}

		public static bool IsHost()
		{
			return NetworkInfo.IsHost;
		}

		public static void SendState(bool active, Vector3 position, bool reliable)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkInfo.IsHost)
			{
				MessageRelay.RelayModule<NyanStateMessage, NyanStateData>(new NyanStateData
				{
					Active = active,
					Position = position
				}, reliable ? CommonMessageRoutes.ReliableToOtherClients : CommonMessageRoutes.UnreliableToOtherClients);
			}
		}

		public static void AddRemoteHeads(List<Transform> list)
		{
			foreach (NetworkPlayer player in NetworkPlayer.Players)
			{
				if (player != null && player.PlayerID != null && !player.PlayerID.IsMe && player.HasRig)
				{
					Transform head = player.RigRefs.Head;
					if ((Object)(object)head != (Object)null)
					{
						list.Add(head);
					}
				}
			}
		}
	}
	public class NyanStateData : INetSerializable
	{
		public bool Active;

		public Vector3 Position;

		public int? GetSize()
		{
			return 13;
		}

		public void Serialize(INetSerializer serializer)
		{
			serializer.SerializeValue(ref Active);
			NetSerializerUnityExtensions.SerializeValue(serializer, ref Position);
		}
	}
	public class NyanStateMessage : ModuleMessageHandler
	{
		protected override void OnHandleMessage(ReceivedMessage received)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkInfo.IsHost && ((ReceivedMessage)(ref received)).Sender == 0)
			{
				NyanStateData nyanStateData = ((ReceivedMessage)(ref received)).ReadData<NyanStateData>();
				Mod.OnRemoteState(nyanStateData.Active, nyanStateData.Position);
			}
		}
	}
	public class Mod : MelonMod
	{
		public static Sprite NyanSprite;

		public static AudioClip NyanClip;

		public static readonly List<GameObject> Active = new List<GameObject>();

		public static GameObject Puppet;

		public static int Generation;

		public static bool AllowKill = true;

		private static bool _fusionReady;

		private static string Dir => Path.Combine(MelonEnvironment.UserDataDirectory, "NyanBot");

		public static bool InServer
		{
			get
			{
				if (_fusionReady)
				{
					return FusionBridge.HasServer();
				}
				return false;
			}
		}

		public static bool IsHostOrSolo
		{
			get
			{
				if (InServer)
				{
					return FusionBridge.IsHost();
				}
				return true;
			}
		}

		public override void OnInitializeMelon()
		{
			ClassInjector.RegisterTypeInIl2Cpp<NyanBot>();
			ClassInjector.RegisterTypeInIl2Cpp<NyanPuppet>();
			ClassInjector.RegisterTypeInIl2Cpp<NyanVoice>();
			Directory.CreateDirectory(Dir);
			MelonCoroutines.Start(LoadAssets());
			SetupMenu();
			MelonLogger.Msg("NyanBot 0.3.0 loaded (menu: Spawn / Despawn / Can kill me)");
		}

		public override void OnLateInitializeMelon()
		{
			try
			{
				if (AppDomain.CurrentDomain.GetAssemblies().Any((Assembly a) => a.GetName().Name == "LabFusion"))
				{
					FusionBridge.Register();
					_fusionReady = true;
					MelonLogger.Msg("NyanBot: Fusion detected, multiplayer sync enabled.");
				}
				else
				{
					MelonLogger.Msg("NyanBot: Fusion not found, single-player only.");
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("NyanBot: Fusion hookup failed: " + ex.Message);
			}
		}

		private void SetupMenu()
		{
			//IL_000a: 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_0048: 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)
			Page obj = Page.Root.CreatePage("NyanBot", Color.magenta, 0, true);
			obj.CreateFunction("Spawn Nyan Cat", Color.white, (Action)Spawn);
			obj.CreateFunction("Despawn Nyan Cat", Color.red, (Action)Despawn);
			obj.CreateBool("Nyan Cat can kill me", Color.white, true, (Action<bool>)delegate(bool v)
			{
				AllowKill = v;
			});
		}

		private IEnumerator LoadAssets()
		{
			string path = Path.Combine(Dir, "nyan.png");
			if (File.Exists(path))
			{
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(File.ReadAllBytes(path)));
				((Texture)val).filterMode = (FilterMode)0;
				((Object)val).hideFlags = (HideFlags)32;
				NyanSprite = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
				((Object)NyanSprite).hideFlags = (HideFlags)32;
			}
			string wav = Path.Combine(Dir, "nyan.wav");
			string text = Path.Combine(Dir, "nyan.mp3");
			if (File.Exists(wav))
			{
				try
				{
					NyanClip = LoadWav(wav);
				}
				catch (Exception ex)
				{
					MelonLogger.Error("NyanBot WAV load failed: " + ex);
				}
			}
			if ((Object)(object)NyanClip == (Object)null && File.Exists(text))
			{
				UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip(new Uri(text).AbsoluteUri, (AudioType)13);
				yield return req.SendWebRequest();
				NyanClip = DownloadHandlerAudioClip.GetContent(req);
			}
			if ((Object)(object)NyanClip != (Object)null)
			{
				((Object)NyanClip).hideFlags = (HideFlags)32;
				MelonLogger.Msg("NyanBot audio loaded: " + NyanClip.length + "s");
			}
			else
			{
				MelonLogger.Error("NyanBot: audio failed to load. Expected " + wav);
			}
			MelonLogger.Msg("NyanBot assets loaded. Use BoneMenu > NyanBot (F9 spawn / F10 despawn on desktop).");
		}

		private static AudioClip LoadWav(string path)
		{
			byte[] array = File.ReadAllBytes(path);
			int i = 12;
			int num = 2;
			int num2 = 44100;
			int num3 = 16;
			int num4 = -1;
			int num5 = 0;
			int num6;
			for (; i + 8 <= array.Length; i += 8 + num6 + (num6 & 1))
			{
				string text = Encoding.ASCII.GetString(array, i, 4);
				num6 = BitConverter.ToInt32(array, i + 4);
				if (text == "fmt ")
				{
					num = BitConverter.ToInt16(array, i + 10);
					num2 = BitConverter.ToInt32(array, i + 12);
					num3 = BitConverter.ToInt16(array, i + 22);
				}
				else if (text == "data")
				{
					num4 = i + 8;
					num5 = Math.Min(num6, array.Length - num4);
					break;
				}
			}
			if (num4 < 0 || num3 != 16)
			{
				throw new Exception("Unsupported WAV (need 16-bit PCM)");
			}
			int num7 = num5 / 2;
			float[] array2 = new float[num7];
			for (int j = 0; j < num7; j++)
			{
				array2[j] = (float)BitConverter.ToInt16(array, num4 + j * 2) / 32768f;
			}
			AudioClip obj = AudioClip.Create("NyanBotClip", num7 / num, num, num2, false);
			obj.SetData(new Il2CppStructArray<float>(array2), 0);
			return obj;
		}

		public override void OnUpdate()
		{
			if (Input.GetKeyDown((KeyCode)290))
			{
				Spawn();
			}
			if (Input.GetKeyDown((KeyCode)291))
			{
				Despawn();
			}
		}

		public static List<Transform> ChaseTargets()
		{
			List<Transform> list = new List<Transform>();
			if ((Object)(object)Player.Head != (Object)null)
			{
				list.Add(Player.Head);
			}
			if (InServer)
			{
				try
				{
					FusionBridge.AddRemoteHeads(list);
				}
				catch (Exception ex)
				{
					MelonLogger.Warning("NyanBot: could not read remote players: " + ex.Message);
				}
			}
			return list;
		}

		public static GameObject BuildObject(Vector3 pos)
		{
			//IL_0022: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			GameObject obj = GameObject.CreatePrimitive((PrimitiveType)5);
			Object.Destroy((Object)(object)obj.GetComponent<Collider>());
			((Object)obj).name = "NyanBot";
			obj.transform.position = pos;
			float num = (((Object)(object)NyanSprite != (Object)null) ? ((float)((Texture)NyanSprite.texture).height / (float)((Texture)NyanSprite.texture).width) : 0.41f);
			obj.transform.localScale = new Vector3(3f, 3f * num, 1f);
			MeshRenderer component = obj.GetComponent<MeshRenderer>();
			Material val = new Material(Shader.Find("Sprites/Default"));
			if ((Object)(object)NyanSprite != (Object)null)
			{
				val.mainTexture = (Texture)(object)NyanSprite.texture;
			}
			((Renderer)component).material = val;
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
			obj.AddComponent<NyanVoice>();
			return obj;
		}

		public static void Spawn()
		{
			//IL_0023: 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_0048: 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_0071: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			if (!IsHostOrSolo)
			{
				MelonLogger.Warning("NyanBot: only the lobby host can spawn the Nyan Cat.");
				return;
			}
			Transform head = Player.Head;
			if (!((Object)(object)head == (Object)null))
			{
				Vector3 val = -head.forward;
				val.y = 0f;
				((Vector3)(ref val)).Normalize();
				float num = 10f;
				RaycastHit val2 = default(RaycastHit);
				if (Physics.Raycast(head.position, val, ref val2, num))
				{
					num = Mathf.Max(((RaycastHit)(ref val2)).distance - 1f, 2f);
				}
				Vector3 val3 = head.position + val * num;
				float num2 = head.position.y - 1.6f;
				RaycastHit val4 = default(RaycastHit);
				if (Physics.Raycast(new Vector3(val3.x, head.position.y, val3.z), Vector3.down, ref val4, 6f))
				{
					num2 = ((RaycastHit)(ref val4)).point.y;
				}
				val3.y = num2 + 1.2f;
				GameObject val5 = BuildObject(val3);
				val5.AddComponent<NyanBot>();
				Active.Add(val5);
			}
		}

		public static void Despawn()
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			if (!IsHostOrSolo)
			{
				MelonLogger.Warning("NyanBot: only the lobby host can despawn the Nyan Cat.");
				return;
			}
			Generation++;
			foreach (GameObject item in Active)
			{
				if ((Object)(object)item != (Object)null)
				{
					Object.Destroy((Object)(object)item);
				}
			}
			Active.Clear();
			if (InServer)
			{
				FusionBridge.SendState(active: false, Vector3.zero, reliable: true);
			}
			MelonLogger.Msg("NyanBot despawned.");
		}

		public static void OnRemoteState(bool active, Vector3 pos)
		{
			//IL_003a: 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 (!active)
			{
				Generation++;
				if ((Object)(object)Puppet != (Object)null)
				{
					Object.Destroy((Object)(object)Puppet);
				}
				Puppet = null;
				return;
			}
			if ((Object)(object)Puppet == (Object)null)
			{
				Puppet = BuildObject(pos);
				Puppet.AddComponent<NyanPuppet>();
			}
			NyanPuppet component = Puppet.GetComponent<NyanPuppet>();
			if ((Object)(object)component != (Object)null)
			{
				component.SetTarget(pos);
			}
		}
	}
	public class NyanVoice : MonoBehaviour
	{
		private AudioSource _audio;

		public NyanVoice(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Start()
		{
			_audio = ((Component)this).gameObject.AddComponent<AudioSource>();
			_audio.loop = true;
			_audio.playOnAwake = false;
			_audio.spatialBlend = 1f;
			_audio.rolloffMode = (AudioRolloffMode)1;
			_audio.minDistance = 5f;
			_audio.maxDistance = 120f;
			_audio.volume = 1f;
			TryStart();
		}

		private void TryStart()
		{
			if (!((Object)(object)_audio == (Object)null) && !_audio.isPlaying && !((Object)(object)Mod.NyanClip == (Object)null))
			{
				_audio.clip = Mod.NyanClip;
				_audio.Play();
			}
		}

		private void Update()
		{
			TryStart();
		}
	}
	public static class NyanHit
	{
		public const float LaunchForce = 40f;

		public const float KillDelay = 0.4f;

		public const float TouchPadding = 0.5f;

		public static bool Touching(Renderer rend, Vector3 center, Transform head)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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_0036: 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_0046: 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)
			Bounds val = (Bounds)(((Object)(object)rend != (Object)null) ? rend.bounds : new Bounds(center, Vector3.one * 2f));
			((Bounds)(ref val)).Expand(1f);
			if (((Bounds)(ref val)).Contains(head.position))
			{
				return true;
			}
			if (Vector3.Distance(center, head.position) < 2f)
			{
				return true;
			}
			PhysicsRig physicsRig = Player.PhysicsRig;
			if ((Object)(object)physicsRig != (Object)null)
			{
				foreach (Rigidbody componentsInChild in ((Component)physicsRig).GetComponentsInChildren<Rigidbody>())
				{
					if (((Bounds)(ref val)).Contains(componentsInChild.position))
					{
						return true;
					}
				}
			}
			return false;
		}

		public static void Hit(Vector3 center, Transform head)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_0014: 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_0026: 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)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			if (!Mod.AllowKill)
			{
				return;
			}
			Vector3 val = head.position - center;
			Vector3 val2 = ((Vector3)(ref val)).normalized + Vector3.up * 0.7f;
			PhysicsRig physicsRig = Player.PhysicsRig;
			if ((Object)(object)physicsRig != (Object)null)
			{
				foreach (Rigidbody componentsInChild in ((Component)physicsRig).GetComponentsInChildren<Rigidbody>())
				{
					componentsInChild.AddForce(((Vector3)(ref val2)).normalized * 40f, (ForceMode)2);
				}
			}
			MelonCoroutines.Start(KillAfterDelay(Mod.Generation));
		}

		private static IEnumerator KillAfterDelay(int gen)
		{
			yield return (object)new WaitForSeconds(0.4f);
			if (gen == Mod.Generation && Mod.AllowKill)
			{
				KillPlayer();
			}
		}

		private static void KillPlayer()
		{
			RigManager rigManager = Player.RigManager;
			Health val = ((rigManager != null) ? rigManager.health : null);
			if ((Object)(object)val == (Object)null)
			{
				MelonLogger.Warning("NyanBot: no player health found");
				return;
			}
			object obj = val;
			try
			{
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				foreach (Assembly assembly in assemblies)
				{
					Type type = null;
					try
					{
						type = assembly.GetTypes().FirstOrDefault((Type x) => x.Name == "Player_Health");
					}
					catch
					{
					}
					if (!(type == null))
					{
						object obj3 = typeof(Il2CppObjectBase).GetMethod("TryCast")?.MakeGenericMethod(type).Invoke(val, null);
						if (obj3 != null)
						{
							obj = obj3;
						}
						break;
					}
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("NyanBot cast failed: " + ex.Message);
			}
			Type type2 = obj.GetType();
			string[] array = new string[2] { "TAKE_DAMAGE", "TakeDamage" };
			foreach (string text in array)
			{
				MethodInfo method = type2.GetMethod(text, new Type[1] { typeof(float) });
				if (method != null)
				{
					method.Invoke(obj, new object[1] { 9999f });
					MelonLogger.Msg("NyanBot killed via " + text);
					return;
				}
			}
			MethodInfo method2 = type2.GetMethod("Death", Type.EmptyTypes);
			if (method2 != null)
			{
				method2.Invoke(obj, null);
				MelonLogger.Msg("NyanBot killed via Death()");
				return;
			}
			FieldInfo field = type2.GetField("curr_Health");
			if (field != null)
			{
				field.SetValue(obj, 0f);
				MelonLogger.Msg("NyanBot killed via curr_Health field");
				return;
			}
			PropertyInfo property = type2.GetProperty("curr_Health");
			if (property != null && property.CanWrite)
			{
				property.SetValue(obj, 0f);
				MelonLogger.Msg("NyanBot killed via curr_Health property");
				return;
			}
			MelonLogger.Warning("NyanBot: no kill member found on " + type2.FullName + ". Methods: " + string.Join(", ", from x in (from x in type2.GetMethods()
					select x.Name).Distinct()
				orderby x
				select x));
		}
	}
	public class NyanBot : MonoBehaviour
	{
		public float Speed = 6f;

		public float Cooldown = 3f;

		public float JumpSpeed = 8f;

		public float Gravity = 20f;

		public float SendInterval = 0.05f;

		private MeshRenderer _rend;

		private float _cooldownUntil;

		private CharacterController _cc;

		private float _vy;

		private float _nextJump;

		private float _blockedTime;

		private float _sideSign = 1f;

		private float _nextSend;

		private bool _blocked;

		private float _nextIgnoreRefresh;

		public NyanBot(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Start()
		{
			//IL_0043: 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)
			_rend = ((Component)this).GetComponent<MeshRenderer>();
			_cc = ((Component)this).gameObject.AddComponent<CharacterController>();
			_cc.radius = 0.5f;
			_cc.height = 1.4f;
			_cc.center = Vector3.zero;
			_cc.stepOffset = 0.4f;
			_cc.slopeLimit = 60f;
			IgnorePlayerColliders();
			if (Mod.InServer)
			{
				FusionBridge.SendState(active: true, ((Component)this).transform.position, reliable: true);
			}
		}

		private void Update()
		{
			//IL_007b: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: 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_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Invalid comparison between Unknown and I4
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: 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_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			Transform head = Player.Head;
			if ((Object)(object)head == (Object)null || (Object)(object)_cc == (Object)null)
			{
				return;
			}
			bool flag = Time.time < _cooldownUntil;
			if (Time.time >= _nextIgnoreRefresh)
			{
				IgnorePlayerColliders();
				_nextIgnoreRefresh = Time.time + 1f;
			}
			Transform val = null;
			float num = float.MaxValue;
			foreach (Transform item in Mod.ChaseTargets())
			{
				if (!((Object)(object)item == (Object)null))
				{
					Vector3 val2 = item.position - ((Component)this).transform.position;
					float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						val = item;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				val = head;
			}
			Vector3 val3 = val.position - ((Component)this).transform.position;
			Vector3 val4 = default(Vector3);
			((Vector3)(ref val4))..ctor(val3.x, 0f, val3.z);
			Vector3 val5 = head.position - ((Component)this).transform.position;
			Vector3 val6 = default(Vector3);
			((Vector3)(ref val6))..ctor(val5.x, 0f, val5.z);
			if (((Vector3)(ref val6)).sqrMagnitude > 0.001f)
			{
				((Component)this).transform.rotation = Quaternion.LookRotation(-((Vector3)(ref val6)).normalized, Vector3.up);
			}
			Vector3 val7 = Vector3.zero;
			if (!flag && ((Vector3)(ref val4)).sqrMagnitude > 0.01f)
			{
				Vector3 val8 = ((Vector3)(ref val4)).normalized;
				if (_blockedTime > 0.6f)
				{
					val8 = Quaternion.AngleAxis(_sideSign * 70f, Vector3.up) * val8;
				}
				val7 = val8 * Speed;
			}
			bool isGrounded = _cc.isGrounded;
			if (isGrounded && _vy < 0f)
			{
				_vy = -2f;
			}
			bool flag2 = ((Vector3)(ref val4)).magnitude < 3f;
			if (!flag && isGrounded && !flag2 && Time.time >= _nextJump && (_blocked || val3.y > 1.2f))
			{
				_vy = JumpSpeed;
				_nextJump = Time.time + 0.6f;
			}
			_vy -= Gravity * Time.deltaTime;
			val7.y = _vy;
			CollisionFlags val9 = _cc.Move(val7 * Time.deltaTime);
			_blocked = (val9 & 1) > 0;
			if ((val9 & 2) != 0 && _vy > 0f)
			{
				_vy = 0f;
			}
			if (_blocked)
			{
				_blockedTime += Time.deltaTime;
				if (_blockedTime > 1.6f)
				{
					_sideSign = 0f - _sideSign;
					_blockedTime = 0.7f;
				}
			}
			else
			{
				_blockedTime = 0f;
			}
			if (!flag && NyanHit.Touching((Renderer)(object)_rend, ((Component)this).transform.position, head))
			{
				NyanHit.Hit(((Component)this).transform.position, head);
				_cooldownUntil = Time.time + Cooldown;
			}
			if (Mod.InServer && Time.time >= _nextSend)
			{
				FusionBridge.SendState(active: true, ((Component)this).transform.position, reliable: false);
				_nextSend = Time.time + SendInterval;
			}
		}

		private void IgnorePlayerColliders()
		{
			PhysicsRig physicsRig = Player.PhysicsRig;
			if ((Object)(object)physicsRig == (Object)null || (Object)(object)_cc == (Object)null)
			{
				return;
			}
			foreach (Collider componentsInChild in ((Component)physicsRig).GetComponentsInChildren<Collider>())
			{
				if ((Object)(object)componentsInChild != (Object)null)
				{
					Physics.IgnoreCollision((Collider)(object)_cc, componentsInChild, true);
				}
			}
		}
	}
	public class NyanPuppet : MonoBehaviour
	{
		public float Cooldown = 3f;

		public float TimeoutSeconds = 3f;

		private MeshRenderer _rend;

		private Vector3 _target;

		private float _lastReceive;

		private float _cooldownUntil;

		private bool _hasTarget;

		public NyanPuppet(IntPtr ptr)
			: base(ptr)
		{
		}

		public void SetTarget(Vector3 pos)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: 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)
			_target = pos;
			_lastReceive = Time.time;
			if (!_hasTarget)
			{
				((Component)this).transform.position = pos;
				_hasTarget = true;
			}
		}

		private void Start()
		{
			//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)
			_rend = ((Component)this).GetComponent<MeshRenderer>();
			if (!_hasTarget)
			{
				_target = ((Component)this).transform.position;
				_hasTarget = true;
			}
			_lastReceive = Time.time;
		}

		private void Update()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_0086: 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)
			//IL_00b2: 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)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time - _lastReceive > TimeoutSeconds)
			{
				Mod.Puppet = null;
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			((Component)this).transform.position = Vector3.Lerp(((Component)this).transform.position, _target, 1f - Mathf.Exp(-15f * Time.deltaTime));
			Transform head = Player.Head;
			if (!((Object)(object)head == (Object)null))
			{
				Vector3 val = head.position - ((Component)this).transform.position;
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(val.x, 0f, val.z);
				if (((Vector3)(ref val2)).sqrMagnitude > 0.001f)
				{
					((Component)this).transform.rotation = Quaternion.LookRotation(-((Vector3)(ref val2)).normalized, Vector3.up);
				}
				if (Time.time >= _cooldownUntil && NyanHit.Touching((Renderer)(object)_rend, ((Component)this).transform.position, head))
				{
					NyanHit.Hit(((Component)this).transform.position, head);
					_cooldownUntil = Time.time + Cooldown;
				}
			}
		}
	}
}