Decompiled source of FapEnergy v1.0.0

com.github.zehsteam.FapEnergy.dll

Decompiled 4 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Dawn;
using GameNetcodeStuff;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;
using com.github.zehsteam.FapEnergy.Dependencies;
using com.github.zehsteam.FapEnergy.Extensions;
using com.github.zehsteam.FapEnergy.Helpers;
using com.github.zehsteam.FapEnergy.Managers;
using com.github.zehsteam.FapEnergy.NetcodePatcher;
using com.github.zehsteam.FapEnergy.Objects;
using com.github.zehsteam.FapEnergy.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Zehs")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyCopyright("Copyright © 2026 Zehs")]
[assembly: AssemblyDescription("Marketed as “fuel for maximum performance,” FAP keeps things vague, which is probably for the best. Need to power through work? FAP. Suddenly deep-cleaning your house at midnight? FAP. Considering texting your ex? Maybe put the can down first.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+0d95f599460d6e2e8c4441ac18668d82f556df9e")]
[assembly: AssemblyProduct("FapEnergy")]
[assembly: AssemblyTitle("com.github.zehsteam.FapEnergy")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
[CompilerGenerated]
internal sealed class <>z__ReadOnlyList<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T>
{
	int ICollection.Count => _items.Count;

	bool ICollection.IsSynchronized => false;

	object ICollection.SyncRoot => this;

	object IList.this[int index]
	{
		get
		{
			return _items[index];
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	bool IList.IsFixedSize => true;

	bool IList.IsReadOnly => true;

	int IReadOnlyCollection<T>.Count => _items.Count;

	T IReadOnlyList<T>.this[int index] => _items[index];

	int ICollection<T>.Count => _items.Count;

	bool ICollection<T>.IsReadOnly => true;

	T IList<T>.this[int index]
	{
		get
		{
			return _items[index];
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	public <>z__ReadOnlyList(List<T> items)
	{
		_items = items;
	}

	IEnumerator IEnumerable.GetEnumerator()
	{
		return ((IEnumerable)_items).GetEnumerator();
	}

	void ICollection.CopyTo(Array array, int index)
	{
		((ICollection)_items).CopyTo(array, index);
	}

	int IList.Add(object value)
	{
		throw new NotSupportedException();
	}

	void IList.Clear()
	{
		throw new NotSupportedException();
	}

	bool IList.Contains(object value)
	{
		return ((IList)_items).Contains(value);
	}

	int IList.IndexOf(object value)
	{
		return ((IList)_items).IndexOf(value);
	}

	void IList.Insert(int index, object value)
	{
		throw new NotSupportedException();
	}

	void IList.Remove(object value)
	{
		throw new NotSupportedException();
	}

	void IList.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}

	IEnumerator<T> IEnumerable<T>.GetEnumerator()
	{
		return ((IEnumerable<T>)_items).GetEnumerator();
	}

	void ICollection<T>.Add(T item)
	{
		throw new NotSupportedException();
	}

	void ICollection<T>.Clear()
	{
		throw new NotSupportedException();
	}

	bool ICollection<T>.Contains(T item)
	{
		return _items.Contains(item);
	}

	void ICollection<T>.CopyTo(T[] array, int arrayIndex)
	{
		_items.CopyTo(array, arrayIndex);
	}

	bool ICollection<T>.Remove(T item)
	{
		throw new NotSupportedException();
	}

	int IList<T>.IndexOf(T item)
	{
		return _items.IndexOf(item);
	}

	void IList<T>.Insert(int index, T item)
	{
		throw new NotSupportedException();
	}

	void IList<T>.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}
}
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 com.github.zehsteam.FapEnergy
{
	internal static class Assets
	{
		public static readonly string AssetBundleFileName = "fapenergy_assets";

		public static AssetBundle AssetBundle { get; private set; }

		public static bool IsLoaded { get; private set; }

		public static Item FapEnergyDrink { get; private set; }

		public static void Load()
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			string text = Path.Combine(directoryName, AssetBundleFileName);
			if (!File.Exists(text))
			{
				Logger.LogFatal("Failed to load assets. AssetBundle file could not be found at path \"" + text + "\". Make sure the \"" + AssetBundleFileName + "\" file is in the same folder as the mod's DLL file.");
			}
			else
			{
				AssetBundle = AssetBundle.LoadFromFile(text);
				if ((Object)(object)AssetBundle == (Object)null)
				{
					Logger.LogFatal("Failed to load assets. AssetBundle is null.");
					return;
				}
				OnAssetBundleLoaded(AssetBundle);
				IsLoaded = true;
			}
		}

		private static void OnAssetBundleLoaded(AssetBundle assetBundle)
		{
			FapEnergyDrink = LoadAsset<Item>("FapEnergyDrink", assetBundle);
		}

		private static T LoadAsset<T>(string name, AssetBundle assetBundle) where T : Object
		{
			if (string.IsNullOrWhiteSpace(name))
			{
				Logger.LogError("Failed to load asset of type \"" + typeof(T).Name + "\" from AssetBundle. Name is null or whitespace.");
				return default(T);
			}
			if ((Object)(object)assetBundle == (Object)null)
			{
				Logger.LogError("Failed to load asset of type \"" + typeof(T).Name + "\" with name \"" + name + "\" from AssetBundle. AssetBundle is null.");
				return default(T);
			}
			T val = assetBundle.LoadAsset<T>(name);
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError("Failed to load asset of type \"" + typeof(T).Name + "\" with name \"" + name + "\" from AssetBundle. No asset found with that type and name.");
				return default(T);
			}
			return val;
		}

		private static bool TryLoadAsset<T>(string name, AssetBundle assetBundle, out T asset) where T : Object
		{
			asset = LoadAsset<T>(name, assetBundle);
			return (Object)(object)asset != (Object)null;
		}
	}
	public static class FapEnergyKeys
	{
		public static readonly NamespacedKey<DawnItemInfo> FapEnergyDrink = NamespacedKey<DawnItemInfo>.From("fap_energy", "fap_energy_drink");
	}
	internal static class Logger
	{
		public static ManualLogSource ManualLogSource { get; private set; }

		public static bool IsExtendedLoggingEnabled => ConfigManager.Misc_ExtendedLogging?.Value ?? false;

		public static void Initialize(ManualLogSource manualLogSource)
		{
			ManualLogSource = manualLogSource;
		}

		public static void LogDebug(object data)
		{
			Log((LogLevel)32, data);
		}

		public static void LogInfo(object data, bool extended = false)
		{
			Log((LogLevel)16, data, extended);
		}

		public static void LogMessage(object data, bool extended = false)
		{
			Log((LogLevel)8, data, extended);
		}

		public static void LogWarning(object data, bool extended = false)
		{
			Log((LogLevel)4, data, extended);
		}

		public static void LogError(object data, bool extended = false)
		{
			Log((LogLevel)2, data, extended);
		}

		public static void LogFatal(object data, bool extended = false)
		{
			Log((LogLevel)1, data, extended);
		}

		public static void Log(LogLevel logLevel, object data, bool extended = false)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (!extended || IsExtendedLoggingEnabled)
			{
				ManualLogSource manualLogSource = ManualLogSource;
				if (manualLogSource != null)
				{
					manualLogSource.Log(logLevel, data);
				}
			}
		}
	}
	[BepInPlugin("com.github.zehsteam.FapEnergy", "FapEnergy", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class Plugin : BaseUnityPlugin
	{
		private readonly Harmony _harmony = new Harmony("com.github.zehsteam.FapEnergy");

		internal static Plugin Instance { get; private set; }

		private void Awake()
		{
			Instance = this;
			Logger.Initialize(Logger.CreateLogSource("com.github.zehsteam.FapEnergy"));
			Logger.LogInfo("FapEnergy has awoken!");
			_harmony.PatchAll(typeof(StartOfRound_Patches));
			_harmony.PatchAll(typeof(PlayerControllerB_Patches));
			Assets.Load();
			if (Assets.IsLoaded)
			{
				ConfigManager.Initialize(((BaseUnityPlugin)this).Config);
				PlayerControllerB_Patches.Initialize();
				RegisterItems();
				NetworkUtils.NetcodePatcherAwake();
			}
		}

		private void RegisterItems()
		{
			int spawnWeight = ConfigManager.FapEnergyDrink_SpawnWeight.Value;
			DawnLib.DefineItem(FapEnergyKeys.FapEnergyDrink, Assets.FapEnergyDrink, (Action<ItemInfoBuilder>)delegate(ItemInfoBuilder builder)
			{
				builder.DefineScrap((Action<ScrapBuilder>)delegate(ScrapBuilder scrapBuilder)
				{
					scrapBuilder.SetWeights((Action<WeightTableBuilder<DawnMoonInfo, SpawnWeightContext>>)delegate(WeightTableBuilder<DawnMoonInfo, SpawnWeightContext> weightTableBuilder)
					{
						weightTableBuilder.SetGlobalWeight(spawnWeight);
					});
				});
			});
			DawnLib.RegisterNetworkPrefab(Assets.FapEnergyDrink.spawnPrefab);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.github.zehsteam.FapEnergy";

		public const string PLUGIN_NAME = "FapEnergy";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace com.github.zehsteam.FapEnergy.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal static class PlayerControllerB_Patches
	{
		private static Color? _defaultSprintMeterUIColor;

		public static bool StaminaUIEffectsEnabled => ConfigManager.FapEnergyDrink_StaminaUIEffectsEnabled.Value;

		public static void Initialize()
		{
			FapEnergyStaminaEffect.OnStateChanged = (Action<FapEnergyStaminaEffect.States>)Delegate.Combine(FapEnergyStaminaEffect.OnStateChanged, new Action<FapEnergyStaminaEffect.States>(OnStaminaEffectStateChanged));
			Application.quitting += delegate
			{
				FapEnergyStaminaEffect.OnStateChanged = (Action<FapEnergyStaminaEffect.States>)Delegate.Remove(FapEnergyStaminaEffect.OnStateChanged, new Action<FapEnergyStaminaEffect.States>(OnStaminaEffectStateChanged));
			};
		}

		[HarmonyPatch("LateUpdate")]
		[HarmonyPostfix]
		private static void LateUpdate_Patch(PlayerControllerB __instance)
		{
			if (!PlayerUtils.IsLocalPlayer(__instance))
			{
				return;
			}
			FapEnergyStaminaEffect.Tick();
			if (FapEnergyStaminaEffect.State == FapEnergyStaminaEffect.States.InfiniteStamina)
			{
				__instance.sprintMeter = 1f;
			}
			if (FapEnergyStaminaEffect.State == FapEnergyStaminaEffect.States.StaminaDrained)
			{
				__instance.sprintMeter = 0f;
				if (StaminaUIEffectsEnabled)
				{
					float value = 1f - FapEnergyStaminaEffect.StateProgress;
					SetSprintMeterUIFillAmount(__instance.sprintMeterUI, value);
				}
			}
		}

		private static void OnStaminaEffectStateChanged(FapEnergyStaminaEffect.States state)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB localPlayerScript = PlayerUtils.LocalPlayerScript;
			if ((Object)(object)localPlayerScript == (Object)null)
			{
				return;
			}
			if (!_defaultSprintMeterUIColor.HasValue && FapEnergyStaminaEffect.PreviousState == FapEnergyStaminaEffect.States.None)
			{
				_defaultSprintMeterUIColor = ((Graphic)localPlayerScript.sprintMeterUI).color;
			}
			if (StaminaUIEffectsEnabled)
			{
				if (1 == 0)
				{
				}
				Color val = (Color)(state switch
				{
					FapEnergyStaminaEffect.States.InfiniteStamina => Color32.op_Implicit(new Color32((byte)151, (byte)187, (byte)36, byte.MaxValue)), 
					FapEnergyStaminaEffect.States.StaminaDrained => Color32.op_Implicit(new Color32(byte.MaxValue, (byte)0, (byte)0, byte.MaxValue)), 
					_ => ((??)_defaultSprintMeterUIColor) ?? Color32.op_Implicit(new Color32(byte.MaxValue, (byte)118, (byte)0, byte.MaxValue)), 
				});
				if (1 == 0)
				{
				}
				Color color = val;
				((Graphic)localPlayerScript.sprintMeterUI).color = color;
			}
		}

		private static void SetSprintMeterUIFillAmount(Image image, float value)
		{
			if (!((Object)(object)image == (Object)null))
			{
				image.fillAmount = Utils.Remap(value, 0f, 1f, 0.29767f, 0.911f);
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal static class StartOfRound_Patches
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Start_Patch()
		{
			ItemHelper.OnLobbyLoaded();
		}

		[HarmonyPatch("EndOfGame")]
		[HarmonyPostfix]
		private static void EndOfGame_Patch()
		{
			FapEnergyStaminaEffect.Reset();
		}

		[HarmonyPatch("OnLocalDisconnect")]
		[HarmonyPostfix]
		private static void OnLocalDisconnect_Patch()
		{
			FapEnergyStaminaEffect.Reset();
		}
	}
}
namespace com.github.zehsteam.FapEnergy.MonoBehaviours
{
	public abstract class AdvancedGrabbableObject : GrabbableObject
	{
		public int UniqueId { get; private set; }

		public string SaveKey => $"{((object)this).GetType().Name}_{UniqueId}";

		public virtual void Awake()
		{
			if (NetworkUtils.IsServer)
			{
				UniqueId = Random.Range(0, 1000000);
			}
		}

		public override void OnNetworkSpawn()
		{
			((NetworkBehaviour)this).OnNetworkSpawn();
			if (NetworkUtils.IsServer)
			{
				NetworkManager.Singleton.OnClientConnectedCallback += OnClientConnected_Server;
			}
		}

		public override void OnNetworkDespawn()
		{
			((NetworkBehaviour)this).OnNetworkDespawn();
			if (NetworkUtils.IsServer)
			{
				NetworkManager.Singleton.OnClientConnectedCallback -= OnClientConnected_Server;
			}
		}

		protected virtual void OnClientConnected_Server(ulong clientId)
		{
		}

		public override int GetItemDataToSave()
		{
			return UniqueId;
		}

		public override void LoadItemSaveData(int saveData)
		{
			((GrabbableObject)this).LoadItemSaveData(saveData);
			UniqueId = saveData;
		}

		protected override void __initializeVariables()
		{
			((GrabbableObject)this).__initializeVariables();
		}

		protected override void __initializeRpcs()
		{
			((GrabbableObject)this).__initializeRpcs();
		}

		protected internal override string __getTypeName()
		{
			return "AdvancedGrabbableObject";
		}
	}
	public class AdvancedNoisemakerProp : AdvancedGrabbableObject
	{
		[Space(20f)]
		[Header("Advanced Noisemaker Prop")]
		[Space(5f)]
		public AudioSourceGroup NoiseAudio;

		public WeightedList<AudioClip> NoiseSFX;

		[Space(10f)]
		public float MinVolume = 1f;

		public float MaxVolume = 1f;

		public float MinPitch = 1f;

		public float MaxPitch = 1f;

		[Space(10f)]
		public bool UseDynamicCooldown;

		[Space(10f)]
		public bool IsEnemyAudible = true;

		public float EnemyAudibleNoiseRange = 65f;

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			if (NoiseSFX != null && NoiseSFX.Count != 0 && NoiseSFX.TryGetRandomIndex(out var index))
			{
				PlaySound(index);
			}
		}

		public void PlaySound(int index)
		{
			if (NoiseSFX.IsValidIndex(index))
			{
				PlaySound_Rpc(index);
				PlaySound_Local(index);
			}
		}

		[Rpc(/*Could not decode attribute arguments.*/)]
		protected void PlaySound_Rpc(int index)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1)
				{
					RpcAttributeParams val = new RpcAttributeParams
					{
						RequireOwnership = false
					};
					RpcParams val2 = default(RpcParams);
					FastBufferWriter val3 = ((NetworkBehaviour)this).__beginSendRpc(3275817297u, val2, val, (SendTo)5, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val3, index);
					((NetworkBehaviour)this).__endSendRpc(ref val3, 3275817297u, val2, val, (SendTo)5, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1)
				{
					((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
					PlaySound_Local(index);
				}
			}
		}

		public void PlaySound_Local(int index)
		{
			if (NoiseSFX.TryGet(index, out var value))
			{
				PlaySound_Local(value);
				OnPlayedSoundFromIndex(index);
			}
		}

		public float PlaySound_Local(AudioClip clip)
		{
			if ((Object)(object)clip == (Object)null)
			{
				return 0f;
			}
			if (UseDynamicCooldown)
			{
				((GrabbableObject)this).currentUseCooldown = clip.length;
			}
			NoiseAudio.Stop();
			float num = Random.Range(MinVolume, MaxVolume);
			float pitch = Random.Range(MinPitch, MaxPitch);
			NoiseAudio.Volume = num;
			NoiseAudio.Pitch = pitch;
			NoiseAudio.PlayOneShot(clip);
			WalkieTalkie.TransmitOneShotAudio(NoiseAudio.Main, clip, num);
			if (IsEnemyAudible)
			{
				((GrabbableObject)(object)this).MakeEnemyAudibleNoise(EnemyAudibleNoiseRange, num, MinVolume);
			}
			return clip.length;
		}

		protected virtual void OnPlayedSoundFromIndex(int index)
		{
		}

		protected override void __initializeVariables()
		{
			base.__initializeVariables();
		}

		protected override void __initializeRpcs()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			((NetworkBehaviour)this).__registerRpc(3275817297u, new RpcReceiveHandler(__rpc_handler_3275817297), "PlaySound_Rpc");
			base.__initializeRpcs();
		}

		private static void __rpc_handler_3275817297(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int index = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref index);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((AdvancedNoisemakerProp)(object)target).PlaySound_Rpc(index);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "AdvancedNoisemakerProp";
		}
	}
	public class FapEnergyDrink : AdvancedNoisemakerProp
	{
		private static readonly List<FapEnergyDrink> _instances = new List<FapEnergyDrink>();

		[Space(20f)]
		[Header("Fap Energy Drink")]
		[Space(5f)]
		public AudioSourceGroup RandomMusicAudio;

		public AudioClip[] RandomMusic = Array.Empty<AudioClip>();

		[HideInInspector]
		public NetworkVariable<bool> UsedInfiniteStamina = new NetworkVariable<bool>(false, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)1);

		private float _randomMusicTimer;

		public bool InfiniteStaminaEffectEnabled => ConfigManager.FapEnergyDrink_InfiniteStaminaEffectEnabled.Value;

		public bool RandomMusicEnabled => ConfigManager.FapEnergyDrink_RandomMusicEnabled.Value;

		public float RandomMusicChance => ConfigManager.FapEnergyDrink_RandomMusicChance.Value;

		public float RandomMusicRollChanceCooldown => ConfigManager.FapEnergyDrink_RandomMusicRollChanceCooldown.Value;

		public float RandomMusicSuccessMinCooldown => ConfigManager.FapEnergyDrink_RandomMusicSuccessMinCooldown.Value;

		public float RandomMusicSuccessMaxCooldown => ConfigManager.FapEnergyDrink_RandomMusicSuccessMaxCooldown.Value;

		public float RandomMusicSuccessCooldown => Random.Range(RandomMusicSuccessMinCooldown, RandomMusicSuccessMaxCooldown);

		public bool RandomMusicOnlyAllowSingleInstance => ConfigManager.FapEnergyDrink_RandomMusicOnlyAllowSingleInstance.Value;

		public override void Awake()
		{
			base.Awake();
			_randomMusicTimer = RandomMusicRollChanceCooldown;
		}

		private void OnEnable()
		{
			if (!_instances.Contains(this))
			{
				_instances.Add(this);
			}
		}

		private void OnDisable()
		{
			_instances.Remove(this);
		}

		public override void Update()
		{
			((GrabbableObject)this).Update();
			RandomMusicTick_Server();
		}

		private void RandomMusicTick_Server()
		{
			if (!NetworkUtils.IsServer || !RandomMusicEnabled || RandomMusicAudio.IsPlaying || (RandomMusicOnlyAllowSingleInstance && IsAnyInstancePlayingRandomMusic()) || ((GrabbableObject)this).isHeld || !((GrabbableObject)this).isInFactory || ((GrabbableObject)this).isInShipRoom || ((GrabbableObject)this).isInElevator)
			{
				return;
			}
			if (_randomMusicTimer <= 0f)
			{
				if (Utils.RollPercentChance(RandomMusicChance))
				{
					PlayRandomMusic();
					_randomMusicTimer = RandomMusicSuccessCooldown;
				}
				else
				{
					_randomMusicTimer = RandomMusicRollChanceCooldown;
				}
			}
			else
			{
				_randomMusicTimer -= Time.deltaTime;
			}
		}

		private bool IsAnyInstancePlayingRandomMusic()
		{
			return _instances.Any((FapEnergyDrink x) => x.RandomMusicAudio.IsPlaying);
		}

		private void PlayRandomMusic()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			int index = Random.Range(0, RandomMusic.Length);
			PlayRandomMusic_Rpc(index);
		}

		[Rpc(/*Could not decode attribute arguments.*/)]
		private void PlayRandomMusic_Rpc(int index, RpcParams rpcParams = default(RpcParams))
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1)
			{
				RpcAttributeParams val = new RpcAttributeParams
				{
					RequireOwnership = false
				};
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendRpc(1625127774u, rpcParams, val, (SendTo)6, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, index);
				((NetworkBehaviour)this).__endSendRpc(ref val2, 1625127774u, rpcParams, val, (SendTo)6, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1)
			{
				((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
				ulong senderClientId = rpcParams.Receive.SenderClientId;
				if (index >= 0 && index < RandomMusic.Length)
				{
					AudioClip clip = RandomMusic[index];
					RandomMusicAudio.Play(clip);
				}
			}
		}

		[Rpc(/*Could not decode attribute arguments.*/)]
		private void StopRandomMusic_Rpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1)
				{
					RpcAttributeParams val = default(RpcAttributeParams);
					RpcParams val2 = default(RpcParams);
					FastBufferWriter val3 = ((NetworkBehaviour)this).__beginSendRpc(50365314u, val2, val, (SendTo)6, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendRpc(ref val3, 50365314u, val2, val, (SendTo)6, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1)
				{
					((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
					RandomMusicAudio.Stop();
				}
			}
		}

		public override void GrabItem()
		{
			((GrabbableObject)this).GrabItem();
			if (((NetworkBehaviour)this).IsOwner)
			{
				StopRandomMusic_Rpc();
			}
		}

		public override void SetControlTipsForItem()
		{
			string[] array = ((!UsedInfiniteStamina.Value) ? new string[1] { "Drink : [LMB]".RichColor("#97bb24") } : new string[1] { "Interact : [LMB]" });
			HUDManager.Instance.ChangeControlTipMultiple(array, true, ((GrabbableObject)this).itemProperties);
		}

		public override void LoadItemSaveData(int saveData)
		{
			base.LoadItemSaveData(saveData);
			UsedInfiniteStamina.Value = GameSaveFileHelper.Load(base.SaveKey + "_UsedInfiniteStamina", defaultValue: false);
		}

		public override int GetItemDataToSave()
		{
			GameSaveFileHelper.Save(base.SaveKey + "_UsedInfiniteStamina", UsedInfiniteStamina.Value);
			return base.GetItemDataToSave();
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			base.ItemActivate(used, buttonDown);
			if (!StartOfRound.Instance.inShipPhase && !StartOfRound.Instance.shipIsLeaving)
			{
				TryUseInfiniteStamina();
			}
		}

		private void TryUseInfiniteStamina()
		{
			if (InfiniteStaminaEffectEnabled && FapEnergyStaminaEffect.State != FapEnergyStaminaEffect.States.InfiniteStamina && !UsedInfiniteStamina.Value)
			{
				UsedInfiniteStamina.Value = true;
				FapEnergyStaminaEffect.Apply();
				((GrabbableObject)this).SetControlTipsForItem();
			}
		}

		private void ApplyConfigSettings()
		{
		}

		public static void OnConfigSettingsChanged()
		{
			foreach (FapEnergyDrink instance in _instances)
			{
				instance.ApplyConfigSettings();
			}
		}

		protected override void __initializeVariables()
		{
			if (UsedInfiniteStamina == null)
			{
				throw new Exception("FapEnergyDrink.UsedInfiniteStamina cannot be null. All NetworkVariableBase instances must be initialized.");
			}
			((NetworkVariableBase)UsedInfiniteStamina).Initialize((NetworkBehaviour)(object)this);
			((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)UsedInfiniteStamina, "UsedInfiniteStamina");
			((NetworkBehaviour)this).NetworkVariableFields.Add((NetworkVariableBase)(object)UsedInfiniteStamina);
			base.__initializeVariables();
		}

		protected override void __initializeRpcs()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			((NetworkBehaviour)this).__registerRpc(1625127774u, new RpcReceiveHandler(__rpc_handler_1625127774), "PlayRandomMusic_Rpc");
			((NetworkBehaviour)this).__registerRpc(50365314u, new RpcReceiveHandler(__rpc_handler_50365314), "StopRandomMusic_Rpc");
			base.__initializeRpcs();
		}

		private static void __rpc_handler_1625127774(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int index = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref index);
				RpcParams ext = rpcParams.Ext;
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((FapEnergyDrink)(object)target).PlayRandomMusic_Rpc(index, ext);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_50365314(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((FapEnergyDrink)(object)target).StopRandomMusic_Rpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "FapEnergyDrink";
		}
	}
}
namespace com.github.zehsteam.FapEnergy.Objects
{
	internal static class FapEnergyStaminaEffect
	{
		public enum States
		{
			None,
			InfiniteStamina,
			StaminaDrained
		}

		public static Action<States> OnStateChanged;

		private static float _timeSinceStartedState;

		public static States State { get; private set; }

		public static States PreviousState { get; private set; }

		public static float ElapsedStateTime => Time.realtimeSinceStartup - _timeSinceStartedState;

		public static float StateProgress { get; private set; }

		public static void Apply()
		{
			SetState(States.InfiniteStamina);
		}

		public static void Reset()
		{
			SetState(States.None);
		}

		private static void SetState(States state)
		{
			PreviousState = State;
			State = state;
			StateProgress = 0f;
			OnStateChanged?.Invoke(state);
			_timeSinceStartedState = Time.realtimeSinceStartup;
		}

		public static void Tick()
		{
			switch (State)
			{
			case States.None:
				break;
			case States.InfiniteStamina:
				InfiniteStamina_Tick();
				break;
			case States.StaminaDrained:
				StaminaDrained_Tick();
				break;
			}
		}

		private static void InfiniteStamina_Tick()
		{
			float value = ConfigManager.FapEnergyDrink_InfiniteStaminaDuration.Value;
			StateProgress = ElapsedStateTime / value;
			if (ElapsedStateTime > value)
			{
				SetState(States.StaminaDrained);
			}
		}

		private static void StaminaDrained_Tick()
		{
			float value = ConfigManager.FapEnergyDrink_StaminaDrainedDuration.Value;
			StateProgress = ElapsedStateTime / value;
			if (ElapsedStateTime > value)
			{
				Reset();
			}
		}
	}
	[Serializable]
	public class AudioSourceGroup
	{
		public AudioSource Main;

		public AudioSource Far;

		public bool IsPlaying => Main.isPlaying;

		public float Volume
		{
			get
			{
				return Main.volume;
			}
			set
			{
				Main.volume = value;
				AudioSource far = Far;
				if (far != null)
				{
					far.volume = value;
				}
			}
		}

		public float Pitch
		{
			get
			{
				return Main.pitch;
			}
			set
			{
				Main.pitch = value;
				AudioSource far = Far;
				if (far != null)
				{
					far.pitch = value;
				}
			}
		}

		public AudioClip Clip
		{
			get
			{
				return Main.clip;
			}
			set
			{
				Main.clip = value;
				AudioSource far = Far;
				if (far != null)
				{
					far.clip = value;
				}
			}
		}

		public void Play()
		{
			Main.Play();
			AudioSource far = Far;
			if (far != null)
			{
				far.Play();
			}
		}

		public void Play(AudioClip clip)
		{
			if (IsPlaying)
			{
				Stop();
			}
			Clip = clip;
			Play();
		}

		public void Stop()
		{
			Main.Stop();
			AudioSource far = Far;
			if (far != null)
			{
				far.Stop();
			}
		}

		public void PlayOneShot(AudioClip clip)
		{
			PlayOneShot(clip, Volume);
		}

		public float PlayOneShot(AudioClip clip, float volumeScale)
		{
			if ((Object)(object)clip == (Object)null)
			{
				return 0f;
			}
			Main.PlayOneShot(clip, volumeScale);
			AudioSource far = Far;
			if (far != null)
			{
				far.PlayOneShot(clip, volumeScale);
			}
			return clip.length;
		}
	}
	[Serializable]
	public class WeightedList<T>
	{
		public List<WeightedItem<T>> List = new List<WeightedItem<T>>();

		public IReadOnlyList<WeightedItem<T>> ValidList
		{
			get
			{
				List<WeightedItem<T>> list = new List<WeightedItem<T>>();
				list.AddRange(List.Where((WeightedItem<T> x) => x.Weight > 0));
				return new <>z__ReadOnlyList<WeightedItem<T>>(list);
			}
		}

		public int Count => ValidList.Count;

		public int GetRandomIndex()
		{
			if (List == null || List.Count == 0 || ValidList.Count == 0)
			{
				return -1;
			}
			return Utils.GetRandomIndexFromWeightList(ValidList.Select((WeightedItem<T> x) => x.Weight).ToList());
		}

		public bool TryGetRandomIndex(out int index)
		{
			index = GetRandomIndex();
			return IsValidIndex(index);
		}

		public T GetRandom()
		{
			if (!TryGetRandom(out var value))
			{
				return default(T);
			}
			return value;
		}

		public bool TryGetRandom(out T value)
		{
			if (!TryGetRandomIndex(out var index))
			{
				value = default(T);
				return false;
			}
			value = ValidList[index].Value;
			return true;
		}

		public bool TryGet(int index, out T value)
		{
			if (!IsValidIndex(index))
			{
				value = default(T);
				return false;
			}
			value = ValidList[index].Value;
			return true;
		}

		public bool IsValidIndex(int index)
		{
			return index >= 0 && index < ValidList.Count;
		}
	}
	[Serializable]
	public class WeightedItem<T>
	{
		public T Value;

		public int Weight;

		public WeightedItem(T value, int weight)
		{
			Value = value;
			Weight = weight;
		}
	}
}
namespace com.github.zehsteam.FapEnergy.Managers
{
	internal static class ConfigManager
	{
		public static ConfigFile ConfigFile { get; private set; }

		public static ConfigEntry<bool> Misc_ExtendedLogging { get; private set; }

		public static ConfigEntry<int> FapEnergyDrink_SpawnWeight { get; private set; }

		public static ConfigEntry<bool> FapEnergyDrink_InfiniteStaminaEffectEnabled { get; private set; }

		public static ConfigEntry<float> FapEnergyDrink_InfiniteStaminaDuration { get; private set; }

		public static ConfigEntry<float> FapEnergyDrink_StaminaDrainedDuration { get; private set; }

		public static ConfigEntry<bool> FapEnergyDrink_StaminaUIEffectsEnabled { get; private set; }

		public static ConfigEntry<bool> FapEnergyDrink_RandomMusicEnabled { get; private set; }

		public static ConfigEntry<float> FapEnergyDrink_RandomMusicChance { get; private set; }

		public static ConfigEntry<float> FapEnergyDrink_RandomMusicRollChanceCooldown { get; private set; }

		public static ConfigEntry<float> FapEnergyDrink_RandomMusicSuccessMinCooldown { get; private set; }

		public static ConfigEntry<float> FapEnergyDrink_RandomMusicSuccessMaxCooldown { get; private set; }

		public static ConfigEntry<bool> FapEnergyDrink_RandomMusicOnlyAllowSingleInstance { get; private set; }

		public static void Initialize(ConfigFile configFile)
		{
			ConfigFile = configFile;
			BindConfigs();
		}

		private static void BindConfigs()
		{
			ConfigHelper.SkipAutoGen();
			Misc_ExtendedLogging = ConfigHelper.Bind("Misc", "ExtendedLogging", defaultValue: false, "Enable extended logging.");
			FapEnergyDrink_SpawnWeight = ConfigHelper.Bind("Fap Energy Drink", "SpawnWeight", 20, "How likely this item will spawn.");
			FapEnergyDrink_SpawnWeight.SettingChanged += delegate
			{
				ItemHelper.UpdateScrapRarity(Assets.FapEnergyDrink, FapEnergyDrink_SpawnWeight.Value);
			};
			FapEnergyDrink_InfiniteStaminaEffectEnabled = ConfigHelper.Bind("Fap Energy Drink", "InfiniteStaminaEnabled", defaultValue: true, "If enabled, using this item will temporary give you inifinte stamina.");
			FapEnergyDrink_InfiniteStaminaDuration = ConfigHelper.Bind("Fap Energy Drink", "InfiniteStaminaDuration", 30f, "The duration in seconds you will have infinite stamina for.");
			FapEnergyDrink_StaminaDrainedDuration = ConfigHelper.Bind("Fap Energy Drink", "StaminaDrainedDuration", 10f, "The duration in seconds your stamina will be completely drained for after having infinite stamina.");
			FapEnergyDrink_StaminaUIEffectsEnabled = ConfigHelper.Bind("Fap Energy Drink", "StaminaUIEffectsEnabled", defaultValue: true, "If enabled, infinite/drained stamina will change the stamina UI.");
			FapEnergyDrink_RandomMusicEnabled = ConfigHelper.Bind("Fap Energy Drink", "RandomMusicEnabled", defaultValue: true, "If enabled, this item will have a chance to randomly play music while inside the facility.");
			FapEnergyDrink_RandomMusicChance = ConfigHelper.Bind("Fap Energy Drink", "RandomMusicChance", 10f, "The percent chance for random music to start playing.");
			FapEnergyDrink_RandomMusicRollChanceCooldown = ConfigHelper.Bind("Fap Energy Drink", "RandomMusicRollChanceCooldown", 15f, "The cooldown in seconds between each time RandomMusicChance is rolled.");
			FapEnergyDrink_RandomMusicSuccessMinCooldown = ConfigHelper.Bind("Fap Energy Drink", "RandomMusicSuccessMinCooldown", 30f, "The minimum cooldown in seconds after random music successfully plays.");
			FapEnergyDrink_RandomMusicSuccessMaxCooldown = ConfigHelper.Bind("Fap Energy Drink", "RandomMusicSuccessMaxCooldown", 60f, "The maximum cooldown in seconds after random music successfully plays.");
			FapEnergyDrink_RandomMusicOnlyAllowSingleInstance = ConfigHelper.Bind("Fap Energy Drink", "RandomMusicOnlyAllowSingleInstance", defaultValue: false, "If enabled, will only allow a single item instance to play random music at a time.");
		}
	}
}
namespace com.github.zehsteam.FapEnergy.Helpers
{
	internal static class ConfigHelper
	{
		public static void SkipAutoGen()
		{
			if (LethalConfigProxy.IsInstalled)
			{
				LethalConfigProxy.SkipAutoGen();
			}
		}

		public static void AddButton(string section, string name, string buttonText, string description, Action callback)
		{
			if (LethalConfigProxy.IsInstalled)
			{
				LethalConfigProxy.AddButton(section, name, buttonText, description, callback);
			}
		}

		public static ConfigEntry<T> Bind<T>(string section, string key, T defaultValue, string description, bool requiresRestart = false, AcceptableValueBase acceptableValues = null, Action<T> settingChanged = null, ConfigFile configFile = null)
		{
			if (configFile == null)
			{
				configFile = ConfigManager.ConfigFile;
			}
			ConfigEntry<T> configEntry = configFile.Bind(section, key, defaultValue, description, acceptableValues);
			if (settingChanged != null)
			{
				configEntry.SettingChanged += delegate
				{
					settingChanged?.Invoke(configEntry.Value);
				};
			}
			if (LethalConfigProxy.IsInstalled)
			{
				LethalConfigProxy.AddConfig<T>(configEntry, requiresRestart);
			}
			return configEntry;
		}
	}
	internal static class GameSaveFileHelper
	{
		private static string GetCurrentSaveFilePath()
		{
			if ((Object)(object)GameNetworkManager.Instance == (Object)null)
			{
				Logger.LogWarning("GameSaveFileHelper: GetCurrentSaveFilePath() GameNetworkManager instance is null. Returning an empty string.");
				return string.Empty;
			}
			return GameNetworkManager.Instance.currentSaveFileName;
		}

		public static bool KeyExists(string key)
		{
			if (!NetworkUtils.IsServer)
			{
				return false;
			}
			return ES3.KeyExists(key, GetCurrentSaveFilePath());
		}

		public static T Load<T>(string key, T defaultValue = default(T))
		{
			if (!NetworkUtils.IsServer)
			{
				return defaultValue;
			}
			if (TryLoad<T>(key, out var value))
			{
				return value;
			}
			return defaultValue;
		}

		public static bool TryLoad<T>(string key, out T value)
		{
			if (!NetworkUtils.IsServer)
			{
				value = default(T);
				return false;
			}
			value = ES3.Load<T>(key, GetCurrentSaveFilePath());
			return value != null;
		}

		public static bool Save<T>(string key, T value)
		{
			if (!NetworkUtils.IsServer)
			{
				return false;
			}
			ES3.Save<T>(key, value, GetCurrentSaveFilePath());
			return true;
		}
	}
	internal static class ItemHelper
	{
		private static readonly Dictionary<Item, int> _spawnWeightsToUpdate = new Dictionary<Item, int>();

		public static void UpdateScrapRarity(Item item, int rarity)
		{
			if ((Object)(object)item == (Object)null)
			{
				Logger.LogError("[ItemHelper] Failed to update scrap item rarity. Item is null.");
				return;
			}
			if ((Object)(object)StartOfRound.Instance == (Object)null)
			{
				Logger.LogWarning("[ItemHelper] Failed to update scrap item rarity. StartOfRound instance is null.");
				_spawnWeightsToUpdate[item] = rarity;
				return;
			}
			SelectableLevel[] levels = StartOfRound.Instance.levels;
			foreach (SelectableLevel val in levels)
			{
				foreach (SpawnableItemWithRarity item2 in val.spawnableScrap)
				{
					if (!((Object)(object)item2.spawnableItem != (Object)(object)item))
					{
						item2.rarity = rarity;
						Logger.LogInfo(string.Format("[{0}] Updated \"{1}\" scrap item rarity to {2} on \"{3}\".", "ItemHelper", item.itemName, rarity, val.PlanetName));
					}
				}
			}
		}

		public static void OnLobbyLoaded()
		{
			if (_spawnWeightsToUpdate.Count == 0)
			{
				return;
			}
			foreach (KeyValuePair<Item, int> item in _spawnWeightsToUpdate)
			{
				UpdateScrapRarity(item.Key, item.Value);
			}
			_spawnWeightsToUpdate.Clear();
		}
	}
	internal static class NetworkUtils
	{
		public static bool IsConnected
		{
			get
			{
				NetworkManager singleton = NetworkManager.Singleton;
				return singleton != null && singleton.IsConnectedClient;
			}
		}

		public static bool IsServer
		{
			get
			{
				NetworkManager singleton = NetworkManager.Singleton;
				return singleton != null && singleton.IsServer;
			}
		}

		public static ulong LocalClientId
		{
			get
			{
				NetworkManager singleton = NetworkManager.Singleton;
				return (singleton != null) ? singleton.LocalClientId : 0;
			}
		}

		public static int ConnectedPlayerCount => GameNetworkManager.Instance?.connectedPlayers ?? 0;

		public static bool IsLocalClientId(ulong clientId)
		{
			return clientId == LocalClientId;
		}

		public static bool HasClient(ulong clientId)
		{
			if ((Object)(object)NetworkManager.Singleton == (Object)null)
			{
				return false;
			}
			return NetworkManager.Singleton.ConnectedClients.ContainsKey(clientId);
		}

		public static bool IsNetworkPrefab(GameObject prefab)
		{
			IReadOnlyList<NetworkPrefab> prefabs = NetworkManager.Singleton.NetworkConfig.Prefabs.Prefabs;
			return prefabs.Any((NetworkPrefab x) => (Object)(object)x.Prefab == (Object)(object)prefab);
		}

		public static bool AddNetworkPrefab(GameObject prefab)
		{
			if ((Object)(object)prefab == (Object)null)
			{
				Logger.LogError("Failed to register network prefab. GameObject is null.");
				return false;
			}
			if ((Object)(object)NetworkManager.Singleton == (Object)null)
			{
				Logger.LogError("Failed to register network prefab. NetworkManager Singleton is null.");
				return false;
			}
			NetworkManager.Singleton.AddNetworkPrefab(prefab);
			Logger.LogInfo("Registered \"" + ((Object)prefab).name + "\" network prefab.");
			return true;
		}

		public static void NetcodePatcherAwake()
		{
			try
			{
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				Type[] types = executingAssembly.GetTypes();
				Type[] array = types;
				foreach (Type type in array)
				{
					MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
					MethodInfo[] array2 = methods;
					foreach (MethodInfo methodInfo in array2)
					{
						try
						{
							object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
							if (customAttributes.Length != 0)
							{
								try
								{
									methodInfo.Invoke(null, null);
								}
								catch (TargetInvocationException ex)
								{
									Logger.LogWarning("Failed to invoke method " + methodInfo.Name + ": " + ex.Message);
								}
							}
						}
						catch (Exception ex2)
						{
							Logger.LogWarning("Error processing method " + methodInfo.Name + " in type " + type.Name + ": " + ex2.Message);
						}
					}
				}
			}
			catch (Exception ex3)
			{
				Logger.LogError("An error occurred in NetcodePatcherAwake: " + ex3.Message);
			}
		}
	}
	internal static class PlayerUtils
	{
		public static PlayerControllerB LocalPlayerScript => GameNetworkManager.Instance?.localPlayerController ?? null;

		public static PlayerControllerB[] AllPlayerScripts => StartOfRound.Instance?.allPlayerScripts ?? Array.Empty<PlayerControllerB>();

		public static PlayerControllerB[] ConnectedPlayerScripts => AllPlayerScripts.Where(IsConnected).ToArray();

		public static PlayerControllerB[] AlivePlayerScripts => ConnectedPlayerScripts.Where((PlayerControllerB x) => !x.isPlayerDead).ToArray();

		public static PlayerControllerB[] DeadPlayerScripts => ConnectedPlayerScripts.Where((PlayerControllerB x) => x.isPlayerDead).ToArray();

		public static bool IsLocalPlayer(PlayerControllerB playerScript)
		{
			if ((Object)(object)playerScript == (Object)null)
			{
				return false;
			}
			return (Object)(object)playerScript == (Object)(object)LocalPlayerScript;
		}

		public static bool IsConnected(PlayerControllerB playerScript)
		{
			if ((Object)(object)playerScript == (Object)null)
			{
				return false;
			}
			return playerScript.isPlayerControlled || playerScript.isPlayerDead;
		}

		public static PlayerControllerB GetPlayerScriptByClientId(ulong clientId)
		{
			return ((IEnumerable<PlayerControllerB>)ConnectedPlayerScripts).FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB playerScript) => playerScript.actualClientId == clientId));
		}

		public static bool TryGetPlayerScriptByClientId(ulong clientId, out PlayerControllerB playerScript)
		{
			playerScript = GetPlayerScriptByClientId(clientId);
			return (Object)(object)playerScript != (Object)null;
		}

		public static PlayerControllerB GetPlayerScriptByPlayerId(int playerId)
		{
			if (playerId < 0 || playerId > ConnectedPlayerScripts.Length - 1)
			{
				return null;
			}
			return ConnectedPlayerScripts[playerId];
		}

		public static bool TryGetPlayerScriptByPlayerId(int playerId, out PlayerControllerB playerScript)
		{
			playerScript = GetPlayerScriptByPlayerId(playerId);
			return (Object)(object)playerScript != (Object)null;
		}

		public static PlayerControllerB GetPlayerScriptByUsername(string username)
		{
			PlayerControllerB val = null;
			PlayerControllerB[] source = ConnectedPlayerScripts.OrderByDescending((PlayerControllerB x) => x.playerUsername.Length).ToArray();
			val = ((IEnumerable<PlayerControllerB>)source).FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB x) => x.playerUsername.StartsWith(username, StringComparison.OrdinalIgnoreCase)));
			if (val == null)
			{
				val = ((IEnumerable<PlayerControllerB>)source).FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB x) => x.playerUsername.Contains(username, StringComparison.OrdinalIgnoreCase)));
			}
			return val;
		}

		public static bool TryGetPlayerScriptByUsername(string username, out PlayerControllerB playerScript)
		{
			playerScript = GetPlayerScriptByUsername(username);
			return (Object)(object)playerScript != (Object)null;
		}

		public static PlayerControllerB GetRandomPlayerScript(PlayerControllerB[] playerScripts, bool excludeLocal = false)
		{
			if (playerScripts == null || playerScripts.Length == 0)
			{
				return null;
			}
			PlayerControllerB[] array = playerScripts.Where((PlayerControllerB playerScript) => !excludeLocal || !IsLocalPlayer(playerScript)).ToArray();
			if (array.Length == 0)
			{
				return null;
			}
			return array[Random.Range(0, array.Length)];
		}

		public static bool TryGetRandomPlayerScript(PlayerControllerB[] playerScripts, out PlayerControllerB playerScript, bool excludeLocal = false)
		{
			playerScript = GetRandomPlayerScript(playerScripts, excludeLocal);
			return (Object)(object)playerScript != (Object)null;
		}
	}
	internal static class Utils
	{
		public static bool RollPercentChance(float percent)
		{
			if (percent <= 0f)
			{
				return false;
			}
			if (percent >= 100f)
			{
				return true;
			}
			return Random.value * 100f <= percent;
		}

		public static int GetRandomIndexFromWeightList(List<int> weightList)
		{
			List<(int, int)> list = new List<(int, int)>();
			for (int i = 0; i < weightList.Count; i++)
			{
				int num = weightList[i];
				if (num > 0)
				{
					list.Add((i, num));
				}
			}
			int num2 = 0;
			foreach (var item4 in list)
			{
				int item = item4.Item2;
				num2 += item;
			}
			if (num2 == 0)
			{
				return -1;
			}
			int num3 = Random.Range(0, num2);
			int num4 = 0;
			foreach (var item5 in list)
			{
				int item2 = item5.Item1;
				int item3 = item5.Item2;
				num4 += item3;
				if (num3 < num4)
				{
					return item2;
				}
			}
			throw new InvalidOperationException("Weights are not properly specified.");
		}

		public static float Remap(float value, float fromMin, float fromMax, float toMin, float toMax)
		{
			return Mathf.Lerp(toMin, toMax, Mathf.InverseLerp(fromMin, fromMax, value));
		}
	}
}
namespace com.github.zehsteam.FapEnergy.Extensions
{
	internal static class ConfigFileExtensions
	{
		public static ConfigEntry<T> Bind<T>(this ConfigFile configFile, string section, string key, T defaultValue, string description, AcceptableValueBase acceptableValues)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			if (acceptableValues == null)
			{
				return configFile.Bind<T>(section, key, defaultValue, description);
			}
			return configFile.Bind<T>(section, key, defaultValue, new ConfigDescription(description, acceptableValues, Array.Empty<object>()));
		}
	}
	internal static class GrabbableObjectExtensions
	{
		public static void MakeEnemyAudibleNoise(this GrabbableObject grabbableObject, float noiseRange, float noiseLoudness, float minNoiseLoudness)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)grabbableObject == (Object)null))
			{
				bool flag = grabbableObject.isInElevator && StartOfRound.Instance.hangarDoorsClosed;
				RoundManager.Instance.PlayAudibleNoise(((Component)grabbableObject).transform.position, noiseRange, noiseLoudness, 0, flag, 0);
				if (minNoiseLoudness >= 0.6f && (Object)(object)grabbableObject.playerHeldBy != (Object)null)
				{
					grabbableObject.playerHeldBy.timeSinceMakingLoudNoise = 0f;
				}
			}
		}
	}
	internal static class StringExtensions
	{
		public static bool IsHexColor(this string s)
		{
			return Regex.IsMatch(s, "^#?([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$");
		}

		public static string RichColor(this string s, string colorHex)
		{
			if (string.IsNullOrWhiteSpace(colorHex))
			{
				colorHex = "#FFFFFF";
			}
			return "<color=" + colorHex + ">" + s + "</color>";
		}
	}
}
namespace com.github.zehsteam.FapEnergy.Dependencies
{
	internal static class LethalConfigProxy
	{
		public const string PLUGIN_GUID = "ainavt.lc.lethalconfig";

		public static bool IsInstalled => Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig");

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void SkipAutoGen()
		{
			LethalConfigManager.SkipAutoGen();
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static object AddConfig<T>(ConfigEntry<T> configEntry, bool requiresRestart = false)
		{
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Expected O, but got Unknown
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Expected O, but got Unknown
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Expected O, but got Unknown
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Expected O, but got Unknown
			if (typeof(T).IsEnum)
			{
				MethodInfo methodInfo = AccessTools.Method(typeof(LethalConfigProxy), "AddEnumDropdown", (Type[])null, (Type[])null);
				MethodInfo methodInfo2 = methodInfo.MakeGenericMethod(typeof(T));
				object? obj = methodInfo2.Invoke(null, new object[2] { configEntry, requiresRestart });
				return (obj is BaseConfigItem) ? obj : null;
			}
			AcceptableValueBase acceptableValues = ((ConfigEntryBase)configEntry).Description.AcceptableValues;
			if (acceptableValues != null)
			{
				if (acceptableValues is AcceptableValueRange<float> || acceptableValues is AcceptableValueRange<int>)
				{
					return AddConfigSlider<T>(configEntry, requiresRestart);
				}
				if (acceptableValues is AcceptableValueList<string>)
				{
					return AddConfigDropdown<T>(configEntry, requiresRestart);
				}
			}
			if (configEntry is ConfigEntry<string> val && IsConfigEntryForHexColor(val))
			{
				return AddConfigItem((BaseConfigItem)new HexColorInputFieldConfigItem(val, requiresRestart));
			}
			if (1 == 0)
			{
			}
			BaseConfigItem result;
			if (!(configEntry is ConfigEntry<int> val2))
			{
				if (!(configEntry is ConfigEntry<float> val3))
				{
					if (!(configEntry is ConfigEntry<bool> val4))
					{
						if (!(configEntry is ConfigEntry<string> val5))
						{
							throw new NotSupportedException($"Unsupported type: {typeof(T)}");
						}
						result = AddConfigItem((BaseConfigItem)new TextInputFieldConfigItem(val5, requiresRestart));
					}
					else
					{
						result = AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(val4, requiresRestart));
					}
				}
				else
				{
					result = AddConfigItem((BaseConfigItem)new FloatInputFieldConfigItem(val3, requiresRestart));
				}
			}
			else
			{
				result = AddConfigItem((BaseConfigItem)new IntInputFieldConfigItem(val2, requiresRestart));
			}
			if (1 == 0)
			{
			}
			return result;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static object AddButton(string section, string name, string buttonText, string description, Action callback)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			BaseConfigItem configItem = (BaseConfigItem)new GenericButtonConfigItem(section, name, description, buttonText, (GenericButtonHandler)delegate
			{
				callback?.Invoke();
			});
			return AddConfigItem(configItem);
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private static BaseConfigItem AddConfigSlider<T>(ConfigEntry<T> configEntry, bool requiresRestart = false)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			if (1 == 0)
			{
			}
			BaseConfigItem result;
			if (!(configEntry is ConfigEntry<float> val))
			{
				if (!(configEntry is ConfigEntry<int> val2))
				{
					throw new NotSupportedException($"Slider not supported for type: {typeof(T)}");
				}
				result = AddConfigItem((BaseConfigItem)new IntSliderConfigItem(val2, requiresRestart));
			}
			else
			{
				result = AddConfigItem((BaseConfigItem)new FloatSliderConfigItem(val, requiresRestart));
			}
			if (1 == 0)
			{
			}
			return result;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private static BaseConfigItem AddConfigDropdown<T>(ConfigEntry<T> configEntry, bool requiresRestart = false)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			if (1 == 0)
			{
			}
			if (configEntry is ConfigEntry<string> val)
			{
				BaseConfigItem result = AddConfigItem((BaseConfigItem)new TextDropDownConfigItem(val, requiresRestart));
				if (1 == 0)
				{
				}
				return result;
			}
			throw new NotSupportedException($"Dropdown not supported for type: {typeof(T)}");
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private static BaseConfigItem AddEnumDropdown<T>(ConfigEntry<T> configEntry, bool requiresRestart = false) where T : Enum
		{
			return AddConfigItem((BaseConfigItem)(object)new EnumDropDownConfigItem<T>(configEntry, requiresRestart));
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private static bool IsConfigEntryForHexColor(ConfigEntry<string> configEntry)
		{
			if (!(((ConfigEntryBase)configEntry).DefaultValue is string s))
			{
				return false;
			}
			return s.IsHexColor();
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private static BaseConfigItem AddConfigItem(BaseConfigItem configItem)
		{
			LethalConfigManager.AddConfigItem(configItem);
			return configItem;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace __GEN
{
	internal class NetworkVariableSerializationHelper
	{
		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeSerialization()
		{
			NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedByMemcpy<bool>();
			NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedIEquatable<bool>();
		}
	}
}
namespace com.github.zehsteam.FapEnergy.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}