1#include "Game/System/FileLoader.hpp"
2#include "Game/Util.hpp"
3#include "Game/SingletonHolder.hpp"
9 extern const char* getCurrentLanguagePrefix();
11 bool isFileExist(
const char *pFile,
bool considerLanguage) {
14 if (considerLanguage) {
15 entryNum = MR::convertPathToEntrynumConsideringLanguage(pFile);
18 entryNum = DVDConvertPathToEntrynum(pFile);
24 u32 getFileSize(
const char *pFile,
bool considerLanguage) {
27 if (considerLanguage) {
28 entryNum = MR::convertPathToEntrynumConsideringLanguage(pFile);
31 entryNum = DVDConvertPathToEntrynum(pFile);
35 DVDFastOpen(entryNum, &fileInfo);
36 u32 size = fileInfo.length;
42 s32 convertPathToEntrynumConsideringLanguage(
const char *pFile) {
43 const char* langPrefix = getCurrentLanguagePrefix();
46 MR::addFilePrefix(buf, 0x100, pFile, langPrefix);
48 if (!isFileExist(buf,
false)) {
49 snprintf(buf, 0x100,
"%s", pFile);
52 return DVDConvertPathToEntrynum(buf);
55 void* loadToMainRAM(
const char *pFile, u8 *pData, JKRHeap *pHeap, JKRDvdRipper::EAllocDirection allocDir) {
56 MR::loadAsyncToMainRAM(pFile, pData, pHeap, allocDir);
57 return MR::receiveFile(pFile);
60 void loadAsyncToMainRAM(
const char *pFile, u8 *pData, JKRHeap *pHeap, JKRDvdRipper::EAllocDirection allocDir) {
61 const char* langPrefix = getCurrentLanguagePrefix();
64 MR::addFilePrefix(buf, 0x100, pFile, langPrefix);
66 if (!isFileExist(buf,
false)) {
67 snprintf(buf, 0x100,
"%s", pFile);
73 void* mountArchive(
const char *pFile, JKRHeap *pHeap) {
74 MR::mountAsyncArchive(pFile, pHeap);
75 return MR::receiveArchive(pFile);
78 void mountAsyncArchive(
const char *pFile, JKRHeap *pHeap) {
79 const char* langPrefix = getCurrentLanguagePrefix();
82 MR::addFilePrefix(buf, 0x100, pFile, langPrefix);
84 if (!isFileExist(buf,
false)) {
85 snprintf(buf, 0x100,
"%s", pFile);
91 void mountAsyncArchiveByObjectOrLayoutName(
const char *pFile, JKRHeap *pHeap) {
98 heap = MR::getAproposHeapForSceneArchive(0.029999999f);
102 bool objArchiveName = MR::makeObjectArchiveFileNameFromPrefix(objArch, 0x100, pFile,
false);
105 bool layoutArchiveName = MR::makeLayoutArchiveFileNameFromPrefix(layArch, 0x100, pFile,
false);
107 if (objArchiveName) {
108 MR::mountAsyncArchive(objArch, heap);
110 else if (layoutArchiveName) {
111 MR::mountAsyncArchive(layArch, heap);
115 void* receiveFile(
const char *pFile) {
116 const char* langPrefix = getCurrentLanguagePrefix();
119 MR::addFilePrefix(buf, 0x100, pFile, langPrefix);
121 if (!isFileExist(buf,
false)) {
122 snprintf(buf, 0x100,
"%s", pFile);
128 void* receiveArchive(
const char *pFile) {
129 const char* langPrefix = getCurrentLanguagePrefix();
132 MR::addFilePrefix(buf, 0x100, pFile, langPrefix);
134 if (!isFileExist(buf,
false)) {
135 snprintf(buf, 0x100,
"%s", pFile);
141 void receiveAllRequestedFile() {
145 void* createAndAddArchive(
void *pData, JKRHeap *pHeap,
const char *pFile) {
149 void getMountedArchiveAndHeap(
const char *pFile, JKRArchive **pArchive, JKRHeap **pHeap) {
150 const char* langPrefix = getCurrentLanguagePrefix();
153 MR::addFilePrefix(buf, 0x100, pFile, langPrefix);
155 if (!isFileExist(buf,
false)) {
156 snprintf(buf, 0x100,
"%s", pFile);
162 void removeFileConsideringLanguage(
const char *pFile) {
163 const char* langPrefix = getCurrentLanguagePrefix();
166 MR::addFilePrefix(buf, 0x100, pFile, langPrefix);
168 if (!isFileExist(buf,
false)) {
169 snprintf(buf, 0x100,
"%s", pFile);
178 bool isLoadedFile(
const char *pFile) {
179 const char* langPrefix = getCurrentLanguagePrefix();
182 MR::addFilePrefix(buf, 0x100, pFile, langPrefix);
184 if (!isFileExist(buf,
false)) {
185 snprintf(buf, 0x100,
"%s", pFile);
191 bool isMountedArchive(
const char *pFile) {
192 const char* langPrefix = getCurrentLanguagePrefix();
195 MR::addFilePrefix(buf, 0x100, pFile, langPrefix);
197 if (!isFileExist(buf,
false)) {
198 snprintf(buf, 0x100,
"%s", pFile);
204 bool isLoadedObjectOrLayoutArchive(
const char *pFile) {
206 bool obj_arch = MR::makeObjectArchiveFileNameFromPrefix(objFile, 0x100, pFile,
false);
208 char archFile[0x100];
209 bool lay_arch = MR::makeLayoutArchiveFileNameFromPrefix(archFile, 0x100, pFile,
false);
212 return MR::isLoadedFile(objFile);
215 return MR::isLoadedFile(archFile);
219 void makeFileNameConsideringLanguage(
char *pName, u32 length,
const char *pFile) {
220 const char* langPrefix = getCurrentLanguagePrefix();
222 MR::addFilePrefix(pName, length, pFile, langPrefix);
224 if (!isFileExist(pName,
false)) {
225 snprintf(pName, length,
"%s", pFile);
229 bool makeObjectArchiveFileName(
char *pName, u32 length,
const char *pFile) {
230 snprintf(pName, length,
"/ObjectData/%s", pFile);
232 if (MR::isFileExist(pName,
true)) {
236 snprintf(pName, length,
"/MapPartsData/%s", pFile);
238 if (MR::isFileExist(pName,
false)) {
242 snprintf(pName, length,
"%s", pFile);
243 return MR::isFileExist(pName,
true);
246 bool makeObjectArchiveFileNameFromPrefix(
char *pName, u32 length,
const char *pFile,
bool ) {
248 snprintf(buf, 0x100,
"%s.arc", pFile);
249 return MR::makeObjectArchiveFileName(pName, length, buf);
252 bool makeLayoutArchiveFileName(
char *pName, u32 length,
const char *pFile) {
253 snprintf(pName, length,
"/Region/LayoutData/%s", pFile);
255 if (MR::isFileExist(pName,
false)) {
259 snprintf(pName, length,
"/LayoutData/%s", pFile);
261 if (MR::isFileExist(pName,
true)) {
265 snprintf(pName, length,
"%s", pFile);
266 return MR::isFileExist(pName,
false);
271 void makeScenarioArchiveFileName(
char *pName, u32 length,
const char *pFile) {
272 snprintf(pName, length,
"/StageData/%s/%sScenario.arc", pFile, pFile);