using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using CompanyCruiserConfig.Patches; using CompanyCruiserConfig.Utils; using HarmonyLib; using Microsoft.CodeAnalysis; using Unity.Netcode; using UnityEngine; [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("Tomatobird.CompanyCruiserConfig")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("0.1.2.0")] [assembly: AssemblyInformationalVersion("0.1.2+190d9b18f2d11f2b042ea925ddb7e3164ad54243")] [assembly: AssemblyProduct("CompanyCruiserConfig")] [assembly: AssemblyTitle("Tomatobird.CompanyCruiserConfig")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.1.2.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [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 CompanyCruiserConfig { [BepInPlugin("Tomatobird.CompanyCruiserConfig", "CompanyCruiserConfig", "0.1.2")] public class CompanyCruiserConfig : BaseUnityPlugin { public static ConfigEntry editRigidbody; public static ConfigEntry despawnInVoid; public static ConfigEntry despawnInSky; public static ConfigEntry despawnDepthThreshold; public static ConfigEntry despawnHeightThreshold; public static ConfigEntry editEnemyCollisionDamage; public static ConfigEntry baseCarHP; public static ConfigEntry brakeSpeed; public static ConfigEntry carAcceleration; public static ConfigEntry carFragility; public static ConfigEntry carHitPlayerForceFraction; public static ConfigEntry carMaxSpeed; public static ConfigEntry carReactToPlayerHitMultiplier; public static ConfigEntry engineIntensityPercentage; public static ConfigEntry engineTorque; public static ConfigEntry idleSpeed; public static ConfigEntry jumpForce; public static ConfigEntry maxEngineRPM; public static ConfigEntry maximumBumpForce; public static ConfigEntry mediumBumpForce; public static ConfigEntry minEngineRPM; public static ConfigEntry minimalBumpForce; public static ConfigEntry movingAverageLength; public static ConfigEntry pushForceMultiplier; public static ConfigEntry pushVerticalOffsetAmount; public static ConfigEntry radioSignalDecreaseThreshold; public static ConfigEntry radioSignalQuality; public static ConfigEntry radioSignalTurbulence; public static ConfigEntry speed; public static ConfigEntry springForce; public static ConfigEntry stability; public static ConfigEntry steeringWheelTurnSpeed; public static ConfigEntry syncRotationSpeed; public static ConfigEntry syncSpeedMultiplier; public static ConfigEntry torqueForce; public static ConfigEntry turboBoostForce; public static ConfigEntry turboBoostUpwardForce; public static ConfigEntry angularDrag; public static ConfigEntry drag; public static ConfigEntry mass; public static ConfigEntry maxAngularVelocity; public static ConfigEntry maxDepenetrationVelocity; public static ConfigEntry maxLinearVelocity; public static ConfigEntry sleepThreshold; public static ConfigEntry solverIterations; public static ConfigEntry solverVelocityIterations; public static ConfigEntry smallHit; public static ConfigEntry largeHit; public static CompanyCruiserConfig Instance { get; private set; } internal static ManualLogSource Logger { get; private set; } internal static Harmony? Harmony { get; set; } private void Awake() { Logger = ((BaseUnityPlugin)this).Logger; Instance = this; InitializeConfigs(); Patch(); Logger.LogInfo((object)"Tomatobird.CompanyCruiserConfig v0.1.2 has loaded!"); } internal void InitializeConfigs() { editRigidbody = ((BaseUnityPlugin)this).Config.Bind("General", "Edit Rigidbody", false, "Should configuration for the main rigidbody in VehicleController be enabled?"); despawnInVoid = ((BaseUnityPlugin)this).Config.Bind("General", "Despawn In Void", true, "Should any VehicleController object that goes below Despawn Depth Threshold be despawned? This check runs in FixedUpdate()"); despawnInSky = ((BaseUnityPlugin)this).Config.Bind("General", "Despawn In Sky", true, "Should any VehicleController object that goes above Despawn Height Threshold be despawned? This check runs in FixedUpdate()"); despawnDepthThreshold = ((BaseUnityPlugin)this).Config.Bind("General", "Despawn Depth Threshold", -500f, "Threshold where any VehicleController object below this height will be despawned."); despawnHeightThreshold = ((BaseUnityPlugin)this).Config.Bind("General", "Despawn Height Threshold", 9999f, "Threshold where any VehicleController object above this height will be despawned."); editEnemyCollisionDamage = ((BaseUnityPlugin)this).Config.Bind("General", "Edit Enemy Collision Damage", false, "Should configuration of enemy collision damage values be enabled?"); baseCarHP = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Base Car HP", 30, "Initial car hp."); brakeSpeed = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Brake Speed", 500f, "Vehicle braking speed."); carAcceleration = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Car Acceleration", 250f, ""); carFragility = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Car Fragility", 1f, ""); carHitPlayerForceFraction = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Car Hit Player Force Fraction", 30f, ""); carMaxSpeed = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Car Max Speed", 600f, ""); carReactToPlayerHitMultiplier = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Car React To Player Hit Multiplier", 2850f, ""); engineIntensityPercentage = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Engine Intensity Percentage", 180f, ""); engineTorque = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Engine Torque", 1100f, ""); idleSpeed = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Idle Speed", 15f, ""); jumpForce = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Jump Force", 600f, ""); maxEngineRPM = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Max Engine RPM", 3000f, ""); maximumBumpForce = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Maximum Bump Force", 75000f, ""); mediumBumpForce = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Medium Bump Force", 30000f, ""); minEngineRPM = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Min Engine RPM", 1000f, ""); minimalBumpForce = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Minimal Bump Force", 9000f, ""); movingAverageLength = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Moving Average Length", 20, ""); pushForceMultiplier = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Push Force Multiplier", 27f, "Multiplier of the force to push the cruiser."); pushVerticalOffsetAmount = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Push Vertical Offset Amount", 1f, ""); radioSignalDecreaseThreshold = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Radio Signal Decrease Threshold", 50f, ""); radioSignalQuality = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Radio Signal Quality", 3f, ""); radioSignalTurbulence = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Radio Signal Turbulence", 4f, ""); speed = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Speed", 50f, ""); springForce = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Spring Force", 130f, ""); stability = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Stability", 0.4f, ""); steeringWheelTurnSpeed = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Steering Wheel Turn Speed", 4f, ""); syncRotationSpeed = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Sync Rotation Speed", 0.2f, ""); syncSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Sync Speed Multiplier", 10f, ""); torqueForce = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Torque Force", 2.5f, ""); turboBoostForce = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Turbo Boost Force", 3000f, ""); turboBoostUpwardForce = ((BaseUnityPlugin)this).Config.Bind("VehicleController", "Turbo Boost Upward Force", 7200f, ""); angularDrag = ((BaseUnityPlugin)this).Config.Bind("Rigidbody", "Angular Drag", 0.5f, ""); drag = ((BaseUnityPlugin)this).Config.Bind("Rigidbody", "Drag", 0.01f, ""); mass = ((BaseUnityPlugin)this).Config.Bind("Rigidbody", "Mass", 200f, ""); maxAngularVelocity = ((BaseUnityPlugin)this).Config.Bind("Rigidbody", "Max Angular Velocity", 4f, ""); maxDepenetrationVelocity = ((BaseUnityPlugin)this).Config.Bind("Rigidbody", "Max Depenetration Velocity", 1f, ""); maxLinearVelocity = ((BaseUnityPlugin)this).Config.Bind("Rigidbody", "Max Linear Velocity", 50f, ""); sleepThreshold = ((BaseUnityPlugin)this).Config.Bind("Rigidbody", "Sleep Threshold", 0.005f, ""); solverIterations = ((BaseUnityPlugin)this).Config.Bind("Rigidbody", "Solver Iterations", 16, ""); solverVelocityIterations = ((BaseUnityPlugin)this).Config.Bind("Rigidbody", "Solver Velocity Iterations", 2, ""); smallHit = ((BaseUnityPlugin)this).Config.Bind("Collision", "Small Hit", 2, ""); largeHit = ((BaseUnityPlugin)this).Config.Bind("Collision", "Large Hit", 12, ""); } internal static void Patch() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown if (Harmony == null) { Harmony = new Harmony("Tomatobird.CompanyCruiserConfig"); } Logger.LogDebug((object)"Patching..."); Harmony.PatchAll(typeof(VehicleControllerPatch)); Harmony.PatchAll(typeof(RegisterNetworkPrefabPatch)); if (despawnInVoid.Value) { Harmony.PatchAll(typeof(VehicleControllerDestroyCruiserDepthPatch)); } if (despawnInSky.Value) { Harmony.PatchAll(typeof(VehicleControllerDestroyCruiserHeightPatch)); } if (editEnemyCollisionDamage.Value) { Harmony.PatchAll(typeof(CarReactToObstaclePatch)); } Logger.LogDebug((object)"Finished patching!"); } internal static void Unpatch() { Logger.LogDebug((object)"Unpatching..."); Harmony? harmony = Harmony; if (harmony != null) { harmony.UnpatchSelf(); } Logger.LogDebug((object)"Finished unpatching!"); } } public static class MyPluginInfo { public const string PLUGIN_GUID = "Tomatobird.CompanyCruiserConfig"; public const string PLUGIN_NAME = "CompanyCruiserConfig"; public const string PLUGIN_VERSION = "0.1.2"; } } namespace CompanyCruiserConfig.Utils { internal class DestroyObject : MonoBehaviour { private void Awake() { Object.Destroy((Object)(object)((Component)this).gameObject); } } } namespace CompanyCruiserConfig.Patches { [HarmonyPatch(typeof(VehicleController))] internal class CarReactToObstaclePatch { [HarmonyPatch("CarReactToObstacle")] [HarmonyTranspiler] public static IEnumerable CarReactToObstacleTranspiler(IEnumerable instructions) { CompanyCruiserConfig.Logger.LogDebug((object)"Running CarReactToObstacleTranspiler to patch damage values."); int num = -1; int num2 = 150; List list = new List(instructions); for (int i = num2; i < list.Count; i++) { if (list[i - 2].opcode == OpCodes.Ldarg_S && list[i - 1].opcode == OpCodes.Ldc_I4_2 && list[i].opcode == OpCodes.Ldarg_0) { num = i - 1; num2 = num; break; } } if (num > -1) { list[num].opcode = OpCodes.Ldc_I4_S; list[num].operand = (sbyte)CompanyCruiserConfig.smallHit.Value; CompanyCruiserConfig.Logger.LogDebug((object)$"opcode at index {num} replaced"); } else { CompanyCruiserConfig.Logger.LogError((object)"CarReactToObstacleTranspiler failed on first inject."); } num = -1; for (int j = num2; j < list.Count; j++) { if (list[j - 2].opcode == OpCodes.Ldarg_S && list[j - 1].opcode == OpCodes.Ldc_I4_S && list[j].opcode == OpCodes.Ldloc_3) { num = j - 1; break; } } if (num > -1) { list[num].operand = (sbyte)CompanyCruiserConfig.largeHit.Value; CompanyCruiserConfig.Logger.LogDebug((object)$"opcode at index {num} replaced"); } else { CompanyCruiserConfig.Logger.LogError((object)"CarReactToObstacleTranspiler failed on second inject."); } return list.AsEnumerable(); } } [HarmonyPatch(typeof(NetworkManager))] internal static class RegisterNetworkPrefabPatch { private static readonly string MOD_GUID = "Tomatobird.CompanyCruiserConfig"; [HarmonyPatch("SetSingleton")] [HarmonyPostfix] private static void RegisterPrefab() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown //IL_0018: 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) GameObject val = new GameObject(MOD_GUID + " Prefab"); ((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x3D); Object.DontDestroyOnLoad((Object)(object)val); NetworkObject obj = val.AddComponent(); FieldInfo field = typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic); field.SetValue(obj, GetHash(MOD_GUID)); NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(val); static uint GetHash(string value) { return value?.Aggregate(17u, (uint current, char c) => (current * 31) ^ c) ?? 0; } } } [HarmonyPatch(typeof(VehicleController))] internal class VehicleControllerDestroyCruiserDepthPatch { [HarmonyPatch("FixedUpdate")] [HarmonyPostfix] private static void FixedUpdate_Postfix(VehicleController __instance) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) if (((Component)__instance).transform.position.y < CompanyCruiserConfig.despawnDepthThreshold.Value) { __instance.OnDisable(); ((Component)__instance).gameObject.AddComponent(); } } } [HarmonyPatch(typeof(VehicleController))] internal class VehicleControllerDestroyCruiserHeightPatch { [HarmonyPatch("FixedUpdate")] [HarmonyPostfix] private static void FixedUpdate_Postfix(VehicleController __instance) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) if (((Component)__instance).transform.position.y > CompanyCruiserConfig.despawnHeightThreshold.Value) { __instance.OnDisable(); ((Component)__instance).gameObject.AddComponent(); } } } [HarmonyPatch(typeof(VehicleController))] internal class VehicleControllerPatch { [HarmonyPatch("Start")] [HarmonyPrefix] private static void StartPrefix(VehicleController __instance) { __instance.baseCarHP = CompanyCruiserConfig.baseCarHP.Value; } [HarmonyPatch("Start")] [HarmonyPostfix] private static void StartPostfix(VehicleController __instance) { __instance.brakeSpeed = CompanyCruiserConfig.brakeSpeed.Value; __instance.carAcceleration = CompanyCruiserConfig.carAcceleration.Value; __instance.carFragility = CompanyCruiserConfig.carFragility.Value; __instance.carHitPlayerForceFraction = CompanyCruiserConfig.carHitPlayerForceFraction.Value; __instance.carMaxSpeed = CompanyCruiserConfig.carMaxSpeed.Value; __instance.carReactToPlayerHitMultiplier = CompanyCruiserConfig.carReactToPlayerHitMultiplier.Value; __instance.engineIntensityPercentage = CompanyCruiserConfig.engineIntensityPercentage.Value; __instance.EngineTorque = CompanyCruiserConfig.engineTorque.Value; __instance.idleSpeed = CompanyCruiserConfig.idleSpeed.Value; __instance.jumpForce = CompanyCruiserConfig.jumpForce.Value; __instance.MaxEngineRPM = CompanyCruiserConfig.maxEngineRPM.Value; __instance.maximumBumpForce = CompanyCruiserConfig.maximumBumpForce.Value; __instance.mediumBumpForce = CompanyCruiserConfig.mediumBumpForce.Value; __instance.MinEngineRPM = CompanyCruiserConfig.minEngineRPM.Value; __instance.minimalBumpForce = CompanyCruiserConfig.minimalBumpForce.Value; __instance.movingAverageLength = CompanyCruiserConfig.movingAverageLength.Value; __instance.pushForceMultiplier = CompanyCruiserConfig.pushForceMultiplier.Value; __instance.pushVerticalOffsetAmount = CompanyCruiserConfig.pushVerticalOffsetAmount.Value; __instance.radioSignalDecreaseThreshold = CompanyCruiserConfig.radioSignalDecreaseThreshold.Value; __instance.radioSignalQuality = CompanyCruiserConfig.radioSignalQuality.Value; __instance.radioSignalTurbulence = CompanyCruiserConfig.radioSignalTurbulence.Value; __instance.speed = CompanyCruiserConfig.speed.Value; __instance.springForce = CompanyCruiserConfig.springForce.Value; __instance.stability = CompanyCruiserConfig.stability.Value; __instance.steeringWheelTurnSpeed = CompanyCruiserConfig.steeringWheelTurnSpeed.Value; __instance.syncRotationSpeed = CompanyCruiserConfig.syncRotationSpeed.Value; __instance.syncSpeedMultiplier = CompanyCruiserConfig.syncSpeedMultiplier.Value; __instance.torqueForce = CompanyCruiserConfig.torqueForce.Value; __instance.turboBoostForce = CompanyCruiserConfig.turboBoostForce.Value; __instance.turboBoostUpwardForce = CompanyCruiserConfig.turboBoostUpwardForce.Value; if (CompanyCruiserConfig.editRigidbody.Value) { __instance.mainRigidbody.angularDrag = CompanyCruiserConfig.angularDrag.Value; __instance.mainRigidbody.drag = CompanyCruiserConfig.drag.Value; __instance.mainRigidbody.mass = CompanyCruiserConfig.mass.Value; __instance.mainRigidbody.maxAngularVelocity = CompanyCruiserConfig.maxAngularVelocity.Value; __instance.mainRigidbody.maxDepenetrationVelocity = CompanyCruiserConfig.maxDepenetrationVelocity.Value; __instance.mainRigidbody.maxLinearVelocity = CompanyCruiserConfig.maxLinearVelocity.Value; __instance.mainRigidbody.sleepThreshold = CompanyCruiserConfig.sleepThreshold.Value; __instance.mainRigidbody.solverIterations = CompanyCruiserConfig.solverIterations.Value; __instance.mainRigidbody.solverVelocityIterations = CompanyCruiserConfig.solverVelocityIterations.Value; } } [HarmonyPatch("PushTruckWithArms")] [HarmonyPrefix] private static void PushTruckWithForcePatch(VehicleController __instance) { __instance.pushForceMultiplier = CompanyCruiserConfig.pushForceMultiplier.Value; } [HarmonyPatch("PushTruckClientRpc")] [HarmonyPrefix] private static void PushTruckClientRpcPatch(VehicleController __instance) { __instance.pushForceMultiplier = CompanyCruiserConfig.pushForceMultiplier.Value; } } }