Decompiled source of SeekerScoutmaster v1.0.2

plugins/Spacerats-SeekerScoutmaster/SeekerScoutmaster.dll

Decompiled 3 days ago
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Runner")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Runner")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f6f5b18b-682d-408a-bffc-efbdcadb468f")]
[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.seekerscoutmaster", "Seeker Scoutmaster", "1.0.2")]
public class ScoutmasterSpawnerPlugin : BaseUnityPlugin
{
	private float forcedChaseDuration = 240f;

	private float spawnInterval = 300f;

	private float spawnTimer;

	private void Start()
	{
		spawnTimer = spawnInterval;
	}

	private void Update()
	{
		if (Input.GetKeyDown((KeyCode)286))
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"F5 pressed — forcing Scoutmaster to chase a random player!");
			SpawnScoutmasterNearRandomPlayer();
		}
		if (PhotonNetwork.IsMasterClient)
		{
			spawnTimer -= Time.deltaTime;
			if (spawnTimer <= 0f)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Spawning Scoutmaster due to 5-minute timer.");
				SpawnScoutmasterNearRandomPlayer();
				spawnTimer = spawnInterval;
			}
		}
	}

	private void SpawnScoutmasterNearRandomPlayer()
	{
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		if (!PhotonNetwork.IsConnected || !PhotonNetwork.InRoom)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"Not connected to Photon room, cannot spawn Scoutmaster.");
			return;
		}
		if (!PhotonNetwork.IsMasterClient)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"Only the Master Client can spawn Scoutmaster.");
			return;
		}
		Player[] playerList = PhotonNetwork.PlayerList;
		if (playerList.Length == 0)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"No players in the room.");
			return;
		}
		Player val = playerList[Random.Range(0, playerList.Length)];
		Character val2 = default(Character);
		if (!PlayerHandler.TryGetCharacter(val.ActorNumber, ref val2))
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Target player character not found for player " + val.NickName + "."));
			return;
		}
		Vector3 val3 = default(Vector3);
		((Vector3)(ref val3))..ctor(Random.Range(-3f, 3f), 0f, Random.Range(-3f, 3f));
		Vector3 val4 = ((Component)val2).transform.position + val3;
		Quaternion identity = Quaternion.identity;
		GameObject scoutmasterObj = PhotonNetwork.InstantiateRoomObject("Character_Scoutmaster", val4, identity, (byte)0, (object[])null);
		((BaseUnityPlugin)this).Logger.LogInfo((object)("Spawned Scoutmaster near player " + val.NickName + "."));
		((MonoBehaviour)this).StartCoroutine(StartChasingNextFrame(scoutmasterObj, val2));
	}

	private IEnumerator StartChasingNextFrame(GameObject scoutmasterObj, Character target)
	{
		yield return null;
		((MonoBehaviour)this).StartCoroutine(KeepChasing(scoutmasterObj, target));
	}

	private IEnumerator KeepChasing(GameObject scoutmasterObj, Character target)
	{
		Component scoutmasterComp = scoutmasterObj.GetComponent("Scoutmaster");
		if ((Object)(object)scoutmasterComp == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"Scoutmaster component not found.");
			yield break;
		}
		MethodInfo setTargetMethod = ((object)scoutmasterComp).GetType().GetMethod("SetCurrentTarget", BindingFlags.Instance | BindingFlags.NonPublic);
		if (setTargetMethod == null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"SetCurrentTarget method not found.");
			yield break;
		}
		while (true)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Refreshing chase on target Character [{target.characterName} : ViewID {((MonoBehaviourPun)target).photonView.ViewID}].");
			setTargetMethod.Invoke(scoutmasterComp, new object[2] { null, 0f });
			yield return (object)new WaitForSeconds(0.1f);
			setTargetMethod.Invoke(scoutmasterComp, new object[2] { target, forcedChaseDuration });
			yield return (object)new WaitForSeconds(forcedChaseDuration - 2f);
		}
	}
}