Decompiled source of RoundsPatchFpsFix v1.0.9

RoundsPatchFpsFix.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using InControl;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using RoundsPatchFpsFix.Patches;
using RoundsPatchFpsFix.Utils;
using Sonigon;
using Sonigon.Internal;
using TMPro;
using UnboundLib;
using UnboundLib.GameModes;
using UnboundLib.Utils.UI;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[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("RoundsPatchFpsFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.8.0")]
[assembly: AssemblyInformationalVersion("1.0.8")]
[assembly: AssemblyProduct("RoundsPatchFpsFix")]
[assembly: AssemblyTitle("RoundsPatchFpsFix")]
[assembly: AssemblyVersion("1.0.8.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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 RoundsPatchFpsFix
{
	[BepInPlugin("com.naccel.rounds.patchfpsfix", "RoundsPatchFpsFix", "1.0.9")]
	[BepInProcess("Rounds.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class RoundsPatchFpsFixPlugin : BaseUnityPlugin
	{
		public const string ModId = "com.naccel.rounds.patchfpsfix";

		public const string ModName = "RoundsPatchFpsFix";

		public const string ModVersion = "1.0.9";

		public static RoundsPatchFpsFixPlugin Instance { get; private set; }

		public static ManualLogSource Logger { get; private set; }

		public static Harmony HarmonyInstance { get; private set; }

		private void Awake()
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			AppDomain.CurrentDomain.AssemblyResolve += delegate(object sender, ResolveEventArgs args)
			{
				try
				{
					if (new AssemblyName(args.Name).Name.Equals("LocalZoom", StringComparison.OrdinalIgnoreCase))
					{
						using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("LocalZoom.dll");
						if (stream != null)
						{
							byte[] array = new byte[stream.Length];
							stream.Read(array, 0, array.Length);
							Logger.LogInfo((object)"[RoundsPatchFpsFix] Auto-resolved missing LocalZoom assembly from memory stub.");
							return Assembly.Load(array);
						}
					}
				}
				catch
				{
				}
				return (Assembly)null;
			};
			Logger.LogInfo((object)"[RoundsPatchFpsFix] v1.0.9 initializing high-FPS acceleration pipeline...");
			try
			{
				FpsFixConfig.Initialize(((BaseUnityPlugin)this).Config);
			}
			catch (Exception arg)
			{
				Logger.LogError((object)string.Format("[{0}] Error initializing config: {1}", "RoundsPatchFpsFix", arg));
			}
			try
			{
				HarmonyInstance = new Harmony("com.naccel.rounds.patchfpsfix");
				HarmonyInstance.PatchAll();
				ModSafetyFixesPatch.Apply(HarmonyInstance);
			}
			catch (Exception arg2)
			{
				Logger.LogError((object)string.Format("[{0}] Error applying Harmony patches: {1}", "RoundsPatchFpsFix", arg2));
			}
			try
			{
				EngineOptimizationPatch.ApplyEngineSettings();
			}
			catch (Exception arg3)
			{
				Logger.LogError((object)string.Format("[{0}] Error applying engine optimizations: {1}", "RoundsPatchFpsFix", arg3));
			}
		}

		private void Start()
		{
			try
			{
				ModSafetyFixesPatch.Apply(HarmonyInstance);
			}
			catch
			{
			}
			try
			{
				if (Chainloader.PluginInfos.ContainsKey("com.willis.rounds.unbound") || Chainloader.PluginInfos.ContainsKey("com.willis.rounds.unboundlib"))
				{
					EngineOptimizationPatch.RegisterUnboundHooks();
					InitUnboundMenu();
				}
				else
				{
					Logger.LogInfo((object)"[RoundsPatchFpsFix] UnboundLib not detected; running standalone with optimal config.");
				}
			}
			catch (Exception ex)
			{
				Logger.LogWarning((object)("[RoundsPatchFpsFix] UnboundLib integration skipped: " + ex.Message));
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void InitUnboundMenu()
		{
			UnboundMenuIntegration.Register();
		}
	}
}
namespace RoundsPatchFpsFix.Utils
{
	public static class FpsFixConfig
	{
		public static ConfigEntry<bool> PauseGcDuringCombat { get; private set; }

		public static ConfigEntry<bool> SilenceCombatLogSpam { get; private set; }

		public static ConfigEntry<bool> LimitAudioConcurrency { get; private set; }

		public static ConfigEntry<bool> OptimizeRayCastTrails { get; private set; }

		public static ConfigEntry<bool> OptimizeBulletTrails { get; private set; }

		public static ConfigEntry<bool> CleanMapDebrisAfterRound { get; private set; }

		public static ConfigEntry<bool> SmoothFramePacing { get; private set; }

		public static ConfigEntry<bool> EnsurePhysicsStability { get; private set; }

		public static void Initialize(ConfigFile config)
		{
			PauseGcDuringCombat = config.Bind<bool>("CombatPerformance", "PauseGcDuringCombat", false, "Temporarily disables Mono Garbage Collection during active battle rounds to eliminate micro-stutters. Defaults to false in heavy modpacks to allow smooth incremental GC without heap expansion stalls.");
			SilenceCombatLogSpam = config.Bind<bool>("CombatPerformance", "SilenceCombatLogSpam", true, "Silences redundant Debug.Log output from bullet and projectile instantiation during battle to prevent main-thread disk I/O stalls.");
			LimitAudioConcurrency = config.Bind<bool>("Audio", "LimitAudioConcurrency", true, "Limits identical Sonigon sound events during bullet storms to 2 per 40ms, preventing audio buffer overruns, distortion, and main-thread DSP overhead.");
			OptimizeRayCastTrails = config.Bind<bool>("Physics", "OptimizeRayCastTrails", true, "Replaces RaycastAll/CircleCastAll/Concat heap allocations in RayCastTrail.Update() with static non-alloc buffers, eliminating thousands of heap allocations per second.");
			OptimizeBulletTrails = config.Bind<bool>("Graphics", "OptimizeBulletTrails", true, "Clamps TrailRenderer lifetime to 0.20s on fast projectiles to reduce dynamic mesh vertex churn and draw call overhead.");
			CleanMapDebrisAfterRound = config.Bind<bool>("Map", "CleanMapDebrisAfterRound", true, "Purges leftover wall hit debris, broken box pieces, and temporary impact objects between rounds so FPS does not degrade over a 5-round match.");
			SmoothFramePacing = config.Bind<bool>("Graphics", "SmoothFramePacing", false, "Caps framerate cleanly at 60 FPS when true. Default is false (unlocked framerate) to prevent frame pacing jitter, micro-stutters, and conflicts with Linux desktop compositors.");
			EnsurePhysicsStability = config.Bind<bool>("Physics", "EnsurePhysicsStability", true, "Maintains stable Box2D solver iterations (8 vel / 3 pos) and autoSyncTransforms to prevent projectile penetration and collision multiplier explosions.");
		}
	}
	internal static class UnboundMenuIntegration
	{
		public static void Register()
		{
			try
			{
				Unbound.RegisterMenu("FpsFix", (UnityAction)null, (Action<GameObject>)SetupMenu, (GameObject)null, true);
				ManualLogSource logger = RoundsPatchFpsFixPlugin.Logger;
				if (logger != null)
				{
					logger.LogInfo((object)"[RoundsPatchFpsFix] In-game MODS tab registered successfully.");
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger2 = RoundsPatchFpsFixPlugin.Logger;
				if (logger2 != null)
				{
					logger2.LogWarning((object)("[RoundsPatchFpsFix] RegisterMenu warning: " + ex.Message));
				}
			}
		}

		private static void SetupMenu(GameObject menu)
		{
			try
			{
				TextMeshProUGUI val = default(TextMeshProUGUI);
				MenuHandler.CreateText("ROUNDS PATCH FPS FIX (v1.0.5)", menu, ref val, 55, false, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
				MenuHandler.CreateText("Ultra high-FPS acceleration and combat bottleneck elimination", menu, ref val, 28, false, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
				MenuHandler.CreateText(" ", menu, ref val, 20, false, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
				MenuHandler.CreateToggle(FpsFixConfig.PauseGcDuringCombat.Value, "Freeze Mono GC During Combat (Eliminates Micro-Stutter)", menu, (UnityAction<bool>)delegate(bool value)
				{
					FpsFixConfig.PauseGcDuringCombat.Value = value;
				}, 30, false, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
				MenuHandler.CreateToggle(FpsFixConfig.SilenceCombatLogSpam.Value, "Silence Bullet & Effect Debug Logs (Eliminates Disk I/O Lag)", menu, (UnityAction<bool>)delegate(bool value)
				{
					FpsFixConfig.SilenceCombatLogSpam.Value = value;
				}, 30, false, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
				MenuHandler.CreateToggle(FpsFixConfig.LimitAudioConcurrency.Value, "Sonigon Audio Voice Limiter (Stops Audio Distortion & DSP Lag)", menu, (UnityAction<bool>)delegate(bool value)
				{
					FpsFixConfig.LimitAudioConcurrency.Value = value;
				}, 30, false, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
				MenuHandler.CreateToggle(FpsFixConfig.OptimizeRayCastTrails.Value, "RayCastTrail Non-Alloc Physics (Eliminates 4800+ Heap Allocs/s)", menu, (UnityAction<bool>)delegate(bool value)
				{
					FpsFixConfig.OptimizeRayCastTrails.Value = value;
				}, 30, false, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
				MenuHandler.CreateToggle(FpsFixConfig.OptimizeBulletTrails.Value, "Clamp Bullet Trail Lifetimes (Prevents Vertex Bloat & Draw Calls)", menu, (UnityAction<bool>)delegate(bool value)
				{
					FpsFixConfig.OptimizeBulletTrails.Value = value;
				}, 30, false, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
				MenuHandler.CreateToggle(FpsFixConfig.CleanMapDebrisAfterRound.Value, "Purge Map Debris & Decals Between Rounds (Consistent 5-Round FPS)", menu, (UnityAction<bool>)delegate(bool value)
				{
					FpsFixConfig.CleanMapDebrisAfterRound.Value = value;
				}, 30, false, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
				MenuHandler.CreateToggle(FpsFixConfig.SmoothFramePacing.Value, "Smooth 60 FPS Pacing (Prevents Intel iGPU Power Throttling)", menu, (UnityAction<bool>)delegate(bool value)
				{
					FpsFixConfig.SmoothFramePacing.Value = value;
					EngineOptimizationPatch.ApplyEngineSettings();
				}, 30, false, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
				MenuHandler.CreateToggle(FpsFixConfig.EnsurePhysicsStability.Value, "Stable Box2D Physics Solver (Prevents Collision Explosion)", menu, (UnityAction<bool>)delegate(bool value)
				{
					FpsFixConfig.EnsurePhysicsStability.Value = value;
					EngineOptimizationPatch.ApplyEngineSettings();
				}, 30, false, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
			}
			catch (Exception arg)
			{
				ManualLogSource logger = RoundsPatchFpsFixPlugin.Logger;
				if (logger != null)
				{
					logger.LogError((object)$"[RoundsPatchFpsFix] Error building in-game menu: {arg}");
				}
			}
		}
	}
}
namespace RoundsPatchFpsFix.Patches
{
	[HarmonyPatch]
	public static class AudioConcurrencyLimiterPatch
	{
		private struct SoundThrottleData
		{
			public float LastPlayTime;

			public int PlayCount;
		}

		private static readonly Dictionary<int, SoundThrottleData> EventThrottleMap = new Dictionary<int, SoundThrottleData>(128);

		private const float TimeWindow = 0.04f;

		private const int MaxPlaysPerWindow = 2;

		[HarmonyPatch(typeof(SoundManagerData), "PlaySoundEvent")]
		[HarmonyPrefix]
		public static bool PlaySoundEvent_Prefix(SoundEvent soundEvent)
		{
			try
			{
				if ((Object)(object)soundEvent == (Object)null)
				{
					return true;
				}
				if (FpsFixConfig.LimitAudioConcurrency != null && !FpsFixConfig.LimitAudioConcurrency.Value)
				{
					return true;
				}
				int instanceID = ((Object)soundEvent).GetInstanceID();
				float realtimeSinceStartup = Time.realtimeSinceStartup;
				if (EventThrottleMap.TryGetValue(instanceID, out var value))
				{
					if (realtimeSinceStartup - value.LastPlayTime < 0.04f)
					{
						value.PlayCount++;
						EventThrottleMap[instanceID] = value;
						if (value.PlayCount > 2)
						{
							return false;
						}
					}
					else
					{
						value.LastPlayTime = realtimeSinceStartup;
						value.PlayCount = 1;
						EventThrottleMap[instanceID] = value;
					}
				}
				else
				{
					EventThrottleMap[instanceID] = new SoundThrottleData
					{
						LastPlayTime = realtimeSinceStartup,
						PlayCount = 1
					};
				}
			}
			catch
			{
				return true;
			}
			return true;
		}

		public static void ResetThrottles()
		{
			try
			{
				EventThrottleMap.Clear();
			}
			catch
			{
			}
		}

		[HarmonyPatch(typeof(Voice), "ResetVoice")]
		[HarmonyPrefix]
		public static bool ResetVoice_Prefix(Voice __instance)
		{
			if (__instance == null)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(SoundManagerVoicePool), "PoolVoice")]
		[HarmonyFinalizer]
		public static Exception PoolVoice_Finalizer(Exception __exception)
		{
			return null;
		}
	}
	[HarmonyPatch]
	public static class BotSafetyFixPatch
	{
		private static float _lastBotCreatedTime = -10f;

		private static float _lastPlayerJoinTime = -10f;

		private const float BotSpawnCooldown = 0.4f;

		private const float PlayerJoinCooldown = 0.8f;

		[HarmonyPatch(typeof(PlayerAssigner), "LateUpdate")]
		[HarmonyPrefix]
		[HarmonyPriority(800)]
		public static bool PlayerAssigner_LateUpdate_Prefix(PlayerAssigner __instance)
		{
			try
			{
				bool flag = (Object)(object)GameManager.instance != (Object)null && GameManager.instance.isPlaying;
				float realtimeSinceStartup = Time.realtimeSinceStartup;
				if (Input.GetKeyDown((KeyCode)98))
				{
					if (realtimeSinceStartup - _lastBotCreatedTime < 0.4f)
					{
						return false;
					}
					_lastBotCreatedTime = realtimeSinceStartup;
				}
				if (flag)
				{
					if (Input.GetKey((KeyCode)32))
					{
						if (HasPlayerSpawnedInGame())
						{
							return false;
						}
						if (realtimeSinceStartup - _lastPlayerJoinTime < 0.8f)
						{
							return false;
						}
						_lastPlayerJoinTime = realtimeSinceStartup;
					}
				}
				else if (Input.GetKey((KeyCode)32))
				{
					if (HasKeyboardPlayerJoined(__instance))
					{
						return false;
					}
					if (realtimeSinceStartup - _lastPlayerJoinTime < 0.8f)
					{
						return false;
					}
					_lastPlayerJoinTime = realtimeSinceStartup;
				}
				if ((Object)(object)__instance != (Object)null && __instance.players != null)
				{
					for (int i = 0; i < __instance.players.Count; i++)
					{
						SanitizePlayerActions(__instance.players[i]);
					}
				}
			}
			catch
			{
			}
			return true;
		}

		private static bool HasPlayerSpawnedInGame()
		{
			if ((Object)(object)PlayerManager.instance != (Object)null && PlayerManager.instance.players != null && PlayerManager.instance.players.Count > 0)
			{
				return true;
			}
			PlayerAssigner instance = PlayerAssigner.instance;
			if ((Object)(object)instance != (Object)null && instance.players != null && instance.players.Count > 0)
			{
				return true;
			}
			return false;
		}

		public static bool IsAI(CharacterData data)
		{
			if ((Object)(object)data == (Object)null)
			{
				return false;
			}
			try
			{
				if ((Object)(object)((Component)data).GetComponent("PlayerAIBase") != (Object)null)
				{
					return true;
				}
				if ((Object)(object)((Component)data).GetComponentInChildren<PlayerAI>() != (Object)null || (Object)(object)((Component)data).GetComponentInChildren<PlayerAIZorro>() != (Object)null || (Object)(object)((Component)data).GetComponent("PlayerAIDavid") != (Object)null || (Object)(object)((Component)data).GetComponent("PlayerAIPhilip") != (Object)null || (Object)(object)((Component)data).GetComponent("PlayerAIWilhelm") != (Object)null || (Object)(object)((Component)data).GetComponent("PlayerAIPetter") != (Object)null)
				{
					return true;
				}
				PlayerAPI component = ((Component)data).GetComponent<PlayerAPI>();
				if ((Object)(object)component != (Object)null && ((Behaviour)component).enabled)
				{
					return true;
				}
				Type type = AccessTools.TypeByName("RoundsWithBots.Extensions.CharacterDataExtension");
				if (type != null)
				{
					MethodInfo methodInfo = AccessTools.Method(type, "GetAdditionalData", new Type[1] { typeof(CharacterData) }, (Type[])null);
					if (methodInfo != null)
					{
						object obj = methodInfo.Invoke(null, new object[1] { data });
						if (obj != null)
						{
							PropertyInfo propertyInfo = AccessTools.Property(obj.GetType(), "IsBot");
							if (propertyInfo != null && (bool)propertyInfo.GetValue(obj, null))
							{
								return true;
							}
						}
					}
				}
			}
			catch
			{
			}
			return false;
		}

		public static bool IsKeyboardHuman(CharacterData data)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)data == (Object)null)
			{
				return false;
			}
			if (IsAI(data))
			{
				return false;
			}
			if (data.playerActions != null && ((PlayerActionSet)data.playerActions).Device != null && ((PlayerActionSet)data.playerActions).Device != InputDevice.Null && data.playerActions.Aim != null)
			{
				Vector2 vector = ((TwoAxisInputControl)data.playerActions.Aim).Vector;
				if (((Vector2)(ref vector)).magnitude > 0.15f)
				{
					return false;
				}
			}
			return true;
		}

		public static bool HasKeyboardPlayerJoined(PlayerAssigner assigner)
		{
			if ((Object)(object)PlayerManager.instance != (Object)null && PlayerManager.instance.players != null)
			{
				for (int i = 0; i < PlayerManager.instance.players.Count; i++)
				{
					Player val = PlayerManager.instance.players[i];
					if ((Object)(object)val != (Object)null && (Object)(object)val.data != (Object)null && IsKeyboardHuman(val.data))
					{
						return true;
					}
				}
			}
			if ((Object)(object)assigner != (Object)null && assigner.players != null)
			{
				for (int j = 0; j < assigner.players.Count; j++)
				{
					CharacterData val2 = assigner.players[j];
					if ((Object)(object)val2 != (Object)null && IsKeyboardHuman(val2))
					{
						return true;
					}
				}
			}
			CharacterSelectionInstance[] array = Object.FindObjectsOfType<CharacterSelectionInstance>();
			if (array != null)
			{
				foreach (CharacterSelectionInstance val3 in array)
				{
					if ((Object)(object)val3 != (Object)null && (Object)(object)val3.currentPlayer != (Object)null && (Object)(object)val3.currentPlayer.data != (Object)null && IsKeyboardHuman(val3.currentPlayer.data))
					{
						return true;
					}
				}
			}
			return false;
		}

		[HarmonyPatch(typeof(CharacterSelectionInstance), "Update")]
		[HarmonyPrefix]
		[HarmonyPriority(800)]
		public static void CharacterSelectionInstance_Update_Prefix(CharacterSelectionInstance __instance)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!((Object)(object)__instance != (Object)null) || !((Object)(object)__instance.currentPlayer != (Object)null) || !((Object)(object)__instance.currentPlayer.data != (Object)null))
				{
					return;
				}
				CharacterData data = __instance.currentPlayer.data;
				SanitizePlayerActions(data);
				if (IsKeyboardHuman(data))
				{
					if ((Object)(object)data.input != (Object)null)
					{
						data.input.inputType = (InputType)1;
					}
					if (data.playerActions != null)
					{
						((PlayerActionSet)data.playerActions).Device = null;
					}
				}
			}
			catch
			{
			}
		}

		public static void AssignColorID_Prefix(Player instance, ref int colorID)
		{
			if (colorID < 0)
			{
				colorID = 0;
			}
		}

		public static void SanitizePlayerActions(CharacterData data)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)data == (Object)null)
			{
				return;
			}
			if (IsAI(data))
			{
				if (data.playerActions == null)
				{
					data.playerActions = new PlayerActions();
				}
				((PlayerActionSet)data.playerActions).Device = InputDevice.Null;
				return;
			}
			if (data.playerActions != null && ((PlayerActionSet)data.playerActions).Device != null && ((PlayerActionSet)data.playerActions).Device != InputDevice.Null && data.playerActions.Aim != null)
			{
				Vector2 vector = ((TwoAxisInputControl)data.playerActions.Aim).Vector;
				if (((Vector2)(ref vector)).magnitude > 0.15f)
				{
					return;
				}
			}
			if ((Object)(object)data.input != (Object)null)
			{
				data.input.inputType = (InputType)1;
			}
			if (data.playerActions == null)
			{
				data.playerActions = PlayerActions.CreateWithKeyboardBindings();
			}
			((PlayerActionSet)data.playerActions).Device = null;
		}

		public static bool IsRemotePlayer(CharacterData data)
		{
			if ((Object)(object)data == (Object)null)
			{
				return false;
			}
			try
			{
				if (!PhotonNetwork.InRoom || PhotonNetwork.OfflineMode)
				{
					return false;
				}
				if ((Object)(object)data.view != (Object)null && !data.view.IsMine)
				{
					return true;
				}
			}
			catch
			{
			}
			return false;
		}

		[HarmonyPatch(typeof(GeneralInput), "Update")]
		[HarmonyPrefix]
		[HarmonyPriority(800)]
		public static void GeneralInput_Update_Prefix(GeneralInput __instance)
		{
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)__instance == (Object)null)
				{
					return;
				}
				CharacterData component = ((Component)__instance).GetComponent<CharacterData>();
				if ((Object)(object)component == (Object)null || IsAI(component) || IsRemotePlayer(component))
				{
					return;
				}
				__instance.controlledElseWhere = false;
				if (component.playerActions != null && ((PlayerActionSet)component.playerActions).Device != null && ((PlayerActionSet)component.playerActions).Device != InputDevice.Null && component.playerActions.Aim != null)
				{
					Vector2 vector = ((TwoAxisInputControl)component.playerActions.Aim).Vector;
					if (((Vector2)(ref vector)).magnitude > 0.15f)
					{
						return;
					}
				}
				if (component.playerActions == null)
				{
					component.playerActions = PlayerActions.CreateWithKeyboardBindings();
				}
				((PlayerActionSet)component.playerActions).Device = null;
				__instance.inputType = (InputType)1;
				if ((Object)(object)MainCam.instance == (Object)null)
				{
					Camera val = Camera.main ?? Object.FindObjectOfType<Camera>();
					if ((Object)(object)val != (Object)null)
					{
						MainCam obj = new GameObject("MainCam").AddComponent<MainCam>();
						obj.cam = val;
						MainCam.instance = obj;
					}
				}
				else if ((Object)(object)MainCam.instance.cam == (Object)null)
				{
					MainCam.instance.cam = Camera.main ?? Object.FindObjectOfType<Camera>();
				}
			}
			catch
			{
			}
		}
	}
	public static class DecalCleanupPatch
	{
		public static void PurgeMapDebris()
		{
			try
			{
				if (FpsFixConfig.CleanMapDebrisAfterRound != null && !FpsFixConfig.CleanMapDebrisAfterRound.Value)
				{
					return;
				}
				RemoveAfterSeconds[] array = Object.FindObjectsOfType<RemoveAfterSeconds>();
				if (array != null)
				{
					foreach (RemoveAfterSeconds val in array)
					{
						if ((Object)(object)val != (Object)null && (Object)(object)((Component)val).gameObject != (Object)null && !((Object)(object)((Component)val).GetComponentInParent<Player>() != (Object)null) && !((Object)(object)((Component)val).GetComponent<Player>() != (Object)null) && !((Object)(object)((Component)val).GetComponentInParent<CharacterData>() != (Object)null) && !((Object)(object)((Component)val).GetComponentInParent<Gun>() != (Object)null))
						{
							Object.Destroy((Object)(object)((Component)val).gameObject);
						}
					}
				}
				DestructibleBoxDestruction[] array2 = Object.FindObjectsOfType<DestructibleBoxDestruction>();
				if (array2 == null)
				{
					return;
				}
				for (int j = 0; j < array2.Length; j++)
				{
					if ((Object)(object)array2[j] != (Object)null && (Object)(object)((Component)array2[j]).gameObject != (Object)null)
					{
						Object.Destroy((Object)(object)((Component)array2[j]).gameObject);
					}
				}
			}
			catch
			{
			}
		}
	}
	[HarmonyPatch]
	public static class EngineOptimizationPatch
	{
		private static bool isLogged;

		private static bool isCombatActive;

		private static bool hooksRegistered;

		public static void ApplyEngineSettings()
		{
			try
			{
				Application.runInBackground = true;
				QualitySettings.vSyncCount = 0;
				if (FpsFixConfig.SmoothFramePacing != null && FpsFixConfig.SmoothFramePacing.Value)
				{
					Application.targetFrameRate = 60;
				}
				else
				{
					Application.targetFrameRate = -1;
				}
				if (FpsFixConfig.EnsurePhysicsStability != null && FpsFixConfig.EnsurePhysicsStability.Value)
				{
					Physics2D.autoSyncTransforms = true;
					Physics2D.velocityIterations = 8;
					Physics2D.positionIterations = 3;
					Physics2D.reuseCollisionCallbacks = false;
				}
				if (!isLogged)
				{
					isLogged = true;
					ManualLogSource logger = RoundsPatchFpsFixPlugin.Logger;
					if (logger != null)
					{
						string[] obj = new string[11]
						{
							"[RoundsPatchFpsFix] Engine settings active: targetFPS=", null, null, null, null, null, null, null, null, null,
							null
						};
						ConfigEntry<bool> smoothFramePacing = FpsFixConfig.SmoothFramePacing;
						obj[1] = ((smoothFramePacing != null && smoothFramePacing.Value) ? "60 (stable)" : "unlocked");
						obj[2] = ", autoSyncTransforms=true, LogSilence=";
						ConfigEntry<bool> silenceCombatLogSpam = FpsFixConfig.SilenceCombatLogSpam;
						obj[3] = ((silenceCombatLogSpam != null && silenceCombatLogSpam.Value) ? "ON" : "OFF");
						obj[4] = ", AudioLimiter=";
						ConfigEntry<bool> limitAudioConcurrency = FpsFixConfig.LimitAudioConcurrency;
						obj[5] = ((limitAudioConcurrency != null && limitAudioConcurrency.Value) ? "ON" : "OFF");
						obj[6] = ", RayCastNonAlloc=";
						ConfigEntry<bool> optimizeRayCastTrails = FpsFixConfig.OptimizeRayCastTrails;
						obj[7] = ((optimizeRayCastTrails != null && optimizeRayCastTrails.Value) ? "ON" : "OFF");
						obj[8] = ", TrailOptimizer=";
						ConfigEntry<bool> optimizeBulletTrails = FpsFixConfig.OptimizeBulletTrails;
						obj[9] = ((optimizeBulletTrails != null && optimizeBulletTrails.Value) ? "ON" : "OFF");
						obj[10] = ".";
						logger.LogInfo((object)string.Concat(obj));
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger2 = RoundsPatchFpsFixPlugin.Logger;
				if (logger2 != null)
				{
					logger2.LogWarning((object)("[RoundsPatchFpsFix] Engine optimization note: " + ex.Message));
				}
			}
		}

		public static void OnBattleStart()
		{
			if (isCombatActive)
			{
				return;
			}
			isCombatActive = true;
			AudioConcurrencyLimiterPatch.ResetThrottles();
			if (FpsFixConfig.SilenceCombatLogSpam == null || !FpsFixConfig.SilenceCombatLogSpam.Value)
			{
				return;
			}
			try
			{
				Debug.unityLogger.logEnabled = false;
			}
			catch
			{
			}
		}

		public static void OnBattleEnd()
		{
			if (isCombatActive)
			{
				isCombatActive = false;
				try
				{
					Debug.unityLogger.logEnabled = true;
				}
				catch
				{
				}
				DecalCleanupPatch.PurgeMapDebris();
				AudioConcurrencyLimiterPatch.ResetThrottles();
			}
		}

		public static void RegisterUnboundHooks()
		{
			if (hooksRegistered)
			{
				return;
			}
			hooksRegistered = true;
			try
			{
				GameModeManager.AddHook("BattleStart", (Func<IGameModeHandler, IEnumerator>)OnBattleStartHook);
				GameModeManager.AddHook("RoundEnd", (Func<IGameModeHandler, IEnumerator>)OnBattleEndHook);
				GameModeManager.AddHook("GameEnd", (Func<IGameModeHandler, IEnumerator>)OnBattleEndHook);
				ManualLogSource logger = RoundsPatchFpsFixPlugin.Logger;
				if (logger != null)
				{
					logger.LogInfo((object)"[RoundsPatchFpsFix] UnboundLib battle lifecycle hooks registered.");
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger2 = RoundsPatchFpsFixPlugin.Logger;
				if (logger2 != null)
				{
					logger2.LogWarning((object)("[RoundsPatchFpsFix] Could not register UnboundLib hooks: " + ex.Message));
				}
			}
		}

		private static IEnumerator OnBattleStartHook(IGameModeHandler gm)
		{
			OnBattleStart();
			yield break;
		}

		private static IEnumerator OnBattleEndHook(IGameModeHandler gm)
		{
			OnBattleEnd();
			yield break;
		}

		[HarmonyPatch(typeof(MainMenuHandler), "Awake")]
		[HarmonyPostfix]
		public static void Postfix_MainMenu()
		{
			OnBattleEnd();
			ApplyEngineSettings();
			try
			{
				if (RoundsPatchFpsFixPlugin.HarmonyInstance != null)
				{
					ModSafetyFixesPatch.Apply(RoundsPatchFpsFixPlugin.HarmonyInstance);
				}
			}
			catch
			{
			}
		}

		[HarmonyPatch(typeof(LowFrameRate), "OnJoinedRoom")]
		[HarmonyPrefix]
		public static bool Prefix_LowFrameRate()
		{
			return false;
		}

		[HarmonyPatch(typeof(Optionshandler), "ApplyOptions")]
		[HarmonyPostfix]
		public static void Postfix_ApplyOptions()
		{
			ApplyEngineSettings();
		}
	}
	[HarmonyPatch]
	public static class LegRendererSafetyPatch
	{
		private static readonly FieldInfo StartField = AccessTools.Field(typeof(LegRenderer), "start");

		private static readonly FieldInfo MidField = AccessTools.Field(typeof(LegRenderer), "mid");

		private static readonly FieldInfo EndField = AccessTools.Field(typeof(LegRenderer), "end");

		private static readonly FieldInfo SegmentsField = AccessTools.Field(typeof(LegRenderer), "segments");

		[HarmonyPatch(typeof(LegRenderer), "LateUpdate")]
		[HarmonyPrefix]
		public static bool Prefix_LegRenderer(LegRenderer __instance)
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)__instance == (Object)null)
				{
					return false;
				}
				object? obj = StartField?.GetValue(__instance);
				Transform val = (Transform)((obj is Transform) ? obj : null);
				object? obj2 = MidField?.GetValue(__instance);
				Transform val2 = (Transform)((obj2 is Transform) ? obj2 : null);
				object? obj3 = EndField?.GetValue(__instance);
				Transform val3 = (Transform)((obj3 is Transform) ? obj3 : null);
				IList list = SegmentsField?.GetValue(__instance) as IList;
				if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null || list == null || list.Count < 2)
				{
					return false;
				}
				Vector3 val4 = val.position - val3.position;
				if (((Vector3)(ref val4)).sqrMagnitude < 0.0001f)
				{
					goto IL_0100;
				}
				val4 = val.position - val2.position;
				if (((Vector3)(ref val4)).sqrMagnitude < 0.0001f)
				{
					goto IL_0100;
				}
				val4 = val2.position - val3.position;
				if (((Vector3)(ref val4)).sqrMagnitude < 0.0001f)
				{
					goto IL_0100;
				}
				goto end_IL_0000;
				IL_0100:
				return false;
				end_IL_0000:;
			}
			catch
			{
				return false;
			}
			return true;
		}
	}
	public static class ModSafetyFixesPatch
	{
		private static bool _isApplying;

		private static bool _patchedRwfFollow;

		private static bool _patchedWwcFollow;

		private static bool _patchedRwfSpotlight;

		private static bool _patchedUnboundColor;

		private static bool _patchedGoBack;

		private static bool _patchedDeckCustomization;

		private static bool _patchedCardsPlus;

		private static bool _patchedDemonicPact;

		private static bool _patchedModdingUtils;

		private static bool _patchedPCE;

		private static bool _patchedWWCPlasma;

		private static bool _patchedRwfRoomHandler;

		private static bool _patchedClientSideBlock;

		private static bool _patchedToggleEffects;

		private static bool _patchedGravityPatch;

		private static bool _patchedPlayerManagerReset;

		private static bool _patchedPlayerFullReset;

		private static bool _patchedPerformanceImprovements;

		private static bool _patchedCosmicRounds;

		private static readonly MethodInfo PlayerFullResetMethod = AccessTools.Method(typeof(Player), "FullReset", (Type[])null, (Type[])null);

		private static readonly string[] CosmicRoundsProjectileTypes = new string[14]
		{
			"CR.MonoBehaviors.DroneMono", "CR.MonoBehaviors.CloudMono", "CR.MonoBehaviors.PulseMono", "CR.MonoBehaviors.DriveMono", "CR.MonoBehaviors.SunMono", "CR.MonoBehaviors.MeteorMono", "CR.MonoBehaviors.CometMono", "CR.MonoBehaviors.CareenMono", "CR.MonoBehaviors.AsteroidMono", "CR.MonoBehaviors.ShootingStarMono",
			"CR.MonoBehaviors.SatelliteMono", "CR.MonoBehaviors.BeeMono", "CR.MonoBehaviors.SquidMono", "CR.MonoBehaviors.MoonMono"
		};

		public static void Apply(Harmony harmony)
		{
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Expected O, but got Unknown
			//IL_093e: Unknown result type (might be due to invalid IL or missing references)
			//IL_094c: Expected O, but got Unknown
			//IL_09ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Expected O, but got Unknown
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Expected O, but got Unknown
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Expected O, but got Unknown
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c6: Expected O, but got Unknown
			//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d5: Expected O, but got Unknown
			//IL_0558: Unknown result type (might be due to invalid IL or missing references)
			//IL_0566: Expected O, but got Unknown
			//IL_05e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f7: Expected O, but got Unknown
			//IL_067a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0688: Expected O, but got Unknown
			//IL_070e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0719: Expected O, but got Unknown
			//IL_079c: Unknown result type (might be due to invalid IL or missing references)
			//IL_07aa: Expected O, but got Unknown
			//IL_082d: Unknown result type (might be due to invalid IL or missing references)
			//IL_083b: Expected O, but got Unknown
			//IL_08be: Unknown result type (might be due to invalid IL or missing references)
			//IL_08cc: Expected O, but got Unknown
			//IL_0a92: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aa0: Expected O, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_0423: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a03: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ae2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0af0: Expected O, but got Unknown
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_0be3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bc7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bce: Expected O, but got Unknown
			//IL_0bf7: Unknown result type (might be due to invalid IL or missing references)
			if (harmony == null || _isApplying)
			{
				return;
			}
			_isApplying = true;
			try
			{
				try
				{
					if (!_patchedRwfFollow)
					{
						Type type = AccessTools.TypeByName("RWF.UI.FollowPlayer");
						if (type != null)
						{
							MethodInfo methodInfo = AccessTools.Method(type, "Update", (Type[])null, (Type[])null);
							MethodInfo method = typeof(ModSafetyFixesPatch).GetMethod("FollowPlayer_Prefix", BindingFlags.Static | BindingFlags.NonPublic);
							if (methodInfo != null && method != null)
							{
								harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(method), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
								_patchedRwfFollow = true;
								ManualLogSource logger = RoundsPatchFpsFixPlugin.Logger;
								if (logger != null)
								{
									logger.LogInfo((object)"[RoundsPatchFpsFix] RWF FollowPlayer NRE safety patch applied.");
								}
							}
						}
					}
				}
				catch
				{
				}
				try
				{
					if (!_patchedWwcFollow)
					{
						Type type2 = AccessTools.TypeByName("WWC.UI.FollowPlayer");
						if (type2 != null)
						{
							MethodInfo methodInfo2 = AccessTools.Method(type2, "Update", (Type[])null, (Type[])null);
							MethodInfo method2 = typeof(ModSafetyFixesPatch).GetMethod("FollowPlayer_Prefix", BindingFlags.Static | BindingFlags.NonPublic);
							if (methodInfo2 != null && method2 != null)
							{
								harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
								_patchedWwcFollow = true;
								ManualLogSource logger2 = RoundsPatchFpsFixPlugin.Logger;
								if (logger2 != null)
								{
									logger2.LogInfo((object)"[RoundsPatchFpsFix] WWC FollowPlayer NRE safety patch applied.");
								}
							}
						}
					}
				}
				catch
				{
				}
				try
				{
					if (!_patchedRwfSpotlight)
					{
						Type type3 = AccessTools.TypeByName("RWF.UI.PlayerSpotlight");
						if (type3 != null)
						{
							MethodInfo methodInfo3 = AccessTools.Method(type3, "SetShadowOpacity", (Type[])null, (Type[])null);
							MethodInfo method3 = typeof(ModSafetyFixesPatch).GetMethod("Spotlight_Prefix", BindingFlags.Static | BindingFlags.NonPublic);
							if (methodInfo3 != null && method3 != null)
							{
								harmony.Patch((MethodBase)methodInfo3, new HarmonyMethod(method3), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
								_patchedRwfSpotlight = true;
								ManualLogSource logger3 = RoundsPatchFpsFixPlugin.Logger;
								if (logger3 != null)
								{
									logger3.LogInfo((object)"[RoundsPatchFpsFix] RWF PlayerSpotlight NRE safety patch applied.");
								}
							}
						}
					}
				}
				catch
				{
				}
				try
				{
					if (!_patchedUnboundColor)
					{
						Type type4 = AccessTools.TypeByName("UnboundLib.Extensions.PlayerExtensions");
						if (type4 != null)
						{
							MethodInfo methodInfo4 = AccessTools.Method(type4, "AssignColorID", (Type[])null, (Type[])null);
							MethodInfo method4 = typeof(BotSafetyFixPatch).GetMethod("AssignColorID_Prefix", BindingFlags.Static | BindingFlags.Public);
							if (methodInfo4 != null && method4 != null)
							{
								harmony.Patch((MethodBase)methodInfo4, new HarmonyMethod(method4), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
								_patchedUnboundColor = true;
								ManualLogSource logger4 = RoundsPatchFpsFixPlugin.Logger;
								if (logger4 != null)
								{
									logger4.LogInfo((object)"[RoundsPatchFpsFix] UnboundLib AssignColorID safety patch applied.");
								}
							}
						}
					}
				}
				catch
				{
				}
				try
				{
					if (!_patchedGoBack)
					{
						MethodInfo methodInfo5 = AccessTools.Method(typeof(GoBack), "Update", (Type[])null, (Type[])null);
						MethodInfo method5 = typeof(ModSafetyFixesPatch).GetMethod("GoBack_Update_Prefix", BindingFlags.Static | BindingFlags.NonPublic);
						if (methodInfo5 != null && method5 != null)
						{
							harmony.Patch((MethodBase)methodInfo5, new HarmonyMethod(method5), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
							_patchedGoBack = true;
							ManualLogSource logger5 = RoundsPatchFpsFixPlugin.Logger;
							if (logger5 != null)
							{
								logger5.LogInfo((object)"[RoundsPatchFpsFix] GoBack.Update NRE safety patch applied.");
							}
						}
					}
				}
				catch
				{
				}
				try
				{
					if (!_patchedDeckCustomization)
					{
						Type type5 = AccessTools.TypeByName("DeckCustomization.RarityUtils");
						if (type5 != null)
						{
							MethodInfo methodInfo6 = AccessTools.Method(type5, "GetThemeColor", (Type[])null, (Type[])null);
							MethodInfo method6 = typeof(ModSafetyFixesPatch).GetMethod("DeckCustomization_GetThemeColor_Prefix", BindingFlags.Static | BindingFlags.NonPublic);
							if (methodInfo6 != null && method6 != null)
							{
								harmony.Patch((MethodBase)methodInfo6, new HarmonyMethod(method6), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
								_patchedDeckCustomization = true;
								ManualLogSource logger6 = RoundsPatchFpsFixPlugin.Logger;
								if (logger6 != null)
								{
									logger6.LogInfo((object)"[RoundsPatchFpsFix] DeckCustomization GetThemeColor safety patch applied.");
								}
							}
						}
					}
				}
				catch
				{
				}
				try
				{
					if (!_patchedCardsPlus)
					{
						Type type6 = AccessTools.TypeByName("CardsPlusPlugin.Cards.Cyberpunk.CyberCardEffect");
						if (type6 != null)
						{
							MethodInfo methodInfo7 = AccessTools.Method(type6, "SetFont", (Type[])null, (Type[])null);
							MethodInfo method7 = typeof(ModSafetyFixesPatch).GetMethod("CyberCardEffect_SetFont_Prefix", BindingFlags.Static | BindingFlags.NonPublic);
							if (methodInfo7 != null && method7 != null)
							{
								harmony.Patch((MethodBase)methodInfo7, new HarmonyMethod(method7), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
							}
							MethodInfo methodInfo8 = AccessTools.Method(type6, "CreateFrame", (Type[])null, (Type[])null);
							MethodInfo method8 = typeof(ModSafetyFixesPatch).GetMethod("CyberCardEffect_CreateFrame_Prefix", BindingFlags.Static | BindingFlags.NonPublic);
							MethodInfo method9 = typeof(ModSafetyFixesPatch).GetMethod("CyberCardEffect_CreateFrame_Finalizer", BindingFlags.Static | BindingFlags.NonPublic);
							if (methodInfo8 != null)
							{
								harmony.Patch((MethodBase)methodInfo8, (!(method8 != null)) ? ((HarmonyMethod)null) : new HarmonyMethod(method8), (HarmonyMethod)null, (HarmonyMethod)null, (!(method9 != null)) ? ((HarmonyMethod)null) : new HarmonyMethod(method9), (HarmonyMethod)null);
							}
							_patchedCardsPlus = true;
							ManualLogSource logger7 = RoundsPatchFpsFixPlugin.Logger;
							if (logger7 != null)
							{
								logger7.LogInfo((object)"[RoundsPatchFpsFix] CardsPlus CyberCardEffect safety patch applied.");
							}
						}
					}
				}
				catch
				{
				}
				try
				{
					if (!_patchedDemonicPact)
					{
						Type type7 = AccessTools.TypeByName("DemonicPactPatch.PlayerPatchFullReset");
						if (type7 != null)
						{
							MethodInfo methodInfo9 = AccessTools.Method(type7, "Prefix", (Type[])null, (Type[])null);
							MethodInfo method10 = typeof(ModSafetyFixesPatch).GetMethod("DemonicPact_Prefix_Guard", BindingFlags.Static | BindingFlags.NonPublic);
							if (methodInfo9 != null && method10 != null)
							{
								harmony.Patch((MethodBase)methodInfo9, new HarmonyMethod(method10), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
								_patchedDemonicPact = true;
								ManualLogSource logger8 = RoundsPatchFpsFixPlugin.Logger;
								if (logger8 != null)
								{
									logger8.LogInfo((object)"[RoundsPatchFpsFix] DemonicPactPatch.PlayerPatchFullReset safety patch applied.");
								}
							}
						}
					}
				}
				catch
				{
				}
				try
				{
					if (!_patchedModdingUtils)
					{
						Type type8 = AccessTools.TypeByName("ModdingUtils.Patches.PlayerPatchFullReset");
						if (type8 != null)
						{
							MethodInfo methodInfo10 = AccessTools.Method(type8, "Prefix", (Type[])null, (Type[])null);
							MethodInfo method11 = typeof(ModSafetyFixesPatch).GetMethod("DemonicPact_Prefix_Guard", BindingFlags.Static | BindingFlags.NonPublic);
							if (methodInfo10 != null && method11 != null)
							{
								harmony.Patch((MethodBase)methodInfo10, new HarmonyMethod(method11), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
								_patchedModdingUtils = true;
								ManualLogSource logger9 = RoundsPatchFpsFixPlugin.Logger;
								if (logger9 != null)
								{
									logger9.LogInfo((object)"[RoundsPatchFpsFix] ModdingUtils.Patches.PlayerPatchFullReset safety patch applied.");
								}
							}
						}
					}
				}
				catch
				{
				}
				try
				{
					if (!_patchedWWCPlasma)
					{
						Type type9 = AccessTools.TypeByName("WWC.MonoBehaviours.PlasmaWeapon_Mono");
						if (type9 != null)
						{
							MethodInfo methodInfo11 = AccessTools.Method(type9, "UpdateChargeBar", (Type[])null, (Type[])null);
							MethodInfo method12 = typeof(ModSafetyFixesPatch).GetMethod("PlasmaWeapon_UpdateChargeBar_Prefix", BindingFlags.Static | BindingFlags.NonPublic);
							if (methodInfo11 != null && method12 != null)
							{
								harmony.Patch((MethodBase)methodInfo11, new HarmonyMethod(method12), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
								_patchedWWCPlasma = true;
								ManualLogSource logger10 = RoundsPatchFpsFixPlugin.Logger;
								if (logger10 != null)
								{
									logger10.LogInfo((object)"[RoundsPatchFpsFix] WWC PlasmaWeapon_Mono.UpdateChargeBar safety patch applied.");
								}
							}
						}
					}
				}
				catch
				{
				}
				try
				{
					if (!_patchedRwfRoomHandler)
					{
						Type type10 = AccessTools.TypeByName("RWF.PrivateRoomHandler");
						if (type10 != null)
						{
							MethodInfo methodInfo12 = AccessTools.Method(type10, "SetGameSettings", (Type[])null, (Type[])null);
							MethodInfo method13 = typeof(ModSafetyFixesPatch).GetMethod("PrivateRoomHandler_SetGameSettings_Prefix", BindingFlags.Static | BindingFlags.NonPublic);
							if (methodInfo12 != null && method13 != null)
							{
								harmony.Patch((MethodBase)methodInfo12, new HarmonyMethod(method13), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
								_patchedRwfRoomHandler = true;
								ManualLogSource logger11 = RoundsPatchFpsFixPlugin.Logger;
								if (logger11 != null)
								{
									logger11.LogInfo((object)"[RoundsPatchFpsFix] RWF PrivateRoomHandler.SetGameSettings safety patch applied.");
								}
							}
						}
					}
				}
				catch
				{
				}
				try
				{
					if (!_patchedClientSideBlock)
					{
						Type type11 = AccessTools.TypeByName("ClientSideBlock.ProjectileHitPatch+<HitCoroutine>d__1");
						if (type11 != null)
						{
							MethodInfo methodInfo13 = AccessTools.Method(type11, "MoveNext", (Type[])null, (Type[])null);
							MethodInfo method14 = typeof(ModSafetyFixesPatch).GetMethod("HitCoroutine_MoveNext_Finalizer", BindingFlags.Static | BindingFlags.NonPublic);
							if (methodInfo13 != null && method14 != null)
							{
								harmony.Patch((MethodBase)methodInfo13, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(method14), (HarmonyMethod)null);
								_patchedClientSideBlock = true;
								ManualLogSource logger12 = RoundsPatchFpsFixPlugin.Logger;
								if (logger12 != null)
								{
									logger12.LogInfo((object)"[RoundsPatchFpsFix] ClientSideBlock ProjectileHitPatch safety patch applied.");
								}
							}
						}
					}
				}
				catch
				{
				}
				try
				{
					if (!_patchedPCE)
					{
						Type type12 = AccessTools.TypeByName("PCE.Patches.PlayerPatchFullReset");
						if (type12 != null)
						{
							MethodInfo methodInfo14 = AccessTools.Method(type12, "Prefix", (Type[])null, (Type[])null);
							MethodInfo method15 = typeof(ModSafetyFixesPatch).GetMethod("DemonicPact_Prefix_Guard", BindingFlags.Static | BindingFlags.NonPublic);
							if (methodInfo14 != null && method15 != null)
							{
								harmony.Patch((MethodBase)methodInfo14, new HarmonyMethod(method15), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
								_patchedPCE = true;
								ManualLogSource logger13 = RoundsPatchFpsFixPlugin.Logger;
								if (logger13 != null)
								{
									logger13.LogInfo((object)"[RoundsPatchFpsFix] PCE.Patches.PlayerPatchFullReset safety patch applied.");
								}
							}
						}
					}
				}
				catch
				{
				}
				try
				{
					if (!_patchedToggleEffects)
					{
						Type type13 = AccessTools.TypeByName("RoundsToggleEffectsMod.ToggleEffectsMod");
						if (type13 != null)
						{
							MethodInfo methodInfo15 = AccessTools.Method(type13, "OnChromaticAbberationToggled", (Type[])null, (Type[])null);
							MethodInfo method16 = typeof(ModSafetyFixesPatch).GetMethod("OnChromaticAbberationToggled_Prefix", BindingFlags.Static | BindingFlags.NonPublic);
							if (methodInfo15 != null && method16 != null)
							{
								harmony.Patch((MethodBase)methodInfo15, new HarmonyMethod(method16), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
								_patchedToggleEffects = true;
								ManualLogSource logger14 = RoundsPatchFpsFixPlugin.Logger;
								if (logger14 != null)
								{
									logger14.LogInfo((object)"[RoundsPatchFpsFix] RoundsToggleEffectsMod chromatic aberration safety patch applied.");
								}
							}
						}
					}
				}
				catch
				{
				}
				try
				{
					if (!_patchedGravityPatch)
					{
						Type type14 = AccessTools.TypeByName("Gravity_Patch.Patch");
						if (type14 != null)
						{
							MethodInfo methodInfo16 = AccessTools.Method(type14, "Prefix", (Type[])null, (Type[])null);
							MethodInfo method17 = typeof(ModSafetyFixesPatch).GetMethod("DemonicPact_Prefix_Guard", BindingFlags.Static | BindingFlags.NonPublic);
							if (methodInfo16 != null && method17 != null)
							{
								harmony.Patch((MethodBase)methodInfo16, new HarmonyMethod(method17), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
								_patchedGravityPatch = true;
								ManualLogSource logger15 = RoundsPatchFpsFixPlugin.Logger;
								if (logger15 != null)
								{
									logger15.LogInfo((object)"[RoundsPatchFpsFix] Gravity_Patch.Patch safety patch applied.");
								}
							}
						}
					}
				}
				catch
				{
				}
				try
				{
					if (!_patchedPlayerManagerReset)
					{
						MethodInfo methodInfo17 = AccessTools.Method(typeof(PlayerManager), "ResetCharacters", (Type[])null, (Type[])null);
						MethodInfo method18 = typeof(ModSafetyFixesPatch).GetMethod("PlayerManager_ResetCharacters_Prefix", BindingFlags.Static | BindingFlags.NonPublic);
						if (methodInfo17 != null && method18 != null)
						{
							harmony.Patch((MethodBase)methodInfo17, new HarmonyMethod(method18), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
							_patchedPlayerManagerReset = true;
							ManualLogSource logger16 = RoundsPatchFpsFixPlugin.Logger;
							if (logger16 != null)
							{
								logger16.LogInfo((object)"[RoundsPatchFpsFix] PlayerManager.ResetCharacters cleanup safety patch applied.");
							}
						}
					}
				}
				catch
				{
				}
				try
				{
					if (!_patchedPlayerFullReset)
					{
						MethodInfo methodInfo18 = AccessTools.Method(typeof(Player), "FullReset", (Type[])null, (Type[])null);
						MethodInfo method19 = typeof(ModSafetyFixesPatch).GetMethod("Player_FullReset_Prefix", BindingFlags.Static | BindingFlags.NonPublic);
						MethodInfo method20 = typeof(ModSafetyFixesPatch).GetMethod("Player_FullReset_Finalizer", BindingFlags.Static | BindingFlags.NonPublic);
						if (methodInfo18 != null)
						{
							harmony.Patch((MethodBase)methodInfo18, (!(method19 != null)) ? ((HarmonyMethod)null) : new HarmonyMethod(method19, 800, (string[])null, (string[])null, (bool?)null), (HarmonyMethod)null, (HarmonyMethod)null, (!(method20 != null)) ? ((HarmonyMethod)null) : new HarmonyMethod(method20), (HarmonyMethod)null);
							_patchedPlayerFullReset = true;
							ManualLogSource logger17 = RoundsPatchFpsFixPlugin.Logger;
							if (logger17 != null)
							{
								logger17.LogInfo((object)"[RoundsPatchFpsFix] Player.FullReset root guard and finalizer applied.");
							}
						}
					}
				}
				catch
				{
				}
				try
				{
					if (!_patchedPerformanceImprovements)
					{
						Type type15 = AccessTools.TypeByName("PerformanceImprovements.PerformanceImprovements");
						if (type15 != null)
						{
							MethodInfo methodInfo19 = AccessTools.PropertyGetter(type15, "DisablePlayerParticles");
							MethodInfo method21 = typeof(ModSafetyFixesPatch).GetMethod("DisablePlayerParticles_Prefix", BindingFlags.Static | BindingFlags.NonPublic);
							if (methodInfo19 != null && method21 != null)
							{
								harmony.Patch((MethodBase)methodInfo19, new HarmonyMethod(method21), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
							}
							MethodInfo methodInfo20 = AccessTools.Method(type15, "CycleArt", (Type[])null, (Type[])null);
							MethodInfo method22 = typeof(ModSafetyFixesPatch).GetMethod("CycleArt_Prefix", BindingFlags.Static | BindingFlags.NonPublic);
							if (methodInfo20 != null && method22 != null)
							{
								harmony.Patch((MethodBase)methodInfo20, new HarmonyMethod(method22), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
							}
							_patchedPerformanceImprovements = true;
							ManualLogSource logger18 = RoundsPatchFpsFixPlugin.Logger;
							if (logger18 != null)
							{
								logger18.LogInfo((object)"[RoundsPatchFpsFix] PerformanceImprovements player model and art glitch protection applied.");
							}
						}
					}
				}
				catch
				{
				}
				try
				{
					if (_patchedCosmicRounds)
					{
						return;
					}
					MethodInfo method23 = typeof(ModSafetyFixesPatch).GetMethod("CosmicRounds_Start_Transpiler", BindingFlags.Static | BindingFlags.NonPublic);
					MethodInfo method24 = typeof(ModSafetyFixesPatch).GetMethod("CosmicRounds_Start_Finalizer", BindingFlags.Static | BindingFlags.NonPublic);
					MethodInfo method25 = typeof(ModSafetyFixesPatch).GetMethod("CareenMono_Start_Prefix", BindingFlags.Static | BindingFlags.NonPublic);
					int num = 0;
					string[] cosmicRoundsProjectileTypes = CosmicRoundsProjectileTypes;
					foreach (string text in cosmicRoundsProjectileTypes)
					{
						Type type16 = AccessTools.TypeByName(text);
						if (!(type16 != null))
						{
							continue;
						}
						MethodInfo methodInfo21 = AccessTools.Method(type16, "Start", (Type[])null, (Type[])null);
						if (methodInfo21 != null)
						{
							HarmonyMethod val = null;
							if (text == "CR.MonoBehaviors.CareenMono" && method25 != null)
							{
								val = new HarmonyMethod(method25);
							}
							harmony.Patch((MethodBase)methodInfo21, val, (HarmonyMethod)null, (!(method23 != null)) ? ((HarmonyMethod)null) : new HarmonyMethod(method23), (!(method24 != null)) ? ((HarmonyMethod)null) : new HarmonyMethod(method24), (HarmonyMethod)null);
							num++;
						}
					}
					if (num > 0)
					{
						_patchedCosmicRounds = true;
						ManualLogSource logger19 = RoundsPatchFpsFixPlugin.Logger;
						if (logger19 != null)
						{
							logger19.LogInfo((object)$"[RoundsPatchFpsFix] CosmicRounds projectile safety patches applied ({num} cards protected).");
						}
					}
				}
				catch
				{
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger20 = RoundsPatchFpsFixPlugin.Logger;
				if (logger20 != null)
				{
					logger20.LogWarning((object)("[RoundsPatchFpsFix] Mod safety fixes note: " + ex.Message));
				}
			}
			finally
			{
				_isApplying = false;
			}
		}

		private static bool FollowPlayer_Prefix(Component __instance)
		{
			try
			{
				if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.gameObject == (Object)null)
				{
					return false;
				}
				Type type = ((object)__instance).GetType();
				object obj = null;
				PropertyInfo property = type.GetProperty("player", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (property != null)
				{
					obj = property.GetValue(__instance, null);
				}
				else
				{
					FieldInfo fieldInfo = type.GetField("player", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ?? type.GetField("<player>k__BackingField", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (fieldInfo != null)
					{
						obj = fieldInfo.GetValue(__instance);
					}
				}
				if (obj == null)
				{
					Object.Destroy((Object)(object)__instance.gameObject);
					return false;
				}
				Object val = (Object)((obj is Object) ? obj : null);
				if (val != null && val == (Object)null)
				{
					Object.Destroy((Object)(object)__instance.gameObject);
					return false;
				}
				Player val2 = (Player)((obj is Player) ? obj : null);
				if (val2 != null && ((Object)(object)val2 == (Object)null || (Object)(object)((Component)val2).gameObject == (Object)null || (Object)(object)((Component)val2).transform == (Object)null))
				{
					Object.Destroy((Object)(object)__instance.gameObject);
					return false;
				}
			}
			catch
			{
				return false;
			}
			return true;
		}

		private static bool Spotlight_Prefix()
		{
			try
			{
				PropertyInfo propertyInfo = AccessTools.Property(AccessTools.TypeByName("RWF.UI.PlayerSpotlight"), "BG");
				if (propertyInfo != null && propertyInfo.GetValue(null, null) == null)
				{
					return false;
				}
			}
			catch
			{
			}
			return true;
		}

		private static bool GoBack_Update_Prefix(GoBack __instance)
		{
			try
			{
				if ((Object)(object)__instance == (Object)null)
				{
					return false;
				}
				ReadOnlyCollection<InputDevice> activeDevices = InputManager.ActiveDevices;
				if (activeDevices != null)
				{
					for (int i = 0; i < activeDevices.Count; i++)
					{
						InputDevice val = activeDevices[i];
						if (val != null && val.Action2 != null && ((OneAxisInputControl)val.Action2).WasPressed)
						{
							UnityEvent goBackEvent = __instance.goBackEvent;
							if (goBackEvent != null)
							{
								goBackEvent.Invoke();
							}
							ListMenuPage target = __instance.target;
							if (target != null)
							{
								target.Open();
							}
						}
					}
				}
				if (Input.GetKeyDown((KeyCode)27))
				{
					UnityEvent goBackEvent2 = __instance.goBackEvent;
					if (goBackEvent2 != null)
					{
						goBackEvent2.Invoke();
					}
					ListMenuPage target2 = __instance.target;
					if (target2 != null)
					{
						target2.Open();
					}
				}
			}
			catch
			{
			}
			return false;
		}

		private static bool DeckCustomization_GetThemeColor_Prefix(CardThemeColorType theme, ref Color __result)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)CardChoice.instance != (Object)null && CardChoice.instance.cardThemes != null)
				{
					for (int i = 0; i < CardChoice.instance.cardThemes.Length; i++)
					{
						CardThemeColor val = CardChoice.instance.cardThemes[i];
						if (val != null && val.themeType == theme)
						{
							__result = val.targetColor;
							return false;
						}
					}
				}
			}
			catch
			{
			}
			__result = Color.white;
			return false;
		}

		private static bool CyberCardEffect_SetFont_Prefix(Component __instance)
		{
			try
			{
				if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.transform == (Object)null)
				{
					return false;
				}
				if (__instance.transform.childCount <= 0)
				{
					return false;
				}
			}
			catch
			{
				return false;
			}
			return true;
		}

		private static bool DemonicPact_Prefix_Guard(Player __instance)
		{
			if ((Object)(object)__instance == (Object)null || (Object)(object)((Component)__instance).gameObject == (Object)null || (Object)(object)__instance.data == (Object)null)
			{
				return false;
			}
			return true;
		}

		private static bool PlasmaWeapon_UpdateChargeBar_Prefix(MonoBehaviour __instance)
		{
			try
			{
				if ((Object)(object)__instance == (Object)null)
				{
					return false;
				}
				Type type = ((object)__instance).GetType();
				object? obj = AccessTools.Field(type, "gun")?.GetValue(__instance);
				Gun val = (Gun)((obj is Gun) ? obj : null);
				object? obj2 = AccessTools.Field(type, "chargeImage")?.GetValue(__instance);
				Image val2 = (Image)((obj2 is Image) ? obj2 : null);
				if ((Object)(object)val == (Object)null)
				{
					CharacterData componentInParent = ((Component)__instance).GetComponentInParent<CharacterData>();
					if ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent.weaponHandler != (Object)null && (Object)(object)componentInParent.weaponHandler.gun != (Object)null)
					{
						AccessTools.Field(type, "gun")?.SetValue(__instance, componentInParent.weaponHandler.gun);
						val = componentInParent.weaponHandler.gun;
					}
				}
				if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
				{
					return false;
				}
			}
			catch
			{
				return false;
			}
			return true;
		}

		private static bool PrivateRoomHandler_SetGameSettings_Prefix(string gameMode, GameSettings settings)
		{
			try
			{
				Type type = AccessTools.TypeByName("RWF.PrivateRoomHandler");
				if (type != null)
				{
					object obj = AccessTools.Field(type, "instance")?.GetValue(null);
					object obj2 = ((obj == null) ? null : AccessTools.Field(type, "gamemodeHeaderText")?.GetValue(obj));
					if (obj == null || obj2 == null)
					{
						GameModeManager.SetGameMode(gameMode);
						if (GameModeManager.CurrentHandler != null && settings != null)
						{
							GameModeManager.CurrentHandler.SetSettings(settings);
						}
						return false;
					}
				}
			}
			catch
			{
			}
			return true;
		}

		private static Exception HitCoroutine_MoveNext_Finalizer(Exception __exception, ref bool __result)
		{
			if (__exception != null)
			{
				__result = false;
				return null;
			}
			return null;
		}

		private static bool CyberCardEffect_CreateFrame_Prefix(Component __instance)
		{
			try
			{
				if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.gameObject == (Object)null)
				{
					return false;
				}
				if ((Object)(object)__instance.GetComponentInChildren<Canvas>() == (Object)null)
				{
					return false;
				}
				Type type = AccessTools.TypeByName("CardsPlusPlugin.Assets");
				if (type != null)
				{
					FieldInfo fieldInfo = AccessTools.Field(type, "ElectricFrame");
					if (fieldInfo != null && fieldInfo.GetValue(null) == null)
					{
						return false;
					}
				}
			}
			catch
			{
				return false;
			}
			return true;
		}

		private static Exception CyberCardEffect_CreateFrame_Finalizer(Exception __exception)
		{
			return null;
		}

		private static bool OnChromaticAbberationToggled_Prefix()
		{
			try
			{
				Type type = AccessTools.TypeByName("RoundsToggleEffectsMod.ToggleEffectsMod");
				if (type != null)
				{
					PropertyInfo propertyInfo = AccessTools.Property(type, "ChromaticAbberation");
					if (propertyInfo != null && propertyInfo.GetValue(null, null) == null)
					{
						return false;
					}
				}
			}
			catch
			{
				return false;
			}
			return true;
		}

		private static bool PlayerManager_ResetCharacters_Prefix(PlayerManager __instance)
		{
			try
			{
				if ((Object)(object)__instance == (Object)null || __instance.players == null)
				{
					return false;
				}
				CardBarHandler instance = CardBarHandler.instance;
				if (instance != null)
				{
					instance.ResetCardBards();
				}
				for (int i = 0; i < __instance.players.Count; i++)
				{
					Player val = __instance.players[i];
					if ((Object)(object)val != (Object)null && (Object)(object)((Component)val).gameObject != (Object)null && (Object)(object)val.data != (Object)null)
					{
						PlayerFullResetMethod?.Invoke(val, null);
					}
				}
				return false;
			}
			catch
			{
				return true;
			}
		}

		private static bool Player_FullReset_Prefix(Player __instance)
		{
			if ((Object)(object)__instance == (Object)null || (Object)(object)((Component)__instance).gameObject == (Object)null || (Object)(object)__instance.data == (Object)null)
			{
				return false;
			}
			return true;
		}

		private static Exception Player_FullReset_Finalizer(Exception __exception)
		{
			return null;
		}

		private static bool DisablePlayerParticles_Prefix(ref bool __result)
		{
			__result = false;
			return false;
		}

		private static bool CycleArt_Prefix()
		{
			return false;
		}

		public static void SafeSetSyncActive(SyncProjectile sync, bool val)
		{
			if ((Object)(object)sync != (Object)null)
			{
				sync.active = val;
			}
		}

		private static IEnumerable<CodeInstruction> CosmicRounds_Start_Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			MethodInfo safeMethod = AccessTools.Method(typeof(ModSafetyFixesPatch), "SafeSetSyncActive", (Type[])null, (Type[])null);
			foreach (CodeInstruction instruction in instructions)
			{
				if (instruction.opcode == OpCodes.Stfld && instruction.operand is FieldInfo { Name: "active" } fieldInfo && (fieldInfo.DeclaringType == typeof(SyncProjectile) || fieldInfo.DeclaringType?.Name == "SyncProjectile"))
				{
					yield return new CodeInstruction(OpCodes.Call, (object)safeMethod);
				}
				else
				{
					yield return instruction;
				}
			}
		}

		private static void CareenMono_Start_Prefix(MonoBehaviour __instance)
		{
			if ((Object)(object)__instance == (Object)null || (Object)(object)((Component)__instance).gameObject == (Object)null)
			{
				return;
			}
			try
			{
				if ((Object)(object)((Component)__instance).GetComponentInParent<RayHitReflect>() == (Object)null)
				{
					((Component)__instance).gameObject.AddComponent<RayHitReflect>();
				}
			}
			catch
			{
			}
		}

		private static Exception CosmicRounds_Start_Finalizer(Exception __exception)
		{
			if (__exception != null)
			{
				ManualLogSource logger = RoundsPatchFpsFixPlugin.Logger;
				if (logger != null)
				{
					logger.LogWarning((object)("[RoundsPatchFpsFix] Cleanly suppressed CosmicRounds projectile start exception: " + __exception.Message));
				}
			}
			return null;
		}
	}
	public static class RayCastTrailNonAllocPatch
	{
		public static bool Prefix()
		{
			return true;
		}
	}
	[HarmonyPatch]
	public static class TrailRendererOptimizationPatch
	{
		[HarmonyPatch(typeof(RayCastTrail), "Start")]
		[HarmonyPostfix]
		public static void RayCastTrail_Start_Postfix(RayCastTrail __instance)
		{
			try
			{
				if ((FpsFixConfig.OptimizeBulletTrails != null && !FpsFixConfig.OptimizeBulletTrails.Value) || (Object)(object)__instance == (Object)null)
				{
					return;
				}
				TrailRenderer componentInChildren = ((Component)__instance).GetComponentInChildren<TrailRenderer>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					if (componentInChildren.time > 0.2f)
					{
						componentInChildren.time = 0.2f;
					}
					if (componentInChildren.minVertexDistance < 0.1f)
					{
						componentInChildren.minVertexDistance = 0.1f;
					}
				}
			}
			catch
			{
			}
		}
	}
}