forked from derandark/DungeonViewerAC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DATDisk.h
190 lines (147 loc) · 3.58 KB
/
DATDisk.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#pragma once
#ifdef PRE_TOD
#define DAT_HEADER_OFFSET 0x12C
#else
#define DAT_HEADER_OFFSET 0x140
#endif
#ifdef PRE_TOD
struct DATHeader
{
DWORD FileType; // 0x00 'TB' !
DWORD BlockSize; // 0x04 0x400 for PORTAL : 0x100 for CELL
DWORD FileSize; // 0x08 Should match file size.
DWORD Iteration; // 0x0C Version iteration.
DWORD FreeHead; // 0x10
DWORD FreeTail; // 0x14
DWORD FreeCount; // 0x18
DWORD BTree; // 0x1C BTree offset
DWORD Unknown0; // 0x20
DWORD Unknown1; // 0x24
DWORD Unknown2; // 0x28
};
#else
struct DATHeader
{
DWORD FileType;
DWORD BlockSize;
DWORD FileSize;
DWORD Iteration;
DWORD Iteration2;
DWORD FreeHead;
DWORD FreeTail;
DWORD FreeCount;
DWORD BTree;
DWORD Unknown0;
DWORD Unknown1;
DWORD Unknown2;
DWORD Unknown3;
DWORD Unknown4;
DWORD Unknown5;
DWORD Unknown6;
};
#endif
#ifdef PRE_TOD
struct BTreeEntry
{
DWORD ID;
DWORD BlockHead;
DWORD Length;
};
#else
struct BTreeEntry
{
DWORD Unknown00;
DWORD ID;
DWORD BlockHead;
DWORD Length;
DWORD Timestamp;
DWORD Unknown14;
};
#endif
struct BTreeData
{
DWORD BlockSpacer;
DWORD Branches[ 0x3E ];
DWORD EntryCount;
BTreeEntry Entries[ 0x3D ];
};
class BlockLoader;
class BTreeNode
{
public:
BTreeNode(BlockLoader *pBlockLoader);
virtual ~BTreeNode();
BOOL LoadData(DWORD BlockHead);
void LoadChildren();
void LoadChildrenRecursive();
void SetFileCallback(void(*)(DWORD, BTreeEntry *));
void SetProgressCallback(void(*)(float));
BOOL Lookup(DWORD ID, BTreeEntry *pEntry);
void FindEntryIDsWithinRange(DWORD Min, DWORD Max, float Progress, float ProgressDelta);
protected:
DWORD GetBranchCount() const;
BTreeNode *GetBranch(DWORD index);
// Using this design, you can't run 2 scans at the same time.
static void (*m_pfnFileCallback)(DWORD, BTreeEntry *);
static void (*m_pfnProgressCallback)(float);
BlockLoader *m_pBlockLoader;
BTreeData m_TreeData;
BTreeNode* m_Branches[ 0x3E ];
BOOL m_bLeaf;
};
class BTree : public BTreeNode
{
public:
BTree(BlockLoader *pBlockLoader);
virtual ~BTree();
BOOL Init();
};
class DiskDev
{
public:
DiskDev();
~DiskDev();
BOOL OpenFile(const char* Path, DATHeader *pHeader);
void CloseFile();
BOOL SyncRead(void *pBuffer, DWORD dwLength, DWORD dwPosition);
BOOL SyncWrite(void *pBuffer, DWORD dwLength, DWORD dwPosition);
private:
HANDLE m_hFile;
};
class BlockLoader
{
public:
BlockLoader();
~BlockLoader();
BOOL Init(const char *Path, DATHeader *pHeader);
DWORD GetTreeOrigin();
BOOL LoadData(DWORD HeadBlock, void *pBuffer, DWORD Length);
private:
DATHeader *m_pHeader;
DiskDev m_DiskDev;
};
struct DATEntry
{
DWORD ID;
BYTE* Data;
DWORD Length;
};
class DATDisk
{
public:
static BOOL OpenDisks();
static void CloseDisks();
static DATDisk *pPortal;
static DATDisk *pCell;
DATDisk(const char *Path);
~DATDisk();
BOOL Open();
BOOL GetData(DWORD ID, DATEntry *pEntry);
BOOL GetDataEx(DWORD BlockHead, void *Data, DWORD Length);
void FindFileIDsWithinRange(DWORD Min, DWORD Max, void(*FileCallback)(DWORD, BTreeEntry *), void(*ProgressCallback)(float));
private:
char *m_FilePath;
DATHeader m_DATHeader;
BlockLoader m_BlockLoader;
BTree m_BTree;
};