Decompiled source of AFKConfig v1.0.1

plugins/Marioalexsan.AFKConfig.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Marioalexsan.AFKConfig.SoftDependencies;
using Microsoft.CodeAnalysis;
using Nessie.ATLYSS.EasySettings;
using Nessie.ATLYSS.EasySettings.UIElements;
using UnityEngine;
using UnityEngine.Events;

[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")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Marioalexsan.AFKConfig")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+3f0e25126398eb3527541a6f243d70465c66a4da")]
[assembly: AssemblyProduct("AFKConfig")]
[assembly: AssemblyTitle("Marioalexsan.AFKConfig")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Marioalexsan.AFKConfig
{
	[HarmonyPatch]
	internal static class PlayerAFKTimer
	{
		private static readonly KeyCode[] AllKeys = (KeyCode[])Enum.GetValues(typeof(KeyCode));

		private static MethodInfo TargetMethod()
		{
			return AccessTools.FirstMethod(typeof(Player), (Func<MethodInfo, bool>)((MethodInfo x) => x.Name.Contains("Handle_AFKCondition")));
		}

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> code)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(code, (ILGenerator)null);
			while (val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction x) => CodeInstructionExtensions.LoadsConstant(x, 125.0)), (string)null)
			}).IsValid)
			{
				val.SetAndAdvance(OpCodes.Call, (object)AccessTools.Method(typeof(PlayerAFKTimer), "GetAFKTimer", (Type[])null, (Type[])null));
			}
			val.Start();
			while (val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction x) => CodeInstructionExtensions.LoadsConstant(x, 126.0)), (string)null)
			}).IsValid)
			{
				val.SetAndAdvance(OpCodes.Call, (object)AccessTools.Method(typeof(PlayerAFKTimer), "GetAFKTimerPlusOne", (Type[])null, (Type[])null));
			}
			val.Start();
			while (val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction x) => CodeInstructionExtensions.Calls(x, AccessTools.Method(typeof(Player), "Cmd_InitAfkCondition", (Type[])null, (Type[])null))), (string)null)
			}).IsValid)
			{
				val.SetAndAdvance(OpCodes.Call, (object)AccessTools.Method(typeof(PlayerAFKTimer), "InitAfkCondition", (Type[])null, (Type[])null));
			}
			return val.InstructionEnumeration();
		}

		private static float GetAFKTimer()
		{
			return AFKConfig.GetAFKTimer();
		}

		private static float GetAFKTimerPlusOne()
		{
			return AFKConfig.GetAFKTimer() + 1f;
		}

		private static void InitAfkCondition(Player player, bool goAfk)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Invalid comparison between Unknown and I4
			//IL_0031: 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_003a: Invalid comparison between Unknown and I4
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			if (AFKConfig.AllowTabbingOut.Value)
			{
				for (int i = 0; i < AllKeys.Length; i++)
				{
					KeyCode val = AllKeys[i];
					KeyCode val2 = val;
					KeyCode val3 = val2;
					if ((int)val3 != 9)
					{
						if (val3 - 307 <= 3)
						{
							continue;
						}
					}
					else
					{
						if (!Input.GetKey((KeyCode)9) || Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307))
						{
							continue;
						}
						flag = true;
					}
					if (Input.GetKey(val))
					{
						flag = true;
						break;
					}
				}
			}
			else
			{
				flag = Input.anyKey;
			}
			if (goAfk)
			{
				player.Cmd_InitAfkCondition(true);
				if (!AFKConfig.SitDownOnAFK.Value)
				{
					AFKConfig.ShouldSendIdleAnim = true;
				}
			}
			else if (flag)
			{
				player.Cmd_InitAfkCondition(false);
				if (!AFKConfig.StandUpFromAFK.Value)
				{
					AFKConfig.ShouldSendSitAnim = true;
				}
			}
		}
	}
	[BepInPlugin("Marioalexsan.AFKConfig", "AFKConfig", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class AFKConfig : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__35_0;

			internal void <Awake>b__35_0()
			{
				EasySettings.AddHeader("AFKConfig");
				EasySettings.AddToggle("AFK Enabled", AFKEnabled);
				EasySettings.AddAdvancedSlider("AFK Timer (minutes)", AFKTimer);
				EasySettings.AddToggle("Allow Tabbing Out", AllowTabbingOut);
				EasySettings.AddToggle("Sit Down On AFK", SitDownOnAFK);
				EasySettings.AddToggle("Stand Up From AFK", StandUpFromAFK);
			}
		}

		private readonly Harmony _harmony = new Harmony("Marioalexsan.AFKConfig");

		internal static ManualLogSource Logger { get; private set; }

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

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

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

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

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

		public static bool ShouldSendSitAnim { get; set; }

		public static bool ShouldSendIdleAnim { get; set; }

		public static float GetAFKTimer()
		{
			return AFKEnabled.Value ? (AFKTimer.Value * 60f) : 10000000f;
		}

		public AFKConfig()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			_harmony.PatchAll();
			AFKTimer = ((BaseUnityPlugin)this).Config.Bind<float>("General", "AFKTimer", 2f, new ConfigDescription("The time in minutes before AFK mode is activated.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 60f), Array.Empty<object>()));
			AFKEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AFKEnabled", true, "Enable or disable the AFK mechanic.");
			AllowTabbingOut = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AllowTabbingOut", false, "Prevents AFK state from being modified when alt-tabbing or pressing the Windows (Meta) key.");
			SitDownOnAFK = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "SitDownOnAFK", true, "If true, the character will sit down when entering AFK.");
			StandUpFromAFK = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "StandUpFromAFK", true, "If true, the character will stand up when exiting AFK.");
		}

		public void Awake()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			if (!EasySettings.IsAvailable)
			{
				return;
			}
			UnityEvent onInitialized = EasySettings.OnInitialized;
			object obj = <>c.<>9__35_0;
			if (obj == null)
			{
				UnityAction val = delegate
				{
					EasySettings.AddHeader("AFKConfig");
					EasySettings.AddToggle("AFK Enabled", AFKEnabled);
					EasySettings.AddAdvancedSlider("AFK Timer (minutes)", AFKTimer);
					EasySettings.AddToggle("Allow Tabbing Out", AllowTabbingOut);
					EasySettings.AddToggle("Sit Down On AFK", SitDownOnAFK);
					EasySettings.AddToggle("Stand Up From AFK", StandUpFromAFK);
				};
				<>c.<>9__35_0 = val;
				obj = (object)val;
			}
			onInitialized.AddListener((UnityAction)obj);
			EasySettings.OnApplySettings.AddListener((UnityAction)delegate
			{
				((BaseUnityPlugin)this).Config.Save();
			});
		}

		public void Update()
		{
			if (ShouldSendSitAnim && Object.op_Implicit((Object)(object)Player._mainPlayer))
			{
				ShouldSendSitAnim = false;
				Player._mainPlayer._pVisual.Send_CrossFadeAnim("sit", 0f, 11, (LatencyCheck)0);
			}
			if (ShouldSendIdleAnim && Object.op_Implicit((Object)(object)Player._mainPlayer))
			{
				ShouldSendIdleAnim = false;
				Player._mainPlayer._pVisual.Send_CrossFadeAnim("Idle", 0f, 11, (LatencyCheck)0);
			}
		}
	}
	internal static class Logging
	{
		private static ManualLogSource InternalLogger => AFKConfig.Logger;

		public static void LogFatal(object data, ConfigEntry<bool>? toggle = null)
		{
			Log(data, (LogLevel)1, toggle);
		}

		public static void LogError(object data, ConfigEntry<bool>? toggle = null)
		{
			Log(data, (LogLevel)2, toggle);
		}

		public static void LogWarning(object data, ConfigEntry<bool>? toggle = null)
		{
			Log(data, (LogLevel)4, toggle);
		}

		public static void LogMessage(object data, ConfigEntry<bool>? toggle = null)
		{
			Log(data, (LogLevel)8, toggle);
		}

		public static void LogInfo(object data, ConfigEntry<bool>? toggle = null)
		{
			Log(data, (LogLevel)16, toggle);
		}

		public static void LogDebug(object data, ConfigEntry<bool>? toggle = null)
		{
			Log(data, (LogLevel)32, toggle);
		}

		private static void Log(object data, LogLevel level = 16, ConfigEntry<bool>? toggle = null)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (toggle == null || toggle.Value)
			{
				ManualLogSource internalLogger = InternalLogger;
				if (internalLogger != null)
				{
					internalLogger.Log(level, data);
				}
			}
		}
	}
	internal static class ModInfo
	{
		public const string GUID = "Marioalexsan.AFKConfig";

		public const string NAME = "AFKConfig";

		public const string VERSION = "1.0.1";
	}
}
namespace Marioalexsan.AFKConfig.SoftDependencies
{
	public static class EasySettings
	{
		private const MethodImplOptions SoftDepend = MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization;

		public const string ModID = "EasySettings";

		public static readonly Version ExpectedVersion = new Version("1.2.1");

		private static BaseUnityPlugin? _plugin;

		private static bool _initialized;

		public static bool IsAvailable
		{
			get
			{
				if (!_initialized)
				{
					_plugin = (Chainloader.PluginInfos.TryGetValue("EasySettings", out var value) ? value.Instance : null);
					_initialized = true;
					if ((Object)(object)_plugin == (Object)null)
					{
						Logging.LogWarning("Soft dependency EasySettings was not found.");
					}
					else if (_plugin.Info.Metadata.Version != ExpectedVersion)
					{
						Logging.LogWarning(string.Format("Soft dependency {0} has a different version than expected (have: {1}, expect: {2}).", "EasySettings", _plugin.Info.Metadata.Version, ExpectedVersion));
					}
				}
				return (Object)(object)_plugin != (Object)null;
			}
		}

		public static UnityEvent OnInitialized
		{
			[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
			get
			{
				return Settings.OnInitialized;
			}
		}

		public static UnityEvent OnCancelSettings
		{
			[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
			get
			{
				return Settings.OnCancelSettings;
			}
		}

		public static UnityEvent OnApplySettings
		{
			[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
			get
			{
				return Settings.OnApplySettings;
			}
		}

		public static UnityEvent OnCloseSettings
		{
			[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
			get
			{
				return Settings.OnCloseSettings;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static GameObject AddSpace()
		{
			return ((Component)((BaseAtlyssElement)Settings.ModTab.AddSpace()).Root).gameObject;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static GameObject AddHeader(string label)
		{
			return ((Component)((BaseAtlyssElement)Settings.ModTab.AddHeader(label)).Root).gameObject;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static GameObject AddButton(string buttonLabel, UnityAction onClick)
		{
			return ((Component)((BaseAtlyssElement)Settings.ModTab.AddButton(buttonLabel, onClick)).Root).gameObject;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static GameObject AddToggle(string label, ConfigEntry<bool> config)
		{
			return ((Component)((BaseAtlyssElement)Settings.ModTab.AddToggle(label, config)).Root).gameObject;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static GameObject AddSlider(string label, ConfigEntry<float> config, bool wholeNumbers = false)
		{
			return ((Component)((BaseAtlyssElement)Settings.ModTab.AddSlider(label, config, wholeNumbers)).Root).gameObject;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static GameObject AddAdvancedSlider(string label, ConfigEntry<float> config, bool wholeNumbers = false)
		{
			return ((Component)((BaseAtlyssElement)Settings.ModTab.AddAdvancedSlider(label, config, wholeNumbers)).Root).gameObject;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static GameObject AddDropdown<T>(string label, ConfigEntry<T> config) where T : Enum
		{
			return ((Component)((BaseAtlyssElement)Settings.ModTab.AddDropdown<T>(label, config)).Root).gameObject;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static GameObject AddKeyButton(string label, ConfigEntry<KeyCode> config)
		{
			return ((Component)((BaseAtlyssElement)Settings.ModTab.AddKeyButton(label, config)).Root).gameObject;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}