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