using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BoneLib.BoneMenu;
using HarmonyLib;
using HealthRegenToggle;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "HealthRegenToggle", "1.0.2", "jorink", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("HealthRegenToggle")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+b729beb481c6a68ff87382ca3ded6405a21714c8")]
[assembly: AssemblyProduct("HealthRegenToggle")]
[assembly: AssemblyTitle("HealthRegenToggle")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 HealthRegenToggle
{
public class Core : MelonMod
{
internal static Core Instance;
private bool lastRegenEnabled;
private MelonPreferences_Category category;
private MelonPreferences_Entry<bool> RegenEntry;
public override void OnInitializeMelon()
{
Instance = this;
SetupMelonPreferences();
lastRegenEnabled = RegenEntry.Value;
SetupBoneMenu();
PatchRegenMethods();
}
public override void OnUpdate()
{
if (RegenEntry != null)
{
bool value = RegenEntry.Value;
if (value != lastRegenEnabled)
{
lastRegenEnabled = value;
}
}
}
private void SetupBoneMenu()
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
Page obj = Page.Root.CreatePage("Jorink", Color.red, 0, true).CreatePage("HealthRegenToggle", Color.green, 0, true);
obj.CreateBool("Enable Health Regen", Color.blue, RegenEntry.Value, (Action<bool>)delegate(bool a)
{
RegenEntry.Value = a;
});
obj.CreateFunction("Save Settings", Color.cyan, (Action)delegate
{
MelonPreferences.Save();
});
}
private void SetupMelonPreferences()
{
category = MelonPreferences.CreateCategory("HealthRegenToggle");
RegenEntry = category.CreateEntry<bool>("Health Regen", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
MelonPreferences.Save();
category.SaveToFile(true);
}
private void PatchRegenMethods()
{
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Expected O, but got Unknown
MethodInfo method = typeof(Core).GetMethod("AllowHealthRegen", BindingFlags.Static | BindingFlags.NonPublic);
HashSet<string> hashSet = new HashSet<string>();
Type type = TryResolveType("Il2CppSLZ.Marrow.Player_Health");
if (type == null)
{
MelonLogger.Warning("Could not resolve target type Il2CppSLZ.Marrow.Player_Health.");
return;
}
Type[] nestedTypes = type.GetNestedTypes(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
foreach (Type type2 in nestedTypes)
{
if (!type2.Name.Contains("CoRegenHealth"))
{
continue;
}
MethodInfo method2 = type2.GetMethod("MoveNext", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (method2 == null)
{
continue;
}
string methodKey = GetMethodKey(method2);
if (hashSet.Add(methodKey))
{
try
{
((MelonBase)this).HarmonyInstance.Patch((MethodBase)method2, new HarmonyMethod(method), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
catch (Exception ex)
{
MelonLogger.Warning($"Failed to patch coroutine {type2.FullName}.MoveNext: {ex.GetType().Name}: {ex.Message}");
}
}
}
}
private static string GetMethodKey(MethodInfo method)
{
return $"{method.DeclaringType?.FullName ?? "<null>"}::{method}";
}
private static Type TryResolveType(string fullTypeName)
{
Type type = Type.GetType(fullTypeName, throwOnError: false);
if (type != null)
{
return type;
}
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
for (int i = 0; i < assemblies.Length; i++)
{
type = assemblies[i].GetType(fullTypeName, throwOnError: false, ignoreCase: false);
if (type != null)
{
return type;
}
}
return null;
}
private static bool AllowHealthRegen()
{
if (Instance == null)
{
return true;
}
return Instance.RegenEntry.Value;
}
}
}