summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurice <maurice.henke@protonmail.com>2021-07-04 18:59:23 +0200
committerMaurice <maurice.henke@protonmail.com>2021-07-04 18:59:23 +0200
commit66cde1088cbba816e01aba46a615574726b7a41c (patch)
treef67a72a266445d5e62d144f978fbb2037f90f188
parent3993d6385fec4fd09d889dbbb88efe3e445d3205 (diff)
Renamed & Recoded the SeedSelector into a SeedList
-rw-r--r--GameCube/include/rando/seedlist.h45
-rw-r--r--GameCube/include/rando/seedselector.h40
-rw-r--r--GameCube/source/rando/seedlist.cpp95
-rw-r--r--GameCube/source/rando/seedselector.cpp102
4 files changed, 140 insertions, 142 deletions
diff --git a/GameCube/include/rando/seedlist.h b/GameCube/include/rando/seedlist.h
new file mode 100644
index 00000000..9eb06205
--- /dev/null
+++ b/GameCube/include/rando/seedlist.h
@@ -0,0 +1,45 @@
+/** @file seedselector.h
+ * @brief Selection tool to select the desired data-gci
+ *
+ * @author AECX
+ * @bug No known bugs.
+ */
+#ifndef RANDO_SEEDLIST_H
+#define RANDO_SEEDLIST_H
+#include <cinttypes>
+
+#include "rando/seed.h"
+#include "rando/seedlist.h"
+
+#define SEED_MAX_ENTRIES 10
+
+namespace mod::rando
+{
+ // Seed with index
+ struct SeedInfo
+ {
+ uint64_t seed;
+ uint8_t fileIndex; // (0-9) rando-dataX
+ };
+
+ class SeedList
+ {
+ public:
+ SeedList( void );
+ ~SeedList( void );
+
+ SeedInfo FindSeed( uint64_t seed );
+
+ SeedInfo operator[]( int n )
+ {
+ // Returning with mod guarantees for read access within numSeeds
+ return static_cast<SeedInfo>( m_seedInfo[n % m_numSeeds] );
+ }
+ int m_numSeeds;
+ int m_selectedSeed;
+
+ private:
+ SeedInfo* m_seedInfo = nullptr;
+ };
+} // namespace mod::rando
+#endif \ No newline at end of file
diff --git a/GameCube/include/rando/seedselector.h b/GameCube/include/rando/seedselector.h
deleted file mode 100644
index da340add..00000000
--- a/GameCube/include/rando/seedselector.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/** @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/seedlist.cpp b/GameCube/source/rando/seedlist.cpp
new file mode 100644
index 00000000..89d45174
--- /dev/null
+++ b/GameCube/source/rando/seedlist.cpp
@@ -0,0 +1,95 @@
+/** @file seedselector.cpp
+ * @brief Selection tool to select the desired data-gci
+ *
+ * @author AECX
+ * @bug No known bugs.
+ */
+#include "rando/seedlist.h"
+
+#include <gc/card.h>
+
+#include <cinttypes>
+#include <cstdio>
+#include <cstring>
+
+#include "main.h"
+#include "rando/data.h"
+#include "rando/seed.h"
+#include "tools.h"
+#include "tp/JKRExpHeap.h"
+#include "tp/m_do_controller_pad.h"
+#include "tp/m_do_ext.h"
+
+namespace mod::rando
+{
+ SeedList::SeedList()
+ {
+ using namespace libtp;
+
+ // Loop through possible seed-data-gcis until we don't read anything
+ char filename[12] = "rando-data\0";
+
+ // Bitwise representation of the seeds available
+ uint16_t seedIDX = 0;
+ m_numSeeds = 0;
+
+ for ( uint8_t i = 0; i < SEED_MAX_ENTRIES; i++ )
+ {
+ // Check next filename depending on i
+ // rando-data0, rando-data1, ...
+ filename[10] = static_cast<char>( '0' + i );
+
+ Seed tempSeed = Seed( CARD_SLOT_A, filename );
+
+ if ( CARD_RESULT_READY == tempSeed.m_CARDResult )
+ {
+ uint16_t version = static_cast<uint16_t>( _VERSION_MAJOR << 8 | _VERSION_MINOR );
+ if ( tempSeed.m_Header->minVersion >= version )
+ {
+ if ( tempSeed.m_Header->maxVersion <= version )
+ {
+ seedIDX = seedIDX | ( 1 << i );
+ m_numSeeds++;
+ }
+ }
+ }
+ }
+
+ m_seedInfo = new SeedInfo[m_numSeeds];
+
+ uint8_t j = 0; // seedInfo index
+
+ // Loop through all possible seeds and load them into our seedInfo
+ for ( uint8_t i = 0; i < SEED_MAX_ENTRIES; i++ )
+ {
+ if ( ( ( seedIDX >> i ) & 1 ) == 1 )
+ {
+ // Index exists, load seed
+ filename[10] = static_cast<char>( '0' + i );
+
+ Seed tempSeed = Seed( CARD_SLOT_A, filename );
+
+ m_seedInfo[j].seed = tempSeed.m_Header->seed;
+ m_seedInfo[j].fileIndex = i;
+ j++;
+ }
+ }
+ }
+
+ SeedInfo SeedList::FindSeed( uint64_t seed )
+ {
+ for ( uint8_t i = 0; i < SEED_MAX_ENTRIES && i < m_numSeeds; i++ )
+ {
+ if ( m_seedInfo[i].seed == seed )
+ {
+ return static_cast<SeedInfo>( m_seedInfo[i] );
+ }
+ }
+
+ // No seed found; Return one with index FF as error indicator (max is 9)
+ return { 0x00, 0xFF };
+ }
+
+ SeedList::~SeedList() { delete[] m_seedInfo; }
+
+} // namespace mod::rando \ No newline at end of file
diff --git a/GameCube/source/rando/seedselector.cpp b/GameCube/source/rando/seedselector.cpp
deleted file mode 100644
index 7c35540b..00000000
--- a/GameCube/source/rando/seedselector.cpp
+++ /dev/null
@@ -1,102 +0,0 @@
-/** @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