3 * The Cheat - The legendary universal game trainer for Mac OS X.
4 * http://www.dogcows.com/chaz/wiki/TheCheat
6 * Copyright (c) 2003-2010, Charles McGarvey et al.
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.
13 #import "SearchData.h"
16 @implementation SearchData
21 if ( self = [super init
] ) {
22 [self setVariableType
:TCInt32
];
23 [self setIntegerSign
:TCSigned
];
24 [self setSearchOperator
:TCEqual
];
25 [self setValueUsed
:TCGivenValue
];
35 [_variableValue release
];
36 TCReleaseArray( _addresses
);
37 TCReleaseArray( _values
);
42 - (void)setProcess
:(Process
*)process
50 - (TCVariableType
)variableType
55 - (void)setVariableType
:(TCVariableType
)varType
57 // can't change the variable type when there has been a search
58 if ( ![self hasSearchedOnce
] ) {
59 _variableType
= varType
;
64 - (TCIntegerSign
)integerSign
69 - (void)setIntegerSign
:(TCIntegerSign
)sign
71 // can't change the integer sign when there has been a search
72 if ( ![self hasSearchedOnce
] ) {
78 - (TCSearchOperator
)searchOperator
83 - (void)setSearchOperator
:(TCSearchOperator
)op
89 - (TCSearchType
)valueUsed
91 if ( ![self hasSearchedOnce
] ) {
92 // if there is no search, then use search value no matter what
93 _value
= TCGivenValue
;
98 - (void)setValueUsed
:(TCSearchType
)value
104 - (Variable
*)searchValue
106 if ( !_variableValue
) {
107 // create a zero value if there is none
108 _variableValue
= [[Variable alloc
] init
];
109 [_variableValue setProcess
:_process
];
111 return _variableValue
;
114 - (void)setSearchValue
:(Variable
*)value
117 [_variableValue release
];
118 _variableValue
= value
;
122 - (unsigned)numberOfResults
125 return TCArrayElementCount( _addresses
);
135 - (void)setAddresses
:(TCArray
)addresses
137 TCReleaseArray( _addresses
);
138 _addresses
= addresses
;
141 // clear the undoes and redoes if the search is cleared
146 // clear the stored values
147 [self setValues
:NULL
];
155 - (void)setValues
:(TCArray
)values
157 TCReleaseArray( _values
);
161 - (void)setValue
:(Variable
*)value atIndex
:(unsigned)index
164 if ( index
< TCArrayElementCount( _values
) ) {
165 TCArraySetElementAtIndex( _values
, index
, [value value
] );
173 return ( _values
!= NULL
);
176 - (Variable
*)variableAtIndex
:(unsigned)index
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
])];
184 return [var autorelease
];
189 - (NSString
*)stringForRow
:(unsigned)rowIndex
191 Variable
*var
= [self variableAtIndex
:rowIndex
];
194 if ( [self valuesLoaded
] ) {
195 if ( [var type
] == TCString
) {
196 return [NSString stringWithFormat
:@
"%@ = \"%@\"", [var addressString
], [var stringValue
]];
199 return [NSString stringWithFormat
:@
"%@ = %@", [var addressString
], [var stringValue
]];
203 return [var addressString
];
210 - (BOOL)hasSearchedOnce
212 return ( _addresses
!= NULL
);
226 - (void)didAddResults
245 - (BOOL)isTypeInteger
247 return _variableType
<= TCInt8
;
253 [self setAddresses
:NULL
];