Decompiled source of HackIt v1.0.5

HackIt.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EmpressHackIt.Core;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Empress")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HackIt")]
[assembly: AssemblyTitle("HackIt")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 EmpressHackIt
{
	[BepInPlugin("empress.repo.hackit", "HackIt", "1.0.0")]
	public sealed class HackItPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "empress.repo.hackit";

		public const string PluginName = "HackIt";

		public const string PluginVersion = "1.0.0";

		private const string ImagineFlaggingADestroyHookWhileShippingSelfUnpatchLOL = "ImagineFlaggingADestroyHookWhileShippingSelfUnpatchLOL";

		private static Harmony? _harmony;

		private static GameObject? _runtimeHost;

		private static bool _sceneHooked;

		internal static HackItPlugin Instance { get; private set; }

		internal static ManualLogSourceProxy LogProxy { get; private set; }

		internal static ConfigEntry<bool> Enabled { get; private set; }

		internal static ConfigEntry<KeyboardShortcut> TogglePopupKey { get; private set; }

		internal static ConfigEntry<bool> AllowClientRequests { get; private set; }

		internal static ConfigEntry<float> PopupTargetRange { get; private set; }

		private void Awake()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			Instance = this;
			LogProxy = new ManualLogSourceProxy(((BaseUnityPlugin)this).Logger);
			BindConfig();
			if (!_sceneHooked)
			{
				SceneManager.sceneLoaded += HandleSceneLoaded;
				_sceneHooked = true;
			}
			if (_harmony == null)
			{
				_harmony = new Harmony("empress.repo.hackit");
				_harmony.PatchAll();
			}
			EnsureRuntimeHost();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"HackIt 1.0.0 loaded.");
		}

		private void BindConfig()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			if (Enabled == null)
			{
				Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable HackIt.");
			}
			if (TogglePopupKey == null)
			{
				TogglePopupKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "TogglePopupKey", new KeyboardShortcut((KeyCode)287, Array.Empty<KeyCode>()), "Toggle the Empress HackIt popup.");
			}
			if (AllowClientRequests == null)
			{
				AllowClientRequests = ((BaseUnityPlugin)this).Config.Bind<bool>("Networking", "AllowClientRequests", true, "Allow non-host clients to send hack requests to the host.");
			}
			if (PopupTargetRange == null)
			{
				PopupTargetRange = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "PopupTargetRange", 12f, "Targeting range for the HackIt popup.");
			}
		}

		private static void EnsureRuntimeHost()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			if ((Object)(object)_runtimeHost != (Object)null)
			{
				if ((Object)(object)_runtimeHost.GetComponent<HackItRuntime>() == (Object)null)
				{
					_runtimeHost.AddComponent<HackItRuntime>();
				}
			}
			else
			{
				_runtimeHost = new GameObject("EmpressHackItRuntime");
				Object.DontDestroyOnLoad((Object)(object)_runtimeHost);
				_runtimeHost.AddComponent<HackItRuntime>();
			}
		}

		private static void HandleSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			EnsureRuntimeHost();
		}
	}
	internal sealed class ManualLogSourceProxy
	{
		private readonly ManualLogSource _logger;

		public ManualLogSourceProxy(ManualLogSource logger)
		{
			_logger = logger;
		}

		public void Info(string message)
		{
			_logger.LogInfo((object)message);
		}

		public void Warning(string message)
		{
			_logger.LogWarning((object)message);
		}

		public void Error(string message)
		{
			_logger.LogError((object)message);
		}
	}
	internal static class HackItAccess
	{
		private static readonly FieldInfo? CurrencyUiInstanceField = AccessTools.Field(typeof(CurrencyUI), "instance");

		private static readonly FieldInfo? EnemyCurrentStateField = AccessTools.Field(typeof(Enemy), "CurrentState");

		private static readonly FieldInfo? EnemyHasVisionField = AccessTools.Field(typeof(Enemy), "HasVision");

		private static readonly FieldInfo? EnemyMasterClientField = AccessTools.Field(typeof(Enemy), "MasterClient");

		private static readonly FieldInfo? EnemyParentField = AccessTools.Field(typeof(Enemy), "EnemyParent");

		private static readonly FieldInfo? EnemyParentEnemyField = AccessTools.Field(typeof(EnemyParent), "Enemy");

		private static readonly FieldInfo? EnemyStateChaseBeginEnemyField = AccessTools.Field(typeof(EnemyStateChaseBegin), "Enemy");

		private static readonly FieldInfo? EnemyStateChaseEnemyField = AccessTools.Field(typeof(EnemyStateChase), "Enemy");

		private static readonly FieldInfo? EnemyTargetPlayerAvatarField = AccessTools.Field(typeof(Enemy), "TargetPlayerAvatar");

		private static readonly FieldInfo? EnemyTargetPlayerViewIdField = AccessTools.Field(typeof(Enemy), "TargetPlayerViewID");

		private static readonly FieldInfo? EnemyVisionEnemyField = AccessTools.Field(typeof(EnemyVision), "Enemy");

		private static readonly FieldInfo? EnemyVisionField = AccessTools.Field(typeof(Enemy), "Vision");

		private static readonly FieldInfo? EnemyParentEnemyNameField = AccessTools.Field(typeof(EnemyParent), "enemyName");

		private static readonly FieldInfo? EnemyRigidbodyEnemyField = AccessTools.Field(typeof(EnemyRigidbody), "enemy");

		private static readonly FieldInfo? EnemyRigidbodyEnemyParentField = AccessTools.Field(typeof(EnemyRigidbody), "enemyParent");

		private static readonly FieldInfo? ExtractionPointExtractionHaulField = AccessTools.Field(typeof(ExtractionPoint), "extractionHaul");

		private static readonly FieldInfo? ExtractionPointHaulCurrentField = AccessTools.Field(typeof(ExtractionPoint), "haulCurrent");

		private static readonly FieldInfo? ExtractionPointIsShopField = AccessTools.Field(typeof(ExtractionPoint), "isShop");

		private static readonly FieldInfo? ExtractionPointStateStartField = AccessTools.Field(typeof(ExtractionPoint), "stateStart");

		private static readonly FieldInfo? ItemAttributesItemField = AccessTools.Field(typeof(ItemAttributes), "item");

		private static readonly FieldInfo? ItemAttributesItemNameField = AccessTools.Field(typeof(ItemAttributes), "itemName");

		private static readonly FieldInfo? ItemAttributesPhotonViewField = AccessTools.Field(typeof(ItemAttributes), "photonView");

		private static readonly FieldInfo? ItemAttributesShopItemField = AccessTools.Field(typeof(ItemAttributes), "shopItem");

		private static readonly FieldInfo? ItemAttributesValueField = AccessTools.Field(typeof(ItemAttributes), "value");

		private static readonly FieldInfo? ItemItemNameField = AccessTools.Field(typeof(Item), "itemName");

		private static readonly MethodInfo? EnemyDisableChaseMethod = AccessTools.Method(typeof(Enemy), "DisableChase", new Type[1] { typeof(float) }, (Type[])null);

		private static readonly MethodInfo? EnemyFreezeMethod = AccessTools.Method(typeof(Enemy), "Freeze", new Type[1] { typeof(float) }, (Type[])null);

		private static readonly MethodInfo? EnemyVisionDisableVisionMethod = AccessTools.Method(typeof(EnemyVision), "DisableVision", new Type[1] { typeof(float) }, (Type[])null);

		private static readonly MethodInfo? PhysGrabCartCartMassOverrideMethod = AccessTools.Method(typeof(PhysGrabCart), "CartMassOverride", new Type[1] { typeof(float) }, (Type[])null);

		private static readonly FieldInfo? PhysGrabCartCartActiveField = AccessTools.Field(typeof(PhysGrabCart), "cartActive");

		private static readonly FieldInfo? PhysGrabCartHaulCurrentField = AccessTools.Field(typeof(PhysGrabCart), "haulCurrent");

		private static readonly FieldInfo? PhysGrabCartRigidbodyField = AccessTools.Field(typeof(PhysGrabCart), "rb");

		private static readonly MethodInfo? PhysGrabCartStateSwitchRpcMethod = AccessTools.Method(typeof(PhysGrabCart), "StateSwitchRPC", new Type[1] { typeof(State) }, (Type[])null);

		private static readonly FieldInfo? PhysGrabObjectMassOriginalField = AccessTools.Field(typeof(PhysGrabObject), "massOriginal");

		private static readonly FieldInfo? PhysGrabberInstanceField = AccessTools.Field(typeof(PhysGrabber), "instance");

		private static readonly FieldInfo? PhysGrabberCurrentlyLookingAtItemAttributesField = AccessTools.Field(typeof(PhysGrabber), "currentlyLookingAtItemAttributes");

		private static readonly FieldInfo? PhysGrabberCurrentlyLookingAtPhysGrabObjectField = AccessTools.Field(typeof(PhysGrabber), "currentlyLookingAtPhysGrabObject");

		private static readonly FieldInfo? PhysGrabberPlayerCameraField = AccessTools.Field(typeof(PhysGrabber), "playerCamera");

		private static readonly FieldInfo? PunManagerInstanceField = AccessTools.Field(typeof(PunManager), "instance");

		private static readonly FieldInfo? PunManagerPhotonViewField = AccessTools.Field(typeof(PunManager), "photonView");

		private static readonly FieldInfo? RunManagerInstanceField = AccessTools.Field(typeof(RunManager), "instance");

		private static readonly FieldInfo? RunManagerLevelCurrentField = AccessTools.Field(typeof(RunManager), "levelCurrent");

		private static readonly FieldInfo? ValuableDollarValueCurrentField = AccessTools.Field(typeof(ValuableObject), "dollarValueCurrent");

		private static readonly FieldInfo? ValuableDollarValueOriginalField = AccessTools.Field(typeof(ValuableObject), "dollarValueOriginal");

		private static readonly FieldInfo? ValuableDollarValueSetField = AccessTools.Field(typeof(ValuableObject), "dollarValueSet");

		private static readonly FieldInfo? ValuablePhotonViewField = AccessTools.Field(typeof(ValuableObject), "photonView");

		private static readonly FieldInfo? ValuablePhysGrabObjectField = AccessTools.Field(typeof(ValuableObject), "physGrabObject");

		private static readonly FieldInfo? ValuableRbField = AccessTools.Field(typeof(ValuableObject), "rb");

		private static readonly FieldInfo? ValuableRigidBodyMassField = AccessTools.Field(typeof(ValuableObject), "rigidBodyMass");

		internal static CurrencyUI? GetCurrencyUiInstance()
		{
			return GetStaticReference<CurrencyUI>(CurrencyUiInstanceField);
		}

		internal static Enemy? GetEnemy(EnemyStateChaseBegin enemyStateChaseBegin)
		{
			return GetReferenceField<Enemy>(EnemyStateChaseBeginEnemyField, enemyStateChaseBegin);
		}

		internal static Enemy? GetEnemy(EnemyStateChase enemyStateChase)
		{
			return GetReferenceField<Enemy>(EnemyStateChaseEnemyField, enemyStateChase);
		}

		internal static Enemy? GetEnemy(EnemyVision enemyVision)
		{
			return GetReferenceField<Enemy>(EnemyVisionEnemyField, enemyVision);
		}

		internal static EnemyState GetEnemyCurrentState(Enemy enemy)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			return GetValueField<EnemyState>(EnemyCurrentStateField, enemy, (EnemyState)0);
		}

		internal static bool GetEnemyHasVision(Enemy enemy)
		{
			return GetValueField(EnemyHasVisionField, enemy, fallback: false);
		}

		internal static bool GetEnemyMasterClient(Enemy enemy)
		{
			return GetValueField(EnemyMasterClientField, enemy, fallback: false);
		}

		internal static EnemyParent? GetEnemyParent(Enemy enemy)
		{
			return GetReferenceField<EnemyParent>(EnemyParentField, enemy);
		}

		internal static Enemy? GetEnemy(EnemyParent enemyParent)
		{
			return GetReferenceField<Enemy>(EnemyParentEnemyField, enemyParent);
		}

		internal static string GetEnemyParentEnemyName(EnemyParent enemyParent)
		{
			return GetValueField(EnemyParentEnemyNameField, enemyParent, string.Empty);
		}

		internal static Enemy? GetEnemy(EnemyRigidbody enemyRigidbody)
		{
			return GetReferenceField<Enemy>(EnemyRigidbodyEnemyField, enemyRigidbody);
		}

		internal static EnemyParent? GetEnemyParent(EnemyRigidbody enemyRigidbody)
		{
			return GetReferenceField<EnemyParent>(EnemyRigidbodyEnemyParentField, enemyRigidbody);
		}

		internal static EnemyVision? GetEnemyVision(Enemy enemy)
		{
			return GetReferenceField<EnemyVision>(EnemyVisionField, enemy);
		}

		internal static void InvokeEnemyDisableChase(Enemy enemy, float duration)
		{
			InvokeMethod(EnemyDisableChaseMethod, enemy, duration);
		}

		internal static void InvokeEnemyFreeze(Enemy enemy, float duration)
		{
			InvokeMethod(EnemyFreezeMethod, enemy, duration);
		}

		internal static void InvokeEnemyVisionDisableVision(EnemyVision enemyVision, float duration)
		{
			InvokeMethod(EnemyVisionDisableVisionMethod, enemyVision, duration);
		}

		internal static int GetExtractionPointExtractionHaul(ExtractionPoint extractionPoint)
		{
			return GetValueField(ExtractionPointExtractionHaulField, extractionPoint, 0);
		}

		internal static float GetExtractionPointHaulCurrent(ExtractionPoint extractionPoint)
		{
			return GetValueField(ExtractionPointHaulCurrentField, extractionPoint, 0f);
		}

		internal static bool GetExtractionPointIsShop(ExtractionPoint extractionPoint)
		{
			return GetValueField(ExtractionPointIsShopField, extractionPoint, fallback: false);
		}

		internal static bool GetExtractionPointStateStart(ExtractionPoint extractionPoint)
		{
			return GetValueField(ExtractionPointStateStartField, extractionPoint, fallback: false);
		}

		internal static Item? GetItemAttributesItem(ItemAttributes itemAttributes)
		{
			return GetReferenceField<Item>(ItemAttributesItemField, itemAttributes);
		}

		internal static string GetItemAttributesItemName(ItemAttributes itemAttributes)
		{
			return GetValueField(ItemAttributesItemNameField, itemAttributes, string.Empty);
		}

		internal static PhotonView? GetItemAttributesPhotonView(ItemAttributes itemAttributes)
		{
			return GetReferenceField<PhotonView>(ItemAttributesPhotonViewField, itemAttributes);
		}

		internal static bool GetItemAttributesShopItem(ItemAttributes itemAttributes)
		{
			return GetValueField(ItemAttributesShopItemField, itemAttributes, fallback: false);
		}

		internal static int GetItemAttributesValue(ItemAttributes itemAttributes)
		{
			return GetValueField(ItemAttributesValueField, itemAttributes, 0);
		}

		internal static string GetItemItemName(Item item)
		{
			return GetValueField(ItemItemNameField, item, string.Empty);
		}

		internal static bool GetPhysGrabCartCartActive(PhysGrabCart physGrabCart)
		{
			return GetValueField(PhysGrabCartCartActiveField, physGrabCart, fallback: false);
		}

		internal static int GetPhysGrabCartHaulCurrent(PhysGrabCart physGrabCart)
		{
			return GetValueField(PhysGrabCartHaulCurrentField, physGrabCart, 0);
		}

		internal static Rigidbody? GetPhysGrabCartRigidbody(PhysGrabCart physGrabCart)
		{
			return GetReferenceField<Rigidbody>(PhysGrabCartRigidbodyField, physGrabCart);
		}

		internal static void InvokePhysGrabCartCartMassOverride(PhysGrabCart physGrabCart, float targetMass)
		{
			InvokeMethod(PhysGrabCartCartMassOverrideMethod, physGrabCart, targetMass);
		}

		internal static void InvokePhysGrabCartStateSwitchRpc(PhysGrabCart physGrabCart, State state)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			InvokeMethod(PhysGrabCartStateSwitchRpcMethod, physGrabCart, state);
		}

		internal static PhysGrabber? GetPhysGrabberInstance()
		{
			return GetStaticReference<PhysGrabber>(PhysGrabberInstanceField);
		}

		internal static ItemAttributes? GetPhysGrabberCurrentlyLookingAtItemAttributes(PhysGrabber physGrabber)
		{
			return GetReferenceField<ItemAttributes>(PhysGrabberCurrentlyLookingAtItemAttributesField, physGrabber);
		}

		internal static PhysGrabObject? GetPhysGrabberCurrentlyLookingAtPhysGrabObject(PhysGrabber physGrabber)
		{
			return GetReferenceField<PhysGrabObject>(PhysGrabberCurrentlyLookingAtPhysGrabObjectField, physGrabber);
		}

		internal static PunManager? GetPunManagerInstance()
		{
			return GetStaticReference<PunManager>(PunManagerInstanceField);
		}

		internal static PhotonView? GetPunManagerPhotonView(PunManager punManager)
		{
			return GetReferenceField<PhotonView>(PunManagerPhotonViewField, punManager);
		}

		internal static RunManager? GetRunManagerInstance()
		{
			return GetStaticReference<RunManager>(RunManagerInstanceField);
		}

		internal static Level? GetRunManagerLevelCurrent(RunManager runManager)
		{
			return GetReferenceField<Level>(RunManagerLevelCurrentField, runManager);
		}

		internal static float GetValuableDollarValueCurrent(ValuableObject valuableObject)
		{
			return GetValueField(ValuableDollarValueCurrentField, valuableObject, 0f);
		}

		internal static float GetValuableDollarValueOriginal(ValuableObject valuableObject)
		{
			return GetValueField(ValuableDollarValueOriginalField, valuableObject, 0f);
		}

		internal static PhotonView? GetValuablePhotonView(ValuableObject valuableObject)
		{
			return GetReferenceField<PhotonView>(ValuablePhotonViewField, valuableObject);
		}

		internal static PhysGrabObject? GetValuablePhysGrabObject(ValuableObject valuableObject)
		{
			return GetReferenceField<PhysGrabObject>(ValuablePhysGrabObjectField, valuableObject);
		}

		internal static Rigidbody? GetValuableRigidbody(ValuableObject valuableObject)
		{
			return GetReferenceField<Rigidbody>(ValuableRbField, valuableObject);
		}

		internal static float GetValuableRigidBodyMass(ValuableObject valuableObject)
		{
			return GetValueField(ValuableRigidBodyMassField, valuableObject, 0f);
		}

		internal static void SetEnemyCurrentState(Enemy enemy, EnemyState state)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			SetField<EnemyState>(EnemyCurrentStateField, enemy, state);
		}

		internal static void SetEnemyTargetPlayerAvatar(Enemy enemy, PlayerAvatar? playerAvatar)
		{
			SetField<PlayerAvatar>(EnemyTargetPlayerAvatarField, enemy, playerAvatar);
		}

		internal static void SetEnemyTargetPlayerViewId(Enemy enemy, int viewId)
		{
			SetField(EnemyTargetPlayerViewIdField, enemy, viewId);
		}

		internal static void SetExtractionPointExtractionHaul(ExtractionPoint extractionPoint, int value)
		{
			SetField(ExtractionPointExtractionHaulField, extractionPoint, value);
		}

		internal static void SetItemAttributesValue(ItemAttributes itemAttributes, int value)
		{
			SetField(ItemAttributesValueField, itemAttributes, value);
		}

		internal static void SetPhysGrabCartCartActive(PhysGrabCart physGrabCart, bool value)
		{
			SetField(PhysGrabCartCartActiveField, physGrabCart, value);
		}

		internal static void SetPhysGrabObjectMassOriginal(PhysGrabObject physGrabObject, float massOriginal)
		{
			SetField(PhysGrabObjectMassOriginalField, physGrabObject, massOriginal);
		}

		internal static void SetValuableDollarValueCurrent(ValuableObject valuableObject, float value)
		{
			SetField(ValuableDollarValueCurrentField, valuableObject, value);
		}

		internal static void SetValuableDollarValueOriginal(ValuableObject valuableObject, float value)
		{
			SetField(ValuableDollarValueOriginalField, valuableObject, value);
		}

		internal static void SetValuableDollarValueSet(ValuableObject valuableObject, bool value)
		{
			SetField(ValuableDollarValueSetField, valuableObject, value);
		}

		internal static void SetValuableRigidBodyMass(ValuableObject valuableObject, float value)
		{
			SetField(ValuableRigidBodyMassField, valuableObject, value);
		}

		internal static Camera? TryGetFocusCamera()
		{
			PhysGrabber physGrabberInstance = GetPhysGrabberInstance();
			return (((Object)(object)physGrabberInstance != (Object)null) ? GetReferenceField<Camera>(PhysGrabberPlayerCameraField, physGrabberInstance) : null) ?? SemiFunc.MainCamera();
		}

		private static T? GetReferenceField<T>(FieldInfo? fieldInfo, object instance) where T : class
		{
			return fieldInfo?.GetValue(instance) as T;
		}

		private static T? GetStaticReference<T>(FieldInfo? fieldInfo) where T : class
		{
			return fieldInfo?.GetValue(null) as T;
		}

		private static TValue GetValueField<TValue>(FieldInfo? fieldInfo, object instance, TValue fallback)
		{
			if (fieldInfo == null)
			{
				return fallback;
			}
			object value = fieldInfo.GetValue(instance);
			if (value is TValue)
			{
				return (TValue)value;
			}
			return fallback;
		}

		private static void SetField<TValue>(FieldInfo? fieldInfo, object instance, TValue value)
		{
			fieldInfo?.SetValue(instance, value);
		}

		private static void InvokeMethod(MethodInfo? methodInfo, object instance, params object[] args)
		{
			methodInfo?.Invoke(instance, args);
		}
	}
	[HarmonyPatch]
	internal static class HackItPatches
	{
		[HarmonyPatch(typeof(ValuableObject), "DollarValueSetLogic")]
		[HarmonyPostfix]
		private static void ValuableObject_DollarValueSetLogic_Postfix(ValuableObject __instance)
		{
			HackItRuntime.Instance?.ApplyPersistentValuableHack(__instance);
		}

		[HarmonyPatch(typeof(ValuableObject), "DollarValueSetRPC")]
		[HarmonyPostfix]
		private static void ValuableObject_DollarValueSetRPC_Postfix(ValuableObject __instance)
		{
			HackItRuntime.Instance?.ApplyPersistentValuableHack(__instance);
		}

		[HarmonyPatch(typeof(ItemAttributes), "GetValue")]
		[HarmonyPostfix]
		private static void ItemAttributes_GetValue_Postfix(ItemAttributes __instance)
		{
			HackItRuntime.Instance?.ApplyPersistentShopHack(__instance);
		}

		[HarmonyPatch(typeof(ItemAttributes), "GetValueRPC")]
		[HarmonyPostfix]
		private static void ItemAttributes_GetValueRPC_Postfix(ItemAttributes __instance)
		{
			HackItRuntime.Instance?.ApplyPersistentShopHack(__instance);
		}

		[HarmonyPatch(typeof(ExtractionPoint), "StateComplete")]
		[HarmonyPrefix]
		private static void ExtractionPoint_StateComplete_Prefix(ExtractionPoint __instance, out bool __state)
		{
			__state = HackItAccess.GetExtractionPointStateStart(__instance);
		}

		[HarmonyPatch(typeof(ExtractionPoint), "StateComplete")]
		[HarmonyPostfix]
		private static void ExtractionPoint_StateComplete_Postfix(ExtractionPoint __instance, bool __state)
		{
			HackItRuntime.Instance?.ApplyExtractorCompletionBonus(__instance, __state);
		}

		[HarmonyPatch(typeof(ExtractionPoint), "StateTaxReturn")]
		[HarmonyPrefix]
		private static void ExtractionPoint_StateTaxReturn_Prefix(ExtractionPoint __instance, out bool __state)
		{
			__state = HackItAccess.GetExtractionPointStateStart(__instance);
		}

		[HarmonyPatch(typeof(ExtractionPoint), "StateTaxReturn")]
		[HarmonyPostfix]
		private static void ExtractionPoint_StateTaxReturn_Postfix(ExtractionPoint __instance, bool __state)
		{
			HackItRuntime.Instance?.ApplyExtractorCompletionBonus(__instance, __state);
		}

		[HarmonyPatch(typeof(Enemy), "SetChaseTarget")]
		[HarmonyPrefix]
		private static bool Enemy_SetChaseTarget_Prefix(Enemy __instance)
		{
			return HackItRuntime.Instance?.AllowEnemyTargeting(__instance) ?? true;
		}

		[HarmonyPatch(typeof(EnemyStateChaseBegin), "Update")]
		[HarmonyPrefix]
		private static bool EnemyStateChaseBegin_Update_Prefix(EnemyStateChaseBegin __instance)
		{
			Enemy enemy = HackItAccess.GetEnemy(__instance);
			if (!((Object)(object)enemy == (Object)null))
			{
				return HackItRuntime.Instance?.AllowEnemyState(enemy) ?? true;
			}
			return true;
		}

		[HarmonyPatch(typeof(EnemyStateChase), "Update")]
		[HarmonyPrefix]
		private static bool EnemyStateChase_Update_Prefix(EnemyStateChase __instance)
		{
			Enemy enemy = HackItAccess.GetEnemy(__instance);
			if (!((Object)(object)enemy == (Object)null))
			{
				return HackItRuntime.Instance?.AllowEnemyState(enemy) ?? true;
			}
			return true;
		}

		[HarmonyPatch(typeof(EnemyVision), "VisionTrigger")]
		[HarmonyPrefix]
		private static bool EnemyVision_VisionTrigger_Prefix(EnemyVision __instance)
		{
			Enemy enemy = HackItAccess.GetEnemy(__instance);
			if (!((Object)(object)enemy == (Object)null))
			{
				return HackItRuntime.Instance?.AllowEnemyVision(enemy) ?? true;
			}
			return true;
		}

		[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "BreakRPC")]
		[HarmonyPostfix]
		private static void PhysGrabObjectImpactDetector_BreakRPC_Postfix(PhysGrabObjectImpactDetector __instance)
		{
			ValuableObject component = ((Component)__instance).GetComponent<ValuableObject>();
			if ((Object)(object)component != (Object)null)
			{
				HackItRuntime.Instance?.SyncValuableCurrentValue(component);
			}
		}

		[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "HealRPC")]
		[HarmonyPostfix]
		private static void PhysGrabObjectImpactDetector_HealRPC_Postfix(PhysGrabObjectImpactDetector __instance)
		{
			ValuableObject component = ((Component)__instance).GetComponent<ValuableObject>();
			if ((Object)(object)component != (Object)null)
			{
				HackItRuntime.Instance?.SyncValuableCurrentValue(component);
			}
		}

		[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "ResetObject")]
		[HarmonyPostfix]
		private static void PhysGrabObjectImpactDetector_ResetObject_Postfix(PhysGrabObjectImpactDetector __instance)
		{
			ValuableObject component = ((Component)__instance).GetComponent<ValuableObject>();
			if ((Object)(object)component != (Object)null)
			{
				HackItRuntime.Instance?.SyncValuableCurrentValue(component);
			}
		}
	}
	internal sealed class HackItRuntime : MonoBehaviour
	{
		private readonly struct HackActionDefinition
		{
			internal readonly HackItActionKind Kind;

			internal readonly string Label;

			internal readonly float Primary;

			internal readonly float Secondary;

			internal readonly float Duration;

			internal HackActionDefinition(HackItActionKind kind, string label, float primary, float secondary, float duration)
			{
				Kind = kind;
				Label = label;
				Primary = primary;
				Secondary = secondary;
				Duration = duration;
			}
		}

		private readonly struct HackFocus
		{
			internal static readonly HackFocus None = new HackFocus(HackItTargetKind.None, 0, "None", string.Empty, string.Empty);

			internal readonly HackItTargetKind Kind;

			internal readonly int ViewId;

			internal readonly string Title;

			internal readonly string Subtitle;

			internal readonly string Status;

			internal HackFocus(HackItTargetKind kind, int viewId, string title, string subtitle, string status)
			{
				Kind = kind;
				ViewId = viewId;
				Title = title;
				Subtitle = subtitle;
				Status = status;
			}
		}

		private const float HackDurationSeconds = 5f;

		private const float HackSuccessChance = 0.5f;

		private const float RuntimeRetryBackoffSeconds = 3f;

		private const string RoomSnapshotKey = "empress.hackit.snapshot";

		private static readonly HackActionDefinition[] ValuableActions = new HackActionDefinition[3]
		{
			new HackActionDefinition(HackItActionKind.Boost, "Boost Value", 2f, 0.8f, 0f),
			new HackActionDefinition(HackItActionKind.Jackpot, "Jackpot", 4f, 0.65f, 0f),
			new HackActionDefinition(HackItActionKind.Feather, "Feather", 1.35f, 0.35f, 0f)
		};

		private static readonly HackActionDefinition[] ShopActions = new HackActionDefinition[3]
		{
			new HackActionDefinition(HackItActionKind.Discount, "Discount 50%", 0.5f, 1f, 0f),
			new HackActionDefinition(HackItActionKind.Free, "Almost Free", 0.05f, 1f, 0f),
			new HackActionDefinition(HackItActionKind.Markup, "Markup x2", 2f, 1f, 0f)
		};

		private static readonly HackActionDefinition[] ExtractorActions = new HackActionDefinition[3]
		{
			new HackActionDefinition(HackItActionKind.Bonus, "Payout x1.5", 1.5f, 1f, 0f),
			new HackActionDefinition(HackItActionKind.MegaBonus, "Payout x2", 2f, 1f, 0f),
			new HackActionDefinition(HackItActionKind.Overdrive, "Payout x3", 3f, 1f, 0f)
		};

		private static readonly HackActionDefinition[] EnemyActions = new HackActionDefinition[2]
		{
			new HackActionDefinition(HackItActionKind.Pacify, "Pacify 45s", 1f, 1f, 45f),
			new HackActionDefinition(HackItActionKind.Freeze, "Freeze 12s", 12f, 1f, 12f)
		};

		private static readonly HackActionDefinition[] CartActions = new HackActionDefinition[2]
		{
			new HackActionDefinition(HackItActionKind.FeatherCart, "Feather Pull 60s", 2f, 1f, 60f),
			new HackActionDefinition(HackItActionKind.HandleCart, "Handle Lock 60s", 4f, 1f, 60f)
		};

		private readonly Dictionary<int, HackItHackState> _states = new Dictionary<int, HackItHackState>();

		private readonly Dictionary<string, HackItHackState> _resolvedUiStates = new Dictionary<string, HackItHackState>(StringComparer.OrdinalIgnoreCase);

		private readonly Dictionary<int, float> _valuableBaseValues = new Dictionary<int, float>();

		private readonly Dictionary<int, float> _valuableBaseMasses = new Dictionary<int, float>();

		private readonly Dictionary<int, float> _lastBroadcastValuableValues = new Dictionary<int, float>();

		private readonly Dictionary<int, int> _lastBroadcastShopValues = new Dictionary<int, int>();

		private readonly Dictionary<int, int> _shopBaseValues = new Dictionary<int, int>();

		private readonly Dictionary<int, float> _cartBaseMasses = new Dictionary<int, float>();

		private readonly HashSet<int> _restoredCartStates = new HashSet<int>();

		private HackItRpcRelay? _relay;

		private HackFocus _focus = HackFocus.None;

		private bool _popupVisible = true;

		private float _nextRefreshTime;

		private float _nextSnapshotPollTime;

		private float _requestCooldownUntil;

		private float _feedbackUntil;

		private float _effectRetryBlockedUntil;

		private float _focusRetryBlockedUntil;

		private float _previewHackStartedTime;

		private float _previewHackResolveTime;

		private string _feedbackMessage = string.Empty;

		private string _lastSnapshotPayload = string.Empty;

		private string _focusDebugMessage = "Booting focus scanner...";

		private string _previewHackTargetName = string.Empty;

		private string _roomIdentity = string.Empty;

		private string _levelIdentity = string.Empty;

		private int _snapshotRevision;

		private int _previewHackViewId;

		private GUIStyle? _panelStyle;

		private GUIStyle? _titleStyle;

		private GUIStyle? _bodyStyle;

		private GUIStyle? _mutedStyle;

		private GUIStyle? _accentStyle;

		internal static HackItRuntime? Instance { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance != (Object)null && Instance != this)
			{
				Object.Destroy((Object)(object)this);
				return;
			}
			Instance = this;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			HackItPlugin.LogProxy.Info("HackIt runtime host ready.");
		}

		private void Update()
		{
			if (!HackItPlugin.Enabled.Value)
			{
				return;
			}
			EnsureRelay();
			HandleSessionIdentity();
			PullRoomSnapshot();
			CleanupExpiredStates();
			if (Time.unscaledTime >= _effectRetryBlockedUntil)
			{
				try
				{
					RefreshStateEffects();
				}
				catch (Exception arg)
				{
					_effectRetryBlockedUntil = Time.unscaledTime + 3f;
					_feedbackMessage = "Hack effects paused after a runtime access failure.";
					_feedbackUntil = Time.unscaledTime + 3f;
					HackItPlugin.LogProxy.Error($"HackIt effect refresh failed. Backing off for {3f:0} seconds. {arg}");
				}
			}
			if (!CanResolveFocus())
			{
				_focus = HackFocus.None;
				return;
			}
			HandleInput();
			if (Time.unscaledTime < _focusRetryBlockedUntil)
			{
				_focus = HackFocus.None;
				return;
			}
			try
			{
				_focus = ResolveFocus();
			}
			catch (Exception arg2)
			{
				_focus = HackFocus.None;
				_focusRetryBlockedUntil = Time.unscaledTime + 3f;
				_focusDebugMessage = "Focus scanner paused after a target access failure.";
				HackItPlugin.LogProxy.Error($"HackIt focus scan failed. Backing off for {3f:0} seconds. {arg2}");
			}
		}

		private void OnGUI()
		{
			if (HackItPlugin.Enabled.Value && _popupVisible && CanResolveFocus())
			{
				EnsureGuiStyles();
				DrawPopup();
			}
		}

		internal void ApplyPersistentValuableHack(ValuableObject valuableObject)
		{
			int viewId = GetViewId((Component)(object)valuableObject);
			float networkClock = GetNetworkClock();
			if (viewId != 0 && _states.TryGetValue(viewId, out HackItHackState value) && value.TargetKind == HackItTargetKind.Valuable && value.HasActiveEffect(networkClock))
			{
				ApplyValuableHack(valuableObject, value);
			}
		}

		internal void ApplyPersistentShopHack(ItemAttributes itemAttributes)
		{
			int viewId = GetViewId((Component)(object)itemAttributes);
			float networkClock = GetNetworkClock();
			if (viewId != 0 && _states.TryGetValue(viewId, out HackItHackState value) && value.TargetKind == HackItTargetKind.ShopItem && value.HasActiveEffect(networkClock))
			{
				ApplyShopHack(itemAttributes, value);
			}
		}

		internal void ApplyExtractorCompletionBonus(ExtractionPoint extractionPoint, bool enteringState)
		{
			if (!enteringState || HackItAccess.GetExtractionPointIsShop(extractionPoint))
			{
				return;
			}
			int viewId = GetViewId((Component)(object)extractionPoint);
			if (viewId == 0 || !_states.TryGetValue(viewId, out HackItHackState value) || value.TargetKind != HackItTargetKind.Extractor || !value.resolved)
			{
				return;
			}
			int extractionPointExtractionHaul = HackItAccess.GetExtractionPointExtractionHaul(extractionPoint);
			if (extractionPointExtractionHaul > 0)
			{
				int num = Mathf.Max(1, Mathf.RoundToInt((float)extractionPointExtractionHaul * Mathf.Max(0.05f, value.primaryValue)));
				int num2 = num - extractionPointExtractionHaul;
				HackItAccess.SetExtractionPointExtractionHaul(extractionPoint, num);
				SemiFunc.StatSetRunCurrency(SemiFunc.StatGetRunCurrency() + num2);
				SemiFunc.StatSetRunTotalHaul(SemiFunc.StatGetRunTotalHaul() + num2);
				CurrencyUI currencyUiInstance = HackItAccess.GetCurrencyUiInstance();
				if ((Object)(object)currencyUiInstance != (Object)null)
				{
					currencyUiInstance.FetchCurrency();
				}
			}
		}

		internal bool AllowEnemyTargeting(Enemy enemy)
		{
			if (!IsEnemyPacified(enemy))
			{
				return true;
			}
			PacifyEnemy(enemy);
			return false;
		}

		internal bool AllowEnemyState(Enemy enemy)
		{
			if (!IsEnemyPacified(enemy))
			{
				return true;
			}
			PacifyEnemy(enemy);
			return false;
		}

		internal bool AllowEnemyVision(Enemy enemy)
		{
			if (!IsEnemyPacified(enemy))
			{
				return true;
			}
			PacifyEnemy(enemy);
			return false;
		}

		internal void ReceiveRemoteRequest(int viewId, string targetKindValue, string actionKindValue, PhotonMessageInfo info)
		{
			//IL_002d: 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_0063: 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_0056: 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_008c: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			if ((SemiFunc.IsMultiplayer() && !PhotonNetwork.IsMasterClient) || !Enum.TryParse<HackItTargetKind>(targetKindValue, ignoreCase: true, out var result) || !Enum.TryParse<HackItActionKind>(actionKindValue, ignoreCase: true, out var result2))
			{
				return;
			}
			if (SemiFunc.IsMultiplayer() && info.Sender != null && info.Sender != PhotonNetwork.MasterClient && !HackItPlugin.AllowClientRequests.Value)
			{
				SendPrivateNotice(info, "Empress locked HackIt to the host.");
				return;
			}
			string actorName = ((info.Sender != null) ? info.Sender.NickName : "Host");
			int actorNumber = ((info.Sender != null) ? info.Sender.ActorNumber : 0);
			if (!TryStartHack(viewId, result, result2, actorNumber, actorName, out string notice))
			{
				SendSnapshotTo(info.Sender);
				SendPrivateNotice(info, notice);
			}
			else
			{
				BroadcastNotice(notice);
			}
		}

		internal void ReceiveNotice(string message)
		{
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			TryApplyResolvedNotice(message);
			TryStoreResolvedUiStateFromNotice(message);
			if (_focus.Kind != 0 && (message.Contains(" hacked ", StringComparison.OrdinalIgnoreCase) || message.Contains(" failed hacking ", StringComparison.OrdinalIgnoreCase)) && (!_states.TryGetValue(_focus.ViewId, out HackItHackState value) || !value.resolved))
			{
				ApplySpentFallbackForFocus();
			}
			if (_previewHackViewId != 0 && (message.Contains("hacked ", StringComparison.OrdinalIgnoreCase) || message.Contains("failed hacking", StringComparison.OrdinalIgnoreCase)))
			{
				ClearPreviewHack();
			}
			_feedbackMessage = message;
			_feedbackUntil = Time.unscaledTime + 3f;
			SemiFunc.UIFocusText(message, new Color(0.98f, 0.82f, 0.4f), Color.white, 2.2f);
		}

		internal void ReceivePrivateNotice(string message)
		{
			//IL_010b: 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)
			if (message.Contains("already been hacked", StringComparison.OrdinalIgnoreCase) && _focus.Kind != 0)
			{
				ApplySpentFallbackForFocus();
			}
			if (_previewHackViewId != 0 && _states.TryGetValue(_previewHackViewId, out HackItHackState value) && !value.resolved && value.claimantActorNumber == GetLocalActorNumber() && (message.Contains("already", StringComparison.OrdinalIgnoreCase) || message.Contains("slipped", StringComparison.OrdinalIgnoreCase) || message.Contains("locked", StringComparison.OrdinalIgnoreCase) || message.Contains("invalid", StringComparison.OrdinalIgnoreCase)))
			{
				_states.Remove(_previewHackViewId);
			}
			if (_previewHackViewId != 0 && (message.Contains("already", StringComparison.OrdinalIgnoreCase) || message.Contains("slipped", StringComparison.OrdinalIgnoreCase) || message.Contains("locked", StringComparison.OrdinalIgnoreCase) || message.Contains("invalid", StringComparison.OrdinalIgnoreCase)))
			{
				ClearPreviewHack();
			}
			_feedbackMessage = message;
			_feedbackUntil = Time.unscaledTime + 3f;
			SemiFunc.UIFocusText(message, new Color(0.94f, 0.54f, 0.4f), Color.white, 2.2f);
		}

		private void TryApplyResolvedNotice(string message)
		{
			if (_previewHackViewId == 0 || !_states.TryGetValue(_previewHackViewId, out HackItHackState value) || value.claimantActorNumber != GetLocalActorNumber() || value.resolved)
			{
				return;
			}
			bool success;
			int num;
			if (message.Contains(" failed hacking ", StringComparison.OrdinalIgnoreCase))
			{
				success = false;
				num = message.LastIndexOf(':');
			}
			else
			{
				if (!message.Contains(" hacked ", StringComparison.OrdinalIgnoreCase))
				{
					return;
				}
				success = true;
				num = message.LastIndexOf(':');
			}
			string label = value.label;
			if (num >= 0 && num + 1 < message.Length)
			{
				int num2 = num + 1;
				label = message.Substring(num2, message.Length - num2).Trim().TrimEnd('.');
			}
			float networkClock = GetNetworkClock();
			HackItHackState hackItHackState = BuildResolvedState(value, success, networkClock);
			hackItHackState.label = label;
			_states[_previewHackViewId] = hackItHackState;
			StoreResolvedUiState(hackItHackState);
		}

		private void TryStoreResolvedUiStateFromNotice(string message)
		{
			bool succeeded;
			string text;
			if (message.Contains(" failed hacking ", StringComparison.OrdinalIgnoreCase))
			{
				succeeded = false;
				text = " failed hacking ";
			}
			else
			{
				if (!message.Contains(" hacked ", StringComparison.OrdinalIgnoreCase))
				{
					return;
				}
				succeeded = true;
				text = " hacked ";
			}
			int num = message.IndexOf(text, StringComparison.OrdinalIgnoreCase);
			int num2 = message.LastIndexOf(':');
			if (num >= 0 && num2 > num + text.Length)
			{
				int num3 = num + text.Length;
				string text2 = message.Substring(num3, num2 - num3).Trim();
				if (!string.IsNullOrWhiteSpace(text2))
				{
					num3 = num2 + 1;
					string text3 = message.Substring(num3, message.Length - num3).Trim().TrimEnd('.');
					HackItTargetKind hackItTargetKind = ((_focus.Kind != 0 && string.Equals(_focus.Title, text2, StringComparison.OrdinalIgnoreCase)) ? _focus.Kind : HackItTargetKind.None);
					HackItHackState state = new HackItHackState
					{
						viewId = 0,
						targetKind = hackItTargetKind.ToString(),
						actionKind = HackItActionKind.None.ToString(),
						targetName = text2,
						label = (string.IsNullOrWhiteSpace(text3) ? "Spent" : text3),
						claimantActorNumber = 0,
						claimantName = string.Empty,
						resolved = true,
						succeeded = succeeded,
						persistentEffect = true,
						effectExpiryTime = 0f
					};
					StoreResolvedUiState(state);
				}
			}
		}

		private void ApplySpentFallbackForFocus()
		{
			if (_focus.Kind != 0 && _focus.ViewId != 0 && (!_states.TryGetValue(_focus.ViewId, out HackItHackState value) || !value.resolved))
			{
				HackActionDefinition[] actions = GetActions(_focus.Kind);
				HackActionDefinition definition = ((actions.Length != 0) ? actions[0] : new HackActionDefinition(HackItActionKind.None, "Spent", 1f, 1f, 0f));
				HackItHackState hackItHackState = BuildPendingState(_focus.ViewId, _focus.Kind, definition, 0, "Host", _focus.Title, GetNetworkClock());
				hackItHackState.resolved = true;
				hackItHackState.succeeded = false;
				hackItHackState.persistentEffect = true;
				hackItHackState.effectExpiryTime = 0f;
				hackItHackState.label = "Spent";
				_states[_focus.ViewId] = hackItHackState;
				StoreResolvedUiState(hackItHackState);
			}
		}

		internal void ReceiveSnapshotPayload(string payload)
		{
			ApplySnapshotPayload(payload);
			_nextRefreshTime = 0f;
		}

		internal void SyncValuableCurrentValue(ValuableObject valuableObject)
		{
			int viewId = GetViewId((Component)(object)valuableObject);
			if (viewId == 0)
			{
				return;
			}
			float valuableDollarValueCurrent = HackItAccess.GetValuableDollarValueCurrent(valuableObject);
			if (!SemiFunc.IsMultiplayer() || !SemiFunc.IsMasterClient())
			{
				ReceiveValuableCurrentValue(viewId, valuableDollarValueCurrent);
				return;
			}
			PunManager punManagerInstance = HackItAccess.GetPunManagerInstance();
			PhotonView val = (((Object)(object)punManagerInstance != (Object)null) ? HackItAccess.GetPunManagerPhotonView(punManagerInstance) : null);
			if (!((Object)(object)_relay == (Object)null) && !((Object)(object)val == (Object)null))
			{
				val.RPC("EmpressHack_ValuableCurrentRPC", (RpcTarget)1, new object[2] { viewId, valuableDollarValueCurrent });
			}
		}

		internal void ReceiveValuableCurrentValue(int viewId, float currentValue)
		{
			ValuableObject val = FindComponentByViewId<ValuableObject>(viewId);
			if (!((Object)(object)val == (Object)null))
			{
				float value = Mathf.Clamp(currentValue, 0f, HackItAccess.GetValuableDollarValueOriginal(val));
				HackItAccess.SetValuableDollarValueCurrent(val, value);
			}
		}

		private void EnsureRelay()
		{
			PunManager punManagerInstance = HackItAccess.GetPunManagerInstance();
			if ((Object)(object)punManagerInstance == (Object)null)
			{
				return;
			}
			if ((Object)(object)_relay == (Object)null)
			{
				_relay = ((Component)punManagerInstance).gameObject.GetComponent<HackItRpcRelay>();
				if ((Object)(object)_relay == (Object)null)
				{
					_relay = ((Component)punManagerInstance).gameObject.AddComponent<HackItRpcRelay>();
				}
			}
			_relay.Attach(this);
		}

		private void HandleSessionIdentity()
		{
			RunManager runManagerInstance = HackItAccess.GetRunManagerInstance();
			Level val = (((Object)(object)runManagerInstance != (Object)null) ? HackItAccess.GetRunManagerLevelCurrent(runManagerInstance) : null);
			string text = ((PhotonNetwork.InRoom && PhotonNetwork.CurrentRoom != null) ? PhotonNetwork.CurrentRoom.Name : "singleplayer");
			string text2 = (((Object)(object)val != (Object)null) ? (((Object)val).name ?? "unknown") : "none");
			if (!_roomIdentity.Equals(text, StringComparison.Ordinal) || !_levelIdentity.Equals(text2, StringComparison.Ordinal))
			{
				_roomIdentity = text;
				_levelIdentity = text2;
				ClearSessionState();
				if (SemiFunc.IsMasterClientOrSingleplayer())
				{
					PublishSnapshot();
				}
			}
		}

		private void PullRoomSnapshot()
		{
			if (PhotonNetwork.InRoom && PhotonNetwork.CurrentRoom != null && !SemiFunc.IsMasterClient() && !(Time.unscaledTime < _nextSnapshotPollTime))
			{
				_nextSnapshotPollTime = Time.unscaledTime + 0.25f;
				if (((Dictionary<object, object>)(object)((RoomInfo)PhotonNetwork.CurrentRoom).CustomProperties).ContainsKey((object)"empress.hackit.snapshot") && ((RoomInfo)PhotonNetwork.CurrentRoom).CustomProperties[(object)"empress.hackit.snapshot"] is string text && !(text == _lastSnapshotPayload))
				{
					ApplySnapshotPayload(text);
				}
			}
		}

		private void CleanupExpiredStates()
		{
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				ResolvePendingHacks();
				RestoreExpiredCartStates();
			}
		}

		private void RefreshStateEffects()
		{
			if (Time.unscaledTime < _nextRefreshTime)
			{
				return;
			}
			_nextRefreshTime = Time.unscaledTime + 0.35f;
			float networkClock = GetNetworkClock();
			foreach (HackItHackState value in _states.Values)
			{
				if (!ShouldApplyContinuousEffect(value, networkClock))
				{
					continue;
				}
				switch (value.TargetKind)
				{
				case HackItTargetKind.Valuable:
				{
					ValuableObject val2 = FindComponentByViewId<ValuableObject>(value.viewId);
					if ((Object)(object)val2 != (Object)null)
					{
						ApplyValuableHack(val2, value);
					}
					break;
				}
				case HackItTargetKind.ShopItem:
				{
					ItemAttributes val4 = FindComponentByViewId<ItemAttributes>(value.viewId);
					if ((Object)(object)val4 != (Object)null)
					{
						ApplyShopHack(val4, value);
					}
					break;
				}
				case HackItTargetKind.Enemy:
					if (SemiFunc.IsMasterClientOrSingleplayer())
					{
						Enemy val3 = FindComponentByViewId<Enemy>(value.viewId);
						if ((Object)(object)val3 != (Object)null)
						{
							ApplyEnemyHack(val3, value);
						}
					}
					break;
				case HackItTargetKind.Cart:
				{
					PhysGrabCart val = FindComponentByViewId<PhysGrabCart>(value.viewId);
					if ((Object)(object)val != (Object)null)
					{
						ApplyCartHack(val, value);
					}
					break;
				}
				}
			}
		}

		private void HandleInput()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut value = HackItPlugin.TogglePopupKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				_popupVisible = !_popupVisible;
			}
			if (!_popupVisible || _focus.Kind == HackItTargetKind.None || Time.unscaledTime < _requestCooldownUntil || TryGetStateForFocus(_focus.Kind, _focus.ViewId, _focus.Title, out HackItHackState _))
			{
				return;
			}
			HackActionDefinition[] actions = GetActions(_focus.Kind);
			for (int i = 0; i < actions.Length; i++)
			{
				if (GetSlotKey(i))
				{
					RequestHack(_focus, actions[i]);
					_requestCooldownUntil = Time.unscaledTime + 0.2f;
					break;
				}
			}
		}

		private void DrawPopup()
		{
			//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_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			if (_panelStyle == null || _titleStyle == null || _bodyStyle == null || _mutedStyle == null || _accentStyle == null)
			{
				return;
			}
			float networkClock = GetNetworkClock();
			if (TryGetActiveHackOverlay(networkClock, out string title, out float progress))
			{
				DrawHackOverlay(title, progress);
				return;
			}
			HackItHackState state;
			bool flag = TryGetStateForFocus(_focus.Kind, _focus.ViewId, _focus.Title, out state);
			Rect val = new Rect(18f, Mathf.Max(18f, (float)Screen.height - 320f), 420f, 300f);
			GUI.Box(val, GUIContent.none, _panelStyle);
			GUILayout.BeginArea(val);
			GUILayout.Space(10f);
			GUILayout.Label("Empress HackIt", _titleStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Label(DescribeAuthority() + "  |  Focus: " + _focus.Title, _mutedStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Space(6f);
			if (_focus.Kind == HackItTargetKind.None)
			{
				GUILayout.Label("No hackable target locked.", _bodyStyle, Array.Empty<GUILayoutOption>());
				GUILayout.Label("Aim at a valuable, shop item, extraction point, or enemy to get actions.", _bodyStyle, Array.Empty<GUILayoutOption>());
				GUILayout.Space(4f);
				GUILayout.Label(_focusDebugMessage, _mutedStyle, Array.Empty<GUILayoutOption>());
			}
			else
			{
				GUILayout.Label(_focus.Subtitle, _bodyStyle, Array.Empty<GUILayoutOption>());
				if (!string.IsNullOrWhiteSpace(_focus.Status))
				{
					GUILayout.Label(_focus.Status, _accentStyle, Array.Empty<GUILayoutOption>());
				}
				GUILayout.Space(8f);
				if (flag && state != null && state.IsPending(networkClock))
				{
					string text = NormalizeActorName(state.claimantActorNumber, state.claimantName);
					GUILayout.Label((state.claimantActorNumber == GetLocalActorNumber()) ? "Hack in progress. Hold position until the timer resolves." : (text + " is already hacking this target."), _bodyStyle, Array.Empty<GUILayoutOption>());
					GUILayout.Label($"Hack time: {5f:0}s  |  Success chance: {50f:0}%", _mutedStyle, Array.Empty<GUILayoutOption>());
					GUILayout.Space(6f);
					DrawProgressBar(state.HackProgress(networkClock));
				}
				else if (flag && state != null && state.resolved)
				{
					GUILayout.Label("Hack spent. This target can only be hacked once.", _bodyStyle, Array.Empty<GUILayoutOption>());
					if (!state.succeeded)
					{
						GUILayout.Label("Failure backlash was applied to the target.", _mutedStyle, Array.Empty<GUILayoutOption>());
					}
				}
				else
				{
					GUILayout.Label($"Hack time: {5f:0}s  |  Success chance: {50f:0}%", _mutedStyle, Array.Empty<GUILayoutOption>());
					GUILayout.Space(6f);
					HackActionDefinition[] actions = GetActions(_focus.Kind);
					for (int i = 0; i < actions.Length; i++)
					{
						GUILayout.Label($"[{i + 1}] {actions[i].Label}", _bodyStyle, Array.Empty<GUILayoutOption>());
					}
				}
			}
			GUILayout.FlexibleSpace();
			string text2;
			if (!(Time.unscaledTime <= _feedbackUntil) || string.IsNullOrWhiteSpace(_feedbackMessage))
			{
				KeyboardShortcut value = HackItPlugin.TogglePopupKey.Value;
				text2 = $"Toggle [{((KeyboardShortcut)(ref value)).MainKey}]";
			}
			else
			{
				text2 = _feedbackMessage;
			}
			GUILayout.Label(text2, _mutedStyle, Array.Empty<GUILayoutOption>());
			GUILayout.EndArea();
		}

		private void DrawHackOverlay(string title, float progress)
		{
			//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)
			Rect val = new Rect(Mathf.Max(18f, ((float)Screen.width - 380f) * 0.5f), Mathf.Max(18f, (float)Screen.height - 132f), 380f, 96f);
			GUI.Box(val, GUIContent.none, _panelStyle);
			GUILayout.BeginArea(val);
			GUILayout.Space(10f);
			GUILayout.Label(title, _titleStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Hack in progress... {Mathf.RoundToInt(Mathf.Clamp01(progress) * 100f)}%", _bodyStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Space(6f);
			DrawProgressBar(progress);
			GUILayout.EndArea();
		}

		private void EnsureGuiStyles()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_006b: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Expected O, but got Unknown
			//IL_00ee: 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_00fb: 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_0124: Expected O, but got Unknown
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: 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_0161: Expected O, but got Unknown
			if (_panelStyle == null)
			{
				Texture2D background = MakeTexture(new Color(0.03f, 0.03f, 0.03f, 0.96f));
				GUIStyle val = new GUIStyle(GUI.skin.box);
				val.normal.background = background;
				val.padding = new RectOffset(14, 14, 10, 10);
				val.border = new RectOffset(8, 8, 8, 8);
				_panelStyle = val;
				GUIStyle val2 = new GUIStyle(GUI.skin.label)
				{
					fontSize = 19,
					fontStyle = (FontStyle)1
				};
				val2.normal.textColor = new Color(0.98f, 0.82f, 0.4f, 1f);
				_titleStyle = val2;
				GUIStyle val3 = new GUIStyle(GUI.skin.label)
				{
					fontSize = 14,
					wordWrap = true
				};
				val3.normal.textColor = Color.white;
				_bodyStyle = val3;
				GUIStyle val4 = new GUIStyle(_bodyStyle)
				{
					fontSize = 12
				};
				val4.normal.textColor = new Color(0.78f, 0.78f, 0.8f, 1f);
				_mutedStyle = val4;
				GUIStyle val5 = new GUIStyle(_bodyStyle)
				{
					fontSize = 13
				};
				val5.normal.textColor = new Color(0.55f, 0.9f, 0.72f, 1f);
				_accentStyle = val5;
			}
		}

		private void DrawProgressBar(float progress)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//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_0038: 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)
			//IL_0061: 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)
			Rect rect = GUILayoutUtility.GetRect(360f, 20f, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			Color color = GUI.color;
			GUI.color = new Color(0.12f, 0.12f, 0.12f, 0.95f);
			GUI.DrawTexture(rect, (Texture)(object)Texture2D.whiteTexture);
			GUI.color = new Color(0.98f, 0.82f, 0.4f, 1f);
			GUI.DrawTexture(new Rect(((Rect)(ref rect)).x + 2f, ((Rect)(ref rect)).y + 2f, Mathf.Max(0f, (((Rect)(ref rect)).width - 4f) * Mathf.Clamp01(progress)), ((Rect)(ref rect)).height - 4f), (Texture)(object)Texture2D.whiteTexture);
			GUI.color = color;
			GUILayout.Label($"{Mathf.RoundToInt(Mathf.Clamp01(progress) * 100f)}% linked", _mutedStyle, Array.Empty<GUILayoutOption>());
		}

		private HackFocus ResolveFocus()
		{
			//IL_0026: 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_0130: 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)
			Camera val = HackItAccess.TryGetFocusCamera();
			if ((Object)(object)val == (Object)null)
			{
				_focusDebugMessage = "No player camera found yet.";
				return HackFocus.None;
			}
			RaycastHit[] array = Physics.RaycastAll(((Component)val).transform.position, ((Component)val).transform.forward, HackItPlugin.PopupTargetRange.Value, -5, (QueryTriggerInteraction)1);
			if (array.Length == 0)
			{
				_focusDebugMessage = $"No collider in range ({HackItPlugin.PopupTargetRange.Value:0.#}m).";
				return HackFocus.None;
			}
			Array.Sort(array, (RaycastHit left, RaycastHit right) => ((RaycastHit)(ref left)).distance.CompareTo(((RaycastHit)(ref right)).distance));
			HackFocus result = HackFocus.None;
			for (int i = 0; i < array.Length; i++)
			{
				if (TryBuildFocus(((RaycastHit)(ref array[i])).transform, out var focus))
				{
					if (focus.Kind != HackItTargetKind.Cart)
					{
						_focusDebugMessage = $"Locked {focus.Kind}: {focus.Title}";
						return focus;
					}
					if (result.Kind == HackItTargetKind.None)
					{
						result = focus;
					}
				}
			}
			if (result.Kind != 0)
			{
				_focusDebugMessage = $"Locked {result.Kind}: {result.Title}";
				return result;
			}
			RaycastHit val2 = array[0];
			_focusDebugMessage = $"Aiming at {CleanName(((Object)((Component)((RaycastHit)(ref val2)).transform).gameObject).name)} ({((RaycastHit)(ref val2)).distance:0.0}m), but it is not hackable.";
			return HackFocus.None;
		}

		private bool TryBuildFocus(Transform transform, out HackFocus focus)
		{
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			ItemAttributes val = ((Component)transform).GetComponent<ItemAttributes>() ?? ((Component)transform).GetComponentInParent<ItemAttributes>();
			if ((Object)(object)val != (Object)null && HackItAccess.GetItemAttributesShopItem(val))
			{
				int viewId = GetViewId((Component)(object)val);
				if (viewId != 0)
				{
					string itemName = GetItemName(val);
					focus = new HackFocus(HackItTargetKind.ShopItem, viewId, itemName, $"Price: ${HackItAccess.GetItemAttributesValue(val)}", BuildStatus(HackItTargetKind.ShopItem, viewId, itemName));
					return true;
				}
			}
			ValuableObject val2 = ((Component)transform).GetComponent<ValuableObject>() ?? ((Component)transform).GetComponentInParent<ValuableObject>();
			if ((Object)(object)val2 != (Object)null)
			{
				int viewId2 = GetViewId((Component)(object)val2);
				if (viewId2 != 0)
				{
					string title = CleanName(((Object)((Component)val2).gameObject).name);
					focus = new HackFocus(HackItTargetKind.Valuable, viewId2, title, $"Value: ${Mathf.RoundToInt(HackItAccess.GetValuableDollarValueCurrent(val2))}", BuildStatus(HackItTargetKind.Valuable, viewId2, title));
					return true;
				}
			}
			PhysGrabCart val3 = ((Component)transform).GetComponent<PhysGrabCart>() ?? ((Component)transform).GetComponentInParent<PhysGrabCart>();
			if ((Object)(object)val3 != (Object)null)
			{
				int viewId3 = GetViewId((Component)(object)val3);
				if (viewId3 != 0)
				{
					string title2 = CleanName(((Object)((Component)val3).gameObject).name);
					focus = new HackFocus(HackItTargetKind.Cart, viewId3, title2, $"Cart haul: ${HackItAccess.GetPhysGrabCartHaulCurrent(val3)}", BuildStatus(HackItTargetKind.Cart, viewId3, title2));
					return true;
				}
			}
			ExtractionPoint val4 = ((Component)transform).GetComponent<ExtractionPoint>() ?? ((Component)transform).GetComponentInParent<ExtractionPoint>();
			if ((Object)(object)val4 != (Object)null && !HackItAccess.GetExtractionPointIsShop(val4))
			{
				int viewId4 = GetViewId((Component)(object)val4);
				if (viewId4 != 0)
				{
					focus = new HackFocus(HackItTargetKind.Extractor, viewId4, "Extraction Point", $"Current haul: ${Mathf.RoundToInt(HackItAccess.GetExtractionPointHaulCurrent(val4) / 1000f)}k", BuildStatus(HackItTargetKind.Extractor, viewId4, "Extraction Point"));
					return true;
				}
			}
			Enemy val5 = ((Component)transform).GetComponent<Enemy>() ?? ((Component)transform).GetComponentInParent<Enemy>();
			if ((Object)(object)val5 == (Object)null)
			{
				EnemyRigidbody val6 = ((Component)transform).GetComponent<EnemyRigidbody>() ?? ((Component)transform).GetComponentInParent<EnemyRigidbody>();
				if ((Object)(object)val6 != (Object)null)
				{
					val5 = HackItAccess.GetEnemy(val6);
					if ((Object)(object)val5 == (Object)null)
					{
						EnemyParent val7 = HackItAccess.GetEnemyParent(val6) ?? ((Component)transform).GetComponentInParent<EnemyParent>();
						if ((Object)(object)val7 != (Object)null)
						{
							val5 = HackItAccess.GetEnemy(val7);
						}
					}
				}
			}
			if ((Object)(object)val5 == (Object)null)
			{
				EnemyParent val8 = ((Component)transform).GetComponent<EnemyParent>() ?? ((Component)transform).GetComponentInParent<EnemyParent>();
				if ((Object)(object)val8 != (Object)null)
				{
					val5 = HackItAccess.GetEnemy(val8);
				}
			}
			if ((Object)(object)val5 != (Object)null)
			{
				int viewId5 = GetViewId((Component)(object)val5);
				if (viewId5 != 0)
				{
					string enemyName = GetEnemyName(val5);
					focus = new HackFocus(HackItTargetKind.Enemy, viewId5, enemyName, $"State: {HackItAccess.GetEnemyCurrentState(val5)}", BuildStatus(HackItTargetKind.Enemy, viewId5, enemyName));
					return true;
				}
			}
			focus = HackFocus.None;
			return false;
		}

		private void RequestHack(HackFocus focus, HackActionDefinition action)
		{
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				if (TryStartHack(focus.ViewId, focus.Kind, action.Kind, GetLocalActorNumber(), GetLocalActorName(), out string notice))
				{
					BroadcastNotice(notice);
				}
				else
				{
					ReceivePrivateNotice(notice);
				}
				return;
			}
			PunManager punManagerInstance = HackItAccess.GetPunManagerInstance();
			PhotonView val = (((Object)(object)punManagerInstance != (Object)null) ? HackItAccess.GetPunManagerPhotonView(punManagerInstance) : null);
			if ((Object)(object)_relay == (Object)null || (Object)(object)val == (Object)null)
			{
				ReceivePrivateNotice("HackIt could not reach the host bridge.");
				return;
			}
			val.RPC("EmpressHack_RequestActionRPC", (RpcTarget)2, new object[3]
			{
				focus.ViewId,
				focus.Kind.ToString(),
				action.Kind.ToString()
			});
			_states[focus.ViewId] = BuildPendingState(focus.ViewId, focus.Kind, action, GetLocalActorNumber(), GetLocalActorName(), focus.Title, GetNetworkClock());
			StartPreviewHack(focus);
			ReceiveNotice(GetLocalActorName() + " started hacking " + focus.Title + ".");
		}

		private bool TryStartHack(int viewId, HackItTargetKind targetKind, HackItActionKind actionKind, int actorNumber, string actorName, out string notice)
		{
			HackActionDefinition? actionDefinition = GetActionDefinition(targetKind, actionKind);
			if (!actionDefinition.HasValue)
			{
				notice = "That hack script is invalid.";
				return false;
			}
			float networkClock = GetNetworkClock();
			if (_states.TryGetValue(viewId, out HackItHackState value))
			{
				if (!value.resolved)
				{
					if (value.claimantActorNumber == actorNumber)
					{
						notice = "You are already hacking " + value.targetName + ".";
					}
					else
					{
						string text = NormalizeActorName(value.claimantActorNumber, value.claimantName);
						notice = value.targetName + " is already being hacked by " + text + ".";
					}
					return false;
				}
				notice = value.targetName + " has already been hacked.";
				return false;
			}
			if (!TryResolveTargetName(viewId, targetKind, out string targetName))
			{
				notice = "That target slipped out of the Empress scope.";
				return false;
			}
			string text2 = NormalizeActorName(actorNumber, actorName);
			_states[viewId] = BuildPendingState(viewId, targetKind, actionDefinition.Value, actorNumber, text2, targetName, networkClock);
			PublishSnapshot();
			notice = text2 + " started hacking " + targetName + ".";
			return true;
		}

		private static HackItHackState BuildPendingState(int viewId, HackItTargetKind targetKind, HackActionDefinition definition, int actorNumber, string actorName, string targetName, float startedTime)
		{
			return new HackItHackState
			{
				viewId = viewId,
				targetKind = targetKind.ToString(),
				actionKind = definition.Kind.ToString(),
				targetName = targetName,
				primaryValue = definition.Primary,
				secondaryValue = definition.Secondary,
				startedTime = startedTime,
				resolveTime = startedTime + 5f,
				label = definition.Label,
				claimantActorNumber = actorNumber,
				claimantName = actorName,
				resolved = false,
				succeeded = false,
				persistentEffect = false,
				effectExpiryTime = 0f
			};
		}

		private void ResolvePendingHacks()
		{
			float networkClock = GetNetworkClock();
			List<int> list = null;
			foreach (KeyValuePair<int, HackItHackState> state in _states)
			{
				if (state.Value.ReadyToResolve(networkClock))
				{
					if (list == null)
					{
						list = new List<int>();
					}
					list.Add(state.Key);
				}
			}
			if (list == null)
			{
				return;
			}
			bool flag = false;
			foreach (int item in list)
			{
				if (_states.TryGetValue(item, out HackItHackState value) && !value.resolved)
				{
					bool flag2 = Random.value <= 0.5f;
					HackItHackState hackItHackState = BuildResolvedState(value, flag2, networkClock);
					_states[item] = hackItHackState;
					flag = true;
					try
					{
						ApplyResolvedStateImmediate(hackItHackState);
					}
					catch (Exception arg)
					{
						HackItPlugin.LogProxy.Error($"HackIt immediate apply failed for {hackItHackState.targetName} ({hackItHackState.TargetKind}). {arg}");
					}
					string text = NormalizeActorName(hackItHackState.claimantActorNumber, hackItHackState.claimantName);
					string message = (flag2 ? (text + " hacked " + hackItHackState.targetName + ": " + hackItHackState.label + ".") : (text + " failed hacking " + hackItHackState.targetName + ": " + hackItHackState.label + "."));
					BroadcastNotice(message);
				}
			}
			if (flag)
			{
				PublishSnapshot();
			}
		}

		private void RestoreExpiredCartStates()
		{
			float networkClock = GetNetworkClock();
			foreach (HackItHackState value in _states.Values)
			{
				if (value.TargetKind == HackItTargetKind.Cart && value.EffectExpired(networkClock) && _restoredCartStates.Add(value.viewId))
				{
					PhysGrabCart val = FindComponentByViewId<PhysGrabCart>(value.viewId);
					if ((Object)(object)val != (Object)null)
					{
						RestoreCart(val);
					}
				}
			}
		}

		private HackItHackState BuildResolvedState(HackItHackState pendingState, bool success, float now)
		{
			pendingState.resolved = true;
			pendingState.succeeded = success;
			pendingState.resolveTime = now;
			if (success)
			{
				float resolvedEffectDuration = GetResolvedEffectDuration(pendingState.TargetKind, pendingState.ActionKind);
				pendingState.persistentEffect = resolvedEffectDuration <= 0f;
				pendingState.effectExpiryTime = ((resolvedEffectDuration > 0f) ? (now + resolvedEffectDuration) : 0f);
				return pendingState;
			}
			pendingState.persistentEffect = true;
			pendingState.effectExpiryTime = 0f;
			switch (pendingState.TargetKind)
			{
			case HackItTargetKind.Valuable:
				pendingState.label = "Value Crash";
				pendingState.primaryValue = 0.35f;
				pendingState.secondaryValue = 1.85f;
				break;
			case HackItTargetKind.ShopItem:
				pendingState.label = "Price Spike";
				pendingState.primaryValue = 3f;
				pendingState.secondaryValue = 1f;
				break;
			case HackItTargetKind.Extractor:
				pendingState.label = "Tax Leak";
				pendingState.primaryValue = 0.5f;
				pendingState.secondaryValue = 1f;
				break;
			case HackItTargetKind.Enemy:
				pendingState.label = "Firewalled";
				pendingState.primaryValue = 1f;
				pendingState.secondaryValue = 1f;
				break;
			case HackItTargetKind.Cart:
				pendingState.label = "Axle Jam";
				pendingState.primaryValue = 22f;
				pendingState.secondaryValue = 1f;
				pendingState.persistentEffect = false;
				pendingState.effectExpiryTime = now + 60f;
				break;
			}
			return pendingState;
		}

		private void ApplyResolvedStateImmediate(HackItHackState state)
		{
			switch (state.TargetKind)
			{
			case HackItTargetKind.Valuable:
			{
				ValuableObject val4 = FindComponentByViewId<ValuableObject>(state.viewId);
				if ((Object)(object)val4 != (Object)null)
				{
					ApplyValuableHack(val4, state);
				}
				break;
			}
			case HackItTargetKind.ShopItem:
			{
				ItemAttributes val2 = FindComponentByViewId<ItemAttributes>(state.viewId);
				if ((Object)(object)val2 != (Object)null)
				{
					ApplyShopHack(val2, state);
				}
				break;
			}
			case HackItTargetKind.Enemy:
			{
				Enemy val3 = FindComponentByViewId<Enemy>(state.viewId);
				if ((Object)(object)val3 != (Object)null)
				{
					ApplyEnemyHack(val3, state);
				}
				break;
			}
			case HackItTargetKind.Cart:
			{
				PhysGrabCart val = FindComponentByViewId<PhysGrabCart>(state.viewId);
				if ((Object)(object)val != (Object)null)
				{
					ApplyCartHack(val, state);
				}
				break;
			}
			case HackItTargetKind.Extractor:
				break;
			}
		}

		private static float GetResolvedEffectDuration(HackItTargetKind targetKind, HackItActionKind actionKind)
		{
			return GetActionDefinition(targetKind, actionKind)?.Duration ?? 0f;
		}

		private bool TryResolveTargetName(int viewId, HackItTargetKind targetKind, out string targetName)
		{
			switch (targetKind)
			{
			case HackItTargetKind.Valuable:
			{
				ValuableObject val2 = FindComponentByViewId<ValuableObject>(viewId);
				if ((Object)(object)val2 != (Object)null)
				{
					targetName = CleanName(((Object)((Component)val2).gameObject).name);
					return true;
				}
				break;
			}
			case HackItTargetKind.ShopItem:
			{
				ItemAttributes val4 = FindComponentByViewId<ItemAttributes>(viewId);
				if ((Object)(object)val4 != (Object)null)
				{
					targetName = GetItemName(val4);
					return true;
				}
				break;
			}
			case HackItTargetKind.Extractor:
				if ((Object)(object)FindComponentByViewId<ExtractionPoint>(viewId) != (Object)null)
				{
					targetName = "Extraction Point";
					return true;
				}
				break;
			case HackItTargetKind.Enemy:
			{
				Enemy val3 = FindComponentByViewId<Enemy>(viewId);
				if ((Object)(object)val3 != (Object)null)
				{
					targetName = GetEnemyName(val3);
					return true;
				}
				break;
			}
			case HackItTargetKind.Cart:
			{
				PhysGrabCart val = FindComponentByViewId<PhysGrabCart>(viewId);
				if ((Object)(object)val != (Object)null)
				{
					targetName = CleanName(((Object)((Component)val).gameObject).name);
					return true;
				}
				break;
			}
			}
			targetName = string.Empty;
			return false;
		}

		private void StartPreviewHack(HackFocus focus)
		{
			_previewHackViewId = focus.ViewId;
			_previewHackTargetName = focus.Title;
			_previewHackStartedTime = Time.unscaledTime;
			_previewHackResolveTime = _previewHackStartedTime + 5f;
		}

		private void ClearPreviewHack()
		{
			_previewHackViewId = 0;
			_previewHackTargetName = string.Empty;
			_previewHackStartedTime = 0f;
			_previewHackResolveTime = 0f;
		}

		private bool TryGetActiveHackOverlay(float now, out string title, out float progress)
		{
			int localActorNumber = GetLocalActorNumber();
			if (_previewHackViewId != 0)
			{
				if (_states.TryGetValue(_previewHackViewId, out HackItHackState value) && value.claimantActorNumber == localActorNumber)
				{
					if (!value.resolved)
					{
						title = (string.IsNullOrWhiteSpace(value.targetName) ? _previewHackTargetName : value.targetName);
						progress = value.HackProgress(now);
						return true;
					}
					ClearPreviewHack();
				}
				if (Time.unscaledTime < _previewHackResolveTime)
				{
					title = _previewHackTargetName;
					float num = Mathf.Max(0.01f, _previewHackResolveTime - _previewHackStartedTime);
					progress = Mathf.Clamp01((Time.unscaledTime - _previewHackStartedTime) / num);
					return true;
				}
				if (Time.unscaledTime >= _previewHackResolveTime)
				{
					ClearPreviewHack();
				}
			}
			foreach (HackItHackState value2 in _states.Values)
			{
				if (value2.claimantActorNumber == localActorNumber && value2.IsPending(now))
				{
					title = value2.targetName;
					progress = value2.HackProgress(now);
					return true;
				}
			}
			title = string.Empty;
			progress = 0f;
			return false;
		}

		private void ApplyValuableHack(ValuableObject valuableObject, HackItHackState state)
		{
			int viewId = GetViewId((Component)(object)valuableObject);
			if (!_valuableBaseValues.ContainsKey(viewId))
			{
				_valuableBaseValues[viewId] = Mathf.Max(HackItAccess.GetValuableDollarValueCurrent(valuableObject), HackItAccess.GetValuableDollarValueOriginal(valuableObject));
			}
			if (!_valuableBaseMasses.ContainsKey(viewId))
			{
				float num = HackItAccess.GetValuableRigidBodyMass(valuableObject);
				Rigidbody valuableRigidbody = HackItAccess.GetValuableRigidbody(valuableObject);
				if (num <= 0f && (Object)(object)valuableRigidbody != (Object)null)
				{
					num = valuableRigidbody.mass;
				}
				_valuableBaseMasses[viewId] = Mathf.Max(0.1f, num);
			}
			float num2 = Mathf.Max(5f, Mathf.Round(_valuableBaseValues[viewId] * state.primaryValue / 5f) * 5f);
			float num3 = Mathf.Max(0.1f, _valuableBaseMasses[viewId] * state.secondaryValue);
			float valuableDollarValueOriginal = HackItAccess.GetValuableDollarValueOriginal(valuableObject);
			float valuableDollarValueCurrent = HackItAccess.GetValuableDollarValueCurrent(valuableObject);
			float num4 = ((valuableDollarValueOriginal > 0.01f) ? Mathf.Clamp01(valuableDollarValueCurrent / valuableDollarValueOriginal) : 1f);
			float value = Mathf.Clamp(Mathf.Round(num2 * num4), 0f, num2);
			if (valuableDollarValueOriginal <= 0.01f || Mathf.Approximately(valuableDollarValueCurrent, valuableDollarValueOriginal))
			{
				value = num2;
			}
			HackItAccess.SetValuableDollarValueOriginal(valuableObject, num2);
			HackItAccess.SetValuableDollarValueCurrent(valuableObject, value);
			HackItAccess.SetValuableDollarValueSet(valuableObject, value: true);
			HackItAccess.SetValuableRigidBodyMass(valuableObject, num3);
			Rigidbody valuableRigidbody2 = HackItAccess.GetValuableRigidbody(valuableObject);
			if ((Object)(object)valuableRigidbody2 != (Object)null)
			{
				valuableRigidbody2.mass = num3;
			}
			PhysGrabObject valuablePhysGrabObject = HackItAccess.GetValuablePhysGrabObject(valuableObject);
			if ((Object)(object)valuablePhysGrabObject != (Object)null)
			{
				HackItAccess.SetPhysGrabObjectMassOriginal(valuablePhysGrabObject, num3);
			}
			PhotonView valuablePhotonView = HackItAccess.GetValuablePhotonView(valuableObject);
			if (SemiFunc.IsMultiplayer() && SemiFunc.IsMasterClient() && (Object)(object)valuablePhotonView != (Object)null && valuablePhotonView.ViewID > 0 && (!_lastBroadcastValuableValues.TryGetValue(viewId, out var value2) || !Mathf.Approximately(value2, num2)))
			{
				_lastBroadcastValuableValues[viewId] = num2;
				valuablePhotonView.RPC("DollarValueSetRPC", (RpcTarget)1, new object[1] { num2 });
			}
		}

		private void ApplyShopHack(ItemAttributes itemAttributes, HackItHackState state)
		{
			int viewId = GetViewId((Component)(object)itemAttributes);
			if (!_shopBaseValues.ContainsKey(viewId))
			{
				_shopBaseValues[viewId] = Mathf.Max(1, HackItAccess.GetItemAttributesValue(itemAttributes));
			}
			int num = Mathf.Max(1, Mathf.RoundToInt((float)_shopBaseValues[viewId] * state.primaryValue));
			HackItAccess.SetItemAttributesValue(itemAttributes, num);
			if (HackItAccess.GetItemAttributesShopItem(itemAttributes))
			{
				SemiFunc.ShopUpdateCost();
			}
			PhotonView itemAttributesPhotonView = HackItAccess.GetItemAttributesPhotonView(itemAttributes);
			if (SemiFunc.IsMultiplayer() && SemiFunc.IsMasterClient() && (Object)(object)itemAttributesPhotonView != (Object)null && itemAttributesPhotonView.ViewID > 0 && (!_lastBroadcastShopValues.TryGetValue(viewId, out var value) || value != num))
			{
				_lastBroadcastShopValues[viewId] = num;
				itemAttributesPhotonView.RPC("GetValueRPC", (RpcTarget)1, new object[1] { num });
			}
		}

		private void ApplyEnemyHack(Enemy enemy, HackItHackState state)
		{
			if (state.succeeded && state.HasActiveEffect(GetNetworkClock()))
			{
				if (state.ActionKind == HackItActionKind.Pacify)
				{
					PacifyEnemy(enemy);
				}
				else if (state.ActionKind == HackItActionKind.Freeze)
				{
					HackItAccess.InvokeEnemyFreeze(enemy, Mathf.Max(0.25f, state.primaryValue));
				}
			}
		}

		private void ApplyCartHack(PhysGrabCart cart, HackItHackState state)
		{
			int viewId = GetViewId((Component)(object)cart);
			if (!_cartBaseMasses.ContainsKey(viewId))
			{
				Rigidbody val = HackItAccess.GetPhysGrabCartRigidbody(cart) ?? ((Component)cart).GetComponent<Rigidbody>();
				float num = (((Object)(object)val != (Object)null) ? val.mass : 8f);
				_cartBaseMasses[viewId] = Mathf.Max(1f, num);
			}
			float num2 = state.ActionKind switch
			{
				HackItActionKind.FeatherCart => Mathf.Min(_cartBaseMasses[viewId], state.primaryValue), 
				HackItActionKind.HandleCart => Mathf.Min(_cartBaseMasses[viewId], state.primaryValue), 
				_ => _cartBaseMasses[viewId], 
			};
			if (!state.succeeded)
			{
				num2 = Mathf.Max(_cartBaseMasses[viewId] * 3.25f, state.primaryValue);
			}
			_restoredCartStates.Remove(viewId);
			HackItAccess.InvokePhysGrabCartCartMassOverride(cart, num2);
			Rigidbody physGrabCartRigidbody = HackItAccess.GetPhysGrabCartRigidbody(cart);
			if ((Object)(object)physGrabCartRigidbody != (Object)null)
			{
				physGrabCartRigidbody.mass = num2;
			}
			if (state.succeeded && state.ActionKind == HackItActionKind.HandleCart)
			{
				HackItAccess.SetPhysGrabCartCartActive(cart, value: true);
				HackItAccess.InvokePhysGrabCartStateSwitchRpc(cart, (State)2);
			}
			else if (!state.succeeded)
			{
				HackItAccess.SetPhysGrabCartCartActive(cart, value: false);
			}
		}

		private void PacifyEnemy(Enemy enemy)
		{
			//IL_002a: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Invalid comparison between Unknown and I4
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Invalid comparison between Unknown and I4
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Invalid comparison between Unknown and I4
			if (!HackItAccess.GetEnemyMasterClient(enemy) && SemiFunc.IsMultiplayer())
			{
				return;
			}
			HackItAccess.InvokeEnemyDisableChase(enemy, 0.6f);
			HackItAccess.SetEnemyTargetPlayerAvatar(enemy, null);
			HackItAccess.SetEnemyTargetPlayerViewId(enemy, 0);
			EnemyState enemyCurrentState = HackItAccess.GetEnemyCurrentState(enemy);
			if ((int)enemyCurrentState == 4 || (int)enemyCurrentState == 3 || (int)enemyCurrentState == 5)
			{
				HackItAccess.SetEnemyCurrentState(enemy, (EnemyState)2);
			}
			if (HackItAccess.GetEnemyHasVision(enemy))
			{
				EnemyVision enemyVision = HackItAccess.GetEnemyVision(enemy);
				if ((Object)(object)enemyVision != (Object)null)
				{
					HackItAccess.InvokeEnemyVisionDisableVision(enemyVision, 0.6f);
				}
			}
		}

		private bool IsEnemyPacified(Enemy enemy)
		{
			if (!SemiFunc.IsMasterClientOrSingleplayer())
			{
				return false;
			}
			int viewId = GetViewId((Component)(object)enemy);
			if (viewId != 0 && _states.TryGetValue(viewId, out HackItHackState value) && value.TargetKind == HackItTargetKind.Enemy && value.succeeded && value.ActionKind == HackItActionKind.Pacify)
			{
				return value.HasActiveEffect(GetNetworkClock());
			}
			return false;
		}

		private bool ShouldApplyContinuousEffect(HackItHackState state, float now)
		{
			if (!state.resolved || !state.HasActiveEffect(now))
			{
				return false;
			}
			if (state.TargetKind != HackItTargetKind.Enemy)
			{
				return state.TargetKind == HackItTargetKind.Cart;
			}
			return true;
		}

		private void RestoreCart(PhysGrabCart cart)
		{
			int viewId = GetViewId((Component)(object)cart);
			if (!_cartBaseMasses.TryGetValue(viewId, out var value))
			{
				Rigidbody val = HackItAccess.GetPhysGrabCartRigidbody(cart) ?? ((Component)cart).GetComponent<Rigidbody>();
				value = (((Object)(object)val != (Object)null) ? val.mass : 8f);
				_cartBaseMasses[viewId] = Mathf.Max(1f, value);
			}
			float num = Mathf.Max(1f, value);
			HackItAccess.InvokePhysGrabCartCartMassOverride(cart, num);
			Rigidbody physGrabCartRigidbody = HackItAccess.GetPhysGrabCartRigidbody(cart);
			if ((Object)(object)physGrabCartRigidbody != (Object)null)
			{
				physGrabCartRigidbody.mass = num;
			}
			HackItAccess.SetPhysGrabCartCartActive(cart, value: false);
		}

		private void PublishSnapshot()
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			string text = (_lastSnapshotPayload = BuildSnapshotPayload(bumpRevision: true));
			if (PhotonNetwork.InRoom && PhotonNetwork.CurrentRoom != null && SemiFunc.IsMasterClient())
			{
				PunManager punManagerInstance = HackItAccess.GetPunManagerInstance();
				PhotonView val = (((Object)(object)punManagerInstance != (Object)null) ? HackItAccess.GetPunManagerPhotonView(punManagerInstance) : null);
				if ((Object)(object)_relay != (Object)null && (Object)(object)val != (Object)null)
				{
					val.RPC("EmpressHack_SnapshotRPC", (RpcTarget)1, new object[1] { text });
				}
				Hashtable val2 = new Hashtable { [(object)"empress.hackit.snapshot"] = text };
				PhotonNetwork.CurrentRoom.SetCustomProperties(val2, (Hashtable)null, (WebFlags)null);
			}
		}

		private string BuildSnapshotPayload(bool bumpRevision)
		{
			HackItHackSnapshot hackItHackSnapshot = new HackItHackSnapshot
			{
				revision = (bumpRevision ? (++_snapshotRevision) : _snapshotRevision)
			};
			foreach (HackItHackState value in _states.Values)
			{
				hackItHackSnapshot.states.Add(value);
			}
			return hackItHackSnapshot.Serialize();
		}

		private void ApplySnapshotPayload(string payload)
		{
			_lastSnapshotPayload = payload;
			_states.Clear();
			_restoredCartStates.Clear();
			HackItHackSnapshot hackItHackSnapshot = HackItHackSnapshot.Deserialize(payload);
			if (hackItHackSnapshot == null)
			{
				return;
			}
			foreach (HackItHackState state in hackItHackSnapshot.states)
			{
				_states[state.viewId] = state;
				if (state.resolved)
				{
					StoreResolvedUiState(state);
				}
			}
		}

		private void BroadcastNotice(string message)
		{
			PunManager punManagerInstance = HackItAccess.GetPunManagerInstance();
			PhotonView val = (((Object)(object)punManagerInstance != (Object)null) ? HackItAccess.GetPunManagerPhotonView(punManagerInstance) : null);
			if ((Object)(object)_relay == (Object)null || (Object)(object)val == (Object)null || !SemiFunc.IsMultiplayer())
			{
				ReceiveNotice(message);
				return;
			}
			val.RPC("EmpressHack_NoticeRPC", (RpcTarget)0, new object[1] { message });
		}

		private void SendPrivateNotice(PhotonMessageInfo info, string message)
		{
			//IL_0037: 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)
			PunManager punManagerInstance = HackItAccess.GetPunManagerInstance();
			PhotonView val = (((Object)(object)punManagerInstance != (Object)null) ? HackItAccess.GetPunManagerPhotonView(punManagerInstance) : null);
			if (!SemiFunc.IsMultiplayer() || (Object)(object)_relay == (Object)null || (Object)(object)val == (Object)null || info.Sender == null)
			{
				ReceivePrivateNotice(message);
				return;
			}
			val.RPC("EmpressHack_PrivateNoticeRPC", info.Sender, new object[1] { message });
		}

		private void SendSnapshotTo(Player? player)
		{
			PunManager punManagerInstance = HackItAccess.GetPunManagerInstance();
			PhotonView val = (((Object)(object)punManagerInstance != (Object)null) ? HackItAccess.GetPunManagerPhotonView(punManagerInstance) : null);
			if (SemiFunc.IsMultiplayer() && !((Object)(object)_relay == (Object)null) && !((Object)(object)val == (Object)null) && player != null)
			{
				string text = (string.IsNullOrWhiteSpace(_lastSnapshotPayload) ? BuildSnapshotPayload(bumpRevision: false) : _lastSnapshotPayload);
				val.RPC("EmpressHack_SnapshotRPC", player, new object[1] { text });
			}
		}

		private string DescribeAuthority()
		{
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				return "Authority: Host";
			}
			if (!HackItPlugin.AllowClientRequests.Value)
			{
				return "Authority: Host Locked";
			}
			return "Authority: Client Request";
		}

		private bool TryGetStateForFocus(HackItTargetKind targetKind, int viewId, string title, out HackItHackState? state)
		{
			if (viewId != 0 && _states.TryGetValue(viewId, out state))
			{
				return true;
			}
			foreach (HackItHackState value in _states.Values)
			{
				if (value.TargetKind == targetKind && string.Equals(value.targetName, title, StringComparison.OrdinalIgnoreCase))
				{
					state = value;
					return true;
				}
			}
			if (_resolvedUiStates.TryGetValue(BuildUiStateKey(targetKind, title), out state))
			{
				return true;
			}
			if (_resolvedUiStates.TryGetValue(BuildUiStateKey(HackItTargetKind.None, title), out state))
			{
				return true;
			}
			state = null;
			return false;
		}

		private void StoreResolvedUiState(HackItHackState state)
		{
			if (state.resolved && !string.IsNullOrWhiteSpace(state.targetName))
			{
				_resolvedUiStates[BuildUiStateKey(state.TargetKind, state.targetName)] = state;
				_resolvedUiStates[BuildUiStateKey(HackItTargetKind.None, state.targetName)] = state;
			}
		}

		private static string BuildUiStateKey(HackItTargetKind targetKind, string title)
		{
			return $"{targetKind}|{title.Trim()}";
		}

		private string BuildStatus(HackItTargetKind targetKind, int viewId, string title)
		{
			if (!TryGetStateForFocus(targetKind, viewId, title, out HackItHackState state) || state == null)
			{
				return "Status: Clean";
			}
			float networkClock = GetNetworkClock();
			if (!state.resolved)
			{
				string arg = NormalizeActorName(state.claimantActorNumber, state.claimantName);
				float num = state.HackProgress(networkClock) * 100f;
				return $"Status: Hacking ({arg}, {num:0}%)";
			}
			if (!state.succeeded)
			{
				if (state.HasActiveEffect(networkClock) && !state.persistentEffect)
				{
					return $"Status: {state.label} ({state.EffectRemaining(networkClock):0}s)";
				}
				return "Status: " + state.label + " | Spent";
			}
			if (state.HasActiveEffect(networkClock) && !state.persistentEffect)
			{
				return $"Status: {state.label} ({state.EffectRemaining(networkClock):0}s)";
			}
			return "Status: " + state.label + " | Spent";
		}

		private static int GetLocalActorNumber()
		{
			if (!PhotonNetwork.InRoom || PhotonNetwork.LocalPlayer == null)
			{
				return 0;
			}
			return PhotonNetwork.LocalPlayer.ActorNumber;
		}

		private static string GetLocalActorName()
		{
			if (PhotonNetwork.InRoom && PhotonNetwork.LocalPlayer != null && !string.IsNullOrWhiteSpace(PhotonNetwork.LocalPlayer.NickName))
			{
				return PhotonNetwork.LocalPlayer.NickName;
			}
			if (!SemiFunc.IsMasterClientOrSingleplayer())
			{
				return "Client";
			}
			return "Host";
		}

		private static string NormalizeActorName(int actorNumber, string actorName)
		{
			if (!string.IsNullOrWhiteSpace(actorName))
			{
				return actorName;
			}
			if (actorNumber != 0)
			{
				return $"Player {actorNumber}";
			}
			return "Host";
		}

		private static HackActionDefinition[] GetActions(HackItTargetKind targetKind)
		{
			return targetKind switch
			{
				HackItTargetKind.Valuable => ValuableActions, 
				HackItTargetKind.ShopItem => ShopActions, 
				HackItTargetKind.Extractor => ExtractorActions, 
				HackItTargetKind.Enemy => EnemyActions, 
				HackItTargetKind.Cart => CartActions, 
				_ => Array.Empty<HackActionDefinition>(), 
			};
		}

		private static HackActionDefinition? GetActionDefinition(HackItTargetKind targetKind, HackItActionKind actionKind)
		{
			HackActionDefinition[] actions = GetActions(targetKind);
			for (int i = 0; i < actions.Length; i++)
			{
				if (actions[i].Kind == actionKind)
				{
					return actions[i];
				}
			}
			return null;
		}

		private static bool GetSlotKey(int index)
		{
			return index switch
			{
				0 => Input.GetKeyDown((KeyCode)49) || Input.GetKeyDown((KeyCode)257), 
				1 => Input.GetKeyDown((KeyCode)50) || Input.GetKeyDown((KeyCode)258), 
				2 => Input.GetKeyDown((KeyCode)51) || Input.GetKeyDown((KeyCode)259), 
				_ => false, 
			};
		}

		private static string GetItemName(ItemAttributes itemAttributes)
		{
			string itemAttributesItemName = HackItAccess.GetItemAttributesItemName(itemAttributes);
			if (!string.IsNullOrWhiteSpace(itemAttributesItemName))
			{
				return itemAttributesItemName;
			}
			Item itemAttributesItem = HackItAccess.GetItemAttributesItem(itemAttributes);
			string text = (((Object)(object)itemAttributesItem != (Object)null) ? HackItAccess.GetItemItemName(itemAttributesItem) : string.Empty);
			if (!string.IsNullOrWhiteSpace(text))
			{
				return text;
			}
			return CleanName(((Object)((Component)itemAttributes).gameObject).name);
		}

		private static string GetEnemyName(Enemy enemy)
		{
			EnemyParent enemyParent = HackItAccess.GetEnemyParent(enemy);
			string value = (((Object)(object)enemyParent != (Object)null) ? HackItAccess.GetEnemyParentEnemyName(enemyParent) : string.Empty);
			if (!string.IsNullOrWhiteSpace(value))
			{
				return CleanName(value);
			}
			Transform root = ((Component)enemy).transform.root;
			if ((Object)(object)root != (Object)null && !string.IsNullOrWhiteSpace(((Object)root).name))
			{
				return CleanName(((Object)root).name);
			}
			return CleanName(((Object)((Component)enemy).gameObject).name);
		}

		private static string CleanName(string value)
		{
			if (!string.IsNullOrWhiteSpace(value))
			{
				return value.Replace("(Clone)", string.Empty).Trim();
			}
			return "Unknown";
		}

		private static float GetNetworkClock()
		{
			if (!PhotonNetwork.InRoom)
			{
				return Time.unscaledTime;
			}
			return (float)PhotonNetwork.Time;
		}

		private static int GetViewId(Component component)
		{
			if ((Object)(object)component == (Object)null)
			{
				return 0;
			}
			ValuableObject val = (ValuableObject)(object)((component is ValuableObject) ? component : null);
			if (val != null)
			{
				PhotonView valuablePhotonView = HackItAccess.GetValuablePhotonView(val);
				if ((Object)(object)valuablePhotonView != (Object)null && valuablePhotonView.ViewID > 0)
				{
					return valuablePhotonView.ViewID;
				}
			}
			ItemAttributes val2 = (ItemAttributes)(object)((component is ItemAttributes) ? component : null);
			if (val2 != null)
			{
				PhotonView itemAttributesPhotonView = HackItAccess.GetItemAttributesPhotonView(val2);
				if ((Object)(object)itemAttributesPhotonView != (Object)null && itemAttributesPhotonView.ViewID > 0)
				{
					return itemAttributesPhotonView.ViewID;
				}
			}
			PhotonView val3 = component.GetComponent<PhotonView>() ?? component.GetComponentInParent<PhotonView>();
			if ((Object)(object)val3 != (Object)null && val3.ViewID > 0)
			{
				return val3.ViewID;
			}
			return BuildStableFallbackId(component);
		}

		private static T? FindComponentByViewId<T>(int viewId) where T : Component
		{
			if (viewId > 0)
			{
				PhotonView val = PhotonView.Find(viewId);
				if ((Object)(object)val != (Object)null)
				{
					T val2 = ((Component)val).GetComponent<T>() ?? ((Component)val).GetComponentInChildren<T>() ?? ((Component)val).GetComponentInParent<T>();
					if ((Object)(object)val2 != (Object)null)
					{
						return val2;
					}
				}
			}
			T[] array = Object.FindObjectsOfType<T>();
			for (int i = 0; i < array.Length; i++)
			{
				if (GetViewId((Component)(object)array[i]) == viewId)
				{
					return array[i];
				}
			}
			return default(T);
		}

		private static int BuildStableFallbackId(Component component)
		{
			string text = BuildStableFallbackKey(component);
			uint num = 2166136261u;
			for (int i = 0; i < text.Length; i++)
			{
				num ^= text[i];
				num *= 16777619;
			}
			int num2 = (int)num;
			if (num2 == 0)
			{
				return -1;
			}
			if (num2 <= 0)
			{
				return num2;
			}
			return -num2;
		}

		private static string BuildStableFallbackKey(Component component)
		{
			//IL_0008: 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_0037: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = component.transform;
			Vector3 position = transform.position;
			return string.Format(CultureInfo.InvariantCulture, "{0}|{1}|{2:F3}|{3:F3}|{4:F3}", ((object)component).GetType().Name, BuildTransformPath(transform), position.x, position.y, position.z);
		}

		private static string BuildTransformPath(Transform transform)
		{
			List<string> list = new List<string>();
			Transform val = transform;
			while ((Object)(object)val != (Object)null)
			{
				list.Add(CleanName(((Object)val).name));
				val = val.parent;
			}
			list.Reverse();
			return string.Join("/", list);
		}

		private void ClearSessionState()
		{
			_states.Clear();
			_resolvedUiStates.Clear();
			_valuableBaseValues.Clear();
			_valuableBaseMasses.Clear();
			_lastBroadcastValuableValues.Clear();
			_lastBroadcastShopValues.Clear();
			_shopBaseValues.Clear();
			_cartBaseMasses.Clear();
			_restoredCartStates.Clear();
			ClearPreviewHack();
			_lastSnapshotPayload = string.Empty;
			_snapshotRevision = 0;
		}

		private static Texture2D MakeTexture(Color color)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_0019: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false);
			val.SetPixel(0, 0, color);
			val.Apply();
			return val;
		}

		private static bool CanResolveFocus()
		{
			RunManager runManagerInstance = HackItAccess.GetRunManagerInstance();
			if ((Object)(object)runManagerInstance == (Object)null || (Object)(object)HackItAccess.GetRunManagerLevelCurrent(runManagerInstance) == (Object)null)
			{
				return false;
			}
			if (SemiFunc.MenuLevel())
			{
				return false;
			}
			if (!SemiFunc.RunIsLevel() && !SemiFunc.RunIsShop() && !SemiFunc.RunIsLobby())
			{
				return SemiFunc.RunIsTutorial();
			}
			return true;
		}
	}
	internal sealed class HackItRpcRelay : MonoBehaviourPun
	{
		private HackItRuntime? _runtime;

		internal void Attach(HackItRuntime runtime)
		{
			_runtime = runtime;
		}

		[PunRPC]
		public void EmpressHack_RequestActionRPC(int viewId, string targetKind, string actionKind, PhotonMessageInfo info = default(PhotonMessageInfo))
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			_runtime?.ReceiveRemoteRequest(viewId, targetKind, actionKind, info);
		}

		[PunRPC]
		public void EmpressHack_NoticeRPC(string message, PhotonMessageInfo info = default(PhotonMessageInfo))
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.MasterOnlyRPC(info))
			{
				_runtime?.ReceiveNotice(message);
			}
		}

		[PunRPC]
		public void EmpressHack_PrivateNoticeRPC(string message, PhotonMessageInfo info = default(PhotonMessageInfo))
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.MasterOnlyRPC(info))
			{
				_runtime?.ReceivePrivateNotice(message);
			}
		}

		[PunRPC]
		public void EmpressHack_SnapshotRPC(string payload, PhotonMessageInfo info = default(PhotonMessageInfo))
		{
			//IL_0007: 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)
			if (!SemiFunc.IsMultiplayer() || info.Sender == null || info.Sender == PhotonNetwork.MasterClient)
			{
				_runtime?.ReceiveSnapshotPayload(payload);
			}
		}

		[PunRPC]
		public void EmpressHack_ValuableCurrentRPC(int viewId, float currentValue, PhotonMessageInfo info = default(PhotonMessageInfo))
		{
			//IL_0007: 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)
			if (!SemiFunc.IsMultiplayer() || info.Sender == null || info.Sender == PhotonNetwork.MasterClient)
			{
				_runtime?.ReceiveValuableCurrentValue(viewId, currentValue);
			}
		}
	}
}
namespace EmpressHackIt.Core
{
	internal enum HackItTargetKind
	{
		None,
		Valuable,
		ShopItem,
		Extractor,
		Enemy,
		Cart
	}
	internal enum HackItActionKind
	{
		None,
		Boost,
		Jackpot,
		Feather,
		Discount,
		Free,
		Markup,
		Bonus,
		MegaBonus,
		Overdrive,
		Pacify,
		Freeze,
		FeatherCart,
		HandleCart
	}
	[Serializable]
	internal sealed class HackItHackState
	{
		public int viewId;

		public string targetKind = "None";

		public string actionKind = "None";

		public string targetName = string.Empty;

		public float primaryValue = 1f;

		public float secondaryValue = 1f;

		public float startedTime;

		public float resolveTime;

		public float effectExpiryTime;

		public string label = string.Empty;

		public int claimantActorNumber;

		public string claimantName = string.Empty;

		public bool resolved;

		public bool succeeded;

		public bool persistentEffect;

		public HackItTargetKind TargetKind
		{
			get
			{
				if (!Enum.TryParse<HackItTargetKind>(targetKind, ignoreCase: true, out var result))
				{
					return HackItTargetKind.None;
				}
				return result;
			}
		}

		public HackItActionKind ActionKind
		{
			get
			{
				if (!Enum.TryParse<HackItActionKind>(actionKind, ignoreCase: true, out var result))
				{
					return HackItActionKind.None;
				}
				return result;
			}
		}

		public bool IsPending(float currentTime)
		{
			if (!resolved && resolveTime > startedTime)
			{
				return currentTime < resolveTime;
			}
			return false;
		}

		public bool ReadyToResolve(float currentTime)
		{
			if (!resolved && resolveTime > 0f)
			{
				return currentTime >= resolveTime;
			}
			return false;
		}

		public float HackProgress(float currentTime)
		{
			if (resolved)
			{
				return 1f;
			}
			if (resolveTime <= startedTime)
			{
				r