Decompiled source of Knife Item v0.0.1

Knife.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PEAKLib.Core;
using PEAKLib.Items.UnityEditor;
using Peak.Afflictions;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Knife")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Knife")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("67d4785d-c610-41cd-99f4-1c5e99f24ee7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
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 Knife_Gun
{
	public class Action_Ammo : ItemAction
	{
		public bool consumeOnFullyUsed;

		[PunRPC]
		public void ReduceUsesRPC()
		{
			OptionableIntItemData data = ((ItemActionBase)this).item.GetData<OptionableIntItemData>((DataEntryKey)2);
			if (data.HasData && data.Value > 0)
			{
				data.Value--;
				if (((ItemActionBase)this).item.totalUses > 0)
				{
					((ItemActionBase)this).item.SetUseRemainingPercentage((float)data.Value / (float)((ItemActionBase)this).item.totalUses);
				}
				if (data.Value == 0 && consumeOnFullyUsed && Object.op_Implicit((Object)(object)((ItemActionBase)this).character) && ((ItemActionBase)this).character.IsLocal && (Object)(object)((ItemActionBase)this).character.data.currentItem == (Object)(object)((ItemActionBase)this).item)
				{
					((MonoBehaviour)((ItemActionBase)this).item).StartCoroutine(((ItemActionBase)this).item.ConsumeDelayed(false));
				}
			}
		}
	}
	public class Action_Gun : ItemAction
	{
		public GameObject shotSFXPrefab;

		private static AudioSource cachedReferenceSfx;

		public float maxDistance;

		public float dartCollisionSize;

		[SerializeReference]
		public Affliction[] afflictionsOnHit;

		public Transform spawnTransform;

		public GameObject dartVFX;

		public float fireRate = 0.15f;

		public Action OnShoot;

		private RaycastHit lineHit;

		private RaycastHit[] sphereHits;

		private RaycastHit[] itemSphereHits;

		private float lastShootTime;

		private Item lastHitItem;

		private Vector3 originalDefaultPos;

		public override void RunAction()
		{
			if (!(Time.time <= lastShootTime + fireRate))
			{
				lastShootTime = Time.time;
				FireGun();
			}
		}

		private AudioSource FindReferenceSfx()
		{
			if ((Object)(object)cachedReferenceSfx != (Object)null)
			{
				return cachedReferenceSfx;
			}
			AudioSource[] array = Object.FindObjectsByType<AudioSource>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			AudioSource[] array2 = array;
			foreach (AudioSource val in array2)
			{
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val.outputAudioMixerGroup == (Object)null))
				{
					string name = ((Object)val.outputAudioMixerGroup).name;
					if (name == "SFX" || name == "Effects")
					{
						cachedReferenceSfx = val;
						return cachedReferenceSfx;
					}
				}
			}
			AudioSource[] array3 = array;
			foreach (AudioSource val2 in array3)
			{
				if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.outputAudioMixerGroup == (Object)null))
				{
					cachedReferenceSfx = val2;
					return cachedReferenceSfx;
				}
			}
			return null;
		}

		private void PlayKnifeSfx()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)shotSFXPrefab == (Object)null || (Object)(object)spawnTransform == (Object)null)
			{
				return;
			}
			GameObject val = Object.Instantiate<GameObject>(shotSFXPrefab, spawnTransform.position, Quaternion.identity);
			AudioSource component = val.GetComponent<AudioSource>();
			if ((Object)(object)component == (Object)null || (Object)(object)component.clip == (Object)null)
			{
				Object.Destroy((Object)(object)val, 2f);
				return;
			}
			AudioSource val2 = FindReferenceSfx();
			if ((Object)(object)val2 != (Object)null)
			{
				component.outputAudioMixerGroup = val2.outputAudioMixerGroup;
			}
			component.playOnAwake = false;
			component.mute = false;
			component.volume = 1f;
			component.pitch = 1f;
			component.spatialBlend = 1f;
			component.rolloffMode = (AudioRolloffMode)0;
			component.minDistance = 2f;
			component.maxDistance = 80f;
			component.dopplerLevel = 0f;
			component.priority = 128;
			component.Play();
			Object.Destroy((Object)(object)val, Mathf.Max(component.clip.length + 0.5f, 2f));
		}

		protected override void Start()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			((ItemActionBase)this).Start();
			if ((Object)(object)((ItemActionBase)this).item != (Object)null)
			{
				originalDefaultPos = ((ItemActionBase)this).item.defaultPos;
			}
		}

		private void OnDrawGizmosSelected()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)spawnTransform == (Object)null))
			{
				Gizmos.color = Color.red;
				Gizmos.DrawWireSphere(spawnTransform.position, dartCollisionSize);
			}
		}

		private void FireGun()
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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_00f6: 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_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)((ItemActionBase)this).item == (Object)null || (Object)(object)((MonoBehaviourPun)((ItemActionBase)this).item).photonView == (Object)null || (Object)(object)spawnTransform == (Object)null)
			{
				return;
			}
			((MonoBehaviourPun)((ItemActionBase)this).item).photonView.RPC("ReduceUsesRPC", (RpcTarget)0, Array.Empty<object>());
			OnShoot?.Invoke();
			PlayKnifeSfx();
			Physics.Raycast(spawnTransform.position, ((Component)MainCamera.instance).transform.forward, ref lineHit, maxDistance, LayerMask.op_Implicit(HelperFunctions.terrainMapMask), (QueryTriggerInteraction)1);
			if (!Object.op_Implicit((Object)(object)((RaycastHit)(ref lineHit)).collider))
			{
				((RaycastHit)(ref lineHit)).distance = maxDistance;
				((RaycastHit)(ref lineHit)).point = spawnTransform.position + ((Component)MainCamera.instance).transform.forward * maxDistance;
			}
			sphereHits = Physics.SphereCastAll(spawnTransform.position, dartCollisionSize, ((Component)MainCamera.instance).transform.forward, ((RaycastHit)(ref lineHit)).distance, LayerMask.GetMask(new string[1] { "Character" }), (QueryTriggerInteraction)1);
			RaycastHit[] array = sphereHits;
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit val = array[i];
				if (!((Object)(object)((RaycastHit)(ref val)).collider == (Object)null))
				{
					Character componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Character>();
					if ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent != (Object)(object)((ItemActionBase)this).character)
					{
						GunImpact(componentInParent, spawnTransform.position, ((RaycastHit)(ref val)).point);
						return;
					}
				}
			}
			GunImpact(null, spawnTransform.position, ((RaycastHit)(ref lineHit)).point);
			itemSphereHits = Physics.SphereCastAll(spawnTransform.position, dartCollisionSize, ((Component)MainCamera.instance).transform.forward, ((RaycastHit)(ref lineHit)).distance, LayerMask.GetMask(new string[1] { "Default" }), (QueryTriggerInteraction)1);
			RaycastHit[] array2 = itemSphereHits;
			for (int j = 0; j < array2.Length; j++)
			{
				RaycastHit val2 = array2[j];
				if (!((Object)(object)((RaycastHit)(ref val2)).collider == (Object)null))
				{
					Item componentInParent2 = ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<Item>();
					if ((Object)(object)componentInParent2 != (Object)null && (Object)(object)componentInParent2 != (Object)(object)((Component)this).GetComponentInParent<Item>())
					{
						GunItemImpact(componentInParent2, spawnTransform.position, ((RaycastHit)(ref val2)).point);
						break;
					}
				}
			}
		}

		private void GunImpact(Character hitCharacter, Vector3 origin, Vector3 endpoint)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)hitCharacter != (Object)null && hitCharacter.isZombie)
			{
				Vector3 forward = ((Component)MainCamera.instance).transform.forward;
				((MonoBehaviourPun)hitCharacter).photonView.RPC("RPC_ShootSelfT", (RpcTarget)0, new object[3]
				{
					0.25f,
					((MonoBehaviourPun)hitCharacter).photonView.ViewID,
					-(forward * 2f)
				});
			}
			else if ((Object)(object)hitCharacter != (Object)null)
			{
				((MonoBehaviourPun)this).photonView.RPC("RPC_GunImpact", (RpcTarget)0, new object[4]
				{
					((MonoBehaviourPun)hitCharacter).photonView.Owner,
					origin,
					endpoint,
					((Component)MainCamera.instance).transform.forward
				});
			}
			else
			{
				((MonoBehaviourPun)this).photonView.RPC("RPC_GunImpact", (RpcTarget)0, new object[4]
				{
					null,
					origin,
					endpoint,
					((Component)MainCamera.instance).transform.forward
				});
			}
		}

		private void GunItemImpact(Item hitItem, Vector3 origin, Vector3 endpoint)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			lastHitItem = hitItem;
			((MonoBehaviourPun)this).photonView.RPC("RPC_GunItemImpact", (RpcTarget)0, new object[3]
			{
				origin,
				endpoint,
				((Component)MainCamera.instance).transform.forward
			});
		}

		[PunRPC]
		private void RPC_GunImpact(Player hitPlayer, Vector3 origin, Vector3 endpoint, Vector3 direction)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			if (hitPlayer != null && PhotonNetwork.LocalPlayer != null && hitPlayer.ActorNumber == PhotonNetwork.LocalPlayer.ActorNumber)
			{
				((Component)Character.localCharacter).GetComponent<GunCharacterLaunch>().ShootSelfT(0.25f, Character.localCharacter, -(direction * 2f));
				if (afflictionsOnHit != null)
				{
					Affliction[] array = afflictionsOnHit;
					foreach (Affliction val in array)
					{
						Character.localCharacter.refs.afflictions.AddAffliction(val, false);
					}
				}
			}
			if ((Object)(object)GamefeelHandler.instance != (Object)null)
			{
				GamefeelHandler.instance.AddPerlinShakeProximity(endpoint, 5f, 0.2f, 15f, 10f);
			}
		}

		[PunRPC]
		private void RPC_GunItemImpact(Vector3 origin, Vector3 endpoint, Vector3 direction)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)lastHitItem != (Object)null)
			{
				((MonoBehaviourPun)lastHitItem).photonView.RPC("RPC_ShootSelfT", (RpcTarget)0, new object[2] { 0.1f, direction });
			}
			if ((Object)(object)GamefeelHandler.instance != (Object)null)
			{
				GamefeelHandler.instance.AddPerlinShakeProximity(endpoint, 5f, 0.2f, 15f, 10f);
			}
		}
	}
	public class KnifeVFX : ItemVFX
	{
		public ParticleSystem knifeParticles;

		private ParticleSystem[] allParticles;

		protected override void Start()
		{
			((ItemVFX)this).Start();
			CacheParticles();
			StopAllParticlesImmediate();
			Subscribe();
		}

		private void OnEnable()
		{
			CacheParticles();
			Subscribe();
		}

		private void OnDisable()
		{
			Unsubscribe();
		}

		private void CacheParticles()
		{
			if (allParticles == null || allParticles.Length == 0)
			{
				if ((Object)(object)knifeParticles == (Object)null)
				{
					knifeParticles = ((Component)this).GetComponentInChildren<ParticleSystem>(true);
				}
				allParticles = ((Component)this).GetComponentsInChildren<ParticleSystem>(true);
			}
		}

		private void StopAllParticlesImmediate()
		{
			if (allParticles == null)
			{
				return;
			}
			ParticleSystem[] array = allParticles;
			foreach (ParticleSystem val in array)
			{
				if (!((Object)(object)val == (Object)null))
				{
					val.Stop(true, (ParticleSystemStopBehavior)0);
				}
			}
		}

		private void Subscribe()
		{
			Action_Gun action_Gun = (((Object)(object)base.item != (Object)null) ? ((Component)base.item).GetComponent<Action_Gun>() : null);
			if ((Object)(object)action_Gun != (Object)null)
			{
				action_Gun.OnShoot = (Action)Delegate.Remove(action_Gun.OnShoot, new Action(RunAction));
				action_Gun.OnShoot = (Action)Delegate.Combine(action_Gun.OnShoot, new Action(RunAction));
			}
		}

		private void Unsubscribe()
		{
			Action_Gun action_Gun = (((Object)(object)base.item != (Object)null) ? ((Component)base.item).GetComponent<Action_Gun>() : null);
			if ((Object)(object)action_Gun != (Object)null)
			{
				action_Gun.OnShoot = (Action)Delegate.Remove(action_Gun.OnShoot, new Action(RunAction));
			}
		}

		public void RunAction()
		{
			CacheParticles();
			if (allParticles == null || allParticles.Length == 0)
			{
				return;
			}
			ParticleSystem[] array = allParticles;
			foreach (ParticleSystem val in array)
			{
				if (!((Object)(object)val == (Object)null))
				{
					((Component)val).gameObject.SetActive(true);
					val.Stop(true, (ParticleSystemStopBehavior)0);
					val.Play(true);
				}
			}
		}
	}
	public class KnifeVisualRuntime : MonoBehaviour
	{
		public Item item;

		private GameObject worldVisual;

		private Renderer[] worldRenderers;

		private float nextCharacterCollisionPatchTime;

		private void Awake()
		{
			item = ((Component)this).GetComponent<Item>();
			EnsureWorldVisual();
			PatchKnifeCharacterCollisions(force: true);
		}

		private void Start()
		{
			item = (((Object)(object)item != (Object)null) ? item : ((Component)this).GetComponent<Item>());
			EnsureWorldVisual();
			PatchKnifeCharacterCollisions(force: true);
		}

		private void OnEnable()
		{
			EnsureWorldVisual();
			PatchKnifeCharacterCollisions(force: true);
		}

		private void LateUpdate()
		{
			item = (((Object)(object)item != (Object)null) ? item : ((Component)this).GetComponent<Item>());
			HideDuplicateOriginalModelRenderers();
			EnsureWorldVisual();
			if ((Object)(object)worldVisual != (Object)null && !worldVisual.activeSelf)
			{
				worldVisual.SetActive(true);
			}
			ForceRenderers(worldRenderers);
			PatchKnifeCharacterCollisions(force: false);
		}

		private void EnsureWorldVisual()
		{
			if (!((Object)(object)worldVisual != (Object)null))
			{
				Transform val = FindOriginalKnifeVisualTransform();
				if (!((Object)(object)val == (Object)null))
				{
					worldVisual = ((Component)val).gameObject;
					worldVisual.SetActive(true);
					SanitizeOriginalVisualObject(worldVisual);
					worldRenderers = worldVisual.GetComponentsInChildren<Renderer>(true);
					RefreshShaders(worldRenderers);
					ForceRenderers(worldRenderers);
				}
			}
		}

		private void RefreshShaders(Renderer[] renderers)
		{
			if (renderers == null)
			{
				return;
			}
			Shader val = Shader.Find("Universal Render Pipeline/Lit");
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Standard");
			}
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			foreach (Renderer val2 in renderers)
			{
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				Material[] sharedMaterials = val2.sharedMaterials;
				if (sharedMaterials == null)
				{
					continue;
				}
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					if ((Object)(object)sharedMaterials[j] != (Object)null)
					{
						sharedMaterials[j].shader = val;
					}
				}
			}
		}

		private void PatchKnifeCharacterCollisions(bool force)
		{
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.DisableKnifeCharacterCollision || (!force && Time.time < nextCharacterCollisionPatchTime))
			{
				return;
			}
			nextCharacterCollisionPatchTime = Time.time + 0.25f;
			Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>(true);
			if (componentsInChildren == null || componentsInChildren.Length == 0)
			{
				return;
			}
			int num = 0;
			int num2 = LayerMask.NameToLayer("Character");
			int num3 = LayerMask.NameToLayer("Player");
			if (num2 >= 0)
			{
				num |= 1 << num2;
			}
			if (num3 >= 0)
			{
				num |= 1 << num3;
			}
			if (num != 0)
			{
				Collider[] array = componentsInChildren;
				foreach (Collider val in array)
				{
					if (!((Object)(object)val == (Object)null))
					{
						LayerMask excludeLayers = val.excludeLayers;
						((LayerMask)(ref excludeLayers)).value = ((LayerMask)(ref excludeLayers)).value | num;
						val.excludeLayers = excludeLayers;
					}
				}
			}
			Character[] array2 = Object.FindObjectsByType<Character>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			Character[] array3 = array2;
			foreach (Character val2 in array3)
			{
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				Collider[] componentsInChildren2 = ((Component)val2).GetComponentsInChildren<Collider>(true);
				if (componentsInChildren2 == null || componentsInChildren2.Length == 0)
				{
					continue;
				}
				Collider[] array4 = componentsInChildren;
				foreach (Collider val3 in array4)
				{
					if ((Object)(object)val3 == (Object)null)
					{
						continue;
					}
					Collider[] array5 = componentsInChildren2;
					foreach (Collider val4 in array5)
					{
						if (!((Object)(object)val4 == (Object)null) && !((Object)(object)val4 == (Object)(object)val3))
						{
							Physics.IgnoreCollision(val3, val4, true);
						}
					}
				}
			}
		}

		private Transform FindOriginalKnifeVisualTransform()
		{
			Transform val = ((Component)this).transform.Find("KnifeOBJ");
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(true);
			Transform[] array = componentsInChildren;
			foreach (Transform val2 in array)
			{
				if ((Object)(object)val2 != (Object)null && ((Object)val2).name == "KnifeOBJ")
				{
					return val2;
				}
			}
			Transform[] array2 = componentsInChildren;
			foreach (Transform val3 in array2)
			{
				if ((Object)(object)val3 != (Object)null && (((Object)val3).name.Contains("KnifeOBJ") || ((Object)val3).name.Contains("Knife_Model") || ((Object)val3).name.Contains("KnifeModel")) && !((Object)val3).name.Contains("Injected") && !((Object)val3).name.Contains("ModelInstance") && !((Object)val3).name.Contains("HeldCamera"))
				{
					return val3;
				}
			}
			return null;
		}

		private void SanitizeOriginalVisualObject(GameObject visual)
		{
			if ((Object)(object)visual == (Object)null)
			{
				return;
			}
			PhotonView[] componentsInChildren = visual.GetComponentsInChildren<PhotonView>(true);
			foreach (PhotonView val in componentsInChildren)
			{
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
			}
			Rigidbody[] componentsInChildren2 = visual.GetComponentsInChildren<Rigidbody>(true);
			foreach (Rigidbody val2 in componentsInChildren2)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					Object.Destroy((Object)(object)val2);
				}
			}
			Collider[] componentsInChildren3 = visual.GetComponentsInChildren<Collider>(true);
			foreach (Collider val3 in componentsInChildren3)
			{
				if ((Object)(object)val3 != (Object)null)
				{
					Object.Destroy((Object)(object)val3);
				}
			}
			int num = LayerMask.NameToLayer("Default");
			if (num >= 0)
			{
				SetLayerRecursively(visual, num);
			}
		}

		private void SetLayerRecursively(GameObject obj, int layer)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			if ((Object)(object)obj == (Object)null)
			{
				return;
			}
			obj.layer = layer;
			foreach (Transform item in obj.transform)
			{
				Transform val = item;
				SetLayerRecursively(((Component)val).gameObject, layer);
			}
		}

		private void HideDuplicateOriginalModelRenderers()
		{
			Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(true);
			Transform[] array = componentsInChildren;
			foreach (Transform val in array)
			{
				if (!((Object)(object)val == (Object)null))
				{
					string name = ((Object)val).name;
					if ((name == "Knife_InjectedVisual" || name == "Knife_ModelInstance" || name == "Knife_HeldCameraVisual") && (!((Object)(object)worldVisual != (Object)null) || !((Object)(object)val == (Object)(object)worldVisual.transform)))
					{
						((Component)val).gameObject.SetActive(false);
						Object.Destroy((Object)(object)((Component)val).gameObject);
					}
				}
			}
		}

		private void ForceRenderers(Renderer[] renderers)
		{
			if (renderers == null)
			{
				return;
			}
			foreach (Renderer val in renderers)
			{
				if (!((Object)(object)val == (Object)null))
				{
					((Component)val).gameObject.SetActive(true);
					val.enabled = true;
					val.forceRenderingOff = false;
					val.shadowCastingMode = (ShadowCastingMode)1;
					val.receiveShadows = true;
					val.allowOcclusionWhenDynamic = false;
					val.lightProbeUsage = (LightProbeUsage)0;
					val.reflectionProbeUsage = (ReflectionProbeUsage)0;
				}
			}
		}
	}
	public static class CharacterExtensions
	{
		public static void AddForce(this Character input, Vector3 move, float minRandomMultiplier, float maxRandomMultiplier, ForceMode forceMode = 5)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			foreach (Bodypart part in input.refs.ragdoll.partList)
			{
				Vector3 val = move;
				if (minRandomMultiplier != maxRandomMultiplier)
				{
					val *= Random.Range(minRandomMultiplier, maxRandomMultiplier);
				}
				part.AddForce(val, forceMode);
			}
		}
	}
	public class GunCharacterLaunch : MonoBehaviour
	{
		public float shotTime;

		private Character characterGettingShot;

		private Vector3 shotDirection;

		private void Start()
		{
			characterGettingShot = Character.localCharacter;
		}

		private void Update()
		{
			if (shotTime > 0f)
			{
				shotTime -= Time.deltaTime;
				UpdateShotPhysicsT();
			}
		}

		public void ShootSelfT(float howLongToFly, Character whoIsGettingShot, Vector3 whichDirectionShooting)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			shotTime = howLongToFly;
			characterGettingShot = whoIsGettingShot;
			shotDirection = whichDirectionShooting;
		}

		[PunRPC]
		public void RPC_ShootSelfT(float howLongToFly, int characterViewID, Vector3 whichDirectionShooting)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			PhotonView val = PhotonView.Find(characterViewID);
			if ((Object)(object)val != (Object)null)
			{
				Character component = ((Component)val).GetComponent<Character>();
				characterGettingShot = (((Object)(object)component != (Object)null) ? component : Character.localCharacter);
			}
			else
			{
				characterGettingShot = Character.localCharacter;
			}
			shotTime = howLongToFly;
			shotDirection = whichDirectionShooting;
		}

		public void UpdateShotPhysicsT()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)characterGettingShot == (Object)null))
			{
				Vector3 move = shotDirection * 25f * -1f;
				characterGettingShot.AddForce(move, 1f, 1f, (ForceMode)5);
			}
		}
	}
	public class GunItemLaunch : MonoBehaviour
	{
		public float shotTime;

		private Item itemGettingShot;

		private Vector3 shotDirection;

		private void Update()
		{
			if (shotTime > 0f)
			{
				shotTime -= Time.deltaTime;
				PhotonView component = ((Component)this).GetComponent<PhotonView>();
				if ((Object)(object)component != (Object)null)
				{
					component.RPC("UpdateShotPhysicsT", (RpcTarget)0, Array.Empty<object>());
				}
			}
		}

		public void ShootSelfT(float howLongToFly, Item whoIsGettingShot, Vector3 whichDirectionShooting)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			shotTime = howLongToFly;
			itemGettingShot = whoIsGettingShot;
			shotDirection = whichDirectionShooting;
		}

		[PunRPC]
		public void RPC_ShootSelfT(float howLongToFly, Vector3 whichDirectionShooting)
		{
			//IL_0015: 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)
			itemGettingShot = ((Component)this).GetComponent<Item>();
			shotTime = howLongToFly;
			shotDirection = whichDirectionShooting;
		}

		[PunRPC]
		public void UpdateShotPhysicsT()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)itemGettingShot == (Object)null))
			{
				Rigidbody component = ((Component)itemGettingShot).GetComponent<Rigidbody>();
				if ((Object)(object)component != (Object)null)
				{
					component.AddForce(shotDirection * 10f, (ForceMode)1);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Character), "Awake")]
	internal static class GunPatch_Character
	{
		[HarmonyPostfix]
		private static void AddGunCharacterLaunch(Character __instance)
		{
			if ((Object)(object)((Component)__instance).GetComponent<GunCharacterLaunch>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<GunCharacterLaunch>();
			}
		}
	}
	[HarmonyPatch(typeof(Item), "Awake")]
	internal static class GunPatch_Item
	{
		[HarmonyPostfix]
		private static void AddGunItemLaunchAndKnifeVisual(Item __instance)
		{
			if ((Object)(object)((Component)__instance).GetComponent<GunItemLaunch>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<GunItemLaunch>();
			}
			if (Plugin.IsKnifeItem(__instance) && (Object)(object)((Component)__instance).GetComponent<KnifeVisualRuntime>() == (Object)null)
			{
				KnifeVisualRuntime knifeVisualRuntime = ((Component)__instance).gameObject.AddComponent<KnifeVisualRuntime>();
				knifeVisualRuntime.item = __instance;
			}
		}
	}
	[BepInDependency("com.github.PEAKModding.PEAKLib.Items", "1.0.0")]
	[BepInDependency("com.github.PEAKModding.PEAKLib.Core", "1.0.0")]
	[BepInPlugin("com.sol.knife", "Knife", "1.2.5")]
	public class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <PatchAfterLoadFinished>d__13 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public Plugin <>4__this;

			private float <timeout>5__1;

			private GameObject <bingBong>5__2;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <PatchAfterLoadFinished>d__13(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<bingBong>5__2 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_007d: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<timeout>5__1 = Time.time + 20f;
					break;
				case 1:
					<>1__state = -1;
					<bingBong>5__2 = null;
					break;
				}
				if (Time.time < <timeout>5__1)
				{
					<bingBong>5__2 = GameObject.Find("BingBong_Spawner");
					if ((Object)(object)Knife != (Object)null && (Object)(object)<bingBong>5__2 != (Object)null)
					{
						CreateItemSpawners();
						return false;
					}
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 1;
					return true;
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public const string Id = "com.sol.knife";

		public const string Name = "Knife";

		public const string Version = "1.2.5";

		internal static GameObject KnifeVisualPrefab;

		internal static bool DisableKnifeCharacterCollision = true;

		private Harmony _harmony;

		private Coroutine _levelLoadCompleteCoroutine;

		private static GameObject Knife;

		private void Awake()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			SceneManager.sceneLoaded += OnSceneLoaded;
			LocalizationFix();
			BundleLoader.LoadBundleWithName((BaseUnityPlugin)(object)this, "knife.peakbundle", (Action<PeakBundle>)delegate(PeakBundle peakBundle)
			{
				//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fb: Expected O, but got Unknown
				try
				{
					UnityItemContent val = peakBundle.LoadAsset<UnityItemContent>("IC_Knife");
					GameObject shotSFXPrefab = peakBundle.LoadAsset<GameObject>("SFX_Knife");
					if (!((Object)(object)val == (Object)null))
					{
						Knife = val.ItemPrefab;
						if (!((Object)(object)Knife == (Object)null))
						{
							if ((Object)(object)Knife.GetComponent<Action_Ammo>() == (Object)null)
							{
								Knife.AddComponent<Action_Ammo>();
							}
							Action_Gun action_Gun = Knife.GetComponent<Action_Gun>();
							if ((Object)(object)action_Gun == (Object)null)
							{
								action_Gun = Knife.AddComponent<Action_Gun>();
							}
							action_Gun.maxDistance = 500f;
							action_Gun.dartCollisionSize = 0.3f;
							action_Gun.fireRate = 0.8f;
							((ItemAction)action_Gun).OnHeld = true;
							action_Gun.spawnTransform = Knife.transform.Find("SpawnPos");
							action_Gun.shotSFXPrefab = shotSFXPrefab;
							action_Gun.dartVFX = null;
							action_Gun.afflictionsOnHit = (Affliction[])(object)new Affliction[1] { (Affliction)new Affliction_AdjustStatus((STATUSTYPE)0, 0.1f, 1f) };
							Transform val2 = Knife.transform.Find("VFX_Knife");
							if ((Object)(object)val2 != (Object)null)
							{
								((Component)val2).gameObject.SetActive(true);
								KnifeVFX knifeVFX = Knife.GetComponent<KnifeVFX>();
								if ((Object)(object)knifeVFX == (Object)null)
								{
									knifeVFX = Knife.AddComponent<KnifeVFX>();
								}
								ParticleSystem componentInChildren = ((Component)val2).GetComponentInChildren<ParticleSystem>(true);
								if ((Object)(object)componentInChildren != (Object)null)
								{
									knifeVFX.knifeParticles = componentInChildren;
								}
							}
							ConfigureKnifePrefab(Knife);
							peakBundle.Mod.RegisterContent();
						}
					}
				}
				catch
				{
				}
			});
			_harmony = new Harmony("com.sol.knife");
			_harmony.PatchAll();
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		internal static bool IsKnifeItem(Item item)
		{
			if ((Object)(object)item == (Object)null)
			{
				return false;
			}
			if ((Object)(object)((Component)item).GetComponent<Action_Gun>() != (Object)null)
			{
				return true;
			}
			string name = ((Object)((Component)item).gameObject).name;
			return name.Contains("Knife") || name.Contains("com.sol.knife");
		}

		private static void ConfigureKnifePrefab(GameObject prefab)
		{
			if (!((Object)(object)prefab == (Object)null))
			{
				KnifeVisualRuntime knifeVisualRuntime = prefab.GetComponent<KnifeVisualRuntime>();
				if ((Object)(object)knifeVisualRuntime == (Object)null)
				{
					knifeVisualRuntime = prefab.AddComponent<KnifeVisualRuntime>();
				}
				knifeVisualRuntime.item = prefab.GetComponent<Item>();
			}
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			if (((Scene)(ref scene)).path.StartsWith("Assets/8_SCENES/Generated/"))
			{
				if (_levelLoadCompleteCoroutine != null)
				{
					((MonoBehaviour)this).StopCoroutine(_levelLoadCompleteCoroutine);
					_levelLoadCompleteCoroutine = null;
				}
				_levelLoadCompleteCoroutine = ((MonoBehaviour)this).StartCoroutine(PatchAfterLoadFinished());
			}
		}

		[IteratorStateMachine(typeof(<PatchAfterLoadFinished>d__13))]
		private IEnumerator PatchAfterLoadFinished()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <PatchAfterLoadFinished>d__13(0)
			{
				<>4__this = this
			};
		}

		private static void CreateItemSpawners()
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("BingBong_Spawner");
			if ((Object)(object)val == (Object)null || (Object)(object)Knife == (Object)null || (Object)(object)GameObject.Find("Knife_Spawner") != (Object)null)
			{
				return;
			}
			GameObject val2 = Object.Instantiate<GameObject>(val, val.transform.parent);
			val2.SetActive(false);
			((Object)val2).name = "Knife_Spawner";
			val2.transform.localPosition = new Vector3(-10.862f, 0.7437f, -4.13f);
			try
			{
				SingleItemSpawner component = val2.GetComponent<SingleItemSpawner>();
				if ((Object)(object)component == (Object)null)
				{
					Object.Destroy((Object)(object)val2);
					return;
				}
				component.prefab = Knife;
				val2.SetActive(true);
				component.TrySpawnItems();
			}
			catch
			{
				if ((Object)(object)val2 != (Object)null)
				{
					Object.Destroy((Object)(object)val2);
				}
			}
		}

		private static void LocalizationFix()
		{
			LocalizedText.mainTable["NAME_KNIFE"] = new List<string>(15)
			{
				"Knife", "Knife", "Knife", "Knife", "Knife", "Knife", "Knife", "Knife", "Knife", "Knife",
				"Knife", "Knife", "Knife", "Knife", "Knife"
			};
			LocalizedText.mainTable["DESC_KNIFE"] = new List<string>(15)
			{
				"Knife", "Knife", "Knife", "Knife", "Knife", "Knife", "Knife", "Knife", "Knife", "Knife",
				"Knife", "Knife", "Knife", "Knife", "Knife"
			};
		}
	}
}