Skip to content

Commit a650a9d

Browse files
Add more hook priority utilities (#1510)
* Add more hook priority utilities * change to string reference
1 parent 126ed5b commit a650a9d

File tree

1 file changed

+104
-8
lines changed

1 file changed

+104
-8
lines changed

loader/include/Geode/modify/Modify.hpp

Lines changed: 104 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,18 @@ namespace geode::modifier {
244244

245245
/// @brief Set the priority of a hook to be after another hook in different mods
246246
/// @param name The name of the hook to set the priority of
247-
/// @param after The mod to set the priority after
247+
/// @param mod The mod to set the priority after
248248
/// @returns Ok if the hook was found and the priority was set, Err if the hook was not found
249249
Result<> setHookPriorityAfter(std::string_view name, Mod* mod) {
250250
GEODE_UNWRAP_INTO(auto hook, this->getHook(name));
251+
this->setHookPriorityAfter(hook, mod);
252+
return Ok();
253+
}
254+
255+
/// @brief Set the priority of a hook to be after another hook in different mods
256+
/// @param hook The hook to set the priority of
257+
/// @param mod The mod to set the priority after
258+
void setHookPriorityAfter(Hook* hook, Mod* mod) {
251259
auto func = [=](ModStateEvent* event){
252260
auto hooks = mod->getHooks();
253261
for (auto modHook : hooks) {
@@ -265,7 +273,6 @@ namespace geode::modifier {
265273
else {
266274
new EventListener(func, ModStateFilter(mod, ModEventType::Loaded));
267275
}
268-
return Ok();
269276
}
270277

271278
/// @brief Set the priority of a hook to be after another hook in different mods
@@ -278,12 +285,31 @@ namespace geode::modifier {
278285
return this->setHookPriorityAfter(name, mod);
279286
}
280287

288+
/// @brief Set the priority of a hook to be after another hook in different mods
289+
/// @param hook The hook to set the priority of
290+
/// @param after The mod id of the mod to set the priority after
291+
/// @returns Ok if the mod was found and the priority was set, Err if the mod was not found
292+
Result<> setHookPriorityAfter(Hook* hook, const std::string& after) {
293+
auto mod = Loader::get()->getInstalledMod(after);
294+
if (!mod) return Err("Mod not found");
295+
this->setHookPriorityAfter(hook, mod);
296+
return Ok();
297+
}
298+
281299
/// @brief Set the priority of a hook to be before another hook in different mods
282300
/// @param name The name of the hook to set the priority of
283-
/// @param before The mod to set the priority before
301+
/// @param mod The mod to set the priority before
284302
/// @returns Ok if the hook was found and the priority was set, Err if the hook was not found
285303
Result<> setHookPriorityBefore(std::string_view name, Mod* mod) {
286304
GEODE_UNWRAP_INTO(auto hook, this->getHook(name));
305+
this->setHookPriorityBefore(hook, mod);
306+
return Ok();
307+
}
308+
309+
/// @brief Set the priority of a hook to be before another hook in different mods
310+
/// @param hook The hook to set the priority of
311+
/// @param mod The mod to set the priority before
312+
void setHookPriorityBefore(Hook* hook, Mod* mod) {
287313
auto func = [=](ModStateEvent* event){
288314
auto hooks = mod->getHooks();
289315
for (auto modHook : hooks) {
@@ -301,7 +327,6 @@ namespace geode::modifier {
301327
else {
302328
new EventListener(func, ModStateFilter(mod, ModEventType::Loaded));
303329
}
304-
return Ok();
305330
}
306331

307332
/// @brief Set the priority of a hook to be before another hook in different mods
@@ -314,6 +339,17 @@ namespace geode::modifier {
314339
return this->setHookPriorityBefore(name, mod);
315340
}
316341

342+
/// @brief Set the priority of a hook to be before another hook in different mods
343+
/// @param hook The hook to set the priority of
344+
/// @param before The mod id of the mod to set the priority before
345+
/// @returns Ok if the mod was found and the priority was set, Err if the mod was not found
346+
Result<> setHookPriorityBefore(Hook* hook, const std::string& before) {
347+
auto mod = Loader::get()->getInstalledMod(before);
348+
if (!mod) return Err("Mod not found");
349+
this->setHookPriorityBefore(hook, mod);
350+
return Ok();
351+
}
352+
317353
/// @brief Set the priority of a hook to be after another hook in different mods
318354
/// @param name The name of the hook to set the priority of
319355
/// @param after The mod id of the mod to set the priority after
@@ -324,12 +360,27 @@ namespace geode::modifier {
324360

325361
/// @brief Set the priority of a hook to be after another hook in different mods
326362
/// @param name The name of the hook to set the priority of
327-
/// @param before The mod to set the priority after
363+
/// @param mod The mod to set the priority after
328364
/// @returns Ok if the hook was found and the priority was set, Err if the hook was not found
329365
Result<> setHookPriorityAfterPre(std::string_view name, Mod* mod) {
330366
return this->setHookPriorityAfter(name, mod);
331367
}
332368

369+
/// @brief Set the priority of a hook to be after another hook in different mods
370+
/// @param hook The hook to set the priority of
371+
/// @param after The mod id of the mod to set the priority after
372+
/// @returns Ok if the mod was found and the priority was set, Err if the mod was not found
373+
Result<> setHookPriorityAfterPre(Hook* hook, const std::string& after) {
374+
return this->setHookPriorityAfter(hook, after);
375+
}
376+
377+
/// @brief Set the priority of a hook to be after another hook in different mods
378+
/// @param hook The hook to set the priority of
379+
/// @param mod The mod to set the priority after
380+
void setHookPriorityAfterPre(Hook* hook, Mod* mod) {
381+
this->setHookPriorityAfter(hook, mod);
382+
}
383+
333384
/// @brief Set the priority of a hook to be before another hook in different mods
334385
/// @param name The name of the hook to set the priority of
335386
/// @param before The mod id of the mod to set the priority before
@@ -340,12 +391,27 @@ namespace geode::modifier {
340391

341392
/// @brief Set the priority of a hook to be before another hook in different mods
342393
/// @param name The name of the hook to set the priority of
343-
/// @param before The mod to set the priority before
394+
/// @param mod The mod to set the priority before
344395
/// @returns Ok if the hook was found and the priority was set, Err if the hook was not found
345396
Result<> setHookPriorityBeforePre(std::string_view name, Mod* mod) {
346397
return this->setHookPriorityBefore(name, mod);
347398
}
348399

400+
/// @brief Set the priority of a hook to be before another hook in different mods
401+
/// @param hook The hook to set the priority of
402+
/// @param before The mod id of the mod to set the priority before
403+
/// @returns Ok if the mod was found and the priority was set, Err if the mod was not found
404+
Result<> setHookPriorityBeforePre(Hook* hook, const std::string& before) {
405+
return this->setHookPriorityBefore(hook, before);
406+
}
407+
408+
/// @brief Set the priority of a hook to be before another hook in different mods
409+
/// @param hook The hook to set the priority of
410+
/// @param mod The mod to set the priority before
411+
void setHookPriorityBeforePre(Hook* hook, Mod* mod) {
412+
this->setHookPriorityBefore(hook, mod);
413+
}
414+
349415
/// @brief Set the priority of a hook to be after another hook in different mods
350416
/// @param name The name of the hook to set the priority of
351417
/// @param after The mod id of the mod to set the priority after
@@ -356,12 +422,27 @@ namespace geode::modifier {
356422

357423
/// @brief Set the priority of a hook to be after another hook in different mods
358424
/// @param name The name of the hook to set the priority of
359-
/// @param before The mod to set the priority after
425+
/// @param mod The mod to set the priority after
360426
/// @returns Ok if the hook was found and the priority was set, Err if the hook was not found
361427
Result<> setHookPriorityAfterPost(std::string_view name, Mod* mod) {
362428
return this->setHookPriorityBefore(name, mod);
363429
}
364430

431+
/// @brief Set the priority of a hook to be after another hook in different mods
432+
/// @param hook The hook to set the priority of
433+
/// @param after The mod id of the mod to set the priority after
434+
/// @returns Ok if the mod was found and the priority was set, Err if the mod was not found
435+
Result<> setHookPriorityAfterPost(Hook* hook, const std::string& after) {
436+
return this->setHookPriorityBefore(hook, after);
437+
}
438+
439+
/// @brief Set the priority of a hook to be after another hook in different mods
440+
/// @param hook The hook to set the priority of
441+
/// @param mod The mod to set the priority after
442+
void setHookPriorityAfterPost(Hook* hook, Mod* mod) {
443+
this->setHookPriorityBefore(hook, mod);
444+
}
445+
365446
/// @brief Set the priority of a hook to be before another hook in different mods
366447
/// @param name The name of the hook to set the priority of
367448
/// @param before The mod id of the mod to set the priority before
@@ -372,12 +453,27 @@ namespace geode::modifier {
372453

373454
/// @brief Set the priority of a hook to be before another hook in different mods
374455
/// @param name The name of the hook to set the priority of
375-
/// @param before The mod to set the priority before
456+
/// @param mod The mod to set the priority before
376457
/// @returns Ok if the hook was found and the priority was set, Err if the hook was not found
377458
Result<> setHookPriorityBeforePost(std::string_view name, Mod* mod) {
378459
return this->setHookPriorityAfter(name, mod);
379460
}
380461

462+
/// @brief Set the priority of a hook to be before another hook in different mods
463+
/// @param hook The hook to set the priority of
464+
/// @param before The mod id of the mod to set the priority before
465+
/// @returns Ok if the mod was found and the priority was set, Err if the mod was not found
466+
Result<> setHookPriorityBeforePost(Hook* hook, const std::string& before) {
467+
return this->setHookPriorityAfter(hook, before);
468+
}
469+
470+
/// @brief Set the priority of a hook to be before another hook in different mods
471+
/// @param hook The hook to set the priority of
472+
/// @param mod The mod to set the priority before
473+
void setHookPriorityBeforePost(Hook* hook, Mod* mod) {
474+
this->setHookPriorityAfter(hook, mod);
475+
}
476+
381477
// unordered_map<handles> idea
382478
ModifyBase() {
383479
struct EboCheck : ModifyDerived::Base {

0 commit comments

Comments
 (0)