]> Dogcows Code - chaz/thecheat/blob - SearchData.m
The Cheat 1.2.4
[chaz/thecheat] / SearchData.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
22 #import "SearchData.h"
23
24
25 @implementation SearchData
26
27
28 - (id)init
29 {
30 if ( self = [super init] ) {
31 [self setVariableType:TCInt32];
32 [self setIntegerSign:TCSigned];
33 [self setSearchOperator:TCEqual];
34 [self setValueUsed:TCGivenValue];
35
36 _undoes = -1;
37 _redoes = 0;
38 }
39 return self;
40 }
41
42 - (void)dealloc
43 {
44 [_variableValue release];
45 TCReleaseArray( _addresses );
46 TCReleaseArray( _values );
47 [super dealloc];
48 }
49
50
51 - (void)setProcess:(Process *)process
52 {
53 [process retain];
54 [_process release];
55 _process = process;
56 }
57
58
59 - (TCVariableType)variableType
60 {
61 return _variableType;
62 }
63
64 - (void)setVariableType:(TCVariableType)varType
65 {
66 // can't change the variable type when there has been a search
67 if ( ![self hasSearchedOnce] ) {
68 _variableType = varType;
69 }
70 }
71
72
73 - (TCIntegerSign)integerSign
74 {
75 return _integerSign;
76 }
77
78 - (void)setIntegerSign:(TCIntegerSign)sign
79 {
80 // can't change the integer sign when there has been a search
81 if ( ![self hasSearchedOnce] ) {
82 _integerSign = sign;
83 }
84 }
85
86
87 - (TCSearchOperator)searchOperator
88 {
89 return _operator;
90 }
91
92 - (void)setSearchOperator:(TCSearchOperator)op
93 {
94 _operator = op;
95 }
96
97
98 - (TCSearchType)valueUsed
99 {
100 if ( ![self hasSearchedOnce] ) {
101 // if there is no search, then use search value no matter what
102 _value = TCGivenValue;
103 }
104 return _value;
105 }
106
107 - (void)setValueUsed:(TCSearchType)value
108 {
109 _value = value;
110 }
111
112
113 - (Variable *)searchValue
114 {
115 if ( !_variableValue ) {
116 // create a zero value if there is none
117 _variableValue = [[Variable alloc] init];
118 [_variableValue setProcess:_process];
119 }
120 return _variableValue;
121 }
122
123 - (void)setSearchValue:(Variable *)value
124 {
125 [value retain];
126 [_variableValue release];
127 _variableValue = value;
128 }
129
130
131 - (unsigned)numberOfResults
132 {
133 if ( _addresses ) {
134 return TCArrayElementCount( _addresses );
135 }
136 return 0;
137 }
138
139 - (TCArray)addresses
140 {
141 return _addresses;
142 }
143
144 - (void)setAddresses:(TCArray)addresses
145 {
146 TCReleaseArray( _addresses );
147 _addresses = addresses;
148
149 if ( !_addresses ) {
150 // clear the undoes and redoes if the search is cleared
151 _undoes = -1;
152 _redoes = 0;
153 }
154
155 // clear the stored values
156 [self setValues:NULL];
157 }
158
159 - (TCArray)values
160 {
161 return _values;
162 }
163
164 - (void)setValues:(TCArray)values
165 {
166 TCReleaseArray( _values );
167 _values = values;
168 }
169
170 - (void)setValue:(Variable *)value atIndex:(unsigned)index
171 {
172 if ( _values ) {
173 if ( index < TCArrayElementCount( _values ) ) {
174 TCArraySetElementAtIndex( _values, index, [value value] );
175 }
176 }
177
178 }
179
180 - (BOOL)valuesLoaded
181 {
182 return ( _values != NULL );
183 }
184
185 - (Variable *)variableAtIndex:(unsigned)index
186 {
187 if ( [self hasSearchedOnce] ) {
188 Variable *var = [[Variable alloc] initWithType:[self variableType] integerSign:[self integerSign]];
189 [var setAddress:*(TCAddress *)TCArrayElementAtIndex( [self addresses], index )];
190 if ( [self valuesLoaded] ) {
191 [var setValue:TCArrayElementAtIndex( [self values], index ) size:TCArrayElementSize([self values])];
192 }
193 return [var autorelease];
194 }
195 return nil;
196 }
197
198 - (NSString *)stringForRow:(unsigned)rowIndex
199 {
200 Variable *var = [self variableAtIndex:rowIndex];
201
202 if ( var ) {
203 if ( [self valuesLoaded] ) {
204 if ( [var type] == TCString ) {
205 return [NSString stringWithFormat:@"%@ = \"%@\"", [var addressString], [var stringValue]];
206 }
207 else {
208 return [NSString stringWithFormat:@"%@ = %@", [var addressString], [var stringValue]];
209 }
210 }
211 else {
212 return [var addressString];
213 }
214 }
215 return @"";
216 }
217
218
219 - (BOOL)hasSearchedOnce
220 {
221 return ( _addresses != NULL );
222 }
223
224
225 - (int)undoesLeft
226 {
227 return _undoes;
228 }
229
230 - (int)redoesLeft
231 {
232 return _redoes;
233 }
234
235 - (void)didAddResults
236 {
237 _undoes++;
238 _redoes = 0;
239 }
240
241 - (void)didUndo
242 {
243 _undoes--;
244 _redoes++;
245 }
246
247 - (void)didRedo
248 {
249 _undoes++;
250 _redoes--;
251 }
252
253
254 - (BOOL)isTypeInteger
255 {
256 return _variableType <= TCInt8;
257 }
258
259
260 - (void)clearResults
261 {
262 [self setAddresses:NULL];
263 }
264
265
266 @end
This page took 0.040167 seconds and 4 git commands to generate.