Decompiled source of Player Markers v1.1.1

CrawlPlayerArrows.dll

Decompiled 4 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace CrawlPlayerArrows;

[BepInPlugin("ibeck.crawl.playerarrows", "Player Markers", "1.1.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	private class Arrow
	{
		public GameObject GO;

		public MeshRenderer MR;

		public Material Mat;

		public GameObject Target;

		public float TopOffset;

		public int Layer = -1;

		public float NextBoundsScan;

		public bool TargetVisible;

		public GameObject BodyFor;

		public Renderer Body;
	}

	public const string GUID = "ibeck.crawl.playerarrows";

	public const string NAME = "Player Markers";

	public const string VERSION = "1.1.1";

	private const int MaxSlots = 4;

	private const int TexSize = 17;

	private ConfigEntry<bool> cfgEnabled;

	private ConfigEntry<KeyCode> cfgToggleKey;

	private ConfigEntry<string> cfgMyColor;

	private ConfigEntry<string> cfgOtherColor;

	private ConfigEntry<string> cfgOutlineColor;

	private ConfigEntry<string> cfgNumberColor;

	private ConfigEntry<bool> cfgShowNumbers;

	private ConfigEntry<float> cfgSize;

	private ConfigEntry<float> cfgGap;

	private ConfigEntry<float> cfgBob;

	private ConfigEntry<bool> cfgShowOwn;

	private ConfigEntry<bool> cfgShowBots;

	private ConfigEntry<string> cfgColorMode;

	private Texture2D[] textures = (Texture2D[])(object)new Texture2D[4];

	private bool[] texIsMine = new bool[4];

	private bool[] texBuilt = new bool[4];

	private string texStamp = "";

	private GameObject root;

	private Arrow[] arrows = new Arrow[4];

	private Mesh quad;

	private Shader shader;

	private readonly bool[] mine = new bool[4];

	private readonly float[] lastSeenMine = new float[4];

	private readonly List<MeshRenderer> rendScratch = new List<MeshRenderer>();

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

	private static readonly string[][] Digits = new string[4][]
	{
		new string[5] { "010", "110", "010", "010", "111" },
		new string[5] { "110", "001", "010", "100", "111" },
		new string[5] { "110", "001", "010", "001", "110" },
		new string[5] { "101", "101", "111", "001", "001" }
	};

	private const int DigitLeft = 7;

	private const int DigitTop = 3;

	private static readonly Type[] BodyOwnerTypes = new Type[2]
	{
		typeof(Ghost),
		typeof(Player)
	};

	private void Awake()
	{
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Expected O, but got Unknown
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Expected O, but got Unknown
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Expected O, but got Unknown
		//IL_0236: Unknown result type (might be due to invalid IL or missing references)
		//IL_0240: Expected O, but got Unknown
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0255: Expected O, but got Unknown
		//IL_02af: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
		cfgEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Show the player arrows");
		cfgToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ToggleKey", (KeyCode)289, "Key that turns the arrows on and off");
		cfgShowOwn = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowOwnArrow", true, "Show the green arrow over your own character");
		cfgShowBots = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowBots", true, "Also show red arrows over bot-controlled player slots");
		cfgColorMode = ((BaseUnityPlugin)this).Config.Bind<string>("General", "ColorMode", "Mine", new ConfigDescription("Mine: players on this computer are green, everyone else red. Hero: the hero is green, everyone else red (handy for couch play on one screen; online clients always use Mine).", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[2] { "Mine", "Hero" }), new object[0]));
		cfgMyColor = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", "MyColor", "#2EE84A", "Marker colour for your own character (hex RGB or RGBA)");
		cfgOtherColor = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", "OpponentColor", "#FF3030", "Marker colour for the other players (hex RGB or RGBA)");
		cfgOutlineColor = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", "OutlineColor", "#000000", "Marker outline colour (hex RGB or RGBA)");
		cfgNumberColor = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", "NumberColor", "#101010", "Colour of the player number inside the marker (hex RGB or RGBA)");
		cfgShowNumbers = ((BaseUnityPlugin)this).Config.Bind<bool>("Look", "ShowPlayerNumbers", true, "Show the player number (1-4) inside each marker");
		cfgSize = ((BaseUnityPlugin)this).Config.Bind<float>("Look", "Size", 0.04f, new ConfigDescription("Marker height as a fraction of the screen height", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.02f, 0.2f), new object[0]));
		cfgGap = ((BaseUnityPlugin)this).Config.Bind<float>("Look", "Gap", 0.25f, new ConfigDescription("Space between the character's head and the marker tip, as a fraction of the marker height", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), new object[0]));
		cfgBob = ((BaseUnityPlugin)this).Config.Bind<float>("Look", "Bob", 0.15f, new ConfigDescription("How far the marker bobs up and down, as a fraction of its height (0 = still)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
		for (int i = 0; i < 4; i++)
		{
			Texture2D val = new Texture2D(17, 17, (TextureFormat)4, false);
			((Object)val).name = "CrawlArrows_P" + (i + 1);
			((Texture)val).filterMode = (FilterMode)0;
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Object)val).hideFlags = (HideFlags)32;
			textures[i] = val;
		}
		RebuildTextures(force: true);
		((BaseUnityPlugin)this).Logger.LogInfo((object)("Player Markers 1.1.1 ready. Toggle key: " + ((object)cfgToggleKey.Value/*cast due to .constrained prefix*/).ToString()));
	}

	private void Update()
	{
		//IL_0006: 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)
		try
		{
			if ((int)cfgToggleKey.Value != 0 && Input.GetKeyDown(cfgToggleKey.Value))
			{
				cfgEnabled.Value = !cfgEnabled.Value;
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Player arrows " + (cfgEnabled.Value ? "on" : "off")));
			}
		}
		catch
		{
		}
	}

	private void LateUpdate()
	{
		try
		{
			OnlineBridge.Refresh();
			bool isClient = OnlineBridge.IsClient;
			if (isClient)
			{
				ComputeMineAsClient();
				HideAll();
			}
			else
			{
				ComputeMineAsHost();
			}
			RebuildTextures(force: false);
			if (!isClient)
			{
				UpdateArrows();
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Update failed: " + ex));
			HideAll();
		}
	}

	private void ComputeMineAsClient()
	{
		float realtimeSinceStartup = Time.realtimeSinceStartup;
		int num = OnlineBridge.ClientPlayerSlot();
		if (num >= 0 && num < 4)
		{
			lastSeenMine[num] = realtimeSinceStartup;
		}
		foreach (int item in OnlineBridge.ClientAnchorPlayers())
		{
			if (item >= 0 && item < 4)
			{
				lastSeenMine[item] = realtimeSinceStartup;
			}
		}
		for (int i = 0; i < 4; i++)
		{
			mine[i] = lastSeenMine[i] > 0f && realtimeSinceStartup - lastSeenMine[i] < 5f;
		}
	}

	private void ComputeMineAsHost()
	{
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Expected I4, but got Unknown
		remoteControllers.Clear();
		if (OnlineBridge.IsHost)
		{
			OnlineBridge.HostRemoteControllers(remoteControllers);
		}
		bool flag = string.Equals(cfgColorMode.Value, "Hero", StringComparison.OrdinalIgnoreCase) && !OnlineBridge.IsHost;
		for (int i = 0; i < 4; i++)
		{
			mine[i] = false;
			PlayerData player = GetPlayer(i);
			if (player != null)
			{
				if (flag)
				{
					mine[i] = player.IsHero;
				}
				else if (player.IsHuman && !remoteControllers.Contains((int)player.ControllerId))
				{
					mine[i] = true;
				}
			}
		}
	}

	private static PlayerData GetPlayer(int id)
	{
		try
		{
			if (!Singleton<SystemPlayers>.HasInstance())
			{
				return null;
			}
			PlayerData player = SystemPlayers.GetPlayer(id);
			if (player == null || !player.IsActive)
			{
				return null;
			}
			return player;
		}
		catch
		{
			return null;
		}
	}

	private void RebuildTextures(bool force)
	{
		//IL_00ad: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: 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_00db: 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_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		string text = cfgMyColor.Value + "|" + cfgOtherColor.Value + "|" + cfgOutlineColor.Value + "|" + cfgNumberColor.Value + "|" + cfgShowNumbers.Value;
		if (text != texStamp)
		{
			force = true;
			texStamp = text;
		}
		Color32 val = ParseColor(cfgMyColor.Value, new Color32((byte)46, (byte)232, (byte)74, byte.MaxValue));
		Color32 val2 = ParseColor(cfgOtherColor.Value, new Color32(byte.MaxValue, (byte)48, (byte)48, byte.MaxValue));
		Color32 outline = ParseColor(cfgOutlineColor.Value, new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue));
		Color32 number = ParseColor(cfgNumberColor.Value, new Color32((byte)16, (byte)16, (byte)16, byte.MaxValue));
		for (int i = 0; i < 4; i++)
		{
			if (force || !texBuilt[i] || texIsMine[i] != mine[i])
			{
				FillMarker(textures[i], mine[i] ? val : val2, outline, number, cfgShowNumbers.Value ? i : (-1));
				texIsMine[i] = mine[i];
				texBuilt[i] = true;
			}
		}
	}

	private static bool MarkerFill(int x, int rowFromTop)
	{
		if (rowFromTop < 1 || rowFromTop > 15)
		{
			return false;
		}
		float num = Math.Min(7.5f, (15.5f - (float)rowFromTop) * 0.55f);
		return (float)Math.Abs(x - 8) <= num;
	}

	private static bool DigitPixel(int slot, int x, int rowFromTop)
	{
		if (slot < 0 || slot >= Digits.Length)
		{
			return false;
		}
		int num = x - 7;
		int num2 = rowFromTop - 3;
		if (num < 0 || num > 2 || num2 < 0 || num2 > 4)
		{
			return false;
		}
		return Digits[slot][num2][num] == '1';
	}

	private static void FillMarker(Texture2D t, Color32 fill, Color32 outline, Color32 number, int slot)
	{
		//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_0043: 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_008e: 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_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		Color32[] array = (Color32[])(object)new Color32[289];
		Color32 val = default(Color32);
		((Color32)(ref val))..ctor((byte)0, (byte)0, (byte)0, (byte)0);
		for (int i = 0; i < 17; i++)
		{
			int num = 16 - i;
			for (int j = 0; j < 17; j++)
			{
				Color32 val2 = val;
				if (MarkerFill(j, num))
				{
					val2 = (DigitPixel(slot, j, num) ? number : fill);
				}
				else
				{
					for (int k = -1; k <= 1; k++)
					{
						if (val2.a != 0)
						{
							break;
						}
						for (int l = -1; l <= 1; l++)
						{
							if (MarkerFill(j + l, num + k))
							{
								val2 = outline;
								break;
							}
						}
					}
				}
				array[i * 17 + j] = val2;
			}
		}
		t.SetPixels32(array);
		t.Apply(false, false);
	}

	private static Color32 ParseColor(string s, Color32 fallback)
	{
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: 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_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			s = (s ?? "").Trim().TrimStart(new char[1] { '#' });
			if (s.Length != 6 && s.Length != 8)
			{
				return fallback;
			}
			byte num = Convert.ToByte(s.Substring(0, 2), 16);
			byte b = Convert.ToByte(s.Substring(2, 2), 16);
			byte b2 = Convert.ToByte(s.Substring(4, 2), 16);
			byte b3 = ((s.Length == 8) ? Convert.ToByte(s.Substring(6, 2), 16) : byte.MaxValue);
			return new Color32(num, b, b2, b3);
		}
		catch
		{
			return fallback;
		}
	}

	private void EnsureObjects()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Expected O, but got Unknown
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: 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_00da: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: 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_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: Expected O, but got Unknown
		//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b0: Expected O, but got Unknown
		if (!((Object)(object)root != (Object)null))
		{
			root = new GameObject("CrawlPlayerMarkers");
			Object.DontDestroyOnLoad((Object)(object)root);
			quad = new Mesh();
			((Object)quad).name = "CrawlPlayerArrowQuad";
			quad.vertices = (Vector3[])(object)new Vector3[4]
			{
				new Vector3(-0.5f, 0f, 0f),
				new Vector3(0.5f, 0f, 0f),
				new Vector3(-0.5f, 1f, 0f),
				new Vector3(0.5f, 1f, 0f)
			};
			quad.uv = (Vector2[])(object)new Vector2[4]
			{
				new Vector2(0f, 0f),
				new Vector2(1f, 0f),
				new Vector2(0f, 1f),
				new Vector2(1f, 1f)
			};
			quad.colors32 = (Color32[])(object)new Color32[4]
			{
				new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue),
				new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue),
				new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue),
				new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue)
			};
			quad.triangles = new int[6] { 0, 2, 1, 2, 3, 1 };
			quad.RecalculateBounds();
			shader = Shader.Find("ex2D/Alpha Blended");
			if ((Object)(object)shader == (Object)null)
			{
				shader = Shader.Find("PowerHoof/SpriteTinted");
			}
			if ((Object)(object)shader == (Object)null)
			{
				shader = Shader.Find("Sprites/Default");
			}
			for (int i = 0; i < 4; i++)
			{
				Arrow arrow = new Arrow();
				arrow.GO = new GameObject("CrawlPlayerArrow_P" + (i + 1));
				arrow.GO.transform.SetParent(root.transform, false);
				arrow.GO.AddComponent<MeshFilter>().sharedMesh = quad;
				arrow.MR = arrow.GO.AddComponent<MeshRenderer>();
				arrow.Mat = new Material(shader);
				((Object)arrow.Mat).name = "CrawlPlayerArrowMat_P" + (i + 1);
				arrow.Mat.mainTexture = (Texture)(object)textures[i];
				arrow.Mat.renderQueue = 4000;
				((Renderer)arrow.MR).sharedMaterial = arrow.Mat;
				((Renderer)arrow.MR).receiveShadows = false;
				((Renderer)arrow.MR).enabled = false;
				arrows[i] = arrow;
			}
		}
	}

	private void HideAll()
	{
		for (int i = 0; i < 4; i++)
		{
			if (arrows[i] != null && (Object)(object)arrows[i].MR != (Object)null)
			{
				((Renderer)arrows[i].MR).enabled = false;
			}
		}
	}

	private void UpdateArrows()
	{
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0217: Unknown result type (might be due to invalid IL or missing references)
		//IL_021e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0233: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		EnsureObjects();
		if (!cfgEnabled.Value)
		{
			HideAll();
			return;
		}
		Camera val = null;
		try
		{
			val = SystemMain.GetCameraMain();
		}
		catch
		{
		}
		if ((Object)(object)val == (Object)null)
		{
			val = Camera.main;
		}
		if ((Object)(object)val == (Object)null)
		{
			HideAll();
			return;
		}
		float num = (val.orthographic ? (val.orthographicSize * 2f) : 10f) * cfgSize.Value;
		float num2 = ((cfgBob.Value > 0f) ? (Mathf.Sin(Time.unscaledTime * 4f) * 0.5f * cfgBob.Value * num) : 0f);
		float num3 = cfgGap.Value * num;
		float unscaledTime = Time.unscaledTime;
		for (int i = 0; i < 4; i++)
		{
			Arrow arrow = arrows[i];
			PlayerData player = GetPlayer(i);
			GameObject val2 = null;
			if (player != null)
			{
				try
				{
					val2 = player.GameObject;
				}
				catch
				{
					val2 = null;
				}
				if (player.IsBot && !cfgShowBots.Value)
				{
					val2 = null;
				}
				if (mine[i] && !cfgShowOwn.Value)
				{
					val2 = null;
				}
			}
			if ((Object)(object)val2 == (Object)null || !val2.activeInHierarchy)
			{
				((Renderer)arrow.MR).enabled = false;
				arrow.Target = null;
				continue;
			}
			if ((Object)(object)arrow.Target != (Object)(object)val2)
			{
				arrow.Target = val2;
				arrow.NextBoundsScan = 0f;
				arrow.TopOffset = -1f;
			}
			if (unscaledTime >= arrow.NextBoundsScan)
			{
				ScanTarget(arrow, val2);
				arrow.NextBoundsScan = unscaledTime + 0.1f;
			}
			if (!arrow.TargetVisible)
			{
				((Renderer)arrow.MR).enabled = false;
				continue;
			}
			Vector3 position = val2.transform.position;
			float num4 = (val.orthographic ? (((Component)val).transform.position.z + val.nearClipPlane + 1f) : (position.z - 0.5f));
			Transform transform = arrow.GO.transform;
			transform.position = new Vector3(position.x, position.y + arrow.TopOffset + num3 + num2, num4);
			transform.rotation = Quaternion.identity;
			transform.localScale = new Vector3(num, num, 1f);
			if (arrow.Layer >= 0 && arrow.GO.layer != arrow.Layer)
			{
				arrow.GO.layer = arrow.Layer;
			}
			((Renderer)arrow.MR).enabled = true;
			if (OnlineBridge.IsHost)
			{
				OnlineBridge.SetOwner(arrow.GO, i + 1);
			}
		}
	}

	private void ScanTarget(Arrow a, GameObject target)
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: 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_0108: 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)
		if ((Object)(object)a.BodyFor != (Object)(object)target)
		{
			a.BodyFor = target;
			a.Body = FindBodyRenderer(target);
		}
		bool flag = false;
		Bounds val = default(Bounds);
		int num = -1;
		if ((Object)(object)a.Body != (Object)null)
		{
			Renderer body = a.Body;
			if (body.enabled && ((Component)body).gameObject.activeInHierarchy)
			{
				Bounds bounds = body.bounds;
				if (((Bounds)(ref bounds)).size.y > 0f)
				{
					val = body.bounds;
					flag = true;
					num = ((Component)body).gameObject.layer;
				}
			}
		}
		else
		{
			rendScratch.Clear();
			target.GetComponentsInChildren<MeshRenderer>(false, rendScratch);
			for (int i = 0; i < rendScratch.Count; i++)
			{
				MeshRenderer val2 = rendScratch[i];
				if ((Object)(object)val2 == (Object)null || !((Renderer)val2).enabled || (Object)(object)((Component)val2).GetComponent<TextMesh>() != (Object)null)
				{
					continue;
				}
				Bounds bounds2 = ((Renderer)val2).bounds;
				if (!(((Bounds)(ref bounds2)).size.y <= 0f))
				{
					if (!flag)
					{
						val = bounds2;
						flag = true;
						num = ((Component)val2).gameObject.layer;
					}
					else
					{
						((Bounds)(ref val)).Encapsulate(bounds2);
					}
				}
			}
		}
		a.TargetVisible = flag;
		if (flag)
		{
			if (num != 5 && num != 17)
			{
				a.Layer = num;
			}
			float num2 = Mathf.Max(0f, ((Bounds)(ref val)).max.y - target.transform.position.y);
			a.TopOffset = ((a.TopOffset < 0f) ? num2 : Mathf.Lerp(a.TopOffset, num2, 0.35f));
		}
	}

	private static Renderer FindBodyRenderer(GameObject target)
	{
		try
		{
			Type[] bodyOwnerTypes = BodyOwnerTypes;
			foreach (Type type in bodyOwnerTypes)
			{
				Component val = target.GetComponent(type);
				if ((Object)(object)val == (Object)null)
				{
					val = target.GetComponentInChildren(type);
				}
				if (!((Object)(object)val == (Object)null))
				{
					object? obj = type.GetField("m_sprite", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(val);
					Renderer val2 = null;
					Component val3 = (Component)((obj is Component) ? obj : null);
					if ((Object)(object)val3 != (Object)null)
					{
						val2 = val3.GetComponent<Renderer>();
					}
					GameObject val4 = (GameObject)((obj is GameObject) ? obj : null);
					if ((Object)(object)val2 == (Object)null && (Object)(object)val4 != (Object)null)
					{
						val2 = val4.GetComponent<Renderer>();
					}
					if ((Object)(object)val2 != (Object)null)
					{
						return val2;
					}
				}
			}
		}
		catch
		{
		}
		return null;
	}

	private void OnDestroy()
	{
		if ((Object)(object)root != (Object)null)
		{
			Object.Destroy((Object)(object)root);
		}
	}
}
internal static class OnlineBridge
{
	private static bool s_init;

	private static PropertyInfo s_host;

	private static PropertyInfo s_client;

	private static FieldInfo s_ownerOverrides;

	private static object s_hostObj;

	private static object s_clientObj;

	public static bool IsHost => s_hostObj != null;

	public static bool IsClient => s_clientObj != null;

	private static void Init()
	{
		if (s_init)
		{
			return;
		}
		s_init = true;
		try
		{
			Type type = FindType("CrawlOnline.Online");
			if ((object)type != null)
			{
				s_host = type.GetProperty("Host", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				s_client = type.GetProperty("Client", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			}
			Type type2 = FindType("CrawlOnline.Host.SceneCapture");
			if ((object)type2 != null)
			{
				s_ownerOverrides = type2.GetField("OwnerOverrides", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			}
		}
		catch
		{
		}
	}

	private static Type FindType(string name)
	{
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		foreach (Assembly assembly in assemblies)
		{
			try
			{
				Type type = assembly.GetType(name, throwOnError: false);
				if ((object)type != null)
				{
					return type;
				}
			}
			catch
			{
			}
		}
		return null;
	}

	public static void Refresh()
	{
		Init();
		s_hostObj = null;
		s_clientObj = null;
		try
		{
			if ((object)s_host != null)
			{
				s_hostObj = s_host.GetValue(null, null);
			}
		}
		catch
		{
		}
		try
		{
			if ((object)s_client != null)
			{
				s_clientObj = s_client.GetValue(null, null);
			}
		}
		catch
		{
		}
	}

	private static object Get(object o, string member)
	{
		if (o == null)
		{
			return null;
		}
		Type type = o.GetType();
		FieldInfo field = type.GetField(member, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if ((object)field != null)
		{
			return field.GetValue(o);
		}
		return type.GetProperty(member, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(o, null);
	}

	private static int ToInt(object o, int fallback)
	{
		try
		{
			return (o == null) ? fallback : Convert.ToInt32(o);
		}
		catch
		{
			return fallback;
		}
	}

	public static int ClientPlayerSlot()
	{
		try
		{
			return ToInt(Get(s_clientObj, "MyPlayerSlot"), -1);
		}
		catch
		{
			return -1;
		}
	}

	public static IEnumerable<int> ClientAnchorPlayers()
	{
		List<int> list = new List<int>();
		try
		{
			if (Get(s_clientObj, "m_anchors") is IEnumerable enumerable)
			{
				foreach (object item in enumerable)
				{
					list.Add(ToInt(Get(item, "Player"), -1));
				}
			}
		}
		catch
		{
		}
		return list;
	}

	public static void HostRemoteControllers(HashSet<int> into)
	{
		try
		{
			if (!(Get(s_hostObj, "Clients") is IEnumerable enumerable))
			{
				return;
			}
			foreach (object item in enumerable)
			{
				if (!(Get(item, "Pads") is IEnumerable enumerable2))
				{
					continue;
				}
				foreach (object item2 in enumerable2)
				{
					if (item2 != null)
					{
						int num = ToInt(Get(item2, "DeviceIndex"), -1);
						if (num >= 0)
						{
							into.Add(num);
						}
					}
				}
			}
		}
		catch
		{
		}
	}

	public static void SetOwner(GameObject go, int owner)
	{
		try
		{
			IDictionary dictionary = (((object)s_ownerOverrides != null) ? (s_ownerOverrides.GetValue(null) as IDictionary) : null);
			if (dictionary != null)
			{
				int instanceID = ((Object)go).GetInstanceID();
				object obj = (dictionary.Contains(instanceID) ? dictionary[instanceID] : null);
				if (obj == null || ToInt(obj, -1) != owner)
				{
					dictionary[instanceID] = owner;
				}
			}
		}
		catch
		{
		}
	}
}