Skip to content

Commit 589aeaa

Browse files
authored
Merge branch 'master' into TheNormalnij/remove_vtbl
2 parents 608973b + 2f4a0a4 commit 589aeaa

File tree

13 files changed

+4586
-4858
lines changed

13 files changed

+4586
-4858
lines changed

Client/game_sa/CModelInfoSA.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -801,16 +801,28 @@ void CModelInfoSA::SetTextureDictionaryID(unsigned short usID)
801801
if (!m_pInterface)
802802
return;
803803

804-
// Remove ref from the old TXD
805-
CTxdStore_RemoveRef(m_pInterface->usTextureDictionary);
804+
// CBaseModelInfo::AddRef adds references to model and TXD
805+
// We need transfer added references from old TXD to new TXD
806+
size_t referencesCount = m_pInterface->usNumberOfRefs;
807+
808+
// +1 reference for active rwObject
809+
// The current textures will be removed in RpAtomicDestroy
810+
// RenderWare uses an additional reference counter per texture
811+
if (m_pInterface->pRwObject)
812+
referencesCount++;
813+
814+
for (size_t i = 0; i < referencesCount; i++)
815+
CTxdStore_RemoveRef(m_pInterface->usTextureDictionary);
806816

807817
// Store vanilla TXD ID
808818
if (!MapContains(ms_DefaultTxdIDMap, m_dwModelID))
809819
ms_DefaultTxdIDMap[m_dwModelID] = m_pInterface->usTextureDictionary;
810820

811821
// Set new TXD and increase ref of it
812822
m_pInterface->usTextureDictionary = usID;
813-
CTxdStore_AddRef(usID);
823+
824+
for (size_t i = 0; i < referencesCount; i++)
825+
CTxdStore_AddRef(usID);
814826
}
815827

816828
void CModelInfoSA::ResetTextureDictionaryID()

Client/game_sa/CRenderWareSA.TextureReplacing.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,10 @@ void CRenderWareSA::ModelInfoTXDRemoveTextures(SReplacementTextures* pReplacemen
266266
ListRemove(currentTextures, pOriginalTexture);
267267
}
268268
assert(currentTextures.empty());
269-
#endif
270269

270+
int32_t refsCount = CTxdStore_GetNumRefs(pInfo->usTxdId);
271+
assert(refsCount > 0, "Should have at least one TXD reference here");
272+
#endif
271273
// Remove info
272274
CTxdStore_RemoveRef(pInfo->usTxdId);
273275
MapRemove(ms_ModelTexturesInfoMap, usTxdId);

Client/game_sa/CWeaponInfoSA.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class CEntitySAInterface;
1919
// Flame shot array for flamethrower flames and maybe molotovs
2020
#define ARRAY_CFlameShotInfo 0xC89690
2121
#define MAX_FLAME_SHOT_INFOS 100
22+
#define FUNC_CWeaponInfo_GetWeaponReloadTime 0x743D70
2223

2324
class CFlameShotInfo
2425
{
@@ -88,6 +89,8 @@ class CWeaponInfoSAInterface // 112 byte long class
8889
/////////////////////////////////
8990
BYTE m_defaultCombo; // base combo for this melee weapon
9091
BYTE m_nCombosAvailable; // how many further combos are available
92+
93+
int GetWeaponReloadTime() { return ((int(__thiscall*)(CWeaponInfoSAInterface*))FUNC_CWeaponInfo_GetWeaponReloadTime)(this); }
9194
};
9295

9396
class CWeaponInfoSA : public CWeaponInfo

0 commit comments

Comments
 (0)