Decompiled source of MoreScouts v0.3.1

MoreScouts.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using TMPro;
using UnityEngine;
using Zorro.Core;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("MoreScouts")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Mod for more Players in PEAK")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyInformationalVersion("0.0.1+d9418b14b8b8eb650054a64c9650b262494901d5")]
[assembly: AssemblyProduct("MoreScouts")]
[assembly: AssemblyTitle("MoreScouts")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MaxPlayersPatch
{
	[BepInPlugin("com.coddingcat.maxplayerspatch", "Max Players Patch", "1.0.0")]
	public class MaxPlayersPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Campfire), "Awake")]
		public static class Patch_Campfire_Awake_MarshmallowSpawner
		{
			private static readonly HashSet<Vector3> handledCampfires = new HashSet<Vector3>();

			private static void Postfix(Campfire __instance)
			{
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: 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_0051: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				if (PhotonNetwork.IsMasterClient && PlayerHandler.GetAllPlayers().Count >= 5)
				{
					Vector3 position = ((Component)__instance).transform.position;
					if (!handledCampfires.Contains(position))
					{
						handledCampfires.Add(position);
						Debug.Log((object)$"Spawning marshmallow for campfire at {position}");
						SpawnMarshmallows(PlayerHandler.GetAllPlayers().Count - 4, position);
					}
				}
			}
		}

		private ConfigEntry<int> maxPlayersConfig;

		private void Awake()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			maxPlayersConfig = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaxPlayers", 20, "Sets the maximum number of players allowed on the server.");
			Harmony val = new Harmony("com.coddingcat.maxplayerspatch");
			val.PatchAll();
			SetMaxPlayers(maxPlayersConfig.Value);
		}

		private static void SpawnMarshmallows(int number, Vector3 campfirePosition)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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)
			ItemDatabase instance = SingletonAsset<ItemDatabase>.Instance;
			if (!instance.itemLookup.TryGetValue(46, out var value))
			{
				Debug.LogError((object)"Version is Incompatible to spawn marshmallows");
				return;
			}
			float innerRadius = 1f;
			float outerRadius = 2f;
			List<Vector3> pointsAroundCampfire = GetPointsAroundCampfire(number, innerRadius, outerRadius, campfirePosition);
			foreach (Vector3 item in pointsAroundCampfire)
			{
				AddItemToWorld(value, item);
			}
		}

		private static void AddItemToWorld(Item item, Vector3 position)
		{
			//IL_001b: 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)
			if (PhotonNetwork.IsConnected)
			{
				PhotonNetwork.Instantiate("0_Items/" + ((Object)item).name, position, Quaternion.Euler(0f, Random.Range(0f, 360f), 0f), (byte)0, (object[])null);
			}
		}

		private static List<Vector3> GetPointsAroundCampfire(int numPoints, float innerRadius, float outerRadius, Vector3 campfirePosition)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_0058: 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)
			List<Vector3> list = new List<Vector3>();
			for (int i = 0; i < numPoints; i++)
			{
				float num = Mathf.Sqrt(Random.Range(innerRadius * innerRadius, outerRadius * outerRadius));
				float num2 = Random.Range(0f, (float)Math.PI * 2f);
				float num3 = Mathf.Cos(num2) * num;
				float num4 = Mathf.Sin(num2) * num;
				Vector3 toGround = new Vector3(num3, 0f, num4) + campfirePosition;
				list.Add(SetToGround(toGround));
			}
			return list;
		}

		private static Vector3 SetToGround(Vector3 position)
		{
			//IL_0001: 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_000d: 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)
			return HelperFunctions.GetGroundPos(position, (LayerType)2, 0f);
		}

		private void SetMaxPlayers(int newMax)
		{
			try
			{
				Type typeFromHandle = typeof(NetworkConnector);
				FieldInfo field = typeFromHandle.GetField("MAX_PLAYERS", BindingFlags.Static | BindingFlags.Public);
				if (field != null)
				{
					field.SetValue(null, newMax);
					((BaseUnityPlugin)this).Logger.LogDebug((object)$"Player Cap Set to {newMax}");
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"[MaxPlayersPatch] Patch Did Not Work - MAX_PLAYERS field not found.");
				}
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)$"[MaxPlayersPatch] Error: {arg}");
			}
		}
	}
}
namespace Lanx.NoHungerNearCampfire
{
	[BepInPlugin("com.Lanx.nohungernearcampfire", "No Hunger Near Campfire", "1.0.0")]
	public class NoHungerPatchPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Campfire), "Awake")]
		private class Campfire_Awake_Patch
		{
			private static void Postfix(Campfire __instance)
			{
				__instance.burnsFor = float.PositiveInfinity;
				__instance.beenBurningFor = 0f;
			}
		}

		[HarmonyPatch(typeof(CharacterAfflictions), "UpdateNormalStatuses")]
		private class Patch_UpdateNormalStatuses
		{
			private static readonly Dictionary<CharacterAfflictions, Character> characterCache = new Dictionary<CharacterAfflictions, Character>();

			private static bool Prefix(CharacterAfflictions __instance)
			{
				//IL_0064: 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_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_0090: 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)
				if (!characterCache.TryGetValue(__instance, out var value))
				{
					value = ((Component)__instance).GetComponent<Character>();
					if ((Object)(object)value != (Object)null)
					{
						characterCache[__instance] = value;
					}
				}
				if ((Object)(object)value == (Object)null || !value.IsLocal || value.data.dead)
				{
					return true;
				}
				Vector3 center = value.Center;
				foreach (Campfire item in campfireCache)
				{
					Vector3 val = ((Component)item).transform.position - center;
					float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
					float num = item.moraleBoostRadius * item.moraleBoostRadius;
					if (sqrMagnitude <= num)
					{
						return false;
					}
				}
				return true;
			}
		}

		private static List<Campfire> campfireCache = new List<Campfire>();

		private static float nextCampfireScanTime = 0f;

		private const float campfireScanInterval = 2f;

		private void Update()
		{
			if (Time.time >= nextCampfireScanTime)
			{
				campfireCache = (from cf in Object.FindObjectsByType<Campfire>((FindObjectsSortMode)0)
					where (Object)(object)cf != (Object)null && ((Behaviour)cf).isActiveAndEnabled
					select cf).ToList();
				nextCampfireScanTime = Time.time + 2f;
			}
		}

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			Harmony val = new Harmony("com.Lanx.nohungerpatch");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"No Hunger Near Campfire patch applied.");
		}
	}
}
namespace Lanx.MaxPlayerNamesPatch
{
	[BepInPlugin("com.Lanx.maxplayersnamepatch", "Max Players Name Patch", "1.0.0")]
	public class MaxPlayerNamesPlugin : BaseUnityPlugin
	{
		private static GameObject playerNameUIPrefab;

		private static Dictionary<int, PlayerName> lanxCustomPlayerNames = new Dictionary<int, PlayerName>();

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			Harmony val = new Harmony("com.Lanx.maxplayersnamepatch");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Lanx Max Player Name Patch initialized.");
		}

		private void Update()
		{
			//IL_0066: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			foreach (KeyValuePair<int, PlayerName> lanxCustomPlayerName in lanxCustomPlayerNames)
			{
				CharacterInteractible characterInteractable = lanxCustomPlayerName.Value.characterInteractable;
				if (!((Object)(object)characterInteractable == (Object)null))
				{
					Camera value = Traverse.Create((object)MainCamera.instance).Field<Camera>("cam").Value;
					if (!((Object)(object)value == (Object)null))
					{
						Vector3 val = ((Component)characterInteractable).transform.position + Vector3.up * 2f;
						((Component)lanxCustomPlayerName.Value).transform.position = value.WorldToScreenPoint(val);
					}
				}
			}
		}

		[HarmonyPatch(typeof(UIPlayerNames), "Init")]
		[HarmonyPrefix]
		public static bool Init_Prefix(UIPlayerNames __instance, CharacterInteractible characterInteractable, ref int __result)
		{
			int instanceID = ((Object)characterInteractable).GetInstanceID();
			if (lanxCustomPlayerNames.ContainsKey(instanceID))
			{
				__result = instanceID;
				return false;
			}
			if ((Object)(object)playerNameUIPrefab == (Object)null)
			{
				FieldInfo field = typeof(UIPlayerNames).GetField("playerNameText", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field == null)
				{
					return true;
				}
				if (!(field.GetValue(__instance) is PlayerName[] array) || array.Length == 0)
				{
					return true;
				}
				playerNameUIPrefab = Object.Instantiate<GameObject>(((Component)array[0]).gameObject);
				playerNameUIPrefab.SetActive(false);
			}
			GameObject val = Object.Instantiate<GameObject>(playerNameUIPrefab, ((Component)__instance).transform);
			val.SetActive(true);
			PlayerName component = val.GetComponent<PlayerName>();
			component.characterInteractable = characterInteractable;
			((TMP_Text)component.text).text = characterInteractable.GetName();
			lanxCustomPlayerNames[instanceID] = component;
			__result = instanceID;
			return false;
		}

		[HarmonyPatch(typeof(UIPlayerNames), "UpdateName")]
		[HarmonyPrefix]
		public static bool UpdateName_Prefix(UIPlayerNames __instance, int index, Vector3 position, bool visible, int speakingAmplitude)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			if (!lanxCustomPlayerNames.TryGetValue(index, out var value))
			{
				return true;
			}
			Camera value2 = Traverse.Create((object)MainCamera.instance).Field<Camera>("cam").Value;
			if ((Object)(object)value2 == (Object)null)
			{
				return true;
			}
			((Component)value).transform.position = value2.WorldToScreenPoint(position);
			if (visible)
			{
				((Component)value).gameObject.SetActive(true);
				value.group.alpha = Mathf.MoveTowards(value.group.alpha, 1f, Time.deltaTime * 5f);
				if (Object.op_Implicit((Object)(object)value.characterInteractable) && AudioLevels.GetPlayerLevel(((MonoBehaviourPun)value.characterInteractable.character).photonView.OwnerActorNr) == 0f)
				{
					value.audioImage.sprite = __instance.mutedAudioSprite;
				}
				else if (speakingAmplitude > 0)
				{
					value.audioImage.sprite = __instance.audioSprites[Mathf.Clamp(speakingAmplitude, 0, __instance.audioSprites.Length - 1)];
					value.audioImageTimeout = __instance.audioImageTimeoutMax;
				}
				else
				{
					PlayerName obj = value;
					obj.audioImageTimeout -= Time.deltaTime;
					if (value.audioImageTimeout <= 0f)
					{
						value.audioImage.sprite = __instance.audioSprites[0];
					}
				}
			}
			else
			{
				value.group.alpha = Mathf.MoveTowards(value.group.alpha, 0f, Time.deltaTime * 5f);
				if (value.group.alpha < 0.01f)
				{
					((Component)value).gameObject.SetActive(false);
				}
			}
			return false;
		}

		[HarmonyPatch(typeof(UIPlayerNames), "DisableName")]
		[HarmonyPrefix]
		public static bool DisableName_Prefix(UIPlayerNames __instance, int index)
		{
			if (lanxCustomPlayerNames.TryGetValue(index, out var value))
			{
				((Component)value).gameObject.SetActive(false);
				return false;
			}
			return true;
		}
	}
}