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 HarmonyLib;
using Photon.Pun;
using UnityEngine;
using UnityEngine.SceneManagement;
using Zorro.Core.Serizalization;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Starter Medkit")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Starter Medkit")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("add8e766-67f3-4b94-a1d5-74a8103ac3ad")]
[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 Starter_Medkit;
[BepInPlugin("tony4twentys.Starter_Medkit", "Starter Medkit", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
private Harmony _harmony;
public static Plugin Instance;
private Coroutine _scanCoroutine;
private void Awake()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
_harmony = new Harmony("tony4twentys.Starter_Medkit");
_harmony.PatchAll();
SceneManager.sceneLoaded += OnSceneLoaded;
Instance = this;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
if (_scanCoroutine != null)
{
((MonoBehaviour)this).StopCoroutine(_scanCoroutine);
_scanCoroutine = null;
}
StarterMedkit.ResetTracking();
if (((Scene)(ref scene)).name != null && ((Scene)(ref scene)).name.Contains("Level_"))
{
_scanCoroutine = ((MonoBehaviour)this).StartCoroutine(StarterMedkit.PeriodicPlayerScan());
}
}
private void OnDestroy()
{
try
{
SceneManager.sceneLoaded -= OnSceneLoaded;
}
catch
{
}
try
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
catch
{
}
if (_scanCoroutine != null)
{
((MonoBehaviour)this).StopCoroutine(_scanCoroutine);
}
}
}
internal static class StarterMedkit
{
[CompilerGenerated]
private sealed class <PeriodicPlayerScan>d__4 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
private List<Character> <characters>5__1;
private int <count>5__2;
private int <i>5__3;
private Character <c>5__4;
private int <actorNr>5__5;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <PeriodicPlayerScan>d__4(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<characters>5__1 = null;
<c>5__4 = 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_0178: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: 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;
break;
case 2:
<>1__state = -1;
break;
}
if (PhotonNetwork.IsMasterClient)
{
<characters>5__1 = Character.AllCharacters;
<count>5__2 = <characters>5__1.Count;
<i>5__3 = 0;
while (<i>5__3 < <count>5__2)
{
<c>5__4 = <characters>5__1[<i>5__3];
if (IsAlive(<c>5__4) && !<c>5__4.isBot && (Object)(object)<c>5__4.refs?.view != (Object)null)
{
<actorNr>5__5 = <c>5__4.refs.view.OwnerActorNr;
if (!_receivedMedkit.Contains(<actorNr>5__5) && TryGiveMedkitTo(<c>5__4))
{
_receivedMedkit.Add(<actorNr>5__5);
}
}
<c>5__4 = null;
<i>5__3++;
}
<characters>5__1 = null;
}
<>2__current = (object)new WaitForSeconds(5f);
<>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 const ushort MedkitId = 29;
private const float ScanIntervalSeconds = 5f;
private static readonly HashSet<int> _receivedMedkit = new HashSet<int>();
public static void ResetTracking()
{
_receivedMedkit.Clear();
}
[IteratorStateMachine(typeof(<PeriodicPlayerScan>d__4))]
public static IEnumerator PeriodicPlayerScan()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <PeriodicPlayerScan>d__4(0);
}
private static bool IsAlive(Character c)
{
return (Object)(object)c != (Object)null && (Object)(object)c.data != (Object)null && !c.data.dead && c.data.fullyConscious;
}
private static bool TryGiveMedkitTo(Character c)
{
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Expected O, but got Unknown
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
try
{
Player player = c.player;
if ((Object)(object)player == (Object)null || player.itemSlots == null)
{
return false;
}
Item val = default(Item);
InventorySyncData val3 = default(InventorySyncData);
for (int i = 0; i < 3 && i < player.itemSlots.Length; i++)
{
if (player.itemSlots[i].IsEmpty())
{
if (!ItemDatabase.TryGetItem((ushort)29, ref val))
{
return false;
}
ItemInstanceData val2 = new ItemInstanceData(Guid.NewGuid());
ItemInstanceDataHandler.AddInstanceData(val2);
player.itemSlots[i].SetItem(val, val2);
((InventorySyncData)(ref val3))..ctor(player.itemSlots, player.backpackSlot, player.tempFullSlot);
((MonoBehaviourPun)player).photonView.RPC("SyncInventoryRPC", (RpcTarget)1, new object[2]
{
IBinarySerializable.ToManagedArray<InventorySyncData>(val3),
false
});
return true;
}
}
return false;
}
catch
{
return false;
}
}
}