Skip to content

Commit 04c247a

Browse files
authored
Merge pull request #358 from PiggyChu620/patch-1
Update hooking.adoc
2 parents 33be512 + d0c3b95 commit 04c247a

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

modules/ROOT/pages/Development/Cpp/hooking.adoc

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
= Hooking
22

3-
Hooking is a {cpp} exclusive feature of SML that allows you to attach a custom function body to a existing function.
3+
Hooking is a {cpp} exclusive feature of SML that allows you to attach a custom function body to an existing function.
44

55
All C/{cpp} functioning hooking stuff can be found in `#include "Patching/NativeHookManager.h"`.
66
All Blueprint function hook stuff can be found in `#include "Patching/BlueprintHookManager.h"`.
@@ -15,8 +15,8 @@ SML's hooking interface provides distinct 3 ways of hooking functions, each of w
1515

1616
If multiple hooks are attached to the same function, these hooks will then get called in the order they were registered.
1717

18-
There is a normal hook which gets called before the actual function gets called.
19-
Through this hook you are able to prevent the final function call and you are also able to overwrite the return value.
18+
There is a normal hook that gets called before the actual function gets called.
19+
Through this hook, you are able to prevent the final function call and you are also able to overwrite the return value.
2020
If you cancel the execution of the final function, you can prevent the following hooks from being called.
2121
Keep in mind that this means that another hook can prevent your hooks from being called by Satisfactory.
2222
The normal hook's signature is `void(TCallScope<HookFuncSignature>&, hookFuncParams)`.
@@ -57,12 +57,12 @@ void hook(TCallScope<int(int)>& Scope, class* exampleClass, int exampleArg) {
5757
----
5858

5959
Since you still want to make sure your hook gets called,
60-
no care about if the final function got called or not we introduce the "after" hooks.
60+
no care about whether the final function got called or not we introduce the "after" hooks.
6161
These hooks get all called after the normal hook calls and only allow you to
6262
read the parameters as well as the resulting return value.
6363
That means you can't influence the final function call.
6464
Also, don't use the TCallScope object, instead the first parameter of your hooks signature
65-
is the return value following by the function call parameters.
65+
is the return value followed by the function call parameters.
6666

6767
[source,cpp]
6868
----
@@ -76,7 +76,7 @@ void hook(int returnValue, int exampleArg) {
7676
By 'hook types' we mean the different ways of attaching a hook to a function.
7777
Each attachment method works differently under the hood, and it's important to pay attention to the key differences between the different types of hooks.
7878

79-
Be aware that type of return values and parameters etc has nothing to do with each other or if it is a member function, you can use them in any way.
79+
Be aware that the type of return values and parameters etc has nothing to do with each other or if it is a member function, you can use them in any way.
8080
Note that the Hook function is a std::function, which means that it can be any type a std::function can accept, such as function pointers, function pointers with bound placeholders, or even lambdas.
8181

8282
[IMPORTANT]
@@ -94,7 +94,7 @@ if (!WITH_EDITOR) {
9494
}
9595
----
9696
97-
Using `#if !WITH_EDITOR` and `#endif` directives is also an option, but it is not recommended: it hides errors until building shipping and confuses IDEs, making development and debugging slightly more annoying with no benefit.
97+
Using `#if !WITH_EDITOR` and `#endif` directives are also an option, but it is not recommended: they hide errors until building shipping and confuse IDEs, making development and debugging slightly more annoying with no benefit.
9898
====
9999

100100
=== Type: SUBSCRIBE_METHOD
@@ -105,7 +105,7 @@ such that the code you pass will be called before the function executes.
105105
If multiple mods have subscribed to the same function,
106106
the hooks will be called in the order they were registered.
107107

108-
Usage goes as following:
108+
Usage goes as follows:
109109

110110
[source,cpp]
111111
----
@@ -131,7 +131,7 @@ void registerHooks() {
131131
[WARNING]
132132
====
133133
Hooking an overloaded function might not work as intended since the compiler has no clue what exact symbol you now want to hook.
134-
For that you should have an look at the `SUBSCRIBE_METHOD_MANUAL`-Macro which allows you
134+
For that, you should have a look at the `SUBSCRIBE_METHOD_MANUAL`-Macro which allows you
135135
to explicitly set the symbol you want to hook.
136136
====
137137

@@ -145,7 +145,7 @@ but the hook will still run if the hooked function is called by the overriding i
145145
If the overriding implementation of a subclass does not "call super", you have to hook said subclass separately.
146146
Because pure virtual functions do not have a proper function body, they cannot possibly be hooked.
147147

148-
Usage goes as following:
148+
Usage goes as follows:
149149

150150
[source,cpp]
151151
----
@@ -162,7 +162,7 @@ public:
162162
#include "Patching/NativeHookManager.h"
163163
164164
void registerHooks() {
165-
SomeClass* SampleObject = new SomeClass(); // For UObject derived classes, use SUBSCRIBE_UOBJECT_METHOD instead
165+
SomeClass* SampleObject = GetMutableDefault<SomeClass>(); // For UObject derived classes, use SUBSCRIBE_UOBJECT_METHOD instead
166166
SUBSCRIBE_METHOD_VIRTUAL(SomeClass::MemberFunction, SampleObject, [](auto& scope, SomeClass* self, int arg1) {
167167
// do some nice stuff there
168168
});
@@ -192,8 +192,10 @@ For "after" hooks, add the `_AFTER` postfix to the macro names.
192192

193193
Be aware that the hook function signature changes accordingly and will no longer need the "scope":
194194
[horizontal]
195-
*Non-Virtual*:: `SUBSCRIBE_METHOD_AFTER(SomeClass::MemberFunction, [](SomeClass* self))`
196-
*Virtual*:: `SUBSCRIBE_METHOD_VIRTUAL_AFTER(SomeClass::MemberFunction, [](SomeClass* self))`
195+
*Non-Virtual*:: `SUBSCRIBE_METHOD_AFTER(SomeClass::MemberFunction, []([*return value by reference,*] SomeClass* self [*,parameters*]))`
196+
*Virtual*:: `SUBSCRIBE_METHOD_VIRTUAL_AFTER(SomeClass::MemberFunction, []([*return value by reference,*] SomeClass* self [*,parameters*]))`
197+
198+
**★ [*return value by reference,*] and [*,parameters*] are to be replaced if present, do NOT leave it as is!**
197199

198200
==== FORCEINLINE Functions
199201

0 commit comments

Comments
 (0)