Decompiled source of PeakSeedPicker v1.3.0

PeakSeedPicker.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using Zorro.Core;
using Zorro.Core.Editor;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.turtledsr.peakseedpicker")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0+b80ef8a288a945f2b29c9934ab8bf4d40ee1bdff")]
[assembly: AssemblyProduct("PeakSeedPicker")]
[assembly: AssemblyTitle("com.turtledsr.peakseedpicker")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.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 peakseedpicker
{
	public sealed class Version : ICloneable, IComparable<Version>, IEquatable<Version>
	{
		public int major;

		public int minor;

		public char build;

		public Version(int major, int minor, char build)
		{
			this.major = major;
			this.minor = minor;
			this.build = build;
		}

		public Version(string version)
		{
			string[] array = version.Trim('.').Split('.');
			major = Convert.ToInt32(array[0]);
			minor = Convert.ToInt32(array[1]);
			build = array[2][0];
		}

		object ICloneable.Clone()
		{
			return new Version(major, minor, build);
		}

		public int CompareTo(Version other)
		{
			int result;
			if ((result = minor - other.minor) != 0)
			{
				return result;
			}
			if ((result = minor - other.minor) != 0)
			{
				return result;
			}
			if ((result = build - other.build) != 0)
			{
				return result;
			}
			return 0;
		}

		public bool Equals(Version other)
		{
			if (other.major == major && other.minor == minor && other.build == build)
			{
				return true;
			}
			return false;
		}

		public override bool Equals(object o)
		{
			if (o == null)
			{
				return false;
			}
			Version version = o as Version;
			return version != null && this == version;
		}

		public override int GetHashCode()
		{
			return EqualityComparer<Version>.Default.GetHashCode(this);
		}

		public override string ToString()
		{
			return $"v{major}.{minor}.{build}";
		}

		public static bool operator >(Version v1, Version v2)
		{
			return v1.CompareTo(v2) > 0;
		}

		public static bool operator <(Version v1, Version v2)
		{
			return v1.CompareTo(v2) < 0;
		}

		public static bool operator >=(Version v1, Version v2)
		{
			return v1.CompareTo(v2) >= 0;
		}

		public static bool operator <=(Version v1, Version v2)
		{
			return v1.CompareTo(v2) <= 0;
		}

		public static bool operator ==(Version v1, Version v2)
		{
			return v1.Equals(v2);
		}

		public static bool operator !=(Version v1, Version v2)
		{
			return !v1.Equals(v2);
		}
	}
	[BepInPlugin("com.turtledsr.peakseedpicker", "PeakSeedPicker", "1.3.0")]
	public class Plugin : BaseUnityPlugin
	{
		public enum LevelChoice
		{
			level_0,
			level_1,
			level_2,
			level_3,
			level_4,
			level_5,
			level_6,
			level_7,
			level_8,
			level_9,
			level_10,
			level_11,
			level_12,
			level_13,
			level_14,
			level_15,
			level_16,
			level_17,
			level_18,
			level_19,
			level_20,
			daily
		}

		[HarmonyPatch(typeof(MapBaker), "GetLevel")]
		private static class MapBaker_GetLevel_v1dot6_plus_Patch
		{
			private static bool Prefix(MapBaker __instance, ref string __result)
			{
				if (level == LevelChoice.daily || (version < v1dot7 && level > LevelChoice.level_13))
				{
					return true;
				}
				Logger.LogInfo((object)"Using v1.6.x+ Level-Loader");
				__result = PathUtil.WithoutExtensions(PathUtil.GetFileName(__instance.AllLevels[(int)level]));
				return false;
			}
		}

		[HarmonyPatch(typeof(MapBaker), "GetLevel")]
		private static class MapBaker_GetLevel_PRE_v1dot6_Patch
		{
			private static bool Prefix(MapBaker __instance, ref string __result)
			{
				if (level == LevelChoice.daily || (version < v1dot7 && level > LevelChoice.level_13))
				{
					return true;
				}
				Logger.LogInfo((object)"Using PRE-v1.6.x Level-Loader");
				SceneReference[] array = (SceneReference[])((object)__instance).GetType().GetField("AllLevels").GetValue(__instance);
				__result = PathUtil.WithoutExtensions(PathUtil.GetFileName(array[(int)level].ScenePath));
				return false;
			}
		}

		public static Version version;

		public static Version v1dot7 = new Version("1.7.a");

		internal static ManualLogSource Logger;

		internal static Harmony harmony = new Harmony("com.turtledsr.peakseedpicker");

		public static ConfigEntry<LevelChoice> levelConfig;

		public static LevelChoice level;

		public static Vector2 overlayPos;

		public static bool timerActive;

		private void Awake()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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)
			Logger = ((BaseUnityPlugin)this).Logger;
			Resolution currentResolution = Screen.currentResolution;
			overlayPos = new Vector2((float)(((Resolution)(ref currentResolution)).width - 210), 10f);
			levelConfig = ((BaseUnityPlugin)this).Config.Bind<LevelChoice>("General", "Seed", LevelChoice.daily, "Seed that gets loaded, Versions prior to 1.7.a only have level_0 to level_13, any other value will be counted as daily");
			level = levelConfig.Value;
			levelConfig.SettingChanged += delegate
			{
				level = levelConfig.Value;
			};
			Logger.LogInfo((object)"Plugin com.turtledsr.peakseedpicker is loaded!");
		}

		private void Start()
		{
			if (Chainloader.PluginInfos.ContainsKey("com.turtledsr.peaktimer"))
			{
				Logger.LogInfo((object)"PeakTimer Found. Moving UI");
				overlayPos.y = 40f;
				timerActive = true;
			}
			version = new Version(Application.version);
			PatchMapBaker();
			Logger.LogInfo((object)("Using version: " + Application.version));
		}

		private void OnGUI()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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_0018: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val = new GUIStyle
			{
				fontSize = 30,
				fontStyle = (FontStyle)1
			};
			if (!timerActive)
			{
				val.alignment = (TextAnchor)5;
			}
			val.normal.textColor = Color.white;
			GUI.Label(new Rect(overlayPos.x, overlayPos.y, 200f, 30f), (version < v1dot7 && level > LevelChoice.level_13) ? "daily" : level.ToString(), val);
		}

		private static void PatchMapBaker()
		{
			if (version >= new Version("1.6.a"))
			{
				Logger.LogInfo((object)"Patched for 1.6.x+");
				harmony.PatchAll(typeof(MapBaker_GetLevel_v1dot6_plus_Patch));
			}
			else
			{
				Logger.LogInfo((object)"Patched for PRE-1.6.x");
				harmony.PatchAll(typeof(MapBaker_GetLevel_PRE_v1dot6_Patch));
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.turtledsr.peakseedpicker";

		public const string PLUGIN_NAME = "PeakSeedPicker";

		public const string PLUGIN_VERSION = "1.3.0";
	}
}