using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Assets.Scripts.Managers;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("EasyRestart")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("for easy rolling good seed for start")]
[assembly: AssemblyTitle("EasyRestart")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace MegaBonkObjectCounter
{
[BepInPlugin("org.bepinex.plugins.easyrestartformegabonk", "For easy reroll starting seed", "1.0.0")]
public class Plugin : BasePlugin
{
private GameObject hudGO;
private ObjectCounterBehaviour hudBehaviour;
private Harmony harmony;
private static ManualLogSource _logger;
private ConfigEntry<string> restartKeyConfig;
public override void Load()
{
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Expected O, but got Unknown
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Expected O, but got Unknown
//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
//IL_02e0: Expected O, but got Unknown
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Expected O, but got Unknown
//IL_0158: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Expected O, but got Unknown
//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
//IL_01d0: Expected O, but got Unknown
//IL_0231: Unknown result type (might be due to invalid IL or missing references)
//IL_023e: Expected O, but got Unknown
//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
//IL_02b5: Expected O, but got Unknown
_logger = ((BasePlugin)this).Log;
_logger.LogInfo((object)"[ObjectCounter] loaded");
restartKeyConfig = ((BasePlugin)this).Config.Bind<string>("Hotkeys", "InstantRestart", "LeftControl+R", "Instant restart key combination (LeftControl+R by default)");
ClassInjector.RegisterTypeInIl2Cpp<ObjectCounterBehaviour>();
hudGO = new GameObject("MegaBonk_ObjectCounter_HUD");
Object.DontDestroyOnLoad((Object)(object)hudGO);
((Object)hudGO).hideFlags = (HideFlags)61;
hudBehaviour = hudGO.AddComponent<ObjectCounterBehaviour>();
hudBehaviour.SetRestartKey(restartKeyConfig.Value);
harmony = new Harmony("com.yourname.megabonk.objectcounter");
try
{
Type typeFromHandle = typeof(SpawnInteractables);
MethodInfo method = typeFromHandle.GetMethod("SpawnChests", BindingFlags.Instance | BindingFlags.Public);
if (method != null)
{
harmony.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(typeof(ObjectTrackerPatches).GetMethod("TrackSpawnChests")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
_logger.LogInfo((object)"Successfully patched SpawnInteractables.SpawnChests");
}
else
{
_logger.LogWarning((object)"SpawnChests method not found");
}
MethodInfo method2 = typeFromHandle.GetMethod("SpawnShrines", BindingFlags.Instance | BindingFlags.Public);
if (method2 != null)
{
harmony.Patch((MethodBase)method2, (HarmonyMethod)null, new HarmonyMethod(typeof(ObjectTrackerPatches).GetMethod("TrackSpawnShrines")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
_logger.LogInfo((object)"Successfully patched SpawnInteractables.SpawnShrines");
}
else
{
_logger.LogWarning((object)"SpawnShrines method not found");
}
MethodInfo method3 = typeFromHandle.GetMethod("SpawnOther", BindingFlags.Instance | BindingFlags.NonPublic);
if (method3 != null)
{
harmony.Patch((MethodBase)method3, (HarmonyMethod)null, new HarmonyMethod(typeof(ObjectTrackerPatches).GetMethod("TrackSpawnOther")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
_logger.LogInfo((object)"Successfully patched SpawnInteractables.SpawnOther");
}
else
{
_logger.LogWarning((object)"SpawnOther method not found");
}
MethodInfo method4 = typeFromHandle.GetMethod("SpawnShit", BindingFlags.Instance | BindingFlags.Public);
if (method4 != null)
{
harmony.Patch((MethodBase)method4, (HarmonyMethod)null, new HarmonyMethod(typeof(ObjectTrackerPatches).GetMethod("TrackSpawnShit")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
_logger.LogInfo((object)"Successfully patched SpawnInteractables.SpawnShit");
}
else
{
_logger.LogWarning((object)"SpawnShit method not found");
}
MethodInfo method5 = typeof(InteractableShadyGuy).GetMethod("Start", BindingFlags.Instance | BindingFlags.Public);
if (method5 != null)
{
harmony.Patch((MethodBase)method5, (HarmonyMethod)null, new HarmonyMethod(typeof(ObjectTrackerPatches).GetMethod("TrackShadyGuy")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
_logger.LogInfo((object)"Successfully patched InteractableShadyGuy.Start");
}
}
catch (Exception ex)
{
ManualLogSource logger = _logger;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(32, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Error applying Harmony patches: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
}
logger.LogError(val);
}
SceneManager.sceneLoaded += UnityAction<Scene, LoadSceneMode>.op_Implicit((Action<Scene, LoadSceneMode>)OnSceneLoaded);
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
ManualLogSource logger = _logger;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(30, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ObjectCounter] Scene loaded: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Scene)(ref scene)).name);
}
logger.LogInfo(val);
if (((Scene)(ref scene)).name == "GeneratedMap" || ((Scene)(ref scene)).name.Contains("Game") || ((Scene)(ref scene)).name.Contains("Level"))
{
if ((Object)(object)hudBehaviour != (Object)null)
{
hudBehaviour.ResetCounts();
}
ObjectCounterBehaviour objectCounterBehaviour = hudBehaviour;
if (objectCounterBehaviour != null)
{
((MonoBehaviour)objectCounterBehaviour).Invoke("FindExistingObjects", 1f);
}
}
}
public static void LogMessage(string message)
{
ManualLogSource logger = _logger;
if (logger != null)
{
logger.LogInfo((object)message);
}
}
}
[HarmonyPatch]
public static class ObjectTrackerPatches
{
[HarmonyPostfix]
public static void TrackSpawnChests(SpawnInteractables __instance)
{
ObjectCounterBehaviour objectCounterBehaviour = Object.FindObjectOfType<ObjectCounterBehaviour>();
if ((Object)(object)objectCounterBehaviour != (Object)null)
{
FieldInfo field = typeof(SpawnInteractables).GetField("numChestsPerStage", BindingFlags.Static | BindingFlags.Public);
if (field != null)
{
int num = (int)field.GetValue(null);
objectCounterBehaviour.SetChests(num);
Plugin.LogMessage($"[ObjectCounter] Chests spawned: {num}");
}
}
}
[HarmonyPostfix]
public static void TrackSpawnShrines(SpawnInteractables __instance)
{
ObjectCounterBehaviour objectCounterBehaviour = Object.FindObjectOfType<ObjectCounterBehaviour>();
if ((Object)(object)objectCounterBehaviour != (Object)null)
{
FieldInfo field = typeof(SpawnInteractables).GetField("numShrines", BindingFlags.Static | BindingFlags.Public);
if (field != null)
{
int num = (int)field.GetValue(null);
objectCounterBehaviour.SetShrines(num);
Plugin.LogMessage($"[ObjectCounter] Shrines spawned: {num}");
}
}
}
[HarmonyPostfix]
public static void TrackSpawnOther(SpawnInteractables __instance)
{
ObjectCounterBehaviour objectCounterBehaviour = Object.FindObjectOfType<ObjectCounterBehaviour>();
if ((Object)(object)objectCounterBehaviour != (Object)null)
{
((MonoBehaviour)objectCounterBehaviour).Invoke("FindExistingObjects", 0.5f);
Plugin.LogMessage("[ObjectCounter] Other objects spawned, searching...");
}
}
[HarmonyPostfix]
public static void TrackSpawnShit(SpawnInteractables __instance)
{
ObjectCounterBehaviour objectCounterBehaviour = Object.FindObjectOfType<ObjectCounterBehaviour>();
if ((Object)(object)objectCounterBehaviour != (Object)null)
{
((MonoBehaviour)objectCounterBehaviour).Invoke("FindExistingObjects", 1f);
Plugin.LogMessage("[ObjectCounter] All objects spawned, updating counters...");
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(InteractableShadyGuy), "Start")]
public static void TrackShadyGuy(InteractableShadyGuy __instance)
{
ObjectCounterBehaviour objectCounterBehaviour = Object.FindObjectOfType<ObjectCounterBehaviour>();
if ((Object)(object)objectCounterBehaviour != (Object)null)
{
objectCounterBehaviour.IncrementTraders();
Plugin.LogMessage("[ObjectCounter] Trader found");
}
}
}
public struct ObjectCounts
{
public int traders;
public int microwaves;
public int moaiHeads;
public int magnets;
public int cursedShrines;
public int challengeShrines;
}
public class ObjectCounterBehaviour : MonoBehaviour
{
private ObjectCounts counts;
private bool visible = false;
private string restartKeyCombo;
public void SetRestartKey(string keyCombo)
{
restartKeyCombo = keyCombo;
}
public void ResetCounts()
{
counts = default(ObjectCounts);
}
public void SetChests(int count)
{
}
public void SetShrines(int count)
{
counts.moaiHeads = count;
}
public void IncrementTraders()
{
counts.traders++;
}
public void IncrementMicrowaves()
{
counts.microwaves++;
}
public void IncrementMoaiHeads()
{
counts.moaiHeads++;
}
public void IncrementMagnets()
{
counts.magnets++;
}
public void IncrementCursedShrines()
{
counts.cursedShrines++;
}
public void IncrementChallengeShrines()
{
counts.challengeShrines++;
}
public void FindExistingObjects()
{
try
{
Il2CppArrayBase<InteractableShadyGuy> val = Object.FindObjectsOfType<InteractableShadyGuy>();
Il2CppArrayBase<InteractableMicrowave> val2 = Object.FindObjectsOfType<InteractableMicrowave>();
Il2CppArrayBase<InteractableShrineMoai> val3 = Object.FindObjectsOfType<InteractableShrineMoai>();
Il2CppArrayBase<InteractableShrineMagnet> val4 = Object.FindObjectsOfType<InteractableShrineMagnet>();
Il2CppArrayBase<InteractableShrineCursed> val5 = Object.FindObjectsOfType<InteractableShrineCursed>();
Il2CppArrayBase<InteractableShrineChallenge> val6 = Object.FindObjectsOfType<InteractableShrineChallenge>();
counts.traders = val?.Length ?? 0;
counts.microwaves = val2?.Length ?? 0;
counts.moaiHeads = val3?.Length ?? 0;
counts.magnets = val4?.Length ?? 0;
counts.cursedShrines = val5?.Length ?? 0;
counts.challengeShrines = val6?.Length ?? 0;
Plugin.LogMessage($"[ObjectCounter] Found objects - Traders: {counts.traders}, Microwaves: {counts.microwaves}, Moai: {counts.moaiHeads}, Magnets: {counts.magnets}, Cursed: {counts.cursedShrines}, Challenge: {counts.challengeShrines}");
}
catch (Exception value)
{
Plugin.LogMessage($"[ObjectCounter] Error finding objects: {value}");
}
}
private void Update()
{
if (Input.GetKeyDown((KeyCode)9))
{
visible = true;
}
if (Input.GetKeyUp((KeyCode)9))
{
visible = false;
}
if (CheckRestartKey())
{
InstantRestart();
}
}
private bool CheckRestartKey()
{
return (Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)9)) && Input.GetKeyDown((KeyCode)282);
}
private void InstantRestart()
{
try
{
Type typeFromHandle = typeof(MapController);
MethodInfo method = typeFromHandle.GetMethod("RestartRun", BindingFlags.Static | BindingFlags.Public);
if (method != null)
{
method.Invoke(null, null);
Plugin.LogMessage("[ObjectCounter] Instant restart triggered");
}
else
{
Plugin.LogMessage("[ObjectCounter] RestartRun method not found");
}
}
catch (Exception value)
{
Plugin.LogMessage($"[ObjectCounter] Error during instant restart: {value}");
}
}
private void OnGUI()
{
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Expected O, but got Unknown
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Expected O, but got Unknown
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_0265: Unknown result type (might be due to invalid IL or missing references)
if (visible)
{
int num = 320;
int num2 = 200;
int num3 = 8;
Rect val = default(Rect);
((Rect)(ref val))..ctor((float)(Screen.width - num - num3), (float)(Screen.height - num2 - num3), (float)num, (float)num2);
GUIStyle val2 = new GUIStyle(GUI.skin.box);
val2.alignment = (TextAnchor)0;
val2.fontSize = 20;
val2.normal.textColor = Color.white;
GUI.Box(val, "", val2);
Rect val3 = default(Rect);
((Rect)(ref val3))..ctor(((Rect)(ref val)).x + 15f, ((Rect)(ref val)).y + 15f, ((Rect)(ref val)).width - 30f, ((Rect)(ref val)).height - 30f);
GUIStyle val4 = new GUIStyle(GUI.skin.label);
val4.fontSize = 18;
val4.alignment = (TextAnchor)0;
val4.normal.textColor = Color.white;
string[] array = new string[6]
{
$"Traders: {counts.traders}",
$"Moai Heads: {counts.moaiHeads}",
$"Microwaves: {counts.microwaves}",
$"Challenge: {counts.challengeShrines}",
$"Magnets: {counts.magnets}",
$"Cursed: {counts.cursedShrines}"
};
Rect val5 = default(Rect);
for (int i = 0; i < array.Length; i++)
{
((Rect)(ref val5))..ctor(((Rect)(ref val3)).x, ((Rect)(ref val3)).y + (float)(i * 28), ((Rect)(ref val3)).width, 25f);
GUI.Label(val5, array[i], val4);
}
}
}
}
}