Decompiled source of EarlyMoon v1.0.1

EarlyMoon.dll

Decompiled 8 hours ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HG.Reflection;
using Logger;
using Microsoft.CodeAnalysis;
using On.RoR2;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.ContentManagement;
using RoR2BepInExPack.GameAssetPathsBetter;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("EarlyMoon")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+481458098e409133760d2b3ab162d74375c7867a")]
[assembly: AssemblyProduct("EarlyMoon")]
[assembly: AssemblyTitle("EarlyMoon")]
[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 Logger
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
}
namespace EarlyMoon
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal static class Options
	{
		public static bool IsEnabled => Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions");

		public static void Init()
		{
			EarlyMoon.moonTpStage = ((BaseUnityPlugin)EarlyMoon.Instance).Config.Bind<int>("General", "Stages until Lunar Tp", 5, "The number of stages you have to beat between each occurence of a lunar teleporters, vanilla is 5");
			if (IsEnabled)
			{
				RiskOfOptionsConfig();
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void RiskOfOptionsConfig()
		{
			//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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			//IL_0103: 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)
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(EarlyMoon.moonTpStage, new IntSliderConfig
			{
				min = 0,
				max = 10
			}), "Onyx.EarlyMoon", "EarlyMoon");
			ModSettingsManager.SetModDescription("Options for EarlyMoon", "Onyx.EarlyMoon", "EarlyMoon");
			FileInfo fileInfo = null;
			DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
			do
			{
				FileInfo[] files = directoryInfo.GetFiles("icon.png", SearchOption.TopDirectoryOnly);
				if (files != null && files.Length != 0)
				{
					fileInfo = files[0];
					break;
				}
				directoryInfo = directoryInfo.Parent;
			}
			while (directoryInfo != null && directoryInfo.Exists && !string.Equals(directoryInfo.Name, "plugins", StringComparison.OrdinalIgnoreCase));
			if (fileInfo != null)
			{
				Texture2D val = new Texture2D(256, 256);
				if (ImageConversion.LoadImage(val, File.ReadAllBytes(fileInfo.FullName)))
				{
					Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
					((Object)val2).name = "EarlyMoonIcon";
					ModSettingsManager.SetModIcon(val2, "Onyx.EarlyMoon", "EarlyMoon");
				}
			}
		}
	}
	[BepInPlugin("Onyx.EarlyMoon", "EarlyMoon", "1.0.1")]
	public sealed class EarlyMoon : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Action<AsyncOperationHandle<InteractableSpawnCard>> <>9__11_0;

			public static Action<AsyncOperationHandle<InteractableSpawnCard>> <>9__11_1;

			public static hook_PlaceTeleporter <>9__11_2;

			internal void <Awake>b__11_0(AsyncOperationHandle<InteractableSpawnCard> x)
			{
				defaultTp = x.Result;
			}

			internal void <Awake>b__11_1(AsyncOperationHandle<InteractableSpawnCard> x)
			{
				MoonTp = x.Result;
			}

			internal void <Awake>b__11_2(orig_PlaceTeleporter orig, SceneDirector self)
			{
				if (!Object.op_Implicit((Object)(object)self.teleporterSpawnCard))
				{
					orig.Invoke(self);
					return;
				}
				if (SceneCatalog.GetSceneDefForCurrentScene().stageOrder % moonTpStage.Value == 0)
				{
					self.teleporterSpawnCard = (SpawnCard)(object)MoonTp;
				}
				else
				{
					self.teleporterSpawnCard = (SpawnCard)(object)defaultTp;
				}
				orig.Invoke(self);
			}
		}

		public const string PluginGUID = "Onyx.EarlyMoon";

		public const string PluginAuthor = "Onyx";

		public const string PluginName = "EarlyMoon";

		public const string PluginVersion = "1.0.1";

		public static EarlyMoon Instance;

		private static InteractableSpawnCard defaultTp;

		private static InteractableSpawnCard MoonTp;

		public static ConfigEntry<int> moonTpStage { get; set; }

		public void Awake()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			Instance = SingletonHelper.Assign<EarlyMoon>(Instance, this);
			Options.Init();
			AssetReferenceT<InteractableSpawnCard> val = new AssetReferenceT<InteractableSpawnCard>(RoR2_Base_Teleporters.iscTeleporter_asset);
			AsyncOperationHandle<InteractableSpawnCard> val2 = AssetAsyncReferenceManager<InteractableSpawnCard>.LoadAsset(val, (AsyncReferenceHandleUnloadType)2);
			val2.Completed += delegate(AsyncOperationHandle<InteractableSpawnCard> x)
			{
				defaultTp = x.Result;
			};
			val = new AssetReferenceT<InteractableSpawnCard>(RoR2_Base_Teleporters.iscLunarTeleporter_asset);
			val2 = AssetAsyncReferenceManager<InteractableSpawnCard>.LoadAsset(val, (AsyncReferenceHandleUnloadType)2);
			val2.Completed += delegate(AsyncOperationHandle<InteractableSpawnCard> x)
			{
				MoonTp = x.Result;
			};
			object obj = <>c.<>9__11_2;
			if (obj == null)
			{
				hook_PlaceTeleporter val3 = delegate(orig_PlaceTeleporter orig, SceneDirector self)
				{
					if (!Object.op_Implicit((Object)(object)self.teleporterSpawnCard))
					{
						orig.Invoke(self);
					}
					else
					{
						if (SceneCatalog.GetSceneDefForCurrentScene().stageOrder % moonTpStage.Value == 0)
						{
							self.teleporterSpawnCard = (SpawnCard)(object)MoonTp;
						}
						else
						{
							self.teleporterSpawnCard = (SpawnCard)(object)defaultTp;
						}
						orig.Invoke(self);
					}
				};
				<>c.<>9__11_2 = val3;
				obj = (object)val3;
			}
			SceneDirector.PlaceTeleporter += (hook_PlaceTeleporter)obj;
		}
	}
}