Decompiled source of ColdFix v1.0.1

plugins/Cold problem.dll

Decompiled 3 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.Logging;
using HarmonyLib;
using Photon.Pun;
using UnityEngine;
using Zorro.Core;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Cold problem")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Cold problem")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b4d6361f-fc9a-4361-bcd6-de78b9771f67")]
[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 NightColdDirectFix;

[BepInPlugin("com.sol.nightcolddirectfix", "Night Cold Direct Fix", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	private Harmony _harmony;

	private void Awake()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		_harmony = new Harmony("com.sol.nightcolddirectfix");
		_harmony.PatchAll();
		Log.LogInfo((object)"Night Cold Direct Fix loaded.");
	}

	private void OnDestroy()
	{
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}
}
internal struct UpdateNormalStatusesState
{
	internal bool Valid;

	internal float ColdBefore;
}
[HarmonyPatch(typeof(CharacterAfflictions), "UpdateNormalStatuses")]
internal static class Patch_CharacterAfflictions_UpdateNormalStatuses
{
	private const float LogInterval = 1f;

	private static float _nextLogTime;

	[HarmonyPrefix]
	private static void Prefix(CharacterAfflictions __instance, ref UpdateNormalStatusesState __state)
	{
		__state = default(UpdateNormalStatusesState);
		try
		{
			if ((Object)(object)__instance == (Object)null)
			{
				return;
			}
			PhotonView component = ((Component)__instance).GetComponent<PhotonView>();
			if (!((Object)(object)component == (Object)null) && component.IsMine)
			{
				Character component2 = ((Component)__instance).GetComponent<Character>();
				if (!((Object)(object)component2 == (Object)null) && component2.IsLocal)
				{
					__state.Valid = true;
					__state.ColdBefore = __instance.GetCurrentStatus((STATUSTYPE)2);
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("[NightColdDirectFix] Prefix failed: " + ex));
		}
	}

	[HarmonyPostfix]
	private static void Postfix(CharacterAfflictions __instance, ref UpdateNormalStatusesState __state)
	{
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (!__state.Valid || (Object)(object)__instance == (Object)null || Ascents.currentAscent < 5 || !Ascents.isNightCold || (Object)(object)DayNightManager.instance == (Object)null || DayNightManager.instance.isDay >= 0.5f)
			{
				return;
			}
			Character component = ((Component)__instance).GetComponent<Character>();
			if ((Object)(object)component == (Object)null || !component.IsLocal || ShouldBlockColdFromCurrentSegment())
			{
				return;
			}
			float num = Time.deltaTime * (1f - DayNightManager.instance.isDay) * Ascents.nightColdRate;
			if (num <= 0f)
			{
				return;
			}
			float currentStatus = __instance.GetCurrentStatus((STATUSTYPE)2);
			float num2 = currentStatus - __state.ColdBefore;
			if (num2 < 0f)
			{
				num2 = 0f;
			}
			float num3 = num - num2;
			if (num3 <= 1E-06f)
			{
				return;
			}
			__instance.AddStatus((STATUSTYPE)2, num3, false, true, true);
			if (!(Time.time >= _nextLogTime))
			{
				return;
			}
			_nextLogTime = Time.time + 1f;
			Vector3 center = component.Center;
			string name = ((Object)((Component)component).gameObject).name;
			int num4 = -1;
			string text = "<unknown>";
			try
			{
				if ((Object)(object)Singleton<MountainProgressHandler>.Instance != (Object)null)
				{
					num4 = Singleton<MountainProgressHandler>.Instance.maxProgressPointReached;
				}
			}
			catch
			{
			}
			try
			{
				if ((Object)(object)Singleton<MapHandler>.Instance != (Object)null)
				{
					Segment currentSegment = Singleton<MapHandler>.Instance.GetCurrentSegment();
					text = ((object)(Segment)(ref currentSegment)).ToString();
				}
			}
			catch
			{
			}
			Plugin.Log.LogInfo((object)("[NightColdDirectFix] Missing cold injected | time=" + Time.time.ToString("F2") + ", ascent=" + Ascents.currentAscent + ", isNightCold=" + Ascents.isNightCold + ", isDay=" + DayNightManager.instance.isDay.ToString("F4") + ", currentSegmentName=" + text + ", maxProgressPointReached=" + num4 + ", expectedColdAdd=" + num.ToString("F8") + ", originalColdDelta=" + num2.ToString("F8") + ", missingCold=" + num3.ToString("F8") + ", localCharacter=" + name + ", localCenter=(" + center.x.ToString("F2") + ", " + center.y.ToString("F2") + ", " + center.z.ToString("F2") + ")"));
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("[NightColdDirectFix] Postfix failed: " + ex));
		}
	}

	private static bool ShouldBlockColdFromCurrentSegment()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Invalid comparison between Unknown and I4
		try
		{
			if ((Object)(object)Singleton<MapHandler>.Instance == (Object)null)
			{
				return false;
			}
			Segment currentSegment = Singleton<MapHandler>.Instance.GetCurrentSegment();
			return (int)currentSegment >= 3;
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("[NightColdDirectFix] ShouldBlockColdFromCurrentSegment failed: " + ex));
			return false;
		}
	}
}