Jump to content
Maintenance ×
×
×
  • Create New...
  • 0

c++ Library Hooking Problem


oguzhan karacabay

Question

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

2 answers to this question

Recommended Posts

  • 0

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.


  • Activity

    1. 0

      erorrs after update granny to 2.9

    2. 0

      Navicat Premium 16.1.1 x64

    3. 5

      problem Dargon Soul Changre Attribute

    4. 5

      problem Dargon Soul Changre Attribute

    5. 41

      Global Chat

    6. 5

      problem Dargon Soul Changre Attribute

    7. 2

      Startup Loading Window Library

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.