...ah ok im srry i understood wrong...sending packets to yourself is tricky but here is how i do it. I hook the wsarecv() ,which im sure tibia uses, you can add this to the above code i posted.
#include <winsock2.h>
#include <windows.h>
#include "detours.h"
#pragma comment( lib, "WSOCK32.lib" )
typedef int (WINAPI *t_wrecv)(SOCKET,LPWSABUF ,DWORD ,LPDWORD ,LPDWORD,LPWSAOVERLAPPED ,LPWSAOVERLAPPED_COMPLETION_ROUTINE );
//Globals
t_wrecv o_wrecv;
DWORD bytesReceived;
int MyWrecv(SOCKET s,LPWSABUF lpBuffers,DWORD dwBufferCount,LPDWORD lpNumberOfBytesRecvd,LPDWORD lpFlags,LPWSAOVERLAPPED lpOverlapped,LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
{
int ret;
ret =o_wrecv(s,lpBuffers,1,lpNumberOfBytesRecvd,lpFlags,lpOverlapped,lpCompletionRoutine);
if(ret==0)
{
bytesReceived = *lpNumberOfBytesRecvd; //getting real size
}
if(lpBuffers->buf[0] == '\x42')//just an example change accordingly
char packet[20] =
"\x42\x10\x00\xBA\x0B\x0C\x00\x0E\x02\x2E\x00\x09\x01\x0A\x00\x00\x00\x00\x00";
packet[15] = lpBuffers->buf[11];//example of what i wanted to change
memcpy(lpBuffers->buf + bytesReceived ,packet,19);//adding to data being recived from server
*lpNumberOfBytesRecvd +=19 ;//adding our custom packet size to buffer size
bytesReceived += 19 ;//adding our custom size to our real size
}
return ret;
}
unsigned int APIENTRY DllMain(HMODULE hModule, unsigned long ulReason, void* vpReserved)
{
if(ulReason == DLL_PROCESS_ATTACH)
{
//Setting our hook
o_wrecv = (t_wrecv)DetourFunction((PBYTE)GetProcAddress(GetModuleHandle("ws2_32.dll"), "WSARecv"), (PBYTE)MyWrecv);
return true;
}
else if(ulReason == DLL_PROCESS_DETACH)
return false;
}
So... we have to wait to receive data from server then add our custom packet to the original data being received.
Btw you may need to comment out the recv() hook the game and just hook wsarecv() ...iv had problems in the past where the game crashes or locks up.Anyways you dont really need to have recv() hooked if you have wsarecv() hooked.