❓ SendDatagram Help - Instantly Crashes
What am i doing wrong? Insantly Crashes when injecting.
Code:
VFTableHook* g_pNetChannel2;
SendDatagramFn* g_pNetChannel = nullptr;
void __stdcall Hooks::Hooked_FrameStageNotify(ClientFrameStage_t curStage) {
if (g_pNetChannel == nullptr)
{
static auto pClientState = **reinterpret_cast<CClientState***>((game::search.FindPatternV2("engine.dll", "A1 ? ? ? ? 8B 80 ? ? ? ? C3") + 0x1));
DWORD ClientState_a = *(DWORD*)pClientState;
if (ClientState_a)
{
DWORD NetChannel = *(DWORD*)(*(DWORD*)ClientState_a + 0x9C);
if (NetChannel)
{
//using SendDatagramFn = int(__thiscall*)(INetChannel*, bf_write *);
g_pNetChannel2 = new VFTableHook((DWORD*)NetChannel);
oSendDatagram = (SendDatagramFn)g_pNetChannel2->Hook((DWORD)LagCompensation::SendDatagram, 48);
}
}
}
}
Code:
struct CIncomingSequence
{
CIncomingSequence::CIncomingSequence(int instate, int outstate, int seqnr, float time)
{
inreliablestate = instate;
outreliablestate = outstate;
sequencenr = seqnr;
curtime = time;
}
int inreliablestate;
int outreliablestate;
int sequencenr;
float curtime;
};
std::deque<CIncomingSequence> sequences;
int lastincomingsequencenumber;
using SendDatagramFn = int(__thiscall*)(INetChannel*, bf_write *);
SendDatagramFn oSendDatagram;
int __fastcall LagCompensation::SendDatagram(INetChannel* netchan, void*, bf_write* datagram)
{
//if (DisableAllChk.Checked || !BacktrackExploitChk.Checked || datagram)
if (datagram)
{
return oSendDatagram(netchan, datagram);
}
int instate = netchan->m_nInReliableState;
int insequencenr = netchan->m_nInSequenceNr;
LagCompensation::AddLatencyToNetchan(netchan, 0.8f);
int ret = oSendDatagram(netchan, datagram);
netchan->m_nInReliableState = instate;
netchan->m_nInSequenceNr = insequencenr;
return ret;
}
Code:
int __fastcall LagCompensation::SendDatagram(INetChannel* netchan, void*, bf_write* datagram)
{
//if (DisableAllChk.Checked || !BacktrackExploitChk.Checked || datagram)
if (datagram)
{
return oSendDatagram(netchan, datagram);
}
int instate = netchan->m_nInReliableState;
int insequencenr = netchan->m_nInSequenceNr;
LagCompensation::AddLatencyToNetchan(netchan, 0.8f);
int ret = oSendDatagram(netchan, datagram);
netchan->m_nInReliableState = instate;
netchan->m_nInSequenceNr = insequencenr;
return ret;
}
void LagCompensation::AddLatencyToNetchan(INetChannel *netchan, float Latency)
{
for (auto& seq : sequences)
{
if (m_pGlobals->realtime - seq.curtime >= Latency)
{
netchan->m_nInReliableState = seq.inreliablestate;
netchan->m_nInSequenceNr = seq.sequencenr;
break;
}
}
}
Code:
void LagCompensation::UpdateIncomingSequences()
{
//CClientState pClientState = reinterpret_cast<CClientState***>((game::search.pattern("engine.dll", "A1 ? ? ? ? 8B 80 ? ? ? ? C3")) + 0x1);
static auto pClientState = **reinterpret_cast<CClientState***>((game::search.FindPatternV2("engine.dll", "A1 ? ? ? ? 8B 80 ? ? ? ? C3") + 0x1));
DWORD ClientState = *(DWORD*)pClientState;
if (ClientState)
{
INetChannel *netchan = (INetChannel*)*(DWORD*)(ClientState + 0x9C);
if (netchan)
{
if (netchan->m_nInSequenceNr > lastincomingsequencenumber)
{
lastincomingsequencenumber = netchan->m_nInSequenceNr;
sequences.push_front(CIncomingSequence(netchan->m_nInReliableState, netchan->m_nOutReliableState, netchan->m_nInSequenceNr, m_pGlobals->realtime));
}
if (sequences.size() > 2048)
sequences.pop_back();
}
}
}