Decompiled source of HealthyCompany v0.1.1

plugins/CoddingCat.MedkitItem/CoddingCat.MedkitItem.dll

Decompiled 15 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CSync.Extensions;
using CSync.Lib;
using CoddingCat.MedkitItem.NetcodePatcher;
using GameNetcodeStuff;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CoddingCat.MedkitItem")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MedkitItem")]
[assembly: AssemblyTitle("CoddingCat.MedkitItem")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
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;
		}
	}
}
internal class MyModConfig : SyncedConfig2<MyModConfig>
{
	[SyncedEntryField]
	public readonly SyncedEntry<int> config;

	[SyncedEntryField]
	public readonly SyncedEntry<int> config2;

	[SyncedEntryField]
	public readonly SyncedEntry<float> config3;

	[SyncedEntryField]
	public readonly SyncedEntry<int> config4;

	public MyModConfig(ConfigFile cfg)
		: base("CoddingCat.MedkitItem")
	{
		config = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "General Medkit", "Price", 150, "A Price for a single medkit (Default : 150, Perfectly balanced)");
		config2 = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "General Medkit", "Spawnable / Rarity", 0, "Chance of making medkit spawnable inside the building. (Default 0 means that it doesn't spawn inside facility)");
		config3 = SyncedBindingExtensions.BindSyncedEntry<float>(cfg, "General Medkit", "Max Uses", 3f, "Max uses that medkit has (default : 3f)");
		config4 = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "General Medkit", "Health Regeneration", 30, "Max Regeneration Per use (default : 30)");
		ConfigManager.Register<MyModConfig>((SyncedConfig2<MyModConfig>)(object)this);
	}
}
namespace MedkitItem
{
	[BepInPlugin("CoddingCat.MedkitItem", "MedkitItem", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency("com.sigurd.csync", "5.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		public static AssetBundle? ModAssets;

		internal static MyModConfig BoundConfig { get; private set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			BoundConfig = new MyModConfig(((BaseUnityPlugin)this).Config);
			string path = "modassets";
			ModAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), path));
			if ((Object)(object)ModAssets == (Object)null)
			{
				Logger.LogError((object)"Failed to load custom assets.");
				return;
			}
			int value = BoundConfig.config2.Value;
			Item MyCustomItem = ModAssets.LoadAsset<Item>("Medkit");
			Utilities.FixMixerGroups(MyCustomItem.spawnPrefab);
			NetworkPrefabs.RegisterNetworkPrefab(MyCustomItem.spawnPrefab);
			Items.RegisterScrap(MyCustomItem, value, (LevelTypes)(-1));
			TerminalNode val = ModAssets.LoadAsset<TerminalNode>("MeTerminalNode");
			Items.RegisterShopItem(MyCustomItem, (TerminalNode)null, (TerminalNode)null, val, BoundConfig.config.Value);
			BoundConfig.config.Changed += delegate(object sender, SyncedSettingChangedEventArgs<int> args)
			{
				Logger.LogInfo((object)$"Price updated, new value is {args.NewValue}");
				MyCustomItem.creditsWorth = args.NewValue;
			};
			Logger.LogInfo((object)"Plugin CoddingCat.MedkitItem is loaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "CoddingCat.MedkitItem";

		public const string PLUGIN_NAME = "MedkitItem";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace MedkitItem.MonoBehaviours
{
	public class Medkit : PhysicsProp
	{
		public bool isFiring = false;

		public float reloadTime = 2f;

		private float timer = 0f;

		private float maxUses = Plugin.BoundConfig.config3.Value;

		private const float holdDuration = 8.6f;

		public float slowMovementSpeed = 0.5f;

		public float originalMovementSpeed = 1f;

		public AudioClip[] audios;

		public AudioSource audioSource;

		public Sprite thingie;

		private static GameObject _timerObject;

		public Sprite whiteSquareSprite;

		private static GameObject whiteSquare;

		public Sprite fullScreenSprite;

		private GameObject fullScreenImage;

		private static PlayerControllerB lastplayerHolded;

		private float alpha = 0f;

		private float alphaLerpSpeed = 2f;

		public override void Start()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: 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_011d: Expected O, but got Unknown
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).Start();
			GameObject val = GameObject.Find("/Systems/UI/Canvas/IngamePlayerHUD/OpenEyes");
			_timerObject = Object.Instantiate<GameObject>(val.gameObject, val.transform.parent, false);
			if ((Object)(object)whiteSquare == (Object)null)
			{
				whiteSquare = new GameObject("WhiteSquare");
				whiteSquare.transform.SetParent(val.transform.parent, false);
				Image val2 = whiteSquare.AddComponent<Image>();
				val2.sprite = whiteSquareSprite;
				RectTransform component = whiteSquare.GetComponent<RectTransform>();
				component.sizeDelta = new Vector2(75f, 75f);
				component.anchoredPosition = new Vector2(350f, -200f);
				whiteSquare.GetComponent<Image>().type = (Type)3;
				((Graphic)whiteSquare.GetComponent<Image>()).color = new Color(1f, 1f, 1f, 0f);
			}
			if ((Object)(object)fullScreenImage == (Object)null)
			{
				fullScreenImage = new GameObject("FullScreenImage");
				fullScreenImage.transform.SetParent(val.transform.parent, false);
				Image val3 = fullScreenImage.AddComponent<Image>();
				val3.sprite = fullScreenSprite;
				RectTransform component2 = fullScreenImage.GetComponent<RectTransform>();
				component2.anchorMin = new Vector2(0f, 0f);
				component2.anchorMax = new Vector2(1f, 1f);
				component2.offsetMin = new Vector2(0f, 0f);
				component2.offsetMax = new Vector2(0f, 0f);
				fullScreenImage.SetActive(false);
			}
		}

		public override void Update()
		{
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).Update();
			if ((Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null && ((GrabbableObject)this).playerHeldBy.health < 100 && isFiring)
			{
				timer += Time.deltaTime;
				((GrabbableObject)this).playerHeldBy.movementSpeed = slowMovementSpeed;
				Debug.Log((object)$"Healing in progress... Timer: {timer}, Player Speed: {((GrabbableObject)this).playerHeldBy.movementSpeed}");
				if ((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)(object)((GrabbableObject)this).playerHeldBy)
				{
					whiteSquare.SetActive(true);
					whiteSquare.GetComponent<Image>().fillAmount = Mathf.Lerp(1f, 0f, timer / 8.6f);
					((Graphic)whiteSquare.GetComponent<Image>()).color = new Color(1f, 1f, 1f, Mathf.Lerp(((Graphic)whiteSquare.GetComponent<Image>()).color.a, 1f, Time.deltaTime * alphaLerpSpeed));
				}
				if (timer >= 8.6f)
				{
					PlayerControllerB playerHeldBy = ((GrabbableObject)this).playerHeldBy;
					playerHeldBy.health += Plugin.BoundConfig.config4.Value;
					maxUses -= 1f;
					if (maxUses == 0f)
					{
						((GrabbableObject)this).deactivated = true;
					}
					((GrabbableObject)this).playerHeldBy.health = Mathf.Clamp(((GrabbableObject)this).playerHeldBy.health, -200, 100);
					HUDManager.Instance.UpdateHealthUI(((GrabbableObject)this).playerHeldBy.health, false);
					isFiring = false;
					ResetTimerAndSpeed();
					((GrabbableObject)this).customGrabTooltip = "Grab : [E] (USES LEFT " + maxUses + " )";
					audioSource.Stop();
					audioSource.PlayOneShot(audios[2]);
					((GrabbableObject)this).playerHeldBy.RemoveBloodFromBody();
					if ((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)(object)((GrabbableObject)this).playerHeldBy)
					{
						whiteSquare.GetComponent<Image>().fillAmount = 1f;
					}
				}
			}
			else if ((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)(object)((GrabbableObject)this).playerHeldBy)
			{
				((Graphic)whiteSquare.GetComponent<Image>()).color = new Color(1f, 1f, 1f, Mathf.Lerp(((Graphic)whiteSquare.GetComponent<Image>()).color.a, 0f, Time.deltaTime * alphaLerpSpeed));
			}
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (maxUses != 0f && (((Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null && ((GrabbableObject)this).playerHeldBy.health == 100) || ((GrabbableObject)this).deactivated) && buttonDown)
			{
				audioSource.PlayOneShot(audios[1]);
			}
			if (!((Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null) || ((GrabbableObject)this).playerHeldBy.health >= 100 || ((GrabbableObject)this).deactivated)
			{
				return;
			}
			if (buttonDown)
			{
				if ((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)(object)((GrabbableObject)this).playerHeldBy && (Object)(object)whiteSquare != (Object)null)
				{
					whiteSquare.SetActive(true);
				}
				if (!isFiring)
				{
					originalMovementSpeed = ((GrabbableObject)this).playerHeldBy.movementSpeed;
				}
				isFiring = true;
				audioSource.clip = audios[0];
				audioSource.Play();
				lastplayerHolded = ((GrabbableObject)this).playerHeldBy;
				((GrabbableObject)this).playerHeldBy.activatingItem = true;
				Debug.Log((object)$"Medkit activated. Player Speed: {((GrabbableObject)this).playerHeldBy.movementSpeed}");
			}
			else
			{
				ResetTimerAndSpeed();
				isFiring = false;
				audioSource.Stop();
				((GrabbableObject)this).playerHeldBy.activatingItem = false;
				if ((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)(object)((GrabbableObject)this).playerHeldBy)
				{
					whiteSquare.GetComponent<Image>().fillAmount = 1f;
				}
				Debug.Log((object)"Medkit deactivated by button up.");
			}
		}

		private void ResetTimerAndSpeed()
		{
			timer = 0f;
			if ((Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null)
			{
				((GrabbableObject)this).playerHeldBy.activatingItem = false;
				((GrabbableObject)this).playerHeldBy.movementSpeed = originalMovementSpeed;
				Debug.Log((object)$"Resetting Player Speed to {originalMovementSpeed}");
				isFiring = false;
			}
		}

		public override void EquipItem()
		{
			((PhysicsProp)this).EquipItem();
			originalMovementSpeed = ((GrabbableObject)this).playerHeldBy.movementSpeed;
		}

		public override void DiscardItem()
		{
			ResetTimerAndSpeed();
			audioSource.Stop();
			((GrabbableObject)this).DiscardItem();
		}

		protected override void __initializeVariables()
		{
			((PhysicsProp)this).__initializeVariables();
		}

		protected internal override string __getTypeName()
		{
			return "Medkit";
		}
	}
}
namespace MedkitItem.Configuration
{
	public class PluginConfig
	{
		private void ClearUnusedEntries(ConfigFile cfg)
		{
			PropertyInfo property = ((object)cfg).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic);
			Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)property.GetValue(cfg, null);
			dictionary.Clear();
			cfg.Save();
		}
	}
}
namespace CoddingCat.MedkitItem.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}