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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
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("Campfire Building")]
[assembly: AssemblyDescription("BepInEx plugin for PEAK that adds firewood requirements to campfires")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("tony4twentys")]
[assembly: AssemblyProduct("Campfire Building")]
[assembly: AssemblyCopyright("Copyright © tony4twentys 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("69efbd55-05ad-4c68-8483-6d8e9db0b1c9")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace tony4twentys.Campfire_Building;
[BepInPlugin("tony4twentys.Campfire_Building", "Campfire Building", "1.0.0")]
public class CampfireBuildingPlugin : BaseUnityPlugin
{
[CompilerGenerated]
private sealed class <SpawnFirewoodAfterSceneLoad>d__6 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public CampfireBuildingPlugin <>4__this;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <SpawnFirewoodAfterSceneLoad>d__6(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(2f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
<>4__this.SpawnFirewoodNearNaturalObjects();
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
[CompilerGenerated]
private sealed class <WaitForRunStart>d__4 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public CampfireBuildingPlugin <>4__this;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <WaitForRunStart>d__4(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Expected O, but got Unknown
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
goto IL_004f;
case 1:
<>1__state = -1;
goto IL_004f;
case 2:
{
<>1__state = -1;
<>4__this.SpawnFirewoodNearNaturalObjects();
return false;
}
IL_004f:
if (!PhotonNetwork.InRoom || !Object.op_Implicit((Object)(object)Character.localCharacter) || LoadingScreenHandler.loading)
{
<>2__current = (object)new WaitForSeconds(1f);
<>1__state = 1;
return true;
}
<>2__current = (object)new WaitForSeconds(3f);
<>1__state = 2;
return true;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
public static CampfireBuildingPlugin instance;
private readonly Harmony harmony = new Harmony("tony4twentys.Campfire_Building");
private static ManualLogSource logger;
private void Awake()
{
instance = this;
logger = ((BaseUnityPlugin)this).Logger;
logger.LogInfo((object)"Plugin Campfire Building is loaded!");
harmony.PatchAll();
SceneManager.activeSceneChanged += OnSceneChanged;
((MonoBehaviour)this).StartCoroutine(WaitForRunStart());
}
[IteratorStateMachine(typeof(<WaitForRunStart>d__4))]
private IEnumerator WaitForRunStart()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <WaitForRunStart>d__4(0)
{
<>4__this = this
};
}
private void OnSceneChanged(Scene oldScene, Scene newScene)
{
if (((Scene)(ref newScene)).name != "Airport" && ((Scene)(ref newScene)).name != ((Scene)(ref oldScene)).name)
{
((MonoBehaviour)this).StartCoroutine(SpawnFirewoodAfterSceneLoad());
}
}
[IteratorStateMachine(typeof(<SpawnFirewoodAfterSceneLoad>d__6))]
private IEnumerator SpawnFirewoodAfterSceneLoad()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <SpawnFirewoodAfterSceneLoad>d__6(0)
{
<>4__this = this
};
}
public void SpawnFirewoodNearNaturalObjects()
{
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
if (!PhotonNetwork.IsMasterClient)
{
logger.LogInfo((object)"Not master client, skipping firewood spawning");
return;
}
try
{
GameObject[] array = Object.FindObjectsByType<GameObject>((FindObjectsSortMode)0);
int num = 0;
int currentAscent = Ascents.currentAscent;
logger.LogInfo((object)$"Current ascent level: {currentAscent}");
GameObject[] array2 = array;
foreach (GameObject val in array2)
{
string text = ((Object)val).name.ToLower();
float num2 = 0f;
int num3 = 1;
if (text.Contains("tree") || text.Contains("pine"))
{
num2 = ((currentAscent >= 6) ? 0.01f : ((currentAscent < 3) ? 0.03f : 0.02f));
}
else if (text.Contains("bush"))
{
num2 = 0.01f;
}
else if (text.Contains("nest"))
{
num2 = 1f;
num3 = ((currentAscent >= 3) ? 1 : 2);
}
else if (text.Contains("tumbleweed"))
{
num2 = 1f;
num3 = ((currentAscent >= 3) ? 1 : 2);
}
if (num2 > 0f && Random.Range(0f, 1f) < num2)
{
for (int j = 0; j < num3; j++)
{
Vector3 position = val.transform.position + new Vector3(Random.Range(-5f, 5f), Random.Range(0f, 2f), Random.Range(-5f, 5f));
SpawnFirewoodAtPosition(position);
num++;
}
}
}
if (num > 0)
{
logger.LogInfo((object)$"Spawned {num} firewood items near natural objects");
}
}
catch
{
}
}
public void CleanupOldFirewood()
{
if (!PhotonNetwork.IsMasterClient)
{
logger.LogInfo((object)"Not master client, skipping firewood cleanup");
return;
}
try
{
Item[] array = Object.FindObjectsByType<Item>((FindObjectsSortMode)0);
int num = 0;
Item[] array2 = array;
foreach (Item val in array2)
{
if (val.itemID == 28 && (Object)(object)((Component)val).gameObject != (Object)null)
{
PhotonNetwork.Destroy(((Component)val).gameObject);
num++;
}
}
if (num > 0)
{
logger.LogInfo((object)$"Cleaned up {num} old firewood items");
}
}
catch
{
}
}
private void SpawnFirewoodAtPosition(Vector3 position)
{
//IL_0007: 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)
try
{
GameObject val = PhotonNetwork.Instantiate("0_Items/FireWood", position, Random.rotation, (byte)0, (object[])null);
if ((Object)(object)val != (Object)null)
{
Item component = val.GetComponent<Item>();
if ((Object)(object)component != (Object)null)
{
component.itemID = 28;
}
}
}
catch
{
}
}
private void OnDestroy()
{
harmony.UnpatchSelf();
SceneManager.activeSceneChanged -= OnSceneChanged;
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "tony4twentys.Campfire_Building";
public const string PLUGIN_NAME = "Campfire Building";
public const string PLUGIN_VERSION = "1.0.0";
}
[HarmonyPatch]
public static class CampfirePatches
{
[CompilerGenerated]
private sealed class <SpawnFirewoodInNewSegment>d__2 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <SpawnFirewoodInNewSegment>d__2(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
if ((Object)(object)CampfireBuildingPlugin.instance != (Object)null)
{
CampfireBuildingPlugin.instance.CleanupOldFirewood();
}
<>2__current = (object)new WaitForSeconds(10f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
if ((Object)(object)CampfireBuildingPlugin.instance != (Object)null)
{
CampfireBuildingPlugin.instance.SpawnFirewoodNearNaturalObjects();
}
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
[HarmonyPatch(typeof(Campfire), "Awake")]
[HarmonyPostfix]
public static void Awake_Postfix(Campfire __instance)
{
EnhancedCampfireSystem.SetFireWoodCount(__instance, 0);
}
[HarmonyPatch(typeof(MapHandler), "GoToSegment")]
[HarmonyPostfix]
public static void GoToSegment_Postfix(MapHandler __instance, Segment s)
{
((MonoBehaviour)__instance).StartCoroutine(SpawnFirewoodInNewSegment());
}
[IteratorStateMachine(typeof(<SpawnFirewoodInNewSegment>d__2))]
private static IEnumerator SpawnFirewoodInNewSegment()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <SpawnFirewoodInNewSegment>d__2(0);
}
[HarmonyPatch(typeof(Campfire), "SetFireWoodCount")]
[HarmonyPrefix]
public static bool SetFireWoodCount_Prefix(Campfire __instance, int count)
{
EnhancedCampfireSystem.SetFireWoodCount(__instance, count);
return false;
}
[HarmonyPatch(typeof(Campfire), "GetInteractionText")]
[HarmonyPrefix]
public static bool GetInteractionText_Prefix(Campfire __instance, ref string __result)
{
__result = EnhancedCampfireSystem.GetInteractionText(__instance);
return false;
}
[HarmonyPatch(typeof(Campfire), "Interact")]
[HarmonyPrefix]
public static bool Interact_Prefix(Campfire __instance, Character interactor)
{
return EnhancedCampfireSystem.Interact(__instance, interactor);
}
[HarmonyPatch(typeof(Campfire), "Interact_CastFinished")]
[HarmonyPrefix]
public static bool Interact_CastFinished_Prefix(Campfire __instance, Character interactor)
{
return EnhancedCampfireSystem.Interact_CastFinished(__instance, interactor);
}
}
public static class EnhancedCampfireSystem
{
private static Dictionary<Campfire, int> firewoodCounts = new Dictionary<Campfire, int>();
private static int GetFirewoodCount(Campfire campfire)
{
if (firewoodCounts.ContainsKey(campfire))
{
return firewoodCounts[campfire];
}
return 0;
}
private static void SetFirewoodCount(Campfire campfire, int count)
{
firewoodCounts[campfire] = count;
}
public static void SetFireWoodCount(Campfire campfire, int count)
{
SetFirewoodCount(campfire, count);
Debug.Log((object)$"[Campfire Building] SetFireWoodCount called with count: {count}");
Transform val = FindLogsObject(campfire);
if ((Object)(object)val != (Object)null)
{
Debug.Log((object)$"[Campfire Building] logRoot found! Name: {((Object)val).name}, Child count: {val.childCount}");
for (int i = 0; i < val.childCount; i++)
{
((Component)val.GetChild(i)).gameObject.SetActive(false);
}
if (count >= 1)
{
SetLogActive(val, 0, active: true);
SetLogActive(val, 5, active: true);
}
if (count >= 2)
{
SetLogActive(val, 2, active: true);
SetLogActive(val, 3, active: true);
}
if (count >= 3)
{
SetLogActive(val, 1, active: true);
SetLogActive(val, 4, active: true);
}
}
else
{
Debug.LogError((object)"[Campfire Building] Could not find Logs object!");
}
}
private static Transform FindLogsObject(Campfire campfire)
{
if ((Object)(object)campfire.logRoot != (Object)null)
{
Debug.Log((object)("[Campfire Building] Found logRoot via field: " + ((Object)campfire.logRoot).name));
return campfire.logRoot;
}
return FindLogsRecursive(((Component)campfire).transform, 0);
}
private static Transform FindLogsRecursive(Transform parent, int depth)
{
if (depth > 3)
{
return null;
}
for (int i = 0; i < parent.childCount; i++)
{
Transform child = parent.GetChild(i);
if (((Object)child).name.Contains("Logs"))
{
Debug.Log((object)$"[Campfire Building] Found logRoot at depth {depth}: {((Object)child).name}");
return child;
}
Transform val = FindLogsRecursive(child, depth + 1);
if ((Object)(object)val != (Object)null)
{
return val;
}
}
return null;
}
private static void SetLogActive(Transform logRoot, int index, bool active)
{
if (index < logRoot.childCount)
{
Transform child = logRoot.GetChild(index);
if ((Object)(object)child != (Object)null)
{
((Component)child).gameObject.SetActive(active);
Debug.Log((object)string.Format("[Campfire Building] Log {0}: {1} -> {2}", index, ((Object)child).name, active ? "ON" : "OFF"));
}
}
}
public static string GetInteractionText(Campfire campfire)
{
if (!campfire.Lit)
{
int firewoodCount = GetFirewoodCount(campfire);
int num = 3;
if (firewoodCount >= num)
{
string result = default(string);
if (!campfire.EveryoneInRange(ref result))
{
return result;
}
return "LIGHT";
}
return $"ADD FIREWOOD ({firewoodCount}/{num})";
}
return "COOK";
}
public static bool Interact(Campfire campfire, Character interactor)
{
Debug.Log((object)string.Format("[Campfire Building] Interact called - Fire lit: {0}, Current item: {1}", campfire.Lit, ((Object)(object)interactor.data.currentItem != (Object)null) ? ((Object)interactor.data.currentItem).name : "null"));
if (campfire.Lit && (Object)(object)interactor.data.currentItem != (Object)null && interactor.data.currentItem.cooking.canBeCooked)
{
Debug.Log((object)"[Campfire Building] Allowing cooking interaction");
return true;
}
if (!campfire.Lit)
{
int firewoodCount = GetFirewoodCount(campfire);
Debug.Log((object)$"[Campfire Building] Fire not lit, current firewood count: {firewoodCount}");
if (firewoodCount >= 3)
{
Debug.Log((object)"[Campfire Building] Enough firewood, allowing lighting");
return true;
}
if (firewoodCount < 3 && (Object)(object)interactor.data.currentItem != (Object)null && IsFirewoodItem(interactor.data.currentItem))
{
Debug.Log((object)$"[Campfire Building] Adding firewood! Current: {firewoodCount}, Adding 1");
SetFireWoodCount(campfire, firewoodCount + 1);
PhotonView component = ((Component)campfire).GetComponent<PhotonView>();
if ((Object)(object)component != (Object)null)
{
component.RPC("SetFireWoodCount", (RpcTarget)1, new object[1] { firewoodCount + 1 });
}
int num = -1;
if ((Object)(object)((MonoBehaviourPun)interactor).photonView != (Object)null)
{
num = ((MonoBehaviourPun)interactor).photonView.ViewID;
}
interactor.data.currentItem.Consume(num);
Debug.Log((object)"[Campfire Building] Firewood consumed, skipping original method");
return false;
}
Debug.Log((object)"[Campfire Building] Not enough firewood and no firewood item, preventing interaction");
return false;
}
return true;
}
public static bool Interact_CastFinished(Campfire campfire, Character interactor)
{
if (campfire.Lit)
{
return true;
}
int firewoodCount = GetFirewoodCount(campfire);
if (firewoodCount >= 3)
{
return true;
}
return false;
}
private static bool IsFirewoodItem(Item item)
{
return (Object)(object)item != (Object)null && item.itemID == 28;
}
}