Decompiled source of greatestmod v0.1.4

plugins/Greatestmod/R0B0.GreatestMod.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using R0B0.GreatestMod.Config;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Video;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("R0B0.GreatestMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.4.0")]
[assembly: AssemblyInformationalVersion("0.1.4")]
[assembly: AssemblyProduct("GreatestMod")]
[assembly: AssemblyTitle("R0B0.GreatestMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.4.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace R0B0.GreatestMod
{
	[BepInPlugin("R0B0.GreatestMod", "GreatestMod", "0.1.4")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static GreatestModConfig Config;

		public static AssetBundle MyCustomAssets;

		public static AudioClip carLights;

		public static GameObject carAdditions;

		public static Plugin Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Config = new GreatestModConfig(((BaseUnityPlugin)this).Config);
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			MyCustomAssets = AssetBundle.LoadFromFile(Path.Combine(directoryName, "greatestmod"));
			if ((Object)(object)MyCustomAssets == (Object)null)
			{
				Logger.LogError((object)"Failed to load custom assets.");
				return;
			}
			carLights = MyCustomAssets.LoadAsset<AudioClip>("Assets/GreatestMod/CompanyCruiserToy/Cruiser_HeadlightsOn.ogg");
			carAdditions = MyCustomAssets.LoadAsset<GameObject>("Assets/GreatestMod/CompanyCruiserCarComputer/Additions.prefab");
			if (Config.EnableCompanyCruiserToy.Value)
			{
				int num = 30;
				Item val = MyCustomAssets.LoadAsset<Item>("Assets/GreatestMod/CompanyCruiserToy/CompanyCruiserToy.asset");
				NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
				Items.RegisterScrap(val, num, (LevelTypes)4096);
			}
			if (Config.EnablePortableBattery.Value)
			{
				Item val2 = MyCustomAssets.LoadAsset<Item>("Assets/GreatestMod/PortableCharger/PortableCharger.asset");
				NetworkPrefabs.RegisterNetworkPrefab(val2.spawnPrefab);
				int num2 = 100;
				TerminalNode val3 = MyCustomAssets.LoadAsset<TerminalNode>("Assets/GreatestMod/TerminalNodes/iTerminalNode.asset");
				Items.RegisterShopItem(val2, (TerminalNode)null, (TerminalNode)null, val3, num2);
			}
			if (Config.EnableBrokenCamera.Value)
			{
				int num3 = 30;
				Item val4 = MyCustomAssets.LoadAsset<Item>("Assets/GreatestMod/BrokenCamera/BrokenCamera.asset");
				NetworkPrefabs.RegisterNetworkPrefab(val4.spawnPrefab);
				Items.RegisterScrap(val4, num3, (LevelTypes)2596);
			}
			Patch();
			Logger.LogInfo((object)"R0B0.GreatestMod v0.1.4 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("R0B0.GreatestMod");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "R0B0.GreatestMod";

		public const string PLUGIN_NAME = "GreatestMod";

		public const string PLUGIN_VERSION = "0.1.4";
	}
}
namespace R0B0.GreatestMod.Patches
{
	[HarmonyPatch(typeof(VehicleController), "Start")]
	internal class CompanyCruiserPatch
	{
		[HarmonyPostfix]
		public static void AddTheAdditions(VehicleController __instance)
		{
			GameObject val = Object.Instantiate<GameObject>(Plugin.carAdditions, ((Component)__instance).transform.Find("Meshes/MainBody"));
			Plugin.Logger.LogMessage((object)"Added the additions to the company cruiser");
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "Interact_performed")]
	internal class PlayerInteractionPatch
	{
		[HarmonyPostfix]
		private static void PlayerControllerB_Interact_performed(PlayerControllerB __instance, CallbackContext context)
		{
			if (!Plugin.Config.EnableChargerUpgrades.Value || (((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerDead && (!((NetworkBehaviour)__instance).IsServer || __instance.isHostPlayerObject)) || ((!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled || (((NetworkBehaviour)__instance).IsServer && !__instance.isHostPlayerObject)) && !__instance.isTestingPlayer) || !((CallbackContext)(ref context)).performed || __instance.timeSinceSwitchingSlots < 0.2f || __instance.inSpecialMenu)
			{
				return;
			}
			ShipBuildModeManager.Instance.CancelBuildMode(true);
			if (!__instance.isGrabbingObjectAnimation && !__instance.isTypingChat && !__instance.inTerminalMenu && !__instance.throwingObject && !__instance.IsInspectingItem && !((Object)(object)__instance.inAnimationWithEnemy != (Object)null) && !__instance.jetpackControls && !__instance.disablingJetpackControls && !StartOfRound.Instance.suckingPlayersOutOfShip)
			{
				if (!__instance.activatingItem && !__instance.waitingToDropItem)
				{
					__instance.BeginGrabObject();
				}
				if (!((Object)(object)__instance.hoveringOverTrigger == (Object)null) && !__instance.hoveringOverTrigger.holdInteraction && (!__instance.isHoldingObject || __instance.hoveringOverTrigger.oneHandedItemAllowed) && (!__instance.twoHanded || (__instance.hoveringOverTrigger.twoHandedItemAllowed && !__instance.hoveringOverTrigger.specialCharacterAnimation) || (__instance.hoveringOverTrigger.twoHandedItemAllowed && __instance.hoveringOverTrigger.hoverTip == "Charge item : [LMB]")) && __instance.InteractTriggerUseConditionsMet())
				{
					__instance.hoveringOverTrigger.Interact(__instance.thisPlayerBody);
				}
			}
		}
	}
	[HarmonyPatch(typeof(ItemCharger))]
	internal class PowerOutletStun
	{
		private const int DAMAGEAMOUNT = 50;

		private const float BODYTHROWMULTIPLIER = 0.5f;

		private const int DAMAGEDISTRIBUTION = 3;

		[HarmonyPatch("ChargeItem")]
		[HarmonyPrefix]
		private static void ItemCharger_ChargeItem(ItemCharger __instance)
		{
			if (!Plugin.Config.EnableChargerUpgrades.Value)
			{
				return;
			}
			Plugin.Logger.LogDebug((object)"------------- Charged item!! ------------------------");
			GrabbableObject currentlyHeldObjectServer = GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer;
			if (!((Object)(object)currentlyHeldObjectServer == (Object)null) && (currentlyHeldObjectServer.itemProperties.requiresBattery || currentlyHeldObjectServer.itemProperties.isConductiveMetal))
			{
				__instance.PlayChargeItemEffectServerRpc((int)GameNetworkManager.Instance.localPlayerController.playerClientId);
				if (__instance.chargeItemCoroutine != null)
				{
					((MonoBehaviour)__instance).StopCoroutine(__instance.chargeItemCoroutine);
				}
				if (currentlyHeldObjectServer.itemProperties.requiresBattery)
				{
					__instance.chargeItemCoroutine = ((MonoBehaviour)__instance).StartCoroutine(__instance.chargeItemDelayed(currentlyHeldObjectServer));
				}
				else if (currentlyHeldObjectServer.itemProperties.isConductiveMetal && !currentlyHeldObjectServer.itemProperties.twoHanded)
				{
					__instance.chargeItemCoroutine = ((MonoBehaviour)__instance).StartCoroutine(chargeItemDelayedButBetter(currentlyHeldObjectServer, __instance.zapAudio, __instance.chargeStationAnimator, 1f));
				}
				else if (currentlyHeldObjectServer.itemProperties.isConductiveMetal && currentlyHeldObjectServer.itemProperties.twoHanded)
				{
					__instance.chargeItemCoroutine = ((MonoBehaviour)__instance).StartCoroutine(chargeItemDelayedButBetter(currentlyHeldObjectServer, __instance.zapAudio, __instance.chargeStationAnimator, 2f));
				}
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void ItemCharger_Update(ItemCharger __instance)
		{
			if (__instance.updateInterval == 0f)
			{
				__instance.updateInterval = 0f;
				if ((Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null)
				{
					__instance.triggerScript.interactable = (Object)(object)GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer != (Object)null && (GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer.itemProperties.isConductiveMetal || GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer.itemProperties.requiresBattery);
				}
			}
		}

		private static IEnumerator chargeItemDelayedButBetter(GrabbableObject itemToCharge, AudioSource zapAudio, Animator chargeStationAnimator, float damageMultiplier)
		{
			zapAudio.Play();
			yield return (object)new WaitForSeconds(0.6f);
			chargeStationAnimator.SetTrigger("zap");
			if ((Object)(object)itemToCharge != (Object)null)
			{
				for (int i = 0; i < 3; i++)
				{
					GameNetworkManager.Instance.localPlayerController.DamagePlayer(Mathf.RoundToInt(16f * damageMultiplier), true, true, (CauseOfDeath)11, 0, false, default(Vector3));
					yield return (object)new WaitForSeconds(0.1f);
				}
			}
		}
	}
}
namespace R0B0.GreatestMod.Monobehaviours
{
	public class BrokenCamera : GrabbableObject
	{
		[Header("Stun grenade settings")]
		public float TimeToExplode = 2.25f;

		public bool DestroyGrenade;

		public string playerAnimation = "PullGrenadePin";

		[Space(5f)]
		public bool explodeOnCollision;

		public bool dontRequirePullingPin;

		public float chanceToExplode = 100f;

		public bool spawnDamagingShockwave;

		private bool explodeOnThrow;

		private bool gotExplodeOnThrowRPC;

		private bool hasCollided;

		[Space(3f)]
		public string throwString = "Throw grenade: [RMB]";

		private Coroutine pullPinCoroutine;

		public Animator itemAnimator;

		public AudioSource itemAudio;

		public AudioClip pullPinSFX;

		public AudioClip explodeSFX;

		private int stunGrenadeMask = 268437761;

		public GameObject stunGrenadeExplosion;

		private PlayerControllerB playerThrownBy;

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			ExplodeStunGrenade();
		}

		private void ExplodeStunGrenade(bool destroy = false)
		{
			//IL_00ed: 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_012b: Unknown result type (might be due to invalid IL or missing references)
			if (base.insertedBattery.charge < 1f || base.insertedBattery.empty)
			{
				return;
			}
			base.insertedBattery.charge = 0f;
			base.insertedBattery.empty = true;
			((GrabbableObject)this).SyncBatteryServerRpc(0);
			if ((chanceToExplode < 100f && !explodeOnThrow) || (explodeOnCollision && !StartOfRound.Instance.currentLevel.spawnEnemiesAndScrap && (Object)(object)base.parentObject == (Object)(object)Object.FindObjectOfType<DepositItemsDesk>().deskObjectsContainer))
			{
				if ((Object)(object)playerThrownBy != (Object)null)
				{
					playerThrownBy.activatingItem = false;
				}
				return;
			}
			Transform val = ((!base.isInElevator) ? RoundManager.Instance.mapPropsContainer.transform : StartOfRound.Instance.elevatorTransform);
			StunFlash(((Component)this).transform.position, affectAudio: false, 1.25f, 5f, 0.8f, isHeldItem: false, base.playerHeldBy, playerThrownBy);
			Object.Instantiate<GameObject>(stunGrenadeExplosion, ((Component)this).transform.position, Quaternion.identity, val);
			itemAudio.PlayOneShot(explodeSFX);
			WalkieTalkie.TransmitOneShotAudio(itemAudio, explodeSFX, 1f);
			if (DestroyGrenade)
			{
				((GrabbableObject)this).DestroyObjectInHand(playerThrownBy);
			}
		}

		public void StunFlash(Vector3 explosionPosition, bool affectAudio, float flashSeverityMultiplier, float enemyStunTime, float flashSeverityDistanceRolloff = 1f, bool isHeldItem = false, PlayerControllerB playerHeldBy = null, PlayerControllerB playerThrownBy = null, float addToFlashSeverity = 0f)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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)
			//IL_008a: 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_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = GameNetworkManager.Instance.localPlayerController;
			if (GameNetworkManager.Instance.localPlayerController.isPlayerDead && (Object)(object)GameNetworkManager.Instance.localPlayerController.spectatedPlayerScript != (Object)null)
			{
				val = GameNetworkManager.Instance.localPlayerController.spectatedPlayerScript;
			}
			float num = Vector3.Distance(((Component)val).transform.position, explosionPosition);
			float num2 = 7f / (num * flashSeverityDistanceRolloff);
			if (Physics.Linecast(explosionPosition + Vector3.up * 0.5f, ((Component)val.gameplayCamera).transform.position, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
			{
				num2 /= 13f;
			}
			else if (num < 2f)
			{
				num2 = 1f;
			}
			else if (!val.HasLineOfSightToPosition(explosionPosition, 60f, 15, 2f))
			{
				num2 = Mathf.Clamp(num2 / 3f, 0f, 1f);
			}
			if (!playerHeldBy.HasLineOfSightToPosition(((Component)val).transform.position, 60f, 15, 2f))
			{
				num2 = Mathf.Clamp(num2 * 0.005f, 0f, 1f);
			}
			if (isHeldItem && (Object)(object)playerHeldBy == (Object)(object)GameNetworkManager.Instance.localPlayerController)
			{
				num2 = 1f;
			}
			num2 = Mathf.Clamp(num2 * flashSeverityMultiplier, 0f, 1f);
			if (num2 > 0.6f)
			{
				num2 += addToFlashSeverity;
			}
			if ((Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)(object)playerHeldBy)
			{
				HUDManager.Instance.flashFilter = num2;
			}
			if (affectAudio)
			{
			}
			if (enemyStunTime <= 0f)
			{
				return;
			}
			Collider[] array = Physics.OverlapSphere(explosionPosition, 12f, 524288);
			if (array.Length == 0)
			{
				return;
			}
			for (int i = 0; i < array.Length; i++)
			{
				EnemyAICollisionDetect component = ((Component)array[i]).GetComponent<EnemyAICollisionDetect>();
				if ((Object)(object)component == (Object)null)
				{
					continue;
				}
				Vector3 val2 = ((Component)component.mainScript).transform.position + Vector3.up * 0.5f;
				if (component.mainScript.CheckLineOfSightForPosition(explosionPosition + Vector3.up * 0.5f, 120f, 23, 7f, (Transform)null) || (!Physics.Linecast(explosionPosition + Vector3.up * 0.5f, ((Component)component.mainScript).transform.position + Vector3.up * 0.5f, 256) && Vector3.Distance(explosionPosition, val2) < 11f))
				{
					if ((Object)(object)playerThrownBy != (Object)null)
					{
						component.mainScript.SetEnemyStunned(true, enemyStunTime, playerThrownBy);
					}
					else
					{
						component.mainScript.SetEnemyStunned(true, enemyStunTime, (PlayerControllerB)null);
					}
				}
			}
		}
	}
	public class CompanyCruiserCarComputer : NetworkBehaviour
	{
		public bool tvOn;

		private bool wasTvOnLastFrame;

		public MeshRenderer tvMesh;

		public VideoPlayer video;

		[Space(5f)]
		public VideoClip[] tvClips;

		public AudioClip[] tvAudioClips;

		[Space(5f)]
		private float currentClipTime;

		private int currentClip;

		public Material tvOnMaterial;

		public Material tvOffMaterial;

		public AudioClip switchTVOn;

		public AudioClip switchTVOff;

		public AudioSource tvSFX;

		private float timeSinceTurningOffTV;

		public Light tvLight;

		[Space(5f)]
		public GameObject ParkingCameraGameObject;

		public Material parkingCameraOnMaterial;

		public bool parkingCameraOn = false;

		private bool wasParkCamOnLastFrame = false;

		public void TurnTVOnOff(bool on)
		{
			tvOn = on;
			if (on && parkingCameraOn)
			{
				tvSFX.PlayOneShot(switchTVOn);
				WalkieTalkie.TransmitOneShotAudio(tvSFX, switchTVOn, 1f);
			}
			else if (on && !parkingCameraOn)
			{
				tvSFX.clip = tvAudioClips[currentClip];
				tvSFX.time = currentClipTime;
				tvSFX.Play();
				tvSFX.PlayOneShot(switchTVOn);
				WalkieTalkie.TransmitOneShotAudio(tvSFX, switchTVOn, 1f);
			}
			else
			{
				tvSFX.Stop();
				tvSFX.PlayOneShot(switchTVOff);
				WalkieTalkie.TransmitOneShotAudio(tvSFX, switchTVOff, 1f);
			}
		}

		public void SwitchTVLocalClient()
		{
			if (tvOn)
			{
				TurnOffTVServerRpc();
			}
			else
			{
				TurnOnTVServerRpc();
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void TurnOnTVServerRpc()
		{
			timeSinceTurningOffTV = 0f;
			if (timeSinceTurningOffTV > 7f)
			{
				TurnOnTVAndSyncClientRpc(currentClip, currentClipTime);
			}
			else
			{
				TurnOnTVClientRpc();
			}
		}

		[ClientRpc]
		public void TurnOnTVClientRpc()
		{
			TurnTVOnOff(on: true);
		}

		[ClientRpc]
		public void TurnOnTVAndSyncClientRpc(int clipIndex, float clipTime)
		{
			currentClip = clipIndex;
			currentClipTime = clipTime;
			TurnTVOnOff(on: true);
		}

		[ServerRpc(RequireOwnership = false)]
		public void TurnOffTVServerRpc()
		{
			TurnOffTVClientRpc();
		}

		[ClientRpc]
		public void TurnOffTVClientRpc()
		{
			TurnTVOnOff(on: false);
		}

		[ServerRpc(RequireOwnership = false)]
		public void SyncTVServerRpc()
		{
			SyncTVClientRpc(currentClip, currentClipTime, tvOn);
		}

		[ClientRpc]
		public void SyncTVClientRpc(int clipIndex, float clipTime, bool isOn)
		{
			SyncTimeAndClipWithClients(clipIndex, clipTime, isOn);
		}

		private void SyncTimeAndClipWithClients(int clipIndex, float clipTime, bool isOn)
		{
			currentClip = clipIndex;
			currentClipTime = clipTime;
			tvOn = isOn;
		}

		private void OnEnable()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			video.loopPointReached += new EventHandler(TVFinishedClip);
		}

		private void OnDisable()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			video.loopPointReached -= new EventHandler(TVFinishedClip);
		}

		private void TVFinishedClip(VideoPlayer source)
		{
			if (tvOn && !GameNetworkManager.Instance.localPlayerController.isInsideFactory)
			{
				currentClip = (currentClip + 1) % tvClips.Length;
				video.clip = tvClips[currentClip];
				video.Play();
				tvSFX.clip = tvAudioClips[currentClip];
				tvSFX.time = 0f;
				tvSFX.Play();
			}
		}

		private void Update()
		{
			if (NetworkManager.Singleton.ShutdownInProgress || (Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
			{
				return;
			}
			if (!tvOn || GameNetworkManager.Instance.localPlayerController.isInsideFactory)
			{
				if (wasTvOnLastFrame)
				{
					wasTvOnLastFrame = false;
					SetTVScreenMaterial(on: false);
					currentClipTime = (float)video.time;
					video.Stop();
				}
				if (wasParkCamOnLastFrame)
				{
					ParkingCameraGameObject.SetActive(false);
					wasParkCamOnLastFrame = false;
					SetTVScreenMaterial(on: false);
				}
				if (((NetworkBehaviour)this).IsServer && !tvOn)
				{
					timeSinceTurningOffTV += Time.deltaTime;
				}
				currentClipTime += Time.deltaTime;
				if ((double)currentClipTime > tvClips[currentClip].length)
				{
					currentClip = (currentClip + 1) % tvClips.Length;
					currentClipTime = 0f;
					if (tvOn)
					{
						tvSFX.clip = tvAudioClips[currentClip];
						tvSFX.Play();
					}
				}
				return;
			}
			if (parkingCameraOn)
			{
				if (wasTvOnLastFrame)
				{
					Debug.Log((object)"TV was on last frame");
					wasTvOnLastFrame = false;
					currentClipTime = (float)video.time;
					video.Stop();
				}
				if (!wasParkCamOnLastFrame)
				{
					wasTvOnLastFrame = false;
					currentClipTime = (float)video.time;
					video.Stop();
					wasParkCamOnLastFrame = true;
					SetTVScreenMaterialBetweenParkingCameraAndNormalTV(input: true);
				}
				currentClipTime += Time.deltaTime;
				if ((double)currentClipTime > tvClips[currentClip].length)
				{
					currentClip = (currentClip + 1) % tvClips.Length;
					currentClipTime = 0f;
					if (tvOn)
					{
						tvSFX.clip = tvAudioClips[currentClip];
						tvSFX.Play();
					}
				}
				Debug.Log((object)currentClipTime);
			}
			else if (!wasTvOnLastFrame)
			{
				wasParkCamOnLastFrame = false;
				wasTvOnLastFrame = true;
				SetTVScreenMaterial(on: true);
				video.clip = tvClips[currentClip];
				video.time = currentClipTime;
				video.Play();
			}
			currentClipTime = (float)video.time;
		}

		private void SetTVScreenMaterial(bool on)
		{
			Material[] sharedMaterials = ((Renderer)tvMesh).sharedMaterials;
			if (on)
			{
				sharedMaterials[1] = tvOnMaterial;
			}
			else
			{
				sharedMaterials[1] = tvOffMaterial;
			}
			((Renderer)tvMesh).sharedMaterials = sharedMaterials;
			((Behaviour)tvLight).enabled = on;
		}

		public void SwitchToParkingCamera()
		{
			SwitchToParkingCameraServerRpc();
		}

		[ServerRpc(RequireOwnership = false)]
		public void SwitchToParkingCameraServerRpc()
		{
			SwitchToParkingCameraClientRpc();
		}

		[ClientRpc]
		public void SwitchToParkingCameraClientRpc()
		{
			parkingCameraOn = !parkingCameraOn;
			tvSFX.PlayOneShot(switchTVOn);
			WalkieTalkie.TransmitOneShotAudio(tvSFX, switchTVOn, 1f);
			if (!parkingCameraOn && tvOn)
			{
				tvSFX.clip = tvAudioClips[currentClip];
				tvSFX.time = currentClipTime;
				tvSFX.Play();
			}
			else
			{
				tvSFX.Stop();
			}
		}

		private void SetTVScreenMaterialBetweenParkingCameraAndNormalTV(bool input)
		{
			if (tvOn)
			{
				ParkingCameraGameObject.SetActive(input);
				Material[] sharedMaterials = ((Renderer)tvMesh).sharedMaterials;
				sharedMaterials[1] = parkingCameraOnMaterial;
				if (input)
				{
					sharedMaterials[1] = parkingCameraOnMaterial;
				}
				else
				{
					sharedMaterials[1] = tvOnMaterial;
				}
				((Renderer)tvMesh).sharedMaterials = sharedMaterials;
				((Behaviour)tvLight).enabled = true;
			}
		}
	}
	public class CompanyCruiserToy : GrabbableObject
	{
		[Space(15f)]
		public int flashlightInterferenceLevel;

		public static int globalFlashlightInterferenceLevel;

		public bool changeMaterial = true;

		public Light flashlightBulb { get; set; }

		public Light flashlightBulbGlow { get; set; }

		public AudioSource flashlightAudio { get; set; }

		public AudioClip[] flashlightClips { get; set; }

		public AudioClip outOfBatteriesClip { get; set; }

		public AudioClip flashlightFlicker { get; set; }

		public Material bulbLight { get; set; }

		public Material bulbDark { get; set; }

		public MeshRenderer flashlightMesh { get; set; }

		public int flashlightTypeID { get; set; }

		private float initialIntensity { get; set; }

		private PlayerControllerB previousPlayerHeldBy { get; set; }

		public void Awake()
		{
			base.grabbable = true;
			base.isInFactory = true;
			base.grabbableToEnemies = true;
			changeMaterial = false;
			flashlightBulb = ((Component)this).GetComponentsInChildren<Light>()[0];
			flashlightBulbGlow = ((Component)this).GetComponentsInChildren<Light>()[1];
			flashlightAudio = ((Component)this).GetComponent<AudioSource>();
			flashlightClips = (AudioClip[])(object)new AudioClip[1];
			flashlightClips[0] = Plugin.carLights;
			base.insertedBattery.empty = false;
			base.insertedBattery.charge = 100f;
		}

		public override void Start()
		{
			((GrabbableObject)this).Start();
			initialIntensity = flashlightBulb.intensity;
		}

		public override void UseUpBatteries()
		{
			((GrabbableObject)this).UseUpBatteries();
			SwitchFlashlight(on: false);
		}

		public override void PocketItem()
		{
			Plugin.Logger.LogError((object)"Truck pocketed");
			if (!((NetworkBehaviour)this).IsOwner)
			{
				((GrabbableObject)this).PocketItem();
				return;
			}
			if ((Object)(object)previousPlayerHeldBy != (Object)null)
			{
				((Behaviour)flashlightBulb).enabled = false;
				((Behaviour)flashlightBulbGlow).enabled = false;
				if (base.isBeingUsed && ((Object)(object)previousPlayerHeldBy.ItemSlots[previousPlayerHeldBy.currentItemSlot] == (Object)null || previousPlayerHeldBy.ItemSlots[previousPlayerHeldBy.currentItemSlot].itemProperties.itemId != 1 || previousPlayerHeldBy.ItemSlots[previousPlayerHeldBy.currentItemSlot].itemProperties.itemId != 6))
				{
					previousPlayerHeldBy.pocketedFlashlight = (GrabbableObject)(object)this;
					PocketFlashlightServerRpc(stillUsingFlashlight: true);
				}
				else
				{
					base.isBeingUsed = false;
					((Behaviour)flashlightBulbGlow).enabled = false;
					SwitchFlashlight(on: false);
					PocketFlashlightServerRpc();
				}
			}
			else
			{
				Debug.Log((object)"Could not find what player was holding this flashlight item");
			}
			((GrabbableObject)this).PocketItem();
		}

		[ServerRpc]
		public void PocketFlashlightServerRpc(bool stillUsingFlashlight = false)
		{
			PocketFlashlightClientRpc(stillUsingFlashlight);
		}

		[ClientRpc]
		public void PocketFlashlightClientRpc(bool stillUsingFlashlight)
		{
			if (((NetworkBehaviour)this).IsOwner)
			{
				return;
			}
			((Behaviour)flashlightBulb).enabled = false;
			((Behaviour)flashlightBulbGlow).enabled = false;
			if (stillUsingFlashlight)
			{
				if (!((Object)(object)previousPlayerHeldBy == (Object)null))
				{
					previousPlayerHeldBy.pocketedFlashlight = (GrabbableObject)(object)this;
				}
			}
			else
			{
				base.isBeingUsed = false;
				((Behaviour)flashlightBulbGlow).enabled = false;
				SwitchFlashlight(on: false);
			}
		}

		public override void DiscardItem()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).DiscardItem();
			RoundManager.Instance.PlayAudibleNoise(((Component)this).transform.position, 25f, 0.95f, 0, base.isInElevator && StartOfRound.Instance.hangarDoorsClosed, 0);
		}

		public override void EquipItem()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			previousPlayerHeldBy = base.playerHeldBy;
			SwitchFlashlight(on: true);
			RoundManager.Instance.PlayAudibleNoise(((Component)this).transform.position, 15f, 0.65f, 0, base.isInElevator && StartOfRound.Instance.hangarDoorsClosed, 0);
			((GrabbableObject)this).EquipItem();
		}

		public void SwitchFlashlight(bool on)
		{
			base.isBeingUsed = on;
			if (!((NetworkBehaviour)this).IsOwner)
			{
				Debug.Log((object)$"Flashlight click. playerheldby null?: {(Object)(object)base.playerHeldBy != (Object)null}");
				Debug.Log((object)$"Flashlight being disabled or enabled: {on}");
				Plugin.Logger.LogInfo((object)"If not owner or something?");
			}
			else
			{
				((Behaviour)flashlightBulb).enabled = on;
				((Behaviour)flashlightBulbGlow).enabled = on;
			}
			if (changeMaterial)
			{
				Material[] sharedMaterials = ((Renderer)flashlightMesh).sharedMaterials;
				if (on)
				{
					sharedMaterials[1] = bulbLight;
				}
				else
				{
					sharedMaterials[1] = bulbDark;
				}
				((Renderer)flashlightMesh).sharedMaterials = sharedMaterials;
			}
		}

		public override void Update()
		{
			((GrabbableObject)this).Update();
			int num = ((flashlightInterferenceLevel <= globalFlashlightInterferenceLevel) ? globalFlashlightInterferenceLevel : flashlightInterferenceLevel);
			if (num >= 2)
			{
				flashlightBulb.intensity = 0f;
			}
			else if (num == 1)
			{
				flashlightBulb.intensity = Random.Range(0f, 200f);
			}
			else
			{
				flashlightBulb.intensity = initialIntensity;
			}
		}
	}
	public class PortableItemCharger : NetworkBehaviour
	{
		private const float CHARGEBATTERYAMOUNT = 0.1f;

		public PortableItemChargerItem itemThing;

		public InteractTrigger triggerScript;

		public Animator chargeStationAnimator;

		private Coroutine chargeItemCoroutine;

		public AudioSource zapAudio;

		private float updateInterval;

		public void ChargeItem()
		{
			GrabbableObject currentlyHeldObjectServer = GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer;
			if (!((Object)(object)currentlyHeldObjectServer == (Object)null) && !((Object)(object)currentlyHeldObjectServer == (Object)null) && currentlyHeldObjectServer.itemProperties.requiresBattery && ((GrabbableObject)itemThing).insertedBattery.charge >= 0.1f)
			{
				PlayChargeItemEffectServerRpc((int)GameNetworkManager.Instance.localPlayerController.playerClientId);
				if (chargeItemCoroutine != null)
				{
					((MonoBehaviour)this).StopCoroutine(chargeItemCoroutine);
				}
				chargeItemCoroutine = ((MonoBehaviour)this).StartCoroutine(chargeItemDelayed(currentlyHeldObjectServer));
			}
		}

		private void Update()
		{
			if ((Object)(object)NetworkManager.Singleton == (Object)null)
			{
				return;
			}
			if (updateInterval > 1f)
			{
				updateInterval = 0f;
				if ((Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null)
				{
					if (((GrabbableObject)itemThing).heldByPlayerOnServer)
					{
						triggerScript.interactable = false;
						triggerScript.disabledHoverTip = "This item is currently not in use. Please put the item down to use it";
					}
					else if (((GrabbableObject)itemThing).insertedBattery.charge < 0.1f)
					{
						triggerScript.interactable = false;
						triggerScript.disabledHoverTip = "(It's empty. Why would I even try)";
					}
					else if ((Object)(object)GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer == (Object)(object)itemThing)
					{
						triggerScript.interactable = false;
						triggerScript.disabledHoverTip = "You can't charge the battery with itself >:(";
					}
					else
					{
						triggerScript.disabledHoverTip = "(Requires battery-powered item)";
						triggerScript.interactable = (Object)(object)GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer != (Object)null && GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer.itemProperties.requiresBattery;
					}
				}
			}
			else
			{
				updateInterval += Time.deltaTime;
			}
		}

		private IEnumerator chargeItemDelayed(GrabbableObject itemToCharge)
		{
			zapAudio.Play();
			yield return (object)new WaitForSeconds(0.05f);
			chargeStationAnimator.SetTrigger("zap");
			if ((Object)(object)itemToCharge != (Object)null)
			{
				itemToCharge.insertedBattery = new Battery(false, 1f);
				itemToCharge.SyncBatteryServerRpc(100);
				Battery insertedBattery = ((GrabbableObject)itemThing).insertedBattery;
				insertedBattery.charge -= 0.1f;
				Debug.Log((object)Mathf.RoundToInt(((GrabbableObject)itemThing).insertedBattery.charge * 10f));
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void PlayChargeItemEffectServerRpc(int playerChargingItem)
		{
			PlayChargeItemEffectClientRpc(playerChargingItem);
		}

		[ClientRpc]
		public void PlayChargeItemEffectClientRpc(int playerChargingItem)
		{
			if (!((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null) && (int)GameNetworkManager.Instance.localPlayerController.playerClientId != playerChargingItem)
			{
				if (chargeItemCoroutine != null)
				{
					((MonoBehaviour)this).StopCoroutine(chargeItemCoroutine);
				}
				chargeItemCoroutine = ((MonoBehaviour)this).StartCoroutine(chargeItemDelayed(null));
			}
		}
	}
	public class PortableItemChargerItem : GrabbableObject
	{
		public Collider ItemChargerInterractCollider;

		public override void Update()
		{
			((GrabbableObject)this).Update();
			if (base.heldByPlayerOnServer)
			{
				ItemChargerInterractCollider.enabled = false;
			}
			else
			{
				ItemChargerInterractCollider.enabled = true;
			}
			if ((double)base.insertedBattery.charge < 0.1 && (double)base.insertedBattery.charge > 0.01 && !base.insertedBattery.empty)
			{
				base.insertedBattery.charge = 0.1f;
			}
			else if (base.insertedBattery.charge == 0f)
			{
				base.insertedBattery.empty = true;
			}
		}
	}
}
namespace R0B0.GreatestMod.Config
{
	[Serializable]
	public class SyncedInstance<T>
	{
		[NonSerialized]
		protected static int IntSize = 4;

		internal static CustomMessagingManager MessageManager => NetworkManager.Singleton.CustomMessagingManager;

		internal static bool IsClient => NetworkManager.Singleton.IsClient;

		internal static bool IsHost => NetworkManager.Singleton.IsHost;

		public static T Default { get; private set; }

		public static T Instance { get; private set; }

		public static bool Synced { get; internal set; }

		protected void InitInstance(T instance)
		{
			Default = instance;
			Instance = instance;
			IntSize = 4;
		}

		internal static void SyncInstance(byte[] data)
		{
			Instance = DeserializeFromBytes(data);
			Synced = true;
		}

		internal static void RevertSync()
		{
			Instance = Default;
			Synced = false;
		}

		public static byte[] SerializeToBytes(T val)
		{
			BinaryFormatter binaryFormatter = new BinaryFormatter();
			using MemoryStream memoryStream = new MemoryStream();
			try
			{
				binaryFormatter.Serialize(memoryStream, val);
				return memoryStream.ToArray();
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"Error serializing instance: {arg}");
				return null;
			}
		}

		public static T DeserializeFromBytes(byte[] data)
		{
			BinaryFormatter binaryFormatter = new BinaryFormatter();
			using MemoryStream serializationStream = new MemoryStream(data);
			try
			{
				return (T)binaryFormatter.Deserialize(serializationStream);
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"Error deserializing instance: {arg}");
				return default(T);
			}
		}
	}
	[Serializable]
	public class GreatestModConfig : SyncedInstance<GreatestModConfig>
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__OnRequestSync;

			public static HandleNamedMessageDelegate <1>__OnReceiveSync;
		}

		public readonly ConfigEntry<int> DebugLevel;

		public readonly ConfigEntry<bool> EnableCompanyCruiserToy;

		public readonly ConfigEntry<bool> EnablePortableBattery;

		public readonly ConfigEntry<bool> EnableBrokenCamera;

		public readonly ConfigEntry<bool> EnableChargerUpgrades;

		public readonly ConfigEntry<bool> EnableCompanyCruiserComputer;

		public readonly ConfigEntry<float> aFloat;

		public GreatestModConfig(ConfigFile cfg)
		{
			//IL_0024: 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_003f: Expected O, but got Unknown
			//IL_003f: Expected O, but got Unknown
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_006b: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			//IL_0097: Expected O, but got Unknown
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			//IL_00c3: Expected O, but got Unknown
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Expected O, but got Unknown
			//IL_00ef: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Expected O, but got Unknown
			//IL_011b: Expected O, but got Unknown
			//IL_012c: 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_014b: Expected O, but got Unknown
			//IL_014b: Expected O, but got Unknown
			InitInstance(this);
			cfg.SaveOnConfigSet = false;
			DebugLevel = cfg.Bind<int>(new ConfigDefinition("General", "Debug Level"), 0, new ConfigDescription("Debug logging level for the mod. This has to be set before lauching the game.", (AcceptableValueBase)null, Array.Empty<object>()));
			EnableCompanyCruiserToy = cfg.Bind<bool>(new ConfigDefinition("Items", "Enable Company Cruiser Toy"), true, new ConfigDescription("Enable Company Cruiser Toy. This has to be set before lauching the game", (AcceptableValueBase)null, Array.Empty<object>()));
			EnablePortableBattery = cfg.Bind<bool>(new ConfigDefinition("Items", "Enable Portable Battery"), true, new ConfigDescription("Enable Portable Battery. This has to be set before lauching the game", (AcceptableValueBase)null, Array.Empty<object>()));
			EnableBrokenCamera = cfg.Bind<bool>(new ConfigDefinition("Items", "Enable Broken Camera"), true, new ConfigDescription("Enable Broken Camera. This has to be set before lauching the game", (AcceptableValueBase)null, Array.Empty<object>()));
			EnableChargerUpgrades = cfg.Bind<bool>(new ConfigDefinition("Items", "Enable Charger Upgrades"), true, new ConfigDescription("Enable Charger Upgrades. This has to be set before lauching the game.", (AcceptableValueBase)null, Array.Empty<object>()));
			EnableCompanyCruiserComputer = cfg.Bind<bool>(new ConfigDefinition("Items", "Enable Company Cruiser Computer"), true, new ConfigDescription("Enable Company Cruiser Computer. This has to be set before lauching the game", (AcceptableValueBase)null, Array.Empty<object>()));
			aFloat = cfg.Bind<float>(new ConfigDefinition("Movement", "Climb Speed"), 3.9f, new ConfigDescription("The base speed at which the player climbs.", (AcceptableValueBase)null, Array.Empty<object>()));
			ClearOrphanedEntries(cfg);
			cfg.Save();
			cfg.SaveOnConfigSet = true;
			Plugin.Logger.LogDebug((object)"Registering Config");
		}

		public static void RequestSync()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (!SyncedInstance<GreatestModConfig>.IsClient)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(SyncedInstance<GreatestModConfig>.IntSize, (Allocator)2, -1);
			try
			{
				SyncedInstance<GreatestModConfig>.MessageManager.SendNamedMessage("R0B0.GreatestMod_OnRequestConfigSync", 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(FastBufferWriter)(ref val)).Dispose();
			}
		}

		public static void OnRequestSync(ulong clientId, FastBufferReader _)
		{
			//IL_0053: 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)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			if (!SyncedInstance<GreatestModConfig>.IsHost)
			{
				return;
			}
			Plugin.Logger.LogInfo((object)$"Config sync request received from client: {clientId}");
			byte[] array = SyncedInstance<GreatestModConfig>.SerializeToBytes(SyncedInstance<GreatestModConfig>.Instance);
			int num = array.Length;
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(num + SyncedInstance<GreatestModConfig>.IntSize, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteBytesSafe(array, -1, 0);
				SyncedInstance<GreatestModConfig>.MessageManager.SendNamedMessage("R0B0.GreatestMod_OnReceiveConfigSync", clientId, val, (NetworkDelivery)3);
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogInfo((object)$"Error occurred syncing config with client: {clientId}\n{arg}");
			}
			finally
			{
				((IDisposable)(FastBufferWriter)(ref val)).Dispose();
			}
		}

		public static void OnReceiveSync(ulong _, FastBufferReader reader)
		{
			//IL_002d: 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)
			if (!((FastBufferReader)(ref reader)).TryBeginRead(SyncedInstance<GreatestModConfig>.IntSize))
			{
				Plugin.Logger.LogError((object)"Config sync error: Could not begin reading buffer.");
				return;
			}
			int num = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			if (!((FastBufferReader)(ref reader)).TryBeginRead(num))
			{
				Plugin.Logger.LogError((object)"Config sync error: Host could not sync.");
				return;
			}
			byte[] data = new byte[num];
			((FastBufferReader)(ref reader)).ReadBytesSafe(ref data, num, 0);
			SyncedInstance<GreatestModConfig>.SyncInstance(data);
			Plugin.Logger.LogInfo((object)"Successfully synced config with host.");
		}

		private static void ClearOrphanedEntries(ConfigFile cfg)
		{
			PropertyInfo propertyInfo = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries");
			Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)propertyInfo.GetValue(cfg);
			dictionary.Clear();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
		public static void InitializeLocalPlayer()
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			if (SyncedInstance<GreatestModConfig>.IsHost)
			{
				CustomMessagingManager messageManager = SyncedInstance<GreatestModConfig>.MessageManager;
				object obj = <>O.<0>__OnRequestSync;
				if (obj == null)
				{
					HandleNamedMessageDelegate val = OnRequestSync;
					<>O.<0>__OnRequestSync = val;
					obj = (object)val;
				}
				messageManager.RegisterNamedMessageHandler("R0B0.GreatestMod_OnRequestConfigSync", (HandleNamedMessageDelegate)obj);
				SyncedInstance<GreatestModConfig>.Synced = true;
				return;
			}
			SyncedInstance<GreatestModConfig>.Synced = false;
			CustomMessagingManager messageManager2 = SyncedInstance<GreatestModConfig>.MessageManager;
			object obj2 = <>O.<1>__OnReceiveSync;
			if (obj2 == null)
			{
				HandleNamedMessageDelegate val2 = OnReceiveSync;
				<>O.<1>__OnReceiveSync = val2;
				obj2 = (object)val2;
			}
			messageManager2.RegisterNamedMessageHandler("R0B0.GreatestMod_OnReceiveConfigSync", (HandleNamedMessageDelegate)obj2);
			RequestSync();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "StartDisconnect")]
		public static void PlayerLeave()
		{
			SyncedInstance<GreatestModConfig>.RevertSync();
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}