From 67af82ad0cb8ae4cf225d548f4dde0b58a04c8e2 Mon Sep 17 00:00:00 2001 From: InfiniteBlueGX <105176909+InfiniteBlueGX@users.noreply.github.com> Date: Mon, 7 Nov 2022 15:26:28 -0600 Subject: [PATCH] Add support for newer format .cht files and OptionBrowser text scrolling (#1038) * Add support for BML-format .cht files, and OptionBrowser text scrolling * Move BML handling out of cheatmgr.cpp --- source/cheatmgr.cpp | 21 ++++++++++++++++++++- source/gui/gui_optionbrowser.cpp | 6 ++++++ source/snes9x/cheats.h | 2 ++ source/snes9x/cheats2.cpp | 2 +- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/source/cheatmgr.cpp b/source/cheatmgr.cpp index da9da08..a92f20f 100644 --- a/source/cheatmgr.cpp +++ b/source/cheatmgr.cpp @@ -15,6 +15,7 @@ #include "snes9xgx.h" #include "fileop.h" #include "filebrowser.h" +#include "bml.h" #define MAX_CHEATS 150 @@ -91,7 +92,25 @@ WiiSetupCheats() // load cheat file if present if(offset > 0) - LoadCheatFile (offset); + { + bml_node bml; + if (!bml.parse_file(filepath)) + { + LoadCheatFile (offset); + } + + bml_node *n = bml.find_subnode("cheat"); + if (n) + { + S9xLoadCheatsFromBMLNode (&bml); + } + + if (!n) + { + LoadCheatFile (offset); + } + } + FreeSaveBuffer (); } diff --git a/source/gui/gui_optionbrowser.cpp b/source/gui/gui_optionbrowser.cpp index 3674cb2..a02a584 100644 --- a/source/gui/gui_optionbrowser.cpp +++ b/source/gui/gui_optionbrowser.cpp @@ -79,6 +79,7 @@ GuiOptionBrowser::GuiOptionBrowser(int w, int h, OptionList * l) optionTxt[i] = new GuiText(NULL, 20, (GXColor){0, 0, 0, 0xff}); optionTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); optionTxt[i]->SetPosition(8,0); + optionTxt[i]->SetMaxWidth(235); optionVal[i] = new GuiText(NULL, 20, (GXColor){0, 0, 0, 0xff}); optionVal[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); @@ -312,6 +313,11 @@ void GuiOptionBrowser::Update(GuiTrigger * t) if(optionBtn[i]->GetState() == STATE_SELECTED) selectedItem = i; + + if(selectedItem == i) + optionTxt[i]->SetScroll(SCROLL_HORIZONTAL); + else + optionTxt[i]->SetScroll(SCROLL_NONE); } // pad/joystick navigation diff --git a/source/snes9x/cheats.h b/source/snes9x/cheats.h index 7fbabd7..6924140 100644 --- a/source/snes9x/cheats.h +++ b/source/snes9x/cheats.h @@ -8,6 +8,7 @@ #define _CHEATS_H_ #include "port.h" +#include "bml.h" #include struct SCheat @@ -95,6 +96,7 @@ void S9xSearchForChange (SCheatData *, S9xCheatComparisonType, S9xCheatDataSize, void S9xSearchForValue (SCheatData *, S9xCheatComparisonType, S9xCheatDataSize, uint32, bool8, bool8); void S9xSearchForAddress (SCheatData *, S9xCheatComparisonType, S9xCheatDataSize, uint32, bool8); void S9xOutputCheatSearchResults (SCheatData *); +void S9xLoadCheatsFromBMLNode (bml_node *); const char * S9xGameGenieToRaw (const char *, uint32 &, uint8 &); const char * S9xProActionReplayToRaw (const char *, uint32 &, uint8 &); diff --git a/source/snes9x/cheats2.cpp b/source/snes9x/cheats2.cpp index 83a2969..7178144 100644 --- a/source/snes9x/cheats2.cpp +++ b/source/snes9x/cheats2.cpp @@ -558,7 +558,7 @@ static int S9xCheatIsDuplicate (const char *name, const char *code) return FALSE; } -static void S9xLoadCheatsFromBMLNode (bml_node *n) +void S9xLoadCheatsFromBMLNode (bml_node *n) { unsigned int i;