using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using HarmonyLib; using Il2CppInterop.Runtime.InteropTypes; using Il2CppSLZ.Marrow; using Il2CppSLZ.Vehicle; using MelonLoader; using Microsoft.CodeAnalysis; using TriggerDriving; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: MelonInfo(typeof(TriggerDrivingMod), "Trigger Driving", "1.0.0", "Codex", null)] [assembly: MelonGame("Stress Level Zero", "BONELAB")] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("TriggerDriving")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("TriggerDriving")] [assembly: AssemblyTitle("TriggerDriving")] [assembly: AssemblyVersion("1.0.0.0")] 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; } } } namespace TriggerDriving { public sealed class TriggerDrivingMod : MelonMod { private readonly record struct DriveInput(IntPtr Controller, float Throttle); [ThreadStatic] private static DriveInput currentInput; public override void OnInitializeMelon() { ((MelonBase)this).HarmonyInstance.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(OpenController), "GetThumbStickAxis", (Type[])null, (Type[])null), (HarmonyMethod)null, Hook("ReplaceThrottleAxis"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); ((MelonBase)this).HarmonyInstance.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Atv), "Update", (Type[])null, (Type[])null), Hook("BeginKartUpdate"), (HarmonyMethod)null, (HarmonyMethod)null, Hook("RestoreInput"), (HarmonyMethod)null); ((MelonBase)this).HarmonyInstance.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Atv_WheelColliders), "Update", (Type[])null, (Type[])null), Hook("BeginWheelColliderUpdate"), (HarmonyMethod)null, (HarmonyMethod)null, Hook("RestoreInput"), (HarmonyMethod)null); ((MelonBase)this).LoggerInstance.Msg("Vehicle controls active. Right trigger forward, left trigger reverse."); } private static HarmonyMethod Hook(string methodName) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown return new HarmonyMethod(typeof(TriggerDrivingMod), methodName, (Type[])null); } private static void BeginKartUpdate(Atv __instance, out DriveInput __state) { __state = currentInput; currentInput = ReadDriveInput(__instance.driverSeat, usesRightStick: true); } private static void BeginWheelColliderUpdate(Atv_WheelColliders __instance, out DriveInput __state) { __state = currentInput; currentInput = (__instance.use_keyboard ? default(DriveInput) : ReadDriveInput(__instance.driverSeat, usesRightStick: false)); } private static void RestoreInput(DriveInput __state) { currentInput = __state; } private static void ReplaceThrottleAxis(OpenController __instance, ref Vector2 __result) { //IL_003e: 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) if (!(currentInput.Controller == IntPtr.Zero) && !(currentInput.Controller != ((Il2CppObjectBase)__instance).Pointer)) { __result = new Vector2(0f, currentInput.Throttle); } } private static DriveInput ReadDriveInput(Seat? seat, bool usesRightStick) { RigManager val = (Object.op_Implicit((Object)(object)seat) ? seat.rigManager : null); ControllerRig val2 = (Object.op_Implicit((Object)(object)val) ? val.controllerRig : null); if (!Object.op_Implicit((Object)(object)val2)) { return default(DriveInput); } BaseController leftController = val2.leftController; OpenController val3 = ((leftController != null) ? ((Il2CppObjectBase)leftController).TryCast() : null); BaseController rightController = val2.rightController; OpenController val4 = ((rightController != null) ? ((Il2CppObjectBase)rightController).TryCast() : null); if (!Object.op_Implicit((Object)(object)val3) || !Object.op_Implicit((Object)(object)val4)) { return default(DriveInput); } OpenController val5 = (usesRightStick ? val4 : val3); float throttle = NormalizeTrigger(((BaseController)val4).GetPrimaryInteractionButtonAxis()) - NormalizeTrigger(((BaseController)val3).GetPrimaryInteractionButtonAxis()); return new DriveInput(((Il2CppObjectBase)val5).Pointer, throttle); } private static float NormalizeTrigger(float value) { if (!float.IsFinite(value)) { return 0f; } return Math.Clamp((value - 0.05f) / 0.95f, 0f, 1f); } } }