cheat.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. class Cheat {
  2. public:
  3. enum type_t {
  4. ProActionReplay,
  5. GameGenie,
  6. };
  7. struct cheat_t {
  8. bool enabled;
  9. string code;
  10. string desc;
  11. unsigned count;
  12. array<unsigned> addr;
  13. array<uint8_t> data;
  14. cheat_t& operator=(const cheat_t&);
  15. bool operator<(const cheat_t&);
  16. };
  17. bool decode(const char *s, cheat_t &item) const;
  18. bool read(unsigned addr, uint8_t &data) const;
  19. bool enabled() const;
  20. void enable();
  21. void disable();
  22. inline unsigned count() const { return code.size(); }
  23. inline bool active() const { return cheat_enabled; }
  24. inline bool exists(unsigned addr) const { return mask[addr >> 3] & 1 << (addr & 7); }
  25. bool add(bool enable, const char *code, const char *desc);
  26. bool edit(unsigned i, bool enable, const char *code, const char *desc);
  27. bool remove(unsigned i);
  28. bool get(unsigned i, cheat_t &item) const;
  29. bool enabled(unsigned i) const;
  30. void enable(unsigned i);
  31. void disable(unsigned i);
  32. bool load(const char *fn);
  33. bool save(const char *fn) const;
  34. void clear();
  35. Cheat();
  36. private:
  37. bool cheat_enabled; //cheat_enabled == (cheat_enabled_code_exists && cheat_system_enabled);
  38. bool cheat_enabled_code_exists;
  39. bool cheat_system_enabled;
  40. uint8_t mask[0x200000];
  41. vector<cheat_t> code;
  42. bool decode(const char *str, unsigned &addr, uint8_t &data, type_t &type) const;
  43. bool encode(string &str, unsigned addr, uint8_t data, type_t type) const;
  44. void update_cheat_status();
  45. unsigned mirror_address(unsigned addr) const;
  46. void update(const cheat_t& item);
  47. void set(unsigned addr);
  48. void clear(unsigned addr);
  49. string& encode_description(string &desc) const;
  50. string& decode_description(string &desc) const;
  51. };
  52. extern Cheat cheat;