Decompiled source of BetterExpandedWeaponSpawns v1.1.1

BetterExpandedWeaponSpawns.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using HarmonyLib;
using InControl;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using WeaponFramework;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("BetterExpandedWeaponSpawns")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+4af5d0f9d0a6f6abb3c7ce7ae9ff339184cb9c64")]
[assembly: AssemblyProduct("BetterExpandedWeaponSpawns")]
[assembly: AssemblyTitle("BetterExpandedWeaponSpawns")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace ExpandedWeapons;

[HarmonyPatch]
internal static class Bow
{
	private const float DrawTime = 0.6f;

	private const float MinDraw = 0.15f;

	private const float Overdraw = 1.4f;

	private static bool IsCharged(Fighting f)
	{
		if ((Object)(object)f != (Object)null && (Object)(object)f.weapon != (Object)null && f.weapon.isCharged)
		{
			return !MatchmakingHandler.IsNetworkMatch;
		}
		return false;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(Controller), "Attack")]
	private static bool BeforeAttack(Fighting ___fighting)
	{
		return !IsCharged(___fighting);
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(Controller), "Update")]
	private static void AfterUpdate(Controller __instance, Fighting ___fighting, CharacterActions ___mPlayerActions, bool ___mHasControl, CharacterInformation ___info)
	{
		if (!IsCharged(___fighting) || ___mPlayerActions == null || __instance.isAI || __instance.inactive || PauseManager.isPaused || ((Object)(object)___info != (Object)null && ___info.isDead) || (!GameManager.inFight && !GameManager.stillInMenu))
		{
			return;
		}
		Weapon weapon = ___fighting.weapon;
		if (___mHasControl && ((OneAxisInputControl)___mPlayerActions.PunchOrFire).IsPressed)
		{
			float num = weapon.maxChargeTime * 1.4f;
			weapon.currentCharge = Mathf.Min(num, weapon.currentCharge + Time.deltaTime * num / 0.6f);
		}
		else if (((OneAxisInputControl)___mPlayerActions.PunchOrFire).WasReleased && weapon.currentCharge > 0f)
		{
			bool flag = false;
			if (___mHasControl && weapon.currentCharge >= weapon.maxChargeTime * 0.15f)
			{
				float counter = ___fighting.counter;
				___fighting.Attack();
				flag = ___fighting.counter < counter;
			}
			if (!flag)
			{
				weapon.currentCharge = 0f;
			}
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(Weapon), "ActuallyShoot")]
	private static void AfterShoot(Weapon __instance)
	{
		if (__instance.isCharged && !MatchmakingHandler.IsNetworkMatch)
		{
			__instance.currentCharge = 0f;
		}
	}
}
internal static class FrameworkBridge
{
	public static void Register()
	{
		List<WeaponDefinition> list = new List<WeaponDefinition>();
		Add(list, (VanillaWeapon)8, "SHIELD", "gadgets", 6, "Blocks bullets.");
		Add(list, (VanillaWeapon)9, "FAN", "control", 4, "Blows everyone in front of you away.");
		Add(list, (VanillaWeapon)11, "BALL", "party", 6, null);
		WeaponDefinition obj = Add(list, (VanillaWeapon)13, "BOW", "rifles", 8, "Hold attack to draw, let go to shoot. 5 arrows.");
		obj.Ammo = 5;
		obj.ChargeTime = 0.6f;
		obj.ChargePower = 1.4f;
		Add(list, (VanillaWeapon)15, "LIGHTSABER", "melee", 5, null);
		Add(list, (VanillaWeapon)18, "TINY MINIGUN", "heavy", 4, null);
		Add(list, (VanillaWeapon)28, "LASER PLANTER", "gadgets", 3, null);
		Add(list, (VanillaWeapon)29, "HOLY SWORD", "godlike", 2, null);
		WeaponDefinition obj2 = Add(list, (VanillaWeapon)30, "GOD MINIGUN", "godlike", 1, "Each hit sticks a golden sword in that strikes for 25 a moment later. 200 shots.");
		obj2.Ammo = 200;
		obj2.ConfigurePickup = delegate(GameObject p)
		{
			ModelledPickup(p, 30);
		};
		Add(list, (VanillaWeapon)34, "LAVA WHIP", "lava", 2, null).ConfigurePickup = delegate(GameObject p)
		{
			ModelledPickup(p, 34);
		};
		foreach (WeaponDefinition item in list)
		{
			WeaponRegistry.Add(item);
		}
		Plugin.Log.LogInfo((object)("Weapon Framework found: the " + list.Count + " hidden weapons are in its weapon page."));
	}

	private static void ModelledPickup(GameObject pickup, int index)
	{
		ControllerHandler instance = ControllerHandler.Instance;
		Weapon val = (((Object)(object)instance != (Object)null && (Object)(object)instance.playerPrefab != (Object)null) ? Spawning.FindWeapon(instance.playerPrefab, index) : null);
		if ((Object)(object)val != (Object)null)
		{
			PickupModel.Build(pickup, val);
		}
	}

	private static WeaponDefinition Add(List<WeaponDefinition> list, VanillaWeapon w, string name, string category, int tickets, string description)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		WeaponDefinition val = WeaponDefinition.FromExisting("bews." + name.Replace(" ", "").ToLowerInvariant(), name, w);
		val.Category = category;
		val.Rarity = tickets;
		val.Description = description;
		val.OnByDefault = false;
		val.Mod = "Better Expanded Weapon Spawns";
		list.Add(val);
		return val;
	}
}
[HarmonyPatch(typeof(WeaponSelectionHandler), "Start")]
internal static class MenuRow
{
	private const float RowSqueeze = 0.9f;

	private const float Box = 15f;

	private const float BoxToText = 8f;

	private const float Gap = 37f;

	private const float GridStart = -22f;

	private const float GridEnd = 1426f;

	private static void Prefix(WeaponSelectionHandler __instance)
	{
		try
		{
			Build(__instance);
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("Couldn't add the Special row: " + ex));
		}
	}

	private static void Build(WeaponSelectionHandler handler)
	{
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Expected O, but got Unknown
		//IL_00a4: 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)
		//IL_00b0: 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_00c0: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: 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_011e: 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_0129: Unknown result type (might be due to invalid IL or missing references)
		WeaponCategoryTAG[] componentsInChildren = ((Component)handler).GetComponentsInChildren<WeaponCategoryTAG>();
		if (componentsInChildren.Length < 2)
		{
			Plugin.Log.LogError((object)"Weapon menu not found.");
			return;
		}
		WeaponCategoryTAG val = componentsInChildren[^1];
		Transform parent = ((Component)val).transform.parent;
		GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, parent, false);
		((Object)val2).name = "Special";
		val2.transform.SetSiblingIndex(((Component)val).transform.GetSiblingIndex() + 1);
		Toggle component = ((Component)val2.transform.Find("Toggle")).GetComponent<Toggle>();
		((TMP_Text)((Component)component).GetComponentInChildren<TextMeshProUGUI>()).text = "Special".ToUpperInvariant();
		RectTransform val3 = (RectTransform)((Component)componentsInChildren[0]).transform;
		Vector2 val4 = (((RectTransform)((Component)val).transform).anchoredPosition - val3.anchoredPosition) / (float)(componentsInChildren.Length - 1) * 0.9f;
		for (int i = 1; i < componentsInChildren.Length; i++)
		{
			((RectTransform)((Component)componentsInChildren[i]).transform).anchoredPosition = val3.anchoredPosition + val4 * (float)i;
		}
		((RectTransform)val2.transform).anchoredPosition = val3.anchoredPosition + val4 * (float)componentsInChildren.Length;
		WeaponCategoryTAG[] array = componentsInChildren;
		for (int j = 0; j < array.Length; j++)
		{
			Rechain(((Component)array[j]).transform.Find("Grid"));
		}
		List<Toggle> toggles = FillGrid(val2.transform.Find("Grid"));
		LayOut(toggles);
		Wire(toggles, component, ((Component)((Component)val).transform.Find("Grid")).GetComponentsInChildren<Toggle>(true), ((Component)parent).GetComponentInChildren<Button>());
	}

	private static List<Toggle> FillGrid(Transform grid)
	{
		List<Toggle> list = new List<Toggle>(((Component)grid).GetComponentsInChildren<Toggle>(true));
		while (list.Count < Specials.All.Length)
		{
			Toggle val = list[list.Count - 1];
			list.Add(Object.Instantiate<GameObject>(((Component)val).gameObject, ((Component)val).transform.parent, false).GetComponent<Toggle>());
		}
		for (int num = list.Count - 1; num >= Specials.All.Length; num--)
		{
			Object.DestroyImmediate((Object)(object)((Component)list[num]).gameObject);
			list.RemoveAt(num);
		}
		for (int i = 0; i < list.Count; i++)
		{
			((Object)((Component)list[i]).gameObject).name = Specials.All[i].Label;
			((TMP_Text)((Component)list[i]).GetComponentInChildren<TextMeshProUGUI>()).text = Specials.All[i].Label.ToUpperInvariant();
			list[i].isOn = false;
		}
		return list;
	}

	private static void LayOut(List<Toggle> toggles)
	{
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Expected O, but got Unknown
		//IL_00df: 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_0102: 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_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Expected O, but got Unknown
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		TextMeshProUGUI[] array = (TextMeshProUGUI[])(object)new TextMeshProUGUI[toggles.Count];
		float[] array2 = new float[toggles.Count];
		float num = 0f;
		for (int i = 0; i < toggles.Count; i++)
		{
			array[i] = ((Component)toggles[i]).GetComponentInChildren<TextMeshProUGUI>();
			((TMP_Text)array[i]).enableWordWrapping = false;
			array2[i] = ((TMP_Text)array[i]).GetPreferredValues(((TMP_Text)array[i]).text).x;
			num += array2[i];
		}
		float num2 = (float)toggles.Count * 23f + (float)(toggles.Count - 1) * 37f;
		float num3 = Mathf.Min(1f, (1448f - num2) / num);
		float num4 = -22f;
		for (int j = 0; j < toggles.Count; j++)
		{
			float num5 = array2[j] * num3;
			float num6 = 23f + num5;
			RectTransform val = (RectTransform)((Component)toggles[j]).transform;
			val.sizeDelta = new Vector2(num6, val.sizeDelta.y);
			val.anchoredPosition = new Vector2(num4 + num6 / 2f, val.anchoredPosition.y);
			RectTransform val2 = (RectTransform)((Component)toggles[j]).transform.Find("Background");
			if ((Object)(object)val2 != (Object)null)
			{
				val2.anchoredPosition = new Vector2((0f - num6) / 2f + 7.5f, val2.anchoredPosition.y);
			}
			TextMeshProUGUI obj = array[j];
			((TMP_Text)obj).fontSize = ((TMP_Text)obj).fontSize * num3;
			RectTransform rectTransform = ((TMP_Text)array[j]).rectTransform;
			float num7 = num5 + 10f;
			rectTransform.sizeDelta = new Vector2(num7, rectTransform.sizeDelta.y);
			rectTransform.anchoredPosition = new Vector2((0f - num6) / 2f + 15f + 8f + num7 / 2f, rectTransform.anchoredPosition.y);
			num4 += num6 + 37f;
		}
	}

	private static void Wire(List<Toggle> toggles, Toggle category, Toggle[] above, Button back)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: 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_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Invalid comparison between Unknown and I4
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: 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_00e2: Invalid comparison between Unknown and I4
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < toggles.Count; i++)
		{
			Navigation navigation = ((Selectable)toggles[i]).navigation;
			((Navigation)(ref navigation)).mode = (Mode)4;
			((Navigation)(ref navigation)).selectOnLeft = (Selectable)(object)((i > 0) ? toggles[i - 1] : category);
			((Navigation)(ref navigation)).selectOnRight = (Selectable)(object)((i < toggles.Count - 1) ? toggles[i + 1] : null);
			((Navigation)(ref navigation)).selectOnUp = Nearest(above, toggles[i]);
			((Navigation)(ref navigation)).selectOnDown = (Selectable)(object)back;
			((Selectable)toggles[i]).navigation = navigation;
		}
		foreach (Toggle val in above)
		{
			Navigation navigation2 = ((Selectable)val).navigation;
			if ((int)((Navigation)(ref navigation2)).mode == 4)
			{
				((Navigation)(ref navigation2)).selectOnDown = Nearest(toggles.ToArray(), val);
				((Selectable)val).navigation = navigation2;
			}
		}
		if ((Object)(object)back != (Object)null)
		{
			Navigation navigation3 = ((Selectable)back).navigation;
			if ((int)((Navigation)(ref navigation3)).mode == 4)
			{
				((Navigation)(ref navigation3)).selectOnUp = (Selectable)(object)category;
				((Selectable)back).navigation = navigation3;
			}
		}
	}

	private static void Rechain(Transform grid)
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Invalid comparison between Unknown and I4
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)grid == (Object)null)
		{
			return;
		}
		List<Toggle> list = new List<Toggle>(((Component)grid).GetComponentsInChildren<Toggle>(true));
		list.Sort((Toggle a, Toggle b) => ((RectTransform)((Component)a).transform).anchoredPosition.x.CompareTo(((RectTransform)((Component)b).transform).anchoredPosition.x));
		for (int num = 0; num < list.Count; num++)
		{
			Navigation navigation = ((Selectable)list[num]).navigation;
			if ((int)((Navigation)(ref navigation)).mode == 4)
			{
				if (num > 0)
				{
					((Navigation)(ref navigation)).selectOnLeft = (Selectable)(object)list[num - 1];
				}
				if (num < list.Count - 1)
				{
					((Navigation)(ref navigation)).selectOnRight = (Selectable)(object)list[num + 1];
				}
				((Selectable)list[num]).navigation = navigation;
			}
		}
	}

	private static Selectable Nearest(Toggle[] candidates, Toggle to)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: 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_0037: Unknown result type (might be due to invalid IL or missing references)
		Toggle result = null;
		float num = float.MaxValue;
		float x = ((RectTransform)((Component)to).transform).anchoredPosition.x;
		foreach (Toggle val in candidates)
		{
			float num2 = Mathf.Abs(((RectTransform)((Component)val).transform).anchoredPosition.x - x);
			if (num2 < num)
			{
				num = num2;
				result = val;
			}
		}
		return (Selectable)(object)result;
	}
}
[HarmonyPatch(typeof(WeaponSelectionHandler), "GetWeaponObjectFromPlayer")]
internal static class SpecialLookup
{
	private static bool Prefix(string weaponName, ref byte index, ref Weapon __result, GameObject ___m_PlayerObject)
	{
		Special special = Specials.ByLabel(weaponName);
		if (special == null)
		{
			return true;
		}
		Weapon val = Spawning.FindWeapon(___m_PlayerObject, special.Index);
		if ((Object)(object)val == (Object)null)
		{
			ManualLogSource log = Plugin.Log;
			byte index2 = special.Index;
			log.LogError((object)("No weapon " + index2 + " on the player."));
			return true;
		}
		index = special.Index;
		__result = val;
		return false;
	}
}
internal static class PickupFix
{
	public static void Apply(Harmony h)
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		MethodInfo methodInfo = AccessTools.Method(typeof(WeaponPickUp), "Awake", (Type[])null, (Type[])null);
		if ((object)methodInfo != null)
		{
			h.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(PickupFix), "AfterAwake", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}

	private static void AfterAwake(WeaponPickUp __instance)
	{
		PunchForce[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<PunchForce>(true);
		foreach (PunchForce obj in componentsInChildren)
		{
			((Behaviour)obj).enabled = false;
			Object.Destroy((Object)(object)obj);
		}
	}
}
internal static class PickupModel
{
	private const int KeptSegments = 1;

	public static void Build(GameObject pickup, Weapon held)
	{
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: 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_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0278: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0286: Unknown result type (might be due to invalid IL or missing references)
		//IL_0271: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a0: 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_02a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: 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_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: 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_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: 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_014b: 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)
		//IL_015d: 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_0170: 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_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0308: Unknown result type (might be due to invalid IL or missing references)
		//IL_030a: Unknown result type (might be due to invalid IL or missing references)
		//IL_030c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0301: Unknown result type (might be due to invalid IL or missing references)
		//IL_0311: Unknown result type (might be due to invalid IL or missing references)
		//IL_0315: Unknown result type (might be due to invalid IL or missing references)
		//IL_032c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: 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_037a: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_021e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0222: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: Unknown result type (might be due to invalid IL or missing references)
		//IL_023d: Unknown result type (might be due to invalid IL or missing references)
		//IL_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_024a: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: 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)
		//IL_0232: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		PhysicMaterial sharedMaterial = null;
		BoxCollider componentInChildren = pickup.GetComponentInChildren<BoxCollider>(true);
		if ((Object)(object)componentInChildren != (Object)null)
		{
			sharedMaterial = ((Collider)componentInChildren).sharedMaterial;
		}
		for (int num = pickup.transform.childCount - 1; num >= 0; num--)
		{
			Object.DestroyImmediate((Object)(object)((Component)pickup.transform.GetChild(num)).gameObject);
		}
		Transform transform = ((Component)held).transform;
		Dictionary<Transform, int> depth = SegmentDepths(held);
		Matrix4x4 worldToLocalMatrix = transform.worldToLocalMatrix;
		bool flag = false;
		Vector3 val = Vector3.zero;
		Vector3 val2 = Vector3.zero;
		MeshRenderer[] componentsInChildren = ((Component)held).GetComponentsInChildren<MeshRenderer>(true);
		foreach (MeshRenderer val3 in componentsInChildren)
		{
			MeshFilter component = ((Component)val3).GetComponent<MeshFilter>();
			if (!((Renderer)val3).enabled || (Object)(object)component == (Object)null || (Object)(object)component.sharedMesh == (Object)null || !ActiveUnder(((Component)val3).transform, transform) || Depth(((Component)val3).transform, transform, depth) > 1)
			{
				continue;
			}
			Matrix4x4 val4 = worldToLocalMatrix * ((Component)val3).transform.localToWorldMatrix;
			GameObject val5 = new GameObject(((Object)val3).name)
			{
				layer = pickup.layer
			};
			val5.transform.SetParent(pickup.transform, false);
			val5.transform.localPosition = Vector4.op_Implicit(((Matrix4x4)(ref val4)).GetColumn(3));
			val5.transform.localRotation = Quaternion.LookRotation(Vector4.op_Implicit(((Matrix4x4)(ref val4)).GetColumn(2)), Vector4.op_Implicit(((Matrix4x4)(ref val4)).GetColumn(1)));
			Transform transform2 = val5.transform;
			Vector4 column = ((Matrix4x4)(ref val4)).GetColumn(0);
			float magnitude = ((Vector4)(ref column)).magnitude;
			column = ((Matrix4x4)(ref val4)).GetColumn(1);
			float magnitude2 = ((Vector4)(ref column)).magnitude;
			column = ((Matrix4x4)(ref val4)).GetColumn(2);
			transform2.localScale = new Vector3(magnitude, magnitude2, ((Vector4)(ref column)).magnitude);
			val5.AddComponent<MeshFilter>().sharedMesh = component.sharedMesh;
			((Renderer)val5.AddComponent<MeshRenderer>()).sharedMaterials = ((Renderer)val3).sharedMaterials;
			Bounds bounds = component.sharedMesh.bounds;
			for (int j = 0; j < 8; j++)
			{
				Vector3 val6 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((j & 1) != 0) ? 1 : (-1)), (float)(((j & 2) != 0) ? 1 : (-1)), (float)(((j & 4) != 0) ? 1 : (-1))));
				Vector3 val7 = ((Matrix4x4)(ref val4)).MultiplyPoint3x4(val6);
				if (!flag)
				{
					val = (val2 = val7);
					flag = true;
				}
				else
				{
					val = Vector3.Min(val, val7);
					val2 = Vector3.Max(val2, val7);
				}
			}
		}
		Vector3 val8 = (flag ? ((val + val2) * 0.5f) : Vector3.zero);
		for (int k = 0; k < pickup.transform.childCount; k++)
		{
			Transform child = pickup.transform.GetChild(k);
			child.localPosition -= val8;
		}
		GameObject val9 = new GameObject("BOX")
		{
			layer = pickup.layer
		};
		val9.transform.SetParent(pickup.transform, false);
		BoxCollider obj = val9.AddComponent<BoxCollider>();
		Vector3 val10 = (flag ? (val2 - val) : (Vector3.one * 0.5f));
		val10.x = Mathf.Max(val10.x, 0.3f);
		obj.size = val10;
		((Collider)obj).sharedMaterial = sharedMaterial;
		Rigidbody component2 = pickup.GetComponent<Rigidbody>();
		Rigidbody val11 = (((Object)(object)held.weaponDrop != (Object)null) ? held.weaponDrop.GetComponent<Rigidbody>() : null);
		if ((Object)(object)component2 != (Object)null)
		{
			component2.constraints = (RigidbodyConstraints)((!((Object)(object)val11 != (Object)null)) ? 2 : ((int)val11.constraints));
		}
	}

	private static Dictionary<Transform, int> SegmentDepths(Weapon held)
	{
		Dictionary<Transform, Joint> dictionary = new Dictionary<Transform, Joint>();
		Joint[] componentsInChildren = ((Component)held).GetComponentsInChildren<Joint>(true);
		foreach (Joint val in componentsInChildren)
		{
			if ((Object)(object)((Component)val).transform != (Object)(object)((Component)held).transform)
			{
				dictionary[((Component)val).transform] = val;
			}
		}
		Dictionary<Transform, int> dictionary2 = new Dictionary<Transform, int>();
		foreach (Transform key in dictionary.Keys)
		{
			int num = 0;
			Transform val2 = key;
			Joint value;
			while ((Object)(object)val2 != (Object)null && dictionary.TryGetValue(val2, out value) && num < 64)
			{
				num++;
				val2 = (((Object)(object)value.connectedBody != (Object)null) ? ((Component)value.connectedBody).transform : null);
			}
			dictionary2[key] = num;
		}
		return dictionary2;
	}

	private static int Depth(Transform t, Transform root, Dictionary<Transform, int> depth)
	{
		while ((Object)(object)t != (Object)null && (Object)(object)t != (Object)(object)root)
		{
			if (depth.TryGetValue(t, out var value))
			{
				return value;
			}
			t = t.parent;
		}
		return 0;
	}

	private static bool ActiveUnder(Transform t, Transform root)
	{
		while ((Object)(object)t != (Object)null && (Object)(object)t != (Object)(object)root)
		{
			if (!((Component)t).gameObject.activeSelf)
			{
				return false;
			}
			t = t.parent;
		}
		return (Object)(object)t == (Object)(object)root;
	}
}
[BepInPlugin("stickfight.betterexpandedweaponspawns", "BetterExpandedWeaponSpawns", "1.1.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	public const string Guid = "stickfight.betterexpandedweaponspawns";

	public const string Name = "BetterExpandedWeaponSpawns";

	public const string Version = "1.1.1";

	private const string FrameworkGuid = "stickfight.weaponframework";

	internal static ManualLogSource Log;

	private void Awake()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		Harmony val = new Harmony("stickfight.betterexpandedweaponspawns");
		if (Chainloader.PluginInfos.ContainsKey("stickfight.weaponframework"))
		{
			FrameworkBridge.Register();
		}
		else
		{
			val.PatchAll(typeof(Plugin).Assembly);
		}
		PickupFix.Apply(val);
		WhipPlane.Apply(val);
		Log.LogInfo((object)"BetterExpandedWeaponSpawns 1.1.1 loaded.");
	}
}
[HarmonyPatch]
internal static class Spawning
{
	private static GameObject templates;

	public static Weapon FindWeapon(GameObject player, int index)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		Transform val = player.transform.Find("Weapons");
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		foreach (Transform item in val)
		{
			Transform val2 = item;
			string name = ((Object)val2).name;
			int num = 0;
			int i;
			for (i = 0; i < name.Length && char.IsDigit(name[i]); i++)
			{
				num = num * 10 + (name[i] - 48);
			}
			if (i > 0 && num == index)
			{
				return ((Component)val2).GetComponent<Weapon>();
			}
		}
		return null;
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(WeaponSelectionHandler), "InitWeaponList")]
	private static void AfterInit(List<SingleWeaponUI> ___m_Weapons, GameObject[] ___m_WeaponObjects, GameObject ___m_PlayerObject)
	{
		GameObject val = null;
		foreach (GameObject val2 in ___m_WeaponObjects)
		{
			if ((Object)(object)val2 != (Object)null && (Object)(object)val2.GetComponent<WeaponPickUp>() != (Object)null)
			{
				val = val2;
				break;
			}
		}
		StringBuilder stringBuilder = new StringBuilder("Special weapons:");
		foreach (SingleWeaponUI ___m_Weapon in ___m_Weapons)
		{
			if (___m_Weapon.Category != "Special")
			{
				continue;
			}
			Special special = Specials.ByLabel(___m_Weapon.WeaponName);
			Weapon val3 = FindWeapon(___m_PlayerObject, ___m_Weapon.WeaponIndex);
			if (special != null && !((Object)(object)val3 == (Object)null))
			{
				___m_Weapon.Rarity = special.Rarity;
				if (special.Ammo > 0)
				{
					val3.startBullets = special.Ammo;
				}
				WeaponPickUp val4 = (((Object)(object)val3.weaponDrop != (Object)null) ? val3.weaponDrop.GetComponent<WeaponPickUp>() : null);
				if (((Object)(object)val4 == (Object)null || val4.id != special.Index) && (Object)(object)val != (Object)null)
				{
					val3.weaponDrop = MakePickup(((Object)(object)val4 != (Object)null) ? ((Component)val4).gameObject : val, special.Index, val3);
				}
				___m_WeaponObjects[special.Index] = val3.weaponDrop;
				stringBuilder.AppendFormat(" {0}={1}", special.Label, ___m_Weapon.IsLocallyActive ? "on" : "off");
			}
		}
		Plugin.Log.LogInfo((object)stringBuilder.ToString());
	}

	private static GameObject MakePickup(GameObject basePickup, byte index, Weapon held)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		if ((Object)(object)templates == (Object)null)
		{
			templates = new GameObject("ExpandedWeaponsTemplates");
			templates.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)templates);
		}
		GameObject obj = Object.Instantiate<GameObject>(basePickup, templates.transform, false);
		((Object)obj).name = "Pickup " + index;
		obj.GetComponent<WeaponPickUp>().id = index;
		PickupModel.Build(obj, held);
		return obj;
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(WeaponSelectionHandler), "GenerateWeaponRarityArray")]
	private static void AfterGenerate(List<byte> ___m_WeaponRaritiesArray)
	{
		if (MatchmakingHandler.IsNetworkMatch)
		{
			___m_WeaponRaritiesArray.RemoveAll((byte b) => Specials.IsSpecial(b));
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(WeaponSelectionHandler), "GetRandomWeaponIndex")]
	private static void BeforeDraw(List<byte> ___m_WeaponRaritiesArray)
	{
		if (MatchmakingHandler.IsNetworkMatch)
		{
			___m_WeaponRaritiesArray?.RemoveAll((byte b) => Specials.IsSpecial(b));
		}
	}
}
internal sealed class Special
{
	public readonly byte Index;

	public readonly string Label;

	public readonly byte Rarity;

	public readonly int Ammo;

	public Special(byte index, string label, byte rarity, int ammo = 0)
	{
		Index = index;
		Label = label;
		Rarity = rarity;
		Ammo = ammo;
	}
}
internal static class Specials
{
	public const string Category = "Special";

	public static readonly Special[] All;

	private static readonly HashSet<byte> indices;

	static Specials()
	{
		All = new Special[10]
		{
			new Special(8, "Shield", 6),
			new Special(9, "Fan", 4),
			new Special(11, "Ball", 6),
			new Special(13, "Bow", 8, 5),
			new Special(15, "Lightsaber", 5),
			new Special(18, "Tiny Minigun", 4),
			new Special(28, "Laser Planter", 3),
			new Special(29, "Holy Sword", 2),
			new Special(30, "God Minigun", 1, 200),
			new Special(34, "Lava Whip", 2)
		};
		indices = new HashSet<byte>();
		Special[] all = All;
		foreach (Special special in all)
		{
			indices.Add(special.Index);
		}
	}

	public static bool IsSpecial(int index)
	{
		if (index >= 0 && index < 256)
		{
			return indices.Contains((byte)index);
		}
		return false;
	}

	public static Special ByLabel(string label)
	{
		string text = Squash(label);
		Special[] all = All;
		foreach (Special special in all)
		{
			if (Squash(special.Label) == text)
			{
				return special;
			}
		}
		return null;
	}

	private static string Squash(string s)
	{
		return s.Trim().Replace(" ", string.Empty).ToLowerInvariant();
	}
}
internal static class WhipPlane
{
	private const int WhipIndex = 34;

	public static void Apply(Harmony h)
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		MethodInfo methodInfo = AccessTools.Method(typeof(Fighting), "Start", (Type[])null, (Type[])null);
		if ((object)methodInfo != null)
		{
			h.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(WhipPlane), "AfterStart", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}

	private static void AfterStart(Fighting __instance)
	{
		Weapon val = Spawning.FindWeapon(((Component)__instance).gameObject, 34);
		if ((Object)(object)val == (Object)null || MatchmakingHandler.IsNetworkMatch)
		{
			return;
		}
		Rigidbody[] componentsInChildren = ((Component)val).GetComponentsInChildren<Rigidbody>(true);
		foreach (Rigidbody val2 in componentsInChildren)
		{
			if ((Object)(object)((Component)val2).transform != (Object)(object)((Component)val).transform)
			{
				val2.constraints = (RigidbodyConstraints)98;
			}
		}
	}
}