using 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(); 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 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(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 d__1 : IEnumerable, IEnumerable, IEnumerator, IEnumerator, IDisposable { private int <>1__state; private CodeInstruction <>2__current; private int <>l__initialThreadId; private IEnumerable instructions; public IEnumerable <>3__instructions; private ConstructorInfo 5__1; private bool 5__2; private IEnumerator <>s__3; private CodeInstruction 5__4; CodeInstruction IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public 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(); } } 5__1 = null; <>s__3 = null; 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; 5__1 = typeof(WaitUntil).GetConstructor(new Type[1] { typeof(Func) }); 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; 5__4 = null; goto IL_0148; } IL_0148: if (<>s__3.MoveNext()) { 5__4 = <>s__3.Current; if (5__4.opcode == OpCodes.Newobj && 5__4.operand as ConstructorInfo == 5__1) { MaterialAssetRestorerCore.Logger.LogInfo((object)"Found WaitUntil in original UnlockLever(), injecting wait for materials."); 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 (!5__2) { MaterialAssetRestorerCore.Logger.LogWarning((object)"Never found WaitUntil constructor in MoveNext!"); } return false; IL_0121: <>2__current = 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 IEnumerable.GetEnumerator() { d__1 d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; d__ = this; } else { d__ = new d__1(0); } d__.instructions = <>3__instructions; return d__; } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)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(d__1))] [HarmonyTranspiler] public static IEnumerable InjectWaitInstruction(IEnumerable instructions) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__1(-2) { <>3__instructions = instructions }; } public static Func WaitForMaterials(Func original) { Func original2 = original; return () => original2() && MaterialInit.materialsInitialized; } } [HarmonyPatch(typeof(StartOfRound))] public class MaterialInit { [CompilerGenerated] private sealed class <>c__DisplayClass3_0 { public MaterialInformationContainer container; internal void b__0(Material foundMaterial) { if ((Object)(object)foundMaterial != (Object)null) { container.replacementMaterial = foundMaterial; } } } [CompilerGenerated] private sealed class d__3 : IEnumerator, IEnumerator, IDisposable { private int <>1__state; private object <>2__current; private List.Enumerator <>s__1; private <>c__DisplayClass3_0 <>8__2; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public 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.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.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 materialInformationContainers = new List(); public static bool materialsInitialized = false; [HarmonyPostfix] [HarmonyPatch(typeof(StartOfRound), "Start")] public static void InitializeMaterialsPatch() { ((MonoBehaviour)CoroutineHelper.Instance).StartCoroutine(InitializeMaterialsCoroutine()); } [IteratorStateMachine(typeof(d__3))] public static IEnumerator InitializeMaterialsCoroutine() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new 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 d__0 : IEnumerator, IEnumerator, IDisposable { private int <>1__state; private object <>2__current; public string materialToFind; public string prefabToSearch; public string sceneToSearch; public Action onComplete; private Material 5__1; private GameObject[] 5__2; private GameObject[] <>s__3; private int <>s__4; private GameObject 5__5; private Renderer[] <>s__6; private int <>s__7; private Renderer 5__8; private Scene 5__9; private Renderer[] 5__10; private Renderer[] <>s__11; private int <>s__12; private Renderer 5__13; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__0(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { 5__1 = null; 5__2 = null; <>s__3 = null; 5__5 = null; <>s__6 = null; 5__8 = null; 5__10 = null; <>s__11 = null; 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; 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)) { 5__2 = Resources.FindObjectsOfTypeAll(); <>s__3 = 5__2; for (<>s__4 = 0; <>s__4 < <>s__3.Length; <>s__4++) { 5__5 = <>s__3[<>s__4]; if (((Object)5__5).name == prefabToSearch) { MaterialAssetRestorerCore.Logger.LogDebug((object)("Found a prefab '" + prefabToSearch + "'.")); <>s__6 = 5__5.GetComponentsInChildren(true); for (<>s__7 = 0; <>s__7 < <>s__6.Length; <>s__7++) { 5__8 = <>s__6[<>s__7]; if ((Object)(object)5__8.sharedMaterial != (Object)null && ((Object)5__8.sharedMaterial).name == materialToFind && ((Object)5__8.sharedMaterial.shader).name != "Hidden/InternalErrorShader") { MaterialAssetRestorerCore.Logger.LogDebug((object)("Found material '" + materialToFind + "' in prefab '" + prefabToSearch + "'.")); 5__1 = 5__8.sharedMaterial; break; } 5__8 = null; } <>s__6 = null; if ((Object)(object)5__1 != (Object)null) { break; } } 5__5 = null; } <>s__3 = null; 5__2 = null; break; } if (string.IsNullOrEmpty(sceneToSearch)) { break; } 5__9 = SceneManager.GetSceneByName(sceneToSearch); if (sceneToSearch != "SampleSceneRelay" && !((Scene)(ref 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; 5__9 = SceneManager.GetSceneByName(sceneToSearch); MaterialAssetRestorerCore.Logger.LogDebug((object)$"Found scene '{sceneToSearch}'? {((Scene)(ref 5__9)).isLoaded}"); if (!((Scene)(ref 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: 5__10 = Object.FindObjectsOfType(true); <>s__11 = 5__10; for (<>s__12 = 0; <>s__12 < <>s__11.Length; <>s__12++) { 5__13 = <>s__11[<>s__12]; if ((Object)(object)5__13.sharedMaterial != (Object)null && ((Object)5__13.sharedMaterial).name == materialToFind) { MaterialAssetRestorerCore.Logger.LogDebug((object)("Found material '" + materialToFind + "' in " + sceneToSearch + ".")); 5__1 = 5__13.sharedMaterial; break; } 5__13 = null; } <>s__11 = null; if (sceneToSearch != "SampleSceneRelay" && ((Scene)(ref 5__9)).isLoaded) { <>2__current = SceneManager.UnloadSceneAsync(5__9); <>1__state = 2; return true; } goto IL_04d7; IL_04d7: 5__10 = null; break; } MaterialAssetRestorerCore.Logger.LogInfo((object)("Material '" + materialToFind + "' search completed. Found: " + (((Object)(object)5__1 != (Object)null) ? "Yes" : "No"))); onComplete?.Invoke(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(d__0))] public static IEnumerator GET_material(string materialToFind, string prefabToSearch = null, string sceneToSearch = null, Action onComplete = null) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new 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(); 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 { } }