Anyone able to help debug this?

Just on the off chance that there are some C++ experts here.
Would anyone be able to suggest a course of action to resolve the following error?

int CNWNXChat::SendMsg(int nChannel, int oSender, char * sMessage, int nRecipientID){

	CNWSMessage * mess = (*NWN_AppManager)->app_server->GetNWSMessage();

	CExoString * msg = (CExoString*)mem.nwnx_malloc(sizeof(CExoString));


	int ret = mess->SendServerToPlayerChatMessage(nChannel, oSender, *msg, nRecipientID);

	if (msg->text)

	return ret;

When debugging, I can see the execution gets into the line
int ret = mess->SendServerToPlayerChatMessage(nChannel, oSender, *msg, nRecipientID);

Which looks like this:

 int CNWSMessage_s::SendServerToPlayerChatMessage(uint8_t Channel, nwn_objid_t Sender, CExoString Msg, uint32_t player_id) {
    	return CNWSMessage__SendServerToPlayerChatMessage(this, Channel, Sender, Msg, player_id);

When it steps past the return line - it errors out with the following error

The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

The hooked method is declared as:
int (__thiscall *CNWSMessage__SendServerToPlayerChatMessage)(CNWSMessage *pTHIS, uint8_t Channel, nwn_objid_t Sender, CExoString Msg, uint32_t player_id) = (int (__thiscall*)(CNWSMessage *pTHIS, uint8_t Channel, nwn_objid_t Sender, CExoString Msg, uint32_t player_id))0x0043CA00;

Yes - this is 1.69, not EE

I haven’t used C++ for such a long time but one thing I noticed.


So msg is already a pointer which means that when used in that problem line you are sending a pointer to a pointer to an CExoString. Is that supposed to be the way it works?


Im not too sure
The full back-story is that on my 1.69 server, I was having to host it on windows server2003. As on 2008+ it would crash in nwnx_chat.
I have since found a version of nwnx_chat that looks promising - and may be stable enough to work on 2008+
This version was made by Terrah Kitsune

However, when plugging that version in - I found that SimTools would crash the server when languages were used.
Today I finally managed to get visual studio debugger to step through the server code and I found that the crash actually occured at the lines posted above - seemingly when it is sending a ‘tell’ message to the players with the translated message.

nwnx_chat ->
Tulduil Erinesh(Baaleos)[Talk] !speak magic
o onChat: 7FFFFFFE test
o TEXT(…)
o SPEAK(e80f¬7ffffffe¬4¬<cþ>Tulduil Erinesh <c!}þ>[Magic] test)
o SPEAK: e80f¬7ffffffe¬4¬<cþ>Tulduil Erinesh <c!}þ>[Magic] test
o SendMsg(4, 0000E80F, ‘<cþ>Tulduil Erinesh <c!}þ>[Magic] test’, 0)

And my nwn log file:
[Sun Nov 04 16:14:54] SendChatLogMessage called:e80f¬7ffffffe¬4¬<cþ>Tulduil Erinesh <c!}þ>[Magic] test

So it is not so much the chat hook that was the problem, it looks like it may be this SendServerToPlayerChatMessage

If anyone can suggest a fix to it, I am eagerly awaiting assistance.
At the moment I have had to turn off SimTools just for server stability.

The use of msg in the second quote is a dereference of the pointer in msg, not taking the address of the pointer variable (that would be &msg).

I did say that it was a long time since I used C++.


Thanks for the replies
I gave up on fixing the nwnx_chat plugin itself persay - instead, I discovered that there was a functional replacement method in nwnx_messages - which could be used to send feedback messages via TELL to the players.