Decompiled source of Care Packages v0.1.0

tony4twentys-Care Packages.dll

Decompiled 4 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
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.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Care Packages")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Care Packages")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("27e252b7-3ebe-46f0-832a-22c6ff530b7d")]
[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]
[BepInPlugin("tony4twentys.Care_Packages", "Care Packages", "1.0.0")]
public class CarePackages : BaseUnityPlugin
{
	private class FlareTracker
	{
		public int instanceID;

		public Item flareItem;

		public Vector3 lastKnownPosition;

		public Character lighter;

		public float startTime;

		public bool carePackageSpawned;

		public bool audioStarted;

		public Coroutine coroutine;
	}

	[HarmonyPatch(typeof(Action_Flare), "RunAction")]
	private class Action_Flare_RunAction_Patch
	{
		[HarmonyPostfix]
		private static void Postfix(Action_Flare __instance)
		{
			if ((Object)(object)__instance.flare != (Object)null && (Object)(object)((ItemComponent)__instance.flare).item != (Object)null)
			{
				ManualLogSource logger = ((BaseUnityPlugin)instance).Logger;
				Character trueHolderCharacter = ((ItemComponent)__instance.flare).item.trueHolderCharacter;
				logger.LogInfo((object)("[CarePackages] Flare lit by: " + ((trueHolderCharacter != null) ? ((Object)trueHolderCharacter).name : null)));
				StartFlareCycle(((Component)((ItemComponent)__instance.flare).item).gameObject);
			}
		}
	}

	[CompilerGenerated]
	private sealed class <DestroyLuggageAfterDelay>d__20 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public Luggage luggage;

		public float delay;

		public CarePackages <>4__this;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <DestroyLuggageAfterDelay>d__20(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = (object)new WaitForSeconds(delay);
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				if ((Object)(object)luggage != (Object)null && (Object)(object)((Component)luggage).gameObject != (Object)null)
				{
					((BaseUnityPlugin)instance).Logger.LogInfo((object)"[CarePackages] Destroying opened luggage after delay");
					PhotonNetwork.Destroy(((Component)luggage).gameObject);
				}
				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 <LoadAudioFromPluginDirectory>d__15 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public CarePackages <>4__this;

		private string <pluginLocation>5__1;

		private string <pluginDirectory>5__2;

		private string[] <audioFiles>5__3;

		private string <soundFile>5__4;

		private string <url>5__5;

		private AudioType <audioType>5__6;

		private UnityWebRequest <www>5__7;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <LoadAudioFromPluginDirectory>d__15(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			int num = <>1__state;
			if (num == -3 || num == 1)
			{
				try
				{
				}
				finally
				{
					<>m__Finally1();
				}
			}
			<pluginLocation>5__1 = null;
			<pluginDirectory>5__2 = null;
			<audioFiles>5__3 = null;
			<soundFile>5__4 = null;
			<url>5__5 = null;
			<www>5__7 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Invalid comparison between Unknown and I4
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Expected O, but got Unknown
			bool result;
			try
			{
				switch (<>1__state)
				{
				default:
					result = false;
					break;
				case 0:
					<>1__state = -1;
					<pluginLocation>5__1 = ((BaseUnityPlugin)<>4__this).Info.Location;
					<pluginDirectory>5__2 = Path.GetDirectoryName(<pluginLocation>5__1);
					((BaseUnityPlugin)instance).Logger.LogInfo((object)("[CarePackages] Looking for audio files in: " + <pluginDirectory>5__2));
					<audioFiles>5__3 = Directory.GetFiles(<pluginDirectory>5__2, "*.ogg", SearchOption.AllDirectories).Concat(Directory.GetFiles(<pluginDirectory>5__2, "*.wav", SearchOption.AllDirectories)).ToArray();
					if (<audioFiles>5__3.Length == 0)
					{
						((BaseUnityPlugin)instance).Logger.LogWarning((object)("[CarePackages] No .wav or .ogg files found in " + <pluginDirectory>5__2));
						((BaseUnityPlugin)instance).Logger.LogInfo((object)"[CarePackages] Audio will be disabled - plugin will work without sound");
						result = false;
						break;
					}
					<soundFile>5__4 = <audioFiles>5__3[0];
					((BaseUnityPlugin)instance).Logger.LogInfo((object)("[CarePackages] Loading audio from " + <soundFile>5__4));
					<url>5__5 = "file://" + Path.GetFullPath(<soundFile>5__4).Replace("\\", "/");
					<audioType>5__6 = (AudioType)(<soundFile>5__4.EndsWith(".ogg") ? 14 : 20);
					<www>5__7 = UnityWebRequestMultimedia.GetAudioClip(<url>5__5, <audioType>5__6);
					<>1__state = -3;
					<>2__current = <www>5__7.SendWebRequest();
					<>1__state = 1;
					result = true;
					break;
				case 1:
					<>1__state = -3;
					if ((int)<www>5__7.result != 1)
					{
						((BaseUnityPlugin)instance).Logger.LogError((object)("[CarePackages] Failed to load audio: " + <www>5__7.error));
						result = false;
					}
					else
					{
						<>4__this.cueClip = DownloadHandlerAudioClip.GetContent(<www>5__7);
						if (!((Object)(object)<>4__this.cueClip == (Object)null))
						{
							<>4__this.audioHost = new GameObject("CarePackagesAudioHost");
							<>4__this.audioSource = <>4__this.audioHost.AddComponent<AudioSource>();
							<>4__this.audioSource.clip = <>4__this.cueClip;
							<>4__this.audioSource.loop = false;
							<>4__this.audioSource.playOnAwake = false;
							<>4__this.audioSource.spatialBlend = 0f;
							<>4__this.audioSource.dopplerLevel = 0f;
							<>4__this.audioSource.rolloffMode = (AudioRolloffMode)1;
							<>4__this.audioSource.minDistance = 1f;
							<>4__this.audioSource.maxDistance = 500f;
							<>4__this.audioSource.ignoreListenerPause = true;
							<>4__this.audioSource.bypassEffects = false;
							<>4__this.audioSource.bypassListenerEffects = false;
							<>4__this.audioSource.bypassReverbZones = true;
							<>4__this.audioSource.volume = 0.5f;
							Object.DontDestroyOnLoad((Object)(object)<>4__this.audioHost);
							<>4__this.audioLoaded = true;
							((BaseUnityPlugin)instance).Logger.LogInfo((object)"[CarePackages] Audio loaded successfully");
							<>m__Finally1();
							<www>5__7 = null;
							result = false;
							break;
						}
						((BaseUnityPlugin)instance).Logger.LogError((object)"[CarePackages] Failed to create audio clip");
						result = false;
					}
					<>m__Finally1();
					break;
				}
			}
			catch
			{
				//try-fault
				((IDisposable)this).Dispose();
				throw;
			}
			return result;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		private void <>m__Finally1()
		{
			<>1__state = -1;
			if (<www>5__7 != null)
			{
				((IDisposable)<www>5__7).Dispose();
			}
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <ReplaceLuggageAtPosition>d__19 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public Luggage oldLuggage;

		public Vector3 position;

		public Quaternion rotation;

		public CarePackages <>4__this;

		private GameObject <newLuggage>5__1;

		private Rigidbody <rb>5__2;

		private Collider <col>5__3;

		private Bonkable <bonkable>5__4;

		private Luggage <luggageComponent>5__5;

		private BoxCollider <boxCol>5__6;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <ReplaceLuggageAtPosition>d__19(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<newLuggage>5__1 = null;
			<rb>5__2 = null;
			<col>5__3 = null;
			<bonkable>5__4 = null;
			<luggageComponent>5__5 = null;
			<boxCol>5__6 = null;
			<>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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = (object)new WaitForSeconds(0.1f);
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				if ((Object)(object)oldLuggage != (Object)null && (Object)(object)((Component)oldLuggage).gameObject != (Object)null)
				{
					((BaseUnityPlugin)instance).Logger.LogInfo((object)"[CarePackages] Destroying old luggage");
					PhotonNetwork.Destroy(((Component)oldLuggage).gameObject);
				}
				<>2__current = (object)new WaitForSeconds(0.1f);
				<>1__state = 2;
				return true;
			case 2:
				<>1__state = -1;
				((BaseUnityPlugin)instance).Logger.LogInfo((object)$"[CarePackages] Spawning new luggage at exact position: {position}");
				<newLuggage>5__1 = PhotonNetwork.Instantiate("0_Items/LuggageEpic", position, rotation, (byte)0, (object[])null);
				if ((Object)(object)<newLuggage>5__1 != (Object)null)
				{
					<rb>5__2 = <newLuggage>5__1.GetComponent<Rigidbody>();
					if ((Object)(object)<rb>5__2 == (Object)null)
					{
						<rb>5__2 = <newLuggage>5__1.AddComponent<Rigidbody>();
						<rb>5__2.mass = 50f;
						<rb>5__2.linearDamping = 0.5f;
						<rb>5__2.angularDamping = 2f;
						<rb>5__2.useGravity = true;
						<rb>5__2.isKinematic = false;
					}
					<col>5__3 = <newLuggage>5__1.GetComponent<Collider>();
					if ((Object)(object)<col>5__3 == (Object)null)
					{
						<boxCol>5__6 = <newLuggage>5__1.AddComponent<BoxCollider>();
						<boxCol>5__6.size = new Vector3(1f, 1f, 1f);
						((Collider)<boxCol>5__6).isTrigger = false;
						<boxCol>5__6 = null;
					}
					<bonkable>5__4 = <newLuggage>5__1.GetComponent<Bonkable>();
					if ((Object)(object)<bonkable>5__4 == (Object)null)
					{
						<bonkable>5__4 = <newLuggage>5__1.AddComponent<Bonkable>();
						<bonkable>5__4.minBonkVelocity = 3f;
						<bonkable>5__4.ragdollTime = 2f;
						<bonkable>5__4.bonkForce = 1500f;
						<bonkable>5__4.bonkRange = 2f;
					}
					<luggageComponent>5__5 = <newLuggage>5__1.GetComponent<Luggage>();
					if ((Object)(object)<luggageComponent>5__5 != (Object)null)
					{
						instance.replacementLuggage.Add(<luggageComponent>5__5);
						((BaseUnityPlugin)instance).Logger.LogInfo((object)"[CarePackages] CLIENT: Replacement luggage spawned and added to replacement tracking");
					}
					<rb>5__2 = null;
					<col>5__3 = null;
					<bonkable>5__4 = null;
					<luggageComponent>5__5 = null;
				}
				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 <TrackFlare>d__13 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public FlareTracker tracker;

		public CarePackages <>4__this;

		private bool <flareFound>5__1;

		private TrackableNetworkObject[] <allTrackables>5__2;

		private TrackableNetworkObject[] <>s__3;

		private int <>s__4;

		private TrackableNetworkObject <trackable>5__5;

		private Flare <flareComponent>5__6;

		private bool <flareStillActive>5__7;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <TrackFlare>d__13(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<allTrackables>5__2 = null;
			<>s__3 = null;
			<trackable>5__5 = null;
			<flareComponent>5__6 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				((BaseUnityPlugin)instance).Logger.LogInfo((object)$"[CarePackages] Starting tracking for flare instance ID: {tracker.instanceID}");
				break;
			case 1:
				<>1__state = -1;
				<allTrackables>5__2 = null;
				break;
			}
			if (Time.time - tracker.startTime < 60f)
			{
				<flareFound>5__1 = false;
				<allTrackables>5__2 = Object.FindObjectsByType<TrackableNetworkObject>((FindObjectsSortMode)0);
				<>s__3 = <allTrackables>5__2;
				for (<>s__4 = 0; <>s__4 < <>s__3.Length; <>s__4++)
				{
					<trackable>5__5 = <>s__3[<>s__4];
					if (<trackable>5__5.instanceID == tracker.instanceID)
					{
						tracker.lastKnownPosition = ((Component)<trackable>5__5).transform.position;
						tracker.flareItem = ((Component)<trackable>5__5).GetComponent<Item>();
						<flareFound>5__1 = true;
						<flareComponent>5__6 = ((Component)<trackable>5__5).GetComponent<Flare>();
						if ((Object)(object)<flareComponent>5__6 != (Object)null && ((ItemComponent)<flareComponent>5__6).HasData((DataEntryKey)3))
						{
							<flareStillActive>5__7 = ((ItemComponent)<flareComponent>5__6).GetData<BoolItemData>((DataEntryKey)3).Value;
							if (!<flareStillActive>5__7)
							{
								((BaseUnityPlugin)instance).Logger.LogInfo((object)$"[CarePackages] Flare instance ID {tracker.instanceID} extinguished, stopping tracking");
							}
						}
						break;
					}
					<trackable>5__5 = null;
				}
				<>s__3 = null;
				if (!<flareFound>5__1)
				{
					((BaseUnityPlugin)instance).Logger.LogInfo((object)$"[CarePackages] Flare instance ID {tracker.instanceID} not found in scene, using last known position");
				}
				if (!tracker.audioStarted && Time.time - tracker.startTime >= 10f)
				{
					<>4__this.StartAudio();
					tracker.audioStarted = true;
					((BaseUnityPlugin)instance).Logger.LogInfo((object)$"[CarePackages] Audio started for flare instance ID: {tracker.instanceID}");
				}
				if (tracker.carePackageSpawned || !(Time.time - tracker.startTime >= 20f))
				{
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 1;
					return true;
				}
				<>4__this.SpawnCarePackage(tracker);
				tracker.carePackageSpawned = true;
				((BaseUnityPlugin)instance).Logger.LogInfo((object)$"[CarePackages] Care package spawned for flare instance ID: {tracker.instanceID}");
				((BaseUnityPlugin)instance).Logger.LogInfo((object)"[CarePackages] Audio will play out naturally");
			}
			instance.activeFlareTrackers.Remove(tracker.instanceID);
			((BaseUnityPlugin)instance).Logger.LogInfo((object)$"[CarePackages] Stopped tracking flare instance ID: {tracker.instanceID}");
			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();
		}
	}

	private static CarePackages instance;

	private Harmony harmony;

	private GameObject audioHost;

	private AudioSource audioSource;

	private AudioClip cueClip;

	private bool audioLoaded = false;

	private Dictionary<int, FlareTracker> activeFlareTrackers = new Dictionary<int, FlareTracker>();

	private HashSet<Luggage> carePackages = new HashSet<Luggage>();

	private HashSet<Luggage> replacedLuggage = new HashSet<Luggage>();

	private HashSet<Luggage> replacementLuggage = new HashSet<Luggage>();

	public 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("tony4twentys.care_packages");
		harmony.PatchAll();
		GlobalEvents.OnLuggageOpened = (Action<Luggage, Character>)Delegate.Combine(GlobalEvents.OnLuggageOpened, new Action<Luggage, Character>(OnLuggageOpened));
		GlobalEvents.OnItemThrown = (Action<Item>)Delegate.Combine(GlobalEvents.OnItemThrown, new Action<Item>(OnItemThrown));
		((MonoBehaviour)this).StartCoroutine(LoadAudioFromPluginDirectory());
		((BaseUnityPlugin)instance).Logger.LogInfo((object)"[CarePackages] Loaded");
	}

	public static void StartFlareCycle(GameObject flare)
	{
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		Item component = flare.GetComponent<Item>();
		if ((Object)(object)component == (Object)null)
		{
			return;
		}
		TrackableNetworkObject component2 = flare.GetComponent<TrackableNetworkObject>();
		if (!((Object)(object)component2 == (Object)null))
		{
			int instanceID = component2.instanceID;
			((BaseUnityPlugin)instance).Logger.LogInfo((object)$"[CarePackages] Starting flare cycle for instance ID: {instanceID}");
			if (instance.activeFlareTrackers.ContainsKey(instanceID))
			{
				((BaseUnityPlugin)instance).Logger.LogInfo((object)$"[CarePackages] Already tracking flare instance ID: {instanceID}");
				return;
			}
			FlareTracker flareTracker = new FlareTracker
			{
				instanceID = instanceID,
				flareItem = component,
				lastKnownPosition = ((Component)component).transform.position,
				lighter = component.trueHolderCharacter,
				startTime = Time.time,
				carePackageSpawned = false,
				audioStarted = false
			};
			instance.activeFlareTrackers[instanceID] = flareTracker;
			flareTracker.coroutine = ((MonoBehaviour)instance).StartCoroutine(instance.TrackFlare(flareTracker));
		}
	}

	[IteratorStateMachine(typeof(<TrackFlare>d__13))]
	private IEnumerator TrackFlare(FlareTracker tracker)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <TrackFlare>d__13(0)
		{
			<>4__this = this,
			tracker = tracker
		};
	}

	private void SpawnCarePackage(FlareTracker tracker)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: 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)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		Vector3 lastKnownPosition = tracker.lastKnownPosition;
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(lastKnownPosition.x, lastKnownPosition.y + 50f, lastKnownPosition.z);
		((BaseUnityPlugin)instance).Logger.LogInfo((object)$"[CarePackages] Spawning care package for flare instance ID {tracker.instanceID} at position: {val}");
		Quaternion val2 = Quaternion.LookRotation(Vector3.forward, Vector3.up);
		GameObject val3 = PhotonNetwork.Instantiate("0_Items/LuggageEpic", val, val2, (byte)0, (object[])null);
		Luggage component = val3.GetComponent<Luggage>();
		if ((Object)(object)component != (Object)null)
		{
			instance.carePackages.Add(component);
			((BaseUnityPlugin)instance).Logger.LogInfo((object)$"[CarePackages] Added care package to tracking list. Total tracked: {instance.carePackages.Count}");
		}
		if ((Object)(object)val3 != (Object)null)
		{
			Rigidbody component2 = val3.GetComponent<Rigidbody>();
			if ((Object)(object)component2 == (Object)null)
			{
				component2 = val3.AddComponent<Rigidbody>();
				component2.mass = 50f;
				component2.linearDamping = 0.5f;
				component2.angularDamping = 2f;
				component2.useGravity = true;
				component2.isKinematic = false;
			}
			Collider component3 = val3.GetComponent<Collider>();
			if ((Object)(object)component3 == (Object)null)
			{
				BoxCollider val4 = val3.AddComponent<BoxCollider>();
				val4.size = new Vector3(1f, 1f, 1f);
				((Collider)val4).isTrigger = false;
			}
			if ((Object)(object)component3 != (Object)null && component3.isTrigger)
			{
				component3.isTrigger = false;
			}
			Bonkable component4 = val3.GetComponent<Bonkable>();
			if ((Object)(object)component4 == (Object)null)
			{
				component4 = val3.AddComponent<Bonkable>();
				component4.minBonkVelocity = 3f;
				component4.ragdollTime = 2f;
				component4.bonkForce = 1500f;
				component4.bonkRange = 2f;
			}
		}
		((BaseUnityPlugin)instance).Logger.LogInfo((object)$"[CarePackages] Care package spawned successfully for flare instance ID: {tracker.instanceID}!");
	}

	[IteratorStateMachine(typeof(<LoadAudioFromPluginDirectory>d__15))]
	private IEnumerator LoadAudioFromPluginDirectory()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <LoadAudioFromPluginDirectory>d__15(0)
		{
			<>4__this = this
		};
	}

	private void StartAudio()
	{
		if (audioLoaded && (Object)(object)audioSource != (Object)null && !audioSource.isPlaying)
		{
			audioSource.Play();
			((BaseUnityPlugin)instance).Logger.LogInfo((object)"[CarePackages] Audio started");
		}
	}

	private void StopAudio()
	{
		if (audioLoaded && (Object)(object)audioSource != (Object)null && audioSource.isPlaying)
		{
			audioSource.Stop();
			((BaseUnityPlugin)instance).Logger.LogInfo((object)"[CarePackages] Audio stopped");
		}
	}

	private void OnLuggageOpened(Luggage luggage, Character character)
	{
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		if (instance.replacementLuggage.Contains(luggage))
		{
			((BaseUnityPlugin)instance).Logger.LogInfo((object)"[CarePackages] CLIENT: Replacement luggage opened, scheduling destruction after 1 second");
			instance.replacementLuggage.Remove(luggage);
			((MonoBehaviour)this).StartCoroutine(DestroyLuggageAfterDelay(luggage, 1f));
		}
		else if (instance.carePackages.Contains(luggage) && !instance.replacedLuggage.Contains(luggage))
		{
			if (PhotonNetwork.IsMasterClient)
			{
				((BaseUnityPlugin)instance).Logger.LogInfo((object)"[CarePackages] HOST: Care package opened, removing from tracking and scheduling destruction");
				instance.carePackages.Remove(luggage);
				((MonoBehaviour)this).StartCoroutine(DestroyLuggageAfterDelay(luggage, 1f));
				return;
			}
			((BaseUnityPlugin)instance).Logger.LogInfo((object)"[CarePackages] CLIENT: Care package opened, replacing with new luggage at exact position");
			instance.replacedLuggage.Add(luggage);
			instance.carePackages.Remove(luggage);
			Vector3 position = ((Component)luggage).transform.position;
			Quaternion rotation = ((Component)luggage).transform.rotation;
			((BaseUnityPlugin)instance).Logger.LogInfo((object)$"[CarePackages] CLIENT: Captured position: {position}, rotation: {rotation}");
			((MonoBehaviour)this).StartCoroutine(ReplaceLuggageAtPosition(luggage, position, rotation));
		}
	}

	[IteratorStateMachine(typeof(<ReplaceLuggageAtPosition>d__19))]
	private IEnumerator ReplaceLuggageAtPosition(Luggage oldLuggage, Vector3 position, Quaternion rotation)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <ReplaceLuggageAtPosition>d__19(0)
		{
			<>4__this = this,
			oldLuggage = oldLuggage,
			position = position,
			rotation = rotation
		};
	}

	[IteratorStateMachine(typeof(<DestroyLuggageAfterDelay>d__20))]
	private IEnumerator DestroyLuggageAfterDelay(Luggage luggage, float delay)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <DestroyLuggageAfterDelay>d__20(0)
		{
			<>4__this = this,
			luggage = luggage,
			delay = delay
		};
	}

	private void OnItemThrown(Item item)
	{
		//IL_005b: 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)
		if (((Object)item).name.ToLower().Contains("flare"))
		{
			TrackableNetworkObject component = ((Component)item).GetComponent<TrackableNetworkObject>();
			if ((Object)(object)component != (Object)null && activeFlareTrackers.ContainsKey(component.instanceID))
			{
				activeFlareTrackers[component.instanceID].lastKnownPosition = ((Component)item).transform.position;
				((BaseUnityPlugin)instance).Logger.LogInfo((object)$"[CarePackages] Updated position for thrown flare instance ID: {component.instanceID}");
			}
		}
	}

	private void OnDestroy()
	{
		GlobalEvents.OnLuggageOpened = (Action<Luggage, Character>)Delegate.Remove(GlobalEvents.OnLuggageOpened, new Action<Luggage, Character>(OnLuggageOpened));
		GlobalEvents.OnItemThrown = (Action<Item>)Delegate.Remove(GlobalEvents.OnItemThrown, new Action<Item>(OnItemThrown));
		StopAudio();
		if ((Object)(object)audioHost != (Object)null)
		{
			Object.DestroyImmediate((Object)(object)audioHost);
		}
		foreach (FlareTracker value in activeFlareTrackers.Values)
		{
			if (value.coroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(value.coroutine);
			}
		}
		activeFlareTrackers.Clear();
	}
}