mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-07 22:55:40 +12:00
Merge pull request #571 from jonian/lr-cheats
Libretro: Add support for cheats
This commit is contained in:
commit
e9f98bffa9
1 changed files with 22 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
#include <libretro.h>
|
#include <libretro.h>
|
||||||
|
|
||||||
|
@ -381,5 +382,24 @@ void* retro_get_memory_data(uint id) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void retro_cheat_set(uint index, bool enabled, const char* code) {}
|
void retro_cheat_set(uint index, bool enabled, const char* code) {
|
||||||
void retro_cheat_reset() {}
|
std::string cheatCode = std::regex_replace(code, std::regex("[^0-9a-fA-F]"), "");
|
||||||
|
std::vector<u8> bytes;
|
||||||
|
|
||||||
|
for (usize i = 0; i < cheatCode.size(); i += 2) {
|
||||||
|
std::string hex = cheatCode.substr(i, 2);
|
||||||
|
bytes.push_back((u8)std::stoul(hex, nullptr, 16));
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 id = emulator->getCheats().addCheat(bytes.data(), bytes.size());
|
||||||
|
|
||||||
|
if (enabled) {
|
||||||
|
emulator->getCheats().enableCheat(id);
|
||||||
|
} else {
|
||||||
|
emulator->getCheats().disableCheat(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void retro_cheat_reset() {
|
||||||
|
emulator->getCheats().reset();
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue