NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
dRes_c Class Reference

#include <dol/bases/d_res.hpp>

Description

A utility class for loading resource files (files contained within a .arc file).

dRes_c is a holder for multiple archive (.arc) files.

Definition at line 12 of file d_res.hpp.

Classes

class  callback_c
 A callback class for processing resources. More...
 
class  info_c
 A class that holds information about an archive. More...
 
class  searchCallback_c
 A callback class for EGG::Archive::searchInside. More...
 

Public Member Functions

 dRes_c ()
 Constructs a new dRes_c.
 
 ~dRes_c ()
 Destroys this dRes_c.
 
bool init (u16 maxCount, callback_c *callback)
 Initializes the dRes_c.
 
bool setRes (const char *arcName, const char *containingFolder, u8 allocDir, EGG::Heap *heap)
 Registers an archive to be loaded next.
 
bool deleteRes (const char *arcName)
 Marks the archive as no longer needed.
 
void * getRes (const char *arcName, const char *resPath) const
 Loads a resource.
 
void * getRes (const char *arcName, const char *resPath, unsigned long *size) const
 Loads a resource.
 
void * getRes (const char *arcName, const char *resPath, unsigned long *size, int *compressionType) const
 Loads a resource which may optionally be compressed.
 
void * getResSilently (const char *arcName, const char *resPath) const
 Loads a resource without logging a message if the resource is not found.
 
void * getResSilently (const char *arcName, const char *resPath, unsigned long *size) const
 Loads a resource without logging a message if the resource is not found.
 
bool syncAllRes ()
 Attempts to load the resources of an archive that has finished loading since the last call to this function. The callback is executed on all files and folders.
 
info_cgetResInfo (const char *arcName) const
 Gets the info_c for an archive, if it exists.
 
info_cgetResInfoLoaded (const char *arcName) const
 Gets the info_c for an archive, if it exists and has been loaded into memory.
 
info_cnewResInfo ()
 Gets a free info_c that can be used to store an archive reference.
 

Static Public Member Functions

static void copyRes (const void *from, void *to, int size)
 Copies an uncompressed resource.
 
static void copyRes (const void *from, void *to, int size, int compressionType)
 Copies an optionally compressed resource.
 

Private Attributes

info_cmpArcInfos
 An array of archive holders.
 
u16 mNumArcs
 The number of archive holders.
 
callback_cmpCallback
 The callback for when a resource is loaded.
 

Static Private Attributes

static void(* mSetCallback )(const char *arcName, EGG::Heap *heap)
 [Unused]. The callback for when dRes_c::info_c::set is called.
 

Constructor & Destructor Documentation

◆ dRes_c()

dRes_c::dRes_c ( )

Constructs a new dRes_c.

Definition at line 7 of file d_res.cpp.

◆ ~dRes_c()

dRes_c::~dRes_c ( )

Destroys this dRes_c.

Definition at line 13 of file d_res.cpp.

Member Function Documentation

◆ init()

bool dRes_c::init ( u16  maxCount,
callback_c callback 
)

Initializes the dRes_c.

Parameters
maxCountThe number of archive holders to allocate.
callbackThe callback for after a archive has been loaded.
Returns
Whether the initialization was successful.

Definition at line 21 of file d_res.cpp.

◆ setRes()

bool dRes_c::setRes ( const char *  arcName,
const char *  containingFolder,
u8  allocDir,
EGG::Heap heap 
)

Registers an archive to be loaded next.

Parameters
resNameThe name of the archive to load.
filePathThe path to the folder which the archive is in.
allocDirThe allocation direction. 1: top-down, anything else: bottom-up.
heapThe heap to load the archive into.
Returns
Whether the operation was successful.

Definition at line 32 of file d_res.cpp.

◆ deleteRes()

bool dRes_c::deleteRes ( const char *  arcName)

Marks the archive as no longer needed.

Parameters
arcNameThe name of the archive to unload.
Returns
Whether the operation was successful.

Definition at line 50 of file d_res.cpp.

◆ getRes() [1/3]

void * dRes_c::getRes ( const char *  arcName,
const char *  resPath 
) const

Loads a resource.

Parameters
arcNameThe name of the archive which contains the resource.
resPathThe path to the resource within the archive.
Returns
A pointer to the contents of the resource.

Definition at line 64 of file d_res.cpp.

◆ getRes() [2/3]

void * dRes_c::getRes ( const char *  arcName,
const char *  resPath,
unsigned long *  size 
) const

Loads a resource.

Parameters
arcNameThe name of the archive which contains the resource.
resPathThe path to the resource within the archive.
sizeA pointer where the size of the resource will be written to.
Returns
A pointer to the contents of the resource.

Definition at line 73 of file d_res.cpp.

◆ getRes() [3/3]

void * dRes_c::getRes ( const char *  arcName,
const char *  resPath,
unsigned long *  size,
int *  compressionType 
) const

Loads a resource which may optionally be compressed.

If the resource is not found, it tries to load "<resource name>.LZ". Only .LZ compression is supported.

Parameters
arcNameThe name of the archive which contains the resource.
resPathThe path to the resource within the archive.
sizeA pointer where the size of the resource will be written to.
compressionTypeA pointer where the compression type of the resource will be written to.
Returns
A pointer to the contents of the resource.

Definition at line 87 of file d_res.cpp.

◆ getResSilently() [1/2]

void * dRes_c::getResSilently ( const char *  arcName,
const char *  resPath 
) const

Loads a resource without logging a message if the resource is not found.

See also
getRes(const char*, const char*) const

Definition at line 142 of file d_res.cpp.

◆ getResSilently() [2/2]

void * dRes_c::getResSilently ( const char *  arcName,
const char *  resPath,
unsigned long *  size 
) const

Loads a resource without logging a message if the resource is not found.

See also
getRes(const char*, const char*, unsigned long*) const

Definition at line 159 of file d_res.cpp.

◆ syncAllRes()

bool dRes_c::syncAllRes ( )

Attempts to load the resources of an archive that has finished loading since the last call to this function. The callback is executed on all files and folders.

Returns
Whether such an archive was found.

Definition at line 181 of file d_res.cpp.

◆ getResInfo()

dRes_c::info_c * dRes_c::getResInfo ( const char *  arcName) const

Gets the info_c for an archive, if it exists.

Parameters
arcNameThe name of the archive.
Returns
The info_c for the archive, if it exists, otherwise nullptr .

Definition at line 194 of file d_res.cpp.

◆ getResInfoLoaded()

dRes_c::info_c * dRes_c::getResInfoLoaded ( const char *  arcName) const

Gets the info_c for an archive, if it exists and has been loaded into memory.

Parameters
arcNameThe name of the archive.
Returns
The info_c for the archive, or nullptr if the info_c doesn't exist or the archive hasn't been loaded into memory.

Definition at line 218 of file d_res.cpp.

◆ newResInfo()

dRes_c::info_c * dRes_c::newResInfo ( )

Gets a free info_c that can be used to store an archive reference.

Returns
The info_c for the archive, or nullptr if none was available.

Definition at line 206 of file d_res.cpp.

◆ copyRes() [1/2]

void dRes_c::copyRes ( const void *  from,
void *  to,
int  size 
)
static

Copies an uncompressed resource.

Definition at line 130 of file d_res.cpp.

◆ copyRes() [2/2]

void dRes_c::copyRes ( const void *  from,
void *  to,
int  size,
int  compressionType 
)
static

Copies an optionally compressed resource.

Definition at line 134 of file d_res.cpp.

Member Data Documentation

◆ mpArcInfos

info_c* dRes_c::mpArcInfos
private

An array of archive holders.

Definition at line 219 of file d_res.hpp.

◆ mNumArcs

u16 dRes_c::mNumArcs
private

The number of archive holders.

Definition at line 220 of file d_res.hpp.

◆ mpCallback

callback_c* dRes_c::mpCallback
private

The callback for when a resource is loaded.

Definition at line 221 of file d_res.hpp.

◆ mSetCallback

void(* dRes_c::mSetCallback)(const char *arcName, EGG::Heap *heap)
staticprivate

[Unused]. The callback for when dRes_c::info_c::set is called.

Definition at line 224 of file d_res.hpp.