From 53cd576ae69e283f9d574344c4b5da909cb41f5d Mon Sep 17 00:00:00 2001 From: Tater Date: Wed, 18 Dec 2024 20:41:23 -0600 Subject: [PATCH] Add CopyWorldClean to fix ASan --- src/game/client/gameclient.cpp | 4 +- src/game/client/prediction/gameworld.cpp | 49 ++++++++++++++++++++++++ src/game/client/prediction/gameworld.h | 1 + 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 123d9d2397f..78605a9bf01 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -2404,7 +2404,7 @@ void CGameClient::OnPredict() if(g_Config.m_ClRemoveAnti) { - m_ExtraPredictedWorld.CopyWorld(&m_PredictedWorld); + m_ExtraPredictedWorld.CopyWorldClean(&m_PredictedWorld); // Remove other tees to reduce lag and because they aren't really important in this case for(int i = 0; i < MAX_CLIENTS; i++) @@ -2687,7 +2687,7 @@ void CGameClient::OnPredict() // Copy the current pred world so on the next tick we have the "previous" pred world to advance and test against if(m_NewPredictedTick) - m_PredSmoothingWorld.CopyWorld(&m_PredictedWorld); + m_PredSmoothingWorld.CopyWorldClean(&m_PredictedWorld); for(int i = 0; i < MAX_CLIENTS; i++) { diff --git a/src/game/client/prediction/gameworld.cpp b/src/game/client/prediction/gameworld.cpp index cecffb9b8f3..c72e35500c1 100644 --- a/src/game/client/prediction/gameworld.cpp +++ b/src/game/client/prediction/gameworld.cpp @@ -579,6 +579,55 @@ void CGameWorld::NetObjEnd() } } +void CGameWorld::CopyWorldClean(CGameWorld *pFrom) +{ + if(pFrom == this || !pFrom) + return; + m_IsValidCopy = false; + + m_GameTick = pFrom->m_GameTick; + m_pCollision = pFrom->m_pCollision; + m_WorldConfig = pFrom->m_WorldConfig; + for(int i = 0; i < 2; i++) + { + m_Core.m_aTuning[i] = pFrom->m_Core.m_aTuning[i]; + } + m_pTuningList = pFrom->m_pTuningList; + m_Teams = pFrom->m_Teams; + m_Core.m_vSwitchers = pFrom->m_Core.m_vSwitchers; + // delete the previous entities + Clear(); + for(int i = 0; i < MAX_CLIENTS; i++) + { + m_apCharacters[i] = 0; + m_Core.m_apCharacters[i] = 0; + } + // copy and add the new entities + for(int Type = 0; Type < NUM_ENTTYPES; Type++) + { + for(CEntity *pEnt = pFrom->FindLast(Type); pEnt; pEnt = pEnt->TypePrev()) + { + CEntity *pCopy = 0; + if(Type == ENTTYPE_PROJECTILE) + pCopy = new CProjectile(*((CProjectile *)pEnt)); + else if(Type == ENTTYPE_LASER) + pCopy = new CLaser(*((CLaser *)pEnt)); + else if(Type == ENTTYPE_DRAGGER) + pCopy = new CDragger(*((CDragger *)pEnt)); + else if(Type == ENTTYPE_CHARACTER) + pCopy = new CCharacter(*((CCharacter *)pEnt)); + else if(Type == ENTTYPE_PICKUP) + pCopy = new CPickup(*((CPickup *)pEnt)); + if(pCopy) + { + pCopy->m_pParent = nullptr; + pCopy->m_pChild = nullptr; + this->InsertEntity(pCopy); + } + } + } +} + void CGameWorld::CopyWorld(CGameWorld *pFrom) { if(pFrom == this || !pFrom) diff --git a/src/game/client/prediction/gameworld.h b/src/game/client/prediction/gameworld.h index 78d64030847..42dcb782a78 100644 --- a/src/game/client/prediction/gameworld.h +++ b/src/game/client/prediction/gameworld.h @@ -96,6 +96,7 @@ class CGameWorld void NetObjAdd(int ObjId, int ObjType, const void *pObjData, const CNetObj_EntityEx *pDataEx); void NetObjEnd(); void CopyWorld(CGameWorld *pFrom); + void CopyWorldClean(CGameWorld *pFrom); //TClient CEntity *FindMatch(int ObjId, int ObjType, const void *pObjData); void Clear();