Decompiled source of MyCampfireDontLeaveMe v0.1.1

plugins/my.pahsiv.MyCampfireDontLeaveMe.dll

Decompiled 2 weeks 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 UnityEngine;
using UnityEngine.SceneManagement;
using Zorro.Core;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("my.pahsiv.MyCampfireDontLeaveMe")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1")]
[assembly: AssemblyProduct("my.pahsiv.MyCampfireDontLeaveMe")]
[assembly: AssemblyTitle("MyCampfireDontLeaveMe")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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.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]
	[Microsoft.CodeAnalysis.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]
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace MyCampfireDontLeaveMe
{
	public static class ColorHelper
	{
		public const string White = "FFFFFF";

		public const string Black = "000000";

		public const string Red = "FF0000";

		public const string Green = "00FF00";

		public const string Blue = "0000FF";

		public const string Yellow = "FFFF00";

		public const string Purple = "8765CA";

		public const string Gray = "808080";

		public const string Orange = "FFA500";

		public const string Cyan = "00FFFF";

		public const string Magenta = "FF00FF";

		public const string Pink = "FFC0CB";

		public const string Brown = "A52A2A";

		public const string Lime = "00FF00";

		public const string Teal = "008080";

		public const string Navy = "000080";

		public const string Maroon = "800000";

		public const string Olive = "808000";

		public const string Aqua = "00FFFF";

		public const string Silver = "C0C0C0";

		public const string Gold = "FFD700";

		public const string LightRed = "FF6B6B";

		public const string LightGreen = "90EE90";

		public const string LightBlue = "ADD8E6";

		public const string LightGray = "D3D3D3";

		public const string LightPink = "FFB6C1";

		public const string DarkRed = "8B0000";

		public const string DarkGreen = "006400";

		public const string DarkBlue = "00008B";

		public const string DarkGray = "A9A9A9";

		public const string DarkOrange = "FF8C00";

		public const string Pahsiv = "3582E7";
	}
	[BepInPlugin("my.pahsiv.MyCampfireDontLeaveMe", "MyCampfireDontLeaveMe", "0.1.1")]
	public class Plugin : BaseUnityPlugin
	{
		public static ConfigEntry<KeyCode> ForceLoad;

		private bool inLevel;

		private float holdDuration;

		private bool isHolding;

		private const float REQUIRED_HOLD_TIME = 3f;

		public const string Id = "my.pahsiv.MyCampfireDontLeaveMe";

		internal static ManualLogSource Log { get; private set; }

		public static Plugin Instance { get; private set; }

		public static string Name => "MyCampfireDontLeaveMe";

		public static string Version => "0.1.1";

		private void Update()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: 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_0027: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Invalid comparison between Unknown and I4
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			if (!inLevel)
			{
				return;
			}
			if (Input.GetKeyDown(ForceLoad.Value))
			{
				Segment currentSegment = Singleton<MapHandler>.Instance.GetCurrentSegment();
				Utilities.Notification("Current Segment is " + Utilities.AddColor(GetSegmentName(currentSegment), "00FFFF") + "!", "FFFF00");
				if ((int)currentSegment == 3)
				{
					RespawnChest val = FindFurthestRespawnStatue();
					if ((Object)(object)val != (Object)null && ((Component)Camera.main).transform.position.z < ((Component)val).transform.position.z + 240f)
					{
						Utilities.Notification("Approach the campfire before force loading " + Utilities.AddColor(GetSegmentName((Segment)4), "FFC0CB") + "!", "FFFF00");
						return;
					}
					isHolding = true;
					holdDuration = 0f;
					Utilities.Notification("Hold for 3 seconds to force load " + Utilities.AddColor(GetSegmentName((Segment)4), "FFC0CB") + ".", "FFFF00");
				}
			}
			if (Input.GetKey(ForceLoad.Value) && isHolding)
			{
				holdDuration += Time.deltaTime;
				if (holdDuration >= 3f)
				{
					ExecuteForceLoad();
					isHolding = false;
				}
			}
			if (Input.GetKeyUp(ForceLoad.Value))
			{
				isHolding = false;
			}
		}

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			ForceLoad = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "Force Load hotkey", (KeyCode)292, "Press to force load The Kiln!");
			SceneManager.sceneLoaded += OnSceneLoaded;
			Log.LogMessage((object)("          Plugin " + Name + " " + Version + " is loaded!"));
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			if (((Scene)(ref scene)).name == "Airport")
			{
				inLevel = false;
			}
			else if (((Scene)(ref scene)).name.Contains("Level_"))
			{
				inLevel = true;
			}
			else if (((Scene)(ref scene)).name.Contains("Title"))
			{
				inLevel = false;
			}
		}

		private void ExecuteForceLoad()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			if ((int)Singleton<MapHandler>.Instance.GetCurrentSegment() == 3)
			{
				Utilities.Notification("Forcing " + Utilities.AddColor(GetSegmentName((Segment)4), "FFC0CB") + " to load!", "FFFF00", sound: true);
				Shader.SetGlobalFloat("FakeMountainEnabled", 0f);
				if (Object.op_Implicit((Object)(object)Singleton<MapHandler>.Instance))
				{
					Singleton<MapHandler>.Instance.GoToSegment((Segment)4);
				}
			}
		}

		public RespawnChest? FindFurthestRespawnStatue()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			RespawnChest val = null;
			List<RespawnChest> list = Object.FindObjectsByType<RespawnChest>((FindObjectsSortMode)0).ToList();
			foreach (RespawnChest item in list)
			{
				if ((Object)(object)val == (Object)null)
				{
					val = item;
				}
				else if (((Component)item).transform.position.z >= ((Component)val).transform.position.z)
				{
					val = item;
				}
			}
			return val;
		}

		public string GetSegmentName(Segment currnetSegment)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			if ((int)currnetSegment >= 3)
			{
				return ((object)(Segment)(ref currnetSegment)).ToString();
			}
			BiomeType biome = Singleton<MapHandler>.Instance.segments[Singleton<MapHandler>.Instance.currentSegment].biome;
			return ((object)(BiomeType)(ref biome)).ToString();
		}
	}
	public static class Utilities
	{
		public static void VerifyPatch(Harmony harmony)
		{
			IEnumerable<MethodBase> patchedMethods = harmony.GetPatchedMethods();
			Plugin.Log.LogMessage((object)$"          Total patched methods: {patchedMethods.Count()}");
			foreach (MethodBase item in patchedMethods)
			{
				Plugin.Log.LogMessage((object)("          Patched: " + item.DeclaringType?.Name + "." + item.Name));
			}
		}

		public static void Notification(string message, string color = "FFFFFF", bool sound = false)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			PlayerConnectionLog val = Object.FindFirstObjectByType<PlayerConnectionLog>();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			string text = "<color=#" + color + ">" + message + "</color>";
			MethodInfo method = typeof(PlayerConnectionLog).GetMethod("AddMessage", BindingFlags.Instance | BindingFlags.NonPublic);
			if (method != null)
			{
				method.Invoke(val, new object[1] { text });
				if ((Object)(object)val.sfxJoin != (Object)null && sound)
				{
					val.sfxJoin.Play(default(Vector3));
				}
			}
			else
			{
				Plugin.Log.LogWarning((object)"AddMessage method not found.");
			}
		}

		public static string AddColor(string text, string color)
		{
			return "<color=#" + color + ">" + text + "</color>";
		}

		public static string ConvertKeyCodeToInputPath(KeyCode keyCode)
		{
			string text = ((object)(KeyCode)(ref keyCode)).ToString();
			if (text.StartsWith("Keypad"))
			{
				text = text.Replace("Keypad", "numpad");
			}
			return "<Keyboard>/" + text.ToLower();
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}