Decompiled source of PublicSave v1.0.0

PublicSave.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
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;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PublicSave")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PublicSave")]
[assembly: AssemblyTitle("PublicSave")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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 PublicSave
{
	[BepInPlugin("custom.publicsave", "PublicSave", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static Plugin Instance;

		internal static ManualLogSource Log;

		internal static bool PublicSaveMenu = false;

		internal static string ServerName = "";

		private void Awake()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			new Harmony("custom.publicsave").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PublicSave loaded!");
		}

		internal IEnumerator OpenSaveMenu(string serverName)
		{
			yield return null;
			ServerName = serverName;
			PublicSaveMenu = true;
			SemiFunc.MainMenuSetMultiplayer();
			MenuManager.instance.PageCloseAll();
			MenuManager.instance.PageOpen((MenuPageIndex)11, false);
			Log.LogInfo((object)"Opened public save menu.");
		}
	}
	[HarmonyPatch(typeof(StatsManager), "Awake")]
	internal static class EnablePublicSave
	{
		private static void Postfix(StatsManager __instance)
		{
			if (!__instance.savedLobbyTypes.Contains((LobbyTypes)1))
			{
				__instance.savedLobbyTypes.Add((LobbyTypes)1);
			}
			Plugin.Log.LogInfo((object)"Public saving enabled.");
		}
	}
	[HarmonyPatch(typeof(MenuPageServerList), "ButtonCreateNew")]
	internal static class CreatePublicServer
	{
		private static bool Prefix(bool ___searchInProgress)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			if (___searchInProgress)
			{
				return false;
			}
			Plugin.PublicSaveMenu = false;
			MenuManager.instance.PagePopUpTextInput("Create Server", (LocalizedAsset)null, new Color(1f, 0.55f, 0f), "Enter a server name", (LocalizedAsset)null, "", "Confirm", (LocalizedAsset)null, false, 60, false, (UnityAction<string>)delegate(string serverName)
			{
				((MonoBehaviour)Plugin.Instance).StartCoroutine(Plugin.Instance.OpenSaveMenu(serverName));
			}, (UnityAction)null);
			return false;
		}
	}
	[HarmonyPatch(typeof(SemiFunc), "MenuActionHostGame")]
	internal static class HostPublicGame
	{
		private static bool Prefix(string saveFileName, List<string> saveFileBackups)
		{
			if (!Plugin.PublicSaveMenu)
			{
				return true;
			}
			Plugin.PublicSaveMenu = false;
			Traverse.Create((object)DataDirector.instance).Field("networkServerName").SetValue((object)Plugin.ServerName);
			RunManager.instance.ResetProgress();
			GameManager.instance.SetConnectRandom(true);
			GameManager.instance.SetLobbyType((LobbyTypes)1);
			if (saveFileName != null)
			{
				SemiFunc.SaveFileLoad(saveFileName, saveFileBackups);
				Plugin.Log.LogInfo((object)("Loading public save: " + saveFileName));
			}
			else
			{
				SemiFunc.SaveFileCreate();
				Plugin.Log.LogInfo((object)"Creating new public save.");
			}
			Traverse.Create((object)GameManager.instance).Field("localTest").SetValue((object)false);
			RunManager.instance.ChangeLevel(true, false, (ChangeLevelType)3);
			Traverse.Create((object)RunManager.instance).Field("lobbyJoin").SetValue((object)true);
			return false;
		}
	}
	[HarmonyPatch(typeof(MenuPageSaves), "OnGoBack")]
	internal static class BackToServerList
	{
		private static bool Prefix()
		{
			if (!Plugin.PublicSaveMenu)
			{
				return true;
			}
			Plugin.PublicSaveMenu = false;
			Plugin.ServerName = "";
			MenuManager.instance.PageCloseAll();
			MenuManager.instance.PageOpen((MenuPageIndex)14, false);
			return false;
		}
	}
}