Decompiled source of PublicSaves v1.0.0

PublicSaves.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PublicSaves")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PublicSaves")]
[assembly: AssemblyTitle("PublicSaves")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace PublicSaves
{
	[BepInPlugin("ozoka.publicsaves", "PublicSaves", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private readonly Harmony _harmony = new Harmony("ozoka.publicsaves");

		internal static bool openedFromServerList;

		internal static string selectedSaveFileName;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"PublicSaves geladen!");
			_harmony.PatchAll();
		}

		internal static bool IsPublicLobby()
		{
			FieldInfo field = typeof(GameManager).GetField("connectRandom", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null && (Object)(object)GameManager.instance != (Object)null)
			{
				return (bool)field.GetValue(GameManager.instance);
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(MenuPageServerList))]
	internal class MenuPageServerListPatch
	{
		[HarmonyPatch("ButtonCreateNew")]
		[HarmonyPrefix]
		internal static bool ButtonCreateNewPatch()
		{
			Plugin.openedFromServerList = true;
			Plugin.selectedSaveFileName = null;
			MenuManager.instance.PageOpenOnTop((MenuPageIndex)11);
			Plugin.Log.LogInfo((object)"[PublicSaves] Saves-Seite geöffnet von ServerList");
			return false;
		}
	}
	[HarmonyPatch(typeof(MenuPageSaves))]
	internal class MenuPageSavesPatch
	{
		private static FieldInfo _currentSaveFileNameField = typeof(MenuPageSaves).GetField("currentSaveFileName", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		private static FieldInfo _currentSaveFileBackupsField = typeof(MenuPageSaves).GetField("currentSaveFileBackups", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		private static FieldInfo _saveFileNameField = typeof(MenuPageServerListCreateNew).GetField("saveFileName", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		[HarmonyPatch("OnLoadGame")]
		[HarmonyPrefix]
		internal static bool OnLoadGamePatch(MenuPageSaves __instance)
		{
			if (!Plugin.openedFromServerList)
			{
				return true;
			}
			string text = (Plugin.selectedSaveFileName = (_currentSaveFileNameField?.GetValue(__instance) as string) ?? "");
			Plugin.Log.LogInfo((object)("[PublicSaves] Spielstand gewählt: " + text));
			MenuPageServerListCreateNew component = ((Component)MenuManager.instance.PageOpenOnTop((MenuPageIndex)15)).GetComponent<MenuPageServerListCreateNew>();
			_saveFileNameField?.SetValue(component, text);
			Plugin.openedFromServerList = false;
			return false;
		}

		[HarmonyPatch("OnNewGame")]
		[HarmonyPrefix]
		internal static bool OnNewGamePatch(MenuPageSaves __instance)
		{
			if (!Plugin.openedFromServerList)
			{
				return true;
			}
			Plugin.Log.LogInfo((object)"[PublicSaves] Neues öffentliches Spiel ohne Spielstand");
			MenuPageServerListCreateNew component = ((Component)MenuManager.instance.PageOpenOnTop((MenuPageIndex)15)).GetComponent<MenuPageServerListCreateNew>();
			_saveFileNameField?.SetValue(component, null);
			Plugin.openedFromServerList = false;
			return false;
		}

		[HarmonyPatch("OnGoBack")]
		[HarmonyPostfix]
		internal static void OnGoBackPatch()
		{
			Plugin.openedFromServerList = false;
			Plugin.selectedSaveFileName = null;
		}
	}
	[HarmonyPatch(typeof(StatsManager))]
	internal class StatsManagerPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		internal static void AwakePatch(StatsManager __instance)
		{
			if (!__instance.savedLobbyTypes.Contains((LobbyTypes)1))
			{
				__instance.savedLobbyTypes.Add((LobbyTypes)1);
			}
			if (!__instance.savedLobbyTypes.Contains((LobbyTypes)2))
			{
				__instance.savedLobbyTypes.Add((LobbyTypes)2);
			}
			Plugin.Log.LogInfo((object)"[PublicSaves] savedLobbyTypes erweitert!");
		}
	}
	[HarmonyPatch(typeof(DataDirector))]
	internal class DataDirectorPatch
	{
		[HarmonyPatch("SaveDeleteCheck", new Type[] { typeof(bool) })]
		[HarmonyPrefix]
		internal static bool SaveDeleteCheckPatch(bool _leaveGame)
		{
			if (Plugin.IsPublicLobby())
			{
				if ((Object)(object)StatsManager.instance != (Object)null)
				{
					StatsManager.instance.SaveFileSave();
				}
				Plugin.Log.LogInfo((object)"[PublicSaves] Öffentliche Lobby – Spielstand wird nicht gelöscht!");
				return false;
			}
			return true;
		}
	}
}