Data Types, Typedefs, Structs, Unions, and Enums

Basic Data Types

Because 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.

Type Aliases Description
char int8, __int8, CHAR, TCHAR 8-Bit Signed Integer
byte unsigned int8, unsigned __int8, BYTE 8-Bit Unsigned Integer
short int16, __int16, wchar_t, SHORT, WCHAR 16-Bit Signed Integer
unsigned short unsigned int16, unsigned __int16, WORD 16-Bit Unsigned Integer
int int32, __int32, long, INT, LONG 32-Bit Signed Integer
unsigned int unsigned int32, unsigned __int32, unsigned long, UINT, ULONG, DWORD 32-Bit Unsigned Integer
int64 __int64, INT64 64-Bit Signed Integer
unsigned int64 unsigned __int64, UINT64, QWORD 64-Bit Unsigned Integer
float FLOAT 32-Bit Floating-Point Number
double DOUBLE 64-Bit Floating-Point Number

 

Typedefs

Aliases 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.

 

Structs

Structures 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 {
    int iA;
    int iB;
    int iC;
};

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 {
    int iA;
    int iB;
    int iC;
} npPuffster;

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 {
    int iA;
    int iB;
    int iC;
    struct NestedStruct {
        float fD;
        double dE;
    } nsF;
} npPuffster;

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.

 

Unions

Unions 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 {
    int iA;
    int iB;
    int iC;
    struct NestedStruct {
        float fD;
        double dE;
    } nsF;
} npPuffster;

 

Enums

Enumerations 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 {
    CARDS_NONE = -1,
    CARDS_HEARTS,
    CARDS_CLUBS,
    CARDS_DIAMONDS,
    CARDS_SPADES
};

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