2 // **********************************************************************
3 // The Cheat - A universal game cheater for Mac OS X
4 // (C) 2003-2005 Chaz McGarvey (BrokenZipper)
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)
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.
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.
22 #import "SearchData.h"
25 @implementation SearchData
30 if ( self = [super init
] ) {
31 [self setVariableType
:TCInt32
];
32 [self setIntegerSign
:TCSigned
];
33 [self setSearchOperator
:TCEqual
];
34 [self setValueUsed
:TCGivenValue
];
44 [_variableValue release
];
45 TCReleaseArray( _addresses
);
46 TCReleaseArray( _values
);
51 - (void)setProcess
:(Process
*)process
59 - (TCVariableType
)variableType
64 - (void)setVariableType
:(TCVariableType
)varType
66 // can't change the variable type when there has been a search
67 if ( ![self hasSearchedOnce
] ) {
68 _variableType
= varType
;
73 - (TCIntegerSign
)integerSign
78 - (void)setIntegerSign
:(TCIntegerSign
)sign
80 // can't change the integer sign when there has been a search
81 if ( ![self hasSearchedOnce
] ) {
87 - (TCSearchOperator
)searchOperator
92 - (void)setSearchOperator
:(TCSearchOperator
)op
98 - (TCSearchType
)valueUsed
100 if ( ![self hasSearchedOnce
] ) {
101 // if there is no search, then use search value no matter what
102 _value
= TCGivenValue
;
107 - (void)setValueUsed
:(TCSearchType
)value
113 - (Variable
*)searchValue
115 if ( !_variableValue
) {
116 // create a zero value if there is none
117 _variableValue
= [[Variable alloc
] init
];
118 [_variableValue setProcess
:_process
];
120 return _variableValue
;
123 - (void)setSearchValue
:(Variable
*)value
126 [_variableValue release
];
127 _variableValue
= value
;
131 - (unsigned)numberOfResults
134 return TCArrayElementCount( _addresses
);
144 - (void)setAddresses
:(TCArray
)addresses
146 TCReleaseArray( _addresses
);
147 _addresses
= addresses
;
150 // clear the undoes and redoes if the search is cleared
155 // clear the stored values
156 [self setValues
:NULL
];
164 - (void)setValues
:(TCArray
)values
166 TCReleaseArray( _values
);
170 - (void)setValue
:(Variable
*)value atIndex
:(unsigned)index
173 if ( index
< TCArrayElementCount( _values
) ) {
174 TCArraySetElementAtIndex( _values
, index
, [value value
] );
182 return ( _values
!= NULL
);
185 - (Variable
*)variableAtIndex
:(unsigned)index
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
])];
193 return [var autorelease
];
198 - (NSString
*)stringForRow
:(unsigned)rowIndex
200 Variable
*var
= [self variableAtIndex
:rowIndex
];
203 if ( [self valuesLoaded
] ) {
204 if ( [var type
] == TCString
) {
205 return [NSString stringWithFormat
:@
"%@ = \"%@\"", [var addressString
], [var stringValue
]];
208 return [NSString stringWithFormat
:@
"%@ = %@", [var addressString
], [var stringValue
]];
212 return [var addressString
];
219 - (BOOL)hasSearchedOnce
221 return ( _addresses
!= NULL
);
235 - (void)didAddResults
254 - (BOOL)isTypeInteger
256 return _variableType
<= TCInt8
;
262 [self setAddresses
:NULL
];