using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("GracefulLanding")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Crystal")]
[assembly: AssemblyProduct("GracefulLanding")]
[assembly: AssemblyCopyright("Copyright © 2023 Crystal Ferrai")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("59e3a8b0-42d8-4f95-b9e2-e61bbe7f58f4")]
[assembly: AssemblyFileVersion("1.0.6.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.6.0")]
namespace GracefulLanding;
[BepInPlugin("dev.crystal.gracefullanding", "Graceful Landing", "1.0.6.0")]
[BepInProcess("valheim.exe")]
[BepInProcess("valheim_server.exe")]
public class GracefulLandingPlugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(Character))]
private static class Character_Patches
{
[HarmonyPatch("UpdateGroundContact")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> UpdateGroundContact_Transpiler(IEnumerable<CodeInstruction> instructions)
{
foreach (CodeInstruction instruction in instructions)
{
if (instruction.opcode == OpCodes.Ldc_R4)
{
float num = (float)instruction.operand;
if (num != 4f)
{
if (num != 16f)
{
if (num == 100f)
{
instruction.operand = MaxDamageAmount.Value;
}
}
else
{
instruction.operand = MaxDamageHeight.Value;
}
}
else
{
instruction.operand = MinDamageHeight.Value;
}
}
yield return instruction;
}
}
}
public const string ModId = "dev.crystal.gracefullanding";
public static ConfigEntry<float> MinDamageHeight;
public static ConfigEntry<float> MaxDamageHeight;
public static ConfigEntry<float> MaxDamageAmount;
private static Harmony sCharacterHarmony;
private void Awake()
{
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Expected O, but got Unknown
MinDamageHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Falling", "MinDamageHeight", 8f, "The minimum distance you must fall to receive any fall damage. Allowed range 1-10000. Game default 4.");
MinDamageHeight.SettingChanged += Falling_SettingChanged;
MaxDamageHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Falling", "MaxDamageHeight", 64f, "The minimum distance you must to receive maximum fall damage. Allowed range 1-10000. Must be equal to or higher than MinDamageHeight. Game default 16.");
MaxDamageHeight.SettingChanged += Falling_SettingChanged;
MaxDamageAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Falling", "MaxDamageAmount", 100f, "The maximum fall damage that can be received. Allowed range 0-10000. Game default 100.");
MaxDamageAmount.SettingChanged += Falling_SettingChanged;
ClampConfig();
sCharacterHarmony = new Harmony("dev.crystal.gracefullanding_Character");
sCharacterHarmony.PatchAll(typeof(Character_Patches));
}
private void OnDestroy()
{
sCharacterHarmony.UnpatchSelf();
}
private static void ClampConfig()
{
if (MinDamageHeight.Value < 1f)
{
MinDamageHeight.Value = 1f;
}
if (MinDamageHeight.Value > 10000f)
{
MinDamageHeight.Value = 10000f;
}
if (MaxDamageHeight.Value < MinDamageHeight.Value)
{
MaxDamageHeight.Value = MinDamageHeight.Value;
}
if (MaxDamageHeight.Value > 10000f)
{
MaxDamageHeight.Value = 10000f;
}
if (MaxDamageAmount.Value < 0f)
{
MaxDamageAmount.Value = 0f;
}
if (MaxDamageAmount.Value > 10000f)
{
MaxDamageAmount.Value = 10000f;
}
}
private void Falling_SettingChanged(object sender, EventArgs e)
{
ClampConfig();
sCharacterHarmony.UnpatchSelf();
sCharacterHarmony.PatchAll(typeof(Character_Patches));
}
}