View Single Post
01/09/23, 06:07 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
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:
  1. local function myLogoutOrQuitHandler()
  2.   --do your savedvariables update of companion stuff here
  3. end
  4.  
  5. ZO_PreHook("Logout", function()
  6.   myLogoutOrQuitHandler()
  7. end)
  8.  
  9. ZO_PreHook("Quit", function()
  10.   myLogoutOrQuitHandler()
  11. 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

Last edited by Baertram : 01/09/23 at 06:21 AM.
  Reply With Quote