View Single Post
11/23/21, 11:09 AM   #1
@DeadSoon
AddOn Author - Click to view addons
Join Date: Sep 2018
Posts: 22
Secure Protected Function "UseItem"

Hello,

I know there are a lot of posts about the topic of protected functions. However, I have a question on a concrete example/issue what I do not understand:

I want to intersect the use of an item in special cases (if the player clicks on an item in the inventory). Thefore, I have a prehook on the protected function "UseItem", following the approach of "ZO_PreHookProtected" from here. My pre-hooking function returns true in the case that I want to intersect/prevent the "UseItem" call, in all other cases it returns false (pass execution).

Because UseItem is a proteced function, this works fine for all cases out of combat.


Now the issue:
Without prehook in place, it is possible to use items even in combat (open inventory and click on an item!). Although, I know that "UseItem" is called and it shouldnt because it is protected. However, it seems that ZOS has built its own exception.

With the prehook in place, it is no longer possible to use items from the inventory while in combat. I can observe that my prehook is called and even if my function returns false to let the function pass without modifying anything, the item is not be used. Simply, nothing happens.

Now my question:
  1. Can anyone explain this behavior to me?
  2. Even if ZOS has its own exception in place, why does my pre-hooking function breaks the "UseItem" call in combat?
  3. Do you have an idea, how I can keep my prehook for UseItem (in practice: whenever the player tries to use an item from the inventory) but at the same time fix the issue, that the player cannot use items in combat any longer?

Thank you so much in advance!
Best regards
  Reply With Quote