Add a ZO_PreHook to the logout and/or quit function instead or in addition.
They will be called as you logout/quit by the menu or /logout slash command or /quit slash command
PreHooks will be called before the original functions are called. So you can add your callback function there, like you add it to an event, and it will run your code first, and then the original code.
Make sure you DO NOT "return true" in your prehook or it will cancel all following coe, including vanilla game code (like the logout or quit).
To find the logout and quit functions to hook into:
Search the esoui sources (
https://github.com/esoui/esoui/tree/master/esoui) for the quit and/or logout to find the function names.
If you search for logout e.g. you'll find
ShowLogoutDialog
which is local and locals cannot be hooked into! So you need to find the global function (API function) used to call that dialog function ShowLogoutDialog -> OnLogoutDeferred (local too) ->
Code:
EVENT_MANAGER:RegisterForEvent("Globals", EVENT_LOGOUT_DEFERRED, OnLogoutDeferred)
EVENT_MANAGER:RegisterForEvent("Globals", EVENT_LOGOUT_DISALLOWED, OnLogoutDisallowed)
-> Here you got 2 other events to maybe use instead of a ZO_PreHook
There does not seem to exist any global variable to hook into, but the dialog names are shown in the code:
https://github.com/esoui/esoui/blob/...lobals.lua#L25
LOGOUT_DEFERRED
QUIT_DEFERRED
If you search for those you'll find the definition of these dialogs and it's "Yes" button's callback function, which should be the logout/quit function then.
I did find a function "Logout" and "Quit" e.g. that way, and a preHook would look like this then:
Lua Code:
local function myLogoutOrQuitHandler()
--do your savedvariables update of companion stuff here
end
ZO_PreHook("Logout", function()
myLogoutOrQuitHandler()
end)
ZO_PreHook("Quit", function()
myLogoutOrQuitHandler()
end)
References:
https://github.com/esoui/esoui/blob/...logs.lua#L1841
https://github.com/esoui/esoui/blob/...hared.lua#L139
https://github.com/esoui/esoui/blob/...ands_pc.lua#L1
https://github.com/esoui/esoui/blob/...yboard.lua#L37