-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInputMappingReporter.cs
More file actions
289 lines (255 loc) · 12.2 KB
/
Copy pathInputMappingReporter.cs
File metadata and controls
289 lines (255 loc) · 12.2 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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
using System;
using System.Collections.Generic;
using System.Text;
using Rewired;
namespace DateEverythingAccess
{
internal static class InputMappingReporter
{
// Rewired action id for Move_Vertical (RewiredConsts.Action.Move_Vertical = 4). The game ships
// an UNDOCUMENTED secondary keyboard binding of the "O" key to this action (walk), NOT shown in
// the Controls UI. Because the mod's O accessibility shortcut is POLLED via GetAsyncKeyState
// (which doesn't consume the key), pressing O both opens the object tracker AND walks the
// player. We strip just that one binding at startup so O is free for the tracker; W/A/S/D and
// the arrows are untouched. See the hidden-keybinds reference memo.
private const int MoveVerticalActionId = 4;
// Display label of the key we strip off Move_Vertical. Rewired labels the letter keys by their
// letter, so matching elementIdentifierName is layout-stable rather than depending on a raw
// Rewired KeyboardKeyCode enum value.
private const string MoveVerticalKeyToStrip = "O";
// Removes the game's undocumented "O" -> Move_Vertical keyboard binding so the mod's O
// accessibility shortcut no longer also walks the player. One-shot: returns true once it has
// actually deleted the binding (or confirmed it's already gone); returns false while Rewired
// isn't ready yet so the caller can retry next frame. Scans ALL keyboard controller maps
// regardless of their enabled state — the input-mode state machine toggles map enabled flags,
// but the binding itself lives in the map and DeleteElementMap removes it permanently for the
// session. W/A/S/D and the arrows are left alone; only the O element map on action 4 is touched.
public static bool TryStripObjectTrackerMovementBinding()
{
try
{
if (!ReInput.isReady)
return false;
Player player = ReInput.players.GetPlayer(0);
if (player == null || !player.controllers.hasKeyboard)
return false;
Keyboard keyboard = player.controllers.Keyboard;
IList<ControllerMap> maps = player.controllers.maps.GetMaps(keyboard.type, keyboard.id);
if (maps == null || maps.Count == 0)
return false; // maps not populated yet — retry next frame rather than latch as done
bool sawMoveVerticalMap = false;
int removed = 0;
for (int i = 0; i < maps.Count; i++)
{
ControllerMap map = maps[i];
if (map == null)
continue;
// Collect the element-map ids to delete first, then delete — deleting while
// iterating AllMaps would mutate the collection under the loop.
List<int> toDelete = null;
for (int j = 0; j < map.AllMaps.Count; j++)
{
ActionElementMap m = map.AllMaps[j];
if (m == null || m.actionId != MoveVerticalActionId)
continue;
sawMoveVerticalMap = true;
if (!string.Equals(m.elementIdentifierName, MoveVerticalKeyToStrip, StringComparison.OrdinalIgnoreCase))
continue;
(toDelete ?? (toDelete = new List<int>())).Add(m.id);
}
if (toDelete != null)
{
for (int k = 0; k < toDelete.Count; k++)
if (map.DeleteElementMap(toDelete[k]))
removed++;
}
}
// Only consider the job done once the Move_Vertical bindings actually exist to inspect.
// Before the game loads its controller maps, no action-4 map is present — keep retrying
// so we don't latch "done" against an empty map and miss the real binding.
if (!sawMoveVerticalMap)
return false;
if (Main.Log != null)
Main.Log.LogInfo("[INPUTMAP] Stripped " + removed + " '" + MoveVerticalKeyToStrip +
"' -> Move_Vertical keyboard binding(s) so the object-tracker key no longer moves the player.");
return true;
}
catch (Exception ex)
{
if (Main.Log != null)
Main.Log.LogWarning("[INPUTMAP] TryStripObjectTrackerMovementBinding failed: " + ex.Message);
return false; // let the caller retry; a transient not-ready state shouldn't be permanent
}
}
public static bool TryDumpCurrentMappings(out int dumpedControllerCount)
{
dumpedControllerCount = 0;
try
{
if (!ReInput.isReady)
{
Main.Log.LogWarning("[INPUTMAP] ReInput is not ready yet.");
return false;
}
StringBuilder builder = new StringBuilder();
builder.AppendLine("[INPUTMAP] Rewired mapping dump start");
HashSet<string> dumpedControllers = new HashSet<string>(StringComparer.Ordinal);
DumpPlayerMappings(ReInput.players.GetPlayer(0), "Player0", builder, dumpedControllers, ref dumpedControllerCount);
DumpPlayerMappings(ReInput.players.GetSystemPlayer(), "SystemPlayer", builder, dumpedControllers, ref dumpedControllerCount);
if (dumpedControllerCount == 0)
{
Main.Log.LogWarning("[INPUTMAP] No active keyboard, mouse, or joystick controllers were available to dump from Player0 or SystemPlayer.");
return false;
}
builder.AppendLine("[INPUTMAP] Rewired mapping dump end");
Main.Log.LogInfo(builder.ToString());
return true;
}
catch (Exception ex)
{
Main.Log.LogError("[INPUTMAP] Failed to dump current mappings: " + ex);
return false;
}
}
private static void DumpPlayerMappings(Player player, string playerLabel, StringBuilder builder, HashSet<string> dumpedControllers, ref int dumpedControllerCount)
{
if (player == null)
{
builder.AppendLine("[INPUTMAP] Player=" + playerLabel + " is unavailable.");
return;
}
bool dumpedAnyForPlayer = false;
if (player.controllers.hasKeyboard && TryMarkController(dumpedControllers, player.controllers.Keyboard.type, player.controllers.Keyboard.id))
{
dumpedAnyForPlayer = true;
dumpedControllerCount++;
DumpControllerMaps(
builder,
playerLabel,
"Keyboard",
player.controllers.Keyboard.type,
player.controllers.Keyboard.id,
player.controllers.Keyboard.name,
player.controllers.maps.GetMaps(player.controllers.Keyboard.type, player.controllers.Keyboard.id));
}
if (player.controllers.hasMouse && TryMarkController(dumpedControllers, player.controllers.Mouse.type, player.controllers.Mouse.id))
{
dumpedAnyForPlayer = true;
dumpedControllerCount++;
DumpControllerMaps(
builder,
playerLabel,
"Mouse",
player.controllers.Mouse.type,
player.controllers.Mouse.id,
player.controllers.Mouse.name,
player.controllers.maps.GetMaps(player.controllers.Mouse.type, player.controllers.Mouse.id));
}
for (int i = 0; i < player.controllers.joystickCount; i++)
{
Joystick joystick = player.controllers.Joysticks[i];
if (joystick == null || !TryMarkController(dumpedControllers, joystick.type, joystick.id))
{
continue;
}
dumpedAnyForPlayer = true;
dumpedControllerCount++;
string label = string.IsNullOrEmpty(joystick.hardwareName) ? joystick.name : joystick.hardwareName;
DumpControllerMaps(
builder,
playerLabel,
"Joystick",
joystick.type,
joystick.id,
label,
player.controllers.maps.GetMaps(joystick.type, joystick.id));
}
if (!dumpedAnyForPlayer)
{
builder.AppendLine("[INPUTMAP] Player=" + playerLabel + " has no uniquely assigned active controllers.");
}
}
private static void DumpControllerMaps(StringBuilder builder, string playerLabel, string label, ControllerType controllerType, int controllerId, string controllerName, IList<ControllerMap> maps)
{
builder.AppendLine(string.Format(
"[INPUTMAP] Player={0} Controller={1} Type={2} Id={3} Name={4}",
playerLabel,
label,
controllerType,
controllerId,
Safe(controllerName)));
if (maps == null || maps.Count == 0)
{
builder.AppendLine("[INPUTMAP] No maps returned.");
return;
}
for (int i = 0; i < maps.Count; i++)
{
ControllerMap map = maps[i];
if (map == null)
{
continue;
}
builder.AppendLine(string.Format(
"[INPUTMAP] Map Category={0} LayoutId={1} Enabled={2}",
GetCategoryName(map.categoryId),
map.layoutId,
map.enabled));
for (int j = 0; j < map.AllMaps.Count; j++)
{
ActionElementMap actionMap = map.AllMaps[j];
if (actionMap == null)
{
continue;
}
builder.AppendLine(string.Format(
"[INPUTMAP] {0} ({1}) -> {2} [ElementType={3}, AxisRange={4}]",
Safe(GetActionName(actionMap.actionId, actionMap.actionDescriptiveName)),
actionMap.actionId,
Safe(actionMap.elementIdentifierName),
actionMap.elementType,
actionMap.axisRange));
}
}
}
private static bool TryMarkController(HashSet<string> dumpedControllers, ControllerType controllerType, int controllerId)
{
return dumpedControllers.Add(controllerType + ":" + controllerId);
}
private static string GetActionName(int actionId, string fallbackName)
{
InputAction action = ReInput.mapping.GetAction(actionId);
if (action != null && !string.IsNullOrEmpty(action.name))
{
return action.name;
}
return string.IsNullOrEmpty(fallbackName) ? "Action " + actionId : fallbackName;
}
private static string GetCategoryName(int categoryId)
{
switch (categoryId)
{
case 0:
return "Default";
case 1:
return "Dialog";
case 2:
return "CharacterController";
case 3:
return "Engagement";
case 4:
return "Debug";
case 5:
return "UI";
case 6:
return "Toggle_Dateviators";
default:
return "Category_" + categoryId;
}
}
private static string Safe(string value)
{
return string.IsNullOrEmpty(value) ? "<unnamed>" : value;
}
}
}