Decompiled source of CozyCampfire v1.0.1

plugins/com.github.lukeprime.peakcozycampfire.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.lukeprime.peakcozycampfire")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+eecc5e45526e9e8b8d41ae81698493d6fd7e1892")]
[assembly: AssemblyProduct("com.github.lukeprime.peakcozycampfire")]
[assembly: AssemblyTitle("Cozy Campfire")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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.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 PEAK_CozyCampfire
{
	[BepInPlugin("com.github.lukeprime.peakcozycampfire", "Cozy Campfire", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Campfire), "Awake")]
		private class Campfire_Awake_Patch
		{
			private static void Postfix(Campfire __instance)
			{
				for (int num = campfireCache.Count - 1; num >= 0; num--)
				{
					if ((Object)(object)campfireCache[num] == (Object)null)
					{
						campfireCache.RemoveAt(num);
					}
				}
				if (!string.Equals(__instance.GetName(), "PORTABLE STOVE", StringComparison.InvariantCultureIgnoreCase))
				{
					__instance.burnsFor = float.PositiveInfinity;
					__instance.beenBurningFor = 0f;
					if (!campfireCache.Contains(__instance))
					{
						campfireCache.Add(__instance);
					}
				}
			}
		}

		[HarmonyPatch(typeof(CharacterAfflictions), "AddStatus")]
		private class Patch_AddStatus
		{
			private static readonly Dictionary<CharacterAfflictions, Character> playerCache = new Dictionary<CharacterAfflictions, Character>();

			private static bool Prefix(STATUSTYPE statusType, float amount, CharacterAfflictions __instance)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Invalid comparison between Unknown and I4
				//IL_005b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_007c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0081: Unknown result type (might be due to invalid IL or missing references)
				//IL_0082: 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)
				if ((int)statusType == 1)
				{
					if (!playerCache.TryGetValue(__instance, out Character value))
					{
						value = ((Component)__instance).GetComponent<Character>();
						if ((Object)(object)value != (Object)null)
						{
							playerCache[__instance] = value;
						}
					}
					if ((Object)(object)value == (Object)null || !value.IsLocal || value.data.dead || value.isBot)
					{
						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;
			}
		}

		[HarmonyPatch(typeof(EndScreen), "Start")]
		private class Patch_EndScreen
		{
			private static bool Prefix(EndScreen __instance)
			{
				campfireCache.Clear();
				return true;
			}
		}

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

		public const string Id = "com.github.lukeprime.peakcozycampfire";

		internal static ManualLogSource Log { get; private set; } = null;


		public static string Name => "Cozy Campfire";

		public static string Version => "1.0.1";

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony val = new Harmony("com.github.lukeprime.peakcozycampfire");
			val.PatchAll();
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}