Please disclose if your mod was created primarily 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 RetryMod v1.0.0
RetryMod.dll
Decompiled 14 hours agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("RetryMod")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("RetryMod")] [assembly: AssemblyCopyright("Copyright © 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("045c5e0e-dbf3-4310-912d-eb59e0fca719")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.0.0")] [BepInPlugin("cody.retryfix", "Retry Fix", "1.0.0")] public class RetryFix : BaseUnityPlugin { [HarmonyPatch(typeof(RunManager), "ChangeLevel")] public class ChangeLevelPatch { private static bool Prefix(bool __0, bool __1) { if (!__1) { return true; } Log.LogInfo((object)"Retry triggered"); isRestarting = true; RunManager.instance.RestartScene(); return false; } } [HarmonyPatch(typeof(RoundDirector), "StartRoundLogic")] public class RoundStartPatch { private static void Postfix(RoundDirector __instance) { if (isRestarting) { ((MonoBehaviour)__instance).StartCoroutine(HandleRestart()); isRestarting = false; } } } [HarmonyPatch(typeof(ChargingStation), "Start")] public class ChargingStationStartPatch { private static void Postfix(ChargingStation __instance) { if (originalChargeTotal == -1) { FieldInfo fieldInfo = AccessTools.Field(typeof(ChargingStation), "chargeTotal"); originalChargeTotal = (int)fieldInfo.GetValue(__instance); Log.LogInfo((object)("Saved ORIGINAL chargeTotal: " + originalChargeTotal)); } } } [HarmonyPatch(typeof(RoundDirector), "StartRoundLogic")] public class SaveStatePatch { private static void Prefix(RoundDirector __instance) { if (isRestarting) { Log.LogInfo((object)"Skipping save (retry in progress)"); return; } List<PlayerAvatar> list = SemiFunc.PlayerGetAll(); if (list == null || list.Count == 0) { return; } PlayerAvatar val = list[0]; PlayerHealth playerHealth = val.playerHealth; savedHealth = GetCurrentHealth(playerHealth); savedMoney = GetMoney(); FieldInfo[] fields = ((object)val).GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { Log.LogInfo((object)$"PLAYER FIELD: {fieldInfo.Name} = {fieldInfo.GetValue(val)}"); } foreach (KeyValuePair<string, int> runStat in StatsManager.instance.runStats) { Log.LogInfo((object)$"STAT: {runStat.Key} = {runStat.Value}"); } Log.LogInfo((object)("Saved health: " + savedHealth)); Log.LogInfo((object)$"Saved money: {savedMoney}"); } private static void ResetEnergyPool() { if (!((Object)(object)StatsManager.instance == (Object)null) && originalChargeTotal != -1) { Log.LogInfo((object)"Restoring ORIGINAL charging station state..."); StatsManager.instance.runStats["chargingStationChargeTotal"] = originalChargeTotal; ChargingStation instance = ChargingStation.instance; if ((Object)(object)instance != (Object)null) { FieldInfo fieldInfo = AccessTools.Field(typeof(ChargingStation), "chargeTotal"); FieldInfo fieldInfo2 = AccessTools.Field(typeof(ChargingStation), "chargeFloat"); FieldInfo fieldInfo3 = AccessTools.Field(typeof(ChargingStation), "chargeSegmentCurrent"); fieldInfo?.SetValue(instance, originalChargeTotal); fieldInfo2?.SetValue(instance, (float)originalChargeTotal / 100f); fieldInfo3?.SetValue(instance, Mathf.RoundToInt((float)originalChargeTotal / 100f * 40f)); } Log.LogInfo((object)("Charging station restored to ORIGINAL startup value: " + originalChargeTotal)); } } private static int GetMoney() { if (StatsManager.instance.runStats.ContainsKey("currency")) { return StatsManager.instance.runStats["currency"]; } return 0; } } [CompilerGenerated] private sealed class <HandleRestart>d__12 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; private List<PlayerAvatar>.Enumerator <>s__1; private PlayerAvatar <p>5__2; private PlayerHealth <health>5__3; private FieldInfo[] <>s__4; private int <>s__5; private FieldInfo <f>5__6; private Type <healthType>5__7; private FieldInfo <healthField>5__8; private int <max>5__9; private int <target>5__10; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <HandleRestart>d__12(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>s__1 = default(List<PlayerAvatar>.Enumerator); <p>5__2 = null; <health>5__3 = null; <>s__4 = null; <f>5__6 = null; <healthType>5__7 = null; <healthField>5__8 = null; <>1__state = -2; } private bool MoveNext() { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = (object)new WaitForSeconds(2f); <>1__state = 1; return true; case 1: <>1__state = -1; <>s__1 = SemiFunc.PlayerGetAll().GetEnumerator(); try { while (<>s__1.MoveNext()) { <p>5__2 = <>s__1.Current; <health>5__3 = <p>5__2.playerHealth; <>s__4 = ((object)<health>5__3).GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); for (<>s__5 = 0; <>s__5 < <>s__4.Length; <>s__5++) { <f>5__6 = <>s__4[<>s__5]; Log.LogInfo((object)(<f>5__6.Name + " = " + <f>5__6.GetValue(<health>5__3))); <f>5__6 = null; } <>s__4 = null; if (savedHealth > 0) { <healthType>5__7 = ((object)<health>5__3).GetType(); <healthField>5__8 = AccessTools.Field(<healthType>5__7, "health"); <max>5__9 = GetMaxHealth(<health>5__3); <target>5__10 = Mathf.Clamp(savedHealth, 1, <max>5__9); <healthField>5__8?.SetValue(<health>5__3, <target>5__10); Log.LogInfo((object)$"Restored health to {<target>5__10}"); <healthType>5__7 = null; <healthField>5__8 = null; } SetMoney(savedMoney); Log.LogInfo((object)$"Restored money to {savedMoney}"); <health>5__3 = null; <p>5__2 = null; } } finally { ((IDisposable)<>s__1).Dispose(); } <>s__1 = default(List<PlayerAvatar>.Enumerator); Log.LogInfo((object)"Player state restored after retry"); 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(); } } public static ManualLogSource Log; private static bool isRestarting = false; private static int originalChargeTotal = -1; private static int savedHealth = 9; private static int savedMoney = 0; private void Awake() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; Log.LogInfo((object)"RetryFix loaded!"); Harmony val = new Harmony("cody.retryfix"); val.PatchAll(); } private static int GetCurrentHealth(object playerHealth) { FieldInfo fieldInfo = AccessTools.Field(playerHealth.GetType(), "health"); return (int)fieldInfo.GetValue(playerHealth); } private static int GetMaxHealth(object playerHealth) { FieldInfo fieldInfo = AccessTools.Field(playerHealth.GetType(), "maxHealth"); return (int)fieldInfo.GetValue(playerHealth); } private static void SetMoney(int value) { if (StatsManager.instance.runStats.ContainsKey("currency")) { StatsManager.instance.runStats["currency"] = value; } } [IteratorStateMachine(typeof(<HandleRestart>d__12))] private static IEnumerator HandleRestart() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <HandleRestart>d__12(0); } }