Skip to content

Commit 10286e4

Browse files
committed
Adjusted multiple functions that return arrays
Most of the functions did not need to return the array, so they were changed to not do so.
1 parent 2ba02e4 commit 10286e4

File tree

4 files changed

+71
-73
lines changed

4 files changed

+71
-73
lines changed

ttyd-tools/rel/include/menufunctions.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ void lowerSystemLevel();
1919
const char *getItemName(int16_t item);
2020
void *getFreeSlotPointer();
2121
int32_t getTotalItems();
22-
int32_t *getUpperAndLowerBounds(int32_t *tempArray, uint32_t currentMenu);
23-
uint32_t *getPouchAddressAndSize(uint32_t *tempArray);
22+
void getUpperAndLowerBounds(int32_t arrayOut[2], uint32_t currentMenu);
23+
uint32_t *getPouchAddressAndSize(uint32_t tempArray[2]);
2424
bool checkForItemsOnNextPage(uint32_t currentPage);
2525
bool checkForClosingErrorMessage();
2626

@@ -60,9 +60,9 @@ void cheatClearAreaFlags(uint32_t currentMenuOption);
6060
const char *getMapFromIndex(int32_t index);
6161
int32_t getMapIndex();
6262

63-
// uint8_t *getButtonsPressedDynamic(uint8_t *buttonArray, uint16_t currentButtonCombo);
64-
uint8_t *getButtonsPressed(uint8_t *buttonArray, uint16_t currentButtonCombo);
65-
char *createButtonStringArray(char *tempArray, uint8_t *buttonArray);
63+
// void getButtonsPressedDynamic(uint8_t *buttonArrayOut, uint16_t currentButtonCombo);
64+
void getButtonsPressed(uint8_t *buttonArrayOut, uint16_t currentButtonCombo);
65+
void createButtonStringArray(char *stringOut, uint8_t *buttonArray);
6666
bool incrementCheatsBButtonCounter(uint32_t buttonInput);
6767
bool cheatsManageTimer(uint32_t buttonInput);
6868

ttyd-tools/rel/source/draw.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,9 +2425,10 @@ void drawAddByIconMain(uint32_t currentMenu)
24252425

24262426
// Draw the main window
24272427
int32_t UpperAndLowerBounds[2];
2428-
int32_t *tempArray = getUpperAndLowerBounds(UpperAndLowerBounds, MenuSelectedOption);
2429-
int32_t LowerBound = tempArray[0];
2430-
int32_t UpperBound = tempArray[1];
2428+
getUpperAndLowerBounds(UpperAndLowerBounds, MenuSelectedOption);
2429+
2430+
int32_t LowerBound = UpperAndLowerBounds[0];
2431+
int32_t UpperBound = UpperAndLowerBounds[1];
24312432

24322433
uint32_t MaxIconsPerRow = 16;
24332434
uint32_t IconSpaceOccupied = 30;
@@ -2770,19 +2771,19 @@ void drawButtonCombo(uint16_t buttonCombo, int32_t posY, const char *description
27702771
drawText(description, PosX, posY, Alpha, Color, Scale);
27712772

27722773
// Draw the button combo
2773-
uint8_t tempButtonArray[14]; // Extra spot for 0 at the end of the array
2774-
clearMemory(tempButtonArray, sizeof(tempButtonArray));
2775-
uint8_t *ButtonArray = getButtonsPressed(tempButtonArray, buttonCombo);
2774+
uint8_t ButtonArray[14]; // Extra spot for 0 at the end of the array
2775+
clearMemory(ButtonArray, sizeof(ButtonArray));
2776+
getButtonsPressed(ButtonArray, buttonCombo);
27762777

2777-
// uint8_t *CurrentButtonComboArray = nullptr;
2778-
// uint8_t *ButtonArray = getButtonsPressed(CurrentButtonComboArray);
2778+
// uint8_t *ButtonArray = nullptr;
2779+
// getButtonsPressed(ButtonArray);
27792780

27802781
char ButtonString[256];
27812782
clearMemory(ButtonString, sizeof(ButtonString));
2782-
char *tempButtonString = createButtonStringArray(ButtonString, ButtonArray);
2783+
createButtonStringArray(ButtonString, ButtonArray);
27832784

27842785
posY -= 20;
2785-
drawText(tempButtonString, PosX, posY, Alpha, Color, Scale);
2786+
drawText(ButtonString, PosX, posY, Alpha, Color, Scale);
27862787
// delete[] (ButtonArray);
27872788
// ButtonArray = nullptr;
27882789
}
@@ -2854,11 +2855,10 @@ void drawChangeButtonCombo(uint16_t &currentButtonCombo)
28542855

28552856
char ButtonString[256];
28562857
clearMemory(ButtonString, sizeof(ButtonString));
2857-
char *tempButtonString = createButtonStringArray(ButtonString,
2858-
CheatsDisplayButtons.CheatsCurrentButtonsHeld);
2858+
createButtonStringArray(ButtonString, tempButtonArray);
28592859

28602860
PosY -= 20;
2861-
drawText(tempButtonString, PosX, PosY, Alpha, Color, Scale);
2861+
drawText(ButtonString, PosX, PosY, Alpha, Color, Scale);
28622862

28632863
// Decrement the timer and check to see if it's at 0
28642864
if (cheatsManageTimer(ButtonInput))

ttyd-tools/rel/source/menu.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,9 @@ void menuCheckButton()
429429
if (CurrentItem != 0)
430430
{
431431
int32_t UpperAndLowerBounds[2];
432-
int32_t *tempArray2 = getUpperAndLowerBounds(
433-
UpperAndLowerBounds, tempMenuSelectedOption);
432+
getUpperAndLowerBounds(UpperAndLowerBounds, tempMenuSelectedOption);
434433

435-
int32_t LowerBound = tempArray2[0];
434+
int32_t LowerBound = UpperAndLowerBounds[0];
436435
SecondaryMenuOption = CurrentItem - LowerBound;
437436
}
438437
else

ttyd-tools/rel/source/menufunctions.cpp

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ int32_t getTotalItems()
243243
return Counter;
244244
}
245245

246-
int32_t *getUpperAndLowerBounds(int32_t *tempArray, uint32_t currentMenu)
246+
void getUpperAndLowerBounds(int32_t arrayOut[2], uint32_t currentMenu)
247247
{
248248
uint32_t tempMenuSelectedOption = MenuSelectedOption;
249249
uint32_t tempSelectedOption = SelectedOption;
@@ -595,12 +595,11 @@ int32_t *getUpperAndLowerBounds(int32_t *tempArray, uint32_t currentMenu)
595595
}
596596
}
597597

598-
tempArray[0] = LowerBound;
599-
tempArray[1] = UpperBound;
600-
return tempArray;
598+
arrayOut[0] = LowerBound;
599+
arrayOut[1] = UpperBound;
601600
}
602601

603-
uint32_t *getPouchAddressAndSize(uint32_t *tempArray)
602+
uint32_t *getPouchAddressAndSize(uint32_t tempArray[2])
604603
{
605604
uint32_t tempAddressOffset;
606605
uint32_t tempSize;
@@ -753,9 +752,10 @@ void correctInventoryCurrentMenuOptionAndPage(uint32_t maxOptionsPerPage)
753752
uint32_t getHighestAdjustableValueDigit(uint32_t currentMenu)
754753
{
755754
int32_t UpperAndLowerBounds[2];
756-
int32_t *tempArray = getUpperAndLowerBounds(UpperAndLowerBounds, currentMenu);
757-
int32_t LowerBound = tempArray[0];
758-
int32_t UpperBound = tempArray[1];
755+
getUpperAndLowerBounds(UpperAndLowerBounds, currentMenu);
756+
757+
int32_t LowerBound = UpperAndLowerBounds[0];
758+
int32_t UpperBound = UpperAndLowerBounds[1];
759759

760760
// Make sure each value is positive
761761
if (LowerBound < 0)
@@ -812,18 +812,18 @@ int32_t getDigitBeingChanged(int32_t number, int32_t valueChangedBy)
812812
void setAdjustableValueToMax(uint32_t currentMenu)
813813
{
814814
int32_t UpperAndLowerBounds[2];
815-
int32_t *tempArray = getUpperAndLowerBounds(UpperAndLowerBounds, currentMenu);
816-
int32_t UpperBound = tempArray[1];
815+
getUpperAndLowerBounds(UpperAndLowerBounds, currentMenu);
817816

817+
int32_t UpperBound = UpperAndLowerBounds[1];
818818
MenuSecondaryValue = UpperBound;
819819
}
820820

821821
void setAdjustableValueToMin(uint32_t currentMenu)
822822
{
823823
int32_t UpperAndLowerBounds[2];
824-
int32_t *tempArray = getUpperAndLowerBounds(UpperAndLowerBounds, currentMenu);
825-
int32_t LowerBound = tempArray[0];
824+
getUpperAndLowerBounds(UpperAndLowerBounds, currentMenu);
826825

826+
int32_t LowerBound = UpperAndLowerBounds[0];
827827
MenuSecondaryValue = LowerBound;
828828
}
829829

@@ -1295,9 +1295,9 @@ uint32_t addByIconButtonControls(uint32_t currentMenu)
12951295
case DPADUP:
12961296
{
12971297
int32_t UpperAndLowerBounds[2];
1298-
int32_t *tempArray = getUpperAndLowerBounds(UpperAndLowerBounds, currentMenu);
1299-
int32_t LowerBound = tempArray[0];
1300-
int32_t UpperBound = tempArray[1];
1298+
getUpperAndLowerBounds(UpperAndLowerBounds, currentMenu);
1299+
int32_t LowerBound = UpperAndLowerBounds[0];
1300+
int32_t UpperBound = UpperAndLowerBounds[1];
13011301

13021302
uint32_t MaxOptionsPerRow = 16;
13031303
uint32_t tempTotalMenuOptions = UpperBound - LowerBound + 1;
@@ -1924,9 +1924,10 @@ void adjustMenuItemBounds(int32_t valueChangedBy, uint32_t currentMenu)
19241924
}
19251925

19261926
int32_t UpperAndLowerBounds[2];
1927-
int32_t *tempArray = getUpperAndLowerBounds(UpperAndLowerBounds, currentMenu);
1928-
int32_t LowerBound = tempArray[0];
1929-
int32_t UpperBound = tempArray[1];
1927+
getUpperAndLowerBounds(UpperAndLowerBounds, currentMenu);
1928+
1929+
int32_t LowerBound = UpperAndLowerBounds[0];
1930+
int32_t UpperBound = UpperAndLowerBounds[1];
19301931

19311932
adjustMenuItemBoundsMain(valueChangedBy, LowerBound, UpperBound);
19321933
}
@@ -2454,8 +2455,9 @@ void setAddByIdValue(void *address)
24542455
void setAddByIconValue(void *address)
24552456
{
24562457
int32_t UpperAndLowerBounds[2];
2457-
int32_t *tempArray = getUpperAndLowerBounds(UpperAndLowerBounds, MenuSelectedOption);
2458-
int32_t LowerBound = tempArray[0];
2458+
getUpperAndLowerBounds(UpperAndLowerBounds, MenuSelectedOption);
2459+
2460+
int32_t LowerBound = UpperAndLowerBounds[0];
24592461
uint32_t tempSecondaryMenuOption = SecondaryMenuOption;
24602462
int32_t NewItem = LowerBound + tempSecondaryMenuOption;
24612463

@@ -2916,7 +2918,7 @@ int32_t getMapIndex()
29162918
return -1;
29172919
}
29182920

2919-
/*uint8_t *getButtonsPressedDynamic(uint8_t *buttonArray, uint16_t currentButtonCombo)
2921+
/*void getButtonsPressedDynamic(uint8_t *buttonArrayOut, uint16_t currentButtonCombo)
29202922
{
29212923
uint32_t Counter = 0;
29222924
uint32_t Size = 1;
@@ -2931,10 +2933,10 @@ int32_t getMapIndex()
29312933
29322934
if (currentButtonCombo & (1 << i))
29332935
{
2934-
if (!buttonArray)
2936+
if (!buttonArrayOut)
29352937
{
2936-
buttonArray = new uint8_t[2]; // Extra spot for a 0 at the end of the array
2937-
clearMemory(buttonArray, (2 * sizeof(uint8_t)));
2938+
buttonArrayOut = new uint8_t[2]; // Extra spot for a 0 at the end of the array
2939+
clearMemory(buttonArrayOut, (2 * sizeof(uint8_t)));
29382940
}
29392941
else
29402942
{
@@ -2945,48 +2947,46 @@ int32_t getMapIndex()
29452947
clearMemory(tempButtonArray, ((Size + 1) * sizeof(uint8_t)));
29462948
29472949
// Copy the contents of the old array to the new array
2948-
ttyd::__mem::memcpy(tempButtonArray, buttonArray, ((Size - 1) * sizeof(uint8_t)));
2950+
ttyd::__mem::memcpy(tempButtonArray, buttonArrayOut, ((Size - 1) * sizeof(uint8_t)));
29492951
29502952
// Delete the old array
2951-
delete[] (buttonArray);
2953+
delete[] (buttonArrayOut);
29522954
29532955
// Set the new array as the current array
2954-
buttonArray = tempButtonArray;
2956+
buttonArrayOut = tempButtonArray;
29552957
}
29562958
2957-
buttonArray[Size - 1] = Counter + 1;
2959+
buttonArrayOut[Size - 1] = Counter + 1;
29582960
}
29592961
29602962
Counter++;
29612963
}
29622964
2963-
if (buttonArray)
2965+
if (buttonArrayOut)
29642966
{
2965-
buttonArray[Size] = 0;
2967+
buttonArrayOut[Size] = 0;
29662968
}
29672969
else
29682970
{
2969-
buttonArray = new uint8_t[1];
2970-
buttonArray[0] = 0;
2971+
buttonArrayOut = new uint8_t[1];
2972+
buttonArrayOut[0] = 0;
29712973
}
2972-
2973-
return buttonArray;
29742974
}*/
29752975

2976-
/*uint8_t *getButtonsPressedDynamic(uint8_t *buttonArray, uint16_t currentButtonCombo)
2976+
/*void getButtonsPressedDynamic(uint8_t *buttonArrayOut, uint16_t currentButtonCombo)
29772977
{
2978-
if (!buttonArray)
2978+
if (!buttonArrayOut)
29792979
{
2980-
buttonArray = new uint8_t[14]; // Extra spot for a 0 at the end of the array
2980+
buttonArrayOut = new uint8_t[14]; // Extra spot for a 0 at the end of the array
29812981
}
29822982
29832983
// Clear the memory, so that the previous results do not interfere with the new results
2984-
clearMemory(buttonArray, (14 * sizeof(uint8_t)));
2984+
clearMemory(buttonArrayOut, (14 * sizeof(uint8_t)));
29852985
2986-
return getButtonsPressed(buttonArray, currentButtonCombo);
2986+
getButtonsPressed(buttonArrayOut, currentButtonCombo);
29872987
}*/
29882988

2989-
uint8_t *getButtonsPressed(uint8_t *buttonArray, uint16_t currentButtonCombo)
2989+
void getButtonsPressed(uint8_t *buttonArrayOut, uint16_t currentButtonCombo)
29902990
{
29912991
uint32_t Counter = 1;
29922992
uint32_t Size = 0;
@@ -3001,20 +3001,18 @@ uint8_t *getButtonsPressed(uint8_t *buttonArray, uint16_t currentButtonCombo)
30013001

30023002
if (currentButtonCombo & (1 << i))
30033003
{
3004-
buttonArray[Size] = Counter;
3004+
buttonArrayOut[Size] = Counter;
30053005
Size++;
30063006
}
30073007

30083008
Counter++;
30093009
}
3010-
3011-
return buttonArray;
30123010
}
30133011

3014-
char *createButtonStringArray(char *tempArray, uint8_t *buttonArray)
3012+
void createButtonStringArray(char *stringOut, uint8_t *buttonArray)
30153013
{
30163014
char *tempDisplayBuffer = DisplayBuffer;
3017-
const char *Button = "";
3015+
const char *Button;
30183016
uint32_t i = 0;
30193017

30203018
while (buttonArray[i] != 0)
@@ -3083,28 +3081,28 @@ char *createButtonStringArray(char *tempArray, uint8_t *buttonArray)
30833081
}
30843082
default:
30853083
{
3084+
Button = "";
30863085
break;
30873086
}
30883087
}
30893088

30903089
if (i == 0)
30913090
{
30923091
// Set the initial button pressed
3093-
ttyd::string::strcpy(tempArray, Button);
3092+
ttyd::string::strcpy(stringOut, Button);
30943093
}
30953094
else
30963095
{
30973096
// Add the next button pressed onto the first button pressed
30983097
sprintf(tempDisplayBuffer,
30993098
" + %s",
31003099
Button);
3101-
ttyd::string::strcat(tempArray, tempDisplayBuffer);
3100+
3101+
ttyd::string::strcat(stringOut, tempDisplayBuffer);
31023102
}
31033103

31043104
i++;
31053105
}
3106-
3107-
return tempArray;
31083106
}
31093107

31103108
bool incrementCheatsBButtonCounter(uint32_t buttonInput)
@@ -3398,9 +3396,10 @@ void adjustMenuSelectionInventory(uint32_t button)
33983396
/*void adjustAddByIconCurrentOption(uint32_t button)
33993397
{
34003398
int32_t UpperAndLowerBounds[2];
3401-
int32_t *tempArray = getUpperAndLowerBounds(UpperAndLowerBounds, MenuSelectedOption);
3402-
int32_t LowerBound = tempArray[0];
3403-
int32_t UpperBound = tempArray[1];
3399+
getUpperAndLowerBounds(UpperAndLowerBounds, MenuSelectedOption);
3400+
3401+
int32_t LowerBound = UpperAndLowerBounds[0];
3402+
int32_t UpperBound = UpperAndLowerBounds[1];
34043403
34053404
uint32_t MaxIconsPerRow = 16;
34063405

0 commit comments

Comments
 (0)