# Practical Information

## Still have Questions?

You're welcome to contact us:

* [Cherax Forum](https://cherax.vip)


# API Reference

![](/files/pVk02wBfVigFrH84lIFo)

## Lua Engine Version

* Lua 5.4

## Development Q\&A

Lua Directory:

C:\Users\\{machine.username}\AppData\Roaming\Cherax\Lua


# Classes

Some classes that are automatically imported when loading a script.


# vec2

@property float x @property float y

@constructor vec2() @constructor vec2(float, float)

@method vec2 \_\_add(vec2|vec3|float)&#x20;

@method vec2 \_\_sub(vec2|vec3|float)&#x20;

@method vec2 \_\_mul(vec2|vec3|float)&#x20;

@method vec2 \_\_div(vec2|vec3|float)&#x20;

@method bool \_\_eq(vec2)&#x20;

@method bool \_\_lt(vec2)&#x20;

@method bool \_\_le(vec2)&#x20;

@method string \_\_tostring()&#x20;

@method float length() @method float distanceTo(vec2)


# vec3

@property float x&#x20;

@property float y&#x20;

@property float z

@constructor vec3()&#x20;

@constructor vec3(float, float, float)

@method vec3 \_\_add(vec2|vec3|float)&#x20;

@method vec3 \_\_sub(vec2|vec3|float)

&#x20;@method vec3 \_\_mul(vec2|vec3|float)&#x20;

@method vec3 \_\_div(vec2|vec3|float)&#x20;

@method bool \_\_eq(vec3)&#x20;

@method bool \_\_lt(vec3)&#x20;

@method bool \_\_le(vec3)&#x20;

@method string \_\_tostring()&#x20;

@method float length()&#x20;

@method float distance(vec3)


# g\_lua

```
g_lua.register();
// your code here
g_lua.unregister();
```


# register

This function has to be called exactly once at the beginning of your script.

void register()


# unregister

This function indicates that the script wants to be unloaded.

void unregister()


# load\_lua

Loads a lua and executes it.

void load\_lua(string filepath)


# g\_memory


# get\_base\_address

Returns the base address for the given module.

int get\_base\_address(string module = nil)

```lua
address = g_memory.get_base_address() -- base address of GTA5.exe
address2 = g_memory.get_base_address("socialclub.dll") -- base address of socialclub.dll
```


# scan\_pattern

Scans the module for a specific IDA-Style pattern. Returns the address of the scan result.

int g\_memory.scan\_pattern(string pattern, string module = nil)

```lua
result = g_memory.scan_pattern("40 38 35 ? ? ? ? 75 0E 4C 8B C3 49 8B D7 49 8B CE") -- scans for that pattern in GTA5.exe
```


# rip

Reads an offset from the instruction and returns the resulting address.

int g\_memory.rip(int address)

```lua
result = g_memory.scan_pattern("40 38 35 ? ? ? ? 75 0E 4C 8B C3 49 8B D7 49 8B CE") -- scans for that pattern in GTA5.exe
is_session_started_ptr = g_memory.rip(result + 3)

if g_memory.read_byte(is_session_started_ptr) then
   g_logger.log_info("Session is started") 
end
```


# allocate

Allocated given bytes and return a pointer to the memory. Do not forget to free the memory after using it.

int allocate(int bytes)

```
ptr = g_memory.allocate(4)
g_memory.write_int(ptr, 1337)
g_memory.free(ptr)
```


# free

void free(int address)


# write\_byte

void write\_byte(int address, byte value)


# write\_short

void write\_short(int address, short value)


# write\_int

void write\_int(int address, int value)


# write\_long\_long

void write\_long\_long(int address, long long value)


# write\_float

void write\_float(int address, float value)


# write\_double

void write\_double(int address, double value)


# write\_string

void write\_string(int address, string value)


# read\_byte

byte read\_byte(int address)


# read\_short

short read\_short(int address)


# read\_int

int read\_int(int address)


# read\_long\_long

long long read\_long\_long(int address)


# read\_float

float read\_float(int address)


# read\_double

double read\_double(int address)


# read\_string

string read\_string(int address)


# g\_logger


# log\_info

Logs given text to the cherax console.

void log\_info(string text)


# g\_gui

Options to communicate with the default gui.

```
g_lua.register();

myBoolean = false;
myLongLong = 1337;

g_gui.add_toggle("misc_lua", "Test Toggle", "test tooltip", function(on) myBoolean = on; end);
g_gui.add_input_int("misc_lua", "INPUT", myLongLong, 50, 20000, 5, 100, function(val) myLongLong = val; end);
g_gui.add_input_string("misc_lua", "text", "default", function(val) g_logger.log_info("in callback " .. val); end);

while g_isRunning do

	g_logger.log_info("myLongLong is: " .. myLongLong);
	g_util.yield(1000)
end

g_lua.unregister();
```


# is\_open

Returns whether the main cherax windo is opened or not.

bool is\_open()


# open

opens the GUI

void open()


# close

closes the GUI

void close()


# toggle

toggles the GUI

void toggle


# add\_toast

Adds a notifcation on the top right corner.

void add\_toast(string text, float ms = default)


# add\_button

Adds a button to one of the main cherax child windows. The name can be obtained by right clicking on the child.

void add\_button(string childWindow, string name, function() callback)

void add\_button(string childWindow, string name, string tooltip, function() callback)


# add\_toggle

Adds a toggle to one of the main cherax child windows. The name can be obtained by right clicking on the child.

void add\_toggle(string childWindow, string name, function(bool) callback)

void add\_toggle(string childWindow, string name, string tooltip, function(bool) callback)


# add\_input\_int

Adds an integer input field to one of the main cherax child windows. The name can be obtained by right clicking on the child.

void add\_input\_int(string childWindow, string name, int default, int min, int max, int step, int stepfast, function(int) callback)


# add\_input\_float

Adds a float input field to one of the main cherax child windows. The name can be obtained by right clicking on the child.

void add\_input\_float(string childWindow, string name, float startValue, float minValue, float maxValue, function callback)

void add\_input\_float(string childWindow, string name, float startValue, float minValue, float maxValue, float step, function callback)


# add\_input\_string

void add\_input\_string(string childWindow, string name, string initialText, function(string) callback)


# g\_hooking


# register\_D3D\_hook

Registers a function which gets called on every frame. It returns an ID used for unregistering the hook.

int register\_D3D\_hook(function() callback)


# register\_wndproc\_hook

Registers a function which gets called on every input. It returns an ID used for unregistering the hook.

int register\_wndproc\_hook(function(int msg, int wparam, int lparam) callback)


# register\_scripted\_game\_event\_hook

Registers a function which gets called on every received scripted game event. It returns an ID used for unregistering the hook. Hoook should either return true or false.

int register\_scripted\_game\_event\_hook(function(int sender, int count, array\<int> args) callback)

```lua
function mySGEhook(sender, count, args)
    g_logger.log_info("Script Event from "..PLAYER.GET_PLAYER_NAME(player)) 
    g_logger.log_info("SE Hash: " .. tostring(args[1]) .. " Last Arg: " .. tostring(args[count]))
    
    if (args[1] == 1337) then
        return false -- false to block
    end
    
    return true
end
```


# unregister\_hook

Removes hook by given id.

bool unregister\_hook(int id)


# g\_math


# sin

int sin(int value)


# cos

int cos(int value)


# tan

int tan(int value)


# g\_util


# yield

If executed within scripting thread, the thread will be paused for the given time.

void yield(int ms = default)


# is\_session\_started

Returns whether the player is in an online session or not.

### bool is\_session\_started()


# get\_selected\_player

Returns the current selected player in the player list of the menu.

### int get\_selected\_player()


# trigger\_script\_event

### void trigger\_script\_event(int player, array data)


# get\_menu\_version

Returns the current menu version.

### string get\_menu\_version()


# joaat

### Hash joaat(string str)


# play\_wav\_file

void play\_wav\_file(string file, bool looped, bool stop)


# g\_imgui

All of these functions can only be executed within a D3D hook. https\://github.com/ocornut/imgui

```lua
function myButtonCallback()
	g_logger.log_info("Callback called")
end

function myToggleCallback(value)
	myBool = value
end

function myD3DHook()
	if g_gui.is_open() then
		g_imgui.set_next_window_size(vec2(400, 600))
		if  g_imgui.begin_window("Test Window", ImGuiWindowFlags_NoResize) then
			g_imgui.begin_child("Test Child", vec2(), true)
			g_imgui.add_button("Test Button", vec2(), myButtonCallback)
			g_imgui.add_checkbox("Test Checkbox", myToggleCallback)
			
			if g_imgui.add_button("Test Button 2", vec2(), function() g_logger.log_info("Callback in scripting thread") end) then
                		g_logger.log_info("Pressed")
            		end 	
			
			g_imgui.end_child()
			g_imgui.end_window()	
		end
	end

	if myBool then
		g_imgui.add_circle_filled(g_imgui.get_display_size() / 2, 50.0, 105, 205, 255)
		g_imgui.add_line(vec2(), g_imgui.get_display_size(), 45, 155, 255)
	end
end

g_lua.register();

id = g_hooking.register_D3D_hook(myD3DHook);

while g_isRunning do
	g_util.yield(100)
end

g_hooking.unregister_hook(id);
g_lua.unregister();
```


# Globals

Flags used by ImGui.

```cpp
// Flags for ImGui::Begin()
enum ImGuiWindowFlags_
{
    ImGuiWindowFlags_None                   = 0,
    ImGuiWindowFlags_NoTitleBar             = 1 << 0,   // Disable title-bar
    ImGuiWindowFlags_NoResize               = 1 << 1,   // Disable user resizing with the lower-right grip
    ImGuiWindowFlags_NoMove                 = 1 << 2,   // Disable user moving the window
    ImGuiWindowFlags_NoScrollbar            = 1 << 3,   // Disable scrollbars (window can still scroll with mouse or programmatically)
    ImGuiWindowFlags_NoScrollWithMouse      = 1 << 4,   // Disable user vertically scrolling with mouse wheel. On child window, mouse wheel will be forwarded to the parent unless NoScrollbar is also set.
    ImGuiWindowFlags_NoCollapse             = 1 << 5,   // Disable user collapsing window by double-clicking on it
    ImGuiWindowFlags_AlwaysAutoResize       = 1 << 6,   // Resize every window to its content every frame
    ImGuiWindowFlags_NoBackground           = 1 << 7,   // Disable drawing background color (WindowBg, etc.) and outside border. Similar as using SetNextWindowBgAlpha(0.0f).
    ImGuiWindowFlags_NoSavedSettings        = 1 << 8,   // Never load/save settings in .ini file
    ImGuiWindowFlags_NoMouseInputs          = 1 << 9,   // Disable catching mouse, hovering test with pass through.
    ImGuiWindowFlags_MenuBar                = 1 << 10,  // Has a menu-bar
    ImGuiWindowFlags_HorizontalScrollbar    = 1 << 11,  // Allow horizontal scrollbar to appear (off by default). You may use SetNextWindowContentSize(ImVec2(width,0.0f)); prior to calling Begin() to specify width. Read code in imgui_demo in the "Horizontal Scrolling" section.
    ImGuiWindowFlags_NoFocusOnAppearing     = 1 << 12,  // Disable taking focus when transitioning from hidden to visible state
    ImGuiWindowFlags_NoBringToFrontOnFocus  = 1 << 13,  // Disable bringing window to front when taking focus (e.g. clicking on it or programmatically giving it focus)
    ImGuiWindowFlags_AlwaysVerticalScrollbar= 1 << 14,  // Always show vertical scrollbar (even if ContentSize.y < Size.y)
    ImGuiWindowFlags_AlwaysHorizontalScrollbar=1<< 15,  // Always show horizontal scrollbar (even if ContentSize.x < Size.x)
    ImGuiWindowFlags_AlwaysUseWindowPadding = 1 << 16,  // Ensure child windows without border uses style.WindowPadding (ignored by default for non-bordered child windows, because more convenient)
    ImGuiWindowFlags_NoNavInputs            = 1 << 18,  // No gamepad/keyboard navigation within the window
    ImGuiWindowFlags_NoNavFocus             = 1 << 19,  // No focusing toward this window with gamepad/keyboard navigation (e.g. skipped by CTRL+TAB)
    ImGuiWindowFlags_UnsavedDocument        = 1 << 20,  // Display a dot next to the title. When used in a tab/docking context, tab is selected when clicking the X + closure is not assumed (will wait for user to stop submitting the tab). Otherwise closure is assumed when pressing the X, so if you keep submitting the tab may reappear at end of tab bar.
    ImGuiWindowFlags_NoNav                  = ImGuiWindowFlags_NoNavInputs | ImGuiWindowFlags_NoNavFocus,
    ImGuiWindowFlags_NoDecoration           = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse,
    ImGuiWindowFlags_NoInputs               = ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs | ImGuiWindowFlags_NoNavFocus,

    // [Internal]
    ImGuiWindowFlags_NavFlattened           = 1 << 23,  // [BETA] On child window: allow gamepad/keyboard navigation to cross over parent border to this child or between sibling child windows.
    ImGuiWindowFlags_ChildWindow            = 1 << 24,  // Don't use! For internal use by BeginChild()
    ImGuiWindowFlags_Tooltip                = 1 << 25,  // Don't use! For internal use by BeginTooltip()
    ImGuiWindowFlags_Popup                  = 1 << 26,  // Don't use! For internal use by BeginPopup()
    ImGuiWindowFlags_Modal                  = 1 << 27,  // Don't use! For internal use by BeginPopupModal()
    ImGuiWindowFlags_ChildMenu              = 1 << 28   // Don't use! For internal use by BeginMenu()

    // [Obsolete]
    //ImGuiWindowFlags_ResizeFromAnySide    = 1 << 17,  // --> Set io.ConfigWindowsResizeFromEdges=true and make sure mouse cursors are supported by backend (io.BackendFlags & ImGuiBackendFlags_HasMouseCursors)
};
```

```cpp
enum ImGuiStyleVar_
{
    // Enum name --------------------- // Member in ImGuiStyle structure (see ImGuiStyle for descriptions)
    ImGuiStyleVar_Alpha,               // float     Alpha
    ImGuiStyleVar_WindowPadding,       // ImVec2    WindowPadding
    ImGuiStyleVar_WindowRounding,      // float     WindowRounding
    ImGuiStyleVar_WindowBorderSize,    // float     WindowBorderSize
    ImGuiStyleVar_WindowMinSize,       // ImVec2    WindowMinSize
    ImGuiStyleVar_WindowTitleAlign,    // ImVec2    WindowTitleAlign
    ImGuiStyleVar_ChildRounding,       // float     ChildRounding
    ImGuiStyleVar_ChildBorderSize,     // float     ChildBorderSize
    ImGuiStyleVar_PopupRounding,       // float     PopupRounding
    ImGuiStyleVar_PopupBorderSize,     // float     PopupBorderSize
    ImGuiStyleVar_FramePadding,        // ImVec2    FramePadding
    ImGuiStyleVar_FrameRounding,       // float     FrameRounding
    ImGuiStyleVar_FrameBorderSize,     // float     FrameBorderSize
    ImGuiStyleVar_ItemSpacing,         // ImVec2    ItemSpacing
    ImGuiStyleVar_ItemInnerSpacing,    // ImVec2    ItemInnerSpacing
    ImGuiStyleVar_IndentSpacing,       // float     IndentSpacing
    ImGuiStyleVar_ScrollbarSize,       // float     ScrollbarSize
    ImGuiStyleVar_ScrollbarRounding,   // float     ScrollbarRounding
    ImGuiStyleVar_GrabMinSize,         // float     GrabMinSize
    ImGuiStyleVar_GrabRounding,        // float     GrabRounding
    ImGuiStyleVar_TabRounding,         // float     TabRounding
    ImGuiStyleVar_ButtonTextAlign,     // ImVec2    ButtonTextAlign
    ImGuiStyleVar_SelectableTextAlign, // ImVec2    SelectableTextAlign
    ImGuiStyleVar_COUNT
};
```

```cpp
// Flags for ImGui::BeginTabItem()
enum ImGuiTabItemFlags_
{
    ImGuiTabItemFlags_None                          = 0,
    ImGuiTabItemFlags_UnsavedDocument               = 1 << 0,   // Append '*' to title without affecting the ID, as a convenience to avoid using the ### operator. Also: tab is selected on closure and closure is deferred by one frame to allow code to undo it without flicker.
    ImGuiTabItemFlags_SetSelected                   = 1 << 1,   // Trigger flag to programmatically make the tab selected when calling BeginTabItem()
    ImGuiTabItemFlags_NoCloseWithMiddleMouseButton  = 1 << 2,   // Disable behavior of closing tabs (that are submitted with p_open != NULL) with middle mouse button. You can still repro this behavior on user's side with if (IsItemHovered() && IsMouseClicked(2)) *p_open = false.
    ImGuiTabItemFlags_NoPushId                      = 1 << 3    // Don't call PushID(tab->ID)/PopID() on BeginTabItem()/EndTabItem()
};
```

```cpp
enum ImGuiTabBarFlags_
{
    ImGuiTabBarFlags_None                           = 0,
    ImGuiTabBarFlags_Reorderable                    = 1 << 0,   // Allow manually dragging tabs to re-order them + New tabs are appended at the end of list
    ImGuiTabBarFlags_AutoSelectNewTabs              = 1 << 1,   // Automatically select new tabs when they appear
    ImGuiTabBarFlags_TabListPopupButton             = 1 << 2,   // Disable buttons to open the tab list popup
    ImGuiTabBarFlags_NoCloseWithMiddleMouseButton   = 1 << 3,   // Disable behavior of closing tabs (that are submitted with p_open != NULL) with middle mouse button. You can still repro this behavior on user's side with if (IsItemHovered() && IsMouseClicked(2)) *p_open = false.
    ImGuiTabBarFlags_NoTabListScrollingButtons      = 1 << 4,   // Disable scrolling buttons (apply when fitting policy is ImGuiTabBarFlags_FittingPolicyScroll)
    ImGuiTabBarFlags_NoTooltip                      = 1 << 5,   // Disable tooltips when hovering a tab
    ImGuiTabBarFlags_FittingPolicyResizeDown        = 1 << 6,   // Resize tabs when they don't fit
    ImGuiTabBarFlags_FittingPolicyScroll            = 1 << 7,   // Add scroll buttons when tabs don't fit
    ImGuiTabBarFlags_FittingPolicyMask_             = ImGuiTabBarFlags_FittingPolicyResizeDown | ImGuiTabBarFlags_FittingPolicyScroll,
    ImGuiTabBarFlags_FittingPolicyDefault_          = ImGuiTabBarFlags_FittingPolicyResizeDown
};
```

```cpp
enum ImGuiHoveredFlags_
{
    ImGuiHoveredFlags_None                          = 0,        // Return true if directly over the item/window, not obstructed by another window, not obstructed by an active popup or modal blocking inputs under them.
    ImGuiHoveredFlags_ChildWindows                  = 1 << 0,   // IsWindowHovered() only: Return true if any children of the window is hovered
    ImGuiHoveredFlags_RootWindow                    = 1 << 1,   // IsWindowHovered() only: Test from root window (top most parent of the current hierarchy)
    ImGuiHoveredFlags_AnyWindow                     = 1 << 2,   // IsWindowHovered() only: Return true if any window is hovered
    ImGuiHoveredFlags_AllowWhenBlockedByPopup       = 1 << 3,   // Return true even if a popup window is normally blocking access to this item/window
    //ImGuiHoveredFlags_AllowWhenBlockedByModal     = 1 << 4,   // Return true even if a modal popup window is normally blocking access to this item/window. FIXME-TODO: Unavailable yet.
    ImGuiHoveredFlags_AllowWhenBlockedByActiveItem  = 1 << 5,   // Return true even if an active item is blocking access to this item/window. Useful for Drag and Drop patterns.
    ImGuiHoveredFlags_AllowWhenOverlapped           = 1 << 6,   // Return true even if the position is obstructed or overlapped by another window
    ImGuiHoveredFlags_AllowWhenDisabled             = 1 << 7,   // Return true even if the item is disabled
    ImGuiHoveredFlags_RectOnly                      = ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem | ImGuiHoveredFlags_AllowWhenOverlapped,
    ImGuiHoveredFlags_RootAndChildWindows           = ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows
};
```


# get\_display\_size

### vec2 get\_display\_size()


# set\_next\_window\_size

### void set\_next\_window\_size(vec2 size)


# set\_next\_window\_pos

### void set\_next\_window\_pos(vec2 pos)


# get\_window\_size

### vec2 get\_window\_size()


# get\_window\_pos

### vec2 get\_window\_pos()


# push\_style\_var

Pushes a style onto the stack.

void push\_style\_var(int ImGuiStyleVar\_, float|vec2)

```lua
g_imgui.push_style_var(ImGuiStyleVar_WindowBorderSize, 0.0);
g_imgui.push_style_var(ImGuiStyleVar_WindowPadding, vec(0, 0));
```


# pop\_style\_var

Pops a style from the stack.

void pop\_style\_var(int count = 1)

```lua
g_imgui.push_style_var(ImGuiStyleVar_WindowBorderSize, 0.0);
g_imgui.push_style_var(ImGuiStyleVar_WindowPadding, vec(0, 0));
// draw your stuff here
g_imgui.pop_style_var(2) // resets the style changes
```


# begin\_window

### bool begin\_window(string name, int ImGuiWindowFlags\_ = 0)


# end\_window

### void end\_window()


# begin\_child

### bool begin\_child(string name, vec2 pos = vec2(), bool border = false, int ImGuiWindowFlags\_ = 0)


# end\_child

### void end\_child()


# same\_line

### void same\_line()


# new\_line

### void new\_line()


# separator

### void separator()


# columns

### void columns(int count = 1, bool border = true)


# next\_column

void next\_column()


# set\_column\_offset

void set\_column\_offset(int idx, float offset)


# is\_item\_hovered

Returns whether the last item is being hovered by the mouse or not.

bool is\_item\_hovered()


# add\_line

### void add\_line(vec2 p1, vec2 p2, int r, int g, int b, float thickness = 1.f)


# add\_circle

### void add\_circle(vec2 center, float radius, int r, int g, int b, int num\_segments = 12, float thickness = 1.f)


# add\_circle\_filled

### void add\_circle\_filled(vec2 center, float radius, int r, int g, int b, int num\_segments = 12)


# add\_rect

### void add\_rect(vec2 min, vec2 max, int r, int g, int b, float rounding = 0.f, float thickness = 1.f)


# add\_rect\_filled

### void add\_rect\_filled(vec2 min, vec2 max, int r, int g, int b, float rounding = 0.f)


# set\_next\_item\_width

### void set\_next\_item\_width(float width)


# get\_content\_region\_avail

### vec2 get\_content\_region\_avail()


# add\_button

### bool add\_button(string name, vec2|function() callback)


# add\_checkbox

### bool add\_checkbox(string name, function(bool) callback)


# add\_input\_string

bool add\_input\_string(string name, function(string) callback)


# add\_input\_string\_with\_hint

bool add\_input\_string\_with\_hint(string name, string hint, function(string) callback)


# add\_text

### void add\_text(string text)


# add\_triangle

void add\_triangle(vec2 p1, vec2 p2, vec2 p3, int r, int g, int b, float thickness = 1.f)


# add\_triangle\_filled

void add\_triangle\_filled(vec2 p1, vec2 p2, vec2 p3, int r, int g, int b)


# begin\_main\_menu\_bar

bool begin\_main\_menu\_bar()


# end\_main\_menu\_bar

void end\_main\_menu\_bar()


# begin\_menu

bool begin\_menu(string label, bool enabled = true)


# end\_menu

void end\_menu()


# menu\_item

bool menu\_item(string label)


# begin\_tab\_bar

bool begin\_tab\_bar(string str\_id, int ImGuiTabBarFlags)


# end\_tab\_bar

void end\_tab\_bar()




---

[Next Page](/llms-full.txt/1)

