Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

API Reference

Oleksandr Nemesh edited this page Apr 18, 2024 · 4 revisions

The API is a simple set of functions that you can use to interact with OpenHack. Here is a list of all available functions:

Base functions

bool openhack::isLoaded()*

Returns true if OpenHack is loaded and the API is available.

Note

This function is only available if you include the API with dynamic symbol loading. If you include the API as a dependency, you can assume that OpenHack is loaded.

if (!openhack::isLoaded()) {
    // Break or return out of the function, because OpenHack is not loaded
    return;
}

You're supposed to call this function before calling any other API functions to make sure that OpenHack is loaded.

bool openhack::isCheating()

Returns true if user have any cheats enabled (e.g. auto safe mode is active).

if (openhack::isCheating()) {
    // User is cheating
}

bool openhack::getSetting(const char* key)

Returns true if the setting with the specified key is enabled.

if (openhack::getSetting("level.noclip")) {
    // Noclip is enabled
}

UI Functions

The following functions are used to use the OpenHack UI system to create custom windows and buttons.

void openhack::ui::label(char const* text)

Draws a label with the specified text.

openhack::ui::label("My Custom Label");
openhack::ui::label(fmt::format("Hello, {}!", "World").c_str());

void openhack::ui::width(float width = 0.f)

Pushes the width of the next UI element.

openhack::ui::width(200.f);
// The next UI element will have a width of 200 pixels
// Don't forget to call this function again with 0.f to reset the width 
// (may lead to memory leaks)
openhack::ui::width();

bool openhack::ui::inputFloat(char const* label, float* value, float min = FLT_MIN, float max = FLT_MAX, char const* format = "%.3f")

Draws an input field for a float value.

// somewhere in your code
float myValue = 0.f;

// in your draw callback
openhack::ui::width(120.f); // Set the width of the input field

// Create an input field for the value 
// with a minimum of 0 and a maximum of 100
if (openhack::ui::inputFloat("My Value", &myValue, 0.f, 100.f)) {
    // Value has changed
}

openhack::ui::width();

bool openhack::ui::inputText(char const* label, const std::string* value, int maxLength = 256, char const* placeholder = "")

Draws an input field for a string value.

// somewhere in your code
std::string myText = "Hello, World!";

// in your draw callback
openhack::ui::width(120.f); // Set the width of the input field

// Create an input field for the value
if (openhack::ui::inputText("My Text", &myText)) {
    // Text has changed
}

openhack::ui::width();

bool openhack::ui::button(char const* label, float widthScale = 0.f)

Draws a button with the specified label.

if (openhack::ui::button("My Button")) {
    // Button was clicked
}

bool openhack::ui::checkbox(char const* label, bool* value)

Draws a checkbox with the specified label.

// somewhere in your code
bool myValue = false;

// in your draw callback
if (openhack::ui::checkbox("My Checkbox", &myValue)) {
    // Checkbox was toggled
}

void openhack::ui::tooltip(char const* text)

Adds a tooltip to the last UI element.

openhack::ui::button("My Button");
openhack::ui::tooltip("This is a tooltip for the button");

void openhack::ui::createWindow(char const* title, std::function<void()> const& drawCallback)

Creates a new UI window with the specified title and draw callback.

Warning

You should only call this function once! Calling it multiple times will create multiple windows. If you want to update the window content, you should use the draw callback function.

openhack::createWindow("My Custom Window", []() {
    openhack::ui::label("Hello, World!");
    if (openhack::ui::button("My Button")) {
        FLAlertLayer::create("Hi!", "You've pressed the button!", "OK")->show();
    }
    // You can use any other UI functions here...
});