Decompiled source of AlwaysOnTrinkets v1.0.0

Dupo_AlwaysOnTrinkets.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("Dupo_AlwaysOnTrinkets")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Dupo_AlwaysOnTrinkets")]
[assembly: AssemblyTitle("Dupo_AlwaysOnTrinkets")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 Dupo.AlwaysOnTrinkets
{
	[BepInPlugin("dupo.AlwaysOnTrinkets", "Dupo_AlwaysOnTrinkets", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGuid = "dupo.AlwaysOnTrinkets";

		public const string ModName = "Dupo_AlwaysOnTrinkets";

		public const string ModVersion = "1.0.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<bool> DebugLog;

		private const float CheckInterval = 0.5f;

		private const float RefreshBelow = 3f;

		private static readonly HashSet<int> Kept = new HashSet<int>();

		private static readonly HashSet<int> Equipped = new HashSet<int>();

		private float _nextCheck;

		private readonly Harmony _harmony = new Harmony("dupo.AlwaysOnTrinkets");

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "Enabled", true, "The effect of the equipped trinket is always active, without filling the adrenaline bar.");
			DebugLog = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "Debug Log", false, "Write extra diagnostic lines to BepInEx/LogOutput.log.");
			_harmony.PatchAll(typeof(Plugin).Assembly);
			Log.LogInfo((object)"Dupo_AlwaysOnTrinkets 1.0.0 loaded");
		}

		private void OnDestroy()
		{
			_harmony.UnpatchSelf();
		}

		internal static void Debug(string message)
		{
			if (DebugLog != null && DebugLog.Value)
			{
				Log.LogInfo((object)message);
			}
		}

		private void Update()
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Invalid comparison between Unknown and I4
			if (Time.time < _nextCheck)
			{
				return;
			}
			_nextCheck = Time.time + 0.5f;
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead())
			{
				Kept.Clear();
				return;
			}
			SEMan sEMan = ((Character)localPlayer).GetSEMan();
			Equipped.Clear();
			if (Enabled.Value)
			{
				foreach (ItemData allItem in ((Humanoid)localPlayer).GetInventory().GetAllItems())
				{
					if (!allItem.m_equipped || (int)allItem.m_shared.m_itemType != 24)
					{
						continue;
					}
					StatusEffect fullAdrenalineSE = allItem.m_shared.m_fullAdrenalineSE;
					if (!((Object)(object)fullAdrenalineSE == (Object)null))
					{
						int num = fullAdrenalineSE.NameHash();
						Equipped.Add(num);
						StatusEffect statusEffect = sEMan.GetStatusEffect(num);
						if ((Object)(object)statusEffect == (Object)null)
						{
							sEMan.AddStatusEffect(fullAdrenalineSE, false, 0, 0f, (short)(-1));
							Debug($"Added {((Object)fullAdrenalineSE).name} from {allItem.m_shared.m_name} (duration {fullAdrenalineSE.m_ttl:0.#}s)");
						}
						else if (statusEffect.m_ttl > 0f && statusEffect.GetRemaningTime() < 3f)
						{
							float remaningTime = statusEffect.GetRemaningTime();
							statusEffect.ResetTime();
							Debug($"Refreshed {((Object)statusEffect).name}: {remaningTime:0.#}s left, reset to {statusEffect.m_ttl:0.#}s");
						}
						Kept.Add(num);
					}
				}
			}
			if (Kept.SetEquals(Equipped))
			{
				return;
			}
			List<int> list = new List<int>();
			foreach (int item in Kept)
			{
				if (!Equipped.Contains(item))
				{
					list.Add(item);
				}
			}
			foreach (int item2 in list)
			{
				sEMan.RemoveStatusEffect(item2, true);
				Kept.Remove(item2);
				StatusEffect val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetStatusEffect(item2) : null);
				Debug("Removed " + (((Object)(object)val != (Object)null) ? ((Object)val).name : item2.ToString()));
			}
		}
	}
}