Created
November 12, 2020 20:30
-
-
Save leoetlino/85bc401d52c9fd05f37479cc082807eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename T> | |
T* ActorParamMgr::loadFile(ActorParam* param, ActorParam::ResourceType type, const char* dir_name_c, | |
const char* extension_c, const char* name_c, res::Handle* pack_handle, | |
void* x, u32 load_req_c) { | |
const sead::SafeString name = name_c; | |
const sead::SafeString extension = extension_c; | |
sead::FixedSafeString<128> path; | |
T* res = nullptr; | |
if (name != "Dummy" && !name.isEmpty()) { | |
auto* temp_handle = param->allocHandle(); | |
const sead::SafeString* actor_name; | |
path.format("%s/%s.b%s", dir_name_c, name_c, extension_c); | |
{ | |
res::SimpleLoadRequest req; | |
req._8 = true; | |
actor_name = ¶m->getActorName(); | |
req.mRequester = *actor_name; | |
req.mPath = path; | |
req._c = 2; | |
res = sead::DynamicCast<T>(temp_handle->load(path, &req)); | |
} | |
// If directly loading the resource has failed, try to load it from the actor pack. | |
if (!res) { | |
if (!pack_handle->isSuccess()) | |
loadActorPack(pack_handle, *actor_name, load_req_c); | |
res::LoadRequest req; | |
prepareLoadFromActorPack(&path, &req, x, dir_name_c, extension_c, name_c, pack_handle, | |
load_req_c, *actor_name); | |
res = sead::DynamicCast<T>(temp_handle->load(path, &req)); | |
if (!res) { | |
static_cast<void>(temp_handle->isSuccess()); | |
// Try again without the pack. | |
if (req.mPackHandle) { | |
req.mPackHandle = nullptr; | |
req._24 = false; | |
res = sead::DynamicCast<T>(temp_handle->load(path, &req)); | |
if (!res) | |
static_cast<void>(temp_handle->isSuccess()); | |
} | |
} | |
} | |
if (!res) | |
param->freeLastHandle(); | |
else if (type == ActorParam::ResourceType::EventFlow) | |
temp_handle->requestUnload2(); | |
} else { | |
path.format("%s/%s.b%s", dir_name_c, name_c, extension_c); | |
res = sead::DynamicCast<T>(mResHandles[s32(type)].getResource()); | |
} | |
if (res) { | |
if (type == ActorParam::ResourceType::EventFlow) | |
return res; | |
static_cast<ParamIO*>(res)->getPath().copy(path); | |
if (ActorParam::isValidType(type)) | |
param->setResource(type, res); | |
return res; | |
} | |
if (extension != "fevfl") | |
param->_a = 1; | |
// Fall back to using the dummy resource. | |
res = sead::DynamicCast<T>(mResHandles[s32(type)].getResource()); | |
sead::FixedSafeString<128> dummy_path; | |
dummy_path.format("%s/Dummy.b%s", dir_name_c, extension_c); | |
if (res) { | |
static_cast<ParamIO*>(res)->getPath().copy(dummy_path); | |
if (ActorParam::isValidType(type)) | |
param->setResource(type, res); | |
} | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment