Hooking:
Server-boot, battle->check_target points to battle_check_target.
HPM stores the original address of battle->check_target.
Plugins initialise, hooking to battle->check_target causes the address of battle->check_target to change from battle_check_target to HP_battle_check_target, so calling battle->check_target gets to HP_battle_check_target.
HP_battle_check_target triggers the pre plugin (if any), runs the original address (battle_check_target), triggers post plugins (if any), and returns.
--
int HP_battle_check_target( struct block_list *src, struct block_list *target,int flag) {
int retVal;
int i;
/* hooks.battle_check_target_pre -> int */
if( HPMHooks.count.HP_battle_check_target_pre ) {
for(i = 0; i < HPMHooks.count.HP_battle_check_target_pre; i++ ) {
retVal = (HPMHooks.list.HP_battle_check_target_pre[i])(src,target,&flag);
}
}
retVal = HPMHooks.source.battle.check_target(src,target,flag);
if( HPMHooks.count.HP_battle_check_target_post ) {
for(i = 0; i < HPMHooks.count.HP_battle_check_target_post; i++ ) {
retVal = (HPMHooks.list.HP_battle_check_target_post[i])(src,target,&flag,retVal);
}
}
return retVal;
}
--