Skip to content
This repository has been archived by the owner on Mar 18, 2023. It is now read-only.

Commit

Permalink
Don't display enable cheat in cheat menu when using text cheats. It w…
Browse files Browse the repository at this point in the history
…ill be treat the first cheat for a game as the enable code and enable it separately.
  • Loading branch information
root670 committed Mar 21, 2016
1 parent 8c21de4 commit 5a3511b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 50 deletions.
85 changes: 40 additions & 45 deletions cheats.c
Expand Up @@ -205,9 +205,6 @@ int cheatsToggleCheat(cheatsCheat_t *cheat)
{
if(cheat && cheat->type != CHEATHEADER)
{
if(cheat == activeGame->cheats) // first cheat is the enable code, which will be enabled/disabled automatically.
return 0;

if(!cheat->enabled)
{
if((numEnabledCodes + cheat->numCodeLines) >= 250)
Expand All @@ -219,24 +216,12 @@ int cheatsToggleCheat(cheatsCheat_t *cheat)
cheat->enabled = 1;
numEnabledCheats++;
numEnabledCodes += cheat->numCodeLines;
if(numEnabledCheats == 1) // first cheat was enabled
{
activeGame->cheats->enabled = 1; // toggle enable code on
numEnabledCheats++;
numEnabledCodes += activeGame->cheats->numCodeLines;
}
}
else
{
cheat->enabled = 0;
numEnabledCheats--;
numEnabledCodes -= cheat->numCodeLines;
if(numEnabledCheats == 1) // last cheat was disabled
{
activeGame->cheats->enabled = 0; // toggle enable code off
numEnabledCheats--;
numEnabledCodes -= activeGame->cheats->numCodeLines;
}
}
}
else
Expand Down Expand Up @@ -369,6 +354,44 @@ void SetupERL()
printf("Symbols loaded.\n");
}

static void readCodes(cheatsCheat_t *cheats)
{
int i;
u32 addr, val;
int nextCodeCanBeHook = 1;
cheatsCheat_t *cheat = cheats;

while(cheat)
{
if(cheat->enabled)
{
for(i = 0; i < cheat->numCodeLines; ++i)
{
addr = (u32)*((u32 *)cheat->codeLines + 2*i);
val = (u32)*((u32 *)cheat->codeLines + 2*i + 1);

if(((addr & 0xfe000000) == 0x90000000) && nextCodeCanBeHook == 1)
{
printf("hook: %08X %08X\n", addr, val);
add_hook(addr, val);
}
else
{
printf("code: %08X %08X\n", addr, val);
add_code(addr, val);
}

if ((addr & 0xf0000000) == 0x40000000 || (addr & 0xf0000000) == 0x30000000)
nextCodeCanBeHook = 0;
else
nextCodeCanBeHook = 1;
}
}

cheat = cheat->next;
}
}

void cheatsInstallCodesForEngine()
{
if(activeGame != NULL)
Expand All @@ -378,36 +401,8 @@ void cheatsInstallCodesForEngine()
int nextCodeCanBeHook = 1;

SetupERL();

cheatsCheat_t *cheat = activeGame->cheats;

while(cheat)
{
if(cheat->enabled)
{
for(i = 0; i < cheat->numCodeLines; ++i)
{
addr = (u32)*((u32 *)cheat->codeLines + 2*i);
val = (u32)*((u32 *)cheat->codeLines + 2*i + 1);

if(((addr & 0xfe000000) == 0x90000000) && nextCodeCanBeHook == 1)
{
printf("hook: %08X %08X\n", addr, val);
add_hook(addr, val);
}
else
{
printf("code: %08X %08X\n", addr, val);
add_code(addr, val);
}

if ((addr & 0xf0000000) == 0x40000000 || (addr & 0xf0000000) == 0x30000000)
nextCodeCanBeHook = 0;
else
nextCodeCanBeHook = 1;
}
}
cheat = cheat->next;
}
readCodes(activeGame->enableCheat);
readCodes(activeGame->cheats);
}
}
1 change: 1 addition & 0 deletions cheats.h
Expand Up @@ -35,6 +35,7 @@ typedef struct cheatsGame {
char title[81];
unsigned int numCheats;
cheatsCheat_t *cheats;
cheatsCheat_t *enableCheat;

struct cheatsGame *next;
} cheatsGame_t;
Expand Down
1 change: 1 addition & 0 deletions startgame.c
Expand Up @@ -11,6 +11,7 @@
#include "menus.h"
#include "cheats.h"
#include "settings.h"
#include "util.h"

typedef struct {
u8 ident[16]; // struct definition for ELF object header
Expand Down
16 changes: 11 additions & 5 deletions textcheats.c
Expand Up @@ -226,19 +226,25 @@ int parseLine(const char *line)
case TOKEN_CHEAT: // Add new cheat to game
if(!game)
return 0;

game->numCheats++;

if(game->cheats == NULL)

if(game->enableCheat == NULL)
{
game->enableCheat = &cheatsHead[usedCheats++];
game->enableCheat->enabled = 1;
cheat = game->enableCheat;
}
else if(game->cheats == NULL)
{
// Game's first cheat
// Game's first cheat following enable cheat
game->cheats = &cheatsHead[usedCheats++];
cheat = game->cheats;
game->numCheats++;
}
else
{
cheat->next = &cheatsHead[usedCheats++];
cheat = cheat->next;
game->numCheats++;
}

strncpy(cheat->title, line, 81);
Expand Down

0 comments on commit 5a3511b

Please sign in to comment.