Decompiled source of Carry Restraint v1.0.1

com.github.glarmer.CarryRestraint.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using CarryRestraint.Patches;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.glarmer.CarryRestraint")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+fc5cd1ff8b98fc0551db0612a5632f5ffe22ca57")]
[assembly: AssemblyProduct("com.github.glarmer.CarryRestraint")]
[assembly: AssemblyTitle("CarryRestraint")]
[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace CarryRestraint
{
	public class Notification : MonoBehaviour
	{
		private TextMeshProUGUI text;

		private Image background;

		private CanvasGroup canvasGroup;

		private float fadeDelay = 2f;

		private float fadeDuration = 0.5f;

		private int fontSize = 28;

		private float timer;

		internal static Notification instance;

		public static Notification Create()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			if ((Object)(object)instance != (Object)null)
			{
				return instance;
			}
			GameObject val = new GameObject("Notification");
			val.transform.SetParent(((Component)GUIManager.instance.hudCanvas).transform, false);
			instance = val.AddComponent<Notification>();
			instance.Initialise();
			return instance;
		}

		private void Initialise()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Expected O, but got Unknown
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			canvasGroup = ((Component)this).gameObject.AddComponent<CanvasGroup>();
			RectTransform val = ((Component)this).gameObject.AddComponent<RectTransform>();
			val.anchorMin = new Vector2(0.5f, 0f);
			val.anchorMax = new Vector2(0.5f, 0f);
			val.pivot = new Vector2(0.5f, 0f);
			val.anchoredPosition = new Vector2(0f, 200f);
			GameObject val2 = new GameObject("NotificationBackground");
			val2.transform.SetParent(((Component)this).transform, false);
			background = val2.AddComponent<Image>();
			((Graphic)background).color = new Color(0f, 0f, 0f, 0f);
			RectTransform component = val2.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0.5f, 0.5f);
			component.anchorMax = new Vector2(0.5f, 0.5f);
			component.pivot = new Vector2(0.5f, 0.5f);
			GameObject val3 = new GameObject("NotificationText");
			val3.transform.SetParent(val2.transform, false);
			text = val3.AddComponent<TextMeshProUGUI>();
			TMP_FontAsset font = ((IEnumerable<TMP_FontAsset>)Resources.FindObjectsOfTypeAll<TMP_FontAsset>()).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => ((Object)f).name == "DarumaDropOne-Regular SDF"));
			Material fontSharedMaterial = ((IEnumerable<Material>)Resources.FindObjectsOfTypeAll<Material>()).FirstOrDefault((Func<Material, bool>)((Material m) => ((Object)m).name == "DarumaDropOne-Regular SDF Outline"));
			((TMP_Text)text).font = font;
			((TMP_Text)text).fontSharedMaterial = fontSharedMaterial;
			((TMP_Text)text).fontSize = fontSize;
			((TMP_Text)text).alignment = (TextAlignmentOptions)514;
			((TMP_Text)text).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)text).enableVertexGradient = true;
			((TMP_Text)text).colorGradient = new VertexGradient(Color.white);
			Shadow val4 = ((Component)text).gameObject.AddComponent<Shadow>();
			val4.effectColor = new Color(0f, 0f, 0f, 0.8f);
			val4.effectDistance = new Vector2(2f, -2f);
			RectTransform component2 = ((Component)text).GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(0.5f, 0.5f);
			component2.anchorMax = new Vector2(0.5f, 0.5f);
			component2.pivot = new Vector2(0.5f, 0.5f);
			canvasGroup.alpha = 0f;
		}

		public void SetText(string message)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			((TMP_Text)text).text = message;
			((TMP_Text)text).ForceMeshUpdate(false, false);
			Vector2 renderedValues = ((TMP_Text)text).GetRenderedValues(false);
			float num = 30f;
			RectTransform rectTransform = ((Graphic)background).rectTransform;
			rectTransform.sizeDelta = renderedValues + new Vector2(num, num);
			RectTransform rectTransform2 = ((TMP_Text)text).rectTransform;
			rectTransform2.sizeDelta = renderedValues;
			canvasGroup.alpha = 1f;
			timer = fadeDelay;
		}

		private void Update()
		{
			if (!(canvasGroup.alpha <= 0f))
			{
				timer -= Time.deltaTime;
				if (timer <= 0f)
				{
					canvasGroup.alpha = Mathf.Lerp(canvasGroup.alpha, 0f, Time.deltaTime * 5f);
				}
			}
		}
	}
	[BepInPlugin("com.github.glarmer.CarryRestraint", "CarryRestraint", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		public const string Id = "com.github.glarmer.CarryRestraint";

		internal static ManualLogSource Log { get; private set; }

		public static string Name => "CarryRestraint";

		public static string Version => "1.0.0";

		private void Awake()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("com.github.glarmer.CarryRestraint");
			_harmony.PatchAll(typeof(CharacterCarryingStartCarryPatch));
			_harmony.PatchAll(typeof(GUIManagerStartPatch));
			_harmony.PatchAll(typeof(GUIManagerRefreshInteractablePromptPatch));
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
		}
	}
}
namespace CarryRestraint.Patches
{
	public class CharacterCarryingStartCarryPatch
	{
		[HarmonyPatch(typeof(CharacterCarrying), "StartCarry")]
		[HarmonyPrefix]
		private static bool Prefix(Character target)
		{
			if (!target.data._cannibalismPermitted)
			{
				Plugin.Log.LogInfo((object)("[Carry Patch]: " + ((Object)target).name + " has cannibalism disabled... Displaying notification"));
				Notification.instance.SetText(target.characterName + " cannot be carried!");
				return false;
			}
			return true;
		}
	}
	public class GUIManagerRefreshInteractablePromptPatch
	{
		[HarmonyPatch(typeof(GUIManager), "RefreshInteractablePrompt")]
		[HarmonyPostfix]
		private static void Postfix(GUIManager __instance)
		{
			IInteractible currentInteractable = __instance.currentInteractable;
			CharacterInteractible val = (CharacterInteractible)(object)((currentInteractable is CharacterInteractible) ? currentInteractable : null);
			if (val != null)
			{
				Character character = val.character;
				string interactionText = __instance.currentInteractable.GetInteractionText();
				if (!character.data._cannibalismPermitted && interactionText.ToLower().Contains("carry"))
				{
					TextMeshProUGUI interactPromptText = __instance.interactPromptText;
					((TMP_Text)interactPromptText).richText = true;
					((TMP_Text)interactPromptText).text = "<s>" + ((TMP_Text)interactPromptText).text + "</s>";
				}
			}
		}
	}
	public class GUIManagerStartPatch
	{
		[HarmonyPatch(typeof(GUIManager), "Start")]
		[HarmonyPostfix]
		private static void Postfix()
		{
			Plugin.Log.LogInfo((object)"[GUIManagerStartPatch] Starting Notification System...");
			Notification.Create().SetText("Hopefully this test is enough to work!");
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}