Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of GolfCart v0.1.0
GolfCart.dll
Decompiled 3 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security.Cryptography; using System.Text; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using LethalCompanyInputUtils.Api; using Microsoft.CodeAnalysis; using ModMenu; using Unity.Collections; using Unity.Netcode; using UnityEngine; using UnityEngine.Events; using UnityEngine.InputSystem; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("GolfCart")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.1.0.0")] [assembly: AssemblyInformationalVersion("0.1.0+5cc92ad867fbaa56f59ff8b169ddc50e6b84bfe9")] [assembly: AssemblyProduct("GolfCart")] [assembly: AssemblyTitle("GolfCart")] [assembly: AssemblyVersion("0.1.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace GolfCart { internal static class Settings { internal static float TopSpeed = 10f; internal static float ReverseSpeed = 4f; internal static int BasketCapacity = 12; internal static bool SelfRighting = true; internal static bool Explode; internal static void FromConfig() { TopSpeed = Plugin.TopSpeed.Value; ReverseSpeed = Plugin.ReverseSpeed.Value; BasketCapacity = Plugin.BasketCapacity.Value; SelfRighting = Plugin.SelfRighting.Value; Explode = Plugin.ExplodeAtZeroHp.Value; } } public class Cart : MonoBehaviour { internal const ulong NoOne = ulong.MaxValue; internal const float WheelRadius = 0.36f; internal static readonly List<Cart> All = new List<Cart>(); public Vector3 comLocal; internal VehicleController Vc; internal Rigidbody Rb; internal readonly InteractTrigger[] Rear = (InteractTrigger[])(object)new InteractTrigger[2]; internal readonly ulong[] RearSeat = new ulong[2] { 18446744073709551615uL, 18446744073709551615uL }; internal int LocalRear = -1; internal float ReverseHold; internal float Torque; private float _tiltTime; private float _watchTime; private bool _righting; internal static PlayerControllerB Local { get { if (!((Object)(object)GameNetworkManager.Instance != (Object)null)) { return null; } return GameNetworkManager.Instance.localPlayerController; } } internal static Cart Of(VehicleController vc) { Cart result = default(Cart); if (!((Object)(object)vc != (Object)null) || !((Component)vc).TryGetComponent<Cart>(ref result)) { return null; } return result; } internal void Setup(VehicleController vc, Transform model) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: 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_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) Transform val = model.Find("Markers"); Vector3 val2 = Vector3.zero; int num = 0; string[] array = new string[4] { "FL", "FR", "BL", "BR" }; foreach (string text in array) { Transform[] componentsInChildren = ((Component)val).GetComponentsInChildren<Transform>(true); foreach (Transform val3 in componentsInChildren) { if (((Object)val3).name == "M_Wheel_" + text) { val2 += val3.position; num++; } } } if (num > 0) { val2 /= (float)num; } comLocal = ((Component)vc).transform.InverseTransformPoint(new Vector3(0f, val2.y + 0.1f, val2.z)); } private void Awake() { Vc = ((Component)this).GetComponent<VehicleController>(); Rb = (((Object)(object)Vc.mainRigidbody != (Object)null) ? Vc.mainRigidbody : ((Component)this).GetComponent<Rigidbody>()); InteractTrigger[] componentsInChildren = ((Component)this).GetComponentsInChildren<InteractTrigger>(true); foreach (InteractTrigger val in componentsInChildren) { if (((Object)val).name == "GolfCartRearSeat0") { Rear[0] = val; } else if (((Object)val).name == "GolfCartRearSeat1") { Rear[1] = val; } } for (int j = 0; j < 2; j++) { if ((Object)(object)Rear[j] == (Object)null) { Plugin.Log.LogError((object)$"Golf Cart: rear seat {j} missing."); continue; } int k = j; ((UnityEvent<PlayerControllerB>)(object)Rear[j].onInteractEarly).AddListener((UnityAction<PlayerControllerB>)delegate { SitLocal(k); }); ((UnityEvent<PlayerControllerB>)(object)Rear[j].onCancelAnimation).AddListener((UnityAction<PlayerControllerB>)delegate { LeaveLocal(k); }); } All.Add(this); } private void OnDestroy() { All.Remove(this); if (LocalRear >= 0 && (Object)(object)Local != (Object)null) { LocalRear = -1; Vc.SetVehicleCollisionForPlayer(true, Local); Local.CancelSpecialTriggerAnimations(); } } private void SitLocal(int i) { PlayerControllerB local = Local; if (!((Object)(object)local == (Object)null)) { LocalRear = i; Vc.SetVehicleCollisionForPlayer(false, local); Vc.SetPlayerInCar(local); Net.RequestSeat(this, i, sit: true); } } private void LeaveLocal(int i) { //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) PlayerControllerB local = Local; if (LocalRear != i || (Object)(object)local == (Object)null) { return; } LocalRear = -1; Vc.SetVehicleCollisionForPlayer(true, local); Transform[] array = ((i == 0) ? Vc.driverSideExitPoints : Vc.passengerSideExitPoints); if (array != null && array.Length != 0) { Transform val = array[Mathf.Min(1, array.Length - 1)]; Transform[] array2 = array; foreach (Transform val2 in array2) { if ((Object)(object)val2 != (Object)null && !Physics.Linecast(((Component)local.gameplayCamera).transform.position, val2.position, 2305, (QueryTriggerInteraction)1)) { val = val2; break; } } local.TeleportPlayer(val.position, false, 0f, false, true); } Net.RequestSeat(this, i, sit: false); } internal void ApplySeats(ulong s0, ulong s1) { RearSeat[0] = s0; RearSeat[1] = s1; RefreshSeats(); } internal void RefreshSeats() { ulong num = (((Object)(object)Local != (Object)null) ? Local.playerClientId : ulong.MaxValue); for (int i = 0; i < 2; i++) { if ((Object)(object)Rear[i] != (Object)null) { Rear[i].interactable = !Vc.carDestroyed && (RearSeat[i] == ulong.MaxValue || RearSeat[i] == num); } } } internal void HostSeat(ulong player, int seat, bool sit) { if (seat < 0 || seat > 1) { return; } if (sit) { if (RearSeat[seat] != ulong.MaxValue && RearSeat[seat] != player) { return; } for (int i = 0; i < 2; i++) { if (RearSeat[i] == player) { RearSeat[i] = ulong.MaxValue; } } RearSeat[seat] = player; } else if (RearSeat[seat] == player) { RearSeat[seat] = ulong.MaxValue; } RefreshSeats(); Net.BroadcastSeats(this); } internal bool HasRoomFor(GrabbableObject item) { Transform val = (((Object)(object)Vc.physicsRegion != (Object)null) ? Vc.physicsRegion.physicsTransform : null); if ((Object)(object)val == (Object)null) { return true; } int num = 0; GrabbableObject[] componentsInChildren = ((Component)val).GetComponentsInChildren<GrabbableObject>(); foreach (GrabbableObject val2 in componentsInChildren) { if ((Object)(object)val2 != (Object)(object)item) { num += Weight(val2); } } return num + Weight(item) <= Settings.BasketCapacity; } private static int Weight(GrabbableObject g) { if (!((Object)(object)g != (Object)null) || !((Object)(object)g.itemProperties != (Object)null) || !g.itemProperties.twoHanded) { return 1; } return 2; } private void Update() { //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) if (!Net.IsHost || !((_watchTime += Time.deltaTime) > 0.5f)) { return; } _watchTime = 0f; bool flag = false; PlayerControllerB[] array = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.allPlayerScripts : null); for (int i = 0; i < 2; i++) { if (RearSeat[i] != ulong.MaxValue) { PlayerControllerB val = ((array != null && (int)RearSeat[i] < array.Length) ? array[(uint)RearSeat[i]] : null); if ((Object)(object)val == (Object)null || !val.isPlayerControlled || val.isPlayerDead || Vc.carDestroyed || Vector3.Distance(((Component)val).transform.position, ((Object)(object)Rear[i] != (Object)null) ? ((Component)Rear[i]).transform.position : ((Component)this).transform.position) > 4f) { RearSeat[i] = ulong.MaxValue; flag = true; } } } if (flag) { RefreshSeats(); Net.BroadcastSeats(this); } } private void FixedUpdate() { //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: 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_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Vc == (Object)null || (Object)(object)Rb == (Object)null || !((NetworkBehaviour)Vc).IsOwner || Vc.magnetedToShip || Vc.carDestroyed || !Vc.hasBeenSpawned || Vc.inDropshipAnimation || _righting || Rb.isKinematic) { return; } if (Vector3.Dot(((Component)this).transform.up, Vector3.up) > 0.5f) { Rb.AddForce(-((Component)this).transform.up * Rb.mass * 3f, (ForceMode)0); } if ((Object)(object)Vc.currentDriver != (Object)null) { Vector3 velocity = Rb.velocity; Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(velocity.x, 0f, velocity.z); float num = ((Vector3.Dot(val, ((Component)this).transform.forward) >= 0f) ? Settings.TopSpeed : Settings.ReverseSpeed) * 1.08f; if (((Vector3)(ref val)).magnitude > num) { Rb.velocity = ((Vector3)(ref val)).normalized * num + Vector3.up * velocity.y; } } if (!Settings.SelfRighting) { _tiltTime = 0f; return; } if (Vector3.Angle(((Component)this).transform.up, Vector3.up) > 55f) { Vector3 velocity2 = Rb.velocity; if (((Vector3)(ref velocity2)).magnitude < 2f) { _tiltTime += Time.fixedDeltaTime; goto IL_01cb; } } _tiltTime = 0f; goto IL_01cb; IL_01cb: if (_tiltTime > 1.5f) { _tiltTime = 0f; RightNow(); } } internal bool RightNow() { if (_righting || !((NetworkBehaviour)Vc).IsOwner || Vc.magnetedToShip || Vc.carDestroyed) { return false; } ((MonoBehaviour)this).StartCoroutine(Right()); return true; } private IEnumerator Right() { _righting = true; bool wasKinematic = Rb.isKinematic; Rb.isKinematic = true; Vector3 p0 = ((Component)this).transform.position; Quaternion r0 = ((Component)this).transform.rotation; Vector3 val = Vector3.ProjectOnPlane(((Component)this).transform.forward, Vector3.up); if (((Vector3)(ref val)).sqrMagnitude < 0.01f) { val = Vector3.ProjectOnPlane(((Component)this).transform.up, Vector3.up); } if (((Vector3)(ref val)).sqrMagnitude < 0.01f) { val = Vector3.forward; } Quaternion r1 = Quaternion.LookRotation(((Vector3)(ref val)).normalized, Vector3.up); Vector3 p1 = p0 + Vector3.up * 0.4f; for (float t = 0f; t < 0.8f; t += Time.deltaTime) { float num = Mathf.SmoothStep(0f, 1f, t / 0.8f); ((Component)this).transform.SetPositionAndRotation(Vector3.Lerp(p0, p1, num), Quaternion.Slerp(r0, r1, num)); yield return null; } ((Component)this).transform.SetPositionAndRotation(p1, r1); Rb.isKinematic = wasKinematic; if (!Rb.isKinematic) { Rb.velocity = Vector3.zero; Rb.angularVelocity = Vector3.zero; } Vc.syncedPosition = p1; _righting = false; } } internal static class Keys { private static InputAction _horn; private static InputAction _lights; internal static void Init() { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown //IL_0066: Expected O, but got Unknown if (Plugin.InputUtilsLoaded) { FromInputUtils(out _horn, out _lights); } if (_horn == null || _lights == null) { InputActionMap val = new InputActionMap("GolfCart"); _horn = InputActionSetupExtensions.AddAction(val, "GolfCart.Horn", (InputActionType)1, Plugin.HornKey.Value, (string)null, (string)null, (string)null, (string)null); _lights = InputActionSetupExtensions.AddAction(val, "GolfCart.Lights", (InputActionType)1, Plugin.LightsKey.Value, (string)null, (string)null, (string)null, (string)null); } _horn.performed += delegate { Horn(on: true); }; _horn.canceled += delegate { Horn(on: false); }; _lights.performed += delegate { Lights(); }; } [MethodImpl(MethodImplOptions.NoInlining)] private static void FromInputUtils(out InputAction horn, out InputAction lights) { horn = GolfCartInputs.Instance.Horn; lights = GolfCartInputs.Instance.Lights; } internal static void Enable(bool on) { InputAction[] array = (InputAction[])(object)new InputAction[2] { _horn, _lights }; foreach (InputAction val in array) { if (val != null) { if (on) { val.Enable(); } else { val.Disable(); } } } } internal static string Binding(bool horn) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) InputAction val = (horn ? _horn : _lights); if (val == null || val.bindings.Count <= 0) { if (!horn) { return "L"; } return "H"; } return InputActionRebindingExtensions.GetBindingDisplayString(val, (DisplayStringOptions)0, (string)null); } internal static Cart Driven() { PlayerControllerB local = Cart.Local; if ((Object)(object)local == (Object)null || local.isPlayerDead || local.isTypingChat || local.inTerminalMenu) { return null; } if ((Object)(object)local.quickMenuManager != (Object)null && local.quickMenuManager.isMenuOpen) { return null; } foreach (Cart item in Cart.All) { if ((Object)(object)item != (Object)null && (Object)(object)item.Vc != (Object)null && item.Vc.localPlayerInControl && !item.Vc.carDestroyed) { return item; } } return null; } private static void Horn(bool on) { Cart cart = (on ? Driven() : null); if (!on) { foreach (Cart item in Cart.All) { if ((Object)(object)item != (Object)null && (Object)(object)item.Vc != (Object)null && item.Vc.localPlayerInControl && item.Vc.honkingHorn) { item.Vc.SetHonkingLocalClient(false); } } return; } if ((Object)(object)cart != (Object)null && !cart.Vc.honkingHorn) { cart.Vc.SetHonkingLocalClient(true); } } internal static string Lights() { Cart cart = Driven(); if ((Object)(object)cart == (Object)null || (Object)(object)cart.Vc.headlightsContainer == (Object)null) { return null; } cart.Vc.ToggleHeadlightsLocalClient(); if (!cart.Vc.headlightsContainer.activeSelf) { return "headlights off"; } return "headlights on"; } } internal class GolfCartInputs : LcInputActions { internal static readonly GolfCartInputs Instance = new GolfCartInputs(); [InputAction("<Keyboard>/h", Name = "Golf cart horn")] public InputAction Horn { get; set; } [InputAction("<Keyboard>/l", Name = "Golf cart headlights")] public InputAction Lights { get; set; } } [HarmonyPatch] internal static class KeyPatches { [HarmonyPatch(typeof(StartOfRound), "OnEnable")] [HarmonyPostfix] private static void On() { Keys.Enable(on: true); } [HarmonyPatch(typeof(StartOfRound), "OnDisable")] [HarmonyPostfix] private static void Off() { Keys.Enable(on: false); } } internal static class MenuHooks { internal const string ModMenuGuid = "daniel.lethalcompany.modmenu"; private const string Tab = "Golf Cart"; [MethodImpl(MethodImplOptions.NoInlining)] internal static void Register() { MenuApi.Button("Golf Cart", "Spawn golf cart at the ship", (Func<string>)SpawnCart, true, true, (Func<string>)(() => NoSpawn()), (string)null); MenuApi.Button("Golf Cart", "Repair golf cart", (Func<string>)Repair, true, true, (Func<string>)(() => (!((Object)(object)Any() == (Object)null)) ? null : "no cart out"), (string)null); MenuApi.Button("Golf Cart", "Flip cart upright", (Func<string>)Flip, true, true, (Func<string>)(() => (!((Object)(object)Any() == (Object)null)) ? null : "no cart out"), (string)null); MenuApi.Button("Golf Cart", "Bring cart to me", (Func<string>)Bring, true, true, (Func<string>)(() => BringBlocked()), (string)null); MenuApi.Choice("Golf Cart", "Top speed", new string[6] { "6 m/s", "8 m/s", "10 m/s", "12 m/s", "14 m/s", "16 m/s" }, (Func<int, string>)((int i) => Set(delegate { Plugin.TopSpeed.Value = 6f + 2f * (float)i; }, $"top speed {6 + 2 * i} m/s")), true, false, (Func<string>)null, (string)null); int[] caps = new int[5] { 6, 9, 12, 16, 24 }; MenuApi.Choice("Golf Cart", "Basket capacity", caps.Select((int c) => c + " items").ToArray(), (Func<int, string>)((int i) => Set(delegate { Plugin.BasketCapacity.Value = caps[i]; }, $"basket holds {caps[i]}")), true, false, (Func<string>)null, (string)null); MenuApi.Toggle("Golf Cart", "Self-righting", (Func<bool>)(() => Plugin.SelfRighting.Value), (Func<bool, string>)((bool on) => Set(delegate { Plugin.SelfRighting.Value = on; }, on ? "self-righting on" : "self-righting off")), true, false, (Func<string>)null, (string)null); MenuApi.Choice("Golf Cart", "When it runs out of HP", new string[2] { "Breakdown", "Explode like the Cruiser" }, (Func<int, string>)((int i) => Set(delegate { Plugin.ExplodeAtZeroHp.Value = i == 1; }, (i == 1) ? "it explodes at 0 HP" : "it breaks down at 0 HP")), true, false, (Func<string>)null, (string)null); int[] prices = new int[5] { 150, 200, 250, 300, 370 }; MenuApi.Choice("Golf Cart", "Price", prices.Select((int p) => "$" + p).ToArray(), (Func<int, string>)delegate(int i) { Plugin.Price.Value = prices[i]; return $"price ${prices[i]} (from the next lobby)"; }, true, false, (Func<string>)null, (string)null); MenuApi.Toggle("Golf Cart", "Lights on when it's dark", (Func<bool>)(() => Plugin.AutoLights.Value), (Func<bool, string>)delegate(bool on) { Plugin.AutoLights.Value = on; return (!on) ? "auto lights off" : "auto lights on"; }, false, false, (Func<string>)null, (string)null); MenuApi.Button("Golf Cart", "Headlights", (Func<string>)(() => Keys.Lights()), false, false, (Func<string>)(() => (!((Object)(object)Keys.Driven() == (Object)null)) ? null : "drive a cart first"), "or press L"); MenuApi.Button("Golf Cart", "Show cart keys", (Func<string>)(() => "W drive, S brake then reverse, A/D steer, " + Keys.Binding(horn: true) + " horn, " + Keys.Binding(horn: false) + " lights, LMB or Space get out"), false, false, (Func<string>)null, (string)null); } private static string Set(Action set, string what) { set(); Net.BroadcastConfig(); return what; } private static PlayerControllerB Player() { if (!((Object)(object)StartOfRound.Instance != (Object)null)) { return null; } return StartOfRound.Instance.localPlayerController; } private static Cart Any() { return Cart.All.FirstOrDefault((Cart c) => (Object)(object)c != (Object)null && (Object)(object)c.Vc != (Object)null && ((NetworkBehaviour)c.Vc).IsSpawned); } private static string NoSpawn() { if ((Object)(object)Registry.Prefab == (Object)null) { return "cart not built (see the log)"; } if ((Object)(object)StartOfRound.Instance == (Object)null || (Object)(object)Player() == (Object)null) { return "not in a game"; } if ((Object)(object)Any() != (Object)null || (Object)(object)StartOfRound.Instance.attachedVehicle != (Object)null || (Object)(object)Object.FindObjectOfType<VehicleController>() != (Object)null) { return "a vehicle is already out"; } return null; } private static string SpawnCart() { if (NoSpawn() != null) { return null; } StartOfRound instance = StartOfRound.Instance; Save.SpawnOnMagnet(instance, instance.inShipPhase ? 5f : 7f); if (!instance.inShipPhase) { return "spawned a golf cart behind the ship"; } return "spawned a golf cart on the magnet"; } private static string Repair() { Cart cart = Any(); if ((Object)(object)cart == (Object)null) { return null; } if (cart.Vc.carDestroyed) { return "it's a wreck: engine oil can't bring it back (vanilla)"; } cart.Vc.AddEngineOilServerRpc((int)Player().playerClientId, cart.Vc.baseCarHP); return "golf cart repaired"; } private static string Flip() { Cart cart = Any(); if ((Object)(object)cart == (Object)null) { return null; } if (!((NetworkBehaviour)cart.Vc).IsOwner) { return "the driver's game runs the cart: they can wait 1.5 s on its side and it rights itself"; } if (!cart.RightNow()) { return "can't flip it now"; } return "flipping the cart upright"; } private static string BringBlocked() { Cart cart = Any(); PlayerControllerB val = Player(); if ((Object)(object)cart == (Object)null) { return "no cart out"; } if ((Object)(object)val == (Object)null || val.isPlayerDead) { return "not in a game"; } if (val.isInsideFactory) { return "outdoors only"; } if ((Object)(object)cart.Vc.currentDriver != (Object)null) { return "someone's driving it"; } if (cart.Vc.magnetedToShip) { return "it's on the magnet"; } if (!((NetworkBehaviour)cart.Vc).IsOwner) { return "another player's game runs it"; } return null; } private static string Bring() { //IL_0019: 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_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: 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_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) if (BringBlocked() != null) { return null; } Cart cart = Any(); PlayerControllerB obj = Player(); Vector3 val = Vector3.ProjectOnPlane(((Component)obj).transform.forward, Vector3.up); Vector3 normalized = ((Vector3)(ref val)).normalized; Vector3 val2 = ((Component)obj).transform.position + normalized * 4f + Vector3.up * 0.6f; RaycastHit val3 = default(RaycastHit); if (Physics.Raycast(val2 + Vector3.up * 3f, Vector3.down, ref val3, 10f, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1)) { val2 = ((RaycastHit)(ref val3)).point + Vector3.up * 0.6f; } cart.Rb.velocity = Vector3.zero; cart.Rb.angularVelocity = Vector3.zero; ((Component)cart).transform.SetPositionAndRotation(val2, Quaternion.LookRotation(-normalized, Vector3.up)); cart.Vc.syncedPosition = val2; return "brought the golf cart to you"; } } internal static class Net { [CompilerGenerated] private static class <>O { public static HandleNamedMessageDelegate <0>__OnSeatRequest; public static HandleNamedMessageDelegate <1>__OnConfig; public static HandleNamedMessageDelegate <2>__OnSeats; public static Action<FastBufferWriter> <3>__WriteConfig; } [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static HandleNamedMessageDelegate <>9__8_0; internal void <Register>b__8_0(ulong sender, FastBufferReader r) { SendFull(sender); } } private const string MsgHello = "daniel.golfcart.hello"; private const string MsgConfig = "daniel.golfcart.cfg"; private const string MsgSeatReq = "daniel.golfcart.seatreq"; private const string MsgSeats = "daniel.golfcart.seats"; private static readonly string[] AllNames = new string[4] { "daniel.golfcart.hello", "daniel.golfcart.cfg", "daniel.golfcart.seatreq", "daniel.golfcart.seats" }; private static bool _registered; public static bool IsHost { get { if ((Object)(object)NetworkManager.Singleton != (Object)null) { return NetworkManager.Singleton.IsServer; } return false; } } public static void Register() { //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Expected O, but got Unknown //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Expected O, but got Unknown //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown NetworkManager singleton = NetworkManager.Singleton; if (_registered || (Object)(object)singleton == (Object)null || singleton.CustomMessagingManager == null) { return; } CustomMessagingManager customMessagingManager = singleton.CustomMessagingManager; if (singleton.IsServer) { object obj = <>c.<>9__8_0; if (obj == null) { HandleNamedMessageDelegate val = delegate(ulong sender, FastBufferReader r) { SendFull(sender); }; <>c.<>9__8_0 = val; obj = (object)val; } customMessagingManager.RegisterNamedMessageHandler("daniel.golfcart.hello", (HandleNamedMessageDelegate)obj); object obj2 = <>O.<0>__OnSeatRequest; if (obj2 == null) { HandleNamedMessageDelegate val2 = OnSeatRequest; <>O.<0>__OnSeatRequest = val2; obj2 = (object)val2; } customMessagingManager.RegisterNamedMessageHandler("daniel.golfcart.seatreq", (HandleNamedMessageDelegate)obj2); Settings.FromConfig(); } else { object obj3 = <>O.<1>__OnConfig; if (obj3 == null) { HandleNamedMessageDelegate val3 = OnConfig; <>O.<1>__OnConfig = val3; obj3 = (object)val3; } customMessagingManager.RegisterNamedMessageHandler("daniel.golfcart.cfg", (HandleNamedMessageDelegate)obj3); object obj4 = <>O.<2>__OnSeats; if (obj4 == null) { HandleNamedMessageDelegate val4 = OnSeats; <>O.<2>__OnSeats = val4; obj4 = (object)val4; } customMessagingManager.RegisterNamedMessageHandler("daniel.golfcart.seats", (HandleNamedMessageDelegate)obj4); Send("daniel.golfcart.hello", 0uL, null); } _registered = true; } public static void Unregister() { CustomMessagingManager val = (((Object)(object)NetworkManager.Singleton != (Object)null) ? NetworkManager.Singleton.CustomMessagingManager : null); if (val != null) { string[] allNames = AllNames; foreach (string text in allNames) { try { val.UnregisterNamedMessageHandler(text); } catch (Exception) { } } } _registered = false; } internal static void BroadcastConfig() { if (IsHost) { Settings.FromConfig(); Send("daniel.golfcart.cfg", null, WriteConfig); } } private static void WriteConfig(FastBufferWriter w) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) ((FastBufferWriter)(ref w)).WriteValueSafe<float>(ref Settings.TopSpeed, default(ForPrimitives)); ((FastBufferWriter)(ref w)).WriteValueSafe<float>(ref Settings.ReverseSpeed, default(ForPrimitives)); ((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref Settings.BasketCapacity, default(ForPrimitives)); ((FastBufferWriter)(ref w)).WriteValueSafe<bool>(ref Settings.SelfRighting, default(ForPrimitives)); ((FastBufferWriter)(ref w)).WriteValueSafe<bool>(ref Settings.Explode, default(ForPrimitives)); } private static void OnConfig(ulong sender, FastBufferReader r) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) ((FastBufferReader)(ref r)).ReadValueSafe<float>(ref Settings.TopSpeed, default(ForPrimitives)); ((FastBufferReader)(ref r)).ReadValueSafe<float>(ref Settings.ReverseSpeed, default(ForPrimitives)); ((FastBufferReader)(ref r)).ReadValueSafe<int>(ref Settings.BasketCapacity, default(ForPrimitives)); ((FastBufferReader)(ref r)).ReadValueSafe<bool>(ref Settings.SelfRighting, default(ForPrimitives)); ((FastBufferReader)(ref r)).ReadValueSafe<bool>(ref Settings.Explode, default(ForPrimitives)); Plugin.Log.LogInfo((object)$"Golf Cart: host settings: top {Settings.TopSpeed} m/s, reverse {Settings.ReverseSpeed}, basket {Settings.BasketCapacity}, self-righting {Settings.SelfRighting}, explode {Settings.Explode}."); } private static void SendFull(ulong client) { Send("daniel.golfcart.cfg", client, WriteConfig); foreach (Cart c in Cart.All) { if ((Object)(object)c != (Object)null && (Object)(object)c.Vc != (Object)null && ((NetworkBehaviour)c.Vc).IsSpawned) { Send("daniel.golfcart.seats", client, delegate(FastBufferWriter w) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) WriteSeats(w, c); }); } } } internal static void RequestSeat(Cart c, int seat, bool sit) { if ((Object)(object)c == (Object)null || (Object)(object)c.Vc == (Object)null || !((NetworkBehaviour)c.Vc).IsSpawned || (Object)(object)Cart.Local == (Object)null) { return; } if (IsHost) { c.HostSeat(Cart.Local.playerClientId, seat, sit); return; } ulong id = ((NetworkBehaviour)c.Vc).NetworkObjectId; Send("daniel.golfcart.seatreq", 0uL, delegate(FastBufferWriter w) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0026: 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_003c: Unknown result type (might be due to invalid IL or missing references) ((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref id, default(ForPrimitives)); ((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref seat, default(ForPrimitives)); ((FastBufferWriter)(ref w)).WriteValueSafe<bool>(ref sit, default(ForPrimitives)); }); } private static void OnSeatRequest(ulong sender, FastBufferReader r) { //IL_0006: 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) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) ulong id = default(ulong); ((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref id, default(ForPrimitives)); int seat = default(int); ((FastBufferReader)(ref r)).ReadValueSafe<int>(ref seat, default(ForPrimitives)); bool sit = default(bool); ((FastBufferReader)(ref r)).ReadValueSafe<bool>(ref sit, default(ForPrimitives)); Cart cart = Find(id); if (!((Object)(object)cart == (Object)null)) { StartOfRound instance = StartOfRound.Instance; if (!((Object)(object)instance == (Object)null) && instance.ClientPlayerList.TryGetValue(sender, out var value)) { cart.HostSeat((ulong)value, seat, sit); } } } internal static void BroadcastSeats(Cart c) { if (IsHost && !((Object)(object)c == (Object)null) && !((Object)(object)c.Vc == (Object)null) && ((NetworkBehaviour)c.Vc).IsSpawned) { Send("daniel.golfcart.seats", null, delegate(FastBufferWriter w) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) WriteSeats(w, c); }); } } private static void WriteSeats(FastBufferWriter w, Cart c) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) ulong networkObjectId = ((NetworkBehaviour)c.Vc).NetworkObjectId; ((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref networkObjectId, default(ForPrimitives)); ((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref c.RearSeat[0], default(ForPrimitives)); ((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref c.RearSeat[1], default(ForPrimitives)); } private static void OnSeats(ulong sender, FastBufferReader r) { //IL_0006: 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) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) ulong id = default(ulong); ((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref id, default(ForPrimitives)); ulong s = default(ulong); ((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref s, default(ForPrimitives)); ulong s2 = default(ulong); ((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref s2, default(ForPrimitives)); Cart cart = Find(id); if ((Object)(object)cart != (Object)null) { cart.ApplySeats(s, s2); } } private static Cart Find(ulong id) { NetworkManager singleton = NetworkManager.Singleton; if (!((Object)(object)singleton != (Object)null) || !singleton.SpawnManager.SpawnedObjects.TryGetValue(id, out var value)) { return null; } return ((Component)value).GetComponent<Cart>(); } private static void Send(string name, ulong? to, Action<FastBufferWriter> write) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || singleton.CustomMessagingManager == null) { return; } FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(64, (Allocator)2, 4096); try { write?.Invoke(val); if (to.HasValue) { singleton.CustomMessagingManager.SendNamedMessage(name, to.Value, val, (NetworkDelivery)3); return; } foreach (ulong connectedClientsId in singleton.ConnectedClientsIds) { if (connectedClientsId != 0L) { singleton.CustomMessagingManager.SendNamedMessage(name, connectedClientsId, val, (NetworkDelivery)3); } } } finally { ((FastBufferWriter)(ref val)).Dispose(); } } } [HarmonyPatch] internal static class NetPatches { [HarmonyPatch(typeof(StartOfRound), "Start")] [HarmonyPostfix] private static void StartOfRoundStart() { Net.Register(); } [HarmonyPatch(typeof(StartOfRound), "OnDestroy")] [HarmonyPrefix] private static void StartOfRoundDestroy() { Net.Unregister(); } } [HarmonyPatch(typeof(VehicleController))] internal static class Patches { private static readonly FieldRef<VehicleController, bool> GearBoost = AccessTools.FieldRefAccess<VehicleController, bool>("switchGearsBoostEnabled"); private static readonly FieldRef<VehicleController, bool> KeyInHand = AccessTools.FieldRefAccess<VehicleController, bool>("keyIsInDriverHand"); private static readonly FieldRef<VehicleController, float> MagnetRotationTime = AccessTools.FieldRefAccess<VehicleController, float>("magnetRotationTime"); private static readonly FieldRef<VehicleController, Vector3> MagnetTargetPosition = AccessTools.FieldRefAccess<VehicleController, Vector3>("magnetTargetPosition"); private static readonly FieldRef<VehicleController, Vector3> MagnetStartPosition = AccessTools.FieldRefAccess<VehicleController, Vector3>("magnetStartPosition"); private static readonly FieldRef<VehicleController, Quaternion> MagnetTargetRotation = AccessTools.FieldRefAccess<VehicleController, Quaternion>("magnetTargetRotation"); private static readonly FieldRef<VehicleController, Quaternion> MagnetStartRotation = AccessTools.FieldRefAccess<VehicleController, Quaternion>("magnetStartRotation"); private static readonly FieldRef<VehicleController, Vector3> VelocityAtMagnetStart = AccessTools.FieldRefAccess<VehicleController, Vector3>("averageVelocityAtMagnetStart"); internal static bool SuppressExplosion; private static int LocalId => (int)Cart.Local.playerClientId; private static WheelCollider[] Wheels(VehicleController vc) { return (WheelCollider[])(object)new WheelCollider[4] { vc.FrontLeftWheel, vc.FrontRightWheel, vc.BackLeftWheel, vc.BackRightWheel }; } [HarmonyPatch("Start")] [HarmonyPostfix] private static void Start(VehicleController __instance) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) Cart cart = Cart.Of(__instance); if (!((Object)(object)cart == (Object)null)) { __instance.mainRigidbody.centerOfMass = cart.comLocal; cart.RefreshSeats(); } } [HarmonyPatch("SetWheelFriction")] [HarmonyPostfix] private static void SetWheelFriction(VehicleController __instance) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Cart.Of(__instance) == (Object)null) { return; } WheelCollider[] array = Wheels(__instance); foreach (WheelCollider val in array) { if (!((Object)(object)val == (Object)null)) { WheelFrictionCurve forwardFriction = val.forwardFriction; ((WheelFrictionCurve)(ref forwardFriction)).stiffness = 2.5f; val.forwardFriction = forwardFriction; WheelFrictionCurve sidewaysFriction = val.sidewaysFriction; ((WheelFrictionCurve)(ref sidewaysFriction)).stiffness = 3.5f; val.sidewaysFriction = sidewaysFriction; } } } [HarmonyPatch("TakeControlOfVehicle")] [HarmonyPostfix] private static void TakeControl(VehicleController __instance) { if (!((Object)(object)Cart.Of(__instance) == (Object)null) && __instance.localPlayerInControl && !((Object)(object)Cart.Local == (Object)null)) { if (!__instance.ignitionStarted) { __instance.SetIgnition(true); KeyInHand.Invoke(__instance) = false; __instance.StartIgnitionServerRpc(LocalId); } Cart.Local.playerBodyAnimator.SetInteger("SA_CarAnim", 1); if (Plugin.AutoLights.Value && IsDark() && (Object)(object)__instance.headlightsContainer != (Object)null && !__instance.headlightsContainer.activeSelf) { __instance.ToggleHeadlightsLocalClient(); } } } private static bool IsDark() { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Invalid comparison between Unknown and I4 //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Invalid comparison between Unknown and I4 PlayerControllerB local = Cart.Local; if ((Object)(object)local != (Object)null && local.isInsideFactory) { return true; } TimeOfDay instance = TimeOfDay.Instance; if ((Object)(object)instance == (Object)null) { return false; } if (!(instance.normalizedTimeOfDay > 0.62f) && (int)instance.currentLevelWeather != 5) { return (int)instance.currentLevelWeather == 3; } return true; } [HarmonyPatch("LoseControlOfVehicle")] [HarmonyPostfix] private static void LoseControl(VehicleController __instance) { if (!((Object)(object)Cart.Of(__instance) == (Object)null) && !((Object)(object)Cart.Local == (Object)null)) { if (__instance.honkingHorn) { __instance.SetHonkingLocalClient(false); } if (__instance.ignitionStarted && !__instance.carDestroyed) { __instance.SetIgnition(false); __instance.RemoveKeyFromIgnitionServerRpc(LocalId); } } } [HarmonyPatch("GetVehicleInput")] [HarmonyPostfix] private static void GetVehicleInput(VehicleController __instance) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Invalid comparison between Unknown and I4 //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Invalid comparison between Unknown and I4 //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Expected I4, but got Unknown Cart cart = Cart.Of(__instance); if ((Object)(object)cart == (Object)null || !__instance.localPlayerInControl || (Object)(object)cart.Rb == (Object)null) { return; } float x = __instance.moveInputVector.x; float y = __instance.moveInputVector.y; float num = Vector3.Dot(cart.Rb.velocity, ((Component)__instance).transform.forward); CarGearShift val = __instance.gear; bool drivePedalPressed = false; bool brakePedalPressed = false; if (y > 0.1f) { cart.ReverseHold = 0f; if (num < -0.5f) { brakePedalPressed = true; } else { val = (CarGearShift)1; drivePedalPressed = true; } } else if (y < -0.1f) { if (num > 0.5f) { brakePedalPressed = true; cart.ReverseHold = 0f; } else { cart.ReverseHold += Time.deltaTime; if (cart.ReverseHold > 0.25f || (int)__instance.gear == 2) { val = (CarGearShift)2; drivePedalPressed = true; } else { brakePedalPressed = true; } } } else { cart.ReverseHold = 0f; } __instance.drivePedalPressed = drivePedalPressed; __instance.brakePedalPressed = brakePedalPressed; if (val != __instance.gear && (int)val != 3) { __instance.gear = val; __instance.ShiftToGearServerRpc((int)val, LocalId); } float num2 = Mathf.Lerp(30f, 14f, Mathf.Clamp01(Mathf.Abs(num) / Mathf.Max(1f, Settings.TopSpeed))); float num3 = x * num2 / 15f; float num4 = ((Mathf.Abs(x) > 0.1f) ? 3f : 5f); __instance.steeringInput = Mathf.MoveTowards(__instance.steeringInput, num3, num4 * Time.deltaTime); } [HarmonyPatch("Update")] [HarmonyPrefix] private static void UpdatePrefix(VehicleController __instance) { if ((Object)(object)Cart.Of(__instance) != (Object)null) { GearBoost.Invoke(__instance) = false; } } [HarmonyPatch("Update")] [HarmonyPostfix] private static void UpdatePostfix(VehicleController __instance) { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Invalid comparison between Unknown and I4 //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Invalid comparison between Unknown and I4 Cart cart = Cart.Of(__instance); if ((Object)(object)cart == (Object)null || (Object)(object)cart.Rb == (Object)null) { return; } if (!((NetworkBehaviour)__instance).IsOwner || !__instance.localPlayerInControl || !__instance.ignitionStarted || __instance.carDestroyed || __instance.magnetedToShip) { return; } float num = Vector3.Dot(cart.Rb.velocity, ((Component)__instance).transform.forward); float num2 = cart.Rb.mass * (Settings.TopSpeed / 2.5f) * 0.36f / 4f * 1.6f; float motorTorque; float brakeTorque; if (__instance.drivePedalPressed && (int)__instance.gear == 1) { float num3 = Mathf.Clamp01((Settings.TopSpeed - num) / (Settings.TopSpeed * 0.3f)); cart.Torque = Mathf.MoveTowards(cart.Torque, num2 * num3, num2 * 1.5f * Time.deltaTime); motorTorque = cart.Torque; brakeTorque = 0f; } else if (__instance.drivePedalPressed && (int)__instance.gear == 2) { float num4 = Mathf.Clamp01((Settings.ReverseSpeed + num) / (Settings.ReverseSpeed * 0.3f)); cart.Torque = Mathf.MoveTowards(cart.Torque, (0f - num2) * 0.6f * num4, num2 * 1.5f * Time.deltaTime); motorTorque = cart.Torque; brakeTorque = 0f; } else if (__instance.brakePedalPressed) { cart.Torque = 0f; motorTorque = 0f; brakeTorque = 2000f; } else { cart.Torque = 0f; motorTorque = 0f; brakeTorque = ((Mathf.Abs(num) < 0.4f) ? 2000f : 250f); } WheelCollider[] array = Wheels(__instance); foreach (WheelCollider val in array) { if (!((Object)(object)val == (Object)null)) { val.motorTorque = motorTorque; val.brakeTorque = brakeTorque; } } } [HarmonyPatch("SetInternalStress")] [HarmonyPrefix] private static bool SetInternalStress(VehicleController __instance) { return (Object)(object)Cart.Of(__instance) == (Object)null; } [HarmonyPatch("DoTurboBoost")] [HarmonyPrefix] private static bool DoTurboBoost(VehicleController __instance) { if ((Object)(object)Cart.Of(__instance) == (Object)null) { return true; } if (__instance.localPlayerInControl && (Object)(object)Cart.Local != (Object)null) { Cart.Local.CancelSpecialTriggerAnimations(); } return false; } [HarmonyPatch("AddTurboBoost")] [HarmonyPrefix] private static bool AddTurboBoost(VehicleController __instance) { if ((Object)(object)Cart.Of(__instance) == (Object)null) { return true; } if ((Object)(object)HUDManager.Instance != (Object)null) { HUDManager.Instance.DisplayTip("Golf Cart", "The turbo doesn't fit the golf cart.", false, false, "LC_Tip1"); } return false; } [HarmonyPatch("StartMagneting")] [HarmonyPrefix] private static bool StartMagneting(VehicleController __instance) { if ((Object)(object)Cart.Of(__instance) == (Object)null) { return true; } try { Magnet(__instance); } catch (Exception arg) { Plugin.Log.LogError((object)$"Golf Cart: magnet fit failed, using vanilla's: {arg}"); return true; } return false; } private static void Magnet(VehicleController vc) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: 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_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01f0: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_01fe: Unknown result type (might be due to invalid IL or missing references) //IL_0202: 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_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_0240: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_0247: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_024f: Unknown result type (might be due to invalid IL or missing references) //IL_0254: Unknown result type (might be due to invalid IL or missing references) //IL_0260: Unknown result type (might be due to invalid IL or missing references) //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_026a: Unknown result type (might be due to invalid IL or missing references) //IL_026f: Unknown result type (might be due to invalid IL or missing references) //IL_0273: Unknown result type (might be due to invalid IL or missing references) //IL_027f: Unknown result type (might be due to invalid IL or missing references) //IL_0284: Unknown result type (might be due to invalid IL or missing references) //IL_0286: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_0297: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_029e: Unknown result type (might be due to invalid IL or missing references) //IL_02a3: Unknown result type (might be due to invalid IL or missing references) //IL_02ab: Unknown result type (might be due to invalid IL or missing references) //IL_02ad: Unknown result type (might be due to invalid IL or missing references) //IL_02af: Unknown result type (might be due to invalid IL or missing references) //IL_02b1: Unknown result type (might be due to invalid IL or missing references) //IL_02d3: Unknown result type (might be due to invalid IL or missing references) //IL_02e8: Unknown result type (might be due to invalid IL or missing references) //IL_030a: Unknown result type (might be due to invalid IL or missing references) //IL_030c: Unknown result type (might be due to invalid IL or missing references) //IL_0311: Unknown result type (might be due to invalid IL or missing references) //IL_0317: Unknown result type (might be due to invalid IL or missing references) //IL_032a: Unknown result type (might be due to invalid IL or missing references) //IL_032f: Unknown result type (might be due to invalid IL or missing references) //IL_0346: Unknown result type (might be due to invalid IL or missing references) //IL_034b: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_0224: 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 (!((NetworkBehaviour)vc).IsOwner) { return; } StartOfRound instance = StartOfRound.Instance; Transform transform = ((Component)vc).transform; vc.magnetTime = 0f; MagnetRotationTime.Invoke(vc) = 0f; instance.isObjectAttachedToMagnet = true; instance.attachedVehicle = vc; vc.magnetedToShip = true; VelocityAtMagnetStart.Invoke(vc) = vc.averageVelocity; ((Component)vc).GetComponent<Rigidbody>().isKinematic = true; float num = Vector3.Angle(Quaternion.Euler(0f, transform.eulerAngles.y, 0f) * Vector3.forward, -instance.magnetPoint.forward); Vector3 eulerAngles = transform.eulerAngles; if (num < 47f || num > 133f) { if (eulerAngles.y < 0f) { eulerAngles.y -= 46f - num; } else { eulerAngles.y += 46f - num; } } eulerAngles.y = Mathf.Round(eulerAngles.y / 90f) * 90f; eulerAngles.z = Mathf.Round(eulerAngles.z / 90f) * 90f; eulerAngles.x += Random.Range(-5f, 5f); Quaternion val = Quaternion.Euler(eulerAngles); MagnetTargetRotation.Invoke(vc) = val; MagnetStartRotation.Invoke(vc) = transform.rotation; Quaternion rotation = transform.rotation; transform.rotation = val; BoxCollider boundsCollider = vc.boundsCollider; Vector3 val2 = ((Collider)boundsCollider).ClosestPoint(instance.magnetPoint.position) - transform.position; float y = val2.y; Bounds bounds = ((Collider)boundsCollider).bounds; if (y >= ((Bounds)(ref bounds)).extents.y) { ref float y2 = ref val2.y; float num2 = y2; bounds = ((Collider)boundsCollider).bounds; y2 = num2 - ((Bounds)(ref bounds)).extents.y / 2f; } else { float y3 = val2.y; bounds = ((Collider)boundsCollider).bounds; if (y3 <= ((Bounds)(ref bounds)).extents.y * 0.4f) { ref float y4 = ref val2.y; float num3 = y4; bounds = ((Collider)boundsCollider).bounds; y4 = num3 + ((Bounds)(ref bounds)).extents.y / 2f; } } val2 = instance.magnetPoint.position - val2; Vector3 lossyScale = transform.lossyScale; Vector3 centreRoot = transform.InverseTransformPoint(((Component)boundsCollider).transform.TransformPoint(boundsCollider.center)); Vector3 sizeRoot = Vector3.Scale(boundsCollider.size, Div(((Component)boundsCollider).transform.lossyScale, lossyScale)); float num4 = -20.4f + FrontZ(val, Registry.CruiserBoundsCenter, Registry.CruiserBoundsSize, lossyScale) - FrontZ(val, centreRoot, sizeRoot, lossyScale); float num5 = 2.5f - Registry.CruiserDrop + Drop(vc); val2.z = Mathf.Min(num4, val2.z); val2.y = Mathf.Max(num5, val2.y); MagnetTargetPosition.Invoke(vc) = instance.elevatorTransform.InverseTransformPoint(val2); transform.rotation = rotation; MagnetStartPosition.Invoke(vc) = transform.position; vc.CollectItemsInTruck(); vc.MagnetCarServerRpc(MagnetTargetPosition.Invoke(vc), eulerAngles, LocalId); } private static Vector3 Div(Vector3 a, Vector3 b) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) return new Vector3(a.x / b.x, a.y / b.y, a.z / b.z); } private static float FrontZ(Quaternion q, Vector3 centreRoot, Vector3 sizeRoot, Vector3 ls) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Vector3.Scale(centreRoot, ls); Vector3 val2 = Vector3.Scale(sizeRoot, ls) * 0.5f; return (q * val).z + Mathf.Abs((q * Vector3.right).z) * val2.x + Mathf.Abs((q * Vector3.up).z) * val2.y + Mathf.Abs((q * Vector3.forward).z) * val2.z; } internal static float Drop(VehicleController vc) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) Transform transform = ((Component)vc).transform; float num = float.MaxValue; WheelCollider[] array = Wheels(vc); foreach (WheelCollider val in array) { if (!((Object)(object)val == (Object)null)) { float num2 = Mathf.Abs(((Component)val).transform.lossyScale.y); num = Mathf.Min(num, transform.InverseTransformPoint(((Component)val).transform.position).y * transform.lossyScale.y - val.suspensionDistance * val.suspensionSpring.targetPosition * num2 - val.radius * num2); } } if (num != float.MaxValue) { return 0f - num; } return 0.55f; } [HarmonyPatch("DestroyCar")] [HarmonyPrefix] private static void DestroyCarPrefix(VehicleController __instance) { //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) Cart cart = Cart.Of(__instance); if ((Object)(object)cart == (Object)null || __instance.carDestroyed || Settings.Explode) { return; } SuppressExplosion = true; PlayerControllerB local = Cart.Local; if (!((Object)(object)local == (Object)null) && (__instance.localPlayerInControl || __instance.localPlayerInPassengerSeat || cart.LocalRear >= 0)) { local.CancelSpecialTriggerAnimations(); if (__instance.localPlayerInControl) { __instance.LoseControlOfVehicle(); } if (__instance.localPlayerInPassengerSeat) { __instance.OnPassengerExit(); } __instance.localPlayerInControl = false; __instance.localPlayerInPassengerSeat = false; __instance.SetVehicleCollisionForPlayer(true, local); Vector3 externalForces = local.externalForces; Vector3 val = ((Component)local).transform.position - ((Component)__instance).transform.position; local.externalForces = externalForces + (((Vector3)(ref val)).normalized * 4f + Vector3.up * 2f); } } [HarmonyPatch("DestroyCar")] [HarmonyFinalizer] private static void DestroyCarFinalizer(VehicleController __instance) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) if (SuppressExplosion) { SuppressExplosion = false; Cart cart = Cart.Of(__instance); if ((Object)(object)cart != (Object)null) { cart.RefreshSeats(); } if ((Object)(object)HUDManager.Instance != (Object)null && (Object)(object)cart != (Object)null && (cart.LocalRear >= 0 || Vector3.Distance(((Component)Cart.Local).transform.position, ((Component)__instance).transform.position) < 12f)) { HUDManager.Instance.DisplayTip("Golf Cart", "The cart broke down.", false, false, "LC_Tip1"); } } } } [HarmonyPatch] internal static class OtherPatches { [HarmonyPatch(typeof(Landmine), "SpawnExplosion")] [HarmonyPrefix] private static bool SpawnExplosion() { return !Patches.SuppressExplosion; } [HarmonyPatch(typeof(GrabbableObject), "GetPhysicsRegionOfDroppedObject")] [HarmonyPostfix] private static void DropRegion(GrabbableObject __instance, ref NetworkObject __result, ref Vector3 hitPoint) { Cap(__instance, ref __result, ref hitPoint); } [HarmonyPatch(typeof(GrabbableObject), "GetPhysicsRegionOfDroppedObjectSynced")] [HarmonyPostfix] private static void DropRegionSynced(GrabbableObject __instance, ref NetworkObject __result, ref Vector3 hitPoint) { Cap(__instance, ref __result, ref hitPoint); } private static void Cap(GrabbableObject item, ref NetworkObject result, ref Vector3 hitPoint) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) Cart cart = default(Cart); if (!((Object)(object)result == (Object)null) && ((Component)result).TryGetComponent<Cart>(ref cart) && !cart.HasRoomFor(item)) { result = null; hitPoint = Vector3.zero; if ((Object)(object)HUDManager.Instance != (Object)null && (Object)(object)item.playerHeldBy != (Object)null && (Object)(object)item.playerHeldBy == (Object)(object)Cart.Local) { HUDManager.Instance.DisplayTip("Golf Cart", $"Basket full ({Settings.BasketCapacity}/{Settings.BasketCapacity}).", false, false, "LC_Tip1"); } } } } public static class PluginInfo { public const string Guid = "daniel.lethalcompany.golfcart"; public const string Name = "GolfCart"; public const string Version = "0.1.0"; } [BepInPlugin("daniel.lethalcompany.golfcart", "GolfCart", "0.1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { internal static ManualLogSource Log; internal static ConfigEntry<int> Price; internal static ConfigEntry<float> TopSpeed; internal static ConfigEntry<float> ReverseSpeed; internal static ConfigEntry<int> BasketCapacity; internal static ConfigEntry<bool> SelfRighting; internal static ConfigEntry<bool> ExplodeAtZeroHp; internal static ConfigEntry<string> HornKey; internal static ConfigEntry<string> LightsKey; internal static ConfigEntry<bool> AutoLights; internal static bool InputUtilsLoaded; private readonly Harmony _harmony = new Harmony("daniel.lethalcompany.golfcart"); private void Awake() { //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Expected O, but got Unknown //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Expected O, but got Unknown //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; Price = ((BaseUnityPlugin)this).Config.Bind<int>("Cart (host)", "Price", 250, "Terminal price in credits (Daniel, q_de8519e4dc764a83). Applies the next time the terminal loads."); TopSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Cart (host)", "Top speed", 10f, new ConfigDescription("Metres per second going forward (10 is a little over sprinting).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(6f, 16f), Array.Empty<object>())); ReverseSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Cart (host)", "Reverse speed", 4f, new ConfigDescription("Metres per second in reverse.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 8f), Array.Empty<object>())); BasketCapacity = ((BaseUnityPlugin)this).Config.Bind<int>("Cart (host)", "Basket capacity", 12, new ConfigDescription("Items the basket holds (two-handed items count as 2).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(6, 24), Array.Empty<object>())); SelfRighting = ((BaseUnityPlugin)this).Config.Bind<bool>("Cart (host)", "Self-righting", true, "Puts the cart back on its wheels when it has lain on its side or roof for a moment."); ExplodeAtZeroHp = ((BaseUnityPlugin)this).Config.Bind<bool>("Cart (host)", "Explode at 0 HP", false, "Off: the cart breaks down, riders get off unhurt. On: it explodes like the Cruiser."); HornKey = ((BaseUnityPlugin)this).Config.Bind<string>("Keys", "Horn", "<Keyboard>/h", "Used when LethalCompany InputUtils isn't installed (with it, rebind in the game's keybind menu)."); LightsKey = ((BaseUnityPlugin)this).Config.Bind<string>("Keys", "Headlights", "<Keyboard>/l", "Used when LethalCompany InputUtils isn't installed."); AutoLights = ((BaseUnityPlugin)this).Config.Bind<bool>("Local", "Lights on when it's dark", true, "Switches the headlights on when you take the wheel at night or indoors."); InputUtilsLoaded = Chainloader.PluginInfos.ContainsKey("com.rune580.LethalCompanyInputUtils"); Keys.Init(); _harmony.PatchAll(typeof(Plugin).Assembly); Registry.Load(); if (Chainloader.PluginInfos.ContainsKey("daniel.lethalcompany.modmenu")) { MenuHooks.Register(); } Log.LogInfo((object)("GolfCart 0.1.0 loaded (InputUtils " + (InputUtilsLoaded ? "found" : "not found") + ").")); } } internal static class Registry { private sealed class Builder { private readonly GameObject _go; private readonly Transform _root; private readonly VehicleController _vc; private readonly Dictionary<string, Transform> _m = new Dictionary<string, Transform>(); private Transform _model; private readonly StringBuilder _log = new StringBuilder(); private Bounds _cruiserBox; private Bounds CartBox => new Bounds(P("M_Bounds"), Half("M_Bounds") * 2f); public Builder(GameObject go) { _go = go; _root = go.transform; _vc = go.GetComponent<VehicleController>(); } private Transform Find(string name) { return ((IEnumerable<Transform>)((Component)_root).GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == name)) ?? throw new Exception("part '" + name + "' not found on the Cruiser (game update?)"); } private Transform M(string name) { if (!_m.TryGetValue(name, out var value)) { throw new Exception("marker '" + name + "' missing from the model"); } return value; } private Vector3 P(string name) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) return M(name).position; } private Vector3 Half(string name) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) return M(name).localScale; } private static T Need<T>(T o, string what) where T : Object { if (!((Object)(object)o != (Object)null)) { throw new Exception("VehicleController." + what + " is empty"); } return o; } public void Run() { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) Need<VehicleController>(_vc, "(component)"); _cruiserBox = CruiserBox(); BoxCollider val = Need<BoxCollider>(_vc.boundsCollider, "boundsCollider"); CruiserBoundsCenter = _root.InverseTransformPoint(((Component)val).transform.TransformPoint(val.center)); CruiserBoundsSize = Vector3.Scale(val.size, Abs(Div(((Component)val).transform.lossyScale, _root.lossyScale))); CruiserDrop = (0f - _root.InverseTransformPoint(new Vector3(0f, WheelBottom(), 0f)).y) * _root.lossyScale.y; _model = Object.Instantiate<GameObject>(Model, _root, false).transform; ((Object)_model).name = "GolfCartModel"; _model.localPosition = Vector3.zero; _model.localRotation = Quaternion.identity; _model.localScale = Div(Vector3.one, _root.lossyScale); Transform[] componentsInChildren = ((Component)_model.Find("Markers")).GetComponentsInChildren<Transform>(true); foreach (Transform val2 in componentsInChildren) { _m[((Object)val2).name] = val2; } CartDrop = 0.55f; Squeeze(); HideCruiser(); Body(); Wheels(); Colliders(); Seats(); Regions(); Lights(); Misc(); Tune(); _go.AddComponent<Cart>().Setup(_vc, _model); Plugin.Log.LogInfo((object)("Golf Cart: built from the Cruiser.\n" + _log)); } private static Vector3 Div(Vector3 a, Vector3 b) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) return new Vector3(a.x / b.x, a.y / b.y, a.z / b.z); } private static Vector3 Abs(Vector3 a) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) return new Vector3(Mathf.Abs(a.x), Mathf.Abs(a.y), Mathf.Abs(a.z)); } private void Fit(BoxCollider c, Vector3 centre, Vector3 size, string what) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)c == (Object)null) { throw new Exception("no box collider for " + what); } Transform transform = ((Component)c).transform; if (Quaternion.Angle(transform.rotation, _root.rotation) > 0.5f) { transform.rotation = _root.rotation; } c.center = transform.InverseTransformPoint(centre); c.size = Div(size, Abs(transform.lossyScale)); _log.AppendLine($" {what}: centre {centre} size {size}"); } private void Put(Transform t, Vector3 pos, string what) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)t == (Object)null) { throw new Exception("no transform for " + what); } t.position = pos; t.rotation = _root.rotation; } private Bounds CruiserBox() { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) MeshFilter component = ((Component)Need<MeshRenderer>(_vc.mainBodyMesh, "mainBodyMesh")).GetComponent<MeshFilter>(); Bounds bounds = component.sharedMesh.bounds; Matrix4x4 localToWorldMatrix = ((Component)component).transform.localToWorldMatrix; Bounds result = default(Bounds); ((Bounds)(ref result))..ctor(((Matrix4x4)(ref localToWorldMatrix)).MultiplyPoint3x4(((Bounds)(ref bounds)).min), Vector3.zero); for (int i = 0; i < 8; i++) { ((Bounds)(ref result)).Encapsulate(((Matrix4x4)(ref localToWorldMatrix)).MultiplyPoint3x4(new Vector3(((i & 1) == 0) ? ((Bounds)(ref bounds)).min.x : ((Bounds)(ref bounds)).max.x, ((i & 2) == 0) ? ((Bounds)(ref bounds)).min.y : ((Bounds)(ref bounds)).max.y, ((i & 4) == 0) ? ((Bounds)(ref bounds)).min.z : ((Bounds)(ref bounds)).max.z))); } _log.AppendLine($" Cruiser body box {((Bounds)(ref result)).center} size {((Bounds)(ref result)).size}, root scale {_root.lossyScale}"); return result; } private float WheelBottom() { //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) float num = float.MaxValue; WheelCollider[] array = (WheelCollider[])(object)new WheelCollider[4] { _vc.FrontLeftWheel, _vc.FrontRightWheel, _vc.BackLeftWheel, _vc.BackRightWheel }; foreach (WheelCollider val in array) { Need<WheelCollider>(val, "wheel colliders"); num = Mathf.Min(num, ((Component)val).transform.position.y - val.suspensionDistance * val.suspensionSpring.targetPosition * ((Component)val).transform.lossyScale.y - val.radius * ((Component)val).transform.lossyScale.y); } return num; } private Vector3 Remap(Vector3 p) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) Bounds cruiserBox = _cruiserBox; Bounds cartBox = CartBox; Vector3 val = Div(p - ((Bounds)(ref cruiserBox)).min, ((Bounds)(ref cruiserBox)).size); return ((Bounds)(ref cartBox)).min + Vector3.Scale(val, ((Bounds)(ref cartBox)).size); } private void Squeeze() { //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_0206: Unknown result type (might be due to invalid IL or missing references) //IL_0220: Unknown result type (might be due to invalid IL or missing references) //IL_022a: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_0296: Unknown result type (might be due to invalid IL or missing references) List<Transform> list = new List<Transform>(); list.AddRange(from a in ((Component)_root).GetComponentsInChildren<AudioSource>(true) where (Object)(object)((Component)a).transform != (Object)(object)_root select ((Component)a).transform); list.AddRange(from p in ((Component)_root).GetComponentsInChildren<ParticleSystem>(true) select ((Component)p).transform); list.AddRange(from p in ((Component)_root).GetComponentsInChildren<ScanNodeProperties>(true) select ((Component)p).transform); list.AddRange(from c in ((Component)Find("CollisionTriggers")).GetComponentsInChildren<Collider>(true) select ((Component)c).transform); Transform val = Find("PushTrigger"); list.Add(val); list = list.Where((Transform t) => !t.IsChildOf(_model)).Distinct().ToList(); Dictionary<Transform, Vector3> dictionary = list.ToDictionary((Transform t) => t, (Transform t) => Remap(t.position)); foreach (Transform item in list.OrderBy((Transform t) => Depth(t))) { item.position = dictionary[item]; } Bounds cartBox = CartBox; Vector3 val2 = Div(((Bounds)(ref cartBox)).size, ((Bounds)(ref _cruiserBox)).size); Collider[] componentsInChildren = ((Component)Find("CollisionTriggers")).GetComponentsInChildren<Collider>(true); foreach (Collider val3 in componentsInChildren) { ((Component)val3).transform.localScale = Vector3.Scale(((Component)val3).transform.localScale, val2); } val.localScale = Vector3.Scale(val.localScale, new Vector3(1f, val2.y, val2.z)); ScanNodeProperties[] componentsInChildren2 = ((Component)_root).GetComponentsInChildren<ScanNodeProperties>(true); foreach (ScanNodeProperties obj in componentsInChildren2) { obj.headerText = "Golf Cart"; obj.subText = "Seats 4. Basket in the back."; } _log.AppendLine($" squeezed {list.Count} sounds, particles and triggers into the cart box (x{val2})"); } private static int Depth(Transform t) { int num = 0; while ((Object)(object)t.parent != (Object)null) { num++; t = t.parent; } return num; } private void HideCruiser() { int num = 0; Renderer[] componentsInChildren = ((Component)_root).GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if (!((Component)val).transform.IsChildOf(_model) && !(val is ParticleSystemRenderer)) { val.enabled = false; num++; } } LODGroup[] componentsInChildren2 = ((Component)_root).GetComponentsInChildren<LODGroup>(true); foreach (LODGroup val2 in componentsInChildren2) { if (!((Component)val2).transform.IsChildOf(_model)) { val2.enabled = false; } } int num2 = 0; InteractTrigger[] componentsInChildren3 = ((Component)_root).GetComponentsInChildren<InteractTrigger>(true); Collider[] components; foreach (InteractTrigger val3 in componentsInChildren3) { if (!((Object)(object)val3 == (Object)(object)_vc.driverSeatTrigger) && !((Object)(object)val3 == (Object)(object)_vc.passengerSeatTrigger)) { val3.interactable = false; components = ((Component)val3).GetComponents<Collider>(); for (int j = 0; j < components.Length; j++) { components[j].enabled = false; } num2++; } } components = ((Component)Find("InteractionBlockers")).GetComponentsInChildren<Collider>(true); for (int i = 0; i < components.Length; i++) { components[i].enabled = false; } components = ((Component)Find("WindshieldInteractBlocker")).GetComponentsInChildren<Collider>(true); for (int i = 0; i < components.Length; i++) { components[i].enabled = false; } _log.AppendLine($" hid {num} Cruiser renderers, switched off {num2} Cruiser controls"); } private void Body() { //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) MeshRenderer val = R("Body_LOD0"); MeshRenderer val2 = R("Body_LOD1"); MeshRenderer val3 = R("Body_LOD2"); ((Component)val2).transform.SetParent(((Component)val).transform, true); ((Component)val3).transform.SetParent(((Component)val).transform, true); LODGroup val4 = ((Component)_model).gameObject.AddComponent<LODGroup>(); val4.SetLODs((LOD[])(object)new LOD[3] { new LOD(0.35f, (Renderer[])(object)new Renderer[2] { (Renderer)val, (Renderer)R("SteeringWheel") }), new LOD(0.12f, (Renderer[])(object)new Renderer[1] { (Renderer)val2 }), new LOD(0.02f, (Renderer[])(object)new Renderer[1] { (Renderer)val3 }) }); val4.RecalculateBounds(); int layer = ((Component)_vc.mainBodyMesh).gameObject.layer; Transform[] componentsInChildren = ((Component)_model).GetComponentsInChildren<Transform>(true); for (int i = 0; i < componentsInChildren.Length; i++) { ((Component)componentsInChildren[i]).gameObject.layer = layer; } _vc.mainBodyMesh = val; _vc.lod1Mesh = val2; _vc.lod2Mesh = val3; GameObject gameObject = ((Component)_model.Find("Body_Wrecked")).gameObject; gameObject.SetActive(false); _vc.destroyedTruckMesh = gameObject; if ((Object)(object)_vc.windshieldBrokenMat == (Object)null) { _vc.windshieldBrokenMat = ((Renderer)val).sharedMaterials[2]; } MeshRenderer R(string n) { return ((Component)_model.Find(n)).GetComponent<MeshRenderer>(); } } private void Wheels() { //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) WheelCollider[] array = (WheelCollider[])(object)new WheelCollider[4] { _vc.FrontLeftWheel, _vc.FrontRightWheel, _vc.BackLeftWheel, _vc.BackRightWheel }; string[] array2 = new string[4] { "leftWheelMesh", "rightWheelMesh", "backLeftWheelMesh", "backRightWheelMesh" }; for (int i = 0; i < 4; i++) { WheelCollider obj = Need<WheelCollider>(array[i], "wheel colliders"); bool flag = i < 2; string text = string.Concat(str1: (((Component)obj).transform.position.x < 0f) ? "L" : "R", str0: flag ? "F" : "B"); Vector3 val = P("M_Wheel_" + text); float num = Mathf.Abs(((Component)obj).transform.lossyScale.y); ((Component)obj).transform.position = val + Vector3.up * 0.125f; obj.radius = 0.36f / num; obj.suspensionDistance = 0.25f / num; obj.center = Vector3.zero; MeshRenderer component = ((Component)_model.Find("Wheel_" + text)).GetComponent<MeshRenderer>(); AccessTools.Field(typeof(VehicleController), array2[i]).SetValue(_vc, component); } if (_vc.otherWheels != null) { WheelCollider[] otherWheels = _vc.otherWheels; foreach (WheelCollider val2 in otherWheels) { if ((Object)(object)val2 != (Object)null) { ((Collider)val2).enabled = false; } } } StringBuilder log = _log; object arg = 0.36f; object arg2 = 0.25f; WheelCollider[] otherWheels2 = _vc.otherWheels; log.AppendLine($" wheels: radius {arg}, suspension {arg2}, {((otherWheels2 != null) ? otherWheels2.Length : 0)} belly wheels off"); } private void Colliders() { //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) Collider[] components = ((Component)_root).GetComponents<Collider>(); PhysicMaterial sharedMaterial = components.Select((Collider c) => c.sharedMaterial).FirstOrDefault((Func<PhysicMaterial, bool>)((PhysicMaterial m) => (Object)(object)m != (Object)null)); Collider[] array = components; for (int num = 0; num < array.Leng