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
3 changes: 3 additions & 0 deletions common/include/CommonConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ typedef struct NIN_CFG
signed char VideoOffset;
unsigned char NetworkProfile;
unsigned int WiiUGamepadSlot;
unsigned int GameMakerCode;
unsigned int GameRevision;
unsigned int GameDiscNumber;
} NIN_CFG;

enum ninconfigbitpos
Expand Down
10 changes: 10 additions & 0 deletions loader/include/MemCardPro.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef __MEMCARDPRO_H__
#define __MEMCARDPRO_H__

#include <gctypes.h>
#include "global.h"

bool CheckForMemCardPro(s32 chan);
void SetMemCardProGameInfo(s32 chan, NIN_CFG* ncfg);

#endif
2 changes: 2 additions & 0 deletions loader/include/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ typedef struct GameInfo
char ID[6]; // ID6 of the game.
uint8_t Revision; // Disc revision.
uint8_t Flags; // See GameInfoFlags.
char MakerCode[2];
uint8_t DiscNumber;

char *Name; // Game name. (If NameAlloc, strdup()'d.)
char *Path; // File path.
Expand Down
71 changes: 71 additions & 0 deletions loader/source/MemCardPro.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
Lightly modified from the implementation in swiss
https://github.com/emukidid/swiss-gc/commit/3ee5c037e236060e38521f8f29187c1581df414a
*/

#include "MemCardPro.h"

#include <ogc/card.h>
#include <ogc/exi.h>

static const char digits[16] = "0123456789ABCDEF";

bool CheckForMemCardPro(s32 chan)
{
if (CARD_ProbeEx(chan, NULL, NULL) < 0) {
return false;
}

bool err = false;
u32 id;
u8 cmd[2];

if (!EXI_Lock(chan, EXI_DEVICE_0, NULL)) return false;
if (!EXI_Select(chan, EXI_DEVICE_0, EXI_SPEED16MHZ)) {
EXI_Unlock(chan);
return false;
}

cmd[0] = 0x8B;
cmd[1] = 0x00;

err |= !EXI_Imm(chan, cmd, 2, EXI_WRITE, NULL);
err |= !EXI_Sync(chan);
err |= !EXI_Imm(chan, &id, 4, EXI_READ, NULL);
err |= !EXI_Sync(chan);
err |= !EXI_Deselect(chan);
EXI_Unlock(chan);

if (err)
return false;
else if (id >> 16 != 0x3842)
return false;
else
return true;
}

void SetMemCardProGameInfo(s32 chan, NIN_CFG* ncfg)
{
u8 cmd[12];

if (!EXI_Lock(chan, EXI_DEVICE_0, NULL)) return;
if (!EXI_Select(chan, EXI_DEVICE_0, EXI_SPEED16MHZ)) {
EXI_Unlock(chan);
return;
}

memset(cmd, 0, sizeof(cmd));
cmd[0] = 0x8B;
cmd[1] = 0x11;

memcpy(&cmd[2], &ncfg->GameID, 4);
memcpy(&cmd[6], &ncfg->GameMakerCode, 2);
cmd[8] = digits[ncfg->GameDiscNumber / 16];
cmd[9] = digits[ncfg->GameDiscNumber % 16];
cmd[10] = digits[ncfg->GameRevision / 16];
cmd[11] = digits[ncfg->GameRevision % 16];

EXI_ImmEx(chan, cmd, sizeof(cmd), EXI_WRITE);
EXI_Deselect(chan);
EXI_Unlock(chan);
}
9 changes: 9 additions & 0 deletions loader/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "FPad.h"
#include "menu.h"
#include "MemCard.h"
#include "MemCardPro.h"
#include "Patches.h"
#include "kernel_zip.h"
#include "kernelboot_bin.h"
Expand Down Expand Up @@ -1121,6 +1122,14 @@ int main(int argc, char **argv)
sram->lang = ncfg->Language;
__SYS_UnlockSram(1); // 1 -> write changes
while(!__SYS_SyncSram());

// Send game ID to MemCard Pro GC
s32 chan;
for ( chan = 0; chan < 2; chan++) {
if (CheckForMemCardPro(chan)) {
SetMemCardProGameInfo(chan, ncfg);
}
}
}

//Check if game is Triforce game
Expand Down
8 changes: 8 additions & 0 deletions loader/source/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ static bool IsDiscImageValid(const char *filename, int discNumber, gameinfo *gi)
// Save the revision number.
gi->Revision = buf[0x07];

// Save the maker code.
memcpy(gi->MakerCode, &buf[0x4], 2);

gi->DiscNumber = discNumber;

// Check if this is a multi-game image.
// Reference: https://gbatemp.net/threads/wit-wiimms-iso-tools-gamecube-disc-support.251630/#post-3088119
const bool is_multigame = IsMultiGameDisc((const char*)buf);
Expand Down Expand Up @@ -1843,6 +1848,9 @@ static int SelectGame(void)
strncpy(ncfg->GamePath, StartChar, sizeof(ncfg->GamePath));
ncfg->GamePath[sizeof(ncfg->GamePath)-1] = 0;
memcpy(&(ncfg->GameID), gi[SelectedGame].ID, 4);
memcpy(&(ncfg->GameMakerCode), gi[SelectedGame].MakerCode, 2);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DDRBoxman Before this memcpy of two bytes to GameMakerCode, should the full four bytes of this unsigned int be set to 0 so that the other two bytes aren't random uninitialized bytes?

ncfg->GameMakerCode = 0
memcpy(&(ncfg->GameMakerCode), gi[SelectedGame].MakerCode, 2);

ncfg->GameRevision = gi[SelectedGame].Revision;
ncfg->GameDiscNumber = gi[SelectedGame].DiscNumber;
DCFlushRange((void*)ncfg, sizeof(NIN_CFG));
}
// Free allocated memory in the game list.
Expand Down