Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Return to Bench v1.0.6
ReturnToBench.dll
Decompiled 9 months agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using TeamCherry.Localization; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; [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("ReturnToBench")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.6.0")] [assembly: AssemblyInformationalVersion("1.0.6+1e4f5e669e2a1f0ab9f004d3c228911787583093")] [assembly: AssemblyProduct("ReturnToBench")] [assembly: AssemblyTitle("Return_to_Bench")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/DemoJameson/Silksong.ReturnToBench")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.6.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] 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; } } [CompilerGenerated] [Microsoft.CodeAnalysis.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 BepInEx { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] [Conditional("CodeGeneration")] internal sealed class BepInAutoPluginAttribute : Attribute { public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null) { } } } namespace BepInEx.Preloader.Core.Patching { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] [Conditional("CodeGeneration")] internal sealed class PatcherAutoPluginAttribute : Attribute { public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null) { } } } namespace Silksong.ReturnToBench { [HarmonyPatch] [BepInPlugin("com.demojameson.silksong.returntobench", "Return to Bench", "1.0.6")] public class ReturnToBenchPlugin : BaseUnityPlugin { [CompilerGenerated] private sealed class <GameManagerPauseGameToggleByMenu>d__16 : IEnumerator<object>, IEnumerator, IDisposable { private int <>1__state; private object <>2__current; public IEnumerator __result; public GameManager __instance; private HeroController <heroController>5__2; private bool <origAcceptingInput>5__3; private bool <origDead>5__4; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <GameManagerPauseGameToggleByMenu>d__16(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <heroController>5__2 = null; <>1__state = -2; } private bool MoveNext() { switch (<>1__state) { default: return false; case 0: <>1__state = -1; <heroController>5__2 = HeroController.instance; <origAcceptingInput>5__3 = <heroController>5__2.acceptingInput; <origDead>5__4 = <heroController>5__2.cState.dead; break; case 1: <>1__state = -1; break; } if (__result.MoveNext()) { if (returningToBench) { <heroController>5__2.acceptingInput = false; <heroController>5__2.cState.dead = true; } <>2__current = __result.Current; <>1__state = 1; return true; } if (returningToBench) { if (__instance.IsInSceneTransition || __instance.IsLoadingSceneTransition) { <heroController>5__2.acceptingInput = <origAcceptingInput>5__3; <heroController>5__2.cState.dead = <origDead>5__4; returningToBench = false; return false; } StopAllSceneMusic(); MazeController.ResetSaveData(); __instance.ResetSemiPersistentItems(); __instance.TimePasses(); __instance.ReadyForRespawn(false); __instance.needFirstFadeIn = true; } return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } private static ReturnToBenchPlugin instance; private static ManualLogSource logger; private static GameObject? returnButton; private static Entry? entry; private static bool returningToBench; private const string PAUSE_BENCH = "PAUSE_BENCH"; private Harmony? harmony; public const string Id = "com.demojameson.silksong.returntobench"; public static string Name => "Return to Bench"; public static string Version => "1.0.6"; private void Awake() { instance = this; logger = ((BaseUnityPlugin)this).Logger; harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null); SceneManager.activeSceneChanged += OnActiveSceneChanged; } private void Start() { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown //IL_0057: Unknown result type (might be due to invalid IL or missing references) MethodInfo methodInfo = AccessTools.Method(typeof(Language), "SwitchLanguage", new Type[1] { typeof(LanguageCode) }, (Type[])null); HarmonyMethod val = new HarmonyMethod(typeof(ReturnToBenchPlugin), "LanguageSwitchLanguage", (Type[])null); Harmony? obj = harmony; if (obj != null) { obj.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } LanguageSwitchLanguage(Language._currentLanguage); } private void OnDestroy() { SceneManager.activeSceneChanged -= OnActiveSceneChanged; Harmony? obj = harmony; if (obj != null) { obj.UnpatchSelf(); } if (Object.op_Implicit((Object)(object)returnButton)) { Object.Destroy((Object)(object)returnButton); } if (entry != null && Object.op_Implicit((Object)(object)UIManager._instance)) { MenuButtonList component = ((Component)UIManager._instance.pauseMenuScreen).GetComponent<MenuButtonList>(); List<Entry> list = component.entries.ToList(); list.Remove(entry); component.entries = list.ToArray(); } } private void Update() { if (!Object.op_Implicit((Object)(object)returnButton)) { CreateReturnButton(); } } private void OnActiveSceneChanged(Scene prev, Scene current) { if (returningToBench && ((Scene)(ref current)).name == "Menu_Title") { returningToBench = false; } } private static void CreateReturnButton() { //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Expected O, but got Unknown MenuScreen val = UIManager._instance?.pauseMenuScreen; if (Object.op_Implicit((Object)(object)val)) { Transform obj = ((Component)val).transform.Find("Container/Controls"); Transform val2 = ((obj != null) ? obj.Find("ContinueButton") : null); Transform val3 = ((obj != null) ? obj.Find("ExitButton") : null); if (Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val3)) { returnButton = Object.Instantiate<GameObject>(((Component)val2).gameObject, val2.parent); ((Object)returnButton).name = "ReturnToBenchButton"; returnButton.transform.SetSiblingIndex(val3.GetSiblingIndex()); ((Component)val3).transform.SetSiblingIndex(val3.GetSiblingIndex() + 1); PauseMenuButton component = returnButton.GetComponent<PauseMenuButton>(); MenuButtonList component2 = ((Component)val).GetComponent<MenuButtonList>(); entry = new Entry { selectable = (Selectable)(object)component }; List<Entry> list = component2.entries.ToList(); list.Insert(list.Count - 1, entry); component2.entries = list.ToArray(); AutoLocalizeTextUI componentInChildren = returnButton.GetComponentInChildren<AutoLocalizeTextUI>(); componentInChildren.TextSheet = "com.demojameson.silksong.returntobench"; componentInChildren.TextKey = "PAUSE_BENCH"; } } } private static void LanguageSwitchLanguage(LanguageCode code) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Invalid comparison between Unknown and I4 Language._currentEntrySheets?.TryAdd("com.demojameson.silksong.returntobench", new Dictionary<string, string> { { "PAUSE_BENCH", ((int)code == 199) ? "返回长椅" : "Return to Bench" } }); } [HarmonyPatch(typeof(PauseMenuButton), "OnSubmit")] [HarmonyPostfix] private static void PauseMenuButtonOnSubmit(PauseMenuButton __instance) { if ((Object)(object)((Component)__instance).gameObject == (Object)(object)returnButton && ((Selectable)__instance).interactable && __instance.ih.PauseAllowed && !UIManager.instance.ignoreUnpause) { returningToBench = true; } else { returningToBench = false; } } [HarmonyPatch(typeof(HeroController), "CanTakeDamage")] [HarmonyPatch(typeof(HeroController), "CanTakeDamageIgnoreInvul")] [HarmonyPostfix] private static void HeroControllerCanTakeDamage(ref bool __result) { if (returningToBench) { __result = false; } } [IteratorStateMachine(typeof(<GameManagerPauseGameToggleByMenu>d__16))] [HarmonyPatch(typeof(GameManager), "PauseGameToggleByMenu")] [HarmonyPostfix] private static IEnumerator GameManagerPauseGameToggleByMenu(IEnumerator __result, GameManager __instance) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <GameManagerPauseGameToggleByMenu>d__16(0) { __result = __result, __instance = __instance }; } [HarmonyPatch(typeof(HeroController), "FinishedEnteringScene")] [HarmonyPostfix] private static void HeroControllerFinishedEnteringScene(HeroController __instance) { if (returningToBench) { returningToBench = false; __instance.proxyFSM.SendEvent("HeroCtrl-EnteringScene"); } } private static void StopAllSceneMusic() { GameManager obj = GameManager.instance; obj.AudioManager.StopAndClearMusic(); obj.AudioManager.StopAndClearAtmos(); Transform val = ((Component)obj.AudioManager).transform.Find("Music"); if (Object.op_Implicit((Object)(object)val)) { Transform obj2 = val.Find("RestArea"); PlayMakerFSM val2 = ((obj2 != null) ? ((Component)obj2).GetComponent<PlayMakerFSM>() : null); if (Object.op_Implicit((Object)(object)val2)) { val2.fsm.Finished = false; Extensions.SendEventSafe(val2, "REST AREA MUSIC STOP FAST"); } Transform obj3 = val.Find("FleaCaravan"); PlayMakerFSM val3 = ((obj3 != null) ? ((Component)obj3).GetComponent<PlayMakerFSM>() : null); if (Object.op_Implicit((Object)(object)val3)) { val3.fsm.Finished = false; Extensions.SendEventSafe(val3, "FLEA MUSIC STOP FAST"); } } } } }