static inline bool S9xCompileCheat(struct SCheatItem& cheat, bool8 save_current_value) { std::string codes(cheat.code); std::vector<SCheat> cheatVector; if (codes.empty() || codes[codes.length() - 1] == '+') return false; // std::getline cannot handle this case std::istringstream iss(codes); std::string code; while(std::getline(iss, code, '+')) { SCheat c; if (S9xProActionReplayToRaw(code.c_str(), c.address, c.byte) == NULL || S9xGameGenieToRaw(code.c_str(), c.address, c.byte) == NULL) { c.saved = save_current_value; if (c.saved) { c.saved_byte = S9xGetByteFree(c.address); } cheatVector.push_back(c); } else { uint32 address; uint8 bytes[3]; uint8 num_bytes; if (S9xGoldFingerToRaw(code.c_str(), address, num_bytes, bytes) == NULL) { for (int i = 0; i < num_bytes; i++) { c.address = address + i; c.byte = bytes[i]; c.saved = save_current_value; if (c.saved) { c.saved_byte = S9xGetByteFree(c.address); } cheatVector.push_back(c); } } else return false; // invalid format } } cheat.c.clear(); copy(cheatVector.begin(), cheatVector.end(), std::back_inserter(cheat.c)); return true; }
void S9xAddCheat (bool8 enable, bool8 save_current_value, uint32 address, uint8 byte) { if (Cheat.num_cheats < sizeof(Cheat.c) / sizeof(Cheat.c[0])) { Cheat.c[Cheat.num_cheats].address = address; Cheat.c[Cheat.num_cheats].byte = byte; Cheat.c[Cheat.num_cheats].enabled = enable; if (save_current_value) { Cheat.c[Cheat.num_cheats].saved_byte = S9xGetByteFree(address); Cheat.c[Cheat.num_cheats].saved = TRUE; } Cheat.num_cheats++; } }