-
Notifications
You must be signed in to change notification settings - Fork 13
/
CheaterTypes.m
76 lines (58 loc) · 1.52 KB
/
CheaterTypes.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* The Cheat - The legendary universal game trainer for Mac OS X.
* http://www.brokenzipper.com/trac/wiki/TheCheat
*
* Copyright (c) 2003-2011, Charles McGarvey et al.
*
* Distributable under the terms and conditions of the 2-clause BSD
* license; see the file COPYING for the legal text of the license.
*/
#import "CheaterTypes.h"
TCArray TCMakeArray( unsigned count, unsigned size )
{
TCArray array = (TCArray)malloc( sizeof(struct _TCArray) );
if ( array ) {
array->_bytes = malloc( count * size );
if ( array->_bytes ) {
array->_count = count;
array->_size = size;
array->_ownsBytes = YES;
}
else {
free( array );
return NULL;
}
}
return array;
}
TCArray TCMakeArrayWithBytes( unsigned count, unsigned size, void *bytes )
{
TCArray array = TCMakeArray( count, size );
if ( array && bytes ) {
memcpy( array->_bytes, bytes, count * size );
}
return array;
}
void TCReleaseArray( TCArray array )
{
if ( array && array->_ownsBytes ) {
free( array->_bytes );
free( array );
}
}
void TCArrayAppendArray( TCArray array, TCArray other )
{
unsigned oldCount = array->_count;
unsigned count = oldCount + other->_count;
if ( array->_size != other->_size ) {
return;
}
TCArrayResize( array, count );
if ( array->_count == count ) {
memcpy( array->_bytes + oldCount * array->_size, other->_bytes, other->_count * other->_size );
}
}
NSString *TCStringFromArray( TCArray array )
{
return [NSString stringWithFormat:@"{%p,%u,%u}", array->_bytes, array->_count, array->_size];
}