diff --git a/Source/Project64-core/N64System/N64RomClass.cpp b/Source/Project64-core/N64System/N64RomClass.cpp index 667b12479..1ae373c6c 100644 --- a/Source/Project64-core/N64System/N64RomClass.cpp +++ b/Source/Project64-core/N64System/N64RomClass.cpp @@ -413,6 +413,49 @@ bool CN64Rom::IsValidRomImage(uint8_t Test[4]) return false; } +void CN64Rom::CleanRomName(char * RomName, bool byteswap) +{ + if (byteswap) + { + for (int count = 0; count < 20; count += 4) + { + RomName[count] ^= RomName[count + 3]; + RomName[count + 3] ^= RomName[count]; + RomName[count] ^= RomName[count + 3]; + RomName[count + 1] ^= RomName[count + 2]; + RomName[count + 2] ^= RomName[count + 1]; + RomName[count + 1] ^= RomName[count + 2]; + } + } + + //truncate all the spaces at the end of the string + for (int count = 19; count >= 0; count--) + { + if (RomName[count] == ' ') + { + RomName[count] = '\0'; + } + else if (RomName[count] == '\0') + { + } + else + { + count = -1; + } + } + RomName[20] = '\0'; + + //remove all /,\,: from the string + for (int count = 0; count < (int)strlen(RomName); count++) + { + switch (RomName[count]) + { + case '/': case '\\': RomName[count] = '-'; break; + case ':': RomName[count] = ';'; break; + } + } +} + void CN64Rom::NotificationCB(const char * Status, CN64Rom * /*_this*/) { g_Notify->DisplayMessage(5, stdstr_f("%s", Status).c_str()); @@ -521,49 +564,16 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly) } char RomName[260]; - int count; //Get the header from the rom image memcpy(&RomName[0], (void *)(m_ROMImage + 0x20), 20); - for (count = 0; count < 20; count += 4) - { - RomName[count] ^= RomName[count + 3]; - RomName[count + 3] ^= RomName[count]; - RomName[count] ^= RomName[count + 3]; - RomName[count + 1] ^= RomName[count + 2]; - RomName[count + 2] ^= RomName[count + 1]; - RomName[count + 1] ^= RomName[count + 2]; - } + CN64Rom::CleanRomName(RomName); - //truncate all the spaces at the end of the string - for (count = 19; count >= 0; count--) - { - if (RomName[count] == ' ') - { - RomName[count] = '\0'; - } - else if (RomName[count] == '\0') - { - } - else - { - count = -1; - } - } - RomName[20] = '\0'; if (strlen(RomName) == 0) { strcpy(RomName, CPath(FileLoc).GetName().c_str()); + CN64Rom::CleanRomName(RomName, false); } - //remove all /,\,: from the string - for (count = 0; count < (int)strlen(RomName); count++) - { - switch (RomName[count]) - { - case '/': case '\\': RomName[count] = '-'; break; - case ':': RomName[count] = ';'; break; - } - } WriteTrace(TraceN64System, TraceDebug, "RomName %s", RomName); m_RomName = RomName; @@ -699,48 +709,13 @@ bool CN64Rom::LoadN64ImageIPL(const char * FileLoc, bool LoadBootCodeOnly) } char RomName[260]; - int count; //Get the header from the rom image memcpy(&RomName[0], (void *)(m_ROMImage + 0x20), 20); - for (count = 0; count < 20; count += 4) - { - RomName[count] ^= RomName[count + 3]; - RomName[count + 3] ^= RomName[count]; - RomName[count] ^= RomName[count + 3]; - RomName[count + 1] ^= RomName[count + 2]; - RomName[count + 2] ^= RomName[count + 1]; - RomName[count + 1] ^= RomName[count + 2]; - } - - //truncate all the spaces at the end of the string - for (count = 19; count >= 0; count--) - { - if (RomName[count] == ' ') - { - RomName[count] = '\0'; - } - else if (RomName[count] == '\0') - { - } - else - { - count = -1; - } - } - RomName[20] = '\0'; + CN64Rom::CleanRomName(RomName); if (strlen(RomName) == 0) { strcpy(RomName, CPath(FileLoc).GetName().c_str()); - } - - //remove all /,\,: from the string - for (count = 0; count < (int)strlen(RomName); count++) - { - switch (RomName[count]) - { - case '/': case '\\': RomName[count] = '-'; break; - case ':': RomName[count] = ';'; break; - } + CN64Rom::CleanRomName(RomName,false); } WriteTrace(TraceN64System, TraceDebug, "RomName %s", RomName); diff --git a/Source/Project64-core/N64System/N64RomClass.h b/Source/Project64-core/N64System/N64RomClass.h index fbf84ee9c..84f817108 100644 --- a/Source/Project64-core/N64System/N64RomClass.h +++ b/Source/Project64-core/N64System/N64RomClass.h @@ -37,6 +37,7 @@ public: //Get a message id for the reason that you failed to load the rom LanguageStringID GetError() const { return m_ErrorMsg; } static CICChip GetCicChipID(uint8_t * RomData, uint64_t * CRC = NULL); + static void CleanRomName(char * RomName, bool byteswap = true); private: bool AllocateRomImage(uint32_t RomFileSize); diff --git a/Source/Project64/UserInterface/RomList.cpp b/Source/Project64/UserInterface/RomList.cpp index 9ba289286..6819be31d 100644 --- a/Source/Project64/UserInterface/RomList.cpp +++ b/Source/Project64/UserInterface/RomList.cpp @@ -284,16 +284,7 @@ void CRomList::FillRomList(strlist & FileList, const char * Directory) { char InternalName[22]; memcpy(InternalName, (void *)(RomData + 0x20), 20); - for (int32_t count = 0; count < 20; count += 4) - { - InternalName[count] ^= InternalName[count + 3]; - InternalName[count + 3] ^= InternalName[count]; - InternalName[count] ^= InternalName[count + 3]; - InternalName[count + 1] ^= InternalName[count + 2]; - InternalName[count + 2] ^= InternalName[count + 1]; - InternalName[count + 1] ^= InternalName[count + 2]; - } - InternalName[20] = '\0'; + CN64Rom::CleanRomName(InternalName); wcscpy(RomInfo.InternalName, stdstr(InternalName).ToUTF16(stdstr::CODEPAGE_932).c_str()); } RomInfo.RomSize = (int32_t)f->Size; @@ -432,7 +423,6 @@ bool CRomList::LoadDataFromRomFile(const char * FileName, uint8_t * Data, int32_ bool CRomList::FillRomInfo(ROM_INFO * pRomInfo) { - int32_t count; uint8_t RomData[0x1000]; if (LoadDataFromRomFile(pRomInfo->szFullFileName, RomData, sizeof(RomData), &pRomInfo->RomSize, pRomInfo->FileFormat)) @@ -447,16 +437,7 @@ bool CRomList::FillRomInfo(ROM_INFO * pRomInfo) } char InternalName[22]; memcpy(InternalName, (void *)(RomData + 0x20), 20); - for (count = 0; count < 20; count += 4) - { - InternalName[count] ^= InternalName[count + 3]; - InternalName[count + 3] ^= InternalName[count]; - InternalName[count] ^= InternalName[count + 3]; - InternalName[count + 1] ^= InternalName[count + 2]; - InternalName[count + 2] ^= InternalName[count + 1]; - InternalName[count + 1] ^= InternalName[count + 2]; - } - InternalName[20] = '\0'; + CN64Rom::CleanRomName(InternalName); wcscpy(pRomInfo->InternalName, stdstr(InternalName).ToUTF16(stdstr::CODEPAGE_932).c_str()); pRomInfo->CartID[0] = *(RomData + 0x3F); pRomInfo->CartID[1] = *(RomData + 0x3E);