]> Dogcows Code - chaz/thecheat/blob - CheaterTypes.h
update contact information and project URL
[chaz/thecheat] / CheaterTypes.h
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 #ifndef _CheaterTypes_H
14 #define _CheaterTypes_H
15
16 #import <Cocoa/Cocoa.h>
17
18 #include <mach/vm_types.h>
19
20 #include <stdlib.h>
21 #include <string.h>
22
23
24 /* Compiler macros */
25 #if defined( __cplusplus )
26 #define CHEAT_EXPORT extern "C"
27 #define CHEAT_IMPORT extern "C"
28 #else
29 #define CHEAT_EXPORT extern
30 #define CHEAT_IMPORT extern
31 #endif
32
33 #if !defined( CHEAT_STATIC_INLINE )
34 #define CHEAT_STATIC_INLINE static __inline__
35 #endif
36
37 #if !defined( CHEAT_EXTERN_INLINE )
38 #define CHEAT_EXTERN_INLINE extern __inline__
39 #endif
40
41
42 #pragma mark -
43 #pragma mark Miscellaneous Types
44 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
45
46 typedef mach_vm_address_t TCAddress;
47
48
49 typedef unsigned char TCVariableType;
50 enum {
51 TCInt64 = 0,
52 TCInt32 = 1, // default
53 TCInt16 = 2,
54 TCInt8 = 3,
55 TCString = 4,
56 TCFloat = 5,
57 TCDouble = 6
58 };
59
60 typedef unsigned char TCIntegerSign;
61 enum {
62 TCSigned = 0, // default
63 TCUnsigned = 1
64 };
65
66 typedef unsigned char TCSearchOperator;
67 enum {
68 TCEqual = 0, // default
69 TCNotEqual = 1,
70 TCLessThan = 2,
71 TCGreaterThan = 3,
72 TCLessThanOrEqual = 4, // not used
73 TCGreaterThanOrEqual = 5 // not used
74 };
75
76 typedef unsigned char TCSearchType;
77 enum {
78 TCGivenValue = 0, // default
79 TCLastValue = 1
80 };
81
82
83 #pragma mark -
84 #pragma mark TCArray
85 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
86
87 typedef struct _TCArray
88 {
89 void *_bytes;
90 unsigned _count;
91 unsigned _size;
92 BOOL _ownsBytes;
93 } *TCArray;
94
95
96 #pragma mark -
97 #pragma mark Exported Array Functions
98 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
99
100 CHEAT_EXPORT TCArray TCMakeArray( unsigned count, unsigned size );
101 CHEAT_EXPORT TCArray TCMakeArrayWithBytes( unsigned count, unsigned size, void *bytes );
102 CHEAT_EXPORT void TCReleaseArray( TCArray array );
103
104 CHEAT_EXPORT void TCArrayAppendArray( TCArray array, TCArray other );
105
106 CHEAT_EXPORT NSString *TCStringFromArray( TCArray array );
107
108
109 #pragma mark -
110 #pragma mark Imported Array Functions
111 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
112
113 CHEAT_STATIC_INLINE void *TCArrayBytes( TCArray array )
114 {
115 return array->_bytes;
116 }
117
118 CHEAT_STATIC_INLINE unsigned TCArrayElementCount( TCArray array )
119 {
120 return array->_count;
121 }
122
123 CHEAT_STATIC_INLINE unsigned TCArrayElementSize( TCArray array )
124 {
125 return array->_size;
126 }
127
128 CHEAT_STATIC_INLINE void const *TCArrayElementAtIndex( TCArray array, unsigned index )
129 {
130 return array->_bytes + index * array->_size;
131 }
132
133 CHEAT_STATIC_INLINE void TCArraySetElementAtIndex( TCArray array, unsigned index, void const *element )
134 {
135 memcpy( array->_bytes + index * array->_size, element, array->_size );
136 }
137
138 CHEAT_STATIC_INLINE void TCArrayResize( TCArray array, unsigned count )
139 {
140 void *bytes = realloc( array->_bytes, count * array->_size );
141
142 if ( bytes ) {
143 array->_bytes = bytes;
144 array->_count = count;
145 }
146 }
147
148 CHEAT_STATIC_INLINE TCArray TCArrayCopyElements( TCArray array, unsigned count )
149 {
150 return TCMakeArrayWithBytes( MIN(array->_count,count), array->_size, array->_bytes );
151 }
152
153 CHEAT_STATIC_INLINE TCArray TCArrayCopy( TCArray array )
154 {
155 return TCArrayCopyElements( array, array->_count );
156 }
157
158 CHEAT_STATIC_INLINE TCArray TCArrayCopyContainer( TCArray array, unsigned count )
159 {
160 TCArray copy = TCMakeArray( MIN(array->_count,count), array->_size );
161 copy->_bytes = array->_bytes;
162 copy->_ownsBytes = NO;
163 return copy;
164 }
165
166 CHEAT_STATIC_INLINE void TCArrayFill( TCArray array, int filler )
167 {
168 memset( array->_bytes, filler, array->_count * array->_size );
169 }
170
171
172
173 #endif /* _CheaterTypes_H */
174
This page took 0.040197 seconds and 4 git commands to generate.