Decompiled source of CampfireSafeZone v1.0.1

PEAK-CampfireSafeZone.dll

Decompiled 6 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
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("PEAK-CampfireSafeZone")]
[assembly: AssemblyDescription("Mod made by flipf17")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PEAK-CampfireSafeZone")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d5c9ccef-388a-4cf7-92b3-d6f5ea4b546d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PEAK_CampfireSafeZone;

[HarmonyPatch]
public static class CampfireSafeZone
{
	public static List<Campfire> campfires = new List<Campfire>();

	public static HashSet<Character> playersNearCampfire = new HashSet<Character>();

	public static bool allPlayersNearCampfire = false;

	[HarmonyPatch(typeof(Campfire), "Awake")]
	[HarmonyPrefix]
	public static void CampfireAwake(Campfire __instance)
	{
		campfires.Add(__instance);
	}

	[HarmonyPatch(typeof(CharacterAfflictions), "AddStatus")]
	[HarmonyPrefix]
	public static bool StopHungerDrainNearCampfire(STATUSTYPE statusType, float amount, CharacterAfflictions __instance)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Invalid comparison between Unknown and I4
		if ((int)statusType == 1 && !__instance.character.isBot && !__instance.character.data.dead && IsPlayerInRangeCampfire(__instance.character))
		{
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(Character), "UseStamina")]
	[HarmonyPrefix]
	public static bool StopStaminaDrainNearCampfire(float usage, Character __instance)
	{
		if (!__instance.isBot && !__instance.data.dead && __instance.data.isSprinting && IsPlayerInRangeCampfire(__instance))
		{
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(Fog), "Movement")]
	[HarmonyPatch(typeof(OrbFogHandler), "Move")]
	[HarmonyPatch(typeof(OrbFogHandler), "WaitToMove")]
	[HarmonyPrefix]
	public static bool StopFogMovementAndTimer()
	{
		bool flag = false;
		List<Character> allPlayerCharacters = PlayerHandler.GetAllPlayerCharacters();
		for (int i = 0; i < allPlayerCharacters.Count; i++)
		{
			Character val = allPlayerCharacters[i];
			flag = flag || !val.data.dead;
			if (!val.isBot && !val.data.dead && !IsPlayerInRangeCampfire(val))
			{
				if (allPlayersNearCampfire)
				{
					Plugin.Log("Not all players are near campfire. Fog progression resumed.");
				}
				allPlayersNearCampfire = false;
				return true;
			}
		}
		if (flag)
		{
			if (!allPlayersNearCampfire)
			{
				Plugin.Log("All players are near campfire. Fog progression halted.");
			}
			allPlayersNearCampfire = true;
			return false;
		}
		allPlayersNearCampfire = false;
		return true;
	}

	public static bool IsPlayerInRangeCampfire(Character character)
	{
		//IL_0003: 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_0049: 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)
		Vector3 center;
		try
		{
			center = character.Center;
		}
		catch
		{
			return false;
		}
		for (int i = 0; i < campfires.Count; i++)
		{
			Campfire val = campfires[i];
			if ((Object)(object)val == (Object)null)
			{
				campfires.RemoveAt(i--);
			}
			else if (Vector3.Distance(center, ((Component)val).transform.position) < 15f)
			{
				if (!playersNearCampfire.Contains(character))
				{
					Plugin.Log("Player: (" + character.characterName + ") ENTERED campfire proximity.");
				}
				playersNearCampfire.Add(character);
				return true;
			}
		}
		if (playersNearCampfire.Contains(character))
		{
			Plugin.Log("Player: (" + character.characterName + ") LEFT campfire proximity.");
		}
		playersNearCampfire.Remove(character);
		return false;
	}
}
[BepInPlugin("flipf17.CampfireSafeZone", "CampfireSafeZone", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
	private Harmony _harmony;

	public static Plugin instance;

	private static ManualLogSource logger;

	private void Awake()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		instance = this;
		CreateCustomLogger();
		_harmony = new Harmony("CampfireSafeZone");
		PatchAll();
		Log("CampfireSafeZone loaded");
	}

	private void PatchAll()
	{
		IEnumerable<Type> enumerable;
		try
		{
			enumerable = Assembly.GetExecutingAssembly().GetTypes();
		}
		catch (ReflectionTypeLoadException ex)
		{
			enumerable = ex.Types.Where((Type t) => t != null);
		}
		foreach (Type item in enumerable)
		{
			_harmony.PatchAll(item);
		}
	}

	private void CreateCustomLogger()
	{
		try
		{
			logger = Logger.CreateLogSource(string.Format("{0}-{1}", "CampfireSafeZone", "1.0.1"));
		}
		catch
		{
			logger = ((BaseUnityPlugin)this).Logger;
		}
	}

	internal static void Log(string message)
	{
		logger.LogInfo((object)message);
	}

	internal static void LogError(string message)
	{
		logger.LogError((object)message);
	}

	internal static void LogWarning(string message)
	{
		logger.LogWarning((object)message);
	}
}
public static class PluginInfo
{
	public const string PLUGIN_GUID = "flipf17.CampfireSafeZone";

	public const string PLUGIN_NAME = "CampfireSafeZone";

	public const string PLUGIN_VERSION = "1.0.1";
}