-
Notifications
You must be signed in to change notification settings - Fork 4
/
Plugin.cs
190 lines (171 loc) · 6.87 KB
/
Plugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
using GameReaderCommon;
using SimHub.Plugins;
using System.Collections.Generic;
using AcTools.WheelAngles;
using SharpDX.DirectInput;
namespace Havner.AccSteeringLock
{
[PluginDescription("Sets SIMUCUBE steering lock based on loaded car")]
[PluginAuthor("Havner")]
[PluginName("ACC Steering Lock Setter")]
public class Plugin : IPlugin, IDataPlugin
{
internal string lastCar;
internal int lastRotation;
static readonly internal Dictionary<string, int> cars = new Dictionary<string, int>()
{
// CUP
{"porsche_991ii_gt3_cup", 800},
{"porsche_992_gt3_cup", 540},
// ST
{"lamborghini_huracan_st", 620},
{"lamborghini_huracan_st_evo2", 620},
// CHL
{"ferrari_488_challenge_evo", 480},
// TCX
{"bmw_m2_cs_racing", 360},
// GT2
{"audi_r8_lms_gt2", 720},
{"ktm_xbow_gt2", 582},
{"maserati_mc20_gt2", 480},
{"mercedes_amg_gt2", 492},
{"porsche_935", 720},
{"porsche_991_gt2_rs_mr", 720},
// GT3
{"amr_v12_vantage_gt3", 640},
{"amr_v8_vantage_gt3", 640},
{"audi_r8_lms", 720},
{"audi_r8_lms_evo", 720},
{"audi_r8_lms_evo_ii", 720},
{"bentley_continental_gt3_2016", 640},
{"bentley_continental_gt3_2018", 640},
{"bmw_m4_gt3", 516},
{"bmw_m6_gt3", 566},
{"jaguar_g3", 720},
{"ferrari_296_gt3", 800},
{"ferrari_488_gt3", 480},
{"ferrari_488_gt3_evo", 480},
{"ford_mustang_gt3", 516},
{"honda_nsx_gt3", 620},
{"honda_nsx_gt3_evo", 436},
{"lamborghini_huracan_gt3", 620},
{"lamborghini_huracan_gt3_evo", 620},
{"lamborghini_huracan_gt3_evo2", 620},
{"lexus_rc_f_gt3", 640},
{"mclaren_650s_gt3", 480},
{"mclaren_720s_gt3", 480},
{"mclaren_720s_gt3_evo", 480},
{"mercedes_amg_gt3", 640},
{"mercedes_amg_gt3_evo", 640},
{"nissan_gt_r_gt3_2017", 640},
{"nissan_gt_r_gt3_2018", 640},
{"porsche_991_gt3_r", 800},
{"porsche_991ii_gt3_r", 800},
{"porsche_992_gt3_r", 800},
{"lamborghini_gallardo_rex", 720},
// GT4
{"alpine_a110_gt4", 720},
{"amr_v8_vantage_gt4", 640},
{"audi_r8_gt4", 720},
{"bmw_m4_gt4", 492},
{"chevrolet_camaro_gt4r", 720},
{"ginetta_g55_gt4", 720},
{"ktm_xbow_gt4", 582},
{"maserati_mc_gt4", 900},
{"mclaren_570s_gt4", 480},
{"mercedes_amg_gt4", 492},
{"porsche_718_cayman_gt4_mr", 800},
};
internal IWheelSteerLockSetter wheel;
internal void DetectDevices()
{
DirectInput di = new DirectInput();
foreach (DeviceInstance device in di.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly))
{
SimHub.Logging.Current.Info("AccSteeringLock: detected: " + device.ProductGuid + " " + device.ProductName);
wheel = WheelSteerLock.Get(device.ProductGuid.ToString());
if (wheel != null)
{
SimHub.Logging.Current.Info("AccSteeringLock: found supported wheel: " + device.ProductName + " handled by: " + wheel.ControllerName);
break;
}
}
if (wheel == null)
SimHub.Logging.Current.Warn("AccSteeringLock: no supported wheel found.");
}
internal void ResetRotation()
{
if (wheel == null) return;
if (lastRotation <= 0) return;
SimHub.Logging.Current.Info("AccSteeringLock: resetting rotation from: " + lastRotation);
if (!wheel.Apply(lastRotation, true, out lastRotation))
SimHub.Logging.Current.Error("AccSteeringLock: IWheelSteerLockSetter::Apply() failed.");
lastRotation = 0;
}
/// <summary>
/// Instance of the current plugin manager
/// </summary>
public PluginManager PluginManager { get; set; }
/// <summary>
/// Called once after plugins startup
/// Plugins are rebuilt at game change
/// </summary>
/// <param name="pluginManager"></param>
public void Init(PluginManager pluginManager)
{
SimHub.Logging.Current.Info("AccSteeringLock: Init()");
lastCar = null;
lastRotation = 0;
DetectDevices();
}
/// <summary>
/// Called at plugin manager stop, close/dispose anything needed here !
/// Plugins are rebuilt at game change
/// </summary>
/// <param name="pluginManager"></param>
public void End(PluginManager pluginManager)
{
SimHub.Logging.Current.Info("AccSteeringLock: End()");
ResetRotation();
}
/// <summary>
/// Called one time per game data update, contains all normalized game data,
/// raw data are intentionnally "hidden" under a generic object type (A plugin SHOULD NOT USE IT)
///
/// This method is on the critical path, it must execute as fast as possible and avoid throwing any error
///
/// </summary>
/// <param name="pluginManager"></param>
/// <param name="data"></param>
public void DataUpdate(PluginManager pluginManager, ref GameData data)
{
if (data.GameName != "AssettoCorsaCompetizione") return;
if (!data.GameRunning)
{
ResetRotation();
lastCar = null;
return;
}
if (data.NewData == null) return;
if (data.NewData.CarId == lastCar) return;
// car has changed, if we have no wheel, try to re-detect
if (wheel == null)
DetectDevices();
lastCar = data.NewData.CarId;
if (wheel == null) return;
ResetRotation();
if (cars.TryGetValue(lastCar, out int rotation))
{
SimHub.Logging.Current.Info("AccSteeringLock: setting rotation of " + lastCar + " to: " + rotation);
if (!wheel.Apply(rotation, false, out lastRotation))
SimHub.Logging.Current.Error("AccSteeringLock: IWheelSteerLockSetter::Apply() failed.");
else if (rotation != lastRotation)
SimHub.Logging.Current.Info("AccSteeringLock: rotation had to be clamped due to hardware limitations to: " + lastRotation);
}
else
{
SimHub.Logging.Current.Info("AccSteeringLock: no data for " + lastCar);
}
}
}
}