Decompiled source of VeryHungry v0.0.4

VeryHungry.dll

Decompiled 7 hours 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 BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using SettingsExtender;
using UnityEngine;
using UnityEngine.UI;
using Zorro.Settings;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("VeryHungry")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.0.4.0")]
[assembly: AssemblyInformationalVersion("0.0.4")]
[assembly: AssemblyProduct("VeryHungry")]
[assembly: AssemblyTitle("VeryHungry")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.4.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace VeryHungry
{
	[BepInPlugin("VeryHungry", "VeryHungry", "0.0.4")]
	public class VeryHungry : BaseUnityPlugin
	{
		[ExtenderSetting("VeryHungry", "Enable Cannibal")]
		private class EnableCannibal : ExtenderBoolSetting, IExposedSetting
		{
			public EnableCannibal()
				: base((Action<bool>)_instance.UpdateCannibalSetting)
			{
			}

			protected override bool GetDefaultValue()
			{
				return false;
			}
		}

		[HarmonyPatch(typeof(CharacterCustomization), "BecomeHuman")]
		internal class SetAlwaysChicken
		{
			private static bool Prefix()
			{
				return !_instance.cannibalismEnabled;
			}
		}

		[HarmonyPatch(typeof(Character), "UseStamina")]
		internal class HalveStaminaUsage
		{
			private static void Prefix(ref float usage, bool useBonusStamina = true)
			{
				if (_instance.cannibalismEnabled)
				{
					usage *= 0.5f;
				}
			}
		}

		[HarmonyPatch(typeof(StaminaBar), "Start")]
		internal class SaveDefaultColor
		{
			private static void Prefix(ref StaminaBar __instance)
			{
				//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)
				_instance.defaultBarColor = ((Graphic)((Component)__instance.staminaBar).GetComponentInChildren<Image>()).color;
				_instance.updateBarColor = true;
			}
		}

		[HarmonyPatch(typeof(StaminaBar), "Update")]
		internal class SetBarToRed
		{
			private static void Prefix(ref StaminaBar __instance)
			{
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				if (_instance.updateBarColor)
				{
					if (_instance.cannibalismEnabled)
					{
						((Graphic)((Component)__instance.staminaBar).GetComponentInChildren<Image>()).color = new Color(1f, 0.33f, 0.33f);
					}
					else
					{
						((Graphic)((Component)__instance.staminaBar).GetComponentInChildren<Image>()).color = _instance.defaultBarColor;
					}
					_instance.updateBarColor = false;
				}
			}
		}

		[HarmonyPatch(typeof(CharacterInteractible), "GetInteractTime")]
		internal class PatchEatSpeed
		{
			private static bool Prefix(Character interactor, ref CharacterInteractible __instance, ref float __result)
			{
				if (__instance.character.refs.customization.isCannibalizable)
				{
					__result = 1f;
				}
				else
				{
					__result = 3f;
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(CharacterInteractible), "GetEaten")]
		internal class DisableCurseOnEat
		{
			private static bool Prefix(Character eater, ref CharacterInteractible __instance)
			{
				if (eater.IsLocal)
				{
					AccessTools.Method(typeof(Character), "DieInstantly", (Type[])null, (Type[])null).Invoke(__instance.character, null);
					eater.refs.afflictions.SubtractStatus((STATUSTYPE)1, 1f, false);
					eater.refs.afflictions.AddStatus((STATUSTYPE)6, 0.25f, false);
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(Interaction), "LateUpdate")]
		internal class ShortenPlayerInteractRange
		{
			private static bool Prefix(ref Interaction __instance)
			{
				//IL_010b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0122: Unknown result type (might be due to invalid IL or missing references)
				//IL_0127: Unknown result type (might be due to invalid IL or missing references)
				//IL_012c: Unknown result type (might be due to invalid IL or missing references)
				__instance.currentHovered = null;
				FieldInfo fieldInfo = AccessTools.Field(typeof(Interaction), "bestCharacter");
				FieldInfo fieldInfo2 = AccessTools.Field(typeof(Interaction), "bestInteractable");
				FieldInfo fieldInfo3 = AccessTools.Field(typeof(Interaction), "bestInteractableName");
				bool? flag = AccessTools.PropertyGetter(typeof(Interaction), "canInteract").Invoke(__instance, null) as bool?;
				if (!Object.op_Implicit((Object)(object)Character.localCharacter))
				{
					return false;
				}
				if (flag != true)
				{
					fieldInfo2.SetValue(__instance, null);
					fieldInfo.SetValue(__instance, null);
				}
				else
				{
					object[] array = new object[1];
					AccessTools.Method(typeof(Interaction), "DoInteractableRaycasts", (Type[])null, (Type[])null).Invoke(__instance, array);
					fieldInfo2.SetValue(__instance, array[0]);
					Interaction obj = __instance;
					object? value = fieldInfo2.GetValue(__instance);
					fieldInfo.SetValue(obj, (value is CharacterInteractible) ? value : null);
					if (fieldInfo2.GetValue(__instance) != null)
					{
						Vector3 position = ((Component)MainCamera.instance).transform.position;
						object? value2 = fieldInfo2.GetValue(__instance);
						Vector3 val = position - ((IInteractible)((value2 is IInteractible) ? value2 : null)).GetTransform().position;
						if (((Vector3)(ref val)).magnitude > 3f && (Object)/*isinst with value type is only supported in some contexts*/ != (Object)null)
						{
							fieldInfo2.SetValue(__instance, null);
						}
					}
					if (__instance.currentHeldInteractible != null)
					{
						AccessTools.Method(typeof(Interaction), "DoInteraction", new Type[1] { typeof(IInteractible) }, (Type[])null).Invoke(__instance, new object[1] { (object)/*isinst with value type is only supported in some contexts*/ });
					}
				}
				fieldInfo3.SetValue(__instance, (fieldInfo2.GetValue(__instance) == null) ? "null" : ((Object)((Component)((IInteractible)/*isinst with value type is only supported in some contexts*/).GetTransform()).gameObject).name);
				ref IInteractible currentHovered = ref __instance.currentHovered;
				object? value3 = fieldInfo2.GetValue(__instance);
				currentHovered = (IInteractible)((value3 is IInteractible) ? value3 : null);
				return false;
			}
		}

		[HarmonyPatch(typeof(UIPlayerNames), "UpdateName")]
		internal class AlwaysChicken
		{
			private static bool Prefix(int index, Vector3 position, bool visible, int speakingAmplitude, ref UIPlayerNames __instance)
			{
				if (!Object.op_Implicit((Object)(object)Character.localCharacter))
				{
					return true;
				}
				if (ShouldShowChickens())
				{
					__instance.playerNameText[index].characterInteractable.character.refs.customization.BecomeChicken();
				}
				else
				{
					__instance.playerNameText[index].characterInteractable.character.refs.customization.BecomeHuman();
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(UIPlayerNames), "CanCannibalize")]
		internal class SetAlwaysCannibalize
		{
			private static bool Prefix(Character otherCharacter, ref bool __result)
			{
				__result = !otherCharacter.refs.customization.isCannibalizable && ShouldShowChickens();
				return false;
			}
		}

		[HarmonyPatch(typeof(CharacterAfflictions), "AddStatus")]
		internal class DisableAddInjury
		{
			private static bool Prefix(STATUSTYPE statusType, float amount, bool fromRPC = false)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				if ((int)statusType == 0)
				{
					return !_instance.cannibalismEnabled;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(CharacterAfflictions), "SetStatus")]
		internal class DisableSetInjury
		{
			private static bool Prefix(STATUSTYPE statusType, float amount)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				if ((int)statusType == 0)
				{
					return !_instance.cannibalismEnabled;
				}
				return true;
			}
		}

		internal static ManualLogSource Log;

		internal static VeryHungry _instance;

		public bool cannibalismEnabled;

		public bool updateBarColor = true;

		public Color defaultBarColor = new Color(0.25f, 0.8f, 0f);

		private void Awake()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			_instance = this;
			Harmony val = new Harmony("VeryHungry");
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"VeryHungry Loaded...");
			SettingsRegistry.Register("VeryHungry");
			val.PatchAll();
		}

		private void Start()
		{
			SettingsHandlerExtensions.AddSetting<EnableCannibal>(SettingsHandler.Instance);
		}

		private void UpdateCannibalSetting(bool setting)
		{
			cannibalismEnabled = setting;
			updateBarColor = true;
		}

		public static bool ShouldShowChickens()
		{
			if (!Object.op_Implicit((Object)(object)Character.localCharacter))
			{
				return false;
			}
			if (AccessTools.Field(typeof(CharacterAfflictions), "m_inAirport").GetValue(Character.localCharacter.refs.afflictions) as bool? != true)
			{
				return _instance.cannibalismEnabled;
			}
			return false;
		}
	}
	internal class CannibalManager : MonoBehaviour
	{
		private List<int> cannibalIDs;

		[PunRPC]
		private void AddCannibal_RPC(int cannibalID)
		{
			if (!cannibalIDs.Contains(cannibalID))
			{
				cannibalIDs.Add(cannibalID);
				VeryHungry.Log.LogInfo((object)$"[VeryHungry] Added cannibal {cannibalID}");
			}
			else
			{
				VeryHungry.Log.LogInfo((object)$"[VeryHungry] Tried to add cannibal {cannibalID}, but cannibal is already listed");
			}
		}

		[PunRPC]
		private void RemoveCannibal_RPC(int cannibalID)
		{
			if (cannibalIDs.Remove(cannibalID))
			{
				VeryHungry.Log.LogInfo((object)$"[VeryHungry] Removed cannibal {cannibalID}");
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "VeryHungry";

		public const string PLUGIN_NAME = "VeryHungry";

		public const string PLUGIN_VERSION = "0.0.4";
	}
}