summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoraap <aap@papnet.eu>2019-06-03 05:26:49 +0200
committeraap <aap@papnet.eu>2019-06-03 05:27:07 +0200
commit498a903d0c0332f6a1e06e69ad297ff8f5d3f31c (patch)
tree9ab7e846cff100b8f7a547d5444b250153db2ba2 /src
parentadded CPhysical flags from Nick (diff)
downloadre3-498a903d0c0332f6a1e06e69ad297ff8f5d3f31c.tar
re3-498a903d0c0332f6a1e06e69ad297ff8f5d3f31c.tar.gz
re3-498a903d0c0332f6a1e06e69ad297ff8f5d3f31c.tar.bz2
re3-498a903d0c0332f6a1e06e69ad297ff8f5d3f31c.tar.lz
re3-498a903d0c0332f6a1e06e69ad297ff8f5d3f31c.tar.xz
re3-498a903d0c0332f6a1e06e69ad297ff8f5d3f31c.tar.zst
re3-498a903d0c0332f6a1e06e69ad297ff8f5d3f31c.zip
Diffstat (limited to 'src')
-rw-r--r--src/Directory.cpp65
-rw-r--r--src/Directory.h22
2 files changed, 87 insertions, 0 deletions
diff --git a/src/Directory.cpp b/src/Directory.cpp
new file mode 100644
index 00000000..553dd539
--- /dev/null
+++ b/src/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);
+ return 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
diff --git a/src/Directory.h b/src/Directory.h
new file mode 100644
index 00000000..06e6bba4
--- /dev/null
+++ b/src/Directory.h
@@ -0,0 +1,22 @@
+#pragma once
+
+class CDirectory
+{
+public:
+ struct DirectoryInfo {
+ uint32 offset;
+ uint32 size;
+ char name[24];
+ };
+ DirectoryInfo *entries;
+ int32 maxEntries;
+ int32 numEntries;
+
+ CDirectory(int32 maxEntries);
+ ~CDirectory(void);
+
+ void ReadDirFile(const char *filename);
+ bool WriteDirFile(const char *filename);
+ void AddItem(const DirectoryInfo &dirinfo);
+ bool FindItem(const char *name, uint32 &offset, uint32 &size);
+};