From 48d4f287378e61d4be8cedd8d47e10c681be988d Mon Sep 17 00:00:00 2001 From: Sonic Dreamcaster Date: Sat, 1 Nov 2025 18:26:31 -0300 Subject: [PATCH] Fix duke nukem zero hour --- librecomp/src/pak.cpp | 417 +++++++++++++++++++++++++----------------- 1 file changed, 253 insertions(+), 164 deletions(-) diff --git a/librecomp/src/pak.cpp b/librecomp/src/pak.cpp index 5643a9e..ff4bc48 100644 --- a/librecomp/src/pak.cpp +++ b/librecomp/src/pak.cpp @@ -7,11 +7,11 @@ #include "recomp.h" #include "helpers.hpp" +#define PAK_DEBUG 0 #define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0])) #define MAX_FILES 16 -typedef struct ControllerPak -{ +typedef struct ControllerPak { std::fstream header; std::fstream file; } ControllerPak; @@ -20,56 +20,49 @@ typedef struct ControllerPak // const std::u8string save_folder = u8"saves"; // std::filesystem::path save_folder_path = config_path / save_folder; -void Pfs_PakHeader_Write(u32 *file_size, u32 *game_code, u16 *company_code, u8 *ext_name, u8 *game_name, u8 fileIndex) -{ +void Pfs_PakHeader_Write(u32* file_size, u32* game_code, u16* company_code, u8* ext_name, u8* game_name, u8 fileIndex) { ControllerPak pak; pak.header.open("controllerPak_header.sav", std::ios::binary | std::ios::in | std::ios::out); - if (!pak.header.good()) - { + if (!pak.header.good()) { assert(false); } - if (!pak.header.is_open()) - { + if (!pak.header.is_open()) { assert(false); } /* Set file parameters to header */ - u32 seek = fileIndex * sizeof(OSPfsState); + u32 seek = fileIndex * 0x20; // file_size pak.header.seekp(seek + 0x0, std::ios::beg); - pak.header.write((char *)file_size, 4); + pak.header.write((char*) file_size, 4); // game_code pak.header.seekp(seek + 0x4, std::ios::beg); - pak.header.write((char *)game_code, 4); + pak.header.write((char*) game_code, 4); // company_code pak.header.seekp(seek + 0x08, std::ios::beg); - pak.header.write((char *)company_code, 2); + pak.header.write((char*) company_code, 2); // ext_name - pak.header.seekp(seek + 0x0C, std::ios::beg); - pak.header.write((char *)ext_name, 4); + pak.header.seekp(seek + 0xC, std::ios::beg); + pak.header.write((char*) ext_name, 4); // game_name pak.header.seekp(seek + 0x10, std::ios::beg); - pak.header.write((char *)game_name, 16); + pak.header.write((char*) game_name, 16); pak.header.close(); } -void Pfs_PakHeader_Read(u32 *file_size, u32 *game_code, u16 *company_code, char *ext_name, char *game_name, - u8 fileIndex) -{ +void Pfs_PakHeader_Read(u32* file_size, u32* game_code, u16* company_code, u8* ext_name, u8* game_name, u8 fileIndex) { ControllerPak pak; pak.header.open("controllerPak_header.sav", std::ios::binary | std::ios::in | std::ios::out); - if (!pak.header.good()) - { + if (!pak.header.good()) { assert(false); } - if (!pak.header.is_open()) - { + if (!pak.header.is_open()) { assert(false); } @@ -78,29 +71,27 @@ void Pfs_PakHeader_Read(u32 *file_size, u32 *game_code, u16 *company_code, char // file_size pak.header.seekg(seek + 0x0, std::ios::beg); - pak.header.read((char *)file_size, 4); + pak.header.read((char*) file_size, 4); // game_code pak.header.seekg(seek + 0x4, std::ios::beg); - pak.header.read((char *)game_code, 4); + pak.header.read((char*) game_code, 4); // company_code pak.header.seekg(seek + 0x08, std::ios::beg); - pak.header.read((char *)company_code, 2); + pak.header.read((char*) company_code, 2); // ext_name - pak.header.seekg(seek + 0x0C, std::ios::beg); - pak.header.read((char *)ext_name, 4); + pak.header.seekg(seek + 0xC, std::ios::beg); + pak.header.read((char*) ext_name, 4); // game_name pak.header.seekg(seek + 0x10, std::ios::beg); - pak.header.read((char *)game_name, 16); + pak.header.read((char*) game_name, 16); pak.header.close(); } -void Pfs_ByteSwapFile(u8 *buffer, size_t size) -{ +void Pfs_ByteSwapFile(u8* buffer, size_t size) { uint8_t c0, c1, c2, c3; - for (size_t i = 0; i < size; i += 4) - { + for (size_t i = 0; i < size; i += 4) { c0 = buffer[i + 0]; c1 = buffer[i + 1]; c2 = buffer[i + 2]; @@ -113,24 +104,20 @@ void Pfs_ByteSwapFile(u8 *buffer, size_t size) } } -void ByteSwapCopy(uint8_t *dst, uint8_t *src, size_t size_bytes) -{ - for (size_t i = 0; i < size_bytes; i++) - { +void ByteSwapCopy(uint8_t* dst, uint8_t* src, size_t size_bytes) { + for (size_t i = 0; i < size_bytes; i++) { dst[i] = src[i ^ 3]; } } -extern "C" void osPfsIsPlug_recomp(uint8_t *rdram, recomp_context *ctx) -{ +extern "C" void osPfsIsPlug_recomp(uint8_t* rdram, recomp_context* ctx) { MEM_B(0, ctx->r5) = 0b0001; // *pattern = 1; ctx->r2 = 0; // PFS_NO_ERROR } -extern "C" void osPfsInit_recomp(uint8_t *rdram, recomp_context *ctx) -{ +extern "C" void osPfsInit_recomp(uint8_t* rdram, recomp_context* ctx) { int32_t queue = _arg<0, int32_t>(rdram, ctx); - OSPfs *pfs = _arg<1, OSPfs *>(rdram, ctx); + OSPfs* pfs = _arg<1, OSPfs*>(rdram, ctx); s32 channel = _arg<2, s32>(rdram, ctx); pfs->queue = queue; @@ -140,8 +127,7 @@ extern "C" void osPfsInit_recomp(uint8_t *rdram, recomp_context *ctx) ControllerPak pak; // If a header file doesn't exist, create it. - if (!std::filesystem::exists("controllerPak_header.sav")) - { + if (!std::filesystem::exists("controllerPak_header.sav")) { pak.header.open("controllerPak_header.sav", std::ios::binary | std::ios::in | std::ios::out | std::ios::trunc); pak.header.close(); } @@ -149,10 +135,9 @@ extern "C" void osPfsInit_recomp(uint8_t *rdram, recomp_context *ctx) ctx->r2 = 0; // PFS_NO_ERROR } -extern "C" void osPfsInitPak_recomp(uint8_t *rdram, recomp_context *ctx) -{ +extern "C" void osPfsInitPak_recomp(uint8_t* rdram, recomp_context* ctx) { int32_t queue = _arg<0, int32_t>(rdram, ctx); - OSPfs *pfs = _arg<1, OSPfs *>(rdram, ctx); + OSPfs* pfs = _arg<1, OSPfs*>(rdram, ctx); s32 channel = _arg<2, s32>(rdram, ctx); pfs->queue = queue; @@ -162,36 +147,60 @@ extern "C" void osPfsInitPak_recomp(uint8_t *rdram, recomp_context *ctx) ControllerPak pak; // If a header file doesn't exist, create it. - if (!std::filesystem::exists("controllerPak_header.sav")) - { + if (!std::filesystem::exists("controllerPak_header.sav")) { pak.header.open("controllerPak_header.sav", std::ios::binary | std::ios::in | std::ios::out | std::ios::trunc); pak.header.close(); } +// Test +#if PAK_DEBUG + u32 file_size_ = 0x01020304; + u32 game_code_ = 0x05060708; + u16 company_code_ = 0x0910; + u8 ext_name_[4] = { 0x11, 0x12, 0x13, 0x14 }; + u8 game_name_[16] = { 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24 }; + + Pfs_PakHeader_Write(&file_size_, &game_code_, &company_code_, ext_name_, game_name_, 0); + + Pfs_PakHeader_Read(&file_size_, &game_code_, &company_code_, ext_name_, game_name_, 0); + + printf("TEST\n"); + printf("file_size_: %x\n", file_size_); + printf("game_code: %x\n", game_code_); + printf("company_code: %x\n", company_code_); + + printf("ext_name: "); + for (size_t i = 0; i < 4; i++) { + printf("%x", ext_name_[i]); + } + printf("\n"); + + printf("game_name: "); + for (size_t i = 0; i < 16; i++) { + printf("%x", game_name_[i]); + } + printf("\n"); +#endif + ctx->r2 = 0; // PFS_NO_ERROR } -extern "C" void osPfsFreeBlocks_recomp(uint8_t *rdram, recomp_context *ctx) -{ - s32 *bytes_not_used = _arg<1, s32 *>(rdram, ctx); +extern "C" void osPfsFreeBlocks_recomp(uint8_t* rdram, recomp_context* ctx) { + s32* bytes_not_used = _arg<1, s32*>(rdram, ctx); s32 usedSpace = 0; - for (size_t i = 0; i < MAX_FILES; i++) - { + for (size_t i = 0; i < MAX_FILES; i++) { u32 file_size = 0; u32 game_code = 0; u16 company_code = 0; - char ext_name[4] = {0}; - char game_name[16] = {0}; + u8 ext_name[4] = { 0 }; + u8 game_name[16] = { 0 }; Pfs_PakHeader_Read(&file_size, &game_code, &company_code, ext_name, game_name, i); - if ((company_code == 0) || (game_code == 0)) - { + if ((company_code == 0) || (game_code == 0)) { continue; - } - else - { + } else { usedSpace += file_size >> 8; } } @@ -201,35 +210,31 @@ extern "C" void osPfsFreeBlocks_recomp(uint8_t *rdram, recomp_context *ctx) ctx->r2 = 0; // PFS_NO_ERROR } -extern "C" void osPfsAllocateFile_recomp(uint8_t *rdram, recomp_context *ctx) -{ +extern "C" void osPfsAllocateFile_recomp(uint8_t* rdram, recomp_context* ctx) { u16 company_code = _arg<1, u16>(rdram, ctx); u32 game_code = _arg<2, u32>(rdram, ctx); - u8 *game_name = _arg<3, u8 *>(rdram, ctx); - u8 *ext_name = TO_PTR(u8, MEM_W(0x10, ctx->r29)); - u32 file_size = (s32)MEM_W(0x14, ctx->r29); - s32 *file_no = TO_PTR(s32, MEM_W(0x18, ctx->r29)); + u8* game_name = _arg<3, u8*>(rdram, ctx); + u8* ext_name = TO_PTR(u8, MEM_W(0x10, ctx->r29)); + u32 file_size = (s32) MEM_W(0x14, ctx->r29); + s32* file_no = TO_PTR(s32, MEM_W(0x18, ctx->r29)); - if ((company_code == 0) || (game_code == 0)) - { + if ((company_code == 0) || (game_code == 0)) { ctx->r2 = 5; // PFS_ERR_INVALID return; } /* Search for a free slot */ u8 freeFileIndex = 0; - for (size_t i = 0; i < MAX_FILES; i++) - { + for (size_t i = 0; i < MAX_FILES; i++) { u32 file_size_ = 0; u32 game_code_ = 0; u16 company_code_ = 0; - char ext_name_[4] = {0}; - char game_name_[16] = {0}; + u8 ext_name_[4] = { 0 }; + u8 game_name_[16] = { 0 }; Pfs_PakHeader_Read(&file_size_, &game_code_, &company_code_, ext_name_, game_name_, i); - if ((company_code_ == 0) || (game_code_ == 0)) - { + if ((company_code_ == 0) || (game_code_ == 0)) { freeFileIndex = i; break; } @@ -252,11 +257,11 @@ extern "C" void osPfsAllocateFile_recomp(uint8_t *rdram, recomp_context *ctx) file_size = (file_size + 31) & ~31; - u8 *zero_block = (u8 *)malloc(file_size); + u8* zero_block = (u8*) malloc(file_size); memset(zero_block, 0, file_size); pak.file.seekp(0, std::ios::beg); - pak.file.write((char *)zero_block, file_size); + pak.file.write((char*) zero_block, file_size); free(zero_block); @@ -267,16 +272,15 @@ extern "C" void osPfsAllocateFile_recomp(uint8_t *rdram, recomp_context *ctx) ctx->r2 = 0; // PFS_NO_ERROR } -extern "C" void osPfsFileState_recomp(uint8_t *rdram, recomp_context *ctx) -{ +extern "C" void osPfsFileState_recomp(uint8_t* rdram, recomp_context* ctx) { s32 file_no = _arg<1, s32>(rdram, ctx); - OSPfsState *state = _arg<2, OSPfsState *>(rdram, ctx); + OSPfsState* state = _arg<2, OSPfsState*>(rdram, ctx); u32 file_size = 0; u32 game_code = 0; u16 company_code = 0; - char ext_name[4] = {0}; - char game_name[16] = {0}; + u8 ext_name[4] = { 0 }; + u8 game_name[16] = { 0 }; // should pass the state of the requested file_no to the incoming state pointer, // games call this function 16 times, once per file @@ -284,8 +288,7 @@ extern "C" void osPfsFileState_recomp(uint8_t *rdram, recomp_context *ctx) char filename[100]; sprintf(filename, "controllerPak_file_%d.sav", file_no); - if (!std::filesystem::exists(filename)) - { + if (!std::filesystem::exists(filename)) { ctx->r2 = 5; return; } @@ -293,51 +296,102 @@ extern "C" void osPfsFileState_recomp(uint8_t *rdram, recomp_context *ctx) /* Read game info from pak */ Pfs_PakHeader_Read(&file_size, &game_code, &company_code, ext_name, game_name, file_no); + // Test code +#if 0 + for (size_t i = 0; i < 5; i++) { + ext_name[i] = i + 1; + } + + for (size_t i = 0; i < 16; i++) { + game_name[i] = i + 1; + } +#endif + +#if 1 state->file_size = file_size; - state->company_code = game_code; + state->company_code = company_code; state->game_code = game_code; - for (size_t j = 0; j < ARRAY_COUNT(game_name); j++) - { + for (size_t j = 0; j < ARRAY_COUNT(game_name); j++) { state->game_name[j] = game_name[j]; } - for (size_t j = 0; j < ARRAY_COUNT(ext_name); j++) - { + for (size_t j = 0; j < ARRAY_COUNT(ext_name); j++) { state->ext_name[j] = ext_name[j]; } +#else + u8* ptr = (u8*) state; + *(u32*) &ptr[0] = file_size; + *(u32*) &ptr[0x4] = game_code; + *(u16*) &ptr[0xA] = company_code; + + // printf("*(u16*) &ptr[0x8] = company_code; : %x\n", ptr[0xA]); + + char* ext_name_ = (char*) &ptr[0xC]; + char* game_name_ = (char*) &ptr[0x10]; + + for (size_t j = 0; j < 4; j++) { + ext_name_[j] = ext_name[j]; + } + for (size_t j = 0; j < 16; j++) { + game_name_[j] = game_name[j]; + } +#endif + +#if PAK_DEBUG + if (file_no == 0) { + printf("osPfsFileState_recomp: STORE IN GAME PTR\n"); + printf("file_size: %x\n", state->file_size); + printf("company_code: %x\n", state->company_code); + printf("game_code: %x\n", state->game_code); + + printf("game_name: "); + for (size_t i = 0; i < 16; i++) { + printf("%x", game_name[i]); + } + printf("\n"); + + printf("ext_name: "); + for (size_t i = 0; i < 4; i++) { + printf("%x", ext_name[i]); + } + printf("\n"); + } +#endif ctx->r2 = 0; // PFS_NO_ERROR } -extern "C" void osPfsFindFile_recomp(uint8_t *rdram, recomp_context *ctx) -{ +extern "C" void osPfsFindFile_recomp(uint8_t* rdram, recomp_context* ctx) { u16 company_code = _arg<1, u16>(rdram, ctx); u32 game_code = _arg<2, u32>(rdram, ctx); - u8 *game_name = _arg<3, u8 *>(rdram, ctx); - u8 *ext_name = TO_PTR(u8, MEM_W(0x10, ctx->r29)); - s32 *file_no = TO_PTR(s32, MEM_W(0x14, ctx->r29)); + u8* game_name = _arg<3, u8*>(rdram, ctx); + u8* ext_name = TO_PTR(u8, MEM_W(0x10, ctx->r29)); + s32* file_no = TO_PTR(s32, MEM_W(0x14, ctx->r29)); - for (size_t i = 0; i < MAX_FILES; i++) - { + for (size_t i = 0; i < MAX_FILES; i++) { u32 file_size_ = 0; u32 game_code_ = 0; u16 company_code_ = 0; - char ext_name_[4] = {0}; - char game_name_[16] = {0}; + u8 ext_name_[4] = { 0 }; + u8 game_name_[16] = { 0 }; Pfs_PakHeader_Read(&file_size_, &game_code_, &company_code_, ext_name_, game_name_, i); - if ((company_code_ == 0) || (game_code_ == 0)) - { + if ((company_code_ == 0) || (game_code_ == 0)) { continue; - } - else - { - if ((game_code == game_code_) && (company_code == company_code_) && - (strcmp((const char *)game_name, (const char *)game_name_) == 0) && - strcmp((const char *)ext_name, (const char *)ext_name_) == 0) - { - // File found + } else { + if ((game_code == game_code_) && (company_code == company_code_)) { + for (size_t i = 0; i < ARRAY_COUNT(game_name_); i++) { + if (game_name[i] != game_name_[i]) { + break; + } + } + for (size_t i = 0; i < ARRAY_COUNT(ext_name_); i++) { + if (ext_name[i] != ext_name_[i]) { + break; + } + } + // File found *file_no = i; ctx->r2 = 0; // PFS_NO_ERROR return; @@ -349,13 +403,12 @@ extern "C" void osPfsFindFile_recomp(uint8_t *rdram, recomp_context *ctx) ctx->r2 = 5; // PFS_ERR_INVALID } -extern "C" void osPfsReadWriteFile_recomp(uint8_t *rdram, recomp_context *ctx) -{ +extern "C" void osPfsReadWriteFile_recomp(uint8_t* rdram, recomp_context* ctx) { s32 file_no = _arg<1, s32>(rdram, ctx); u8 flag = _arg<2, u8>(rdram, ctx); s32 offset = _arg<3, s32>(rdram, ctx); - s32 size_in_bytes = (s32)MEM_W(0x10, ctx->r29); - u8 *data_buffer = TO_PTR(u8, MEM_W(0x14, ctx->r29)); + s32 size_in_bytes = (s32) MEM_W(0x10, ctx->r29); + u8* data_buffer = TO_PTR(u8, MEM_W(0x14, ctx->r29)); ControllerPak pak; @@ -363,34 +416,28 @@ extern "C" void osPfsReadWriteFile_recomp(uint8_t *rdram, recomp_context *ctx) sprintf(filename, "controllerPak_file_%d.sav", file_no); pak.file.open(filename, std::ios::binary | std::ios::in | std::ios::out); - if (!std::filesystem::exists(filename)) - { + if (!std::filesystem::exists(filename)) { ctx->r2 = 5; // PFS_ERR_INVALID return; } - if (!pak.file.good()) - { + if (!pak.file.good()) { ctx->r2 = 5; // PFS_ERR_INVALID return; } - if (!pak.file.is_open()) - { + if (!pak.file.is_open()) { ctx->r2 = 5; // PFS_ERR_INVALID return; } - u8 *swapBuffer = (u8 *)malloc(size_in_bytes); - if (flag == 0) - { + u8* swapBuffer = (u8*) malloc(size_in_bytes); + if (flag == 0) { pak.file.seekg(offset, std::ios::beg); - pak.file.read((char *)swapBuffer, size_in_bytes); + pak.file.read((char*) swapBuffer, size_in_bytes); ByteSwapCopy(data_buffer, swapBuffer, size_in_bytes); - } - else - { + } else { ByteSwapCopy(swapBuffer, data_buffer, size_in_bytes); pak.file.seekp(offset, std::ios::beg); - pak.file.write((char *)swapBuffer, size_in_bytes); + pak.file.write((char*) swapBuffer, size_in_bytes); } free(swapBuffer); @@ -399,29 +446,25 @@ extern "C" void osPfsReadWriteFile_recomp(uint8_t *rdram, recomp_context *ctx) ctx->r2 = 0; // PFS_NO_ERROR } -extern "C" void osPfsChecker_recomp(uint8_t *rdram, recomp_context *ctx) -{ +extern "C" void osPfsChecker_recomp(uint8_t* rdram, recomp_context* ctx) { ctx->r2 = 0; // PFS_NO_ERROR } -extern "C" void osPfsNumFiles_recomp(uint8_t *rdram, recomp_context *ctx) -{ - s32 *max_files = _arg<1, s32 *>(rdram, ctx); - s32 *files_used = _arg<2, s32 *>(rdram, ctx); +extern "C" void osPfsNumFiles_recomp(uint8_t* rdram, recomp_context* ctx) { + s32* max_files = _arg<1, s32*>(rdram, ctx); + s32* files_used = _arg<2, s32*>(rdram, ctx); u8 files = 0; - for (size_t i = 0; i < MAX_FILES; i++) - { + for (size_t i = 0; i < MAX_FILES; i++) { u32 file_size = 0; u32 game_code = 0; u16 company_code = 0; - char ext_name[4] = {0}; - char game_name[16] = {0}; + u8 ext_name[4] = { 0 }; + u8 game_name[16] = { 0 }; Pfs_PakHeader_Read(&file_size, &game_code, &company_code, ext_name, game_name, i); - if ((company_code != 0) || (game_code != 0)) - { + if ((company_code != 0) || (game_code != 0)) { files++; } } @@ -432,61 +475,108 @@ extern "C" void osPfsNumFiles_recomp(uint8_t *rdram, recomp_context *ctx) ctx->r2 = 0; // PFS_NO_ERROR } -extern "C" void osPfsDeleteFile_recomp(uint8_t *rdram, recomp_context *ctx) -{ +extern "C" void osPfsDeleteFile_recomp(uint8_t* rdram, recomp_context* ctx) { u16 company_code = _arg<1, u16>(rdram, ctx); u32 game_code = _arg<2, u32>(rdram, ctx); - u8 *game_name = _arg<3, u8 *>(rdram, ctx); - u8 *ext_name = TO_PTR(u8, MEM_W(0x10, ctx->r29)); + u8* game_name = _arg<3, u8*>(rdram, ctx); + u8* ext_name = TO_PTR(u8, MEM_W(0x10, ctx->r29)); - if (company_code == 0 || game_code == 0) - { + // WORKAROUND! This shouldn't be necessary, there's something wrong with the OSPfsState struct + game_name += 2; + ext_name += 2; + +#if PAK_DEBUG + printf("osPfsDeleteFile_recomp: REQUEST\n"); + printf(" company_code: %x\n", company_code); + printf(" game_code: %x\n", game_code); + + printf(" ext_name: "); + for (size_t i = 0; i < 4; i++) { + printf("%x", ext_name[i]); + } + printf("\n"); + + printf(" game_name: "); + for (size_t i = 0; i < 16; i++) { + printf("%x", game_name[i]); + } + printf("\n"); +#endif + + if (company_code == 0 || game_code == 0) { ctx->r2 = 5; // PFS_ERR_INVALID return; } ControllerPak pak; - for (int i = 0; i < MAX_FILES; i++) - { + for (int i = 0; i < MAX_FILES; i++) { u32 file_size_ = 0; u32 game_code_ = 0; u16 company_code_ = 0; - char ext_name_[4] = {0}; - char game_name_[16] = {0}; + u8 ext_name_[4] = { 0 }; + u8 game_name_[16] = { 0 }; Pfs_PakHeader_Read(&file_size_, &game_code_, &company_code_, ext_name_, game_name_, i); - if ((company_code_ == 0) || (game_code_ == 0)) - { - continue; +#if PAK_DEBUG + if (i == 0) { + printf("osPfsDeleteFile_recomp: READ\n"); + printf("company_code: %x\n", company_code_); + printf("game_code: %x\n", game_code_); + + printf("ext_name_: "); + for (size_t i = 0; i < 4; i++) { + printf("%x", ext_name_[i]); + } + printf("\n"); + + printf("game_name_: "); + for (size_t i = 0; i < 16; i++) { + printf("%x", game_name_[i]); + } + printf("\n"); } - else - { - if ((game_code == game_code_) && (company_code == company_code_) && - (strcmp((const char *)game_name, (const char *)game_name_) == 0) && - strcmp((const char *)ext_name, (const char *)ext_name_) == 0) - { +#endif + + if ((company_code_ == 0) || (game_code_ == 0)) { + continue; + } else { + if ((game_code == game_code_) && (company_code == company_code_)) { + int gncount = 0; + int encount = 0; + + for (size_t i = 0; i < ARRAY_COUNT(game_name_); i++) { + if (game_name[i] == game_name_[i]) { + gncount++; + } + } + for (size_t i = 0; i < ARRAY_COUNT(ext_name_); i++) { + if (ext_name[i] == ext_name_[i]) { + encount++; + } + } + if ((gncount != 16) || encount != 4) { + continue; + } // File found pak.header.open("controllerPak_header.sav", std::ios::binary | std::ios::in | std::ios::out); - if (!pak.header.good()) - { + if (!pak.header.good()) { assert(false); } - if (!pak.header.is_open()) - { + if (!pak.header.is_open()) { assert(false); } u32 seek = i * sizeof(OSPfsState); // Zero out the header for this file. - u8 *zero_block = (u8 *)malloc(sizeof(OSPfsState)); + u8* zero_block = (u8*) malloc(sizeof(OSPfsState)); memset(zero_block, 0, sizeof(OSPfsState)); pak.header.seekp(seek + 0x0, std::ios::beg); - pak.header.write((char *)zero_block, sizeof(OSPfsState)); + pak.header.write((char*) zero_block, sizeof(OSPfsState)); free(zero_block); pak.header.close(); @@ -506,7 +596,6 @@ extern "C" void osPfsDeleteFile_recomp(uint8_t *rdram, recomp_context *ctx) return; } -extern "C" void osPfsRepairId_recomp(uint8_t *rdram, recomp_context *ctx) -{ +extern "C" void osPfsRepairId_recomp(uint8_t* rdram, recomp_context* ctx) { _return(ctx, 0); // PFS_NO_ERROR }