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 System.Threading; using System.Threading.Tasks; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Photon.Pun; using UnityEngine; [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("MyDaTeam")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("MyDaSaves")] [assembly: AssemblyTitle("MyDaSaves")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] 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; } } [CompilerGenerated] [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 MyDaSaves { [HarmonyPatch(typeof(StatsManager))] public class StatsManagerHook { [HarmonyPatch("SaveFileDelete")] [HarmonyPrefix] private static bool SaveFileDelete() { return MyDaSaves.DeleteSave(); } [HarmonyPatch("SaveFileSave")] [HarmonyPrefix] private static void SaveFileSave(StatsManager __instance) { MyDaSaves.AddPublicWhitelist(__instance); } [HarmonyPatch("SaveGame")] [HarmonyPrefix] private static bool SaveGame() { return MyDaSaves.SaveGameSet(); } } [HarmonyPatch(typeof(PlayerAvatar))] public static class PlayerAvatarHook { [HarmonyPatch("PlayerDeathRPC")] [HarmonyPostfix] public static void PlayerDeathRPC(PlayerAvatar __instance) { if (!((Object)(object)__instance == (Object)null)) { MyDaSaves.AllPlayersDeathSet(); } } [HarmonyPatch("Revive")] [HarmonyPrefix] public static void Revive() { MyDaSaves.PlayerDead = false; MyDaSaves.allPlayersDead = false; } [HarmonyPatch("PlayerDeath")] [HarmonyPrefix] public static void PlayerDeath() { MyDaSaves.PlayerDeathSet(); } } [HarmonyPatch(typeof(MenuPageSaves))] public class MenuPageSavesHook { [HarmonyPatch("OnNewGame")] [HarmonyPrefix] private static bool OnNewGame() { MyDaSaves.Savelimit(); return false; } [HarmonyPatch("OnDeleteGame")] [HarmonyPrefix] private static bool OnDeleteGame() { MyDaSaves.IsPlayerDeletingSave = true; return true; } } [HarmonyPatch(typeof(ItemReviveItem))] public class ItemReviveItemHook { [HarmonyPatch("UpdatePlayerTarget")] [HarmonyPostfix] private static void UpdatePlayerTarget() { MyDaSaves.PlayerDead = false; } } [BepInPlugin("MyDaTeam.MyDaSaves", "MyDaSaves", "1.0")] public class MyDaSaves : BaseUnityPlugin { public static bool IsPlayerDeletingSave; public static bool PlayerDead; public static bool allPlayersDead; internal static MyDaSaves Instance { get; private set; } internal static ManualLogSource Logger => Instance.Log; private ManualLogSource Log => ((BaseUnityPlugin)this).Logger; internal Harmony? Harmony { get; set; } public static ConfigEntry AllowSaveDelete { get; private set; } private void Awake() { Instance = this; ((Component)this).gameObject.transform.parent = null; ((Object)((Component)this).gameObject).hideFlags = (HideFlags)61; AllowSaveDelete = ((BaseUnityPlugin)this).Config.Bind("Saves", "AllowSavesDelete", false, "AllowSavesDelete"); Patch(); Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!"); } internal void Patch() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown //IL_0025: Expected O, but got Unknown if (Harmony == null) { Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID); Harmony val2 = val; Harmony = val; } Harmony.PatchAll(); } internal static bool DeleteSave() { if (IsPlayerDeletingSave) { IsPlayerDeletingSave = false; return true; } if (AllowSaveDelete.Value) { return true; } return false; } internal static bool SaveGameSet() { if (AllowSaveDelete.Value) { return true; } if (RunManager.instance.levelArena.Contains(RunManager.instance.levelCurrent)) { return false; } if (allPlayersDead && SemiFunc.IsMultiplayer()) { return false; } if (PlayerDead && !SemiFunc.IsMultiplayer()) { return false; } return true; } internal static void PlayerDeathSet() { if (!AllowSaveDelete.Value && !SemiFunc.IsMultiplayer() && (SemiFunc.RunIsLevel() || SemiFunc.RunIsArena())) { PlayerDead = true; ReLoad(); } } internal static void AllPlayersDeathSet() { if (AllowSaveDelete.Value || !SemiFunc.IsMultiplayer() || !PhotonNetwork.IsMasterClient) { return; } List list = SemiFunc.PlayerGetList(); bool flag = true; foreach (PlayerAvatar item in list) { if (!item.deadSet) { flag = false; break; } } if (flag) { allPlayersDead = true; ReLoad(); } } private static async void ReLoad() { if (!SemiFunc.RunIsLevel() && !SemiFunc.RunIsArena()) { return; } string saveFileName = StatsManager.instance.saveFileCurrent; if (string.IsNullOrEmpty(saveFileName)) { if (SemiFunc.IsMultiplayer()) { allPlayersDead = false; } else { PlayerDead = false; } } else if (!SemiFunc.IsMultiplayer()) { CancellationTokenSource cts = new CancellationTokenSource(); try { CancellationToken token = cts.Token; Task.Run(async delegate { while (!token.IsCancellationRequested) { if (!(SemiFunc.IsMultiplayer() ? allPlayersDead : PlayerDead)) { cts.Cancel(); break; } await Task.Delay(50, token).ConfigureAwait(continueOnCapturedContext: false); } }, token); try { await Task.Delay(3000, token).ConfigureAwait(continueOnCapturedContext: false); } catch (TaskCanceledException) { return; } } finally { if (cts != null) { ((IDisposable)cts).Dispose(); } } SemiFunc.MenuActionSingleplayerGame(saveFileName, (List)null); PlayerDead = false; } else if (SemiFunc.RunIsArena()) { await Task.Delay(1000); RunManager.instance.ChangeLevel(true, SemiFunc.RunIsArena(), (ChangeLevelType)3); SemiFunc.SaveFileLoad(saveFileName, (List)null); allPlayersDead = false; } } internal static void Savelimit() { if (SemiFunc.MainMenuIsMultiplayer()) { SemiFunc.MenuActionHostGame((string)null, (List)null); } else { SemiFunc.MenuActionSingleplayerGame((string)null, (List)null); } } internal static void AddPublicWhitelist(StatsManager __instance) { if (!__instance.savedLobbyTypes.Contains((LobbyTypes)1)) { __instance.savedLobbyTypes.Add((LobbyTypes)1); } } } }