diff options
author | aap <aap@papnet.eu> | 2019-06-13 12:25:55 +0200 |
---|---|---|
committer | aap <aap@papnet.eu> | 2019-06-13 12:25:55 +0200 |
commit | f407c9829fb5eac2c00867d2b31b2766dfe70540 (patch) | |
tree | 49afbef27c493ac1406c0b621a29ed5df78e9a86 /src/TxdStore.cpp | |
parent | implemented GTA stream read functions (diff) | |
download | re3-f407c9829fb5eac2c00867d2b31b2766dfe70540.tar re3-f407c9829fb5eac2c00867d2b31b2766dfe70540.tar.gz re3-f407c9829fb5eac2c00867d2b31b2766dfe70540.tar.bz2 re3-f407c9829fb5eac2c00867d2b31b2766dfe70540.tar.lz re3-f407c9829fb5eac2c00867d2b31b2766dfe70540.tar.xz re3-f407c9829fb5eac2c00867d2b31b2766dfe70540.tar.zst re3-f407c9829fb5eac2c00867d2b31b2766dfe70540.zip |
Diffstat (limited to 'src/TxdStore.cpp')
-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 |