From 7f8b4c8a4fb817911b19f536312bfb7ed546a019 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Mon, 28 Sep 2026 23:57:01 -0500 Subject: [PATCH 01/18] wad: continue decompilation (worker snapshot f33bf397) (#252) --- libs/RVL_SDK/src/wad/wad.c | 582 ++++++++++++++++++++----------------- 1 file changed, 308 insertions(+), 274 deletions(-) diff --git a/libs/RVL_SDK/src/wad/wad.c b/libs/RVL_SDK/src/wad/wad.c index 0f2c89e1..43373a86 100644 --- a/libs/RVL_SDK/src/wad/wad.c +++ b/libs/RVL_SDK/src/wad/wad.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -236,7 +237,7 @@ static s32 _WADCheckContents(ESTmdView* titleMeta, ESContentMask* contentMask); static void _WADRandPad(void* buffer, u32 size); static s32 _WADVerifySavedataZD(WADSaveDataHeader* header, WADStream* stream, MEMAllocator* allocator, u32 offset); -static void _WADCleanTmpDir(MEMAllocator* allocator); +static s32 _WADCleanTmpDir(MEMAllocator* allocator); u32 _WADIsTerminated(const char* text, u32 maxLength); extern s32 ES_GetBoot2Version(u32* version); @@ -1173,22 +1174,15 @@ cleanup: } static s32 WAD_815C1288(WADExportLoopArgs* args) { - s32 result; - u32 remaining; - u32 bufferIndex; - ESFd fd; - WADImportTransfer* transfer; - u32 size; - OSMutex* mutex; - - fd = args->fd; - result = 0; - remaining = args->size; - bufferIndex = 0; - transfer = args->transfer; + ESFd fd = args->fd; + s32 result = 0; + u32 remaining = args->size; + u32 bufferIndex = 0; + WADImportTransfer* transfer = args->transfer; while ((remaining != 0) && (result == 0)) { - size = remaining; + u32 size = remaining; + OSMutex* mutex; if (remaining > transfer->chunkSize) { size = transfer->chunkSize; @@ -1317,10 +1311,16 @@ s32 WADBackupEx(u64 titleId, u32 ticketId, MEMAllocator* allocator, char* path, } if ((flags & 2) != 0) { char currentDirectory[NAND_MAX_PATH] ALIGN32; + u32 currentTitleHigh = 0; + u32 currentTitleLow = 0; result = NANDGetCurrentDir(currentDirectory); if (result != 0) { goto cleanup; } + if (strncmp(currentDirectory, "/title/", 7) == 0) { + sscanf(currentDirectory, "/title/%x/%x", ¤tTitleHigh, ¤tTitleLow); + headerBlock.header.titleId = ((u64)currentTitleHigh << 32) | currentTitleLow; + } result = _WADBackupGetFiles(0, flags, allocator, &fileCount, 0); if (result != 0) { goto cleanup; @@ -1374,7 +1374,6 @@ s32 WADBackupEx(u64 titleId, u32 ticketId, MEMAllocator* allocator, char* path, headerBlock.header.tmdSize = titleMetaSize; headerBlock.header.contentSize = contentDataSize; headerBlock.header.backupAreaLen = titleMetaSize + contentDataSize + fileDataSize; - headerBlock.header.titleId = titleId; result = ES_GetDeviceId(&headerBlock.header.deviceId); if (result != 0) { goto cleanup; @@ -1734,6 +1733,58 @@ done: return result; } +#pragma dont_inline on +static void* _WADMemAlloc(MEMAllocator* allocator, u32 size) { + s32 allocationKind; + u32 heapType; + void* buffer = 0; + + if ((allocator != 0) && (allocator->heap != 0)) { + heapType = ((MEMiHeapHead*)allocator->heap)->magic; + switch (heapType) { + case 0x45585048: + allocationKind = 0; + break; + case 0x46524D48: + allocationKind = 1; + break; + case 0x554E5448: + allocationKind = 2; + break; + default: + allocationKind = 3; + break; + } + + switch (allocationKind) { + case 0: + buffer = MEMAllocFromExpHeapEx(allocator->heap, size, 0x40); + break; + case 1: + buffer = MEMAllocFromFrmHeapEx(allocator->heap, size, 0x40); + break; + case 2: + default: + buffer = MEMAllocFromAllocator(allocator, size); + if (((u32)buffer & 0x3F) != 0) { + OSReport("%s: Memory Allocator must return 64B aligned memBlocks\n", __func__); + MEMFreeToAllocator(allocator, buffer); + buffer = 0; + } + break; + } + } + return buffer; +} + +static void _WADMemFree(MEMAllocator* allocator, void* buffer) { + if ((allocator == 0) || (allocator->heap == 0) || (buffer == 0)) { + return; + } + MEMFreeToAllocator(allocator, buffer); +} +#pragma dont_inline reset + s32 _WADGetCidxCount(const ESContentMask* contentMask) { s32 count = 0; u32 bitIndex = 0; @@ -1835,8 +1886,9 @@ static s32 _WADCanImportFile(const WADFileHeader* fileHeader, u32 transferId, co static s32 _WADBackupGetFiles(const char* directoryPath, u32 flags, MEMAllocator* allocator, u32* fileCount, WADBackupFileHeader* files) { char currentDirectory[NAND_MAX_PATH] ALIGN32; - char fullDirectoryPath[NAND_MAX_PATH] ALIGN32; char fullFilePath[NAND_MAX_PATH] ALIGN32; + char noCopyPath[NAND_MAX_PATH] ALIGN32; + char bannerPath[NAND_MAX_PATH] ALIGN32; char* names = 0; char* nameList = 0; u32 nameCount = 0; @@ -1856,17 +1908,9 @@ static s32 _WADBackupGetFiles(const char* directoryPath, u32 flags, MEMAllocator return result; } if (directoryPath == 0) { - directoryPath = ""; + directoryPath = "."; } - if (directoryPath[0] == '\0') { - strncpy(fullDirectoryPath, currentDirectory, sizeof(fullDirectoryPath)); - } else if (directoryPath[0] == '/') { - strncpy(fullDirectoryPath, directoryPath, sizeof(fullDirectoryPath)); - } else { - snprintf(fullDirectoryPath, sizeof(fullDirectoryPath), "%s/%s", currentDirectory, - directoryPath); - } - result = NANDPrivateReadDir(fullDirectoryPath, 0, &nameCount); + result = NANDPrivateReadDir(directoryPath, 0, &nameCount); if (result == -1) { *fileCount = 0; return 0; @@ -1880,7 +1924,7 @@ static s32 _WADBackupGetFiles(const char* directoryPath, u32 flags, MEMAllocator return -3003; } names = nameList; - result = NANDPrivateReadDir(fullDirectoryPath, nameList, &nameCount); + result = NANDPrivateReadDir(directoryPath, nameList, &nameCount); if (result != 0) { goto cleanup; } @@ -1934,6 +1978,29 @@ static s32 _WADBackupGetFiles(const char* directoryPath, u32 flags, MEMAllocator if (result != 0) { break; } + if ((flags & 0x10) == 0) { + if ((flags & 4) == 0) { + if (strcmp(directoryPath, ".") == 0) { + snprintf(noCopyPath, sizeof(noCopyPath), "%s/%s", currentDirectory, + "nocopy"); + snprintf(bannerPath, sizeof(bannerPath), "%s/%s", currentDirectory, + "banner.bin"); + if ((strcmp(fullFilePath, noCopyPath) == 0) && (fileType == 2)) { + goto nextName; + } + if ((strcmp(fullFilePath, bannerPath) == 0) && (fileType == 1)) { + goto nextName; + } + } + } else { + if ((strcmp(fullFilePath, "nocopy") == 0) && (fileType == 2)) { + goto nextName; + } + if ((strcmp(fullFilePath, "banner.bin") == 0) && (fileType == 1)) { + goto nextName; + } + } + } if (files != 0) { file = &files[totalFiles]; file->magic = 0x3ADF17E; @@ -2022,57 +2089,6 @@ static s32 _WADBackupGetSize(u32 flags, ESTmdView* titleMeta, ESContentMask* con } #pragma dont_inline reset -#pragma dont_inline on -static void* _WADMemAlloc(MEMAllocator* allocator, u32 size) { - s32 allocationKind; - u32 heapType; - void* buffer = 0; - - if ((allocator != 0) && (allocator->heap != 0)) { - heapType = ((MEMiHeapHead*)allocator->heap)->magic; - switch (heapType) { - case 0x45585048: - allocationKind = 0; - break; - case 0x46524D48: - allocationKind = 1; - break; - case 0x554E5448: - allocationKind = 2; - break; - default: - allocationKind = 3; - break; - } - - switch (allocationKind) { - case 0: - buffer = MEMAllocFromExpHeapEx(allocator->heap, size, 0x40); - break; - case 1: - buffer = MEMAllocFromFrmHeapEx(allocator->heap, size, 0x40); - break; - case 2: - default: - buffer = MEMAllocFromAllocator(allocator, size); - if (((u32)buffer & 0x3F) != 0) { - OSReport("%s: Memory Allocator must return 64B aligned memBlocks\n", "_WADMemAlloc"); - MEMFreeToAllocator(allocator, buffer); - buffer = 0; - } - break; - } - } - return buffer; -} - -static void _WADMemFree(MEMAllocator* allocator, void* buffer) { - if ((allocator == 0) || (allocator->heap == 0) || (buffer == 0)) { - return; - } - MEMFreeToAllocator(allocator, buffer); -} -#pragma dont_inline reset static void _WADFreeMemory(WADUnpackInfo* info, MEMAllocator* allocator) { if ((info->size_0x18 != 0) && (info->buffer_0x14 != 0)) { @@ -2099,17 +2115,14 @@ static void _WADRandPad(void* buffer, u32 size) { u32 remainder = size & 3; u32 wordIndex; + if (size == 0) { + return; + } for (wordIndex = 0; wordIndex < wordCount; wordIndex++) { - u32 first = rand(); - u32 second = rand(); - u32 third = rand(); - words[wordIndex] = (third & 3) | (second << 17) | (first << 2); + words[wordIndex] = ((u32)rand() << 2) | ((u32)rand() << 17) | (rand() & 3); } if (remainder != 0) { - u32 first = rand(); - u32 second = rand(); - u32 third = rand(); - u32 randomWord = (third & 3) | (second << 17) | (first << 2); + u32 randomWord = ((u32)rand() << 2) | ((u32)rand() << 17) | (rand() & 3); u8* tail = (u8*)&words[wordCount]; u8* randomBytes = (u8*)&randomWord; u32 byteIndex; @@ -2136,34 +2149,62 @@ typedef union WADFileInfoView { s32 WADOpenStream(WADLocation location, const char* path, WADStream* stream, u32 write, u32 offset) { - s32 result; - stream->location = location; - if (location == WAD_LOCATION_SD_CARD) { - if (write == 0) { - stream->handle.fa = FAFopen(path, "r"); + + switch (location) { + case WAD_LOCATION_CNT_DVD: { + WADContentPath* contentPath = (WADContentPath*)path; + s32 result; + if (write != 0) { + result = -3004; } else { - stream->handle.fa = FAFopen(path, "r+"); - if (stream->handle.fa == 0) { - stream->handle.fa = FACreate(path, 0); - } - if (stream->handle.fa == 0) { - return -3004; - } - if ((offset != 0) && (WADSeekStream(stream, offset, 0) != offset)) { - return -3004; + result = contentOpenDVD(contentPath->handle, contentPath->name, + &stream->handle.contentDvd); + if (result != 0) { + result = -3004; } } - return stream->handle.fa == 0 ? -3004 : 0; + return result; } - if (location < WAD_LOCATION_SD_CARD) { - if (location == WAD_LOCATION_DVD) { - if (write != 0) { - return -3004; + + case WAD_LOCATION_CNT_NAND: { + WADContentPath* contentPath = (WADContentPath*)path; + s32 result; + if (write != 0) { + result = -3004; + } else { + result = contentOpenNAND(contentPath->handle, contentPath->name, + &stream->handle.contentNand); + if (result != 0) { + result = -3004; } - return DVDOpen(path, &stream->handle.dvd) ? 0 : -3004; } - if (location == WAD_LOCATION_NAND) { + return result; + } + + case (WADLocation)0: + if ((((u32)path + offset) & 0x3F) != 0) { + return -3007; + } + stream->handle.memoryBase = (void*)((u32)path + offset); + return 0; + + case WAD_LOCATION_DVD: + { + s32 result; + if (write != 0) { + result = -3004; + } else if (DVDOpen(path, &stream->handle.dvd)) { + result = 0; + } else { + result = -3004; + } + return result; + } + + case WAD_LOCATION_NAND: + { + s32 result; if (write == 0) { return NANDPrivateOpen(path, &stream->handle.nand, 1) == 0 ? 0 : -3004; } @@ -2184,7 +2225,7 @@ s32 WADOpenStream(WADLocation location, const char* path, WADStream* stream, u32 u32 fileSize; fileSize = NANDSeek(&stream->handle.nand, 0, 2); - if (offset <= fileSize) { + if (fileSize < offset) { return -3004; } memset(zeroes, 0, sizeof(zeroes)); @@ -2203,142 +2244,130 @@ s32 WADOpenStream(WADLocation location, const char* path, WADStream* stream, u32 } return result == offset ? 0 : -3004; } - if ((s32)location >= 0) { - if ((((u32)path + offset) & 0x3F) != 0) { - return -3007; + + case WAD_LOCATION_SD_CARD: { + if (write == 0) { + stream->handle.fa = FAFopen(path, "r"); + } else { + stream->handle.fa = FAFopen(path, "r+"); + if (stream->handle.fa == 0) { + stream->handle.fa = FACreate(path, 0); + } + if (stream->handle.fa == 0) { + return -3004; + } + if ((offset != 0) && (WADSeekStream(stream, offset, 0) != offset)) { + return -3004; } - stream->handle.memoryBase = (void*)((u32)path + offset); - return 0; } - } else if (location == WAD_LOCATION_CNT_NAND) { - WADContentPath* contentPath = (WADContentPath*)path; - if (write != 0) { - return -3004; - } - return contentOpenNAND(contentPath->handle, contentPath->name, - &stream->handle.contentNand) == 0 - ? 0 - : -3004; - } else if (location < WAD_LOCATION_CNT_NAND) { - WADContentPath* contentPath = (WADContentPath*)path; - if (write != 0) { - return -3004; - } - return contentOpenDVD(contentPath->handle, contentPath->name, - &stream->handle.contentDvd) == 0 - ? 0 - : -3004; + return stream->handle.fa == 0 ? -3004 : 0; + } + + default: + return -3000; } - return -3000; } size_t WADReadStream(WADStream* stream, void** buffer, size_t size, s32 offset) { size_t result; u32 alignedSize; - s32 location; if ((s32)size <= 0) { - result = 0; - } else if ((stream == 0) || (buffer == 0)) { - result = -3000; - } else { - alignedSize = (size + WAD_READ_ALIGNMENT - 1) & ~(WAD_READ_ALIGNMENT - 1); - if (size == alignedSize) { - location = stream->location; - if (location != WAD_LOCATION_SD_CARD) { - if (location < WAD_LOCATION_SD_CARD) { - if (location != WAD_LOCATION_DVD) { - if (location > 0) { - result = NANDSeek(&stream->handle.nand, offset, 0); - if ((s32)result < 0) { - return result; - } - return NANDRead(&stream->handle.nand, *buffer, alignedSize); - } - if (location >= 0) { - memcpy(*buffer, (u8*)stream->handle.memoryBase + offset, size); - return size; - } - } else { - return DVDReadPrio(&stream->handle.dvd, *buffer, alignedSize, offset, 2); - } - } else { - if (location != WAD_LOCATION_CNT_NAND) { - if (location < WAD_LOCATION_CNT_NAND) { - return contentReadDVD(&stream->handle.contentDvd, *buffer, alignedSize, - offset); - } - } else { - return contentReadNAND(&stream->handle.contentNand, *buffer, alignedSize, - offset); - } - } - result = -3000; - } else if (stream->handle.fa == 0) { - result = -3000; - } else { - result = FAFseek(stream->handle.fa, offset, 0); - if (result == 0) { - result = FAFread(*buffer, 1, size, stream->handle.fa); - } - } - } else { - result = -3000; - } + return 0; + } + if ((stream == 0) || (buffer == 0)) { + return -3000; + } + alignedSize = (size + WAD_READ_ALIGNMENT - 1) & ~(WAD_READ_ALIGNMENT - 1); + if (size != alignedSize) { + return -3000; + } + + switch (stream->location) { + case WAD_LOCATION_CNT_DVD: + return contentReadDVD(&stream->handle.contentDvd, *buffer, alignedSize, offset); + + case WAD_LOCATION_CNT_NAND: + return contentReadNAND(&stream->handle.contentNand, *buffer, alignedSize, offset); + + case (WADLocation)0: + memcpy(*buffer, (u8*)stream->handle.memoryBase + offset, size); + return size; + + case WAD_LOCATION_DVD: + return DVDReadPrio(&stream->handle.dvd, *buffer, alignedSize, offset, 2); + + case WAD_LOCATION_NAND: + result = NANDSeek(&stream->handle.nand, offset, 0); + if ((s32)result >= 0) { + result = NANDRead(&stream->handle.nand, *buffer, alignedSize); + } + return result; + + case WAD_LOCATION_SD_CARD: + if (stream->handle.fa == 0) { + return -3000; + } + result = FAFseek(stream->handle.fa, offset, 0); + if (result == 0) { + return FAFread(*buffer, 1, size, stream->handle.fa); + } + return result; + + default: + return -3000; } - return result; } void WADCloseStream(WADStream* stream) { if (stream == 0) { return; } - if (stream->location != WAD_LOCATION_SD_CARD) { - if (stream->location < WAD_LOCATION_SD_CARD) { - if (stream->location != WAD_LOCATION_DVD) { - if (stream->location < WAD_LOCATION_DVD) { - return; - } - NANDClose(&stream->handle.nand); - return; - } - DVDClose(&stream->handle.dvd); - return; - } - if (stream->location != WAD_LOCATION_CNT_NAND) { - if (stream->location > WAD_LOCATION_CNT_NAND) { - return; - } - contentCloseDVD(&stream->handle.contentDvd); - return; - } + switch (stream->location) { + case WAD_LOCATION_CNT_DVD: + contentCloseDVD(&stream->handle.contentDvd); + return; + case WAD_LOCATION_CNT_NAND: contentCloseNAND(&stream->handle.contentNand); return; - } - if (stream->handle.fa != 0) { - FAFclose(stream->handle.fa); + case WAD_LOCATION_DVD: + DVDClose(&stream->handle.dvd); + return; + case WAD_LOCATION_NAND: + NANDClose(&stream->handle.nand); + return; + case WAD_LOCATION_SD_CARD: + if (stream->handle.fa != 0) { + FAFclose(stream->handle.fa); + } + return; + default: + return; } } s32 WADWriteStream(WADStream* stream, void* buffer, u32 size) { + s32 result = size; + if ((stream == 0) || (buffer == 0)) { - return -3000; - } - if (stream->location == WAD_LOCATION_NAND) { - return NANDWrite(&stream->handle.nand, buffer, size); - } - if (stream->location == WAD_LOCATION_DVD - 1) { - memcpy(stream->handle.memoryBase, buffer, size); - return size; - } - if ((stream->location > WAD_LOCATION_NAND) && - (stream->location < WAD_LOCATION_CNT_DVD)) { - if (stream->handle.fa == 0) { - return -3000; + result = -3000; + } else if (stream->location != WAD_LOCATION_NAND) { + if (stream->location == (WADLocation)0) { + memcpy(stream->handle.memoryBase, buffer, size); + } else if ((stream->location > WAD_LOCATION_NAND) && + (stream->location < WAD_LOCATION_CNT_DVD)) { + if (stream->handle.fa == 0) { + result = -3000; + } else { + result = FAFwrite(buffer, 1, size, stream->handle.fa); + } + } else { + result = -3000; } - return FAFwrite(buffer, 1, size, stream->handle.fa); + } else { + result = NANDWrite(&stream->handle.nand, buffer, size); } - return -3000; + return result; } s32 WADSeekStream(WADStream* stream, u32 offset, s32 origin) { @@ -2734,7 +2763,7 @@ static s32 _WADUnpackBackup(WADHeader* header, WADStream* stream, WADUnpackInfo* info->titleMetaSize = 1; result = WADReadStream(stream, (void**)&info->titleMeta, alignedSize, offset + info->sectionOffset); - if (result != alignedSize) { + if ((s32)result != (s32)alignedSize) { return -3005; } result = 0; @@ -2853,7 +2882,8 @@ static s32 _WADVerifySavedataZD(WADSaveDataHeader* header, WADStream* stream, s32 result; if (header->saveType != 1) { - return -3009; + result = -3009; + goto cleanup; } fileHeader = MEMAllocFromAllocator(allocator, sizeof(WADFileHeader)); if (fileHeader == 0) { @@ -2877,26 +2907,29 @@ static s32 _WADVerifySavedataZD(WADSaveDataHeader* header, WADStream* stream, } memset(encryptedData, 0, 0x4000); memset(decryptedData, 0, 0x4000); - if (strcmp(fileHeader->name, "zeldaTp.dat") != 0) { - result = -3009; - goto cleanup; - } - result = WADReadStream(stream, &encryptedData, 0x4000, offset + 0x80); - if (result != 0x4000) { - result = -3005; - goto cleanup; - } - result = ES_Decrypt(6, fileHeader->iv, encryptedData, 0x4000, decryptedData); - if (result != 0) { - result = -3005; - goto cleanup; - } - if (WADCheckSavedataZD(decryptedData) == 0) { - result = -3009; - goto cleanup; - } - result = NANDPrivateCreate(fileHeader->name, 0x34, 0); - if ((result == 0) && (NANDPrivateOpen(fileHeader->name, &fileInfo, 2) == 0)) { + if (strcmp(fileHeader->name, "zeldaTp.dat") == 0) { + result = WADReadStream(stream, &encryptedData, 0x4000, offset + 0x80); + if (result != 0x4000) { + result = -3005; + goto cleanup; + } + result = ES_Decrypt(6, fileHeader->iv, encryptedData, 0x4000, decryptedData); + if (result != 0) { + result = -3005; + goto cleanup; + } + if (WADCheckSavedataZD(decryptedData) == 0) { + result = -3009; + goto cleanup; + } + result = NANDPrivateCreate(fileHeader->name, 0x34, 0); + if (result != 0) { + goto cleanup; + } + result = NANDPrivateOpen(fileHeader->name, &fileInfo, 2); + if (result != 0) { + goto cleanup; + } fileOpened = TRUE; result = NANDWrite(&fileInfo, decryptedData, 0x4000); if (result != 0x4000) { @@ -2907,6 +2940,8 @@ static s32 _WADVerifySavedataZD(WADSaveDataHeader* header, WADStream* stream, fileOpened = FALSE; } } + } else { + result = -3009; } cleanup: @@ -2925,33 +2960,38 @@ cleanup: return result; } -static void _WADCleanTmpDir(MEMAllocator* allocator) { +static s32 _WADCleanTmpDir(MEMAllocator* allocator) { + s32 result; + u32 fileCount = 0; char* names = 0; char* name; - char filePath[NAND_MAX_PATH] ALIGN32; - u32 fileCount = 0; + char filePath[NAND_MAX_PATH + 1] = {0}; u32 fileIndex; - s32 result; result = NANDPrivateReadDir("/tmp", 0, &fileCount); if ((result == 0) && (fileCount != 0)) { names = MEMAllocFromAllocator(allocator, fileCount * 0x41); - if ((names != 0) && (NANDPrivateReadDir("/tmp", names, &fileCount) == 0)) { - name = names; - for (fileIndex = 0; fileIndex < fileCount; fileIndex++) { - char* extension = strrchr(name, '.'); - if ((extension != 0) && (strncmp(extension + 1, "tmp", 3) == 0)) { - snprintf(filePath, sizeof(filePath), "/tmp/%s", name); - NANDPrivateDelete(filePath); - OSReport("%s:%d remove %s", "WADImportEx", 0x1777, filePath); + if (names != 0) { + result = NANDPrivateReadDir("/tmp", names, &fileCount); + if (result == 0) { + name = names; + for (fileIndex = 0; fileIndex < fileCount;) { + char* extension = strrchr(name, '.'); + if ((extension != 0) && (strncmp(extension + 1, "tmp", 3) == 0)) { + sprintf(filePath, "/tmp/%s", name); + NANDPrivateDelete(filePath); + OSReport("%s:%d remove %s\n", __func__, 0x1777, filePath); + } + fileIndex++; + name += strlen(name) + 1; } - name += strlen(name) + 1; } } } if (names != 0) { MEMFreeToAllocator(allocator, names); } + return result; } s32 WADImportDVDForBS(const char* path, void* buffer, u32 bufferSize) { @@ -2993,7 +3033,7 @@ s32 WADImportDVDForBS(const char* path, void* buffer, u32 bufferSize) { header = (WADHeader*)readBuffer; result = WAD_815C2F44(header, parts.headerInfo); if (result != 2) { - OSReport("%s:%d Format should be iRD format: %s\n", "WADImportDVDForBS", 0x17D2, + OSReport("%s:%d Format should be iRD format: %s\n", __func__, 0x17D2, path); result = -3000; goto cleanup; @@ -3023,23 +3063,23 @@ s32 WADImportDVDForBS(const char* path, void* buffer, u32 bufferSize) { titleMeta = parts.titleMeta; applicationSize = ((u32)titleMeta->contents[0].size + 0xF) & ~0xF; applicationData = readBuffer + sectionOffset; - if ((titleMeta == 0) || (titleMeta->head.titleId != ES_TITLE_ID(1, 1))) { - OSReport("%s:%d This function only works for boot2 import.\n", "WADImportDVDForBS", - 0x180D); - result = -3000; - } else { + if ((titleMeta != 0) && (titleMeta->head.titleId == ES_TITLE_ID(1, 1))) { result = ES_ImportBoot(parts.ticket, parts.certificates, parts.certificateSize, parts.titleMeta, parts.titleMetaSize, parts.certificates, parts.certificateSize, parts.crls, parts.crlSize, applicationData, applicationSize); if (result != 0) { - OSReport("%s: Import Boot Failed: %d\n", "WADImportDVDForBS", result); + OSReport("%s: Import Boot Failed: %d\n", __func__, result); } else { - OSReport("%s: Import Boot Successful\n", "WADImportDVDForBS"); + OSReport("%s: Import Boot Successful\n", __func__); } + } else { + OSReport("%s:%d This function only works for boot2 import.\n", __func__, + 0x180D); + result = -3000; } } else { - OSReport("%s:%d This function only works for boot2 import.\n", "WADImportDVDForBS", + OSReport("%s:%d This function only works for boot2 import.\n", __func__, 0x1814); result = -3000; } @@ -3242,17 +3282,11 @@ extern s32 SHA1Reset(void* context); extern s32 SHA1Result(void* context, void* digest); static s32 WAD_815C43E0(WADHashThreadArgs* args) { - void* context; - s32 result; - u32 remaining; - u32 bufferIndex; - WADImportTransfer* transfer; - - context = args->context; - result = 0; - remaining = args->size; - bufferIndex = 0; - transfer = args->transfer; + void* context = args->context; + s32 result = 0; + u32 remaining = args->size; + u32 bufferIndex = 0; + WADImportTransfer* transfer = args->transfer; while ((remaining != 0) && (result == 0)) { u32 size = remaining; -- 2.49.1 From f98e550b24e7752f1674ee1d1cfa92afe418ed5a Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Mon, 28 Sep 2026 23:57:07 -0500 Subject: [PATCH 02/18] sdchansel: continue decompilation (worker snapshot b063d97f) (#253) --- config/43U/symbols.txt | 18 +- .../sdChannelSelect/iplSDChannelSelect.h | 44 ++- .../sdChannelSelect/iplSDChannelSelect.cpp | 303 +++++++++++++++++- 3 files changed, 351 insertions(+), 14 deletions(-) diff --git a/config/43U/symbols.txt b/config/43U/symbols.txt index 1aa0bdf3..2679503c 100644 --- a/config/43U/symbols.txt +++ b/config/43U/symbols.txt @@ -4580,9 +4580,9 @@ handleNandTitleUsage__Q33ipl5scene15SDChannelSelectFv = .text:0x813DBD94; // typ compareTitleUsage__Q33ipl5scene15SDChannelSelectFPCvPCv = .text:0x813DBE6C; // type:function size:0x28 handleSDTitleList__Q33ipl5scene15SDChannelSelectFv = .text:0x813DBE94; // type:function size:0x124 compareTitleInfo__Q33ipl5scene15SDChannelSelectFPCvPCv = .text:0x813DBFB8; // type:function size:0x28 -iplSDChannelSelect_813DBFE0 = .text:0x813DBFE0; // type:function size:0x2AC +handleSDTitleListResult__Q33ipl5scene15SDChannelSelectFv = .text:0x813DBFE0; // type:function size:0x2AC handleSDMountComplete__Q33ipl5scene15SDChannelSelectFv = .text:0x813DC28C; // type:function size:0x64 -iplSDChannelSelect_813DC2F0 = .text:0x813DC2F0; // type:function size:0x1B0 +handleSDChannelUpdateComplete__Q33ipl5scene15SDChannelSelectFv = .text:0x813DC2F0; // type:function size:0x1B0 handleSDCardReady__Q33ipl5scene15SDChannelSelectFv = .text:0x813DC4A0; // type:function size:0x5C handleCardCommand__Q33ipl5scene15SDChannelSelectFv = .text:0x813DC4FC; // type:function size:0x78 handleCopyComplete__Q33ipl5scene15SDChannelSelectFv = .text:0x813DC574; // type:function size:0x80 @@ -4592,7 +4592,7 @@ handleMoveComplete__Q33ipl5scene15SDChannelSelectFv = .text:0x813DC684; // type: handleBackupFitComplete__Q33ipl5scene15SDChannelSelectFv = .text:0x813DC714; // type:function size:0x48 handleNandSDCleanupComplete__Q33ipl5scene15SDChannelSelectFv = .text:0x813DC75C; // type:function size:0x48 handleSDDeleteComplete__Q33ipl5scene15SDChannelSelectFv = .text:0x813DC7A4; // type:function size:0x48 -iplSDChannelSelect_813DC7EC = .text:0x813DC7EC; // type:function size:0x14C +updateChannelNotices__Q33ipl5scene15SDChannelSelectFii = .text:0x813DC7EC; // type:function size:0x14C processWorkerState__Q33ipl5scene15SDChannelSelectFv = .text:0x813DC938; // type:function size:0x18C updateDialogAnimation__Q33ipl5scene15SDChannelSelectFv = .text:0x813DCAC4; // type:function size:0x42C setDialogMessage__Q33ipl5scene15SDChannelSelectFUlUl = .text:0x813DCEF0; // type:function size:0x24 @@ -4632,15 +4632,15 @@ iplSDChannelSelect_813DF3FC = .text:0x813DF3FC; // type:function size:0x110 iplSDChannelSelect_813DF50C = .text:0x813DF50C; // type:function size:0x4C iplSDChannelSelect_813DF558 = .text:0x813DF558; // type:function size:0x178 iplSDChannelSelect_813DF6D0 = .text:0x813DF6D0; // type:function size:0x164 -iplSDChannelSelect_813DF834 = .text:0x813DF834; // type:function size:0x110 -iplSDChannelSelect_813DF944 = .text:0x813DF944; // type:function size:0x84 -iplSDChannelSelect_813DF9C8 = .text:0x813DF9C8; // type:function size:0xF8 -iplSDChannelSelect_813DFAC0 = .text:0x813DFAC0; // type:function size:0xFC -iplSDChannelSelect_813DFBBC = .text:0x813DFBBC; // type:function size:0xE4 +createChannelList__Q33ipl5scene15SDChannelSelectFib = .text:0x813DF834; // type:function size:0x110 +createChannelObject__Q33ipl5scene15SDChannelSelectFii = .text:0x813DF944; // type:function size:0x84 +destroyUnusedChannelObjects__Q33ipl5scene15SDChannelSelectFiPQ33ipl5scene12SDChannelObj = .text:0x813DF9C8; // type:function size:0xF8 +refreshChannelList__Q33ipl5scene15SDChannelSelectFv = .text:0x813DFAC0; // type:function size:0xFC +refreshAfterSDTitleList__Q33ipl5scene15SDChannelSelectFv = .text:0x813DFBBC; // type:function size:0xE4 destroyChannelObject__Q33ipl5scene15SDChannelSelectFPQ33ipl5scene12SDChannelObj = .text:0x813DFCA0; // type:function size:0x50 iplSDChannelSelect_813DFCF0 = .text:0x813DFCF0; // type:function size:0x74 iplSDChannelSelect_813DFD64 = .text:0x813DFD64; // type:function size:0x154 -iplSDChannelSelect_813DFEB8 = .text:0x813DFEB8; // type:function size:0x74 +findChannelObject__Q33ipl5scene15SDChannelSelectCFii = .text:0x813DFEB8; // type:function size:0x74 iplSDChannelSelect_813DFF2C = .text:0x813DFF2C; // type:function size:0x1C0 hasChannelObject__Q33ipl5scene15SDChannelSelectCFii = .text:0x813E00EC; // type:function size:0x140 isChannelInCalc__Q33ipl5scene15SDChannelSelectCFiii = .text:0x813E022C; // type:function size:0x68 diff --git a/include/scene/sdChannelSelect/iplSDChannelSelect.h b/include/scene/sdChannelSelect/iplSDChannelSelect.h index d650b64d..ea16e604 100644 --- a/include/scene/sdChannelSelect/iplSDChannelSelect.h +++ b/include/scene/sdChannelSelect/iplSDChannelSelect.h @@ -12,6 +12,7 @@ namespace ipl { namespace scene { class SDChannelObj { public: + SDChannelObj(EGG::Heap* heap, int page, int index); ~SDChannelObj(); EGG::Heap* getHeap() const { return mpHeap; } @@ -19,13 +20,41 @@ namespace ipl { int getIndex() const { return mIndex; } private: + friend class SDChannelSelect; + nw4r::ut::Link mListLink; - f32 mOffsetX; - f32 mOffsetY; + EGG::ExpHeap* mpDialogHeap; + EGG::ExpHeap* mpChannelHeap; EGG::Heap* mpHeap; u32 mState; int mPage; int mIndex; + nand::LayoutFile* mpLayoutFile; + nw4r::lyt::Pane* mpPane; + layout::Animator* mpPaneAnimator; + layout::Object* mpBaseLayout; + layout::Animator* mpBaseAnimator; + layout::Object* mpPageLayout; + layout::Animator* mpPageAnimators[3]; + int mPageAnimation; + int mPageAnimationFrame; + layout::Object* mpDialogLayout; + layout::Animator* mpDialogAnimator; + int mDialogState; + int mDialogFrame; + int mDialogTimer; + int mAnimationState; + nw4r::lyt::Group* mpNewMessageGroup; + int mNewMessageCount; + u8 mbNewMessageGroupActive; + int mNewMessageState; + int mNewMessageFrame; + f32 mOffsetX; + f32 mOffsetY; + f32 mAspectRatioScale; + int mStateFlags; + void* mpThumbnailData; + NandSDWorker::SDAppMetaEntry mAppMeta; }; extern "C" void iplSDChannelObj_813E3104(SDChannelObj* channel); extern "C" void iplSDChannelObj_813E311C(SDChannelObj* channel, EGG::ExpHeap* firstHeap, @@ -35,6 +64,8 @@ namespace ipl { extern "C" void iplSDChannelObj_813E3180(SDChannelObj* channel, nand::LayoutFile* layoutFile); extern "C" void iplSDChannelObj_813E3304(SDChannelObj* channel); extern "C" void iplSDChannelObj_813E330C(SDChannelObj* channel); + extern "C" void* iplSDChannelObj_813E3128(SDChannelObj* channel); + extern "C" bool iplSDChannelObj_813E3330(SDChannelObj* channel); union SDChannelSelectCommandArguments { u32 values[3]; @@ -68,7 +99,7 @@ namespace ipl { struct SDChannelSelectTitleInfo { ESTitleId32 titleId; - u32 state; + bool used; }; struct SDChannelSelectNoticeQueue { @@ -147,6 +178,10 @@ namespace ipl { void handleNandTitleUsage(); void handleNandTitleUsageComplete(); void handleSDTitleList(); + void handleSDTitleListResult(); + void refreshAfterSDTitleList(); + void handleSDChannelUpdateComplete(); + void updateChannelNotices(int pageOffset, int index); void handleSDMountComplete(); void handleCopyComplete(); void handleDeleteComplete(); @@ -164,7 +199,10 @@ namespace ipl { static int compareTitleInfo(const void* lhs, const void* rhs); void createChannelList(int page, bool force); void destroyChannelObject(SDChannelObj* channel); + void destroyUnusedChannelObjects(int currentPage, SDChannelObj* keepChannel); + void refreshChannelList(); bool hasChannelObject(int page, int index) const; + SDChannelObj* findChannelObject(int page, int index) const; void createChannelObject(int page, int index); void createBaseLayout(); void updateNoCardLayouts(); diff --git a/src/scene/sdChannelSelect/iplSDChannelSelect.cpp b/src/scene/sdChannelSelect/iplSDChannelSelect.cpp index 793ccfb9..678f43af 100644 --- a/src/scene/sdChannelSelect/iplSDChannelSelect.cpp +++ b/src/scene/sdChannelSelect/iplSDChannelSelect.cpp @@ -433,7 +433,7 @@ namespace ipl { mpSDWorker->startup_async(); mWorkerState = 2; } else if (mPreviousSDState != mCurrentSDState && mCurrentSDState == 7) { - System::getErrorHandler()->set(ErrorHandler::DEFAULT, 1); + setDialogMessage(8, 0xaa); } } @@ -544,6 +544,91 @@ namespace ipl { return left->titleId != right->titleId; } + void SDChannelSelect::handleSDTitleListResult() { + if (mpSDWorker->is_working()) { + return; + } + + mLastOperation = 14; + if (mDialogState != 0) { + return; + } + + if (OSGetTime() - mOperationStartTime >= OS_TIMER_CLOCK) { + setDialogMessage(1, 0); + int result = mpSDWorker->get_async_result(); + if (result == NandSDWorker::RESULT_OK || + result == NandSDWorker::RESULT_SD_APP_LOC_NOT_FOUND) { + for (int channelIndex = 0; channelIndex < mPageCount * 12; + ++channelIndex) { + if (mpChannelTitleIds[channelIndex] != 0) { + SDChannelSelectTitleInfo* info = + static_cast( + bsearch(mpChannelTitleIds + channelIndex, mpSDTitleInfo, + mSDTitleCount, sizeof(SDChannelSelectTitleInfo), + compareTitleInfo)); + if (info != NULL) { + info->used = true; + } else { + mpChannelTitleIds[channelIndex] = 0; + } + } + } + + int channelIndex = 0; + u32 titleIndex = 0; + bool addedTitle = false; + for (; channelIndex < mPageCount * 12; ++channelIndex) { + if (mpChannelTitleIds[channelIndex] == 0) { + if (titleIndex == mSDTitleCount) { + break; + } + + for (; titleIndex < mSDTitleCount; ++titleIndex) { + SDChannelSelectTitleInfo* info = &mpSDTitleInfo[titleIndex]; + if (!info->used && info->titleId != 0x48415A41) { + mpChannelTitleIds[channelIndex] = info->titleId; + addedTitle = true; + ++titleIndex; + break; + } + } + } + } + + if (addedTitle || result == NandSDWorker::RESULT_SD_APP_LOC_NOT_FOUND) { + enqueueLoadNotice(); + } + } else { + int channelCount = 0; + int channelIndex = 0; + u32 titleIndex = 0; + for (; titleIndex < mSDTitleCount; ++titleIndex) { + u32 titleId = mpSDTitleInfo[titleIndex].titleId; + if (titleId != 0x48415A41) { + ++channelCount; + mpChannelTitleIds[channelIndex++] = titleId; + if (channelCount == mPageCount * 12) { + break; + } + } + } + enqueueLoadNotice(); + } + + mWorkerCommand = 1; + mbNeedsRefresh = true; + u32 titleCount = mbHazardTitleFound ? mSDTitleCount - 1 : mSDTitleCount; + if (titleCount > static_cast(mPageCount * 12)) { + mbOperationActive = true; + } + if (titleCount >= static_cast(mPageCount * 12)) { + mbSDCardBroken = true; + } + refreshAfterSDTitleList(); + } + } + void SDChannelSelect::processWorkerCommands() { if (mpSDWorker->is_working() || mWorkerState != 4) { return; @@ -643,6 +728,53 @@ namespace ipl { } } + void SDChannelSelect::handleSDChannelUpdateComplete() { + if (mpSDWorker->is_working()) { + return; + } + + mLastOperation = 14; + SDChannelObj* channel = mpCurrentLoadedChannel; + int page = channel->mPage; + int index = channel->mIndex; + if (!isChannelInCalc(page, index, mCurrentPage) || + static_cast(mCurrentSDState) - 1 <= 1) { + destroyChannelObject(channel); + mWorkerCommand = 1; + mpCurrentLoadedChannel = NULL; + return; + } + + if (mpSDWorker->get_async_result() >= 0) { + channel->mStateFlags = 0; + channel->mState = 2; + DCFlushRange(iplSDChannelObj_813E3128(channel), 0x19000); + } else { + memcpy(iplSDChannelObj_813E3128(channel), + mpCorruptIconFile->getBuffer(), mpCorruptIconFile->getLength()); + memset(&channel->mAppMeta, 0, sizeof(channel->mAppMeta)); + channel->mStateFlags = 3; + channel->mState = 2; + } + + SDChannelObj* previous = findChannelObject(page, index); + if (previous != NULL) { + nw4r::ut::List_Insert(&mChannelObjects, previous, channel); + nw4r::ut::List_Remove(&mChannelObjects, previous); + destroyChannelObject(previous); + } else { + nw4r::ut::List_Append(&mChannelObjects, channel); + } + + updateChannelObject(channel); + if (mCurrentPage == page) { + mpPaneManager->initPane(getChannelPane(index)); + } + + mWorkerCommand = 1; + mpCurrentLoadedChannel = NULL; + } + void SDChannelSelect::handleCopyComplete() { if (!mpSDWorker->is_working()) { mLastOperation = 14; @@ -736,6 +868,50 @@ namespace ipl { } } + void SDChannelSelect::updateChannelNotices(int pageOffset, int index) { + int page = mCurrentPage + pageOffset; + if (page < 0 || mpChannelTitleIds == NULL) { + return; + } + + int firstIndex; + int indexStep; + if (pageOffset == 2) { + firstIndex = 0; + indexStep = 4; + } else if (pageOffset < 2) { + if (pageOffset == -2) { + firstIndex = 3; + indexStep = 4; + } else { + firstIndex = 0; + indexStep = 1; + } + } else { + firstIndex = 0; + indexStep = 1; + } + + int pageTitleIndex = page * 12; + SDChannelObj* channel; + if (index >= 0 && index < 12 && + (channel = findChannelObject(page, index)) != NULL && channel->mState == 2 && + mpChannelTitleIds[pageTitleIndex + index] != 0) { + enqueueNotice(mpChannelTitleIds[pageTitleIndex + index], page, index); + } + + for (int channelIndex = firstIndex; channelIndex < 12; + channelIndex += indexStep) { + if (channelIndex != index && + (channel = findChannelObject(page, channelIndex)) != NULL && + channel->mState == 2 && + mpChannelTitleIds[pageTitleIndex + channelIndex] != 0) { + enqueueNotice(mpChannelTitleIds[pageTitleIndex + channelIndex], page, + channelIndex); + } + } + } + void SDChannelSelect::processWorkerState() { mPreviousSDState = mCurrentSDState; mCurrentSDState = mpSDWorker->get_sd_state(); @@ -761,7 +937,7 @@ namespace ipl { handleSDTitleList(); break; case 3: - handleCopyComplete(); + handleSDChannelUpdateComplete(); break; case 4: handleSDMountComplete(); @@ -1337,6 +1513,129 @@ namespace ipl { return mpLayout->FindPaneByName(mscChannelPaneNames[2][index]); } + void SDChannelSelect::createChannelList(int page, bool force) { + for (int index = 0; index < MAX_CHANNEL_INDEX; ++index) { + if (force || findChannelObject(page, index) == NULL) { + createChannelObject(page, index); + } + } + + if (page < mPageCount - 1) { + for (int index = 0; index < MAX_CHANNEL_INDEX; index += 4) { + if (force || findChannelObject(page + 1, index) == NULL) { + createChannelObject(page + 1, index); + } + } + } + + if (page > 0) { + for (int index = 3; index < MAX_CHANNEL_INDEX; index += 4) { + if (force || findChannelObject(page - 1, index) == NULL) { + createChannelObject(page - 1, index); + } + } + } + } + + void SDChannelSelect::destroyUnusedChannelObjects(int currentPage, + SDChannelObj* keepChannel) { + int keepPage; + int keepIndex; + if (keepChannel != NULL) { + keepPage = keepChannel->getPage(); + keepIndex = keepChannel->getIndex(); + } + + SDChannelObj* channel = NULL; + while (channel = static_cast( + nw4r::ut::List_GetNext(&mChannelObjects, channel)), + channel != NULL) { + int page = channel->getPage(); + int index = channel->getIndex(); + if (keepChannel != NULL && page == keepPage && index == keepIndex) { + continue; + } + if (mState < 0x18) { + if (mState >= 0xF && page == mSourcePage && index == mSourceIndex) { + continue; + } + } + if (!isChannelInCalc(page, index, currentPage)) { + SDChannelObj* previous = static_cast( + nw4r::ut::List_GetPrev(&mChannelObjects, channel)); + nw4r::ut::List_Remove(&mChannelObjects, channel); + destroyChannelObject(channel); + channel = previous; + } + } + } + + void SDChannelSelect::createChannelObject(int page, int index) { + EGG::FrmHeap* objectHeap = EGG::FrmHeap::create(0x212B8, mpLayoutHeap, 2); + SDChannelObj* channel = new (mpThumbnailHeap, 4) SDChannelObj(objectHeap, page, index); + nw4r::ut::List_Append(&mChannelObjects, channel); + } + + void SDChannelSelect::refreshChannelList() { + SDChannelObj* channel = NULL; + while (channel = static_cast( + nw4r::ut::List_GetNext(&mChannelObjects, channel)), + channel != NULL) { + if (iplSDChannelObj_813E3330(channel)) { + SDChannelObj* previous = static_cast( + nw4r::ut::List_GetPrev(&mChannelObjects, channel)); + nw4r::ut::List_Remove(&mChannelObjects, channel); + destroyChannelObject(channel); + channel = previous; + } else if (channel->mStateFlags == 2) { + channel->mStateFlags = 1; + } + } + + createChannelList(mCurrentPage, false); + if (mCurrentPage < mPageCount - 1) { + createChannelList(mCurrentPage + 1, false); + } + if (mCurrentPage > 0) { + createChannelList(mCurrentPage - 1, false); + } + updateChannelObjects(); + } + + void SDChannelSelect::refreshAfterSDTitleList() { + SDChannelObj* channel = NULL; + while (channel = static_cast( + nw4r::ut::List_GetNext(&mChannelObjects, channel)), + channel != NULL) { + int channelIndex = channel->mPage * 12 + channel->mIndex; + if (!iplSDChannelObj_813E3330(channel) && + mpChannelTitleIds[channelIndex] != 0) { + channel->mStateFlags = 2; + } + } + + clearNoticeQueue(); + updateChannelNotices(0, -1); + updateChannelNotices(-1, -1); + updateChannelNotices(1, -1); + updateChannelNotices(-2, -1); + updateChannelNotices(2, -1); + } + + SDChannelObj* SDChannelSelect::findChannelObject(int page, int index) const { + SDChannelObj* channel = NULL; + while (channel = static_cast( + nw4r::ut::List_GetNext(&mChannelObjects, channel)), + channel != NULL) { + if (page == channel->getPage()) { + if (index == channel->getIndex()) { + return channel; + } + } + } + return NULL; + } + math::VEC3 SDChannelSelect::getChannelPanePosition(SDChannelSelect* scene, int index) { math::VEC3 position(0.0f, 0.0f, 0.0f); MTXMultVec(scene->getCenterChannelPane(index)->GetGlobalMtx(), position, position); -- 2.49.1 From 313e396989c1bc8d4f0719633133bb4f4574fd2f Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Mon, 28 Sep 2026 23:57:13 -0500 Subject: [PATCH 03/18] sdmemory: continue decompilation (worker snapshot d94f5e95) (#254) --- config/43U/symbols.txt | 4 +- include/layout/iplLayout.h | 4 + include/scene/sdChannelMemory/iplSDMemory.h | 3 +- include/system/iplDialogWindow.h | 1 + src/scene/sdChannelMemory/iplSDMemory.cpp | 186 +++++++++++++++++++- 5 files changed, 190 insertions(+), 8 deletions(-) diff --git a/config/43U/symbols.txt b/config/43U/symbols.txt index 2679503c..db234d49 100644 --- a/config/43U/symbols.txt +++ b/config/43U/symbols.txt @@ -4881,12 +4881,12 @@ onDialogState23__Q33ipl5scene8SDMemoryFv = .text:0x813EEDF8; // type:function si onDialogState24__Q33ipl5scene8SDMemoryFv = .text:0x813EEE70; // type:function size:0xC0 iplSDMemory_813EEF30 = .text:0x813EEF30; // type:function size:0x88 iplSDMemory_813EEFB8 = .text:0x813EEFB8; // type:function size:0x70C -iplSDMemory_813EF6C4 = .text:0x813EF6C4; // type:function size:0x14 +writeFourFlagBytes__Q23ipl5sceneFPUcUcUcUcUc = .text:0x813EF6C4; // type:function size:0x14 iplSDMemory_813EF6D8 = .text:0x813EF6D8; // type:function size:0x48 GetBeginIter__Q34nw4r2ut28LinkListFv = .text:0x813EF720; // type:function size:0x8 iplSDMemory_813EF728 = .text:0x813EF728; // type:function size:0x8 __ne__Q24nw4r2utFQ44nw4r2ut28LinkList8IteratorQ44nw4r2ut28LinkList8Iterator = .text:0x813EF730; // type:function size:0x18 -iplSDMemory_813EF748 = .text:0x813EF748; // type:function size:0x74 +getControlPaneIndex__Q33ipl5scene8SDMemoryFPCc = .text:0x813EF748; // type:function size:0x74 iplSDMemory_813EF7BC = .text:0x813EF7BC; // type:function size:0x128 iplSDMemory_813EF8E4 = .text:0x813EF8E4; // type:function size:0xF0 iplSDMemory_813EF9D4 = .text:0x813EF9D4; // type:function size:0x120 diff --git a/include/layout/iplLayout.h b/include/layout/iplLayout.h index 46ab9cd3..cc14ecd0 100644 --- a/include/layout/iplLayout.h +++ b/include/layout/iplLayout.h @@ -180,7 +180,11 @@ namespace ipl { /*** TODO: These always generate a weak. Try and make them not do that. ***/ const nw4r::ut::Rect getTextDrawRect(const nw4r::lyt::TextBox* textBox) const { return textBox->GetTextDrawRect(mDrawInfo); } +#ifdef IPL_SDMEMORY_GET_TEXT_DRAW_RECT_OUT_OF_LINE + const nw4r::ut::Rect getTextDrawRect(const char* paneName) const; +#else const nw4r::ut::Rect getTextDrawRect(const char* paneName) const { return getTextDrawRect(nw4r::ut::DynamicCast(mLayout.GetRootPane()->FindPaneByName(paneName))); } +#endif const nw4r::ut::Rect getPaneRect(nw4r::lyt::Pane* pane) const { return pane->GetPaneRect(mDrawInfo); } const nw4r::ut::Rect getPaneRect(const char* paneName) const { return getPaneRect(mLayout.GetRootPane()->FindPaneByName(paneName)); } diff --git a/include/scene/sdChannelMemory/iplSDMemory.h b/include/scene/sdChannelMemory/iplSDMemory.h index 6352f88c..e4d3826d 100644 --- a/include/scene/sdChannelMemory/iplSDMemory.h +++ b/include/scene/sdChannelMemory/iplSDMemory.h @@ -13,7 +13,7 @@ namespace ipl { class SDMemory { public: struct TitleRange { - ESTitleId* mpTitles; + s32 mByteSize; u32 mCount; }; @@ -62,6 +62,7 @@ namespace ipl { void onDialogState23(); bool onDialogState24(); void resetDialogPaneAnimations(); + s32 getControlPaneIndex(const char* paneName); layout::Object* mpMainLayout; layout::Object* mpTitleLayout; diff --git a/include/system/iplDialogWindow.h b/include/system/iplDialogWindow.h index 5fe75217..59c707ca 100644 --- a/include/system/iplDialogWindow.h +++ b/include/system/iplDialogWindow.h @@ -121,6 +121,7 @@ namespace ipl { #ifdef IPL_SDMEMORY_DIALOG_STATE_ACCESSOR int getStateForSDMemory() const { return mState; } int getResultForSDMemory() const { return mResult; } + void setTitleForSDMemory(const wchar_t* text) { set_title(text); } #endif /*=================*/ diff --git a/src/scene/sdChannelMemory/iplSDMemory.cpp b/src/scene/sdChannelMemory/iplSDMemory.cpp index eb7cd7d3..ec77a71a 100644 --- a/src/scene/sdChannelMemory/iplSDMemory.cpp +++ b/src/scene/sdChannelMemory/iplSDMemory.cpp @@ -1,13 +1,27 @@ #define IPL_SDMEMORY_SCROLLER_INIT_OUT_OF_LINE #define IPL_SDMEMORY_SET_TRANSLATE_OUT_OF_LINE #define IPL_SDMEMORY_DIALOG_STATE_ACCESSOR +#define IPL_SDMEMORY_GET_TEXT_DRAW_RECT_OUT_OF_LINE #include "scene/sdChannelMemory/iplSDMemory.h" #undef IPL_SDMEMORY_DIALOG_STATE_ACCESSOR #undef IPL_SDMEMORY_SET_TRANSLATE_OUT_OF_LINE #undef IPL_SDMEMORY_SCROLLER_INIT_OUT_OF_LINE +#undef IPL_SDMEMORY_GET_TEXT_DRAW_RECT_OUT_OF_LINE #include "system/iplSystem.h" #include "sound/iplSound.h" +#include "utility/iplLayout.h" +#include + +extern "C" bool iplSDChannelSelect_813DDB74(ipl::scene::NandSDCardManager* manager, + ipl::scene::SDMemory::TitleRange* nandTitles, + ipl::scene::SDMemory::TitleRange* sdTitles, + ESTitleId* titleIds, wchar_t* titleNames, u32* titleCount, + s32 state); +extern "C" bool iplSDChannelSelect_813DB5EC(ipl::scene::NandSDCardManager* manager, + const ESTitleId* titleEntry, ESTitleId titleId); +extern "C" bool iplSDChannelSelect_813DB4D4(ipl::scene::NandSDCardManager* manager, + const ESTitleId* titleEntry, ESTitleId titleId, u32 flags); namespace ipl { namespace utility { @@ -22,9 +36,11 @@ namespace ipl { namespace scene { static const char* const sControlPaneNames[] = { - "A", "B", "B_BtnA", "A", "B", "C", "D", "B_BtnA", "B_00", "C_00", "D_00", "B_BtnA", + "A", "B", "B_BtnA", }; + static const char* const sTitlePaneNames[] = {"A", "B", "B_BtnA", "C", "D"}; + static const char* const sAdditionalTitlePaneNames[] = {"B_00", "C_00", "D_00", "B_BtnA"}; static const char* const sDialogPaneNames[] = {"B_ArwR", "B_ArwL", "B_CalExit", "B_CalExit_00"}; SDMemory::SDMemory() : mScroller() {} @@ -470,7 +486,8 @@ namespace ipl { if (!mpMainLayout->isPlaying(-1)) { for (int i = 0; i < 3; i++) { mPanelStates[i] = 0; - mpPaneManagers[0]->initPane(mpMainLayout->getNW4RLyt()->GetRootPane()->FindPaneByName(sControlPaneNames[i], true)); + nw4r::lyt::Pane* pane = mpMainLayout->FindPaneByName(sControlPaneNames[i]); + mpPaneManagers[0]->initPane(pane); } mDialogState = 1; @@ -492,17 +509,46 @@ namespace ipl { } } + bool SDMemory::onDialogState3() { + if (!mpMainLayout->isPlaying(-1)) { + switch (mProcessState) { + case 0: + if (iplSDChannelSelect_813DDB74(mpNandSDCardManager, &mNandTitleRange, &mSDTitleRange, + mTitleIds, &mTitleNames[0][0], &mTitleCount, 2)) { + mDialogState = 4; + mpTitleLayout->getAnim(0)->initAnmFrame(); + mpTitleLayout->getAnim(0)->play(); + snd::getSystem()->startSE("WIPL_SE_INFO_WINDOW"); + } else { + mDialogState = 21; + mMessageId = 0xB4; + } + break; + case 1: + mDialogState = 21; + mMessageId = 0xB3; + break; + case 2: + mDialogState = 25; + mErrorCode = 3; + return true; + } + } + + return false; + } + void SDMemory::onDialogState4() { if (!mpTitleLayout->isPlaying(-1)) { if (mDisplayMode == 4) { for (int i = 0; i < 5; i++) { mTitlePanelStates[i] = 0; - mpPaneManagers[1]->initPane(mpTitleLayout->FindPaneByName(sControlPaneNames[i + 3])); + mpPaneManagers[1]->initPane(mpTitleLayout->GetRootPane()->FindPaneByName(sTitlePaneNames[i], true)); } } else { for (int i = 1; i < 5; i++) { mTitlePanelStates[i] = 0; - mpPaneManagers[1]->initPane(mpTitleLayout->FindPaneByName(sControlPaneNames[i + 7])); + mpPaneManagers[1]->initPane(mpTitleLayout->GetRootPane()->FindPaneByName(sAdditionalTitlePaneNames[i - 1], true)); } } @@ -518,6 +564,52 @@ namespace ipl { } } + void SDMemory::onDialogState8() { + if (System::getDialog()->getStateForSDMemory() == 2) { + if (mTransferStartTime == 0) { + mTransferStartTime = OSGetTime(); + } + + if (!mpNandSDCardManager->getWorker()->is_working() && + OSGetTime() - mTransferStartTime > OS_TIMER_CLOCK) { + System::getDialog()->terminate(); + } + } + + if (System::getDialog()->getLastResult() != -1) { + if (mpNandSDCardManager->getWorker()->get_async_result() == 0) { + mNandTitleCount = mTitleListState.mSecondaryCount; + mTitleNameCount = mTitleListState.mNameCount; + } else { + mNandTitleCount = 0; + mTitleNameCount = 0; + } + + mDialogState = 9; + layout::Animator* animation = mpMainLayout->getAnim(0); + animation->initFrame(); + animation->restart(); + + nw4r::lyt::Pane* headerPane = mpMainLayout->FindPaneByName("T_Header"); + static_cast(headerPane)->SetString(System::getMessage(0xBE), 0); + + mButtonState = 0; + nw4r::lyt::Pane* titlePane = mpMainLayout->FindPaneByName("N_Body"); + nw4r::lyt::Pane* bodyPane = mpMainLayout->FindPaneByName("T_Letter"); + bodyPane->SetAlpha(0xFF); + + for (u32 i = 0; i < mTitleCount; i++) { + utility::layout::set_string(bodyPane, mTitleNames[i]); + nw4r::ut::Rect textRect = mpMainLayout->getTextDrawRect("T_Letter"); + f32 lineCount = -(textRect.bottom - textRect.top) / titlePane->GetSize().height; + mButtonState += static_cast(ceil(lineCount)); + } + + setScrollLimit(); + resetScrollArrows(); + } + } + void SDMemory::onDialogState7() { if (!mpTitleLayout->isPlaying(-1)) { switch (mProcessState) { @@ -536,11 +628,14 @@ namespace ipl { } } + + void SDMemory::onDialogState9() { if (!mpDialogLayout->isPlaying(0)) { for (int i = 0; i < 4; i++) { mPanelAnimationStates[i] = 0; - mpPaneManagers[2]->initPane(mpDialogLayout->getNW4RLyt()->GetRootPane()->FindPaneByName(sDialogPaneNames[i], true)); + nw4r::lyt::Pane* pane = mpDialogLayout->FindPaneByName(sDialogPaneNames[i]); + mpPaneManagers[2]->initPane(pane); } mDialogState = 10; @@ -589,6 +684,41 @@ namespace ipl { } } + void SDMemory::onDialogState16() { + if (mTitleCount > mCurrentTitle && System::isReceiveScheduleStopped()) { + const ESTitleId* titleEntry = &mTitleIds[mCurrentTitle]; + if (iplSDChannelSelect_813DB4D4(mpNandSDCardManager, titleEntry, *titleEntry, 0)) { + mDialogState = 16; + } else { + System::getDialog()->terminate(); + mDialogState = 20; + mErrorCode = 1; + mMessageId = 0xAE; + } + } + } + + void SDMemory::onDialogState18() { + if (System::getDialog()->getStateForSDMemory() == 2) { + mCurrentTitleName[0] = L'\0'; + const wchar_t* message = System::getMessage(0xB1); + const wchar_t* titleName = mTitleNames[mCurrentTitle]; + swprintf(mCurrentTitleName, 0x107f, L"%ls\n%ls", titleName, message); + System::getDialog()->setTitleForSDMemory(mCurrentTitleName); + + const ESTitleId* titleEntry = &mTitleIds[mCurrentTitle]; + const ESTitleId titleId = *titleEntry; + if (iplSDChannelSelect_813DB5EC(mpNandSDCardManager, titleEntry, titleId)) { + mDialogState = 18; + } else { + System::getDialog()->terminate(); + mDialogState = 20; + mErrorCode = 1; + mMessageId = 0xAE; + } + } + } + void SDMemory::onDialogState19() { if (!mpNandSDCardManager->getWorker()->is_working()) { if (mpNandSDCardManager->getWorker()->get_async_result() == 0) { @@ -623,6 +753,33 @@ namespace ipl { return false; } + void SDMemory::onDialogState21() { + const wchar_t* message = System::getMessage(mMessageId); + const wchar_t* blockCountMarker = wcsstr(message, L"***\n"); + wchar_t* format = new (System::getMem2App(), -32) wchar_t[0x400]; + wchar_t* dialogMessage = new (System::getMem2App(), -32) wchar_t[0x400]; + + if (blockCountMarker != NULL && message != NULL) { + format[0] = L'\0'; + wcsncat(format, message, static_cast(blockCountMarker - message) >> 1); + wcscat(format, L"%d"); + wcscat(format, blockCountMarker + 4); + + s32 blocks = mNandTitleRange.mByteSize / 0x20000; + if (mNandTitleRange.mByteSize % 0x20000 != 0) { + blocks++; + } + + swprintf(dialogMessage, 0x3ff, format, blocks); + } + + System::getDialog()->callBtn2NoShade(dialogMessage, 0xC8, 0xA5, false); + mDialogState = 22; + + delete[] format; + delete[] dialogMessage; + } + bool SDMemory::onDialogState22() { DialogWindow* dialog = System::getDialog(); if (dialog->getStateForSDMemory() == 3 && dialog->getResultForSDMemory() == 1) { @@ -677,5 +834,24 @@ namespace ipl { return false; } + + s32 SDMemory::getControlPaneIndex(const char* paneName) { + s32 paneIndex = -1; + for (s32 i = 0; i < 3; i++) { + if (strcmp(paneName, sControlPaneNames[i]) == 0) { + paneIndex = i; + break; + } + } + + return paneIndex; + } + + void writeFourFlagBytes(u8* flags, u8 first, u8 second, u8 third, u8 fourth) { + flags[0] = first; + flags[1] = second; + flags[2] = third; + flags[3] = fourth; + } } } -- 2.49.1 From 8e254f1c883d7e75d5fa33d19455fff87625464b Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 29 Sep 2026 00:39:13 -0500 Subject: [PATCH 04/18] wad: refine import/backup paths (21/40) (#255) --- libs/RVL_SDK/src/wad/wad.c | 100 ++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 47 deletions(-) diff --git a/libs/RVL_SDK/src/wad/wad.c b/libs/RVL_SDK/src/wad/wad.c index 43373a86..33835973 100644 --- a/libs/RVL_SDK/src/wad/wad.c +++ b/libs/RVL_SDK/src/wad/wad.c @@ -232,7 +232,7 @@ static s32 _WADBackupGetFiles(const char* path, u32 flags, MEMAllocator* allocat u32* fileCount, WADBackupFileHeader* files); static s32 _WADBackupGetSize(u32 flags, ESTmdView* titleMeta, ESContentMask* contentMask, u32 fileCount, WADBackupFileHeader* files, u32* titleMetaSize, - u32* contentDataSize, u32* totalSize); + u32* contentDataSize, u32* fileDataSize, u32* totalSize); static s32 _WADCheckContents(ESTmdView* titleMeta, ESContentMask* contentMask); static void _WADRandPad(void* buffer, u32 size); static s32 _WADVerifySavedataZD(WADSaveDataHeader* header, WADStream* stream, @@ -432,14 +432,14 @@ s32 WADImportGetBlocks(char* path, MEMAllocator* allocator, WADLocation location blocks->unkBlocks += (workspace.unpackInfo.sectionSize + 0x3FFF) >> 14; blocks->unkInodes = 1; } - if (workspace.unpackInfo.cidxMode < 1) { - contentCount = titleMeta->head.numContents; - } else { + if (workspace.unpackInfo.cidxMode >= 1) { contentCount = _WADGetCidxCount(workspace.unpackInfo.contentIndex); if (contentCount > titleMeta->head.numContents) { result = -3001; goto cleanup; } + } else { + contentCount = titleMeta->head.numContents; } contentMeta = titleMeta->contents; for (index = 0; index < contentCount; index++) { @@ -453,12 +453,12 @@ s32 WADImportGetBlocks(char* path, MEMAllocator* allocator, WADLocation location contentMeta = titleMeta->contents + selectedIndex; result = 0; } - if ((contentMeta->type & 0x8000) == 0) { - blocks->privateInodes++; - blocks->privateBlocks += ((u32)contentMeta->size + 0x3FFF) >> 14; - } else { + if ((contentMeta->type & 0x8000) != 0) { blocks->sharedInodes++; blocks->sharedBlocks += ((u32)contentMeta->size + 0x3FFF) >> 14; + } else { + blocks->privateInodes++; + blocks->privateBlocks += ((u32)contentMeta->size + 0x3FFF) >> 14; } contentMeta++; } @@ -1338,7 +1338,7 @@ s32 WADBackupEx(u64 titleId, u32 ticketId, MEMAllocator* allocator, char* path, } } result = _WADBackupGetSize(flags, titleMeta, &existingContentMask, fileCount, files, - &titleMetaSize, &contentDataSize, &fileDataSize); + &titleMetaSize, &contentDataSize, &fileDataSize, &totalSize); if (result != 0) { goto cleanup; } @@ -1346,9 +1346,8 @@ s32 WADBackupEx(u64 titleId, u32 ticketId, MEMAllocator* allocator, char* path, result = -3002; goto cleanup; } - totalSize = titleMetaSize + contentDataSize + fileDataSize + 0x340; if (path == 0) { - *sizeOut = totalSize; + *sizeOut = totalSize + 0x340; result = 0; goto cleanup; } @@ -1794,48 +1793,51 @@ s32 _WADGetCidxCount(const ESContentMask* contentMask) { if ((contentMask->data[bitIndex >> 3] & (1 << (bitIndex & 7))) != 0) { count++; } - if ((contentMask->data[(bitIndex + 1) >> 3] & (1 << ((bitIndex + 1) & 7))) != 0) { + bitIndex++; + if ((contentMask->data[bitIndex >> 3] & (1 << (bitIndex & 7))) != 0) { count++; } - if ((contentMask->data[(bitIndex + 2) >> 3] & (1 << ((bitIndex + 2) & 7))) != 0) { + bitIndex++; + if ((contentMask->data[bitIndex >> 3] & (1 << (bitIndex & 7))) != 0) { count++; } - if ((contentMask->data[(bitIndex + 3) >> 3] & (1 << ((bitIndex + 3) & 7))) != 0) { + bitIndex++; + if ((contentMask->data[bitIndex >> 3] & (1 << (bitIndex & 7))) != 0) { count++; } - bitIndex += 4; + bitIndex++; } return count; } static s32 _WADGetCidx(const ESContentMask* contentMask, u32 contentNumber) { u32 remaining = contentNumber + 1; - u32 bitIndex = 0; - u32 nextIndex; + s32 bitIndex = 0; + s32 nextIndex; for (bitIndex = 0; bitIndex < 0x200; bitIndex += 4) { - if ((contentMask->data[(s32)bitIndex >> 3] & (1 << (bitIndex & 7))) != 0) { + if ((contentMask->data[bitIndex >> 3] & (1 << (bitIndex & 7))) != 0) { remaining--; } if (remaining == 0) { return bitIndex; } nextIndex = bitIndex + 1; - if ((contentMask->data[(s32)nextIndex >> 3] & (1 << (nextIndex & 7))) != 0) { + if ((contentMask->data[nextIndex >> 3] & (1 << (nextIndex & 7))) != 0) { remaining--; } if (remaining == 0) { return nextIndex; } nextIndex = bitIndex + 2; - if ((contentMask->data[(s32)nextIndex >> 3] & (1 << (nextIndex & 7))) != 0) { + if ((contentMask->data[nextIndex >> 3] & (1 << (nextIndex & 7))) != 0) { remaining--; } if (remaining == 0) { return nextIndex; } nextIndex = bitIndex + 3; - if ((contentMask->data[(s32)nextIndex >> 3] & (1 << (nextIndex & 7))) != 0) { + if ((contentMask->data[nextIndex >> 3] & (1 << (nextIndex & 7))) != 0) { remaining--; } if (remaining == 0) { @@ -2041,8 +2043,8 @@ cleanup: static s32 _WADBackupGetSize(u32 flags, ESTmdView* titleMeta, ESContentMask* contentMask, u32 fileCount, WADBackupFileHeader* files, u32* titleMetaSize, - u32* contentDataSize, u32* fileDataSize) { - u32 titleSize = 0; + u32* contentDataSize, u32* fileDataSize, u32* totalSize) { + u32 titleSize = 0x80; u32 contentSize = 0; u32 filesSize = 0; u32 selectedCount; @@ -2050,26 +2052,26 @@ static s32 _WADBackupGetSize(u32 flags, ESTmdView* titleMeta, ESContentMask* con u32 fileIndex; s32 result = 0; - if (titleMeta == 0) { - if (titleMetaSize != 0) { - *titleMetaSize = 0; - } - } else if (((flags & 1) != 0) || ((flags & 0x20) != 0)) { - result = ES_GetTmdSizeFromView(titleMeta, &titleSize); - if (result != 0) { - return result; - } - titleSize = (titleSize + 0x3F) & ~0x3F; - } - if (((flags & 1) != 0) && (titleMeta != 0)) { - selectedCount = _WADGetCidxCount(contentMask); - for (contentIndex = 0; contentIndex < selectedCount; contentIndex++) { - s32 tmdIndex = _WADGetCidx(contentMask, contentIndex); - if ((tmdIndex < 0) || (titleMeta->head.numContents <= tmdIndex)) { - return -3009; + if ((titleMeta != 0) && (titleMetaSize != 0)) { + if (((flags & 1) != 0) || ((flags & 0x20) != 0)) { + result = ES_GetTmdSizeFromView(titleMeta, titleMetaSize); + if (result != 0) { + return result; } - contentSize += (titleMeta->contents[tmdIndex].size + 0x3F) & ~0x3F; + titleSize += (*titleMetaSize + 0x3F) & ~0x3F; } + if ((flags & 1) != 0) { + selectedCount = _WADGetCidxCount(contentMask); + for (contentIndex = 0; contentIndex < selectedCount; contentIndex++) { + s32 tmdIndex = _WADGetCidx(contentMask, contentIndex); + if ((tmdIndex < 0) || (titleMeta->head.numContents <= tmdIndex)) { + return -3009; + } + contentSize += (titleMeta->contents[tmdIndex].size + 0x3F) & ~0x3F; + } + } + } else if ((titleMeta == 0) && (titleMetaSize != 0)) { + *titleMetaSize = 0; } if ((fileCount != 0) && (files != 0)) { for (fileIndex = 0; fileIndex < fileCount; fileIndex++) { @@ -2085,6 +2087,9 @@ static s32 _WADBackupGetSize(u32 flags, ESTmdView* titleMeta, ESContentMask* con if (fileDataSize != 0) { *fileDataSize = filesSize; } + if (totalSize != 0) { + *totalSize = titleSize + contentSize + filesSize; + } return result; } #pragma dont_inline reset @@ -2998,13 +3003,13 @@ s32 WADImportDVDForBS(const char* path, void* buffer, u32 bufferSize) { DVDFileInfo fileInfo; WADBootImportParts parts; WADHeader* header; - ESTitleMeta* titleMeta; - u8* readBuffer = buffer; + u8* readBuffer; + BOOL fileOpened = FALSE; + ESTitleMeta* titleMeta = 0; void* applicationData; u32 paddedFileSize; u32 sectionOffset; u32 applicationSize; - BOOL fileOpened = FALSE; s32 result; if ((path == 0) || (buffer == 0)) { @@ -3015,6 +3020,7 @@ s32 WADImportDVDForBS(const char* path, void* buffer, u32 bufferSize) { return -3004; } fileOpened = TRUE; + readBuffer = buffer; paddedFileSize = (fileInfo.length + 0x1F) & ~0x1F; if (paddedFileSize > bufferSize) { result = -3003; @@ -3057,10 +3063,10 @@ s32 WADImportDVDForBS(const char* path, void* buffer, u32 bufferSize) { } if (header->tmdSize != 0) { parts.titleMetaSize = header->tmdSize; - parts.titleMeta = readBuffer + sectionOffset; + titleMeta = (ESTitleMeta*)(readBuffer + sectionOffset); + parts.titleMeta = titleMeta; sectionOffset += (header->tmdSize + 0x3F) & ~0x3F; } - titleMeta = parts.titleMeta; applicationSize = ((u32)titleMeta->contents[0].size + 0xF) & ~0xF; applicationData = readBuffer + sectionOffset; if ((titleMeta != 0) && (titleMeta->head.titleId == ES_TITLE_ID(1, 1))) { @@ -3093,8 +3099,8 @@ cleanup: s32 WADImportDVDExForBS(const char* path, void* buffer, u32 bufferSize) { WADHeader header ALIGN32; - WADBootImportParts parts; DVDFileInfo fileInfo; + WADBootImportParts parts; u8* readBuffer = buffer; u8* contentBuffer; ESTitleMeta* titleMeta; -- 2.49.1 From 51f940c1eae06ca422a75418b039c97e56b7e561 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 29 Sep 2026 01:28:56 -0500 Subject: [PATCH 05/18] Decompile iplSetting to 68/112 functions (#256) * start decompiling setting scene * match basic setting scene helpers * match setting constructor and storage * match setting lookup helpers * match setting cleanup methods * restore setting scene name tables * match setting fadein state copy * decompile setting screen transitions * match setting video mode transition * decompile setting normal update * decompile setting fadeout * match setting data initialization * decompile setting input initialization * decompile setting access point flow * decompile setting network workflows * match setting helper frames * match setting update initialization * match setting eula initialization * match setting fadein readiness * type setting helper allocations * localize browser setting tables * match setting controller flow * match setting exit condition * improve setting screen mode flow * match setting normal state cases * improve setting keyboard initialization * match setting text input handling * match setting ssid initialization * match setting address initialization * match setting proxy initialization * match setting nickname save * match setting security and ssid writes * match setting proxy profile updates * match setting mtu parsing * match parental password results * match parental security answer result * match master key result order * improve setting text validation * implement setting reverse ip conversion * type setting text buffer as wide characters * match setting default back string * improve setting safe mode match * match setting access point reset * match setting access point redraw * match setting access point events * match setting left event * improve setting creation and AP traversal --- include/scene/setting/iplAPScanThread.h | 6 +- include/scene/setting/iplSetting.h | 234 +- include/system/iplKeyboard.h | 7 + src/scene/setting/iplSetting.cpp | 3531 +++++++++++++++++++++++ 4 files changed, 3776 insertions(+), 2 deletions(-) create mode 100644 src/scene/setting/iplSetting.cpp diff --git a/include/scene/setting/iplAPScanThread.h b/include/scene/setting/iplAPScanThread.h index 2b8f5aa5..5a3f93c7 100644 --- a/include/scene/setting/iplAPScanThread.h +++ b/include/scene/setting/iplAPScanThread.h @@ -17,7 +17,11 @@ namespace ipl { virtual ~APScanThread(); // 0x08 virtual void* Run(); // 0x0C - virtual void unk_0x2C() = 0; // 0x2C +#ifdef IPL_SETTING_IMPLEMENTATION + virtual void unk_0x2C(); +#else + virtual void unk_0x2C() = 0; +#endif void setResultData(unsigned short* buffer); void setParam(); diff --git a/include/scene/setting/iplSetting.h b/include/scene/setting/iplSetting.h index e3152884..6743299c 100644 --- a/include/scene/setting/iplSetting.h +++ b/include/scene/setting/iplSetting.h @@ -3,14 +3,168 @@ #include "iplSceneHeader.h" +#ifdef IPL_SETTING_IMPLEMENTATION +#include +#include "layout/iplGuiManager.h" +#include "layout/GUIManager.h" +#include "iplwww/www_wiisetting.h" +#include "iplwww/www_browser.h" +#include "system/iplKeyboard.h" +#include "system/iplNand.h" +#include "utility/iplThread.h" +extern "C" { +#include +} +#endif + +namespace ipl { + namespace controller { + class Interface; + } +} + namespace ipl { namespace scene { +#ifdef IPL_SETTING_IMPLEMENTATION + class Setting; + class APScanThread; + + class APEvent : public ::gui::EventHandler { + public: + APEvent(Setting* setting) : ::gui::EventHandler(), mpSetting(setting) {} + + virtual void onEvent(u32 componentID, u32 event, void* data); + + private: + Setting* mpSetting; + }; + + struct SettingAnimation { + u8 unknown[0x14]; + int state; + }; + + struct SettingAPScanList { + u8 unknown[0x14]; + u16 count; + u8 entries[0x7fe]; + WDBssDesc_* currentDescriptor; + }; +#endif + FADER_SCENE_CLASS(Setting) { public: Setting(EGG::Heap * heap, int arg); - void setInitializeResult(bool, int); +#ifdef IPL_SETTING_IMPLEMENTATION + virtual ~Setting(); + + bool isAnimating(); + void getFuncMsgQ(); + void resetFuncMsgQ(); + void createBrowser(); + void initDirectUrl(); + void initString(); + void initWiiSettingData(); + void initNickName(); + void initSecurityKey(); + void initSSID(); + void initIP(); + void initDNS(); + void initProxy(); + void initBasic(); + void initMTU(); + void initSecA(); + void initVersion(); + void updateController_(); + void setSE(); + void changeVideoMode(); + bool isInitialSequenceExit(const ::ipl::controller::Interface* input); + bool updateScreenMode(); + void initHTMLText(); + void initMessage(); + void initKeyboard(const char* text); + bool checkInputString(const wchar_t* text); + int checkIPString(const wchar_t* text); + void setDefaultBackString(); + void calcKeyboard(); + void calcSetting(); + void onTextInputOK(); + void setDisPos(); + void setNickName(); + void setSecurityKey(); + void setSSID(); + void setIP(); + void setDNS(); + void setProxy(); + void setBasic(); + void setMTU(); + void setParePass(); + void setPareRePass(); + void setPareJudgePass(); + void setSecA(); + void setReSecA(); + void setMasterKey(); + void adjustSecA(wchar_t* text); + void reAdjustSecA(); + u8 checkTextNum(const char* text); + bool checkSpace(); + void convertIP(char* destination, const u8* address); + void convertRevIP(u8* destination, const char* address); + void initScroll(); + void updateScroll(); + void setAPDraw(); + int getRadioLevel(const WDBssDesc_* descriptor); + void setUseEULA_Init_(); + void setUseEULA_Cancel_(); + void setUseEULA_Start_(); + void setUseEULA_WaitStopMotor_(); + bool validateEULA_(); + void setUpdate_Init_(); + void setUpdate_WaitAcceptDialog_(); + void setUpdate_ConnectTestStart_(); + void setUpdate_ConnectTestCreateWait_(); + void setUpdate_ConnectTestRun_(); + void setUpdate_ConnectTestFailed_(); + void setUpdate_SuccessDialog_(); + void setUpdate_NoUpdateDialog_(); + void setUpdate_EULAInit_(); + void setUpdate_Reboot_(); + void makeErrorMessage(); + bool calcSafeMode(); + void waitStart(); + void waitFinish(); + bool isWaitPlaying(); + void initAP(); + void resetAP(); + void redrawAP(); + void scanAP(); + void setNUP(); + void setUSBAP(); + void cancelUSBAP(); + void AOSSProcess(); + void RakuProcess(); + void setUpdate_(); + void setUseEULA_(); + void start_point_event(const char* pageName); + void start_trig_event(const char* pageName); + void start_left_event(const char* pageName); + int get_arw_no(const char* paneName); + int get_ap_no(const char* buttonName); + void makeSupportCode(); + int getErrorNum(); + virtual void destroy(); + virtual void prepare(); + virtual void create(); + virtual void calc(); + virtual void draw(); + virtual FaderSceneCommand calcFadein(); + virtual FaderSceneCommand calcNormal(); + virtual FaderSceneCommand calcFadeout(); + virtual BOOL isResetAcceptable() const; +#endif u16 getProfileID(); + void setInitializeResult(bool, int); void setConnectTestResult(int, int, bool, int); int getUpdateTiming(); @@ -25,7 +179,85 @@ namespace ipl { }; private: +#ifdef IPL_SETTING_IMPLEMENTATION + int mUpdateTiming; + u8 unk_0x5C; + u8 unk_0x5D[3]; + nand::Base* mpWWWLibraryFile; + nand::Base* mpSettingHTMLFile; + nand::Base* mpWWWArchiveFile; + nand::Base* mpFontFile; + nand::Base* mpBackgroundTPLFile; + int unk_0x74; + int unk_0x78; + int unk_0x7C; + int mProfileIDMode; + int unk_0x84; + int mAOSSState; + int mRakuState; + int mFuncMsgPending; + int unk_0x94; + ESTitleId mUpdateTitleId; + u32 mPrepareTick; + u8 mSettingData[0x16]; + u8 unk_0xBA[2]; + nand::LayoutFile* mpSettingLayoutFile; + layout::Object* mpChangeLayout; + layout::Object* mpMainLayout; + layout::Object* mpWaitLayout; + SettingAnimation* mpFirstAnimation; + SettingAnimation* mpSecondAnimation; + APEvent* mpEventHandler; + gui::PaneManager* mpPaneManager; + void* mpUSBAPThread; + utility::ut_thread* mpAOSSThread; + utility::ut_thread* mpRakuRakuThread; + APScanThread* mpAPScanThread; + SettingAPScanList mAPScanList; + void* mpMem1BrowserBuffer; + u32 unk_0x908; + void* mpMem2BrowserBuffer; + void* mpBrowserStringBuffer; + int unk_0x914; + int unk_0x918; + u8 unk_0x91C[4]; + ext_ead::www::ImeData* mpBrowserData; + www::wiisetting::WiiData* mpWiiSettingData; + www::wiisetting::WiiFlag* mpWiiSettingFlag; + u8 unk_0x92C; + u8 unk_0x92D[3]; + int unk_0x930; + www::wiisetting::SetStringBuf* mpStringBuffer; +#ifdef IPL_SETTING_IMPLEMENTATION + wchar_t unk_0x938[0x101]; +#else + u8 unk_0x938[0x202]; +#endif + u8 unk_0xB3A; + u8 mBrowserCreated; + keyboard::Manager::State mKeyboardState; + int mInitialArgument; + int mAspectRatio; + int mProgressiveMode; + int mEuRgb60Mode; + u8 mIsResetAcceptable; + u8 unk_0xB5D[3]; + OSMessageQueue mFuncMessageQueue; + OSMessage mFuncMessages[5]; + int unk_0xB94; + int mState; + int unk_0xB9C; + OSTime mCreatePageTime; + u32 unk_0xBA8; + u8 unk_0xBAC; + u8 unk_0xBAD[3]; + u8 unk_0xBB0[0x10]; + static void* mem1Buffer_; + static void* mem2Buffer_; +#else u8 unk_0x58[0xB68]; +#endif + }; } // namespace scene } // namespace ipl diff --git a/include/system/iplKeyboard.h b/include/system/iplKeyboard.h index 717d309d..a9f06df3 100644 --- a/include/system/iplKeyboard.h +++ b/include/system/iplKeyboard.h @@ -63,8 +63,15 @@ namespace ipl { textinput::MemoManager::StateType type; // 0x00 KeyboardState iplType; // 0x04 bool pressOK; // 0x08 +#ifdef IPL_SETTING_IMPLEMENTATION + u8 reservedByte; +#else u8 unused_0x09; +#endif wchar_t* wcString; // 0x0C +#ifdef IPL_SETTING_IMPLEMENTATION + State& operator=(const State& other); +#endif } State; Manager() : mpManager(NULL), mEvent(), mCurrentConChan(0), mbActivated(false), mpSaveFile(NULL) {} diff --git a/src/scene/setting/iplSetting.cpp b/src/scene/setting/iplSetting.cpp new file mode 100644 index 00000000..5b46c3e8 --- /dev/null +++ b/src/scene/setting/iplSetting.cpp @@ -0,0 +1,3531 @@ +#define IPL_SETTING_IMPLEMENTATION +#include "scene/setting/iplSetting.h" +#include "scene/setting/iplAPScanThread.h" + +#include "scene/setting/iplNCDSetting.h" +#include "scene/setting/iplParental.h" +#include "scene/nakamuraTest/iplNakamuraTest.h" +#include "scene/parentalDialog/iplParentalDialog.h" +#include "system/iplErrorHandler.h" +#include "system/iplSystem.h" +#include "utility/iplWpad.h" +#include "utility/iplCharacterCode.h" +#include "sound/iplSound.h" +#include "utility/iplESMisc.h" + +#include "iplwww/www_wiisetting.h" +#include "iplwww/www_surface.h" +#include "iplwww/www_trasition.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" void __VISetAdjustingValues(s32 horizontal, s32 vertical); + +namespace ipl { + class SensitivityDrawing { + public: + static void draw(nand::File* file); + }; +} + +namespace ipl { + namespace keyboard { + Manager::State& Manager::State::operator=(const Manager::State& other) { + type = other.type; + iplType = other.iplType; + pressOK = other.pressOK; + reservedByte = other.reservedByte; + wcString = other.wcString; + return *this; + } + } +} + +namespace ipl { + namespace scene { + class USBAPThread { + public: + USBAPThread(); + bool is(); + void setData(const wchar_t* nickname, u8* result); + void Init(unsigned short* profile, u8* result); + void cancel(); + + private: + wchar_t mNickname[10]; + }; + + class AOSSThread : public utility::ut_thread { + public: + AOSSThread(EGG::Heap* heap); + virtual ~AOSSThread(); + virtual void* Run(); + int start(); + int finish(NCDAossConfig* config, int* result); + void cancel(); + + private: + int mResult; + int mPriority; + void* mpThreadStack; + void* mpHeapArea; + void* mpExpandedHeap; + u8 mStartParameters[0x26c]; + }; + + class RakuRakuThread : public utility::ut_thread { + public: + RakuRakuThread(EGG::Heap* heap); + virtual ~RakuRakuThread(); + virtual void* Run(); + int getState(); + int start(); + int finish(NCDApConfig* config, int* result); + void cancel(); + + private: + int mResult; + int mState; + void* mpMessageQueue; + u32 mFlags; + void* mpHeapArea; + void* mpThreadStack; + int mMessage; + }; + + struct SettingAnimationBinding { + u16 animation; + u16 pane; + }; + + struct SettingSecAText { + wchar_t firstLine[16]; + wchar_t wrappedLine[17]; + }; + + static const SettingAnimationBinding sSettingAnimationBindings[] = { + {0, 2}, {0, 3}, {1, 2}, {1, 3}, {2, 2}, {2, 3}, {3, 2}, {3, 3}, {4, 2}, {4, 3}, + {5, 0}, {6, 0}, {7, 8}, {7, 9}, {7, 10}, {7, 11}, {8, 8}, {8, 9}, {8, 10}, {8, 11}, + {9, 1}, {10, 1}, {11, 14}, {11, 15}, {11, 16}, {11, 17}, {11, 18}, {11, 19}, {12, 14}, {12, 15}, + {12, 16}, {12, 17}, {12, 18}, {12, 19}, {13, 14}, {13, 15}, {13, 16}, {13, 17}, {13, 18}, {13, 19}, + {14, 14}, {14, 15}, {14, 16}, {14, 17}, {14, 18}, {14, 19}, {15, 20}, {15, 21}, {15, 22}, {15, 23}, + {15, 24}, {15, 25}, {16, 20}, {16, 21}, {16, 22}, {16, 23}, {16, 24}, {16, 25}, + }; + + const char* sSettingAPButtonNames[] = {"B_AP2", "B_AP3", "B_AP4", "B_AP5"}; + + const char* sSettingArrowNames[] = {"B_ArwA", "B_ArwB"}; + + const char* sSettingAPTextNames[] = {"T_Name1", "T_Name2", "T_Name3", "T_Name4", "T_Name5", "T_Name6"}; + + const char* sSettingAPNumberNames[] = {"N_AP1", "N_AP2", "N_AP3", "N_AP4", "N_AP5", "N_AP6"}; + + const char* sSettingAPPaneNames[] = { + "G_ListUpDown", "G_ListInOut", "G_ArwA", "G_ArwB", "G_Denpa", "G_Lock", "G_AP0", + "G_AP1", "G_AP2", "G_AP3", "G_AP4", "G_AP5", "G_AP6", "G_AP7", + "G_Denpa1", "G_Denpa2", "G_Denpa3", "G_Denpa4", "G_Denpa5", "G_Denpa6", + "G_Lock1", "G_Lock2", "G_Lock3", "G_Lock4", "G_Lock5", "G_Lock6", + }; + + const char* sSettingAPAnimations[] = { + "my_AP_a_ArwAppear.brlan", "my_AP_a_ArwLost.brlan", "my_AP_a_ArwFocusOn.brlan", + "my_AP_a_ArwFocusOff.brlan", "my_AP_a_ArwSelect.brlan", "my_AP_a_ScrollUp.brlan", + "my_AP_a_ScrollDown.brlan", "my_AP_a_BtnFocusOn.brlan", "my_AP_a_BtnFocusOff.brlan", + "my_AP_a_ListAppear.brlan", "my_AP_a_ListLost.brlan", "my_AP_a_Denpa0.brlan", + "my_AP_a_Denpa1.brlan", "my_AP_a_Denpa2.brlan", "my_AP_a_Denpa3.brlan", + "my_AP_a_LockOff.brlan", "my_AP_a_LockOn.brlan", + }; + + NCDAossConfig m_AOSSConfig; + NCDRakuApConfig m_RakuConfig; + + void* Setting::mem1Buffer_; + void* Setting::mem2Buffer_; + + Setting::Setting(EGG::Heap* heap, int arg) : FaderSceneBase(heap) { + unk_0x5C = 0; + mpWWWLibraryFile = 0; + mpSettingHTMLFile = 0; + mpWWWArchiveFile = 0; + mpFontFile = 0; + mpSettingLayoutFile = 0; + mBrowserCreated = 0; + setSceneParentFlags(3); + unk_0x74 = 0; + mInitialArgument = arg; + unk_0x78 = 1; + unk_0x84 = 1; + mProfileIDMode = 0; + mUpdateTiming = 0; + unk_0x914 = 0; + unk_0x918 = -1; + unk_0x91C[0] = 0; + unk_0x91C[1] = 0; + unk_0x91C[2] = 0; + unk_0x91C[3] = 0; + unk_0x7C = 0; + unk_0xB9C = 0; + unk_0x92C = 0; + unk_0x930 = 0; + mIsResetAcceptable = 1; + mFuncMsgPending = 0; + mAspectRatio = SCGetAspectRatio(); + mProgressiveMode = SCGetProgressiveMode(); + mEuRgb60Mode = SCGetEuRgb60Mode(); + unk_0xB94 = 0; + unk_0xBAC = 0; + unk_0x94 = 0; + } + + bool Setting::isAnimating() { + return mpSecondAnimation->state == 1 || mpFirstAnimation->state == 1 || mState != 20; + } + + void Setting::getFuncMsgQ() { + OSMessage message = 0; + if (mFuncMsgPending == 0 && OSReceiveMessage(&mFuncMessageQueue, &message, 0)) { + mFuncMsgPending = 1; + mpWiiSettingFlag->smthMsgData = (u8)message; + } + } + + void Setting::resetFuncMsgQ() { + mpWiiSettingFlag->smthMsgData = 0; + mFuncMsgPending = 0; + } + + Setting::~Setting() { + OSReport("***Destruct!!\n"); + if (mem1Buffer_) { + System::createMem1AppHeap()->free(mem1Buffer_); + mem1Buffer_ = 0; + } + if (mem2Buffer_) { + System::getMem2App()->free(mem2Buffer_); + mem2Buffer_ = 0; + } + if (mpWWWLibraryFile) { + delete mpWWWLibraryFile; + } + if (mpSettingHTMLFile) { + delete mpSettingHTMLFile; + } + if (mpWWWArchiveFile) { + delete mpWWWArchiveFile; + } + if (mpFontFile) { + delete mpFontFile; + } + if (mpBackgroundTPLFile) { + delete mpBackgroundTPLFile; + } + System::destroyMem1AppHeap(); + System::getBS2Manager()->restart(); + OSReport(" ... bs2 manager restarted\n"); + } + + void Setting::destroy() { + delete mpAOSSThread; + delete mpRakuRakuThread; + } + + void Setting::prepare() { + System::getBS2Manager()->abort(); + while (System::getBS2Manager()->getIPLState() != 8) { + System::getBS2Manager()->update(); + VIWaitForRetrace(); + } + + System::getUsbEtherMacAddr(); + mPrepareTick = OSGetTick(); + mpWWWLibraryFile = System::getNandManager()->readSharedAsync( + System::createMem1AppHeap(), "wwwlib-rvl.lz7", 2); + + char fontName[32]; + char htmlPath[64]; + char productArea = SCGetProductArea(); + if (productArea == 6) { + goto koreanFont; + } + if (productArea < 6) { + if (productArea == 4) { + goto defaultFont; + } + if (productArea >= 4) { + goto europeFont; + } + if (productArea >= 0) { + goto standardFont; + } + } else if (productArea == 11) { + goto chineseFont; + } + goto defaultFont; + + standardFont: + snprintf(fontName, sizeof(fontName), "WiiNTLG-Regular.ttc"); + snprintf(htmlPath, sizeof(htmlPath), "/html/%s/iplsetting.ash", "US2"); + goto loadFiles; + + koreanFont: + snprintf(fontName, sizeof(fontName), "Wii-kr_Round Gothic B.ttf"); + snprintf(htmlPath, sizeof(htmlPath), "/html/%s/iplsetting.ash", "US2"); + goto loadFiles; + + chineseFont: + snprintf(fontName, sizeof(fontName), "Wii-cn_HeiTiW5.ttf"); + snprintf(htmlPath, sizeof(htmlPath), "/html/%s/iplsetting.ash", "US2"); + goto loadFiles; + + europeFont: + snprintf(fontName, sizeof(fontName), "WiiNTLG-Regular.ttc"); + snprintf(htmlPath, sizeof(htmlPath), "/html/%s/iplsetting.ash", "TW2"); + goto loadFiles; + + defaultFont: + snprintf(fontName, sizeof(fontName), "WiiNTLG-Regular.ttc"); + snprintf(htmlPath, sizeof(htmlPath), "/html/%s/iplsetting.ash", "US2"); + + loadFiles: + mpSettingHTMLFile = System::getNandManager()->readAsync( + System::createMem1AppHeap(), htmlPath, 0, 0, false); + mpWWWArchiveFile = System::getNandManager()->readAsync( + System::getMem2App(), "/www.arc", 0, 0, false); + mpFontFile = System::getNandManager()->readSharedAsync( + System::getMem2App(), fontName, 3); + mpBackgroundTPLFile = System::getNandManager()->readAsync( + System::getMem2App(), "/html/BG_16x9.tpl", 0, 0, false); + mpSettingLayoutFile = System::getNandManager()->readLayoutAsync(getSceneHeap(), "setting.ash", false); + + if (mInitialArgument == 2) { + memset(mSettingData, 0, sizeof(mSettingData)); + mAspectRatio = 0; + www::wiisetting::setInitSetupFlag(1); + } else if (mInitialArgument == 5) { + www::wiisetting::setInitSetupFlag(1); + } else { + www::wiisetting::setInitSetupFlag(0); + } + } + + void Setting::create() { + nand::File* archiveFile = static_cast(mpWWWArchiveFile); + nand::File* writtenArchive = System::getNandManager()->write( + getSceneHeap(), "/tmp/www.arc", archiveFile->getBuffer(), archiveFile->getLength(), 0x30); + if (writtenArchive->isFullForTask()) { + System::getErrorHandler()->log("NAND", 0, "iplSetting.cpp", 0x178); + System::getErrorHandler()->set(ErrorHandler::DEFAULT, 2, NULL, 0, -1); + } + delete writtenArchive; + + mpChangeLayout = new layout::Object(getSceneHeap(), mpSettingLayoutFile, "arc", "SceenChange_b.brlyt"); + mpFirstAnimation = reinterpret_cast(mpChangeLayout->bind("SceenChange_b_Right.brlan")); + mpSecondAnimation = reinterpret_cast(mpChangeLayout->bind("SceenChange_b_Left.brlan")); + mpChangeLayout->finishBinding(); + + mpMainLayout = new layout::Object(getSceneHeap(), mpSettingLayoutFile, "arc", "my_AP_a.brlyt"); + for (int index = 0; index < 58; index++) { + bool initialAnimation = index == 20 || index == 10; + const SettingAnimationBinding& binding = sSettingAnimationBindings[index]; + const char* animation = sSettingAPAnimations[binding.animation]; + const char* pane = sSettingAPPaneNames[binding.pane]; + mpMainLayout->bindToGroup(animation, pane, false, initialAnimation); + } + mpMainLayout->finishBinding(); + + mpWaitLayout = new layout::Object(getSceneHeap(), mpSettingLayoutFile, "arc", "it_Waiting_a.brlyt"); + mpWaitLayout->bindToGroup("it_Waiting_a_Wait.brlan", "G_Wait", false, false); + mpWaitLayout->finishBinding(); + mpWaitLayout->FindPaneByName("N_Wait")->SetVisible(false); + + mpBrowserData = new ext_ead::www::ImeData; + mpAPScanThread = new APScanThread(); + mpUSBAPThread = new USBAPThread(); + ncd::NCDSetting::init(); + parental::Parental::init(); + + mpAOSSThread = new AOSSThread(getSceneHeap()); + mAOSSState = 0; + mpRakuRakuThread = new RakuRakuThread(getSceneHeap()); + mRakuState = 0; + + www::wiisetting::initWiiSetting(); + initWiiSettingData(); + initString(); + www::wiisetting::setStringBuf(mpStringBuffer); + OSInitMessageQueue(&mFuncMessageQueue, mFuncMessages, 5); + www::wiisetting::setMsgQueue(&mFuncMessageQueue); + + mpMem1BrowserBuffer = getSceneHeap()->alloc(0x1000, 0x20); + mpMem2BrowserBuffer = getSceneHeap()->alloc(0x800, 4); + memset(mpMem2BrowserBuffer, 0, 0x800); + mpBrowserStringBuffer = getSceneHeap()->alloc(0x79, 4); + memset(mpBrowserStringBuffer, 0, 0x79); + + mpEventHandler = new APEvent(this); + mpPaneManager = new gui::PaneManager(mpEventHandler, mpMainLayout->getDrawInfo(), NULL, NULL, true); + mpPaneManager->setupScene(mpMainLayout); + mpPaneManager->setAllComponentTriggerTarget(false); + + for (int index = 0; index < 4; index++) { + mpPaneManager->setTriggerTarget(mpMainLayout->FindPaneByName(sSettingAPButtonNames[index]), true); + } + for (int index = 0; index < 2; index++) { + mpPaneManager->setTriggerTarget(mpMainLayout->FindPaneByName(sSettingArrowNames[index]), true); + } + + TPLBind(reinterpret_cast(static_cast(mpBackgroundTPLFile)->getBuffer())); + u32 elapsed = OSGetTick() - mPrepareTick; + OSReport("*** prepare costs: %dms\n", elapsed / (OS_TIMER_CLOCK / 1000)); + mPrepareTick = OSGetTick(); + } + + void Setting::createBrowser() { + EGG::Heap* mem1Heap = System::createMem1AppHeap(); + u32 mem1Size = mem1Heap->getAllocatableSize(4); + EGG::Heap* mem2Heap = System::getMem2App(); + u32 mem2Size = mem2Heap->getAllocatableSize(4) - 0x80000; + mem1Buffer_ = System::createMem1AppHeap()->alloc(mem1Size, 4); + mem2Buffer_ = mem2Heap->alloc(mem2Size, 4); + OSReport("Setting Scene: mem1: %d mem2: %d\n", mem1Size, mem2Size); + + nw4r::ut::Rect projection16x9; + nw4r::ut::Rect projection4x3; + System::getProjectionRect16x9(&projection16x9); + System::getProjectionRect4x3(&projection4x3); + int width = projection16x9.right - projection16x9.left; + int height = projection16x9.bottom - projection16x9.top; + + const char* urlFormats[] = {"marc:%s/%s/", "file:dvd/html/IPLSetting/%s/%s/"}; + const char* pagePaths[] = { + "index01.html", "Internet/Internet_index.html", "Setup/startup_index1.html", + "Update/Update_index.html", "index02.html", "Setup/ScreenSave.html", + "Country/US_Country_flame.html", + }; + const char* pageNames[] = {"Calendar", "Parental_Control", "Internet", "Wiiconnect24"}; + const char* regionCodes[] = {"JP/JP", "FIX/US", "EU/EU", "TW/TW", "KR/KR", "CN/CN"}; + const char* languageCodes[] = {"JPN", "ENG", "GER", "FRA", "SPA", "ITA", "DUT", "CHN", "KOR"}; + + char basePath[100]; + char browserPath[100]; + memset(basePath, 0, sizeof(basePath)); + memset(browserPath, 0, sizeof(browserPath)); + strcpy(basePath, urlFormats[0]); + int pageIndex = mInitialArgument; + if (pageIndex < 0 || pageIndex >= 7) { + pageIndex = 0; + } + strcat(basePath, pagePaths[pageIndex]); + + int regionIndex = 1; + char productArea = SCGetProductArea(); + if (productArea >= 0 && productArea < 4) { + regionIndex = productArea > 2 ? 2 : 0; + } else if (productArea == 6) { + regionIndex = 4; + } else if (productArea == 11) { + regionIndex = 5; + } else if (productArea >= 7 && productArea < 11) { + regionIndex = 2; + } + + if (mInitialArgument == ARG_UNK_5) { + snprintf(browserPath, sizeof(browserPath), basePath, regionCodes[regionIndex], + languageCodes[System::getLanguage()], pagePaths[pageIndex]); + } else if (mInitialArgument == ARG_UNK_6) { + int directPage = 0; + for (int index = 0; index < 4; index++) { + if (strstr(mpStringBuffer->netSettingArg, pageNames[index]) != NULL) { + directPage = index; + break; + } + } + if (directPage == 0) { + snprintf(browserPath, sizeof(browserPath), basePath, regionCodes[regionIndex], + languageCodes[System::getLanguage()], "index01.html"); + } else if (directPage == 1) { + snprintf(browserPath, sizeof(browserPath), basePath, regionCodes[regionIndex], + languageCodes[System::getLanguage()], "index02.html"); + } else { + snprintf(browserPath, sizeof(browserPath), basePath, regionCodes[regionIndex], + languageCodes[System::getLanguage()], "index03.html"); + } + } else { + snprintf(browserPath, sizeof(browserPath), basePath, regionCodes[regionIndex], + languageCodes[System::getLanguage()]); + } + + OSReport("***********************************\n"); + OSReport(" RSO PLACED : %p %d\n", static_cast(mpWWWLibraryFile)->getBuffer(), + static_cast(mpWWWLibraryFile)->getLength()); + ICInvalidateRange(static_cast(mpWWWLibraryFile)->getBuffer(), + static_cast(mpWWWLibraryFile)->getLength()); + ext_ead::www::SurfaceManager::CreateManager(width, height, width, height, mem1Buffer_, mem1Size, + mem2Buffer_, mem2Size, + static_cast(mpWWWLibraryFile)->getBuffer(), + browserPath); + ext_ead::www::SurfaceManager::RegisterArcFile(static_cast(mpWWWArchiveFile)->getBuffer()); + ext_ead::www::SurfaceManager::RegisterIniFile(static_cast(mpSettingHTMLFile)->getBuffer(), + static_cast(mpSettingHTMLFile)->getLength()); + ext_ead::www::SurfaceManager::RegisterFontFile(0, static_cast(mpFontFile)->getBuffer(), + static_cast(mpFontFile)->getLength()); + ext_ead::www::SurfaceManager::StartThread(); + } + + void Setting::initDirectUrl() { + if (mInitialArgument != ARG_UNK_6) { + return; + } + const char* settingArgument = System::getNetSettingArg(); + if (settingArgument != NULL) { + memcpy(mpStringBuffer->netSettingArg, settingArgument, 0x80); + } + } + + void Setting::initString() { + mpStringBuffer = reinterpret_cast(getSceneHeap()->alloc(0x64e, 4)); + OSReport("HTML String Alloc Size:%d\n", 0x64e); + memset(mpStringBuffer, 0, 0x64e); + memset(unk_0x938, 0, 0x202); + initNickName(); + initSecurityKey(); + initSSID(); + initIP(); + initDNS(); + initProxy(); + initBasic(); + initMTU(); + initSecA(); + initVersion(); + initDirectUrl(); + } + + FaderSceneCommand Setting::calcFadein() { + if (System::hasCreatedAfter() && mBrowserCreated == 0) { + mBrowserCreated = 1; + createBrowser(); + OSReport("............browser created\n"); + } else if (mBrowserCreated == 0) { + OSReport("wait first init\n"); + return FADER_SCN_CONTINUE; + } + + ext_ead::www::SurfaceManager* surfaceManager = ext_ead::www::SurfaceManager::GetInstance(); + ext_ead::www::BrowserThread* browserThread = surfaceManager->GetBrowserThread(); + if (browserThread != NULL && browserThread->GetTextureBuffer(0, NULL) != NULL && System::hasCreatedAfter()) { + mKeyboardState = *System::getKeyboard()->getState(); + System::getFader()->fadeIn(); + mCreatePageTime = OSGetTime(); + OSReport("*** create page costs: %dms\n", + (OSGetTick() - mPrepareTick) / (OS_TIMER_CLOCK / 1000)); + return FADER_SCN_NEXT; + } + return FADER_SCN_CONTINUE; + } + + void Setting::updateController_() { + nw4r::ut::Rect projection; + System::getProjectionRect4x3(&projection); + + if (isAnimating()) { + return; + } + + controller::Interface* youngController = System::getYoungController(); + ext_ead::www::BrowserThread::CmdPacket packet; + + if (youngController != NULL) { + if (unk_0xB9C < 10 || mpStringBuffer->netSettingArg[0] != 0) { + packet.data.controller.irX = -1000.0f; + packet.data.controller.irY = -1000.0f; + packet.data.controller.btnHold = 0; + packet.data.controller.btnTrigger = 0; + packet.data.controller.btnRelease = 0; + } else { + packet.data.controller.irX = youngController->getDpdProjectionPos().x - projection.left; + packet.data.controller.irY = youngController->getDpdProjectionPos().y - projection.top; + u32 classicHold = youngController->getClassicHoldFlag(); + u32 classicTrigger = youngController->getClassicTrigFlag(); + u32 classicRelease = youngController->getClassicReleaseFlag(); + packet.data.controller.btnHold = (classicHold << 16) | youngController->getHoldFlag(); + packet.data.controller.btnTrigger = (classicTrigger << 16) | youngController->getTrigFlag(); + packet.data.controller.btnRelease = (classicRelease << 16) | youngController->getReleaseFlag(); + } + + packet.type = 0; + if (mKeyboardState.type == textinput::MemoManager::ST_Hidden && unk_0x74 == 0) { + ext_ead::www::SurfaceManager::GetInstance()->GetBrowserThread()->SendUIEvent(&packet); + } + } else { + packet.data.controller.irX = -1000.0f; + packet.data.controller.irY = -1000.0f; + packet.data.controller.btnHold = 0; + packet.data.controller.btnTrigger = 0; + packet.data.controller.btnRelease = 0; + packet.type = 0; + ext_ead::www::SurfaceManager::GetInstance()->GetBrowserThread()->SendUIEvent(&packet); + } + } + + void Setting::changeVideoMode() { + setSE(); + VISetBlack(TRUE); + VIFlush(); + VIWaitForRetrace(); + System::resetFrameworkRenderMode(); + + u32 startTick = OSGetTick(); + while ((OSGetTick() - startTick) / (OS_TIMER_CLOCK / 1000) < 0x67c) { + VIWaitForRetrace(); + } + + mAspectRatio = SCGetAspectRatio(); + mProgressiveMode = SCGetProgressiveMode(); + mEuRgb60Mode = SCGetEuRgb60Mode(); + unk_0xB94 = 0; + + VISetBlack(FALSE); + VIFlush(); + VIWaitForRetrace(); + + if (static_cast(System::getRegion()) == 2) { + if (mEuRgb60Mode == 0) { + *reinterpret_cast(0x800000cc) = 1; + } else { + *reinterpret_cast(0x800000cc) = 5; + } + } + + while (mpSecondAnimation->state == 1 || mpFirstAnimation->state == 1) { + mpChangeLayout->calc(); + } + + mState = 20; + unk_0xB9C = 10; + } + + bool Setting::isInitialSequenceExit(const controller::Interface* input) { + u32 connectedMask = utility::wpad::getWpadConnectedMask(); + if (input->downTrg(0x100800) || + ((OSGetTime() - mCreatePageTime) / (OS_TIMER_CLOCK / 1000) >= 500 && + connectedMask != unk_0xBA8 && + utility::wpad::isIncreaseConnectedWpad(unk_0xBA8, connectedMask))) { + return true; + } + + if (connectedMask != unk_0xBA8) { + unk_0xBA8 = connectedMask; + } + return false; + } + + bool Setting::updateScreenMode() { + if (unk_0x91C[2] != 0) { + if (unk_0xB94 == 0) { + if (mEuRgb60Mode == SCGetEuRgb60Mode()) { + if (mProgressiveMode != SCGetProgressiveMode()) { + unk_0xB94 = 2; + } + } else { + unk_0xB94 = 3; + } + + if (unk_0xB94 != 0 && unk_0xB94 != 1) { + System::getFader()->fadeOut(); + mState = 0; + return true; + } + } + } else if (unk_0xB94 == 1 && unk_0x74 == 8) { + System::getFader()->fadeOut(); + mState = 0; + unk_0x92C = 0; + unk_0x74 = 0; + return true; + } + + if (unk_0xB94 == 1) { + if (System::getFader()->getStatus() == EGG::Fader::PREPARE_IN) { + System::getDialog()->terminate(); + SCSetAspectRatio(mAspectRatio & 0xff); + SCFlush(); + if (System::getDialog()->getLastResult() < 0) { + mState = 0; + return true; + } + + changeVideoMode(); + www::wiisetting::setStringBuf(mpStringBuffer); + System::getFader()->fadeIn(); + } else { + mState = 0; + return true; + } + } else if (unk_0xB94 > 0 && unk_0xB94 < 4) { + if (System::getFader()->getStatus() == EGG::Fader::PREPARE_IN) { + changeVideoMode(); + System::getFader()->fadeIn(); + } else { + mState = 0; + return true; + } + } + + return false; + } + + FaderSceneCommand Setting::calcNormal() { + if (unk_0x5C == 0) { + getFuncMsgQ(); + controller::Interface* input = System::getYoungController(); + + ++mState; + if (mState > 20) { + mState = 20; + } + if (unk_0xB9C > 0) { + ++unk_0xB9C; + } + if (unk_0xB9C > 10) { + unk_0xB9C = 10; + } + if (updateScreenMode()) { + return FADER_SCN_CONTINUE; + } + + if (input != NULL) { + if (input->downTrg(0x100800) && mpWiiSettingData->data[0x12] == 0x1e && + unk_0x92C > 0x1e && unk_0x92C < 0x78) { + unk_0x92C = 0x78; + www::wiisetting::setFuncResult(1); + mpWiiSettingData->data[0x37] = 1; + setSE(); + unk_0xB9C = 0; + } + if (isInitialSequenceExit(input) && mpWiiSettingData->data[0x12] == 0x1f) { + snd::getSystem()->startSE("WIPL_SE_DECIDE"); + www::wiisetting::setFuncResult(1); + mpWiiSettingData->data[0x12] = 0; + } + } + + if (unk_0xBAC == 0 && unk_0xB9C == 10 && mpStringBuffer->netSettingArg[0] != 0) { + www::wiisetting::setFuncResult(1); + unk_0xBAC = 1; + } + + if (System::getAspectRatio()) { + updateController_(); + } + + ext_ead::www::BrowserThread* browserThread = + ext_ead::www::SurfaceManager::GetInstance()->GetBrowserThread(); + if (browserThread->ReceiveWindowEvent(mpBrowserData)) { + if (mpBrowserData->unk_0x00 == 0) { + OSReport("IME Created "); + if (mpBrowserData->text != NULL) { + OSReport("initKeyboard %s\n"); + OSReport("initKeyboard %d\n", mpWiiSettingData->data[0x11]); + if (mpWiiSettingData->data[0x11] == 0) { + browserThread->CommitIme(mpBrowserData, mpBrowserData->text); + browserThread->DisposeImeData(mpBrowserData); + } else { + unk_0x74 = 1; + initKeyboard(mpBrowserData->text); + } + } else { + OSReport("NULL ptr\n"); + } + } else { + OSReport("Other Event\n"); + } + } + } + + switch (unk_0x74) { + case 1: + calcKeyboard(); + break; + case 2: + if (System::getDialog()->getLastResult() >= 0) { + unk_0xB9C = 1; + unk_0x74 = 0; + mIsResetAcceptable = 1; + } + break; + case 3: + if (System::getDialog()->getLastResult() == 1) { + if (unk_0xB9C == 0) { + www::wiisetting::setFuncResult(1); + } else if (www::wiisetting::getFuncResult() == 0) { + unk_0x74 = 0; + } + unk_0xB9C = 1; + } else if (System::getDialog()->getLastResult() == 2) { + if (unk_0xB9C == 0) { + www::wiisetting::setFuncResult(2); + } else if (www::wiisetting::getFuncResult() == 0) { + unk_0x74 = 0; + } + unk_0xB9C = 1; + } + break; + case 4: + mpWiiSettingData->data[0x12] = 1; + if (System::getHomeButtonMenu()->disable() && + System::getDialog()->getLastResult() >= 0) { + unk_0x74 = 0; + } + break; + case 5: + if (System::getScene(0x1b) == NULL) { + if (unk_0x91C[3] == 1) { + unk_0x74 = 0; + unk_0x91C[3] = 0; + resetFuncMsgQ(); + if (mpWiiSettingFlag->smthMsgData != 'O') { + unk_0xB9C = 1; + } + } + } else { + unk_0x91C[3] = 1; + scene::ParentalDialog* parentalDialog = + static_cast(System::getScene(0x1b)); + scene::ParentalDialog::Result result = parentalDialog->getResult(); + if (result == scene::ParentalDialog::RESULT_OVER_ATTEMPTS) { + www::wiisetting::setFuncResult(2); + } else if (result == scene::ParentalDialog::RESULT_SUCCESS) { + unk_0x74 = 6; + www::wiisetting::setFuncResult(1); + } else if (result > scene::ParentalDialog::RESULT_OVER_ATTEMPTS && + result <= scene::ParentalDialog::RESULT_CANCELLED) { + www::wiisetting::setFuncResult(2); + } + } + break; + case 6: + if (System::getScene(0x1b) == NULL) { + unk_0x91C[3] = 0; + if (mpWiiSettingFlag->smthMsgData == 'O') { + if (!ncd::NCDSetting::getEnableFlag()) { + System::getDialog()->callBtn2(System::getRegion() == 2 ? 0x174 : 0x170, + 0x146, 0x25); + unk_0x74 = 9; + } else if (SCGetEULA() == 0) { + System::getDialog()->callBtn2(System::getRegion() == 2 ? 0x175 : 0x172, + 0x2e, 0x25); + unk_0x74 = 0xe; + } else { + www::wiisetting::setFuncResult(6); + unk_0x74 = 0; + resetFuncMsgQ(); + } + } else { + unk_0x74 = 0; + } + } + break; + case 7: + if (System::getDialog()->getLastResult() == 1) { + www::wiisetting::setFuncResult(1); + SCSetWCFlags(SCGetWCFlags() & 0xfffffffe); + SCIdleModeInfo idleMode = {0, 0}; + SCSetIdleMode(&idleMode); + System::getNwc24Manager()->enableLedNotification(TRUE); + SCSetEULA(0); + ncd::NCDSetting::adjustNWC24Flag(); + parental::Parental::setCountry(mpWiiSettingData->data[0x3c]); + parental::Parental::clear(); + System::reloadDownloadTask(); + unk_0x74 = 0; + } else if (System::getDialog()->getLastResult() == 2) { + www::wiisetting::setFuncResult(2); + unk_0x74 = 0; + unk_0xB9C = 1; + } + break; + case 8: + ++unk_0x92C; + if (unk_0x92C == 0xb4) { + unk_0xB94 = 1; + unk_0x92C = 0; + } + break; + case 9: + if (System::getDialog()->getLastResult() == 1) { + if (mpWiiSettingFlag->smthMsgData == 'O') { + www::wiisetting::setFuncResult(5); + resetFuncMsgQ(); + } else { + www::wiisetting::setFuncResult(6); + } + unk_0x74 = 0; + } else if (System::getDialog()->getLastResult() == 2) { + if (mpWiiSettingFlag->smthMsgData == 'O') { + if (unk_0xB9C == 0) { + www::wiisetting::setFuncResult(2); + } else if (www::wiisetting::getFuncResult() == 0) { + unk_0x74 = 0; + resetFuncMsgQ(); + } + unk_0xB9C = 1; + } else { + unk_0x74 = 0; + www::wiisetting::setFuncResult(2); + } + } + break; + case 10: + if (System::getDialog()->getLastResult() == 2) { + System::getDialog()->callBtn1(0x172, 1); + unk_0x74 = 0xb; + SCSetWCFlags(SCGetWCFlags() & 0xfffffffe); + SCIdleModeInfo idleMode = {0, 0}; + SCSetIdleMode(&idleMode); + System::getNwc24Manager()->enableLedNotification(TRUE); + SCSetEULA(0); + ncd::NCDSetting::adjustNWC24Flag(); + SCFlush(); + } else if (System::getDialog()->getLastResult() == 1) { + mProfileIDMode = 0; + unk_0xB9C = 1; + unk_0x74 = 0; + } + break; + case 0xb: + if (System::getDialog()->getLastResult() >= 0) { + mProfileIDMode = 10; + mpWiiSettingFlag->smthMsgData = 0x54; + unk_0x74 = 0; + } + break; + case 0xc: + if (System::getDialog()->getLastResult() == 2) { + SCSetWCFlags(SCGetWCFlags() & 0xfffffffe); + SCIdleModeInfo idleMode = {0, 0}; + SCSetIdleMode(&idleMode); + System::getNwc24Manager()->enableLedNotification(TRUE); + SCSetEULA(0); + ncd::NCDSetting::adjustNWC24Flag(); + SCFlush(); + System::getDialog()->callBtn1(0x170, 0x2e); + unk_0x74 = 9; + } else if (System::getDialog()->getLastResult() == 1) { + unk_0xB9C = 1; + unk_0x74 = 0; + } + break; + case 0xd: + if (System::getDialog()->getLastResult() == 1) { + www::wiisetting::setFuncResult(8); + unk_0x74 = 0; + } else if (System::getDialog()->getLastResult() == 2) { + www::wiisetting::setFuncResult(7); + unk_0x74 = 0; + } + break; + case 0xe: + if (System::getDialog()->getLastResult() == 1) { + mpWiiSettingFlag->smthMsgData = 0x55; + unk_0x74 = 0; + } else if (System::getDialog()->getLastResult() == 2) { + if (unk_0xB9C == 0) { + www::wiisetting::setFuncResult(2); + } else if (www::wiisetting::getFuncResult() == 0) { + resetFuncMsgQ(); + unk_0x74 = 0; + } + unk_0xB9C = 1; + } + break; + case 0x11: + calcSafeMode(); + break; + } + + u8 action = mpWiiSettingData->data[0x12]; + if (action != 0) { + if (action == 0x1e) { + ++unk_0x92C; + if (unk_0x92C == 1) { + System::getDialog()->callBtn1(0x1bf, 0x2e); + unk_0x74 = 4; + } else if (unk_0x92C == 3) { + TPLBind(NULL); + } else if (unk_0x92C == 0x55 || unk_0x92C == 0x5a) { + BOOL interruptLevel = OSDisableInterrupts(); + WPADSetSensorBarPower(unk_0x92C == 0x5a); + OSRestoreInterrupts(interruptLevel); + if (unk_0x92C == 0x5a) { + unk_0x92C = 0x1e; + } + } else if (unk_0x92C == 0x96) { + BOOL interruptLevel = OSDisableInterrupts(); + WPADSetSensorBarPower(TRUE); + OSRestoreInterrupts(interruptLevel); + System::getHomeButtonMenu()->enable(); + mpWiiSettingData->data[0x12] = 0; + TPLBind(reinterpret_cast( + static_cast(mpBackgroundTPLFile)->getBuffer())); + unk_0x92C = 0; + } + } else if (action < 0x1f) { + initHTMLText(); + initMessage(); + } + } + + if (mpWiiSettingData->data[0x36] != 0) { + calcSetting(); + } + + switch (mpWiiSettingFlag->smthMsgData) { + case 1: + resetFuncMsgQ(); + waitStart(); + createChildScene(0x19, this, NULL, NULL); + break; + case 4: + resetAP(); + initAP(); + mpWiiSettingFlag->smthMsgData = 2; + case 2: + case 3: + scanAP(); + break; + case 5: + resetAP(); + break; + case 6: + initAP(); + resetFuncMsgQ(); + break; + case 7: + redrawAP(); + break; + case 9: + setNUP(); + break; + case 0x17: + parental::Parental::clearMiss(); + case 'Z': + System::getHomeButtonMenu()->enable(); + resetFuncMsgQ(); + break; + case 0x18: + ncd::NCDSetting::write(); + case ']': + mIsResetAcceptable = 0; + resetFuncMsgQ(); + break; + case 0x1a: + System::getDialog()->callBtn2(System::getRegion() == 2 ? 0x160 : 0x15f, + 0x2e, 0x13b); + unk_0x74 = 3; + resetFuncMsgQ(); + break; + case 0x1c: + if (mAspectRatio != mpWiiSettingData->data[6]) { + mAspectRatio = mpWiiSettingData->data[6]; + if (mAspectRatio == 1) { + System::getDialog()->callBtn0(0x1bd, 0, false); + } else if (mAspectRatio == 0) { + System::getDialog()->callBtn0(0x1c9, 0, false); + } + unk_0x74 = 8; + } + resetFuncMsgQ(); + break; + case 0x1d: + case 'M': + case 'N': + if (action == 0x1d || calcSafeMode()) { + if (!parental::Parental::checkFlags()) { + www::wiisetting::setFuncResult(1); + if (mpWiiSettingFlag->smthMsgData == 'N') { + unk_0x74 = 6; + } + } else { + createChildScene(0x1b, this, NULL, reinterpret_cast(1)); + unk_0x74 = 5; + } + if (mpWiiSettingFlag->smthMsgData == 0x1d || + mpWiiSettingFlag->smthMsgData == 'M') { + resetFuncMsgQ(); + } else { + mpWiiSettingFlag->smthMsgData = 'O'; + } + } + break; + case 0x1e: + memset(mpMem2BrowserBuffer, 0, 0x800); + memset(mpBrowserStringBuffer, 0, 0x79); + mpWiiSettingFlag->smthMsgData = 0x23; + case '#': + setUSBAP(); + break; + case 0x1f: + cancelUSBAP(); + break; + case ' ': + case '!': + case '"': + AOSSProcess(); + break; + case '(': + case ')': + case '*': + case '+': + case ',': + RakuProcess(); + break; + case '4': + if (System::getHomeButtonMenu()->disable() && unk_0x5C == 0) { + controller::Interface* youngController = System::getYoungController(); + if (youngController != NULL && youngController->downTrg(0x100800)) { + resetFuncMsgQ(); + System::getHomeButtonMenu()->enable(); + www::wiisetting::setFuncResult(5); + } + } + break; + case 'P': + SCSetLanguage(mpWiiSettingData->data[0x30]); + if (SCGetConfigDoneFlag() == 0 && SCGetConfigDoneFlag2() == 0 && + System::getRegion() == 2) { + if (mpWiiSettingData->data[0x30] == 3) { + mpWiiSettingData->data[0x3c] = 0x68; + parental::Parental::setCountry(0x68); + } else { + mpWiiSettingData->data[0x3c] = 0x40; + parental::Parental::setCountry(0x40); + } + } + SCFlush(); + System::getKeyboard()->setLanguage(SCGetLanguage()); + parental::Parental::init(); + System::reloadDownloadTask(); + resetFuncMsgQ(); + break; + case 'Q': + snd::getSystem()->muteOffBGM(0x5a); + resetFuncMsgQ(); + break; + case 'R': + snd::getSystem()->muteOnBGM(0x5a); + resetFuncMsgQ(); + break; + case 'S': + if (mInitialArgument == 2 || mInitialArgument == 5) { + parental::Parental::setCountry(mpWiiSettingData->data[0x3c]); + parental::Parental::clear(); + www::wiisetting::setFuncResult(1); + } else if (mpWiiSettingData->data[0x3c] == parental::Parental::getCountry()) { + www::wiisetting::setFuncResult(1); + } else { + System::getDialog()->callBtn2(0x1c4, 0x2e, 0x13b); + unk_0x74 = 7; + } + resetFuncMsgQ(); + break; + case 'T': + setUpdate_(); + break; + case 'U': + if (unk_0x7C == 0) { + unk_0x7C = 1; + } + setUseEULA_(); + break; + case 'V': + mProfileIDMode = 9; + setUpdate_(); + break; + case 'W': + setUseEULA_(); + break; + case 'X': + if (unk_0x7C == 0) { + unk_0x7C = 2; + } + setUseEULA_(); + break; + case 'Y': + mProfileIDMode = 2; + mpWiiSettingFlag->smthMsgData = 0x54; + break; + case '[': + if (System::getHomeButtonMenu()->disable()) { + resetFuncMsgQ(); + } + break; + case '\\': + mIsResetAcceptable = 1; + resetFuncMsgQ(); + break; + case '^': + System::getHomeButtonMenu()->enable(); + mIsResetAcceptable = 1; + resetFuncMsgQ(); + break; + case '_': + if (System::getHomeButtonMenu()->disable()) { + mIsResetAcceptable = 0; + resetFuncMsgQ(); + } + break; + case 'd': + createChildScene(0x1d, this, NULL, reinterpret_cast(2)); + resetFuncMsgQ(); + waitStart(); + break; + case 'e': + unk_0x74 = 0xf; + ++unk_0x92C; + if (unk_0x92C >= 100) { + mIsResetAcceptable = 1; + System::getResetHandler()->reset(); + resetFuncMsgQ(); + } + break; + case 'f': + unk_0x74 = 0x10; + ++unk_0x92C; + if (unk_0x92C >= 100) { + mIsResetAcceptable = 1; + System::getResetHandler()->powerOff(); + resetFuncMsgQ(); + } + break; + case 'g': + if (calcSafeMode()) { + www::wiisetting::setFuncResult(1); + resetFuncMsgQ(); + } + break; + } + + if (mpWiiSettingData->data[0x37] != 0 || mpWiiSettingData->data[0x38] != 0) { + setSE(); + } + if (mpWiiSettingData->data[0x39] != 0) { + return FADER_SCN_NEXT; + } + + mpChangeLayout->calc(); + mpMainLayout->calc(); + mpWaitLayout->calc(); + unk_0x91C[2] = 0; + return FADER_SCN_CONTINUE; + } + + FaderSceneCommand Setting::calcFadeout() { + if (System::getFader()->getStatus() == EGG::Fader::PREPARE_IN) { + if (unk_0x5C == 0) { + unk_0x5C = 1; + ext_ead::www::SurfaceManager::GetInstance()->StopThreadAsync(); + OSReport("!!!!!!!!!!!!! SCFlush !!!!!!!!!!!!!!\n"); + SCFlush(); + } else if (unk_0x7C == 5) { + if (mInitialArgument == 2 || mInitialArgument == 5) { + SCSetConfigDoneFlag(TRUE); + SCSetConfigDoneFlag2(TRUE); + SCSetUpdateType(0); + SCFlush(); + } + + while (WPADGetStatus() != 0 || + System::getBS2Manager()->getIPLState() != bs2::IPL_STATE_8) { + snd::getSystem()->calc(); + System::getBS2Manager()->update(); + VIWaitForRetrace(); + if (WPADGetStatus() != 0) { + OSReport("wait for WPAD\n"); + } + if (System::getBS2Manager()->getIPLState() != bs2::IPL_STATE_8) { + OSReport("wait for BS2\n"); + } + } + + VISetBlack(TRUE); + VIFlush(); + VIWaitForRetrace(); + OSReport("VI Black\n"); + while (!__OSSyncSram()) { + OSReport("sync sram\n"); + } + while (!System::isReceiveScheduleStopped()) { + OSReport("Wait ScheduleStopped\n"); + OSSleepMilliseconds(5); + } + __OSLaunchTitlelForSystem(mUpdateTitleId, 0, NULL); + for (;;) { + OSReport(NULL); + } + } else if (ext_ead::www::SurfaceManager::GetInstance()->IsThreadStopped()) { + OSReport("reserve destroy\n"); + ext_ead::www::SurfaceManager::DisposeManager(); + OSReport("reserve destroy done\n"); + if (mInitialArgument == 2 || mInitialArgument == 5) { + SCSetConfigDoneFlag(TRUE); + SCSetConfigDoneFlag2(TRUE); + SCSetUpdateType(0); + SCFlush(); + reserveAllSceneDestruction(0x1a, NULL); + } else { + System::reloadDownloadTask(); + reserveAllSceneDestruction(0x15, NULL); + } + delete mpBrowserData; + return FADER_SCN_NEXT; + } + } + + return FADER_SCN_CONTINUE; + } + + void Setting::draw() { + if (!System::onDrawLayer(1)) { + return; + } + + if (!mBrowserCreated) { + utility::Graphics::setOrtho(0); + nw4r::ut::Rect background(-1000.0f, -1000.0f, 1000.0f, 1000.0f); + GXColor color = {0, 0, 0, 0xFF}; + utility::Graphics::drawPolygon(background, color); + return; + } + + ext_ead::www::SurfaceManager* surface = ext_ead::www::SurfaceManager::GetInstance(); + if (surface == NULL) { + return; + } + + ext_ead::www::BrowserThread* browser = surface->GetBrowserThread(); + if (browser == NULL || browser->GetTextureBuffer(0, NULL) == NULL) { + return; + } + + WWWRect* wideRect = NULL; + WWWRect* standardRect = NULL; + void* wideBuffer = browser->GetTextureBuffer(1, &wideRect); + void* standardBuffer = browser->GetTextureBuffer(0, &standardRect); + if (wideBuffer == NULL || standardBuffer == NULL) { + return; + } + + if (www::trasition::GetScrollState() != www::trasition::SCROLL_RESET) { + www::trasition::ResetScrollState(); + OSReport("changed %p %p\n", standardBuffer, wideBuffer); + ext_ead::www::Heap::reportLeaHeap(); + } + + nw4r::ut::Rect projection4x3; + nw4r::ut::Rect projection16x9; + System::getProjectionRect4x3(&projection4x3); + System::getProjectionRect16x9(&projection16x9); + + GXTexObj standardTexture; + GXTexObj wideTexture; + GXInitTexObj(&standardTexture, standardBuffer, standardRect->w, standardRect->h, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); + GXInitTexObj(&wideTexture, wideBuffer, wideRect->w, wideRect->h, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); + GXInitTexObjLOD(&standardTexture, GX_LINEAR, GX_LINEAR, 0.0f, 0.0f, 0.0f, GX_FALSE, GX_FALSE, GX_ANISO_1); + GXInitTexObjLOD(&wideTexture, GX_LINEAR, GX_LINEAR, 0.0f, 0.0f, 0.0f, GX_FALSE, GX_FALSE, GX_ANISO_1); + + utility::Graphics::setOrtho(0); + GXColor color = {0xFF, 0xFF, 0xFF, (u8)(mState * 0xFF / 20)}; + utility::Graphics::drawTexture(projection4x3, standardTexture, color, 1); + utility::Graphics::drawTexture(projection16x9, wideTexture, color, 1); + + if (mpWiiSettingData->data[0x12] == 0x1E && unk_0x92C > 3) { + SensitivityDrawing::draw(static_cast(mpBackgroundTPLFile)); + } + + mpChangeLayout->draw(); + mpWaitLayout->draw(); + if (mState == 0xC) { + unk_0xB9C = 1; + } + + if (mpWiiSettingFlag->smthMsgData >= 2 && mpWiiSettingFlag->smthMsgData <= 7) { + u32 left; + u32 top; + u32 width; + u32 height; + GXGetScissor(&left, &top, &width, &height); + GXSetScissor(0, System::getRenderModeObj()->efbHeight / 2 - 0xA4, System::getRenderModeObj()->fbWidth, 0x132); + mpWaitLayout->draw(); + GXSetScissor(left, top, width, height); + } + } + + void Setting::initWiiSettingData() { + mpWiiSettingData = www::wiisetting::getWiiSettingData(); + mpWiiSettingFlag = www::wiisetting::getWiiSettingFlag(); + mpWiiSettingData->data[0x3c] = parental::Parental::getCountry(); + mpWiiSettingData->data[7] = 0x20 - (SCGetDisplayOffsetH() + 0x10); + mpWiiSettingData->data[0xb] = SCGetBtDpdSensibility(); + mpWiiSettingData->data[6] = SCGetAspectRatio(); + mpWiiSettingData->data[0x30] = SCGetLanguage(); + mpWiiSettingData->data[0x2d] = parental::Parental::checkRating(); + } + + void Setting::initHTMLText() { + OSReport("initHTMLText pageId:%d\n", mpWiiSettingData->data[0x12]); + memset(unk_0x938, 0, sizeof(unk_0x938)); + + switch (mpWiiSettingData->data[0x12]) { + case 2: + initNickName(); + break; + case 3: + initSecurityKey(); + break; + case 4: + initSSID(); + break; + case 5: + initIP(); + break; + case 6: + initDNS(); + break; + case 7: + initProxy(); + break; + case 8: + initBasic(); + break; + case 9: + initMTU(); + break; + case 10: + memset(&mpStringBuffer->parentalPass, 0, sizeof(mpStringBuffer->parentalPass)); + break; + case 11: + memset(&mpStringBuffer->parentalRePass, 0, sizeof(mpStringBuffer->parentalRePass)); + break; + case 12: + memset(&mpStringBuffer->parentalJudgePass, 0, sizeof(mpStringBuffer->parentalJudgePass)); + break; + case 13: + initSecA(); + break; + case 14: + memset(&mpStringBuffer->parentalReSecA, 0, sizeof(mpStringBuffer->parentalReSecA)); + break; + case 15: + memset(&mpStringBuffer->masterKey, 0, sizeof(mpStringBuffer->masterKey)); + break; + case 16: + memset(&mpStringBuffer->asterisks, 0, sizeof(mpStringBuffer->asterisks)); + break; + } + } + + void Setting::initMessage() { + OSReport("initMessage pageId:%d\n", mpWiiSettingData->data[0x12]); + mpWiiSettingData->data[0x12] = 0; + } + + void Setting::initKeyboard(const char* text) { + OSReport("initKeyboard formId:%d\n", mpWiiSettingData->data[0x11]); + memset(unk_0x938, 0, sizeof(unk_0x938)); + + int invalidInput = 0; + keyboard::Manager::KeyboardType keyboardType = keyboard::Manager::LETTER; + int rowLimit = 0; + int stringLimit = 0; + int productArea = SCGetProductArea(); + + switch (mpWiiSettingData->data[0x11]) { + case 1: + stringLimit = 10; + rowLimit = 6; + break; + case 2: + if (ncd::NCDSetting::getPrivacyMode() == 1) { + stringLimit = 0x1A; + keyboardType = keyboard::Manager::NORMAL_WITHOUT_LINEFEED; + } else { + stringLimit = 0x40; + keyboardType = keyboard::Manager::NORMAL_WITHOUT_LINEFEED_WITH_SIGN; + } + rowLimit = 7; + break; + case 3: + stringLimit = 0x20; + keyboardType = keyboard::Manager::NORMAL_WITHOUT_LINEFEED; + rowLimit = 7; + break; + case 12: + stringLimit = 0x20; + keyboardType = keyboard::Manager::NORMAL_WITHOUT_LINEFEED; + rowLimit = 7; + break; + case 13: + stringLimit = 0x20; + keyboardType = keyboard::Manager::NORMAL_WITHOUT_LINEFEED; + rowLimit = 7; + break; + case 4: + case 5: + case 6: + case 7: + case 8: + stringLimit = 0xF; + rowLimit = 10; + break; + case 10: + stringLimit = 0xFF; + keyboardType = keyboard::Manager::NUMERIC_WITH_DOT; + rowLimit = 7; + break; + case 11: + case 20: + stringLimit = 5; + rowLimit = 3; + break; + case 14: + case 15: + case 16: + case 17: + stringLimit = 4; + rowLimit = 3; + break; + case 18: + case 19: + stringLimit = 0x20; + keyboardType = keyboard::Manager::NORMAL_WITHOUT_LINEFEED; + rowLimit = productArea == 11 || productArea == 6 ? 13 : 5; + break; + case 22: + stringLimit = 0x40; + keyboardType = keyboard::Manager::NORMAL_WITHOUT_LINEFEED_WITH_SIGN; + rowLimit = 7; + break; + } + + if (mpWiiSettingData->data[0x11] != 13 && mpWiiSettingData->data[0x11] != 2 && + mpWiiSettingData->data[0x11] != 18 && mpWiiSettingData->data[0x11] != 19 && + mpWiiSettingData->data[0x11] != 22) { + utility::CharacterCode::UTF8ToUTF16(reinterpret_cast(unk_0x938), text, 0x101); + } + + size_t textLength = wcslen(reinterpret_cast(unk_0x938)); + OSReport("キーボード: %d %d %d %d\n", rowLimit, stringLimit, keyboardType, textLength); + reinterpret_cast(unk_0x938)[stringLimit] = 0; + + if (mpWiiSettingData->data[0x11] >= 4 && mpWiiSettingData->data[0x11] <= 8) { + invalidInput = checkIPString(reinterpret_cast(unk_0x938)); + } else if ((mpWiiSettingData->data[0x11] > 0 && mpWiiSettingData->data[0x11] < 4) || + (mpWiiSettingData->data[0x11] >= 10 && mpWiiSettingData->data[0x11] <= 20) || + mpWiiSettingData->data[0x11] == 22) { + invalidInput = checkInputString(reinterpret_cast(unk_0x938)); + } + + if (invalidInput != 0) { + memset(unk_0x938, 0, sizeof(unk_0x938)); + } + + keyboard::Manager* keyboardManager = System::getKeyboard(); + if (productArea == 11) { + keyboardManager->memoFrm()->setZiDictionary(keyboardManager->getZiOemDic(), keyboardManager->getZiSystemDic()); + } + + keyboard::Manager::KeyboardSetting setting; + setting.type = keyboardType; + setting.wcString = reinterpret_cast(unk_0x938); + setting.stringLimit = stringLimit; + setting.rowLimit = rowLimit; + keyboardManager->init(); + keyboardManager->start(0, setting); + + if (invalidInput != 0) { + setDefaultBackString(); + } else { + reinterpret_cast(keyboardManager->memoFrm())->setString(reinterpret_cast(unk_0x938)); + } + } + + void Setting::calcKeyboard() { + char* formText; + if (mKeyboardState.iplType == keyboard::Manager::STATE_DISAPPEARING) { + if (mKeyboardState.pressOK) { + onTextInputOK(); + u8 formId = mpWiiSettingData->data[0x11]; + formText = NULL; + switch (formId) { + case 1: + formText = mpStringBuffer->nickname; + break; + case 2: + case 22: + formText = mpStringBuffer->securityKey; + break; + case 3: + formText = mpStringBuffer->securityKey; + break; + case 4: + formText = mpStringBuffer->ip.addr; + break; + case 5: + formText = mpStringBuffer->ip.netmask; + break; + case 6: + formText = mpStringBuffer->ip.gateway; + break; + case 7: + formText = mpStringBuffer->dns1; + break; + case 8: + formText = mpStringBuffer->dns2; + break; + case 10: + formText = mpStringBuffer->proxy.server; + break; + case 11: + formText = mpStringBuffer->proxy.port; + break; + case 12: + formText = mpStringBuffer->proxyBasic.uname; + break; + case 13: + formText = mpStringBuffer->proxyBasic.pass; + break; + case 14: + formText = mpStringBuffer->adjMtu; + break; + case 15: + formText = mpStringBuffer->parentalPass; + break; + case 16: + formText = mpStringBuffer->parentalRePass; + break; + case 17: + formText = mpStringBuffer->parentalJudgePass; + break; + case 18: + formText = mpStringBuffer->parentalSecA; + break; + case 19: + formText = mpStringBuffer->parentalReSecA; + break; + case 20: + formText = mpStringBuffer->masterKey; + break; + } + OSReport("formID:%d %s\n", formId, formText); + if (strlen(formText) == 0) { + formText[0] = 0; + ext_ead::www::SurfaceManager::GetInstance()->GetBrowserThread()->CommitIme(mpBrowserData, formText); + memset(mpStringBuffer->asterisks, 0, sizeof(mpStringBuffer->asterisks)); + } else if (formId == 2 || formId == 22) { + memcpy(mpStringBuffer->asterisks, mpStringBuffer->securityKey, sizeof(mpStringBuffer->securityKey)); + mpStringBuffer->asterisks[0x41] = 0; + u32 index = 0; + while (mpStringBuffer->asterisks[index] != 0) { + mpStringBuffer->asterisks[index++] = '*'; + } + if (index > 0x20) { + mpStringBuffer->asterisks[0x20] = '\n'; + mpStringBuffer->asterisks[index] = '*'; + } + ext_ead::www::SurfaceManager::GetInstance()->GetBrowserThread()->CommitIme(mpBrowserData, mpStringBuffer->asterisks); + } else { + ext_ead::www::SurfaceManager::GetInstance()->GetBrowserThread()->CommitIme(mpBrowserData, formText); + } + } else { + u8 formId = mpWiiSettingData->data[0x11]; + formText = NULL; + switch (formId) { + case 1: + formText = mpStringBuffer->nickname; + break; + case 2: + case 22: + formText = mpStringBuffer->asterisks; + break; + case 3: + formText = mpStringBuffer->securityKey; + break; + case 4: + formText = mpStringBuffer->ip.addr; + break; + case 5: + formText = mpStringBuffer->ip.netmask; + break; + case 6: + formText = mpStringBuffer->ip.gateway; + break; + case 7: + formText = mpStringBuffer->dns1; + break; + case 8: + formText = mpStringBuffer->dns2; + break; + case 10: + formText = mpStringBuffer->proxy.server; + break; + case 11: + formText = mpStringBuffer->proxy.port; + break; + case 12: + formText = mpStringBuffer->proxyBasic.uname; + break; + case 13: + formText = mpStringBuffer->proxyBasic.pass; + break; + case 14: + formText = mpStringBuffer->adjMtu; + break; + case 15: + formText = mpStringBuffer->parentalPass; + break; + case 16: + formText = mpStringBuffer->parentalRePass; + break; + case 17: + formText = mpStringBuffer->parentalJudgePass; + break; + case 18: + formText = mpStringBuffer->parentalSecA; + break; + case 19: + formText = mpStringBuffer->parentalReSecA; + break; + case 20: + formText = mpStringBuffer->masterKey; + break; + } + ext_ead::www::SurfaceManager::GetInstance()->GetBrowserThread()->CommitIme(mpBrowserData, formText); + } + + mpWiiSettingData->data[0x11] = 0; + ext_ead::www::SurfaceManager::GetInstance()->GetBrowserThread()->DisposeImeData(mpBrowserData); + } else if (mKeyboardState.iplType < keyboard::Manager::STATE_VISIBLE) { + u8 formId = mpWiiSettingData->data[0x11]; + if (mKeyboardState.iplType < keyboard::Manager::STATE_APPEARING && + formId != 0 && formId != 9 && formId != 21 && formId <= 22) { + if (System::getKeyboard()->memoMgr()->isVacancy()) { + reinterpret_cast(System::getKeyboard()->memoFrm())->setString(L""); + } else { + setDefaultBackString(); + } + } + } else if (mKeyboardState.iplType < keyboard::Manager::STATE_HIDDEN_AFTER_DISAPPEAR) { + reinterpret_cast(System::getKeyboard()->memoFrm())->setString(L""); + unk_0x74 = 0; + } + + mKeyboardState = *System::getKeyboard()->getState(); + } + + void Setting::calcSetting() { + OSReport("setstring:%d\n", mpWiiSettingData->data[0x36]); + u8 settingId = mpWiiSettingData->data[0x36]; + switch (settingId) { + case 1: + setDisPos(); + break; + case 2: + setNickName(); + break; + case 3: + setSecurityKey(); + break; + case 4: + setSSID(); + break; + case 5: + setIP(); + break; + case 6: + setDNS(); + break; + case 7: + setProxy(); + break; + case 8: + setBasic(); + break; + case 9: + setMTU(); + break; + case 10: + setParePass(); + break; + case 11: + setPareRePass(); + break; + case 12: + setPareJudgePass(); + break; + case 13: + setSecA(); + break; + case 14: + setReSecA(); + break; + case 15: + setMasterKey(); + break; + } + mpWiiSettingData->data[0x36] = 0; + } + + void Setting::onTextInputOK() { + OSReport("Keyboard Confirm:%d\n", mpWiiSettingData->data[0x11]); + wcslen(mKeyboardState.wcString); + + memset(unk_0x938, 0, sizeof(unk_0x938)); + u8 convertedText[0x302]; + memset(convertedText, 0, sizeof(convertedText)); + memcpy(unk_0x938, mKeyboardState.wcString, sizeof(unk_0x938)); + u8 formId = mpWiiSettingData->data[0x11]; + + if (formId == 2 || formId == 22) { + utility::CharacterCode::UTF16ToANSI(convertedText, reinterpret_cast(unk_0x938), 0x100); + memset(convertedText + wcslen(reinterpret_cast(unk_0x938)), 0, + 0x100 - wcslen(reinterpret_cast(unk_0x938))); + memcpy(mpStringBuffer->securityKey, convertedText, sizeof(mpStringBuffer->securityKey)); + return; + } + + if (formId == 18 || formId == 19) { + adjustSecA(reinterpret_cast(unk_0x938)); + } + utility::CharacterCode::UTF16ToUTF8(reinterpret_cast(convertedText), + reinterpret_cast(unk_0x938), 0x301); + + switch (mpWiiSettingData->data[0x11]) { + case 1: + memcpy(mpStringBuffer->nickname, convertedText, sizeof(mpStringBuffer->nickname)); + break; + case 3: + memcpy(mpStringBuffer->ssid, convertedText, sizeof(mpStringBuffer->ssid)); + break; + case 4: + memcpy(mpStringBuffer->ip.addr, convertedText, sizeof(mpStringBuffer->ip.addr)); + break; + case 5: + memcpy(mpStringBuffer->ip.netmask, convertedText, sizeof(mpStringBuffer->ip.netmask)); + break; + case 6: + memcpy(mpStringBuffer->ip.gateway, convertedText, sizeof(mpStringBuffer->ip.gateway)); + break; + case 7: + memcpy(mpStringBuffer->dns1, convertedText, sizeof(mpStringBuffer->dns1)); + break; + case 8: + memcpy(mpStringBuffer->dns2, convertedText, sizeof(mpStringBuffer->dns2)); + break; + case 10: + memcpy(mpStringBuffer->proxy.server, convertedText, sizeof(mpStringBuffer->proxy.server)); + break; + case 11: + memcpy(mpStringBuffer->proxy.port, convertedText, sizeof(mpStringBuffer->proxy.port)); + break; + case 12: + memcpy(mpStringBuffer->proxyBasic.uname, convertedText, sizeof(mpStringBuffer->proxyBasic.uname)); + break; + case 13: + memcpy(mpStringBuffer->proxyBasic.pass, convertedText, sizeof(mpStringBuffer->proxyBasic.pass)); + break; + case 15: + memcpy(mpStringBuffer->parentalPass, convertedText, sizeof(mpStringBuffer->parentalPass)); + break; + case 16: + memcpy(mpStringBuffer->parentalRePass, convertedText, sizeof(mpStringBuffer->parentalRePass)); + break; + case 17: + memcpy(mpStringBuffer->parentalJudgePass, convertedText, sizeof(mpStringBuffer->parentalJudgePass)); + break; + case 18: + memcpy(mpStringBuffer->parentalSecA, convertedText, sizeof(mpStringBuffer->parentalSecA)); + break; + case 19: + memcpy(mpStringBuffer->parentalReSecA, convertedText, sizeof(mpStringBuffer->parentalReSecA)); + break; + case 20: + memcpy(mpStringBuffer->masterKey, convertedText, sizeof(mpStringBuffer->masterKey)); + break; + case 14: + memcpy(mpStringBuffer->adjMtu, convertedText, sizeof(mpStringBuffer->adjMtu)); + break; + } + } + + void Setting::initNickName() { + bool nicknameExists = SCGetOwnerNickName(reinterpret_cast(mSettingData)) != 0; + OSReport("SCGetOwnerNickName:%d\n", nicknameExists); + if (nicknameExists) { + SCOwnerNickname* ownerNickname = reinterpret_cast(mSettingData); + memcpy(unk_0x938, mSettingData, ownerNickname->length * sizeof(wchar_t)); + } + memset(mpStringBuffer->nickname, 0, sizeof(mpStringBuffer->nickname)); + utility::CharacterCode::UTF16ToUTF8(mpStringBuffer->nickname, + reinterpret_cast(unk_0x938), + sizeof(mpStringBuffer->nickname)); + } + + void Setting::initSecurityKey() { + memset(mpStringBuffer->securityKey, 0, sizeof(mpStringBuffer->securityKey)); + s32 privacyMode = ncd::NCDSetting::getNCDPrivacyMode(); + size_t keyLength; + if (privacyMode != 2) { + if (privacyMode < 2) { + if (privacyMode == 0) { + keyLength = 0; + } else { + keyLength = 5; + } + } else if (privacyMode < 7 && privacyMode > 3) { + keyLength = 64; + } else { + keyLength = 0; + } + } else { + keyLength = 13; + } + if (keyLength != 0) { + memcpy(mpStringBuffer->securityKey, ncd::NCDSetting::getPrivacy(), keyLength); + } + OSReport("privacy : %s\n", ncd::NCDSetting::getPrivacy()); + } + + void Setting::initSSID() { + memset(mpStringBuffer->ssid, 0, sizeof(mpStringBuffer->ssid)); + u16 stringLength = ncd::NCDSetting::getSSID()->ssidLength; + utility::CharacterCode::ANSIToUTF8(mpStringBuffer->ssid, ncd::NCDSetting::getSSID()->ssid, stringLength); + u16 reportLength = ncd::NCDSetting::getSSID()->ssidLength; + OSReport("initHTMLText initString:%s length:%d\n", ncd::NCDSetting::getSSID()->ssid, reportLength); + } + + void Setting::initIP() { + memset(mpStringBuffer->ip.addr, 0, sizeof(mpStringBuffer->ip.addr)); + memset(mpStringBuffer->ip.netmask, 0, sizeof(mpStringBuffer->ip.netmask)); + memset(mpStringBuffer->ip.gateway, 0, sizeof(mpStringBuffer->ip.gateway)); + convertIP(mpStringBuffer->ip.addr, ncd::NCDSetting::getIP()->addr); + convertIP(mpStringBuffer->ip.netmask, ncd::NCDSetting::getIP()->netmask); + convertIP(mpStringBuffer->ip.gateway, ncd::NCDSetting::getIP()->gateway); + } + + void Setting::initDNS() { + memset(mpStringBuffer->dns1, 0, sizeof(mpStringBuffer->dns1)); + memset(mpStringBuffer->dns2, 0, sizeof(mpStringBuffer->dns2)); + convertIP(mpStringBuffer->dns1, ncd::NCDSetting::getIP()->dns1); + convertIP(mpStringBuffer->dns2, ncd::NCDSetting::getIP()->dns2); + } + + void Setting::initProxy() { + memset(mpStringBuffer->proxy.server, 0, sizeof(mpStringBuffer->proxy.server)); + memset(mpStringBuffer->proxy.port, 0, sizeof(mpStringBuffer->proxy.port)); + memcpy(mpStringBuffer->proxy.server, ncd::NCDSetting::getProxy()->http.server, + sizeof(ncd::NCDSetting::getProxy()->http.server)); + sprintf(mpStringBuffer->proxy.port, "%d", ncd::NCDSetting::getProxy()->http.port); + } + + void Setting::initBasic() { + memset(mpStringBuffer->proxyBasic.uname, 0, sizeof(mpStringBuffer->proxyBasic.uname)); + memset(mpStringBuffer->proxyBasic.pass, 0, sizeof(mpStringBuffer->proxyBasic.pass)); + memcpy(mpStringBuffer->proxyBasic.uname, ncd::NCDSetting::getProxy()->http.username, + sizeof(ncd::NCDSetting::getProxy()->http.username)); + memcpy(mpStringBuffer->proxyBasic.pass, ncd::NCDSetting::getProxy()->http.password, + sizeof(ncd::NCDSetting::getProxy()->http.password)); + } + + void Setting::initMTU() { + memset(mpStringBuffer->adjMtu, 0, sizeof(mpStringBuffer->adjMtu)); + char mtuText[12]; + sprintf(mtuText, "%d", ncd::NCDSetting::getMTU()); + utility::CharacterCode::ANSIToUTF8(mpStringBuffer->adjMtu, + reinterpret_cast(mtuText)); + } + + void Setting::initSecA() { + memset(mpStringBuffer->parentalSecA, 0, sizeof(mpStringBuffer->parentalSecA)); + wchar_t answer[34]; + memset(answer, 0, 0x44); + wcsncpy(answer, parental::Parental::getSecA(), 0x20); + memset(unk_0x938, 0, sizeof(unk_0x938)); + wcsncpy(reinterpret_cast(unk_0x938), answer, 0x20); + adjustSecA(answer); + utility::CharacterCode::UTF16ToUTF8(mpStringBuffer->parentalSecA, answer, + sizeof(mpStringBuffer->parentalSecA)); + } + + void Setting::initVersion() { + const char* versionSuffix[12] = {"J", "U", "E", "", "", "J", "K", "", "", "", "", "C"}; + u32 versionData[24] = { + 0x00010008, 0x48414B4A, 0x00010008, 0x48414B45, 0x00010008, 0x48414B50, + 0, 0, 0, 0, 0, 0, 0x00010008, 0x48414B4A, 0x00010008, 0x48414B4B, + 0, 0, 0, 0, 0, 0, 0x00010008, 0x48414B43, + }; + u32 region = System::getRegion(); + sprintf(mpStringBuffer->version, "Ver. %d.%d%s", 4, 3, versionSuffix[region]); + mUpdateTitleId = *reinterpret_cast(&versionData[region * 2]); + } + + void Setting::setDisPos() { + int displayPosition = 0x10 - mpWiiSettingData->data[7]; + __VISetAdjustingValues(static_cast(displayPosition), 0); + } + + void Setting::setNickName() { + reinterpret_cast(mSettingData)->length = wcslen(reinterpret_cast(unk_0x938)); + if (checkTextNum(mpStringBuffer->nickname) == 3) { + memset(mSettingData, 0, sizeof(reinterpret_cast(mSettingData)->name)); + memcpy(mSettingData, unk_0x938, + reinterpret_cast(mSettingData)->length * sizeof(wchar_t)); + bool written = SCSetOwnerNickName(reinterpret_cast(mSettingData)) != 0; + OSReport("nicknameFlag:1 %d %s\n", written, + reinterpret_cast(mSettingData)->name); + } + } + + void Setting::setSecurityKey() { + int keyLength = ncd::NCDSetting::checkWEPKey(mpStringBuffer->securityKey); + if (keyLength >= 0) { + www::wiisetting::setFuncResult(3); + ncd::NCDSetting::setPrivacy(reinterpret_cast(mpStringBuffer->securityKey), keyLength); + OSReport("securityFlag:1 %s\n", mpStringBuffer->securityKey); + } else { + System::getDialog()->callBtn0(0x1be, 0xb4, false); + unk_0x74 = 2; + www::wiisetting::setFuncResult(4); + } + } + + void Setting::setSSID() { + u8 ssid[0x61]; + memset(ssid, 0, sizeof(ssid)); + utility::CharacterCode::UTF8ToANSI(ssid, mpStringBuffer->ssid); + memset(ssid + 0x20, 0, 0x41); + ncd::NCDSetting::setSSID(ssid); + } + + void Setting::setIP() { + NCDIpProfile ip; + memset(&ip, 0, sizeof(ip)); + convertRevIP(ip.addr, mpStringBuffer->ip.addr); + convertRevIP(ip.netmask, mpStringBuffer->ip.netmask); + convertRevIP(ip.gateway, mpStringBuffer->ip.gateway); + ncd::NCDSetting::setIP(&ip); + } + + void Setting::setDNS() { + NCDIpProfile ip; + memset(&ip, 0, sizeof(ip)); + convertRevIP(ip.dns1, mpStringBuffer->dns1); + convertRevIP(ip.dns2, mpStringBuffer->dns2); + ncd::NCDSetting::setDNS(&ip); + } + + void Setting::setProxy() { + NCDProxyServerProfile proxy; + const char* portString = mpStringBuffer->proxy.port; + wchar_t portText[6]; + u32 port; + memset(portText, 0, sizeof(portText)); + utility::CharacterCode::UTF8ToUTF16(portText, portString, 6); + utility::CharacterCode::UTF16ToU32(&port, portText); + proxy.port = port; + if (proxy.port == 0) { + www::wiisetting::setFuncResult(4); + System::getDialog()->callBtn0(0x1be, 0xb4, false); + unk_0x74 = 2; + } else { + if (ncd::NCDSetting::checkProxy(mpStringBuffer->proxy.server) != 0) { + www::wiisetting::setFuncResult(3); + memset(proxy.server, 0, sizeof(proxy.server)); + utility::CharacterCode::UTF8ToANSI(reinterpret_cast(proxy.server), + mpStringBuffer->proxy.server); + ncd::NCDSetting::setProxy(&proxy); + } else { + www::wiisetting::setFuncResult(4); + System::getDialog()->callBtn0(0x1be, 0xb4, false); + unk_0x74 = 2; + } + } + } + + void Setting::setBasic() { + if (ncd::NCDSetting::checkProxyBasic(mpStringBuffer->proxyBasic.uname) != 0 && + ncd::NCDSetting::checkProxyBasic(mpStringBuffer->proxyBasic.pass) != 0) { + NCDProxyServerProfile proxy; + www::wiisetting::setFuncResult(3); + memset(&proxy, 0, sizeof(proxy)); + utility::CharacterCode::UTF8ToANSI(reinterpret_cast(proxy.username), + mpStringBuffer->proxyBasic.uname); + utility::CharacterCode::UTF8ToANSI(reinterpret_cast(proxy.password), + mpStringBuffer->proxyBasic.pass); + ncd::NCDSetting::setBasic(&proxy); + } else { + www::wiisetting::setFuncResult(4); + System::getDialog()->callBtn0(0x1be, 0xb4, false); + unk_0x74 = 2; + } + } + + void Setting::setMTU() { + const char* mtuString = mpStringBuffer->adjMtu; + wchar_t mtuText[6]; + u32 parsedMtu; + memset(mtuText, 0, sizeof(mtuText)); + utility::CharacterCode::UTF8ToUTF16(mtuText, mtuString, 6); + utility::CharacterCode::UTF16ToU32(&parsedMtu, mtuText); + s32 mtu = parsedMtu & 0xffff; + if (mtu < 0x240 || mtu > 0x5dc) { + mtu = 0; + } + ncd::NCDSetting::setMTU(mtu); + mpWiiSettingData->data[0x36] = 0; + } + + void Setting::setParePass() { + char password[5]; + memset(password, 0, 5); + utility::CharacterCode::UTF8ToANSI(reinterpret_cast(password), mpStringBuffer->parentalPass); + if (checkTextNum(password) == 3) { + parental::Parental::setPass(password); + } + memset(mpStringBuffer->parentalPass, 0, 5); + } + + void Setting::setPareRePass() { + char password[16]; + memset(password, 0, 5); + u8 result = 2; + utility::CharacterCode::UTF8ToANSI(reinterpret_cast(password), mpStringBuffer->parentalRePass); + if (checkTextNum(password) == 3) { + if (parental::Parental::checkPass(password)) { + result = 1; + } + www::wiisetting::setFuncResult(result); + } + memset(mpStringBuffer->parentalRePass, 0, 5); + } + + void Setting::setPareJudgePass() { + char password[16]; + memset(password, 0, 5); + u8 result = 2; + utility::CharacterCode::UTF8ToANSI(reinterpret_cast(password), mpStringBuffer->parentalJudgePass); + if (checkTextNum(password) == 3) { + if (parental::Parental::judgePass(password)) { + result = 1; + } + www::wiisetting::setFuncResult(result); + } + memset(mpStringBuffer->parentalJudgePass, 0, 5); + } + + void Setting::setSecA() { + memset(unk_0x938, 0, sizeof(unk_0x938)); + utility::CharacterCode::UTF8ToUTF16(reinterpret_cast(unk_0x938), + mpStringBuffer->parentalSecA, 0x44); + reAdjustSecA(); + if (checkTextNum(NULL) == 3) { + parental::Parental::setSecA(reinterpret_cast(unk_0x938)); + } + memset(unk_0x938, 0, sizeof(unk_0x938)); + } + + void Setting::setReSecA() { + u8 result = 2; + memset(unk_0x938, 0, sizeof(unk_0x938)); + utility::CharacterCode::UTF8ToUTF16(reinterpret_cast(unk_0x938), + mpStringBuffer->parentalReSecA, 0x44); + reAdjustSecA(); + if (checkTextNum(NULL) == 3) { + if (parental::Parental::judgeSecA(reinterpret_cast(unk_0x938))) { + result = 1; + } + www::wiisetting::setFuncResult(result); + } + memset(unk_0x938, 0, sizeof(unk_0x938)); + } + + void Setting::setMasterKey() { + char masterKey[16]; + memset(masterKey, 0, 6); + u8 result = 2; + if (checkTextNum(mpStringBuffer->masterKey) == 3) { + utility::CharacterCode::UTF8ToANSI(reinterpret_cast(masterKey), mpStringBuffer->masterKey); + if (parental::Parental::judgeMaster(masterKey)) { + result = 1; + } + www::wiisetting::setFuncResult(result); + } + memset(mpStringBuffer->masterKey, 0, 6); + } + + u8 Setting::checkTextNum(const char* text) { + int formId = mpWiiSettingData->data[0x36]; + u8 result = 4; + u32 message = 0; + if (formId < 13) { + if (formId != 2) { + if (formId < 2) { + } else if (formId < 10) { + } else { + if (strlen(text) == 4) { + result = 3; + } + message = 0x1ba; + } + } else { + size_t length = wcslen(reinterpret_cast(unk_0x938)); + if (length == 0) { + message = 0x1c0; + } else if (checkSpace()) { + result = 3; + } else { + message = 0x1c1; + } + } + } else if (formId != 15) { + if (formId <= 14) { + int region = System::getRegion(); + u32 minimum; + if (region == 6) { + minimum = 2; + } else if (region < 6) { + if (region == 0) { + minimum = 3; + } else { + minimum = 6; + } + } else { + if (region == 11) { + minimum = 3; + } else { + minimum = 6; + } + } + size_t length = wcslen(reinterpret_cast(unk_0x938)); + if (length < minimum) { + message = 0x1bb; + } else if (checkSpace()) { + result = 3; + } else { + message = 0x1c1; + } + } + } else { + if (strlen(text) == 5) { + result = 3; + } + message = 0x1bc; + } + www::wiisetting::setFuncResult(result); + if (result == 4) { + System::getDialog()->callBtn0(message, 0xb4, false); + unk_0x74 = 2; + } + return result; + } + + bool Setting::checkSpace() { + for (u32 i = 0; unk_0x938[i] != 0; ++i) { + if (unk_0x938[i] != L' ' && unk_0x938[i] != 0x3000) { + return true; + } + } + return false; + } + + void Setting::convertIP(char* destination, const u8* address) { + char ascii[20]; + sprintf(ascii, "%03d.%03d.%03d.%03d", address[0], address[1], address[2], address[3]); + utility::CharacterCode::ANSIToUTF8(destination, reinterpret_cast(ascii)); + } + + void Setting::convertRevIP(u8* destination, const char* address) { + char ascii[20]; + int count = 0; + memset(ascii, 0, sizeof(ascii)); + utility::CharacterCode::UTF8ToANSI(reinterpret_cast(ascii), address); + char* converted = ascii; + int componentStart = 0; + u8* output = destination; + for (int index = 0; index < 0x10; ++index) { + u8 character = static_cast(converted[index]); + if (character == '.' || character == 0) { + if (character == 0) { + index = 0x10; + } + converted[index] = 0; + u32 value = atoi(converted + componentStart); + if (value > 0xff) { + value = 0xff; + } + if (count == 0) { + *output = value; + } else { + destination[1] = destination[2]; + destination[2] = destination[3]; + destination[3] = value; + } + componentStart = index + 1; + ++count; + ++output; + if (count == 3 && index != 0x10) { + value = atoi(converted + componentStart); + if (value > 0xff) { + value = 0xff; + } + destination[1] = destination[2]; + destination[2] = destination[3]; + destination[3] = value; + return; + } + } + } + } + + void Setting::adjustSecA(wchar_t* text) { + u32 index = 0; + bool containsWideCharacter = false; + for (; text[index] != 0; ++index) { + if (text[index] > 0x7f) { + containsWideCharacter = true; + break; + } + } + if (containsWideCharacter && wcslen(reinterpret_cast(unk_0x938)) > 0x10) { + char secondLine[0x22]; + SettingSecAText* lines = reinterpret_cast(text); + memcpy(secondLine, lines->wrappedLine, 0x22); + memcpy(&lines->wrappedLine[1], secondLine, 0x22); + lines->wrappedLine[0] = L'\n'; + } + } + + void Setting::reAdjustSecA() { + u32 i = 0; + bool containsWideCharacter = false; + for (; unk_0x938[i] != 0; ++i) { + if (unk_0x938[i] > 0x7f) { + containsWideCharacter = true; + break; + } + } + if (containsWideCharacter && wcslen(unk_0x938) > 0x10) { + char secondLine[0x22]; + SettingSecAText* lines = reinterpret_cast(unk_0x938); + memcpy(secondLine, &lines->wrappedLine[1], 0x22); + memcpy(lines->wrappedLine, secondLine, 0x22); + } + } + + void Setting::setDefaultBackString() { + switch (mpWiiSettingData->data[0x11]) { + case 1: + System::getKeyboard()->memoMgr()->setTitleText(System::getMessage(0x15c)); + break; + case 2: + System::getKeyboard()->memoMgr()->setTitleText(System::getMessage(0x153)); + break; + case 3: + System::getKeyboard()->memoMgr()->setTitleText(System::getMessage(0x152)); + break; + case 4: + System::getKeyboard()->memoMgr()->setTitleText(System::getMessage(0x14d)); + break; + case 5: + System::getKeyboard()->memoMgr()->setTitleText(System::getMessage(0x150)); + break; + case 6: + System::getKeyboard()->memoMgr()->setTitleText(System::getMessage(0x151)); + break; + case 7: + System::getKeyboard()->memoMgr()->setTitleText(System::getMessage(0x14e)); + break; + case 8: + System::getKeyboard()->memoMgr()->setTitleText(System::getMessage(0x14f)); + break; + case 10: + System::getKeyboard()->memoMgr()->setTitleText(System::getMessage(0x154)); + break; + case 11: + System::getKeyboard()->memoMgr()->setTitleText(System::getMessage(0x155)); + break; + case 12: + System::getKeyboard()->memoMgr()->setTitleText(System::getMessage(0x156)); + break; + case 13: + System::getKeyboard()->memoMgr()->setTitleText(System::getMessage(0x157)); + break; + case 14: + System::getKeyboard()->memoMgr()->setTitleText(System::getMessage(0x158)); + break; + case 15: + System::getKeyboard()->memoMgr()->setTitleText(System::getMessage(0x159)); + break; + case 16: + System::getKeyboard()->memoMgr()->setTitleText(System::getMessage(0x159)); + break; + case 17: + System::getKeyboard()->memoMgr()->setTitleText(System::getMessage(0x159)); + break; + case 18: + System::getKeyboard()->memoMgr()->setTitleText(System::getMessage(0x15a)); + break; + case 19: + System::getKeyboard()->memoMgr()->setTitleText(System::getMessage(0x15a)); + break; + case 20: + System::getKeyboard()->memoMgr()->setTitleText(System::getMessage(0x15b)); + break; + case 22: + System::getKeyboard()->memoMgr()->setTitleText(System::getMessage(0x153)); + break; + } + } + + bool Setting::checkInputString(const wchar_t* text) { + return *text == 0; + } + + int Setting::checkIPString(const wchar_t* text) { + wchar_t zeroAddress[16] = L"000.000.000.000"; + return memcmp(text, zeroAddress, sizeof(zeroAddress)) == 0 || checkInputString(text); + } + + bool Setting::calcSafeMode() { + if (System::getNwc24Manager() != NULL) { + return true; + } + if (unk_0x94 != 1) { + if (unk_0x94 < 1 && unk_0x94 >= 0) { + resetFuncMsgQ(); + System::getDialog()->callBtn1(0x21, 0x2e); + www::wiisetting::setFuncResult(2); + unk_0x74 = 0x11; + unk_0x94 = 1; + } + } else if (System::getDialog()->getLastResult() >= 0) { + unk_0xB9C = 1; + unk_0x74 = 0; + unk_0x94 = 0; + } + return false; + } + + void Setting::initAP() { + unk_0x78 = 1; + unk_0x914 = 0; + unk_0x918 = -1; + } + + void Setting::resetAP() { + layout::Animator* animation = mpMainLayout->getAnim(0x15); + animation->initFrame(); + animation->restart(); + if (unk_0x914 != 0) { + animation = mpMainLayout->getAnim(2); + animation->initFrame(); + animation->restart(); + } + if (mAPScanList.count != unk_0x914 + 4) { + animation = mpMainLayout->getAnim(3); + animation->initFrame(); + animation->restart(); + } + for (int index = 0x10; index <= 0x13; ++index) { + animation = mpMainLayout->getAnim(index); + animation->initFrame(); + animation->restart(); + } + initAP(); + unk_0x918 = 0x15; + mpWiiSettingFlag->smthMsgData = 3; + unk_0x78 = 9; + } + + void Setting::redrawAP() { + unk_0x78 = 4; + unk_0x914 = 0; + unk_0x918 = -1; + mpWiiSettingFlag->smthMsgData = 3; + mpMainLayout->getAnim(0x14)->initFrame(); + for (int index = 0x10; index <= 0x13; ++index) { + layout::Animator* animation = mpMainLayout->getAnim(index); + animation->initFrame(); + animation->restart(); + } + mpMainLayout->calc(); + unk_0x91C[2] = 0; + } + + void Setting::scanAP() { + switch (unk_0x78) { + case 1: + memset(&mAPScanList.count, 0, 0x800); + mpAPScanThread->setResultData(reinterpret_cast(&mAPScanList.count)); + memset(mpMem1BrowserBuffer, 0, 0x1000); + mpAPScanThread->Create(mpMem1BrowserBuffer, 0x1000, 0x12, true); + unk_0x78 = 2; + unk_0x91C[2] = 0; + break; + case 2: + if (unk_0x91C[2] == 1) { + waitStart(); + } + if (mpAPScanThread->IsThreadTerminated()) { + mpAPScanThread->WaitForThreadExit(); + if (mAPScanList.count == 0) { + www::wiisetting::setFuncResult(2); + initAP(); + mpMainLayout->getAnim(0x14)->initAnmFrame(); + mpMainLayout->getAnim(0)->initAnmFrame(); + mpMainLayout->getAnim(1)->initAnmFrame(); + } else { + www::wiisetting::setFuncResult(1); + setAPDraw(); + unk_0x78 = 3; + } + resetFuncMsgQ(); + unk_0xB9C = 0; + waitFinish(); + } + break; + case 3: + if (mpWiiSettingFlag->smthMsgData == 3) { + unk_0x78 = 4; + unk_0x91C[2] = 0; + } + break; + case 4: + initScroll(); + setAPDraw(); + mpPaneManager->update(); + break; + case 5: + mpPaneManager->update(); + break; + case 6: + unk_0xB9C = 1; + if (!mpMainLayout->getAnim(unk_0x918)->isPlaying()) { + unk_0x78 = 5; + setAPDraw(); + mpMainLayout->getAnim(unk_0x91C[0] == 0 ? 0xb : 0xa)->initAnmFrame(); + if (unk_0x914 == 0) { + mpMainLayout->FindPaneByName(sSettingAPNumberNames[0])->SetVisible(false); + } else if (unk_0x914 == 1) { + mpMainLayout->FindPaneByName(sSettingAPNumberNames[0])->SetVisible(true); + } + if (mAPScanList.count == unk_0x914 + 4) { + mpMainLayout->FindPaneByName(sSettingAPNumberNames[1])->SetVisible(false); + } else if (mAPScanList.count == unk_0x914 + 5) { + mpMainLayout->FindPaneByName(sSettingAPNumberNames[1])->SetVisible(true); + } + mpMainLayout->FindPaneByName(sSettingAPTextNames[0])->SetVisible(true); + mpMainLayout->FindPaneByName(sSettingAPTextNames[1])->SetVisible(true); + } + break; + case 7: + unk_0xB9C = 1; + if (!mpMainLayout->getAnim(unk_0x918)->isPlaying()) { + updateScroll(); + unk_0x78 = 6; + } + break; + case 8: + resetAP(); + unk_0x91C[2] = 0; + break; + case 9: + if (!mpMainLayout->getAnim(unk_0x918)->isPlaying()) { + resetFuncMsgQ(); + unk_0x78 = 1; + unk_0x918 = -1; + mpPaneManager->update(); + mpMainLayout->getAnim(0x14)->initFrame(); + mpMainLayout->calc(); + } + break; + } + } + + void Setting::initScroll() { + if (unk_0x91C[2] == 0) { + return; + } + for (int index = 1; index <= 4; ++index) { + mpMainLayout->FindPaneByName(sSettingAPNumberNames[index])->SetVisible(true); + } + u16 count = mAPScanList.count; + if (count == 2) { + mpMainLayout->FindPaneByName(sSettingAPNumberNames[3])->SetVisible(false); + } else if (count < 2) { + if (count == 0) { + mpMainLayout->FindPaneByName(sSettingAPNumberNames[1])->SetVisible(false); + } + mpMainLayout->FindPaneByName(sSettingAPNumberNames[2])->SetVisible(false); + mpMainLayout->FindPaneByName(sSettingAPNumberNames[3])->SetVisible(false); + } + if (count < 4) { + for (int index = 4; index < 6; ++index) { + mpMainLayout->FindPaneByName(sSettingAPNumberNames[index])->SetVisible(false); + } + mpMainLayout->FindPaneByName("N_AP7")->SetVisible(false); + } + mpMainLayout->getAnim(0x14)->initFrame(); + mpMainLayout->getAnim(0x14)->restart(); + mpMainLayout->getAnim(0)->initAnmFrame(); + mpMainLayout->FindPaneByName(sSettingAPPaneNames[0])->SetVisible(false); + mpMainLayout->FindPaneByName(sSettingAPPaneNames[1])->SetVisible(false); + if (count > unk_0x914 + 4) { + mpMainLayout->FindPaneByName(sSettingAPPaneNames[3])->SetVisible(true); + mpMainLayout->getAnim(1)->initFrame(); + mpMainLayout->getAnim(1)->restart(); + for (int index = 1; index < 6; ++index) { + mpMainLayout->FindPaneByName(sSettingAPNumberNames[index])->SetVisible(true); + } + } else { + mpMainLayout->FindPaneByName(sSettingAPPaneNames[3])->SetVisible(false); + for (int index = count + 1; index < 6; ++index) { + mpMainLayout->FindPaneByName(sSettingAPNumberNames[index])->SetVisible(false); + } + } + unk_0x78 = 6; + unk_0x918 = 0x14; + unk_0x91C[2] = 0; + } + + void Setting::updateScroll() { + if (unk_0x91C[0] == 0) { + --unk_0x914; + if (unk_0x914 == 0) { + layout::Animator* animation = mpMainLayout->getAnim(2); + animation->initFrame(); + animation->restart(); + mpMainLayout->FindPaneByName(sSettingAPPaneNames[0])->SetVisible(false); + for (int point = 0; point < 8; ++point) { + mpPaneManager->getPaneComponentByPane( + mpMainLayout->FindPaneByName(sSettingAPPaneNames[0]))->setPointed(point, false); + } + } + if (mAPScanList.count == unk_0x914 + 5) { + layout::Animator* animation = mpMainLayout->getAnim(1); + animation->initFrame(); + animation->restart(); + mpMainLayout->FindPaneByName(sSettingAPPaneNames[1])->SetVisible(true); + } + } else { + ++unk_0x914; + if (mAPScanList.count == unk_0x914 + 4) { + layout::Animator* animation = mpMainLayout->getAnim(3); + animation->initFrame(); + animation->restart(); + mpMainLayout->FindPaneByName(sSettingAPPaneNames[1])->SetVisible(false); + for (int point = 0; point < 8; ++point) { + mpPaneManager->getPaneComponentByPane( + mpMainLayout->FindPaneByName(sSettingAPPaneNames[1]))->setPointed(point, false); + } + } + if (unk_0x914 == 1) { + layout::Animator* animation = mpMainLayout->getAnim(0); + animation->initFrame(); + animation->restart(); + mpMainLayout->FindPaneByName(sSettingAPPaneNames[0])->SetVisible(true); + } + } + mpMainLayout->getAnim(10)->stop(); + mpMainLayout->getAnim(11)->stop(); + unk_0x918 = unk_0x91C[0] + 10; + layout::Animator* animation = mpMainLayout->getAnim(unk_0x918); + animation->initFrame(); + animation->restart(); + } + + void Setting::setAPDraw() { + mAPScanList.currentDescriptor = reinterpret_cast(mAPScanList.entries); + u32 recordOffset = 2; + for (u32 index = 0; index <= mAPScanList.count; ++index) { + WDBssDesc_* descriptor = mAPScanList.currentDescriptor; + recordOffset += descriptor->length * 2; + if (recordOffset > 0x800) { + return; + } + mpMainLayout->getAnim(10)->stop(); + mpMainLayout->getAnim(11)->stop(); + int privacyMode = WDGetPrivacyMode(descriptor); + char ssid[0x21]; + wchar_t displayName[0x21]; + memcpy(ssid, descriptor->ssid, 0x20); + ssid[0x20] = 0; + memset(displayName, 0, sizeof(displayName)); + int row = index + 1 - unk_0x914; + if (row >= 0 && row < 6) { + utility::CharacterCode::UTF8ToUTF16(displayName, ssid, 0x21); + nw4r::lyt::TextBox* textBox = static_cast( + mpMainLayout->FindPaneByName(sSettingAPTextNames[row])); + textBox->SetString(displayName); + if (privacyMode == 0) { + mpMainLayout->getAnim(row + 0x2e)->initFrame(); + mpMainLayout->getAnim(row + 0x2e)->restart(); + mpMainLayout->getAnim(row + 0x34)->stop(); + } else { + mpMainLayout->getAnim(row + 0x34)->initFrame(); + mpMainLayout->getAnim(row + 0x34)->restart(); + mpMainLayout->getAnim(row + 0x2e)->stop(); + } + for (int animation = row + 0x16; animation <= row + 0x28; animation += 6) { + mpMainLayout->getAnim(animation)->stop(); + } + int signal = getRadioLevel(descriptor); + mpMainLayout->getAnim(row + signal * 6 + 0x16)->initFrame(); + mpMainLayout->getAnim(row + signal * 6 + 0x16)->restart(); + } + mAPScanList.currentDescriptor = + reinterpret_cast(mAPScanList.entries + recordOffset - 2); + } + } + + int Setting::get_arw_no(const char* paneName) { + for (int index = 0; index < 2; ++index) { + if (strcmp(sSettingArrowNames[index], paneName) == 0) { + return index; + } + } + return -1; + } + + int Setting::get_ap_no(const char* buttonName) { + for (int index = 0; index < 4; ++index) { + if (strcmp(sSettingAPButtonNames[index], buttonName) == 0) { + return index; + } + } + return -1; + } + + void Setting::start_point_event(const char* pageName) { + int accessPoint = get_ap_no(pageName); + mpMainLayout->getAnim(10)->stop(); + mpMainLayout->getAnim(11)->stop(); + if (accessPoint != -1) { + layout::Animator* animator = mpMainLayout->getAnim(accessPoint + 0xc); + animator->initFrame(); + animator->restart(); + mpWiiSettingData->data[0x37] = 2; + setSE(); + return; + } + int arrow = get_arw_no(pageName); + if (arrow == -1) { + return; + } + int animation = arrow + 4; + layout::Animator* animator = mpMainLayout->getAnim(animation); + animator->initFrame(); + animator->restart(); + mpWiiSettingData->data[0x37] = 2; + setSE(); + } + + void Setting::start_left_event(const char* pageName) { + int accessPoint = get_ap_no(pageName); + if (accessPoint != -1) { + layout::Animator* animator = mpMainLayout->getAnim(accessPoint + 0x10); + animator->initFrame(); + animator->restart(); + return; + } + int arrow = get_arw_no(pageName); + if (arrow == -1) { + return; + } + layout::Animator* animator = mpMainLayout->getAnim(arrow + 6); + animator->initFrame(); + animator->restart(); + } + + void Setting::start_trig_event(const char* pageName) { + int accessPoint = get_ap_no(pageName); + if (accessPoint != -1) { + u32 recordOffset = 2; + u32 index = 0; + while (index <= mAPScanList.count) { + WDBssDesc_* descriptor = mAPScanList.currentDescriptor; + recordOffset += descriptor->length * 2; + if (recordOffset > 0x800) { + break; + } + if (index == accessPoint + unk_0x914 + 1) { + int privacyMode = WDGetPrivacyMode(descriptor); + char ssid[0x21]; + memcpy(ssid, descriptor->ssid, 0x20); + ssid[0x20] = 0; + memset(mpStringBuffer->securityKey, 0, sizeof(mpStringBuffer->securityKey)); + memset(mpStringBuffer->ssid, 0, sizeof(mpStringBuffer->ssid)); + utility::CharacterCode::ANSIToUTF8(mpStringBuffer->ssid, + reinterpret_cast(ssid), 0x20); + ncd::NCDSetting::setSSID(reinterpret_cast(ssid)); + ncd::NCDSetting::setWDPrivacyMode(privacyMode); + www::wiisetting::setFuncResult(privacyMode == 0 ? 2 : 1); + mpWiiSettingData->data[0x37] = 3; + setSE(); + OSReport("SET DATA : %d %s %d\n", index, ssid, privacyMode); + break; + } + mAPScanList.currentDescriptor = + reinterpret_cast(mAPScanList.entries + recordOffset - 2); + ++index; + } + unk_0x91C[2] = 0; + unk_0x78 = 8; + } else { + int arrow = get_arw_no(pageName); + if (arrow == -1) { + return; + } + unk_0x918 = arrow + 8; + layout::Animator* animator = mpMainLayout->getAnim(unk_0x918); + animator->initFrame(); + animator->restart(); + if (arrow == 0) { + unk_0x91C[0] = 0; + if (unk_0x914 == 1) { + mpMainLayout->FindPaneByName("N_AP0")->SetVisible(false); + } + } else { + unk_0x91C[0] = 1; + if (mAPScanList.count == unk_0x914 + 5) { + mpMainLayout->FindPaneByName("N_AP7")->SetVisible(false); + } + } + unk_0x78 = 7; + snd::getSystem()->startSE("WIPL_SE_BT_PUSH"); + } + } + + int Setting::getRadioLevel(const WDBssDesc_* descriptor) { + u16 signal = descriptor->rssi & 0xff; + if (signal > 0xc3) { + return 3; + } + if (signal > 0xb4) { + return 2; + } + return signal < 0xab ? 0 : 1; + } + + void Setting::setUseEULA_() { + if (unk_0x7C == 2) { + setUseEULA_Cancel_(); + } else if (unk_0x7C == 0) { + setUseEULA_Init_(); + } else if (unk_0x7C == 1) { + setUseEULA_Start_(); + } else if (unk_0x7C == 4) { + setUseEULA_WaitStopMotor_(); + } else if (unk_0x7C < 4 && !snd::getSystem()->isSEActive("WIPL_SE_DECIDE")) { + unk_0x7C = 4; + } + } + + void Setting::setUseEULA_Init_() { + if (ncd::NCDSetting::getEnableFlag()) { + unk_0x7C = 1; + } else { + if (static_cast(System::getRegion()) != 2) { + System::getDialog()->callBtn2(0x170, 0x146, 0x25); + } else { + System::getDialog()->callBtn2(0x174, 0x146, 0x25); + } + unk_0x74 = 9; + unk_0x7C = 0; + resetFuncMsgQ(); + } + } + + void Setting::setUseEULA_Cancel_() { + System::getDialog()->callBtn2(0x16f, 0x142, 0x141, true); + unk_0x74 = 0xc; + unk_0x7C = 0; + resetFuncMsgQ(); + } + + void Setting::setUseEULA_Start_() { + if (!validateEULA_()) { + return; + } + for (int channel = 0; channel < 4; ++channel) { + controller::Interface* input = System::getController(channel); + if (input != NULL) { + input->rumble(); + } + } + System::getBS2Manager()->abort(); + System::stopReceiveSchedule(); + unk_0x7C = 3; + } + + void Setting::setUseEULA_WaitStopMotor_() { + __WPADReconnect(1); + mSettingData[0x39] = 1; + snd::getSystem()->stopAllSound(0x14); + unk_0x7C = 5; + resetFuncMsgQ(); + } + + bool Setting::validateEULA_() { + ESTmdView* titleView = NULL; + s32 contentResult = 0; + s32 result = utility::ESMisc::GetTmdView(System::getMem1Root(), mUpdateTitleId, &titleView); + bool valid = false; + if (result == -0x401 || result == -0x6a) { + unk_0x7C = 0; + unk_0x74 = 0xd; + resetFuncMsgQ(); + System::getDialog()->callBtn2(0x180, 0x2e, 0x25); + } else if (result == 0) { + if (!utility::ESMisc::ContentExist(titleView, 1, &contentResult) && contentResult != 0) { + System::getErrorHandler()->log("error", contentResult, "iplSetting.cpp", 0x10fc); + System::getErrorHandler()->set(ErrorHandler::DEFAULT, 2); + } + valid = true; + } else { + System::getErrorHandler()->log("error", result, "iplSetting.cpp", 0x10f1); + System::getErrorHandler()->set(ErrorHandler::DEFAULT, 2); + } + if (titleView != NULL) { + System::getMem1Root()->free(titleView); + } + return valid; + } + + void Setting::setUpdate_() { + switch (mProfileIDMode) { + case 0: setUpdate_Init_(); break; + case 1: setUpdate_WaitAcceptDialog_(); break; + case 2: setUpdate_ConnectTestStart_(); break; + case 3: setUpdate_ConnectTestCreateWait_(); break; + case 4: setUpdate_ConnectTestRun_(); break; + case 5: setUpdate_ConnectTestFailed_(); break; + case 6: setUpdate_SuccessDialog_(); break; + case 7: setUpdate_NoUpdateDialog_(); break; + case 8: setUpdate_EULAInit_(); break; + case 9: + System::getDialog()->callBtn2(0x16f, 0x142, 0x141, true); + unk_0x74 = 10; + resetFuncMsgQ(); + break; + case 10: setUpdate_Reboot_(); break; + } + } + + void Setting::setUpdate_Init_() { + if (ncd::NCDSetting::getEnableFlag()) { + www::wiisetting::setFuncResult(1); + if (static_cast(System::getRegion()) == 2) { + System::getDialog()->callBtn1Sml(0x177, 0x179); + } else { + System::getDialog()->callBtn1Sml(0x176, 0x178); + } + mProfileIDMode = 1; + } else { + System::getDialog()->callBtn2(0x17f, 0x146, 0x25); + unk_0x74 = 9; + resetFuncMsgQ(); + } + } + + void Setting::setUpdate_WaitAcceptDialog_() { + if (System::getDialog()->getLastResult() >= 0) { + mProfileIDMode = 2; + } + } + + void Setting::setUpdate_ConnectTestStart_() { + if (System::getSceneManager()->getScene(0x19) == NULL && www::wiisetting::getFuncResult() == 0) { + waitStart(); + createChildScene(0x19, this, NULL, NULL); + mProfileIDMode = 3; + } + } + + void Setting::setUpdate_ConnectTestCreateWait_() { + if (System::getSceneManager()->getScene(0x19) != NULL) { + mProfileIDMode = 4; + } + } + + void Setting::setUpdate_ConnectTestRun_() { + if (isWaitPlaying()) { + return; + } + if (mpWiiSettingFlag->err == 0) { + mpWiiSettingFlag->smthMsgData = 9; + mUpdateTiming = 3; + } else if (System::getDialog()->getLastResult() == 1) { + mProfileIDMode = 2; + } else if (System::getDialog()->getLastResult() == 2) { + www::wiisetting::setFuncResult(1); + mProfileIDMode = 5; + unk_0x92C = 0; + } + } + + void Setting::setUpdate_ConnectTestFailed_() { + if (unk_0x92C == 0) { + System::getDialog()->callBtn1(0x16c, 1); + ++unk_0x92C; + } else if (System::getDialog()->getLastResult() >= 0) { + mProfileIDMode = 10; + } + } + + void Setting::setUpdate_SuccessDialog_() { + if (System::getDialog()->getLastResult() >= 0) { + System::getDialog()->callBtn1(0x16a, 0x2e); + mProfileIDMode = 8; + } + } + + void Setting::setUpdate_NoUpdateDialog_() { + if (System::getDialog()->getLastResult() >= 0) { + if (unk_0x92C == 0) { + System::getDialog()->callBtn1(0x167, 1); + ++unk_0x92C; + } else { + mProfileIDMode = 10; + } + } + } + + void Setting::setUpdate_EULAInit_() { + if (System::getDialog()->getLastResult() >= 0) { + if (SCGetEULA() != 0) { + mProfileIDMode = 10; + } else { + mProfileIDMode = 0; + www::wiisetting::setFuncResult(1); + resetFuncMsgQ(); + } + } + } + + void Setting::setUpdate_Reboot_() { + if (unk_0x92C == 0xb4) { + if (mInitialArgument == 2 || mInitialArgument == 5) { + SCSetConfigDoneFlag(1); + SCSetConfigDoneFlag2(1); + SCFlush(); + } + mIsResetAcceptable = 1; + System::getResetHandler()->reset(); + } + ++unk_0x92C; + } + + u16 Setting::getProfileID() { + if (mProfileIDMode < 3) { + return ncd::NCDSetting::getID(); + } + u16 profileID = ncd::NCDSetting::getUseProfileID(); + ncd::NCDSetting::initSetID(profileID & 0xff); + if ((profileID & 0xff) == 3) { + profileID = 0; + } + return profileID; + } + + int Setting::getUpdateTiming() { + return mUpdateTiming; + } + + void Setting::setConnectTestResult(int result, int networkError, bool updateFound, int supportCode) { + unk_0x930 = supportCode; + if (!updateFound && result == 3) { + resetFuncMsgQ(); + mUpdateTiming = 0; + mIsResetAcceptable = 1; + } else if (mpWiiSettingFlag->smthMsgData == 9) { + if (result == 2) { + System::getDialog()->terminate(); + mUpdateTiming = 6; + mpWiiSettingFlag->err = networkError; + } else if (result == 1) { + System::getDialog()->setProgBarLength(100); + mProfileIDMode = 6; + mUpdateTiming = 0; + mpWiiSettingFlag->smthMsgData = 0x54; + SCSetUpdateType(2); + SCFlush(); + } else if (result == 3) { + System::getDialog()->terminate(); + if (SCGetConfigDoneFlag2() == 0) { + mProfileIDMode = 6; + } else { + mProfileIDMode = 7; + unk_0x92C = 0; + } + mUpdateTiming = 0; + mpWiiSettingFlag->smthMsgData = 0x54; + } + } else { + if (result == 1) { + mpWiiSettingFlag->err = 0; + ncd::NCDSetting::setConnectTestFlag(true); + System::reloadDownloadTask(); + } else { + if (mProfileIDMode == 0) { + unk_0x74 = 2; + } + mpWiiSettingFlag->err = networkError; + makeErrorMessage(); + ncd::NCDSetting::setConnectTestFlag(false); + } + waitFinish(); + www::wiisetting::setFuncResult(result); + } + } + + void Setting::setNUP() { + switch (mUpdateTiming) { + case 0: + makeSupportCode(); + mUpdateTiming = 1; + break; + case 1: + if (System::getDialog()->getLastResult() == 2) { + System::getDialog()->callBtn1Sml(System::getRegion() == 2 ? 0x177 : 0x176, + System::getRegion() == 2 ? 0x179 : 0x178); + mUpdateTiming = 2; + } else if (System::getDialog()->getLastResult() == 1) { + www::wiisetting::setFuncResult(2); + mUpdateTiming = 10; + } + break; + case 2: + if (System::getDialog()->getLastResult() >= 0) { + mUpdateTiming = 3; + } + break; + case 3: + System::getDialog()->callBtnPrg(0x162); + mUpdateTiming = 4; + break; + case 4: { + scene::NakamuraTest* test = static_cast(System::getSceneManager()->getScene(0x19)); + if (test != NULL && test->amtTotal() != 0) { + System::getDialog()->setProgBarLength(test->amtCompleted() * 100 / test->amtTotal()); + } + break; + } + case 5: + if (System::getDialog()->getLastResult() >= 0) { + System::getDialog()->callBtn0(0x163, 0xb4); + mUpdateTiming = 8; + } + break; + case 6: + if (System::getDialog()->getLastResult() >= 0) { + makeErrorMessage(); + mUpdateTiming = 0xb; + } + break; + case 7: + if (System::getDialog()->getLastResult() >= 0) { + System::getDialog()->callBtn1(0x167, 1); + mUpdateTiming = 8; + } + break; + case 8: + if (System::getDialog()->getLastResult() >= 0) { + mUpdateTiming = 9; + unk_0x92C = 0; + if (mProgressiveMode == 2 || mProgressiveMode == 5) { + SCSetConfigDoneFlag(1); + SCSetConfigDoneFlag2(1); + SCFlush(); + } + } + break; + case 9: + if (unk_0x92C == 0xb4) { + mIsResetAcceptable = 1; + System::getResetHandler()->reset(); + } + ++unk_0x92C; + break; + case 0xb: + if (System::getDialog()->getLastResult() >= 0) { + mProfileIDMode = 5; + mpWiiSettingFlag->smthMsgData = 0x54; + mUpdateTiming = 0; + unk_0x92C = 0; + } + break; + } + } + + void Setting::makeErrorMessage() { + const wchar_t* prefix = System::getMessage(400); + int messageId = getErrorNum(); + const wchar_t* detail = System::getMessage(messageId); + int error = mpWiiSettingFlag->err; + OSReport("error:%d\n", error); + wchar_t errorText[8]; + wchar_t message[0x140]; + swprintf(errorText, 8, L"\n%03d", error); + memset(message, 0, sizeof(message)); + size_t prefixLength = wcslen(prefix); + wcsncat(message, prefix, prefixLength); + size_t errorLength = wcslen(errorText); + wcsncat(message + prefixLength, errorText, errorLength); + size_t detailLength = wcslen(detail); + wcsncat(message + prefixLength + errorLength, detail, detailLength); + message[prefixLength + errorLength + detailLength] = 0; + bool connectTestError = mpWiiSettingFlag->smthMsgData == 9; + bool japaneseRegion = System::getRegion() == 2 && System::getLanguage() == 2 && getErrorNum() == 0x1b6; + if (connectTestError || mProfileIDMode == 0) { + if (japaneseRegion) { + System::getDialog()->callBtn1(message, 0x2e, 46.0f); + } else { + System::getDialog()->callBtn1(message, 0x2e); + } + } else { + System::getDialog()->callBtn2(message, 0x171, 0x25); + } + } + + int Setting::getErrorNum() { + int error = mpWiiSettingFlag->err; + if (error == 0x7d01) return System::getRegion() == 2 ? 0x1a5 : 0x191; + if (error == 0x7d02) return System::getRegion() == 2 ? 0x1a6 : 0x192; + if (error == 0x7d03) return System::getRegion() == 2 ? 0x1a7 : 0x193; + if (error < 33000) return System::getRegion() == 2 ? 0x1a8 : 0x194; + if (error < 0xc418) return System::getRegion() == 2 ? 0x1a9 : 0x195; + if (error < 0xc47c) return System::getRegion() == 2 ? 0x1aa : 0x196; + if (error < 0xc4e0) return System::getRegion() == 2 ? 0x1ab : 0x197; + if (error < 0xc544) return System::getRegion() == 2 ? 0x1ac : 0x198; + if (error < 0xc760) return System::getRegion() == 2 ? 0x1ad : 0x199; + if (error < 0xc76a) return System::getRegion() == 2 ? 0x1b8 : 0x1a4; + if (error < 0xc79c) return System::getRegion() == 2 ? 0x1ad : 0x199; + if (error < 0xc8c8) return System::getRegion() == 2 ? 0x1ae : 0x19a; + if (error < 0xc92c) return System::getRegion() == 2 ? 0x1af : 0x19b; + if (error < 0xcb84) return System::getRegion() == 2 ? 0x1b0 : 0x19c; + if (error < 0xcbe8) return System::getRegion() == 2 ? 0x1b1 : 0x19d; + if (error < 0xcc4c) return System::getRegion() == 2 ? 0x1b2 : 0x19e; + if (error < 0xcd14) return System::getRegion() == 2 ? 0x1b3 : 0x19f; + if (error < 0xcd78) return System::getRegion() == 2 ? 0x1b4 : 0x1a0; + if (error < 0xcddc) return System::getRegion() == 2 ? 0x1b5 : 0x1a1; + if (error < 0xce40) return System::getRegion() == 2 ? 0x1b6 : 0x1a2; + if (error < 55000) return System::getRegion() == 2 ? 0x1b7 : 0x1a3; + if (error > 100000) return 0x1c5; + return System::getRegion(); + } + + void Setting::makeSupportCode() { + const wchar_t* title = System::getMessage(0x16d); + const wchar_t* codeLabel = System::getMessage(0x1b9); + wchar_t supportCode[12]; + wchar_t message[0x110]; + swprintf(supportCode, 12, L"\n%03d", unk_0x930); + memset(message, 0, sizeof(message)); + size_t titleLength = wcslen(title); + wcsncat(message, title, titleLength); + message[titleLength] = L'\n'; + message[titleLength + 1] = 0; + size_t labelLength = wcslen(codeLabel); + wcsncat(message + titleLength + 1, codeLabel, labelLength); + size_t codeLength = wcslen(supportCode); + wcsncat(message + titleLength + 1 + labelLength, supportCode, codeLength); + message[titleLength + 1 + labelLength + codeLength] = 0; + System::getDialog()->callBtn2(message, 0x142, 0x141, true); + } + + void Setting::setInitializeResult(bool initialized, int error) { + waitFinish(); + if (!initialized) { + if (error == -2) { + System::getErrorHandler()->log("NandSDWorker", error, "iplSetting.cpp", 0x13a7); + System::getErrorHandler()->set(ErrorHandler::DEFAULT, 2); + } else if (error == -5) { + System::getErrorHandler()->set(ErrorHandler::DEFAULT, 1); + } + } else { + www::wiisetting::setFuncResult(1); + } + } + + void Setting::setUSBAP() { + if (unk_0x84 == 2) { + if (unk_0x91C[1] != 0) { + www::wiisetting::setFuncResult(unk_0x91C[1]); + unk_0x84 = 1; + unk_0x91C[1] = 0; + resetFuncMsgQ(); + } + } else if (unk_0x84 == 1 && static_cast(mpUSBAPThread)->is()) { + SCOwnerNickname nickname; + int result = SCGetOwnerNickName(&nickname); + if (!result) { + www::wiisetting::setFuncResult(2); + resetFuncMsgQ(); + } else { + OSReport("USB SCGetOwnerNickName:%d\n", result); + static_cast(mpUSBAPThread)->setData( + reinterpret_cast(nickname.name), &unk_0x91C[1]); + static_cast(mpUSBAPThread)->Init( + reinterpret_cast(mpMem1BrowserBuffer), + reinterpret_cast(mpMem2BrowserBuffer)); + unk_0x84 = 2; + } + } + } + + void Setting::cancelUSBAP() { + if (unk_0x84 == 3) { + if (unk_0x91C[1] != 0 || static_cast(mpUSBAPThread)->is()) { + www::wiisetting::setFuncResult(5); + unk_0x84 = 1; + unk_0x91C[1] = 0; + resetFuncMsgQ(); + } + } else if (unk_0x84 > 0 && unk_0x84 < 3) { + static_cast(mpUSBAPThread)->cancel(); + unk_0x84 = 3; + } + } + + void Setting::AOSSProcess() { + int error = mpWiiSettingFlag->err; + if (error == '"') { + if (mAOSSState == 3) { + if (System::getDialog()->getLastResult() >= 0) { + mAOSSState = 0; + www::wiisetting::setFuncResult(10); + resetFuncMsgQ(); + } + } else { + System::getDialog()->callBtn1(0x1c2, 0x2e); + mAOSSState = 3; + unk_0x74 = 2; + } + return; + } + AOSSThread* thread = reinterpret_cast(mpAOSSThread); + bool cancelled = error == '!'; + if (mAOSSState == 0) { + if (!snd::getSystem()->isSEActive("WIPL_SE_DECIDE")) { + if (cancelled || thread->start() == 0) { + www::wiisetting::setFuncResult(cancelled ? 5 : 2); + resetFuncMsgQ(); + } else { + mAOSSState = 1; + } + } + } else if (mAOSSState >= 0 && mAOSSState < 3) { + int result = 0; + if (thread->finish(&m_AOSSConfig, &result) != 0) { + mAOSSState = 0; + if (cancelled) { + www::wiisetting::setFuncResult(5); + } else if (result == 0) { + ncd::NCDSetting::getData(); + ncd::NCDSetting::getID(); + ncd::NCDSetting::setAOSSParams(m_AOSSConfig); + www::wiisetting::setFuncResult(1); + } else { + OSReport("m_AOSSThread : Terminated with Error(%d)\n", result); + www::wiisetting::setFuncResult(2); + } + resetFuncMsgQ(); + } else if (cancelled && mAOSSState != 2) { + thread->cancel(); + mAOSSState = 2; + } + } + } + + void Setting::RakuProcess() { + int command = mpWiiSettingFlag->smthMsgData; + int state = reinterpret_cast(mpRakuRakuThread)->getState(); + RakuRakuThread* thread = reinterpret_cast(mpRakuRakuThread); + int result = 0; + if (command == ',') { + if (mRakuState != 1) { + System::getDialog()->callBtn1(0x1c3, 0x2e); + mRakuState = 1; + unk_0x74 = 2; + } else if (System::getDialog()->getLastResult() >= 0) { + mRakuState = 0; + www::wiisetting::setFuncResult(10); + resetFuncMsgQ(); + } + return; + } + if (command == '+' && (state == 0 || state == 6 || state == 7 || state == 8)) { + if (thread->finish(NULL, NULL) != 0) { + www::wiisetting::setFuncResult(5); + resetFuncMsgQ(); + } else { + thread->cancel(); + } + return; + } + if (command != '+' && state == 0) { + if (!snd::getSystem()->isSEActive("WIPL_SE_DECIDE") && thread->start() == 0) { + www::wiisetting::setFuncResult(2); + resetFuncMsgQ(); + } + return; + } + if (command != '+' && state == 5) { + if (command == ')') { + www::wiisetting::setFuncResult(1); + resetFuncMsgQ(); + } + return; + } + if (state == 7) { + if (thread->finish(NULL, &result) != 0) { + www::wiisetting::setFuncResult(2); + resetFuncMsgQ(); + } + return; + } + if (state > 4 && state < 7) { + if (thread->finish(&m_RakuConfig.cfg, &result) != 0) { + if (result == 1) { + ncd::NCDSetting::getData(); + ncd::NCDSetting::getID(); + ncd::NCDSetting::setRakuParams(m_RakuConfig.cfg); + www::wiisetting::setFuncResult(1); + } else { + www::wiisetting::setFuncResult(2); + } + resetFuncMsgQ(); + } + return; + } + if (state > 0 && state < 4 && command == '(') { + www::wiisetting::setFuncResult(1); + resetFuncMsgQ(); + } + } + + void Setting::waitStart() { + mpWaitLayout->getAnim(0)->initFrame(); + mpWaitLayout->getAnim(0)->restart(); + mpWaitLayout->FindPaneByName("G_Wait")->SetVisible(true); + snd::getSystem()->startSE("WIPL_SE_COPYING"); + } + + void Setting::waitFinish() { + mpWaitLayout->getAnim(0)->stop(); + mpWaitLayout->FindPaneByName("G_Wait")->SetVisible(false); + snd::getSystem()->startSE("WIPL_SE_COPY_FINISH"); + } + + bool Setting::isWaitPlaying() { + return mpWaitLayout->getAnim(0)->isPlaying(); + } + + void Setting::setSE() { + u8& action = mpWiiSettingData->data[0x37]; + u8& pendingAction = mpWiiSettingData->data[0x38]; + if (unk_0xB9C < 10 && action == 2) { + action = 0; + } + if ((action == 0 || action == 2) && pendingAction != 0) { + action = pendingAction; + } + switch (action) { + case 1: + snd::getSystem()->startSE("WIPL_SE_BT_PUSH"); + break; + case 2: + snd::getSystem()->startSE("WIPL_SE_BT_TARGETTING"); + break; + case 3: + snd::getSystem()->startSE("WIPL_SE_DECIDE"); + break; + case 4: + snd::getSystem()->startSE("WIPL_SE_CANCEL"); + break; + case 5: + snd::getSystem()->startSE("WIPL_SE_CHOICE_CHG"); + break; + case 6: + snd::getSystem()->startSE("WIPL_SE_CHAR_DELETE_ERROR"); + break; + case 10: + snd::getSystem()->setOutputMode(snd::AUDIO_OUTPUT_MODE_MONO); + snd::getSystem()->startSE("WIPL_SE_OUTPUT_MODE_SELECT"); + break; + case 11: + snd::getSystem()->setOutputMode(snd::AUDIO_OUTPUT_MODE_STEREO); + snd::getSystem()->startSE("WIPL_SE_OUTPUT_MODE_SELECT"); + break; + case 12: + snd::getSystem()->setOutputMode(snd::AUDIO_OUTPUT_MODE_SURROUND); + snd::getSystem()->startSE("WIPL_SE_OUTPUT_MODE_SELECT"); + break; + case 30: + snd::getSystem()->setOutputMode(snd::AUDIO_OUTPUT_MODE_MONO); + snd::getSystem()->startSE("WIPL_SE_CANCEL"); + break; + case 31: + snd::getSystem()->setOutputMode(snd::AUDIO_OUTPUT_MODE_STEREO); + snd::getSystem()->startSE("WIPL_SE_CANCEL"); + break; + case 32: + snd::getSystem()->setOutputMode(snd::AUDIO_OUTPUT_MODE_SURROUND); + snd::getSystem()->startSE("WIPL_SE_CANCEL"); + break; + } + if (action == 2 || action == 0 || mpWiiSettingData->data[0x12] == 0x1e || pendingAction != 0) { + if (action == 2) { + controller::Interface* controller = System::getYoungController(); + if (controller != NULL) { + controller->rumble(0); + } + } + } else { + unk_0xB9C = 0; + } + action = 0; + pendingAction = 0; + } + + void APEvent::onEvent(u32 componentID, u32 event, void* data) { + gui::PaneComponent* component = static_cast(mpManager->getComponent(componentID)); + const char* paneName = component->getPane()->GetName(); + if (event == ::gui::EventHandler::ON_POINT) { + mpSetting->start_point_event(paneName); + } else if (event == ::gui::EventHandler::ON_TRIG) { + controller::Interface* input = static_cast(data); + if (input->downTrg(0x100800)) { + mpSetting->start_trig_event(paneName); + } + } else if (event == ::gui::EventHandler::ON_LEFT) { + mpSetting->start_left_event(paneName); + } + } + + BOOL Setting::isResetAcceptable() const { + return mIsResetAcceptable; + } + + } // namespace scene +} // namespace ipl -- 2.49.1 From 823ee319373318bf348c8dbb6673c20a440a2003 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 29 Sep 2026 04:11:22 -0500 Subject: [PATCH 06/18] Decompile PrFILE2 pf_file to 23/45 functions (worker 90e4121e) (#257) --- libs/RVL_SDK/src/fa/pf_file.c | 2205 +++++++++++++++++++++++++++++++++ 1 file changed, 2205 insertions(+) create mode 100644 libs/RVL_SDK/src/fa/pf_file.c diff --git a/libs/RVL_SDK/src/fa/pf_file.c b/libs/RVL_SDK/src/fa/pf_file.c new file mode 100644 index 00000000..2bf6dce0 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_file.c @@ -0,0 +1,2205 @@ +#include +#include +#include +#include + +typedef struct PFFILE_FAT_HINT { + pf_u32 chain_index; + pf_u32 cluster; + pf_u32 previous_cluster; +} PFFILE_FAT_HINT; + +typedef struct PFFILE_FFD { + pf_u32 start_cluster; + pf_u32 flags; + pf_u32* p_start_cluster; + PF_LAST_CLUSTER last_cluster; + PF_FAT_LAST_ACCESS last_access_cluster; + PF_CLUSTER_LINK cluster_link; + PF_FAT_HINT* p_hint; + PF_VOLUME* p_vol; +} PFFILE_FFD; + +typedef struct PFFILE_CURSOR { + pf_u32 position; + pf_u32 sector; + pf_u32 file_sector_index; + pf_u16 offset_in_sector; + pf_u16 reserved; +} PFFILE_CURSOR; + +typedef struct PFFILE_SFD { + pf_u32 stat; + PFFILE_FFD ffd; + PF_DIR_ENT dir_entry; + PF_LOCK lock; + pf_u32 lock_state[3]; + pf_u16 handler_count; + pf_u8 reserved[2]; +} PFFILE_SFD; + +typedef struct PFFILE_SDD { + pf_u32 stat; + pf_u16 num_handlers; + pf_u16 alignment; + PFFILE_FFD ffd; + PF_DIR_ENT dir_entry; +} PFFILE_SDD; + +typedef struct PFFILE_FILE PFFILE_FILE; + +typedef struct PFFILE_DIR { + pf_u32 stat; + PFFILE_SDD* p_sdd; + PFFILE_FAT_HINT hint; + pf_u32 current_position; + pf_u32 next_position; + pf_u32 end_position; +} PFFILE_DIR; + +typedef struct PFFILE_ENT_ITER { + pf_u32 index; + PF_VOLUME* p_vol; + PFFILE_FFD ffd; + pf_u32 file_sector_index; + pf_u32 sector; + pf_u16 offset; + pf_u16 offset_mask; + pf_u8 buffer[32]; + pf_u8 log2_entries_per_sector; +} PFFILE_ENT_ITER; + +typedef struct PFFILE_CLUSTER_LINK_VOL { + pf_u16 flag; + pf_u16 interval; + pf_u32* buffer; + pf_u32 link_max; +} PFFILE_CLUSTER_LINK_VOL; + +typedef struct PFFILE_CLUSTER_LINK_SETTINGS { + pf_u32* buffer; + pf_u32 link_max; + pf_u16 interval; + pf_u16 reserved; +} PFFILE_CLUSTER_LINK_SETTINGS; + +typedef struct PFFILE_GLOBAL_STATE { + pf_u8 state_prefix[0x40]; + pf_s32 last_error; + pf_u8 settings_prefix[0x1C]; + pf_u32 file_settings; +} PFFILE_GLOBAL_STATE; + +struct PFFILE_FILE { + pf_u32 stat; + pf_u32 open_mode; + PFFILE_SFD* p_sfd; + PF_FAT_HINT hint; + union { + PF_FAT_HINT last_access; + struct { + pf_u32 last_access_chain_index; + pf_s32 last_error; + } state; + } last_access_data; + PFFILE_CURSOR cursor; + pf_u16 lock_count; + pf_u16 state_flags; +}; + +typedef struct PFFILE_VOLUME_DIRS { + pf_u8 volume_prefix[0x40]; + PFFILE_SFD sfds[5]; + PFFILE_FILE ufds[5]; + PFFILE_SDD sdds[3]; + PFFILE_DIR udds[3]; + pf_s32 num_opened_files; + pf_s32 num_opened_directories; + pf_u32 cache_control; + pf_u8 cache_state[0x1C]; + void* cache_signature; + pf_u8 volume_tail[0x1F80 - 0x1648]; + pf_s32 last_error; + pf_s32 last_driver_error; + pf_u32 file_config; + pf_u16 flags; + pf_u8 drv_char; + pf_u16 fsi_flag; + pf_u16 cluster_link_alignment; + PFFILE_CLUSTER_LINK_VOL cluster_link; +} PFFILE_VOLUME_DIRS; + +extern void PFCLUSTER_UpdateLastAccessCluster(); +extern pf_s32 PFFAT_GetSectorSpecified(PFFILE_FFD* ffd, pf_u32 file_sector_index, pf_u32 cluster_index, + pf_u32* sector); +extern pf_s32 PFFAT_getContinuousSector(PFFILE_FFD* ffd, pf_u32 file_sector_index, pf_u32 size, + pf_u32* sector, pf_u32* num_sectors); +extern pf_s32 PFSEC_ReadData(PF_VOLUME* volume, pf_u8* buffer, pf_u32 sector, pf_u16 offset, + pf_u32 size, pf_u32* size_read, pf_u32 mode); +extern pf_s32 PFSEC_WriteData(PF_VOLUME* volume, const pf_u8* buffer, pf_u32 sector, pf_u16 offset, + pf_u32 size, pf_u32* size_written, pf_u32 mode); +extern pf_s32 PFFAT_CountAllocatedClusters(PFFILE_FFD* ffd, pf_u32 position, pf_u32* num_clusters); +extern pf_s32 PFCLUSTER_AppendCluster(PFFILE_FILE* file, pf_u32 size, pf_u32* appended_size); +extern pf_s32 PFCLUSTER_AdjustCluster(PFFILE_FILE* file); +extern pf_s32 PFCLUSTER_GetAppendSize(PFFILE_FILE* file, pf_u32* append_size); +extern pf_s32 PFFAT_InitFFD(PFFILE_FFD* ffd, void* hint, PF_VOLUME* volume, pf_u32* start_cluster); +extern void* pf_memset(void* destination, pf_s32 value, pf_u32 size); +extern pf_u32 PFSTR_StrNumChar(PF_STR* path_string, pf_u32 mode); +extern pf_u32 PFSTR_GetCodeMode(PF_STR* path_string); +extern void* PFSTR_GetStrPos(PF_STR* path_string, pf_u32 mode); +extern pf_s32 PFPATH_parseShortName(pf_s8* short_name, PF_STR* path_string); +extern pf_s32 PFENT_AdjustSFN(PF_DIR_ENT* entry, pf_s8* short_name); +extern void PFPATH_transformInUnicode(PF_DIR_ENT* entry, void* unicode_text); +extern pf_u16* pf_w_strcpy(pf_u16* destination, const pf_u16* source); +extern pf_u8 PFENT_getcurrentDateTimeForEnt(pf_u16* date, pf_u16* time); +extern pf_s32 PFENT_allocateEntry(PF_DIR_ENT* entry, pf_u32 count, PFFILE_FFD* ffd, + pf_u32* previous_sectors, PF_STR* filename); +extern pf_s32 PFENT_allocateEntryPos(PF_DIR_ENT* entry, pf_u32 count, PFFILE_FFD* ffd, + pf_u32* previous_sectors, PF_STR* filename, + pf_u32* position); +extern void PFPATH_AdjustExtShortName(pf_s8* short_name, pf_u32 position); +extern pf_u8 PFENT_CalcCheckSum(PF_DIR_ENT* entry); +extern void PFENT_storeLFNEntryFieldsToBuf(pf_u8* buffer, PF_DIR_ENT* entry, pf_u8 ordinal, + pf_u8 checksum, pf_bool is_last); +extern pf_s32 PFENT_updateEntry(PF_DIR_ENT* entry, pf_u32 update_archive); +extern pf_s32 PFPATH_SplitPath(PF_STR* path, PF_STR* directory, PF_STR* filename); +extern pf_s32 PFENT_ITER_GetEntryOfPath(PFFILE_ENT_ITER* iter, PF_DIR_ENT* entry, + PF_VOLUME* volume, PF_STR* path, pf_u32 no_look_last); +extern pf_s32 PFENT_RemoveEntry(PF_DIR_ENT* entry, PFFILE_ENT_ITER* iter); +extern pf_s32 PFFAT_FreeChain(PFFILE_FFD* ffd, pf_u32 start_cluster, pf_u32 chain_index, + pf_u32 size); +extern pf_s32 PFCACHE_AllocateDataPage(PF_VOLUME* volume, pf_u32 sector, + PF_CACHE_PAGE** page, pf_u32* option); +extern void PFCACHE_FreeDataPage(PF_VOLUME* volume, PF_CACHE_PAGE* page); +extern pf_s32 PFENT_findEntry(PFFILE_FFD* ffd, PF_DIR_ENT* entry, pf_u32 start, + PF_STR* pattern, pf_u8 attr_required, pf_u32 flags); +extern pf_s32 PFCLUSTER_CombineFiles(PFFILE_ENT_ITER* first_iter, + PFFILE_ENT_ITER* second_iter_copy, + PF_DIR_ENT* first_entry, PF_DIR_ENT* second_entry); +extern pf_s32 PFCLUSTER_InsertCluster(PFFILE_ENT_ITER* iter, PF_DIR_ENT* entry, + pf_u32 cluster_index, pf_u32 count, pf_u32 mode); +extern pf_s32 PFCLUSTER_DeleteCluster(PFFILE_ENT_ITER* iter, PF_DIR_ENT* entry, + pf_u32 cluster_index, pf_u32 count, pf_u32 mode); +extern pf_s32 PFCLUSTER_DivideFile(PFFILE_ENT_ITER* source_iter, + PFFILE_ENT_ITER* destination_iter, + PF_DIR_ENT* source_entry_copy, + PF_DIR_ENT* destination_entry, pf_u32 split_size); +extern void* pf_memcpy(void* destination, const void* source, pf_u32 size); +extern pf_s32 PFCACHE_FlushDataCacheSpecific(PF_VOLUME* volume, void* signature); +extern pf_s32 PFCACHE_FlushFATCache(PF_VOLUME* volume); +extern void PFFAT_InitHint(void* hint); +extern void PFFAT_FinalizeFFD(PFFILE_FFD* ffd); +extern void PFSTR_SetLocalStr(PF_STR* path_string, const pf_s8* converted_path); +extern pf_s32 PFPATH_transformFromUnicodeToNormal(pf_s8* destination, const pf_u16* source); +extern PF_VOLUME* PFPATH_GetVolumeFromPath(PF_STR* path_string); +extern pf_s32 PFVOL_CheckForWrite(PF_VOLUME* volume); +extern pf_s32 PFVOL_CheckForRead(PF_VOLUME* volume); +extern pf_s32 PFDRV_IsWProtected(PF_VOLUME* volume); +extern pf_s32 PF_LockFile(PF_FILE* file, PF_FILE* owner); +extern pf_s32 PF_UnLockFile(PF_FILE* file); +extern pf_bool PFFILE_IsOpened(PF_DIR_ENT* entry); +extern PFFILE_GLOBAL_STATE pf_vol_set; + +static void PFFILE_Cursor_Recalc(PFFILE_FILE* file) { + PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + + file->cursor.file_sector_index = file->cursor.position >> volume->bpb.log2_bytes_per_sector; + file->cursor.offset_in_sector = file->cursor.position & (volume->bpb.bytes_per_sector - 1); +} + +pf_bool PFFILE_Cursor_AdvanceToRead(PFFILE_FILE* file, pf_u32 size, pf_u32 sector) { + pf_bool result = PF_TRUE; + PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + pf_u32 next_sector = sector + ((file->cursor.offset_in_sector + size) >> volume->bpb.log2_bytes_per_sector); + + if ((file->cursor.position + size) < file->p_sfd->dir_entry.file_size) { + if (((volume->bpb.bytes_per_sector - 1) & (file->cursor.offset_in_sector + size)) != 0) { + file->cursor.sector = sector + ((file->cursor.offset_in_sector + size) >> volume->bpb.log2_bytes_per_sector); + } else { + file->cursor.sector = -1; + } + file->cursor.position += size; + } else if (file->p_sfd->dir_entry.file_size == 0) { + file->cursor.sector = -1; + file->cursor.position = 0; + if (size != 0) { + result = PF_FALSE; + } + } else { + file->cursor.sector = -1; + file->cursor.position = file->p_sfd->dir_entry.file_size; + result = PF_FALSE; + } + PFFILE_Cursor_Recalc(file); + PFCLUSTER_UpdateLastAccessCluster(file, next_sector); + return result; +} + +pf_s32 PFFILE_Cursor_ReadHeadSector(PFFILE_FILE* file, pf_u8* buffer, pf_u32 size, pf_u32* size_read) { + pf_s32 error; + pf_u32 max_size; + pf_u32 success_size; + PF_VOLUME* volume; + + *size_read = 0; + if (file->cursor.offset_in_sector == 0) { + return 0; + } + volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + max_size = volume->bpb.bytes_per_sector - file->cursor.offset_in_sector; + if (size > max_size) { + size = max_size; + } + if (file->cursor.position + size > file->p_sfd->dir_entry.file_size) { + size = file->p_sfd->dir_entry.file_size - file->cursor.position; + if (size < max_size) { + return 0; + } + } + if (file->cursor.sector == -1) { + error = PFFAT_GetSectorSpecified(&file->p_sfd->ffd, file->cursor.file_sector_index, 0, + &file->cursor.sector); + if (error != 0) { + return error; + } + if (file->cursor.sector == -1) { + file->cursor.position = file->p_sfd->dir_entry.file_size; + PFFILE_Cursor_Recalc(file); + return 0x1C; + } + if (file->cursor.position + size > file->p_sfd->dir_entry.file_size) { + file->cursor.position = file->p_sfd->dir_entry.file_size; + PFFILE_Cursor_Recalc(file); + return 0x1B; + } + } + error = PFSEC_ReadData(volume, buffer, file->cursor.sector, file->cursor.offset_in_sector, size, + &success_size, 1); + if (error != 0 && success_size == 0) { + return error; + } + *size_read = success_size; + PFFILE_Cursor_AdvanceToRead(file, success_size, file->cursor.sector); + if (success_size != size) { + return error; + } + return 0; +} + +pf_s32 PFFILE_Cursor_ReadBodySectors(PFFILE_FILE* file, pf_u8* buffer, pf_u32 size, + pf_u32* size_read) { + pf_s32 error; + pf_u32 num_sectors; + pf_u32 max_size; + pf_u32 success_size; + PF_VOLUME* volume; + + *size_read = 0; + volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + num_sectors = 0; + error = PFFAT_getContinuousSector(&file->p_sfd->ffd, file->cursor.file_sector_index, size, + &file->cursor.sector, &num_sectors); + if (error != 0) { + return error; + } + if (file->cursor.sector == -1) { + file->cursor.position = file->p_sfd->dir_entry.file_size; + PFFILE_Cursor_Recalc(file); + return 0x1C; + } + max_size = num_sectors << volume->bpb.log2_bytes_per_sector; + if (size > max_size) { + size = max_size; + } + if (file->cursor.position + size > file->p_sfd->dir_entry.file_size) { + size = file->p_sfd->dir_entry.file_size - file->cursor.position; + size -= size & (volume->bpb.bytes_per_sector - 1); + if (size < volume->bpb.bytes_per_sector) { + return 0; + } + } + error = PFSEC_ReadData(volume, buffer, file->cursor.sector, file->cursor.offset_in_sector, size, + &success_size, 1); + if (error != 0 && success_size == 0) { + return error; + } + *size_read = success_size; + PFFILE_Cursor_AdvanceToRead(file, success_size, file->cursor.sector); + if (success_size != size - (size & (volume->bpb.bytes_per_sector - 1))) { + return error; + } + return 0; +} + +pf_s32 PFFILE_Cursor_ReadTailSector(PFFILE_FILE* file, pf_u8* buffer, pf_u32 size, + pf_u32* size_read) { + pf_s32 error; + pf_u32 success_size; + PF_VOLUME* volume; + + *size_read = 0; + volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + if (size == 0) { + return 0; + } + if (file->cursor.position + size > file->p_sfd->dir_entry.file_size) { + size = file->p_sfd->dir_entry.file_size - file->cursor.position; + if (size == 0) { + return 0; + } + } + if (file->cursor.sector == -1) { + error = PFFAT_GetSectorSpecified(&file->p_sfd->ffd, file->cursor.file_sector_index, 0, + &file->cursor.sector); + if (error != 0) { + return error; + } + if (file->cursor.sector == -1) { + file->cursor.position = file->p_sfd->dir_entry.file_size; + PFFILE_Cursor_Recalc(file); + return 0x1C; + } + if (file->cursor.position + size > file->p_sfd->dir_entry.file_size) { + file->cursor.position = file->p_sfd->dir_entry.file_size; + PFFILE_Cursor_Recalc(file); + return 0x1B; + } + } + error = PFSEC_ReadData(volume, buffer, file->cursor.sector, file->cursor.offset_in_sector, size, + &success_size, 1); + if (error != 0 && success_size == 0) { + return error; + } + *size_read = success_size; + PFFILE_Cursor_AdvanceToRead(file, success_size, file->cursor.sector); + if (success_size != size) { + return error; + } + return 0; +} + +pf_s32 PFFILE_Cursor_Read(PFFILE_FILE* file, pf_u8* buffer, pf_u32 size, pf_u32* size_read) { + pf_s32 error; + pf_u32 part_size; + PF_VOLUME* volume; + + file->p_sfd->ffd.p_hint = &file->hint; + *size_read = 0; + error = PFFILE_Cursor_ReadHeadSector(file, buffer, size, &part_size); + *size_read += part_size; + if (error != 0) { + return error; + } + if (size <= part_size) { + return 0; + } + size -= part_size; + volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + while (volume->bpb.bytes_per_sector <= size) { + error = PFFILE_Cursor_ReadBodySectors(file, buffer + *size_read, size, &part_size); + *size_read += part_size; + if (error != 0) { + return error; + } + if (part_size == 0) { + break; + } + size -= part_size; + } + error = PFFILE_Cursor_ReadTailSector(file, buffer + *size_read, size, &part_size); + *size_read += part_size; + if (error == 0) { + error = 0; + } + return error; +} + +pf_s32 PFFILE_Cursor_WriteHeadSector(PFFILE_FILE* file, const pf_u8* buffer, pf_u32 size, + pf_u32* size_written) { + pf_s32 error; + pf_u32 success_size; + pf_u32 next_position; + PF_VOLUME* volume; + + *size_written = 0; + if (file->cursor.offset_in_sector == 0) { + return 0; + } + volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + if (size > volume->bpb.bytes_per_sector - file->cursor.offset_in_sector) { + size = volume->bpb.bytes_per_sector - file->cursor.offset_in_sector; + } + if (file->cursor.sector == -1) { + error = PFFAT_GetSectorSpecified(&file->p_sfd->ffd, file->cursor.file_sector_index, 0, + &file->cursor.sector); + if (error != 0) { + return error; + } + if (file->cursor.sector == -1) { + file->cursor.position = file->p_sfd->dir_entry.file_size; + PFFILE_Cursor_Recalc(file); + return 0x1C; + } + } + error = PFSEC_WriteData(volume, buffer, file->cursor.sector, file->cursor.offset_in_sector, size, + &success_size, 1); + if (error != 0 && success_size == 0) { + return error; + } + *size_written = success_size; + volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + next_position = file->cursor.offset_in_sector + success_size; + if (((volume->bpb.bytes_per_sector - 1) & next_position) != 0) { + file->cursor.sector += next_position >> volume->bpb.log2_bytes_per_sector; + } else { + file->cursor.sector = -1; + } + file->cursor.position += success_size; + if (file->cursor.position > file->p_sfd->dir_entry.file_size) { + file->p_sfd->dir_entry.file_size = file->cursor.position; + } + PFFILE_Cursor_Recalc(file); + PFCLUSTER_UpdateLastAccessCluster(file); + if (success_size != size) { + return error; + } + return 0; +} + +pf_s32 PFFILE_Cursor_WriteBodySectors(PFFILE_FILE* file, const pf_u8* buffer, pf_u32 size, + pf_u32* size_written) { + pf_s32 error; + pf_u32 num_sectors; + pf_u32 success_size; + pf_u32 next_position; + PF_VOLUME* volume; + + *size_written = 0; + num_sectors = 0; + error = PFFAT_getContinuousSector(&file->p_sfd->ffd, file->cursor.file_sector_index, size, + &file->cursor.sector, &num_sectors); + if (error != 0) { + return error; + } + if (file->cursor.sector == -1) { + file->cursor.position = file->p_sfd->dir_entry.file_size; + PFFILE_Cursor_Recalc(file); + return 0x1C; + } + volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + if (size > (num_sectors << volume->bpb.log2_bytes_per_sector)) { + size = num_sectors << volume->bpb.log2_bytes_per_sector; + } + error = PFSEC_WriteData(volume, buffer, file->cursor.sector, file->cursor.offset_in_sector, + size, &success_size, 1); + if (error != 0 && success_size == 0) { + return error; + } + *size_written = success_size; + next_position = file->cursor.offset_in_sector + success_size; + if (((volume->bpb.bytes_per_sector - 1) & next_position) != 0) { + file->cursor.sector += next_position >> volume->bpb.log2_bytes_per_sector; + } else { + file->cursor.sector = -1; + } + file->cursor.position += success_size; + if (file->cursor.position > file->p_sfd->dir_entry.file_size) { + file->p_sfd->dir_entry.file_size = file->cursor.position; + } + PFFILE_Cursor_Recalc(file); + PFCLUSTER_UpdateLastAccessCluster(file); + if (success_size != size - (size & (volume->bpb.bytes_per_sector - 1))) { + return error; + } + return 0; +} + +pf_s32 PFFILE_Cursor_WriteTailSector(PFFILE_FILE* file, const pf_u8* buffer, pf_u32 size, + pf_u32* size_written) { + pf_s32 error; + pf_u32 success_size; + pf_u32 next_position; + PF_VOLUME* volume; + + *size_written = 0; + if (size == 0) { + return 0; + } + volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + if (size > volume->bpb.bytes_per_sector - file->cursor.offset_in_sector || + size > volume->bpb.bytes_per_sector) { + return 0x1A; + } + if (file->cursor.sector == -1) { + error = PFFAT_GetSectorSpecified(&file->p_sfd->ffd, file->cursor.file_sector_index, 0, + &file->cursor.sector); + if (error != 0) { + return error; + } + if (file->cursor.sector == -1) { + file->cursor.position = file->p_sfd->dir_entry.file_size; + PFFILE_Cursor_Recalc(file); + return 0x1C; + } + } + error = PFSEC_WriteData(volume, buffer, file->cursor.sector, file->cursor.offset_in_sector, size, + &success_size, 1); + if (error != 0 && success_size == 0) { + return error; + } + *size_written = success_size; + volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + next_position = file->cursor.offset_in_sector + success_size; + if (((volume->bpb.bytes_per_sector - 1) & next_position) != 0) { + file->cursor.sector += next_position >> volume->bpb.log2_bytes_per_sector; + } else { + file->cursor.sector = -1; + } + file->cursor.position += success_size; + if (file->cursor.position > file->p_sfd->dir_entry.file_size) { + file->p_sfd->dir_entry.file_size = file->cursor.position; + } + PFFILE_Cursor_Recalc(file); + PFCLUSTER_UpdateLastAccessCluster(file); + if (success_size != size) { + return error; + } + return 0; +} + +pf_s32 PFFILE_Cursor_Write(PFFILE_FILE* file, const pf_u8* buffer, pf_u32 size, + pf_u32* size_written) { + pf_s32 error; + pf_u32 part_size; + pf_u32 num_clusters; + pf_u32 append_size; + pf_u32 append_needed; + pf_u32 allocated_end; + pf_u32 requested_end; + pf_u32 remaining; + PF_VOLUME* volume; + PFFILE_VOLUME_DIRS* volume_dirs; + + file->p_sfd->ffd.p_hint = &file->hint; + *size_written = 0; + if (0xFFFFFFFF - file->cursor.position < size) { + size = 0xFFFFFFFF - file->cursor.position; + pf_vol_set.last_error = 0x25; + volume_dirs = (PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol; + volume_dirs->last_error = 0x25; + file->last_access_data.state.last_error = 0x25; + } + volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + error = PFFILE_Cursor_WriteHeadSector(file, buffer, size, &part_size); + *size_written += part_size; + if (error != 0) { + return error; + } + if (part_size >= size) { + return 0; + } + remaining = size - part_size; + error = PFFAT_CountAllocatedClusters(&file->p_sfd->ffd, + file->cursor.position + remaining, &num_clusters); + if (file == PF_NULL) { + volume = PF_NULL; + } else { + volume = file->p_sfd->dir_entry.p_vol; + } + allocated_end = num_clusters << (volume->bpb.log2_bytes_per_sector + + volume->bpb.log2_sectors_per_cluster); + requested_end = file->cursor.position + remaining; + if (allocated_end < requested_end) { + append_needed = requested_end - allocated_end; + } else { + append_needed = 0; + } + append_size = 0; + while (append_needed != 0 || remaining >= volume->bpb.bytes_per_sector) { + if (append_needed != 0) { + error = PFCLUSTER_AppendCluster(file, append_needed, &append_size); + if (error != 0 && remaining == append_needed) { + return error; + } + if (append_size == 0) { + append_needed = 0; + } + append_needed -= append_size; + } + while (remaining >= append_needed + append_size && + remaining >= volume->bpb.bytes_per_sector) { + error = PFFILE_Cursor_WriteBodySectors(file, buffer + *size_written, remaining, + &part_size); + *size_written += part_size; + if (error != 0) { + return error; + } + if (part_size == 0) { + return 0; + } + remaining -= part_size; + if (remaining == 0) { + break; + } + } + } + error = PFFILE_Cursor_WriteTailSector(file, buffer + *size_written, remaining, &part_size); + *size_written += part_size; + error = error & ((-error | error) >> 31); + return error; +} + +void PFFILE_Cursor_MoveToEnd(PFFILE_FILE* file) { + file->cursor.position = file->p_sfd->dir_entry.file_size; + PFFILE_Cursor_Recalc(file); +} + +void PFFILE_Cursor_MoveToClusterEnd(PFFILE_FILE* file, pf_u32 size) { + PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + pf_u32 num_clusters; + + PFFAT_CountAllocatedClusters(&file->p_sfd->ffd, size, &num_clusters); + if (num_clusters > (0xFFFFFFFF >> (volume->bpb.log2_bytes_per_sector + + volume->bpb.log2_sectors_per_cluster))) { + file->cursor.position = 0xFFFFFFFF; + PFFILE_Cursor_Recalc(file); + } else { + file->cursor.position = num_clusters << (volume->bpb.log2_bytes_per_sector + + volume->bpb.log2_sectors_per_cluster); + PFFILE_Cursor_Recalc(file); + } +} + +PFFILE_SFD* PFFILE_GetSFD(PF_VOLUME* volume, PF_DIR_ENT* entry) { + PFFILE_VOLUME_DIRS* volume_dirs = (PFFILE_VOLUME_DIRS*)volume; + PFFILE_SFD* first_free_sfd = PF_NULL; + PFFILE_SFD* sfd = volume_dirs->sfds; + pf_u32 first_free_index = 0; + pf_u32 index = 0; + + for (; index < 5; index++, sfd++) { + if ((sfd->stat & 1) == 0 || (sfd->stat & 2) == 0) { + if (first_free_sfd == PF_NULL) { + first_free_sfd = sfd; + first_free_index = index; + } + } else if (entry->p_vol == sfd->dir_entry.p_vol && + entry->entry_sector == sfd->dir_entry.entry_sector && + entry->entry_offset == sfd->dir_entry.entry_offset) { + return sfd; + } + } + + if (first_free_sfd == PF_NULL) { + return PF_NULL; + } + first_free_sfd->stat = 3; + first_free_sfd->handler_count = 0; + first_free_sfd->dir_entry = *entry; + first_free_sfd->lock.mode = 0; + first_free_sfd->lock.count = 0; + first_free_sfd->lock.wcount = 0; + first_free_sfd->lock.owner = PF_NULL; + first_free_sfd->lock.resource = 0; + PFFAT_InitFFD(&first_free_sfd->ffd, PF_NULL, entry->p_vol, + &first_free_sfd->dir_entry.start_cluster); + if ((volume_dirs->cluster_link.flag & 1) != 0) { + pf_u32* link_buffer = volume_dirs->cluster_link.buffer + + first_free_index * volume_dirs->cluster_link.link_max; + + first_free_sfd->ffd.cluster_link.buffer = link_buffer; + pf_memset(link_buffer, 0, volume_dirs->cluster_link.link_max << 2); + first_free_sfd->ffd.cluster_link.max_count = volume_dirs->cluster_link.link_max; + first_free_sfd->ffd.cluster_link.interval = volume_dirs->cluster_link.interval; + first_free_sfd->ffd.cluster_link.interval_offset = 0; + first_free_sfd->ffd.cluster_link.position = 0; + first_free_sfd->ffd.cluster_link.save_index = 0; + if (entry->file_size != 0 && first_free_sfd->ffd.cluster_link.max_count != 0) { + *first_free_sfd->ffd.cluster_link.buffer = entry->start_cluster; + first_free_sfd->ffd.cluster_link.position++; + } + } + return first_free_sfd; +} + +pf_s32 PFFILE_createEmptyFile(PF_VOLUME* volume, PF_DIR_ENT* entry, PF_STR* filename) { + PF_DIR_ENT parent_entry = *entry; + PFFILE_FFD ffd; + PF_FAT_HINT hint; + pf_u32 previous_sectors[2]; + pf_u32 entry_position; + pf_u32 num_chars; + pf_u32 num_entries; + pf_u32 ordinal; + pf_u32 sector; + pf_u32 success_size; + pf_s32 error; + pf_u8 short_entry_buffer[13]; + pf_u8 long_entry_buffer[32]; + + num_chars = PFSTR_StrNumChar(filename, 1) & 0xFFFF; + if (num_chars + parent_entry.path_len >= 0x104 || num_chars >= 0x100) { + return 1; + } + PFFAT_InitFFD(&ffd, &hint, parent_entry.p_vol, &parent_entry.start_cluster); + if (((PFFILE_VOLUME_DIRS*)volume)->num_opened_files >= 5) { + return 0x15; + } + error = PFPATH_parseShortName(entry->short_name, filename); + if (error != 0 && entry->short_name[0] == 0) { + return 1; + } + if (error == 0) { + entry->long_name[0] = 0; + } else { + error = PFENT_AdjustSFN(&parent_entry, entry->short_name); + if (error != 0) { + return error; + } + if (PFSTR_GetCodeMode(filename) == 1) { + PFPATH_transformInUnicode(entry, PFSTR_GetStrPos(filename, 1)); + } else { + pf_w_strcpy(entry->long_name, (const pf_u16*)PFSTR_GetStrPos(filename, 1)); + } + } + entry->start_cluster = volume->bpb.fat_type == FAT_32 ? 1 : 0; + entry->file_size = 0; + entry->p_vol = volume; + entry->small_letter_flag = 0; + entry->attr = 0x20; + entry->create_time_ms = PFENT_getcurrentDateTimeForEnt(&entry->create_date, + &entry->create_time); + entry->access_date = entry->create_date; + entry->modify_time = entry->create_time; + entry->modify_date = entry->create_date; + if (entry->long_name[0] != 0 && (entry->small_letter_flag & 0x18) == 0) { + num_entries = num_chars / 13 + (num_chars % 13 != 0); + error = PFENT_allocateEntryPos(entry, (num_entries + 1) & 0xFF, &ffd, + previous_sectors, filename, &entry_position); + if (error != 0) { + return error; + } + if ((pf_vol_set.file_settings & 2) != 0) { + PFPATH_AdjustExtShortName(entry->short_name, entry_position); + } + entry->num_entry_LFNs = num_entries; + sector = entry->entry_sector; + for (ordinal = num_entries; ordinal != 0; ordinal--) { + PFENT_storeLFNEntryFieldsToBuf(long_entry_buffer, entry, ordinal, + PFENT_CalcCheckSum(entry), ordinal == num_entries); + error = PFSEC_WriteData(volume, long_entry_buffer, sector, entry->entry_offset, + 0x20, &success_size, 0); + if (error != 0) { + return error; + } + if (success_size != 0x20) { + return 0x11; + } + entry->entry_offset += 0x20; + if (entry->entry_offset >= volume->bpb.bytes_per_sector) { + entry->entry_offset = 0; + sector = previous_sectors[0]; + previous_sectors[0] = previous_sectors[1]; + } + } + entry->entry_sector = sector; + } else { + error = PFENT_allocateEntry(entry, 1, &ffd, previous_sectors, filename); + if (error != 0) { + return error; + } + } + if (entry->start_cluster == 1) { + entry->start_cluster = 0; + } + return PFENT_updateEntry(entry, 1); +} + +pf_s32 PFFILE_p_remove(PF_VOLUME* volume, PF_STR* path) { + PF_STR directory; + PF_STR filename; + PF_DIR_ENT entry; + PFFILE_ENT_ITER iter; + PFFILE_VOLUME_DIRS* volume_dirs = (PFFILE_VOLUME_DIRS*)volume; + pf_s32 error; + pf_u32 index; + + error = PFPATH_SplitPath(path, &directory, &filename); + if (error != 0) { + return error; + } + error = PFENT_ITER_GetEntryOfPath(&iter, &entry, volume, path, 0); + if (error != 0) { + return error; + } + if ((entry.attr & 0x19) != 0) { + return 0xB; + } + for (index = 0; index < 5; index++) { + if ((volume_dirs->sfds[index].stat & 1) != 0 && + (volume_dirs->sfds[index].stat & 2) != 0 && + entry.p_vol == volume_dirs->sfds[index].dir_entry.p_vol && + entry.entry_sector == volume_dirs->sfds[index].dir_entry.entry_sector && + entry.entry_offset == volume_dirs->sfds[index].dir_entry.entry_offset) { + return 0x13; + } + } + error = PFENT_RemoveEntry(&entry, &iter); + if (error != 0) { + return error; + } + return PFFAT_FreeChain(&iter.ffd, entry.start_cluster, 0xFFFFFFFF, entry.file_size); +} + +pf_s32 PFFILE_p_fopen(PF_VOLUME* volume, PF_STR* path, pf_u32 open_mode, + PFFILE_FILE** result) { + PF_STR directory; + PF_STR filename; + PF_DIR_ENT entry; + PFFILE_ENT_ITER iter; + PFFILE_FFD ffd; + PF_FAT_HINT hint; + PFFILE_SFD* sfd; + PFFILE_FILE* file; + pf_s8 normalized_filename[0x200]; + pf_u32 num_chars; + pf_u32 index; + pf_u32 success_size; + pf_u16 access_time; + pf_s32 error; + + *result = PF_NULL; + error = PFPATH_SplitPath(path, &directory, &filename); + if (error != 0) { + return 1; + } + error = PFENT_ITER_GetEntryOfPath(&iter, &entry, volume, path, 1); + if (error != 0) { + return error; + } + if ((entry.attr & 0x10) == 0) { + return 1; + } + if (PFSTR_GetCodeMode(&filename) == 2) { + num_chars = PFSTR_StrNumChar(&filename, 1) & 0xFFFF; + if (num_chars > 0xFF) { + return 1; + } + PFPATH_transformFromUnicodeToNormal(normalized_filename, + (const pf_u16*)PFSTR_GetStrPos(&filename, 1)); + } + PFSTR_SetLocalStr(&filename, normalized_filename); + if ((open_mode & 2) == 0) { + error = PFFILE_createEmptyFile(volume, &entry, &filename); + if (error == 8) { + if ((open_mode & 0x10) != 0) { + return 8; + } + if ((open_mode & 1) != 0) { + for (index = 0; index < 5; index++) { + if ((((PFFILE_VOLUME_DIRS*)entry.p_vol)->sfds[index].stat & 3) == 3 && + entry.p_vol == + ((PFFILE_VOLUME_DIRS*)entry.p_vol)->sfds[index].dir_entry.p_vol && + entry.entry_sector == + ((PFFILE_VOLUME_DIRS*)entry.p_vol)->sfds[index].dir_entry.entry_sector && + entry.entry_offset == + ((PFFILE_VOLUME_DIRS*)entry.p_vol)->sfds[index].dir_entry.entry_offset) { + return 8; + } + } + } + if ((entry.attr & 1) != 0 && + ((open_mode & 1) != 0 || (open_mode & 4) != 0 || (open_mode & 8) != 0)) { + return 0xA; + } + if ((entry.attr & 0x10) != 0) { + return 0x17; + } + if ((open_mode & 1) != 0) { + PFFAT_InitFFD(&ffd, &hint, entry.p_vol, &entry.start_cluster); + if (entry.start_cluster > 1 && entry.start_cluster != 0xFFFFFFFF && + entry.file_size != 0) { + PFFAT_FreeChain(&ffd, entry.start_cluster, 0xFFFFFFFF, entry.file_size); + } + entry.start_cluster = 0; + entry.file_size = 0; + PFENT_getcurrentDateTimeForEnt(&entry.modify_date, &entry.modify_time); + entry.access_date = entry.modify_date; + } else { + PFENT_getcurrentDateTimeForEnt(&entry.access_date, &access_time); + } + } else if (error != 0) { + return error; + } + } else { + PFFAT_InitFFD(&ffd, &hint, entry.p_vol, &entry.start_cluster); + error = PFENT_findEntry(&ffd, &entry, 0, &filename, 0x7F, 0); + if (error != 0) { + return 3; + } + if ((open_mode & 8) != 0 && (entry.attr & 1) != 0) { + return 0xA; + } + if ((entry.attr & 0x10) != 0) { + return 0x17; + } + PFENT_getcurrentDateTimeForEnt(&entry.access_date, &access_time); + } + volume = entry.p_vol; + sfd = PFFILE_GetSFD(volume, &entry); + if (sfd == PF_NULL) { + return 0x15; + } + file = PF_NULL; + for (index = 0; index < 5; index++) { + if ((((PFFILE_VOLUME_DIRS*)volume)->ufds[index].stat & 1) == 0) { + file = &((PFFILE_VOLUME_DIRS*)volume)->ufds[index]; + break; + } + } + if (file == PF_NULL) { + return 0x16; + } + file->p_sfd = sfd; + file->stat = 1; + file->open_mode = open_mode; + file->last_access_data.state.last_access_chain_index = 0; + file->last_access_data.state.last_error = 0; + file->lock_count = 0; + PFFAT_InitHint(&file->hint); + file->cursor.position = 0; + file->cursor.sector = 0xFFFFFFFF; + PFFILE_Cursor_Recalc(file); + if ((open_mode & 1) != 0) { + sfd->stat |= 4; + } + if ((open_mode & 4) != 0) { + file->cursor.position = entry.file_size; + PFFILE_Cursor_Recalc(file); + } + sfd->handler_count++; + *result = file; + return 0; +} + +pf_s32 PFFILE_p_fread(PF_VOLUME* volume, pf_u8* buffer, pf_u32 size, pf_u32 count, + PFFILE_FILE* file, pf_u32* count_read); + +pf_s32 PFFILE_p_fwrite(PF_VOLUME* volume, const pf_u8* buffer, pf_u32 size, pf_u32 count, + PFFILE_FILE* file, pf_u32* count_written) { + PF_CACHE_PAGE* page; + pf_u32 allocation_option; + pf_u32 bytes_written = 0; + pf_u32 remaining; + pf_s32 error; + + *count_written = 0; + if ((file->open_mode & 8) == 0 && (file->open_mode & 2) != 0) { + return 0xA; + } + if ((file->p_sfd->lock.mode & 3) != 0 && + ((file->p_sfd->lock.mode & 1) != 0 || + ((file->p_sfd->lock.mode & 2) != 0 && file->lock_count == 0))) { + return 0x19; + } + if ((file->open_mode & 4) != 0) { + file->cursor.position = file->p_sfd->dir_entry.file_size; + PFFILE_Cursor_Recalc(file); + } + if (file->cursor.position > file->p_sfd->dir_entry.file_size) { + remaining = file->cursor.position - file->p_sfd->dir_entry.file_size; + file->cursor.position = file->p_sfd->dir_entry.file_size; + PFFILE_Cursor_Recalc(file); + error = PFCACHE_AllocateDataPage(volume, 0xFFFFFFFF, &page, &allocation_option); + if (error != 0) { + return error; + } + pf_memset(page->p_buf, 0, volume->bpb.bytes_per_sector); + while (remaining != 0) { + if (remaining <= volume->bpb.bytes_per_sector) { + error = PFFILE_Cursor_Write(file, page->p_buf, remaining, &bytes_written); + if (error != 0) { + return error; + } + break; + } + error = PFFILE_Cursor_Write(file, page->p_buf, volume->bpb.bytes_per_sector, + &bytes_written); + if (error != 0) { + return error; + } + remaining -= volume->bpb.bytes_per_sector; + } + PFCACHE_FreeDataPage(volume, page); + } + error = PFFILE_Cursor_Write(file, buffer, size * count, &bytes_written); + *count_written = bytes_written / size; + return error; +} + +pf_s32 PFFILE_p_fappend(PFFILE_FILE* file, pf_u32 size, pf_u32* size_appended) { + pf_u32 max_size; + pf_u32 appended_size; + pf_s32 error; + + *size_appended = 0; + if ((file->open_mode & 8) == 0 && (file->open_mode & 2) != 0) { + return 0xA; + } + if ((file->p_sfd->lock.mode & 3) != 0 && + ((file->p_sfd->lock.mode & 1) != 0 || + ((file->p_sfd->lock.mode & 2) != 0 && file->lock_count == 0))) { + return 0x19; + } + file->p_sfd->ffd.p_hint = &file->hint; + max_size = 0xFFFFFFFF - file->cursor.position; + if (max_size < size) { + size = max_size; + pf_vol_set.last_error = 0x25; + ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = 0x25; + file->last_access_data.state.last_error = 0x25; + } + error = PFCLUSTER_AppendCluster(file, size, &appended_size); + *size_appended = appended_size; + if (error != 0) { + return error; + } + return 0; +} + +pf_s32 PFFILE_p_finfo(PFFILE_FILE* file, PF_INFO* info) { + PF_VOLUME* volume; + pf_u32 cluster_size; + pf_u32 file_size_remainder; + pf_u32 file_size; + pf_u32 nonempty_bytes; + pf_s32 sign_bits; + pf_s32 error; + + file->p_sfd->ffd.p_hint = &file->hint; + volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + info->file_size = file->p_sfd->dir_entry.file_size; + info->io_pointer = file->cursor.position; + cluster_size = volume->bpb.bytes_per_sector << volume->bpb.log2_sectors_per_cluster; + if (file->p_sfd->dir_entry.start_cluster != 0) { + error = PFCLUSTER_GetAppendSize(file, &info->allocated_size); + if (error != 0) { + return error; + } + file_size = file->p_sfd->dir_entry.file_size; + file_size_remainder = file_size % cluster_size; + nonempty_bytes = cluster_size - file_size_remainder; + sign_bits = -(pf_s32)file_size_remainder | (pf_s32)file_size_remainder; + info->empty_size = info->allocated_size + (nonempty_bytes & (sign_bits >> 31)); + } else { + info->allocated_size = 0; + info->empty_size = 0; + } + info->lock_mode = file->p_sfd->lock.mode & 3; + info->lock_owner = file->p_sfd->lock.owner; + info->lock_count = file->lock_count; + info->lock_tcount = file->p_sfd->lock.count; + return 0; +} + +pf_s32 PFFILE_p_combine(PF_VOLUME* volume, PF_STR* first_path, PF_STR* second_path) { + PFFILE_ENT_ITER first_iter; + PFFILE_ENT_ITER second_iter; + PFFILE_ENT_ITER second_iter_copy; + PF_DIR_ENT first_entry; + PF_DIR_ENT second_entry; + PFFILE_FFD first_ffd; + PFFILE_FFD second_ffd; + PF_FAT_HINT first_hint; + PF_FAT_HINT second_hint; + pf_u32 index; + pf_s32 error; + + error = PFENT_ITER_GetEntryOfPath(&first_iter, &first_entry, volume, first_path, 0); + if (error != 0) { + return error; + } + error = PFENT_ITER_GetEntryOfPath(&second_iter, &second_entry, volume, second_path, 0); + if (error != 0) { + return error; + } + if ((first_entry.attr & 0x10) != 0 || (second_entry.attr & 0x10) != 0) { + return 0x17; + } + if ((first_entry.attr & 1) != 0 || (second_entry.attr & 1) != 0) { + return 0x18; + } + for (index = 0; index < 5; index++) { + PFFILE_SFD* sfd = &((PFFILE_VOLUME_DIRS*)first_entry.p_vol)->sfds[index]; + + if ((sfd->stat & 3) == 3 && first_entry.p_vol == sfd->dir_entry.p_vol && + first_entry.entry_sector == sfd->dir_entry.entry_sector && + first_entry.entry_offset == sfd->dir_entry.entry_offset) { + return 0x13; + } + } + for (index = 0; index < 5; index++) { + PFFILE_SFD* sfd = &((PFFILE_VOLUME_DIRS*)second_entry.p_vol)->sfds[index]; + + if ((sfd->stat & 3) == 3 && second_entry.p_vol == sfd->dir_entry.p_vol && + second_entry.entry_sector == sfd->dir_entry.entry_sector && + second_entry.entry_offset == sfd->dir_entry.entry_offset) { + return 0x13; + } + } + if (first_entry.entry_sector == second_entry.entry_sector && + first_entry.entry_offset == second_entry.entry_offset) { + return 0xA; + } + if (0xFFFFFFFF - second_entry.file_size < first_entry.file_size) { + return 0x25; + } + PFFAT_InitHint(&first_hint); + PFFAT_InitFFD(&first_ffd, &first_hint, volume, &first_entry.start_cluster); + PFFAT_InitHint(&second_hint); + PFFAT_InitFFD(&second_ffd, &second_hint, volume, &second_entry.start_cluster); + pf_memcpy(&second_iter_copy, &second_iter, sizeof(second_iter_copy)); + error = PFENT_RemoveEntry(&second_entry, &second_iter); + if (error != 0) { + return error; + } + error = PFCLUSTER_CombineFiles(&first_iter, &second_iter_copy, &first_entry, &second_entry); + if (error != 0) { + return error; + } + PFENT_getcurrentDateTimeForEnt(&first_entry.modify_date, &first_entry.modify_time); + first_entry.access_date = first_entry.modify_date; + error = PFENT_updateEntry(&first_entry, 1); + return error & (-error | error) >> 31; +} + +pf_s32 PFFILE_p_divide(PF_VOLUME* volume, PF_STR* source_path, PF_STR* destination_path, + pf_u32 split_size) { + PF_STR destination_directory; + PF_STR destination_filename; + PF_DIR_ENT source_entry; + PF_DIR_ENT source_entry_copy; + PF_DIR_ENT destination_entry; + PFFILE_ENT_ITER source_iter; + PFFILE_ENT_ITER destination_iter; + PFFILE_ENT_ITER destination_file_iter; + PFFILE_FFD source_ffd; + PFFILE_FFD destination_ffd; + PF_FAT_HINT source_hint; + PF_FAT_HINT destination_hint; + pf_s8 normalized_filename[0x200]; + pf_u32 original_start_cluster; + pf_u32 original_size; + pf_u32 index; + pf_u16 current_time; + pf_s32 error; + + error = PFENT_ITER_GetEntryOfPath(&source_iter, &source_entry, volume, source_path, 0); + if (error != 0) { + return error; + } + if ((source_entry.attr & 0x10) != 0) { + return 0x17; + } + if ((source_entry.attr & 1) != 0) { + return 0x18; + } + for (index = 0; index < 5; index++) { + if ((((PFFILE_VOLUME_DIRS*)source_entry.p_vol)->sfds[index].stat & 3) == 3 && + source_entry.p_vol == + ((PFFILE_VOLUME_DIRS*)source_entry.p_vol)->sfds[index].dir_entry.p_vol && + source_entry.entry_sector == + ((PFFILE_VOLUME_DIRS*)source_entry.p_vol)->sfds[index].dir_entry.entry_sector && + source_entry.entry_offset == + ((PFFILE_VOLUME_DIRS*)source_entry.p_vol)->sfds[index].dir_entry.entry_offset) { + return 0x13; + } + } + if (source_entry.file_size == 0) { + return 0xA; + } + if (source_entry.file_size < split_size) { + return 0xA; + } + error = PFPATH_SplitPath(destination_path, &destination_directory, &destination_filename); + if (error != 0) { + return 1; + } + if (PFSTR_GetCodeMode(&destination_filename) == 2) { + if ((PFSTR_StrNumChar(&destination_filename, 1) & 0xFFFF) > 0xFF) { + return 1; + } + PFPATH_transformFromUnicodeToNormal( + normalized_filename, (const pf_u16*)PFSTR_GetStrPos(&destination_filename, 1)); + } + PFSTR_SetLocalStr(&destination_filename, normalized_filename); + error = PFENT_ITER_GetEntryOfPath(&destination_iter, &destination_entry, volume, + destination_path, 1); + if (error != 0) { + return error; + } + if ((destination_entry.attr & 0x10) == 0) { + return 1; + } + error = PFFILE_createEmptyFile(volume, &destination_entry, &destination_filename); + if (error != 0) { + return error; + } + PFFAT_InitHint(&destination_hint); + PFFAT_InitFFD(&destination_ffd, &destination_hint, volume, &destination_entry.start_cluster); + PFFAT_InitHint(&source_hint); + PFFAT_InitFFD(&source_ffd, &source_hint, volume, &source_entry.start_cluster); + pf_memcpy(&source_entry_copy, &source_entry, sizeof(source_entry_copy)); + original_start_cluster = source_entry.start_cluster; + original_size = source_entry.file_size; + PFENT_getcurrentDateTimeForEnt(&source_entry.modify_date, &source_entry.modify_time); + source_entry.access_date = source_entry.modify_date; + if (split_size == 0) { + source_entry.start_cluster = 0; + } + source_entry.file_size = split_size; + error = PFENT_updateEntry(&source_entry, 1); + if (error == 0 && + ((((PFFILE_VOLUME_DIRS*)volume)->cache_control & 4) == 0 || + PFCACHE_FlushDataCacheSpecific(volume, 0) == 0)) { + error = PFCLUSTER_DivideFile(&source_iter, &destination_iter, &source_entry_copy, + &destination_entry, split_size); + if (error == 0) { + destination_entry.create_time = source_entry.modify_time; + destination_entry.create_date = source_entry.modify_date; + destination_entry.modify_time = source_entry.modify_time; + destination_entry.modify_date = source_entry.modify_date; + destination_entry.access_date = source_entry.access_date; + destination_entry.attr = source_entry.attr; + error = PFENT_updateEntry(&destination_entry, 1); + return error & (-error | error) >> 31; + } + PFCACHE_FlushFATCache(volume); + source_entry.start_cluster = original_start_cluster; + source_entry.file_size = original_size; + PFENT_updateEntry(&source_entry, 1); + error = PFENT_ITER_GetEntryOfPath(&destination_file_iter, &destination_entry, volume, + destination_path, 0); + if (error == 0) { + PFENT_RemoveEntry(&destination_entry, &destination_file_iter); + } + } + return error; +} + +pf_s32 PFFILE_p_cinsert(PF_VOLUME* volume, PF_STR* path, pf_u32 cluster_index, + pf_u32 count, pf_u32 mode) { + PFFILE_ENT_ITER iter; + PF_DIR_ENT entry; + PFFILE_FAT_HINT hint; + pf_u32 cluster_bytes; + pf_u32 required_clusters; + pf_u32 remainder; + pf_s32 error; + + error = PFENT_ITER_GetEntryOfPath(&iter, &entry, volume, path, 0); + if (error != 0) { + return error; + } + if ((entry.attr & 0x10) != 0) { + return 0x17; + } + if ((entry.attr & 1) != 0) { + return 0x18; + } + if (PFFILE_IsOpened(&entry)) { + return 0x13; + } + cluster_bytes = volume->bpb.bytes_per_sector << volume->bpb.log2_sectors_per_cluster; + required_clusters = entry.file_size / cluster_bytes; + remainder = entry.file_size - required_clusters * cluster_bytes; + if (remainder != 0) { + required_clusters++; + } + if (required_clusters < cluster_index) { + return 10; + } + PFFAT_InitHint(&hint); + PFFAT_InitFFD(&iter.ffd, &hint, volume, &entry.start_cluster); + error = PFCLUSTER_InsertCluster(&iter, &entry, cluster_index, count, mode); + if (error != 0) { + return error; + } + PFENT_getcurrentDateTimeForEnt(&entry.modify_date, &entry.modify_time); + entry.access_date = entry.modify_date; + error = PFENT_updateEntry(&entry, 1); + return error & (-error | error) >> 31; +} + +pf_s32 PFFILE_p_cdelete(PF_VOLUME* volume, PF_STR* path, pf_u32 cluster_index, + pf_u32 count, pf_u32 mode) { + PFFILE_ENT_ITER iter; + PF_DIR_ENT entry; + PFFILE_FAT_HINT hint; + pf_u32 cluster_bytes; + pf_u32 required_clusters; + pf_u32 remainder; + pf_s32 error; + + error = PFENT_ITER_GetEntryOfPath(&iter, &entry, volume, path, 0); + if (error != 0) { + return error; + } + if ((entry.attr & 0x10) != 0) { + return 0x17; + } + if ((entry.attr & 1) != 0) { + return 0x18; + } + if (PFFILE_IsOpened(&entry)) { + return 0x13; + } + if (entry.file_size == 0) { + return 10; + } + cluster_bytes = volume->bpb.bytes_per_sector << volume->bpb.log2_sectors_per_cluster; + required_clusters = entry.file_size / cluster_bytes; + remainder = entry.file_size - required_clusters * cluster_bytes; + if (remainder != 0) { + required_clusters++; + } + if (required_clusters <= cluster_index) { + return 10; + } + PFFAT_InitHint(&hint); + PFFAT_InitFFD(&iter.ffd, &hint, volume, &entry.start_cluster); + error = PFCLUSTER_DeleteCluster(&iter, &entry, cluster_index, count, mode); + return error & (-error | error) >> 31; +} + +pf_s32 PFFILE_p_flock(PFFILE_FILE* file, pf_u32 mode) { + if ((mode & 3) != 0) { + if ((file->p_sfd->lock.mode & 3) != 0 && (mode & 0x10) != 0) { + if ((mode & 1) != 0) { + if ((file->p_sfd->lock.mode & 2) != 0) { + return 0x27; + } + } else if ((mode & 2) != 0 && (file->p_sfd->lock.mode & 1) != 0) { + return 0x27; + } + if (file->p_sfd->lock.owner != 0 && file->p_sfd->lock.owner != (PF_FILE*)file) { + return 0x27; + } + } + if ((mode & 1) != 0) { + if (file->p_sfd->lock.count == 0 || (file->p_sfd->lock.mode & 2) == 0) { + file->p_sfd->lock.wcount++; + PF_LockFile((PF_FILE*)file, 0); + file->p_sfd->lock.wcount--; + file->p_sfd->lock.mode = 1; + file->p_sfd->lock.owner = 0; + } + } else if (file->p_sfd->lock.owner != (PF_FILE*)file) { + file->p_sfd->lock.wcount++; + PF_LockFile((PF_FILE*)file, (PF_FILE*)file); + file->p_sfd->lock.wcount--; + file->p_sfd->lock.mode = 2; + file->p_sfd->lock.owner = (PF_FILE*)file; + } + file->p_sfd->lock.count++; + file->lock_count++; + return 0; + } + if (file->lock_count == 0 || file->p_sfd->lock.count == 0) { + return 0x27; + } + if ((file->p_sfd->lock.mode & 2) != 0 && file->p_sfd->lock.owner != (PF_FILE*)file) { + return 0x27; + } + if ((file->p_sfd->lock.mode & 1) != 0) { + file->p_sfd->lock.count -= file->lock_count; + file->lock_count = 0; + if (file->p_sfd->lock.count == 0) { + PF_UnLockFile((PF_FILE*)file); + } + file->p_sfd->lock.mode &= ~3; + } else { + if (file->p_sfd->lock.owner != (PF_FILE*)file) { + return 0x27; + } + file->p_sfd->lock.count = 0; + file->lock_count = 0; + file->p_sfd->lock.owner = 0; + PF_UnLockFile((PF_FILE*)file); + file->p_sfd->lock.mode &= ~3; + } + return 0; +} + +static PFFILE_FILE* PFFILE_GetFreeUFD(PF_VOLUME* volume) { + PFFILE_VOLUME_DIRS* volume_dirs = (PFFILE_VOLUME_DIRS*)volume; + pf_u32 index; + + for (index = 0; index < 5; index++) { + if ((volume_dirs->ufds[index].stat & 1) == 0) { + return &volume_dirs->ufds[index]; + } + } + return PF_NULL; +} + +pf_s32 PFFILE_FsexecOpenFile(PF_DIR_ENT* entry, PFFILE_ENT_ITER* iter, + pf_u32 mode, PF_DTA* data) { + PF_VOLUME* volume = entry->p_vol; + PFFILE_SFD* sfd; + PFFILE_FILE* file; + pf_u16 access_time; + pf_u32 start_cluster; + + data->p_file = PF_NULL; + if ((entry->attr & 0x10) != 0) { + return 0x17; + } + if ((entry->attr & 1) != 0 && + ((mode & 1) != 0 || (mode & 4) != 0 || (mode & 8) != 0)) { + return 10; + } + if ((mode & 1) != 0 && PFFILE_IsOpened(entry)) { + return 8; + } + if ((mode & 1) != 0) { + start_cluster = entry->start_cluster; + if (start_cluster >= 2 && start_cluster != 0xFFFFFFFF && entry->file_size != 0) { + PFFAT_FreeChain(&iter->ffd, start_cluster, -1, entry->file_size); + } + entry->start_cluster = 0; + entry->file_size = 0; + PFENT_getcurrentDateTimeForEnt(&entry->modify_date, &entry->modify_time); + entry->access_date = entry->modify_date; + } else { + PFENT_getcurrentDateTimeForEnt(&entry->access_date, &access_time); + } + sfd = PFFILE_GetSFD(volume, entry); + if (sfd == PF_NULL) { + return 0x15; + } + file = PFFILE_GetFreeUFD(volume); + if (file == PF_NULL) { + return 0x16; + } + file->p_sfd = sfd; + file->stat = 1; + file->open_mode = mode; + file->lock_count = 0; + PFFAT_InitHint(&file->hint); + file->cursor.sector = 0xFFFFFFFF; + file->last_access_data.state.last_error = 0; + file->cursor.position = 0; + PFFILE_Cursor_Recalc(file); + if ((mode & 1) != 0) { + sfd->stat |= 4; + } + if ((mode & 4) != 0) { + PFFILE_Cursor_MoveToEnd(file); + } + data->p_file = (PF_FILE*)file; + return 0; +} + +pf_bool PFFILE_IsOpened(PF_DIR_ENT* entry) { + PFFILE_VOLUME_DIRS* volume_dirs = (PFFILE_VOLUME_DIRS*)entry->p_vol; + pf_u32 index; + + for (index = 0; index < 5; index++) { + PFFILE_SFD* sfd = &volume_dirs->sfds[index]; + + if ((sfd->stat & 1) != 0 && (sfd->stat & 2) != 0 && + entry->p_vol == sfd->dir_entry.p_vol && entry->entry_sector == sfd->dir_entry.entry_sector && + entry->entry_offset == sfd->dir_entry.entry_offset) { + return PF_TRUE; + } + } + return PF_FALSE; +} + +void PFFILE_FinalizeAllFiles(PF_VOLUME* volume) { + PFFILE_VOLUME_DIRS* volume_dirs = (PFFILE_VOLUME_DIRS*)volume; + pf_u16 index; + + for (index = 0; index < 5; index++) { + PFFILE_SFD* sfd = &volume_dirs->sfds[index]; + + sfd->stat = 0; + PFFAT_FinalizeFFD(&sfd->ffd); + } + for (index = 0; index < 5; index++) { + volume_dirs->ufds[index].stat &= ~1U; + } + volume_dirs->num_opened_files = 0; +} + +pf_s32 PFFILE_remove(PF_STR* path) { + PF_VOLUME* volume; + pf_s32 error; + + volume = PFPATH_GetVolumeFromPath(path); + error = PFVOL_CheckForWrite(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + return error; + } + ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = 0; + error = PFFILE_p_remove(volume, path); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + return error; + } + error = PFCACHE_FlushFATCache(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + } + return error; +} + +pf_s32 PFFILE_ferror(PFFILE_FILE* file) { + PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + pf_s32 error; + + error = PFVOL_CheckForRead(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + return -1; + } + if ((file->p_sfd->stat & 1) == 0 || (file->p_sfd->stat & 2) == 0) { + pf_vol_set.last_error = 0x26; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = 0x26; + return -1; + } + return file->last_access_data.state.last_error; +} + +pf_s32 PFFILE_fopen(PF_STR* path, pf_s32 mode, PFFILE_FILE** result) { + PF_VOLUME* volume; + pf_s32 error; + + *result = PF_NULL; + volume = PFPATH_GetVolumeFromPath(path); + error = PFVOL_CheckForWrite(volume); + if (error != 0 && (error != 0x0B || mode != 2)) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + return error; + } + error = PFFILE_p_fopen(volume, path, mode, result); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + } else { + ((PFFILE_VOLUME_DIRS*)volume)->num_opened_files++; + } + return error; +} + +pf_s32 PFFILE_fclose(PFFILE_FILE* file) { + PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + PFFILE_VOLUME_DIRS* volume_dirs; + pf_s32 error; + + error = PFVOL_CheckForWrite(volume); + if (error != 0 && (error != 0x0B || file->open_mode != 2)) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + return error; + } + volume_dirs = (PFFILE_VOLUME_DIRS*)volume; + if ((file->p_sfd->stat & 1) == 0 || (file->p_sfd->stat & 2) == 0) { + pf_vol_set.last_error = 10; + volume_dirs->last_error = 10; + return 10; + } + volume_dirs->cache_signature = file; + if (file->p_sfd->handler_count <= 1 && (file->p_sfd->dir_entry.attr & 0x19) == 0 && + PFVOL_CheckForWrite(volume) == 0 && + ((file->p_sfd->stat & 4) != 0 || (volume_dirs->file_config & 1) != 1)) { + error = PFENT_updateEntry(&file->p_sfd->dir_entry, 1); + } else { + error = 0; + } + if (file->lock_count != 0) { + if ((file->p_sfd->lock.mode & 1) != 0) { + file->p_sfd->lock.count -= file->lock_count; + file->lock_count = 0; + if (file->p_sfd->lock.count == 0) { + PF_UnLockFile((PF_FILE*)file); + } + file->p_sfd->lock.mode &= ~3; + } else if (file->p_sfd->lock.owner != (PF_FILE*)file) { + error = 0x19; + } else { + file->p_sfd->lock.count = 0; + file->lock_count = 0; + file->p_sfd->lock.owner = 0; + PF_UnLockFile((PF_FILE*)file); + file->p_sfd->lock.mode &= ~3; + } + } + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = error; + file->last_access_data.state.last_error = error; + } else if ((volume_dirs->cache_control & 2) != 0) { + error = PFCACHE_FlushFATCache(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = error; + file->last_access_data.state.last_error = error; + } else { + error = PFCACHE_FlushDataCacheSpecific(volume, file); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = error; + file->last_access_data.state.last_error = error; + } + } + } + if (error == 0) { + file->p_sfd->handler_count--; + if (file->p_sfd->handler_count == 0) { + file->p_sfd->stat &= ~1U; + file->p_sfd->ffd.cluster_link.buffer = PF_NULL; + } + file->stat &= ~1U; + volume_dirs->num_opened_files--; + } + volume_dirs->cache_signature = PF_NULL; + return error; +} + +pf_s32 PFFILE_fread(pf_u8* buffer, pf_u32 size, pf_u32 count, + PFFILE_FILE* file, pf_u32* count_read) { + PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + pf_s32 error; + + *count_read = 0; + error = PFVOL_CheckForRead(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + return error; + } + if ((file->p_sfd->stat & 1) == 0 || (file->p_sfd->stat & 2) == 0) { + pf_vol_set.last_error = 0x26; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = 0x26; + return 0x26; + } + ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = file; + error = PFFILE_p_fread(volume, buffer, size, count, file, count_read); + ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = PF_NULL; + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = error; + file->last_access_data.state.last_error = error; + } + return error; +} + +pf_s32 PFFILE_fwrite(const pf_u8* buffer, pf_u32 size, pf_u32 count, + PFFILE_FILE* file, pf_u32* count_written) { + PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + pf_u32 bytes_written; + pf_s32 error; + + *count_written = 0; + error = PFVOL_CheckForWrite(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + return error; + } + if ((file->p_sfd->stat & 1) == 0 || (file->p_sfd->stat & 2) == 0) { + pf_vol_set.last_error = 0x26; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = 0x26; + return 0x26; + } + ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = file; + error = PFFILE_p_fwrite(volume, buffer, size, count, file, &bytes_written); + *count_written = bytes_written; + ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = PF_NULL; + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = error; + file->last_access_data.state.last_error = error; + } + if (bytes_written != 0) { + PFENT_getcurrentDateTimeForEnt(&file->p_sfd->dir_entry.modify_date, + &file->p_sfd->dir_entry.modify_time); + file->p_sfd->dir_entry.access_date = file->p_sfd->dir_entry.modify_date; + file->p_sfd->stat |= 4; + } + return error; +} + +pf_s32 PFFILE_feof(PFFILE_FILE* file) { + PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + pf_s32 error; + + error = PFVOL_CheckForRead(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + return error; + } + if ((file->p_sfd->stat & 1) == 0 || (file->p_sfd->stat & 2) == 0) { + pf_vol_set.last_error = 0x26; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = 0x26; + return 0x26; + } + if (file->cursor.position < file->p_sfd->dir_entry.file_size) { + return 0; + } + return 1; +} + +pf_s32 PFFILE_fseek(PFFILE_FILE* file, pf_s32 offset, pf_s32 origin) { + PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + pf_s32 error = 0; + pf_u32 file_io; + pf_u32 wk_offset; + + error = PFVOL_CheckForRead(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + return error; + } + if ((file->p_sfd->stat & 1) == 0 || (file->p_sfd->stat & 2) == 0) { + pf_vol_set.last_error = 0x26; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = 0x26; + return 0x26; + } + switch (origin) { + case 1: + file_io = file->cursor.position; + break; + case 0: + file_io = 0; + break; + case 2: + file_io = file->p_sfd->dir_entry.file_size; + break; + default: + return file->last_access_data.state.last_error = + ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = + pf_vol_set.last_error = 0x0A; + } + if (((pf_u32)offset & 0x80000000) != 0) { + wk_offset = ~((pf_u32)offset | (pf_u32)offset) & 0x7FFFFFFF; + wk_offset += 1; + if (file_io < wk_offset) { + return file->last_access_data.state.last_error = + ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = + pf_vol_set.last_error = 0x0A; + } + file_io -= wk_offset; + } else { + wk_offset = 0xFFFFFFFF - file_io; + if ((pf_u32)offset > wk_offset) { + return file->last_access_data.state.last_error = + ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = + pf_vol_set.last_error = 0x25; + } + file_io += offset; + } + file->cursor.sector = 0xFFFFFFFF; + file->cursor.position = 0; + PFFILE_Cursor_Recalc(file); + file->cursor.position = file_io; + PFFILE_Cursor_Recalc(file); + return error; +} + +pf_s32 PFFILE_fsetclstlink(PFFILE_FILE* file, pf_u32 mode, + PFFILE_CLUSTER_LINK_SETTINGS* settings) { + PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + pf_s32 error; + + error = PFVOL_CheckForRead(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + return error; + } + if (mode == 1) { + file->p_sfd->ffd.cluster_link.buffer = settings->buffer; + pf_memset(settings->buffer, 0, settings->link_max * 4); + file->p_sfd->ffd.cluster_link.max_count = settings->link_max; + file->p_sfd->ffd.cluster_link.interval = settings->interval; + file->p_sfd->ffd.cluster_link.interval_offset = 0; + file->p_sfd->ffd.cluster_link.position = 0; + file->p_sfd->ffd.cluster_link.save_index = 0; + if (file->p_sfd->dir_entry.file_size != 0 && settings->link_max != 0) { + settings->buffer[0] = *file->p_sfd->ffd.p_start_cluster; + file->p_sfd->ffd.cluster_link.position++; + } + if (file->p_sfd->ffd.p_hint != PF_NULL) { + PFFILE_FAT_HINT* hint = (PFFILE_FAT_HINT*)file->p_sfd->ffd.p_hint; + hint->chain_index = 0; + hint->cluster = 0; + hint->previous_cluster = 0; + } + file->p_sfd->ffd.last_cluster.num_last_cluster = 0; + file->p_sfd->ffd.last_cluster.max_chain_index = 0; + file->p_sfd->ffd.last_access_cluster.chain_index = 0; + file->p_sfd->ffd.last_access_cluster.cluster = 0; + } else { + file->p_sfd->ffd.cluster_link.buffer = PF_NULL; + } + return error; +} + +pf_s32 PFFILE_fsync(PFFILE_FILE* file) { + PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + pf_u16 access_time; + pf_s32 error; + + error = PFVOL_CheckForWrite(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + return error; + } + if ((file->p_sfd->stat & 1) == 0 || (file->p_sfd->stat & 2) == 0) { + pf_vol_set.last_error = 0x26; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = 0x26; + return 0x26; + } + error = PFCACHE_FlushFATCache(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = error; + file->last_access_data.state.last_error = error; + return error; + } + PFENT_getcurrentDateTimeForEnt(&file->p_sfd->dir_entry.access_date, &access_time); + error = PFENT_updateEntry(&file->p_sfd->dir_entry, 1); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = error; + file->last_access_data.state.last_error = error; + return error; + } + error = PFCACHE_FlushDataCacheSpecific(volume, file); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = error; + file->last_access_data.state.last_error = error; + } + return error; +} + +pf_s32 PFFILE_fappend(PFFILE_FILE* file, pf_u32 size, pf_u32* size_appended) { + PF_VOLUME* volume; + pf_u32 appended_size; + pf_u16 modify_time; + pf_s32 error; + + *size_appended = 0; + volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + error = PFVOL_CheckForWrite(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = error; + file->last_access_data.state.last_error = error; + return error; + } + if ((file->p_sfd->stat & 1) == 0 || (file->p_sfd->stat & 2) == 0) { + pf_vol_set.last_error = 0x26; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = 0x26; + return 0x26; + } + ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = file; + error = PFFILE_p_fappend(file, size, &appended_size); + *size_appended = appended_size; + ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = PF_NULL; + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = error; + file->last_access_data.state.last_error = error; + return error; + } + PFENT_getcurrentDateTimeForEnt(&file->p_sfd->dir_entry.access_date, &modify_time); + return 0; +} + +pf_s32 PFFILE_fadjust(PFFILE_FILE* file) { + PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + PFFILE_CURSOR saved_cursor; + PF_FAT_HINT saved_hint; + pf_u32 saved_last_access_chain_index; + pf_u16 access_time; + pf_s32 error; + + error = PFVOL_CheckForWrite(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = error; + file->last_access_data.state.last_error = error; + return error; + } + if ((file->p_sfd->stat & 1) == 0 || (file->p_sfd->stat & 2) == 0) { + pf_vol_set.last_error = 0x26; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = 0x26; + return 0x26; + } + ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = file; + saved_cursor = file->cursor; + saved_hint = file->hint; + saved_last_access_chain_index = file->last_access_data.last_access.chain_index; + if ((file->open_mode & 8) == 0 && (file->open_mode & 4) != 0) { + error = 0x0A; + } else if ((file->p_sfd->lock.mode & 3) != 0 && + ((file->p_sfd->lock.mode & 1) != 0 || + ((file->p_sfd->lock.mode & 2) != 0 && file->lock_count == 0))) { + error = 0x19; + } else { + error = PFCLUSTER_AdjustCluster(file); + error &= (-error | error) >> 31; + } + file->cursor = saved_cursor; + file->hint = saved_hint; + file->last_access_data.last_access.chain_index = saved_last_access_chain_index; + ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = PF_NULL; + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = error; + file->last_access_data.state.last_error = error; + return error; + } + PFENT_getcurrentDateTimeForEnt(&file->p_sfd->dir_entry.access_date, &access_time); + return 0; +} + +pf_s32 PFFILE_finfo(PFFILE_FILE* file, PF_INFO* info) { + PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + PFFILE_CURSOR saved_cursor; + PF_FAT_HINT saved_hint; + pf_u32 saved_last_access_chain_index; + pf_s32 error; + + error = PFVOL_CheckForRead(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = error; + file->last_access_data.state.last_error = error; + return error; + } + if ((file->p_sfd->stat & 1) == 0 || (file->p_sfd->stat & 2) == 0) { + pf_vol_set.last_error = 0x26; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = 0x26; + return 0x26; + } + ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = file; + saved_cursor = file->cursor; + saved_hint = file->hint; + saved_last_access_chain_index = file->last_access_data.last_access.chain_index; + error = PFFILE_p_finfo(file, info); + file->cursor = saved_cursor; + file->hint = saved_hint; + file->last_access_data.last_access.chain_index = saved_last_access_chain_index; + ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = PF_NULL; + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = error; + file->last_access_data.state.last_error = error; + return error; + } + return 0; +} + +pf_s32 PFFILE_combine(PF_STR* first_path, PF_STR* second_path) { + PF_VOLUME* volume = PFPATH_GetVolumeFromPath(first_path); + PF_VOLUME* second_volume = PFPATH_GetVolumeFromPath(second_path); + pf_s32 error; + + if (volume != second_volume) { + pf_vol_set.last_error = 0x0A; + return 0x0A; + } + error = PFVOL_CheckForWrite(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + return error; + } + ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = PF_NULL; + error = PFFILE_p_combine(volume, first_path, second_path); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + } else { + error = PFCACHE_FlushFATCache(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + } else { + error = PFCACHE_FlushDataCacheSpecific(volume, PF_NULL); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + } + } + } + ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = PF_NULL; + return error; +} + +pf_s32 PFFILE_divide(PF_STR* source_path, PF_STR* destination_path, pf_u32 split_size) { + PF_VOLUME* volume = PFPATH_GetVolumeFromPath(source_path); + PF_VOLUME* destination_volume = PFPATH_GetVolumeFromPath(destination_path); + pf_s32 error; + + if (volume != destination_volume) { + pf_vol_set.last_error = 0x1F; + return 0x1F; + } + error = PFVOL_CheckForWrite(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + return error; + } + ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = PF_NULL; + error = PFFILE_p_divide(volume, source_path, destination_path, split_size); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + } else { + error = PFCACHE_FlushFATCache(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + } else { + error = PFCACHE_FlushDataCacheSpecific(volume, PF_NULL); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + } + } + } + ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = PF_NULL; + return error; +} + +pf_s32 PFFILE_cinsert(PF_STR* path, pf_u32 cluster_index, pf_u32 count, + pf_u32* cluster_result) { + PF_VOLUME* volume; + pf_s32 error; + + *cluster_result = 0; + volume = PFPATH_GetVolumeFromPath(path); + error = PFVOL_CheckForWrite(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + return error; + } + ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = PF_NULL; + error = PFFILE_p_cinsert(volume, path, cluster_index, count, (pf_u32)cluster_result); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + } else { + error = PFCACHE_FlushFATCache(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + } else { + error = PFCACHE_FlushDataCacheSpecific(volume, PF_NULL); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + } + } + } + ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = PF_NULL; + return error; +} + +pf_s32 PFFILE_cdelete(PF_STR* path, pf_u32 cluster_index, pf_u32 count, + pf_u32* cluster_result) { + PF_VOLUME* volume; + pf_s32 error; + + *cluster_result = 0; + volume = PFPATH_GetVolumeFromPath(path); + error = PFVOL_CheckForWrite(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + return error; + } + ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = PF_NULL; + error = PFFILE_p_cdelete(volume, path, cluster_index, count, (pf_u32)cluster_result); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + } else { + error = PFCACHE_FlushDataCacheSpecific(volume, PF_NULL); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + } else { + error = PFCACHE_FlushFATCache(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + } + } + } + ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = PF_NULL; + return error; +} + +pf_s32 PFFILE_flock(PFFILE_FILE* file, pf_u32 mode) { + PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + pf_s32 error; + + error = PFVOL_CheckForRead(volume); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + return error; + } + if ((file->p_sfd->stat & 1) == 0 || (file->p_sfd->stat & 2) == 0) { + pf_vol_set.last_error = 0x26; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = 0x26; + return 0x26; + } + error = PFFILE_p_flock(file, mode); + if (error != 0) { + pf_vol_set.last_error = error; + ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; + } + return error; +} + +pf_s32 PFFILE_p_fread(PF_VOLUME* volume, pf_u8* buffer, pf_u32 size, pf_u32 count, + PFFILE_FILE* file, pf_u32* count_read) { + pf_u32 bytes_read = 0; + pf_s32 error; + + *count_read = 0; + if ((file->open_mode & 8) == 0 && + ((file->open_mode & 1) != 0 || (file->open_mode & 4) != 0)) { + return 0xA; + } + if ((file->p_sfd->lock.mode & 3) != 0 && file->lock_count == 0) { + return 0x19; + } + if (file->cursor.position >= file->p_sfd->dir_entry.file_size) { + return 0x1C; + } + error = PFFILE_Cursor_Read(file, buffer, size * count, &bytes_read); + *count_read = bytes_read / size; + error &= (-error | error) >> 31; + return error; +} -- 2.49.1 From 6490b90f658d77998468cf5a700ddcbb47cc0d20 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 29 Sep 2026 04:13:13 -0500 Subject: [PATCH 07/18] Decompile PrFILE2 pf_volume to 6/37 functions (worker 0686f984) (#258) --- libs/RVL_SDK/src/fa/pf_volume.c | 2129 +++++++++++++++++++++++++++++++ 1 file changed, 2129 insertions(+) create mode 100644 libs/RVL_SDK/src/fa/pf_volume.c diff --git a/libs/RVL_SDK/src/fa/pf_volume.c b/libs/RVL_SDK/src/fa/pf_volume.c new file mode 100644 index 00000000..bdf290fe --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_volume.c @@ -0,0 +1,2129 @@ +#include + +typedef struct PFVOL_VOLUME PFVOL_VOLUME; + +typedef struct PFVOL_BPB { + u16 bytes_per_sector; + u16 num_reserved_sectors; + u16 num_root_dir_entries; + u8 sectors_per_cluster; + u8 num_FATs; + u32 total_sectors; + u32 sectors_per_FAT; + u32 root_dir_cluster; + u16 fs_info_sector; + u16 backup_boot_sector; + u16 ext_flags; + u8 media; + u8 pad_1b; + s32 fat_type; + u8 log2_bytes_per_sector; + u8 log2_sectors_per_cluster; + u8 num_active_FATs; + u8 pad_23; + u16 num_root_dir_sectors; + u16 pad_26; + u32 active_FAT_sector; + u32 first_root_dir_sector; + u32 first_data_sector; + u32 num_clusters; +} PFVOL_BPB; + +typedef struct PFVOL_DIR_ENTRY { + u16 long_name[261]; + u8 num_entry_LFNs; + u8 ordinal; + u8 check_sum; + u8 pad_20d; + s8 short_name[13]; + u8 small_letter_flag; + u8 attr; + u8 create_time_ms; + u16 create_time; + u16 create_date; + u16 access_date; + u16 modify_time; + u16 modify_date; + u32 file_size; + PFVOL_VOLUME* volume; + u32 path_len; + u32 start_cluster; + u32 entry_sector; + u16 entry_offset; +} PFVOL_DIR_ENTRY; + +typedef struct PFVOL_FAT_HINT { + u32 chain_index; + u32 cluster; + u32 previous_cluster; + u32 reserved; +} PFVOL_FAT_HINT; + +typedef struct PFVOL_LAST_CLUSTER { + u32 num_last_cluster; + u32 max_chain_index; +} PFVOL_LAST_CLUSTER; + +typedef struct PFVOL_FAT_LAST_ACCESS { + u32 chain_index; + u32 cluster; +} PFVOL_FAT_LAST_ACCESS; + +typedef struct PFVOL_CLUSTER_LINK { + u32* buffer; + u16 interval; + u16 interval_offset; + u32 position; + u32 max_count; + u32 save_index; +} PFVOL_CLUSTER_LINK; + +typedef struct PFVOL_FFD { + u32 start_cluster; + u32 flags; + u32* p_start_cluster; + PFVOL_LAST_CLUSTER last_cluster; + PFVOL_FAT_LAST_ACCESS last_access; + PFVOL_CLUSTER_LINK cluster_link; + PFVOL_FAT_HINT* hint; + PFVOL_VOLUME* volume; +} PFVOL_FFD; + +typedef struct PFVOL_STR { + const char* head; + const char* tail; + const char* current; + u32 code_mode; +} PFVOL_STR; + +typedef struct PFVOL_CURRENT_DIR { + u32 stat; + s32 context_id; + PFVOL_DIR_ENTRY directory; +} PFVOL_CURRENT_DIR; + +typedef struct PFVOL_CURRENT_VOLUME { + u32 stat; + s32 context_id; + PFVOL_VOLUME* volume; +} PFVOL_CURRENT_VOLUME; + +typedef struct PFVOL_CONTEXT { + u32 stat; + s32 context_id; +} PFVOL_CONTEXT; + +typedef struct PFVOL_VOLUME_INFO { + s8 label[12]; + u8 attr; + u8 reserved_0d[3]; + u32 time; + u32 date; +} PFVOL_VOLUME_INFO; + +typedef struct PFVOL_CHARCODE { + s32 (*oem2unicode)(const s8*, u16*); + s32 (*unicode2oem)(const u16*, s8*); + s32 (*oem_char_width)(const s8*); + s32 (*is_oem_mb_char)(s8, s32); + s32 (*unicode_char_width)(const u16*); + s32 (*is_unicode_mb_char)(u16, s32); +} PFVOL_CHARCODE; + +typedef struct PFVOL_CACHE_SETTING { + void* pages; + void* buffers; + u16 num_fat_pages; + u16 num_data_pages; + u32 num_fat_buf_size; + u32 num_data_buf_size; +} PFVOL_CACHE_SETTING; + +typedef struct PFVOL_DRIVER { + void* partition; + PFVOL_CACHE_SETTING* cache; + s8 drive; + u8 stat; + u8 pad_0a[2]; +} PFVOL_DRIVER; + +typedef struct PFVOL_OPEN_SFD { + u8 gap_0000[0x3C]; + PFVOL_DIR_ENTRY directory_entry; +} PFVOL_OPEN_SFD; + +typedef struct PFVOL_OPEN_FILE { + u32 stat; + u32 reserved; + PFVOL_OPEN_SFD* stream; + u8 gap_000C[0x24]; +} PFVOL_OPEN_FILE; + +typedef struct PFVOL_CLUSTER_SETTING { + u32* buffer; + u32 max_count; + u16 interval; + u16 reserved; +} PFVOL_CLUSTER_SETTING; + +struct PFVOL_VOLUME { + PFVOL_BPB bpb; + u32 num_free_clusters; + u8 gap_003C[0xD10]; + PFVOL_OPEN_FILE files[5]; + u8 gap_0E3C[0x7E0]; + u32 num_open_files; + u32 num_open_dirs; + u32 cache_flags; + u16 num_fat_pages; + u16 num_data_pages; + u8 gap_162C[0x10]; + u32 num_fat_buf_size; + u32 num_data_buf_size; + u8 gap_1644[4]; + s8 label[12]; + PFVOL_CURRENT_DIR current_dir[4]; + u32 file_buffer_count; + void* file_buffers; + void* current_file_buffer; + u32 last_error; + u32 last_driver_error; + u32 reserved_1f88; + u16 flags; + u16 options; + u16 fsi_flag; + u16 cluster_link_flags; + u16 cluster_link_interval; + u32* cluster_link_buffer; + u32 cluster_link_capacity; + void* driver_partition; + u8 gap_1fa4[4]; + const u8* format_options; +}; + +typedef struct PFVOL_SET { + u32 flags; + u32 reserved_004; + PFVOL_VOLUME* current_volume; + PFVOL_CURRENT_VOLUME context_volume[3]; + s32 num_attached_drives; + s32 num_mounted_volumes; + u32 config; + void* user_data; + s32 last_error; + s32 last_driver_error; + PFVOL_CHARCODE codeset; + u32 setting; + u8 gap_0064[0x0C]; + PFVOL_CONTEXT context[3]; + PFVOL_VOLUME volumes[26]; +} PFVOL_SET; + +PFVOL_SET pf_vol_set; + +extern s32 PFDRV_mount(PFVOL_VOLUME* volume); +extern s32 PFDRV_unmount(PFVOL_VOLUME* volume, u32 mode); +extern s32 PFDRV_format(PFVOL_VOLUME* volume, const u8* format_options); +extern s32 PFDRV_IsInserted(PFVOL_VOLUME* volume); +extern s32 PFDRV_IsUnmountRequested(PFVOL_VOLUME* volume); +extern s32 PFDRV_IsMountRequested(PFVOL_VOLUME* volume); +extern void PFDRV_ClearMountRequested(PFVOL_VOLUME* volume); +extern void PFDRV_ClearUnmountRequested(PFVOL_VOLUME* volume); +extern s32 PFCACHE_InitCaches(PFVOL_VOLUME* volume); +extern s32 PFCACHE_FlushAllCaches(PFVOL_VOLUME* volume); +extern void PFCACHE_FreeAllCaches(PFVOL_VOLUME* volume); +extern s32 PFENT_GetRootDir(PFVOL_VOLUME* volume, PFVOL_DIR_ENTRY* entry); +extern s32 PFENT_MakeRootDir(PFVOL_VOLUME* volume); +extern s32 PFFAT_InitFATRegion(PFVOL_VOLUME* volume); +extern s32 PFSYS_GetCurrentContextID(s32* context_id); +extern void PFFILE_FinalizeAllFiles(PFVOL_VOLUME* volume); +extern void PFDIR_FinalizeAllDirs(PFVOL_VOLUME* volume); +extern s32 PFFAT_RefreshFSINFO(PFVOL_VOLUME* volume); +extern s32 PFFAT_CountFreeClusters(PFVOL_VOLUME* volume, u32* free_clusters); +extern s32 PFFAT_InitFFD(PFVOL_FFD* ffd, PFVOL_FAT_HINT* hint, PFVOL_VOLUME* volume, u32* start_cluster); +extern s32 PFSTR_InitStr(PFVOL_STR* path, const char* text, u32 code_mode); +extern void PFSTR_SetLocalStr(PFVOL_STR* path, const char* path_component); +extern s32 PFSTR_StrLen(const s8* text); +extern s32 PFSTR_ToUpperNStr(const s8* text, u32 max_len, s8* out); +extern s32 PFENT_findEntryPos(PFVOL_FFD* ffd, PFVOL_DIR_ENTRY* entry, u32 start, PFVOL_STR* path, + u8 attr_required, u32 skip, u32* logical_position, u32* entry_position); +extern s32 PFENT_allocateEntry(PFVOL_DIR_ENTRY* entry, u8 num_entries, PFVOL_FFD* ffd, u32* prev_cluster, + PFVOL_STR* path); +extern u8 PFENT_getcurrentDateTimeForEnt(u16* date, u16* time); +extern s32 PFENT_updateEntry(PFVOL_DIR_ENTRY* entry, u32 clear_archive); +extern void* pf_memcpy(void* dst, const void* src, u32 size); +extern s8* pf_strcpy(s8* dst, const s8* src); +extern s32 PFDRV_StoreVolumeLabelToBuf(PFVOL_VOLUME_INFO* volume_info, PFVOL_VOLUME* volume); +extern s32 PFDRV_StoreVolumeLabelToBPB(PFVOL_VOLUME* volume, const s8* label); +extern s32 PFSEC_WriteData(PFVOL_VOLUME* volume, const void* buffer, u32 sector, u16 offset, u32 count, + u32* processed, u32 flags); +extern s32 PFCACHE_FlushFATCache(PFVOL_VOLUME* volume); +extern s32 PFCACHE_FlushDataCacheSpecific(PFVOL_VOLUME* volume, u32 sector); +extern s32 PFCACHE_FlushDataCache(PFVOL_VOLUME* volume); +extern s32 PFCACHE_SetWriteBackMode(PFVOL_VOLUME* volume); +extern s32 PFCACHE_SetWriteThroughMode(PFVOL_VOLUME* volume); +extern s32 PFCACHE_SetCache(PFVOL_VOLUME* volume, void* pages, void* buffers, u16 num_fat_pages, + u16 num_data_pages); +extern s32 PFCACHE_SetFATBufferSize(PFVOL_VOLUME* volume, u32 size); +extern s32 PFCACHE_SetDataBufferSize(PFVOL_VOLUME* volume, u32 size); +extern s32 PFDRV_init(PFVOL_VOLUME* volume); +extern s32 PFDRV_finalize(PFVOL_VOLUME* volume); +extern s32 fa_nanddrv_NotifyNANDFile(s32 command, void* callback_data); +extern s32 PFVOL_DoMountVolume(PFVOL_VOLUME* volume); +extern s32 PFVOL_p_unmount(PFVOL_VOLUME* volume, u32 mode); +extern s32 PFVOL_p_format(PFVOL_VOLUME* volume, const u8* format_options); +extern s32 PFVOL_p_setvol(PFVOL_VOLUME* volume, const s8* label); +extern s32 PFVOL_p_getvol(PFVOL_VOLUME* volume, PFVOL_VOLUME_INFO* volume_info); +extern s32 PFVOL_p_rmvvol(PFVOL_VOLUME* volume); +extern s16 pf_toupper(s32 value); +extern void PF_InitLockFile(void); +extern s32 PFCODE_CP932_OEM2Unicode(const s8* source, u16* destination); +extern s32 PFCODE_CP932_Unicode2OEM(const u16* source, s8* destination); +extern s32 PFCODE_CP932_OEMCharWidth(const s8* source); +extern s32 PFCODE_CP932_isOEMMBchar(s8 value, s32 mode); +extern s32 PFCODE_CP932_UnicodeCharWidth(const u16* source); +extern s32 PFCODE_CP932_isUnicodeMBchar(u16 value, s32 mode); +extern void* pf_memset(void* dst, int value, u32 size); +extern s32 pf_memcmp(const void* left, const void* right, u32 size); + +s32 PFVOL_DoMountVolume(PFVOL_VOLUME* volume) { + s32 error; + s32 context_id; + u32 i; + u32 context_registered; + + volume->last_error = 0; + volume->last_driver_error = 0; + error = PFDRV_mount(volume); + if (error != 0) { + return error; + } + if (volume->bpb.bytes_per_sector == 0 || (volume->bpb.bytes_per_sector & 0x01FF) != 0) { + return 15; + } + if ((volume->bpb.bytes_per_sector >> 9) > volume->num_fat_pages || + ((volume->bpb.bytes_per_sector >> 9) << 1) > volume->num_data_pages) { + return 30; + } + error = PFCACHE_InitCaches(volume); + if (error != 0) { + return error; + } + volume->flags |= 8; + if ((volume->flags & 8) == 0) { + return 9; + } + error = PFSYS_GetCurrentContextID(&context_id); + volume->current_dir[0].stat |= 1; + context_registered = 0; + for (i = 0; i < 3; i++) { + pf_vol_set.context[i].stat &= 1; + if (pf_vol_set.context[i].stat != 0 && pf_vol_set.context[i].context_id == context_id) { + context_registered = 1; + break; + } + } + if (context_registered != 0) { + volume->current_dir[0].stat |= 1; + volume->current_dir[0].context_id = context_id; + } + for (i = 0; i < 4; i++) { + error = PFENT_GetRootDir(volume, &volume->current_dir[i].directory); + if (error != 0) { + break; + } + } + if (error == 0 && (volume->flags & 0x40) != 0) { + error = PFDRV_format(volume, volume->format_options); + if (error == 0 && (volume->flags & 0x80) == 0) { + error = PFFAT_InitFATRegion(volume); + if (error == 0) { + error = PFENT_MakeRootDir(volume); + } + } + } + if (error != 0) { + volume->flags &= ~8; + } + return error; +} + +s32 PFVOL_p_unmount(PFVOL_VOLUME* volume, u32 mode) { + s32 error; + s32 prior_error = 0; + + if ((volume->flags & 8) == 0) { + return 9; + } + PFFILE_FinalizeAllFiles(volume); + PFDIR_FinalizeAllDirs(volume); + error = PFCACHE_FlushAllCaches(volume); + if (error != 0) { + prior_error = error; + } + if (error == 0 || (mode & 1) != 0) { + PFCACHE_FreeAllCaches(volume); + error = PFDRV_unmount(volume, mode); + if (error != 0) { + goto unmount_done; + } + if ((volume->flags & 8) != 0) { + volume->current_dir[0].stat = 0; + volume->current_dir[1].stat = 0; + volume->current_dir[2].stat = 0; + volume->current_dir[3].stat = 0; + } + error = 0; + volume->flags &= ~8; +unmount_done: + if (error != 0 && prior_error == 0) { + prior_error = error; + } + } + if (prior_error == 0 || (mode & 1) != 0) { + PFDRV_ClearMountRequested(volume); + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes--; + } + return prior_error; +} + +s32 PFVOL_p_format(PFVOL_VOLUME* volume, const u8* format_options) { + s32 error; + u32 free_clusters; + + if (volume == 0) { + return 10; + } + if ((volume->flags & 2) != 0) { + return 11; + } + error = PFDRV_format(volume, format_options); + if (error != 0) { + return error; + } + if ((volume->flags & 8) != 0) { + PFCACHE_FreeAllCaches(volume); + error = PFVOL_p_unmount(volume, 0); + if (error != 0) { + return error; + } + } + if ((volume->flags & 8) == 0) { + error = PFVOL_DoMountVolume(volume); + if (error != 0) { + goto mount_done; + } + volume->fsi_flag &= ~7; + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes++; + } + PFDRV_ClearMountRequested(volume); + error = 0; +mount_done: + if (error == 0) { + if ((volume->flags & 2) != 0) { + error = 11; + } else if ((volume->flags & 0x80) == 0) { + error = PFFAT_InitFATRegion(volume); + if (error == 0) { + error = PFENT_MakeRootDir(volume); + if (error == 0) { + if (volume->bpb.fat_type != 2) { + volume->fsi_flag &= ~3; + } + if ((volume->bpb.fat_type != 2 || (volume->fsi_flag & 2) == 0) || + (error = PFFAT_RefreshFSINFO(volume)) == 0) { + error = 0; + } + } + } + } else { + if (volume->bpb.fat_type == 2 && (volume->fsi_flag & 2) != 0) { + volume->fsi_flag |= 4; + PFFAT_RefreshFSINFO(volume); + } else { + volume->fsi_flag &= ~4; + if (volume->bpb.fat_type != 2) { + volume->fsi_flag &= ~7; + } + error = PFFAT_CountFreeClusters(volume, &free_clusters); + if (error != 0) { + return error; + } + } + error = 0; + } + } + return error; +} + +s32 PFVOL_p_setvol(PFVOL_VOLUME* volume, const s8* label) { + PFVOL_FFD ffd; + PFVOL_FAT_HINT hint; + PFVOL_STR path; + PFVOL_DIR_ENTRY root_entry; + PFVOL_DIR_ENTRY entry; + u32 logical_position; + u32 entry_position; + u32 previous_cluster[2]; + s32 error; + + error = PFENT_GetRootDir(volume, &root_entry); + if (error == 0) { + PFFAT_InitFFD(&ffd, &hint, volume, &root_entry.start_cluster); + PFSTR_InitStr(&path, "*", 1); + PFSTR_SetLocalStr(&path, 0); + error = PFENT_findEntryPos(&ffd, &entry, 0, &path, 8, 0, &logical_position, &entry_position); + if (error != 0 && error != 3) { + return error; + } + { + if (entry_position != 999999) { + if (entry.start_cluster == 1) { + entry.start_cluster = 0; + } + } else { + PFSTR_InitStr(&path, "", 1); + PFSTR_SetLocalStr(&path, 0); + error = PFENT_allocateEntry(&entry, 1, &ffd, previous_cluster, &path); + if (error != 0) { + return error; + } + entry.long_name[0] = 0; + entry.start_cluster = 0; + entry.file_size = 0; + entry.volume = volume; + entry.small_letter_flag = 0; + entry.attr = 8; + entry.path_len = 3; + entry.create_date = 0; + entry.create_time = 0; + entry.access_date = 0; + entry.create_time_ms = 0; + } + pf_memcpy(entry.short_name, label, 12); + PFENT_getcurrentDateTimeForEnt(&entry.modify_date, &entry.modify_time); + error = PFENT_updateEntry(&entry, 0); + } + } else { + return error; + } + return error; +} + +s32 PFVOL_p_getvol(PFVOL_VOLUME* volume, PFVOL_VOLUME_INFO* volume_info) { + PFVOL_FFD ffd; + PFVOL_FAT_HINT hint; + PFVOL_STR path; + PFVOL_DIR_ENTRY root_entry; + PFVOL_DIR_ENTRY entry; + u32 logical_position; + u32 entry_position; + s32 error; + + error = PFENT_GetRootDir(volume, &root_entry); + if (error != 0) { + return error; + } + PFFAT_InitFFD(&ffd, &hint, volume, &root_entry.start_cluster); + PFSTR_InitStr(&path, "*", 1); + PFSTR_SetLocalStr(&path, "*"); + error = PFENT_findEntryPos(&ffd, &entry, 0, &path, 8, 0, &logical_position, &entry_position); + if (error != 0 && error != 3) { + return error; + } + if (entry_position != 999999) { + volume_info->time = entry.modify_date; + volume_info->date = entry.modify_time; + volume_info->attr = entry.attr; + pf_strcpy(volume_info->label, entry.short_name); + } else { + volume_info->time = 0; + volume_info->date = 0; + volume_info->attr = 8; + PFDRV_StoreVolumeLabelToBuf(volume_info, volume); + } + return 0; +} + +s32 PFVOL_p_rmvvol(PFVOL_VOLUME* volume) { + PFVOL_FFD ffd; + PFVOL_FAT_HINT hint; + PFVOL_STR path; + PFVOL_DIR_ENTRY root_entry; + PFVOL_DIR_ENTRY entry; + u32 logical_position; + u32 entry_position; + u32 processed; + u8 deleted = 0xE5; + s32 error; + + error = PFENT_GetRootDir(volume, &root_entry); + if (error != 0) { + return error; + } + PFFAT_InitFFD(&ffd, &hint, volume, &root_entry.start_cluster); + PFSTR_InitStr(&path, "*", 1); + PFSTR_SetLocalStr(&path, "*"); + error = PFENT_findEntryPos(&ffd, &entry, 0, &path, 8, 0, &logical_position, &entry_position); + if (error != 0 && error != 3) { + return error; + } + if (entry_position != 999999) { + error = PFSEC_WriteData(volume, &deleted, entry.entry_sector, entry.entry_offset, 1, &processed, 0); + if (error != 0) { + return error; + } + if (processed != 1) { + return 17; + } + } + return 0; +} + +s32 PFVOL_InitModule(u32 config, void* user_data) { + s32 i; + + if ((config & 0x10000) != 0) { + pf_vol_set.config |= 0x10000; + } else { + pf_vol_set.config &= ~0x10000; + } + pf_vol_set.current_volume = &pf_vol_set.volumes[0]; + pf_vol_set.context_volume[0].volume = &pf_vol_set.volumes[0]; + pf_vol_set.context_volume[1].volume = &pf_vol_set.volumes[0]; + pf_vol_set.context_volume[2].volume = &pf_vol_set.volumes[0]; + pf_vol_set.flags |= 1; + pf_vol_set.num_attached_drives = 0; + pf_vol_set.num_mounted_volumes = 0; + if ((config & 0x10000) != 0) { + pf_vol_set.config |= 0x10000; + } else { + pf_vol_set.config &= ~0x10000; + } + pf_vol_set.user_data = user_data; + pf_vol_set.last_error = 0; + pf_vol_set.last_driver_error = 0; + pf_vol_set.setting = 1; + pf_vol_set.codeset.oem2unicode = PFCODE_CP932_OEM2Unicode; + pf_vol_set.codeset.unicode2oem = PFCODE_CP932_Unicode2OEM; + pf_vol_set.codeset.oem_char_width = PFCODE_CP932_OEMCharWidth; + pf_vol_set.codeset.is_oem_mb_char = PFCODE_CP932_isOEMMBchar; + pf_vol_set.codeset.unicode_char_width = PFCODE_CP932_UnicodeCharWidth; + pf_vol_set.codeset.is_unicode_mb_char = PFCODE_CP932_isUnicodeMBchar; + for (i = 0; i < 26; i++) { + pf_memset(&pf_vol_set.volumes[i], 0, 0x1FAC); + } + PF_InitLockFile(); + return 0; +} + +#define PFVOL_CLEAR_CURRENT_DIRS(volume) \ + do { \ + (volume)->current_dir[0].stat = 0; \ + (volume)->current_dir[1].stat = 0; \ + (volume)->current_dir[2].stat = 0; \ + (volume)->current_dir[3].stat = 0; \ + } while (0) + +#define PFVOL_UPDATE_DRIVER_REQUESTS(volume, result) \ + do { \ + if (PFDRV_IsInserted(volume) == 0) { \ + if (PFDRV_IsUnmountRequested(volume) != 0 && ((volume)->flags & 8) == 0) { \ + PFFILE_FinalizeAllFiles(volume); \ + PFDIR_FinalizeAllDirs(volume); \ + (result) = PFDRV_unmount(volume, 1); \ + if ((result) == 0) { \ + if (((volume)->flags & 8) != 0) { \ + PFVOL_CLEAR_CURRENT_DIRS(volume); \ + } \ + (volume)->flags &= ~8; \ + } \ + PFDRV_ClearUnmountRequested(volume); \ + pf_vol_set.num_mounted_volumes--; \ + } \ + if (PFDRV_IsMountRequested(volume) != 0) { \ + PFDRV_ClearMountRequested(volume); \ + } \ + (result) = 0; \ + } else { \ + if (PFDRV_IsUnmountRequested(volume) != 0 && ((volume)->flags & 8) == 0) { \ + PFFILE_FinalizeAllFiles(volume); \ + PFDIR_FinalizeAllDirs(volume); \ + (result) = PFDRV_unmount(volume, 1); \ + if ((result) == 0) { \ + if (((volume)->flags & 8) != 0) { \ + PFVOL_CLEAR_CURRENT_DIRS(volume); \ + } \ + (volume)->flags &= ~8; \ + } \ + PFDRV_ClearUnmountRequested(volume); \ + pf_vol_set.num_mounted_volumes--; \ + } \ + if (PFDRV_IsMountRequested(volume) != 0) { \ + if (((volume)->flags & 8) == 0) { \ + (result) = PFVOL_DoMountVolume(volume); \ + if ((result) == 0) { \ + (volume)->fsi_flag &= ~7; \ + PFDRV_ClearUnmountRequested(volume); \ + pf_vol_set.num_mounted_volumes++; \ + } \ + } \ + if (((volume)->flags & 8) != 0 || (result) == 0) { \ + PFDRV_ClearMountRequested(volume); \ + (result) = 0; \ + } \ + } else { \ + (result) = 0; \ + } \ + } \ + } while (0) + +s32 PFVOL_CheckForRead(PFVOL_VOLUME* volume) { + s32 error; + + if (PFDRV_IsUnmountRequested(volume) != 0 && (volume->flags & 8) == 0) { + PFFILE_FinalizeAllFiles(volume); + PFDIR_FinalizeAllDirs(volume); + error = PFDRV_unmount(volume, 1); + if (error == 0) { + if ((volume->flags & 8) != 0) { + PFVOL_CLEAR_CURRENT_DIRS(volume); + } + volume->flags &= ~8; + } + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes--; + } + if (PFDRV_IsInserted(volume) == 0) { + if (PFDRV_IsMountRequested(volume) != 0) { + PFDRV_ClearMountRequested(volume); + } + } else if (PFDRV_IsMountRequested(volume) != 0) { + if ((volume->flags & 8) == 0) { + error = PFVOL_DoMountVolume(volume); + if (error != 0) { + goto check_result; + } + volume->fsi_flag &= ~7; + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes++; + } + PFDRV_ClearMountRequested(volume); + error = 0; + } + error = 0; +check_result: + if (error == 0) { + error = (((volume->flags >> 3) & 1) - 1) & 9; + } + return error; +} + +s32 PFVOL_CheckForWrite(PFVOL_VOLUME* volume) { + s32 error = 0; + + if (PFDRV_IsInserted(volume) == 0) { + if (PFDRV_IsUnmountRequested(volume) != 0 && (volume->flags & 8) == 0) { + PFFILE_FinalizeAllFiles(volume); + PFDIR_FinalizeAllDirs(volume); + error = PFDRV_unmount(volume, 1); + if (error == 0) { + if ((volume->flags & 8) != 0) { + PFVOL_CLEAR_CURRENT_DIRS(volume); + } + volume->flags &= ~8; + } + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes--; + } + if (PFDRV_IsMountRequested(volume) != 0) { + PFDRV_ClearMountRequested(volume); + } + } else { + if (PFDRV_IsUnmountRequested(volume) != 0 && (volume->flags & 8) == 0) { + PFFILE_FinalizeAllFiles(volume); + PFDIR_FinalizeAllDirs(volume); + error = PFDRV_unmount(volume, 1); + if (error == 0) { + if ((volume->flags & 8) != 0) { + PFVOL_CLEAR_CURRENT_DIRS(volume); + } + volume->flags &= ~8; + } + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes--; + } + if (PFDRV_IsMountRequested(volume) != 0) { + if ((volume->flags & 8) == 0) { + error = PFVOL_DoMountVolume(volume); + if (error == 0) { + volume->fsi_flag &= ~7; + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes++; + PFDRV_ClearMountRequested(volume); + error = 0; + } + } else { + PFDRV_ClearMountRequested(volume); + error = 0; + } + if (error != 0) { + return error; + } + } + } + if ((volume->flags & 8) == 0) { + return 9; + } + if ((volume->flags & 2) != 0) { + return 11; + } + return 0; +} + +s32 PFVOL_CheckCurrentDir(PFVOL_VOLUME* volume, u32 start_cluster) { + s32 context_id; + u32 current_dir_index; + + if ((volume->flags & 8) == 0) { + return 9; + } + PFSYS_GetCurrentContextID(&context_id); + for (current_dir_index = 1; current_dir_index < 4; current_dir_index++) { + if ((volume->current_dir[current_dir_index].stat & 1) != 0 && + volume->current_dir[current_dir_index].context_id == context_id) { + break; + } + } + if (current_dir_index == 4) { + current_dir_index = 0; + } + if (start_cluster == volume->current_dir[current_dir_index].directory.start_cluster) { + return -1; + } + return 0; +} + +s32 PFVOL_SetCurrentDir(PFVOL_VOLUME* volume, PFVOL_DIR_ENTRY* directory) { + s32 context_id; + u32 current_dir_index; + u32 context_index; + s32 context_registered = 0; + + if ((volume->flags & 8) == 0) { + return 9; + } + PFSYS_GetCurrentContextID(&context_id); + for (current_dir_index = 1; current_dir_index < 4; current_dir_index++) { + if ((volume->current_dir[current_dir_index].stat & 1) != 0 && + volume->current_dir[current_dir_index].context_id == context_id) { + volume->current_dir[current_dir_index].directory = *directory; + break; + } + } + if (current_dir_index == 4) { + for (context_index = 0; context_index < 3; context_index++) { + pf_vol_set.context[context_index].stat &= 1; + if (pf_vol_set.context[context_index].stat != 0 && + pf_vol_set.context[context_index].context_id == context_id) { + context_registered = 1; + break; + } + } + if (context_registered != 0) { + for (current_dir_index = 1; current_dir_index < 4; current_dir_index++) { + if ((volume->current_dir[current_dir_index].stat & 1) == 0) { + volume->current_dir[current_dir_index].stat |= 1; + volume->current_dir[current_dir_index].context_id = context_id; + volume->current_dir[current_dir_index].directory = *directory; + break; + } + } + } + } + volume->current_dir[0].directory = *directory; + return 0; +} + +s32 PFVOL_GetCurrentDir(PFVOL_VOLUME* volume, PFVOL_DIR_ENTRY* directory) { + s32 context_id; + u32 current_dir_index; + u32 context_index; + s32 context_registered = 0; + + if ((volume->flags & 8) == 0) { + return 9; + } + PFSYS_GetCurrentContextID(&context_id); + for (current_dir_index = 1; current_dir_index < 4; current_dir_index++) { + if ((volume->current_dir[current_dir_index].stat & 1) != 0 && + volume->current_dir[current_dir_index].context_id == context_id) { + *directory = volume->current_dir[current_dir_index].directory; + break; + } + } + if (current_dir_index == 4) { + for (context_index = 0; context_index < 3; context_index++) { + pf_vol_set.context[context_index].stat &= 1; + if (pf_vol_set.context[context_index].stat != 0 && + pf_vol_set.context[context_index].context_id == context_id) { + context_registered = 1; + break; + } + } + if (context_registered != 0) { + for (current_dir_index = 1; current_dir_index < 4; current_dir_index++) { + if ((volume->current_dir[current_dir_index].stat & 1) == 0) { + volume->current_dir[current_dir_index].stat |= 1; + volume->current_dir[current_dir_index].context_id = context_id; + *directory = volume->current_dir[current_dir_index].directory; + break; + } + } + } else { + *directory = volume->current_dir[0].directory; + } + } + return 0; +} + +void PFVOL_SetCurrentVolume(PFVOL_VOLUME* volume) { + s32 context_id; + u32 context_index; + s32 context_registered; + + PFSYS_GetCurrentContextID(&context_id); + context_registered = 0; + for (context_index = 1; context_index < 4; context_index++) { + if ((pf_vol_set.context_volume[context_index - 1].stat & 1) != 0 && + pf_vol_set.context_volume[context_index - 1].context_id == context_id) { + pf_vol_set.context_volume[context_index - 1].volume = volume; + break; + } + } + if (context_index == 4) { + for (context_index = 1; context_index < 4; context_index++) { + pf_vol_set.context[context_index - 1].stat &= 1; + if (pf_vol_set.context[context_index - 1].stat != 0 && + pf_vol_set.context[context_index - 1].context_id == context_id) { + context_registered = 1; + break; + } + } + if (context_registered != 0) { + for (context_index = 1; context_index < 4; context_index++) { + if ((pf_vol_set.context_volume[context_index - 1].stat & 1) == 0) { + pf_vol_set.context_volume[context_index - 1].stat |= 1; + pf_vol_set.context_volume[context_index - 1].context_id = context_id; + pf_vol_set.context_volume[context_index - 1].volume = volume; + break; + } + } + } + } + pf_vol_set.current_volume = volume; +} + +PFVOL_VOLUME* PFVOL_GetCurrentVolume(void) { + s32 context_id; + u32 context_index; + s32 context_registered; + PFVOL_VOLUME* volume = 0; + + PFSYS_GetCurrentContextID(&context_id); + context_registered = 0; + for (context_index = 1; context_index < 4; context_index++) { + if ((pf_vol_set.context_volume[context_index - 1].stat & 1) != 0 && + pf_vol_set.context_volume[context_index - 1].context_id == context_id) { + volume = pf_vol_set.context_volume[context_index - 1].volume; + break; + } + } + if (context_index == 4) { + for (context_index = 1; context_index < 4; context_index++) { + pf_vol_set.context[context_index - 1].stat &= 1; + if (pf_vol_set.context[context_index - 1].stat != 0 && + pf_vol_set.context[context_index - 1].context_id == context_id) { + context_registered = 1; + break; + } + } + if (context_registered != 0) { + for (context_index = 1; context_index < 4; context_index++) { + if ((pf_vol_set.context_volume[context_index - 1].stat & 1) == 0) { + pf_vol_set.context_volume[context_index - 1].stat |= 1; + pf_vol_set.context_volume[context_index - 1].context_id = context_id; + volume = pf_vol_set.context_volume[context_index - 1].volume; + break; + } + } + } else { + volume = pf_vol_set.current_volume; + } + } + return volume; +} + +PFVOL_VOLUME* PFVOL_GetVolumeFromDrvChar(s8 drive) { + s16 volume_index; + + volume_index = pf_toupper(drive) - 'A'; + if (volume_index < 0 || volume_index >= 26) { + return 0; + } + return &pf_vol_set.volumes[volume_index]; +} + +s32 PFVOL_derrnum(s8 drive) { + s16 volume_index; + PFVOL_VOLUME* volume; + + volume_index = pf_toupper(drive) - 'A'; + if (volume_index < 0 || volume_index >= 26) { + volume = 0; + } else { + volume = &pf_vol_set.volumes[volume_index]; + } + return volume->last_driver_error; +} + +s32 PFVOL_errnum(void) { + return pf_vol_set.last_error; +} + +void PFVOL_setvol(s8 drive, const s8* label) { + s16 volume_index; + PFVOL_VOLUME* volume; + u16 label_length; + s32 error; + s8 upper_label[12]; + + volume_index = pf_toupper(drive) - 'A'; + if (volume_index < 0 || volume_index >= 26) { + volume = 0; + } else { + volume = &pf_vol_set.volumes[volume_index]; + } + label_length = PFSTR_StrLen(label); + error = PFDRV_IsInserted(volume); + if (error != 0) { + if (PFDRV_IsUnmountRequested(volume) != 0 && (volume->flags & 8) == 0) { + PFFILE_FinalizeAllFiles(volume); + PFDIR_FinalizeAllDirs(volume); + error = PFDRV_unmount(volume, 1); + if (error == 0) { + if ((volume->flags & 8) != 0) { + PFVOL_CLEAR_CURRENT_DIRS(volume); + } + volume->flags &= ~8; + } + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes--; + } + error = PFDRV_IsMountRequested(volume); + if (error != 0) { + if ((volume->flags & 8) == 0) { + error = PFVOL_DoMountVolume(volume); + if (error == 0) { + volume->fsi_flag &= ~7; + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes++; + PFDRV_ClearMountRequested(volume); + error = 0; + } + } else { + PFDRV_ClearMountRequested(volume); + error = 0; + } + if (error != 0) { + goto save_error; + } + } + } else { + if (PFDRV_IsUnmountRequested(volume) != 0 && (volume->flags & 8) == 0) { + PFFILE_FinalizeAllFiles(volume); + PFDIR_FinalizeAllDirs(volume); + error = PFDRV_unmount(volume, 1); + if (error == 0) { + if ((volume->flags & 8) != 0) { + PFVOL_CLEAR_CURRENT_DIRS(volume); + } + volume->flags &= ~8; + } + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes--; + } + if (PFDRV_IsMountRequested(volume) != 0) { + PFDRV_ClearMountRequested(volume); + } + } + error = 0; + if ((volume->flags & 8) == 0) { + error = 9; + } else if ((volume->flags & 2) != 0) { + error = 11; + } + if (error != 0) { + goto save_error; + } + PFSTR_ToUpperNStr(label, 11, upper_label); + if (label_length < 11) { + upper_label[label_length] = 0; + } + error = PFVOL_p_setvol(volume, upper_label); + if (error != 0) { + goto save_error; + } + error = PFCACHE_FlushFATCache(volume); + if (error != 0) { + goto save_error; + } + error = PFCACHE_FlushDataCacheSpecific(volume, 0); + if (error != 0) { + goto save_error; + } + error = PFDRV_StoreVolumeLabelToBPB(volume, upper_label); + if (error != 0) { + goto save_error; + } + return; + +save_error: + pf_vol_set.last_error = error; + volume->last_error = error; + return; +} + +s32 PFVOL_getvol(s8 drive, PFVOL_VOLUME_INFO* volume_info) { + s16 volume_index; + PFVOL_VOLUME* volume; + s32 error; + + volume_index = pf_toupper(drive) - 'A'; + if (volume_index < 0 || volume_index >= 26) { + volume = 0; + } else { + volume = &pf_vol_set.volumes[volume_index]; + } + if (pf_memcmp(volume->label, "NO NAME ", 11) == 0) { + pf_vol_set.last_error = 3; + volume->last_error = 3; + return 3; + } + if (PFDRV_IsInserted(volume) != 0) { + if (PFDRV_IsUnmountRequested(volume) != 0 && (volume->flags & 8) == 0) { + PFFILE_FinalizeAllFiles(volume); + PFDIR_FinalizeAllDirs(volume); + error = PFDRV_unmount(volume, 1); + if (error == 0) { + if ((volume->flags & 8) != 0) { + PFVOL_CLEAR_CURRENT_DIRS(volume); + } + volume->flags &= ~8; + } + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes--; + } + error = PFDRV_IsMountRequested(volume); + if (error != 0) { + if ((volume->flags & 8) == 0) { + error = PFVOL_DoMountVolume(volume); + if (error == 0) { + volume->fsi_flag &= ~7; + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes++; + PFDRV_ClearMountRequested(volume); + error = 0; + } + } else { + PFDRV_ClearMountRequested(volume); + error = 0; + } + if (error != 0) { + goto save_error; + } + } + } else { + if (PFDRV_IsUnmountRequested(volume) != 0 && (volume->flags & 8) == 0) { + PFFILE_FinalizeAllFiles(volume); + PFDIR_FinalizeAllDirs(volume); + error = PFDRV_unmount(volume, 1); + if (error == 0) { + if ((volume->flags & 8) != 0) { + PFVOL_CLEAR_CURRENT_DIRS(volume); + } + volume->flags &= ~8; + } + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes--; + } + if (PFDRV_IsMountRequested(volume) != 0) { + PFDRV_ClearMountRequested(volume); + } + } + error = 0; + if ((volume->flags & 8) == 0) { + error = 9; + } + if (error != 0) { + goto save_error; + } + error = PFVOL_p_getvol(volume, volume_info); + if (error != 0) { + goto save_error; + } + return 0; + +save_error: + pf_vol_set.last_error = error; + volume->last_error = error; + return error; +} + +s32 PFVOL_rmvvol(s8 drive) { + s16 volume_index; + PFVOL_VOLUME* volume; + s32 error; + + volume_index = pf_toupper(drive) - 'A'; + if (volume_index < 0 || volume_index >= 26) { + volume = 0; + } else { + volume = &pf_vol_set.volumes[volume_index]; + } + if (pf_memcmp(volume->label, "NO NAME ", 11) == 0) { + pf_vol_set.last_error = 3; + volume->last_error = 3; + return 3; + } + if (PFDRV_IsInserted(volume) != 0) { + if (PFDRV_IsUnmountRequested(volume) != 0 && (volume->flags & 8) == 0) { + PFFILE_FinalizeAllFiles(volume); + PFDIR_FinalizeAllDirs(volume); + error = PFDRV_unmount(volume, 1); + if (error == 0) { + if ((volume->flags & 8) != 0) { + PFVOL_CLEAR_CURRENT_DIRS(volume); + } + volume->flags &= ~8; + } + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes--; + } + error = PFDRV_IsMountRequested(volume); + if (error != 0) { + if ((volume->flags & 8) == 0) { + error = PFVOL_DoMountVolume(volume); + if (error == 0) { + volume->fsi_flag &= ~7; + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes++; + PFDRV_ClearMountRequested(volume); + error = 0; + } + } else { + PFDRV_ClearMountRequested(volume); + error = 0; + } + if (error != 0) { + goto save_error; + } + } + } else { + if (PFDRV_IsUnmountRequested(volume) != 0 && (volume->flags & 8) == 0) { + PFFILE_FinalizeAllFiles(volume); + PFDIR_FinalizeAllDirs(volume); + error = PFDRV_unmount(volume, 1); + if (error == 0) { + if ((volume->flags & 8) != 0) { + PFVOL_CLEAR_CURRENT_DIRS(volume); + } + volume->flags &= ~8; + } + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes--; + } + if (PFDRV_IsMountRequested(volume) != 0) { + PFDRV_ClearMountRequested(volume); + } + } + error = 0; + if ((volume->flags & 8) == 0) { + error = 9; + } else if ((volume->flags & 2) != 0) { + error = 11; + } + if (error != 0) { + goto save_error; + } + error = PFDRV_StoreVolumeLabelToBPB(volume, (const s8*)"NO NAME "); + if (error != 0) { + goto save_error; + } + error = PFVOL_p_rmvvol(volume); + if (error != 0) { + goto save_error; + } + error = PFCACHE_FlushDataCacheSpecific(volume, 0); + if (error != 0) { + goto save_error; + } + return 0; + +save_error: + pf_vol_set.last_error = error; + volume->last_error = error; + return error; +} + +s32 PFVOL_getdev(s8 drive, u32* device_info) { + s16 volume_index; + PFVOL_VOLUME* volume; + s32 error; + + volume_index = pf_toupper(drive) - 'A'; + if (volume_index < 0 || volume_index >= 26) { + volume = 0; + } else { + volume = &pf_vol_set.volumes[volume_index]; + } + if (PFDRV_IsInserted(volume) != 0) { + if (PFDRV_IsUnmountRequested(volume) != 0 && (volume->flags & 8) == 0) { + PFFILE_FinalizeAllFiles(volume); + PFDIR_FinalizeAllDirs(volume); + error = PFDRV_unmount(volume, 1); + if (error == 0) { + if ((volume->flags & 8) != 0) { + PFVOL_CLEAR_CURRENT_DIRS(volume); + } + volume->flags &= ~8; + } + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes--; + } + error = PFDRV_IsMountRequested(volume); + if (error != 0) { + if ((volume->flags & 8) == 0) { + error = PFVOL_DoMountVolume(volume); + if (error == 0) { + volume->fsi_flag &= ~7; + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes++; + PFDRV_ClearMountRequested(volume); + error = 0; + } + } else { + PFDRV_ClearMountRequested(volume); + error = 0; + } + if (error != 0) { + goto save_error; + } + } + } else { + if (PFDRV_IsUnmountRequested(volume) != 0 && (volume->flags & 8) == 0) { + PFFILE_FinalizeAllFiles(volume); + PFDIR_FinalizeAllDirs(volume); + error = PFDRV_unmount(volume, 1); + if (error == 0) { + if ((volume->flags & 8) != 0) { + PFVOL_CLEAR_CURRENT_DIRS(volume); + } + volume->flags &= ~8; + } + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes--; + } + if (PFDRV_IsMountRequested(volume) != 0) { + PFDRV_ClearMountRequested(volume); + } + } + error = 0; + if ((volume->flags & 8) == 0) { + error = 9; + } + if (error != 0) { + goto save_error; + } + device_info[2] = volume->bpb.bytes_per_sector; + device_info[3] = volume->bpb.sectors_per_cluster; + device_info[0] = volume->bpb.num_clusters; + error = PFFAT_CountFreeClusters(volume, &device_info[1]); + if (error != 0) { + goto save_error; + } + return 0; + +save_error: + pf_vol_set.last_error = error; + volume->last_error = error; + return error; +} + +s32 PFVOL_buffering(s8 drive, u32 mode) { + s16 volume_index; + PFVOL_VOLUME* volume; + s32 error; + + volume_index = pf_toupper(drive) - 'A'; + if (volume_index < 0 || volume_index >= 26) { + volume = 0; + } else { + volume = &pf_vol_set.volumes[volume_index]; + } + if (PFDRV_IsInserted(volume) != 0) { + if (PFDRV_IsUnmountRequested(volume) != 0 && (volume->flags & 8) == 0) { + PFFILE_FinalizeAllFiles(volume); + PFDIR_FinalizeAllDirs(volume); + error = PFDRV_unmount(volume, 1); + if (error == 0) { + if ((volume->flags & 8) != 0) { + PFVOL_CLEAR_CURRENT_DIRS(volume); + } + volume->flags &= ~8; + } + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes--; + } + error = PFDRV_IsMountRequested(volume); + if (error != 0) { + if ((volume->flags & 8) == 0) { + error = PFVOL_DoMountVolume(volume); + if (error == 0) { + volume->fsi_flag &= ~7; + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes++; + PFDRV_ClearMountRequested(volume); + error = 0; + } + } else { + PFDRV_ClearMountRequested(volume); + error = 0; + } + if (error != 0) { + goto save_error; + } + } + } else { + if (PFDRV_IsUnmountRequested(volume) != 0 && (volume->flags & 8) == 0) { + PFFILE_FinalizeAllFiles(volume); + PFDIR_FinalizeAllDirs(volume); + error = PFDRV_unmount(volume, 1); + if (error == 0) { + if ((volume->flags & 8) != 0) { + PFVOL_CLEAR_CURRENT_DIRS(volume); + } + volume->flags &= ~8; + } + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes--; + } + if (PFDRV_IsMountRequested(volume) != 0) { + PFDRV_ClearMountRequested(volume); + } + } + error = 0; + if ((volume->flags & 8) == 0) { + error = 9; + } else if ((volume->flags & 2) != 0) { + error = 11; + } + if (error == 0) { + if ((mode & 4) == 0 || (volume->cache_flags & 1) != 0) { + error = 0; + } else { + error = PFCACHE_FlushFATCache(volume); + if (error != 0) { + goto save_error; + } + } + if (error == 0) { + if ((mode & 1) == 0) { + error = PFCACHE_SetWriteBackMode(volume); + } else { + error = PFCACHE_SetWriteThroughMode(volume); + } + if (error != 0) { + goto save_error; + } + if ((mode & 4) != 0) { + volume->cache_flags |= 4; + } else { + volume->cache_flags &= ~4; + } + if ((mode & 2) != 0) { + volume->cache_flags |= 2; + } else { + volume->cache_flags &= ~2; + } + } + } else { + goto save_error; + } + return 0; + +save_error: + pf_vol_set.last_error = error; + volume->last_error = error; + return error; +} + +s32 PFVOL_attach(PFVOL_DRIVER* driver, s32 notify_command, void* callback_data) { + PFVOL_CACHE_SETTING* cache; + PFVOL_VOLUME* volume; + s32 volume_index; + s32 error; + + cache = driver->cache; + if (cache->num_fat_buf_size == 0) { + cache->num_fat_buf_size = 1; + } + if (cache->num_data_buf_size == 0) { + cache->num_data_buf_size = 1; + } + driver->drive = 0; + driver->stat = 0; + if (notify_command != 0 && fa_nanddrv_NotifyNANDFile(notify_command, callback_data) != 0) { + pf_vol_set.last_error = 17; + return 17; + } + volume_index = 0; + volume = pf_vol_set.volumes; + while (volume_index < 26) { + if ((volume->flags & 1) == 0) { + break; + } + volume++; + volume_index++; + if ((volume->flags & 1) == 0) { + break; + } + volume++; + volume_index++; + } + if (volume_index < 0 || volume_index >= 26 || pf_vol_set.num_attached_drives < 0 || + pf_vol_set.num_attached_drives >= 26) { + pf_vol_set.last_error = 4; + return 4; + } + volume->last_error = -1; + volume->last_driver_error = -1; + pf_memset(volume, 0, 0x1FAC); + volume->driver_partition = driver->partition; + volume->options = volume_index + 'A'; + volume->file_buffer_count = 1; + volume->current_file_buffer = &volume->file_buffers; + error = PFDRV_init(volume); + if (error == 0) { + PFCACHE_SetCache(volume, cache->pages, cache->buffers, cache->num_fat_pages, + cache->num_data_pages); + PFCACHE_SetFATBufferSize(volume, cache->num_fat_buf_size); + PFCACHE_SetDataBufferSize(volume, cache->num_data_buf_size); + } + if (error != 0) { + pf_vol_set.last_error = error; + return error; + } + volume->flags |= 1; + driver->stat |= 1; + volume->options = volume_index + 'A'; + driver->drive = volume_index + 'A'; + pf_vol_set.num_attached_drives++; + if (PFDRV_IsInserted(volume) == 0) { + return 0; + } + driver->stat |= 0x10; + if ((volume->flags & 8) == 0) { + error = PFVOL_DoMountVolume(volume); + if (error == 0) { + volume->fsi_flag &= ~7; + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes++; + } + } + if (error == 0) { + PFDRV_ClearMountRequested(volume); + driver->stat |= 2; + return 0; + } + pf_vol_set.last_error = error; + volume->last_error = error; + return 0; +} + +s32 PFVOL_detach(s8 drive) { + s16 volume_index; + PFVOL_VOLUME* volume; + s32 error; + + volume_index = pf_toupper(drive) - 'A'; + if (volume_index < 0 || volume_index >= 26) { + volume = 0; + } else { + volume = &pf_vol_set.volumes[volume_index]; + } + if ((volume->flags & 8) != 0) { + error = 10; + pf_vol_set.last_error = error; + volume->last_error = error; + } else if ((volume->flags & 1) == 0) { + error = 10; + pf_vol_set.last_error = error; + volume->last_error = error; + } else { + error = PFDRV_finalize(volume); + if (error == 0) { + volume->flags &= ~1; + pf_vol_set.num_attached_drives--; + } else { + pf_vol_set.last_error = error; + volume->last_error = error; + } + } + return error; +} + +s32 PFVOL_format(s8 drive, const u8* format_options) { + s16 volume_index; + PFVOL_VOLUME* volume; + s32 error; + u8 mount_requested; + + volume_index = pf_toupper(drive) - 'A'; + if (volume_index < 0 || volume_index >= 26) { + volume = 0; + } else { + volume = &pf_vol_set.volumes[volume_index]; + } + if ((volume->flags & 1) == 0) { + error = 10; + goto save_error; + } + if (PFDRV_IsInserted(volume) == 0) { + error = 9; + goto save_error; + } + mount_requested = PFDRV_IsMountRequested(volume) != 0; + if (mount_requested != 0) { + PFDRV_ClearMountRequested(volume); + } + if (PFDRV_IsInserted(volume) != 0) { + if (PFDRV_IsUnmountRequested(volume) != 0 && (volume->flags & 8) == 0) { + PFFILE_FinalizeAllFiles(volume); + PFDIR_FinalizeAllDirs(volume); + error = PFDRV_unmount(volume, 1); + if (error == 0) { + if ((volume->flags & 8) != 0) { + PFVOL_CLEAR_CURRENT_DIRS(volume); + } + volume->flags &= ~8; + } + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes--; + } + error = PFDRV_IsMountRequested(volume); + if (error != 0) { + if ((volume->flags & 8) == 0) { + error = PFVOL_DoMountVolume(volume); + if (error == 0) { + volume->fsi_flag &= ~7; + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes++; + PFDRV_ClearMountRequested(volume); + error = 0; + } + } else { + PFDRV_ClearMountRequested(volume); + error = 0; + } + if (error != 0) { + goto after_mount; + } + } + } else { + if (PFDRV_IsUnmountRequested(volume) != 0 && (volume->flags & 8) == 0) { + PFFILE_FinalizeAllFiles(volume); + PFDIR_FinalizeAllDirs(volume); + error = PFDRV_unmount(volume, 1); + if (error == 0) { + if ((volume->flags & 8) != 0) { + PFVOL_CLEAR_CURRENT_DIRS(volume); + } + volume->flags &= ~8; + } + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes--; + } + if (PFDRV_IsMountRequested(volume) != 0) { + PFDRV_ClearMountRequested(volume); + } + } + error = 0; +after_mount: + if (error == 0) { + if (volume->num_open_files != 0) { + PFFILE_FinalizeAllFiles(volume); + PFCACHE_FreeAllCaches(volume); + } + if (volume->num_open_dirs != 0) { + PFDIR_FinalizeAllDirs(volume); + } + error = PFVOL_p_format(volume, format_options); + if (error == 0) { + volume->fsi_flag |= 4; + volume->num_free_clusters = volume->bpb.num_clusters - (volume->bpb.fat_type == 2); + return 0; + } + } + if (mount_requested) { + volume->flags |= 0x10; + } + if (error != 0) { + pf_vol_set.last_error = error; + volume->last_error = error; + } + return error; + +save_error: + pf_vol_set.last_error = error; + volume->last_error = error; + return error; +} + +s32 PFVOL_mount(s8 drive) { + s16 volume_index; + PFVOL_VOLUME* volume; + s32 error; + + volume_index = pf_toupper(drive) - 'A'; + if (volume_index < 0 || volume_index >= 26) { + volume = 0; + } else { + volume = &pf_vol_set.volumes[volume_index]; + } + PFVOL_UPDATE_DRIVER_REQUESTS(volume, error); + if (error == 0) { + if (PFDRV_IsInserted(volume) != 0) { + if ((volume->flags & 8) == 0) { + error = PFVOL_DoMountVolume(volume); + if (error == 0) { + volume->fsi_flag &= ~7; + PFDRV_ClearUnmountRequested(volume); + pf_vol_set.num_mounted_volumes++; + PFDRV_ClearMountRequested(volume); + } + } + } else { + error = 9; + } + } + if (error != 0) { + pf_vol_set.last_error = error; + volume->last_error = error; + } + return error; +} + +s32 PFVOL_unmount(s8 drive, u32 mode) { + s16 volume_index; + PFVOL_VOLUME* volume; + s32 error; + s32 prior_error = 0; + s32 result; + + volume_index = pf_toupper(drive) - 'A'; + if (volume_index < 0 || volume_index >= 26) { + volume = 0; + } else { + volume = &pf_vol_set.volumes[volume_index]; + } + if ((volume->flags & 1) == 0) { + pf_vol_set.last_error = 10; + return 10; + } + PFDRV_ClearMountRequested(volume); + PFVOL_UPDATE_DRIVER_REQUESTS(volume, error); + if (error != 0) { + pf_vol_set.last_error = error; + volume->last_error = error; + return error; + } + if ((volume->flags & 8) == 0) { + return 0; + } + if (volume->num_open_files != 0 || volume->num_open_dirs != 0) { + prior_error = 1; + pf_vol_set.last_error = 19; + volume->last_error = 19; + if ((mode & 1) == 0) { + return 19; + } + } + error = PFVOL_p_unmount(volume, mode); + result = prior_error; + if (error != 0 && prior_error == 0) { + pf_vol_set.last_error = error; + volume->last_error = error; + result = 1; + if ((mode & 1) == 0) { + result = error; + } + } + return result; +} + +s32 PFVOL_setupfsi(s8 drive, u32 mode) { + s16 volume_index; + PFVOL_VOLUME* volume; + s32 error; + u16 prior_fsi_flags; + u32 free_clusters; + + volume_index = pf_toupper(drive) - 'A'; + if (volume_index < 0 || volume_index >= 26) { + volume = 0; + } else { + volume = &pf_vol_set.volumes[volume_index]; + } + PFVOL_UPDATE_DRIVER_REQUESTS(volume, error); + if (error == 0 && (volume->flags & 8) == 0) { + error = 9; + } + if (error == 0) { + if (volume->bpb.fat_type == 2) { + if ((mode & 1) == 1) { + volume->fsi_flag |= 5; + } else if ((mode & 2) == 2) { + volume->fsi_flag &= ~1; + } + if ((mode & 4) == 4) { + volume->fsi_flag |= 2; + if ((volume->fsi_flag & 4) == 0) { + PFFAT_CountFreeClusters(volume, &free_clusters); + } + } else if ((mode & 8) == 8) { + volume->fsi_flag &= ~2; + } + } else { + error = 12; + } + } + if (error != 0) { + pf_vol_set.last_error = error; + volume->last_error = error; + } + return error; +} + +s32 PFVOL_setclstlink(s8 drive, s32 mode, PFVOL_CLUSTER_SETTING* setting) { + s16 volume_index; + PFVOL_VOLUME* volume; + s32 error; + + volume_index = pf_toupper(drive) - 'A'; + if (volume_index < 0 || volume_index >= 26) { + volume = 0; + } else { + volume = &pf_vol_set.volumes[volume_index]; + } + if (volume->num_open_files != 0) { + pf_vol_set.last_error = 19; + volume->last_error = 19; + return 19; + } + PFVOL_UPDATE_DRIVER_REQUESTS(volume, error); + if (error == 0) { + if ((volume->flags & 8) == 0) { + error = 9; + } else if ((volume->flags & 2) != 0) { + error = 11; + } + } + if (error == 0) { + if (mode == 1) { + if (setting->buffer == 0) { + pf_vol_set.last_error = 10; + volume->last_error = 10; + return 10; + } else { + volume->cluster_link_flags |= 1; + volume->cluster_link_buffer = setting->buffer; + pf_memset(setting->buffer, 0, setting->max_count * 0x14); + volume->cluster_link_interval = setting->interval; + volume->cluster_link_capacity = setting->max_count; + } + } else { + volume->cluster_link_flags &= ~1; + volume->cluster_link_buffer = 0; + volume->cluster_link_interval = 0; + volume->cluster_link_capacity = 0; + } + } + if (error != 0) { + pf_vol_set.last_error = error; + volume->last_error = error; + return error; + } + return 0; +} + +s32 PFVOL_sync(s8 drive, s32 mode) { + s16 volume_index; + PFVOL_VOLUME* volume; + PFVOL_OPEN_FILE* file; + s32 error; + u32 file_index; + + volume_index = pf_toupper(drive) - 'A'; + if (volume_index < 0 || volume_index >= 26) { + volume = 0; + } else { + volume = &pf_vol_set.volumes[volume_index]; + } + PFVOL_UPDATE_DRIVER_REQUESTS(volume, error); + if (error == 0) { + if ((volume->flags & 8) == 0) { + error = 9; + } else if ((volume->flags & 2) != 0) { + error = 11; + } + } + if (error == 0) { + error = PFCACHE_FlushFATCache(volume); + if (error == 0) { + file_index = 0; + do { + file = &volume->files[file_index]; + if ((file->stat & 1) != 0) { + error = PFENT_updateEntry(&file->stream->directory_entry, 1); + if (error != 0) { + pf_vol_set.last_error = error; + volume->last_error = error; + return error; + } + } + file_index++; + } while (file_index < 5); + error = PFCACHE_FlushDataCache(volume); + if (error == 0 && mode == 1) { + PFCACHE_FreeAllCaches(volume); + } + } + } + if (error != 0) { + pf_vol_set.last_error = error; + volume->last_error = error; + } + return error; +} + +void PFVOL_settailbuf(s8 drive, u32 count, void* buffer) { + s16 volume_index; + PFVOL_VOLUME* volume; + s32 error; + + volume_index = pf_toupper(drive) - 'A'; + if (volume_index < 0 || volume_index >= 26) { + volume = 0; + } else { + volume = &pf_vol_set.volumes[volume_index]; + } + PFVOL_UPDATE_DRIVER_REQUESTS(volume, error); + if (error == 0 && (volume->flags & 8) == 0) { + error = 9; + } + if (error == 0) { + volume->file_buffer_count = count; + volume->current_file_buffer = buffer; + } else { + pf_vol_set.last_error = error; + volume->last_error = error; + } +} + +s32 PFVOL_setvolcfg(s8 drive, u32* config) { + s16 volume_index; + PFVOL_VOLUME* volume; + s32 error; + + if (drive == -1) { + if ((config[0] & 0x10000) != 0) { + pf_vol_set.config |= 0x10000; + } else if ((config[0] & 0x20000) != 0) { + pf_vol_set.config &= ~0x10000; + } + return 0; + } + volume_index = pf_toupper(drive) - 'A'; + if (volume_index < 0 || volume_index >= 26) { + volume = 0; + } else { + volume = &pf_vol_set.volumes[volume_index]; + } + if (config[2] == 0) { + config[2] = 1; + } + if (config[3] == 0) { + config[3] = 1; + } + PFVOL_UPDATE_DRIVER_REQUESTS(volume, error); + if (volume->num_open_files != 0 || volume->num_open_dirs != 0) { + pf_vol_set.last_error = 19; + volume->last_error = 19; + return 19; + } + if ((config[0] & 1) != 0 || (config[0] & 2) != 0) { + PFCACHE_FlushAllCaches(volume); + PFCACHE_FreeAllCaches(volume); + if ((config[0] & 1) != 0) { + if (config[2] != volume->num_fat_buf_size) { + PFCACHE_SetFATBufferSize(volume, config[2]); + config[0] &= ~1; + } + } + if ((config[0] & 2) != 0) { + if (config[3] != volume->num_data_buf_size) { + PFCACHE_SetDataBufferSize(volume, config[3]); + config[0] &= ~2; + } + } + PFCACHE_InitCaches(volume); + } + if ((config[1] & 1) != 0) { + volume->reserved_1f88 |= 1; + } else if ((config[1] & 2) != 0) { + volume->reserved_1f88 &= ~1; + } + return 0; + +} + +s32 PFVOL_getvolcfg(s8 drive, u32* config) { + s16 volume_index; + PFVOL_VOLUME* volume; + s32 error; + + if (drive == -1) { + config[0] = pf_vol_set.config; + if ((pf_vol_set.config & 0x10000) == 0) { + config[0] |= 0x20000; + } + config[1] = 0; + config[2] = 0; + config[3] = 0; + return 0; + } + volume_index = pf_toupper(drive) - 'A'; + if (volume_index < 0 || volume_index >= 26) { + volume = 0; + } else { + volume = &pf_vol_set.volumes[volume_index]; + } + PFVOL_UPDATE_DRIVER_REQUESTS(volume, error); + config[0] = 0; + config[1] = volume->reserved_1f88; + if ((volume->reserved_1f88 & 1) == 0) { + config[1] |= 2; + } + config[2] = volume->num_fat_buf_size; + config[3] = volume->num_data_buf_size; + return 0; +} + +s32 PFVOL_setcode(const PFVOL_CHARCODE* code_set) { + if (pf_vol_set.num_attached_drives > 0) { + pf_vol_set.last_error = 36; + return 36; + } + pf_vol_set.codeset.oem2unicode = code_set->oem2unicode; + pf_vol_set.codeset.unicode2oem = code_set->unicode2oem; + pf_vol_set.codeset.oem_char_width = code_set->oem_char_width; + pf_vol_set.codeset.is_oem_mb_char = code_set->is_oem_mb_char; + pf_vol_set.codeset.unicode_char_width = code_set->unicode_char_width; + pf_vol_set.codeset.is_unicode_mb_char = code_set->is_unicode_mb_char; + return 0; +} + +s32 PFVOL_regctx(void) { + PFVOL_CONTEXT* context; + s32 context_id; + s32 error; + u32 context_index; + u32 free_context_index = 0; + + error = PFSYS_GetCurrentContextID(&context_id); + if (error != 0) { + pf_vol_set.last_error = 26; + return 26; + } + context = pf_vol_set.context; + for (context_index = 1; context_index <= 3; context_index++) { + if ((context->stat & 1) != 0) { + if (context->context_id == context_id) { + return 0; + } + } else if (free_context_index == 0) { + free_context_index = context_index; + } + context++; + } + if (free_context_index == 0) { + pf_vol_set.last_error = 26; + return 26; + } + context = &pf_vol_set.context[free_context_index - 1]; + context->stat = 1; + context->context_id = context_id; + return 0; +} + +s32 PFVOL_unregctx(void) { + s32 context_id; + s32 error; + u32 context_index; + u32 volume_index; + u32 current_dir_index; + u32 current_volume_index; + s32 found = 0; + + error = PFSYS_GetCurrentContextID(&context_id); + if (error != 0) { + pf_vol_set.last_error = 26; + return 26; + } + for (context_index = 0; context_index < 3; context_index++) { + if ((pf_vol_set.context[context_index].stat & 1) != 0 && + pf_vol_set.context[context_index].context_id == context_id) { + pf_vol_set.context[context_index].stat &= ~1; + found = 1; + for (current_volume_index = 0; current_volume_index < 3; current_volume_index++) { + if ((pf_vol_set.context_volume[current_volume_index].stat & 1) != 0 && + pf_vol_set.context_volume[current_volume_index].context_id == context_id) { + pf_vol_set.context_volume[current_volume_index].stat &= ~1; + } + } + for (volume_index = 0; volume_index < 26; volume_index++) { + for (current_dir_index = 1; current_dir_index < 4; current_dir_index++) { + if ((pf_vol_set.volumes[volume_index].current_dir[current_dir_index].stat & 1) != 0 && + pf_vol_set.volumes[volume_index].current_dir[current_dir_index].context_id == context_id) { + pf_vol_set.volumes[volume_index].current_dir[current_dir_index].stat &= ~1; + break; + } + } + } + break; + } + } + if (found == 0) { + pf_vol_set.last_error = 26; + return 26; + } + return 0; +} + +s32 PFVOL_setencode(u32 mode) { + pf_vol_set.setting = pf_vol_set.setting & ~3 | mode; + return 0; +} -- 2.49.1 From ac51d83fa501464463922f8637c3503de524a175 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 29 Sep 2026 04:14:07 -0500 Subject: [PATCH 08/18] iplSetting: 78/112 functions (worker 3adbf457) (#259) --- include/scene/setting/iplSetting.h | 5 +- src/scene/setting/iplSetting.cpp | 607 +++++++++++++++++------------ 2 files changed, 368 insertions(+), 244 deletions(-) diff --git a/include/scene/setting/iplSetting.h b/include/scene/setting/iplSetting.h index 6743299c..5f590cdf 100644 --- a/include/scene/setting/iplSetting.h +++ b/include/scene/setting/iplSetting.h @@ -48,7 +48,10 @@ namespace ipl { u8 unknown[0x14]; u16 count; u8 entries[0x7fe]; - WDBssDesc_* currentDescriptor; + union { + WDBssDesc_* currentDescriptor; + u16* currentDescriptorWords; + }; }; #endif diff --git a/src/scene/setting/iplSetting.cpp b/src/scene/setting/iplSetting.cpp index 5b46c3e8..6d84318f 100644 --- a/src/scene/setting/iplSetting.cpp +++ b/src/scene/setting/iplSetting.cpp @@ -393,10 +393,9 @@ namespace ipl { void Setting::createBrowser() { EGG::Heap* mem1Heap = System::createMem1AppHeap(); u32 mem1Size = mem1Heap->getAllocatableSize(4); - EGG::Heap* mem2Heap = System::getMem2App(); - u32 mem2Size = mem2Heap->getAllocatableSize(4) - 0x80000; + u32 mem2Size = static_cast(System::getMem2App()->getAllocatableSize(4) - 0x80000 - 2.6 * 1024 * 1024); mem1Buffer_ = System::createMem1AppHeap()->alloc(mem1Size, 4); - mem2Buffer_ = mem2Heap->alloc(mem2Size, 4); + mem2Buffer_ = System::getMem2App()->alloc(mem2Size, 4); OSReport("Setting Scene: mem1: %d mem2: %d\n", mem1Size, mem2Size); nw4r::ut::Rect projection16x9; @@ -409,12 +408,18 @@ namespace ipl { const char* urlFormats[] = {"marc:%s/%s/", "file:dvd/html/IPLSetting/%s/%s/"}; const char* pagePaths[] = { "index01.html", "Internet/Internet_index.html", "Setup/startup_index1.html", - "Update/Update_index.html", "index02.html", "Setup/ScreenSave.html", - "Country/US_Country_flame.html", + "Update/Update_index.html", "index02.html", "%s", "%s", }; - const char* pageNames[] = {"Calendar", "Parental_Control", "Internet", "Wiiconnect24"}; - const char* regionCodes[] = {"JP/JP", "FIX/US", "EU/EU", "TW/TW", "KR/KR", "CN/CN"}; - const char* languageCodes[] = {"JPN", "ENG", "GER", "FRA", "SPA", "ITA", "DUT", "CHN", "KOR"}; + const char* regionCodes[] = {"JP/JP", "FIX/US", "EU/EU", "", "", "TW/TW", "KR/KR", + "", "", "", "", "CN/CN"}; + const char* languageCodes[] = {"JPN", "ENG", "GER", "FRA", "SPA", "ITA", + "DUT", "CHN", "ENG", "KOR"}; + const char* regionPages[] = {"Setup/ScreenSave.html", "Country/US_Country_flame.html", + "Setup/ScreenSave.html", "Setup/ScreenSave.html", + "Setup/ScreenSave.html", "Setup/ScreenSave.html", + "Setup/ScreenSave.html", "Setup/ScreenSave.html", + "Setup/ScreenSave.html", "Setup/ScreenSave.html", + "Setup/ScreenSave.html", "Calendar"}; char basePath[100]; char browserPath[100]; @@ -427,39 +432,59 @@ namespace ipl { } strcat(basePath, pagePaths[pageIndex]); - int regionIndex = 1; - char productArea = SCGetProductArea(); - if (productArea >= 0 && productArea < 4) { - regionIndex = productArea > 2 ? 2 : 0; - } else if (productArea == 6) { - regionIndex = 4; - } else if (productArea == 11) { - regionIndex = 5; - } else if (productArea >= 7 && productArea < 11) { - regionIndex = 2; + s8 regionIndex = static_cast(SCGetProductArea()); + if (regionIndex == 4) { + regionIndex = 1; + } else if (regionIndex >= 4) { + if (regionIndex == 11) { + } else if (regionIndex >= 11) { + regionIndex = 1; + } else if (regionIndex >= 7) { + regionIndex = 1; + } + } else { + if (regionIndex >= 3) { + regionIndex = 2; + } else if (regionIndex >= 0) { + } else { + regionIndex = 1; + } } if (mInitialArgument == ARG_UNK_5) { snprintf(browserPath, sizeof(browserPath), basePath, regionCodes[regionIndex], - languageCodes[System::getLanguage()], pagePaths[pageIndex]); + languageCodes[System::getLanguage()], regionPages[regionIndex]); } else if (mInitialArgument == ARG_UNK_6) { - int directPage = 0; - for (int index = 0; index < 4; index++) { - if (strstr(mpStringBuffer->netSettingArg, pageNames[index]) != NULL) { - directPage = index; + const char* pageNames[] = {"Display", "Sound", "Parental_Control", "Internet", + "Wiiconnect24", "Update", "Update"}; + int directPage; + for (directPage = 0; directPage < 7; directPage++) { + if (strstr(mpStringBuffer->netSettingArg, pageNames[directPage]) != NULL) { break; } } - if (directPage == 0) { - snprintf(browserPath, sizeof(browserPath), basePath, regionCodes[regionIndex], - languageCodes[System::getLanguage()], "index01.html"); - } else if (directPage == 1) { - snprintf(browserPath, sizeof(browserPath), basePath, regionCodes[regionIndex], - languageCodes[System::getLanguage()], "index02.html"); - } else { - snprintf(browserPath, sizeof(browserPath), basePath, regionCodes[regionIndex], - languageCodes[System::getLanguage()], "index03.html"); + const char* directPagePath; + switch (directPage) { + case 0: + case 1: + case 2: + directPagePath = "index01.html"; + break; + case 3: + case 4: + case 5: + directPagePath = "index02.html"; + break; + case 6: + directPagePath = "index03.html"; + break; + case 7: + default: + directPagePath = "index01.html"; + break; } + snprintf(browserPath, sizeof(browserPath), basePath, regionCodes[regionIndex], + languageCodes[System::getLanguage()], directPagePath); } else { snprintf(browserPath, sizeof(browserPath), basePath, regionCodes[regionIndex], languageCodes[System::getLanguage()]); @@ -554,12 +579,12 @@ namespace ipl { } else { packet.data.controller.irX = youngController->getDpdProjectionPos().x - projection.left; packet.data.controller.irY = youngController->getDpdProjectionPos().y - projection.top; - u32 classicHold = youngController->getClassicHoldFlag(); - u32 classicTrigger = youngController->getClassicTrigFlag(); - u32 classicRelease = youngController->getClassicReleaseFlag(); - packet.data.controller.btnHold = (classicHold << 16) | youngController->getHoldFlag(); - packet.data.controller.btnTrigger = (classicTrigger << 16) | youngController->getTrigFlag(); - packet.data.controller.btnRelease = (classicRelease << 16) | youngController->getReleaseFlag(); + u32 classicHold = youngController->getClassicHoldFlag() << 16; + u32 classicTrigger = youngController->getClassicTrigFlag() << 16; + u32 classicRelease = youngController->getClassicReleaseFlag() << 16; + packet.data.controller.btnHold = classicHold | youngController->getHoldFlag(); + packet.data.controller.btnTrigger = classicTrigger | youngController->getTrigFlag(); + packet.data.controller.btnRelease = classicRelease | youngController->getReleaseFlag(); } packet.type = 0; @@ -567,12 +592,12 @@ namespace ipl { ext_ead::www::SurfaceManager::GetInstance()->GetBrowserThread()->SendUIEvent(&packet); } } else { + packet.type = 0; packet.data.controller.irX = -1000.0f; packet.data.controller.irY = -1000.0f; packet.data.controller.btnHold = 0; packet.data.controller.btnTrigger = 0; packet.data.controller.btnRelease = 0; - packet.type = 0; ext_ead::www::SurfaceManager::GetInstance()->GetBrowserThread()->SendUIEvent(&packet); } } @@ -632,12 +657,10 @@ namespace ipl { bool Setting::updateScreenMode() { if (unk_0x91C[2] != 0) { if (unk_0xB94 == 0) { - if (mEuRgb60Mode == SCGetEuRgb60Mode()) { - if (mProgressiveMode != SCGetProgressiveMode()) { - unk_0xB94 = 2; - } - } else { + if (mEuRgb60Mode != SCGetEuRgb60Mode()) { unk_0xB94 = 3; + } else if (mProgressiveMode != SCGetProgressiveMode()) { + unk_0xB94 = 2; } if (unk_0xB94 != 0 && unk_0xB94 != 1) { @@ -654,24 +677,27 @@ namespace ipl { return true; } - if (unk_0xB94 == 1) { + switch (unk_0xB94) { + case 1: if (System::getFader()->getStatus() == EGG::Fader::PREPARE_IN) { System::getDialog()->terminate(); SCSetAspectRatio(mAspectRatio & 0xff); SCFlush(); - if (System::getDialog()->getLastResult() < 0) { + if (System::getDialog()->getLastResult() >= 0) { + changeVideoMode(); + System::getKeyboard()->changeAspectRatio(); + System::getFader()->fadeIn(); + } else { mState = 0; return true; } - - changeVideoMode(); - www::wiisetting::setStringBuf(mpStringBuffer); - System::getFader()->fadeIn(); } else { mState = 0; return true; } - } else if (unk_0xB94 > 0 && unk_0xB94 < 4) { + break; + case 2: + case 3: if (System::getFader()->getStatus() == EGG::Fader::PREPARE_IN) { changeVideoMode(); System::getFader()->fadeIn(); @@ -679,6 +705,9 @@ namespace ipl { mState = 0; return true; } + break; + default: + break; } return false; @@ -705,7 +734,7 @@ namespace ipl { if (input != NULL) { if (input->downTrg(0x100800) && mpWiiSettingData->data[0x12] == 0x1e && - unk_0x92C > 0x1e && unk_0x92C < 0x78) { + unk_0x92C >= 0x1e && unk_0x92C < 0x78) { unk_0x92C = 0x78; www::wiisetting::setFuncResult(1); mpWiiSettingData->data[0x37] = 1; @@ -724,24 +753,25 @@ namespace ipl { unk_0xBAC = 1; } - if (System::getAspectRatio()) { + if (System::getFader()->getStatus() == EGG::Fader::PREPARE_OUT) { updateController_(); } - ext_ead::www::BrowserThread* browserThread = - ext_ead::www::SurfaceManager::GetInstance()->GetBrowserThread(); - if (browserThread->ReceiveWindowEvent(mpBrowserData)) { + if (ext_ead::www::SurfaceManager::GetInstance()->GetBrowserThread()->ReceiveWindowEvent( + mpBrowserData)) { if (mpBrowserData->unk_0x00 == 0) { OSReport("IME Created "); if (mpBrowserData->text != NULL) { OSReport("initKeyboard %s\n"); OSReport("initKeyboard %d\n", mpWiiSettingData->data[0x11]); - if (mpWiiSettingData->data[0x11] == 0) { - browserThread->CommitIme(mpBrowserData, mpBrowserData->text); - browserThread->DisposeImeData(mpBrowserData); - } else { + if (mpWiiSettingData->data[0x11] != 0) { unk_0x74 = 1; initKeyboard(mpBrowserData->text); + } else { + ext_ead::www::SurfaceManager::GetInstance()->GetBrowserThread()->CommitIme( + mpBrowserData, mpBrowserData->text); + ext_ead::www::SurfaceManager::GetInstance()->GetBrowserThread()->DisposeImeData( + mpBrowserData); } } else { OSReport("NULL ptr\n"); @@ -2409,18 +2439,21 @@ namespace ipl { if (System::getNwc24Manager() != NULL) { return true; } - if (unk_0x94 != 1) { - if (unk_0x94 < 1 && unk_0x94 >= 0) { - resetFuncMsgQ(); - System::getDialog()->callBtn1(0x21, 0x2e); - www::wiisetting::setFuncResult(2); - unk_0x74 = 0x11; - unk_0x94 = 1; + switch (unk_0x94) { + case 0: + resetFuncMsgQ(); + System::getDialog()->callBtn1(0x21, 0x2e); + www::wiisetting::setFuncResult(2); + unk_0x74 = 0x11; + unk_0x94 = 1; + break; + case 1: + if (System::getDialog()->getLastResult() >= 0) { + unk_0xB9C = 1; + unk_0x74 = 0; + unk_0x94 = 0; } - } else if (System::getDialog()->getLastResult() >= 0) { - unk_0xB9C = 1; - unk_0x74 = 0; - unk_0x94 = 0; + break; } return false; } @@ -2487,16 +2520,16 @@ namespace ipl { } if (mpAPScanThread->IsThreadTerminated()) { mpAPScanThread->WaitForThreadExit(); - if (mAPScanList.count == 0) { + if (mAPScanList.count != 0) { + www::wiisetting::setFuncResult(1); + setAPDraw(); + unk_0x78 = 3; + } else { www::wiisetting::setFuncResult(2); initAP(); mpMainLayout->getAnim(0x14)->initAnmFrame(); mpMainLayout->getAnim(0)->initAnmFrame(); mpMainLayout->getAnim(1)->initAnmFrame(); - } else { - www::wiisetting::setFuncResult(1); - setAPDraw(); - unk_0x78 = 3; } resetFuncMsgQ(); unk_0xB9C = 0; @@ -2565,9 +2598,12 @@ namespace ipl { if (unk_0x91C[2] == 0) { return; } - for (int index = 1; index <= 4; ++index) { - mpMainLayout->FindPaneByName(sSettingAPNumberNames[index])->SetVisible(true); - } + mpMainLayout->FindPaneByName(sSettingAPNumberNames[1])->SetVisible(true); + mpMainLayout->FindPaneByName(sSettingAPNumberNames[2])->SetVisible(true); + mpMainLayout->FindPaneByName(sSettingAPNumberNames[3])->SetVisible(true); + mpMainLayout->FindPaneByName(sSettingAPNumberNames[4])->SetVisible(true); + mpMainLayout->FindPaneByName(sSettingAPNumberNames[0])->SetVisible(true); + mpMainLayout->FindPaneByName(sSettingAPNumberNames[5])->SetVisible(true); u16 count = mAPScanList.count; if (count == 2) { mpMainLayout->FindPaneByName(sSettingAPNumberNames[3])->SetVisible(false); @@ -2655,72 +2691,84 @@ namespace ipl { void Setting::setAPDraw() { mAPScanList.currentDescriptor = reinterpret_cast(mAPScanList.entries); - u32 recordOffset = 2; - for (u32 index = 0; index <= mAPScanList.count; ++index) { + enum { + APPrivacyOpenAnimation = 0x2e, + APPrivacyProtectedAnimation = 0x34, + APSignalAnimationBase = 0x16, + APSignalAnimationEnd = 0x28, + }; + int recordOffset = 2; + for (int index = 0; index <= mAPScanList.count; ++index) { WDBssDesc_* descriptor = mAPScanList.currentDescriptor; - recordOffset += descriptor->length * 2; + int recordLength = descriptor->length * 2; + recordOffset += recordLength; if (recordOffset > 0x800) { return; } mpMainLayout->getAnim(10)->stop(); mpMainLayout->getAnim(11)->stop(); - int privacyMode = WDGetPrivacyMode(descriptor); + u8 privacyMode = static_cast(WDGetPrivacyMode(descriptor)); char ssid[0x21]; wchar_t displayName[0x21]; memcpy(ssid, descriptor->ssid, 0x20); ssid[0x20] = 0; memset(displayName, 0, sizeof(displayName)); int row = index + 1 - unk_0x914; - if (row >= 0 && row < 6) { + if (row >= 0 && row <= 5) { utility::CharacterCode::UTF8ToUTF16(displayName, ssid, 0x21); nw4r::lyt::TextBox* textBox = static_cast( mpMainLayout->FindPaneByName(sSettingAPTextNames[row])); textBox->SetString(displayName); if (privacyMode == 0) { - mpMainLayout->getAnim(row + 0x2e)->initFrame(); - mpMainLayout->getAnim(row + 0x2e)->restart(); - mpMainLayout->getAnim(row + 0x34)->stop(); + mpMainLayout->getAnim(row + APPrivacyOpenAnimation)->initFrame(); + mpMainLayout->getAnim(row + APPrivacyOpenAnimation)->restart(); + mpMainLayout->getAnim(row + APPrivacyProtectedAnimation)->stop(); } else { - mpMainLayout->getAnim(row + 0x34)->initFrame(); - mpMainLayout->getAnim(row + 0x34)->restart(); - mpMainLayout->getAnim(row + 0x2e)->stop(); + mpMainLayout->getAnim(row + APPrivacyProtectedAnimation)->initFrame(); + mpMainLayout->getAnim(row + APPrivacyProtectedAnimation)->restart(); + mpMainLayout->getAnim(row + APPrivacyOpenAnimation)->stop(); } - for (int animation = row + 0x16; animation <= row + 0x28; animation += 6) { + for (int animation = row + APSignalAnimationBase; + animation <= row + APSignalAnimationEnd; animation += 6) { mpMainLayout->getAnim(animation)->stop(); } int signal = getRadioLevel(descriptor); - mpMainLayout->getAnim(row + signal * 6 + 0x16)->initFrame(); - mpMainLayout->getAnim(row + signal * 6 + 0x16)->restart(); + mpMainLayout->getAnim(row + signal * 6 + APSignalAnimationBase)->initFrame(); + mpMainLayout->getAnim(row + signal * 6 + APSignalAnimationBase)->restart(); } - mAPScanList.currentDescriptor = - reinterpret_cast(mAPScanList.entries + recordOffset - 2); + mAPScanList.currentDescriptorWords += recordLength / sizeof(u16); } } int Setting::get_arw_no(const char* paneName) { + int result = -1; for (int index = 0; index < 2; ++index) { if (strcmp(sSettingArrowNames[index], paneName) == 0) { - return index; + result = index; + break; } } - return -1; + return result; } int Setting::get_ap_no(const char* buttonName) { + int result = -1; for (int index = 0; index < 4; ++index) { if (strcmp(sSettingAPButtonNames[index], buttonName) == 0) { - return index; + result = index; + break; } } - return -1; + return result; } void Setting::start_point_event(const char* pageName) { + enum { APPointAnimationOffset = 0xc }; int accessPoint = get_ap_no(pageName); mpMainLayout->getAnim(10)->stop(); mpMainLayout->getAnim(11)->stop(); if (accessPoint != -1) { - layout::Animator* animator = mpMainLayout->getAnim(accessPoint + 0xc); + layout::Animator* animator = mpMainLayout->getAnim(accessPoint + APPointAnimationOffset); animator->initFrame(); animator->restart(); mpWiiSettingData->data[0x37] = 2; @@ -2740,9 +2788,10 @@ namespace ipl { } void Setting::start_left_event(const char* pageName) { + enum { APLeftAnimationOffset = 0x10 }; int accessPoint = get_ap_no(pageName); if (accessPoint != -1) { - layout::Animator* animator = mpMainLayout->getAnim(accessPoint + 0x10); + layout::Animator* animator = mpMainLayout->getAnim(accessPoint + APLeftAnimationOffset); animator->initFrame(); animator->restart(); return; @@ -2758,17 +2807,18 @@ namespace ipl { void Setting::start_trig_event(const char* pageName) { int accessPoint = get_ap_no(pageName); + int recordOffset = 2; if (accessPoint != -1) { - u32 recordOffset = 2; - u32 index = 0; + int index = 0; while (index <= mAPScanList.count) { WDBssDesc_* descriptor = mAPScanList.currentDescriptor; - recordOffset += descriptor->length * 2; + int recordLength = descriptor->length * 2; + recordOffset += recordLength; if (recordOffset > 0x800) { break; } if (index == accessPoint + unk_0x914 + 1) { - int privacyMode = WDGetPrivacyMode(descriptor); + u8 privacyMode = static_cast(WDGetPrivacyMode(descriptor)); char ssid[0x21]; memcpy(ssid, descriptor->ssid, 0x20); ssid[0x20] = 0; @@ -2778,14 +2828,17 @@ namespace ipl { reinterpret_cast(ssid), 0x20); ncd::NCDSetting::setSSID(reinterpret_cast(ssid)); ncd::NCDSetting::setWDPrivacyMode(privacyMode); - www::wiisetting::setFuncResult(privacyMode == 0 ? 2 : 1); + if (privacyMode == 0) { + www::wiisetting::setFuncResult(2); + } else { + www::wiisetting::setFuncResult(1); + } mpWiiSettingData->data[0x37] = 3; setSE(); OSReport("SET DATA : %d %s %d\n", index, ssid, privacyMode); break; } - mAPScanList.currentDescriptor = - reinterpret_cast(mAPScanList.entries + recordOffset - 2); + mAPScanList.currentDescriptorWords += recordLength / sizeof(u16); ++index; } unk_0x91C[2] = 0; @@ -2817,26 +2870,33 @@ namespace ipl { int Setting::getRadioLevel(const WDBssDesc_* descriptor) { u16 signal = descriptor->rssi & 0xff; - if (signal > 0xc3) { + if (signal >= 0xc4) { return 3; } - if (signal > 0xb4) { + if (signal >= 0xb5) { return 2; } - return signal < 0xab ? 0 : 1; + u8 level = signal < 0xab ? 0 : 1; + return level; } void Setting::setUseEULA_() { - if (unk_0x7C == 2) { + if (unk_0x7C != 2) { + if (unk_0x7C < 2) { + if (unk_0x7C != 0) { + if (unk_0x7C >= 0) { + setUseEULA_Start_(); + } + } else { + setUseEULA_Init_(); + } + } else if (unk_0x7C == 4) { + setUseEULA_WaitStopMotor_(); + } else if (unk_0x7C < 4 && !snd::getSystem()->isSEActive("WIPL_SE_DECIDE")) { + unk_0x7C = 4; + } + } else { setUseEULA_Cancel_(); - } else if (unk_0x7C == 0) { - setUseEULA_Init_(); - } else if (unk_0x7C == 1) { - setUseEULA_Start_(); - } else if (unk_0x7C == 4) { - setUseEULA_WaitStopMotor_(); - } else if (unk_0x7C < 4 && !snd::getSystem()->isSEActive("WIPL_SE_DECIDE")) { - unk_0x7C = 4; } } @@ -2869,7 +2929,7 @@ namespace ipl { for (int channel = 0; channel < 4; ++channel) { controller::Interface* input = System::getController(channel); if (input != NULL) { - input->rumble(); + input->cancelRumbling(); } } System::getBS2Manager()->abort(); @@ -2879,7 +2939,7 @@ namespace ipl { void Setting::setUseEULA_WaitStopMotor_() { __WPADReconnect(1); - mSettingData[0x39] = 1; + mpWiiSettingData->data[0x39] = 1; snd::getSystem()->stopAllSound(0x14); unk_0x7C = 5; resetFuncMsgQ(); @@ -3000,11 +3060,12 @@ namespace ipl { } void Setting::setUpdate_NoUpdateDialog_() { - if (System::getDialog()->getLastResult() >= 0) { + s32 lastResult = System::getDialog()->getLastResult(); + if (lastResult >= 0) { if (unk_0x92C == 0) { System::getDialog()->callBtn1(0x167, 1); ++unk_0x92C; - } else { + } else if (lastResult >= 0) { mProfileIDMode = 10; } } @@ -3106,8 +3167,11 @@ namespace ipl { break; case 1: if (System::getDialog()->getLastResult() == 2) { - System::getDialog()->callBtn1Sml(System::getRegion() == 2 ? 0x177 : 0x176, - System::getRegion() == 2 ? 0x179 : 0x178); + if (static_cast(System::getRegion()) == 2) { + System::getDialog()->callBtn1Sml(0x177, 0x179); + } else { + System::getDialog()->callBtn1Sml(0x176, 0x178); + } mUpdateTiming = 2; } else if (System::getDialog()->getLastResult() == 1) { www::wiisetting::setFuncResult(2); @@ -3125,9 +3189,7 @@ namespace ipl { break; case 4: { scene::NakamuraTest* test = static_cast(System::getSceneManager()->getScene(0x19)); - if (test != NULL && test->amtTotal() != 0) { - System::getDialog()->setProgBarLength(test->amtCompleted() * 100 / test->amtTotal()); - } + System::getDialog()->setProgBarLength(test->amtCompleted() * 100 / test->amtTotal()); break; } case 5: @@ -3152,7 +3214,7 @@ namespace ipl { if (System::getDialog()->getLastResult() >= 0) { mUpdateTiming = 9; unk_0x92C = 0; - if (mProgressiveMode == 2 || mProgressiveMode == 5) { + if (mInitialArgument == 2 || mInitialArgument == 5) { SCSetConfigDoneFlag(1); SCSetConfigDoneFlag2(1); SCFlush(); @@ -3177,6 +3239,8 @@ namespace ipl { } } + static const wchar_t errorFormat[] = L"\n%03d"; + void Setting::makeErrorMessage() { const wchar_t* prefix = System::getMessage(400); int messageId = getErrorNum(); @@ -3185,19 +3249,29 @@ namespace ipl { OSReport("error:%d\n", error); wchar_t errorText[8]; wchar_t message[0x140]; - swprintf(errorText, 8, L"\n%03d", error); + swprintf(errorText, 8, errorFormat, error); memset(message, 0, sizeof(message)); size_t prefixLength = wcslen(prefix); wcsncat(message, prefix, prefixLength); size_t errorLength = wcslen(errorText); wcsncat(message + prefixLength, errorText, errorLength); + prefixLength += errorLength; size_t detailLength = wcslen(detail); - wcsncat(message + prefixLength + errorLength, detail, detailLength); - message[prefixLength + errorLength + detailLength] = 0; - bool connectTestError = mpWiiSettingFlag->smthMsgData == 9; - bool japaneseRegion = System::getRegion() == 2 && System::getLanguage() == 2 && getErrorNum() == 0x1b6; - if (connectTestError || mProfileIDMode == 0) { - if (japaneseRegion) { + wcsncat(message + prefixLength, detail, detailLength); + prefixLength += detailLength; + message[prefixLength] = 0; + if (mpWiiSettingFlag->smthMsgData == 9) { + if (static_cast(System::getRegion()) == 2 && + static_cast(System::getLanguage()) == 2 && + static_cast(getErrorNum()) == 0x1b6) { + System::getDialog()->callBtn1(message, 0x2e, 46.0f); + } else { + System::getDialog()->callBtn1(message, 0x2e); + } + } else if (mProfileIDMode == 0) { + if (static_cast(System::getRegion()) == 2 && + static_cast(System::getLanguage()) == 2 && + static_cast(getErrorNum()) == 0x1b6) { System::getDialog()->callBtn1(message, 0x2e, 46.0f); } else { System::getDialog()->callBtn1(message, 0x2e); @@ -3208,108 +3282,149 @@ namespace ipl { } int Setting::getErrorNum() { - int error = mpWiiSettingFlag->err; - if (error == 0x7d01) return System::getRegion() == 2 ? 0x1a5 : 0x191; - if (error == 0x7d02) return System::getRegion() == 2 ? 0x1a6 : 0x192; - if (error == 0x7d03) return System::getRegion() == 2 ? 0x1a7 : 0x193; - if (error < 33000) return System::getRegion() == 2 ? 0x1a8 : 0x194; - if (error < 0xc418) return System::getRegion() == 2 ? 0x1a9 : 0x195; - if (error < 0xc47c) return System::getRegion() == 2 ? 0x1aa : 0x196; - if (error < 0xc4e0) return System::getRegion() == 2 ? 0x1ab : 0x197; - if (error < 0xc544) return System::getRegion() == 2 ? 0x1ac : 0x198; - if (error < 0xc760) return System::getRegion() == 2 ? 0x1ad : 0x199; - if (error < 0xc76a) return System::getRegion() == 2 ? 0x1b8 : 0x1a4; - if (error < 0xc79c) return System::getRegion() == 2 ? 0x1ad : 0x199; - if (error < 0xc8c8) return System::getRegion() == 2 ? 0x1ae : 0x19a; - if (error < 0xc92c) return System::getRegion() == 2 ? 0x1af : 0x19b; - if (error < 0xcb84) return System::getRegion() == 2 ? 0x1b0 : 0x19c; - if (error < 0xcbe8) return System::getRegion() == 2 ? 0x1b1 : 0x19d; - if (error < 0xcc4c) return System::getRegion() == 2 ? 0x1b2 : 0x19e; - if (error < 0xcd14) return System::getRegion() == 2 ? 0x1b3 : 0x19f; - if (error < 0xcd78) return System::getRegion() == 2 ? 0x1b4 : 0x1a0; - if (error < 0xcddc) return System::getRegion() == 2 ? 0x1b5 : 0x1a1; - if (error < 0xce40) return System::getRegion() == 2 ? 0x1b6 : 0x1a2; - if (error < 55000) return System::getRegion() == 2 ? 0x1b7 : 0x1a3; - if (error > 100000) return 0x1c5; - return System::getRegion(); + u32 result = System::getRegion(); + if (result != 2) { + int error = mpWiiSettingFlag->err; + if (error == 0x7d01) result = 0x191; + else if (error == 0x7d02) result = 0x192; + else if (error == 0x7d03) result = 0x193; + else if (error < 33000) result = 0x194; + else if (error < 0xc418) result = 0x195; + else if (error < 0xc47c) result = 0x196; + else if (error < 0xc4e0) result = 0x197; + else if (error < 0xc544) result = 0x198; + else if (error < 0xc760) result = 0x199; + else if (error < 0xc76a) result = 0x1a4; + else if (error < 0xc79c) result = 0x199; + else if (error < 0xc8c8) result = 0x19a; + else if (error < 0xc92c) result = 0x19b; + else if (error < 0xcb84) result = 0x19c; + else if (error < 0xcbe8) result = 0x19d; + else if (error < 0xcc4c) result = 0x19e; + else if (error < 0xcd14) result = 0x19f; + else if (error < 0xcd78) result = 0x1a0; + else if (error < 0xcddc) result = 0x1a1; + else if (error < 0xce40) result = 0x1a2; + else if (error < 55000) result = 0x1a3; + else if (error > 100000) result = 0x1c5; + } else { + int error = mpWiiSettingFlag->err; + if (error == 0x7d01) result = 0x1a5; + else if (error == 0x7d02) result = 0x1a6; + else if (error == 0x7d03) result = 0x1a7; + else if (error < 33000) result = 0x1a8; + else if (error < 0xc418) result = 0x1a9; + else if (error < 0xc47c) result = 0x1aa; + else if (error < 0xc4e0) result = 0x1ab; + else if (error < 0xc544) result = 0x1ac; + else if (error < 0xc760) result = 0x1ad; + else if (error < 0xc76a) result = 0x1b8; + else if (error < 0xc79c) result = 0x1ad; + else if (error < 0xc8c8) result = 0x1ae; + else if (error < 0xc92c) result = 0x1af; + else if (error < 0xcb84) result = 0x1b0; + else if (error < 0xcbe8) result = 0x1b1; + else if (error < 0xcc4c) result = 0x1b2; + else if (error < 0xcd14) result = 0x1b3; + else if (error < 0xcd78) result = 0x1b4; + else if (error < 0xcddc) result = 0x1b5; + else if (error < 0xce40) result = 0x1b6; + else if (error < 55000) result = 0x1b7; + else if (error > 100000) result = 0x1c5; + } + return result; } void Setting::makeSupportCode() { const wchar_t* title = System::getMessage(0x16d); const wchar_t* codeLabel = System::getMessage(0x1b9); wchar_t supportCode[12]; - wchar_t message[0x110]; - swprintf(supportCode, 12, L"\n%03d", unk_0x930); + wchar_t message[0x100]; + swprintf(supportCode, 12, errorFormat, unk_0x930); memset(message, 0, sizeof(message)); - size_t titleLength = wcslen(title); - wcsncat(message, title, titleLength); - message[titleLength] = L'\n'; - message[titleLength + 1] = 0; + size_t messageLength = wcslen(title); + wcsncat(message, title, messageLength); + message[messageLength] = L'\n'; + ++messageLength; + message[messageLength] = 0; size_t labelLength = wcslen(codeLabel); - wcsncat(message + titleLength + 1, codeLabel, labelLength); + wcsncat(message + messageLength, codeLabel, labelLength); + messageLength += labelLength; size_t codeLength = wcslen(supportCode); - wcsncat(message + titleLength + 1 + labelLength, supportCode, codeLength); - message[titleLength + 1 + labelLength + codeLength] = 0; + wcsncat(message + messageLength, supportCode, codeLength); + messageLength += codeLength; + message[messageLength] = 0; System::getDialog()->callBtn2(message, 0x142, 0x141, true); } void Setting::setInitializeResult(bool initialized, int error) { waitFinish(); - if (!initialized) { - if (error == -2) { + if (initialized) { + www::wiisetting::setFuncResult(1); + } else { + if (error < -2) { + if (error == -5) { + System::getErrorHandler()->set(ErrorHandler::DEFAULT, 1); + } + } else if (error == -2) { System::getErrorHandler()->log("NandSDWorker", error, "iplSetting.cpp", 0x13a7); System::getErrorHandler()->set(ErrorHandler::DEFAULT, 2); - } else if (error == -5) { - System::getErrorHandler()->set(ErrorHandler::DEFAULT, 1); } - } else { - www::wiisetting::setFuncResult(1); } } void Setting::setUSBAP() { - if (unk_0x84 == 2) { - if (unk_0x91C[1] != 0) { - www::wiisetting::setFuncResult(unk_0x91C[1]); - unk_0x84 = 1; - unk_0x91C[1] = 0; - resetFuncMsgQ(); + if (unk_0x84 != 2) { + if (unk_0x84 < 2) { + if (unk_0x84 >= 1) { + if (static_cast(mpUSBAPThread)->is()) { + bool result = SCGetOwnerNickName(reinterpret_cast(mSettingData)); + if (!result) { + www::wiisetting::setFuncResult(2); + resetFuncMsgQ(); + } else { + OSReport("USB SCGetOwnerNickName:%d\n", result); + static_cast(mpUSBAPThread)->setData( + reinterpret_cast(mSettingData), &unk_0x91C[1]); + static_cast(mpUSBAPThread)->Init( + reinterpret_cast(mpMem2BrowserBuffer), + reinterpret_cast(mpBrowserStringBuffer)); + unk_0x84 = 2; + } + } + } } - } else if (unk_0x84 == 1 && static_cast(mpUSBAPThread)->is()) { - SCOwnerNickname nickname; - int result = SCGetOwnerNickName(&nickname); - if (!result) { - www::wiisetting::setFuncResult(2); - resetFuncMsgQ(); - } else { - OSReport("USB SCGetOwnerNickName:%d\n", result); - static_cast(mpUSBAPThread)->setData( - reinterpret_cast(nickname.name), &unk_0x91C[1]); - static_cast(mpUSBAPThread)->Init( - reinterpret_cast(mpMem1BrowserBuffer), - reinterpret_cast(mpMem2BrowserBuffer)); - unk_0x84 = 2; + } else if (unk_0x91C[1] != 0) { + www::wiisetting::setFuncResult(unk_0x91C[1]); + unk_0x84 = 1; + unk_0x91C[1] = 0; + resetFuncMsgQ(); } - } } void Setting::cancelUSBAP() { - if (unk_0x84 == 3) { + switch (unk_0x84) { + case 3: if (unk_0x91C[1] != 0 || static_cast(mpUSBAPThread)->is()) { www::wiisetting::setFuncResult(5); unk_0x84 = 1; unk_0x91C[1] = 0; resetFuncMsgQ(); } - } else if (unk_0x84 > 0 && unk_0x84 < 3) { + break; + case 1: + case 2: static_cast(mpUSBAPThread)->cancel(); unk_0x84 = 3; + break; + default: + break; } } void Setting::AOSSProcess() { - int error = mpWiiSettingFlag->err; - if (error == '"') { + u8 message = mpWiiSettingFlag->smthMsgData; + if (message == 0x22u) { if (mAOSSState == 3) { if (System::getDialog()->getLastResult() >= 0) { mAOSSState = 0; @@ -3323,11 +3438,10 @@ namespace ipl { } return; } - AOSSThread* thread = reinterpret_cast(mpAOSSThread); - bool cancelled = error == '!'; + bool cancelled = message == 0x21u; if (mAOSSState == 0) { if (!snd::getSystem()->isSEActive("WIPL_SE_DECIDE")) { - if (cancelled || thread->start() == 0) { + if (cancelled || static_cast(mpAOSSThread)->start() == 0) { www::wiisetting::setFuncResult(cancelled ? 5 : 2); resetFuncMsgQ(); } else { @@ -3336,7 +3450,7 @@ namespace ipl { } } else if (mAOSSState >= 0 && mAOSSState < 3) { int result = 0; - if (thread->finish(&m_AOSSConfig, &result) != 0) { + if (static_cast(mpAOSSThread)->finish(&m_AOSSConfig, &result) != 0) { mAOSSState = 0; if (cancelled) { www::wiisetting::setFuncResult(5); @@ -3351,18 +3465,15 @@ namespace ipl { } resetFuncMsgQ(); } else if (cancelled && mAOSSState != 2) { - thread->cancel(); + static_cast(mpAOSSThread)->cancel(); mAOSSState = 2; } } } void Setting::RakuProcess() { - int command = mpWiiSettingFlag->smthMsgData; - int state = reinterpret_cast(mpRakuRakuThread)->getState(); - RakuRakuThread* thread = reinterpret_cast(mpRakuRakuThread); - int result = 0; - if (command == ',') { + u8 command = mpWiiSettingFlag->smthMsgData; + if (command == 0x2cu) { if (mRakuState != 1) { System::getDialog()->callBtn1(0x1c3, 0x2e); mRakuState = 1; @@ -3374,38 +3485,43 @@ namespace ipl { } return; } - if (command == '+' && (state == 0 || state == 6 || state == 7 || state == 8)) { - if (thread->finish(NULL, NULL) != 0) { + bool cancelCommand = command == 0x2bu; + int state = static_cast(mpRakuRakuThread)->getState(); + int result = 0; + if (cancelCommand && (state == 0 || state == 6 || state == 7 || state == 8)) { + if (static_cast(mpRakuRakuThread)->finish(NULL, NULL) != 0) { www::wiisetting::setFuncResult(5); resetFuncMsgQ(); } else { - thread->cancel(); + static_cast(mpRakuRakuThread)->cancel(); } return; } - if (command != '+' && state == 0) { - if (!snd::getSystem()->isSEActive("WIPL_SE_DECIDE") && thread->start() == 0) { + if (!cancelCommand && state == 0) { + if (!snd::getSystem()->isSEActive("WIPL_SE_DECIDE") && + static_cast(mpRakuRakuThread)->start() == 0) { www::wiisetting::setFuncResult(2); resetFuncMsgQ(); } return; } - if (command != '+' && state == 5) { - if (command == ')') { + if (!cancelCommand && state == 5) { + if (mpWiiSettingFlag->smthMsgData == 0x29u) { www::wiisetting::setFuncResult(1); resetFuncMsgQ(); } return; } if (state == 7) { - if (thread->finish(NULL, &result) != 0) { + if (static_cast(mpRakuRakuThread)->finish(NULL, &result) != 0) { www::wiisetting::setFuncResult(2); resetFuncMsgQ(); } return; } if (state > 4 && state < 7) { - if (thread->finish(&m_RakuConfig.cfg, &result) != 0) { + if (static_cast(mpRakuRakuThread)->finish( + &m_RakuConfig.cfg, &result) != 0) { if (result == 1) { ncd::NCDSetting::getData(); ncd::NCDSetting::getID(); @@ -3418,15 +3534,16 @@ namespace ipl { } return; } - if (state > 0 && state < 4 && command == '(') { + if (state > 0 && state < 4 && mpWiiSettingFlag->smthMsgData == 0x28u) { www::wiisetting::setFuncResult(1); resetFuncMsgQ(); } } void Setting::waitStart() { - mpWaitLayout->getAnim(0)->initFrame(); - mpWaitLayout->getAnim(0)->restart(); + layout::Animator* animation = mpWaitLayout->getAnim(0); + animation->initFrame(); + animation->restart(); mpWaitLayout->FindPaneByName("G_Wait")->SetVisible(true); snd::getSystem()->startSE("WIPL_SE_COPYING"); } @@ -3442,15 +3559,14 @@ namespace ipl { } void Setting::setSE() { - u8& action = mpWiiSettingData->data[0x37]; - u8& pendingAction = mpWiiSettingData->data[0x38]; - if (unk_0xB9C < 10 && action == 2) { - action = 0; + if (unk_0xB9C < 10 && mpWiiSettingData->data[0x37] == 2) { + mpWiiSettingData->data[0x37] = 0; } - if ((action == 0 || action == 2) && pendingAction != 0) { - action = pendingAction; + if ((mpWiiSettingData->data[0x37] == 0 || mpWiiSettingData->data[0x37] == 2) && + mpWiiSettingData->data[0x38] != 0) { + mpWiiSettingData->data[0x37] = mpWiiSettingData->data[0x38]; } - switch (action) { + switch (mpWiiSettingData->data[0x37]) { case 1: snd::getSystem()->startSE("WIPL_SE_BT_PUSH"); break; @@ -3494,32 +3610,37 @@ namespace ipl { snd::getSystem()->startSE("WIPL_SE_CANCEL"); break; } - if (action == 2 || action == 0 || mpWiiSettingData->data[0x12] == 0x1e || pendingAction != 0) { - if (action == 2) { - controller::Interface* controller = System::getYoungController(); - if (controller != NULL) { - controller->rumble(0); - } - } - } else { + if (mpWiiSettingData->data[0x37] != 2 && mpWiiSettingData->data[0x37] != 0 && + mpWiiSettingData->data[0x12] != 0x1e && mpWiiSettingData->data[0x38] == 0) { unk_0xB9C = 0; + } else if (mpWiiSettingData->data[0x37] == 2) { + controller::Interface* controller = System::getYoungController(); + if (controller != NULL) { + controller->rumble(0); + } } - action = 0; - pendingAction = 0; + mpWiiSettingData->data[0x37] = 0; + mpWiiSettingData->data[0x38] = 0; } void APEvent::onEvent(u32 componentID, u32 event, void* data) { gui::PaneComponent* component = static_cast(mpManager->getComponent(componentID)); const char* paneName = component->getPane()->GetName(); - if (event == ::gui::EventHandler::ON_POINT) { + switch (event) { + case ::gui::EventHandler::ON_POINT: mpSetting->start_point_event(paneName); - } else if (event == ::gui::EventHandler::ON_TRIG) { + break; + case ::gui::EventHandler::ON_TRIG: controller::Interface* input = static_cast(data); if (input->downTrg(0x100800)) { mpSetting->start_trig_event(paneName); } - } else if (event == ::gui::EventHandler::ON_LEFT) { + break; + case ::gui::EventHandler::ON_LEFT: mpSetting->start_left_event(paneName); + break; + default: + break; } } -- 2.49.1 From c21dcc3d31837545a627b2d17cb2abb3e39e459f Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 29 Sep 2026 04:21:39 -0500 Subject: [PATCH 09/18] iplSDMemory: 48/66 functions (#260) * sdmemory: carry over worker delta (sd channel select header changes left out) * add SDChannelSelect state/worker accessors used by iplSDMemory --- config/43U/symbols.txt | 38 +- include/scene/board/iplFocusObject.h | 6 + include/scene/sdChannelMemory/iplSDMemory.h | 52 +- .../sdChannelSelect/iplSDChannelSelect.h | 5 + include/system/iplDialogWindow.h | 3 + include/system/iplNandSDWorker.h | 4 + include/utility/iplScroller.h | 3 + libs/NW4R/include/nw4r/lyt/textBox.h | 6 + src/scene/sdChannelMemory/iplSDMemory.cpp | 1025 ++++++++++++++++- 9 files changed, 1096 insertions(+), 46 deletions(-) diff --git a/config/43U/symbols.txt b/config/43U/symbols.txt index db234d49..819ea9e1 100644 --- a/config/43U/symbols.txt +++ b/config/43U/symbols.txt @@ -4837,7 +4837,7 @@ onEvent__Q33ipl5scene22SDMenuEventHandlerBaseFUlUlPv = .text:0x813EB51C; // type onEventDerived__Q33ipl5scene22SDMenuEventHandlerBaseFUlUlPCQ33ipl10controller9Interface = .text:0x813EB5E8; // type:function size:0x4 __ct__Q33ipl5scene8SDMemoryFv = .text:0x813EB5EC; // type:function size:0x48 __dt__Q33ipl5scene8SDMemoryFv = .text:0x813EB634; // type:function size:0x5C -create__Q33ipl5scene8SDMemoryFPQ23EGG4HeapPQ33ipl4nand10LayoutFilePQ33ipl5scene17NandSDCardManager = .text:0x813EB690; // type:function size:0x10A0 +create__Q33ipl5scene8SDMemoryFPQ23EGG4HeapPQ33ipl4nand10LayoutFilePQ33ipl5scene15SDChannelSelect = .text:0x813EB690; // type:function size:0x10A0 setTitleLists__Q33ipl5scene8SDMemoryFRCQ43ipl5scene8SDMemory10TitleRangeRCQ43ipl5scene8SDMemory10TitleRange = .text:0x813EC730; // type:function size:0xD4 setScrollLimit__Q33ipl5scene8SDMemoryFv = .text:0x813EC804; // type:function size:0x144 init__Q33ipl7utility8ScrollerFv = .text:0x813EC948; // type:function size:0x20 @@ -4879,28 +4879,28 @@ onDialogState21__Q33ipl5scene8SDMemoryFv = .text:0x813EEB94; // type:function si onDialogState22__Q33ipl5scene8SDMemoryFv = .text:0x813EECDC; // type:function size:0x11C onDialogState23__Q33ipl5scene8SDMemoryFv = .text:0x813EEDF8; // type:function size:0x78 onDialogState24__Q33ipl5scene8SDMemoryFv = .text:0x813EEE70; // type:function size:0xC0 -iplSDMemory_813EEF30 = .text:0x813EEF30; // type:function size:0x88 -iplSDMemory_813EEFB8 = .text:0x813EEFB8; // type:function size:0x70C +draw__Q33ipl5scene8SDMemoryFv = .text:0x813EEF30; // type:function size:0x88 +drawTransferTitles__Q33ipl5scene8SDMemoryFv = .text:0x813EEFB8; // type:function size:0x70C writeFourFlagBytes__Q23ipl5sceneFPUcUcUcUcUc = .text:0x813EF6C4; // type:function size:0x14 -iplSDMemory_813EF6D8 = .text:0x813EF6D8; // type:function size:0x48 +setTitleRowColors__Q23ipl5sceneFPQ34nw4r3lyt7TextBoxRCQ34nw4r2ut5ColorRCQ34nw4r2ut5Color = .text:0x813EF6D8; // type:function size:0x48 GetBeginIter__Q34nw4r2ut28LinkListFv = .text:0x813EF720; // type:function size:0x8 -iplSDMemory_813EF728 = .text:0x813EF728; // type:function size:0x8 +GetEndIter__Q34nw4r2ut28LinkListFv = .text:0x813EF728; // type:function size:0x8 __ne__Q24nw4r2utFQ44nw4r2ut28LinkList8IteratorQ44nw4r2ut28LinkList8Iterator = .text:0x813EF730; // type:function size:0x18 getControlPaneIndex__Q33ipl5scene8SDMemoryFPCc = .text:0x813EF748; // type:function size:0x74 -iplSDMemory_813EF7BC = .text:0x813EF7BC; // type:function size:0x128 -iplSDMemory_813EF8E4 = .text:0x813EF8E4; // type:function size:0xF0 -iplSDMemory_813EF9D4 = .text:0x813EF9D4; // type:function size:0x120 -iplSDMemory_813EFAF4 = .text:0x813EFAF4; // type:function size:0xD8 -iplSDMemory_813EFBCC = .text:0x813EFBCC; // type:function size:0xC0 -iplSDMemory_813EFC8C = .text:0x813EFC8C; // type:function size:0x160 -iplSDMemory_813EFDEC = .text:0x813EFDEC; // type:function size:0x128 -iplSDMemory_813EFF14 = .text:0x813EFF14; // type:function size:0x24C -iplSDMemory_813F0160 = .text:0x813F0160; // type:function size:0xD8 -iplSDMemory_813F0238 = .text:0x813F0238; // type:function size:0x74 -iplSDMemory_813F02AC = .text:0x813F02AC; // type:function size:0x144 -iplSDMemory_813F03F0 = .text:0x813F03F0; // type:function size:0x10C -iplSDMemory_813F04FC = .text:0x813F04FC; // type:function size:0x1A0 -iplSDMemory_813F069C = .text:0x813F069C; // type:function size:0xD8 +activateControlPane__Q33ipl5scene8SDMemoryFPCcPQ23gui9Component = .text:0x813EF7BC; // type:function size:0x128 +deactivateControlPane__Q33ipl5scene8SDMemoryFPCc = .text:0x813EF8E4; // type:function size:0xF0 +cancelControlPane__Q33ipl5scene8SDMemoryFPCc = .text:0x813EF9D4; // type:function size:0x120 +onEvent__Q43ipl5scene8SDMemory23ControlPaneEventHandlerFUlUlPv = .text:0x813EFAF4; // type:function size:0xD8 +getTitlePaneIndex__Q33ipl5scene8SDMemoryFPCc = .text:0x813EFBCC; // type:function size:0xC0 +activateTitlePane__Q33ipl5scene8SDMemoryFPCcPQ23gui9Component = .text:0x813EFC8C; // type:function size:0x160 +deactivateTitlePane__Q33ipl5scene8SDMemoryFPCc = .text:0x813EFDEC; // type:function size:0x128 +selectTitlePane__Q33ipl5scene8SDMemoryFPCc = .text:0x813EFF14; // type:function size:0x24C +onEvent__Q43ipl5scene8SDMemory21TitlePaneEventHandlerFUlUlPv = .text:0x813F0160; // type:function size:0xD8 +getDialogPaneIndex__Q33ipl5scene8SDMemoryFPCc = .text:0x813F0238; // type:function size:0x74 +activateDialogPane__Q33ipl5scene8SDMemoryFPCcPQ23gui9Component = .text:0x813F02AC; // type:function size:0x144 +deactivateDialogPane__Q33ipl5scene8SDMemoryFPCc = .text:0x813F03F0; // type:function size:0x10C +selectDialogPane__Q33ipl5scene8SDMemoryFPCc = .text:0x813F04FC; // type:function size:0x1A0 +onEvent__Q43ipl5scene8SDMemory22DialogPaneEventHandlerFUlUlPv = .text:0x813F069C; // type:function size:0xD8 __ct__Q33ipl5scene7SettingFPQ23EGG4Heapi = .text:0x813F0774; // type:function size:0xF8 isAnimating__Q33ipl5scene7SettingFv = .text:0x813F086C; // type:function size:0x3C getFuncMsgQ__Q33ipl5scene7SettingFv = .text:0x813F08A8; // type:function size:0x68 diff --git a/include/scene/board/iplFocusObject.h b/include/scene/board/iplFocusObject.h index c4af2cf6..70ac3aa1 100644 --- a/include/scene/board/iplFocusObject.h +++ b/include/scene/board/iplFocusObject.h @@ -85,6 +85,9 @@ namespace ipl { } const utility::BScroller& getBInst() { return mBScroller; } +#ifdef IPL_SDMEMORY_SCROLLER_BINST_RESET + void resetBInst() { mBScroller.reset(); } +#endif bool isDownEnd() const { return mScroller.isDownEnd(); } bool isUpEnd() const { return mScroller.isUpEnd(); } @@ -98,6 +101,9 @@ namespace ipl { void setDownLimit(f32 v) { mScroller.setDownLimit(v); } void setUpLimit(f32 v) { mScroller.setUpLimit(v); } +#ifdef IPL_SDMEMORY_SCROLLER_STATE_ACCESSOR + void setState(int state) { mScroller.setState(state); } +#endif bool isActive() const { return mScroller.isActive(); } diff --git a/include/scene/sdChannelMemory/iplSDMemory.h b/include/scene/sdChannelMemory/iplSDMemory.h index e4d3826d..f74b691b 100644 --- a/include/scene/sdChannelMemory/iplSDMemory.h +++ b/include/scene/sdChannelMemory/iplSDMemory.h @@ -10,6 +10,8 @@ namespace ipl { namespace scene { + class SDChannelSelect; + class SDMemory { public: struct TitleRange { @@ -20,9 +22,10 @@ namespace ipl { SDMemory(); ~SDMemory(); - void create(EGG::Heap* heap, nand::LayoutFile* layoutFile, NandSDCardManager* manager); + void create(EGG::Heap* heap, nand::LayoutFile* layoutFile, SDChannelSelect* channelSelect); void setTitleLists(const TitleRange& nandTitles, const TitleRange& sdTitles); bool calc(); + void draw(); void setScrollLimit(); void updateSideArrows(); void resetScrollArrows(); @@ -38,6 +41,7 @@ namespace ipl { private: s32 updateState(); + void drawTransferTitles(); void onDialogState0(); void onDialogState2(); bool onDialogState3(); @@ -63,6 +67,44 @@ namespace ipl { bool onDialogState24(); void resetDialogPaneAnimations(); s32 getControlPaneIndex(const char* paneName); + void activateControlPane(const char* paneName, ::gui::Component* component); + void deactivateControlPane(const char* paneName); + void cancelControlPane(const char* paneName); + s32 getTitlePaneIndex(const char* paneName); + void activateTitlePane(const char* paneName, ::gui::Component* component); + void deactivateTitlePane(const char* paneName); + void selectTitlePane(const char* paneName); + s32 getDialogPaneIndex(const char* paneName); + void activateDialogPane(const char* paneName, ::gui::Component* component); + void deactivateDialogPane(const char* paneName); + void selectDialogPane(const char* paneName); + + class ControlPaneEventHandler : public ::gui::EventHandler { + public: + ControlPaneEventHandler(SDMemory* instance) : ::gui::EventHandler(), mpInstance(instance) {} + virtual void onEvent(u32 compId, u32 event, void* data); + + private: + SDMemory* mpInstance; + }; + + class TitlePaneEventHandler : public ::gui::EventHandler { + public: + TitlePaneEventHandler(SDMemory* instance) : ::gui::EventHandler(), mpInstance(instance) {} + virtual void onEvent(u32 compId, u32 event, void* data); + + private: + SDMemory* mpInstance; + }; + + class DialogPaneEventHandler : public ::gui::EventHandler { + public: + DialogPaneEventHandler(SDMemory* instance) : ::gui::EventHandler(), mpInstance(instance) {} + virtual void onEvent(u32 compId, u32 event, void* data); + + private: + SDMemory* mpInstance; + }; layout::Object* mpMainLayout; layout::Object* mpTitleLayout; @@ -77,7 +119,7 @@ namespace ipl { u32 mPanelStates[3]; u32 mTitlePanelStates[5]; u32 mPanelAnimationStates[4]; - NandSDCardManager* mpNandSDCardManager; + SDChannelSelect* mpSDChannelSelect; TitleRange mNandTitleRange; TitleRange mSDTitleRange; u32 mTitleCount; @@ -86,11 +128,11 @@ namespace ipl { ESTitleId mTitleIds[96]; wchar_t mTitleNames[96][21]; u32 mTitleNameCount; - u32 mNandTitleNameCount; - ESTitleId mNandTitleIds[96]; - u32 mNandTitleCount; u32 mSDTitleCount; ESTitleId mSDTitleIds[96]; + u32 mNandTitleCount; + u32 mNandTitleNameCount; + ESTitleId mNandTitleIds[96]; wchar_t mCurrentTitleName[0x840]; u8 mTransferFlags[4]; u32 mTransferStatus; diff --git a/include/scene/sdChannelSelect/iplSDChannelSelect.h b/include/scene/sdChannelSelect/iplSDChannelSelect.h index ea16e604..e978db31 100644 --- a/include/scene/sdChannelSelect/iplSDChannelSelect.h +++ b/include/scene/sdChannelSelect/iplSDChannelSelect.h @@ -125,6 +125,11 @@ namespace ipl { SDChannelSelect(EGG::Heap* heap); virtual ~SDChannelSelect(); + NandSDWorker::WorkSDState getSDState() const { + return static_cast(mCurrentSDState); + } + NandSDWorker* getWorker() const { return mpSDWorker; } + virtual BOOL isResetProcessDone(); virtual void startResetting(); virtual void prepare(); diff --git a/include/system/iplDialogWindow.h b/include/system/iplDialogWindow.h index 59c707ca..99c4c3ad 100644 --- a/include/system/iplDialogWindow.h +++ b/include/system/iplDialogWindow.h @@ -327,6 +327,9 @@ namespace ipl { void setProgBarLength(int len) { mProgBarLen = len; } /** @return The current length of the progress bar */ int getProgBarLength() { return mProgBarLen; } +#ifdef IPL_SDMEMORY_DIALOG_PROGRESS_FRAME_ACCESSOR + int getProgBarFrame() const { return mProgBarFrame; } +#endif /** * Dialog component handler (Automatically executed by the GUI manager) diff --git a/include/system/iplNandSDWorker.h b/include/system/iplNandSDWorker.h index e51fc8e5..42297f73 100644 --- a/include/system/iplNandSDWorker.h +++ b/include/system/iplNandSDWorker.h @@ -179,6 +179,10 @@ namespace ipl { static const int SD_APP_BACKUP_THUMBNAIL_LENGTH = 0xC800; +#ifdef IPL_SDMEMORY_COMPLETION_PCT_ACCESSOR + static int getCompletionPct() { return s_completion_pct; } +#endif + protected: static const int FAT_PAGES = 8; static const int DATA_PAGES = 32; diff --git a/include/utility/iplScroller.h b/include/utility/iplScroller.h index fe39e065..fae3e157 100644 --- a/include/utility/iplScroller.h +++ b/include/utility/iplScroller.h @@ -73,6 +73,9 @@ namespace ipl { void setDownLimit(f32 v) { mDownLimit = v; } void setUpLimit(f32 v) { mUpLimit = v; } +#ifdef IPL_SDMEMORY_SCROLLER_STATE_ACCESSOR + void setState(int state) { mState = state; } +#endif void addScroll(f32 v) { mScroll += v; } diff --git a/libs/NW4R/include/nw4r/lyt/textBox.h b/libs/NW4R/include/nw4r/lyt/textBox.h index df6cd23d..61be7d8e 100644 --- a/libs/NW4R/include/nw4r/lyt/textBox.h +++ b/libs/NW4R/include/nw4r/lyt/textBox.h @@ -55,6 +55,12 @@ namespace nw4r { NW4R_ASSERT(type < TEXTCOLOR_MAX); return mTextColors[type]; } +#ifdef IPL_SDMEMORY_SET_TEXT_COLORS + void SetTextColors(const ut::Color& first, const ut::Color& second) { + mTextColors[0] = first; + mTextColors[1] = second; + } +#endif void SetTextColor(u32 type, ut::Color value) { NW4R_ASSERT(type < TEXTCOLOR_MAX); mTextColors[type] = value; diff --git a/src/scene/sdChannelMemory/iplSDMemory.cpp b/src/scene/sdChannelMemory/iplSDMemory.cpp index ec77a71a..40847d82 100644 --- a/src/scene/sdChannelMemory/iplSDMemory.cpp +++ b/src/scene/sdChannelMemory/iplSDMemory.cpp @@ -2,26 +2,47 @@ #define IPL_SDMEMORY_SET_TRANSLATE_OUT_OF_LINE #define IPL_SDMEMORY_DIALOG_STATE_ACCESSOR #define IPL_SDMEMORY_GET_TEXT_DRAW_RECT_OUT_OF_LINE +#define IPL_SDMEMORY_SCROLLER_BINST_RESET +#define IPL_SDMEMORY_SD_CHANNEL_SELECT_LAYOUT +#define IPL_SDMEMORY_COMPLETION_PCT_ACCESSOR +#define IPL_SDMEMORY_DIALOG_PROGRESS_FRAME_ACCESSOR +#define IPL_SDMEMORY_SET_TEXT_COLORS +#define IPL_SDMEMORY_SCROLLER_STATE_ACCESSOR +#include "system/iplDialogWindow.h" +#undef IPL_SDMEMORY_DIALOG_PROGRESS_FRAME_ACCESSOR #include "scene/sdChannelMemory/iplSDMemory.h" +#include "scene/sdChannelSelect/iplSDChannelSelect.h" +#undef IPL_SDMEMORY_SET_TEXT_COLORS +#undef IPL_SDMEMORY_SCROLLER_STATE_ACCESSOR #undef IPL_SDMEMORY_DIALOG_STATE_ACCESSOR #undef IPL_SDMEMORY_SET_TRANSLATE_OUT_OF_LINE #undef IPL_SDMEMORY_SCROLLER_INIT_OUT_OF_LINE #undef IPL_SDMEMORY_GET_TEXT_DRAW_RECT_OUT_OF_LINE +#undef IPL_SDMEMORY_SCROLLER_BINST_RESET +#undef IPL_SDMEMORY_SD_CHANNEL_SELECT_LAYOUT +#undef IPL_SDMEMORY_COMPLETION_PCT_ACCESSOR #include "system/iplSystem.h" #include "sound/iplSound.h" #include "utility/iplLayout.h" #include -extern "C" bool iplSDChannelSelect_813DDB74(ipl::scene::NandSDCardManager* manager, +extern "C" bool iplSDChannelSelect_813DDB74(ipl::scene::SDChannelSelect* channelSelect, ipl::scene::SDMemory::TitleRange* nandTitles, ipl::scene::SDMemory::TitleRange* sdTitles, ESTitleId* titleIds, wchar_t* titleNames, u32* titleCount, s32 state); -extern "C" bool iplSDChannelSelect_813DB5EC(ipl::scene::NandSDCardManager* manager, +extern "C" bool iplSDChannelSelect_813DB5EC(ipl::scene::SDChannelSelect* channelSelect, const ESTitleId* titleEntry, ESTitleId titleId); -extern "C" bool iplSDChannelSelect_813DB4D4(ipl::scene::NandSDCardManager* manager, +extern "C" bool iplSDChannelSelect_813DB4D4(ipl::scene::SDChannelSelect* channelSelect, const ESTitleId* titleEntry, ESTitleId titleId, u32 flags); +extern "C" bool iplSDChannelSelect_813DB530(ipl::scene::SDChannelSelect* channelSelect, + ESTitleId** titleNames, ESTitleId** secondaryTitles); +extern "C" bool iplSDChannelSelect_813DB478(ipl::scene::SDChannelSelect* channelSelect, + const ESTitleId* titleEntry, ESTitleId titleId); +extern "C" bool iplSDChannelSelect_813DB58C(ipl::scene::SDChannelSelect* channelSelect, + ESTitleId** titles, ESTitleId** secondaryTitles, + ESTitleId** names); namespace ipl { namespace utility { @@ -35,6 +56,13 @@ namespace ipl { } namespace scene { + typedef ::gui::Component GuiComponent; + typedef ::gui::PaneComponent GuiPaneComponent; + typedef controller::Interface ControllerInterface; + + void setTitleRowColors(nw4r::lyt::TextBox* textBox, const nw4r::ut::Color& first, + const nw4r::ut::Color& second); + static const char* const sControlPaneNames[] = { "A", "B", "B_BtnA", }; @@ -47,8 +75,8 @@ namespace ipl { SDMemory::~SDMemory() {} - void SDMemory::create(EGG::Heap* heap, nand::LayoutFile* layoutFile, NandSDCardManager* manager) { - mpNandSDCardManager = manager; + void SDMemory::create(EGG::Heap* heap, nand::LayoutFile* layoutFile, SDChannelSelect* channelSelect) { + mpSDChannelSelect = channelSelect; mpMainLayout = new (heap) layout::Object(heap, layoutFile, "arc", "mn_DialogWindow_ChChange_a.brlyt"); mpMainLayout->bindToGroup("mn_DialogWindow_ChChange_a_DialogIn.brlan", "G_InOut", false, true); @@ -168,6 +196,37 @@ namespace ipl { mpProgressLayout->finishBinding(); mpProgressLayout->getAnim(0)->initAnmFrame(); + ControlPaneEventHandler* controlEvent = new ControlPaneEventHandler(this); + mpPaneManagers[0] = new gui::PaneManager(controlEvent, mpMainLayout->getDrawInfo(), NULL, NULL); + mpPaneManagers[0]->setupScene(mpMainLayout); + mpPaneManagers[0]->setAllComponentTriggerTarget(false); + for (s32 i = 0; i < 3; ++i) { + mpPaneManagers[0]->setTriggerTarget(mpMainLayout->FindPaneByName(sControlPaneNames[i]), true); + } + + TitlePaneEventHandler* titleEvent = new TitlePaneEventHandler(this); + mpPaneManagers[1] = new gui::PaneManager(titleEvent, mpTitleLayout->getDrawInfo(), NULL, NULL); + mpPaneManagers[1]->setupScene(mpTitleLayout); + mpPaneManagers[1]->setAllComponentTriggerTarget(false); + if (mDisplayMode == 4) { + for (s32 i = 0; i < 5; ++i) { + mpPaneManagers[1]->setTriggerTarget(mpTitleLayout->FindPaneByName(sTitlePaneNames[i]), true); + } + } else { + for (s32 i = 0; i < 4; ++i) { + mpPaneManagers[1]->setTriggerTarget( + mpTitleLayout->FindPaneByName(sAdditionalTitlePaneNames[i]), true); + } + } + + DialogPaneEventHandler* dialogEvent = new DialogPaneEventHandler(this); + mpPaneManagers[2] = new gui::PaneManager(dialogEvent, mpDialogLayout->getDrawInfo(), NULL, NULL); + mpPaneManagers[2]->setupScene(mpDialogLayout); + mpPaneManagers[2]->setAllComponentTriggerTarget(false); + for (s32 i = 0; i < 4; ++i) { + mpPaneManagers[2]->setTriggerTarget(mpDialogLayout->FindPaneByName(sDialogPaneNames[i]), true); + } + } void SDMemory::setTitleLists(const TitleRange& nandTitles, const TitleRange& sdTitles) { @@ -482,6 +541,134 @@ namespace ipl { return stateResult == 2 ? true : result; } + s32 SDMemory::updateState() { + NandSDWorker::WorkSDState sdState = mpSDChannelSelect->getSDState(); + s32 result = 0; + if (static_cast(sdState - NandSDWorker::SD_STATE_EJECTED) > + static_cast(NandSDWorker::SD_STATE_INSERTED - NandSDWorker::SD_STATE_EJECTED)) { + return result; + } + + switch (mDialogState) { + case 1: + case 2: { + mpMainLayout->getAnim(1)->initAnmFrame(); + mpMainLayout->getAnim(1)->initFrame(); + mpMainLayout->getAnim(1)->restart(); + mpDialogLayout->getAnim(1)->initAnmFrame(); + mpDialogLayout->getAnim(1)->initFrame(); + mpDialogLayout->getAnim(1)->restart(); + mTransferFlags[1] = 0; + mDialogState = 3; + result = 1; + break; + } + case 3: + if (mTransferFlags[1] != 0) { + mpDialogLayout->getAnim(1)->initAnmFrame(); + mpDialogLayout->getAnim(1)->initFrame(); + mpDialogLayout->getAnim(1)->restart(); + mTransferFlags[1] = 0; + } + if (!mpMainLayout->isPlaying(1) && !mpDialogLayout->isPlaying(1)) { + result = 2; + } else { + result = 1; + } + break; + case 5: + case 6: + mpTitleLayout->getAnim(1)->initAnmFrame(); + mpTitleLayout->getAnim(1)->initFrame(); + mpTitleLayout->getAnim(1)->restart(); + mpDialogLayout->getAnim(1)->initAnmFrame(); + mpDialogLayout->getAnim(1)->initFrame(); + mpDialogLayout->getAnim(1)->restart(); + mTransferFlags[1] = 0; + mDialogState = 7; + result = 1; + break; + case 7: + if (mTransferFlags[1] != 0) { + mpDialogLayout->getAnim(1)->initAnmFrame(); + mpDialogLayout->getAnim(1)->initFrame(); + mpDialogLayout->getAnim(1)->restart(); + mTransferFlags[1] = 0; + } + if (!mpTitleLayout->isPlaying(1) && !mpDialogLayout->isPlaying(1)) { + result = 2; + } else { + result = 1; + } + break; + case 10: + case 11: + mDialogState = 12; + mpDialogLayout->getAnim(1)->initAnmFrame(); + mpDialogLayout->getAnim(1)->initFrame(); + mpDialogLayout->getAnim(1)->restart(); + mTransferFlags[1] = 0; + mScroller.init(); + mScroller.resetBInst(); + if (mControllerFlags[0] != 0) { + hideDownArrow(); + } + if (mControllerFlags[1] != 0) { + hideUpArrow(); + } + result = 1; + break; + case 12: + if (mTransferFlags[1] != 0) { + mScroller.init(); + mScroller.resetBInst(); + mpDialogLayout->getAnim(1)->initAnmFrame(); + mpDialogLayout->getAnim(1)->initFrame(); + mpDialogLayout->getAnim(1)->restart(); + mTransferFlags[1] = 0; + } + if (!mpTitleLayout->isPlaying(1) && !mpDialogLayout->isPlaying(1)) { + result = 2; + } else { + result = 1; + } + break; + case 8: + case 22: { + DialogWindow* dialog = System::getDialog(); + s32 dialogState = dialog->getStateForSDMemory(); + if (dialogState == 2) { + dialog->terminate(); + mpDialogLayout->getAnim(1)->initAnmFrame(); + mpDialogLayout->getAnim(1)->initFrame(); + mpDialogLayout->getAnim(1)->restart(); + mTransferFlags[1] = 0; + } else if ((dialogState == 3 || dialogState == 4) && mTransferFlags[1] != 0) { + mpDialogLayout->getAnim(1)->initAnmFrame(); + mpDialogLayout->getAnim(1)->initFrame(); + mpDialogLayout->getAnim(1)->restart(); + mTransferFlags[1] = 0; + } + + if (dialog->getLastResult() != -1) { + if (mpDialogLayout->isPlaying(1) || dialog->getLastResult() == 1) { + result = 1; + } else { + result = 2; + } + } + break; + } + default: + break; + } + + if (result == 2) { + mErrorCode = 6; + } + return result; + } + void SDMemory::onDialogState0() { if (!mpMainLayout->isPlaying(-1)) { for (int i = 0; i < 3; i++) { @@ -513,7 +700,7 @@ namespace ipl { if (!mpMainLayout->isPlaying(-1)) { switch (mProcessState) { case 0: - if (iplSDChannelSelect_813DDB74(mpNandSDCardManager, &mNandTitleRange, &mSDTitleRange, + if (iplSDChannelSelect_813DDB74(mpSDChannelSelect, &mNandTitleRange, &mSDTitleRange, mTitleIds, &mTitleNames[0][0], &mTitleCount, 2)) { mDialogState = 4; mpTitleLayout->getAnim(0)->initAnmFrame(); @@ -570,14 +757,14 @@ namespace ipl { mTransferStartTime = OSGetTime(); } - if (!mpNandSDCardManager->getWorker()->is_working() && + if (!mpSDChannelSelect->getWorker()->is_working() && OSGetTime() - mTransferStartTime > OS_TIMER_CLOCK) { System::getDialog()->terminate(); } } if (System::getDialog()->getLastResult() != -1) { - if (mpNandSDCardManager->getWorker()->get_async_result() == 0) { + if (mpSDChannelSelect->getWorker()->get_async_result() == 0) { mNandTitleCount = mTitleListState.mSecondaryCount; mTitleNameCount = mTitleListState.mNameCount; } else { @@ -586,23 +773,24 @@ namespace ipl { } mDialogState = 9; - layout::Animator* animation = mpMainLayout->getAnim(0); + layout::Animator* animation = mpDialogLayout->getAnim(0); animation->initFrame(); animation->restart(); - nw4r::lyt::Pane* headerPane = mpMainLayout->FindPaneByName("T_Header"); + nw4r::lyt::Pane* headerPane = mpDialogLayout->FindPaneByName("T_Header"); static_cast(headerPane)->SetString(System::getMessage(0xBE), 0); mButtonState = 0; - nw4r::lyt::Pane* titlePane = mpMainLayout->FindPaneByName("N_Body"); - nw4r::lyt::Pane* bodyPane = mpMainLayout->FindPaneByName("T_Letter"); + nw4r::lyt::Pane* titlePane = mpDialogLayout->FindPaneByName("N_Body"); + nw4r::lyt::Pane* bodyPane = mpDialogLayout->FindPaneByName("T_Letter"); bodyPane->SetAlpha(0xFF); for (u32 i = 0; i < mTitleCount; i++) { utility::layout::set_string(bodyPane, mTitleNames[i]); - nw4r::ut::Rect textRect = mpMainLayout->getTextDrawRect("T_Letter"); + nw4r::ut::Rect textRect = mpDialogLayout->getTextDrawRect("T_Letter"); f32 lineCount = -(textRect.bottom - textRect.top) / titlePane->GetSize().height; - mButtonState += static_cast(ceil(lineCount)); + f32 roundedLineCount = ceil(lineCount); + mButtonState += static_cast(roundedLineCount); } setScrollLimit(); @@ -655,8 +843,8 @@ namespace ipl { } } - bool previousDownEnd = !!mControllerFlags[0]; - bool previousUpEnd = !!mControllerFlags[1]; + bool previousDownEnd = !mControllerFlags[0]; + bool previousUpEnd = !mControllerFlags[1]; updateScrollArrows(previousDownEnd, previousUpEnd, mScroller.isUpEnd(), mScroller.isDownEnd()); if (mScroller.getBInst().isActive() ? false : true) { @@ -667,7 +855,9 @@ namespace ipl { void SDMemory::onDialogState11() { if (!mpDialogLayout->isPlaying(4) && !mpDialogLayout->isPlaying(7)) { - if (mProcessState < 4 && mProcessState >= 2) { + switch (mProcessState) { + case 2: + case 3: mDialogState = 12; mpDialogLayout->getAnim(1)->initAnmFrame(); mpDialogLayout->getAnim(1)->play(); @@ -678,8 +868,181 @@ namespace ipl { if (mControllerFlags[1] != 0) { hideUpArrow(); } - } else { + break; + default: mDialogState = 10; + break; + } + } + } + + void SDMemory::onDialogState12() { + if (mpDialogLayout->isPlaying(1)) { + return; + } + + switch (mProcessState) { + case 2: { + mDialogState = 4; + layout::Animator* animation = mpTitleLayout->getAnim(0); + animation->initAnmFrame(); + animation->play(); + snd::getSystem()->startSE("WIPL_SE_INFO_WINDOW"); + break; + } + case 3: { + mTransferFlags[0] = 0; + System::getHomeButtonMenu()->disable(); + + if ((mTitleNameCount != 0 || mNandTitleCount != 0) && + mpSDChannelSelect->getWorker()->is_sd_write_protected()) { + mErrorCode = 5; + mDialogState = 23; + mMessageId = 0xBF; + return; + } + + if (iplSDChannelSelect_813DB530(mpSDChannelSelect, &mTitleListState.mpNames, + &mTitleListState.mpSecondaryTitles)) { + mDialogState = 19; + mCurrentTitleName[0] = L'\0'; + mCurrentTitle = 0; + const wchar_t* message = System::getMessage(0xB1); + const wchar_t* titleName = mTitleNames[mCurrentTitle]; + swprintf(mCurrentTitleName, 0x107f, L"%ls\n%ls", titleName, message); + System::getDialog()->callBtnPrgNoShade(mCurrentTitleName); + } else { + mDialogState = 23; + mErrorCode = 1; + mMessageId = 0xAE; + } + break; + } + default: + break; + } + } + + extern "C" bool iplSDMemory_813EE358(const SDMemory* memory, + const ESTitleId* titleEntry, ESTitleId titleId, + const ESTitleId* titleIds, u32 titleCount) { + for (u32 i = 0; i < titleCount; i++) { + if (titleIds[i] == titleId) { + return true; + } + } + + return false; + } + + void SDMemory::onDialogState13() { + if (!mpSDChannelSelect->getWorker()->is_working()) { + s32 result = mpSDChannelSelect->getWorker()->get_async_result(); + if (result == 0) { + const ESTitleId* titleEntry = &mTitleIds[mCurrentTitle]; + ESTitleId titleId = *titleEntry; + if (iplSDMemory_813EE358(this, titleEntry, titleId, + mNandTitleIds, mNandTitleCount)) { + mDialogState = 17; + } else { + mDialogState = 13; + } + } else { + if (result > 0) { + System::getDialog()->terminate(); + mDialogState = 20; + mErrorCode = 2; + mMessageId = 0xB5; + } else { + System::getDialog()->terminate(); + mDialogState = 20; + mErrorCode = 1; + mMessageId = 0xAE; + } + } + } + } + + void SDMemory::onDialogState14() { + if (System::getDialog()->getStateForSDMemory() != 2) { + return; + } + + mCurrentTitleName[0] = L'\0'; + const wchar_t* message = System::getMessage(0xB1); + const wchar_t* titleName = mTitleNames[mCurrentTitle]; + swprintf(mCurrentTitleName, 0x107f, L"%ls\n%ls", titleName, message); + System::getDialog()->setTitleForSDMemory(mCurrentTitleName); + + bool isKnownTitle; + { + const ESTitleId* titleEntry = &mTitleIds[mCurrentTitle]; + ESTitleId titleId = *titleEntry; + isKnownTitle = iplSDMemory_813EE358(this, titleEntry, titleId, + mSDTitleIds, mTitleNameCount); + } + if (!isKnownTitle) { + const ESTitleId* titleEntry = &mTitleIds[mCurrentTitle]; + ESTitleId titleId = *titleEntry; + isKnownTitle = iplSDMemory_813EE358(this, titleEntry, titleId, + mNandTitleIds, mNandTitleCount); + } + + if (isKnownTitle) { + const ESTitleId* titleEntry = &mTitleIds[mCurrentTitle]; + ESTitleId titleId = *titleEntry; + if (iplSDChannelSelect_813DB478(mpSDChannelSelect, titleEntry, titleId)) { + mDialogState = 14; + } else { + System::getDialog()->terminate(); + mDialogState = 20; + mErrorCode = 1; + mMessageId = 0xAE; + } + } else { + f32 completedTitles = static_cast(mCurrentTitle + 1); + f32 totalTitles = static_cast(mTitleCount); + mDialogState = 15; + f32 progress = completedTitles * 100.0f / totalTitles; + if (progress >= 100.0f) { + progress = 100.0f; + } + + mTransferFrame = static_cast(progress); + System::getDialog()->setProgBarLength(mTransferFrame); + } + } + + void SDMemory::onDialogState15() { + u32 completedPercent = NandSDWorker::getCompletionPct() / mTitleCount; + u32 currentTitle = mCurrentTitle; + u32 titleCount = mTitleCount; + f32 completedPercentFloat = static_cast(completedPercent); + f32 currentTitleNumber = static_cast(currentTitle + 1); + f32 progress = currentTitleNumber * 100.0f; + progress = progress / static_cast(titleCount); + progress += completedPercentFloat; + if (progress >= 100.0f) { + progress = 100.0f; + } + + mTransferFrame = static_cast(progress); + System::getDialog()->setProgBarLength(mTransferFrame); + + if (!mpSDChannelSelect->getWorker()->is_working()) { + s32 result = mpSDChannelSelect->getWorker()->get_async_result(); + if (result == 0) { + mDialogState = 15; + } else { + System::getDialog()->terminate(); + mDialogState = 20; + if (result == -7) { + mErrorCode = 2; + mMessageId = 0xB5; + } else { + mErrorCode = 1; + mMessageId = 0xAE; + } } } } @@ -687,7 +1050,7 @@ namespace ipl { void SDMemory::onDialogState16() { if (mTitleCount > mCurrentTitle && System::isReceiveScheduleStopped()) { const ESTitleId* titleEntry = &mTitleIds[mCurrentTitle]; - if (iplSDChannelSelect_813DB4D4(mpNandSDCardManager, titleEntry, *titleEntry, 0)) { + if (iplSDChannelSelect_813DB4D4(mpSDChannelSelect, titleEntry, *titleEntry, 0)) { mDialogState = 16; } else { System::getDialog()->terminate(); @@ -698,6 +1061,42 @@ namespace ipl { } } + void SDMemory::onDialogState17() { + if (mpSDChannelSelect->getWorker()->is_working()) { + return; + } + + if (System::getDialog()->getProgBarFrame() < mTransferFrame) { + return; + } + + const ESTitleId* titleEntry = &mTitleIds[mCurrentTitle]; + System::getChannelManager()->fn_8133AA50(*titleEntry); + + if (mpSDChannelSelect->getWorker()->get_async_result() == 0) { + mCurrentTitle++; + if (mTitleCount > mCurrentTitle) { + const ESTitleId* nextTitle = &mTitleIds[mCurrentTitle]; + ESTitleId nextTitleId = *nextTitle; + if (iplSDMemory_813EE358(this, nextTitle, nextTitleId, + mNandTitleIds, mNandTitleCount)) { + mDialogState = 17; + } else { + mDialogState = 13; + } + } else { + System::getDialog()->setProgBarLength(100); + mDialogState = 20; + mErrorCode = 0; + } + } else { + System::getDialog()->terminate(); + mDialogState = 20; + mErrorCode = 1; + mMessageId = 0xAE; + } + } + void SDMemory::onDialogState18() { if (System::getDialog()->getStateForSDMemory() == 2) { mCurrentTitleName[0] = L'\0'; @@ -708,7 +1107,7 @@ namespace ipl { const ESTitleId* titleEntry = &mTitleIds[mCurrentTitle]; const ESTitleId titleId = *titleEntry; - if (iplSDChannelSelect_813DB5EC(mpNandSDCardManager, titleEntry, titleId)) { + if (iplSDChannelSelect_813DB5EC(mpSDChannelSelect, titleEntry, titleId)) { mDialogState = 18; } else { System::getDialog()->terminate(); @@ -720,8 +1119,8 @@ namespace ipl { } void SDMemory::onDialogState19() { - if (!mpNandSDCardManager->getWorker()->is_working()) { - if (mpNandSDCardManager->getWorker()->get_async_result() == 0) { + if (!mpSDChannelSelect->getWorker()->is_working()) { + if (mpSDChannelSelect->getWorker()->get_async_result() == 0) { mDialogState = 13; } else { System::getDialog()->terminate(); @@ -835,6 +1234,151 @@ namespace ipl { return false; } + void SDMemory::draw() { + utility::Graphics::setDefaultOrtho(0); + mpProgressLayout->draw(); + + switch (mDialogState) { + case 0: + case 1: + case 2: + case 3: + mpMainLayout->draw(); + break; + case 4: + case 5: + case 6: + case 7: + mpTitleLayout->draw(); + break; + case 9: + case 10: + case 11: + case 12: + drawTransferTitles(); + break; + default: + break; + } + } + + void SDMemory::drawTransferTitles() { + nw4r::lyt::Pane* memoPane = mpDialogLayout->FindPaneByName("N_Memo"); + nw4r::lyt::Pane* headerPane = mpDialogLayout->FindPaneByName("header_header"); + nw4r::lyt::Pane* bodyPane = mpDialogLayout->FindPaneByName("header_body"); + + f32 bodyY = headerPane->GetTranslate().y; + if (bodyY < 0.0f) { + mpDialogLayout->draw("header_header"); + } + + nw4r::ut::LinkList::Iterator child = + bodyPane->GetChildList().GetBeginIter(); + while (child != bodyPane->GetChildList().GetEndIter()) { + child->SetAlpha(memoPane->GetAlpha()); + ++child; + } + + u32 lineCount = 0; + f32 messageOffset = 0.0f; + f32 bodyHeight = bodyPane->GetSize().height; + if (mNandTitleCount != 0) { + const wchar_t* messageForCount = System::getMessage(0xCB); + const wchar_t* newline = wcsstr(messageForCount, L"\n"); + while (newline != NULL) { + ++lineCount; + newline = wcsstr(newline + 1, L"\n"); + } + + const wchar_t* messageLine = System::getMessage(0xCB); + nw4r::lyt::TextBox* messageText = static_cast( + mpDialogLayout->FindPaneByName("T_Header_body")); + u32 lineIndex = 0; + while (lineIndex <= lineCount) { + const wchar_t* lineEnd = wcsstr(messageLine, L"\n"); + if (lineEnd != NULL) { + u32 lineLength = static_cast(lineEnd - messageLine); + wcsncpy(mCurrentTitleName, messageLine, lineLength); + mCurrentTitleName[lineLength] = L'\0'; + utility::layout::set_string(messageText, mCurrentTitleName); + messageLine = lineEnd + 1; + } else { + utility::layout::set_string(messageText, messageLine); + } + + if (bodyY < 500.0f) { + nw4r::math::VEC2 translation(0.0f, messageOffset); + bodyPane->SetTranslate(translation); + bodyPane->CalculateMtx(*mpDialogLayout->getDrawInfo()); + mpDialogLayout->draw(bodyPane); + } + + messageOffset -= bodyHeight; + ++lineIndex; + } + } + + messageOffset += bodyHeight; + f32 titleOffset = messageOffset; + + nw4r::lyt::TextBox* titleSizePane = static_cast( + mpDialogLayout->FindPaneByName("T_Letter")); + f32 rowHeight = titleSizePane->GetSize().height; + nw4r::lyt::PaneList::Iterator titleChild = titleSizePane->GetChildList().GetBeginIter(); + while (titleChild != titleSizePane->GetChildList().GetEndIter()) { + titleChild->SetAlpha(memoPane->GetAlpha()); + ++titleChild; + } + + nw4r::lyt::TextBox* titleText = static_cast( + mpDialogLayout->FindPaneByName("T_Letter")); + titleText->SetAlpha(memoPane->GetAlpha()); + + nw4r::ut::Color activeTitleColor(0x34, 0xBE, 0xED, 0xFF); + nw4r::ut::Color inactiveTitleColor(0x64, 0x64, 0x64, 0xFF); + for (u32 titleIndex = 0; titleIndex < mTitleCount; ++titleIndex) { + utility::layout::set_string(titleText, mTitleNames[titleIndex]); + if (titleIndex < mNandTitleCount && mTitleIds[titleIndex] == mNandTitleIds[titleIndex]) { + setTitleRowColors(titleText, activeTitleColor, activeTitleColor); + } else { + setTitleRowColors(titleText, inactiveTitleColor, inactiveTitleColor); + } + + nw4r::ut::Rect textRect = mpDialogLayout->getTextDrawRect("T_Header_body"); + f32 rowTop = textRect.bottom - textRect.top; + u32 visibleRows = static_cast(ceil(-rowTop / rowHeight)); + for (u32 row = 0; row < visibleRows; ++row) { + f32 rowOffset = titleOffset + static_cast(row) * rowHeight; + f32 rowY = bodyY + rowOffset; + if (rowY > -500.0f && rowY < 500.0f) { + nw4r::math::VEC2 translation(0.0f, rowOffset); + titleText->SetTranslate(translation); + titleText->CalculateMtx(*mpDialogLayout->getDrawInfo()); + mpDialogLayout->draw(titleText); + } + } + titleOffset -= rowHeight * static_cast(visibleRows); + } + + nw4r::lyt::Pane* footerPane = mpDialogLayout->FindPaneByName("N_Footer"); + nw4r::lyt::PaneList::Iterator footerChild = footerPane->GetChildList().GetBeginIter(); + while (footerChild != footerPane->GetChildList().GetEndIter()) { + footerChild->SetAlpha(memoPane->GetAlpha()); + ++footerChild; + } + + if (bodyY + titleOffset > -500.0f) { + nw4r::math::VEC2 translation(0.0f, titleOffset); + footerPane->SetTranslate(translation); + footerPane->CalculateMtx(*mpDialogLayout->getDrawInfo()); + mpDialogLayout->draw(footerPane); + } + + mpDialogLayout->draw("header_body"); + mpDialogLayout->draw("N_TopBtn_00"); + mpDialogLayout->draw("N_Memo"); + } + s32 SDMemory::getControlPaneIndex(const char* paneName) { s32 paneIndex = -1; for (s32 i = 0; i < 3; i++) { @@ -847,11 +1391,448 @@ namespace ipl { return paneIndex; } + void SDMemory::activateControlPane(const char* paneName, ::gui::Component* component) { + layout::Animator* animator = NULL; + s32 paneIndex = getControlPaneIndex(paneName); + if (mPanelStates[paneIndex] == 0) { + switch (paneIndex) { + case 0: + animator = mpMainLayout->getAnim(5); + break; + case 1: + animator = mpMainLayout->getAnim(8); + break; + case 2: + animator = mpMainLayout->getAnim(2); + break; + } + + if (animator != NULL) { + animator->initAnmFrame(); + animator->setAnmType(ANIM_TYPE_FORWARD); + animator->initFrame(); + animator->restart(); + snd::getSystem()->startSE("WIPL_SE_BT_TARGETTING"); + if (component != NULL) { + component->offPoint(0); + } + if (static_cast(mPanelStates[paneIndex]) < 4) { + ++mPanelStates[paneIndex]; + } + } + } + } + + void SDMemory::deactivateControlPane(const char* paneName) { + layout::Animator* animator = NULL; + s32 paneIndex = getControlPaneIndex(paneName); + if (static_cast(mPanelStates[paneIndex]) == 1) { + switch (paneIndex) { + case 0: + animator = mpMainLayout->getAnim(6); + break; + case 1: + animator = mpMainLayout->getAnim(9); + break; + case 2: + animator = mpMainLayout->getAnim(3); + break; + } + + if (animator != NULL) { + animator->initAnmFrame(); + animator->setAnmType(ANIM_TYPE_FORWARD); + animator->initFrame(); + animator->restart(); + if (static_cast(mPanelStates[paneIndex]) > 0) { + --mPanelStates[paneIndex]; + } + } + } + } + + void SDMemory::cancelControlPane(const char* paneName) { + layout::Animator* animator = NULL; + s32 paneIndex = getControlPaneIndex(paneName); + if (static_cast(mPanelStates[paneIndex]) > 0) { + switch (paneIndex) { + case 0: + animator = mpMainLayout->getAnim(7); + break; + case 1: + animator = mpMainLayout->getAnim(10); + break; + case 2: + animator = mpMainLayout->getAnim(4); + break; + } + + if (animator != NULL) { + mProcessState = paneIndex; + mDialogState = 2; + animator->initAnmFrame(); + animator->setAnmType(ANIM_TYPE_FORWARD); + animator->initFrame(); + animator->restart(); + if (paneIndex == 2) { + snd::getSystem()->startSE("WIPL_SE_CANCEL"); + } else { + snd::getSystem()->startSE("WIPL_SE_DECIDE"); + } + } + } + } + + void SDMemory::ControlPaneEventHandler::onEvent(u32 compId, u32 event, void* data) { + GuiPaneComponent* component = static_cast(mpManager->getComponent(compId)); + const char* paneName = component->getPane()->GetName(); + s32 eventType = static_cast(event); + switch (eventType) { + case ON_POINT: + mpInstance->activateControlPane(paneName, static_cast(data)); + break; + case ON_LEFT: + mpInstance->deactivateControlPane(paneName); + break; + case ON_TRIG: + if (static_cast(data)->downTrg(controller::BTN_INTERACT)) { + mpInstance->cancelControlPane(paneName); + } + break; + } + } + + s32 SDMemory::getTitlePaneIndex(const char* paneName) { + s32 paneIndex = -1; + if (mDisplayMode == 4) { + for (s32 i = 0; i < 5; i++) { + if (strcmp(paneName, sTitlePaneNames[i]) == 0) { + paneIndex = i; + break; + } + } + } else { + for (s32 i = 0; i < 4; i++) { + if (strcmp(paneName, sAdditionalTitlePaneNames[i]) == 0) { + paneIndex = i + 1; + break; + } + } + } + return paneIndex; + } + + void SDMemory::activateTitlePane(const char* paneName, ::gui::Component* component) { + layout::Animator* animator = NULL; + s32 paneIndex = getTitlePaneIndex(paneName); + u32* panelState = &mTitlePanelStates[paneIndex]; + if (*panelState == 0) { + switch (paneIndex) { + case 0: + animator = mpTitleLayout->getAnim(5); + break; + case 1: + animator = mpTitleLayout->getAnim(8); + break; + case 2: + animator = mpTitleLayout->getAnim(11); + break; + case 3: + animator = mpTitleLayout->getAnim(14); + break; + case 4: + animator = mpTitleLayout->getAnim(2); + break; + } + + if (animator != NULL) { + mProcessState = paneIndex; + mDialogState = 2; + animator->initAnmFrame(); + animator->setAnmType(ANIM_TYPE_FORWARD); + animator->initFrame(); + animator->restart(); + snd::getSystem()->startSE("WIPL_SE_BT_TARGETTING"); + if (component != NULL) { + component->offPoint(0); + } + if (static_cast(*panelState) < 4) { + ++*panelState; + } + } + } + } + + void SDMemory::deactivateTitlePane(const char* paneName) { + layout::Animator* animator = NULL; + s32 paneIndex = getTitlePaneIndex(paneName); + if (static_cast(mTitlePanelStates[paneIndex]) == 1) { + switch (paneIndex) { + case 0: + animator = mpTitleLayout->getAnim(6); + break; + case 1: + animator = mpTitleLayout->getAnim(9); + break; + case 2: + animator = mpTitleLayout->getAnim(12); + break; + case 3: + animator = mpTitleLayout->getAnim(15); + break; + case 4: + animator = mpTitleLayout->getAnim(3); + break; + } + + if (animator != NULL) { + animator->initAnmFrame(); + animator->setAnmType(ANIM_TYPE_FORWARD); + animator->initFrame(); + animator->restart(); + if (static_cast(mTitlePanelStates[paneIndex]) > 0) { + --mTitlePanelStates[paneIndex]; + } + } + } + } + + void SDMemory::selectTitlePane(const char* paneName) { + layout::Animator* animator = NULL; + s32 paneIndex = getTitlePaneIndex(paneName); + if (static_cast(mTitlePanelStates[paneIndex]) > 0) { + switch (paneIndex) { + case 0: + animator = mpTitleLayout->getAnim(7); + iplSDChannelSelect_813DDB74(mpSDChannelSelect, &mNandTitleRange, &mSDTitleRange, + mTitleIds, &mTitleNames[0][0], &mTitleCount, 0); + break; + case 1: + animator = mpTitleLayout->getAnim(10); + iplSDChannelSelect_813DDB74(mpSDChannelSelect, &mNandTitleRange, &mSDTitleRange, + mTitleIds, &mTitleNames[0][0], &mTitleCount, 1); + break; + case 2: + animator = mpTitleLayout->getAnim(13); + iplSDChannelSelect_813DDB74(mpSDChannelSelect, &mNandTitleRange, &mSDTitleRange, + mTitleIds, &mTitleNames[0][0], &mTitleCount, 2); + break; + case 3: + animator = mpTitleLayout->getAnim(16); + iplSDChannelSelect_813DDB74(mpSDChannelSelect, &mNandTitleRange, &mSDTitleRange, + mTitleIds, &mTitleNames[0][0], &mTitleCount, 3); + break; + case 4: + animator = mpTitleLayout->getAnim(4); + break; + } + + if (animator != NULL) { + mProcessState = paneIndex; + mDialogState = 6; + animator->initAnmFrame(); + animator->setAnmType(ANIM_TYPE_FORWARD); + animator->initFrame(); + animator->restart(); + + if (paneIndex >= 0 && paneIndex <= 3) { + memset(mNandTitleIds, 0, sizeof(mNandTitleIds)); + memset(mSDTitleIds, 0, sizeof(mSDTitleIds)); + mNandTitleCount = 0; + mTitleNameCount = 0; + mTitleListState.mpTitles = mTitleIds; + mTitleListState.mCount = mTitleCount; + mTitleListState.mpSecondaryTitles = mNandTitleIds; + mTitleListState.mSecondaryCount = 0; + mTitleListState.mpNames = mSDTitleIds; + mTitleListState.mNameCount = 0; + iplSDChannelSelect_813DB58C(mpSDChannelSelect, + &mTitleListState.mpTitles, + &mTitleListState.mpSecondaryTitles, + &mTitleListState.mpNames); + } + + if (paneIndex == 4) { + snd::getSystem()->startSE("WIPL_SE_CANCEL"); + } else { + snd::getSystem()->startSE("WIPL_SE_DECIDE"); + } + } + } + } + + void SDMemory::TitlePaneEventHandler::onEvent(u32 compId, u32 event, void* data) { + GuiPaneComponent* component = static_cast(mpManager->getComponent(compId)); + const char* paneName = component->getPane()->GetName(); + s32 eventType = static_cast(event); + switch (eventType) { + case ON_POINT: + mpInstance->activateTitlePane(paneName, static_cast(data)); + break; + case ON_LEFT: + mpInstance->deactivateTitlePane(paneName); + break; + case ON_TRIG: + if (static_cast(data)->downTrg(controller::BTN_INTERACT)) { + mpInstance->selectTitlePane(paneName); + } + break; + } + } + + s32 SDMemory::getDialogPaneIndex(const char* paneName) { + s32 paneIndex = -1; + for (s32 i = 0; i < 4; i++) { + if (strcmp(paneName, sDialogPaneNames[i]) == 0) { + paneIndex = i; + break; + } + } + return paneIndex; + } + + void SDMemory::activateDialogPane(const char* paneName, ::gui::Component* component) { + layout::Animator* animator = NULL; + s32 paneIndex = getDialogPaneIndex(paneName); + if (static_cast(mPanelAnimationStates[paneIndex]) == 0) { + switch (paneIndex) { + case 2: + animator = mpDialogLayout->getAnim(2); + break; + case 3: + animator = mpDialogLayout->getAnim(5); + break; + case 0: + animator = mpDialogLayout->getAnim(11); + break; + case 1: + animator = mpDialogLayout->getAnim(8); + break; + } + + if (animator != NULL) { + animator->initAnmFrame(); + animator->setAnmType(ANIM_TYPE_FORWARD); + animator->initFrame(); + animator->restart(); + snd::getSystem()->startSE("WIPL_SE_BT_TARGETTING"); + if (component != NULL) { + component->offPoint(0); + } + if (static_cast(mPanelAnimationStates[paneIndex]) < 4) { + ++mPanelAnimationStates[paneIndex]; + } + } + } + } + + void SDMemory::deactivateDialogPane(const char* paneName) { + layout::Animator* animator = NULL; + s32 paneIndex = getDialogPaneIndex(paneName); + if (static_cast(mPanelAnimationStates[paneIndex]) == 1) { + switch (paneIndex) { + case 2: + animator = mpDialogLayout->getAnim(3); + break; + case 3: + animator = mpDialogLayout->getAnim(6); + break; + case 0: + animator = mpDialogLayout->getAnim(12); + break; + case 1: + animator = mpDialogLayout->getAnim(9); + break; + } + + if (animator != NULL) { + animator->initAnmFrame(); + animator->setAnmType(ANIM_TYPE_FORWARD); + animator->initFrame(); + animator->restart(); + if (static_cast(mPanelAnimationStates[paneIndex]) > 0) { + --mPanelAnimationStates[paneIndex]; + } + } + } + } + + void SDMemory::selectDialogPane(const char* paneName) { + layout::Animator* animator = NULL; + s32 paneIndex = getDialogPaneIndex(paneName); + if (static_cast(mPanelAnimationStates[paneIndex]) > 0) { + switch (paneIndex) { + case 2: + if (!mScroller.is_busy()) { + animator = mpDialogLayout->getAnim(4); + } + break; + case 3: + if (!mScroller.is_busy()) { + animator = mpDialogLayout->getAnim(7); + } + break; + case 0: + if (!mScroller.is_busy()) { + animator = mpDialogLayout->getAnim(13); + mScroller.setState(3); + } + break; + case 1: + if (!mScroller.is_busy()) { + animator = mpDialogLayout->getAnim(10); + mScroller.setState(4); + } + break; + } + + if (animator != NULL) { + mProcessState = paneIndex; + if (static_cast(paneIndex - 2) <= 1) { + mDialogState = 11; + } + animator->initAnmFrame(); + animator->setAnmType(ANIM_TYPE_FORWARD); + animator->initFrame(); + animator->restart(); + if (paneIndex == 2) { + snd::getSystem()->startSE("WIPL_SE_CANCEL"); + } else if (paneIndex == 3) { + snd::getSystem()->startSE("WIPL_SE_DECIDE"); + } + } + } + } + + void SDMemory::DialogPaneEventHandler::onEvent(u32 compId, u32 event, void* data) { + GuiPaneComponent* component = static_cast(mpManager->getComponent(compId)); + const char* paneName = component->getPane()->GetName(); + s32 eventType = static_cast(event); + switch (eventType) { + case ON_POINT: + mpInstance->activateDialogPane(paneName, static_cast(data)); + break; + case ON_LEFT: + mpInstance->deactivateDialogPane(paneName); + break; + case ON_TRIG: + if (static_cast(data)->downTrg(controller::BTN_INTERACT)) { + mpInstance->selectDialogPane(paneName); + } + break; + } + } + void writeFourFlagBytes(u8* flags, u8 first, u8 second, u8 third, u8 fourth) { flags[0] = first; flags[1] = second; flags[2] = third; flags[3] = fourth; } + + void setTitleRowColors(nw4r::lyt::TextBox* textBox, const nw4r::ut::Color& first, + const nw4r::ut::Color& second) { + textBox->SetTextColors(first, second); + } } } -- 2.49.1 From db27a09ea3a656ddec185958ed10e286fef1d4b4 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 29 Sep 2026 04:39:51 -0500 Subject: [PATCH 10/18] iplSDMemory: 49/66 functions (worker ba5a48eb) (#261) --- src/scene/sdChannelMemory/iplSDMemory.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/scene/sdChannelMemory/iplSDMemory.cpp b/src/scene/sdChannelMemory/iplSDMemory.cpp index 40847d82..36d5c93d 100644 --- a/src/scene/sdChannelMemory/iplSDMemory.cpp +++ b/src/scene/sdChannelMemory/iplSDMemory.cpp @@ -1140,13 +1140,15 @@ namespace ipl { } if (System::getDialog()->getLastResult() != -1) { - if (mErrorCode == 0) { + switch (mErrorCode) { + case 0: mTransferFlags[0] = 1; mDialogState = 25; return true; + default: + mDialogState = 23; + break; } - - mDialogState = 23; } return false; -- 2.49.1 From 44f42d98ed097a0c3ccf0a6c071106b9cd288dae Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 29 Sep 2026 04:57:07 -0500 Subject: [PATCH 11/18] pf_volume: 7/37 functions (worker 5930b324) (#262) --- libs/RVL_SDK/src/fa/pf_volume.c | 37 +++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/libs/RVL_SDK/src/fa/pf_volume.c b/libs/RVL_SDK/src/fa/pf_volume.c index bdf290fe..87af2a9f 100644 --- a/libs/RVL_SDK/src/fa/pf_volume.c +++ b/libs/RVL_SDK/src/fa/pf_volume.c @@ -786,6 +786,7 @@ s32 PFVOL_CheckForWrite(PFVOL_VOLUME* volume) { s32 PFVOL_CheckCurrentDir(PFVOL_VOLUME* volume, u32 start_cluster) { s32 context_id; u32 current_dir_index; + s32 result = 0; if ((volume->flags & 8) == 0) { return 9; @@ -801,9 +802,9 @@ s32 PFVOL_CheckCurrentDir(PFVOL_VOLUME* volume, u32 start_cluster) { current_dir_index = 0; } if (start_cluster == volume->current_dir[current_dir_index].directory.start_cluster) { - return -1; + result = -1; } - return 0; + return result; } s32 PFVOL_SetCurrentDir(PFVOL_VOLUME* volume, PFVOL_DIR_ENTRY* directory) { @@ -824,13 +825,15 @@ s32 PFVOL_SetCurrentDir(PFVOL_VOLUME* volume, PFVOL_DIR_ENTRY* directory) { } } if (current_dir_index == 4) { - for (context_index = 0; context_index < 3; context_index++) { - pf_vol_set.context[context_index].stat &= 1; - if (pf_vol_set.context[context_index].stat != 0 && - pf_vol_set.context[context_index].context_id == context_id) { - context_registered = 1; - break; - } + if (((pf_vol_set.context[0].stat &= 1) != 0 && + context_id == pf_vol_set.context[0].context_id) || + ((pf_vol_set.context[1].stat &= 1) != 0 && + context_id == pf_vol_set.context[1].context_id) || + ((pf_vol_set.context[2].stat &= 1) != 0 && + context_id == pf_vol_set.context[2].context_id)) { + context_registered = 1; + } else { + context_registered = 0; } if (context_registered != 0) { for (current_dir_index = 1; current_dir_index < 4; current_dir_index++) { @@ -865,13 +868,15 @@ s32 PFVOL_GetCurrentDir(PFVOL_VOLUME* volume, PFVOL_DIR_ENTRY* directory) { } } if (current_dir_index == 4) { - for (context_index = 0; context_index < 3; context_index++) { - pf_vol_set.context[context_index].stat &= 1; - if (pf_vol_set.context[context_index].stat != 0 && - pf_vol_set.context[context_index].context_id == context_id) { - context_registered = 1; - break; - } + if (((pf_vol_set.context[0].stat &= 1) != 0 && + context_id == pf_vol_set.context[0].context_id) || + ((pf_vol_set.context[1].stat &= 1) != 0 && + context_id == pf_vol_set.context[1].context_id) || + ((pf_vol_set.context[2].stat &= 1) != 0 && + context_id == pf_vol_set.context[2].context_id)) { + context_registered = 1; + } else { + context_registered = 0; } if (context_registered != 0) { for (current_dir_index = 1; current_dir_index < 4; current_dir_index++) { -- 2.49.1 From 4402bd99a8b0361e1d49082a80f941f5db63ace5 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 29 Sep 2026 05:38:18 -0500 Subject: [PATCH 12/18] pf_file: 31/45 functions (worker 44d9c236) (#263) --- libs/RVL_SDK/src/fa/pf_file.c | 163 +++++++++++++++++++--------------- 1 file changed, 89 insertions(+), 74 deletions(-) diff --git a/libs/RVL_SDK/src/fa/pf_file.c b/libs/RVL_SDK/src/fa/pf_file.c index 2bf6dce0..b3f2de4c 100644 --- a/libs/RVL_SDK/src/fa/pf_file.c +++ b/libs/RVL_SDK/src/fa/pf_file.c @@ -390,12 +390,12 @@ pf_s32 PFFILE_Cursor_Read(PFFILE_FILE* file, pf_u8* buffer, pf_u32 size, pf_u32* if (error != 0) { return error; } - if (size <= part_size) { + if (part_size >= size) { return 0; } size -= part_size; volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; - while (volume->bpb.bytes_per_sector <= size) { + while (size >= volume->bpb.bytes_per_sector) { error = PFFILE_Cursor_ReadBodySectors(file, buffer + *size_read, size, &part_size); *size_read += part_size; if (error != 0) { @@ -408,10 +408,10 @@ pf_s32 PFFILE_Cursor_Read(PFFILE_FILE* file, pf_u8* buffer, pf_u32 size, pf_u32* } error = PFFILE_Cursor_ReadTailSector(file, buffer + *size_read, size, &part_size); *size_read += part_size; - if (error == 0) { - error = 0; + if (error != 0) { + return error; } - return error; + return 0; } pf_s32 PFFILE_Cursor_WriteHeadSector(PFFILE_FILE* file, const pf_u8* buffer, pf_u32 size, @@ -419,6 +419,8 @@ pf_s32 PFFILE_Cursor_WriteHeadSector(PFFILE_FILE* file, const pf_u8* buffer, pf_ pf_s32 error; pf_u32 success_size; pf_u32 next_position; + pf_u32 current_sector; + pf_u32 written_size; PF_VOLUME* volume; *size_written = 0; @@ -447,10 +449,13 @@ pf_s32 PFFILE_Cursor_WriteHeadSector(PFFILE_FILE* file, const pf_u8* buffer, pf_ return error; } *size_written = success_size; + current_sector = file->cursor.sector; + written_size = success_size; volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; - next_position = file->cursor.offset_in_sector + success_size; + next_position = file->cursor.offset_in_sector + written_size; if (((volume->bpb.bytes_per_sector - 1) & next_position) != 0) { - file->cursor.sector += next_position >> volume->bpb.log2_bytes_per_sector; + file->cursor.sector = current_sector + + (next_position >> volume->bpb.log2_bytes_per_sector); } else { file->cursor.sector = -1; } @@ -519,6 +524,8 @@ pf_s32 PFFILE_Cursor_WriteTailSector(PFFILE_FILE* file, const pf_u8* buffer, pf_ pf_s32 error; pf_u32 success_size; pf_u32 next_position; + pf_u32 current_sector; + pf_u32 written_size; PF_VOLUME* volume; *size_written = 0; @@ -548,10 +555,13 @@ pf_s32 PFFILE_Cursor_WriteTailSector(PFFILE_FILE* file, const pf_u8* buffer, pf_ return error; } *size_written = success_size; + current_sector = file->cursor.sector; + written_size = success_size; volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; - next_position = file->cursor.offset_in_sector + success_size; + next_position = file->cursor.offset_in_sector + written_size; if (((volume->bpb.bytes_per_sector - 1) & next_position) != 0) { - file->cursor.sector += next_position >> volume->bpb.log2_bytes_per_sector; + file->cursor.sector = current_sector + + (next_position >> volume->bpb.log2_bytes_per_sector); } else { file->cursor.sector = -1; } @@ -576,7 +586,6 @@ pf_s32 PFFILE_Cursor_Write(PFFILE_FILE* file, const pf_u8* buffer, pf_u32 size, pf_u32 append_needed; pf_u32 allocated_end; pf_u32 requested_end; - pf_u32 remaining; PF_VOLUME* volume; PFFILE_VOLUME_DIRS* volume_dirs; @@ -598,9 +607,9 @@ pf_s32 PFFILE_Cursor_Write(PFFILE_FILE* file, const pf_u8* buffer, pf_u32 size, if (part_size >= size) { return 0; } - remaining = size - part_size; + size -= part_size; error = PFFAT_CountAllocatedClusters(&file->p_sfd->ffd, - file->cursor.position + remaining, &num_clusters); + file->cursor.position + size, &num_clusters); if (file == PF_NULL) { volume = PF_NULL; } else { @@ -608,17 +617,17 @@ pf_s32 PFFILE_Cursor_Write(PFFILE_FILE* file, const pf_u8* buffer, pf_u32 size, } allocated_end = num_clusters << (volume->bpb.log2_bytes_per_sector + volume->bpb.log2_sectors_per_cluster); - requested_end = file->cursor.position + remaining; + requested_end = file->cursor.position + size; if (allocated_end < requested_end) { append_needed = requested_end - allocated_end; } else { append_needed = 0; } append_size = 0; - while (append_needed != 0 || remaining >= volume->bpb.bytes_per_sector) { + while (append_needed != 0 || size >= volume->bpb.bytes_per_sector) { if (append_needed != 0) { error = PFCLUSTER_AppendCluster(file, append_needed, &append_size); - if (error != 0 && remaining == append_needed) { + if (error != 0 && size == append_needed) { return error; } if (append_size == 0) { @@ -626,9 +635,9 @@ pf_s32 PFFILE_Cursor_Write(PFFILE_FILE* file, const pf_u8* buffer, pf_u32 size, } append_needed -= append_size; } - while (remaining >= append_needed + append_size && - remaining >= volume->bpb.bytes_per_sector) { - error = PFFILE_Cursor_WriteBodySectors(file, buffer + *size_written, remaining, + while (size >= append_needed + append_size && + size >= volume->bpb.bytes_per_sector) { + error = PFFILE_Cursor_WriteBodySectors(file, buffer + *size_written, size, &part_size); *size_written += part_size; if (error != 0) { @@ -637,13 +646,13 @@ pf_s32 PFFILE_Cursor_Write(PFFILE_FILE* file, const pf_u8* buffer, pf_u32 size, if (part_size == 0) { return 0; } - remaining -= part_size; - if (remaining == 0) { + size -= part_size; + if (size == 0) { break; } } } - error = PFFILE_Cursor_WriteTailSector(file, buffer + *size_written, remaining, &part_size); + error = PFFILE_Cursor_WriteTailSector(file, buffer + *size_written, size, &part_size); *size_written += part_size; error = error & ((-error | error) >> 31); return error; @@ -1072,7 +1081,6 @@ pf_s32 PFFILE_p_finfo(PFFILE_FILE* file, PF_INFO* info) { pf_u32 cluster_size; pf_u32 file_size_remainder; pf_u32 file_size; - pf_u32 nonempty_bytes; pf_s32 sign_bits; pf_s32 error; @@ -1088,9 +1096,9 @@ pf_s32 PFFILE_p_finfo(PFFILE_FILE* file, PF_INFO* info) { } file_size = file->p_sfd->dir_entry.file_size; file_size_remainder = file_size % cluster_size; - nonempty_bytes = cluster_size - file_size_remainder; sign_bits = -(pf_s32)file_size_remainder | (pf_s32)file_size_remainder; - info->empty_size = info->allocated_size + (nonempty_bytes & (sign_bits >> 31)); + info->empty_size = info->allocated_size + + ((sign_bits >> 31) & (cluster_size - file_size_remainder)); } else { info->allocated_size = 0; info->empty_size = 0; @@ -1485,18 +1493,19 @@ pf_s32 PFFILE_FsexecOpenFile(PF_DIR_ENT* entry, PFFILE_ENT_ITER* iter, file->p_sfd = sfd; file->stat = 1; file->open_mode = mode; + file->last_access_data.state.last_error = 0; file->lock_count = 0; PFFAT_InitHint(&file->hint); file->cursor.sector = 0xFFFFFFFF; - file->last_access_data.state.last_error = 0; file->cursor.position = 0; PFFILE_Cursor_Recalc(file); if ((mode & 1) != 0) { - sfd->stat |= 4; + file->p_sfd->stat |= 4; } - if ((mode & 4) != 0) { + if ((file->open_mode & 4) != 0) { PFFILE_Cursor_MoveToEnd(file); } + sfd->handler_count++; data->p_file = (PF_FILE*)file; return 0; } @@ -1600,12 +1609,13 @@ pf_s32 PFFILE_fopen(PF_STR* path, pf_s32 mode, PFFILE_FILE** result) { } pf_s32 PFFILE_fclose(PFFILE_FILE* file) { + pf_s32 close_error = 0; PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; PFFILE_VOLUME_DIRS* volume_dirs; pf_s32 error; error = PFVOL_CheckForWrite(volume); - if (error != 0 && (error != 0x0B || file->open_mode != 2)) { + if (error != 0 && (error != 0x0B || (pf_s32)file->open_mode != 2)) { pf_vol_set.last_error = error; ((PFFILE_VOLUME_DIRS*)volume)->last_error = error; return error; @@ -1617,12 +1627,11 @@ pf_s32 PFFILE_fclose(PFFILE_FILE* file) { return 10; } volume_dirs->cache_signature = file; - if (file->p_sfd->handler_count <= 1 && (file->p_sfd->dir_entry.attr & 0x19) == 0 && - PFVOL_CheckForWrite(volume) == 0 && + if (((pf_s32)file->p_sfd->handler_count - 1) <= 0 && + (file->p_sfd->dir_entry.attr & 0x19) == 0 && + (error & 0x0B) == 0 && ((file->p_sfd->stat & 4) != 0 || (volume_dirs->file_config & 1) != 1)) { - error = PFENT_updateEntry(&file->p_sfd->dir_entry, 1); - } else { - error = 0; + close_error = PFENT_updateEntry(&file->p_sfd->dir_entry, 1); } if (file->lock_count != 0) { if ((file->p_sfd->lock.mode & 1) != 0) { @@ -1633,7 +1642,7 @@ pf_s32 PFFILE_fclose(PFFILE_FILE* file) { } file->p_sfd->lock.mode &= ~3; } else if (file->p_sfd->lock.owner != (PF_FILE*)file) { - error = 0x19; + close_error = 0x19; } else { file->p_sfd->lock.count = 0; file->lock_count = 0; @@ -1642,36 +1651,38 @@ pf_s32 PFFILE_fclose(PFFILE_FILE* file) { file->p_sfd->lock.mode &= ~3; } } - if (error != 0) { - pf_vol_set.last_error = error; - ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = error; - file->last_access_data.state.last_error = error; - } else if ((volume_dirs->cache_control & 2) != 0) { - error = PFCACHE_FlushFATCache(volume); - if (error != 0) { - pf_vol_set.last_error = error; - ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = error; - file->last_access_data.state.last_error = error; + if (close_error != 0) { + pf_vol_set.last_error = close_error; + ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = close_error; + file->last_access_data.state.last_error = close_error; + goto close_file_complete; + } + if ((volume_dirs->cache_control & 2) != 0) { + close_error = PFCACHE_FlushFATCache(volume); + if (close_error != 0) { + pf_vol_set.last_error = close_error; + ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = close_error; + file->last_access_data.state.last_error = close_error; } else { - error = PFCACHE_FlushDataCacheSpecific(volume, file); - if (error != 0) { - pf_vol_set.last_error = error; - ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = error; - file->last_access_data.state.last_error = error; + close_error = PFCACHE_FlushDataCacheSpecific(volume, file); + if (close_error != 0) { + pf_vol_set.last_error = close_error; + ((PFFILE_VOLUME_DIRS*)file->p_sfd->ffd.p_vol)->last_error = close_error; + file->last_access_data.state.last_error = close_error; } } } - if (error == 0) { - file->p_sfd->handler_count--; - if (file->p_sfd->handler_count == 0) { + if (close_error == 0) { + if (--file->p_sfd->handler_count == 0) { file->p_sfd->stat &= ~1U; file->p_sfd->ffd.cluster_link.buffer = PF_NULL; } file->stat &= ~1U; volume_dirs->num_opened_files--; } +close_file_complete: volume_dirs->cache_signature = PF_NULL; - return error; + return close_error; } pf_s32 PFFILE_fread(pf_u8* buffer, pf_u32 size, pf_u32 count, @@ -1704,11 +1715,12 @@ pf_s32 PFFILE_fread(pf_u8* buffer, pf_u32 size, pf_u32 count, pf_s32 PFFILE_fwrite(const pf_u8* buffer, pf_u32 size, pf_u32 count, PFFILE_FILE* file, pf_u32* count_written) { - PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; + PF_VOLUME* volume; pf_u32 bytes_written; pf_s32 error; *count_written = 0; + volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; error = PFVOL_CheckForWrite(volume); if (error != 0) { pf_vol_set.last_error = error; @@ -1753,10 +1765,10 @@ pf_s32 PFFILE_feof(PFFILE_FILE* file) { ((PFFILE_VOLUME_DIRS*)volume)->last_error = 0x26; return 0x26; } - if (file->cursor.position < file->p_sfd->dir_entry.file_size) { - return 0; + if (file->cursor.position >= file->p_sfd->dir_entry.file_size) { + error = 1; } - return 1; + return error; } pf_s32 PFFILE_fseek(PFFILE_FILE* file, pf_s32 offset, pf_s32 origin) { @@ -1841,10 +1853,9 @@ pf_s32 PFFILE_fsetclstlink(PFFILE_FILE* file, pf_u32 mode, file->p_sfd->ffd.cluster_link.position++; } if (file->p_sfd->ffd.p_hint != PF_NULL) { - PFFILE_FAT_HINT* hint = (PFFILE_FAT_HINT*)file->p_sfd->ffd.p_hint; - hint->chain_index = 0; - hint->cluster = 0; - hint->previous_cluster = 0; + ((PFFILE_FAT_HINT*)file->p_sfd->ffd.p_hint)->chain_index = 0; + ((PFFILE_FAT_HINT*)file->p_sfd->ffd.p_hint)->cluster = 0; + ((PFFILE_FAT_HINT*)file->p_sfd->ffd.p_hint)->previous_cluster = 0; } file->p_sfd->ffd.last_cluster.num_last_cluster = 0; file->p_sfd->ffd.last_cluster.max_chain_index = 0; @@ -1933,8 +1944,10 @@ pf_s32 PFFILE_fappend(PFFILE_FILE* file, pf_u32 size, pf_u32* size_appended) { pf_s32 PFFILE_fadjust(PFFILE_FILE* file) { PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; PFFILE_CURSOR saved_cursor; - PF_FAT_HINT saved_hint; - pf_u32 saved_last_access_chain_index; + struct { + PF_FAT_HINT hint; + pf_u32 last_access_chain_index; + } saved_hint; pf_u16 access_time; pf_s32 error; @@ -1952,9 +1965,9 @@ pf_s32 PFFILE_fadjust(PFFILE_FILE* file) { } ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = file; saved_cursor = file->cursor; - saved_hint = file->hint; - saved_last_access_chain_index = file->last_access_data.last_access.chain_index; - if ((file->open_mode & 8) == 0 && (file->open_mode & 4) != 0) { + saved_hint.hint = file->hint; + saved_hint.last_access_chain_index = file->last_access_data.last_access.chain_index; + if ((file->open_mode & 8) == 0 && (file->open_mode & 2) != 0) { error = 0x0A; } else if ((file->p_sfd->lock.mode & 3) != 0 && ((file->p_sfd->lock.mode & 1) != 0 || @@ -1965,8 +1978,8 @@ pf_s32 PFFILE_fadjust(PFFILE_FILE* file) { error &= (-error | error) >> 31; } file->cursor = saved_cursor; - file->hint = saved_hint; - file->last_access_data.last_access.chain_index = saved_last_access_chain_index; + file->hint = saved_hint.hint; + file->last_access_data.last_access.chain_index = saved_hint.last_access_chain_index; ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = PF_NULL; if (error != 0) { pf_vol_set.last_error = error; @@ -1981,8 +1994,10 @@ pf_s32 PFFILE_fadjust(PFFILE_FILE* file) { pf_s32 PFFILE_finfo(PFFILE_FILE* file, PF_INFO* info) { PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; PFFILE_CURSOR saved_cursor; - PF_FAT_HINT saved_hint; - pf_u32 saved_last_access_chain_index; + struct { + PF_FAT_HINT hint; + pf_u32 last_access_chain_index; + } saved_hint; pf_s32 error; error = PFVOL_CheckForRead(volume); @@ -1999,12 +2014,12 @@ pf_s32 PFFILE_finfo(PFFILE_FILE* file, PF_INFO* info) { } ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = file; saved_cursor = file->cursor; - saved_hint = file->hint; - saved_last_access_chain_index = file->last_access_data.last_access.chain_index; + saved_hint.hint = file->hint; + saved_hint.last_access_chain_index = file->last_access_data.last_access.chain_index; error = PFFILE_p_finfo(file, info); file->cursor = saved_cursor; - file->hint = saved_hint; - file->last_access_data.last_access.chain_index = saved_last_access_chain_index; + file->hint = saved_hint.hint; + file->last_access_data.last_access.chain_index = saved_hint.last_access_chain_index; ((PFFILE_VOLUME_DIRS*)volume)->cache_signature = PF_NULL; if (error != 0) { pf_vol_set.last_error = error; -- 2.49.1 From 2a4e4f85edbc7ac8f639d2a2fac8871c0141f763 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 29 Sep 2026 05:57:26 -0500 Subject: [PATCH 13/18] iplSetting: 88/112 functions (worker 77873dae) (#264) --- include/iplwww/www_browser.h | 11 ++ src/scene/setting/iplSetting.cpp | 223 ++++++++++++++++++------------- 2 files changed, 143 insertions(+), 91 deletions(-) diff --git a/include/iplwww/www_browser.h b/include/iplwww/www_browser.h index dae02741..c0abfb74 100644 --- a/include/iplwww/www_browser.h +++ b/include/iplwww/www_browser.h @@ -122,6 +122,14 @@ extern WWWProtocolFinalizeFn WWWProtocolFinished; extern WWWProtocolFinalizeFn WWWProtocolFailed; extern WWWAddProtocolFn WWWAddProtocol; +#ifdef IPL_SETTING_IMPLEMENTATION +namespace ipl { + namespace scene { + class Setting; + } +} +#endif + namespace www { namespace arcreader { class ArcContainer; @@ -206,6 +214,9 @@ namespace ext_ead { WWWHandle* GetHandle() { return mpBrowserHandle; } private: +#ifdef IPL_SETTING_IMPLEMENTATION + friend class ::ipl::scene::Setting; +#endif static BOOL SNotifyCallback_(WWWHandle* wwwBrowser, WWWHandlewindow* wwwWindow, WWWEvent event, WWWHandleEventData* eventData); BOOL NotifyCallback_(WWWHandle* wwwBrowser, WWWHandlewindow* wwwWindow, WWWEvent event, WWWHandleEventData* eventData); diff --git a/src/scene/setting/iplSetting.cpp b/src/scene/setting/iplSetting.cpp index 6d84318f..ed0dc58b 100644 --- a/src/scene/setting/iplSetting.cpp +++ b/src/scene/setting/iplSetting.cpp @@ -15,6 +15,7 @@ #include "iplwww/www_wiisetting.h" #include "iplwww/www_surface.h" +#include "iplwww/www_window.h" #include "iplwww/www_trasition.h" #include @@ -31,6 +32,12 @@ extern "C" void __VISetAdjustingValues(s32 horizontal, s32 vertical); +namespace ipl { + namespace scene { + static s32 browserScrollDirection; + } +} + namespace ipl { class SensitivityDrawing { public: @@ -137,7 +144,7 @@ namespace ipl { "G_Lock1", "G_Lock2", "G_Lock3", "G_Lock4", "G_Lock5", "G_Lock6", }; - const char* sSettingAPAnimations[] = { + const char* sSettingAPAnimations[19] = { "my_AP_a_ArwAppear.brlan", "my_AP_a_ArwLost.brlan", "my_AP_a_ArwFocusOn.brlan", "my_AP_a_ArwFocusOff.brlan", "my_AP_a_ArwSelect.brlan", "my_AP_a_ScrollUp.brlan", "my_AP_a_ScrollDown.brlan", "my_AP_a_BtnFocusOn.brlan", "my_AP_a_BtnFocusOff.brlan", @@ -656,7 +663,8 @@ namespace ipl { bool Setting::updateScreenMode() { if (unk_0x91C[2] != 0) { - if (unk_0xB94 == 0) { + switch (unk_0xB94) { + case 0: if (mEuRgb60Mode != SCGetEuRgb60Mode()) { unk_0xB94 = 3; } else if (mProgressiveMode != SCGetProgressiveMode()) { @@ -668,6 +676,9 @@ namespace ipl { mState = 0; return true; } + break; + default: + goto screenModeDispatch; } } else if (unk_0xB94 == 1 && unk_0x74 == 8) { System::getFader()->fadeOut(); @@ -677,6 +688,7 @@ namespace ipl { return true; } + screenModeDispatch: switch (unk_0xB94) { case 1: if (System::getFader()->getStatus() == EGG::Fader::PREPARE_IN) { @@ -1261,63 +1273,67 @@ namespace ipl { FaderSceneCommand Setting::calcFadeout() { if (System::getFader()->getStatus() == EGG::Fader::PREPARE_IN) { - if (unk_0x5C == 0) { + const u8 surfaceState = unk_0x5C; + if (surfaceState == 0) { unk_0x5C = 1; ext_ead::www::SurfaceManager::GetInstance()->StopThreadAsync(); OSReport("!!!!!!!!!!!!! SCFlush !!!!!!!!!!!!!!\n"); SCFlush(); - } else if (unk_0x7C == 5) { - if (mInitialArgument == 2 || mInitialArgument == 5) { - SCSetConfigDoneFlag(TRUE); - SCSetConfigDoneFlag2(TRUE); - SCSetUpdateType(0); - SCFlush(); } + if (surfaceState != 0) { + if (unk_0x7C == 5) { + if (mInitialArgument == 2 || mInitialArgument == 5) { + SCSetConfigDoneFlag(TRUE); + SCSetConfigDoneFlag2(TRUE); + SCSetUpdateType(0); + SCFlush(); + } - while (WPADGetStatus() != 0 || - System::getBS2Manager()->getIPLState() != bs2::IPL_STATE_8) { - snd::getSystem()->calc(); - System::getBS2Manager()->update(); + while (WPADGetStatus() != 0 || + System::getBS2Manager()->getIPLState() != bs2::IPL_STATE_8) { + snd::getSystem()->calc(); + System::getBS2Manager()->update(); + VIWaitForRetrace(); + if (WPADGetStatus() != 0) { + OSReport("wait for WPAD\n"); + } + if (System::getBS2Manager()->getIPLState() != bs2::IPL_STATE_8) { + OSReport("wait for BS2\n"); + } + } + + VISetBlack(TRUE); + VIFlush(); VIWaitForRetrace(); - if (WPADGetStatus() != 0) { - OSReport("wait for WPAD\n"); + OSReport("VI Black\n"); + while (!__OSSyncSram()) { + OSReport("sync sram\n"); } - if (System::getBS2Manager()->getIPLState() != bs2::IPL_STATE_8) { - OSReport("wait for BS2\n"); + while (!System::isReceiveScheduleStopped()) { + OSReport("Wait ScheduleStopped\n"); + OSSleepMilliseconds(5); } + __OSLaunchTitlelForSystem(mUpdateTitleId, 0, NULL); + for (;;) { + OSReport(NULL); + } + } else if (ext_ead::www::SurfaceManager::GetInstance()->IsThreadStopped()) { + OSReport("reserve destroy\n"); + ext_ead::www::SurfaceManager::DisposeManager(); + OSReport("reserve destroy done\n"); + if (mInitialArgument == 2 || mInitialArgument == 5) { + SCSetConfigDoneFlag(TRUE); + SCSetConfigDoneFlag2(TRUE); + SCSetUpdateType(0); + SCFlush(); + reserveAllSceneDestruction(0x1a, NULL); + } else { + System::reloadDownloadTask(); + reserveAllSceneDestruction(0x15, NULL); + } + delete mpBrowserData; + return FADER_SCN_NEXT; } - - VISetBlack(TRUE); - VIFlush(); - VIWaitForRetrace(); - OSReport("VI Black\n"); - while (!__OSSyncSram()) { - OSReport("sync sram\n"); - } - while (!System::isReceiveScheduleStopped()) { - OSReport("Wait ScheduleStopped\n"); - OSSleepMilliseconds(5); - } - __OSLaunchTitlelForSystem(mUpdateTitleId, 0, NULL); - for (;;) { - OSReport(NULL); - } - } else if (ext_ead::www::SurfaceManager::GetInstance()->IsThreadStopped()) { - OSReport("reserve destroy\n"); - ext_ead::www::SurfaceManager::DisposeManager(); - OSReport("reserve destroy done\n"); - if (mInitialArgument == 2 || mInitialArgument == 5) { - SCSetConfigDoneFlag(TRUE); - SCSetConfigDoneFlag2(TRUE); - SCSetUpdateType(0); - SCFlush(); - reserveAllSceneDestruction(0x1a, NULL); - } else { - System::reloadDownloadTask(); - reserveAllSceneDestruction(0x15, NULL); - } - delete mpBrowserData; - return FADER_SCN_NEXT; } } @@ -1347,6 +1363,27 @@ namespace ipl { return; } + ext_ead::www::BrowserWindow* browserWindow = + static_cast(browser->mpBrowserWindows[0]); + if (browserWindow != NULL && browserWindow->unk_0x2C4[3] != 0) { + unk_0x91C[2] = 1; + mState = 0; + browserWindow->unk_0x2C4[3] = 0; + www::trasition::ScrollState scrollState = www::trasition::GetScrollState(); + browserScrollDirection = scrollState == www::trasition::SCROLL_LEFT + ? 1 + : (scrollState == www::trasition::SCROLL_RIGHT ? -1 : 0); + www::trasition::ResetScrollState(); + void* changedWideBuffer = browser->GetTextureBuffer(1, NULL); + void* changedStandardBuffer = browser->GetTextureBuffer(0, NULL); + OSReport("changed %p %p\n", changedStandardBuffer, changedWideBuffer); + ext_ead::www::Heap::reportLeaHeap(); + } + + bool showBrowserWindow = + mpSecondAnimation->state == 1 || mpFirstAnimation->state == 1; + mpChangeLayout->FindPaneByName("hoge")->SetVisible(showBrowserWindow); + WWWRect* wideRect = NULL; WWWRect* standardRect = NULL; void* wideBuffer = browser->GetTextureBuffer(1, &wideRect); @@ -1355,12 +1392,6 @@ namespace ipl { return; } - if (www::trasition::GetScrollState() != www::trasition::SCROLL_RESET) { - www::trasition::ResetScrollState(); - OSReport("changed %p %p\n", standardBuffer, wideBuffer); - ext_ead::www::Heap::reportLeaHeap(); - } - nw4r::ut::Rect projection4x3; nw4r::ut::Rect projection16x9; System::getProjectionRect4x3(&projection4x3); @@ -1373,6 +1404,10 @@ namespace ipl { GXInitTexObjLOD(&standardTexture, GX_LINEAR, GX_LINEAR, 0.0f, 0.0f, 0.0f, GX_FALSE, GX_FALSE, GX_ANISO_1); GXInitTexObjLOD(&wideTexture, GX_LINEAR, GX_LINEAR, 0.0f, 0.0f, 0.0f, GX_FALSE, GX_FALSE, GX_ANISO_1); + if (browserScrollDirection != 0) { + mpChangeLayout->FindPaneByName("hoge")->SetVisible(true); + } + utility::Graphics::setOrtho(0); GXColor color = {0xFF, 0xFF, 0xFF, (u8)(mState * 0xFF / 20)}; utility::Graphics::drawTexture(projection4x3, standardTexture, color, 1); @@ -1914,20 +1949,24 @@ namespace ipl { memset(mpStringBuffer->securityKey, 0, sizeof(mpStringBuffer->securityKey)); s32 privacyMode = ncd::NCDSetting::getNCDPrivacyMode(); size_t keyLength; - if (privacyMode != 2) { - if (privacyMode < 2) { - if (privacyMode == 0) { - keyLength = 0; - } else { - keyLength = 5; - } - } else if (privacyMode < 7 && privacyMode > 3) { - keyLength = 64; - } else { - keyLength = 0; - } - } else { + switch (privacyMode) { + case 0: + keyLength = 0; + break; + case 1: + keyLength = 5; + break; + case 2: keyLength = 13; + break; + case 4: + case 5: + case 6: + keyLength = 64; + break; + default: + keyLength = 0; + break; } if (keyLength != 0) { memcpy(mpStringBuffer->securityKey, ncd::NCDSetting::getPrivacy(), keyLength); @@ -2288,17 +2327,16 @@ namespace ipl { int count = 0; memset(ascii, 0, sizeof(ascii)); utility::CharacterCode::UTF8ToANSI(reinterpret_cast(ascii), address); - char* converted = ascii; int componentStart = 0; u8* output = destination; for (int index = 0; index < 0x10; ++index) { - u8 character = static_cast(converted[index]); + u8 character = static_cast(ascii[index]); if (character == '.' || character == 0) { if (character == 0) { index = 0x10; } - converted[index] = 0; - u32 value = atoi(converted + componentStart); + ascii[index] = 0; + u32 value = atoi(ascii + componentStart); if (value > 0xff) { value = 0xff; } @@ -2313,7 +2351,7 @@ namespace ipl { ++count; ++output; if (count == 3 && index != 0x10) { - value = atoi(converted + componentStart); + value = atoi(ascii + componentStart); if (value > 0xff) { value = 0xff; } @@ -2811,16 +2849,15 @@ namespace ipl { if (accessPoint != -1) { int index = 0; while (index <= mAPScanList.count) { - WDBssDesc_* descriptor = mAPScanList.currentDescriptor; - int recordLength = descriptor->length * 2; + int recordLength = mAPScanList.currentDescriptor->length * 2; recordOffset += recordLength; if (recordOffset > 0x800) { break; } if (index == accessPoint + unk_0x914 + 1) { - u8 privacyMode = static_cast(WDGetPrivacyMode(descriptor)); + u8 privacyMode = static_cast(WDGetPrivacyMode(mAPScanList.currentDescriptor)); char ssid[0x21]; - memcpy(ssid, descriptor->ssid, 0x20); + memcpy(ssid, mAPScanList.currentDescriptor->ssid, 0x20); ssid[0x20] = 0; memset(mpStringBuffer->securityKey, 0, sizeof(mpStringBuffer->securityKey)); memset(mpStringBuffer->ssid, 0, sizeof(mpStringBuffer->ssid)); @@ -2838,7 +2875,9 @@ namespace ipl { OSReport("SET DATA : %d %s %d\n", index, ssid, privacyMode); break; } - mAPScanList.currentDescriptorWords += recordLength / sizeof(u16); + mAPScanList.currentDescriptor = + reinterpret_cast( + mAPScanList.entries + recordOffset - sizeof(mAPScanList.count)); ++index; } unk_0x91C[2] = 0; @@ -2857,7 +2896,7 @@ namespace ipl { if (unk_0x914 == 1) { mpMainLayout->FindPaneByName("N_AP0")->SetVisible(false); } - } else { + } else if (arrow == 1) { unk_0x91C[0] = 1; if (mAPScanList.count == unk_0x914 + 5) { mpMainLayout->FindPaneByName("N_AP7")->SetVisible(false); @@ -3097,13 +3136,15 @@ namespace ipl { } u16 Setting::getProfileID() { - if (mProfileIDMode < 3) { - return ncd::NCDSetting::getID(); - } - u16 profileID = ncd::NCDSetting::getUseProfileID(); - ncd::NCDSetting::initSetID(profileID & 0xff); - if ((profileID & 0xff) == 3) { - profileID = 0; + u16 profileID; + if (mProfileIDMode >= 3) { + profileID = ncd::NCDSetting::getUseProfileID(); + ncd::NCDSetting::initSetID(static_cast(profileID)); + if (static_cast(profileID) == 3) { + profileID = 0; + } + } else { + profileID = ncd::NCDSetting::getID(); } return profileID; } @@ -3239,7 +3280,7 @@ namespace ipl { } } - static const wchar_t errorFormat[] = L"\n%03d"; + static const wchar_t errorFormat[] = L"%d\n"; void Setting::makeErrorMessage() { const wchar_t* prefix = System::getMessage(400); @@ -3399,7 +3440,7 @@ namespace ipl { unk_0x84 = 1; unk_0x91C[1] = 0; resetFuncMsgQ(); - } + } } void Setting::cancelUSBAP() { @@ -3630,15 +3671,15 @@ namespace ipl { case ::gui::EventHandler::ON_POINT: mpSetting->start_point_event(paneName); break; + case ::gui::EventHandler::ON_LEFT: + mpSetting->start_left_event(paneName); + break; case ::gui::EventHandler::ON_TRIG: controller::Interface* input = static_cast(data); if (input->downTrg(0x100800)) { mpSetting->start_trig_event(paneName); } break; - case ::gui::EventHandler::ON_LEFT: - mpSetting->start_left_event(paneName); - break; default: break; } -- 2.49.1 From 506535db408fd458e2bc0e9eb57efe33c45ac6e2 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 29 Sep 2026 06:13:58 -0500 Subject: [PATCH 14/18] pf_file: 32/45 functions (worker 99e93149) (#265) --- libs/RVL_SDK/src/fa/pf_file.c | 63 +++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/libs/RVL_SDK/src/fa/pf_file.c b/libs/RVL_SDK/src/fa/pf_file.c index b3f2de4c..97857189 100644 --- a/libs/RVL_SDK/src/fa/pf_file.c +++ b/libs/RVL_SDK/src/fa/pf_file.c @@ -419,8 +419,11 @@ pf_s32 PFFILE_Cursor_WriteHeadSector(PFFILE_FILE* file, const pf_u8* buffer, pf_ pf_s32 error; pf_u32 success_size; pf_u32 next_position; + pf_u32 new_position; pf_u32 current_sector; pf_u32 written_size; + pf_u32 sector_advance; + pf_u32 next_sector; PF_VOLUME* volume; *size_written = 0; @@ -453,15 +456,17 @@ pf_s32 PFFILE_Cursor_WriteHeadSector(PFFILE_FILE* file, const pf_u8* buffer, pf_ written_size = success_size; volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; next_position = file->cursor.offset_in_sector + written_size; + sector_advance = next_position >> volume->bpb.log2_bytes_per_sector; + next_sector = current_sector + sector_advance; if (((volume->bpb.bytes_per_sector - 1) & next_position) != 0) { - file->cursor.sector = current_sector + - (next_position >> volume->bpb.log2_bytes_per_sector); + file->cursor.sector = next_sector; } else { file->cursor.sector = -1; } - file->cursor.position += success_size; - if (file->cursor.position > file->p_sfd->dir_entry.file_size) { - file->p_sfd->dir_entry.file_size = file->cursor.position; + new_position = file->cursor.position + success_size; + file->cursor.position = new_position; + if (new_position > file->p_sfd->dir_entry.file_size) { + file->p_sfd->dir_entry.file_size = new_position; } PFFILE_Cursor_Recalc(file); PFCLUSTER_UpdateLastAccessCluster(file); @@ -526,6 +531,9 @@ pf_s32 PFFILE_Cursor_WriteTailSector(PFFILE_FILE* file, const pf_u8* buffer, pf_ pf_u32 next_position; pf_u32 current_sector; pf_u32 written_size; + pf_u32 sector_advance; + pf_u32 next_sector; + pf_u32 new_position; PF_VOLUME* volume; *size_written = 0; @@ -559,15 +567,17 @@ pf_s32 PFFILE_Cursor_WriteTailSector(PFFILE_FILE* file, const pf_u8* buffer, pf_ written_size = success_size; volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol; next_position = file->cursor.offset_in_sector + written_size; + sector_advance = next_position >> volume->bpb.log2_bytes_per_sector; + next_sector = current_sector + sector_advance; if (((volume->bpb.bytes_per_sector - 1) & next_position) != 0) { - file->cursor.sector = current_sector + - (next_position >> volume->bpb.log2_bytes_per_sector); + file->cursor.sector = next_sector; } else { file->cursor.sector = -1; } - file->cursor.position += success_size; - if (file->cursor.position > file->p_sfd->dir_entry.file_size) { - file->p_sfd->dir_entry.file_size = file->cursor.position; + new_position = file->cursor.position + success_size; + file->cursor.position = new_position; + if (new_position > file->p_sfd->dir_entry.file_size) { + file->p_sfd->dir_entry.file_size = new_position; } PFFILE_Cursor_Recalc(file); PFCLUSTER_UpdateLastAccessCluster(file); @@ -1081,7 +1091,6 @@ pf_s32 PFFILE_p_finfo(PFFILE_FILE* file, PF_INFO* info) { pf_u32 cluster_size; pf_u32 file_size_remainder; pf_u32 file_size; - pf_s32 sign_bits; pf_s32 error; file->p_sfd->ffd.p_hint = &file->hint; @@ -1096,9 +1105,10 @@ pf_s32 PFFILE_p_finfo(PFFILE_FILE* file, PF_INFO* info) { } file_size = file->p_sfd->dir_entry.file_size; file_size_remainder = file_size % cluster_size; - sign_bits = -(pf_s32)file_size_remainder | (pf_s32)file_size_remainder; info->empty_size = info->allocated_size + - ((sign_bits >> 31) & (cluster_size - file_size_remainder)); + (file_size_remainder != 0 + ? cluster_size - file_size_remainder + : 0); } else { info->allocated_size = 0; info->empty_size = 0; @@ -1116,11 +1126,10 @@ pf_s32 PFFILE_p_combine(PF_VOLUME* volume, PF_STR* first_path, PF_STR* second_pa PFFILE_ENT_ITER second_iter_copy; PF_DIR_ENT first_entry; PF_DIR_ENT second_entry; - PFFILE_FFD first_ffd; - PFFILE_FFD second_ffd; PF_FAT_HINT first_hint; PF_FAT_HINT second_hint; pf_u32 index; + pf_s32 found; pf_s32 error; error = PFENT_ITER_GetEntryOfPath(&first_iter, &first_entry, volume, first_path, 0); @@ -1137,24 +1146,36 @@ pf_s32 PFFILE_p_combine(PF_VOLUME* volume, PF_STR* first_path, PF_STR* second_pa if ((first_entry.attr & 1) != 0 || (second_entry.attr & 1) != 0) { return 0x18; } + found = 0; for (index = 0; index < 5; index++) { PFFILE_SFD* sfd = &((PFFILE_VOLUME_DIRS*)first_entry.p_vol)->sfds[index]; - if ((sfd->stat & 3) == 3 && first_entry.p_vol == sfd->dir_entry.p_vol && + if ((sfd->stat & 1) != 0 && (sfd->stat & 2) != 0 && + first_entry.p_vol == sfd->dir_entry.p_vol && first_entry.entry_sector == sfd->dir_entry.entry_sector && first_entry.entry_offset == sfd->dir_entry.entry_offset) { - return 0x13; + found = 1; + break; } } + if (found != 0) { + return 0x13; + } + found = 0; for (index = 0; index < 5; index++) { PFFILE_SFD* sfd = &((PFFILE_VOLUME_DIRS*)second_entry.p_vol)->sfds[index]; - if ((sfd->stat & 3) == 3 && second_entry.p_vol == sfd->dir_entry.p_vol && + if ((sfd->stat & 1) != 0 && (sfd->stat & 2) != 0 && + second_entry.p_vol == sfd->dir_entry.p_vol && second_entry.entry_sector == sfd->dir_entry.entry_sector && second_entry.entry_offset == sfd->dir_entry.entry_offset) { - return 0x13; + found = 1; + break; } } + if (found != 0) { + return 0x13; + } if (first_entry.entry_sector == second_entry.entry_sector && first_entry.entry_offset == second_entry.entry_offset) { return 0xA; @@ -1163,9 +1184,9 @@ pf_s32 PFFILE_p_combine(PF_VOLUME* volume, PF_STR* first_path, PF_STR* second_pa return 0x25; } PFFAT_InitHint(&first_hint); - PFFAT_InitFFD(&first_ffd, &first_hint, volume, &first_entry.start_cluster); + PFFAT_InitFFD(&first_iter.ffd, &first_hint, volume, &first_entry.start_cluster); PFFAT_InitHint(&second_hint); - PFFAT_InitFFD(&second_ffd, &second_hint, volume, &second_entry.start_cluster); + PFFAT_InitFFD(&second_iter.ffd, &second_hint, volume, &second_entry.start_cluster); pf_memcpy(&second_iter_copy, &second_iter, sizeof(second_iter_copy)); error = PFENT_RemoveEntry(&second_entry, &second_iter); if (error != 0) { -- 2.49.1 From 74f1719bfd7b602700461b388d53f50eb35636e3 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 29 Sep 2026 08:17:16 -0500 Subject: [PATCH 15/18] iplSDChannelSelect: 89/129 functions (worker f62627b8) (#266) --- config/43U/symbols.txt | 272 +- include/scene/sdButton/iplSDButton.h | 15 + .../sdChannelSelect/iplSDChannelSelect.h | 100 +- include/system/iplChannelManager.h | 8 + include/system/iplNandSDWorker.h | 4 + include/system/iplSaveDataManager.h | 9 + libs/NW4R/include/nw4r/math/types.h | 4 + .../sdChannelSelect/iplSDChannelSelect.cpp | 2502 ++++++++++++++--- 8 files changed, 2426 insertions(+), 488 deletions(-) diff --git a/config/43U/symbols.txt b/config/43U/symbols.txt index 819ea9e1..5811c23b 100644 --- a/config/43U/symbols.txt +++ b/config/43U/symbols.txt @@ -4596,21 +4596,21 @@ updateChannelNotices__Q33ipl5scene15SDChannelSelectFii = .text:0x813DC7EC; // ty processWorkerState__Q33ipl5scene15SDChannelSelectFv = .text:0x813DC938; // type:function size:0x18C updateDialogAnimation__Q33ipl5scene15SDChannelSelectFv = .text:0x813DCAC4; // type:function size:0x42C setDialogMessage__Q33ipl5scene15SDChannelSelectFUlUl = .text:0x813DCEF0; // type:function size:0x24 -iplSDChannelSelect_813DCF14 = .text:0x813DCF14; // type:function size:0xCC -iplSDChannelSelect_813DCFE0 = .text:0x813DCFE0; // type:function size:0xCC -iplSDChannelSelect_813DD0AC = .text:0x813DD0AC; // type:function size:0x194 -iplSDChannelSelect_813DD240 = .text:0x813DD240; // type:function size:0x198 -iplSDChannelSelect_813DD3D8 = .text:0x813DD3D8; // type:function size:0x1F8 -iplSDChannelSelect_813DD5D0 = .text:0x813DD5D0; // type:function size:0x5A4 -iplSDChannelSelect_813DDB74 = .text:0x813DDB74; // type:function size:0x40 -iplSDChannelSelect_813DDBB4 = .text:0x813DDBB4; // type:function size:0xB4 -iplSDChannelSelect_813DDC68 = .text:0x813DDC68; // type:function size:0x18 -iplSDChannelSelect_813DDC80 = .text:0x813DDC80; // type:function size:0x58 -iplSDChannelSelect_813DDCD8 = .text:0x813DDCD8; // type:function size:0x8C -iplSDChannelSelect_813DDD64 = .text:0x813DDD64; // type:function size:0x58 -iplSDChannelSelect_813DDDBC = .text:0x813DDDBC; // type:function size:0x5C -iplSDChannelSelect_813DDE18 = .text:0x813DDE18; // type:function size:0x2C -iplSDChannelSelect_813DDE44 = .text:0x813DDE44; // type:function size:0x24 +isCurrentTitleUsageEnough__Q33ipl5scene15SDChannelSelectCFPCl = .text:0x813DCF14; // type:function size:0xCC +getCurrentTitleUsage__Q33ipl5scene15SDChannelSelectCFPlPl = .text:0x813DCFE0; // type:function size:0xCC +collectTitlesByUsage__Q33ipl5scene15SDChannelSelectFPClPClPUxPcPUl = .text:0x813DD0AC; // type:function size:0x194 +collectTitlesFromNandUsage__Q33ipl5scene15SDChannelSelectFPClPClPUxPcPUl = .text:0x813DD240; // type:function size:0x198 +collectTitlesByChannelOrder__Q33ipl5scene15SDChannelSelectFPClPClPUxPcPUl = .text:0x813DD3D8; // type:function size:0x1F8 +collectTitlesBySpecialChannels__Q33ipl5scene15SDChannelSelectFPClPClPUxPcPUl = .text:0x813DD5D0; // type:function size:0x5A4 +collectTitlesForMode__Q33ipl5scene15SDChannelSelectFPClPClPUxPcPUli = .text:0x813DDB74; // type:function size:0x40 +findAdjacentChannel__Q33ipl5scene15SDChannelSelectCFiPiPi = .text:0x813DDBB4; // type:function size:0xB4 +setCurrentPageAndRefresh__Q33ipl5scene15SDChannelSelectFiiPQ33ipl5scene12SDChannelObj = .text:0x813DDC68; // type:function size:0x18 +handleFourPageDialog__Q33ipl5scene15SDChannelSelectFv = .text:0x813DDC80; // type:function size:0x58 +flushSaveDataAndMountSD__Q33ipl5scene15SDChannelSelectFv = .text:0x813DDCD8; // type:function size:0x8C +handleThreePageDialog__Q33ipl5scene15SDChannelSelectFv = .text:0x813DDD64; // type:function size:0x58 +finishCardDialog__Q33ipl5scene15SDChannelSelectFv = .text:0x813DDDBC; // type:function size:0x5C +finishDialogOperation__Q33ipl5scene15SDChannelSelectFv = .text:0x813DDE18; // type:function size:0x2C +finishDialogTransition__Q33ipl5scene15SDChannelSelectFv = .text:0x813DDE44; // type:function size:0x24 isResetProcessDone__Q33ipl5scene15SDChannelSelectFv = .text:0x813DDE68; // type:function size:0x28 calcCommon__Q33ipl5scene15SDChannelSelectFv = .text:0x813DDE90; // type:function size:0x1B0 calcFadein__Q33ipl5scene15SDChannelSelectFv = .text:0x813DE040; // type:function size:0x30 @@ -4623,60 +4623,60 @@ createBaseLayout__Q33ipl5scene15SDChannelSelectFv = .text:0x813DE9FC; // type:fu updateChannelObjects__Q33ipl5scene15SDChannelSelectFv = .text:0x813DEE3C; // type:function size:0x5C updateChannelObject__Q33ipl5scene15SDChannelSelectFPQ33ipl5scene12SDChannelObj = .text:0x813DEE98; // type:function size:0x78 calcChannelObjects__Q33ipl5scene15SDChannelSelectFv = .text:0x813DEF10; // type:function size:0x58 -iplSDChannelSelect_813DEF68 = .text:0x813DEF68; // type:function size:0x27C -iplSDChannelSelect_813DF1E4 = .text:0x813DF1E4; // type:function size:0x14 +drawChannelTransitionObjects__Q33ipl5scene15SDChannelSelectFv = .text:0x813DEF68; // type:function size:0x27C +isChannelReady__Q33ipl5scene15SDChannelSelectFPCQ33ipl5scene12SDChannelObj = .text:0x813DF1E4; // type:function size:0x14 drawChannelObjects__Q33ipl5scene15SDChannelSelectFv = .text:0x813DF1F8; // type:function size:0xB0 -iplSDChannelSelect_813DF2A8 = .text:0x813DF2A8; // type:function size:0x138 -iplSDChannelSelect_813DF3E0 = .text:0x813DF3E0; // type:function size:0x1C -iplSDChannelSelect_813DF3FC = .text:0x813DF3FC; // type:function size:0x110 -iplSDChannelSelect_813DF50C = .text:0x813DF50C; // type:function size:0x4C -iplSDChannelSelect_813DF558 = .text:0x813DF558; // type:function size:0x178 -iplSDChannelSelect_813DF6D0 = .text:0x813DF6D0; // type:function size:0x164 +processNormalInput__Q33ipl5scene15SDChannelSelectFv = .text:0x813DF2A8; // type:function size:0x138 +setPageActionFrame__Q33ipl5scene15SDChannelSelectFv = .text:0x813DF3E0; // type:function size:0x1C +finishPageScroll__Q33ipl5scene15SDChannelSelectFv = .text:0x813DF3FC; // type:function size:0x110 +advancePageAnimation__Q33ipl5scene15SDChannelSelectFv = .text:0x813DF50C; // type:function size:0x4C +initializeNormalPage__Q33ipl5scene15SDChannelSelectFv = .text:0x813DF558; // type:function size:0x178 +refreshPageObjects__Q33ipl5scene15SDChannelSelectFiPQ33ipl5scene12SDChannelObji = .text:0x813DF6D0; // type:function size:0x164 createChannelList__Q33ipl5scene15SDChannelSelectFib = .text:0x813DF834; // type:function size:0x110 createChannelObject__Q33ipl5scene15SDChannelSelectFii = .text:0x813DF944; // type:function size:0x84 destroyUnusedChannelObjects__Q33ipl5scene15SDChannelSelectFiPQ33ipl5scene12SDChannelObj = .text:0x813DF9C8; // type:function size:0xF8 refreshChannelList__Q33ipl5scene15SDChannelSelectFv = .text:0x813DFAC0; // type:function size:0xFC refreshAfterSDTitleList__Q33ipl5scene15SDChannelSelectFv = .text:0x813DFBBC; // type:function size:0xE4 destroyChannelObject__Q33ipl5scene15SDChannelSelectFPQ33ipl5scene12SDChannelObj = .text:0x813DFCA0; // type:function size:0x50 -iplSDChannelSelect_813DFCF0 = .text:0x813DFCF0; // type:function size:0x74 -iplSDChannelSelect_813DFD64 = .text:0x813DFD64; // type:function size:0x154 +updateChannelObjectOrder__Q33ipl5scene15SDChannelSelectFi = .text:0x813DFCF0; // type:function size:0x74 +moveChannelObjectsToDrawOrder__Q33ipl5scene15SDChannelSelectFii = .text:0x813DFD64; // type:function size:0x154 findChannelObject__Q33ipl5scene15SDChannelSelectCFii = .text:0x813DFEB8; // type:function size:0x74 -iplSDChannelSelect_813DFF2C = .text:0x813DFF2C; // type:function size:0x1C0 +updateArrowVisibility__Q33ipl5scene15SDChannelSelectFv = .text:0x813DFF2C; // type:function size:0x1C0 hasChannelObject__Q33ipl5scene15SDChannelSelectCFii = .text:0x813E00EC; // type:function size:0x140 isChannelInCalc__Q33ipl5scene15SDChannelSelectCFiii = .text:0x813E022C; // type:function size:0x68 -iplSDChannelSelect_813E0294 = .text:0x813E0294; // type:function size:0x104 -iplSDChannelSelect_813E0398 = .text:0x813E0398; // type:function size:0x18 -iplSDChannelSelect_813E03B0 = .text:0x813E03B0; // type:function size:0xA0 -iplSDChannelSelect_813E0450 = .text:0x813E0450; // type:function size:0xEC -iplSDChannelSelect_813E053C = .text:0x813E053C; // type:function size:0x84 -iplSDChannelSelect_813E05C0 = .text:0x813E05C0; // type:function size:0x64 -iplSDChannelSelect_813E0624 = .text:0x813E0624; // type:function size:0xB4 +isPageCreated__Q33ipl5scene15SDChannelSelectCFi = .text:0x813E0294; // type:function size:0x104 +setStateAndPlaySelectSound__Q33ipl5scene15SDChannelSelectFi = .text:0x813E0398; // type:function size:0x18 +setLayoutFrame__Q33ipl5scene15SDChannelSelectFi = .text:0x813E03B0; // type:function size:0xA0 +selectChannel__Q33ipl5scene15SDChannelSelectFii = .text:0x813E0450; // type:function size:0xEC +tellStartingZoomAnm__Q33ipl5scene15SDChannelSelectFv = .text:0x813E053C; // type:function size:0x84 +prepareRestarting__Q33ipl5scene15SDChannelSelectFi = .text:0x813E05C0; // type:function size:0x64 +startPageTransition__Q33ipl5scene15SDChannelSelectFii = .text:0x813E0624; // type:function size:0xB4 getChannelBasePane__Q33ipl5scene15SDChannelSelectCFiii = .text:0x813E06D8; // type:function size:0xAC getCenterChannelPane__Q33ipl5scene15SDChannelSelectCFi = .text:0x813E0784; // type:function size:0x30 getChannelPane__Q33ipl5scene15SDChannelSelectCFi = .text:0x813E07B4; // type:function size:0x30 getChannelPanePosition__Q33ipl5scene15SDChannelSelectFPQ33ipl5scene15SDChannelSelecti = .text:0x813E07E4; // type:function size:0x64 -iplSDChannelSelect_813E0848 = .text:0x813E0848; // type:function size:0x3A4 -iplSDChannelSelect_813E0BEC = .text:0x813E0BEC; // type:function size:0x294 +setChannelScissor__Q33ipl5scene15SDChannelSelectCFPCQ33ipl5scene12SDChannelObj = .text:0x813E0848; // type:function size:0x3A4 +initPageAnimations__Q33ipl5scene15SDChannelSelectFRCQ33ipl4math4VEC3i = .text:0x813E0BEC; // type:function size:0x294 calcPageAnimations__Q33ipl5scene15SDChannelSelectFv = .text:0x813E0E80; // type:function size:0x60 -iplSDChannelSelect_813E0EE0 = .text:0x813E0EE0; // type:function size:0x26C -iplSDChannelSelect_813E114C = .text:0x813E114C; // type:function size:0x78 -iplSDChannelSelect_813E11C4 = .text:0x813E11C4; // type:function size:0x3A4 -iplSDChannelSelect_813E1568 = .text:0x813E1568; // type:function size:0x124 -iplSDChannelSelect_813E168C = .text:0x813E168C; // type:function size:0x2D0 -iplSDChannelSelect_813E195C = .text:0x813E195C; // type:function size:0x6C -iplSDChannelSelect_813E19C8 = .text:0x813E19C8; // type:function size:0x68 -iplSDChannelSelect_813E1A30 = .text:0x813E1A30; // type:function size:0x208 -iplSDChannelSelect_813E1C38 = .text:0x813E1C38; // type:function size:0x118 -iplSDChannelSelect_813E1D50 = .text:0x813E1D50; // type:function size:0xFC -iplSDChannelSelect_813E1E4C = .text:0x813E1E4C; // type:function size:0x19C -iplSDChannelSelect_813E1FE8 = .text:0x813E1FE8; // type:function size:0x1A4 -iplSDChannelSelect_813E218C = .text:0x813E218C; // type:function size:0x16C -iplSDChannelSelect_813E22F8 = .text:0x813E22F8; // type:function size:0x1E0 -iplSDChannelSelect_813E24D8 = .text:0x813E24D8; // type:function size:0x204 -iplSDChannelSelect_813E26DC = .text:0x813E26DC; // type:function size:0x74 -iplSDChannelSelect_813E2750 = .text:0x813E2750; // type:function size:0x164 -iplSDChannelSelect_813E28B4 = .text:0x813E28B4; // type:function size:0x2A0 -iplSDChannelSelect_813E2B54 = .text:0x813E2B54; // type:function size:0x240 +updatePageTransform__Q33ipl5scene15SDChannelSelectFv = .text:0x813E0EE0; // type:function size:0x26C +getCenterChannelIndex__Q33ipl5scene15SDChannelSelectCFPCc = .text:0x813E114C; // type:function size:0x78 +createSceneLayouts__Q33ipl5scene15SDChannelSelectFv = .text:0x813E11C4; // type:function size:0x3A4 +updateDragState__Q33ipl5scene15SDChannelSelectFv = .text:0x813E1568; // type:function size:0x124 +updateDragPageTransition__Q33ipl5scene15SDChannelSelectFv = .text:0x813E168C; // type:function size:0x2D0 +finishDragWait__Q33ipl5scene15SDChannelSelectFv = .text:0x813E195C; // type:function size:0x6C +finishDragPageTransition__Q33ipl5scene15SDChannelSelectFv = .text:0x813E19C8; // type:function size:0x68 +applyChannelMove__Q33ipl5scene15SDChannelSelectFv = .text:0x813E1A30; // type:function size:0x208 +finishChannelMove__Q33ipl5scene15SDChannelSelectFv = .text:0x813E1C38; // type:function size:0x118 +resetDragPreview__Q33ipl5scene15SDChannelSelectFv = .text:0x813E1D50; // type:function size:0xFC +finishDragPageChange__Q33ipl5scene15SDChannelSelectFv = .text:0x813E1E4C; // type:function size:0x19C +onEventDerived__Q33ipl5scene15SDChannelSelectFPCcUlPQ33ipl10controller9Interface = .text:0x813E1FE8; // type:function size:0x1A4 +onButtonEvent__Q33ipl5scene15SDChannelSelectFPCcUlPCQ33ipl10controller9Interface = .text:0x813E218C; // type:function size:0x16C +startDrag__Q33ipl5scene15SDChannelSelectFPCQ33ipl10controller9Interfaceii = .text:0x813E22F8; // type:function size:0x1E0 +finishDrag__Q33ipl5scene15SDChannelSelectFv = .text:0x813E24D8; // type:function size:0x204 +isChannelMoveTarget__Q33ipl5scene15SDChannelSelectCFii = .text:0x813E26DC; // type:function size:0x74 +moveDrag__Q33ipl5scene15SDChannelSelectFv = .text:0x813E2750; // type:function size:0x164 +onEvent__Q43ipl5scene32@unnamed@iplSDChannelSelect_cpp@27SDChannelSelectEventHandlerFUlUlPv = .text:0x813E28B4; // type:function size:0x2A0 +onEventDerived__Q43ipl5scene32@unnamed@iplSDChannelSelect_cpp@33SDChannelSelectButtonEventHandlerFUlUlPCQ33ipl10controller9Interface = .text:0x813E2B54; // type:function size:0x240 startResetting__Q33ipl5scene15SDChannelSelectFv = .text:0x813E2D94; // type:function size:0x44 pop__Q33ipl5scene26SDChannelSelectNoticeQueueFv = .text:0x813E2DD8; // type:function size:0x4C push__Q33ipl5scene27SDChannelSelectCommandQueueFRCQ33ipl5scene22SDChannelSelectCommand = .text:0x813E2E24; // type:function size:0x80 @@ -4694,7 +4694,7 @@ iplSDChannelObj_813E322C = .text:0x813E322C; // type:function size:0x9C iplSDChannelObj_813E32C8 = .text:0x813E32C8; // type:function size:0x3C iplSDChannelObj_813E3304 = .text:0x813E3304; // type:function size:0x8 iplSDChannelObj_813E330C = .text:0x813E330C; // type:function size:0x14 -iplSDChannelObj_813E3320 = .text:0x813E3320; // type:function size:0x10 +getTranslate__Q33ipl5scene12SDChannelObjCFv = .text:0x813E3320; // type:function size:0x10 iplSDChannelObj_813E3330 = .text:0x813E3330; // type:function size:0x24 iplSDChannelObj_813E3354 = .text:0x813E3354; // type:function size:0x98 iplSDChannelObj_813E33EC = .text:0x813E33EC; // type:function size:0x94 @@ -16752,73 +16752,73 @@ __vt__Q33ipl5scene14ParentalDialog = .data:0x81653ED8; // type:object size:0x68 @10007 = .data:0x81653FD8; // type:object size:0xE scope:local data:string __vt__Q33ipl5scene6Reboot = .data:0x81653FE8; // type:object size:0x4C __vt__Q33ipl5scene9RootScene = .data:0x81654038; // type:object size:0x4C -lbl_81654088 = .data:0x81654088; // type:object size:0x9 data:string -lbl_81654091 = .data:0x81654091; // type:object size:0x9 data:string -lbl_8165409A = .data:0x8165409A; // type:object size:0x9 data:string -lbl_816540A3 = .data:0x816540A3; // type:object size:0x9 data:string -lbl_816540AC = .data:0x816540AC; // type:object size:0x9 data:string -lbl_816540B5 = .data:0x816540B5; // type:object size:0x9 data:string -lbl_816540BE = .data:0x816540BE; // type:object size:0x9 data:string -lbl_816540C7 = .data:0x816540C7; // type:object size:0x9 data:string -lbl_816540D0 = .data:0x816540D0; // type:object size:0x9 data:string -lbl_816540D9 = .data:0x816540D9; // type:object size:0x9 data:string -lbl_816540E2 = .data:0x816540E2; // type:object size:0x9 data:string -lbl_816540EB = .data:0x816540EB; // type:object size:0x9 data:string -lbl_816540F4 = .data:0x816540F4; // type:object size:0x9 data:string -lbl_816540FD = .data:0x816540FD; // type:object size:0x9 data:string -lbl_81654106 = .data:0x81654106; // type:object size:0x9 data:string -lbl_8165410F = .data:0x8165410F; // type:object size:0x9 data:string -lbl_81654118 = .data:0x81654118; // type:object size:0x9 data:string -lbl_81654121 = .data:0x81654121; // type:object size:0x9 data:string -lbl_8165412A = .data:0x8165412A; // type:object size:0x9 data:string -lbl_81654133 = .data:0x81654133; // type:object size:0x9 data:string -lbl_8165413C = .data:0x8165413C; // type:object size:0x9 data:string -lbl_81654145 = .data:0x81654145; // type:object size:0x9 data:string -lbl_8165414E = .data:0x8165414E; // type:object size:0x9 data:string -lbl_81654157 = .data:0x81654157; // type:object size:0x9 data:string -lbl_81654160 = .data:0x81654160; // type:object size:0x9 data:string -lbl_81654169 = .data:0x81654169; // type:object size:0x9 data:string -lbl_81654172 = .data:0x81654172; // type:object size:0x9 data:string -lbl_8165417B = .data:0x8165417B; // type:object size:0x9 data:string -lbl_81654184 = .data:0x81654184; // type:object size:0x9 data:string -lbl_8165418D = .data:0x8165418D; // type:object size:0x9 data:string -lbl_81654196 = .data:0x81654196; // type:object size:0x9 data:string -lbl_8165419F = .data:0x8165419F; // type:object size:0x9 data:string -lbl_816541A8 = .data:0x816541A8; // type:object size:0x9 data:string -lbl_816541B1 = .data:0x816541B1; // type:object size:0x9 data:string -lbl_816541BA = .data:0x816541BA; // type:object size:0x9 data:string -lbl_816541C3 = .data:0x816541C3; // type:object size:0x9 data:string -lbl_816541CC = .data:0x816541CC; // type:object size:0x9 data:string -lbl_816541D5 = .data:0x816541D5; // type:object size:0x9 data:string -lbl_816541DE = .data:0x816541DE; // type:object size:0x9 data:string -lbl_816541E7 = .data:0x816541E7; // type:object size:0x9 data:string -lbl_816541F0 = .data:0x816541F0; // type:object size:0x9 data:string -lbl_816541F9 = .data:0x816541F9; // type:object size:0x9 data:string +@16632 = .data:0x81654088; // type:object size:0x9 scope:local data:string +@16633 = .data:0x81654091; // type:object size:0x9 scope:local data:string +@16634 = .data:0x8165409A; // type:object size:0x9 scope:local data:string +@16635 = .data:0x816540A3; // type:object size:0x9 scope:local data:string +@16636 = .data:0x816540AC; // type:object size:0x9 scope:local data:string +@16637 = .data:0x816540B5; // type:object size:0x9 scope:local data:string +@16638 = .data:0x816540BE; // type:object size:0x9 scope:local data:string +@16639 = .data:0x816540C7; // type:object size:0x9 scope:local data:string +@16640 = .data:0x816540D0; // type:object size:0x9 scope:local data:string +@16641 = .data:0x816540D9; // type:object size:0x9 scope:local data:string +@16642 = .data:0x816540E2; // type:object size:0x9 scope:local data:string +@16643 = .data:0x816540EB; // type:object size:0x9 scope:local data:string +@16644 = .data:0x816540F4; // type:object size:0x9 scope:local data:string +@16645 = .data:0x816540FD; // type:object size:0x9 scope:local data:string +@16646 = .data:0x81654106; // type:object size:0x9 scope:local data:string +@16647 = .data:0x8165410F; // type:object size:0x9 scope:local data:string +@16648 = .data:0x81654118; // type:object size:0x9 scope:local data:string +@16649 = .data:0x81654121; // type:object size:0x9 scope:local data:string +@16650 = .data:0x8165412A; // type:object size:0x9 scope:local data:string +@16651 = .data:0x81654133; // type:object size:0x9 scope:local data:string +@16652 = .data:0x8165413C; // type:object size:0x9 scope:local data:string +@16653 = .data:0x81654145; // type:object size:0x9 scope:local data:string +@16654 = .data:0x8165414E; // type:object size:0x9 scope:local data:string +@16655 = .data:0x81654157; // type:object size:0x9 scope:local data:string +@16656 = .data:0x81654160; // type:object size:0x9 scope:local data:string +@16657 = .data:0x81654169; // type:object size:0x9 scope:local data:string +@16658 = .data:0x81654172; // type:object size:0x9 scope:local data:string +@16659 = .data:0x8165417B; // type:object size:0x9 scope:local data:string +@16660 = .data:0x81654184; // type:object size:0x9 scope:local data:string +@16661 = .data:0x8165418D; // type:object size:0x9 scope:local data:string +@16662 = .data:0x81654196; // type:object size:0x9 scope:local data:string +@16663 = .data:0x8165419F; // type:object size:0x9 scope:local data:string +@16664 = .data:0x816541A8; // type:object size:0x9 scope:local data:string +@16665 = .data:0x816541B1; // type:object size:0x9 scope:local data:string +@16666 = .data:0x816541BA; // type:object size:0x9 scope:local data:string +@16667 = .data:0x816541C3; // type:object size:0x9 scope:local data:string +@16668 = .data:0x816541CC; // type:object size:0x9 scope:local data:string +@16669 = .data:0x816541D5; // type:object size:0x9 scope:local data:string +@16670 = .data:0x816541DE; // type:object size:0x9 scope:local data:string +@16671 = .data:0x816541E7; // type:object size:0x9 scope:local data:string +@16672 = .data:0x816541F0; // type:object size:0x9 scope:local data:string +@16673 = .data:0x816541F9; // type:object size:0x9 scope:local data:string lbl_81654204 = .data:0x81654204; // type:object size:0xF0 -lbl_816542F4 = .data:0x816542F4; // type:object size:0xA data:string -lbl_816542FE = .data:0x816542FE; // type:object size:0xA data:string -lbl_81654308 = .data:0x81654308; // type:object size:0xA data:string -lbl_81654312 = .data:0x81654312; // type:object size:0xA data:string +@16674 = .data:0x816542F4; // type:object size:0xA scope:local data:string +@16675 = .data:0x816542FE; // type:object size:0xA scope:local data:string +@16676 = .data:0x81654308; // type:object size:0xA scope:local data:string +@16677 = .data:0x81654312; // type:object size:0xA scope:local data:string lbl_8165431C = .data:0x8165431C; // type:object size:0x20 -lbl_8165433C = .data:0x8165433C; // type:object size:0xB data:string -lbl_81654347 = .data:0x81654347; // type:object size:0xB data:string -lbl_81654352 = .data:0x81654352; // type:object size:0xB data:string -lbl_8165435D = .data:0x8165435D; // type:object size:0xB data:string +@16679 = .data:0x8165433C; // type:object size:0xB scope:local data:string +@16680 = .data:0x81654347; // type:object size:0xB scope:local data:string +@16681 = .data:0x81654352; // type:object size:0xB scope:local data:string +@16682 = .data:0x8165435D; // type:object size:0xB scope:local data:string lbl_81654368 = .data:0x81654368; // type:object size:0x20 lbl_81654388 = .data:0x81654388; // type:object size:0x14 data:4byte -lbl_8165439C = .data:0x8165439C; // type:object size:0x70 -lbl_8165440C = .data:0x8165440C; // type:object size:0x54 -lbl_81654460 = .data:0x81654460; // type:object size:0x9 data:string -lbl_81654469 = .data:0x81654469; // type:object size:0x9 data:string +sFourPageDialogPages__Q23ipl5scene = .data:0x8165439C; // type:object size:0x70 +sThreePageDialogPages__Q23ipl5scene = .data:0x8165440C; // type:object size:0x54 +@16689 = .data:0x81654460; // type:object size:0x9 scope:local data:string +@16690 = .data:0x81654469; // type:object size:0x9 scope:local data:string lbl_81654472 = .data:0x81654472; // type:object size:0x16 -lbl_81654488 = .data:0x81654488; // type:object size:0xE data:string -lbl_81654496 = .data:0x81654496; // type:object size:0x11 data:string -lbl_816544A7 = .data:0x816544A7; // type:object size:0x19 data:string -lbl_816544C0 = .data:0x816544C0; // type:object size:0x1B data:string +@24438 = .data:0x81654488; // type:object size:0xE scope:local data:string +@24439 = .data:0x81654496; // type:object size:0x11 scope:local data:string +@24489 = .data:0x816544A7; // type:object size:0x19 scope:local data:string +@24490 = .data:0x816544C0; // type:object size:0x1B scope:local data:string jumptable_816544DC = .data:0x816544DC; // type:object size:0x38 scope:local jumptable_81654514 = .data:0x81654514; // type:object size:0x40 scope:local -lbl_81654554 = .data:0x81654554; // type:object size:0xB data:string -lbl_8165455F = .data:0x8165455F; // type:object size:0xE data:string +@24961 = .data:0x81654554; // type:object size:0xB scope:local data:string +@24962 = .data:0x8165455F; // type:object size:0xE scope:local data:string jumptable_81654570 = .data:0x81654570; // type:object size:0x3C scope:local jumptable_816545AC = .data:0x816545AC; // type:object size:0x40 scope:local jumptable_816545EC = .data:0x816545EC; // type:object size:0x40 scope:local @@ -16826,16 +16826,16 @@ jumptable_8165462C = .data:0x8165462C; // type:object size:0x40 scope:local jumptable_8165466C = .data:0x8165466C; // type:object size:0x28 scope:local jumptable_81654694 = .data:0x81654694; // type:object size:0x78 scope:local lbl_8165473B = .data:0x8165473B; // type:object size:0xD4 -lbl_8165480F = .data:0x8165480F; // type:object size:0xE data:string -lbl_8165481D = .data:0x8165481D; // type:object size:0xB data:string -lbl_81654828 = .data:0x81654828; // type:object size:0x10 data:string +@26032 = .data:0x8165480F; // type:object size:0xE scope:local data:string +@26047 = .data:0x8165481D; // type:object size:0xB scope:local data:string +@26062 = .data:0x81654828; // type:object size:0x10 scope:local data:string lbl_81654838 = .data:0x81654838; // type:object size:0x146 -lbl_8165497E = .data:0x8165497E; // type:object size:0x16 data:string -lbl_81654994 = .data:0x81654994; // type:object size:0x10 data:string -lbl_816549A4 = .data:0x816549A4; // type:object size:0xF data:string -lbl_816549B3 = .data:0x816549B3; // type:object size:0x14 data:string -lbl_816549C7 = .data:0x816549C7; // type:object size:0x10 data:string -lbl_816549D7 = .data:0x816549D7; // type:object size:0xF data:string +@26231 = .data:0x8165497E; // type:object size:0x16 scope:local data:string +@26266 = .data:0x81654994; // type:object size:0x10 scope:local data:string +@26311 = .data:0x816549A4; // type:object size:0xF scope:local data:string +@26312 = .data:0x816549B3; // type:object size:0x14 scope:local data:string +@26336 = .data:0x816549C7; // type:object size:0x10 scope:local data:string +@26559 = .data:0x816549D7; // type:object size:0xF scope:local data:string lbl_81654A08 = .data:0x81654A08; // type:object size:0x1C lbl_81654A24 = .data:0x81654A24; // type:object size:0x18 lbl_81654A3C = .data:0x81654A3C; // type:object size:0xFC @@ -22014,20 +22014,20 @@ natType = .sdata:0x81696D30; // type:object size:0x4 scope:local data:4byte @11124 = .sdata:0x81696D69; // type:object size:0x7 scope:local data:string @11125 = .sdata:0x81696D70; // type:object size:0x7 scope:local data:string @11250 = .sdata:0x81696D78; // type:object size:0x2 scope:local -lbl_81696D80 = .sdata:0x81696D80; // type:object size:0x1 -lbl_81696D81 = .sdata:0x81696D81; // type:object size:0x6 data:string -lbl_81696D87 = .sdata:0x81696D87; // type:object size:0x6 data:string -lbl_81696D8D = .sdata:0x81696D8D; // type:object size:0x6 data:string -lbl_81696D93 = .sdata:0x81696D93; // type:object size:0x6 data:string -lbl_81696D99 = .sdata:0x81696D99; // type:object size:0x6 data:string -lbl_81696D9F = .sdata:0x81696D9F; // type:object size:0x7 data:string +@16631 = .sdata:0x81696D80; // type:object size:0x1 scope:local +@16684 = .sdata:0x81696D81; // type:object size:0x6 scope:local data:string +@16685 = .sdata:0x81696D87; // type:object size:0x6 scope:local data:string +@16686 = .sdata:0x81696D8D; // type:object size:0x6 scope:local data:string +@16687 = .sdata:0x81696D93; // type:object size:0x6 scope:local data:string +@16688 = .sdata:0x81696D99; // type:object size:0x6 scope:local data:string +@16692 = .sdata:0x81696D9F; // type:object size:0x7 scope:local data:string lbl_81696DA8 = .sdata:0x81696DA8; // type:object size:0x4 data:4byte lbl_81696DAC = .sdata:0x81696DAC; // type:object size:0x6 data:wstring -lbl_81696DB2 = .sdata:0x81696DB2; // type:object size:0x4 data:string -lbl_81696DB6 = .sdata:0x81696DB6; // type:object size:0x7 data:string -lbl_81696DBD = .sdata:0x81696DBD; // type:object size:0x1 -lbl_81696DBE = .sdata:0x81696DBE; // type:object size:0x4 data:string -lbl_81696DC2 = .sdata:0x81696DC2; // type:object size:0x5 data:string +@25675 = .sdata:0x81696DB2; // type:object size:0x4 scope:local data:string +@25689 = .sdata:0x81696DB6; // type:object size:0x7 scope:local data:string +@25710 = .sdata:0x81696DBD; // type:object size:0x1 scope:local +@26199 = .sdata:0x81696DBE; // type:object size:0x4 scope:local data:string +@26201 = .sdata:0x81696DC2; // type:object size:0x5 scope:local data:string lbl_81696DC7 = .sdata:0x81696DC7; // type:object size:0x8 data:string lbl_81696DD0 = .sdata:0x81696DD0; // type:object size:0x4 data:4byte lbl_81696DD4 = .sdata:0x81696DD4; // type:object size:0x4 data:4byte diff --git a/include/scene/sdButton/iplSDButton.h b/include/scene/sdButton/iplSDButton.h index e82f5766..a3de1f2b 100644 --- a/include/scene/sdButton/iplSDButton.h +++ b/include/scene/sdButton/iplSDButton.h @@ -11,6 +11,12 @@ namespace ipl { namespace scene { +#ifdef IPL_SD_CHANNEL_SELECT_CPP + namespace { + class SDChannelSelectButtonEventHandler; + } +#endif + class SDButtonEventHandlerBase : public ::gui::EventHandler { public: virtual void onEvent(u32 compId, u32 event, void* data); @@ -92,7 +98,12 @@ namespace ipl { bool isActive() const; +#ifdef IPL_SD_CHANNEL_SELECT_CPP + void setEventHandler(::gui::EventHandler * event, + ::gui::EventHandler * optOutEvent = NULL); +#else void setEventHandler(::gui::EventHandler * event, ::gui::EventHandler * optOutEvent); +#endif void setText(const char* paneName, u32 msgId); void setText(const char* paneName, const wchar_t* text); @@ -156,6 +167,10 @@ namespace ipl { friend class SDArrow; friend class SDButtonEventHandlerBase; +#ifdef IPL_SD_CHANNEL_SELECT_CPP + friend class SDChannelSelect; + friend class SDChannelSelectButtonEventHandler; +#endif }; } // namespace scene } // namespace ipl diff --git a/include/scene/sdChannelSelect/iplSDChannelSelect.h b/include/scene/sdChannelSelect/iplSDChannelSelect.h index e978db31..de47f1fb 100644 --- a/include/scene/sdChannelSelect/iplSDChannelSelect.h +++ b/include/scene/sdChannelSelect/iplSDChannelSelect.h @@ -10,6 +10,14 @@ namespace ipl { namespace scene { +#ifdef IPL_SD_CHANNEL_SELECT_CPP + class SDChannelSelect; + namespace { + class SDChannelSelectEventHandler; + class SDChannelSelectButtonEventHandler; + } +#endif + class SDChannelObj { public: SDChannelObj(EGG::Heap* heap, int page, int index); @@ -18,6 +26,7 @@ namespace ipl { EGG::Heap* getHeap() const { return mpHeap; } int getPage() const { return mPage; } int getIndex() const { return mIndex; } + nw4r::math::VEC3& getTranslate() const; private: friend class SDChannelSelect; @@ -60,10 +69,16 @@ namespace ipl { extern "C" void iplSDChannelObj_813E311C(SDChannelObj* channel, EGG::ExpHeap* firstHeap, EGG::ExpHeap* secondHeap); extern "C" void iplSDChannelObj_813E322C(SDChannelObj* channel); + extern "C" void iplSDChannelObj_813E32C8(SDChannelObj* channel); + extern "C" void iplSDChannelObj_813E34E0(SDChannelObj* channel); extern "C" void iplSDChannelObj_813E3178(SDChannelObj* channel, nw4r::lyt::Pane* pane); extern "C" void iplSDChannelObj_813E3180(SDChannelObj* channel, nand::LayoutFile* layoutFile); extern "C" void iplSDChannelObj_813E3304(SDChannelObj* channel); extern "C" void iplSDChannelObj_813E330C(SDChannelObj* channel); + extern "C" void iplSDChannelObj_813E3354(SDChannelObj* channel, int state); + extern "C" void iplSDChannelObj_813E33EC(SDChannelObj* channel, int state); + extern "C" void iplSDChannelObj_813E3480(SDChannelObj* channel, bool selected); + extern "C" void iplSDChannelObj_813E34E8(SDChannelObj* channel, int enabled); extern "C" void* iplSDChannelObj_813E3128(SDChannelObj* channel); extern "C" bool iplSDChannelObj_813E3330(SDChannelObj* channel); @@ -142,6 +157,14 @@ namespace ipl { virtual FaderSceneCommand calcNormal(); virtual FaderSceneCommand calcFadeout(); + void onButtonEvent(const char* paneName, u32 event, + const controller::Interface* controller); + BOOL onEventDerived(const char* paneName, u32 event, + controller::Interface* controller); + bool collectTitlesByUsage(const s32* firstUsage, const s32* secondUsage, + ESTitleId* titleIds, char* titleNames, + u32* titleCount); + static const char* mscChannelPaneNames[PAGE_COUNT][MAX_CHANNEL_INDEX]; static const char* mscBasePaneNames[PAGE_COUNT]; static const char* mscPicturePaneNames[PAGE_COUNT]; @@ -150,6 +173,10 @@ namespace ipl { static const char* mscMaskPaneName; private: +#ifdef IPL_SD_CHANNEL_SELECT_CPP + friend class SDChannelSelectEventHandler; + friend class SDChannelSelectButtonEventHandler; +#endif void enqueueStartNotice(); bool enqueueFinishNotice(); bool enqueueNotice(u32 highTitleId, u32 lowTitleId, u32 result); @@ -167,16 +194,40 @@ namespace ipl { void calcChannelObjects(); void updateChannelObjects(); void updateChannelObject(SDChannelObj* channel); + void drawChannelTransitionObjects(); void drawChannelObjects(); bool isChannelInCalc(int page, int index, int currentPage) const; nw4r::lyt::Pane* getChannelBasePane(int page, int index, int currentPage) const; + int getCenterChannelIndex(const char* paneName) const; nw4r::lyt::Pane* getCenterChannelPane(int index) const; nw4r::lyt::Pane* getChannelPane(int index) const; static math::VEC3 getChannelPanePosition(SDChannelSelect* scene, int index); void calcPageAnimations(); + void processNormalInput(); void updateArrowVisibility(); void processWorkerState(); void updateDialogAnimation(); + void initializeNormalPage(); + void updatePageTransform(); + void setChannelScissor(const SDChannelObj* channel) const; + bool isCurrentTitleUsageEnough(const s32* usage) const; + void getCurrentTitleUsage(s32* bytes, s32* blocks) const; + bool collectTitlesByChannelOrder(const s32* firstUsage, const s32* secondUsage, + ESTitleId* titleIds, char* titleNames, + u32* titleCount); + bool collectTitlesFromNandUsage(const s32* firstUsage, const s32* secondUsage, + ESTitleId* titleIds, char* titleNames, + u32* titleCount); + bool collectTitlesBySpecialChannels(const s32* firstUsage, const s32* secondUsage, + ESTitleId* titleIds, char* titleNames, + u32* titleCount); + bool collectTitlesForMode(const s32* firstUsage, const s32* secondUsage, + ESTitleId* titleIds, char* titleNames, + u32* titleCount, int searchMode); + bool findAdjacentChannel(int direction, int* page, int* index) const; + void setStateAndPlaySelectSound(int state) NO_INLINE; + void finishDialogOperation(); + void finishDialogTransition(); void processWorkerCommands(); void handleWorkerStartup(); void handleNandTitleCount(); @@ -210,9 +261,38 @@ namespace ipl { SDChannelObj* findChannelObject(int page, int index) const; void createChannelObject(int page, int index); void createBaseLayout(); - void updateNoCardLayouts(); - void createChannelThumbnails(); - + void createSceneLayouts(); + BOOL isChannelMoveTarget(int page, int index) const; + void selectChannel(int page, int index); + BOOL prepareRestarting(int page); + void startPageTransition(int page, int index); + void setCurrentPageAndRefresh(int page, int index, SDChannelObj* keepChannel); + void handleFourPageDialog(); + void handleThreePageDialog(); + void setPageActionFrame(); + void advancePageAnimation(); + void finishPageScroll(); + void finishCardDialog(); + void flushSaveDataAndMountSD(); + void startDrag(const controller::Interface* controller, int page, int index); + void finishDrag(); + void moveDrag(); + void updateDragState(); + void updateDragPageTransition(); + void finishDragWait(); + void finishDragPageTransition(); + void applyChannelMove(); + void finishChannelMove(); + void resetDragPreview(); + void finishDragPageChange(); + BOOL isPageCreated(int page) const; + void refreshPageObjects(int page, SDChannelObj* keepChannel, int noticeIndex); + void updateChannelObjectOrder(int page); + void moveChannelObjectsToDrawOrder(int page, int mode); + void setLayoutFrame(int state); + BOOL tellStartingZoomAnm(); + void initPageAnimations(const math::VEC3& position, int direction); + static BOOL isChannelReady(const SDChannelObj* channel); nw4r::ut::List mChannelObjects; nand::LayoutFile* mpLayoutFile; layout::Object* mpLayout; @@ -228,7 +308,7 @@ namespace ipl { int mCurrentChannelIndex; f32 mThumbOffsetX; f32 mThumbOffsetY; - nw4r::math::VEC3 mPosition; + math::VEC3 mPosition; math::VEC2 mScale; f32 mAspectRatioScale; bool mbLeftArrowVisible; @@ -251,9 +331,9 @@ namespace ipl { bool mbButtonEnabled; bool mbDialogActive; u16 mInputFlags; - SDChannelObj* mpCurrentChannel; + void* mpCurrentChannel; layout::Object* mpStateLayout; - layout::Object* mpHelpLayout; + layout::Animator* mpHelpLayout; EGG::ExpHeap* mpRsoHeap; channel::RsoThread* mpRsoThread; u32 mCommandQueueState; @@ -269,8 +349,8 @@ namespace ipl { ESTitleId32* mpSDTitleIds; SDChannelSelectTitleInfo* mpSDTitleInfo; NandSDWorker::TitleUsage* mpNandTitleInfo; - u32 mFirstTitleCount; - u32 mSecondTitleCount; + s32 mFirstTitleCount; + s32 mSecondTitleCount; SDChannelObj* mpCurrentLoadedChannel; u32 mSDTitleCount; u32 mNandTitleCount; @@ -284,8 +364,8 @@ namespace ipl { u8 mbShowNoCardMessage; u8 mbOperationActive; u8 mbSDCardBroken; - u32 mOperationState; - u32 mDialogState; + int mOperationState; + int mDialogState; nand::File* mpSaveDataFile; u32 mAnimationState; u32 mAnimationTarget; diff --git a/include/system/iplChannelManager.h b/include/system/iplChannelManager.h index 6a72b9ea..0e7236bf 100644 --- a/include/system/iplChannelManager.h +++ b/include/system/iplChannelManager.h @@ -36,6 +36,11 @@ #define MAX_CHANNEL_INFO_SIZE CHANNEL_INFO_SIZE(MAX_CHANNEL_PAGE, MAX_CHANNEL_INDEX) namespace ipl { +#ifdef IPL_SD_CHANNEL_SELECT_CPP + namespace scene { + class SDChannelSelect; + } +#endif namespace channel { enum { PRIMARY_TYPE_NONE = 0, @@ -368,6 +373,9 @@ namespace ipl { char* getChJumpData() { return mChJumpData; } private: +#ifdef IPL_SD_CHANNEL_SELECT_CPP + friend class ipl::scene::SDChannelSelect; +#endif typedef struct MD5Head { u8 magic[4]; // 0x00 (`IMD5`; "IPL MD5"?) u32 length; // 0x04 diff --git a/include/system/iplNandSDWorker.h b/include/system/iplNandSDWorker.h index 42297f73..b9781e8c 100644 --- a/include/system/iplNandSDWorker.h +++ b/include/system/iplNandSDWorker.h @@ -151,6 +151,10 @@ namespace ipl { BOOL is_terminated(); BOOL is_working(); +#ifdef IPL_SD_CHANNEL_SELECT_CPP + void requestCancel() { unk_0x04 = true; } +#endif + WIISaveBannerFile* get_cached_nand_save_banner(ESTitleId titleId); void* get_cached_nand_app_thumbnail(ESTitleId titleId, u32*); WIISaveBannerFile* get_cached_sd_save_banner(ESTitleId32 titleId); diff --git a/include/system/iplSaveDataManager.h b/include/system/iplSaveDataManager.h index 4ede525a..151ea485 100644 --- a/include/system/iplSaveDataManager.h +++ b/include/system/iplSaveDataManager.h @@ -15,6 +15,11 @@ #define SAVEDATA_VERSION 3 namespace ipl { +#ifdef IPL_SD_CHANNEL_SELECT_ACCESS + namespace scene { + class SDChannelSelect; + } +#endif namespace channel { class Manager; } @@ -54,6 +59,7 @@ namespace ipl { int getLastSDPrevPage() { return mLastSDPrevPage; } void setLastSDPrevPage(int page) { mLastSDPrevPage = page; } BOOL didntGotoSDMenu() const { return mData.didntGotoSDMenu; } + void setDidntGotoSDMenu(BOOL value) { mData.didntGotoSDMenu = value; } #endif bool hasPhotoMP3Dummy() { return mbPhotoMP3; } @@ -68,6 +74,9 @@ namespace ipl { void iplSavedata_813596B8(ESTitleId titleId); private: +#ifdef IPL_SD_CHANNEL_SELECT_ACCESS + friend class ipl::scene::SDChannelSelect; +#endif BOOL checkValidApp(ESTitleId titleId); static void initManagerTask(void* work); diff --git a/libs/NW4R/include/nw4r/math/types.h b/libs/NW4R/include/nw4r/math/types.h index 08e9515f..489a0b06 100644 --- a/libs/NW4R/include/nw4r/math/types.h +++ b/libs/NW4R/include/nw4r/math/types.h @@ -157,11 +157,15 @@ namespace nw4r { y = pF[1]; z = pF[2]; } +#if defined(IPL_SD_CHANNEL_SELECT_CPP) + VEC3(f32 fx, f32 fy, f32 fz); +#else VEC3(f32 fx, f32 fy, f32 fz) { x = fx; y = fy; z = fz; } +#endif operator Vec*() { return reinterpret_cast(this); } operator const Vec*() const { return reinterpret_cast(this); } diff --git a/src/scene/sdChannelSelect/iplSDChannelSelect.cpp b/src/scene/sdChannelSelect/iplSDChannelSelect.cpp index 678f43af..218d0044 100644 --- a/src/scene/sdChannelSelect/iplSDChannelSelect.cpp +++ b/src/scene/sdChannelSelect/iplSDChannelSelect.cpp @@ -15,16 +15,28 @@ #include namespace ipl { - namespace scene { + namespace scene { namespace { + class SDChannelSelectEventHandler : public ::gui::EventHandler { + public: + explicit SDChannelSelectEventHandler(SDChannelSelect* scene) + : mpScene(scene) { + } + + void onEvent(u32 compId, u32 event, void* data) override; + + private: + SDChannelSelect* mpScene; + }; + class SDChannelSelectButtonEventHandler : public SDButtonEventHandlerBase { public: explicit SDChannelSelectButtonEventHandler(SDChannelSelect* scene) : mpScene(scene) { } - void onEventDerived(u32 compId, u32 event, const controller::Interface* con) override { - } + void onEventDerived(u32 compId, u32 event, + const controller::Interface* con) override; private: SDChannelSelect* mpScene; @@ -65,6 +77,19 @@ namespace ipl { "Edge0", "Edge1", "Edge2", "Edge3", "Edge4", }; + static DialogWindow::Page sFourPageDialogPages[4] = { + {0x9d, 0xa3, 0xa5, FALSE, NULL, 0.0f, FALSE}, + {0x9e, 0xa3, 0xa5, TRUE, NULL, 0.0f, FALSE}, + {0x9f, 0xa3, 0xa5, TRUE, NULL, 74.0f, TRUE}, + {0xca, 0xa4, 0xa5, TRUE, NULL, 108.0f, FALSE}, + }; + + static DialogWindow::Page sThreePageDialogPages[3] = { + {0xc9, 0xa3, 0xa5, TRUE, NULL, 0.0f, FALSE}, + {0x9e, 0xa3, 0xa5, TRUE, NULL, 0.0f, FALSE}, + {0x9f, 0xa4, 0xa5, TRUE, NULL, 74.0f, TRUE}, + }; + const char* SDChannelSelect::mscClockPaneNames[3] = { "N_Clock0", "N_Clock1", "N_Clock2", }; @@ -80,6 +105,39 @@ namespace ipl { 11, 7, 3, 10, 6, 2, 9, 5, 1, 8, 4, 0, }; + void SDChannelSelect::onButtonEvent(const char* paneName, u32 event, + const controller::Interface* controller) { + if (controller != NULL && + controller != System::getControllerManager()->getController(mControllerChannel)) { + return; + } + + switch (event) { + case ::gui::EventHandler::ON_LEFT: + if (strcmp(paneName, SDButton::smButtonName[SDButton::BTN_ARROW_LEFT]) == 0) { + if (mCurrentPage > 0) { + mPendingIndex = -1; + } + } else if (strcmp(paneName, SDButton::smButtonName[SDButton::BTN_ARROW_RIGHT]) == 0) { + if (mCurrentPage < mPageCount - 1) { + mPendingPage = -1; + } + } + break; + case ::gui::EventHandler::ON_POINT: + if (strcmp(paneName, SDButton::smButtonName[SDButton::BTN_ARROW_LEFT]) == 0) { + if (mCurrentPage > 0 && mPendingIndex < 0) { + mPendingIndex = 0; + } + } else if (strcmp(paneName, SDButton::smButtonName[SDButton::BTN_ARROW_RIGHT]) == 0) { + if (mCurrentPage < mPageCount - 1 && mPendingPage < 0) { + mPendingPage = 0; + } + } + break; + } + } + SDChannelSelect::SDChannelSelect(EGG::Heap* heap) : FaderSceneBase(heap), mpButtonEventHandler(new SDChannelSelectButtonEventHandler(this)), @@ -114,25 +172,29 @@ namespace ipl { mbChannelLimitReached(false), mbInitialLoadComplete(false), mbNeedsRefresh(false) { - mCurrentPage = System::getSaveData()->getLastSDPrevPage(); mPageCount = 20; + mCurrentPage = System::getSaveData()->getLastSDPrevPage(); mCurrentChannelIndex = 0; - mbLeftArrowVisible = mCurrentPage != 0; - mbRightArrowVisible = mCurrentPage != mPageCount - 1; + if (mCurrentPage == 0) { + mbLeftArrowVisible = false; + } else { + mbLeftArrowVisible = true; + } + if (mCurrentPage == mPageCount - 1) { + mbRightArrowVisible = false; + } else { + mbRightArrowVisible = true; + } setSceneParentFlags(SCN_PARENTFLAG_DRAW | SCN_PARENTFLAG_CALC); - math::VEC3 position(0.0f, 0.0f, 0.0f); - mPosition = position; - math::VEC2 scale(1.0f, 1.0f); - mScale = scale; + mPosition = math::VEC3(0.0f, 0.0f, 0.0f); + mScale = math::VEC2(1.0f, 1.0f); nw4r::ut::Rect projection4x3; System::getProjectionRect4x3(&projection4x3); nw4r::ut::Rect projection16x9; System::getProjectionRect16x9(&projection16x9); f32 aspectScale = projection16x9.GetWidth() / projection4x3.GetWidth(); - if (SCGetAspectRatio() != SC_ASPECT_RATIO_16x9) { - aspectScale = 1.0f; - } + aspectScale = SCGetAspectRatio() == SC_ASPECT_RATIO_16x9 ? aspectScale : 1.0f; mAspectRatioScale = aspectScale; memset(&mPointerPosition, 0, 0x30); @@ -145,7 +207,8 @@ namespace ipl { createChannelList(mCurrentPage, true); TVRCManager::getHandle()->setEnable(TRUE); - mpChannelTitleIds = (u32*)new (System::getMem2App(), 32) u8[mPageCount * 0x30]; + mpChannelTitleIds = new (System::getMem2App(), 32) + u32[mPageCount * MAX_CHANNEL_INDEX]; memset(mpChannelTitleIds, 0, mPageCount * 0x30); mpSDTitleInfo = new (System::getMem2App(), 32) SDChannelSelectTitleInfo[0x4B00 / sizeof(SDChannelSelectTitleInfo)]; @@ -192,9 +255,8 @@ namespace ipl { void SDChannelSelect::create() { mpSDWorker = new (System::getMem2App(), 4) NandSDWorker(); mpWorkerHeap = (EGG::Heap*)System::getMem2App()->alloc(0x3EA60, 0x40); - u32 thumbnailHeapSize = MEMCalcHeapSizeForUnitHeap(0x19620, 0x60, 0x20); mpThumbnailWorkHeap = (EGG::Heap*)System::getMem2App()->alloc( - thumbnailHeapSize + 0x40000, 0x40); + MEMCalcHeapSizeForUnitHeap(0x19620, 0x60, 0x20) + 0x40000, 0x40); mpSDWorker->create(mpWorkerHeap, NULL, mpThumbnailWorkHeap, 0x12); if (System::getSaveData()->didntGotoSDMenu() == FALSE) { @@ -204,7 +266,7 @@ namespace ipl { mpDialogHeap = EGG::ExpHeap::create(0x21100, getSceneHeap(), 6); mpChannelHeap = EGG::ExpHeap::create(0x2C100, getSceneHeap(), 6); - mpRsoHeap = EGG::ExpHeap::create(TVRCManager::getHandle(), 0x200000, 0); + mpRsoHeap = EGG::ExpHeap::create(System::getChannelArena(), 0x200000, 0); mpRsoThread = new (System::getMem2App(), 32) channel::RsoThread(mpRsoHeap); createBaseLayout(); @@ -214,8 +276,8 @@ namespace ipl { if (mCurrentPage > 0) { createChannelList(mCurrentPage - 1, false); } - updateNoCardLayouts(); - createChannelThumbnails(); + updateChannelObjects(); + createSceneLayouts(); u32 startTick = OSGetTick(); while (System::getBS2Manager()->getIPLState() != 8) { @@ -234,9 +296,9 @@ namespace ipl { void SDChannelSelect::enqueueStartNotice() { SDChannelSelectCommand command; command.type = 1; - command.titleId = 0; command.arguments.values[0] = 0; command.arguments.values[1] = 0; + command.titleId = 0; command.arguments.values[2] = 0; mCommandQueue.push(command); } @@ -244,9 +306,9 @@ namespace ipl { bool SDChannelSelect::enqueueFinishNotice() { SDChannelSelectCommand command; command.type = 2; - command.titleId = 0; command.arguments.values[0] = 0; command.arguments.values[1] = 0; + command.titleId = 0; command.arguments.values[2] = 0; mCommandQueue.push(command); return true; @@ -257,13 +319,13 @@ namespace ipl { return false; } + SDChannelSelectCommand notice; + notice.type = 4; + notice.arguments.values[0] = argument0; + notice.arguments.values[1] = argument1; + notice.titleId = titleId; + notice.arguments.values[2] = 0; if (mNoticeQueue.capacity != mNoticeQueue.count) { - SDChannelSelectCommand notice; - notice.type = 4; - notice.titleId = titleId; - notice.arguments.values[0] = argument0; - notice.arguments.values[1] = argument1; - notice.arguments.values[2] = 0; mNoticeQueue.notices[mNoticeQueue.writeIndex].copyFrom(notice); ++mNoticeQueue.writeIndex; if (mNoticeQueue.writeIndex >= mNoticeQueue.capacity) { @@ -281,9 +343,9 @@ namespace ipl { SDChannelSelectCommand command; command.type = 8; - command.titleId = 0; command.arguments.values[0] = 0; command.arguments.values[1] = 0; + command.titleId = 0; command.arguments.values[2] = 0; mCommandQueue.push(command); return true; @@ -296,9 +358,9 @@ namespace ipl { SDChannelSelectCommand command; command.type = 9; - command.titleId = 0; command.arguments.values[0] = 0; command.arguments.values[1] = 0; + command.titleId = 0; command.arguments.values[2] = 0; mCommandQueue.push(command); return true; @@ -311,9 +373,9 @@ namespace ipl { SDChannelSelectCommand command; command.type = 5; - command.titleId = result; command.arguments.values[0] = 0; command.arguments.values[1] = 0; + command.titleId = result; command.arguments.values[2] = 0; mCommandQueue.push(command); return true; @@ -326,9 +388,9 @@ namespace ipl { SDChannelSelectCommand command; command.type = 10; - command.titleId = ((u64)page << 32) | index; command.arguments.values[0] = value; command.arguments.values[1] = (u32)&mFirstTitleCount; + command.titleId = ((u64)page << 32) | index; command.arguments.values[2] = 0; mCommandQueue.push(command); return true; @@ -341,9 +403,9 @@ namespace ipl { SDChannelSelectCommand command; command.type = 6; - command.titleId = ((u64)page << 32) | index; command.arguments.values[0] = 0; command.arguments.values[1] = 0; + command.titleId = ((u64)page << 32) | index; command.arguments.values[2] = 0; mCommandQueue.push(command); return true; @@ -356,9 +418,9 @@ namespace ipl { SDChannelSelectCommand command; command.type = 7; - command.titleId = ((u64)page << 32) | index; command.arguments.values[0] = state; command.arguments.values[1] = 0; + command.titleId = ((u64)page << 32) | index; command.arguments.values[2] = 0; mCommandQueue.push(command); return true; @@ -371,9 +433,9 @@ namespace ipl { SDChannelSelectCommand command; command.type = 11; - command.titleId = 0; command.arguments.values[0] = page; command.arguments.values[1] = index; + command.titleId = 0; command.arguments.values[2] = 0; mCommandQueue.push(command); return true; @@ -385,11 +447,11 @@ namespace ipl { } SDChannelSelectCommand command; - command.type = 12; - command.titleId = 0; command.arguments.values[0] = page; + command.type = 12; command.arguments.values[1] = index; command.arguments.values[2] = commandType; + command.titleId = 0; mCommandQueue.push(command); return true; } @@ -401,10 +463,10 @@ namespace ipl { SDChannelSelectCommand command; command.type = 13; - command.titleId = ((u64)page << 32) | index; command.arguments.values[0] = 0; command.arguments.values[1] = 0; command.arguments.values[2] = 0; + command.titleId = ((u64)page << 32) | index; mCommandQueue.push(command); return true; } @@ -554,167 +616,261 @@ namespace ipl { return; } - if (OSGetTime() - mOperationStartTime >= OS_TIMER_CLOCK) { - setDialogMessage(1, 0); - int result = mpSDWorker->get_async_result(); - if (result == NandSDWorker::RESULT_OK || - result == NandSDWorker::RESULT_SD_APP_LOC_NOT_FOUND) { - for (int channelIndex = 0; channelIndex < mPageCount * 12; - ++channelIndex) { - if (mpChannelTitleIds[channelIndex] != 0) { - SDChannelSelectTitleInfo* info = - static_cast( - bsearch(mpChannelTitleIds + channelIndex, mpSDTitleInfo, - mSDTitleCount, sizeof(SDChannelSelectTitleInfo), - compareTitleInfo)); - if (info != NULL) { - info->used = true; - } else { - mpChannelTitleIds[channelIndex] = 0; - } + if (OSGetTime() - mOperationStartTime < OS_TIMER_CLOCK) { + return; + } + setDialogMessage(1, 0); + int result = mpSDWorker->get_async_result(); + if (result == NandSDWorker::RESULT_OK || + result == NandSDWorker::RESULT_SD_APP_LOC_NOT_FOUND) { + for (int channelIndex = 0; channelIndex < mPageCount * 12; + ++channelIndex) { + if (mpChannelTitleIds[channelIndex] != 0) { + SDChannelSelectTitleInfo* info = + static_cast( + bsearch(mpChannelTitleIds + channelIndex, mpSDTitleInfo, + mSDTitleCount, sizeof(SDChannelSelectTitleInfo), + compareTitleInfo)); + if (info != NULL) { + info->used = true; + } else { + mpChannelTitleIds[channelIndex] = 0; } } + } - int channelIndex = 0; - u32 titleIndex = 0; - bool addedTitle = false; - for (; channelIndex < mPageCount * 12; ++channelIndex) { - if (mpChannelTitleIds[channelIndex] == 0) { - if (titleIndex == mSDTitleCount) { - break; - } + int channelIndex = 0; + u32 titleIndex = 0; + bool addedTitle = false; + for (; channelIndex < mPageCount * 12; ++channelIndex) { + if (mpChannelTitleIds[channelIndex] == 0) { + if (titleIndex == mSDTitleCount) { + break; + } - for (; titleIndex < mSDTitleCount; ++titleIndex) { - SDChannelSelectTitleInfo* info = &mpSDTitleInfo[titleIndex]; - if (!info->used && info->titleId != 0x48415A41) { - mpChannelTitleIds[channelIndex] = info->titleId; - addedTitle = true; - ++titleIndex; - break; - } + for (; titleIndex < mSDTitleCount; ++titleIndex) { + SDChannelSelectTitleInfo* info = &mpSDTitleInfo[titleIndex]; + if (info->used) { + continue; } + if (info->titleId == 0x48415A41) { + continue; + } + mpChannelTitleIds[channelIndex] = info->titleId; + addedTitle = true; + ++titleIndex; + break; } } + } - if (addedTitle || result == NandSDWorker::RESULT_SD_APP_LOC_NOT_FOUND) { - enqueueLoadNotice(); - } - } else { - int channelCount = 0; - int channelIndex = 0; - u32 titleIndex = 0; - for (; titleIndex < mSDTitleCount; ++titleIndex) { - u32 titleId = mpSDTitleInfo[titleIndex].titleId; - if (titleId != 0x48415A41) { - ++channelCount; - mpChannelTitleIds[channelIndex++] = titleId; - if (channelCount == mPageCount * 12) { - break; - } - } - } + if (addedTitle || result == NandSDWorker::RESULT_SD_APP_LOC_NOT_FOUND) { enqueueLoadNotice(); } - - mWorkerCommand = 1; - mbNeedsRefresh = true; - u32 titleCount = mbHazardTitleFound ? mSDTitleCount - 1 : mSDTitleCount; - if (titleCount > static_cast(mPageCount * 12)) { - mbOperationActive = true; + } else { + int channelCount = 0; + int channelIndex = 0; + u32 titleIndex = 0; + for (; titleIndex < mSDTitleCount; ++titleIndex) { + u32 titleId = mpSDTitleInfo[titleIndex].titleId; + if (titleId != 0x48415A41) { + ++channelCount; + mpChannelTitleIds[channelIndex++] = titleId; + if (channelCount == mPageCount * 12) { + break; + } + } } - if (titleCount >= static_cast(mPageCount * 12)) { - mbSDCardBroken = true; - } - refreshAfterSDTitleList(); + enqueueLoadNotice(); } + + mWorkerCommand = 1; + mbNeedsRefresh = true; + u32 titleCount = mbHazardTitleFound ? mSDTitleCount - 1 : mSDTitleCount; + if (titleCount > static_cast(mPageCount * 12)) { + mbOperationActive = true; + } + if (titleCount >= static_cast(mPageCount * 12)) { + mbSDCardBroken = true; + } + refreshAfterSDTitleList(); } void SDChannelSelect::processWorkerCommands() { - if (mpSDWorker->is_working() || mWorkerState != 4) { - return; - } - - if (mCommandQueue.count == 0) { - if (mNoticeQueue.count > 0) { - mNoticeQueue.pop(); - } - return; - } - - SDChannelSelectCommand command = {0, 0, {{0, 0, 0}}}; - command.copyFrom(mCommandQueue.commands[mCommandQueue.readIndex]); - mLastOperation = command.type; - - switch (command.type) { + switch (mCurrentSDState) { case 1: - mpSDWorker->mount_sd_async(); - mWorkerCommand = 0; + case 3: + case 4: mbInitialLoadComplete = false; break; case 2: - mSDTitleCount = mpSDWorker->get_sd_app_num(); - mpSDWorker->list_sd_app_async(mpSDTitleIds); - mWorkerCommand = 2; - break; - case 5: - mpSDWorker->copy_sd_app_to_nand_async((ESTitleId32)command.titleId, true); - mWorkerCommand = 7; - break; - case 6: - mpSDWorker->copy_nand_app_to_sd_async((ESTitleId)command.titleId); - mWorkerCommand = 9; - break; - case 7: { - mpSDWorker->delete_nand_app_async((ESTitleId)command.titleId, - command.arguments.values[2] != 0); - mWorkerCommand = 10; - u32 index = 0; - while (index < mNandTitleCount && - mpNandTitleInfo[index].curTitleId != command.titleId) { - ++index; - } - if (index < mNandTitleCount) { - for (; index + 1 < mNandTitleCount; ++index) { - mpNandTitleInfo[index] = mpNandTitleInfo[index + 1]; - } - --mNandTitleCount; - } - break; - } - case 8: - mpSDWorker->update_sd_app_location_async(mpChannelTitleIds); - mWorkerCommand = 4; - break; - case 9: - mpSDWorker->read_sd_app_location_async(mpChannelTitleIds); - mWorkerCommand = 5; - break; - case 10: - mpSDWorker->check_for_sd_app_to_nand_async( - (ESTitleId)command.titleId, - command.arguments.appBlocks[0], command.arguments.appBlocks[1]); - mWorkerCommand = 8; - break; - case 11: - mpSDWorker->check_backup_fits_async( - command.arguments.titleLists[0], command.arguments.titleLists[1]); - mWorkerCommand = 11; - break; - case 12: - mpSDWorker->iplNandSD_81348EA8( - command.arguments.pointers[0], command.arguments.pointers[1], - command.arguments.pointers[2]); - mWorkerCommand = 12; - break; - case 13: - mpSDWorker->delete_sd_app_async((ESTitleId32)command.titleId); - mWorkerCommand = 13; + clearCommandQueue(); + clearNoticeQueue(); break; default: break; } - mCommandQueue.pop(); + if (mState < 8) { + if (mState == 1) { + } else if (mState >= 1) { + goto process_worker; + } else if (mState >= 0) { + goto process_worker; + } + } else { + if (mState >= 15) { + } else if (mState >= 12) { + goto process_worker; + } + } + if (mCurrentSDState < 5 && mCurrentSDState >= 1 && mDialogState == 0) { + mSourcePage = -1; + mSourceIndex = -1; + mbShowNoCardMessage = true; + refreshChannelList(); + memset(mpChannelTitleIds, 0, mPageCount * 0x30); + memset(mpSDTitleInfo, 0, 0x4b00); + mSDTitleCount = 0; + mbOperationActive = false; + mbHazardTitleFound = false; + mbChannelLimitReached = false; + mbSDCardBroken = false; + mbNeedsRefresh = false; + + switch (mCurrentSDState) { + case 1: + setDialogMessage(2, 0xa9); + mWorkerCommand = 6; + break; + case 2: + if (!mbInitialLoadComplete) { + setDialogMessage(8, 0xaa); + } + mbInitialLoadComplete = true; + enqueueStartNotice(); + enqueueFinishNotice(); + break; + case 3: + case 4: + setDialogMessage(2, 0xab); + mWorkerCommand = 15; + break; + default: + break; + } + } + + process_worker: + if (mpSDWorker->is_working() || mWorkerState != 4) { + return; + } + + if (mCommandQueue.count > 0) { + SDChannelSelectCommand command = + mCommandQueue.commands[mCommandQueue.readIndex]; + + switch (command.type) { + case 1: + mpSDWorker->mount_sd_async(); + mWorkerCommand = 0; + mbInitialLoadComplete = false; + break; + case 2: + mSDTitleCount = mpSDWorker->get_sd_app_num(); + mpSDWorker->list_sd_app_async(mpSDTitleIds); + mWorkerCommand = 2; + break; + case 5: + mpSDWorker->copy_sd_app_to_nand_async( + static_cast(command.titleId), true); + mWorkerCommand = 7; + break; + case 6: + mpSDWorker->copy_nand_app_to_sd_async( + static_cast(command.titleId)); + mWorkerCommand = 9; + break; + case 7: { + mpSDWorker->delete_nand_app_async( + static_cast(command.titleId), + command.arguments.values[2] != 0); + mWorkerCommand = 10; + u32 index = 0; + if (mNandTitleCount > 0) { + do { + if (mpNandTitleInfo[index].curTitleId == command.titleId) { + break; + } + ++index; + } while (index < mNandTitleCount); + } + if (index < mNandTitleCount) { + for (; index + 1 < mNandTitleCount; ++index) { + mpNandTitleInfo[index] = mpNandTitleInfo[index + 1]; + } + --mNandTitleCount; + } + break; + } + case 8: + mpSDWorker->update_sd_app_location_async(mpChannelTitleIds); + mWorkerCommand = 4; + break; + case 9: + mpSDWorker->read_sd_app_location_async(mpChannelTitleIds); + mWorkerCommand = 5; + break; + case 10: + mpSDWorker->check_for_sd_app_to_nand_async( + static_cast(command.titleId), + command.arguments.appBlocks[0], command.arguments.appBlocks[1]); + mWorkerCommand = 8; + break; + case 11: + mpSDWorker->check_backup_fits_async( + command.arguments.titleLists[0], command.arguments.titleLists[1]); + mWorkerCommand = 11; + break; + case 12: + mpSDWorker->iplNandSD_81348EA8( + command.arguments.pointers[0], command.arguments.pointers[1], + command.arguments.pointers[2]); + mWorkerCommand = 12; + break; + case 13: + mpSDWorker->delete_sd_app_async( + static_cast(command.titleId)); + mWorkerCommand = 13; + break; + default: + break; + } + + mLastOperation = command.type; + mCommandQueue.pop(); + } else if (mNoticeQueue.count > 0) { + SDChannelSelectCommand notice = + mNoticeQueue.notices[mNoticeQueue.readIndex]; + SDChannelObj* channel = findChannelObject( + notice.arguments.values[1], notice.arguments.values[2]); + if (channel != NULL && channel->mStateFlags >= 1 && + channel->mStateFlags <= 2) { + EGG::FrmHeap* objectHeap = EGG::FrmHeap::create( + 0x212b8, mpLayoutHeap, 2); + SDChannelObj* loadedChannel = + new (mpThumbnailHeap, 4) SDChannelObj( + objectHeap, notice.arguments.values[1], + notice.arguments.values[2]); + mpCurrentLoadedChannel = loadedChannel; + mpSDWorker->get_sd_app_meta_async( + notice.arguments.values[0], + static_cast(iplSDChannelObj_813E3128(loadedChannel)), + &loadedChannel->mAppMeta); + mWorkerCommand = 3; + } + mNoticeQueue.pop(); + } } void SDChannelSelect::handleSDMountComplete() { @@ -916,66 +1072,74 @@ namespace ipl { mPreviousSDState = mCurrentSDState; mCurrentSDState = mpSDWorker->get_sd_state(); - if (mWorkerState == 2) { + switch (mWorkerState) { + case 1: + handleWorkerStartup(); + break; + case 2: handleNandTitleCount(); - } else if (mWorkerState < 2) { - if (mWorkerState > 0) { - handleWorkerStartup(); - } - } else if (mWorkerState < 4) { + break; + case 3: handleNandTitleUsage(); + break; } switch (mWorkerCommand) { case 0: - handleNandTitleUsageComplete(); + processWorkerCommands(); break; case 1: - processWorkerCommands(); + handleNandTitleUsageComplete(); break; case 2: handleSDTitleList(); break; case 3: - handleSDChannelUpdateComplete(); - break; - case 4: handleSDMountComplete(); break; + case 4: + handleSDTitleListResult(); + break; case 5: - handleDeleteComplete(); + handleSDChannelUpdateComplete(); break; case 6: - handleSDCardReady(); - break; - case 7: handleCopyComplete(); break; - case 8: + case 7: handleSDLocationUpdateComplete(); break; - case 9: + case 8: handleSDLocationReadComplete(); break; - case 10: + case 9: handleMoveComplete(); break; - case 11: + case 10: handleBackupFitComplete(); break; - case 12: + case 11: handleNandSDCleanupComplete(); break; - case 13: + case 12: handleSDDeleteComplete(); break; - case 15: + case 13: + handleSDCardReady(); + break; + case 14: handleCardCommand(); break; + case 15: + break; } - if (mCurrentSDState != 6 && mState > 14 && mState < 24) { - mbDialogActive = true; + if (mCurrentSDState != 6) { + if (mState < 24) { + if (mState >= 15) { + mbDialogActive = true; + } + } } updateDialogAnimation(); @@ -1007,13 +1171,17 @@ namespace ipl { break; } - if (mDialogState == 0) { - if (mOperationState == 10) { + switch (mDialogState) { + case 0: + if (mOperationState != 10) { + if (mOperationState < 10 && mOperationState == 7) { + mOperationState = 8; + } + } else { mOperationState = 14; - } else if (mOperationState < 10 && mOperationState == 7) { - mOperationState = 8; } - } else if (mDialogState == 2) { + break; + case 2: switch (mOperationState) { case 0: case 1: @@ -1041,30 +1209,30 @@ namespace ipl { mOperationState = 11; break; } - } else if (mDialogState < 2) { - if (mDialogState > 0) { - switch (mOperationState) { - case 0: - case 1: - case 2: - case 7: - case 8: - case 13: - mOperationState = 1; - mDialogState = 0; - mAnimationState = mAnimationTarget; - break; - case 4: - mOperationState = 5; - break; - case 10: - case 14: - case 15: - mOperationState = 11; - break; - } + break; + case 1: + switch (mOperationState) { + case 0: + case 1: + case 2: + case 7: + case 8: + case 13: + mOperationState = 1; + mDialogState = 0; + mAnimationState = mAnimationTarget; + break; + case 4: + mOperationState = 5; + break; + case 10: + case 14: + case 15: + mOperationState = 11; + break; } - } else if (mDialogState == 8) { + break; + case 8: switch (mOperationState) { case 0: case 1: @@ -1092,6 +1260,9 @@ namespace ipl { } break; } + break; + default: + break; } layout::Animator* animator = NULL; @@ -1126,6 +1297,375 @@ namespace ipl { } } + bool SDChannelSelect::isCurrentTitleUsageEnough(const s32* usage) const { + s32 blocks = mSecondTitleCount; + s32 bytes = mFirstTitleCount; + ESTitleId currentTitleId = SCGetTmpTitleID(); + + u32 titleCount = mNandTitleCount; + u32 index; + for (index = 0; index < titleCount; ++index) { + if (mpNandTitleInfo[index].curTitleId == currentTitleId) { + break; + } + } + if (index < titleCount) { + bytes += mpNandTitleInfo[index].size; + blocks += mpNandTitleInfo[index].inode; + } + + return bytes >= usage[0] && blocks >= usage[1]; + } + + void SDChannelSelect::getCurrentTitleUsage(s32* bytes, s32* blocks) const { + *bytes = mFirstTitleCount; + *blocks = mSecondTitleCount; + ESTitleId currentTitleId = SCGetTmpTitleID(); + + u32 titleCount = mNandTitleCount; + u32 index; + for (index = 0; index < titleCount; ++index) { + if (mpNandTitleInfo[index].curTitleId == currentTitleId) { + break; + } + } + if (index < titleCount) { + *bytes += mpNandTitleInfo[index].size; + *blocks += mpNandTitleInfo[index].inode; + } + } + + bool SDChannelSelect::collectTitlesByUsage( + const s32* firstUsage, const s32* secondUsage, ESTitleId* titleIds, + char* titleNames, u32* titleCount) { + s32 bytes; + s32 blocks; + getCurrentTitleUsage(&bytes, &blocks); + *titleCount = 0; + + for (u32 index = 0; index < mNandTitleCount; ++index) { + if (mpNandTitleInfo[index].curTitleId != 0x48415A41) { + int page; + int channelIndex; + if (System::getChannelManager()->hasChannel( + mpNandTitleInfo[index].curTitleId, &page, &channelIndex) != 0) { + bytes += mpNandTitleInfo[index].size; + blocks += mpNandTitleInfo[index].inode; + titleIds[*titleCount] = mpNandTitleInfo[index].curTitleId; + wchar_t* titleName = System::getChannelManager()->getTitleName( + page, channelIndex, 0); + memcpy(titleNames + *titleCount * 0x2a, titleName, 0x2a); + u32 nextTitleCount = *titleCount + 1; + *titleCount = nextTitleCount; + + if (bytes < secondUsage[0] || blocks < secondUsage[1]) { + continue; + } + return true; + } + } + } + + if (bytes >= firstUsage[0] && blocks >= firstUsage[1]) { + return true; + } + return false; + } + + bool SDChannelSelect::collectTitlesFromNandUsage( + const s32* firstUsage, const s32* secondUsage, + ESTitleId* titleIds, char* titleNames, u32* titleCount) { + s32 bytes; + s32 blocks; + getCurrentTitleUsage(&bytes, &blocks); + *titleCount = 0; + + for (int index = mNandTitleCount - 1; index >= 0; --index) { + if (mpNandTitleInfo[index].curTitleId == 0x48415A41) { + continue; + } + + int page; + int channelIndex; + if (System::getChannelManager()->hasChannel( + mpNandTitleInfo[index].curTitleId, &page, &channelIndex) == 0) { + continue; + } + + bytes += mpNandTitleInfo[index].size; + blocks += mpNandTitleInfo[index].inode; + titleIds[*titleCount] = mpNandTitleInfo[index].curTitleId; + wchar_t* titleName = System::getChannelManager()->getTitleName( + page, channelIndex, 0); + memcpy(titleNames + *titleCount * 0x2a, titleName, 0x2a); + ++*titleCount; + + if (bytes >= secondUsage[0] && blocks >= secondUsage[1]) { + return true; + } + } + + if (bytes >= firstUsage[0] && blocks >= firstUsage[1]) { + return true; + } + return false; + } + + bool SDChannelSelect::findAdjacentChannel(int direction, int* page, int* index) const { + int currentPage = mCurrentPage; + int currentIndex = mCurrentChannelIndex; + int pageSize = MAX_CHANNEL_INDEX; + int currentSlot = currentPage * pageSize + currentIndex; + int step = direction == 1 ? -1 : 1; + int slotCount = mPageCount * pageSize; + int slot = currentSlot + step; + + if (slot < 0) { + slot = slotCount - 1; + } + if (slot >= slotCount) { + slot = 0; + } + + while (slot != currentSlot) { + int candidatePage = slot / pageSize; + int candidateIndex = slot % pageSize; + if (mpChannelTitleIds[slot] != 0) { + *page = candidatePage; + *index = candidateIndex; + return true; + } + + slot += step; + if (slot < 0) { + slot = slotCount - 1; + } + if (slot >= slotCount) { + slot = 0; + } + } + + *page = currentPage; + *index = currentIndex; + return false; + } + + extern "C" bool iplSDChannelSelect_813DD240( + SDChannelSelect* scene, const s32* requiredBytes, const s32* requiredBlocks, + ESTitleId* titleIds, char* titleNames, u32* titleCount); + + bool SDChannelSelect::collectTitlesByChannelOrder( + const s32* firstUsage, const s32* secondUsage, ESTitleId* titleIds, + char* titleNames, u32* titleCount) { + static const int channelOrder[MAX_CHANNEL_INDEX] = { + 11, 7, 3, 10, 6, 2, 9, 5, 1, 8, 4, 0, + }; + s32 bytes; + s32 blocks; + getCurrentTitleUsage(&bytes, &blocks); + *titleCount = 0; + + for (int page = MAX_CHANNEL_PAGE - 1; page >= 0; --page) { + for (int order = 0; order < MAX_CHANNEL_INDEX; ++order) { + int channelIndex = channelOrder[order]; + if (!System::getChannelManager()->mChannels[page][channelIndex].loadedBnr) { + continue; + } + + ESTitleId titleId = ES_TITLE_ID( + System::getChannelManager()->mChannels[page][channelIndex].info.titleType, + System::getChannelManager()->mChannels[page][channelIndex].info.titleCode); + if (titleId == 0 || titleId == 0x48415A41) { + continue; + } + + for (u32 usageIndex = 0; usageIndex < mNandTitleCount; ++usageIndex) { + NandSDWorker::TitleUsage& usage = mpNandTitleInfo[usageIndex]; + if (usage.curTitleId != titleId) { + continue; + } + + bytes += usage.size; + blocks += usage.inode; + titleIds[*titleCount] = titleId; + wchar_t* titleName = + System::getChannelManager()->getTitleName(page, channelIndex, 0); + memcpy(titleNames + *titleCount * 0x2a, titleName, 0x2a); + ++*titleCount; + + if (bytes >= secondUsage[0] && blocks >= secondUsage[1]) { + return true; + } + } + } + } + + if (bytes >= firstUsage[0] && blocks >= firstUsage[1]) { + return true; + } + return false; + } + + bool SDChannelSelect::collectTitlesBySpecialChannels( + const s32* firstUsage, const s32* secondUsage, ESTitleId* titleIds, + char* titleNames, u32* titleCount) { + const ESTitleId hateTitle = ES_TITLE_ID(0x00010001, 0x48415445); + const ESTitleId hadeTitle = ES_TITLE_ID(0x00010001, 0x48414445); + const ESTitleId hazardTitle = 0x48415A41; + int hateUsageIndex = -1; + int hatePage = 0; + int hateChannelIndex = 0; + int hadeUsageIndex = -1; + int hadePage = 0; + int hadeChannelIndex = 0; + s32 bytes; + s32 blocks; + getCurrentTitleUsage(&bytes, &blocks); + + for (u32 usageIndex = 0; usageIndex < mNandTitleCount; ++usageIndex) { + ESTitleId titleId = mpNandTitleInfo[usageIndex].curTitleId; + if (titleId == hateTitle) { + hateUsageIndex = usageIndex; + System::getChannelManager()->hasChannel( + hateTitle, &hatePage, &hateChannelIndex); + } else if (titleId == hadeTitle) { + hadeUsageIndex = usageIndex; + System::getChannelManager()->hasChannel( + hadeTitle, &hadePage, &hadeChannelIndex); + } + } + + *titleCount = 0; + for (int usageIndex = mNandTitleCount - 1; usageIndex >= 0; --usageIndex) { + NandSDWorker::TitleUsage& usage = mpNandTitleInfo[usageIndex]; + ESTitleId titleId = usage.curTitleId; + if (titleId == hazardTitle || titleId == hateTitle || titleId == hadeTitle) { + continue; + } + + int page; + int channelIndex; + if (System::getChannelManager()->hasChannel(titleId, &page, &channelIndex) == 0) { + continue; + } + if (iplSavedata_813597A0(System::getSaveData(), titleId) != FALSE) { + continue; + } + + bytes += usage.size; + blocks += usage.inode; + titleIds[*titleCount] = titleId; + wchar_t* titleName = System::getChannelManager()->getTitleName( + page, channelIndex, 0); + memcpy(titleNames + *titleCount * 0x2a, titleName, 0x2a); + ++*titleCount; + + if (bytes >= secondUsage[0] && blocks >= secondUsage[1]) { + return true; + } + } + + ESTitleId* cachedTitles = &System::getSaveData()->mData.titleCache[0][0]; + for (int cacheIndex = MAX_CHANNEL_TOTAL - 1; cacheIndex >= 0; --cacheIndex) { + ESTitleId titleId = cachedTitles[cacheIndex]; + int page; + int channelIndex; + if (System::getChannelManager()->hasChannel(titleId, &page, &channelIndex) == 0) { + continue; + } + + for (u32 usageIndex = 0; usageIndex < mNandTitleCount; ++usageIndex) { + NandSDWorker::TitleUsage& usage = mpNandTitleInfo[usageIndex]; + if (usage.curTitleId != titleId) { + continue; + } + + bytes += usage.size; + blocks += usage.inode; + titleIds[*titleCount] = titleId; + wchar_t* titleName = System::getChannelManager()->getTitleName( + page, channelIndex, 0); + memcpy(titleNames + *titleCount * 0x2a, titleName, 0x2a); + ++*titleCount; + + if (bytes >= secondUsage[0] && blocks >= secondUsage[1]) { + return true; + } + } + } + + if (hadeUsageIndex >= 0) { + NandSDWorker::TitleUsage& usage = mpNandTitleInfo[hadeUsageIndex]; + bytes += usage.size; + blocks += usage.inode; + titleIds[*titleCount] = hadeTitle; + wchar_t* titleName = + System::getChannelManager()->getTitleName( + hadePage, hadeChannelIndex, 0); + memcpy(titleNames + *titleCount * 0x2a, titleName, 0x2a); + ++*titleCount; + + if (bytes >= secondUsage[0] && blocks >= secondUsage[1]) { + return true; + } + } + + if (hateUsageIndex >= 0) { + NandSDWorker::TitleUsage& usage = mpNandTitleInfo[hateUsageIndex]; + bytes += usage.size; + blocks += usage.inode; + titleIds[*titleCount] = hateTitle; + wchar_t* titleName = + System::getChannelManager()->getTitleName( + hatePage, hateChannelIndex, 0); + memcpy(titleNames + *titleCount * 0x2a, titleName, 0x2a); + ++*titleCount; + + if (bytes >= secondUsage[0] && blocks >= secondUsage[1]) { + return true; + } + } + + if (bytes >= firstUsage[0] && blocks >= firstUsage[1]) { + return true; + } + return false; + } + + bool SDChannelSelect::collectTitlesForMode( + const s32* requiredBytes, const s32* requiredBlocks, + ESTitleId* titleIds, char* titleNames, u32* titleCount, int searchMode) { + switch (searchMode) { + case 0: + return collectTitlesBySpecialChannels( + requiredBytes, requiredBlocks, titleIds, titleNames, titleCount); + case 1: + return collectTitlesByChannelOrder( + requiredBytes, requiredBlocks, titleIds, titleNames, titleCount); + case 2: + return collectTitlesFromNandUsage( + requiredBytes, requiredBlocks, titleIds, titleNames, titleCount); + case 3: + return collectTitlesByUsage( + requiredBytes, requiredBlocks, titleIds, titleNames, titleCount); + default: + return false; + } + } + + void SDChannelSelect::finishDialogOperation() { + if (System::getDialog()->getLastResult() != DialogWindow::RESULT_NONE) { + mbOperationActive = false; + mState = 1; + } + } + + void SDChannelSelect::finishDialogTransition() { + if (System::getDialog()->getLastResult() != DialogWindow::RESULT_NONE) { + mState = 1; + } + } + void SDChannelSelect::updateChannelObjects() { SDChannelObj* channel = NULL; while (channel = static_cast(nw4r::ut::List_GetNext(&mChannelObjects, channel)), @@ -1151,6 +1691,61 @@ namespace ipl { } } + void SDChannelSelect::drawChannelTransitionObjects() { + int index; + int page; + SDChannelObj* channel = NULL; + while (channel = static_cast(nw4r::ut::List_GetNext(&mChannelObjects, channel)), + channel != NULL) { + page = channel->getPage(); + index = channel->getIndex(); + if (!hasChannelObject(page, index) || !isChannelReady(channel)) { + continue; + } + + setChannelScissor(channel); + iplSDChannelObj_813E32C8(channel); + + if (iplSDChannelObj_813E3330(channel)) { + if (mState < 24 && mState >= 15 && + (page != mSourcePage || index != mSourceIndex)) { + nw4r::math::VEC3 position(channel->getTranslate()); + mpPageLayouts[0]->GetRootPane()->SetTranslate(position); + mpPageLayouts[0]->calcMtx(); + mpPageLayouts[0]->draw(); + } + } else if (channel->mState == 2) { + nw4r::math::VEC3 position(channel->getTranslate()); + mpErrorLayout->GetRootPane()->SetTranslate(position); + mpErrorLayout->calcMtx(); + mpErrorLayout->draw(); + } + + switch (mState) { + case 15: + case 16: + case 19: + case 20: + case 21: + case 22: + case 23: + if (page == mSourcePage && index == mSourceIndex) { + nw4r::math::VEC3 position(channel->getTranslate()); + mpStateLayout->GetRootPane()->SetTranslate(position); + mpStateLayout->calcMtx(); + mpStateLayout->draw(); + } + break; + } + + if (mState < 22 && mState >= 19 && + page == mDestinationPage && index == mDestinationIndex) { + mpPageLayouts[2]->draw(); + mpPointerLayout->draw(); + } + } + } + void SDChannelSelect::drawChannelObjects() { SDChannelObj* channel = NULL; while (channel = static_cast(nw4r::ut::List_GetNext(&mChannelObjects, channel)), @@ -1170,24 +1765,31 @@ namespace ipl { } void SDChannelSelect::updateArrowVisibility() { - int leftPageOffset = (mState == 10 || mState == 22) ? 1 : 0; - int rightPageOffset = (mState == 11 || mState == 23) ? 1 : 0; - layout::Object* layout = mpLayout; - - if (mCurrentPage <= leftPageOffset) { - layout->hide(mscEdgePaneNames[0]); - layout->hide(mscEdgePaneNames[1]); + int leftPageOffset; + if (mState == 10 || mState == 22) { + leftPageOffset = 1; } else { - layout->show(mscEdgePaneNames[0]); - layout->show(mscEdgePaneNames[1]); + leftPageOffset = 0; } - if (mCurrentPage + rightPageOffset + 1 >= mPageCount) { - layout->hide(mscEdgePaneNames[3]); - layout->hide(mscEdgePaneNames[4]); + if (mCurrentPage - 1 - leftPageOffset >= 0) { + mpLayout->FindPaneByName(mscEdgePaneNames[0])->SetVisible(true); + mpLayout->FindPaneByName(mscEdgePaneNames[1])->SetVisible(true); } else { - layout->show(mscEdgePaneNames[3]); - layout->show(mscEdgePaneNames[4]); + mpLayout->FindPaneByName(mscEdgePaneNames[1 - leftPageOffset])->SetVisible(false); + } + + int rightPageOffset; + if (mState == 11 || mState == 23) { + rightPageOffset = 1; + } else { + rightPageOffset = 0; + } + if (mCurrentPage + rightPageOffset + 1 < mPageCount) { + mpLayout->FindPaneByName(mscEdgePaneNames[3])->SetVisible(true); + mpLayout->FindPaneByName(mscEdgePaneNames[4])->SetVisible(true); + } else { + mpLayout->FindPaneByName(mscEdgePaneNames[rightPageOffset + 3])->SetVisible(false); } } @@ -1201,16 +1803,16 @@ namespace ipl { if (button != NULL) { button->setEventHandler(mpButtonEventHandler, NULL); mState = 3; - if (mCurrentPage < 1) { - button->initArrowAppearance(1, false); - } else { + if (mCurrentPage > 0) { button->initArrowAppearance(1, true); + } else { + button->initArrowAppearance(1, false); } - if (mPageCount < 2 || mPageCount - 1 <= mCurrentPage) { - button->initArrowAppearance(0, false); - } else { + if (mPageCount > 1 && mCurrentPage < mPageCount - 1) { button->initArrowAppearance(0, true); + } else { + button->initArrowAppearance(0, false); } } } @@ -1230,13 +1832,122 @@ namespace ipl { mpPageLayouts[0]->calc(); mpPageLayouts[1]->calc(); mpPageLayouts[2]->calc(); - mpHelpButtonLayout->calc(); mpErrorLayout->calc(); + mpPointerLayout->calc(); mpStateLayout->calc(); mpNoCardLayout->calc(); processWorkerState(); } + extern "C" void iplSDChannelObj_813E3534(SDChannelObj* channel, int enabled); + + FaderSceneCommand SDChannelSelect::calcNormal() { + int state = mState; + if (state == 13) { + return FADER_SCN_CONTINUE; + } + + switch (state) { + case 0: + processNormalInput(); + break; + case 1: + setPageActionFrame(); + break; + case 2: + finishPageScroll(); + break; + case 3: + createChildScene(0x23, this, NULL, this); + mState = 6; + break; + case 4: + advancePageAnimation(); + break; + case 5: + mState = 13; + break; + case 6: + initializeNormalPage(); + break; + case 7: + updateDragState(); + break; + case 8: + updateDragPageTransition(); + break; + case 9: + finishDragWait(); + break; + case 10: + finishDragPageTransition(); + break; + case 11: + applyChannelMove(); + break; + case 12: + finishChannelMove(); + break; + case 13: + resetDragPreview(); + break; + case 14: + finishDragPageChange(); + break; + case 15: + handleFourPageDialog(); + break; + case 16: + flushSaveDataAndMountSD(); + break; + case 17: + handleThreePageDialog(); + break; + case 18: + finishCardDialog(); + break; + case 19: + finishDialogOperation(); + break; + case 20: + finishDialogTransition(); + break; + case 21: + case 22: + case 23: + case 24: + case 25: + case 26: + case 27: + case 28: + case 29: + default: + break; + } + + if (state == 1 && mState != 1 && mState != 15) { + SDChannelObj* channel = NULL; + while (channel = static_cast( + nw4r::ut::List_GetNext(&mChannelObjects, channel)), + channel != NULL) { + int channelPage = channel->getPage(); + int channelIndex = channel->getIndex(); + if (channelPage == mCurrentPage) { + if (mState != 5 || channelIndex != mCurrentChannelIndex) { + iplSDChannelObj_813E34E8(channel, 1); + } + iplSDChannelObj_813E3534(channel, 1); + } + } + + for (int index = 0; index < MAX_CHANNEL_INDEX; ++index) { + mpPaneManager->initPane(getChannelPane(index)); + } + } + + return mState == 4 ? FADER_SCN_NEXT : FADER_SCN_CONTINUE; + } + void SDChannelSelect::initCalcFadeout() { if (mState == 4) { clearCommandQueue(); @@ -1244,7 +1955,11 @@ namespace ipl { System::getFader()->fadeOut(); TVRCManager::getHandle()->setEnable(FALSE); System::getChannelManager()->refreshAsync(); - reserveAllSceneDestruction(4, NULL); + reserveAllSceneDestruction( + 4, System::isSafeMode() + ? NULL + : reinterpret_cast( + System::getNwc24ManagerForce()->received())); } } @@ -1257,58 +1972,62 @@ namespace ipl { } void SDChannelSelect::draw() { - bool onDrawLayer = System::onDrawLayer(DRAW_LAYER_DEFAULT); - if (mState == 13) { - if (onDrawLayer) { + if (mState != 13) { + if (System::onDrawLayer(DRAW_LAYER_DEFAULT)) { + if (mState == 7 || mState == 12 || mState == 14) { + utility::Graphics::setOrthoTransAndScale(mPosition, mScale); + } utility::Graphics::setOrtho(); - GXColor color = {0, 0, 0, 255}; - nw4r::ut::Rect projection; - System::getProjectionRect(&projection); - utility::Graphics::drawPolygon(projection, color); + + for (int edge = 0; edge < PAGE_COUNT; ++edge) { + nw4r::lyt::Pane* pane = mpLayout->FindPaneByName(mscBasePaneNames[edge]); + pane->SetVisible(true); + mpLayout->draw(pane); + pane->SetVisible(false); + } + + drawChannelTransitionObjects(); + updateArrowVisibility(); + + GXSetScissor(0, 0, System::getRenderModeObj()->fbWidth, + System::getRenderModeObj()->efbHeight); + + nw4r::lyt::Pane* mask = mpLayout->FindPaneByName(mscMaskPaneName); + mask->SetVisible(false); + mpLayout->draw(); + + nw4r::lyt::TextBox* pageText = nw4r::ut::DynamicCast( + mpDialogLayout->FindPaneByName("TextBox_00")); + for (int page = 0; page < 3; ++page) { + wchar_t pageNumber[21]; + pageNumber[20] = L'\0'; + swprintf(pageNumber, 19, L"%d", mCurrentPage + page); + pageText->SetString(pageNumber, 0); + nw4r::lyt::Pane* clockPane = mpLayout->FindPaneByName(mscClockPaneNames[page]); + nw4r::math::MTX34 paneMatrix = clockPane->GetGlobalMtx(); + nw4r::math::VEC3 position(0.0f, 0.0f, 0.0f); + PSMTXMultVec(paneMatrix, position, position); + mpDialogLayout->GetRootPane()->SetTranslate(position); + mpDialogLayout->calcMtx(); + mpDialogLayout->draw(); + } + + drawChannelObjects(); + mask->SetVisible(true); + mpLayout->draw(mask); + mpPageLayouts[1]->draw(); + mpNoCardLayout->draw(); + return; } - return; } - if (!onDrawLayer) { - return; + if (mState == 13 && System::onDrawLayer(DRAW_LAYER_DEFAULT)) { + utility::Graphics::setOrtho(); + GXColor color = {0, 0, 0, 255}; + nw4r::ut::Rect projection; + System::getProjectionRect(&projection); + utility::Graphics::drawPolygon(projection, color); } - - if (mState == 7 || mState == 12 || mState == 14) { - utility::Graphics::setOrthoTransAndScale(mPosition, mScale); - } - utility::Graphics::setOrtho(); - - for (int edge = 0; edge < PAGE_COUNT; ++edge) { - nw4r::lyt::Pane* pane = mpLayout->FindPaneByName(mscEdgePaneNames[edge]); - pane->SetVisible(true); - mpLayout->draw(pane); - pane->SetVisible(false); - } - - drawChannelObjects(); - updateArrowVisibility(); - - GXSetScissor(0, 0, System::getRenderModeObj()->fbWidth, - System::getRenderModeObj()->efbHeight); - - nw4r::lyt::Pane* mask = mpLayout->FindPaneByName(mscMaskPaneName); - mask->SetVisible(false); - mpLayout->draw(); - - nw4r::lyt::TextBox* pageText = static_cast( - mpDialogLayout->FindPaneByName("TextBox_00")); - for (int page = 0; page < 3; ++page) { - wchar_t pageNumber[20]; - swprintf(pageNumber, 19, L"%d", mCurrentPage + page); - pageText->SetString(pageNumber, 0); - mpDialogLayout->draw(); - } - - drawChannelObjects(); - mask->SetVisible(true); - mpLayout->draw(mask); - mpPageLayouts[1]->draw(); - mpNoCardLayout->draw(); } void SDChannelSelect::destroyChannelObject(SDChannelObj* channel) { @@ -1363,63 +2082,60 @@ namespace ipl { void SDChannelSelect::destroy() { System::getBS2Manager()->restart(); - System::getSaveData()->setLastSDPrevPage(mCurrentPage); SDChannelObj* channel = NULL; - while (channel = static_cast(nw4r::ut::List_GetNext(&mChannelObjects, channel)), + System::getSaveData()->setLastSDPrevPage(mCurrentPage); + + while (channel = static_cast(nw4r::ut::List_GetNext(&mChannelObjects, NULL)), channel != NULL) { nw4r::ut::List_Remove(&mChannelObjects, channel); destroyChannelObject(channel); } - if (mpRsoThread != NULL) { - delete mpRsoThread; - mpRsoThread = NULL; - } + mpLayoutHeap->destroy(); + mpThumbnailHeap->destroy(); + mpDialogHeap->destroy(); + mpChannelHeap->destroy(); - if (mpThumbnailHeap != NULL) { - mpThumbnailHeap->destroy(); - } - if (mpLayoutHeap != NULL) { - mpLayoutHeap->destroy(); - } - if (mpDialogHeap != NULL) { - mpDialogHeap->destroy(); - } - if (mpChannelHeap != NULL) { - mpChannelHeap->destroy(); - } + delete mpRsoThread; + mpRsoHeap->destroy(); if (mpSaveDataFile != NULL) { while (!System::getSaveData()->isFinished(mpSaveDataFile)) { - OSYieldThread(); + OSSleepTicks(OSMicrosecondsToTicks((OSTime)100)); } delete mpSaveDataFile; - mpSaveDataFile = NULL; } + mpSaveDataFile = NULL; if (mpSDWorker != NULL) { if (!mpSDWorker->is_terminated()) { - mpSDWorker->terminate_async(); + mpSDWorker->requestCancel(); while (mpSDWorker->is_working()) { - OSYieldThread(); + OSSleepTicks(OSMicrosecondsToTicks((OSTime)100)); } + mpSDWorker->terminate_async(); while (!mpSDWorker->is_terminated()) { - OSYieldThread(); + OSSleepTicks(OSMicrosecondsToTicks((OSTime)100)); } } - if (mpWorkerHeap != NULL) { - mpWorkerHeap->destroy(); - } - if (mpThumbnailWorkHeap != NULL) { - mpThumbnailWorkHeap->destroy(); - } + System::getMem2App()->free(mpWorkerHeap); + System::getMem2App()->free(mpThumbnailWorkHeap); - delete[] mpSDTitleIds; - delete[] mpSDTitleInfo; - delete[] mpChannelTitleIds; - delete[] mpNandTitleInfo; + if (mpSDTitleIds != NULL) { + delete[] mpSDTitleIds; + } + if (mpSDTitleInfo != NULL) { + delete[] mpSDTitleInfo; + } + if (mpChannelTitleIds != NULL) { + delete[] mpChannelTitleIds; + } + if (mpNandTitleInfo != NULL) { + delete[] mpNandTitleInfo; + } + mWorkerCommand = 6; delete mpSDWorker; mpSDWorker = NULL; } @@ -1468,19 +2184,17 @@ namespace ipl { mpHelpButtonLayout = new layout::Object(getSceneHeap(), mpLayoutFile, "arc", "help_Btn.brlyt"); + sFourPageDialogPages[3].layoutObj = mpHelpButtonLayout; - mpButtonEventHandler = new SDChannelSelectButtonEventHandler(this); - mpPaneManager = new gui::PaneManager(mpButtonEventHandler, mpLayout->getDrawInfo(), + SDChannelSelectEventHandler* eventHandler = new SDChannelSelectEventHandler(this); + mpPaneManager = new gui::PaneManager(eventHandler, mpLayout->getDrawInfo(), NULL, NULL); mpPaneManager->createLayoutScene(*mpLayout->getNW4RLyt()); mpPaneManager->setAllComponentTriggerTarget(false); for (int index = 0; index < MAX_CHANNEL_INDEX; ++index) { - const char* paneName = mscChannelPaneNames[mCurrentPage % PAGE_COUNT][index]; - if (paneName[0] != '\0') { - mpPaneManager->getPaneComponentByPane(mpLayout->FindPaneByName(paneName)) - ->setTriggerTarget(true); - } + mpPaneManager->getPaneComponentByPane(getChannelPane(index)) + ->setTriggerTarget(true); } for (int index = 0; index < 4; ++index) { @@ -1556,8 +2270,10 @@ namespace ipl { continue; } if (mState < 0x18) { - if (mState >= 0xF && page == mSourcePage && index == mSourceIndex) { - continue; + if (mState >= 0xF) { + if (page == mSourcePage && index == mSourceIndex) { + continue; + } } } if (!isChannelInCalc(page, index, currentPage)) { @@ -1576,6 +2292,168 @@ namespace ipl { nw4r::ut::List_Append(&mChannelObjects, channel); } +#pragma dont_inline on + BOOL SDChannelSelect::isChannelReady(const SDChannelObj* channel) { + return channel->mState == 3; + } +#pragma dont_inline reset + + BOOL SDChannelSelect::isPageCreated(int page) const { + for (int index = 0; index < MAX_CHANNEL_INDEX; ++index) { + SDChannelObj* channel = findChannelObject(page, index); + if (channel == NULL || !isChannelReady(channel)) { + return FALSE; + } + } + + if (page + 1 < mPageCount) { + for (int index = 0; index < MAX_CHANNEL_INDEX; index += 4) { + SDChannelObj* channel = findChannelObject(page + 1, index); + if (channel == NULL || !isChannelReady(channel)) { + return FALSE; + } + } + } + + if (page - 1 >= 0) { + for (int index = 3; index < MAX_CHANNEL_INDEX; index += 4) { + SDChannelObj* channel = findChannelObject(page - 1, index); + if (channel == NULL || !isChannelReady(channel)) { + return FALSE; + } + } + } + + return TRUE; + } + + BOOL SDChannelSelect::prepareRestarting(int page) { + if (page == mCurrentPage) { + return isPageCreated(page); + } + + mCurrentPage = page; + refreshPageObjects(page, NULL, -1); + return isPageCreated(page); + } + + void SDChannelSelect::startPageTransition(int page, int index) { + mCurrentPage = page; + mCurrentChannelIndex = index; + mpLayout->setAnmType(ANIM_TYPE_BACKWARD, -1); + mpLayout->start(-1); + + nw4r::math::VEC3 position(0.0f, 0.0f, 0.0f); + nw4r::lyt::Pane* pane = getCenterChannelPane(index); + PSMTXMultVec(pane->GetGlobalMtx(), position, position); + math::VEC3 animationPosition(position); + initPageAnimations(animationPosition, 1); + updatePageTransform(); + mState = 14; + } + + void SDChannelSelect::moveChannelObjectsToDrawOrder(int page, int mode) { + for (int index = 0; index < MAX_CHANNEL_INDEX; ++index) { + if (mode == -1) { + if ((index & 3) == 0) { + continue; + } + } else if (mode == 1 && (index & 3) == 3) { + continue; + } + + SDChannelObj* channel = findChannelObject(page, index); + if (channel != NULL) { + nw4r::ut::List_Remove(&mChannelObjects, channel); + nw4r::ut::List_Append(&mChannelObjects, channel); + } + } + + if (mode != 1 && page + 1 < mPageCount) { + for (int index = 0; index < MAX_CHANNEL_INDEX; index += 4) { + SDChannelObj* channel = findChannelObject(page + 1, index); + if (channel != NULL) { + nw4r::ut::List_Remove(&mChannelObjects, channel); + nw4r::ut::List_Append(&mChannelObjects, channel); + } + } + } + + if (mode != -1 && page - 1 >= 0) { + for (int index = 3; index < MAX_CHANNEL_INDEX; index += 4) { + SDChannelObj* channel = findChannelObject(page - 1, index); + if (channel != NULL) { + nw4r::ut::List_Remove(&mChannelObjects, channel); + nw4r::ut::List_Append(&mChannelObjects, channel); + } + } + } + } + + void SDChannelSelect::updateChannelObjectOrder(int page) { + moveChannelObjectsToDrawOrder(page, 0); + if (page < mPageCount - 1) { + moveChannelObjectsToDrawOrder(page + 1, -1); + } + if (page > 0) { + moveChannelObjectsToDrawOrder(page - 1, 1); + } + } + + void SDChannelSelect::refreshPageObjects(int page, SDChannelObj* keepChannel, + int noticeIndex) { + destroyUnusedChannelObjects(page, keepChannel); + createChannelList(page, false); + if (page < mPageCount - 1) { + createChannelList(page + 1, false); + } + if (page > 0) { + createChannelList(page - 1, false); + } + + updateChannelObjectOrder(page); + + SDChannelObj* channel = NULL; + while (channel = static_cast( + nw4r::ut::List_GetNext(&mChannelObjects, channel)), + channel != NULL) { + int titleIndex = channel->getPage() * MAX_CHANNEL_INDEX + channel->getIndex(); + if (!iplSDChannelObj_813E3330(channel) && mpChannelTitleIds[titleIndex] != 0 && + mbNeedsRefresh) { + channel->mStateFlags = 2; + } + } + + updateChannelObjects(); + if (mbNeedsRefresh) { + clearNoticeQueue(); + updateChannelNotices(0, noticeIndex); + updateChannelNotices(-1, -1); + updateChannelNotices(1, -1); + updateChannelNotices(-2, -1); + updateChannelNotices(2, -1); + } + } + + void SDChannelSelect::setCurrentPageAndRefresh(int page, int index, + SDChannelObj* keepChannel) { + mCurrentPage = page; + mCurrentChannelIndex = index; + refreshPageObjects(page, keepChannel, index); + } + + void SDChannelSelect::handleFourPageDialog() { + if (System::getDialog()->callBtn2Multi(sFourPageDialogPages, 4, 10)) { + mState = 25; + } + } + + void SDChannelSelect::handleThreePageDialog() { + if (System::getDialog()->callBtn2Multi(sThreePageDialogPages, 3, 10)) { + mState = 27; + } + } + void SDChannelSelect::refreshChannelList() { SDChannelObj* channel = NULL; while (channel = static_cast( @@ -1625,12 +2503,12 @@ namespace ipl { SDChannelObj* SDChannelSelect::findChannelObject(int page, int index) const { SDChannelObj* channel = NULL; while (channel = static_cast( - nw4r::ut::List_GetNext(&mChannelObjects, channel)), + nw4r::ut::List_GetNext(&mChannelObjects, channel)), channel != NULL) { - if (page == channel->getPage()) { - if (index == channel->getIndex()) { - return channel; - } + int channelPage = channel->getPage(); + int channelIndex = channel->getIndex(); + if (channelPage == page && channelIndex == index) { + return channel; } } return NULL; @@ -1704,5 +2582,945 @@ namespace ipl { } return result; } + + void SDChannelSelect::updatePageTransform() { + math::VEC3 frames[3]; + for (int index = 0; index < 3; ++index) { + frames[index] = mpPageAnimations[index]->get(); + } + + nw4r::ut::Rect projection; + System::getProjectionRect(&projection); + + mPosition = math::VEC3((frames[0].x + frames[1].x) / 2.0f, + (frames[0].y + frames[2].y) / 2.0f, 0.0f); + mScale = math::VEC2(projection.GetWidth() / (frames[1].x - frames[0].x), + projection.GetHeight() / (frames[0].y - frames[2].y)); + } + + void SDChannelSelect::advancePageAnimation() { + calcPageAnimations(); + updatePageTransform(); + if (!mpPageAnimations[0]->isPlaying()) { + mState = 12; + } + } + + void SDChannelSelect::finishPageScroll() { + if (mpLayout->isPlaying(0)) { + return; + } + + SDButton* button = static_cast(System::getSceneManager()->getScene(0x24)); + if (mState == 10) { + --mCurrentPage; + if (mCurrentPage == 0) { + button->animation(15); + mbLeftArrowVisible = false; + } else if (!mbRightArrowVisible) { + button->animation(14); + mbRightArrowVisible = true; + } + } else { + ++mCurrentPage; + if (mCurrentPage == mPageCount - 1) { + button->animation(16); + mbRightArrowVisible = false; + } else if (!mbLeftArrowVisible) { + button->animation(13); + mbLeftArrowVisible = true; + } + } + + mpLayout->finishBinding(); + refreshPageObjects(mCurrentPage, NULL, -1); + mState = 1; + } + + void SDChannelSelect::finishCardDialog() { + if (System::getDialog()->getLastResult() != DialogWindow::RESULT_NONE) { + mpPointerLayout->getAnim(0)->initAnmFrame(); + mState = 1; + } + } + + void SDChannelSelect::flushSaveDataAndMountSD() { + if (System::getDialog()->getLastResult() != DialogWindow::RESULT_NONE) { + mpPointerLayout->getAnim(0)->initAnmFrame(); + System::getSaveData()->setDidntGotoSDMenu(FALSE); + mpSaveDataFile = System::getSaveData()->flushAsync(System::getMem2App()); + mState = 1; + mpSDWorker->mount_sd_async(); + mWorkerState = 1; + } + } + + int SDChannelSelect::getCenterChannelIndex(const char* paneName) const { + int index = 0; + while (index < MAX_CHANNEL_INDEX) { + if (strcmp(paneName, mscChannelPaneNames[2][index]) == 0) { + break; + } + ++index; + } + + return index < MAX_CHANNEL_INDEX ? index : -1; + } + + void SDChannelSelect::initializeNormalPage() { + if (!mpPageAnimations[0]->isPlaying() && + System::getSceneManager()->getScene(0x23) == NULL) { + SDButton* button = static_cast( + System::getSceneManager()->getScene(0x24)); + button->enableBtn(); + + if (mCurrentPage > 0) { + button->animation(SDButton::IDANIM_ARROW_LEFT_APPEAR); + mbLeftArrowVisible = true; + } else { + mbLeftArrowVisible = false; + } + + if (mPageCount > 1 && mCurrentPage < mPageCount - 1) { + button->animation(SDButton::IDANIM_ARROW_RIGHT_APPEAR); + mbRightArrowVisible = true; + } else { + mbRightArrowVisible = false; + } + + button->setEventHandler(mpButtonEventHandler, NULL); + TVRCManager::getHandle()->setEnable(TRUE); + snd::getSystem()->startBGM("WIPL_BGM_MENU"); + clearNoticeQueue(); + updateChannelNotices(0, -1); + updateChannelNotices(-1, -1); + updateChannelNotices(1, -1); + updateChannelNotices(-2, -1); + updateChannelNotices(2, -1); + mState = 1; + } else { + calcPageAnimations(); + updatePageTransform(); + } + } + + void SDChannelSelect::processNormalInput() { + if (mbOperationActive && System::getDialog()->callBtn1(0xc1, 0x2e)) { + mState = 28; + } + + SDButton* button = static_cast(System::getSceneManager()->getScene(0x24)); + if (button != NULL && button->isActive()) { + button->update(); + } + + if (mState == 1) { + controller::Interface* controller = System::getMasterController(); + if (controller->down(0x30001000)) { + if (mCurrentPage > 0) { + setStateAndPlaySelectSound(8); + return; + } + } else if (controller->down(0x06000010) && mCurrentPage < mPageCount - 1) { + setStateAndPlaySelectSound(9); + return; + } + + } + + mpPaneManager->update(); + } + + void SDChannelSelect::setStateAndPlaySelectSound(int state) { + mState = state; + snd::getSystem()->startSE("WSD_SELECT"); + } + + void SDChannelSelect::selectChannel(int page, int index) { + SDChannelObj* channel = findChannelObject(page, index); + initPageAnimations( + math::VEC3((nw4r::math::VEC3&)channel->mpBaseLayout->GetRootPane()->GetTranslate()), + 0); + iplSDChannelObj_813E34E0(channel); + + SDButton* button = static_cast(System::getSceneManager()->getScene(0x24)); + if (mbLeftArrowVisible) { + button->animation(SDButton::IDANIM_ARROW_LEFT_DISAPPEAR); + } + if (mbRightArrowVisible) { + button->animation(SDButton::IDANIM_ARROW_RIGHT_DISAPPEAR); + } + button->disableBtn(); + button->setEventHandler(NULL); + mCurrentChannelIndex = index; + mState = 5; + snd::getSystem()->startSE("WIPL_SE_BT_PUSH"); + snd::getSystem()->stopBGM(5); + } + + BOOL SDChannelSelect::tellStartingZoomAnm() { + mpLayout->setMinFrame(200.0f); + mpLayout->setMaxFrame(228.0f); + mpLayout->setAnmType(ANIM_TYPE_FORWARD); + mpLayout->start(); + snd::getSystem()->startSE("WIPL_SE_CH_SELECT"); + mState = 7; + return TRUE; + } + + void SDChannelSelect::setPageActionFrame() { + if (mState == 8) { + setLayoutFrame(10); + } else { + setLayoutFrame(11); + } + } + + void SDChannelSelect::setLayoutFrame(int state) { + if (state == 10) { + mpLayout->setMinFrame(0.0f); + mpLayout->setMaxFrame(20.0f); + } else { + mpLayout->setMinFrame(40.0f); + mpLayout->setMaxFrame(60.0f); + } + mpLayout->setAnmType(ANIM_TYPE_FORWARD); + mpLayout->start(); + mState = state; + } + + void SDChannelSelect::initPageAnimations(const math::VEC3& position, int direction) { + nw4r::ut::Rect projection; + System::getProjectionRect(&projection); + + math::VEC3 topLeft(projection.left, -projection.top, 0.0f); + math::VEC3 lowerLeft(position.x - mThumbOffsetX, position.y + mThumbOffsetY, 0.0f); + math::VEC3 topRight(projection.right, -projection.top, 0.0f); + math::VEC3 lowerRight(position.x + mThumbOffsetX, position.y + mThumbOffsetY, 0.0f); + math::VEC3 bottomLeft(projection.left, -projection.bottom, 0.0f); + math::VEC3 upperLeft(position.x - mThumbOffsetX, position.y - mThumbOffsetY, 0.0f); + math::VEC3 bottomRight(projection.right, -projection.bottom, 0.0f); + math::VEC3 upperRight(position.x + mThumbOffsetX, position.y - mThumbOffsetY, 0.0f); + + if (direction == 0) { + mpPageAnimations[0]->init(topLeft, lowerLeft, 28.0f, 0.0f, 0.0f, + ANIM_TYPE_FORWARD, 1.0f); + mpPageAnimations[1]->init(topRight, lowerRight, 28.0f, 0.0f, 0.0f, + ANIM_TYPE_FORWARD, 1.0f); + mpPageAnimations[2]->init(bottomLeft, upperLeft, 28.0f, 0.0f, 0.0f, + ANIM_TYPE_FORWARD, 1.0f); + mpPageAnimations[3]->init(bottomRight, upperRight, 28.0f, 0.0f, 0.0f, + ANIM_TYPE_FORWARD, 1.0f); + } else { + mpPageAnimations[0]->init(lowerLeft, topLeft, 28.0f, 0.0f, 0.0f, + ANIM_TYPE_FORWARD, 1.0f); + mpPageAnimations[1]->init(lowerRight, topRight, 28.0f, 0.0f, 0.0f, + ANIM_TYPE_FORWARD, 1.0f); + mpPageAnimations[2]->init(upperLeft, bottomLeft, 28.0f, 0.0f, 0.0f, + ANIM_TYPE_FORWARD, 1.0f); + mpPageAnimations[3]->init(upperRight, bottomRight, 28.0f, 0.0f, 0.0f, + ANIM_TYPE_FORWARD, 1.0f); + } + + math::HermiteIntp* animation; + int index = 0; + do { + animation = mpPageAnimations[index]; + animation->play(); + ++index; + } while (index < 4); + } + + void SDChannelSelect::setChannelScissor(const SDChannelObj* channel) const { + nw4r::math::VEC3 position(channel->getTranslate()); + nw4r::ut::Rect projection; + System::getProjectionRect(&projection); + GXRenderModeObj* renderMode = System::getRenderModeObj(); + f32 scissorWidth; + f32 scissorY; + f32 scissorX; + f32 scissorHeight; + u16 framebufferWidth; + u16 framebufferHeight; + + if (mState == 7 || mState == 12 || mState == 14) { + nw4r::math::MTX44 matrix; + f32 rightScale = projection.right / mScale.x; + f32 leftScale = projection.left / mScale.x; + f32 topScale = projection.top / mScale.y; + f32 bottomScale = projection.bottom / mScale.y; + f32 bottom = mPosition.y - bottomScale; + f32 right = mPosition.x + rightScale; + f32 left = mPosition.x + leftScale; + f32 top = mPosition.y - topScale; + MTXOrtho(matrix, top, bottom, left, right, -100.0f, 100.0f); + + nw4r::math::VEC4 input(position.x, position.y, 0.0f, 1.0f); + nw4r::math::VEC4 transformed; + nw4r::math::VEC4Transform(&transformed, &matrix, &input); + framebufferWidth = renderMode->fbWidth; + framebufferHeight = renderMode->efbHeight; + scissorWidth = projection.GetWidth(); + scissorY = (framebufferHeight - ((1.0f + transformed.y) * framebufferHeight / 2)) - + (mThumbOffsetY * mScale.y); + f32 widthScale = framebufferWidth / scissorWidth; + scissorX = ((1.0f + transformed.x) * framebufferWidth / 2) - + ((mThumbOffsetX * mScale.x) * widthScale); + scissorWidth = 2.0f * (mThumbOffsetX * mScale.x) * + (framebufferWidth / scissorWidth); + scissorHeight = 2.0f * (mThumbOffsetY * mScale.y); + } else { + framebufferWidth = renderMode->fbWidth; + framebufferHeight = renderMode->efbHeight; + scissorX = ((f32)framebufferWidth / 2) + + ((position.x - mThumbOffsetX) * + (framebufferWidth / projection.GetWidth())); + scissorY = (((f32)framebufferHeight / 2) - position.y) - mThumbOffsetY; + scissorWidth = 2.0f * mThumbOffsetX * + (framebufferWidth / projection.GetWidth()); + scissorHeight = 2.0f * mThumbOffsetY; + } + + scissorX -= 1.0f; + scissorY -= 1.0f; + scissorWidth += 2.0f; + scissorHeight += 2.0f; + + if (scissorX >= framebufferWidth || (scissorX + scissorWidth) <= 0.0f || + scissorY >= framebufferHeight || (scissorY + scissorHeight) <= 0.0f) { + GXSetScissor(0, 0, 0, 0); + } else { + if (scissorX < 0.0f) { + scissorWidth += scissorX; + scissorX = 0.0f; + } + if (scissorY < 0.0f) { + scissorHeight += scissorY; + scissorY = 0.0f; + } + if ((scissorX + scissorWidth) > 1705.0f) { + scissorWidth -= (scissorX + scissorWidth) - 1705.0f; + } + if ((scissorY + scissorHeight) > 1705.0f) { + scissorHeight -= (scissorY + scissorHeight) - 1705.0f; + } + GXSetScissor(scissorX, scissorY, scissorWidth, scissorHeight); + } + } + + void SDChannelSelect::createSceneLayouts() { + GXTexObj widescreenTexture; + + mpStateLayout = new layout::Object(getSceneHeap(), mpLayoutFile, "arc", + "mn_SdcardMenu_d.brlyt"); + mpHelpLayout = mpStateLayout->bind("mn_SdcardMenu_d.brlan"); + f32 frame = System::getRndm()->get_u16() % 2000; + mpHelpLayout->play(); + mpStateLayout->finishBinding(); + mpHelpLayout->setCurrentFrame(frame); + + mpPageLayouts[0] = new layout::Object(getSceneHeap(), mpLayoutFile, "arc", + "my_TVMask_a.brlyt"); + mpPageLayouts[0]->bind("my_TVMask_a_Apear.brlan", "Picture_00", false, true); + mpPageLayouts[0]->bind("my_TVMask_a_Lost.brlan", "Picture_00", false, false); + mpPageLayouts[0]->finishBinding(); + mpPageLayouts[0]->getAnim(0)->initAnmFrame(); + + mpPageLayouts[1] = new layout::Object(getSceneHeap(), mpLayoutFile, "arc", + "my_TVShade_a.brlyt"); + const char* shadeAppear = "my_TVShade_a_Apear.brlan"; + mpPageLayouts[1]->bind(shadeAppear, "4x3", true, true); + mpPageLayouts[1]->bind("my_TVShade_a_Lost.brlan", "4x3", true, false); + mpPageLayouts[1]->finishBinding(); + + if (SCGetAspectRatio() == SC_ASPECT_RATIO_16x9) { + mpPageLayouts[1]->FindPaneByName("16x9") + ->GetMaterial()->GetTexture(&widescreenTexture, GX_TEXMAP0); + mpPageLayouts[1]->FindPaneByName("4x3") + ->GetMaterial()->SetTexture(GX_TEXMAP0, widescreenTexture); + mpPageLayouts[1]->FindPaneByName("4x3_dummy") + ->GetMaterial()->SetTexture(GX_TEXMAP0, widescreenTexture); + } + + mpPageLayouts[1]->getAnim(0)->initAnmFrame(); + + mpPageLayouts[2] = new layout::Object(getSceneHeap(), mpLayoutFile, "arc", + "my_TVApear_a.brlyt"); + mpPageLayouts[2]->bind("my_TVApear_a_Apear.brlan", "Picture_00", false, true); + mpPageLayouts[2]->bind("my_TVApear_a_Lost.brlan", "Picture_00", false, false); + mpPageLayouts[2]->finishBinding(); + mpPageLayouts[2]->getAnim(0)->initAnmFrame(); + + mpErrorLayout = new layout::Object(getSceneHeap(), mpLayoutFile, "arc", + "my_TVMask_a.brlyt"); + mpErrorLayout->bind("my_TVMask_a_Lost.brlan", "Picture_00", false, true); + mpErrorLayout->finishBinding(); + + mpPointerLayout = new layout::Object(getSceneHeap(), mpLayoutFile, "arc", + "wait_icon.brlyt"); + mpPointerLayout->bind("wait_icon_wait_loop.brlan", NULL, false, true); + mpPointerLayout->finishBinding(); + mpPointerLayout->getAnim(0)->initAnmFrame(); + + sFourPageDialogPages[2].layoutObj = mpPointerLayout; + sThreePageDialogPages[2].layoutObj = mpPointerLayout; + } + + BOOL SDChannelSelect::isChannelMoveTarget(int page, int index) const { + if (page < 0 || page >= mPageCount) { + return FALSE; + } + if (index < 0 || index >= MAX_CHANNEL_INDEX) { + return FALSE; + } + if (page == mSourcePage && index == mSourceIndex) { + return TRUE; + } + u32 titleId = mpChannelTitleIds[page * MAX_CHANNEL_INDEX + index]; + return titleId == 0; + } + + BOOL SDChannelSelect::onEventDerived(const char* paneName, u32 event, + controller::Interface* controller) { + if (controller != NULL && + controller != System::getControllerManager()->getController(mControllerChannel)) { + return TRUE; + } + + int index = getCenterChannelIndex(paneName); + if (index >= 0) { + s32 eventType = event; + if (eventType != 2) { + if (eventType >= 2) { + if (eventType == 5 && !controller->pinch()) { + mDestinationIndex = index; + mDestinationPage = mCurrentPage; + mbButtonEnabled = true; + } + } else if (eventType >= 1) { + if (isChannelMoveTarget(mCurrentPage, index) || + (mCurrentPage == mSourcePage && index == mSourceIndex)) { + SDChannelObj* channel = findChannelObject(mCurrentPage, index); + iplSDChannelObj_813E3354(channel, 2); + snd::getSystem()->startSE("WIPL_SE_CH_TARGETTING"); + controller->rumble(1); + } + } + } else if (isChannelMoveTarget(mCurrentPage, index) || + (mCurrentPage == mSourcePage && index == mSourceIndex)) { + SDChannelObj* channel = findChannelObject(mCurrentPage, index); + iplSDChannelObj_813E33EC(channel, 2); + } + } + + return TRUE; + } + + void SDChannelSelect::startDrag(const controller::Interface* controller, + int page, int index) { + if (controller->getChannel() < 0) { + return; + } + + if (controller->isValidDpd()) { + mPointerPosition = controller->getDpdPos(); + } else { + mPointerPosition = math::VEC2(0.0f, 0.0f); + } + + mControllerChannel = controller->getChannel(); + mSourcePage = page; + mSourceIndex = index; + mDestinationPage = -1; + mDestinationIndex = -1; + mPendingPage = -1; + mPendingIndex = -1; + mMoveState = 0; + mbButtonEnabled = false; + mbDialogActive = false; + + System::getPointer()->changeType(controller->getChannel(), 1); + mpPageLayouts[0]->getAnim(0)->play(); + mpPageLayouts[1]->getAnim(0)->play(); + + SDButton* button = static_cast(System::getSceneManager()->getScene(0x24)); + button->disableBtn(); + + SDChannelObj* channel = NULL; + while (channel = static_cast(nw4r::ut::List_GetNext(&mChannelObjects, channel)), + channel != NULL) { + iplSDChannelObj_813E3480( + channel, channel->getPage() == page && channel->getIndex() == index); + } + + snd::getSystem()->startSEwithPos("WIPL_SE_CH_HOLD", mPointerPosition.x); + mState = 15; + } + + void SDChannelSelect::finishDrag() { + if (isChannelMoveTarget(mDestinationPage, mDestinationIndex) && !mbDialogActive) { + SDChannelObj* channel = findChannelObject(mDestinationPage, mDestinationIndex); + nw4r::math::VEC3 position = channel->getTranslate(); + mpPageLayouts[2]->GetRootPane()->SetTranslate(position); + mpPageLayouts[2]->getAnim(0)->play(); + mpPointerLayout->GetRootPane()->SetTranslate(position); + mpPointerLayout->calcMtx(); + mpPointerLayout->getAnim(0)->play(); + snd::getSystem()->startSEwithPos("WIPL_SE_CH_SET", mPointerPosition.x); + mpPageLayouts[0]->getAnim(1)->play(); + mState = 19; + } else { + snd::getSystem()->startSEwithPos("WIPL_SE_CH_NOT_MOVE", mPointerPosition.x); + mState = 17; + } + + System::getPointer()->changeType(mControllerChannel, 0); + mpPageLayouts[1]->getAnim(1)->play(); + + SDButton* button = static_cast(System::getSceneManager()->getScene(0x24)); + button->enableBtn(); + + mbButtonEnabled = false; + mbDialogActive = false; + + SDChannelObj* channel = NULL; + while (channel = static_cast(nw4r::ut::List_GetNext(&mChannelObjects, channel)), + channel != NULL) { + iplSDChannelObj_813E34E8(channel, 1); + } + + for (int index = 0; index < MAX_CHANNEL_INDEX; ++index) { + mpPaneManager->initPane(getChannelPane(index)); + } + } + + void SDChannelSelect::moveDrag() { + if (System::getControllerManager()->getController(mControllerChannel) != NULL && + System::getControllerManager()->getController(mControllerChannel)->isValidDpd()) { + math::VEC2 position = System::getControllerManager() + ->getController(mControllerChannel) + ->getDpdProjectionPos(); + nw4r::math::VEC3 translation(position.x, -position.y, 0.0f); + mpPageLayouts[1]->GetRootPane()->SetTranslate(translation); + mpPageLayouts[1]->calcMtx(); + + math::VEC2 delta; + delta.y = position.y - mPointerPosition.y; + delta.x = position.x - mPointerPosition.x; + f32 distance = delta.x * delta.x + delta.y * delta.y; + f32 speed = distance <= 0.0f ? 0.0f : distance * nw4r::math::FrSqrt(distance); + + snd::getSystem()->holdSEwithPosDis("WIPL_SE_CH_DRAG", position.x, speed); + mPointerPosition = position; + } + } + + void SDChannelSelect::updateDragState() { + SDButton* button = static_cast(System::getSceneManager()->getScene(0x24)); + if (button != NULL && button->isActive()) { + button->update(); + } + + mpPaneManager->update(); + + if (System::getControllerManager()->getController(mControllerChannel) == NULL || + !System::getControllerManager()->getController(mControllerChannel)->pinch()) { + mbButtonEnabled = true; + } + + if (mPendingIndex >= 0) { + ++mPendingIndex; + } + if (mPendingPage >= 0) { + ++mPendingPage; + } + + moveDrag(); + + if (!mpPageLayouts[0]->getAnim(0)->isPlaying() && + !mpPageLayouts[1]->getAnim(0)->isPlaying()) { + mState = 16; + } + } + + void SDChannelSelect::updateDragPageTransition() { + SDButton* button = static_cast(System::getSceneManager()->getScene(0x24)); + if (button != NULL && button->isActive()) { + button->update(); + } + + mpPaneManager->update(); + + if (System::getControllerManager()->getController(mControllerChannel) == NULL || + !System::getControllerManager()->getController(mControllerChannel)->pinch()) { + mbButtonEnabled = true; + } + + if (mPendingIndex >= 0) { + ++mPendingIndex; + } + if (mPendingPage >= 0) { + ++mPendingPage; + } + + moveDrag(); + + if (mbButtonEnabled || mbDialogActive) { + finishDrag(); + } else if (mCurrentPage > 0 && mPendingIndex >= 15) { + button->animation(7); + mpLayout->setMinFrame(0.0f, -1); + mpLayout->setMaxFrame(20.0f, -1); + mpLayout->setAnmType(ANIM_TYPE_FORWARD, -1); + mpLayout->start(-1); + mState = 22; + mPendingIndex = 0; + mPendingPage = -1; + + SDChannelObj* channel = NULL; + while (channel = static_cast( + nw4r::ut::List_GetNext(&mChannelObjects, channel)), + channel != NULL) { + iplSDChannelObj_813E34E8(channel, 1); + } + + for (int index = 0; index < MAX_CHANNEL_INDEX; ++index) { + mpPaneManager->initPane(getChannelPane(index)); + } + + snd::getSystem()->startSE("WSD_SELECT"); + } else if (mCurrentPage < mPageCount - 1 && mPendingPage >= 15) { + button->animation(8); + mpLayout->setMinFrame(40.0f, -1); + mpLayout->setMaxFrame(60.0f, -1); + mpLayout->setAnmType(ANIM_TYPE_FORWARD, -1); + mpLayout->start(-1); + mState = 23; + mPendingIndex = -1; + mPendingPage = 0; + + SDChannelObj* channel = NULL; + while (channel = static_cast( + nw4r::ut::List_GetNext(&mChannelObjects, channel)), + channel != NULL) { + iplSDChannelObj_813E34E8(channel, 1); + } + + for (int index = 0; index < MAX_CHANNEL_INDEX; ++index) { + mpPaneManager->initPane(getChannelPane(index)); + } + + snd::getSystem()->startSE("WSD_SELECT"); + } + } + + void SDChannelSelect::finishDragWait() { + if (++mMoveState > 20) { + mpPageLayouts[0]->getAnim(1)->play(); + mState = 18; + } + } + + void SDChannelSelect::finishDragPageTransition() { + if (!mpPageLayouts[0]->getAnim(1)->isPlaying() && + !mpPageLayouts[1]->getAnim(1)->isPlaying()) { + mState = 1; + } + } + + void SDChannelSelect::applyChannelMove() { + if (mpPageLayouts[2]->getAnim(0)->isPlaying()) { + return; + } + + if (mSourcePage == mDestinationPage && mSourceIndex == mDestinationIndex) { + mpPageLayouts[2]->getAnim(1)->play(); + mState = 21; + return; + } + + int sourceSlot = mSourcePage * MAX_CHANNEL_INDEX + mSourceIndex; + int destinationSlot = mDestinationPage * MAX_CHANNEL_INDEX + mDestinationIndex; + u32 sourceTitleId = mpChannelTitleIds[sourceSlot]; + u32 destinationTitleId = mpChannelTitleIds[destinationSlot]; + mpChannelTitleIds[sourceSlot] = destinationTitleId; + mpChannelTitleIds[destinationSlot] = sourceTitleId; + + layout::Animator* transitionAnimator; + if (enqueueLoadNotice()) { + transitionAnimator = NULL; + mbShowNoCardMessage = false; + } else { + transitionAnimator = mpPageLayouts[2]->getAnim(1); + transitionAnimator->play(); + mState = 21; + } + + mpCurrentChannel = findChannelObject(mSourcePage, mSourceIndex); + if (mpCurrentChannel == NULL) { + mpCurrentChannel = findChannelObject(mDestinationPage, mDestinationIndex); + enqueueNotice(mpChannelTitleIds[destinationSlot], mDestinationPage, + mDestinationIndex); + } else { + SDChannelObj* destination = findChannelObject(mDestinationPage, mDestinationIndex); + + iplSDChannelObj_813E3178( + static_cast(mpCurrentChannel), + getChannelBasePane(mDestinationPage, mDestinationIndex, mCurrentPage)); + iplSDChannelObj_813E3178( + destination, getChannelBasePane(mSourcePage, mSourceIndex, mCurrentPage)); + + static_cast(mpCurrentChannel)->mPage = mDestinationPage; + static_cast(mpCurrentChannel)->mIndex = mDestinationIndex; + destination->mPage = mSourcePage; + destination->mIndex = mSourceIndex; + + iplSDChannelObj_813E322C(static_cast(mpCurrentChannel)); + iplSDChannelObj_813E322C(destination); + + mpCurrentChannel = transitionAnimator; + destination->mpBaseAnimator->setCurrentFrame(mpHelpLayout->getCurrentFrame()); + } + + mState = 20; + } + + void SDChannelSelect::finishChannelMove() { + if (!mbShowNoCardMessage) { + return; + } + + if (mpCurrentChannel != NULL && + !isChannelReady(static_cast(mpCurrentChannel))) { + return; + } + + if (mpCurrentChannel != NULL) { + mpCurrentChannel = NULL; + } else if (mSourcePage != -1) { + SDChannelObj* source = findChannelObject(mSourcePage, mSourceIndex); + SDChannelObj* destination = + findChannelObject(mDestinationPage, mDestinationIndex); + SDChannelObj* next = static_cast( + nw4r::ut::List_GetNext(&mChannelObjects, destination)); + if (next == source) { + next = destination; + } + + nw4r::ut::List_Remove(&mChannelObjects, destination); + nw4r::ut::List_Insert(&mChannelObjects, source, destination); + nw4r::ut::List_Remove(&mChannelObjects, source); + nw4r::ut::List_Insert(&mChannelObjects, next, source); + } + + mpPageLayouts[2]->getAnim(1)->play(); + mState = 21; + } + + void SDChannelSelect::resetDragPreview() { + if (mpPageLayouts[0]->getAnim(1)->isPlaying()) { + return; + } + if (mpPageLayouts[1]->getAnim(1)->isPlaying()) { + return; + } + if (mpPageLayouts[2]->getAnim(1)->isPlaying()) { + return; + } + + f32 frame = System::getRndm()->get_u16() % 2000; + mpHelpLayout->setCurrentFrame(frame); + mSourcePage = -1; + mSourceIndex = -1; + mpPointerLayout->getAnim(0)->stop(); + mpPointerLayout->getAnim(0)->initAnmFrame(); + mState = 1; + } + + void SDChannelSelect::finishDragPageChange() { + SDButton* button = static_cast(System::getSceneManager()->getScene(0x24)); + if (button != NULL && button->isActive()) { + button->update(); + } + + if (System::getControllerManager()->getController(mControllerChannel) == NULL || + !System::getControllerManager()->getController(mControllerChannel)->pinch()) { + mbButtonEnabled = true; + } + + moveDrag(); + if (mpLayout->isPlaying(0)) { + return; + } + + button = static_cast(System::getSceneManager()->getScene(0x24)); + if (mState == 22) { + --mCurrentPage; + if (mCurrentPage == 0) { + button->animation(15); + mbLeftArrowVisible = false; + } else if (!mbRightArrowVisible) { + button->animation(14); + mbRightArrowVisible = true; + } + } else { + ++mCurrentPage; + if (mCurrentPage == mPageCount - 1) { + button->animation(16); + mbRightArrowVisible = false; + } else if (!mbLeftArrowVisible) { + button->animation(13); + mbLeftArrowVisible = true; + } + } + + mpLayout->finishBinding(); + refreshPageObjects(mCurrentPage, NULL, -1); + mState = 16; + } + + void SDChannelSelectButtonEventHandler::onEventDerived( + u32 compId, u32 event, const controller::Interface* con) { + gui::PaneComponent* component = static_cast( + mpManager->getComponent(compId)); + const char* paneName = component->getPane()->GetName(); + + int state = mpScene->mState; + switch (state) { + case 15: + case 16: + case 17: + case 18: + case 19: + case 20: + case 21: + case 22: + case 23: + mpScene->onButtonEvent(paneName, event, con); + return; + default: + break; + } + + if (event == 0) { + if (mpScene->mState == 1) { + if (System::getFader()->getStatus() == EGG::Fader::PREPARE_OUT) { + if (con != NULL) { + if (con->downTrg(0x00100800)) { + SDButton* button = static_cast( + System::getSceneManager()->getScene(0x24)); + if (strcmp(paneName, + SDButton::smButtonName[SDButton::BTN_HELP]) == 0) { + mpScene->mOperationResult = 0; + mpScene->mState = 26; + button->animation(4); + snd::getSystem()->startSE("WIPL_SE_DECIDE"); + return; + } + + if (strcmp(paneName, + SDButton::smButtonName[SDButton::BTN_WII_MENU]) == 0) { + button->setEventHandler(NULL, NULL); + mpScene->mState = 4; + snd::getSystem()->startSE("WIPL_SE_DECIDE"); + return; + } + + if (strcmp(paneName, + SDButton::smButtonName[SDButton::BTN_ARROW_LEFT]) == 0) { + if (mpScene->mCurrentPage > 0) { + button->animation(7); + mpScene->setStateAndPlaySelectSound(8); + return; + } + } + + if (strcmp(paneName, + SDButton::smButtonName[SDButton::BTN_ARROW_RIGHT]) == 0 && + mpScene->mCurrentPage < mpScene->mPageCount - 1) { + button->animation(8); + mpScene->setStateAndPlaySelectSound(9); + } + } else { + return; + } + } else { + return; + } + } + } + } else { + return; + } + } + + void SDChannelSelectEventHandler::onEvent(u32 compId, u32 event, void* data) { + gui::PaneComponent* component = static_cast( + mpManager->getComponent(compId)); + const char* paneName = component->getPane()->GetName(); + controller::Interface* controller = static_cast(data); + + BOOL handled = FALSE; + switch (mpScene->mState) { + case 15: + case 16: + handled = mpScene->onEventDerived(paneName, event, controller); + break; + default: + break; + } + + handle_channel_event: + if (handled) { + return; + } + + int index = mpScene->getCenterChannelIndex(paneName); + if (index < 0) { + return; + } + + SDChannelObj* channel = mpScene->findChannelObject(mpScene->mCurrentPage, index); + if (channel == NULL) { + return; + } + + switch (event) { + case ::gui::EventHandler::ON_TRIG: + if (mpScene->mState == 1 && controller != NULL) { + BOOL writeProtected = mpScene->mpSDWorker->is_sd_write_protected(); + if (controller->pinchTrg() && SDChannelSelect::isChannelReady(channel) && + !mpScene->mbSDCardBroken) { + if (!writeProtected) { + mpScene->startDrag(controller, mpScene->mCurrentPage, index); + } else if (!mpScene->mbChannelLimitReached && + System::getDialog()->callBtn1(0xC6, 0x2E)) { + mpScene->mbChannelLimitReached = true; + mpScene->mState = 29; + } + } + } + break; + case ::gui::EventHandler::ON_DRAG: + if (mpScene->mState == 1 && controller != NULL && controller->decide() && + SDChannelSelect::isChannelReady(channel)) { + mpScene->selectChannel(channel->getPage(), channel->getIndex()); + TVRCManager::getHandle()->setEnable(FALSE); + } + break; + case ::gui::EventHandler::ON_POINT: + if (mpScene->mState == 1 && SDChannelSelect::isChannelReady(channel)) { + iplSDChannelObj_813E3354(channel, 0); + snd::getSystem()->startSE("WIPL_SE_CH_TARGETTING"); + controller->rumble(1); + } + break; + case ::gui::EventHandler::ON_LEFT: + if (mpScene->mState == 1 && SDChannelSelect::isChannelReady(channel)) { + iplSDChannelObj_813E33EC(channel, 0); + } + break; + } + } } } -- 2.49.1 From 7f627435b55b536ae5ff9c5076c74f3219a0afad Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 29 Sep 2026 08:50:37 -0500 Subject: [PATCH 16/18] Decompile ATERM to 3/26 functions plus its data (worker af65e648) (#267) --- src/scene/setting/ATERM.c | 2345 +++++++++++++++++++++++++++++++++++++ 1 file changed, 2345 insertions(+) create mode 100644 src/scene/setting/ATERM.c diff --git a/src/scene/setting/ATERM.c b/src/scene/setting/ATERM.c new file mode 100644 index 00000000..bf138fcc --- /dev/null +++ b/src/scene/setting/ATERM.c @@ -0,0 +1,2345 @@ +#include + +#include +#include +#include +#include +#include +#include +#include + +static const u32 gAtermAesTables[10][256] = { + { + 0xc66363a5, 0xf87c7c84, 0xee777799, 0xf67b7b8d, 0xfff2f20d, 0xd66b6bbd, 0xde6f6fb1, 0x91c5c554, + 0x60303050, 0x02010103, 0xce6767a9, 0x562b2b7d, 0xe7fefe19, 0xb5d7d762, 0x4dababe6, 0xec76769a, + 0x8fcaca45, 0x1f82829d, 0x89c9c940, 0xfa7d7d87, 0xeffafa15, 0xb25959eb, 0x8e4747c9, 0xfbf0f00b, + 0x41adadec, 0xb3d4d467, 0x5fa2a2fd, 0x45afafea, 0x239c9cbf, 0x53a4a4f7, 0xe4727296, 0x9bc0c05b, + 0x75b7b7c2, 0xe1fdfd1c, 0x3d9393ae, 0x4c26266a, 0x6c36365a, 0x7e3f3f41, 0xf5f7f702, 0x83cccc4f, + 0x6834345c, 0x51a5a5f4, 0xd1e5e534, 0xf9f1f108, 0xe2717193, 0xabd8d873, 0x62313153, 0x2a15153f, + 0x0804040c, 0x95c7c752, 0x46232365, 0x9dc3c35e, 0x30181828, 0x379696a1, 0x0a05050f, 0x2f9a9ab5, + 0x0e070709, 0x24121236, 0x1b80809b, 0xdfe2e23d, 0xcdebeb26, 0x4e272769, 0x7fb2b2cd, 0xea75759f, + 0x1209091b, 0x1d83839e, 0x582c2c74, 0x341a1a2e, 0x361b1b2d, 0xdc6e6eb2, 0xb45a5aee, 0x5ba0a0fb, + 0xa45252f6, 0x763b3b4d, 0xb7d6d661, 0x7db3b3ce, 0x5229297b, 0xdde3e33e, 0x5e2f2f71, 0x13848497, + 0xa65353f5, 0xb9d1d168, 0x00000000, 0xc1eded2c, 0x40202060, 0xe3fcfc1f, 0x79b1b1c8, 0xb65b5bed, + 0xd46a6abe, 0x8dcbcb46, 0x67bebed9, 0x7239394b, 0x944a4ade, 0x984c4cd4, 0xb05858e8, 0x85cfcf4a, + 0xbbd0d06b, 0xc5efef2a, 0x4faaaae5, 0xedfbfb16, 0x864343c5, 0x9a4d4dd7, 0x66333355, 0x11858594, + 0x8a4545cf, 0xe9f9f910, 0x04020206, 0xfe7f7f81, 0xa05050f0, 0x783c3c44, 0x259f9fba, 0x4ba8a8e3, + 0xa25151f3, 0x5da3a3fe, 0x804040c0, 0x058f8f8a, 0x3f9292ad, 0x219d9dbc, 0x70383848, 0xf1f5f504, + 0x63bcbcdf, 0x77b6b6c1, 0xafdada75, 0x42212163, 0x20101030, 0xe5ffff1a, 0xfdf3f30e, 0xbfd2d26d, + 0x81cdcd4c, 0x180c0c14, 0x26131335, 0xc3ecec2f, 0xbe5f5fe1, 0x359797a2, 0x884444cc, 0x2e171739, + 0x93c4c457, 0x55a7a7f2, 0xfc7e7e82, 0x7a3d3d47, 0xc86464ac, 0xba5d5de7, 0x3219192b, 0xe6737395, + 0xc06060a0, 0x19818198, 0x9e4f4fd1, 0xa3dcdc7f, 0x44222266, 0x542a2a7e, 0x3b9090ab, 0x0b888883, + 0x8c4646ca, 0xc7eeee29, 0x6bb8b8d3, 0x2814143c, 0xa7dede79, 0xbc5e5ee2, 0x160b0b1d, 0xaddbdb76, + 0xdbe0e03b, 0x64323256, 0x743a3a4e, 0x140a0a1e, 0x924949db, 0x0c06060a, 0x4824246c, 0xb85c5ce4, + 0x9fc2c25d, 0xbdd3d36e, 0x43acacef, 0xc46262a6, 0x399191a8, 0x319595a4, 0xd3e4e437, 0xf279798b, + 0xd5e7e732, 0x8bc8c843, 0x6e373759, 0xda6d6db7, 0x018d8d8c, 0xb1d5d564, 0x9c4e4ed2, 0x49a9a9e0, + 0xd86c6cb4, 0xac5656fa, 0xf3f4f407, 0xcfeaea25, 0xca6565af, 0xf47a7a8e, 0x47aeaee9, 0x10080818, + 0x6fbabad5, 0xf0787888, 0x4a25256f, 0x5c2e2e72, 0x381c1c24, 0x57a6a6f1, 0x73b4b4c7, 0x97c6c651, + 0xcbe8e823, 0xa1dddd7c, 0xe874749c, 0x3e1f1f21, 0x964b4bdd, 0x61bdbddc, 0x0d8b8b86, 0x0f8a8a85, + 0xe0707090, 0x7c3e3e42, 0x71b5b5c4, 0xcc6666aa, 0x904848d8, 0x06030305, 0xf7f6f601, 0x1c0e0e12, + 0xc26161a3, 0x6a35355f, 0xae5757f9, 0x69b9b9d0, 0x17868691, 0x99c1c158, 0x3a1d1d27, 0x279e9eb9, + 0xd9e1e138, 0xebf8f813, 0x2b9898b3, 0x22111133, 0xd26969bb, 0xa9d9d970, 0x078e8e89, 0x339494a7, + 0x2d9b9bb6, 0x3c1e1e22, 0x15878792, 0xc9e9e920, 0x87cece49, 0xaa5555ff, 0x50282878, 0xa5dfdf7a, + 0x038c8c8f, 0x59a1a1f8, 0x09898980, 0x1a0d0d17, 0x65bfbfda, 0xd7e6e631, 0x844242c6, 0xd06868b8, + 0x824141c3, 0x299999b0, 0x5a2d2d77, 0x1e0f0f11, 0x7bb0b0cb, 0xa85454fc, 0x6dbbbbd6, 0x2c16163a + }, + { + 0xa5c66363, 0x84f87c7c, 0x99ee7777, 0x8df67b7b, 0x0dfff2f2, 0xbdd66b6b, 0xb1de6f6f, 0x5491c5c5, + 0x50603030, 0x03020101, 0xa9ce6767, 0x7d562b2b, 0x19e7fefe, 0x62b5d7d7, 0xe64dabab, 0x9aec7676, + 0x458fcaca, 0x9d1f8282, 0x4089c9c9, 0x87fa7d7d, 0x15effafa, 0xebb25959, 0xc98e4747, 0x0bfbf0f0, + 0xec41adad, 0x67b3d4d4, 0xfd5fa2a2, 0xea45afaf, 0xbf239c9c, 0xf753a4a4, 0x96e47272, 0x5b9bc0c0, + 0xc275b7b7, 0x1ce1fdfd, 0xae3d9393, 0x6a4c2626, 0x5a6c3636, 0x417e3f3f, 0x02f5f7f7, 0x4f83cccc, + 0x5c683434, 0xf451a5a5, 0x34d1e5e5, 0x08f9f1f1, 0x93e27171, 0x73abd8d8, 0x53623131, 0x3f2a1515, + 0x0c080404, 0x5295c7c7, 0x65462323, 0x5e9dc3c3, 0x28301818, 0xa1379696, 0x0f0a0505, 0xb52f9a9a, + 0x090e0707, 0x36241212, 0x9b1b8080, 0x3ddfe2e2, 0x26cdebeb, 0x694e2727, 0xcd7fb2b2, 0x9fea7575, + 0x1b120909, 0x9e1d8383, 0x74582c2c, 0x2e341a1a, 0x2d361b1b, 0xb2dc6e6e, 0xeeb45a5a, 0xfb5ba0a0, + 0xf6a45252, 0x4d763b3b, 0x61b7d6d6, 0xce7db3b3, 0x7b522929, 0x3edde3e3, 0x715e2f2f, 0x97138484, + 0xf5a65353, 0x68b9d1d1, 0x00000000, 0x2cc1eded, 0x60402020, 0x1fe3fcfc, 0xc879b1b1, 0xedb65b5b, + 0xbed46a6a, 0x468dcbcb, 0xd967bebe, 0x4b723939, 0xde944a4a, 0xd4984c4c, 0xe8b05858, 0x4a85cfcf, + 0x6bbbd0d0, 0x2ac5efef, 0xe54faaaa, 0x16edfbfb, 0xc5864343, 0xd79a4d4d, 0x55663333, 0x94118585, + 0xcf8a4545, 0x10e9f9f9, 0x06040202, 0x81fe7f7f, 0xf0a05050, 0x44783c3c, 0xba259f9f, 0xe34ba8a8, + 0xf3a25151, 0xfe5da3a3, 0xc0804040, 0x8a058f8f, 0xad3f9292, 0xbc219d9d, 0x48703838, 0x04f1f5f5, + 0xdf63bcbc, 0xc177b6b6, 0x75afdada, 0x63422121, 0x30201010, 0x1ae5ffff, 0x0efdf3f3, 0x6dbfd2d2, + 0x4c81cdcd, 0x14180c0c, 0x35261313, 0x2fc3ecec, 0xe1be5f5f, 0xa2359797, 0xcc884444, 0x392e1717, + 0x5793c4c4, 0xf255a7a7, 0x82fc7e7e, 0x477a3d3d, 0xacc86464, 0xe7ba5d5d, 0x2b321919, 0x95e67373, + 0xa0c06060, 0x98198181, 0xd19e4f4f, 0x7fa3dcdc, 0x66442222, 0x7e542a2a, 0xab3b9090, 0x830b8888, + 0xca8c4646, 0x29c7eeee, 0xd36bb8b8, 0x3c281414, 0x79a7dede, 0xe2bc5e5e, 0x1d160b0b, 0x76addbdb, + 0x3bdbe0e0, 0x56643232, 0x4e743a3a, 0x1e140a0a, 0xdb924949, 0x0a0c0606, 0x6c482424, 0xe4b85c5c, + 0x5d9fc2c2, 0x6ebdd3d3, 0xef43acac, 0xa6c46262, 0xa8399191, 0xa4319595, 0x37d3e4e4, 0x8bf27979, + 0x32d5e7e7, 0x438bc8c8, 0x596e3737, 0xb7da6d6d, 0x8c018d8d, 0x64b1d5d5, 0xd29c4e4e, 0xe049a9a9, + 0xb4d86c6c, 0xfaac5656, 0x07f3f4f4, 0x25cfeaea, 0xafca6565, 0x8ef47a7a, 0xe947aeae, 0x18100808, + 0xd56fbaba, 0x88f07878, 0x6f4a2525, 0x725c2e2e, 0x24381c1c, 0xf157a6a6, 0xc773b4b4, 0x5197c6c6, + 0x23cbe8e8, 0x7ca1dddd, 0x9ce87474, 0x213e1f1f, 0xdd964b4b, 0xdc61bdbd, 0x860d8b8b, 0x850f8a8a, + 0x90e07070, 0x427c3e3e, 0xc471b5b5, 0xaacc6666, 0xd8904848, 0x05060303, 0x01f7f6f6, 0x121c0e0e, + 0xa3c26161, 0x5f6a3535, 0xf9ae5757, 0xd069b9b9, 0x91178686, 0x5899c1c1, 0x273a1d1d, 0xb9279e9e, + 0x38d9e1e1, 0x13ebf8f8, 0xb32b9898, 0x33221111, 0xbbd26969, 0x70a9d9d9, 0x89078e8e, 0xa7339494, + 0xb62d9b9b, 0x223c1e1e, 0x92158787, 0x20c9e9e9, 0x4987cece, 0xffaa5555, 0x78502828, 0x7aa5dfdf, + 0x8f038c8c, 0xf859a1a1, 0x80098989, 0x171a0d0d, 0xda65bfbf, 0x31d7e6e6, 0xc6844242, 0xb8d06868, + 0xc3824141, 0xb0299999, 0x775a2d2d, 0x111e0f0f, 0xcb7bb0b0, 0xfca85454, 0xd66dbbbb, 0x3a2c1616 + }, + { + 0x63a5c663, 0x7c84f87c, 0x7799ee77, 0x7b8df67b, 0xf20dfff2, 0x6bbdd66b, 0x6fb1de6f, 0xc55491c5, + 0x30506030, 0x01030201, 0x67a9ce67, 0x2b7d562b, 0xfe19e7fe, 0xd762b5d7, 0xabe64dab, 0x769aec76, + 0xca458fca, 0x829d1f82, 0xc94089c9, 0x7d87fa7d, 0xfa15effa, 0x59ebb259, 0x47c98e47, 0xf00bfbf0, + 0xadec41ad, 0xd467b3d4, 0xa2fd5fa2, 0xafea45af, 0x9cbf239c, 0xa4f753a4, 0x7296e472, 0xc05b9bc0, + 0xb7c275b7, 0xfd1ce1fd, 0x93ae3d93, 0x266a4c26, 0x365a6c36, 0x3f417e3f, 0xf702f5f7, 0xcc4f83cc, + 0x345c6834, 0xa5f451a5, 0xe534d1e5, 0xf108f9f1, 0x7193e271, 0xd873abd8, 0x31536231, 0x153f2a15, + 0x040c0804, 0xc75295c7, 0x23654623, 0xc35e9dc3, 0x18283018, 0x96a13796, 0x050f0a05, 0x9ab52f9a, + 0x07090e07, 0x12362412, 0x809b1b80, 0xe23ddfe2, 0xeb26cdeb, 0x27694e27, 0xb2cd7fb2, 0x759fea75, + 0x091b1209, 0x839e1d83, 0x2c74582c, 0x1a2e341a, 0x1b2d361b, 0x6eb2dc6e, 0x5aeeb45a, 0xa0fb5ba0, + 0x52f6a452, 0x3b4d763b, 0xd661b7d6, 0xb3ce7db3, 0x297b5229, 0xe33edde3, 0x2f715e2f, 0x84971384, + 0x53f5a653, 0xd168b9d1, 0x00000000, 0xed2cc1ed, 0x20604020, 0xfc1fe3fc, 0xb1c879b1, 0x5bedb65b, + 0x6abed46a, 0xcb468dcb, 0xbed967be, 0x394b7239, 0x4ade944a, 0x4cd4984c, 0x58e8b058, 0xcf4a85cf, + 0xd06bbbd0, 0xef2ac5ef, 0xaae54faa, 0xfb16edfb, 0x43c58643, 0x4dd79a4d, 0x33556633, 0x85941185, + 0x45cf8a45, 0xf910e9f9, 0x02060402, 0x7f81fe7f, 0x50f0a050, 0x3c44783c, 0x9fba259f, 0xa8e34ba8, + 0x51f3a251, 0xa3fe5da3, 0x40c08040, 0x8f8a058f, 0x92ad3f92, 0x9dbc219d, 0x38487038, 0xf504f1f5, + 0xbcdf63bc, 0xb6c177b6, 0xda75afda, 0x21634221, 0x10302010, 0xff1ae5ff, 0xf30efdf3, 0xd26dbfd2, + 0xcd4c81cd, 0x0c14180c, 0x13352613, 0xec2fc3ec, 0x5fe1be5f, 0x97a23597, 0x44cc8844, 0x17392e17, + 0xc45793c4, 0xa7f255a7, 0x7e82fc7e, 0x3d477a3d, 0x64acc864, 0x5de7ba5d, 0x192b3219, 0x7395e673, + 0x60a0c060, 0x81981981, 0x4fd19e4f, 0xdc7fa3dc, 0x22664422, 0x2a7e542a, 0x90ab3b90, 0x88830b88, + 0x46ca8c46, 0xee29c7ee, 0xb8d36bb8, 0x143c2814, 0xde79a7de, 0x5ee2bc5e, 0x0b1d160b, 0xdb76addb, + 0xe03bdbe0, 0x32566432, 0x3a4e743a, 0x0a1e140a, 0x49db9249, 0x060a0c06, 0x246c4824, 0x5ce4b85c, + 0xc25d9fc2, 0xd36ebdd3, 0xacef43ac, 0x62a6c462, 0x91a83991, 0x95a43195, 0xe437d3e4, 0x798bf279, + 0xe732d5e7, 0xc8438bc8, 0x37596e37, 0x6db7da6d, 0x8d8c018d, 0xd564b1d5, 0x4ed29c4e, 0xa9e049a9, + 0x6cb4d86c, 0x56faac56, 0xf407f3f4, 0xea25cfea, 0x65afca65, 0x7a8ef47a, 0xaee947ae, 0x08181008, + 0xbad56fba, 0x7888f078, 0x256f4a25, 0x2e725c2e, 0x1c24381c, 0xa6f157a6, 0xb4c773b4, 0xc65197c6, + 0xe823cbe8, 0xdd7ca1dd, 0x749ce874, 0x1f213e1f, 0x4bdd964b, 0xbddc61bd, 0x8b860d8b, 0x8a850f8a, + 0x7090e070, 0x3e427c3e, 0xb5c471b5, 0x66aacc66, 0x48d89048, 0x03050603, 0xf601f7f6, 0x0e121c0e, + 0x61a3c261, 0x355f6a35, 0x57f9ae57, 0xb9d069b9, 0x86911786, 0xc15899c1, 0x1d273a1d, 0x9eb9279e, + 0xe138d9e1, 0xf813ebf8, 0x98b32b98, 0x11332211, 0x69bbd269, 0xd970a9d9, 0x8e89078e, 0x94a73394, + 0x9bb62d9b, 0x1e223c1e, 0x87921587, 0xe920c9e9, 0xce4987ce, 0x55ffaa55, 0x28785028, 0xdf7aa5df, + 0x8c8f038c, 0xa1f859a1, 0x89800989, 0x0d171a0d, 0xbfda65bf, 0xe631d7e6, 0x42c68442, 0x68b8d068, + 0x41c38241, 0x99b02999, 0x2d775a2d, 0x0f111e0f, 0xb0cb7bb0, 0x54fca854, 0xbbd66dbb, 0x163a2c16 + }, + { + 0x6363a5c6, 0x7c7c84f8, 0x777799ee, 0x7b7b8df6, 0xf2f20dff, 0x6b6bbdd6, 0x6f6fb1de, 0xc5c55491, + 0x30305060, 0x01010302, 0x6767a9ce, 0x2b2b7d56, 0xfefe19e7, 0xd7d762b5, 0xababe64d, 0x76769aec, + 0xcaca458f, 0x82829d1f, 0xc9c94089, 0x7d7d87fa, 0xfafa15ef, 0x5959ebb2, 0x4747c98e, 0xf0f00bfb, + 0xadadec41, 0xd4d467b3, 0xa2a2fd5f, 0xafafea45, 0x9c9cbf23, 0xa4a4f753, 0x727296e4, 0xc0c05b9b, + 0xb7b7c275, 0xfdfd1ce1, 0x9393ae3d, 0x26266a4c, 0x36365a6c, 0x3f3f417e, 0xf7f702f5, 0xcccc4f83, + 0x34345c68, 0xa5a5f451, 0xe5e534d1, 0xf1f108f9, 0x717193e2, 0xd8d873ab, 0x31315362, 0x15153f2a, + 0x04040c08, 0xc7c75295, 0x23236546, 0xc3c35e9d, 0x18182830, 0x9696a137, 0x05050f0a, 0x9a9ab52f, + 0x0707090e, 0x12123624, 0x80809b1b, 0xe2e23ddf, 0xebeb26cd, 0x2727694e, 0xb2b2cd7f, 0x75759fea, + 0x09091b12, 0x83839e1d, 0x2c2c7458, 0x1a1a2e34, 0x1b1b2d36, 0x6e6eb2dc, 0x5a5aeeb4, 0xa0a0fb5b, + 0x5252f6a4, 0x3b3b4d76, 0xd6d661b7, 0xb3b3ce7d, 0x29297b52, 0xe3e33edd, 0x2f2f715e, 0x84849713, + 0x5353f5a6, 0xd1d168b9, 0x00000000, 0xeded2cc1, 0x20206040, 0xfcfc1fe3, 0xb1b1c879, 0x5b5bedb6, + 0x6a6abed4, 0xcbcb468d, 0xbebed967, 0x39394b72, 0x4a4ade94, 0x4c4cd498, 0x5858e8b0, 0xcfcf4a85, + 0xd0d06bbb, 0xefef2ac5, 0xaaaae54f, 0xfbfb16ed, 0x4343c586, 0x4d4dd79a, 0x33335566, 0x85859411, + 0x4545cf8a, 0xf9f910e9, 0x02020604, 0x7f7f81fe, 0x5050f0a0, 0x3c3c4478, 0x9f9fba25, 0xa8a8e34b, + 0x5151f3a2, 0xa3a3fe5d, 0x4040c080, 0x8f8f8a05, 0x9292ad3f, 0x9d9dbc21, 0x38384870, 0xf5f504f1, + 0xbcbcdf63, 0xb6b6c177, 0xdada75af, 0x21216342, 0x10103020, 0xffff1ae5, 0xf3f30efd, 0xd2d26dbf, + 0xcdcd4c81, 0x0c0c1418, 0x13133526, 0xecec2fc3, 0x5f5fe1be, 0x9797a235, 0x4444cc88, 0x1717392e, + 0xc4c45793, 0xa7a7f255, 0x7e7e82fc, 0x3d3d477a, 0x6464acc8, 0x5d5de7ba, 0x19192b32, 0x737395e6, + 0x6060a0c0, 0x81819819, 0x4f4fd19e, 0xdcdc7fa3, 0x22226644, 0x2a2a7e54, 0x9090ab3b, 0x8888830b, + 0x4646ca8c, 0xeeee29c7, 0xb8b8d36b, 0x14143c28, 0xdede79a7, 0x5e5ee2bc, 0x0b0b1d16, 0xdbdb76ad, + 0xe0e03bdb, 0x32325664, 0x3a3a4e74, 0x0a0a1e14, 0x4949db92, 0x06060a0c, 0x24246c48, 0x5c5ce4b8, + 0xc2c25d9f, 0xd3d36ebd, 0xacacef43, 0x6262a6c4, 0x9191a839, 0x9595a431, 0xe4e437d3, 0x79798bf2, + 0xe7e732d5, 0xc8c8438b, 0x3737596e, 0x6d6db7da, 0x8d8d8c01, 0xd5d564b1, 0x4e4ed29c, 0xa9a9e049, + 0x6c6cb4d8, 0x5656faac, 0xf4f407f3, 0xeaea25cf, 0x6565afca, 0x7a7a8ef4, 0xaeaee947, 0x08081810, + 0xbabad56f, 0x787888f0, 0x25256f4a, 0x2e2e725c, 0x1c1c2438, 0xa6a6f157, 0xb4b4c773, 0xc6c65197, + 0xe8e823cb, 0xdddd7ca1, 0x74749ce8, 0x1f1f213e, 0x4b4bdd96, 0xbdbddc61, 0x8b8b860d, 0x8a8a850f, + 0x707090e0, 0x3e3e427c, 0xb5b5c471, 0x6666aacc, 0x4848d890, 0x03030506, 0xf6f601f7, 0x0e0e121c, + 0x6161a3c2, 0x35355f6a, 0x5757f9ae, 0xb9b9d069, 0x86869117, 0xc1c15899, 0x1d1d273a, 0x9e9eb927, + 0xe1e138d9, 0xf8f813eb, 0x9898b32b, 0x11113322, 0x6969bbd2, 0xd9d970a9, 0x8e8e8907, 0x9494a733, + 0x9b9bb62d, 0x1e1e223c, 0x87879215, 0xe9e920c9, 0xcece4987, 0x5555ffaa, 0x28287850, 0xdfdf7aa5, + 0x8c8c8f03, 0xa1a1f859, 0x89898009, 0x0d0d171a, 0xbfbfda65, 0xe6e631d7, 0x4242c684, 0x6868b8d0, + 0x4141c382, 0x9999b029, 0x2d2d775a, 0x0f0f111e, 0xb0b0cb7b, 0x5454fca8, 0xbbbbd66d, 0x16163a2c + }, + { + 0x63636363, 0x7c7c7c7c, 0x77777777, 0x7b7b7b7b, 0xf2f2f2f2, 0x6b6b6b6b, 0x6f6f6f6f, 0xc5c5c5c5, + 0x30303030, 0x01010101, 0x67676767, 0x2b2b2b2b, 0xfefefefe, 0xd7d7d7d7, 0xabababab, 0x76767676, + 0xcacacaca, 0x82828282, 0xc9c9c9c9, 0x7d7d7d7d, 0xfafafafa, 0x59595959, 0x47474747, 0xf0f0f0f0, + 0xadadadad, 0xd4d4d4d4, 0xa2a2a2a2, 0xafafafaf, 0x9c9c9c9c, 0xa4a4a4a4, 0x72727272, 0xc0c0c0c0, + 0xb7b7b7b7, 0xfdfdfdfd, 0x93939393, 0x26262626, 0x36363636, 0x3f3f3f3f, 0xf7f7f7f7, 0xcccccccc, + 0x34343434, 0xa5a5a5a5, 0xe5e5e5e5, 0xf1f1f1f1, 0x71717171, 0xd8d8d8d8, 0x31313131, 0x15151515, + 0x04040404, 0xc7c7c7c7, 0x23232323, 0xc3c3c3c3, 0x18181818, 0x96969696, 0x05050505, 0x9a9a9a9a, + 0x07070707, 0x12121212, 0x80808080, 0xe2e2e2e2, 0xebebebeb, 0x27272727, 0xb2b2b2b2, 0x75757575, + 0x09090909, 0x83838383, 0x2c2c2c2c, 0x1a1a1a1a, 0x1b1b1b1b, 0x6e6e6e6e, 0x5a5a5a5a, 0xa0a0a0a0, + 0x52525252, 0x3b3b3b3b, 0xd6d6d6d6, 0xb3b3b3b3, 0x29292929, 0xe3e3e3e3, 0x2f2f2f2f, 0x84848484, + 0x53535353, 0xd1d1d1d1, 0x00000000, 0xedededed, 0x20202020, 0xfcfcfcfc, 0xb1b1b1b1, 0x5b5b5b5b, + 0x6a6a6a6a, 0xcbcbcbcb, 0xbebebebe, 0x39393939, 0x4a4a4a4a, 0x4c4c4c4c, 0x58585858, 0xcfcfcfcf, + 0xd0d0d0d0, 0xefefefef, 0xaaaaaaaa, 0xfbfbfbfb, 0x43434343, 0x4d4d4d4d, 0x33333333, 0x85858585, + 0x45454545, 0xf9f9f9f9, 0x02020202, 0x7f7f7f7f, 0x50505050, 0x3c3c3c3c, 0x9f9f9f9f, 0xa8a8a8a8, + 0x51515151, 0xa3a3a3a3, 0x40404040, 0x8f8f8f8f, 0x92929292, 0x9d9d9d9d, 0x38383838, 0xf5f5f5f5, + 0xbcbcbcbc, 0xb6b6b6b6, 0xdadadada, 0x21212121, 0x10101010, 0xffffffff, 0xf3f3f3f3, 0xd2d2d2d2, + 0xcdcdcdcd, 0x0c0c0c0c, 0x13131313, 0xecececec, 0x5f5f5f5f, 0x97979797, 0x44444444, 0x17171717, + 0xc4c4c4c4, 0xa7a7a7a7, 0x7e7e7e7e, 0x3d3d3d3d, 0x64646464, 0x5d5d5d5d, 0x19191919, 0x73737373, + 0x60606060, 0x81818181, 0x4f4f4f4f, 0xdcdcdcdc, 0x22222222, 0x2a2a2a2a, 0x90909090, 0x88888888, + 0x46464646, 0xeeeeeeee, 0xb8b8b8b8, 0x14141414, 0xdededede, 0x5e5e5e5e, 0x0b0b0b0b, 0xdbdbdbdb, + 0xe0e0e0e0, 0x32323232, 0x3a3a3a3a, 0x0a0a0a0a, 0x49494949, 0x06060606, 0x24242424, 0x5c5c5c5c, + 0xc2c2c2c2, 0xd3d3d3d3, 0xacacacac, 0x62626262, 0x91919191, 0x95959595, 0xe4e4e4e4, 0x79797979, + 0xe7e7e7e7, 0xc8c8c8c8, 0x37373737, 0x6d6d6d6d, 0x8d8d8d8d, 0xd5d5d5d5, 0x4e4e4e4e, 0xa9a9a9a9, + 0x6c6c6c6c, 0x56565656, 0xf4f4f4f4, 0xeaeaeaea, 0x65656565, 0x7a7a7a7a, 0xaeaeaeae, 0x08080808, + 0xbabababa, 0x78787878, 0x25252525, 0x2e2e2e2e, 0x1c1c1c1c, 0xa6a6a6a6, 0xb4b4b4b4, 0xc6c6c6c6, + 0xe8e8e8e8, 0xdddddddd, 0x74747474, 0x1f1f1f1f, 0x4b4b4b4b, 0xbdbdbdbd, 0x8b8b8b8b, 0x8a8a8a8a, + 0x70707070, 0x3e3e3e3e, 0xb5b5b5b5, 0x66666666, 0x48484848, 0x03030303, 0xf6f6f6f6, 0x0e0e0e0e, + 0x61616161, 0x35353535, 0x57575757, 0xb9b9b9b9, 0x86868686, 0xc1c1c1c1, 0x1d1d1d1d, 0x9e9e9e9e, + 0xe1e1e1e1, 0xf8f8f8f8, 0x98989898, 0x11111111, 0x69696969, 0xd9d9d9d9, 0x8e8e8e8e, 0x94949494, + 0x9b9b9b9b, 0x1e1e1e1e, 0x87878787, 0xe9e9e9e9, 0xcececece, 0x55555555, 0x28282828, 0xdfdfdfdf, + 0x8c8c8c8c, 0xa1a1a1a1, 0x89898989, 0x0d0d0d0d, 0xbfbfbfbf, 0xe6e6e6e6, 0x42424242, 0x68686868, + 0x41414141, 0x99999999, 0x2d2d2d2d, 0x0f0f0f0f, 0xb0b0b0b0, 0x54545454, 0xbbbbbbbb, 0x16161616 + }, + { + 0x51f4a750, 0x7e416553, 0x1a17a4c3, 0x3a275e96, 0x3bab6bcb, 0x1f9d45f1, 0xacfa58ab, 0x4be30393, + 0x2030fa55, 0xad766df6, 0x88cc7691, 0xf5024c25, 0x4fe5d7fc, 0xc52acbd7, 0x26354480, 0xb562a38f, + 0xdeb15a49, 0x25ba1b67, 0x45ea0e98, 0x5dfec0e1, 0xc32f7502, 0x814cf012, 0x8d4697a3, 0x6bd3f9c6, + 0x038f5fe7, 0x15929c95, 0xbf6d7aeb, 0x955259da, 0xd4be832d, 0x587421d3, 0x49e06929, 0x8ec9c844, + 0x75c2896a, 0xf48e7978, 0x99583e6b, 0x27b971dd, 0xbee14fb6, 0xf088ad17, 0xc920ac66, 0x7dce3ab4, + 0x63df4a18, 0xe51a3182, 0x97513360, 0x62537f45, 0xb16477e0, 0xbb6bae84, 0xfe81a01c, 0xf9082b94, + 0x70486858, 0x8f45fd19, 0x94de6c87, 0x527bf8b7, 0xab73d323, 0x724b02e2, 0xe31f8f57, 0x6655ab2a, + 0xb2eb2807, 0x2fb5c203, 0x86c57b9a, 0xd33708a5, 0x302887f2, 0x23bfa5b2, 0x02036aba, 0xed16825c, + 0x8acf1c2b, 0xa779b492, 0xf307f2f0, 0x4e69e2a1, 0x65daf4cd, 0x0605bed5, 0xd134621f, 0xc4a6fe8a, + 0x342e539d, 0xa2f355a0, 0x058ae132, 0xa4f6eb75, 0x0b83ec39, 0x4060efaa, 0x5e719f06, 0xbd6e1051, + 0x3e218af9, 0x96dd063d, 0xdd3e05ae, 0x4de6bd46, 0x91548db5, 0x71c45d05, 0x0406d46f, 0x605015ff, + 0x1998fb24, 0xd6bde997, 0x894043cc, 0x67d99e77, 0xb0e842bd, 0x07898b88, 0xe7195b38, 0x79c8eedb, + 0xa17c0a47, 0x7c420fe9, 0xf8841ec9, 0x00000000, 0x09808683, 0x322bed48, 0x1e1170ac, 0x6c5a724e, + 0xfd0efffb, 0x0f853856, 0x3daed51e, 0x362d3927, 0x0a0fd964, 0x685ca621, 0x9b5b54d1, 0x24362e3a, + 0x0c0a67b1, 0x9357e70f, 0xb4ee96d2, 0x1b9b919e, 0x80c0c54f, 0x61dc20a2, 0x5a774b69, 0x1c121a16, + 0xe293ba0a, 0xc0a02ae5, 0x3c22e043, 0x121b171d, 0x0e090d0b, 0xf28bc7ad, 0x2db6a8b9, 0x141ea9c8, + 0x57f11985, 0xaf75074c, 0xee99ddbb, 0xa37f60fd, 0xf701269f, 0x5c72f5bc, 0x44663bc5, 0x5bfb7e34, + 0x8b432976, 0xcb23c6dc, 0xb6edfc68, 0xb8e4f163, 0xd731dcca, 0x42638510, 0x13972240, 0x84c61120, + 0x854a247d, 0xd2bb3df8, 0xaef93211, 0xc729a16d, 0x1d9e2f4b, 0xdcb230f3, 0x0d8652ec, 0x77c1e3d0, + 0x2bb3166c, 0xa970b999, 0x119448fa, 0x47e96422, 0xa8fc8cc4, 0xa0f03f1a, 0x567d2cd8, 0x223390ef, + 0x87494ec7, 0xd938d1c1, 0x8ccaa2fe, 0x98d40b36, 0xa6f581cf, 0xa57ade28, 0xdab78e26, 0x3fadbfa4, + 0x2c3a9de4, 0x5078920d, 0x6a5fcc9b, 0x547e4662, 0xf68d13c2, 0x90d8b8e8, 0x2e39f75e, 0x82c3aff5, + 0x9f5d80be, 0x69d0937c, 0x6fd52da9, 0xcf2512b3, 0xc8ac993b, 0x10187da7, 0xe89c636e, 0xdb3bbb7b, + 0xcd267809, 0x6e5918f4, 0xec9ab701, 0x834f9aa8, 0xe6956e65, 0xaaffe67e, 0x21bccf08, 0xef15e8e6, + 0xbae79bd9, 0x4a6f36ce, 0xea9f09d4, 0x29b07cd6, 0x31a4b2af, 0x2a3f2331, 0xc6a59430, 0x35a266c0, + 0x744ebc37, 0xfc82caa6, 0xe090d0b0, 0x33a7d815, 0xf104984a, 0x41ecdaf7, 0x7fcd500e, 0x1791f62f, + 0x764dd68d, 0x43efb04d, 0xccaa4d54, 0xe49604df, 0x9ed1b5e3, 0x4c6a881b, 0xc12c1fb8, 0x4665517f, + 0x9d5eea04, 0x018c355d, 0xfa877473, 0xfb0b412e, 0xb3671d5a, 0x92dbd252, 0xe9105633, 0x6dd64713, + 0x9ad7618c, 0x37a10c7a, 0x59f8148e, 0xeb133c89, 0xcea927ee, 0xb761c935, 0xe11ce5ed, 0x7a47b13c, + 0x9cd2df59, 0x55f2733f, 0x1814ce79, 0x73c737bf, 0x53f7cdea, 0x5ffdaa5b, 0xdf3d6f14, 0x7844db86, + 0xcaaff381, 0xb968c43e, 0x3824342c, 0xc2a3405f, 0x161dc372, 0xbce2250c, 0x283c498b, 0xff0d9541, + 0x39a80171, 0x080cb3de, 0xd8b4e49c, 0x6456c190, 0x7bcb8461, 0xd532b670, 0x486c5c74, 0xd0b85742 + }, + { + 0x5051f4a7, 0x537e4165, 0xc31a17a4, 0x963a275e, 0xcb3bab6b, 0xf11f9d45, 0xabacfa58, 0x934be303, + 0x552030fa, 0xf6ad766d, 0x9188cc76, 0x25f5024c, 0xfc4fe5d7, 0xd7c52acb, 0x80263544, 0x8fb562a3, + 0x49deb15a, 0x6725ba1b, 0x9845ea0e, 0xe15dfec0, 0x02c32f75, 0x12814cf0, 0xa38d4697, 0xc66bd3f9, + 0xe7038f5f, 0x9515929c, 0xebbf6d7a, 0xda955259, 0x2dd4be83, 0xd3587421, 0x2949e069, 0x448ec9c8, + 0x6a75c289, 0x78f48e79, 0x6b99583e, 0xdd27b971, 0xb6bee14f, 0x17f088ad, 0x66c920ac, 0xb47dce3a, + 0x1863df4a, 0x82e51a31, 0x60975133, 0x4562537f, 0xe0b16477, 0x84bb6bae, 0x1cfe81a0, 0x94f9082b, + 0x58704868, 0x198f45fd, 0x8794de6c, 0xb7527bf8, 0x23ab73d3, 0xe2724b02, 0x57e31f8f, 0x2a6655ab, + 0x07b2eb28, 0x032fb5c2, 0x9a86c57b, 0xa5d33708, 0xf2302887, 0xb223bfa5, 0xba02036a, 0x5ced1682, + 0x2b8acf1c, 0x92a779b4, 0xf0f307f2, 0xa14e69e2, 0xcd65daf4, 0xd50605be, 0x1fd13462, 0x8ac4a6fe, + 0x9d342e53, 0xa0a2f355, 0x32058ae1, 0x75a4f6eb, 0x390b83ec, 0xaa4060ef, 0x065e719f, 0x51bd6e10, + 0xf93e218a, 0x3d96dd06, 0xaedd3e05, 0x464de6bd, 0xb591548d, 0x0571c45d, 0x6f0406d4, 0xff605015, + 0x241998fb, 0x97d6bde9, 0xcc894043, 0x7767d99e, 0xbdb0e842, 0x8807898b, 0x38e7195b, 0xdb79c8ee, + 0x47a17c0a, 0xe97c420f, 0xc9f8841e, 0x00000000, 0x83098086, 0x48322bed, 0xac1e1170, 0x4e6c5a72, + 0xfbfd0eff, 0x560f8538, 0x1e3daed5, 0x27362d39, 0x640a0fd9, 0x21685ca6, 0xd19b5b54, 0x3a24362e, + 0xb10c0a67, 0x0f9357e7, 0xd2b4ee96, 0x9e1b9b91, 0x4f80c0c5, 0xa261dc20, 0x695a774b, 0x161c121a, + 0x0ae293ba, 0xe5c0a02a, 0x433c22e0, 0x1d121b17, 0x0b0e090d, 0xadf28bc7, 0xb92db6a8, 0xc8141ea9, + 0x8557f119, 0x4caf7507, 0xbbee99dd, 0xfda37f60, 0x9ff70126, 0xbc5c72f5, 0xc544663b, 0x345bfb7e, + 0x768b4329, 0xdccb23c6, 0x68b6edfc, 0x63b8e4f1, 0xcad731dc, 0x10426385, 0x40139722, 0x2084c611, + 0x7d854a24, 0xf8d2bb3d, 0x11aef932, 0x6dc729a1, 0x4b1d9e2f, 0xf3dcb230, 0xec0d8652, 0xd077c1e3, + 0x6c2bb316, 0x99a970b9, 0xfa119448, 0x2247e964, 0xc4a8fc8c, 0x1aa0f03f, 0xd8567d2c, 0xef223390, + 0xc787494e, 0xc1d938d1, 0xfe8ccaa2, 0x3698d40b, 0xcfa6f581, 0x28a57ade, 0x26dab78e, 0xa43fadbf, + 0xe42c3a9d, 0x0d507892, 0x9b6a5fcc, 0x62547e46, 0xc2f68d13, 0xe890d8b8, 0x5e2e39f7, 0xf582c3af, + 0xbe9f5d80, 0x7c69d093, 0xa96fd52d, 0xb3cf2512, 0x3bc8ac99, 0xa710187d, 0x6ee89c63, 0x7bdb3bbb, + 0x09cd2678, 0xf46e5918, 0x01ec9ab7, 0xa8834f9a, 0x65e6956e, 0x7eaaffe6, 0x0821bccf, 0xe6ef15e8, + 0xd9bae79b, 0xce4a6f36, 0xd4ea9f09, 0xd629b07c, 0xaf31a4b2, 0x312a3f23, 0x30c6a594, 0xc035a266, + 0x37744ebc, 0xa6fc82ca, 0xb0e090d0, 0x1533a7d8, 0x4af10498, 0xf741ecda, 0x0e7fcd50, 0x2f1791f6, + 0x8d764dd6, 0x4d43efb0, 0x54ccaa4d, 0xdfe49604, 0xe39ed1b5, 0x1b4c6a88, 0xb8c12c1f, 0x7f466551, + 0x049d5eea, 0x5d018c35, 0x73fa8774, 0x2efb0b41, 0x5ab3671d, 0x5292dbd2, 0x33e91056, 0x136dd647, + 0x8c9ad761, 0x7a37a10c, 0x8e59f814, 0x89eb133c, 0xeecea927, 0x35b761c9, 0xede11ce5, 0x3c7a47b1, + 0x599cd2df, 0x3f55f273, 0x791814ce, 0xbf73c737, 0xea53f7cd, 0x5b5ffdaa, 0x14df3d6f, 0x867844db, + 0x81caaff3, 0x3eb968c4, 0x2c382434, 0x5fc2a340, 0x72161dc3, 0x0cbce225, 0x8b283c49, 0x41ff0d95, + 0x7139a801, 0xde080cb3, 0x9cd8b4e4, 0x906456c1, 0x617bcb84, 0x70d532b6, 0x74486c5c, 0x42d0b857 + }, + { + 0xa75051f4, 0x65537e41, 0xa4c31a17, 0x5e963a27, 0x6bcb3bab, 0x45f11f9d, 0x58abacfa, 0x03934be3, + 0xfa552030, 0x6df6ad76, 0x769188cc, 0x4c25f502, 0xd7fc4fe5, 0xcbd7c52a, 0x44802635, 0xa38fb562, + 0x5a49deb1, 0x1b6725ba, 0x0e9845ea, 0xc0e15dfe, 0x7502c32f, 0xf012814c, 0x97a38d46, 0xf9c66bd3, + 0x5fe7038f, 0x9c951592, 0x7aebbf6d, 0x59da9552, 0x832dd4be, 0x21d35874, 0x692949e0, 0xc8448ec9, + 0x896a75c2, 0x7978f48e, 0x3e6b9958, 0x71dd27b9, 0x4fb6bee1, 0xad17f088, 0xac66c920, 0x3ab47dce, + 0x4a1863df, 0x3182e51a, 0x33609751, 0x7f456253, 0x77e0b164, 0xae84bb6b, 0xa01cfe81, 0x2b94f908, + 0x68587048, 0xfd198f45, 0x6c8794de, 0xf8b7527b, 0xd323ab73, 0x02e2724b, 0x8f57e31f, 0xab2a6655, + 0x2807b2eb, 0xc2032fb5, 0x7b9a86c5, 0x08a5d337, 0x87f23028, 0xa5b223bf, 0x6aba0203, 0x825ced16, + 0x1c2b8acf, 0xb492a779, 0xf2f0f307, 0xe2a14e69, 0xf4cd65da, 0xbed50605, 0x621fd134, 0xfe8ac4a6, + 0x539d342e, 0x55a0a2f3, 0xe132058a, 0xeb75a4f6, 0xec390b83, 0xefaa4060, 0x9f065e71, 0x1051bd6e, + 0x8af93e21, 0x063d96dd, 0x05aedd3e, 0xbd464de6, 0x8db59154, 0x5d0571c4, 0xd46f0406, 0x15ff6050, + 0xfb241998, 0xe997d6bd, 0x43cc8940, 0x9e7767d9, 0x42bdb0e8, 0x8b880789, 0x5b38e719, 0xeedb79c8, + 0x0a47a17c, 0x0fe97c42, 0x1ec9f884, 0x00000000, 0x86830980, 0xed48322b, 0x70ac1e11, 0x724e6c5a, + 0xfffbfd0e, 0x38560f85, 0xd51e3dae, 0x3927362d, 0xd9640a0f, 0xa621685c, 0x54d19b5b, 0x2e3a2436, + 0x67b10c0a, 0xe70f9357, 0x96d2b4ee, 0x919e1b9b, 0xc54f80c0, 0x20a261dc, 0x4b695a77, 0x1a161c12, + 0xba0ae293, 0x2ae5c0a0, 0xe0433c22, 0x171d121b, 0x0d0b0e09, 0xc7adf28b, 0xa8b92db6, 0xa9c8141e, + 0x198557f1, 0x074caf75, 0xddbbee99, 0x60fda37f, 0x269ff701, 0xf5bc5c72, 0x3bc54466, 0x7e345bfb, + 0x29768b43, 0xc6dccb23, 0xfc68b6ed, 0xf163b8e4, 0xdccad731, 0x85104263, 0x22401397, 0x112084c6, + 0x247d854a, 0x3df8d2bb, 0x3211aef9, 0xa16dc729, 0x2f4b1d9e, 0x30f3dcb2, 0x52ec0d86, 0xe3d077c1, + 0x166c2bb3, 0xb999a970, 0x48fa1194, 0x642247e9, 0x8cc4a8fc, 0x3f1aa0f0, 0x2cd8567d, 0x90ef2233, + 0x4ec78749, 0xd1c1d938, 0xa2fe8cca, 0x0b3698d4, 0x81cfa6f5, 0xde28a57a, 0x8e26dab7, 0xbfa43fad, + 0x9de42c3a, 0x920d5078, 0xcc9b6a5f, 0x4662547e, 0x13c2f68d, 0xb8e890d8, 0xf75e2e39, 0xaff582c3, + 0x80be9f5d, 0x937c69d0, 0x2da96fd5, 0x12b3cf25, 0x993bc8ac, 0x7da71018, 0x636ee89c, 0xbb7bdb3b, + 0x7809cd26, 0x18f46e59, 0xb701ec9a, 0x9aa8834f, 0x6e65e695, 0xe67eaaff, 0xcf0821bc, 0xe8e6ef15, + 0x9bd9bae7, 0x36ce4a6f, 0x09d4ea9f, 0x7cd629b0, 0xb2af31a4, 0x23312a3f, 0x9430c6a5, 0x66c035a2, + 0xbc37744e, 0xcaa6fc82, 0xd0b0e090, 0xd81533a7, 0x984af104, 0xdaf741ec, 0x500e7fcd, 0xf62f1791, + 0xd68d764d, 0xb04d43ef, 0x4d54ccaa, 0x04dfe496, 0xb5e39ed1, 0x881b4c6a, 0x1fb8c12c, 0x517f4665, + 0xea049d5e, 0x355d018c, 0x7473fa87, 0x412efb0b, 0x1d5ab367, 0xd25292db, 0x5633e910, 0x47136dd6, + 0x618c9ad7, 0x0c7a37a1, 0x148e59f8, 0x3c89eb13, 0x27eecea9, 0xc935b761, 0xe5ede11c, 0xb13c7a47, + 0xdf599cd2, 0x733f55f2, 0xce791814, 0x37bf73c7, 0xcdea53f7, 0xaa5b5ffd, 0x6f14df3d, 0xdb867844, + 0xf381caaf, 0xc43eb968, 0x342c3824, 0x405fc2a3, 0xc372161d, 0x250cbce2, 0x498b283c, 0x9541ff0d, + 0x017139a8, 0xb3de080c, 0xe49cd8b4, 0xc1906456, 0x84617bcb, 0xb670d532, 0x5c74486c, 0x5742d0b8 + }, + { + 0xf4a75051, 0x4165537e, 0x17a4c31a, 0x275e963a, 0xab6bcb3b, 0x9d45f11f, 0xfa58abac, 0xe303934b, + 0x30fa5520, 0x766df6ad, 0xcc769188, 0x024c25f5, 0xe5d7fc4f, 0x2acbd7c5, 0x35448026, 0x62a38fb5, + 0xb15a49de, 0xba1b6725, 0xea0e9845, 0xfec0e15d, 0x2f7502c3, 0x4cf01281, 0x4697a38d, 0xd3f9c66b, + 0x8f5fe703, 0x929c9515, 0x6d7aebbf, 0x5259da95, 0xbe832dd4, 0x7421d358, 0xe0692949, 0xc9c8448e, + 0xc2896a75, 0x8e7978f4, 0x583e6b99, 0xb971dd27, 0xe14fb6be, 0x88ad17f0, 0x20ac66c9, 0xce3ab47d, + 0xdf4a1863, 0x1a3182e5, 0x51336097, 0x537f4562, 0x6477e0b1, 0x6bae84bb, 0x81a01cfe, 0x082b94f9, + 0x48685870, 0x45fd198f, 0xde6c8794, 0x7bf8b752, 0x73d323ab, 0x4b02e272, 0x1f8f57e3, 0x55ab2a66, + 0xeb2807b2, 0xb5c2032f, 0xc57b9a86, 0x3708a5d3, 0x2887f230, 0xbfa5b223, 0x036aba02, 0x16825ced, + 0xcf1c2b8a, 0x79b492a7, 0x07f2f0f3, 0x69e2a14e, 0xdaf4cd65, 0x05bed506, 0x34621fd1, 0xa6fe8ac4, + 0x2e539d34, 0xf355a0a2, 0x8ae13205, 0xf6eb75a4, 0x83ec390b, 0x60efaa40, 0x719f065e, 0x6e1051bd, + 0x218af93e, 0xdd063d96, 0x3e05aedd, 0xe6bd464d, 0x548db591, 0xc45d0571, 0x06d46f04, 0x5015ff60, + 0x98fb2419, 0xbde997d6, 0x4043cc89, 0xd99e7767, 0xe842bdb0, 0x898b8807, 0x195b38e7, 0xc8eedb79, + 0x7c0a47a1, 0x420fe97c, 0x841ec9f8, 0x00000000, 0x80868309, 0x2bed4832, 0x1170ac1e, 0x5a724e6c, + 0x0efffbfd, 0x8538560f, 0xaed51e3d, 0x2d392736, 0x0fd9640a, 0x5ca62168, 0x5b54d19b, 0x362e3a24, + 0x0a67b10c, 0x57e70f93, 0xee96d2b4, 0x9b919e1b, 0xc0c54f80, 0xdc20a261, 0x774b695a, 0x121a161c, + 0x93ba0ae2, 0xa02ae5c0, 0x22e0433c, 0x1b171d12, 0x090d0b0e, 0x8bc7adf2, 0xb6a8b92d, 0x1ea9c814, + 0xf1198557, 0x75074caf, 0x99ddbbee, 0x7f60fda3, 0x01269ff7, 0x72f5bc5c, 0x663bc544, 0xfb7e345b, + 0x4329768b, 0x23c6dccb, 0xedfc68b6, 0xe4f163b8, 0x31dccad7, 0x63851042, 0x97224013, 0xc6112084, + 0x4a247d85, 0xbb3df8d2, 0xf93211ae, 0x29a16dc7, 0x9e2f4b1d, 0xb230f3dc, 0x8652ec0d, 0xc1e3d077, + 0xb3166c2b, 0x70b999a9, 0x9448fa11, 0xe9642247, 0xfc8cc4a8, 0xf03f1aa0, 0x7d2cd856, 0x3390ef22, + 0x494ec787, 0x38d1c1d9, 0xcaa2fe8c, 0xd40b3698, 0xf581cfa6, 0x7ade28a5, 0xb78e26da, 0xadbfa43f, + 0x3a9de42c, 0x78920d50, 0x5fcc9b6a, 0x7e466254, 0x8d13c2f6, 0xd8b8e890, 0x39f75e2e, 0xc3aff582, + 0x5d80be9f, 0xd0937c69, 0xd52da96f, 0x2512b3cf, 0xac993bc8, 0x187da710, 0x9c636ee8, 0x3bbb7bdb, + 0x267809cd, 0x5918f46e, 0x9ab701ec, 0x4f9aa883, 0x956e65e6, 0xffe67eaa, 0xbccf0821, 0x15e8e6ef, + 0xe79bd9ba, 0x6f36ce4a, 0x9f09d4ea, 0xb07cd629, 0xa4b2af31, 0x3f23312a, 0xa59430c6, 0xa266c035, + 0x4ebc3774, 0x82caa6fc, 0x90d0b0e0, 0xa7d81533, 0x04984af1, 0xecdaf741, 0xcd500e7f, 0x91f62f17, + 0x4dd68d76, 0xefb04d43, 0xaa4d54cc, 0x9604dfe4, 0xd1b5e39e, 0x6a881b4c, 0x2c1fb8c1, 0x65517f46, + 0x5eea049d, 0x8c355d01, 0x877473fa, 0x0b412efb, 0x671d5ab3, 0xdbd25292, 0x105633e9, 0xd647136d, + 0xd7618c9a, 0xa10c7a37, 0xf8148e59, 0x133c89eb, 0xa927eece, 0x61c935b7, 0x1ce5ede1, 0x47b13c7a, + 0xd2df599c, 0xf2733f55, 0x14ce7918, 0xc737bf73, 0xf7cdea53, 0xfdaa5b5f, 0x3d6f14df, 0x44db8678, + 0xaff381ca, 0x68c43eb9, 0x24342c38, 0xa3405fc2, 0x1dc37216, 0xe2250cbc, 0x3c498b28, 0x0d9541ff, + 0xa8017139, 0x0cb3de08, 0xb4e49cd8, 0x56c19064, 0xcb84617b, 0x32b670d5, 0x6c5c7448, 0xb85742d0 + }, + { + 0x52525252, 0x09090909, 0x6a6a6a6a, 0xd5d5d5d5, 0x30303030, 0x36363636, 0xa5a5a5a5, 0x38383838, + 0xbfbfbfbf, 0x40404040, 0xa3a3a3a3, 0x9e9e9e9e, 0x81818181, 0xf3f3f3f3, 0xd7d7d7d7, 0xfbfbfbfb, + 0x7c7c7c7c, 0xe3e3e3e3, 0x39393939, 0x82828282, 0x9b9b9b9b, 0x2f2f2f2f, 0xffffffff, 0x87878787, + 0x34343434, 0x8e8e8e8e, 0x43434343, 0x44444444, 0xc4c4c4c4, 0xdededede, 0xe9e9e9e9, 0xcbcbcbcb, + 0x54545454, 0x7b7b7b7b, 0x94949494, 0x32323232, 0xa6a6a6a6, 0xc2c2c2c2, 0x23232323, 0x3d3d3d3d, + 0xeeeeeeee, 0x4c4c4c4c, 0x95959595, 0x0b0b0b0b, 0x42424242, 0xfafafafa, 0xc3c3c3c3, 0x4e4e4e4e, + 0x08080808, 0x2e2e2e2e, 0xa1a1a1a1, 0x66666666, 0x28282828, 0xd9d9d9d9, 0x24242424, 0xb2b2b2b2, + 0x76767676, 0x5b5b5b5b, 0xa2a2a2a2, 0x49494949, 0x6d6d6d6d, 0x8b8b8b8b, 0xd1d1d1d1, 0x25252525, + 0x72727272, 0xf8f8f8f8, 0xf6f6f6f6, 0x64646464, 0x86868686, 0x68686868, 0x98989898, 0x16161616, + 0xd4d4d4d4, 0xa4a4a4a4, 0x5c5c5c5c, 0xcccccccc, 0x5d5d5d5d, 0x65656565, 0xb6b6b6b6, 0x92929292, + 0x6c6c6c6c, 0x70707070, 0x48484848, 0x50505050, 0xfdfdfdfd, 0xedededed, 0xb9b9b9b9, 0xdadadada, + 0x5e5e5e5e, 0x15151515, 0x46464646, 0x57575757, 0xa7a7a7a7, 0x8d8d8d8d, 0x9d9d9d9d, 0x84848484, + 0x90909090, 0xd8d8d8d8, 0xabababab, 0x00000000, 0x8c8c8c8c, 0xbcbcbcbc, 0xd3d3d3d3, 0x0a0a0a0a, + 0xf7f7f7f7, 0xe4e4e4e4, 0x58585858, 0x05050505, 0xb8b8b8b8, 0xb3b3b3b3, 0x45454545, 0x06060606, + 0xd0d0d0d0, 0x2c2c2c2c, 0x1e1e1e1e, 0x8f8f8f8f, 0xcacacaca, 0x3f3f3f3f, 0x0f0f0f0f, 0x02020202, + 0xc1c1c1c1, 0xafafafaf, 0xbdbdbdbd, 0x03030303, 0x01010101, 0x13131313, 0x8a8a8a8a, 0x6b6b6b6b, + 0x3a3a3a3a, 0x91919191, 0x11111111, 0x41414141, 0x4f4f4f4f, 0x67676767, 0xdcdcdcdc, 0xeaeaeaea, + 0x97979797, 0xf2f2f2f2, 0xcfcfcfcf, 0xcececece, 0xf0f0f0f0, 0xb4b4b4b4, 0xe6e6e6e6, 0x73737373, + 0x96969696, 0xacacacac, 0x74747474, 0x22222222, 0xe7e7e7e7, 0xadadadad, 0x35353535, 0x85858585, + 0xe2e2e2e2, 0xf9f9f9f9, 0x37373737, 0xe8e8e8e8, 0x1c1c1c1c, 0x75757575, 0xdfdfdfdf, 0x6e6e6e6e, + 0x47474747, 0xf1f1f1f1, 0x1a1a1a1a, 0x71717171, 0x1d1d1d1d, 0x29292929, 0xc5c5c5c5, 0x89898989, + 0x6f6f6f6f, 0xb7b7b7b7, 0x62626262, 0x0e0e0e0e, 0xaaaaaaaa, 0x18181818, 0xbebebebe, 0x1b1b1b1b, + 0xfcfcfcfc, 0x56565656, 0x3e3e3e3e, 0x4b4b4b4b, 0xc6c6c6c6, 0xd2d2d2d2, 0x79797979, 0x20202020, + 0x9a9a9a9a, 0xdbdbdbdb, 0xc0c0c0c0, 0xfefefefe, 0x78787878, 0xcdcdcdcd, 0x5a5a5a5a, 0xf4f4f4f4, + 0x1f1f1f1f, 0xdddddddd, 0xa8a8a8a8, 0x33333333, 0x88888888, 0x07070707, 0xc7c7c7c7, 0x31313131, + 0xb1b1b1b1, 0x12121212, 0x10101010, 0x59595959, 0x27272727, 0x80808080, 0xecececec, 0x5f5f5f5f, + 0x60606060, 0x51515151, 0x7f7f7f7f, 0xa9a9a9a9, 0x19191919, 0xb5b5b5b5, 0x4a4a4a4a, 0x0d0d0d0d, + 0x2d2d2d2d, 0xe5e5e5e5, 0x7a7a7a7a, 0x9f9f9f9f, 0x93939393, 0xc9c9c9c9, 0x9c9c9c9c, 0xefefefef, + 0xa0a0a0a0, 0xe0e0e0e0, 0x3b3b3b3b, 0x4d4d4d4d, 0xaeaeaeae, 0x2a2a2a2a, 0xf5f5f5f5, 0xb0b0b0b0, + 0xc8c8c8c8, 0xebebebeb, 0xbbbbbbbb, 0x3c3c3c3c, 0x83838383, 0x53535353, 0x99999999, 0x61616161, + 0x17171717, 0x2b2b2b2b, 0x04040404, 0x7e7e7e7e, 0xbabababa, 0x77777777, 0xd6d6d6d6, 0x26262626, + 0xe1e1e1e1, 0x69696969, 0x14141414, 0x63636363, 0x55555555, 0x21212121, 0x0c0c0c0c, 0x7d7d7d7d + } +}; +static const u32 gAtermAesRoundConstants[10] = { + 0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000, + 0x20000000, 0x40000000, 0x80000000, 0x1b000000, 0x36000000 +}; +extern int SOBind(int socket, void* address); +extern int SORecvFrom(int socket, void* buffer, int length, int flags, void* address); +extern int SOSendTo(int socket, const void* buffer, int length, int flags, void* address); + +typedef struct { + NCDIpConfig ipConfig; + NCDIfConfig ifConfig; +} AtermNetworkSettings; + +typedef struct { + u32 ssidLength; + u8 ssid[32]; + u8 reserved[4]; + u8 bssid[6]; + u16 status; +} AtermApRecord; + +typedef struct { + u32 count; + AtermApRecord entries[1]; +} AtermApRecordSet; + +typedef struct { + u16 sequence; + u16 length; + u16 checksum; + u8 payload[1]; +} AtermPacket; + +typedef struct { + u16 type; + u16 length; + u8 value[1]; +} AtermPacketOption; + +typedef struct { + u16 type; + u16 length; + u8 value[12]; +} AtermRequestOption16; + +typedef struct { + u16 type; + u16 length; + u8 value[20]; +} AtermRequestOption24; + +typedef struct { + u8 firstAddress[6]; + u8 secondAddress[6]; + char productName[4]; +} AtermAssociationRequest; + +typedef struct { + u8 length; + u8 family; + u16 port; + u32 address; +} AtermSocketAddress; + +typedef struct { + s32 state; + s32 remainingTime; + s32 result; +} AtermProgress; + +typedef struct { + u32 word0; + u32 word1; + u32 word2; + u32 word3; + u32 word4; + u32 word5; + u32 word6; + u32 word7; + u16 finalWord; +} AtermSsidClear; + +typedef union { + AtermSsidClear clear; + char text[36]; +} AtermSsidBuffer; + +typedef struct { + u32 keyFormat; + u32 keyLength; + char key[32]; +} AtermWirelessKey; + +typedef struct { + u8 reserved000[0x100]; + char ssid[32]; + u8 reserved120[12]; + s32 selectedSecurity; + u32 authAlgorithm; + u8 reserved134[0x28]; + AtermWirelessKey wirelessKeys[4]; + u8 sharedKey[0x48]; + u8 trailingData[0x14]; +} AtermScanSettings; + +typedef struct { + char ssid[32]; + u32 setupMode; + u32 securityMode; + u8 reserved028[0x80]; + u8 keyMaterial[0x40]; + u8 connectionPrefix[0x10]; + u8 packetBuffer[0x800]; + u16 responseLength; + u8 trailingData[6]; +} AtermConfigurationResult; + +typedef struct { + u8 data[0x818]; +} AtermThreadBuffer; + +typedef void (*AtermProgressCallback)(void*); +typedef void* (*AtermAllocateCallback)(u32); +typedef void (*AtermFreeCallback)(void*); + +AtermNetworkSettings gNetworkSettings; +char gAccessPointName[0x24]; +AtermScanSettings gScanSettings; +AtermConfigurationResult gAtermConfigurationResult; +AtermThreadBuffer gAtermResponseBuffer; +static OSThread sAtermThread; +u32 gAtermDeadline = 0xFFFFFFFF; +u32 gAtermScanLimit = 0x40; +u32 gAtermScanBufferSize = 0x800; +u32 gDefaultIpAddress = 0xC0A800B0; +u32 gDefaultSubnetMask = 0xFFFFFF00; +u32 gDefaultGateway = 0xC0A80001; +u32 gDefaultPrimaryDns = 0xC0A80001; +u32 gDefaultSecondaryDns = 0xC0A80001; +char gAtermAossSsid[7] = "******"; +u32 gAtermUseSharedAddress = 1; +char gAtermProductName[5] = "WARP"; +u32 gAtermCancelRequested; +u8 gAtermSelectedBssid[8]; +u32 gAtermProtocolState; +u8 gAtermAddressBuffer[8]; +u32 gAtermResponseMode; +u8 gAtermMode; +u32 gAtermReplyLength; +u32 gAtermMessageLength; +u32 gAtermSocketStarted; +u32 gAtermSocketReady; +u32 gAtermSelectedRecordIndex; +u32 gAtermThreadStarted; +void* gAtermAllocation; +AtermFreeCallback gAtermRelease; +AtermAllocateCallback gAtermAllocate; +AtermProgressCallback gAtermProgressCallback; +u32 gAtermResult; +s32 gAtermState; + +void ATERM_8140684C(OSAlarm* alarm, OSContext* context); +s32 ATERM_814038C8(void); +int ATERM_81404844(u16* destination, u16* source, u32 length, void* key, u32 keyLength); +int ATERM_81404A18(u16* destination, u16* source, u32 length, void* key, u32 keyLength); +int ATERM_81404BFC(u32* expandedKey, const void* key, u32 keyBits); +int ATERM_8140502C(u32* expandedKey, const void* key, u32 keyBits); +void ATERM_81405254(const u32* expandedKey, u32 rounds, const u8* input, u8* output); +void ATERM_81405690(const u32* expandedKey, u32 rounds, const u8* input, u8* output); +int ATERM_814033F0(u16* response); + +int ATERM_814021BC(void) { + int status; + int waitCount = 0; + u32 convertedHost; + u32 timeoutTicks; + NCDIpConfig* ipConfig; + NCDIfConfig* ifConfig; + OSMessageQueue interfaceQueue; + OSMessage interfaceMessage; + OSMessage interfaceQueueBuffer; + OSAlarm interfaceAlarm; + OSMessageQueue hostQueue; + OSMessage hostMessage; + OSMessage hostQueueBuffer; + OSAlarm hostAlarm; + + ipConfig = &gNetworkSettings.ipConfig; + memset(ipConfig, 0, sizeof(*ipConfig)); + ipConfig->adjust.maxTransferUnit = 0x514; + ipConfig->adjust.tcpRetransTimeout = 100; + ipConfig->adjust.dhcpRetransCount = 4; + ipConfig->useDhcp = 0; + ipConfig->useProxy = 0; + memcpy(ipConfig->ip.addr, &gDefaultIpAddress, 4); + memcpy(ipConfig->ip.netmask, &gDefaultSubnetMask, 4); + memcpy(ipConfig->ip.gateway, &gDefaultGateway, 4); + memcpy(ipConfig->ip.dns1, &gDefaultPrimaryDns, 4); + memcpy(ipConfig->ip.dns2, &gDefaultSecondaryDns, 4); + NCDSetIpConfig(ipConfig); + + ifConfig = &gNetworkSettings.ifConfig; + memset(ifConfig, 0, sizeof(*ifConfig)); + ifConfig->selectedMedia = 1; + ifConfig->netif.wireless.rateset = 0; + ifConfig->netif.wireless.configMethod = 0; + ifConfig->netif.wireless.config.rakuraku.privacy.mode = 0; + ifConfig->netif.wireless.config.rakuraku.ssidLength = strlen(gAccessPointName); + memcpy(ifConfig->netif.wireless.config.rakuraku.ssid, gAccessPointName, 0x20); + status = NCDSetIfConfig(ifConfig); + if (status != 0) { + return -2; + } + + while (NCDIsInterfaceDecided() == 0) { + if (waitCount > 500) { + return -2; + } + waitCount++; + OSInitMessageQueue(&interfaceQueue, &interfaceQueueBuffer, 1); + OSCreateAlarm(&interfaceAlarm); + OSSetAlarmTag(&interfaceAlarm, (u32)&interfaceQueue); + timeoutTicks = (__mulhwu(0x10624DD3, *(u32*)0x800000F8 >> 2) >> 6) * 10; + OSSetAlarm(&interfaceAlarm, timeoutTicks, ATERM_8140684C); + OSReceiveMessage(&interfaceQueue, &interfaceMessage, 1); + } + + waitCount = 1; + gAtermSocketStarted = waitCount; + status = SOStartup(); + if (status == 0) { + gAtermSocketReady = waitCount; + } + if (gAtermSocketReady != 0) { + for (;;) { + convertedHost = SOHtoNl(0); + if (SOGetHostID() != convertedHost) { + break; + } + OSInitMessageQueue(&hostQueue, &hostQueueBuffer, 1); + OSCreateAlarm(&hostAlarm); + OSSetAlarmTag(&hostAlarm, (u32)&hostQueue); + timeoutTicks = (__mulhwu(0x10624DD3, *(u32*)0x800000F8 >> 2) >> 6) * 10; + OSSetAlarm(&hostAlarm, timeoutTicks, ATERM_8140684C); + OSReceiveMessage(&hostQueue, &hostMessage, 1); + } + } else { + waitCount = -2; + } + + return waitCount; +} + +int ATERM_81402424(u16* resultBuffer, u32 resultBufferLength) { + int lockId; + int result = -2; + u16* scanBuffer = resultBuffer; + u32 scanBufferLength = resultBufferLength; + int startupRetries = 0; + int scanRetries = 0; + int cleanupRetries = 0; + int unlockRetries = 0; + int scanResult; + OSMessage startupQueueBuffer[1]; + OSMessage startupMessage; + OSMessage scanQueueBuffer[1]; + OSMessage scanMessage; + OSMessage cleanupQueueBuffer[1]; + OSMessage cleanupMessage; + OSMessage unlockQueueBuffer[1]; + OSMessage unlockMessage; + u32 scanStatus; + u8 interfaceMac[8]; + OSMessageQueue startupQueue; + OSMessageQueue scanQueue; + OSMessageQueue cleanupQueue; + OSMessageQueue unlockQueue; + OSAlarm startupAlarm; + OSAlarm scanAlarm; + OSAlarm cleanupAlarm; + OSAlarm unlockAlarm; + WDScanParam scanParameters; + WD_Info interfaceInfo ATTRIBUTE_ALIGN(32); + + lockId = NCDLockWirelessDriver(); + if (lockId > 0) { + + do { + scanResult = WD_Startup(3); + if (scanResult == 0) { + break; + } + if (startupRetries > 10) { + goto unlock_driver; + } + startupRetries++; + OSInitMessageQueue(&startupQueue, startupQueueBuffer, 1); + OSCreateAlarm(&startupAlarm); + OSSetAlarmTag(&startupAlarm, (u32)&startupQueue); + OSSetAlarm(&startupAlarm, (__mulhwu(0x10624DD3, *(u32*)0x800000F8 >> 2) >> 6) * 10, + ATERM_8140684C); + OSReceiveMessage(&startupQueue, &startupMessage, 1); + } while (1); + + WD_GetInfo(&interfaceInfo); + memcpy(interfaceMac, interfaceInfo.MAC, 6); + scanParameters.channelBit = interfaceInfo.enableChannel; + scanParameters.maxChannelTime = 0x1E; + memset(scanParameters.bssid, 0xFF, sizeof(scanParameters.bssid)); + scanParameters.type = 0; + scanParameters.ssidLength = 0; + memset(scanParameters.ssid, 0, sizeof(scanParameters.ssid)); + memset(scanParameters.ssidMask, 0xFF, sizeof(scanParameters.ssidMask)); + + for (;;) { + if (gAtermCancelRequested != 0) { + result = -8; + goto cleanup_driver; + } + + scanResult = WD_Scan(&scanParameters, (u8*)scanBuffer, scanBufferLength & 0xFFFF); + if (scanResult != 0 && scanResult != -0x7FFF7FFC) { + goto cleanup_driver; + } + + scanStatus = *scanBuffer; + if (scanStatus != 0) { + result = scanStatus; + goto cleanup_driver; + } + + scanRetries++; + if (scanRetries > 10) { + result = 0; + goto cleanup_driver; + } + + OSInitMessageQueue(&scanQueue, scanQueueBuffer, 1); + OSCreateAlarm(&scanAlarm); + OSSetAlarmTag(&scanAlarm, (u32)&scanQueue); + OSSetAlarm(&scanAlarm, (__mulhwu(0x10624DD3, *(u32*)0x800000F8 >> 2) >> 6) * 10, + ATERM_8140684C); + OSReceiveMessage(&scanQueue, &scanMessage, 1); + } + +cleanup_driver: + while (WD_Cleanup() != 0) { + if (cleanupRetries > 10) { + result = -2; + goto unlock_driver; + } + cleanupRetries++; + OSInitMessageQueue(&cleanupQueue, cleanupQueueBuffer, 1); + OSCreateAlarm(&cleanupAlarm); + OSSetAlarmTag(&cleanupAlarm, (u32)&cleanupQueue); + OSSetAlarm(&cleanupAlarm, (__mulhwu(0x10624DD3, *(u32*)0x800000F8 >> 2) >> 6) * 10, + ATERM_8140684C); + OSReceiveMessage(&cleanupQueue, &cleanupMessage, 1); + } + +unlock_driver: + while (NCDUnlockWirelessDriver(lockId) != 0) { + if (unlockRetries > 10) { + result = -2; + break; + } + unlockRetries++; + OSInitMessageQueue(&unlockQueue, unlockQueueBuffer, 1); + OSCreateAlarm(&unlockAlarm); + OSSetAlarmTag(&unlockAlarm, (u32)&unlockQueue); + OSSetAlarm(&unlockAlarm, (__mulhwu(0x10624DD3, *(u32*)0x800000F8 >> 2) >> 6) * 10, + ATERM_8140684C); + OSReceiveMessage(&unlockQueue, &unlockMessage, 1); + } + } + + return result; +} + +int ATERM_8140276C(AtermApRecordSet* currentRecords, AtermApRecordSet* previousRecords, + u32* changedIndex) { + AtermApRecord* currentRecord = currentRecords->entries; + AtermApRecord* previousRecord; + u32 currentIndex; + u32 previousIndex; + u32 resultIndex = 0; + u32 ssidLength; + size_t compareLength; + size_t aossLength; + size_t formattedSsidLength; + int found = 0; + int previousHasAoss = 0; + int currentHasAoss = 0; + + for (currentIndex = 0; currentIndex < currentRecords->count; currentIndex++) { + AtermSsidBuffer ssidName; + ssidName.clear.word0 = 0; + ssidName.clear.word1 = 0; + ssidName.clear.word2 = 0; + ssidName.clear.word3 = 0; + ssidName.clear.word4 = 0; + ssidName.clear.word5 = 0; + ssidName.clear.word6 = 0; + ssidName.clear.word7 = 0; + ssidName.clear.finalWord = 0; + memcpy(ssidName.text, currentRecord->ssid, sizeof(currentRecord->ssid)); + ssidName.text[currentRecord->ssidLength] = '\0'; + previousRecord = previousRecords->entries; + for (previousIndex = 0; previousIndex < previousRecords->count; previousIndex++) { + ssidLength = currentRecord->ssidLength; + if (ssidLength == 0 || ssidLength > sizeof(currentRecord->ssid) || + (ssidLength == 1 && (currentRecord->ssid[0] == '\0' || + currentRecord->ssid[0] == ' '))) { + break; + } + compareLength = strlen(ssidName.text); + if (memcmp(ssidName.text, previousRecord->ssid, compareLength) == 0 && + memcmp(currentRecord->bssid, previousRecord->bssid, + sizeof(currentRecord->bssid)) == 0 && + currentRecord->status != previousRecord->status && currentRecord->status == 0) { + found = 1; + break; + } + previousRecord++; + } + if (found) { + break; + } + currentRecord++; + } + + if (!found) { + AtermSsidBuffer aossSsidName; + + aossSsidName.clear.word0 = 0; + aossSsidName.clear.word1 = 0; + aossSsidName.clear.word2 = 0; + aossSsidName.clear.word3 = 0; + aossSsidName.clear.word4 = 0; + aossSsidName.clear.word5 = 0; + aossSsidName.clear.word6 = 0; + aossSsidName.clear.word7 = 0; + aossSsidName.clear.finalWord = 0; + + currentRecord = currentRecords->entries; + previousRecord = previousRecords->entries; + for (previousIndex = 0; previousIndex < previousRecords->count; previousIndex++) { + memcpy(aossSsidName.text, previousRecord->ssid, sizeof(previousRecord->ssid)); + aossSsidName.text[previousRecord->ssidLength] = '\0'; + aossLength = strlen(gAtermAossSsid); + if (memcmp(aossSsidName.text, gAtermAossSsid, aossLength) == 0 && + previousRecord->status == 0) { + previousHasAoss = 1; + break; + } + previousRecord++; + } + + currentRecord = currentRecords->entries; + for (currentIndex = 0; currentIndex < currentRecords->count; currentIndex++) { + memcpy(aossSsidName.text, currentRecord->ssid, sizeof(currentRecord->ssid)); + aossSsidName.text[currentRecord->ssidLength] = '\0'; + aossLength = strlen(gAtermAossSsid); + formattedSsidLength = strlen(aossSsidName.text); + if (formattedSsidLength == aossLength) { + aossLength = strlen(gAtermAossSsid); + if (memcmp(aossSsidName.text, gAtermAossSsid, aossLength) == 0 && + currentRecord->status == 0) { + currentHasAoss = 1; + break; + } + } + currentRecord++; + } + if (currentHasAoss && !previousHasAoss) { + found = 1; + } + } + + if (found) { + resultIndex = currentIndex; + *changedIndex = resultIndex; + } + return found; +} + +int ATERM_81402A24(void) { + s32 result = -1; + s32 progressInfo[4] = {0, 0, 0, 0}; + AtermApRecordSet* currentRecords = NULL; + AtermApRecordSet* previousRecords = NULL; + u8* rawScanBuffer = NULL; + u8* scanBuffer; + AtermApRecord* recordCursor; + u32 recordBytes = gAtermScanLimit * sizeof(AtermApRecord) + sizeof(u32); + u32 scanBufferBytes = gAtermScanBufferSize * 0x100; + u32 scanCount; + u32 recordIndex; + u32 iteration = 0; + u32 now; + char selectedMacText[32]; + + currentRecords = (AtermApRecordSet*)gAtermAllocate(recordBytes); + if (currentRecords == NULL) { + goto cleanup; + } + memset(currentRecords, 0, recordBytes); + previousRecords = (AtermApRecordSet*)gAtermAllocate(recordBytes); + if (previousRecords == NULL) { + goto cleanup; + } + memset(previousRecords, 0, recordBytes); + rawScanBuffer = (u8*)gAtermAllocate(scanBufferBytes + 0x40); + if (rawScanBuffer == NULL) { + goto cleanup; + } + scanBuffer = (u8*)(((u32)rawScanBuffer + 0x1F) & ~0x1F); + + while (iteration < 300 && gAtermCancelRequested == 0) { + s64 currentTime = OSGetTime(); + now = (u32)(currentTime / (OS_BUS_CLOCK / 4000)); + if (gAtermDeadline <= now) { + break; + } + + result = ATERM_81402424((u16*)scanBuffer, scanBufferBytes); + if (result < 0) { + goto cleanup; + } + if (gAtermCancelRequested != 0) { + break; + } + if (result >= (s32)gAtermScanLimit) { + result = -6; + goto cleanup; + } + + scanCount = (u32)result; + currentRecords->count = scanCount; + { + u16* descriptorWords = (u16*)(scanBuffer + sizeof(u16)); + recordCursor = currentRecords->entries; + recordIndex = 0; + while (recordIndex < scanCount) { + WDBssDesc* descriptor = (WDBssDesc*)descriptorWords; + + memcpy(recordCursor->ssid, descriptor->ssid, sizeof(recordCursor->ssid)); + if (descriptor->ssidLength <= sizeof(recordCursor->ssid)) { + recordCursor->ssidLength = descriptor->ssidLength; + } else { + recordCursor->ssidLength = 0; + } + recordCursor->ssid[recordCursor->ssidLength] = '\0'; + recordCursor->status = (descriptor->capabilities >> 4) & 1; + memcpy(recordCursor->bssid, descriptor->bssid, sizeof(recordCursor->bssid)); + descriptorWords += descriptor->length; + recordCursor++; + recordIndex++; + } + } + + if (gAtermState != 1 && + ATERM_8140276C(currentRecords, previousRecords, (u32*)&progressInfo[0])) { + gAtermSelectedRecordIndex = progressInfo[0]; + strcpy(gAccessPointName, (char*)currentRecords->entries[progressInfo[0]].ssid); + memcpy(gAtermSelectedBssid, + currentRecords->entries[progressInfo[0]].bssid, + sizeof(currentRecords->entries[progressInfo[0]].bssid)); + { + u8* addressCursor = gAtermSelectedBssid; + s32 addressIndex = 0; + s32 addressesRemaining = 6; + char* output = selectedMacText; + + do { + u8 addressByte = *addressCursor++; + u8 highNibble = addressByte >> 4; + u8 lowNibble = addressByte & 0xF; + char* nextOutput = output + 2; + + if (highNibble < 10) { + *output = highNibble + 0x30; + } else { + *output = highNibble + 0x37; + } + if (lowNibble < 10) { + output[1] = lowNibble + 0x30; + } else { + output[1] = lowNibble + 0x37; + } + *nextOutput = '\0'; + if (addressIndex < 5) { + *nextOutput = ':'; + nextOutput = output + 3; + } + addressIndex++; + addressesRemaining--; + output = nextOutput; + } while (addressesRemaining != 0); + *output = '\0'; + } + break; + } + + memcpy(previousRecords, currentRecords, recordBytes); + gAtermState = 2; + progressInfo[1] = 2; + if (gAtermDeadline == 0xFFFFFFFF) { + progressInfo[2] = -1; + } else { + s64 currentTime = OSGetTime(); + now = (u32)(currentTime / (OS_BUS_CLOCK / 4000)); + progressInfo[2] = gAtermDeadline - now; + } + progressInfo[3] = gAtermResult; + gAtermProgressCallback(&progressInfo[1]); + iteration++; + } + + if (iteration < 300) { + s64 currentTime = OSGetTime(); + now = (u32)(currentTime / (OS_BUS_CLOCK / 4000)); + if (now <= gAtermDeadline) { + result = gAtermCancelRequested == 0 ? 1 : -8; + goto cleanup; + } + } + result = -3; + +cleanup: + if (rawScanBuffer != NULL) { + gAtermRelease(rawScanBuffer); + } + if (currentRecords != NULL) { + gAtermRelease(currentRecords); + } + if (previousRecords != NULL) { + gAtermRelease(previousRecords); + } + return result; +} + +int ATERM_81402E40(u16* messageBuffer, u32 sequence, u16* payload, size_t payloadLength, + void* encryptionKey) { + s32 byteLength; + u8* end; + u8* cursor; + u8* limit; + u32 checksum = 0; + + memset(payload, 0, 8); + payload[0] = SOHtoNs((payloadLength - 8) & 0xFFFF); + if (encryptionKey != NULL) { + ATERM_81404844(messageBuffer + 3, payload, payloadLength, encryptionKey, 0x10); + payloadLength += 8; + } else { + memcpy(messageBuffer + 3, payload, payloadLength); + } + memset(messageBuffer, 0, 6); + messageBuffer[0] = SOHtoNs(sequence & 0xFFFF); + messageBuffer[1] = SOHtoNs(payloadLength & 0xFFFF); + + end = (u8*)(messageBuffer + 3); + end += payloadLength; + cursor = (u8*)messageBuffer; + if ((u8*)messageBuffer < end) { + byteLength = end - (u8*)messageBuffer; + limit = end - 8; + if (byteLength > 8 && cursor <= end) { + for (; cursor < limit; cursor += 8) { + checksum += cursor[0]; + checksum += cursor[1]; + checksum += cursor[2]; + checksum += cursor[3]; + checksum += cursor[4]; + checksum += cursor[5]; + checksum += cursor[6]; + checksum += cursor[7]; + } + } + while (cursor < end) { + checksum += *cursor++; + } + } + *(u16*)end = SOHtoNs(checksum); + return (int)(end + sizeof(u16) - (u8*)messageBuffer); +} + +int ATERM_81402FC0(AtermPacket* packet, u32* setupType) { + u8* cursor; + u8* end; + u8* limit; + u8* payload; + u8* value; + u16 checksum; + u16 messageType; + u32 payloadLength; + u16 optionType; + u16 optionLength; + u16 authenticationReady; + u16 networkReady; + u16 selectedMode; + AtermPacketOption* option; + s32 byteLength; + + messageType = SONtoHs(packet->sequence); + payloadLength = SONtoHs(packet->length); + checksum = 0; + cursor = (u8*)packet; + end = packet->payload + payloadLength; + if (cursor < end) { + byteLength = end - cursor; + limit = end - 8; + if (byteLength > 8 && cursor <= end) { + for (; cursor < limit; cursor += 8) { + checksum += cursor[0]; + checksum += cursor[1]; + checksum += cursor[2]; + checksum += cursor[3]; + checksum += cursor[4]; + checksum += cursor[5]; + checksum += cursor[6]; + checksum += cursor[7]; + } + } + while (cursor < end) { + checksum += *cursor++; + } + } + if (checksum == SONtoHs(*(u16*)end)) { + payload = packet->payload; + } else { + payload = NULL; + } + authenticationReady = 0; + networkReady = 0; + selectedMode = 0; + if (payload == NULL) { + return 0; + } + if (messageType == 1) { + end = payload + payloadLength; + cursor = payload + 8; + while (cursor < end) { + option = (AtermPacketOption*)cursor; + optionType = SONtoHs(option->type); + optionLength = SONtoHs(option->length); + value = option->value; + cursor += (optionLength + 0x0B) & ~7; + switch (optionType) { + case 1: + authenticationReady = SONtoHs(*(u16*)value); + break; + case 2: + networkReady = SONtoHs(*(u16*)value); + break; + case 5: + selectedMode = SONtoHs(*(u16*)value); + break; + } + } + if (authenticationReady == 1 && networkReady == 1) { + *setupType = selectedMode >= 1; + return 1; + } + } + return 0; +} + +int ATERM_814031DC(AtermAssociationRequest* request) { + u8 scanAddress[8]; + u8 interfaceMacAddress[8]; + char scanAddressText[32]; + char interfaceMacText[36]; + int addressOrder; + + memcpy(request->productName, gAtermProductName, sizeof(request->productName)); + memcpy(scanAddress, gAtermSelectedBssid, 6); + scanAddress[0] &= 0xFD; + NCDGetWirelessMacAddress(interfaceMacAddress); + memcpy(gAtermAddressBuffer, interfaceMacAddress, 6); + addressOrder = memcmp(scanAddress, interfaceMacAddress, 6); + if (addressOrder <= 0) { + memcpy(request->firstAddress, interfaceMacAddress, 6); + memcpy(request->secondAddress, scanAddress, 6); + } else { + memcpy(request->firstAddress, scanAddress, 6); + memcpy(request->secondAddress, interfaceMacAddress, 6); + } + if (gAtermUseSharedAddress != 0) { + int addressIndex; + char* textCursor = interfaceMacText; + + for (addressIndex = 0; addressIndex < 6; addressIndex++) { + u8 addressByte = interfaceMacAddress[addressIndex]; + s32 highNibble = (addressByte & 0xF0) >> 4; + s32 lowNibble = addressByte & 0xF; + char* nextText = textCursor + 2; + + if (highNibble < 10) { + *textCursor = highNibble + 0x30; + } else { + *textCursor = highNibble + 0x37; + } + if (lowNibble < 10) { + textCursor[1] = lowNibble + 0x30; + } else { + textCursor[1] = lowNibble + 0x37; + } + *nextText = '\0'; + if (addressIndex < 5) { + *nextText = ':'; + nextText = textCursor + 3; + } + textCursor = nextText; + } + *textCursor = '\0'; + + textCursor = scanAddressText; + for (addressIndex = 0; addressIndex < 6; addressIndex++) { + u8 addressByte = scanAddress[addressIndex]; + s32 highNibble = (addressByte & 0xF0) >> 4; + s32 lowNibble = addressByte & 0xF; + char* nextText = textCursor + 2; + + if (highNibble < 10) { + *textCursor = highNibble + 0x30; + } else { + *textCursor = highNibble + 0x37; + } + if (lowNibble < 10) { + textCursor[1] = lowNibble + 0x30; + } else { + textCursor[1] = lowNibble + 0x37; + } + *nextText = '\0'; + if (addressIndex < 5) { + *nextText = ':'; + nextText = textCursor + 3; + } + textCursor = nextText; + } + *textCursor = '\0'; + } + return 1; +} + +int ATERM_814033F0(u16* response) { + u16* optionCursor = response + 4; + u16* responseEnd = (u16*)((u8*)optionCursor + SONtoHs(response[0])); + u16 optionType; + u16 optionLength; + u8* optionValue; + u32 value; + u32 result = 0; + + for (;;) { + if (optionCursor < responseEnd) { + optionType = SONtoHs(optionCursor[0]); + optionLength = SONtoHs(optionCursor[1]); + optionValue = (u8*)(optionCursor + 2); + optionCursor = (u16*)((u8*)optionCursor + ((optionLength + 0x0B) & ~7)); + } else { + break; + } + + switch (optionType) { + case 0x201: + memset(gScanSettings.ssid, 0, sizeof(gScanSettings.ssid)); + memcpy(gScanSettings.ssid, optionValue, optionLength); + result = 1; + break; + case 0x202: + gScanSettings.selectedSecurity = SONtoHs(*(u16*)optionValue); + break; + case 0x203: + value = SONtoHs(*(u16*)optionValue); + gScanSettings.wirelessKeys[0].keyFormat = value; + gScanSettings.wirelessKeys[1].keyFormat = value; + gScanSettings.wirelessKeys[2].keyFormat = value; + gScanSettings.wirelessKeys[3].keyFormat = value; + break; + case 0x204: + value = SONtoHs(*(u16*)optionValue); + gScanSettings.wirelessKeys[0].keyLength = value; + gScanSettings.wirelessKeys[1].keyLength = value; + gScanSettings.wirelessKeys[2].keyLength = value; + gScanSettings.wirelessKeys[3].keyLength = value; + break; + case 0x205: + gScanSettings.authAlgorithm = SONtoHs(*(u16*)optionValue); + break; + case 0x206: + case 0x207: + case 0x208: + case 0x209: + { + u32 keyIndex = optionType - 0x206; + char* key = gScanSettings.wirelessKeys[keyIndex].key; + memset(key, 0, sizeof(gScanSettings.wirelessKeys[keyIndex].key)); + if (gScanSettings.wirelessKeys[0].keyFormat == 1) { + u32 byteIndex = 0; + if (optionLength != 0) { + do { + u8 sourceByte = optionValue[byteIndex++]; + u8 highNibble = sourceByte >> 4; + u8 lowNibble = sourceByte & 0xF; + + if (highNibble < 10) { + *key++ = highNibble + 0x30; + } else { + *key++ = highNibble + 0x37; + } + if (lowNibble < 10) { + *key++ = lowNibble + 0x30; + } else { + *key++ = lowNibble + 0x37; + } + *key = '\0'; + } while (byteIndex < optionLength); + } + } else { + memcpy(key, optionValue, optionLength); + } + break; + } + case 0x20A: + memset(gScanSettings.sharedKey, 0, sizeof(gScanSettings.sharedKey)); + memcpy(gScanSettings.sharedKey, optionValue, optionLength); + break; + } + } + return result; +} + +int ATERM_81403614(u8* destination, const char* source, s32 length) { + s32 value = 0; + u32 characterIndex = 0; + + while (length > 0) { + s32 character = *source++; + + if (character < 'G') { + if (character < '0') { + return 0; + } + if (character < ':') { + value += character - '0'; + } else { + if (character < 'A') { + return 0; + } + value += character - '7'; + } + } else { + if (character > 'f' || character < 'a') { + return 0; + } + value += character - 'W'; + } + + if ((characterIndex & 1) == 0) { + value <<= 4; + } else { + *destination++ = (u8)value; + value = 0; + } + characterIndex++; + length--; + } + return 1; +} + +int ATERM_814036D8(void) { + s32 result = 1; + char* outputKey; + char* sourceKey; + s32 keyIndex; + size_t keyLength; + struct { + char text[32]; + char terminator; + } keyText; + + strcpy(gAtermConfigurationResult.ssid, gScanSettings.ssid); + if (gScanSettings.selectedSecurity == 2) { + gAtermConfigurationResult.setupMode = 4; + memcpy(gAtermConfigurationResult.keyMaterial, gScanSettings.sharedKey, 0x40); + } else if (gScanSettings.selectedSecurity < 2) { + if (gScanSettings.selectedSecurity == 0) { + gAtermConfigurationResult.setupMode = 0; + } else if (gScanSettings.authAlgorithm == 0) { + result = -7; + } else { + gAtermConfigurationResult.securityMode = gScanSettings.authAlgorithm; + outputKey = (char*)gAtermConfigurationResult.reserved028; + sourceKey = gScanSettings.wirelessKeys[0].key; + keyIndex = 0; + + do { + memcpy(keyText.text, sourceKey, 0x20); + keyText.terminator = '\0'; + keyLength = strlen(keyText.text); + switch (keyLength) { + case 0: + break; + case 5: + gAtermConfigurationResult.setupMode = 1; + memcpy(outputKey, keyText.text, 5); + break; + case 10: + gAtermConfigurationResult.setupMode = 1; + ATERM_81403614((u8*)outputKey, keyText.text, 10); + break; + case 13: + gAtermConfigurationResult.setupMode = 2; + memcpy(outputKey, keyText.text, 0xD); + break; + case 16: + gAtermConfigurationResult.setupMode = 3; + memcpy(outputKey, keyText.text, 0x10); + break; + case 26: + gAtermConfigurationResult.setupMode = 2; + ATERM_81403614((u8*)outputKey, keyText.text, 0x1A); + break; + case 32: + gAtermConfigurationResult.setupMode = 3; + ATERM_81403614((u8*)outputKey, keyText.text, 0x20); + break; + default: + result = -7; + break; + } + outputKey += 0x20; + sourceKey += 0x28; + keyIndex++; + } while (keyIndex < 4); + } + } else if (gScanSettings.selectedSecurity < 4) { + gAtermConfigurationResult.setupMode = 5; + memcpy(gAtermConfigurationResult.keyMaterial, gScanSettings.sharedKey, 0x40); + } else { + result = -7; + } + return result; +} + +s32 ATERM_814038C8(void) { + OSMessageQueue waitQueue; + OSMessage waitBuffer[1]; + OSMessage waitMessage; + OSAlarm waitAlarm; + AtermSocketAddress socketBindAddress; + AtermSocketAddress peerAddress; + u8* packetBuffer = gAtermConfigurationResult.packetBuffer; + u8* requestOptions = gAtermResponseBuffer.data; + u8 digest[16]; + AtermRequestOption16* shortOption; + AtermRequestOption24* longOption; + u8* optionEnd; + s32 socket = -1; + s32 result = -5; + s32 failed = 0; + s32 retries = 0; + u32 lastSendTime = 0; + u32 now; + u32 requestLength; + s32 receivedLength; + s32 stateProgress[3]; + u16 enabled; + u32 reciprocal = 0x10624DD3; + + gAtermProtocolState = 1; + memset(&peerAddress, 0, sizeof(peerAddress)); + for (;;) { + if (failed != 0 || gAtermCancelRequested != 0) { + if (socket >= 0) { + SOClose(socket); + } + if (gAtermCancelRequested != 0) { + result = -8; + } + return result; + } + + OSInitMessageQueue(&waitQueue, waitBuffer, 1); + OSCreateAlarm(&waitAlarm); + OSSetAlarmTag(&waitAlarm, (u32)&waitQueue); + OSSetPeriodicAlarm(&waitAlarm, OS_BUS_CLOCK >> 2, + (OS_BUS_CLOCK / 4000) * 500, ATERM_8140684C); + OSReceiveMessage(&waitQueue, &waitMessage, 1); + + switch (gAtermProtocolState) { + case 1: + if (ATERM_81402A24() == 1) { + gAtermProtocolState = 2; + } else { + failed = 1; + } + break; + case 2: + if (ATERM_814021BC() == 1) { + now = (u32)(OSGetTime() / (__mulhwu(reciprocal, OS_BUS_CLOCK >> 2) >> 6)); + if (gAtermDeadline < now + 10000) { + gAtermDeadline = now + 10000; + } + gAtermProtocolState = 3; + } else { + result = -2; + failed = 1; + } + break; + case 3: + socket = SOSocket(2, 2, 0); + if (socket < 0) { + result = -2; + failed = 1; + break; + } + memset(&socketBindAddress, 0, sizeof(socketBindAddress)); + socketBindAddress.length = 8; + socketBindAddress.family = 2; + socketBindAddress.port = SOHtoNs(0xE601); + if (SOBind(socket, &socketBindAddress) < 0) { + result = -2; + failed = 1; + } else { + gAtermProtocolState = 4; + } + break; + case 4: + now = (u32)(OSGetTime() / (__mulhwu(reciprocal, OS_BUS_CLOCK >> 2) >> 6)); + if (now >= gAtermDeadline) { + SOClose(socket); + socket = -1; + result = -3; + failed = 1; + break; + } + memset(&peerAddress, 0, sizeof(peerAddress)); + receivedLength = SORecvFrom(socket, packetBuffer, + sizeof(gAtermConfigurationResult.packetBuffer), 4, + &peerAddress); + if (receivedLength > 0 && + ATERM_81402FC0((AtermPacket*)packetBuffer, &gAtermResponseMode)) { + now = (u32)(OSGetTime() / (__mulhwu(reciprocal, OS_BUS_CLOCK >> 2) >> 6)); + gAtermDeadline = now + 30000; + gAtermProtocolState = 5; + stateProgress[0] = 4; + stateProgress[1] = 30000; + stateProgress[2] = gAtermResult; + (*gAtermProgressCallback)(stateProgress); + } + break; + case 5: + memset(requestOptions, 0, + sizeof(AtermRequestOption16) * 3 + sizeof(AtermRequestOption24) * 2); + shortOption = (AtermRequestOption16*)requestOptions; + shortOption->type = SOHtoNs(1); + shortOption->length = SOHtoNs(2); + *(u16*)shortOption->value = SOHtoNs(1); + shortOption++; + shortOption->type = SOHtoNs(2); + shortOption->length = SOHtoNs(2); + *(u16*)shortOption->value = SOHtoNs(1); + shortOption++; + if (gAtermResponseMode != 0) { + shortOption->type = SOHtoNs(5); + shortOption->length = SOHtoNs(2); + *(u16*)shortOption->value = SOHtoNs(1); + shortOption++; + } + longOption = (AtermRequestOption24*)shortOption; + longOption->type = SOHtoNs(3); + longOption->length = SOHtoNs(7); + memcpy(longOption->value, gAtermProductName, 4); + longOption++; + if (gAtermResponseMode != 0) { + longOption->type = SOHtoNs(4); + longOption->length = SOHtoNs(6); + memcpy(longOption->value, gAtermAddressBuffer, 6); + longOption++; + } + optionEnd = (u8*)longOption; + requestLength = ATERM_81402E40((u16*)packetBuffer, 2, + (u16*)requestOptions, + optionEnd - requestOptions, 0); + gAtermMessageLength = requestLength; + if (SOSendTo(socket, packetBuffer, requestLength, 0, &peerAddress) < 0) { + result = -2; + failed = 1; + break; + } + lastSendTime = (u32)(OSGetTime() / (__mulhwu(reciprocal, OS_BUS_CLOCK >> 2) >> 6)); + gAtermProtocolState = 6; + break; + case 6: + now = (u32)(OSGetTime() / (__mulhwu(reciprocal, OS_BUS_CLOCK >> 2) >> 6)); + if (now >= gAtermDeadline) { + SOClose(socket); + socket = -1; + result = -4; + failed = 1; + break; + } + receivedLength = SORecvFrom(socket, packetBuffer, + sizeof(gAtermConfigurationResult.packetBuffer), 4, + &peerAddress); + if (receivedLength > 0 && + ATERM_81402FC0((AtermPacket*)packetBuffer, &gAtermResponseMode) && + ATERM_81404A18((u16*)packetBuffer, (u16*)packetBuffer, receivedLength, + gAtermAddressBuffer, 0x10)) { + memcpy(digest, packetBuffer, sizeof(digest)); + gAtermProtocolState = 7; + stateProgress[0] = 5; + stateProgress[1] = (s32)(gAtermDeadline - now); + stateProgress[2] = gAtermResult; + (*gAtermProgressCallback)(stateProgress); + } else if (now - lastSendTime >= 2000) { + if (++retries >= 10) { + result = -2; + failed = 1; + } else { + gAtermProtocolState = 5; + } + } + break; + case 7: + memset(requestOptions, 0, sizeof(AtermRequestOption24)); + longOption = (AtermRequestOption24*)requestOptions; + longOption->type = SOHtoNs(0x102); + longOption->length = SOHtoNs(8); + memcpy(longOption->value, digest, 8); + requestLength = ATERM_81402E40((u16*)packetBuffer, 4, + (u16*)requestOptions, + sizeof(AtermRequestOption24), + packetBuffer); + SOSendTo(socket, packetBuffer, requestLength, 0, &peerAddress); + gAtermProtocolState = 8; + lastSendTime = now; + break; + case 8: + receivedLength = SORecvFrom(socket, packetBuffer, + sizeof(gAtermConfigurationResult.packetBuffer), 4, + &peerAddress); + if (receivedLength > 0 && + ATERM_81402FC0((AtermPacket*)packetBuffer, &gAtermResponseMode) && + ATERM_814033F0((u16*)packetBuffer)) { + gAtermMode = (gScanSettings.ssid[0] & 0x80) != 0; + gAtermProtocolState = 9; + retries = 0; + } else if (now - lastSendTime >= 1000) { + if (++retries < 10) { + gAtermProtocolState = 7; + } else { + result = -2; + failed = 1; + } + } + break; + case 9: + memset(requestOptions, 0, sizeof(AtermRequestOption16)); + shortOption = (AtermRequestOption16*)requestOptions; + shortOption->type = SOHtoNs(0x301); + shortOption->length = SOHtoNs(1); + shortOption->value[0] = gAtermMode; + requestLength = ATERM_81402E40((u16*)packetBuffer, 6, + (u16*)requestOptions, + sizeof(AtermRequestOption16), + gAtermAddressBuffer); + SOSendTo(socket, packetBuffer, requestLength, 0, &peerAddress); + gAtermProtocolState = 10; + lastSendTime = now; + break; + case 10: + if (NCDGetLinkStatus() == 5) { + SOClose(socket); + socket = -1; + return ATERM_814036D8(); + } + now = (u32)(OSGetTime() / (__mulhwu(reciprocal, OS_BUS_CLOCK >> 2) >> 6)); + if (now - lastSendTime >= 1000) { + if (++retries >= 10) { + result = -5; + failed = 1; + } else { + gAtermProtocolState = 9; + } + } + break; + default: + result = -5; + failed = 1; + break; + } + } +} + +s32 ATERMi_AutoConfigThread(void) { + s32 result = ATERM_814038C8(); + s32 progress[5]; + u32 equalityMask; + s32 completedState; + + gAtermResult = result; + if (gAtermSocketStarted != 0) { + gAtermSocketStarted = 0; + } + if (gAtermSocketReady != 0) { + gAtermSocketReady = 0; + SOCleanup(); + } + equalityMask = ~(result - 1U | 1U - result); + gAtermDeadline = 0xFFFFFFFF; + completedState = ((s32)equalityMask >> 31) + 7; + gAtermState = completedState; + progress[0] = completedState; + progress[1] = -1; + progress[2] = gAtermResult; + (*gAtermProgressCallback)(progress); + return 0; +} + +int ATERM_81404844(u16* destination, u16* source, u32 length, void* key, u32 keyLength) { + u32 expandedKey[64]; + u32 stateWords[4]; + u8* destinationBytes = (u8*)destination; + const u8* sourceBytes = (const u8*)source; + u32 blockCount; + u32 rounds; + u32 pass; + + if ((length & 7) != 0 || (keyLength & 7) != 0) { + return 0; + } + blockCount = length >> 3; + if (blockCount < 2) { + return 0; + } + + rounds = ATERM_81404BFC(expandedKey, key, keyLength << 3); + memcpy(destinationBytes + 8, sourceBytes, length); + stateWords[0] = 0x4D4D4D4D; + stateWords[1] = 0x4D4D4D4D; + for (pass = 0; pass < 6; pass++) { + u32 blockIndex; + for (blockIndex = 1; blockIndex <= blockCount; blockIndex++) { + u64 counter = (u64)pass * blockCount + blockIndex; + u8* stateBytes = (u8*)stateWords; + + memcpy(stateBytes + 8, destinationBytes + blockIndex * 8, 8); + ATERM_81405254(expandedKey, rounds, stateBytes, stateBytes); + stateBytes[0] ^= (u8)(counter >> 56); + stateBytes[1] ^= (u8)(counter >> 48); + stateBytes[2] ^= (u8)(counter >> 40); + stateBytes[3] ^= (u8)(counter >> 32); + stateBytes[4] ^= (u8)(counter >> 24); + stateBytes[5] ^= (u8)(counter >> 16); + stateBytes[6] ^= (u8)(counter >> 8); + stateBytes[7] ^= (u8)counter; + } + } + memcpy(destinationBytes, stateWords, 8); + return 1; +} + +int ATERM_81404A18(u16* destination, u16* source, u32 length, void* key, u32 keyLength) { + u32 expandedKey[64]; + u32 stateWords[4]; + u8* destinationBytes = (u8*)destination; + const u8* sourceBytes = (const u8*)source; + u32 blockCount; + u32 rounds; + s32 pass; + + if ((length & 7) != 0 || (keyLength & 7) != 0) { + return 0; + } + blockCount = (length - 1) >> 3; + if (blockCount < 2) { + return 0; + } + + rounds = ATERM_8140502C(expandedKey, key, keyLength << 3); + memcpy(stateWords, sourceBytes, 8); + memcpy(destinationBytes, sourceBytes + 8, length - 1); + for (pass = 5; pass >= 0; pass--) { + u32 blockIndex; + for (blockIndex = blockCount; blockIndex != 0; blockIndex--) { + u64 counter = (u64)(u32)pass * blockCount + blockIndex; + u8* stateBytes = (u8*)stateWords; + u8* outputBlock = destinationBytes + (blockIndex - 1) * 8; + + memcpy(stateBytes + 8, outputBlock, 8); + ATERM_81405690(expandedKey, rounds, stateBytes, stateBytes); + stateBytes[0] ^= (u8)(counter >> 56); + stateBytes[1] ^= (u8)(counter >> 48); + stateBytes[2] ^= (u8)(counter >> 40); + stateBytes[3] ^= (u8)(counter >> 32); + stateBytes[4] ^= (u8)(counter >> 24); + stateBytes[5] ^= (u8)(counter >> 16); + stateBytes[6] ^= (u8)(counter >> 8); + stateBytes[7] ^= (u8)counter; + memcpy(outputBlock, stateBytes + 8, 8); + } + } + return stateWords[0] == 0x4D4D4D4D && stateWords[1] == 0x4D4D4D4D; +} + +#define ATERM_AES_SUB_BYTE(value) (gAtermAesTables[4][(value)] & 0xFF) +#define ATERM_AES_SUB_WORD(value) \ + ((ATERM_AES_SUB_BYTE(((value) >> 24) & 0xFF) << 24) | \ + (ATERM_AES_SUB_BYTE(((value) >> 16) & 0xFF) << 16) | \ + (ATERM_AES_SUB_BYTE(((value) >> 8) & 0xFF) << 8) | \ + ATERM_AES_SUB_BYTE((value) & 0xFF)) + +#define ATERM_AES_READ_KEY_WORD(index) \ + (((u32)keyBytes[(index) * 4] << 24) | \ + ((u32)keyBytes[(index) * 4 + 1] << 16) | \ + ((u32)keyBytes[(index) * 4 + 2] << 8) | \ + keyBytes[(index) * 4 + 3]) + +int ATERM_81404BFC(u32* expandedKey, const void* key, u32 keyBits) { + const u8* keyBytes = (const u8*)key; + u32* roundKey; + const u32* roundConstant; + u32 temp; + + expandedKey[0] = ATERM_AES_READ_KEY_WORD(0); + expandedKey[1] = ATERM_AES_READ_KEY_WORD(1); + expandedKey[2] = ATERM_AES_READ_KEY_WORD(2); + expandedKey[3] = ATERM_AES_READ_KEY_WORD(3); + + if (keyBits == 0x80) { + roundKey = expandedKey + 4; + roundConstant = gAtermAesRoundConstants; + do { + temp = roundKey[3]; + temp = (temp << 8) | (temp >> 24); + temp = ATERM_AES_SUB_WORD(temp) ^ *roundConstant++; + roundKey[0] = roundKey[-4] ^ temp; + roundKey[1] = roundKey[-3] ^ roundKey[0]; + roundKey[2] = roundKey[-2] ^ roundKey[1]; + roundKey[3] = roundKey[-1] ^ roundKey[2]; + roundKey += 4; + } while (roundKey < expandedKey + 44); + return 10; + } + + expandedKey[4] = ATERM_AES_READ_KEY_WORD(4); + expandedKey[5] = ATERM_AES_READ_KEY_WORD(5); + if (keyBits == 0xC0) { + roundKey = expandedKey + 6; + roundConstant = gAtermAesRoundConstants; + do { + temp = roundKey[5]; + temp = (temp << 8) | (temp >> 24); + temp = ATERM_AES_SUB_WORD(temp) ^ *roundConstant++; + roundKey[0] = roundKey[-6] ^ temp; + roundKey[1] = roundKey[-5] ^ roundKey[0]; + roundKey[2] = roundKey[-4] ^ roundKey[1]; + roundKey[3] = roundKey[-3] ^ roundKey[2]; + roundKey[4] = roundKey[-2] ^ roundKey[0]; + roundKey[5] = roundKey[-1] ^ roundKey[4]; + roundKey += 6; + } while (roundKey < expandedKey + 54); + return 12; + } + + expandedKey[6] = ATERM_AES_READ_KEY_WORD(6); + expandedKey[7] = ATERM_AES_READ_KEY_WORD(7); + if (keyBits == 0x100) { + roundKey = expandedKey + 8; + roundConstant = gAtermAesRoundConstants; + do { + temp = roundKey[7]; + temp = (temp << 8) | (temp >> 24); + temp = ATERM_AES_SUB_WORD(temp) ^ *roundConstant++; + roundKey[0] = roundKey[-8] ^ temp; + roundKey[1] = roundKey[-7] ^ roundKey[0]; + roundKey[2] = roundKey[-6] ^ roundKey[1]; + roundKey[3] = roundKey[-5] ^ roundKey[2]; + temp = ATERM_AES_SUB_WORD(roundKey[3]); + roundKey[4] = roundKey[-4] ^ temp; + roundKey[5] = roundKey[-3] ^ roundKey[4]; + roundKey[6] = roundKey[-2] ^ roundKey[5]; + roundKey[7] = roundKey[-1] ^ roundKey[6]; + roundKey += 8; + } while (roundKey < expandedKey + 64); + return 14; + } + return 0; +} + +#undef ATERM_AES_READ_KEY_WORD +#undef ATERM_AES_SUB_WORD +#undef ATERM_AES_SUB_BYTE +#undef ATERM_AES_SUB_BYTE + + +#define ATERM_AES_TRANSFORM_KEY(roundKey, index) \ + { \ + u32 word = (roundKey)[index]; \ + u32 byte0 = gAtermAesTables[4][(word >> 24) & 0xFF] & 0xFF; \ + u32 byte1 = gAtermAesTables[4][(word >> 16) & 0xFF] & 0xFF; \ + u32 byte2 = gAtermAesTables[4][(word >> 8) & 0xFF] & 0xFF; \ + u32 byte3 = gAtermAesTables[4][word & 0xFF] & 0xFF; \ + (roundKey)[index] = gAtermAesTables[5][byte0] ^ gAtermAesTables[6][byte1] ^ \ + gAtermAesTables[7][byte2] ^ gAtermAesTables[8][byte3]; \ + } + +int ATERM_8140502C(u32* expandedKey, const void* key, u32 keyBits) { + int rounds = ATERM_81404BFC(expandedKey, key, keyBits); + u32* firstRound = expandedKey; + u32* lastRound = expandedKey + rounds * 4; + u32* roundKey; + u32 roundCount; + + while (firstRound < lastRound) { + u32 word0 = firstRound[0]; + u32 word1 = firstRound[1]; + u32 word2 = firstRound[2]; + u32 word3 = firstRound[3]; + + firstRound[0] = lastRound[0]; + firstRound[1] = lastRound[1]; + firstRound[2] = lastRound[2]; + firstRound[3] = lastRound[3]; + lastRound[0] = word0; + lastRound[1] = word1; + lastRound[2] = word2; + lastRound[3] = word3; + firstRound += 4; + lastRound -= 4; + } + + if (rounds > 1) { + roundKey = expandedKey + 4; + roundCount = rounds - 1; + do { + ATERM_AES_TRANSFORM_KEY(roundKey, 0); + ATERM_AES_TRANSFORM_KEY(roundKey, 1); + ATERM_AES_TRANSFORM_KEY(roundKey, 2); + ATERM_AES_TRANSFORM_KEY(roundKey, 3); + roundKey += 4; + } while (--roundCount != 0); + } + return rounds; +} + +#undef ATERM_AES_TRANSFORM_KEY + +void ATERM_81405254(const u32* expandedKey, u32 rounds, const u8* input, u8* output) { + u32 state0 = ((u32)input[0] << 24) | ((u32)input[1] << 16) | + ((u32)input[2] << 8) | input[3]; + u32 state1 = ((u32)input[4] << 24) | ((u32)input[5] << 16) | + ((u32)input[6] << 8) | input[7]; + u32 state2 = ((u32)input[8] << 24) | ((u32)input[9] << 16) | + ((u32)input[10] << 8) | input[11]; + u32 state3 = ((u32)input[12] << 24) | ((u32)input[13] << 16) | + ((u32)input[14] << 8) | input[15]; + u32 roundIndex; + + state0 ^= expandedKey[0]; + state1 ^= expandedKey[1]; + state2 ^= expandedKey[2]; + state3 ^= expandedKey[3]; + + for (roundIndex = 1; roundIndex < rounds; roundIndex++) { + u32 next0 = gAtermAesTables[0][state0 >> 24] ^ + gAtermAesTables[1][(state1 >> 16) & 0xFF] ^ + gAtermAesTables[2][(state2 >> 8) & 0xFF] ^ + gAtermAesTables[3][state3 & 0xFF] ^ expandedKey[roundIndex * 4]; + u32 next1 = gAtermAesTables[0][state1 >> 24] ^ + gAtermAesTables[1][(state2 >> 16) & 0xFF] ^ + gAtermAesTables[2][(state3 >> 8) & 0xFF] ^ + gAtermAesTables[3][state0 & 0xFF] ^ expandedKey[roundIndex * 4 + 1]; + u32 next2 = gAtermAesTables[0][state2 >> 24] ^ + gAtermAesTables[1][(state3 >> 16) & 0xFF] ^ + gAtermAesTables[2][(state0 >> 8) & 0xFF] ^ + gAtermAesTables[3][state1 & 0xFF] ^ expandedKey[roundIndex * 4 + 2]; + u32 next3 = gAtermAesTables[0][state3 >> 24] ^ + gAtermAesTables[1][(state0 >> 16) & 0xFF] ^ + gAtermAesTables[2][(state1 >> 8) & 0xFF] ^ + gAtermAesTables[3][state2 & 0xFF] ^ expandedKey[roundIndex * 4 + 3]; + + state0 = next0; + state1 = next1; + state2 = next2; + state3 = next3; + } + + { + u32 result0 = (((gAtermAesTables[4][state0 >> 24] & 0xFF000000) | + (gAtermAesTables[4][(state1 >> 16) & 0xFF] & 0x00FF0000) | + (gAtermAesTables[4][(state2 >> 8) & 0xFF] & 0x0000FF00) | + (gAtermAesTables[4][state3 & 0xFF] & 0x000000FF)) ^ expandedKey[rounds * 4]); + u32 result1 = (((gAtermAesTables[4][state1 >> 24] & 0xFF000000) | + (gAtermAesTables[4][(state2 >> 16) & 0xFF] & 0x00FF0000) | + (gAtermAesTables[4][(state3 >> 8) & 0xFF] & 0x0000FF00) | + (gAtermAesTables[4][state0 & 0xFF] & 0x000000FF)) ^ expandedKey[rounds * 4 + 1]); + u32 result2 = (((gAtermAesTables[4][state2 >> 24] & 0xFF000000) | + (gAtermAesTables[4][(state3 >> 16) & 0xFF] & 0x00FF0000) | + (gAtermAesTables[4][(state0 >> 8) & 0xFF] & 0x0000FF00) | + (gAtermAesTables[4][state1 & 0xFF] & 0x000000FF)) ^ expandedKey[rounds * 4 + 2]); + u32 result3 = (((gAtermAesTables[4][state3 >> 24] & 0xFF000000) | + (gAtermAesTables[4][(state0 >> 16) & 0xFF] & 0x00FF0000) | + (gAtermAesTables[4][(state1 >> 8) & 0xFF] & 0x0000FF00) | + (gAtermAesTables[4][state2 & 0xFF] & 0x000000FF)) ^ expandedKey[rounds * 4 + 3]); + + output[0] = result0 >> 24; + output[1] = result0 >> 16; + output[2] = result0 >> 8; + output[3] = result0; + output[4] = result1 >> 24; + output[5] = result1 >> 16; + output[6] = result1 >> 8; + output[7] = result1; + output[8] = result2 >> 24; + output[9] = result2 >> 16; + output[10] = result2 >> 8; + output[11] = result2; + output[12] = result3 >> 24; + output[13] = result3 >> 16; + output[14] = result3 >> 8; + output[15] = result3; + } +} + +void ATERM_81405690(const u32* expandedKey, u32 rounds, const u8* input, u8* output) { + u32 state0 = ((u32)input[0] << 24) | ((u32)input[1] << 16) | + ((u32)input[2] << 8) | input[3]; + u32 state1 = ((u32)input[4] << 24) | ((u32)input[5] << 16) | + ((u32)input[6] << 8) | input[7]; + u32 state2 = ((u32)input[8] << 24) | ((u32)input[9] << 16) | + ((u32)input[10] << 8) | input[11]; + u32 state3 = ((u32)input[12] << 24) | ((u32)input[13] << 16) | + ((u32)input[14] << 8) | input[15]; + u32 roundIndex; + + state0 ^= expandedKey[0]; + state1 ^= expandedKey[1]; + state2 ^= expandedKey[2]; + state3 ^= expandedKey[3]; + + for (roundIndex = 1; roundIndex < rounds; roundIndex++) { + u32 next0 = gAtermAesTables[5][state0 >> 24] ^ + gAtermAesTables[6][(state3 >> 16) & 0xFF] ^ + gAtermAesTables[7][(state2 >> 8) & 0xFF] ^ + gAtermAesTables[8][state1 & 0xFF] ^ expandedKey[roundIndex * 4]; + u32 next1 = gAtermAesTables[5][state1 >> 24] ^ + gAtermAesTables[6][(state0 >> 16) & 0xFF] ^ + gAtermAesTables[7][(state3 >> 8) & 0xFF] ^ + gAtermAesTables[8][state2 & 0xFF] ^ expandedKey[roundIndex * 4 + 1]; + u32 next2 = gAtermAesTables[5][state2 >> 24] ^ + gAtermAesTables[6][(state1 >> 16) & 0xFF] ^ + gAtermAesTables[7][(state0 >> 8) & 0xFF] ^ + gAtermAesTables[8][state3 & 0xFF] ^ expandedKey[roundIndex * 4 + 2]; + u32 next3 = gAtermAesTables[5][state3 >> 24] ^ + gAtermAesTables[6][(state2 >> 16) & 0xFF] ^ + gAtermAesTables[7][(state1 >> 8) & 0xFF] ^ + gAtermAesTables[8][state0 & 0xFF] ^ expandedKey[roundIndex * 4 + 3]; + + state0 = next0; + state1 = next1; + state2 = next2; + state3 = next3; + } + + { + u32 result0 = (((gAtermAesTables[9][state0 >> 24] & 0xFF000000) | + (gAtermAesTables[9][(state3 >> 16) & 0xFF] & 0x00FF0000) | + (gAtermAesTables[9][(state2 >> 8) & 0xFF] & 0x0000FF00) | + (gAtermAesTables[9][state1 & 0xFF] & 0x000000FF)) ^ expandedKey[rounds * 4]); + u32 result1 = (((gAtermAesTables[9][state1 >> 24] & 0xFF000000) | + (gAtermAesTables[9][(state0 >> 16) & 0xFF] & 0x00FF0000) | + (gAtermAesTables[9][(state3 >> 8) & 0xFF] & 0x0000FF00) | + (gAtermAesTables[9][state2 & 0xFF] & 0x000000FF)) ^ expandedKey[rounds * 4 + 1]); + u32 result2 = (((gAtermAesTables[9][state2 >> 24] & 0xFF000000) | + (gAtermAesTables[9][(state1 >> 16) & 0xFF] & 0x00FF0000) | + (gAtermAesTables[9][(state0 >> 8) & 0xFF] & 0x0000FF00) | + (gAtermAesTables[9][state3 & 0xFF] & 0x000000FF)) ^ expandedKey[rounds * 4 + 2]); + u32 result3 = (((gAtermAesTables[9][state3 >> 24] & 0xFF000000) | + (gAtermAesTables[9][(state2 >> 16) & 0xFF] & 0x00FF0000) | + (gAtermAesTables[9][(state1 >> 8) & 0xFF] & 0x0000FF00) | + (gAtermAesTables[9][state0 & 0xFF] & 0x000000FF)) ^ expandedKey[rounds * 4 + 3]); + + output[0] = result0 >> 24; + output[1] = result0 >> 16; + output[2] = result0 >> 8; + output[3] = result0; + output[4] = result1 >> 24; + output[5] = result1 >> 16; + output[6] = result1 >> 8; + output[7] = result1; + output[8] = result2 >> 24; + output[9] = result2 >> 16; + output[10] = result2 >> 8; + output[11] = result2; + output[12] = result3 >> 24; + output[13] = result3 >> 16; + output[14] = result3 >> 8; + output[15] = result3; + } +} + +void ATERM_81405D0C(u32 state[4], const u8 block[64]); + +void ATERM_81405ACC(NETMD5Context* context, const void* input, u32 length) { + const u8* data = (const u8*)input; + u32 bufferIndex = (u32)(context->length >> 3) & 0x3F; + u32 bytesToFill = 64 - bufferIndex; + u32 copiedBytes; + u32 index; + + context->length += (u64)length << 3; + if (length >= bytesToFill) { + u32 alignedBytes = bytesToFill & ~7U; + + for (copiedBytes = 0; copiedBytes < alignedBytes; copiedBytes += 8) { + context->buffer8[bufferIndex + copiedBytes] = data[copiedBytes]; + context->buffer8[bufferIndex + copiedBytes + 1] = data[copiedBytes + 1]; + context->buffer8[bufferIndex + copiedBytes + 2] = data[copiedBytes + 2]; + context->buffer8[bufferIndex + copiedBytes + 3] = data[copiedBytes + 3]; + context->buffer8[bufferIndex + copiedBytes + 4] = data[copiedBytes + 4]; + context->buffer8[bufferIndex + copiedBytes + 5] = data[copiedBytes + 5]; + context->buffer8[bufferIndex + copiedBytes + 6] = data[copiedBytes + 6]; + context->buffer8[bufferIndex + copiedBytes + 7] = data[copiedBytes + 7]; + } + for (index = copiedBytes; index < bytesToFill; index++) { + context->buffer8[bufferIndex + index] = data[index]; + } + ATERM_81405D0C(context->state, context->buffer8); + data += bytesToFill; + length -= bytesToFill; + while (length >= sizeof(context->buffer8)) { + ATERM_81405D0C(context->state, data); + data += sizeof(context->buffer8); + length -= sizeof(context->buffer8); + } + bufferIndex = 0; + } + if (length != 0) { + for (index = 0; index < length; index++) { + context->buffer8[bufferIndex + index] = data[index]; + } + } +} + +#define ATERM_MD5_STEP(A, B, C, D, WORD, CONSTANT, SHIFT, F) \ + do { \ + u32 value = (A) + (F) + (WORD) + (CONSTANT); \ + (A) = (D); \ + (D) = (C); \ + (C) = (B); \ + (B) += (value << (SHIFT)) | (value >> (32 - (SHIFT))); \ + } while (0) + +void ATERM_81405D0C(u32 state[4], const u8 block[64]) { + u32 words[16]; + u32 a = state[0]; + u32 b = state[1]; + u32 c = state[2]; + u32 d = state[3]; + u32 index; + + for (index = 0; index < 2; index++) { + const u8* inputGroup = block + index * 32; + u32* wordGroup = words + index * 8; + + wordGroup[0] = (u32)inputGroup[0] | ((u32)inputGroup[1] << 8) | + ((u32)inputGroup[2] << 16) | ((u32)inputGroup[3] << 24); + wordGroup[1] = (u32)inputGroup[4] | ((u32)inputGroup[5] << 8) | + ((u32)inputGroup[6] << 16) | ((u32)inputGroup[7] << 24); + wordGroup[2] = (u32)inputGroup[8] | ((u32)inputGroup[9] << 8) | + ((u32)inputGroup[10] << 16) | ((u32)inputGroup[11] << 24); + wordGroup[3] = (u32)inputGroup[12] | ((u32)inputGroup[13] << 8) | + ((u32)inputGroup[14] << 16) | ((u32)inputGroup[15] << 24); + wordGroup[4] = (u32)inputGroup[16] | ((u32)inputGroup[17] << 8) | + ((u32)inputGroup[18] << 16) | ((u32)inputGroup[19] << 24); + wordGroup[5] = (u32)inputGroup[20] | ((u32)inputGroup[21] << 8) | + ((u32)inputGroup[22] << 16) | ((u32)inputGroup[23] << 24); + wordGroup[6] = (u32)inputGroup[24] | ((u32)inputGroup[25] << 8) | + ((u32)inputGroup[26] << 16) | ((u32)inputGroup[27] << 24); + wordGroup[7] = (u32)inputGroup[28] | ((u32)inputGroup[29] << 8) | + ((u32)inputGroup[30] << 16) | ((u32)inputGroup[31] << 24); + } + + ATERM_MD5_STEP(a, b, c, d, words[0], 0xd76aa478, 7, (b & c) | (~b & d)); + ATERM_MD5_STEP(d, a, b, c, words[1], 0xe8c7b756, 12, (b & c) | (~b & d)); + ATERM_MD5_STEP(c, d, a, b, words[2], 0x242070db, 17, (b & c) | (~b & d)); + ATERM_MD5_STEP(b, c, d, a, words[3], 0xc1bdceee, 22, (b & c) | (~b & d)); + ATERM_MD5_STEP(a, b, c, d, words[4], 0xf57c0faf, 7, (b & c) | (~b & d)); + ATERM_MD5_STEP(d, a, b, c, words[5], 0x4787c62a, 12, (b & c) | (~b & d)); + ATERM_MD5_STEP(c, d, a, b, words[6], 0xa8304613, 17, (b & c) | (~b & d)); + ATERM_MD5_STEP(b, c, d, a, words[7], 0xfd469501, 22, (b & c) | (~b & d)); + ATERM_MD5_STEP(a, b, c, d, words[8], 0x698098d8, 7, (b & c) | (~b & d)); + ATERM_MD5_STEP(d, a, b, c, words[9], 0x8b44f7af, 12, (b & c) | (~b & d)); + ATERM_MD5_STEP(c, d, a, b, words[10], 0xffff5bb1, 17, (b & c) | (~b & d)); + ATERM_MD5_STEP(b, c, d, a, words[11], 0x895cd7be, 22, (b & c) | (~b & d)); + ATERM_MD5_STEP(a, b, c, d, words[12], 0x6b901122, 7, (b & c) | (~b & d)); + ATERM_MD5_STEP(d, a, b, c, words[13], 0xfd987193, 12, (b & c) | (~b & d)); + ATERM_MD5_STEP(c, d, a, b, words[14], 0xa679438e, 17, (b & c) | (~b & d)); + ATERM_MD5_STEP(b, c, d, a, words[15], 0x49b40821, 22, (b & c) | (~b & d)); + ATERM_MD5_STEP(a, b, c, d, words[1], 0xf61e2562, 5, (d & b) | (~d & c)); + ATERM_MD5_STEP(d, a, b, c, words[6], 0xc040b340, 9, (d & b) | (~d & c)); + ATERM_MD5_STEP(c, d, a, b, words[11], 0x265e5a51, 14, (d & b) | (~d & c)); + ATERM_MD5_STEP(b, c, d, a, words[0], 0xe9b6c7aa, 20, (d & b) | (~d & c)); + ATERM_MD5_STEP(a, b, c, d, words[5], 0xd62f105d, 5, (d & b) | (~d & c)); + ATERM_MD5_STEP(d, a, b, c, words[10], 0x02441453, 9, (d & b) | (~d & c)); + ATERM_MD5_STEP(c, d, a, b, words[15], 0xd8a1e681, 14, (d & b) | (~d & c)); + ATERM_MD5_STEP(b, c, d, a, words[4], 0xe7d3fbc8, 20, (d & b) | (~d & c)); + ATERM_MD5_STEP(a, b, c, d, words[9], 0x21e1cde6, 5, (d & b) | (~d & c)); + ATERM_MD5_STEP(d, a, b, c, words[14], 0xc33707d6, 9, (d & b) | (~d & c)); + ATERM_MD5_STEP(c, d, a, b, words[3], 0xf4d50d87, 14, (d & b) | (~d & c)); + ATERM_MD5_STEP(b, c, d, a, words[8], 0x455a14ed, 20, (d & b) | (~d & c)); + ATERM_MD5_STEP(a, b, c, d, words[13], 0xa9e3e905, 5, (d & b) | (~d & c)); + ATERM_MD5_STEP(d, a, b, c, words[2], 0xfcefa3f8, 9, (d & b) | (~d & c)); + ATERM_MD5_STEP(c, d, a, b, words[7], 0x676f02d9, 14, (d & b) | (~d & c)); + ATERM_MD5_STEP(b, c, d, a, words[12], 0x8d2a4c8a, 20, (d & b) | (~d & c)); + ATERM_MD5_STEP(a, b, c, d, words[5], 0xfffa3942, 4, b ^ c ^ d); + ATERM_MD5_STEP(d, a, b, c, words[8], 0x8771f681, 11, b ^ c ^ d); + ATERM_MD5_STEP(c, d, a, b, words[11], 0x6d9d6122, 16, b ^ c ^ d); + ATERM_MD5_STEP(b, c, d, a, words[14], 0xfde5380c, 23, b ^ c ^ d); + ATERM_MD5_STEP(a, b, c, d, words[1], 0xa4beea44, 4, b ^ c ^ d); + ATERM_MD5_STEP(d, a, b, c, words[4], 0x4bdecfa9, 11, b ^ c ^ d); + ATERM_MD5_STEP(c, d, a, b, words[7], 0xf6bb4b60, 16, b ^ c ^ d); + ATERM_MD5_STEP(b, c, d, a, words[10], 0xbebfbc70, 23, b ^ c ^ d); + ATERM_MD5_STEP(a, b, c, d, words[13], 0x289b7ec6, 4, b ^ c ^ d); + ATERM_MD5_STEP(d, a, b, c, words[0], 0xeaa127fa, 11, b ^ c ^ d); + ATERM_MD5_STEP(c, d, a, b, words[3], 0xd4ef3085, 16, b ^ c ^ d); + ATERM_MD5_STEP(b, c, d, a, words[6], 0x04881d05, 23, b ^ c ^ d); + ATERM_MD5_STEP(a, b, c, d, words[9], 0xd9d4d039, 4, b ^ c ^ d); + ATERM_MD5_STEP(d, a, b, c, words[12], 0xe6db99e5, 11, b ^ c ^ d); + ATERM_MD5_STEP(c, d, a, b, words[15], 0x1fa27cf8, 16, b ^ c ^ d); + ATERM_MD5_STEP(b, c, d, a, words[2], 0xc4ac5665, 23, b ^ c ^ d); + ATERM_MD5_STEP(a, b, c, d, words[0], 0xf4292244, 6, c ^ (b | ~d)); + ATERM_MD5_STEP(d, a, b, c, words[7], 0x432aff97, 10, c ^ (b | ~d)); + ATERM_MD5_STEP(c, d, a, b, words[14], 0xab9423a7, 15, c ^ (b | ~d)); + ATERM_MD5_STEP(b, c, d, a, words[5], 0xfc93a039, 21, c ^ (b | ~d)); + ATERM_MD5_STEP(a, b, c, d, words[12], 0x655b59c3, 6, c ^ (b | ~d)); + ATERM_MD5_STEP(d, a, b, c, words[3], 0x8f0ccc92, 10, c ^ (b | ~d)); + ATERM_MD5_STEP(c, d, a, b, words[10], 0xffeff47d, 15, c ^ (b | ~d)); + ATERM_MD5_STEP(b, c, d, a, words[1], 0x85845dd1, 21, c ^ (b | ~d)); + ATERM_MD5_STEP(a, b, c, d, words[8], 0x6fa87e4f, 6, c ^ (b | ~d)); + ATERM_MD5_STEP(d, a, b, c, words[15], 0xfe2ce6e0, 10, c ^ (b | ~d)); + ATERM_MD5_STEP(c, d, a, b, words[6], 0xa3014314, 15, c ^ (b | ~d)); + ATERM_MD5_STEP(b, c, d, a, words[13], 0x4e0811a1, 21, c ^ (b | ~d)); + ATERM_MD5_STEP(a, b, c, d, words[4], 0xf7537e82, 6, c ^ (b | ~d)); + ATERM_MD5_STEP(d, a, b, c, words[11], 0xbd3af235, 10, c ^ (b | ~d)); + ATERM_MD5_STEP(c, d, a, b, words[2], 0x2ad7d2bb, 15, c ^ (b | ~d)); + ATERM_MD5_STEP(b, c, d, a, words[9], 0xeb86d391, 21, c ^ (b | ~d)); + + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; +} +#undef ATERM_MD5_STEP + +void ATERM_8140684C(OSAlarm* alarm, OSContext* context) { + OSMessageQueue* queue = (OSMessageQueue*)alarm->tag; + OSSendMessage(queue, NULL, 0); +} + +int ATERMi_ApConfigStart(OSPriority priority, u32 scanLimit, + AtermProgressCallback progressCallback, + AtermAllocateCallback allocateCallback, + AtermFreeCallback freeCallback, u32 stackSize) { + AtermProgress progress; + + if (gAtermState > 0 && gAtermState < 6) { + return -10; + } + + gAtermState = 7; + gAtermScanLimit = scanLimit; + gAtermScanBufferSize = stackSize; + gAtermProgressCallback = progressCallback; + gAtermAllocate = allocateCallback; + gAtermRelease = freeCallback; + gAtermAllocation = allocateCallback(stackSize); + if (gAtermAllocation == NULL) { + gAtermResult = -1; + return -1; + } + + OSCreateThread(&sAtermThread, (void* (*)(void*))ATERMi_AutoConfigThread, NULL, + (u8*)gAtermAllocation + (stackSize & ~7), stackSize, priority, 1); + gAtermState = 1; + gAtermDeadline = (u32)(OSGetTime() / + (__mulhwu(0x10624DD3, OS_BUS_CLOCK >> 2) >> 6)) + 60000; + gAtermCancelRequested = 0; + memset(&gAtermConfigurationResult, 0, 0xE8); + + progress.state = gAtermState; + if (gAtermDeadline == 0xFFFFFFFF) { + progress.remainingTime = -1; + } else { + progress.remainingTime = gAtermDeadline - + (u32)(OSGetTime() / + (__mulhwu(0x10624DD3, OS_BUS_CLOCK >> 2) >> 6)); + } + progress.result = gAtermResult; + progressCallback(&progress); + OSResumeThread(&sAtermThread); + gAtermThreadStarted = 1; + return 1; +} + +int ATERMi_ApConfigEnd(void) { + s32 initialState = gAtermState; + + if (gAtermThreadStarted != 0) { + OSMessageQueue cancelQueue; + OSMessage cancelQueueBuffer; + OSMessage cancelMessage; + OSAlarm cancelAlarm; + OSMessageQueue joinQueue; + OSMessage joinQueueBuffer; + OSMessage joinMessage; + OSAlarm joinAlarm; + + gAtermCancelRequested = 1; + while (gAtermState >= 1 && gAtermState <= 5) { + OSInitMessageQueue(&cancelQueue, &cancelQueueBuffer, 1); + OSCreateAlarm(&cancelAlarm); + OSSetAlarmTag(&cancelAlarm, (u32)&cancelQueue); + OSSetAlarm(&cancelAlarm, + (__mulhwu(0x10624DD3, OS_BUS_CLOCK >> 2) >> 6) * 100, + ATERM_8140684C); + OSReceiveMessage(&cancelQueue, &cancelMessage, 1); + } + + OSInitMessageQueue(&joinQueue, &joinQueueBuffer, 1); + OSCreateAlarm(&joinAlarm); + OSSetAlarmTag(&joinAlarm, (u32)&joinQueue); + OSSetAlarm(&joinAlarm, 0x10624DD3, ATERM_8140684C); + OSReceiveMessage(&joinQueue, &joinMessage, 1); + while (OSIsThreadTerminated(&sAtermThread) == 0) { + OSJoinThread(&sAtermThread, NULL); + } + + if (gAtermAllocation != NULL) { + gAtermRelease(gAtermAllocation); + gAtermAllocation = NULL; + } + gAtermThreadStarted = 0; + if (initialState != gAtermState) { + AtermProgress progress; + progress.state = gAtermState; + if (gAtermDeadline == 0xFFFFFFFF) { + progress.remainingTime = -1; + } else { + OSTime now = OSGetTime(); + u32 busClock = OS_BUS_CLOCK >> 2; + u32 reciprocal = 0x10624DD3; + u32 ticksPerMillisecond = __mulhwu(reciprocal, busClock) >> 6; + u32 elapsedMilliseconds = (u32)(now / ticksPerMillisecond); + progress.remainingTime = gAtermDeadline - elapsedMilliseconds; + } + progress.result = gAtermResult; + gAtermProgressCallback(&progress); + } + } + return 1; +} + +int ATERMi_ApConfigGetState(AtermProgress* progress) { + progress->state = gAtermState; + if (gAtermDeadline == 0xFFFFFFFF) { + progress->remainingTime = -1; + } else { + OSTime currentTime = OSGetTime(); + u32 busClock = OS_BUS_CLOCK >> 2; + u32 reciprocal = 0x10624DD3; + u32 ticksPerMillisecond = __mulhwu(busClock, reciprocal) >> 6; + u32 elapsedMilliseconds = (u32)(currentTime / ticksPerMillisecond); + progress->remainingTime = gAtermDeadline - elapsedMilliseconds; + } + progress->result = gAtermResult; + return 1; +} + +int ATERMi_ApConfigGetResult(void* result) { + memcpy(result, &gAtermConfigurationResult, 0xE8); + return 1; +} + +int ATERMi_ApConfigGetVersion(void) { + return 0x106; +} -- 2.49.1 From 3b93fc8664a4c710b745c87771d346c63ec655a1 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 29 Sep 2026 08:54:49 -0500 Subject: [PATCH 17/18] iplSDChannelSelect: 90/129 functions (worker 9a63deb2) (#268) --- src/scene/sdChannelSelect/iplSDChannelSelect.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/scene/sdChannelSelect/iplSDChannelSelect.cpp b/src/scene/sdChannelSelect/iplSDChannelSelect.cpp index 218d0044..88cdb7c1 100644 --- a/src/scene/sdChannelSelect/iplSDChannelSelect.cpp +++ b/src/scene/sdChannelSelect/iplSDChannelSelect.cpp @@ -2958,7 +2958,7 @@ namespace ipl { mpPointerLayout = new layout::Object(getSceneHeap(), mpLayoutFile, "arc", "wait_icon.brlyt"); - mpPointerLayout->bind("wait_icon_wait_loop.brlan", NULL, false, true); + mpPointerLayout->bind("wait_icon_wait_loop.brlan", "Wait_00", false, true); mpPointerLayout->finishBinding(); mpPointerLayout->getAnim(0)->initAnmFrame(); @@ -3049,8 +3049,10 @@ namespace ipl { SDChannelObj* channel = NULL; while (channel = static_cast(nw4r::ut::List_GetNext(&mChannelObjects, channel)), channel != NULL) { - iplSDChannelObj_813E3480( - channel, channel->getPage() == page && channel->getIndex() == index); + int channelPage = channel->getPage(); + int channelIndex = channel->getIndex(); + bool selected = channelPage == page && channelIndex == index; + iplSDChannelObj_813E3480(channel, selected); } snd::getSystem()->startSEwithPos("WIPL_SE_CH_HOLD", mPointerPosition.x); -- 2.49.1 From ead5d19fc14bab9db147bf950a466d57ba7acfda Mon Sep 17 00:00:00 2001 From: devin Date: Tue, 29 Sep 2026 14:06:57 +0000 Subject: [PATCH 18/18] nhttp: link 8 matched units (bgnend, control, list, os_RVL, request, response, d_nhttp, d_nhttp_common) Co-Authored-By: wch --- configure.py | 16 +- libs/RevoEX/include/private/nhttp.h | 182 +++++ libs/RevoEX/include/revolution/nhttp.h | 88 ++- libs/RevoEX/include/revolution/so/SOBasic.h | 5 +- libs/RevoEX/include/revolution/so/SOOption.h | 1 + libs/RevoEX/src/nhttp/NHTTP_bgnend.c | 179 +++++ libs/RevoEX/src/nhttp/NHTTP_control.c | 102 +++ libs/RevoEX/src/nhttp/NHTTP_list.c | 126 ++++ libs/RevoEX/src/nhttp/NHTTP_os_RVL.c | 120 ++++ libs/RevoEX/src/nhttp/NHTTP_request.c | 487 ++++++++++++++ libs/RevoEX/src/nhttp/NHTTP_response.c | 202 ++++++ libs/RevoEX/src/nhttp/d_nhttp.c | 673 +++++++++++++++++++ libs/RevoEX/src/nhttp/d_nhttp_common.c | 421 ++++++++++++ 13 files changed, 2564 insertions(+), 38 deletions(-) create mode 100644 libs/RevoEX/include/private/nhttp.h create mode 100644 libs/RevoEX/src/nhttp/NHTTP_bgnend.c create mode 100644 libs/RevoEX/src/nhttp/NHTTP_control.c create mode 100644 libs/RevoEX/src/nhttp/NHTTP_list.c create mode 100644 libs/RevoEX/src/nhttp/NHTTP_os_RVL.c create mode 100644 libs/RevoEX/src/nhttp/NHTTP_request.c create mode 100644 libs/RevoEX/src/nhttp/NHTTP_response.c create mode 100644 libs/RevoEX/src/nhttp/d_nhttp.c create mode 100644 libs/RevoEX/src/nhttp/d_nhttp_common.c diff --git a/configure.py b/configure.py index bb86da5b..01fb5790 100644 --- a/configure.py +++ b/configure.py @@ -1053,19 +1053,19 @@ config.libs = [ ] ), RevoEXLib("nhttp", [ - Object(NonMatching, "nhttp/NHTTP_bgnend.c"), - Object(NonMatching, "nhttp/NHTTP_control.c"), - Object(NonMatching, "nhttp/NHTTP_list.c"), - Object(NonMatching, "nhttp/NHTTP_os_RVL.c"), + Object(Matching, "nhttp/NHTTP_bgnend.c"), + Object(Matching, "nhttp/NHTTP_control.c"), + Object(Matching, "nhttp/NHTTP_list.c"), + Object(Matching, "nhttp/NHTTP_os_RVL.c"), Object(NonMatching, "nhttp/NHTTP_recvbuf.c"), - Object(NonMatching, "nhttp/NHTTP_request.c"), - Object(NonMatching, "nhttp/NHTTP_response.c"), + Object(Matching, "nhttp/NHTTP_request.c"), + Object(Matching, "nhttp/NHTTP_response.c"), Object(NonMatching, "nhttp/NHTTP_socket_RVL.c"), Object(NonMatching, "nhttp/NHTTP_stdlib_RVL.c"), Object(NonMatching, "nhttp/NHTTP_thread.c"), Object(NonMatching, "nhttp/d_nhttp_private.c"), - Object(NonMatching, "nhttp/d_nhttp.c"), - Object(NonMatching, "nhttp/d_nhttp_common.c"), + Object(Matching, "nhttp/d_nhttp.c"), + Object(Matching, "nhttp/d_nhttp_common.c"), ] ), RevoEXLib("nwc24", [ diff --git a/libs/RevoEX/include/private/nhttp.h b/libs/RevoEX/include/private/nhttp.h new file mode 100644 index 00000000..9926ad42 --- /dev/null +++ b/libs/RevoEX/include/private/nhttp.h @@ -0,0 +1,182 @@ +#ifndef PRIVATE_NHTTP_H +#define PRIVATE_NHTTP_H + +#include +#include +#include + +#define STR_POSTBOUND "--t9Sf4yfjf1RtvDu3AA" +#define LEN_POSTBOUND 18 +#define LEN_URLBUF 256 +#define MIN(AA, BB) (((AA) > (BB)) ? (BB) : (AA)) + +typedef struct NHTTPBgnEndInfo NHTTPBgnEndInfo; +typedef struct NHTTPRequestInfo NHTTPRequestInfo; +#define NHTTP_CONN_RECVBUF_SIZE 0x8000 + +typedef struct NHTTPConnectionInfo NHTTPConnectionInfo; + +typedef enum NHTTPConnectionEvent +{ + NHTTP_EVENT_NONE, + NHTTP_EVENT_POST_SEND, + NHTTP_EVENT_BODY_RECV_FULL, + NHTTP_EVENT_BODY_RECV_DONE, + NHTTP_EVENT_COMPLETE, + NHTTP_CALLBACK_EVENT_MAX, +} NHTTPConnectionEvent; + +typedef s32 (*NHTTPConnectionCallback)(NHTTPConnectionInfo* connection, + NHTTPConnectionEvent event, void* arg); + +typedef struct NHTTPConnectionCallbackParam +{ + void* value; + u32 _unk4; + u32 _unk8; + u32 _unkC; +} NHTTPConnectionCallbackParam; + +typedef struct NHTTPPostSendArg +{ + const char* label; + char* buf; + u32 size; + u32 offset; +} NHTTPPostSendArg; + +typedef struct NHTTPBodyBufArg +{ + char* buf; + u32 size; + u32 offset; +} NHTTPBodyBufArg; + +typedef struct NHTTPHeader +{ + struct NHTTPHeader* next; + struct NHTTPHeader* prev; + char* name; + char* value; + u32 length; + u32 _unk14; +} NHTTPHeader; + +typedef struct NHTTPReqQueue +{ + struct NHTTPReqQueue* next; + struct NHTTPReqQueue* prev; + s32 requestId; + NHTTPRequestInfo* volatile request; + s32 _unk10; +} NHTTPReqQueue; + +typedef struct NHTTPListInfo +{ + NHTTPReqQueue* reqQueue; + s32 nextRequestId; +} NHTTPListInfo; + +typedef struct NHTTPReqInfo +{ + NHTTPReqQueue* reqQueue; +} NHTTPReqInfo; + +typedef struct NHTTPi_HDRBUFLIST +{ + struct NHTTPi_HDRBUFLIST* next_p; + u8 block[NHTTP_HDRRECVBUF_BLOCKLEN]; +} NHTTPi_HDRBUFLIST; + +typedef struct NHTTPResponseInfo +{ + volatile s32 headerLen; + volatile s32 bodyLen; + volatile s32 totalBodyLen; + volatile s32 contentLength; + s32 isSuccess; + s32 isHeaderParse; + s32 httpStatus; + u32 recvBufLen; + char* allHeader_p; + char* foundHeader_p; + char* recvBuf_p; + NHTTPResponseCallback bufFull; + NHTTPResponseCleanup freeBuf; + NHTTPi_HDRBUFLIST* hdrBufBlock_p; + u8 hdrBufFirst[NHTTP_HDRRECVBUF_INILEN]; + void* param_p; +} NHTTPResponseInfo; + +struct NHTTPRequestInfo +{ + BOOL cancel; + s32 state; + BOOL secure; + BOOL proxyEnabled; + BOOL isRawData; + s32 hostEnd; + s32 pathStart; + s32 method; + u32 port; + char* url; + char* host; + NHTTPResponseInfo* response; + NHTTPHeader* headers; + NHTTPHeader* postData; + char multipartBoundary[LEN_POSTBOUND + 2]; + char authorization[0x5C]; + s32 authorizationLength; + SSLId sslId; + const char* clientCertData; + u32 clientCertSize; + const char* privateKeyData; + u32 privateKeySize; + const char* rootCAData; + u32 rootCASize; + BOOL clientCertDefault; + u32 verifyOption; + NHTTPEncodingType encodingType; + void* _unkD4; + u32 builtinRootCA; + u32 builtinClientCert; + char proxyServer[0x100]; + u32 proxyPort; + char proxyAuthorization[0x5C]; + s32 proxyAuthorizationLength; + u32 recvBufferSize; + const void* postBuffer; + u32 postBufferSize; + void* _unk250; +}; + +struct NHTTPConnectionInfo +{ + BOOL started; + s32 state; + s32 sslError; + u32 _unkC; + NHTTPRequestInfo* request; + NHTTPResponseInfo* response; + s32 requestId; + NHTTPConnectionCallback callback; + NHTTPConnectionInfo* next; + u32 _unk24; + u32 _unk28; + u32 virtualContentLength; + NHTTPReqCallback requestCallback; + u32 _unk34; + u32 _unk38; + u32 _unk3C; + u8 recvBuf[0x8000]; + u32 recvBufOffset; + u32 recvBufDataLen; + u32 _unk8048; + u32 _unk804C; + u32 _unk8050; + u32 _unk8054; + u32 _unk8058; + u32 _unk805C; +}; + +#endif // PRIVATE_NHTTP_H diff --git a/libs/RevoEX/include/revolution/nhttp.h b/libs/RevoEX/include/revolution/nhttp.h index d94db82c..6fc0bb9d 100644 --- a/libs/RevoEX/include/revolution/nhttp.h +++ b/libs/RevoEX/include/revolution/nhttp.h @@ -1,4 +1,3 @@ - #ifndef REVOLUTION_NHTTP_H #define REVOLUTION_NHTTP_H @@ -6,49 +5,80 @@ #include +#define NHTTP_HDRRECVBUF_INILEN 1024 +#define NHTTP_HDRRECVBUF_BLOCKSHIFT 9 +#define NHTTP_HDRRECVBUF_BLOCKLEN (1 << NHTTP_HDRRECVBUF_BLOCKSHIFT) +#define NHTTP_HDRRECVBUF_BLOCKMASK (NHTTP_HDRRECVBUF_BLOCKLEN - 1) + #ifdef __cplusplus extern "C" { #endif // __cplusplus -typedef struct { - u8 dummy[1]; -} NHTTPRequest; -typedef struct { - u8 dummy[1]; -} NHTTPResponse; - -typedef int NHTTPConnection; - typedef void* (*NHTTPAlloc)(u32 size, int align); typedef void (*NHTTPFree)(void* buf); - -typedef void (*NHTTPRequestCallback)(int, NHTTPResponse*); typedef void (*NHTTPCleanupCallback)(); -int NHTTPStartup(NHTTPAlloc alloc, NHTTPFree free, u32 priority); -int NHTTPCleanupAsync(NHTTPCleanupCallback); -int NHTTPGetError(); +typedef struct NHTTPRequestInfo NHTTPRequest; +typedef struct NHTTPResponseInfo NHTTPResponse; +typedef s32 NHTTPConnection; -NHTTPRequest* NHTTPCreateRequest(char* url, undefined4, void* buf, u32 bufSize, NHTTPRequestCallback reqCallback, undefined4); -NHTTPRequest* NHTTPCreateRequestEx(char* url, undefined4, void* buf, u32 bufSize, NHTTPRequestCallback reqCallback, undefined4, undefined4, - undefined4); -int NHTTPDeleteRequest(NHTTPRequest* request); +typedef enum NHTTPReqMethod { + NHTTP_REQMETHOD_GET, + NHTTP_REQMETHOD_POST, + NHTTP_REQMETHOD_HEAD, +} NHTTPReqMethod; + +typedef enum NHTTPEncodingType { + NHTTP_ENCODING_TYPE_AUTO, + NHTTP_ENCODING_TYPE_URL, + NHTTP_ENCODING_TYPE_MULTIPART, + NHTTP_ENCODING_TYPE_MAX, +} NHTTPEncodingType; + +typedef void (*NHTTPReqCallback)(); +typedef void* (*NHTTPResponseCallback)(void** buffer, void* data, + u32 contentLength, NHTTPAlloc alloc, + NHTTPFree free, void* userParam); +typedef void (*NHTTPResponseCleanup)(void* buffer, NHTTPFree free, + void* userParam); + +s32 NHTTPStartup(NHTTPAlloc alloc, NHTTPFree free, u32 priority); +void NHTTPCleanupAsync(NHTTPCleanupCallback callback); +s32 NHTTPGetError(void); + +NHTTPRequest* NHTTPCreateRequest(const char* url, NHTTPReqMethod method, + void* buffer, u32 bufferSize, + NHTTPReqCallback callback, void* userParam); +NHTTPRequest* NHTTPCreateRequestEx(const char* url, NHTTPReqMethod method, + void* buffer, u32 bufferSize, + NHTTPReqCallback callback, void* userParam, + NHTTPResponseCallback responseCallback, + NHTTPResponseCleanup cleanup); +s32 NHTTPAddHeaderField(NHTTPRequest* request, const char* name, + const char* value); +s32 NHTTPAddPostDataRaw(NHTTPRequest* request, const void* data, + u32 size, const char* label); +s32 NHTTPDeleteRequest(NHTTPRequest* request); NHTTPConnection NHTTPSendRequestAsync(NHTTPRequest* request); -int NHTTPCancelRequestAsync(NHTTPConnection connection); +s32 NHTTPCancelRequestAsync(NHTTPConnection connection); -void NHTTPGetProgress(u32* complete, u32* total); +s32 NHTTPGetProgress(u32* complete, u32* total); -int NHTTPDestroyResponse(NHTTPResponse* response); -u32 NHTTPGetHeaderField(NHTTPResponse* response, const char* name, const char** value); +void NHTTPDestroyResponse(NHTTPResponse* response); +s32 NHTTPGetHeaderAll(NHTTPResponse* response, const char** header); +s32 NHTTPGetHeaderField(NHTTPResponse* response, const char* name, + const char** value); -int NHTTPGetResultCode(NHTTPResponse* res); +s32 NHTTPGetBodyAll(NHTTPResponse* response, void** buffer); +s32 NHTTPGetResultCode(NHTTPResponse* response); -int NHTTPSetVerifyOption(NHTTPRequest* request, u32 option); - -int NHTTPSetProxyDefault(NHTTPRequest* request); -int NHTTPSetRootCADefault(NHTTPRequest* request); -int NHTTPSetClientCertDefault(NHTTPRequest* request); +s32 NHTTPSetVerifyOption(NHTTPRequest* request, u32 option); +s32 NHTTPSetProxy(NHTTPRequest* request, const char* server, u16 port, + const char* username, const char* password); +s32 NHTTPSetProxyDefault(NHTTPRequest* request); +s32 NHTTPSetClientCertDefault(NHTTPRequest* request); +s32 NHTTPSetRootCADefault(NHTTPRequest* request); #ifdef __cplusplus } diff --git a/libs/RevoEX/include/revolution/so/SOBasic.h b/libs/RevoEX/include/revolution/so/SOBasic.h index b79a96bd..54ef91ee 100644 --- a/libs/RevoEX/include/revolution/so/SOBasic.h +++ b/libs/RevoEX/include/revolution/so/SOBasic.h @@ -102,13 +102,16 @@ struct SOAddrInfo { SOAddrInfo* next; // 0x20 }; +#define SO_ENOTCONN -56 + int SOSocket(int pf, int type, int protocol); +int __SOCreateSocket(int pf, int type, int protocol); int SOClose(int s); int SOConnect(int s, void* sockAddr); int SORecv(int s, void* buf, int len, int flags); -int SOSend(int s, void* buf, int len, int flags); +int SOSend(int s, const void* buf, int len, int flags); int SOFcntl(int s, int cmd, ...); int SOShutdown(int s, int how); diff --git a/libs/RevoEX/include/revolution/so/SOOption.h b/libs/RevoEX/include/revolution/so/SOOption.h index 76e1fa64..df35c735 100644 --- a/libs/RevoEX/include/revolution/so/SOOption.h +++ b/libs/RevoEX/include/revolution/so/SOOption.h @@ -14,6 +14,7 @@ typedef struct IPAddrEntry { } IPAddrEntry; int SOGetInterfaceOpt(void* unk, int level, int optname, void* optval, int* optlen); +int SOSetSockOpt(int s, int level, int optname, const void* optval, int optlen); #ifdef __cplusplus } diff --git a/libs/RevoEX/src/nhttp/NHTTP_bgnend.c b/libs/RevoEX/src/nhttp/NHTTP_bgnend.c new file mode 100644 index 00000000..85588e15 --- /dev/null +++ b/libs/RevoEX/src/nhttp/NHTTP_bgnend.c @@ -0,0 +1,179 @@ +#include + +#include +#include + +#include + +int SOClose(int s); + +typedef struct NHTTPBgnEndInfo +{ + NCDIpConfig ipConfig; + NHTTPAlloc alloc; + NHTTPFree free; + BOOL started; + s32 socket; + s32 sslError; + NHTTPErr error; + u32 _unk7DC; + void* threadStack; + u32 _unk7E4; +} NHTTPBgnEndInfo; + +NHTTPBgnEndInfo* NHTTPi_GetSystemInfoP(void); +NHTTPBgnEndInfo* NHTTPi_GetBgnEndInfoP(void* systemInfo); +void* NHTTPi_GetListInfoP(void* systemInfo); +void* NHTTPi_GetReqInfoP(void* systemInfo); +void* NHTTPi_GetMutexInfoP(void* systemInfo); +void* NHTTPi_GetThreadInfoP(void* systemInfo); + +void NHTTPi_InitListInfo(void* listInfo); +void NHTTPi_InitRequestInfo(void* reqInfo); +void NHTTPi_initLockReqList(void* mutexInfo); +void NHTTPi_exitLockReqList(void); +BOOL NHTTPi_createCommThread(void* threadInfo, u32 priority, void* stack); +void NHTTPi_destroyCommThread(void* threadInfo, NHTTPBgnEndInfo* bgnEndInfo); +void NHTTPi_CheckCurrentThread(void* threadInfo, BOOL allowCommThread); +void NHTTPi_cancelAllRequests(void* systemInfo); +int NHTTPi_GetConnectionListLength(void); +void NHTTPi_InitConnectionList(void); + +void NHTTPi_InitBgnEndInfo(NHTTPBgnEndInfo* info) +{ + info->sslError = 0; + info->error = NHTTP_ERROR_NONE; + info->alloc = NULL; + info->free = NULL; + info->started = FALSE; + info->socket = -1; + info->_unk7DC = 0; + info->threadStack = NULL; + info->_unk7E4 = 0; +} + +void* NHTTPi_alloc(u32 size, int align) +{ + NHTTPBgnEndInfo* info = NHTTPi_GetSystemInfoP(); + + if (info->alloc != NULL) + { + return info->alloc(size, align); + } + return NULL; +} + +void NHTTPi_free(void* buf) +{ + NHTTPBgnEndInfo* info = NHTTPi_GetSystemInfoP(); + + if (info->free != NULL) + { + info->free(buf); + } +} + +void NHTTPi_SetError(NHTTPBgnEndInfo* info, NHTTPErr error) +{ + info->error = error; +} + +void NHTTPi_SetSSLError(NHTTPBgnEndInfo* info, s32 error) +{ + info->sslError = error; +} + +s32 NHTTPi_GetSSLError(NHTTPBgnEndInfo* info) +{ + return info->sslError; +} + +BOOL NHTTPi_Startup(void* systemInfo, NHTTPAlloc alloc, NHTTPFree free, + u32 priority) +{ + NHTTPBgnEndInfo* bgnEndInfo = NHTTPi_GetBgnEndInfoP(systemInfo); + void* listInfo = NHTTPi_GetListInfoP(systemInfo); + void* reqInfo = NHTTPi_GetReqInfoP(systemInfo); + void* mutexInfo = NHTTPi_GetMutexInfoP(systemInfo); + void* threadInfo = NHTTPi_GetThreadInfoP(systemInfo); + void* stack; + NCDErr result; + + bgnEndInfo->alloc = alloc; + bgnEndInfo->free = free; + bgnEndInfo->error = NHTTP_ERROR_NONE; + bgnEndInfo->sslError = 0; + bgnEndInfo->_unk7DC = 0; + + NHTTPi_InitListInfo(listInfo); + NHTTPi_InitRequestInfo(reqInfo); + NHTTPi_initLockReqList(mutexInfo); + NHTTPi_InitConnectionList(); + bgnEndInfo->socket = -1; + + stack = NHTTPi_alloc(0x2000, 8); + bgnEndInfo->threadStack = stack; + if (stack == NULL) + { + bgnEndInfo->error = NHTTP_ERROR_ALLOC; + NHTTPi_exitLockReqList(); + return FALSE; + } + + if (!NHTTPi_createCommThread(threadInfo, priority, stack)) + { + bgnEndInfo->error = NHTTP_ERROR_REVOLUTIONSDK; + NHTTPi_free(bgnEndInfo->threadStack); + bgnEndInfo->threadStack = NULL; + NHTTPi_exitLockReqList(); + return FALSE; + } + + result = NCDGetCurrentIpConfig(&bgnEndInfo->ipConfig); + if (result < 0) + { + OSReport("NCDGetCurrentIpConfig err = %d\n", result); + OSPanic("NHTTP_bgnend.c", 230, "NCDGetCurrentIpConfig"); + } + + bgnEndInfo->started = TRUE; + return TRUE; +} + +void NHTTPi_CleanupAsync(void* systemInfo, NHTTPCleanupCallback callback) +{ + NHTTPBgnEndInfo* bgnEndInfo = NHTTPi_GetBgnEndInfoP(systemInfo); + void* threadInfo = NHTTPi_GetThreadInfoP(systemInfo); + int connectionCount; + + NHTTPi_CheckCurrentThread(threadInfo, TRUE); + NHTTPi_cancelAllRequests(systemInfo); + NHTTPi_destroyCommThread(threadInfo, bgnEndInfo); + NHTTPi_free(bgnEndInfo->threadStack); + bgnEndInfo->threadStack = NULL; + NHTTPi_exitLockReqList(); + bgnEndInfo->started = FALSE; + + if (callback != NULL) + { + callback(); + } + + connectionCount = NHTTPi_GetConnectionListLength(); + if (connectionCount != 0) + { + printf("*warning: %d connections rests! Please free connections.\n", + connectionCount); + } + + if (bgnEndInfo->socket >= 0) + { + SOClose(bgnEndInfo->socket); + bgnEndInfo->socket = -1; + } +} + +s32 NHTTPi_GetError(NHTTPBgnEndInfo* info) +{ + return info->error; +} diff --git a/libs/RevoEX/src/nhttp/NHTTP_control.c b/libs/RevoEX/src/nhttp/NHTTP_control.c new file mode 100644 index 00000000..adc5225f --- /dev/null +++ b/libs/RevoEX/src/nhttp/NHTTP_control.c @@ -0,0 +1,102 @@ +#include + +#include +s32 NHTTPi_compareToken(const char* lhs, const char* rhs); +void* NHTTPi_alloc(u32 size, int align); +void NHTTPi_SetError(NHTTPBgnEndInfo* info, NHTTPErr error); + +static BOOL addHdrList(NHTTPHeader** list, NHTTPBgnEndInfo* info, char* name, + char* value) +{ + BOOL found = FALSE; + NHTTPHeader* header = *list; + + if (header != NULL) + { + if (NHTTPi_compareToken(name, header->name) != 0) + { + header = header->prev; + while (header != *list) + { + if (NHTTPi_compareToken(name, header->name) == 0) + { + found = TRUE; + break; + } + header = header->prev; + } + } + else + { + found = TRUE; + } + } + + if (found) + { + header->value = value; + } + else + { + header = NHTTPi_alloc(sizeof(NHTTPHeader), 4); + if (header == NULL) + { + printf("failed to allocate memory\n"); + NHTTPi_SetError(info, NHTTP_ERROR_ALLOC); + return FALSE; + } + + header->name = name; + header->value = value; + header->length = 0; + header->_unk14 = 0; + + if (*list != NULL) + { + header->next = (*list)->next; + header->prev = *list; + (*list)->next->prev = header; + (*list)->next = header; + } + else + { + header->prev = header; + header->next = header; + *list = header; + } + } + + return TRUE; +} + +NHTTPHeader* NHTTPi_getHdrFromList(NHTTPHeader** list) +{ + NHTTPHeader* header = *list; + + if (header != NULL) + { + if (header != header->next) + { + header->next->prev = header->prev; + header->prev->next = header->next; + *list = header->prev; + } + else + { + *list = NULL; + } + } + + return header; +} + +BOOL NHTTP_AddHeaderField(NHTTPRequestInfo* request, NHTTPBgnEndInfo* info, + char* name, char* value) +{ + if (request->state != 0) + { + return FALSE; + } + return addHdrList(&request->headers, info, name, value); +} + diff --git a/libs/RevoEX/src/nhttp/NHTTP_list.c b/libs/RevoEX/src/nhttp/NHTTP_list.c new file mode 100644 index 00000000..2a600916 --- /dev/null +++ b/libs/RevoEX/src/nhttp/NHTTP_list.c @@ -0,0 +1,126 @@ +#include + +void* NHTTPi_alloc(u32 size, int align); +void NHTTPi_free(void* ptr); +NHTTPConnectionInfo* NHTTPi_Request2Connection(void* mutexInfo, + NHTTPRequestInfo* request); +void NHTTPi_destroyRequestObject(void* mutexInfo, NHTTPRequestInfo* request); +void NHTTPi_CompleteCallback(void* mutexInfo, NHTTPConnectionInfo* connection); +NHTTPHeader* NHTTPi_getHdrFromList(NHTTPHeader** list); + +void NHTTPi_InitListInfo(NHTTPListInfo* info) +{ + info->reqQueue = NULL; + info->nextRequestId = 0; +} + +s32 NHTTPi_setReqQueue(NHTTPListInfo* info, NHTTPRequestInfo* request) +{ + s32 requestId = -1; + NHTTPReqQueue* queue = NHTTPi_alloc(sizeof(NHTTPReqQueue), 4); + + if (queue != NULL) + { + if (info->reqQueue != NULL) + { + queue->next = info->reqQueue->next; + queue->prev = info->reqQueue; + info->reqQueue->next->prev = queue; + info->reqQueue->next = queue; + } + else + { + queue->next = queue; + queue->prev = queue; + info->reqQueue = queue; + } + + queue->requestId = info->nextRequestId++; + queue->request = request; + queue->_unk10 = -1; + requestId = queue->requestId; + + if (info->nextRequestId < 0) + { + info->nextRequestId = 0; + } + } + + return requestId; +} + +BOOL NHTTPi_freeReqQueue(NHTTPListInfo* info, void* mutexInfo, s32 requestId) +{ + NHTTPReqQueue* current; + NHTTPReqQueue* queue = info->reqQueue; + NHTTPReqQueue* found = NULL; + BOOL result = FALSE; + + if (queue != NULL) + { + if (queue->requestId == requestId) + { + found = queue; + } + else + { + current = queue->prev; + + while (current != queue) + { + if (current->requestId == requestId) + { + found = current; + break; + } + current = current->prev; + } + } + } + + if (found != NULL) + { + NHTTPConnectionInfo* connection; + + if (queue != queue->next) + { + found->next->prev = found->prev; + found->prev->next = found->next; + + if (info->reqQueue == found) + { + info->reqQueue = found->prev; + } + } + else + { + info->reqQueue = NULL; + } + + connection = NHTTPi_Request2Connection(mutexInfo, found->request); + NHTTPi_destroyRequestObject(mutexInfo, found->request); + NHTTPi_free(found); + + if (connection != NULL) + { + connection->state = 8; + NHTTPi_CompleteCallback(mutexInfo, connection); + } + result = TRUE; + } + + return result; +} + +void NHTTPi_allFreeReqQueue(NHTTPListInfo* info, void* mutexInfo) +{ + while (info->reqQueue != NULL) + { + NHTTPi_freeReqQueue(info, mutexInfo, info->reqQueue->requestId); + } +} + +NHTTPReqQueue* NHTTPi_getReqFromReqQueue(NHTTPReqQueue** queue) +{ + return (NHTTPReqQueue*)NHTTPi_getHdrFromList((NHTTPHeader**)queue); +} diff --git a/libs/RevoEX/src/nhttp/NHTTP_os_RVL.c b/libs/RevoEX/src/nhttp/NHTTP_os_RVL.c new file mode 100644 index 00000000..69c96274 --- /dev/null +++ b/libs/RevoEX/src/nhttp/NHTTP_os_RVL.c @@ -0,0 +1,120 @@ +#include + +#include +#include + +typedef struct NHTTPMutexInfo +{ + OSMutex mutex; + BOOL initialized; +} NHTTPMutexInfo; + +typedef struct NHTTPBgnEndInfo +{ + NCDIpConfig ipConfig; + NHTTPAlloc alloc; + NHTTPFree free; + BOOL started; + s32 socket; + s32 sslError; + NHTTPErr error; + u32 _unk7DC; + void* threadStack; + u32 _unk7E4; +} NHTTPBgnEndInfo; + +typedef struct NHTTPThreadInfo +{ + OSMessageQueue messageQueue; + OSMessage messages[3]; + OSThread thread; + BOOL isCreateCommThreadMessageQueue; + u8 _unk34C[0x14]; + char commBuf[0x100]; +} NHTTPThreadInfo; + +BOOL NHTTPi_IsCreateCommThreadMessageQueue(NHTTPThreadInfo* info); +void NHTTPi_IsCreateCommThreadMessageQueueOn(NHTTPThreadInfo* info); +void NHTTPi_CommThreadProcMain(void* argument); + +void NHTTPi_InitMutexInfo(NHTTPMutexInfo* info) +{ + info->initialized = FALSE; +} + +void NHTTPi_initLockReqList(NHTTPMutexInfo* info) +{ + if (!info->initialized) + { + OSInitMutex(&info->mutex); + info->initialized = TRUE; + } +} + +void NHTTPi_exitLockReqList(void) +{ +} + +void NHTTPi_lockReqList(NHTTPMutexInfo* info) +{ + OSLockMutex(&info->mutex); +} + +void NHTTPi_unlockReqList(NHTTPMutexInfo* info) +{ + OSUnlockMutex(&info->mutex); +} + +void* NHTTPi_CommThreadProc(void* argument); + +BOOL NHTTPi_createCommThread(NHTTPThreadInfo* info, s32 priority, void* stack) +{ + if (!NHTTPi_IsCreateCommThreadMessageQueue(info)) + { + OSInitMessageQueue(&info->messageQueue, info->messages, 3); + NHTTPi_IsCreateCommThreadMessageQueueOn(info); + } + + OSCreateThread(&info->thread, NHTTPi_CommThreadProc, NULL, (u8*)stack + 0x2000, 0x2000, priority, 0); + OSResumeThread(&info->thread); + return TRUE; +} + +void NHTTPi_destroyCommThread(NHTTPThreadInfo* info, NHTTPBgnEndInfo* bgnEndInfo) +{ + bgnEndInfo->_unk7DC = 1; + OSSendMessage(&info->messageQueue, NULL, 0); + OSJoinThread(&info->thread, NULL); +} + +void NHTTPi_idleCommThread(NHTTPThreadInfo* info) +{ + OSMessage message; + + OSReceiveMessage(&info->messageQueue, &message, OS_MESSAGE_BLOCK); +} + +void NHTTPi_kickCommThread(NHTTPThreadInfo* info) +{ + OSSendMessage(&info->messageQueue, NULL, 0); +} + +void NHTTPi_CheckCurrentThread(NHTTPThreadInfo* info, BOOL notCommThread) +{ + OSThread* current = OSGetCurrentThread(); + OSThread* commThread = &info->thread; + + if (current != NULL + && ((!notCommThread && current != commThread) + || (notCommThread && current == commThread))) + { + OSReport("%s:illegal thread\n", __FUNCTION__); + OSPanic(__FILE__, 223, "halt\n"); + } +} + +void* NHTTPi_CommThreadProc(void* argument) +{ + NHTTPi_CommThreadProcMain(argument); + return NULL; +} diff --git a/libs/RevoEX/src/nhttp/NHTTP_request.c b/libs/RevoEX/src/nhttp/NHTTP_request.c new file mode 100644 index 00000000..cba4b038 --- /dev/null +++ b/libs/RevoEX/src/nhttp/NHTTP_request.c @@ -0,0 +1,487 @@ +#include + +const char NHTTPi_strMultipartBound[] = STR_POSTBOUND; + +void* NHTTPi_alloc(u32 size, int align); +void NHTTPi_free(void* ptr); +void NHTTPi_SetError(NHTTPBgnEndInfo* info, NHTTPErr error); +void* NHTTPi_memclr(void* destination, u32 size); +s32 NHTTPi_strlen(const char* string); +void* NHTTPi_memcpy(void* destination, const void* source, u32 size); +s32 NHTTPi_strnicmp(const char* left, const char* right, s32 size); +s32 NHTTPi_strToHex(const char* string, s32 length); +s32 NHTTPi_strtonum(const char* string, s32 length); + +NHTTPBgnEndInfo* NHTTPi_GetBgnEndInfoP(void* systemInfo); +NHTTPListInfo* NHTTPi_GetListInfoP(void* systemInfo); +NHTTPReqInfo* NHTTPi_GetReqInfoP(void* systemInfo); +void* NHTTPi_GetMutexInfoP(void* systemInfo); +void* NHTTPi_GetThreadInfoP(void* systemInfo); +NHTTPConnectionInfo* NHTTPi_Request2Connection(void* mutexInfo, + NHTTPRequestInfo* request); +void NHTTPi_lockReqList(void* mutexInfo); +void NHTTPi_unlockReqList(void* mutexInfo); +s32 NHTTPi_setReqQueue(NHTTPListInfo* listInfo, NHTTPRequestInfo* request); +void NHTTPi_kickCommThread(void* threadInfo); +void NHTTPi_SocCancel(void* mutexInfo, NHTTPRequestInfo* request, s32 socket); +BOOL NHTTPi_freeReqQueue(NHTTPListInfo* listInfo, void* mutexInfo, + s32 requestId); +void NHTTPi_allFreeReqQueue(NHTTPListInfo* listInfo, void* mutexInfo); + +void NHTTPi_InitRequestInfo(NHTTPReqInfo* info) +{ + info->reqQueue = NULL; +} + +NHTTPRequestInfo* NHTTP_CreateRequest(NHTTPBgnEndInfo* bgnEndInfo_p, + const char* url_p, s32 method, void* buf_p, u32 len, void* param_p, + NHTTPResponseCallback bufFull, NHTTPResponseCleanup freeBuf) +{ + int i; + int suflen, urllen, prelen; + int nhostenc, deccount; + int declen, hostend; + int port; + int decode_urllen; + + char a_url[LEN_URLBUF]; + char* prefix_p; + NHTTPRequestInfo* req_p = NULL; + + if (method >= 3 || method < 0) + { + NHTTPi_SetError(bgnEndInfo_p, NHTTP_ERROR_UNKNOWN); + goto errend; + } + + req_p = NHTTPi_alloc(sizeof(NHTTPRequestInfo), 4); + if (!req_p) + { + NHTTPi_SetError(bgnEndInfo_p, NHTTP_ERROR_ALLOC); + goto errend; + } + NHTTPi_memclr(req_p, sizeof(NHTTPRequestInfo)); + + req_p->response = NHTTPi_alloc(sizeof(NHTTPResponseInfo), 4); + if (!req_p->response) + { + NHTTPi_SetError(bgnEndInfo_p, NHTTP_ERROR_ALLOC); + goto errend; + } + NHTTPi_memclr(req_p->response, sizeof(NHTTPResponseInfo)); + req_p->response->recvBuf_p = buf_p; + req_p->response->recvBufLen = len; + req_p->response->bufFull = bufFull; + req_p->response->freeBuf = freeBuf; + + urllen = NHTTPi_strlen(url_p); + if (urllen <= 7) + { + NHTTPi_SetError(bgnEndInfo_p, NHTTP_ERROR_DNS); + goto errend; + } + + NHTTPi_memclr(a_url, urllen); + NHTTPi_memcpy(a_url, url_p, urllen); + + req_p->port = 80; + suflen = 7; + if (NHTTPi_strnicmp(a_url, "http://", 7) != 0) + { + if (NHTTPi_strnicmp(a_url, "https://", 8) != 0) + { + NHTTPi_SetError(bgnEndInfo_p, NHTTP_ERROR_DNS); + goto errend; + } + req_p->secure = TRUE; + req_p->port = 443; + suflen = 8; + } + + prefix_p = a_url + suflen; + prelen = urllen - suflen; + if (prelen <= 0) + { + NHTTPi_SetError(bgnEndInfo_p, NHTTP_ERROR_DNS); + goto errend; + } + + for (i = 0, nhostenc = 0, deccount = 0; + (i < prelen) && (prefix_p[i] != '/'); i++) + { + if (deccount == 2) + { + deccount--; + } + else if (deccount == 1) + { + s8 c = (s8)NHTTPi_strToHex(&prefix_p[i - 1], 2); + deccount--; + if (c < 0) + { + NHTTPi_SetError(bgnEndInfo_p, NHTTP_ERROR_DNS); + goto errend; + } + if (c == '/') + { + nhostenc--; + break; + } + } + else if (prefix_p[i] == '%') + { + deccount = 2; + nhostenc++; + } + } + + if (deccount) + { + NHTTPi_SetError(bgnEndInfo_p, NHTTP_ERROR_DNS); + goto errend; + } + + decode_urllen = suflen + prelen - nhostenc * 2 + 1; + req_p->url = NHTTPi_alloc(decode_urllen, 4); + if (!req_p->url) + { + NHTTPi_SetError(bgnEndInfo_p, NHTTP_ERROR_ALLOC); + goto errend; + } + NHTTPi_memclr(req_p->url, decode_urllen); + NHTTPi_memcpy(req_p->url, a_url, suflen); + + for (i = 0, declen = 0, deccount = 0, hostend = FALSE; + i < prelen; i++) + { + if (deccount == 2) + { + deccount--; + } + else if (deccount == 1) + { + char c = (char)NHTTPi_strToHex(&prefix_p[i - 1], 2); + deccount--; + req_p->url[suflen + declen - 1] = c; + if (c == '/') + { + hostend = TRUE; + } + } + else + { + if (prefix_p[i] == '/') + { + hostend = TRUE; + } + if (!hostend & (prefix_p[i] == '%')) + { + deccount = 2; + } + else + { + req_p->url[suflen + declen] = prefix_p[i]; + } + declen++; + } + } + req_p->url[suflen + declen] = 0; + + prefix_p = &req_p->url[suflen]; + prelen = declen; + + for (i = 0; i < prelen; i++) + { + if ((prefix_p[i] == '/') || (prefix_p[i] == ':')) + { + req_p->hostEnd = i + suflen; + break; + } + } + + if (i == prelen) + { + req_p->pathStart = req_p->hostEnd = i + suflen; + } + else if (prefix_p[i] == '/') + { + req_p->pathStart = req_p->hostEnd; + } + else if (prefix_p[i] == ':') + { + for (; i < prelen; i++) + { + if (prefix_p[i] == '/') + { + req_p->pathStart = i + suflen; + break; + } + } + + if (i == prelen) + { + req_p->pathStart = i + suflen; + } + else + { + port = NHTTPi_strtonum(&req_p->url[req_p->hostEnd + 1], + (int)(req_p->pathStart - (req_p->hostEnd + 1))); + if (port < 0) + { + port = req_p->port; + } + else if (port > 65535) + { + NHTTPi_SetError(bgnEndInfo_p, NHTTP_ERROR_DNS); + goto errend; + } + req_p->port = (u16)port; + } + } + + { + u32 a_hostnameLen = (u32)(req_p->hostEnd - (req_p->secure ? 8 : 7)); + req_p->host = NHTTPi_alloc(a_hostnameLen + 1, 4); + if (!req_p->host) + { + NHTTPi_SetError(bgnEndInfo_p, NHTTP_ERROR_ALLOC); + goto errend; + } + NHTTPi_memclr(req_p->host, (int)(a_hostnameLen + 1)); + NHTTPi_memcpy(req_p->host, + req_p->url + (req_p->secure ? 8 : 7), (int)a_hostnameLen); + } + + NHTTPi_memcpy(req_p->multipartBoundary, NHTTPi_strMultipartBound, + sizeof(req_p->multipartBoundary)); + req_p->method = method; + req_p->sslId = 0; + req_p->clientCertData = NULL; + req_p->clientCertSize = 0; + req_p->privateKeyData = NULL; + req_p->privateKeySize = 0; + req_p->rootCAData = NULL; + req_p->rootCASize = 0; + req_p->clientCertDefault = FALSE; + req_p->verifyOption = 0; + req_p->_unkD4 = NULL; + req_p->response->param_p = param_p; + req_p->proxyEnabled = FALSE; + req_p->recvBufferSize = 0; + return req_p; + +errend: + if (req_p) + { + if (req_p->url) + { + NHTTPi_free(req_p->url); + } + if (req_p->host) + { + NHTTPi_free(req_p->host); + } + if (req_p->response) + { + NHTTPi_free(req_p->response); + } + NHTTPi_free(req_p); + } + return NULL; +} + +void NHTTP_DestroyRequest(void* systemInfo, NHTTPRequestInfo* request) +{ + NHTTPConnectionInfo* connection; + NHTTPHeader* header; + NHTTPHeader* next; + NHTTPHeader* post; + NHTTPHeader* nextPost; + void* mutexInfo = NHTTPi_GetMutexInfoP(systemInfo); + + connection = NHTTPi_Request2Connection(mutexInfo, request); + if (connection != NULL) + { + connection->response = NULL; + } + NHTTPi_free(request->response); + + connection = NHTTPi_Request2Connection(mutexInfo, request); + if (connection != NULL) + { + connection->request = NULL; + } + + header = request->headers; + while (header != NULL) + { + if (header != header->next) + { + next = header->next->next; + NHTTPi_free(header->next); + header->next = next; + } + else + { + NHTTPi_free(header); + header = NULL; + } + } + + post = request->postData; + while (post != NULL) + { + if (post != post->next) + { + nextPost = post->next->next; + NHTTPi_free(post->next); + post->next = nextPost; + } + else + { + NHTTPi_free(post); + post = NULL; + } + } + + NHTTPi_free(request->url); + NHTTPi_free(request->host); + NHTTPi_free(request); +} + +BOOL NHTTPi_destroyRequestObject(void* mutexInfo, NHTTPRequestInfo* request) +{ + NHTTPConnectionInfo* connection; + NHTTPHeader* header; + NHTTPHeader* next; + NHTTPHeader* post; + NHTTPHeader* nextPost; + + connection = NHTTPi_Request2Connection(mutexInfo, request); + if (connection != NULL) + { + connection->request = NULL; + } + + header = request->headers; + while (header != NULL) + { + if (header != header->next) + { + next = header->next->next; + NHTTPi_free(header->next); + header->next = next; + } + else + { + NHTTPi_free(header); + header = NULL; + } + } + + post = request->postData; + while (post != NULL) + { + if (post != post->next) + { + nextPost = post->next->next; + NHTTPi_free(post->next); + post->next = nextPost; + } + else + { + NHTTPi_free(post); + post = NULL; + } + } + + NHTTPi_free(request->url); + NHTTPi_free(request->host); + NHTTPi_free(request); + return TRUE; +} + +s32 NHTTP_SendRequestAsync(void* systemInfo, NHTTPRequestInfo* request) +{ + NHTTPBgnEndInfo* info = NHTTPi_GetBgnEndInfoP(systemInfo); + void* threadInfo = NHTTPi_GetThreadInfoP(systemInfo); + void* mutexInfo = NHTTPi_GetMutexInfoP(systemInfo); + s32 requestId; + + if (request->state != 0) + { + NHTTPi_SetError(info, NHTTP_ERROR_UNKNOWN); + return -1; + } + + NHTTPi_lockReqList(mutexInfo); + requestId = NHTTPi_setReqQueue(NHTTPi_GetListInfoP(systemInfo), request); + if (requestId >= 0) + { + request->state = 1; + NHTTPi_kickCommThread(threadInfo); + } + else + { + NHTTPi_SetError(info, NHTTP_ERROR_ALLOC); + } + NHTTPi_unlockReqList(mutexInfo); + return requestId; +} + +BOOL NHTTP_CancelRequestAsync(void* sysInfo_p, s32 id) +{ + BOOL rc = FALSE; + NHTTPReqInfo* reqInfo_p = NHTTPi_GetReqInfoP(sysInfo_p); + void* mutexInfo_p = NHTTPi_GetMutexInfoP(sysInfo_p); + volatile NHTTPReqQueue* reqCurrent_p = reqInfo_p->reqQueue; + + NHTTPi_lockReqList(mutexInfo_p); + + if (reqCurrent_p) + { + if (reqCurrent_p->requestId == id) + { + if (!reqCurrent_p->request->cancel) + { + reqCurrent_p->request->cancel = TRUE; + NHTTPi_SocCancel(mutexInfo_p, reqCurrent_p->request, + reqCurrent_p->_unk10); + rc = TRUE; + } + } + } + + if (!rc) + { + NHTTPListInfo* listInfo_p = NHTTPi_GetListInfoP(sysInfo_p); + rc = NHTTPi_freeReqQueue(listInfo_p, mutexInfo_p, id); + } + + NHTTPi_unlockReqList(mutexInfo_p); + + return rc; +} + +void NHTTPi_cancelAllRequests(void* sysInfo_p) +{ + NHTTPReqInfo* reqInfo_p = NHTTPi_GetReqInfoP(sysInfo_p); + NHTTPListInfo* listInfo_p = NHTTPi_GetListInfoP(sysInfo_p); + void* mutexInfo_p = NHTTPi_GetMutexInfoP(sysInfo_p); + volatile NHTTPReqQueue* reqCurrent_p = reqInfo_p->reqQueue; + + NHTTPi_lockReqList(mutexInfo_p); + + if (reqCurrent_p) + { + if (!reqCurrent_p->request->cancel) + { + reqCurrent_p->request->cancel = TRUE; + NHTTPi_SocCancel(mutexInfo_p, reqCurrent_p->request, + reqCurrent_p->_unk10); + } + } + + NHTTPi_allFreeReqQueue(listInfo_p, mutexInfo_p); + NHTTPi_unlockReqList(mutexInfo_p); +} diff --git a/libs/RevoEX/src/nhttp/NHTTP_response.c b/libs/RevoEX/src/nhttp/NHTTP_response.c new file mode 100644 index 00000000..de023bc0 --- /dev/null +++ b/libs/RevoEX/src/nhttp/NHTTP_response.c @@ -0,0 +1,202 @@ +#include + +void* NHTTPi_alloc(u32 size, int align); +void NHTTPi_free(void* ptr); +void NHTTPi_SetError(NHTTPBgnEndInfo* info, NHTTPErr error); +s32 NHTTPi_loadFromHdrRecvBuf(NHTTPResponseInfo* res_p, char* dst, s32 pos, + s32 size); +s32 NHTTPi_strcmp(const char* lhs, const char* rhs); +s32 NHTTPi_getHeaderValue(const NHTTPResponseInfo* res_p, const char* label_p, + s32* pos_p); +NHTTPConnectionInfo* NHTTPi_Response2Connection(void* mutexInfo_p, + NHTTPResponseInfo* res_p); +s32 NHTTPi_findNextLineHdrRecvBuf(const NHTTPResponseInfo* res_p, s32 pos, + s32 limit, s32* colon_pos_p, s32* return_code_size_p); +s32 NHTTPi_compareTokenN_HdrRecvBuf(const NHTTPResponseInfo* res_p, s32 pos, + s32 limit, const char* str_p, s8 extdeli); +s32 NHTTPi_skipSpaceHdrRecvBuf( + const NHTTPResponseInfo* res_p, s32 pos, s32 limit); + +void NHTTP_DestroyResponse(void* mutexInfo_p, NHTTPResponseInfo* res_p) +{ + NHTTPi_HDRBUFLIST* list_p = NULL; + + while (res_p->hdrBufBlock_p) + { + list_p = res_p->hdrBufBlock_p->next_p; + NHTTPi_free(res_p->hdrBufBlock_p); + res_p->hdrBufBlock_p = list_p; + } + + if (res_p->allHeader_p) + { + NHTTPi_free(res_p->allHeader_p); + } + + if (res_p->foundHeader_p) + { + NHTTPi_free(res_p->foundHeader_p); + } + + if (res_p->freeBuf != NULL) + { + res_p->freeBuf(res_p->recvBuf_p, NHTTPi_free, res_p->param_p); + res_p->recvBuf_p = NULL; + res_p->recvBufLen = 0; + } + + { + NHTTPConnectionInfo* connection_p = + NHTTPi_Response2Connection(mutexInfo_p, res_p); + + if (connection_p != NULL) + { + connection_p->response = NULL; + } + } + + NHTTPi_free(res_p); +} + +s32 NHTTPi_getHeaderValue(const NHTTPResponseInfo* res_p, const char* label_p, + s32* pos_p) +{ + s32 linetop, nextlinetop; + s32 labeltop, labelend; + s32 valuetop, valueend; + s32 return_code_size = 0; + + linetop = NHTTPi_findNextLineHdrRecvBuf( + res_p, 12, res_p->headerLen, &labelend, &return_code_size); + + while (linetop > 0) + { + nextlinetop = NHTTPi_findNextLineHdrRecvBuf(res_p, linetop, + res_p->headerLen, &labelend, &return_code_size); + + if (labelend > 0) + { + labeltop = linetop; + + if (NHTTPi_compareTokenN_HdrRecvBuf( + res_p, labeltop, labelend, label_p, 0) + == 0) + { + if (labelend + 1 < res_p->headerLen) + { + valueend = NHTTPi_findNextLineHdrRecvBuf(res_p, + labelend + 1, res_p->headerLen, NULL, + &return_code_size); + if (valueend <= 0) + { + valueend = res_p->headerLen; + } + else + { + if (valueend < return_code_size) + { + return -1; + } + valueend -= return_code_size; + } + + valuetop = NHTTPi_skipSpaceHdrRecvBuf( + res_p, labelend + 1, valueend); + if (valuetop < 0) + { + valuetop = valueend; + } + + *pos_p = valuetop; + return valueend - valuetop; + } + else + { + return 0; + } + } + } + + linetop = nextlinetop; + } + + return -1; +} +s32 NHTTP_GetHeaderField(NHTTPResponseInfo* res_p, const char* label_p, + const char** value_p) +{ + s32 pos; + s32 length; + + if (res_p->isHeaderParse == 0) + { + return -1; + } + + if (res_p->foundHeader_p != NULL) + { + NHTTPi_free(res_p->foundHeader_p); + res_p->foundHeader_p = NULL; + } + + length = NHTTPi_getHeaderValue(res_p, label_p, &pos); + if (length >= 0) + { + res_p->foundHeader_p = NHTTPi_alloc(length + 1, 4); + if (res_p->foundHeader_p == NULL) + { + return -1; + } + res_p->foundHeader_p[length] = 0; + NHTTPi_loadFromHdrRecvBuf(res_p, res_p->foundHeader_p, pos, length); + *value_p = res_p->foundHeader_p; + return length; + } + + if (NHTTPi_strcmp("HTTPSTATUSCODE", label_p) == 0) + { + res_p->foundHeader_p = NHTTPi_alloc(4, 4); + if (res_p->foundHeader_p == NULL) + { + return -1; + } + res_p->foundHeader_p[3] = 0; + NHTTPi_loadFromHdrRecvBuf(res_p, res_p->foundHeader_p, 9, 3); + *value_p = res_p->foundHeader_p; + return 3; + } + + return -1; +} + +s32 NHTTP_GetHeaderAll(void* bgnEndInfo_p, NHTTPResponseInfo* res_p, + const char** header_p) +{ + if (res_p->isHeaderParse == 0 || res_p->headerLen == 0) + { + return -1; + } + + if (res_p->headerLen < NHTTP_HDRRECVBUF_INILEN) + { + *header_p = (const char*)res_p->hdrBufFirst; + } + else + { + if (res_p->allHeader_p == NULL) + { + res_p->allHeader_p = NHTTPi_alloc(res_p->headerLen, 4); + if (res_p->allHeader_p == NULL) + { + NHTTPi_SetError(bgnEndInfo_p, NHTTP_ERROR_ALLOC); + return -1; + } + NHTTPi_loadFromHdrRecvBuf(res_p, res_p->allHeader_p, 0, + res_p->headerLen); + } + *header_p = res_p->allHeader_p; + } + + return res_p->headerLen; +} + diff --git a/libs/RevoEX/src/nhttp/d_nhttp.c b/libs/RevoEX/src/nhttp/d_nhttp.c new file mode 100644 index 00000000..63620488 --- /dev/null +++ b/libs/RevoEX/src/nhttp/d_nhttp.c @@ -0,0 +1,673 @@ +#include + +#include + +#include +#include + + +struct NHTTPBgnEndInfo +{ + NCDIpConfig ipConfig; +}; + +typedef s32 (*NHTTPPostSend)(const char* label, char** value_p, + u32* length_p, s32 offset, void* userParam); + +void* NHTTPi_GetSystemInfoP(void); +NHTTPBgnEndInfo* NHTTPi_GetBgnEndInfoP(void* systemInfo); +void* NHTTPi_GetMutexInfoP(void* systemInfo); +BOOL NHTTPi_Startup(void* systemInfo, NHTTPAlloc alloc, NHTTPFree free, + u32 priority); +void NHTTPi_CleanupAsync(void* systemInfo, NHTTPCleanupCallback callback); +s32 NHTTPi_GetError(NHTTPBgnEndInfo* info); +void* NHTTPi_alloc(u32 size, int align); +void NHTTPi_free(void* buffer); +s32 NHTTPi_strlen(const char* string); +void* NHTTPi_memcpy(void* destination, const void* source, u32 size); +void* NHTTPi_memclr(void* destination, u32 size); +s32 NHTTPi_Base64Encode(char* destination, const char* source); +NHTTPConnectionInfo* NHTTPCreateConnection(const char* url, s32 method, + void* buffer, u32 bufferSize, NHTTPConnectionCallback callback, + void* userParam); +s32 NHTTPStartConnection(NHTTPConnectionInfo* connection); +s32 NHTTPGetBodyBuffer(NHTTPConnectionInfo* connection, void** buffer, + u32* bufferSize); +void* NHTTPGetUserParam(NHTTPConnectionInfo* connection); +s32 NHTTPGetConnectionError(NHTTPConnectionInfo* connection); +NHTTPConnectionInfo* NHTTPi_GetConnection(void* mutexInfo, + NHTTPConnectionInfo* connection); +NHTTPRequestInfo* NHTTPi_Connection2Request(void* mutexInfo, + NHTTPConnectionInfo* connection); +NHTTPResponseInfo* NHTTPi_Connection2Response(void* mutexInfo, + NHTTPConnectionInfo* connection); +NHTTPConnectionInfo* NHTTPi_Request2Connection(void* mutexInfo, + NHTTPRequestInfo* request); +NHTTPConnectionInfo* NHTTPi_Response2Connection(void* mutexInfo, + NHTTPResponseInfo* response); +NHTTPRequestInfo* NHTTPi_GetRequest(void* mutexInfo, + NHTTPRequestInfo* request); +NHTTPResponseInfo* NHTTPi_GetResponse(void* mutexInfo, + NHTTPResponseInfo* response); +s32 NHTTPi_OmitConnectionList(void* mutexInfo, + NHTTPConnectionInfo* connection); +u32 NHTTPi_GetVirtualContentLength(NHTTPConnectionInfo* connection); +BOOL NHTTP_AddHeaderField(NHTTPRequestInfo* request, NHTTPBgnEndInfo* info, + const char* name, const char* value); +BOOL NHTTP_AddPostDataAscii(NHTTPRequestInfo* request, NHTTPBgnEndInfo* info, + const char* name, const char* value); +BOOL NHTTP_CancelRequestAsync(void* systemInfo, s32 requestId); +void NHTTP_DestroyRequest(void* systemInfo, NHTTPRequestInfo* request); +void NHTTP_DestroyResponse(void* mutexInfo, NHTTPResponseInfo* response); + +static s32 nhttpRegistered = 0; + +const char* __NHTTPVersion = "<< RVL_SDK - NHTTP \trelease build: Jun 27 2007 16:27:59 (0x4199_60726) >>"; +char __NHTTPUnofficialVersion[] = "<< RVL_SDK - NHTTP \trelease build: Jun 27 2007 16:27:59 (0x4199_60726) UNOFFICIAL >>"; + +s32 NHTTPStartup(NHTTPAlloc alloc, NHTTPFree free, u32 priority) +{ + void* system = NHTTPi_GetSystemInfoP(); + if (nhttpRegistered == 0) + { + OSRegisterVersion(__NHTTPVersion); + nhttpRegistered = TRUE; + } + return NHTTPi_Startup(system, alloc, free, priority) ? 0 : -1; +} + +void NHTTPCleanupAsync(NHTTPCleanupCallback callback) +{ + NHTTPi_CleanupAsync(NHTTPi_GetSystemInfoP(), callback); +} + +s32 NHTTPGetError(void) +{ + return NHTTPi_GetError(NHTTPi_GetSystemInfoP()); +} + +static s32 NHTTPi_PostSendCallbackWrap(void* mutexInfo_p, + NHTTPConnectionInfo* connection_p, void* arg_p) +{ + if (connection_p != NULL) + { + NHTTPRequestInfo* req_p = + NHTTPi_Connection2Request(mutexInfo_p, connection_p); + if (req_p != NULL) + { + NHTTPPostSend postSend = (NHTTPPostSend)req_p->_unk250; + if (postSend != NULL) + { + NHTTPPostSendArg* postSendArg_p = arg_p; + return postSend(postSendArg_p->label, + &postSendArg_p->buf, &postSendArg_p->size, + postSendArg_p->offset, + NHTTPGetUserParam(connection_p)); + } + } + } + return -1; +} + +static s32 NHTTPi_BufFullCallbackWrap(void* mutexInfo_p, + NHTTPConnectionInfo* connection_p, void* arg_p) +{ + if (connection_p != NULL) + { + NHTTPResponseInfo* res_p = + NHTTPi_Connection2Response(mutexInfo_p, connection_p); + if (res_p != NULL) + { + NHTTPResponseCallback bufFull = res_p->bufFull; + if (bufFull != NULL) + { + NHTTPBodyBufArg* bodyBufArg_p = arg_p; + char* oldBuf_p = bodyBufArg_p->buf; + u32 contentLength = + NHTTPi_GetVirtualContentLength(connection_p); + bodyBufArg_p->buf = bufFull((void**)&oldBuf_p, + &bodyBufArg_p->size, contentLength, NHTTPi_alloc, + NHTTPi_free, NHTTPGetUserParam(connection_p)); + if (bodyBufArg_p->buf != NULL && oldBuf_p != NULL) + { + bodyBufArg_p->offset = 0; + } + } + } + } + return 0; +} + +static s32 NHTTPi_CompleteCallbackWrap(void* mutexInfo_p, + NHTTPConnectionInfo* connection_p) +{ + if (connection_p != NULL) + { + NHTTPReqCallback reqCallback = connection_p->requestCallback; + if (reqCallback != NULL) + { + NHTTPResponseInfo* res_p = + NHTTPi_Connection2Response(mutexInfo_p, connection_p); + if (res_p != NULL) + { + NHTTPErr result = NHTTPGetConnectionError(connection_p); + reqCallback( + result, res_p, NHTTPGetUserParam(connection_p)); + } + } + } + return 0; +} + +s32 NHTTPi_TemplateConnectionCallback(NHTTPConnectionInfo* handle, + NHTTPConnectionEvent event, void* arg_p) +{ + void* sysInfo_p = NHTTPi_GetSystemInfoP(); + void* mutexInfo_p = NHTTPi_GetMutexInfoP(sysInfo_p); + NHTTPConnectionInfo* connection_p = + NHTTPi_GetConnection(mutexInfo_p, handle); + s32 ret = 0; + + switch (event) + { + case NHTTP_EVENT_POST_SEND: + ret = NHTTPi_PostSendCallbackWrap( + mutexInfo_p, connection_p, arg_p); + break; + case NHTTP_EVENT_BODY_RECV_FULL: + ret = NHTTPi_BufFullCallbackWrap( + mutexInfo_p, connection_p, arg_p); + break; + case NHTTP_EVENT_BODY_RECV_DONE: + break; + case NHTTP_EVENT_COMPLETE: + ret = NHTTPi_CompleteCallbackWrap(mutexInfo_p, connection_p); + break; + default: + break; + } + return ret; +} + +NHTTPRequest* NHTTPCreateRequest(const char* url, NHTTPReqMethod method, + void* buffer, u32 bufferSize, NHTTPReqCallback callback, void* userParam) +{ + return NHTTPCreateRequestEx(url, method, buffer, bufferSize, callback, userParam, NULL, NULL); +} + +NHTTPRequest* NHTTPCreateRequestEx(const char* url, NHTTPReqMethod method, + void* buffer, u32 bufferSize, NHTTPReqCallback callback, void* userParam, + NHTTPResponseCallback responseCallback, NHTTPResponseCleanup cleanup) +{ + void* systemInfo; + void* mutexInfo; + NHTTPConnectionInfo* connection; + NHTTPRequestInfo* request; + + connection = NHTTPCreateConnection(url, method, buffer, bufferSize, NHTTPi_TemplateConnectionCallback, userParam); + request = NULL; + if (connection != NULL) + { + systemInfo = NHTTPi_GetSystemInfoP(); + mutexInfo = NHTTPi_GetMutexInfoP(systemInfo); + connection = NHTTPi_GetConnection(mutexInfo, connection); + request = NHTTPi_Connection2Request(mutexInfo, connection); + if (request != NULL) + { + if (request->response != NULL) + { + connection->requestCallback = callback; + request->response->bufFull = responseCallback; + request->response->freeBuf = cleanup; + return request; + } + else + { + NHTTP_DestroyRequest(systemInfo, request); + NHTTPi_OmitConnectionList(mutexInfo, connection); + NHTTPi_free(connection); + request = NULL; + } + } + } + return request; +} + +s32 NHTTPDeleteRequest(NHTTPRequest* request) +{ + NHTTPConnectionInfo* connection = NHTTPi_Request2Connection( + NHTTPi_GetMutexInfoP(NHTTPi_GetSystemInfoP()), request); + if (connection != NULL) + { + NHTTPDeleteConnection(connection); + } +} + +s32 NHTTPAddHeaderField(NHTTPRequest* handle, const char* name, + const char* value) +{ + void* systemInfo; + NHTTPRequestInfo* request; + void* bgnEndInfo; + + systemInfo = NHTTPi_GetSystemInfoP(); + request = NHTTPi_GetRequest(NHTTPi_GetMutexInfoP(systemInfo), handle); + bgnEndInfo = NHTTPi_GetBgnEndInfoP(systemInfo); + if (request == NULL) + { + return -1; + } + if (request->state != 0) + { + static char name[] = "NHTTPAddHeaderField"; + printf("%s can be called before NHTTPStartConnection()\n", name); + return -1; + } + return NHTTP_AddHeaderField(request, bgnEndInfo, name, value) ? 0 : -1; +} + +s32 NHTTPAddPostDataAscii(NHTTPRequest* handle, const char* name, + const char* value) +{ + NHTTPRequestInfo* request; + void* bgnEndInfo; + + bgnEndInfo = NHTTPi_GetBgnEndInfoP(NHTTPi_GetSystemInfoP()); + request = NHTTPi_GetRequest( + NHTTPi_GetMutexInfoP(NHTTPi_GetSystemInfoP()), handle); + if (request == NULL) + { + return -1; + } + if (request->state != 0) + { + printf("%s can be called before NHTTPStartConnection()\n", + "NHTTPAddPostDataAscii"); + return -1; + } + return NHTTP_AddPostDataAscii(request, bgnEndInfo, name, value) + ? 0 + : -1; +} + +s32 NHTTPAddPostDataBinary(NHTTPRequest* handle, const char* name, + const char* value) +{ + NHTTPRequestInfo* request; + void* bgnEndInfo; + + bgnEndInfo = NHTTPi_GetBgnEndInfoP(NHTTPi_GetSystemInfoP()); + request = NHTTPi_GetRequest( + NHTTPi_GetMutexInfoP(NHTTPi_GetSystemInfoP()), handle); + if (request == NULL) + { + return -1; + } + if (request->state != 0) + { + printf("%s can be called before NHTTPStartConnection()\n", + "NHTTPAddPostDataBinary"); + return -1; + } + return NHTTP_AddPostDataAscii(request, bgnEndInfo, name, value) + ? 0 + : -1; +} + +s32 NHTTPAddPostDataRaw(NHTTPRequest* handle, const void* data, + u32 size, const char* label) +{ + NHTTPRequestInfo* request; + + request = NHTTPi_GetRequest( + NHTTPi_GetMutexInfoP(NHTTPi_GetSystemInfoP()), handle); + if (request == NULL) + { + return -1; + } + if (request->state != 0) + { + printf("%s can be called before NHTTPStartConnection()\n", + "NHTTPAddPostDataRaw"); + return -1; + } + if (request->postData != NULL) + { + printf("already called NHTTPAddPostDataAscii or NHTTPAddPostDataBinary (exclusive fucntion)\n"); + return -1; + } + request->isRawData = TRUE; + request->postBuffer = data; + request->postBufferSize = size; + return 0; +} + +s32 NHTTPSetPostDataEncoding(NHTTPRequest* handle, u32 encodingType) +{ + NHTTPRequestInfo* request; + + request = NHTTPi_GetRequest( + NHTTPi_GetMutexInfoP(NHTTPi_GetSystemInfoP()), handle); + if (request == NULL) + { + return -1; + } + if (request->state != 0) + { + printf("%s can be called before NHTTPStartConnection()\n", + "NHTTPSetPostDataEncoding"); + return -1; + } + request->encodingType = encodingType; + return 0; +} + +NHTTPConnection NHTTPSendRequestAsync(NHTTPRequest* request) +{ + NHTTPConnectionInfo* connection; + s32 result; + + connection = NHTTPi_Request2Connection( + NHTTPi_GetMutexInfoP(NHTTPi_GetSystemInfoP()), request); + if (connection != NULL && NHTTPStartConnection(connection) == 0) + { + result = connection->requestId; + } + else + { + result = -1; + } + return result; +} + +s32 NHTTPCancelRequestAsync(NHTTPConnection connection) +{ + return NHTTP_CancelRequestAsync(NHTTPi_GetSystemInfoP(), connection) + ? 0 + : -1; +} + +s32 NHTTPGetProgress(u32* complete, u32* total) +{ + s32 result; + result = NHTTP_GetProgress(NHTTPi_GetSystemInfoP(), complete, total) + == 0; + return -result; +} + +void NHTTPDestroyResponse(NHTTPResponse* handle) +{ + void* mutexInfo; + NHTTPConnectionInfo* connection; + + mutexInfo = NHTTPi_GetMutexInfoP(NHTTPi_GetSystemInfoP()); + connection = NHTTPi_Response2Connection(mutexInfo, handle); + if (connection != NULL) + { + if (NHTTPi_Connection2Response(mutexInfo, connection) != NULL) + { + NHTTP_DestroyResponse(mutexInfo, connection->response); + } + NHTTPi_OmitConnectionList(mutexInfo, connection); + NHTTPi_free(connection); + } +} + +s32 NHTTPGetHeaderField(NHTTPResponse* response, const char* name, + const char** value) +{ + void* mutexInfo; + NHTTPResponseInfo* res; + + mutexInfo = NHTTPi_GetMutexInfoP(NHTTPi_GetSystemInfoP()); + res = NHTTPi_GetResponse(mutexInfo, response); + if (res == NULL) + { + return -1; + } + return NHTTP_GetHeaderField(res, name, value); +} + +s32 NHTTPGetHeaderAll(NHTTPResponse* response, const char** header) +{ + void* systemInfo; + NHTTPBgnEndInfo* bgnEndInfo; + NHTTPResponseInfo* res; + + systemInfo = NHTTPi_GetSystemInfoP(); + bgnEndInfo = NHTTPi_GetBgnEndInfoP(systemInfo); + res = NHTTPi_GetResponse(NHTTPi_GetMutexInfoP(systemInfo), response); + if (res == NULL) + { + return -1; + } + return NHTTP_GetHeaderAll(bgnEndInfo, res, header); +} + +s32 NHTTPGetBodyAll(NHTTPResponse* response, void** buffer) +{ + NHTTPConnectionInfo* connection; + u32 bufferSize; + s32 result; + + connection = NHTTPi_Response2Connection( + NHTTPi_GetMutexInfoP(NHTTPi_GetSystemInfoP()), response); + if (connection != NULL) + { + bufferSize = 0; + result = NHTTPGetBodyBuffer(connection, buffer, &bufferSize); + } + else + { + result = -1; + } + return result; +} + +s32 NHTTPGetResultCode(NHTTPResponse* handle) +{ + NHTTPResponseInfo* response; + response = NHTTPi_GetResponse( + NHTTPi_GetMutexInfoP(NHTTPi_GetSystemInfoP()), handle); + if (response == NULL) + return -1; + if (response->isHeaderParse != FALSE) + return response->httpStatus; + return -1; +} + +s32 NHTTPSetVerifyOption(NHTTPRequest* handle, u32 option) +{ + NHTTPRequestInfo* request; + s32 result; + + request = NHTTPi_GetRequest( + NHTTPi_GetMutexInfoP(NHTTPi_GetSystemInfoP()), handle); + if (request == NULL) + { + result = -1; + } + else + { + request->verifyOption = option; + result = 0; + } + return result; +} + +s32 NHTTPSetProxy(NHTTPRequest* handle, const char* proxy_p, u16 port, + const char* username_p, const char* password_p) +{ + void* sysInfo_p = NHTTPi_GetSystemInfoP(); + void* mutexInfo_p = NHTTPi_GetMutexInfoP(sysInfo_p); + NHTTPRequestInfo* req_p = NHTTPi_GetRequest(mutexInfo_p, handle); + s32 proxyLen = 0; + + if (req_p == NULL || proxy_p == NULL) + { + return -1; + } + + proxyLen = NHTTPi_strlen(proxy_p); + if (proxyLen > 0x100) + { + printf("proxy-address exceeded 256 characters\n"); + return -1; + } + NHTTPi_memcpy(req_p->proxyServer, proxy_p, proxyLen); + req_p->proxyPort = port; + + if (username_p != NULL && password_p != NULL) + { + s32 username_len; + s32 password_len; + char tmpbuf[0x41]; + + username_len = NHTTPi_strlen(username_p); + password_len = NHTTPi_strlen(password_p); + if (username_len > 0x20) + { + printf("username exceeded 32 characters\n"); + return -1; + } + if (password_len > 0x20) + { + printf("password exceeded 32 characters\n"); + return -1; + } + NHTTPi_memclr(tmpbuf, sizeof(tmpbuf)); + NHTTPi_memcpy(tmpbuf, username_p, username_len); + NHTTPi_memcpy(&(tmpbuf[username_len]), ":", 1); + NHTTPi_memcpy( + &(tmpbuf[(username_len + 1)]), password_p, password_len); + req_p->proxyAuthorizationLength = + NHTTPi_Base64Encode(req_p->proxyAuthorization, tmpbuf); + } + + req_p->proxyEnabled = TRUE; + return 0; +} + +s32 NHTTPSetProxyDefault(NHTTPRequest* handle) +{ + NCDProxyServerProfile* proxy; + void* systemInfo; + NHTTPBgnEndInfo* bgnEndInfo; + NHTTPRequestInfo* request; + const char* username; + const char* password; + s32 result; + + systemInfo = NHTTPi_GetSystemInfoP(); + request = NHTTPi_GetRequest(NHTTPi_GetMutexInfoP(systemInfo), handle); + bgnEndInfo = NHTTPi_GetBgnEndInfoP(systemInfo); + if (request->secure != FALSE) + { + proxy = &bgnEndInfo->ipConfig.proxy.ssl; + } + else + { + proxy = &bgnEndInfo->ipConfig.proxy.http; + } + + if (proxy->mode == 1) + { + username = NULL; + password = NULL; + if (proxy->authType == 1) + { + username = proxy->username; + password = proxy->password; + } + OSReport("Using proxy server %s:%d (%s/%s).\n", proxy->server, proxy->port, username != NULL ? username : "[no-auth]", password != NULL ? password : "[no-auth]"); + result = NHTTPSetProxy(request, proxy->server, proxy->port, username, password); + if (result < 0) + { + OSReport("NHTTPSetProxy failed.(%d)\n", result); + OSPanic("d_nhttp.c", 0x37d, "NHTTPSetProxy"); + } + else + { + return 0; + } + } + else + { + printf("NCD proxy-settings are disabled\n"); + } + return -1; +} + +s32 NHTTPSetRootCADefault(NHTTPRequest* handle) +{ + s32 result; + NHTTPRequestInfo* request; + + request = NHTTPi_GetRequest( + NHTTPi_GetMutexInfoP(NHTTPi_GetSystemInfoP()), handle); + + if (request == NULL) + { + result = -1; + } + else + { + request->builtinRootCA = FALSE; + request->rootCAData = NULL; + request->rootCASize = 0; + result = 0; + } + return result; +} + +s32 NHTTPSetClientCertDefault(NHTTPRequest* handle) +{ + s32 result; + NHTTPRequestInfo* request; + + request = NHTTPi_GetRequest( + NHTTPi_GetMutexInfoP(NHTTPi_GetSystemInfoP()), handle); + + if (request == NULL) + { + result = -1; + } + else + { + request->builtinClientCert = FALSE; + request->clientCertDefault = TRUE; + request->clientCertData = NULL; + request->clientCertSize = 0; + request->privateKeyData = NULL; + request->privateKeySize = 0; + result = 0; + } + return result; +} + +s32 NHTTPDisableVerifyOptionForDebug(NHTTPRequest* handle, u32 option) +{ + NHTTPRequestInfo* request; + + request = NHTTPi_GetRequest( + NHTTPi_GetMutexInfoP(NHTTPi_GetSystemInfoP()), handle); + if (request == NULL) + { + return -1; + } + if (request->state != 0) + { + printf("%s can be called before NHTTPStartConnection()\n", + "NHTTPDisableVerifyOptionForDebug"); + return -1; + } + { + static s32 debugSet; + if (debugSet == 0) + { + debugSet = 1; + } + } + request->verifyOption &= ~option; + return 0; +} diff --git a/libs/RevoEX/src/nhttp/d_nhttp_common.c b/libs/RevoEX/src/nhttp/d_nhttp_common.c new file mode 100644 index 00000000..ad97c610 --- /dev/null +++ b/libs/RevoEX/src/nhttp/d_nhttp_common.c @@ -0,0 +1,421 @@ +#include + +#include + +typedef struct NHTTPSysInfo +{ + u8 bgnEndInfo[0x800]; + NHTTPListInfo listInfo; + NHTTPReqInfo reqInfo; + u8 mutexInfo[0x34]; + u8 threadInfo[0x460]; +} NHTTPSysInfo; + +typedef struct NHTTPStaticResource +{ + BOOL initialized; + OSMutex mutex; + OSCond cond; + u32 _unk24; + u8 _unk28[0x18]; +} NHTTPStaticResource; + +static NHTTPSysInfo sysInfo; +static NHTTPSysInfo* sysInfo_p; +static NHTTPConnectionInfo* sConnectionList; +static NHTTPStaticResource NHTTPiStaticResource; + +void NHTTPi_lockReqList(void* mutexInfo); +void NHTTPi_unlockReqList(void* mutexInfo); +void NHTTPi_InitBgnEndInfo(NHTTPBgnEndInfo* info); +void NHTTPi_InitListInfo(NHTTPListInfo* info); +void NHTTPi_InitRequestInfo(NHTTPReqInfo* info); +void NHTTPi_InitMutexInfo(void* info); +void NHTTPi_InitThreadInfo(void* info); +NHTTPBgnEndInfo* NHTTPi_GetBgnEndInfoP(NHTTPSysInfo* sysInfo_p); +NHTTPListInfo* NHTTPi_GetListInfoP(NHTTPSysInfo* sysInfo_p); +NHTTPReqInfo* NHTTPi_GetReqInfoP(NHTTPSysInfo* sysInfo_p); +void* NHTTPi_GetThreadInfoP(NHTTPSysInfo* sysInfo_p); +void* NHTTPi_GetMutexInfoP(NHTTPSysInfo* sysInfo_p); + +void NHTTPi_WaitForCompletion(NHTTPConnectionInfo* connection) +{ + NHTTPStaticResource* res_p = &NHTTPiStaticResource; + + if (!res_p->initialized) + { + OSInitMutex(&res_p->mutex); + OSInitCond(&res_p->cond); + res_p->initialized = TRUE; + } + OSLockMutex(&res_p->mutex); + while (connection->_unkC != 0) + { + OSWaitCond(&res_p->cond, &res_p->mutex); + } + OSUnlockMutex(&res_p->mutex); +} + +void NHTTPi_NotifyCompletion(NHTTPConnectionInfo* connection) +{ + NHTTPStaticResource* res_p = &NHTTPiStaticResource; + + if (!res_p->initialized) + { + OSInitMutex(&res_p->mutex); + OSInitCond(&res_p->cond); + res_p->initialized = TRUE; + } + OSLockMutex(&res_p->mutex); + connection->_unkC = 0; + OSSignalCond(&res_p->cond); + OSUnlockMutex(&res_p->mutex); +} + +NHTTPConnectionInfo* NHTTPi_ControlConnectionList(void* mutexInfo, + void* handle, u32 mode) +{ + NHTTPConnectionInfo* connection; + NHTTPConnectionInfo* result; + NHTTPConnectionInfo** current; + + result = NULL; + NHTTPi_lockReqList(mutexInfo); + if (mode == 3) + { + connection = handle; + connection->next = sConnectionList; + sConnectionList = connection; + result = connection; + } + else + { + current = &sConnectionList; + while (*current != NULL) + { + connection = *current; + switch (mode) + { + case 0: + if (connection == handle) + { + result = connection; + } + break; + case 1: + if (connection->request == handle) + { + result = connection; + } + break; + case 2: + if (connection->response == handle) + { + result = connection; + } + break; + case 4: + if (connection == handle) + { + *current = connection->next; + result = connection; + } + break; + } + + if (result != NULL) + { + break; + } + current = &(*current)->next; + } + } + NHTTPi_unlockReqList(mutexInfo); + return result; +} + +s32 NHTTPi_CommitConnectionList(void* mutexInfo_p, + NHTTPConnectionInfo* connection_p) +{ + return ((NHTTPi_ControlConnectionList(mutexInfo_p, connection_p, 3) + != NULL) + ? 0 + : -1); +} + +s32 NHTTPi_OmitConnectionList(void* mutexInfo_p, + NHTTPConnectionInfo* connection_p) +{ + return ((NHTTPi_ControlConnectionList(mutexInfo_p, connection_p, 4) + != NULL) + ? 0 + : -1); +} + +NHTTPRequestInfo* NHTTPi_Connection2Request(void* mutexInfo, + NHTTPConnectionInfo* connection) +{ + connection = NHTTPi_ControlConnectionList(mutexInfo, connection, 0); + return connection != NULL ? connection->request : NULL; +} + +NHTTPResponseInfo* NHTTPi_Connection2Response(void* mutexInfo, + NHTTPConnectionInfo* connection) +{ + connection = NHTTPi_ControlConnectionList(mutexInfo, connection, 0); + return connection != NULL ? connection->response : NULL; +} + +NHTTPConnectionInfo* NHTTPi_Request2Connection(void* mutexInfo, + NHTTPRequestInfo* request) +{ + return NHTTPi_ControlConnectionList( + mutexInfo, request, 1); +} + +NHTTPConnectionInfo* NHTTPi_Response2Connection(void* mutexInfo, + NHTTPResponseInfo* response) +{ + return NHTTPi_ControlConnectionList( + mutexInfo, response, 2); +} + +NHTTPConnectionInfo* NHTTPi_GetConnection(void* mutexInfo, + NHTTPConnectionInfo* connection) +{ + return NHTTPi_ControlConnectionList(mutexInfo, connection, 0); +} + +NHTTPRequestInfo* NHTTPi_GetRequest(void* mutexInfo, + NHTTPRequestInfo* request) +{ + NHTTPConnectionInfo* connection; + + connection = NHTTPi_ControlConnectionList( + mutexInfo, request, 0); + return connection != NULL ? connection->request : request; +} + +NHTTPResponseInfo* NHTTPi_GetResponse(void* mutexInfo, + NHTTPResponseInfo* response) +{ + NHTTPConnectionInfo* connection; + + connection = NHTTPi_ControlConnectionList( + mutexInfo, response, 0); + return connection != NULL ? connection->response : response; +} + +s32 NHTTPi_GetConnectionListLength(void) +{ + NHTTPConnectionInfo* connection; + s32 length; + + connection = sConnectionList; + length = 0; + while (connection != NULL) + { + connection = connection->next; + length++; + } + return length; +} + +s32 NHTTPi_PostSendCallback(void* mutexInfo, + NHTTPConnectionInfo* connection, void* value, u32 arg) +{ + u32 callbackArg4; + u32 callbackArg8; + s32 result; + NHTTPResponseInfo* response; + NHTTPConnectionCallbackParam param; + + result = -1; + if (NHTTPi_GetConnection(mutexInfo, connection) != NULL) + { + response = NHTTPi_Connection2Response(mutexInfo, connection); + if (response != NULL && connection->callback != NULL) + { + param.value = value; + param._unk4 = connection->_unk24; + param._unk8 = connection->_unk28; + param._unkC = arg; + result = connection->callback(connection, 1, ¶m); + callbackArg8 = param._unk8; + callbackArg4 = param._unk4; + + connection = NHTTPi_GetConnection(mutexInfo, connection); + if (connection != NULL) + { + connection->_unk24 = callbackArg4; + connection->_unk28 = callbackArg8; + } + } + } + return result; +} + +void NHTTPi_BufferFullCallback(void* mutexInfo, + NHTTPConnectionInfo* connection) +{ + void* buffer; + u32 bufferSize; + s32 responseResult; + NHTTPResponseInfo* response; + NHTTPConnectionCallbackParam param; + + if (NHTTPi_GetConnection(mutexInfo, connection) != NULL) + { + response = NHTTPi_Connection2Response(mutexInfo, connection); + if (response != NULL && connection->callback != NULL) + { + param.value = response->recvBuf_p; + param._unk4 = response->recvBufLen; + param._unk8 = response->bodyLen; + connection->callback(connection, 2, ¶m); + responseResult = param._unk8; + bufferSize = param._unk4; + buffer = param.value; + + connection = NHTTPi_GetConnection(mutexInfo, connection); + if (connection != NULL) + { + response = NHTTPi_Connection2Response(mutexInfo, connection); + if (response != NULL) + { + response->recvBuf_p = buffer; + response->recvBufLen = bufferSize; + response->bodyLen = responseResult; + } + } + } + } +} + +void NHTTPi_ReceivedCallback(void* mutexInfo, + NHTTPConnectionInfo* connection) +{ + void* buffer; + u32 bufferSize; + s32 responseResult; + NHTTPResponseInfo* response; + NHTTPConnectionCallbackParam param; + + if (NHTTPi_GetConnection(mutexInfo, connection) != NULL) + { + response = NHTTPi_Connection2Response(mutexInfo, connection); + if (response != NULL && connection->callback != NULL) + { + param.value = response->recvBuf_p; + param._unk4 = response->recvBufLen; + param._unk8 = response->bodyLen; + connection->callback(connection, 3, ¶m); + responseResult = param._unk8; + bufferSize = param._unk4; + buffer = param.value; + + connection = NHTTPi_GetConnection(mutexInfo, connection); + if (connection != NULL) + { + response = NHTTPi_Connection2Response(mutexInfo, connection); + if (response != NULL) + { + response->recvBuf_p = buffer; + response->recvBufLen = bufferSize; + response->bodyLen = responseResult; + } + } + } + } +} + +void NHTTPi_CompleteCallback(void* mutexInfo, + NHTTPConnectionInfo* connection) +{ + if (NHTTPi_GetConnection(mutexInfo, connection) != NULL + && connection->callback != NULL) + { + connection->callback(connection, 4, NULL); + } +} + +static void NHTTPi_InitSystemInfo(NHTTPSysInfo* sysInfo_p) +{ + NHTTPi_InitBgnEndInfo(NHTTPi_GetBgnEndInfoP(sysInfo_p)); + NHTTPi_InitListInfo(NHTTPi_GetListInfoP(sysInfo_p)); + NHTTPi_InitRequestInfo(NHTTPi_GetReqInfoP(sysInfo_p)); + NHTTPi_InitMutexInfo(NHTTPi_GetMutexInfoP(sysInfo_p)); + NHTTPi_InitThreadInfo(NHTTPi_GetThreadInfoP(sysInfo_p)); +} + +NHTTPSysInfo* NHTTPi_GetSystemInfoP(void) +{ + if (sysInfo_p == NULL) + { + sysInfo_p = &sysInfo; + NHTTPi_InitSystemInfo(sysInfo_p); + } + return sysInfo_p; +} + +NHTTPBgnEndInfo* NHTTPi_GetBgnEndInfoP(NHTTPSysInfo* sysInfo_p) +{ + return (NHTTPBgnEndInfo*)sysInfo_p->bgnEndInfo; +} + +NHTTPListInfo* NHTTPi_GetListInfoP(NHTTPSysInfo* sysInfo_p) +{ + return &sysInfo_p->listInfo; +} + +NHTTPReqInfo* NHTTPi_GetReqInfoP(NHTTPSysInfo* sysInfo_p) +{ + return &sysInfo_p->reqInfo; +} + +void* NHTTPi_GetThreadInfoP(NHTTPSysInfo* sysInfo_p) +{ + return sysInfo_p->threadInfo; +} + +void* NHTTPi_GetMutexInfoP(NHTTPSysInfo* sysInfo_p) +{ + return sysInfo_p->mutexInfo; +} + +void NHTTPi_SetVirtualContentLength(NHTTPConnectionInfo* connection, + u32 length) +{ + if (connection != NULL) + { + connection->virtualContentLength = length; + } +} + +u32 NHTTPi_GetVirtualContentLength(NHTTPConnectionInfo* connection) +{ + return connection != NULL ? connection->virtualContentLength : 0; +} + +void NHTTPi_InitConnectionList(void) +{ + NHTTPConnectionInfo* connection; + s32 count; + + connection = sConnectionList; + if (connection != NULL) + { + count = 0; + while (connection != NULL) + { + connection = connection->next; + count++; + } + if (count != 0) + { + printf("*warning: %d connections rests! Please free connections.\n", + count); + } + } + sConnectionList = NULL; +} -- 2.49.1