Skip to content

Commit 8f6e6cc

Browse files
committed
final hook, clean-up
1 parent 95f52bd commit 8f6e6cc

File tree

4 files changed

+19
-143
lines changed

4 files changed

+19
-143
lines changed

src/red4ext/Hooks/ApplyOverrides.cpp

Lines changed: 7 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ bool Manager::Override(
1313
Overridable overridableUI,
1414
uint16_t inputKey
1515
) {
16-
// static UniRelocFunc<decltype(&Manager::Override)> call(2948927698);
17-
// call(this, contextName, overridableUI, inputKey);
1816
bool status = false;
1917
for (auto & action : this->contextManager->actions.values) {
2018
for (auto & mapName : action->data.mapNames) {
2119
auto mappingCollection = this->contextManager->userMapping->GetMappingCollection(mapName);
2220
for (auto & mapping : mappingCollection->mappings) {
23-
if (mapping.overridableUI == overridableUI && mapping.key16 != inputKey) {
24-
mapping.key16 = inputKey;
21+
if (mapping.overridableUI == overridableUI) {
22+
if (mapping.key16 != inputKey) {
23+
mapping.key16 = inputKey;
24+
}
2525
status = true;
2626
}
2727
}
@@ -30,127 +30,10 @@ bool Manager::Override(
3030
return status;
3131
}
3232

33-
// enum EMappingType : uint8_t {
34-
// Internal = 0, // maybe
35-
// Button = 1,
36-
// FakeButton = 2,
37-
// Axis = 3,
38-
// FakeAxis = 4,
39-
// Relative = 5,
40-
// Unk6 = 6
41-
// };
33+
decltype(&ApplyOverrides) ApplyOverrides_Original;
34+
ModModuleHookHash s_ApplyOverrides_Hook("ApplyOverrides", 1773342692, reinterpret_cast<void*>(&ApplyOverrides), reinterpret_cast<void**>(&ApplyOverrides_Original));
4235

43-
// #pragma pack(push, 1)
44-
// struct Mapping {
45-
// EMappingType type;
46-
// // 210 / 0xD2 - pre apply 175 25
47-
// // 35 / 0x23 - post apply 35 35
48-
// // 116 / 0x74 - pre apply 2 252 45
49-
// // 35 / 0x23 - post apply 2 35 35
50-
// // 35 / 0x23 - pre settings apply
51-
// // 35 / 0x23 - post settings apply
52-
// uint8_t unk01; // set to 0x23 after apply
53-
// EInputKey key16;
54-
// EInputKey key32;
55-
// uint16_t unk08;
56-
// CName name;
57-
// CName presetName;
58-
// float val;
59-
// float thresholdPress;
60-
// float thresholdRelease;
61-
// uint32_t overridableUI; // Java's String.hashCode()
62-
// uint32_t unk28;
63-
// uint32_t unk2C;
64-
// };
65-
// #pragma pack(pop)
66-
67-
// struct MappingCollection {
68-
// DynArray<Mapping> mappings;
69-
// };
70-
71-
// struct RawMappingCollection {
72-
// DynArray<Mapping> mappings;
73-
// // set to 0 after an ApplyOverrides
74-
// bool has_update;
75-
// };
76-
77-
// struct UserMapping {
78-
// DynArray<void *> unk00; // 00
79-
// uint8_t sorted; // 10
80-
// DynArray<void *> unk18; // 18
81-
// CString invalid_str; // 28
82-
// void * contextManager; // 48
83-
// void * buttons; // 50
84-
// void * buttonGroups; // 58
85-
// void * axes; // 60
86-
// void * relativeAxes; // 68
87-
// // updated from actionMap on save
88-
// Map<EInputKey, MappingCollection> keyMap; // 70
89-
// Map<CName, RawMappingCollection> actionMap; // 98
90-
// HashMap<CString, EInputKey> stringToKey; // C0
91-
// HashMap<CString, EInputKey> inputKeyMap_F0; // F0
92-
// HashMap<EInputKey, CString> unk120; // 120
93-
// };
94-
95-
// after OnStreamingWorldLoaded
96-
// unk00 & unk18 empty
97-
// baseMap 144
98-
// overrides 462
99-
// inputKeyMap_C0 272
100-
// inputKeyMap_F0 272
101-
102-
// .xml binding
103-
// ApplyOverrides()
104-
// UserSettings.json applied
105-
106-
// after OnWorldAttached
107-
// updated:
108-
// contextManager
109-
// buttons
110-
// buttonGroups
111-
// axes
112-
// relativeAxes
113-
114-
// .xml binding
115-
// ApplyOverrides()
116-
// UserSettings.json applied
117-
118-
// after "Apply" is hit
119-
120-
// class ContextManager {
121-
122-
// };
123-
124-
// called once after Override
125-
REGISTER_HOOK_HASH(void, 1773342692, ApplyOverrides, Manager * manager) {
126-
// manager->Override("VehicleDrive", "vehicleFlight", EInputKey::IK_D);
127-
// manager->Override("BaseVehicleFlight", "vehicleFlight", EInputKey::IK_F);
36+
void ApplyOverrides(Manager * manager) {
12837
ModSettings::ModSettings::AddOverrides(manager);
12938
ApplyOverrides_Original(manager);
13039
}
131-
132-
// called once after Override
133-
// REGISTER_HOOK_HASH(void, 3016757648, ApplyOverrides, UserMapping *userMapping) {
134-
// auto hash = CalcHash("vehicleFlight");
135-
// userMapping->actionMap.ForEach([hash](const CName & action, RawMappingCollection & mappingCollection) {
136-
// bool updated = false;
137-
// for (auto mapping : mappingCollection.mappings) {
138-
// if (mapping.overridableUI == hash) {
139-
// updated = true;
140-
// mapping.key16 = EInputKey::IK_L;
141-
// mapping.key32 = EInputKey::IK_L;
142-
// }
143-
// }
144-
// mappingCollection.has_update = true;
145-
// });
146-
// ApplyOverrides_Original(userMapping);
147-
// }
148-
149-
// called per key when updating
150-
// REGISTER_HOOK_HASH(void, 1120015283, ContextManager_Override,
151-
// ContextManager * contextManager,
152-
// CName contextName,
153-
// unsigned int overridableUI,
154-
// EInputKey inputKey) {
155-
// ContextManager_Override_Original(contextManager, contextName, overridableUI, inputKey);
156-
// }

src/red4ext/Hooks/ApplyOverrides.hpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,6 @@ struct Overridable {
1919
uint32_t m_hash;
2020
};
2121

22-
// struct OverridableMapping {
23-
// uint32_t overridableUI;
24-
// uint32_t unk04_unk28;
25-
// uint64_t name;
26-
// uint64_t unk10;
27-
// EInputKey inputKey;
28-
// float val;
29-
// float thresholdPress;
30-
// float thresholdRelease;
31-
// };
32-
3322
struct UserMapping {
3423
struct Mapping {
3524
uint8_t type;
@@ -123,4 +112,6 @@ struct Manager {
123112
DynArray<void*> validators;
124113
DynArray<void*> unk40;
125114
uint64_t listener_id;
126-
};
115+
};
116+
117+
void ApplyOverrides(Manager * manager);

src/red4ext/ModSettings.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ void ModSettings::AddOverrides(Manager* manager) {
300300
auto name = variable->name.ToString();
301301
auto key = *(EInputKey*)variable->runtimeVar->GetValuePtr();
302302
if (!manager->Override(name, (uint16_t)key)) {
303-
sdk->logger->WarnF(pluginHandle, "%s is not specified as an overridableUI via input config (%s, %s)", name, modName.ToString(), className.ToString());
303+
sdk->logger->WarnF(pluginHandle, "overridableUI \"%s\" not found (%s, %s)", name, modName.ToString(), className.ToString());
304304
}
305305
}
306306
}
@@ -362,6 +362,8 @@ void ModSettings::AcceptChanges() {
362362
ModSettings::WriteToFile();
363363
modSettings.changeMade = false;
364364
modSettings.NotifyListeners();
365+
if (gameinputManager != nullptr)
366+
ApplyOverrides(gameinputManager);
365367
}
366368

367369
void ModSettings::RestoreDefaults(CName modName) {

src/redscript/mod_settings/ModSettings.reds

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ public native class ModConfigVarEnum extends ConfigVar {
7979
public native func GetDisplayValue(index: Int32) -> CName;
8080
}
8181

82-
public class ModSettingsTest {
82+
// public class ModSettingsTest {
8383
84-
@runtimeProperty("ModSettings.mod", "Test mod")
85-
public let vehicleFlight: EInputKey = EInputKey.IK_L;
84+
// @runtimeProperty("ModSettings.mod", "Test mod")
85+
// public let vehicleFlight: EInputKey = EInputKey.IK_L;
8686
87-
@runtimeProperty("ModSettings.mod", "Test mod")
88-
public let not_found: EInputKey = EInputKey.IK_A;
87+
// @runtimeProperty("ModSettings.mod", "Test mod")
88+
// public let not_found: EInputKey = EInputKey.IK_A;
8989
9090
// @runtimeProperty("ModSettings.mod", "Stone Mod")
9191
// public let stoneValue: Float = 0.0;
@@ -228,4 +228,4 @@ public let not_found: EInputKey = EInputKey.IK_A;
228228
// @runtimeProperty("ModSettings.mod", "Reflect Mod")
229229
// public let reflectValue: Float = 0.0;
230230
231-
}
231+
// }

0 commit comments

Comments
 (0)