Decompiled source of TrailMarks Arrow v1.1.0

TrailMarks.dll

Decompiled 6 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("TrailMarks")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+814ca5a6247512ed74f46c637c2a5db3c7ffbf7a")]
[assembly: AssemblyProduct("TrailMarks")]
[assembly: AssemblyTitle("TrailMarks")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace TrailMarks;

internal static class Eraser
{
	private const float Reach = 1f;

	internal static void EraseAimed()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		if (Spray.TryAim("erased", out var hit, out var _))
		{
			if (!MarkStore.RemoveLocalNear(((RaycastHit)(ref hit)).point, 1f, out var id))
			{
				Plugin.Log.LogInfo((object)"TrailMarks: no mark erased (none of your marks within 1 m of the aimed point).");
				return;
			}
			MarkNet.SendEraseToReady(id);
			Plugin.Log.LogInfo((object)"TrailMarks: erased one of your marks.");
		}
	}
}
internal static class MarkErase
{
	private const string Tag = "t0y9n.trailmarks/erase/1";

	internal static object[] Encode(int id)
	{
		return new object[2] { "t0y9n.trailmarks/erase/1", id };
	}

	internal static bool TryDecode(object data, out int id)
	{
		id = 0;
		if (!(data is object[] array) || array.Length != 2 || !(array[0] is string text) || text != "t0y9n.trailmarks/erase/1" || !(array[1] is int num) || num < 1)
		{
			return false;
		}
		id = num;
		return true;
	}
}
internal static class MarkIcons
{
	private const int Size = 128;

	private const float WorldSize = 0.75f;

	private const float Stroke = 0.034f;

	private const float FineStroke = 0.02f;

	private const float SoftPixels = 1.2f;

	private const float EdgeScale = 4f;

	private const float EdgeRoughness = 0.012f;

	private const float WobbleScale = 24f;

	private const float Wobble = 0.006f;

	private const float GrainMinimum = 0.45f;

	private const float DustScale = 6f;

	private const float DustMinimum = 0.55f;

	private const float ShadowWidth = 0.045f;

	private const float ShadowAlpha = 0.45f;

	private static readonly Color Chalk = new Color(49f / 51f, 0.9490196f, 0.9098039f, 1f);

	private static readonly Color Shadow = new Color(8f / 85f, 0.08627451f, 4f / 51f, 1f);

	private static readonly Sprite[] Sprites = (Sprite[])(object)new Sprite[12];

	internal static Sprite Get(int kind)
	{
		//IL_0023: 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_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Expected O, but got Unknown
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_0281: 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_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: 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)
		if ((Object)(object)Sprites[kind] != (Object)null)
		{
			return Sprites[kind];
		}
		Texture2D val = new Texture2D(128, 128, (TextureFormat)4, true)
		{
			filterMode = (FilterMode)1,
			wrapMode = (TextureWrapMode)1,
			hideFlags = (HideFlags)61
		};
		int num = kind + 1;
		float num2 = MarkKind.AngleDegrees(kind) * (MathF.PI / 180f);
		float num3 = Mathf.Cos(num2);
		float num4 = Mathf.Sin(num2);
		float num5 = 0.009375f;
		Color[] array = (Color[])(object)new Color[16384];
		Vector2 point = default(Vector2);
		for (int i = 0; i < 128; i++)
		{
			for (int j = 0; j < 128; j++)
			{
				float num6 = ((float)j + 0.5f) / 128f - 0.5f;
				float num7 = ((float)i + 0.5f) / 128f - 0.5f;
				((Vector2)(ref point))..ctor(num3 * num6 - num4 * num7 + (Noise(j, i, 24f, num + 101) - 0.5f) * 2f * 0.006f, num4 * num6 + num3 * num7 + (Noise(j, i, 24f, num + 202) - 0.5f) * 2f * 0.006f);
				float num8 = Distance(kind, point);
				float num9 = 0.45f * (1f - Smooth(num8 / 0.045f));
				num8 += (Noise(j, i, 4f, num) - 0.5f) * 2f * 0.012f;
				float num10 = (1f - Smooth((num8 + num5) / (2f * num5))) * Mathf.Lerp(0.45f, 1f, Hash(j, i, num + 7)) * Mathf.Lerp(0.55f, 1f, Noise(j, i, 6f, num + 13));
				float num11 = num10 + num9 * (1f - num10);
				Color val2 = ((num11 > 0f) ? ((Chalk * num10 + Shadow * (num9 * (1f - num10))) / num11) : Chalk);
				val2.a = num11;
				array[i * 128 + j] = val2;
			}
		}
		val.SetPixels(array);
		val.Apply(true, false);
		Sprites[kind] = Sprite.Create(val, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f), 170.66667f);
		((Object)Sprites[kind]).hideFlags = (HideFlags)61;
		return Sprites[kind];
	}

	private static float Distance(int kind, Vector2 point)
	{
		//IL_0004: 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_001c: 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_0028: Unknown result type (might be due to invalid IL or missing references)
		return kind switch
		{
			8 => Luggage(point), 
			9 => Danger(point), 
			10 => Cross(point), 
			11 => Erase(point), 
			_ => Arrow(point), 
		};
	}

	private static float Arrow(Vector2 point)
	{
		//IL_0000: 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_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: 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_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: 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)
		float num = Segment(point, new Vector2(0f, -0.36f), new Vector2(0f, 0.36f));
		float num2 = Segment(point, new Vector2(0f, 0.37f), new Vector2(-0.19f, 0.17f));
		float num3 = Segment(point, new Vector2(0f, 0.37f), new Vector2(0.19f, 0.17f));
		return Mathf.Min(num, Mathf.Min(num2, num3)) - 0.034f;
	}

	private static float Luggage(Vector2 point)
	{
		//IL_0000: 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_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: 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_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: 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_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: 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_00d0: 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_00e5: 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)
		float num = Mathf.Abs(RoundedBox(point - new Vector2(0f, -0.07f), new Vector2(0.36f, 0.25f), 0.07f)) - 0.034f;
		float num2 = Mathf.Min(Segment(point, new Vector2(-0.11f, 0.18f), new Vector2(-0.11f, 0.3f)), Mathf.Min(Segment(point, new Vector2(-0.11f, 0.3f), new Vector2(0.11f, 0.3f)), Segment(point, new Vector2(0.11f, 0.3f), new Vector2(0.11f, 0.18f)))) - 0.034f;
		float num3 = Mathf.Min(Segment(point, new Vector2(-0.17f, -0.32f), new Vector2(-0.17f, 0.18f)), Segment(point, new Vector2(0.17f, -0.32f), new Vector2(0.17f, 0.18f))) - 0.034f;
		return Mathf.Min(num, Mathf.Min(num2, num3));
	}

	private static float Danger(Vector2 point)
	{
		//IL_0000: 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_001a: 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_002a: 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)
		//IL_0058: 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)
		//IL_0072: 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_0092: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: 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_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Abs(Mathf.Min(Circle(point, new Vector2(0f, 0.08f), 0.31f), RoundedBox(point - new Vector2(0f, -0.22f), new Vector2(0.17f, 0.13f), 0.05f))) - 0.034f;
		float num2 = Mathf.Min(Circle(point, new Vector2(-0.12f, 0.03f), 0.07f), Circle(point, new Vector2(0.12f, 0.03f), 0.07f));
		float num3 = Mathf.Min(Segment(point, new Vector2(0f, -0.06f), new Vector2(-0.045f, -0.13f)), Segment(point, new Vector2(0f, -0.06f), new Vector2(0.045f, -0.13f))) - 0.02f;
		float num4 = Mathf.Min(Segment(point, new Vector2(-0.12f, -0.24f), new Vector2(0.12f, -0.24f)), Mathf.Min(Segment(point, new Vector2(-0.06f, -0.24f), new Vector2(-0.06f, -0.33f)), Segment(point, new Vector2(0.06f, -0.24f), new Vector2(0.06f, -0.33f)))) - 0.02f;
		return Mathf.Min(Mathf.Min(num, num2), Mathf.Min(num3, num4));
	}

	private static float Cross(Vector2 point)
	{
		//IL_0000: 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_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: 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)
		return Mathf.Min(Segment(point, new Vector2(-0.3f, -0.3f), new Vector2(0.3f, 0.3f)), Segment(point, new Vector2(-0.3f, 0.3f), new Vector2(0.3f, -0.3f))) - 0.034f;
	}

	private static float Erase(Vector2 point)
	{
		//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_001b: 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_0035: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Abs(Circle(point, Vector2.zero, 0.3f)) - 0.034f;
		float num2 = Segment(point, new Vector2(-0.21f, 0.21f), new Vector2(0.21f, -0.21f)) - 0.034f;
		return Mathf.Min(num, num2);
	}

	private static float Segment(Vector2 point, Vector2 start, Vector2 end)
	{
		//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_0008: 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_000a: 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)
		//IL_0015: 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_0023: 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_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0036: Unknown result type (might be due to invalid IL or missing references)
		Vector2 val = end - start;
		float num = Mathf.Clamp01(Vector2.Dot(point - start, val) / Vector2.Dot(val, val));
		Vector2 val2 = point - start - val * num;
		return ((Vector2)(ref val2)).magnitude;
	}

	private static float Circle(Vector2 point, Vector2 centre, float radius)
	{
		//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)
		Vector2 val = point - centre;
		return ((Vector2)(ref val)).magnitude - radius;
	}

	private static float RoundedBox(Vector2 point, Vector2 halfSize, float radius)
	{
		//IL_0000: 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_0016: 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_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//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_0031: 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_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: 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)
		Vector2 val = new Vector2(Mathf.Abs(point.x), Mathf.Abs(point.y)) - halfSize + Vector2.one * radius;
		Vector2 val2 = new Vector2(Mathf.Max(val.x, 0f), Mathf.Max(val.y, 0f));
		return ((Vector2)(ref val2)).magnitude + Mathf.Min(Mathf.Max(val.x, val.y), 0f) - radius;
	}

	private static float Smooth(float value)
	{
		float num = Mathf.Clamp01(value);
		return num * num * (3f - 2f * num);
	}

	private static float Noise(int x, int y, float scale, int seed)
	{
		float num = (float)x / scale;
		float num2 = (float)y / scale;
		int num3 = Mathf.FloorToInt(num);
		int num4 = Mathf.FloorToInt(num2);
		float num5 = num - (float)num3;
		float num6 = num2 - (float)num4;
		num5 = num5 * num5 * (3f - 2f * num5);
		num6 = num6 * num6 * (3f - 2f * num6);
		float num7 = Mathf.Lerp(Hash(num3, num4, seed), Hash(num3 + 1, num4, seed), num5);
		float num8 = Mathf.Lerp(Hash(num3, num4 + 1, seed), Hash(num3 + 1, num4 + 1, seed), num5);
		return Mathf.Lerp(num7, num8, num6);
	}

	private static float Hash(int x, int y, int seed)
	{
		int num = x * 374761393 + y * 668265263 + seed * -2048144777;
		int num2 = (num ^ (num >>> 13)) * 1274126177;
		return (float)(uint)((num2 ^ (num2 >>> 16)) & 0xFFFFFF) / 16777215f;
	}
}
internal static class MarkKind
{
	internal const int Count = 11;

	internal const int EntryCount = 12;

	internal const int ArrowCount = 8;

	internal const int Luggage = 8;

	internal const int Danger = 9;

	internal const int Cross = 10;

	internal const int Erase = 11;

	private const float ArrowAngle = 45f;

	private static readonly string[] Keys = new string[12]
	{
		"UP", "UP_RIGHT", "RIGHT", "DOWN_RIGHT", "DOWN", "DOWN_LEFT", "LEFT", "UP_LEFT", "LUGGAGE", "DANGER",
		"CROSS", "ERASE"
	};

	private static readonly string[] Names = new string[12]
	{
		"up", "up-right", "right", "down-right", "down", "down-left", "left", "up-left", "luggage", "danger",
		"cross", "erase"
	};

	private static readonly string[] EnglishNames = new string[12]
	{
		"Mark: up", "Mark: up-right", "Mark: right", "Mark: down-right", "Mark: down", "Mark: down-left", "Mark: left", "Mark: up-left", "Mark: luggage", "Mark: danger",
		"Mark: X", "Erase my mark"
	};

	private static readonly string[] Translations = new string[12]
	{
		"印:上", "印:右上", "印:右", "印:右下", "印:下", "印:左下", "印:左", "印:左上", "印:スーツケース", "印:危険",
		"印:×", "自分の印を消す"
	};

	internal static bool IsArrow(int kind)
	{
		if (kind >= 0)
		{
			return kind < 8;
		}
		return false;
	}

	internal static string Key(int kind)
	{
		return "TRAILMARKS_" + Keys[kind];
	}

	internal static string English(int kind)
	{
		return EnglishNames[kind];
	}

	internal static string Japanese(int kind)
	{
		return Translations[kind];
	}

	internal static string LogName(int kind)
	{
		return Names[kind];
	}

	internal static float AngleDegrees(int kind)
	{
		if (!IsArrow(kind))
		{
			return 0f;
		}
		return (float)kind * 45f;
	}
}
internal sealed class MarkNet : MonoBehaviour, IInRoomCallbacks
{
	internal const byte EventCode = 149;

	internal const string PropertyKey = "t0y9n.trailmarks";

	private static bool reportedInvalid;

	private bool wasReady;

	private int readyCount;

	private void OnEnable()
	{
		PhotonNetwork.AddCallbackTarget((object)this);
		PhotonNetwork.NetworkingClient.EventReceived += OnEvent;
		SceneManager.sceneLoaded += OnSceneLoaded;
	}

	private void OnDisable()
	{
		SceneManager.sceneLoaded -= OnSceneLoaded;
		PhotonNetwork.NetworkingClient.EventReceived -= OnEvent;
		PhotonNetwork.RemoveCallbackTarget((object)this);
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		wasReady = false;
	}

	private void Update()
	{
		//IL_0026: 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_004c: Expected O, but got Unknown
		//IL_0053: Expected O, but got Unknown
		bool flag = PhotonNetwork.InRoom && (Object)(object)Character.localCharacter != (Object)null;
		if (flag && !wasReady)
		{
			Player localPlayer = PhotonNetwork.LocalPlayer;
			Hashtable val = new Hashtable();
			((Dictionary<object, object>)val).Add((object)"t0y9n.trailmarks", (object)(++readyCount));
			localPlayer.SetCustomProperties(val, (Hashtable)null, (WebFlags)null);
		}
		wasReady = flag;
	}

	internal static void SendToReady(MarkPacket packet)
	{
		int[] array = ReadyActors();
		if (array != null)
		{
			Send(packet, array);
		}
	}

	internal static void SendEraseToReady(int id)
	{
		int[] array = ReadyActors();
		if (array != null)
		{
			Raise(MarkErase.Encode(id), array);
		}
	}

	private static int[] ReadyActors()
	{
		if (!PhotonNetwork.InRoom || PhotonNetwork.OfflineMode)
		{
			return null;
		}
		List<int> list = new List<int>();
		Player[] playerListOthers = PhotonNetwork.PlayerListOthers;
		foreach (Player val in playerListOthers)
		{
			if (((Dictionary<object, object>)(object)val.CustomProperties).ContainsKey((object)"t0y9n.trailmarks"))
			{
				list.Add(val.ActorNumber);
			}
		}
		if (list.Count == 0)
		{
			return null;
		}
		return list.ToArray();
	}

	private static void Send(MarkPacket packet, int[] actors)
	{
		Raise(packet.Encode(), actors);
	}

	private static void Raise(object content, int[] actors)
	{
		//IL_0006: 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_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Expected O, but got Unknown
		PhotonNetwork.RaiseEvent((byte)149, content, new RaiseEventOptions
		{
			TargetActors = actors,
			CachingOption = (EventCaching)0
		}, SendOptions.SendReliable);
	}

	private static void OnEvent(EventData photonEvent)
	{
		if (photonEvent.Code != 149)
		{
			return;
		}
		try
		{
			MarkPacket packet;
			if (MarkErase.TryDecode(photonEvent.CustomData, out var id))
			{
				if (MarkStore.RemoveRemote(photonEvent.Sender, id))
				{
					Plugin.Log.LogInfo((object)"TrailMarks: another player erased one of their marks.");
				}
			}
			else if (!MarkPacket.TryDecode(photonEvent.CustomData, out packet))
			{
				if (!reportedInvalid)
				{
					reportedInvalid = true;
					Plugin.Log.LogWarning((object)"TrailMarks: ignored an event with the TrailMarks code that is not a TrailMarks mark.");
				}
			}
			else
			{
				MarkStore.AddRemote(photonEvent.Sender, packet);
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("TrailMarks: could not receive a mark. " + ex.Message));
		}
	}

	public void OnPlayerPropertiesUpdate(Player target, Hashtable changed)
	{
		if (target.IsLocal || !((Dictionary<object, object>)(object)changed).ContainsKey((object)"t0y9n.trailmarks") || !PhotonNetwork.InRoom || PhotonNetwork.OfflineMode)
		{
			return;
		}
		foreach (MarkPacket item in MarkStore.LocalMarksOldestFirst())
		{
			Send(item, new int[1] { target.ActorNumber });
		}
	}

	public void OnPlayerLeftRoom(Player other)
	{
		MarkStore.RemoveOwner(other.ActorNumber);
	}

	public void OnPlayerEnteredRoom(Player other)
	{
	}

	public void OnRoomPropertiesUpdate(Hashtable propertiesThatChanged)
	{
	}

	public void OnMasterClientSwitched(Player newMasterClient)
	{
	}
}
internal readonly struct MarkPacket
{
	private const string Tag = "t0y9n.trailmarks/1";

	private const float MinimumLength = 0.5f;

	private const float MaximumLength = 1.5f;

	private const float MinimumProjection = 0.01f;

	internal readonly int Id;

	internal readonly int Kind;

	internal readonly Vector3 Point;

	internal readonly Vector3 Normal;

	internal readonly Vector3 Up;

	internal MarkPacket(int id, int kind, Vector3 point, Vector3 normal, Vector3 up)
	{
		//IL_000f: 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_0016: 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_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		Id = id;
		Kind = kind;
		Point = point;
		Normal = normal;
		Up = up;
	}

	internal object[] Encode()
	{
		return new object[4]
		{
			"t0y9n.trailmarks/1",
			Id,
			Kind,
			new float[9] { Point.x, Point.y, Point.z, Normal.x, Normal.y, Normal.z, Up.x, Up.y, Up.z }
		};
	}

	internal static bool TryDecode(object data, out MarkPacket packet)
	{
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		packet = default(MarkPacket);
		if (!(data is object[] array) || array.Length != 4 || !(array[0] is string text) || text != "t0y9n.trailmarks/1" || !(array[1] is int num) || num < 1 || !(array[2] is int num2) || num2 < 0 || num2 >= 11 || !(array[3] is float[] array2) || array2.Length != 9)
		{
			return false;
		}
		float[] array3 = array2;
		foreach (float f in array3)
		{
			if (float.IsNaN(f) || float.IsInfinity(f))
			{
				return false;
			}
		}
		Vector3 point = default(Vector3);
		((Vector3)(ref point))..ctor(array2[0], array2[1], array2[2]);
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(array2[3], array2[4], array2[5]);
		Vector3 val2 = default(Vector3);
		((Vector3)(ref val2))..ctor(array2[6], array2[7], array2[8]);
		if (((Vector3)(ref val)).magnitude < 0.5f || ((Vector3)(ref val)).magnitude > 1.5f || ((Vector3)(ref val2)).magnitude < 0.5f || ((Vector3)(ref val2)).magnitude > 1.5f)
		{
			return false;
		}
		((Vector3)(ref val)).Normalize();
		val2 = Vector3.ProjectOnPlane(val2, val);
		if (((Vector3)(ref val2)).magnitude < 0.01f)
		{
			return false;
		}
		packet = new MarkPacket(num, num2, point, val, ((Vector3)(ref val2)).normalized);
		return true;
	}
}
internal sealed class MarkStore : MonoBehaviour
{
	private sealed class Entry
	{
		internal MarkPacket Packet;

		internal GameObject Object;

		internal Collider Anchor;

		internal bool Waiting;
	}

	internal const int LocalOwner = -1;

	private const int LimitPerOwner = 10;

	private const float SupportStart = 0.25f;

	private const float SupportDistance = 0.5f;

	private const float RetrySeconds = 1f;

	private static readonly Dictionary<int, List<Entry>> Owners = new Dictionary<int, List<Entry>>();

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

	private static GameObject root;

	private static int nextId;

	private float nextRetry;

	internal static int Count(int owner)
	{
		if (!Owners.TryGetValue(owner, out var value))
		{
			return 0;
		}
		return value.Count;
	}

	internal static bool AddLocal(int kind, Vector3 point, Vector3 normal, Vector3 up, Collider anchor, out MarkPacket packet)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: 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)
		packet = new MarkPacket(++nextId, kind, point, normal, up);
		Append(-1, new Entry
		{
			Packet = packet,
			Object = CreateObject(packet),
			Anchor = anchor
		});
		return true;
	}

	internal static bool AddRemote(int owner, MarkPacket packet)
	{
		if (Owners.TryGetValue(owner, out var value) && value.Exists((Entry entry) => entry.Packet.Id == packet.Id))
		{
			return false;
		}
		if (!TryFindSupport(packet, out var anchor))
		{
			Append(owner, new Entry
			{
				Packet = packet,
				Waiting = true
			});
			Plugin.Log.LogInfo((object)"TrailMarks: a mark from another player waits for its ground on this PC.");
			return false;
		}
		Append(owner, new Entry
		{
			Packet = packet,
			Object = CreateObject(packet),
			Anchor = anchor
		});
		return true;
	}

	private static bool TryFindSupport(MarkPacket packet, out Collider anchor)
	{
		//IL_0004: 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_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		anchor = null;
		RaycastHit val = default(RaycastHit);
		if (!Physics.Raycast(packet.Point + packet.Normal * 0.25f, -packet.Normal, ref val, 0.5f, LayerMask.op_Implicit(HelperFunctions.GetMask((LayerType)1)), (QueryTriggerInteraction)1))
		{
			return false;
		}
		anchor = ((RaycastHit)(ref val)).collider;
		return true;
	}

	private static GameObject CreateObject(MarkPacket packet)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		if ((Object)(object)root == (Object)null)
		{
			root = new GameObject("TrailMarks");
		}
		return MarkSurface.Create(packet, root.transform);
	}

	private static void Append(int owner, Entry entry)
	{
		if (!Owners.TryGetValue(owner, out var value))
		{
			Owners.Add(owner, value = new List<Entry>());
		}
		value.Add(entry);
		if (value.Count > 10)
		{
			if ((Object)(object)value[0].Object != (Object)null)
			{
				Object.Destroy((Object)(object)value[0].Object);
			}
			value.RemoveAt(0);
		}
	}

	internal static bool RemoveLocalNear(Vector3 point, float distance, out int id)
	{
		//IL_0044: 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)
		id = 0;
		if (!Owners.TryGetValue(-1, out var value))
		{
			return false;
		}
		int num = -1;
		float num2 = distance;
		for (int i = 0; i < value.Count; i++)
		{
			Entry entry = value[i];
			if (!entry.Waiting && !((Object)(object)entry.Object == (Object)null))
			{
				float num3 = Vector3.Distance(entry.Packet.Point, point);
				if (num3 <= num2)
				{
					num2 = num3;
					num = i;
				}
			}
		}
		if (num < 0)
		{
			return false;
		}
		id = value[num].Packet.Id;
		Object.Destroy((Object)(object)value[num].Object);
		value.RemoveAt(num);
		return true;
	}

	internal static bool RemoveRemote(int owner, int id)
	{
		if (!Owners.TryGetValue(owner, out var value))
		{
			return false;
		}
		int num = value.FindIndex((Entry entry) => entry.Packet.Id == id);
		if (num < 0)
		{
			return false;
		}
		if ((Object)(object)value[num].Object != (Object)null)
		{
			Object.Destroy((Object)(object)value[num].Object);
		}
		value.RemoveAt(num);
		return true;
	}

	internal static void RemoveOwner(int owner)
	{
		if (!Owners.TryGetValue(owner, out var value))
		{
			return;
		}
		foreach (Entry item in value)
		{
			if ((Object)(object)item.Object != (Object)null)
			{
				Object.Destroy((Object)(object)item.Object);
			}
		}
		Owners.Remove(owner);
	}

	internal static IReadOnlyList<MarkPacket> LocalMarksOldestFirst()
	{
		List<MarkPacket> list = new List<MarkPacket>();
		if (Owners.TryGetValue(-1, out var value))
		{
			foreach (Entry item in value)
			{
				if ((Object)(object)item.Object != (Object)null && (Object)(object)item.Anchor != (Object)null)
				{
					list.Add(item.Packet);
				}
			}
		}
		return list;
	}

	private void OnEnable()
	{
		SceneManager.sceneLoaded += OnSceneLoaded;
	}

	private void OnDisable()
	{
		SceneManager.sceneLoaded -= OnSceneLoaded;
	}

	private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		foreach (List<Entry> value in Owners.Values)
		{
			value.RemoveAll((Entry entry) => entry.Waiting);
		}
	}

	private void LateUpdate()
	{
		try
		{
			bool flag = Time.unscaledTime >= nextRetry;
			if (flag)
			{
				nextRetry = Time.unscaledTime + 1f;
			}
			foreach (List<Entry> value in Owners.Values)
			{
				for (int num = value.Count - 1; num >= 0; num--)
				{
					Entry entry = value[num];
					if (entry.Waiting)
					{
						if (flag && TryFindSupport(entry.Packet, out var anchor))
						{
							entry.Object = CreateObject(entry.Packet);
							entry.Anchor = anchor;
							entry.Waiting = false;
							Plugin.Log.LogInfo((object)"TrailMarks: a mark from another player was placed after its ground appeared.");
						}
					}
					else if ((Object)(object)entry.Object == (Object)null || (Object)(object)entry.Anchor == (Object)null)
					{
						if ((Object)(object)entry.Object != (Object)null)
						{
							Object.Destroy((Object)(object)entry.Object);
						}
						value.RemoveAt(num);
					}
					else if (entry.Object.activeSelf != ((Component)entry.Anchor).gameObject.activeInHierarchy)
					{
						entry.Object.SetActive(((Component)entry.Anchor).gameObject.activeInHierarchy);
					}
				}
			}
		}
		catch (Exception ex)
		{
			if (ReportedErrors.Add(ex.ToString()))
			{
				Plugin.Log.LogError((object)("TrailMarks: could not update marks. " + ex.Message));
			}
		}
	}
}
internal static class MarkSurface
{
	private sealed class MeshOwner : MonoBehaviour
	{
		internal Mesh Mesh;

		private void OnDestroy()
		{
			if ((Object)(object)Mesh != (Object)null)
			{
				Object.Destroy((Object)(object)Mesh);
			}
		}
	}

	private const int Cells = 24;

	private const int Corners = 25;

	private const float Width = 0.75f;

	private const float RayStart = 0.25f;

	private const float RayDistance = 0.5f;

	private const float Offset = 0.02f;

	private const float MaxHeightDifference = 0.12f;

	private static readonly Material[] Materials = (Material[])(object)new Material[11];

	private static Material spriteMaterial;

	private static bool materialChecked;

	internal static GameObject Create(MarkPacket packet, Transform parent)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//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)
		//IL_005a: Expected O, but got Unknown
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: 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_0131: 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_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Expected O, but got Unknown
		//IL_0180: 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_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: 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_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0301: Unknown result type (might be due to invalid IL or missing references)
		//IL_0308: Expected O, but got Unknown
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_021a: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: 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)
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0263: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: 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)
		GameObject val = new GameObject("TrailMark");
		val.transform.SetParent(parent, false);
		val.transform.SetPositionAndRotation(packet.Point, Quaternion.identity);
		if (!materialChecked)
		{
			materialChecked = true;
			GameObject val2 = new GameObject("TrailMarkMaterial");
			spriteMaterial = ((Renderer)val2.AddComponent<SpriteRenderer>()).sharedMaterial;
			Object.Destroy((Object)val2);
			if ((Object)(object)spriteMaterial == (Object)null)
			{
				Plugin.Log.LogError((object)"TrailMarks: no sprite material was found; marks cannot be drawn.");
			}
		}
		if ((Object)(object)spriteMaterial == (Object)null)
		{
			return val;
		}
		if ((Object)(object)Materials[packet.Kind] == (Object)null)
		{
			Materials[packet.Kind] = new Material(spriteMaterial);
			((Object)Materials[packet.Kind]).hideFlags = (HideFlags)61;
			Materials[packet.Kind].mainTexture = (Texture)(object)MarkIcons.Get(packet.Kind).texture;
		}
		List<Vector3> list = new List<Vector3>();
		List<Vector2> list2 = new List<Vector2>();
		List<Color32> list3 = new List<Color32>();
		List<int> list4 = new List<int>();
		int[] array = new int[625];
		float[] array2 = new float[625];
		Collider[] array3 = (Collider[])(object)new Collider[625];
		Vector3 val3 = Vector3.Cross(packet.Normal, packet.Up);
		Vector3 normalized = ((Vector3)(ref val3)).normalized;
		int num = LayerMask.op_Implicit(HelperFunctions.GetMask((LayerType)1));
		RaycastHit val4 = default(RaycastHit);
		for (int i = 0; i < 25; i++)
		{
			for (int j = 0; j < 25; j++)
			{
				int num2 = i * 25 + j;
				array[num2] = -1;
				float num3 = (float)j / 24f;
				float num4 = (float)i / 24f;
				if (Physics.Raycast(packet.Point + normalized * ((num3 - 0.5f) * 0.75f) + packet.Up * ((num4 - 0.5f) * 0.75f) + packet.Normal * 0.25f, -packet.Normal, ref val4, 0.5f, num, (QueryTriggerInteraction)1))
				{
					array[num2] = list.Count;
					list.Add(((RaycastHit)(ref val4)).point + packet.Normal * 0.02f - packet.Point);
					list2.Add(new Vector2(num3, num4));
					list3.Add(new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue));
					array2[num2] = Vector3.Dot(((RaycastHit)(ref val4)).point - packet.Point, packet.Normal);
					array3[num2] = ((RaycastHit)(ref val4)).collider;
				}
			}
		}
		for (int k = 0; k < 24; k++)
		{
			for (int l = 0; l < 24; l++)
			{
				int num5 = k * 25 + l;
				int third = num5 + 1;
				int num6 = num5 + 25;
				int num7 = num6 + 1;
				AddTriangle(num5, num6, num7, array, array2, array3, list4);
				AddTriangle(num5, num7, third, array, array2, array3, list4);
			}
		}
		Mesh val5 = new Mesh();
		val.AddComponent<MeshOwner>().Mesh = val5;
		val5.SetVertices(list);
		val5.SetUVs(0, list2);
		val5.SetColors(list3);
		val5.SetTriangles(list4, 0);
		val5.RecalculateBounds();
		val.AddComponent<MeshFilter>().sharedMesh = val5;
		MeshRenderer obj = val.AddComponent<MeshRenderer>();
		((Renderer)obj).sharedMaterial = Materials[packet.Kind];
		((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)obj).receiveShadows = false;
		if (list4.Count == 0)
		{
			Plugin.Log.LogInfo((object)"TrailMarks: a mark has no surface under it on this PC; nothing is drawn.");
		}
		return val;
	}

	private static void AddTriangle(int first, int second, int third, int[] indices, float[] heights, Collider[] colliders, List<int> triangles)
	{
		if (indices[first] >= 0 && indices[second] >= 0 && indices[third] >= 0 && colliders[first] == colliders[second] && colliders[first] == colliders[third])
		{
			float num = Mathf.Min(heights[first], Mathf.Min(heights[second], heights[third]));
			if (!(Mathf.Max(heights[first], Mathf.Max(heights[second], heights[third])) - num > 0.12f))
			{
				triangles.Add(indices[first]);
				triangles.Add(indices[second]);
				triangles.Add(indices[third]);
			}
		}
	}
}
[BepInPlugin("t0y9n.peak.trailmarks", "TrailMarks", "1.1.0")]
public sealed class Plugin : BaseUnityPlugin
{
	public const string Guid = "t0y9n.peak.trailmarks";

	internal static ManualLogSource Log;

	private void Awake()
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Expected O, but got Unknown
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Invalid comparison between Unknown and I4
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		if (!((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Add the marks pages to the emote wheel and share marks with other players who have this plugin. Read once at start; restart the game after changing it.").Value)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"TrailMarks 1.1.0 loaded. Enabled = false; nothing is patched.");
			return;
		}
		Harmony harmony = new Harmony("t0y9n.peak.trailmarks");
		List<string> list = new List<string>();
		if (Apply(harmony, typeof(WheelPage.ChoosePatch), "wheel choose", list))
		{
			if (Apply(harmony, typeof(WheelPage.PagePatch), "wheel page", list))
			{
				Apply(harmony, typeof(WheelPage.GamepadPatch), "wheel gamepad", list);
			}
		}
		else
		{
			list.Add("wheel page");
			((BaseUnityPlugin)this).Logger.LogWarning((object)"TrailMarks: wheel page was not applied because wheel choose was not applied.");
		}
		GameObject val = ((Component)this).gameObject;
		if ((((Object)val).hideFlags & 0x3D) == 61)
		{
			val = new GameObject("TrailMarks services");
			Object.DontDestroyOnLoad((Object)(object)val);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"TrailMarks: services use a persistent GameObject.");
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"TrailMarks: services use the plugin GameObject.");
		}
		val.AddComponent<MarkStore>();
		val.AddComponent<MarkNet>();
		((BaseUnityPlugin)this).Logger.LogInfo((object)("TrailMarks 1.1.0 loaded. Parts off: " + ((list.Count == 0) ? "none" : string.Join(", ", list))));
	}

	private bool Apply(Harmony harmony, Type patch, string name, List<string> failed)
	{
		try
		{
			harmony.CreateClassProcessor(patch).Patch();
			((BaseUnityPlugin)this).Logger.LogInfo((object)("TrailMarks: patched " + name + "."));
			return true;
		}
		catch (Exception ex)
		{
			failed.Add(name);
			((BaseUnityPlugin)this).Logger.LogError((object)("TrailMarks: " + name + " was not applied. " + ex.Message));
			return false;
		}
	}
}
internal static class Spray
{
	private const float MaximumDistance = 10f;

	private const float MinimumProjection = 0.01f;

	internal static bool TryAim(string what, out RaycastHit hit, out Camera camera)
	{
		//IL_0001: 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_007a: 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)
		hit = default(RaycastHit);
		camera = null;
		if (!Character.localCharacter.data.fullyConscious)
		{
			Plugin.Log.LogInfo((object)("TrailMarks: no mark " + what + " (not fully conscious)."));
			return false;
		}
		camera = Camera.main;
		if ((Object)(object)camera == (Object)null)
		{
			Plugin.Log.LogInfo((object)("TrailMarks: no mark " + what + " (no camera)."));
			return false;
		}
		if (!Physics.Raycast(camera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f)), ref hit, 10f, LayerMask.op_Implicit(HelperFunctions.GetMask((LayerType)1)), (QueryTriggerInteraction)1))
		{
			Plugin.Log.LogInfo((object)("TrailMarks: no mark " + what + " (no ground or rock within 10 m at the centre of the screen)."));
			return false;
		}
		return true;
	}

	internal static void Place(int kind)
	{
		//IL_0013: 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_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: 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_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: 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_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: 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_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_00b3: 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)
		if (!TryAim("placed", out var hit, out var camera))
		{
			return;
		}
		Vector3 normal = ((RaycastHit)(ref hit)).normal;
		Vector3 normalized = ((Vector3)(ref normal)).normalized;
		Vector3 val = Vector3.Cross(((Component)camera).transform.right, normalized);
		if (((Vector3)(ref val)).magnitude < 0.01f)
		{
			val = Vector3.ProjectOnPlane(((Component)camera).transform.up, normalized);
			if (((Vector3)(ref val)).magnitude < 0.01f)
			{
				val = Vector3.ProjectOnPlane(((Component)camera).transform.forward, normalized);
			}
		}
		else
		{
			float num = Vector3.Dot(val, ((Component)camera).transform.up);
			if (Mathf.Abs(num) < 0.01f)
			{
				num = Vector3.Dot(val, ((Component)camera).transform.forward);
			}
			if (num < 0f)
			{
				val = -val;
			}
		}
		if (MarkStore.AddLocal(kind, ((RaycastHit)(ref hit)).point, normalized, ((Vector3)(ref val)).normalized, ((RaycastHit)(ref hit)).collider, out var packet))
		{
			MarkNet.SendToReady(packet);
			Plugin.Log.LogInfo((object)("TrailMarks: placed a mark (" + MarkKind.LogName(kind) + ")."));
		}
	}
}
internal static class WheelPage
{
	[HarmonyPatch(typeof(EmoteWheel), "OnEnable")]
	internal static class PagePatch
	{
		private static void Prefix(EmoteWheel __instance)
		{
			EmoteWheelData[] data = __instance.data;
			int pages = __instance.pages;
			try
			{
				AddPages(__instance);
			}
			catch (Exception ex)
			{
				__instance.data = data;
				__instance.pages = pages;
				Plugin.Log.LogError((object)("TrailMarks: could not add the marks pages. " + ex.Message));
			}
		}
	}

	[HarmonyPatch(typeof(EmoteWheel), "Choose")]
	internal static class ChoosePatch
	{
		private static bool Prefix(EmoteWheel __instance)
		{
			bool flag = false;
			try
			{
				flag = IsMarkData(Chosen.Invoke(__instance), out var kind);
				if (!flag)
				{
					return true;
				}
				if ((Object)(object)Character.localCharacter == (Object)null)
				{
					return false;
				}
				if (kind == 11)
				{
					Eraser.EraseAimed();
				}
				else
				{
					Spray.Place(kind);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("TrailMarks: could not choose an emote or mark. " + ex.Message));
			}
			return !flag;
		}
	}

	[HarmonyPatch(typeof(EmoteWheel), "TestSelectSliceGamepad")]
	internal static class GamepadPatch
	{
		private static bool reported;

		private static void Postfix(EmoteWheel __instance)
		{
			try
			{
				EmoteWheelData val = Chosen.Invoke(__instance);
				if (!IsMarkData(val, out var _) || (Object)(object)EventSystem.current == (Object)null)
				{
					return;
				}
				GameObject currentSelectedGameObject = EventSystem.current.currentSelectedGameObject;
				if ((Object)(object)currentSelectedGameObject == (Object)null)
				{
					return;
				}
				EmoteWheelSlice[] slices = __instance.slices;
				foreach (EmoteWheelSlice val2 in slices)
				{
					if ((Object)(object)val2 != (Object)null && (Object)(object)((UIWheelSlice)val2).button != (Object)null && (Object)(object)((Component)((UIWheelSlice)val2).button).gameObject == (Object)(object)currentSelectedGameObject)
					{
						if (!((Selectable)((UIWheelSlice)val2).button).interactable)
						{
							__instance.Dehover(val);
						}
						break;
					}
				}
			}
			catch (Exception ex)
			{
				if (!reported)
				{
					reported = true;
					Plugin.Log.LogError((object)("TrailMarks: could not clear a mark when the gamepad moved to an empty slice. " + ex.Message));
				}
			}
		}
	}

	private const int SliceCount = 8;

	private const int DangerDirection = 0;

	private const int CrossDirection = 2;

	private const int LuggageDirection = 4;

	private const int EraseDirection = 6;

	private static readonly EmoteWheelData[] Marks = (EmoteWheelData[])(object)new EmoteWheelData[12];

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

	private static readonly FieldRef<EmoteWheel, EmoteWheelData> Chosen = AccessTools.FieldRefAccess<EmoteWheel, EmoteWheelData>("chosenEmoteData");

	internal static bool IsMarkData(EmoteWheelData data, out int kind)
	{
		for (int i = 0; i < Marks.Length; i++)
		{
			if ((Object)(object)data != (Object)null && (Object)(object)data == (Object)(object)Marks[i])
			{
				kind = i;
				return true;
			}
		}
		kind = -1;
		return false;
	}

	private static EmoteWheelData Data(int kind)
	{
		if ((Object)(object)Marks[kind] == (Object)null)
		{
			EmoteWheelData val = ScriptableObject.CreateInstance<EmoteWheelData>();
			val.emoteName = MarkKind.Key(kind);
			val.emoteSprite = MarkIcons.Get(kind);
			val.anim = "";
			val.requireGrounded = false;
			((Object)val).hideFlags = (HideFlags)61;
			Marks[kind] = val;
		}
		return Marks[kind];
	}

	private static EmoteWheelData Symbol(int direction)
	{
		return (EmoteWheelData)(direction switch
		{
			0 => Data(9), 
			4 => Data(8), 
			2 => Data(10), 
			6 => Data(11), 
			_ => null, 
		});
	}

	private static void EnsureNames()
	{
		Dictionary<string, List<string>> mainTable = LocalizedText.mainTable;
		int length = Enum.GetValues(typeof(Language)).Length;
		for (int i = 0; i < 12; i++)
		{
			string key = MarkKind.Key(i);
			if (!mainTable.ContainsKey(key))
			{
				List<string> list = new List<string>(length);
				for (int j = 0; j < length; j++)
				{
					list.Add(MarkKind.English(i));
				}
				list[11] = MarkKind.Japanese(i);
				mainTable.Add(key, list);
			}
		}
	}

	private static void AddPages(EmoteWheel wheel)
	{
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		if (wheel.slices == null || wheel.slices.Length != 8 || wheel.data == null)
		{
			if (Warned.Add(((Object)wheel).GetInstanceID()))
			{
				Plugin.Log.LogWarning((object)$"TrailMarks: the emote wheel has {((wheel.slices != null) ? wheel.slices.Length : 0)} slices, not 8; the marks pages were not added.");
			}
			return;
		}
		EmoteWheelData[] data = wheel.data;
		for (int i = 0; i < data.Length; i++)
		{
			if (IsMarkData(data[i], out var _))
			{
				EnsureNames();
				return;
			}
		}
		int[] array = new int[8];
		bool[] array2 = new bool[8];
		for (int j = 0; j < 8; j++)
		{
			Vector3 upVector = ((UIWheelSlice)wheel.slices[j]).GetUpVector();
			int num = Mathf.RoundToInt(Mathf.Repeat(Mathf.Atan2(upVector.x, upVector.y) * 57.29578f, 360f) / 45f) % 8;
			if (array2[num])
			{
				if (Warned.Add(((Object)wheel).GetInstanceID()))
				{
					Plugin.Log.LogWarning((object)"TrailMarks: the emote wheel slices do not cover eight directions; the marks pages were not added.");
				}
				return;
			}
			array[j] = num;
			array2[num] = true;
		}
		int pages = wheel.pages;
		EmoteWheelData[] array3 = (EmoteWheelData[])(object)new EmoteWheelData[(pages + 2) * 8];
		Array.Copy(wheel.data, array3, Math.Min(wheel.data.Length, pages * 8));
		for (int k = 0; k < 8; k++)
		{
			array3[pages * 8 + k] = Data(array[k]);
			array3[(pages + 1) * 8 + k] = Symbol(array[k]);
		}
		EnsureNames();
		wheel.data = array3;
		wheel.pages = pages + 2;
		Plugin.Log.LogInfo((object)$"TrailMarks: added the marks pages to the emote wheel (pages {pages + 1} and {pages + 2} of {pages + 2}).");
	}
}