Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of NoAFKEvents v1.0.3
NoAFKEvents.dll
Decompiled 2 weeks agousing System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("NoAFKEvents")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("NoAFKEvents")] [assembly: AssemblyCopyright("Copyright © 2022")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("16dee695-9561-4bde-8eab-3f4fcccaa52a")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyVersion("1.0.0.0")] namespace NoAFKEvents; [BepInPlugin("GemHunter1.NoAFKEvents", "NoAFKEvents", "1.0.3")] public class NoAFKEvents : BaseUnityPlugin { private class Info { public Vector3 position; public float lastChange; public Info(ZDO zdo) { //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) position = zdo.GetPosition(); lastChange = Time.timeSinceLevelLoad; } } [HarmonyPatch(typeof(RandEventSystem), "CheckBase")] private class CheckBasePatch { public static void Postfix(ref RandomEvent ev, ref PlayerEventData player, ref bool __result) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) instance.CheckAFKPlayers(); Vector3 pos = player.position; if (instance.afkPlayers.Any(delegate(ZDO x) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) Vector3 val = x.GetPosition() - pos; return ((Vector3)(ref val)).sqrMagnitude < 0.001f; })) { logger.LogMessage((object)("Player is AFK, prevented random event (" + ev.m_name + ") in his area.")); __result = false; } } } [HarmonyPatch(typeof(Game), "Start")] private class GameStartPatch { public static void Prefix() { instance.afkPlayers.Clear(); instance.playerInfo.Clear(); } } public readonly Harmony harmony = new Harmony("GemHunter1.NoAFKEvents"); public static ManualLogSource logger; public static NoAFKEvents instance; public HashSet<ZDO> afkPlayers = new HashSet<ZDO>(); private Dictionary<ZDO, Info> playerInfo = new Dictionary<ZDO, Info>(); private float timer; public static ConfigEntry<float> afkTime; public static ConfigEntry<float> checkFrequency; private void Awake() { instance = this; logger = ((BaseUnityPlugin)this).Logger; harmony.PatchAll(); afkTime = ((BaseUnityPlugin)this).Config.Bind<float>("General", "AFK Time (s)", 300f, "How long player should not be moving until recognized as AFK"); checkFrequency = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Check Frequency (s)", 30f, "Frequency of checking AFK players"); } private void OnDestroy() { harmony.UnpatchSelf(); } private void FixedUpdate() { if (timer > checkFrequency.Value) { CheckAFKPlayers(); timer = 0f; } else { timer += Time.deltaTime; } } public void CheckAFKPlayers() { //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) if ((double)timer < 0.1 || (Object)(object)ZNet.instance == (Object)null) { return; } timer = 0f; foreach (ZDO allCharacterZDO in ZNet.instance.GetAllCharacterZDOS()) { if (!playerInfo.ContainsKey(allCharacterZDO)) { logger.LogDebug((object)("Player not yet registered (" + allCharacterZDO.GetString("playerName", ""))); playerInfo.Add(allCharacterZDO, new Info(allCharacterZDO)); continue; } Info info = playerInfo[allCharacterZDO]; float num = Vector3.SqrMagnitude(info.position - allCharacterZDO.GetPosition()); info.position = allCharacterZDO.GetPosition(); if ((double)num < 0.0001) { if (Time.timeSinceLevelLoad - info.lastChange > afkTime.Value && afkPlayers.Add(allCharacterZDO)) { logger.LogMessage((object)("Player is AFK (" + allCharacterZDO.GetString("playerName", "") + ")")); } continue; } info.lastChange = Time.timeSinceLevelLoad; if (afkPlayers.Remove(allCharacterZDO)) { logger.LogMessage((object)("Player is no longer AFK (" + allCharacterZDO.GetString("playerName", "") + ")")); } } } }