Resource::IResourceManager class

IResourceManager is a singleton class used to access resources in Spore's file system.

The main function of the ResourceManager is to access to the resources stored in Spore's files. The manager contains multiple IResourceFactory instances, which are assigned to certain typeIDs. When trying to get a resource, those factories will be used to generate an instance of the correct class according to the resource type. Therefore, the ResourceManager can only be used for those types that have factories assigned to them.

You can assign your own factories or delete existing ones, but if that is not an option, ResourceManager provides a method to find the DatabasePackedFile that contains a certain file. This way, ResourceManager can always be used to get files, either via the GetResource method or the GetDBPF one. The DBPFs are stored in the resource manager according to their priority.

The manager contains a cache of IResourceMap instances that is used to avoid repeteadly creating new instances of a resource that already exists. The ReadResource method can be used instead of GetResource to forcibly create a new resource even if it's already in the cache.

This manager provides additional functionality relating files. It keeps a map of ResourceKey - string16 values, which can be used to store the original name of certain resources. For example:

ResourceManager.SetFileName(ResourceKey(0x00000000, 0x40212002, 0x0469A3F7), u"ShaderFragments!LowQuality.graphics");
// Now you can access this file using the name we assigned instead of the original name, which had special IDs
ResourceManager.GetFileName(dstKey, u"ShaderFragments!LowQuality.graphics");

Additionally, the manager also keeps a map of typeID - string16 values, which allows to map extension strings to certain typeIDs. For example:

// for example, we could have the mappings on a file and load it on startup
ResourceManager.AddExtensionMapping(0x2F7D0004, u"png");
// now, if we try to use the .png extension, we will receive the correct typeID, instead of using the FNV hash of "png" (which is not 0x2F7D0004)
ResourceManager.GetFileName(dstKey, u"MyImages!EditorUIFrame.png");

Base classes

class IResourceContainer

Derived classes

class cResourceManager
The implementation of IResourceManager; this should only be used for extending and detouring.

Public types

using DBPFList = list<DatabasePackedFile*, CoreAllocatorAdapter<ICoreAllocator>>

Public static functions

static auto Get() -> IResourceManager*
Gets the active resource manager.

Public functions

auto GetResource(const ResourceKey& name, ResourceObjectPtr* ppDst = nullptr, int arg_8 = 0, DBPF* pDBPF = nullptr, IResourceFactory* pFactory = nullptr, const ResourceKey* pCacheName = nullptr) -> bool pure virtual
Gets the resource that has the given ResourceKey name.
auto GetAsyncResource(const ResourceKey& name, ResourceObjectPtr* ppDst = nullptr, AsyncResourcePtr* ppDstAsync = nullptr, void* arg_C = nullptr, void* arg_10 = nullptr, DBPF* pDBPF = nullptr, IResourceFactory* pFactory = nullptr, const ResourceKey* pAlternativeName = nullptr) -> bool pure virtual
Similar usage to ResourceManager::GetResource .
auto GetCachedResource(const ResourceKey& name, ResourceObjectPtr* pDst) -> bool pure virtual
Gets a resource from the resource cache in this manager.
auto func18h(int arg_0, int arg_4, int arg_8, int arg_C, int arg_10) -> bool pure virtual
auto ReadResource(const ResourceKey& name, ResourceObjectPtr* ppDst = nullptr, int arg_8 = 0, DBPF* pDBPF = nullptr, IResourceFactory* pFactory = nullptr, const ResourceKey* pCacheName = nullptr) -> bool pure virtual
Similar usage to ResourceManager::GetResource .
auto WriteResource(const ResourceObject* pResource, int arg_4 = 0, DBPF* pDBPF = nullptr, IResourceFactory* pFactory = nullptr, const ResourceKey* pNameKey = nullptr) -> bool pure virtual
Writes the given resource to a package file.
void SetTypeRemap(uint32_t nTypeID, uint32_t* pnTypes, size_t nCount) pure virtual
Maps all the alternative typeIDs in pnTypes (which has nCount values) to nTypeID.
auto GetTypeRemap(vector<uint32_t>& dst, uint32_t nTypeID) const -> size_t pure virtual
Gets all the alternative typeIDs mapped to nTypeID.
auto GetGeneralTypeID(uint32_t nSubtypeID) const -> uint32_t pure virtual
Gets the typeID that nSubtypeId is assigned to.
auto GetRealFileKey(const ResourceKey& nameKey, ResourceKey* pDst = nullptr, DBPF* pDBPF = nullptr) const -> DBPF* pure virtual
Used to get the real name of a file ResourceKey, using the correct type according to the mappings in this manager.
auto func34h(vector<ResourceKey>& pDst, int arg_4) -> size_t pure virtual
auto GetFileKeys(vector<ResourceKey>& dst, IResourceFilter* request, vector<DBPF*>* pDstDBPFs = nullptr) const -> size_t pure virtual
Gets all the file keys in this manager that match the criteria specified by the given request.
auto func3Ch(int, int, int) -> int pure virtual
auto func40h(int, int, int, int, int) -> bool pure virtual
auto SetResourceFactory(bool add, IResourceFactory* pFactory, uint32_t arg_8) -> bool pure virtual
Adds or removes the given IResourceFactory to this manager.
auto GetResourceFactory(uint32_t typeID, uint32_t subTypeID = ResourceKey::kWildcardID) const -> IResourceFactory* pure virtual
Returns the IResourceFactory that belongs to the specified typeID.
auto GetResourceFactories(list<IResourceFactory*>& dst, uint32_t typeID = ResourceKey::kWildcardID) const -> size_t pure virtual
Puts all the IResourceFactory instances that are assigned to the specified typeID into the given list.
auto AddDBPF(bool, DatabasePackedFile* pDBPF, int nPriority) -> bool pure virtual
Adds the given DatabasePackedFile to this manager, using the priority specified.
auto GetPriority(DatabasePackedFile* pDBPF, int* pDst = nullptr) const -> bool pure virtual
Gets the priority of the given DatabasePackedFile if it is contained in this ResourceManager.
auto GetDBPF(const ResourceKey& name) const -> DatabasePackedFile* pure virtual
Returns the first DatabasePackedFile that contains the given.
auto GetAllDBPFs(DBPFList& dst, const ResourceKey* pFileKey = nullptr) -> size_t pure virtual
Gets all the DatabasePackedFile objects in this manager and puts it to the dst list.
auto func60h(int, int) -> int pure virtual
auto func64h(int, int, int) -> bool pure virtual
auto GetResourceCache(ResourceKey& name) const -> IResourceMap* pure virtual
Returns the IResourceMap cache that contains a resource with this name (if any).
auto func6Ch(int, int) -> bool pure virtual
void func70h(IResourceMap*, SpecialResourceObject*) pure virtual
auto GetResourceCaches(list<IResourceMap*>& dst) const -> size_t pure virtual
Puts all the resource caches used in this manager into the given list.
auto AddFileName(const char16_t* pFileName) -> bool pure virtual
Adds this file name to the list, so that it can be accessed using the corresponding ResourceKey.
void GetFileName(const ResourceKey& resourceKey, string16& dst) const pure virtual
Gets the file name that corresponds to the specified ResourceKey.
auto SetFileName(const ResourceKey& resourceKey, const char16_t* pFileName) -> bool pure virtual
Maps the given ResourceKey to the file name specified, which is in the format "groupID!instanceID.typeID".
auto RemoveFileName(const ResourceKey& resourceKey) -> bool pure virtual
Removes the file name mapped for the given ResourceKey.
auto GetTypeID(const char16_t* pExtension) const -> uint32_t pure virtual
Returns the typeID that has the given extension mapped to it, or (uint32_t)-1 (so 0xFFFFFFFF) if no typeID has this extension mapped.
auto GetExtension(uint32_t typeID) const -> char16_t* pure virtual
Returns the extension that is mapped to the given type ID, or nullptr if there's no mapping.
auto AddExtensionMapping(uint32_t typeID, const char16_t* pExtension) -> bool pure virtual
Maps the given typeID (as a uint32_t hash) to the specified extension string.
auto RemoveExtensionMapping(uint32_t typeID) -> bool pure virtual
Removes the given typeID (as a uint32_t hash) and the extension it is mapped to.

Function documentation

bool Resource::IResourceManager::GetResource(const ResourceKey& name, ResourceObjectPtr* ppDst = nullptr, int arg_8 = 0, DBPF* pDBPF = nullptr, IResourceFactory* pFactory = nullptr, const ResourceKey* pCacheName = nullptr) pure virtual

Gets the resource that has the given ResourceKey name.

Parameters
name in The ResourceKey name to find. If the typeID is mapped in the manager to other alternative typeIDs, all them will be tested.
ppDst out [Optional] A pointer to a ResourceObject*. It will be assigned with the generated resource.
arg_8 [Optional] Usage unknown, usually 0.
pDBPF in [Optional] The DatabasePackedFile where the file will be searched. Use nullptr to search in all DBPFs in this manager.
pFactory in [Optional] The IResourceFactory used to generate the resource. Use nullptr to use the appropiate factory according to the typeID mapping in this manager.
pCacheName in [Optional] The ResourceKey name used to search the resource in the cache.
Returns True if the resource was found or generated, false otherwise.

If the resource is contained in the cache, that will be used. The name will be modified to use the correct types, according to the mappings in this manager. The resource will be seached in all the DBPF files in this manager, unless a specific one is specified. Once the file is found, the correct factory will be used to generate the appropiate resource, unless a specific IResourceFactory is specified.

bool Resource::IResourceManager::GetAsyncResource(const ResourceKey& name, ResourceObjectPtr* ppDst = nullptr, AsyncResourcePtr* ppDstAsync = nullptr, void* arg_C = nullptr, void* arg_10 = nullptr, DBPF* pDBPF = nullptr, IResourceFactory* pFactory = nullptr, const ResourceKey* pAlternativeName = nullptr) pure virtual

Similar usage to ResourceManager::GetResource .

This method allows to get more info, but it is unknown what that info is.

bool Resource::IResourceManager::GetCachedResource(const ResourceKey& name, ResourceObjectPtr* pDst) pure virtual

Gets a resource from the resource cache in this manager.

Returns True if the file was present in the cache, false otherwise.

If it isn't present in the cache, nothing will happen.

bool Resource::IResourceManager::ReadResource(const ResourceKey& name, ResourceObjectPtr* ppDst = nullptr, int arg_8 = 0, DBPF* pDBPF = nullptr, IResourceFactory* pFactory = nullptr, const ResourceKey* pCacheName = nullptr) pure virtual

Similar usage to ResourceManager::GetResource .

Returns True if the resource was successfully generated and read, false otherwise.

This method does not check the cache, however, therefore always generating a new resource.

bool Resource::IResourceManager::WriteResource(const ResourceObject* pResource, int arg_4 = 0, DBPF* pDBPF = nullptr, IResourceFactory* pFactory = nullptr, const ResourceKey* pNameKey = nullptr) pure virtual

Writes the given resource to a package file.

Parameters
pResource
arg_4 [Optional] Usage unknown, usually 0.
pDBPF
pFactory
pNameKey
Returns True if the resource was successfuly written, false otherwise.

If the DBPF is specified in this method, a new file will always be created on it even if it does not exist yet; however, if no DBPF is specified, the resource will be written in the first DBPF that contains a file with the given name. If there is a problem while writing the resource, the file on the DBPF will be deleted.

size_t Resource::IResourceManager::GetTypeRemap(vector<uint32_t>& dst, uint32_t nTypeID) const pure virtual

Gets all the alternative typeIDs mapped to nTypeID.

Returns The number of alternative typeIDs mapped.

DBPF* Resource::IResourceManager::GetRealFileKey(const ResourceKey& nameKey, ResourceKey* pDst = nullptr, DBPF* pDBPF = nullptr) const pure virtual

Used to get the real name of a file ResourceKey, using the correct type according to the mappings in this manager.

Parameters
nameKey in The original ResourceKey of the file.
pDst out [Optional] The ResourceKey where the real key of the file will be put, with the correct typeID.
pDBPF in [Optional] The DatabasePackedFile where the file will be searched. If not specified, it will be searched in all the DBPFs in this manager.
Returns The DatabasePackedFile that contains this file.

size_t Resource::IResourceManager::GetFileKeys(vector<ResourceKey>& dst, IResourceFilter* request, vector<DBPF*>* pDstDBPFs = nullptr) const pure virtual

Gets all the file keys in this manager that match the criteria specified by the given request.

Parameters
dst out The vector where all the files ResourceKey names will be added.
request in The criteria that the files must match in order to be added to the vector.
pDstDBPFs out [Optional] A vector where all the DatabasePackedFile objects that contained the files will be added.
Returns The number of file keys that matched the criteria.

If request is nullptr, all the files in the manager will be added.

bool Resource::IResourceManager::SetResourceFactory(bool add, IResourceFactory* pFactory, uint32_t arg_8) pure virtual

Adds or removes the given IResourceFactory to this manager.

Parameters
add If true, pFactory will be added to the manager; if false, it will be removed from the manager.
pFactory The IResourceFactory to add to/remove from this manager.
arg_8 Unknown usage, usually 0.
Returns True if the factory was successfully added/removed, false otherwise.

Resource factories are used to generate resource objects depending on their type. The factory will be assigned to the types returned by IResourceFactory::GetSupportedTypes.

IResourceFactory* Resource::IResourceManager::GetResourceFactory(uint32_t typeID, uint32_t subTypeID = ResourceKey::kWildcardID) const pure virtual

Returns the IResourceFactory that belongs to the specified typeID.

If subTypeID is ResourceKey::kWildcardID, the first factory assigned to the typeID will be returned; Otherwise, IResourceFactory::IsValid() will be called on every factory using the types provided here, and the first one that returns true will be returned.

size_t Resource::IResourceManager::GetResourceFactories(list<IResourceFactory*>& dst, uint32_t typeID = ResourceKey::kWildcardID) const pure virtual

Puts all the IResourceFactory instances that are assigned to the specified typeID into the given list.

Returns The number of factories found.

If typeID is ResourceKey::kWildcardID, all the factories in this manager will be added.

bool Resource::IResourceManager::AddDBPF(bool, DatabasePackedFile* pDBPF, int nPriority) pure virtual

Adds the given DatabasePackedFile to this manager, using the priority specified.

The priority of a DBPF is used when getting files from the resource manager; since a certain file name can be contained in multiple packages, the one with the most priority will be chosen. The usage of the first argument is unknown, but it is usually 'true'.

bool Resource::IResourceManager::GetPriority(DatabasePackedFile* pDBPF, int* pDst = nullptr) const pure virtual

Gets the priority of the given DatabasePackedFile if it is contained in this ResourceManager.

Parameters
pDBPF in The DatabasePackedFile from which the priority will be got.
pDst
Returns True if the manager contained the DBPF, false otherwise.

This method can also be used to check if a DBPF is added or not in this list.

size_t Resource::IResourceManager::GetAllDBPFs(DBPFList& dst, const ResourceKey* pFileKey = nullptr) pure virtual

Gets all the DatabasePackedFile objects in this manager and puts it to the dst list.

Parameters
dst out A list of DBPF pointers that uses CoreAllocatorAdapter<ICoreAllocator> where the DBPFs will be added.
pFileKey in [Optional] A ResourceKey that the DBPFs must contain, or nullptr if no filtering is wanted.
Returns The number of DBPFs added to the list.

Optionally, a ResourceKey can be specified; in that case, only the DBPFs that contain that file will be added.

size_t Resource::IResourceManager::GetResourceCaches(list<IResourceMap*>& dst) const pure virtual

Puts all the resource caches used in this manager into the given list.

Returns the number of caches added.

bool Resource::IResourceManager::AddFileName(const char16_t* pFileName) pure virtual

Adds this file name to the list, so that it can be accessed using the corresponding ResourceKey.

Returns True if the file name was mapped successfully, false otherwise.

The file name is in the format "groupID!instanceID.typeID", and it will be mapped to the key generated using the ResourceKey::Parse function.

void Resource::IResourceManager::GetFileName(const ResourceKey& resourceKey, string16& dst) const pure virtual

Gets the file name that corresponds to the specified ResourceKey.

Parameters
resourceKey in The ResourceKey that will be represented as a string.
dst out A string16 that will contain the resulting text.

The file name will be in the format "groupID!instanceID.typeID". The file name can be parsed to a key again using the ResourceKey::Parse method. A file name wil be generated even if it's not mapped; when that happens, the ResourceKey members are displayed in hexadecimal format.

bool Resource::IResourceManager::SetFileName(const ResourceKey& resourceKey, const char16_t* pFileName) pure virtual

Maps the given ResourceKey to the file name specified, which is in the format "groupID!instanceID.typeID".

Returns True if it was successfully mapped.

The file name can be parsed to a key again using the ResourceKey::Parse method.

bool Resource::IResourceManager::RemoveFileName(const ResourceKey& resourceKey) pure virtual

Removes the file name mapped for the given ResourceKey.

Returns True if the file name mapping was removed, false if it did not exist.

The file name can be parsed to a key again using the ResourceKey::Parse method.

bool Resource::IResourceManager::AddExtensionMapping(uint32_t typeID, const char16_t* pExtension) pure virtual

Maps the given typeID (as a uint32_t hash) to the specified extension string.

Returns True if the extension was successfully mapped or already existed, false if the typeID was mapped to a different extension.

bool Resource::IResourceManager::RemoveExtensionMapping(uint32_t typeID) pure virtual

Removes the given typeID (as a uint32_t hash) and the extension it is mapped to.

Returns True if the extension existed and was removed, false otherwise.