• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

"hook" what is that?

Status
Not open for further replies.
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
 
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
 
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
 
^ 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.
 
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.
Back
Top