Decompiled source of ModelReplacementAPIMirrorDecorFix v1.1.0

ModelReplacementAPIMirrorDecorFix.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Diagnostics;
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;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("ModelReplacementAPIMirrorDecorFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+9f903b65ecb0cac9ff5f393aa6372525fd9b2460")]
[assembly: AssemblyProduct("ModelReplacementAPIMirrorDecorFix")]
[assembly: AssemblyTitle("ModelReplacementAPIMirrorDecorFix")]
[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 ModelReplacementAPIMirrorDecorFix
{
	[BepInPlugin("com.bigboe97.ModelReplacementAPIMirrorDecorFix", "ModelReplacementAPI-MirrorDecor-Fix", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const int armsLayer = 4;

		private Coroutine patchCoroutine;

		private void Awake()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("com.bigboe97.ModelReplacementAPIMirrorDecorFix").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"ModelReplacementAPIMirrorDecorFix loaded");
			SceneManager.sceneLoaded += OnSceneLoaded;
			patchCoroutine = ((MonoBehaviour)this).StartCoroutine(TryPatchMirrorScriptRoutine());
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			if (patchCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(patchCoroutine);
			}
			patchCoroutine = ((MonoBehaviour)this).StartCoroutine(TryPatchMirrorScriptRoutine());
		}

		private IEnumerator TryPatchMirrorScriptRoutine()
		{
			Type mirrorScriptType = AccessTools.TypeByName("MirrorDecor.MirrorScript");
			if (mirrorScriptType == null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"[ModelReplacementAPIMirrorDecorFix] MirrorScript type not found!");
				yield break;
			}
			bool patched = false;
			bool fristTry = true;
			while (!patched)
			{
				Object[] array = Object.FindObjectsOfType(mirrorScriptType, true);
				foreach (Object obj in array)
				{
					MonoBehaviour val = (MonoBehaviour)(object)((obj is MonoBehaviour) ? obj : null);
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					Camera[] componentsInChildren = ((Component)val).GetComponentsInChildren<Camera>(true);
					((BaseUnityPlugin)this).Logger.LogInfo((object)$"[ModelReplacementAPIMirrorDecorFix] Found {componentsInChildren.Length} cameras in MirrorScript instance {((Object)val).name}.");
					if (componentsInChildren.Length != 0)
					{
						Camera[] array2 = componentsInChildren;
						foreach (Camera val2 in array2)
						{
							((BaseUnityPlugin)this).Logger.LogInfo((object)("[ModelReplacementAPIMirrorDecorFix] Before patch: Camera '" + ((Object)val2).name + "' cullingMask = " + Convert.ToString(val2.cullingMask, 2).PadLeft(32, '0')));
							int num2 = (val2.cullingMask &= -17);
							((BaseUnityPlugin)this).Logger.LogInfo((object)("[ModelReplacementAPIMirrorDecorFix] After patch: Camera '" + ((Object)val2).name + "' cullingMask = " + Convert.ToString(val2.cullingMask, 2).PadLeft(32, '0')));
							((BaseUnityPlugin)this).Logger.LogInfo((object)$"[ModelReplacementAPIMirrorDecorFix] Set cullingMask {num2} on camera {((Object)val2).name} in MirrorScript.");
						}
						patched = true;
					}
				}
				if (!patched)
				{
					if (fristTry)
					{
						((BaseUnityPlugin)this).Logger.LogInfo((object)"[ModelReplacementAPIMirrorDecorFix] MirrorScript cameras not found yet, will keep retrying until found.");
						fristTry = false;
					}
					yield return (object)new WaitForSeconds(1f);
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[ModelReplacementAPIMirrorDecorFix] Successfully patched MirrorScript cameras!");
		}
	}
}