2 // **********************************************************************
3 // The Cheat - A universal game cheater for Mac OS X
4 // (C) 2003-2005 Chaz McGarvey (BrokenZipper)
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 1, or (at your option)
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 @implementation CheatData
27 // #############################################################################
28 #pragma mark Initialization
29 // #############################################################################
33 if ( self = [super init
] )
36 [self setWindowTitle
:@
""];
37 [self setCheatInfo
:@
""];
38 [self setProcess
:[[[Process alloc
] initWithName
:@
"No Target Set" version
:@
""] autorelease
]];
41 myRepeatInterval
= 5.0;
44 myVariables
= [[NSMutableArray alloc
] init
];
52 [myWindowTitle release
];
53 [myCheatInfo release
];
55 [myVariables release
];
61 // #############################################################################
63 // #############################################################################
65 - (id)initWithCoder
:(NSCoder
*)coder
67 if ( self = [super init
] )
69 [self setWindowTitle
:[coder decodeObject
]];
70 [self setCheatInfo
:[coder decodeObject
]];
71 [self setProcess
:[coder decodeObject
]];
72 myVariables
= [[coder decodeObject
] retain
];
73 [coder decodeValueOfObjCType
:@encode(BOOL) at
:&myRepeats
];
74 [coder decodeValueOfObjCType
:@encode(NSTimeInterval
) at
:&myRepeatInterval
];
79 - (void)encodeWithCoder
:(NSCoder
*)coder
81 [coder encodeObject
:myWindowTitle
];
82 [coder encodeObject
:myCheatInfo
];
83 [coder encodeObject
:myProcess
];
84 [coder encodeObject
:myVariables
];
85 [coder encodeValueOfObjCType
:@encode(BOOL) at
:&myRepeats
];
86 [coder encodeValueOfObjCType
:@encode(NSTimeInterval
) at
:&myRepeatInterval
];
90 // #############################################################################
91 #pragma mark Accessing Properties
92 // #############################################################################
95 - (NSString
*)windowTitle
100 - (NSString
*)cheatInfo
105 - (NSString
*)gameName
107 return [myProcess name
];
110 - (NSString
*)gameVersion
112 return [myProcess version
];
125 - (NSTimeInterval
)repeatInterval
127 return myRepeatInterval
;
131 - (void)setWindowTitle
:(NSString
*)title
134 title
= [NSString stringWithString
:@
""];
137 [myWindowTitle release
];
138 myWindowTitle
= title
;
141 - (void)setCheatInfo
:(NSString
*)info
144 info
= [NSString stringWithString
:@
"Description not provided."];
147 [myCheatInfo release
];
151 - (void)setProcess
:(Process
*)process
158 - (void)setRepeats
:(BOOL)repeats
163 - (void)setRepeatInterval
:(NSTimeInterval
)interval
165 myRepeatInterval
= interval
;
169 // #############################################################################
170 #pragma mark Variables
171 // #############################################################################
173 - (NSArray
*)variables
175 return [NSArray arrayWithArray
:myVariables
];
178 - (unsigned)variableCount
180 return [myVariables count
];
183 - (unsigned)indexOfVariable
:(Variable
*)variable
185 return [myVariables indexOfObject
:variable
];
188 - (Variable
*)variableAtIndex
:(unsigned)index
190 return [myVariables objectAtIndex
:index
];
193 - (Variable
*)lastVariable
195 return [myVariables lastObject
];
199 - (void)addVariable
:(Variable
*)variable
201 [myVariables addObject
:variable
];
204 - (void)insertVariable
:(Variable
*)variable atIndex
:(unsigned)index
206 [myVariables insertObject
:variable atIndex
:index
];
210 - (void)removeAllVariables
212 [myVariables removeAllObjects
];
215 - (void)removeVariable
:(Variable
*)variable
217 [myVariables removeObject
:variable
];
220 - (void)removeVariableAtIndex
:(unsigned)index
222 [myVariables removeObjectAtIndex
:index
];
226 - (NSArray
*)enabledVariables
228 NSMutableArray
*vars
;
231 top
= [myVariables count
];
232 vars
= [[NSMutableArray alloc
] init
];
234 for ( i
= 0; i
< top
; i
++ ) {
235 Variable
*var
= [myVariables objectAtIndex
:i
];
236 if ( [var isEnabled
] ) {
237 [vars addObject
:var
];
240 return [vars autorelease
];
243 - (unsigned)enabledVariableCount
245 return [[self enabledVariables
] count
];