using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using CarCompany.Patches;
using CarCompany.Scripts;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using RuntimeNetcodeRPCValidator;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CarCompany")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A Car mod for Lethal Company")]
[assembly: AssemblyFileVersion("0.6.1.0")]
[assembly: AssemblyInformationalVersion("0.6.1+3df898ac10003b1973de78d3e79dec0f5ece803d")]
[assembly: AssemblyProduct("CarCompany")]
[assembly: AssemblyTitle("CarCompany")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.6.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace CarCompany
{
public class MervusNetworkHandler : NetworkBehaviour
{
public GameObject CarGameObject = null;
private PlayerControllerB localPlayer;
private void Update()
{
if (((NetworkBehaviour)this).IsOwner)
{
if ((Object)(object)localPlayer == (Object)null)
{
localPlayer = StartOfRound.Instance.localPlayerController;
}
if (((ButtonControl)Keyboard.current[(Key)101]).wasPressedThisFrame)
{
CarModBase.Logger.LogInfo((object)localPlayer.playerUsername);
SpawnCarServerRpc(localPlayer.playerClientId);
CarModBase.Logger.LogInfo((object)"Calling Server Spawn Car");
}
}
}
private Vector3 CarSpawnPosition(ulong clientId)
{
//IL_0018: 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_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
Vector3 position = ((Component)StartOfRound.Instance.allPlayerScripts[clientId]).gameObject.transform.position;
position.x += 2f;
position.y += 2f;
return position;
}
[ClientRpc]
private void SpawnCarClientRpc(ulong clientId)
{
}
[ServerRpc(RequireOwnership = false)]
public void SpawnCarServerRpc(ulong clientId)
{
//IL_002c: 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_00d1: 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)
CarModBase.Logger.LogInfo((object)"SpawnCarServerRpc");
if ((Object)(object)CarGameObject == (Object)null)
{
GameObject val = Object.Instantiate<GameObject>(CarModBase.FiatPrefab, CarSpawnPosition(clientId), new Quaternion(0f, 0f, 0f, 0f));
((Component)val.transform.GetChild(0).Find("WheelColliders")).gameObject.AddComponent<WheelController>();
((Component)val.transform.Find("PlayerOnCarHandler")).gameObject.AddComponent<HandlePlayerOnCar>();
val.GetComponent<NetworkObject>().Spawn(false);
val.SetActive(true);
CarGameObject = val;
}
else if (clientId == CarGameObject.GetComponent<NetworkObject>().OwnerClientId)
{
CarGameObject.transform.position = CarSpawnPosition(clientId);
CarGameObject.transform.rotation = Quaternion.identity;
}
CarModBase.Logger.LogInfo((object)("Spawned Car on Client" + StartOfRound.Instance.allPlayerScripts[clientId].playerUsername));
SpawnCarClientRpc(clientId);
}
[ServerRpc]
public void DespawnCarServerRpc()
{
CarGameObject.GetComponent<NetworkObject>().Despawn(true);
CarGameObject = null;
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "Mervus.CarCompany";
public const string PLUGIN_NAME = "CarCompany";
public const string PLUGIN_VERSION = "0.6.1";
}
[BepInPlugin("Mervus.CarCompany", "CarCompany", "0.6.1")]
[BepInDependency("NicholaScott.BepInEx.RuntimeNetcodeRPCValidator", "0.2.5")]
internal class CarModBase : BaseUnityPlugin
{
private readonly Harmony _harmony = new Harmony("Mervus.CarCompany");
internal static CarModBase Instance;
private NetcodeValidator netcodeValidator;
internal static AssetBundle Bundle;
internal static GameObject FiatPrefab;
internal static ManualLogSource Logger { get; private set; }
private void Awake()
{
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_014d: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
_harmony.PatchAll(typeof(CarModBase));
_harmony.PatchAll(typeof(PlayerControllerBPatch));
_harmony.PatchAll(typeof(NetworkManagerPatch));
_harmony.PatchAll(typeof(StartOfRound));
FiatPrefab = null;
string location = ((BaseUnityPlugin)Instance).Info.Location;
location = location.TrimEnd("CarCompany.dll".ToCharArray());
Logger.LogInfo((object)("CarMod: Folder location " + location));
Bundle = AssetBundle.LoadFromFile(location + "fiat");
if ((Object)(object)Bundle != (Object)null)
{
FiatPrefab = Bundle.LoadAsset<GameObject>("assets/fiat.prefab");
Logger.LogInfo((object)("Successfully loaded bundle, " + (object)FiatPrefab));
}
else
{
Logger.LogError((object)"Asset Bundle could not be loaded");
}
Logger.LogInfo((object)"Plugin Mervus.CarCompany is loaded!");
netcodeValidator = new NetcodeValidator("Mervus.CarCompany");
netcodeValidator.PatchAll();
netcodeValidator.BindToPreExistingObjectByBehaviour<HandlePlayerOnCar, PlayerControllerB>();
netcodeValidator.BindToPreExistingObjectByBehaviour<MervusNetworkHandler, StartOfRound>();
}
}
}
namespace CarCompany.Scripts
{
public class HandlePlayerOnCar : NetworkBehaviour
{
private void OnTriggerEnter(Collider collision)
{
if ((((NetworkBehaviour)this).IsOwner || ((NetworkBehaviour)this).IsLocalPlayer) && ((Object)((Component)collision).gameObject).name == "PlayerOnCarHandler")
{
CarModBase.Logger.LogInfo((object)"Entering Car Trigger");
AttachPlayerToCarServerRpc(((NetworkBehaviour)this).OwnerClientId, ((Component)collision).gameObject.GetComponentInParent<NetworkObject>().NetworkObjectId);
}
}
private void OnTriggerExit(Collider collision)
{
if ((((NetworkBehaviour)this).IsOwner || ((NetworkBehaviour)this).IsLocalPlayer) && ((Object)((Component)collision).gameObject).name == "PlayerOnCarHandler")
{
CarModBase.Logger.LogInfo((object)"Exiting Car Trigger");
DetachPlayerFromCarServerRpc(((NetworkBehaviour)this).OwnerClientId, ((Component)collision).gameObject.GetComponentInParent<NetworkObject>().NetworkObjectId);
}
}
[ServerRpc(RequireOwnership = false)]
private void AttachPlayerToCarServerRpc(ulong senderId, ulong carNetworkId)
{
AttachPlayerToCarClientRpc(senderId, carNetworkId);
}
[ServerRpc(RequireOwnership = false)]
private void DetachPlayerFromCarServerRpc(ulong senderId, ulong carNetworkId)
{
DetachPlayerFromCarClientRpc(senderId, carNetworkId);
}
[ClientRpc]
private void AttachPlayerToCarClientRpc(ulong senderId, ulong carNetworkId)
{
PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[senderId];
if ((Object)(object)val == (Object)null)
{
CarModBase.Logger.LogError((object)"AttachPlayerToCarServerRpc: playerController is null");
return;
}
GameObject gameObject = ((Component)((NetworkBehaviour)this).GetNetworkObject(carNetworkId)).gameObject;
((Component)this).transform.parent = gameObject.transform;
}
[ClientRpc]
private void DetachPlayerFromCarClientRpc(ulong senderId, ulong carNetworkId)
{
PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[senderId];
((Component)val).transform.parent = StartOfRound.Instance.playersContainer;
}
}
public class PlayerCarUtil : NetworkBehaviour
{
}
public class WheelController : MonoBehaviour
{
private WheelCollider frontRight;
private WheelCollider frontLeft;
private WheelCollider backRight;
private WheelCollider backLeft;
public float acceleration = 500f;
public float breakingForce = 300f;
public float maxTurnAngle = 15f;
private float currentAcceleration = 0f;
private float currentBrakeForce = 0f;
private float currentTurnAngle = 0f;
private void Start()
{
WheelCollider[] componentsInChildren = ((Component)this).GetComponentsInChildren<WheelCollider>();
Debug.Log((object)componentsInChildren.Length);
if (componentsInChildren.Length != 4)
{
Debug.Log((object)"Error could not find every wheel");
return;
}
WheelCollider[] array = componentsInChildren;
foreach (WheelCollider val in array)
{
Debug.Log((object)((Object)((Component)val).gameObject).name);
switch (((Object)((Component)val).gameObject).name)
{
case "FrontRightCollider":
frontRight = val;
break;
case "FrontLeftCollider":
frontLeft = val;
break;
case "BackRightCollider":
backRight = val;
break;
case "BackLeftCollider":
backLeft = val;
break;
}
}
}
private void FixedUpdate()
{
currentAcceleration = acceleration * GetVerticalAxis();
if (((ButtonControl)Keyboard.current[(Key)52]).isPressed)
{
currentBrakeForce = breakingForce;
}
else
{
currentBrakeForce = 0f;
}
frontRight.motorTorque = currentAcceleration;
frontLeft.motorTorque = currentAcceleration;
frontRight.brakeTorque = currentBrakeForce;
frontLeft.brakeTorque = currentBrakeForce;
backRight.brakeTorque = currentBrakeForce;
backLeft.brakeTorque = currentBrakeForce;
currentTurnAngle = maxTurnAngle * GetHorizontalAxis();
frontLeft.steerAngle = currentTurnAngle;
frontRight.steerAngle = currentTurnAngle;
}
public float GetVerticalAxis()
{
if (((ButtonControl)Keyboard.current[(Key)63]).isPressed)
{
return 1f;
}
if (((ButtonControl)Keyboard.current[(Key)64]).isPressed)
{
return -1f;
}
return 0f;
}
public float GetHorizontalAxis()
{
if (((ButtonControl)Keyboard.current[(Key)61]).isPressed)
{
return -1f;
}
if (((ButtonControl)Keyboard.current[(Key)62]).isPressed)
{
return 1f;
}
return 0f;
}
}
}
namespace CarCompany.Patches
{
[HarmonyPatch(typeof(GameNetworkManager))]
internal class NetworkManagerPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void patchStart(ref GameNetworkManager __instance)
{
CarModBase.Logger.LogInfo((object)"Adding CarModBase to NetworkPrefab List.");
NetworkManager.Singleton.AddNetworkPrefab(CarModBase.FiatPrefab);
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
}
[HarmonyPatch(typeof(StartOfRound))]
public class StartOfRoundPatch
{
[HarmonyPatch("ShipLeave")]
[HarmonyPostfix]
private static void patchShipLeave(ref StartOfRound __instance)
{
MervusNetworkHandler component = ((Component)__instance).gameObject.GetComponent<MervusNetworkHandler>();
if ((Object)(object)component == (Object)null)
{
CarModBase.Logger.LogError((object)"Could not find MervusNetworkHandler");
}
else
{
component.DespawnCarServerRpc();
}
}
}
}