Thread Tools Display Modes
03/28/24, 04:25 PM   #1
SSM24
 
SSM24's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2023
Posts: 4
Question about CallSecureProtected

I was looking at the API page and I noticed it says this:

To call a protected function, you must use the following code :

Lua Code:
  1. if IsProtectedFunction("TheNameOfYourFunction") then
  2.     CallSecureProtected("TheNameOfYourFunction", arg1, arg2, arg3)
  3. else
  4.     TheNameOfYourFunction(arg1, arg2, arg3)
  5. end
However in the past I've simply just used CallSecureProtected without checking IsProtectedFunction first (specifically when I used RequestMoveItem in Restock Bank Materials) and I haven't run into issues or had any reported. But it says on the API page you "must" use that first form, in bold and everything. Out of curiosity, what exactly is the benefit of doing so? Is it just for forward compatibility in case they un-protect an API function in the future, or is there another reason?
  Reply With Quote
03/28/24, 04:58 PM   #2
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
I remember asking ZOS that same question a long time ago and they where as surprised to see this code as you are.
The only reason we could think of is that whoever originally wrote it was using one of the game launchers that allowed to circumvent the security system of the api (which is obviously against the TOS) to call protected and private functions just as normal functions from addon code and everyone else just copied it without understanding it.
Guess nobody bothered updating the wiki afterwards.
  Reply With Quote
03/28/24, 08:02 PM   #3
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
I remember (several years ago though) that calling a secure function directly, without using CallSecureProtected(funcName, ...), was raising lua errors?
  Reply With Quote
03/29/24, 05:46 AM   #4
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
Originally Posted by Baertram View Post
I remember (several years ago though) that calling a secure function directly, without using CallSecureProtected(funcName, ...), was raising lua errors?
It does. The point is, you don't need to warp it in the "if IsProtectedFunction", since that would always be true, unless you use a hacked game client.
  Reply With Quote
03/29/24, 11:51 AM   #5
ZOS_DanBatson
ZOS Staff!
 
ZOS_DanBatson's Avatar
Yes this person is from ZeniMax!
Join Date: Jul 2015
Posts: 181
If you call a function with CallSecureProtected and the function is not a protected function, then it will fail. You don't specifically have to check if it's protected if you already know from the documentation that it's protected, although if you just assume it is and we change it later to no longer be protected your code will suddenly break if you're not checking first. So, you know, caveat emptor. CallSecureProtected returns a bool telling you if it worked, and if it didn't, it returns a string explaining what what wrong.

Also just as a reminder, protected just means you can't call it during combat. Private means you can't call it at all.
  Reply With Quote
03/29/24, 04:28 PM   #6
SSM24
 
SSM24's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2023
Posts: 4
Originally Posted by ZOS_DanBatson View Post
If you call a function with CallSecureProtected and the function is not a protected function, then it will fail. You don't specifically have to check if it's protected if you already know from the documentation that it's protected, although if you just assume it is and we change it later to no longer be protected your code will suddenly break if you're not checking first. So, you know, caveat emptor. CallSecureProtected returns a bool telling you if it worked, and if it didn't, it returns a string explaining what what wrong.

Also just as a reminder, protected just means you can't call it during combat. Private means you can't call it at all.
So essentially I was correct then, the only real benefit of doing it this way is potential forward compatibility. It sounds like this would also apply equally to unprotected functions if they become protected in the future, at which point stuff would break anyway (and probably in an even more widespread way), so probably not worth worrying too much about. Thanks!
  Reply With Quote
03/30/24, 03:21 PM   #7
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
Thanks for the explanation Dan, updated the Wiki too.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Question about CallSecureProtected


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off