Decompiled source of DynamicJesterCrank v1.0.1

DynamicJesterCrank.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RadiationIsCool")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RadiationIsCool")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8ee335db-0cbe-470c-8fbc-69263f01b35a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.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 DynamicJesterCrank
{
	[BepInPlugin("Piggy.DynamicJesterCrank", "DynamicJesterCrank", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "Piggy.DynamicJesterCrank";

		private const string modName = "DynamicJesterCrank";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("Piggy.DynamicJesterCrank");

		private static Plugin Instance;

		public static string PluginDirectory;

		public static ManualLogSource mls;

		public static AssetBundle Bundle;

		public static RuntimeAnimatorController jesterController;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			PluginDirectory = ((BaseUnityPlugin)this).Info.Location;
			mls = Logger.CreateLogSource("Piggy.DynamicJesterCrank");
			mls.LogInfo((object)"DynamicJesterCrank is loaded");
			LoadAssets();
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
		}

		private void LoadAssets()
		{
			try
			{
				Bundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(PluginDirectory), "dynamicjestercrank"));
			}
			catch (Exception ex)
			{
				mls.LogError((object)("Couldn't load asset bundle: " + ex.Message));
				return;
			}
			try
			{
				jesterController = Bundle.LoadAsset<RuntimeAnimatorController>("DynamicJesterRig.controller");
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Successfully loaded assets!");
			}
			catch (Exception ex2)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Couldn't load assets: " + ex2.Message));
			}
		}
	}
}
namespace DynamicJesterCrank.Patches
{
	[HarmonyPatch(typeof(JesterAI))]
	internal class JesterAIPatch
	{
		public static float animationSpeed = 1f;

		public static float popUpTime = 40f;

		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void Start_Postfix(ref Animator ___creatureAnimator)
		{
			___creatureAnimator.runtimeAnimatorController = Plugin.jesterController;
		}

		[HarmonyPostfix]
		[HarmonyPatch("SetJesterInitialValues")]
		private static void SetJesterInitialValues_Postfix(ref float ___popUpTimer)
		{
			animationSpeed = 1f;
			popUpTime = ___popUpTimer;
		}

		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		private static void Update_Postfix(JesterAI __instance, ref float ___popUpTimer, ref Animator ___creatureAnimator)
		{
			((EnemyAI)__instance).creatureAnimator.SetFloat("CrankSpeedMultiplier2", 1f);
			switch (((EnemyAI)__instance).currentBehaviourStateIndex)
			{
			case 0:
				___creatureAnimator.SetFloat("CrankSpeedMultiplier2", 0f);
				break;
			case 1:
				if (((EnemyAI)__instance).stunNormalizedTimer > 0f)
				{
					___creatureAnimator.SetFloat("CrankSpeedMultiplier2", 0f);
				}
				else if ((popUpTime - ___popUpTimer * 2.2f) * 0.04f >= 0.6f)
				{
					___creatureAnimator.SetFloat("CrankSpeedMultiplier2", 0.6f + (popUpTime - ___popUpTimer * 2.2f) * 0.04f);
				}
				break;
			}
		}
	}
}