Decompiled source of TargetDummy v1.0.1

TargetDummy.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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 ExitGames.Client.Photon;
using HarmonyLib;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnityEngine;
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 = "")]
[assembly: AssemblyCompany("TargetDummy")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TargetDummy")]
[assembly: AssemblyTitle("TargetDummy")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace TargetDummy;

public static class AllyApi
{
	public static bool Exists => (Object)(object)Dummy.Ally != (Object)null;

	public static Transform Chest
	{
		get
		{
			if (!((Object)(object)Dummy.Ally != (Object)null))
			{
				return null;
			}
			return Dummy.Ally.Chest;
		}
	}

	public static Transform Root
	{
		get
		{
			if (!((Object)(object)Dummy.Ally != (Object)null))
			{
				return null;
			}
			return ((Component)Dummy.Ally).transform;
		}
	}

	public static int Health
	{
		get
		{
			if (!((Object)(object)Dummy.Ally != (Object)null))
			{
				return 0;
			}
			return Dummy.Ally.Health;
		}
	}

	public static int MaxHealth
	{
		get
		{
			if (!((Object)(object)Dummy.Ally != (Object)null))
			{
				return 0;
			}
			return Dummy.Ally.MaxHealth;
		}
	}

	public static bool IsFullHealth
	{
		get
		{
			if ((Object)(object)Dummy.Ally != (Object)null)
			{
				return Dummy.Ally.Health >= Dummy.Ally.MaxHealth;
			}
			return false;
		}
	}

	public static bool IsAllyCollider(Collider c)
	{
		if ((Object)(object)Dummy.Ally != (Object)null && (Object)(object)c != (Object)null)
		{
			return ((Component)c).transform.IsChildOf(((Component)Dummy.Ally).transform);
		}
		return false;
	}

	public static void Heal(int amount, Vector3 from)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)Dummy.Ally != (Object)null)
		{
			Dummy.Ally.HostHeal(amount, from);
		}
	}

	public static void Hurt(int damage, Vector3 direction)
	{
		//IL_001f: 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_0031: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)Dummy.Ally != (Object)null)
		{
			Dummy.Ally.TargetDummyHit(new float[4] { damage, direction.x, direction.y, direction.z });
		}
	}
}
internal class BorrowedModel
{
	internal static readonly BorrowedModel Robe = new BorrowedModel("Robe", new string[1] { "Enemies/Enemy - Robe" }, () => Settings.HideRobeParts.Value, readRobeStats: true);

	internal static readonly BorrowedModel Droid = new BorrowedModel("Droid", new string[3] { "PlayerAvatar Dummy", "PlayerAvatarMenu", "PlayerAvatar" }, () => Settings.HideDroidParts.Value, readRobeStats: false);

	private static GameObject holder;

	private readonly string label;

	private readonly string[] paths;

	private readonly Func<string> hideSetting;

	private readonly bool readRobeStats;

	private GameObject template;

	private bool tried;

	private static readonly string[] EffectWords = new string[15]
	{
		"particle", "effect", "fx", "death", "hurt", "attack", "debug", "gizmo", "flash", "spawn",
		"despawn", "trail", "beam", "smoke", "hit"
	};

	internal static float RobeDamageResistance { get; private set; }

	internal static float RobeObjectHurtMultiplier { get; private set; } = 1f;

	internal static bool RobeObjectHurt { get; private set; } = true;

	private BorrowedModel(string label, string[] paths, Func<string> hideSetting, bool readRobeStats)
	{
		this.label = label;
		this.paths = paths;
		this.hideSetting = hideSetting;
		this.readRobeStats = readRobeStats;
	}

	internal GameObject Spawn(Transform parent)
	{
		if (!tried)
		{
			tried = true;
			try
			{
				template = Build();
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Building the {label} for the dummy failed: {arg}");
			}
		}
		if ((Object)(object)template == (Object)null)
		{
			return null;
		}
		GameObject obj = Object.Instantiate<GameObject>(template, parent, false);
		((Object)obj).name = label;
		return obj;
	}

	private GameObject Build()
	{
		//IL_00e4: 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_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Expected O, but got Unknown
		GameObject val = null;
		string path = null;
		string[] array = paths;
		foreach (string text in array)
		{
			val = Resources.Load<GameObject>(text);
			if ((Object)(object)val != (Object)null)
			{
				path = text;
				break;
			}
		}
		if ((Object)(object)val == (Object)null)
		{
			Plugin.Log.LogError((object)("No " + label + " model found (" + string.Join(", ", paths) + "); the dummy will be just the stand."));
			return null;
		}
		if ((Object)(object)holder == (Object)null)
		{
			holder = new GameObject("TargetDummy.PrefabHolder");
			holder.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)holder);
			((Object)holder).hideFlags = (HideFlags)61;
		}
		GameObject val2 = Object.Instantiate<GameObject>(val, holder.transform);
		val2.transform.localPosition = Vector3.zero;
		val2.transform.localRotation = Quaternion.identity;
		val2.transform.localScale = Vector3.one;
		if (readRobeStats)
		{
			ReadRobeStats(val2);
		}
		string[] hide = SplitList(hideSetting());
		Renderer[] componentsInChildren = val2.GetComponentsInChildren<Renderer>(true);
		List<Renderer> list = new List<Renderer>();
		Renderer[] array2 = componentsInChildren;
		foreach (Renderer val3 in array2)
		{
			if (Usable(val3, val2.transform, hide) && val3.enabled && ActiveUnder(((Component)val3).transform, val2.transform))
			{
				list.Add(val3);
			}
		}
		if (list.Count == 0)
		{
			array2 = componentsInChildren;
			foreach (Renderer val4 in array2)
			{
				if (Usable(val4, val2.transform, hide) && !LooksLikeEffect(((Component)val4).transform, val2.transform))
				{
					list.Add(val4);
				}
			}
		}
		if (Settings.LogRobeParts.Value)
		{
			LogParts(path, componentsInChildren, list, val2.transform);
		}
		if (list.Count == 0)
		{
			Plugin.Log.LogError((object)("The " + label + " has no visible meshes; the dummy will be just the stand."));
			Object.Destroy((Object)(object)val2);
			return null;
		}
		GameObject obj = MirrorVisuals(val2, list);
		((Object)obj).name = "TargetDummy " + label;
		Object.Destroy((Object)(object)val2);
		return obj;
	}

	private static void ReadRobeStats(GameObject clone)
	{
		EnemyHealth componentInChildren = clone.GetComponentInChildren<EnemyHealth>(true);
		if ((Object)(object)componentInChildren == (Object)null)
		{
			Plugin.Log.LogWarning((object)"The Robe has no EnemyHealth; numbers use raw damage.");
			return;
		}
		RobeObjectHurt = componentInChildren.objectHurt;
		RobeObjectHurtMultiplier = componentInChildren.objectHurtMultiplier;
		FieldInfo fieldInfo = AccessTools.Field(typeof(EnemyHealth), "damageResistance");
		if (fieldInfo != null)
		{
			RobeDamageResistance = (float)fieldInfo.GetValue(componentInChildren);
		}
		Plugin.Log.LogInfo((object)$"Robe: {componentInChildren.health} hp, damage resistance {RobeDamageResistance:0.##}, thrown-object multiplier {RobeObjectHurtMultiplier:0.##}.");
	}

	private static bool Usable(Renderer r, Transform root, string[] hide)
	{
		if (!(r is SkinnedMeshRenderer) && !(r is MeshRenderer))
		{
			return false;
		}
		string text = LayerMask.LayerToName(((Component)r).gameObject.layer).ToLowerInvariant();
		if (text.Contains("map") || text.Contains("ui"))
		{
			return false;
		}
		if (Matches(r, hide))
		{
			return false;
		}
		Transform val = ((Component)r).transform;
		while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)root)
		{
			string text2 = ((Object)val).name.ToLowerInvariant();
			if (text2.Contains("map") || text2.Contains("icon") || text2.Contains("flashlight"))
			{
				return false;
			}
			val = val.parent;
		}
		return true;
	}

	private static bool ActiveUnder(Transform t, Transform root)
	{
		while ((Object)(object)t != (Object)null && (Object)(object)t != (Object)(object)root)
		{
			if (!((Component)t).gameObject.activeSelf)
			{
				return false;
			}
			t = t.parent;
		}
		return true;
	}

	private static bool LooksLikeEffect(Transform t, Transform root)
	{
		while ((Object)(object)t != (Object)null && (Object)(object)t != (Object)(object)root)
		{
			string text = ((Object)t).name.ToLowerInvariant();
			string[] effectWords = EffectWords;
			foreach (string value in effectWords)
			{
				if (text.Contains(value))
				{
					return true;
				}
			}
			t = t.parent;
		}
		return false;
	}

	private static string[] SplitList(string s)
	{
		List<string> list = new List<string>();
		string[] array = (s ?? "").Split(',');
		for (int i = 0; i < array.Length; i++)
		{
			string text = array[i].Trim().ToLowerInvariant();
			if (text.Length > 0)
			{
				list.Add(text);
			}
		}
		return list.ToArray();
	}

	private static bool Matches(Renderer r, string[] words)
	{
		if (words.Length == 0)
		{
			return false;
		}
		string text = ((Object)r).name.ToLowerInvariant();
		foreach (string value in words)
		{
			if (text.Contains(value))
			{
				return true;
			}
		}
		return false;
	}

	private static GameObject MirrorVisuals(GameObject source, List<Renderer> keep)
	{
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		Dictionary<Transform, Transform> dictionary = new Dictionary<Transform, Transform>();
		GameObject val = MirrorTree(source.transform, holder.transform, dictionary);
		foreach (Renderer item in keep)
		{
			if (!dictionary.TryGetValue(((Component)item).transform, out var value))
			{
				continue;
			}
			SkinnedMeshRenderer val2 = (SkinnedMeshRenderer)(object)((item is SkinnedMeshRenderer) ? item : null);
			if (val2 != null)
			{
				SkinnedMeshRenderer val3 = ((Component)value).gameObject.AddComponent<SkinnedMeshRenderer>();
				val3.sharedMesh = val2.sharedMesh;
				Transform[] bones = val2.bones;
				Transform[] array = (Transform[])(object)new Transform[bones.Length];
				for (int i = 0; i < bones.Length; i++)
				{
					array[i] = (((Object)(object)bones[i] != (Object)null && dictionary.TryGetValue(bones[i], out var value2)) ? value2 : null);
				}
				val3.bones = array;
				val3.rootBone = (((Object)(object)val2.rootBone != (Object)null && dictionary.TryGetValue(val2.rootBone, out var value3)) ? value3 : null);
				((Renderer)val3).localBounds = ((Renderer)val2).localBounds;
				val3.quality = val2.quality;
				val3.updateWhenOffscreen = false;
				((Renderer)val3).sharedMaterials = ((Renderer)val2).sharedMaterials;
				if ((Object)(object)val2.sharedMesh != (Object)null)
				{
					for (int j = 0; j < val2.sharedMesh.blendShapeCount; j++)
					{
						val3.SetBlendShapeWeight(j, val2.GetBlendShapeWeight(j));
					}
				}
			}
			else
			{
				MeshFilter component = ((Component)item).GetComponent<MeshFilter>();
				if ((Object)(object)component == (Object)null || (Object)(object)component.sharedMesh == (Object)null)
				{
					continue;
				}
				((Component)value).gameObject.AddComponent<MeshFilter>().sharedMesh = component.sharedMesh;
				((Renderer)((Component)value).gameObject.AddComponent<MeshRenderer>()).sharedMaterials = item.sharedMaterials;
			}
			Transform val4 = value;
			while ((Object)(object)val4 != (Object)null && (Object)(object)val4 != (Object)(object)val.transform)
			{
				((Component)val4).gameObject.SetActive(true);
				val4 = val4.parent;
			}
		}
		val.SetActive(true);
		SetLayer(val.transform, 0);
		return val;
	}

	private static GameObject MirrorTree(Transform src, Transform parent, Dictionary<Transform, Transform> map)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_0020: 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_0042: 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_0079: Expected O, but got Unknown
		GameObject val = new GameObject(((Object)src).name);
		val.transform.SetParent(parent, false);
		val.transform.localPosition = src.localPosition;
		val.transform.localRotation = src.localRotation;
		val.transform.localScale = src.localScale;
		map[src] = val.transform;
		foreach (Transform item in src)
		{
			MirrorTree(item, val.transform, map);
		}
		val.SetActive(((Component)src).gameObject.activeSelf);
		return val;
	}

	private static void SetLayer(Transform t, int layer)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Expected O, but got Unknown
		((Component)t).gameObject.layer = layer;
		foreach (Transform item in t)
		{
			SetLayer(item, layer);
		}
	}

	private void LogParts(string path, Renderer[] all, List<Renderer> keep, Transform root)
	{
		string text = ((label == "Robe") ? "HideRobeParts" : "HideDroidParts");
		StringBuilder stringBuilder = new StringBuilder(label + " pieces from '" + path + "' (+ = shown on the dummy). Hide any with " + text + " in TargetDummy.cfg:");
		foreach (Renderer val in all)
		{
			stringBuilder.Append("\n  ").Append(keep.Contains(val) ? "+ " : "- ").Append(Path(((Component)val).transform, root))
				.Append(" [")
				.Append(((object)val).GetType().Name)
				.Append(", layer ")
				.Append(LayerMask.LayerToName(((Component)val).gameObject.layer))
				.Append(']');
		}
		Plugin.Log.LogInfo((object)stringBuilder.ToString());
	}

	private static string Path(Transform t, Transform root)
	{
		string text = ((Object)t).name;
		t = t.parent;
		while ((Object)(object)t != (Object)null && (Object)(object)t != (Object)(object)root)
		{
			text = ((Object)t).name + "/" + text;
			t = t.parent;
		}
		return text;
	}
}
internal class DamagePopup : MonoBehaviour
{
	internal class Label : MonoBehaviour
	{
		internal TextMeshPro Text;

		internal Vector3 Home;

		private float alpha;

		private float target;

		internal void Set(string content, Color c)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			((TMP_Text)Text).text = content;
			((Graphic)Text).color = c;
			alpha = (target = 1f);
			((Component)this).gameObject.SetActive(true);
		}

		internal void Fade()
		{
			target = 0f;
		}

		private void Update()
		{
			//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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: 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_00bc: 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)
			alpha = Mathf.MoveTowards(alpha, target, Time.deltaTime * 1.5f);
			Color color = ((Graphic)Text).color;
			color.a = alpha;
			((Graphic)Text).color = color;
			Vector3 val = (((Object)(object)((Component)this).transform.parent != (Object)null) ? ((Component)this).transform.parent.TransformPoint(Home) : ((Component)this).transform.position);
			((Component)this).transform.position = Unblocked(val, out var shrink);
			Camera val2 = ViewCamera();
			if ((Object)(object)val2 != (Object)null)
			{
				((Component)this).transform.rotation = Quaternion.LookRotation(((Component)this).transform.position - ((Component)val2).transform.position);
			}
			((Component)this).transform.localScale = Vector3.one * DistanceScale(val) * shrink;
			if (alpha <= 0f && target <= 0f)
			{
				((Component)this).gameObject.SetActive(false);
			}
		}
	}

	private static TMP_FontAsset font;

	private static bool fontSearched;

	private TextMeshPro text;

	private float age;

	private float life;

	private Vector3 start;

	private Vector3 drift;

	private Color color;

	private static Camera cachedCamera;

	private static Shader overlayShader;

	private static bool overlaySearched;

	private static Shader OverlayShader
	{
		get
		{
			if (!overlaySearched)
			{
				overlaySearched = true;
				overlayShader = Shader.Find("TextMeshPro/Distance Field Overlay");
			}
			return overlayShader;
		}
	}

	internal static void SpawnHit(HitInfo hit)
	{
		//IL_01fa: 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_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0376: Unknown result type (might be due to invalid IL or missing references)
		//IL_037b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0385: Unknown result type (might be due to invalid IL or missing references)
		//IL_038a: Unknown result type (might be due to invalid IL or missing references)
		//IL_038f: 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_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_039b: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a9: 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_03b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03be: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
		List<string> list = new List<string>();
		bool flag = hit.Dummy == DummyKind.Ally;
		string value;
		Color c = default(Color);
		if (hit.Type == HitInfo.Kind.Heal)
		{
			value = "+" + (flag ? hit.Effective : hit.Damage).ToString("N0");
			((Color)(ref c))..ctor(0.45f, 1f, 0.3f);
			if (flag && hit.Effective < hit.Damage)
			{
				list.Add((hit.Effective == 0) ? $"Full health ({hit.Damage:N0} wasted)" : $"Full health (of {hit.Damage:N0})");
			}
		}
		else if (flag)
		{
			value = (hit.Kill ? "KILL" : ("-" + hit.Damage.ToString("N0")));
			c = ((hit.Damage <= 0 && !hit.Kill) ? new Color(0.75f, 0.75f, 0.75f) : new Color(1f, 0.38f, 0.3f));
			if (hit.WouldDie)
			{
				list.Add("<color=#ff4040>Would have downed a player</color>");
			}
		}
		else if (hit.Kill)
		{
			value = "KILL";
			((Color)(ref c))..ctor(1f, 0.2f, 0.45f);
		}
		else
		{
			value = hit.Damage.ToString("N0");
			c = (Color)((hit.Damage <= 0) ? new Color(0.75f, 0.75f, 0.75f) : ((hit.Damage < 50) ? Color.white : ((hit.Damage < 150) ? new Color(1f, 0.9f, 0.3f) : ((hit.Damage < 400) ? new Color(1f, 0.55f, 0.15f) : new Color(1f, 0.22f, 0.18f)))));
		}
		StringBuilder stringBuilder = new StringBuilder(value);
		if (Settings.ShowForce.Value)
		{
			if (hit.Type == HitInfo.Kind.Impact)
			{
				list.Add($"Impact {hit.ImpactForce:0}");
				list.Add($"{hit.Speed:0.0} m/s");
			}
			if (hit.Type == HitInfo.Kind.Push)
			{
				list.Add("Push");
			}
			if (hit.Knockback > 0f)
			{
				list.Add($"Knockback {hit.Knockback:0.#}");
			}
			if (hit.Torque > 0f)
			{
				list.Add(flag ? $"Tumble force {hit.Torque:0.#}" : $"Torque {hit.Torque:0.#}");
			}
			if (hit.Stun > 0f)
			{
				list.Add($"Stun {hit.Stun:0.#}s");
			}
			if (hit.Freeze > 0f)
			{
				list.Add(flag ? $"Tumble {hit.Freeze:0.#}s" : $"Freeze {hit.Freeze:0.#}s");
			}
		}
		if (list.Count > 0)
		{
			stringBuilder.Append("\n<size=45%><color=#9fd8ff>").Append(string.Join("   ", list)).Append("</color></size>");
		}
		Camera val = ViewCamera();
		Vector3 val2 = hit.Point + Vector3.up * 0.15f;
		if ((Object)(object)val != (Object)null)
		{
			Vector3 val3 = val2;
			Vector3 val4 = ((Component)val).transform.position - val2;
			val2 = val3 + ((Vector3)(ref val4)).normalized * 0.35f;
		}
		float scale = Mathf.Lerp(0.85f, 1.35f, Mathf.InverseLerp(0f, 400f, (float)Mathf.Abs(hit.Damage)));
		Spawn(stringBuilder.ToString(), c, val2, scale, Settings.NumberLifetime.Value);
	}

	private static void Spawn(string content, Color c, Vector3 position, float scale, float lifetime)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0011: 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_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)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("Target Dummy Number");
		val.transform.position = position;
		DamagePopup damagePopup = val.AddComponent<DamagePopup>();
		damagePopup.text = MakeText(val, 3.2f * scale * Settings.NumberSize.Value);
		((TMP_Text)damagePopup.text).text = content;
		damagePopup.color = c;
		((Graphic)damagePopup.text).color = c;
		damagePopup.life = lifetime;
		damagePopup.start = position;
		damagePopup.drift = new Vector3(Random.Range(-0.25f, 0.25f), 0f, Random.Range(-0.25f, 0.25f));
		damagePopup.Face();
	}

	private void Update()
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: 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_00a7: 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_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_00c8: 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_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_0110: Unknown result type (might be due to invalid IL or missing references)
		age += Time.deltaTime;
		float num = age / life;
		if (num >= 1f)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
			return;
		}
		float num2 = 1f - (1f - num) * (1f - num);
		Vector3 val = start + Vector3.up * (0.9f * num2) + drift * num2;
		float num3 = ((num < 0.12f) ? Mathf.Lerp(1.6f, 1f, num / 0.12f) : 1f);
		((Component)this).transform.position = Unblocked(val, out var shrink);
		((Component)this).transform.localScale = Vector3.one * num3 * DistanceScale(val) * shrink;
		Color val2 = color;
		val2.a = ((num < 0.65f) ? 1f : (1f - (num - 0.65f) / 0.35f));
		((Graphic)text).color = val2;
		Face();
	}

	private void Face()
	{
		//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_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		Camera val = ViewCamera();
		if ((Object)(object)val != (Object)null)
		{
			((Component)this).transform.rotation = Quaternion.LookRotation(((Component)this).transform.position - ((Component)val).transform.position);
		}
	}

	internal static Vector3 Unblocked(Vector3 wanted, out float shrink)
	{
		//IL_0022: 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_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0037: 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_004b: 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_0048: 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_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		shrink = 1f;
		Camera val = ViewCamera();
		if ((Object)(object)val == (Object)null || !Settings.NumbersThroughWalls.Value)
		{
			return wanted;
		}
		Vector3 position = ((Component)val).transform.position;
		Vector3 val2 = wanted - position;
		float magnitude = ((Vector3)(ref val2)).magnitude;
		if (magnitude < 0.05f)
		{
			return wanted;
		}
		RaycastHit val3 = default(RaycastHit);
		if (!Physics.Raycast(position, val2 / magnitude, ref val3, magnitude, -5, (QueryTriggerInteraction)1))
		{
			return wanted;
		}
		float num = Mathf.Max(0.3f, ((RaycastHit)(ref val3)).distance - 0.15f);
		if (num >= magnitude)
		{
			return wanted;
		}
		shrink = num / magnitude;
		return position + val2 / magnitude * num;
	}

	private static float DistanceScale(Vector3 p)
	{
		//IL_001b: 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)
		Camera val = ViewCamera();
		if ((Object)(object)val == (Object)null)
		{
			return 1f;
		}
		return Mathf.Clamp(Vector3.Distance(((Component)val).transform.position, p) / 5f, 1f, 2.5f);
	}

	private static Camera ViewCamera()
	{
		if ((Object)(object)cachedCamera != (Object)null && ((Behaviour)cachedCamera).isActiveAndEnabled)
		{
			return cachedCamera;
		}
		cachedCamera = Camera.main;
		if ((Object)(object)cachedCamera == (Object)null)
		{
			cachedCamera = Object.FindAnyObjectByType<Camera>();
		}
		return cachedCamera;
	}

	internal static TextMeshPro MakeText(GameObject go, float size)
	{
		//IL_0058: 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)
		TextMeshPro val = go.AddComponent<TextMeshPro>();
		TMP_FontAsset val2 = GameFont();
		if ((Object)(object)val2 != (Object)null)
		{
			((TMP_Text)val).font = val2;
		}
		((TMP_Text)val).fontSize = size;
		((TMP_Text)val).alignment = (TextAlignmentOptions)514;
		((TMP_Text)val).textWrappingMode = (TextWrappingModes)0;
		((TMP_Text)val).richText = true;
		((TMP_Text)val).fontStyle = (FontStyles)1;
		((TMP_Text)val).outlineWidth = 0.18f;
		((TMP_Text)val).outlineColor = new Color32((byte)0, (byte)0, (byte)0, (byte)220);
		((TMP_Text)val).rectTransform.sizeDelta = new Vector2(8f, 2f);
		if (Settings.NumbersThroughWalls.Value)
		{
			Material fontMaterial = ((TMP_Text)val).fontMaterial;
			if ((Object)(object)fontMaterial != (Object)null)
			{
				if ((Object)(object)OverlayShader != (Object)null)
				{
					fontMaterial.shader = OverlayShader;
				}
				if (fontMaterial.HasProperty("unity_GUIZTestMode"))
				{
					fontMaterial.SetFloat("unity_GUIZTestMode", 8f);
				}
				fontMaterial.renderQueue = 4000;
			}
			val.renderer.sortingOrder = 100;
		}
		return val;
	}

	private static TMP_FontAsset GameFont()
	{
		if ((Object)(object)font != (Object)null || fontSearched)
		{
			return font;
		}
		fontSearched = true;
		CosmeticShopMachine instance = CosmeticShopMachine.instance;
		if ((Object)(object)instance != (Object)null && instance.screenCosmeticTexts != null)
		{
			foreach (TextMeshPro screenCosmeticText in instance.screenCosmeticTexts)
			{
				if ((Object)(object)screenCosmeticText != (Object)null && (Object)(object)((TMP_Text)screenCosmeticText).font != (Object)null)
				{
					font = ((TMP_Text)screenCosmeticText).font;
					break;
				}
			}
		}
		if ((Object)(object)font == (Object)null)
		{
			TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
			int num = 0;
			if (num < array.Length)
			{
				font = array[num];
			}
		}
		if ((Object)(object)font == (Object)null)
		{
			Plugin.Log.LogWarning((object)"No TextMeshPro font found; numbers use TextMeshPro's default.");
		}
		return font;
	}

	internal static Label Persistent(Transform parent, Vector3 localPosition)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("Target Dummy Total");
		val.transform.SetParent(parent, false);
		val.transform.localPosition = localPosition;
		Label label = val.AddComponent<Label>();
		label.Home = localPosition;
		label.Text = MakeText(val, 2.4f * Settings.NumberSize.Value);
		((TMP_Text)label.Text).text = "";
		val.SetActive(false);
		return label;
	}
}
internal enum DummyKind : byte
{
	Target,
	Ally
}
internal struct HitInfo
{
	internal enum Kind : byte
	{
		Hurt,
		Push,
		Impact,
		Direct,
		Heal,
		State
	}

	public DummyKind Dummy;

	public Kind Type;

	public Vector3 Point;

	public Vector3 Direction;

	public int Damage;

	public bool Kill;

	public float Knockback;

	public float Torque;

	public float Stun;

	public float Freeze;

	public float ImpactForce;

	public float Speed;

	public int Health;

	public int MaxHealth;

	public int Effective;

	public bool WouldDie;
}
internal class Dummy : MonoBehaviour
{
	private const string ModelFile = "target_dummy.mesh";

	private const float BaseTop = 0.6f;

	private Transform upper;

	private Vector2 tilt;

	private Vector2 tiltVelocity;

	private readonly List<Collider> hitboxes = new List<Collider>();

	private Bounds localBounds;

	internal readonly Dictionary<HurtCollider, float> NextHit = new Dictionary<HurtCollider, float>();

	private DamagePopup.Label total;

	private int totalDamage;

	private int totalHealed;

	private int totalHits;

	private float lastHitTime = -999f;

	private HealthBar bar;

	private Collider bodyHitbox;

	private float lastChange;

	private float nextStateSync;

	internal static Dummy Target { get; private set; }

	internal static Dummy Ally { get; private set; }

	internal static IEnumerable<Dummy> All
	{
		get
		{
			if ((Object)(object)Target != (Object)null)
			{
				yield return Target;
			}
			if ((Object)(object)Ally != (Object)null)
			{
				yield return Ally;
			}
		}
	}

	internal DummyKind Kind { get; private set; }

	internal bool IsAlly => Kind == DummyKind.Ally;

	internal int Health { get; private set; }

	internal int MaxHealth { get; private set; }

	internal Transform Chest { get; private set; }

	internal Bounds WorldBounds { get; private set; }

	internal static Dummy Get(DummyKind kind)
	{
		if (kind != DummyKind.Ally)
		{
			return Target;
		}
		return Ally;
	}

	internal static Dummy Create(DummyKind kind, Vector3 position, Quaternion rotation, Material template, Transform sceneAnchor, float maxHeight = 99f)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_003f: 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_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject((kind == DummyKind.Ally) ? "Ally Dummy" : "Target Dummy");
		if ((Object)(object)sceneAnchor != (Object)null)
		{
			SceneManager.MoveGameObjectToScene(val, ((Component)sceneAnchor).gameObject.scene);
		}
		val.layer = 0;
		val.transform.SetPositionAndRotation(position, Quaternion.identity);
		Dummy dummy = val.AddComponent<Dummy>();
		dummy.Kind = kind;
		if (kind == DummyKind.Ally)
		{
			Ally = dummy;
		}
		else
		{
			Target = dummy;
		}
		dummy.Build(template, maxHeight);
		val.transform.rotation = rotation;
		dummy.UpdateWorldBounds();
		return dummy;
	}

	private void Build(Material template, float maxHeight)
	{
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_035d: Unknown result type (might be due to invalid IL or missing references)
		//IL_039d: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0455: Unknown result type (might be due to invalid IL or missing references)
		//IL_0466: Unknown result type (might be due to invalid IL or missing references)
		//IL_0332: 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_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: 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_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: 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_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_0222: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_0255: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: Unknown result type (might be due to invalid IL or missing references)
		//IL_0266: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0515: Unknown result type (might be due to invalid IL or missing references)
		//IL_0527: Unknown result type (might be due to invalid IL or missing references)
		//IL_0538: Unknown result type (might be due to invalid IL or missing references)
		//IL_053d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0542: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_060a: Unknown result type (might be due to invalid IL or missing references)
		//IL_063d: Unknown result type (might be due to invalid IL or missing references)
		//IL_064c: Unknown result type (might be due to invalid IL or missing references)
		//IL_065b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0593: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c7: Unknown result type (might be due to invalid IL or missing references)
		float num = (IsAlly ? Settings.AllyTotalHeight.Value : Settings.TotalHeight.Value);
		float num2 = (IsAlly ? Settings.DroidHeight.Value : Settings.RobeHeight.Value);
		if (maxHeight < num)
		{
			float num3 = Mathf.Max(1.6f, maxHeight) / num;
			Plugin.Log.LogInfo((object)$"{((Object)this).name}: only {maxHeight:0.00} m of headroom, so it's {num3 * 100f:0}% of its usual height.");
			num *= num3;
			num2 *= num3;
		}
		num2 = Mathf.Min(num2, num - 0.6f - 0.05f);
		float num4 = num - num2;
		float num5 = (IsAlly ? Settings.AllyCrossbarHeight.Value : Settings.CrossbarHeight.Value);
		float num6 = (IsAlly ? Settings.DroidYaw.Value : Settings.RobeYaw.Value);
		BorrowedModel obj = (IsAlly ? BorrowedModel.Droid : BorrowedModel.Robe);
		MeshLibrary.Model model = MeshLibrary.Get("target_dummy.mesh", "TD_Base");
		if (model != null)
		{
			MeshLibrary.Attach(model, ((Component)this).transform, "Base", template);
		}
		upper = new GameObject("Upper").transform;
		upper.SetParent(((Component)this).transform, false);
		upper.localPosition = new Vector3(0f, 0.6f, 0f);
		Vector3 size = default(Vector3);
		((Vector3)(ref size))..ctor(0.9f, num2, 0.6f);
		GameObject val = obj.Spawn(upper);
		if ((Object)(object)val != (Object)null)
		{
			val.transform.localRotation = Quaternion.Euler(0f, num6, 0f);
			val.SetActive(true);
			if (RendererBounds(val, out var bounds) && ((Bounds)(ref bounds)).size.y > 0.01f)
			{
				val.transform.localScale = Vector3.one * (num2 / ((Bounds)(ref bounds)).size.y);
				RendererBounds(val, out bounds);
				Vector3 val2 = ((Component)this).transform.InverseTransformPoint(((Bounds)(ref bounds)).center);
				float num7 = val2.y - ((Bounds)(ref bounds)).extents.y;
				Transform transform = val.transform;
				transform.position += new Vector3(0f - val2.x, num4 - num7, 0f - val2.z);
				size = ((Bounds)(ref bounds)).size;
			}
			else
			{
				Plugin.Log.LogWarning((object)"Couldn't measure the dummy's model; it may sit at the wrong height.");
			}
		}
		float num8 = num4 + num2 * 0.8f;
		float num9 = num4 + num2 * num5;
		float num10 = Mathf.Clamp(size.x * 1.1f, 1.3f, 3.2f);
		MeshLibrary.Model model2 = MeshLibrary.Get("target_dummy.mesh", "TD_Post");
		if (model2 != null)
		{
			MeshLibrary.Attach(model2, upper, "Post", template).transform.localScale = new Vector3(1f, num8 - 0.6f, 1f);
		}
		MeshLibrary.Model model3 = MeshLibrary.Get("target_dummy.mesh", "TD_Crossbar");
		if (model3 != null)
		{
			GameObject obj2 = MeshLibrary.Attach(model3, upper, "Crossbar", template);
			obj2.transform.localPosition = new Vector3(0f, num9 - 0.6f, 0f);
			obj2.transform.localScale = new Vector3(num10, 1f, 1f);
		}
		Chest = new GameObject("Chest").transform;
		Chest.SetParent(upper, false);
		Chest.localPosition = new Vector3(0f, num4 + num2 * 0.6f - 0.6f, 0f);
		float num11 = Mathf.Clamp(Mathf.Min(size.x, size.z) * 0.5f, 0.25f, 0.6f);
		CapsuleCollider val3 = Hitbox("Hitbox Body").AddComponent<CapsuleCollider>();
		val3.center = new Vector3(0f, num4 + num2 / 2f, 0f);
		val3.radius = num11;
		val3.height = Mathf.Max(num2, num11 * 2f);
		val3.direction = 1;
		hitboxes.Add((Collider)(object)val3);
		bodyHitbox = (Collider)(object)val3;
		hitboxes.Add(Box("Hitbox Crossbar", new Vector3(0f, num9, 0f), new Vector3(num10, 0.16f, 0.16f)));
		if (num4 > 0.6f)
		{
			hitboxes.Add(Box("Hitbox Post", new Vector3(0f, (0.6f + num4) / 2f, 0f), new Vector3(0.14f, num4 - 0.6f, 0.14f)));
		}
		hitboxes.Add(Box("Hitbox Base", new Vector3(0f, 0.3f, 0f), new Vector3(0.9f, 0.6f, 0.9f)));
		localBounds = new Bounds(new Vector3(0f, num / 2f, 0f), new Vector3(Mathf.Max(num10, 1.3f), num, Mathf.Max(size.z, 1.3f)));
		float num12 = num + 0.35f;
		if (IsAlly)
		{
			MaxHealth = Settings.AllyMaxHealth.Value;
			Health = Mathf.Clamp(Settings.AllyStartHealth.Value, 1, MaxHealth);
			PseudoPlayer.Create(this, new Vector3(0f, num4, 0f), bodyHitbox);
			if (Settings.AllyHealthBar.Value)
			{
				bar = HealthBar.Create(((Component)this).transform, new Vector3(0f, num + 0.3f, 0f));
				bar.Set(Health, MaxHealth, instant: true);
				num12 = num + 0.75f;
			}
		}
		total = DamagePopup.Persistent(((Component)this).transform, new Vector3(0f, num12, 0f));
		Plugin.Log.LogInfo((object)($"{((Object)this).name} built: {num:0.##} m tall, model {size.x:0.##} x {size.y:0.##} x {size.z:0.##} m, crossbar {num10:0.##} m" + (IsAlly ? $", {Health}/{MaxHealth} health." : ".")));
	}

	private GameObject Hitbox(string name)
	{
		//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_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		GameObject val = new GameObject(name);
		val.transform.SetParent(((Component)this).transform, false);
		val.layer = 0;
		return val;
	}

	private Collider Box(string name, Vector3 center, Vector3 size)
	{
		//IL_000d: 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)
		BoxCollider obj = Hitbox(name).AddComponent<BoxCollider>();
		obj.center = center;
		obj.size = size;
		return (Collider)(object)obj;
	}

	private static bool RendererBounds(GameObject go, out Bounds bounds)
	{
		//IL_0001: 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)
		//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)
		bounds = default(Bounds);
		bool flag = false;
		Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>();
		foreach (Renderer val in componentsInChildren)
		{
			if (val.enabled)
			{
				if (!flag)
				{
					bounds = val.bounds;
					flag = true;
				}
				else
				{
					((Bounds)(ref bounds)).Encapsulate(val.bounds);
				}
			}
		}
		return flag;
	}

	private void UpdateWorldBounds()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: 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_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		Bounds worldBounds = default(Bounds);
		((Bounds)(ref worldBounds))..ctor(((Component)this).transform.position + Vector3.up * ((Bounds)(ref localBounds)).center.y, Vector3.zero);
		foreach (Collider hitbox in hitboxes)
		{
			if ((Object)(object)hitbox != (Object)null)
			{
				((Bounds)(ref worldBounds)).Encapsulate(hitbox.bounds);
			}
		}
		WorldBounds = worldBounds;
	}

	internal bool Owns(Collider c)
	{
		if ((Object)(object)c != (Object)null)
		{
			return hitboxes.Contains(c);
		}
		return false;
	}

	internal Vector3 ClosestPoint(Vector3 p)
	{
		//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_0009: 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_0038: 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_003e: 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_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: 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_005b: 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)
		Bounds worldBounds = WorldBounds;
		Vector3 result = ((Bounds)(ref worldBounds)).center;
		float num = float.MaxValue;
		foreach (Collider hitbox in hitboxes)
		{
			if (!((Object)(object)hitbox == (Object)null))
			{
				Vector3 val = hitbox.ClosestPoint(p);
				Vector3 val2 = val - p;
				float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
				if (sqrMagnitude < num)
				{
					num = sqrMagnitude;
					result = val;
				}
			}
		}
		return result;
	}

	private void LateUpdate()
	{
		if (SemiFunc.IsMasterClientOrSingleplayer())
		{
			HitWatch.Scan(this);
		}
	}

	public void TargetDummyHit(float[] data)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		//IL_0093: 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)
		if (data != null && data.Length >= 1 && SemiFunc.IsMasterClientOrSingleplayer())
		{
			Vector3 direction = (Vector3)((data.Length >= 4) ? new Vector3(data[1], data[2], data[3]) : Vector3.zero);
			HitInfo hit = new HitInfo
			{
				Type = HitInfo.Kind.Direct,
				Damage = Mathf.RoundToInt(data[0]),
				Direction = direction,
				Knockback = ((data.Length >= 5) ? data[4] : 0f)
			};
			Bounds worldBounds = WorldBounds;
			hit.Point = ClosestPoint(((Bounds)(ref worldBounds)).center - ((Vector3)(ref direction)).normalized * 2f);
			Report(hit);
		}
	}

	internal void HostHeal(int amount, Vector3 from)
	{
		//IL_001a: 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_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		if (IsAlly && amount > 0 && SemiFunc.IsMasterClientOrSingleplayer())
		{
			Vector3 val = Chest.position - from;
			Report(new HitInfo
			{
				Type = HitInfo.Kind.Heal,
				Damage = amount,
				Point = Chest.position,
				Direction = ((((Vector3)(ref val)).sqrMagnitude > 0.0001f) ? ((Vector3)(ref val)).normalized : Vector3.zero)
			});
		}
	}

	internal void Report(HitInfo hit)
	{
		hit.Dummy = Kind;
		if (!IsAlly)
		{
			if (Settings.ApplyRobeResistance.Value && hit.Type != HitInfo.Kind.Impact)
			{
				hit.Damage = (int)((float)hit.Damage * (1f - Mathf.Min(BorrowedModel.RobeDamageResistance, 1f)));
			}
		}
		else
		{
			int health = Health;
			if (hit.Type == HitInfo.Kind.Heal)
			{
				Health = Mathf.Min(MaxHealth, Health + hit.Damage);
			}
			else
			{
				int num = (hit.Kill ? health : hit.Damage);
				hit.WouldDie = hit.Kill || (num > 0 && health - num <= 0);
				Health = Mathf.Max(1, health - num);
			}
			PseudoPlayer.SyncHealth(Health, MaxHealth);
			hit.Effective = Mathf.Abs(Health - health);
			hit.Health = Health;
			hit.MaxHealth = MaxHealth;
			lastChange = Time.time;
		}
		if (Settings.DebugLog.Value && hit.Type != HitInfo.Kind.Hurt && hit.Type != HitInfo.Kind.Push)
		{
			Plugin.Log.LogInfo((object)($"{((Object)this).name}: {hit.Type} {hit.Damage}" + (IsAlly ? $", health now {Health}/{MaxHealth}." : ".")));
		}
		Net.SendHit(hit);
	}

	private void HostAllyUpkeep()
	{
		float value = Settings.AllyResetAfter.Value;
		int num = Mathf.Clamp(Settings.AllyStartHealth.Value, 1, MaxHealth);
		if (value > 0f && Health != num && Time.time - lastChange > value)
		{
			Health = num;
			PseudoPlayer.SyncHealth(Health, MaxHealth);
			lastChange = Time.time;
			nextStateSync = 0f;
		}
		if (Time.time >= nextStateSync)
		{
			nextStateSync = Time.time + 3f;
			if (SemiFunc.IsMultiplayer())
			{
				Net.SendHit(new HitInfo
				{
					Dummy = Kind,
					Type = HitInfo.Kind.State,
					Health = Health,
					MaxHealth = MaxHealth
				});
			}
			else if ((Object)(object)bar != (Object)null)
			{
				bar.Set(Health, MaxHealth, instant: false);
			}
		}
	}

	internal void Show(HitInfo hit)
	{
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0120: 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_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		if (IsAlly && hit.MaxHealth > 0)
		{
			Health = hit.Health;
			MaxHealth = hit.MaxHealth;
			PseudoPlayer.SyncHealth(Health, MaxHealth);
			if ((Object)(object)bar != (Object)null)
			{
				bar.Set(Health, MaxHealth, hit.Type == HitInfo.Kind.State);
			}
		}
		if (hit.Type != HitInfo.Kind.State)
		{
			Vector3 direction = hit.Direction;
			direction.y = 0f;
			if (hit.Type != HitInfo.Kind.Heal && ((Vector3)(ref direction)).sqrMagnitude > 0.0001f && Settings.Wobble.Value > 0f)
			{
				Vector3 val = ((Component)this).transform.InverseTransformDirection(((Vector3)(ref direction)).normalized);
				float num = Mathf.Clamp(6f + hit.Knockback * 0.8f + hit.Torque * 0.2f + (float)hit.Damage * 0.05f + hit.ImpactForce * 0.1f, 0f, 70f);
				tiltVelocity += new Vector2(val.z, 0f - val.x) * num * Settings.Wobble.Value;
			}
			if (hit.Type == HitInfo.Kind.Heal)
			{
				totalHealed += (IsAlly ? hit.Effective : hit.Damage);
			}
			else
			{
				totalDamage += hit.Damage;
			}
			totalHits++;
			lastHitTime = Time.time;
			if ((Object)(object)total != (Object)null && Settings.ShowTotal.Value)
			{
				total.Set(TotalText(), Color.white);
			}
			DamagePopup.SpawnHit(hit);
		}
	}

	private string TotalText()
	{
		string text = string.Format("<size=60%>({0} hit{1})</size>", totalHits, (totalHits == 1) ? "" : "s");
		if (!IsAlly)
		{
			return $"<size=70%>Total</size> {totalDamage:N0}  {text}";
		}
		string text2 = "";
		if (totalDamage > 0)
		{
			text2 += $"<color=#ff6a5c>-{totalDamage:N0}</color>  ";
		}
		if (totalHealed > 0 || totalDamage == 0)
		{
			text2 += $"<color=#7dff5a>+{totalHealed:N0}</color>  ";
		}
		return text2 + text;
	}

	private void Update()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: 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_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_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: 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_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		float deltaTime = Time.deltaTime;
		tiltVelocity += (-70f * tilt - 7f * tiltVelocity) * deltaTime;
		tilt += tiltVelocity * deltaTime;
		tilt = Vector2.ClampMagnitude(tilt, 14f);
		if ((Object)(object)upper != (Object)null)
		{
			upper.localRotation = Quaternion.Euler(tilt.x, 0f, tilt.y);
		}
		if ((Object)(object)total != (Object)null && totalHits > 0 && Time.time - lastHitTime > 3f)
		{
			totalDamage = 0;
			totalHealed = 0;
			totalHits = 0;
			total.Fade();
		}
		if (IsAlly)
		{
			PseudoPlayer.UpdateVision(Camera.main);
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				HostAllyUpkeep();
			}
		}
	}

	private void OnDestroy()
	{
		if ((Object)(object)Target == (Object)(object)this)
		{
			Target = null;
		}
		if ((Object)(object)Ally == (Object)(object)this)
		{
			Ally = null;
			PseudoPlayer.Forget();
		}
	}
}
internal class HealthBar : MonoBehaviour
{
	private const float Width = 1.1f;

	private const float Height = 0.12f;

	private Transform fill;

	private Transform trail;

	private Material fillMat;

	private Material trailMat;

	private Material backMat;

	private TextMeshPro text;

	private float shown;

	private float trailShown;

	private float target;

	private float flash;

	private int lastHealth = -1;

	private Vector3 home;

	internal static HealthBar Create(Transform parent, Vector3 localPosition)
	{
		//IL_0005: 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_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: 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)
		GameObject val = new GameObject("Health Bar");
		val.transform.SetParent(parent, false);
		val.transform.localPosition = localPosition;
		HealthBar healthBar = val.AddComponent<HealthBar>();
		healthBar.home = localPosition;
		healthBar.Build();
		return healthBar;
	}

	private void Build()
	{
		//IL_000d: 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_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: 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_0061: Expected O, but got Unknown
		//IL_0063: 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_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Expected O, but got Unknown
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: 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_0111: Expected O, but got Unknown
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		Shader val = Shader.Find("Sprites/Default");
		backMat = new Material(val)
		{
			color = new Color(0f, 0f, 0f, 0.65f)
		};
		trailMat = new Material(val)
		{
			color = new Color(1f, 0.95f, 0.85f, 0.9f)
		};
		fillMat = new Material(val)
		{
			color = Color.green
		};
		Quad("Back", backMat, new Vector3(1.14f, 0.16f, 1f), 0.002f, 0);
		trail = Quad("Trail", trailMat, new Vector3(1.1f, 0.12f, 1f), 0.001f, 1);
		fill = Quad("Fill", fillMat, new Vector3(1.1f, 0.12f, 1f), 0f, 2);
		GameObject val2 = new GameObject("Text");
		val2.transform.SetParent(((Component)this).transform, false);
		val2.transform.localPosition = new Vector3(0f, 0.19f, 0f);
		text = DamagePopup.MakeText(val2, 1.6f);
	}

	private Transform Quad(string name, Material mat, Vector3 scale, float back, int order)
	{
		//IL_0037: 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)
		GameObject obj = GameObject.CreatePrimitive((PrimitiveType)5);
		Object.Destroy((Object)(object)obj.GetComponent<Collider>());
		((Object)obj).name = name;
		obj.layer = 0;
		obj.transform.SetParent(((Component)this).transform, false);
		obj.transform.localScale = scale;
		obj.transform.localPosition = new Vector3(0f, 0f, back);
		MeshRenderer component = obj.GetComponent<MeshRenderer>();
		((Renderer)component).sharedMaterial = mat;
		((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)component).receiveShadows = false;
		((Renderer)component).sortingOrder = 90 + order;
		return obj.transform;
	}

	internal void Set(int health, int max, bool instant)
	{
		target = ((max > 0) ? Mathf.Clamp01((float)health / (float)max) : 0f);
		if (instant || lastHealth < 0)
		{
			shown = (trailShown = target);
		}
		else if (health > lastHealth)
		{
			flash = 1f;
		}
		lastHealth = health;
		((TMP_Text)text).text = $"{health:N0} <size=70%>/ {max:N0}</size>";
	}

	private void Update()
	{
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: 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_01fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_0218: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0228: Unknown result type (might be due to invalid IL or missing references)
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		shown = Mathf.MoveTowards(shown, target, Time.deltaTime * 1.5f);
		trailShown = ((trailShown > shown) ? Mathf.MoveTowards(trailShown, shown, Time.deltaTime * 0.4f) : shown);
		Place(fill, shown);
		Place(trail, trailShown);
		Color val = ((target > 0.5f) ? Color.Lerp(new Color(1f, 0.85f, 0.15f), new Color(0.3f, 0.95f, 0.3f), (target - 0.5f) * 2f) : Color.Lerp(new Color(0.95f, 0.2f, 0.15f), new Color(1f, 0.85f, 0.15f), target * 2f));
		flash = Mathf.MoveTowards(flash, 0f, Time.deltaTime * 2f);
		fillMat.color = Color.Lerp(val, new Color(0.75f, 1f, 0.5f), flash);
		((Graphic)text).color = Color.Lerp(Color.white, new Color(0.6f, 1f, 0.45f), flash);
		Vector3 val2 = (((Object)(object)((Component)this).transform.parent != (Object)null) ? ((Component)this).transform.parent.TransformPoint(home) : ((Component)this).transform.position);
		((Component)this).transform.position = DamagePopup.Unblocked(val2, out var shrink);
		Camera val3 = Camera.main;
		if ((Object)(object)val3 == (Object)null)
		{
			val3 = Object.FindAnyObjectByType<Camera>();
		}
		if ((Object)(object)val3 != (Object)null)
		{
			((Component)this).transform.rotation = Quaternion.LookRotation(((Component)this).transform.position - ((Component)val3).transform.position);
			((Component)this).transform.localScale = Vector3.one * Mathf.Clamp(Vector3.Distance(((Component)val3).transform.position, val2) / 6f, 1f, 2f) * shrink;
		}
	}

	private static void Place(Transform t, float fraction)
	{
		//IL_0024: 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_0052: Unknown result type (might be due to invalid IL or missing references)
		fraction = Mathf.Clamp01(fraction);
		t.localScale = new Vector3(Mathf.Max(0.0001f, 1.1f * fraction), 0.12f, 1f);
		t.localPosition = new Vector3(-1.1f * (1f - fraction) / 2f, 0f, t.localPosition.z);
	}

	private void OnDestroy()
	{
		Object.Destroy((Object)(object)fillMat);
		Object.Destroy((Object)(object)trailMat);
		Object.Destroy((Object)(object)backMat);
	}
}
[HarmonyPatch]
internal static class HitWatch
{
	private static readonly HashSet<HurtCollider> active = new HashSet<HurtCollider>();

	private static readonly List<HurtCollider> scratch = new List<HurtCollider>();

	private static readonly Collider[] overlap = (Collider[])(object)new Collider[64];

	private static int primedFrame = -1;

	private static readonly FieldInfo RbField = AccessTools.Field(typeof(PhysGrabObjectImpactDetector), "rb");

	private static readonly FieldInfo BreakForceField = AccessTools.Field(typeof(PhysGrabObjectImpactDetector), "breakForce");

	private static readonly FieldInfo Level1Field = AccessTools.Field(typeof(PhysGrabObjectImpactDetector), "impactLevel1");

	private static readonly FieldInfo Level2Field = AccessTools.Field(typeof(PhysGrabObjectImpactDetector), "impactLevel2");

	private static readonly FieldInfo Level3Field = AccessTools.Field(typeof(PhysGrabObjectImpactDetector), "impactLevel3");

	private static readonly FieldInfo VelocityField = AccessTools.Field(typeof(PhysGrabObjectImpactDetector), "previousPreviousVelocityRaw");

	private static readonly FieldInfo ImpactForceField = AccessTools.Field(typeof(PhysGrabObjectImpactDetector), "impactForce");

	private static readonly FieldInfo IndestructibleField = AccessTools.Field(typeof(PhysGrabObjectImpactDetector), "isIndestructible");

	private static readonly FieldInfo InCartField = AccessTools.Field(typeof(PhysGrabObjectImpactDetector), "inCart");

	private static readonly Dictionary<PhysGrabObjectImpactDetector, float> impactCooldown = new Dictionary<PhysGrabObjectImpactDetector, float>();

	[HarmonyPostfix]
	[HarmonyPatch(typeof(HurtCollider), "OnEnable")]
	private static void HurtEnabled(HurtCollider __instance)
	{
		active.Add(__instance);
		foreach (Dummy item in Dummy.All)
		{
			item.NextHit.Remove(__instance);
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(HurtCollider), "OnDisable")]
	private static void HurtDisabled(HurtCollider __instance)
	{
		active.Remove(__instance);
	}

	internal static void Scan(Dummy dummy)
	{
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		if (primedFrame < 0 || (active.Count == 0 && Time.frameCount - primedFrame > 600))
		{
			HurtCollider[] array = Object.FindObjectsByType<HurtCollider>((FindObjectsSortMode)0);
			foreach (HurtCollider val in array)
			{
				if (((Behaviour)val).isActiveAndEnabled)
				{
					active.Add(val);
				}
			}
			primedFrame = Time.frameCount;
		}
		if (active.Count == 0)
		{
			return;
		}
		Bounds worldBounds = dummy.WorldBounds;
		((Bounds)(ref worldBounds)).Expand(0.5f);
		scratch.Clear();
		scratch.AddRange(active);
		foreach (HurtCollider item in scratch)
		{
			if ((Object)(object)item == (Object)null)
			{
				active.Remove(item);
				continue;
			}
			if (!((Behaviour)item).isActiveAndEnabled)
			{
				continue;
			}
			bool num;
			if (!dummy.IsAlly)
			{
				if (item.enemyLogic)
				{
					goto IL_0107;
				}
				num = !item.physLogic;
			}
			else
			{
				num = !item.playerLogic;
			}
			if (num)
			{
				continue;
			}
			goto IL_0107;
			IL_0107:
			if ((dummy.IsAlly && item.playerDamage <= 0 && !item.playerKill && item.playerHitForce <= 0f && item.playerTumbleForce <= 0f) || (dummy.NextHit.TryGetValue(item, out var value) && Time.time < value))
			{
				continue;
			}
			Collider component = ((Component)item).GetComponent<Collider>();
			if ((Object)(object)component == (Object)null)
			{
				continue;
			}
			Bounds val2 = ShapeBounds(component);
			if (((Bounds)(ref val2)).Intersects(worldBounds) && Touches(component, dummy))
			{
				float num2 = (dummy.IsAlly ? item.playerDamageCooldown : (item.enemyLogic ? item.enemyDamageCooldown : item.physDamageCooldown));
				if (dummy.NextHit.Count > 512)
				{
					dummy.NextHit.Clear();
				}
				dummy.NextHit[item] = ((num2 > 0f) ? (Time.time + num2) : float.MaxValue);
				HitInfo hit = FromHurtCollider(item, component, dummy);
				if (Settings.DebugLog.Value)
				{
					Plugin.Log.LogInfo((object)$"{((Object)dummy).name}: hit by '{((Object)item).name}' ({hit.Type}, damage {hit.Damage}, knockback {hit.Knockback:0.#}).");
				}
				dummy.Report(hit);
			}
		}
	}

	private static Bounds ShapeBounds(Collider zone)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: 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_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: 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_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: 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_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: 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)
		Transform transform = ((Component)zone).transform;
		Vector3 lossyScale = transform.lossyScale;
		float num = Mathf.Max(new float[3]
		{
			Mathf.Abs(lossyScale.x),
			Mathf.Abs(lossyScale.y),
			Mathf.Abs(lossyScale.z)
		});
		BoxCollider val = (BoxCollider)(object)((zone is BoxCollider) ? zone : null);
		if (val != null)
		{
			Vector3 val2 = transform.TransformPoint(val.center);
			Vector3 one = Vector3.one;
			Vector3 size = val.size;
			return new Bounds(val2, one * (((Vector3)(ref size)).magnitude * num));
		}
		SphereCollider val3 = (SphereCollider)(object)((zone is SphereCollider) ? zone : null);
		if (val3 != null)
		{
			return new Bounds(transform.TransformPoint(val3.center), Vector3.one * (val3.radius * 2f * num));
		}
		CapsuleCollider val4 = (CapsuleCollider)(object)((zone is CapsuleCollider) ? zone : null);
		if (val4 != null)
		{
			return new Bounds(transform.TransformPoint(val4.center), Vector3.one * (Mathf.Max(val4.height, val4.radius * 2f) * num));
		}
		return zone.bounds;
	}

	private static bool Touches(Collider zone, Dummy dummy)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: 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_002f: 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_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: 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_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_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		Transform transform = ((Component)zone).transform;
		BoxCollider val = (BoxCollider)(object)((zone is BoxCollider) ? zone : null);
		int num;
		if (val != null)
		{
			Vector3 val2 = Vector3.Scale(val.size, transform.lossyScale) * 0.5f;
			((Vector3)(ref val2))..ctor(Mathf.Abs(val2.x), Mathf.Abs(val2.y), Mathf.Abs(val2.z));
			num = Physics.OverlapBoxNonAlloc(transform.TransformPoint(val.center), val2, overlap, transform.rotation, 1, (QueryTriggerInteraction)1);
		}
		else
		{
			SphereCollider val3 = (SphereCollider)(object)((zone is SphereCollider) ? zone : null);
			if (val3 != null)
			{
				Vector3 lossyScale = transform.lossyScale;
				float num2 = val3.radius * Mathf.Max(new float[3]
				{
					Mathf.Abs(lossyScale.x),
					Mathf.Abs(lossyScale.y),
					Mathf.Abs(lossyScale.z)
				});
				num = Physics.OverlapSphereNonAlloc(transform.TransformPoint(val3.center), num2, overlap, 1, (QueryTriggerInteraction)1);
			}
			else
			{
				Bounds bounds = zone.bounds;
				num = Physics.OverlapBoxNonAlloc(((Bounds)(ref bounds)).center, ((Bounds)(ref bounds)).extents, overlap, Quaternion.identity, 1, (QueryTriggerInteraction)1);
			}
		}
		for (int i = 0; i < num; i++)
		{
			if (dummy.Owns(overlap[i]))
			{
				return true;
			}
		}
		return false;
	}

	private static HitInfo FromHurtCollider(HurtCollider h, Collider zone, Dummy dummy)
	{
		//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_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_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)
		//IL_0017: 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_0019: 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_001f: 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_0045: 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_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		Bounds val = ShapeBounds(zone);
		Vector3 center = ((Bounds)(ref val)).center;
		Vector3 val2 = dummy.ClosestPoint(center);
		Vector3 val3 = val2 - center;
		if (((Vector3)(ref val3)).sqrMagnitude < 0.0001f)
		{
			val3 = ((Component)h).transform.forward;
		}
		HitInfo result = new HitInfo
		{
			Point = val2,
			Direction = ((Vector3)(ref val3)).normalized
		};
		if (dummy.IsAlly)
		{
			result.Type = HitInfo.Kind.Hurt;
			result.Damage = h.playerDamage;
			result.Kill = h.playerKill;
			result.Knockback = h.playerHitForce;
			result.Torque = h.playerTumbleForce;
			result.Stun = h.playerStunTime;
			result.Freeze = h.playerTumbleTime;
		}
		else if (h.enemyLogic)
		{
			result.Type = HitInfo.Kind.Hurt;
			result.Damage = h.enemyDamage;
			result.Kill = h.enemyKill;
			result.Knockback = h.enemyHitForce;
			result.Torque = h.enemyHitTorque;
			result.Stun = (h.enemyStun ? h.enemyStunTime : 0f);
			result.Freeze = h.enemyFreezeTime;
		}
		else
		{
			result.Type = HitInfo.Kind.Push;
			result.Knockback = h.physHitForce;
			result.Torque = h.physHitTorque;
		}
		return result;
	}

	private static float F(FieldInfo f, object o)
	{
		if (!(f != null))
		{
			return 0f;
		}
		return (float)f.GetValue(o);
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "OnCollisionStay")]
	private static void ObjectImpact(PhysGrabObjectImpactDetector __instance, Collision collision)
	{
		//IL_00cf: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0218: Unknown result type (might be due to invalid IL or missing references)
		//IL_021d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0221: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: 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_0226: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: Unknown result type (might be due to invalid IL or missing references)
		//IL_023d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_024b: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Dummy target = Dummy.Target;
			if ((Object)(object)target == (Object)null || collision == null || !target.Owns(collision.collider) || !SemiFunc.IsMasterClientOrSingleplayer() || (InCartField != null && (bool)InCartField.GetValue(__instance)) || __instance.destroyDisable || (IndestructibleField != null && (bool)IndestructibleField.GetValue(__instance)) || (Object)(object)((Component)__instance).GetComponentInParent<ItemAttributes>() != (Object)null || (impactCooldown.TryGetValue(__instance, out var value) && Time.time < value))
			{
				return;
			}
			Vector3 val = (Vector3)((VelocityField != null) ? ((Vector3)VelocityField.GetValue(__instance)) : Vector3.zero);
			float magnitude = ((Vector3)(ref val)).magnitude;
			if (magnitude <= 2f)
			{
				return;
			}
			object? obj = RbField?.GetValue(__instance);
			Rigidbody val2 = (Rigidbody)((obj is Rigidbody) ? obj : null);
			float num = (((Object)(object)val2 != (Object)null) ? val2.mass : 1f);
			float num2 = F(BreakForceField, __instance);
			float num3 = Mathf.Max(num, 1f);
			int num4 = ((num2 > F(Level3Field, __instance) * num3) ? 3 : ((num2 > F(Level2Field, __instance) * num3) ? 2 : ((num2 > F(Level1Field, __instance) * num3) ? 1 : 0)));
			float num5 = F(ImpactForceField, __instance);
			if (num4 != 0 || !(num5 <= 20f))
			{
				int num6 = Mathf.RoundToInt((float)(10 * num4) * num * 0.5f);
				num6 = (BorrowedModel.RobeObjectHurt ? Mathf.RoundToInt((float)num6 * BorrowedModel.RobeObjectHurtMultiplier) : 0);
				impactCooldown[__instance] = Time.time + 0.5f;
				if (impactCooldown.Count > 256)
				{
					impactCooldown.Clear();
				}
				Vector3 val3;
				if (collision.contactCount <= 0)
				{
					val3 = target.ClosestPoint(((Component)__instance).transform.position);
				}
				else
				{
					ContactPoint contact = collision.GetContact(0);
					val3 = ((ContactPoint)(ref contact)).point;
				}
				Vector3 point = val3;
				target.Report(new HitInfo
				{
					Type = HitInfo.Kind.Impact,
					Point = point,
					Direction = ((Vector3)(ref val)).normalized,
					Damage = num6,
					ImpactForce = num5,
					Speed = magnitude
				});
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogDebug((object)("Impact check failed: " + ex.Message));
		}
	}
}
internal static class MeshLibrary
{
	internal class Part
	{
		public string MaterialName;

		public Color Color;

		public float Smoothness;

		public float Metallic;
	}

	internal class Model
	{
		public string Name;

		public Mesh Mesh;

		public List<Part> Parts = new List<Part>();
	}

	private static readonly Dictionary<string, Dictionary<string, Model>> cache = new Dictionary<string, Dictionary<string, Model>>();

	private static readonly Dictionary<string, Material> materialCache = new Dictionary<string, Material>();

	internal static Model Get(string file, string objectName)
	{
		if (!cache.TryGetValue(file, out var value))
		{
			value = (cache[file] = Load(file));
		}
		if (value == null || !value.TryGetValue(objectName, out var value2))
		{
			return null;
		}
		return value2;
	}

	private static Dictionary<string, Model> Load(string file)
	{
		//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_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e9: Expected O, but got Unknown
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		string text = "TargetDummy.Assets." + file;
		using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(text);
		if (stream == null)
		{
			Plugin.Log.LogError((object)("Embedded model '" + text + "' is missing."));
			return null;
		}
		using BinaryReader binaryReader = new BinaryReader(stream);
		if (Encoding.ASCII.GetString(binaryReader.ReadBytes(4)) != "HWM1")
		{
			Plugin.Log.LogError((object)("'" + file + "' is not a HWM1 model."));
			return null;
		}
		Dictionary<string, Model> dictionary = new Dictionary<string, Model>();
		int num = binaryReader.ReadInt32();
		for (int i = 0; i < num; i++)
		{
			Model model = new Model
			{
				Name = ReadString(binaryReader)
			};
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<int[]> list3 = new List<int[]>();
			int num2 = binaryReader.ReadInt32();
			for (int j = 0; j < num2; j++)
			{
				Part part = new Part
				{
					MaterialName = ReadString(binaryReader)
				};
				part.Color = new Color(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
				part.Smoothness = binaryReader.ReadSingle();
				part.Metallic = binaryReader.ReadSingle();
				model.Parts.Add(part);
				int count = list.Count;
				int num3 = binaryReader.ReadInt32();
				for (int k = 0; k < num3; k++)
				{
					list.Add(new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle()));
					list2.Add(new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle()));
				}
				int num4 = binaryReader.ReadInt32();
				int[] array = new int[num4];
				for (int l = 0; l < num4; l++)
				{
					array[l] = binaryReader.ReadInt32() + count;
				}
				list3.Add(array);
			}
			Mesh val = new Mesh
			{
				name = model.Name
			};
			if (list.Count > 65000)
			{
				val.indexFormat = (IndexFormat)1;
			}
			val.SetVertices(list);
			val.SetNormals(list2);
			val.subMeshCount = list3.Count;
			for (int m = 0; m < list3.Count; m++)
			{
				val.SetTriangles(list3[m], m, false);
			}
			val.RecalculateBounds();
			val.UploadMeshData(false);
			model.Mesh = val;
			dictionary[model.Name] = model;
		}
		return dictionary;
	}

	private static string ReadString(BinaryReader r)
	{
		return Encoding.UTF8.GetString(r.ReadBytes(r.ReadInt32()));
	}

	internal static GameObject Attach(Model model, Transform parent, string name, Material template)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		GameObject val = new GameObject(name);
		val.transform.SetParent(parent, false);
		val.layer = ((Component)parent).gameObject.layer;
		val.AddComponent<MeshFilter>().sharedMesh = model.Mesh;
		MeshRenderer val2 = val.AddComponent<MeshRenderer>();
		Material[] array = (Material[])(object)new Material[model.Parts.Count];
		for (int i = 0; i < array.Length; i++)
		{
			array[i] = MakeMaterial(template, model.Parts[i]);
		}
		((Renderer)val2).sharedMaterials = array;
		return val;
	}

	private static Material MakeMaterial(Material template, Part part)
	{
		//IL_003a: 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_0040: Expected O, but got Unknown
		//IL_00e1: 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)
		if (materialCache.TryGetValue(part.MaterialName, out var value) && (Object)(object)value != (Object)null)
		{
			return value;
		}
		Material val = (((Object)(object)template != (Object)null) ? new Material(template) : new Material(Shader.Find("Standard")));
		((Object)val).name = "TargetDummy " + part.MaterialName;
		string[] array = new string[6] { "_MainTex", "_BaseMap", "_BumpMap", "_MetallicGlossMap", "_EmissionMap", "_OcclusionMap" };
		foreach (string text in array)
		{
			if (val.HasProperty(text))
			{
				val.SetTexture(text, (Texture)null);
			}
		}
		array = new string[2] { "_Color", "_BaseColor" };
		foreach (string text2 in array)
		{
			if (val.HasProperty(text2))
			{
				val.SetColor(text2, part.Color);
			}
		}
		if (val.HasProperty("_EmissionColor"))
		{
			val.SetColor("_EmissionColor", Color.black);
		}
		val.DisableKeyword("_EMISSION");
		if (val.HasProperty("_Metallic"))
		{
			val.SetFloat("_Metallic", part.Metallic);
		}
		array = new string[2] { "_Smoothness", "_Glossiness" };
		foreach (string text3 in array)
		{
			if (val.HasProperty(text3))
			{
				val.SetFloat(text3, part.Smoothness);
			}
		}
		materialCache[part.MaterialName] = val;
		return val;
	}
}
internal static class Net
{
	private const byte EventCode = 151;

	private const byte RequestCode = 152;

	private const string Tag = "TDMY2";

	internal static void Init()
	{
		try
		{
			PhotonNetwork.NetworkingClient.EventReceived += OnEvent;
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"Couldn't listen for dummy hits; multiplayer numbers won't show: {arg}");
		}
	}

	internal static void SendHit(HitInfo h)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: 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_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Expected O, but got Unknown
		if (!SemiFunc.IsMultiplayer())
		{
			Show(h);
			return;
		}
		float[] array = new float[20]
		{
			(int)h.Type,
			h.Point.x,
			h.Point.y,
			h.Point.z,
			h.Direction.x,
			h.Direction.y,
			h.Direction.z,
			h.Damage,
			h.Kill ? 1f : 0f,
			h.Knockback,
			h.Torque,
			h.Stun,
			h.Freeze,
			h.ImpactForce,
			h.Speed,
			(int)h.Dummy,
			h.Health,
			h.MaxHealth,
			h.Effective,
			h.WouldDie ? 1f : 0f
		};
		Show(h);
		try
		{
			PhotonNetwork.RaiseEvent((byte)151, (object)new object[2] { "TDMY2", array }, new RaiseEventOptions
			{
				Receivers = (ReceiverGroup)0
			}, SendOptions.SendReliable);
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Sending a dummy hit failed: " + ex.Message));
		}
	}

	internal static void Request(HitInfo.Kind type, int amount, Vector3 direction)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0057: Expected O, but got Unknown
		try
		{
			PhotonNetwork.RaiseEvent((byte)152, (object)new object[2]
			{
				"TDMY2",
				new float[5]
				{
					(int)type,
					amount,
					direction.x,
					direction.y,
					direction.z
				}
			}, new RaiseEventOptions
			{
				Receivers = (ReceiverGroup)2
			}, SendOptions.SendReliable);
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Asking the host to update the Ally Dummy failed: " + ex.Message));
		}
	}

	private static void OnRequest(EventData e)
	{
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		if (SemiFunc.IsMasterClientOrSingleplayer() && !((Object)(object)Dummy.Ally == (Object)null) && e.CustomData is object[] array && array.Length >= 2 && array[0] is string text && !(text != "TDMY2") && array[1] is float[] array2 && array2.Length >= 5)
		{
			int num = Mathf.Clamp(Mathf.RoundToInt(array2[1]), 0, 100000);
			if (Settings.DebugLog.Value)
			{
				Plugin.Log.LogInfo((object)$"Ally Dummy: player {e.Sender} asks for {(HitInfo.Kind)array2[0]} {num}.");
			}
			if ((byte)array2[0] == 4)
			{
				Dummy.Ally.HostHeal(num, Dummy.Ally.Chest.position + ((Component)Dummy.Ally).transform.forward);
				return;
			}
			Dummy.Ally.TargetDummyHit(new float[4]
			{
				num,
				array2[2],
				array2[3],
				array2[4]
			});
		}
	}

	private static void OnEvent(EventData e)
	{
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: 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_009c: Unknown result type (might be due to invalid IL or missing references)
		if (e.Code == 152)
		{
			OnRequest(e);
		}
		else if (e.Code == 151 && e.CustomData is object[] array && array.Length >= 2 && array[0] is string text && !(text != "TDMY2") && array[1] is float[] array2 && array2.Length >= 20)
		{
			HitInfo h = new HitInfo
			{
				Type = (HitInfo.Kind)array2[0],
				Point = new Vector3(array2[1], array2[2], array2[3]),
				Direction = new Vector3(array2[4], array2[5], array2[6]),
				Damage = Mathf.RoundToInt(array2[7]),
				Kill = (array2[8] > 0.5f),
				Knockback = array2[9],
				Torque = array2[10],
				Stun = array2[11],
				Freeze = array2[12],
				ImpactForce = array2[13],
				Speed = array2[14],
				Dummy = (DummyKind)array2[15],
				Health = Mathf.RoundToInt(array2[16]),
				MaxHealth = Mathf.RoundToInt(array2[17]),
				Effective = Mathf.RoundToInt(array2[18]),
				WouldDie = (array2[19] > 0.5f)
			};
			if (Settings.DebugLog.Value && h.Type != HitInfo.Kind.State)
			{
				Plugin.Log.LogInfo((object)$"Received a {h.Dummy} Dummy {h.Type} from the host.");
			}
			Show(h);
		}
	}

	private static void Show(HitInfo h)
	{
		try
		{
			Dummy.Get(h.Dummy)?.Show(h);
		}
		catch (Exception arg)
		{
			Plugin.Log.LogWarning((object)$"Showing a dummy hit failed: {arg}");
		}
	}
}
[BepInPlugin("TargetDummy", "TargetDummy", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public const string Guid = "TargetDummy";

	public const string Name = "TargetDummy";

	public const string Version = "1.0.0";

	internal static ManualLogSource Log { get; private set; }

	private void Awake()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		Settings.Bind(((BaseUnityPlugin)this).Config);
		new Harmony("TargetDummy").PatchAll(typeof(Plugin).Assembly);
		Net.Init();
		Log.LogInfo((object)"TargetDummy 1.0.0 loaded.");
	}
}
[HarmonyPatch]
internal static class PseudoPlayer
{
	internal const int ViewId = 16700001;

	internal const string DisplayName = "Ally Dummy";

	private static PlayerHealth health;

	private static Transform vision;

	private static Dummy owner;

	private static Collider body;

	private static readonly FieldInfo ViewIdField = AccessTools.Field(typeof(PhotonView), "viewIdField");

	private static readonly FieldInfo NameField = AccessTools.Field(typeof(PlayerAvatar), "playerName");

	private static readonly FieldInfo HealthField = AccessTools.Field(typeof(PlayerHealth), "health");

	private static readonly FieldInfo MaxHealthField = AccessTools.Field(typeof(PlayerHealth), "maxHealth");

	private static readonly FieldInfo HealthAvatarField = AccessTools.Field(typeof(PlayerHealth), "playerAvatar");

	private static readonly FieldInfo HealthViewField = AccessTools.Field(typeof(PlayerHealth), "photonView");

	private static readonly FieldInfo VisionAvatarField = AccessTools.Field(typeof(PlayerVisionTarget), "PlayerAvatar");

	private static readonly FieldInfo VisionViewField = AccessTools.Field(typeof(PlayerVisionTarget), "PhotonView");

	private static readonly List<PlayerAvatar> withDummy = new List<PlayerAvatar>();

	private static readonly Assembly Game = typeof(SemiFunc).Assembly;

	private static readonly Assembly Self = typeof(PseudoPlayer).Assembly;

	internal static PlayerAvatar Avatar { get; private set; }

	private static bool IsDummy(PlayerHealth h)
	{
		if ((Object)(object)h != (Object)null && h == health)
		{
			return (Object)(object)health != (Object)null;
		}
		return false;
	}

	internal static void Create(Dummy ally, Vector3 feet, Collider bodyHitbox)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			owner = ally;
			body = bodyHitbox;
			GameObject val = new GameObject("Ally Dummy");
			val.SetActive(false);
			val.transform.SetParent(((Component)ally).transform, false);
			val.transform.localPosition = feet;
			PhotonView val2 = val.GetComponent<PhotonView>() ?? val.AddComponent<PhotonView>();
			ViewIdField?.SetValue(val2, 16700001);
			PlayerHealth val3 = val.GetComponent<PlayerHealth>() ?? val.AddComponent<PlayerHealth>();
			PlayerVisionTarget val4 = val.GetComponent<PlayerVisionTarget>() ?? val.AddComponent<PlayerVisionTarget>();
			PlayerAvatar val5 = val.GetComponent<PlayerAvatar>() ?? val.AddComponent<PlayerAvatar>();
			vision = new GameObject("Ally Dummy Vision Point").transform;
			vision.SetParent(((Component)ally).transform, false);
			vision.position = ally.Chest.position;
			val5.photonView = val2;
			val5.playerHealth = val3;
			val5.PlayerVisionTarget = val4;
			NameField?.SetValue(val5, "Ally Dummy");
			HealthAvatarField?.SetValue(val3, val5);
			HealthViewField?.SetValue(val3, val2);
			val4.VisionTransform = vision;
			VisionAvatarField?.SetValue(val4, val5);
			VisionViewField?.SetValue(val4, val2);
			health = val3;
			Avatar = val5;
			SyncHealth(ally.Health, ally.MaxHealth);
			Plugin.Log.LogInfo((object)$"Ally Dummy joined as a pseudo-player (network ID {16700001}): other mods will see it as a teammate.");
		}
		catch (Exception arg)
		{
			Avatar = null;
			health = null;
			Plugin.Log.LogError((object)$"Making the Ally Dummy a pseudo-player failed; mods won't see it as a teammate: {arg}");
		}
	}

	internal static void SyncHealth(int hp, int max)
	{
		if (!((Object)(object)health == (Object)null))
		{
			HealthField?.SetValue(health, hp);
			MaxHealthField?.SetValue(health, max);
		}
	}

	internal static void UpdateVision(Camera cam)
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: 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)
		//IL_0050: 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 ref