Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Client/game_sa/CFileLoaderSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ CEntitySAInterface* CFileLoaderSA::LoadObjectInstance(const char* szLine)
return CFileLoader_LoadObjectInstance(szLine);
}

class CDamagableModelInfo;

class CAtomicModelInfo
{
public:
void DeleteRwObject() { ((void(__thiscall*)(CAtomicModelInfo*))(*(void***)this)[8])(this); }

void SetAtomic(RpAtomic* atomic) { ((void(__thiscall*)(CAtomicModelInfo*, RpAtomic*))(*(void***)this)[15])(this, atomic); }

CDamagableModelInfo* AsDamageAtomicModelInfoPtr() { return ((CDamagableModelInfo * (__thiscall*)(CAtomicModelInfo*))(*(void***)this)[2])(this); }
};

class CDamagableModelInfo
Expand Down Expand Up @@ -210,12 +214,19 @@ RpAtomic* CFileLoader_SetRelatedModelInfoCB(RpAtomic* atomic, SRelatedModelInfo*
GetNameAndDamage(frameNodeName, name, bDamage);
}

CDamagableModelInfo* pDamagableModelInfo = bDamage ? pAtomicModelInfo->AsDamageAtomicModelInfoPtr() : nullptr;
if (bDamage && !pDamagableModelInfo)
{
// Returning null would stop RpClumpForAllAtomics, so leave the atomic with the clump
pRelatedModelInfo->bAtomicNotConsumed = true;
return atomic;
}

CVisibilityPlugins_SetAtomicRenderCallback(atomic, 0);

RpAtomic* pOldAtomic = reinterpret_cast<RpAtomic*>(pBaseModelInfo->pRwObject);
if (bDamage)
{
auto pDamagableModelInfo = reinterpret_cast<CDamagableModelInfo*>(pAtomicModelInfo);
pDamagableModelInfo->SetDamagedAtomic(atomic);
}
else
Expand Down
1 change: 1 addition & 0 deletions Client/game_sa/CFileLoaderSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct SRelatedModelInfo
{
RpClump* pClump;
bool bDeleteOldRwObject;
bool bAtomicNotConsumed;
};

struct SFileObjectInstance
Expand Down
8 changes: 5 additions & 3 deletions Client/game_sa/CRenderWareSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,11 @@ bool AtomicsReplacer(RpAtomic* pAtomic, void* data)
relatedModelInfo.bDeleteOldRwObject = true;
CFileLoader_SetRelatedModelInfoCB(pAtomic, &relatedModelInfo);

// The above function adds a reference to the model's TXD by either
// calling CAtomicModelInfo::SetAtomic or CDamagableModelInfo::SetDamagedAtomic. Remove it again.
CTxdStore_RemoveRef(pData->usTxdID);
// The above function adds a reference to the model's TXD when it calls
// CAtomicModelInfo::SetAtomic or CDamagableModelInfo::SetDamagedAtomic. It calls neither if the
// atomic was left with the clump, so only remove the reference when one was taken.
if (!relatedModelInfo.bAtomicNotConsumed)
CTxdStore_RemoveRef(pData->usTxdID);
return true;
}

Expand Down
Loading