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 EntityStates; using HarmonyLib; using IL.RoR2; using IL.RoR2.CameraModes; using IL.RoR2.Skills; using IL.RoR2.UI; using Microsoft.CodeAnalysis; using Mono.Cecil; using Mono.Cecil.Cil; using MonoMod.Cil; using On.EntityStates; using R2API.AutoVersionGen; using R2API.Utils; using Rewired; using RoR2; using RoR2.CameraModes; using RoR2.ConVar; using RoR2.Skills; 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.4.0.0")] [assembly: AssemblyInformationalVersion("1.4.0+b18ad407f6a7dd91f8942af84dbefd9ed003cade")] [assembly: AssemblyProduct("R2API.CharacterBody")] [assembly: AssemblyTitle("R2API.CharacterBody")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.4.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.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] [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] [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 delegate bool CanAlwaysSprint(CharacterBody characterBody); public enum ModdedBodyFlag { } [CompilerGenerated] private static class <>O { public static Manipulator <0>__SprintIcon_FixedUpdate; public static hook_HandleMovements <1>__GenericCharacterMain_HandleMovements; public static Manipulator <2>__PlayerCharacterMasterController_PollButtonInput; public static Manipulator <3>__CameraModePlayerBasic_CollectLookInputInternal; public static Manipulator <4>__SkillDef_OnExecute; public static Manipulator <5>__SkillDef_OnFixedUpdate; public static Manipulator <6>__CameraModePlayerBasic_UpdateInternal; public static Manipulator <7>__CrosshairManager_UpdateCrosshair; public static Action <8>__SetSprintIconCustomSprintColor; public static Func <9>__CheckCustomSprintIcon; public static Action <10>__SetSprintIconCustomSprintIcon; public static Func <11>__GetCustomIconObject; public static Action <12>__NullcheckAndDeactivateCustomIconObject; } public const string PluginGUID = "com.bepis.r2api.character_body"; public const string PluginName = "R2API.CharacterBody"; private static List canAlwaysSprints = new List(); private static bool _hooksEnabled = false; public const string PluginVersion = "1.4.0"; public static ModdedBodyFlag AlwaysSprint { get; private set; } public static Color DefaultSprintColor => new Color(0.816f, 0.9655f, 1f, 1f); [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_0028: 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_0033: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Expected O, but got Unknown //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Expected O, but got Unknown //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Expected O, but got Unknown //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Expected O, but got Unknown //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Expected O, but got Unknown //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Expected O, but got Unknown if (!_hooksEnabled) { _hooksEnabled = true; AlwaysSprint = ReserveBodyFlag(); 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; object obj2 = <>O.<1>__GenericCharacterMain_HandleMovements; if (obj2 == null) { hook_HandleMovements val2 = GenericCharacterMain_HandleMovements; <>O.<1>__GenericCharacterMain_HandleMovements = val2; obj2 = (object)val2; } GenericCharacterMain.HandleMovements += (hook_HandleMovements)obj2; object obj3 = <>O.<2>__PlayerCharacterMasterController_PollButtonInput; if (obj3 == null) { Manipulator val3 = PlayerCharacterMasterController_PollButtonInput; <>O.<2>__PlayerCharacterMasterController_PollButtonInput = val3; obj3 = (object)val3; } PlayerCharacterMasterController.PollButtonInput += (Manipulator)obj3; object obj4 = <>O.<3>__CameraModePlayerBasic_CollectLookInputInternal; if (obj4 == null) { Manipulator val4 = CameraModePlayerBasic_CollectLookInputInternal; <>O.<3>__CameraModePlayerBasic_CollectLookInputInternal = val4; obj4 = (object)val4; } CameraModePlayerBasic.CollectLookInputInternal += (Manipulator)obj4; object obj5 = <>O.<4>__SkillDef_OnExecute; if (obj5 == null) { Manipulator val5 = SkillDef_OnExecute; <>O.<4>__SkillDef_OnExecute = val5; obj5 = (object)val5; } SkillDef.OnExecute += (Manipulator)obj5; object obj6 = <>O.<5>__SkillDef_OnFixedUpdate; if (obj6 == null) { Manipulator val6 = SkillDef_OnFixedUpdate; <>O.<5>__SkillDef_OnFixedUpdate = val6; obj6 = (object)val6; } SkillDef.OnFixedUpdate += (Manipulator)obj6; object obj7 = <>O.<6>__CameraModePlayerBasic_UpdateInternal; if (obj7 == null) { Manipulator val7 = CameraModePlayerBasic_UpdateInternal; <>O.<6>__CameraModePlayerBasic_UpdateInternal = val7; obj7 = (object)val7; } CameraModePlayerBasic.UpdateInternal += (Manipulator)obj7; object obj8 = <>O.<7>__CrosshairManager_UpdateCrosshair; if (obj8 == null) { Manipulator val8 = CrosshairManager_UpdateCrosshair; <>O.<7>__CrosshairManager_UpdateCrosshair = val8; obj8 = (object)val8; } CrosshairManager.UpdateCrosshair += (Manipulator)obj8; } } 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 //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Expected O, but got Unknown //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Expected O, but got Unknown //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Expected O, but got Unknown //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Expected O, but got Unknown //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0109: 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; object obj2 = <>O.<1>__GenericCharacterMain_HandleMovements; if (obj2 == null) { hook_HandleMovements val2 = GenericCharacterMain_HandleMovements; <>O.<1>__GenericCharacterMain_HandleMovements = val2; obj2 = (object)val2; } GenericCharacterMain.HandleMovements -= (hook_HandleMovements)obj2; object obj3 = <>O.<2>__PlayerCharacterMasterController_PollButtonInput; if (obj3 == null) { Manipulator val3 = PlayerCharacterMasterController_PollButtonInput; <>O.<2>__PlayerCharacterMasterController_PollButtonInput = val3; obj3 = (object)val3; } PlayerCharacterMasterController.PollButtonInput -= (Manipulator)obj3; object obj4 = <>O.<3>__CameraModePlayerBasic_CollectLookInputInternal; if (obj4 == null) { Manipulator val4 = CameraModePlayerBasic_CollectLookInputInternal; <>O.<3>__CameraModePlayerBasic_CollectLookInputInternal = val4; obj4 = (object)val4; } CameraModePlayerBasic.CollectLookInputInternal -= (Manipulator)obj4; object obj5 = <>O.<4>__SkillDef_OnExecute; if (obj5 == null) { Manipulator val5 = SkillDef_OnExecute; <>O.<4>__SkillDef_OnExecute = val5; obj5 = (object)val5; } SkillDef.OnExecute -= (Manipulator)obj5; object obj6 = <>O.<5>__SkillDef_OnFixedUpdate; if (obj6 == null) { Manipulator val6 = SkillDef_OnFixedUpdate; <>O.<5>__SkillDef_OnFixedUpdate = val6; obj6 = (object)val6; } SkillDef.OnFixedUpdate -= (Manipulator)obj6; object obj7 = <>O.<6>__CameraModePlayerBasic_UpdateInternal; if (obj7 == null) { Manipulator val7 = CameraModePlayerBasic_UpdateInternal; <>O.<6>__CameraModePlayerBasic_UpdateInternal = val7; obj7 = (object)val7; } CameraModePlayerBasic.UpdateInternal -= (Manipulator)obj7; object obj8 = <>O.<7>__CrosshairManager_UpdateCrosshair; if (obj8 == null) { Manipulator val8 = CrosshairManager_UpdateCrosshair; <>O.<7>__CrosshairManager_UpdateCrosshair = val8; obj8 = (object)val8; } CrosshairManager.UpdateCrosshair -= (Manipulator)obj8; } } private static void GenericCharacterMain_HandleMovements(orig_HandleMovements orig, GenericCharacterMain self) { if (self != null && Object.op_Implicit((Object)(object)((EntityState)self).characterBody) && ((EntityState)self).characterBody.GetAlwaysSprint()) { self.sprintInputReceived = true; } orig.Invoke(self); } 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_008a: 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_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_027f: 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>((Action)SetSprintIconCustomSprintColor); val.Emit(OpCodes.Ldarg_0); val.EmitDelegate>((Func)CheckCustomSprintIcon); val.Emit(OpCodes.Brfalse_S, val3); val.Emit(OpCodes.Ldarg_0); val.EmitDelegate>((Action)SetSprintIconCustomSprintIcon); val.Emit(OpCodes.Br, val2); if (val.TryGotoNext((MoveType)2, new Func[4] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, "sprintIconObject"), (Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 0), (Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, "SetActive") })) { _ = val.Next; val.Emit(OpCodes.Ldarg_0); val.EmitDelegate>((Func)GetCustomIconObject); val.EmitDelegate>((Action)NullcheckAndDeactivateCustomIconObject); } else { CharacterBodyPlugin.Logger.LogError((object)(((MemberReference)il.Method).Name + " IL Hook 1 failed!")); } if (val.TryGotoNext((MoveType)2, new Func[4] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, "sprintIconObject"), (Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 1), (Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, "SetActive") })) { _ = val.Next; val.Emit(OpCodes.Ldarg_0); val.EmitDelegate>((Func)GetCustomIconObject); val.EmitDelegate>((Action)NullcheckAndDeactivateCustomIconObject); } else { CharacterBodyPlugin.Logger.LogError((object)(((MemberReference)il.Method).Name + " IL Hook 2 failed!")); } } private static void PlayerCharacterMasterController_PollButtonInput(ILContext il) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) ILCursor val = new ILCursor(il); if (val.TryGotoNext((MoveType)0, new Func[2] { (Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 16), (Instruction x) => ILPatternMatchingExt.MatchStloc(x, 6) })) { int index = val.Index; val.Index = index + 1; Instruction next = val.Next; _ = val.Next.Next; val.Emit(OpCodes.Ldarg_0); val.EmitDelegate>((Func)GetFlag); val.Emit(OpCodes.Brfalse_S, next); val.Emit(OpCodes.Pop); val.Emit(OpCodes.Ldloc, 13); val.Emit(OpCodes.Ldc_I4, 18); val.Emit(OpCodes.Callvirt, (MethodBase)AccessTools.Method(typeof(Player), "GetButton", new Type[1] { typeof(int) }, (Type[])null)); } else { CharacterBodyPlugin.Logger.LogError((object)(((MemberReference)il.Method).Name + " IL Hook 1 failed!")); } static bool GetFlag(PlayerCharacterMasterController playerCharacterMasterController) { return playerCharacterMasterController.body.GetAlwaysSprint(); } } private static void CameraModePlayerBasic_CollectLookInputInternal(ILContext il) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) ILCursor val = new ILCursor(il); ILLabel iLLabel = null; if (val.TryGotoNext(new Func[3] { (Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, "enableSprintSensitivitySlowdown"), (Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, "get_value"), (Instruction x) => ILPatternMatchingExt.MatchBrfalse(x, ref iLLabel) })) { val.Emit(OpCodes.Ldarg_2); val.Emit(OpCodes.Ldflda, "targetInfo"); val.Emit(OpCodes.Ldfld, "body"); val.EmitDelegate>((Func)((CharacterBody cb) => Object.op_Implicit((Object)(object)cb) && cb.GetAlwaysSprint())); val.Emit(OpCodes.Brtrue_S, (object)iLLabel); } else { CharacterBodyPlugin.Logger.LogError((object)(((MemberReference)il.Method).Name + " IL Hook 1 failed!")); } } private static void SkillDef_OnExecute(ILContext il) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) ILCursor val = new ILCursor(il); ILLabel iLLabel = null; if (val.TryGotoNext(new Func[3] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, "cancelSprintingOnActivation"), (Instruction x) => ILPatternMatchingExt.MatchBrfalse(x, ref iLLabel) })) { val.Emit(OpCodes.Ldarg_1); val.EmitDelegate>((Func)((GenericSkill cb) => cb.characterBody.GetAlwaysSprint())); val.Emit(OpCodes.Brtrue_S, (object)iLLabel); } else { CharacterBodyPlugin.Logger.LogError((object)(((MemberReference)il.Method).Name + " IL Hook failed!")); } } private static void SkillDef_OnFixedUpdate(ILContext il) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) ILCursor val = new ILCursor(il); ILLabel iLLabel = null; if (val.TryGotoNext(new Func[4] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 1), (Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, "get_characterBody"), (Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, "get_isSprinting"), (Instruction x) => ILPatternMatchingExt.MatchBrfalse(x, ref iLLabel) })) { val.Emit(OpCodes.Ldarg_1); val.EmitDelegate>((Func)((GenericSkill cb) => Object.op_Implicit((Object)(object)cb) && Object.op_Implicit((Object)(object)cb.characterBody) && cb.characterBody.GetAlwaysSprint())); val.Emit(OpCodes.Brtrue_S, (object)iLLabel); } else { CharacterBodyPlugin.Logger.LogError((object)(((MemberReference)il.Method).Name + " IL Hook failed!")); } } private static void CameraModePlayerBasic_UpdateInternal(ILContext il) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) ILCursor val = new ILCursor(il); ILLabel iLLabel = null; if (val.TryGotoNext(new Func[4] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 2), (Instruction x) => ILPatternMatchingExt.MatchLdflda(x, "targetInfo"), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, "isSprinting"), (Instruction x) => ILPatternMatchingExt.MatchBrfalse(x, ref iLLabel) })) { val.Emit(OpCodes.Ldarg_2); val.EmitDelegate<<>F{00000001}>((<>F{00000001})method); val.Emit(OpCodes.Brtrue_S, (object)iLLabel); } else { CharacterBodyPlugin.Logger.LogError((object)(((MemberReference)il.Method).Name + " IL Hook failed!")); } static bool method(ref CameraModeContext cameraModeContext) { if ((Object)(object)cameraModeContext.targetInfo.body != (Object)null) { return cameraModeContext.targetInfo.body.GetAlwaysSprint(); } return true; } } private static void CrosshairManager_UpdateCrosshair(ILContext il) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) ILCursor val = new ILCursor(il); ILLabel iLLabel = null; ILLabel iLLabel2 = null; if (val.TryGotoNext(new Func[4] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, "cameraRigController"), (Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, "get_hasOverride"), (Instruction x) => ILPatternMatchingExt.MatchBrtrue(x, ref iLLabel) }) && val.TryGotoNext(new Func[3] { (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 1), (Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, "get_isSprinting"), (Instruction x) => ILPatternMatchingExt.MatchBrfalse(x, ref iLLabel2) })) { val.Emit(OpCodes.Ldarg_1); val.EmitDelegate>((Func)((CharacterBody cb) => cb.GetAlwaysSprint())); val.Emit(OpCodes.Brtrue_S, (object)iLLabel); } else { CharacterBodyPlugin.Logger.LogError((object)(((MemberReference)il.Method).Name + " IL Hook failed!")); } } 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 SetSprintIconCustomSprintColor(SprintIcon sprintIcon) { //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: 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) if (Object.op_Implicit((Object)(object)sprintIcon) && Object.op_Implicit((Object)(object)sprintIcon.body)) { Color? customSprintColor = sprintIcon.body.GetCustomSprintColor(); Color? currentCustomSprintColor = sprintIcon.GetCurrentCustomSprintColor(); Color? val = customSprintColor; if (currentCustomSprintColor.HasValue != val.HasValue || (currentCustomSprintColor.HasValue && currentCustomSprintColor.GetValueOrDefault() != val.GetValueOrDefault())) { SetGameObjectCustomSprintColor(sprintIcon.GetCustomIconObject(), customSprintColor.HasValue ? customSprintColor.Value : DefaultSprintColor); SetGameObjectCustomSprintColor(sprintIcon.descendIconObject, customSprintColor.HasValue ? customSprintColor.Value : DefaultSprintColor); SetGameObjectCustomSprintColor(sprintIcon.sprintIconObject, customSprintColor.HasValue ? customSprintColor.Value : DefaultSprintColor); sprintIcon.SetCurrentCustomSprintColor(customSprintColor); } } } private static void SetGameObjectCustomSprintColor(GameObject gameObject, Color color) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)gameObject)) { ((Graphic)gameObject.GetComponent()).color = color; } } 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().sprite = customSprintIcon; sprintIcon.SetCurrentCustomSprintIcon(customSprintIcon); } } else { Transform val2 = ((Component)sprintIcon).transform.Find("SprintIcon"); if (Object.op_Implicit((Object)(object)val2)) { val = Object.Instantiate(((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(); 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); } public static Color? GetCustomSprintColor(this CharacterBody characterBody) { return CharacterBodyInterop.GetCustomSprintColor(characterBody); } public static void SetCustomSprintColor(this CharacterBody characterBody, Color? color) { CharacterBodyInterop.SetCustomSprintColor(characterBody, color); } public static bool GetAlwaysSprint(this CharacterBody characterBody) { SetHooks(); if (characterBody.HasModdedBodyFlag(AlwaysSprint)) { return true; } foreach (CanAlwaysSprint canAlwaysSprint in canAlwaysSprints) { if (canAlwaysSprint != null && canAlwaysSprint(characterBody)) { return true; } } return false; } public static void AddAlwaysSprintCondition(CanAlwaysSprint canAlwaysSprint) { canAlwaysSprints.Add(canAlwaysSprint); } 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); } private static Color? GetCurrentCustomSprintColor(this SprintIcon sprintIcon) { return CharacterBodyInterop.GetCurrentCustomSprintColor(sprintIcon); } private static void SetCurrentCustomSprintColor(this SprintIcon sprintIcon, Color? color) { CharacterBodyInterop.SetCurrentCustomSprintColor(sprintIcon, color); } } [BepInPlugin("com.bepis.r2api.character_body", "R2API.CharacterBody", "1.4.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} <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[2] { (Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, "FindChild"), (Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref childTransformLocal) })) { int childIndexLocal = 0; if (val.TryGotoNext((MoveType)2, new Func[2] { (Instruction x) => ILPatternMatchingExt.MatchCallvirt(x, "FindChildIndex"), (Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref childIndexLocal) })) { int raycastHitLocal = 0; if (val.TryGotoNext((MoveType)2, new Func[2] { (Instruction x) => ILPatternMatchingExt.MatchLdloca(x, ref raycastHitLocal), (Instruction x) => ILPatternMatchingExt.MatchInitobj(x) })) { int surfaceDefLocal = 0; if (val.TryGotoNext((MoveType)2, new Func[2] { (Instruction x) => ILPatternMatchingExt.MatchCall(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}>((<>A{00000200})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 = new FootstepReport { childIndex = index, childName = name, childTransform = transform, raycastHit = raycastHit, footstepHandler = footstepHandler, surfaceDef = surfaceDef, footstepEffect = footstepEffect }; FootstepAPI.OnFootstep?.Invoke(footstepReport); } 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 OverlayInfos = new List(); private static FixedConditionalWeakTable HealthBarData = new FixedConditionalWeakTable(); 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 val = new ILCursor(il); VariableDefinition val2 = new VariableDefinition(il.Import(typeof(float))); il.Method.Body.Variables.Add(val2); VariableDefinition val3 = new VariableDefinition(il.Import(typeof(AssignedOverlaysData))); il.Method.Body.Variables.Add(val3); val.Emit(OpCodes.Ldarg_0); val.EmitDelegate>((Func)((HealthBar source) => Object.op_Implicit((Object)(object)source.source) ? HealthBarData.GetOrCreateValue(source.source) : null)); val.Emit(OpCodes.Stloc, val3); int fullHealthIndex = -1; val.TryGotoNext((MoveType)2, new Func[2] { (Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, "get_fullHealth"), (Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref fullHealthIndex) }); if (fullHealthIndex < 0) { valuesHookFailed = true; return; } val.Emit(OpCodes.Ldarg_0); val.Emit(OpCodes.Call, (MethodBase)get_source); val.Emit(OpCodes.Call, (MethodBase)get_combinedHealth); val.Emit(OpCodes.Stloc, val2); foreach (BarOverlayInfo overlay in OverlayInfos) { val.Emit(OpCodes.Ldarg_0); val.Emit(OpCodes.Ldloc, val3); val.Emit(OpCodes.Ldloca, val2); val.Emit(OpCodes.Ldloca, fullHealthIndex); val.EmitDelegate((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 = val.Next.Offset; Assert(val.TryGotoNext((MoveType)2, new Func[1] { (Instruction x) => ILPatternMatchingExt.MatchLdloc(x, fullHealthIndex) && x.Offset > index })); int num2 = default(int); Assert(val.TryGotoPrev((MoveType)0, new Func[1] { (Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref num2) && x.Offset > index })); if (valuesHookFailed) { return; } val.Emit(OpCodes.Pop); val.Emit(OpCodes.Ldloc, val2); Assert(val.TryGotoNext((MoveType)0, new Func[3] { (Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, (MethodBase)get_combinedHealth), (Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0), (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, "oldHealth") })); if (valuesHookFailed) { return; } int index2 = val.Index; val.Index = index2 + 1; val.Emit(OpCodes.Pop); val.Emit(OpCodes.Ldloc, val2); for (int num = 0; num < 2; num++) { Assert(val.TryGotoNext((MoveType)2, new Func[1] { (Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, (MethodBase)get_combinedHealth) })); if (valuesHookFailed) { break; } val.Emit(OpCodes.Pop); val.Emit(OpCodes.Ldloc, val2); } static void Assert(bool flag) { if (!flag) { 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[1] { (Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, ref handleBar) && handleBar != null && ((MemberReference)handleBar).Name.StartsWith("g__HandleBar|") }); bool flag2 = val.TryGotoPrev(new Func[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 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)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 barInfo = new BarInfo { enabled = overlay.BarInfo.enabled, color = overlay.BarInfo.color, sprite = overlay.BarInfo.sprite, imageType = overlay.BarInfo.imageType, sizeDelta = overlay.BarInfo.sizeDelta, normalizedXMax = overlay.BarInfo.normalizedXMax, normalizedXMin = overlay.BarInfo.normalizedXMin }; if (data == null || (overlay.BodySpecific && !data.AssignedOverlays[(int)overlay.OverlayIndex])) { barInfo.enabled = false; return barInfo; } overlay.ModifyBarInfo?.Invoke(source, ref barInfo); return barInfo; }); val.Emit(OpCodes.Stloc, val5); if (!val.TryGotoNext((MoveType)2, new Func[1] { (Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, "GetActiveCount") })) { overlaysHookFailed = true; CharacterBodyPlugin.Logger.LogError((object)"Failed to find GetActiveCount in ApplyBars."); break; } val.Emit(OpCodes.Ldloca, val5); val.EmitDelegate<<>F{00000018}>((<>F{00000018})delegate(int count, in BarInfo barInfo) { if (barInfo.enabled) { count++; } return count; }); val.TryGotoNext((MoveType)0, new Func[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 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 { } }