Available functions

void log(? value)

Logs a value to the Visual Studio console. The value can be of any type. This includes strings, simple types and native objects. If a native object is passed, the data will be serialized and logged as a string. If you need to log the address of a pointer, use log(hex(pointer.address)).

log also supports logging character pointers, which e.g allows to log std::string's: log(stdString.c_str()).

void print(? value)

The same as log, but the value will be printed out to stdout (the console will be allocated if it is not already).

void assert(const bool condition)

assert throws a script exception if the passed condition is false. Otherwise, does nothing. The exception will be logged to the console together with the filename and line number. Currently, the program continues to run after the exception is thrown.

uint32 getCurrentThreadId()

Calls the Windows GetCurrentThreadId API and returns the result. This is the thread that executes the snippet.

void sleep(uint32 milliseconds)

Calls the Windows Sleep API and waits until the time-out interval elapses.

[1] void view()
[2] void view(? value, int sort = -1)
[3] void view(? value, const string& name, int sort = -1)
[1] view() views all available objects within the context of the snippet. This includes all native local function variables and parameters. Calling the function copies the data to a buffer that is then sent to the D0 client UI. This means that the object state is updated only when view() is called.

Unlike breakpoints, view() does not stop the execution, which requires D0 to omit data referenced by pointers in the objects that are viewed. Data from pointers is transferred only when the user expands the pointer object in the UI, this expansion requires that view() is called again, so that D0 can copy the data. When a user changes a value of the object in D0, this change is applied in the next call to view().

It is currently not possible to configure manually what data should be transferred when viewing pointers.

D0 determines which object to update by the filename and line number the call is placed on. If the call is in a for loop and you want to view different objects from the same line, you can use the name parameter in the [3] view() overload to differentiate between them.

Two other overloads are available:
  1. Takes the object to view and an additional optional sort value. Unlike [1] view(), only the object that was passed is viewed. You can additionally pass a positive integer to determine in which position the object should be viewed in the UI. This is useful when viewing multiple objects e.g in an ordered list.
  2. Same as 2, but allows to specify the name of the object that is displayed in the UI. If the name is specified, it will be used to identify which object to update, instead of the filename and line number.

[1] void list(ptr<?>& value, int count = -1, const string& name = "")
[2] void list(ptr<?>& value, const string& name = "")

list() may be used to view a list of objects given a pointer to the first element of the list. The type and size of an element is determined by the inner type of the pointer.

If a ptr<char> is passed, the list will be viewed as a string. In this case, if count is not specified, the length of the string will be determined by calling strlen on the pointer. If the value is not a character pointer and count is not specified, a list of length 1 will be assumed.

If a name is specified, it will be displayed in the UI along with the element index instead of the default Object title.

void clearLog()

Clears all the messages from the Visual Studio Logs window.

[1] string hex(int64 value)
[2] string hex(uint64 value)

Converts the passed value to a hexadecimal string. The 0x prefix is not included.

For negative values, the [1] hex() overload is used and - is prepended to the result.

[1] string bin(int64 value)
[2] string bin(uint64 value)

Converts the passed value to a binary representation string. The 0b prefix is not included.

For negative values, the [1] bin() overload is used and - is prepended to the result.

uint64 allocate(uint64 size)
Allocates a block of memory of the specified size and returns a pointer to it. The allocated memory is not freed automatically, so you need to call free when you are done with it.

To cast the returned address to a pointer of a specific type:
ptr<Type> p;
    p.address = allocate(100);

bool free(uint64 block)
Frees the memory block pointed to by block.

Returns false in case a snippet tries to free a 64bit address when running in a 32bit process.

bool memset(uint64 destination, uint8 value, uint64 size)
Sets the first size bytes of the memory block pointed to by destination to the specified value.

Returns false in case a snippet tries to set a 64bit address when running in a 32bit process.

bool memcpy(uint64 destination, uint64 source, uint64 size)
Copies size bytes from the memory block pointed to by source to the memory block pointed to by destination.

Returns false in case a snippet tries to copy from a 64bit address when running in a 32bit process.

double time()

Returns the time in milliseconds using QueryPerformanceCounter.

uint8 popcount(uint64 value)

Returns the number of bits set to 1 in the passed value.

[1] float min(float a, float b)
[2] double min(float a, double b)
[3] int64 min(int64 a, int64 b)
[4] uint64 min(uint64 a, uint64 b)

Returns the minimum of the two passed values.

[1] float max(float a, float b)
[2] double max(float a, double b)
[3] int64 max(int64 a, int64 b)
[4] uint64 max(uint64 a, uint64 b)

Returns the maximum of the two passed values.

[1] float clamp(float value, float min, float max)
[2] double clamp(double value, double min, double max)
[3] int64 clamp(int64 value, int64 min, int64 max)
[4] uint64 clamp(uint64 value, uint64 min, uint64 max)

Returns the passed value clamped to the specified range.

float sin(float a)

Calls std::sin.

float cos(float a)

Calls std::cos.

float tan(float a)

Calls std::tan.