Decompiled source of MidorinoEnemies v0.1.0

MidorinoEnemies.dll

Decompiled 5 hours ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using MidorinoEnemies.Config;
using MidorinoEnemies.Enemies.Beyblade;
using MidorinoEnemies.Enemies.Beyblade.Logic;
using MidorinoEnemies.Enemies.Shifter;
using MidorinoEnemies.Enemies.Shifter.Logic;
using MidorinoEnemies.Game;
using MidorinoEnemies.Template;
using MidorinoEnemies.Template.Logic;
using Photon.Pun;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("Midorino")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+31102d77029fdf5627616fc64d66868c333eaa11")]
[assembly: AssemblyProduct("MidorinoEnemies")]
[assembly: AssemblyTitle("MidorinoEnemies")]
[assembly: UnityAPICompatibilityVersion("6000.3.17f1", new string[] { "UnityEngine.CoreModule:2655F640D5664F2AABEFFC59106D80941AEAB81F", "UnityEngine.AudioModule:A523C7BE14FEB2DD0700C48A47F93388DA10A07F", "UnityEngine.ParticleSystemModule:072D428B56BB48211EEE7B341592090CF9266EE7", "UnityEngine.AIModule:E68931A9A4F6A58DB9D9A7C2A930E09167BE152A", "UnityEngine.PhysicsModule:EBB15F93568427B1A13575C59EAECBA706C1CAFC", "UnityEngine.AnimationModule:4730470ADFDC2902076AD1F817BEC3B16FB831BA" })]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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;
		}
	}
	[EditorBrowsable(EditorBrowsableState.Never)]
	internal static class IsExternalInit
	{
	}
}
namespace MidorinoEnemies
{
	[BepInPlugin("Midorino.MidorinoEnemies", "MidorinoEnemies", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class MidorinoEnemiesPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger { get; private set; }

		internal static BeybladeConfig BeybladeConfig { get; private set; }

		internal static BeybladeConfig RaigomaConfig { get; private set; }

		internal static RaigomaAbilityConfig RaigomaAbilities { get; private set; }

		internal static ShifterConfig ShifterConfig { get; private set; }

		internal static BeybladeConfig ConfigFor(BeybladeVariant variant)
		{
			if (variant != BeybladeVariant.Raigoma)
			{
				return BeybladeConfig;
			}
			return RaigomaConfig;
		}

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			ModLog.Init(Logger);
			BeybladeConfig = new BeybladeConfig(((BaseUnityPlugin)this).Config);
			RaigomaConfig = new BeybladeConfig(((BaseUnityPlugin)this).Config, "Raigoma", RaigomaDefaults.Values);
			RaigomaAbilities = new RaigomaAbilityConfig(((BaseUnityPlugin)this).Config, "Raigoma");
			ShifterConfig = new ShifterConfig(((BaseUnityPlugin)this).Config);
			ModLog.BindConfig(((BaseUnityPlugin)this).Config);
			HarmonyPatches.Apply();
			ModLog.Info("MidorinoEnemies 0.1.0 loaded.");
		}
	}
	internal static class ModLog
	{
		private const string VerboseDescription = "詳しいログ (敵の状態の切り替え・当たった武器の名前など) を BepInEx のログに出す。不具合を報告するときに true にする。通常は false。\nWrites detailed logs (enemy state changes, names of weapons that hit, etc.) to the BepInEx log. Turn on when reporting a bug. Normally false.";

		private const float DefaultThrottleSeconds = 30f;

		private static ManualLogSource? _log;

		private static ConfigEntry<bool>? _verbose;

		private static readonly HashSet<string> Shown = new HashSet<string>();

		private static readonly Dictionary<string, float> LastShown = new Dictionary<string, float>();

		public static bool Verbose
		{
			get
			{
				if (_verbose != null)
				{
					return _verbose.Value;
				}
				return false;
			}
		}

		public static void Init(ManualLogSource log)
		{
			_log = log;
		}

		public static void BindConfig(ConfigFile config)
		{
			_verbose = config.Bind<bool>("Debug", "VerboseLogging", false, "詳しいログ (敵の状態の切り替え・当たった武器の名前など) を BepInEx のログに出す。不具合を報告するときに true にする。通常は false。\nWrites detailed logs (enemy state changes, names of weapons that hit, etc.) to the BepInEx log. Turn on when reporting a bug. Normally false.");
		}

		public static void Info(string message)
		{
			ManualLogSource? log = _log;
			if (log != null)
			{
				log.LogInfo((object)message);
			}
		}

		public static void Warn(string message)
		{
			ManualLogSource? log = _log;
			if (log != null)
			{
				log.LogWarning((object)message);
			}
		}

		public static void Error(string message)
		{
			ManualLogSource? log = _log;
			if (log != null)
			{
				log.LogError((object)message);
			}
		}

		public static void Debug(Func<string> message)
		{
			if (Verbose)
			{
				ManualLogSource? log = _log;
				if (log != null)
				{
					log.LogInfo((object)message());
				}
			}
		}

		public static void Debug(string message)
		{
			if (Verbose)
			{
				ManualLogSource? log = _log;
				if (log != null)
				{
					log.LogInfo((object)message);
				}
			}
		}

		public static void WarnOnce(string key, string message)
		{
			if (Shown.Add(key))
			{
				Warn(message);
			}
		}

		public static void ErrorOnce(string key, string message)
		{
			if (Shown.Add(key))
			{
				Error(message);
			}
		}

		public static void WarnThrottled(string key, string message, float intervalSeconds = 30f)
		{
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			if (!LastShown.TryGetValue(key, out var value) || !(realtimeSinceStartup - value < intervalSeconds))
			{
				LastShown[key] = realtimeSinceStartup;
				Warn(message);
			}
		}
	}
	internal static class PluginInfo
	{
		public const string GUID = "Midorino.MidorinoEnemies";

		public const string NAME = "MidorinoEnemies";

		public const string VERSION = "0.1.0";
	}
}
namespace MidorinoEnemies.Template
{
	public abstract class EnemyTemplateBehaviour : MonoBehaviour
	{
		protected const float DefaultStuckSeconds = 20f;

		protected const float DefaultStuckDistance = 2.5f;

		private const int VanillaStuckDespawnCount = 10;

		private const float LocalizedNameCheckInterval = 1f;

		private string _localizedNameLocale = string.Empty;

		private float _localizedNameTimer;

		protected IEnemyParameters Parameters { get; private set; }

		protected IRepoGameBridge Game { get; private set; }

		protected Vec3 Position
		{
			get
			{
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				if (Game == null)
				{
					return ((Component)this).transform.position.ToVec3();
				}
				return Game.GetBodyPosition(this);
			}
		}

		protected StuckWatchdog StuckWatch { get; } = new StuckWatchdog(20f, 2.5f);

		protected virtual string LogTag => "Enemy";

		public void Initialize(IEnemyParameters parameters, IRepoGameBridge game)
		{
			Parameters = parameters;
			Game = game;
			OnInitialized();
		}

		protected void EnableVanillaStuckDespawn()
		{
			Game.ConfigureStuckDespawn(this, enabled: true, 10);
		}

		protected void UpdateStuckWatchdog(bool trying, bool interrupted, float dt)
		{
			if (Game != null && Game.IsHost() && StuckWatch.Tick(Position, trying, interrupted, dt))
			{
				ModLog.Debug(() => $"[{LogTag}] Stuck for {StuckWatch.Seconds:F0}s without moving {StuckWatch.Distance:F1}m -> despawn");
				Game.RequestStuckDespawn(this);
			}
		}

		protected void ResetStuckState()
		{
			StuckWatch.Reset();
			Game?.ResetStuckCounters(this);
		}

		protected void ApplyLocalizedName(string english, string japanese, bool force = false)
		{
			string localeCode = Game.GetLocaleCode();
			if (force || !(localeCode == _localizedNameLocale))
			{
				_localizedNameLocale = localeCode;
				bool flag = localeCode.StartsWith("ja", StringComparison.OrdinalIgnoreCase);
				Game.SetDisplayName(this, flag ? japanese : english);
			}
		}

		protected void TickLocalizedName(float dt, string english, string japanese)
		{
			_localizedNameTimer -= dt;
			if (_localizedNameTimer <= 0f)
			{
				_localizedNameTimer = 1f;
				ApplyLocalizedName(english, japanese);
			}
		}

		protected virtual void Update()
		{
			if (Parameters != null)
			{
				OnActiveUpdate();
			}
		}

		protected abstract void OnInitialized();

		protected abstract void OnActiveUpdate();
	}
	public static class Vec3Extensions
	{
		public static Vec3 ToVec3(this Vector3 v)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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)
			return new Vec3(v.x, v.y, v.z);
		}

		public static Vector3 ToUnity(this Vec3 v)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(v.X, v.Y, v.Z);
		}
	}
}
namespace MidorinoEnemies.Template.Logic
{
	public interface ITarget
	{
		Vec3 Position { get; }
	}
	public interface IKnockbackTarget
	{
		Vec3 Position { get; }
	}
	public interface IEnemyParameters
	{
		int MaxHealth { get; }

		float DetectionRadius { get; }

		float SpawnChance { get; }

		int ImpactLightDamage { get; }

		int ImpactMediumDamage { get; }

		int ImpactHeavyDamage { get; }
	}
	public interface IBeybladeParameters : IEnemyParameters
	{
		float KnockbackStrength { get; }

		IReadOnlyCollection<string> WeaponWhitelist { get; }

		bool ImpactHurtEnabled { get; }

		int ContactDamage { get; }

		int ChargeDamage { get; }

		float StunDurationMultiplier { get; }
	}
	public sealed class StuckWatchdog
	{
		private Vec3 _reference;

		private bool _hasReference;

		public float Seconds { get; }

		public float Distance { get; }

		public float StuckSeconds { get; private set; }

		public StuckWatchdog(float seconds, float distance)
		{
			Seconds = seconds;
			Distance = distance;
			Reset();
		}

		public void Reset()
		{
			StuckSeconds = 0f;
			_hasReference = false;
		}

		public bool Tick(Vec3 position, bool trying, bool interrupted, float dt)
		{
			if (!_hasReference || interrupted || (position - _reference).Magnitude > Distance)
			{
				_reference = position;
				_hasReference = true;
				StuckSeconds = 0f;
				return false;
			}
			if (!trying || dt <= 0f)
			{
				return false;
			}
			StuckSeconds += dt;
			if (StuckSeconds < Seconds)
			{
				return false;
			}
			Reset();
			return true;
		}
	}
	public readonly struct Vec3 : IEquatable<Vec3>
	{
		public readonly float X;

		public readonly float Y;

		public readonly float Z;

		public static Vec3 Zero => new Vec3(0f, 0f, 0f);

		public float SqrMagnitude => X * X + Y * Y + Z * Z;

		public float Magnitude => (float)Math.Sqrt(SqrMagnitude);

		public Vec3(float x, float y, float z)
		{
			X = x;
			Y = y;
			Z = z;
		}

		public static Vec3 operator +(Vec3 a, Vec3 b)
		{
			return new Vec3(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
		}

		public static Vec3 operator -(Vec3 a, Vec3 b)
		{
			return new Vec3(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
		}

		public static Vec3 operator *(Vec3 v, float s)
		{
			return new Vec3(v.X * s, v.Y * s, v.Z * s);
		}

		public static Vec3 operator *(float s, Vec3 v)
		{
			return v * s;
		}

		public Vec3 Normalized()
		{
			float magnitude = Magnitude;
			if (magnitude < 1E-06f)
			{
				return Zero;
			}
			return new Vec3(X / magnitude, Y / magnitude, Z / magnitude);
		}

		public Vec3 Horizontal()
		{
			return new Vec3(X, 0f, Z);
		}

		public bool Equals(Vec3 other)
		{
			if (X.Equals(other.X) && Y.Equals(other.Y))
			{
				return Z.Equals(other.Z);
			}
			return false;
		}

		public override bool Equals(object? obj)
		{
			if (obj is Vec3 other)
			{
				return Equals(other);
			}
			return false;
		}

		public override int GetHashCode()
		{
			int hashCode = X.GetHashCode();
			hashCode = (hashCode * 397) ^ Y.GetHashCode();
			return (hashCode * 397) ^ Z.GetHashCode();
		}

		public override string ToString()
		{
			return $"({X}, {Y}, {Z})";
		}
	}
}
namespace MidorinoEnemies.Game
{
	internal static class BorrowedAssets
	{
		internal const string GrenadeItemPath = "items/Item Grenade Explosive";

		internal const string ExplosionEffectPath = "Effects/Part Prefab Explosion";

		internal const string AnimalEnemyPath = "enemies/Enemy - Animal";

		private const float MissRetrySeconds = 5f;

		private static GameObject? _grenadePrefab;

		private static GameObject? _explosionEffectPrefab;

		private static GameObject? _animalPrefab;

		private static float _grenadeRetryAt;

		private static float _explosionRetryAt;

		private static float _animalRetryAt;

		internal static GameObject? GrenadePrefab()
		{
			return LoadPrefab(ref _grenadePrefab, ref _grenadeRetryAt, "items/Item Grenade Explosive", "grenade");
		}

		internal static GameObject? ExplosionEffectPrefab()
		{
			return LoadPrefab(ref _explosionEffectPrefab, ref _explosionRetryAt, "Effects/Part Prefab Explosion", "explosionEffect");
		}

		internal static GameObject? AnimalPrefab()
		{
			return LoadPrefab(ref _animalPrefab, ref _animalRetryAt, "enemies/Enemy - Animal", "animal");
		}

		private static GameObject? LoadPrefab(ref GameObject? cache, ref float retryAt, string path, string key)
		{
			if ((Object)(object)cache != (Object)null)
			{
				return cache;
			}
			if (Time.realtimeSinceStartup < retryAt)
			{
				return null;
			}
			retryAt = Time.realtimeSinceStartup + 5f;
			try
			{
				cache = Resources.Load<GameObject>(path);
			}
			catch (Exception ex)
			{
				ModLog.Warn("[Game] loading '" + path + "' failed: " + ex.Message);
			}
			if ((Object)(object)cache == (Object)null)
			{
				ModLog.WarnOnce("BorrowedAssets.NotFound:" + key, "[Game] borrowed prefab not found at Resources path '" + path + "'");
			}
			else
			{
				GameObject loaded = cache;
				ModLog.Debug(() => "[Game] borrowed prefab loaded: '" + path + "' (" + ((Object)loaded).name + ")");
			}
			return cache;
		}

		internal static AudioClip[]? GrenadeTickClips()
		{
			GameObject? obj = GrenadePrefab();
			ItemGrenade val = ((obj != null) ? obj.GetComponent<ItemGrenade>() : null);
			if ((Object)(object)val != (Object)null && val.soundTick != null && SoundUtil.HasClips(val.soundTick) && (Object)(object)val.soundTick.Sounds[0] != (Object)null)
			{
				return val.soundTick.Sounds;
			}
			return null;
		}

		internal static ExplosionPreset? GrenadeExplosionPreset()
		{
			GameObject? obj = GrenadePrefab();
			ParticleScriptExplosion val = ((obj != null) ? obj.GetComponent<ParticleScriptExplosion>() : null);
			if (!((Object)(object)val != (Object)null))
			{
				return null;
			}
			return val.explosionPreset;
		}

		internal static void PreloadForShifter()
		{
			GrenadePrefab();
			ExplosionEffectPrefab();
		}

		internal static void PreloadForBeigoma()
		{
			AnimalPrefab();
		}
	}
	internal static class DebrisTint
	{
		public const string DebrisNameMarker = "Bits";

		public static void Apply(ParticleSystem ps, Color tint)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//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_0012: 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_0022: 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_0037: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			MainModule main = ps.main;
			((MainModule)(ref main)).startColor = Retint(((MainModule)(ref main)).startColor, tint, greyOnly: false);
			TrailModule trails = ps.trails;
			if (((TrailModule)(ref trails)).enabled)
			{
				((TrailModule)(ref trails)).colorOverLifetime = Retint(((TrailModule)(ref trails)).colorOverLifetime, tint, greyOnly: true);
				((TrailModule)(ref trails)).colorOverTrail = Retint(((TrailModule)(ref trails)).colorOverTrail, tint, greyOnly: true);
			}
		}

		private static float Value(Color c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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)
			return Mathf.Max(c.r, Mathf.Max(c.g, c.b));
		}

		private static Color Scale(Color tint, float factor, float alpha, bool greyOnly)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (!greyOnly)
			{
				return new Color(tint.r * factor, tint.g * factor, tint.b * factor, alpha);
			}
			return new Color(factor, factor, factor, alpha);
		}

		private static MinMaxGradient Retint(MinMaxGradient g, Color tint, bool greyOnly)
		{
			//IL_0002: 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_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected I4, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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_0059: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			ParticleSystemGradientMode mode = ((MinMaxGradient)(ref g)).mode;
			switch ((int)mode)
			{
			case 0:
				((MinMaxGradient)(ref g)).color = Scale(tint, 1f, ((MinMaxGradient)(ref g)).color.a, greyOnly);
				break;
			case 2:
			{
				float num = Mathf.Max(Value(((MinMaxGradient)(ref g)).colorMin), Value(((MinMaxGradient)(ref g)).colorMax));
				if (num <= 0f)
				{
					num = 1f;
				}
				((MinMaxGradient)(ref g)).colorMin = Scale(tint, Value(((MinMaxGradient)(ref g)).colorMin) / num, ((MinMaxGradient)(ref g)).colorMin.a, greyOnly);
				((MinMaxGradient)(ref g)).colorMax = Scale(tint, Value(((MinMaxGradient)(ref g)).colorMax) / num, ((MinMaxGradient)(ref g)).colorMax.a, greyOnly);
				break;
			}
			case 1:
			case 4:
				((MinMaxGradient)(ref g)).gradient = RetintGradient(((MinMaxGradient)(ref g)).gradient, tint, greyOnly);
				break;
			case 3:
				((MinMaxGradient)(ref g)).gradientMin = RetintGradient(((MinMaxGradient)(ref g)).gradientMin, tint, greyOnly);
				((MinMaxGradient)(ref g)).gradientMax = RetintGradient(((MinMaxGradient)(ref g)).gradientMax, tint, greyOnly);
				break;
			}
			return g;
		}

		private static Gradient RetintGradient(Gradient source, Color tint, bool greyOnly)
		{
			//IL_0019: 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_0021: 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_0060: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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_00a4: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			GradientColorKey[] colorKeys = source.colorKeys;
			float num = 0f;
			GradientColorKey[] array = colorKeys;
			foreach (GradientColorKey val in array)
			{
				num = Mathf.Max(num, Value(val.color));
			}
			if (num <= 0f)
			{
				num = 1f;
			}
			GradientColorKey[] array2 = (GradientColorKey[])(object)new GradientColorKey[colorKeys.Length];
			for (int j = 0; j < colorKeys.Length; j++)
			{
				array2[j] = new GradientColorKey(Scale(tint, Value(colorKeys[j].color) / num, 1f, greyOnly), colorKeys[j].time);
			}
			Gradient val2 = new Gradient
			{
				mode = source.mode
			};
			val2.SetKeys(array2, source.alphaKeys);
			return val2;
		}
	}
	internal static class HarmonyPatches
	{
		[HarmonyPatch(typeof(EnemyHealth), "Hurt")]
		internal static class EnemyHealthHurtPatch
		{
			private static bool Prefix(EnemyHealth __instance, int _damage, Vector3 _hurtDirection)
			{
				//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)
				try
				{
					ShifterEnemyBehaviour component = ((Component)__instance).GetComponent<ShifterEnemyBehaviour>();
					if ((Object)(object)component != (Object)null && component.BlocksDamage)
					{
						return false;
					}
					if (_allowDepth > 0 || !IsBeyblade((Component?)(object)__instance))
					{
						return true;
					}
					if (Time.time - _lastBlockLogTime > 0.5f)
					{
						_lastBlockLogTime = Time.time;
						ModLog.Debug(() => $"[Beigoma] blocked damage {_damage} (invincible)");
					}
					if (_objectCollisionDepth > 0 && _enemyHurtDepth == 0 && Time.time - _lastObjectKnockbackTime > 0.25f)
					{
						Enemy component2 = ((Component)__instance).GetComponent<Enemy>();
						if (TryGetBeyblade(component2, out BeybladeEnemyBehaviour beyblade) && (Object)(object)beyblade != (Object)null)
						{
							_lastObjectKnockbackTime = Time.time;
							beyblade.OnPlayerAttackHitFromDirection(-_hurtDirection, "object hit");
						}
					}
					return false;
				}
				catch (Exception ex)
				{
					ModLog.WarnThrottled("EnemyHealthHurtPatch", "[Game] EnemyHealthHurtPatch failed: " + ex.Message);
					return true;
				}
			}
		}

		[HarmonyPatch(typeof(EnemyHealth), "LightImpact")]
		internal static class LightImpactPatch
		{
			private static void Prefix(EnemyHealth __instance, out bool __state)
			{
				__state = AllowImpact(__instance);
			}

			private static void Finalizer(bool __state)
			{
				ReleaseIf(__state);
			}
		}

		[HarmonyPatch(typeof(EnemyHealth), "MediumImpact")]
		internal static class MediumImpactPatch
		{
			private static void Prefix(EnemyHealth __instance, out bool __state)
			{
				__state = AllowImpact(__instance);
			}

			private static void Finalizer(bool __state)
			{
				ReleaseIf(__state);
			}
		}

		[HarmonyPatch(typeof(EnemyHealth), "HeavyImpact")]
		internal static class HeavyImpactPatch
		{
			private static void Prefix(EnemyHealth __instance, out bool __state)
			{
				__state = AllowImpact(__instance);
			}

			private static void Finalizer(bool __state)
			{
				ReleaseIf(__state);
			}
		}

		internal sealed class HurtGateState
		{
			public bool Allowed;

			public PhysGrabObject? Body;

			public bool Light;

			public bool Medium;

			public bool Heavy;

			public bool CountedDepth;

			public BeybladeEnemyBehaviour? Beyblade;

			public string Source = string.Empty;

			public Vector3 SourcePosition;

			public Vector3 SourceForward;
		}

		[HarmonyPatch(typeof(HurtCollider), "EnemyHurt")]
		[HarmonyPriority(600)]
		internal static class ShifterEnemyHurtBlockPatch
		{
			private static bool Prefix(HurtCollider __instance, Enemy _enemy)
			{
				try
				{
					ShifterHurtOwner shifterHurtOwner = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).GetComponent<ShifterHurtOwner>() : null);
					if ((Object)(object)shifterHurtOwner != (Object)null && (Object)(object)shifterHurtOwner.Owner != (Object)null && (Object)(object)shifterHurtOwner.Owner == (Object)(object)_enemy)
					{
						return false;
					}
					ShifterEnemyBehaviour shifterEnemyBehaviour = (((Object)(object)_enemy != (Object)null) ? ((Component)_enemy).GetComponent<ShifterEnemyBehaviour>() : null);
					return (Object)(object)shifterEnemyBehaviour == (Object)null || !shifterEnemyBehaviour.BlocksDamage;
				}
				catch (Exception ex)
				{
					ModLog.WarnOnce("ShifterEnemyHurtBlockPatch", "[Shifter] ShifterEnemyHurtBlockPatch failed: " + ex.Message);
					return true;
				}
			}
		}

		[HarmonyPatch(typeof(HurtCollider), "EnemyHurt")]
		[HarmonyPriority(400)]
		internal static class EnemyHurtPatch
		{
			private static void Prefix(HurtCollider __instance, Enemy _enemy, out HurtGateState? __state)
			{
				//IL_0137: Unknown result type (might be due to invalid IL or missing references)
				//IL_013c: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
				__state = null;
				try
				{
					if (!TryGetBeyblade(_enemy, out BeybladeEnemyBehaviour beyblade) || (Object)(object)beyblade == (Object)null)
					{
						return;
					}
					string text = ResolveWeaponName(__instance);
					bool flag = text.Length > 0 && beyblade.IsWeaponWhitelisted(text);
					bool deathPit = __instance.deathPit;
					if (ModLog.Verbose && Time.time - _lastWeaponLogTime > 0.5f)
					{
						_lastWeaponLogTime = Time.time;
						bool flag2 = IsPlayerTumble(__instance);
						ModLog.Debug("[Beigoma] hit by '" + ((text.Length > 0) ? text : ((Object)((Component)__instance).gameObject).name) + "' " + $"(whitelisted={flag}, deathPit={deathPit}, tumble={flag2}, " + $"damage={__instance.enemyDamage}, impact={__instance.enemyImpact})");
					}
					HurtGateState hurtGateState = new HurtGateState();
					if (flag || deathPit)
					{
						Allow();
						hurtGateState.Allowed = true;
					}
					else
					{
						hurtGateState.Beyblade = beyblade;
						hurtGateState.Source = ((text.Length > 0) ? text : ((Object)((Component)__instance).gameObject).name);
						hurtGateState.SourcePosition = ((Component)__instance).transform.position;
						hurtGateState.SourceForward = ((Component)__instance).transform.forward;
						if (_enemy.HasRigidbody && (Object)(object)_enemy.Rigidbody.physGrabObject != (Object)null)
						{
							PhysGrabObject val = (hurtGateState.Body = _enemy.Rigidbody.physGrabObject);
							hurtGateState.Light = val.lightBreakImpulse;
							hurtGateState.Medium = val.mediumBreakImpulse;
							hurtGateState.Heavy = val.heavyBreakImpulse;
						}
					}
					_enemyHurtDepth++;
					hurtGateState.CountedDepth = true;
					__state = hurtGateState;
				}
				catch (Exception ex)
				{
					ModLog.WarnThrottled("EnemyHurtPatch.Prefix", "[Game] EnemyHurtPatch.Prefix failed: " + ex.Message);
				}
			}

			private static void Finalizer(HurtGateState? __state, bool __result)
			{
				//IL_0075: 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)
				if (__state == null)
				{
					return;
				}
				ReleaseIf(__state.Allowed);
				if (__state.CountedDepth && _enemyHurtDepth > 0)
				{
					_enemyHurtDepth--;
				}
				try
				{
					PhysGrabObject body = __state.Body;
					if ((Object)(object)body != (Object)null)
					{
						body.lightBreakImpulse = __state.Light;
						body.mediumBreakImpulse = __state.Medium;
						body.heavyBreakImpulse = __state.Heavy;
					}
					BeybladeEnemyBehaviour beyblade = __state.Beyblade;
					if (__result && (Object)(object)beyblade != (Object)null)
					{
						beyblade.OnPlayerAttackHit(__state.SourcePosition, __state.SourceForward, __state.Source);
					}
				}
				catch (Exception ex)
				{
					ModLog.WarnThrottled("EnemyHurtPatch.Finalizer", "[Game] EnemyHurtPatch.Finalizer failed: " + ex.Message);
				}
			}
		}

		[HarmonyPatch(typeof(EnemyDirector), "PickEnemies")]
		internal static class SpawnChancePatch
		{
			private static readonly (string SetupName, string Label, Func<float?> Chance)[] Setups = new(string, string, Func<float?>)[3]
			{
				("Enemy - Beyblade", "Beigoma", () => MidorinoEnemiesPlugin.BeybladeConfig?.SpawnChance),
				("Enemy - Raiblade", "Raigoma", () => MidorinoEnemiesPlugin.RaigomaConfig?.SpawnChance),
				("Enemy - Dronebot", "Shifter", () => MidorinoEnemiesPlugin.ShifterConfig?.SpawnChance)
			};

			private static readonly Dictionary<string, RarityPreset> Presets = new Dictionary<string, RarityPreset>();

			private static readonly HashSet<string> Logged = new HashSet<string>();

			private static void Prefix(List<EnemySetup> _enemiesList)
			{
				try
				{
					if (_enemiesList == null)
					{
						return;
					}
					if (BeigomaDisabled)
					{
						int num = _enemiesList.RemoveAll((EnemySetup setup) => MatchesName(setup, "Enemy - Beyblade") || MatchesName(setup, "Enemy - Raiblade"));
						if (num > 0)
						{
							ModLog.WarnThrottled("SpawnChance.Disabled", "[Game] Beigoma/Raigoma removed from the spawn pool (damage gate unavailable).");
						}
					}
					foreach (EnemySetup _enemies in _enemiesList)
					{
						if (!TryMatch(_enemies, out string setupName, out string label, out Func<float?> getChance))
						{
							continue;
						}
						float? num2 = getChance();
						if (!num2.HasValue)
						{
							continue;
						}
						if (!Presets.TryGetValue(setupName, out RarityPreset value) || (Object)(object)value == (Object)null)
						{
							value = ScriptableObject.CreateInstance<RarityPreset>();
							((Object)value).name = "Rarity - Midorino " + label + " (Config)";
							Object.DontDestroyOnLoad((Object)(object)value);
							Presets[setupName] = value;
						}
						value.chance = num2.Value;
						_enemies.rarityPreset = value;
						if (Logged.Add(setupName))
						{
							float appliedChance = value.chance;
							string setupLabel = ((Object)_enemies).name;
							ModLog.Debug(() => $"[SpawnChance] applied: {appliedChance} (setup '{setupLabel}', {label})");
						}
					}
				}
				catch (Exception ex)
				{
					ModLog.WarnThrottled("SpawnChancePatch", "[Game] SpawnChancePatch failed: " + ex.Message);
				}
			}

			private static bool TryMatch(EnemySetup? setup, out string setupName, out string label, out Func<float?> getChance)
			{
				setupName = string.Empty;
				label = string.Empty;
				getChance = () => (float?)null;
				if ((Object)(object)setup == (Object)null)
				{
					return false;
				}
				(string, string, Func<float?>)[] setups = Setups;
				for (int num = 0; num < setups.Length; num++)
				{
					var (text, text2, func) = setups[num];
					if (MatchesName(setup, text))
					{
						setupName = text;
						label = text2;
						getChance = func;
						return true;
					}
				}
				return false;
			}

			private static bool MatchesName(EnemySetup? setup, string name)
			{
				if ((Object)(object)setup == (Object)null)
				{
					return false;
				}
				if (((Object)setup).name == name)
				{
					return true;
				}
				if (setup.spawnObjects != null)
				{
					foreach (PrefabRef spawnObject in setup.spawnObjects)
					{
						if (spawnObject != null && ((PrefabRef<GameObject>)(object)spawnObject).PrefabName == name)
						{
							return true;
						}
					}
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "OnCollisionStay")]
		internal static class ObjectCollisionPatch
		{
			private static void Prefix()
			{
				_objectCollisionDepth++;
			}

			private static void Finalizer()
			{
				if (_objectCollisionDepth > 0)
				{
					_objectCollisionDepth--;
				}
			}
		}

		[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "DestroyObject")]
		internal static class DestroyObjectPatch
		{
			private static void Prefix()
			{
				Allow();
			}

			private static void Finalizer()
			{
				Release();
			}
		}

		[HarmonyPatch(typeof(EnemyStateStunned), "Set")]
		internal static class StunDurationPatch
		{
			private static bool Prefix(EnemyStateStunned __instance, ref float time)
			{
				try
				{
					ShifterEnemyBehaviour component = ((Component)__instance).GetComponent<ShifterEnemyBehaviour>();
					if ((Object)(object)component != (Object)null && component.BlocksStun)
					{
						return false;
					}
					BeybladeEnemyBehaviour component2 = ((Component)__instance).GetComponent<BeybladeEnemyBehaviour>();
					if ((Object)(object)component2 != (Object)null && component2.Settings != null)
					{
						time *= component2.Settings.StunDurationMultiplier;
					}
				}
				catch (Exception ex)
				{
					ModLog.WarnThrottled("StunDurationPatch", "[Game] StunDurationPatch failed: " + ex.Message);
				}
				return true;
			}
		}

		private const string HarmonyId = "Midorino.MidorinoEnemies.harmony";

		private const float LogInterval = 0.5f;

		private static Harmony? _harmony;

		private static int _allowDepth;

		private static int _enemyHurtDepth;

		private static int _objectCollisionDepth;

		private const float ObjectKnockbackInterval = 0.25f;

		private static float _lastObjectKnockbackTime = -999f;

		private static float _lastBlockLogTime = -999f;

		private static float _lastWeaponLogTime = -999f;

		private static readonly Type[] DamageGateTypes = new Type[7]
		{
			typeof(EnemyHealthHurtPatch),
			typeof(LightImpactPatch),
			typeof(MediumImpactPatch),
			typeof(HeavyImpactPatch),
			typeof(EnemyHurtPatch),
			typeof(ObjectCollisionPatch),
			typeof(DestroyObjectPatch)
		};

		internal static bool BeigomaDisabled { get; private set; }

		public static void Apply()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (_harmony != null)
			{
				return;
			}
			try
			{
				_harmony = new Harmony("Midorino.MidorinoEnemies.harmony");
				if (!TryPatchClass(typeof(SpawnChancePatch), out List<MethodInfo> patched))
				{
					ModLog.Error("[Game] SpawnChancePatch failed; the mod cannot control spawning, so all patches are removed.");
					_harmony.UnpatchSelf();
					_harmony = null;
					return;
				}
				HashSet<Type> hashSet = new HashSet<Type>(DamageGateTypes);
				List<Type> list = new List<Type>();
				bool flag = false;
				Type[] damageGateTypes = DamageGateTypes;
				foreach (Type type in damageGateTypes)
				{
					if (TryPatchClass(type, out patched))
					{
						list.Add(type);
					}
					else
					{
						flag = true;
					}
				}
				Type[] typesFromAssembly = AccessTools.GetTypesFromAssembly(typeof(HarmonyPatches).Assembly);
				foreach (Type type2 in typesFromAssembly)
				{
					if (!(type2 == typeof(SpawnChancePatch)) && !hashSet.Contains(type2) && IsPatchClass(type2))
					{
						TryPatchClass(type2, out patched);
					}
				}
				if (flag)
				{
					foreach (Type item in list)
					{
						UnpatchClass(item);
					}
					BeigomaDisabled = true;
					ModLog.Error("[Game] The damage gate could not be fully applied, so Beigoma and Raigoma will not spawn this session (Shifter is not affected). The game may have been updated; please update the mod.");
				}
				else
				{
					ModLog.Info("[Game] Harmony patches applied (damage gate).");
				}
				WeaponSourcePatches.Apply(_harmony);
			}
			catch (Exception arg)
			{
				ModLog.Error($"[Game] HarmonyPatches.Apply failed: {arg}");
				try
				{
					Harmony? harmony = _harmony;
					if (harmony != null)
					{
						harmony.UnpatchSelf();
					}
				}
				catch (Exception ex)
				{
					ModLog.Error("[Game] Unpatch after failure also failed: " + ex.Message);
				}
				_harmony = null;
			}
		}

		private static bool IsPatchClass(Type type)
		{
			if (type.IsClass)
			{
				return type.GetCustomAttributes(typeof(HarmonyPatch), inherit: false).Length != 0;
			}
			return false;
		}

		private static bool TryPatchClass(Type type, out List<MethodInfo>? patched)
		{
			patched = null;
			try
			{
				patched = _harmony.CreateClassProcessor(type).Patch();
				return true;
			}
			catch (Exception ex)
			{
				ModLog.Error("[Game] Patch " + type.Name + " failed: " + ex.Message);
				return false;
			}
		}

		private static void UnpatchClass(Type type)
		{
			try
			{
				HarmonyMethod mergedFromType = HarmonyMethodExtensions.GetMergedFromType(type);
				MethodBase methodBase = ((mergedFromType.declaringType == null || mergedFromType.methodName == null) ? null : AccessTools.DeclaredMethod(mergedFromType.declaringType, mergedFromType.methodName, mergedFromType.argumentTypes, (Type[])null));
				if (methodBase == null)
				{
					return;
				}
				string[] array = new string[4] { "Prefix", "Postfix", "Finalizer", "Transpiler" };
				foreach (string name in array)
				{
					MethodInfo method = type.GetMethod(name, BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					if (method != null)
					{
						_harmony.Unpatch(methodBase, method);
					}
				}
			}
			catch (Exception ex)
			{
				ModLog.Error("[Game] Unpatch " + type.Name + " failed: " + ex.Message);
			}
		}

		internal static bool TryGetBeyblade(Enemy? enemy, out BeybladeEnemyBehaviour? beyblade)
		{
			beyblade = (((Object)(object)enemy != (Object)null) ? ((Component)enemy).GetComponentInChildren<BeybladeEnemyBehaviour>() : null);
			return (Object)(object)beyblade != (Object)null;
		}

		private static bool IsBeyblade(Component? component)
		{
			if ((Object)(object)component == (Object)null)
			{
				return false;
			}
			Enemy component2 = component.GetComponent<Enemy>();
			BeybladeEnemyBehaviour beyblade;
			return TryGetBeyblade(component2, out beyblade);
		}

		private static void Allow()
		{
			_allowDepth++;
		}

		private static void Release()
		{
			if (_allowDepth > 0)
			{
				_allowDepth--;
			}
		}

		internal static string ResolveWeaponName(HurtCollider hurtCollider)
		{
			try
			{
				string text = WeaponSourcePatches.FindTaggedName((Component)(object)hurtCollider);
				if (text.Length > 0)
				{
					return text;
				}
				PhysGrabObject value = Traverse.Create((object)hurtCollider).Field("parentPhysGrabObject").GetValue<PhysGrabObject>();
				if ((Object)(object)value == (Object)null)
				{
					return string.Empty;
				}
				ItemAttributes component = ((Component)value).GetComponent<ItemAttributes>();
				if ((Object)(object)component != (Object)null && (Object)(object)component.item != (Object)null)
				{
					if (!string.IsNullOrWhiteSpace(((Object)component.item).name))
					{
						return ((Object)component.item).name;
					}
					if (!string.IsNullOrWhiteSpace(component.item.itemName))
					{
						return component.item.itemName;
					}
				}
				return ((Object)((Component)value).gameObject).name.Replace("(Clone)", string.Empty).Trim();
			}
			catch (Exception ex)
			{
				ModLog.WarnThrottled("ResolveWeaponName", "[Game] ResolveWeaponName failed: " + ex.Message);
				return string.Empty;
			}
		}

		private static bool AllowImpact(EnemyHealth health)
		{
			try
			{
				if ((Object)(object)health == (Object)null || !TryGetBeyblade(((Component)health).GetComponent<Enemy>(), out BeybladeEnemyBehaviour beyblade) || (Object)(object)beyblade == (Object)null || beyblade.Settings == null || !beyblade.Settings.ImpactHurtEnabled)
				{
					return false;
				}
				Allow();
				return true;
			}
			catch (Exception ex)
			{
				ModLog.WarnThrottled("AllowImpact", "[Game] AllowImpact failed: " + ex.Message);
				return false;
			}
		}

		private static void ReleaseIf(bool allowed)
		{
			if (allowed)
			{
				Release();
			}
		}

		private static bool IsPlayerTumble(HurtCollider hurtCollider)
		{
			try
			{
				PhysGrabObject value = Traverse.Create((object)hurtCollider).Field("parentPhysGrabObject").GetValue<PhysGrabObject>();
				if ((Object)(object)value != (Object)null && (Object)(object)((Component)value).GetComponent<PlayerTumble>() != (Object)null)
				{
					return true;
				}
				return (Object)(object)((Component)hurtCollider).GetComponentInParent<PlayerTumble>() != (Object)null;
			}
			catch (Exception ex)
			{
				ModLog.WarnThrottled("IsPlayerTumble", "[Game] IsPlayerTumble failed: " + ex.Message);
				return false;
			}
		}
	}
	public enum ChargeLine
	{
		Direct,
		Approach,
		NoRoute
	}
	public interface IRepoGameBridge
	{
		Vec3 GetBodyPosition(EnemyTemplateBehaviour enemy);

		bool IsStunned(EnemyTemplateBehaviour enemy);

		float GetBodyTiltDegrees(EnemyTemplateBehaviour enemy);

		bool IsDespawnRequested(EnemyTemplateBehaviour enemy);

		bool HookGameEvents(EnemyTemplateBehaviour enemy, Action<ITarget> onPlayerSeen, Action<IKnockbackTarget> onPlayerTouched, Action<Vec3> onNoiseHeard, Action<ITarget> onGrabbedByPlayer);

		void ConfigureVision(EnemyTemplateBehaviour enemy, float visionDistance);

		void ConfigureHealth(EnemyTemplateBehaviour enemy, int maxHealth, int lightDamage, int mediumDamage, int heavyDamage);

		ChargeLine EvaluateChargeLine(EnemyTemplateBehaviour enemy, ITarget target, out Vec3 approachPoint);

		bool IsSpawnIdlePaused();

		bool ShouldForceLeave(EnemyTemplateBehaviour enemy);

		bool TryPickRoamDestination(EnemyTemplateBehaviour enemy, out Vec3 destination);

		bool TryPickLeaveDestination(EnemyTemplateBehaviour enemy, out Vec3 destination);

		void WalkTo(EnemyTemplateBehaviour enemy, Vec3 destination, float speed);

		void StopMoving(EnemyTemplateBehaviour enemy);

		float GetNotMovingSeconds(EnemyTemplateBehaviour enemy);

		void FaceDirection(EnemyTemplateBehaviour enemy, Vec3 direction, float maxDegreesPerSecond);

		Vec3 GetFacing(EnemyTemplateBehaviour enemy);

		void AlignAgentToBody(EnemyTemplateBehaviour enemy);

		void BeginCharge(EnemyTemplateBehaviour enemy);

		void DriveCharge(EnemyTemplateBehaviour enemy, Vec3 direction, float speed);

		void EndCharge(EnemyTemplateBehaviour enemy, Vec3 bounceVelocity);

		void SuppressStuckJump(EnemyTemplateBehaviour enemy, float seconds);

		void QueueHitKnockback(EnemyTemplateBehaviour enemy, Vec3 velocity, float minStunSeconds);

		void ApplyPendingHitKnockback(EnemyTemplateBehaviour enemy);

		void ApplyImpulse(IKnockbackTarget target, Vec3 impulse);

		void DealContactDamage(EnemyTemplateBehaviour enemy, IKnockbackTarget target, int amount);

		void SpinVisual(EnemyTemplateBehaviour enemy, float degreesThisFrame);

		void RequestDespawn(EnemyTemplateBehaviour enemy);

		void CancelDespawnRequest(EnemyTemplateBehaviour enemy);

		void HoldInPlace(EnemyTemplateBehaviour enemy, float seconds);

		void SetRespawnDelay(EnemyTemplateBehaviour enemy, float seconds);

		Vec3 GetPathDirection(EnemyTemplateBehaviour enemy, Vec3 destination);

		bool HookDeath(EnemyTemplateBehaviour enemy, Action onDeath);

		bool HookHurt(EnemyTemplateBehaviour enemy, Action onHurt);

		int MuteLegacyAiEvents(EnemyTemplateBehaviour enemy, Type legacyAiType);

		string DescribeDespawnCause(EnemyTemplateBehaviour enemy);

		void OverrideBodyFollow(EnemyTemplateBehaviour enemy, float maxSpeed, float turnSpeed);

		float GetTargetHorizontalSpeed(ITarget target);

		bool HookImpacts(EnemyTemplateBehaviour enemy, Action<int> onImpact);

		string GetLocaleCode();

		void SetDisplayName(EnemyTemplateBehaviour enemy, string name);

		bool HookSpawn(EnemyTemplateBehaviour enemy, Action onSpawn);

		void SpawnTeleport(EnemyTemplateBehaviour enemy);

		void DeathEffectsAndDespawn(EnemyTemplateBehaviour enemy, string[]? particleNames = null, Color? debrisColor = null);

		int GetTargetId(object target);

		bool IsHost();

		bool IsMultiplayer();

		bool SendRpc(Component owner, string method, bool includeSelf, params object[] args);

		bool PreventWallCling(EnemyTemplateBehaviour enemy);

		bool TryClimbStep(EnemyTemplateBehaviour enemy, float maxStepHeight, float liftScale, out float stepHeight);

		bool KeepAgentNearBody(EnemyTemplateBehaviour enemy, float maxLead);

		void SetBodyFollowPoint(EnemyTemplateBehaviour enemy, Vector3? worldPoint);

		Vector3 GetDefaultFollowPoint(EnemyTemplateBehaviour enemy);

		bool TryGetPathCorners(EnemyTemplateBehaviour enemy, Vector3 destination, List<Vector3> corners);

		void KeepAgentUnderBody(EnemyTemplateBehaviour enemy, float speed, float warpDistance);

		void TeleportBodyToAgent(EnemyTemplateBehaviour enemy);

		bool TryRelocate(EnemyTemplateBehaviour enemy, float minDistance, float maxDistance, out Vector3 destination);

		void SetBodyGravity(EnemyTemplateBehaviour enemy, bool gravity);

		bool TryGetLookUnderPoint(EnemyTemplateBehaviour enemy, ITarget target, out Vector3 point);

		PlayerAvatar? GetPlayerAvatar(ITarget target);

		Vec3 ClampToReachable(EnemyTemplateBehaviour enemy, Vec3 destination);

		void RequestStuckDespawn(EnemyTemplateBehaviour enemy);

		void ConfigureStuckDespawn(EnemyTemplateBehaviour enemy, bool enabled, int count);

		void ResetStuckCounters(EnemyTemplateBehaviour enemy);

		void SetVisualPresence(EnemyTemplateBehaviour enemy, float amount, float sinkDepth);

		bool PlayEnemyParticle(EnemyTemplateBehaviour enemy, string name);

		Transform? GetBodyTransform(EnemyTemplateBehaviour enemy);

		Transform? GetSpinVisualTransform(EnemyTemplateBehaviour enemy);

		Behaviour? SetupPlayerHurtCollider(EnemyTemplateBehaviour enemy, GameObject target, int damage, float cooldownSeconds);

		void SetPlayerHurtDamage(Behaviour hurtCollider, int damage);

		int ChargeBatteriesInRange(GameObject charger, Vector3 center, float radius, float chargeMultiplier);

		AudioSource? FindLoopAudioSource(EnemyTemplateBehaviour enemy);
	}
	public sealed class RepoGameBridge : IRepoGameBridge
	{
		private sealed class PlayerTarget : ITarget, IKnockbackTarget
		{
			public PlayerAvatar Avatar { get; }

			public Vec3 Position
			{
				get
				{
					//IL_0073: 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)
					if ((Object)(object)Avatar != (Object)null && (Object)(object)Avatar.PlayerVisionTarget != (Object)null && (Object)(object)Avatar.PlayerVisionTarget.VisionTransform != (Object)null)
					{
						return Avatar.PlayerVisionTarget.VisionTransform.position.ToVec3();
					}
					if (!((Object)(object)Avatar != (Object)null))
					{
						return Vec3.Zero;
					}
					return ((Component)Avatar).transform.position.ToVec3();
				}
			}

			public PlayerTarget(PlayerAvatar avatar)
			{
				Avatar = avatar;
			}
		}

		private const float NavMeshSampleRadius = 3f;

		private const float BounceFollowDisableSeconds = 0.35f;

		private const float MaxChargeUpwardSpeed = 2f;

		private const float KnockbackTumbleSeconds = 1f;

		private const float KnockbackTumbleEnemyHurtDisableSeconds = 0.6f;

		private const float RouteGroundRayLength = 3f;

		private const float RouteTargetSampleRadius = 0.5f;

		private const float RouteDirectMaxHeightDiff = 0.8f;

		private const float RouteEdgeTolerance = 1f;

		private const float PendingKnockbackLifetime = 1f;

		private const float HitKnockbackFollowDisableSeconds = 0.6f;

		private const string LoopAudioSourceName = "Audio Source";

		private const string ShideNamePrefix = "Shide";

		private const float ShideFlareMinSpin = 360f;

		private const float ShideFlareMaxSpin = 1440f;

		private const float ShideRestDegrees = 15f;

		private const float ShideFlareMaxDegrees = 50f;

		private const float ShideFlareFollowRate = 6f;

		private const float ShideFlutterMaxDegrees = 8f;

		private const float ShideFlutterHz = 2.5f;

		private const float ShidePhaseStep = 1.7f;

		private const string VisualObjectName = "BeybladeVisual";

		private const float WobbleMaxDegrees = 4f;

		private const float WobbleMinDegrees = 0.5f;

		private const float WobbleHz = 1.2f;

		private const float WobbleBaseSpin = 720f;

		private const float WobbleStableSpin = 1440f;

		private const float TiltFollowRateRecover = 3f;

		private const float TiltFollowRateStunned = 14f;

		private Enemy? _enemy;

		private EnemyRigidbody? _body;

		private EnemyVision? _vision;

		private EnemyStateInvestigate? _investigate;

		private bool _hooked;

		private bool _visionHooked;

		private bool _touchHooked;

		private bool _grabHooked;

		private bool _noiseHooked;

		private bool _deathHooked;

		private bool _hurtHooked;

		private bool _impactsHooked;

		private bool _spawnHooked;

		private Vector3 _pendingKnockback;

		private float _pendingKnockbackExpire;

		private bool _hasPendingKnockback;

		private float _pendingStunSeconds;

		private readonly List<Transform> _shides = new List<Transform>();

		private readonly List<Quaternion> _shideBaseLocalRotations = new List<Quaternion>();

		private readonly List<Vector3> _shideLocalHang = new List<Vector3>();

		private bool _shidesResolved;

		private float _shideFlare;

		private Transform? _cachedVisual;

		private float _spinYaw;

		private Vector3 _visualUp = Vector3.up;

		private bool _visualUpInitialized;

		private float _wobblePhase;

		private readonly NavMeshPath _pathBuffer = new NavMeshPath();

		private static bool _localeLookupResolved;

		private static MethodInfo? _localeGetCode;

		private static readonly string[] DeathParticleNames = new string[3] { "Impact", "Bits", "Directional Bits" };

		private bool _rpcWarned;

		private const float FallBelowAgentThreshold = 1.74f;

		private bool _fallingLogged;

		private const float ResyncBelowAgentThreshold = 2.5f;

		private const float ResyncSampleRadius = 1.5f;

		private float _resyncCooldownUntil;

		private const int RoamPickAttempts = 8;

		private const float RoomProbeRadius = 0.5f;

		private const float RoomProbeLowerOffset = 1f;

		private const int SameRoomCandidateCount = 3;

		private const float SameRoomHeightWeight = 0.5f;

		private static readonly Collider[] RoomProbeBuffer = (Collider[])(object)new Collider[8];

		private static readonly LevelPoint[] SameRoomBest = (LevelPoint[])(object)new LevelPoint[3];

		private static readonly float[] SameRoomBestScore = new float[3];

		private const float StepProbeExtra = 0.3f;

		private const float StepBlockedSpeed = 1.2f;

		private const float StepForwardPush = 1.2f;

		private const float StepRiserMaxNormalY = 0.7f;

		private const float StepClimbPathMaxHeight = 0.9f;

		private const float StepClimbPathRise = 0.3f;

		private const float StepClimbPathLookAhead = 2f;

		private const float StepClimbPathSampleRadius = 0.3f;

		private const float StepClimbPathTopTolerance = 0.15f;

		private const float StepClimbPathMinLift = 1.25f;

		private const float StepClimbPathMaxLift = 1.4f;

		private const float StepClimbPathForwardPush = 1.8f;

		private float _stepClimbCooldownUntil;

		private readonly List<Collider> _bodyColliders = new List<Collider>();

		private bool _bodyCollidersResolved;

		private const float LeashReleaseStuckSeconds = 1.5f;

		private Transform? _followTarget;

		private Vector3 _followBaseLocal;

		private bool _followCaptured;

		private readonly NavMeshPath _cornerPathBuffer = new NavMeshPath();

		private const int RelocateAttempts = 6;

		private Transform? _presenceMesh;

		private Vector3 _presenceBaseScale;

		private Vector3 _presenceBasePosition;

		private bool _presenceResolved;

		private float _presenceLast = -1f;

		private readonly List<ItemBattery> _chargeTargets = new List<ItemBattery>();

		public Vec3 GetBodyPosition(EnemyTemplateBehaviour enemy)
		{
			//IL_0033: 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)
			if ((Object)(object)enemy == (Object)null)
			{
				return Vec3.Zero;
			}
			EnemyRigidbody val = Body(enemy);
			return (((Object)(object)val != (Object)null) ? ((Component)val).transform.position : ((Component)enemy).transform.position).ToVec3();
		}

		public bool IsStunned(EnemyTemplateBehaviour enemy)
		{
			Enemy val = GameEnemy(enemy);
			if ((Object)(object)val != (Object)null)
			{
				return val.IsStunned();
			}
			return false;
		}

		public float GetBodyTiltDegrees(EnemyTemplateBehaviour enemy)
		{
			//IL_001d: 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)
			EnemyRigidbody val = Body(enemy);
			if (!((Object)(object)val != (Object)null))
			{
				return -1f;
			}
			return Vector3.Angle(((Component)val).transform.up, Vector3.up);
		}

		public bool IsDespawnRequested(EnemyTemplateBehaviour enemy)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Invalid comparison between Unknown and I4
			Enemy val = GameEnemy(enemy);
			if ((Object)(object)val != (Object)null)
			{
				return (int)val.CurrentState == 11;
			}
			return false;
		}

		public string DescribeDespawnCause(EnemyTemplateBehaviour enemy)
		{
			try
			{
				Enemy val = GameEnemy(enemy);
				if ((Object)(object)val == (Object)null || (Object)(object)val.EnemyParent == (Object)null)
				{
					return "unknown";
				}
				EnemyParent enemyParent = val.EnemyParent;
				EnemyStateDespawn val2 = FindInOwnEnemy<EnemyStateDespawn>((Component)(object)enemy);
				int num = (((Object)(object)val2 != (Object)null) ? val2.StuckDespawnCount : (-1));
				string text = (((Object)(object)val2 != (Object)null && val2.StuckDespawn && val.StuckCount >= num) ? "stuck" : ((enemyParent.SpawnedTimer <= 0f) ? "time" : "other"));
				return $"{text} (stuckCount={val.StuckCount}/{num}, spawnedTimer={enemyParent.SpawnedTimer:F0}s, " + $"playerClose={enemyParent.playerClose})";
			}
			catch (Exception ex)
			{
				return "unknown (" + ex.Message + ")";
			}
		}

		public bool HookGameEvents(EnemyTemplateBehaviour enemy, Action<ITarget> onPlayerSeen, Action<IKnockbackTarget> onPlayerTouched, Action<Vec3> onNoiseHeard, Action<ITarget> onGrabbedByPlayer)
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Expected O, but got Unknown
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Expected O, but got Unknown
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Expected O, but got Unknown
			if (_hooked)
			{
				return true;
			}
			if ((Object)(object)enemy == (Object)null)
			{
				return false;
			}
			try
			{
				Resolve(enemy);
				if ((Object)(object)_vision == (Object)null)
				{
					return false;
				}
				if (!_visionHooked)
				{
					EnemyVision vision = _vision;
					vision.onVisionTriggered.AddListener((UnityAction)delegate
					{
						PlayerAvatar onVisionTriggeredPlayer = vision.onVisionTriggeredPlayer;
						if ((Object)(object)onVisionTriggeredPlayer != (Object)null && !onVisionTriggeredPlayer.isDisabled)
						{
							onPlayerSeen(new PlayerTarget(onVisionTriggeredPlayer));
						}
					});
					_visionHooked = true;
				}
				if ((Object)(object)_body != (Object)null && !_touchHooked)
				{
					EnemyRigidbody body = _body;
					body.onTouchPlayer.AddListener((UnityAction)delegate
					{
						PlayerAvatar onTouchPlayerAvatar = body.onTouchPlayerAvatar;
						if ((Object)(object)onTouchPlayerAvatar != (Object)null && !onTouchPlayerAvatar.isDisabled)
						{
							onPlayerTouched(new PlayerTarget(onTouchPlayerAvatar));
						}
					});
					_touchHooked = true;
				}
				if ((Object)(object)_body != (Object)null && !_grabHooked)
				{
					EnemyRigidbody body2 = _body;
					body2.onGrabbed.AddListener((UnityAction)delegate
					{
						PlayerAvatar onGrabbedPlayerAvatar = body2.onGrabbedPlayerAvatar;
						if ((Object)(object)onGrabbedPlayerAvatar != (Object)null && !onGrabbedPlayerAvatar.isDisabled)
						{
							onGrabbedByPlayer(new PlayerTarget(onGrabbedPlayerAvatar));
						}
					});
					_grabHooked = true;
				}
				if ((Object)(object)_investigate != (Object)null && !_noiseHooked)
				{
					EnemyStateInvestigate investigate = _investigate;
					investigate.onInvestigateTriggered.AddListener((UnityAction)delegate
					{
						//IL_0011: Unknown result type (might be due to invalid IL or missing references)
						onNoiseHeard(investigate.onInvestigateTriggeredPosition.ToVec3());
					});
					_noiseHooked = true;
				}
				_hooked = true;
				ModLog.Debug(() => $"[Game] HookGameEvents OK (vision=true, touch={(Object)(object)_body != (Object)null}, noise={(Object)(object)_investigate != (Object)null})");
				return true;
			}
			catch (Exception ex)
			{
				ModLog.Warn("[Game] HookGameEvents failed: " + ex.Message);
				return false;
			}
		}

		public void ConfigureVision(EnemyTemplateBehaviour enemy, float visionDistance)
		{
			Resolve(enemy);
			if ((Object)(object)_vision != (Object)null && visionDistance > 0f)
			{
				_vision.VisionDistance = visionDistance;
			}
		}

		public void ConfigureHealth(EnemyTemplateBehaviour enemy, int maxHealth, int lightDamage, int mediumDamage, int heavyDamage)
		{
			if ((Object)(object)enemy == (Object)null)
			{
				return;
			}
			try
			{
				EnemyHealth val = ((Component)enemy).GetComponent<EnemyHealth>();
				if ((Object)(object)val == (Object)null)
				{
					val = FindInOwnEnemy<EnemyHealth>((Component)(object)enemy);
				}
				if ((Object)(object)val == (Object)null)
				{
					ModLog.Warn("[Game] ConfigureHealth: EnemyHealth not found");
					return;
				}
				val.health = maxHealth;
				val.healthCurrent = maxHealth;
				val.impactLightDamage = lightDamage;
				val.impactMediumDamage = mediumDamage;
				val.impactHeavyDamage = heavyDamage;
				ModLog.Debug(() => $"[{EnemyTag(enemy)}] health config applied: HP={maxHealth}, impact L/M/H={lightDamage}/{mediumDamage}/{heavyDamage}");
			}
			catch (Exception ex)
			{
				ModLog.Warn("[Game] ConfigureHealth failed: " + ex.Message);
			}
		}

		public ChargeLine EvaluateChargeLine(EnemyTemplateBehaviour enemy, ITarget target, out Vec3 approachPoint)
		{
			//IL_003c: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_0091: 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_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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_00d6: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Expected O, but got Unknown
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: 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_0158: 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)
			approachPoint = target?.Position ?? Vec3.Zero;
			EnemyRigidbody val = Body(enemy);
			if ((Object)(object)enemy == (Object)null || (Object)(object)val == (Object)null || target == null)
			{
				return ChargeLine.Direct;
			}
			try
			{
				NavMeshHit val2 = default(NavMeshHit);
				if (!NavMesh.SamplePosition(((Component)val).transform.position, ref val2, 3f, -1))
				{
					return ChargeLine.Direct;
				}
				Vector3 val3 = ((target is PlayerTarget playerTarget && (Object)(object)playerTarget.Avatar != (Object)null) ? ((Component)playerTarget.Avatar).transform.position : target.Position.ToUnity());
				Vector3 val4 = val3;
				RaycastHit val5 = default(RaycastHit);
				if (Physics.Raycast(val3 + Vector3.up * 0.1f, Vector3.down, ref val5, 3f, LayerMask.GetMask(new string[1] { "Default" }), (QueryTriggerInteraction)1))
				{
					val4 = ((RaycastHit)(ref val5)).point;
				}
				NavMeshHit val6 = default(NavMeshHit);
				if (!NavMesh.SamplePosition(val4, ref val6, 0.5f, -1))
				{
					return ChargeLine.NoRoute;
				}
				approachPoint = ((NavMeshHit)(ref val6)).position.ToVec3();
				float num = Mathf.Abs(((NavMeshHit)(ref val6)).position.y - ((NavMeshHit)(ref val2)).position.y);
				if (num <= 0.8f)
				{
					NavMeshHit val7 = default(NavMeshHit);
					if (!NavMesh.Raycast(((NavMeshHit)(ref val2)).position, ((NavMeshHit)(ref val6)).position, ref val7, -1))
					{
						return ChargeLine.Direct;
					}
					Vector3 val8 = ((NavMeshHit)(ref val6)).position - ((NavMeshHit)(ref val2)).position;
					val8.y = 0f;
					if (((NavMeshHit)(ref val7)).distance >= ((Vector3)(ref val8)).magnitude - 1f)
					{
						return ChargeLine.Direct;
					}
				}
				NavMeshPath val9 = new NavMeshPath();
				if (NavMesh.CalculatePath(((NavMeshHit)(ref val2)).position, ((NavMeshHit)(ref val6)).position, -1, val9) && (int)val9.status == 0)
				{
					return ChargeLine.Approach;
				}
				return ChargeLine.NoRoute;
			}
			catch (Exception ex)
			{
				ModLog.WarnThrottled("EvaluateChargeLine", "[Game] EvaluateChargeLine failed: " + ex.Message);
				return ChargeLine.Direct;
			}
		}

		public bool IsSpawnIdlePaused()
		{
			try
			{
				return SemiFunc.EnemySpawnIdlePause();
			}
			catch (Exception ex)
			{
				ModLog.WarnThrottled("IsSpawnIdlePaused", "[Game] IsSpawnIdlePaused failed: " + ex.Message);
				return false;
			}
		}

		public bool ShouldForceLeave(EnemyTemplateBehaviour enemy)
		{
			Enemy val = GameEnemy(enemy);
			if ((Object)(object)val == (Object)null || !SemiFunc.IsMasterClientOrSingleplayer())
			{
				return false;
			}
			try
			{
				return SemiFunc.EnemyForceLeave(val);
			}
			catch (Exception ex)
			{
				ModLog.WarnThrottled("ShouldForceLeave", "[Game] ShouldForceLeave failed: " + ex.Message);
				return false;
			}
		}

		public bool TryPickRoamDestination(EnemyTemplateBehaviour enemy, out Vec3 destination)
		{
			//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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_006c: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			destination = Vec3.Zero;
			if ((Object)(object)enemy == (Object)null)
			{
				return false;
			}
			try
			{
				Vector3 val = GetBodyPosition(enemy).ToUnity();
				Vector3 position = ((Component)enemy).transform.position;
				Vector3? val2 = null;
				Enemy val3 = GameEnemy(enemy);
				NavMeshHit val5 = default(NavMeshHit);
				for (int i = 0; i < 8; i++)
				{
					LevelPoint val4 = ((i < 4) ? SemiFunc.LevelPointGet(val, 5f, 15f) : null);
					if ((Object)(object)val4 == (Object)null)
					{
						val4 = SemiFunc.LevelPointGet(val, 0f, 999f);
					}
					if (!((Object)(object)val4 == (Object)null) && NavMesh.SamplePosition(((Component)val4).transform.position + Random.insideUnitSphere * 3f, ref val5, 5f, -1) && Physics.Raycast(((NavMeshHit)(ref val5)).position, Vector3.down, 5f, LayerMask.GetMask(new string[1] { "Default" })) && !((Object)(object)val3 == (Object)null) && TryGetPath(val3, ((NavMeshHit)(ref val5)).position, out var end, out var complete))
					{
						if (complete)
						{
							destination = ((NavMeshHit)(ref val5)).position.ToVec3();
							return true;
						}
						if (!val2.HasValue && Vector3.Distance(end, position) > 3f)
						{
							val2 = end;
						}
					}
				}
				if (val2.HasValue)
				{
					destination = val2.Value.ToVec3();
					return true;
				}
			}
			catch (Exception ex)
			{
				ModLog.WarnThrottled("TryPickRoamDestination", "[Game] TryPickRoamDestination failed: " + ex.Message);
			}
			return false;
		}

		public bool TryPickLeaveDestination(EnemyTemplateBehaviour enemy, out Vec3 destination)
		{
			//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_0033: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			destination = Vec3.Zero;
			Enemy val = GameEnemy(enemy);
			if ((Object)(object)val == (Object)null || !SemiFunc.IsMasterClientOrSingleplayer())
			{
				return false;
			}
			try
			{
				Vector3 val2 = GetBodyPosition(enemy).ToUnity();
				LevelPoint val3 = SemiFunc.LevelPointGetPlayerDistance(val2, 25f, 50f, false);
				if (!Object.op_Implicit((Object)(object)val3))
				{
					val3 = SemiFunc.LevelPointGetFurthestFromPlayer(val2, 5f);
				}
				bool result = false;
				if (Object.op_Implicit((Object)(object)val3))
				{
					destination = ((Component)val3).transform.position.ToVec3();
					result = true;
				}
				else
				{
					val.EnemyParent.SpawnedTimerSet(0f);
				}
				SemiFunc.EnemyLeaveStart(val);
				return result;
			}
			catch (Exception ex)
			{
				ModLog.WarnThrottled("TryPickLeaveDestination", "[Game] TryPickLeaveDestination failed: " + ex.Message);
				return false;
			}
		}

		public void WalkTo(EnemyTemplateBehaviour enemy, Vec3 destination, float speed)
		{
			//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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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)
			Enemy val = GameEnemy(enemy);
			if ((Object)(object)val == (Object)null || !val.HasNavMeshAgent || !SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			try
			{
				Vector3 val2 = destination.ToUnity();
				val.NavMeshAgent.SetDestination(TryProjectToNavMesh(val2, out var onNav) ? onNav : val2);
				if (speed > 0f)
				{
					val.NavMeshAgent.OverrideAgent(speed, speed * 3f, 0.25f);
				}
			}
			catch (Exception ex)
			{
				ModLog.WarnThrottled("WalkTo", "[Game] WalkTo failed: " + ex.Message);
			}
		}

		public void StopMoving(EnemyTemplateBehaviour enemy)
		{
			//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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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_0053: 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)
			Enemy val = GameEnemy(enemy);
			if ((Object)(object)val == (Object)null || !val.HasNavMeshAgent || !SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			try
			{
				Vector3 val2 = GetBodyPosition(enemy).ToUnity();
				NavMeshHit val3 = default(NavMeshHit);
				Vector3 destination = (NavMesh.SamplePosition(val2, ref val3, 3f, -1) ? ((NavMeshHit)(ref val3)).position : ((Component)enemy).transform.position);
				val.NavMeshAgent.SetDestination(destination);
			}
			catch (Exception ex)
			{
				ModLog.WarnThrottled("StopMoving", "[Game] StopMoving failed: " + ex.Message);
			}
		}

		public float GetNotMovingSeconds(EnemyTemplateBehaviour enemy)
		{
			EnemyRigidbody val = Body(enemy);
			if (!((Object)(object)val != (Object)null))
			{
				return 0f;
			}
			return val.notMovingTimer;
		}

		public void FaceDirection(EnemyTemplateBehaviour enemy, Vec3 direction, float maxDegreesPerSecond)
		{
			//IL_0018: 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_002f: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_0050: 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 (!((Object)(object)enemy == (Object)null) && SemiFunc.IsMasterClientOrSingleplayer())
			{
				Vector3 val = direction.Horizontal().ToUnity();
				if (!(((Vector3)(ref val)).sqrMagnitude < 0.0001f))
				{
					Quaternion val2 = Quaternion.LookRotation(((Vector3)(ref val)).normalized, Vector3.up);
					((Component)enemy).transform.rotation = Quaternion.RotateTowards(((Component)enemy).transform.rotation, val2, maxDegreesPerSecond * Time.deltaTime);
				}
			}
		}

		public Vec3 GetFacing(EnemyTemplateBehaviour enemy)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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)
			if ((Object)(object)enemy == (Object)null)
			{
				return new Vec3(0f, 0f, 1f);
			}
			Vector3 forward = ((Component)enemy).transform.forward;
			forward.y = 0f;
			if (!(((Vector3)(ref forward)).sqrMagnitude > 0.0001f))
			{
				return new Vec3(0f, 0f, 1f);
			}
			return ((Vector3)(ref forward)).normalized.ToVec3();
		}

		public void AlignAgentToBody(EnemyTemplateBehaviour enemy)
		{
			//IL_0039: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			Enemy val = GameEnemy(enemy);
			EnemyRigidbody val2 = Body(enemy);
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || !val.HasNavMeshAgent || !SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			try
			{
				NavMeshHit val3 = default(NavMeshHit);
				if (NavMesh.SamplePosition(((Component)val2).transform.position, ref val3, 3f, -1))
				{
					val.NavMeshAgent.Warp(((NavMeshHit)(ref val3)).position, true);
					val.NavMeshAgent.SetDestination(((NavMeshHit)(ref val3)).position);
				}
			}
			catch (Exception ex)
			{
				ModLog.WarnThrottled("AlignAgentToBody", "[Game] AlignAgentToBody failed: " + ex.Message);
			}
		}

		public void SuppressStuckJump(EnemyTemplateBehaviour enemy, float seconds)
		{
			Enemy val = GameEnemy(enemy);
			if ((Object)(object)val == (Object)null || !val.HasJump || (Object)(object)val.Jump == (Object)null || !SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			try
			{
				val.Jump.StuckDisable(seconds);
			}
			catch (Exception ex)
			{
				ModLog.WarnThrottled("SuppressStuckJump", "[Game] SuppressStuckJump failed: " + ex.Message);
			}
		}

		public void BeginCharge(EnemyTemplateBehaviour enemy)
		{
			AlignAgentToBody(enemy);
		}

		public void DriveCharge(EnemyTemplateBehaviour enemy, Vec3 direction, float speed)
		{
			//IL_007d: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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_0091: 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_00ad: 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)
			Enemy val = GameEnemy(enemy);
			EnemyRigidbody val2 = Body(enemy);
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || !SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			try
			{
				val2.DisableFollowPosition(0.15f, 10f);
				if (val.HasNavMeshAgent)
				{
					val.NavMeshAgent.Disable(0.15f);
				}
				Rigidbody rb = val2.rb;
				if (!((Object)(object)rb == (Object)null) && !rb.isKinematic)
				{
					Vector3 val3 = direction.Horizontal().Normalized().ToUnity() * speed;
					Vector3 linearVelocity = rb.linearVelocity;
					float num = Mathf.Min(linearVelocity.y, 2f);
					rb.linearVelocity = new Vector3(val3.x, num, val3.z);
				}
			}
			catch (Exception ex)
			{
				ModLog.WarnThrottled("DriveCharge", "[Game] DriveCharge failed: " + ex.Message);
			}
		}

		public void EndCharge(EnemyTemplateBehaviour enemy, Vec3 bounceVelocity)
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_0055: 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_00c4: 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)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			Enemy val = GameEnemy(enemy);
			EnemyRigidbody val2 = Body(enemy);
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || !SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			try
			{
				if (val.HasNavMeshAgent)
				{
					NavMeshHit val3 = default(NavMeshHit);
					if (NavMesh.SamplePosition(((Component)val2).transform.position, ref val3, 3f, -1))
					{
						((Component)val).transform.position = ((NavMeshHit)(ref val3)).position;
					}
					val.NavMeshAgent.Enable();
				}
				AlignAgentToBody(enemy);
				Vector3 val4 = bounceVelocity.ToUnity();
				if (((Vector3)(ref val4)).sqrMagnitude > 0.0001f && (Object)(object)val2.rb != (Object)null && !val2.rb.isKinematic)
				{
					val2.DisableFollowPosition(0.35f, 5f);
					Vector3 linearVelocity = val2.rb.linearVelocity;
					val2.rb.linearVelocity = new Vector3(val4.x, Mathf.Min(linearVelocity.y, 2f), val4.z);
				}
			}
			catch (Exception ex)
			{
				ModLog.WarnThrottled("EndCharge", "[Game] EndCharge failed: " + ex.Message);
			}
		}

		public void QueueHitKnockback(EnemyTemplateBehaviour enemy, Vec3 velocity, float minStunSeconds)
		{
			//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)
			Enemy val = GameEnemy(enemy);
			if ((Object)(object)val == (Object)null || !SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			try
			{
				_pendingStunSeconds = minStunSeconds;
				_pendingKnockback = velocity.ToUnity();
				_pendingKnockbackExpire = Time.time + 1f;
				_hasPendingKnockback = true;
			}
			catch (Exception ex)
			{
				ModLog.WarnThrottled("QueueHitKnockback", "[Game] QueueHitKnockback failed: " + ex.Message);
			}
		}

		public void ApplyPendingHitKnockback(EnemyTemplateBehaviour enemy)
		{
			//IL_00c6: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			if (!_hasPendingKnockback)
			{
				return;
			}
			if (Time.time > _pendingKnockbackExpire)
			{
				_hasPendingKnockback = false;
				return;
			}
			Enemy val = GameEnemy(enemy);
			EnemyRigidbody val2 = Body(enemy);
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || !SemiFunc.IsMasterClientOrSingleplayer())
			{
				_hasPendingKnockback = false;
			}
			else
			{
				if (val.FreezeTimer > 0f)
				{
					return;
				}
				_hasPendingKnockback = false;
				try
				{
					Rigidbody rb = val2.rb;
					if (!((Object)(object)rb == (Object)null) && !rb.isKinematic)
					{
						if (val.HasStateStunned && (Object)(object)val.StateStunned != (Object)null && _pendingStunSeconds > 0f)
						{
							val.StateStunned.Set(_pendingStunSeconds);
						}
						val2.DisableFollowPosition(0.6f, 5f);
						Vector3 linearVelocity = rb.linearVelocity;
						rb.linearVelocity = new Vector3(_pendingKnockback.x, Mathf.Max(linearVelocity.y, _pendingKnockback.y), _pendingKnockback.z);
					}
				}
				catch (Exception ex)
				{
					ModLog.WarnThrottled("ApplyPendingHitKnockback", "[Game] ApplyPendingHitKnockback failed: " + ex.Message);
				}
			}
		}

		public void ApplyImpulse(IKnockbackTarget target, Vec3 impulse)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			if (!SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			try
			{
				if (target is PlayerTarget playerTarget && (Object)(object)playerTarget.Avatar != (Object)null)
				{
					PlayerTumble tumble = playerTarget.Avatar.tumble;
					if ((Object)(object)tumble != (Object)null)
					{
						tumble.TumbleRequest(true, false);
						tumble.TumbleOverrideTime(1f);
						tumble.TumbleForce(impulse.ToUnity());
						tumble.OverrideEnemyHurt(0.6f);
					}
				}
			}
			catch (Exception ex)
			{
				ModLog.WarnThrottled("ApplyImpulse", "[Game] ApplyImpulse failed: " + ex.Message);
			}
		}

		public void DealContactDamage(EnemyTemplateBehaviour enemy, IKnockbackTarget target, int amount)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			if (amount <= 0 || !SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			try
			{
				if (target is PlayerTarget playerTarget && (Object)(object)playerTarget.Avatar != (Object)null)
				{
					PlayerHealth playerHealth = playerTarget.Avatar.playerHealth;
					if (!((Object)(object)playerHealth == (Object)null))
					{
						Enemy val = GameEnemy(enemy);
						int num = (((Object)(object)val != (Object)null) ? SemiFunc.EnemyGetIndex(val) : (-1));
						playerHealth.HurtOther(amount, Vector3.zero, true, num, false);
					}
				}
			}
			catch (Exception ex)
			{
				ModLog.WarnThrottled("DealContactDamage", "[Game] DealContactDamage failed: " + ex.Message);
			}
		}

		public void HoldInPlace(EnemyTemplateBehaviour enemy, float seconds)
		{
			Enemy val = GameEnemy(enemy);
			EnemyRigidbody val2 = Body(enemy);
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				return;
			}
			try
			{
				if ((Object)(object)val2.physGrabObject != (Object)null)
				{
					val2.physGrabObject.OverrideGrabDisable(seconds);
				}
				if (SemiFunc.IsMasterClientOrSingleplayer())
				{
					if ((Object)(object)val2.physGrabObject != (Object)null && val2.physGrabObject.playerGrabbing.Count > 0)
					{
						val2.GrabRelease(false, seconds);
					}
					if (val.FreezeTimer < seconds * 0.5f)
					{
						val.Freeze(seconds);
					}
				}
			}
			catch (Exception ex)
			{
				ModLog.WarnThrottled("HoldInPlace", "[Game] HoldInPlace failed: " + ex.Message);
			}
		}

		public Vec3 GetPathDirection(EnemyTemplateBehaviour enemy, Vec3 destination)
		{
			//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_000e: 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)
			//IL_0014: 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_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_0028: 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_0032: 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_010c: 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_004e: 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_008a: 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_0094: 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)
			Vector3 val = GetBodyPosition(enemy).ToUnity();
			Vector3 val2 = destination.ToUnity();
			Vector3 val3 = val2 - val;
			val3.y = 0f;
			try
			{
				if (TryProjectToNavMesh(val2, out var onNav))
				{
					val2 = onNav;
				}
				NavMeshHit val4 = default(NavMeshHit);
				if (NavMesh.SamplePosition(val, ref val4, 3f, -1) && NavMesh.CalculatePath(((NavMeshHit)(ref val4)).position, val2, -1, _pathBuffer) && _pathBuffer.corners.Length >= 2)
				{
					Vector3[] corners = _pathBuffer.corners;
					for (int i = 1; i < corners.Length; i++)
					{
						Vector3 val5 = corners[i] - ((NavMeshHit)(ref val4)).position;
						val5.y = 0f;
						if (((Vector3)(ref val5)).sqrMagnitude > 0.04f)
						{
							return ((Vector3)(ref val5)).normalized.ToVec3();
						}
					}
				}
			}
			catch (Exception ex)
			{
				Exception ex2 = ex;
				Exception ex3 = ex2;
				ModLog.Debug(() => "[Game] GetPathDirection failed: " + ex3.Message);
			}
			if (!(((Vector3)(ref val3)).sqrMagnitude > 0.0001f))
			{
				return Vec3.Zero;
			}
			return ((Vector3)(ref val3)).normalized.ToVec3();
		}

		public void SetRespawnDelay(EnemyTemplateBehaviour enemy, float seconds)
		{
			if (!((Object)(object)enemy == (Object)null) && SemiFunc.IsMasterClientOrSingleplayer())
			{
				EnemyParent componentInParent = ((Component)enemy).GetComponentInParent<EnemyParent>();
				if ((Object)(object)componentInParent != (Object)null)
				{
					componentInParent.DespawnedTimer = Mathf.Max(1f, seconds);
				}
			}
		}

		public void RequestDespawn(EnemyTemplateBehaviour enemy)
		{
			if ((Object)(object)enemy == (Object)null || !SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			try
			{
				EnemyParent componentInParent = ((Component)enemy).GetComponentInParent<EnemyParent>();
				if ((Object)(object)componentInParent != (Object)null)
				{
					componentInParent.Despawn();
				}
			}
			catch (Exception ex)
			{
				ModLog.Warn("[Game] RequestDespawn failed: " + ex.Message);
			}
		}

		public void CancelDespawnRequest(EnemyTemplateBehaviour enemy)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Invalid comparison between Unknown and I4
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			Enemy val = GameEnemy(enemy);
			if (!((Object)(object)val == (Object)null) && SemiFunc.IsMasterClientOrSingleplayer() && (int)val.CurrentState == 11)
			{
				val.CurrentState = (EnemyState)2;
			}
		}

		public bool HookDeath(EnemyTemplateBehaviour enemy, Action onDeath)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			if (_deathHooked)
			{
				return true;
			}
			if ((Object)(object)enemy == (Object)null || onDeath == null)
			{
				return false;
			}
			try
			{
				EnemyHealth val = ((Component)enemy).GetComponent<EnemyHealth>();
				if ((Object)(object)val == (Object)null)
				{
					val = FindInOwnEnemy<EnemyHealth>((Component)(object)enemy);
				}
				if ((Object)(object)val == (Object)null)
				{
					ModLog.Warn("[Game] HookDeath: EnemyHealth not found");
					return false;
				}
				val.onDeath.AddListener((UnityAction)delegate
				{
					onDeath();
				});
				_deathHooked = true;
				return true;
			}
			catch (Exception ex)
			{
				ModLog.Warn("[Game] HookDeath failed: " + ex.Message);
				return false;
			}
		}

		public int MuteLegacyAiEvents(EnemyTemplateBehaviour enemy, Type legacyAiType)
		{
			if ((Object)(object)enemy == (Object)null || legacyAiType == null)
			{
				return 0;
			}
			int muted = 0;
			try
			{
				EnemyVision val = FindInOwnEnemy<EnemyVision>((Component)(object)enemy);
				EnemyStateInvestigate val2 = FindInOwnEnemy<EnemyStateInvestigate>((Component)(object)enemy);
				EnemyRigidbody val3 = FindInOwnEnemy<EnemyRigidbody>((Component)(object)enemy);
				EnemyHealth val4 = FindInOwnEnemy<EnemyHealth>((Component)(object)enemy);
				if ((Object)(object)val != (Object)null)
				{
					Mute((UnityEventBase?)(object)val.onVisionTriggered);
				}
				if ((Object)(object)val2 != (Object)null)
				{
					Mute((UnityEventBase?)(object)val2.onInvestigateTriggered);
				}
				if ((Object)(object)val3 != (Object)null)
				{
					Mute((UnityEventBase?)(object)val3.onGrabbed);
					Mute((UnityEventBase?)(object)val3.onTouchPlayer);
					Mute((UnityEventBase?)(object)val3.onTouchPlayerGrabbedObject);
				}
				if ((Object)(object)val4 != (Object)null)
				{
					Mute((UnityEventBase?)(object)val4.onHurt);
				}
			}
			catch (Exception ex)
			{
				ModLog.Warn("[Game] MuteLegacyAiEvents failed: " + ex.Message);
			}
			return muted;
			void Mute(UnityEventBase? ev)
			{
				if (ev != null)
				{
					for (int i = 0; i < ev.GetPersistentEventCount(); i++)
					{
						Object persistentTarget = ev.GetPersistentTarget(i);
						if (persistentTarget != (Object)null && legacyAiType.IsInstanceOfType(persistentTarget))
						{
							ev.SetPersistentListenerState(i, (UnityEventCallState)0);
							muted++;
						}
					}
				}
			}
		}

		public void OverrideBodyFollow(EnemyTemplateBehaviour enemy, float maxSpeed, float turnSpeed)
		{
			if ((Object)(object)enemy == (Object)null || !SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			EnemyRigidbody val = Body(enemy);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			try
			{
				val.OverrideFollowPosition(0.2f, maxSpeed, -1f);
				if (turnSpeed > 0f)
				{
					val.OverrideFollowRotation(0.2f, turnSpeed);
				}
			}
			catch (Exception ex)
			{
				ModLog.WarnThrottled("OverrideBodyFollow", "[Game] OverrideBodyFollow failed: " + ex.Message);
			}
		}

		public float GetTargetHorizontalSpeed(ITarget target)
		{
			//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)
			try
			{
				if (target is PlayerTarget playerTarget && (Object)(object)playerTarget.Avatar != (Object)null)
				{
					Vector3 rbVelocityRaw = playerTarget.Avatar.rbVelocityRaw;
					rbVelocityRaw.y = 0f;
					return ((Vector3)(ref rbVelocityRaw)).magnitude;
				}
			}
			catch (Exception ex)
			{
				ModLog.WarnOnce("GetTargetHorizontalSpeed", "[Game] GetTargetHorizontalSpeed failed: " + ex.Message);
			}
			return 0f;
		}

		public bool HookHurt(EnemyTemplateBehaviour enemy, Action onHurt)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			if (_hurtHooked)
			{
				return true;
			}
			if ((Object)(object)enemy == (Object)null || onHurt == null)
			{
				return false;
			}
			try
			{
				EnemyHealth val = ((Component)enemy).GetComponent<EnemyHealth>() ?? FindInOwnEnemy<EnemyHealth>((Component)(object)enemy);
				if ((Object)(object)val == (Object)null)
				{
					ModLog.Warn("[" + EnemyTag(enemy) + "] HookHurt: EnemyHealth not found");
					return false;
				}
				val.onHurt.AddListener((UnityAction)delegate
				{
					onHurt();
				});
				_hurtHooked = true;
				return true;
			}
			catch (Exception ex)
			{
				ModLog.Warn("[Game] HookHurt failed: " + ex.Message);
				return false;
			}
		}

		public bool HookImpacts(EnemyTemplateBehaviour enemy, Action<int> onImpact)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Expected O, but got Unknown
			if (_impactsHooked)
			{
				return true;
			}
			if ((Object)(object)enemy == (Object)null || onImpact == null)
			{
				return false;
			}
			try
			{
				EnemyRigidbody val = Body(enemy);
				PhysGrabObjectImpactDetector val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<PhysGrabObjectImpactDetector>() : null);
				if ((Object)(object)val2 == (Object)null)
				{
					ModLog.Warn("[Game] HookImpacts: impact detector not found");
					return false;
				}
				val2.onBreakLight.AddListener((UnityAction)delegate
				{
					onImpact(1);
				});
				val2.onBreakMedium.AddListener((UnityAction)delegate
				{
					onImpact(2);
				});
				val2.onBreakHeavy.AddListener((UnityAction)delegate
				{
					onImpact(3);
				});
				_impactsHooked = true;
				return true;
			}
			catch (Exception ex)
			{
				ModLog.Warn("[Game] HookImpacts failed: " + ex.Message);
				return false;
			}
		}

		public string GetLocaleCode()
		{
			try
			{
				if (!_localeLookupResolved)
				{
					_localeLookupResolved = true;
					_localeGetCode = typeof(SemiFunc).GetMethod("LocaleGetCode", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null);
					if (_localeGetCode == null)
					{
						ModLog.Warn("[Game] SemiFunc.LocaleGetCode not found; fallback to Unity Localization");
					}
				}
				string text = ((_localeGetCode != null) ? (_localeGetCode.Invoke(null, null) as string) : UnityLocaleCode());
				return string.IsNullOrEmpty(text) ? "en" : text;
			}
			catch (Exception ex)
			{
				ModLog.WarnOnce("GetLocaleCode", "[Game] GetLocaleCode failed: " + ex.Message);
				return "en";
			}
		}

		private static string EnemyTag(EnemyTemplateBehaviour enemy)
		{
			if (!(((object)enemy).GetType().Name == "ShifterEnemyBehaviour"))
			{
				return "Beigoma";
			}
			return "Shifter";
		}

		private static string? UnityLocaleCode()
		{
			object obj = Type.GetType("UnityEngine.Localization.Settings.LocalizationSettings, Unity.Localization")?.GetProperty("SelectedLocale")?.GetValue(null);
			object obj2 = obj?.GetType().GetProperty("Identifier")?.GetValue(obj);
			return obj2?.GetType().GetProperty("Code")?.GetValue(obj2) as string;
		}

		public void SetDisplayName(EnemyTemplateBehaviour enemy, string name)
		{
			Enemy val = GameEnemy(enemy);
			if (!((Object)(object)val == (Object)null) && !((Object)(object)val.EnemyParent == (Object)null))
			{
				val.EnemyParent.enemyNameLocalized = null;
				val.EnemyParent.enemyName = name;
			}
		}

		public bool HookSpawn(EnemyTemplateBehaviour enemy, Action onSpawn)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			if (_spawnHooked)
			{
				return true;
			}
			EnemyStateSpawn val = FindInOwnEnemy<EnemyStateSpawn>((Component)(object)enemy);
			if ((Object)(object)val == (Object)null || onSpawn == null)
			{
				return false;
			}
			val.OnSpawn.AddListener((UnityAction)delegate
			{
				onSpawn();
			});
			_spawnHooked = true;
			return true;
		}

		public void SpawnTeleport(EnemyTemplateBehaviour enemy)
		{
			Enemy val = GameEnemy(enemy);
			if ((Object)(object)val == (Object)null || !SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			try
			{
				SemiFunc.EnemySpawn(val);
			}
			catch (Exception ex)
			{
				ModLog.Warn("[Game] SpawnTeleport failed: " + ex.Message);
			}
		}

		public void DeathEffectsAndDespawn(EnemyTemplateBehaviour enemy, string[]? particleNames = null, Color? debrisColor = null)
		{
			//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_0046: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			Enemy val = GameEnemy(enemy);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			try
			{
				Vector3 val2 = GetBodyPosition(enemy).ToUnity();
				if ((Object)(object)GameDirector.instance != (Object)null)
				{
					GameDirector.instance.CameraShake.ShakeDistance(3f, 3f, 8f, val2, 0.5f);
					GameDirector.instance.CameraImpact.ShakeDistance(3f, 3f, 8f, val2, 0.1f);
				}
				Transform root = EnemyRoot((Component)(object)enemy);
				string[] array = particleNames ?? DeathParticleNames;
				foreach (string text in array)
				{
					Transform val3 = root.FindDeep(text);
					ParticleSystem val4 = (((Object)(object)val3 != (Object)null) ? ((Component)val3).GetComponent<ParticleSystem>() : null);
					if ((Object)(object)val4 != (Object)null)
					{
						if (debrisColor.HasValue && text.Contains("Bits"))
						{
							DebrisTint.Apply(val4, debrisColor.Value);
						}
						if (particleNames != null)
						{
							((Component)val4).transform.position = val2;
						}
						if (text == "Directional Bits" && val.HasHealth && ((Vector3)(ref val.Health.hurtDirection)).sqrMagnitude > 0.0001f)
						{
							((Component)val4).transform.rotation = Quaternion.LookRotation(-((Vector3)(ref val.Health.hurtDirection)).normalized);
						}
						val4.Play();
					}
				}
			}
			catch (Exception ex)
			{
				ModLog.Warn("[Game] DeathEffects failed: " + ex.Message);
			}
			if (SemiFunc.IsMasterClientOrSingleplayer() && (Object)(object)val.EnemyParent != (Object)null)
			{
				val.EnemyParent.Despawn();
			}
		}

		public int GetTargetId(object target)
		{
			if (!(target is PlayerTarget playerTarget) || !((Object)(object)playerTarget.Avatar != (Object)null))
			{
				return -1;
			}
			return ((Object)playerTarget.Avatar).GetInstanceID();
		}

		public bool IsHost()
		{
			return SemiFunc.IsMasterClientOrSingleplayer();
		}

		public bool IsMultiplayer()
		{
			return SemiFunc.IsMultiplayer();
		}

		public bool SendRpc(Component owner, string method, bool includeSelf, params object[] args)
		{
			if ((Object)(object)owner == (Object)null || !SemiFunc.IsMultiplayer())
			{
				return false;
			}
			try
			{
				PhotonView component = owner.GetComponent<PhotonView>();
				if ((Object)(object)component == (Object)null)
				{
					if (!_rpcWarned)
					{
						_rpcWarned = true;
						ModLog.Warn("[Game] RPC '" + method + "' not sent: no PhotonView on '" + ((Object)owner.gameObject).name + "' (ability components must be attached to the Controller object)");
					}
					return