-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubModule.cs
More file actions
250 lines (170 loc) · 7.48 KB
/
SubModule.cs
File metadata and controls
250 lines (170 loc) · 7.48 KB
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
using HarmonyLib;
using MotionControlsOverhaul.Config;
using System.Runtime.InteropServices;
using TaleWorlds.Core;
using TaleWorlds.InputSystem;
using TaleWorlds.Library;
using TaleWorlds.MountAndBlade;
using TaleWorlds.MountAndBlade.View.MissionViews;
using TaleWorlds.MountAndBlade.View.Screens;
namespace MotionControlsOverhaul
{
public class SubModule : MBSubModuleBase
{
public static readonly string ModuleFolderName = "MotionControlsOverhaul";
public static readonly string ModName = "MotionControlsOverhaul";
protected override void OnGameStart(Game game, IGameStarter gameStarter)
{
}
protected override void OnSubModuleLoad()
{
base.OnSubModuleLoad();
Harmony harmony = new Harmony("MotionController");
harmony.PatchAll();
}
protected override void OnSubModuleUnloaded()
{
base.OnSubModuleUnloaded();
}
protected override void OnBeforeInitialModuleScreenSetAsRoot()
{
base.OnBeforeInitialModuleScreenSetAsRoot();
}
public override void OnMissionBehaviorInitialize(Mission mission)
{
base.OnMissionBehaviorInitialize(mission);
mission.AddMissionBehavior(new MotionControllerBehavior());
}
}
public class MotionControllerBehavior : MissionLogic
{
private Agent _mainAgent => Mission.MainAgent;
private GameKeyContext _gameAxisKey = HotKeyManager.GetCategory("Generic");
private GameKeyContext _keyContextGeneric = HotKeyManager.GetCategory("Generic");
private GameKeyContext _keyContext = HotKeyManager.GetCategory("CombatHotKeyCategory");
private static bool _rStickBinded = true;
private static InputKey _controllerRStick;
private IInputContext _inputContext => Mission.InputManager;
public override void EarlyStart()
{
base.EarlyStart();
_keyContext.GetGameKey(25).ControllerKey.ChangeKey(InputKey.Invalid);
}
public override void OnMissionTick(float dt)
{
base.OnMissionTick(dt);
AlternateFighting();
//AddGyroToLookDirection();
}
public override void OnMissionStateFinalized()
{
base.OnMissionStateFinalized();
BindCameraRStick();
}
public void UnbindCameraRStick()
{
//_keyContext.GetGameKey(9).ControllerKey.ChangeKey(InputKey.Invalid); //unbind Attack
//_keyContext.GetGameKey(10).ControllerKey.ChangeKey(InputKey.Invalid); //unbind Defend
foreach (var key in _gameAxisKey.RegisteredGameAxisKeys)
{
if(key.AxisKey.IsControllerInput && ((key.Id == "CameraAxisX") || (key.Id == "CameraAxisY")))
{
_controllerRStick = key.AxisKey.InputKey;
key.AxisKey.ChangeKey(InputKey.Invalid);
}
}
_rStickBinded = false;
}
public void BindCameraRStick()
{
//_keyContext.GetGameKey(9).ControllerKey.ChangeKey(InputKey.Invalid); //bind Attack
//_keyContext.GetGameKey(10).ControllerKey.ChangeKey(InputKey.Invalid); //bind Defend
foreach (var key in _gameAxisKey.RegisteredGameAxisKeys)
{
if (((key.Id == "CameraAxisX") || (key.Id == "CameraAxisY")) && (key.AxisKey.InputKey == InputKey.Invalid)) key.AxisKey.ChangeKey(_controllerRStick);
}
_rStickBinded = true;
}
public void AlternateFighting()
{
if (!MCOSettings.Instance.AlternateFighting)
{
if (!_rStickBinded) BindCameraRStick();
return;
}
if (_rStickBinded) UnbindCameraRStick();
if (Input.IsKeyDown(InputKey.ControllerLLeft))
{
}
if (Input.IsKeyReleased(InputKey.ControllerLLeft))
{
}
if (Input.GetKeyState(InputKey.ControllerRTrigger).x>0.99f)
{
}
if (Input.IsKeyReleased(InputKey.ControllerRTrigger))
{
}
//if (_inputContext.GetKeyState(InputKey.ControllerRTrigger).x > 0.2f)
//{
// InformationManager.DisplayMessage(new InformationMessage("Rtrigger"));
// switch (Input.GetFirstKeyDownInRange(236))
// {
// case 236:
// _mainAgent.MovementFlags |= Agent.MovementControlFlag.AttackUp;
// break;
// case 237:
// _mainAgent.MovementFlags |= Agent.MovementControlFlag.AttackDown;
// break;
// case 238:
// _mainAgent.MovementFlags |= Agent.MovementControlFlag.AttackLeft;
// break;
// case 239:
// _mainAgent.MovementFlags |= Agent.MovementControlFlag.AttackRight;
// break;
// }
//}
//if (_inputContext.GetKeyState(InputKey.ControllerLTrigger).x > 0.2f)
//{
// switch (Input.GetFirstKeyDownInRange(236))
// {
// case 236:
// _mainAgent.MovementFlags |= Agent.MovementControlFlag.DefendUp;
// break;
// case 237:
// _mainAgent.MovementFlags |= Agent.MovementControlFlag.DefendDown;
// break;
// case 238:
// _mainAgent.MovementFlags |= Agent.MovementControlFlag.DefendLeft;
// break;
// case 239:
// _mainAgent.MovementFlags |= Agent.MovementControlFlag.DefendRight;
// break;
// }
// Game.Current?.EventManager.TriggerEvent(new MissionPlayerMovementFlagsChangeEvent(_mainAgent.MovementFlags));
//}
}
/*private void AddGyroToLookDirection()
{
if(Input.IsKeyPressed(TaleWorlds.InputSystem.InputKey.Q))
{
InformationManager.DisplayMessage(new InformationMessage("haha"));
}
if (TaleWorlds.InputSystem.Input.ControllerType == TaleWorlds.InputSystem.Input.ControllerTypes.PlayStationDualShock || TaleWorlds.InputSystem.Input.ControllerType == TaleWorlds.InputSystem.Input.ControllerTypes.PlayStationDualSense)
{
float axisX = TaleWorlds.InputSystem.Input.GetGyroY() * 12f * -1f;
float axisY = TaleWorlds.InputSystem.Input.GetGyroX() * 12f;
if (Agent.Main != null)
{
//CameraBearing
//GameAxisKey
//Mission.MainAgent.AddController()
//Agent.Main.LookDirection.RotateAboutZ;
//Agent.Main.LookDirection.RotationX + gyroZ;
//Agent.Main.LookRotation.RotateAboutSide();
}
}
}
*/
}
}