Decompiled source of RandomBullshit v1.0.9

RandomBullshit.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using GUIFramework;
using HarmonyLib;
using Jotunn.Entities;
using Jotunn.Managers;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyCompany("RandomBullshit")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+8f38ed67aa642205dc465717dff98f0c86eea118")]
[assembly: AssemblyProduct("RandomBullshit")]
[assembly: AssemblyTitle("RandomBullshit")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class IsReadOnlyAttribute : Attribute
	{
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RandomBullshit
{
	[BepInPlugin("com.randombullshit.mod", "RandomBullshit", "1.0.9")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class RandomBullshitPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.randombullshit.mod";

		public const string PluginName = "RandomBullshit";

		public const string PluginVersion = "1.0.9";

		internal static RandomBullshitPlugin Instance { get; private set; }

		private void Awake()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			new Harmony("com.randombullshit.mod").PatchAll(typeof(TrainingDummyCharacterDpsPatch).Assembly);
			CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
			string text = "$piece_TWMTrainingDummy";
			localization.AddTranslation(ref text, "T.W.M");
			PrefabManager.OnVanillaPrefabsAvailable += RegisterTrainingWithMexicanito;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"RandomBullshit loaded. Type Mexicaniando!");
		}

		private void RegisterTrainingWithMexicanito()
		{
			PrefabManager.OnVanillaPrefabsAvailable -= RegisterTrainingWithMexicanito;
			TrainingWithMexicanitoPiece.Register();
		}

		internal static void LogInfo(string message)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)message);
		}

		internal static void LogError(string message)
		{
			((BaseUnityPlugin)Instance).Logger.LogError((object)message);
		}
	}
	[HarmonyPatch(typeof(Chat), "InputText")]
	internal static class RemoveTrainingDummyChatPatch
	{
		private const string Command = "/removedummy";

		private const float RemovalRange = 8f;

		private static bool Prefix(Chat __instance)
		{
			GuiInputField input = ((Terminal)__instance).m_input;
			if ((Object)(object)input == (Object)null)
			{
				return true;
			}
			string text = ((TMP_InputField)input).text;
			if (string.IsNullOrEmpty(text) || !text.StartsWith("/removedummy", StringComparison.OrdinalIgnoreCase) || (text.Length > "/removedummy".Length && !char.IsWhiteSpace(text["/removedummy".Length])))
			{
				return true;
			}
			((TMP_InputField)input).text = string.Empty;
			if (!string.IsNullOrWhiteSpace(text.Substring("/removedummy".Length)))
			{
				((Terminal)__instance).AddString("Usage: /removedummy");
				return false;
			}
			RemoveNearestDummy((Terminal)(object)__instance);
			return false;
		}

		private static void RemoveNearestDummy(Terminal context)
		{
			//IL_003c: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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)
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				context.AddString("Cannot remove a training dummy because no local player is available.");
				return;
			}
			if ((Object)(object)ZNetScene.instance == (Object)null)
			{
				context.AddString("Cannot remove a training dummy because the network scene is unavailable.");
				return;
			}
			Vector3 position = ((Component)Player.m_localPlayer).transform.position;
			Character val = null;
			float num = 64f;
			Character[] array = Object.FindObjectsByType<Character>((FindObjectsSortMode)0);
			foreach (Character val2 in array)
			{
				if (TrainingDummyDpsDisplayPatch.IsTrainingDummy(val2))
				{
					Vector3 val3 = ((Component)val2).transform.position - position;
					float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
					if (!(sqrMagnitude > num))
					{
						val = val2;
						num = sqrMagnitude;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				context.AddString($"No training dummy found within {8f:F0} meters.");
				return;
			}
			ZNetView component = ((Component)val).GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null)
			{
				context.AddString("Cannot remove the training dummy because its network view is missing.");
				return;
			}
			if (!component.IsOwner())
			{
				context.AddString("Cannot remove the training dummy because your player does not own it.");
				return;
			}
			ZNetScene.instance.Destroy(((Component)val).gameObject);
			context.AddString("Removed the nearest training dummy.");
		}
	}
	[HarmonyPatch(typeof(Chat), "InputText")]
	internal static class SpawnTrainingDummyChatPatch
	{
		private const string Command = "/spawndummy";

		private const float SpawnDistance = 3f;

		private const string TwigPrefabName = "piece_TrainingDummy";

		private static bool Prefix(Chat __instance)
		{
			GuiInputField input = ((Terminal)__instance).m_input;
			if ((Object)(object)input == (Object)null)
			{
				return true;
			}
			string text = ((TMP_InputField)input).text;
			if (string.IsNullOrEmpty(text) || !text.StartsWith("/spawndummy", StringComparison.OrdinalIgnoreCase) || (text.Length > "/spawndummy".Length && !char.IsWhiteSpace(text["/spawndummy".Length])))
			{
				return true;
			}
			((TMP_InputField)input).text = string.Empty;
			string text2 = text.Substring("/spawndummy".Length).Trim();
			string prefabName;
			if (string.IsNullOrEmpty(text2) || string.Equals(text2, "twm", StringComparison.OrdinalIgnoreCase))
			{
				prefabName = "piece_TWMTrainingDummy";
			}
			else
			{
				if (!string.Equals(text2, "twig", StringComparison.OrdinalIgnoreCase))
				{
					((Terminal)__instance).AddString("Usage: /spawndummy [twig|twm]");
					return false;
				}
				prefabName = "piece_TrainingDummy";
			}
			SpawnDummy((Terminal)(object)__instance, prefabName);
			return false;
		}

		private static void SpawnDummy(Terminal context, string prefabName)
		{
			//IL_0064: 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_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)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				context.AddString("Cannot spawn a training dummy because no local player is available.");
				return;
			}
			ZNetScene instance = ZNetScene.instance;
			if ((Object)(object)instance == (Object)null)
			{
				context.AddString("Cannot spawn a training dummy because the network scene is unavailable.");
				return;
			}
			GameObject prefab = instance.GetPrefab(prefabName);
			if ((Object)(object)prefab == (Object)null)
			{
				context.AddString("Cannot spawn training dummy: prefab '" + prefabName + "' is unavailable.");
				return;
			}
			Vector3 forward = ((Component)localPlayer).transform.forward;
			forward.y = 0f;
			if (((Vector3)(ref forward)).sqrMagnitude <= 0f)
			{
				forward = Vector3.forward;
			}
			((Vector3)(ref forward)).Normalize();
			Vector3 val = ((Component)localPlayer).transform.position + forward * 3f;
			Quaternion val2 = Quaternion.LookRotation(forward);
			instance.SpawnObject(val, val2, prefab);
			context.AddString("Spawned " + ((prefabName == "piece_TrainingDummy") ? "T.W.I.G." : "T.W.M.") + " for testing.");
		}
	}
	internal static class TrainingDummySettings
	{
		internal const float MaxHealth = 500000f;
	}
	[HarmonyPatch(typeof(Character), "Awake")]
	internal static class TrainingDummyHealthPatch
	{
		private static void Prefix(Character __instance)
		{
			if (TrainingDummyDpsDisplayPatch.IsTrainingDummy(__instance))
			{
				__instance.m_health = 500000f;
			}
		}

		private static void Postfix(Character __instance)
		{
			if (TrainingDummyDpsDisplayPatch.IsTrainingDummy(__instance))
			{
				ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
				if (!((Object)(object)component == (Object)null) && component.IsValid() && component.IsOwner() && __instance.GetMaxHealth() < 500000f)
				{
					__instance.SetMaxHealth(500000f);
					__instance.SetHealth(500000f);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Character), "Start")]
	internal static class TrainingDummyDpsDisplayPatch
	{
		private static void Postfix(Character __instance)
		{
			if (IsTrainingDummy(__instance))
			{
				Piece component = ((Component)__instance).GetComponent<Piece>();
				if ((Object)(object)component != (Object)null)
				{
					component.m_canBeRemoved = true;
				}
				if ((Object)(object)((Component)__instance).GetComponent<TrainingDummyDpsDisplay>() == (Object)null)
				{
					((Component)__instance).gameObject.AddComponent<TrainingDummyDpsDisplay>();
				}
				if ((Object)(object)((Component)__instance).GetComponent<TrainingDummyRegeneration>() == (Object)null)
				{
					((Component)__instance).gameObject.AddComponent<TrainingDummyRegeneration>();
				}
			}
		}

		internal static bool IsTrainingDummy(Character character)
		{
			if (!IsTwigDummy(character))
			{
				return IsTwmDummy(character);
			}
			return true;
		}

		internal static bool IsTwmDummy(Character character)
		{
			if (!((Object)(object)((Component)character).GetComponent<TwmTrainingDummyMarker>() != (Object)null))
			{
				return ((Object)((Component)character).gameObject).name.StartsWith("piece_TWMTrainingDummy", StringComparison.OrdinalIgnoreCase);
			}
			return true;
		}

		private static bool IsTwigDummy(Character character)
		{
			return ((Object)((Component)character).gameObject).name.StartsWith("piece_TrainingDummy", StringComparison.OrdinalIgnoreCase);
		}
	}
	[HarmonyPatch(typeof(Character), "SetHealth", new Type[] { typeof(float) })]
	internal static class TwmDummyPreventDeathPatch
	{
		private static void Prefix(Character __instance, ref float __0)
		{
			if (TrainingDummyDpsDisplayPatch.IsTrainingDummy(__instance) && !TrainingDummyRemovalContext.IsRemovingPiece && __0 <= 0f)
			{
				__0 = 1f;
			}
		}
	}
	[HarmonyPatch(typeof(Piece), "CanBeRemoved")]
	internal static class TrainingDummyCanBeRemovedPatch
	{
		private static bool Prefix(Piece __instance, ref bool __result)
		{
			Character component = ((Component)__instance).GetComponent<Character>();
			if ((Object)(object)component == (Object)null || !TrainingDummyDpsDisplayPatch.IsTrainingDummy(component))
			{
				return true;
			}
			__result = true;
			return false;
		}
	}
	[HarmonyPatch(typeof(Player), "RemovePiece")]
	internal static class TrainingDummyPlayerRemovalContextPatch
	{
		private static void Prefix(out bool __state)
		{
			__state = TrainingDummyRemovalContext.IsRemovingPiece;
			TrainingDummyRemovalContext.IsRemovingPiece = true;
		}

		private static void Postfix(bool __state)
		{
			TrainingDummyRemovalContext.IsRemovingPiece = __state;
		}
	}
	[HarmonyPatch(typeof(WearNTear), "RPC_Remove", new Type[]
	{
		typeof(long),
		typeof(bool)
	})]
	internal static class TrainingDummyWearNTearRemovalContextPatch
	{
		private static void Prefix(WearNTear __instance, out bool __state)
		{
			__state = TrainingDummyRemovalContext.IsRemovingPiece;
			Character component = ((Component)__instance).GetComponent<Character>();
			if ((Object)(object)component != (Object)null && TrainingDummyDpsDisplayPatch.IsTrainingDummy(component))
			{
				TrainingDummyRemovalContext.IsRemovingPiece = true;
			}
		}

		private static void Postfix(bool __state)
		{
			TrainingDummyRemovalContext.IsRemovingPiece = __state;
		}
	}
	internal static class TrainingDummyRemovalContext
	{
		internal static bool IsRemovingPiece { get; set; }
	}
	[HarmonyPatch(typeof(Destructible), "Destroy", new Type[] { typeof(HitData) })]
	internal static class TrainingDummyPreventDamageDestructionPatch
	{
		private static bool Prefix(Destructible __instance, HitData __0)
		{
			Character component = ((Component)__instance).GetComponent<Character>();
			if (!((Object)(object)component == (Object)null) && TrainingDummyDpsDisplayPatch.IsTrainingDummy(component))
			{
				return TrainingDummyRemovalContext.IsRemovingPiece;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(WearNTear), "Destroy", new Type[]
	{
		typeof(HitData),
		typeof(bool)
	})]
	internal static class TrainingDummyPreventDamageWearNTearDestructionPatch
	{
		private static bool Prefix(WearNTear __instance, HitData __0)
		{
			Character component = ((Component)__instance).GetComponent<Character>();
			if (!((Object)(object)component == (Object)null) && TrainingDummyDpsDisplayPatch.IsTrainingDummy(component))
			{
				return TrainingDummyRemovalContext.IsRemovingPiece;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Piece), "DropResources", new Type[] { typeof(HitData) })]
	internal static class TrainingDummyDropResourcesPatch
	{
		private static bool Prefix(Piece __instance, HitData __0)
		{
			Character component = ((Component)__instance).GetComponent<Character>();
			if (!((Object)(object)component == (Object)null) && TrainingDummyDpsDisplayPatch.IsTrainingDummy(component))
			{
				return TrainingDummyRemovalContext.IsRemovingPiece;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Character), "RPC_Damage")]
	internal static class TrainingDummyCharacterDpsPatch
	{
		private static bool Prefix(Character __instance, out float __state)
		{
			if (!TrainingDummyDpsDisplayPatch.IsTrainingDummy(__instance))
			{
				__state = float.NaN;
				return true;
			}
			__state = __instance.GetHealth();
			return true;
		}

		private static void Postfix(Character __instance, HitData __1, float __state)
		{
			if (float.IsNaN(__state))
			{
				return;
			}
			float num = __state - __instance.GetHealth();
			if (num <= 0f && __1 != null)
			{
				num = __1.GetTotalDamage();
			}
			if (!(num <= 0f))
			{
				RecordDamage(__instance, num);
				TrainingDummyRegeneration component = ((Component)__instance).GetComponent<TrainingDummyRegeneration>();
				if ((Object)(object)component != (Object)null)
				{
					component.RecordDamage();
				}
			}
		}

		internal static void RecordDamage(Character character, float damage)
		{
			TrainingDummyDpsDisplay trainingDummyDpsDisplay = ((Component)character).GetComponent<TrainingDummyDpsDisplay>();
			if ((Object)(object)trainingDummyDpsDisplay == (Object)null)
			{
				trainingDummyDpsDisplay = ((Component)character).gameObject.AddComponent<TrainingDummyDpsDisplay>();
			}
			trainingDummyDpsDisplay.RecordDamage(damage);
		}
	}
	[HarmonyPatch(typeof(ZNetView), "InvokeRPC", new Type[]
	{
		typeof(string),
		typeof(object[])
	})]
	internal static class TrainingDummyLocalDamageRpcPatch
	{
		private static void Postfix(ZNetView __instance, string __0, object[] __1)
		{
			//IL_0050: 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)
			if (!string.Equals(__0, "RPC_Damage", StringComparison.Ordinal) || __1 == null || __1.Length == 0)
			{
				return;
			}
			Character component = ((Component)__instance).GetComponent<Character>();
			if ((Object)(object)component == (Object)null || !TrainingDummyDpsDisplayPatch.IsTrainingDummy(component) || __instance.IsOwner() || (Object)(object)Player.m_localPlayer == (Object)null)
			{
				return;
			}
			object obj = __1[0];
			HitData val = (HitData)((obj is HitData) ? obj : null);
			if (val != null && !(val.m_attacker != ((Character)Player.m_localPlayer).GetZDOID()))
			{
				float totalDamage = val.GetTotalDamage();
				if (totalDamage > 0f)
				{
					TrainingDummyCharacterDpsPatch.RecordDamage(component, totalDamage);
				}
			}
		}
	}
	internal sealed class TrainingDummyRegeneration : MonoBehaviour
	{
		private const float RegenerationDelaySeconds = 5f;

		private Character _character;

		private float _lastDamageAt = float.NegativeInfinity;

		private void Awake()
		{
			_character = ((Component)this).GetComponent<Character>();
		}

		internal void RecordDamage()
		{
			_lastDamageAt = Time.time;
		}

		private void Update()
		{
			if (!float.IsNegativeInfinity(_lastDamageAt) && !(Time.time - _lastDamageAt < 5f))
			{
				WearNTear component = ((Component)this).GetComponent<WearNTear>();
				if ((Object)(object)component != (Object)null)
				{
					component.Repair();
				}
				_character.SetHealth(_character.GetMaxHealth());
				_lastDamageAt = float.NegativeInfinity;
			}
		}
	}
	internal sealed class TrainingDummyDpsDisplay : MonoBehaviour
	{
		private readonly struct DamageSample
		{
			internal float Time { get; }

			internal float Amount { get; }

			internal DamageSample(float time, float amount)
			{
				Time = time;
				Amount = amount;
			}
		}

		private const float DpsWindowSeconds = 5f;

		private const float IdleResetSeconds = 3f;

		private const float DisplayTimeoutSeconds = 5f;

		private const float RefreshIntervalSeconds = 0.1f;

		private const float MinimumAverageSeconds = 1f;

		private readonly Queue<DamageSample> _samples = new Queue<DamageSample>();

		private TextMesh _label;

		private float _totalDamage;

		private float _windowStartedAt;

		private float _lastDamageAt = float.NegativeInfinity;

		private float _lastActivityAt;

		private float _nextRefreshAt;

		private void Awake()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_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_00d7: Unknown result type (might be due to invalid IL or missing references)
			_lastActivityAt = Time.time;
			Font builtinResource = Resources.GetBuiltinResource<Font>("Arial.ttf");
			if ((Object)(object)builtinResource == (Object)null)
			{
				builtinResource = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
			}
			if ((Object)(object)builtinResource == (Object)null)
			{
				RandomBullshitPlugin.LogError("Could not create the T.W.I.G. DPS label because Unity's built-in font could not be loaded.");
				return;
			}
			GameObject val = new GameObject("RandomBullshit.TwigDps");
			val.transform.SetParent(((Component)this).transform, false);
			val.transform.localPosition = Vector3.up * 3f;
			_label = val.AddComponent<TextMesh>();
			_label.font = builtinResource;
			_label.fontSize = 64;
			_label.characterSize = 0.06f;
			_label.anchor = (TextAnchor)4;
			_label.alignment = (TextAlignment)1;
			_label.color = new Color(1f, 0.92f, 0.68f);
			_label.text = "0";
			RandomBullshitPlugin.LogInfo("Attached DPS label to a training dummy.");
		}

		private void LateUpdate()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_label == (Object)null))
			{
				Camera main = Camera.main;
				if ((Object)(object)main != (Object)null)
				{
					((Component)_label).transform.rotation = ((Component)main).transform.rotation;
				}
			}
		}

		private void Update()
		{
			float time = Time.time;
			if (time - _lastDamageAt >= 3f && !float.IsNegativeInfinity(_lastDamageAt))
			{
				_samples.Clear();
				_totalDamage = 0f;
				_lastDamageAt = float.NegativeInfinity;
				_windowStartedAt = time;
			}
			while (_samples.Count > 0 && time - _samples.Peek().Time > 5f)
			{
				_totalDamage -= _samples.Dequeue().Amount;
			}
			if ((Object)(object)_label != (Object)null && time >= _nextRefreshAt)
			{
				_label.text = $"{GetDps(time):F0}";
				((Component)_label).gameObject.SetActive(time - _lastActivityAt < 5f);
				_nextRefreshAt = time + 0.1f;
			}
		}

		internal void RecordDamage(float amount)
		{
			float time = Time.time;
			if (time - _lastDamageAt >= 3f)
			{
				_samples.Clear();
				_totalDamage = 0f;
				_windowStartedAt = time;
			}
			_samples.Enqueue(new DamageSample(time, amount));
			_totalDamage += amount;
			_lastDamageAt = time;
			_lastActivityAt = time;
		}

		private float GetDps(float now)
		{
			if (_lastDamageAt == float.NegativeInfinity)
			{
				return 0f;
			}
			float num = now - _windowStartedAt;
			float num2 = Mathf.Min(5f, Mathf.Max(1f, num));
			return _totalDamage / num2;
		}
	}
	internal static class TrainingWithMexicanitoPiece
	{
		private const string VanillaPrefabName = "piece_TrainingDummy";

		internal const string PrefabName = "piece_TWMTrainingDummy";

		internal static GameObject Prefab { get; private set; }

		internal static void Register()
		{
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			GameObject val = PrefabManager.Instance.CreateClonedPrefab("piece_TWMTrainingDummy", "piece_TrainingDummy");
			if ((Object)(object)val == (Object)null)
			{
				RandomBullshitPlugin.LogError("Could not create TWM because the vanilla prefab 'piece_TrainingDummy' was not found.");
				return;
			}
			Prefab = val;
			val.AddComponent<TwmTrainingDummyMarker>();
			Piece component = val.GetComponent<Piece>();
			if ((Object)(object)component == (Object)null)
			{
				RandomBullshitPlugin.LogError("Could not register TWM because prefab 'piece_TrainingDummy' has no Piece component.");
				Object.Destroy((Object)(object)val);
				return;
			}
			component.m_canBeRemoved = true;
			component.m_name = "$piece_TWMTrainingDummy";
			component.m_description = "A stationary training dummy for practicing attacks.";
			Character component2 = val.GetComponent<Character>();
			if ((Object)(object)component2 == (Object)null)
			{
				RandomBullshitPlugin.LogError("Could not set the TWM dummy's in-world name because its Character component was not found.");
				Object.Destroy((Object)(object)val);
				return;
			}
			component2.m_name = "$piece_TWMTrainingDummy";
			if ((Object)(object)val.GetComponent<TrainingDummyRegeneration>() == (Object)null)
			{
				val.AddComponent<TrainingDummyRegeneration>();
			}
			BaseAI[] componentsInChildren = val.GetComponentsInChildren<BaseAI>(true);
			BaseAI[] array = componentsInChildren;
			for (int i = 0; i < array.Length; i++)
			{
				((Behaviour)array[i]).enabled = false;
			}
			if (componentsInChildren.Length == 0)
			{
				RandomBullshitPlugin.LogInfo("TWM prefab has no AI components to disable.");
			}
			else
			{
				RandomBullshitPlugin.LogInfo($"Disabled {componentsInChildren.Length} AI component(s) on TWM.");
			}
			CustomPiece val2 = new CustomPiece(val, "Hammer", false);
			if (!PieceManager.Instance.AddPiece(val2))
			{
				RandomBullshitPlugin.LogError("Jötunn could not add TWM to the hammer build menu.");
				Object.Destroy((Object)(object)val);
			}
			else
			{
				RandomBullshitPlugin.LogInfo("Registered TWM (Training with Mexicanito) in the hammer build menu.");
			}
		}
	}
	internal sealed class TwmTrainingDummyMarker : MonoBehaviour
	{
	}
}