Jump to content

c++ Library Hooking Problem


Go to solution Solved by Tasho,

Recommended Posts

Hi to all,

I am coding a library for hooking some functions in game, its okay while i am not using aditional definitions on character class i mean ;

 

class iCHARACTER: public CHARACTER{
  public:
    int m_counterxxx;
  public:
    void ban(long len, const char* reason, const char* by);
};
#endif // __GAME_ICHARACTER_HPP
/////////////////////////////////////////////////iCHARACTER.hpp

namespace Hooks{
MoveHook::MoveHook():Hook::Hook() {
    // default config
}

void MoveHook::hook(CInputMain* self, iCHARACTER* ch, const char * data) {
    if (ch->m_counterxxx == 100)
        ch->m_counterxxx = 0;
    
    ch->m_counterxxx++;

instance()->detour->GetOriginalFunction()(self,ch,data);
}
}

//MoveHook.cpp

 

if i wont use ch->m_counterxxx pointer there isnt any problem but when i use it while i am playing its ok, but when i exit the game, game creates a core.

 

gdb : 

#0  CItem::SetSkipSave (b=<optimized out>, this=<optimized out>) at item.h:141
#1  CHARACTER::ClearItem (this=0x5342f000) at char_item.cpp:532
#2  0x0807bb7c in CHARACTER::Destroy (this=0x5342f000) at char.cpp:509
#3  0x0807bbf6 in CHARACTER::~CHARACTER (this=0x5342f000,
    __in_chrg=<optimized out>) at char.cpp:138
#4  0x080b49ae in CHARACTER_MANAGER::DestroyCharacter (this=0xbfbfd424,
    ch=0x5342f000) at char_manager.cpp:169
#5  0x0807e292 in CHARACTER::Disconnect (this=0x5342f000,
    c_pszReason=0x8395afb "DESC::~DESC") at char.cpp:1533
#6  0x0810c2c6 in DESC::Destroy (this=0x2b0c0e00) at desc.cpp:131
#7  0x081109af in DESC_MANAGER::DestroyDesc (this=0xbfbfe91c, d=0x2b0c0e00,
    bEraseFromSet=false) at desc_manager.cpp:254
#8  0x081113d5 in DESC_MANAGER::DestroyClosed (this=0xbfbfe91c)
    at desc_manager.cpp:283
#9  0x082716e3 in io_loop (fdw=0x29358760) at main.cpp:895
#10 0x08272271 in idle () at main.cpp:842
#11 0x08273aec in main (argc=1, argv=0x53420000) at main.cpp:507


 

 


 

Link to comment
Share on other sites

  • Solution

Try that.

// Change the hook function with this:
void MoveHook::hook(CInputMain* self, iCHARACTER* ch, const char* data)
{
	if (!ch || !self || !*data)
		return;

	if (ch->m_counterxxx == 100)
		ch->m_counterxxx = 0;
    
	ch->m_counterxxx++;
	instance()->detour->GetOriginalFunction()(self, ch, data);
}

// Search for: void CHARACTER::Destroy() and add inside:
	m_counterxxx = 0;
// Search for: void CHARACTER::Disconnect(const char * c_pszReason) and add inside:
	m_counterxxx = 0;

The crash is generated when he destroyed the desc, you should check your class destroy and stop if something is nullptr and try to reinitializate the variables store to default.

Without full code i can't say too much about that, but i hope you get my points.

  • Love 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.