]> Dogcows Code - chaz/thecheat/blob - DocCheaterDelegate.m
update contact information and project URL
[chaz/thecheat] / DocCheaterDelegate.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 "CheatDocument.h"
14
15
16 @implementation CheatDocument ( DocCheaterDelegate )
17
18
19 - (void)cheaterDidConnect:(Cheater *)cheater
20 {
21 ChazLog( @"cheaterDidConnect:" );
22 [ibStatusText setDefaultStatus:[self defaultStatusString]];
23 // update the interface
24 [self updateInterface];
25 }
26
27 - (void)cheaterDidDisconnect:(Cheater *)cheater
28 {
29 ChazLog( @"cheaterDidDisonnect:" );
30 [self disconnectFromCheater];
31 // update status
32 [self showError:@"Disconnected by server."];
33 [ibStatusBar setIndeterminate:NO];
34 [ibStatusBar setDoubleValue:0.0];
35 [ibStatusBar stopAnimation:self];
36 // update the interface
37 [self updateInterface];
38 }
39
40
41 - (void)cheaterRequiresAuthentication:(Cheater *)cheater
42 {
43 ChazLog( @"cheaterRequiresAuthentication:" );
44
45 [self ibRunPasswordSheet:nil];
46 }
47
48 - (void)cheaterRejectedPassword:(Cheater *)cheater
49 {
50 ChazLog( @"cheaterRejectedPassword" );
51
52
53 }
54
55 - (void)cheaterAcceptedPassword:(Cheater *)cheater
56 {
57 ChazLog( @"cheaterAcceptedPassword" );
58
59 [ibStatusText setTemporaryStatus:@"Password Accepted"];
60 }
61
62
63 - (void)cheater:(Cheater *)cheater didFindProcesses:(NSArray *)processes
64 {
65 NSMenu *processMenu;
66 NSMenuItem *menuItem;
67
68 unsigned i, len;
69
70 Process *selectThis = nil;
71
72 ChazLog( @"cheater:didFindProcesses:" );
73
74 // create and set the server popup menu
75 processMenu = [[NSMenu alloc] init];
76 [processMenu setAutoenablesItems:YES];
77
78 // add menu items
79 // processes returned
80 len = [processes count];
81 for ( i = 0; i < len; i++ ) {
82 Process *item = [processes objectAtIndex:i];
83
84 menuItem = [[NSMenuItem alloc] init];
85 [menuItem setTarget:self];
86 [menuItem setAction:@selector(ibSetProcess:)];
87 [menuItem setTitle:[item name]];
88 [menuItem setImage:[item icon]];
89 [menuItem setRepresentedObject:item];
90 [processMenu addItem:menuItem];
91 [menuItem release];
92
93 // check and see if our document uses this application
94 if ( [self isLoadedFromFile] && [[_cheatData process] sameApplicationAs:item] ) {
95 selectThis = item;
96 }
97 }
98 // set the menu
99 [ibProcessPopup setMenu:processMenu];
100 [processMenu release];
101
102 // if we're loaded from a file, select the process matching
103 // the one saved, if it is launched.
104 if ( selectThis ) {
105 [_cheater setTarget:selectThis];
106 }
107 // otherwise, select the global target
108 else if ( selectThis = [CheatDocument globalTarget] ) {
109 ChazLog( @"setting global target" );
110 [_cheater setTarget:selectThis];
111 }
112 // otherwise, select the first process in this list
113 else if ( len > 0 ) {
114 [_cheater setTarget:[processes objectAtIndex:0]];
115 }
116 }
117
118 - (void)cheater:(Cheater *)cheater didAddProcess:(Process *)process
119 {
120 NSMenu *processMenu = [ibProcessPopup menu];
121 NSMenuItem *menuItem;
122
123 Process *savedTarget = [_cheatData process];
124
125 // add the newly found process to the process popup
126 menuItem = [[NSMenuItem alloc] init];
127 [menuItem setTarget:self];
128 [menuItem setAction:@selector(ibSetProcess:)];
129 [menuItem setTitle:[process name]];
130 [menuItem setImage:[process icon]];
131 [menuItem setRepresentedObject:process];
132 [processMenu addItem:menuItem];
133 [menuItem release];
134
135 // make this the target if appropiate
136 if ( _status == TCIdleStatus &&
137 ![_searchData hasSearchedOnce] &&
138 [savedTarget sameApplicationAs:process] &&
139 ![savedTarget sameApplicationAs:_process] ) {
140 [_cheater setTarget:process];
141 }
142 }
143
144 - (void)cheater:(Cheater *)cheater didRemoveProcess:(Process *)process
145 {
146 NSMenu *processes = [ibProcessPopup menu];
147 // remove the service from the menu
148 [processes removeItemWithRepresentedObject:process];
149
150 // if this is the current process, select the first one
151 if ( [_process isEqual:process] ) {
152 [_process release];
153 _process = nil;
154
155 if ( [processes numberOfItems] > 0 ) {
156 [_cheater setTarget:[[processes itemAtIndex:0] representedObject]];
157 }
158 }
159 }
160
161
162 - (void)cheater:(Cheater *)cheater didSetTarget:(Process *)target
163 {
164 ChazLog( @"cheater:setTarget:" );
165
166 // save a reference to the process
167 [_process release];
168 _process = [target retain];
169
170 [CheatDocument setGlobalTarget:_process];
171
172 // make sure the correct item is selected
173 [ibProcessPopup selectItemAtIndex:[ibProcessPopup indexOfItemWithRepresentedObject:target]];
174 //[ibProcessPopup selectItemWithTitle:[target name]];
175
176 // apply the name and version to the document if the doc isn't saved
177 if ( ![self isLoadedFromFile] ) {
178 [_cheatData setProcess:target];
179 }
180
181 [ibStatusText setTemporaryStatus:[NSString stringWithFormat:@"Target is %@.", [target name]] duration:2.0];
182 [self updateInterface];
183 }
184
185 - (void)cheaterPausedTarget:(Cheater *)cheater
186 {
187 _isTargetPaused = YES;
188 [ibStatusText setTemporaryStatus:@"Target Paused"];
189 }
190
191 - (void)cheaterResumedTarget:(Cheater *)cheater
192 {
193 _isTargetPaused = NO;
194 [ibStatusText setTemporaryStatus:@"Target Resumed"];
195 }
196
197
198 - (void)cheater:(Cheater *)cheater didFindVariables:(TCArray)variables actualAmount:(unsigned)count
199 {
200 if ( _status == TCSearchingStatus ) {
201 _status = TCIdleStatus;
202
203 // do something with the variables
204 [_searchData setAddresses:variables];
205 [_searchData didAddResults];
206 [ibSearchVariableTable reloadData];
207
208 [self setActualResults:count];
209
210 [ibStatusText setDefaultStatus:[self defaultStatusString]];
211 if ( count == 1 ) {
212 NSColor *green = [NSColor colorWithCalibratedRed:0.0 green:0.7 blue:0.0 alpha:1.0];
213 [ibStatusText setTemporaryStatus:[NSString stringWithFormat:@"Search found one result.", count] color:green duration:6.0];
214 }
215 else if ( count == 0 ) {
216 NSColor *red = [NSColor colorWithCalibratedRed:0.7 green:0.0 blue:0.0 alpha:1.0];
217 [ibStatusText setTemporaryStatus:[NSString stringWithFormat:@"Search found no results.", count] color:red duration:6.0];
218 }
219 else {
220 [ibStatusText setTemporaryStatus:[NSString stringWithFormat:@"Search found %i results.", count] duration:6.0];
221 }
222 [ibStatusBar setIndeterminate:NO];
223 [ibStatusBar setDoubleValue:0.0];
224 [ibStatusBar stopAnimation:self];
225
226 [self updateInterface];
227 if ( _mode == TCSearchMode ) {
228 [ibWindow makeFirstResponder:ibSearchValueField];
229 }
230 }
231 }
232
233 - (void)cheater:(Cheater *)cheater didFindValues:(TCArray)values
234 {
235 [_searchData setValues:values];
236 [ibSearchVariableTable reloadData];
237
238 [self watchVariables];
239 }
240
241 - (void)cheaterDidCancelSearch:(Cheater *)cheater
242 {
243 ChazLog( @"cheaterDidCancelSearch:" );
244
245 if ( _isCancelingTask ) {
246 _status = TCIdleStatus;
247 _isCancelingTask = NO;
248
249 [ibStatusText setDefaultStatus:[self defaultStatusString]];
250 [ibStatusText setTemporaryStatus:@"Search cancelled." duration:2.0];
251 [ibStatusBar setIndeterminate:NO];
252 [ibStatusBar setDoubleValue:0.0];
253 [ibStatusBar stopAnimation:self];
254
255 [self updateInterface];
256 if ( _mode == TCSearchMode ) {
257 [ibWindow makeFirstResponder:ibSearchValueField];
258 }
259 }
260 }
261
262 - (void)cheaterDidClearSearch:(Cheater *)cheater
263 {
264 [_searchData clearResults];
265 [ibSearchVariableTable reloadData];
266
267 [self setActualResults:0];
268
269 [ibStatusText setTemporaryStatus:@"The search was cleared." duration:2.0];
270 [self updateInterface];
271 }
272
273
274 - (void)cheater:(Cheater *)cheater didDumpMemory:(NSData *)memoryDump
275 {
276 NSSavePanel *panel;
277
278 ChazLog( @"cheater:didDumpMemory:" );
279
280 ChazLog( @"status: %i", _status );
281 if ( _status == TCDumpingStatus ) {
282 _status = TCIdleStatus;
283
284 panel = [NSSavePanel savePanel];
285 [panel setRequiredFileType:@"dump"];
286 [panel setExtensionHidden:NO];
287 [panel setCanSelectHiddenExtension:YES];
288 if ( MacOSXVersion() >= 0x1030 ) {
289 [panel setMessage:@"Dump files are huge! Exercise patience while saving."];
290 }
291
292 [panel beginSheetForDirectory:nil
293 file:[NSString stringWithFormat:[NSString stringWithFormat:@"%@.dump", [_process name]]]
294 modalForWindow:ibWindow
295 modalDelegate:self
296 didEndSelector:@selector(saveMemoryDumpDidEnd:returnCode:contextInfo:)
297 contextInfo:memoryDump];
298 [memoryDump retain];
299 }
300 }
301
302 - (void)saveMemoryDumpDidEnd:(NSSavePanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
303 {
304 NSData *dump = (NSData *)contextInfo;
305
306 [ibStatusText setDefaultStatus:[self defaultStatusString]];
307
308 if ( returnCode == NSOKButton ) {
309 // write the file
310 [dump writeToFile:[sheet filename] atomically:YES];
311
312 [ibStatusText setTemporaryStatus:[NSString stringWithFormat:@"Successfully dumped %@'s memory.", [_process name]]];
313 }
314 else {
315 [ibStatusText setTemporaryStatus:@"Dumping memory cancelled."];
316 }
317
318 [dump release];
319
320 [ibStatusBar stopAnimation:self];
321 [ibStatusBar setIndeterminate:NO];
322
323 [self updateInterface];
324 if ( _mode == TCSearchMode ) {
325 [ibWindow makeFirstResponder:ibSearchValueField];
326 }
327 }
328
329 - (void)cheaterDidCancelMemoryDump:(Cheater *)cheater
330 {
331 ChazLog( @"cheaterDidCancelMemoryDump:" );
332
333 if ( _isCancelingTask ) {
334 _status = TCIdleStatus;
335 _isCancelingTask = NO;
336
337 [ibStatusText setDefaultStatus:[self defaultStatusString]];
338 [ibStatusText setTemporaryStatus:@"Dumping memory cancelled."];
339 [ibStatusBar stopAnimation:self];
340 [ibStatusBar setIndeterminate:NO];
341
342 [self updateInterface];
343 if ( _mode == TCSearchMode ) {
344 [ibWindow makeFirstResponder:ibSearchValueField];
345 }
346 }
347 }
348
349
350 - (void)cheater:(Cheater *)cheater didChangeVariables:(unsigned)changeCount
351 {
352 ChazLog( @"CHEATER changed %u variables.", changeCount );
353 if ( ![_cheatData repeats] ) {
354 _status = TCIdleStatus;
355 }
356
357 if ( changeCount == 0 ) {
358 [ibStatusText setTemporaryStatus:@"No variables were changed." duration:2.0];
359 }
360 else if ( changeCount == 1 ) {
361 [ibStatusText setTemporaryStatus:@"Changed one variable." duration:2.0];
362 }
363 else {
364 [ibStatusText setTemporaryStatus:[NSString stringWithFormat:@"Changed %i variables.", changeCount] duration:2.0];
365 }
366
367 [self updateInterface];
368 }
369
370 - (void)cheaterDidStopChangingVariables:(Cheater *)cheater
371 {
372 _status = TCIdleStatus;
373 _isCancelingTask = NO;
374
375 [ibStatusText setDefaultStatus:[self defaultStatusString]];
376 [ibStatusBar stopAnimation:self];
377 [ibStatusBar setIndeterminate:NO];
378
379 [self updateInterface];
380 if ( _mode == TCSearchMode ) {
381 [ibWindow makeFirstResponder:ibSearchValueField];
382 }
383 }
384
385
386 - (void)cheater:(Cheater *)cheater didReportProgress:(int)progress
387 {
388 if ( _status == TCSearchingStatus && !_isCancelingTask ) {
389 [ibStatusBar setDoubleValue:(double)progress];
390 }
391 }
392
393
394 - (void)cheater:(Cheater *)cheater didRevertToVariables:(TCArray)variables actualAmount:(unsigned)count
395 {
396 // do something with the variables
397 [_searchData setAddresses:variables];
398 [ibSearchVariableTable reloadData];
399
400 [self setActualResults:count];
401
402 [self updateInterface];
403 }
404
405
406 - (void)cheaterDidUndo:(Cheater *)cheater
407 {
408 [_searchData didUndo];
409
410 [ibStatusText setTemporaryStatus:@"Reverted to previous results." duration:2.0];
411 }
412
413 - (void)cheaterDidRedo:(Cheater *)cheater
414 {
415 [_searchData didRedo];
416
417 [ibStatusText setTemporaryStatus:@"Reverted to saved results." duration:2.0];
418 }
419
420
421 - (void)cheater:(Cheater *)cheater variableAtIndex:(unsigned)index didChangeTo:(Variable *)variable
422 {
423 [_searchData setValue:variable atIndex:index];
424 [ibSearchVariableTable reloadData];
425 }
426
427
428 - (void)cheater:(Cheater *)cheater didFailLastRequest:(NSString *)reason
429 {
430 _status = TCIdleStatus;
431
432 // echo the reason to the status
433 [self showError:reason];
434 [ibStatusBar setIndeterminate:NO];
435 [ibStatusBar setDoubleValue:0.0];
436 [ibStatusBar stopAnimation:self];
437
438 [self updateInterface];
439 }
440
441 - (void)cheater:(Cheater *)cheater echo:(NSString *)message
442 {
443 // echo the message to the status
444 [ibStatusText setTemporaryStatus:message duration:7.0];
445 }
446
447
448 @end
This page took 0.046045 seconds and 4 git commands to generate.