Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of MaterialAssetRestorerCore v1.0.2
Sniper1_1.MaterialAssetRestorerCore.dll
Decompiled 3 weeks agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Logging; using Dawn.Internal; using DunGen; using HarmonyLib; using LethalLevelLoader; 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.github.teamxiaolan.dawnlib.compatibility")] [assembly: IgnoresAccessChecksTo("com.github.teamxiaolan.dawnlib")] [assembly: IgnoresAccessChecksTo("com.github.teamxiaolan.dawnlib.dusk")] [assembly: IgnoresAccessChecksTo("com.github.teamxiaolan.dawnlib.interfaces")] [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("LethalLevelLoader")] [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+9b10838f003875f6b0c75cc35ba63f482ba2f9b3")] [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")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class MaterialAssetRestorerCore : BaseUnityPlugin { public static bool hasLLL; public static bool hasDL; 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(typeof(MaterialInit)); Harmony.PatchAll(typeof(WaterSwap)); JSONManager.ReadJSONFiles(); PatchLever(); 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); } } } } private static void PatchLever() { try { Harmony.PatchAll(typeof(LLLLeverPatch)); Logger.LogInfo((object)"LethalLevelLoader detected, patching CheckLever()"); hasLLL = true; } catch { Logger.LogInfo((object)"LethalLevelLoader not detected, checking for DawnLib"); try { Harmony.PatchAll(typeof(DawnLibLeverPatch)); Logger.LogInfo((object)"DawnLib detected, patching DawnMoonNetworker.UnlockLever()"); hasDL = true; } catch { Logger.LogWarning((object)"DawnLib not detected either. What would you possible be using this for?"); } } } } 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)); } } } } } internal static class LLLLeverPatch { [HarmonyPatch(typeof(Patches), "CheckLever")] [HarmonyPrefix] public static bool LeverPatch(InteractTrigger trigger) { if (!MaterialInit.materialsInitialized) { trigger.disabledHoverTip = "[ M.A.R.C. still caching materials!]"; trigger.interactable = false; return false; } return true; } } [HarmonyPatch] internal static class DawnLibLeverPatch { [CompilerGenerated] private sealed class <InjectWaitInstruction>d__1 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IEnumerator, IDisposable { private int <>1__state; private CodeInstruction <>2__current; private int <>l__initialThreadId; private IEnumerable<CodeInstruction> instructions; public IEnumerable<CodeInstruction> <>3__instructions; private ConstructorInfo <waitUntilConstructor>5__1; private bool <foundWaitUntil>5__2; private IEnumerator<CodeInstruction> <>s__3; private CodeInstruction <instruction>5__4; CodeInstruction IEnumerator<CodeInstruction>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <InjectWaitInstruction>d__1(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void IDisposable.Dispose() { int num = <>1__state; if (num == -3 || (uint)(num - 1) <= 1u) { try { } finally { <>m__Finally1(); } } <waitUntilConstructor>5__1 = null; <>s__3 = null; <instruction>5__4 = null; <>1__state = -2; } private bool MoveNext() { //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Expected O, but got Unknown try { switch (<>1__state) { default: return false; case 0: <>1__state = -1; <waitUntilConstructor>5__1 = typeof(WaitUntil).GetConstructor(new Type[1] { typeof(Func<bool>) }); <foundWaitUntil>5__2 = false; <>s__3 = instructions.GetEnumerator(); <>1__state = -3; goto IL_0148; case 1: <>1__state = -3; goto IL_0121; case 2: { <>1__state = -3; <instruction>5__4 = null; goto IL_0148; } IL_0148: if (<>s__3.MoveNext()) { <instruction>5__4 = <>s__3.Current; if (<instruction>5__4.opcode == OpCodes.Newobj && <instruction>5__4.operand as ConstructorInfo == <waitUntilConstructor>5__1) { MaterialAssetRestorerCore.Logger.LogInfo((object)"Found WaitUntil in original UnlockLever(), injecting wait for materials."); <foundWaitUntil>5__2 = true; <>2__current = new CodeInstruction(OpCodes.Call, (object)typeof(DawnLibLeverPatch).GetMethod("WaitForMaterials", BindingFlags.Static | BindingFlags.Public)); <>1__state = 1; return true; } goto IL_0121; } <>m__Finally1(); <>s__3 = null; if (!<foundWaitUntil>5__2) { MaterialAssetRestorerCore.Logger.LogWarning((object)"Never found WaitUntil constructor in MoveNext!"); } return false; IL_0121: <>2__current = <instruction>5__4; <>1__state = 2; return true; } } 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; if (<>s__3 != null) { <>s__3.Dispose(); } } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } [DebuggerHidden] IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator() { <InjectWaitInstruction>d__1 <InjectWaitInstruction>d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; <InjectWaitInstruction>d__ = this; } else { <InjectWaitInstruction>d__ = new <InjectWaitInstruction>d__1(0); } <InjectWaitInstruction>d__.instructions = <>3__instructions; return <InjectWaitInstruction>d__; } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable<CodeInstruction>)this).GetEnumerator(); } } [HarmonyTargetMethod] public static MethodBase FindUnlockLever() { try { Type[] nestedTypes = typeof(DawnMoonNetworker).GetNestedTypes(BindingFlags.Instance | BindingFlags.NonPublic); Type type = nestedTypes.FirstOrDefault((Type t) => t.Name.Contains("UnlockLever")); if (type == null) { MaterialAssetRestorerCore.Logger.LogError((object)"Could not find UnlockLever state machine type!"); return null; } MaterialAssetRestorerCore.Logger.LogInfo((object)"Found the UnlockLever"); return type.GetMethod("MoveNext", BindingFlags.Instance | BindingFlags.NonPublic); } catch (Exception arg) { MaterialAssetRestorerCore.Logger.LogError((object)$"Error in DawnLibLeverPatch.FindUnlockLeverInstruction(): {arg}"); return null; } } [IteratorStateMachine(typeof(<InjectWaitInstruction>d__1))] [HarmonyTranspiler] public static IEnumerable<CodeInstruction> InjectWaitInstruction(IEnumerable<CodeInstruction> instructions) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <InjectWaitInstruction>d__1(-2) { <>3__instructions = instructions }; } public static Func<bool> WaitForMaterials(Func<bool> original) { Func<bool> original2 = original; return () => original2() && MaterialInit.materialsInitialized; } } [HarmonyPatch(typeof(StartOfRound))] public class MaterialInit { [CompilerGenerated] private sealed class <>c__DisplayClass3_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__3 : IEnumerator<object>, IEnumerator, IDisposable { private int <>1__state; private object <>2__current; private List<MaterialInformationContainer>.Enumerator <>s__1; private <>c__DisplayClass3_0 <>8__2; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <InitializeMaterialsCoroutine>d__3(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; materialsInitialized = false; 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__DisplayClass3_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."); materialsInitialized = true; 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>(); public static bool materialsInitialized = false; [HarmonyPostfix] [HarmonyPatch(typeof(StartOfRound), "Start")] public static void InitializeMaterialsPatch() { ((MonoBehaviour)CoroutineHelper.Instance).StartCoroutine(InitializeMaterialsCoroutine()); } [IteratorStateMachine(typeof(<InitializeMaterialsCoroutine>d__3))] public static IEnumerator InitializeMaterialsCoroutine() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <InitializeMaterialsCoroutine>d__3(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[] <objects>5__2; private GameObject[] <>s__3; private int <>s__4; private GameObject <prefab>5__5; private Renderer[] <>s__6; private int <>s__7; private Renderer <renderer>5__8; private Scene <scene>5__9; private Renderer[] <renderers>5__10; private Renderer[] <>s__11; private int <>s__12; private Renderer <renderer>5__13; 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; <objects>5__2 = null; <>s__3 = null; <prefab>5__5 = null; <>s__6 = null; <renderer>5__8 = null; <renderers>5__10 = null; <>s__11 = null; <renderer>5__13 = null; <>1__state = -2; } private bool MoveNext() { //IL_02fa: Unknown result type (might be due to invalid IL or missing references) //IL_02ff: Unknown result type (might be due to invalid IL or missing references) //IL_027a: Unknown result type (might be due to invalid IL or missing references) //IL_027f: Unknown result type (might be due to invalid IL or missing references) //IL_0497: 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)) { <objects>5__2 = Resources.FindObjectsOfTypeAll<GameObject>(); <>s__3 = <objects>5__2; for (<>s__4 = 0; <>s__4 < <>s__3.Length; <>s__4++) { <prefab>5__5 = <>s__3[<>s__4]; if (((Object)<prefab>5__5).name == prefabToSearch) { MaterialAssetRestorerCore.Logger.LogDebug((object)("Found a prefab '" + prefabToSearch + "'.")); <>s__6 = <prefab>5__5.GetComponentsInChildren<Renderer>(true); for (<>s__7 = 0; <>s__7 < <>s__6.Length; <>s__7++) { <renderer>5__8 = <>s__6[<>s__7]; if ((Object)(object)<renderer>5__8.sharedMaterial != (Object)null && ((Object)<renderer>5__8.sharedMaterial).name == materialToFind && ((Object)<renderer>5__8.sharedMaterial.shader).name != "Hidden/InternalErrorShader") { MaterialAssetRestorerCore.Logger.LogDebug((object)("Found material '" + materialToFind + "' in prefab '" + prefabToSearch + "'.")); <materialToReturn>5__1 = <renderer>5__8.sharedMaterial; break; } <renderer>5__8 = null; } <>s__6 = null; if ((Object)(object)<materialToReturn>5__1 != (Object)null) { break; } } <prefab>5__5 = null; } <>s__3 = null; <objects>5__2 = null; break; } if (string.IsNullOrEmpty(sceneToSearch)) { break; } <scene>5__9 = SceneManager.GetSceneByName(sceneToSearch); if (sceneToSearch != "SampleSceneRelay" && !((Scene)(ref <scene>5__9)).isLoaded) { MaterialAssetRestorerCore.Logger.LogDebug((object)("Attempting to access scene '" + sceneToSearch + "'.")); <>2__current = SceneManager.LoadSceneAsync(sceneToSearch, (LoadSceneMode)1); <>1__state = 1; return true; } goto IL_037a; case 1: <>1__state = -1; <scene>5__9 = SceneManager.GetSceneByName(sceneToSearch); MaterialAssetRestorerCore.Logger.LogDebug((object)$"Found scene '{sceneToSearch}'? {((Scene)(ref <scene>5__9)).isLoaded}"); if (!((Scene)(ref <scene>5__9)).IsValid()) { MaterialAssetRestorerCore.Logger.LogWarning((object)("Scene '" + sceneToSearch + "' not found.")); onComplete?.Invoke(null); return false; } goto IL_037a; case 2: { <>1__state = -1; MaterialAssetRestorerCore.Logger.LogDebug((object)("Unloaded scene '" + sceneToSearch + "'.")); goto IL_04d7; } IL_037a: <renderers>5__10 = Object.FindObjectsOfType<Renderer>(true); <>s__11 = <renderers>5__10; for (<>s__12 = 0; <>s__12 < <>s__11.Length; <>s__12++) { <renderer>5__13 = <>s__11[<>s__12]; if ((Object)(object)<renderer>5__13.sharedMaterial != (Object)null && ((Object)<renderer>5__13.sharedMaterial).name == materialToFind) { MaterialAssetRestorerCore.Logger.LogDebug((object)("Found material '" + materialToFind + "' in " + sceneToSearch + ".")); <materialToReturn>5__1 = <renderer>5__13.sharedMaterial; break; } <renderer>5__13 = null; } <>s__11 = null; if (sceneToSearch != "SampleSceneRelay" && ((Scene)(ref <scene>5__9)).isLoaded) { <>2__current = SceneManager.UnloadSceneAsync(<scene>5__9); <>1__state = 2; return true; } goto IL_04d7; IL_04d7: <renderers>5__10 = null; break; } 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 { } }