Decompiled source of Koki Weapons v1.1.10001

KokiWeapons.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using ComputerysModdingUtilities;
using FishNet;
using FishNet.Connection;
using FishNet.Managing.Object;
using FishNet.Managing.Server;
using FishNet.Object;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using MyceliumNetworking;
using Steamworks;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: StraftatMod(false)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("ComputerysModdingUtilities")]
[assembly: IgnoresAccessChecksTo("FishNet.Runtime")]
[assembly: IgnoresAccessChecksTo("Heathen.PhysKit")]
[assembly: IgnoresAccessChecksTo("STRAFTAT")]
[assembly: AssemblyCompany("Koki")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+cd3ef92cffd95a6cd398cf47201dca27fbba3fc2")]
[assembly: AssemblyProduct("KokiWeapons")]
[assembly: AssemblyTitle("KokiWeapons")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
public static class KokiDebug
{
	public static void Log(object s)
	{
		KokiWeaponsPlugin.Logger.LogError(s);
	}

	public static void PrintComponents(GameObject obj)
	{
		Component[] components = obj.GetComponents<Component>();
		foreach (Component val in components)
		{
			KokiWeaponsPlugin.Logger.LogError((object)((object)val).GetType().Name);
		}
	}
}
[HarmonyPatch(typeof(Settings))]
public class SpawnWeaponOnTaunt
{
	public static List<GameObject> weapons = new List<GameObject>();

	[HarmonyPatch("IncreaseTauntsAmount")]
	public static void Prefix(Settings __instance)
	{
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = null;
		if (Input.GetKeyDown((KeyCode)49))
		{
			if (!Object.op_Implicit((Object)(object)TPTrap.TemplateGameObject))
			{
				TPTrap.InitTemplate();
			}
			val = TPTrap.TemplateGameObject;
		}
		else if (Input.GetKeyDown((KeyCode)50))
		{
			val = SpawnerManager.NameToWeaponDict["APMine"];
		}
		else if (Input.GetKeyDown((KeyCode)51))
		{
			val = SpawnerManager.NameToWeaponDict["ProximityMine"];
		}
		else if (Input.GetKeyDown((KeyCode)52))
		{
			val = SpawnerManager.NameToWeaponDict["Gun"];
		}
		else if (Input.GetKeyDown((KeyCode)53))
		{
			if (!Object.op_Implicit((Object)(object)KBGrenade.TemplateGameObject))
			{
				KBGrenade.InitTemplate();
			}
			val = KBGrenade.TemplateGameObject;
		}
		if (Object.op_Implicit((Object)(object)val) && InstanceFinder.IsServer)
		{
			FirstPersonController[] array = Object.FindObjectsOfType<FirstPersonController>();
			foreach (FirstPersonController val2 in array)
			{
				Vector3 val3 = val2.playerCameraHolder.transform.position + ((Vector3)(ref val2.dirForward)).normalized;
				val3.y -= 0.5f;
				GameObject val4 = Object.Instantiate<GameObject>(val, val3, Quaternion.identity);
				val4.GetComponent<ItemBehaviour>().DispenserDrop(Vector3.zero);
				val4.GetComponent<Rigidbody>().isKinematic = true;
				((NetworkBehaviour)val2).ServerManager.Spawn(val4, (NetworkConnection)null);
				weapons.Add(val4);
			}
		}
	}
}
[HarmonyPatch]
public static class KBGrenade
{
	public static GameObject TemplateGameObject;

	public static GameObject TemplatePhysGameObject;

	public static GameObject Mesh;

	public static GameObject PhysMesh;

	public static void LoadBundleAssets(AssetBundle bundle)
	{
	}

	[HarmonyPatch(typeof(SpawnerManager), "PopulateAllWeapons")]
	[HarmonyPostfix]
	public static void RegisterWeapon()
	{
	}

	public static void InitTemplate()
	{
		GameObject val = Object.Instantiate<GameObject>(SpawnerManager.NameToWeaponDict["StunGrenade"]);
		ToKBGrenade(val, isClientVisual: false);
		TemplateGameObject = val;
		TemplateGameObject.SetActive(false);
		Object.DontDestroyOnLoad((Object)(object)TemplateGameObject);
	}

	public static void ToKBGrenade(GameObject go, bool isClientVisual)
	{
		((Object)go).name = "Repulsion Grenade";
		ItemBehaviour component = go.GetComponent<ItemBehaviour>();
		component.weaponName = "repulsion grenade";
		((Component)go.GetComponent<DualLauncher>().trickShot.template).gameObject.AddComponent<IsKBGrenade>();
		if (isClientVisual)
		{
		}
		if (Object.op_Implicit((Object)(object)TemplatePhysGameObject))
		{
		}
	}

	public static void ConvertToPhysTPTrap(GameObject go, bool isClientVisual)
	{
		((Object)go).name = "Physics Repulsion Grenade";
		Object.DontDestroyOnLoad((Object)(object)go);
		if (!isClientVisual)
		{
		}
	}

	public static IsKBGrenade GetIsKBGrenade(GameObject go)
	{
		if (!KokiWeaponsPlugin.Debug)
		{
			return go.GetComponent<IsKBGrenade>();
		}
		Component[] components = go.GetComponents<Component>();
		foreach (Component val in components)
		{
			if (((object)val).GetType().Name == "IsKBGrenade")
			{
				return (IsKBGrenade)(object)val;
			}
		}
		return null;
	}
}
public class IsKBGrenade : MonoBehaviour
{
}
[HarmonyPatch]
public static class KBGrenadeMechanics
{
	[HarmonyPatch(typeof(PhysicsGrenade), "RpcLogic___HandleExplosion_4276783012")]
	[HarmonyTranspiler]
	public static IEnumerable<CodeInstruction> InsertKBEffect(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
	{
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Expected O, but got Unknown
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Expected O, but got Unknown
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Expected O, but got Unknown
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Expected O, but got Unknown
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Expected O, but got Unknown
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Expected O, but got Unknown
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Expected O, but got Unknown
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Expected O, but got Unknown
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Expected O, but got Unknown
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Expected O, but got Unknown
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Expected O, but got Unknown
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Expected O, but got Unknown
		//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Expected O, but got Unknown
		FieldInfo fieldInfo = AccessTools.Field(typeof(PhysicsGrenade), "isOwner");
		FieldInfo fieldInfo2 = AccessTools.Field(typeof(PhysicsGrenade), "ph2");
		FieldInfo fieldInfo3 = AccessTools.Field(typeof(PhysicsGrenade), "makeBlood");
		MethodInfo methodInfo = AccessTools.Method(typeof(KBGrenadeMechanics), "KBEffect", (Type[])null, (Type[])null);
		MethodInfo methodInfo2 = AccessTools.Method(typeof(KBGrenade), "GetIsKBGrenade", (Type[])null, (Type[])null);
		MethodInfo methodInfo3 = AccessTools.Method(typeof(Object), "op_Implicit", (Type[])null, (Type[])null);
		MethodInfo methodInfo4 = AccessTools.PropertyGetter(typeof(PhysicsGrenade), "gameObject");
		Label label = default(Label);
		Label label2 = default(Label);
		return new CodeMatcher(instructions, generator).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((OpCode?)OpCodes.Ldstr, (object)"Player", (string)null)
		}).CreateLabel(ref label).MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((OpCode?)OpCodes.Stfld, (object)fieldInfo3, (string)null)
		})
			.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldc_I4_0, (object)null, (string)null)
			})
			.CreateLabel(ref label2)
			.Insert((CodeInstruction[])(object)new CodeInstruction[10]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Callvirt, (object)methodInfo4),
				new CodeInstruction(OpCodes.Call, (object)methodInfo2),
				new CodeInstruction(OpCodes.Call, (object)methodInfo3),
				new CodeInstruction(OpCodes.Brfalse, (object)label2),
				new CodeInstruction(OpCodes.Ldloc_2, (object)null),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)fieldInfo2),
				new CodeInstruction(OpCodes.Call, (object)methodInfo),
				new CodeInstruction(OpCodes.Br, (object)label)
			})
			.InstructionEnumeration();
	}

	public static void KBEffect(Collider[] colliders, PlayerHealth[] healths)
	{
		PlayerHealth[] array = healths.Distinct().ToArray();
		CollectionExtensions.Do<PlayerHealth>((IEnumerable<PlayerHealth>)healths, (Action<PlayerHealth>)delegate(PlayerHealth x)
		{
			KokiDebug.Log(x);
		});
	}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.koki.weapons", "Koki Weapons", "1.1.0")]
public class KokiWeaponsPlugin : BaseUnityPlugin
{
	internal static ManualLogSource Logger;

	internal static Harmony Harmony;

	internal static AssetBundle Bundle;

	internal static bool Debug;

	private void Awake()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		Logger = ((BaseUnityPlugin)this).Logger;
		Harmony = new Harmony("com.koki.weapons");
		((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
		IEnumerable<AssetBundle> allLoadedAssetBundles = AssetBundle.GetAllLoadedAssetBundles();
		AssetBundle val = allLoadedAssetBundles.FirstOrDefault((Func<AssetBundle, bool>)((AssetBundle b) => ((Object)b).name == "kokiweaponsbundle"));
		if (Object.op_Implicit((Object)(object)val))
		{
			val.Unload(true);
		}
		string text = ((!Debug) ? Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "kokiWeaponsBundle") : Path.Combine(Paths.PluginPath, "KokiWeapons/kokiWeaponsBundle"));
		Bundle = AssetBundle.LoadFromFile(text);
		if (!Object.op_Implicit((Object)(object)Bundle))
		{
			Logger.LogError((object)"Bundle for KokiWeapons not found! Plugin will not load.");
			return;
		}
		((Component)this).gameObject.AddComponent<TPTrapNetworking>();
		Harmony.PatchAll();
		if (!Debug)
		{
			Harmony.Unpatch((MethodBase)typeof(Settings).GetMethod("IncreaseTauntsAmount"), (HarmonyPatchType)1, "com.koki.weapons");
		}
		TPTrap.LoadBundleAssets(Bundle);
	}

	public void OnDestroy()
	{
		if (Debug)
		{
			foreach (GameObject weapon in SpawnWeaponOnTaunt.weapons)
			{
				if (Object.op_Implicit((Object)(object)weapon))
				{
					InstanceFinder.ServerManager.Despawn(weapon, (DespawnType?)null);
				}
			}
		}
		TPTrap.TemplateGameObject = null;
		TPTrap.TemplatePhysGameObject = null;
		TPTrap.MineMesh = null;
		TPTrap.PhysMineMesh = null;
		Harmony.UnpatchSelf();
	}
}
[HarmonyPatch]
public static class TPTrap
{
	public static GameObject TemplateGameObject;

	public static GameObject TemplatePhysGameObject;

	public static GameObject MineMesh;

	public static GameObject PhysMineMesh;

	public static AnimationClip SphereAnim;

	public static AnimationClip TorusAnim;

	public static void LoadBundleAssets(AssetBundle bundle)
	{
		MineMesh = bundle.LoadAsset<GameObject>("TeleTrapMesh");
		PhysMineMesh = bundle.LoadAsset<GameObject>("TeleTrapPhysMesh");
		SphereAnim = bundle.LoadAsset<AnimationClip>("tpmineSphere");
		TorusAnim = bundle.LoadAsset<AnimationClip>("tpmineTorus");
		SphereAnim.wrapMode = (WrapMode)2;
		TorusAnim.wrapMode = (WrapMode)2;
	}

	[HarmonyPatch(typeof(SpawnerManager), "PopulateAllWeapons")]
	[HarmonyPostfix]
	public static void RegisterWeapon()
	{
		if (!SpawnerManager.NameToWeaponDict.ContainsKey("Teleport Mine"))
		{
			InitTemplate();
			GameObject templateGameObject = TemplateGameObject;
			Array.Resize(ref SpawnerManager.AllWeapons, SpawnerManager.AllWeapons.Length + 1);
			SpawnerManager.AllWeapons[^1] = templateGameObject;
			SpawnerManager.NameToWeaponDict.Add(((Object)templateGameObject).name, templateGameObject);
			SpawnerManager.NameToIndexDict.Add(((Object)templateGameObject).name, SpawnerManager.AllWeapons.Length - 1);
		}
	}

	public static void InitTemplate()
	{
		GameObject val = Object.Instantiate<GameObject>(SpawnerManager.NameToWeaponDict["APMine"]);
		ConvertToTPTrap(val, isClientVisual: false);
		TemplateGameObject = val;
		TemplateGameObject.SetActive(false);
		Object.DontDestroyOnLoad((Object)(object)TemplateGameObject);
	}

	public static void ConvertToTPTrap(GameObject go, bool isClientVisual)
	{
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
		go.AddComponent<TrapLink>();
		((Object)go).name = "Teleport Mine";
		ItemBehaviour component = go.GetComponent<ItemBehaviour>();
		component.weaponName = "teleport mine";
		WeaponHandSpawner component2 = go.GetComponent<WeaponHandSpawner>();
		((Weapon)component2).currentAmmo = 2;
		Transform val = go.transform.Find("ElbowPivotPoint").Find("AimStrafePivot");
		((Component)val.Find("PF_APMine_00")).gameObject.SetActive(false);
		GameObject val2 = Object.Instantiate<GameObject>(MineMesh);
		val2.transform.SetParent(val);
		if (isClientVisual)
		{
			val2.transform.localPosition = new Vector3(0f, -0.2f, 0f);
			val2.transform.localScale = new Vector3(0.8f, 0.8f, 0.8f);
			val2.transform.localRotation = Quaternion.identity;
		}
		val2.SetActive(true);
		BoxCollider component3 = go.GetComponent<BoxCollider>();
		component3.center = new Vector3(0f, 0.09f, 0f);
		component3.size = new Vector3(0.21f, 0.5f, 0.16f);
		if (!Object.op_Implicit((Object)(object)TemplatePhysGameObject))
		{
			GameObject val3 = Object.Instantiate<GameObject>(component2.objToSpawn);
			ConvertToPhysTPTrap(val3, isClientVisual: false);
			TemplatePhysGameObject = val3;
		}
	}

	public static void ConvertToPhysTPTrap(GameObject go, bool isClientVisual)
	{
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		((Object)go).name = "Physics Teleport Mine";
		Object.DontDestroyOnLoad((Object)(object)go);
		ProximityMine component = go.GetComponent<ProximityMine>();
		component.canActivate = false;
		Transform transform = go.transform;
		((Component)transform.Find("PF_APMine_00")).gameObject.SetActive(false);
		GameObject val = Object.Instantiate<GameObject>(PhysMineMesh);
		val.transform.SetParent(transform);
		Animation val2 = ((Component)go.transform.Find("TeleTrapPhysMesh(Clone)").Find("trap_010")).gameObject.AddComponent<Animation>();
		val2.AddClip(SphereAnim, "sphere");
		val2.AddClip(TorusAnim, "torus");
		if (isClientVisual)
		{
			val.transform.localPosition = new Vector3(0f, 0f, 0f);
			val2["sphere"].layer = 0;
			val2.Play("sphere");
			val2["torus"].layer = 1;
			val2["torus"].weight = 1f;
			val2["torus"].enabled = true;
			val2.Play("torus");
		}
		if (Object.op_Implicit((Object)(object)transform.Find("radius(Clone)")))
		{
			Object.Destroy((Object)(object)((Component)transform.Find("radius(Clone)")).gameObject);
		}
		GameObject val3 = Object.Instantiate<GameObject>(((Component)Resources.FindObjectsOfTypeAll<GameObject>().First((GameObject go) => ((Object)go).name == "ProximityMine" && Object.op_Implicit((Object)(object)go.transform.Find("radius"))).transform.Find("radius")).gameObject);
		val3.transform.SetParent(transform);
		val3.transform.localScale = new Vector3(1.858382f, 1.858382f, 1.858382f);
		val3.SetActive(false);
		Object.Destroy((Object)(object)GetTrapLink(go));
		go.AddComponent<TrapLink>();
		BoxCollider component2 = ((Component)transform).GetComponent<BoxCollider>();
		component2.size = new Vector3(1.6f, 1.6f, 1.6f);
		Object.Destroy((Object)(object)((Component)((Component)transform).transform.Find("Cube")).gameObject);
	}

	public static TrapLink GetTrapLink(GameObject go)
	{
		if (!KokiWeaponsPlugin.Debug)
		{
			return go.GetComponent<TrapLink>();
		}
		Component[] components = go.GetComponents<Component>();
		foreach (Component val in components)
		{
			if (((object)val).GetType().Name == "TrapLink")
			{
				return (TrapLink)(object)val;
			}
		}
		return null;
	}
}
public class TrapLink : MonoBehaviour
{
	public GameObject otherTrap;
}
[HarmonyPatch]
public static class TPTrapMechanics
{
	[HarmonyPatch(typeof(WeaponHandSpawner), "RpcLogic___SpawnObject_2587446063")]
	[HarmonyPrefix]
	private static void SwapTemplateGO(WeaponHandSpawner __instance, ref GameObject obj)
	{
		if (Object.op_Implicit((Object)(object)TPTrap.GetTrapLink(((Component)__instance).gameObject)))
		{
			obj = TPTrap.TemplatePhysGameObject;
		}
	}

	[HarmonyPatch(typeof(WeaponHandSpawner), "RpcLogic___SpawnObject_2587446063")]
	[HarmonyTranspiler]
	private static IEnumerable<CodeInstruction> LinkMineOnPlace(IEnumerable<CodeInstruction> instructions)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Expected O, but got Unknown
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Expected O, but got Unknown
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Expected O, but got Unknown
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Expected O, but got Unknown
		MethodInfo methodInfo = AccessTools.Method(typeof(TPTrapMechanics), "OnPlace", (Type[])null, (Type[])null);
		return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(ProximityMine), "sync___set_value__rootObject", (Type[])null, (Type[])null), (string)null)
		}).Insert((CodeInstruction[])(object)new CodeInstruction[3]
		{
			new CodeInstruction(OpCodes.Ldarg_0, (object)null),
			new CodeInstruction(OpCodes.Ldloc_0, (object)null),
			new CodeInstruction(OpCodes.Call, (object)methodInfo)
		}).InstructionEnumeration();
	}

	public static void OnPlace(WeaponHandSpawner __instance, GameObject newTrap)
	{
		TrapLink component = ((Component)__instance).gameObject.GetComponent<TrapLink>();
		if (Object.op_Implicit((Object)(object)component))
		{
			if (KokiWeaponsPlugin.Debug)
			{
				SpawnWeaponOnTaunt.weapons.Add(newTrap);
			}
			ProximityMine component2 = newTrap.GetComponent<ProximityMine>();
			component2.activated = false;
			component2.canActivate = false;
			component2.stunMine = false;
			Animation component3 = ((Component)newTrap.transform.Find("TeleTrapPhysMesh(Clone)").Find("trap_010")).GetComponent<Animation>();
			component3["sphere"].layer = 0;
			component3.Play("sphere");
			component3["torus"].layer = 1;
			component3["torus"].weight = 1f;
			component3["torus"].enabled = true;
			component3.Play("torus");
			MyceliumNetwork.RPC(932828u, "DisplayClientVisual", (ReliableType)1, new object[3]
			{
				newTrap.GetComponent<NetworkObject>().ObjectId,
				"ConvertToPhysTPTrap",
				false
			});
			if (Object.op_Implicit((Object)(object)component.otherTrap))
			{
				GameObject gameObject = component.otherTrap.gameObject;
				TPTrap.GetTrapLink(gameObject).otherTrap = newTrap;
				TPTrap.GetTrapLink(newTrap).otherTrap = gameObject;
				ProximityMine component4 = gameObject.GetComponent<ProximityMine>();
				((Component)gameObject.transform.Find("radius(Clone)")).gameObject.SetActive(true);
				((Component)newTrap.transform.Find("radius(Clone)")).gameObject.SetActive(true);
				MyceliumNetwork.RPC(932828u, "DisplayClientVisual", (ReliableType)1, new object[3]
				{
					gameObject.GetComponent<NetworkObject>().ObjectId,
					"ToggleRadius",
					false
				});
				MyceliumNetwork.RPC(932828u, "DisplayClientVisual", (ReliableType)1, new object[3]
				{
					newTrap.GetComponent<NetworkObject>().ObjectId,
					"ToggleRadius",
					false
				});
			}
			else
			{
				component.otherTrap = newTrap;
			}
		}
	}

	[HarmonyPatch(typeof(ProximityMine), "OnTriggerStay")]
	[HarmonyPostfix]
	public static void DetectExplosion(ProximityMine __instance)
	{
		if (Object.op_Implicit((Object)(object)TPTrap.GetTrapLink(((Component)__instance).gameObject)))
		{
			GameObject otherTrap = TPTrap.GetTrapLink(((Component)__instance).gameObject).otherTrap;
			if (InstanceFinder.IsServer && !__instance.stunMine && Object.op_Implicit((Object)(object)otherTrap))
			{
				__instance.ChangeState();
				__instance.HandleExplosion();
			}
		}
	}

	[HarmonyPatch(typeof(ProximityMine), "HandleExplosion")]
	[HarmonyPrefix]
	public static bool HandleExplosion(ProximityMine __instance)
	{
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		if (!InstanceFinder.IsServer)
		{
			return false;
		}
		if (!Object.op_Implicit((Object)(object)TPTrap.GetTrapLink(((Component)__instance).gameObject)))
		{
			return true;
		}
		ProximityMine component = TPTrap.GetTrapLink(((Component)__instance).gameObject).otherTrap.GetComponent<ProximityMine>();
		Collider[] array = Physics.OverlapSphere(((Component)__instance).transform.position, __instance.explosionRadius, LayerMask.op_Implicit(__instance.bodyLayer));
		Vector3 position = ((Component)component).transform.position;
		__instance.stunMine = true;
		if (!component.stunMine)
		{
			component.ChangeState();
			component.HandleExplosion();
		}
		if (array.Length != 0)
		{
			Collider[] array2 = array;
			foreach (Collider val in array2)
			{
				FirstPersonController component2 = ((Component)val).GetComponent<FirstPersonController>();
				if (Object.op_Implicit((Object)(object)component2))
				{
					if (((NetworkBehaviour)component2).Owner.IsLocalClient)
					{
						component2.Teleport(position, 0f, false, (Transform)null, 0f, 0f, true);
						continue;
					}
					ulong.TryParse(((NetworkBehaviour)component2).Owner.GetAddress(), out var result);
					MyceliumNetwork.RPCTarget(932828u, "TeleportClient", (CSteamID)result, (ReliableType)1, new object[1] { position });
				}
			}
		}
		__instance.ExplodeServer();
		return false;
	}

	[HarmonyPatch(typeof(ProximityMine), "Start")]
	[HarmonyTranspiler]
	public static IEnumerable<CodeInstruction> StopActivateCoroutine(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
	{
		//IL_001a: 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)
		//IL_0044: Expected O, but got Unknown
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Expected O, but got Unknown
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Expected O, but got Unknown
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Expected O, but got Unknown
		MethodInfo methodInfo = AccessTools.Method(typeof(TPTrap), "GetTrapLink", (Type[])null, (Type[])null);
		Label label = default(Label);
		return new CodeMatcher(instructions, generator).End().CreateLabel(ref label).Start()
			.Insert((CodeInstruction[])(object)new CodeInstruction[4]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Callvirt, (object)AccessTools.PropertyGetter(typeof(ProximityMine), "gameObject")),
				new CodeInstruction(OpCodes.Call, (object)methodInfo),
				new CodeInstruction(OpCodes.Brtrue, (object)label)
			})
			.InstructionEnumeration();
	}

	[HarmonyPatch(typeof(Weapon), "TriggerEnvironment")]
	[HarmonyPrefix]
	public static void ExplodeTPTrapOnHit(Weapon __instance, GameObject obj)
	{
		GameObject gameObject = ((Component)obj.transform.root).gameObject;
		if (!obj.CompareTag("Mine") || !Object.op_Implicit((Object)(object)TPTrap.GetTrapLink(gameObject)))
		{
			return;
		}
		if (!InstanceFinder.IsHost)
		{
			MyceliumNetwork.RPC(932828u, "ExplodeMineFromClient", (ReliableType)1, new object[1] { ((Component)obj.transform.root).gameObject.GetComponent<NetworkObject>().ObjectId });
			return;
		}
		GameObject otherTrap = TPTrap.GetTrapLink(gameObject).otherTrap;
		if (Object.op_Implicit((Object)(object)otherTrap))
		{
			((Component)otherTrap.transform.Find("radius(Clone)")).gameObject.SetActive(false);
			MyceliumNetwork.RPC(932828u, "DisplayClientVisual", (ReliableType)1, new object[3]
			{
				otherTrap.GetComponent<NetworkObject>().ObjectId,
				"ToggleRadius",
				false
			});
		}
		((Component)obj.transform.root).GetComponent<ProximityMine>().ChangeState();
		((Component)obj.transform.root).GetComponent<ProximityMine>().ExplodeServer();
	}
}
[HarmonyPatch]
public class TPTrapNetworking : MonoBehaviour
{
	[CompilerGenerated]
	private sealed class <CallOnObj>d__4 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public int nobid;

		public Action<GameObject, bool> callback;

		public bool waitForIBehavior;

		public TPTrapNetworking <>4__this;

		private NetworkObject <nob>5__1;

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

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

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

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

		private bool MoveNext()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			int num = <>1__state;
			if (num != 0)
			{
				if (num != 1)
				{
					return false;
				}
				<>1__state = -1;
				if (waitForIBehavior && Object.op_Implicit((Object)(object)<nob>5__1))
				{
					waitForIBehavior = !Object.op_Implicit((Object)(object)((Component)<nob>5__1).gameObject.GetComponent<ItemBehaviour>());
				}
				if (!(!((ManagedObjects)InstanceFinder.ClientManager.Objects).Spawned.TryGetValue(nobid, out <nob>5__1) | waitForIBehavior))
				{
					callback(((Component)<nob>5__1).gameObject, arg2: true);
					return false;
				}
			}
			else
			{
				<>1__state = -1;
				<nob>5__1 = null;
			}
			<>2__current = (object)new WaitForSeconds(0.15f);
			<>1__state = 1;
			return true;
		}

		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 uint MyceliumID = 932828u;

	public void Awake()
	{
		MyceliumNetwork.DeregisterNetworkObject((object)((Component)this).gameObject.GetComponent<TPTrapNetworking>(), 932828u, 0);
		MyceliumNetwork.RegisterNetworkObject((object)this, 932828u, 0);
	}

	[HarmonyPatch(typeof(ServerManager), "Spawn", new Type[]
	{
		typeof(NetworkObject),
		typeof(NetworkConnection)
	})]
	[HarmonyPostfix]
	public static void SendClientWeaponVisuals(NetworkObject nob)
	{
		GameObject gameObject = ((Component)nob).gameObject;
		if (Object.op_Implicit((Object)(object)TPTrap.GetTrapLink(gameObject)))
		{
			MyceliumNetwork.RPC(932828u, "DisplayClientVisual", (ReliableType)1, new object[3] { nob.ObjectId, "ConvertToTPTrap", true });
		}
	}

	[CustomRPC]
	public void DisplayClientVisual(int nobID, string callbackName, bool waitForIbehavior)
	{
		if (!InstanceFinder.IsServer)
		{
			Dictionary<string, Action<GameObject, bool>> dictionary = new Dictionary<string, Action<GameObject, bool>>();
			dictionary.Add("ConvertToTPTrap", TPTrap.ConvertToTPTrap);
			dictionary.Add("ConvertToPhysTPTrap", TPTrap.ConvertToPhysTPTrap);
			dictionary.Add("ToggleRadius", ToggleRadius);
			Dictionary<string, Action<GameObject, bool>> dictionary2 = dictionary;
			((MonoBehaviour)this).StartCoroutine(CallOnObj(nobID, dictionary2[callbackName], waitForIbehavior));
		}
	}

	[IteratorStateMachine(typeof(<CallOnObj>d__4))]
	private IEnumerator CallOnObj(int nobid, Action<GameObject, bool> callback, bool waitForIBehavior)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <CallOnObj>d__4(0)
		{
			<>4__this = this,
			nobid = nobid,
			callback = callback,
			waitForIBehavior = waitForIBehavior
		};
	}

	public static void ToggleRadius(GameObject go, bool _)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		GameObject gameObject = ((Component)go.transform.Find("radius(Clone)")).gameObject;
		gameObject.transform.localPosition = Vector3.zero;
		gameObject.SetActive(!gameObject.activeSelf);
	}

	[CustomRPC]
	public void TeleportClient(Vector3 pos)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		FirstPersonController.instance.Teleport(pos, 0f, false, (Transform)null, 0f, 0f, true);
	}

	[CustomRPC]
	public void ExplodeMineFromClient(int nobID)
	{
		if (InstanceFinder.IsHost)
		{
			((ManagedObjects)InstanceFinder.ServerManager.Objects).Spawned.TryGetValue(nobID, out var value);
			TPTrapMechanics.ExplodeTPTrapOnHit(null, ((Component)value).gameObject);
		}
	}
}