Decompiled source of MoreCompanySuitPreview v1.0.1

MoreCompanySuitPreview.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("MoreCompanySuitPreview")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("MoreCompanySuitPreview")]
[assembly: AssemblyTitle("MoreCompanySuitPreview")]
[assembly: AssemblyVersion("1.0.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 MoreCompanySuitPreview
{
	[BepInPlugin("MoreCompanySuitPreview", "MoreCompanySuitPreview", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private const string MoreCompanyGuid = "me.swipez.melonloader.morecompany";

		private static FieldInfo? _menuRoot;

		private void Awake()
		{
			//IL_0053: 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_0077: Expected O, but got Unknown
			Type type = AccessTools.TypeByName("MoreCompany.Cosmetics.CosmeticRegistry");
			MethodInfo methodInfo = AccessTools.Method(type, "SpawnCosmeticGUI", (Type[])null, (Type[])null);
			_menuRoot = AccessTools.Field(type, "cosmeticGUIGlobalScale");
			if (methodInfo == null || _menuRoot == null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Couldn't find MoreCompany's cosmetics menu, so the suit preview is off.");
			}
			else
			{
				new Harmony("MoreCompanySuitPreview").Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "AttachToPreview", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		private static void AttachToPreview()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			Transform val = (Transform)_menuRoot.GetValue(null);
			if (!((Object)(object)val == (Object)null))
			{
				Transform val2 = val.Find("CosmeticsScreen/ObjectHolder/ScavengerModel");
				if ((Object)(object)val2 != (Object)null)
				{
					((Component)val2).gameObject.AddComponent<SuitPreview>();
				}
			}
		}
	}
	internal class SuitPreview : MonoBehaviour
	{
		private Renderer[] _body = Array.Empty<Renderer>();

		private Material? _shown;

		private void Awake()
		{
			LODGroup val = default(LODGroup);
			if (((Component)this).TryGetComponent<LODGroup>(ref val))
			{
				_body = val.GetLODs().SelectMany((LOD lod) => lod.renderers).ToArray();
			}
			else
			{
				((Behaviour)this).enabled = false;
			}
		}

		private void LateUpdate()
		{
			Material val = CurrentSuit();
			if (!((Object)(object)val == (Object)null) && val != _shown)
			{
				Renderer[] body = _body;
				for (int i = 0; i < body.Length; i++)
				{
					body[i].sharedMaterial = val;
				}
				_shown = val;
			}
		}

		private static Material? CurrentSuit()
		{
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.localPlayerController == (Object)null || (Object)(object)instance.unlockablesList == (Object)null)
			{
				return null;
			}
			List<UnlockableItem> unlockables = instance.unlockablesList.unlockables;
			int currentSuitID = instance.localPlayerController.currentSuitID;
			if (currentSuitID < 0 || currentSuitID >= unlockables.Count)
			{
				return null;
			}
			return unlockables[currentSuitID].suitMaterial;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "MoreCompanySuitPreview";

		public const string PLUGIN_NAME = "MoreCompanySuitPreview";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}