Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Assets/dll/melonDS.wbx.zst
100644 → 100755
Binary file not shown.
23 changes: 22 additions & 1 deletion waterbox/melon/BizConsoleCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ static std::unique_ptr<T> CreateBiosImage(u8* biosData, u32 biosLength, std::opt
return std::move(bios);
}

static bool isValidMacAddress(const melonDS::MacAddress& mac)
{
// Invalid 48bit MAC address: FF:FF:FF:FF:FF:FF
const bool isAll0xFF = mac[0] == 0xFF && mac[1] == 0xFF && mac[2] == 0xFF && mac[3] == 0xFF && mac[4] == 0xFF && mac[5] == 0xFF;

// Broadcast channel 48bit MAC address: 03:09:BF:XX:XX:XX
const bool isBroadsast = mac[0] == 0x03 && mac[1] == 0x09 && mac[2] == 0xBF;

return !isAll0xFF || !isBroadsast;
}

static void SanitizeExternalFirmware(melonDS::Firmware& firmware)
{
auto& header = firmware.GetHeader();
Expand All @@ -84,7 +95,17 @@ static void SanitizeExternalFirmware(melonDS::Firmware& firmware)
memset(&header.Bytes[0x28], 0xFF, 2);
}

memcpy(&header.Bytes[0x2C], &defaultHeader.Bytes[0x2C], 0x136);
memcpy(&header.Bytes[0x2C], &defaultHeader.Bytes[0x2C], 10);

// MAC address offset is 0x36, so we skip writing from 0x36 to 0x3B (48 bit)
// to avoid copying melonDS default MAC address 0x0009BF112233
// only if the external firmware MAC address is valid
if (!isValidMacAddress(header.MacAddr))
{
memcpy(&header.Bytes[0x36], &defaultHeader.Bytes[0x36], 6);
}

memcpy(&header.Bytes[0x3C], &defaultHeader.Bytes[0x3C], 0x126);
memset(&header.Bytes[0x162], 0xFF, 0x9E);

if (isDSiFw)
Expand Down