cheat.cpp
Go to the documentation of this file.00001
00002
00005 #include "stdafx.h"
00006 #include "saveload.h"
00007 #include "cheat_type.h"
00008
00009 Cheats _cheats;
00010
00011 void InitializeCheats()
00012 {
00013 memset(&_cheats, 0, sizeof(Cheats));
00014 }
00015
00016 static void Save_CHTS()
00017 {
00018
00019 byte count = sizeof(_cheats) / sizeof(Cheat);
00020 Cheat *cht = (Cheat*) &_cheats;
00021 Cheat *cht_last = &cht[count];
00022
00023 SlSetLength(count * 2);
00024 for (; cht != cht_last; cht++) {
00025 SlWriteByte(cht->been_used);
00026 SlWriteByte(cht->value);
00027 }
00028 }
00029
00030 static void Load_CHTS()
00031 {
00032 Cheat *cht = (Cheat*)&_cheats;
00033 size_t count = SlGetFieldLength() / 2;
00034
00035 for (uint i = 0; i < count; i++) {
00036 cht[i].been_used = (SlReadByte() != 0);
00037 cht[i].value = (SlReadByte() != 0);
00038 }
00039 }
00040
00041 bool CheatHasBeenUsed()
00042 {
00043
00044 const Cheat* cht = (Cheat*)&_cheats;
00045 const Cheat* cht_last = &cht[sizeof(_cheats) / sizeof(Cheat)];
00046
00047 for (; cht != cht_last; cht++) {
00048 if (cht->been_used) return true;
00049 }
00050
00051 return false;
00052 }
00053
00054
00055 extern const ChunkHandler _cheat_chunk_handlers[] = {
00056 { 'CHTS', Save_CHTS, Load_CHTS, CH_RIFF | CH_LAST}
00057 };