Decompiled source of MoreSaveSlots v1.0.0

Yap_SaveSlots.dll

Decompiled 2 days 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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;
using YAPYAP;

[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("Yap_SaveSlots")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("YapYap Save Slot Expansion MOD")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Yap_SaveSlots")]
[assembly: AssemblyTitle("Yap_SaveSlots")]
[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 Yap_SaveSlots
{
	[BepInPlugin("com.yapyap.saveslots", "Yap Save Slots", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		internal static ConfigEntry<int> SlotCount;

		private void Awake()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			SlotCount = ((BaseUnityPlugin)this).Config.Bind<int>("General", "SlotCount", 5, "Total number of save slots (>=1)");
			Harmony val = new Harmony("com.yapyap.saveslots");
			val.PatchAll();
			Log.LogInfo((object)$"Yap Save Slots MOD loaded. Target slots: {SlotCount.Value}");
		}
	}
	[HarmonyPatch(typeof(InitialiseSaveManagerOnEnter), "OnEnter")]
	internal static class Patch_InitialiseSaveManagerOnEnter
	{
		private static bool Prefix()
		{
			SaveManager val = default(SaveManager);
			if (!Service.Get<SaveManager>(ref val))
			{
				return false;
			}
			int num = Mathf.Max(1, Plugin.SlotCount.Value);
			val.Initialise(num);
			Plugin.Log.LogInfo((object)$"SaveManager.Initialise overridden. SlotCount = {num}");
			return false;
		}
	}
	[HarmonyPatch(typeof(MenuController), "Awake")]
	internal static class Patch_MenuController_Awake
	{
		private static void Postfix(MenuController __instance)
		{
			SaveSlotExpander.ExpandSaveSlots(__instance);
		}
	}
	internal static class SaveSlotExpander
	{
		public static void ExpandSaveSlots(MenuController menu)
		{
			if ((Object)(object)menu == (Object)null)
			{
				return;
			}
			int num = Mathf.Max(1, Plugin.SlotCount.Value);
			FieldInfo field = typeof(MenuController).GetField("_saveSlots", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field == null)
			{
				Plugin.Log.LogWarning((object)"MenuController._saveSlots field not found");
				return;
			}
			if (!(field.GetValue(menu) is List<UISaveSlot> list))
			{
				Plugin.Log.LogWarning((object)"MenuController._saveSlots is null or not a List<UISaveSlot>");
				return;
			}
			int count = list.Count;
			if (count >= num)
			{
				Plugin.Log.LogInfo((object)$"Save slots UI already has {count} entries, target {num}. No expansion needed.");
				return;
			}
			if (count == 0)
			{
				Plugin.Log.LogWarning((object)"MenuController._saveSlots is empty, cannot expand UI");
				return;
			}
			UISaveSlot val = list[count - 1];
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"Template UISaveSlot is null, cannot expand UI");
				return;
			}
			Transform parent = ((Component)val).transform.parent;
			for (int i = count; i < num; i++)
			{
				GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, parent);
				((Object)val2).name = ((Object)((Component)val).gameObject).name + "_Extra_" + i;
				val2.SetActive(false);
				UISaveSlot component = val2.GetComponent<UISaveSlot>();
				if ((Object)(object)component == (Object)null)
				{
					Plugin.Log.LogWarning((object)$"Clone at index {i} has no UISaveSlot component");
					Object.Destroy((Object)(object)val2);
				}
				else
				{
					list.Add(component);
				}
			}
			Plugin.Log.LogInfo((object)$"Expanded save slots UI from {count} to {list.Count} entries (target {num}).");
			if (Plugin.SlotCount.Value > 3)
			{
				SetupScroll(menu, list);
			}
		}

		private static void SetupScroll(MenuController menu, List<UISaveSlot> slots)
		{
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Expected O, but got Unknown
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cf: Expected O, but got Unknown
			//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_041c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0433: Unknown result type (might be due to invalid IL or missing references)
			//IL_045d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0492: Unknown result type (might be due to invalid IL or missing references)
			//IL_0499: Expected O, but got Unknown
			//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0507: Unknown result type (might be due to invalid IL or missing references)
			if (slots == null || slots.Count == 0)
			{
				return;
			}
			UISaveSlot val = slots[0];
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Transform parent = ((Component)val).transform.parent;
			RectTransform val2 = (RectTransform)(object)((parent is RectTransform) ? parent : null);
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			Transform parent2 = ((Transform)val2).parent;
			RectTransform val3 = (RectTransform)(object)((parent2 is RectTransform) ? parent2 : null);
			if ((Object)(object)val3 == (Object)null)
			{
				return;
			}
			Transform val4 = ((Transform)val2).Find("SlotsScrollContent");
			RectTransform val5;
			if ((Object)(object)val4 != (Object)null)
			{
				val5 = (RectTransform)(object)((val4 is RectTransform) ? val4 : null);
			}
			else
			{
				GameObject val6 = new GameObject("SlotsScrollContent", new Type[1] { typeof(RectTransform) });
				val5 = val6.GetComponent<RectTransform>();
				((Transform)val5).SetParent((Transform)(object)val2, false);
				val5.anchorMin = new Vector2(0f, 0f);
				val5.anchorMax = new Vector2(1f, 1f);
				val5.pivot = val2.pivot;
				val5.offsetMin = Vector2.zero;
				val5.offsetMax = Vector2.zero;
				List<Transform> list = new List<Transform>();
				for (int i = 0; i < ((Transform)val2).childCount; i++)
				{
					Transform child = ((Transform)val2).GetChild(i);
					if (!((Object)(object)child == (Object)(object)val5))
					{
						list.Add(child);
					}
				}
				foreach (Transform item in list)
				{
					item.SetParent((Transform)(object)val5, false);
				}
			}
			VerticalLayoutGroup component = ((Component)val2).GetComponent<VerticalLayoutGroup>();
			if ((Object)(object)component != (Object)null)
			{
				VerticalLayoutGroup val7 = ((Component)val5).GetComponent<VerticalLayoutGroup>();
				if ((Object)(object)val7 == (Object)null)
				{
					val7 = ((Component)val5).gameObject.AddComponent<VerticalLayoutGroup>();
				}
				((LayoutGroup)val7).childAlignment = ((LayoutGroup)component).childAlignment;
				((HorizontalOrVerticalLayoutGroup)val7).childControlWidth = ((HorizontalOrVerticalLayoutGroup)component).childControlWidth;
				((HorizontalOrVerticalLayoutGroup)val7).childControlHeight = ((HorizontalOrVerticalLayoutGroup)component).childControlHeight;
				((HorizontalOrVerticalLayoutGroup)val7).childForceExpandWidth = ((HorizontalOrVerticalLayoutGroup)component).childForceExpandWidth;
				((HorizontalOrVerticalLayoutGroup)val7).childForceExpandHeight = ((HorizontalOrVerticalLayoutGroup)component).childForceExpandHeight;
				((HorizontalOrVerticalLayoutGroup)val7).spacing = ((HorizontalOrVerticalLayoutGroup)component).spacing;
				((LayoutGroup)val7).padding = ((LayoutGroup)component).padding;
				((Behaviour)component).enabled = false;
			}
			else
			{
				VerticalLayoutGroup component2 = ((Component)val5).GetComponent<VerticalLayoutGroup>();
				if ((Object)(object)component2 == (Object)null)
				{
					component2 = ((Component)val5).gameObject.AddComponent<VerticalLayoutGroup>();
					((LayoutGroup)component2).childAlignment = (TextAnchor)1;
					((HorizontalOrVerticalLayoutGroup)component2).childControlWidth = true;
					((HorizontalOrVerticalLayoutGroup)component2).childControlHeight = true;
					((HorizontalOrVerticalLayoutGroup)component2).childForceExpandWidth = true;
					((HorizontalOrVerticalLayoutGroup)component2).childForceExpandHeight = false;
					((HorizontalOrVerticalLayoutGroup)component2).spacing = 5f;
				}
			}
			ContentSizeFitter component3 = ((Component)val5).GetComponent<ContentSizeFitter>();
			if ((Object)(object)component3 == (Object)null)
			{
				component3 = ((Component)val5).gameObject.AddComponent<ContentSizeFitter>();
				component3.verticalFit = (FitMode)2;
			}
			Mask val8 = ((Component)val2).GetComponent<Mask>();
			if ((Object)(object)val8 == (Object)null)
			{
				val8 = ((Component)val2).gameObject.AddComponent<Mask>();
			}
			val8.showMaskGraphic = true;
			ScrollRect val9 = ((Component)val3).GetComponent<ScrollRect>();
			if ((Object)(object)val9 == (Object)null)
			{
				val9 = ((Component)val3).gameObject.AddComponent<ScrollRect>();
			}
			val9.viewport = val2;
			val9.content = val5;
			val9.horizontal = false;
			val9.vertical = true;
			val9.movementType = (MovementType)2;
			val9.scrollSensitivity = 20f;
			Transform val10 = ((Transform)val2).Find("ScrollbarVertical");
			Scrollbar val11;
			if ((Object)(object)val10 != (Object)null)
			{
				val11 = ((Component)val10).GetComponent<Scrollbar>();
			}
			else
			{
				GameObject val12 = new GameObject("ScrollbarVertical", new Type[1] { typeof(RectTransform) });
				RectTransform component4 = val12.GetComponent<RectTransform>();
				((Transform)component4).SetParent((Transform)(object)val2, false);
				component4.anchorMin = new Vector2(1f, 0f);
				component4.anchorMax = new Vector2(1f, 1f);
				component4.pivot = new Vector2(1f, 0.5f);
				component4.sizeDelta = new Vector2(15f, 0f);
				Image val13 = val12.AddComponent<Image>();
				((Graphic)val13).color = new Color(1f, 1f, 1f, 0.2f);
				val11 = val12.AddComponent<Scrollbar>();
				val11.direction = (Direction)2;
				GameObject val14 = new GameObject("Handle", new Type[1] { typeof(RectTransform) });
				RectTransform component5 = val14.GetComponent<RectTransform>();
				((Transform)component5).SetParent((Transform)(object)component4, false);
				component5.anchorMin = new Vector2(0f, 0f);
				component5.anchorMax = new Vector2(1f, 1f);
				component5.sizeDelta = Vector2.zero;
				Image val15 = val14.AddComponent<Image>();
				((Graphic)val15).color = new Color(0.5f, 0.8f, 1f, 0.9f);
				((Selectable)val11).targetGraphic = (Graphic)(object)val15;
				val11.handleRect = component5;
			}
			val9.verticalScrollbar = val11;
			val9.verticalScrollbarVisibility = (ScrollbarVisibility)2;
		}
	}
}