From a15a6128031bb3a3d5d6b60696978d9f60a48e3a Mon Sep 17 00:00:00 2001 From: Extrems Date: Sat, 15 Feb 2025 13:09:59 -0500 Subject: [PATCH] Use device code to determine console type on Wii Fix unintended fallthrough switch statement --- gc/ogc/system.h | 1 + libogc/stm.c | 2 ++ libogc/system.c | 27 +++++++++++++++++++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/gc/ogc/system.h b/gc/ogc/system.h index 3b5a1160..c976452d 100644 --- a/gc/ogc/system.h +++ b/gc/ogc/system.h @@ -121,6 +121,7 @@ distribution. #define SYS_CONSOLE_RETAIL_ES2_1 0x00000021 #define SYS_CONSOLE_RETAIL_ES3_0 0x00000030 #define SYS_CONSOLE_RETAIL_ES3_1 0x00000031 +#define SYS_CONSOLE_ARCADE 0x00000100 #define SYS_CONSOLE_NDEV_ES1_0 0x10000010 #define SYS_CONSOLE_NDEV_ES1_1 0x10000011 #define SYS_CONSOLE_NDEV_ES1_2 0x10000012 diff --git a/libogc/stm.c b/libogc/stm.c index 66b467ac..7992b55a 100644 --- a/libogc/stm.c +++ b/libogc/stm.c @@ -223,8 +223,10 @@ s32 STM_ShutdownToIdle(void) case 1: case 2: __stm_immbufin[0] = 0xFCA08280; + break; default: __stm_immbufin[0] = 0xFCE082C0; + break; } res= IOS_Ioctl(__stm_imm_fd,IOCTL_STM_IDLE,__stm_immbufin,0x20,__stm_immbufout,0x20); if(res<0) { diff --git a/libogc/system.c b/libogc/system.c index 026328e2..2bd9bb9e 100644 --- a/libogc/system.c +++ b/libogc/system.c @@ -2036,8 +2036,31 @@ u32 SYS_GetConsoleType(void) u32 SYS_GetConsoleType(void) { u32 type; - type = SYS_CONSOLE_RETAIL_ES1_0; - type += *((u32*)0x80003138); + u16 dev_code; + + type = 0; + dev_code = *((u16*)0x800030e6); + if(dev_code&0x8000) { + switch(dev_code&~0x8000) { + case 0x0002: + case 0x0003: + case 0x0203: + type = SYS_CONSOLE_RETAIL_ES1_0; + type += *((u32*)0x80003138); + break; + case 0x0201: + case 0x0202: + type = SYS_CONSOLE_NDEV_ES1_0; + type += *((u32*)0x80003138); + break; + case 0x0300: + type = SYS_CONSOLE_ARCADE; + break; + } + } else { + type = SYS_CONSOLE_RETAIL_ES1_0; + type += *((u32*)0x80003138); + } return type; }