diff options
author | TakaRikka <38417346+TakaRikka@users.noreply.github.com> | 2021-09-16 20:51:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-16 20:51:49 -0700 |
commit | de3d9346e2601c34b1c5a51ced6493cd0c74eff4 (patch) | |
tree | c76d0ca12da365692ce5021fb32210a47f2495ef | |
parent | d1622d3cae13860823206322b63ea8841471b1d4 (diff) | |
parent | 10b69b3b411801e520a3f9e755b80ebe71b987c4 (diff) |
Merge pull request #4 from Zephiles/master
__CARDGetFileNo - Use __CARDCompareFileName instead of strncmp
-rw-r--r-- | include/card.h | 4 | ||||
-rw-r--r-- | include/card_internal.h | 4 | ||||
-rw-r--r-- | src/card.c | 16 |
3 files changed, 14 insertions, 10 deletions
diff --git a/include/card.h b/include/card.h index 6e1117d..87aed7a 100644 --- a/include/card.h +++ b/include/card.h @@ -3,8 +3,8 @@ #include <stdint.h> -#define CARD_SLOT_A 0 // Memory card slot A -#define CARD_SLOT_B 1 // Memory card slot B +#define CARD_SLOT_A 0 // Memory card slot A +#define CARD_SLOT_B 1 // Memory card slot B #define CARD_FILENAME_MAX 32 #define CARD_ICON_MAX 8 diff --git a/include/card_internal.h b/include/card_internal.h index 237ac1d..de47934 100644 --- a/include/card_internal.h +++ b/include/card_internal.h @@ -5,12 +5,13 @@ #define __CARD_INTERNAL_H__ #include "card.h" #include <stddef.h> +#include <stdbool.h> typedef struct CARDBlock { uint8_t unk[0x110]; } CARDBlock; -// 0x8044cbc0 in US; Specifically have to use this one and not make a new one +// Specifically have to use this one and not make a new one extern CARDBlock __CARDBlock[2]; // One for each memory card slot // Vanilla functions used in main code @@ -22,6 +23,7 @@ int32_t __CARDSync(int32_t chn); int32_t __CARDUpdateFatBlock(int32_t chn, void* fatBlock, CARDCallback callback); void* __CARDGetDirBlock(void* card); int32_t __CARDUpdateDir(int32_t chn, CARDCallback callback); +bool __CARDCompareFileName(void* dirBlock, const char* fileName); int32_t __CARDAccess(void* card, void* dirBlock); #endif // __CARD_INTERNAL_H__
\ No newline at end of file @@ -5,7 +5,6 @@ // We declare those instead of using the standard headers to let // the linker link them against the ones already in the game's code. -int32_t strncmp(const char* str1, const char* str2, size_t n); void* memset(void* dst, int val, size_t n); // +=-=-=-=-=-=-=-=-=-=-=+ @@ -70,14 +69,17 @@ int32_t __CARDGetFileNo(void* card, const char* fileName, int32_t* fileNo) { for (i = 0; i < 127; i++) { uint8_t* currentDirBlock = (uint8_t*)(dirBlock + (i * 0x40)); - const char* currentFileName = (const char*)(¤tDirBlock[0x8]); - if (strncmp(fileName, currentFileName, 32) == 0) { - if (__CARDAccess(card, currentDirBlock) >= Ready) { - *fileNo = i; - break; - } + if (!__CARDCompareFileName(currentDirBlock, fileName)) { + continue; } + + if (__CARDAccess(card, currentDirBlock) < Ready) { + continue; + } + + *fileNo = i; + break; } if (i >= 127) { |