WiiFlow_Lite/source/menu/menu_cheat.cpp

313 lines
11 KiB
C++
Raw Normal View History

2012-01-21 21:57:41 +01:00
#include "menu.hpp"
#include "gui/text.hpp"
-updated NIN_CFG_VERSION to 7 for Nintendont argsboot and added triforce arcade option to game settings menu. tested and working. -fixed wii u widescreen option in game config menu. should properly work now. thanks pBullet! -added a fix for coverflow titles display when coverflow has 3 or more rows. for some reason 3 or more rows caused the title to display improperly. -removed **disabled** message from source menu. no need for it - was a stupid idea. if you don't want it to display then remove it from your source menu or don't add it. when a view is disabled in wiiflow_lite.ini then only that view icon is disabled from showing on the main menu screen. -removed titles.ini which wasn't really used except for displaying the return to channel in settings. I googled it and nothing really showed up. it seemed to be the same as custom_titles.ini - it seemed useless. -removed cacheing sourceflow list. the list is never big enuff to worry about cacheing. plus if you add or remove source btns you won't have to reload cache for the changes to take effect. -removed max_source_btns from wiiflow_lite.ini - added code to get highest source menu btn so now source menu can have as many buttons as you like. -removed Manage Languages Menu - restored option to just change wiiflow language. no need for downloading languages and the google link didn't work anyway. when i make a pack all the languages will be included. -added flat cover options for sourceflow and homebrew view. can be turned on/off via their config menu's accessed via 'HOME' btn. -added config menu for homebrew view - press 'HOME' btn while in homebrew view to access it. config menu options are - switch apps partition, adjust coverflow, smallbox on/off, and flat covers on/off. -updated config menu for source menu/flow. options include - sourceflow on/off, adjust coverflow, smallbox on/off, flat covers on/off, and for source menu only - multisource on/off. -added coverflow layouts/versions for individual plugins - which means each plugin can have its own coverflow layout without affecting the others. -set HQ cover to default to ON -made it so coverflow doesn't reload every time you access another menu or change favorites or whatever. -added error messages to game and app launching if any of the bin files needed for launching are missing. previously whenever these errors occurred wiiflow would just exit without the user knowing why. Now the error message should display before exit so the user has an idea what went wrong. had to move cleanup() back some for the errors to show. hopefully that doesn't cause out of mem issues for users with large game collections. -added error messages to game config menu. now all config options will show but if you can't use it then a error shows telling you. such as 'use neek2o' will be available but if you set it to on and neek2o isn't installed then an error message shows. added error msgs for extracting and flashing saves too. -added show_mem=yes/no option to wiiflow_lite.ini under [DEBUG]. manually edit wiiflow_lite.ini to turn it on/off. if set to 'yes' wiiflow will show how much free mem is available on screen. no need to compile wiiflow for this option anymore. -cleaned up some of the boot up code. -starting a random game - just hold 'B' and press '-'. no longer press'B' on config or question mark icon and no need to allow it in wiiflow_lite.ini
2016-11-07 16:06:00 +01:00
#include "lockMutex.hpp"
#include "network/http.h"
2012-01-21 21:57:41 +01:00
//#define GECKOURL "http://geckocodes.org/codes/%c/%s.txt"
#define GECKOURL "http://geckocodes.org/txt.php?txt=%s"
2012-01-21 21:57:41 +01:00
#define CHEATSPERPAGE 4
u8 m_cheatSettingsPage = 0;
int CMenu::_downloadCheatFileAsync()
2012-01-21 21:57:41 +01:00
{
m_thrdTotal = 2;// download and save
m_thrdMessage = _t("dlmsg1", L"Initializing network...");
m_thrdMessageAdded = true;
if(_initNetwork() < 0)
2012-01-21 21:57:41 +01:00
{
return -2;
2012-01-21 21:57:41 +01:00
}
const char *id = CoverFlow.getId();
//char type = id[0] == 'S' ? 'R' : id[0];
2012-01-21 21:57:41 +01:00
block cheatfile = downloadfile(fmt(GECKOURL, id));
2012-01-21 21:57:41 +01:00
if(cheatfile.data != NULL && cheatfile.size > 65 && cheatfile.data[0] != '<')
2012-01-21 21:57:41 +01:00
{
update_pThread(1);//its downloaded
fsop_WriteFile(fmt("%s/%s.txt", m_txtCheatDir.c_str(), id), cheatfile.data, cheatfile.size);
if(cheatfile.data != NULL)
free(cheatfile.data);
return 0;
2012-01-21 21:57:41 +01:00
}
if(cheatfile.data != NULL)
free(cheatfile.data);
return -3;// download failed
2012-01-21 21:57:41 +01:00
}
void CMenu::_CheatSettings()
{
SetupInput();
const char *id = CoverFlow.getId();
2012-01-21 21:57:41 +01:00
m_cheatSettingsPage = 1;
int txtavailable = m_cheatfile.openTxtfile(fmt("%s/%s.txt", m_txtCheatDir.c_str(), id));
2012-01-21 21:57:41 +01:00
_showCheatSettings();
_textCheatSettings();
if (txtavailable)
m_btnMgr.setText(m_cheatLblTitle, m_cheatfile.getGameName());
2012-01-21 21:57:41 +01:00
else
m_btnMgr.setText(m_cheatLblTitle, L"");
2012-01-21 21:57:41 +01:00
2012-09-09 20:35:15 +02:00
while(!m_exit)
2012-01-21 21:57:41 +01:00
{
_mainLoopCommon();
2012-09-09 20:35:15 +02:00
if(BTN_HOME_PRESSED || BTN_B_PRESSED)
2012-01-21 21:57:41 +01:00
break;
else if (BTN_UP_PRESSED)
m_btnMgr.up();
else if (BTN_DOWN_PRESSED)
m_btnMgr.down();
else if (txtavailable && (BTN_MINUS_PRESSED || BTN_LEFT_PRESSED || (BTN_A_PRESSED && m_btnMgr.selected(m_cheatBtnPageM))))
{
_hideCheatSettings();
if (m_cheatSettingsPage == 1)
m_cheatSettingsPage = (m_cheatfile.getCnt()+CHEATSPERPAGE-1)/CHEATSPERPAGE;
else if (m_cheatSettingsPage > 1)
--m_cheatSettingsPage;
if(BTN_LEFT_PRESSED || BTN_MINUS_PRESSED) m_btnMgr.click(m_cheatBtnPageM);
_showCheatSettings();
}
else if (txtavailable && (BTN_PLUS_PRESSED || BTN_RIGHT_PRESSED || (BTN_A_PRESSED && m_btnMgr.selected(m_cheatBtnPageP))))
{
_hideCheatSettings();
if (m_cheatSettingsPage == (m_cheatfile.getCnt()+CHEATSPERPAGE-1)/CHEATSPERPAGE)
m_cheatSettingsPage = 1;
else if (m_cheatSettingsPage < (m_cheatfile.getCnt()+CHEATSPERPAGE-1)/CHEATSPERPAGE)
++m_cheatSettingsPage;
if(BTN_RIGHT_PRESSED || BTN_PLUS_PRESSED) m_btnMgr.click(m_cheatBtnPageP);
_showCheatSettings();
}
else if ((WBTN_2_HELD && WBTN_1_PRESSED) || (WBTN_1_HELD && WBTN_2_PRESSED))
{
fsop_deleteFile(fmt("%s/%s.gct", m_cheatDir.c_str(), id));
fsop_deleteFile(fmt("%s/%s.txt", m_txtCheatDir.c_str(), id));
m_gcfg2.remove(id, "cheat");
m_gcfg2.remove(id, "hooktype");
2012-01-21 21:57:41 +01:00
break;
}
else if (BTN_A_PRESSED)
{
if (m_btnMgr.selected(m_cheatBtnBack))
break;
for (int i = 0; i < CHEATSPERPAGE; ++i)
if (m_btnMgr.selected(m_cheatBtnItem[i]))
{
// handling code for clicked cheat
m_cheatfile.sCheatSelected[(m_cheatSettingsPage-1)*CHEATSPERPAGE + i] = !m_cheatfile.sCheatSelected[(m_cheatSettingsPage-1)*CHEATSPERPAGE + i];
_showCheatSettings();
}
if (m_btnMgr.selected(m_cheatBtnApply))
{
bool selected = false;
//checks if at least one cheat is selected
for (unsigned int i=0; i < m_cheatfile.getCnt(); ++i)
{
if (m_cheatfile.sCheatSelected[i] == true)
{
selected = true;
break;
}
}
if (selected)
{
m_cheatfile.createGCT(fmt("%s/%s.gct", m_cheatDir.c_str(), id));
m_gcfg2.setOptBool(id, "cheat", 1);
m_gcfg2.setInt(id, "hooktype", m_gcfg2.getInt(id, "hooktype", 1));
2012-01-21 21:57:41 +01:00
}
else
{
fsop_deleteFile(fmt("%s/%s.gct", m_cheatDir.c_str(), id));
m_gcfg2.remove(id, "cheat");
m_gcfg2.remove(id, "hooktype");
2012-01-21 21:57:41 +01:00
}
m_cheatfile.createTXT(fmt("%s/%s.txt", m_txtCheatDir.c_str(), id));
2012-01-21 21:57:41 +01:00
break;
}
else if (m_btnMgr.selected(m_cheatBtnDownload))
{
_hideCheatSettings();
bool dl_finished = false;
while(!m_exit)
2012-01-21 21:57:41 +01:00
{
2012-09-09 20:35:15 +02:00
_mainLoopCommon();
if((BTN_HOME_PRESSED || BTN_B_PRESSED) && dl_finished)
2012-01-21 21:57:41 +01:00
{
m_btnMgr.hide(m_wbfsPBar);
m_btnMgr.hide(m_wbfsLblMessage);
m_btnMgr.hide(m_wbfsLblDialog);
break;
2012-01-21 21:57:41 +01:00
}
if(!dl_finished)
2012-01-21 21:57:41 +01:00
{
m_btnMgr.setProgress(m_wbfsPBar, 0.f, true);
m_btnMgr.setText(m_wbfsLblMessage, L"0%");
m_btnMgr.setText(m_wbfsLblDialog, L"");
m_btnMgr.show(m_wbfsPBar);
m_btnMgr.show(m_wbfsLblMessage);
m_btnMgr.show(m_wbfsLblDialog);
_start_pThread();
int ret = _downloadCheatFileAsync();
_stop_pThread();
if(ret == -1)
m_btnMgr.setText(m_wbfsLblDialog, _t("dlmsg27", L"Not enough memory!"));
else if(ret == -2)
m_btnMgr.setText(m_wbfsLblDialog, _t("dlmsg2", L"Network initialization failed!"));
else if(ret == -3)
m_btnMgr.setText(m_wbfsLblDialog, _t("dlmsg12", L"Download failed!"));
else
m_btnMgr.setText(m_wbfsLblDialog, _t("dlmsg14", L"Done."));
dl_finished = true;
2012-01-21 21:57:41 +01:00
}
}
txtavailable = m_cheatfile.openTxtfile(fmt("%s/%s.txt", m_txtCheatDir.c_str(), id));
2012-01-21 21:57:41 +01:00
_showCheatSettings();
if(txtavailable)
m_btnMgr.setText(m_cheatLblTitle, m_cheatfile.getGameName());
2012-01-21 21:57:41 +01:00
else
m_btnMgr.setText(m_cheatLblTitle, L"");
2012-01-21 21:57:41 +01:00
if (m_cheatfile.getCnt() == 0)
{
// cheat code not found, show result
//char type = id[0] == 'S' ? 'R' : id[0];
2012-01-21 21:57:41 +01:00
m_btnMgr.setText(m_cheatLblItem[0], _t("cheat4", L"Download not found."));
m_btnMgr.setText(m_cheatLblItem[1], sfmt(GECKOURL, id));
2012-01-21 21:57:41 +01:00
m_btnMgr.show(m_cheatLblItem[1]);
}
}
}
}
_hideCheatSettings();
}
void CMenu::_hideCheatSettings(bool instant)
{
m_btnMgr.hide(m_cheatBtnBack, instant);
m_btnMgr.hide(m_cheatBtnApply, instant);
m_btnMgr.hide(m_cheatBtnDownload, instant);
m_btnMgr.hide(m_cheatLblTitle, instant);
m_btnMgr.hide(m_cheatLblPage, instant);
m_btnMgr.hide(m_cheatBtnPageM, instant);
m_btnMgr.hide(m_cheatBtnPageP, instant);
for (int i=0;i<CHEATSPERPAGE;++i) {
m_btnMgr.hide(m_cheatBtnItem[i], instant);
m_btnMgr.hide(m_cheatLblItem[i], instant);
}
for(u8 i = 0; i < ARRAY_SIZE(m_cheatLblUser); ++i)
if(m_cheatLblUser[i] != -1)
2012-01-21 21:57:41 +01:00
m_btnMgr.hide(m_cheatLblUser[i], instant);
}
void CMenu::_showCheatSettings(void)
{
_setBg(m_cheatBg, m_cheatBg);
m_btnMgr.show(m_cheatBtnBack);
m_btnMgr.show(m_cheatLblTitle);
for(u8 i = 0; i < ARRAY_SIZE(m_cheatLblUser); ++i)
if(m_cheatLblUser[i] != -1)
2012-01-21 21:57:41 +01:00
m_btnMgr.show(m_cheatLblUser[i]);
if (m_cheatfile.getCnt() > 0)
{
// cheat found, show apply
m_btnMgr.show(m_cheatBtnApply);
m_btnMgr.show(m_cheatLblPage);
m_btnMgr.show(m_cheatBtnPageM);
m_btnMgr.show(m_cheatBtnPageP);
m_btnMgr.setText(m_cheatLblPage, wfmt(L"%i / %i", m_cheatSettingsPage, (m_cheatfile.getCnt()+CHEATSPERPAGE-1)/CHEATSPERPAGE));
// Show cheats if available, else hide
for (u32 i=0; i < CHEATSPERPAGE; ++i)
{
// cheat in range?
if (((m_cheatSettingsPage-1)*CHEATSPERPAGE + i + 1) <= m_cheatfile.getCnt())
{
wstringEx chtName;
chtName.fromUTF8(m_cheatfile.getCheatName((m_cheatSettingsPage-1)*CHEATSPERPAGE + i));
m_btnMgr.setText(m_cheatLblItem[i], chtName);
2012-01-21 21:57:41 +01:00
m_btnMgr.setText(m_cheatBtnItem[i], _optBoolToString(m_cheatfile.sCheatSelected[(m_cheatSettingsPage-1)*CHEATSPERPAGE + i]));
m_btnMgr.show(m_cheatLblItem[i], true);
m_btnMgr.show(m_cheatBtnItem[i], true);
}
else
{
// cheat out of range, hide elements
m_btnMgr.hide(m_cheatLblItem[i], true);
m_btnMgr.hide(m_cheatBtnItem[i], true);
}
}
}
else
{
// no cheat found, allow downloading
m_btnMgr.show(m_cheatBtnDownload);
m_btnMgr.setText(m_cheatLblItem[0], _t("cheat3", L"Cheat file for game not found."));
m_btnMgr.show(m_cheatLblItem[0]);
}
}
void CMenu::_initCheatSettingsMenu()
2012-01-21 21:57:41 +01:00
{
_addUserLabels(m_cheatLblUser, ARRAY_SIZE(m_cheatLblUser), "CHEAT");
m_cheatBg = _texture("CHEAT/BG", "texture", theme.bg, false);
m_cheatLblTitle = _addTitle("CHEAT/TITLE", theme.titleFont, L"Cheats", 0, 10, 640, 60, theme.titleFontColor, FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE);
m_cheatBtnBack = _addButton("CHEAT/BACK_BTN", theme.btnFont, L"", 420, 400, 200, 48, theme.btnFontColor);
m_cheatBtnApply = _addButton("CHEAT/APPLY_BTN", theme.btnFont, L"", 220, 400, 200, 48, theme.btnFontColor);
m_cheatBtnDownload = _addButton("CHEAT/DOWNLOAD_BTN", theme.btnFont, L"", 470, 130, 150, 48, theme.btnFontColor);
2012-01-21 21:57:41 +01:00
m_cheatLblPage = _addLabel("CHEAT/PAGE_BTN", theme.btnFont, L"", 68, 400, 104, 48, theme.btnFontColor, FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE, theme.btnTexC);
m_cheatBtnPageM = _addPicButton("CHEAT/PAGE_MINUS", theme.btnTexMinus, theme.btnTexMinusS, 20, 400, 48, 48);
m_cheatBtnPageP = _addPicButton("CHEAT/PAGE_PLUS", theme.btnTexPlus, theme.btnTexPlusS, 172, 400, 48, 48);
2012-01-21 21:57:41 +01:00
m_cheatLblItem[0] = _addLabel("CHEAT/ITEM_0", theme.lblFont, L"", 20, 125, 460, 56, theme.lblFontColor, FTGX_JUSTIFY_LEFT | FTGX_ALIGN_MIDDLE);
m_cheatBtnItem[0] = _addButton("CHEAT/ITEM_0_BTN", theme.btnFont, L"", 500, 130, 120, 48, theme.btnFontColor);
m_cheatLblItem[1] = _addLabel("CHEAT/ITEM_1", theme.lblFont, L"", 20, 185, 460, 56, theme.lblFontColor, FTGX_JUSTIFY_LEFT | FTGX_ALIGN_MIDDLE);
m_cheatBtnItem[1] = _addButton("CHEAT/ITEM_1_BTN", theme.btnFont, L"", 500, 190, 120, 48, theme.btnFontColor);
m_cheatLblItem[2] = _addLabel("CHEAT/ITEM_2", theme.lblFont, L"", 20, 245, 460, 56, theme.lblFontColor, FTGX_JUSTIFY_LEFT | FTGX_ALIGN_MIDDLE);
m_cheatBtnItem[2] = _addButton("CHEAT/ITEM_2_BTN", theme.btnFont, L"", 500, 250, 120, 48, theme.btnFontColor);
m_cheatLblItem[3] = _addLabel("CHEAT/ITEM_3", theme.lblFont, L"", 20, 305, 460, 56, theme.lblFontColor, FTGX_JUSTIFY_LEFT | FTGX_ALIGN_MIDDLE);
m_cheatBtnItem[3] = _addButton("CHEAT/ITEM_3_BTN", theme.btnFont, L"", 500, 305, 120, 48, theme.btnFontColor);
2012-01-21 21:57:41 +01:00
_setHideAnim(m_cheatLblTitle, "CHEAT/TITLE", 0, 0, -2.f, 0.f);
_setHideAnim(m_cheatBtnApply, "CHEAT/APPLY_BTN", 0, 0, 1.f, -1.f);
_setHideAnim(m_cheatBtnBack, "CHEAT/BACK_BTN", 0, 0, 1.f, -1.f);
_setHideAnim(m_cheatBtnDownload, "CHEAT/DOWNLOAD_BTN", -50, 0, 1.f, 0.f);
_setHideAnim(m_cheatLblPage, "CHEAT/PAGE_BTN", 0, 0, 1.f, -1.f);
_setHideAnim(m_cheatBtnPageM, "CHEAT/PAGE_MINUS", 0, 0, 1.f, -1.f);
_setHideAnim(m_cheatBtnPageP, "CHEAT/PAGE_PLUS", 0, 0, 1.f, -1.f);
2012-01-21 21:57:41 +01:00
for (int i=0;i<CHEATSPERPAGE;++i) {
_setHideAnim(m_cheatLblItem[i], fmt("CHEAT/ITEM_%i", i), 50, 0, -2.f, 0.f);
_setHideAnim(m_cheatBtnItem[i], fmt("CHEAT/ITEM_%i_BTN", i), -50, 0, 1.f, 0.f);
2012-01-21 21:57:41 +01:00
}
_hideCheatSettings();
_textCheatSettings();
}
void CMenu::_textCheatSettings(void)
{
m_btnMgr.setText(m_cheatBtnBack, _t("cheat1", L"Back"));
m_btnMgr.setText(m_cheatBtnApply, _t("cheat2", L"Apply"));
m_btnMgr.setText(m_cheatBtnDownload, _t("cfg4", L"Download"));
}