Decompiled source of Cruiser Additions v1.4.2

plugins/4902-Cruiser_Additions.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Steamworks;
using Steamworks.Data;
using TMPro;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace kirby;

[BepInPlugin("4902.Cruiser_Additions", "Cruiser_Additions", "1.0.0")]
public class ca : BaseUnityPlugin
{
	public static readonly Harmony harmony = new Harmony("4902.Cruiser_Additions");

	public static ManualLogSource mls;

	public static ConfigEntry<bool> temp1_magnet;

	public static ConfigEntry<int> temp2_moveitems;

	public static ConfigEntry<bool> temp2_scraponly;

	public static ConfigEntry<bool> temp3_engine;

	public static ConfigEntry<bool> temp3_radio;

	public static ConfigEntry<bool> temp4_light;

	public static ConfigEntry<bool> temp4_night;

	public static ConfigEntry<bool> temp5_scrap;

	public static ConfigEntry<int> temp5_cruiser;

	public static ConfigEntry<int> temp5_cruiseralt;

	public static ConfigEntry<bool> temp5_playwithtoy;

	public static ConfigEntry<bool> temp5_saveseeds;

	public static ConfigEntry<int> temp5_millisecond;

	public static ConfigEntry<bool> temp5_percentages;

	public static ConfigEntry<bool> temp6_speedometer;

	public static ConfigEntry<bool> temp7_unlockables;

	public static ConfigEntry<bool> temp8_collide;

	public static ConfigEntry<bool> temp9_1up;

	public static ConfigEntry<bool> tempk_lever;

	public static ConfigEntry<int> tempi_headlights;

	public static ConfigEntry<bool> tempr_input;

	public static cfg_bool cfg1_magnet = new cfg_bool();

	public static cfg_int cfg2_moveitems = new cfg_int();

	public static cfg_bool cfg2_scraponly = new cfg_bool();

	public static cfg_bool cfg3_engine = new cfg_bool();

	public static cfg_bool cfg3_radio = new cfg_bool();

	public static cfg_bool cfg4_light = new cfg_bool();

	public static cfg_bool cfg4_night = new cfg_bool();

	public static cfg_bool cfg5_scrap = new cfg_bool();

	public static cfg_int cfg5_cruiser = new cfg_int();

	public static cfg_int cfg5_cruiseralt = new cfg_int();

	public static cfg_bool cfg5_playwithtoy = new cfg_bool();

	public static cfg_bool cfg5_saveseeds = new cfg_bool();

	public static cfg_int cfg5_millisecond = new cfg_int();

	public static cfg_bool cfg5_percentages = new cfg_bool();

	public static cfg_bool cfg6_speedometer = new cfg_bool();

	public static cfg_bool cfg7_unlockables = new cfg_bool();

	public static cfg_bool cfg8_collide = new cfg_bool();

	public static cfg_bool cfg9_1up = new cfg_bool();

	public static cfg_bool cfgk_lever = new cfg_bool();

	public static cfg_int cfgi_headlights = new cfg_int();

	public static cfg_bool cfgr_input = new cfg_bool();

	private void Awake()
	{
		temp1_magnet = ((BaseUnityPlugin)this).Config.Bind<bool>("Cruiser+", "magnet_rotation", true, "[Magnet rotation]\nfixes the cruiser rotation when magneted to only be 90 or 270 (parallel to the ship). otherwise at certain angles (~225 or 315-360) it can be magneted to 180 or 360 and be partially inside the ship.\nhost must have this enabled for it to apply. all clients will see the fixed rotation if host has this enabled");
		cfg1_magnet.Value = temp1_magnet.Value;
		temp2_moveitems = ((BaseUnityPlugin)this).Config.Bind<int>("Cruiser+", "move_items", 2, "[Move items]\nmove items from the cruiser to the ship when going into orbit. the items are only moved if they were collected (like with the magnet).\nthis is client sided so items are only shown to have been moved to players with this enabled.\nif one player has this enabled and another player has this disabled (or doesn't have this mod), the item positions will be different, however picking up the item/s will resync the position.\nin vanilla any collected items in the cruiser will be moved to the ship when leaving and rejoining after the game saved, so this feature is the same as vanilla except without having to leave and rejoin.\n1 = disabled\n2 = only enabled when you're host, or if the host has this enabled\n3 = always enabled");
		cfg2_moveitems.Value = temp2_moveitems.Value;
		temp2_scraponly = ((BaseUnityPlugin)this).Config.Bind<bool>("Cruiser+", "only_scrap", true, "[Only move scrap items]\nonly moves scrap and leaves other items in the cruiser.\nif the host has this mod this will be set to what the host has this set to");
		cfg2_scraponly.Value = temp2_scraponly.Value;
		temp3_engine = ((BaseUnityPlugin)this).Config.Bind<bool>("Cruiser+", "mute_engine", true, "[Mute engine audio]\nmute engine audio while in orbit");
		cfg3_engine.Value = temp3_engine.Value;
		temp3_radio = ((BaseUnityPlugin)this).Config.Bind<bool>("Cruiser+", "mute_radio", true, "[Mute radio audio]\nmute radio audio while in orbit");
		cfg3_radio.Value = temp3_radio.Value;
		temp4_light = ((BaseUnityPlugin)this).Config.Bind<bool>("Cruiser+", "light", true, "[Storage light]\nadds a light to the storage area of the cruiser");
		cfg4_light.Value = temp4_light.Value;
		temp4_night = ((BaseUnityPlugin)this).Config.Bind<bool>("Cruiser+", "light_switch", true, "[Storage light switch]\nadds a button in the storage area of the cruiser for turning on/off the storage light.\nturning the light on/off is synced with other players if the host has this mod");
		cfg4_night.Value = temp4_night.Value;
		temp5_scrap = ((BaseUnityPlugin)this).Config.Bind<bool>("Cruiser+", "scrap", true, "[Scrap items]\nwhether cruiser scrap items should be enabled or disabled.\nitems are a percentage based retexture of v-type engine, and are synced with other players if the synced percentages config is enabled");
		cfg5_scrap.Value = temp5_scrap.Value;
		temp5_cruiser = ((BaseUnityPlugin)this).Config.Bind<int>("Cruiser+", "cruiser_percentage", 40, "[Cruiser item percentage]\npercentage that the cruiser item will replace v-type engine.\ninput = percentage, 40 is 40%");
		cfg5_cruiser.Value = temp5_cruiser.Value;
		temp5_cruiseralt = ((BaseUnityPlugin)this).Config.Bind<int>("Cruiser+", "cruiser_alt_percentage", 40, "[Cruiser alt item percentage]\npercentage that the cruiser item will be an alternate version.\ninput = percentage, 40 is 40%");
		cfg5_cruiseralt.Value = temp5_cruiseralt.Value;
		temp5_playwithtoy = ((BaseUnityPlugin)this).Config.Bind<bool>("Cruiser+", "cruiser_item_interaction", true, "[Cruiser item interaction]\nadds interacting with the cruiser items by clicking while holding them to play an event.\nevents are a mix of audio and visual effects, there are about 49 events, some events have follow-up effects that are related to or continue the previous effect.\nhost must have this config and the scrap config enabled for the events to be synced between players. if host has either config disabled or doesn't have this mod then the events will play locally instead");
		cfg5_playwithtoy.Value = temp5_playwithtoy.Value;
		temp5_saveseeds = ((BaseUnityPlugin)this).Config.Bind<bool>("Cruiser+", "save/load", true, "[Save/load seeds]\nwhether the engine/cruiser item types should be saved to the save file. this saves the seed that determines the items type, so it will be the same when rejoining.\nloading a save file that has saved seeds without having the scrap config enabled or without having this enabled or while in lan isn't recommended as the saved seeds can be reset if the number of items is changed.\nsaved item types are synced with other players if the synced percentages config is enabled.\nscrap config must be enabled for this to be enabled");
		cfg5_saveseeds.Value = temp5_saveseeds.Value;
		temp5_millisecond = ((BaseUnityPlugin)this).Config.Bind<int>("Cruiser+", "timer", 100, "[Client wait_timer]\nwhen joining a lobby as non-host engine items will wait to set their item type until the network message sent by the host has been received or the time spent waiting reached the maximum amount set by this config.\nthere will be a log message specifying if the network message was received first or the timer ended first. if the timer is often ending before the message from the host is being received then this should be increased.\nmin is 20, max is 4000. 100 is before the player spawn animation ends, 500 is about 10 seconds, 1000 is about 15 seconds");
		cfg5_millisecond.Value = temp5_millisecond.Value;
		temp5_percentages = ((BaseUnityPlugin)this).Config.Bind<bool>("Cruiser+", "sync", true, "[Synced percentages]\nautomatically sync config cruiser item percentages with the host. only disable if you're aware that disabling this can cause the cruiser item types to not be the same as other players if playing with others that have this mod");
		cfg5_percentages.Value = temp5_percentages.Value;
		temp6_speedometer = ((BaseUnityPlugin)this).Config.Bind<bool>("Cruiser+", "speedometer", true, "[Speedometer]\nadds a speedometer");
		cfg6_speedometer.Value = temp6_speedometer.Value;
		temp7_unlockables = ((BaseUnityPlugin)this).Config.Bind<bool>("Cruiser+", "fix", true, "[Cruiser position/rotation after joining]\nwhen joining a lobby with a cruiser, it will be on the magnet instead of on the opposite side of the ship.\nalso fixes the 'rotation quaternions must be unit length' error from the cruiser after joining");
		cfg7_unlockables.Value = temp7_unlockables.Value;
		temp8_collide = ((BaseUnityPlugin)this).Config.Bind<bool>("Cruiser+", "collide", true, "[QueryTriggerInteraction]\nchanges the Physics.OverlapSphere QueryTriggerInteraction in VehicleController.CollectItemsInTruck from Ignore to Collide.\nattempts to fix some modded items (and teeth) not being collected by the magnet and not having isInShipRoom set to true, so the move items script would skip them");
		cfg8_collide.Value = temp8_collide.Value;
		temp9_1up = ((BaseUnityPlugin)this).Config.Bind<bool>("Cruiser+", "1up", false, "[Cruiser 1up]\nallows purchasing another cruiser in the same day if the current cruiser is destroyed");
		cfg9_1up.Value = temp9_1up.Value;
		tempk_lever = ((BaseUnityPlugin)this).Config.Bind<bool>("Cruiser+", "lever", true, "[Magnet lever]\nadds a lever to the cruiser for turning on/off the ship magnet");
		cfgk_lever.Value = tempk_lever.Value;
		tempi_headlights = ((BaseUnityPlugin)this).Config.Bind<int>("Cruiser+", "headlights", 2, "[Headlights]\nwhether the headlights are on or off when the cruiser is spawned.\n1 = headlights on, headlights material off (same as vanilla)\n2 = headlights on, headlights material on\n3 = headlights off, headlights material off");
		cfgi_headlights.Value = tempi_headlights.Value;
		tempr_input = ((BaseUnityPlugin)this).Config.Bind<bool>("Cruiser+", "disable_input", false, "[Disable input while typing]\nwhether driving the cruiser (wasd/space) is disabled while typing in chat");
		cfgr_input.Value = tempr_input.Value;
		mls = Logger.CreateLogSource("Cruiser+");
		mls.LogInfo((object)":red_car:");
		harmony.PatchAll(typeof(cruiser_additions));
	}
}
public class cfg_bool
{
	public bool Value { get; set; }
}
public class cfg_int
{
	public int Value { get; set; }
}
public class cruiser_additions
{
	private static Vector3 cruiser_rotation;

	private static Transform light_tree = null;

	private static Transform nightlight = null;

	private static Transform meter_cube = null;

	private static Transform meter_text = null;

	private static Transform lever_tree = null;

	private static string[] item = new string[2];

	private static Transform[] tree = (Transform[])(object)new Transform[2];

	private static AudioClip[] take = (AudioClip[])(object)new AudioClip[2];

	private static AudioClip[] give = (AudioClip[])(object)new AudioClip[2];

	private static Vector3[] position = (Vector3[])(object)new Vector3[3];

	private static Vector3[] rotation = (Vector3[])(object)new Vector3[2];

	private static bool first_pending = false;

	private static ulong lobbyid = 0uL;

	private static bool[] first_item = new bool[3] { true, true, true };

	public static int discoball = 1;

	public static string[] red_toy = new string[32]
	{
		"r/Music1^playMusic1^follow_effect,stopMusic", "r/Music2^playMusic2^follow_effect,stopMusic", "r/Music3^playMusic3^follow_effect,stopMusic", "r/Music4^playMusic4^follow_effect,stopMusic", "r/ExtremeStress^extremeStress^follow_effect,switchGear1/switchGear2,duration,60", "r/SwitchGear^switchGear1/switchGear2/switchGear3", "r/PressSpace^jump/boost", "r/SetPlayerInCar^sitDown", "r/Key^insertKey/twistKey/removeKey", "r/Collisions1^minCollision1/minCollision2^chance_percent_one,30,chance_effect_one,maxCollision1/maxCollision2/breakWindshield",
		"r/Collisions2^medCollision1/medCollision2/medCollision3^chance_percent_one,30,chance_effect_one,maxCollision1/maxCollision2/breakWindshield", "r/FrontHood^openFrontHood^follow_effect,closeFrontHood,chance_percent_two,40,chance_effect_two,addHealth/addBoost", "r/Rolling^startRolling^follow_effect,stopRolling", "r/LeftDoor^openLeftDoor^follow_effect,closeLeftDoor,chance_percent_two,5,chance_effect_two,sitDown", "r/RightDoor^openRightDoor^follow_effect,closeRightDoor,chance_percent_two,5,chance_effect_two,sitDown", "r/Spring^spring", "r/Windshield^enableWind^follow_effect,disableWind", "r/CabinWindow^closeWindow^follow_effect,openWindow", "r/LiftGlass^openGlass^follow_effect,closeGlass,chance_percent_two,30,chance_effect_two,spring", "r/FrontHoodFire^startFire^follow_effect,stopFire,chance_percent_two,10,chance_effect_two,addHealth",
		"r/StorageDoor^openBackDoor^follow_effect,closeBackDoor,chance_percent_two,15,chance_effect_two,switchLight", "r/Headlights^enableHeadlights^follow_effect,disableHeadlights", "r/StorageLightSwitch^switchLight", "r/Magnet^enableMagnet1/enableMagnet2^follow_effect,disableMagnet", "r/OpenRandomDoors^openDoors^follow_effect,closeDoors,rarity,80,shion", "r/ScaleToyCar^decreaseScale^follow_effect,resetScale,duration,90,rarity,60", "r/ColoredHeadlights^enableHeadlights^follow_effect,disableHeadlights,rarity,60,shion", "r/Pumpkin^spawnPumpkin^chain,chain_end_effect,spawnPumpkin,chain_end_next,despawnPumpkin,chain_timer_override,rarity,40", "r/Plushie^spawnPlushie^chain,chain_end_effect,spawnPlushie,chain_end_next,despawnPlushie,chain_timer_override,rarity,70", "r/Goldfish^spawnGoldfish^follow_effect,despawnGoldfish,rarity,60",
		"r/DiscoBall^spawnDiscoBall^follow_effect,despawnDiscoBall,rarity,70", "r/Boombox^spawnBoombox^follow_effect,despawnBoombox,rarity,40,shion"
	};

	public static string[] kuro_toy = new string[16]
	{
		"k\\Collisions1^minCollision1/minCollision2", "k\\Collisions2^medCollision1/medCollision2/medCollision3", "k\\Collisions3^maxCollision1/maxCollision2", "k\\Collisions4^obsCollision1/obsCollision2/obsCollision3", "k\\ChainedCollisions^minCollision1_cd/minCollision2_cd/medCollision1_cd/medCollision2_cd/medCollision3_cd/maxCollision1_cd/maxCollision2_cd^chain", "k\\ChainedCollisionsExplosion^minCollision1_cd/minCollision2_cd/medCollision1_cd/medCollision2_cd/medCollision3_cd/maxCollision1_cd/maxCollision2_cd^chain,chain_end_effect,explosion,chain_end_next,stopFire", "k\\Explosion^explosion^follow_effect,stopFire,chance_percent_two,10,chance_effect_two,addHealth", "k\\ChainedBoost^boost^chain,shion", "k\\ChainedBoostExplosion^boost^chain,chain_end_effect,explosion,chain_end_next,stopFire,shion", "k\\ExtremeStressExplosion^extremeStress^follow_effect,stopFire,chance_percent_two,100,chance_effect_two,explosion,duration,60",
		"k\\CollectToyCar^collect^chance_percent_one,20,chance_effect_one,collectN/collect240/collect240N,follow_effect,uncollect,duration,160", "k\\Pumpkin^spawnPumpkin^chain,chain_end_effect,spawnPumpkin,chain_end_next,despawnPumpkin,chain_timer_override,rarity,60", "k\\Plushie^spawnPlushie^chain,chain_end_effect,spawnPlushie,chain_end_next,despawnPlushie,chain_timer_override,rarity,20", "k\\Goldfish^spawnGoldfish^follow_effect,despawnGoldfish,rarity,20", "k\\DiscoBall^spawnDiscoBall^follow_effect,despawnDiscoBall,rarity,60", "k\\Boombox^spawnBoombox^follow_effect,despawnBoombox,rarity,60,shion"
	};

	private static bool sync = false;

	private static string hostmoveitems = "nil";

	private static string hostscraponly = "nil";

	private static string hosttoycarcfg = "nil";

	private static string seeds = "nil";

	private static bool[] disconnected;

	private static int[] synced_percents;

	private static bool client_received;

	private static string saved_engine;

	private static List<string> loaded_engine;

	[HarmonyPrefix]
	[HarmonyPatch(typeof(VehicleController), "StartMagneting")]
	private static void pre1(VehicleController __instance)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		cruiser_rotation = ((Component)__instance).transform.eulerAngles;
	}

	[HarmonyPatch(typeof(VehicleController), "StartMagneting")]
	[HarmonyTranspiler]
	private static IEnumerable<CodeInstruction> trn1(IEnumerable<CodeInstruction> Instrs)
	{
		List<CodeInstruction> i = new List<CodeInstruction>(Instrs);
		for (int j = 0; j < i.Count; j++)
		{
			if (j >= 11 && ((object)i[j - 11]).ToString() == "call static UnityEngine.Color UnityEngine.Color::get_white()")
			{
				yield return new CodeInstruction(OpCodes.Call, (object)typeof(cruiser_additions).GetMethod("return_rotation"));
			}
			yield return i[j];
		}
	}

	public static float return_rotation(float r)
	{
		if (ca.cfg1_magnet.Value)
		{
			if (cruiser_rotation.y < 180f)
			{
				ca.mls.LogInfo((object)("eulerAngles.y " + cruiser_rotation.y + " < 180, returning 90"));
				return 90f;
			}
			ca.mls.LogInfo((object)("eulerAngles.y " + cruiser_rotation.y + " > 180, returning 270"));
			return 270f;
		}
		return r;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(StartOfRound), "EndOfGame")]
	private static void pre2(StartOfRound __instance)
	{
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: 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_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0332: Unknown result type (might be due to invalid IL or missing references)
		//IL_0337: Unknown result type (might be due to invalid IL or missing references)
		//IL_033c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0372: Unknown result type (might be due to invalid IL or missing references)
		//IL_0383: Unknown result type (might be due to invalid IL or missing references)
		//IL_038c: Unknown result type (might be due to invalid IL or missing references)
		//IL_038e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0394: Unknown result type (might be due to invalid IL or missing references)
		//IL_0396: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
		VehicleController attachedVehicle = __instance.attachedVehicle;
		if (!((Object)(object)attachedVehicle != (Object)null))
		{
			return;
		}
		if (ca.cfg2_moveitems.Value == 3 || (ca.cfg2_moveitems.Value == 2 && (hostmoveitems == "true" || GameNetworkManager.Instance.isHostingGame)))
		{
			ca.mls.LogInfo((object)"moving items");
			ca.mls.LogInfo((object)("host:" + hostscraponly + " client:" + ca.cfg2_scraponly.Value).ToLower());
			Collider[] array = Physics.OverlapBox(((Component)attachedVehicle).transform.position, new Vector3(4f, 11f, 11f) / 2f, new Quaternion(0f, 0.7071068f, 0f, 0.7071068f), 64, (QueryTriggerInteraction)2);
			ca.mls.LogInfo((object)("total items found in cruiser: " + array.Length));
			for (int i = 0; i < array.Length; i++)
			{
				GrabbableObject component = ((Component)array[i]).GetComponent<GrabbableObject>();
				if ((Object)(object)component != (Object)null && (hostscraponly == "false" || (hostscraponly == "true" && component.itemProperties.isScrap) || (hostscraponly == "nil" && !ca.cfg2_scraponly.Value) || (hostscraponly == "nil" && ca.cfg2_scraponly.Value && component.itemProperties.isScrap)) && !component.isHeld && !component.isHeldByEnemy && component.isInShipRoom)
				{
					ca.mls.LogInfo((object)("moving item " + (i + 1) + " " + component.itemProperties.itemName + " / " + ((Object)component.itemProperties).name + " / " + ((Object)component).name));
					((Component)component).transform.SetParent(StartOfRound.Instance.elevatorTransform);
					Shion shion = ((!GameNetworkManager.Instance.disableSteam && lobbyid != 0 && (Object)(object)((Component)component).GetComponent<NetworkObject>() != (Object)null) ? new Shion(lobbyid + ((Component)component).GetComponent<NetworkObject>().NetworkObjectId) : new Shion());
					double num = shion.next01() * Math.PI * 2.0;
					double num2 = shion.next01() * 1.0;
					double num3 = -0.33000001311302185 + num2 * Math.Cos(num);
					double num4 = -14.399999618530273 + num2 * Math.Sin(num);
					Vector3 val = ((Component)component).transform.parent.InverseTransformPoint(new Vector3((float)num3, component.itemProperties.verticalOffset + 0.2362f, (float)num4));
					((Component)component).transform.eulerAngles = new Vector3(component.itemProperties.restingRotation.x, (float)shion.next32mm(0, 360), component.itemProperties.restingRotation.z);
					((Component)component).transform.position = val;
					component.startFallingPosition = val;
					component.targetFloorPosition = val;
					if ((Object)(object)component.itemProperties.spawnPrefab != (Object)null)
					{
						((Component)component).transform.localScale = component.itemProperties.spawnPrefab.transform.localScale;
					}
					else
					{
						((Component)component).transform.localScale = component.originalScale;
					}
				}
				else if ((Object)(object)component != (Object)null)
				{
					ca.mls.LogInfo((object)("skipped item " + (i + 1) + " " + component.itemProperties.itemName + " / " + ((Object)component.itemProperties).name + " / " + ((Object)component).name));
					if (!component.isInShipRoom)
					{
						ca.mls.LogInfo((object)("skipped item " + (i + 1) + " wasn't collected! isInShipRoom was false. it will be in the cruiser"));
					}
				}
			}
		}
		if (ca.cfg3_engine.Value)
		{
			ca.mls.LogInfo((object)"muting engine");
			attachedVehicle.engineAudio1.mute = true;
			attachedVehicle.engineAudio2.mute = true;
		}
		if (ca.cfg3_radio.Value)
		{
			ca.mls.LogInfo((object)"muting radio");
			attachedVehicle.radioAudio.mute = true;
			attachedVehicle.radioInterference.mute = true;
		}
	}

	[HarmonyTranspiler]
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	private static IEnumerable<CodeInstruction> trn2(IEnumerable<CodeInstruction> Instrs)
	{
		List<CodeInstruction> i = new List<CodeInstruction>(Instrs);
		for (int j = 0; j < i.Count; j++)
		{
			yield return i[j];
			if (j >= 2 && ((object)i[j - 2]).ToString() == "ldstr \"Closed\"")
			{
				yield return new CodeInstruction(OpCodes.Call, (object)typeof(cruiser_additions).GetMethod("unmute_audio"));
			}
		}
	}

	public static void unmute_audio()
	{
		VehicleController attachedVehicle = StartOfRound.Instance.attachedVehicle;
		if ((Object)(object)attachedVehicle != (Object)null)
		{
			if (ca.cfg3_engine.Value)
			{
				ca.mls.LogInfo((object)"unmuting engine");
				attachedVehicle.engineAudio1.mute = false;
				attachedVehicle.engineAudio2.mute = false;
			}
			if (ca.cfg3_radio.Value)
			{
				ca.mls.LogInfo((object)"unmuting radio");
				attachedVehicle.radioAudio.mute = false;
				attachedVehicle.radioInterference.mute = false;
			}
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(VehicleController), "Start")]
	private static void pre3(VehicleController __instance)
	{
		//IL_0843: Unknown result type (might be due to invalid IL or missing references)
		//IL_0897: Unknown result type (might be due to invalid IL or missing references)
		//IL_08b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_08cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cfe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d1a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_09fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_034c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0367: Unknown result type (might be due to invalid IL or missing references)
		//IL_0382: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0e00: Unknown result type (might be due to invalid IL or missing references)
		//IL_0e1c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0e38: Unknown result type (might be due to invalid IL or missing references)
		//IL_0e68: Unknown result type (might be due to invalid IL or missing references)
		//IL_0e72: Expected O, but got Unknown
		//IL_04d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_050a: Unknown result type (might be due to invalid IL or missing references)
		//IL_053a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0544: Expected O, but got Unknown
		//IL_0f8f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0fab: Unknown result type (might be due to invalid IL or missing references)
		//IL_0fc7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0aed: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b09: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b25: Unknown result type (might be due to invalid IL or missing references)
		//IL_06dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_06f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0714: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b8d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ba9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bc5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0beb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c07: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c23: Unknown result type (might be due to invalid IL or missing references)
		string text = (ca.cfg4_light.Value ? ", light" : "") + ((ca.cfg4_light.Value && ca.cfg4_night.Value) ? ", light switch" : "") + (ca.cfg6_speedometer.Value ? ", speedometer" : "") + (ca.cfgk_lever.Value ? ", magnet lever" : "");
		if (text != null && text != "")
		{
			ca.mls.LogInfo((object)("adding " + text.Substring(2)));
		}
		if (ca.cfg4_light.Value)
		{
			if ((Object)(object)light_tree == (Object)null)
			{
				Transform val = Object.Instantiate<Transform>(__instance.frontCabinLightContainer.GetComponentsInChildren<Transform>(true)[1]);
				((Object)val).name = "cruiser_storage_light";
				Light componentInChildren = ((Component)val).GetComponentInChildren<Light>();
				componentInChildren.type = (LightType)0;
				componentInChildren.spotAngle = 120f;
				componentInChildren.range = 10f;
				light_tree = val;
				((Component)light_tree).gameObject.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)light_tree);
				ca.mls.LogInfo((object)"saved light");
			}
			if ((Object)(object)light_tree != (Object)null)
			{
				Transform val = Object.Instantiate<Transform>(light_tree);
				val.SetParent(((Component)__instance).GetComponentsInChildren<Transform>().First((Transform _) => ((Object)_).name == "Meshes"));
				val.localPosition = new Vector3(0f, 3f, -2f);
				val.localEulerAngles = new Vector3(90f, 0f, 0f);
				val.localScale = new Vector3(1f, 1f, 1f);
				((Component)val).gameObject.SetActive(__instance.frontCabinLightContainer.activeSelf);
				ca.mls.LogInfo((object)"added light");
			}
			if (ca.cfg4_night.Value)
			{
				if ((Object)(object)nightlight == (Object)null)
				{
					Transform val2 = Object.Instantiate<Transform>(GameObject.Find("Environment/HangarShip/damageTrigger/Cube").transform);
					((Renderer)((Component)val2).GetComponent<MeshRenderer>()).materials = (Material[])(object)new Material[1] { ((Renderer)GameObject.Find("Environment/HangarShip/ShipModels2b/MonitorWall/Cube").GetComponent<MeshRenderer>()).materials[1] };
					Transform val3 = Object.Instantiate<Transform>(GameObject.Find("Environment/HangarShip/ShipModels2b/MonitorWall/Cube.001/CameraMonitorOnButton").transform);
					val3.SetParent(val2);
					val3.localPosition = new Vector3(0f, 0f, 0.375f);
					val3.localEulerAngles = new Vector3(90f, 180f, 0f);
					val3.localScale = new Vector3(4.8137f, 19.5712f, 4.8137f);
					((Component)val3).gameObject.SetActive(true);
					Object.DestroyImmediate((Object)(object)((Component)val3.GetChild(0)).gameObject);
					Transform val = Object.Instantiate<Transform>(light_tree);
					val.SetParent(val2);
					val.localPosition = new Vector3(0f, 0f, 0.875f);
					val.localEulerAngles = new Vector3(0f, 0f, 0f);
					val.localScale = new Vector3(1f, 1f, 1f);
					((Component)val).gameObject.SetActive(false);
					Light component = ((Component)val).GetComponent<Light>();
					component.color = new Color(0.165f, 0f, 0f, 1f);
					component.colorTemperature = 1f;
					component.innerSpotAngle = 5.2f;
					component.intensity = 5f;
					component.range = 0.06f;
					component.shadows = (LightShadows)0;
					component.spotAngle = 5.2f;
					component.type = (LightType)2;
					HDAdditionalLightData component2 = ((Component)val).GetComponent<HDAdditionalLightData>();
					component2.customSpotLightShadowCone = 5.2f;
					component2.innerSpotPercent = 66.4f;
					component2.intensity = 14.7321f;
					component.intensity = 5f;
					component2.shadowFadeDistance = 8f;
					component2.shadowNearPlane = 0f;
					component2.shapeRadius = 0.2f;
					component2.volumetricDimmer = 0.86f;
					Transform val4 = Object.Instantiate<Transform>(((Component)__instance).GetComponentsInChildren<Transform>(true).First((Transform _) => ((Object)_).name == "ChangeChannel (3)"));
					val4.SetParent(val2);
					val4.localPosition = new Vector3(0f, 0f, 0.25f);
					val4.localEulerAngles = new Vector3(0f, 0f, 0f);
					val4.localScale = new Vector3(2f, 2f, 1.25f);
					((Component)val4).gameObject.SetActive(true);
					InteractTrigger component3 = ((Component)val4).GetComponent<InteractTrigger>();
					component3.hoverTip = "Switch light: [LMB]";
					component3.onInteract = new InteractEvent();
					component3.twoHandedItemAllowed = true;
					((Component)val2).gameObject.AddComponent<cruiser_light_switch_component>();
					((Component)val2).gameObject.AddComponent<AudioSource>();
					AudioSource component4 = ((Component)val2).gameObject.GetComponent<AudioSource>();
					component4.clip = StartOfRound.Instance.allItemsList.itemsList.First((Item _) => ((Object)_).name == "ProFlashlight").spawnPrefab.GetComponent<FlashlightItem>().flashlightClips[0];
					component4.dopplerLevel = 0.3f;
					component4.maxDistance = 9f;
					component4.minDistance = 4f;
					component4.playOnAwake = false;
					component4.rolloffMode = (AudioRolloffMode)1;
					component4.spatialBlend = 1f;
					component4.spread = 71f;
					((Object)val2).name = "cruiser_light_switch";
					((Object)val3).name = "cruiser_night_switch";
					((Object)val).name = "cruiser_night_light";
					((Object)val4).name = "cruiser_night_interact";
					nightlight = val2;
					((Component)nightlight).gameObject.SetActive(false);
					Object.DontDestroyOnLoad((Object)(object)nightlight);
					ca.mls.LogInfo((object)"saved light switch");
				}
				if ((Object)(object)nightlight != (Object)null)
				{
					Transform val5 = Object.Instantiate<Transform>(nightlight);
					val5.SetParent(((Component)__instance).GetComponentsInChildren<Transform>().First((Transform _) => ((Object)_).name == "Triggers"));
					val5.localPosition = new Vector3(-1.34f, 0.9f, -3.2f);
					val5.localEulerAngles = new Vector3(0f, 90f, 0f);
					val5.localScale = new Vector3(0.15f, 0.15f, 0.08f);
					((Component)val5.GetChild(1)).GetComponent<Light>().intensity = 5f;
					((Component)val5).gameObject.SetActive(true);
					((Component)val5.GetChild(1)).gameObject.SetActive(!((Component)((Component)__instance).GetComponentsInChildren<Transform>(true).First((Transform _) => ((Object)_).name == "cruiser_storage_light(Clone)")).gameObject.activeSelf);
					ca.mls.LogInfo((object)"added light switch");
				}
			}
		}
		if (ca.cfg6_speedometer.Value)
		{
			if ((Object)(object)meter_cube == (Object)null)
			{
				Transform val6 = Object.Instantiate<Transform>(GameObject.Find("Environment/HangarShip/damageTrigger/Cube").transform);
				Transform val2 = Object.Instantiate<Transform>(val6);
				((Renderer)((Component)val6).GetComponent<MeshRenderer>()).materials = (Material[])(object)new Material[1] { ((Renderer)GameObject.Find("Environment/HangarShip/SmallDetails/Cameras/TinyCamera").GetComponent<MeshRenderer>()).materials[0] };
				((Renderer)((Component)val6).GetComponent<MeshRenderer>()).materials[0].color = new Color(0f, 0f, 0f, 0f);
				((Renderer)((Component)val2).GetComponent<MeshRenderer>()).materials = (Material[])(object)new Material[1] { ((Renderer)GameObject.Find("Environment/HangarShip/ShipModels2b/MonitorWall/Cube").GetComponent<MeshRenderer>()).materials[1] };
				val2.SetParent(val6);
				val2.localPosition = new Vector3(0f, 0f, 0f);
				val2.localEulerAngles = new Vector3(0f, 0f, 0f);
				val2.localScale = new Vector3(0.98f, 1.2f, 1.2f);
				((Object)val6).name = "cruiser_speedometer_screen";
				((Object)val2).name = "cruiser_speedometer_border";
				meter_cube = val6;
				((Component)meter_cube).gameObject.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)meter_cube);
				ca.mls.LogInfo((object)"saved speedometer object");
				Transform val7 = Object.Instantiate<Transform>(GameObject.Find("Environment/HangarShip/ShipModels2b/MonitorWall/Cube/Canvas (1)").transform);
				Transform val8 = ((Component)val7).GetComponentsInChildren<Transform>(true).First((Transform _) => ((Object)_).name == "HeaderText");
				val8.SetParent(val7);
				((Component)val8).gameObject.SetActive(true);
				Transform val9 = ((Component)val7).GetComponentsInChildren<Transform>(true).First((Transform _) => ((Object)_).name == "MainContainer");
				Object.DestroyImmediate((Object)(object)((Component)val9).GetComponent<Image>());
				Object.DestroyImmediate((Object)(object)((Component)val9).gameObject);
				TextMeshProUGUI component5 = ((Component)val8).GetComponent<TextMeshProUGUI>();
				((Behaviour)component5).enabled = true;
				((TMP_Text)component5).alignment = (TextAlignmentOptions)514;
				((Graphic)component5).color = new Color(1f, 1f, 1f, 1f);
				((TMP_Text)component5).fontStyle = (FontStyles)1;
				((TMP_Text)component5).horizontalAlignment = (HorizontalAlignmentOptions)2;
				((TMP_Text)component5).text = "444";
				((Object)val7).name = "cruiser_speedometer_text1";
				((Object)val8).name = "cruiser_speedometer_text2";
				meter_text = val7;
				((Component)meter_text).gameObject.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)meter_text);
				ca.mls.LogInfo((object)"saved speedometer text");
			}
			if ((Object)(object)meter_cube != (Object)null && (Object)(object)meter_text != (Object)null)
			{
				Transform val10 = Object.Instantiate<Transform>(meter_cube);
				val10.SetParent(((Component)__instance).GetComponentsInChildren<Transform>().First((Transform _) => ((Object)_).name == "Meshes"));
				val10.localPosition = new Vector3(-1f, 0.115f, 2.65f);
				val10.localEulerAngles = new Vector3(0f, 90f, 30f);
				val10.localScale = new Vector3(0.2f, 0.08f, 0.13f);
				((Component)val10).gameObject.SetActive(true);
				Transform val11 = Object.Instantiate<Transform>(meter_text);
				val11.SetParent(((Component)__instance).GetComponentsInChildren<Transform>().First((Transform _) => ((Object)_).name == "Meshes"));
				val11.localPosition = new Vector3(-0.995f, 0.157f, 2.558f);
				val11.localEulerAngles = new Vector3(30f, 0f, 0f);
				val11.localScale = new Vector3(0.001f, 0.001f, 0.001f);
				Transform val8 = val11.GetChild(0);
				val8.localPosition = new Vector3(-4.7f, 7f, 0f);
				val8.localEulerAngles = new Vector3(0f, 0f, 0f);
				val8.localScale = new Vector3(1f, 1f, 1f);
				TextMeshProUGUI component6 = ((Component)val8).GetComponent<TextMeshProUGUI>();
				((Behaviour)component6).enabled = true;
				((TMP_Text)component6).enableWordWrapping = false;
				((TMP_Text)component6).autoSizeTextContainer = false;
				((TMP_Text)component6).enableAutoSizing = false;
				((TMP_Text)component6).text = "444";
				((TMP_Text)component6).autoSizeTextContainer = true;
				((TMP_Text)component6).enableAutoSizing = true;
				((Component)val11).gameObject.SetActive(__instance.frontCabinLightContainer.activeSelf);
				ca.mls.LogInfo((object)"added speedometer");
			}
		}
		if (ca.cfgk_lever.Value)
		{
			Transform transform = ((Component)((Component)__instance).GetComponentsInChildren<InteractTrigger>(true).First((InteractTrigger _) => ((Object)_).name == "DoorTrigger" && ((Object)((Component)_).transform.parent.parent).name == "DoorLeftContainer")).transform;
			transform.localPosition = new Vector3(1.1171f, -0.0073f, -0.4219f);
			transform.localScale = new Vector3(1.8201f, 0.2525f, 1.8792f);
			if ((Object)(object)lever_tree == (Object)null)
			{
				GameObject val12 = GameObject.Find("Environment/HangarShip/MagnetLever");
				Transform val13 = Object.Instantiate<Transform>(val12.transform);
				AudioSource component4 = ((Component)val13).GetComponent<AudioSource>();
				component4.clip = val12.GetComponent<AnimatedObjectTrigger>().boolFalseAudios[0];
				component4.dopplerLevel = 0.3f;
				component4.maxDistance = 17f;
				component4.spread = 45f;
				component4.volume = 0.9f;
				component4.playOnAwake = false;
				Transform val4 = Object.Instantiate<Transform>(((Component)__instance).GetComponentsInChildren<Transform>(true).First((Transform _) => ((Object)_).name == "ChangeChannel (3)"));
				val4.SetParent(val13);
				val4.localPosition = new Vector3(0.0667f, -0.0833f, 0f);
				val4.localEulerAngles = new Vector3(0f, 225f, 60f);
				val4.localScale = new Vector3(0.2f, 0.4167f, 0.4167f);
				((Component)val4).gameObject.SetActive(true);
				InteractTrigger component3 = ((Component)val4).GetComponent<InteractTrigger>();
				component3.hoverTip = "Pull lever: [LMB]";
				component3.onInteract = new InteractEvent();
				component3.twoHandedItemAllowed = true;
				component3.holdInteraction = true;
				component3.cooldownTime = 1f;
				component3.timeToHold = 1.7f;
				component3.timeToHoldSpeedMultiplier = 1f;
				((Component)val13).gameObject.AddComponent<cruiser_magnet_lever_component>();
				Object.DestroyImmediate((Object)(object)((Component)val13).GetComponent<BoxCollider>());
				Object.DestroyImmediate((Object)(object)((Component)val13).GetComponent<AnimatedObjectTrigger>());
				Object.DestroyImmediate((Object)(object)((Component)val13).GetComponent<InteractTrigger>());
				((Object)val4).name = "cruiser_magnet_lever_interact";
				((Object)val13).name = "cruiser_magnet_lever";
				lever_tree = val13;
				((Component)lever_tree).gameObject.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)lever_tree);
				ca.mls.LogInfo((object)"saved magnet lever");
			}
			if ((Object)(object)lever_tree != (Object)null)
			{
				Transform val13 = Object.Instantiate<Transform>(lever_tree);
				val13.SetParent(((Component)__instance).GetComponentsInChildren<Transform>().First((Transform _) => ((Object)_).name == "Meshes"));
				val13.localPosition = new Vector3(-1.71f, 0f, 2.78f);
				val13.localEulerAngles = new Vector3(90f, 90f, 0f);
				val13.localScale = new Vector3(0.6f, 0.6f, 0.6f);
				((Component)val13).gameObject.SetActive(true);
				ca.mls.LogInfo((object)"added magnet lever");
			}
		}
		if (ca.cfgi_headlights.Value == 2 || ca.cfgi_headlights.Value == 3)
		{
			set_headlights(__instance);
		}
	}

	private static async void set_headlights(VehicleController v)
	{
		v.headlightsContainer.SetActive(ca.cfgi_headlights.Value == 2);
		Material cat = ((ca.cfgi_headlights.Value == 2) ? v.headlightsOnMat : v.headlightsOffMat);
		Material[] cats = ((Renderer)v.mainBodyMesh).sharedMaterials;
		cats[1] = cat;
		((Renderer)v.mainBodyMesh).sharedMaterials = cats;
		await wait_frames(1);
		v.headlightsContainer.SetActive(ca.cfgi_headlights.Value == 2);
		((Renderer)v.mainBodyMesh).sharedMaterials = cats;
		await wait_frames(4);
		v.headlightsContainer.SetActive(ca.cfgi_headlights.Value == 2);
		((Renderer)v.mainBodyMesh).sharedMaterials = cats;
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(VehicleController), "SetFrontCabinLightOn")]
	private static void pst1(VehicleController __instance, ref bool setOn)
	{
		if (__instance.averageCount < 4)
		{
			return;
		}
		if (ca.cfg4_light.Value && (Object)(object)light_tree != (Object)null)
		{
			((Component)((IEnumerable<Transform>)((Component)__instance).GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform _) => ((Object)_).name == "cruiser_storage_light(Clone)"))).gameObject.SetActive(setOn);
			if (ca.cfg4_night.Value && (Object)(object)nightlight != (Object)null)
			{
				((Component)((IEnumerable<Transform>)((Component)__instance).GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform _) => ((Object)_).name == "cruiser_night_light"))).gameObject.SetActive(!setOn);
			}
		}
		if (!ca.cfg6_speedometer.Value || !((Object)(object)meter_cube != (Object)null) || !((Object)(object)meter_text != (Object)null))
		{
			return;
		}
		RectTransform val = ((IEnumerable<RectTransform>)((Component)__instance).GetComponentsInChildren<RectTransform>(true)).FirstOrDefault((Func<RectTransform, bool>)((RectTransform _) => ((Object)_).name == "cruiser_speedometer_text1(Clone)"));
		if ((Object)(object)val != (Object)null)
		{
			if (((TMP_Text)((Component)((Transform)val).GetChild(0)).GetComponent<TextMeshProUGUI>()).text == "444")
			{
				((TMP_Text)((Component)((Transform)val).GetChild(0)).GetComponent<TextMeshProUGUI>()).text = "0";
			}
			((Component)val).gameObject.SetActive(setOn);
		}
	}

	[HarmonyPatch(typeof(VehicleController), "DestroyCar")]
	[HarmonyPostfix]
	private static void pst2(VehicleController __instance)
	{
		if (ca.cfg4_light.Value && (Object)(object)light_tree != (Object)null)
		{
			((Component)((Component)__instance).GetComponentsInChildren<Transform>(true).First((Transform _) => ((Object)_).name == "cruiser_storage_light(Clone)")).gameObject.SetActive(false);
		}
		if (ca.cfg6_speedometer.Value && (Object)(object)meter_cube != (Object)null && (Object)(object)meter_text != (Object)null)
		{
			((Component)((Component)__instance).GetComponentsInChildren<Transform>(true).First((Transform _) => ((Object)_).name == "cruiser_speedometer_screen(Clone)")).gameObject.SetActive(false);
			((Component)((Component)__instance).GetComponentsInChildren<RectTransform>(true).First((RectTransform _) => ((Object)_).name == "cruiser_speedometer_text1(Clone)")).gameObject.SetActive(false);
		}
		if (ca.cfgk_lever.Value && (Object)(object)lever_tree != (Object)null)
		{
			((Component)((Component)__instance).GetComponentsInChildren<Transform>(true).First((Transform _) => ((Object)_).name == "cruiser_magnet_lever(Clone)")).gameObject.SetActive(false);
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(VehicleController), "FixedUpdate")]
	private static void pst3(VehicleController __instance)
	{
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		if (!ca.cfg6_speedometer.Value || !((Object)(object)meter_cube != (Object)null) || !((Object)(object)meter_text != (Object)null) || !__instance.ignitionStarted || __instance.averageCount < 4)
		{
			return;
		}
		RectTransform val = ((IEnumerable<RectTransform>)((Component)__instance).GetComponentsInChildren<RectTransform>(true)).FirstOrDefault((Func<RectTransform, bool>)((RectTransform _) => ((Object)_).name == "cruiser_speedometer_text1(Clone)"));
		if (!((Object)(object)val != (Object)null) || !((Component)val).gameObject.activeSelf)
		{
			return;
		}
		TextMeshProUGUI component = ((Component)((Transform)val).GetChild(0)).GetComponent<TextMeshProUGUI>();
		Vector3 velocity = __instance.mainRigidbody.velocity;
		string text = Mathf.Round(((Vector3)(ref velocity)).magnitude * 2f).ToString();
		if (text != ((TMP_Text)component).text)
		{
			if (text.Length > 5)
			{
				text = "Error";
			}
			((TMP_Text)component).text = text;
		}
	}

	[HarmonyPatch(typeof(StartOfRound), "SetMagnetOnClientRpc")]
	[HarmonyPostfix]
	private static void pst4(StartOfRound __instance, bool on)
	{
		if (!ca.cfgk_lever.Value || !((Object)(object)lever_tree != (Object)null))
		{
			return;
		}
		VehicleController[] array = Object.FindObjectsOfType<VehicleController>();
		foreach (VehicleController val in array)
		{
			Transform val2 = ((IEnumerable<Transform>)((Component)val).GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform _) => ((Object)_).name == "cruiser_magnet_lever(Clone)"));
			if (!((Object)(object)val2 == (Object)null))
			{
				Animator component = ((Component)val2).GetComponent<Animator>();
				if (component.GetBool("leverUp") != on)
				{
					AudioSource component2 = ((Component)val2).GetComponent<AudioSource>();
					component2.PlayOneShot(on ? __instance.magnetOnAudio : __instance.magnetOffAudio);
					component2.Play();
				}
				component.SetBool("leverUp", on);
			}
		}
	}

	public static void switch_light_event(PlayerControllerB player)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		Ray val = default(Ray);
		((Ray)(ref val))..ctor(((Component)player.gameplayCamera).transform.position, ((Component)player.gameplayCamera).transform.forward);
		RaycastHit val2 = default(RaycastHit);
		Physics.Raycast(val, ref val2, player.grabDistance, 1073742656);
		VehicleController component = ((Component)((Component)((RaycastHit)(ref val2)).collider).gameObject.transform.root).GetComponent<VehicleController>();
		if ((Object)(object)component != (Object)null && (Object)(object)((Component)component).GetComponent<NetworkObject>() != (Object)null)
		{
			ulong networkObjectId = ((Component)component).GetComponent<NetworkObject>().NetworkObjectId;
			bool flag = !((Component)((Component)component).GetComponentsInChildren<Transform>(true).First((Transform _) => ((Object)_).name == "cruiser_night_light")).gameObject.activeSelf;
			if (StartOfRound.Instance.connectedPlayersAmount + 1 != 1 && sync)
			{
				if (GameNetworkManager.Instance.isHostingGame)
				{
					update_clients_lights(networkObjectId, flag);
					return;
				}
				if (client_received && !NetworkManager.Singleton.IsHost)
				{
					string text = "LightSwitchRequest^" + networkObjectId + "^" + flag;
					FastBufferWriter val3 = default(FastBufferWriter);
					((FastBufferWriter)(ref val3))..ctor(FastBufferWriter.GetWriteSize(text, false), (Allocator)2, -1);
					((FastBufferWriter)(ref val3)).WriteValueSafe(text, false);
					NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("4902.Cruiser_Additions-Host", 0uL, val3, (NetworkDelivery)4);
					((FastBufferWriter)(ref val3)).Dispose();
					return;
				}
			}
			switch_light(networkObjectId, flag);
		}
		else
		{
			ca.mls.LogError((object)("switch_light_event error" + (((Object)(object)component == (Object)null) ? ", cruiser was null" : ", cruiser NetworkObject component was null")));
		}
	}

	private static void switch_light(ulong guid, bool red)
	{
		if (!ca.cfg4_light.Value || !ca.cfg4_night.Value || !((Object)(object)nightlight != (Object)null))
		{
			return;
		}
		VehicleController val = ((IEnumerable<VehicleController>)Object.FindObjectsOfType<VehicleController>()).FirstOrDefault((Func<VehicleController, bool>)((VehicleController _) => (Object)(object)((Component)_).GetComponent<NetworkObject>() != (Object)null && ((Component)_).GetComponent<NetworkObject>().NetworkObjectId == guid));
		if ((Object)(object)val != (Object)null)
		{
			Transform val2 = ((IEnumerable<Transform>)((Component)val).GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform _) => ((Object)_).name == "cruiser_storage_light(Clone)"));
			if (((Component)val2).gameObject.activeSelf == red)
			{
				Transform val3 = ((IEnumerable<Transform>)((Component)val).GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform _) => ((Object)_).name == "cruiser_light_switch(Clone)"));
				Transform child = val3.GetChild(1);
				((Component)child).GetComponent<Light>().intensity = 5f;
				((Component)child).gameObject.SetActive(red);
				AudioSource component = ((Component)val3).gameObject.GetComponent<AudioSource>();
				if ((Object)(object)component != (Object)null)
				{
					component.PlayOneShot(component.clip);
				}
				((Component)val2).gameObject.SetActive(!red);
			}
		}
		else
		{
			ca.mls.LogError((object)"switch_light error, cruiser was null");
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(GrabbableObject), "Start")]
	private static void pst5(GrabbableObject __instance)
	{
		pst5async(__instance);
	}

	private static async void pst5async(GrabbableObject __instance)
	{
		if (!ca.cfg5_scrap.Value || !(((Object)__instance.itemProperties).name == "EnginePart1"))
		{
			return;
		}
		await wait_frames(1);
		if ((Object)(object)((Component)__instance).gameObject.GetComponent<temporary>() != (Object)null)
		{
			return;
		}
		((Component)__instance).gameObject.AddComponent<temporary>();
		if (first_item[0])
		{
			Item val = StartOfRound.Instance.allItemsList.itemsList.First((Item _) => ((Object)_).name == "EnginePart1");
			val.restingRotation = new Vector3(0f, 0f, 90f);
			val.verticalOffset = 0.4f;
		}
		if (!GameNetworkManager.Instance.disableSteam && seeds == "nil")
		{
			if (!GameNetworkManager.Instance.isHostingGame)
			{
				if (first_item[0])
				{
					ca.mls.LogInfo((object)"await wait_timer");
					first_item[0] = false;
				}
				await wait_timer((ca.cfg5_millisecond.Value >= 20 && ca.cfg5_millisecond.Value <= 4000) ? ca.cfg5_millisecond.Value : 100);
				if (disconnected[0])
				{
					return;
				}
			}
			if (seeds == "nil")
			{
				seeds = "?";
			}
		}
		if (first_pending)
		{
			await wait_frames(2);
		}
		if (item[0] == null && !first_pending)
		{
			ca.mls.LogInfo((object)"first engine");
			first_pending = true;
			Transform tr = Object.Instantiate<Transform>(StartOfRound.Instance.VehiclesList[0].GetComponentsInChildren<Transform>().First((Transform _) => ((Object)_).name == "Meshes"));
			List<string> sl = new List<string>
			{
				"Cube.002", "Cube.003", "HoodTrigger", "DoorTrigger", "Collider", "DoorTrigger", "Collider", "Links", "ClosedCollider", "ClosedTrigger",
				"OpenCollider", "OpenTrigger", "DoorLeft", "ShiftToReverseTrigger", "ShiftToDriveTrigger", "ShiftToParkTrigger", "CarKeyTurnedPos", "CarKeyNotTurnedPos", "StartIgnition", "StopIgnition",
				"InteractionBlockers", "Cube", "Cube", "WindshieldInteractBlocker", "FrontCabinLight", "BackLights", "SparkParticle (1)"
			};
			Transform[] componentsInChildren = ((Component)tr).GetComponentsInChildren<Transform>(true);
			foreach (Transform val2 in componentsInChildren)
			{
				foreach (string item in sl)
				{
					if (((Object)val2).name == item)
					{
						Object.Destroy((Object)(object)((Component)val2).gameObject);
						sl.Remove(item);
						break;
					}
				}
				if (((Object)val2).name.Contains("Audio"))
				{
					Object.Destroy((Object)(object)((Component)val2).gameObject);
				}
				else if (((Object)val2).name == "MainBodyDestroyed")
				{
					tree[0] = Object.Instantiate<Transform>(val2);
					((Component)tree[0]).gameObject.SetActive(false);
					((Object)tree[0]).name = "ToyCar(Exploded)";
					Object.DontDestroyOnLoad((Object)(object)tree[0]);
					Object.Destroy((Object)(object)((Component)val2).gameObject);
				}
				else if (((Object)val2).name == "CarHoodFire" && ca.cfg5_playwithtoy.Value)
				{
					((Component)val2).GetComponent<ParticleSystem>().scalingMode = (ParticleSystemScalingMode)0;
					((Component)val2).GetComponentInChildren<Light>(true).intensity = 45f;
				}
				else if (((Object)val2).name == "Headlights" && !ca.cfg5_playwithtoy.Value)
				{
					Object.Destroy((Object)(object)((Component)val2).gameObject);
				}
			}
			if (true)
			{
			}
			AnimatedObjectTrigger[] componentsInChildren2 = ((Component)tr).GetComponentsInChildren<AnimatedObjectTrigger>();
			foreach (AnimatedObjectTrigger val3 in componentsInChildren2)
			{
				Object.Destroy((Object)(object)val3);
			}
			if (true)
			{
			}
			PlayAudioAnimationEvent[] componentsInChildren3 = ((Component)tr).GetComponentsInChildren<PlayAudioAnimationEvent>();
			foreach (PlayAudioAnimationEvent val4 in componentsInChildren3)
			{
				Object.Destroy((Object)(object)val4);
			}
			if (true)
			{
			}
			Transform eject = Object.Instantiate<Transform>(StartOfRound.Instance.VehiclesList[0].GetComponentsInChildren<Transform>().First((Transform _) => ((Object)_).name == "ButtonAnimContainer"));
			Object.Destroy((Object)(object)((Component)eject.GetChild(0)).GetComponent<BoxCollider>());
			Object.Destroy((Object)(object)((Component)eject.GetChild(0)).GetComponent<InteractTrigger>());
			Object.Destroy((Object)(object)((Component)eject.GetChild(1)).GetComponent<BoxCollider>());
			Object.Destroy((Object)(object)((Component)eject.GetChild(1)).GetComponent<InteractTrigger>());
			Object.Destroy((Object)(object)((Component)eject.GetChild(1)).GetComponent<AnimatedObjectTrigger>());
			eject.SetParent(tr);
			if (ca.cfg5_playwithtoy.Value)
			{
				Transform val5 = Object.Instantiate<Transform>(StartOfRound.Instance.VehiclesList[0].GetComponentsInChildren<Transform>().First((Transform _) => ((Object)_).name == "Particle System"));
				((Component)val5).GetComponent<ParticleSystem>().scalingMode = (ParticleSystemScalingMode)0;
				val5.SetParent(tr);
			}
			((Component)tr).GetComponentInChildren<LODGroup>().size = 60f;
			await wait_frames(1);
			tree[1] = tr;
			((Component)tree[1]).gameObject.SetActive(false);
			((Object)tree[1]).name = "ToyCar";
			Object.DontDestroyOnLoad((Object)(object)tree[1]);
			ca.mls.LogInfo((object)"saved cruiser scrap transforms");
			cruiser_additions.item[0] = "V-type engine";
			take[0] = __instance.itemProperties.grabSFX;
			give[0] = __instance.itemProperties.dropSFX;
			ref Vector3 reference = ref position[0];
			reference = __instance.itemProperties.positionOffset;
			ref Vector3 reference2 = ref rotation[0];
			reference2 = __instance.itemProperties.rotationOffset;
			Item temp = StartOfRound.Instance.allItemsList.itemsList.First((Item _) => ((Object)_).name == "ToyCube");
			cruiser_additions.item[1] = "Toy car";
			take[1] = temp.grabSFX;
			give[1] = temp.dropSFX;
			ref Vector3 reference3 = ref position[1];
			reference3 = new Vector3(-0.035f, 0.2f, 0.02f);
			ref Vector3 reference4 = ref position[2];
			reference4 = new Vector3(-0.02f, 0.31f, -0.008f);
			ref Vector3 reference5 = ref rotation[1];
			reference5 = new Vector3(0f, 16f, 76f);
			first_pending = false;
			ca.mls.LogInfo((object)"saved engine/cruiser scrap variables");
		}
		if (cruiser_additions.item[0] == null)
		{
			return;
		}
		Shion shion;
		if (!GameNetworkManager.Instance.disableSteam && lobbyid != 0 && (Object)(object)((Component)__instance).GetComponent<NetworkObject>() != (Object)null)
		{
			ulong seed;
			if (ca.cfg5_saveseeds.Value && seeds != "nil" && seeds != "?" && seeds.Contains(((Component)__instance).GetComponent<NetworkObject>().NetworkObjectId + "."))
			{
				if (first_item[2])
				{
					ca.mls.LogInfo((object)"custom_random = new Shion(saved seed)");
				}
				int num = seeds.IndexOf(((Component)__instance).GetComponent<NetworkObject>().NetworkObjectId + ".");
				int num2 = ((Component)__instance).GetComponent<NetworkObject>().NetworkObjectId.ToString().Length + 1;
				seed = ulong.Parse(seeds.Substring(num + num2, seeds.IndexOf("/", num) - (num + num2)));
			}
			else
			{
				if (first_item[2])
				{
					ca.mls.LogInfo((object)"custom_random = new Shion(lobbyid+networkobjectid)");
				}
				seed = lobbyid + ((Component)__instance).GetComponent<NetworkObject>().NetworkObjectId;
			}
			shion = new Shion(seed);
			if (ca.cfg5_saveseeds.Value)
			{
				((Component)__instance).gameObject.AddComponent<ItemTypeSeed>();
				((Component)__instance).gameObject.GetComponent<ItemTypeSeed>().seed = seed.ToString();
			}
		}
		else
		{
			if (first_item[2])
			{
				ca.mls.LogInfo((object)"custom_random = new Shion()");
			}
			shion = new Shion();
		}
		if (first_item[2])
		{
			ca.mls.LogInfo((object)((ca.cfg5_percentages.Value && synced_percents[0] != -1) ? "host config" : "local config"));
		}
		first_item[2] = false;
		int[] array = ((ca.cfg5_percentages.Value && synced_percents[0] != -1) ? synced_percents : new int[3]
		{
			-1,
			ca.cfg5_cruiser.Value,
			ca.cfg5_cruiseralt.Value
		});
		Transform val6 = null;
		int num3 = ((shion.next32mm(0, 100) < array[1]) ? 1 : 0);
		if (num3 == 1)
		{
			BoxCollider component = ((Component)__instance).GetComponent<BoxCollider>();
			if (shion.next32mm(0, 100) < array[2])
			{
				val6 = Object.Instantiate<Transform>(tree[0], ((Component)__instance).transform);
				val6.localPosition = new Vector3(21.5f, 0f, 0f);
				val6.localEulerAngles = new Vector3(0f, 90f, 180f);
				val6.localScale = new Vector3(-6f, -6f, -6f);
				((Component)val6).gameObject.SetActive(true);
				component.center = new Vector3(5f, 0f, 0f);
				component.size = new Vector3(27.5f, 23f, 60f);
				((Component)((Component)__instance).GetComponentInChildren<ScanNodeProperties>()).transform.localPosition = new Vector3(5f, 0f, 0f);
			}
			else
			{
				val6 = Object.Instantiate<Transform>(tree[1], ((Component)__instance).transform);
				val6.localPosition = new Vector3(3.5f, 0f, 0f);
				val6.localEulerAngles = new Vector3(0f, 180f, 90f);
				val6.localScale = new Vector3(-6f, -6f, -6f);
				((Component)val6).gameObject.SetActive(true);
				component.center = new Vector3(2.5f, 0f, 0f);
				component.size = new Vector3(33f, 23f, 60f);
				((Component)((Component)__instance).GetComponentInChildren<ScanNodeProperties>()).transform.localPosition = new Vector3(2.5f, 0f, 0f);
				((Component)((Component)__instance).GetComponentsInChildren<Transform>().First((Transform _) => ((Object)_).name == "SteeringWheelContainer")).GetComponent<Animator>().SetFloat("steeringWheelTurnSpeed", 0.875f);
			}
			((Component)__instance).GetComponent<MeshFilter>().mesh = null;
		}
		((Component)__instance).GetComponentInChildren<ScanNodeProperties>().headerText = cruiser_additions.item[num3];
		if (ca.cfg5_playwithtoy.Value && num3 == 1 && ((Component)__instance).transform.childCount >= 2)
		{
			__instance.useCooldown = 0.1f;
			__instance.itemProperties.holdButtonUse = false;
			__instance.itemProperties.requiresBattery = false;
			__instance.itemProperties.syncUseFunction = false;
			PlayWithToy playWithToy = ((Component)__instance).gameObject.AddComponent<PlayWithToy>();
			playWithToy.toycar = val6;
			playWithToy.vehicle = StartOfRound.Instance.VehiclesList[0].GetComponent<VehicleController>();
			playWithToy.redkuro = ((!(((Object)val6).name == "ToyCar(Clone)") && !(((Object)val6).name == "ToyCar(Exploded)(Clone)")) ? null : ((((Object)val6).name == "ToyCar(Clone)") ? red_toy : kuro_toy));
			Transform transform = new GameObject("ToyCarAudio").transform;
			transform.parent = val6;
			transform.localPosition = ((((Object)val6).name == "ToyCar(Clone)") ? new Vector3(0f, 1f, 1f) : new Vector3(-1f, 0f, 3f));
			transform.localEulerAngles = new Vector3(0f, 0f, 0f);
			transform.localScale = new Vector3(1f, 1f, 1f);
			AudioSource val7 = ((Component)transform).gameObject.AddComponent<AudioSource>();
			AudioSource val8 = ((Component)transform).gameObject.AddComponent<AudioSource>();
			AudioSource val9 = ((Component)transform).gameObject.AddComponent<AudioSource>();
			playWithToy.audio = val7;
			playWithToy.mixed = val8;
			playWithToy.third = val9;
			float num5 = (val7.dopplerLevel = 0.3f);
			num5 = (val8.dopplerLevel = num5);
			val9.dopplerLevel = num5;
			num5 = (val7.maxDistance = 17f);
			num5 = (val8.maxDistance = num5);
			val9.maxDistance = num5;
			num5 = (val7.minDistance = 1f);
			num5 = (val8.minDistance = num5);
			val9.minDistance = num5;
			bool flag2 = (val7.playOnAwake = false);
			flag2 = (val8.playOnAwake = flag2);
			val9.playOnAwake = flag2;
			AudioRolloffMode val10 = (AudioRolloffMode)1;
			val7.rolloffMode = (AudioRolloffMode)1;
			val10 = (val8.rolloffMode = val10);
			val9.rolloffMode = val10;
			num5 = (val7.spatialBlend = 1f);
			num5 = (val8.spatialBlend = num5);
			val9.spatialBlend = num5;
			num5 = (val7.spread = 45f);
			num5 = (val8.spread = num5);
			val9.spread = num5;
			flag2 = (val7.loop = true);
			flag2 = (val8.loop = flag2);
			val9.loop = flag2;
			num5 = (val7.volume = 0.5f);
			val9.volume = num5;
			val8.volume = 0f;
		}
	}

	private static async Task wait_frames(int frames)
	{
		int previous_frames = Time.frameCount;
		while (Time.frameCount <= previous_frames + frames)
		{
			await Task.Delay(4);
		}
	}

	private static async Task wait_timer(int maxwell)
	{
		int i = 0;
		while (seeds == "nil" && !client_received && i < maxwell && !disconnected[0])
		{
			i++;
			await Task.Delay(4);
		}
		if (disconnected[0])
		{
			if (!disconnected[1])
			{
				ca.mls.LogMessage((object)"disconnected before wait_timer ended");
				disconnected[1] = true;
			}
		}
		else if (first_item[1])
		{
			ca.mls.LogMessage((object)((seeds == "nil" && !client_received) ? ("timer ended before receiving network message (" + i + "/" + ca.cfg5_millisecond.Value + ")") : ("received network message before timer ended (" + i + "/" + ca.cfg5_millisecond.Value + ")")));
			first_item[1] = false;
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(GrabbableObject), "PlayDropSFX")]
	private static void pre4(ref GrabbableObject __instance)
	{
		if (item[0] != null && (Object)(object)__instance != (Object)null && ((Object)__instance.itemProperties).name == "EnginePart1" && (Object)(object)((Component)__instance).GetComponentInChildren<ScanNodeProperties>() != (Object)null)
		{
			__instance.itemProperties.dropSFX = ((((Component)__instance).GetComponentInChildren<ScanNodeProperties>().headerText == item[1]) ? give[1] : give[0]);
		}
	}

	[HarmonyPatch(typeof(PlayerControllerB), "BeginGrabObject")]
	[HarmonyTranspiler]
	private static IEnumerable<CodeInstruction> trn3(IEnumerable<CodeInstruction> Instrs)
	{
		List<CodeInstruction> i = new List<CodeInstruction>(Instrs);
		for (int j = 0; j < i.Count; j++)
		{
			yield return i[j];
			if (j > 0 && ((object)i[j - 1]).ToString() == "call static float UnityEngine.Mathf::Clamp(float value, float min, float max)" && ((object)i[j]).ToString() == "stfld float GameNetcodeStuff.PlayerControllerB::carryWeight")
			{
				yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
				yield return new CodeInstruction(OpCodes.Ldfld, (object)typeof(PlayerControllerB).GetField("currentlyGrabbingObject", BindingFlags.Instance | BindingFlags.NonPublic));
				yield return new CodeInstruction(OpCodes.Call, (object)typeof(cruiser_additions).GetMethod("grab_item"));
			}
		}
	}

	public static void grab_item(GrabbableObject currentlyGrabbingObject)
	{
		//IL_00bd: 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_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)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		if (item[0] != null && (Object)(object)currentlyGrabbingObject != (Object)null && ((Object)currentlyGrabbingObject.itemProperties).name == "EnginePart1" && (Object)(object)((Component)currentlyGrabbingObject).GetComponentInChildren<ScanNodeProperties>() != (Object)null)
		{
			int num = ((((Component)currentlyGrabbingObject).GetComponentInChildren<ScanNodeProperties>().headerText == item[1]) ? 1 : 0);
			currentlyGrabbingObject.itemProperties.grabSFX = take[num];
			if (GameNetworkManager.Instance.isHostingGame)
			{
				currentlyGrabbingObject.itemProperties.positionOffset = ((((Component)currentlyGrabbingObject).GetComponentsInChildren<Transform>().Length > 2 && ((Object)((Component)currentlyGrabbingObject).GetComponentsInChildren<Transform>()[2]).name.Contains("Exploded")) ? position[2] : position[num]);
				currentlyGrabbingObject.itemProperties.rotationOffset = rotation[num];
			}
			currentlyGrabbingObject.itemProperties.itemName = item[num];
			if (ca.cfg5_playwithtoy.Value)
			{
				currentlyGrabbingObject.itemProperties.toolTips = ((num == 1) ? new string[1] { "Play with toy : [RMB]" } : new string[0]);
			}
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(GrabbableObject), "GrabItemOnClient")]
	private static void pre5(GrabbableObject __instance)
	{
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		if (item[0] != null && (Object)(object)__instance != (Object)null && ((Object)__instance.itemProperties).name == "EnginePart1" && (Object)(object)((Component)__instance).GetComponentInChildren<ScanNodeProperties>() != (Object)null)
		{
			int num = ((((Component)__instance).GetComponentInChildren<ScanNodeProperties>().headerText == item[1]) ? 1 : 0);
			__instance.itemProperties.positionOffset = ((((Component)__instance).GetComponentsInChildren<Transform>().Length > 2 && ((Object)((Component)__instance).GetComponentsInChildren<Transform>()[2]).name.Contains("Exploded")) ? position[2] : position[num]);
			__instance.itemProperties.rotationOffset = rotation[num];
		}
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(PlayerControllerB), "SwitchToItemSlot")]
	private static IEnumerable<CodeInstruction> trn4(IEnumerable<CodeInstruction> Instrs)
	{
		List<CodeInstruction> i = new List<CodeInstruction>(Instrs);
		for (int j = 0; j < i.Count; j++)
		{
			yield return i[j];
			if (j < i.Count - 4 && ((object)i[j + 4]).ToString() == "callvirt virtual void GrabbableObject::EquipItem()")
			{
				yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
				yield return new CodeInstruction(OpCodes.Call, (object)typeof(cruiser_additions).GetMethod("hold_item"));
			}
		}
	}

	public static void hold_item(PlayerControllerB player)
	{
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		GrabbableObject val = player.ItemSlots[player.currentItemSlot];
		if (item[0] == null || !((Object)(object)val != (Object)null) || !(((Object)val.itemProperties).name == "EnginePart1") || !((Object)(object)((Component)val).GetComponentInChildren<ScanNodeProperties>() != (Object)null))
		{
			return;
		}
		int num = ((((Component)val).GetComponentInChildren<ScanNodeProperties>().headerText == item[1]) ? 1 : 0);
		val.itemProperties.grabSFX = take[num];
		PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
		if ((Object)(object)player == (Object)(object)localPlayerController || (Object)(object)localPlayerController.ItemSlots[localPlayerController.currentItemSlot] == (Object)null || ((Object)localPlayerController.ItemSlots[localPlayerController.currentItemSlot].itemProperties).name != "EnginePart1" || localPlayerController.isPlayerDead)
		{
			val.itemProperties.itemName = item[num];
			if (ca.cfg5_playwithtoy.Value)
			{
				val.itemProperties.toolTips = ((num == 1) ? new string[1] { "Play with toy : [RMB]" } : new string[0]);
			}
			if (val.isHeld || (Object)(object)player != (Object)(object)localPlayerController)
			{
				val.itemProperties.positionOffset = ((((Component)val).GetComponentsInChildren<Transform>().Length > 2 && ((Object)((Component)val).GetComponentsInChildren<Transform>()[2]).name.Contains("Exploded")) ? position[2] : position[num]);
				val.itemProperties.rotationOffset = rotation[num];
			}
		}
	}

	[HarmonyPatch(typeof(HUDManager), "DisplayNewScrapFound")]
	[HarmonyTranspiler]
	private static IEnumerable<CodeInstruction> trn5(IEnumerable<CodeInstruction> Instrs)
	{
		List<CodeInstruction> i = new List<CodeInstruction>(Instrs);
		for (int j = 0; j < i.Count; j++)
		{
			if (j < i.Count - 1 && ((object)i[j + 1]).ToString() == "callvirt UnityEngine.Renderer[] UnityEngine.GameObject::GetComponentsInChildren()")
			{
				yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
				yield return new CodeInstruction(OpCodes.Ldloc_0, (object)null);
				yield return new CodeInstruction(OpCodes.Call, (object)typeof(cruiser_additions).GetMethod("display_cruiser"));
			}
			yield return i[j];
		}
	}

	public static void display_cruiser(HUDManager instance, GameObject displayingObject)
	{
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: 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_01f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0228: Unknown result type (might be due to invalid IL or missing references)
		if (item[0] == null || !((Object)(object)instance.itemsToBeDisplayed[0] != (Object)null) || !(((Object)instance.itemsToBeDisplayed[0].itemProperties).name == "EnginePart1") || !(((Object)displayingObject).name == "EnginePart(Clone)") || !((Object)(object)((Component)instance.itemsToBeDisplayed[0]).GetComponentInChildren<ScanNodeProperties>() != (Object)null))
		{
			return;
		}
		int num = ((((Component)instance.itemsToBeDisplayed[0]).GetComponentInChildren<ScanNodeProperties>().headerText == item[1]) ? 1 : 0);
		instance.itemsToBeDisplayed[0].itemProperties.itemName = item[num];
		if (num != 1)
		{
			return;
		}
		displayingObject.GetComponent<MeshFilter>().mesh = null;
		if (((Component)instance.itemsToBeDisplayed[0]).transform.childCount >= 2)
		{
			if (((Object)((Component)instance.itemsToBeDisplayed[0]).transform.GetChild(1)).name == "ToyCar(Clone)")
			{
				Transform val = Object.Instantiate<Transform>(tree[1], displayingObject.transform);
				val.localPosition = new Vector3(3.5f, 0f, 0f);
				val.localEulerAngles = new Vector3(0f, 180f, 90f);
				val.localScale = new Vector3(-6f, -6f, -6f);
				((Component)val).gameObject.SetActive(true);
			}
			else if (((Object)((Component)instance.itemsToBeDisplayed[0]).transform.GetChild(1)).name == "ToyCar(Exploded)(Clone)")
			{
				Transform val = Object.Instantiate<Transform>(tree[0], displayingObject.transform);
				val.localPosition = new Vector3(21.5f, 0f, 0f);
				val.localEulerAngles = new Vector3(0f, 90f, 180f);
				val.localScale = new Vector3(-6f, -6f, -6f);
				((Component)val).gameObject.SetActive(true);
			}
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(StartOfRound), "Awake")]
	private static void pst6()
	{
		//IL_0065: 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_006e: Unknown result type (might be due to invalid IL or missing references)
		if (!GameNetworkManager.Instance.disableSteam)
		{
			bool[] array = new bool[2];
			disconnected = array;
			synced_percents = new int[3] { -1, -1, -1 };
			if (GameNetworkManager.Instance.currentLobby.HasValue)
			{
				Lobby value = GameNetworkManager.Instance.currentLobby.Value;
				lobbyid = SteamId.op_Implicit(((Lobby)(ref value)).Id) % 1000000000;
				ca.mls.LogInfo((object)lobbyid);
			}
			else
			{
				ca.mls.LogError((object)"current lobby id is null");
			}
		}
		if (discoball == 1 && ca.cfg5_scrap.Value && ca.cfg5_playwithtoy.Value)
		{
			discoball = 2;
			Transform transform = StartOfRound.Instance.unlockablesList.unlockables.First((UnlockableItem _) => _.unlockableName == "Disco Ball").prefabObject.transform;
			Transform[] componentsInChildren = ((Component)transform).GetComponentsInChildren<Transform>(true);
			Transform val = componentsInChildren.First((Transform _) => ((Object)_).name == "AnimContainer");
			Transform val2 = componentsInChildren.First((Transform _) => ((Object)_).name == "Audio");
			val2.SetParent(transform);
			Object.DestroyImmediate((Object)(object)((Component)val).GetComponent<CozyLights>());
			CozyLights val3 = ((Component)transform).gameObject.AddComponent<CozyLights>();
			val3.cozyLightsAnimator = ((Component)val).GetComponent<Animator>();
			val3.turnOnAudio = ((Component)val2).GetComponent<AudioSource>();
			discoball = 3;
		}
	}

	[HarmonyPatch(typeof(GrabbableObject), "ItemActivate")]
	[HarmonyPostfix]
	private static void play_with_toy_event(GrabbableObject __instance)
	{
		//IL_021a: Unknown result type (might be due to invalid IL or missing references)
		if (!(((Object)__instance.itemProperties).name == "EnginePart1") || !((Object)(object)((Component)__instance).GetComponentInChildren<ScanNodeProperties>() != (Object)null) || !(((Component)__instance).GetComponentInChildren<ScanNodeProperties>().headerText == item[1]) || !ca.cfg5_scrap.Value || !ca.cfg5_playwithtoy.Value || !((Object)(object)__instance.playerHeldBy == (Object)(object)GameNetworkManager.Instance.localPlayerController))
		{
			return;
		}
		PlayWithToy component = ((Component)__instance).GetComponent<PlayWithToy>();
		if ((Object)(object)component == (Object)null || (Object)(object)component.toycar == (Object)null || (Object)(object)((Component)__instance).GetComponent<NetworkObject>() == (Object)null)
		{
			ca.mls.LogError((object)("play_with_toy_event error" + (((Object)(object)component == (Object)null) ? ", PlayWithToy component was null" : "") + ((!((Object)(object)component != (Object)null)) ? "" : (((Object)(object)component.toycar == (Object)null) ? "ToyCar gameobject was null" : "")) + (((Object)(object)((Component)__instance).GetComponent<NetworkObject>() == (Object)null) ? ", NetworkObject component was null" : "")));
		}
		else
		{
			if (!(component.cooldown <= 0f))
			{
				return;
			}
			ulong networkObjectId = ((Component)__instance).GetComponent<NetworkObject>().NetworkObjectId;
			if (StartOfRound.Instance.connectedPlayersAmount + 1 != 1 && sync)
			{
				if (GameNetworkManager.Instance.isHostingGame)
				{
					update_clients_toy(networkObjectId, __instance);
					return;
				}
				if (client_received)
				{
					if (hosttoycarcfg == "true" && !NetworkManager.Singleton.IsHost)
					{
						((Component)__instance).GetComponent<PlayWithToy>().cooldown = 0.8f;
						string text = "ToyCarRequest^" + networkObjectId;
						FastBufferWriter val = default(FastBufferWriter);
						((FastBufferWriter)(ref val))..ctor(FastBufferWriter.GetWriteSize(text, false), (Allocator)2, -1);
						((FastBufferWriter)(ref val)).WriteValueSafe(text, false);
						NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("4902.Cruiser_Additions-Host", 0uL, val, (NetworkDelivery)4);
						((FastBufferWriter)(ref val)).Dispose();
						return;
					}
				}
				else if (component.time_since_spawned < 8f)
				{
					return;
				}
			}
			play_with_toy(networkObjectId, __instance, determine: true);
		}
	}

	private static string play_with_toy(ulong guid, GrabbableObject _item = null, bool determine = false, string effect = "nil")
	{
		if (ca.cfg5_scrap.Value && ca.cfg5_playwithtoy.Value)
		{
			if ((Object)(object)_item == (Object)null)
			{
				PlayWithToy playWithToy = Object.FindObjectsOfType<PlayWithToy>(true).FirstOrDefault((PlayWithToy _) => (Object)(object)((Component)_).GetComponent<NetworkObject>() != (Object)null && ((Component)_).GetComponent<NetworkObject>().NetworkObjectId == guid);
				if ((Object)(object)playWithToy != (Object)null)
				{
					_item = ((Component)playWithToy).gameObject.GetComponent<GrabbableObject>();
				}
			}
			if ((Object)(object)_item != (Object)null && ((Object)_item.itemProperties).name == "EnginePart1" && (Object)(object)((Component)_item).GetComponentInChildren<ScanNodeProperties>() != (Object)null && ((Component)_item).GetComponentInChildren<ScanNodeProperties>().headerText == item[1])
			{
				PlayWithToy component = ((Component)_item).GetComponent<PlayWithToy>();
				if ((Object)(object)component != (Object)null && (Object)(object)component.toycar != (Object)null)
				{
					if (determine && effect == "nil")
					{
						if (component.cooldown > 0f)
						{
							return "nil";
						}
						effect = component.determine_next_event();
					}
					else if ((effect.StartsWith("r.") && ((Object)component.toycar).name != "ToyCar(Clone)") || (effect.StartsWith("k.") && ((Object)component.toycar).name != "ToyCar(Exploded)(Clone)"))
					{
						ca.mls.LogError((object)string.Concat("play_with_toy error, effect identifier doesn't match toy car type. ", effect, " ", component.toycar, (((Component)_item).transform.childCount >= 2) ? (" " + ((Object)((Component)_item).transform.GetChild(1)).name) : ""));
						return "nil";
					}
					try
					{
						component.play_effect(effect);
					}
					catch (Exception ex)
					{
						ca.mls.LogError((object)("! play_effect error, caught error while playing effect " + effect + ". " + ((Object)component.toycar).name + ", " + determine + ", " + component.previous_event + " !\n" + ex));
					}
					return effect;
				}
				if ((Object)(object)component == (Object)null)
				{
					ca.mls.LogError((object)"play_with_toy error, PlayWithToy component was null");
				}
				else if ((Object)(object)component.toycar == (Object)null)
				{
					ca.mls.LogError((object)"play_with_toy error, ToyCar gameobject was null");
				}
			}
			if ((Object)(object)_item == (Object)null)
			{
				ca.mls.LogError((object)("play_with_toy error, item was null or item wasn't a toy car. " + client_received.ToString().ToLower() + ", " + hosttoycarcfg + ", " + (StartOfRound.Instance.connectedPlayersAmount + 1) + ", " + NetworkManager.Singleton.IsHost.ToString().ToLower()));
			}
		}
		return "nil";
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(StartOfRound), "SyncShipUnlockablesClientRpc")]
	private static void pst7(StartOfRound __instance)
	{
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: 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_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		if (ca.cfg7_unlockables.Value && (Object)(object)__instance.attachedVehicle != (Object)null && !GameNetworkManager.Instance.isHostingGame)
		{
			typeof(VehicleController).GetField("magnetTargetRotation", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(__instance.attachedVehicle, (object)new Quaternion(0f, 0.7071068f, 0f, 0.7071068f));
			typeof(VehicleController).GetField("magnetStartRotation", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(__instance.attachedVehicle, (object)new Quaternion(0f, 0.7071068f, 0f, 0.7071068f));
			typeof(VehicleController).GetField("magnetTargetPosition", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(__instance.attachedVehicle, __instance.magnetPoint.position - __instance.magnetPoint.forward * 5.5f);
			typeof(VehicleController).GetField("magnetStartPosition", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(__instance.attachedVehicle, __instance.magnetPoint.position + __instance.magnetPoint.forward * 5f);
			ca.mls.LogInfo((object)"attached cruiser to the magnet");
		}
	}

	[HarmonyPatch(typeof(VehicleController), "CollectItemsInTruck")]
	[HarmonyTranspiler]
	private static IEnumerable<CodeInstruction> trn6(IEnumerable<CodeInstruction> Instrs)
	{
		List<CodeInstruction> i = new List<CodeInstruction>(Instrs);
		for (int j = 0; j < i.Count; j++)
		{
			if (ca.cfg8_collide.Value && j < i.Count - 1 && ((object)i[j + 1]).ToString() == "call static UnityEngine.Collider[] UnityEngine.Physics::OverlapSphere(UnityEngine.Vector3 position, float radius, int layerMask, UnityEngine.QueryTriggerInteraction queryTriggerInteraction)")
			{
				yield return new CodeInstruction(OpCodes.Ldc_I4_2, (object)null);
			}
			else
			{
				yield return i[j];
			}
		}
	}

	[HarmonyPatch(typeof(Terminal), "LoadNewNodeIfAffordable")]
	[HarmonyTranspiler]
	private static IEnumerable<CodeInstruction> trn7(IEnumerable<CodeInstruction> Instrs)
	{
		List<CodeInstruction> i = new List<CodeInstruction>(Instrs);
		for (int j = 0; j < i.Count; j++)
		{
			if (ca.cfg9_1up.Value && ((object)i[j]).ToString() == "call static VehicleController UnityEngine.Object::FindObjectOfType()")
			{
				yield return new CodeInstruction(OpCodes.Call, (object)typeof(cruiser_additions).GetMethod("return_exploded"));
				j++;
			}
			else
			{
				yield return i[j];
			}
		}
	}

	public static bool return_exploded()
	{
		return Object.op_Implicit((Object)(object)((IEnumerable<VehicleController>)Object.FindObjectsOfType<VehicleController>()).FirstOrDefault((Func<VehicleController, bool>)((VehicleController _) => (Object)(object)_ != (Object)null && !_.carDestroyed)));
	}

	[HarmonyPatch(typeof(VehicleController), "DoTurboBoost")]
	[HarmonyPrefix]
	private static bool pre6()
	{
		return (!ca.cfgr_input.Value || !GameNetworkManager.Instance.localPlayerController.isTypingChat) ? true : false;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(VehicleController), "GetVehicleInput")]
	private static bool pre7()
	{
		return (!ca.cfgr_input.Value || !GameNetworkManager.Instance.localPlayerController.isTypingChat) ? true : false;
	}

	[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
	[HarmonyPostfix]
	private static void pst8()
	{
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Expected O, but got Unknown
		//IL_0092: 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_0040: Expected O, but got Unknown
		if (!sync)
		{
			if (NetworkManager.Singleton.IsHost)
			{
				NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("4902.Cruiser_Additions-Host", new HandleNamedMessageDelegate(host_receive));
			}
			else
			{
				ca.mls.LogInfo((object)"requesting message from host");
				NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("4902.Cruiser_Additions-Client", new HandleNamedMessageDelegate(client_receive));
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(0, (Allocator)2, -1);
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("4902.Cruiser_Additions-Host", 0uL, val, (NetworkDelivery)3);
				((FastBufferWriter)(ref val)).Dispose();
			}
			sync = true;
		}
	}

	private static void host_receive(ulong id, FastBufferReader r)
	{
		//IL_025a: Unknown result type (might be due to invalid IL or missing references)
		if (!NetworkManager.Singleton.IsHost)
		{
			return;
		}
		if (((FastBufferReader)(ref r)).TryBeginRead(1))
		{
			string text = default(string);
			((FastBufferReader)(ref r)).ReadValueSafe(ref text, false);
			if (text.StartsWith("LightSwitchRequest"))
			{
				int num = 2;
				if (count_carets(text, num))
				{
					string[] array = text.Split(new char[1] { '^' }, num + 1);
					update_clients_lights(ulong.Parse(array[1]), bool.Parse(array[2]));
				}
				return;
			}
			if (text.StartsWith("ToyCarRequest") && ca.cfg5_scrap.Value && ca.cfg5_playwithtoy.Value)
			{
				int num = 1;
				if (count_carets(text, num))
				{
					string[] array2 = text.Split(new char[1] { '^' }, num + 1);
					update_clients_toy(ulong.Parse(array2[1]));
				}
				return;
			}
		}
		ca.mls.LogInfo((object)"received request from client");
		string text2 = ((ca.cfg2_moveitems.Value == 2 || ca.cfg2_moveitems.Value == 3) ? "true" : "false") + "^" + ca.cfg2_scraponly.Value.ToString().ToLower() + "^" + (ca.cfg5_scrap.Value && ca.cfg5_playwithtoy.Value).ToString().ToLower() + "^1," + ca.cfg5_cruiser.Value + "," + ca.cfg5_cruiseralt.Value + "^" + lobbyid + "^" + seeds;
		ca.mls.LogInfo((object)("sending message " + text2));
		FastBufferWriter val = default(FastBufferWriter);
		((FastBufferWriter)(ref val))..ctor(FastBufferWriter.GetWriteSize(text2, false), (Allocator)2, -1);
		((FastBufferWriter)(ref val)).WriteValueSafe(text2, false);
		NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("4902.Cruiser_Additions-Client", id, val, (NetworkDelivery)4);
		((FastBufferWriter)(ref val)).Dispose();
	}

	private static void client_receive(ulong id, FastBufferReader r)
	{
		if (NetworkManager.Singleton.IsHost)
		{
			return;
		}
		string text = default(string);
		((FastBufferReader)(ref r)).ReadValueSafe(ref text, false);
		int num = 5;
		if (text.StartsWith("LightSwitchReceive"))
		{
			num = 2;
			if (count_carets(text, num))
			{
				string[] array = text.Split(new char[1] { '^' }, num + 1);
				switch_light(ulong.Parse(array[1]), bool.Parse(array[2]));
			}
			return;
		}
		if (text.StartsWith("ToyCarReceive"))
		{
			num = 2;
			if (count_carets(text, num))
			{
				string[] array2 = text.Split(new char[1] { '^' }, num + 1);
				play_with_toy(ulong.Parse(array2[1]), null, determine: false, array2[2]);
			}
			return;
		}
		client_received = true;
		ca.mls.LogInfo((object)("client received message " + text));
		if (count_carets(text, num))
		{
			string[] array3 = text.Split(new char[1] { '^' }, num + 1);
			hostmoveitems = array3[0];
			hostscraponly = array3[1];
			hosttoycarcfg = array3[2];
			synced_percents = Array.ConvertAll(array3[3].split(","), Convert.ToInt32);
			lobbyid = ulong.Parse(array3[4]);
			seeds = array3[5];
		}
	}

	private static void update_clients_lights(ulong guid, bool red)
	{
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		if (NetworkManager.Singleton.IsHost)
		{
			switch_light(guid, red);
			string text = "LightSwitchReceive^" + guid + "^" + red;
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(FastBufferWriter.GetWriteSize(text, false), (Allocator)2, -1);
			((FastBufferWriter)(ref val)).WriteValueSafe(text, false);
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("4902.Cruiser_Additions-Client", val, (NetworkDelivery)4);
			((FastBufferWriter)(ref val)).Dispose();
		}
	}

	private static void update_clients_toy(ulong guid, GrabbableObject _item = null)
	{
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		if (NetworkManager.Singleton.IsHost)
		{
			string text = play_with_toy(guid, _item, determine: true);
			if (text != "nil")
			{
				string text2 = "ToyCarReceive^" + guid + "^" + text;
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(FastBufferWriter.GetWriteSize(text2, false), (Allocator)2, -1);
				((FastBufferWriter)(ref val)).WriteValueSafe(text2, false);
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("4902.Cruiser_Additions-Client", val, (NetworkDelivery)4);
				((FastBufferWriter)(ref val)).Dispose();
			}
		}
	}

	private static bool count_carets(string message = "counting carets", int n = 1)
	{
		if (message.Length - message.Replace("^", "").Length == n)
		{
			return true;
		}
		ca.mls.LogError((object)"received message was not what was expected. wasn't able to sync variables with host. (are the mod versions not the same?)");
		ca.mls.LogError((object)("found " + (message.Length - message.Replace("^", "").Length) + "/" + n + " ^ in message " + message));
		return false;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(GameNetworkManager), "Disconnect")]
	private static void pre8()
	{
		disconnected[0] = true;
		if ((Object)(object)StartOfRound.Instance != (Object)null && (Object)(object)NetworkManager.Singleton != (Object)null && NetworkManager.Singleton.CustomMessagingManager != null)
		{
			try
			{
				NetworkManager.Singleton.CustomMessagingManager.UnregisterNamedMessageHandler("4902.Cruiser_Additions-Host");
				NetworkManager.Singleton.CustomMessagingManager.UnregisterNamedMessageHandler("4902.Cruiser_Additions-Client");
			}
			catch (Exception ex)
			{
				ca.mls.LogError((object)ex);
			}
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(GameNetworkManager), "Disconnect")]
	private static void pst9()
	{
		sync = false;
		hostmoveitems = "nil";
		hostscraponly = "nil";
		hosttoycarcfg = "nil";
		seeds = "nil";
		lobbyid = 0uL;
		first_item = new bool[3] { true, true, true };
		saved_engine = "";
		loaded_engine = new List<string>();
		synced_percents = new int[3] { -1, -1, -1 };
		client_received = false;
	}

	[HarmonyPatch(typeof(GameNetworkManager), "SaveItemsInShip")]
	[HarmonyTranspiler]
	private static IEnumerable<CodeInstruction> trn8(IEnumerable<CodeInstruction> Instrs)
	{
		List<CodeInstruction> i = new List<CodeInstruction>(Instrs);
		for (int j = 0; j < i.Count; j++)
		{
			yield return i[j];
			if (((object)i[j]).ToString() == "callvirt virtual void System.Collections.Generic.List<UnityEngine.Vector3>::Add(UnityEngine.Vector3 item)")
			{
				yield return new CodeInstruction(OpCodes.Ldloc_0, (object)null);
				yield return new CodeInstruction(OpCodes.Ldloc, (object)6);
				yield return new CodeInstruction(OpCodes.Call, (object)typeof(cruiser_additions).GetMethod("save_engine"));
			}
		}
	}

	public static void save_engine(GrabbableObject[] items, int index)
	{
		if (ca.cfg5_scrap.Value && ca.cfg5_saveseeds.Value && GameNetworkManager.Instance.isHostingGame && !GameNetworkManager.Instance.disableSteam && lobbyid != 0 && ((Object)items[index].itemProperties).name == "EnginePart1")
		{
			if ((Object)(object)((Component)items[index]).GetComponent<ItemTypeSeed>() != (Object)null)
			{
				ItemTypeSeed component = ((Component)items[index]).GetComponent<ItemTypeSeed>();
				saved_engine = saved_engine + component.seed + "/";
			}
			else if ((Object)(object)((Component)items[index]).GetComponent<NetworkObject>() != (Object)null)
			{
				saved_engine = saved_engine + (lobbyid + ((Component)items[index]).GetComponent<NetworkObject>().NetworkObjectId) + "/";
				ca.mls.LogInfo((object)"ItemTypeSeed is null! saving seed for this item as lobbyid+networkobjectid");
			}
			else
			{
				saved_engine = saved_engine + new Shion().next32mm(1, 101) + "/";
				ca.mls.LogInfo((object)"ItemTypeSeed and NetworkObject are null! saving seed for this item as a random number from 1 to 100");
			}
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(GameNetworkManager), "SaveGame")]
	private static void pst10()
	{
		if (!ca.cfg5_scrap.Value || !ca.cfg5_saveseeds.Value || !GameNetworkManager.Instance.isHostingGame || GameNetworkManager.Instance.disableSteam || !StartOfRound.Instance.inShipPhase || StartOfRound.Instance.isChallengeFile)
		{
			return;
		}
		try
		{
			if (saved_engine == "")
			{
				saved_engine = "nil";
			}
			if (saved_engine.EndsWith("/"))
			{
				saved_engine = saved_engine.Substring(0, saved_engine.Length - 1);
			}
			ca.mls.LogInfo((object)("saving " + saved_engine));
			ES3.Save<string>("4902.Cruiser_Additions-1", saved_engine, GameNetworkManager.Instance.currentSaveFileName);
			saved_engine = "";
		}
		catch (Exception ex)
		{
			ca.mls.LogError((object)("Error saving item types: " + ex));
		}
	}

	[HarmonyPatch(typeof(StartOfRound), "LoadShipGrabbableItems")]
	[HarmonyTranspiler]
	private static IEnumerable<CodeInstruction> trn9(IEnumerable<CodeInstruction> Instrs)
	{
		List<CodeInstruction> i = new List<CodeInstruction>(Instrs);
		for (int j = 0; j < i.Count; j++)
		{
			yield return i[j];
			if (((object)i[j]).ToString() == "callvirt void Unity.Netcode.NetworkObject::Spawn(bool destroyWithScene)")
			{
				yield return new CodeInstruction(OpCodes.Ldloc_0, (object)null);
				yield return new CodeInstruction(OpCodes.Call, (object)typeof(cruiser_additions).GetMethod("load_engine"));
			}
		}
	}

	public static void load_engine(GrabbableObject item)
	{
		if (ca.cfg5_scrap.Value && ca.cfg5_saveseeds.Value && GameNetworkManager.Instance.isHostingGame && !GameNetworkManager.Instance.disableSteam && lobbyid != 0 && ((Object)item.itemProperties).name == "EnginePart1")
		{
			if ((Object)(object)((Component)item).GetComponent<NetworkObject>() != (Object)null)
			{
				loaded_engine.Add(((Component)item).GetComponent<NetworkObject>().NetworkObjectId.ToString());
				return;
			}
			loaded_engine.Add("nil");
			ca.mls.LogInfo((object)"NetworkObject is null! the seed can't be loaded for this item");
		}
	}

	[HarmonyPatch(typeof(StartOfRound), "Start")]
	[HarmonyPostfix]
	private static void pst11()
	{
		if (!ca.cfg5_scrap.Value || !ca.cfg5_saveseeds.Value || !GameNetworkManager.Instance.isHostingGame || GameNetworkManager.Instance.disableSteam)
		{
			return;
		}
		try
		{
			string text = ES3.Load<string>("4902.Cruiser_Additions-1", GameNetworkManager.Instance.currentSaveFileName, "nil");
			ca.mls.LogInfo((object)("loaded " + text));
			string[] array = text.split("/");
			if (array[0] != "nil" && array[0] != "" && array.Length == loaded_engine.Count)
			{
				seeds = "";
				for (int i = 0; i < loaded_engine.Count; i++)
				{
					seeds = seeds + loaded_engine[i] + "." + array[i] + "/";
				}
				ca.mls.LogInfo((object)("current networkobjectids + saved seeds " + seeds));
			}
			loaded_engine = new List<string>();
		}
		catch (Exception ex)
		{
			ca.mls.LogError((object)("Error loading item types: " + ex));
		}
	}

	static cruiser_additions()
	{
		bool[] array = new bool[2];
		disconnected = array;
		synced_percents = new int[3] { -1, -1, -1 };
		client_received = false;
		saved_engine = "";
		loaded_engine = new List<string>();
	}
}
public class cruiser_light_switch_component : MonoBehaviour
{
	public string guid = ca.harmony.Id;

	public void Awake()
	{
		if (((Object)this).name == "cruiser_light_switch(Clone)")
		{
			((UnityEvent<PlayerControllerB>)(object)((Component)this).GetComponentInChildren<InteractTrigger>().onInteract).AddListener((UnityAction<PlayerControllerB>)placeholderfunction);
		}
	}

	public void placeholderfunction(PlayerControllerB player)
	{
		cruiser_additions.switch_light_event(player);
	}
}
public class cruiser_magnet_lever_component : MonoBehaviour
{
	public string guid = ca.harmony.Id;

	public void Awake()
	{
		if (((Object)this).name == "cruiser_magnet_lever(Clone)")
		{
			((UnityEvent<PlayerControllerB>)(object)((Component)this).GetComponentInChildren<InteractTrigger>().onInteract).AddListener((UnityAction<PlayerControllerB>)placeholderfunction);
		}
	}

	public void placeholderfunction(PlayerControllerB player)
	{
		((UnityEvent<PlayerControllerB>)(object)((Component)StartOfRound.Instance.magnetLever).GetComponent<InteractTrigger>().onInteract).Invoke(player);
	}
}
public class PlayWithToy : MonoBehaviour
{
	public string guid = ca.harmony.Id;

	public Transform toycar = null;

	public VehicleController vehicle = null;

	public string[] redkuro = null;

	public string next_effect = "nil";

	public string previous_event = "nil";

	public string previous_effect = "nil";

	public int chain_percent = 135;

	public Animator[] savedAnimators;

	public table<string, Animator> saved_a = new table<string, Animator>();

	public static table<string, AudioClip> saved_ac = new table<string, AudioClip>();

	public table<string, ParticleSystem> saved_ps = new table<string, ParticleSystem>();

	public table<string, MeshRenderer> saved_mr = new table<string, MeshRenderer>();

	public table<string, GameObject> saved_go = new table<string, GameObject>();

	public static table<string, Material> saved_mt = new table<string, Material>();

	public AudioSource audio = null;

	public AudioSource mixed = null;

	public AudioSource third = null;

	public bool mixed_active = false;

	public float mixed_lowest;

	public float mixed_highest;

	public float mixed_lerpSpeed;

	public float cooldown = 0f;

	public float time_since_spawned = 0f;

	public float time_of_event = 0f;

	public float time_since_last_gear = 0f;

	public float mixed_disable_delay = 0f;

	public int gear = 1;

	public float gearAnimValue = 0f;

	public float kuro1080 = 0f;

	public float kuro_z = 72f;

	public float red666 = 0f;

	public float red_s = 0.1f;

	public void Awake()
	{
		savedAnimators = ((Component)this).gameObject.GetComponentsInChildren<Animator>(true);
		Transform val = ((IEnumerable<Transform>)((Component)this).GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform _) => ((Object)_).name == "Headlights"));
		if ((Object)(object)val != (Object)null)
		{
			((Component)val).gameObject.SetActive(false);
			Light[] componentsInChildren = ((Component)val).GetComponentsInChildren<Light>(true);
			foreach (Light val2 in componentsInChildren)
			{
				val2.intensity = 45f;
			}
		}
	}

	public void Update()
	{
		//IL_0407: Unknown result type (might be due to invalid IL or missing references)
		//IL_0397: Unknown result type (might be due to invalid IL or missing references)
		//IL_0467: Unknown result type (might be due to invalid IL or missing references)
		//IL_0471: Unknown result type (might be due to invalid IL or missing references)
		//IL_0432: Unknown result type (might be due to invalid IL or missing references)
		//IL_0449: Unknown result type (might be due to invalid IL or missing references)
		//IL_044e: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ae: Unknown result type (might be due to invalid IL or missing references)
		if (cooldown > 0f)
		{
			cooldown -= Time.deltaTime;
		}
		time_since_spawned += Time.deltaTime;
		if (mixed_disable_delay > 0f)
		{
			mixed_disable_delay -= Time.deltaTime;
			if (mixed_disable_delay <= 0f)
			{
				mixed_active = false;
			}
		}
		if (mixed_active)
		{
			mixed.volume = Mathf.Max(Mathf.Lerp(mixed.volume, mixed_highest, mixed_lerpSpeed * Time.deltaTime), mixed_lowest);
		}
		else if (mixed.isPlaying && (Object)(object)mixed.clip != (Object)null && ((Object)mixed.clip).name != "Fireplace")
		{
			mixed.volume = Mathf.Lerp(mixed.volume, 0f, 3f * Time.deltaTime);
			if (mixed.volume == 0f)
			{
				mixed.Stop();
			}
		}
		if ((Object)(object)saved_a["gear"] != (Object)null && time_since_spawned - time_since_last_gear < 4f)
		{
			if (gear == 1)
			{
				gearAnimValue = Mathf.MoveTowards(gearAnimValue, 0f, 15f * Time.deltaTime * (time_since_spawned - time_since_last_gear));
			}
			else if (gear == 2)
			{
				gearAnimValue = Mathf.MoveTowards(gearAnimValue, 0.5f, 15f * Time.deltaTime * (time_since_spawned - time_since_last_gear));
			}
			else if (gear == 3)
			{
				gearAnimValue = Mathf.MoveTowards(gearAnimValue, 1f, 15f * Time.deltaTime * (time_since_spawned - time_since_last_gear));
			}
			saved_a["gear"].SetFloat("gear", Mathf.Clamp(gearAnimValue, 0.01f, 0.99f));
		}
		if (kuro1080 > 0f && (Object)(object)toycar != (Object)null)
		{
			kuro1080 -= Time.deltaTime;
			toycar.Rotate(0f, 0f, kuro_z * Time.deltaTime);
			if (kuro1080 <= 0f)
			{
				if ((Object)(object)saved_mt["kuro"] == (Object)null)
				{
					saved_mt["kuro"] = ((Renderer)((Component)toycar).GetComponent<MeshRenderer>()).material;
				}
				if ((Object)(object)saved_mt["kuro"] != (Object)null)
				{
					((Renderer)