Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
Loading...
Searching...
No Matches
JKRArchive.h
Go to the documentation of this file.
1#ifndef JKRARCHIVE_H
2#define JKRARCHIVE_H
3
6#include "global.h"
7
8class JKRHeap;
9
14struct SArcHeader {
15 /* 0x00 */ u32 signature;
16 /* 0x04 */ u32 file_length;
17 /* 0x08 */ u32 header_length;
20 /* 0x14 */ u32 field_0x14;
21 /* 0x18 */ u32 field_0x18;
22 /* 0x1C */ u32 field_0x1c;
23};
24
30 /* 0x00 */ u32 num_nodes;
31 /* 0x04 */ u32 node_offset;
38 /* 0x1B */ u8 field_1b[5];
39};
40
41inline u32 read_big_endian_u32(void* ptr) {
42 u8* uptr = (u8*)ptr;
43 return ((u32)uptr[0] << 0x18) | ((u32)uptr[1] << 0x10) | ((u32)uptr[2] << 8) | (u32)uptr[3];
44}
45
46inline u16 read_big_endian_u16(void* ptr) {
47 u8* uptr = (u8*)ptr;
48 return ((u16)uptr[0] << 8) | ((u16)uptr[1]);
49}
50
51extern u32 sCurrentDirID__10JKRArchive; // JKRArchive::sCurrentDirID
52
57class JKRArchive : public JKRFileLoader {
58public:
59 struct SDirEntry {
63 const char* name;
64 };
65
73
74 struct SDIFileEntry {
80 void* data;
81
82 u32 getNameOffset() const { return type_flags_and_name_offset & 0xFFFFFF; }
83 u16 getNameHash() const { return name_hash; }
84 u32 getFlags() const { return type_flags_and_name_offset >> 24; }
85 u32 getAttr() const { return getFlags(); }
86 u16 getFileID() const { return file_id; }
87 bool isDirectory() const { return (getFlags() & 0x02) != 0; }
88 bool isUnknownFlag1() const { return (getFlags() & 0x01) != 0; }
89 bool isCompressed() const { return (getFlags() & 0x04) != 0; }
90 // was needed for open__14JKRAramArchiveFl
91 u8 getCompressFlag() const { return (getFlags() & 0x04); }
92 bool isYAZ0Compressed() const { return (getFlags() & 0x80) != 0; }
93 u32 getSize() const { return data_size; }
94 };
95
103
109
110 class CArcName {
111 public:
113 CArcName(char const* data) { this->store(data); }
114 CArcName(char const** data, char endChar) { *data = this->store(*data, endChar); }
115
116 void store(char const* data);
117 const char* store(char const* data, char endChar);
118
119 u16 getHash() const { return mHash; }
120
121 const char* getString() const { return mData; }
122
123 private:
126 char mData[256];
127 };
128
129protected:
132
133public:
134 virtual ~JKRArchive();
135 bool getDirEntry(SDirEntry*, u32) const;
136 void* getIdxResource(u32);
137 void* getResource(u16);
138 u32 readIdxResource(void*, u32, u32);
139 u32 readResource(void*, u32, u16);
140 u32 countResource(void) const;
141 u32 getFileAttribute(u32) const;
142
143 SDIFileEntry* findNameResource(const char*) const;
144 bool isSameName(CArcName&, u32, u16) const;
146 SDIDirEntry* findDirectory(const char*, u32) const;
147 SDIFileEntry* findTypeResource(u32, const char*) const;
148 SDIFileEntry* findFsResource(const char*, u32) const;
150 SDIFileEntry* findPtrResource(const void*) const;
152
153public:
154 /* vt[04] */ virtual bool becomeCurrent(const char*); /* override */
155 /* vt[05] */ virtual void* getResource(const char*); /* override */
156 /* vt[06] */ virtual void* getResource(u32, const char*); /* override */
157 /* vt[07] */ virtual u32 readResource(void*, u32, const char*); /* override */
158 /* vt[08] */ virtual u32 readResource(void*, u32, u32, const char*); /* override */
159 /* vt[09] */ virtual void removeResourceAll(void); /* override */
160 /* vt[10] */ virtual bool removeResource(void*); /* override */
161 /* vt[11] */ virtual bool detachResource(void*); /* override */
162 /* vt[12] */ virtual u32 getResSize(const void*) const; /* override */
163 /* vt[13] */ virtual u32 countFile(const char*) const; /* override */
164 /* vt[14] */ virtual JKRFileFinder* getFirstFile(const char*) const; /* override */
165 /* vt[15] */ virtual u32 getExpandedResSize(const void* res) const { return getResSize(res); }
166 /* vt[16] */ virtual void* fetchResource(SDIFileEntry*, u32*) = 0;
167 /* vt[17] */ virtual void* fetchResource(void*, u32, SDIFileEntry*, u32*) = 0;
168 /* vt[18] */ virtual void setExpandSize(SDIFileEntry*, u32);
169 /* vt[19] */ virtual u32 getExpandSize(SDIFileEntry*) const;
170
173 u8 getMountMode() const { return mMountMode; }
175 return getFileAttribute(param_0) & 1;
176 }
177
178public:
179 /* 0x00 */ // vtable
180 /* 0x04 */ // JKRFileLoader
181 /* 0x38 */ JKRHeap* mHeap;
182 /* 0x3C */ u8 mMountMode;
183 /* 0x3D */ u8 field_0x3d[3];
184 /* 0x40 */ s32 mEntryNum;
186 /* 0x48 */ SDIDirEntry* mNodes;
187 /* 0x4C */ SDIFileEntry* mFiles;
188 /* 0x50 */ s32* mExpandedSize;
189 /* 0x54 */ char* mStringTable;
190
191protected:
192 /* 0x58 */ u32 field_0x58;
195
196public:
198 static JKRArchive* mount(const char*, EMountMode, JKRHeap*, EMountDirection);
199 static JKRArchive* mount(void*, JKRHeap*, EMountDirection);
201 static void* getGlbResource(u32, const char*, JKRArchive*);
202
204#define JKRARCHIVE_ATTR_COMPRESSION 0x04
205#define JKRARCHIVE_ATTR_YAY0 0x80
206
210 } else if (!FLAG_ON(attr, JKRARCHIVE_ATTR_YAY0)) {
212 } else {
214 }
215 return compression;
216 }
217
218 static u32 getCurrentDirID() { return sCurrentDirID; }
220
221private:
223};
224
228
229inline void* JKRGetResource(u32 node, const char* path, JKRArchive* archive) {
230 return JKRArchive::getGlbResource(node, path, archive);
231}
232
233inline void* JKRGetTypeResource(u32 tag, const char* name, JKRArchive* arc) {
234 return JKRArchive::getGlbResource(tag, name, arc);
235}
236
240
242 arc->unmount();
243}
244
245inline void JKRReadIdxResource(void* param_1, u32 param_2, u32 param_3, JKRArchive* param_4) {
246 param_4->readIdxResource(param_1, param_2, param_3);
247}
248
249#endif
u16 read_big_endian_u16(void *ptr)
Definition JKRArchive.h:46
u32 sCurrentDirID__10JKRArchive
bool JKRRemoveResource(void *resource, JKRFileLoader *fileLoader)
Definition JKRArchive.h:237
void * JKRGetTypeResource(u32 tag, const char *name, JKRArchive *arc)
Definition JKRArchive.h:233
u32 read_big_endian_u32(void *ptr)
Definition JKRArchive.h:41
void * JKRGetResource(u32 node, const char *path, JKRArchive *archive)
Definition JKRArchive.h:229
void JKRUnmountArchive(JKRArchive *arc)
Definition JKRArchive.h:241
void JKRReadIdxResource(void *param_1, u32 param_2, u32 param_3, JKRArchive *param_4)
Definition JKRArchive.h:245
JKRCompression JKRConvertAttrToCompressionType(u32 attr)
Definition JKRArchive.h:225
int JKRCompression
Definition JKRCompression.h:4
const JKRCompression COMPRESSION_YAZ0
Definition JKRCompression.h:7
const JKRCompression COMPRESSION_YAY0
Definition JKRCompression.h:6
const JKRCompression COMPRESSION_NONE
Definition JKRCompression.h:5
T cLib_calcTimer(T *value)
Definition c_lib.h:74
Definition JKRArchive.h:110
CArcName()
Definition JKRArchive.h:112
u16 mLength
Definition JKRArchive.h:125
CArcName(char const *data)
Definition JKRArchive.h:113
char mData[256]
Definition JKRArchive.h:126
CArcName(char const **data, char endChar)
Definition JKRArchive.h:114
u16 getHash() const
Definition JKRArchive.h:119
void store(char const *data)
Definition JKRArchivePri.cpp:187
u16 mHash
Definition JKRArchive.h:124
const char * getString() const
Definition JKRArchive.h:121
Definition JKRArchive.h:57
SDIFileEntry * findFsResource(const char *, u32) const
Definition JKRArchivePri.cpp:102
bool isFileEntry(u32 param_0)
Definition JKRArchive.h:174
u32 countFile() const
Definition JKRArchive.h:171
virtual JKRFileFinder * getFirstFile(const char *) const
Definition JKRArchivePub.cpp:359
virtual u32 getExpandSize(SDIFileEntry *) const
Definition JKRArchivePri.cpp:237
virtual bool becomeCurrent(const char *)
Definition JKRArchivePub.cpp:103
SDIDirEntry * mNodes
Definition JKRArchive.h:186
s32 countDirectory() const
Definition JKRArchive.h:172
JKRCompression mCompression
Definition JKRArchive.h:193
SDIFileEntry * findTypeResource(u32, const char *) const
Definition JKRArchivePri.cpp:82
static JKRArchive * mount(const char *, EMountMode, JKRHeap *, EMountDirection)
Definition JKRArchivePub.cpp:34
u32 countResource(void) const
Definition JKRArchivePub.cpp:328
static JKRArchive * check_mount_already(s32, JKRHeap *)
Definition JKRArchivePub.cpp:12
virtual u32 getResSize(const void *) const
Definition JKRArchivePub.cpp:318
u8 field_0x3d[3]
Definition JKRArchive.h:183
SDIFileEntry * findPtrResource(const void *) const
Definition JKRArchivePri.cpp:153
static u32 getCurrentDirID()
Definition JKRArchive.h:218
virtual ~JKRArchive()
Definition JKRArchivePri.cpp:31
u32 getFileAttribute(u32) const
Definition JKRArchivePub.cpp:382
static JKRCompression convertAttrToCompressionType(u32 attr)
Definition JKRArchive.h:203
void * getIdxResource(u32)
Definition JKRArchivePub.cpp:193
void * getResource(u16)
Definition JKRArchivePub.cpp:204
static void * getGlbResource(u32, const char *, JKRArchive *)
Definition JKRArchivePub.cpp:139
static void setCurrentDirID(u32 dirID)
Definition JKRArchive.h:219
virtual bool detachResource(void *)
Definition JKRArchivePub.cpp:307
virtual void * fetchResource(void *, u32, SDIFileEntry *, u32 *)=0
u8 mMountMode
Definition JKRArchive.h:182
virtual bool removeResource(void *)
Definition JKRArchivePub.cpp:295
char * mStringTable
Definition JKRArchive.h:189
bool getDirEntry(SDirEntry *, u32) const
Definition JKRArchivePub.cpp:126
static u32 sCurrentDirID
Definition JKRArchive.h:222
u32 readResource(void *, u32, u16)
Definition JKRArchivePub.cpp:268
EMountDirection mMountDirection
Definition JKRArchive.h:194
JKRHeap * mHeap
Definition JKRArchive.h:181
SDIFileEntry * findIdxResource(u32) const
Definition JKRArchivePri.cpp:128
s32 * mExpandedSize
Definition JKRArchive.h:188
virtual u32 getExpandedResSize(const void *res) const
Definition JKRArchive.h:165
SDIFileEntry * findNameResource(const char *) const
Definition JKRArchivePri.cpp:138
SDIDirEntry * findDirectory(const char *, u32) const
Definition JKRArchivePri.cpp:60
virtual void * fetchResource(SDIFileEntry *, u32 *)=0
u8 getMountMode() const
Definition JKRArchive.h:173
SDIFileEntry * mFiles
Definition JKRArchive.h:187
s32 mEntryNum
Definition JKRArchive.h:184
SDIFileEntry * findIdResource(u16) const
Definition JKRArchivePri.cpp:165
EMountDirection
Definition JKRArchive.h:104
@ MOUNT_DIRECTION_TAIL
Definition JKRArchive.h:107
@ UNKNOWN_MOUNT_DIRECTION
Definition JKRArchive.h:105
@ MOUNT_DIRECTION_HEAD
Definition JKRArchive.h:106
bool isSameName(CArcName &, u32, u16) const
Definition JKRArchivePri.cpp:35
virtual void removeResourceAll(void)
Definition JKRArchivePub.cpp:282
u32 readIdxResource(void *, u32, u32)
Definition JKRArchivePub.cpp:254
virtual void setExpandSize(SDIFileEntry *, u32)
Definition JKRArchivePri.cpp:227
SArcDataInfo * mArcInfoBlock
Definition JKRArchive.h:185
SDIDirEntry * findResType(u32) const
Definition JKRArchivePri.cpp:43
u32 field_0x58
Definition JKRArchive.h:192
EMountMode
Definition JKRArchive.h:96
@ MOUNT_DVD
Definition JKRArchive.h:100
@ UNKNOWN_MOUNT_MODE
Definition JKRArchive.h:97
@ MOUNT_COMP
Definition JKRArchive.h:101
@ MOUNT_ARAM
Definition JKRArchive.h:99
@ MOUNT_MEM
Definition JKRArchive.h:98
Definition JKRFileFinder.h:10
Definition JKRFileLoader.h:12
virtual bool removeResource(void *)=0
Definition JKRHeap.h:16
static const Attr & attr()
Definition d_a_obj_ladder.cpp:135
static u16 data[4]
Definition d_vibration.cpp:114
Definition JKRArchive.h:66
u16 num_entries
Definition JKRArchive.h:70
u32 first_file_index
Definition JKRArchive.h:71
u32 type
Definition JKRArchive.h:67
u32 name_offset
Definition JKRArchive.h:68
u16 field_0x8
Definition JKRArchive.h:69
Definition JKRArchive.h:74
u8 getCompressFlag() const
Definition JKRArchive.h:91
bool isDirectory() const
Definition JKRArchive.h:87
u16 file_id
Definition JKRArchive.h:75
u32 getFlags() const
Definition JKRArchive.h:84
bool isUnknownFlag1() const
Definition JKRArchive.h:88
u16 getNameHash() const
Definition JKRArchive.h:83
bool isCompressed() const
Definition JKRArchive.h:89
u32 getAttr() const
Definition JKRArchive.h:85
u32 type_flags_and_name_offset
Definition JKRArchive.h:77
u16 name_hash
Definition JKRArchive.h:76
u32 data_size
Definition JKRArchive.h:79
u32 getSize() const
Definition JKRArchive.h:93
bool isYAZ0Compressed() const
Definition JKRArchive.h:92
void * data
Definition JKRArchive.h:80
u32 data_offset
Definition JKRArchive.h:78
u16 getFileID() const
Definition JKRArchive.h:86
u32 getNameOffset() const
Definition JKRArchive.h:82
Definition JKRArchive.h:59
u8 flags
Definition JKRArchive.h:60
u16 id
Definition JKRArchive.h:62
u8 padding
Definition JKRArchive.h:61
const char * name
Definition JKRArchive.h:63
Definition JKRArchive.h:29
u32 num_file_entries
Definition JKRArchive.h:32
u32 string_table_offset
Definition JKRArchive.h:35
u32 string_table_length
Definition JKRArchive.h:34
u32 node_offset
Definition JKRArchive.h:31
u32 file_entry_offset
Definition JKRArchive.h:33
u16 next_free_file_id
Definition JKRArchive.h:36
bool sync_file_ids_and_indices
Definition JKRArchive.h:37
u32 num_nodes
Definition JKRArchive.h:30
u8 field_1b[5]
Definition JKRArchive.h:38
Definition JKRArchive.h:14
u32 file_data_length
Definition JKRArchive.h:19
u32 field_0x14
Definition JKRArchive.h:20
u32 file_data_offset
Definition JKRArchive.h:18
u32 field_0x1c
Definition JKRArchive.h:22
u32 header_length
Definition JKRArchive.h:17
u32 file_length
Definition JKRArchive.h:16
u32 signature
Definition JKRArchive.h:15
u32 field_0x18
Definition JKRArchive.h:21
unsigned long u32
Definition types.h:10
unsigned short u16
Definition types.h:9
signed long s32
Definition types.h:6
unsigned char u8
Definition types.h:8