Skip to content

Commit c35fadb

Browse files
committed
Adjusted the Lock Flags menu to allow for locking each type of flag individually
1 parent 921d6eb commit c35fadb

File tree

8 files changed

+353
-106
lines changed

8 files changed

+353
-106
lines changed

ttyd-tools/rel/include/global.h

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,14 @@ enum CHEATS_RESOLVE_FADES_RETURN_VALUES
119119

120120
enum CHEATS_LOCK_FLAGS_SELECTION
121121
{
122-
LOCK_CURRENT_FLAGS = 1,
123-
SET_NEW_AREA,
122+
LOCK_GSW_FLAGS = 1,
123+
LOCK_GSWF_FLAGS,
124+
LOCK_GW_FLAGS,
125+
LOCK_GF_FLAGS,
126+
LOCK_LSW_FLAGS,
127+
LOCK_LSWF_FLAGS,
128+
SET_NEW_LSW_AREA,
129+
SET_NEW_LSWF_AREA,
124130
};
125131

126132
enum CHEATS_MANAGE_FLAGS_SELECTION
@@ -600,8 +606,20 @@ struct ClearCacheForBattlesStruct
600606

601607
struct LockFlagsStruct
602608
{
603-
uint8_t *FlagsToLockMemory;
604-
char AreaLocked[4]; // 3 bytes for the area, 1 byte for NULL
609+
/*
610+
uint8_t *GSWsMemory; // 0x800
611+
uint8_t *GSWFsMemory; // 0x400
612+
uint8_t *GWsMemory; // 0x80
613+
uint8_t *GFsMemory; // 0xC
614+
uint8_t *LSWsMemory; // 0x400
615+
uint8_t *LSWFsMemory; // 0x40
616+
*/
617+
618+
bool MemoryRegionLocked[6];
619+
uint8_t *MemoryRegion[6];
620+
uint32_t SequencePosition;
621+
char LSWsAreaLocked[4]; // 3 bytes for the area, 1 byte for NULL
622+
char LSWFsAreaLocked[4]; // 3 bytes for the area, 1 byte for NULL
605623
};
606624

607625
struct TrickDisplay

ttyd-tools/rel/include/menufunctions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ void raiseSystemLevel();
2323
void lowerSystemLevel();
2424

2525
void partnerMenuRemoveOrBringOut(void *partnerEnabledAddress);
26+
bool lockFlagsMenuBackUpStandardFlags(bool &flag, uint8_t *&memoryRegion, uint32_t size, uint32_t offset);
27+
bool lockFlagsMenuBackUpGWOrGFFlags(bool &flag, uint8_t *&dstMemoryRegion, void *srcMemoryRegion, uint32_t size);
28+
bool lockFlagsMenuSetNewArea(bool flag, uint8_t *memoryRegion, char *area, uint32_t size, uint32_t offset);
2629
const char *getItemName(int16_t item);
2730
void *getFreeSlotPointer();
2831
int32_t getTotalItems();

ttyd-tools/rel/source/codes.cpp

Lines changed: 88 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -831,36 +831,110 @@ void checkIfAreaFlagsShouldBeCleared()
831831
}
832832
}
833833

834-
void lockFlags()
834+
void lockFlagsStandard(bool flag, uint8_t *memoryRegion, uint32_t size, uint32_t offset)
835835
{
836-
if (!Cheat[LOCK_FLAGS].Active)
836+
if (!flag)
837837
{
838838
return;
839839
}
840840

841-
uint8_t *tempFlagsToLockMemory = LockFlags.FlagsToLockMemory;
842-
if (!tempFlagsToLockMemory)
841+
if (!memoryRegion)
843842
{
844843
return;
845844
}
846845

846+
// Restore the memory
847847
uint32_t GlobalWorkPtrRaw = reinterpret_cast<uint32_t>(ttyd::mariost::globalWorkPointer);
848+
void *MemoryStart = reinterpret_cast<void *>(GlobalWorkPtrRaw + offset);
849+
memcpy(MemoryStart, memoryRegion, size);
850+
}
851+
852+
void lockFlagsGWsOrGFs(bool flag, void *dstMemoryRegion, uint8_t *srcMemoryRegion, uint32_t size)
853+
{
854+
if (!flag)
855+
{
856+
return;
857+
}
848858

849-
// Restore the GSWFs
850-
void *GSWFsAddresses = reinterpret_cast<void *>(GlobalWorkPtrRaw + 0x178);
851-
memcpy(GSWFsAddresses, tempFlagsToLockMemory, 0x400);
859+
if (!dstMemoryRegion)
860+
{
861+
return;
862+
}
852863

853-
// Restore the GFs
854-
ttyd::evtmgr::EvtWork *EventWork = ttyd::evtmgr::evtGetWork();
855-
memcpy(EventWork->gfData, &tempFlagsToLockMemory[0x440], sizeof(EventWork->gfData));
864+
memcpy(dstMemoryRegion, srcMemoryRegion, size);
865+
}
866+
867+
void lockFlagsLSWsOrLSWFs(char *area, bool flag, uint8_t *memoryRegion, uint32_t size, uint32_t offset)
868+
{
869+
if (!flag)
870+
{
871+
return;
872+
}
856873

857-
// Restore the LSWFs
858874
// Only restore if currently in the original area where the code was enabled
859-
if (compareStrings(LockFlags.AreaLocked, ttyd::seq_mapchange::NextArea))
875+
if (!compareStrings(area, ttyd::seq_mapchange::NextArea))
860876
{
861-
void *LSWFsAddresses = reinterpret_cast<void *>(GlobalWorkPtrRaw + 0xD78);
862-
memcpy(LSWFsAddresses, &tempFlagsToLockMemory[0x400], 0x40);
877+
return;
863878
}
879+
880+
lockFlagsStandard(flag, memoryRegion, size, offset);
881+
}
882+
883+
void lockFlags()
884+
{
885+
uint32_t Index = 0;
886+
887+
// Restore the GSWs
888+
uint32_t Size = 0x800;
889+
uint32_t Offset = 0x578;
890+
bool tempFlag = LockFlags.MemoryRegionLocked[Index];
891+
lockFlagsStandard(tempFlag, LockFlags.MemoryRegion[Index], Size, Offset);
892+
893+
// Restore the Sequence Position if the code is enabled
894+
if (tempFlag)
895+
{
896+
setSequencePosition(LockFlags.SequencePosition);
897+
}
898+
Index++;
899+
900+
// Restore the GSWFs
901+
Size = 0x400;
902+
Offset = 0x178;
903+
lockFlagsStandard(LockFlags.MemoryRegionLocked[Index], LockFlags.MemoryRegion[Index], Size, Offset);
904+
Index++;
905+
906+
// Restore the GWs
907+
ttyd::evtmgr::EvtWork *EventWork = ttyd::evtmgr::evtGetWork();
908+
Size = 0x80;
909+
lockFlagsGWsOrGFs(LockFlags.MemoryRegionLocked[Index], EventWork->gwData, LockFlags.MemoryRegion[Index], Size);
910+
Index++;
911+
912+
// Restore the GFs
913+
Size = 0xC;
914+
lockFlagsGWsOrGFs(LockFlags.MemoryRegionLocked[Index], EventWork->gfData, LockFlags.MemoryRegion[Index], Size);
915+
Index++;
916+
917+
// Restore the LSWs
918+
Size = 0x400;
919+
Offset = 0xDB8;
920+
921+
lockFlagsLSWsOrLSWFs(LockFlags.LSWsAreaLocked,
922+
LockFlags.MemoryRegionLocked[Index],
923+
LockFlags.MemoryRegion[Index],
924+
Size,
925+
Offset);
926+
927+
Index++;
928+
929+
// Restore the LSWFs
930+
Size = 0x40;
931+
Offset = 0xD78;
932+
933+
lockFlagsLSWsOrLSWFs(LockFlags.LSWFsAreaLocked,
934+
LockFlags.MemoryRegionLocked[Index],
935+
LockFlags.MemoryRegion[Index],
936+
Size,
937+
Offset);
864938
}
865939

866940
void displaySequenceInPauseMenu()

ttyd-tools/rel/source/draw.cpp

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3075,42 +3075,73 @@ void drawCheatsResolveFades()
30753075

30763076
void drawCheatsLockFlags()
30773077
{
3078-
// Draw the text indicating which area has its flags locked
3079-
uint32_t Color = 0xFFFFFFFF;
3078+
// Draw the Yes/No text for each option
30803079
uint8_t Alpha = 0xFF;
30813080
int32_t PosX = -232;
3082-
int32_t PosY = 60;
3081+
int32_t PosY = 180;
30833082
float Scale = 0.6;
3083+
uint32_t Color;
30843084

3085-
const char *String = "Current Area Local Flags Locked";
3086-
drawText(String, PosX, PosY, Alpha, Color, Scale);
3087-
PosY -= 20;
3088-
3089-
// Get the text for which area has its flags locked
3090-
char CurrentAreaLockedText[64];
3091-
char *tempAreaLockedText = LockFlags.AreaLocked;
3085+
const char *String;
30923086

3093-
// Make sure the current area with its flags locked is valid
3094-
if (!Cheat[LOCK_FLAGS].Active || tempAreaLockedText[0] == '\0')
3087+
uint32_t Size = sizeof(LockFlags.MemoryRegionLocked) / sizeof(LockFlags.MemoryRegionLocked[0]);
3088+
for (uint32_t i = 0; i < Size; i++)
30953089
{
3096-
strcpy(CurrentAreaLockedText, "None");
3090+
getYesNoTextAndColor(LockFlags.MemoryRegionLocked[i], &String, &Color);
3091+
drawText(String, PosX + 120, PosY, Alpha, Color, Scale);
3092+
PosY -= 20;
30973093
}
3098-
else
3094+
PosY -= 60;
3095+
3096+
auto getAreaText = [](char *stringOut, char *areaLocked, bool flag)
30993097
{
3100-
strcpy(CurrentAreaLockedText, tempAreaLockedText);
3101-
3102-
// Check to see if the current area is one that can have its flags cleared
3103-
const char **tempAreaText = CheatsClearAreaFlagsAreas;
3104-
uint32_t Size = CheatsClearAreaFlagsAreasSize;
3105-
for (uint32_t i = 0; i < Size; i++)
3098+
// Make sure the current area with its flags locked is valid
3099+
if (!flag || areaLocked[0] == '\0')
31063100
{
3107-
if (compareStrings(tempAreaLockedText, tempAreaText[i]))
3101+
strcpy(stringOut, "None");
3102+
return static_cast<uint32_t>(0x4B4B4BFF);
3103+
}
3104+
else
3105+
{
3106+
strcpy(stringOut, areaLocked);
3107+
3108+
// Check to see if the current area is one that can have its flags cleared
3109+
const char **tempAreaText = CheatsClearAreaFlagsAreas;
3110+
uint32_t Size = CheatsClearAreaFlagsAreasSize;
3111+
for (uint32_t i = 0; i < Size; i++)
31083112
{
3109-
strcpy(CurrentAreaLockedText, CheatsClearAreaFlagsAreasFullNames[i]);
3110-
break;
3113+
if (compareStrings(areaLocked, tempAreaText[i]))
3114+
{
3115+
strcpy(stringOut, CheatsClearAreaFlagsAreasFullNames[i]);
3116+
break;
3117+
}
31113118
}
31123119
}
3113-
}
3120+
return static_cast<uint32_t>(0xFFFFFFFF);
3121+
};
3122+
3123+
// Draw the text indicating which area has its LSW flags locked
3124+
Color = 0xFFFFFFFF;
3125+
String = "Current Area LSW Flags Locked";
3126+
drawText(String, PosX, PosY, Alpha, Color, Scale);
3127+
PosY -= 20;
3128+
3129+
// Get the text for which area has its LSW flags locked
3130+
char CurrentAreaLockedText[64];
3131+
Color = getAreaText(CurrentAreaLockedText, LockFlags.LSWsAreaLocked, LockFlags.MemoryRegionLocked[4]);
3132+
3133+
// Draw the text for which area has its flags locked
3134+
drawText(CurrentAreaLockedText, PosX, PosY, Alpha, Color, Scale);
3135+
PosY -= 40;
3136+
3137+
// Draw the text indicating which area has its LSWF flags locked
3138+
Color = 0xFFFFFFFF;
3139+
String = "Current Area LSWF Flags Locked";
3140+
drawText(String, PosX, PosY, Alpha, Color, Scale);
3141+
PosY -= 20;
3142+
3143+
// Get the text for which area has its LSWF flags locked
3144+
Color = getAreaText(CurrentAreaLockedText, LockFlags.LSWFsAreaLocked, LockFlags.MemoryRegionLocked[5]);
31143145

31153146
// Draw the text for which area has its flags locked
31163147
drawText(CurrentAreaLockedText, PosX, PosY, Alpha, Color, Scale);

ttyd-tools/rel/source/global.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,8 +1017,14 @@ const char *CheatsManageGlobalWordsOptions[]
10171017

10181018
const char *CheatsLockFlagsOptions[]
10191019
{
1020-
"Toggle Value",
1021-
"Set New Area",
1020+
"Lock GSWs",
1021+
"Lock GSWFs",
1022+
"Lock GWs",
1023+
"Lock GFs",
1024+
"Lock LSWs",
1025+
"Lock LSWFs",
1026+
"Set New LSW Area",
1027+
"Set New LSWF Area",
10221028
};
10231029

10241030
const char *CheatsManageGlobalFlagsOptions[]

ttyd-tools/rel/source/memcard.cpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,9 @@ int32_t saveSettings()
323323
uint32_t CheatsSize = sizeof(Cheat) / sizeof(Cheat[0]);
324324
for (uint32_t i = 0; i < CheatsSize; i++)
325325
{
326-
uint32_t CurrentIndex = CheatsOrder[i];
327-
328-
// Don't update the bool for the Lock Flags code
329-
if (CurrentIndex != LOCK_FLAGS)
330-
{
331-
Settings->CheatsActive[i] = Cheat[CurrentIndex].Active;
332-
}
333-
334-
Settings->CheatButtonCombos[i] = Cheat[CurrentIndex].ButtonCombo;
326+
uint32_t CurrentIndex = CheatsOrder[i];
327+
Settings->CheatsActive[i] = Cheat[CurrentIndex].Active;
328+
Settings->CheatButtonCombos[i] = Cheat[CurrentIndex].ButtonCombo;
335329
}
336330

337331
// Copy the Displays bools
@@ -447,13 +441,8 @@ int32_t loadSettings()
447441
uint32_t CheatsSize = sizeof(Cheat) / sizeof(Cheat[0]);
448442
for (uint32_t i = 0; i < CheatsSize; i++)
449443
{
450-
uint32_t CurrentIndex = CheatsOrder[i];
451-
452-
// Don't update the bool for the Lock Flags code
453-
if (CurrentIndex != LOCK_FLAGS)
454-
{
455-
Cheat[CurrentIndex].Active = Settings->CheatsActive[i];
456-
}
444+
uint32_t CurrentIndex = CheatsOrder[i];
445+
Cheat[CurrentIndex].Active = Settings->CheatsActive[i];
457446

458447
// Make sure the button combo is valid, so that new button combos are not overwritten with 0
459448
uint16_t ButtonCombo = Settings->CheatButtonCombos[i];

0 commit comments

Comments
 (0)