Decompiled source of Revolver Grenade Launcher v1.0.0

plugins/newgan.dll

Decompiled an hour ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("newgan")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("newgan")]
[assembly: AssemblyTitle("newgan")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace UltrakillMglMod;

[BepInPlugin("com.custom.ultrakill.mgl", "MGL Grenade Launcher", "0.6.1")]
public class MglPlugin : BaseUnityPlugin
{
	public static GameObject MglModelPrefab;

	public static Sprite MglCustomIcon;

	public static GameObject ActiveMglWeapon;

	public static GameObject PreviousWeaponBeforeMgl;

	public static bool IsMglEquipped;

	private static PropertyInfo CurrentKeyboardProp;

	private static PropertyInfo TKeyProp;

	private static PropertyInfo WasPressedThisFrameProp;

	private static bool InputReflectionInitialized;

	private void Awake()
	{
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Expected O, but got Unknown
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Expected O, but got Unknown
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
		string text = Path.Combine(directoryName, "mgl_bundle");
		if (File.Exists(text))
		{
			AssetBundle val = AssetBundle.LoadFromFile(text);
			if ((Object)(object)val != (Object)null)
			{
				MglModelPrefab = val.LoadAsset<GameObject>("MGL_Prefab");
				((BaseUnityPlugin)this).Logger.LogInfo((object)(((Object)(object)MglModelPrefab != (Object)null) ? "[MGL] Префаб MGL_Prefab успешно загружен из бандла!" : "[MGL] Бандл открыт, но MGL_Prefab внутри не найден!"));
			}
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("[MGL] Файл mgl_bundle не найден рядом с DLL: " + text));
		}
		string path = Path.Combine(directoryName, "mgl_icon.png");
		if (File.Exists(path))
		{
			byte[] array = File.ReadAllBytes(path);
			Texture2D val2 = new Texture2D(2, 2, (TextureFormat)4, false);
			if (ImageConversion.LoadImage(val2, array))
			{
				((Texture)val2).filterMode = (FilterMode)0;
				MglCustomIcon = Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), new Vector2(0.5f, 0.5f), 100f);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"[MGL] Иконка mgl_icon.png успешно загружена!");
			}
		}
		Harmony val3 = new Harmony("com.custom.ultrakill.mgl");
		val3.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"MGL Mod loaded!");
	}

	private void Update()
	{
		GunControl instance = MonoSingleton<GunControl>.Instance;
		if (!((Object)(object)instance == (Object)null) && instance.activated && (!((Object)(object)GameStateManager.Instance != (Object)null) || !GameStateManager.Instance.PlayerInputLocked) && IsTKeyPressedThisFrame())
		{
			ToggleMglWeapon(instance);
		}
	}

	public static bool IsTKeyPressedThisFrame()
	{
		bool flag = false;
		try
		{
			flag = Input.GetKeyDown((KeyCode)116);
		}
		catch
		{
		}
		if (flag)
		{
			return true;
		}
		try
		{
			if (!InputReflectionInitialized)
			{
				InputReflectionInitialized = true;
				Type type = Type.GetType("UnityEngine.InputSystem.Keyboard, Unity.InputSystem");
				if (type != null)
				{
					CurrentKeyboardProp = type.GetProperty("current", BindingFlags.Static | BindingFlags.Public);
					TKeyProp = type.GetProperty("tKey", BindingFlags.Instance | BindingFlags.Public);
					if (TKeyProp != null)
					{
						WasPressedThisFrameProp = TKeyProp.PropertyType.GetProperty("wasPressedThisFrame", BindingFlags.Instance | BindingFlags.Public);
					}
				}
			}
			if (CurrentKeyboardProp != null && TKeyProp != null && WasPressedThisFrameProp != null)
			{
				object value = CurrentKeyboardProp.GetValue(null);
				if (value != null)
				{
					object value2 = TKeyProp.GetValue(value);
					if (value2 != null)
					{
						object value3 = WasPressedThisFrameProp.GetValue(value2);
						bool flag2 = default(bool);
						int num;
						if (value3 is bool)
						{
							flag2 = (bool)value3;
							num = 1;
						}
						else
						{
							num = 0;
						}
						if (((uint)num & (flag2 ? 1u : 0u)) != 0)
						{
							return true;
						}
					}
				}
			}
		}
		catch
		{
		}
		return false;
	}

	public static void ToggleMglWeapon(GunControl gc)
	{
		if ((Object)(object)gc == (Object)null)
		{
			return;
		}
		if ((Object)(object)ActiveMglWeapon == (Object)null)
		{
			CreateMglWeapon(gc);
		}
		if ((Object)(object)ActiveMglWeapon == (Object)null)
		{
			return;
		}
		if (IsMglEquipped)
		{
			IsMglEquipped = false;
			ActiveMglWeapon.SetActive(false);
			GameObject val = PreviousWeaponBeforeMgl;
			if ((Object)(object)val == (Object)null && gc.allWeapons != null)
			{
				val = ((IEnumerable<GameObject>)gc.allWeapons).FirstOrDefault((Func<GameObject, bool>)((GameObject w) => (Object)(object)w != (Object)null && (Object)(object)w != (Object)(object)ActiveMglWeapon));
			}
			if (!((Object)(object)val != (Object)null))
			{
				return;
			}
			int num = ((gc.slotDict == null || !gc.slotDict.ContainsKey(val)) ? 1 : gc.slotDict[val]);
			int value = 0;
			List<GameObject> slotList = GetSlotList(gc, num);
			if (slotList != null)
			{
				int num2 = slotList.IndexOf(val);
				if (num2 >= 0)
				{
					value = num2;
				}
			}
			gc.SwitchWeapon(num, (int?)value, false, false, false);
			val.SetActive(true);
			gc.currentWeapon = val;
			WeaponIcon componentInChildren = val.GetComponentInChildren<WeaponIcon>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				componentInChildren.UpdateIcon();
			}
			return;
		}
		if ((Object)(object)gc.currentWeapon != (Object)null && (Object)(object)gc.currentWeapon != (Object)(object)ActiveMglWeapon)
		{
			PreviousWeaponBeforeMgl = gc.currentWeapon;
			gc.currentWeapon.SetActive(false);
		}
		if (gc.allWeapons != null)
		{
			foreach (GameObject allWeapon in gc.allWeapons)
			{
				if ((Object)(object)allWeapon != (Object)null && (Object)(object)allWeapon != (Object)(object)ActiveMglWeapon && allWeapon.activeSelf)
				{
					allWeapon.SetActive(false);
				}
			}
		}
		IsMglEquipped = true;
		gc.currentWeapon = ActiveMglWeapon;
		ActiveMglWeapon.SetActive(true);
		MglLauncher component = ActiveMglWeapon.GetComponent<MglLauncher>();
		if ((Object)(object)component != (Object)null)
		{
			component.ForceInstantReady();
		}
		WeaponIcon componentInChildren2 = ActiveMglWeapon.GetComponentInChildren<WeaponIcon>(true);
		if ((Object)(object)componentInChildren2 != (Object)null)
		{
			componentInChildren2.UpdateIcon();
		}
	}

	private static List<GameObject> GetSlotList(GunControl gc, int slotNumber)
	{
		return slotNumber switch
		{
			1 => gc.slot1, 
			2 => gc.slot2, 
			3 => gc.slot3, 
			4 => gc.slot4, 
			5 => gc.slot5, 
			6 => gc.slot6, 
			_ => null, 
		};
	}

	public static GameObject CreateMglWeapon(GunControl gc)
	{
		if ((Object)(object)gc == (Object)null || gc.slot5 == null)
		{
			return null;
		}
		if ((Object)(object)ActiveMglWeapon != (Object)null)
		{
			return ActiveMglWeapon;
		}
		GameObject val = ((IEnumerable<GameObject>)gc.slot5).FirstOrDefault((Func<GameObject, bool>)delegate(GameObject w)
		{
			if ((Object)(object)w == (Object)null)
			{
				return false;
			}
			RocketLauncher component3 = w.GetComponent<RocketLauncher>();
			return (Object)(object)component3 != (Object)null && component3.variation == 2;
		});
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		GameObject val2 = Object.Instantiate<GameObject>(val, val.transform.parent);
		((Object)val2).name = "Rocket Launcher MGL";
		val2.SetActive(false);
		RocketLauncher component = val2.GetComponent<RocketLauncher>();
		DisableNapalmVisuals(component, val2);
		MglLauncher mglLauncher = val2.AddComponent<MglLauncher>();
		mglLauncher.shootPoint = component.shootPoint;
		mglLauncher.muzzleFlash = component.muzzleFlash;
		mglLauncher.aud = val2.GetComponent<AudioSource>();
		mglLauncher.anim = val2.GetComponent<Animator>();
		if ((Object)(object)component.rocket != (Object)null)
		{
			Grenade component2 = component.rocket.GetComponent<Grenade>();
			if ((Object)(object)component2 != (Object)null && (Object)(object)component2.superExplosion != (Object)null)
			{
				mglLauncher.superExplosionPrefab = component2.superExplosion;
			}
		}
		MglLauncher.CacheGlobalPrefabs(mglLauncher.superExplosionPrefab);
		if ((Object)(object)MglModelPrefab != (Object)null)
		{
			ApplyCustomModel(val2, mglLauncher);
		}
		if ((Object)(object)MglCustomIcon != (Object)null)
		{
			ApplyCustomHudIcon(val2);
		}
		Object.Destroy((Object)(object)component);
		if (gc.allWeapons != null && !gc.allWeapons.Contains(val2))
		{
			gc.allWeapons.Add(val2);
		}
		if (gc.slotDict != null && !gc.slotDict.ContainsKey(val2))
		{
			gc.slotDict[val2] = 5;
		}
		ActiveMglWeapon = val2;
		IsMglEquipped = false;
		return val2;
	}

	private static void ApplyCustomHudIcon(GameObject mglObj)
	{
		WeaponIcon componentInChildren = mglObj.GetComponentInChildren<WeaponIcon>(true);
		if ((Object)(object)componentInChildren == (Object)null)
		{
			return;
		}
		if ((Object)(object)componentInChildren.weaponDescriptor != (Object)null)
		{
			WeaponDescriptor val = Object.Instantiate<WeaponDescriptor>(componentInChildren.weaponDescriptor);
			val.icon = MglCustomIcon;
			val.glowIcon = MglCustomIcon;
			componentInChildren.weaponDescriptor = val;
		}
		Image[] componentsInChildren = ((Component)componentInChildren).GetComponentsInChildren<Image>(true);
		foreach (Image val2 in componentsInChildren)
		{
			if ((Object)(object)val2 != (Object)null)
			{
				val2.sprite = MglCustomIcon;
			}
		}
	}

	private static void ApplyCustomModel(GameObject mglObj, MglLauncher mgl)
	{
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: 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)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0231: Unknown result type (might be due to invalid IL or missing references)
		Renderer[] componentsInChildren = mglObj.GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val in componentsInChildren)
		{
			val.enabled = false;
		}
		DisableWorldIndicators(mglObj);
		Camera[] componentsInParent = mglObj.GetComponentsInParent<Camera>(true);
		foreach (Camera val2 in componentsInParent)
		{
			if (val2.nearClipPlane > 0.01f)
			{
				val2.nearClipPlane = 0.01f;
			}
		}
		GameObject val3 = Object.Instantiate<GameObject>(MglModelPrefab, mglObj.transform);
		((Object)val3).name = "MGL_Visual";
		val3.transform.localPosition = mgl.baseLocalPos;
		val3.transform.localRotation = Quaternion.Euler(mgl.baseLocalRot);
		val3.transform.localScale = Vector3.one * 0.65f;
		mgl.visualTransform = val3.transform;
		int layer = mglObj.layer;
		Transform[] componentsInChildren2 = val3.GetComponentsInChildren<Transform>(true);
		foreach (Transform val4 in componentsInChildren2)
		{
			((Component)val4).gameObject.layer = layer;
		}
		Shader val5 = Shader.Find("ULTRAKILL/Standard");
		Renderer[] componentsInChildren3 = val3.GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val6 in componentsInChildren3)
		{
			val6.enabled = true;
			Material[] materials = val6.materials;
			foreach (Material val7 in materials)
			{
				if ((Object)(object)val7 == (Object)null)
				{
					continue;
				}
				Texture val8 = val7.mainTexture;
				if ((Object)(object)val8 == (Object)null && val7.HasProperty("baseColorTexture"))
				{
					val8 = val7.GetTexture("baseColorTexture");
				}
				if ((Object)(object)val8 != (Object)null)
				{
					val8.filterMode = (FilterMode)0;
				}
				if ((Object)(object)val5 != (Object)null)
				{
					Color color = (val7.HasProperty("_Color") ? val7.color : Color.white);
					val7.shader = val5;
					if ((Object)(object)val8 != (Object)null)
					{
						val7.mainTexture = val8;
					}
					if (val7.HasProperty("_Color"))
					{
						val7.color = color;
					}
				}
			}
		}
		Transform val9 = val3.transform.Find("ShootPoint");
		if ((Object)(object)val9 != (Object)null)
		{
			mgl.shootPoint = val9;
		}
	}

	public static void DisableWorldIndicators(GameObject mglObj)
	{
		if (!((Object)(object)mglObj == (Object)null))
		{
			Canvas[] componentsInChildren = mglObj.GetComponentsInChildren<Canvas>(true);
			foreach (Canvas val in componentsInChildren)
			{
				((Component)val).gameObject.SetActive(false);
			}
			Image[] componentsInChildren2 = mglObj.GetComponentsInChildren<Image>(true);
			foreach (Image val2 in componentsInChildren2)
			{
				((Behaviour)val2).enabled = false;
			}
		}
	}

	private static void DisableNapalmVisuals(RocketLauncher rl, GameObject root)
	{
		if ((Object)(object)rl != (Object)null)
		{
			FieldInfo[] fields = typeof(RocketLauncher).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			FieldInfo[] array = fields;
			foreach (FieldInfo fieldInfo in array)
			{
				if (!fieldInfo.Name.ToLower().Contains("napalm"))
				{
					continue;
				}
				object value = fieldInfo.GetValue(rl);
				GameObject val = (GameObject)((value is GameObject) ? value : null);
				if (val != null && (Object)(object)val != (Object)null && val.transform.IsChildOf(root.transform))
				{
					val.SetActive(false);
					continue;
				}
				Component val2 = (Component)((value is Component) ? value : null);
				if (val2 != null && (Object)(object)val2 != (Object)null && val2.transform.IsChildOf(root.transform))
				{
					val2.gameObject.SetActive(false);
				}
			}
		}
		ParticleSystem[] componentsInChildren = root.GetComponentsInChildren<ParticleSystem>(true);
		foreach (ParticleSystem val3 in componentsInChildren)
		{
			val3.Stop(true, (ParticleSystemStopBehavior)0);
			((Component)val3).gameObject.SetActive(false);
		}
	}
}
[HarmonyPatch(typeof(GunControl), "Start")]
public static class GunControlStartPatch
{
	[HarmonyPostfix]
	public static void Postfix(GunControl __instance)
	{
		MglPlugin.IsMglEquipped = false;
		MglPlugin.ActiveMglWeapon = null;
		MglPlugin.CreateMglWeapon(__instance);
	}
}
[HarmonyPatch(typeof(GunControl), "Update")]
public static class GunControlUpdatePatch
{
	[HarmonyPostfix]
	public static void Postfix(GunControl __instance)
	{
		if (MglPlugin.IsMglEquipped && !((Object)(object)MglPlugin.ActiveMglWeapon == (Object)null) && !((Object)(object)__instance == (Object)null) && (Object)(object)__instance.currentWeapon != (Object)(object)MglPlugin.ActiveMglWeapon)
		{
			if ((Object)(object)__instance.currentWeapon != (Object)null)
			{
				MglPlugin.IsMglEquipped = false;
				MglPlugin.ActiveMglWeapon.SetActive(false);
			}
			else
			{
				__instance.currentWeapon = MglPlugin.ActiveMglWeapon;
				MglPlugin.ActiveMglWeapon.SetActive(true);
			}
		}
	}
}
[HarmonyPatch(typeof(GunControl), "SwitchWeapon")]
public static class GunControlSwitchWeaponPatch
{
	[HarmonyPrefix]
	public static void Prefix()
	{
		if (MglPlugin.IsMglEquipped && (Object)(object)MglPlugin.ActiveMglWeapon != (Object)null)
		{
			MglPlugin.IsMglEquipped = false;
			MglPlugin.ActiveMglWeapon.SetActive(false);
		}
	}
}
[HarmonyPatch(typeof(GunSetter), "ResetWeapons")]
public static class GunSetterResetWeaponsPatch
{
	[HarmonyPostfix]
	public static void Postfix()
	{
		if ((Object)(object)MonoSingleton<GunControl>.Instance != (Object)null)
		{
			MglPlugin.ActiveMglWeapon = null;
			MglPlugin.IsMglEquipped = false;
			MglPlugin.CreateMglWeapon(MonoSingleton<GunControl>.Instance);
		}
	}
}
[HarmonyPatch(typeof(StyleHUD), "GetLocalizedName")]
public static class StyleHudGetLocalizedNamePatch
{
	[HarmonyPrefix]
	public static bool Prefix(string id, ref string __result)
	{
		switch (id)
		{
		case "mgl.exploded":
			__result = "ВЗОРВАН";
			return false;
		case "mgl.fireworks":
			__result = "<color=#00ffffff>ФЕЙРВЕРК</color>";
			return false;
		case "mgl.godaim":
			__result = "<color=green>ЕБЕЙШИЙ АИМ</color>";
			return false;
		default:
			return true;
		}
	}
}
[HarmonyPatch(typeof(WalkingBob), "Update")]
public static class WalkingBobPatch
{
	public struct BobState
	{
		public bool modified;

		public Vector3 origRight;

		public Vector3 origLeft;

		public Vector3 posBeforeUpdate;
	}

	private static readonly FieldInfo RightPosField = typeof(WalkingBob).GetField("rightPos", BindingFlags.Instance | BindingFlags.NonPublic);

	private static readonly FieldInfo LeftPosField = typeof(WalkingBob).GetField("leftPos", BindingFlags.Instance | BindingFlags.NonPublic);

	private static readonly FieldInfo OriginalPosField = typeof(WalkingBob).GetField("originalPos", BindingFlags.Instance | BindingFlags.NonPublic);

	private static readonly FieldInfo TargetField = typeof(WalkingBob).GetField("target", BindingFlags.Instance | BindingFlags.NonPublic);

	[HarmonyPrefix]
	public static void Prefix(WalkingBob __instance, out BobState __state)
	{
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: 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_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: 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_0187: Unknown result type (might be due to invalid IL or missing references)
		__state = new BobState
		{
			modified = false
		};
		if ((Object)(object)__instance == (Object)null || RightPosField == null || LeftPosField == null || OriginalPosField == null || !MglPlugin.IsMglEquipped || !((Object)(object)MglPlugin.ActiveMglWeapon != (Object)null))
		{
			return;
		}
		Vector3 val = (Vector3)OriginalPosField.GetValue(__instance);
		Vector3 val2 = (Vector3)RightPosField.GetValue(__instance);
		Vector3 val3 = (Vector3)LeftPosField.GetValue(__instance);
		__state.modified = true;
		__state.origRight = val2;
		__state.origLeft = val3;
		__state.posBeforeUpdate = ((Component)__instance).transform.localPosition;
		float num = 0.35f;
		Vector3 val4 = val + (val2 - val) * num;
		Vector3 val5 = val + (val3 - val) * num;
		RightPosField.SetValue(__instance, val4);
		LeftPosField.SetValue(__instance, val5);
		if (TargetField != null)
		{
			Vector3 val6 = (Vector3)TargetField.GetValue(__instance);
			if (val6 == val2)
			{
				TargetField.SetValue(__instance, val4);
			}
			else if (val6 == val3)
			{
				TargetField.SetValue(__instance, val5);
			}
		}
	}

	[HarmonyPostfix]
	public static void Postfix(WalkingBob __instance, BobState __state)
	{
		//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_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: 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)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: 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)
		//IL_00ee: 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_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		if (!__state.modified || (Object)(object)__instance == (Object)null)
		{
			return;
		}
		float num = 0.35f;
		Vector3 localPosition = ((Component)__instance).transform.localPosition;
		((Component)__instance).transform.localPosition = Vector3.Lerp(__state.posBeforeUpdate, localPosition, num);
		RightPosField.SetValue(__instance, __state.origRight);
		LeftPosField.SetValue(__instance, __state.origLeft);
		if (TargetField != null)
		{
			Vector3 val = (Vector3)TargetField.GetValue(__instance);
			Vector3 val2 = (Vector3)OriginalPosField.GetValue(__instance);
			Vector3 val3 = val2 + (__state.origRight - val2) * 0.35f;
			Vector3 val4 = val2 + (__state.origLeft - val2) * 0.35f;
			if (val == val3)
			{
				TargetField.SetValue(__instance, __state.origRight);
			}
			else if (val == val4)
			{
				TargetField.SetValue(__instance, __state.origLeft);
			}
		}
	}
}
[HarmonyPatch(typeof(EnemyIdentifier), "DeliverDamage")]
public static class EnemyDeliverDamagePatch
{
	[HarmonyPrefix]
	public static void Prefix(EnemyIdentifier __instance, ref bool __state)
	{
		__state = (Object)(object)__instance != (Object)null && !__instance.dead && __instance.health > 0f;
	}

	[HarmonyPostfix]
	public static void Postfix(EnemyIdentifier __instance, GameObject sourceWeapon, bool __state)
	{
		if (!__state || (Object)(object)__instance == (Object)null || !__instance.dead || (Object)(object)MglPlugin.ActiveMglWeapon == (Object)null || (Object)(object)sourceWeapon != (Object)(object)MglPlugin.ActiveMglWeapon)
		{
			return;
		}
		MglGrenadeMarker currentExplodingGrenade = MglGrenadeMarker.CurrentExplodingGrenade;
		if ((Object)(object)currentExplodingGrenade == (Object)null)
		{
			return;
		}
		StyleHUD instance = MonoSingleton<StyleHUD>.Instance;
		if ((Object)(object)instance != (Object)null && !__instance.puppet)
		{
			if (currentExplodingGrenade.triggeredFireworks)
			{
				instance.AddPoints(120, "mgl.fireworks", MglPlugin.ActiveMglWeapon, __instance, -1, "", "");
			}
			else
			{
				instance.AddPoints(45, "mgl.exploded", MglPlugin.ActiveMglWeapon, __instance, -1, "", "");
			}
		}
		if (currentExplodingGrenade.burstTracker != null)
		{
			currentExplodingGrenade.burstTracker.RegisterKill(currentExplodingGrenade.shotIndex, ((Object)__instance).GetInstanceID());
		}
	}
}
public class MglBurstTracker
{
	private readonly HashSet<int> shotsWithKills = new HashSet<int>();

	private readonly HashSet<int> countedEnemyIds = new HashSet<int>();

	private bool bonusAwarded = false;

	public void RegisterKill(int shotIndex, int enemyInstanceId)
	{
		if (bonusAwarded || countedEnemyIds.Contains(enemyInstanceId))
		{
			return;
		}
		countedEnemyIds.Add(enemyInstanceId);
		shotsWithKills.Add(shotIndex);
		if (shotsWithKills.Count >= 3)
		{
			bonusAwarded = true;
			StyleHUD instance = MonoSingleton<StyleHUD>.Instance;
			if ((Object)(object)instance != (Object)null && (Object)(object)MglPlugin.ActiveMglWeapon != (Object)null)
			{
				instance.AddPoints(250, "mgl.godaim", MglPlugin.ActiveMglWeapon, (EnemyIdentifier)null, -1, "", "");
			}
		}
	}
}
public class MglGrenadeMarker : MonoBehaviour
{
	public static MglGrenadeMarker CurrentExplodingGrenade;

	public static readonly List<MglGrenadeMarker> ActiveRemoteGrenades = new List<MglGrenadeMarker>();

	public MglBurstTracker burstTracker;

	public int shotIndex;

	public GameObject normalExplosion;

	public GameObject superExplosion;

	public bool isRemoteControlled = false;

	public bool triggeredFireworks = false;

	private bool hasDetonated = false;

	private void OnEnable()
	{
		if (isRemoteControlled && !ActiveRemoteGrenades.Contains(this))
		{
			ActiveRemoteGrenades.Add(this);
		}
	}

	private void OnDisable()
	{
		if (isRemoteControlled)
		{
			ActiveRemoteGrenades.Remove(this);
		}
	}

	private void OnTriggerEnter(Collider other)
	{
		if (!hasDetonated && !isRemoteControlled && !((Object)(object)other == (Object)null))
		{
			CheckAirborneDirectHit(other);
		}
	}

	private void OnCollisionEnter(Collision collision)
	{
		if (!hasDetonated && !isRemoteControlled && collision != null)
		{
			CheckAirborneDirectHit(collision.collider);
		}
	}

	private void CheckAirborneDirectHit(Collider col)
	{
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)col == (Object)null)
		{
			return;
		}
		EnemyIdentifierIdentifier component = ((Component)col).GetComponent<EnemyIdentifierIdentifier>();
		EnemyIdentifier val = (((Object)(object)component != (Object)null) ? component.eid : ((Component)col).GetComponentInParent<EnemyIdentifier>());
		if ((Object)(object)val == (Object)null || val.dead || val.health <= 0f)
		{
			return;
		}
		bool flag = false;
		if ((Object)(object)val.gce != (Object)null && !val.gce.onGround)
		{
			flag = true;
		}
		else
		{
			Rigidbody component2 = ((Component)val).GetComponent<Rigidbody>();
			if ((Object)(object)component2 != (Object)null && Mathf.Abs(component2.velocity.y) > 1.2f)
			{
				flag = true;
			}
		}
		if (flag)
		{
			triggeredFireworks = true;
			Projectile component3 = ((Component)this).GetComponent<Projectile>();
			if ((Object)(object)component3 != (Object)null && (Object)(object)superExplosion != (Object)null)
			{
				component3.explosionEffect = superExplosion;
			}
		}
	}

	public void RemoteDetonate()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		if (hasDetonated)
		{
			return;
		}
		hasDetonated = true;
		ActiveRemoteGrenades.Remove(this);
		GameObject val = normalExplosion;
		Collider[] array = Physics.OverlapSphere(((Component)this).transform.position, 4.5f);
		Collider[] array2 = array;
		foreach (Collider val2 in array2)
		{
			if ((Object)(object)val2 == (Object)null)
			{
				continue;
			}
			EnemyIdentifierIdentifier component = ((Component)val2).GetComponent<EnemyIdentifierIdentifier>();
			EnemyIdentifier val3 = (((Object)(object)component != (Object)null) ? component.eid : ((Component)val2).GetComponentInParent<EnemyIdentifier>());
			if ((Object)(object)val3 != (Object)null && !val3.dead && val3.health > 0f && (Object)(object)val3.gce != (Object)null && !val3.gce.onGround)
			{
				triggeredFireworks = true;
				if ((Object)(object)superExplosion != (Object)null)
				{
					val = superExplosion;
				}
				break;
			}
		}
		CurrentExplodingGrenade = this;
		if ((Object)(object)val != (Object)null)
		{
			GameObject val4 = Object.Instantiate<GameObject>(val, ((Component)this).transform.position, Quaternion.identity);
			Explosion[] componentsInChildren = val4.GetComponentsInChildren<Explosion>(true);
			foreach (Explosion val5 in componentsInChildren)
			{
				val5.sourceWeapon = MglPlugin.ActiveMglWeapon;
			}
		}
		CurrentExplodingGrenade = null;
		Object.Destroy((Object)(object)((Component)this).gameObject);
	}

	private void OnDestroy()
	{
		if (isRemoteControlled)
		{
			ActiveRemoteGrenades.Remove(this);
		}
		if (!hasDetonated)
		{
			hasDetonated = true;
			CurrentExplodingGrenade = this;
		}
	}
}
public class MglRemoteRollingGrenade : MonoBehaviour
{
	public Vector3 initialVelocity;

	private Rigidbody rb;

	private bool hasTouchedGround = false;

	private float spawnTime;

	private void Start()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		spawnTime = Time.time;
		PhysicMaterial val = new PhysicMaterial("MglRollingMat");
		val.bounciness = 0.55f;
		val.dynamicFriction = 0.08f;
		val.staticFriction = 0.08f;
		val.bounceCombine = (PhysicMaterialCombine)3;
		val.frictionCombine = (PhysicMaterialCombine)2;
		Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>(true);
		foreach (Collider val2 in componentsInChildren)
		{
			val2.isTrigger = false;
			val2.material = val;
		}
		rb = ((Component)this).GetComponent<Rigidbody>();
		if ((Object)(object)rb == (Object)null)
		{
			rb = ((Component)this).gameObject.AddComponent<Rigidbody>();
		}
		rb.isKinematic = false;
		rb.useGravity = true;
		rb.collisionDetectionMode = (CollisionDetectionMode)2;
		rb.drag = 0.1f;
		rb.angularDrag = 0.2f;
		rb.velocity = initialVelocity;
		rb.angularVelocity = new Vector3(Random.Range(-10f, 10f), Random.Range(-10f, 10f), Random.Range(-10f, 10f));
	}

	private void OnCollisionEnter(Collision collision)
	{
		if (collision != null && !((Object)(object)collision.gameObject == (Object)null) && !(Time.time - spawnTime < 0.08f) && !((Object)(object)collision.gameObject.GetComponentInParent<NewMovement>() != (Object)null) && !hasTouchedGround)
		{
			hasTouchedGround = true;
			if ((Object)(object)rb != (Object)null)
			{
				rb.drag = 1.45f;
				rb.angularDrag = 1.8f;
			}
		}
	}

	private void FixedUpdate()
	{
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: 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)
		//IL_0048: 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_0059: 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_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: 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)
		if ((Object)(object)rb == (Object)null)
		{
			return;
		}
		Vector3 velocity2;
		if (hasTouchedGround)
		{
			Vector3 velocity = rb.velocity;
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(velocity.x, 0f, velocity.z);
			val = Vector3.MoveTowards(val, Vector3.zero, Time.fixedDeltaTime * 1.4f);
			rb.velocity = new Vector3(val.x, velocity.y, val.z);
			velocity2 = rb.velocity;
			if (((Vector3)(ref velocity2)).sqrMagnitude < 0.05f)
			{
				rb.velocity = Vector3.zero;
				rb.angularVelocity = Vector3.zero;
			}
		}
		else
		{
			velocity2 = rb.velocity;
			if (((Vector3)(ref velocity2)).sqrMagnitude > 0.01f)
			{
				Transform transform = ((Component)this).transform;
				velocity2 = rb.velocity;
				transform.rotation = Quaternion.LookRotation(((Vector3)(ref velocity2)).normalized);
			}
		}
	}
}
public class MglLauncher : MonoBehaviour
{
	public static GameObject CachedGrenadePrefab;

	public static GameObject CachedExplosionPrefab;

	public static GameObject CachedSuperExplosionPrefab;

	public Transform shootPoint;

	public GameObject muzzleFlash;

	public AudioSource aud;

	public Animator anim;

	public GameObject grenadePrefab;

	public GameObject explosionPrefab;

	public GameObject superExplosionPrefab;

	public Transform visualTransform;

	public Vector3 baseLocalPos = new Vector3(0.15f, -0.145f, 0.08f);

	public Vector3 baseLocalRot = new Vector3(-1.5f, -3.5f, 0f);

	public int burstCount = 3;

	public float timeBetweenShots = 0.13f;

	public float burstCooldown = 0.85f;

	public float launchSpeed = 80f;

	public float upwardArc = 4.5f;

	public float grenadeDamage = 13.5f;

	private bool isFiring = false;

	private float cooldownTimer = 0f;

	private Vector3 currentRecoilPos = Vector3.zero;

	private Vector3 currentRecoilRot = Vector3.zero;

	private float equipProgress = 1f;

	public static void CacheGlobalPrefabs(GameObject knownSuperExplosion = null)
	{
		if ((Object)(object)knownSuperExplosion != (Object)null && (Object)(object)CachedSuperExplosionPrefab == (Object)null)
		{
			CachedSuperExplosionPrefab = knownSuperExplosion;
		}
		if ((Object)(object)CachedGrenadePrefab == (Object)null || (Object)(object)CachedExplosionPrefab == (Object)null)
		{
			Shotgun[] array = Resources.FindObjectsOfTypeAll<Shotgun>();
			Shotgun[] array2 = array;
			foreach (Shotgun val in array2)
			{
				if ((Object)(object)val != (Object)null && (Object)(object)val.bullet != (Object)null)
				{
					CachedGrenadePrefab = val.bullet;
					if ((Object)(object)val.explosion != (Object)null)
					{
						CachedExplosionPrefab = val.explosion;
					}
					break;
				}
			}
			if ((Object)(object)CachedExplosionPrefab == (Object)null && (Object)(object)MonoSingleton<DefaultReferenceManager>.Instance != (Object)null)
			{
				CachedExplosionPrefab = MonoSingleton<DefaultReferenceManager>.Instance.explosion;
			}
		}
		if (!((Object)(object)CachedSuperExplosionPrefab == (Object)null))
		{
			return;
		}
		Grenade[] array3 = Resources.FindObjectsOfTypeAll<Grenade>();
		Grenade[] array4 = array3;
		foreach (Grenade val2 in array4)
		{
			if ((Object)(object)val2 != (Object)null && (Object)(object)val2.superExplosion != (Object)null)
			{
				CachedSuperExplosionPrefab = val2.superExplosion;
				break;
			}
		}
	}

	public void ForceInstantReady()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: 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_0024: Unknown result type (might be due to invalid IL or missing references)
		isFiring = false;
		cooldownTimer = 0f;
		currentRecoilPos = Vector3.zero;
		currentRecoilRot = Vector3.zero;
		equipProgress = 0f;
		SyncFromCache();
	}

	private void SyncFromCache()
	{
		if ((Object)(object)CachedGrenadePrefab == (Object)null || (Object)(object)CachedExplosionPrefab == (Object)null || (Object)(object)CachedSuperExplosionPrefab == (Object)null)
		{
			CacheGlobalPrefabs(superExplosionPrefab);
		}
		if ((Object)(object)grenadePrefab == (Object)null)
		{
			grenadePrefab = CachedGrenadePrefab;
		}
		if ((Object)(object)explosionPrefab == (Object)null)
		{
			explosionPrefab = CachedExplosionPrefab;
		}
		if ((Object)(object)superExplosionPrefab == (Object)null)
		{
			superExplosionPrefab = CachedSuperExplosionPrefab;
		}
	}

	private void OnEnable()
	{
		ForceInstantReady();
		MglPlugin.DisableWorldIndicators(((Component)this).gameObject);
		WeaponIcon componentInChildren = ((Component)this).GetComponentInChildren<WeaponIcon>(true);
		if ((Object)(object)componentInChildren != (Object)null)
		{
			componentInChildren.UpdateIcon();
		}
		WeaponPos component = ((Component)this).GetComponent<WeaponPos>();
		if ((Object)(object)component != (Object)null)
		{
			component.CheckPosition();
		}
		if ((Object)(object)anim != (Object)null)
		{
			anim.Play("Equip", -1, 0f);
		}
	}

	private void OnDisable()
	{
		isFiring = false;
		((MonoBehaviour)this).StopAllCoroutines();
	}

	private void Update()
	{
		//IL_0063: 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_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: 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_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: 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_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: 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_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: 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)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		if (cooldownTimer > 0f)
		{
			cooldownTimer = Mathf.MoveTowards(cooldownTimer, 0f, Time.deltaTime);
		}
		if (equipProgress < 1f)
		{
			equipProgress = Mathf.MoveTowards(equipProgress, 1f, Time.deltaTime / 0.22f);
		}
		currentRecoilPos = Vector3.Lerp(currentRecoilPos, Vector3.zero, Time.deltaTime * 16f);
		currentRecoilRot = Vector3.Lerp(currentRecoilRot, Vector3.zero, Time.deltaTime * 16f);
		if ((Object)(object)visualTransform != (Object)null)
		{
			float num = 1f - Mathf.Pow(1f - equipProgress, 3f);
			Vector3 val = Vector3.Lerp(new Vector3(0f, -0.35f, -0.15f), Vector3.zero, num);
			Vector3 val2 = Vector3.Lerp(new Vector3(35f, 0f, 0f), Vector3.zero, num);
			visualTransform.localPosition = baseLocalPos + val + currentRecoilPos;
			visualTransform.localRotation = Quaternion.Euler(baseLocalRot + val2 + currentRecoilRot);
		}
		if (!MonoSingleton<GunControl>.Instance.activated || GameStateManager.Instance.PlayerInputLocked)
		{
			return;
		}
		MglGrenadeMarker.ActiveRemoteGrenades.RemoveAll((MglGrenadeMarker g) => (Object)(object)g == (Object)null);
		bool flag = MglGrenadeMarker.ActiveRemoteGrenades.Count > 0;
		if (MonoSingleton<InputManager>.Instance.InputSource.Fire2.WasPerformedThisFrame)
		{
			if (flag)
			{
				DetonateAllRemoteGrenades();
			}
			else if (!isFiring && cooldownTimer <= 0f)
			{
				SyncFromCache();
				if ((Object)(object)grenadePrefab != (Object)null)
				{
					((MonoBehaviour)this).StartCoroutine(FireBurst(remoteMode: true));
				}
			}
		}
		if (!flag && !isFiring && cooldownTimer <= 0f && MonoSingleton<InputManager>.Instance.InputSource.Fire1.IsPressed)
		{
			SyncFromCache();
			if ((Object)(object)grenadePrefab != (Object)null)
			{
				((MonoBehaviour)this).StartCoroutine(FireBurst(remoteMode: false));
			}
		}
	}

	private void DetonateAllRemoteGrenades()
	{
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		MglGrenadeMarker.ActiveRemoteGrenades.RemoveAll((MglGrenadeMarker g) => (Object)(object)g == (Object)null);
		if (MglGrenadeMarker.ActiveRemoteGrenades.Count == 0)
		{
			return;
		}
		if ((Object)(object)aud != (Object)null)
		{
			AudioSourceExtensions.SetPitch(aud, 1.45f);
			AudioSourceExtensions.Play(aud, true);
		}
		currentRecoilPos += new Vector3(0f, 0.025f, -0.02f);
		currentRecoilRot += new Vector3(-4f, 0f, 0f);
		List<MglGrenadeMarker> list = MglGrenadeMarker.ActiveRemoteGrenades.ToList();
		foreach (MglGrenadeMarker item in list)
		{
			if ((Object)(object)item != (Object)null)
			{
				item.RemoteDetonate();
			}
		}
	}

	private IEnumerator FireBurst(bool remoteMode)
	{
		isFiring = true;
		MglBurstTracker tracker = new MglBurstTracker();
		for (int i = 0; i < burstCount; i++)
		{
			FireSingleGrenade(tracker, i, remoteMode);
			if (i < burstCount - 1)
			{
				yield return (object)new WaitForSeconds(timeBetweenShots);
			}
		}
		cooldownTimer = burstCooldown;
		isFiring = false;
	}

	private void FireSingleGrenade(MglBurstTracker tracker, int shotIndex, bool remoteMode)
	{
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: 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)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0306: Unknown result type (might be due to invalid IL or missing references)
		CameraController instance = MonoSingleton<CameraController>.Instance;
		if ((Object)(object)aud != (Object)null)
		{
			AudioSourceExtensions.SetPitch(aud, remoteMode ? Random.Range(0.78f, 0.88f) : Random.Range(0.95f, 1.1f));
			AudioSourceExtensions.Play(aud, true);
		}
		if ((Object)(object)anim != (Object)null)
		{
			anim.Play("Fire", -1, 0f);
		}
		currentRecoilPos += new Vector3(0f, 0.015f, -0.07f);
		currentRecoilRot += new Vector3(-6.5f, 0f, 0f);
		Vector3 val = ((Component)instance).transform.position + ((Component)instance).transform.forward * 1.15f;
		GameObject val2 = Object.Instantiate<GameObject>(grenadePrefab, val, ((Component)instance).transform.rotation);
		if ((Object)(object)MonoSingleton<CameraFrustumTargeter>.Instance != (Object)null && Object.op_Implicit((Object)(object)MonoSingleton<CameraFrustumTargeter>.Instance.CurrentTarget) && MonoSingleton<CameraFrustumTargeter>.Instance.IsAutoAimed)
		{
			val2.transform.LookAt(MonoSingleton<CameraFrustumTargeter>.Instance.CurrentTargetAimPosition);
		}
		Vector3 val3 = val2.transform.forward * launchSpeed + Vector3.up * upwardArc;
		Projectile component = val2.GetComponent<Projectile>();
		if (remoteMode)
		{
			if ((Object)(object)component != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component);
			}
			MglGrenadeMarker mglGrenadeMarker = val2.AddComponent<MglGrenadeMarker>();
			mglGrenadeMarker.isRemoteControlled = true;
			mglGrenadeMarker.burstTracker = tracker;
			mglGrenadeMarker.shotIndex = shotIndex;
			mglGrenadeMarker.normalExplosion = explosionPrefab;
			mglGrenadeMarker.superExplosion = superExplosionPrefab;
			MglGrenadeMarker.ActiveRemoteGrenades.Add(mglGrenadeMarker);
			MglRemoteRollingGrenade mglRemoteRollingGrenade = val2.AddComponent<MglRemoteRollingGrenade>();
			mglRemoteRollingGrenade.initialVelocity = val3;
		}
		else
		{
			if ((Object)(object)component != (Object)null)
			{
				component.sourceWeapon = MglPlugin.ActiveMglWeapon;
				component.playerBullet = true;
				component.friendly = true;
				component.boosted = false;
				component.weaponType = "";
				component.bulletType = "mgl_grenade";
				component.damage = grenadeDamage;
				component.speed = 0f;
				component.ignoreExplosions = true;
				component.undeflectable = true;
				component.breakable = false;
				component.precheckForCollisions = true;
				if ((Object)(object)explosionPrefab != (Object)null)
				{
					component.explosionEffect = explosionPrefab;
				}
			}
			MglGrenadeMarker mglGrenadeMarker2 = val2.AddComponent<MglGrenadeMarker>();
			mglGrenadeMarker2.isRemoteControlled = false;
			mglGrenadeMarker2.burstTracker = tracker;
			mglGrenadeMarker2.shotIndex = shotIndex;
			mglGrenadeMarker2.normalExplosion = explosionPrefab;
			mglGrenadeMarker2.superExplosion = superExplosionPrefab;
			MglBallisticGrenade mglBallisticGrenade = val2.AddComponent<MglBallisticGrenade>();
			mglBallisticGrenade.velocity = val3;
		}
		Transform transform = val2.transform;
		transform.localScale *= 1.8f;
		instance.CameraShake(0.5f);
	}
}
public class MglBallisticGrenade : MonoBehaviour
{
	public Vector3 velocity;

	private Rigidbody rb;

	private void Awake()
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		rb = ((Component)this).GetComponent<Rigidbody>();
		if ((Object)(object)rb != (Object)null)
		{
			rb.useGravity = false;
			rb.velocity = velocity;
		}
	}

	private void FixedUpdate()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: 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_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: 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_006c: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)rb == (Object)null))
		{
			velocity += Physics.gravity * Time.fixedDeltaTime;
			rb.velocity = velocity;
			if (((Vector3)(ref velocity)).sqrMagnitude > 0.01f)
			{
				((Component)this).transform.rotation = Quaternion.LookRotation(((Vector3)(ref velocity)).normalized);
			}
		}
	}
}