Decompiled source of PlaylistMemory v1.0.0

PlaylistMemory.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("PlaylistMemory")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PlaylistMemory")]
[assembly: AssemblyCopyright("Copyright © DasGerippe 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5ce28d6e-4bea-4395-8ac6-b9b92caf8106")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PlaylistMemory
{
	internal static class PlaylistNameCache
	{
		private const string LastPlaylistNameConfigKey = "Last Playlist Name";

		internal static string LastPlaylistName
		{
			get
			{
				return G.Sys.GameData_.GetString("Last Playlist Name", "");
			}
			set
			{
				G.Sys.GameData_.SetString("Last Playlist Name", value);
			}
		}
	}
	[BepInPlugin("de.dasgerippe.distance.playlistmemory", "PlaylistMemory", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			new Harmony("de.dasgerippe.distance.playlistmemory").PatchAll();
		}
	}
}
namespace PlaylistMemory.Properties
{
	internal static class ModInfo
	{
		internal const string ID = "de.dasgerippe.distance.playlistmemory";

		internal const string NAME = "PlaylistMemory";

		internal const string VERSION = "1.0.0";
	}
}
namespace PlaylistMemory.Patches.Assembly_CSharp
{
	[HarmonyPatch(typeof(LevelGridGrid), "SelectButtonForCurrentPage")]
	public class LevelGridGrid_SelectButtonForCurrentPage
	{
		private static void Postfix(LevelGridGrid __instance)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			LevelGridMenu levelGridMenu_ = __instance.levelGridMenu_;
			DisplayType displayType_ = ((LevelSelectMenuAbstract)levelGridMenu_).DisplayType_;
			if ((int)displayType_ == 3 || (int)displayType_ == 0)
			{
				PlaylistNameCache.LastPlaylistName = levelGridMenu_.DisplayedEntry_.Playlist_.Name_;
			}
		}
	}
	[HarmonyPatch(typeof(LevelGridMenu), "CreateEntries")]
	internal class LevelGridMenu_CreateEntries
	{
		[CompilerGenerated]
		private sealed class <Transpiler>d__0 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private CodeInstruction <>2__current;

			private int <>l__initialThreadId;

			private IEnumerable<CodeInstruction> instructions;

			public IEnumerable<CodeInstruction> <>3__instructions;

			private MethodInfo <oldFindIndexMethod>5__2;

			private MethodInfo <newFindIndexMethod>5__3;

			private IEnumerator<CodeInstruction> <>7__wrap3;

			CodeInstruction IEnumerator<CodeInstruction>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <Transpiler>d__0(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Thread.CurrentThread.ManagedThreadId;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || num == 1)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<oldFindIndexMethod>5__2 = null;
				<newFindIndexMethod>5__3 = null;
				<>7__wrap3 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						Plugin.Logger.LogInfo((object)"Transpiling LevelGridMenu.CreateEntries().");
						<oldFindIndexMethod>5__2 = AccessTools.Method(typeof(List<PlaylistEntry>), "FindIndex", new Type[1] { typeof(Predicate<PlaylistEntry>) }, (Type[])null);
						<newFindIndexMethod>5__3 = AccessTools.Method(typeof(LevelGridMenu_CreateEntries), "FindPlaylistLevelIndex", (Type[])null, (Type[])null);
						<>7__wrap3 = instructions.GetEnumerator();
						<>1__state = -3;
						break;
					case 1:
						<>1__state = -3;
						break;
					}
					if (<>7__wrap3.MoveNext())
					{
						CodeInstruction current = <>7__wrap3.Current;
						if (current.opcode == OpCodes.Callvirt && current.operand == <oldFindIndexMethod>5__2)
						{
							Plugin.Logger.LogInfo((object)"Replacing FindIndex method.");
							current.opcode = OpCodes.Call;
							current.operand = <newFindIndexMethod>5__3;
						}
						<>2__current = current;
						<>1__state = 1;
						return true;
					}
					<>m__Finally1();
					<>7__wrap3 = null;
					return false;
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<>7__wrap3 != null)
				{
					<>7__wrap3.Dispose();
				}
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}

			[DebuggerHidden]
			IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
			{
				<Transpiler>d__0 <Transpiler>d__;
				if (<>1__state == -2 && <>l__initialThreadId == Thread.CurrentThread.ManagedThreadId)
				{
					<>1__state = 0;
					<Transpiler>d__ = this;
				}
				else
				{
					<Transpiler>d__ = new <Transpiler>d__0(0);
				}
				<Transpiler>d__.instructions = <>3__instructions;
				return <Transpiler>d__;
			}

			[DebuggerHidden]
			IEnumerator IEnumerable.GetEnumerator()
			{
				return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
			}
		}

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <Transpiler>d__0(-2)
			{
				<>3__instructions = instructions
			};
		}

		private static int FindPlaylistLevelIndex(List<PlaylistEntry> list, Predicate<PlaylistEntry> predicate)
		{
			string lastPlaylistName = PlaylistNameCache.LastPlaylistName;
			bool flag = string.IsNullOrEmpty(lastPlaylistName);
			int num = -1;
			for (int i = 0; i < list.Count; i++)
			{
				PlaylistEntry val = list[i];
				if (predicate(val))
				{
					if (flag || val.Playlist_.Name_ == lastPlaylistName)
					{
						return i;
					}
					if (num == -1)
					{
						num = i;
					}
				}
			}
			return num;
		}
	}
	[HarmonyPatch(typeof(LevelGridMenu), "OnGridCellClicked")]
	public class LevelGridMenu_OnGridCellClicked
	{
		private static void Postfix(LevelGridMenu __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)((LevelSelectMenuAbstract)__instance).DisplayType_ == 1)
			{
				PlaylistNameCache.LastPlaylistName = __instance.DisplayedEntry_.Playlist_.Name_;
			}
		}
	}
	[HarmonyPatch(typeof(LevelGridMenu), "OnLevelEntrySelected")]
	public class LevelGridMenu_OnLevelEntrySelected
	{
		private static void Postfix(LevelGridMenu __instance)
		{
			//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_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			DisplayType displayType_ = ((LevelSelectMenuAbstract)__instance).DisplayType_;
			if ((int)displayType_ == 0 || (int)displayType_ == 3)
			{
				__instance.SetLevelInfoIfNeeded();
			}
		}
	}
}