using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using IL.RoR2;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2;
using RoR2;
using UnityEngine;
using UnityEngine.Networking;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SneedHooks")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f1ac97bc373d02c17feeb1cc08dbdcfd756b43a8")]
[assembly: AssemblyProduct("SneedHooks")]
[assembly: AssemblyTitle("SneedHooks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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;
}
}
}
namespace R2API.Utils
{
[AttributeUsage(AttributeTargets.Assembly)]
public class ManualNetworkRegistrationAttribute : Attribute
{
}
}
namespace SneedHooks
{
public static class ModifyFinalDamage
{
public class DamageModifierArgs
{
public float damageMultAdd = 0f;
public float damageMultFinal = 1f;
public float damageReductionFactorAdd = 0f;
public float flatDamageAdd = 0f;
}
public delegate void ModifyFinalDamageDelegate(DamageModifierArgs damageModifierArgs, DamageInfo damageInfo, HealthComponent victim, CharacterBody victimBody);
public delegate void ModifyFinalDamageAttackerDelegate(DamageModifierArgs damageModifierArgs, DamageInfo damageInfo, HealthComponent victim, CharacterBody victimBody, CharacterBody attackerBody);
public static ModifyFinalDamageDelegate ModifyFinalDamageActions;
public static ModifyFinalDamageAttackerDelegate ModifyFinalDamageAttackerActions;
internal static void HealthComponent_TakeDamageProcess(ILContext il)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Expected O, but got Unknown
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
bool flag = false;
ILCursor val = new ILCursor(il);
int targetIndex = 0;
int ignoreIndex = 0;
if (val.TryGotoNext(new Func<Instruction, bool>[3]
{
(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref targetIndex),
(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref ignoreIndex),
(Instruction x) => ILPatternMatchingExt.MatchLdfld<TeamDef>(x, "friendlyFireScaling")
}))
{
val = new ILCursor(il);
if (val.TryGotoNext(new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchStloc(x, targetIndex)
}))
{
val.Emit(OpCodes.Ldarg_0);
val.Emit(OpCodes.Ldarg_1);
val.EmitDelegate<Func<float, HealthComponent, DamageInfo, float>>((Func<float, HealthComponent, DamageInfo, float>)delegate(float origDamage, HealthComponent victimHealth, DamageInfo damageInfo)
{
float num = origDamage;
CharacterBody body = victimHealth.body;
if (Object.op_Implicit((Object)(object)body))
{
DamageModifierArgs damageModifierArgs = new DamageModifierArgs();
ModifyFinalDamageActions?.Invoke(damageModifierArgs, damageInfo, victimHealth, body);
if (Object.op_Implicit((Object)(object)damageInfo.attacker))
{
CharacterBody component = damageInfo.attacker.GetComponent<CharacterBody>();
if (Object.op_Implicit((Object)(object)component))
{
ModifyFinalDamageAttackerActions?.Invoke(damageModifierArgs, damageInfo, victimHealth, body, component);
}
}
num *= (1f + damageModifierArgs.damageMultAdd) * damageModifierArgs.damageMultFinal / (1f + damageModifierArgs.damageReductionFactorAdd);
num += damageModifierArgs.flatDamageAdd;
}
return num;
});
flag = true;
}
}
if (!flag)
{
Debug.LogError((object)"SneedHooks: ModifyFinalDamage IL Hook failed. This will break a lot of things.");
}
}
}
public static class ProcessHitEnemy
{
public delegate void OnHit(DamageInfo damageInfo, CharacterBody victimBody);
public delegate void OnHitAttacker(DamageInfo damageInfo, CharacterBody victimBody, CharacterBody attackerBody);
public static OnHit OnHitActions;
public static OnHit PreOnHitActions;
public static OnHitAttacker OnHitAttackerActions;
public static OnHitAttacker PreOnHitAttackerActions;
internal static void GlobalEventManager_ProcessHitEnemy(orig_ProcessHitEnemy orig, GlobalEventManager self, DamageInfo damageInfo, GameObject victim)
{
CharacterBody val = null;
CharacterBody val2 = null;
Inventory val3 = null;
bool flag = NetworkServer.active && Object.op_Implicit((Object)(object)victim) && damageInfo.procCoefficient > 0f && !damageInfo.rejected;
if (flag)
{
val2 = victim.GetComponent<CharacterBody>();
if (Object.op_Implicit((Object)(object)val2))
{
PreOnHitActions?.Invoke(damageInfo, val2);
if (Object.op_Implicit((Object)(object)damageInfo.attacker))
{
val = damageInfo.attacker.GetComponent<CharacterBody>();
if (Object.op_Implicit((Object)(object)val))
{
PreOnHitAttackerActions?.Invoke(damageInfo, val2, val);
}
}
}
else
{
flag = false;
}
}
orig.Invoke(self, damageInfo, victim);
if (flag && Object.op_Implicit((Object)(object)val2))
{
OnHitActions?.Invoke(damageInfo, val2);
if (Object.op_Implicit((Object)(object)val))
{
OnHitAttackerActions?.Invoke(damageInfo, val2, val);
}
}
}
}
[BepInPlugin("com.RiskyLives.SneedHooks", "SneedHooks", "1.0.0")]
public class SneedHooksPlugin : BaseUnityPlugin
{
private void Awake()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
GlobalEventManager.ProcessHitEnemy += new hook_ProcessHitEnemy(ProcessHitEnemy.GlobalEventManager_ProcessHitEnemy);
HealthComponent.TakeDamageProcess += new Manipulator(ModifyFinalDamage.HealthComponent_TakeDamageProcess);
}
}
}