Decompiled source of The Scout Leader Chases After v2.0.0

TheScoutLeaderChasesAfter.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("mod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("mod")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("bfab371c-efc3-450d-8d08-3382acb60bf8")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SeekerScoutmaster;

[BepInPlugin("com.spacerats.thescoutleaderchasesafter", "The Scout Leader Chases After", "2.0.0")]
public class ScoutmasterSpawnerPlugin : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <ChaseRoutine>d__11 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public GameObject scoutmasterObj;

		public ScoutmasterSpawnerPlugin <>4__this;

		public Character target;

		private Component <scoutComp>5__2;

		private MethodInfo <setTargetMethod>5__3;

		private MethodInfo <lookAtMethod>5__4;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <ChaseRoutine>d__11(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<scoutComp>5__2 = null;
			<setTargetMethod>5__3 = null;
			<lookAtMethod>5__4 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_00d1: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Expected O, but got Unknown
			int num = <>1__state;
			ScoutmasterSpawnerPlugin scoutmasterSpawnerPlugin = <>4__this;
			switch (num)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = (object)new WaitForSeconds(1f);
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				if ((Object)(object)scoutmasterObj == (Object)null)
				{
					return false;
				}
				<scoutComp>5__2 = scoutmasterObj.GetComponent("Scoutmaster");
				if ((Object)(object)<scoutComp>5__2 == (Object)null)
				{
					return false;
				}
				scoutmasterSpawnerPlugin.InitializeAIParameters(<scoutComp>5__2);
				<setTargetMethod>5__3 = ((object)<scoutComp>5__2).GetType().GetMethod("SetCurrentTarget", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				<lookAtMethod>5__4 = ((object)<scoutComp>5__2).GetType().GetMethod("LookAt", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				break;
			case 2:
				<>1__state = -1;
				break;
			}
			if ((Object)(object)scoutmasterObj != (Object)null && (Object)(object)target != (Object)null)
			{
				Vector3 realWorldPosition = scoutmasterSpawnerPlugin.GetRealWorldPosition(target);
				float num2 = Vector3.Distance(realWorldPosition, scoutmasterObj.transform.position);
				if (!(num2 > scoutmasterSpawnerPlugin.configDespawnDist.Value))
				{
					<setTargetMethod>5__3?.Invoke(<scoutComp>5__2, new object[2] { target, 999f });
					<lookAtMethod>5__4?.Invoke(<scoutComp>5__2, new object[1] { realWorldPosition });
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 2;
					return true;
				}
				((BaseUnityPlugin)scoutmasterSpawnerPlugin).Logger.LogInfo((object)$"玩家成功逃脱 ({num2:F1}m)。");
			}
			if ((Object)(object)scoutmasterObj != (Object)null)
			{
				PhotonNetwork.Destroy(scoutmasterObj);
			}
			scoutmasterSpawnerPlugin.currentScoutmaster = null;
			return false;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	private ConfigEntry<KeyCode> configF10Key;

	private ConfigEntry<float> configSpawnInterval;

	private ConfigEntry<float> configMinSpawnDist;

	private ConfigEntry<float> configMaxSpawnDist;

	private ConfigEntry<float> configDespawnDist;

	private float spawnTimer;

	private GameObject currentScoutmaster;

	private Coroutine chaseCoroutine;

	private void Awake()
	{
		configF10Key = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "F10KeyBinding", (KeyCode)291, "手动刷新的按键绑定");
		configSpawnInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Timings", "SpawnIntervalSeconds", 180f, "首领销毁后重新生成的间隔时间(秒)");
		configMinSpawnDist = ((BaseUnityPlugin)this).Config.Bind<float>("Distance", "MinSpawnDistance", 35f, "最小生成距离");
		configMaxSpawnDist = ((BaseUnityPlugin)this).Config.Bind<float>("Distance", "MaxSpawnDistance", 40f, "最大生成距离");
		configDespawnDist = ((BaseUnityPlugin)this).Config.Bind<float>("Distance", "DespawnDistance", 75f, "逃脱(销毁)距离");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"The Scout Leader Chases After v2.0.0: 配置文件已重命名并载入成功。");
	}

	private void Update()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKeyDown(configF10Key.Value))
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"手动按键触发:强制重置首领。");
			SpawnScoutmaster();
			spawnTimer = configSpawnInterval.Value;
		}
		if (PhotonNetwork.IsMasterClient && (Object)(object)currentScoutmaster == (Object)null)
		{
			spawnTimer -= Time.deltaTime;
			if (spawnTimer <= 0f)
			{
				SpawnScoutmaster();
				spawnTimer = configSpawnInterval.Value;
			}
		}
	}

	private void SpawnScoutmaster()
	{
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		if (!PhotonNetwork.IsConnected || !PhotonNetwork.InRoom)
		{
			return;
		}
		Character lowestCharacter = GetLowestCharacter();
		if ((Object)(object)lowestCharacter == (Object)null)
		{
			return;
		}
		if ((Object)(object)currentScoutmaster != (Object)null)
		{
			PhotonNetwork.Destroy(currentScoutmaster);
			if (chaseCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(chaseCoroutine);
			}
			currentScoutmaster = null;
		}
		Vector3 realWorldPosition = GetRealWorldPosition(lowestCharacter);
		Vector3 val = CalculateSpawnPosition(realWorldPosition, lowestCharacter);
		currentScoutmaster = PhotonNetwork.InstantiateRoomObject("Character_Scoutmaster", val, Quaternion.identity, (byte)0, (object[])null);
		chaseCoroutine = ((MonoBehaviour)this).StartCoroutine(ChaseRoutine(currentScoutmaster, lowestCharacter));
		((BaseUnityPlugin)this).Logger.LogInfo((object)("新首领已在玩家 " + ((Object)lowestCharacter).name + " 附近生成。"));
	}

	[IteratorStateMachine(typeof(<ChaseRoutine>d__11))]
	private IEnumerator ChaseRoutine(GameObject scoutmasterObj, Character target)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <ChaseRoutine>d__11(0)
		{
			<>4__this = this,
			scoutmasterObj = scoutmasterObj,
			target = target
		};
	}

	private Vector3 CalculateSpawnPosition(Vector3 playerPos, Character target)
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		RaycastHit val = default(RaycastHit);
		for (int i = 0; i < 20; i++)
		{
			float num = Random.Range(0f, 360f) * ((float)Math.PI / 180f);
			float num2 = Random.Range(configMinSpawnDist.Value, configMaxSpawnDist.Value);
			if (Physics.Raycast(new Vector3(playerPos.x + Mathf.Cos(num) * num2, playerPos.y + 15f, playerPos.z + Mathf.Sin(num) * num2), Vector3.down, ref val, 200f) && ((RaycastHit)(ref val)).point.y < playerPos.y + 5f)
			{
				return ((RaycastHit)(ref val)).point + new Vector3(0f, 1.2f, 0f);
			}
		}
		return playerPos - ((Component)target).transform.forward * configMinSpawnDist.Value - new Vector3(0f, 10f, 0f);
	}

	private void InitializeAIParameters(Component scoutComp)
	{
		FieldInfo[] fields = ((object)scoutComp).GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		foreach (FieldInfo fieldInfo in fields)
		{
			string text = fieldInfo.Name.ToLower();
			if ((text.Contains("dist") || text.Contains("range") || text.Contains("view") || text.Contains("sense")) && fieldInfo.FieldType == typeof(float))
			{
				try
				{
					fieldInfo.SetValue(scoutComp, 500f);
				}
				catch
				{
				}
			}
			if ((text.Contains("hunt") || text.Contains("active")) && fieldInfo.FieldType == typeof(bool))
			{
				fieldInfo.SetValue(scoutComp, true);
			}
		}
	}

	private Vector3 GetRealWorldPosition(Character c)
	{
		//IL_0009: 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_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)c == (Object)null)
		{
			return Vector3.zero;
		}
		SkinnedMeshRenderer componentInChildren = ((Component)c).GetComponentInChildren<SkinnedMeshRenderer>();
		if ((Object)(object)componentInChildren != (Object)null)
		{
			Bounds bounds = ((Renderer)componentInChildren).bounds;
			return ((Bounds)(ref bounds)).center;
		}
		return ((Component)c).transform.position;
	}

	private Character GetLowestCharacter()
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		if (PhotonNetwork.PlayerList == null)
		{
			return null;
		}
		Character result = null;
		float num = float.MaxValue;
		Player[] playerList = PhotonNetwork.PlayerList;
		Character val = default(Character);
		for (int i = 0; i < playerList.Length; i++)
		{
			if (PlayerHandler.TryGetCharacter(playerList[i].ActorNumber, ref val) && (Object)(object)val != (Object)null)
			{
				float y = GetRealWorldPosition(val).y;
				if (y < num && y > -100f)
				{
					num = y;
					result = val;
				}
			}
		}
		return result;
	}
}