Decompiled source of MaterialAssetRestorerCore v1.0.1

Sniper1_1.MaterialAssetRestorerCore.dll

Decompiled 2 days 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 System.Text;
using BepInEx;
using BepInEx.Logging;
using DunGen;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Sniper1_1.MaterialAssetRestorerCore.NetcodePatcher;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("com.olegknyazev.softmask")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("DunGen")]
[assembly: IgnoresAccessChecksTo("DunGen.Integration.ASPP")]
[assembly: IgnoresAccessChecksTo("DunGen.Integration.UnityNav")]
[assembly: IgnoresAccessChecksTo("EasyTextEffects")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.XR.CoreUtils")]
[assembly: IgnoresAccessChecksTo("Unity.XR.Management")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.ConformanceAutomation")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.MetaQuestSupport")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.MockRuntime")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.OculusQuestSupport")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.RuntimeDebugger")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.SpatialTracking")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: IgnoresAccessChecksTo("UnityEngine.XR.LegacyInputHelpers")]
[assembly: AssemblyCompany("Sniper1_1.MaterialAssetRestorerCore")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f8726f67ccfb48ec08f09c767378b62d4d9faac3")]
[assembly: AssemblyProduct("MaterialAssetRestorerCore")]
[assembly: AssemblyTitle("Sniper1_1.MaterialAssetRestorerCore")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
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;
		}
	}
}
[HarmonyPatch(typeof(NetworkManager))]
internal static class NetworkPrefabPatch1
{
	private static readonly string MOD_GUID = "Sniper1_1.MaterialAssetRestorerCore";

	[HarmonyPostfix]
	[HarmonyPatch("SetSingleton")]
	private static void RegisterPrefab()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(MOD_GUID + " Prefab");
		((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x3D);
		Object.DontDestroyOnLoad((Object)(object)val);
		NetworkObject val2 = val.AddComponent<NetworkObject>();
		val2.GlobalObjectIdHash = GetHash(MOD_GUID);
		NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(val);
		static uint GetHash(string value)
		{
			return value?.Aggregate(17u, (uint current, char c) => (current * 31) ^ c) ?? 0;
		}
	}
}
namespace MaterialAssetRestorerCore
{
	[BepInPlugin("Sniper1_1.MaterialAssetRestorerCore", "MaterialAssetRestorerCore", "1.0.0")]
	public class MaterialAssetRestorerCore : BaseUnityPlugin
	{
		public static MaterialAssetRestorerCore Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			NetcodePatcher();
			Patch();
			Logger.LogInfo((object)"Sniper1_1.MaterialAssetRestorerCore v1.0.0 has loaded!");
			Logger.LogInfo((object)"Oh hi, M.A.R.C.");
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("Sniper1_1.MaterialAssetRestorerCore");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			JSONManager.ReadJSONFiles();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}

		private void NetcodePatcher()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}
	}
	public class JSONManager
	{
		private class MaterialSetsWrapper
		{
			public List<MaterialInformationContainer> MaterialSets { get; set; }
		}

		public static void ReadJSONFiles()
		{
			DirectoryInfo parent = new DirectoryInfo(Assembly.GetExecutingAssembly().Location).Parent.Parent;
			DirectoryInfo[] directories = parent.GetDirectories("MaterialReplacements", SearchOption.AllDirectories);
			if (directories.Length == 0)
			{
				MaterialAssetRestorerCore.Logger.LogWarning((object)"Could not find MaterialReplacements in plugins folder.");
				return;
			}
			MaterialAssetRestorerCore.Logger.LogDebug((object)("Found MaterialReplacements in plugins folder with " + directories.Length + " files."));
			DirectoryInfo[] array = directories;
			foreach (DirectoryInfo directoryInfo in array)
			{
				FileInfo[] files = directoryInfo.GetFiles("*.json", SearchOption.AllDirectories);
				foreach (FileInfo fileInfo in files)
				{
					MaterialAssetRestorerCore.Logger.LogDebug((object)("Reading JSON file: " + fileInfo.FullName));
					try
					{
						string text = File.ReadAllText(fileInfo.FullName, Encoding.UTF8);
						MaterialSetsWrapper materialSetsWrapper = JsonConvert.DeserializeObject<MaterialSetsWrapper>(text);
						if (materialSetsWrapper == null || materialSetsWrapper.MaterialSets.Count == 0)
						{
							MaterialAssetRestorerCore.Logger.LogWarning((object)("No material sets found in JSON file '" + fileInfo.Name + "', skipping."));
							continue;
						}
						foreach (MaterialInformationContainer materialSet in materialSetsWrapper.MaterialSets)
						{
							if (string.IsNullOrEmpty(materialSet.BaseMaterial))
							{
								MaterialAssetRestorerCore.Logger.LogWarning((object)("Skipping entry in '" + fileInfo.Name + "': missing 'BaseMaterial'."));
								continue;
							}
							if (string.IsNullOrEmpty(materialSet.ReplaceMaterial))
							{
								MaterialAssetRestorerCore.Logger.LogWarning((object)("Skipping entry in '" + fileInfo.Name + "': missing 'ReplaceMaterial'."));
								continue;
							}
							if (string.IsNullOrEmpty(materialSet.PrefabName) && string.IsNullOrEmpty(materialSet.SceneName))
							{
								MaterialAssetRestorerCore.Logger.LogWarning((object)("Skipping entry in '" + fileInfo.Name + "': While both aren't needed, either a valid 'PrefabName' or 'SceneName' is required."));
								continue;
							}
							MaterialInit.materialInformationContainers.Add(materialSet);
							MaterialAssetRestorerCore.Logger.LogDebug((object)("Registered: '" + materialSet.BaseMaterial + "' -> '" + materialSet.ReplaceMaterial + "'" + ((materialSet.SceneName != null) ? (" in scene '" + materialSet.SceneName + "'") : "") + ((materialSet.PrefabName != null) ? (" from prefab '" + materialSet.PrefabName + "'") : "")));
						}
					}
					catch (Exception ex)
					{
						MaterialAssetRestorerCore.Logger.LogError((object)("Error reading JSON file '" + fileInfo.Name + "': " + ex.Message));
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	public class MaterialInit
	{
		[CompilerGenerated]
		private sealed class <>c__DisplayClass2_0
		{
			public MaterialInformationContainer container;

			internal void <InitializeMaterialsCoroutine>b__0(Material foundMaterial)
			{
				if ((Object)(object)foundMaterial != (Object)null)
				{
					container.replacementMaterial = foundMaterial;
				}
			}
		}

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

			private object <>2__current;

			private List<MaterialInformationContainer>.Enumerator <>s__1;

			private <>c__DisplayClass2_0 <>8__2;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || num == 1)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<>s__1 = default(List<MaterialInformationContainer>.Enumerator);
				<>8__2 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						MaterialAssetRestorerCore.Logger.LogInfo((object)"Initializing materials...");
						<>s__1 = materialInformationContainers.GetEnumerator();
						<>1__state = -3;
						break;
					case 1:
						<>1__state = -3;
						<>8__2 = null;
						break;
					}
					if (<>s__1.MoveNext())
					{
						<>8__2 = new <>c__DisplayClass2_0();
						<>8__2.container = <>s__1.Current;
						<>2__current = MaterialGet.GET_material(<>8__2.container.BaseMaterial, <>8__2.container.PrefabName, <>8__2.container.SceneName, delegate(Material foundMaterial)
						{
							if ((Object)(object)foundMaterial != (Object)null)
							{
								<>8__2.container.replacementMaterial = foundMaterial;
							}
						});
						<>1__state = 1;
						return true;
					}
					<>m__Finally1();
					<>s__1 = default(List<MaterialInformationContainer>.Enumerator);
					MaterialAssetRestorerCore.Logger.LogInfo((object)"Finished initializing materials.");
					return false;
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

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

			private void <>m__Finally1()
			{
				<>1__state = -1;
				((IDisposable)<>s__1).Dispose();
			}

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

		public static List<MaterialInformationContainer> materialInformationContainers = new List<MaterialInformationContainer>();

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "Start")]
		public static void InitializeMaterialsPatch()
		{
			((MonoBehaviour)CoroutineHelper.Instance).StartCoroutine(InitializeMaterialsCoroutine());
		}

		[IteratorStateMachine(typeof(<InitializeMaterialsCoroutine>d__2))]
		public static IEnumerator InitializeMaterialsCoroutine()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <InitializeMaterialsCoroutine>d__2(0);
		}
	}
	[HarmonyPatch(typeof(RoundManager), "FinishGeneratingNewLevelClientRpc")]
	public class WaterSwap
	{
		[HarmonyPostfix]
		public static void SwapWaterMaterials()
		{
			foreach (MaterialInformationContainer materialInformationContainer in MaterialInit.materialInformationContainers)
			{
				if ((Object)(object)materialInformationContainer.replacementMaterial != (Object)null)
				{
					MaterialSet.SET_material(materialInformationContainer.ReplaceMaterial, materialInformationContainer.replacementMaterial);
				}
			}
		}
	}
	public class MaterialInformationContainer
	{
		public string BaseMaterial = null;

		public string ReplaceMaterial = null;

		public string PrefabName = null;

		public string SceneName = null;

		public Material replacementMaterial = null;

		public MaterialInformationContainer(string materialToFindName, string materialToReplaceName, string prefabToSearchName, string sceneToSearchName, Material replacementMaterial)
		{
			BaseMaterial = materialToFindName;
			ReplaceMaterial = materialToReplaceName;
			PrefabName = prefabToSearchName;
			SceneName = sceneToSearchName;
			this.replacementMaterial = replacementMaterial;
		}
	}
	public class MaterialGet
	{
		[CompilerGenerated]
		private sealed class <GET_material>d__0 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public string materialToFind;

			public string prefabToSearch;

			public string sceneToSearch;

			public Action<Material> onComplete;

			private Material <materialToReturn>5__1;

			private GameObject <prefab>5__2;

			private GameObject[] <objects>5__3;

			private GameObject[] <>s__4;

			private int <>s__5;

			private GameObject <obj>5__6;

			private Renderer[] <renderers>5__7;

			private Renderer[] <>s__8;

			private int <>s__9;

			private Renderer <renderer>5__10;

			private Scene <scene>5__11;

			private Renderer[] <renderers>5__12;

			private Renderer[] <>s__13;

			private int <>s__14;

			private Renderer <renderer>5__15;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<materialToReturn>5__1 = null;
				<prefab>5__2 = null;
				<objects>5__3 = null;
				<>s__4 = null;
				<obj>5__6 = null;
				<renderers>5__7 = null;
				<>s__8 = null;
				<renderer>5__10 = null;
				<renderers>5__12 = null;
				<>s__13 = null;
				<renderer>5__15 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0333: Unknown result type (might be due to invalid IL or missing references)
				//IL_0338: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_04d0: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<materialToReturn>5__1 = null;
					if (string.IsNullOrEmpty(materialToFind))
					{
						MaterialAssetRestorerCore.Logger.LogWarning((object)"Material to find is null.");
						onComplete?.Invoke(null);
						return false;
					}
					if (!string.IsNullOrEmpty(prefabToSearch))
					{
						<prefab>5__2 = null;
						<objects>5__3 = Resources.FindObjectsOfTypeAll<GameObject>();
						<>s__4 = <objects>5__3;
						for (<>s__5 = 0; <>s__5 < <>s__4.Length; <>s__5++)
						{
							<obj>5__6 = <>s__4[<>s__5];
							if (((Object)<obj>5__6).name == prefabToSearch)
							{
								<prefab>5__2 = <obj>5__6;
								break;
							}
							<obj>5__6 = null;
						}
						<>s__4 = null;
						if ((Object)(object)<prefab>5__2 == (Object)null)
						{
							MaterialAssetRestorerCore.Logger.LogWarning((object)("Prefab '" + prefabToSearch + "' not found."));
							onComplete?.Invoke(null);
							return false;
						}
						MaterialAssetRestorerCore.Logger.LogDebug((object)("Found prefab '" + prefabToSearch + "'."));
						<renderers>5__7 = <prefab>5__2.GetComponentsInChildren<Renderer>(true);
						<>s__8 = <renderers>5__7;
						for (<>s__9 = 0; <>s__9 < <>s__8.Length; <>s__9++)
						{
							<renderer>5__10 = <>s__8[<>s__9];
							if ((Object)(object)<renderer>5__10.sharedMaterial != (Object)null && ((Object)<renderer>5__10.sharedMaterial).name == materialToFind)
							{
								MaterialAssetRestorerCore.Logger.LogDebug((object)("Found material '" + materialToFind + "' in prefab '" + prefabToSearch + "'."));
								<materialToReturn>5__1 = <renderer>5__10.sharedMaterial;
								break;
							}
							<renderer>5__10 = null;
						}
						<>s__8 = null;
						<renderers>5__7 = null;
						<prefab>5__2 = null;
						<objects>5__3 = null;
						break;
					}
					if (string.IsNullOrEmpty(sceneToSearch))
					{
						break;
					}
					<scene>5__11 = SceneManager.GetSceneByName(sceneToSearch);
					if (sceneToSearch != "SampleSceneRelay" && !((Scene)(ref <scene>5__11)).isLoaded)
					{
						MaterialAssetRestorerCore.Logger.LogDebug((object)("Attempting to access scene '" + sceneToSearch + "'."));
						<>2__current = SceneManager.LoadSceneAsync(sceneToSearch, (LoadSceneMode)1);
						<>1__state = 1;
						return true;
					}
					goto IL_03b3;
				case 1:
					<>1__state = -1;
					<scene>5__11 = SceneManager.GetSceneByName(sceneToSearch);
					MaterialAssetRestorerCore.Logger.LogDebug((object)$"Found scene '{sceneToSearch}'? {((Scene)(ref <scene>5__11)).isLoaded}");
					if (!((Scene)(ref <scene>5__11)).IsValid())
					{
						MaterialAssetRestorerCore.Logger.LogWarning((object)("Scene '" + sceneToSearch + "' not found."));
						onComplete?.Invoke(null);
						return false;
					}
					goto IL_03b3;
				case 2:
					{
						<>1__state = -1;
						MaterialAssetRestorerCore.Logger.LogDebug((object)("Unloaded scene '" + sceneToSearch + "'."));
						goto IL_0510;
					}
					IL_0510:
					<renderers>5__12 = null;
					break;
					IL_03b3:
					<renderers>5__12 = Object.FindObjectsOfType<Renderer>(true);
					<>s__13 = <renderers>5__12;
					for (<>s__14 = 0; <>s__14 < <>s__13.Length; <>s__14++)
					{
						<renderer>5__15 = <>s__13[<>s__14];
						if ((Object)(object)<renderer>5__15.sharedMaterial != (Object)null && ((Object)<renderer>5__15.sharedMaterial).name == materialToFind)
						{
							MaterialAssetRestorerCore.Logger.LogDebug((object)("Found material '" + materialToFind + "' in " + sceneToSearch + "."));
							<materialToReturn>5__1 = <renderer>5__15.sharedMaterial;
							break;
						}
						<renderer>5__15 = null;
					}
					<>s__13 = null;
					if (sceneToSearch != "SampleSceneRelay" && ((Scene)(ref <scene>5__11)).isLoaded)
					{
						<>2__current = SceneManager.UnloadSceneAsync(<scene>5__11);
						<>1__state = 2;
						return true;
					}
					goto IL_0510;
				}
				MaterialAssetRestorerCore.Logger.LogInfo((object)("Material '" + materialToFind + "' search completed. Found: " + (((Object)(object)<materialToReturn>5__1 != (Object)null) ? "Yes" : "No")));
				onComplete?.Invoke(<materialToReturn>5__1);
				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();
			}
		}

		[IteratorStateMachine(typeof(<GET_material>d__0))]
		public static IEnumerator GET_material(string materialToFind, string prefabToSearch = null, string sceneToSearch = null, Action<Material> onComplete = null)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <GET_material>d__0(0)
			{
				materialToFind = materialToFind,
				prefabToSearch = prefabToSearch,
				sceneToSearch = sceneToSearch,
				onComplete = onComplete
			};
		}
	}
	public class MaterialSet
	{
		public static void SET_material(string original, Material replacement)
		{
			Renderer[] array = Object.FindObjectsOfType<Renderer>();
			foreach (Renderer val in array)
			{
				Material[] sharedMaterials = val.sharedMaterials;
				bool flag = false;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					if ((Object)(object)sharedMaterials[j] != (Object)null && ((Object)sharedMaterials[j]).name == original)
					{
						sharedMaterials[j] = replacement;
						flag = true;
						MaterialAssetRestorerCore.Logger.LogInfo((object)("Replaced material '" + original + "' with '" + ((Object)replacement).name + "' in renderer '" + ((Object)((Component)val).gameObject).name + "'."));
					}
				}
				if (flag)
				{
					val.sharedMaterials = sharedMaterials;
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Sniper1_1.MaterialAssetRestorerCore";

		public const string PLUGIN_NAME = "MaterialAssetRestorerCore";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace __GEN
{
	internal class NetworkVariableSerializationHelper
	{
		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeSerialization()
		{
		}
	}
}
namespace Sniper1_1.MaterialAssetRestorerCore.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}