Decompiled source of Campfire Refuel v1.2.0

CampfireRefuel.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using Zorro.Core.Serizalization;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("CampfireRefuel")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CampfireRefuel")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("1C6F139B-D451-4327-BCEA-A82A0E66DE5C")]
[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")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CampfireRefuel
{
	[BepInPlugin("HnskNoah.CampfireRefuel", "Campfire Refuel", "1.2.0")]
	public class CampfireRefuel : BaseUnityPlugin
	{
		public static ConfigEntry<bool> ConfigEnabled;

		public static FieldInfo FuelField = typeof(Lantern).GetField("fuel", BindingFlags.Instance | BindingFlags.NonPublic);

		private void Awake()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			ConfigEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable Refuel", true, "是否启用篝火点燃时回满提灯燃料的功能");
			new Harmony("HnskNoah.CampfireRefuel").PatchAll();
		}
	}
	[HarmonyPatch(typeof(Campfire), "Light_Rpc")]
	public static class Patch_Campfire
	{
		private static void Postfix()
		{
			if (CampfireRefuel.ConfigEnabled.Value && PhotonNetwork.IsMasterClient)
			{
				RefuelAllLanterns();
				Debug.Log((object)"[CampfireRefuel] 房主已完成全场提灯燃料补充。");
			}
		}

		private static void RefuelAllLanterns()
		{
			RefuelLanternsInInventory();
			RefuelLanternsInWorld();
		}

		private static void RefuelLanternsInInventory()
		{
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			FloatItemData val2 = default(FloatItemData);
			FloatItemData val3 = default(FloatItemData);
			InventorySyncData val4 = default(InventorySyncData);
			foreach (Character allCharacter in Character.AllCharacters)
			{
				Player player = allCharacter.player;
				if ((Object)(object)player == (Object)null)
				{
					continue;
				}
				bool flag = false;
				ItemSlot[] itemSlots = player.itemSlots;
				foreach (ItemSlot val in itemSlots)
				{
					if (val != null && !val.IsEmpty() && (Object)(object)val.prefab != (Object)null && val.prefab.itemID == 42)
					{
						float value = 60f;
						Lantern component = ((Component)val.prefab).GetComponent<Lantern>();
						if ((Object)(object)component != (Object)null)
						{
							value = component.startingFuel;
						}
						val.data.TryGetDataEntry<FloatItemData>((DataEntryKey)10, ref val2);
						val2.Value = value;
						val.data.TryGetDataEntry<FloatItemData>((DataEntryKey)11, ref val3);
						val3.Value = 1f;
						flag = true;
					}
				}
				if (flag && (Object)(object)((MonoBehaviourPun)player).photonView != (Object)null)
				{
					((InventorySyncData)(ref val4))..ctor(player.itemSlots, player.backpackSlot, player.tempFullSlot);
					((MonoBehaviourPun)player).photonView.RPC("SyncInventoryRPC", (RpcTarget)1, new object[2]
					{
						IBinarySerializable.ToManagedArray<InventorySyncData>(val4),
						false
					});
				}
			}
			Debug.Log((object)"[CampfireRefuel] 已完成物品栏提灯燃料补充。");
		}

		private static void RefuelLanternsInWorld()
		{
			Lantern[] array = Object.FindObjectsByType<Lantern>((FindObjectsSortMode)0);
			if (array == null || array.Length == 0)
			{
				return;
			}
			Lantern[] array2 = array;
			foreach (Lantern val in array2)
			{
				Item item = ((ItemComponent)val).item;
				if ((Object)(object)item != (Object)null && item.itemID == 42)
				{
					float startingFuel = val.startingFuel;
					CampfireRefuel.FuelField?.SetValue(val, startingFuel);
					FloatItemData data = item.GetData<FloatItemData>((DataEntryKey)10);
					if (data != null)
					{
						data.Value = startingFuel;
						item.SetUseRemainingPercentage(1f);
					}
				}
			}
			Debug.Log((object)"[CampfireRefuel] 已完成场上提灯实体燃料补充。");
		}
	}
}