using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Assets.Scripts.Utility;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using MelonLoader;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("MoreRefreshes")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MoreRefreshes")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a052f8b9-b678-40b0-a576-d1c5418579fb")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SaveLoadWeapons
{
[BepInPlugin("mike9k1.megabonk.morerefreshes", "More Refreshes on Level Up", "0.0.3")]
public class MoreRefreshClass : MelonMod
{
public new const string PLUGIN_GUID = "mike9k1.megabonk.morerefreshes";
public new const string PLUGIN_NAME = "More Refreshes on Level Up";
public new const string PLUGIN_VERSION = "0.0.3";
private string PlayerTypeName = "Assets.Scripts.Utility.MyTime";
private string SlideMethodName = "stageTimer";
private string LevelTypeName = "LevelupScreen";
private string LevelMethodName = "GetRefreshes";
private string RefreshTypeName = "PlayerInventory";
private string RefreshMethodName = "Update";
private static int newRefreshCount = 2;
private static int initialRefreshValue = -1;
private LevelupScreen lvlScreen;
private float lastTime;
private static void SlidePostfix(PlayerInventory __instance)
{
if (initialRefreshValue < 0)
{
initialRefreshValue = 0;
initialRefreshValue += __instance.refreshes;
}
__instance.refreshesUsed = 0;
__instance.banishesUsed = 0;
__instance.skipsUsed = 0;
if (newRefreshCount > 0)
{
__instance.skips = 500;
__instance.banishes += newRefreshCount;
__instance.refreshes += newRefreshCount;
newRefreshCount = 0;
MelonLogger.Msg("Refresh postfix executed. More refreshes added");
}
}
private static Type FindType(string fullName)
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
try
{
Type type = assembly.GetType(fullName, throwOnError: false);
if (type != null)
{
return type;
}
}
catch
{
}
}
return null;
}
private void UpdateRefreshes()
{
Type type = FindType(PlayerTypeName);
if (type == null)
{
MelonLogger.Error("Type not found: " + PlayerTypeName);
return;
}
PropertyInfo property = type.GetProperty(SlideMethodName);
if (property == null)
{
MelonLogger.Error("Property not found: " + type.FullName + "." + SlideMethodName + "()");
return;
}
float num = (float)property.GetValue(property);
if (num - lastTime >= 60f)
{
newRefreshCount++;
lastTime = num;
}
else if (num < lastTime)
{
lastTime = num;
newRefreshCount = 2;
}
Type type2 = FindType(LevelTypeName);
if (type2 == null)
{
MelonLogger.Error("Type not found: " + LevelTypeName);
return;
}
lvlScreen = Object.FindFirstObjectByType<LevelupScreen>();
if (!((Object)(object)lvlScreen == (Object)null))
{
type2.GetProperty("hasRefreshes").SetValue(lvlScreen, true);
}
}
private void TryPatch()
{
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Expected O, but got Unknown
Type type = FindType(RefreshTypeName);
if (type == null)
{
MelonLogger.Error("Type not found: " + LevelTypeName);
return;
}
MethodInfo method = type.GetMethod(RefreshMethodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (method == null)
{
MelonLogger.Error("Method not found: " + type.FullName + "." + LevelMethodName + "()");
}
else
{
HarmonyMethod val = new HarmonyMethod(typeof(MoreRefreshClass).GetMethod("SlidePostfix", BindingFlags.Static | BindingFlags.NonPublic));
HarmonyInstance.Patch((MethodBase)method, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
MelonLogger.Msg("Patched " + type.FullName + "." + LevelMethodName + "()");
}
}
public override void OnInitializeMelon()
{
TryPatch();
}
public override void OnFixedUpdate()
{
UpdateRefreshes();
}
}
}
namespace MelonLoader
{
public class MelonMod : BasePlugin
{
public Harmony HarmonyInstance;
public static MelonMod melonModRef;
public virtual string PLUGIN_GUID => "author.game.modname";
public virtual string PLUGIN_NAME => "Mod Name Here";
public virtual string PLUGIN_VERSION => "0.0.1";
public MelonMod()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
HarmonyInstance = new Harmony(PLUGIN_GUID);
melonModRef = this;
}
public virtual void OnInitializeMelon()
{
}
public virtual void OnLateInitializeMelon()
{
}
public virtual void OnFixedUpdate()
{
}
public virtual void OnUpdate()
{
}
public override void Load()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Expected O, but got Unknown
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Expected O, but got Unknown
OnInitializeMelon();
HarmonyMethod val = new HarmonyMethod(typeof(MelonMod).GetMethod("FixedUpdate"));
HarmonyInstance.Patch((MethodBase)typeof(MyTime).GetMethod("FixedUpdate"), (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
HarmonyMethod val2 = new HarmonyMethod(typeof(MelonMod).GetMethod("Update"));
HarmonyInstance.Patch((MethodBase)typeof(MyTime).GetMethod("Update"), (HarmonyMethod)null, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
public void Awake()
{
OnLateInitializeMelon();
}
public static void FixedUpdate()
{
melonModRef.OnFixedUpdate();
}
public static void Update()
{
melonModRef.OnUpdate();
}
}
public class MelonLogger
{
private static ManualLogSource log;
private static bool logAdded;
public static void Msg(string message)
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Expected O, but got Unknown
if (!logAdded)
{
log = new ManualLogSource(((AssemblyTitleAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), inherit: false)[0]).Title);
Logger.Sources.Add((ILogSource)(object)log);
logAdded = true;
}
log.LogInfo((object)message);
}
public static void Error(string message)
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Expected O, but got Unknown
if (!logAdded)
{
log = new ManualLogSource(((AssemblyTitleAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), inherit: false)[0]).Title);
Logger.Sources.Add((ILogSource)(object)log);
logAdded = true;
}
log.LogError((object)message);
}
}
}