]> Dogcows Code - chaz/thecheat/blob - SearchData.m
update contact information and project URL
[chaz/thecheat] / SearchData.m
1
2 /*
3 * The Cheat - The legendary universal game trainer for Mac OS X.
4 * http://www.brokenzipper.com/trac/wiki/TheCheat
5 *
6 * Copyright (c) 2003-2011, Charles McGarvey et al.
7 *
8 * Distributable under the terms and conditions of the 2-clause BSD
9 * license; see the file COPYING for the legal text of the license.
10 */
11
12
13 #import "SearchData.h"
14
15
16 @implementation SearchData
17
18
19 - (id)init
20 {
21 if ( self = [super init] ) {
22 [self setVariableType:TCInt32];
23 [self setIntegerSign:TCSigned];
24 [self setSearchOperator:TCEqual];
25 [self setValueUsed:TCGivenValue];
26
27 _undoes = -1;
28 _redoes = 0;
29 }
30 return self;
31 }
32
33 - (void)dealloc
34 {
35 [_variableValue release];
36 TCReleaseArray( _addresses );
37 TCReleaseArray( _values );
38 [super dealloc];
39 }
40
41
42 - (void)setProcess:(Process *)process
43 {
44 [process retain];
45 [_process release];
46 _process = process;
47 }
48
49
50 - (TCVariableType)variableType
51 {
52 return _variableType;
53 }
54
55 - (void)setVariableType:(TCVariableType)varType
56 {
57 // can't change the variable type when there has been a search
58 if ( ![self hasSearchedOnce] ) {
59 _variableType = varType;
60 }
61 }
62
63
64 - (TCIntegerSign)integerSign
65 {
66 return _integerSign;
67 }
68
69 - (void)setIntegerSign:(TCIntegerSign)sign
70 {
71 // can't change the integer sign when there has been a search
72 if ( ![self hasSearchedOnce] ) {
73 _integerSign = sign;
74 }
75 }
76
77
78 - (TCSearchOperator)searchOperator
79 {
80 return _operator;
81 }
82
83 - (void)setSearchOperator:(TCSearchOperator)op
84 {
85 _operator = op;
86 }
87
88
89 - (TCSearchType)valueUsed
90 {
91 if ( ![self hasSearchedOnce] ) {
92 // if there is no search, then use search value no matter what
93 _value = TCGivenValue;
94 }
95 return _value;
96 }
97
98 - (void)setValueUsed:(TCSearchType)value
99 {
100 _value = value;
101 }
102
103
104 - (Variable *)searchValue
105 {
106 if ( !_variableValue ) {
107 // create a zero value if there is none
108 _variableValue = [[Variable alloc] init];
109 [_variableValue setProcess:_process];
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
171 - (BOOL)valuesLoaded
172 {
173 return ( _values != NULL );
174 }
175
176 - (Variable *)variableAtIndex:(unsigned)index
177 {
178 if ( [self hasSearchedOnce] ) {
179 Variable *var = [[Variable alloc] initWithType:[self variableType] integerSign:[self integerSign]];
180 [var setAddress:*(TCAddress *)TCArrayElementAtIndex( [self addresses], index )];
181 if ( [self valuesLoaded] ) {
182 [var setValue:TCArrayElementAtIndex( [self values], index ) size:TCArrayElementSize([self values])];
183 }
184 return [var autorelease];
185 }
186 return nil;
187 }
188
189 - (NSString *)stringForRow:(unsigned)rowIndex
190 {
191 Variable *var = [self variableAtIndex:rowIndex];
192
193 if ( var ) {
194 if ( [self valuesLoaded] ) {
195 if ( [var type] == TCString ) {
196 return [NSString stringWithFormat:@"%@ = \"%@\"", [var addressString], [var stringValue]];
197 }
198 else {
199 return [NSString stringWithFormat:@"%@ = %@", [var addressString], [var stringValue]];
200 }
201 }
202 else {
203 return [var addressString];
204 }
205 }
206 return @"";
207 }
208
209
210 - (BOOL)hasSearchedOnce
211 {
212 return ( _addresses != NULL );
213 }
214
215
216 - (int)undoesLeft
217 {
218 return _undoes;
219 }
220
221 - (int)redoesLeft
222 {
223 return _redoes;
224 }
225
226 - (void)didAddResults
227 {
228 _undoes++;
229 _redoes = 0;
230 }
231
232 - (void)didUndo
233 {
234 _undoes--;
235 _redoes++;
236 }
237
238 - (void)didRedo
239 {
240 _undoes++;
241 _redoes--;
242 }
243
244
245 - (BOOL)isTypeInteger
246 {
247 return _variableType <= TCInt8;
248 }
249
250
251 - (void)clearResults
252 {
253 [self setAddresses:NULL];
254 }
255
256
257 @end
This page took 0.038225 seconds and 4 git commands to generate.