Decompiled source of SpawnGBBirds v1.0.2

Mods/SpawnGBSharks.dll

Decompiled a week ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using HarmonyLib;
using Il2Cpp;
using Il2CppFemur;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MelonLoader;
using Microsoft.CodeAnalysis;
using SpawnGBShark;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(SpawnGBSharkMod), "SpawnGBShark", "1.0.0", "Zooks", null)]
[assembly: MelonGame("Boneloaf", "Gang Beasts")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("SpawnGBSharks")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("SpawnGBSharks for GB")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SpawnGBSharks")]
[assembly: AssemblyTitle("SpawnGBSharks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 SpawnGBShark
{
	public class SpawnGBSharkMod : MelonMod
	{
		private GameObject template = null;

		private bool hasAutoSpawned = false;

		public static SpawnGBSharkMod Instance { get; private set; }

		public override void OnInitializeMelon()
		{
			Instance = this;
			((MelonBase)this).HarmonyInstance.PatchAll(Assembly.GetExecutingAssembly());
			MelonLogger.Msg("SpawnGBShark Loaded");
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			template = null;
			hasAutoSpawned = false;
		}

		public override void OnUpdate()
		{
			if (Keyboard.current != null && (((ButtonControl)Keyboard.current.minusKey).wasPressedThisFrame || ((ButtonControl)Keyboard.current.numpadMinusKey).wasPressedThisFrame))
			{
				TriggerSharkSpawn();
			}
		}

		public void OnNativeSharkDiscovered(GameObject original)
		{
			if (!(((Object)original).name == "GB_Shark_Template") && !(((Object)original).name == "Spawned_Shark") && !((Object)(object)template != (Object)null))
			{
				template = Object.Instantiate<GameObject>(original);
				((Object)template).name = "GB_Shark_Template";
				template.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)template);
				if (!hasAutoSpawned)
				{
					hasAutoSpawned = true;
					AutoSpawnSceneSharks(original);
				}
			}
		}

		private void AutoSpawnSceneSharks(GameObject original)
		{
			//IL_0037: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = default(Vector3);
			for (int i = 0; i < 2; i++)
			{
				((Vector3)(ref val))..ctor(Random.Range(-6f, 6f), 10f, Random.Range(-6f, 6f));
				SpawnAt(original.transform.position + val, original.transform.rotation);
			}
		}

		private Actor DeepFindPlayer()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			Actor val = Object.FindObjectOfType<Actor>();
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			Il2CppArrayBase<GameObject> val2 = Resources.FindObjectsOfTypeAll<GameObject>();
			foreach (GameObject item in val2)
			{
				Scene scene = item.scene;
				if (((Scene)(ref scene)).name != null)
				{
					Actor component = item.GetComponent<Actor>();
					if ((Object)(object)component != (Object)null)
					{
						return component;
					}
				}
			}
			return null;
		}

		private void TriggerSharkSpawn()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)template == (Object)null)
			{
				return;
			}
			Vector3 val = Vector3.zero;
			Camera main = Camera.main;
			if ((Object)(object)main != (Object)null && Mouse.current != null)
			{
				Vector2 val2 = ((InputControl<Vector2>)(object)((Pointer)Mouse.current).position).ReadValue();
				Ray val3 = main.ScreenPointToRay(new Vector3(val2.x, val2.y, 0f));
				RaycastHit val4 = default(RaycastHit);
				if (Physics.Raycast(val3, ref val4))
				{
					val = ((RaycastHit)(ref val4)).point + Vector3.up * 10f;
				}
			}
			if (val == Vector3.zero)
			{
				Actor val5 = DeepFindPlayer();
				if ((Object)(object)val5 != (Object)null)
				{
					val = ((Component)val5).transform.position + Vector3.up * 12f;
				}
			}
			if (val == Vector3.zero)
			{
				((Vector3)(ref val))..ctor(0f, 18f, 0f);
			}
			SpawnAt(val, Quaternion.identity);
		}

		private void SpawnAt(Vector3 position, Quaternion rotation)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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)
			GameObject val = Object.Instantiate<GameObject>(template);
			((Object)val).name = "Spawned_Shark";
			val.transform.position = position;
			val.transform.rotation = rotation;
			SharkActor componentInChildren = val.GetComponentInChildren<SharkActor>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				componentInChildren.startDelay = 0;
			}
			Il2CppArrayBase<Rigidbody> componentsInChildren = val.GetComponentsInChildren<Rigidbody>();
			foreach (Rigidbody item in componentsInChildren)
			{
				item.isKinematic = false;
				item.velocity = Vector3.zero;
				item.angularVelocity = Vector3.zero;
				item.WakeUp();
			}
			Il2CppArrayBase<SimpleBuoyancy> componentsInChildren2 = val.GetComponentsInChildren<SimpleBuoyancy>();
			foreach (SimpleBuoyancy item2 in componentsInChildren2)
			{
				((Behaviour)item2).enabled = true;
			}
			Il2CppArrayBase<MonoBehaviour> componentsInChildren3 = val.GetComponentsInChildren<MonoBehaviour>();
			foreach (MonoBehaviour item3 in componentsInChildren3)
			{
				((Behaviour)item3).enabled = true;
			}
			val.SetActive(true);
			SharkActor componentInChildren2 = val.GetComponentInChildren<SharkActor>();
			if (!((Object)(object)componentInChildren2 != (Object)null))
			{
				return;
			}
			componentInChildren2.startDelay = 0;
			componentInChildren2.minSleepingTime = 0f;
			componentInChildren2.maxSleepingTime = 0f;
			componentInChildren2.sleepTime = 0f;
			componentInChildren2.stateTimer = 0f;
			componentInChildren2.unconsciousTimer = 0f;
			componentInChildren2.health = componentInChildren2.maxHealth;
			componentInChildren2.target = null;
			componentInChildren2.rigidbodyInMouth = null;
			componentInChildren2.biteJoint = null;
			componentInChildren2.useBuoyancy = true;
			componentInChildren2.currentState = (State)1;
			componentInChildren2.nextState = (State)1;
			componentInChildren2.DelayedStart();
			bool flag = false;
			if (componentInChildren2.searchNodes != null && ((Il2CppArrayBase<Transform>)(object)componentInChildren2.searchNodes).Count > 0)
			{
				Transform val2 = ((Il2CppArrayBase<Transform>)(object)componentInChildren2.searchNodes)[0];
				if ((Object)(object)val2 != (Object)null && (Object)(object)((Component)val2).gameObject != (Object)null)
				{
					flag = true;
				}
			}
			if (!flag)
			{
				componentInChildren2.searchNodes = new Il2CppReferenceArray<Transform>(0L);
				componentInChildren2.retreatNodes = new Il2CppReferenceArray<Transform>(0L);
				componentInChildren2.diveNodes = new Il2CppReferenceArray<Transform>(0L);
				componentInChildren2.breachNodes = new Il2CppReferenceArray<Transform>(0L);
			}
		}
	}
	[HarmonyPatch(typeof(SharkActor), "Start")]
	public static class SharkActorStartPatch
	{
		public static void Prefix(SharkActor __instance)
		{
			__instance.startDelay = 0;
			__instance.minSleepingTime = 0f;
			__instance.maxSleepingTime = 0f;
			__instance.sleepTime = 0f;
			if (SpawnGBSharkMod.Instance != null)
			{
				SpawnGBSharkMod.Instance.OnNativeSharkDiscovered(((Component)__instance).gameObject);
			}
		}
	}
	[HarmonyPatch(typeof(SharkActor), "Sleeping")]
	public static class SharkActorSleepingPatch
	{
		public static bool Prefix(SharkActor __instance)
		{
			__instance.currentState = (State)1;
			__instance.nextState = (State)1;
			return false;
		}
	}
}