summaryrefslogtreecommitdiffstats
path: root/src/core/Directory.cpp
diff options
context:
space:
mode:
authoraap <aap@papnet.eu>2019-07-07 13:09:11 +0200
committeraap <aap@papnet.eu>2019-07-07 13:09:11 +0200
commit53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb (patch)
treefc65a6c40fa719f9d43be9e0e15be79c490135e0 /src/core/Directory.cpp
parentfinished CPhysical (diff)
downloadre3-53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb.tar
re3-53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb.tar.gz
re3-53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb.tar.bz2
re3-53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb.tar.lz
re3-53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb.tar.xz
re3-53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb.tar.zst
re3-53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb.zip
Diffstat (limited to 'src/core/Directory.cpp')
-rw-r--r--src/core/Directory.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/core/Directory.cpp b/src/core/Directory.cpp
new file mode 100644
index 00000000..3e0d5382
--- /dev/null
+++ b/src/core/Directory.cpp
@@ -0,0 +1,65 @@
+#include "common.h"
+#include "patcher.h"
+#include "FileMgr.h"
+#include "Directory.h"
+
+CDirectory::CDirectory(int32 maxEntries)
+ : numEntries(0), maxEntries(maxEntries)
+{
+ entries = new DirectoryInfo[maxEntries];
+}
+
+CDirectory::~CDirectory(void)
+{
+ delete[] entries;
+}
+
+void
+CDirectory::ReadDirFile(const char *filename)
+{
+ int fd;
+ DirectoryInfo dirinfo;
+
+ fd = CFileMgr::OpenFile(filename, "rb");
+ while(CFileMgr::Read(fd, (char*)&dirinfo, sizeof(dirinfo)))
+ AddItem(dirinfo);
+ CFileMgr::CloseFile(fd);
+}
+
+bool
+CDirectory::WriteDirFile(const char *filename)
+{
+ int fd, n;
+ fd = CFileMgr::OpenFileForWriting(filename);
+ n = CFileMgr::Write(fd, (char*)entries, numEntries*sizeof(DirectoryInfo));
+ CFileMgr::CloseFile(fd);
+ return n == numEntries*sizeof(DirectoryInfo);
+}
+
+void
+CDirectory::AddItem(const DirectoryInfo &dirinfo)
+{
+ assert(numEntries < maxEntries);
+ entries[numEntries++] = dirinfo;
+}
+
+bool
+CDirectory::FindItem(const char *name, uint32 &offset, uint32 &size)
+{
+ int i;
+
+ for(i = 0; i < numEntries; i++)
+ if(strcmpi(entries[i].name, name) == 0){
+ offset = entries[i].offset;
+ size = entries[i].size;
+ return true;
+ }
+ return false;
+}
+
+STARTPATCHES
+ InjectHook(0x473630, &CDirectory::ReadDirFile, PATCH_JUMP);
+ InjectHook(0x473690, &CDirectory::WriteDirFile, PATCH_JUMP);
+ InjectHook(0x473600, &CDirectory::AddItem, PATCH_JUMP);
+ InjectHook(0x4736E0, &CDirectory::FindItem, PATCH_JUMP);
+ENDPATCHES