-
Notifications
You must be signed in to change notification settings - Fork 39
Miscellanous Explanatory Stuff
Some helper functions for writing hooks are provided in SFSE/Utilities.h.
This function allows writing call site hooks and accepts two template parameters: your hook class, and an integer argument passed to the write_call function. write_call<5> is used in the majority of cases, so write_thunk_call defaults to 5 (e.g.: write_thunk_call<MyHook>()). In some cases, you need 6 bytes--you may specify write_thunk_call<MyHook, 6>() in these cases. The following is an example of a hook class passed to write_thunk_call:
TODO: class example
This function allows writing virtual method swaps and accepts two template parameters: the destination class (whose vtable we want to hook), and your hook class (e.g.: write_vfunc<RE::PlayerCharacter, MyHook>()). Several variants of write_vfunc are provided to allow selecting a specific vtable for classes with multiple vtables and so on; see SFSE/Utilities.h for the definitions of the variants. The following is an example of a hook class passed to write_vfunc:
class MyHook
{
public:
static HookReturnType Thunk(<args...>); // reverse-engineered function signature
inline static REL::Relocation<decltype(&Thunk)> func;
static constexpr std::size_t idx{ 42 }; // vtable index of the vfunc we want to swap
}NOTE: HookReturnType is a placeholder type
A custom CMake command, add_commonlibsf_plugin, is provided which takes care of several housekeeping tasks for plugin projects. The command accepts the following parameters:
- Optional:
USE_ADDRESS_LIBRARY,USE_SIGNATURE_SCANNING,STRUCT_DEPENDENT,EXCLUDE_FROM_ALL - Single value args:
NAME,AUTHOR,VERSION,MINIMUM_SFSE_VERSION - Multi value args:
COMPATIBLE_RUNTIMES,SOURCES
This command generates a plugin declaration, Plugin.h, which includes the plugin name, version, etc., as well as an exported SFSEPlugin_Version function for SFSE to use with all the appropriate fields filled in.
Example call:
add_commonlibsf_plugin(
${PROJECT_NAME}
AUTHOR AuthorName
SOURCES ${headers} ${sources}
)