using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("JesterTimeout")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Puts Jesters back into their boxes after a configurable timeout")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+b2f9dd0f5393eab179902566b08eea2e55905871")]
[assembly: AssemblyProduct("JesterTimeout")]
[assembly: AssemblyTitle("JesterTimeout")]
[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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace JesterTimeout
{
public static class PatchClass
{
private static readonly Dictionary<JesterAI, float> timeoutDict = new Dictionary<JesterAI, float>();
private static readonly object timeoutDictLock = new object();
private static bool hasClearedList = true;
[HarmonyPatch(typeof(JesterAI), "Update")]
[HarmonyPrefix]
public static void JesterAI_Update(JesterAI __instance)
{
if (!((NetworkBehaviour)__instance).IsHost || ((EnemyAI)__instance).currentBehaviourStateIndex != 2)
{
return;
}
lock (timeoutDictLock)
{
if (!timeoutDict.TryGetValue(__instance, out var value))
{
timeoutDict.Add(__instance, Plugin.TimeoutSecondsConfig.Value);
Debug.Log((object)"Jester added");
return;
}
value -= Time.deltaTime;
if (value <= 0f)
{
Debug.Log((object)"JesterTimeout time elapsed");
__instance.previousState = 0;
__instance.mainCollider.isTrigger = false;
__instance.SetJesterInitialValues();
((EnemyAI)__instance).SwitchToBehaviourState(0);
timeoutDict.Remove(__instance);
}
else
{
timeoutDict[__instance] = value;
}
}
}
[HarmonyPatch(typeof(StartOfRound), "Update")]
[HarmonyPostfix]
public static void StartOfRound_Update(StartOfRound __instance)
{
if (!((NetworkBehaviour)__instance).IsHost)
{
return;
}
if (!__instance.inShipPhase)
{
hasClearedList = false;
}
else if (!hasClearedList)
{
lock (timeoutDictLock)
{
timeoutDict.Clear();
}
hasClearedList = true;
Debug.Log((object)"Cleared jesters list");
}
}
}
[BepInPlugin("Rosentti.JesterTimeout", "JesterTimeout", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
public static ConfigEntry<int> TimeoutSecondsConfig { get; private set; }
private void Awake()
{
TimeoutSecondsConfig = ((BaseUnityPlugin)this).Config.Bind<int>("General", "TimeoutSeconds", 60, "How many seconds the Jester will be active until it's put back in it's box");
Harmony.CreateAndPatchAll(typeof(PatchClass), (string)null);
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "JesterTimeout";
public const string PLUGIN_NAME = "JesterTimeout";
public const string PLUGIN_VERSION = "1.0.1";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}