This is a complete guide on how to get started with the AddonHost and implement your own addon. It is build-system agnostic and avoids compiler-specific extensions where possible.
If all you need is an example, numerous Nexus addons are open source, notably:
Each addon loaded by Nexus is required to export a function matching the signature AddonDefinition_t* GetAddonDef(). See AddonDefinition_t for the full struct definition.
GetAddonDefFields not explicitly marked as optional are required.
Load() will be called when your addon is loaded and should initialize anything the addon needs. The AddonAPI* parameter will contain a version of the Nexus API matching the one specified in AddonDef.APIVersion. See AddonAPI_t for the current API definition.
Unload() will be called when the game shuts down, when your addon is updated, or when it is manually unloaded. If your addon must not be unloaded at runtime, set AddonDef.Flags to EAddonFlags::DisableHotloading.
If your addon is hosted on Raidcore, this should be the unique ID of your addon. If your addon is not hosted on Raidcore, it should be any negative integer.
If you do not use any Nexus API functions, set APIVersion to 0. If APIVersion is non-zero, it must be a current or previous NEXUS_API_VERSION.
It is recommended to store the addon API reference in a shared location so it can be accessed from any file that needs it. An example is shown below.
Shared.hShared.cppModuleMain.cppWhen AddonDefinition_t::Unload() is called, you should free any resources you have allocated (e.g. keybinds).
Nexus will attempt to clean up resources if you forget, but no guarantee is made that cleanup will be complete or correct.
To prevent memory leaks and other issues, always clean up after yourself.