ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Hooks Not Working (https://www.esoui.com/forums/showthread.php?t=9535)

QuantumPie 01/03/21 04:32 PM

Hooks Not Working
 
I'm attempting to make a custom UI for the achievement panel and the first change I want to make is modifying the summary progress bars. On ESOUI's repo, I found that line 1546 in this file is what initializes the summary. Shortly after that is what updates it. I want to hook into these two functions, and I'm attempting to do that via:

Lua Code:
  1. function addon:Test()
  2.     ZO_PreHook(ACHIEVEMENTS, "InitializeSummary", function()
  3.         d("Inside the init hook!")
  4.         --return true
  5.     end)
  6.     ZO_PreHook(ACHIEVEMENTS, "UpdateSummary", function()
  7.         d("Inside the update hook!")
  8.         --return true
  9.     end)
  10.     d("In test!")
  11. end
I'm getting the output for printing "In test!" but I don't see anything for the hooks. Am I doing something incorrectly or can we not hook into these functions?

Baertram 01/03/21 04:51 PM

The hook should work as the ACHIEVEMENTS global exists, is the correct object of the Achievment class.
I've read the code this way:
https://github.com/esoui/esoui/blob/...ents.lua#L1893

Called by the XML's OnInitialized event -> ZO_Achievements_OnInitialize(self) -> ACHIEVEMENTS = Achievements:New(self) ->
https://github.com/esoui/esoui/blob/...ments.lua#L949
-> object:Initialize(...) -> https://github.com/esoui/esoui/blob/...ments.lua#L963
-> function Achievements:Initialize(control) -> self:InitializeSummary()
-> function Achievements:InitializeSummary()

Maybe it was done before the chat output is ready so you are not seeing it (will first be visible at event_player_activated!).
-> Install the addon pChat which should fix this.
-> OR/AND use the LibDebugLogger and the DebugLogViewer UI to see the addon debug messages prior the chat output is ready + stored in your SavedVariables.

Edit1: I've added your code to any of my addons event_player_activated callback function and I also do not see it.

Edit2:
I think it is because the Achievements "class" is defined local:
--[[ Achievements ]]--
local Achievements = ZO_Object:Subclass()

And it's not a ZO_Achievements global variable. I guess this is intended so noone can manipulate the summaries etc.

The only globals are the ones at the bottom of the file below
--[[ XML Handlers ]]--

QuantumPie 01/03/21 05:08 PM

Quote:

Originally Posted by Baertram (Post 42955)
The hook should work as the ACHIEVEMENTS global exists, is the correct object of the Achievment class.
I've read the code this way:
https://github.com/esoui/esoui/blob/...ents.lua#L1893

Called by the XML's OnInitialized event -> ZO_Achievements_OnInitialize(self) -> ACHIEVEMENTS = Achievements:New(self) ->
https://github.com/esoui/esoui/blob/...ments.lua#L949
-> object:Initialize(...) -> https://github.com/esoui/esoui/blob/...ments.lua#L963
-> function Achievements:Initialize(control) -> self:InitializeSummary()
-> function Achievements:InitializeSummary()


Try to use MerTorchbug Updated or zgoo to inspect the ACHIEVEMENTS table if the function InitializeSummary is given (maybe below the __index sub-metatables) and try to run it via SHIFT or CTRL+click. Does your d() mesages show then? Or if you explicitly call it like
/tb ACHIEVEMENTS:InitializeSummary()

Or it was done before the chat output is ready so you are not seeing it (will first be visible at event_player_activated!).
-> Install the addon pChat which should fix this.
-> OR/AND use the LibDebugLogger and the DebugLogViewer UI to see the addon debug messages prior the chat output is ready + stored in your SavedVariables.

But: I've added your code to any of my addons event_player_activated callback function and I also do not see it.
So maybe it's a oo generic achievement class you try to hook there.
Or you expect this to be something that is not the UI element you want to get into depth with?

Manually calling the function showed the output. LibDebugLogger is what I was already using to inspect the chat output. Do I need to set the time to "Current Session"? When I did that, I saw thousands of prints along the line of "Avoiding cycle on table..." which originated from my addon.

Stacktrace:
Lua Code:
  1. .              Avoiding cycle on table...
  2. |rstack traceback:
  3. user:/AddOns/LibDebugLogger/Initialization.lua:80: in function 'LogChatMessage'
  4. EsoUI/Libraries/Utility/ZO_Hook.lua:18: in function 'AddDebugMessage'
  5. EsoUI/Libraries/Globals/DebugUtils.lua:7: in function 'EmitMessage'
  6. EsoUI/Libraries/Globals/DebugUtils.lua:27: in function 'EmitTable'
  7. EsoUI/Libraries/Globals/DebugUtils.lua:30: in function 'EmitTable'
  8. EsoUI/Libraries/Globals/DebugUtils.lua:30: in function 'EmitTable'
  9. EsoUI/Libraries/Globals/DebugUtils.lua:30: in function 'EmitTable'
  10. EsoUI/Libraries/Globals/DebugUtils.lua:30: in function 'EmitTable'
  11. EsoUI/Libraries/Globals/DebugUtils.lua:30: in function 'EmitTable'
  12. EsoUI/Libraries/Globals/DebugUtils.lua:30: in function 'EmitTable'
  13. EsoUI/Libraries/Globals/DebugUtils.lua:30: in function 'EmitTable'
  14. EsoUI/Libraries/Globals/DebugUtils.lua:41: in function 'd'
  15. user:/AddOns/QuantumsGlobalAchievements/QuantumsGlobalAchievements.lua:12: in function 'addon:Test'
  16. user:/AddOns/QuantumsGlobalAchievements/QuantumsGlobalAchievements.lua:25: in function 'addon:Initialize'
  17. user:/AddOns/QuantumsGlobalAchievements/QuantumsGlobalAchievements.lua:32: in function 'OnAddOnLoaded'

QuantumPie 01/03/21 05:21 PM

Interestingly commenting out the print and un-commenting return true in the hook yields the same error. The UI of the summary also remained intact, assuming the proper behavior was to not generate it since the hook cancelled the default function from running.

Baertram 01/04/21 04:38 AM

Current session in LDL only says from start of the game client to end of the game client.
Current UI reload only shows what was added since you did a reloadui -> Should be enough for testing imo.

"Avoiding cycle on table" is a debug output of the d() function in eso source code.
function d(...)
for i = 1, select("#", ...) do
local value = select(i, ...)
if(type(value) == "table")
then
EmitTable(value)
else
EmitMessage(tostring (value))
end
end
end

Within EmitTable then:
if(tableHistory[v])
then
EmitMessage(indent.."Avoiding cycle on table...")

It shows you that the d() output somehow triggered a table and no String to show in chat. > Your line 12 in file QuantumsGlobalAchievements.lua
So one of your parameters in your d calls seems to be a table, or at least gets recognized as a table.

votan 01/04/21 06:46 AM

InitializeSummary is called in Initialize, which is called from XML.
This built-in code runs before any addon code. Your hook is and will be too late.

UpdateSummary is called, if the category is re-selected. So, you have to click to another category and go back.


All times are GMT -6. The time now is 11:34 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI