]> Dogcows Code - chaz/thecheat/blob - CheatData.m
The Cheat 1.2.4
[chaz/thecheat] / CheatData.m
1
2 // **********************************************************************
3 // The Cheat - A universal game cheater for Mac OS X
4 // (C) 2003-2005 Chaz McGarvey (BrokenZipper)
5 //
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)
9 // any later version.
10 //
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.
15 //
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.
19 //
20
21 #import "CheatData.h"
22
23
24 @implementation CheatData
25
26
27 // #############################################################################
28 #pragma mark Initialization
29 // #############################################################################
30
31 - (id)init
32 {
33 if ( self = [super init] )
34 {
35 // set defaults
36 [self setWindowTitle:@""];
37 [self setCheatInfo:@""];
38 [self setProcess:[[[Process alloc] initWithName:@"No Target Set" version:@""] autorelease]];
39
40 myRepeats = NO;
41 myRepeatInterval = 5.0;
42
43 // create objects
44 myVariables = [[NSMutableArray alloc] init];
45 }
46 return self;
47 }
48
49 - (void)dealloc
50 {
51 // release objects
52 [myWindowTitle release];
53 [myCheatInfo release];
54 [myProcess release];
55 [myVariables release];
56
57 [super dealloc];
58 }
59
60
61 // #############################################################################
62 #pragma mark NSCoding
63 // #############################################################################
64
65 - (id)initWithCoder:(NSCoder *)coder
66 {
67 if ( self = [super init] )
68 {
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];
75 }
76 return self;
77 }
78
79 - (void)encodeWithCoder:(NSCoder *)coder
80 {
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];
87 }
88
89
90 // #############################################################################
91 #pragma mark Accessing Properties
92 // #############################################################################
93
94
95 - (NSString *)windowTitle
96 {
97 return myWindowTitle;
98 }
99
100 - (NSString *)cheatInfo
101 {
102 return myCheatInfo;
103 }
104
105 - (NSString *)gameName
106 {
107 return [myProcess name];
108 }
109
110 - (NSString *)gameVersion
111 {
112 return [myProcess version];
113 }
114
115 - (Process *)process
116 {
117 return myProcess;
118 }
119
120 - (BOOL)repeats
121 {
122 return myRepeats;
123 }
124
125 - (NSTimeInterval)repeatInterval
126 {
127 return myRepeatInterval;
128 }
129
130
131 - (void)setWindowTitle:(NSString *)title
132 {
133 if ( !title ) {
134 title = [NSString stringWithString:@""];
135 }
136 [title retain];
137 [myWindowTitle release];
138 myWindowTitle = title;
139 }
140
141 - (void)setCheatInfo:(NSString *)info
142 {
143 if ( !info ) {
144 info = [NSString stringWithString:@"Description not provided."];
145 }
146 [info retain];
147 [myCheatInfo release];
148 myCheatInfo = info;
149 }
150
151 - (void)setProcess:(Process *)process
152 {
153 [process retain];
154 [myProcess release];
155 myProcess = process;
156 }
157
158 - (void)setRepeats:(BOOL)repeats
159 {
160 myRepeats = repeats;
161 }
162
163 - (void)setRepeatInterval:(NSTimeInterval)interval
164 {
165 myRepeatInterval = interval;
166 }
167
168
169 // #############################################################################
170 #pragma mark Variables
171 // #############################################################################
172
173 - (NSArray *)variables
174 {
175 return [NSArray arrayWithArray:myVariables];
176 }
177
178 - (unsigned)variableCount
179 {
180 return [myVariables count];
181 }
182
183 - (unsigned)indexOfVariable:(Variable *)variable
184 {
185 return [myVariables indexOfObject:variable];
186 }
187
188 - (Variable *)variableAtIndex:(unsigned)index
189 {
190 return [myVariables objectAtIndex:index];
191 }
192
193 - (Variable *)lastVariable
194 {
195 return [myVariables lastObject];
196 }
197
198
199 - (void)addVariable:(Variable *)variable
200 {
201 [myVariables addObject:variable];
202 }
203
204 - (void)insertVariable:(Variable *)variable atIndex:(unsigned)index
205 {
206 [myVariables insertObject:variable atIndex:index];
207 }
208
209
210 - (void)removeAllVariables
211 {
212 [myVariables removeAllObjects];
213 }
214
215 - (void)removeVariable:(Variable *)variable
216 {
217 [myVariables removeObject:variable];
218 }
219
220 - (void)removeVariableAtIndex:(unsigned)index
221 {
222 [myVariables removeObjectAtIndex:index];
223 }
224
225
226 - (NSArray *)enabledVariables
227 {
228 NSMutableArray *vars;
229 int i, top;
230
231 top = [myVariables count];
232 vars = [[NSMutableArray alloc] init];
233
234 for ( i = 0; i < top; i++ ) {
235 Variable *var = [myVariables objectAtIndex:i];
236 if ( [var isEnabled] ) {
237 [vars addObject:var];
238 }
239 }
240 return [vars autorelease];
241 }
242
243 - (unsigned)enabledVariableCount
244 {
245 return [[self enabledVariables] count];
246 }
247
248
249 @end
This page took 0.039038 seconds and 4 git commands to generate.