Decompiled source of CheeseHealthPacks v1.0.0

CheeseHealthPacks.dll

Decompiled a month ago
using System;
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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Autodesk.Fbx")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("FbxBuildTestAssets")]
[assembly: IgnoresAccessChecksTo("Klattersynth")]
[assembly: IgnoresAccessChecksTo("Photon3Unity3D")]
[assembly: IgnoresAccessChecksTo("PhotonChat")]
[assembly: IgnoresAccessChecksTo("PhotonRealtime")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking.Utilities")]
[assembly: IgnoresAccessChecksTo("PhotonVoice.API")]
[assembly: IgnoresAccessChecksTo("PhotonVoice")]
[assembly: IgnoresAccessChecksTo("PhotonVoice.PUN")]
[assembly: IgnoresAccessChecksTo("SingularityGroup.HotReload.Runtime")]
[assembly: IgnoresAccessChecksTo("SingularityGroup.HotReload.Runtime.Public")]
[assembly: IgnoresAccessChecksTo("Sirenix.OdinInspector.Attributes")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization.Config")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization")]
[assembly: IgnoresAccessChecksTo("Sirenix.Utilities")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Formats.Fbx.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Postprocessing.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Antlr3.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Core")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Flow")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.State")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: IgnoresAccessChecksTo("websocket-sharp")]
[assembly: AssemblyCompany("NoSpawnn")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+fe8b9ebb118abe10865c11eccd6fcc2d6f4251cb")]
[assembly: AssemblyProduct("CheeseHealthPacks")]
[assembly: AssemblyTitle("CheeseHealthPacks")]
[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 CheeseHealthPacks
{
	[BepInPlugin("NoSpawnn.CheeseHealthPacks", "CheeseHealthPacks", "1.0")]
	public class CheeseHealthPacks : BaseUnityPlugin
	{
		private static Mesh _cheesePackMeshSmall = null;

		private static Mesh _cheesePackMeshMedium = null;

		private static Mesh _cheesePackMeshLarge = null;

		private static Material _cheeseMaterial = null;

		private static readonly Quaternion _meshRot = Quaternion.Euler(-90f, 0f, 0f);

		private static readonly Vector3 _colliderSizeLarge = new Vector3(1.29f, 0.61f, 2.23f);

		private static readonly Vector3 _meshPosLarge = new Vector3(0f, 0.15f, 0f);

		private static readonly Vector3 _meshScaleLarge = new Vector3(26f, 26f, 26f);

		private static readonly Vector3 _colliderSizeMedium = new Vector3(0.56f, 0.57f, 1.53f);

		private static readonly Vector3 _colliderCenterMedium = new Vector3(0f, -0.04f, 0.12f);

		private static readonly Vector3 _meshPosMedium = new Vector3(0f, 0.111f, -0.052f);

		private static readonly Vector3 _meshScaleMedium = new Vector3(15f, 15f, 15f);

		private static readonly Vector3 _colliderSizeSmall = new Vector3(0.92f, 0.15f, 1.6f);

		private static readonly Vector3 _meshPosSmall = new Vector3(0f, 0.11f, 0f);

		private static readonly Vector3 _meshScaleSmall = new Vector3(13f, 13f, 13f);

		internal static CheeseHealthPacks Instance { get; private set; } = null;


		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
			string text = "assets";
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), text));
			if (val == null)
			{
				Logger.LogError((object)("Failed to load asset bundle '" + text + "'"));
				return;
			}
			string text2 = "small";
			GameObject val2 = val.LoadAsset<GameObject>(text2);
			if (val2 == null)
			{
				Logger.LogError((object)("Failed to load small asset ('" + text2 + "')"));
				return;
			}
			_cheesePackMeshSmall = val2.GetComponentInChildren<MeshFilter>().mesh;
			string text3 = "medium";
			GameObject val3 = val.LoadAsset<GameObject>(text3);
			if (val3 == null)
			{
				Logger.LogError((object)("Failed to load medium asset ('" + text3 + "')"));
				return;
			}
			_cheesePackMeshMedium = val3.GetComponentInChildren<MeshFilter>().mesh;
			string text4 = "large";
			GameObject val4 = val.LoadAsset<GameObject>(text4);
			if (val4 == null)
			{
				Logger.LogError((object)("Failed to load large asset ('" + text4 + "')"));
				return;
			}
			_cheesePackMeshLarge = val4.GetComponentInChildren<MeshFilter>().mesh;
			_cheeseMaterial = ((Renderer)val4.GetComponentInChildren<MeshRenderer>()).sharedMaterial;
			if (_cheeseMaterial == null)
			{
				Logger.LogError((object)"Failed to load cheese material");
			}
			else
			{
				Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
			}
		}

		internal void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		public void PatchMeshFor(ItemHealthPack healthPack)
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: 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_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Component)healthPack).transform.Find("Mesh");
			if (val == null)
			{
				Logger.LogError((object)"Could not find mesh in tree, is this a custom health pack?");
				return;
			}
			BoxCollider component = ((Component)((Component)healthPack).transform.Find("Semi Box Collider")).GetComponent<BoxCollider>();
			if (component == null)
			{
				Logger.LogError((object)"Could not find box collider in tree, is this a custom health pack?");
				return;
			}
			MeshFilter component2 = ((Component)val).GetComponent<MeshFilter>();
			MeshRenderer component3 = ((Component)val).GetComponent<MeshRenderer>();
			((Component)component2).transform.rotation = _meshRot;
			((Renderer)component3).material = _cheeseMaterial;
			if (healthPack.healAmount == 100)
			{
				((Component)val).transform.localScale = _meshScaleLarge;
				((Component)val).transform.localPosition = _meshPosLarge;
				component2.mesh = _cheesePackMeshLarge;
				component.size = _colliderSizeLarge;
			}
			else if (healthPack.healAmount == 50)
			{
				((Component)val).transform.localScale = _meshScaleMedium;
				((Component)val).transform.localPosition = _meshPosMedium;
				component2.mesh = _cheesePackMeshMedium;
				component.center = _colliderCenterMedium;
				component.size = _colliderSizeMedium;
			}
			else if (healthPack.healAmount == 25)
			{
				((Component)val).transform.localScale = _meshScaleSmall;
				((Component)val).transform.localPosition = _meshPosSmall;
				component2.mesh = _cheesePackMeshSmall;
				component.size = _colliderSizeSmall;
			}
		}
	}
	[HarmonyPatch(typeof(ItemHealthPack))]
	public class PatchHealthPackMesh
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		public static void Postfix(ItemHealthPack __instance)
		{
			if (__instance == null)
			{
				CheeseHealthPacks.Logger.LogError((object)"ItemHealthPack instance is null");
			}
			else
			{
				CheeseHealthPacks.Instance.PatchMeshFor(__instance);
			}
		}
	}
}