SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
StationedArchiveLoader.cpp
1#include "Game/System/StationedArchiveLoader.hpp"
2#include "Game/System/ResourceHolderManager.hpp"
3#include "Game/SingletonHolder.hpp"
4#include "Game/Util.hpp"
5
6StationedArchiveLoader::Condition::~Condition() {
7
8}
9
10JKRHeap* StationedArchiveLoader::Condition::getProperHeap(const MR::StationedFileInfo *pInfo) const {
11 return nullptr;
12}
13
14JKRHeap* StationedArchiveLoader::getProperHeap(const MR::StationedFileInfo *pInfo) {
15 switch (pInfo->mHeapType) {
16 case 0:
17 return (JKRHeap*)MR::getStationedHeapNapa();
18 break;
19 case 1:
20 return (JKRHeap*)MR::getStationedHeapGDDR3();
21 break;
22 }
23
24 return nullptr;
25}
26
27void StationedArchiveLoader::loadResourcesFromTable(const StationedArchiveLoader::Condition &rCondition) {
28 // grab the stationed file info table
29 const MR::StationedFileInfo* info = MR::getStationedFileInfoTable();
30
31 // while the current archive is not nullptr (the last entry in the list is a null entry)
32 while (info->mArchive != nullptr) {
33 // if the condition of the loader is to execute the loading of archives
34 if (rCondition.isExecute(info)) {
35 // grab the proper heap for loading the archive (0 = NAPA, 1 = GDDR)
36 JKRHeap* heap = rCondition.getProperHeap(info);
37
38 // if there is not a specific proper heap to use, we try the archive loader's specified heap
39 if (heap == nullptr) {
40 heap = StationedArchiveLoader::getProperHeap(info);
41 }
42
43 // load the file into memory based on the load type
44 switch (info->mLoadType) {
45 case 0:
46 MR::loadToMainRAM(info->mArchive, nullptr, heap, JKRDvdRipper::ALLOC_DIRECTION_1);
47 break;
48 case 1:
49 case 2:
50 case 3:
51 case 4:
52 case 5:
53 MR::mountArchive(info->mArchive, heap);
54 break;
55 }
56 }
57
58 // increment to next entry
59 info++;
60 }
61}
62
63void StationedArchiveLoader::createAndAddResourcesFromTable(const StationedArchiveLoader::Condition &rCondition) {
64 const MR::StationedFileInfo* info = MR::getStationedFileInfoTable();
65
66 while (info->mArchive != nullptr) {
67 if (rCondition.isExecute(info)) {
68 switch (info->mLoadType) {
69 case 2:
70 SingletonHolder<ResourceHolderManager>::sInstance->createAndAddStationed(info->mArchive);
71 break;
72 case 5:
73 SingletonHolder<ResourceHolderManager>::sInstance->createAndAddLayoutHolderStationed(info->mArchive);
74 break;
75 }
76 }
77
78 info++;
79 }
80}
81
82void StationedArchiveLoader::loadScenarioData(JKRHeap* pHeap) {
83 DVDDir dir;
84 DVDDirEntry entry;
85 DVDOpenDir("/StageData", &dir);
86
87 while (DVDReadDir(&dir, &entry) != 0) {
88 if (entry.isDir == false) {
89 continue;
90 }
91
92 char name[0x100];
93 MR::makeScenarioArchiveFileName(name, 0x100, entry.name);
94
95 if (MR::isFileExist(name, false)) {
96 MR::mountArchive(name, pHeap);
97 }
98 }
99
100 DVDCloseDir(&dir);
101}