summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurice <maurice.henke@protonmail.com>2021-04-25 23:36:51 +0200
committerMaurice <maurice.henke@protonmail.com>2021-04-25 23:36:51 +0200
commit5077687ded45a7685236ee4123a7b43cd176ebe2 (patch)
tree3282c69cde6bfffecd2553fb96007020d75f04e3
parent5ac605c33c9cd893f39d6f45fd3d368b60195521 (diff)
SeedSelector class
-rw-r--r--GameCube/include/rando/seedselector.h40
-rw-r--r--GameCube/source/rando/seedselector.cpp102
2 files changed, 142 insertions, 0 deletions
diff --git a/GameCube/include/rando/seedselector.h b/GameCube/include/rando/seedselector.h
new file mode 100644
index 0000000..da340ad
--- /dev/null
+++ b/GameCube/include/rando/seedselector.h
@@ -0,0 +1,40 @@
+/** @file seedselector.h
+ * @brief Selection tool to select the desired data-gci
+ *
+ * @author AECX
+ * @bug No known bugs.
+ */
+#ifndef RANDO_SELECTOR_H
+#define RANDO_SELECTOR_H
+#include <cinttypes>
+
+#include "rando/seed.h"
+#include "rando/seedselector.h"
+
+#define SEED_MAX_ENTRIES 10
+
+namespace mod::rando
+{
+ class SeedSelector
+ {
+ public:
+ SeedSelector( void );
+ ~SeedSelector( void );
+
+ /**
+ * @brief Button Input handler
+ *
+ * @param buttonInput The buttons to be parsed
+ * @return True if the input was relevant
+ */
+ bool HandleInputs( uint32_t buttonInput );
+
+ uint8_t m_selectedSeed;
+ char* m_StatusText;
+
+ private:
+ gci::data::Header* m_Headers = new gci::data::Header[SEED_MAX_ENTRIES];
+ uint8_t m_totalSeeds;
+ };
+} // namespace mod::rando
+#endif \ No newline at end of file
diff --git a/GameCube/source/rando/seedselector.cpp b/GameCube/source/rando/seedselector.cpp
new file mode 100644
index 0000000..7c35540
--- /dev/null
+++ b/GameCube/source/rando/seedselector.cpp
@@ -0,0 +1,102 @@
+/** @file seedselector.cpp
+ * @brief Selection tool to select the desired data-gci
+ *
+ * @author AECX
+ * @bug No known bugs.
+ */
+#include "rando/seedselector.h"
+
+#include <gc/card.h>
+
+#include <cinttypes>
+#include <cstdio>
+#include <cstring>
+
+#include "gci/data.h"
+#include "main.h"
+#include "rando/seed.h"
+#include "tools.h"
+#include "tp/m_do_controller_pad.h"
+namespace mod::rando
+{
+ SeedSelector::SeedSelector()
+ {
+ using namespace libtp;
+ m_StatusText = new char[50];
+
+ // Loop through possible seed-data-gcis until we don't read anything
+ char filename[12] = "rando-data\0";
+ uint8_t i = 0;
+ do
+ {
+ // Check next filename depending on i
+ // rando-data0, rando-data1, ...
+ filename[10] = static_cast<char>( '0' + i );
+
+ if ( CARD_RESULT_READY ==
+ tools::ReadGCI( 0, const_cast<char*>( filename ), sizeof( gci::data::Header ), 0, &m_Headers[i] ) )
+ {
+ i++;
+ }
+ else
+ {
+ break;
+ }
+
+ *mod::console << "SS: Checking for GCI: " << filename << "\n";
+
+ } while ( i < SEED_MAX_ENTRIES );
+
+ m_totalSeeds = i;
+
+ // If we have seeds we initialise the default seed to be 1; 0 (default) if there is no seeds
+ m_selectedSeed = ( i > 0 ? 1 : 0 );
+ }
+
+ SeedSelector::~SeedSelector() { delete[] m_Headers; }
+
+ bool SeedSelector::HandleInputs( uint32_t buttonInput )
+ {
+ using namespace mod::gci;
+ using namespace libtp::tp::m_do_controller_pad;
+ using namespace libtp;
+
+ bool status = false;
+
+ if ( m_selectedSeed > 0 )
+ {
+ if ( ( buttonInput & PadInputs::Button_A ) == PadInputs::Button_A )
+ {
+ // Increase seed or reset to 1
+ m_selectedSeed = m_selectedSeed == m_totalSeeds ? 1 : m_selectedSeed + 1;
+ status = true;
+ }
+
+ if ( ( buttonInput & PadInputs::Button_B ) == PadInputs::Button_B )
+ {
+ // Decrease seed or reset to m_totalSeeds
+ m_selectedSeed = m_selectedSeed == 1 ? m_totalSeeds : m_selectedSeed - 1;
+ status = true;
+ }
+
+ // Read in the seed from our previously cached headers (constructor)
+ uint64_t seed = m_Headers[( m_selectedSeed - 1 )].seed;
+ snprintf( m_StatusText,
+ 50,
+ "SS:: %" PRIu8 "/%" PRIu8 " - %04" PRIX32 "%04" PRIX32,
+ m_selectedSeed,
+ m_totalSeeds,
+ static_cast<uint32_t>( seed ),
+ static_cast<uint32_t>( seed >> 32 ) );
+ }
+ else
+ {
+ // Selected seed = 0; no seeds available
+ strncpy( m_StatusText, "SS:: No seeds in Slot A or read error", 50 );
+ status = true;
+ }
+
+ return status;
+ }
+
+} // namespace mod::rando \ No newline at end of file