diff options
Diffstat (limited to '')
-rw-r--r-- | src/TxdStore.cpp | 51 |
1 files changed, 45 insertions, 6 deletions
diff --git a/src/TxdStore.cpp b/src/TxdStore.cpp index 10d6e1f5..291feb2f 100644 --- a/src/TxdStore.cpp +++ b/src/TxdStore.cpp @@ -22,6 +22,18 @@ CTxdStore::Shutdown(void) delete ms_pTxdPool; } +void +CTxdStore::GameShutdown(void) +{ + int i; + + for(i = 0; i < TXDSTORESIZE; i++){ + TxdDef *def = GetSlot(i); + if(def && GetNumRefs(i)) + RemoveTxdSlot(i); + } +} + int CTxdStore::AddTxdSlot(const char *name) { @@ -89,6 +101,12 @@ CTxdStore::Create(int slot) GetSlot(slot)->texDict = RwTexDictionaryCreate(); } +int +CTxdStore::GetNumRefs(int slot) +{ + return GetSlot(slot)->refCount; +} + void CTxdStore::AddRef(int slot) { @@ -137,6 +155,27 @@ CTxdStore::LoadTxd(int slot, const char *filename) return ret; } +bool +CTxdStore::StartLoadTxd(int slot, RwStream *stream) +{ + TxdDef *def = GetSlot(slot); + if(RwStreamFindChunk(stream, rwID_TEXDICTIONARY, nil, nil)){ + def->texDict = RwTexDictionaryGtaStreamRead1(stream); + return def->texDict != nil; + }else{ + printf("Failed to load TXD\n"); + return nil; + } +} + +bool +CTxdStore::FinishLoadTxd(int slot, RwStream *stream) +{ + TxdDef *def = GetSlot(slot); + def->texDict = RwTexDictionaryGtaStreamRead2(stream, def->texDict); + return def->texDict != nil; +} + void CTxdStore::RemoveTxd(int slot) { @@ -146,15 +185,10 @@ CTxdStore::RemoveTxd(int slot) def->texDict = nil; } -//bool -//CTxdStore::isTxdLoaded(int slot) -//{ -// return GetSlot(slot)->texDict != nil; -//} - STARTPATCHES InjectHook(0x527440, CTxdStore::Initialize, PATCH_JUMP); InjectHook(0x527470, CTxdStore::Shutdown, PATCH_JUMP); + InjectHook(0x527490, CTxdStore::GameShutdown, PATCH_JUMP); InjectHook(0x5274E0, CTxdStore::AddTxdSlot, PATCH_JUMP); InjectHook(0x5275D0, CTxdStore::FindTxdSlot, PATCH_JUMP); InjectHook(0x527590, CTxdStore::GetTxdName, PATCH_JUMP); @@ -162,8 +196,13 @@ STARTPATCHES InjectHook(0x527910, CTxdStore::PopCurrentTxd, PATCH_JUMP); InjectHook(0x5278C0, CTxdStore::SetCurrentTxd, PATCH_JUMP); InjectHook(0x527830, CTxdStore::Create, PATCH_JUMP); + InjectHook(0x527A00, CTxdStore::GetNumRefs, PATCH_JUMP); InjectHook(0x527930, CTxdStore::AddRef, PATCH_JUMP); InjectHook(0x527970, CTxdStore::RemoveRef, PATCH_JUMP); InjectHook(0x5279C0, CTxdStore::RemoveRefWithoutDelete, PATCH_JUMP); + InjectHook(0x527700, (bool (*)(int, RwStream*))CTxdStore::LoadTxd, PATCH_JUMP); + InjectHook(0x5276B0, (bool (*)(int, const char*))CTxdStore::LoadTxd, PATCH_JUMP); + InjectHook(0x527770, CTxdStore::StartLoadTxd, PATCH_JUMP); + InjectHook(0x5277E0, CTxdStore::FinishLoadTxd, PATCH_JUMP); InjectHook(0x527870, CTxdStore::RemoveTxd, PATCH_JUMP); ENDPATCHES |