-
Автор темы
- #1
createmove hook:
after prediction
auto net_channel = g_ClientState->m_NetChannel;
if (g_Options.backtrack.enable && g_Options.backtrack.extended)
g_Backtrack.update_incoming_sequences(net_channel);
else
g_Backtrack.clear_incoming_sequences();
if (net_channel != nullptr)
{
Hooks::hk_netchannel.setup(net_channel);
Hooks::hk_netchannel.hook_index(46, send_datagram);
}
spike ping:
void Backtrack::update_incoming_sequences(INetChannel* net_channel) {
if (net_channel == nullptr)
return;
if (last_incoming_sequence == 0)
last_incoming_sequence = net_channel->m_nInSequenceNr;
if (net_channel->m_nInSequenceNr > last_incoming_sequence) {
last_incoming_sequence = net_channel->m_nInSequenceNr;
sequences_vector.emplace_front(sequence_object_t(net_channel->m_nInReliableState, net_channel->m_nOutReliableState, net_channel->m_nInSequenceNr, g_GlobalVars->realtime));
}
if (sequences_vector.size() > 2048U)
sequences_vector.pop_back();
}
void Backtrack::clear_incoming_sequences() {
if (!sequences_vector.empty()) {
last_incoming_sequence = 0;
sequences_vector.clear();
}
}
void Backtrack::add_latency_to_net_channel(INetChannel* net_channel, float latency) {
for (auto& sequence : sequences_vector) {
if (g_GlobalVars->realtime - sequence.flCurrentTime >= latency) {
net_channel->m_nInReliableState = sequence.iInReliableState;
net_channel->m_nInSequenceNr = sequence.iSequenceNr;
break;
}
}
}
sentdatahook:
int __fastcall send_datagram(INetChannel* thisptr, int edx, bf_write* pDatagram)
{
static auto oSendDatagram = hk_netchannel.get_original<senddatagram_fn>(46);
if (!g_EngineClient->IsInGame() || !g_Options.backtrack.extended || pDatagram != nullptr)
return oSendDatagram(thisptr, pDatagram);
const int iInReliableStateOld = thisptr->m_nInReliableState;
const int iInSequenceNrOld = thisptr->m_nInSequenceNr;
g_Backtrack.add_latency_to_net_channel(thisptr, 200);
const int iReturn = oSendDatagram(thisptr, pDatagram);
thisptr->m_nInReliableState = iInReliableStateOld;
thisptr->m_nInSequenceNr = iInSequenceNrOld;
return iReturn;
}