Decompiled source of SkyfallArtillery v0.7.0

BepInEx/plugins/SkyfallArtillery/SkyfallArtillery.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Xml;
using BepInEx;
using BepInEx.Configuration;
using DM;
using Landfall.TABS;
using Landfall.TABS.GameState;
using Landfall.TABS.UnitEditor;
using ModdingForDummies.AssetManagement;
using ModdingForDummies.TABSSimp;
using Sirenix.Serialization;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ModdingForDummies")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ModdingForDummies")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("1619c49c-bc45-486c-bbca-6b52cef4f478")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ModdingForDummies
{
	[BepInPlugin("skyfall.tabs.artillery", "Skyfall Artillery Prototype", "0.7.0")]
	public class Launcher : BaseUnityPlugin
	{
		private static bool bootstrapped;

		public Launcher()
		{
			//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)
			//IL_003d: Expected O, but got Unknown
			Debug.Log((object)"[Skyfall] Loading TABS artillery v0.7.0 (public release)...");
			SkyfallArtillerySettings.Config = ((BaseUnityPlugin)this).Config;
			AssetImporter.Initialize();
			if (!bootstrapped)
			{
				bootstrapped = true;
				GameObject val = new GameObject("SkyfallRuntime");
				Object.DontDestroyOnLoad((Object)val);
				val.AddComponent<SkyfallRuntimeManager>();
			}
			new Main();
		}
	}
	public class Main : Mod
	{
		public Main()
		{
			Mod.DEV_MODE = false;
			try
			{
				ModFaction modFaction = Mod.CreateFaction("Skyfall Artillery");
				if (modFaction == null)
				{
					Debug.LogError((object)"[Skyfall] Could not create the faction.");
					return;
				}
				modFaction.Color("#65735E");
				modFaction.Icon = Mod.GetIcon("Cannon");
				ModWeapon modWeapon = Mod.CreateWeapon("Skyfall High-Arc Tank Weapon", "Tank Barrel");
				if (modWeapon == null || modWeapon.Type != WeaponType.Ranged || modWeapon.Ranged == null || modWeapon.Ranged.Projectile == null)
				{
					Debug.LogError((object)"[Skyfall] 'Tank Barrel' not found or not ranged. Turn DEV_MODE on and inspect MFDPrints/weapons.txt.");
					return;
				}
				modWeapon.Cooldown = 3600f;
				modWeapon.AttackRange = 420f;
				modWeapon.StartCooldown = true;
				modWeapon.Ranged.ProjectileAmount = 1;
				modWeapon.Ranged.Spread = 0f;
				modWeapon.Ranged.Recoil = 0f;
				ModProjectile projectile = modWeapon.Ranged.Projectile;
				projectile.Size = 0.8f;
				ModExplosion modExplosion = projectile.Explosion;
				if (modExplosion == null || (Object)(object)modExplosion.internalObject == (Object)null)
				{
					Debug.LogWarning((object)"[Skyfall] No native Tank Round explosion wrapper; using Bomb Cannon fallback.");
					modExplosion = Mod.CreateExplosion("Skyfall Tank-Like Impact", "ExplosionBombCannon");
					if (modExplosion != null)
					{
						modExplosion.Radius = 5f;
					}
				}
				SkyfallTankArc skyfallTankArc = projectile.internalObject.AddComponent<SkyfallTankArc>();
				skyfallTankArc.ExplosionPrefab = modExplosion?.internalObject;
				Explosion val = (((Object)(object)skyfallTankArc.ExplosionPrefab != (Object)null) ? skyfallTankArc.ExplosionPrefab.GetComponentInChildren<Explosion>(true) : null);
				SkyfallArtillerySettings.Initialize(((Object)(object)val != (Object)null) ? val.radius : 5f);
				SkyfallArtilleryGroundTargetAI.ProjectilePrefab = projectile.internalObject;
				if ((Object)(object)skyfallTankArc.ExplosionPrefab == (Object)null)
				{
					Debug.LogWarning((object)"[Skyfall] No explosion prefab found. Impact may remove the shell without an effect.");
				}
				ModUnit modUnit = modFaction.NewUnit("Skyfall Field Cannon", "Cannon");
				if (modUnit != null)
				{
					modUnit.Health = 200f;
					modUnit.Cost = 1600;
					modUnit.Mass = 5f;
					modUnit.Speed = 0.01f;
					modUnit.Icon = Mod.GetIcon("Cannon");
					modUnit.RightWeapon = modWeapon;
				}
				Debug.Log((object)"[SkyfallArtillery067] Registered field cannon; authorized one-shot indirect fire active.");
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("[Skyfall] v0.6 registration failed: " + ex));
			}
		}
	}
	public class SkyfallRuntimeManager : MonoBehaviour
	{
		private bool settingsOpen;

		private Rect settingsWindow = new Rect(30f, 80f, 440f, 495f);

		private GUISkin styledSkin;

		private GUIStyle panelStyle;

		private GUIStyle cardStyle;

		private GUIStyle titleStyle;

		private GUIStyle helpStyle;

		private GUIStyle sectionStyle;

		private GUIStyle valueStyle;

		private readonly List<Texture2D> menuTextures = new List<Texture2D>();

		private Vector2 menuScroll;

		private Texture2D MenuTint(Color color)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false);
			val.SetPixel(0, 0, color);
			val.Apply();
			menuTextures.Add(val);
			return val;
		}

		private GUIStyle MenuSurface(GUIStyle source, Color color, int pad)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0037: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(source);
			val.normal.background = MenuTint(color);
			val.border = new RectOffset(0, 0, 0, 0);
			val.padding = new RectOffset(pad, pad, pad, pad);
			return val;
		}

		private void EnsureMenuStyles()
		{
			//IL_006d: 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_00af: Expected O, but got Unknown
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			//IL_00fd: 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_015b: 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_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Expected O, but got Unknown
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Expected O, but got Unknown
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Expected O, but got Unknown
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Expected O, but got Unknown
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)styledSkin != (Object)null))
			{
				styledSkin = Object.Instantiate<GUISkin>(GUI.skin);
				Color val = default(Color);
				((Color)(ref val))..ctor(0.94f, 0.96f, 0.99f);
				Color textColor = default(Color);
				((Color)(ref textColor))..ctor(0.68f, 0.73f, 0.8f);
				styledSkin.label.fontSize = 13;
				styledSkin.label.normal.textColor = val;
				styledSkin.label.wordWrap = true;
				styledSkin.button.fontSize = 13;
				styledSkin.button.border = new RectOffset(0, 0, 0, 0);
				styledSkin.button.padding = new RectOffset(8, 8, 5, 5);
				styledSkin.button.fixedHeight = 0f;
				styledSkin.button.normal.background = MenuTint(new Color(0.19f, 0.22f, 0.27f));
				styledSkin.button.hover.background = MenuTint(new Color(0.26f, 0.3f, 0.37f));
				styledSkin.button.active.background = MenuTint(new Color(0.32f, 0.39f, 0.49f));
				GUIStyleState normal = styledSkin.button.normal;
				GUIStyleState hover = styledSkin.button.hover;
				GUIStyleState active = styledSkin.button.active;
				Color val2 = (styledSkin.button.focused.textColor = val);
				Color val4 = (active.textColor = val2);
				Color textColor2 = (hover.textColor = val4);
				normal.textColor = textColor2;
				panelStyle = MenuSurface(GUI.skin.window, new Color(0.09f, 0.11f, 0.14f, 0.98f), 12);
				panelStyle.onNormal.background = panelStyle.normal.background;
				panelStyle.focused.background = panelStyle.normal.background;
				panelStyle.onFocused.background = panelStyle.normal.background;
				panelStyle.active.background = panelStyle.normal.background;
				panelStyle.onActive.background = panelStyle.normal.background;
				cardStyle = MenuSurface(GUI.skin.box, new Color(0.14f, 0.16f, 0.2f), 9);
				titleStyle = new GUIStyle(styledSkin.label)
				{
					fontSize = 20,
					fontStyle = (FontStyle)1
				};
				sectionStyle = new GUIStyle(styledSkin.label)
				{
					fontSize = 13,
					fontStyle = (FontStyle)1
				};
				helpStyle = new GUIStyle(styledSkin.label)
				{
					fontSize = 12,
					wordWrap = true
				};
				helpStyle.normal.textColor = textColor;
				valueStyle = new GUIStyle(styledSkin.label)
				{
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)5,
					wordWrap = false
				};
				valueStyle.normal.textColor = new Color(0.67f, 0.79f, 1f);
			}
		}

		private void OnDestroy()
		{
			foreach (Texture2D menuTexture in menuTextures)
			{
				if ((Object)(object)menuTexture != (Object)null)
				{
					Object.Destroy((Object)(object)menuTexture);
				}
			}
			menuTextures.Clear();
			if ((Object)(object)styledSkin != (Object)null)
			{
				Object.Destroy((Object)(object)styledSkin);
			}
		}

		private void Update()
		{
			SkyfallBattleGate.Active();
			if ((Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307)) && Input.GetKeyDown((KeyCode)110))
			{
				settingsOpen = !settingsOpen;
			}
		}

		private void OnGUI()
		{
			//IL_0146: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Expected O, but got Unknown
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Invalid comparison between Unknown and I4
			if (!settingsOpen || !SkyfallArtillerySettings.Ready)
			{
				return;
			}
			GUISkin skin = GUI.skin;
			try
			{
				EnsureMenuStyles();
				GUI.skin = styledSkin;
				((Rect)(ref settingsWindow)).width = Mathf.Min(440f, (float)Screen.width - 16f);
				((Rect)(ref settingsWindow)).height = Mathf.Min(495f, (float)Screen.height - 16f);
				((Rect)(ref settingsWindow)).x = Mathf.Clamp(((Rect)(ref settingsWindow)).x, 0f, Mathf.Max(0f, (float)Screen.width - ((Rect)(ref settingsWindow)).width));
				((Rect)(ref settingsWindow)).y = Mathf.Clamp(((Rect)(ref settingsWindow)).y, 0f, Mathf.Max(0f, (float)Screen.height - ((Rect)(ref settingsWindow)).height));
				settingsWindow = GUI.Window(((Object)this).GetInstanceID(), settingsWindow, new WindowFunction(DrawSettings), "", panelStyle);
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[SkyfallArtillery0700] Settings menu: " + ex.Message));
				settingsOpen = false;
			}
			finally
			{
				GUI.skin = skin;
				Event current = Event.current;
				if (current != null && ((Rect)(ref settingsWindow)).Contains(current.mousePosition) && (current.isMouse || (int)current.type == 6))
				{
					current.Use();
				}
			}
		}

		private float SettingSlider(string name, string description, float current, float min, float max, float step, string unit, string format)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(name, sectionStyle, Array.Empty<GUILayoutOption>());
			GUILayout.FlexibleSpace();
			GUILayout.Label(current.ToString(format) + unit, valueStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) });
			GUILayout.EndHorizontal();
			GUILayout.Label(description, helpStyle, Array.Empty<GUILayoutOption>());
			if (max <= min)
			{
				return min;
			}
			float num = GUILayout.HorizontalSlider(current, min, max, Array.Empty<GUILayoutOption>());
			if (Mathf.Abs(num - current) <= 0.0001f)
			{
				return current;
			}
			return Mathf.Clamp(Mathf.Round(num / step) * step, min, max);
		}

		private void DrawSettings(int id)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("SKYFALL ARTILLERY", titleStyle, Array.Empty<GUILayoutOption>());
			GUILayout.FlexibleSpace();
			if (GUILayout.Button("Hide", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(64f) }))
			{
				settingsOpen = false;
			}
			GUILayout.EndHorizontal();
			GUILayout.Label("Settings apply to all Skyfall Field Cannons.", helpStyle, Array.Empty<GUILayoutOption>());
			menuScroll = GUILayout.BeginScrollView(menuScroll, Array.Empty<GUILayoutOption>());
			try
			{
				GUILayout.BeginVertical(cardStyle, Array.Empty<GUILayoutOption>());
				GUILayout.Label("EXPLOSION", sectionStyle, Array.Empty<GUILayoutOption>());
				GUILayout.Space(4f);
				float num = SettingSlider("Explosion Damage", "Maximum in-game HP damage at the center.", SkyfallArtillerySettings.Damage, 0f, 1000f, 1f, " HP", "F0");
				GUILayout.Space(8f);
				float r = SettingSlider("Blast Radius", "How far the explosion reaches in game units.", SkyfallArtillerySettings.Radius, 0.5f, Mathf.Max(30f, SkyfallArtillerySettings.DefaultRadius), 0.1f, " units", "F1");
				GUILayout.Space(8f);
				float e = SettingSlider("Edge Damage", "Damage at the outer edge of the explosion.", Mathf.Min(SkyfallArtillerySettings.EdgeDamage, num), 0f, num, 1f, " HP", "F0");
				GUILayout.EndVertical();
				GUILayout.Space(6f);
				GUILayout.BeginVertical(cardStyle, Array.Empty<GUILayoutOption>());
				GUILayout.Label("RELOAD", sectionStyle, Array.Empty<GUILayoutOption>());
				float t = SettingSlider("Reload Time", "Time between game shots. Lower = faster. Applies to new reloads.", SkyfallArtillerySettings.ReloadTime, 1f, 60f, 0.5f, " sec", "F1");
				GUILayout.EndVertical();
				SkyfallArtillerySettings.Set(num, r, e, t);
			}
			finally
			{
				GUILayout.EndScrollView();
			}
			GUILayout.Space(6f);
			if (GUILayout.Button("Reset to Defaults", Array.Empty<GUILayoutOption>()))
			{
				SkyfallArtillerySettings.Reset();
			}
			GUILayout.Label("Settings save automatically.  |  Alt + N  |  v0.7.0", helpStyle, Array.Empty<GUILayoutOption>());
			GUI.DragWindow(new Rect(0f, 0f, Mathf.Max(0f, ((Rect)(ref settingsWindow)).width - 85f), 34f));
		}

		private IEnumerator Start()
		{
			while (true)
			{
				try
				{
					ScanForCannons();
				}
				catch (Exception ex)
				{
					Debug.LogError((object)("[Skyfall] Runtime scan failed: " + ex));
				}
				yield return (object)new WaitForSeconds(1.25f);
			}
		}

		private void ScanForCannons()
		{
			MonoBehaviour[] array = Object.FindObjectsOfType<MonoBehaviour>();
			foreach (MonoBehaviour val in array)
			{
				if ((Object)(object)val == (Object)null || ((object)val).GetType().Name != "Unit")
				{
					continue;
				}
				Unit val2 = (Unit)(object)((val is Unit) ? val : null);
				if ((Object)(object)val2 == (Object)null || (Object)(object)val2.unitBlueprint == (Object)null || val2.unitBlueprint.Entity == null)
				{
					continue;
				}
				string name = val2.unitBlueprint.Entity.Name;
				bool flag = name == "Skyfall Field Cannon";
				if (flag && !((Object)(object)val2.data == (Object)null) && !val2.data.Dead)
				{
					if ((Object)(object)((Component)val).GetComponent<SkyfallArtilleryGroundTargetAI>() == (Object)null)
					{
						((Component)val).gameObject.AddComponent<SkyfallArtilleryGroundTargetAI>();
						Debug.Log((object)("[SkyfallArtillery066] Indirect-fire controller added: " + name));
					}
					Transform root = ((Component)val).transform.root;
					if (!((Object)(object)root == (Object)null) && flag && !((Object)(object)((Component)root).GetComponentInChildren<SkyfallFieldGunVisual>(true) != (Object)null) && LooksLikeSkyfallCannon(root))
					{
						((Component)root).gameObject.AddComponent<SkyfallFieldGunVisual>();
						Debug.Log((object)("[Skyfall] Attached custom field-gun model to: " + ((Object)root).name));
					}
				}
			}
		}

		private bool LooksLikeSkyfallCannon(Transform root)
		{
			bool flag = false;
			WeaponHandler[] componentsInChildren = ((Component)root).GetComponentsInChildren<WeaponHandler>(true);
			foreach (WeaponHandler val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && (((Object)(object)val.rightWeapon != (Object)null && val.rightWeapon.maxRange >= 350f) || ((Object)(object)val.leftWeapon != (Object)null && val.leftWeapon.maxRange >= 350f)))
				{
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				return false;
			}
			string text = ((((Object)root).name != null) ? ((Object)root).name.ToLowerInvariant() : string.Empty);
			if (text.Contains("cannon") || text.Contains("skyfall"))
			{
				return true;
			}
			Transform[] componentsInChildren2 = ((Component)root).GetComponentsInChildren<Transform>(true);
			foreach (Transform val2 in componentsInChildren2)
			{
				string text2 = ((((Object)val2).name != null) ? ((Object)val2).name.ToLowerInvariant() : string.Empty);
				if (text2.Contains("cannon") || text2.Contains("wheel") || text2.Contains("barrel"))
				{
					return true;
				}
			}
			return false;
		}
	}
	internal static class SkyfallArtillerySettings
	{
		internal static ConfigFile Config;

		private static ConfigEntry<float> damage;

		private static ConfigEntry<float> radius;

		private static ConfigEntry<float> edge;

		private static ConfigEntry<float> reload;

		internal const float DefaultReloadTime = 7.5f;

		internal static float DefaultRadius { get; private set; }

		internal static bool Ready
		{
			get
			{
				if (damage != null && radius != null && edge != null)
				{
					return reload != null;
				}
				return false;
			}
		}

		internal static float Damage
		{
			get
			{
				if (!Ready)
				{
					return 450f;
				}
				return Mathf.Clamp(damage.Value, 0f, 1000f);
			}
		}

		internal static float Radius
		{
			get
			{
				if (!Ready)
				{
					return Mathf.Max(0.5f, DefaultRadius);
				}
				return Mathf.Clamp(radius.Value, 0.5f, Mathf.Max(30f, DefaultRadius));
			}
		}

		internal static float EdgeDamage
		{
			get
			{
				if (!Ready)
				{
					return 60f;
				}
				return Mathf.Clamp(edge.Value, 0f, Damage);
			}
		}

		internal static float ReloadTime
		{
			get
			{
				if (!Ready)
				{
					return 7.5f;
				}
				return Mathf.Clamp(reload.Value, 1f, 60f);
			}
		}

		internal static void Initialize(float nativeRadius)
		{
			if (!Ready)
			{
				DefaultRadius = ((nativeRadius > 0f) ? nativeRadius : 5f);
				if (Config != null)
				{
					damage = Config.Bind<float>("Explosion", "Damage", 450f, "Maximum in-game HP damage at the center.");
					radius = Config.Bind<float>("Explosion", "Radius", DefaultRadius, "Explosion radius in TABS game units.");
					edge = Config.Bind<float>("Explosion", "EdgeDamage", 60f, "In-game HP damage at the edge of the explosion.");
					reload = Config.Bind<float>("Reload", "ReloadTime", 7.5f, "Seconds between game shots. New reloads use the current value.");
					Debug.Log((object)("[SkyfallArtillery0700] Settings loaded: damage=" + Damage + " radius=" + Radius + " edge=" + EdgeDamage + " native radius=" + DefaultRadius + " reload=" + ReloadTime));
				}
			}
		}

		internal static void Set(float d, float r, float e, float t)
		{
			if (Ready)
			{
				d = Mathf.Clamp(d, 0f, 1000f);
				r = Mathf.Clamp(r, 0.5f, Mathf.Max(30f, DefaultRadius));
				e = Mathf.Clamp(e, 0f, d);
				if (Mathf.Abs(damage.Value - d) > 0.001f)
				{
					damage.Value = d;
				}
				if (Mathf.Abs(radius.Value - r) > 0.001f)
				{
					radius.Value = r;
				}
				if (Mathf.Abs(edge.Value - e) > 0.001f)
				{
					edge.Value = e;
				}
				t = Mathf.Clamp(t, 1f, 60f);
				if (Mathf.Abs(reload.Value - t) > 0.001f)
				{
					reload.Value = t;
				}
			}
		}

		internal static void Reset()
		{
			Set(450f, DefaultRadius, 60f, 7.5f);
		}
	}
	internal static class SkyfallArtilleryGroundTargets
	{
		private static Unit[] cachedUnits;

		private static float nextRosterRefresh;

		internal static Unit[] Units()
		{
			if (cachedUnits == null || Time.time >= nextRosterRefresh)
			{
				cachedUnits = Object.FindObjectsOfType<Unit>();
				nextRosterRefresh = Time.time + 0.35f;
			}
			return cachedUnits;
		}

		internal static bool IsAircraft(Unit candidate)
		{
			if ((Object)(object)candidate == (Object)null)
			{
				return false;
			}
			string text = "";
			if ((Object)(object)candidate.unitBlueprint != (Object)null && candidate.unitBlueprint.Entity != null)
			{
				text = candidate.unitBlueprint.Entity.Name ?? "";
			}
			if (text.IndexOf("Fighter", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Bomber", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Aircraft", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Airplane", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Plane", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Spitfire", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Bf 109", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
			MonoBehaviour[] componentsInChildren = ((Component)candidate).GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null))
				{
					switch (((object)val).GetType().Name)
					{
					case "SkyfallFighterAI":
					case "SkyfallAircraftAI":
					case "SkyfallDiveBomberAI":
						return true;
					}
				}
			}
			return false;
		}

		internal static Transform AimTransform(Unit candidate)
		{
			if ((Object)(object)candidate == (Object)null || (Object)(object)candidate.data == (Object)null)
			{
				return null;
			}
			if (!((Object)(object)candidate.data.mainRig != (Object)null))
			{
				return ((Component)candidate).transform;
			}
			return ((Component)candidate.data.mainRig).transform;
		}

		internal static bool IsHighAndUnsupported(Unit candidate, Vector3 origin)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			Transform val = AimTransform(candidate);
			if ((Object)(object)val == (Object)null || val.position.y <= origin.y + 17f)
			{
				return false;
			}
			RaycastHit val2 = default(RaycastHit);
			return !Physics.Raycast(val.position + Vector3.up * 0.5f, Vector3.down, ref val2, 13f, -5, (QueryTriggerInteraction)1);
		}

		internal static bool IsGroundEnemy(Unit shooter, Unit candidate, Vector3 origin)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)shooter == (Object)null || (Object)(object)candidate == (Object)null || (Object)(object)candidate == (Object)(object)shooter || (Object)(object)shooter.data == (Object)null || (Object)(object)candidate.data == (Object)null || candidate.data.Dead || !((Component)candidate).gameObject.activeInHierarchy || shooter.Team == candidate.Team || IsAircraft(candidate))
			{
				return false;
			}
			return !IsHighAndUnsupported(candidate, origin);
		}

		internal static Unit ClosestGroundEnemy(Unit shooter, Vector3 origin, float range)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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)
			if ((Object)(object)shooter == (Object)null || (Object)(object)shooter.data == (Object)null || shooter.data.Dead)
			{
				return null;
			}
			Unit result = null;
			float num = range * range;
			Unit[] array = Units();
			foreach (Unit val in array)
			{
				if (!IsGroundEnemy(shooter, val, origin))
				{
					continue;
				}
				Transform val2 = AimTransform(val);
				if (!((Object)(object)val2 == (Object)null))
				{
					Vector3 val3 = val2.position - origin;
					float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
					if (!(sqrMagnitude >= num))
					{
						result = val;
						num = sqrMagnitude;
					}
				}
			}
			return result;
		}

		internal static Unit ChooseGameTarget(SkyfallArtilleryGroundTargetAI requester, Unit shooter, Vector3 origin, float range, HashSet<Unit> hitUnits, out bool recycled)
		{
			//IL_0050: 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_0073: 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_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			recycled = false;
			if ((Object)(object)shooter == (Object)null || (Object)(object)shooter.data == (Object)null || shooter.data.Dead)
			{
				return null;
			}
			List<Unit> list = new List<Unit>();
			List<Unit> list2 = new List<Unit>();
			float num = range * range;
			Unit[] array = Units();
			Vector3 val3;
			foreach (Unit val in array)
			{
				if (!IsGroundEnemy(shooter, val, origin))
				{
					continue;
				}
				Transform val2 = AimTransform(val);
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				val3 = val2.position - origin;
				if (!(((Vector3)(ref val3)).sqrMagnitude >= num))
				{
					list.Add(val);
					if (!hitUnits.Contains(val))
					{
						list2.Add(val);
					}
				}
			}
			if (list.Count == 0)
			{
				return null;
			}
			if (list2.Count == 0)
			{
				hitUnits.Clear();
				recycled = true;
				list2 = list;
			}
			List<Unit> list3 = new List<Unit>();
			foreach (Unit item in list2)
			{
				if (!SkyfallArtilleryGroundTargetAI.SelectedByAnother(requester, item))
				{
					list3.Add(item);
				}
			}
			if (list3.Count == 0)
			{
				return null;
			}
			List<Unit> list4 = new List<Unit>();
			float num2 = SkyfallArtillerySettings.Radius * SkyfallArtillerySettings.Radius;
			foreach (Unit item2 in list3)
			{
				Transform val4 = AimTransform(item2);
				if ((Object)(object)val4 == (Object)null)
				{
					continue;
				}
				int num3 = 0;
				foreach (Unit item3 in list2)
				{
					Transform val5 = AimTransform(item3);
					if (!((Object)(object)val5 == (Object)null))
					{
						val3 = val5.position - val4.position;
						if (((Vector3)(ref val3)).sqrMagnitude <= num2 && ++num3 >= 3)
						{
							break;
						}
					}
				}
				if (num3 >= 3)
				{
					list4.Add(item2);
				}
			}
			List<Unit> list5 = ((list4.Count > 0) ? list4 : list3);
			return list5[Random.Range(0, list5.Count)];
		}

		internal static void SetNativeTarget(Unit shooter, Unit target)
		{
			if ((Object)(object)shooter == (Object)null || (Object)(object)shooter.data == (Object)null)
			{
				return;
			}
			object data = shooter.data;
			Rigidbody val = (((Object)(object)target != (Object)null && (Object)(object)target.data != (Object)null) ? target.data.mainRig : null);
			Type type = data.GetType();
			try
			{
				while (type != null)
				{
					FieldInfo field = type.GetField("targetMainRig", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field != null)
					{
						if ((Object)(object)val == (Object)null)
						{
							field.SetValue(data, null);
						}
						else if (field.FieldType.IsInstanceOfType(val))
						{
							field.SetValue(data, val);
						}
						else if (field.FieldType.IsInstanceOfType(((Component)val).transform))
						{
							field.SetValue(data, ((Component)val).transform);
						}
						break;
					}
					PropertyInfo property = type.GetProperty("targetMainRig", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (property != null && property.CanWrite)
					{
						if ((Object)(object)val == (Object)null)
						{
							property.SetValue(data, null, null);
						}
						else if (property.PropertyType.IsInstanceOfType(val))
						{
							property.SetValue(data, val, null);
						}
						else if (property.PropertyType.IsInstanceOfType(((Component)val).transform))
						{
							property.SetValue(data, ((Component)val).transform, null);
						}
						break;
					}
					type = type.BaseType;
				}
			}
			catch (Exception)
			{
			}
		}
	}
	internal static class SkyfallBattleGate
	{
		private static bool previousActive;

		private static int epoch;

		internal static int Epoch => epoch;

		internal static bool Active()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			bool flag = false;
			try
			{
				GameStateManager service = ServiceLocator.GetService<GameStateManager>();
				flag = service != null && (int)service.GameState == 1;
			}
			catch (Exception)
			{
				flag = false;
			}
			if (flag != previousActive)
			{
				previousActive = flag;
				epoch++;
			}
			return flag;
		}
	}
	public class SkyfallArtilleryGroundTargetAI : MonoBehaviour
	{
		internal static GameObject ProjectilePrefab;

		private const float MaxRange = 420f;

		private Unit shooter;

		private Unit selected;

		private readonly HashSet<Unit> hitUnits = new HashSet<Unit>();

		private bool reconsiderAfterImpact;

		private static readonly HashSet<SkyfallArtilleryGroundTargetAI> ActiveCannons = new HashSet<SkyfallArtilleryGroundTargetAI>();

		private float nextSearch;

		private float nextFire;

		private static readonly Dictionary<int, float> NextAuthorizedShot = new Dictionary<int, float>();

		private readonly Dictionary<WeaponHandler, bool> originalHandlerStates = new Dictionary<WeaponHandler, bool>();

		private bool warnedNoProjectile;

		private int activeEpoch = -1;

		internal static bool SelectedByAnother(SkyfallArtilleryGroundTargetAI requester, Unit candidate)
		{
			if ((Object)(object)candidate == (Object)null)
			{
				return false;
			}
			foreach (SkyfallArtilleryGroundTargetAI activeCannon in ActiveCannons)
			{
				if (!((Object)(object)activeCannon == (Object)null) && !((Object)(object)activeCannon == (Object)(object)requester) && ((Behaviour)activeCannon).isActiveAndEnabled && activeCannon.activeEpoch == SkyfallBattleGate.Epoch && !((Object)(object)activeCannon.selected != (Object)(object)candidate) && !((Object)(object)activeCannon.shooter == (Object)null) && !((Object)(object)activeCannon.shooter.data == (Object)null) && !activeCannon.shooter.data.Dead && activeCannon.ValidSelection(candidate))
				{
					return true;
				}
			}
			return false;
		}

		private void OnEnable()
		{
			ActiveCannons.Add(this);
		}

		internal void RegisterImpact(List<Unit> damaged, int epoch)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			if (epoch != activeEpoch || !SkyfallBattleGate.Active())
			{
				return;
			}
			foreach (Unit item in damaged)
			{
				if ((Object)(object)item != (Object)null && (Object)(object)shooter != (Object)null && item.Team != shooter.Team)
				{
					hitUnits.Add(item);
				}
			}
			if ((Object)(object)selected != (Object)null && hitUnits.Contains(selected))
			{
				selected = null;
				nextSearch = 0f;
			}
			reconsiderAfterImpact = true;
		}

		private void Awake()
		{
			shooter = ((Component)this).GetComponent<Unit>();
			nextFire = float.PositiveInfinity;
			SuppressNativeFiring();
		}

		private void Update()
		{
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)shooter == (Object)null || (Object)(object)shooter.data == (Object)null || shooter.data.Dead)
			{
				if (activeEpoch != -1)
				{
					ResetBattleSchedule();
				}
				return;
			}
			SuppressNativeFiring();
			if (!SkyfallBattleGate.Active())
			{
				ResetBattleSchedule();
				return;
			}
			if (activeEpoch != SkyfallBattleGate.Epoch)
			{
				ResetBattleSchedule();
				activeEpoch = SkyfallBattleGate.Epoch;
				nextFire = Time.time + 1f;
			}
			if (Time.time >= nextSearch || ((Object)(object)selected != (Object)null && !ValidSelection(selected)))
			{
				if (reconsiderAfterImpact || !ValidSelection(selected))
				{
					Unit val = selected;
					selected = SkyfallArtilleryGroundTargets.ChooseGameTarget(this, shooter, ((Component)shooter).transform.position, 420f, hitUnits, out var recycled);
					reconsiderAfterImpact = false;
					if ((Object)(object)selected != (Object)null && (Object)(object)selected != (Object)(object)val)
					{
						Debug.Log((object)("[SkyfallArtillery0700] TABS selection: cannon=" + ((Object)shooter).GetInstanceID() + " unit=" + ((Object)selected).GetInstanceID()));
					}
					if (recycled)
					{
						Debug.Log((object)"[SkyfallArtillery0700] All eligible targets previously hit; starting new selection cycle.");
					}
				}
				nextSearch = Time.time + 0.18f;
			}
			SkyfallArtilleryGroundTargets.SetNativeTarget(shooter, selected);
			if ((Object)(object)selected != (Object)null && Time.time >= nextFire)
			{
				FireIndirectRound();
			}
		}

		private void ResetBattleSchedule()
		{
			if ((Object)(object)shooter != (Object)null && activeEpoch != -1)
			{
				NextAuthorizedShot.Remove(((Object)shooter).GetInstanceID());
			}
			activeEpoch = -1;
			selected = null;
			hitUnits.Clear();
			reconsiderAfterImpact = false;
			nextSearch = 0f;
			nextFire = float.PositiveInfinity;
		}

		private bool ValidSelection(Unit unit)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			if (!SkyfallArtilleryGroundTargets.IsGroundEnemy(shooter, unit, ((Component)shooter).transform.position))
			{
				return false;
			}
			Transform val = SkyfallArtilleryGroundTargets.AimTransform(unit);
			if ((Object)(object)val != (Object)null)
			{
				Vector3 val2 = val.position - ((Component)shooter).transform.position;
				return ((Vector3)(ref val2)).sqrMagnitude <= 176400f;
			}
			return false;
		}

		private void FireIndirectRound()
		{
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: 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_00d5: 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_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_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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: 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)
			//IL_00b8: 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_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			if (!SkyfallBattleGate.Active() || activeEpoch != SkyfallBattleGate.Epoch || !ValidSelection(selected))
			{
				return;
			}
			int instanceID = ((Object)shooter).GetInstanceID();
			if (NextAuthorizedShot.TryGetValue(instanceID, out var value) && Time.time >= 0f && Time.time < value)
			{
				nextFire = Mathf.Max(nextFire, value);
				return;
			}
			if ((Object)(object)ProjectilePrefab == (Object)null)
			{
				if (!warnedNoProjectile)
				{
					warnedNoProjectile = true;
					Debug.LogWarning((object)"[SkyfallArtillery066] Indirect projectile prefab missing; no shell spawned.");
				}
				return;
			}
			Vector3 forward = ((Component)shooter).transform.forward;
			forward.y = 0f;
			if (((Vector3)(ref forward)).sqrMagnitude < 0.001f)
			{
				forward = Vector3.forward;
			}
			((Vector3)(ref forward)).Normalize();
			Vector3 val = ((Component)shooter).transform.position + Vector3.up * 1.6f + forward * 2.25f;
			Quaternion val2 = Quaternion.LookRotation(forward, Vector3.up);
			try
			{
				GameObject val3 = Object.Instantiate<GameObject>(ProjectilePrefab, val, val2);
				if ((Object)(object)val3 == (Object)null)
				{
					return;
				}
				SkyfallTankArc skyfallTankArc = val3.GetComponent<SkyfallTankArc>();
				if ((Object)(object)skyfallTankArc == (Object)null)
				{
					skyfallTankArc = val3.GetComponentInChildren<SkyfallTankArc>(true);
				}
				if ((Object)(object)skyfallTankArc == (Object)null)
				{
					Debug.LogWarning((object)"[SkyfallArtillery066] Spawned shell missing SkyfallTankArc; discarded.");
					Object.Destroy((Object)(object)val3);
					return;
				}
				skyfallTankArc.ConfigureShot(shooter, selected);
				if (!val3.activeSelf)
				{
					val3.SetActive(true);
				}
				nextFire = Time.time + SkyfallArtillerySettings.ReloadTime;
				NextAuthorizedShot[instanceID] = nextFire;
				Debug.Log((object)("[SkyfallArtillery067] AUTHORIZED single indirect shot at ground target " + ((Object)selected).name + " (clear line of sight not required)."));
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("[SkyfallArtillery066] Failed to spawn indirect round: " + ex));
				nextFire = Time.time + 2f;
			}
		}

		private void SuppressNativeFiring()
		{
			WeaponHandler[] componentsInChildren = ((Component)this).GetComponentsInChildren<WeaponHandler>(true);
			foreach (WeaponHandler val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Behaviour val2 = (Behaviour)(object)val;
				if (!((Object)(object)val2 == (Object)null))
				{
					if (!originalHandlerStates.ContainsKey(val))
					{
						originalHandlerStates.Add(val, val2.enabled);
					}
					if (val2.enabled)
					{
						val2.enabled = false;
					}
				}
			}
		}

		private void RestoreNativeFiring()
		{
			foreach (KeyValuePair<WeaponHandler, bool> originalHandlerState in originalHandlerStates)
			{
				Behaviour key = (Behaviour)(object)originalHandlerState.Key;
				if ((Object)(object)key != (Object)null)
				{
					key.enabled = originalHandlerState.Value;
				}
			}
			originalHandlerStates.Clear();
		}

		private void OnDisable()
		{
			ActiveCannons.Remove(this);
			ResetBattleSchedule();
			RestoreNativeFiring();
		}

		private void OnDestroy()
		{
			ActiveCannons.Remove(this);
			ResetBattleSchedule();
			RestoreNativeFiring();
		}
	}
	public class SkyfallFieldGunVisual : MonoBehaviour
	{
		private GameObject modelRoot;

		private Material oliveMaterial;

		private Material darkOliveMaterial;

		private Material edgeMaterial;

		private Material steelMaterial;

		private Material tireMaterial;

		private Material hubMaterial;

		private void Start()
		{
			try
			{
				BuildModel();
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("[Skyfall] v0.6.3 visual model failed: " + ex));
			}
		}

		private Material MakeMaterial(Color color)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			Shader val = Shader.Find("Standard");
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Diffuse");
			}
			return new Material(val)
			{
				color = color
			};
		}

		private void BuildModel()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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_0106: 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)
			//IL_017e: 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_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: 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)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_040f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			//IL_0425: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0458: Unknown result type (might be due to invalid IL or missing references)
			//IL_045d: Unknown result type (might be due to invalid IL or missing references)
			//IL_046e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0473: Unknown result type (might be due to invalid IL or missing references)
			//IL_0484: Unknown result type (might be due to invalid IL or missing references)
			//IL_0489: Unknown result type (might be due to invalid IL or missing references)
			//IL_049a: Unknown result type (might be due to invalid IL or missing references)
			//IL_049f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_050e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0540: Unknown result type (might be due to invalid IL or missing references)
			//IL_0556: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0606: Unknown result type (might be due to invalid IL or missing references)
			//IL_061a: Unknown result type (might be due to invalid IL or missing references)
			//IL_064a: Unknown result type (might be due to invalid IL or missing references)
			//IL_065e: Unknown result type (might be due to invalid IL or missing references)
			//IL_067e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0683: Unknown result type (might be due to invalid IL or missing references)
			//IL_069a: Unknown result type (might be due to invalid IL or missing references)
			//IL_06af: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0707: Unknown result type (might be due to invalid IL or missing references)
			//IL_0712: Unknown result type (might be due to invalid IL or missing references)
			//IL_0738: Unknown result type (might be due to invalid IL or missing references)
			//IL_0769: Unknown result type (might be due to invalid IL or missing references)
			//IL_079a: Unknown result type (might be due to invalid IL or missing references)
			//IL_07cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_07fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_082d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0841: Unknown result type (might be due to invalid IL or missing references)
			//IL_0871: Unknown result type (might be due to invalid IL or missing references)
			//IL_0885: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_08cb: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)modelRoot != (Object)null))
			{
				modelRoot = new GameObject("SkyfallFieldGunModel_v063");
				modelRoot.transform.SetParent(((Component)this).transform, false);
				modelRoot.transform.localPosition = Vector3.zero;
				modelRoot.transform.localRotation = Quaternion.identity;
				modelRoot.transform.localScale = Vector3.one;
				oliveMaterial = MakeMaterial(new Color(0.39f, 0.45f, 0.29f));
				darkOliveMaterial = MakeMaterial(new Color(0.24f, 0.29f, 0.18f));
				edgeMaterial = MakeMaterial(new Color(0.48f, 0.51f, 0.34f));
				steelMaterial = MakeMaterial(new Color(0.24f, 0.26f, 0.26f));
				tireMaterial = MakeMaterial(new Color(0.13f, 0.15f, 0.15f));
				hubMaterial = MakeMaterial(new Color(0.39f, 0.4f, 0.34f));
				CreateWheel("LeftSpokedWheel", -0.76f, 0.475f, -0.24f);
				CreateWheel("RightSpokedWheel", 0.76f, 0.475f, -0.24f);
				Box("AxleHousing", new Vector3(0f, 0.49f, -0.24f), new Vector3(1.36f, 0.12f, 0.14f), darkOliveMaterial);
				Box("Undercarriage", new Vector3(0f, 0.57f, -0.22f), new Vector3(0.58f, 0.2f, 1.06f), oliveMaterial);
				Box("AngledFrontBrace", new Vector3(0f, 0.68f, 0.18f), new Vector3(0.48f, 0.2f, 0.4f), darkOliveMaterial, Quaternion.Euler(-15f, 0f, 0f));
				Bar("LeftRearTrail", new Vector3(-0.2f, 0.53f, -0.53f), new Vector3(-0.54f, 0.16f, -2.08f), 0.15f, 0.13f, oliveMaterial);
				Bar("RightRearTrail", new Vector3(0.2f, 0.53f, -0.53f), new Vector3(0.54f, 0.16f, -2.08f), 0.15f, 0.13f, oliveMaterial);
				Box("LeftTrailEnd", new Vector3(-0.54f, 0.13f, -2.08f), new Vector3(0.3f, 0.12f, 0.23f), darkOliveMaterial);
				Box("RightTrailEnd", new Vector3(0.54f, 0.13f, -2.08f), new Vector3(0.3f, 0.12f, 0.23f), darkOliveMaterial);
				Bar("RearCrossSupport", new Vector3(-0.29f, 0.33f, -1.01f), new Vector3(0.29f, 0.33f, -1.01f), 0.07f, 0.09f, steelMaterial);
				float num = 0.39f;
				PolygonPlate("ShieldLeft", (Vector2[])(object)new Vector2[6]
				{
					new Vector2(-0.88f, 0.65f),
					new Vector2(-0.85f, 1.44f),
					new Vector2(-0.68f, 1.57f),
					new Vector2(-0.22f, 1.57f),
					new Vector2(-0.18f, 1.12f),
					new Vector2(-0.1f, 0.65f)
				}, num, 0.075f, oliveMaterial);
				PolygonPlate("ShieldRight", (Vector2[])(object)new Vector2[6]
				{
					new Vector2(0.1f, 0.65f),
					new Vector2(0.18f, 1.12f),
					new Vector2(0.22f, 1.57f),
					new Vector2(0.68f, 1.57f),
					new Vector2(0.85f, 1.44f),
					new Vector2(0.88f, 0.65f)
				}, num, 0.075f, oliveMaterial);
				Bar("ShieldLeftTop", new Vector3(-0.83f, 1.48f, num + 0.05f), new Vector3(-0.24f, 1.59f, num + 0.05f), 0.04f, 0.04f, edgeMaterial);
				Bar("ShieldRightTop", new Vector3(0.24f, 1.59f, num + 0.05f), new Vector3(0.83f, 1.48f, num + 0.05f), 0.04f, 0.04f, edgeMaterial);
				float[] array = new float[4] { -0.74f, -0.29f, 0.29f, 0.74f };
				foreach (float num2 in array)
				{
					Ball("ShieldRivetLower", new Vector3(num2, 0.77f, num + 0.05f), 0.055f, steelMaterial);
					Ball("ShieldRivetUpper", new Vector3(num2, 1.37f, num + 0.05f), 0.055f, steelMaterial);
				}
				Bar("ShieldLeftStrut", new Vector3(-0.52f, 0.63f, 0.32f), new Vector3(-0.32f, 1f, -0.18f), 0.05f, 0.05f, darkOliveMaterial);
				Bar("ShieldRightStrut", new Vector3(0.52f, 0.63f, 0.32f), new Vector3(0.32f, 1f, -0.18f), 0.05f, 0.05f, darkOliveMaterial);
				GameObject val = new GameObject("ElevatedGunPivot_28deg");
				val.transform.SetParent(modelRoot.transform, false);
				val.transform.localPosition = new Vector3(0f, 1.07f, 0.03f);
				val.transform.localRotation = Quaternion.Euler(-28f, 0f, 0f);
				Transform transform = val.transform;
				Box("GunBreech", new Vector3(0f, 0f, -0.07f), new Vector3(0.37f, 0.31f, 0.52f), darkOliveMaterial, Quaternion.identity, transform);
				Cylinder("RecoilHousing", new Vector3(0f, 0f, 0.43f), 0.21f, 0.92f, steelMaterial, transform);
				Cylinder("BarrelCollar", new Vector3(0f, 0f, 0.92f), 0.165f, 0.24f, darkOliveMaterial, transform);
				Cylinder("LongGunBarrel", new Vector3(0f, 0f, 1.7f), 0.105f, 1.6f, steelMaterial, transform);
				Cylinder("MuzzleBand", new Vector3(0f, 0f, 2.48f), 0.134f, 0.15f, darkOliveMaterial, transform);
				Cylinder("DarkMuzzle", new Vector3(0f, 0f, 2.565f), 0.075f, 0.019f, tireMaterial, transform);
				Bar("LeftGunSupport", new Vector3(-0.36f, 0.58f, 0.07f), new Vector3(-0.18f, 1.07f, 0.04f), 0.12f, 0.15f, oliveMaterial);
				Bar("RightGunSupport", new Vector3(0.36f, 0.58f, 0.07f), new Vector3(0.18f, 1.07f, 0.04f), 0.12f, 0.15f, oliveMaterial);
				GameObject val2 = new GameObject("SkyfallVisualMuzzlePoint");
				val2.transform.SetParent(transform, false);
				val2.transform.localPosition = new Vector3(0f, 0f, 2.59f);
				HideOriginalRenderers();
				((MonoBehaviour)this).StartCoroutine(SnapToMapGround());
				Debug.Log((object)"[Skyfall] v0.6.3 field gun visual built: open-spoke wheels, shaped shield, upward barrel.");
			}
		}

		private void HideOriginalRenderers()
		{
			Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && !(val is ParticleSystemRenderer) && !((Component)val).transform.IsChildOf(modelRoot.transform))
				{
					val.enabled = false;
				}
			}
		}

		private IEnumerator SnapToMapGround()
		{
			yield return (object)new WaitForFixedUpdate();
			yield return (object)new WaitForFixedUpdate();
			yield return null;
			if ((Object)(object)modelRoot == (Object)null)
			{
				yield break;
			}
			float num = 0f;
			int num2 = 0;
			Vector3[] array = (Vector3[])(object)new Vector3[4]
			{
				new Vector3(-0.76f, 0.01f, -0.24f),
				new Vector3(0.76f, 0.01f, -0.24f),
				new Vector3(-0.54f, 0.07f, -2.08f),
				new Vector3(0.54f, 0.07f, -2.08f)
			};
			foreach (Vector3 val in array)
			{
				Vector3 val2 = modelRoot.transform.TransformPoint(val);
				RaycastHit[] array2 = Physics.RaycastAll(val2 + Vector3.up * 3f, Vector3.down, 12f, -5, (QueryTriggerInteraction)1);
				float num3 = float.PositiveInfinity;
				float num4 = 0f;
				RaycastHit[] array3 = array2;
				for (int j = 0; j < array3.Length; j++)
				{
					RaycastHit val3 = array3[j];
					if (!((Object)(object)((RaycastHit)(ref val3)).collider == (Object)null) && !((Component)((RaycastHit)(ref val3)).collider).transform.IsChildOf(((Component)this).transform) && !((Object)(object)((RaycastHit)(ref val3)).collider.attachedRigidbody != (Object)null) && !(((RaycastHit)(ref val3)).normal.y < 0.55f) && ((RaycastHit)(ref val3)).distance < num3)
					{
						num3 = ((RaycastHit)(ref val3)).distance;
						num4 = ((RaycastHit)(ref val3)).point.y;
					}
				}
				if (num3 < float.PositiveInfinity)
				{
					num += num4 - val2.y;
					num2++;
				}
			}
			if (num2 > 0)
			{
				Transform transform = modelRoot.transform;
				transform.position += Vector3.up * (num / (float)num2 + 0.012f);
				Debug.Log((object)("[Skyfall] v0.6.3 model grounded; terrain samples=" + num2));
			}
			else
			{
				Debug.LogWarning((object)"[Skyfall] Field gun: no map ground collider found; using unit root height.");
			}
		}

		private GameObject Part(string name, PrimitiveType type, Vector3 pos, Quaternion rot, Vector3 scale, Material material, Transform parent = null)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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)
			GameObject obj = GameObject.CreatePrimitive(type);
			((Object)obj).name = name;
			obj.transform.SetParent(parent ?? modelRoot.transform, false);
			obj.transform.localPosition = pos;
			obj.transform.localRotation = rot;
			obj.transform.localScale = scale;
			Collider component = obj.GetComponent<Collider>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component);
			}
			Renderer component2 = obj.GetComponent<Renderer>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.sharedMaterial = material;
			}
			return obj;
		}

		private GameObject Box(string name, Vector3 pos, Vector3 scale, Material material, Quaternion? rotation = null, Transform parent = null)
		{
			//IL_0003: 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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			return Part(name, (PrimitiveType)3, pos, (Quaternion)(((??)rotation) ?? Quaternion.identity), scale, material, parent);
		}

		private GameObject Ball(string name, Vector3 pos, float diameter, Material material, Transform parent = null)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			return Part(name, (PrimitiveType)0, pos, Quaternion.identity, Vector3.one * diameter, material, parent);
		}

		private GameObject Cylinder(string name, Vector3 pos, float radius, float length, Material material, Transform parent = null)
		{
			//IL_0003: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			return Part(name, (PrimitiveType)2, pos, Quaternion.Euler(90f, 0f, 0f), new Vector3(radius, length * 0.5f, radius), material, parent);
		}

		private GameObject Bar(string name, Vector3 from, Vector3 to, float width, float height, Material material)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = to - from;
			return Box(name, (from + to) * 0.5f, new Vector3(width, height, ((Vector3)(ref val)).magnitude), material, Quaternion.LookRotation(((Vector3)(ref val)).normalized, Vector3.up));
		}

		private void CreateWheel(string name, float x, float y, float z)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0028: 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_00a1: 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_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: 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_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: 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_0134: 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)
			//IL_0137: 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_014d: 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_016e: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(modelRoot.transform, false);
			val.transform.localPosition = new Vector3(x, y, z);
			TorusRing(name + "Tire", val.transform, 0.415f, 0.045f, tireMaterial);
			TorusRing(name + "SteelRim", val.transform, 0.355f, 0.024f, hubMaterial);
			Part(name + "Hub", (PrimitiveType)2, Vector3.zero, Quaternion.Euler(0f, 0f, 90f), new Vector3(0.125f, 0.12f, 0.125f), darkOliveMaterial, val.transform);
			for (int i = 0; i < 10; i++)
			{
				float num = (float)i * (float)Math.PI * 2f / 10f;
				Vector3 val2 = new Vector3(0f, Mathf.Cos(num), Mathf.Sin(num));
				Vector3 val3 = val2 * 0.13f;
				Vector3 val4 = val2 * 0.355f;
				Vector3 val5 = val4 - val3;
				Part(name + "Spoke" + i, (PrimitiveType)2, (val3 + val4) * 0.5f, Quaternion.FromToRotation(Vector3.up, ((Vector3)(ref val5)).normalized), new Vector3(0.021f, ((Vector3)(ref val5)).magnitude * 0.5f, 0.021f), hubMaterial, val.transform);
			}
		}

		private void TorusRing(string name, Transform parent, float ringRadius, float tubeRadius, Material material)
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_0113: Expected O, but got Unknown
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] array = (Vector3[])(object)new Vector3[297];
			int[] array2 = new int[1536];
			int num = 0;
			for (int i = 0; i <= 32; i++)
			{
				float num2 = (float)Math.PI * 2f * (float)i / 32f;
				for (int j = 0; j <= 8; j++)
				{
					float num3 = (float)Math.PI * 2f * (float)j / 8f;
					float num4 = ringRadius + tubeRadius * Mathf.Cos(num3);
					array[num++] = new Vector3(tubeRadius * Mathf.Sin(num3), Mathf.Cos(num2) * num4, Mathf.Sin(num2) * num4);
				}
			}
			int num5 = 0;
			for (int k = 0; k < 32; k++)
			{
				for (int l = 0; l < 8; l++)
				{
					int num6 = k * 9 + l;
					int num7 = (k + 1) * 9 + l;
					array2[num5++] = num6;
					array2[num5++] = num7;
					array2[num5++] = num6 + 1;
					array2[num5++] = num6 + 1;
					array2[num5++] = num7;
					array2[num5++] = num7 + 1;
				}
			}
			Mesh val = new Mesh();
			((Object)val).name = name;
			val.vertices = array;
			val.triangles = array2;
			val.RecalculateNormals();
			val.RecalculateBounds();
			GameObject val2 = new GameObject(name);
			val2.transform.SetParent(parent, false);
			val2.AddComponent<MeshFilter>().sharedMesh = val;
			((Renderer)val2.AddComponent<MeshRenderer>()).sharedMaterial = material;
		}

		private void PolygonPlate(string name, Vector2[] outline, float z, float thickness, Material material)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_0095: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Expected O, but got Unknown
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			int num = outline.Length;
			Vector3[] array = (Vector3[])(object)new Vector3[num * 2];
			for (int i = 0; i < num; i++)
			{
				array[i] = new Vector3(outline[i].x, outline[i].y, z + thickness * 0.5f);
				array[num + i] = new Vector3(outline[i].x, outline[i].y, z - thickness * 0.5f);
			}
			List<int> list = new List<int>();
			float num2 = 0f;
			for (int j = 0; j < num; j++)
			{
				Vector2 val = outline[j];
				Vector2 val2 = outline[(j + 1) % num];
				num2 += val.x * val2.y - val2.x * val.y;
			}
			bool flag = num2 < 0f;
			for (int k = 1; k < num - 1; k++)
			{
				if (flag)
				{
					list.Add(0);
					list.Add(k + 1);
					list.Add(k);
					list.Add(num);
					list.Add(num + k);
					list.Add(num + k + 1);
				}
				else
				{
					list.Add(0);
					list.Add(k);
					list.Add(k + 1);
					list.Add(num);
					list.Add(num + k + 1);
					list.Add(num + k);
				}
			}
			for (int l = 0; l < num; l++)
			{
				int num3 = (l + 1) % num;
				list.Add(l);
				list.Add(num3);
				list.Add(num + l);
				list.Add(num3);
				list.Add(num + num3);
				list.Add(num + l);
			}
			Mesh val3 = new Mesh();
			((Object)val3).name = name;
			val3.vertices = array;
			val3.triangles = list.ToArray();
			val3.RecalculateNormals();
			val3.RecalculateBounds();
			GameObject val4 = new GameObject(name);
			val4.transform.SetParent(modelRoot.transform, false);
			val4.AddComponent<MeshFilter>().sharedMesh = val3;
			((Renderer)val4.AddComponent<MeshRenderer>()).sharedMaterial = material;
		}
	}
	public class SkyfallTankArc : MonoBehaviour
	{
		public float FallbackDistance = 140f;

		public float MaxTargetSearch = 450f;

		public float CollisionRadius = 0.16f;

		public float ArmDelay = 0.15f;

		public GameObject ExplosionPrefab;

		private Rigidbody body;

		private Transform flightAnchor;

		private Transform targetRig;

		private Transform shooterRoot;

		private Unit assignedShooter;

		private Unit assignedTarget;

		private Vector3 startPoint;

		private Vector3 landingPoint;

		private static readonly RaycastHit[] groundHits = (RaycastHit[])(object)new RaycastHit[32];

		private float duration;

		private float elapsed;

		private bool launched;

		private bool exploded;

		private int generation;

		private static float nextRejectedRoundLog;

		private int shotEpoch = -1;

		public void ConfigureShot(Unit owner, Unit target)
		{
			shotEpoch = (SkyfallBattleGate.Active() ? SkyfallBattleGate.Epoch : (-1));
			assignedShooter = owner;
			assignedTarget = target;
		}

		private void OnEnable()
		{
			//IL_00e3: 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)
			generation++;
			launched = false;
			exploded = false;
			elapsed = 0f;
			targetRig = null;
			shooterRoot = null;
			body = null;
			flightAnchor = ((Component)this).transform;
			Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>(true);
			foreach (Collider val in componentsInChildren)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.enabled = false;
				}
			}
			MoveTransform[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<MoveTransform>(true);
			foreach (MoveTransform val2 in componentsInChildren2)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					((Behaviour)val2).enabled = false;
				}
			}
			RaycastTrail[] componentsInChildren3 = ((Component)this).GetComponentsInChildren<RaycastTrail>(true);
			foreach (RaycastTrail val3 in componentsInChildren3)
			{
				if ((Object)(object)val3 != (Object)null)
				{
					((Behaviour)val3).enabled = false;
				}
			}
			Rigidbody componentInChildren = ((Component)this).GetComponentInChildren<Rigidbody>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				componentInChildren.velocity = Vector3.zero;
				componentInChildren.angularVelocity = Vector3.zero;
				componentInChildren.useGravity = false;
				componentInChildren.isKinematic = true;
			}
			((MonoBehaviour)this).StartCoroutine(BeginFlight(generation));
		}

		private IEnumerator BeginFlight(int ticket)
		{
			Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>(true);
			foreach (Collider val in componentsInChildren)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.enabled = false;
				}
			}
			yield return (object)new WaitForFixedUpdate();
			yield return (object)new WaitForFixedUpdate();
			if (ticket != generation || !((Component)this).gameObject.activeInHierarchy)
			{
				yield break;
			}
			if (!SkyfallBattleGate.Active() || shotEpoch != SkyfallBattleGate.Epoch)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				yield break;
			}
			if ((Object)(object)assignedShooter == (Object)null || (Object)(object)assignedTarget == (Object)null || !SkyfallArtilleryGroundTargets.IsGroundEnemy(assignedShooter, assignedTarget, ((Component)this).transform.position))
			{
				if (Time.time >= nextRejectedRoundLog)
				{
					nextRejectedRoundLog = Time.time + 3f;
					Debug.LogWarning((object)"[SkyfallArtillery067] Blocked UNAUTHORIZED native/unassigned artillery projectile.");
				}
				Object.Destroy((Object)(object)((Component)this).gameObject);
				yield break;
			}
			body = ((Component)this).GetComponentInChildren<Rigidbody>();
			flightAnchor = (((Object)(object)body != (Object)null) ? ((Component)body).transform : ((Component)this).transform);
			startPoint = flightAnchor.position;
			MoveTransform[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<MoveTransform>(true);
			foreach (MoveTransform val2 in componentsInChildren2)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					((Behaviour)val2).enabled = false;
				}
			}
			if ((Object)(object)body != (Object)null)
			{
				body.velocity = Vector3.zero;
				body.angularVelocity = Vector3.zero;
				body.useGravity = false;
				body.isKinematic = true;
			}
			Vector3 forward = flightAnchor.forward;
			forward.y = 0f;
			if (((Vector3)(ref forward)).sqrMagnitude < 0.001f)
			{
				forward = ((Component)this).transform.forward;
			}
			forward.y = 0f;
			if (((Vector3)(ref forward)).sqrMagnitude < 0.001f)
			{
				forward = Vector3.forward;
			}
			((Vector3)(ref forward)).Normalize();
			AcquireTarget(forward);
			if ((Object)(object)targetRig == (Object)null)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				yield break;
			}
			if (TryFindImpactGround(landingPoint, 24f, out var ground))
			{
				landingPoint = ground;
			}
			Vector3 val3 = landingPoint - startPoint;
			val3.y = 0f;
			float magnitude = ((Vector3)(ref val3)).magnitude;
			duration = Mathf.Clamp(1.35f + magnitude / 80f, 1.55f, 7f);
			launched = true;
			Debug.Log((object)("[Skyfall] v0.6 launch: range=" + magnitude.ToString("F1") + " flight=" + duration.ToString("F2") + " target=" + (((Object)(object)targetRig != (Object)null) ? "enemy" : "forward fallback")));
		}

		private static object ReadMember(object source, string name)
		{
			if (source == null)
			{
				return null;
			}
			try
			{
				Type type = source.GetType();
				FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field != null)
				{
					return field.GetValue(source);
				}
				PropertyInfo property = type.GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (property != null)
				{
					return property.GetValue(source, null);
				}
			}
			catch (Exception)
			{
			}
			return null;
		}

		private static Transform ToTransform(object value)
		{
			Transform val = (Transform)((value is Transform) ? value : null);
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			Component val2 = (Component)((value is Component) ? value : null);
			if (!((Object)(object)val2 != (Object)null))
			{
				return null;
			}
			return val2.transform;
		}

		private static object GetData(MonoBehaviour unit)
		{
			object obj = ReadMember(unit, "data");
			if (obj != null)
			{
				return obj;
			}
			MonoBehaviour[] componentsInChildren = ((Component)((Component)unit).transform.root).GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val in componentsInChildren)
			{
				if ((Object)(object)val != (Object)null && ((object)val).GetType().Name == "DataHandler")
				{
					return val;
				}
			}
			return null;
		}

		private static bool IsDead(MonoBehaviour unit, object data)
		{
			object obj = ReadMember(data, "Dead") ?? ReadMember(unit, "dead");
			if (obj is bool)
			{
				return (bool)obj;
			}
			return false;
		}

		private void AcquireTarget(Vector3 forward)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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_0118: 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_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)assignedShooter != (Object)null && (Object)(object)assignedShooter.data != (Object)null && !assignedShooter.data.Dead)
			{
				shooterRoot = ((Component)assignedShooter).transform.root;
				Unit candidate = assignedTarget;
				if (!SkyfallArtilleryGroundTargets.IsGroundEnemy(assignedShooter, candidate, startPoint))
				{
					candidate = SkyfallArtilleryGroundTargets.ClosestGroundEnemy(assignedShooter, startPoint, MaxTargetSearch);
				}
				targetRig = SkyfallArtilleryGroundTargets.AimTransform(candidate);
				if ((Object)(object)targetRig != (Object)null)
				{
					landingPoint = targetRig.position;
				}
				return;
			}
			MonoBehaviour[] array = Object.FindObjectsOfType<MonoBehaviour>();
			MonoBehaviour val = null;
			object source = null;
			float num = 400f;
			MonoBehaviour[] array2 = array;
			foreach (MonoBehaviour val2 in array2)
			{
				if ((Object)(object)val2 == (Object)null || ((object)val2).GetType().Name != "Unit")
				{
					continue;
				}
				object data = GetData(val2);
				if (IsDead(val2, data))
				{
					continue;
				}
				Vector3 val3 = ((Component)val2).transform.position - startPoint;
				float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
				if (!(sqrMagnitude > 400f))
				{
					((Component)val2).GetComponentInChildren<WeaponHandler>();
					Unit val4 = (Unit)(object)((val2 is Unit) ? val2 : null);
					if ((((Object)(object)val4 != (Object)null && (Object)(object)val4.unitBlueprint != (Object)null && val4.unitBlueprint.Entity != null) ? val4.unitBlueprint.Entity.Name : "") == "Skyfall Field Cannon" && sqrMagnitude < num)
					{
						num = sqrMagnitude;
						val = val2;
						source = data;
					}
				}
			}
			Unit val5 = (Unit)(object)((val is Unit) ? val : null);
			if ((Object)(object)val5 != (Object)null)
			{
				shooterRoot = ((Component)val).transform.root;
				Transform val6 = ToTransform(ReadMember(source, "targetMainRig"));
				Unit candidate2 = (((Object)(object)val6 != (Object)null) ? ((Component)val6).GetComponentInParent<Unit>() : null);
				if (SkyfallArtilleryGroundTargets.IsGroundEnemy(val5, candidate2, startPoint))
				{
					targetRig = SkyfallArtilleryGroundTargets.AimTransform(candidate2);
					if ((Object)(object)targetRig != (Object)null)
					{
						landingPoint = targetRig.position;
						return;
					}
				}
				Unit candidate3 = SkyfallArtilleryGroundTargets.ClosestGroundEnemy(val5, startPoint, MaxTargetSearch);
				targetRig = SkyfallArtilleryGroundTargets.AimTransform(candidate3);
				if ((Object)(object)targetRig != (Object)null)
				{
					landingPoint = targetRig.position;
				}
			}
			else
			{
				Debug.LogWarning((object)"[SkyfallArtillery066] Cannot identify firing unit; dropping round rather than using fallback targeting.");
			}
		}

		private void FixedUpdate()
		{
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: 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_0103: 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_0132: 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_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: 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)
			//IL_0160: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: 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_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			if (!SkyfallBattleGate.Active() || shotEpoch != SkyfallBattleGate.Epoch)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
			else
			{
				if (!launched || exploded)
				{
					return;
				}
				elapsed += Time.fixedDeltaTime;
				float num = Mathf.Clamp01(elapsed / duration);
				if ((Object)(object)targetRig != (Object)null && num < 0.65f)
				{
					Vector3 position = targetRig.position;
					Vector3 position2 = Vector3.Lerp(landingPoint, position, Mathf.Clamp01(Time.fixedDeltaTime * 2f));
					position2.y = position.y;
					if (TryFindImpactGround(position2, 24f, out var ground))
					{
						landingPoint = ground;
					}
				}
				Vector3 val = landingPoint - startPoint;
				val.y = 0f;
				float magnitude = ((Vector3)(ref val)).magnitude;
				float num2 = Mathf.Clamp(14f + magnitude * 0.14f, 14f, 60f);
				Vector3 val2 = Vector3.Lerp(startPoint, landingPoint, num);
				val2.y += 4f * num2 * num * (1f - num);
				Vector3 val3 = val2 - flightAnchor.position;
				if (elapsed >= ArmDelay && FindHit(flightAnchor.position, val3, out var point))
				{
					Detonate(point);
					return;
				}
				Transform transform = ((Component)this).transform;
				transform.position += val3;
				if (((Vector3)(ref val3)).sqrMagnitude > 0.01f)
				{
					((Component)this).transform.rotation = Quaternion.LookRotation(((Vector3)(ref val3)).normalized, Vector3.up);
					Transform transform2 = ((Component)this).transform;
					transform2.position += val2 - flightAnchor.position;
				}
				if (num >= 1f)
				{
					if (TryFindImpactGround(landingPoint, 0.55f, out point))
					{
						Detonate(point);
					}
					else
					{
						Object.Destroy((Object)(object)((Component)this).gameObject);
					}
				}
			}
		}

		private bool IsWorldSurface(Collider collider)
		{
			if ((Object)(object)collider == (Object)null || ((Component)collider).transform.IsChildOf(((Component)this).transform) || ((Object)(object)shooterRoot != (Object)null && ((Component)collider).transform.IsChildOf(shooterRoot)))
			{
				return false;
			}
			if ((Object)(object)((Component)collider).GetComponentInParent<Unit>() != (Object)null || (Object)(object)((Component)collider).GetComponentInParent<Holdable>() != (Object)null)
			{
				return false;
			}
			if (collider is SphereCollider && ((Component)collider).gameObject.layer == 18 && ((Object)collider).name == "Sphere")
			{
				return false;
			}
			Rigidbody attachedRigidbody = collider.attachedRigidbody;
			if (!((Object)(object)attachedRigidbody == (Object)null))
			{
				return attachedRigidbody.isKinematic;
			}
			return true;
		}

		private bool TryFindImpactGround(Vector3 position, float depth, out Vector3 ground)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_006a: 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_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)
			ground = position;
			Vector3 val = position + Vector3.up * 0.25f;
			float num = depth + 0.25f;
			RaycastHit[] array = groundHits;
			int num2 = Physics.RaycastNonAlloc(val, Vector3.down, array, num, -5, (QueryTriggerInteraction)1);
			if (num2 == array.Length)
			{
				array = Physics.RaycastAll(val, Vector3.down, num, -5, (QueryTriggerInteraction)1);
				num2 = array.Length;
			}
			float num3 = float.PositiveInfinity;
			for (int i = 0; i < num2; i++)
			{
				RaycastHit val2 = array[i];
				if (!(((RaycastHit)(ref val2)).distance >= num3) && !(((RaycastHit)(ref val2)).normal.y < 0.5f) && IsWorldSurface(((RaycastHit)(ref val2)).collider))
				{
					num3 = ((RaycastHit)(ref val2)).distance;
					ground = ((RaycastHit)(ref val2)).point;
				}
			}
			return !float.IsPositiveInfinity(num3);
		}

		private bool FindHit(Vector3 origin, Vector3 step, out Vector3 point)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			point = Vector3.zero;
			float magnitude = ((Vector3)(ref step)).magnitude;
			if (magnitude < 0.0001f)
			{
				return false;
			}
			RaycastHit[] array = Physics.SphereCastAll(origin, CollisionRadius, ((Vector3)(ref step)).normalized, magnitude + 0.08f, -5, (QueryTriggerInteraction)1);
			float num = float.PositiveInfinity;
			bool result = false;
			RaycastHit[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				RaycastHit val = array2[i];
				if (IsWorldSurface(((RaycastHit)(ref val)).collider) && ((RaycastHit)(ref val)).distance < num)
				{
					num = ((RaycastHit)(ref val)).distance;
					point = ((RaycastHit)(ref val)).point;
					result = true;
				}
			}
			return result;
		}

		private void Detonate(Vector3 location)
		{
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Expected O, but got Unknown
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: 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_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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			if (exploded)
			{
				return;
			}
			if (!SkyfallBattleGate.Active() || shotEpoch != SkyfallBattleGate.Epoch)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			exploded = true;
			launched = false;
			List<Unit> list = new List<Unit>();
			float radius = SkyfallArtillerySettings.Radius;
			float damage = SkyfallArtillerySettings.Damage;
			float edgeDamage = SkyfallArtillerySettings.EdgeDamage;
			Unit[] array = Object.FindObjectsOfType<Unit>();
			foreach (Unit val in array)
			{
				if ((Object)(object)val == (Object)null || !((Component)val).gameObject.activeInHierarchy || (Object)(object)val.data == (Object)null || val.data.Dead || (Object)(object)val.data.healthHandler == (Object)null)
				{
					continue;
				}
				Transform val2 = SkyfallArtilleryGroundTargets.AimTransform(val);
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				Vector3 val3 = val2.position - location;
				if (Mathf.Abs(val3.y) > radius)
				{
					continue;
				}
				val3.y = 0f;
				float magnitude = ((Vector3)(ref val3)).magnitude;
				if (magnitude > radius)
				{
					continue;
				}
				float num = Mathf.Lerp(damage, edgeDamage, Mathf.Clamp01(magnitude / radius));
				if (num <= 0f)
				{
					continue;
				}
				try
				{
					float health = val.data.health;
					((Damagable)val.data.healthHandler).TakeDamage(num, location, assignedShooter, (DamageType)0);
					if ((Object)(object)val != (Object)null && (Object)(object)val.data != (Object)null && (val.data.Dead || val.data.health < health))
					{
						list.Add(val);
					}
				}
				catch (Exception ex)
				{
					Debug.LogWarning((object)("[SkyfallArtillery0700] Game damage failed: " + ex.Message));
				}
			}
			if ((Object)(object)assignedShooter != (Object)null)
			{
				SkyfallArtilleryGroundTargetAI component = ((Component)assignedShooter).GetComponent<SkyfallArtilleryGroundTargetAI>();
				if ((Object)(object)component != (Object)null)
				{
					component.RegisterImpact(list, shotEpoch);
				}
			}
			Debug.Log((object)("[SkyfallArtillery0700] Impact: confirmed damaged units=" + list.Count + " center=" + damage + " edge=" + edgeDamage + " radius=" + radius));
			try
			{
				if ((Object)(object)ExplosionPrefab != (Object)null)
				{
					GameObject val4 = new GameObject("SkyfallArtilleryImpactStage");
					val4.SetActive(false);
					try
					{
						GameObject val5 = Object.Instantiate<GameObject>(ExplosionPrefab, location, Quaternion.identity, val4.transform);
						if ((Object)(object)val5 != (Object)null)
						{
							val5.SetActive(false);
							Explosion[] componentsInChildren = val5.GetComponentsInChildren<Explosion>(true);
							foreach (Explosion obj in componentsInChildren)
							{
								obj.damage = 0f;
								obj.radius = SkyfallArtillerySettings.Radius;
							}
							val5.transform.SetParent((Transform)null, true);
							val5.SetActive(true);
						}
					}
					finally
					{
						Object.Destroy((Object)(object)val4);
					}
				}
				else
				{
					Debug.LogWarning((object)"[Skyfall] Impact happened, but no explosion prefab was available.");
				}
			}
			catch (Exception ex2)
			{
				Debug.LogError((object)("[Skyfall] Explosion failed: " + ex2));
			}
			SkyfallImpactVisual068.Play(location);
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}
	internal static class SkyfallImpactVisual068
	{
		private static Material particleMaterial;

		private static Texture2D particleTexture;

		private static Material GetMaterial()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)particleMaterial != (Object)null)
			{
				return particleMaterial;
			}
			Shader val = Shader.Find("Legacy Shaders/Particles/Alpha Blended");
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Particles/Standard Unlit");
			}
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			particleTexture = new Texture2D(32, 32, (TextureFormat)4, false);
			Color32[] array = (Color32[])(object)new Color32[1024];
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 32; j++)
				{
					float num = ((float)j - 15.5f) / 15.5f;
					float num2 = ((float)i - 15.5f) / 15.5f;
					float num3 = Mathf.Clamp01(1f - Mathf.Sqrt(num * num + num2 * num2));
					num3 = Mathf.SmoothStep(0f, 1f, num3);
					array[i * 32 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(255f * num3));
				}
			}
			particleTexture.SetPixels32(array);
			((Texture)particleTexture).wrapMode = (TextureWrapMode)1;
			((Texture)particleTexture).filterMode = (FilterMode)1;
			particleTexture.Apply(false, true);
			particleMaterial = new Material(val);
			particleMaterial.mainTexture = (Texture)(object)particleTexture;
			return particleMaterial;
		}

		public static void Play(Vector3 position)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_008c: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: 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_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = null;
			try
			{
				Material material = GetMaterial();
				if (!((Object)(object)material == (Object)null))
				{
					val = new GameObject("Skyfall Cosmetic Impact v068");
					val.transform.position = position + Vector3.up * 0.22f;
					Object.Destroy((Object)(object)val, 4.5f);
					Layer(val.transform, material, "Flash", 12, 0.12f, 0.32f, 0.2f, 1.6f, 2.2f, 3.4f, new Color(1f, 0.95f, 0.65f, 0.95f), new Color(1f, 0.43f, 0.08f, 0.9f), 0f, sparks: false);
					Layer(val.transform, material, "Smoke", 25, 1.8f, 3.5f, 0.8f, 2.3f, 1.1f, 2f, new Color(0.36f, 0.32f, 0.29f, 0.65f), new Color(0.16f, 0.16f, 0.17f, 0.7f), -0.05f, sparks: false);
					Layer(val.transform, material, "Dust", 22, 0.65f, 1.5f, 1.2f, 3.5f, 0.8f, 1.6f, new Color(0.65f, 0.53f, 0.39f, 0.55f), new Color(0.45f, 0.4f, 0.34f, 0.5f), 0f, sparks: false);
					Layer(val.transform, material, "Glowing particles", 24, 0.25f, 0.65f, 2f, 5f, 0.1f, 0.25f, new Color(1f, 0.85f, 0.3f, 0.95f), new Color(1f, 0.36f, 0.06f, 0.8f), 0.8f, sparks: true);
				}
			}
			catch (Exception ex)
			{
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
				Debug.LogWarning((object)("[SkyfallImpact068] Cosmetic effect unavailable: " + ex.Message));
			}
		}

		private static void Layer(Transform parent, Material material, string name, int count, float minLife, float maxLife, float minSpeed, float maxSpeed, float minSize, float maxSize, Color first, Color second, float gravity, bool sparks)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_00e0: 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_0124: Unknown result type (might be due to invali