1#include <dol/bases/d_res.hpp>
2#include <lib/MSL_C/string.h>
3#include <lib/rvl/cx/cx.h>
35 if (info ==
nullptr) {
38 if (info ==
nullptr) {
41 if (!info->
set(arcName, containingFolder, allocDir, heap)) {
52 if (info ==
nullptr) {
57 if (info->getRefCount() == 0) {
67 if (info !=
nullptr && info->getArchive() !=
nullptr) {
68 data = info->getArchive()->getFile(resPath,
nullptr);
73void *
dRes_c::getRes(
const char *arcName,
const char *resPath,
unsigned long *size)
const {
77 if (info !=
nullptr && info->getArchive() !=
nullptr) {
80 data = archive->getFile(resPath, &fi);
81 newSize = fi.mFileSize;
87void *
dRes_c::getRes(
const char *arcName,
const char *resPath,
unsigned long *size,
int *compressionType)
const {
91 if (info !=
nullptr && info->getArchive() !=
nullptr) {
93 long entryID = archive->convertPathToEntryID(resPath);
97 data = archive->getFileFast(entryID, &fi);
99 if (data !=
nullptr) {
100 if (compressionType !=
nullptr) {
101 *compressionType = 0;
103 if (size !=
nullptr) {
104 *size = fi.mFileSize;
110 snprintf(path,
sizeof(path),
"%s.LZ", resPath);
111 entryID = archive->convertPathToEntryID(path);
114 data = archive->getFileFast(entryID,
nullptr);
116 if (data !=
nullptr) {
117 if (compressionType !=
nullptr) {
118 *compressionType = ((u8 *) data)[0] & 0xF0;
120 if (size !=
nullptr) {
121 *size = CXGetUncompressedSize(data);
131 memcpy(to, from, size);
135 if (compressionType == 0) {
138 CXUncompressLZ(from, to);
143 void *data =
nullptr;
146 if (info !=
nullptr && info->getArchive() !=
nullptr) {
148 long entryID = archive->convertPathToEntryID(resPath);
152 data = archive->getFileFast(entryID,
nullptr);
160 void *data =
nullptr;
164 if (info !=
nullptr && info->getArchive() !=
nullptr) {
166 long entryID = archive->convertPathToEntryID(resPath);
171 data = archive->getFileFast(entryID, &fi);
172 newSize = fi.mFileSize;
183 for (
int i = 0; i <
mNumArcs; i++) {
184 if (info->getDvdCmd() !=
nullptr) {
197 for (
int i = 0; i < count; i++) {
198 if (info->getRefCount() > 0 && strcmp(arcName, info->getName()) == 0) {
208 for (
int i = 0; i <
mNumArcs; i++) {
210 if (info->getRefCount() == 0) {
220 if (info ==
nullptr) {
222 }
else if (info->getArchive() ==
nullptr) {
A callback class for processing resources.
A class that holds information about an archive.
bool set(const char *arcName, const char *containingFolder, u8 allocDirection, EGG::Heap *heap)
Sets information about the archive to be loaded.
void decRefCount()
Decrements the reference count.
void incRefCount()
Increments the reference count.
int setRes(callback_c *callback)
Attempts to load the archive into memory and load the resources with a callback.
bool cleanup()
Unmounts the archive and frees the holder for use.
~dRes_c()
Destroys this dRes_c.
info_c * newResInfo()
Gets a free info_c that can be used to store an archive reference.
u16 mNumArcs
The number of archive holders.
dRes_c()
Constructs a new dRes_c.
static void copyRes(const void *from, void *to, int size)
Copies an uncompressed resource.
info_c * getResInfoLoaded(const char *arcName) const
Gets the info_c for an archive, if it exists and has been loaded into memory.
static void(* mSetCallback)(const char *arcName, EGG::Heap *heap)
[Unused]. The callback for when dRes_c::info_c::set is called.
callback_c * mpCallback
The callback for when a resource is loaded.
bool syncAllRes()
Attempts to load the resources of an archive that has finished loading since the last call to this fu...
bool deleteRes(const char *arcName)
Marks the archive as no longer needed.
void * getRes(const char *arcName, const char *resPath) const
Loads a resource.
info_c * mpArcInfos
An array of archive holders.
void * getResSilently(const char *arcName, const char *resPath) const
Loads a resource without logging a message if the resource is not found.
bool setRes(const char *arcName, const char *containingFolder, u8 allocDir, EGG::Heap *heap)
Registers an archive to be loaded next.
bool init(u16 maxCount, callback_c *callback)
Initializes the dRes_c.
info_c * getResInfo(const char *arcName) const
Gets the info_c for an archive, if it exists.