Decompiled source of SquishCompany v1.2.1

SquishPlugin.dll

Decompiled 10 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using LethalLib.Modules;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("SquishPlugin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SquishPlugin")]
[assembly: AssemblyTitle("SquishPlugin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace SquishPlugin
{
	[HarmonyPatch(typeof(EnemyAI), "Update")]
	internal class EnemyAIPatch
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
		public static void Update(EnemyAI instance)
		{
			instance.Update();
		}
	}
	[HarmonyPatch(typeof(JesterAI))]
	internal class JesterAIPatcher
	{
		private static MethodInfo CalculateAnimationSpeed = AccessTools.Method(typeof(JesterAI), "CalculateAnimationSpeed", (Type[])null, (Type[])null);

		private static MethodInfo SetJesterInitialValues = AccessTools.Method(typeof(JesterAI), "SetJesterInitialValues", (Type[])null, (Type[])null);

		private static MethodInfo BaseUpdate = AccessTools.Method(typeof(EnemyAI), "Update", (Type[])null, (Type[])null);

		private static FieldInfo previousState = AccessTools.Field(typeof(JesterAI), "previousState");

		private static FieldInfo inKillAnimation = AccessTools.Field(typeof(JesterAI), "inKillAnimation");

		private static FieldInfo targetingPlayer = AccessTools.Field(typeof(JesterAI), "targetingPlayer");

		private static FieldInfo noPlayersToChaseTimer = AccessTools.Field(typeof(JesterAI), "noPlayersToChaseTimer");

		private static FieldInfo popUpTimer = AccessTools.Field(typeof(JesterAI), "popUpTimer");

		[HarmonyPatch("SetJesterInitialValues")]
		[HarmonyPostfix]
		public static void PatchedSetJesterInitialValues(JesterAI __instance)
		{
			popUpTimer.SetValue(__instance, 49.5f);
			__instance.farAudio.dopplerLevel = 0f;
		}

		[HarmonyPatch("Update")]
		[HarmonyPrefix]
		public static bool JesterAIUpdate(JesterAI __instance)
		{
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Unknown result type (might be due to invalid IL or missing references)
			//IL_038e: Unknown result type (might be due to invalid IL or missing references)
			if (((EnemyAI)__instance).isEnemyDead)
			{
				return false;
			}
			CalculateAnimationSpeed.Invoke(__instance, new object[1] { __instance.maxAnimSpeed });
			switch (((EnemyAI)__instance).currentBehaviourStateIndex)
			{
			case 0:
				if ((int)previousState.GetValue(__instance) != 0)
				{
					previousState.SetValue(__instance, 0);
					__instance.mainCollider.isTrigger = false;
					SetJesterInitialValues.Invoke(__instance, null);
				}
				if (!((NetworkBehaviour)__instance).IsOwner)
				{
					break;
				}
				if (((EnemyAI)__instance).stunNormalizedTimer > 0f)
				{
					__instance.beginCrankingTimer -= Time.deltaTime * 15f;
				}
				if ((Object)(object)((EnemyAI)__instance).targetPlayer != (Object)null)
				{
					__instance.beginCrankingTimer -= Time.deltaTime;
					if (__instance.beginCrankingTimer <= 0f)
					{
						((EnemyAI)__instance).SwitchToBehaviourState(1);
					}
				}
				break;
			case 1:
				if ((int)previousState.GetValue(__instance) != 1)
				{
					previousState.SetValue(__instance, 1);
					((EnemyAI)__instance).creatureAnimator.SetBool("turningCrank", true);
					__instance.farAudio.clip = __instance.popGoesTheWeaselTheme;
					__instance.farAudio.Play();
					((EnemyAI)__instance).agent.speed = 0f;
				}
				if (((EnemyAI)__instance).stunNormalizedTimer > 0f)
				{
					__instance.farAudio.Pause();
					((EnemyAI)__instance).creatureAnimator.SetFloat("CrankSpeedMultiplier", 0f);
				}
				else
				{
					if (!__instance.farAudio.isPlaying)
					{
						__instance.farAudio.UnPause();
					}
					((EnemyAI)__instance).creatureAnimator.SetFloat("CrankSpeedMultiplier", 1f);
					__instance.popUpTimer -= Time.deltaTime;
					if (__instance.popUpTimer <= 0f && ((NetworkBehaviour)__instance).IsOwner)
					{
						((EnemyAI)__instance).SwitchToBehaviourState(2);
					}
				}
				if (!((NetworkBehaviour)__instance).IsOwner)
				{
				}
				break;
			case 2:
				if ((int)previousState.GetValue(__instance) != 2)
				{
					previousState.SetValue(__instance, 2);
					((EnemyAI)__instance).creatureAnimator.SetBool("poppedOut", true);
					((EnemyAI)__instance).creatureAnimator.SetFloat("CrankSpeedMultiplier", 1f);
					WalkieTalkie.TransmitOneShotAudio(((EnemyAI)__instance).creatureSFX, __instance.popUpSFX, 1f);
					((EnemyAI)__instance).agent.speed = 0f;
					__instance.mainCollider.isTrigger = true;
					((EnemyAI)__instance).agent.stoppingDistance = 0f;
				}
				if (((NetworkBehaviour)__instance).IsOwner && (Object)(object)((EnemyAI)__instance).targetPlayer != (Object)null && ((EnemyAI)__instance).HasLineOfSightToPosition(((Component)((EnemyAI)__instance).targetPlayer.gameplayCamera).transform.position, 80f, 80, -1f))
				{
					__instance.headRigTarget.rotation = Quaternion.Lerp(__instance.headRigTarget.rotation, Quaternion.LookRotation(((Component)((EnemyAI)__instance).targetPlayer.gameplayCamera).transform.position - ((Component)__instance.headRigTarget).transform.position, Vector3.up), 5f * Time.deltaTime);
				}
				else
				{
					__instance.headRigTarget.rotation = Quaternion.Lerp(__instance.headRigTarget.rotation, Quaternion.LookRotation(__instance.lookForwardTarget.position - ((Component)__instance.headRigTarget).transform.position, Vector3.up), 5f * Time.deltaTime);
				}
				if (!((NetworkBehaviour)__instance).IsOwner)
				{
					break;
				}
				if ((bool)inKillAnimation.GetValue(__instance) || ((EnemyAI)__instance).stunNormalizedTimer > 0f)
				{
					((EnemyAI)__instance).agent.speed = 0f;
				}
				else
				{
					((EnemyAI)__instance).agent.speed = Mathf.Clamp(((EnemyAI)__instance).agent.speed + Time.deltaTime * 1.45f, 0f, 18f);
				}
				((EnemyAI)__instance).creatureAnimator.SetBool("stunned", ((EnemyAI)__instance).stunNormalizedTimer > 0f);
				if (!(bool)targetingPlayer.GetValue(__instance))
				{
					bool flag = false;
					for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++)
					{
						if (StartOfRound.Instance.allPlayerScripts[i].isPlayerControlled && StartOfRound.Instance.allPlayerScripts[i].isInsideFactory)
						{
							flag = true;
						}
					}
					if (!flag)
					{
						noPlayersToChaseTimer.SetValue(__instance, (float)noPlayersToChaseTimer.GetValue(__instance) - Time.deltaTime);
						if ((float)noPlayersToChaseTimer.GetValue(__instance) <= 0f)
						{
							((EnemyAI)__instance).SwitchToBehaviourState(0);
						}
					}
				}
				else
				{
					noPlayersToChaseTimer.SetValue(__instance, 5f);
				}
				break;
			}
			EnemyAIPatch.Update((EnemyAI)(object)__instance);
			return false;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "SquishPlugin";

		public const string PLUGIN_NAME = "SquishPlugin";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace SquishPlugin.Patches
{
	[BepInPlugin("SquishPlugin", "SquishPlugin", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static AssetBundle SquishAssetBundle;

		private ManualLogSource mls;

		private void Awake()
		{
			registerAssets();
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
		}

		private void registerAssets()
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			SquishAssetBundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "SquishCompanyAssets"));
			if ((Object)(object)SquishAssetBundle == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Could not load AssetBundle!");
				return;
			}
			Item val = SquishAssetBundle.LoadAsset<Item>("assets/models/squishmug/squishmug.asset");
			Utilities.FixMixerGroups(val.spawnPrefab);
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Items.RegisterScrap(val, 30, (LevelTypes)(-1));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Registered SquishMug Scrap item.");
		}
	}
}