usbloadergx/source/cheats/cheatmenu.cpp
Cyan fa4b1d162b * Fixed missing games in "GameCube Delete menu" if
the "GameCube Source" setting has USB priority.
* Fixed Playlog writing when using Hermes cIOS v4 (untested)
  (Requires AHB access).
* Fixed EmuNAND when using cIOS revision 65535 (issue 2225)
* Added Nintendont support:
  1. Select Nintendont's boot.dol folder in userpath settings.
  2. Set the "GameCube Mode" setting to Nintendont.
  3. Nintendont share some of DIOS MIOS (Lite) settings.
* Added sections in the Loader settings  
  (Wii/gamecube/Devolution/DIOS MIOS/Nintendont).
* Updated the GameCube game settings to display only 
  the selected GameCube mode related settings.
* Updated some menus to support more controller's input:
   - Prevent GC/CC X and Y buttons to change row number in
     Wall layout (use d-pad up/down only)
   - Added GC/CC support to carousel's arrow button
   - Added GC/CC support to Wall/Carousel continuous 
     scroll (+/- on CC, L/R on GC)
   - Added GC support L/R and Start buttons in the
     settings/homebrew browser.
   - Added D-pad support in listing windows if not pointing 
     the screen. The cursor now moves with the selection 
     (not very good with high Overscan value) (issue 2093)
* Changed the StartupProcess to speed up launch time by 
  using AHB access to read config files. IOS argument in
  meta.xml has priority over AHB detection.
* Added IOS58 + AHB support for launching the loader
  without cIOS (Wii games and EmuNAND still require cIOS).
* Added a Loader's IOS setting (now Loader and Games use 
  two separate settings: loader can use 58 and games 249).
* Added LibruntimeIOSPatch to patch IOS58 and Hermes v4 to
  get ISFS access and enable Banner mode, Channel's title
  and System font with these IOSes (Requires AHB access)
* Added a delete prompt if downloaded cheat file is empty.
* Force all launched homebrew to reload to IOS58 if available.
* Changed Gecko.c to send logs to wifigecko too.
* Changed wifigecko IP to send logs to all IP 192.168.0.x
* Updated French translation.
2013-10-01 21:13:08 +00:00

217 lines
6.5 KiB
C++

#include <string.h>
#include <unistd.h>
#include "GUI/gui.h"
#include "GUI/gui_optionbrowser.h"
#include "prompts/PromptWindows.h"
#include "language/gettext.h"
#include "themes/CTheme.h"
#include "FileOperations/fileops.h"
#include "menu.h"
#include "sys.h"
#include "gct.h"
/****************************************************************************
* CheatMenu
***************************************************************************/
int CheatMenu(const char * gameID)
{
int choice = 0;
bool exit = false;
int ret = 1;
GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png"));
GuiImageData settingsbg(Resources::GetFile("settings_background.png"), Resources::GetFileSize("settings_background.png"));
GuiImage settingsbackground(&settingsbg);
GuiTrigger trigA;
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
GuiTrigger trigB;
trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B);
GuiText backBtnTxt(tr( "Back" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows button text color"));
backBtnTxt.SetMaxWidth(btnOutline.GetWidth() - 30);
GuiImage backBtnImg(&btnOutline);
GuiButton backBtn(&backBtnImg, &backBtnImg, 2, 3, -195, 400, &trigA, NULL, btnSoundClick2, 1);
backBtn.SetLabel(&backBtnTxt);
backBtn.SetTrigger(&trigB);
GuiText updateBtnTxt(tr( "Update" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows button text color"));
updateBtnTxt.SetMaxWidth(btnOutline.GetWidth() - 30);
GuiImage updateBtnImg(&btnOutline);
GuiButton updateBtn(&updateBtnImg, &updateBtnImg, 2, 3, 0, 400, &trigA, NULL, btnSoundClick2, 1);
updateBtn.SetLabel(&updateBtnTxt);
GuiText createBtnTxt(tr( "Create" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows button text color"));
createBtnTxt.SetMaxWidth(btnOutline.GetWidth() - 30);
GuiImage createBtnImg(&btnOutline);
GuiButton createBtn(&createBtnImg, &createBtnImg, 2, 3, 195, 400, &trigA, NULL, btnSoundClick2, 1);
createBtn.SetLabel(&createBtnTxt);
char txtfilename[55];
snprintf(txtfilename, sizeof(txtfilename), "%s%s.txt", Settings.TxtCheatcodespath, gameID);
GCTCheats gctCheats;
int check = gctCheats.openTxtfile(txtfilename);
int download = 0;
int blankchoice = 0;
switch (check)
{
case -1:
blankchoice = WindowPrompt(tr( "Error" ), tr( "Cheatfile is blank" ), tr( "Delete" ), tr( "OK" ));
if(blankchoice)
{
char gctPath[200];
snprintf(gctPath, sizeof(gctPath), "%s%.6s.TXT", Settings.TxtCheatcodespath, gameID);
RemoveFile(gctPath);
}
break;
case 0:
download = WindowPrompt(tr( "Error" ), tr( "No Cheatfile found" ), tr( "Download Now" ), tr( "Cancel" ));
if (download == 1)
{
download = CodeDownload(gameID);
if (download < 0 || gctCheats.openTxtfile(txtfilename) != 1)
break;
}
else
break;
case 1:
int cntcheats = gctCheats.getCnt();
OptionList cheatslst;
GuiOptionBrowser chtBrowser(400, 280, &cheatslst, "bg_options_settings.png");
chtBrowser.SetPosition(0, 90);
chtBrowser.SetAlignment(ALIGN_CENTER, ALIGN_TOP);
chtBrowser.SetClickable(true);
GuiText titleTxt(gctCheats.getGameName().c_str(), 28, ( GXColor ) {0, 0, 0, 255});
titleTxt.SetAlignment(ALIGN_CENTER, ALIGN_TOP);
titleTxt.SetMaxWidth(350, SCROLL_HORIZONTAL);
titleTxt.SetPosition(12, 40);
char gctPath[200];
snprintf(gctPath, sizeof(gctPath), "%s%.6s.gct", Settings.Cheatcodespath, gameID);
u8 *gctBuf = NULL;
u32 gctSize = 0;
LoadFileToMem(gctPath, &gctBuf, &gctSize);
for (int i = 0; i < cntcheats; i++)
{
cheatslst.SetValue(i, "%s", gctCheats.getCheatName(i).c_str());
// search after header and before footer
if(gctBuf && gctCheats.IsCheatIncluded(i, gctBuf, gctSize))
cheatslst.SetName(i, tr("ON"));
else
cheatslst.SetName(i, tr("OFF"));
}
HaltGui();
GuiWindow w(screenwidth, screenheight);
w.Append(&settingsbackground);
w.Append(&titleTxt);
w.Append(&backBtn);
w.Append(&updateBtn);
w.Append(&createBtn);
w.Append(&chtBrowser);
mainWindow->SetState(STATE_DISABLED);
mainWindow->Append(&w);
ResumeGui();
while (!exit)
{
usleep(100000);
ret = chtBrowser.GetClickedOption();
if (ret >= 0)
{
const char *strCheck = cheatslst.GetName(ret);
if (strCheck && strcmp(strCheck, tr("ON")) == 0)
{
cheatslst.SetName(ret, "%s", tr("OFF"));
}
else if (strCheck && strcmp(strCheck, tr("OFF")) == 0)
{
cheatslst.SetName(ret, "%s", tr("ON"));
}
}
if (createBtn.GetState() == STATE_CLICKED)
{
if (cntcheats > 0)
{
vector<int> vActiveCheats;
for (int i = 0; i < cntcheats; i++)
{
const char *strCheck = cheatslst.GetName(i);
if (strCheck && strcmp(strCheck, tr("ON")) == 0)
vActiveCheats.push_back(i);
}
if (vActiveCheats.size() == 0)
{
if(WindowPrompt(tr( "Error" ), tr( "No cheats were selected! Should the GCT file be deleted?" ), tr("Yes"), tr("Cancel")))
{
RemoveFile(gctPath);
w.Remove(&chtBrowser);
for (int i = 0; i < gctCheats.getCnt(); i++)
cheatslst.SetName(i, tr("OFF"));
w.Append(&chtBrowser);
}
}
else
{
CreateSubfolder(Settings.Cheatcodespath);
gctCheats.createGCT(vActiveCheats, gctPath);
WindowPrompt(tr( "GCT File created" ), NULL, tr( "OK" ));
}
}
else
WindowPrompt(tr( "Error" ), tr( "Could not create GCT file" ), tr( "OK" ));
mainWindow->SetState(STATE_DISABLED);
w.SetState(STATE_DEFAULT);
createBtn.ResetState();
}
if (backBtn.GetState() == STATE_CLICKED)
{
backBtn.ResetState();
exit = true;
break;
}
if(updateBtn.GetState() == STATE_CLICKED)
{
download = CodeDownload(gameID);
if (download >= 0 && gctCheats.openTxtfile(txtfilename) == 1)
{
w.Remove(&chtBrowser);
cheatslst.ClearList();
cntcheats = gctCheats.getCnt();
for (int i = 0; i < cntcheats; i++)
{
cheatslst.SetValue(i, "%s", gctCheats.getCheatName(i).c_str());
// search after header and before footer
if(gctBuf && gctCheats.IsCheatIncluded(i, gctBuf, gctSize))
cheatslst.SetName(i, tr("ON"));
else
cheatslst.SetName(i, tr("OFF"));
}
w.Append(&chtBrowser);
}
updateBtn.ResetState();
}
}
if(gctBuf)
free(gctBuf);
HaltGui();
mainWindow->SetState(STATE_DEFAULT);
mainWindow->Remove(&w);
ResumeGui();
break;
}
return choice;
}