# cheat_sl.cpp

Go to the documentation of this file.

    00001 /* $Id: cheat_sl.cpp 15027 2009-01-12 17:11:45Z truebrain $ */
    00002
    00005 #include "../stdafx.h"
    00006 #include "../cheat_type.h"
    00007
    00008 #include "saveload.h"
    00009
    00010 static void Save_CHTS()
    00011 {
    00012   /* Cannot use lengthof because _cheats is of type Cheats, not Cheat */
    00013   byte count = sizeof(_cheats) / sizeof(Cheat);
    00014   Cheat *cht = (Cheat*) &_cheats;
    00015   Cheat *cht_last = &cht[count];
    00016
    00017   SlSetLength(count * 2);
    00018   for (; cht != cht_last; cht++) {
    00019     SlWriteByte(cht->been_used);
    00020     SlWriteByte(cht->value);
    00021   }
    00022 }
    00023
    00024 static void Load_CHTS()
    00025 {
    00026   Cheat *cht = (Cheat*)&_cheats;
    00027   size_t count = SlGetFieldLength() / 2;
    00028
    00029   for (uint i = 0; i < count; i++) {
    00030     cht[i].been_used = (SlReadByte() != 0);
    00031     cht[i].value     = (SlReadByte() != 0);
    00032   }
    00033 }
    00034
    00035 extern const ChunkHandler _cheat_chunk_handlers[] = {
    00036   { 'CHTS', Save_CHTS,     Load_CHTS,     CH_RIFF | CH_LAST}
    00037 };