Help overwriting something for plugin

bWolfie

I'm the man
Messages
850
Points
0
Location
Alberta, Midgard
Github
bWolfie
Emulator
Hello, I want to overwrite a function.

Code:
bool atcommand_exec_pre(const int fd, struct map_session_data *sd, const char *message, bool player_invoked)
I make all the changes to my code, then I try to hook.

This is not working for me:

Code:
addHookPre(atcommand, exec, atcommand_exec_pre);
I get this error:

Code:
atcommand.c: In function ‘atcommand_exec_pre’:
atcommand.c:1510:21: error: ‘atcommand_autotrade’ undeclared (first use in this function)
   if (info->func == atcommand_autotrade) /* autotrade deletes caster, so we got nothing more to do here */
                     ^
atcommand.c:1510:21: note: each undeclared identifier is reported only once for each function it appears in
atcommand.c: In function ‘plugin_init’:
atcommand.c:1555:2: warning: implicit declaration of function ‘addHookPre’ [-Wimplicit-function-declaration]
  addHookPre(atcommand, exec, atcommand_exec_pre);
  ^
atcommand.c:1555:2: warning: nested extern declaration of ‘addHookPre’ [-Wnested-externs]
atcommand.c:1555:24: error: ‘exec’ undeclared (first use in this function)
  addHookPre(atcommand, exec, atcommand_exec_pre);
 
Last edited by a moderator:
Errors log show all issues what you have.

This is "undeclared (first use in this function)". And this mean need add missing includes into your plugin.

Also atcommand_autotrade not exists in plugins, because this is private function. You need other way for detect it.

Also why you hooking atcommand->exec? And if hooking it why copy all code from it to plugin? I think exists better ways for do this.

 
Thanks for your response @4144. I am trying to convert all my source edits into plugin format. Still trying to learn how to use them. This one I am having trouble with.

I want to edit just this particular area in that bool.

Code:
    if (info == NULL) { // I want to edit this 'if' clause
        if (pc_get_group_level(sd) == 0) // TODO: remove or replace with proper permission // remove this line
            return false; // remove this line
        sprintf(output, msg_fd(fd,153), command); // "%s is Unknown Command."
        clif->message(fd, output);
        atcommand->get_suggestions(sd, command + 1, is_atcommand);
        return true;
    }
 
Last edited by a moderator:
Hm, yes atcommand_exec not very optimal for this. You can copy to your pre hook almost whole of this function from start to this if lines.

 
Thanks for help 4144 so far. Seems it compiles now, just with 1 error left to resolve.

This is what I changed code to:

Code:
bool atcommand_exec_pre(const int fd, struct map_session_data *sd, const char *message, bool player_invoked)
//...all in between code here
    if (info == NULL)
        {
            sprintf(output, msg_fd(fd,153), command); // "%s is Unknown Command."
            clif->message(fd, output);
            atcommand->get_suggestions(sd, command + 1, is_atcommand);
            return true;
        }
    hookStop();
    return 0;
}
HPExport void plugin_init (void)
{
     addHookPre(atcommand, exec, atcommand_exec_pre);
}
Error code:

Code:
atcommand.c: In function ‘plugin_init’:
../plugins/HPMHooking.h:49:53: warning: comparison of distinct pointer types lacks a cast [enabled by default]
   (void)((HPMHOOK_pre_ ## ifname ## _ ## funcname)0 == (hook)), \
                                                     ^
atcommand.c:1580:2: note: in expansion of macro ‘addHookPre’
  addHookPre(atcommand, exec, atcommand_exec_pre);
  ^
 
this error mean what your function prototype is wrong.

For pre hooks almost all parameters should be pointers to same parameters from normal function.

For example if was "const int fd", should be "int *const fd" or "int *fd"

was "struct map_session_data *sd" should be "struct map_session_data **sd"

etc

 
this error mean what your function prototype is wrong.

For pre hooks almost all parameters should be pointers to same parameters from normal function.

For example if was "const int fd", should be "int *const fd" or "int *fd"

was "struct map_session_data *sd" should be "struct map_session_data **sd"

etc
thank you for the help. i realised I can ctrl+f in HPMHooking_map.Hooks.inc to find the structure needed. Compiled well this time. :)

 
Back
Top