Decompiled source of Online Additions v1.9.5

OnlineAdditions.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Events;
using Events.ClientToServer;
using Events.Player;
using Events.RaceMode;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("OnlineAdditions")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OnlineAdditions")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("50d13268-78b0-436c-9ea3-b437940457e0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace OnlineAdditions
{
	[BepInPlugin("Distance.OnlineAdditions", "Online Additions", "1.9.5")]
	public sealed class Mod : BaseUnityPlugin
	{
		private const string modGUID = "Distance.OnlineAdditions";

		private const string modName = "Online Additions";

		private const string modVersion = "1.9.5";

		public static string EnableCollisionKey = "Enable Collision";

		public static string EnableCheatsKey = "Enable Cheats";

		public static string EnableEventsKey = "Enable Online Events";

		public static string DisableCarAudioKey = "Disable Car Audio";

		public static string DisableTimeoutKey = "Disable Timeout";

		public static string DisableMultiKillGridRenderKey = "Disable Multiplayer KillGrid Rendering";

		public static string HideChatKey = "Hide Chat";

		public static string HidePlayersKey = "Hide Player Names";

		public static string MaxLevelOfDetailKey = "Max Level Of Car Detail";

		public static string MaxPlayerKey = "Max Number of Players for Hosting Servers";

		public static string OutlineKey = "Adjust Brightness of Car Outlines";

		public static string TimeLimitKey = "Adjust Time Limit Amount";

		private static readonly Harmony harmony = new Harmony("Distance.OnlineAdditions");

		public static ManualLogSource Log = new ManualLogSource("Online Additions");

		public static Mod Instance;

		private bool activatingCollisions = false;

		public static ConfigEntry<bool> DisableCarAudio { get; set; }

		public static ConfigEntry<bool> DisableMultiKillGridRender { get; set; }

		public static ConfigEntry<bool> DisableTimeout { get; set; }

		public static ConfigEntry<bool> EnableCheats { get; set; }

		public static ConfigEntry<bool> EnableCollision { get; set; }

		public static ConfigEntry<bool> EnableOnlineEvents { get; set; }

		public static ConfigEntry<bool> HideChat { get; set; }

		public static ConfigEntry<bool> HidePlayerNames { get; set; }

		public static ConfigEntry<float> OutlineBrightness { get; set; }

		public static ConfigEntry<Level> MaxLevelOfDetail { get; set; }

		public static ConfigEntry<int> MaxPlayerCount { get; set; }

		public static ConfigEntry<int> TimeLimitAmount { get; set; }

		public bool allPlayersFinished { get; set; }

		public bool amIHost { get; set; }

		public bool countdownActive { get; set; }

		public bool playerFinished { get; set; }

		public bool selfRestart { get; set; }

		public bool uploadScore { get; set; }

		public GameObject playerCar { get; set; }

		public int countdownLength { get; set; }

		public List<PlayerDataNet> networkPlayers { get; set; }

		private void Awake()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Expected O, but got Unknown
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Expected O, but got Unknown
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Expected O, but got Unknown
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Expected O, but got Unknown
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Expected O, but got Unknown
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Expected O, but got Unknown
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Expected O, but got Unknown
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Expected O, but got Unknown
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Log = Logger.CreateLogSource("Distance.OnlineAdditions");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Thanks for using Online Additions!");
			networkPlayers = new List<PlayerDataNet>();
			DisableCarAudio = ((BaseUnityPlugin)this).Config.Bind<bool>("General", DisableCarAudioKey, false, new ConfigDescription("Toggles whether car audio from other cars in multiplayer are on.", (AcceptableValueBase)null, new object[0]));
			DisableMultiKillGridRender = ((BaseUnityPlugin)this).Config.Bind<bool>("General", DisableMultiKillGridRenderKey, false, new ConfigDescription("Disables the rendering of the kill grid for every player in multiplayer. The killgrid will only render for you!", (AcceptableValueBase)null, new object[0]));
			DisableTimeout = ((BaseUnityPlugin)this).Config.Bind<bool>("For Hosting", DisableTimeoutKey, false, new ConfigDescription("Completely disables the timeout when one player is left.", (AcceptableValueBase)null, new object[0]));
			MaxPlayerCount = ((BaseUnityPlugin)this).Config.Bind<int>("For Hosting", MaxPlayerKey, 30, new ConfigDescription("Adjust the max number of players that can join your server", (AcceptableValueBase)null, new object[0]));
			EnableCheats = ((BaseUnityPlugin)this).Config.Bind<bool>("Turns Off Leaderboard", EnableCheatsKey, false, new ConfigDescription("Toggle whether cheats can be enabled in multiplayer.", (AcceptableValueBase)null, new object[0]));
			EnableCollision = ((BaseUnityPlugin)this).Config.Bind<bool>("Turns Off Leaderboard", EnableCollisionKey, false, new ConfigDescription("Toggle whether collisions are enabled when playing online.", (AcceptableValueBase)null, new object[0]));
			EnableOnlineEvents = ((BaseUnityPlugin)this).Config.Bind<bool>("Turns Off Leaderboard", EnableEventsKey, false, new ConfigDescription("Toggle whether events get triggered by all players in multiplayer (Only works with Collisions on.) NOTE: CAN BREAK SEVERAL LEVELS!", (AcceptableValueBase)null, new object[0]));
			HideChat = ((BaseUnityPlugin)this).Config.Bind<bool>("General", HideChatKey, false, new ConfigDescription("Toggle whether the chat stays completely hidden in multiplayer.", (AcceptableValueBase)null, new object[0]));
			HidePlayerNames = ((BaseUnityPlugin)this).Config.Bind<bool>("General", HidePlayersKey, false, new ConfigDescription("Toggle whether online player names are visible.", (AcceptableValueBase)null, new object[0]));
			OutlineBrightness = ((BaseUnityPlugin)this).Config.Bind<float>("General", OutlineKey, 1f, new ConfigDescription("Adjust the brightness of the outlines on online player cars", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
			MaxLevelOfDetail = ((BaseUnityPlugin)this).Config.Bind<Level>("General", MaxLevelOfDetailKey, (Level)1, new ConfigDescription("The maximum detail online cars can have. This will lower the visual quality other cars have online. InFocus is the usual default. For an idea of how this looks, Speck turns off all animations of an online car.", (AcceptableValueBase)null, new object[0]));
			TimeLimitAmount = ((BaseUnityPlugin)this).Config.Bind<int>("For Hosting", TimeLimitKey, 60, new ConfigDescription("Adjust the amount of time is set when a time limit occurs", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 600), new object[0]));
			DisableCarAudio.SettingChanged += OnConfigChanged;
			DisableMultiKillGridRender.SettingChanged += OnConfigChanged;
			DisableTimeout.SettingChanged += OnConfigChanged;
			EnableCheats.SettingChanged += OnConfigChanged;
			EnableCollision.SettingChanged += OnConfigChanged;
			HideChat.SettingChanged += OnConfigChanged;
			HidePlayerNames.SettingChanged += OnConfigChanged;
			OutlineBrightness.SettingChanged += OnConfigChanged;
			MaxLevelOfDetail.SettingChanged += OnConfigChanged;
			MaxPlayerCount.SettingChanged += OnConfigChanged;
			TimeLimitAmount.SettingChanged += OnConfigChanged;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loading...");
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded!");
		}

		private void OnConfigChanged(object sender, EventArgs e)
		{
			SettingChangedEventArgs val = (SettingChangedEventArgs)(object)((e is SettingChangedEventArgs) ? e : null);
			if (val != null && (val.ChangedSetting.Definition.Key == EnableCollisionKey || val.ChangedSetting.Definition.Key == EnableCheatsKey || val.ChangedSetting.Definition.Key == EnableEventsKey))
			{
				uploadScore = false;
			}
		}

		public void ActivateRestart()
		{
			((MonoBehaviour)this).StartCoroutine(ActivateRestartAfterSeconds(2f));
		}

		public IEnumerator ActivateRestartAfterSeconds(float seconds)
		{
			yield return (object)new WaitForSeconds(seconds);
			playerCar = null;
			selfRestart = true;
			if (Instance.playerFinished && !Instance.countdownActive)
			{
				G.Sys.PlayerManager_.clientLogic_.UpdateLevelIfNecessaryThenGoToGameMode();
			}
		}

		public IEnumerator ActivateCollidersAfterSeconds(float seconds)
		{
			networkPlayers.RemoveAll((PlayerDataNet item) => (Object)(object)item == (Object)null);
			if (ListEx.IsNullOrEmpty<PlayerDataNet>(networkPlayers))
			{
				yield break;
			}
			activatingCollisions = true;
			foreach (PlayerDataNet playerNet2 in networkPlayers)
			{
				if ((Object)(object)((PlayerDataBase)playerNet2).CarLOD_ != (Object)null)
				{
					((PlayerDataBase)playerNet2).SetAllColliderLayers((Layers)12);
					((PlayerDataBase)playerNet2).CarLOD_.rigidbody_.isKinematic = false;
					((PlayerDataBase)playerNet2).CarLOD_.SetCarSimulationEnabled(false);
				}
			}
			yield return (object)new WaitForSeconds(seconds);
			activatingCollisions = false;
			if (Instance.playerFinished)
			{
				yield break;
			}
			networkPlayers.RemoveAll((PlayerDataNet item) => (Object)(object)item == (Object)null);
			foreach (PlayerDataNet playerNet in networkPlayers)
			{
				if ((Object)(object)((PlayerDataBase)playerNet).CarLOD_ != (Object)null)
				{
					((PlayerDataBase)playerNet).SetAllColliderLayers((Layers)17);
					((PlayerDataBase)playerNet).CarLOD_.rigidbody_.isKinematic = true;
					((PlayerDataBase)playerNet).CarLOD_.SetCarSimulationEnabled(true);
				}
			}
		}

		public IEnumerator ActivateCollidersAfterSeconds(float seconds, PlayerDataNet playerNet)
		{
			if (!activatingCollisions)
			{
				((PlayerDataBase)playerNet).SetAllColliderLayers((Layers)12);
				((PlayerDataBase)playerNet).CarLOD_.rigidbody_.isKinematic = false;
				((PlayerDataBase)playerNet).CarLOD_.SetCarSimulationEnabled(false);
				yield return (object)new WaitForSeconds(seconds);
				if ((Object)(object)((PlayerDataBase)playerNet).CarLOD_ != (Object)null)
				{
					((PlayerDataBase)playerNet).SetAllColliderLayers((Layers)17);
					((PlayerDataBase)playerNet).CarLOD_.rigidbody_.isKinematic = true;
					((PlayerDataBase)playerNet).CarLOD_.SetCarSimulationEnabled(true);
				}
			}
		}
	}
}
namespace OnlineAdditions.Patches
{
	[HarmonyPatch(typeof(CarLevelOfDetail), "IncrementLevel")]
	internal class CarLevelOfDetail__IncrementLevel
	{
		[HarmonyPostfix]
		internal static void MakeSureSimulationIsOn(CarLevelOfDetail __instance)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			if ((int)__instance.type_ == 0)
			{
				if (Mod.EnableCollision.Value && !Mod.Instance.playerFinished)
				{
					__instance.SetCarSimulationEnabled(true);
				}
				else if (Mod.Instance.playerFinished && __instance.rigidbody_.isKinematic)
				{
					__instance.rigidbodyStateTransceiver_.setCarOnFixedUpdate_ = false;
					__instance.rigidbody_.isKinematic = false;
				}
			}
		}
	}
	[HarmonyPatch(typeof(CarLevelOfDetail), "SetLevelOfDetail", new Type[] { typeof(Level) })]
	internal class CarLevelOfDetail__SetLevelOfDetail
	{
		[HarmonyPrefix]
		internal static bool MaxLevelDetail(CarLevelOfDetail __instance, Level newLevel)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			if (newLevel < Mod.MaxLevelOfDetail.Value && G.Sys.NetworkingManager_.IsOnline_)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(ChatInputV2), "CheckForServerCode", new Type[] { typeof(string) })]
	internal class ChatInputV2__CheckForServerCode
	{
		[HarmonyPrefix]
		internal static bool CheckForCommands(ChatInputV2 __instance, string text)
		{
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(text) || (text.Length > 0 && text[0] != '/'))
			{
				return true;
			}
			int num = text.IndexOf(" ");
			string text2 = string.Empty;
			bool flag = false;
			int result = 0;
			string text3;
			if (num != -1)
			{
				text3 = text.Substring(1, num - 1);
				text2 = text.Substring(num + 1, text.Length - num - 1);
				flag = int.TryParse(text2, out result);
			}
			else
			{
				text3 = text.Substring(1, text.Length - 1);
			}
			if (text3 != null && text3 == "timeout" && Mod.Instance.amIHost && !Mod.Instance.allPlayersFinished)
			{
				int num2 = ((!Regex.Match(text2, "^\\d+$").Success) ? Mod.TimeLimitAmount.Value : int.Parse(Regex.Match(text2, "^\\d+$").Value));
				StaticTargetedEvent<Data>.Broadcast((RPCMode)2, new Data(Timex.ModeTime_ + (double)num2, Mathf.RoundToInt((float)num2)));
				Mod.Instance.countdownActive = true;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(ChatWindow), "Update")]
	internal class Update__ChatWindow
	{
		[HarmonyPostfix]
		internal static void HideChatPost(ChatWindow __instance)
		{
			if (Mod.HideChat.Value)
			{
				((UIRect)__instance.panel_).alpha = 0f;
			}
		}
	}
	[HarmonyPatch(typeof(CheatMenu), "TweakCheat", new Type[] { typeof(ECheat) })]
	internal class TweakCheat__CheatMenu
	{
		[HarmonyPrefix]
		internal static bool CheckMotorcycleCheat(ECheat c)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			if ((int)c == 1 && Mod.EnableCheats.Value)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(CheatsManager), "OnEventSceneLoadFinished")]
	internal class CheatsManager__OnEventSceneLoadFinished
	{
		[HarmonyPrefix]
		internal static bool KeepCheatsPrefix(CheatsManager __instance)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			if (Mod.EnableCheats.Value && G.Sys.NetworkingManager_.IsOnline_)
			{
				__instance.gameplayCheatsRecognized_ = true;
			}
			else
			{
				__instance.gameplayCheatsRecognized_ = !G.Sys.NetworkingManager_.IsOnline_;
			}
			__instance.UpdateEnabledFlags();
			__instance.anyGameplayCheatsUsedThisLevel_ = __instance.AnyGameplayCheatsCurrentlyUsed_;
			return false;
		}
	}
	[HarmonyPatch(typeof(ClientLogic), "GetClientChatName")]
	internal class ClientLogic__GetClientChatName
	{
		[HarmonyPostfix]
		internal static void ModifyLocalPlayerName(ClientLogic __instance, ref string __result)
		{
			Regex regex = new Regex("(\\[)");
			string[] array = regex.Split(__result);
			string text = string.Empty;
			string text2 = string.Empty;
			if (Mod.EnableCheats.Value)
			{
				text = " (Cheating)";
			}
			if (Mod.EnableCollision.Value)
			{
				text2 += " (Collision)";
			}
			__result = array[1] + array[2] + text + text2 + array[3] + array[4];
		}
	}
	[HarmonyPatch(typeof(ClientLogic), "GetLocalChatName")]
	internal class ClientLogic__GetLocalChatName
	{
		[HarmonyPostfix]
		internal static void ModifyLocalPlayerName(ref string __result)
		{
			if (Mod.EnableCheats.Value)
			{
				__result += " (Cheating)";
			}
			if (Mod.EnableCollision.Value)
			{
				__result += " (Collision)";
			}
		}
	}
	[HarmonyPatch(typeof(GameMode), "UploadScoreAndReplay")]
	internal class GameMode__UploadScoreAndReplay
	{
		[HarmonyPrefix]
		internal static bool DoISkipMethod()
		{
			if (!Mod.Instance.uploadScore && G.Sys.NetworkingManager_.IsOnline_)
			{
				Mod.Log.LogInfo((object)"Skipping leaderboard upload because online collisions, cheats, or events were enabled");
				if (!Mod.EnableCollision.Value && !Mod.EnableCheats.Value && !Mod.EnableOnlineEvents.Value)
				{
					Mod.Instance.uploadScore = true;
				}
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(GUtils), "IsRelevantCar", new Type[] { typeof(Collider) })]
	internal class GUtils__IsRelevantCar
	{
		[HarmonyPostfix]
		internal static void IsRelevantNetworkCar(Collider car, ref PlayerDataBase __result)
		{
			if (!Mod.EnableOnlineEvents.Value || !G.Sys.NetworkingManager_.IsOnline_)
			{
				return;
			}
			if ((Object)(object)car != (Object)null)
			{
				CarLogic component = ((Component)car).GetComponent<CarLogic>();
				if ((Object)(object)component != (Object)null && ((Behaviour)component).enabled)
				{
					PlayerDataBase playerData_ = component.PlayerData_;
					if (playerData_.IsAliveAndNotFinished_)
					{
						__result = ((playerData_.IsCarRelevant_ || playerData_ is PlayerDataNet) ? playerData_ : null);
					}
				}
			}
			else
			{
				__result = null;
			}
		}
	}
	internal static class IncrementMaxPlayers
	{
		[HarmonyPatch(typeof(HostAGame), "IncrementMaxPlayers")]
		internal static class HostAGame__IncrementMaxPlayers
		{
			internal static bool Prefix(HostAGame __instance, int direction)
			{
				__instance.internalMaxPlayerCalc_ = GUtils.mod(__instance.internalMaxPlayerCalc_ + direction, Mod.MaxPlayerCount.Value);
				__instance.maxPlayersLabel_.text = __instance.MaxPlayers_.ToString();
				if (direction != 0 && AudioManager.Valid())
				{
					G.Sys.AudioManager_.PlaySound("ButtonSelect", "Menus", 1f);
				}
				return false;
			}
		}
	}
	[HarmonyPatch(typeof(KillGrid), "OnEventAddRemovePlayerData", new Type[] { typeof(Data) })]
	internal class KillGrid__OnEventAddRemovePlayerData
	{
		[HarmonyPrefix]
		internal static bool KillGridRenderControl(KillGrid __instance, Data data)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Invalid comparison between Unknown and I4
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Invalid comparison between Unknown and I4
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Expected O, but got Unknown
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Expected O, but got Unknown
			if (Mod.DisableMultiKillGridRender.Value)
			{
				if (data.added_)
				{
					if (!__instance.startCalled_)
					{
						Mod.Log.LogInfo((object)"start wasn't called yet");
					}
					if (__instance.isInvisible_)
					{
						return false;
					}
					if ((int)data.type_ == 1)
					{
						PlayerDataBase player_ = data.player_;
						PlayerDataReplay val2 = (PlayerDataReplay)(object)((player_ is PlayerDataReplay) ? player_ : null);
						if (Object.op_Implicit((Object)(object)val2) && val2.IsGhost_)
						{
							return false;
						}
					}
					if ((int)data.type_ == 2)
					{
						Mod.Log.LogInfo((object)"No killgrids for network car!");
						return false;
					}
					Renderer component = ((Component)__instance).GetComponent<Renderer>();
					__instance.CreateParentIfNeeded();
					GameObject val3 = Object.Instantiate<GameObject>(__instance.followerPrefab_);
					TransformExtensionOnly.SetParentKeepingLocalTransform(val3.transform, __instance.followerParent_);
					__instance.helpers_.Add(new KillGridFollowerHelper(data.player_, val3, component.sharedMaterial.color, __instance.curvature_, new PositionFollowerFn(__instance.PositionFollower)));
				}
				else
				{
					KillGridFollowerHelper val4 = __instance.helpers_.Find((KillGridFollowerHelper val) => (Object)(object)val.player_ == (Object)(object)data.player_);
					if (val4 == null)
					{
						return false;
					}
					val4.Destroy();
					__instance.helpers_.Remove(val4);
				}
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(PlayerDataLocal), "InitCarVirtual", new Type[] { typeof(bool) })]
	internal class PlayerDataLocal__InitCarVirtual
	{
		[HarmonyPostfix]
		internal static void GetCar(PlayerDataLocal __instance, bool fastRespawn)
		{
			Mod.Instance.playerCar = ((PlayerDataBase)__instance).carObj_;
			Mod.Instance.playerFinished = false;
			if (Mod.EnableCollision.Value && fastRespawn)
			{
				((MonoBehaviour)__instance).StartCoroutine(Mod.Instance.ActivateCollidersAfterSeconds(10f));
			}
		}
	}
	[HarmonyPatch(typeof(PlayerDataLocal), "LocalOnPlayerEventFinished")]
	internal class PlayerDataLocal__LocalOnPlayerEventFinished
	{
		[HarmonyPostfix]
		internal static void UpdatePlayerFinishedState()
		{
			Mod.Instance.playerFinished = true;
		}
	}
	[HarmonyPatch(typeof(PlayerDataNet), "AwakeVirtual")]
	internal class PlayerDataNet__AwakeVirtual
	{
		[HarmonyPostfix]
		internal static void SubscribeToEvent(PlayerDataNet __instance)
		{
			Mod.Instance.networkPlayers.Add(__instance);
		}
	}
	[HarmonyPatch(typeof(PlayerDataNet), "InitCarVirtual")]
	internal class PlayerDataNet__InitCarVirtual
	{
		[HarmonyPostfix]
		internal static void CollisionPostFix(PlayerDataNet __instance)
		{
			if (Mod.EnableCollision.Value)
			{
				LowerImpactDeath orAddComponent = GameObjectEx.GetOrAddComponent<LowerImpactDeath>(((PlayerDataBase)__instance).carObj_);
				orAddComponent.deathThresholdMultipler_ = 2.25f;
				((MonoBehaviour)__instance).StartCoroutine(Mod.Instance.ActivateCollidersAfterSeconds(10f, __instance));
			}
			if (Mod.HidePlayerNames.Value)
			{
				((PlayerDataBase)__instance).hoverNameObj_.SetActive(false);
			}
			if (Mod.DisableCarAudio.Value)
			{
				((PlayerDataBase)__instance).DisableCarSounds(((PlayerDataBase)__instance).carObj_);
			}
		}
	}
	[HarmonyPatch(typeof(PlayerDataBase), "SetOutlineColor")]
	internal class PlayerDataBase__SetOutlineColor
	{
		[HarmonyPrefix]
		internal static bool NetworkOutline(PlayerDataBase __instance)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			PlayerDataNet val = (PlayerDataNet)(object)((__instance is PlayerDataNet) ? __instance : null);
			if (val == null)
			{
				return true;
			}
			if (!Object.op_Implicit((Object)(object)__instance.outline_))
			{
				return false;
			}
			__instance.outline_.SetOutlineColorNoNorm(Color.Lerp(Color.black, ColorEx.Normalized(__instance.GlowColor_), Mod.OutlineBrightness.Value));
			return false;
		}
	}
	[HarmonyPatch(typeof(RigidbodyStateTransceiver), "EaseTowards")]
	internal class RigidbodyStateTransceiver__EaseTowards
	{
		[HarmonyPrefix]
		internal static bool KinematicEaseTowards(RigidbodyStateTransceiver __instance)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			if (Mod.EnableCollision.Value && !Mod.Instance.playerFinished)
			{
				Snapshot val = Snapshot.Difference(__instance.goal_, new Snapshot(__instance.rigidbody_));
				double num = ((Vector3)(ref val.pos)).sqrMagnitude;
				if (num > 1000.0 || (double)__instance.errorTimer_ > 1.0)
				{
					__instance.setPositionImmediate_ = true;
				}
				else if (num > 100.0)
				{
					__instance.errorTimer_ += Time.fixedDeltaTime;
				}
				else
				{
					__instance.errorTimer_ = 0f;
				}
				if (__instance.setPositionImmediate_)
				{
					return false;
				}
				Vector3 val2 = 100f * val.pos;
				Vector3 val3 = RigidbodyStateTransceiver.posCorrectionSpringDamping_ * val.vel;
				Vector3 val4 = 250f * QuaternionExtensionOnly.ToVector3(val.rot);
				Vector3 val5 = RigidbodyStateTransceiver.rotCorrectionSpringDamping_ * val.rotVel;
				if (__instance.rigidbody_.isKinematic)
				{
					__instance.rigidbody_.MovePosition((val2 + val3) * Time.fixedDeltaTime);
					__instance.rigidbody_.MoveRotation(QuaternionEx.Normalized(Quaternion.Euler((val4 + val5) * Time.fixedDeltaTime)));
				}
				else
				{
					__instance.rigidbody_.AddForce(val2 + val3, (ForceMode)5);
					__instance.rigidbody_.AddTorque(val4 + val5, (ForceMode)5);
				}
				((Snapshot)(ref __instance.goal_)).SetData(__instance.rigidbody_);
				return false;
			}
			__instance.rigidbody_.isKinematic = false;
			return true;
		}
	}
	[HarmonyPatch(typeof(RigidbodyStateTransceiver), "FixedUpdate")]
	internal class RigidbodyStateTransceiver__FixedUpdate
	{
		[HarmonyPrefix]
		internal static bool FixedTheFixedUpdate(RigidbodyStateTransceiver __instance)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			if (!__instance.setCarOnFixedUpdate_)
			{
				return false;
			}
			__instance.rigidbody_.MovePosition(((CriticallyDampedSpringV3)(ref __instance.posSpring_)).Pos_ + __instance.setCarOnFixedUpdateCoef_ * 0.01f * ((CriticallyDampedSpringV3)(ref __instance.velSpring_)).Pos_);
			__instance.rigidbody_.MoveRotation(QuaternionEx.Normalized(((CriticallyDampedSpringQ)(ref __instance.rotSpring_)).Pos_));
			return false;
		}
	}
	[HarmonyPatch(typeof(ServerLogic), "OnEventCompletedRequest", new Type[] { typeof(Data) })]
	internal static class ServerLogic__OnEventCompletedRequest
	{
		[HarmonyPrefix]
		internal static void SetState(ServerLogic __instance, Data data)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			ClientInfo clientInfo = __instance.GetClientInfo(data.networkPlayer_, true);
			if ((int)data.request_ == 1 && Mod.Instance.selfRestart)
			{
				clientInfo.SetStateOnCondition((State)5, (State)8);
				Mod.Instance.selfRestart = false;
			}
		}
	}
	[HarmonyPatch(typeof(TimeBasedMode), "AwakeVirtual")]
	internal class TimeBasedMode__AwakeVirtual
	{
		[HarmonyPostfix]
		internal static void VirtualedYourVirtual(TimeBasedMode __instance)
		{
			Mod.Instance.amIHost = ((GameMode)__instance).IsHost_;
			Mod.Instance.countdownActive = false;
			Mod.Instance.allPlayersFinished = false;
		}
	}
	[HarmonyPatch(typeof(TimeBasedMode), "UpdateModeFinishedState")]
	internal class TimeBasedMode__UpdateModeFinishedState
	{
		[HarmonyPrefix]
		internal static bool ModifyFinalCountdown(TimeBasedMode __instance)
		{
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			if (((GameMode)__instance).IsHost_)
			{
				Mod.Instance.amIHost = true;
				if (((GameMode)__instance).modePlayerInfos_.FindAll((ModePlayerInfoBase val) => val != null && (int)val.finishType_ > 0).Count == ((GameMode)__instance).modePlayerInfos_.Count)
				{
					Mod.Log.LogInfo((object)"ALL PLAYERS HAVE FINISHED!");
					Mod.Instance.allPlayersFinished = true;
					Mod.Instance.countdownActive = false;
				}
				else
				{
					Mod.Log.LogInfo((object)"NOT ALL OF THE PLAYERS FINISHED YET");
					Mod.Instance.allPlayersFinished = false;
				}
				if (Mod.DisableTimeout.Value)
				{
					return false;
				}
				int count = ((GameMode)__instance).modePlayerInfos_.FindAll((ModePlayerInfoBase val) => val == null || (int)val.finishType_ > 0).Count;
				int count2 = ((GameMode)__instance).modePlayerInfos_.FindAll((ModePlayerInfoBase val) => val != null && (int)val.finishType_ == 3).Count;
				int num = ((GameMode)__instance).modePlayerInfos_.Count - count2;
				int num2 = count - count2;
				if (!__instance.theFinalCountdown_)
				{
					if (num <= 1 || num2 != num - 1)
					{
						return false;
					}
					StaticTargetedEvent<Data>.Broadcast((RPCMode)2, new Data(Timex.ModeTime_ + (double)Mod.TimeLimitAmount.Value, Mathf.RoundToInt((float)Mod.TimeLimitAmount.Value)));
					Mod.Instance.countdownActive = true;
				}
				else
				{
					if (num2 < num || num2 >= num - 1)
					{
						return false;
					}
					Mod.Log.LogInfo((object)"Someone seems to have joined during the countdown! Canceling!");
					StaticTargetedEvent<Data>.Broadcast((RPCMode)2, default(Data));
					Mod.Instance.countdownActive = false;
				}
				return false;
			}
			Mod.Instance.amIHost = false;
			return false;
		}
	}
	[HarmonyPatch(typeof(NetworkingManager), "CreateServer")]
	internal static class NetworkingManager__CreateServer
	{
		internal static bool Prefix(NetworkingManager __instance, string serverTitle, string password, int maxPlayerCount)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Invalid comparison between Unknown and I4
			Network.InitializeSecurity();
			try
			{
				__instance.password_ = password;
				__instance.serverTitle_ = serverTitle;
				G.Sys.GameData_.SetString("ServerTitleDefault", __instance.serverTitle_);
				__instance.maxPlayerCount_ = Mathf.Clamp(maxPlayerCount, 1, Mod.MaxPlayerCount.Value);
				G.Sys.GameData_.SetInt("MaxPlayersDefault", __instance.maxPlayerCount_);
				int num = __instance.maxPlayerCount_ - 1;
				NetworkConnectionError val = Network.InitializeServer(num, 32323, true);
				if ((int)val > 0)
				{
					G.Sys.MenuPanelManager_.ShowError("Failed to create game lobby. Error code: " + ((object)(NetworkConnectionError)(ref val)).ToString(), "Network Error", (OnButtonClicked)null, (Pivot)4);
				}
			}
			catch (Exception ex)
			{
				Debug.LogError((object)ex.Message);
				Mod.Log.LogInfo((object)ex);
			}
			return false;
		}
	}
}