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