Decompiled source of ShrineHunt v0.2.0

MegabonkShrineHunt.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Assets.Scripts.Actors.Player;
using Assets.Scripts.Camera;
using Assets.Scripts.Managers;
using Assets.Scripts.Saves___Serialization.Progression.Stats;
using Assets.Scripts.UI.InGame.Rewards;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("MegabonkShrineHunt")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("My first plugin")]
[assembly: AssemblyTitle("MegabonkShrineHunt")]
[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 MegabonkShrineHunt
{
	[BepInPlugin("MegabonkShrineHunt", "MegabonkShrineHunt", "0.2.0")]
	public class ShrineHunt : BasePlugin
	{
		internal static ManualLogSource Logger;

		internal static bool disableShrineChargedTracker;

		internal static bool enableDoubleReward;

		internal static ChargeShrine shrine;

		public override void Load()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			Logger = ((BasePlugin)this).Log;
			Harmony val = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			ManualLogSource logger = Logger;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(45, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Initialized MegabonkShrineHunt with ");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(val.GetPatchedMethods().Count());
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" patches.");
			}
			logger.LogInfo(val2);
		}

		internal static bool SelectNewShrine()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			ClearShrine();
			ChargeShrine[] array = ((IEnumerable<ChargeShrine>)Object.FindObjectsOfType<ChargeShrine>(false)).Where((ChargeShrine x) => !x.completed).ToArray();
			ManualLogSource logger = Logger;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Found ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(array.Length);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" uncompleted shrines.");
			}
			logger.LogInfo(val);
			if (array.Length == 0)
			{
				return false;
			}
			MyPlayer player = MyPlayer.Instance;
			if (array.Length == 1)
			{
				shrine = array[0];
			}
			else
			{
				array = array.OrderBy(delegate(ChargeShrine x)
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					//IL_0016: Unknown result type (might be due to invalid IL or missing references)
					//IL_001b: 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)
					Vector3 val2 = ((Component)x).transform.position - ((Component)player).transform.position;
					return ((Vector3)(ref val2)).sqrMagnitude;
				}).ToArray();
				if (array.Length == 2)
				{
					shrine = array[1];
				}
				else
				{
					shrine = array[Random.RandomRangeInt(array.Length / 2, array.Length)];
				}
			}
			Transform transform = ((Component)shrine).transform;
			transform.localScale *= 1.5f;
			((Renderer)shrine.altarIcon.GetComponent<MeshRenderer>()).material.color = Color.yellow;
			((Renderer)shrine.minimapIcon.GetComponent<MeshRenderer>()).material.color = Color.yellow;
			MinimapCamera componentInChildren = ((Component)player).gameObject.GetComponentInChildren<MinimapCamera>(false);
			componentInChildren.AddArrow(((Component)shrine).transform, Color.yellow);
			((Renderer)componentInChildren.arrowDict[((Component)shrine).transform].arrowRenderer).material.color = Color.yellow;
			return true;
		}

		internal static void ClearShrine()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			if (shrine != null)
			{
				if (!Object.op_Implicit((Object)(object)shrine))
				{
					shrine = null;
					return;
				}
				Transform transform = ((Component)shrine).transform;
				transform.localScale /= 1.5f;
				((Renderer)shrine.altarIcon.GetComponent<MeshRenderer>()).material.color = Color.white;
				((Renderer)shrine.minimapIcon.GetComponent<MeshRenderer>()).material.color = Color.green;
				((Component)MyPlayer.Instance).gameObject.GetComponentInChildren<MinimapCamera>(false).RemoveArrow(((Component)shrine).transform);
				shrine = null;
			}
		}
	}
	[HarmonyPatch]
	internal static class ShrineHuntPatches
	{
		[HarmonyPatch(typeof(SpawnPlayerPortal), "Update")]
		[HarmonyPostfix]
		private static void SpawnPlayerPortal_Update_Postfix(SpawnPlayerPortal __instance)
		{
			if (!__instance.open && ShrineHunt.shrine == null)
			{
				ShrineHunt.SelectNewShrine();
			}
		}

		[HarmonyPatch(typeof(MapController), "LoadNextStage")]
		[HarmonyPostfix]
		private static void MapController_LoadNextStage_Prefix()
		{
			ShrineHunt.ClearShrine();
		}

		[HarmonyPatch(typeof(MapController), "LoadFinalStage")]
		[HarmonyPostfix]
		private static void MapController_LoadFinalStage_Prefix()
		{
			ShrineHunt.ClearShrine();
		}

		[HarmonyPatch(typeof(ChargeShrine), "Complete")]
		[HarmonyPostfix]
		private static void ChargeShrine_Complete_Postfix(ChargeShrine __instance)
		{
			if (!((Object)(object)ShrineHunt.shrine != (Object)(object)__instance))
			{
				if (ShrineHunt.enableDoubleReward)
				{
					ShrineHunt.disableShrineChargedTracker = false;
					ShrineHunt.enableDoubleReward = false;
					ShrineHunt.SelectNewShrine();
				}
				else
				{
					ShrineHunt.enableDoubleReward = true;
				}
			}
		}

		[HarmonyPatch(typeof(EncounterUi), "Open")]
		[HarmonyPrefix]
		private static void EncounterUi_Open_Prefix(EEncounter encounterType)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)encounterType != 1 || !ShrineHunt.enableDoubleReward)
			{
				ShrineHunt.enableDoubleReward = false;
			}
		}

		[HarmonyPatch(typeof(EncounterUi), "OnClose")]
		[HarmonyPostfix]
		private static void EncounterUi_OnClose_Postfix()
		{
			if (ShrineHunt.enableDoubleReward)
			{
				ShrineHunt.disableShrineChargedTracker = true;
				ShrineHunt.shrine.completed = false;
				ShrineHunt.shrine.rewardGiven = false;
				ShrineHunt.shrine.rewardTime = 0f;
				ShrineHunt.shrine.Complete();
			}
		}

		[HarmonyPatch(typeof(TrackStats), "OnShrineCharged")]
		[HarmonyPrefix]
		private static bool TrackStats_OnShrineCharged_Prefix()
		{
			if (ShrineHunt.disableShrineChargedTracker)
			{
				return false;
			}
			return true;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "MegabonkShrineHunt";

		public const string PLUGIN_NAME = "My first plugin";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}