Decompiled source of SeasonColdDamage v1.0.0

SeasonalColdDamagePlugin.dll

Decompiled 2 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
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: AssemblyTitle("SeasonalColdDamagePlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SeasonalColdDamagePlugin")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8eedef94-31ed-45a5-8579-4443a4eccd39")]
[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")]
public static class SeasonHelper
{
	private static Type _seasonsType;

	private static FieldInfo _seasonStateField;

	private static MethodInfo _getCurrentSeasonMethod;

	static SeasonHelper()
	{
		try
		{
			_seasonsType = Type.GetType("Seasons.Seasons, Seasons");
			if (_seasonsType == null)
			{
				return;
			}
			_seasonStateField = _seasonsType.GetField("seasonState", BindingFlags.Static | BindingFlags.Public);
			if (!(_seasonStateField == null))
			{
				object value = _seasonStateField.GetValue(null);
				if (value != null)
				{
					_getCurrentSeasonMethod = value.GetType().GetMethod("GetCurrentSeason");
				}
			}
		}
		catch
		{
		}
	}

	private static string GetSeasonInternal()
	{
		try
		{
			if (_seasonStateField == null || _getCurrentSeasonMethod == null)
			{
				return null;
			}
			object value = _seasonStateField.GetValue(null);
			if (value == null)
			{
				return null;
			}
			return _getCurrentSeasonMethod.Invoke(value, null)?.ToString();
		}
		catch
		{
			return null;
		}
	}

	public static bool IsWinter()
	{
		return GetSeasonInternal() == "Winter";
	}

	public static bool IsFall()
	{
		return GetSeasonInternal() == "Fall";
	}
}
namespace SeasonColdDamage;

[HarmonyPatch(typeof(Player), "Update")]
public static class PlayerPatch
{
	private static float _timer;

	private const float TickInterval = 1f;

	private static void Postfix(Player __instance)
	{
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Expected O, but got Unknown
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//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)
		if ((Object)(object)__instance == (Object)null || !((Character)__instance).IsOwner())
		{
			return;
		}
		SEMan sEMan = ((Character)__instance).GetSEMan();
		if (sEMan == null || !sEMan.HaveStatusEffect("Cold".GetHashCode()) || (!SeasonHelper.IsFall() && !SeasonHelper.IsWinter()))
		{
			return;
		}
		_timer += Time.deltaTime;
		if (!(_timer < 1f))
		{
			_timer = 0f;
			float num = 0f;
			if (SeasonHelper.IsFall())
			{
				num = SeasonColdDamagePlugin.FallDamagePerTick.Value;
			}
			if (SeasonHelper.IsWinter())
			{
				num = SeasonColdDamagePlugin.WinterDamagePerTick.Value;
			}
			if (!(num <= 0f))
			{
				HitData val = new HitData();
				val.m_damage.m_damage = num;
				val.m_point = ((Component)__instance).transform.position;
				val.m_dir = Vector3.zero;
				((Character)__instance).Damage(val);
			}
		}
	}
}
[BepInPlugin("com.yourname.seasoncolddamage", "Season Cold Damage", "1.0.0")]
public class SeasonColdDamagePlugin : BaseUnityPlugin
{
	public const string ModGUID = "com.yourname.seasoncolddamage";

	public const string ModName = "Season Cold Damage";

	public const string ModVersion = "1.0.0";

	internal static ConfigEntry<float> FallDamagePerTick;

	internal static ConfigEntry<float> WinterDamagePerTick;

	internal static SeasonColdDamagePlugin Instance;

	private Harmony _harmony;

	private void Awake()
	{
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Expected O, but got Unknown
		Instance = this;
		FallDamagePerTick = ((BaseUnityPlugin)this).Config.Bind<float>("General", "FallDamagePerTick", 1f, "Damage per tick during Fall when player is Cold");
		WinterDamagePerTick = ((BaseUnityPlugin)this).Config.Bind<float>("General", "WinterDamagePerTick", 1f, "Damage per tick during Winter when player is Cold");
		_harmony = new Harmony("com.yourname.seasoncolddamage");
		_harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Season Cold Damage loaded.");
	}
}