Intro to Hooking Functions
In this tutorial, we will be hooking the function responsible for summoning a pal from your party.
Hooking functions
To hook a function in ue4ss, we use the RegisterHook
function as discussed in the previous tutorial.
The signature of the function looks like so:
RegisterHook(FunctionName, Callback)
The parameters are as follows:
FunctionName
- is the function name we could get from ue4ss LiveViewCallback
- is the lua function we want to get called, when the hooked function finishes executing. This function can accept several parameters, which will be discussed later.
UE4SS hooks execute after the hooked function has finished executing. We have the ability to inspect the return value, and override it.
Replacing a hook's return value is as simple as just using return
with the new return value. If you don't wanna touch it, you can just not use this directive in your hook.
Registering for object creation
However, for the RegisterHook
function to work, our object needs to already exist, so here's where another important function comes in: NotifyOnNewObject
.
This function will allow us to execute some code, when an object with a specified class gets created, the signature of the function is as follows:
NotifyOnNewObject(ObjectPath, Callback)
With the parameters being:
ObjectPath
- the path to the object we wanna watch for creation, we could get this from ue4ss LiveView.Callback
- the function we want to get called, when the given obejct gets created. This function accepts a single parameter which is the instance of the created object.
Writing our first hook
So for this simple example, we would want to write a snippet of code, which would scale down pals that we spawn from our party.
First of all, all our pals that are part of our party are called otomo
in this game, so we would like to find something related to that.
Aha! There's a BP_OtomoPalHolderComponent
, which is responsible for storing your party pals, and spawning them when requested to.
After looking throgh it's functions, we can find one with a signature like this:
void ActivateOtomo(int32 SlotID, FTransform StartTransform, bool& IsSuccess);