using System;
using System.Diagnostics;
using System.IO;
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 Unity.Netcode;
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("Glass")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+6d6cc03a2e05537fcfa8c43ca049216a71e3b659")]
[assembly: AssemblyProduct("TuneyJester")]
[assembly: AssemblyTitle("TuneyJester")]
[assembly: AssemblyVersion("0.1.0.0")]
[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 TuneyJester
{
[BepInPlugin("keo.lethalcompany.tuneyjester", "TuneyJester", "0.1.1")]
public class Plugin : BaseUnityPlugin
{
public const string GUID = "keo.lethalcompany.tuneyjester";
public const string NAME = "TuneyJester";
public const string VERSION = "0.1.1";
internal static ManualLogSource Logger { get; private set; }
internal static ConfigEntry<float> CalmRadius { get; private set; }
private void Awake()
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
Logger = ((BaseUnityPlugin)this).Logger;
CalmRadius = ((BaseUnityPlugin)this).Config.Bind<float>("General", "CalmRadius", 15f, "Maximum distance between a playing boombox and the Jester for the music to have a calming effect.");
new Harmony("keo.lethalcompany.tuneyjester").PatchAll();
DateTime lastWriteTimeUtc = File.GetLastWriteTimeUtc(Assembly.GetExecutingAssembly().Location);
Logger.LogInfo((object)string.Format("{0} v{1} loaded — built {2:yyyy-MM-dd HH:mm} UTC", "TuneyJester", "0.1.1", lastWriteTimeUtc));
}
}
}
namespace TuneyJester.Patches
{
[HarmonyPatch(typeof(JesterAI))]
public static class JesterPatch
{
private const float TIMER_FLOOR = 2f;
private const float TIMER_RESET = 15f;
private const float BOOMBOX_SCAN_INTERVAL = 0.25f;
private static BoomboxItem[] cachedBoomboxes = Array.Empty<BoomboxItem>();
private static float nextScanTime;
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void SootheJester(JesterAI __instance)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
if (((EnemyAI)__instance).isEnemyDead)
{
return;
}
int currentBehaviourStateIndex = ((EnemyAI)__instance).currentBehaviourStateIndex;
if (currentBehaviourStateIndex < 2)
{
bool flag = IsPlayingBoomboxInRange(((Component)__instance).transform.position);
if (currentBehaviourStateIndex == 0 && ((NetworkBehaviour)__instance).IsOwner && __instance.beginCrankingTimer < 2f && flag)
{
__instance.beginCrankingTimer = 15f;
Plugin.Logger.LogDebug((object)"Boombox soothed Jester — cranking timer reset");
}
else if (currentBehaviourStateIndex == 1 && flag)
{
((EnemyAI)__instance).stunNormalizedTimer = 0.5f;
}
}
}
private static bool IsPlayingBoomboxInRange(Vector3 position)
{
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
if (Time.time >= nextScanTime)
{
cachedBoomboxes = Object.FindObjectsOfType<BoomboxItem>();
nextScanTime = Time.time + 0.25f;
}
float num = Plugin.CalmRadius.Value * Plugin.CalmRadius.Value;
BoomboxItem[] array = cachedBoomboxes;
foreach (BoomboxItem val in array)
{
if ((Object)(object)val != (Object)null && val.isPlayingMusic)
{
Vector3 val2 = ((Component)val).transform.position - position;
if (((Vector3)(ref val2)).sqrMagnitude <= num)
{
return true;
}
}
}
return false;
}
}
}