Decompiled source of TrollstavAim v1.0.0

BepInEx/plugins/TrollstavAim/TrollstavAim.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("Ovosh1337")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright (c) 2026 Ovosh1337")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Trollstav Aim Indicator")]
[assembly: AssemblyTitle("TrollstavAim")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace TrollstavAim;

internal sealed class AimIndicator : MonoBehaviour
{
	private GroundRing m_landing;

	private GroundRing m_inner;

	private GroundRing m_damage;

	private float m_nextCreateAttempt;

	private float m_nextDiagLog;

	private bool m_creationFailedLogged;

	private bool m_shownOnce;

	private void Update()
	{
		try
		{
			Tick();
		}
		catch (Exception ex)
		{
			TrollstavAimPlugin.Log.LogError((object)("AimIndicator.Update: " + ex));
			Hide();
		}
	}

	private void LateUpdate()
	{
		try
		{
			if (m_landing != null)
			{
				m_landing.Rebuild();
			}
			if (m_inner != null)
			{
				m_inner.Rebuild();
			}
			if (m_damage != null)
			{
				m_damage.Rebuild();
			}
		}
		catch (Exception ex)
		{
			TrollstavAimPlugin.Log.LogError((object)("AimIndicator.LateUpdate: " + ex));
		}
	}

	private void OnDestroy()
	{
		if (m_landing != null)
		{
			m_landing.Destroy();
		}
		if (m_inner != null)
		{
			m_inner.Destroy();
		}
		if (m_damage != null)
		{
			m_damage.Destroy();
		}
	}

	private void Tick()
	{
		//IL_006e: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		if (!TrollstavAimPlugin.CfgEnabled.Value)
		{
			Hide();
			return;
		}
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead())
		{
			Hide();
			return;
		}
		if (InventoryGui.IsVisible() || Menu.IsVisible() || Console.IsVisible())
		{
			Hide();
			return;
		}
		TrollstavInfo trollstavInfo = TrollstavData.Resolve(((Humanoid)localPlayer).GetCurrentWeapon());
		if (trollstavInfo == null)
		{
			Hide();
		}
		else
		{
			if (!EnsureRings())
			{
				return;
			}
			Vector3 position = TrollstavData.NominalPoint(localPlayer, trollstavInfo);
			float num = ((TrollstavAimPlugin.CfgRadiusOverride.Value > 0f) ? TrollstavAimPlugin.CfgRadiusOverride.Value : trollstavInfo.SpawnRadius);
			float num2 = 0f;
			if (num > 0.01f && trollstavInfo.SpawnRadius > 0.01f)
			{
				num2 = trollstavInfo.SpawnRadiusInner * (num / trollstavInfo.SpawnRadius);
			}
			m_landing.SetPosition(position);
			m_landing.SetRadius(num);
			m_landing.SetVisible(visible: true);
			bool flag = TrollstavAimPlugin.CfgShowInnerRing.Value && num2 > 0.05f && Mathf.Abs(num2 - num) > 0.05f;
			if (m_inner != null)
			{
				if (flag)
				{
					m_inner.SetPosition(position);
					m_inner.SetRadius(num2);
					m_inner.SetVisible(visible: true);
				}
				else
				{
					m_inner.SetVisible(visible: false);
				}
			}
			bool flag2 = TrollstavAimPlugin.CfgShowDamageRing.Value && trollstavInfo.AoeRadius > 0.05f;
			if (m_damage != null)
			{
				if (flag2)
				{
					float radius = ((TrollstavAimPlugin.CfgDamageRadiusOverride.Value > 0f) ? TrollstavAimPlugin.CfgDamageRadiusOverride.Value : trollstavInfo.AoeRadius);
					m_damage.SetPosition(position);
					m_damage.SetRadius(radius);
					m_damage.SetVisible(visible: true);
				}
				else
				{
					m_damage.SetVisible(visible: false);
				}
			}
			if (!m_shownOnce)
			{
				m_shownOnce = true;
				TrollstavAimPlugin.Log.LogInfo((object)("Indicator active. " + TrollstavData.Describe(localPlayer, trollstavInfo) + " ringRadius=" + num.ToString("0.##") + " inner=" + num2.ToString("0.##")));
			}
			if (TrollstavAimPlugin.CfgLogPrediction.Value && Time.time >= m_nextDiagLog)
			{
				m_nextDiagLog = Time.time + 1f;
				TrollstavAimPlugin.Log.LogInfo((object)("predict: " + TrollstavData.Describe(localPlayer, trollstavInfo)));
			}
		}
	}

	private bool EnsureRings()
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		if (m_landing != null && m_landing.Valid)
		{
			return true;
		}
		if (Time.time < m_nextCreateAttempt)
		{
			return false;
		}
		m_nextCreateAttempt = Time.time + 2f;
		m_landing = GroundRing.Create("landing", TrollstavAimPlugin.CfgRingSegments.Value, TrollstavAimPlugin.CfgRingThickness.Value, TrollstavAimPlugin.CfgHeightOffset.Value, TrollstavAimPlugin.CfgRingColor.Value, out var error);
		if (m_landing == null)
		{
			if (!m_creationFailedLogged)
			{
				m_creationFailedLogged = true;
				TrollstavAimPlugin.Log.LogWarning((object)("Cannot build the landing ring: " + error));
			}
			return false;
		}
		m_creationFailedLogged = false;
		m_inner = GroundRing.Create("inner", TrollstavAimPlugin.CfgRingSegments.Value, TrollstavAimPlugin.CfgInnerThickness.Value, TrollstavAimPlugin.CfgHeightOffset.Value, TrollstavAimPlugin.CfgRingColor.Value, out error);
		if (m_inner == null)
		{
			TrollstavAimPlugin.Log.LogWarning((object)("Inner ring unavailable: " + error));
		}
		m_damage = GroundRing.Create("damage", TrollstavAimPlugin.CfgDamageSegments.Value, TrollstavAimPlugin.CfgDamageThickness.Value, TrollstavAimPlugin.CfgHeightOffset.Value, TrollstavAimPlugin.CfgDamageRingColor.Value, out error);
		if (m_damage == null)
		{
			TrollstavAimPlugin.Log.LogWarning((object)("Damage ring unavailable: " + error));
		}
		return true;
	}

	private void Hide()
	{
		if (m_landing != null)
		{
			m_landing.SetVisible(visible: false);
		}
		if (m_inner != null)
		{
			m_inner.SetVisible(visible: false);
		}
		if (m_damage != null)
		{
			m_damage.SetVisible(visible: false);
		}
		m_shownOnce = false;
	}

	public void Rebuild()
	{
		if (m_landing != null)
		{
			m_landing.Destroy();
			m_landing = null;
		}
		if (m_inner != null)
		{
			m_inner.Destroy();
			m_inner = null;
		}
		if (m_damage != null)
		{
			m_damage.Destroy();
			m_damage = null;
		}
		m_nextCreateAttempt = 0f;
		m_creationFailedLogged = false;
	}
}
internal sealed class GroundRing
{
	private const int RayMaskUnset = -1;

	private static int s_rayMask = -1;

	private static Shader s_shader;

	private readonly GameObject m_root;

	private readonly Mesh m_mesh;

	private readonly Material m_material;

	private readonly MeshRenderer m_renderer;

	private readonly List<Vector3> m_buffer = new List<Vector3>();

	private readonly int m_segments;

	private readonly float m_thickness;

	private readonly float m_heightOffset;

	private Vector3 m_position;

	private float m_radius;

	private bool m_active;

	private bool m_dirty = true;

	private int m_framesSinceRebuild = 999;

	public bool Valid => (Object)(object)m_root != (Object)null;

	private GroundRing(string name, int segments, float thickness, float heightOffset, Color color)
	{
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Expected O, but got Unknown
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Expected O, but got Unknown
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Expected O, but got Unknown
		m_segments = Mathf.Clamp(segments, 6, 200);
		m_thickness = Mathf.Max(0.02f, thickness);
		m_heightOffset = heightOffset;
		m_root = new GameObject("TrollstavAim_" + name);
		Object.DontDestroyOnLoad((Object)(object)m_root);
		m_root.transform.position = Vector3.zero;
		m_root.transform.rotation = Quaternion.identity;
		m_root.transform.localScale = Vector3.one;
		m_material = new Material(s_shader)
		{
			name = "TrollstavAim_" + name + "_mat"
		};
		m_material.mainTexture = (Texture)(object)Texture2D.whiteTexture;
		m_material.renderQueue = 3000;
		ApplyColor(color);
		m_mesh = new Mesh
		{
			name = "TrollstavAim_" + name + "_mesh"
		};
		m_mesh.MarkDynamic();
		m_root.AddComponent<MeshFilter>().sharedMesh = m_mesh;
		m_renderer = m_root.AddComponent<MeshRenderer>();
		((Renderer)m_renderer).sharedMaterial = m_material;
		((Renderer)m_renderer).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)m_renderer).receiveShadows = false;
		((Renderer)m_renderer).enabled = true;
		BuildTopology();
		m_root.SetActive(false);
	}

	public static GroundRing Create(string name, int segments, float thickness, float heightOffset, Color color, out string error)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		error = null;
		if (!EnsureResources(out error))
		{
			return null;
		}
		try
		{
			GroundRing groundRing = new GroundRing(name, segments, thickness, heightOffset, color);
			ManualLogSource log = TrollstavAimPlugin.Log;
			string[] obj = new string[10]
			{
				"Ring '",
				name,
				"' ready: shader=",
				((Object)s_shader).name,
				" segments=",
				null,
				null,
				null,
				null,
				null
			};
			int segments2 = groundRing.m_segments;
			obj[5] = segments2.ToString();
			obj[6] = " thickness=";
			float thickness2 = groundRing.m_thickness;
			obj[7] = thickness2.ToString("0.##");
			obj[8] = " rayMask=";
			obj[9] = s_rayMask.ToString();
			log.LogInfo((object)string.Concat(obj));
			return groundRing;
		}
		catch (Exception ex)
		{
			error = ex.ToString();
			return null;
		}
	}

	private static bool EnsureResources(out string error)
	{
		error = null;
		if (s_rayMask == -1)
		{
			s_rayMask = LayerMask.GetMask(new string[5] { "Default", "static_solid", "Default_small", "piece", "terrain" });
			if (s_rayMask == 0)
			{
				s_rayMask = -5;
				TrollstavAimPlugin.Log.LogWarning((object)"Valheim layer names not found, ring will use the default raycast layers.");
			}
		}
		if ((Object)(object)s_shader != (Object)null)
		{
			return true;
		}
		string[] array = new string[4] { "Sprites/Default", "Legacy Shaders/Particles/Alpha Blended", "UI/Default", "Legacy Shaders/Diffuse" };
		foreach (string text in array)
		{
			try
			{
				s_shader = Shader.Find(text);
			}
			catch
			{
				s_shader = null;
			}
			if ((Object)(object)s_shader != (Object)null)
			{
				break;
			}
		}
		if ((Object)(object)s_shader == (Object)null)
		{
			error = "no unlit/transparent shader found in this build";
			return false;
		}
		return true;
	}

	private void BuildTopology()
	{
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		int segments = m_segments;
		Vector3[] array = (Vector3[])(object)new Vector3[segments * 2];
		m_buffer.Capacity = segments * 2;
		Vector2[] array2 = (Vector2[])(object)new Vector2[segments * 2];
		Color32[] array3 = (Color32[])(object)new Color32[segments * 2];
		int[] array4 = new int[segments * 6];
		for (int i = 0; i < segments; i++)
		{
			int num = i * 2;
			int num2 = num + 1;
			int num3 = (i + 1) % segments * 2;
			int num4 = num3 + 1;
			array4[i * 6] = num;
			array4[i * 6 + 1] = num3;
			array4[i * 6 + 2] = num4;
			array4[i * 6 + 3] = num;
			array4[i * 6 + 4] = num4;
			array4[i * 6 + 5] = num2;
			array2[num] = new Vector2(0f, (float)i / (float)segments);
			array2[num2] = new Vector2(1f, (float)i / (float)segments);
			array3[num] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
			array3[num2] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
			array[num] = Vector3.zero;
			array[num2] = Vector3.zero;
		}
		m_mesh.vertices = array;
		m_mesh.uv = array2;
		m_mesh.colors32 = array3;
		m_mesh.triangles = array4;
		m_mesh.RecalculateBounds();
	}

	public void ApplyColor(Color color)
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)m_material == (Object)null))
		{
			if (m_material.HasProperty("_Color"))
			{
				m_material.SetColor("_Color", color);
			}
			if (m_material.HasProperty("_TintColor"))
			{
				m_material.SetColor("_TintColor", color);
			}
		}
	}

	public void SetPosition(Vector3 position)
	{
		//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_0007: 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_001c: 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)
		Vector3 val = m_position - position;
		if (((Vector3)(ref val)).sqrMagnitude > 0.0001f)
		{
			m_position = position;
			m_dirty = true;
		}
	}

	public void SetRadius(float radius)
	{
		radius = Mathf.Max(0.05f, radius);
		if (!Mathf.Approximately(m_radius, radius))
		{
			m_radius = radius;
			m_dirty = true;
		}
	}

	public void SetVisible(bool visible)
	{
		if (!((Object)(object)m_root == (Object)null) && m_active != visible)
		{
			m_active = visible;
			m_root.SetActive(visible);
			m_dirty = true;
		}
	}

	public void Destroy()
	{
		if ((Object)(object)m_root != (Object)null)
		{
			Object.Destroy((Object)(object)m_root);
		}
		if ((Object)(object)m_mesh != (Object)null)
		{
			Object.Destroy((Object)(object)m_mesh);
		}
		if ((Object)(object)m_material != (Object)null)
		{
			Object.Destroy((Object)(object)m_material);
		}
	}

	public void Rebuild()
	{
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: 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_0140: Unknown result type (might be due to invalid IL or missing references)
		if (!m_active || (Object)(object)m_root == (Object)null)
		{
			return;
		}
		m_framesSinceRebuild++;
		if (m_dirty || m_framesSinceRebuild >= 30)
		{
			m_dirty = false;
			m_framesSinceRebuild = 0;
			int segments = m_segments;
			float num = Mathf.Max(0.02f, m_radius - m_thickness * 0.5f);
			float num2 = m_radius + m_thickness * 0.5f;
			m_buffer.Clear();
			Vector3 position = m_position;
			for (int i = 0; i < segments; i++)
			{
				float num3 = (float)i / (float)segments * (float)Math.PI * 2f;
				float num4 = Mathf.Sin(num3);
				float num5 = Mathf.Cos(num3);
				float num6 = position.x + num4 * num;
				float num7 = position.z + num5 * num;
				float num8 = SampleGround(num6, position.y, num7);
				float num9 = position.x + num4 * num2;
				float num10 = position.z + num5 * num2;
				float num11 = SampleGround(num9, position.y, num10);
				m_buffer.Add(new Vector3(num6, num8 + m_heightOffset, num7));
				m_buffer.Add(new Vector3(num9, num11 + m_heightOffset, num10));
			}
			m_mesh.SetVertices(m_buffer);
			m_mesh.RecalculateBounds();
		}
	}

	private static float SampleGround(float x, float referenceY, float z)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		float num = referenceY + 60f;
		RaycastHit val = default(RaycastHit);
		if (Physics.Raycast(new Vector3(x, num, z), Vector3.down, ref val, 240f, s_rayMask))
		{
			return ((RaycastHit)(ref val)).point.y;
		}
		return referenceY;
	}
}
[BepInPlugin("Ovosh1337.TrollstavAim", "Trollstav Aim Indicator", "1.0.0")]
public class TrollstavAimPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(ZNetScene), "Awake")]
	private static class Patch_ZNetScene_Awake
	{
		[HarmonyPostfix]
		private static void Postfix(ZNetScene __instance)
		{
			Log.LogInfo((object)("ZNetScene awake: " + __instance.m_prefabs.Count + " net prefabs, " + __instance.m_nonNetViewPrefabs.Count + " non-net prefabs."));
			if ((Object)(object)Instance != (Object)null)
			{
				((MonoBehaviour)Instance).StartCoroutine(DelayedRecon());
			}
		}

		private static IEnumerator DelayedRecon()
		{
			if (!CfgReconOnStart.Value)
			{
				yield break;
			}
			float[] array = new float[3] { 0f, 5f, 20f };
			foreach (float num in array)
			{
				if (num > 0f)
				{
					yield return (object)new WaitForSeconds(num);
				}
				RunRecon();
			}
		}
	}

	public const string PluginGuid = "Ovosh1337.TrollstavAim";

	public const string PluginName = "Trollstav Aim Indicator";

	public const string PluginVersion = "1.0.0";

	internal static ManualLogSource Log;

	internal static TrollstavAimPlugin Instance;

	internal static AimIndicator Indicator;

	internal static ConfigEntry<bool> CfgEnabled;

	internal static ConfigEntry<KeyCode> CfgToggleKey;

	internal static ConfigEntry<string> CfgTrackedItems;

	internal static ConfigEntry<int> CfgRingSegments;

	internal static ConfigEntry<float> CfgRingThickness;

	internal static ConfigEntry<float> CfgInnerThickness;

	internal static ConfigEntry<float> CfgHeightOffset;

	internal static ConfigEntry<Color> CfgRingColor;

	internal static ConfigEntry<float> CfgRadiusOverride;

	internal static ConfigEntry<bool> CfgShowInnerRing;

	internal static ConfigEntry<bool> CfgShowDamageRing;

	internal static ConfigEntry<int> CfgDamageSegments;

	internal static ConfigEntry<float> CfgDamageThickness;

	internal static ConfigEntry<float> CfgDamageRadiusOverride;

	internal static ConfigEntry<Color> CfgDamageRingColor;

	internal static ConfigEntry<bool> CfgReconOnStart;

	internal static ConfigEntry<string> CfgReconPrefabs;

	internal static ConfigEntry<bool> CfgReconListAll;

	internal static ConfigEntry<KeyCode> CfgReconKey;

	internal static ConfigEntry<bool> CfgLogPrediction;

	private static readonly HashSet<string> s_tracked = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

	private Harmony m_harmony;

	private bool m_dumpedMenuTime;

	private void Awake()
	{
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Expected O, but got Unknown
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Expected O, but got Unknown
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Expected O, but got Unknown
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Expected O, but got Unknown
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		//IL_0233: Expected O, but got Unknown
		//IL_0266: Unknown result type (might be due to invalid IL or missing references)
		//IL_0270: Expected O, but got Unknown
		//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ad: Expected O, but got Unknown
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d0: Expected O, but got Unknown
		//IL_0424: Unknown result type (might be due to invalid IL or missing references)
		//IL_0429: Unknown result type (might be due to invalid IL or missing references)
		//IL_042f: Expected O, but got Unknown
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		CfgEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1. General", "Enabled", true, "Show the landing indicator while a summon staff is equipped.");
		CfgToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("1. General", "ToggleKey", (KeyCode)289, "Hotkey that switches the indicator on and off.");
		CfgTrackedItems = ((BaseUnityPlugin)this).Config.Bind<string>("1. General", "TrackedItems", "StaffRedTroll,$item_staffredtroll", "Comma separated item prefab names (or item name tokens) that get an indicator. The vanilla Trollstav is StaffRedTroll.");
		CfgRingSegments = ((BaseUnityPlugin)this).Config.Bind<int>("2. Landing ring", "Segments", 40, new ConfigDescription("How many segments the landing ring is built from.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(8, 200), Array.Empty<object>()));
		CfgRadiusOverride = ((BaseUnityPlugin)this).Config.Bind<float>("2. Landing ring", "RadiusOverride", 0f, new ConfigDescription("0 = use the staff's own spawn radius (the game rolls the landing spot anywhere between half and all of it). Set a positive value to force a radius in meters.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 30f), Array.Empty<object>()));
		CfgShowInnerRing = ((BaseUnityPlugin)this).Config.Bind<bool>("2. Landing ring", "ShowInnerRing", true, "Also draw the inner edge of the landing area. The spot is never closer to the centre than this.");
		CfgRingThickness = ((BaseUnityPlugin)this).Config.Bind<float>("2. Landing ring", "Thickness", 0.35f, new ConfigDescription("Width of the ring band in meters.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 3f), Array.Empty<object>()));
		CfgInnerThickness = ((BaseUnityPlugin)this).Config.Bind<float>("2. Landing ring", "InnerThickness", 0.16f, new ConfigDescription("Width of the inner band in meters.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 3f), Array.Empty<object>()));
		CfgHeightOffset = ((BaseUnityPlugin)this).Config.Bind<float>("2. Landing ring", "HeightOffset", 0.07f, "How far above the ground the ring floats.");
		CfgRingColor = ((BaseUnityPlugin)this).Config.Bind<Color>("2. Landing ring", "Color", new Color(1f, 0.45f, 0.1f, 0.9f), "Ring colour (RGBA).");
		CfgShowDamageRing = ((BaseUnityPlugin)this).Config.Bind<bool>("3. Damage ring", "Enabled", false, "Also draw the radius of the impact blast the summoned creature lands with.");
		CfgDamageSegments = ((BaseUnityPlugin)this).Config.Bind<int>("3. Damage ring", "Segments", 56, new ConfigDescription("How many segments the damage ring is built from.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(8, 200), Array.Empty<object>()));
		CfgDamageThickness = ((BaseUnityPlugin)this).Config.Bind<float>("3. Damage ring", "Thickness", 0.5f, new ConfigDescription("Width of the damage ring band in meters.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 3f), Array.Empty<object>()));
		CfgDamageRadiusOverride = ((BaseUnityPlugin)this).Config.Bind<float>("3. Damage ring", "RadiusOverride", 0f, new ConfigDescription("0 = use the attack's own blast radius.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 40f), Array.Empty<object>()));
		CfgDamageRingColor = ((BaseUnityPlugin)this).Config.Bind<Color>("3. Damage ring", "Color", new Color(1f, 0.15f, 0.1f, 0.75f), "Damage ring colour (RGBA).");
		CfgLogPrediction = ((BaseUnityPlugin)this).Config.Bind<bool>("4. Debug", "LogPrediction", false, "Write the predicted landing point to the log once a second while the staff is held.");
		CfgReconOnStart = ((BaseUnityPlugin)this).Config.Bind<bool>("4. Debug", "DumpPrefabsOnStart", false, "Write BepInEx/TrollstavAim-recon.log with the loaded prefab data after the net scene is built.");
		CfgReconPrefabs = ((BaseUnityPlugin)this).Config.Bind<string>("4. Debug", "DumpPrefabNames", "StaffRedTroll", "Comma separated prefab names to dump.");
		CfgReconListAll = ((BaseUnityPlugin)this).Config.Bind<bool>("4. Debug", "DumpListAllTrollPrefabs", true, "Also list every loaded prefab whose name contains troll/staff/summon.");
		CfgReconKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("4. Debug", "DumpHotkey", (KeyCode)290, "Hotkey that re-runs the prefab dump while in game.");
		RefreshTrackedItems();
		CfgTrackedItems.SettingChanged += delegate
		{
			RefreshTrackedItems();
		};
		m_harmony = new Harmony("Ovosh1337.TrollstavAim");
		try
		{
			m_harmony.PatchAll(typeof(TrollstavAimPlugin).Assembly);
			Log.LogInfo((object)"Harmony patches applied.");
		}
		catch (Exception ex)
		{
			Log.LogError((object)("Harmony PatchAll failed: " + ex));
		}
		GameObject val = new GameObject("TrollstavAim.Indicator");
		Object.DontDestroyOnLoad((Object)val);
		Indicator = val.AddComponent<AimIndicator>();
		Log.LogInfo((object)"Trollstav Aim Indicator 1.0.0 loaded.");
	}

	internal static bool IsTrackedItem(string prefabName, string itemToken)
	{
		if (prefabName != null && prefabName.Length > 0 && s_tracked.Contains(prefabName))
		{
			return true;
		}
		if (itemToken != null && itemToken.Length > 0 && s_tracked.Contains(itemToken))
		{
			return true;
		}
		return false;
	}

	private static void RefreshTrackedItems()
	{
		s_tracked.Clear();
		string[] array = (CfgTrackedItems.Value ?? string.Empty).Split(new char[1] { ',' });
		for (int i = 0; i < array.Length; i++)
		{
			string text = array[i].Trim();
			if (text.Length > 0)
			{
				s_tracked.Add(text);
			}
		}
		TrollstavData.ClearCache();
	}

	private void Update()
	{
		//IL_0032: 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)
		try
		{
			if (CfgReconOnStart.Value && !m_dumpedMenuTime && (Object)(object)ObjectDB.instance != (Object)null)
			{
				m_dumpedMenuTime = true;
				RunRecon();
			}
			if (Input.GetKeyDown(CfgToggleKey.Value))
			{
				CfgEnabled.Value = !CfgEnabled.Value;
				Log.LogInfo((object)("Indicator " + (CfgEnabled.Value ? "enabled" : "disabled") + "."));
				if ((Object)(object)Player.m_localPlayer != (Object)null)
				{
					((Character)Player.m_localPlayer).Message((MessageType)1, "Trollstav Aim Indicator: " + (CfgEnabled.Value ? "on" : "off"), 0, (Sprite)null, false);
				}
			}
			if (Input.GetKeyDown(CfgReconKey.Value))
			{
				RunRecon();
			}
		}
		catch (Exception ex)
		{
			Log.LogError((object)("Update: " + ex));
		}
	}

	internal static void RunRecon()
	{
		try
		{
			string text = Path.Combine(Paths.GameRootPath, "BepInEx", "TrollstavAim-recon.log");
			List<string> list = new List<string>();
			string[] array = (CfgReconPrefabs.Value ?? string.Empty).Split(new char[1] { ',' });
			for (int i = 0; i < array.Length; i++)
			{
				string text2 = array[i].Trim();
				if (text2.Length > 0)
				{
					list.Add(text2);
				}
			}
			Recon.WriteReport(text, list, CfgReconListAll.Value);
			Log.LogInfo((object)("Recon written to " + text));
		}
		catch (Exception ex)
		{
			Log.LogError((object)("Recon failed: " + ex));
		}
	}
}
internal static class Recon
{
	private const int MaxDepth = 8;

	private const int MaxLines = 40000;

	private const int MaxCollection = 24;

	private static readonly HashSet<int> s_visited = new HashSet<int>();

	private static readonly StringBuilder s_sb = new StringBuilder();

	private static int s_lines;

	private static readonly HashSet<string> s_skipFieldDeclaringTypes = new HashSet<string> { "UnityEngine.Object", "UnityEngine.Component", "UnityEngine.Behaviour", "UnityEngine.MonoBehaviour", "UnityEngine.ScriptableObject", "UnityEngine.GameObject", "UnityEngine.Transform", "System.Object" };

	public static void WriteReport(string path, IEnumerable<string> prefabNames, bool listTrollPrefabs)
	{
		s_visited.Clear();
		s_sb.Length = 0;
		s_lines = 0;
		Line("=== TrollstavAim prefab recon ===");
		Line("time: " + DateTime.Now.ToString("u"));
		Line("game: " + (((Object)(object)ZNetScene.instance != (Object)null) ? "ZNetScene present" : "ZNetScene MISSING"));
		Line("");
		DumpShaders();
		if (listTrollPrefabs)
		{
			ZNetScene instance = ZNetScene.instance;
			ObjectDB instance2 = ObjectDB.instance;
			Line("--- ZNetScene: " + (((Object)(object)instance == (Object)null) ? "not loaded (main menu)" : "loaded") + " | ObjectDB: " + (((Object)(object)instance2 == (Object)null) ? "not loaded" : (instance2.m_items.Count + " items")) + " ---");
			if ((Object)(object)instance != (Object)null)
			{
				int num = 0;
				int num2 = 0;
				foreach (GameObject prefab in instance.m_prefabs)
				{
					if ((Object)(object)prefab == (Object)null)
					{
						num++;
					}
				}
				foreach (GameObject nonNetViewPrefab in instance.m_nonNetViewPrefabs)
				{
					if ((Object)(object)nonNetViewPrefab == (Object)null)
					{
						num2++;
					}
				}
				Line("--- ZNetScene prefab lists: " + instance.m_prefabs.Count + " net (" + num + " unresolved), " + instance.m_nonNetViewPrefabs.Count + " non-net (" + num2 + " unresolved) ---");
			}
			Line("--- prefabs whose name matches troll/staff/summon ---");
			List<string> list = new List<string>();
			if ((Object)(object)instance != (Object)null)
			{
				foreach (GameObject prefab2 in instance.m_prefabs)
				{
					if (!((Object)(object)prefab2 == (Object)null) && Matches(((Object)prefab2).name))
					{
						list.Add(((Object)prefab2).name);
					}
				}
				foreach (GameObject nonNetViewPrefab2 in instance.m_nonNetViewPrefabs)
				{
					if (!((Object)(object)nonNetViewPrefab2 == (Object)null) && Matches(((Object)nonNetViewPrefab2).name))
					{
						list.Add(((Object)nonNetViewPrefab2).name + "   [nonNetView]");
					}
				}
			}
			if ((Object)(object)instance2 != (Object)null)
			{
				foreach (GameObject item in instance2.m_items)
				{
					if (!((Object)(object)item == (Object)null) && Matches(((Object)item).name))
					{
						list.Add(((Object)item).name + "   [ObjectDB]");
					}
				}
			}
			list.Sort(StringComparer.OrdinalIgnoreCase);
			foreach (string item2 in list)
			{
				Line("  " + item2);
			}
			Line("");
		}
		foreach (string prefabName in prefabNames)
		{
			GameObject val = FindPrefab(prefabName);
			Line("================================================================");
			if ((Object)(object)val == (Object)null)
			{
				Line("PREFAB NOT FOUND: " + prefabName);
				Line("");
				continue;
			}
			Line("PREFAB: " + prefabName + "   (instanceID " + ((Object)val).GetInstanceID() + ")");
			Line("================================================================");
			DumpGameObject(val, "", 0);
			Line("");
		}
		File.WriteAllText(path, s_sb.ToString(), new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
	}

	internal static GameObject FindPrefab(string name)
	{
		ZNetScene instance = ZNetScene.instance;
		if ((Object)(object)instance != (Object)null)
		{
			GameObject prefab = instance.GetPrefab(name);
			if ((Object)(object)prefab != (Object)null)
			{
				return prefab;
			}
		}
		ObjectDB instance2 = ObjectDB.instance;
		if ((Object)(object)instance2 != (Object)null)
		{
			GameObject itemPrefab = instance2.GetItemPrefab(name);
			if ((Object)(object)itemPrefab != (Object)null)
			{
				return itemPrefab;
			}
			foreach (GameObject item in instance2.m_items)
			{
				if ((Object)(object)item != (Object)null && ((Object)item).name == name)
				{
					return item;
				}
			}
		}
		return null;
	}

	private static void DumpShaders()
	{
		Line("--- Shader.Find probes ---");
		string[] array = new string[15]
		{
			"Sprites/Default", "Unlit/Color", "Unlit/Transparent", "Unlit/Texture", "Legacy Shaders/Diffuse", "Legacy Shaders/Transparent/Diffuse", "Particles/Standard Unlit", "Particles/Alpha Blended", "Particles/Additive", "UI/Default",
			"Standard", "Mobile/Particles/Alpha Blended", "Custom/Decal", "Custom/Unlit", "Custom/Particles"
		};
		foreach (string text in array)
		{
			Shader val = null;
			try
			{
				val = Shader.Find(text);
			}
			catch
			{
			}
			Line("  " + text + " -> " + (((Object)(object)val != (Object)null) ? "FOUND" : "missing"));
		}
		Line("");
		Line("--- loaded shaders (name : supported) ---");
		List<string> list = new List<string>();
		try
		{
			Shader[] array2 = Resources.FindObjectsOfTypeAll<Shader>();
			foreach (Shader val2 in array2)
			{
				if (!((Object)(object)val2 == (Object)null))
				{
					list.Add(((Object)val2).name);
				}
			}
		}
		catch (Exception ex)
		{
			Line("  <failed: " + ex.Message + ">");
		}
		list.Sort(StringComparer.OrdinalIgnoreCase);
		foreach (string item in list)
		{
			Line("  " + item);
		}
		Line("");
	}

	private static bool Matches(string name)
	{
		string text = name.ToLowerInvariant();
		if (!text.Contains("troll") && !text.Contains("staff"))
		{
			return text.Contains("summon");
		}
		return true;
	}

	private static void Line(string s)
	{
		if (s_lines++ > 40000)
		{
			if (s_lines == 40001)
			{
				s_sb.AppendLine("... OUTPUT TRUNCATED ...");
			}
		}
		else
		{
			s_sb.AppendLine(s);
		}
	}

	private static void DumpGameObject(GameObject go, string indent, int depth)
	{
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)go == (Object)null)
		{
			Line(indent + "<null GameObject>");
			return;
		}
		if (depth > 8)
		{
			Line(indent + ((Object)go).name + " ... (max depth)");
			return;
		}
		if (!s_visited.Add(((Object)go).GetInstanceID()))
		{
			Line(indent + "GameObject " + ((Object)go).name + "  (already dumped)");
			return;
		}
		Line(indent + "GameObject \"" + ((Object)go).name + "\" active=" + go.activeSelf + " pos=" + Fmt(go.transform.position));
		Component[] components = go.GetComponents<Component>();
		foreach (Component val in components)
		{
			if (!((Object)(object)val == (Object)null))
			{
				Line(indent + "  [" + ((object)val).GetType().FullName + "]");
				DumpFields(val, indent + "    ", depth + 1, ((object)val).GetType());
			}
		}
	}

	private static void DumpFields(object obj, string indent, int depth, Type type)
	{
		if (obj == null || type == null || depth > 8)
		{
			return;
		}
		Type type2 = type;
		while (type2 != null && type2 != typeof(object) && !s_skipFieldDeclaringTypes.Contains(type2.FullName))
		{
			FieldInfo[] fields;
			try
			{
				fields = type2.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			catch
			{
				break;
			}
			FieldInfo[] array = fields;
			foreach (FieldInfo fieldInfo in array)
			{
				if (!fieldInfo.IsStatic && !(fieldInfo.Name == "m_CachedPtr") && !(fieldInfo.Name == "m_InstanceID"))
				{
					object value;
					try
					{
						value = fieldInfo.GetValue(obj);
					}
					catch (Exception ex)
					{
						Line(indent + fieldInfo.Name + " = <throw " + ex.GetType().Name + ">");
						continue;
					}
					DumpValue(fieldInfo.Name, value, indent, depth, fieldInfo.FieldType);
				}
			}
			type2 = type2.BaseType;
		}
	}

	private unsafe static void DumpValue(string name, object v, string indent, int depth, Type declaredType)
	{
		//IL_033f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0344: Unknown result type (might be due to invalid IL or missing references)
		//IL_034d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0368: Unknown result type (might be due to invalid IL or missing references)
		//IL_036d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0396: Unknown result type (might be due to invalid IL or missing references)
		//IL_039b: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ab: 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)
		if (v == null)
		{
			Line(indent + name + " = null");
			return;
		}
		if (v is string text)
		{
			Line(indent + name + " = \"" + text + "\"");
			return;
		}
		if (v is bool flag)
		{
			Line(indent + name + " = " + (flag ? "true" : "false"));
			return;
		}
		if (v is Enum)
		{
			Line(indent + name + " = " + v?.ToString() + " (" + Convert.ToInt64(v).ToString(CultureInfo.InvariantCulture) + ")");
			return;
		}
		if (v is IFormattable && (v is float || v is double || v is int || v is uint || v is long || v is short || v is byte || v is sbyte || v is decimal))
		{
			Line(indent + name + " = " + v);
			return;
		}
		Object val = (Object)((v is Object) ? v : null);
		if (val != null)
		{
			if (val == (Object)null)
			{
				Line(indent + name + " = <destroyed " + declaredType.Name + ">");
				return;
			}
			GameObject val2 = (GameObject)(object)((val is GameObject) ? val : null);
			string text2 = ((val2 != null) ? (" components=" + val2.GetComponents<Component>().Length) : "");
			Line(indent + name + " = " + ((object)val).GetType().Name + " \"" + val.name + "\"" + text2);
			if (depth < 8)
			{
				GameObject val3 = (GameObject)(object)((val is GameObject) ? val : null);
				if (val3 != null)
				{
					DumpGameObject(val3, indent + "  ", depth + 1);
				}
				else
				{
					DumpFields(val, indent + "  ", depth + 1, ((object)val).GetType());
				}
			}
		}
		else if (v is IEnumerable enumerable && !(v is string))
		{
			int num = 0;
			foreach (object item in enumerable)
			{
				if (num >= 24)
				{
					Line(indent + name + "[" + num + "] = ... (truncated)");
					break;
				}
				DumpValue(name + "[" + num + "]", item, indent, depth, item?.GetType() ?? typeof(object));
				num++;
			}
			if (num == 0)
			{
				Line(indent + name + " = <empty>");
			}
		}
		else if (v is Vector3 v2)
		{
			Line(indent + name + " = " + Fmt(v2));
		}
		else if (v is Vector2 val4)
		{
			Line(indent + name + " = " + ((Vector2)(ref val4)).ToString("F3"));
		}
		else if (v is Quaternion val5)
		{
			Vector3 eulerAngles = ((Quaternion)(ref val5)).eulerAngles;
			Line(indent + name + " = " + ((Vector3)(ref eulerAngles)).ToString("F2"));
		}
		else if (v is Color val6)
		{
			Line(indent + name + " = " + ((object)(*(Color*)(&val6))/*cast due to .constrained prefix*/).ToString());
		}
		else
		{
			Type type = v.GetType();
			if (depth < 8 && IsGameType(type))
			{
				Line(indent + name + " : " + type.Name);
				DumpFields(v, indent + "  ", depth + 1, type);
			}
			else
			{
				Line(indent + name + " = " + v);
			}
		}
	}

	private static bool IsGameType(Type t)
	{
		string name = t.Assembly.GetName().Name;
		if (!(name == "assembly_valheim") && !(name == "assembly_utils"))
		{
			return name == "TrollstavAim";
		}
		return true;
	}

	private static string Fmt(Vector3 v)
	{
		return "(" + v.x.ToString("F3", CultureInfo.InvariantCulture) + ", " + v.y.ToString("F3", CultureInfo.InvariantCulture) + ", " + v.z.ToString("F3", CultureInfo.InvariantCulture) + ")";
	}
}
internal sealed class TrollstavInfo
{
	public string PrefabName = "";

	public string ItemToken = "";

	public float Range = 15f;

	public float Height;

	public float Offset;

	public float EitrCost;

	public float HealthCostPercent;

	public string Animation = "";

	public float SpawnRadius = 3f;

	public float SpawnRadiusInner;

	public float SpawnGroundOffset;

	public int SolidHeightMargin = 3;

	public bool SnapToTerrain = true;

	public bool CircleSpawn;

	public float PreSpawnDelay;

	public int MaxSpawned;

	public string SpawnPrefabName = "";

	public float AoeRadius;

	public override string ToString()
	{
		return $"{PrefabName}: range={Range:0.##} height={Height:0.##} offset={Offset:0.##} spawnRadius={SpawnRadius:0.##} (inner {SpawnRadiusInner:0.##}) aoeRadius={AoeRadius:0.##} preSpawnDelay={PreSpawnDelay:0.##} spawns={SpawnPrefabName}";
	}
}
internal static class TrollstavData
{
	private static readonly Dictionary<string, TrollstavInfo> s_cache = new Dictionary<string, TrollstavInfo>();

	private static readonly HashSet<string> s_missing = new HashSet<string>();

	public static TrollstavInfo Resolve(ItemData weapon)
	{
		if (weapon == null)
		{
			return null;
		}
		SharedData shared = weapon.m_shared;
		if (shared == null)
		{
			return null;
		}
		string text = (((Object)(object)weapon.m_dropPrefab != (Object)null) ? ((Object)weapon.m_dropPrefab).name : "");
		string text2 = shared.m_name ?? "";
		if (!TrollstavAimPlugin.IsTrackedItem(text, text2))
		{
			return null;
		}
		string text3 = ((text.Length > 0) ? text : text2);
		if (s_cache.TryGetValue(text3, out var value))
		{
			return value;
		}
		if (s_missing.Contains(text3))
		{
			return null;
		}
		TrollstavInfo trollstavInfo = Build(text3, text2, shared);
		if (trollstavInfo == null)
		{
			s_missing.Add(text3);
			TrollstavAimPlugin.Log.LogWarning((object)("Tracked item '" + text3 + "' has no usable summon attack; indicator disabled for it."));
			return null;
		}
		s_cache[text3] = trollstavInfo;
		TrollstavAimPlugin.Log.LogInfo((object)("Summon staff resolved -> " + trollstavInfo));
		return trollstavInfo;
	}

	private static TrollstavInfo Build(string prefabName, string token, SharedData shared)
	{
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Invalid comparison between Unknown and I4
		Attack attack = shared.m_attack;
		if (attack == null)
		{
			return null;
		}
		GameObject attackProjectile = attack.m_attackProjectile;
		if ((Object)(object)attackProjectile == (Object)null)
		{
			TrollstavAimPlugin.Log.LogWarning((object)("'" + prefabName + "' attack has no projectile prefab."));
			return null;
		}
		SpawnAbility component = attackProjectile.GetComponent<SpawnAbility>();
		if ((Object)(object)component == (Object)null)
		{
			TrollstavAimPlugin.Log.LogWarning((object)("'" + prefabName + "' projectile '" + ((Object)attackProjectile).name + "' has no SpawnAbility (attack type " + ((object)Unsafe.As<AttackType, AttackType>(ref attack.m_attackType)/*cast due to .constrained prefix*/).ToString() + ")."));
			return null;
		}
		TrollstavInfo trollstavInfo = new TrollstavInfo
		{
			PrefabName = prefabName,
			ItemToken = token,
			Range = attack.m_attackRange,
			Height = attack.m_attackHeight,
			Offset = attack.m_attackOffset,
			EitrCost = attack.m_attackEitr,
			HealthCostPercent = attack.m_attackHealthPercentage,
			Animation = attack.m_attackAnimation,
			SpawnRadius = component.m_spawnRadius,
			SpawnGroundOffset = component.m_spawnGroundOffset,
			SolidHeightMargin = component.m_getSolidHeightMargin,
			SnapToTerrain = component.m_snapToTerrain,
			CircleSpawn = component.m_circleSpawn,
			PreSpawnDelay = component.m_preSpawnDelay,
			MaxSpawned = component.m_maxSpawned,
			SpawnPrefabName = ((component.m_spawnPrefab != null && component.m_spawnPrefab.Length != 0 && (Object)(object)component.m_spawnPrefab[0] != (Object)null) ? ((Object)component.m_spawnPrefab[0]).name : "")
		};
		trollstavInfo.SpawnRadiusInner = (((int)component.m_targetType == 4) ? (component.m_spawnRadius * 0.5f) : 0f);
		if ((Object)(object)component.m_aoePrefab != (Object)null)
		{
			Aoe component2 = component.m_aoePrefab.GetComponent<Aoe>();
			if ((Object)(object)component2 != (Object)null)
			{
				trollstavInfo.AoeRadius = component2.m_radius;
			}
		}
		return trollstavInfo;
	}

	public static Vector3 NominalPoint(Player player, TrollstavInfo info)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: 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_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_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)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: 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_007b: Unknown result type (might be due to invalid IL or missing references)
		Transform transform = ((Component)player).transform;
		Vector3 val = transform.position + transform.up * info.Height + transform.forward * info.Range + transform.right * info.Offset;
		ZoneSystem instance = ZoneSystem.instance;
		if ((Object)(object)instance != (Object)null)
		{
			float y = default(float);
			if (instance.GetSolidHeight(val, ref y, info.SolidHeightMargin))
			{
				val.y = y;
			}
			else if (instance.GetSolidHeight(val, ref y, 1000))
			{
				val.y = y;
			}
		}
		return val;
	}

	public static string Describe(Player player, TrollstavInfo info)
	{
		//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_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: 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)
		Vector3 val = NominalPoint(player, info);
		return $"nominal=({val.x:0.00},{val.y:0.00},{val.z:0.00}) range={info.Range:0.##} outer={info.SpawnRadius:0.##} inner={info.SpawnRadiusInner:0.##}";
	}

	public static void ClearCache()
	{
		s_cache.Clear();
		s_missing.Clear();
	}
}