Decompiled source of CampfireSafeZone v1.0.3

PEAK-CampfireSafeZone.dll

Decompiled 3 weeks 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 CharacterPatcher
{
	public static HashSet<Character> playersNearCampfire = new HashSet<Character>();

	public static bool allPlayersNearCampfire = false;

	[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 = AllPlayersInRangeCampfire();
		return !flag;
	}

	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_004b: 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)
		Vector3 center;
		try
		{
			center = character.Center;
		}
		catch
		{
			return false;
		}
		for (int i = 0; i < RunManagerPatcher.campfires.Count; i++)
		{
			Campfire val = RunManagerPatcher.campfires[i];
			if (!Object.op_Implicit((Object)(object)val))
			{
				RunManagerPatcher.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;
	}

	public static bool AllPlayersInRangeCampfire()
	{
		bool flag = true;
		bool flag2 = false;
		foreach (Character allPlayerCharacter in PlayerHandler.GetAllPlayerCharacters())
		{
			flag2 = flag2 || !allPlayerCharacter.data.dead;
			if (!allPlayerCharacter.isBot && !allPlayerCharacter.data.dead && !IsPlayerInRangeCampfire(allPlayerCharacter))
			{
				flag = false;
				break;
			}
		}
		if (!flag2)
		{
			flag = false;
		}
		if (flag != allPlayersNearCampfire)
		{
			allPlayersNearCampfire = flag;
			Plugin.Log(allPlayersNearCampfire ? "All players are near campfire. Fog progression and run timer halted." : "Not all players are near campfire. Fog progression and run timer resumed.");
		}
		return allPlayersNearCampfire;
	}
}
[BepInPlugin("flipf17.CampfireSafeZone", "CampfireSafeZone", "1.0.3")]
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.3"));
		}
		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.3";
}
[HarmonyPatch]
public static class RunManagerPatcher
{
	internal static float timePaused = 0f;

	public static List<Campfire> campfires = new List<Campfire>();

	public static float timeSinceRunStarted => ((Object)(object)RunManager.Instance != (Object)null) ? RunManager.Instance.timeSinceRunStarted : 0f;

	[HarmonyPatch(typeof(RunManager), "StartRun")]
	[HarmonyPostfix]
	public static void RunManagerStartRun()
	{
		timePaused = 0f;
		CharacterPatcher.playersNearCampfire.Clear();
		CharacterPatcher.allPlayersNearCampfire = false;
	}

	[HarmonyPatch(typeof(RunManager), "Update")]
	[HarmonyPrefix]
	public static bool RunManagerUpdate()
	{
		if (CharacterPatcher.AllPlayersInRangeCampfire())
		{
			timePaused += Time.deltaTime;
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(EndScreen), "GetTimeString")]
	[HarmonyPrefix]
	public static void AdjustRunTimeString(ref float totalSeconds)
	{
		//IL_0037: 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)
		float num = 0f;
		try
		{
			num = Character.localCharacter.refs.stats.timelineInfo[Character.localCharacter.refs.stats.timelineInfo.Count - 1].time - Character.localCharacter.refs.stats.timelineInfo[0].time;
		}
		catch (Exception ex)
		{
			Plugin.LogError("Error: " + ex);
			return;
		}
		Plugin.LogWarning("TotalSeconds: " + totalSeconds + " CompareSeconds: " + num + " Delta: " + (num - totalSeconds) + " TimePaused: " + timePaused);
		if (Mathf.Abs(totalSeconds - num) < 0.1f)
		{
			totalSeconds = Mathf.Max(0f, totalSeconds - timePaused);
		}
	}

	[HarmonyPatch(typeof(Campfire), "Awake")]
	[HarmonyPostfix]
	public static void CampfireAwake(Campfire __instance)
	{
		if (((Object)__instance).name.ToLower().StartsWith("campfire") && !campfires.Contains(__instance))
		{
			campfires.Add(__instance);
		}
	}
}