Decompiled source of SlowerColds v1.0.0

plugins/SlowerColds.dll

Decompiled 6 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
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("SlowerColds")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SlowerColds")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c5450fe0-edcf-483f-b9ea-4b1ef9d36da7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace SlowerColds;

[BepInPlugin("sigilbaram.slowercolds", "Slower Colds", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(PlayerCharacterStats), "UpdateDiseasesContraction")]
	public class PlayerCharacterStats_UpdateDiseasesContraction
	{
		private static bool Prefix(PlayerCharacterStats __instance)
		{
			Character character = ((CharacterStats)__instance).m_character;
			StatusEffectFamily diseaseFamily = DiseaseLibrary.Instance.GetDiseaseFamily((Diseases)0);
			if (character.StatusEffectMngr.HasStatusEffect(diseaseFamily))
			{
				return false;
			}
			if (character.StatusEffectMngr.HasStatusEffect("ColdExposure"))
			{
				StatusEffect statusEffectOfName = character.StatusEffectMngr.GetStatusEffectOfName("ColdExposure");
				if ((Object)(object)statusEffectOfName != (Object)null && statusEffectOfName.Age >= (float)coldMinTime.Value)
				{
					if (__instance.m_lastColdCheckGameTime > statusEffectOfName.Age)
					{
						__instance.m_lastColdCheckGameTime = 0f;
					}
					bool flag = __instance.m_lastColdCheckGameTime <= 0f && statusEffectOfName.Age < (float)(coldFrequency.Value + coldMinTime.Value);
					bool flag2 = statusEffectOfName.Age > __instance.m_lastColdCheckGameTime + (float)coldFrequency.Value;
					if (flag || flag2)
					{
						__instance.m_lastColdCheckGameTime = statusEffectOfName.Age;
						if (Random.Range(0f, 100f) <= coldChance.Value)
						{
							DiseaseLibrary.Instance.AddDiseaseToCharacter(character, (Diseases)0, (Character)null);
							__instance.m_lastColdCheckGameTime = 0f;
						}
					}
				}
			}
			else if (character.StatusEffectMngr.HasStatusEffect("Freezing"))
			{
				StatusEffect statusEffectOfName2 = character.StatusEffectMngr.GetStatusEffectOfName("Freezing");
				if ((Object)(object)statusEffectOfName2 != (Object)null && statusEffectOfName2.Age >= (float)freezingMinTime.Value)
				{
					if (__instance.m_lastColdCheckGameTime > statusEffectOfName2.Age)
					{
						__instance.m_lastColdCheckGameTime = 0f;
					}
					bool flag3 = __instance.m_lastColdCheckGameTime <= 0f && statusEffectOfName2.Age < (float)(freezingFrequency.Value + freezingMinTime.Value);
					bool flag4 = statusEffectOfName2.Age > __instance.m_lastColdCheckGameTime + (float)freezingFrequency.Value;
					if (flag3 || flag4)
					{
						__instance.m_lastColdCheckGameTime = statusEffectOfName2.Age;
						if (Random.Range(0f, 100f) <= freezingChance.Value)
						{
							DiseaseLibrary.Instance.AddDiseaseToCharacter(character, (Diseases)0, (Character)null);
							__instance.m_lastColdCheckGameTime = 0f;
						}
					}
				}
			}
			return false;
		}
	}

	public const string GUID = "sigilbaram.slowercolds";

	public const string NAME = "Slower Colds";

	public const string VERSION = "1.0.0";

	internal static ManualLogSource Log;

	public static ConfigEntry<int> coldFrequency;

	public static ConfigEntry<int> coldMinTime;

	public static ConfigEntry<float> coldChance;

	public static ConfigEntry<int> freezingFrequency;

	public static ConfigEntry<int> freezingMinTime;

	public static ConfigEntry<float> freezingChance;

	internal void Awake()
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Expected O, but got Unknown
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Expected O, but got Unknown
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Expected O, but got Unknown
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Expected O, but got Unknown
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Expected O, but got Unknown
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		coldChance = ((BaseUnityPlugin)this).Config.Bind<float>("Need: Cold", "Chance", 9f, new ConfigDescription("Chance during Cold", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
		coldMinTime = ((BaseUnityPlugin)this).Config.Bind<int>("Need: Cold", "Min Time", 30, new ConfigDescription("Minimum time during Cold (sec)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 150), Array.Empty<object>()));
		coldFrequency = ((BaseUnityPlugin)this).Config.Bind<int>("Need: Cold", "Check Frequence", 30, new ConfigDescription("How often to check during Cold (sec)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 150), Array.Empty<object>()));
		freezingChance = ((BaseUnityPlugin)this).Config.Bind<float>("Need: Very Cold", "Chance", 18f, new ConfigDescription("Chance during Very Cold", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
		freezingMinTime = ((BaseUnityPlugin)this).Config.Bind<int>("Need: Very Cold", "Min Time", 0, new ConfigDescription("Minimum time during Very Cold (sec)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 150), Array.Empty<object>()));
		freezingFrequency = ((BaseUnityPlugin)this).Config.Bind<int>("Need: Very Cold", "Check Frequence", 30, new ConfigDescription("How often to check during Very Cold (sec)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 150), Array.Empty<object>()));
		new Harmony("sigilbaram.slowercolds").PatchAll();
	}
}