Decompiled source of PeakMonAmiralStuff v1.0.0

com.github.monamiral.PeakMonAmiralStuff.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using PEAKLib.Core;
using PEAKLib.Items;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("com.github.monamiral.PeakMonAmiralStuff")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("com.github.monamiral.PeakMonAmiralStuff")]
[assembly: AssemblyTitle("PeakMonAmiralStuff")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PeakMonAmiralStuff;

public class Action_ToggleParticleEmission : ItemAction
{
	public bool Toggle;

	public override void RunAction()
	{
		ParticleSystem componentInChildren = ((Component)this).GetComponentInChildren<ParticleSystem>();
		if (Toggle)
		{
			componentInChildren.Play();
			Debug.Log((object)"Toggling particles on");
		}
		else
		{
			componentInChildren.Stop();
			Debug.Log((object)"Toggling particles off");
		}
	}
}
public class DementiaNightmare : MonoBehaviour
{
	private SpriteRenderer sprite;

	private bool isVisible;

	private void Start()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		sprite = ((Component)this).GetComponentInChildren<SpriteRenderer>();
		sprite.color = Color.clear;
		((MonoBehaviour)this).InvokeRepeating("Appear", (float)Random.Range(200, 300), 300f);
	}

	private void Update()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: 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_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		if (isVisible)
		{
			Vector3 val = ((Component)MainCamera.instance).transform.position - ((Component)this).transform.position;
			val.y = 0f;
			((Component)this).transform.rotation = Quaternion.LookRotation(val, Vector3.up);
			Vector3 val2 = Camera.main.WorldToViewportPoint(((Component)this).transform.position);
			if (val2.z >= 0f && val2.x > 0f && val2.x < 1f && val2.y > 0f && val2.y < 1f)
			{
				((MonoBehaviour)this).StartCoroutine(Disappear());
			}
		}
		if (Input.GetKey((KeyCode)304) && Input.GetKeyDown((KeyCode)107))
		{
			Appear();
		}
	}

	private void OnDestroy()
	{
		Debug.Log((object)"[MonAmiral] DementiaNightmare was destroyed.");
	}

	private void Appear()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: 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)
		//IL_0039: 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_0041: 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_0050: 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_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		Vector3 position = ((Component)MainCamera.instance).transform.position;
		Vector3 forward = ((Component)MainCamera.instance).transform.forward;
		forward.y = 0f;
		((Vector3)(ref forward)).Normalize();
		RaycastHit val = default(RaycastHit);
		for (int num = 20; num >= 5; num -= 2)
		{
			if (Physics.SphereCast(position - forward * (float)num + Vector3.up * 10f, 2f, Vector3.down, ref val, 20f))
			{
				Debug.Log((object)$"[MonAmiral] DementiaNightmare appeared {num}m behind the player.");
				isVisible = true;
				((Component)this).transform.position = ((RaycastHit)(ref val)).point;
				sprite.color = Color.white;
				return;
			}
		}
		Debug.LogWarning((object)"[MonAmiral] DementiaNightmare did not find a valid position to spawn.");
	}

	private IEnumerator Disappear()
	{
		Debug.Log((object)"[MonAmiral] DementiaNightmare started disappearing.");
		isVisible = false;
		float elapsedTime = 0f;
		while (elapsedTime < 0.5f)
		{
			sprite.color = new Color(1f, 1f, 1f, 1f - elapsedTime / 0.5f);
			elapsedTime += Time.deltaTime;
			yield return null;
		}
		sprite.color = Color.clear;
	}
}
[BepInPlugin("com.github.monamiral.peakmonamiralstuff", "PeakMonAmiralStuff", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	internal class Patcher
	{
		[HarmonyPatch(typeof(Character), "Start")]
		[HarmonyPostfix]
		public static void CharacterStartPostfix(Character __instance)
		{
			Debug.Log((object)"[MonAmiral] Spawning DementiaNightmare.");
			GameObject obj = Object.Instantiate<GameObject>(Bundle.LoadAsset<GameObject>("Assets/_MonAmiral/DementiaNightmare/DementiaNightmare.prefab"));
			obj.AddComponent<DementiaNightmare>();
			Object.DontDestroyOnLoad((Object)(object)obj);
			Debug.Log((object)"[MonAmiral] Done spawning DementiaNightmare.");
		}

		[HarmonyPatch(typeof(LocalizedText), "GetText", new Type[]
		{
			typeof(string),
			typeof(bool)
		})]
		[HarmonyPrefix]
		private static bool LocalizedTextGetTextPrefix(string id, ref string __result)
		{
			string text = id.ToUpperInvariant();
			if (!(text == "NAME_BLUNT"))
			{
				if (text == "SMOKE")
				{
					__result = "SMOKE";
					return false;
				}
				if (LocalizedText.mainTable.ContainsKey(text))
				{
					return true;
				}
				__result = text;
				return false;
			}
			__result = "BLUNT";
			return false;
		}
	}

	public static Plugin Instance { get; private set; }

	internal static ManualLogSource Log { get; private set; }

	internal static AssetBundle Bundle { get; set; }

	internal static ModDefinition Definition { get; set; }

	private void Awake()
	{
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		Definition = ModDefinition.GetOrCreate(((BaseUnityPlugin)this).Info.Metadata);
		Bundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "peakmonamiralstuff"));
		Item component = Bundle.LoadAsset<GameObject>("Assets/_MonAmiral/Blunt/Blunt.prefab").GetComponent<Item>();
		Action_ToggleParticleEmission action_ToggleParticleEmission = ((Component)component).gameObject.AddComponent<Action_ToggleParticleEmission>();
		((ItemAction)action_ToggleParticleEmission).OnPressed = true;
		action_ToggleParticleEmission.Toggle = true;
		Action_ToggleParticleEmission action_ToggleParticleEmission2 = ((Component)component).gameObject.AddComponent<Action_ToggleParticleEmission>();
		((ItemAction)action_ToggleParticleEmission2).OnCancelled = true;
		((ItemAction)action_ToggleParticleEmission2).OnCastFinished = true;
		new ItemContent(component).Register(Definition);
		new Harmony("monamiral.peakmonamiralstuff").PatchAll(typeof(Patcher));
	}
}