using System;
using System.Collections.Generic;
using System.Diagnostics;
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 IL.RoR2;
using IL.RoR2.UI;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using R2API.AutoVersionGen;
using R2API.Utils;
using RoR2;
using RoR2.UI;
using RoR2BepInExPack.Utilities;
using UnityEngine;
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("R2API.CharacterBody")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0+0001af9ee53c18d338c28cb692e36ce3daaf63a1")]
[assembly: AssemblyProduct("R2API.CharacterBody")]
[assembly: AssemblyTitle("R2API.CharacterBody")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.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.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 System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
internal sealed class MemberNotNullAttribute : Attribute
{
public string[] Members { get; }
public MemberNotNullAttribute(string member)
{
Members = new string[1] { member };
}
public MemberNotNullAttribute(params string[] members)
{
Members = members;
}
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
internal sealed class MemberNotNullWhenAttribute : Attribute
{
public bool ReturnValue { get; }
public string[] Members { get; }
public MemberNotNullWhenAttribute(bool returnValue, string member)
{
ReturnValue = returnValue;
Members = new string[1] { member };
}
public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
{
ReturnValue = returnValue;
Members = members;
}
}
}
namespace R2API
{
[AutoVersion]
public static class CharacterBodyAPI
{
public enum ModdedBodyFlag
{
}
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__SprintIcon_FixedUpdate;
public static Func<SprintIcon, bool> <1>__CheckCustomSprintIcon;
public static Action<SprintIcon> <2>__SetSprintIconCustomSprintIcon;
public static Func<SprintIcon, GameObject> <3>__GetCustomIconObject;
public static Action<GameObject> <4>__NullcheckAndDeactivateCustomIconObject;
}
public const string PluginGUID = "com.bepis.r2api.character_body";
public const string PluginName = "R2API.CharacterBody";
private static bool _hooksEnabled;
public const string PluginVersion = "1.3.0";
[Obsolete("All submodules are automatically loaded and this property is now unused")]
public static bool Loaded => true;
public static int ModdedBodyFlagCount { get; private set; }
internal static void SetHooks()
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Expected O, but got Unknown
if (!_hooksEnabled)
{
_hooksEnabled = true;
object obj = <>O.<0>__SprintIcon_FixedUpdate;
if (obj == null)
{
Manipulator val = SprintIcon_FixedUpdate;
<>O.<0>__SprintIcon_FixedUpdate = val;
obj = (object)val;
}
SprintIcon.FixedUpdate += (Manipulator)obj;
}
}
private static void SprintIcon_FixedUpdate(ILContext il)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_0251: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(il);
Instruction val2 = il.Instrs[il.Instrs.Count - 1];
Instruction val3 = il.Instrs[0];
val.Emit(OpCodes.Ldarg_0);
val.EmitDelegate<Func<SprintIcon, bool>>((Func<SprintIcon, bool>)CheckCustomSprintIcon);
val.Emit(OpCodes.Brfalse_S, val3);
val.Emit(OpCodes.Ldarg_0);
val.EmitDelegate<Action<SprintIcon>>((Action<SprintIcon>)SetSprintIconCustomSprintIcon);
val.Emit(OpCodes.Br, val2);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[4]
{
(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
(Instruction x) => ILPatternMatchingExt.MatchLdfld<SprintIcon>(x, "sprintIconObject"),
(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 0),
(Instruction x) => ILPatternMatchingExt.MatchCallvirt<GameObject>(x, "SetActive")
}))
{
_ = val.Next;
val.Emit(OpCodes.Ldarg_0);
val.EmitDelegate<Func<SprintIcon, GameObject>>((Func<SprintIcon, GameObject>)GetCustomIconObject);
val.EmitDelegate<Action<GameObject>>((Action<GameObject>)NullcheckAndDeactivateCustomIconObject);
}
else
{
CharacterBodyPlugin.Logger.LogError((object)(((MemberReference)il.Method).Name + " IL Hook 1 failed!"));
}
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[4]
{
(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
(Instruction x) => ILPatternMatchingExt.MatchLdfld<SprintIcon>(x, "sprintIconObject"),
(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 1),
(Instruction x) => ILPatternMatchingExt.MatchCallvirt<GameObject>(x, "SetActive")
}))
{
_ = val.Next;
val.Emit(OpCodes.Ldarg_0);
val.EmitDelegate<Func<SprintIcon, GameObject>>((Func<SprintIcon, GameObject>)GetCustomIconObject);
val.EmitDelegate<Action<GameObject>>((Action<GameObject>)NullcheckAndDeactivateCustomIconObject);
}
else
{
CharacterBodyPlugin.Logger.LogError((object)(((MemberReference)il.Method).Name + " IL Hook 2 failed!"));
}
}
internal static void UnsetHooks()
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Expected O, but got Unknown
if (_hooksEnabled)
{
_hooksEnabled = false;
object obj = <>O.<0>__SprintIcon_FixedUpdate;
if (obj == null)
{
Manipulator val = SprintIcon_FixedUpdate;
<>O.<0>__SprintIcon_FixedUpdate = val;
obj = (object)val;
}
SprintIcon.FixedUpdate -= (Manipulator)obj;
}
}
private static void NullcheckAndDeactivateCustomIconObject(GameObject gameObject)
{
if (gameObject != null)
{
gameObject.SetActive(false);
}
}
private static bool CheckCustomSprintIcon(SprintIcon sprintIcon)
{
if (Object.op_Implicit((Object)(object)sprintIcon.body))
{
return Object.op_Implicit((Object)(object)sprintIcon.body.GetCustomSprintIcon());
}
return false;
}
private static void SetSprintIconCustomSprintIcon(SprintIcon sprintIcon)
{
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
Sprite customSprintIcon = sprintIcon.body.GetCustomSprintIcon();
GameObject val = sprintIcon.GetCustomIconObject();
if (Object.op_Implicit((Object)(object)val))
{
if ((Object)(object)sprintIcon.GetCurrentCustomSprintIcon() != (Object)(object)customSprintIcon)
{
val.GetComponent<Image>().sprite = customSprintIcon;
sprintIcon.SetCurrentCustomSprintIcon(customSprintIcon);
}
}
else
{
Transform val2 = ((Component)sprintIcon).transform.Find("SprintIcon");
if (Object.op_Implicit((Object)(object)val2))
{
val = Object.Instantiate<GameObject>(((Component)val2).gameObject, ((Component)sprintIcon).transform);
val.transform.position = val2.position;
val.transform.rotation = val2.rotation;
val.transform.localScale = val2.localScale;
sprintIcon.SetCustomIconObject(val);
Image component = val.GetComponent<Image>();
if (Object.op_Implicit((Object)(object)component))
{
component.sprite = customSprintIcon;
sprintIcon.SetCurrentCustomSprintIcon(customSprintIcon);
}
}
}
if (val != null)
{
val.SetActive(true);
}
GameObject descendIconObject = sprintIcon.descendIconObject;
if (descendIconObject != null)
{
descendIconObject.SetActive(false);
}
GameObject sprintIconObject = sprintIcon.sprintIconObject;
if (sprintIconObject != null)
{
sprintIconObject.SetActive(false);
}
}
public static ModdedBodyFlag ReserveBodyFlag()
{
SetHooks();
if (ModdedBodyFlagCount >= 1152)
{
throw new IndexOutOfRangeException($"Reached the limit of {1152} ModdedBodyFlags. Please contact R2API developers to increase the limit");
}
ModdedBodyFlagCount++;
return (ModdedBodyFlag)ModdedBodyFlagCount;
}
public static void AddModdedBodyFlag(this CharacterBody characterBody, ModdedBodyFlag moddedBodyFlag)
{
AddModdedBodyFlagInternal(characterBody, moddedBodyFlag);
}
public static bool RemoveModdedBodyFlag(this CharacterBody characterBody, ModdedBodyFlag moddedBodyFlag)
{
return RemoveModdedBodyFlagInternal(characterBody, moddedBodyFlag);
}
public static bool HasAnyModdedBodyFlag(this CharacterBody characterBody)
{
SetHooks();
byte[] moddedBodyFlags = CharacterBodyInterop.GetModdedBodyFlags(characterBody);
if (moddedBodyFlags != null)
{
return moddedBodyFlags.Length != 0;
}
return false;
}
public static bool HasModdedBodyFlag(this CharacterBody characterBody, ModdedBodyFlag moddedBodyFlag)
{
return HasModdedBodyFlagInternal(characterBody, moddedBodyFlag);
}
private static void AddModdedBodyFlagInternal(CharacterBody characterBody, ModdedBodyFlag moddedBodyFlag)
{
SetHooks();
if (CheckRange(characterBody, moddedBodyFlag))
{
byte[] moddedBodyFlags = CharacterBodyInterop.GetModdedBodyFlags(characterBody);
CompressedFlagArrayUtilities.AddImmutable(ref moddedBodyFlags, (int)(moddedBodyFlag - 1));
CharacterBodyInterop.SetModdedBodyFlags(characterBody, moddedBodyFlags);
}
}
private static bool RemoveModdedBodyFlagInternal(CharacterBody characterBody, ModdedBodyFlag moddedBodyFlag)
{
SetHooks();
if (!CheckRange(characterBody, moddedBodyFlag))
{
return false;
}
byte[] moddedBodyFlags = CharacterBodyInterop.GetModdedBodyFlags(characterBody);
bool result = CompressedFlagArrayUtilities.RemoveImmutable(ref moddedBodyFlags, (int)(moddedBodyFlag - 1));
CharacterBodyInterop.SetModdedBodyFlags(characterBody, moddedBodyFlags);
return result;
}
private static bool HasModdedBodyFlagInternal(CharacterBody characterBody, ModdedBodyFlag moddedBodyFlag)
{
SetHooks();
if (!CheckRange(characterBody, moddedBodyFlag))
{
return false;
}
return CompressedFlagArrayUtilities.Has(CharacterBodyInterop.GetModdedBodyFlags(characterBody), (int)(moddedBodyFlag - 1));
}
private static bool CheckRange(CharacterBody characterBody, ModdedBodyFlag moddedBodyFlag)
{
if ((int)moddedBodyFlag > ModdedBodyFlagCount || moddedBodyFlag < (ModdedBodyFlag)1)
{
CharacterBodyPlugin.Logger.LogError((object)string.Format("Parameter '{0}' with value {1} is out of range of registered types (1-{2})\n{3}", "moddedBodyFlag", moddedBodyFlag, ModdedBodyFlagCount, new StackTrace(fNeedFileInfo: true)));
return false;
}
return true;
}
public static Sprite GetCustomSprintIcon(this CharacterBody characterBody)
{
return CharacterBodyInterop.GetCustomSprintIcon(characterBody);
}
public static void SetCustomSprintIcon(this CharacterBody characterBody, Sprite sprite)
{
CharacterBodyInterop.SetCustomSprintIcon(characterBody, sprite);
}
private static GameObject GetCustomIconObject(this SprintIcon sprintIcon)
{
return CharacterBodyInterop.GetCustomIconObject(sprintIcon);
}
private static void SetCustomIconObject(this SprintIcon sprintIcon, GameObject gameobject)
{
CharacterBodyInterop.SetCustomIconObject(sprintIcon, gameobject);
}
private static Sprite GetCurrentCustomSprintIcon(this SprintIcon sprintIcon)
{
return CharacterBodyInterop.GetCurrentCustomSprintIcon(sprintIcon);
}
private static void SetCurrentCustomSprintIcon(this SprintIcon sprintIcon, Sprite sprite)
{
CharacterBodyInterop.SetCurrentCustomSprintIcon(sprintIcon, sprite);
}
}
[BepInPlugin("com.bepis.r2api.character_body", "R2API.CharacterBody", "1.3.0")]
public sealed class CharacterBodyPlugin : BaseUnityPlugin
{
internal static ManualLogSource Logger { get; set; }
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
CharacterBodyAPI.SetHooks();
HealthBarAPI.SetHooks();
FootstepAPI.SetHooks();
}
private void OnDestroy()
{
CharacterBodyAPI.UnsetHooks();
HealthBarAPI.UnsetHooks();
FootstepAPI.UnsetHooks();
}
}
public static class FootstepAPI
{
public struct FootstepReport
{
public Transform childTransform;
public int childIndex;
public string childName;
public FootstepHandler footstepHandler;
public SurfaceDef surfaceDef;
public RaycastHit raycastHit;
public GameObject footstepEffect;
}
public delegate void Footstep(FootstepReport footstepReport);
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__FootstepHandler_Footstep_string_GameObject;
public static <>A{00000200}<Transform, int, string, RaycastHit, SurfaceDef, FootstepHandler, GameObject> <1>__HandleFootstep;
}
private static bool _hooksEnabled;
public static event Footstep OnFootstep;
internal static void SetHooks()
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Expected O, but got Unknown
if (!_hooksEnabled)
{
_hooksEnabled = true;
object obj = <>O.<0>__FootstepHandler_Footstep_string_GameObject;
if (obj == null)
{
Manipulator val = FootstepHandler_Footstep_string_GameObject;
<>O.<0>__FootstepHandler_Footstep_string_GameObject = val;
obj = (object)val;
}
FootstepHandler.Footstep_string_GameObject += (Manipulator)obj;
}
}
private static void FootstepHandler_Footstep_string_GameObject(ILContext il)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Expected O, but got Unknown
//IL_014b: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_018d: Unknown result type (might be due to invalid IL or missing references)
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(il);
int childTransformLocal = 0;
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[2]
{
(Instruction x) => ILPatternMatchingExt.MatchCallvirt<ChildLocator>(x, "FindChild"),
(Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref childTransformLocal)
}))
{
int childIndexLocal = 0;
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[2]
{
(Instruction x) => ILPatternMatchingExt.MatchCallvirt<ChildLocator>(x, "FindChildIndex"),
(Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref childIndexLocal)
}))
{
int raycastHitLocal = 0;
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[2]
{
(Instruction x) => ILPatternMatchingExt.MatchLdloca(x, ref raycastHitLocal),
(Instruction x) => ILPatternMatchingExt.MatchInitobj<RaycastHit>(x)
}))
{
int surfaceDefLocal = 0;
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[2]
{
(Instruction x) => ILPatternMatchingExt.MatchCall<SurfaceDefProvider>(x, "GetObjectSurfaceDef"),
(Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref surfaceDefLocal)
}))
{
val.Emit(OpCodes.Ldloc, childTransformLocal);
val.Emit(OpCodes.Ldloc, childIndexLocal);
val.Emit(OpCodes.Ldarg_1);
val.Emit(OpCodes.Ldloca, raycastHitLocal);
val.Emit(OpCodes.Ldloc, surfaceDefLocal);
val.Emit(OpCodes.Ldarg_0);
val.Emit(OpCodes.Ldarg_2);
val.EmitDelegate<<>A{00000200}<Transform, int, string, RaycastHit, SurfaceDef, FootstepHandler, GameObject>>((<>A{00000200}<Transform, int, string, RaycastHit, SurfaceDef, FootstepHandler, GameObject>)HandleFootstep);
}
else
{
CharacterBodyPlugin.Logger.LogError((object)(((MemberReference)il.Method).Name + " IL Hook 4 failed!"));
}
}
else
{
CharacterBodyPlugin.Logger.LogError((object)(((MemberReference)il.Method).Name + " IL Hook 3 failed!"));
}
}
else
{
CharacterBodyPlugin.Logger.LogError((object)(((MemberReference)il.Method).Name + " IL Hook 2 failed!"));
}
}
else
{
CharacterBodyPlugin.Logger.LogError((object)(((MemberReference)il.Method).Name + " IL Hook 1 failed!"));
}
}
private static void HandleFootstep(Transform transform, int index, string name, ref RaycastHit raycastHit, SurfaceDef surfaceDef, FootstepHandler footstepHandler, GameObject footstepEffect)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
FootstepReport footstepReport = default(FootstepReport);
footstepReport.childIndex = index;
footstepReport.childName = name;
footstepReport.childTransform = transform;
footstepReport.raycastHit = raycastHit;
footstepReport.footstepHandler = footstepHandler;
footstepReport.surfaceDef = surfaceDef;
footstepReport.footstepEffect = footstepEffect;
FootstepReport footstepReport2 = footstepReport;
FootstepAPI.OnFootstep?.Invoke(footstepReport2);
}
internal static void UnsetHooks()
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Expected O, but got Unknown
if (_hooksEnabled)
{
_hooksEnabled = false;
object obj = <>O.<0>__FootstepHandler_Footstep_string_GameObject;
if (obj == null)
{
Manipulator val = FootstepHandler_Footstep_string_GameObject;
<>O.<0>__FootstepHandler_Footstep_string_GameObject = val;
obj = (object)val;
}
FootstepHandler.Footstep_string_GameObject -= (Manipulator)obj;
}
}
}
public static class HealthBarAPI
{
internal delegate void HealthValuesRefPasser(HealthBar source, AssignedOverlaysData data, ref float current, ref float max);
public class BarOverlayInfo
{
public delegate void ModifyBarInfoCallback(HealthBar source, ref BarInfo barInfo);
public delegate void ModifyHealthValuesCallback(HealthBar source, ref float currentHealth, ref float maxHealth);
public BarInfo BarInfo;
public bool BodySpecific;
public ModifyBarInfoCallback ModifyBarInfo;
public ModifyHealthValuesCallback ModifyHealthValues;
public BarOverlayIndex OverlayIndex;
}
public enum BarOverlayIndex
{
None = -1
}
internal class AssignedOverlaysData
{
internal bool[] AssignedOverlays = new bool[OverlayInfos.Count];
internal void UpdateSize()
{
if (OverlayInfos.Count > AssignedOverlays.Length)
{
bool[] array = new bool[AssignedOverlays.Length + 32];
for (int i = 0; i < AssignedOverlays.Length; i++)
{
array[i] = AssignedOverlays[i];
}
AssignedOverlays = array;
}
}
}
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__HandleBarInfos;
public static Manipulator <1>__HandleBarValues;
}
private static bool _hooksEnabled;
private static bool alreadyLoaded;
private static bool valuesHookFailed;
private static bool overlaysHookFailed;
private static List<BarOverlayInfo> OverlayInfos = new List<BarOverlayInfo>();
private static FixedConditionalWeakTable<HealthComponent, AssignedOverlaysData> HealthBarData = new FixedConditionalWeakTable<HealthComponent, AssignedOverlaysData>();
private static MethodInfo get_source;
private static MethodInfo get_combinedHealth;
private static int lastClaimedBarIndex = 0;
internal static void SetHooks(bool reset = false)
{
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Expected O, but got Unknown
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Expected O, but got Unknown
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Expected O, but got Unknown
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Expected O, but got Unknown
if (!reset)
{
RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, (Action)delegate
{
alreadyLoaded = true;
if (OverlayInfos.Count > 0)
{
EvaluateHooks();
}
});
get_source = AccessTools.PropertyGetter(typeof(HealthBar), "source");
get_combinedHealth = AccessTools.PropertyGetter(typeof(HealthComponent), "combinedHealth");
return;
}
_hooksEnabled = true;
if (!overlaysHookFailed)
{
object obj = <>O.<0>__HandleBarInfos;
if (obj == null)
{
Manipulator val = HandleBarInfos;
<>O.<0>__HandleBarInfos = val;
obj = (object)val;
}
HealthBar.ApplyBars += (Manipulator)obj;
}
if (!valuesHookFailed)
{
object obj2 = <>O.<1>__HandleBarValues;
if (obj2 == null)
{
Manipulator val2 = HandleBarValues;
<>O.<1>__HandleBarValues = val2;
obj2 = (object)val2;
}
HealthBar.UpdateHealthbar += (Manipulator)obj2;
}
if (valuesHookFailed)
{
object obj3 = <>O.<1>__HandleBarValues;
if (obj3 == null)
{
Manipulator val3 = HandleBarValues;
<>O.<1>__HandleBarValues = val3;
obj3 = (object)val3;
}
HealthBar.UpdateHealthbar -= (Manipulator)obj3;
}
if (overlaysHookFailed)
{
object obj4 = <>O.<0>__HandleBarInfos;
if (obj4 == null)
{
Manipulator val4 = HandleBarInfos;
<>O.<0>__HandleBarInfos = val4;
obj4 = (object)val4;
}
HealthBar.ApplyBars -= (Manipulator)obj4;
}
}
internal static void UnsetHooks()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Expected O, but got Unknown
_hooksEnabled = false;
if (!overlaysHookFailed)
{
object obj = <>O.<0>__HandleBarInfos;
if (obj == null)
{
Manipulator val = HandleBarInfos;
<>O.<0>__HandleBarInfos = val;
obj = (object)val;
}
HealthBar.ApplyBars -= (Manipulator)obj;
}
if (!valuesHookFailed)
{
object obj2 = <>O.<1>__HandleBarValues;
if (obj2 == null)
{
Manipulator val2 = HandleBarValues;
<>O.<1>__HandleBarValues = val2;
obj2 = (object)val2;
}
HealthBar.UpdateHealthbar -= (Manipulator)obj2;
}
}
internal static void EvaluateHooks()
{
if (_hooksEnabled)
{
UnsetHooks();
}
SetHooks(reset: true);
}
internal static void HandleBarValues(ILContext il)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Expected O, but got Unknown
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Expected O, but got Unknown
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_0219: Unknown result type (might be due to invalid IL or missing references)
//IL_0225: Unknown result type (might be due to invalid IL or missing references)
//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
//IL_031e: Unknown result type (might be due to invalid IL or missing references)
//IL_032a: Unknown result type (might be due to invalid IL or missing references)
ILCursor val2 = new ILCursor(il);
VariableDefinition val3 = new VariableDefinition(il.Import(typeof(float)));
il.Method.Body.Variables.Add(val3);
VariableDefinition val4 = new VariableDefinition(il.Import(typeof(AssignedOverlaysData)));
il.Method.Body.Variables.Add(val4);
val2.Emit(OpCodes.Ldarg_0);
val2.EmitDelegate<Func<HealthBar, AssignedOverlaysData>>((Func<HealthBar, AssignedOverlaysData>)((HealthBar source) => Object.op_Implicit((Object)(object)source.source) ? HealthBarData.GetOrCreateValue(source.source) : null));
val2.Emit(OpCodes.Stloc, val4);
int fullHealthIndex = -1;
val2.TryGotoNext((MoveType)2, new Func<Instruction, bool>[2]
{
(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<HealthComponent>(x, "get_fullHealth"),
(Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref fullHealthIndex)
});
if (fullHealthIndex < 0)
{
valuesHookFailed = true;
return;
}
val2.Emit(OpCodes.Ldarg_0);
val2.Emit(OpCodes.Call, (MethodBase)get_source);
val2.Emit(OpCodes.Call, (MethodBase)get_combinedHealth);
val2.Emit(OpCodes.Stloc, val3);
foreach (BarOverlayInfo overlay in OverlayInfos)
{
val2.Emit(OpCodes.Ldarg_0);
val2.Emit(OpCodes.Ldloc, val4);
val2.Emit(OpCodes.Ldloca, val3);
val2.Emit(OpCodes.Ldloca, fullHealthIndex);
val2.EmitDelegate<HealthValuesRefPasser>((HealthValuesRefPasser)delegate(HealthBar source, AssignedOverlaysData data, ref float currentHealth, ref float maxHealth)
{
if (data != null && (!overlay.BodySpecific || data.AssignedOverlays[(int)overlay.OverlayIndex]))
{
overlay.ModifyHealthValues?.Invoke(source, ref currentHealth, ref maxHealth);
}
});
}
int index = val2.Next.Offset;
Assert(val2.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, fullHealthIndex) && x.Offset > index
}));
int num = default(int);
Assert(val2.TryGotoPrev((MoveType)0, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref num) && x.Offset > index
}));
if (valuesHookFailed)
{
return;
}
val2.Emit(OpCodes.Pop);
val2.Emit(OpCodes.Ldloc, val3);
Assert(val2.TryGotoNext((MoveType)0, new Func<Instruction, bool>[3]
{
(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, (MethodBase)get_combinedHealth),
(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
(Instruction x) => ILPatternMatchingExt.MatchLdfld<HealthBar>(x, "oldHealth")
}));
if (valuesHookFailed)
{
return;
}
int index2 = val2.Index;
val2.Index = index2 + 1;
val2.Emit(OpCodes.Pop);
val2.Emit(OpCodes.Ldloc, val3);
for (int i = 0; i < 2; i++)
{
Assert(val2.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, (MethodBase)get_combinedHealth)
}));
if (valuesHookFailed)
{
break;
}
val2.Emit(OpCodes.Pop);
val2.Emit(OpCodes.Ldloc, val3);
}
static void Assert(bool val)
{
if (!val)
{
valuesHookFailed = true;
CharacterBodyPlugin.Logger.LogError((object)"Failed to apply HandleBarValues hook.");
}
}
}
internal static void HandleBarInfos(ILContext il)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Expected O, but got Unknown
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Expected O, but got Unknown
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_012f: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Expected O, but got Unknown
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_019f: Unknown result type (might be due to invalid IL or missing references)
//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
//IL_021a: Unknown result type (might be due to invalid IL or missing references)
//IL_027e: Unknown result type (might be due to invalid IL or missing references)
//IL_028a: Unknown result type (might be due to invalid IL or missing references)
//IL_0298: Unknown result type (might be due to invalid IL or missing references)
//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(il);
MethodReference handleBar = null;
VariableDefinition val2 = null;
int allocatorIndex = -1;
bool flag = val.TryGotoNext(new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, ref handleBar) && handleBar != null && ((MemberReference)handleBar).Name.StartsWith("<ApplyBars>g__HandleBar|")
});
bool flag2 = val.TryGotoPrev(new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchLdloca(x, ref allocatorIndex)
});
if (!flag || !flag2 || allocatorIndex < 0 || allocatorIndex >= il.Method.Body.Variables.Count)
{
overlaysHookFailed = true;
CharacterBodyPlugin.Logger.LogError((object)"Failed to apply IL hook for ApplyBars.");
return;
}
val2 = il.Method.Body.Variables[allocatorIndex];
TypeReference val3 = il.Import(typeof(BarInfo));
val.Index = 0;
VariableDefinition val4 = new VariableDefinition(il.Import(typeof(AssignedOverlaysData)));
il.Method.Body.Variables.Add(val4);
val.Emit(OpCodes.Ldarg_0);
val.EmitDelegate<Func<HealthBar, AssignedOverlaysData>>((Func<HealthBar, AssignedOverlaysData>)((HealthBar source) => Object.op_Implicit((Object)(object)source.source) ? HealthBarData.GetOrCreateValue(source.source) : null));
val.Emit(OpCodes.Stloc, val4);
int index = val.Index;
foreach (BarOverlayInfo overlay in OverlayInfos)
{
val.Index = index;
VariableDefinition val5 = new VariableDefinition(val3);
il.Method.Body.Variables.Add(val5);
val.Emit(OpCodes.Ldarg_0);
val.Emit(OpCodes.Ldloc, val4);
val.EmitDelegate<Func<HealthBar, AssignedOverlaysData, BarInfo>>((Func<HealthBar, AssignedOverlaysData, BarInfo>)delegate(HealthBar source, AssignedOverlaysData data)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
BarInfo val6 = default(BarInfo);
val6.enabled = overlay.BarInfo.enabled;
val6.color = overlay.BarInfo.color;
val6.sprite = overlay.BarInfo.sprite;
val6.imageType = overlay.BarInfo.imageType;
val6.sizeDelta = overlay.BarInfo.sizeDelta;
val6.normalizedXMax = overlay.BarInfo.normalizedXMax;
val6.normalizedXMin = overlay.BarInfo.normalizedXMin;
BarInfo barInfo2 = val6;
if (data == null || (overlay.BodySpecific && !data.AssignedOverlays[(int)overlay.OverlayIndex]))
{
barInfo2.enabled = false;
return barInfo2;
}
overlay.ModifyBarInfo?.Invoke(source, ref barInfo2);
return barInfo2;
});
val.Emit(OpCodes.Stloc, val5);
if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<BarInfoCollection>(x, "GetActiveCount")
}))
{
overlaysHookFailed = true;
CharacterBodyPlugin.Logger.LogError((object)"Failed to find GetActiveCount in ApplyBars.");
break;
}
val.Emit(OpCodes.Ldloca, val5);
val.EmitDelegate<<>F{00000018}<int, BarInfo, int>>((<>F{00000018}<int, BarInfo, int>)delegate(int count, in BarInfo barInfo)
{
if (barInfo.enabled)
{
count++;
}
return count;
});
val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchRet(x)
});
val.Emit(OpCodes.Ldarg_0);
val.Emit(OpCodes.Ldloca, val5);
val.Emit(OpCodes.Ldloca, val2);
val.Emit(OpCodes.Call, handleBar);
}
}
public static BarOverlayIndex RegisterBarOverlay(BarOverlayInfo overlayInfo)
{
if (alreadyLoaded)
{
CharacterBodyPlugin.Logger.LogError((object)"Mod attempted to add a BarOverlayInfo after game load. This is not allowed.");
return BarOverlayIndex.None;
}
overlayInfo.OverlayIndex = (BarOverlayIndex)lastClaimedBarIndex;
lastClaimedBarIndex++;
OverlayInfos.Add(overlayInfo);
foreach (KeyValuePair<HealthComponent, AssignedOverlaysData> healthBarDatum in HealthBarData)
{
healthBarDatum.Value.UpdateSize();
}
return overlayInfo.OverlayIndex;
}
public static void AddOverlayToBody(CharacterBody body, BarOverlayIndex index)
{
if (index >= (BarOverlayIndex)0)
{
AssignedOverlaysData orCreateValue = HealthBarData.GetOrCreateValue(body.healthComponent);
if (orCreateValue.AssignedOverlays.Length >= (int)index)
{
orCreateValue.AssignedOverlays[(int)index] = true;
}
}
}
public static void RemoveOverlayFromBody(CharacterBody body, BarOverlayIndex index)
{
if (index >= (BarOverlayIndex)0)
{
AssignedOverlaysData orCreateValue = HealthBarData.GetOrCreateValue(body.healthComponent);
if (orCreateValue.AssignedOverlays.Length >= (int)index)
{
orCreateValue.AssignedOverlays[(int)index] = false;
}
}
}
}
}
namespace R2API.AutoVersionGen
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
internal class AutoVersionAttribute : Attribute
{
}
}