Skip to content

Commit df8816f

Browse files
committed
add system for per-game AR-style cheats (re #483)
1 parent efd7486 commit df8816f

File tree

2 files changed

+73
-5
lines changed

2 files changed

+73
-5
lines changed

desmume/src/NDSSystem.cpp

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2246,6 +2246,8 @@ void NDS_exec(s32 nb)
22462246
cheats->process(CHEAT_TYPE_INTERNAL);
22472247
CHEATS::ResetJitIfNeeded();
22482248
}
2249+
for(auto& cheat : CommonSettings.gamehacks.flags.cheats)
2250+
cheat->Run();
22492251

22502252
GDBSTUB_MUTEX_UNLOCK();
22512253
}
@@ -3462,16 +3464,67 @@ bool TCommonSettings::single_core()
34623464
return (num_cores == 1);
34633465
}
34643466

3467+
//library of individual game hacks
3468+
namespace
3469+
{
3470+
struct rabbids_us : public GameHackCheat
3471+
{
3472+
void Run() override
3473+
{
3474+
if(0xe28dd02c == read32(0x203cf18))
3475+
write32(0x203cf18, 0xeb0f0878);
3476+
write32(0x23ff100, 0xe59d1000);
3477+
write(0x23ff104, 48, "\x01\x00\x51\xE3\x03\x00\x00\x1A\x10\x10\x8F\xE2\x1E\x00\x91\xE8\x00\x30\x81\xE5\x00\x40\x82\xE5\x2C\xD0\x8D\xE2\x1E\xFF\x2F\xE1\xC4\xD5\x18\x02\xCC\xD5\x18\x02\x21\x59\xA0\xE3\x00\x40\xA0\xE3");
3478+
}
3479+
};
3480+
3481+
struct rabbids_eu : public GameHackCheat
3482+
{
3483+
void Run() override
3484+
{
3485+
if(0xe28dd02c == read32(0x203d108))
3486+
write32(0x203d108, 0xeb0efcbc);
3487+
write32(0x23ff100, 0xe59d1000);
3488+
write(0x23ff104, 48, "\x01\x00\x51\xE3\x03\x00\x00\x1A\x10\x10\x8F\xE2\x1E\x00\x91\xE8\x00\x30\x81\xE5\x00\x40\x82\xE5\x2C\xD0\x8D\xE2\x1E\xFF\x2F\xE1\x4C\xDA\x18\x02\x54\xDA\x18\x02\x21\x59\xA0\xE3\x00\x40\xA0\xE3");
3489+
}
3490+
};
3491+
}
3492+
3493+
void GameHackCheat::write08(uint32_t address, uint8_t value)
3494+
{
3495+
_MMU_ARM9_write08(address, value);
3496+
}
3497+
3498+
void GameHackCheat::write(uint32_t address, size_t sz, void* value)
3499+
{
3500+
for(size_t i = 0; i < sz; i++)
3501+
write08(address + i, ((uint8_t*)value)[i]);
3502+
}
3503+
3504+
void GameHackCheat::write32(uint32_t address, uint32_t value)
3505+
{
3506+
_MMU_ARM9_write32(address, value);
3507+
}
3508+
3509+
uint32_t GameHackCheat::read32(uint32_t address)
3510+
{
3511+
return _MMU_ARM9_read32(address);
3512+
}
3513+
34653514
void TCommonSettings::GameHacks::apply()
34663515
{
34673516
clear();
34683517
if(!en) return;
34693518

34703519
flags.overclock = gameInfo.IsCode("IPK") || gameInfo.IsCode("IPG"); //HG/SS
34713520
flags.stylusjitter = gameInfo.IsCode("YDM"); //CSI: Dark Motives
3521+
3522+
//Rabbids Go Home
3523+
if(gameInfo.IsCode("VRGE")) flags.cheats.emplace_back(new rabbids_us());
3524+
if(gameInfo.IsCode("VRGV")) flags.cheats.emplace_back(new rabbids_eu());
34723525
}
34733526

34743527
void TCommonSettings::GameHacks::clear()
34753528
{
3476-
memset(&flags,0,sizeof(flags));
3529+
reconstruct(&flags);
34773530
}

desmume/src/NDSSystem.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <string.h>
2323
#include <string>
2424
#include <vector>
25+
#include <memory>
2526

2627
#include "types.h"
2728
#include "ROMReader.h"
@@ -487,7 +488,17 @@ enum MicMode
487488
MicMode_Physical = 3
488489
};
489490

490-
extern struct TCommonSettings
491+
struct GameHackCheat
492+
{
493+
virtual void Run() {}
494+
495+
void write08(uint32_t address, uint8_t value);
496+
void write(uint32_t address, size_t sz, void* value);
497+
void write32(uint32_t address, uint32_t value);
498+
uint32_t read32(uint32_t address);
499+
};
500+
501+
struct TCommonSettings
491502
{
492503
bool GFX3D_HighResolutionInterpolateColor;
493504
bool GFX3D_EdgeMark;
@@ -536,10 +547,12 @@ extern struct TCommonSettings
536547

537548
struct
538549
{
539-
bool overclock;
540-
bool stylusjitter;
550+
bool overclock = false;
551+
bool stylusjitter = false;
552+
std::vector<std::shared_ptr<GameHackCheat>> cheats;
541553
} flags;
542554

555+
543556
void apply();
544557
void clear();
545558
} gamehacks;
@@ -594,7 +607,9 @@ extern struct TCommonSettings
594607

595608
TCommonSettings();
596609
bool single_core();
597-
} CommonSettings;
610+
};
611+
612+
extern TCommonSettings CommonSettings;
598613

599614
void NDS_RunAdvansceneAutoImport();
600615

0 commit comments

Comments
 (0)