Decompiled source of EnemyPOVs v1.5.0

EnemyPOVs.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using EnemyPOVs;
using HBMF.GameResources;
using HBMF.ModMenu;
using HarmonyLib;
using Il2Cpp;
using MelonLoader;
using MelonLoader.Preferences;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Mod), "EnemyPOVs", "1.5.0", "korbykob", null)]
[assembly: MelonGame("GexagonVR", "Hard Bullet")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("EnemyPOVs")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EnemyPOVs")]
[assembly: AssemblyTitle("EnemyPOVs")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace EnemyPOVs;

[HarmonyPatch]
public class Mod : MelonMod
{
	private static Transform currentCamera;

	private static MelonPreferences_Entry<bool> enabled;

	private static MelonPreferences_Entry<float> deathSwapDelay;

	private static bool active;

	private static HealthContainer container;

	private static object coroutine;

	public override void OnInitializeMelon()
	{
		MelonPreferences_Category val = MelonPreferences.CreateCategory("EnemyPOVs");
		enabled = val.CreateEntry<bool>("Enabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		deathSwapDelay = val.CreateEntry<float>("DeathSwapDelay", 5f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		Menu.CreateCategory("ENEMY POVS").CreateBool("ENABLE", enabled.Value, (Action<bool>)delegate(bool value)
		{
			enabled.Value = value;
			Transform obj = currentCamera;
			if (obj != null)
			{
				((Component)obj).gameObject.SetActive(value && active);
			}
			if (value && !active)
			{
				GetNewEnemy();
			}
		}).CreateFloat("DEATH SWAP DELAY", deathSwapDelay.Value, 0f, float.PositiveInfinity, 0.1f, " seconds", (Action<float>)delegate(float value)
		{
			deathSwapDelay.Value = value;
		});
		GameResources.ResourcesReady = (Action)Delegate.Combine(GameResources.ResourcesReady, (Action)delegate
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = Object.Instantiate<GameObject>(((Component)GameResources.Camera.Find("RecordingCamera")).gameObject, currentCamera).transform;
			((Component)transform).gameObject.SetActive(true);
			transform.localPosition = Vector3.zero;
			transform.localRotation = Quaternion.identity;
			((Component)transform).GetComponent<Camera>().fieldOfView = 100f;
		});
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		currentCamera = new GameObject().transform;
		((Component)currentCamera).gameObject.SetActive(false);
		active = false;
	}

	private static IEnumerator Death()
	{
		yield return (object)new WaitForSeconds(deathSwapDelay.Value);
		GetNewEnemy();
	}

	private static void GetNewEnemy()
	{
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: 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)
		active = false;
		if (enabled.Value)
		{
			Transform val = null;
			HealthContainer val2 = null;
			for (int i = 0; i < GameResources.Enemies.childCount; i++)
			{
				Transform child = GameResources.Enemies.GetChild(i);
				HealthContainer component = ((Component)child.Find("[SYSTEMS]/AI/Health")).GetComponent<HealthContainer>();
				if (!component.IsHealthContainerEmpty)
				{
					Transform val3 = child.Find("[BODY]/PhysicalBones/head");
					if ((Object)(object)val == (Object)null || Vector3.Distance(val3.position, GameResources.Head.position) < Vector3.Distance(val.position, GameResources.Head.position))
					{
						val = val3;
						val2 = component;
					}
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				active = true;
				currentCamera.SetParent(val);
				currentCamera.localPosition = new Vector3(-0.1f, -0.15f, 0f);
				currentCamera.localEulerAngles = new Vector3(90f, -90f, 0f);
				((Component)currentCamera).gameObject.SetActive(true);
				container = val2;
			}
			else
			{
				((Component)currentCamera).gameObject.SetActive(false);
				active = false;
			}
		}
		coroutine = null;
	}

	[HarmonyPatch(typeof(HealthContainer), "OnEnable")]
	[HarmonyPostfix]
	public static void GetEnemy()
	{
		if (!active && (Object)(object)GameResources.Enemies != (Object)null)
		{
			GetNewEnemy();
		}
	}

	[HarmonyPatch(typeof(HealthContainer), "OnDamageTakenReact", new Type[]
	{
		typeof(Damage),
		typeof(DamageSender)
	})]
	[HarmonyPostfix]
	public static void CheckDead(HealthContainer __instance)
	{
		if (enabled.Value && (Object)(object)__instance == (Object)(object)container && __instance._currentHealthCount <= 0f && coroutine == null)
		{
			coroutine = MelonCoroutines.Start(Death());
		}
	}

	[HarmonyPatch(typeof(HealthContainer), "OnDisable")]
	[HarmonyPostfix]
	public static void CheckDisabled(HealthContainer __instance)
	{
		if (enabled.Value && (Object)(object)__instance == (Object)(object)container)
		{
			if (coroutine != null)
			{
				MelonCoroutines.Stop(coroutine);
			}
			GetNewEnemy();
		}
	}
}