Decompiled source of EOSExt EnvTemperature v1.0.2

plugins/Inas07.EOSExt.EnvTemperature.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Agents;
using BepInEx;
using BepInEx.Unity.IL2CPP;
using EOSExt.EnvTemperature.Components;
using EOSExt.EnvTemperature.Definitions;
using EOSExt.EnvTemperature.Patches;
using ExtraObjectiveSetup.BaseClasses;
using ExtraObjectiveSetup.Utils;
using FloLib.Infos;
using GTFO.API;
using GTFO.API.Utilities;
using GameData;
using GameEvent;
using Gear;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppSystem.Collections.Generic;
using LevelGeneration;
using Localization;
using Microsoft.CodeAnalysis;
using Player;
using SNetwork;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Inas07.EOSExt.EnvTemperature")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+8ea4fc529bf4c30b0880418d9bd567d7c57ce903")]
[assembly: AssemblyProduct("Inas07.EOSExt.EnvTemperature")]
[assembly: AssemblyTitle("Inas07.EOSExt.EnvTemperature")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace EOSExt.EnvTemperature
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Inas.EOSExt.EnvTemperature", "EOSExt.EnvTemperature", "1.0.2")]
	public class EntryPoint : BasePlugin
	{
		public const string AUTHOR = "Inas";

		public const string PLUGIN_NAME = "EOSExt.EnvTemperature";

		public const string VERSION = "1.0.2";

		private Harmony m_Harmony;

		public override void Load()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			SetupManagers();
			m_Harmony = new Harmony("EOSExt.EnvTemperature");
			m_Harmony.PatchAll();
			EOSLogger.Log("ExtraObjectiveSetup.EnvTemperature loaded.");
		}

		private void SetupManagers()
		{
			((GenericDefinitionManager<TemperatureDefinition>)TemperatureDefinitionManager.Current).Init();
		}
	}
	public class TemperatureDefinitionManager : GenericDefinitionManager<TemperatureDefinition>
	{
		public static readonly TemperatureZoneDefinition DEFAULT_ZONE_DEF;

		public const float MIN_TEMP = 0.005f;

		public const float MAX_TEMP = 1f;

		public static TemperatureDefinitionManager Current { get; }

		protected override string DEFINITION_NAME => "EnvTemperature";

		private Dictionary<(eDimensionIndex dimensionIndex, LG_LayerType layerType, eLocalZoneIndex localIndex), TemperatureZoneDefinition> zoneDefs { get; } = new Dictionary<(eDimensionIndex, LG_LayerType, eLocalZoneIndex), TemperatureZoneDefinition>();


		protected override void AddDefinitions(GenericDefinition<TemperatureDefinition> definition)
		{
			List<TemperatureSetting> settings = definition.Definition.Settings;
			if (settings.Count > 0)
			{
				settings.Sort((TemperatureSetting t1, TemperatureSetting t2) => t1.Temperature.CompareTo(t2.Temperature));
				bool flag = true;
				if (settings[0].Temperature < 0f)
				{
					EOSLogger.Error($"Found negative temperature: '{settings[0].Temperature}'");
					flag = false;
				}
				if (settings[settings.Count - 1].Temperature > 1f)
				{
					EOSLogger.Error($"Found temperature greater than 1: '{settings[settings.Count - 1].Temperature}'");
					flag = false;
				}
				if (!flag)
				{
					EOSLogger.Error($"Found invalid temperature for MainLevelLayout '{definition.ID}'. Correct it first to make it effective");
					return;
				}
				if (settings[0].Temperature != 0f)
				{
					List<TemperatureSetting> list = new List<TemperatureSetting>();
					TemperatureSetting item = new TemperatureSetting(settings[0])
					{
						Temperature = 0f
					};
					list.Add(item);
					list.AddRange(settings);
					definition.Definition.Settings = list;
					settings.Clear();
					settings = list;
				}
			}
			foreach (TemperatureZoneDefinition zone in definition.Definition.Zones)
			{
				zone.Temperature_Downlimit = Math.Clamp(zone.Temperature_Downlimit, 0.005f, 1f);
				zone.Temperature_Uplimit = Math.Clamp(zone.Temperature_Uplimit, 0.005f, 1f);
				if (zone.Temperature_Downlimit > zone.Temperature_Uplimit)
				{
					EOSLogger.Error($"Invalid Temperature_Down/Up-limit setting! Downlimit == {zone.Temperature_Downlimit}, Uplimit == {zone.Temperature_Uplimit}");
					float temperature_Downlimit = zone.Temperature_Downlimit;
					zone.Temperature_Downlimit = zone.Temperature_Uplimit;
					zone.Temperature_Uplimit = temperature_Downlimit;
				}
				if (!(zone.Temperature_Downlimit <= zone.Temperature_Normal) || !(zone.Temperature_Normal <= zone.Temperature_Uplimit))
				{
					EOSLogger.Error($"Invalid Temperature_Normal setting! Temperature_Normal == {zone.Temperature_Normal} not in limit range [{zone.Temperature_Downlimit}, {zone.Temperature_Uplimit}] !");
					zone.Temperature_Normal = Math.Clamp(zone.Temperature_Normal, zone.Temperature_Downlimit, zone.Temperature_Uplimit);
				}
				zone.FluctuateRate = Math.Abs(zone.FluctuateRate);
			}
			base.AddDefinitions(definition);
		}

		protected override void FileChanged(LiveEditEventArgs e)
		{
			base.FileChanged(e);
			Clear();
			OnBuildDone();
			if (PlayerTemperatureManager.TryGetCurrentManager(out var mgr) && base.definitions.TryGetValue(RundownManager.ActiveExpedition.LevelLayoutData, out var value))
			{
				mgr.UpdateTemperatureDefinition(value.Definition);
				mgr.UpdateGUIText();
			}
		}

		private void OnBuildDone()
		{
			if (!base.definitions.TryGetValue(RundownManager.ActiveExpedition.LevelLayoutData, out var value))
			{
				return;
			}
			value.Definition.Zones.ForEach(delegate(TemperatureZoneDefinition def)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0071: Unknown result type (might be due to invalid IL or missing references)
				//IL_0077: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: Unknown result type (might be due to invalid IL or missing references)
				if (zoneDefs.ContainsKey((((GlobalZoneIndex)def).DimensionIndex, ((GlobalZoneIndex)def).LayerType, ((GlobalZoneIndex)def).LocalIndex)))
				{
					EOSLogger.Warning($"TemperatureDefinitionManager: duplicate definition found: {(((GlobalZoneIndex)def).DimensionIndex, ((GlobalZoneIndex)def).LayerType, ((GlobalZoneIndex)def).LocalIndex)}");
				}
				zoneDefs[(((GlobalZoneIndex)def).DimensionIndex, ((GlobalZoneIndex)def).LayerType, ((GlobalZoneIndex)def).LocalIndex)] = def;
			});
		}

		private void Clear()
		{
			zoneDefs.Clear();
		}

		public bool TryGetZoneDefinition(eDimensionIndex dimensionIndex, LG_LayerType layerType, eLocalZoneIndex localIndex, out TemperatureZoneDefinition def)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return zoneDefs.TryGetValue((dimensionIndex, layerType, localIndex), out def);
		}

		public bool TryGetLevelTemperatureSettings(out List<TemperatureSetting> settings)
		{
			if (base.definitions.TryGetValue(RundownManager.ActiveExpedition.LevelLayoutData, out var value))
			{
				settings = value.Definition.Settings;
				if (settings != null)
				{
					return settings.Count > 0;
				}
				return false;
			}
			settings = null;
			return false;
		}

		private TemperatureDefinitionManager()
		{
			LevelAPI.OnBuildDone += OnBuildDone;
			LevelAPI.OnBuildStart += Clear;
			LevelAPI.OnLevelCleanup += Clear;
		}

		static TemperatureDefinitionManager()
		{
			Current = new TemperatureDefinitionManager();
			DEFAULT_ZONE_DEF = new TemperatureZoneDefinition
			{
				FluctuateRate = 0f
			};
		}
	}
}
namespace EOSExt.EnvTemperature.Patches
{
	[HarmonyPatch]
	internal static class Patch_BulletWeapon
	{
		private static TemperatureSetting? m_curSetting;

		private static Dictionary<uint, float> DefaultReloadTimes;

		[HarmonyPostfix]
		[HarmonyWrapSafe]
		[HarmonyPatch(typeof(BulletWeaponArchetype), "OnWield")]
		public static void Post_OnWield(BulletWeaponArchetype __instance)
		{
			uint persistentID = ((GameDataBlockBase<ArchetypeDataBlock>)(object)__instance.m_archetypeData).persistentID;
			if (!DefaultReloadTimes.ContainsKey(persistentID))
			{
				DefaultReloadTimes[persistentID] = __instance.m_archetypeData.DefaultReloadTime;
			}
			TemperatureSetting curSetting = m_curSetting;
			if (curSetting != null && curSetting.SlowDownMultiplier_Reload > 0f)
			{
				__instance.m_archetypeData.DefaultReloadTime = DefaultReloadTimes[persistentID] * curSetting.SlowDownMultiplier_Reload;
				EOSLogger.Debug("Temperature: Slowing down reload!");
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(BulletWeaponArchetype), "Update")]
		private static void Post_Update(BulletWeaponArchetype __instance)
		{
			TemperatureSetting currentTemperatureSetting = PlayerTemperatureManager.GetCurrentTemperatureSetting();
			if (m_curSetting == currentTemperatureSetting)
			{
				return;
			}
			uint persistentID = ((GameDataBlockBase<ArchetypeDataBlock>)(object)__instance.m_archetypeData).persistentID;
			if (DefaultReloadTimes.ContainsKey(persistentID))
			{
				float num = DefaultReloadTimes[persistentID];
				if (currentTemperatureSetting == null || currentTemperatureSetting.SlowDownMultiplier_Reload <= 0f)
				{
					__instance.m_archetypeData.DefaultReloadTime = num;
				}
				else
				{
					__instance.m_archetypeData.DefaultReloadTime = num * currentTemperatureSetting.SlowDownMultiplier_Reload;
				}
			}
			m_curSetting = currentTemperatureSetting;
		}

		[HarmonyPrefix]
		[HarmonyWrapSafe]
		[HarmonyPatch(typeof(BulletWeaponArchetype), "OnUnWield")]
		private static void Pre_OnUnWield(BulletWeaponArchetype __instance)
		{
			uint persistentID = ((GameDataBlockBase<ArchetypeDataBlock>)(object)__instance.m_archetypeData).persistentID;
			if (DefaultReloadTimes.ContainsKey(persistentID))
			{
				float defaultReloadTime = DefaultReloadTimes[persistentID];
				__instance.m_archetypeData.DefaultReloadTime = defaultReloadTime;
			}
		}

		private static void Clear()
		{
			DefaultReloadTimes.Clear();
		}

		static Patch_BulletWeapon()
		{
			m_curSetting = null;
			DefaultReloadTimes = new Dictionary<uint, float>();
			LevelAPI.OnBuildStart += Clear;
			LevelAPI.OnLevelCleanup += Clear;
		}
	}
	[HarmonyPatch]
	internal static class Patch_MWS_ChargeUp_Enter
	{
		private static float DefaultChargeTime = 1f;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MWS_ChargeUp), "Enter")]
		private static void Postfix_Enter(MWS_ChargeUp __instance)
		{
			DefaultChargeTime = __instance.m_maxDamageTime;
			TemperatureSetting currentTemperatureSetting = PlayerTemperatureManager.GetCurrentTemperatureSetting();
			if (currentTemperatureSetting != null && currentTemperatureSetting.SlowDownMultiplier_Melee > 0f)
			{
				__instance.m_maxDamageTime *= currentTemperatureSetting.SlowDownMultiplier_Melee;
			}
		}

		[HarmonyPrefix]
		[HarmonyWrapSafe]
		[HarmonyPatch(typeof(MWS_ChargeUp), "Exit")]
		private static void Pre_Exit(MWS_ChargeUp __instance)
		{
			__instance.m_maxDamageTime = DefaultChargeTime;
		}
	}
	[HarmonyPatch]
	internal static class Patch_Dam_PlayerDamageBase
	{
		internal static bool s_disableDialog;

		[HarmonyPrefix]
		[HarmonyWrapSafe]
		[HarmonyPatch(typeof(Dam_PlayerDamageLocal), "ReceiveFallDamage")]
		private static bool Pre_ReceiveFallDamage(Dam_PlayerDamageLocal __instance, pMiniDamageData data)
		{
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			float num = ((UFloat16)(ref data.damage)).Get(((Dam_SyncedDamageBase)__instance).HealthMax);
			((Dam_PlayerDamageBase)__instance).m_nextRegen = Clock.Time + ((Dam_PlayerDamageBase)__instance).Owner.PlayerData.healthRegenStartDelayAfterDamage;
			if (((Agent)((Dam_PlayerDamageBase)__instance).Owner).IsLocallyOwned)
			{
				DramaManager.CurrentState.OnLocalDamage(num);
				GameEventManager.PostEvent((eGameEvent)13, ((Dam_PlayerDamageBase)__instance).Owner, num, "", (Dictionary<string, string>)null);
			}
			else
			{
				DramaManager.CurrentState.OnTeammatesDamage(num);
			}
			if (((Dam_PlayerDamageBase)__instance).IgnoreAllDamage)
			{
				return false;
			}
			if (SNet.IsMaster)
			{
				if (((Dam_SyncedDamageBase)__instance).RegisterDamage(num))
				{
					((Dam_SyncedDamageBase)__instance).SendSetDead(true);
				}
				else
				{
					((Dam_SyncedDamageBase)__instance).SendSetHealth(((Dam_SyncedDamageBase)__instance).Health);
				}
			}
			__instance.Hitreact(((UFloat16)(ref data.damage)).Get(((Dam_SyncedDamageBase)__instance).HealthMax), Vector3.zero, true, !s_disableDialog, false);
			return false;
		}
	}
	[HarmonyPatch]
	internal static class Patch_PlayerAgent
	{
		[HarmonyPostfix]
		[HarmonyWrapSafe]
		[HarmonyPatch(typeof(PlayerAgent), "Setup")]
		private static void Post_Setup(PlayerAgent __instance)
		{
			if (((Agent)__instance).IsLocallyOwned && !((Object)(object)((Component)__instance).gameObject.GetComponent<PlayerTemperatureManager>() != (Object)null))
			{
				((Component)__instance).gameObject.AddComponent<PlayerTemperatureManager>().Setup();
			}
		}
	}
	[HarmonyPatch]
	internal static class Patches_PLOC
	{
		private const float MIN_MOD = 0.1f;

		private static float s_moveSpeedMult = 1f;

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PLOC_Base), "GetHorizontalVelocityFromInput")]
		private static void Pre_GetHorizontalVelocityFromInput(ref float moveSpeed)
		{
			moveSpeed *= s_moveSpeedMult;
		}

		internal static void SetMoveSpeedModifier(float m)
		{
			s_moveSpeedMult = Math.Max(0.1f, m);
		}

		internal static void ResetMoveSpeedModifier()
		{
			s_moveSpeedMult = 1f;
		}
	}
}
namespace EOSExt.EnvTemperature.Definitions
{
	public class TemperatureSetting
	{
		public float Temperature { get; set; } = 1f;


		public float Damage { get; set; } = -1f;


		public float DamageTick { get; set; }

		public float SlowDownMultiplier_Reload { get; set; } = -1f;


		public float SlowDownMultiplier_Melee { get; set; } = -1f;


		public float SlowDownMultiplier_Move { get; set; } = -1f;


		public TemperatureSetting()
		{
		}

		public TemperatureSetting(TemperatureSetting o)
		{
			Temperature = o.Temperature;
			Damage = o.Damage;
			DamageTick = o.DamageTick;
			SlowDownMultiplier_Reload = o.SlowDownMultiplier_Reload;
			SlowDownMultiplier_Melee = o.SlowDownMultiplier_Melee;
			SlowDownMultiplier_Move = o.SlowDownMultiplier_Move;
		}
	}
	public class TemperatureZoneDefinition : GlobalZoneIndex
	{
		public float Temperature_Downlimit { get; set; } = 0.005f;


		public float Temperature_Normal { get; set; } = 0.5f;


		public float Temperature_Uplimit { get; set; } = 1f;


		public float FluctuateRate { get; set; }
	}
	public class TemperatureDefinition
	{
		public float StartTemperature { get; set; } = 0.5f;


		public float JumpActionHeatGained { get; set; }

		public float SprintActionHeatGained { get; set; }

		public float CrouchActionHeatGained { get; set; }

		public float StandingActionHeatGained { get; set; }

		public float LadderClimbingActionHeatGained { get; set; }

		public List<TemperatureZoneDefinition> Zones { get; set; } = new List<TemperatureZoneDefinition>
		{
			new TemperatureZoneDefinition()
		};


		public List<TemperatureSetting> Settings { get; set; } = new List<TemperatureSetting>
		{
			new TemperatureSetting()
		};

	}
}
namespace EOSExt.EnvTemperature.Components
{
	public class PlayerTemperatureManager : MonoBehaviour
	{
		public const float DEFAULT_PLAYER_TEMPERATURE = 0.5f;

		public const float TEMPERATURE_SETTING_UPDATE_TIME = 1f;

		public const float TEMPERATURE_FLUCTUATE_TIME = 1f;

		private float m_tempSettingLastUpdateTime;

		private float m_lastDamageTime;

		private float m_tempFluctuateTime;

		private bool m_ShowDamageWarning = true;

		private TextMeshPro m_TemperatureText;

		private const string DEFAULT_GUI_TEXT = "SUIT TEMP: <color=orange>{0}</color>";

		private string m_GUIText = "SUIT TEMP: <color=orange>{0}</color>";

		private readonly Color m_lowTempColor = new Color(0f, 0.5f, 0.5f);

		private readonly Color m_midTempColor = new Color(1f, 0.64f, 0f);

		private readonly Color m_highTempColor = new Color(1f, 0.07f, 0.576f);

		public PlayerAgent PlayerAgent { get; private set; }

		public TemperatureDefinition? TemperatureDef { get; private set; }

		public TemperatureSetting? TemperatureSetting { get; private set; }

		public float PlayerTemperature { get; private set; } = 0.5f;


		internal void Setup()
		{
			TemperatureDef = null;
			PlayerAgent = ((Component)this).gameObject.GetComponent<PlayerAgent>();
			LevelAPI.OnBuildDone += OnBuildDone;
			LevelAPI.OnEnterLevel += OnEnterLevel;
		}

		private void OnDestroy()
		{
			Object.Destroy((Object)(object)m_TemperatureText);
			LevelAPI.OnBuildDone -= OnBuildDone;
			LevelAPI.OnEnterLevel -= OnEnterLevel;
		}

		private void SetupGUI()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)m_TemperatureText == (Object)null)
			{
				m_TemperatureText = Object.Instantiate<TextMeshPro>(GuiManager.PlayerLayer.m_objectiveTimer.m_titleText);
				m_TemperatureText.transform.SetParent(((Component)GuiManager.PlayerLayer.m_playerStatus).gameObject.transform, false);
				((Component)m_TemperatureText).GetComponent<RectTransform>().anchoredPosition = new Vector2(-5f, 8f);
				((Component)m_TemperatureText).gameObject.transform.localPosition = new Vector3(268.2203f, 25.3799f, 0f);
				((Component)m_TemperatureText).gameObject.transform.localScale = new Vector3(0.75f, 0.75f, 0.75f);
			}
			((Component)m_TemperatureText).gameObject.SetActive(TemperatureDef != null);
		}

		internal void UpdateGUIText()
		{
			TextDataBlock block = GameDataBlockBase<TextDataBlock>.GetBlock("EnvTemperature.Text");
			m_GUIText = ((block != null) ? Text.Get(((GameDataBlockBase<TextDataBlock>)(object)block).persistentID) : "SUIT TEMP: <color=orange>{0}</color>");
		}

		private void UpdateGui()
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			if (TemperatureDef != null)
			{
				((Component)m_TemperatureText).gameObject.SetActive(true);
				((TMP_Text)m_TemperatureText).SetText(string.Format(m_GUIText, (PlayerTemperature * 100f).ToString("N0")), true);
				if (PlayerTemperature > 0.5f)
				{
					((Graphic)m_TemperatureText).color = Color.Lerp(m_midTempColor, m_highTempColor, (PlayerTemperature - 0.5f) * 2f);
				}
				else
				{
					((Graphic)m_TemperatureText).color = Color.Lerp(m_lowTempColor, m_midTempColor, PlayerTemperature * 2f);
				}
				((TMP_Text)m_TemperatureText).ForceMeshUpdate(false, false);
			}
			else
			{
				((Component)m_TemperatureText).gameObject.SetActive(false);
			}
		}

		private void UpdateMoveSpeed()
		{
			if (TemperatureSetting == null || TemperatureSetting.SlowDownMultiplier_Move <= 0f)
			{
				Patches_PLOC.ResetMoveSpeedModifier();
			}
			else
			{
				Patches_PLOC.SetMoveSpeedModifier(TemperatureSetting.SlowDownMultiplier_Move);
			}
		}

		private void ResetMoveSpeed()
		{
			Patches_PLOC.ResetMoveSpeedModifier();
		}

		public void UpdateTemperatureDefinition(TemperatureDefinition def)
		{
			TemperatureDef = def;
			TemperatureSetting = null;
			PlayerTemperature = def?.StartTemperature ?? 0.5f;
		}

		private void OnBuildDone()
		{
			UpdateTemperatureDefinition(((GenericDefinitionManager<TemperatureDefinition>)TemperatureDefinitionManager.Current).GetDefinition(RundownManager.ActiveExpedition.LevelLayoutData)?.Definition ?? null);
		}

		private void OnEnterLevel()
		{
			PlayerTemperature = ((TemperatureDef != null) ? TemperatureDef.StartTemperature : 0.5f);
			UpdateGUIText();
			SetupGUI();
			ResetMoveSpeed();
		}

		private void DealDamage()
		{
			if (TemperatureSetting != null && !(TemperatureSetting.Damage < 0f) && !(Time.time - m_lastDamageTime < TemperatureSetting.DamageTick))
			{
				Patch_Dam_PlayerDamageBase.s_disableDialog = true;
				((Dam_SyncedDamageBase)PlayerAgent.Damage).FallDamage(TemperatureSetting.Damage);
				Patch_Dam_PlayerDamageBase.s_disableDialog = false;
				m_lastDamageTime = Time.time;
			}
		}

		private void UpdateTemperatureSettings()
		{
			if (Time.time - m_tempSettingLastUpdateTime < 1f)
			{
				return;
			}
			if (!TemperatureDefinitionManager.Current.TryGetLevelTemperatureSettings(out var settings))
			{
				TemperatureSetting = null;
				return;
			}
			int num = 0;
			int num2 = settings.Count - 1;
			float playerTemperature = PlayerTemperature;
			while (num < num2)
			{
				int num3 = (num + num2) / 2;
				float temperature = settings[num3].Temperature;
				float num4 = ((num3 + 1 < settings.Count) ? settings[num3 + 1].Temperature : 1f);
				if (temperature <= playerTemperature && playerTemperature < num4)
				{
					break;
				}
				if (playerTemperature < temperature)
				{
					num2 = num3 - 1;
				}
				else
				{
					num = num3 + 1;
				}
			}
			TemperatureSetting = settings[Math.Clamp((num + num2) / 2, 0, settings.Count - 1)];
			m_tempSettingLastUpdateTime = Time.time;
		}

		private void Update()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected I4, but got Unknown
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			if ((int)GameStateManager.CurrentStateName != 10 || TemperatureDef == null || (Object)(object)PlayerAgent == (Object)null)
			{
				return;
			}
			Vector3 lastMoveDelta = PlayerAgent.Locomotion.LastMoveDelta;
			float num = ((Vector3)(ref lastMoveDelta)).magnitude / Clock.FixedDelta;
			float num2 = (PlayerAgent.PlayerData.walkMoveSpeed + PlayerAgent.PlayerData.runMoveSpeed) * 0.5f;
			float num3 = 0f;
			PLOC_State currentStateEnum = PlayerAgent.Locomotion.m_currentStateEnum;
			switch ((int)currentStateEnum)
			{
			case 0:
				num3 = TemperatureDef.StandingActionHeatGained * Time.deltaTime;
				break;
			case 1:
				num3 = ((!(num <= num2)) ? ((TemperatureDef.CrouchActionHeatGained + TemperatureDef.SprintActionHeatGained) * Time.deltaTime) : (TemperatureDef.CrouchActionHeatGained * Time.deltaTime));
				break;
			case 2:
				num3 = TemperatureDef.SprintActionHeatGained * Time.deltaTime;
				break;
			case 3:
				num3 = ((!(num <= num2)) ? ((TemperatureDef.JumpActionHeatGained + TemperatureDef.SprintActionHeatGained) * Time.deltaTime) : (TemperatureDef.JumpActionHeatGained * Time.deltaTime));
				break;
			case 7:
				num3 = 0f;
				break;
			case 8:
				num3 = TemperatureDef.LadderClimbingActionHeatGained * Time.deltaTime;
				break;
			}
			float num4 = TemperatureDef.StartTemperature;
			LG_Zone zone = ((Agent)PlayerAgent).CourseNode.m_zone;
			float min = 0.005f;
			float max = 1f;
			if (TemperatureDefinitionManager.Current.TryGetZoneDefinition(zone.DimensionIndex, zone.Layer.m_type, zone.LocalIndex, out var def))
			{
				num4 = def.Temperature_Normal;
				min = def.Temperature_Downlimit;
				max = def.Temperature_Uplimit;
			}
			if ((double)Math.Abs(num3) < 1E-05)
			{
				if (Time.time - m_tempFluctuateTime > 1f)
				{
					float num5 = def.FluctuateRate * Random.RandomRange(0f, 1f);
					if (PlayerTemperature > num4)
					{
						PlayerTemperature -= num5;
					}
					else
					{
						PlayerTemperature += num5;
					}
					m_tempFluctuateTime = Time.time;
				}
			}
			else
			{
				m_tempFluctuateTime = Time.time;
			}
			PlayerTemperature += num3;
			PlayerTemperature = Math.Clamp(PlayerTemperature, min, max);
			UpdateTemperatureSettings();
			TemperatureSetting? temperatureSetting = TemperatureSetting;
			if (temperatureSetting != null && temperatureSetting.Damage > 0f)
			{
				DealDamage();
			}
			UpdateGui();
			UpdateMoveSpeed();
		}

		public static bool TryGetCurrentManager(out PlayerTemperatureManager mgr)
		{
			mgr = null;
			LocalPlayerAgent val = default(LocalPlayerAgent);
			if (!LocalPlayer.TryGetLocalAgent(ref val))
			{
				EOSLogger.Debug("Temperature: cannot get localplayeragent");
				return false;
			}
			mgr = ((Component)val).gameObject.GetComponent<PlayerTemperatureManager>();
			if ((Object)(object)val == (Object)null)
			{
				EOSLogger.Error("LocalPlayerAgent does not have `PlayerTemperatureManager`!");
				return false;
			}
			return true;
		}

		public static TemperatureSetting? GetCurrentTemperatureSetting()
		{
			if (!TryGetCurrentManager(out var mgr))
			{
				return null;
			}
			return mgr.TemperatureSetting;
		}

		static PlayerTemperatureManager()
		{
			ClassInjector.RegisterTypeInIl2Cpp<PlayerTemperatureManager>();
		}
	}
}