A question about reading packet data in mod

04/03/2014 07:53 anonentity#1
Hi guys, I've been reading some source code of mods and found packets to be quite interesting. However, I can't seem to find a way to read and manipulate the T_BIN packet data using functions in the MabiPacket.cpp/.h files which are publicly available (Can only read the content in AlissaAnalyzer). Could anyone give me some hint on how this could be done?

Besides, can anyone give me the source code of mod_potato if it's ever made available? As it has very likely achieved the aforementioned functionality.

Thanks.
04/03/2014 09:32 Caesarw#2
to extract:
00 T_BIN : BLAHBLAHBLAH
char* s=p.GetElement(0)->str; // your bin string

to pack:
PacketData d;
CMabiPacket p;
char bin[32]="BLAHBLAHBLAH\0"; // your bin string
d.type=7; d.str=bin; d.len=strlen(bin); p.AddElement(&d);
04/03/2014 22:19 anonentity#3
Quote:
Originally Posted by Caesarw View Post
to extract:
00 T_BIN : BLAHBLAHBLAH
char* s=p.GetElement(0)->str; // your bin string

to pack:
PacketData d;
CMabiPacket p;
char bin[32]="BLAHBLAHBLAH\0"; // your bin string
d.type=7; d.str=bin; d.len=strlen(bin); p.AddElement(&d);
Thanks for your code. I tried using it to get the T_BIN in the 5211 packet and write it out in the log file but somehow failed, here's my code:

pdata = recvPacket.GetElement( 2 );
LPSTR iINFO = pdata->str;
WriteLog(iINFO);

No content about the T_BIN is written in the log file. The only result is as following:
"[04/03/14 16:00:00] - "

Did I misunderstand anything?

Anyways, thanks for letting me know that type=7 stands for T_BIN.

And by the way, could you tell me how to make functions execute asynchronously in the mod? Normally we use SendHook and RecvHook to monitor the packets and perform immediate action after identifying specific ones, but in some cases a delayed response is needed.

For example, if I want to make the mod capable of AFK training bard skills, what I would try to do is to send an activate skill packet and wait for a certain amount of time before sending the next one. However, the simplest implementation which is delay(Nms) delays (actually freezes) the entire client. I've also tried using a separate thread that waits for signal to perform operation but it crashes the client every time the Send function is called. Any hint on this one?
:)
04/04/2014 02:08 Caesarw#4
WriteLog writes nothing because the BIN string starts with an 0, which is the termination of a string to printf. Try iterating the str array for the data you want, e.g.
for (int i=0; i<p.GetElement(2)->len; i++)
printf("%d ", p.GetElement(2)->str[i];

You'd better use RecvHook on this scene, making it a packet-driven script.
It crashes the client because the SIGNAL handler resides in different context from the client.exe process, so the Send pointer could be anything to the handler, try calling this pointer would normally cause a segment fault.
04/04/2014 04:49 anonentity#5
Quote:
Originally Posted by Caesarw View Post
WriteLog writes nothing because the BIN string starts with an 0, which is the termination of a string to printf. Try iterating the str array for the data you want, e.g.
for (int i=0; i<p.GetElement(2)->len; i++)
printf("%d ", p.GetElement(2)->str[i];

You'd better use RecvHook on this scene, making it a packet-driven script.
It crashes the client because the SIGNAL handler resides in different context from the client.exe process, so the Send pointer could be anything to the handler, try calling this pointer would normally cause a segment fault.
Thanks a lot for that information. I didn't realize that the 0s I see in AlissaAnalyzer could actually be '\0'.

For my followed question, is there a way to achieve it with some sort of delay?
I could think of a workaround like calculating the desired time for the packet to be sent and save it to some variable. Then checks it in every Recvhook and send it when current time is beyond the scheduled time. However this delay may not be very accurate because it is not guaranteed that packets are being received frequently... or is it?
04/04/2014 07:19 tliu0c#6
Quote:
Originally Posted by anonentity View Post
And by the way, could you tell me how to make functions execute asynchronously in the mod? Normally we use SendHook and RecvHook to monitor the packets and perform immediate action after identifying specific ones, but in some cases a delayed response is needed.

For example, if I want to make the mod capable of AFK training bard skills, what I would try to do is to send an activate skill packet and wait for a certain amount of time before sending the next one. However, the simplest implementation which is delay(Nms) delays (actually freezes) the entire client. I've also tried using a separate thread that waits for signal to perform operation but it crashes the client every time the Send function is called. Any hint on this one?
:)
I think a pake based bot that I wrote long time ago had something like this. Setting a fixed delay would not be a good idea. What I did was simply using WaitForSingleObject to wait for certain event to happen (a recv packet) in my bot thread. The worker thread calls WaitRecv to enter wait. And whenever recvhook gets a packet it compares it with the expected opcode. If it is the expected OP then it will trigger the wait signal to resume the bot worker thread.

I think it was something like that if i remeber correctly. Probably not the most elegant solution. But it was simple and it worked.:)

Code:
void WaitRecv(DWORD OP){
	expectedOP = OP;
	if (expectedOP != 0xdeadc0de)
		SetEvent(hRecvHookSignal);
	#ifdef _DEBUG
		WCHAR err[128] = L"debug: Waiting Recv [";
		wcscat(err, DwordToWSTR(OP));
		wcscat(err, L"]\n");	
		ConsoleOutput(err, cyan);
	#endif // _DEBUG
	if (WaitForSingleObject(hWorkerSignal, 20000) == WAIT_TIMEOUT){
		WCHAR err[128] = L"Lileas: Wait Recv [";
		wcscat(err, DwordToWSTR(OP));
		wcscat(err, L"] timed out. Worker thread terminated...\n");	
		ConsoleOutput(err, lred);
		ExitThread(0xdeadc0de);
	}
}
04/04/2014 07:31 Caesarw#7
Quote:
Originally Posted by tliu0c View Post
I think a pake based bot that I wrote long time ago had something like this. Setting a fixed delay would not be a good idea. What I did was simply using WaitForSingleObject to wait for certain event to happen (a recv packet) in my bot thread. The worker thread calls WaitRecv to enter wait. And whenever recvhook gets a packet it compares it with the expected opcode. If it is the expected OP then it will trigger the wait signal to resume the bot worker thread.

I think it was something like that if i remeber correctly. Probably not the most elegant solution. But it was simple and it worked.:)

Code:
void WaitRecv(DWORD OP){
	expectedOP = OP;
	if (expectedOP != 0xdeadc0de)
		SetEvent(hRecvHookSignal);
	#ifdef _DEBUG
		WCHAR err[128] = L"debug: Waiting Recv [";
		wcscat(err, DwordToWSTR(OP));
		wcscat(err, L"]\n");	
		ConsoleOutput(err, cyan);
	#endif // _DEBUG
	if (WaitForSingleObject(hWorkerSignal, 20000) == WAIT_TIMEOUT){
		WCHAR err[128] = L"Lileas: Wait Recv [";
		wcscat(err, DwordToWSTR(OP));
		wcscat(err, L"] timed out. Worker thread terminated...\n");	
		ConsoleOutput(err, lred);
		ExitThread(0xdeadc0de);
	}
}
Wow, 0x64, being so boring these days, any new mods?
04/04/2014 07:58 tliu0c#8
Quote:
Originally Posted by Caesarw View Post
Wow, 0x64, being so boring these days, any new mods?
No. I'm done with mabi long time ago. I don't even have an account at NA mabi anymore:p. Tho many chinese ppl give me their accounts in CN server and wants me to find exploit.

No good game to mess with:( All the new game these days have heavy western style...They just don't turn me on.

Waiting for a good game like BnS to come to NA. I'll probably be the first one to write a "pake" for it.
04/04/2014 08:13 Caesarw#9
Quote:
Originally Posted by tliu0c View Post
No. I'm done with mabi long time ago. I don't even have an account at NA mabi anymore:p. Tho many chinese ppl give me their accounts in CN server and wants me to find exploit.

No good game to mess with:( All the new game these days have heavy western style...They just don't turn me on.

Waiting for a good game like BnS to come to NA. I'll probably be the first one to write a "pake" for it.
Count me in for the ``pake'', hah