author | peter1138 |
Sun, 03 Aug 2008 17:35:08 +0000 | |
changeset 9834 | 7474149531c1 |
parent 9390 | 88d36f907e96 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
9111
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
8965
diff
changeset
|
3 |
/** @file cheat.cpp Handling (loading/saving/initializing) of cheats. */ |
6201
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6091
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
6 |
#include "saveload.h" |
|
8965
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8925
diff
changeset
|
7 |
#include "cheat_type.h" |
0 | 8 |
|
8965
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8925
diff
changeset
|
9 |
Cheats _cheats; |
0 | 10 |
|
8965
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8925
diff
changeset
|
11 |
void InitializeCheats() |
0 | 12 |
{ |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
13 |
memset(&_cheats, 0, sizeof(Cheats)); |
0 | 14 |
} |
15 |
||
6247 | 16 |
static void Save_CHTS() |
0 | 17 |
{ |
8965
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8925
diff
changeset
|
18 |
/* Cannot use lengthof because _cheats is of type Cheats, not Cheat */ |
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8925
diff
changeset
|
19 |
byte count = sizeof(_cheats) / sizeof(Cheat); |
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8925
diff
changeset
|
20 |
Cheat *cht = (Cheat*) &_cheats; |
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8925
diff
changeset
|
21 |
Cheat *cht_last = &cht[count]; |
0 | 22 |
|
2951 | 23 |
SlSetLength(count * 2); |
24 |
for (; cht != cht_last; cht++) { |
|
0 | 25 |
SlWriteByte(cht->been_used); |
26 |
SlWriteByte(cht->value); |
|
27 |
} |
|
28 |
} |
|
29 |
||
6247 | 30 |
static void Load_CHTS() |
0 | 31 |
{ |
8965
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8925
diff
changeset
|
32 |
Cheat *cht = (Cheat*)&_cheats; |
9390
88d36f907e96
(svn r13301) -Fix [FS#1997]: resolve more MSVC 9 x64 warnings.
rubidium
parents:
9111
diff
changeset
|
33 |
size_t count = SlGetFieldLength() / 2; |
0 | 34 |
|
8819 | 35 |
for (uint i = 0; i < count; i++) { |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
36 |
cht[i].been_used = (SlReadByte() != 0); |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
37 |
cht[i].value = (SlReadByte() != 0); |
0 | 38 |
} |
39 |
} |
|
40 |
||
8965
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8925
diff
changeset
|
41 |
bool CheatHasBeenUsed() |
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8925
diff
changeset
|
42 |
{ |
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8925
diff
changeset
|
43 |
/* Cannot use lengthof because _cheats is of type Cheats, not Cheat */ |
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8925
diff
changeset
|
44 |
const Cheat* cht = (Cheat*)&_cheats; |
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8925
diff
changeset
|
45 |
const Cheat* cht_last = &cht[sizeof(_cheats) / sizeof(Cheat)]; |
0 | 46 |
|
8965
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8925
diff
changeset
|
47 |
for (; cht != cht_last; cht++) { |
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8925
diff
changeset
|
48 |
if (cht->been_used) return true; |
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8925
diff
changeset
|
49 |
} |
0 | 50 |
|
8965
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8925
diff
changeset
|
51 |
return false; |
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8925
diff
changeset
|
52 |
} |
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8925
diff
changeset
|
53 |
|
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8925
diff
changeset
|
54 |
|
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8925
diff
changeset
|
55 |
extern const ChunkHandler _cheat_chunk_handlers[] = { |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
56 |
{ 'CHTS', Save_CHTS, Load_CHTS, CH_RIFF | CH_LAST} |
0 | 57 |
}; |