using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("AutoCampfire")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AutoCampfire")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2dce3d26-1d41-43c4-8f58-3faafc67467d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("com.sappheiros.peak.autocampfire", "Auto Campfire", "1.0.2")]
public sealed class AutoCampfire : BaseUnityPlugin
{
private const float AutoLightDistanceMeters = 20f;
private const float CheckInterval = 0.25f;
private float nextCheckTime;
private Campfire lastTriggeredCampfire;
private void Update()
{
//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
if (Time.unscaledTime < nextCheckTime)
{
return;
}
nextCheckTime = Time.unscaledTime + 0.25f;
if (!PhotonNetwork.InRoom || !PhotonNetwork.IsMasterClient || (Object)(object)Object.FindAnyObjectByType<MapHandler>() == (Object)null)
{
return;
}
Campfire currentCampfire;
try
{
currentCampfire = MapHandler.CurrentCampfire;
}
catch
{
return;
}
if ((Object)(object)currentCampfire == (Object)null || (Object)(object)lastTriggeredCampfire == (Object)(object)currentCampfire)
{
return;
}
int num = 0;
Player[] playerList = PhotonNetwork.PlayerList;
for (int i = 0; i < playerList.Length; i++)
{
if (playerList[i] != null && !playerList[i].IsInactive)
{
num++;
}
}
if (num <= 0)
{
return;
}
int num2 = 0;
bool flag = false;
float unitsToMeters = CharacterStats.unitsToMeters;
if (unitsToMeters <= 0f)
{
return;
}
float num3 = 20f / unitsToMeters;
foreach (Character allPlayerCharacter in PlayerHandler.GetAllPlayerCharacters())
{
if ((Object)(object)allPlayerCharacter == (Object)null || (Object)(object)((MonoBehaviourPun)allPlayerCharacter).photonView == (Object)null || ((MonoBehaviourPun)allPlayerCharacter).photonView.Owner == null || ((MonoBehaviourPun)allPlayerCharacter).photonView.Owner.IsInactive)
{
continue;
}
num2++;
if (!allPlayerCharacter.data.dead)
{
flag = true;
float num4 = Vector3.Distance(((Component)currentCampfire).transform.position, allPlayerCharacter.Center);
if (num4 > num3)
{
return;
}
}
}
if (num2 < num || !flag)
{
return;
}
lastTriggeredCampfire = currentCampfire;
try
{
currentCampfire.DebugLight();
}
catch
{
lastTriggeredCampfire = null;
}
}
}
[BepInPlugin("Sapphire009.Autocook", "Autocook", "1.0.2")]
public sealed class Autocook : BaseUnityPlugin
{
public const string PluginGuid = "Sapphire009.Autocook";
public const string PluginName = "Autocook";
public const string PluginVersion = "1.0.2";
private const ushort MarshmallowItemId = 46;
private const ushort HotDogItemId = 154;
private const float CookRadius = 15f;
private const float CheckInterval = 0.2f;
private readonly HashSet<int> processedCampfires = new HashSet<int>();
private float nextCheckTime;
private void Awake()
{
SceneManager.sceneLoaded += OnSceneLoaded;
}
private void OnDestroy()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
processedCampfires.Clear();
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
processedCampfires.Clear();
nextCheckTime = 0f;
}
private void Update()
{
if (Time.unscaledTime < nextCheckTime)
{
return;
}
nextCheckTime = Time.unscaledTime + 0.2f;
if (!PhotonNetwork.InRoom || !PhotonNetwork.IsMasterClient)
{
return;
}
Campfire[] array = Object.FindObjectsByType<Campfire>((FindObjectsSortMode)0);
foreach (Campfire val in array)
{
if (!((Object)(object)val == (Object)null) && val.Lit)
{
int instanceID = ((Object)val).GetInstanceID();
if (!processedCampfires.Contains(instanceID))
{
processedCampfires.Add(instanceID);
CookNearbyFood(val);
}
}
}
}
private void CookNearbyFood(Campfire campfire)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: 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)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
Item[] array = Object.FindObjectsByType<Item>((FindObjectsSortMode)0);
Vector3 position = ((Component)campfire).transform.position;
foreach (Item val in array)
{
if ((Object)(object)val == (Object)null || (val.itemID != 46 && val.itemID != 154))
{
continue;
}
float num = Vector3.Distance(position, ((Component)val).transform.position);
if (num > 15f)
{
continue;
}
IntItemData data = val.GetData<IntItemData>((DataEntryKey)1);
if (data != null && data.Value == 0)
{
ItemCooking component = ((Component)val).GetComponent<ItemCooking>();
if (!((Object)(object)component == (Object)null) && component.canBeCooked)
{
component.FinishCooking();
}
}
}
}
}
[BepInPlugin("com.sappheiros.peak.autoscoutstatue", "Auto Scout Statue", "1.0.4")]
public sealed class AutoScoutStatue : BaseUnityPlugin
{
[HarmonyPatch(typeof(Campfire), "DebugLight")]
private static class CampfireDebugLightPatch
{
[HarmonyPrefix]
private static void Prefix(Campfire __instance)
{
if (!((Object)(object)Instance == (Object)null))
{
Instance.CaptureStatueBeforeCampfire(__instance);
}
}
}
[HarmonyPatch(typeof(Spawner), "SpawnItems")]
private static class SpawnerSpawnItemsPatch
{
[HarmonyPostfix]
private static void Postfix(Spawner __instance, List<PhotonView> __result)
{
if (!((Object)(object)Instance == (Object)null))
{
Instance.HandleSpawnItemsPostfix(__instance, __result);
}
}
}
private const float CheckInterval = 0.15f;
private const float StatueDelayAfterCampfire = 0.25f;
private const float StatueResolveTimeout = 5f;
private const float RetryDelay = 2f;
private const float SpawnResultWait = 1f;
private const float ItemHeightOffset = 1.25f;
private const float PlayerHeightOffset = 1.5f;
private const float MaximumStatueDistance = 200f;
private const float ReviveProtectionSeconds = 5f;
private const float ReviveProtectionTick = 0.1f;
private static AutoScoutStatue Instance;
private readonly HashSet<int> pendingCampfires = new HashSet<int>();
private readonly HashSet<int> completedCampfires = new HashSet<int>();
private readonly Dictionary<int, float> retryAfter = new Dictionary<int, float>();
private readonly Dictionary<int, RespawnChest> capturedStatues = new Dictionary<int, RespawnChest>();
private Harmony harmony;
private float nextCheckTime;
private bool relocationActive;
private RespawnChest activeStatue;
private Vector3 activeItemSpawnPosition;
private int relocatedItemCount;
private void Awake()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
Instance = this;
harmony = new Harmony("com.sappheiros.peak.autoscoutstatue");
harmony.PatchAll(typeof(AutoScoutStatue).Assembly);
SceneManager.sceneLoaded += OnSceneLoaded;
((BaseUnityPlugin)this).Logger.LogInfo((object)"[AutoScoutStatue] Loaded 1.0.4");
((BaseUnityPlugin)this).Logger.LogInfo((object)"[AutoScoutStatue] Host-only mode active");
}
private void OnDestroy()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
((MonoBehaviour)this).StopAllCoroutines();
if (harmony != null)
{
harmony.UnpatchSelf();
harmony = null;
}
pendingCampfires.Clear();
completedCampfires.Clear();
retryAfter.Clear();
capturedStatues.Clear();
relocationActive = false;
activeStatue = null;
if ((Object)(object)Instance == (Object)(object)this)
{
Instance = null;
}
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
((MonoBehaviour)this).StopAllCoroutines();
pendingCampfires.Clear();
completedCampfires.Clear();
retryAfter.Clear();
capturedStatues.Clear();
relocationActive = false;
activeStatue = null;
relocatedItemCount = 0;
nextCheckTime = 0f;
}
private void Update()
{
if (Time.unscaledTime < nextCheckTime)
{
return;
}
nextCheckTime = Time.unscaledTime + 0.15f;
if (!PhotonNetwork.InRoom || !PhotonNetwork.IsMasterClient)
{
return;
}
Campfire[] array = Object.FindObjectsOfType<Campfire>(true);
if (array == null || array.Length == 0)
{
return;
}
foreach (Campfire val in array)
{
if ((Object)(object)val == (Object)null)
{
continue;
}
int instanceID = ((Object)val).GetInstanceID();
if (!pendingCampfires.Contains(instanceID) && !completedCampfires.Contains(instanceID) && (!retryAfter.TryGetValue(instanceID, out var value) || !(Time.unscaledTime < value)))
{
bool lit;
try
{
lit = val.Lit;
}
catch
{
continue;
}
if (lit)
{
pendingCampfires.Add(instanceID);
((BaseUnityPlugin)this).Logger.LogInfo((object)("[AutoScoutStatue] Campfire lit | " + ((Object)((Component)val).gameObject).name));
((MonoBehaviour)this).StartCoroutine(HandleScoutStatue(val, instanceID));
}
}
}
}
private void CaptureStatueBeforeCampfire(Campfire campfire)
{
if (PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient && !((Object)(object)campfire == (Object)null))
{
RespawnChest val = FindNearestLocalStatue(campfire, requireActive: true);
if (!((Object)(object)val == (Object)null))
{
int instanceID = ((Object)campfire).GetInstanceID();
capturedStatues[instanceID] = val;
}
}
}
private IEnumerator HandleScoutStatue(Campfire campfire, int campfireId)
{
yield return (object)new WaitForSecondsRealtime(0.25f);
if ((Object)(object)campfire == (Object)null)
{
CancelCampfire(campfireId);
yield break;
}
bool lit;
try
{
lit = campfire.Lit;
}
catch
{
CancelCampfire(campfireId);
yield break;
}
if (!lit)
{
CancelCampfire(campfireId);
yield break;
}
RespawnChest statue = null;
float timeout = Time.unscaledTime + 5f;
while (Time.unscaledTime < timeout)
{
statue = ResolveScoutStatue(campfire, campfireId);
if ((Object)(object)statue != (Object)null)
{
break;
}
yield return (object)new WaitForSecondsRealtime(0.1f);
}
if ((Object)(object)statue == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)("[AutoScoutStatue] No local scout statue | " + ((Object)((Component)campfire).gameObject).name));
FinishCampfire(campfireId);
yield break;
}
if (statue.IsSpent)
{
FinishCampfire(campfireId);
yield break;
}
Character hostCharacter = Character.localCharacter;
if ((Object)(object)hostCharacter == (Object)null)
{
ScheduleRetry(campfireId);
yield break;
}
bool interactible;
try
{
interactible = statue.IsInteractible(hostCharacter);
}
catch
{
ScheduleRetry(campfireId);
yield break;
}
if (!interactible)
{
if (statue.IsSpent)
{
FinishCampfire(campfireId);
}
else
{
ScheduleRetry(campfireId);
}
yield break;
}
List<Character> reviveTargets = GetReviveTargets();
bool reviveMode = Ascents.canReviveDead && reviveTargets.Count > 0;
Vector3 campfirePosition = ((Component)campfire).transform.position;
activeStatue = statue;
activeItemSpawnPosition = campfirePosition + Vector3.up * 1.25f;
relocatedItemCount = 0;
relocationActive = true;
((BaseUnityPlugin)this).Logger.LogInfo((object)("[AutoScoutStatue] Breaking scout statue | " + ((Object)((Component)statue).gameObject).name + " | Mode=" + (reviveMode ? "REVIVE" : "ITEM")));
try
{
((Luggage)statue).Interact_CastFinished(hostCharacter);
}
catch (Exception ex)
{
relocationActive = false;
activeStatue = null;
((BaseUnityPlugin)this).Logger.LogError((object)("[AutoScoutStatue] Statue activation failed | " + ex.Message));
ScheduleRetry(campfireId);
yield break;
}
yield return (object)new WaitForSecondsRealtime(1f);
if (reviveMode)
{
Vector3 revivePosition = campfirePosition + Vector3.up * 1.5f;
for (int i = 0; i < reviveTargets.Count; i++)
{
Character character = reviveTargets[i];
if (!((Object)(object)character == (Object)null) && !((Object)(object)((MonoBehaviourPun)character).photonView == (Object)null))
{
try
{
((MonoBehaviourPun)character).photonView.RPC("WarpPlayerRPC", (RpcTarget)0, new object[2] { revivePosition, true });
((MonoBehaviour)this).StartCoroutine(ProtectRevivedPlayer(character));
((BaseUnityPlugin)this).Logger.LogInfo((object)"[AutoScoutStatue] Revived player moved to campfire");
}
catch (Exception ex2)
{
Exception exception = ex2;
((BaseUnityPlugin)this).Logger.LogError((object)("[AutoScoutStatue] Revive relocation failed | " + exception.Message));
}
}
}
}
else if (relocatedItemCount > 0)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"[AutoScoutStatue] Scout item spawned at campfire");
}
else
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"[AutoScoutStatue] Scout statue opened but no item was relocated");
}
relocationActive = false;
activeStatue = null;
FinishCampfire(campfireId);
}
private RespawnChest ResolveScoutStatue(Campfire campfire, int campfireId)
{
if (capturedStatues.TryGetValue(campfireId, out var value) && (Object)(object)value != (Object)null && !value.IsSpent && IsWithinStatueRange(campfire, value))
{
return value;
}
return FindNearestLocalStatue(campfire, requireActive: true);
}
private RespawnChest FindNearestLocalStatue(Campfire campfire, bool requireActive)
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)campfire == (Object)null)
{
return null;
}
RespawnChest[] array = Object.FindObjectsOfType<RespawnChest>(true);
if (array == null || array.Length == 0)
{
return null;
}
RespawnChest result = null;
float num = 40000f;
float num2 = num;
Vector3 position = ((Component)campfire).transform.position;
foreach (RespawnChest val in array)
{
if (!((Object)(object)val == (Object)null) && !val.IsSpent && (!requireActive || ((Component)val).gameObject.activeInHierarchy))
{
Vector3 val2 = ((Component)val).transform.position - position;
float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
if (!(sqrMagnitude > num) && !(sqrMagnitude >= num2))
{
num2 = sqrMagnitude;
result = val;
}
}
}
return result;
}
private bool IsWithinStatueRange(Campfire campfire, RespawnChest statue)
{
//IL_0023: 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_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)campfire == (Object)null || (Object)(object)statue == (Object)null)
{
return false;
}
Vector3 val = ((Component)statue).transform.position - ((Component)campfire).transform.position;
float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
return sqrMagnitude <= 40000f;
}
private IEnumerator ProtectRevivedPlayer(Character character)
{
if ((Object)(object)character == (Object)null || (Object)(object)((MonoBehaviourPun)character).photonView == (Object)null || !PhotonNetwork.InRoom || !PhotonNetwork.IsMasterClient)
{
yield break;
}
int viewId = ((MonoBehaviourPun)character).photonView.ViewID;
float endTime = Time.unscaledTime + 5f;
while (Time.unscaledTime < endTime)
{
if (!PhotonNetwork.InRoom || !PhotonNetwork.IsMasterClient)
{
yield break;
}
PhotonView view = PhotonView.Find(viewId);
if ((Object)(object)view == (Object)null)
{
yield break;
}
Character currentCharacter = ((Component)view).GetComponent<Character>();
if ((Object)(object)currentCharacter == (Object)null || (Object)(object)currentCharacter.data == (Object)null)
{
yield break;
}
SendReviveProtectionPulse(currentCharacter);
yield return (object)new WaitForSecondsRealtime(0.1f);
}
PhotonView finalView = PhotonView.Find(viewId);
if ((Object)(object)finalView != (Object)null)
{
Character finalCharacter = ((Component)finalView).GetComponent<Character>();
if ((Object)(object)finalCharacter != (Object)null)
{
SendReviveProtectionPulse(finalCharacter);
}
}
}
private void SendReviveProtectionPulse(Character character)
{
if ((Object)(object)character == (Object)null || (Object)(object)((MonoBehaviourPun)character).photonView == (Object)null || !PhotonNetwork.InRoom || !PhotonNetwork.IsMasterClient)
{
return;
}
float[] array = new float[CharacterAfflictions.NumStatusTypes];
array[0] = -2f;
array[8] = -2f;
try
{
((MonoBehaviourPun)character).photonView.RPC("RPC_ApplyStatusesFromFloatArray", (RpcTarget)0, new object[1] { array });
}
catch
{
}
}
private List<Character> GetReviveTargets()
{
List<Character> list = new List<Character>();
if (Character.AllCharacters == null)
{
return list;
}
foreach (Character allCharacter in Character.AllCharacters)
{
if (!((Object)(object)allCharacter == (Object)null) && !((Object)(object)allCharacter.data == (Object)null) && (allCharacter.data.dead || allCharacter.data.fullyPassedOut))
{
list.Add(allCharacter);
}
}
return list;
}
private void HandleSpawnItemsPostfix(Spawner spawner, List<PhotonView> spawnedViews)
{
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
if (!relocationActive || !PhotonNetwork.InRoom || !PhotonNetwork.IsMasterClient || (Object)(object)activeStatue == (Object)null || (object)spawner != activeStatue || spawnedViews == null || spawnedViews.Count == 0)
{
return;
}
for (int i = 0; i < spawnedViews.Count; i++)
{
PhotonView val = spawnedViews[i];
if ((Object)(object)val == (Object)null)
{
continue;
}
Item component = ((Component)val).GetComponent<Item>();
if (!((Object)(object)component == (Object)null))
{
try
{
Quaternion rotation = ((Component)component).transform.rotation;
((Component)component).transform.position = activeItemSpawnPosition;
val.RPC("SetKinematicRPC", (RpcTarget)3, new object[3]
{
((Spawner)activeStatue).isKinematic,
activeItemSpawnPosition,
rotation
});
relocatedItemCount++;
((BaseUnityPlugin)this).Logger.LogInfo((object)("[AutoScoutStatue] Item moved to campfire | " + ((Object)((Component)component).gameObject).name));
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("[AutoScoutStatue] Item relocation failed | " + ex.Message));
}
}
}
}
private void ScheduleRetry(int campfireId)
{
pendingCampfires.Remove(campfireId);
retryAfter[campfireId] = Time.unscaledTime + 2f;
}
private void CancelCampfire(int campfireId)
{
pendingCampfires.Remove(campfireId);
}
private void FinishCampfire(int campfireId)
{
pendingCampfires.Remove(campfireId);
retryAfter.Remove(campfireId);
capturedStatues.Remove(campfireId);
completedCampfires.Add(campfireId);
}
}