• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

"hook" what is that?

Status
Not open for further replies.
Level 23
Joined
Apr 16, 2012
Messages
4,041
if you do for instance:

JASS:
function func takes unit u returns nothing
endfunction

hook KillUnit func

it will go over the map script and overwrite all KillUnit function calls to func function calls and then call the KillUnit one.
You can only hook natives and BJs.

The disadvantage of this is it does a trigger evaluations so its not that fast

PS: Im not sure if the syntax is the same, but I know that the function you want to hook must have the same arguments as the hooked one
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
the thing is, it will call your function and after that the hooked function, so in this case it would run:
JASS:
KillUnit(GetTriggerUnit())
RemoveUnit(...)

and this is compiling error because rawr must take the same arguments as RemoveUnit does (unit)
 
Level 3
Joined
Nov 8, 2009
Messages
39
So, let's say you want to hook the KillUnit native into a function that resurrects the unit as a skeleton (only at night :vw_sleep:). Is it possible to then unhook it at daybreak? I'm trying to get a better sense of exactly how this works, because it could be really useful for avoiding lots of conditionals when working with global gamestates such as time of day, upgrade thresholds, etc.
 
^ Wrong.

As of what edo said,this replaces the function of the function you want to be hooked.

Example:
JASS:
function Hello takes nothing returns nothing
    call BJDebugMsg("Hello")
endfunction

hook DoNothing Hello


function UseDoNothing takes nothing returns nothing
    call DoNothing()// This prints Hello
endfunction

in the example above,DoNothing is replaced with Hello function,losing DoNothing's original function
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
actually thats not totally true, it is not replaced, the DoNothing still runs after your print function, try compile the hook and you will see
wtill hook is not good because it generates trigger evaluations

and because how hook works, your code would not work because the KillUnit runs after your ressurection function
 
Level 3
Joined
Nov 8, 2009
Messages
39
^ Wrong.

As of what edo said,this replaces the function of the function you want to be hooked.

Example:
JASS:
function Hello takes nothing returns nothing
    call BJDebugMsg("Hello")
endfunction

hook DoNothing Hello

function UseDoNothing takes nothing returns nothing
    call DoNothing()// This prints Hello
endfunction

in the example above,DoNothing is replaced with Hello function,losing DoNothing's original function

That wasn't my question, though. I was asking if it is possible to undo the hook during run-time, either by hooking it to a different function, or by issuing some sort of "unhook" command.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
actuqlly you could dynamically stop it, because it does trigger evaluations you could disable the trigger and later on enable it
however during the time trigger is disabled you will not make thr natives run so I dont recommend doing it
 
Well, there is no need to actually disable the trigger that goes for the hook. All you need is a simple condition.
JASS:
globals
    boolean theTimeIsNow = false
endglobals

function Example takes unit u returns nothing
    if ( theTimeIsNow ) then
        // do actions
    endif
endfunction

hook RemoveUnit Example

If the boolean returns false, then it won't do anything extra aside from executing RemoveUnit(). It will, of course, still apply the evaluation.

However, I consider hooks an unfinished feature. As edo said, it doesn't replace the function, but rather it performs the function and then adds to it. In my opinion, it should just completely rewrite the function and replace all instances of calling that function in the map to become the new one. This way you could prevent certain natives from being called. Maybe Frotty will eventually implement better hooks into Wurst. Maybe not.
 
Status
Not open for further replies.
Top