Information • API • Callbacks
-
You need to add a function named
on_load
on your script. This function gets called after the script is successfuly loaded into GSF- Doing anything before
on_load
gets called will result in an undefined behaviour as most functionalities are loaded AFTER the script gets loaded
function on_load() -- do your script init here end
- Doing anything before
-
When loading a script the following sequence occures:
- The script gets loaded into the lua state
- GSF looks up an
on_load
function in the script - The API is initialized
- The
on_load
function is called
-
Different API's are placed in different namespace based off their intended purpose, this can also indicate that these different API's have specific permissions and purpose.
-
Snake cases.
NOTE: These namespaces are "pseudo" namespaces implemented through tables. There's a slight performance issue when you call/use the API from the "namespace" due to lua having to "resolve" these values from the "namespace". If you are calling/using an API a lot it is recommended to copy it to a local variable then use that instead.
Example:
local logging_function
function on_load()
logging_function = gsf.log
end
function example()
logging_function("use this instead of doing gsf.log(\"not this\")")
end
Namespaces | Purpose |
---|---|
gsf | Provides internal script related API's for GSF |
win | Windows API and internals |
mem | Process memory access |
imgui | API wrapper to ImGui |
Used for logging messages into the script's internal script log and if GSF is in debug mode, to the debug console.
- Parameters
- str_msg - [string] Message to be logged
- Return
- nil
- Remarks
- Permission
- None
Registers a lua callback function to be called based off the provided ID.
- Parameters
- id - [string] ID of the callback to register for.
- callback - [function] Lua function to be called for the event id.
- Return
- result - [boolean] Returns true if the callback was successfuly registered, otherwise false.
- Remarks
- Check the Callbacks section for more information regarding function signatures and ID's
- Permission
- None
Parses the game's LDR table list and finds the specified module.
- Parameters
- module_name - [string] Name of the module to find.
- Return
{ base_address, size }
- base_address - Contains the starting/base address of the module
- size - Size of the module
- Remarks
- When the module is not found, this function returns a
nil
. - module_name parameter will still require the
.dll
postfix as this API will use exact string matches.
- When the module is not found, this function returns a
- Permission
- None
Scans the memory starting at start_adr
up until the max limit defined by the size
parameter for a pattern provided in an IDA signature style.
- Parameters
- start_adr - [pointer] Starting address of the scan.
- size - [integer] Size limit of the scan from the starting address
- ida_pattern - [string] IDA signature style pattern used for the scan
- Return
- address - [pointer] Address of where the first occurence of the pattern was found.
- Remarks
- Permission
- None
Patches the memory specified by addr
with the array of bytes provided from byte_array
.
- Parameters
- addr - [pointer] Address in memory as to where the
byte_array
is written. - byte_array - [byte array] Array of bytes to be written at the specified address.
- addr - [pointer] Address in memory as to where the
- Return
- 0 - Successful
- 1 - Already patched
- 2 - Failed to change protection to
PAGE_EXECUTE_READWRITE
- 3 - Failed to restore original protection
- Remarks
- Permission
- None
Reads the specified memory address as an unisgned integer with a specified size.
- Parameters
- addr - [pointer] Address in memory to read from.
- prim_t_size - [integer] Size of the primitive int type to read
- 1 - BYTE
- 2 - U16
- 4 - U32
- 8 - U64
- 8 - Pointer
- Return
- value - [integer] value that was read from the target address
- Remarks
- Permission
- None
Writes the value
to a specified memory address
- Parameters
- addr - [pointer] Address in memory to write.
- prim_t_size - [integer] Size of the primitive int type to write
- 1 - BYTE
- 2 - U16
- 4 - U32
- 8 - U64
- 8 - Pointer
- value - [integer] Value to write
- Return
- Remarks
- Permission
- None
This API is only a wrapper for ImGui. Documentation for each function exists in the ImGui repo.
NOTE: These API must be called from an on_imgui_draw callback.
API | Wraps | Translation |
---|---|---|
begin | ImGui::Begin | imgui.begin(text) → ImGui::Begin(text, nullptr, ImGuiWindowFlags_::ImGuiWindowFlags_NoCollapse) |
iend | ImGui::End | |
text | ImGui::Text | imgui.text(text) → ImGui::Text(text) |
same_line | ImGui::SameLine | imgui.same_line() → ImGui::SameLine() |
button | ImGui::Button | imgui.button(text) → ImGui::Button(text) |
separator | ImGui::Separator |
Callback used for calling ImGUI API and ImGUI rendering.
- ID:
on_imgui_draw
- Function signature
function foo()
end
- Function signature arguments
- Remarks
Callback function for ID3D11DeviceContext::Draw
- ID:
dx_draw
- Function signature
function foo(args)
end
- Function signature arguments
- args - [table] Contains event and callback arguments
- cancel - [bool] Cancels the callback preventing the call
- VertexCount - [int] See callback function
- StartVertexLocation - [int] See callback function
- args - [table] Contains event and callback arguments
- Remarks
Callback function for ID3D11DeviceContext::DrawIndexed
- ID:
dx_drawindexed
- Function signature
function foo(args)
end
- Function signature arguments
- args - [table] Contains event and callback arguments
- cancel - [bool] Cancels the callback preventing the call
- IndexCount - [int] See callback function
- StartIndexLocation - [int] See callback function
- BaseVertexLocation - [int] See callback function
- args - [table] Contains event and callback arguments
- Remarks