Merge pull request #12894 from deReeperJosh/infinity-base-numbers
IOS/USB: Use Enum for Infinity Base Positions
This commit is contained in:
5 files changed
+106
-65
No files matched your search
@@ -594,7 +594,7 @@ static u32 InfinityCRC32(const std::array<u8, 16>& buffer)
|
||||
|
||||
std::string
|
||||
InfinityBase::LoadFigure(const std::array<u8, INFINITY_NUM_BLOCKS * INFINITY_BLOCK_SIZE>& buf,
|
||||
File::IOFile in_file, u8 position)
|
||||
File::IOFile in_file, FigureUIPosition position)
|
||||
{
|
||||
std::lock_guard lock(m_infinity_mutex);
|
||||
u8 order_added;
|
||||
@@ -615,7 +615,7 @@ InfinityBase::LoadFigure(const std::array<u8, INFINITY_NUM_BLOCKS * INFINITY_BLO
|
||||
u32(infinity_decrypted_block[3]);
|
||||
DEBUG_LOG_FMT(IOS_USB, "Toy Number: {}", number);
|
||||
|
||||
InfinityFigure& figure = m_figures[position];
|
||||
InfinityFigure& figure = m_figures[static_cast<u8>(position)];
|
||||
|
||||
figure.inf_file = std::move(in_file);
|
||||
memcpy(figure.data.data(), buf.data(), figure.data.size());
|
||||
@@ -627,24 +627,25 @@ InfinityBase::LoadFigure(const std::array<u8, INFINITY_NUM_BLOCKS * INFINITY_BLO
|
||||
}
|
||||
order_added = figure.order_added;
|
||||
|
||||
position = DeriveFigurePosition(position);
|
||||
if (position == 0)
|
||||
FigureBasePosition derived_position = DeriveFigurePosition(position);
|
||||
if (derived_position == FigureBasePosition::Unknown)
|
||||
{
|
||||
ERROR_LOG_FMT(IOS_USB, "Invalid Position for Infinity Figure");
|
||||
return "Unknown Figure";
|
||||
}
|
||||
|
||||
std::array<u8, 32> figure_change_response = {0xab, 0x04, position, 0x09, order_added, 0x00};
|
||||
std::array<u8, 32> figure_change_response = {0xab, 0x04, static_cast<u8>(derived_position),
|
||||
0x09, order_added, 0x00};
|
||||
figure_change_response[6] = GenerateChecksum(figure_change_response, 6);
|
||||
m_figure_added_removed_response.push(figure_change_response);
|
||||
|
||||
return FindFigure(number);
|
||||
}
|
||||
|
||||
void InfinityBase::RemoveFigure(u8 position)
|
||||
void InfinityBase::RemoveFigure(FigureUIPosition position)
|
||||
{
|
||||
std::lock_guard lock(m_infinity_mutex);
|
||||
InfinityFigure& figure = m_figures[position];
|
||||
InfinityFigure& figure = m_figures[static_cast<u8>(position)];
|
||||
|
||||
if (figure.inf_file.IsOpen())
|
||||
{
|
||||
@@ -654,8 +655,8 @@ void InfinityBase::RemoveFigure(u8 position)
|
||||
|
||||
if (figure.present)
|
||||
{
|
||||
position = DeriveFigurePosition(position);
|
||||
if (position == 0)
|
||||
FigureBasePosition derived_position = DeriveFigurePosition(position);
|
||||
if (derived_position == FigureBasePosition::Unknown)
|
||||
{
|
||||
ERROR_LOG_FMT(IOS_USB, "Invalid Position for Infinity Figure");
|
||||
return;
|
||||
@@ -663,8 +664,8 @@ void InfinityBase::RemoveFigure(u8 position)
|
||||
|
||||
figure.present = false;
|
||||
|
||||
std::array<u8, 32> figure_change_response = {0xab, 0x04, position, 0x09, figure.order_added,
|
||||
0x01};
|
||||
std::array<u8, 32> figure_change_response = {
|
||||
0xab, 0x04, static_cast<u8>(derived_position), 0x09, figure.order_added, 0x01};
|
||||
figure_change_response[6] = GenerateChecksum(figure_change_response, 6);
|
||||
m_figure_added_removed_response.push(figure_change_response);
|
||||
}
|
||||
@@ -751,7 +752,7 @@ std::string InfinityBase::FindFigure(u32 number) const
|
||||
return "Unknown Figure";
|
||||
}
|
||||
|
||||
u8 InfinityBase::DeriveFigurePosition(u8 position)
|
||||
FigureBasePosition InfinityBase::DeriveFigurePosition(FigureUIPosition position)
|
||||
{
|
||||
// In the added/removed response, position needs to be 1 for the hexagon, 2 for Player 1 and
|
||||
// Player 1's abilities, and 3 for Player 2 and Player 2's abilities. In the UI, positions 0, 1
|
||||
@@ -760,21 +761,26 @@ u8 InfinityBase::DeriveFigurePosition(u8 position)
|
||||
|
||||
switch (position)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return 1;
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
return 2;
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
return 3;
|
||||
|
||||
case FigureUIPosition::HexagonDiscOne:
|
||||
case FigureUIPosition::HexagonDiscTwo:
|
||||
case FigureUIPosition::HexagonDiscThree:
|
||||
{
|
||||
return FigureBasePosition::HexagonSlot;
|
||||
}
|
||||
case FigureUIPosition::PlayerOne:
|
||||
case FigureUIPosition::P1AbilityOne:
|
||||
case FigureUIPosition::P1AbilityTwo:
|
||||
{
|
||||
return FigureBasePosition::PlayerOneSlot;
|
||||
}
|
||||
case FigureUIPosition::PlayerTwo:
|
||||
case FigureUIPosition::P2AbilityOne:
|
||||
case FigureUIPosition::P2AbilityTwo:
|
||||
{
|
||||
return FigureBasePosition::PlayerTwoSlot;
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
return FigureBasePosition::Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +66,27 @@ private:
|
||||
std::queue<std::unique_ptr<IntrMessage>> m_response_list;
|
||||
};
|
||||
|
||||
enum class FigureUIPosition : u8
|
||||
{
|
||||
HexagonDiscOne = 0,
|
||||
HexagonDiscTwo = 1,
|
||||
HexagonDiscThree = 2,
|
||||
PlayerOne = 3,
|
||||
P1AbilityOne = 4,
|
||||
P1AbilityTwo = 5,
|
||||
PlayerTwo = 6,
|
||||
P2AbilityOne = 7,
|
||||
P2AbilityTwo = 8
|
||||
};
|
||||
|
||||
enum class FigureBasePosition : u8
|
||||
{
|
||||
Unknown = 0,
|
||||
HexagonSlot = 1,
|
||||
PlayerOneSlot = 2,
|
||||
PlayerTwoSlot = 3
|
||||
};
|
||||
|
||||
class InfinityBase final
|
||||
{
|
||||
public:
|
||||
@@ -79,10 +100,10 @@ public:
|
||||
u8 sequence);
|
||||
void DescrambleAndSeed(u8* buf, u8 sequence, std::array<u8, 32>& reply_buf);
|
||||
void GetNextAndScramble(u8 sequence, std::array<u8, 32>& reply_buf);
|
||||
void RemoveFigure(u8 position);
|
||||
void RemoveFigure(FigureUIPosition position);
|
||||
// Returns Infinity Figure name based on data from in_file param
|
||||
std::string LoadFigure(const std::array<u8, INFINITY_NUM_BLOCKS * INFINITY_BLOCK_SIZE>& buf,
|
||||
File::IOFile in_file, u8 position);
|
||||
File::IOFile in_file, FigureUIPosition position);
|
||||
bool CreateFigure(const std::string& file_path, u32 character);
|
||||
static std::span<const std::pair<const char*, const u32>> GetFigureList();
|
||||
std::string FindFigure(u32 character) const;
|
||||
@@ -95,7 +116,7 @@ private:
|
||||
InfinityFigure& GetFigureByOrder(u8 order_added);
|
||||
std::array<u8, 16> GenerateInfinityFigureKey(const std::vector<u8>& sha1_data);
|
||||
std::array<u8, 16> GenerateBlankFigureData(u32 figure_num);
|
||||
u8 DeriveFigurePosition(u8 position);
|
||||
FigureBasePosition DeriveFigurePosition(FigureUIPosition position);
|
||||
void GenerateSeed(u32 seed);
|
||||
u32 GetNext();
|
||||
u64 Scramble(u32 num_to_scramble, u32 garbage);
|
||||
|
||||
Reference in new issue
Block a user