Decompiled source of RebirthOfPurity Upgraded v1.0.2

RebirthOfPurity.dll

Decompiled a day ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("RebirthOfPurity")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+37bcda6ef10b80c868cd6b0d29de53af49488541")]
[assembly: AssemblyProduct("RebirthOfPurity")]
[assembly: AssemblyTitle("RebirthOfPurity")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RebirthOfPurity;

[BepInPlugin("com.github.saschati.rebirthofpurity", "Rebirth Of Purity Upgraded", "1.0.2")]
public class RebirthOfPurity : BaseUnityPlugin
{
	public static ConfigEntry<bool> EnablePurification;

	public static ConfigEntry<float> SleepPurificationRate;

	public static ConfigEntry<bool> OnlyPurifyWhileSleeping;

	private static ManualLogSource logger = Logger.CreateLogSource("RebirthOfPurityUpgraded");

	internal static readonly Harmony harmony = new Harmony("com.github.saschati.rebirthofpurity");

	private void Awake()
	{
		EnablePurification = ((BaseUnityPlugin)this).Config.Bind<bool>("", "Enable Purification", true, "Enable or disable corruption cleansing effects.");
		SleepPurificationRate = ((BaseUnityPlugin)this).Config.Bind<float>("", "Sleep Purification Rate", 100f, "Amount of corruption reduced per unit of in-game sleep time.");
		OnlyPurifyWhileSleeping = ((BaseUnityPlugin)this).Config.Bind<bool>("", "Only Purify While Sleeping", true, "If enabled, corruption is reduced only while the game is processing sleep/rest.");
		harmony.PatchAll();
		logger = Logger.CreateLogSource("Rebirth Of Purity Upgraded");
		logger.LogInfo((object)"loaded");
	}

	public static void LogInfo(params object[] args)
	{
		ManualLogSource val = logger;
		if (val != null)
		{
			val.LogDebug((object)string.Join(",", args));
		}
	}
}
internal static class CorruptionHelper
{
	private static readonly FieldRef<PlayerCharacterStats, float> corruptionLevelRef = AccessTools.FieldRefAccess<PlayerCharacterStats, float>("m_corruptionLevel");

	public static void SetCorruption(PlayerCharacterStats stats, float value)
	{
		if (!((Object)(object)stats == (Object)null))
		{
			corruptionLevelRef.Invoke(stats) = Mathf.Clamp(value, 0f, stats.MaxCorruption);
		}
	}

	public static void AddCorruption(PlayerCharacterStats stats, float value)
	{
		if (!((Object)(object)stats == (Object)null))
		{
			SetCorruption(stats, stats.Corruption + value);
		}
	}
}
[HarmonyPatch(typeof(Character), "SendResurrect")]
internal class Patch_Character_SendResurrect
{
	private static void Postfix(Character __instance)
	{
		if (RebirthOfPurity.EnablePurification.Value)
		{
			CorruptionHelper.SetCorruption(__instance.PlayerStats, 0f);
		}
	}
}
[HarmonyPatch(typeof(PlayerCharacterStats), "UpdateNeeds")]
internal class Patch_PlayerCharacterStats_UpdateNeeds
{
	private static void Postfix(PlayerCharacterStats __instance, float _deltaTime)
	{
		if (RebirthOfPurity.EnablePurification.Value && (!RebirthOfPurity.OnlyPurifyWhileSleeping.Value || (!((Object)(object)CharacterManager.Instance == (Object)null) && CharacterManager.Instance.IsSleepPending)))
		{
			float value = RebirthOfPurity.SleepPurificationRate.Value;
			CorruptionHelper.AddCorruption(__instance, (0f - _deltaTime) * value);
		}
	}
}