From fc4b0b831a6ee9abd9483e6aa949681dabfb7316 Mon Sep 17 00:00:00 2001 From: arthurdead Date: Thu, 5 May 2022 12:12:31 -0300 Subject: [PATCH] consider the snapshot index --- extension.cpp | 119 ++++++++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 58 deletions(-) diff --git a/extension.cpp b/extension.cpp index 3a9d460..61f835b 100644 --- a/extension.cpp +++ b/extension.cpp @@ -282,9 +282,10 @@ struct pack_entity_params_t final int current_slot{-1}; bool in_compute_packs{false}; std::vector entities{}; + CFrameSnapshot *snapshot{nullptr}; - pack_entity_params_t(std::vector &&slots_, std::vector &&entities_) noexcept - : slots{std::move(slots_)}, entities{std::move(entities_)} + pack_entity_params_t(std::vector &&slots_, std::vector &&entities_, CFrameSnapshot *snapshot_) noexcept + : slots{std::move(slots_)}, entities{std::move(entities_)}, snapshot{snapshot_} { entity_data.resize(slots.size()); for(auto &it : entity_data) { @@ -948,61 +949,6 @@ DETOUR_DECL_STATIC8(SendTable_CalcDelta, int, const SendTable *, pTable, const v return global_nChanges; } -DETOUR_DECL_MEMBER2(CFrameSnapshotManager_GetPackedEntity, PackedEntity *, CFrameSnapshot *, pSnapshot, int, entity) -{ - if(!current_packentity_params || !current_packentity_params->client) { - return DETOUR_MEMBER_CALL(CFrameSnapshotManager_GetPackedEntity)(pSnapshot, entity); - } - - PackedEntity *packed{DETOUR_MEMBER_CALL(CFrameSnapshotManager_GetPackedEntity)(pSnapshot, entity)}; - if(!packed) { - return nullptr; - } - - const std::vector &entities{current_packentity_params->entities}; - - if(std::find(entities.cbegin(), entities.cend(), entity) != entities.cend()) { - const int slot{current_packentity_params->client->GetPlayerSlot()}; - - const packed_entity_data_t *packedData{nullptr}; - for(int i{0}; i < current_packentity_params->slots.size(); ++i) { - if(current_packentity_params->slots[i] == slot) { - for(const packed_entity_data_t &it : current_packentity_params->entity_data[i]) { - if(it.objectID == entity) { - packedData = ⁢ - break; - } - } - break; - } - } - - if(packedData) { - packed->AllocAndCopyPadded(packedData->packedData.get(), packedData->writeBuf->GetNumBytesWritten()); - } - } - - return packed; -} - -DETOUR_DECL_MEMBER4(CBaseServer_WriteDeltaEntities, void, CBaseClient *, client, CClientFrame *, to, CClientFrame *, from, bf_write &, pBuf) -{ - if(!current_packentity_params) { - DETOUR_MEMBER_CALL(CBaseServer_WriteDeltaEntities)(client, to, from, pBuf); - return; - } - - if(client->IsFakeClient() || - client->IsHLTV() || - client->IsReplay()) { - current_packentity_params->client = nullptr; - } else { - current_packentity_params->client = client; - } - DETOUR_MEMBER_CALL(CBaseServer_WriteDeltaEntities)(client, to, from, pBuf); - current_packentity_params->client = nullptr; -} - class CFrameSnapshot { DECLARE_FIXEDSIZE_ALLOCATOR( CFrameSnapshot ); @@ -1048,6 +994,63 @@ private: CInterlockedInt m_nReferences; }; +DETOUR_DECL_MEMBER2(CFrameSnapshotManager_GetPackedEntity, PackedEntity *, CFrameSnapshot *, pSnapshot, int, entity) +{ + if(!current_packentity_params || !current_packentity_params->client || !current_packentity_params->snapshot) { + return DETOUR_MEMBER_CALL(CFrameSnapshotManager_GetPackedEntity)(pSnapshot, entity); + } + + PackedEntity *packed{DETOUR_MEMBER_CALL(CFrameSnapshotManager_GetPackedEntity)(pSnapshot, entity)}; + if(!packed) { + return nullptr; + } + + if(current_packentity_params->snapshot->m_ListIndex == pSnapshot->m_ListIndex) { + const std::vector &entities{current_packentity_params->entities}; + + if(std::find(entities.cbegin(), entities.cend(), entity) != entities.cend()) { + const int slot{current_packentity_params->client->GetPlayerSlot()}; + + const packed_entity_data_t *packedData{nullptr}; + for(int i{0}; i < current_packentity_params->slots.size(); ++i) { + if(current_packentity_params->slots[i] == slot) { + for(const packed_entity_data_t &it : current_packentity_params->entity_data[i]) { + if(it.objectID == entity) { + packedData = ⁢ + break; + } + } + break; + } + } + + if(packedData) { + packed->AllocAndCopyPadded(packedData->packedData.get(), packedData->writeBuf->GetNumBytesWritten()); + } + } + } + + return packed; +} + +DETOUR_DECL_MEMBER4(CBaseServer_WriteDeltaEntities, void, CBaseClient *, client, CClientFrame *, to, CClientFrame *, from, bf_write &, pBuf) +{ + if(!current_packentity_params) { + DETOUR_MEMBER_CALL(CBaseServer_WriteDeltaEntities)(client, to, from, pBuf); + return; + } + + if(client->IsFakeClient() || + client->IsHLTV() || + client->IsReplay()) { + current_packentity_params->client = nullptr; + } else { + current_packentity_params->client = client; + } + DETOUR_MEMBER_CALL(CBaseServer_WriteDeltaEntities)(client, to, from, pBuf); + current_packentity_params->client = nullptr; +} + DETOUR_DECL_STATIC3(SV_ComputeClientPacks, void, int, clientCount, CGameClient **, clients, CFrameSnapshot *, snapshot) { if(current_packentity_params) { @@ -1096,7 +1099,7 @@ DETOUR_DECL_STATIC3(SV_ComputeClientPacks, void, int, clientCount, CGameClient * } if(any_per_client && !slots.empty() && !entities.empty()) { - current_packentity_params = new pack_entity_params_t{std::move(slots), std::move(entities)}; + current_packentity_params = new pack_entity_params_t{std::move(slots), std::move(entities), snapshot}; } if(current_packentity_params) {