using System;
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 BepInEx.Logging;
using GameNetcodeStuff;
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("SassyCoilhead")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Mod for Lethal Company that adds a funny dance if you are near him for too long.")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("SassyCoilhead")]
[assembly: AssemblyTitle("SassyCoilhead")]
[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 SassyCoilhead
{
public static class PluginInfo
{
public const string PLUGIN_GUID = "SassyCoilhead";
public const string PLUGIN_NAME = "SassyCoilhead";
public const string PLUGIN_VERSION = "1.0.1";
}
}
namespace SassyCoilheadMod
{
public class CoilheadDanceCheck : MonoBehaviour
{
private SpringManAI _coilhead;
private Animator _coilheadAnimator;
private RuntimeAnimatorController _originalController;
private RuntimeAnimatorController _danceController;
private float _checkTime;
private float _timeNearPlayer;
private bool _dancing;
private const float TurnToPlayerWhileDancingSpeed = 5f;
private const float CheckTimeInterval = 2f;
public bool IsDancing => _dancing;
public static event Action<SpringManAI> OnCoilheadDance;
public void StopDance()
{
if (_dancing)
{
_coilheadAnimator.runtimeAnimatorController = _originalController;
_dancing = false;
}
}
internal void SetSpringMan(SpringManAI springMan)
{
_coilhead = springMan;
_coilheadAnimator = ((Component)_coilhead).GetComponentInChildren<Animator>();
_originalController = _coilheadAnimator.runtimeAnimatorController;
_checkTime = 2f;
_danceController = SassyCoilhead_PluginEntry.DanceControllerAsset;
}
private bool NearAnyPlayer()
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
SpringManAI coilhead = _coilhead;
PlayerControllerB val = ((coilhead != null) ? ((EnemyAI)coilhead).GetClosestPlayer(false, false, false) : null);
if ((Object)(object)val != (Object)null)
{
Vector3 position = ((Component)val).transform.position;
Vector3 val2 = ((Component)_coilhead).transform.position - position;
return ((Vector3)(ref val2)).sqrMagnitude <= SassyCoilhead_PluginEntry.DetectionRadius * SassyCoilhead_PluginEntry.DetectionRadius;
}
return false;
}
private void LateUpdate()
{
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_coilhead == (Object)null)
{
Object.Destroy((Object)(object)this);
}
else if (_dancing)
{
if (!NearAnyPlayer())
{
_coilheadAnimator.runtimeAnimatorController = _originalController;
_dancing = false;
}
else
{
Vector3 val = ((Component)((EnemyAI)_coilhead).GetClosestPlayer(false, false, false)).transform.position - ((Component)_coilhead).transform.position;
((Component)_coilhead).transform.forward = Vector3.RotateTowards(((Component)_coilhead).transform.forward, val, 5f * Time.deltaTime, 0f);
}
}
else if (NearAnyPlayer())
{
_timeNearPlayer += Time.deltaTime;
if (_timeNearPlayer >= SassyCoilhead_PluginEntry.DanceWaitMinTime)
{
_checkTime -= Time.deltaTime;
if (!(_checkTime > 0f))
{
_checkTime = 2f;
AttemptDance();
}
}
}
else
{
_timeNearPlayer = 0f;
}
}
private void AttemptDance()
{
if (Random.value <= SassyCoilhead_PluginEntry.DanceChance)
{
_dancing = true;
_coilheadAnimator.runtimeAnimatorController = _danceController;
CoilheadDanceCheck.OnCoilheadDance?.Invoke(_coilhead);
}
}
}
[BepInPlugin("ghoulmage.funny.sassycoilhead", "Sassy Coilhead", "1.0.1")]
[BepInProcess("Lethal Company.exe")]
public class SassyCoilhead_PluginEntry : BaseUnityPlugin
{
public const string GUID = "ghoulmage.funny.sassycoilhead";
public const string NAME = "Sassy Coilhead";
public const string VERSION = "1.0.1";
internal ConfigEntry<float> _config_detectionRadius;
internal ConfigEntry<float> _config_danceWaitMinTime;
internal ConfigEntry<byte> _config_danceChance;
internal static ManualLogSource Log;
private const string ConfigName = "SassyCoilhead";
public static float DetectionRadius { get; private set; }
public static float DanceWaitMinTime { get; private set; }
public static float DanceChance { get; private set; }
internal static RuntimeAnimatorController DanceControllerAsset { get; private set; }
internal static AnimationClip DanceClipAsset { get; private set; }
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Mod Sassy Coilhead ver 1.0.1 (ghoulmage.funny.sassycoilhead) is loaded!");
DoPatch.This("ghoulmage.funny.sassycoilhead");
FetchConfigurationValues();
LoadDanceFromAssetBundle();
}
private void LoadDanceFromAssetBundle()
{
AssetBundle val = AssetBundle.LoadFromFile(Paths.PluginPath + "\\GhoulMage\\funny\\sassycoilhead");
if ((Object)(object)val == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load Coilhead's dance...");
return;
}
DanceClipAsset = val.LoadAsset<AnimationClip>("Assets/sassy_dance.anim");
if ((Object)(object)DanceClipAsset == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Failed to load Coilhead's dance...");
return;
}
DanceControllerAsset = val.LoadAsset<RuntimeAnimatorController>("Assets/sassy_dance_controller.controller");
if ((Object)(object)DanceControllerAsset == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Failed to load Coilhead's dance...");
return;
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"Succesfully loaded Coilhead's dance!");
val.Unload(false);
}
private void FetchConfigurationValues()
{
_config_detectionRadius = ((BaseUnityPlugin)this).Config.Bind<float>("SassyCoilhead", "Detection Range (meters)", 9.5f, "Coilhead has to be inside this range of a player to check if it should dance.");
_config_danceWaitMinTime = ((BaseUnityPlugin)this).Config.Bind<float>("SassyCoilhead", "Minimum Wait Time (seconds)", 5f, "Minimum time to stay still without dancing near any player.");
_config_danceChance = ((BaseUnityPlugin)this).Config.Bind<byte>("SassyCoilhead", "Dance Chance (0-255)", (byte)42, "Chance that the coilhead will dance every 2 seconds.");
DetectionRadius = _config_detectionRadius.Value;
DanceWaitMinTime = _config_danceWaitMinTime.Value;
DanceChance = (float)(int)_config_danceChance.Value / 255f;
}
}
public static class DoPatch
{
public static void This(string guid)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
new Harmony(guid).PatchAll();
}
}
internal static class SassyCoilhead_Helpers
{
internal static void CreateDetectorOn(SpringManAI target)
{
if ((Object)(object)target == (Object)null)
{
SassyCoilhead_PluginEntry.Log.LogWarning((object)"Attempting to create a dance detector on a null entity. Aborting.");
}
else
{
((Component)target).gameObject.AddComponent<CoilheadDanceCheck>().SetSpringMan(target);
}
}
}
}
namespace SassyCoilheadMod.Patch
{
[HarmonyPatch(typeof(EnemyAI))]
internal class SassyCoilHead_Patch
{
[HarmonyPatch("Start")]
[HarmonyPrefix]
private static void CheckCoilhead(EnemyAI __instance)
{
if (__instance is SpringManAI)
{
SassyCoilhead_PluginEntry.Log.LogInfo((object)"Found a coilhead. Attaching dance script.");
SassyCoilhead_Helpers.CreateDetectorOn((SpringManAI)(object)((__instance is SpringManAI) ? __instance : null));
}
}
}
}