using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.Layouts;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("G29SteeringMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Logitech G29 Support for EDCO")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("G29SteeringMod")]
[assembly: AssemblyTitle("G29SteeringMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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;
}
}
}
public class LogitechGSDK
{
[StructLayout(LayoutKind.Sequential, Pack = 2)]
public struct LogiControllerPropertiesData
{
public bool forceEnable;
public int overallGain;
public int springGain;
public int damperGain;
public bool defaultSpringEnabled;
public int defaultSpringGain;
public bool combinePedals;
public int wheelRange;
public bool gameSettingsEnabled;
public bool allowGameSettings;
}
[StructLayout(LayoutKind.Sequential, Pack = 2)]
public struct DIJOYSTATE2ENGINES
{
public int lX;
public int lY;
public int lZ;
public int lRx;
public int lRy;
public int lRz;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public int[] rglSlider;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public uint[] rgdwPOV;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
public byte[] rgbButtons;
public int lVX;
public int lVY;
public int lVZ;
public int lVRx;
public int lVRy;
public int lVRz;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public int[] rglVSlider;
public int lAX;
public int lAY;
public int lAZ;
public int lARx;
public int lARy;
public int lARz;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public int[] rglASlider;
public int lFX;
public int lFY;
public int lFZ;
public int lFRx;
public int lFRy;
public int lFRz;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public int[] rglFSlider;
}
public const int LOGI_MAX_CONTROLLERS = 4;
public const int LOGI_FORCE_NONE = -1;
public const int LOGI_FORCE_SPRING = 0;
public const int LOGI_FORCE_CONSTANT = 1;
public const int LOGI_FORCE_DAMPER = 2;
public const int LOGI_FORCE_SIDE_COLLISION = 3;
public const int LOGI_FORCE_FRONTAL_COLLISION = 4;
public const int LOGI_FORCE_DIRT_ROAD = 5;
public const int LOGI_FORCE_BUMPY_ROAD = 6;
public const int LOGI_FORCE_SLIPPERY_ROAD = 7;
public const int LOGI_FORCE_SURFACE_EFFECT = 8;
public const int LOGI_NUMBER_FORCE_EFFECTS = 9;
public const int LOGI_FORCE_SOFTSTOP = 10;
public const int LOGI_FORCE_CAR_AIRBORNE = 11;
public const int LOGI_PERIODICTYPE_NONE = -1;
public const int LOGI_PERIODICTYPE_SINE = 0;
public const int LOGI_PERIODICTYPE_SQUARE = 1;
public const int LOGI_PERIODICTYPE_TRIANGLE = 2;
public const int LOGI_DEVICE_TYPE_NONE = -1;
public const int LOGI_DEVICE_TYPE_WHEEL = 0;
public const int LOGI_DEVICE_TYPE_JOYSTICK = 1;
public const int LOGI_DEVICE_TYPE_GAMEPAD = 2;
public const int LOGI_DEVICE_TYPE_OTHER = 3;
public const int LOGI_NUMBER_DEVICE_TYPES = 4;
public const int LOGI_MANUFACTURER_NONE = -1;
public const int LOGI_MANUFACTURER_LOGITECH = 0;
public const int LOGI_MANUFACTURER_MICROSOFT = 1;
public const int LOGI_MANUFACTURER_OTHER = 2;
public const int LOGI_MODEL_G27 = 0;
public const int LOGI_MODEL_DRIVING_FORCE_GT = 1;
public const int LOGI_MODEL_G25 = 2;
public const int LOGI_MODEL_MOMO_RACING = 3;
public const int LOGI_MODEL_MOMO_FORCE = 4;
public const int LOGI_MODEL_DRIVING_FORCE_PRO = 5;
public const int LOGI_MODEL_DRIVING_FORCE = 6;
public const int LOGI_MODEL_NASCAR_RACING_WHEEL = 7;
public const int LOGI_MODEL_FORMULA_FORCE = 8;
public const int LOGI_MODEL_FORMULA_FORCE_GP = 9;
public const int LOGI_MODEL_FORCE_3D_PRO = 10;
public const int LOGI_MODEL_EXTREME_3D_PRO = 11;
public const int LOGI_MODEL_FREEDOM_24 = 12;
public const int LOGI_MODEL_ATTACK_3 = 13;
public const int LOGI_MODEL_FORCE_3D = 14;
public const int LOGI_MODEL_STRIKE_FORCE_3D = 15;
public const int LOGI_MODEL_G940_JOYSTICK = 16;
public const int LOGI_MODEL_G940_THROTTLE = 17;
public const int LOGI_MODEL_G940_PEDALS = 18;
public const int LOGI_MODEL_RUMBLEPAD = 19;
public const int LOGI_MODEL_RUMBLEPAD_2 = 20;
public const int LOGI_MODEL_CORDLESS_RUMBLEPAD_2 = 21;
public const int LOGI_MODEL_CORDLESS_GAMEPAD = 22;
public const int LOGI_MODEL_DUAL_ACTION_GAMEPAD = 23;
public const int LOGI_MODEL_PRECISION_GAMEPAD_2 = 24;
public const int LOGI_MODEL_CHILLSTREAM = 25;
public const int LOGI_MODEL_G29 = 26;
public const int LOGI_MODEL_G920 = 27;
public const int LOGI_NUMBER_MODELS = 28;
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiSteeringInitialize(bool ignoreXInputControllers);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiUpdate();
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr LogiGetStateENGINES(int index);
public static DIJOYSTATE2ENGINES LogiGetStateCSharp(int index)
{
DIJOYSTATE2ENGINES result = default(DIJOYSTATE2ENGINES);
result.rglSlider = new int[2];
result.rgdwPOV = new uint[4];
result.rgbButtons = new byte[128];
result.rglVSlider = new int[2];
result.rglASlider = new int[2];
result.rglFSlider = new int[2];
try
{
result = (DIJOYSTATE2ENGINES)Marshal.PtrToStructure(LogiGetStateENGINES(index), typeof(DIJOYSTATE2ENGINES));
return result;
}
catch (ArgumentException)
{
}
return result;
}
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiGetDevicePath(int index, StringBuilder str, int size);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiGetFriendlyProductName(int index, StringBuilder str, int size);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiIsConnected(int index);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiIsDeviceConnected(int index, int deviceType);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiIsManufacturerConnected(int index, int manufacturerName);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiIsModelConnected(int index, int modelName);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiButtonTriggered(int index, int buttonNbr);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiButtonReleased(int index, int buttonNbr);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiButtonIsPressed(int index, int buttonNbr);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiGenerateNonLinearValues(int index, int nonLinCoeff);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern int LogiGetNonLinearValue(int index, int inputValue);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiHasForceFeedback(int index);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiIsPlaying(int index, int forceType);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiPlaySpringForce(int index, int offsetPercentage, int saturationPercentage, int coefficientPercentage);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiStopSpringForce(int index);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiPlayConstantForce(int index, int magnitudePercentage);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiStopConstantForce(int index);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiPlayDamperForce(int index, int coefficientPercentage);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiStopDamperForce(int index);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiPlaySideCollisionForce(int index, int magnitudePercentage);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiPlayFrontalCollisionForce(int index, int magnitudePercentage);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiPlayDirtRoadEffect(int index, int magnitudePercentage);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiStopDirtRoadEffect(int index);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiPlayBumpyRoadEffect(int index, int magnitudePercentage);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiStopBumpyRoadEffect(int index);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiPlaySlipperyRoadEffect(int index, int magnitudePercentage);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiStopSlipperyRoadEffect(int index);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiPlaySurfaceEffect(int index, int type, int magnitudePercentage, int period);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiStopSurfaceEffect(int index);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiPlayCarAirborne(int index);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiStopCarAirborne(int index);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiPlaySoftstopForce(int index, int usableRangePercentage);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiStopSoftstopForce(int index);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiSetPreferredControllerProperties(LogiControllerPropertiesData properties);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiGetCurrentControllerProperties(int index, ref LogiControllerPropertiesData properties);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern int LogiGetShifterMode(int index);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiSetOperatingRange(int index, int range);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiGetOperatingRange(int index, ref int range);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern bool LogiPlayLeds(int index, float currentRPM, float rpmFirstLedTurnsOn, float rpmRedLine);
[DllImport("LogitechSteeringWheelEnginesWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern void LogiSteeringShutdown();
}
namespace EDCO_G29_Mod
{
[BepInPlugin("me.neibox.edco.g29", "Wheel Support", "1.0.0")]
public class G29Plugin : BaseUnityPlugin
{
public enum InputMode
{
None,
LogitechSDK,
GenericWheel,
Gamepad
}
[CompilerGenerated]
private sealed class <PeriodicCheck>d__33 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public G29Plugin <>4__this;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <PeriodicCheck>d__33(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Expected O, but got Unknown
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Expected O, but got Unknown
int num = <>1__state;
G29Plugin g29Plugin = <>4__this;
switch (num)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(1f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
g29Plugin.DetectBestInputDevice();
break;
case 2:
<>1__state = -1;
g29Plugin.DetectBestInputDevice();
break;
}
<>2__current = (object)new WaitForSeconds(3f);
<>1__state = 2;
return true;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
public static float FinalSteering = 0f;
public static float FinalThrottle = 0f;
public static bool FinalBrake = false;
public static Vector2 FinalDpad = Vector2.zero;
public static InputMode currentInputMode = InputMode.None;
public static bool IsInWalkingMode = false;
public static bool BtnSelect_Down = false;
public static bool BtnSelect_Up = false;
public static bool BtnBack_Down = false;
public static bool BtnBack_Up = false;
public static bool BtnMap_Down = false;
public static bool BtnTab_Down = false;
public static bool BtnTab_Held = false;
public static bool BtnTab_Up = false;
public static bool CmdPause = false;
public static bool CmdLights = false;
public static bool CmdCamera = false;
public static bool CmdHorn = false;
public static bool CmdResetHeld = false;
public static Vector2 CmdRadioVector = Vector2.zero;
private static float radioBufferTimer = 0f;
public static bool IsManualGearboxActive = false;
public static int CurrentGear = 0;
private static int lastShiftMethod = 0;
public static float CurrentSpeedKmh = 0f;
public static bool IsOffRoad = false;
public static bool IsSliding = false;
public static byte[] prevButtons = new byte[128];
private void Awake()
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
((BaseUnityPlugin)this).Logger.LogInfo((object)"Wheel Support v1.0.0: FINAL BUILD");
LogitechGSDK.LogiSteeringInitialize(ignoreXInputControllers: false);
new Harmony("me.neibox.edco.g29").PatchAll();
}
private void Start()
{
InputSystem.onDeviceChange += OnDeviceChange;
((MonoBehaviour)this).StartCoroutine(PeriodicCheck());
}
private void OnDestroy()
{
InputSystem.onDeviceChange -= OnDeviceChange;
}
private void OnDeviceChange(InputDevice device, InputDeviceChange change)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Invalid comparison between Unknown and I4
if ((int)change == 0 || (int)change == 1)
{
DetectBestInputDevice();
}
}
[IteratorStateMachine(typeof(<PeriodicCheck>d__33))]
private IEnumerator PeriodicCheck()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <PeriodicCheck>d__33(0)
{
<>4__this = this
};
}
private void DetectBestInputDevice()
{
//IL_0002: 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)
InputMode inputMode = InputMode.None;
if (((IEnumerable<InputDevice>)(object)InputSystem.devices).Any(delegate(InputDevice d)
{
//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_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_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
InputDeviceDescription description2 = d.description;
if (!((InputDeviceDescription)(ref description2)).product.Contains("G29"))
{
description2 = d.description;
if (!((InputDeviceDescription)(ref description2)).product.Contains("G920"))
{
description2 = d.description;
return ((InputDeviceDescription)(ref description2)).product.Contains("G923");
}
}
return true;
}))
{
LogitechGSDK.LogiUpdate();
if (LogitechGSDK.LogiIsConnected(0))
{
inputMode = InputMode.LogitechSDK;
}
}
else if (((IEnumerable<InputDevice>)(object)InputSystem.devices).Any(delegate(InputDevice d)
{
//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_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)
InputDeviceDescription description = d.description;
if (((InputDeviceDescription)(ref description)).interfaceName == "HID")
{
description = d.description;
return ((InputDeviceDescription)(ref description)).product.ToLower().Contains("wheel");
}
return false;
}))
{
inputMode = InputMode.GenericWheel;
}
else if (Gamepad.current != null)
{
inputMode = InputMode.Gamepad;
}
if (inputMode != currentInputMode)
{
currentInputMode = inputMode;
((BaseUnityPlugin)this).Logger.LogInfo((object)$"*** ACTIVE CONTROL MODE: {currentInputMode} ***");
}
}
private void Update()
{
//IL_002e: 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)
ProcessInputs();
if (radioBufferTimer > 0f)
{
radioBufferTimer -= Time.deltaTime;
if (radioBufferTimer <= 0f)
{
CmdRadioVector = Vector2.zero;
}
}
}
private void ProcessInputs()
{
if (currentInputMode == InputMode.LogitechSDK)
{
LogitechGSDK.LogiUpdate();
RunLogitechLogic();
}
else if (currentInputMode == InputMode.GenericWheel)
{
RunGenericWheelLogic();
}
}
private void RunLogitechLogic()
{
//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
//IL_03da: Unknown result type (might be due to invalid IL or missing references)
//IL_03df: Unknown result type (might be due to invalid IL or missing references)
//IL_0403: Unknown result type (might be due to invalid IL or missing references)
//IL_0408: Unknown result type (might be due to invalid IL or missing references)
//IL_042c: Unknown result type (might be due to invalid IL or missing references)
//IL_0431: Unknown result type (might be due to invalid IL or missing references)
//IL_0455: Unknown result type (might be due to invalid IL or missing references)
//IL_045a: Unknown result type (might be due to invalid IL or missing references)
LogitechGSDK.DIJOYSTATE2ENGINES rec = LogitechGSDK.LogiGetStateCSharp(0);
FinalSteering = (float)rec.lX / 32768f;
float num = Mathf.Clamp01(Mathf.InverseLerp(32767f, -32768f, (float)rec.lZ) * 1.2f);
float num2 = Mathf.Clamp01(Mathf.InverseLerp(32767f, -32768f, (float)rec.lRz) * 1.2f);
if (num < 0.15f)
{
num = 0f;
}
if (num2 < 0.15f)
{
num2 = 0f;
}
if (IsButtonTriggered(rec, 24))
{
IsManualGearboxActive = !IsManualGearboxActive;
((BaseUnityPlugin)this).Logger.LogInfo((object)("Virtual Gearbox: " + (IsManualGearboxActive ? "MANUAL" : "AUTOMATIC")));
}
if (IsManualGearboxActive && !IsInWalkingMode)
{
FinalBrake = num2 > 0.15f;
if (IsButtonTriggered(rec, 4) && CurrentGear < 4)
{
CurrentGear++;
lastShiftMethod = 1;
}
if (IsButtonTriggered(rec, 5) && CurrentGear > -1)
{
CurrentGear--;
lastShiftMethod = 1;
}
bool flag = false;
if (IsButtonPressed(rec, 12))
{
CurrentGear = 1;
flag = true;
}
else if (IsButtonPressed(rec, 13))
{
CurrentGear = 2;
flag = true;
}
else if (IsButtonPressed(rec, 14))
{
CurrentGear = 3;
flag = true;
}
else if (IsButtonPressed(rec, 15))
{
CurrentGear = 4;
flag = true;
}
else if (IsButtonPressed(rec, 18))
{
CurrentGear = -1;
flag = true;
}
if (flag)
{
lastShiftMethod = 2;
}
if (lastShiftMethod == 2 && !flag)
{
CurrentGear = 0;
}
if (CurrentGear == 0)
{
FinalThrottle = 0f;
}
else if (CurrentGear == -1)
{
FinalThrottle = 0f - num;
}
else
{
float num3 = 1f;
if (CurrentGear == 1)
{
num3 = Mathf.Clamp01(1.5f - CurrentSpeedKmh / 50f);
}
else if (CurrentGear == 2)
{
num3 = Mathf.Clamp01(1.2f - Mathf.Abs(CurrentSpeedKmh - 50f) / 70f);
}
else if (CurrentGear == 3)
{
num3 = Mathf.Clamp01(0.5f + CurrentSpeedKmh / 150f);
}
else if (CurrentGear == 4)
{
num3 = Mathf.Clamp01(0.3f + CurrentSpeedKmh / 100f);
}
FinalThrottle = num * num3;
}
float num4 = 40f;
if (CurrentGear == 2)
{
num4 = 80f;
}
else if (CurrentGear == 3)
{
num4 = 130f;
}
else if (CurrentGear == 4)
{
num4 = 180f;
}
float currentRPM = Mathf.Clamp01(CurrentSpeedKmh / num4);
if (CurrentGear == 0)
{
currentRPM = num;
}
LogitechGSDK.LogiPlayLeds(0, currentRPM, 0.4f, 0.85f);
}
else
{
FinalBrake = false;
FinalThrottle = num - num2;
}
int num5 = (int)rec.rgdwPOV[0];
FinalDpad = Vector2.zero;
switch (num5)
{
case 0:
FinalDpad.y = 1f;
break;
case 18000:
FinalDpad.y = -1f;
break;
}
switch (num5)
{
case 9000:
FinalDpad.x = 1f;
break;
case 27000:
FinalDpad.x = -1f;
break;
}
BtnSelect_Down = IsButtonTriggered(rec, 0);
BtnSelect_Up = IsButtonReleased(rec, 0);
BtnBack_Down = IsButtonTriggered(rec, 2);
BtnBack_Up = IsButtonReleased(rec, 2);
BtnMap_Down = IsButtonTriggered(rec, 8);
BtnTab_Down = IsButtonTriggered(rec, 11);
BtnTab_Held = IsButtonPressed(rec, 11);
BtnTab_Up = IsButtonReleased(rec, 11);
if (IsButtonTriggered(rec, 10))
{
CmdRadioVector = new Vector2(0f, 1f);
radioBufferTimer = 0.02f;
}
if (IsButtonTriggered(rec, 23))
{
CmdRadioVector = new Vector2(0f, -1f);
radioBufferTimer = 0.02f;
}
if (IsButtonTriggered(rec, 21))
{
CmdRadioVector = new Vector2(1f, 0f);
radioBufferTimer = 0.02f;
}
if (IsButtonTriggered(rec, 22))
{
CmdRadioVector = new Vector2(-1f, 0f);
radioBufferTimer = 0.02f;
}
if (IsButtonTriggered(rec, 9))
{
CmdPause = true;
}
if (IsButtonTriggered(rec, 1))
{
CmdLights = true;
}
if (IsButtonTriggered(rec, 6))
{
CmdCamera = true;
}
if (IsButtonTriggered(rec, 7))
{
CmdHorn = true;
}
CmdResetHeld = IsButtonPressed(rec, 3);
Array.Copy(rec.rgbButtons, prevButtons, 128);
if (!IsInWalkingMode)
{
ApplyProForceFeedback();
return;
}
LogitechGSDK.LogiStopSpringForce(0);
LogitechGSDK.LogiStopDirtRoadEffect(0);
LogitechGSDK.LogiStopDamperForce(0);
}
private void ApplyProForceFeedback()
{
LogitechGSDK.LogiPlayDamperForce(0, 15);
int num = (int)Mathf.Clamp(30f + CurrentSpeedKmh * 0.3f, 30f, 60f);
LogitechGSDK.LogiPlaySpringForce(0, 0, num, num);
if (IsOffRoad && CurrentSpeedKmh > 5f)
{
LogitechGSDK.LogiPlayDirtRoadEffect(0, (int)Mathf.Clamp(CurrentSpeedKmh * 0.5f, 8f, 30f));
}
else if (CurrentSpeedKmh > 80f)
{
LogitechGSDK.LogiPlayDirtRoadEffect(0, 3);
}
else
{
LogitechGSDK.LogiStopDirtRoadEffect(0);
}
}
private void RunGenericWheelLogic()
{
//IL_01de: Unknown result type (might be due to invalid IL or missing references)
//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
Gamepad current = Gamepad.current;
if (current == null)
{
return;
}
FinalSteering = ((InputControl<float>)(object)((Vector2Control)current.leftStick).x).ReadValue();
float num = ((InputControl<float>)(object)current.rightTrigger).ReadValue();
float num2 = ((InputControl<float>)(object)current.leftTrigger).ReadValue();
if (num < 0.05f)
{
num = 0f;
}
if (num2 < 0.05f)
{
num2 = 0f;
}
if (current.dpad.up.wasPressedThisFrame)
{
IsManualGearboxActive = !IsManualGearboxActive;
((BaseUnityPlugin)this).Logger.LogInfo((object)("Generic Wheel Gearbox: " + (IsManualGearboxActive ? "MANUAL" : "AUTOMATIC")));
}
if (IsManualGearboxActive && !IsInWalkingMode)
{
FinalBrake = num2 > 0.15f;
if (current.rightShoulder.wasPressedThisFrame && CurrentGear < 4)
{
CurrentGear++;
lastShiftMethod = 1;
}
if (current.leftShoulder.wasPressedThisFrame && CurrentGear > -1)
{
CurrentGear--;
lastShiftMethod = 1;
}
if (CurrentGear == 0)
{
FinalThrottle = 0f;
}
else if (CurrentGear == -1)
{
FinalThrottle = 0f - num;
}
else
{
float num3 = 1f;
if (CurrentGear == 1)
{
num3 = Mathf.Clamp01(1.5f - CurrentSpeedKmh / 50f);
}
else if (CurrentGear == 2)
{
num3 = Mathf.Clamp01(1.2f - Mathf.Abs(CurrentSpeedKmh - 50f) / 70f);
}
else if (CurrentGear == 3)
{
num3 = Mathf.Clamp01(0.5f + CurrentSpeedKmh / 150f);
}
else if (CurrentGear == 4)
{
num3 = Mathf.Clamp01(0.3f + CurrentSpeedKmh / 100f);
}
FinalThrottle = num * num3;
}
}
else
{
FinalBrake = false;
FinalThrottle = num - num2;
}
FinalDpad = Vector2.zero;
if (current.dpad.down.wasPressedThisFrame)
{
CmdLights = true;
}
if (current.dpad.left.wasPressedThisFrame)
{
CmdHorn = true;
}
if (current.dpad.right.wasPressedThisFrame)
{
CmdCamera = true;
}
BtnSelect_Down = current.rightStickButton.wasPressedThisFrame;
BtnSelect_Up = current.rightStickButton.wasReleasedThisFrame;
BtnMap_Down = current.startButton.wasPressedThisFrame;
BtnTab_Down = current.selectButton.wasPressedThisFrame;
BtnTab_Held = current.selectButton.isPressed;
BtnTab_Up = current.selectButton.wasReleasedThisFrame;
if (!IsInWalkingMode)
{
float num4 = 0f;
float num5 = 0f;
num5 = Mathf.Clamp01(CurrentSpeedKmh / 150f) * 0.3f;
if (IsOffRoad && CurrentSpeedKmh > 5f)
{
num4 += Mathf.Clamp01(CurrentSpeedKmh / 60f) * 0.8f;
num5 += 0.5f;
}
if (IsSliding)
{
num4 += 0.4f;
num5 += 0.9f;
}
current.SetMotorSpeeds(Mathf.Clamp01(num4), Mathf.Clamp01(num5));
}
else
{
current.SetMotorSpeeds(0f, 0f);
}
}
private bool IsButtonPressed(LogitechGSDK.DIJOYSTATE2ENGINES rec, int btn)
{
return rec.rgbButtons[btn] == 128;
}
private bool IsButtonTriggered(LogitechGSDK.DIJOYSTATE2ENGINES rec, int btn)
{
if (rec.rgbButtons[btn] == 128)
{
return prevButtons[btn] != 128;
}
return false;
}
private bool IsButtonReleased(LogitechGSDK.DIJOYSTATE2ENGINES rec, int btn)
{
if (rec.rgbButtons[btn] != 128)
{
return prevButtons[btn] == 128;
}
return false;
}
}
[HarmonyPatch(typeof(sInputManager), "GetInput")]
public class InputManagerPatch
{
private static void Postfix(sInputManager __instance)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: 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_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: 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_0057: 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_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_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_008d: 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_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
if (G29Plugin.currentInputMode == G29Plugin.InputMode.Gamepad || G29Plugin.currentInputMode == G29Plugin.InputMode.None)
{
return;
}
if (G29Plugin.CmdRadioVector != Vector2.zero)
{
__instance.radioInput = G29Plugin.CmdRadioVector;
__instance.radioPressed = true;
}
else if (G29Plugin.FinalDpad != Vector2.zero)
{
__instance.radioInput = G29Plugin.FinalDpad;
__instance.playerInput = G29Plugin.FinalDpad;
__instance.cameraLook = G29Plugin.FinalDpad;
}
if (G29Plugin.IsInWalkingMode)
{
if (G29Plugin.FinalDpad != Vector2.zero)
{
__instance.driveInput = G29Plugin.FinalDpad;
}
else
{
__instance.driveInput = Vector2.zero;
}
}
else
{
__instance.driveInput = new Vector2(G29Plugin.FinalSteering, G29Plugin.FinalThrottle);
}
if (G29Plugin.FinalBrake)
{
__instance.breakPressed = true;
}
if (G29Plugin.BtnSelect_Down)
{
__instance.selectPressed = true;
}
if (G29Plugin.BtnSelect_Up)
{
__instance.selectReleased = true;
}
if (G29Plugin.BtnBack_Down)
{
__instance.backPressed = true;
}
if (G29Plugin.BtnBack_Up)
{
__instance.backReleased = true;
}
if (G29Plugin.BtnMap_Down)
{
__instance.mapPressed = true;
}
if (G29Plugin.BtnTab_Down)
{
__instance.inventoryPressed = true;
}
if (G29Plugin.BtnTab_Held)
{
__instance.inventoryHeld = true;
}
if (G29Plugin.BtnTab_Up)
{
__instance.inventoryReleased = true;
}
if (G29Plugin.CmdPause)
{
__instance.pausePressed = true;
G29Plugin.CmdPause = false;
}
if (G29Plugin.CmdLights)
{
__instance.headlightsPressed = true;
G29Plugin.CmdLights = false;
}
if (G29Plugin.CmdCamera)
{
__instance.cameraPressed = true;
G29Plugin.CmdCamera = false;
}
if (G29Plugin.CmdHorn)
{
__instance.hornPressed = true;
G29Plugin.CmdHorn = false;
}
if (G29Plugin.CmdResetHeld)
{
__instance.resetHeld = true;
__instance.resetPressed = true;
}
}
}
[HarmonyPatch(typeof(sCarController), "Update")]
public class CarControllerPatch
{
private static void Prefix(sCarController __instance)
{
//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)
if (G29Plugin.currentInputMode == G29Plugin.InputMode.Gamepad || G29Plugin.currentInputMode == G29Plugin.InputMode.None)
{
return;
}
G29Plugin.IsInWalkingMode = __instance.GuyActive;
if (G29Plugin.IsInWalkingMode)
{
return;
}
bool flag = false;
if (G29Plugin.currentInputMode == G29Plugin.InputMode.LogitechSDK)
{
flag = LogitechGSDK.LogiGetStateCSharp(0).rgbButtons[2] == 128 && G29Plugin.prevButtons[2] != 128;
}
if (flag)
{
__instance.handbreakOn = !__instance.handbreakOn;
}
if ((Object)(object)__instance.rb != (Object)null)
{
Vector3 linearVelocity = __instance.rb.linearVelocity;
G29Plugin.CurrentSpeedKmh = ((Vector3)(ref linearVelocity)).magnitude * 3.6f;
}
float num = 0f;
bool isOffRoad = false;
Wheel[] wheels = __instance.wheels;
foreach (Wheel val in wheels)
{
num += val.slide;
if ((Object)(object)val.suspention != (Object)null && val.suspention.contactTag == "offRoad")
{
isOffRoad = true;
}
}
G29Plugin.IsOffRoad = isOffRoad;
G29Plugin.IsSliding = num > 2f;
}
}
[HarmonyPatch(typeof(sCarController), "Move")]
public class LagPatch
{
private static void Prefix(sCarController __instance)
{
//IL_0017: 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)
if ((G29Plugin.currentInputMode == G29Plugin.InputMode.LogitechSDK || G29Plugin.currentInputMode == G29Plugin.InputMode.GenericWheel) && !G29Plugin.IsInWalkingMode && G29Plugin.FinalDpad == Vector2.zero)
{
__instance.input.x = G29Plugin.FinalSteering;
}
}
}
}