Improve cheat execution parameters and handle CRLF properly
This commit is contained in:
parent
4c9fe186d7
commit
2fe1169423
@ -48,9 +48,8 @@ typedef struct CheatDescription
|
||||
{
|
||||
u32 active;
|
||||
u32 valid;
|
||||
u32 keyActivated;
|
||||
u32 keyCombo;
|
||||
char name[40];
|
||||
char hasKeyCode;
|
||||
char name[39];
|
||||
u32 codesCount;
|
||||
u64 codes[0];
|
||||
} CheatDescription;
|
||||
@ -110,7 +109,6 @@ typedef struct CheatState
|
||||
|
||||
CheatState cheat_state = { 0 };
|
||||
u8 cheatCount = 0;
|
||||
u8 hasKeyActivated = 0;
|
||||
u64 cheatTitleInfo = -1ULL;
|
||||
|
||||
char failureReason[64];
|
||||
@ -840,6 +838,7 @@ static Result Cheat_MapMemoryAndApplyCheat(u32 pid, CheatDescription* const chea
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(failureReason, "Debug process failed");
|
||||
svcCloseHandle(processHandle);
|
||||
}
|
||||
}
|
||||
@ -865,8 +864,7 @@ static CheatDescription* Cheat_AllocCheat()
|
||||
cheat->active = 0;
|
||||
cheat->valid = 1;
|
||||
cheat->codesCount = 0;
|
||||
cheat->keyActivated = 0;
|
||||
cheat->keyCombo = 0;
|
||||
cheat->hasKeyCode = 0;
|
||||
cheat->name[0] = '\0';
|
||||
|
||||
cheats[cheatCount] = cheat;
|
||||
@ -883,7 +881,7 @@ static void Cheat_AddCode(CheatDescription* cheat, u64 code)
|
||||
}
|
||||
}
|
||||
|
||||
static Result Cheat_ReadLine(char* line)
|
||||
static Result Cheat_ReadLine(char* line, u32 lineSize)
|
||||
{
|
||||
Result res = 0;
|
||||
|
||||
@ -895,7 +893,13 @@ static Result Cheat_ReadLine(char* line)
|
||||
res = c ? 0 : -1;
|
||||
if (R_SUCCEEDED(res) && c != '\0')
|
||||
{
|
||||
if (c == '\n' || c == '\r' || idx >= 1023)
|
||||
if (c == '\r' && cheatFileBuffer[cheatFilePos] == '\n')
|
||||
{
|
||||
cheatFilePos++;
|
||||
line[idx++] = '\0';
|
||||
return idx;
|
||||
}
|
||||
else if (c == '\n' || idx >= lineSize - 1)
|
||||
{
|
||||
line[idx++] = '\0';
|
||||
return idx;
|
||||
@ -1002,7 +1006,6 @@ static void Cheat_LoadCheatsIntoMemory(u64 titleId)
|
||||
{
|
||||
cheatCount = 0;
|
||||
cheatTitleInfo = titleId;
|
||||
hasKeyActivated = 0;
|
||||
|
||||
char path[64] = { 0 };
|
||||
sprintf(path, "/luma/titles/%016llX/cheats.txt", titleId);
|
||||
@ -1037,7 +1040,7 @@ static void Cheat_LoadCheatsIntoMemory(u64 titleId)
|
||||
cheatFilePos = 0;
|
||||
do
|
||||
{
|
||||
res = Cheat_ReadLine(line);
|
||||
res = Cheat_ReadLine(line, 1024);
|
||||
if (R_SUCCEEDED(res))
|
||||
{
|
||||
s32 lineLen = strnlen(line, 1023);
|
||||
@ -1057,12 +1060,7 @@ static void Cheat_LoadCheatsIntoMemory(u64 titleId)
|
||||
Cheat_AddCode(cheat, tmp);
|
||||
if (((tmp >> 32) & 0xFFFFFFFF) == 0xDD000000)
|
||||
{
|
||||
if (tmp & 0xFFFFFFFF)
|
||||
{
|
||||
// Not empty key code
|
||||
cheat->keyCombo |= (tmp & 0xFFF);
|
||||
cheat->keyActivated = 1;
|
||||
}
|
||||
cheat->hasKeyCode = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1134,25 +1132,18 @@ void Cheat_ApplyCheats(void)
|
||||
if (!titleId)
|
||||
{
|
||||
cheatCount = 0;
|
||||
hasKeyActivated = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (titleId != cheatTitleInfo)
|
||||
{
|
||||
cheatCount = 0;
|
||||
hasKeyActivated = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
u32 keys = HID_PAD & 0xFFF;
|
||||
for (int i = 0; i < cheatCount; i++)
|
||||
{
|
||||
if (cheats[i]->active && !(cheats[i]->keyActivated))
|
||||
{
|
||||
Cheat_MapMemoryAndApplyCheat(pid, cheats[i]);
|
||||
}
|
||||
else if (cheats[i]->active && cheats[i]->keyActivated && (cheats[i]->keyCombo & keys) == keys)
|
||||
if (cheats[i]->active)
|
||||
{
|
||||
Cheat_MapMemoryAndApplyCheat(pid, cheats[i]);
|
||||
}
|
||||
@ -1217,7 +1208,7 @@ void RosalinaMenu_Cheats(void)
|
||||
char buf[65] = { 0 };
|
||||
s32 j = page * CHEATS_PER_MENU_PAGE + i;
|
||||
const char * checkbox = (cheats[j]->active ? "(x) " : "( ) ");
|
||||
const char * keyAct = (cheats[j]->keyActivated ? "*" : " ");
|
||||
const char * keyAct = (cheats[j]->hasKeyCode ? "*" : " ");
|
||||
sprintf(buf, "%s%s%s", checkbox, keyAct, cheats[j]->name);
|
||||
|
||||
Draw_DrawString(30, 30 + i * SPACING_Y, cheats[j]->valid ? COLOR_WHITE : COLOR_RED, buf);
|
||||
@ -1253,15 +1244,6 @@ void RosalinaMenu_Cheats(void)
|
||||
{
|
||||
r = Cheat_MapMemoryAndApplyCheat(pid, cheats[selected]);
|
||||
}
|
||||
hasKeyActivated = 0;
|
||||
for (int i = 0; i < cheatCount; i++)
|
||||
{
|
||||
if (cheats[i]->active && cheats[i]->keyActivated)
|
||||
{
|
||||
hasKeyActivated = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (pressed & BUTTON_DOWN)
|
||||
selected++;
|
||||
|
Reference in New Issue
Block a user