Decompiled source of IndigosMod v0.1.0

plugins/IndigosMod/IndigosMod.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.scoare.IndigosMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("com.github.scoare.IndigosMod")]
[assembly: AssemblyTitle("IndigosMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace IndigosMod
{
	[BepInPlugin("scoare.IndigosMod", "Indigo's Mod", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private class Patcher
		{
			public static bool CreateHatOption(Customization customization, string name, Texture2D icon)
			{
				//IL_0049: 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_0069: 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)
				string name2 = name;
				if (Array.Exists(customization.hats, (CustomizationOption hat) => ((Object)hat).name == name2))
				{
					Debug.LogError((object)("[IndigosMod] Trying to add " + name2 + " a second time."));
					return false;
				}
				CustomizationOption val = ScriptableObject.CreateInstance<CustomizationOption>();
				val.color = Color.white;
				((Object)val).name = name2;
				val.texture = (Texture)(object)icon;
				val.type = (Type)50;
				val.requiredAchievement = (ACHIEVEMENTTYPE)0;
				customization.hats = CollectionExtensions.AddToArray<CustomizationOption>(customization.hats, val);
				Debug.Log((object)("[IndigosMod] " + name2 + " added."));
				return true;
			}

			[HarmonyPatch(typeof(PassportManager), "Awake")]
			[HarmonyPostfix]
			public static void PassportManagerAwakePostfix(PassportManager __instance)
			{
				Customization component = ((Component)__instance).GetComponent<Customization>();
				Debug.Log((object)"[IndigosMod] Removing CustomHats hats.");
				component.hats = component.hats.Where((CustomizationOption hat) => !(((Object)hat).name == "Hat_GhostMask") && !(((Object)hat).name == "Hat_CreeperHat") && !(((Object)hat).name == "Hat_Wat")).ToArray();
				Debug.Log((object)"[IndigosMod] Adding hat CustomizationOptions.");
				for (int i = 0; i < hats.Count; i++)
				{
					HatEntry hatEntry = hats[i];
					CreateHatOption(component, hatEntry.Name, hatEntry.Icon);
				}
				Debug.Log((object)"[IndigosMod] Done.");
			}

			[HarmonyPatch(typeof(CharacterCustomization), "Awake")]
			[HarmonyPostfix]
			public static void CharacterCustomizationAwakePostfix(CharacterCustomization __instance)
			{
				//IL_005e: 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)
				Transform child = ((Component)__instance).transform.GetChild(0).GetChild(0).GetChild(0)
					.GetChild(2)
					.GetChild(0)
					.GetChild(0)
					.GetChild(1)
					.GetChild(1);
				Debug.Log((object)$"[IndigosMod] Instanciating hats as children of {child}.");
				for (int i = 0; i < hats.Count; i++)
				{
					GameObject val = Object.Instantiate<GameObject>(hats[i].Prefab, child.position, child.rotation, child);
					Renderer componentInChildren = val.GetComponentInChildren<Renderer>();
					((Component)componentInChildren).gameObject.SetActive(false);
					if (i <= 2)
					{
						__instance.refs.playerHats[i + 27] = componentInChildren;
					}
					else
					{
						__instance.refs.playerHats = CollectionExtensions.AddToArray<Renderer>(__instance.refs.playerHats, componentInChildren);
					}
				}
			}

			[HarmonyPatch(typeof(CharacterCustomization), "OnPlayerDataChange")]
			[HarmonyPostfix]
			public static void CharacterCustomization_OnPlayerDataChange_Patch(CharacterCustomization __instance, PersistentPlayerData playerData)
			{
				foreach (Character allCharacter in Character.AllCharacters)
				{
					Renderer[] componentsInChildren = ((Component)allCharacter).GetComponentsInChildren<Renderer>();
					foreach (Renderer val in componentsInChildren)
					{
						if (((Object)((Component)val).gameObject).name.StartsWith("Indigo_"))
						{
							val.material = ((Renderer)__instance.refs.mainRenderer).material;
						}
					}
				}
			}
		}

		public struct HatEntry
		{
			public string Name;

			public GameObject Prefab;

			public Texture2D Icon;

			public HatEntry(string name, GameObject prefab, Texture2D icon)
			{
				Name = name;
				Prefab = prefab;
				Icon = icon;
			}
		}

		[CompilerGenerated]
		private sealed class <LoadHatsFromDisk>d__4 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			private AssetBundleCreateRequest <createRequest>5__2;

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

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

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

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

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
				{
					<>1__state = -1;
					Debug.Log((object)"[IndigosMod] Loading hats from disk.");
					string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
					string text = Path.Combine(directoryName, "indigosmod.assetbundle");
					Debug.Log((object)("[IndigosMod] Path to AssetBundle: " + text));
					<createRequest>5__2 = AssetBundle.LoadFromMemoryAsync(File.ReadAllBytes(text));
					<>2__current = <createRequest>5__2;
					<>1__state = 1;
					return true;
				}
				case 1:
					<>1__state = -1;
					assetBundle = <createRequest>5__2.assetBundle;
					Debug.Log((object)"[IndigosMod] AssetBundle loaded.");
					hats = new List<HatEntry>();
					hats.Add(LoadHat("spikyPony"));
					Debug.Log((object)"[IndigosMod] Done!");
					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();
			}
		}

		public static AssetBundle assetBundle;

		public static List<HatEntry> hats;

		public void Awake()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("scoare.IndigosMod").PatchAll(typeof(Patcher));
			((MonoBehaviour)this).StartCoroutine(LoadHatsFromDisk());
		}

		[IteratorStateMachine(typeof(<LoadHatsFromDisk>d__4))]
		private static IEnumerator LoadHatsFromDisk()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <LoadHatsFromDisk>d__4(0);
		}

		private static HatEntry LoadHat(string hatName)
		{
			Debug.Log((object)("[IndigosMod] Loading hat '" + hatName + "'."));
			GameObject val = assetBundle.LoadAsset<GameObject>("Assets/" + hatName + ".prefab");
			Texture2D val2 = assetBundle.LoadAsset<Texture2D>("Assets/" + hatName + ".png");
			Debug.Log((object)$"[IndigosMod] Loaded prefab {val} and texture {val2}");
			return new HatEntry(hatName, val, val2);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}