Decompiled source of RechargeHealthPacks v4.0.0

RechargeHealthPacks.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("REPOJP")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("zabuMod")]
[assembly: AssemblyTitle("zabuMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 REPOJP.RechargeHealthPacks
{
	[BepInPlugin("REPOJP.RechargeHealthPacks", "RechargeHealthPacks", "4.0.0")]
	public class RechargeHealthPacksPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "REPOJP.RechargeHealthPacks";

		public const string PluginName = "RechargeHealthPacks";

		public const string PluginVersion = "4.0.0";

		internal static ManualLogSource Log = Logger.CreateLogSource("RechargeHealthPacks");

		internal static ConfigEntry<bool> ModEnabled;

		internal static ConfigEntry<int> SmallHealthPackChargeCost;

		internal static ConfigEntry<int> MediumHealthPackChargeCost;

		internal static ConfigEntry<int> LargeHealthPackChargeCost;

		internal static ConfigEntry<float> CheckInterval;

		internal static ConfigEntry<bool> DestroyUsedPackAfterRecharge;

		internal static ConfigEntry<bool> ProtectUsedPackInTruck;

		internal static ConfigEntry<bool> DebugLog;

		internal static RechargeHealthPacksPlugin Instance;

		private Harmony harmony;

		private void Awake()
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Expected O, but got Unknown
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Expected O, but got Unknown
			try
			{
				((Component)this).transform.parent = null;
				((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
				Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
				Instance = this;
				ModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ModEnabled", true, "Enable this mod.このMODを有効化します。");
				SmallHealthPackChargeCost = ((BaseUnityPlugin)this).Config.Bind<int>("Charge Cost", "SmallHealthPackChargeCost", 2, new ConfigDescription("Charge consumed to restore a used small health pack.使用済み小ヘルスパックの再生成に消費する充電量。", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
				MediumHealthPackChargeCost = ((BaseUnityPlugin)this).Config.Bind<int>("Charge Cost", "MediumHealthPackChargeCost", 5, new ConfigDescription("Charge consumed to restore a used medium health pack.使用済み中ヘルスパックの再生成に消費する充電量。", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
				LargeHealthPackChargeCost = ((BaseUnityPlugin)this).Config.Bind<int>("Charge Cost", "LargeHealthPackChargeCost", 8, new ConfigDescription("Charge consumed to restore a used large health pack.使用済み大ヘルスパックの再生成に消費する充電量。", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
				CheckInterval = ((BaseUnityPlugin)this).Config.Bind<float>("General", "CheckInterval", 0.5f, new ConfigDescription("Interval in seconds for checking used health packs in the charging station area.充電所内の使用済みヘルスパックを確認する間隔秒。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 5f), Array.Empty<object>()));
				DestroyUsedPackAfterRecharge = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DestroyUsedPackAfterRecharge", true, "Destroy the used health pack after spawning a restored one.新品を生成した後に使用済みヘルスパックを削除します。");
				ProtectUsedPackInTruck = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ProtectUsedPackInTruck", true, "Protect used health packs from being destroyed while they are inside the truck or cart area.使用済みヘルスパックがトラック内またはカート内にある間は破壊を抑止します。");
				DebugLog = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "DebugLog", false, "Enable detailed debug logs.詳細なデバッグログを有効化します。");
				harmony = new Harmony("REPOJP.RechargeHealthPacks");
				harmony.PatchAll();
				Log.LogInfo((object)"RechargeHealthPacks v4.0.0 loaded.");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Failure: Awake\n" + ex));
			}
		}

		private void OnDestroy()
		{
			try
			{
				if (harmony != null)
				{
					harmony.UnpatchSelf();
				}
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Failure: OnDestroy\n" + ex));
			}
		}
	}
	[HarmonyPatch(typeof(ChargingStation), "Update")]
	internal static class ChargingStationUpdatePatch
	{
		private static readonly Dictionary<int, float> checkTimers = new Dictionary<int, float>();

		private static readonly HashSet<int> processingPacks = new HashSet<int>();

		private static readonly HashSet<int> rechargedPacks = new HashSet<int>();

		private static readonly FieldInfo chargeAreaField = AccessTools.Field(typeof(ChargingStation), "chargeArea");

		private static readonly FieldInfo photonViewField = AccessTools.Field(typeof(ChargingStation), "photonView");

		private static readonly FieldInfo chargeFloatField = AccessTools.Field(typeof(ChargingStation), "chargeFloat");

		private static readonly FieldInfo chargeSegmentsField = AccessTools.Field(typeof(ChargingStation), "chargeSegments");

		private static readonly FieldInfo chargeSegmentCurrentField = AccessTools.Field(typeof(ChargingStation), "chargeSegmentCurrent");

		private static readonly FieldInfo lastSentSegmentField = AccessTools.Field(typeof(ChargingStation), "lastSentSegment");

		private static readonly FieldInfo usedField = AccessTools.Field(typeof(ItemHealthPack), "used");

		private static readonly MethodInfo crystalsItShouldHaveMethod = AccessTools.Method(typeof(ChargingStation), "CrystalsItShouldHave", (Type[])null, (Type[])null);

		private static void Postfix(ChargingStation __instance)
		{
			try
			{
				if (RechargeHealthPacksPlugin.ModEnabled.Value && !((Object)(object)__instance == (Object)null) && !((Object)(object)RunManager.instance == (Object)null) && !SemiFunc.RunIsShop() && !RunManager.instance.levelIsShop && !RunManager.instance.restarting && SemiFunc.IsMasterClientOrSingleplayer())
				{
					int instanceID = ((Object)__instance).GetInstanceID();
					float value = 0f;
					checkTimers.TryGetValue(instanceID, out value);
					value += Time.deltaTime;
					if (value < RechargeHealthPacksPlugin.CheckInterval.Value)
					{
						checkTimers[instanceID] = value;
						return;
					}
					checkTimers[instanceID] = 0f;
					TryRechargeUsedHealthPack(__instance);
				}
			}
			catch (Exception ex)
			{
				RechargeHealthPacksPlugin.Log.LogError((object)("Failure: ChargingStation Update patch\n" + ex));
			}
		}

		private static void TryRechargeUsedHealthPack(ChargingStation station)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Transform fieldValue = GetFieldValue<Transform>(chargeAreaField, station);
				if ((Object)(object)fieldValue == (Object)null)
				{
					return;
				}
				Collider[] array = Physics.OverlapBox(fieldValue.position, fieldValue.lossyScale / 2f, fieldValue.rotation, LayerMask.op_Implicit(SemiFunc.LayerMaskGetPhysGrabObject()), (QueryTriggerInteraction)2);
				foreach (Collider val in array)
				{
					if (!((Object)(object)val == (Object)null))
					{
						ItemHealthPack componentInParent = ((Component)val).GetComponentInParent<ItemHealthPack>();
						if (!((Object)(object)componentInParent == (Object)null) && TryProcessHealthPack(station, componentInParent))
						{
							break;
						}
					}
				}
			}
			catch (Exception ex)
			{
				RechargeHealthPacksPlugin.Log.LogError((object)("Failure: TryRechargeUsedHealthPack\n" + ex));
			}
		}

		private static bool TryProcessHealthPack(ChargingStation station, ItemHealthPack healthPack)
		{
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			try
			{
				num = GetStablePackId(healthPack);
				if (processingPacks.Contains(num) || rechargedPacks.Contains(num))
				{
					return false;
				}
				if (!IsUsedHealthPack(healthPack))
				{
					return false;
				}
				int chargeCost = GetChargeCost(healthPack.healAmount);
				if (chargeCost < 0)
				{
					WriteDebug("Unsupported health pack heal amount: " + healthPack.healAmount);
					return false;
				}
				if (station.chargeTotal < chargeCost)
				{
					WriteDebug("Not enough charge. Required=" + chargeCost + " Current=" + station.chargeTotal);
					return false;
				}
				ItemAttributes component = ((Component)healthPack).GetComponent<ItemAttributes>();
				if ((Object)(object)component == (Object)null || (Object)(object)component.item == (Object)null || component.item.prefab == null)
				{
					WriteDebug("ItemAttributes or item prefab is missing.");
					return false;
				}
				string resourcePath = component.item.prefab.ResourcePath;
				if (string.IsNullOrEmpty(resourcePath))
				{
					WriteDebug("ResourcePath is empty.");
					return false;
				}
				if (SemiFunc.IsMultiplayer() && !PhotonNetwork.InRoom)
				{
					WriteDebug("Photon room is not ready.");
					return false;
				}
				processingPacks.Add(num);
				Vector3 position = ((Component)healthPack).transform.position;
				Quaternion rotation = ((Component)healthPack).transform.rotation;
				ConsumeCharge(station, chargeCost);
				GameObject val = SpawnRestoredHealthPack(component, resourcePath, position, rotation);
				if ((Object)(object)val == (Object)null)
				{
					WriteDebug("Failed to spawn restored health pack.");
					return false;
				}
				ResetSpawnedPhysics(val);
				rechargedPacks.Add(num);
				if (RechargeHealthPacksPlugin.DestroyUsedPackAfterRecharge.Value)
				{
					DestroyUsedHealthPack(healthPack);
				}
				WriteDebug("Recharged health pack. HealAmount=" + healthPack.healAmount + " Cost=" + chargeCost + " RemainingCharge=" + station.chargeTotal);
				return true;
			}
			catch (Exception ex)
			{
				RechargeHealthPacksPlugin.Log.LogError((object)("Failure: Process used health pack\n" + ex));
				return false;
			}
			finally
			{
				if (num != 0 && processingPacks.Contains(num))
				{
					processingPacks.Remove(num);
				}
			}
		}

		private static GameObject SpawnRestoredHealthPack(ItemAttributes itemAttributes, string resourcePath, Vector3 spawnPosition, Quaternion spawnRotation)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (SemiFunc.IsMultiplayer())
				{
					return PhotonNetwork.InstantiateRoomObject(resourcePath, spawnPosition, spawnRotation, (byte)0, (object[])null);
				}
				GameObject prefab = itemAttributes.item.prefab.Prefab;
				if ((Object)(object)prefab == (Object)null)
				{
					return null;
				}
				return Object.Instantiate<GameObject>(prefab, spawnPosition, spawnRotation);
			}
			catch (Exception ex)
			{
				RechargeHealthPacksPlugin.Log.LogError((object)("Failure: Spawn restored health pack\n" + ex));
				return null;
			}
		}

		private static bool IsUsedHealthPack(ItemHealthPack healthPack)
		{
			try
			{
				if ((Object)(object)healthPack == (Object)null || usedField == null)
				{
					return false;
				}
				object value = usedField.GetValue(healthPack);
				return value is bool && (bool)value;
			}
			catch (Exception ex)
			{
				RechargeHealthPacksPlugin.Log.LogError((object)("Failure: Used health pack check\n" + ex));
				return false;
			}
		}

		private static int GetStablePackId(ItemHealthPack healthPack)
		{
			if ((Object)(object)healthPack == (Object)null)
			{
				return 0;
			}
			PhotonView component = ((Component)healthPack).GetComponent<PhotonView>();
			if ((Object)(object)component != (Object)null && component.ViewID != 0)
			{
				return component.ViewID;
			}
			return ((Object)healthPack).GetInstanceID();
		}

		private static int GetChargeCost(int healAmount)
		{
			if (healAmount <= 25)
			{
				return Mathf.Clamp(RechargeHealthPacksPlugin.SmallHealthPackChargeCost.Value, 0, 100);
			}
			if (healAmount <= 50)
			{
				return Mathf.Clamp(RechargeHealthPacksPlugin.MediumHealthPackChargeCost.Value, 0, 100);
			}
			if (healAmount <= 100)
			{
				return Mathf.Clamp(RechargeHealthPacksPlugin.LargeHealthPackChargeCost.Value, 0, 100);
			}
			return -1;
		}

		private static void ResetSpawnedPhysics(GameObject newObject)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)newObject == (Object)null)
				{
					return;
				}
				Rigidbody[] componentsInChildren = newObject.GetComponentsInChildren<Rigidbody>();
				foreach (Rigidbody val in componentsInChildren)
				{
					if (!((Object)(object)val == (Object)null) && !val.isKinematic)
					{
						val.velocity = Vector3.zero;
						val.angularVelocity = Vector3.zero;
					}
				}
			}
			catch (Exception ex)
			{
				RechargeHealthPacksPlugin.Log.LogError((object)("Failure: Reset spawned physics\n" + ex));
			}
		}

		private static void ConsumeCharge(ChargingStation station, int cost)
		{
			try
			{
				int chargeTotal = Mathf.Clamp(station.chargeTotal - cost, 0, 100);
				station.chargeTotal = chargeTotal;
				if ((Object)(object)StatsManager.instance != (Object)null && StatsManager.instance.runStats != null)
				{
					StatsManager.instance.runStats["chargingStationChargeTotal"] = station.chargeTotal;
				}
				int chargeSegments = GetChargeSegments(station);
				float num = Mathf.Clamp01((float)station.chargeTotal / 100f);
				int num2 = Mathf.CeilToInt(num * (float)chargeSegments);
				num2 = Mathf.Clamp(num2, 0, chargeSegments);
				SetFieldValue(chargeFloatField, station, num);
				SetFieldValue(chargeSegmentCurrentField, station, num2);
				SetFieldValue(lastSentSegmentField, station, num2);
				if (crystalsItShouldHaveMethod != null)
				{
					crystalsItShouldHaveMethod.Invoke(station, null);
				}
				PhotonView val = GetFieldValue<PhotonView>(photonViewField, station);
				if ((Object)(object)val == (Object)null)
				{
					val = ((Component)station).GetComponent<PhotonView>();
				}
				if (SemiFunc.IsMultiplayer() && (Object)(object)val != (Object)null && PhotonNetwork.InRoom)
				{
					PhotonNetwork.RemoveBufferedRPCs(val.ViewID, "ChargingStationSegmentChangedRPC", (int[])null);
					val.RPC("ChargingStationSegmentChangedRPC", (RpcTarget)3, new object[1] { (byte)num2 });
				}
			}
			catch (Exception ex)
			{
				RechargeHealthPacksPlugin.Log.LogError((object)("Failure: Consume charge\n" + ex));
			}
		}

		private static int GetChargeSegments(ChargingStation station)
		{
			object obj = null;
			if (chargeSegmentsField != null)
			{
				obj = chargeSegmentsField.GetValue(station);
			}
			if (obj is int)
			{
				return Mathf.Max(1, (int)obj);
			}
			return Mathf.Max(1, station.chargeSegments);
		}

		private static void DestroyUsedHealthPack(ItemHealthPack healthPack)
		{
			try
			{
				if ((Object)(object)healthPack == (Object)null)
				{
					return;
				}
				GameObject gameObject = ((Component)healthPack).gameObject;
				if ((Object)(object)gameObject == (Object)null)
				{
					return;
				}
				if (SemiFunc.IsMultiplayer() && PhotonNetwork.InRoom)
				{
					PhotonView component = gameObject.GetComponent<PhotonView>();
					if ((Object)(object)component != (Object)null)
					{
						PhotonNetwork.Destroy(gameObject);
						return;
					}
				}
				Object.Destroy((Object)(object)gameObject);
			}
			catch (Exception ex)
			{
				RechargeHealthPacksPlugin.Log.LogError((object)("Failure: Destroy used health pack\n" + ex));
			}
		}

		private static T GetFieldValue<T>(FieldInfo fieldInfo, object target) where T : class
		{
			if (fieldInfo == null || target == null)
			{
				return null;
			}
			return fieldInfo.GetValue(target) as T;
		}

		private static void SetFieldValue(FieldInfo fieldInfo, object target, object value)
		{
			if (!(fieldInfo == null) && target != null)
			{
				fieldInfo.SetValue(target, value);
			}
		}

		private static void WriteDebug(string message)
		{
			if (RechargeHealthPacksPlugin.DebugLog.Value)
			{
				RechargeHealthPacksPlugin.Log.LogInfo((object)message);
			}
		}
	}
	internal static class UsedHealthPackTruckProtection
	{
		private static readonly FieldInfo usedField = AccessTools.Field(typeof(ItemHealthPack), "used");

		private static readonly FieldInfo timerInCartField = AccessTools.Field(typeof(PhysGrabObjectImpactDetector), "timerInCart");

		private static readonly FieldInfo timerInSafeAreaField = AccessTools.Field(typeof(PhysGrabObjectImpactDetector), "timerInSafeArea");

		private static readonly FieldInfo currentCartField = AccessTools.Field(typeof(PhysGrabObjectImpactDetector), "currentCart");

		private static readonly FieldInfo currentCartPrevField = AccessTools.Field(typeof(PhysGrabObjectImpactDetector), "currentCartPrev");

		private static readonly FieldInfo breakForceField = AccessTools.Field(typeof(PhysGrabObjectImpactDetector), "breakForce");

		private static readonly FieldInfo impactForceField = AccessTools.Field(typeof(PhysGrabObjectImpactDetector), "impactForce");

		private static readonly FieldInfo rbField = AccessTools.Field(typeof(PhysGrabObjectImpactDetector), "rb");

		internal static bool ShouldProtect(PhysGrabObjectImpactDetector impactDetector)
		{
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!RechargeHealthPacksPlugin.ModEnabled.Value || !RechargeHealthPacksPlugin.ProtectUsedPackInTruck.Value)
				{
					return false;
				}
				if ((Object)(object)impactDetector == (Object)null || (Object)(object)((Component)impactDetector).gameObject == (Object)null)
				{
					return false;
				}
				if (!IsUsedHealthPack(((Component)impactDetector).gameObject))
				{
					return false;
				}
				if (impactDetector.inCart)
				{
					return true;
				}
				if (GetFloat(timerInCartField, impactDetector) > 0f)
				{
					return true;
				}
				if (GetFloat(timerInSafeAreaField, impactDetector) > 0f)
				{
					return true;
				}
				if (!IsNullUnity(GetObject(currentCartField, impactDetector)))
				{
					return true;
				}
				if (!IsNullUnity(GetObject(currentCartPrevField, impactDetector)))
				{
					return true;
				}
				if (IsInsideTruckRoomVolume(((Component)impactDetector).transform.position))
				{
					return true;
				}
				object @object = GetObject(rbField, impactDetector);
				Rigidbody val = (Rigidbody)((@object is Rigidbody) ? @object : null);
				if ((Object)(object)val != (Object)null && IsInsideTruckRoomVolume(val.worldCenterOfMass))
				{
					return true;
				}
				Collider[] componentsInChildren = ((Component)impactDetector).GetComponentsInChildren<Collider>();
				foreach (Collider val2 in componentsInChildren)
				{
					if (!((Object)(object)val2 == (Object)null))
					{
						Bounds bounds = val2.bounds;
						if (IsInsideTruckRoomVolume(((Bounds)(ref bounds)).center))
						{
							return true;
						}
					}
				}
				return false;
			}
			catch (Exception ex)
			{
				RechargeHealthPacksPlugin.Log.LogError((object)("Failure: Used health pack truck protection check\n" + ex));
				return false;
			}
		}

		internal static void ApplyProtection(PhysGrabObjectImpactDetector impactDetector)
		{
			try
			{
				if (ShouldProtect(impactDetector))
				{
					SetFloat(breakForceField, impactDetector, 0f);
					SetFloat(impactForceField, impactDetector, 0f);
					PhysGrabObject component = ((Component)impactDetector).GetComponent<PhysGrabObject>();
					if ((Object)(object)component != (Object)null)
					{
						component.dead = false;
						component.OverrideIndestructible(0.5f);
					}
				}
			}
			catch (Exception ex)
			{
				RechargeHealthPacksPlugin.Log.LogError((object)("Failure: Apply used health pack protection\n" + ex));
			}
		}

		private static bool IsUsedHealthPack(GameObject target)
		{
			try
			{
				if ((Object)(object)target == (Object)null || usedField == null)
				{
					return false;
				}
				ItemHealthPack val = target.GetComponent<ItemHealthPack>();
				if ((Object)(object)val == (Object)null)
				{
					val = target.GetComponentInParent<ItemHealthPack>();
				}
				if ((Object)(object)val == (Object)null)
				{
					return false;
				}
				object value = usedField.GetValue(val);
				return value is bool && (bool)value;
			}
			catch (Exception ex)
			{
				RechargeHealthPacksPlugin.Log.LogError((object)("Failure: Used health pack object check\n" + ex));
				return false;
			}
		}

		private static bool IsInsideTruckRoomVolume(Vector3 position)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				int mask = LayerMask.GetMask(new string[1] { "RoomVolume" });
				if (mask == 0)
				{
					return false;
				}
				Collider[] array = Physics.OverlapSphere(position, 0.25f, mask, (QueryTriggerInteraction)2);
				foreach (Collider val in array)
				{
					if (!((Object)(object)val == (Object)null))
					{
						RoomVolume val2 = ((Component)val).GetComponent<RoomVolume>();
						if ((Object)(object)val2 == (Object)null)
						{
							val2 = ((Component)val).GetComponentInParent<RoomVolume>();
						}
						if ((Object)(object)val2 != (Object)null && val2.Truck)
						{
							return true;
						}
					}
				}
				return false;
			}
			catch (Exception ex)
			{
				RechargeHealthPacksPlugin.Log.LogError((object)("Failure: Truck RoomVolume check\n" + ex));
				return false;
			}
		}

		private static float GetFloat(FieldInfo fieldInfo, object target)
		{
			if (fieldInfo == null || target == null)
			{
				return 0f;
			}
			object value = fieldInfo.GetValue(target);
			if (value is float)
			{
				return (float)value;
			}
			return 0f;
		}

		private static object GetObject(FieldInfo fieldInfo, object target)
		{
			if (fieldInfo == null || target == null)
			{
				return null;
			}
			return fieldInfo.GetValue(target);
		}

		private static void SetFloat(FieldInfo fieldInfo, object target, float value)
		{
			if (!(fieldInfo == null) && target != null)
			{
				fieldInfo.SetValue(target, value);
			}
		}

		private static bool IsNullUnity(object obj)
		{
			Object val = (Object)((obj is Object) ? obj : null);
			if (val != (Object)null)
			{
				return false;
			}
			return obj == null;
		}
	}
	[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "Update")]
	internal static class UsedHealthPackImpactDetectorUpdatePatch
	{
		private static void Prefix(PhysGrabObjectImpactDetector __instance)
		{
			UsedHealthPackTruckProtection.ApplyProtection(__instance);
		}

		private static void Postfix(PhysGrabObjectImpactDetector __instance)
		{
			UsedHealthPackTruckProtection.ApplyProtection(__instance);
		}
	}
	[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "OnCollisionStay")]
	internal static class UsedHealthPackOnCollisionStayPatch
	{
		private static bool Prefix(PhysGrabObjectImpactDetector __instance)
		{
			if (UsedHealthPackTruckProtection.ShouldProtect(__instance))
			{
				UsedHealthPackTruckProtection.ApplyProtection(__instance);
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "BreakLight")]
	internal static class UsedHealthPackBreakLightPatch
	{
		private static bool Prefix(PhysGrabObjectImpactDetector __instance)
		{
			return !UsedHealthPackTruckProtection.ShouldProtect(__instance);
		}
	}
	[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "BreakMedium")]
	internal static class UsedHealthPackBreakMediumPatch
	{
		private static bool Prefix(PhysGrabObjectImpactDetector __instance)
		{
			return !UsedHealthPackTruckProtection.ShouldProtect(__instance);
		}
	}
	[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "BreakHeavy")]
	internal static class UsedHealthPackBreakHeavyPatch
	{
		private static bool Prefix(PhysGrabObjectImpactDetector __instance)
		{
			return !UsedHealthPackTruckProtection.ShouldProtect(__instance);
		}
	}
	[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "Break")]
	internal static class UsedHealthPackBreakPatch
	{
		private static bool Prefix(PhysGrabObjectImpactDetector __instance)
		{
			return !UsedHealthPackTruckProtection.ShouldProtect(__instance);
		}
	}
	[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "BreakRPC")]
	internal static class UsedHealthPackBreakRpcPatch
	{
		private static bool Prefix(PhysGrabObjectImpactDetector __instance)
		{
			return !UsedHealthPackTruckProtection.ShouldProtect(__instance);
		}
	}
	[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "DestroyObject")]
	internal static class UsedHealthPackDestroyObjectPatch
	{
		private static bool Prefix(PhysGrabObjectImpactDetector __instance)
		{
			return !UsedHealthPackTruckProtection.ShouldProtect(__instance);
		}
	}
	[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "DestroyObjectRPC")]
	internal static class UsedHealthPackDestroyObjectRpcPatch
	{
		private static bool Prefix(PhysGrabObjectImpactDetector __instance)
		{
			return !UsedHealthPackTruckProtection.ShouldProtect(__instance);
		}
	}
}