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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("REPOJP")]
[assembly: AssemblyConfiguration("Debug")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[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", "1.0.0")]
public class RechargeHealthPacksPlugin : BaseUnityPlugin
{
public const string PluginGuid = "REPOJP.RechargeHealthPacks";
public const string PluginName = "RechargeHealthPacks";
public const string PluginVersion = "1.0.0";
internal static ManualLogSource Log;
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> DebugLog;
internal static RechargeHealthPacksPlugin Instance;
private Harmony harmony;
private void Awake()
{
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Expected O, but got Unknown
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Expected O, but got Unknown
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Expected O, but got Unknown
//IL_011e: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Expected O, but got Unknown
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: 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);
Log = ((BaseUnityPlugin)this).Logger;
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.新品を生成した後に使用済みヘルスパックを削除します。");
DebugLog = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "DebugLog", false, "Enable detailed debug logs.詳細なデバッグログを有効化します。");
harmony = new Harmony("REPOJP.RechargeHealthPacks");
harmony.PatchAll();
Log.LogInfo((object)"RechargeHealthPacks v1.0.0 loaded.");
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Failure: Awake\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 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) && !SemiFunc.RunIsShop() && !((Object)(object)RunManager.instance == (Object)null) && !RunManager.instance.levelIsShop && 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_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: 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_0052: Unknown result type (might be due to invalid IL or missing references)
object? value = chargeAreaField.GetValue(station);
Transform val = (Transform)((value is Transform) ? value : null);
if ((Object)(object)val == (Object)null || station.chargeTotal <= 0)
{
return;
}
Collider[] array = Physics.OverlapBox(val.position, val.localScale / 2f, val.localRotation, LayerMask.op_Implicit(SemiFunc.LayerMaskGetPhysGrabObject()));
for (int i = 0; i < array.Length; i++)
{
ItemHealthPack componentInParent = ((Component)array[i]).GetComponentInParent<ItemHealthPack>();
if (!((Object)(object)componentInParent == (Object)null) && TryProcessHealthPack(station, componentInParent))
{
break;
}
}
}
private static bool TryProcessHealthPack(ChargingStation station, ItemHealthPack healthPack)
{
//IL_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_0188: Unknown result type (might be due to invalid IL or missing references)
//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
try
{
PhotonView component = ((Component)healthPack).GetComponent<PhotonView>();
int item = (((Object)(object)component != (Object)null) ? component.ViewID : ((Object)healthPack).GetInstanceID());
if (processingPacks.Contains(item))
{
return false;
}
object value = usedField.GetValue(healthPack);
if (!(value is bool) || !(bool)value)
{
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 component2 = ((Component)healthPack).GetComponent<ItemAttributes>();
if ((Object)(object)component2 == (Object)null || (Object)(object)component2.item == (Object)null || component2.item.prefab == null)
{
WriteDebug("ItemAttributes or item prefab is missing.");
return false;
}
string resourcePath = component2.item.prefab.ResourcePath;
if (string.IsNullOrEmpty(resourcePath))
{
WriteDebug("ResourcePath is empty.");
return false;
}
processingPacks.Add(item);
Vector3 position = ((Component)healthPack).transform.position;
Quaternion rotation = ((Component)healthPack).transform.rotation;
ConsumeCharge(station, chargeCost);
GameObject newObject = ((!SemiFunc.IsMultiplayer()) ? Object.Instantiate<GameObject>(component2.item.prefab.Prefab, position, rotation) : PhotonNetwork.InstantiateRoomObject(resourcePath, position, rotation, (byte)0, (object[])null));
ResetSpawnedPhysics(newObject);
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 ((Object)(object)healthPack != (Object)null)
{
PhotonView component3 = ((Component)healthPack).GetComponent<PhotonView>();
int item2 = (((Object)(object)component3 != (Object)null) ? component3.ViewID : ((Object)healthPack).GetInstanceID());
if (processingPacks.Contains(item2))
{
processingPacks.Remove(item2);
}
}
}
}
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_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: 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)
{
station.chargeTotal = Mathf.Clamp(station.chargeTotal - cost, 0, 100);
if ((Object)(object)StatsManager.instance != (Object)null && StatsManager.instance.runStats != null)
{
StatsManager.instance.runStats["chargingStationChargeTotal"] = station.chargeTotal;
}
int num = (int)chargeSegmentsField.GetValue(station);
float num2 = Mathf.Clamp01((float)station.chargeTotal / 100f);
int num3 = Mathf.CeilToInt(num2 * (float)num);
chargeFloatField.SetValue(station, num2);
chargeSegmentCurrentField.SetValue(station, num3);
lastSentSegmentField.SetValue(station, num3);
if (crystalsItShouldHaveMethod != null)
{
crystalsItShouldHaveMethod.Invoke(station, null);
}
object? value = photonViewField.GetValue(station);
PhotonView val = (PhotonView)((value is PhotonView) ? value : null);
if ((Object)(object)val == (Object)null)
{
val = ((Component)station).GetComponent<PhotonView>();
}
if (SemiFunc.IsMultiplayer() && (Object)(object)val != (Object)null)
{
val.RPC("ChargingStationSegmentChangedRPC", (RpcTarget)3, new object[1] { (byte)num3 });
}
}
private static void DestroyUsedHealthPack(ItemHealthPack healthPack)
{
GameObject gameObject = ((Component)healthPack).gameObject;
if (SemiFunc.IsMultiplayer())
{
PhotonView component = gameObject.GetComponent<PhotonView>();
if ((Object)(object)component != (Object)null)
{
PhotonNetwork.Destroy(gameObject);
return;
}
}
Object.Destroy((Object)(object)gameObject);
}
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 inCartField = AccessTools.Field(typeof(PhysGrabObjectImpactDetector), "inCart");
private static readonly FieldInfo timerInSafeAreaField = AccessTools.Field(typeof(PhysGrabObjectImpactDetector), "timerInSafeArea");
private static readonly FieldInfo currentCartField = AccessTools.Field(typeof(PhysGrabObjectImpactDetector), "currentCart");
internal static bool ShouldProtect(PhysGrabObjectImpactDetector impactDetector)
{
try
{
if (!RechargeHealthPacksPlugin.ModEnabled.Value)
{
return false;
}
if ((Object)(object)impactDetector == (Object)null)
{
return false;
}
ItemHealthPack component = ((Component)impactDetector).GetComponent<ItemHealthPack>();
if ((Object)(object)component == (Object)null)
{
return false;
}
object value = usedField.GetValue(component);
if (!(value is bool) || !(bool)value)
{
return false;
}
bool flag = false;
object value2 = inCartField.GetValue(impactDetector);
if (value2 is bool)
{
flag = (bool)value2;
}
float num = 0f;
object value3 = timerInSafeAreaField.GetValue(impactDetector);
if (value3 is float)
{
num = (float)value3;
}
object value4 = currentCartField.GetValue(impactDetector);
bool flag2 = !IsNullUnity(value4);
return flag || num > 0f || flag2;
}
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))
{
PhysGrabObject component = ((Component)impactDetector).GetComponent<PhysGrabObject>();
if ((Object)(object)component != (Object)null)
{
component.OverrideIndestructible(0.25f);
}
}
}
catch (Exception ex)
{
RechargeHealthPacksPlugin.Log.LogError((object)("Failure: Apply used health pack truck protection\n" + ex));
}
}
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 Postfix(PhysGrabObjectImpactDetector __instance)
{
UsedHealthPackTruckProtection.ApplyProtection(__instance);
}
}
[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), "DestroyObject")]
internal static class UsedHealthPackDestroyObjectPatch
{
private static bool Prefix(PhysGrabObjectImpactDetector __instance)
{
return !UsedHealthPackTruckProtection.ShouldProtect(__instance);
}
}
internal static class RobustUsedHealthPackTruckProtection
{
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_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
try
{
if (!RechargeHealthPacksPlugin.ModEnabled.Value)
{
return false;
}
if ((Object)(object)impactDetector == (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(currentCartField.GetValue(impactDetector)))
{
return true;
}
if (!IsNullUnity(currentCartPrevField.GetValue(impactDetector)))
{
return true;
}
if (IsInsideTruckRoomVolume(((Component)impactDetector).transform.position))
{
return true;
}
object? value = rbField.GetValue(impactDetector);
Rigidbody val = (Rigidbody)((value is Rigidbody) ? value : 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: Robust used health pack truck protection check\n" + ex));
return false;
}
}
internal static void ApplyProtection(PhysGrabObjectImpactDetector impactDetector)
{
try
{
if (ShouldProtect(impactDetector))
{
if (breakForceField != null)
{
breakForceField.SetValue(impactDetector, 0f);
}
if (impactForceField != null)
{
impactForceField.SetValue(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: Robust protection refresh\n" + ex));
}
}
private static bool IsUsedHealthPack(GameObject target)
{
try
{
if ((Object)(object)target == (Object)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: Robust used health pack check\n" + ex));
return false;
}
}
private static bool IsInsideTruckRoomVolume(Vector3 position)
{
//IL_0026: 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;
}
if (!(fieldInfo.GetValue(target) is float result))
{
return 0f;
}
return result;
}
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), "OnCollisionStay")]
internal static class RobustUsedHealthPackOnCollisionStayPatch
{
private static bool Prefix(PhysGrabObjectImpactDetector __instance)
{
if (RobustUsedHealthPackTruckProtection.ShouldProtect(__instance))
{
RobustUsedHealthPackTruckProtection.ApplyProtection(__instance);
return false;
}
return true;
}
}
[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "Break")]
internal static class RobustUsedHealthPackBreakPatch
{
private static bool Prefix(PhysGrabObjectImpactDetector __instance)
{
return !RobustUsedHealthPackTruckProtection.ShouldProtect(__instance);
}
}
[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "BreakRPC")]
internal static class RobustUsedHealthPackBreakRpcPatch
{
private static bool Prefix(PhysGrabObjectImpactDetector __instance)
{
return !RobustUsedHealthPackTruckProtection.ShouldProtect(__instance);
}
}
[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "DestroyObjectRPC")]
internal static class RobustUsedHealthPackDestroyObjectRpcPatch
{
private static bool Prefix(PhysGrabObjectImpactDetector __instance)
{
return !RobustUsedHealthPackTruckProtection.ShouldProtect(__instance);
}
}
[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "Update")]
internal static class RobustUsedHealthPackUpdatePatch
{
private static void Prefix(PhysGrabObjectImpactDetector __instance)
{
RobustUsedHealthPackTruckProtection.ApplyProtection(__instance);
}
private static void Postfix(PhysGrabObjectImpactDetector __instance)
{
RobustUsedHealthPackTruckProtection.ApplyProtection(__instance);
}
}
}