Decompiled source of ExtraSaveSlots v1.0.1

plugins/Marioalexsan.ExtraSaveSlots.dll

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

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Marioalexsan.ExtraSaveSlots")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+74a120d9dc5b3922f56b65290cfe25e2231072b8")]
[assembly: AssemblyProduct("ExtraSaveSlots")]
[assembly: AssemblyTitle("Marioalexsan.ExtraSaveSlots")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 Marioalexsan.ExtraSaveSlots
{
	[HarmonyPatch(typeof(ProfileDataManager), "Cache_CharacterFiles")]
	internal static class ProfileDataManager_Cache_CharacterFiles
	{
		private static void Prefix()
		{
			ExtraSaveSlots.ResizeSlots();
		}
	}
	[HarmonyPatch(typeof(CharacterSelectManager), "Initalize_CharacterFiles")]
	internal static class ProfileDataManager_Initalize_CharacterFiles
	{
		internal static void Prefix(ref CharacterFile[] _characterFiles)
		{
			ExtraSaveSlots.ResizeSlots();
			_characterFiles = ProfileDataManager._current._characterFiles;
		}
	}
	[HarmonyPatch(typeof(CharacterCreationManager), "Create_Character")]
	internal static class CharacterCreationManager_Create_Character
	{
		private static void Postfix()
		{
			ProfileDataManager._current._charSelectManager.Clear_SelectEntries();
			ProfileDataManager._current._charSelectManager.Initalize_CharacterFiles(ProfileDataManager._current._characterFiles);
		}
	}
	[HarmonyPatch(typeof(ProfileDataManager), "Awake")]
	internal static class ProfileDataManager_Awake
	{
		internal static string SerializedEmptySaveFile = "";

		internal static int HighestSlotIndex = -1;

		private static void Postfix(ProfileDataManager __instance)
		{
			HighestSlotIndex = ExtraSaveSlots.FindHighestSaveSlotIndex();
			SerializedEmptySaveFile = JsonUtility.ToJson((object)__instance._characterFiles[0]);
		}
	}
	[HarmonyPatch(typeof(ProfileDataManager), "Start")]
	internal static class ProfileDataManager_Start
	{
		private static void Prefix(ProfileDataManager __instance)
		{
			__instance._charSelectManager._characterSelectListContent = ExtraSaveSlots.ConvertToScrollView(__instance._charSelectManager._characterSelectListContent);
		}
	}
	[BepInPlugin("Marioalexsan.ExtraSaveSlots", "ExtraSaveSlots", "1.0.1")]
	public class ExtraSaveSlots : BaseUnityPlugin
	{
		private static ExtraSaveSlots? _plugin;

		private readonly Harmony _harmony;

		public ConfigEntry<int> MaxSupportedSaves { get; }

		public static ExtraSaveSlots Plugin => _plugin ?? throw new InvalidOperationException("ExtraSaveSlots hasn't been initialized yet. Either wait until initialization, or check via ChainLoader instead.");

		internal ManualLogSource Logger { get; private set; }

		public static int FindHighestSaveSlotIndex()
		{
			int result = -1;
			for (int i = 0; i < Plugin.MaxSupportedSaves.Value; i++)
			{
				if (File.Exists(Path.Combine(ProfileDataManager._current._dataPath, $"atl_characterProfile_{i}")))
				{
					result = i;
				}
			}
			return result;
		}

		internal static void ResizeSlots()
		{
			int num = ProfileDataManager._current._characterFiles.Length;
			bool flag = num <= 6 || !ProfileDataManager._current._characterFiles[^1]._isEmptySlot;
			int num2 = Math.Min(Math.Max(ProfileDataManager_Awake.HighestSlotIndex + 2, num + (flag ? 1 : 0)), Plugin.MaxSupportedSaves.Value);
			if (num < num2)
			{
				Array.Resize(ref ProfileDataManager._current._characterFiles, num2);
				for (int i = num; i < ProfileDataManager._current._characterFiles.Length; i++)
				{
					ProfileDataManager._current._characterFiles[i] = GetNewFile();
				}
			}
		}

		internal static Transform ConvertToScrollView(Transform container)
		{
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			Transform val = container.Find("_charSelect_illuminatiEye");
			GameObject val2 = GameObject.Find("_dolly_networkSettingsTab") ?? GameObject.Find("_dolly_audioSettingsTab") ?? GameObject.Find("_dolly_inputSettingsTab") ?? GameObject.Find("_dolly_videoSettingsTab");
			if (!Object.op_Implicit((Object)(object)val2))
			{
				Logging.LogWarning("Couldn't instantiate scroll view! Wasn't able to find components to use!");
				return container;
			}
			Transform val3 = val2.transform.Find("_backdrop_videoSettings") ?? val2.transform.Find("Image") ?? val2.transform.Find("_backdrop") ?? val2.transform.Find("_backdrop_videoSettings");
			if (!Object.op_Implicit((Object)(object)val3) || !Object.op_Implicit((Object)(object)val3.Find("Scroll View/Viewport/Content")))
			{
				Logging.LogWarning("Couldn't instantiate scroll view! Wasn't able to find components to use!");
				return container;
			}
			Transform val4 = Object.Instantiate<Transform>(val3);
			val4.SetParent((Transform)null);
			Transform val5 = val4.Find("Scroll View");
			Transform val6 = val4.Find("Scroll View/Viewport/Content");
			for (int i = 0; i < ((Component)val6).transform.childCount; i++)
			{
				Object.Destroy((Object)(object)((Component)((Component)val6).transform.GetChild(i)).gameObject);
			}
			while (container.childCount > 0)
			{
				container.GetChild(0).SetParent(val6);
			}
			val.SetParent(container);
			((Component)val4).transform.SetParent(container);
			RectTransform component = ((Component)val4).GetComponent<RectTransform>();
			RectTransform component2 = ((Component)val5).GetComponent<RectTransform>();
			RectTransform component3 = ((Component)container).GetComponent<RectTransform>();
			float num;
			Rect rect;
			if (val == null)
			{
				num = 0f;
			}
			else
			{
				rect = ((Component)val).gameObject.GetComponent<RectTransform>().rect;
				num = ((Rect)(ref rect)).height;
			}
			float num2 = num;
			rect = component3.rect;
			component3.SetSizeWithCurrentAnchors((Axis)0, ((Rect)(ref rect)).width + 40f);
			((Transform)component).localScale = Vector3.one;
			rect = component3.rect;
			component.SetSizeWithCurrentAnchors((Axis)0, ((Rect)(ref rect)).width - 20f);
			rect = component3.rect;
			component.SetSizeWithCurrentAnchors((Axis)1, ((Rect)(ref rect)).height - num2 - 40f);
			((Transform)component2).localScale = Vector3.one;
			rect = component3.rect;
			component2.SetSizeWithCurrentAnchors((Axis)0, ((Rect)(ref rect)).width - 20f);
			rect = component3.rect;
			component2.SetSizeWithCurrentAnchors((Axis)1, ((Rect)(ref rect)).height - num2 - 40f);
			return val6;
		}

		public static CharacterFile GetNewFile()
		{
			CharacterFile val = JsonUtility.FromJson<CharacterFile>(ProfileDataManager_Awake.SerializedEmptySaveFile);
			val._isEmptySlot = true;
			return val;
		}

		public ExtraSaveSlots()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			_plugin = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("Marioalexsan.ExtraSaveSlots");
			MaxSupportedSaves = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaxSupportedSaves", 128, new ConfigDescription("Max number of saves to support. Don't change this unless you really, really need more saves than the default value provides.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(128, 1024), Array.Empty<object>()));
		}

		private void Awake()
		{
			_harmony.PatchAll();
			Logger.LogInfo((object)"Initialized successfully!");
		}
	}
	internal static class Logging
	{
		private static ManualLogSource InternalLogger => ExtraSaveSlots.Plugin.Logger;

		public static void LogFatal(object data, ConfigEntry<bool>? toggle = null)
		{
			Log(data, (LogLevel)1, toggle);
		}

		public static void LogError(object data, ConfigEntry<bool>? toggle = null)
		{
			Log(data, (LogLevel)2, toggle);
		}

		public static void LogWarning(object data, ConfigEntry<bool>? toggle = null)
		{
			Log(data, (LogLevel)4, toggle);
		}

		public static void LogMessage(object data, ConfigEntry<bool>? toggle = null)
		{
			Log(data, (LogLevel)8, toggle);
		}

		public static void LogInfo(object data, ConfigEntry<bool>? toggle = null)
		{
			Log(data, (LogLevel)16, toggle);
		}

		public static void LogDebug(object data, ConfigEntry<bool>? toggle = null)
		{
			Log(data, (LogLevel)32, toggle);
		}

		private static void Log(object data, LogLevel level = 16, ConfigEntry<bool>? toggle = null)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (toggle == null || toggle.Value)
			{
				ManualLogSource internalLogger = InternalLogger;
				if (internalLogger != null)
				{
					internalLogger.Log(level, data);
				}
			}
		}
	}
	internal static class ModInfo
	{
		public const string PLUGIN_GUID = "Marioalexsan.ExtraSaveSlots";

		public const string PLUGIN_NAME = "ExtraSaveSlots";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}