Decompiled source of Holy Energy Drinks v1.0.2

HolyEnergyDrinks.dll

Decompiled 10 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using GameNetcodeStuff;
using HarmonyLib;
using HolyEnergyDrinks.NetcodePatcher;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Netcode;
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 = "")]
[assembly: AssemblyCompany("HolyEnergyDrinks")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HolyEnergyDrinks")]
[assembly: AssemblyTitle("HolyEnergyDrinks")]
[assembly: AssemblyVersion("1.0.0.0")]
[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;
		}
	}
}
namespace HolyEnergyDrinks
{
	public class HolyEnergyItem : GrabbableObject
	{
		private bool hasUsedEnergy;

		public AudioSource useAudioSource;

		public AudioClip useAudioClip;

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (!((Object)(object)base.playerHeldBy == (Object)null) && !hasUsedEnergy && !((Behaviour)Plugin.buffUI).enabled)
			{
				hasUsedEnergy = true;
				base.playerHeldBy.activatingItem = true;
				((MonoBehaviour)this).StartCoroutine(Plugin.Instance.TempMoveSpeedBuff(base.playerHeldBy));
				UseHolyEnergyServerRpc();
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void UseHolyEnergyServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(3289458157u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3289458157u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					UseHolyEnergyClientRpc();
				}
			}
		}

		[ClientRpc]
		public void UseHolyEnergyClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3909161986u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3909161986u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				useAudioSource.PlayOneShot(useAudioClip);
				WalkieTalkie.TransmitOneShotAudio(useAudioSource, useAudioClip, 1f);
				RoundManager.Instance.PlayAudibleNoise(((Component)useAudioSource).transform.position, 8f, 0.5f, 0, base.isInShipRoom && StartOfRound.Instance.hangarDoorsClosed, 0);
				if ((Object)(object)base.playerHeldBy != (Object)null)
				{
					base.playerHeldBy.activatingItem = false;
					((GrabbableObject)this).DestroyObjectInHand(base.playerHeldBy);
				}
			}
		}

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

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_HolyEnergyItem()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(3289458157u, new RpcReceiveHandler(__rpc_handler_3289458157));
			NetworkManager.__rpc_func_table.Add(3909161986u, new RpcReceiveHandler(__rpc_handler_3909161986));
		}

		private static void __rpc_handler_3289458157(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((HolyEnergyItem)(object)target).UseHolyEnergyServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3909161986(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((HolyEnergyItem)(object)target).UseHolyEnergyClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "HolyEnergyItem";
		}
	}
	[BepInPlugin("TheBonBon.HolyEnergyDrinks", "Holy Energy Drinks", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(HUDManager))]
		internal class HUDManagerPatch
		{
			[HarmonyPostfix]
			[HarmonyPatch("Start")]
			private static void StartPatch(ref HUDManager __instance)
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Expected O, but got Unknown
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				GameObject val = GameObject.Find("Systems/UI/Canvas/IngamePlayerHUD/HandsFullText");
				GameObject val2 = new GameObject("BuffIcon");
				val2.transform.SetParent(val.transform, false);
				buffUI = val2.AddComponent<TextMeshProUGUI>();
				((TMP_Text)buffUI).font = ((TMP_Text)__instance.controlTipLines[0]).font;
				((TMP_Text)buffUI).fontSize = 8f;
				((Behaviour)buffUI).enabled = false;
				((Graphic)buffUI).color = Color.white;
				((TMP_Text)buffUI).alignment = (TextAlignmentOptions)514;
				val2.GetComponent<RectTransform>().anchoredPosition = new Vector2(0f, -35f);
			}
		}

		private const string modGUID = "TheBonBon.HolyEnergyDrinks";

		private const string modName = "Holy Energy Drinks";

		private const string modVersion = "1.0.0";

		public static Plugin Instance;

		public static TextMeshProUGUI buffUI;

		private void Awake()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			NetcodeWeaver();
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "holyenergydrinks");
			AssetBundle val = AssetBundle.LoadFromFile(text);
			Harmony val2 = new Harmony("TheBonBon.HolyEnergyDrinks");
			val2.PatchAll();
			List<string> list = new List<string>
			{
				"Assets/Items/Hydration/HolyHydrationKiwi.asset", "Assets/Items/Hydration/HolyHydrationGrapefruit.asset", "Assets/Items/Hydration/HolyHydrationPeach.asset", "Assets/Items/Ice/HolyIceRaspberryVanilla.asset", "Assets/Items/Ice/HolyIcePeachNectarine.asset", "Assets/Items/Ice/HolyIceLimeMint.asset", "Assets/Items/Energy/HolyEnergyShark.asset", "Assets/Items/Energy/HolyEnergyBear.asset", "Assets/Items/Energy/HolyEnergyWolf.asset", "Assets/Items/Energy/HolyEnergyCheetah.asset",
				"Assets/Items/Energy/HolyEnergyCobra.asset", "Assets/Items/Energy/HolyEnergyRaptor.asset", "Assets/Items/Shaker/HolyShakerEnergyCobra.asset", "Assets/Items/Shaker/HolyShakerEnergyCheetah.asset", "Assets/Items/Shaker/HolyShakerEnergyWolf.asset", "Assets/Items/Shaker/HolyShakerEnergyShark.asset", "Assets/Items/Shaker/HolyShakerEnergyRaptor.asset", "Assets/Items/Shaker/HolyShakerEnergyBear.asset"
			};
			foreach (string item in list)
			{
				Item val3 = val.LoadAsset<Item>(item);
				NetworkPrefabs.RegisterNetworkPrefab(val3.spawnPrefab);
				Items.RegisterScrap(val3, 40, (LevelTypes)(-1));
			}
			LogIt("Plugin TheBonBon.HolyEnergyDrinks is loaded!");
		}

		public void LogIt(string text)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)text);
		}

		public IEnumerator TempMoveSpeedBuff(PlayerControllerB player)
		{
			((Behaviour)buffUI).enabled = true;
			float normalSpeed = player.movementSpeed;
			player.movementSpeed *= 2f;
			for (float buffTime = 180f; buffTime > 0f; buffTime -= 1f)
			{
				((TMP_Text)buffUI).text = "Speed Buff: " + Mathf.CeilToInt(buffTime);
				yield return (object)new WaitForSeconds(1f);
			}
			player.movementSpeed = normalSpeed;
			((Behaviour)buffUI).enabled = false;
		}

		private static void NetcodeWeaver()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}
	}
}
namespace HolyEnergyDrinks.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}