Jump to content
  • 0
Sign in to follow this  
bWolfie

Help overwriting something for plugin

Question

Hello, I want to overwrite a function.

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:

addHookPre(atcommand, exec, atcommand_exec_pre);

I get this error:

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);

Edited by Myriad

Share this post


Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0

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.

 

Share this post


Link to post
Share on other sites
  • 0

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.

    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;
    }

Edited by Myriad

Share this post


Link to post
Share on other sites
  • 0

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.

Share this post


Link to post
Share on other sites
  • 0

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

This is what I changed code to:

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:

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);
  ^

Share this post


Link to post
Share on other sites
  • 0

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

Share this post


Link to post
Share on other sites
  • 0
15 hours ago, 4144 said:

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. :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.