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