Decompiled source of Dehydration v1.1.0

plugins/PeakThirst.dll

Decompiled 3 days ago
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PEAKLib.Core;
using PEAKLib.Stats;
using PeakThirst;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("PeakThirst")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PeakThirst")]
[assembly: AssemblyTitle("PeakThirst")]
[assembly: AssemblyVersion("1.0.0.0")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
[HarmonyPatch(typeof(Item), "Awake")]
public static class Item_TargetMethod_Patch
{
	private static void Postfix(Item __instance)
	{
		Debug.Log((object)((Object)((Component)__instance).gameObject).name);
		float restoration = ThirstRestorationCalculator.CalculateThirstRestoration(((Component)__instance).gameObject);
		if (restoration <= 0f)
		{
			return;
		}
		Item obj = __instance;
		obj.OnConsumed = (Action)Delegate.Combine(obj.OnConsumed, (Action)delegate
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			Character holderCharacter = __instance.holderCharacter;
			CharacterAfflictions val = (((Object)(object)holderCharacter != (Object)null) ? holderCharacter.refs : null)?.afflictions;
			if ((Object)(object)val != (Object)null)
			{
				val.SubtractStatus(ThirstAffliction.DehydrationType, restoration, false);
			}
		});
	}
}
[HarmonyPatch(typeof(Action_RestoreHunger), "RunAction")]
public static class Action_RestoreHunger_TargetMethod_Patch
{
	private static readonly Func<ItemAction, Character> GetCharacter = AccessTools.MethodDelegate<Func<ItemAction, Character>>(AccessTools.PropertyGetter(typeof(ItemAction), "character"), (object)null, true);

	private static void Postfix(Action_RestoreHunger __instance)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		Character val = GetCharacter((ItemAction)(object)__instance);
		val.refs.afflictions.AddStatus(ThirstAffliction.DehydrationType, __instance.restorationAmount / 4f, false);
	}
}
[HarmonyPatch(typeof(CharacterAfflictions), "UpdateNormalStatuses")]
public static class CharacterAfflictions_TargetMethod_Patch
{
	private static void Postfix(CharacterAfflictions __instance)
	{
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		if (__instance.character.data.fullyConscious)
		{
			float num = Time.deltaTime * __instance.hungerPerSecond * Ascents.hungerRateMultiplier * 2f;
			CharacterAfflictions afflictions = __instance.character.refs.afflictions;
			afflictions.AddStatus(ThirstAffliction.DehydrationType, num, false);
		}
	}
}
internal static class SpriteLoader
{
	public static Sprite FromEmbedded(string resourceName, float pixelsPerUnit = 100f)
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Expected O, but got Unknown
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		using Stream stream = executingAssembly.GetManifestResourceStream(resourceName);
		if (stream == null)
		{
			Debug.LogError((object)("[PeakThirst] Embedded resource not found: " + resourceName));
			return null;
		}
		using MemoryStream memoryStream = new MemoryStream();
		stream.CopyTo(memoryStream);
		Texture2D val = new Texture2D(2, 2, (TextureFormat)5, false);
		if (!ImageConversion.LoadImage(val, memoryStream.ToArray()))
		{
			Debug.LogError((object)("[PeakThirst] Failed to load image data for: " + resourceName));
			return null;
		}
		((Object)val).name = Path.GetFileNameWithoutExtension(resourceName);
		((Texture)val).filterMode = (FilterMode)1;
		return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), pixelsPerUnit);
	}
}
public static class ThirstAffliction
{
	public const string StatusName = "Dehydration";

	public static STATUSTYPE DehydrationType;

	public static void CreateThirstAffliction()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: 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_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Expected O, but got Unknown
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		Sprite icon = SpriteLoader.FromEmbedded("PeakThirst.Sprites.Droplet.png");
		Status val = new Status
		{
			Name = "Dehydration",
			Color = new Color(0.075f, 0.286f, 1f),
			MaxAmount = 2f,
			AllowClear = true,
			ReductionCooldown = 0f,
			ReductionPerSecond = 0f,
			Icon = icon
		};
		new StatusContent(val).Register(Thirst.Definition);
		DehydrationType = val.Type;
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.All, Inherited = false)]
	public sealed class NullableAttribute : Attribute
	{
		public NullableAttribute(byte b)
		{
		}

		public NullableAttribute(byte[] b)
		{
		}
	}
	[AttributeUsage(AttributeTargets.All, Inherited = false)]
	public sealed class NullableContextAttribute : Attribute
	{
		public NullableContextAttribute(byte b)
		{
		}
	}
}
namespace PeakThirst
{
	public static class ThirstRestorationCalculator
	{
		public static float CalculateThirstRestoration(GameObject item)
		{
			string name = ((Object)item).name;
			Debug.Log((object)("Calculating thirst for " + name));
			float num = 0f;
			if (name.Contains("Apple Berry"))
			{
				num += 0.1f;
			}
			if (name.Contains("Berrynana"))
			{
				num += 0.2f;
			}
			if (name.Contains("Bugfix"))
			{
				num += 0.15f;
			}
			if (name.Contains("Clusterberry"))
			{
				num += 0.35f;
			}
			if (name.Contains("Kingberry"))
			{
				num += 0.15f;
			}
			if (name.Contains("Marshmallow"))
			{
				num += 0.45f;
			}
			if (name.Contains("Mushroom"))
			{
				num += 0.075f;
			}
			if (name.Contains("Sports Drink"))
			{
				num += 1f;
			}
			if (name.Contains("Winterberry"))
			{
				num += 0.3f;
			}
			if (name.Contains("Honeycomb"))
			{
				num += 0.15f;
			}
			if (name.Contains("Coconut_half"))
			{
				num += 0.6f;
			}
			if (name.Contains("AloeVera"))
			{
				num += 1.5f;
			}
			if (name.Contains("Turkey"))
			{
				num += 0.7f;
			}
			if (name.Contains("Napberry"))
			{
				num += 1f;
			}
			if (name.Contains("Prickleberry"))
			{
				num += 0.5f;
			}
			if (name.Contains("Cure-All"))
			{
				num += 0.9f;
			}
			if (name.Contains("MedicinalRoot"))
			{
				num += 0.2f;
			}
			if (name.Contains("Energy Drink"))
			{
				num += 0.5f;
			}
			return num;
		}
	}
	public class Action_MergerAction : ItemAction
	{
		public ItemAction action1;

		public ItemAction action2;

		public override void RunAction()
		{
			((ItemActionBase)action1).RunAction();
			((ItemActionBase)action2).RunAction();
		}
	}
	[BepInPlugin("com.khakixd.thirst", "Thirst", "0.1.0")]
	public class Thirst : BaseUnityPlugin
	{
		private Harmony _harmony;

		public static ModDefinition Definition { get; set; }

		private void Awake()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			Definition = ModDefinition.GetOrCreate(((BaseUnityPlugin)this).Info.Metadata);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Thirst loaded!");
			_harmony = new Harmony("com.khakixd.thirst");
			ThirstAffliction.CreateThirstAffliction();
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			try
			{
				int num = Harmony.GetAllPatchedMethods().Count();
				((BaseUnityPlugin)this).Logger.LogInfo((object)$"Harmony: total patched methods in process = {num}");
			}
			catch
			{
			}
		}

		private void OnDestroy()
		{
			try
			{
				Harmony harmony = _harmony;
				if (harmony != null)
				{
					harmony.UnpatchSelf();
				}
			}
			catch
			{
				Debug.Log((object)"Cannot unpatch thirst!");
			}
		}
	}
}