using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;
[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("EasyDrift")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EasyDrift")]
[assembly: AssemblyTitle("EasyDrift")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace EasyDrift;
[HarmonyPatch(typeof(sCarController), "ApplyFriction")]
public static class DriftPatch
{
private struct Stock
{
public float MaxSpeed;
public float MaxDrivePower;
}
private const float BrakeThreshold = -0.1f;
private const float TurnThreshold = 0.4f;
private const float MinDriftSpeed = 4f;
private const float RearGripScale = 0.3f;
private const float FrontGripScale = 2f;
private const float SpeedBoost = 1.5f;
private const float PowerBoost = 2f;
private const float VfxEmissionBoost = 3f;
private const float VfxSmokeAlpha = 0.9f;
private static readonly Dictionary<sCarController, Stock> stockValues = new Dictionary<sCarController, Stock>();
private static readonly FieldRef<sCarController, bool> breakingField = AccessTools.FieldRefAccess<sCarController, bool>("breaking");
internal static bool IsDrifting(sCarController car)
{
//IL_004d: 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)
bool num = car.input.y < -0.1f || breakingField.Invoke(car);
bool flag = Mathf.Abs(car.input.x) > 0.4f;
int num2;
if ((Object)(object)car.rb != (Object)null)
{
Vector3 linearVelocity = car.rb.linearVelocity;
num2 = ((((Vector3)(ref linearVelocity)).magnitude > 4f) ? 1 : 0);
}
else
{
num2 = 0;
}
bool flag2 = (byte)num2 != 0;
return num && flag && flag2;
}
private static bool IsRear(sCarController car, Wheel wheel)
{
Wheel[] wheels = car.wheels;
if (wheels != null)
{
for (int i = 0; i < wheels.Length; i++)
{
if (wheels[i] == wheel)
{
return i > 1;
}
}
}
return !wheel.steering;
}
[HarmonyPrefix]
public static void Prefix(sCarController __instance, Wheel wheel, out float __state)
{
__state = float.NaN;
if (!stockValues.TryGetValue(__instance, out var value))
{
Stock stock = default(Stock);
stock.MaxSpeed = __instance.maxSpeed;
stock.MaxDrivePower = __instance.maxDrivePower;
value = stock;
stockValues[__instance] = value;
}
if (IsDrifting(__instance))
{
__instance.maxSpeed = value.MaxSpeed * 1.5f;
__instance.maxDrivePower = value.MaxDrivePower * 2f;
__state = wheel.maxFrictionForce;
wheel.maxFrictionForce *= (IsRear(__instance, wheel) ? 0.3f : 2f);
}
else
{
__instance.maxSpeed = value.MaxSpeed;
__instance.maxDrivePower = value.MaxDrivePower;
}
}
[HarmonyPostfix]
public static void Postfix(sCarController __instance, Wheel wheel, float __state)
{
//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_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_004b: 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)
//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_0068: 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_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: 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_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: 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)
if (!float.IsNaN(__state))
{
wheel.maxFrictionForce = __state;
}
if (IsDrifting(__instance))
{
EmissionModule emission = wheel.dustParticles.emission;
MinMaxCurve rateOverDistance = ((EmissionModule)(ref emission)).rateOverDistance;
((EmissionModule)(ref emission)).rateOverDistance = MinMaxCurve.op_Implicit(((MinMaxCurve)(ref rateOverDistance)).constant * 3f);
EmissionModule emission2 = wheel.snowSkidParticles.emission;
rateOverDistance = ((EmissionModule)(ref emission2)).rateOverDistance;
((EmissionModule)(ref emission2)).rateOverDistance = MinMaxCurve.op_Implicit(((MinMaxCurve)(ref rateOverDistance)).constant * 3f);
if (IsRear(__instance, wheel))
{
MainModule main = wheel.skidParticles.main;
MinMaxGradient startColor = ((MainModule)(ref main)).startColor;
Color color = ((MinMaxGradient)(ref startColor)).color;
color.a = Mathf.Max(color.a, 0.9f);
((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(color);
}
}
}
}
[HarmonyPatch(typeof(sCarController), "Move")]
public static class DriftStabilizer
{
private const float MaxDriftAngle = 45f;
private const float MaxYawRate = 2.2f;
private const float CounterAssist = 6f;
private const float DriftGrip = 4f;
[HarmonyPostfix]
public static void Postfix(sCarController __instance)
{
//IL_001b: 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_003d: 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_0045: 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_0066: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: 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_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: 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)
if (!DriftPatch.IsDrifting(__instance))
{
return;
}
Rigidbody rb = __instance.rb;
if ((Object)(object)rb == (Object)null)
{
return;
}
Vector3 linearVelocity = rb.linearVelocity;
linearVelocity.y = 0f;
if (!(((Vector3)(ref linearVelocity)).magnitude < 1f))
{
Vector3 angularVelocity = rb.angularVelocity;
angularVelocity.y = Mathf.Clamp(angularVelocity.y, -2.2f, 2.2f);
float num = Vector3.SignedAngle(linearVelocity, ((Component)__instance).transform.forward, Vector3.up);
if (Mathf.Abs(num) > 45f)
{
float num2 = Mathf.Abs(num) - 45f;
float num3 = (0f - Mathf.Sign(num)) * num2 * (MathF.PI / 180f) * 6f;
angularVelocity.y = Mathf.Clamp(angularVelocity.y + num3 * Time.deltaTime, -2.2f, 2.2f);
}
rb.angularVelocity = angularVelocity;
float magnitude = ((Vector3)(ref linearVelocity)).magnitude;
Vector3 forward = ((Component)__instance).transform.forward;
forward.y = 0f;
if (((Vector3)(ref forward)).sqrMagnitude > 0.0001f)
{
((Vector3)(ref forward)).Normalize();
Vector3 val = Vector3.Slerp(linearVelocity / magnitude, forward, Mathf.Clamp01(4f * Time.deltaTime)) * magnitude;
rb.linearVelocity = new Vector3(val.x, rb.linearVelocity.y, val.z);
}
}
}
}
[BepInPlugin("com.jxpitwr.easydelivery.driftmod", "EasyDrift", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
private readonly Harmony harmony = new Harmony("com.jxpitwr.easydelivery.driftmod");
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin EasyDrift is loaded!");
harmony.PatchAll();
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "com.jxpitwr.easydelivery.driftmod";
public const string PLUGIN_NAME = "EasyDrift";
public const string PLUGIN_VERSION = "1.0.0";
}