Decompiled source of DSP Save Game Sorter v1.0.5

DSPSaveGameSorter.dll

Decompiled 5 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("DSP Save Game Sorter")]
[assembly: AssemblyDescription("Mod for Dyson Sphere Program will change the save game order in the Load Game screen.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DSP Save Game Sorter")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9b8cbb37-4ebf-4e1a-98f9-1d865b5628d2")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.0")]
[module: UnverifiableCode]
[module: UnverifiableCode]
namespace DSPSaveGameSorter;

[BepInPlugin("jclark.dysonsphereprogram.savegamesorter", "DSP Save Game Sorter", "1.0.5")]
[BepInProcess("DSPGAME.exe")]
public class DSPSaveGameSorter : BaseUnityPlugin
{
	public class GameSaveEntryReverseSorter : IComparer<UIGameSaveEntry>
	{
		public int Compare(UIGameSaveEntry x, UIGameSaveEntry y)
		{
			if (x.fileDate < y.fileDate)
			{
				return 1;
			}
			if (x.fileDate > y.fileDate)
			{
				return -1;
			}
			return 0;
		}
	}

	public const string pluginGuid = "jclark.dysonsphereprogram.savegamesorter";

	public const string pluginName = "DSP Save Game Sorter";

	public const string pluginVersion = "1.0.5";

	internal static ManualLogSource Logger;

	private Harmony harmony;

	public static ConfigEntry<bool> configSortLoadScreen;

	public static ConfigEntry<bool> configSortSaveScreen;

	public void Awake()
	{
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Expected O, but got Unknown
		Logger = ((BaseUnityPlugin)this).Logger;
		configSortLoadScreen = ((BaseUnityPlugin)this).Config.Bind<bool>("Config", "SortLoadScreen", true, "Sort load-game screen list.");
		configSortSaveScreen = ((BaseUnityPlugin)this).Config.Bind<bool>("Config", "SortSaveScreen", true, "Sort save-game screen list.");
		harmony = new Harmony("jclark.dysonsphereprogram.savegamesorter");
		harmony.PatchAll(typeof(DSPSaveGameSorter));
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(UILoadGameWindow), "RefreshList")]
	public static void UILoadGameWindow_RefreshList_Postfix(ref UILoadGameWindow __instance)
	{
		if (!configSortLoadScreen.Value)
		{
			return;
		}
		__instance.entries.Sort(new GameSaveEntryReverseSorter());
		int num = 1;
		int num2 = 0;
		while (num2 < __instance.entries.Count)
		{
			UIGameSaveEntry val = __instance.entries[num2++];
			if (val.fileInfo.Name.Equals(GameSave.LastExitFullName))
			{
				val.SetEntry(num2, 0, val.fileInfo);
			}
			else if (val.fileInfo.Name.Equals(GameSave.AutoSave0FullName))
			{
				val.SetEntry(num2, -1, val.fileInfo);
			}
			else if (val.fileInfo.Name.Equals(GameSave.AutoSave1FullName))
			{
				val.SetEntry(num2, -2, val.fileInfo);
			}
			else if (val.fileInfo.Name.Equals(GameSave.AutoSave2FullName))
			{
				val.SetEntry(num2, -3, val.fileInfo);
			}
			else if (val.fileInfo.Name.Equals(GameSave.AutoSave3FullName))
			{
				val.SetEntry(num2, -4, val.fileInfo);
			}
			else
			{
				val.SetEntry(num2, num++, val.fileInfo);
			}
		}
		__instance.OnSelectedChange();
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(UISaveGameWindow), "RefreshList")]
	public static void UISaveGameWindow_RefreshList_Postfix(ref UISaveGameWindow __instance)
	{
		if (configSortSaveScreen.Value)
		{
			__instance.entries.Sort(new GameSaveEntryReverseSorter());
			int num = 0;
			while (num < __instance.entries.Count)
			{
				UIGameSaveEntry val = __instance.entries[num++];
				val.SetEntry(num, num, val.fileInfo);
			}
			__instance.OnSelectedChange();
		}
	}
}
public static class PluginInfo
{
	public const string PLUGIN_GUID = "DSPSaveGameSorter";

	public const string PLUGIN_NAME = "DSPSaveGameSorter";

	public const string PLUGIN_VERSION = "1.0.0";
}