Project/Resource: Implement ResourceSystem::removeCategory (#816)

This commit is contained in:
Narr the Reg 2026-01-24 05:21:31 -06:00 committed by GitHub
parent 60eef744a4
commit 5a72d499e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 86 additions and 20 deletions

View file

@ -295644,10 +295644,10 @@ Project/Resource/ResourceSystem.o:
- offset: 0xa7d4a0
size: 688
label: _ZN2al14ResourceSystem14removeCategoryERKN4sead14SafeStringBaseIcEE
status: NotDecompiled
status: NonMatchingMajor
- offset: 0xa7d750
size: 8
label: _ZN2al22cleanupResGraphicsFileERKN4sead14SafeStringBaseIcEEPNS_8ResourceE
label: _ZN2al22cleanupResGraphicsFileERN4sead14SafeStringBaseIcEEPNS_8ResourceE
status: Matching
- offset: 0xa7d758
size: 8
@ -295693,58 +295693,58 @@ Project/Resource/ResourceSystem.o:
- offset: 0xa7e484
size: 20
label: _ZN4sead10StrTreeMapILi156EPN2al8ResourceEE19ForEachConstContextIPFvRNS_14SafeStringBaseIcEES3_EE4callEPNS_11TreeMapNodeIS7_EE
status: NotDecompiled
status: Matching
lazy: true
- offset: 0xa7e498
size: 116
label: _ZN4sead11TreeMapImplINS_14SafeStringBaseIcEEE7forEachINS_9Delegate1INS_10StrTreeMapILi156EPN2al8ResourceEE19ForEachConstContextIPFvRS2_S9_EEEPNS_11TreeMapNodeIS2_EEEEEEvSI_RKT_
status: NotDecompiled
status: Matching
lazy: true
- offset: 0xa7e50c
size: 48
label: _ZN4sead9Delegate1INS_10StrTreeMapILi156EPN2al8ResourceEE19ForEachConstContextIPFvRNS_14SafeStringBaseIcEES4_EEEPNS_11TreeMapNodeIS8_EEE6invokeESF_
status: NotDecompiled
status: Matching
lazy: true
- offset: 0xa7e53c
size: 92
label: _ZNK4sead9Delegate1INS_10StrTreeMapILi156EPN2al8ResourceEE19ForEachConstContextIPFvRNS_14SafeStringBaseIcEES4_EEEPNS_11TreeMapNodeIS8_EEE5cloneEPNS_4HeapE
status: NotDecompiled
status: Matching
lazy: true
- offset: 0xa7e598
size: 380
label: ''
status: NotDecompiled
label: _ZN2al13ResourceAudio29disableSoundMemoryPoolHandlerEPN4sead11TreeMapNodeINS1_14SafeStringBaseIcEEEE
status: Matching
- offset: 0xa7e714
size: 116
label: ''
status: NotDecompiled
label: _ZN4sead11TreeMapImplINS_14SafeStringBaseIcEEE7forEachINS_9Delegate1IN2al13ResourceAudioEPNS_11TreeMapNodeIS2_EEEEEEvSA_RKT_
status: Matching
- offset: 0xa7e788
size: 48
label: ''
status: NotDecompiled
label: _ZN4sead9Delegate1IN2al13ResourceAudioEPNS_11TreeMapNodeINS_14SafeStringBaseIcEEEEE6invokeES7_
status: Matching
- offset: 0xa7e7b8
size: 92
label: ''
status: NotDecompiled
label: _ZNK4sead9Delegate1IN2al13ResourceAudioEPNS_11TreeMapNodeINS_14SafeStringBaseIcEEEEE5cloneEPNS_4HeapE
status: NonMatchingMajor
- offset: 0xa7e814
size: 16
label: _ZN4sead10StrTreeMapILi156EPN2al8ResourceEE18eraseNodeForClear_EPNS_11TreeMapNodeINS_14SafeStringBaseIcEEEE
status: NotDecompiled
status: Matching
lazy: true
- offset: 0xa7e824
size: 116
label: _ZN4sead11TreeMapImplINS_14SafeStringBaseIcEEE7forEachINS_9Delegate1INS_10StrTreeMapILi156EPN2al8ResourceEEEPNS_11TreeMapNodeIS2_EEEEEEvSD_RKT_
status: NotDecompiled
status: Matching
lazy: true
- offset: 0xa7e898
size: 48
label: _ZN4sead9Delegate1INS_10StrTreeMapILi156EPN2al8ResourceEEEPNS_11TreeMapNodeINS_14SafeStringBaseIcEEEEE6invokeESA_
status: NotDecompiled
status: Matching
lazy: true
- offset: 0xa7e8c8
size: 92
label: _ZNK4sead9Delegate1INS_10StrTreeMapILi156EPN2al8ResourceEEEPNS_11TreeMapNodeINS_14SafeStringBaseIcEEEEE5cloneEPNS_4HeapE
status: NotDecompiled
status: Matching
lazy: true
- offset: 0xa7e924
size: 4

View file

@ -3,6 +3,7 @@
#include <container/seadStrTreeMap.h>
#include <heap/seadHeapMgr.h>
#include "Library/Audio/System/AudioKeeperFunction.h"
#include "Library/Base/Macros.h"
#include "Library/Base/StringUtil.h"
#include "Library/File/FileUtil.h"
@ -156,11 +157,60 @@ Resource* ResourceSystem::createResource(const sead::SafeString& name, ResourceC
return resource->getFileArchive() ? resource : nullptr;
}
void cleanupResGraphicsFile(const sead::SafeString& key, Resource* resource) {
void cleanupResGraphicsFile(sead::SafeString& key, Resource* resource) {
resource->cleanupResGraphicsFile();
}
// void ResourceSystem::removeCategory(const sead::SafeString& name) {}
class ResourceAudio {
public:
ResourceAudio(ResourceSystem::ResourceAudioInfo* info) : audioPlayerInfo(info) {}
void disableSoundMemoryPoolHandler(sead::TreeMapImpl<sead::SafeString>::Node* node) {
ResourceSystem::ResourceAudioInfo* info = audioPlayerInfo;
if (node->key().comparen(info->filePath, info->filePath.calcLength()) != 0)
return;
SeadAudioPlayer* audioPlayer =
alAudioSystemFunction::tryFindAudioPlayerRegistedSoundMemoryPoolHandler(
node->key().cstr(), info->audioPlayerA, info->audioPlayerB);
if (audioPlayer) {
while (!alAudioSystemFunction::tryDisableSoundMemoryPoolHandlerByFilePath(
node->key().cstr(), audioPlayer)) {
}
}
}
private:
ResourceSystem::ResourceAudioInfo* audioPlayerInfo;
};
// NON_MATCHING: https://decomp.me/scratch/R5MuA
void ResourceSystem::removeCategory(const sead::SafeString& name) {
ResourceAudioInfo audioPlayerInfo(mAudioPlayerA, mAudioPlayerB, "SoundData/");
sead::RingBuffer<ResourceCategory*>::iterator iter = findResourceCategoryIter(name);
if (iter == mCategories.end())
return;
(*iter)->treeMap.forEach(&cleanupResGraphicsFile);
// TODO: Find the correct implementation for this part
ResourceCategory* category = *iter;
{
ResourceAudio ctx(&audioPlayerInfo);
using MapImpl = sead::TreeMapImpl<sead::SafeString>;
sead::Delegate1<ResourceAudio, MapImpl::Node*> delegate(
&ctx, &ResourceAudio::disableSoundMemoryPoolHandler);
category->treeMap.MapImpl::forEach(delegate);
}
(*iter)->treeMap.clear();
mCategories.remove(iter.getIndex());
}
Resource* ResourceSystem::findResource(const sead::SafeString& categoryName) {
return findResourceCore(categoryName, nullptr);

View file

@ -28,6 +28,20 @@ public:
static_assert(sizeof(ResourceCategory) == 0xc0);
struct ResourceAudioInfo {
ResourceAudioInfo(SeadAudioPlayer* playerA, SeadAudioPlayer* playerB, const char* path)
: audioPlayerA(playerA), audioPlayerB(playerB) {
filePath.format(path);
}
// TODO: proper names for these two
SeadAudioPlayer* audioPlayerA;
SeadAudioPlayer* audioPlayerB;
sead::FixedSafeString<0x40> filePath;
};
static_assert(sizeof(ResourceAudioInfo) == 0x68);
ResourceSystem(const char* name);
ResourceCategory* addCategory(const sead::SafeString& name, s32 id, sead::Heap* heap);

View file

@ -320,6 +320,8 @@ def common_const_reference(c, path):
continue
if "calcBendPosAndFront" in line:
continue
if "cleanupResGraphicsFile" in line:
continue
if "sead::IDelegate1<CollisionParts*>" in line:
continue
if "sead::IDelegate1<al::CollisionParts*>" in line: