using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Sons.Gui;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Localization.Components;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("PauseMenuSave")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.4.0")]
[assembly: AssemblyInformationalVersion("0.1.4+8cdc1c40a10e7e99652d95be4005942775697087")]
[assembly: AssemblyProduct("PauseMenuSave")]
[assembly: AssemblyTitle("PauseMenuSave")]
[assembly: AssemblyVersion("0.1.4.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[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 PauseMenuSave
{
[BepInPlugin("aznan.sotf.pausemenusave", "PauseMenuSave", "0.1.4")]
public class Plugin : BasePlugin
{
internal const string Version = "0.1.4";
internal static ManualLogSource Logger;
internal static ConfigEntry<string> ButtonLabel;
public override void Load()
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Expected O, but got Unknown
Logger = ((BasePlugin)this).Log;
ButtonLabel = ((BasePlugin)this).Config.Bind<string>("General", "ButtonLabel", "Save", "Text of the save button added to the pause menu.");
new Harmony("aznan.sotf.pausemenusave").PatchAll();
ManualLogSource logger = Logger;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(21, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("PauseMenuSave ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.1.4");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded");
}
logger.LogInfo(val);
}
}
}
namespace PauseMenuSave.Patches
{
[HarmonyPatch(typeof(PauseMenu), "Open")]
public static class SaveButtonInjector
{
private const string ButtonObjectName = "PauseMenuSave_Button";
public static void Postfix(PauseMenu __instance)
{
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Expected O, but got Unknown
//IL_018c: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Expected O, but got Unknown
foreach (Button componentsInChild in ((Component)__instance).GetComponentsInChildren<Button>(true))
{
if (((Object)componentsInChild).name == "PauseMenuSave_Button")
{
return;
}
}
List<Button> singlePlayerMenuButtons = __instance._singlePlayerMenuButtons;
Button val = ((singlePlayerMenuButtons != null && singlePlayerMenuButtons.Count > 0) ? singlePlayerMenuButtons[0] : null);
if ((Object)(object)val == (Object)null)
{
Plugin.Logger.LogError((object)"Pause menu has no button to copy; save button not added.");
return;
}
Button component = Object.Instantiate<GameObject>(((Component)val).gameObject, ((Component)val).transform.parent).GetComponent<Button>();
((Object)component).name = "PauseMenuSave_Button";
((Component)component).transform.SetSiblingIndex(((Component)val).transform.GetSiblingIndex() + 1);
component.onClick = new ButtonClickedEvent();
((UnityEvent)component.onClick).AddListener(UnityAction.op_Implicit((Action)delegate
{
OpenSaveScreen(__instance);
}));
foreach (LocalizeStringEvent componentsInChild2 in ((Component)component).GetComponentsInChildren<LocalizeStringEvent>(true))
{
Object.DestroyImmediate((Object)(object)componentsInChild2);
}
foreach (LocalizedLinkText componentsInChild3 in ((Component)component).GetComponentsInChildren<LocalizedLinkText>(true))
{
Object.DestroyImmediate((Object)(object)componentsInChild3);
}
TMP_Text componentInChildren = ((Component)component).GetComponentInChildren<TMP_Text>(true);
if ((Object)(object)componentInChildren != (Object)null)
{
componentInChildren.text = Plugin.ButtonLabel.Value;
}
ManualLogSource logger = Plugin.Logger;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(38, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Save button added next to '");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)val).name);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' under '");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)((Component)val).transform.parent).name);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("'.");
}
logger.LogInfo(val2);
}
private static void OpenSaveScreen(PauseMenu menu)
{
menu.SetSaveMenuActive(true);
Plugin.Logger.LogInfo((object)"Save screen opened from pause menu.");
}
}
}