I'm trying to hook this function:
rocessPacket( struct netpacket_s* packet, bool bHasHeader )
Here is my code:
INetChannel* pNetChan = static_cast<INetChannel*>(engine->GetPlayerNetInfo(Index()));
processPacketHookId_ = SH_ADD_HOOK_MEMFUNC(INetChannel, ProcessPacket, pNetChan, this, &CPlayer::ProcessPacket, true);
void CPlayer::ProcessPacket(struct netpacket_s* packet, bool bHasHeader )
The hook works, but the arguments contain junk data. If I call packet->message the server crashes.
I found this source code in the SDK:
void CNetChan::ProcessPacket( netpacket_t * packet, bool bHasHeader )
Here is how this function looks in ida:
int __cdecl sub_28CBC0(int a1, int a2, char a3)
This is how bf_read position is set in this function:
bf_read &msg = packet->message; // handy shortcut
msg.Seek( 0 );
The same in IDA:
v51 = a2 + 48;
sub_314FF0(a2 + 48, 0);
v3 = *(_DWORD *)(a1 + 196);
If I'm correct with my undrestending, it takes the second argument from the function, that is netpacket_s* packet, then it gets the buffer from the netpacket_s* (which is at offset 48 ).
In inetchannel.h second argument is bool and bf_read offset is 32
Can it be that INetChannel and netpacket_s are incorrect in the SDK, if yes, where can I get the correct header?
UPD, I placed 4 dummy integers at the begining of netpacket_s structure, and now I can access bf_read, however all the other variables are a mistery and the bool argument in the function is incorrect.