Decompiled source of Hatify v1.1.1

Hatify.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using On.RoR2;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Hatify")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+741ed8320cf798ada4dbefaafd7af189c18f6cc9")]
[assembly: AssemblyProduct("Hatify")]
[assembly: AssemblyTitle("Hatify")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 Hatify
{
	[BepInPlugin("com.Nuxlar.Hatify", "Hatify", "1.1.1")]
	public class Hatify : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <HatifyThese>d__23 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public CharacterModel model;

			public Hatify <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <HatifyThese>d__23(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Expected O, but got Unknown
				//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_06fc: Unknown result type (might be due to invalid IL or missing references)
				//IL_06fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0afe: Unknown result type (might be due to invalid IL or missing references)
				//IL_0aff: Unknown result type (might be due to invalid IL or missing references)
				//IL_0a4d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0a4e: Unknown result type (might be due to invalid IL or missing references)
				//IL_085e: Unknown result type (might be due to invalid IL or missing references)
				//IL_085f: Unknown result type (might be due to invalid IL or missing references)
				//IL_05a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_05a1: Unknown result type (might be due to invalid IL or missing references)
				//IL_0761: Unknown result type (might be due to invalid IL or missing references)
				//IL_0771: Unknown result type (might be due to invalid IL or missing references)
				//IL_0785: Unknown result type (might be due to invalid IL or missing references)
				//IL_0b54: Unknown result type (might be due to invalid IL or missing references)
				//IL_0b64: Unknown result type (might be due to invalid IL or missing references)
				//IL_0b78: Unknown result type (might be due to invalid IL or missing references)
				//IL_0444: Unknown result type (might be due to invalid IL or missing references)
				//IL_0445: Unknown result type (might be due to invalid IL or missing references)
				//IL_08fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_08fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_0aa6: Unknown result type (might be due to invalid IL or missing references)
				//IL_0ab6: Unknown result type (might be due to invalid IL or missing references)
				//IL_0aca: Unknown result type (might be due to invalid IL or missing references)
				//IL_08a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_08b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_08c9: Unknown result type (might be due to invalid IL or missing references)
				//IL_05f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0609: Unknown result type (might be due to invalid IL or missing references)
				//IL_061d: Unknown result type (might be due to invalid IL or missing references)
				//IL_099c: Unknown result type (might be due to invalid IL or missing references)
				//IL_099d: Unknown result type (might be due to invalid IL or missing references)
				//IL_029e: Unknown result type (might be due to invalid IL or missing references)
				//IL_029f: Unknown result type (might be due to invalid IL or missing references)
				//IL_036b: Unknown result type (might be due to invalid IL or missing references)
				//IL_036c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0497: Unknown result type (might be due to invalid IL or missing references)
				//IL_04a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0651: Unknown result type (might be due to invalid IL or missing references)
				//IL_0652: Unknown result type (might be due to invalid IL or missing references)
				//IL_0944: Unknown result type (might be due to invalid IL or missing references)
				//IL_0954: Unknown result type (might be due to invalid IL or missing references)
				//IL_0968: Unknown result type (might be due to invalid IL or missing references)
				//IL_04ef: Unknown result type (might be due to invalid IL or missing references)
				//IL_04f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_09f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_0a05: Unknown result type (might be due to invalid IL or missing references)
				//IL_0a19: Unknown result type (might be due to invalid IL or missing references)
				//IL_07b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_07ba: Unknown result type (might be due to invalid IL or missing references)
				//IL_030f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0323: Unknown result type (might be due to invalid IL or missing references)
				//IL_0337: Unknown result type (might be due to invalid IL or missing references)
				//IL_06a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_06b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_06c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_0548: Unknown result type (might be due to invalid IL or missing references)
				//IL_0558: Unknown result type (might be due to invalid IL or missing references)
				//IL_056c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0806: Unknown result type (might be due to invalid IL or missing references)
				//IL_0816: Unknown result type (might be due to invalid IL or missing references)
				//IL_082a: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
				//IL_03fc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0410: Unknown result type (might be due to invalid IL or missing references)
				int num = <>1__state;
				Hatify hatify = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForFixedUpdate();
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if (Object.op_Implicit((Object)(object)model.body))
					{
						GameObject val = null;
						Vector3 zero = Vector3.zero;
						switch (((Object)model.body).name)
						{
						case "Bandit2Body(Clone)":
							if (((Component)model).GetComponent<ModelSkinController>().currentSkinIndex == 2)
							{
								((Vector3)(ref zero))..ctor(banditSize.Value, banditSize.Value, banditSize.Value);
								if (zero != Vector3.zero)
								{
									val = Object.Instantiate<GameObject>(hatify.hat, ((Component)model).transform.GetChild(4).GetChild(2).GetChild(0)
										.GetChild(6)
										.GetChild(0)
										.GetChild(2));
									hatify.SetupHat(val, model, new Vector3(banditSize.Value, banditSize.Value, banditSize.Value), new Vector3(0f, 0.15f, 0f), new Vector3(10f, 0f, 0f));
								}
							}
							break;
						case "CaptainBody(Clone)":
							((Vector3)(ref zero))..ctor(captainSize.Value, captainSize.Value, captainSize.Value);
							if (zero != Vector3.zero)
							{
								Transform child = ((Component)model).transform.GetChild(1).GetChild(0).GetChild(0)
									.GetChild(2)
									.GetChild(0)
									.GetChild(2)
									.GetChild(0);
								Transform val2 = child.Find("CaptainHat");
								if (Object.op_Implicit((Object)(object)val2))
								{
									((Component)val2).gameObject.SetActive(false);
								}
								val = Object.Instantiate<GameObject>(hatify.hat, child);
								hatify.SetupHat(val, model, zero, new Vector3(0f, 0.15f, 0f), new Vector3(15f, 0f, 0f));
							}
							break;
						case "CommandoBody(Clone)":
							((Vector3)(ref zero))..ctor(commandoSize.Value, commandoSize.Value, commandoSize.Value);
							if (zero != Vector3.zero)
							{
								val = Object.Instantiate<GameObject>(hatify.hat, ((Component)model).transform.GetChild(0).GetChild(0).GetChild(0)
									.GetChild(3)
									.GetChild(0)
									.GetChild(0));
								hatify.SetupHat(val, model, zero, new Vector3(0f, 0.3f, 0f), new Vector3(15f, 0f, 0f));
							}
							break;
						case "RailgunnerBody(Clone)":
							((Vector3)(ref zero))..ctor(railgunnerSize.Value, railgunnerSize.Value, railgunnerSize.Value);
							if (zero != Vector3.zero)
							{
								val = Object.Instantiate<GameObject>(hatify.hat, ((Component)model).transform.GetChild(5).GetChild(0).GetChild(0)
									.GetChild(2)
									.GetChild(1)
									.GetChild(2)
									.GetChild(0));
								hatify.SetupHat(val, model, zero, new Vector3(0f, 0.175f, -0.025f), new Vector3(30f, 0f, 0f));
							}
							break;
						case "MageBody(Clone)":
							((Vector3)(ref zero))..ctor(artiSize.Value, artiSize.Value, artiSize.Value);
							if (zero != Vector3.zero)
							{
								val = Object.Instantiate<GameObject>(hatify.hat, ((Component)model).transform.GetChild(0).GetChild(2).GetChild(0)
									.GetChild(3)
									.GetChild(0)
									.GetChild(2)
									.GetChild(0));
								hatify.SetupHat(val, model, zero, new Vector3(0f, 0.15f, -0.1f), new Vector3(15f, 0f, 0f));
							}
							break;
						case "HuntressBody(Clone)":
							((Vector3)(ref zero))..ctor(huntressSize.Value, huntressSize.Value, huntressSize.Value);
							if (zero != Vector3.zero)
							{
								val = Object.Instantiate<GameObject>(hatify.hat, ((Component)model).transform.GetChild(2).GetChild(3).GetChild(0)
									.GetChild(2)
									.GetChild(0)
									.GetChild(1));
								hatify.SetupHat(val, model, zero, new Vector3(0f, 0.3f, -0.05f), new Vector3(15f, 0f, 0f));
							}
							break;
						case "CrocoBody(Clone)":
							((Vector3)(ref zero))..ctor(acridSize.Value, acridSize.Value, acridSize.Value);
							if (zero != Vector3.zero)
							{
								val = Object.Instantiate<GameObject>(hatify.hat, ((Component)model).transform.GetChild(5).GetChild(0).GetChild(0)
									.GetChild(2)
									.GetChild(0)
									.GetChild(2)
									.GetChild(0)
									.GetChild(0)
									.GetChild(0));
								hatify.SetupHat(val, model, zero, new Vector3(0f, 0f, 1.6f), new Vector3(55f, 180f, 180f));
							}
							break;
						case "EngiBody(Clone)":
							((Vector3)(ref zero))..ctor(engiSize.Value, engiSize.Value, engiSize.Value);
							if (zero != Vector3.zero)
							{
								val = Object.Instantiate<GameObject>(hatify.hat, ((Component)model).transform.GetChild(0).GetChild(2).GetChild(0)
									.GetChild(3)
									.GetChild(0));
								hatify.SetupHat(val, model, zero, new Vector3(0f, 0.65f, 0f), new Vector3(15f, 0f, 0f));
							}
							break;
						case "EngiWalkerTurretBody(Clone)":
							((Vector3)(ref zero))..ctor(engiWalkerTurretSize.Value, engiWalkerTurretSize.Value, engiWalkerTurretSize.Value);
							if (zero != Vector3.zero)
							{
								val = Object.Instantiate<GameObject>(hatify.hat, ((Component)model).transform.GetChild(1).GetChild(0).GetChild(4)
									.GetChild(0));
								hatify.SetupHat(val, model, zero, new Vector3(0f, 1f, 0f), new Vector3(15f, 0f, 0f));
							}
							break;
						case "EngiTurretBody(Clone)":
							((Vector3)(ref zero))..ctor(engiTurretSize.Value, engiTurretSize.Value, engiTurretSize.Value);
							if (zero != Vector3.zero)
							{
								val = Object.Instantiate<GameObject>(hatify.hat, ((Component)model).transform.GetChild(1).GetChild(0).GetChild(4)
									.GetChild(0));
								hatify.SetupHat(val, model, zero, new Vector3(0f, 0.3f, 0f), new Vector3(15f, 0f, 0f));
							}
							break;
						case "MercBody(Clone)":
							((Vector3)(ref zero))..ctor(mercSize.Value, mercSize.Value, mercSize.Value);
							if (zero != Vector3.zero)
							{
								val = Object.Instantiate<GameObject>(hatify.hat, ((Component)model).transform.GetChild(0).GetChild(2).GetChild(0)
									.GetChild(3)
									.GetChild(0)
									.GetChild(3)
									.GetChild(1));
								hatify.SetupHat(val, model, zero, new Vector3(0f, 0.2f, 0f), new Vector3(15f, 0f, 0f));
							}
							break;
						case "VoidSurvivorBody(Clone)":
							((Vector3)(ref zero))..ctor(fiendSize.Value, fiendSize.Value, fiendSize.Value);
							if (zero != Vector3.zero)
							{
								val = Object.Instantiate<GameObject>(hatify.hat, ((Component)model).transform.GetChild(7).GetChild(0).GetChild(0)
									.GetChild(1)
									.GetChild(2)
									.GetChild(2)
									.GetChild(0));
								hatify.SetupHat(val, model, zero, new Vector3(0f, 0.1f, 0f), new Vector3(15f, 0f, 0f));
							}
							break;
						case "LoaderBody(Clone)":
							((Vector3)(ref zero))..ctor(loaderSize.Value, loaderSize.Value, loaderSize.Value);
							if (zero != Vector3.zero)
							{
								val = Object.Instantiate<GameObject>(hatify.hat, ((Component)model).transform.GetChild(0).GetChild(0).GetChild(0)
									.GetChild(5)
									.GetChild(0)
									.GetChild(3)
									.GetChild(0));
								hatify.SetupHat(val, model, zero, new Vector3(0f, 0.2f, 0f), new Vector3(15f, 0f, 0f));
							}
							break;
						}
					}
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private Material hatMat = Addressables.LoadAssetAsync<Material>((object)"RoR2/Base/Commando/matCommandoDualies.mat").WaitForCompletion();

		private GameObject hat = ((Component)Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Bandit2/mdlBandit2.fbx").WaitForCompletion().transform.GetChild(4).GetChild(2).GetChild(0)
			.GetChild(6)
			.GetChild(0)
			.GetChild(2)
			.GetChild(0)).gameObject;

		private Material banditHatMat = Addressables.LoadAssetAsync<Material>((object)"RoR2/Base/Bandit2/matBandit2AltColossus.mat").WaitForCompletion();

		public static ConfigEntry<float> commandoSize;

		public static ConfigEntry<float> banditSize;

		public static ConfigEntry<float> huntressSize;

		public static ConfigEntry<float> engiSize;

		public static ConfigEntry<float> engiTurretSize;

		public static ConfigEntry<float> engiWalkerTurretSize;

		public static ConfigEntry<float> artiSize;

		public static ConfigEntry<float> mercSize;

		public static ConfigEntry<float> loaderSize;

		public static ConfigEntry<float> acridSize;

		public static ConfigEntry<float> captainSize;

		public static ConfigEntry<float> railgunnerSize;

		public static ConfigEntry<float> fiendSize;

		private static ConfigFile HatifyConfig { get; set; }

		public void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Expected O, but got Unknown
			HatifyConfig = new ConfigFile(Paths.ConfigPath + "\\com.Nuxlar.Hatify.cfg", true);
			commandoSize = HatifyConfig.Bind<float>("General", "Commando Hat Size", 1.3f, "The scale of the hat.");
			banditSize = HatifyConfig.Bind<float>("General", "Bandit Hat Size", 1f, "The scale of the hat.");
			huntressSize = HatifyConfig.Bind<float>("General", "Huntress Hat Size", 1.3f, "The scale of the hat.");
			engiSize = HatifyConfig.Bind<float>("General", "Engi Hat Size", 1.6f, "The scale of the hat.");
			engiTurretSize = HatifyConfig.Bind<float>("General", "Engi Turret Hat Size", 10f, "The scale of the hat.");
			engiWalkerTurretSize = HatifyConfig.Bind<float>("General", "Engi Walker Turret Hat Size", 8f, "The scale of the hat.");
			artiSize = HatifyConfig.Bind<float>("General", "Artificer Hat Size", 1f, "The scale of the hat.");
			mercSize = HatifyConfig.Bind<float>("General", "Merc Hat Size", 1.4f, "The scale of the hat.");
			loaderSize = HatifyConfig.Bind<float>("General", "Loader Hat Size", 1.5f, "The scale of the hat.");
			acridSize = HatifyConfig.Bind<float>("General", "Acrid Hat Size", 15f, "The scale of the hat.");
			captainSize = HatifyConfig.Bind<float>("General", "Captain Hat Size", 1.3f, "The scale of the hat.");
			railgunnerSize = HatifyConfig.Bind<float>("General", "Railgunner Hat Size", 1f, "The scale of the hat.");
			fiendSize = HatifyConfig.Bind<float>("General", "Fiend Hat Size", 1.4f, "The scale of the hat.");
			CharacterModel.Start += new hook_Start(CharacterModel_Start);
		}

		private void CharacterModel_Start(orig_Start orig, CharacterModel self)
		{
			orig.Invoke(self);
			((MonoBehaviour)self).StartCoroutine(HatifyThese(self));
		}

		private void SetupHat(GameObject hat, CharacterModel model, Vector3 size, Vector3 localPos, Vector3 rotation)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			Material material = ((((Object)model.body).name == "Bandit2Body(Clone)") ? banditHatMat : hatMat);
			hat.AddComponent<NetworkIdentity>();
			hat.transform.localScale = size;
			hat.transform.localPosition = localPos;
			hat.transform.Rotate(rotation);
			((Renderer)((Component)hat.transform.GetChild(0)).GetComponent<MeshRenderer>()).material = material;
			List<RendererInfo> list = model.baseRendererInfos.ToList();
			Renderer[] componentsInChildren = hat.GetComponentsInChildren<Renderer>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Renderer val = componentsInChildren[i];
				list.Add(new RendererInfo
				{
					renderer = val,
					defaultMaterial = val.sharedMaterial,
					defaultShadowCastingMode = val.shadowCastingMode,
					hideOnDeath = false,
					ignoreOverlays = false
				});
				val = null;
			}
			componentsInChildren = null;
			model.baseRendererInfos = list.ToArray();
			list = null;
		}

		[IteratorStateMachine(typeof(<HatifyThese>d__23))]
		private IEnumerator HatifyThese(CharacterModel model)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <HatifyThese>d__23(0)
			{
				<>4__this = this,
				model = model
			};
		}
	}
}