using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using DynamicFallDamage.Patches;
using GameNetcodeStuff;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("DynamicFallDamage")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DynamicFallDamage")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d4b16e4c-84a3-435b-96b5-68a570cd58da")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace DynamicFallDamage
{
public class Logger
{
public enum LogLevelConfig
{
None,
Important,
Everything
}
internal ManualLogSource MLS;
public string modName = "No-Name";
public string modVersion = "No-Ver";
public void Init(string modGUID = "")
{
MLS = Logger.CreateLogSource(modGUID);
}
public bool LogLevelAllow(LogLevelConfig severity = LogLevelConfig.Important, LogLevelConfig severity2 = LogLevelConfig.Everything)
{
if (severity2 == LogLevelConfig.None)
{
return false;
}
if (severity == LogLevelConfig.Everything)
{
return severity2 == LogLevelConfig.Everything;
}
return true;
}
public void Log(string text = "", LogLevel level = 16, LogLevelConfig severity = LogLevelConfig.Important)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
if (true)
{
string text2 = $"[{modName} v{modVersion}] - {text}";
MLS.Log(level, (object)text2);
}
}
}
[BepInPlugin("thej01.lc.DynamicFallDamage", "DynamicFallDamage", "1.0.1")]
public class DynamicFallDamageMod : BaseUnityPlugin
{
private const string modGUID = "thej01.lc.DynamicFallDamage";
private const string modName = "DynamicFallDamage";
private const string modVersion = "1.0.1";
private readonly Harmony harmony = new Harmony("thej01.lc.DynamicFallDamage");
private static DynamicFallDamageMod Instance;
public static Logger fallLogger = new Logger();
public static int fallDamageMin = 30;
public static int fallDamageMax = 200;
public static float fallValueRangeMin = 38f;
public static float fallValueRangeMax = 63.5f;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
fallLogger.Init("thej01.lc.DynamicFallDamage");
fallLogger.modName = "DynamicFallDamage";
fallLogger.modVersion = "1.0.1";
fallLogger.Log("fallLogger Initialised!", (LogLevel)16, Logger.LogLevelConfig.Everything);
fallLogger.Log("Patching DynamicFallDamageMod...", (LogLevel)16, Logger.LogLevelConfig.Everything);
harmony.PatchAll(typeof(DynamicFallDamageMod));
fallLogger.Log("Patched DynamicFallDamageMod.", (LogLevel)16, Logger.LogLevelConfig.Everything);
fallLogger.Log("Patching PlayerControllerBPatch...", (LogLevel)16, Logger.LogLevelConfig.Everything);
harmony.PatchAll(typeof(PlayerControllerBPatch));
fallLogger.Log("Patched PlayerControllerBPatch.", (LogLevel)16, Logger.LogLevelConfig.Everything);
}
}
}
namespace DynamicFallDamage.Patches
{
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
[HarmonyPatch(typeof(PlayerControllerB), "PlayerHitGroundEffects")]
[HarmonyPrefix]
public static void PreHitGround(ref PlayerControllerB __instance)
{
//IL_00d3: 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)
if (__instance.takingFallDamage)
{
float num = DynamicFallDamageMod.fallValueRangeMax - DynamicFallDamageMod.fallValueRangeMin;
float num2 = DynamicFallDamageMod.fallDamageMax - DynamicFallDamageMod.fallDamageMin;
float num3 = Math.Abs(__instance.fallValueUncapped);
if (num3 > DynamicFallDamageMod.fallValueRangeMax)
{
num3 = DynamicFallDamageMod.fallValueRangeMax;
}
if (num3 < DynamicFallDamageMod.fallValueRangeMin)
{
return;
}
int num4 = (int)((num3 - DynamicFallDamageMod.fallValueRangeMin) * num2 / num) + DynamicFallDamageMod.fallDamageMin;
if (num4 < 0)
{
num4 = 0;
DynamicFallDamageMod.fallLogger.Log("Fall damage was less than zero! This should never happen!", (LogLevel)4);
}
string text = $"Fall Damage (the better one): {num4} Fall Value: {__instance.fallValueUncapped}, Capped Fall Value: {num3}";
DynamicFallDamageMod.fallLogger.Log(text, (LogLevel)16, Logger.LogLevelConfig.Everything);
__instance.DamagePlayer(num4, true, true, (CauseOfDeath)2, 0, false, default(Vector3));
}
__instance.takingFallDamage = false;
}
}
}