SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
StageFileLoader.cpp
1#include "Game/Scene/StageFileLoader.hpp"
2#include "Game/System/GalaxyStatusAccessor.hpp"
3#include "Game/Util.hpp"
4#include "JSystem/JKernel/JKRArchive.hpp"
5#include "JSystem/JKernel/JKRFileFinder.hpp"
6#include <cstring>
7#include <cstdio>
8
9StageFileLoader::StageFileLoader(const char *pName) {
10 mZoneCount = 0;
11 makeStageArchiveNameList();
12}
13
14void StageFileLoader::startLoadingStageFile() {
15 for (int i = 0; i < mZoneCount; i++) {
16 MR::mountAsyncArchive(mStageFiles[i], MR::getAproposHeapForSceneArchive(0.029999999f));
17 }
18}
19
20void StageFileLoader::waitLoadedStageFile() {
21 for (int i = 0; i < mZoneCount; i++) {
22 const char* file = mStageFiles[i];
23 MR::receiveFile(file);
24 mountFilesInStageMapFile(file);
25 }
26}
27
28void StageFileLoader::makeStageArchiveNameList() {
29 GalaxyStatusAccessor access = MR::makeCurrentGalaxyStatusAccessor();
30 mZoneCount = access.getZoneNum();
31
32 for (int i = 0; i < mZoneCount; i++) {
33 const char* zoneName = access.getZoneName(i);
34 char path[0x100];
35 snprintf(path, 0x100, "/StageData/%s.arc", zoneName);
36 u32 len = strlen(path) + 1;
37 mStageFiles[i] = new char[len];
38 MR::copyString(mStageFiles[i], path, len);
39 }
40}
41
42void StageFileLoader::makeStageArchiveName(char *buf, u32 len, const char *pZoneName) {
43 snprintf(buf, len, "/StageData/%s.arc", pZoneName);
44}
45
46void StageFileLoader::mountFilesInStageMapFile(const char *pName) {
47 JKRArchive* archive = 0;
48 JKRHeap* heap = 0;
49 MR::getMountedArchiveAndHeap(pName, &archive, &heap);
50 void* res;
51 const char* curName;
52 s32 fileCount = archive->countFile("/arc") - 2;
53
54 if (fileCount > 0) {
55 JKRArcFinder* firstFile = archive->getFirstFile("/arc");
56
57 for (int i = 0; i < fileCount;) {
58 if (!MR::isMountedArchive(firstFile->mName)) {
59 curName = firstFile->mName;
60 res = archive->getResource(QUESTIONMARK_MAGIC, curName);
61 MR::createAndAddArchive(res, heap, curName);
62 }
63
64 i++;
65 firstFile->findNextFile();
66 }
67
68 delete firstFile;
69 }
70}