Decompiled source of BountyForge v1.0.0

BountyForge.dll

Decompiled 3 days ago
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BountyForge.Config;
using BountyForge.Data;
using BountyForge.Systems;
using BountyForge.Utils;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Gameplay.Clan;
using ProjectM.Network;
using Stunlock.Core;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using VampireCommandFramework;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BountyForge")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Place a bounty on a players head.")]
[assembly: AssemblyFileVersion("0.1.10.0")]
[assembly: AssemblyInformationalVersion("0.1.10+1.Branch.main.Sha.c33d0879382e1a0da34861ec55914ba7e637a80e")]
[assembly: AssemblyProduct("BountyForge")]
[assembly: AssemblyTitle("BountyForge")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.10.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 BountyForge
{
	public enum ItemGiveStatus
	{
		Failed,
		AddedToInventory,
		DroppedOnGround,
		PartiallyAddedAndDropped
	}
	[BepInPlugin("Bountyforge", "BountyForge", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		private Harmony _harmony;

		public static Plugin Instance { get; private set; }

		public static ManualLogSource LogInstance { get; private set; }

		public static ConfigFile Config { get; private set; }

		public override void Load()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			Instance = this;
			LogInstance = ((BasePlugin)this).Log;
			LoggingHelper.Initialize(LogInstance);
			string text = Path.Combine(Paths.ConfigPath, "BountyForge");
			Directory.CreateDirectory(text);
			string text2 = Path.Combine(text, "Bountyforge.cfg");
			Config = new ConfigFile(text2, true);
			string text3 = Path.Combine(text, "Data");
			Directory.CreateDirectory(text3);
			BountyConfig.Initialize(Config);
			ItemUtils.Initialize();
			BountyMapIcons.Initialize();
			_harmony = new Harmony("Bountyforge");
			try
			{
				_harmony.PatchAll(Assembly.GetExecutingAssembly());
			}
			catch (Exception)
			{
			}
			BountyManager.Initialize(text3);
			LeaderboardSystem.Initialize(text3);
			try
			{
				CommandRegistry.RegisterAll();
			}
			catch (Exception)
			{
			}
			LoggingHelper.Info("[BountyForge] Plugin (v1.0.0) loaded successfully.");
		}

		public void Update()
		{
		}

		public override bool Unload()
		{
			if (Config != null)
			{
				Config.Save();
			}
			BountyTaskScheduler.DisposeAllTimers();
			CommandRegistry.UnregisterAssembly();
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			if (VWorld.IsServerWorldReady())
			{
				BountyManager.SaveActiveBounties();
				BountyManager.SaveActiveContracts();
				LeaderboardSystem.SaveLeaderboard();
				if (BountyConfig.ModEnabled.Value && BountyConfig.EnableMapIcons.Value)
				{
					BountyMapIcons.RemoveAllMapIcons(calledOnShutdown: true);
				}
			}
			return true;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "Bountyforge";

		public const string PLUGIN_NAME = "BountyForge";

		public const string PLUGIN_VERSION = "1.0.0";
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "BountyForge";

		public const string PLUGIN_NAME = "BountyForge";

		public const string PLUGIN_VERSION = "0.1.10";
	}
}
namespace BountyForge.Utils
{
	public static class ChatColors
	{
		public const string ErrorHex = "#FF4136";

		public const string SuccessHex = "#2ECC40";

		public const string InfoHex = "#FFFFFF";

		public const string WarningHex = "#FF851B";

		public const string HighlightHex = "#7FDBFF";

		public const string AccentHex = "#FFDC00";

		public const string MutedHex = "#AAAAAA";

		public const string BountyTargetNameHex = "#E74C3C";

		public const string BountyPosterNameHex = "#3498DB";

		public const string BountyItemHex = "#F1C40F";

		public const string CommandSyntaxHex = "#95A5A6";

		public const string CommandDescriptionHex = "#BDC3C7";

		private static string Format(string message, string colorHex)
		{
			if (string.IsNullOrEmpty(colorHex) || string.IsNullOrEmpty(message))
			{
				return message ?? string.Empty;
			}
			return $"<color={colorHex}>{message}</color>";
		}

		public static string ErrorText(string message)
		{
			return Format(message, "#FF4136");
		}

		public static string SuccessText(string message)
		{
			return Format(message, "#2ECC40");
		}

		public static string InfoText(string message)
		{
			return Format(message, "#FFFFFF");
		}

		public static string WarningText(string message)
		{
			return Format(message, "#FF851B");
		}

		public static string HighlightText(string message)
		{
			return Format(message, "#7FDBFF");
		}

		public static string AccentText(string message)
		{
			return Format(message, "#FFDC00");
		}

		public static string MutedText(string message)
		{
			return Format(message, "#AAAAAA");
		}

		public static string BountyTargetNameText(string playerName)
		{
			return Format(playerName, "#E74C3C");
		}

		public static string BountyPosterNameText(string playerName)
		{
			return Format(playerName, "#3498DB");
		}

		public static string BountyItemText(string itemName)
		{
			return Format(itemName, "#F1C40F");
		}

		public static string CommandSyntaxText(string syntax)
		{
			return Format(syntax, "#95A5A6");
		}

		public static string CommandDescriptionText(string description)
		{
			return Format(description, "#BDC3C7");
		}
	}
	public static class InventoryUtils
	{
		private static bool TryGetItemData(PrefabGUID itemGuid, out ItemData itemData)
		{
			//IL_0002: 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)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			itemData = default(ItemData);
			if (!VWorld.IsServerWorldReady())
			{
				LoggingHelper.Error("[InventoryUtils.TryGetItemData] Server world not ready.");
				return false;
			}
			GameDataSystem existingSystemManaged = VWorld.Server.GetExistingSystemManaged<GameDataSystem>();
			if (existingSystemManaged == null || !existingSystemManaged.ItemHashLookupMap.IsCreated)
			{
				LoggingHelper.Warning($"[InventoryUtils.TryGetItemData] GameDataSystem not available or ItemHashLookupMap not ready for {((PrefabGUID)(ref itemGuid)).GuidHash}.");
				return false;
			}
			if (!existingSystemManaged.ItemHashLookupMap.TryGetValue(itemGuid, ref itemData))
			{
				LoggingHelper.Warning($"[InventoryUtils.TryGetItemData] ItemData not found in ItemHashLookupMap for GUID {((PrefabGUID)(ref itemGuid)).GuidHash}.");
				return false;
			}
			return true;
		}

		private static bool TryGetItemDataLookup(out NativeParallelHashMap<PrefabGUID, ItemData> itemDataLookup)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			itemDataLookup = default(NativeParallelHashMap<PrefabGUID, ItemData>);
			if (!VWorld.IsServerWorldReady())
			{
				LoggingHelper.Error("[InventoryUtils.TryGetItemDataLookup] Server world not ready.");
				return false;
			}
			GameDataSystem existingSystemManaged = VWorld.Server.GetExistingSystemManaged<GameDataSystem>();
			if (existingSystemManaged == null)
			{
				LoggingHelper.Error("[InventoryUtils.TryGetItemDataLookup] GameDataSystem not found.");
				return false;
			}
			itemDataLookup = existingSystemManaged.ItemHashLookupMap;
			if (!itemDataLookup.IsCreated)
			{
				LoggingHelper.Error("[InventoryUtils.TryGetItemDataLookup] ItemHashLookupMap is not created.");
				return false;
			}
			return true;
		}

		private static bool TryGetCommandBuffer(out EntityCommandBuffer commandBuffer)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			commandBuffer = default(EntityCommandBuffer);
			if (!VWorld.IsServerWorldReady())
			{
				LoggingHelper.Error("[InventoryUtils.TryGetCommandBuffer] Server world not ready.");
				return false;
			}
			EndSimulationEntityCommandBufferSystem existingSystemManaged = VWorld.Server.GetExistingSystemManaged<EndSimulationEntityCommandBufferSystem>();
			if (existingSystemManaged == null)
			{
				LoggingHelper.Error("[InventoryUtils.TryGetCommandBuffer] EndSimulationEntityCommandBufferSystem not found.");
				return false;
			}
			commandBuffer = ((EntityCommandBufferSystem)existingSystemManaged).CreateCommandBuffer();
			return true;
		}

		public static bool PlayerHasEnoughItems(Entity playerCharacterEntity, PrefabGUID itemGuid, int neededAmount)
		{
			//IL_0038: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: 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_0197: 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)
			if (neededAmount <= 0)
			{
				return true;
			}
			if (!VWorld.IsServerWorldReady())
			{
				LoggingHelper.Error("[InventoryUtils.PlayerHasEnoughItems] Server world not ready.");
				return false;
			}
			EntityManager entityManager = VWorld.EntityManager;
			if (playerCharacterEntity == Entity.Null || !((EntityManager)(ref entityManager)).Exists(playerCharacterEntity))
			{
				LoggingHelper.Warning("[InventoryUtils.PlayerHasEnoughItems] Invalid or non-existent playerCharacterEntity.");
				return false;
			}
			Entity val = default(Entity);
			if (!InventoryUtilities.TryGetInventoryEntity<EntityManager>(entityManager, playerCharacterEntity, ref val, 0))
			{
				LoggingHelper.Debug($"[InventoryUtils.PlayerHasEnoughItems] Could not get inventory entity for player {playerCharacterEntity}.");
				return false;
			}
			if (!((EntityManager)(ref entityManager)).HasBuffer<InventoryBuffer>(val))
			{
				LoggingHelper.Debug($"[InventoryUtils.PlayerHasEnoughItems] Inventory entity {val} for player {playerCharacterEntity} has no InventoryBuffer.");
				return false;
			}
			DynamicBuffer<InventoryBuffer> buffer = ((EntityManager)(ref entityManager)).GetBuffer<InventoryBuffer>(val, false);
			int num = 0;
			Enumerator<InventoryBuffer> enumerator = buffer.GetEnumerator();
			while (enumerator.MoveNext())
			{
				InventoryBuffer current = enumerator.Current;
				if (current.ItemType == itemGuid)
				{
					num += current.Amount;
				}
			}
			LoggingHelper.Debug($"[InventoryUtils.PlayerHasEnoughItems] Player {playerCharacterEntity} has {num} of item {((PrefabGUID)(ref itemGuid)).GuidHash}. Needed: {neededAmount}.");
			return num >= neededAmount;
		}

		public static bool TryRemoveItemsFromPlayer(Entity playerCharacterEntity, PrefabGUID itemGuid, int amountToRemove)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			if (amountToRemove <= 0)
			{
				return true;
			}
			if (!VWorld.IsServerWorldReady())
			{
				LoggingHelper.Error("[InventoryUtils.TryRemoveItemsFromPlayer] Server world not ready.");
				return false;
			}
			EntityManager entityManager = VWorld.EntityManager;
			if (playerCharacterEntity == Entity.Null || !((EntityManager)(ref entityManager)).Exists(playerCharacterEntity))
			{
				LoggingHelper.Warning("[InventoryUtils.TryRemoveItemsFromPlayer] Invalid or non-existent playerCharacterEntity.");
				return false;
			}
			bool flag = InventoryUtilitiesServer.TryRemoveItem(entityManager, playerCharacterEntity, itemGuid, amountToRemove);
			if (!flag)
			{
				LoggingHelper.Warning($"[InventoryUtils] InventoryUtilitiesServer.TryRemoveItem failed to remove {amountToRemove} of item {((PrefabGUID)(ref itemGuid)).GuidHash} from player {playerCharacterEntity}.");
			}
			else
			{
				LoggingHelper.Info($"[InventoryUtils] Successfully removed {amountToRemove} of item {((PrefabGUID)(ref itemGuid)).GuidHash} from player {playerCharacterEntity}.");
			}
			return flag;
		}

		public static ItemGiveStatus TryAddItemsToPlayer(Entity playerCharacterEntity, PrefabGUID itemGuid, int amountToAdd)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: 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)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_05cf: 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_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0666: Unknown result type (might be due to invalid IL or missing references)
			//IL_068a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0705: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0832: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0531: Unknown result type (might be due to invalid IL or missing references)
			//IL_08b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_08cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0961: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_0429: Unknown result type (might be due to invalid IL or missing references)
			//IL_0431: Unknown result type (might be due to invalid IL or missing references)
			//IL_0432: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			LoggingHelper.Info($"[InventoryUtils.TryAddItemsToPlayer] Entered. TargetChar: {playerCharacterEntity}, ItemGUID: {((PrefabGUID)(ref itemGuid)).GuidHash}, Amount: {amountToAdd}");
			if (amountToAdd <= 0)
			{
				LoggingHelper.Debug("[InventoryUtils.TryAddItemsToPlayer] Amount to add is 0 or less. Returning AddedToInventory (no action).");
				return ItemGiveStatus.AddedToInventory;
			}
			if (!VWorld.IsServerWorldReady())
			{
				LoggingHelper.Error("[InventoryUtils.TryAddItemsToPlayer] Server world not ready.");
				return ItemGiveStatus.Failed;
			}
			EntityManager entityManager = VWorld.EntityManager;
			if (playerCharacterEntity == Entity.Null || !((EntityManager)(ref entityManager)).Exists(playerCharacterEntity))
			{
				LoggingHelper.Error($"[InventoryUtils.TryAddItemsToPlayer] Player character entity {playerCharacterEntity} does not exist or is null.");
				return ItemGiveStatus.Failed;
			}
			if (((PrefabGUID)(ref itemGuid)).GuidHash == 0)
			{
				LoggingHelper.Error("[InventoryUtils.TryAddItemsToPlayer] Invalid itemGuid (0) passed. Cannot add item.");
				return ItemGiveStatus.Failed;
			}
			int num = amountToAdd;
			bool flag = false;
			LoggingHelper.Debug($"[InventoryUtils] Attempting to add {amountToAdd} of {((PrefabGUID)(ref itemGuid)).GuidHash} to {playerCharacterEntity}.");
			Entity val = default(Entity);
			if (InventoryUtilities.TryGetInventoryEntity<EntityManager>(entityManager, playerCharacterEntity, ref val, 0) && ((EntityManager)(ref entityManager)).HasBuffer<InventoryBuffer>(val))
			{
				DynamicBuffer<InventoryBuffer> buffer = ((EntityManager)(ref entityManager)).GetBuffer<InventoryBuffer>(val, false);
				int num2 = 1;
				if (TryGetItemData(itemGuid, out var itemData) && itemData.MaxAmount > 0)
				{
					num2 = itemData.MaxAmount;
				}
				else
				{
					LoggingHelper.Warning($"[InventoryUtils] Could not determine valid MaxAmount for {((PrefabGUID)(ref itemGuid)).GuidHash}. Defaulting stack size to {num2}. Stacking might be imperfect.");
				}
				LoggingHelper.Debug($"[InventoryUtils] Max stack size for {((PrefabGUID)(ref itemGuid)).GuidHash} is {num2}. Attempting to add {num}.");
				for (int i = 0; i < buffer.Length; i++)
				{
					if (num <= 0)
					{
						break;
					}
					if (buffer[i].ItemType == itemGuid && buffer[i].Amount < num2)
					{
						int num3 = Math.Min(num, num2 - buffer[i].Amount);
						InventoryBuffer val2 = buffer[i];
						val2.Amount += num3;
						buffer[i] = val2;
						num -= num3;
						flag = true;
						LoggingHelper.Debug($"[InventoryUtils] Added {num3} to existing stack in slot {i}. Remaining: {num}. Slot now: {val2.Amount}");
					}
				}
				if (num > 0)
				{
					for (int j = 0; j < buffer.Length; j++)
					{
						if (num <= 0)
						{
							break;
						}
						InventoryBuffer val3 = buffer[j];
						if (((PrefabGUID)(ref val3.ItemType)).Equals(PrefabGUID.Empty))
						{
							int num4 = Math.Min(num, num2);
							int num5 = j;
							val3 = new InventoryBuffer
							{
								ItemType = itemGuid,
								Amount = num4
							};
							buffer[num5] = val3;
							num -= num4;
							flag = true;
							LoggingHelper.Debug($"[InventoryUtils] Added {num4} to new stack in empty slot {j}. Remaining: {num}.");
						}
					}
				}
				if (num == 0)
				{
					LoggingHelper.Info($"[InventoryUtils] Successfully added all {amountToAdd} of item {((PrefabGUID)(ref itemGuid)).GuidHash} to player {playerCharacterEntity}'s inventory slots.");
					return ItemGiveStatus.AddedToInventory;
				}
				LoggingHelper.Warning($"[InventoryUtils] Inventory full or no suitable slots after direct add for {((PrefabGUID)(ref itemGuid)).GuidHash}. Remaining {num} to be dropped.");
			}
			else
			{
				LoggingHelper.Warning($"[InventoryUtils] Could not get inventory buffer for {playerCharacterEntity}. Proceeding to drop attempt for all {amountToAdd} items.");
				num = amountToAdd;
			}
			if (num > 0)
			{
				int num6 = num;
				LoggingHelper.Info($"[InventoryUtils] Attempting to drop {num6} of {((PrefabGUID)(ref itemGuid)).GuidHash} for player {playerCharacterEntity}.");
				try
				{
					if (!((EntityManager)(ref entityManager)).HasComponent<LocalToWorld>(playerCharacterEntity))
					{
						LoggingHelper.Error($"[InventoryUtils] Player character {playerCharacterEntity} missing LocalToWorld. Cannot get drop position.");
						return flag ? ItemGiveStatus.PartiallyAddedAndDropped : ItemGiveStatus.Failed;
					}
					LocalToWorld componentData = ((EntityManager)(ref entityManager)).GetComponentData<LocalToWorld>(playerCharacterEntity);
					float3 position = ((LocalToWorld)(ref componentData)).Position;
					position.y += 0.3f;
					if (!TryGetItemData(itemGuid, out var itemData2))
					{
						LoggingHelper.Error($"[InventoryUtils] Could not get ItemData for {((PrefabGUID)(ref itemGuid)).GuidHash} for dropping (MaxAmount needed). Aborting drop.");
						return flag ? ItemGiveStatus.PartiallyAddedAndDropped : ItemGiveStatus.Failed;
					}
					if (!TryGetItemDataLookup(out var itemDataLookup))
					{
						LoggingHelper.Error("[InventoryUtils] Drop: Could not get ItemDataLookup. Cannot drop items.");
						return flag ? ItemGiveStatus.PartiallyAddedAndDropped : ItemGiveStatus.Failed;
					}
					if (!TryGetCommandBuffer(out var commandBuffer))
					{
						LoggingHelper.Error("[InventoryUtils] Drop: Could not create EntityCommandBuffer. Cannot drop items.");
						return flag ? ItemGiveStatus.PartiallyAddedAndDropped : ItemGiveStatus.Failed;
					}
					int num7 = ((itemData2.MaxAmount <= 0) ? 1 : itemData2.MaxAmount);
					LoggingHelper.Debug($"[InventoryUtils] Dropping {num6} of {((PrefabGUID)(ref itemGuid)).GuidHash} in stacks up to {num7} at {position}.");
					int num8 = 0;
					int num9 = num6;
					while (num9 > 0)
					{
						int num10 = Math.Min(num9, num7);
						LoggingHelper.Info($"[InventoryUtils] Queuing drop via CreateDroppedItemEntity: ItemGUID={((PrefabGUID)(ref itemGuid)).GuidHash}, Amount={num10}, Pos={position}");
						InventoryUtilitiesServer.CreateDroppedItemEntity(entityManager, commandBuffer, itemDataLookup, position, itemGuid, num10);
						num8 += num10;
						num9 -= num10;
						if (num9 > 0)
						{
							position.x += 0.2f;
						}
					}
					LoggingHelper.Info($"[InventoryUtils] Successfully queued drop of {num8} items for {((PrefabGUID)(ref itemGuid)).GuidHash} near player {playerCharacterEntity}.");
					return flag ? ItemGiveStatus.PartiallyAddedAndDropped : ItemGiveStatus.DroppedOnGround;
				}
				catch (Exception ex)
				{
					LoggingHelper.Error("[InventoryUtils] Drop: Exception: " + ex.Message + "\n" + ex.StackTrace);
					return flag ? ItemGiveStatus.PartiallyAddedAndDropped : ItemGiveStatus.Failed;
				}
			}
			return ItemGiveStatus.AddedToInventory;
		}
	}
	public static class ItemUtils
	{
		public static void Initialize()
		{
		}

		public static PrefabGUID GetBountyPaymentItemGUID()
		{
			//IL_002c: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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)
			if (BountyConfig.PaymentItemPrefabGUID == null)
			{
				LoggingHelper.Error("[ItemUtils] PaymentItemPrefabGUID from BountyConfig is null! Check BountyConfig initialization.");
				return new PrefabGUID(0);
			}
			return new PrefabGUID(BountyConfig.PaymentItemPrefabGUID.Value);
		}

		public static string GetBountyPaymentItemName()
		{
			if (BountyConfig.PaymentItemDisplayName == null)
			{
				LoggingHelper.Error("[ItemUtils] PaymentItemDisplayName from BountyConfig is null! Check BountyConfig initialization.");
				return "ErrorItem";
			}
			return BountyConfig.PaymentItemDisplayName.Value;
		}

		public static string GetItemNameFromGUID(PrefabGUID itemGuid)
		{
			if (BountyConfig.PaymentItemPrefabGUID == null || ((PrefabGUID)(ref itemGuid)).GuidHash != BountyConfig.PaymentItemPrefabGUID.Value)
			{
				return $"ItemGUID({((PrefabGUID)(ref itemGuid)).GuidHash})";
			}
			return GetBountyPaymentItemName();
		}
	}
	public static class LoggingHelper
	{
		private static ManualLogSource _logger;

		public static void Initialize(ManualLogSource logger)
		{
			_logger = logger;
		}

		public static void Debug(string message)
		{
			ManualLogSource logger = _logger;
			if (logger != null)
			{
				logger.LogDebug((object)message);
			}
		}

		public static void Info(string message)
		{
			ManualLogSource logger = _logger;
			if (logger != null)
			{
				logger.LogInfo((object)message);
			}
		}

		public static void Warning(string message)
		{
			ManualLogSource logger = _logger;
			if (logger != null)
			{
				logger.LogWarning((object)message);
			}
		}

		public static void Error(string message)
		{
			ManualLogSource logger = _logger;
			if (logger != null)
			{
				logger.LogError((object)message);
			}
		}

		public static void Error(string message, Exception ex)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			ManualLogSource logger = _logger;
			if (logger != null)
			{
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(1, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(message);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\n");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				logger.LogError(val);
			}
		}

		public static void Fatal(string message)
		{
			ManualLogSource logger = _logger;
			if (logger != null)
			{
				logger.LogFatal((object)message);
			}
		}
	}
	public static class ModChatUtils
	{
		public static void SendSystemMessageToAllClients(EntityManager entityManager, string message)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (!VWorld.IsServerWorldReady())
			{
				LoggingHelper.Error("ModChatUtils.SendSystemMessageToAllClients: Server world not ready.");
				return;
			}
			FixedString512Bytes val = default(FixedString512Bytes);
			((FixedString512Bytes)(ref val))..ctor(message);
			ServerChatUtils.SendSystemMessageToAllClients(entityManager, ref val);
		}

		public static void SendSystemMessageToClient(EntityManager entityManager, Entity targetUserEntity, string message)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			if (!VWorld.IsServerWorldReady())
			{
				LoggingHelper.Error("ModChatUtils.SendSystemMessageToClient: Server world not ready.");
			}
			else if (targetUserEntity == Entity.Null)
			{
				LoggingHelper.Warning("ModChatUtils.SendSystemMessageToClient: targetUserEntity is Null.");
			}
			else if (((EntityManager)(ref entityManager)).HasComponent<User>(targetUserEntity))
			{
				User componentData = ((EntityManager)(ref entityManager)).GetComponentData<User>(targetUserEntity);
				if (componentData.IsConnected)
				{
					FixedString512Bytes val = default(FixedString512Bytes);
					((FixedString512Bytes)(ref val))..ctor(message);
					ServerChatUtils.SendSystemMessageToClient(entityManager, componentData, ref val);
					return;
				}
				LoggingHelper.Debug($"ModChatUtils.SendSystemMessageToClient: Target user {targetUserEntity} is not connected.");
			}
			else
			{
				LoggingHelper.Warning($"ModChatUtils.SendSystemMessageToClient: Target entity {targetUserEntity} does not have a User component.");
			}
		}
	}
	public static class UserUtils
	{
		public static bool TryGetUserAndCharacterEntity(string characterNameInput, out Entity foundUserEntity, out Entity foundCharacterEntity, out User foundUserData, out string resolvedCharacterName)
		{
			//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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: 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_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			foundUserEntity = Entity.Null;
			foundCharacterEntity = Entity.Null;
			foundUserData = default(User);
			resolvedCharacterName = null;
			if (!VWorld.IsServerWorldReady())
			{
				LoggingHelper.Error("[BountyForge] UserUtils.TryGetUserAndCharacterEntity: Server world not ready.");
				return false;
			}
			EntityManager entityManager = VWorld.EntityManager;
			EntityQuery val = ((EntityManager)(ref entityManager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<User>() });
			NativeArray<Entity> val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)3));
			bool result = false;
			try
			{
				for (int i = 0; i < val2.Length; i++)
				{
					Entity val3 = val2[i];
					if (!((EntityManager)(ref entityManager)).Exists(val3))
					{
						continue;
					}
					User componentData = ((EntityManager)(ref entityManager)).GetComponentData<User>(val3);
					string text = ((object)(FixedString64Bytes)(ref componentData.CharacterName)).ToString();
					if (text.Equals(characterNameInput, StringComparison.OrdinalIgnoreCase) && componentData.IsConnected)
					{
						Entity entity = componentData.LocalCharacter._Entity;
						if (((EntityManager)(ref entityManager)).Exists(entity) && ((EntityManager)(ref entityManager)).HasComponent<PlayerCharacter>(entity))
						{
							foundUserEntity = val3;
							foundUserData = componentData;
							foundCharacterEntity = entity;
							resolvedCharacterName = text;
							result = true;
							break;
						}
					}
				}
			}
			catch (Exception ex)
			{
				LoggingHelper.Error("[BountyForge] UserUtils: Exception while iterating user entities: " + ex.Message + "\n" + ex.StackTrace);
				result = false;
			}
			finally
			{
				if (val2.IsCreated)
				{
					val2.Dispose();
				}
				((EntityQuery)(ref val)).Dispose();
			}
			return result;
		}

		public static bool TryGetUserDataFromEntity(Entity userEntity, out User userData)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			userData = default(User);
			if (!VWorld.IsServerWorldReady() || userEntity == Entity.Null)
			{
				return false;
			}
			EntityManager entityManager = VWorld.EntityManager;
			if (((EntityManager)(ref entityManager)).Exists(userEntity) && ((EntityManager)(ref entityManager)).HasComponent<User>(userEntity))
			{
				userData = ((EntityManager)(ref entityManager)).GetComponentData<User>(userEntity);
				return true;
			}
			return false;
		}

		public static bool TryGetCharacterEntityFromUserEntity(Entity userEntity, out Entity characterEntity)
		{
			//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_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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)
			characterEntity = Entity.Null;
			if (!VWorld.IsServerWorldReady() || userEntity == Entity.Null)
			{
				return false;
			}
			EntityManager entityManager = VWorld.EntityManager;
			if (TryGetUserDataFromEntity(userEntity, out var userData))
			{
				characterEntity = userData.LocalCharacter._Entity;
				if (((EntityManager)(ref entityManager)).Exists(characterEntity))
				{
					return true;
				}
			}
			return false;
		}

		public static List<User> GetAllOnlineUsers(EntityManager entityManager)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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)
			//IL_003c: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			List<User> list = new List<User>();
			if (!VWorld.IsServerWorldReady() || entityManager == default(EntityManager))
			{
				return list;
			}
			EntityQuery val = ((EntityManager)(ref entityManager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<User>() });
			NativeArray<Entity> val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)3));
			try
			{
				Enumerator<Entity> enumerator = val2.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					if (((EntityManager)(ref entityManager)).Exists(current))
					{
						User componentData = ((EntityManager)(ref entityManager)).GetComponentData<User>(current);
						if (componentData.IsConnected)
						{
							list.Add(componentData);
						}
					}
				}
			}
			finally
			{
				if (val2.IsCreated)
				{
					val2.Dispose();
				}
				((EntityQuery)(ref val)).Dispose();
			}
			return list;
		}

		public static Entity GetUserEntityBySteamID(ulong steamID)
		{
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			if (!VWorld.IsServerWorldReady())
			{
				return Entity.Null;
			}
			EntityManager entityManager = VWorld.EntityManager;
			EntityQuery val = ((EntityManager)(ref entityManager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<User>() });
			NativeArray<Entity> val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)3));
			Entity result = Entity.Null;
			try
			{
				Enumerator<Entity> enumerator = val2.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					if (((EntityManager)(ref entityManager)).Exists(current) && ((EntityManager)(ref entityManager)).HasComponent<User>(current))
					{
						User componentData = ((EntityManager)(ref entityManager)).GetComponentData<User>(current);
						if (componentData.PlatformId == steamID)
						{
							result = current;
							break;
						}
					}
				}
			}
			catch (Exception ex)
			{
				LoggingHelper.Error($"[UserUtils.GetUserEntityBySteamID] Exception finding user for SteamID {steamID}: {ex.Message}\n{ex.StackTrace}");
				result = Entity.Null;
			}
			finally
			{
				if (val2.IsCreated)
				{
					val2.Dispose();
				}
				((EntityQuery)(ref val)).Dispose();
			}
			return result;
		}
	}
	internal static class VWorld
	{
		private static World _serverWorld;

		private static EntityManager _entityManager;

		public static World Server
		{
			get
			{
				//IL_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: 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)
				if (_serverWorld != null && _serverWorld.IsCreated)
				{
					return _serverWorld;
				}
				_serverWorld = GetWorld("Server");
				if (_serverWorld == null || !_serverWorld.IsCreated)
				{
					_entityManager = default(EntityManager);
					return null;
				}
				_entityManager = _serverWorld.EntityManager;
				return _serverWorld;
			}
		}

		public static EntityManager EntityManager
		{
			get
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: 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_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				if (Server == null)
				{
					return default(EntityManager);
				}
				return _entityManager;
			}
		}

		private static World GetWorld(string name)
		{
			if (World.s_AllWorlds == null)
			{
				return null;
			}
			Enumerator<World> enumerator = World.s_AllWorlds.GetEnumerator();
			while (enumerator.MoveNext())
			{
				World current = enumerator.Current;
				if (current.Name == name && current.IsCreated)
				{
					return current;
				}
			}
			return null;
		}

		public static bool IsServerWorldReady()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			return Server != null && EntityManager != default(EntityManager);
		}
	}
}
namespace BountyForge.Systems
{
	public static class BountyManager
	{
		public class BountyDetails
		{
			public ulong TargetSteamID { get; set; }

			public string TargetName { get; set; }

			public ulong PlacerSteamID { get; set; }

			public string PlacerName { get; set; }

			public int PaymentAmount { get; set; }

			public string PaymentItemName { get; set; }

			public int KillsAchievedWhileBountied { get; set; }

			public BountyDetails()
			{
			}

			public BountyDetails(ulong targetId, string targetName, ulong placerId, string placerName, int amount, string itemName)
			{
				TargetSteamID = targetId;
				TargetName = targetName;
				PlacerSteamID = placerId;
				PlacerName = placerName;
				PaymentAmount = amount;
				PaymentItemName = itemName;
				KillsAchievedWhileBountied = 0;
			}
		}

		private static Dictionary<ulong, BountyDetails> _activeBounties = new Dictionary<ulong, BountyDetails>();

		private static string _activeBountiesFilePath;

		private static Dictionary<ulong, AssassinContractDetails> _activeContracts = new Dictionary<ulong, AssassinContractDetails>();

		private static string _activeContractsFilePath;

		private static Dictionary<ulong, Dictionary<ulong, long>> _recentClanBetrayalCache = new Dictionary<ulong, Dictionary<ulong, long>>();

		private static string _clanBetrayalCacheFilePath;

		private static Timer _clanBetrayalCacheCleanupTimer = null;

		private const double CLAN_BETRAYAL_CACHE_CLEANUP_INTERVAL_SECONDS = 3600.0;

		private static Random _rng = new Random();

		private static Timer _contractOfferCycleTimer = null;

		private static Timer _expiredContractsCheckTimer = null;

		private const double EXPIRED_CONTRACT_CHECK_INTERVAL_SECONDS = 30.0;

		public static void Initialize(string dataStorageBasePath)
		{
			_activeBounties.Clear();
			_activeBountiesFilePath = Path.Combine(dataStorageBasePath, "active_bounties.csv");
			LoadActiveBounties();
			_activeContracts.Clear();
			_activeContractsFilePath = Path.Combine(dataStorageBasePath, "active_assassin_contracts.csv");
			LoadActiveContracts();
			_recentClanBetrayalCache.Clear();
			_clanBetrayalCacheFilePath = Path.Combine(dataStorageBasePath, "clan_betrayal_cache.csv");
			LoadClanBetrayalCache();
			ScheduleNextContractOfferAttempt(isInitialCall: true);
			if (_expiredContractsCheckTimer != null)
			{
				_expiredContractsCheckTimer.Dispose();
			}
			_expiredContractsCheckTimer = BountyTaskScheduler.RunActionEveryInterval(CheckForExpiredAssassinContracts, 30.0, 30.0);
			if (_clanBetrayalCacheCleanupTimer != null)
			{
				_clanBetrayalCacheCleanupTimer.Dispose();
			}
			_clanBetrayalCacheCleanupTimer = BountyTaskScheduler.RunActionEveryInterval(CleanupExpiredClanBetrayalCache, 3600.0, 3600.0);
		}

		public static void RecordClanLeave(ulong leaverSteamID, List<ulong> formerClanmateSteamIDs)
		{
			if (!BountyConfig.EnableClanBetrayalPrevention.Value || BountyConfig.ClanBetrayalCooldownSeconds.Value <= 0)
			{
				return;
			}
			long num = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
			long value = num + BountyConfig.ClanBetrayalCooldownSeconds.Value;
			if (!_recentClanBetrayalCache.ContainsKey(leaverSteamID))
			{
				_recentClanBetrayalCache[leaverSteamID] = new Dictionary<ulong, long>();
			}
			foreach (ulong formerClanmateSteamID in formerClanmateSteamIDs)
			{
				if (leaverSteamID != formerClanmateSteamID)
				{
					_recentClanBetrayalCache[leaverSteamID][formerClanmateSteamID] = value;
					if (!_recentClanBetrayalCache.ContainsKey(formerClanmateSteamID))
					{
						_recentClanBetrayalCache[formerClanmateSteamID] = new Dictionary<ulong, long>();
					}
					_recentClanBetrayalCache[formerClanmateSteamID][leaverSteamID] = value;
				}
			}
			SaveClanBetrayalCache();
		}

		private static bool IsClanBetrayal(ulong killerSteamID, ulong victimSteamID)
		{
			if (!BountyConfig.EnableClanBetrayalPrevention.Value)
			{
				return false;
			}
			if (_recentClanBetrayalCache.TryGetValue(killerSteamID, out var value) && value.TryGetValue(victimSteamID, out var value2) && DateTimeOffset.UtcNow.ToUnixTimeSeconds() < value2)
			{
				return true;
			}
			return false;
		}

		private static void CleanupExpiredClanBetrayalCache()
		{
			if (!VWorld.IsServerWorldReady() || !_recentClanBetrayalCache.Any())
			{
				return;
			}
			long num = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
			bool flag = false;
			List<ulong> list = new List<ulong>();
			foreach (KeyValuePair<ulong, Dictionary<ulong, long>> item in _recentClanBetrayalCache)
			{
				List<ulong> list2 = new List<ulong>();
				foreach (KeyValuePair<ulong, long> item2 in item.Value)
				{
					if (num >= item2.Value)
					{
						list2.Add(item2.Key);
					}
				}
				foreach (ulong item3 in list2)
				{
					item.Value.Remove(item3);
					flag = true;
				}
				if (item.Value.Count == 0)
				{
					list.Add(item.Key);
				}
			}
			foreach (ulong item4 in list)
			{
				_recentClanBetrayalCache.Remove(item4);
				flag = true;
			}
			if (flag)
			{
				SaveClanBetrayalCache();
			}
		}

		private static void ScheduleNextContractOfferAttempt(bool isInitialCall = false)
		{
			if (BountyConfig.EnableAssassinContracts.Value)
			{
				int value = BountyConfig.AssassinContractOfferMinIntervalSeconds.Value;
				int value2 = BountyConfig.AssassinContractOfferMaxIntervalSeconds.Value;
				if (value > 0 && value2 > 0 && value <= value2)
				{
					double delayInSeconds = _rng.Next(value, value2 + 1);
					_contractOfferCycleTimer?.Dispose();
					_contractOfferCycleTimer = BountyTaskScheduler.RunActionOnceAfterDelay(AttemptContractOfferCycle, delayInSeconds);
				}
			}
		}

		private static void AttemptContractOfferCycle()
		{
			if (BountyConfig.ModEnabled.Value && BountyConfig.EnableAssassinContracts.Value)
			{
				TryOfferAssassinContract();
			}
			if (BountyConfig.ModEnabled.Value && BountyConfig.EnableAssassinContracts.Value)
			{
				ScheduleNextContractOfferAttempt();
			}
		}

		private static void TryOfferAssassinContract()
		{
			//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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			if (!VWorld.IsServerWorldReady() || !BountyConfig.EnableAssassinContracts.Value)
			{
				return;
			}
			int value = BountyConfig.MaxActiveAssassinContracts.Value;
			if (value > 0 && _activeContracts.Count >= value)
			{
				return;
			}
			EntityManager entityManager = VWorld.EntityManager;
			List<User> allOnlineUsers = UserUtils.GetAllOnlineUsers(entityManager);
			List<User> list = allOnlineUsers.Where((User user) => !_activeContracts.ContainsKey(user.PlatformId) && !_activeBounties.ContainsKey(user.PlatformId) && user.IsConnected && !user.IsAdmin).ToList();
			if (!list.Any())
			{
				return;
			}
			User val = list[_rng.Next(list.Count)];
			string playerName = ((object)(FixedString64Bytes)(ref val.CharacterName)).ToString();
			ulong platformId = val.PlatformId;
			Entity userEntityBySteamID = UserUtils.GetUserEntityBySteamID(platformId);
			if (!(userEntityBySteamID == Entity.Null))
			{
				int num = _rng.Next(BountyConfig.AssassinContractMinKillsRequired.Value, BountyConfig.AssassinContractMaxKillsRequired.Value + 1);
				int value2 = BountyConfig.AssassinContractTimeLimitSeconds.Value;
				long contractEndTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds() + value2;
				int value3 = BountyConfig.AssassinContractMinRewardAmount.Value;
				int value4 = BountyConfig.AssassinContractMaxRewardAmount.Value;
				int num2 = ((value3 >= value4) ? value3 : _rng.Next(value3, value4 + 1));
				if (num2 > 0 && num > 0)
				{
					AssassinContractDetails value5 = new AssassinContractDetails(platformId, playerName, num, contractEndTime, num2);
					_activeContracts[platformId] = value5;
					SaveActiveContracts();
					string message = $"{value2 / 60}m {value2 % 60}s";
					ModChatUtils.SendSystemMessageToClient(entityManager, userEntityBySteamID, ChatColors.SuccessText("You have received a contract from the association!"));
					ModChatUtils.SendSystemMessageToClient(entityManager, userEntityBySteamID, string.Format("{0}{1}{2}{3}{4}", ChatColors.InfoText("Eliminate "), ChatColors.ErrorText(num.ToString()), ChatColors.InfoText(" players within "), ChatColors.ErrorText(message), ChatColors.InfoText(".")));
					ModChatUtils.SendSystemMessageToClient(entityManager, userEntityBySteamID, ChatColors.InfoText($"Reward for success: {num2} {BountyConfig.PaymentItemDisplayName.Value}. Failure means no reward."));
				}
			}
		}

		private static void CheckForExpiredAssassinContracts()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//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_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			if (!VWorld.IsServerWorldReady() || !_activeContracts.Any() || !BountyConfig.ModEnabled.Value || !BountyConfig.EnableAssassinContracts.Value)
			{
				return;
			}
			List<ulong> list = new List<ulong>();
			long num = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
			EntityManager entityManager = VWorld.EntityManager;
			foreach (KeyValuePair<ulong, AssassinContractDetails> item in _activeContracts.ToList())
			{
				if (num >= item.Value.ContractEndTimeUnixTimestamp && !list.Contains(item.Key))
				{
					list.Add(item.Key);
				}
			}
			bool flag = false;
			if (list.Any())
			{
				foreach (ulong item2 in list)
				{
					if (_activeContracts.TryGetValue(item2, out var _))
					{
						Entity userEntityBySteamID = UserUtils.GetUserEntityBySteamID(item2);
						if (userEntityBySteamID != Entity.Null)
						{
							ModChatUtils.SendSystemMessageToClient(entityManager, userEntityBySteamID, ChatColors.ErrorText("Time's up! Your contract has expired. You have failed the association's requests."));
						}
						_activeContracts.Remove(item2);
						flag = true;
					}
				}
			}
			if (flag)
			{
				SaveActiveContracts();
			}
		}

		public static bool TryGetActiveAssassinContract(ulong playerSteamID, out AssassinContractDetails contractDetails)
		{
			return _activeContracts.TryGetValue(playerSteamID, out contractDetails);
		}

		public static bool IsPlayerBountied(ulong playerSteamID, out BountyDetails bountyDetails)
		{
			return _activeBounties.TryGetValue(playerSteamID, out bountyDetails);
		}

		public static void TryPlaceBounty(Entity placerCharacterEntity, string placerName, ulong placerSteamID, string targetPlayerName, int bountyAmount, ChatCommandContext ctx)
		{
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: 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_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0386: 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_02ea: Unknown result type (might be due to invalid IL or missing references)
			if (!VWorld.IsServerWorldReady())
			{
				ctx.Reply(ChatColors.ErrorText("Server is not ready."));
				return;
			}
			if (bountyAmount < BountyConfig.MinimumBountyAmount.Value)
			{
				ctx.Reply(ChatColors.ErrorText($"Internal error: Bounty amount {bountyAmount} is less than minimum {BountyConfig.MinimumBountyAmount.Value}."));
				return;
			}
			if (bountyAmount <= 0)
			{
				ctx.Reply(ChatColors.ErrorText("Internal error: Bounty amount must be positive."));
				return;
			}
			EntityManager entityManager = VWorld.EntityManager;
			if (!UserUtils.TryGetUserAndCharacterEntity(targetPlayerName, out var _, out var foundCharacterEntity, out var foundUserData, out var resolvedCharacterName))
			{
				ctx.Reply(ChatColors.ErrorText("Player '" + targetPlayerName + "' not found or is not online."));
				return;
			}
			if (foundUserData.PlatformId == placerSteamID)
			{
				ctx.Reply(ChatColors.HighlightText("You can't backstab your friend this early!"));
				return;
			}
			if (_activeBounties.ContainsKey(foundUserData.PlatformId))
			{
				ctx.Reply(ChatColors.ErrorText(ChatColors.BountyTargetNameText(resolvedCharacterName) + " already has an active bounty."));
				return;
			}
			PrefabGUID bountyPaymentItemGUID = ItemUtils.GetBountyPaymentItemGUID();
			string bountyPaymentItemName = ItemUtils.GetBountyPaymentItemName();
			if (!InventoryUtils.PlayerHasEnoughItems(placerCharacterEntity, bountyPaymentItemGUID, bountyAmount))
			{
				ctx.Reply($"<color={"#FF4136"}>You do not have enough {bountyPaymentItemName} <color={"#FFDC00"}>{bountyAmount}</color> required.</color>");
				return;
			}
			if (!InventoryUtils.TryRemoveItemsFromPlayer(placerCharacterEntity, bountyPaymentItemGUID, bountyAmount))
			{
				ctx.Reply(ChatColors.ErrorText($"Failed to take {ChatColors.HighlightText(bountyAmount.ToString())} {ChatColors.BountyItemText(bountyPaymentItemName)}."));
				return;
			}
			BountyDetails value = new BountyDetails(foundUserData.PlatformId, resolvedCharacterName, placerSteamID, placerName, bountyAmount, bountyPaymentItemName);
			_activeBounties[foundUserData.PlatformId] = value;
			SaveActiveBounties();
			if (BountyConfig.EnableMapIcons.Value && foundCharacterEntity != Entity.Null)
			{
				BountyMapIcons.AddMapIcon(foundCharacterEntity, foundUserData.PlatformId);
			}
			ctx.Reply(string.Format("{0}{1}{2}{3}.", ChatColors.InfoText($"Bounty of {bountyAmount} {bountyPaymentItemName} "), ChatColors.SuccessText("successfully"), ChatColors.InfoText(" placed on "), ChatColors.BountyTargetNameText(resolvedCharacterName)));
			ModChatUtils.SendSystemMessageToAllClients(entityManager, string.Format("{0}{1}{2}{3}{4}!", ChatColors.BountyTargetNameText(placerName), ChatColors.InfoText(" has placed a bounty on "), ChatColors.BountyTargetNameText(resolvedCharacterName), ChatColors.InfoText(" for "), ChatColors.SuccessText(bountyAmount + " " + bountyPaymentItemName)));
		}

		public static void HandlePvPKillEvent(Entity victimUserEntity, string victimName, ulong victimSteamID, Entity killerUserEntity, string killerName, ulong killerSteamID)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0626: Unknown result type (might be due to invalid IL or missing references)
			//IL_0627: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_0419: Unknown result type (might be due to invalid IL or missing references)
			//IL_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0563: Unknown result type (might be due to invalid IL or missing references)
			//IL_0564: Unknown result type (might be due to invalid IL or missing references)
			//IL_046c: Unknown result type (might be due to invalid IL or missing references)
			//IL_046d: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0507: Unknown result type (might be due to invalid IL or missing references)
			//IL_0509: Unknown result type (might be due to invalid IL or missing references)
			if (!VWorld.IsServerWorldReady())
			{
				return;
			}
			EntityManager entityManager = VWorld.EntityManager;
			bool flag = false;
			bool flag2 = false;
			bool flag3 = false;
			bool flag4 = IsClanBetrayal(killerSteamID, victimSteamID);
			if (flag4 && _activeBounties.ContainsKey(victimSteamID))
			{
				ModChatUtils.SendSystemMessageToClient(entityManager, killerUserEntity, ChatColors.HighlightText("You can't backstab your friend this early!"));
			}
			if (_activeBounties.TryGetValue(victimSteamID, out var value) && !flag4)
			{
				if (killerSteamID == value.PlacerSteamID)
				{
					if (BountyConfig.ForbidPlacerReclaimingPayment.Value)
					{
						ModChatUtils.SendSystemMessageToClient(entityManager, killerUserEntity, ChatColors.InfoText("You killed " + ChatColors.BountyTargetNameText(victimName) + ", your bounty target. No payment will be given."));
						ModChatUtils.SendSystemMessageToAllClients(entityManager, ChatColors.BountyPosterNameText(killerName) + " neutralized their own bounty on " + ChatColors.BountyTargetNameText(victimName) + ". They shall not get paid.");
					}
					else
					{
						ModChatUtils.SendSystemMessageToClient(entityManager, killerUserEntity, ChatColors.SuccessText("You killed " + ChatColors.BountyTargetNameText(victimName) + ", your bounty target. Bounty cleared, payment reclaimed."));
						ModChatUtils.SendSystemMessageToAllClients(entityManager, ChatColors.BountyPosterNameText(killerName) + " cleared their own bounty on " + ChatColors.BountyTargetNameText(victimName) + " and reclaimed the payment!");
						if (UserUtils.TryGetCharacterEntityFromUserEntity(killerUserEntity, out var characterEntity))
						{
							InventoryUtils.TryAddItemsToPlayer(characterEntity, ItemUtils.GetBountyPaymentItemGUID(), value.PaymentAmount);
						}
						if (BountyConfig.PlacerReclaimAddsToScore.Value)
						{
							LeaderboardSystem.UpdatePlayerClaimedBounty(killerSteamID, killerName, value.PaymentAmount);
							flag2 = true;
						}
					}
				}
				else
				{
					if (UserUtils.TryGetCharacterEntityFromUserEntity(killerUserEntity, out var characterEntity2))
					{
						InventoryUtils.TryAddItemsToPlayer(characterEntity2, ItemUtils.GetBountyPaymentItemGUID(), value.PaymentAmount);
					}
					ModChatUtils.SendSystemMessageToClient(entityManager, killerUserEntity, ChatColors.SuccessText($"You collected the {ChatColors.BountyItemText(value.PaymentAmount + " " + value.PaymentItemName)} bounty on {ChatColors.BountyTargetNameText(victimName)}!"));
					ModChatUtils.SendSystemMessageToAllClients(entityManager, $"{ChatColors.BountyTargetNameText(killerName)} collected the bounty on {ChatColors.BountyTargetNameText(victimName)} for {ChatColors.BountyItemText(value.PaymentAmount + " " + value.PaymentItemName)}!");
					LeaderboardSystem.UpdatePlayerClaimedBounty(killerSteamID, killerName, value.PaymentAmount);
					flag2 = true;
				}
				_activeBounties.Remove(victimSteamID);
				flag = true;
				if (BountyConfig.EnableMapIcons.Value)
				{
					BountyMapIcons.RemoveMapIcon(victimSteamID);
				}
			}
			if (BountyConfig.EnableTargetSelfClaimViaKills.Value && _activeBounties.TryGetValue(killerSteamID, out var value2) && victimUserEntity != Entity.Null && victimSteamID != killerSteamID)
			{
				value2.KillsAchievedWhileBountied++;
				_activeBounties[killerSteamID] = value2;
				flag = true;
				if (value2.KillsAchievedWhileBountied >= BountyConfig.KillsForTargetSelfClaim.Value)
				{
					ProcessTargetSelfClaim(killerUserEntity, killerName, killerSteamID, value2);
				}
				else
				{
					ModChatUtils.SendSystemMessageToClient(entityManager, killerUserEntity, ChatColors.InfoText("You have an active bounty on you. Get " + ChatColors.HighlightText(Math.Max(0, BountyConfig.KillsForTargetSelfClaim.Value - value2.KillsAchievedWhileBountied).ToString()) + " kill(s) to claim it!"));
				}
			}
			if (_activeContracts.TryGetValue(killerSteamID, out var value3))
			{
				if (!value3.IsExpired())
				{
					bool flag5 = false;
					if (flag4 && BountyConfig.EnableClanBetrayalPrevention.Value)
					{
						flag5 = true;
						ModChatUtils.SendSystemMessageToClient(entityManager, killerUserEntity, ChatColors.HighlightText("This kill on a former clanmate does not count towards your contract."));
					}
					if (!flag5)
					{
						value3.KillsAchieved++;
						if (value3.KillsAchieved >= value3.KillsRequired)
						{
							ModChatUtils.SendSystemMessageToClient(entityManager, killerUserEntity, ChatColors.SuccessText($"Contract complete! You have eliminated {value3.KillsRequired} targets."));
							ModChatUtils.SendSystemMessageToClient(entityManager, killerUserEntity, ChatColors.SuccessText("Reward: " + ChatColors.BountyItemText(value3.RewardAmount + " " + BountyConfig.PaymentItemDisplayName.Value) + " has been paid."));
							if (UserUtils.TryGetCharacterEntityFromUserEntity(killerUserEntity, out var characterEntity3))
							{
								InventoryUtils.TryAddItemsToPlayer(characterEntity3, ItemUtils.GetBountyPaymentItemGUID(), value3.RewardAmount);
							}
							LeaderboardSystem.UpdatePlayerClaimedBounty(killerSteamID, killerName, value3.RewardAmount);
							flag2 = true;
							_activeContracts.Remove(killerSteamID);
						}
						else
						{
							_activeContracts[killerSteamID] = value3;
							int num = value3.KillsRequired - value3.KillsAchieved;
							ModChatUtils.SendSystemMessageToClient(entityManager, killerUserEntity, ChatColors.InfoText($"Contract progress: {value3.KillsAchieved}/{value3.KillsRequired} targets eliminated. {ChatColors.HighlightText(num.ToString())} more to go."));
						}
						flag3 = true;
					}
				}
				else
				{
					ModChatUtils.SendSystemMessageToClient(entityManager, killerUserEntity, ChatColors.ErrorText("Too slow! Your contract had already expired. This kill does not count."));
					_activeContracts.Remove(killerSteamID);
					flag3 = true;
				}
			}
			if (_activeContracts.TryGetValue(victimSteamID, out var _))
			{
				ModChatUtils.SendSystemMessageToClient(entityManager, victimUserEntity, ChatColors.ErrorText("You were eliminated. Your contract has been voided. You have failed the association's requests."));
				_activeContracts.Remove(victimSteamID);
				flag3 = true;
			}
			if (flag)
			{
				SaveActiveBounties();
			}
			if (flag2)
			{
				LeaderboardSystem.SaveLeaderboard();
			}
			if (flag3)
			{
				SaveActiveContracts();
			}
		}

		private static void ProcessTargetSelfClaim(Entity targetUserEntity, string targetName, ulong targetSteamID, BountyDetails bountyDetails)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = VWorld.EntityManager;
			ModChatUtils.SendSystemMessageToAllClients(entityManager, ChatColors.BountyTargetNameText(targetName) + " achieved " + ChatColors.HighlightText(BountyConfig.KillsForTargetSelfClaim.Value.ToString()) + " kills and has " + ChatColors.SuccessText("claimed their own bounty") + " of " + ChatColors.BountyItemText(bountyDetails.PaymentAmount + " " + bountyDetails.PaymentItemName) + "!");
			if (UserUtils.TryGetCharacterEntityFromUserEntity(targetUserEntity, out var characterEntity))
			{
				InventoryUtils.TryAddItemsToPlayer(characterEntity, ItemUtils.GetBountyPaymentItemGUID(), bountyDetails.PaymentAmount);
			}
			if (BountyConfig.TargetSelfClaimAddsToScore.Value)
			{
				LeaderboardSystem.UpdatePlayerClaimedBounty(targetSteamID, targetName, bountyDetails.PaymentAmount);
				LeaderboardSystem.SaveLeaderboard();
			}
			_activeBounties.Remove(targetSteamID);
			SaveActiveBounties();
			if (BountyConfig.EnableMapIcons.Value)
			{
				BountyMapIcons.RemoveMapIcon(targetSteamID);
			}
		}

		public static void SaveActiveBounties()
		{
			try
			{
				List<string> list = new List<string> { "TargetSteamID,TargetName,PlacerSteamID,PlacerName,PaymentAmount,PaymentItemName,KillsAchievedWhileBountied" };
				foreach (BountyDetails value in _activeBounties.Values)
				{
					list.Add($"{value.TargetSteamID},{EscapeCSV(value.TargetName)},{value.PlacerSteamID},{EscapeCSV(value.PlacerName)},{value.PaymentAmount},{EscapeCSV(value.PaymentItemName)},{value.KillsAchievedWhileBountied}");
				}
				File.WriteAllLines(_activeBountiesFilePath, list);
			}
			catch (Exception)
			{
			}
		}

		private static void LoadActiveBounties()
		{
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			if (!File.Exists(_activeBountiesFilePath))
			{
				return;
			}
			try
			{
				string[] array = File.ReadAllLines(_activeBountiesFilePath);
				if (array.Length <= 1)
				{
					return;
				}
				_activeBounties.Clear();
				bool flag = array[0].Contains("KillsAchievedWhileBountied");
				for (int i = 1; i < array.Length; i++)
				{
					if (string.IsNullOrWhiteSpace(array[i]))
					{
						continue;
					}
					List<string> list = SplitCsvLine(array[i]);
					if (list.Count >= (flag ? 7 : 6) && ulong.TryParse(list[0], out var result) && ulong.TryParse(list[2], out var result2) && int.TryParse(list[4], out var result3))
					{
						int killsAchievedWhileBountied = 0;
						if (flag && list.Count >= 7 && int.TryParse(list[6], out var result4))
						{
							killsAchievedWhileBountied = result4;
						}
						BountyDetails bountyDetails = new BountyDetails(result, UnescapeCSV(list[1]), result2, UnescapeCSV(list[3]), result3, UnescapeCSV(list[5]))
						{
							KillsAchievedWhileBountied = killsAchievedWhileBountied
						};
						_activeBounties[result] = bountyDetails;
						if (BountyConfig.EnableMapIcons.Value && VWorld.IsServerWorldReady() && UserUtils.TryGetUserAndCharacterEntity(bountyDetails.TargetName, out var _, out var foundCharacterEntity, out var foundUserData, out var _) && foundCharacterEntity != Entity.Null && foundUserData.IsConnected)
						{
							BountyMapIcons.AddMapIcon(foundCharacterEntity, bountyDetails.TargetSteamID);
						}
					}
				}
			}
			catch (Exception)
			{
				_activeBounties.Clear();
			}
		}

		public static void SaveActiveContracts()
		{
			try
			{
				List<string> list = new List<string> { "PlayerSteamID,PlayerName,KillsRequired,KillsAchieved,ContractEndTimeUnixTimestamp,RewardAmount" };
				foreach (AssassinContractDetails value in _activeContracts.Values)
				{
					list.Add($"{value.PlayerSteamID},{EscapeCSV(value.PlayerName)},{value.KillsRequired},{value.KillsAchieved},{value.ContractEndTimeUnixTimestamp},{value.RewardAmount}");
				}
				File.WriteAllLines(_activeContractsFilePath, list);
			}
			catch (Exception)
			{
			}
		}

		private static void LoadActiveContracts()
		{
			if (!File.Exists(_activeContractsFilePath))
			{
				return;
			}
			try
			{
				string[] array = File.ReadAllLines(_activeContractsFilePath);
				if (array.Length <= 1)
				{
					return;
				}
				_activeContracts.Clear();
				for (int i = 1; i < array.Length; i++)
				{
					if (string.IsNullOrWhiteSpace(array[i]))
					{
						continue;
					}
					List<string> list = SplitCsvLine(array[i]);
					if (list.Count == 6 && ulong.TryParse(list[0], out var result) && int.TryParse(list[2], out var result2) && int.TryParse(list[3], out var result3) && long.TryParse(list[4], out var result4) && int.TryParse(list[5], out var result5))
					{
						AssassinContractDetails assassinContractDetails = new AssassinContractDetails(result, UnescapeCSV(list[1]), result2, result4, result5)
						{
							KillsAchieved = result3
						};
						if (!assassinContractDetails.IsExpired())
						{
							_activeContracts[result] = assassinContractDetails;
						}
					}
				}
			}
			catch (Exception)
			{
				_activeContracts.Clear();
			}
		}

		private static void SaveClanBetrayalCache()
		{
			if (!BountyConfig.EnableClanBetrayalPrevention.Value)
			{
				return;
			}
			try
			{
				List<string> list = new List<string> { "PlayerA_SteamID,PlayerB_SteamID,ExpiryTimestamp" };
				HashSet<Tuple<ulong, ulong>> hashSet = new HashSet<Tuple<ulong, ulong>>();
				foreach (KeyValuePair<ulong, Dictionary<ulong, long>> item in _recentClanBetrayalCache)
				{
					ulong key = item.Key;
					foreach (KeyValuePair<ulong, long> item2 in item.Value)
					{
						ulong key2 = item2.Key;
						long value = item2.Value;
						Tuple<ulong, ulong> tuple = ((key < key2) ? Tuple.Create(key, key2) : Tuple.Create(key2, key));
						if (!hashSet.Contains(tuple))
						{
							list.Add($"{tuple.Item1},{tuple.Item2},{value}");
							hashSet.Add(tuple);
						}
					}
				}
				File.WriteAllLines(_clanBetrayalCacheFilePath, list);
			}
			catch (Exception)
			{
			}
		}

		private static void LoadClanBetrayalCache()
		{
			if (!BountyConfig.EnableClanBetrayalPrevention.Value || !File.Exists(_clanBetrayalCacheFilePath))
			{
				_recentClanBetrayalCache.Clear();
				return;
			}
			try
			{
				string[] array = File.ReadAllLines(_clanBetrayalCacheFilePath);
				if (array.Length <= 1)
				{
					return;
				}
				_recentClanBetrayalCache.Clear();
				long num = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
				for (int i = 1; i < array.Length; i++)
				{
					if (string.IsNullOrWhiteSpace(array[i]))
					{
						continue;
					}
					List<string> list = SplitCsvLine(array[i]);
					if (list.Count == 3 && ulong.TryParse(list[0], out var result) && ulong.TryParse(list[1], out var result2) && long.TryParse(list[2], out var result3) && result3 > num)
					{
						if (!_recentClanBetrayalCache.ContainsKey(result))
						{
							_recentClanBetrayalCache[result] = new Dictionary<ulong, long>();
						}
						_recentClanBetrayalCache[result][result2] = result3;
						if (!_recentClanBetrayalCache.ContainsKey(result2))
						{
							_recentClanBetrayalCache[result2] = new Dictionary<ulong, long>();
						}
						_recentClanBetrayalCache[result2][result] = result3;
					}
				}
			}
			catch (Exception)
			{
				_recentClanBetrayalCache.Clear();
			}
		}

		private static string EscapeCSV(string value)
		{
			if (string.IsNullOrEmpty(value))
			{
				return "";
			}
			if (value.Contains(',') || value.Contains('"') || value.Contains('\n'))
			{
				return "\"" + value.Replace("\"", "\"\"") + "\"";
			}
			return value;
		}

		private static string UnescapeCSV(string value)
		{
			if (string.IsNullOrEmpty(value))
			{
				return "";
			}
			if (value.StartsWith("\"") && value.EndsWith("\""))
			{
				value = value.Substring(1, value.Length - 2).Replace("\"\"", "\"");
			}
			return value;
		}

		private static List<string> SplitCsvLine(string line)
		{
			List<string> list = new List<string>();
			if (string.IsNullOrEmpty(line))
			{
				return list;
			}
			StringBuilder stringBuilder = new StringBuilder();
			bool flag = false;
			for (int i = 0; i < line.Length; i++)
			{
				char c = line[i];
				switch (c)
				{
				case '"':
					if (i + 1 < line.Length && line[i + 1] == '"')
					{
						stringBuilder.Append('"');
						i++;
					}
					else
					{
						flag = !flag;
					}
					continue;
				case ',':
					if (!flag)
					{
						list.Add(stringBuilder.ToString());
						stringBuilder.Clear();
						continue;
					}
					break;
				}
				stringBuilder.Append(c);
			}
			list.Add(stringBuilder.ToString());
			return list;
		}

		public static void ListActiveBounties(ChatCommandContext ctx)
		{
			if (_activeBounties.Count == 0)
			{
				ctx.Reply(ChatColors.InfoText("No active bounties at this time."));
				return;
			}
			ctx.Reply(ChatColors.HighlightText("--- Active  Bounties ---"));
			int num = 1;
			foreach (BountyDetails item in _activeBounties.Values.OrderByDescending((BountyDetails b) => b.PaymentAmount))
			{
				string value = ChatColors.HighlightText(num + ".");
				string value2 = ChatColors.HighlightText("Target:");
				string value3 = ChatColors.InfoText(item.TargetName);
				string value4 = ChatColors.HighlightText("Placed by:");
				string value5 = ChatColors.InfoText(item.PlacerName);
				string value6 = ChatColors.HighlightText("Reward:");
				string value7 = ChatColors.InfoText(item.PaymentAmount + " " + item.PaymentItemName);
				ctx.Reply($"{value} {value2} {value3}, {value4} {value5}, {value6} {value7}");
				num++;
			}
		}
	}
	public static class BountyMapIcons
	{
		private static PrefabGUID _configuredDefaultBountyIconStyleGuid;

		private static bool _mapIconsSystemEnabled;

		private static Dictionary<PrefabGUID, Entity> _iconStylePrefabEntityCache = new Dictionary<PrefabGUID, Entity>();

		private static Dictionary<ulong, Entity> _activePlayerBountyIcons = new Dictionary<ulong, Entity>();

		public static void Initialize()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			_activePlayerBountyIcons.Clear();
			_iconStylePrefabEntityCache.Clear();
			_mapIconsSystemEnabled = BountyConfig.EnableMapIcons.Value;
			if (_mapIconsSystemEnabled)
			{
				_configuredDefaultBountyIconStyleGuid = new PrefabGUID(BountyConfig.BountyMapIconGUID.Value);
				if (((PrefabGUID)(ref _configuredDefaultBountyIconStyleGuid)).GuidHash != 0)
				{
					TryCacheIconStylePrefab(_configuredDefaultBountyIconStyleGuid, out var _);
				}
			}
		}

		private static bool TryCacheIconStylePrefab(PrefabGUID iconStyleGuid, out Entity prefabEntity)
		{
			//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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			prefabEntity = Entity.Null;
			if (((PrefabGUID)(ref iconStyleGuid)).GuidHash == 0)
			{
				return false;
			}
			if (_iconStylePrefabEntityCache.TryGetValue(iconStyleGuid, out var value))
			{
				if (VWorld.IsServerWorldReady())
				{
					EntityManager entityManager = VWorld.EntityManager;
					if (((EntityManager)(ref entityManager)).Exists(value))
					{
						prefabEntity = value;
						return true;
					}
				}
				_iconStylePrefabEntityCache.Remove(iconStyleGuid);
			}
			if (!VWorld.IsServerWorldReady())
			{
				return false;
			}
			PrefabCollectionSystem existingSystemManaged = VWorld.Server.GetExistingSystemManaged<PrefabCollectionSystem>();
			Entity val = default(Entity);
			if (existingSystemManaged != null && existingSystemManaged._PrefabGuidToEntityMap.IsCreated && existingSystemManaged._PrefabGuidToEntityMap.TryGetValue(iconStyleGuid, ref val))
			{
				_iconStylePrefabEntityCache[iconStyleGuid] = val;
				prefabEntity = val;
				return true;
			}
			return false;
		}

		public static void AddMapIcon(Entity targetCharacterEntity, ulong targetSteamID)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			AddMapIcon(targetCharacterEntity, targetSteamID, _configuredDefaultBountyIconStyleGuid);
		}

		public static void AddMapIcon(Entity targetCharacterEntity, ulong targetSteamID, PrefabGUID iconStyleGuidToUse)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: 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_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: 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_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: 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)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			if (!_mapIconsSystemEnabled)
			{
				return;
			}
			PrefabGUID iconStyleGuid = iconStyleGuidToUse;
			if (((PrefabGUID)(ref iconStyleGuid)).GuidHash == 0 || !VWorld.IsServerWorldReady() || !TryCacheIconStylePrefab(iconStyleGuid, out var prefabEntity) || prefabEntity == Entity.Null)
			{
				return;
			}
			if (_activePlayerBountyIcons.TryGetValue(targetSteamID, out var value))
			{
				RemoveMapIconInternal(targetSteamID, value, isReplacing: true);
			}
			EntityManager entityManager = VWorld.EntityManager;
			if (!((EntityManager)(ref entityManager)).Exists(targetCharacterEntity) || !((EntityManager)(ref entityManager)).HasComponent<PlayerCharacter>(targetCharacterEntity))
			{
				return;
			}
			try
			{
				Entity val = ((EntityManager)(ref entityManager)).Instantiate(prefabEntity);
				if (!((EntityManager)(ref entityManager)).HasComponent<MapIconData>(val))
				{
					((EntityManager)(ref entityManager)).AddComponent<MapIconData>(val);
				}
				MapIconData componentData = ((EntityManager)(ref entityManager)).GetComponentData<MapIconData>(val);
				PlayerCharacter componentData2 = ((EntityManager)(ref entityManager)).GetComponentData<PlayerCharacter>(targetCharacterEntity);
				if (((EntityManager)(ref entityManager)).HasComponent<User>(componentData2.UserEntity))
				{
					componentData.TargetUser = componentData2.UserEntity;
					((EntityManager)(ref entityManager)).SetComponentData<MapIconData>(val, componentData);
				}
				if (!((EntityManager)(ref entityManager)).HasComponent<MapIconTargetEntity>(val))
				{
					((EntityManager)(ref entityManager)).AddComponent<MapIconTargetEntity>(val);
				}
				((EntityManager)(ref entityManager)).SetComponentData<MapIconTargetEntity>(val, new MapIconTargetEntity
				{
					TargetEntity = NetworkedEntity.op_Implicit(targetCharacterEntity),
					TargetNetworkId = ((EntityManager)(ref entityManager)).GetComponentData<NetworkId>(targetCharacterEntity)
				});
				if (((EntityManager)(ref entityManager)).HasComponent<SyncToUserBitMask>(val))
				{
					((EntityManager)(ref entityManager)).RemoveComponent<SyncToUserBitMask>(val);
				}
				if (((EntityManager)(ref entityManager)).HasBuffer<SyncToUserBuffer>(val))
				{
					((EntityManager)(ref entityManager)).GetBuffer<SyncToUserBuffer>(val, false).Clear();
				}
				if (((EntityManager)(ref entityManager)).HasComponent<OnlySyncToUsersTag>(val))
				{
					((EntityManager)(ref entityManager)).RemoveComponent<OnlySyncToUsersTag>(val);
				}
				_activePlayerBountyIcons[targetSteamID] = val;
			}
			catch (Exception)
			{
			}
		}

		private static void RemoveMapIconInternal(ulong targetSteamID, Entity iconEntity, bool isReplacing = false)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			if (!VWorld.IsServerWorldReady())
			{
				return;
			}
			EntityManager entityManager = VWorld.EntityManager;
			if (!((EntityManager)(ref entityManager)).Exists(iconEntity))
			{
				if (!isReplacing)
				{
					_activePlayerBountyIcons.Remove(targetSteamID);
				}
				return;
			}
			try
			{
				StatChangeUtility.KillOrDestroyEntity(entityManager, iconEntity, iconEntity, Entity.Null, 0.0, (StatChangeReason)0, true);
			}
			catch (Exception)
			{
			}
			finally
			{
				if (!isReplacing)
				{
					_activePlayerBountyIcons.Remove(targetSteamID);
				}
			}
		}

		public static void RemoveMapIcon(ulong targetSteamID)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0