using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Unity.Netcode; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("MirageNullPrefabFix")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("MirageNullPrefabFix")] [assembly: AssemblyTitle("MirageNullPrefabFix")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace MirageNullPrefabFix { [BepInPlugin("com.azurecore.mirageprefabfix", "Mirage Null-Prefab Fix", "1.0.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string Guid = "com.azurecore.mirageprefabfix"; public const string Version = "1.0.2"; internal static ManualLogSource Log; private void Awake() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; new Harmony("com.azurecore.mirageprefabfix").PatchAll(); Log.LogInfo((object)"Mirage Null-Prefab Fix 1.0.2 loaded."); } } internal static class NetworkPrefabSanitizer { private static readonly FieldInfo? MPrefabsField = AccessTools.Field(typeof(NetworkPrefabs), "m_Prefabs"); internal static void Sanitize(string where) { try { NetworkPrefabs val = NetworkManager.Singleton?.NetworkConfig?.Prefabs; if (val != null && MPrefabsField?.GetValue(val) is List list) { int num = list.RemoveAll((NetworkPrefab np) => np == null || (Object)(object)np.Prefab == (Object)null); if (num > 0) { Plugin.Log.LogInfo((object)$"[{where}] Removed {num} null-Prefab entry(s) from NetworkConfig.Prefabs."); } } } catch (Exception arg) { Plugin.Log.LogError((object)$"[{where}] Sanitize failed: {arg}"); } } } [HarmonyPatch(typeof(StartOfRound), "Awake")] internal static class StartOfRoundAwakePatch { [HarmonyPrefix] [HarmonyPriority(800)] private static void Pre() { NetworkPrefabSanitizer.Sanitize("Awake:pre"); } [HarmonyPostfix] [HarmonyPriority(0)] private static void Post() { NetworkPrefabSanitizer.Sanitize("Awake:post"); } } [HarmonyPatch(typeof(StartOfRound), "Start")] internal static class StartOfRoundStartPatch { [HarmonyPrefix] [HarmonyPriority(800)] private static void Pre() { NetworkPrefabSanitizer.Sanitize("Start:pre"); } [HarmonyPostfix] [HarmonyPriority(0)] private static void Post() { NetworkPrefabSanitizer.Sanitize("Start:post"); } } }