Decompiled source of NoMoreRatCostume v1.0.2

NoMoreRatCostume.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Alexandria.ItemAPI;
using Alexandria.cAPI;
using BepInEx;
using Gunfiguration;
using MonoMod.RuntimeDetour;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("NoMoreRatCostume")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NoMoreRatCostume")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("28c737d6-250c-4c63-a7bd-4e4e0734e044")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace NoMoreRatCostume;

public static class Hooks
{
	private static string hatName = "RatHat";

	private static string previousHatName = null;

	private static bool isHatRestored = false;

	internal static Gunfig _Gunfig = null;

	internal const string DISABLE_COSTUME = "Disable R.R. Costume On Active Synergy";

	internal const string ENABLE_RATHAT = "Enable Tiny Rat Hat for Alternative Costume";

	public static tk2dSpriteCollectionData RatHatCollection;

	public static void Init()
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Expected O, but got Unknown
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		Hook val = new Hook((MethodBase)typeof(RatBootsItem).GetMethod("ProcessRatStatus", BindingFlags.Instance | BindingFlags.NonPublic), typeof(Hooks).GetMethod("DisableOverrideAnimation", BindingFlags.Static | BindingFlags.NonPublic));
		InitRatHat();
		_Gunfig = Gunfig.Get(GunfigHelpers.WithColor("NoMoreRatCostume", Color.white));
		_Gunfig.AddToggle("Disable R.R. Costume On Active Synergy", true, (string)null, (Action<string, string>)null, (Update)0);
		_Gunfig.AddToggle("Enable Tiny Rat Hat for Alternative Costume", false, (string)null, (Action<string, string>)null, (Update)0);
	}

	private static void DisableOverrideAnimation(Action<RatBootsItem, PlayerController, bool> orig, RatBootsItem self, PlayerController player, bool forceDisable)
	{
		orig(self, player, forceDisable);
		if (!Object.op_Implicit((Object)(object)player))
		{
			return;
		}
		bool flag = player.HasActiveBonusSynergy((CustomSynergyType)274, false);
		FieldInfo field = typeof(RatBootsItem).GetField("m_transformed", BindingFlags.Instance | BindingFlags.NonPublic);
		bool flag2 = (object)field != null && (bool)field.GetValue(self);
		if (flag && flag2)
		{
			if (_Gunfig.Enabled("Disable R.R. Costume On Active Synergy") && (Object)(object)player.OverrideAnimationLibrary != (Object)null && ((Object)player.OverrideAnimationLibrary).name == ((Object)self.RatAnimationLibrary).name)
			{
				player.OverrideAnimationLibrary = null;
			}
			else if (!_Gunfig.Enabled("Disable R.R. Costume On Active Synergy") && (Object)(object)player.OverrideAnimationLibrary == (Object)null)
			{
				player.OverrideAnimationLibrary = self.RatAnimationLibrary;
			}
			if (_Gunfig.Enabled("Disable R.R. Costume On Active Synergy") && _Gunfig.Enabled("Enable Tiny Rat Hat for Alternative Costume"))
			{
				HatController orAddComponent = GameObjectExtensions.GetOrAddComponent<HatController>(((Component)player).gameObject);
				if ((Object)(object)orAddComponent != (Object)null && (Object)(object)orAddComponent.CurrentHat == (Object)null)
				{
					ETGModConsole.Log((object)"Wearing RatHat", false);
					previousHatName = null;
					((Behaviour)orAddComponent).enabled = true;
					Hatabase.Hats.TryGetValue(HatUtility.GetDatabaseFriendlyHatName(hatName), out var value);
					orAddComponent.SetHat(value);
				}
				else if ((Object)(object)orAddComponent != (Object)null && (Object)(object)orAddComponent.CurrentHat != (Object)null && orAddComponent.CurrentHat.hatName != hatName)
				{
					ETGModConsole.Log((object)("Replacing RatHat with " + orAddComponent.CurrentHat.hatName), false);
					previousHatName = orAddComponent.CurrentHat.hatName;
					orAddComponent.RemoveCurrentHat();
					((Behaviour)orAddComponent).enabled = true;
					Hatabase.Hats.TryGetValue(HatUtility.GetDatabaseFriendlyHatName(hatName), out var value2);
					orAddComponent.SetHat(value2);
					isHatRestored = false;
				}
			}
			else if (_Gunfig.Enabled("Disable R.R. Costume On Active Synergy") && !_Gunfig.Enabled("Enable Tiny Rat Hat for Alternative Costume"))
			{
				HatController orAddComponent2 = GameObjectExtensions.GetOrAddComponent<HatController>(((Component)player).gameObject);
				if ((Object)(object)orAddComponent2 != (Object)null && (Object)(object)orAddComponent2.CurrentHat != (Object)null && previousHatName != null && !isHatRestored)
				{
					ETGModConsole.Log((object)("Replacing " + orAddComponent2.CurrentHat.hatName + " with RatHat"), false);
					orAddComponent2.RemoveCurrentHat();
					((Behaviour)orAddComponent2).enabled = true;
					Hatabase.Hats.TryGetValue(HatUtility.GetDatabaseFriendlyHatName(previousHatName), out var value3);
					orAddComponent2.SetHat(value3);
					isHatRestored = true;
				}
				else if ((Object)(object)orAddComponent2 != (Object)null && (Object)(object)orAddComponent2.CurrentHat != (Object)null && previousHatName == null && orAddComponent2.CurrentHat.hatName == hatName)
				{
					ETGModConsole.Log((object)"Removing RatHat", false);
					((Behaviour)orAddComponent2).enabled = false;
					orAddComponent2.RemoveCurrentHat();
				}
			}
		}
		else
		{
			HatController orAddComponent3 = GameObjectExtensions.GetOrAddComponent<HatController>(((Component)player).gameObject);
			if ((Object)(object)orAddComponent3 != (Object)null && (Object)(object)orAddComponent3.CurrentHat != (Object)null && orAddComponent3.CurrentHat.hatName == hatName)
			{
				ETGModConsole.Log((object)"Removing RatHat", false);
				((Behaviour)orAddComponent3).enabled = false;
				orAddComponent3.RemoveCurrentHat();
			}
			if ((Object)(object)orAddComponent3 != (Object)null && previousHatName != null)
			{
				ETGModConsole.Log((object)("Wearing " + previousHatName + " again"), false);
				((Behaviour)orAddComponent3).enabled = true;
				Hatabase.Hats.TryGetValue(HatUtility.GetDatabaseFriendlyHatName(previousHatName), out var value4);
				orAddComponent3.SetHat(value4);
				previousHatName = null;
				isHatRestored = false;
			}
		}
	}

	private static void InitRatHat()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Expected O, but got Unknown
		//IL_01ac: 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_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Expected O, but got Unknown
		//IL_029c: 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_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Expected O, but got Unknown
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_026a: Expected O, but got Unknown
		RatHatCollection = SpriteBuilder.ConstructCollection(new GameObject(), "RatHatCollection", false);
		string path = "NoMoreRatCostume/Resources";
		int num = 0;
		int num2 = 0;
		int num3 = 4;
		float num4 = 1f;
		float num5 = 1f;
		bool value = false;
		List<tk2dSpriteDefinition> list = new List<tk2dSpriteDefinition>();
		string text = "Brave/PlayerShader";
		Shader val = ShaderCache.Acquire(text);
		Material val2 = null;
		if ((Object)(object)val != (Object)null)
		{
			val2 = new Material(val);
		}
		List<Tuple<string, string>> list2 = new List<Tuple<string, string>>
		{
			new Tuple<string, string>(Path.Combine(path, "ratbud_idle_back.png"), ETGMod.ToID(hatName) + "_north_001"),
			new Tuple<string, string>(Path.Combine(path, "ratbud_idle_front.png"), ETGMod.ToID(hatName) + "_south_001"),
			new Tuple<string, string>(Path.Combine(path, "ratbud_idle_left.png"), ETGMod.ToID(hatName) + "_west_001"),
			new Tuple<string, string>(Path.Combine(path, "ratbud_idle_right.png"), ETGMod.ToID(hatName) + "_east_001"),
			new Tuple<string, string>(Path.Combine(path, "ratbud_idle_back_left.png"), ETGMod.ToID(hatName) + "_northwest_001"),
			new Tuple<string, string>(Path.Combine(path, "ratbud_idle_back_right.png"), ETGMod.ToID(hatName) + "_northeast_001")
		};
		foreach (Tuple<string, string> item in list2)
		{
			string first = item.First;
			string second = item.Second;
			byte[] array = ResourceExtractor.ExtractEmbeddedResource(first, Assembly.GetCallingAssembly());
			Texture2D val3 = new Texture2D(1, 1, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)0,
				name = second
			};
			ImageConversion.LoadImage(val3, array);
			int num6 = SpriteBuilder.AddSpriteToCollection(val3, RatHatCollection, "");
			tk2dSpriteDefinition val4 = RatHatCollection.spriteDefinitions[num6];
			if ((Object)(object)val2 != (Object)null)
			{
				if ((Object)(object)val4.material != (Object)null)
				{
					val4.material = new Material(val2)
					{
						mainTexture = val4.material.mainTexture
					};
				}
				if ((Object)(object)val4.materialInst != (Object)null)
				{
					val4.materialInst = new Material(val2)
					{
						mainTexture = val4.material.mainTexture
					};
				}
			}
			list.Add(val4);
		}
		Hat val5 = HatUtility.SetupHat(hatName, (List<string>)null, (IntVector2?)new IntVector2(num, num2), num3, (HatAttachLevel)0, (HatDepthType)0, (HatRollReaction)0, (string)null, (string)null, num4, num5, (bool?)value, true, (List<GungeonFlags>)null, (List<DungeonPrerequisite>)null, (string)null, false);
		((Component)val5).gameObject.SetActive(true);
		HatUtility.SetupHatSprites(val5, (List<string>)null, list, num3, (Assembly)null);
		((Component)val5).gameObject.SetActive(false);
	}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("wgowl.etg.nomoreratcostume", "NoMoreRatCostume", "1.0.2")]
public class Module : BaseUnityPlugin
{
	private const string GUID = "wgowl.etg.nomoreratcostume";

	private const string NAME = "NoMoreRatCostume";

	private const string VERSION = "1.0.2";

	public void Awake()
	{
		ETGModMainBehaviour.WaitForGameManagerStart((Action<GameManager>)GMStart);
	}

	public void GMStart(GameManager gm)
	{
		Hooks.Init();
	}
}