Jump to content
  • 0
Sign in to follow this  
AnnieRuru

HPM Hooking return random value from the defined function

Question

need both patch and plugin to explain

 

patch

 src/map/pc.c | 2 ++ 1 file changed, 2 insertions(+)diff --git a/src/map/pc.c b/src/map/pc.cindex 2372d31..412c12b 100644--- a/src/map/pc.c+++ b/src/map/pc.c@@ -975,12 +975,14 @@ bool pc_authok(struct map_session_data *sd, int login_id2, time_t expiration_tim  	sd->login_id2 = login_id2; +ShowDebug ( "2. %s try to login. Value %d Group %d.", sd->status.name, group_id, sd->group_id ); 	if (pc->set_group(sd, group_id) != 0) { 		ShowWarning("pc_authok: %s (AID:%d) logged in with unknown group id (%d)! kicking...n", 			st->name, sd->status.account_id, group_id); 		clif->authfail_fd(sd->fd, 0); 		return false; 	}+ShowDebug ( "3. %s try to login. Value %d Group %d.", sd->status.name, group_id, sd->group_id );  	memcpy(&sd->status, st, sizeof(*st)); 
#include <stdio.h>#include <string.h>#include <stdlib.h>#include "../map/pc.h"#include "../common/HPMi.h"#include "../common/HPMDataCheck.h" /* should always be the last file included! (if you don't make it last, it'll intentionally break compile time) */HPExport struct hplugin_info pinfo = {	"maintenance",	// Plugin name	SERVER_TYPE_MAP,// Which server types this plugin works with?	"1.0",			// Plugin version	HPM_VERSION,	// HPM Version (don't change, macro is automatically updated)};bool pc_authok_pre( struct map_session_data *sd, int login_id2, time_t expiration_time, int group_id, struct mmo_charstatus *st, bool changing_mapservers ) {	ShowDebug ( "1. %s try to login. Value %d Group %d.", sd->status.name, group_id, sd->group_id );	if ( group_id < 99 ) {		clif->authfail_fd( sd->fd, 1 );		return false;	}	return true;}bool pc_authok_post( int retVal, struct map_session_data *sd, int login_id2, time_t expiration_time, int group_id, struct mmo_charstatus *st, bool changing_mapservers ) {	ShowDebug ( "4. %s try to login. Value %d Group %d.", sd->status.name, group_id, sd->group_id );	if ( sd->group_id < 99 ) {		clif->authfail_fd( sd->fd, 1 );		return false;	}	return true;}HPExport void plugin_init (void) {	clif = GET_SYMBOL("clif");	addHookPre( "pc->authok", pc_authok_pre );	addHookPost( "pc->authok", pc_authok_post );}
.

.

.

ok I need the group_id value, when I debug it with a normal char

[Debug]: 1. try to login. Value 90443865 Group 0.

[Debug]: 2. try to login. Value 0 Group 0.

[Debug]: 3. try to login. Value 0 Group 0.

[Debug]: 4. KinoRuru try to login. Value 90443865 Group 0.

then only got a kick

 

debug with a GM99 char

[Debug]: 1. try to login. Value 90443865 Group 0.

[Debug]: 2. try to login. Value 99 Group 0.

[Debug]: 3. try to login. Value 99 Group 99.

[Debug]: 4. AnnieRuru try to login. Value 90443865 Group 99.

and successfully login

 

the problem here is ... why is that when using patch,

the pc_authok function inside pc.c works fine, group_id returns the value correctly

 

but when using plugin,

no matter is pre-hook or post-hook, group_id value gives random-like value ?

 

 

my feeling tells me, there is some bug inside srcpluginsHPMHooking folder..

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

 

need both patch and plugin to explain

 

patch

 src/map/pc.c | 2 ++ 1 file changed, 2 insertions(+)diff --git a/src/map/pc.c b/src/map/pc.cindex 2372d31..412c12b 100644--- a/src/map/pc.c+++ b/src/map/pc.c@@ -975,12 +975,14 @@ bool pc_authok(struct map_session_data *sd, int login_id2, time_t expiration_tim  	sd->login_id2 = login_id2; +ShowDebug ( "2. %s try to login. Value %d Group %d.", sd->status.name, group_id, sd->group_id ); 	if (pc->set_group(sd, group_id) != 0) { 		ShowWarning("pc_authok: %s (AID:%d) logged in with unknown group id (%d)! kicking...n", 			st->name, sd->status.account_id, group_id); 		clif->authfail_fd(sd->fd, 0); 		return false; 	}+ShowDebug ( "3. %s try to login. Value %d Group %d.", sd->status.name, group_id, sd->group_id );  	memcpy(&sd->status, st, sizeof(*st)); 
#include <stdio.h>#include <string.h>#include <stdlib.h>#include "../map/pc.h"#include "../common/HPMi.h"#include "../common/HPMDataCheck.h" /* should always be the last file included! (if you don't make it last, it'll intentionally break compile time) */HPExport struct hplugin_info pinfo = {	"maintenance",	// Plugin name	SERVER_TYPE_MAP,// Which server types this plugin works with?	"1.0",			// Plugin version	HPM_VERSION,	// HPM Version (don't change, macro is automatically updated)};bool pc_authok_pre( struct map_session_data *sd, int login_id2, time_t expiration_time, int group_id, struct mmo_charstatus *st, bool changing_mapservers ) {	ShowDebug ( "1. %s try to login. Value %d Group %d.", sd->status.name, group_id, sd->group_id );	if ( group_id < 99 ) {		clif->authfail_fd( sd->fd, 1 );		return false;	}	return true;}bool pc_authok_post( int retVal, struct map_session_data *sd, int login_id2, time_t expiration_time, int group_id, struct mmo_charstatus *st, bool changing_mapservers ) {	ShowDebug ( "4. %s try to login. Value %d Group %d.", sd->status.name, group_id, sd->group_id );	if ( sd->group_id < 99 ) {		clif->authfail_fd( sd->fd, 1 );		return false;	}	return true;}HPExport void plugin_init (void) {	clif = GET_SYMBOL("clif");	addHookPre( "pc->authok", pc_authok_pre );	addHookPost( "pc->authok", pc_authok_post );}
.

.

.

ok I need the group_id value, when I debug it with a normal char

[Debug]: 1. try to login. Value 90443865 Group 0.

[Debug]: 2. try to login. Value 0 Group 0.

[Debug]: 3. try to login. Value 0 Group 0.

[Debug]: 4. KinoRuru try to login. Value 90443865 Group 0.

then only got a kick

 

debug with a GM99 char

[Debug]: 1. try to login. Value 90443865 Group 0.

[Debug]: 2. try to login. Value 99 Group 0.

[Debug]: 3. try to login. Value 99 Group 99.

[Debug]: 4. AnnieRuru try to login. Value 90443865 Group 99.

and successfully login

 

the problem here is ... why is that when using patch,

the pc_authok function inside pc.c works fine, group_id returns the value correctly

 

but when using plugin,

no matter is pre-hook or post-hook, group_id value gives random-like value ?

 

 

my feeling tells me, there is some bug inside srcpluginsHPMHooking folder..

 

 

 

maybe group_id will retrun memory address , try using  *group_id instead

bool pc_authok_post( int retVal, struct map_session_data *sd, int *login_id2, time_t *expiration_time, int *group_id, struct mmo_charstatus *st, bool *changing_mapservers ) {	ShowDebug ( "4. %s try to login. Value %d Group %d.", sd->status.name, *group_id, sd->group_id );	if ( sd->group_id < 99 ) {		clif->authfail_fd( sd->fd, 1 );		return false;	}	return true;}
Edited by Angelmelody

Share this post


Link to post
Share on other sites
  • 0

tried that

[Debug]: 4. EnnyRuru try to login. Value 150001 Group 99.

[Debug]: 4. RimuRuru try to login. Value 150005 Group 0.

 

weird, why it display their char_id instead of group id

opsss ~ forgot to change 'time_t expiration_time' into 'time_t *expiration_time'

 

now this is working

#include <stdio.h>#include <string.h>#include <stdlib.h>#include "../map/pc.h"#include "../common/HPMi.h"#include "../common/HPMDataCheck.h" /* should always be the last file included! (if you don't make it last, it'll intentionally break compile time) */HPExport struct hplugin_info pinfo = {	"maintenance",	// Plugin name	SERVER_TYPE_MAP,// Which server types this plugin works with?	"1.0",			// Plugin version	HPM_VERSION,	// HPM Version (don't change, macro is automatically updated)};bool pc_authok_pre( struct map_session_data *sd, int *login_id2, time_t *expiration_time, int *group_id, struct mmo_charstatus *st, bool *changing_mapservers ) {//	ShowDebug ( "1. %s try to login. Value %d Group %d.", sd->status.name, group_id, sd->group_id );//	ShowDebug ( "1. %s try to login. Value %d Group %d.", sd->status.name, &group_id, sd->group_id );	ShowDebug ( "1. %s try to login. Value %d Group %d.", sd->status.name, *group_id, sd->group_id );	if ( *group_id < 99 ) {		clif->authfail_fd( sd->fd, 1 );		return false;	}	return true;}bool pc_authok_post( int retVal, struct map_session_data *sd, int *login_id2, time_t *expiration_time, int *group_id, struct mmo_charstatus *st, bool *changing_mapservers ) {//	ShowDebug ( "4. %s try to login. Value %d Group %d.", sd->status.name, group_id, sd->group_id );//	ShowDebug ( "4. %s try to login. Value %d Group %d.", sd->status.name, &group_id, sd->group_id );	ShowDebug ( "4. %s try to login. Value %d Group %d.", sd->status.name, *group_id, sd->group_id );	if ( sd->group_id < 99 ) {		clif->authfail_fd( sd->fd, 1 );		return false;	}	return true;}HPExport void plugin_init (void) {	clif = GET_SYMBOL("clif");	addHookPre( "pc->authok", pc_authok_pre );	addHookPost( "pc->authok", pc_authok_post );}
it seems that I didn't read the documentation properly

http://herc.ws/wiki/Hercules_Plugin_Manager#HPM_Hooks

Edited by AnnieRuru

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

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