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 - (TCVariableType
)variableType
56 - (void)setVariableType
:(TCVariableType
)varType
58 // can't change the variable type when there has been a search
59 if ( ![self hasSearchedOnce
] ) {
60 _variableType
= varType
;
65 - (TCIntegerSign
)integerSign
70 - (void)setIntegerSign
:(TCIntegerSign
)sign
72 // can't change the integer sign when there has been a search
73 if ( ![self hasSearchedOnce
] ) {
79 - (TCSearchOperator
)searchOperator
84 - (void)setSearchOperator
:(TCSearchOperator
)op
90 - (TCSearchType
)valueUsed
92 if ( ![self hasSearchedOnce
] ) {
93 // if there is no search, then use search value no matter what
94 _value
= TCGivenValue
;
99 - (void)setValueUsed
:(TCSearchType
)value
105 - (Variable
*)searchValue
107 if ( !_variableValue
) {
108 // create a zero value if there is none
109 _variableValue
= [[Variable alloc
] init
];
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
] );
172 return ( _values
!= NULL
);
175 - (Variable
*)variableAtIndex
:(unsigned)index
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
])];
183 return [var autorelease
];
188 - (NSString
*)stringForRow
:(unsigned)rowIndex
190 Variable
*var
= [self variableAtIndex
:rowIndex
];
193 if ( [self valuesLoaded
] ) {
194 if ( [var type
] == TCString
) {
195 return [NSString stringWithFormat
:@
"%@ = \"%@\"", [var addressString
], [var stringValue
]];
198 return [NSString stringWithFormat
:@
"%@ = %@", [var addressString
], [var stringValue
]];
202 return [var addressString
];
209 - (BOOL)hasSearchedOnce
211 return ( _addresses
!= NULL
);
225 - (void)didAddResults
244 - (BOOL)isTypeInteger
246 return _variableType
<= TCInt8
;
252 [self setAddresses
:NULL
];