using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("MonsterFallDamagePlugin")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("MonsterFallDamagePlugin")] [assembly: AssemblyTitle("MonsterFallDamagePlugin")] [assembly: AssemblyVersion("1.0.0.0")] namespace MonsterFallDamagePlugin; [BepInPlugin("com.mods.monsterfallDamage", "MonsterFallDamage", "1.0.1")] [BepInProcess("valheim.exe")] public class Plugin : BaseUnityPlugin { public const string GUID = "com.mods.monsterfallDamage"; public const string NAME = "MonsterFallDamage"; public const string VERSION = "1.0.1"; private readonly Harmony _harmony = new Harmony("com.mods.monsterfallDamage"); internal static ConfigEntry MinFallHeight; internal static ConfigEntry DamageDistance; internal static ConfigEntry DamagePerUnit; internal static ConfigEntry MaxDamage; private void Awake() { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Expected O, but got Unknown //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Expected O, but got Unknown //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Expected O, but got Unknown MinFallHeight = ((BaseUnityPlugin)this).Config.Bind("Fall Damage", "Min Fall Height (m)", 4f, new ConfigDescription("Falls below this height deal no damage. (Player default: 4)", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 20f), Array.Empty())); DamageDistance = ((BaseUnityPlugin)this).Config.Bind("Fall Damage", "Damage Interval (m)", 16f, new ConfigDescription("Damage is added for every X meters fallen above the minimum height. (Player default: 16)", (AcceptableValueBase)(object)new AcceptableValueRange(0.5f, 100f), Array.Empty())); DamagePerUnit = ((BaseUnityPlugin)this).Config.Bind("Fall Damage", "Damage Per Interval", 100f, new ConfigDescription("Damage dealt per interval distance. (Player default: 100)", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 100f), Array.Empty())); MaxDamage = ((BaseUnityPlugin)this).Config.Bind("Fall Damage", "Max Damage (0 = unlimited)", 100f, new ConfigDescription("Maximum fall damage cap. Set to 0 for no limit. (Player default: 100)", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 99999f), Array.Empty())); _harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"MonsterFallDamage 1.0.1 loaded."); } private void OnDestroy() { _harmony.UnpatchSelf(); } } [HarmonyPatch(typeof(Character), "UpdateGroundContact")] public static class Patch_MonsterFallDamage { private static readonly FieldInfo f_groundContact = AccessTools.Field(typeof(Character), "m_groundContact"); private static readonly FieldInfo f_maxAirAltitude = AccessTools.Field(typeof(Character), "m_maxAirAltitude"); private static readonly FieldInfo f_groundContactPoint = AccessTools.Field(typeof(Character), "m_groundContactPoint"); private static readonly FieldInfo f_groundContactNormal = AccessTools.Field(typeof(Character), "m_groundContactNormal"); public static void Prefix(Character __instance) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: 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_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Expected O, but got Unknown //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) if (__instance.IsPlayer() || __instance.IsDead() || !(bool)f_groundContact.GetValue(__instance)) { return; } float num = (float)f_maxAirAltitude.GetValue(__instance); float num2 = Mathf.Max(0f, num - ((Component)__instance).transform.position.y); float value = Plugin.MinFallHeight.Value; if (!(num2 <= value)) { float num3 = (num2 - value) / Plugin.DamageDistance.Value * Plugin.DamagePerUnit.Value; float value2 = Plugin.MaxDamage.Value; if (value2 > 0f) { num3 = Mathf.Min(num3, value2); } if (!(num3 <= 0f)) { Vector3 point = (Vector3)f_groundContactPoint.GetValue(__instance); Vector3 dir = (Vector3)f_groundContactNormal.GetValue(__instance); HitData val = new HitData(); val.m_damage.m_damage = num3; val.m_point = point; val.m_dir = dir; val.m_hitType = (HitType)3; __instance.Damage(val); } } } }