From 19ab2e1081cfd94b048e7813610d6c8e4789307f Mon Sep 17 00:00:00 2001 From: iLag Date: Thu, 6 Apr 2017 10:46:37 -0700 Subject: [PATCH] Add multiline cheat support. Delimited based on any non-hexdec character. Individual codes can be split into two parts [8+4char] or in a single part [12char]. --- libretro.cpp | 99 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 71 insertions(+), 28 deletions(-) diff --git a/libretro.cpp b/libretro.cpp index ad43ddd4..fac68604 100644 --- a/libretro.cpp +++ b/libretro.cpp @@ -20,6 +20,10 @@ #include "../pgxp/pgxp_main.h" +#include +#include +#define ISHEXDEC ((codeLine[cursor]>='0') && (codeLine[cursor]<='9')) || ((codeLine[cursor]>='a') && (codeLine[cursor]<='f')) || ((codeLine[cursor]>='A') && (codeLine[cursor]<='F')) + struct retro_perf_callback perf_cb; retro_get_cpu_features_t perf_get_cpu_features_cb = NULL; retro_log_printf_t log_cb; @@ -4174,42 +4178,81 @@ size_t retro_get_memory_size(unsigned type) void retro_cheat_reset(void) { - MDFN_FlushGameCheats(1); + MDFN_FlushGameCheats(1); } -void retro_cheat_set(unsigned index, bool enabled, const char * code) +void retro_cheat_set(unsigned index, bool enabled, const char * codeLine) { - const CheatFormatStruct* cf = CheatFormats; - char name[256]; - MemoryPatch patch; + const CheatFormatStruct* cf = CheatFormats; + std::string name; + std::vector codeParts; + std::vector patches; + int matchLength=0; + int cursor; + std::string part; - //Decode the cheat - try - { - cf->DecodeCheat(std::string(code), &patch); - } - catch(std::exception &e) - { - return; - } + if (codeLine==NULL) return; - //Generate a name - sprintf(name,"cheat_%u",index); + //Break the code into Parts + for (cursor=0;;cursor++) + { + if (ISHEXDEC){ + matchLength++; + } else { + if (matchLength){ + part=codeLine+cursor-matchLength; + part.erase(matchLength,std::string::npos); + codeParts.push_back(part); + matchLength=0; + } + } + if (!codeLine[cursor]){ + break; + } + } + + for (cursor=0;cursorDecodeCheat(std::string(part), &patch); + patches.push_back(patch); + } + catch(std::exception &e) + { + continue; + } + } + } + + //Generate a name + name="cheat_"+index; + + for (cursor=0;cursor