diff --git a/Runtime/CBasics.hpp b/Runtime/CBasics.hpp index 4ab3be986..461e010f6 100644 --- a/Runtime/CBasics.hpp +++ b/Runtime/CBasics.hpp @@ -6,15 +6,9 @@ #include "RetroTypes.hpp" -#include -#include - namespace Retro { -using CInputStream = Athena::io::IStreamReader; -using COutputStream = Athena::io::IStreamWriter; - class CBasics { public: diff --git a/Runtime/CDvdFile.hpp b/Runtime/CDvdFile.hpp index c05398453..ed5e73d9f 100644 --- a/Runtime/CDvdFile.hpp +++ b/Runtime/CDvdFile.hpp @@ -20,12 +20,14 @@ class CDvdRequest; class CDvdFile { + friend class CResLoader; + std::string x18_name; public: CDvdFile(const char*); void UpdateFilePos(int); void CalcFileOffset(int, ESeekOrigin); static void internalCallback(s32, DVDFileInfo*); - bool FileExists(const char*); + static bool FileExists(const char*); void CloseFile(); CDvdRequest* AsyncSeekRead(void*, u32, ESeekOrigin, int); void SyncSeekRead(void*, u32, ESeekOrigin, int); diff --git a/Runtime/CGameAllocator.cpp b/Runtime/CGameAllocator.cpp index 4008f9e14..6a162d943 100644 --- a/Runtime/CGameAllocator.cpp +++ b/Runtime/CGameAllocator.cpp @@ -3,13 +3,81 @@ namespace Retro { -bool CGameAllocator::Initialize(COsContext&) +CGameAllocator::SGameMemInfo* CGameAllocator::FindFreeBlock(u32) { - return true; +} +CGameAllocator::SGameMemInfo* CGameAllocator::FindFreeBlockFromTopOfHeap(u32) +{ +} +u32 CGameAllocator::FixupAllocPtrs(SGameMemInfo*, u32, u32, EHint, const CCallStack&) +{ +} +void CGameAllocator::UpdateAllocDebugStats(u32, u32, u32) +{ +} +bool CGameAllocator::FreeNormalAllocation(void*) +{ +} +u32 CGameAllocator::GetFreeBinEntryForSize(u32) +{ +} +void CGameAllocator::AddFreeEntryToFreeList(SGameMemInfo*) +{ +} +void CGameAllocator::RemoveFreeEntryFromFreeList(SGameMemInfo*) +{ +} +void CGameAllocator::DumpAllocations() const +{ +} +u32 CGameAllocator::GetLargestFreeChunk() const +{ +} +CGameAllocator::SGameMemInfo* CGameAllocator::GetMemInfoFromBlockPtr(void* ptr) +{ + return reinterpret_cast(reinterpret_cast(ptr) - 32); } +bool CGameAllocator::Initialize(COsContext&) +{ +} void CGameAllocator::Shutdown() { } +void* CGameAllocator::Alloc(size_t, EHint, EScope, EType, const CCallStack&) +{ +} +void CGameAllocator::Free(void*) +{ +} +void CGameAllocator::ReleaseAll() +{ +} +void* CGameAllocator::AllocSecondary(size_t, EHint, EScope, EType, const CCallStack&) +{ +} +void CGameAllocator::FreeSecondary(void*) +{ +} +void CGameAllocator::ReleaseAllSecondary() +{ +} +void CGameAllocator::SetOutOfMemoryCallback(const TOutOfMemoryCallback cb, void* ctx) +{ + x58_oomCb = cb; + x5c_oomCtx = ctx; +} +int CGameAllocator::EnumAllocations(const TAllocationVisitCallback, void*, bool) const +{ +} +CGameAllocator::SAllocInfo CGameAllocator::GetAllocInfo(void*) const +{ +} +void CGameAllocator::OffsetFakeStatics(int) +{ +} +CGameAllocator::SMetrics CGameAllocator::GetMetrics() const +{ +} } diff --git a/Runtime/CGameAllocator.hpp b/Runtime/CGameAllocator.hpp index 909ea1f28..e9ee00679 100644 --- a/Runtime/CGameAllocator.hpp +++ b/Runtime/CGameAllocator.hpp @@ -14,7 +14,9 @@ public: { }; private: - SGameMemInfo* x10_rootInfo; + SGameMemInfo* x10_rootInfo = nullptr; + TOutOfMemoryCallback x58_oomCb = nullptr; + void* x5c_oomCtx = nullptr; u32 xbc_fakeStaticOff = 0; public: SGameMemInfo* FindFreeBlock(u32); @@ -27,15 +29,14 @@ public: void RemoveFreeEntryFromFreeList(SGameMemInfo*); void DumpAllocations() const; u32 GetLargestFreeChunk() const; - SGameMemInfo* GetMemInfoFromBlockPtr(void* ptr) - {return reinterpret_cast(reinterpret_cast(ptr) - 32);} + SGameMemInfo* GetMemInfoFromBlockPtr(void* ptr); bool Initialize(COsContext&); void Shutdown(); - void* Alloc(u32, EHint, EScope, EType, const CCallStack&); + void* Alloc(size_t, EHint, EScope, EType, const CCallStack&); void Free(void*); void ReleaseAll(); - void* AllocSecondary(u32, EHint, EScope, EType, const CCallStack&); + void* AllocSecondary(size_t, EHint, EScope, EType, const CCallStack&); void FreeSecondary(void*); void ReleaseAllSecondary(); void SetOutOfMemoryCallback(const TOutOfMemoryCallback, void*); diff --git a/Runtime/CGameState.cpp b/Runtime/CGameState.cpp index 7f4b11d26..330a6c664 100644 --- a/Runtime/CGameState.cpp +++ b/Runtime/CGameState.cpp @@ -1,4 +1,5 @@ #include "CGameState.hpp" +#include "IOStreams.hpp" namespace Retro { diff --git a/Runtime/CMakeLists.txt b/Runtime/CMakeLists.txt index 633265979..3eb7b8dcf 100644 --- a/Runtime/CMakeLists.txt +++ b/Runtime/CMakeLists.txt @@ -60,6 +60,7 @@ add_library(RuntimeCommon CPakFile.hpp CPakFile.cpp CStringExtras.hpp CCallStack.hpp + IOStreams.hpp IOStreams.cpp rstl.hpp rstl.cpp GameGlobalObjects.hpp RetroTypes.hpp diff --git a/Runtime/CMemory.cpp b/Runtime/CMemory.cpp index 63d8c82b3..6e9ca3b3f 100644 --- a/Runtime/CMemory.cpp +++ b/Runtime/CMemory.cpp @@ -1,5 +1,6 @@ #include "CMemory.hpp" #include "CGameAllocator.hpp" +#include "CCallStack.hpp" #include namespace Retro @@ -46,7 +47,7 @@ void CMemory::Free(void* ptr) g_memoryAllocator->Free(ptr); } -void* CMemory::Alloc(u32 sz, IAllocator::EHint hint, IAllocator::EScope scope, +void* CMemory::Alloc(size_t sz, IAllocator::EHint hint, IAllocator::EScope scope, IAllocator::EType type, const CCallStack& cs) { void* newPtr = g_memoryAllocator->Alloc(sz, hint, scope, type, cs); @@ -69,3 +70,47 @@ CMemorySys::~CMemorySys() IAllocator& CMemorySys::GetGameAllocator() {return g_gameAllocator;} } + +void* operator new(std::size_t) +{ + extern void *bare_new_erroneously_called(); + return bare_new_erroneously_called(); +} + +void* operator new(std::size_t sz, + const char* funcName, const char* typeName) +{ + Retro::CCallStack cs(funcName, typeName); + return Retro::CMemory::Alloc(sz, + Retro::IAllocator::HintNone, + Retro::IAllocator::ScopeDefault, + Retro::IAllocator::TypePrimitive, + cs); +} + +void operator delete(void* ptr) noexcept +{ + Retro::CMemory::Free(ptr); +} + +void* operator new[](std::size_t) +{ + extern void *bare_new_array_erroneously_called(); + return bare_new_array_erroneously_called(); +} + +void* operator new[](std::size_t sz, + const char* funcName, const char* typeName) +{ + Retro::CCallStack cs(funcName, typeName); + return Retro::CMemory::Alloc(sz, + Retro::IAllocator::HintNone, + Retro::IAllocator::ScopeDefault, + Retro::IAllocator::TypeArray, + cs); +} + +void operator delete[](void* ptr) noexcept +{ + Retro::CMemory::Free(ptr); +} diff --git a/Runtime/CMemory.hpp b/Runtime/CMemory.hpp index bd822ea9d..4ac2965ea 100644 --- a/Runtime/CMemory.hpp +++ b/Runtime/CMemory.hpp @@ -16,7 +16,7 @@ public: static void OffsetFakeStatics(int); static void SetOutOfMemoryCallback(const IAllocator::TOutOfMemoryCallback, void*); static void Free(void*); - static void* Alloc(u32, IAllocator::EHint, IAllocator::EScope, IAllocator::EType, const CCallStack&); + static void* Alloc(size_t, IAllocator::EHint, IAllocator::EScope, IAllocator::EType, const CCallStack&); }; class CMemorySys @@ -29,4 +29,12 @@ public: } +/* Custom new funcs */ +void* operator new(std::size_t sz, const char* funcName, const char* typeName); +void* operator new[](std::size_t sz, const char* funcName, const char* typeName); + +/* Macro to perform custom with debug strings */ +#define NEW(T) new (AT_PRETTY_FUNCTION, typeid(T).name()) T +#define NEWA(T, N) new (AT_PRETTY_FUNCTION, typeid(T).name()) T[N] + #endif // __RETRO_CMEMORY_HPP__ diff --git a/Runtime/CPakFile.hpp b/Runtime/CPakFile.hpp index fb4c47d3b..6fe20cc7a 100644 --- a/Runtime/CPakFile.hpp +++ b/Runtime/CPakFile.hpp @@ -16,12 +16,13 @@ class CPakFile : public CDvdFile public: struct SResInfo { - u32 compressed; - SObjectTag tag; - u32 size; - u32 offset; + FourCC x0_type; + u32 x4_offset; + u32 x8_size; + bool xb_compressed; }; private: + bool x28_b24_ctFlag; enum EAsyncPhase { PakAsyncWarmup = 0, @@ -34,7 +35,7 @@ private: std::vector x5c_depList; std::vector> x6c_resList; public: - CPakFile(const std::string& filename); + CPakFile(const std::string& filename, bool flag); const std::vector& GetDepList() const {return x5c_depList;} u32 GetResIdByName(const char* name) const { diff --git a/Runtime/CPlayerState.hpp b/Runtime/CPlayerState.hpp index fd68e184b..a8b911b32 100644 --- a/Runtime/CPlayerState.hpp +++ b/Runtime/CPlayerState.hpp @@ -4,6 +4,7 @@ #include "RetroTypes.hpp" #include "CBasics.hpp" #include "CStaticInterference.hpp" +#include "IOStreams.hpp" namespace Retro { diff --git a/Runtime/CResLoader.cpp b/Runtime/CResLoader.cpp index e69de29bb..045f5965f 100644 --- a/Runtime/CResLoader.cpp +++ b/Runtime/CResLoader.cpp @@ -0,0 +1,223 @@ +#include "CResLoader.hpp" +#include "CPakFile.hpp" +#include "CMemory.hpp" +#include "CCallStack.hpp" + +namespace Retro +{ + +const std::vector* CResLoader::GetTagListForFile(const std::string& name) const +{ + std::string namePak = name + ".pak"; + for (const std::unique_ptr& pak : x1c_pakLoadedList) + if (!CStringExtras::CompareCaseInsensitive(namePak, pak->x18_name)) + return &pak->GetDepList(); + return nullptr; +} + +void CResLoader::AddPakFileAsync(const std::string& name, bool flag) +{ + std::string namePak = name + ".pak"; + if (CDvdFile::FileExists(namePak.c_str())) + { + x34_pakLoadingList.emplace_back(NEW(CPakFile)(namePak, flag)); + ++x44_pakLoadingCount; + } +} + +void CResLoader::AddPakFile(const std::string& name, bool flag) +{ + AddPakFileAsync(name, flag); + while (x44_pakLoadingCount) + AsyncIdlePakLoading(); +} + +CInputStream* CResLoader::LoadNewResourcePartSync(const SObjectTag& tag, int offset, int length, void* extBuf) +{ + void* buf = extBuf; + CPakFile* file = FindResourceForLoad(tag); + if (!buf) + { + CCallStack cs(AT_PRETTY_FUNCTION, "UnknownType"); + buf = CMemory::Alloc(length, + IAllocator::HintLarge, + IAllocator::ScopeDefault, + IAllocator::TypePrimitive, + cs); + } + file->SyncSeekRead(buf, length, OriginBegin, x50_cachedResInfo->x4_offset + offset); + return NEW(CMemoryInStream)((atUint8*)buf, length, !extBuf); +} + +void CResLoader::LoadMemResourceSync(const SObjectTag& tag, void** bufOut, int* sizeOut) +{ + CPakFile* file = FindResourceForLoad(tag); + CCallStack cs(AT_PRETTY_FUNCTION, "UnknownType"); + void* buf = CMemory::Alloc(x50_cachedResInfo->x8_size, + IAllocator::HintLarge, + IAllocator::ScopeDefault, + IAllocator::TypePrimitive, + cs); + file->SyncSeekRead(buf, x50_cachedResInfo->x8_size, OriginBegin, + x50_cachedResInfo->x4_offset); + *bufOut = buf; + *sizeOut = x50_cachedResInfo->x8_size; +} + +CInputStream* CResLoader::LoadResourceFromMemorySync(const SObjectTag& tag, const void* buf) +{ + FindResourceForLoad(tag); + CInputStream* newStrm = NEW(CMemoryInStream)((atUint8*)buf, x50_cachedResInfo->x8_size); + if (x50_cachedResInfo->xb_compressed) + { + newStrm->readUint32Big(); + newStrm = NEW(CZipInputStream)(std::move(std::unique_ptr(newStrm))); + } + return newStrm; +} + +CInputStream* CResLoader::LoadNewResourceSync(const SObjectTag& tag, void* extBuf) +{ + void* buf = extBuf; + CPakFile* file = FindResourceForLoad(tag); + size_t resSz = ROUND_UP_32(x50_cachedResInfo->x8_size); + if (!buf) + { + CCallStack cs(AT_PRETTY_FUNCTION, "UnknownType"); + buf = CMemory::Alloc(resSz, + IAllocator::HintLarge, + IAllocator::ScopeDefault, + IAllocator::TypePrimitive, + cs); + } + file->SyncSeekRead(buf, resSz, OriginBegin, x50_cachedResInfo->x4_offset); + CInputStream* newStrm = NEW(CMemoryInStream)((atUint8*)buf, resSz, !extBuf); + if (x50_cachedResInfo->xb_compressed) + { + newStrm->readUint32Big(); + newStrm = NEW(CZipInputStream)(std::move(std::unique_ptr(newStrm))); + } + return newStrm; +} + +CDvdRequest* CResLoader::LoadResourcePartAsync(const SObjectTag& tag, int offset, int length, void* buf) +{ + return FindResourceForLoad(tag.id)->AsyncSeekRead(buf, length, + OriginBegin, x50_cachedResInfo->x4_offset + offset); +} + +CDvdRequest* CResLoader::LoadResourceAsync(const SObjectTag& tag, void* buf) +{ + return FindResourceForLoad(tag.id)->AsyncSeekRead(buf, ROUND_UP_32(x50_cachedResInfo->x8_size), + OriginBegin, x50_cachedResInfo->x4_offset); +} + +bool CResLoader::GetResourceCompression(const SObjectTag& tag) +{ + if (FindResource(tag.id)) + return x50_cachedResInfo->xb_compressed; + return false; +} + +u32 CResLoader::ResourceSize(const SObjectTag& tag) +{ + if (FindResource(tag.id)) + return x50_cachedResInfo->x8_size; + return false; +} + +bool CResLoader::ResourceExists(const SObjectTag& tag) +{ + return FindResource(tag.id); +} + +FourCC CResLoader::GetResourceTypeById(u32 id) +{ + if (FindResource(id)) + return x50_cachedResInfo->x0_type; + return false; +} + +u32 CResLoader::GetResourceIdByName(const char* name) const +{ + for (const std::unique_ptr& file : x1c_pakLoadedList) + { + u32 id = file->GetResIdByName(name); + if (id) + return id; + } + return 0; +} + +bool CResLoader::AreAllPaksLoaded() const +{ + return x44_pakLoadingCount == 0; +} + +void CResLoader::AsyncIdlePakLoading() +{ + for (auto it=x34_pakLoadingList.begin(); + it != x34_pakLoadingList.end(); + ++it) + { + (*it)->AsyncIdle(); + if ((*it)->x2c_asyncLoadPhase == CPakFile::PakAsyncLoaded) + { + MoveToCorrectLoadedList(std::move(*it)); + it = x34_pakLoadingList.erase(it); + --x44_pakLoadingCount; + } + } +} + +bool CResLoader::FindResource(u32 id) +{ + for (const std::unique_ptr& file : x1c_pakLoadedList) + if (CacheFromPak(*file, id)) + return true; + return false; +} + +CPakFile* CResLoader::FindResourceForLoad(u32 id) +{ + for (std::unique_ptr& file : x1c_pakLoadedList) + if (CacheFromPakForLoad(*file, id)) + return file.get(); + return nullptr; +} + +CPakFile* CResLoader::FindResourceForLoad(const SObjectTag& tag) +{ + return FindResourceForLoad(tag.id); +} + +bool CResLoader::CacheFromPakForLoad(CPakFile& file, u32 id) +{ + const CPakFile::SResInfo* info = file.GetResInfoForLoad(id); + if (info) + { + x4c_cachedResId = id; + x50_cachedResInfo = info; + return true; + } + return false; +} + +bool CResLoader::CacheFromPak(const CPakFile& file, u32 id) +{ + const CPakFile::SResInfo* info = file.GetResInfo(id); + if (info) + { + x4c_cachedResId = id; + x50_cachedResInfo = info; + return true; + } + return false; +} + +void CResLoader::MoveToCorrectLoadedList(std::unique_ptr&& file) +{ + x1c_pakLoadedList.push_back(std::move(file)); +} + +} diff --git a/Runtime/CResLoader.hpp b/Runtime/CResLoader.hpp index 3793f2b8b..1724ca9c8 100644 --- a/Runtime/CResLoader.hpp +++ b/Runtime/CResLoader.hpp @@ -5,8 +5,7 @@ #include #include "RetroTypes.hpp" #include "CPakFile.hpp" -#include "CBasics.hpp" -#include "CMemory.hpp" +#include "IOStreams.hpp" namespace Retro { @@ -22,140 +21,28 @@ class CResLoader u32 x4c_cachedResId = -1; const CPakFile::SResInfo* x50_cachedResInfo = nullptr; public: - const std::vector& GetTagListForFile(const std::string&) const; - void AddPakFileAsync(const std::string&, bool); - void AddPakFile(const std::string&, bool); - CInputStream* LoadNewResourcePartSync(const SObjectTag&, int, int, char*); - void LoadMemResourceSync(const SObjectTag&, char*, int*); - CInputStream* LoadResourceFromMemorySync(const SObjectTag&, const void*); - CInputStream* LoadNewResourceSync(const SObjectTag& tag, void* buf) - { - FindResourceForLoad(tag); - if (!buf) - { - - } - } - - CDvdRequest* LoadResourcePartAsync(const SObjectTag& tag, int offset, int length, void* buf) - { - return FindResourceForLoad(tag.id)->AsyncSeekRead(buf, length, - OriginBegin, x50_cachedResInfo->offset + offset); - } - - CDvdRequest* LoadResourceAsync(const SObjectTag& tag, void* buf) - { - return FindResourceForLoad(tag.id)->AsyncSeekRead(buf, ROUND_UP_32(x50_cachedResInfo->size), - OriginBegin, x50_cachedResInfo->offset); - } - - bool GetResourceCompression(const SObjectTag& tag) - { - if (FindResource(tag.id)) - return x50_cachedResInfo->compressed; - return false; - } - - u32 ResourceSize(const SObjectTag& tag) - { - if (FindResource(tag.id)) - return x50_cachedResInfo->size; - return false; - } - - bool ResourceExists(const SObjectTag& tag) - { - return FindResource(tag.id); - } - - FourCC GetResourceTypeById(u32 id) - { - if (FindResource(id)) - return x50_cachedResInfo->tag.type; - return false; - } - - u32 GetResourceIdByName(const char* name) const - { - for (const std::unique_ptr& file : x1c_pakLoadedList) - { - u32 id = file->GetResIdByName(name); - if (id) - return id; - } - return 0; - } - - bool AreAllPaksLoaded() const - { - return x44_pakLoadingCount == 0; - } - - void AsyncIdlePakLoading() - { - for (auto it=x34_pakLoadingList.begin(); - it != x34_pakLoadingList.end(); - ++it) - { - (*it)->AsyncIdle(); - if ((*it)->x2c_asyncLoadPhase == CPakFile::PakAsyncLoaded) - { - MoveToCorrectLoadedList(std::move(*it)); - it = x34_pakLoadingList.erase(it); - --x44_pakLoadingCount; - } - } - } - - bool FindResource(u32 id) - { - for (const std::unique_ptr& file : x1c_pakLoadedList) - if (CacheFromPak(*file, id)) - return true; - return false; - } - - CPakFile* FindResourceForLoad(u32 id) - { - for (std::unique_ptr& file : x1c_pakLoadedList) - if (CacheFromPakForLoad(*file, id)) - return file.get(); - return nullptr; - } - - CPakFile* FindResourceForLoad(const SObjectTag& tag) - { - return FindResourceForLoad(tag.id); - } - - bool CacheFromPakForLoad(CPakFile& file, u32 id) - { - const CPakFile::SResInfo* info = file.GetResInfoForLoad(id); - if (info) - { - x4c_cachedResId = id; - x50_cachedResInfo = info; - return true; - } - return false; - } - - bool CacheFromPak(const CPakFile& file, u32 id) - { - const CPakFile::SResInfo* info = file.GetResInfo(id); - if (info) - { - x4c_cachedResId = id; - x50_cachedResInfo = info; - return true; - } - return false; - } - - void MoveToCorrectLoadedList(std::unique_ptr&& file) - { - x1c_pakLoadedList.push_back(std::move(file)); - } + const std::vector* GetTagListForFile(const std::string& name) const; + void AddPakFileAsync(const std::string& name, bool flag); + void AddPakFile(const std::string& name, bool flag); + CInputStream* LoadNewResourcePartSync(const SObjectTag& tag, int offset, int length, void* extBuf); + void LoadMemResourceSync(const SObjectTag& tag, void** bufOut, int* sizeOut); + CInputStream* LoadResourceFromMemorySync(const SObjectTag& tag, const void* buf); + CInputStream* LoadNewResourceSync(const SObjectTag& tag, void* extBuf=nullptr); + CDvdRequest* LoadResourcePartAsync(const SObjectTag& tag, int offset, int length, void* buf); + CDvdRequest* LoadResourceAsync(const SObjectTag& tag, void* buf); + bool GetResourceCompression(const SObjectTag& tag); + u32 ResourceSize(const SObjectTag& tag); + bool ResourceExists(const SObjectTag& tag); + FourCC GetResourceTypeById(u32 id); + u32 GetResourceIdByName(const char* name) const; + bool AreAllPaksLoaded() const; + void AsyncIdlePakLoading(); + bool FindResource(u32 id); + CPakFile* FindResourceForLoad(u32 id); + CPakFile* FindResourceForLoad(const SObjectTag& tag); + bool CacheFromPakForLoad(CPakFile& file, u32 id); + bool CacheFromPak(const CPakFile& file, u32 id); + void MoveToCorrectLoadedList(std::unique_ptr&& file); }; } diff --git a/Runtime/IAllocator.hpp b/Runtime/IAllocator.hpp index 0697a1c51..e8cea55ff 100644 --- a/Runtime/IAllocator.hpp +++ b/Runtime/IAllocator.hpp @@ -14,12 +14,19 @@ public: virtual ~IAllocator() {} enum EHint { + HintNone = 0x0, + HintTopOfHeap = 0x1, + HintLarge = 0x2 }; enum EScope { + ScopeNone = 0, + ScopeDefault = 1 }; enum EType { + TypePrimitive = 0, + TypeArray = 1 }; struct SAllocInfo { @@ -54,10 +61,10 @@ public: virtual bool Initialize(COsContext&)=0; virtual void Shutdown()=0; - virtual void* Alloc(u32, EHint, EScope, EType, const CCallStack&)=0; + virtual void* Alloc(size_t, EHint, EScope, EType, const CCallStack&)=0; virtual void Free(void*)=0; virtual void ReleaseAll()=0; - virtual void* AllocSecondary(u32, EHint, EScope, EType, const CCallStack&)=0; + virtual void* AllocSecondary(size_t, EHint, EScope, EType, const CCallStack&)=0; virtual void FreeSecondary(void*)=0; virtual void ReleaseAllSecondary()=0; virtual void SetOutOfMemoryCallback(const TOutOfMemoryCallback, void*)=0; diff --git a/Runtime/IOStreams.cpp b/Runtime/IOStreams.cpp new file mode 100644 index 000000000..c3fd1117c --- /dev/null +++ b/Runtime/IOStreams.cpp @@ -0,0 +1,49 @@ +#include "IOStreams.hpp" +#include "CMemory.hpp" + +namespace Retro +{ + +class CZipSupport +{ +public: + static void* Alloc(void*, u32 c, u32 n) + { + return NEWA(u8, c*n); + } + static void Free(void*, void* buf) + { + delete[] static_cast(buf); + } +}; + +CZipInputStream::CZipInputStream(std::unique_ptr&& strm) +: x24_compBuf(NEWA(u8, 4096)), x28_strm(std::move(strm)) +{ + x30_zstrm.next_in = x24_compBuf.get(); + x30_zstrm.avail_in = 0; + x30_zstrm.zalloc = CZipSupport::Alloc; + x30_zstrm.zfree = CZipSupport::Free; + inflateInit(&x30_zstrm); +} + +CZipInputStream::~CZipInputStream() +{ + inflateEnd(&x30_zstrm); +} + +atUint64 CZipInputStream::readUBytesToBuf(void *buf, atUint64 len) +{ + x30_zstrm.next_out = (Bytef*)buf; + x30_zstrm.avail_out = len; + if (!x30_zstrm.avail_in) + { + atUint64 readSz = x28_strm->readUBytesToBuf(x24_compBuf.get(), 4096); + x30_zstrm.avail_in = readSz; + x30_zstrm.next_in = x24_compBuf.get(); + } + inflate(&x30_zstrm, Z_NO_FLUSH); + return x30_zstrm.total_out; +} + +} diff --git a/Runtime/IOStreams.hpp b/Runtime/IOStreams.hpp new file mode 100644 index 000000000..d58b8fd65 --- /dev/null +++ b/Runtime/IOStreams.hpp @@ -0,0 +1,34 @@ +#ifndef __RETRO_IOSTREAMS_HPP__ +#define __RETRO_IOSTREAMS_HPP__ + +#include "RetroTypes.hpp" +#include +#include +#include +#include + +namespace Retro +{ + +using CInputStream = Athena::io::IStreamReader; +using COutputStream = Athena::io::IStreamWriter; + +using CMemoryInStream = Athena::io::MemoryReader; + +class CZipInputStream : public CInputStream +{ + std::unique_ptr x24_compBuf; + std::unique_ptr x28_strm; + z_stream x30_zstrm = {}; +public: + CZipInputStream(std::unique_ptr&& strm); + ~CZipInputStream(); + atUint64 readUBytesToBuf(void *buf, atUint64 len); + void seek(atInt64, Athena::SeekOrigin) {} + atUint64 position() const {return 0;} + atUint64 length() const {return 0;} +}; + +} + +#endif // __RETRO_IOSTREAMS_HPP__ diff --git a/Runtime/MP1/CTweakParticle.hpp b/Runtime/MP1/CTweakParticle.hpp index ecdb1ad18..7c7d564a3 100644 --- a/Runtime/MP1/CTweakParticle.hpp +++ b/Runtime/MP1/CTweakParticle.hpp @@ -1,7 +1,7 @@ #ifndef __RETRO_CTWEAKPARTICLE_HPP__ #define __RETRO_CTWEAKPARTICLE_HPP__ -#include "CBasics.hpp" +#include "IOStreams.hpp" #include "DataSpec/DNAMP1/Tweaks/CTweakParticle.hpp" namespace Retro diff --git a/Runtime/MP1/CTweaks.hpp b/Runtime/MP1/CTweaks.hpp index 6d56ad651..ef642fed4 100644 --- a/Runtime/MP1/CTweaks.hpp +++ b/Runtime/MP1/CTweaks.hpp @@ -1,6 +1,7 @@ #ifndef __RETRO_CTWEAKS_HPP__ #define __RETRO_CTWEAKS_HPP__ +#include "RetroTypes.hpp" #include "CTweakParticle.hpp" namespace Retro diff --git a/hecl b/hecl index 2a9a822dc..cba8336d7 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit 2a9a822dc7643c43731876ae506fcef43b7550ae +Subproject commit cba8336d73c7ea0dd8f673881a6a6d8d4ec5af34