Skip to content
This repository has been archived by the owner on Dec 24, 2018. It is now read-only.

Commit

Permalink
Show SDK version number in per-game settings
Browse files Browse the repository at this point in the history
ALSO: Fix crash if no SDK version is found
ALSO: Fix LED color for GB game setting being saved to a .nds' .ini file instead
  • Loading branch information
RocketRobz committed Jan 25, 2018
1 parent 30a356d commit 33c9063
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 5 deletions.
125 changes: 120 additions & 5 deletions gui/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ const char* musicpath = "romfs:/null.wav";
const char* Lshouldertext = "";
const char* Rshouldertext = "";

const char* SDKnumbertext = "";

int LshoulderYpos = 220;
int RshoulderYpos = 220;

Expand Down Expand Up @@ -1902,6 +1904,10 @@ static void drawMenuDialogBox(void)
}
}
} else {
if(settings.ui.cursorPosition >= 0) {
pp2d_draw_text(162, menudbox_Ypos + 169, 0.50, 0.50, BLACK, SDKnumbertext);
}

for (int i = (int)(sizeof(buttons)/sizeof(buttons[0]))-1; i >= 0; i--) {
if (gamesettings_cursorPosition == i) {
// Button is highlighted.
Expand Down Expand Up @@ -5388,6 +5394,55 @@ int main(){
} else if (hDown & KEY_SELECT) {
// Switch to per-game settings.
menudboxmode = DBOX_MODE_SETTINGS;
if(!settings.twl.forwarder && settings.ui.cursorPosition >= 0 && settings.twl.romtype==0) {
// Get SDK version to show
bool isCia = false;
char path[256];
const char *rom_filename;
if(matching_files.size() == 0){
if (files.size() != 0) {
rom_filename = files.at(settings.ui.cursorPosition).c_str();
} else {
rom_filename = " ";
}
snprintf(path, sizeof(path), "sdmc:/%s/%s", settings.ui.romfolder.c_str(), rom_filename);
} else {
rom_filename = matching_files.at(settings.ui.cursorPosition).c_str();
snprintf(path, sizeof(path), "sdmc:/%s/%s", settings.ui.romfolder.c_str(), rom_filename);
}
std::string fn = rom_filename;
if(fn.substr(fn.find_last_of(".") + 1) == "cia") isCia = true;

if(isCia) {
SDKnumbertext = ""; // Clear number
} else {
FILE *f_nds_file = fopen(path, "rb");
char game_TID[5];
grabTID(f_nds_file, game_TID, false);
game_TID[4] = 0;
game_TID[3] = 0;
u32 SDKVersion = 0;
if(strcmp(game_TID, "###") != 0) {
SDKVersion = getSDKVersion(f_nds_file, rom_filename);
if((SDKVersion > 0x1000000) && (SDKVersion < 0x2000000)) {
SDKnumbertext = "SDK ver: 1";
} else if((SDKVersion > 0x2000000) && (SDKVersion < 0x3000000)) {
SDKnumbertext = "SDK ver: 2";
} else if((SDKVersion > 0x3000000) && (SDKVersion < 0x4000000)) {
SDKnumbertext = "SDK ver: 3";
} else if((SDKVersion > 0x4000000) && (SDKVersion < 0x5000000)) {
SDKnumbertext = "SDK ver: 4";
} else if((SDKVersion > 0x5000000) && (SDKVersion < 0x6000000)) {
SDKnumbertext = "SDK ver: 5 (TWLSDK)";
} else {
SDKnumbertext = "SDK ver: ?";
}
} else {
SDKnumbertext = ""; // Clear number
}
fclose(f_nds_file);
}
}
if (!showdialogbox_menu) {
if (settings.ui.cursorPosition >= 0 && showbubble && menudbox_Ypos == -240) {
if (settings.twl.forwarder) {
Expand Down Expand Up @@ -5635,6 +5690,55 @@ int main(){
if (settings.ui.cursorPosition >= 0 && showbubble) {
// Switch to game-specific settings.
menudboxmode = DBOX_MODE_SETTINGS;
bool isCia = false;
if(!settings.twl.forwarder && settings.ui.cursorPosition >= 0 && settings.twl.romtype==0) {
// Get SDK version to show
char path[256];
const char *rom_filename;
if(matching_files.size() == 0){
if (files.size() != 0) {
rom_filename = files.at(settings.ui.cursorPosition).c_str();
} else {
rom_filename = " ";
}
snprintf(path, sizeof(path), "sdmc:/%s/%s", settings.ui.romfolder.c_str(), rom_filename);
} else {
rom_filename = matching_files.at(settings.ui.cursorPosition).c_str();
snprintf(path, sizeof(path), "sdmc:/%s/%s", settings.ui.romfolder.c_str(), rom_filename);
}
std::string fn = rom_filename;
if(fn.substr(fn.find_last_of(".") + 1) == "cia") isCia = true;

if(isCia) {
SDKnumbertext = ""; // Clear number
} else {
FILE *f_nds_file = fopen(path, "rb");
char game_TID[5];
grabTID(f_nds_file, game_TID, false);
game_TID[4] = 0;
game_TID[3] = 0;
u32 SDKVersion = 0;
if(strcmp(game_TID, "###") != 0) {
SDKVersion = getSDKVersion(f_nds_file, rom_filename);
if((SDKVersion > 0x1000000) && (SDKVersion < 0x2000000)) {
SDKnumbertext = "SDK ver: 1";
} else if((SDKVersion > 0x2000000) && (SDKVersion < 0x3000000)) {
SDKnumbertext = "SDK ver: 2";
} else if((SDKVersion > 0x3000000) && (SDKVersion < 0x4000000)) {
SDKnumbertext = "SDK ver: 3";
} else if((SDKVersion > 0x4000000) && (SDKVersion < 0x5000000)) {
SDKnumbertext = "SDK ver: 4";
} else if((SDKVersion > 0x5000000) && (SDKVersion < 0x6000000)) {
SDKnumbertext = "SDK ver: 5 (TWLSDK)";
} else {
SDKnumbertext = "SDK ver: ?";
}
} else {
SDKnumbertext = ""; // Clear number
}
fclose(f_nds_file);
}
}
}
} else if (hDown & KEY_RIGHT) {
if (startmenu_cursorPosition % 2 != 1 &&
Expand Down Expand Up @@ -5990,16 +6094,21 @@ int main(){
if (settings.twl.forwarder) {
if(matching_files.size() == 0){
rom = fcfiles.at(settings.ui.cursorPosition).c_str();
} else {
}else{
rom = matching_files.at(settings.ui.cursorPosition).c_str();
}
} else {
if (matching_files.size() == 0) {
} else if (settings.twl.romtype == 1) {
if(matching_files.size() == 0){
rom = gbfiles.at(settings.ui.cursorPosition).c_str();
}else{
rom = matching_files.at(settings.ui.cursorPosition).c_str();
}
} else if (settings.twl.romtype == 0) {
if(matching_files.size() == 0){
rom = files.at(settings.ui.cursorPosition).c_str();
}else{
rom = matching_files.at(settings.ui.cursorPosition).c_str();
}

}
SavePerGameSettings();
menudboxmode = DBOX_MODE_OPTIONS;
Expand Down Expand Up @@ -6173,7 +6282,13 @@ int main(){
}else{
rom = matching_files.at(settings.ui.cursorPosition).c_str();
}
} else {
} else if (settings.twl.romtype == 1) {
if(matching_files.size() == 0){
rom = gbfiles.at(settings.ui.cursorPosition).c_str();
}else{
rom = matching_files.at(settings.ui.cursorPosition).c_str();
}
} else if (settings.twl.romtype == 0) {
if(matching_files.size() == 0){
rom = files.at(settings.ui.cursorPosition).c_str();
}else{
Expand Down
4 changes: 4 additions & 0 deletions gui/source/ndsheaderbanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ u32 getSDKVersion(FILE* ndsFile, const char* filename) {

// Looking for moduleparams
uint32_t moduleparams = getOffset((u32*)arm9binary, NDSHeader.arm9binarySize, (u32*)moduleParamsSignature, 2, 1);
if(!moduleparams) {
if (logEnabled) LogFM("NDSBannerHeader.getSDKVersion", "No SDK version found");
return 0;
}

if (logEnabled) {
char textSDKver[8];
Expand Down

0 comments on commit 33c9063

Please sign in to comment.