Compare commits

...

2 Commits

Author SHA1 Message Date
Rosalie Wanders f6b41187cc RMG-COre: try to fix str size in CoreGetCUrrentRomHeader() (TODO: test) 2025-04-30 17:16:06 +02:00
Rosalie Wanders 5696153e34 3rdParty: add small64 signature to open_rom() 2025-04-30 16:57:37 +02:00
2 changed files with 14 additions and 2 deletions
+6 -1
View File
@@ -76,12 +76,16 @@ static const uint8_t Z64_SIGNATURE[4] = { 0x80, 0x37, 0x12, 0x40 };
static const uint8_t V64_SIGNATURE[4] = { 0x37, 0x80, 0x40, 0x12 };
static const uint8_t N64_SIGNATURE[4] = { 0x40, 0x12, 0x37, 0x80 };
static const uint8_t ALT_Z64_SIGNATURE[4] = { 0x31, 0x37, 0x12, 0x40 };
/* Tests if a file is a valid N64 rom by checking the first 4 bytes and size */
static int is_valid_rom(const unsigned char *buffer, unsigned int size)
{
printf("rom signature: 0x%02X, 0x%02X, 0x%02X, 0x%02X\n", buffer[0], buffer[1], buffer[2], buffer[3]);
if ((memcmp(buffer, Z64_SIGNATURE, sizeof(Z64_SIGNATURE)) == 0)
|| (memcmp(buffer, V64_SIGNATURE, sizeof(V64_SIGNATURE)) == 0 && size % 2 == 0)
|| (memcmp(buffer, N64_SIGNATURE, sizeof(N64_SIGNATURE)) == 0 && size % 4 == 0))
|| (memcmp(buffer, N64_SIGNATURE, sizeof(N64_SIGNATURE)) == 0 && size % 4 == 0)
|| (memcmp(buffer, ALT_Z64_SIGNATURE, sizeof(ALT_Z64_SIGNATURE)) == 0))
return 1;
else
return 0;
@@ -149,6 +153,7 @@ m64p_error open_rom(const unsigned char* romimage, unsigned int size)
if (romimage == NULL || !is_valid_rom(romimage, size))
{
DebugMessage(M64MSG_ERROR, "open_rom(): not a valid ROM image");
printf("fail\n");
return M64ERR_INPUT_INVALID;
}
+8 -1
View File
@@ -12,6 +12,7 @@
#else // Unix
#include <arpa/inet.h>
#endif // _WIN32
#include <cstring>
#define CORE_INTERNAL
#include "ConvertStringEncoding.hpp"
@@ -168,13 +169,19 @@ CORE_EXPORT bool CoreGetCurrentRomHeader(CoreRomHeader& header)
return false;
}
printf("header name len: %i\n", strlen((char*)m64p_header.Name));
header.CRC1 = ntohl(m64p_header.CRC1);
header.CRC2 = ntohl(m64p_header.CRC2);
header.CountryCode = m64p_header.Country_code;
header.Name = CoreConvertStringEncoding(std::string(reinterpret_cast<char*>(m64p_header.Name), 20), CoreStringEncoding::Shift_JIS);
header.Name = CoreConvertStringEncoding(std::string(reinterpret_cast<char*>(m64p_header.Name),
std::min(std::strlen(reinterpret_cast<char*>(m64p_header.Name)), static_cast<size_t>(20))),
CoreStringEncoding::Shift_JIS);
header.GameID = get_gameid_from_header(m64p_header);
header.Region = get_region_from_countrycode(static_cast<char>(header.CountryCode));
header.SystemType = get_systemtype_from_countrycode(header.CountryCode);
printf("header name len after: %i\n", header.Name.size());
return true;
}