diff options
author | aap <aap@papnet.eu> | 2019-05-15 16:52:37 +0200 |
---|---|---|
committer | aap <aap@papnet.eu> | 2019-05-15 16:52:37 +0200 |
commit | 600bf0351476a5a21aabb5429132ddf7f52ac0b9 (patch) | |
tree | d8e48b3a581679e33830fb7c98ed69e1e242e2c2 /src/TxdStore.cpp | |
download | re3-600bf0351476a5a21aabb5429132ddf7f52ac0b9.tar re3-600bf0351476a5a21aabb5429132ddf7f52ac0b9.tar.gz re3-600bf0351476a5a21aabb5429132ddf7f52ac0b9.tar.bz2 re3-600bf0351476a5a21aabb5429132ddf7f52ac0b9.tar.lz re3-600bf0351476a5a21aabb5429132ddf7f52ac0b9.tar.xz re3-600bf0351476a5a21aabb5429132ddf7f52ac0b9.tar.zst re3-600bf0351476a5a21aabb5429132ddf7f52ac0b9.zip |
Diffstat (limited to '')
-rw-r--r-- | src/TxdStore.cpp | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/src/TxdStore.cpp b/src/TxdStore.cpp new file mode 100644 index 00000000..ba8eecb9 --- /dev/null +++ b/src/TxdStore.cpp @@ -0,0 +1,158 @@ +#include "common.h" +#include "patcher.h" +#include "templates.h" +#include "Streaming.h" +#include "TxdStore.h" + +CPool<TxdDef,TxdDef> *&CTxdStore::ms_pTxdPool = *(CPool<TxdDef,TxdDef>**)0x8F5FB8; +RwTexDictionary *&CTxdStore::ms_pStoredTxd = *(RwTexDictionary**)0x9405BC; + +void +CTxdStore::Initialize(void) +{ + if(ms_pTxdPool == nil) + ms_pTxdPool = new CPool<TxdDef,TxdDef>(TXDSTORESIZE); +} + +void +CTxdStore::Shutdown(void) +{ + if(ms_pTxdPool) + delete ms_pTxdPool; +} + +int +CTxdStore::AddTxdSlot(const char *name) +{ + TxdDef *def = ms_pTxdPool->New(); + assert(def); + def->texDict = nil; + def->refCount = 0; + strcpy(def->name, name); + return ms_pTxdPool->GetJustIndex(def); +} + +int +CTxdStore::FindTxdSlot(const char *name) +{ + char *defname; + int size = ms_pTxdPool->GetSize(); + for(int i = 0; i < size; i++){ + defname = GetTxdName(i); + if(defname && _strcmpi(defname, name) == 0) + return i; + } + return -1; +} + +char* +CTxdStore::GetTxdName(int slot) +{ + TxdDef *def = GetSlot(slot); + return def ? def->name : nil; +} + +void +CTxdStore::PushCurrentTxd(void) +{ + ms_pStoredTxd = RwTexDictionaryGetCurrent(); +} + +void +CTxdStore::PopCurrentTxd(void) +{ + RwTexDictionarySetCurrent(ms_pStoredTxd); + ms_pStoredTxd = nil; +} + +void +CTxdStore::SetCurrentTxd(int slot) +{ + TxdDef *def = GetSlot(slot); + if(def) + RwTexDictionarySetCurrent(def->texDict); +} + +void +CTxdStore::Create(int slot) +{ + GetSlot(slot)->texDict = RwTexDictionaryCreate(); +} + +void +CTxdStore::AddRef(int slot) +{ + GetSlot(slot)->refCount++; +} + +void +CTxdStore::RemoveRef(int slot) +{ + if(--GetSlot(slot)->refCount <= 0) + CStreaming::RemoveModel(slot + STREAM_OFFSET_TXD); +} + +void +CTxdStore::RemoveRefWithoutDelete(int slot) +{ + GetSlot(slot)->refCount--; +} + +/* +bool +CTxdStore::LoadTxd(int slot, RwStream *stream) +{ + TxdDef *def = GetSlot(slot); + if(!rw::findChunk(stream, rw::ID_TEXDICTIONARY, nil, nil)){ + return false; + }else{ + def->texDict = rw::TexDictionary::streamRead(stream); + convertTxd(def->texDict); + return def->texDict != nil; + } +} + +bool +CTxdStore::LoadTxd(int slot, const char *filename) +{ + rw::StreamFile stream; + if(stream.open(getPath(filename), "rb")){ + LoadTxd(slot, &stream); + stream.close(); + return true; + } + printf("Failed to open TXD\n"); + return false; +} +*/ + +void +CTxdStore::RemoveTxd(int slot) +{ + TxdDef *def = GetSlot(slot); + if(def->texDict) + RwTexDictionaryDestroy(def->texDict); + 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(0x5274E0, CTxdStore::AddTxdSlot, PATCH_JUMP); + InjectHook(0x5275D0, CTxdStore::FindTxdSlot, PATCH_JUMP); + InjectHook(0x527590, CTxdStore::GetTxdName, PATCH_JUMP); + InjectHook(0x527900, CTxdStore::PushCurrentTxd, PATCH_JUMP); + InjectHook(0x527910, CTxdStore::PopCurrentTxd, PATCH_JUMP); + InjectHook(0x5278C0, CTxdStore::SetCurrentTxd, PATCH_JUMP); + InjectHook(0x527830, CTxdStore::Create, PATCH_JUMP); + InjectHook(0x527930, CTxdStore::AddRef, PATCH_JUMP); + InjectHook(0x527970, CTxdStore::RemoveRef, PATCH_JUMP); + InjectHook(0x5279C0, CTxdStore::RemoveRefWithoutDelete, PATCH_JUMP); + InjectHook(0x527870, CTxdStore::RemoveTxd, PATCH_JUMP); +ENDPATCHES |