Data Types, Typedefs, Structs, Unions, and Enums | ![]() |
![]() |
Basic Data TypesBecause the scripting language is intended to work closely with real C and C++ and is used for hacking and mapping the target process RAM, it supports all typical data types. The following chart shows each type.
TypedefsAliases for built-in data types, structures, unions, and existing typedefs can be created by using the typedef keyword. The syntax for creating new types is “typedef <data type> <new type name>”. For example, typedef unsigned int myInt;would generate a new data type myInt for unsigned integers. <data type> can be any data type, structure, union, or typedef. Typedefs can not be used with arrays, however, but they can be used with pointer types. Typedefs must be declared before they can be used, unlike the other data types. Each time the same typedef is declared, it overwrites its previous meaning without throwing an error or warning.
StructsStructures and unions work the same way as in C; they are complicated data types created by combining other data types, including other structures and unions. Use the struct keyword to define structures. For example: struct NiftyPuff { You can declare a variable instance of the structure at the same time as you define the structure, as you can in C. For example, struct NiftyPuff { would define a structure named NiftyPuff and create a variable npPuffster of type NiftyPuff. Unlike in C, you can not use commas to create multiple variables at once. Structures are always global, even when nested inside each other, however variables declared at the same time as the structures have the same locality as they normally would have (global or local). Normally structures can be declared anywhere and used from anywhere. The only exceptions are when the structure members require typedef information, as typedefs must be declared before they can be used, or if any members are typed as structures that have not been declared or forward-declared yet. You can forward-declare a structure the same way as in C, for example, struct NiftyPuff; would forward-declare Niftypuff so that it can be used as a member of other structures without having been defined. The declaration rules for the structure members follow the same rules as other variable declarations, except for locality (they are neither global nor local, but are structure members), which means any member can be declared as any type, including other structures and unions, and those structures and unions can be declared at the same time as the member of that type is declared. For example: struct NiftyPuff { Here we have our npPuffster variable of type NiftyPuff, but NiftyPuff now contains a member nsF, which is of type NestedStruct, which was declared inside NiftyPuff at the same time nsF was declared. Remember that all structures and unions are global, so NestedStruct can be used without having to specify that it is somehow part of NiftyPuff. A structure can not be a member of itself unless done so through a pointer.
UnionsUnions are exactly the same as structs, but with each member starting at offset 0, and the size of the union is just large enough to hold the largest data type in the union. Use the union keyword instead of the struct keyword. union NiftyPuff {
EnumsEnumerations work in the same way as they do in C, except that variables declared as an enumerated type always resolve to type int instead. An enum can be created using the C syntax “enum [<type name>] { <constant name> [ = value ], ... } [<variable name>];”. As in C, <type name> and <variable name> are optional. enum CARDS { As in C, you can define values for each enumerated constant. Any undefined values are one number higher than the previous constant in the enumeration, with the first constant starting at 0, if its value is not otherwise specified. In our example, CLUB_HEARTS has value 0, which is one higher than CARDS_NONE, whose value is -1. If CARDS_NONE was not defined as -1, it would have been 0, and CLUB_HEARTS would then be 1. Enumerations are always global, and do not need to be declared in any specific order. Enumerations are always of type int. |
Copyright © 2006 Shawn (L. Spiro) Wilcoxen |