Decompiled source of PEAK Unlimited v2.3.2

PeakUnlimited.dll

Decompiled 12 hours 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 BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using UnityEngine.SceneManagement;
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("PeakUnlimited")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+0a3938f61ae36e802e8a9733c06b5a5d15e57542")]
[assembly: AssemblyProduct("PEAK Unlimited")]
[assembly: AssemblyTitle("PeakUnlimited")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 PeakUnlimited
{
	[BepInPlugin("PeakUnlimited", "PEAK Unlimited", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public class AwakePatch
		{
			[HarmonyPatch(typeof(Campfire), "Awake")]
			[HarmonyPostfix]
			private static void Postfix(Campfire __instance)
			{
				//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
				//IL_011e: Unknown result type (might be due to invalid IL or missing references)
				if (((Object)((Component)((Component)__instance).gameObject.transform.parent).gameObject).name.ToLower().Contains("wings"))
				{
					Logger.LogInfo((object)"Skipping plane campfire...");
					return;
				}
				Logger.LogInfo((object)"Marshmellowifying campfire...!");
				int num = 4;
				int numberOfPlayers = _numberOfPlayers;
				int number = numberOfPlayers - num;
				if (_cheatExtraMarshmallows != 0)
				{
					Logger.LogInfo((object)"Adding cheatmellows!");
					number = _cheatExtraMarshmallows - num;
					if (numberOfPlayers < num)
					{
						number = _cheatExtraMarshmallows - numberOfPlayers + 1;
					}
				}
				Logger.LogInfo((object)"Start of campfire patch!");
				if (PhotonNetwork.IsMasterClient && (numberOfPlayers > num || _cheatExtraMarshmallows != 0))
				{
					Logger.LogInfo((object)("More than 4 players, preparing to marshmallowify! Number: " + numberOfPlayers));
					Vector3 position = ((Component)__instance).gameObject.transform.position;
					Logger.LogInfo((object)("Spawning " + number + " marshmallows!"));
					spawnMarshmallows(number, position);
					Logger.LogInfo((object)"End of campfire patch!");
				}
				else
				{
					Logger.LogInfo((object)"Not enough players for campfire patch or not host!");
				}
			}
		}

		public class OnPlayerEnteredRoomPatch
		{
			[HarmonyPatch(typeof(PlayerConnectionLog), "OnPlayerEnteredRoom")]
			[HarmonyPostfix]
			private static void Postfix(PlayerConnectionLog __instance)
			{
				_numberOfPlayers++;
				Logger.LogInfo((object)("Someone has joined the room! Number: " + _numberOfPlayers + "/" + NetworkConnector.MAX_PLAYERS));
			}
		}

		public class OnPlayerLeftRoomPatch
		{
			[HarmonyPatch(typeof(PlayerConnectionLog), "OnPlayerLeftRoom")]
			[HarmonyPostfix]
			private static void Postfix(PlayerConnectionLog __instance)
			{
				_numberOfPlayers--;
				if (_numberOfPlayers < 0)
				{
					_numberOfPlayers = 0;
				}
				Logger.LogInfo((object)("Someone has left the room! Number: " + _numberOfPlayers + "/" + NetworkConnector.MAX_PLAYERS));
			}
		}

		internal static ManualLogSource Logger;

		private static int _newMaxPlayers;

		private static int _cheatExtraMarshmallows;

		private static bool _extraMarshmallows;

		private static ConfigEntry<int> _configMaxPlayers;

		private static ConfigEntry<int> _configCheatExtraMarshmallows;

		private static ConfigEntry<bool> _configExtraMarshmallows;

		private static int _numberOfPlayers = 1;

		private readonly Harmony _harmony = new Harmony("PeakUnlimited");

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin PeakUnlimited is loaded!");
			_configMaxPlayers = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaxPlayers", 20, "The maximum number of players you want to be able to join your lobby (Including yourself). Warning: untested, higher numbers may be unstable! Range: 1-20");
			_newMaxPlayers = _configMaxPlayers.Value;
			_configExtraMarshmallows = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ExtraMarshmallows", true, "Controls whether additional marshmallows are spawned for the extra players (Experimental)");
			_extraMarshmallows = _configExtraMarshmallows.Value;
			_configCheatExtraMarshmallows = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Cheat Marshmallows", 0, "(Cheat, disabled by default) This will set the desired amount of marshmallows to the campfires as a cheat, requires ExtraMarshmallows to be enabled.");
			_cheatExtraMarshmallows = _configCheatExtraMarshmallows.Value;
			if (_newMaxPlayers == 0)
			{
				_newMaxPlayers = 1;
			}
			else if (_newMaxPlayers > 30)
			{
				_newMaxPlayers = 30;
			}
			NetworkConnector.MAX_PLAYERS = _newMaxPlayers;
			Logger.LogInfo((object)("Plugin PeakUnlimited set the Max Players to " + NetworkConnector.MAX_PLAYERS + "!"));
			Logger.LogInfo((object)"Plugin PeakUnlimited is patching!");
			if (_extraMarshmallows)
			{
				Logger.LogInfo((object)"Plugin PeakUnlimited extra marshmallows are enabled!");
				_harmony.PatchAll(typeof(AwakePatch));
				Logger.LogInfo((object)"Plugin PeakUnlimited left patch enabled!");
				_harmony.PatchAll(typeof(OnPlayerLeftRoomPatch));
				Logger.LogInfo((object)"Plugin PeakUnlimited joined patch enabled!");
				_harmony.PatchAll(typeof(OnPlayerEnteredRoomPatch));
			}
			Logger.LogInfo((object)"Plugin PeakUnlimited has patched!");
		}

		private static List<Vector3> GetEvenlySpacedPointsAroundCampfire(int numPoints, float innerRadius, float outerRadius, Vector3 campfirePosition)
		{
			//IL_004e: 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_0054: 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)
			List<Vector3> list = new List<Vector3>();
			for (int i = 0; i < numPoints; i++)
			{
				float num = outerRadius;
				if (i % 2 == 0)
				{
					num = innerRadius;
				}
				float num2 = (float)i * (float)Math.PI * 2f / (float)numPoints;
				float num3 = num * Mathf.Cos(num2);
				float num4 = num * Mathf.Sin(num2);
				list.Add(SetToGround(new Vector3(num3, 0f, num4) + campfirePosition));
			}
			return list;
		}

		private static List<Vector3> getCampfirePositions()
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			Campfire[] array = Resources.FindObjectsOfTypeAll<Campfire>().Where(delegate(Campfire c)
			{
				//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)
				Scene scene = ((Component)c).gameObject.scene;
				return ((Scene)(ref scene)).IsValid();
			}).ToArray();
			foreach (Campfire val in array)
			{
				Logger.LogInfo((object)"Found campfire!");
				list.Add(((Component)val).gameObject.transform.position);
			}
			return list;
		}

		private static void spawnMarshmallows(int number, Vector3 campfirePosition)
		{
			//IL_0041: 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_0056: 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)
			Item val = SingletonAsset<ItemDatabase>.Instance.itemLookup[46];
			Logger.LogInfo((object)("Plugin PeakUnlimited " + val.GetName()));
			val.GetName();
			foreach (Vector3 item in GetEvenlySpacedPointsAroundCampfire(number, 2.5f, 3f, campfirePosition))
			{
				Add(val, item);
			}
			Logger.LogInfo((object)("Plugin PeakUnlimited added with position: " + val.GetName()));
		}

		private static Vector3 SetToGround(Vector3 vector)
		{
			//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(vector, (LayerType)4, 0f);
		}

		private static void SpawnMarshmallows(int number, Vector3 campfirePosition)
		{
			//IL_0042: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			ItemDatabase instance = SingletonAsset<ItemDatabase>.Instance;
			Item val = instance.itemLookup[46];
			Logger.LogInfo((object)("Plugin PeakUnlimited " + val.GetName()));
			val.GetName();
			List<Vector3> evenlySpacedPointsAroundCampfire = GetEvenlySpacedPointsAroundCampfire(number, 2.5f, 3f, campfirePosition);
			foreach (Vector3 item in evenlySpacedPointsAroundCampfire)
			{
				Add(val, item);
			}
			Logger.LogInfo((object)("Plugin PeakUnlimited added with position: " + val.GetName()));
		}

		private static void Add(Item item, Vector3 position)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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)
			if (PhotonNetwork.IsConnected)
			{
				Logger.LogInfo((object)$"Spawn item: {item} at {position}");
				PhotonNetwork.Instantiate("0_Items/" + ((Object)item).name, position, Quaternion.Euler(0f, Random.Range(0f, 360f), 0f), (byte)0, (object[])null).GetComponent<Item>();
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "PeakUnlimited";

		public const string PLUGIN_NAME = "PEAK Unlimited";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}