Decompiled source of Symbiosis v1.0.8

BepInEx/plugins/Symbiosis.dll

Decompiled 4 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using NuclearLib;
using NuclearLib.ModContent;
using Symbiosis.Extensions;
using Symbiosis.ModBehaviours;
using Symbiosis.Patches;
using Symbiosis.Utils;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Symbiosis")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Symbiosis")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("97f95e36-1154-479c-be65-4ef35b78018f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace Symbiosis
{
	public class ConfigManager
	{
		public class HoarderBugConfig
		{
			public ConfigEntry<bool> ItemUse { get; set; }

			public ConfigEntry<int> MinItemUseInterval { get; set; }

			public ConfigEntry<int> MaxItemUseInterval { get; set; }

			public ConfigEntry<int> ItemUnuseChance { get; set; }

			public ConfigEntry<bool> Dispersion { get; set; }

			public ConfigEntry<bool> ItemDeathDrop { get; set; }
		}

		public HoarderBugConfig HoarderBug;

		public ConfigManager()
		{
			HoarderBug = new HoarderBugConfig
			{
				ItemUse = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("HoarderBug", "Item Use", true, "Allows the use of items at random intervals."),
				MinItemUseInterval = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<int>("HoarderBug", "Min Item Use Interval", 0, "Sets the minimum time interval (in seconds) between each item use."),
				MaxItemUseInterval = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<int>("HoarderBug", "Max Item Use Interval", 10, "Sets the maximum time interval (in seconds) between each item use."),
				ItemUnuseChance = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<int>("HoarderBug", "Item Unuse Chance", 3, "Defines the probability (1 in X) of stopping item use, e.g., stop spraying."),
				Dispersion = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("HoarderBug", "Dispersion", true, "Enables hoarding bugs to move around and make room, reducing crowding."),
				ItemDeathDrop = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("HoarderBug", "Item Death Drop", true, "Enables a bug fix ensuring hoarding bugs drop held items upon death.")
			};
		}
	}
	[BepInPlugin("niceh.Symbiosis", "Symbiosis", "1.0.8")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "niceh.Symbiosis";

		public const string Name = "Symbiosis";

		public static Plugin Instance { get; private set; }

		public static ManualLogSource Log { get; private set; }

		public static ConfigManager ConfigManager { get; private set; }

		private void Awake()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"Patching...");
			Harmony val = new Harmony("niceh.Symbiosis");
			val.PatchAll(typeof(Patch_HoarderBug));
			Log.LogInfo((object)"Finished patching!");
			Log.LogInfo((object)"Registering ModBehaviours...");
			Plugin.RegisterModBehaviour<Mod_HoarderBug>(typeof(HoarderBugAI));
			Plugin.RegisterModBehaviour<Mod_ExtensionLadder>(typeof(ExtensionLadderItem));
			Plugin.RegisterModBehaviour<Mod_StunGrenade>(typeof(StunGrenadeItem));
			Log.LogInfo((object)"Finished registering ModBehaviours!");
			Log.LogInfo((object)"Loading Config...");
			ConfigManager = new ConfigManager();
			Log.LogInfo((object)"Finished Loading Config!");
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}
	}
}
namespace Symbiosis.Utils
{
	public static class Util_HoarderBug
	{
		public static HoarderBugAI FindHoarderBug(GrabbableObject item)
		{
			if ((Object)(object)item.playerHeldBy != (Object)null)
			{
				return null;
			}
			HoarderBugAI[] array = Object.FindObjectsByType<HoarderBugAI>((FindObjectsSortMode)0);
			HoarderBugAI[] array2 = array;
			foreach (HoarderBugAI val in array2)
			{
				if (val != null && val.heldItem != null && !((Object)(object)val.heldItem.itemGrabbableObject != (Object)(object)item))
				{
					return val;
				}
			}
			return null;
		}

		public static float GetNestSize(HoarderBugAI hoarderBug)
		{
			HoarderBugAI[] source = Object.FindObjectsOfType<HoarderBugAI>();
			return (float)source.Where((HoarderBugAI x) => x.nestPosition == hoarderBug.nestPosition).Count() * 0.5f + 1f;
		}
	}
	public static class Util_NavMesh
	{
		public static Vector3 GetRandomPointInArea(Vector3 center, float radius)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Random.insideUnitSphere * radius;
			val += center;
			NavMeshHit val2 = default(NavMeshHit);
			NavMesh.SamplePosition(val, ref val2, radius, -1);
			return ((NavMeshHit)(ref val2)).position;
		}
	}
}
namespace Symbiosis.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					ResourceManager resourceManager = new ResourceManager("Symbiosis.Properties.Resources", typeof(Resources).Assembly);
					resourceMan = resourceManager;
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal Resources()
		{
		}
	}
}
namespace Symbiosis.Patches
{
	internal static class Patch_HoarderBug
	{
		[HarmonyPatch(typeof(HoarderBugAI), "DropItem")]
		[HarmonyPrefix]
		private static void PreDropItem(HoarderBugAI __instance, NetworkObject item, Vector3 targetFloorPosition, bool droppingInNest = true)
		{
			if (__instance.heldItem != null)
			{
				Mod_HoarderBug component = ((Component)__instance).gameObject.GetComponent<Mod_HoarderBug>();
				component.lastItem = __instance.heldItem.itemGrabbableObject;
			}
		}

		[HarmonyPatch(typeof(HoarderBugAI), "DropItem")]
		[HarmonyPostfix]
		private static void PostDropItem(HoarderBugAI __instance, NetworkObject item, Vector3 targetFloorPosition, bool droppingInNest = true)
		{
			Mod_HoarderBug component = ((Component)__instance).gameObject.GetComponent<Mod_HoarderBug>();
			if (component.activatingItem && (Object)(object)component.lastItem != (Object)null)
			{
				component.lastItem.UseItemOnClient(false);
			}
			component.activatingItem = false;
			component.lastItem = null;
		}
	}
}
namespace Symbiosis.ModBehaviours
{
	public class Mod_HoarderBug : ModAI
	{
		public bool activatingItem;

		public GrabbableObject lastItem;

		private readonly Random _rand = new Random();

		public override void PreStart()
		{
			NetworkBehaviour original = ((ModBehaviour)this).Original;
			HoarderBugAI val = (HoarderBugAI)(object)((original is HoarderBugAI) ? original : null);
			if (val != null && Plugin.ConfigManager.HoarderBug.ItemUse.Value)
			{
				((MonoBehaviour)val).StartCoroutine(HoarderBugUseItem());
			}
		}

		public override void PostAI()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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)
			NetworkBehaviour original = ((ModBehaviour)this).Original;
			HoarderBugAI val = (HoarderBugAI)(object)((original is HoarderBugAI) ? original : null);
			if (val != null && !((EnemyAI)val).isEnemyDead && !StartOfRound.Instance.allPlayersDead && ((EnemyAI)val).currentBehaviourStateIndex == 1 && Plugin.ConfigManager.HoarderBug.Dispersion.Value && val.GetWaitingAtNest() && Vector3.Distance(((Component)val).transform.position, val.nestPosition) <= 0.5f)
			{
				float nestSize = Util_HoarderBug.GetNestSize(val);
				Vector3 randomPointInArea = Util_NavMesh.GetRandomPointInArea(val.nestPosition, nestSize);
				if (((EnemyAI)val).SetDestinationToPosition(randomPointInArea, true))
				{
					Plugin.Log.LogInfo((object)$"FOUND SPOT TO CHILL {Vector3.Distance(randomPointInArea, ((Component)val).transform.position)} UNITS AWAY FROM ME");
				}
			}
		}

		public override void PostKillEnemy(bool destroy = false)
		{
			NetworkBehaviour original = ((ModBehaviour)this).Original;
			HoarderBugAI val = (HoarderBugAI)(object)((original is HoarderBugAI) ? original : null);
			if (val != null && val.heldItem != null && ((NetworkBehaviour)val).IsOwner && Plugin.ConfigManager.HoarderBug.ItemDeathDrop.Value)
			{
				val.DropItemAndCallDropRPC(((Component)val.heldItem.itemGrabbableObject).GetComponent<NetworkObject>(), false);
			}
		}

		private IEnumerator HoarderBugUseItem()
		{
			NetworkBehaviour original = ((ModBehaviour)this).Original;
			HoarderBugAI hoarder = (HoarderBugAI)(object)((original is HoarderBugAI) ? original : null);
			if (hoarder == null)
			{
				yield break;
			}
			while (((Behaviour)hoarder).isActiveAndEnabled)
			{
				try
				{
					if (!((EnemyAI)hoarder).inSpecialAnimation && !((EnemyAI)hoarder).isEnemyDead && !StartOfRound.Instance.allPlayersDead && hoarder.heldItem != null && (Object)(object)hoarder.heldItem.itemGrabbableObject != (Object)null)
					{
						ManualLogSource log = Plugin.Log;
						HoarderBugItem heldItem = hoarder.heldItem;
						log.LogInfo((object)("USING " + ((heldItem != null) ? ((Object)heldItem.itemGrabbableObject.itemProperties).name : null)));
						activatingItem = _rand.Next(Plugin.ConfigManager.HoarderBug.ItemUnuseChance.Value) != 0;
						hoarder.heldItem.itemGrabbableObject.UseItemOnClient(activatingItem);
					}
				}
				catch (Exception ex)
				{
					Plugin.Log.LogError((object)ex);
				}
				yield return (object)new WaitForSeconds((float)_rand.Next(Plugin.ConfigManager.HoarderBug.MinItemUseInterval.Value, Plugin.ConfigManager.HoarderBug.MaxItemUseInterval.Value));
			}
		}

		protected override void __initializeVariables()
		{
			((ModAI)this).__initializeVariables();
		}

		protected internal override string __getTypeName()
		{
			return "Mod_HoarderBug";
		}
	}
	public class Mod_ExtensionLadder : ModItem
	{
		public override bool PreItemActivate(bool used, bool buttonDown)
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			NetworkBehaviour original = ((ModBehaviour)this).Original;
			ExtensionLadderItem val = (ExtensionLadderItem)(object)((original is ExtensionLadderItem) ? original : null);
			if (val == null)
			{
				return true;
			}
			if ((Object)(object)((GrabbableObject)val).playerHeldBy != (Object)null)
			{
				return true;
			}
			Plugin.Log.LogInfo((object)"ITEM IS NOT HELD BY PLAYER");
			if (!((NetworkBehaviour)val).IsOwner)
			{
				return true;
			}
			Plugin.Log.LogInfo((object)"ITEM IS OWNER");
			HoarderBugAI val2 = Util_HoarderBug.FindHoarderBug((GrabbableObject)(object)val);
			if (val2 == null)
			{
				Plugin.Log.LogInfo((object)"NO BUG FOUND");
				return false;
			}
			Plugin.Log.LogInfo((object)"DROPPING LADDER");
			val2.DropItem(((Component)val).GetComponent<NetworkObject>(), ((GrabbableObject)val).GetItemFloorPosition(default(Vector3)), false);
			return false;
		}

		protected override void __initializeVariables()
		{
			((ModItem)this).__initializeVariables();
		}

		protected internal override string __getTypeName()
		{
			return "Mod_ExtensionLadder";
		}
	}
	public class Mod_StunGrenade : ModItem
	{
		public override bool PreItemActivate(bool used, bool buttonDown)
		{
			NetworkBehaviour original = ((ModBehaviour)this).Original;
			StunGrenadeItem val = (StunGrenadeItem)(object)((original is StunGrenadeItem) ? original : null);
			if (val == null)
			{
				return true;
			}
			if ((Object)(object)((GrabbableObject)val).playerHeldBy != (Object)null)
			{
				return true;
			}
			if (val.inPullingPinAnimation || val.pinPulled)
			{
				Plugin.Log.LogInfo((object)"STUNNADE IS ALREADY PULLED");
				return false;
			}
			if (val.GetPullPinCoroutine() != null)
			{
				Plugin.Log.LogInfo((object)"STUNNADE IS ALREADY IN PULLING ANIMATION");
				return false;
			}
			Plugin.Log.LogInfo((object)"ITEM HAS NO COROUTINE: STARTING NO PLAYER PULLING PIN ANIMATION");
			val.SetPullPinCoroutine(((MonoBehaviour)val).StartCoroutine(val.NoPlayerPullPinAnimation()));
			return false;
		}

		protected override void __initializeVariables()
		{
			((ModItem)this).__initializeVariables();
		}

		protected internal override string __getTypeName()
		{
			return "Mod_StunGrenade";
		}
	}
}
namespace Symbiosis.Extensions
{
	public static class Extension_HoarderBugAI
	{
		public static readonly FieldInfo info_waitingAtNest = typeof(HoarderBugAI).GetField("waitingAtNest", BindingFlags.Instance | BindingFlags.NonPublic);

		public static void SetWaitingAtNest(this HoarderBugAI bug, bool value)
		{
			info_waitingAtNest?.SetValue(bug, value);
		}

		public static bool GetWaitingAtNest(this HoarderBugAI bug)
		{
			return (bool)info_waitingAtNest?.GetValue(bug);
		}
	}
	public static class Extension_StunGrenadeItem
	{
		public static readonly FieldInfo info_pullPinCoroutine = typeof(StunGrenadeItem).GetField("pullPinCoroutine", BindingFlags.Instance | BindingFlags.NonPublic);

		public static void SetPullPinCoroutine(this StunGrenadeItem item, Coroutine coroutine)
		{
			info_pullPinCoroutine?.SetValue(item, coroutine);
		}

		public static Coroutine GetPullPinCoroutine(this StunGrenadeItem item)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			return (Coroutine)(info_pullPinCoroutine?.GetValue(item));
		}

		public static IEnumerator NoPlayerPullPinAnimation(this StunGrenadeItem item)
		{
			item.inPullingPinAnimation = true;
			item.itemAnimator.SetTrigger("pullPin");
			item.itemAudio.PlayOneShot(item.pullPinSFX);
			WalkieTalkie.TransmitOneShotAudio(item.itemAudio, item.pullPinSFX, 0.8f);
			yield return (object)new WaitForSeconds(1f);
			item.inPullingPinAnimation = false;
			item.pinPulled = true;
			((GrabbableObject)item).itemUsedUp = true;
		}
	}
}