Reduce code duplication
This commit is contained in:
@@ -134,25 +134,7 @@ void HydraCore::setPollInputCallback(void (*callback)()) { pollInputCallback = c
|
||||
void HydraCore::setCheckButtonCallback(s32 (*callback)(u32 player, hydra::ButtonType button)) { checkButtonCallback = callback; }
|
||||
|
||||
u32 HydraCore::addCheat(const u8* data, u32 size) {
|
||||
// Every 3DS cheat is a multiple of 64 bits == 8 bytes
|
||||
if ((size % 8) != 0) {
|
||||
return hydra::BAD_CHEAT;
|
||||
}
|
||||
|
||||
Cheats::Cheat cheat;
|
||||
cheat.enabled = true;
|
||||
cheat.type = Cheats::CheatType::ActionReplay;
|
||||
|
||||
for (u32 i = 0; i < size; i += 8) {
|
||||
auto read32 = [](const u8* ptr) { return (u32(ptr[3]) << 24) | (u32(ptr[2]) << 16) | (u32(ptr[1]) << 8) | u32(ptr[0]); };
|
||||
|
||||
// Data is passed to us in big endian so we bswap
|
||||
u32 firstWord = Common::swap32(read32(data + i));
|
||||
u32 secondWord = Common::swap32(read32(data + i + 4));
|
||||
cheat.instructions.insert(cheat.instructions.end(), {firstWord, secondWord});
|
||||
}
|
||||
|
||||
return emulator->getCheats().addCheat(cheat);
|
||||
return emulator->getCheats().addCheat(data, size);
|
||||
};
|
||||
|
||||
void HydraCore::removeCheat(u32 id) { emulator->getCheats().removeCheat(id); }
|
||||
|
||||
Reference in New Issue
Block a user