#About hooks
A hook runs your code before, after, around or instead of one of the game's functions.
hook before MarioActor::control {
if frozen { skip } // a void function: skip it
}
hook after MR::getStarPieceNum -> n { // the result, named
result = n * 2 // changes what the caller receives
}
wrap MR::addStarPiece(num) { // the arguments, named; may be written
num *= 2
proceed // the next wrap, then the game's own code
}
replace Kuribo::exeWander { // one mod only (a second is refused at load, naming both mods)
self.mVelocity = vec3
}
hook before `MR::isNear(const LiveActor *, const Vec3f &, f32)`(actor, at, dist) -> bool {
if dist < 0.0 { skip false } // a non-void function: skip needs the result (else a compile error)
}selfis the view ofthisfor member functions.beforemayskip(with a result for a non-void function: the compiler requires it, so a skipped call always has one).aftermay changeresult.wrapcallsproceedzero or one time per path; calling it twice is a compile error; a path that never proceeds must setresultfor a non-void function.replacenever proceeds.- A hook written in a
classapplies to that class's objects only (the compiler adds theis_atest). - Hooks on constructors and destructors:
hook after Kuribo::Kuribo(name),hook before Kuribo::~Kuribo, before and after only (the kernel's rule). hook ... every override of LiveActor::controlhooks the virtual and each override the self-description lists (kernel partK.vhook).- Order: hooks of one mod run in the order written; between mods, in the player's load order (kernel).
- A script error inside a hook ends that hook's run: a
beforedoes not skip; awrapthat has not proceeded proceeds; anafterleaves the result as it was. The game's own behavior goes on.