Skip to content

Commit

Permalink
Plugins/Lua: Add api:add_component_by_class(actor, class)
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Dec 1, 2024
1 parent b14be18 commit 30ed0de
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion include/uevr/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ SOFTWARE.
#define UEVR_OUT

#define UEVR_PLUGIN_VERSION_MAJOR 2
#define UEVR_PLUGIN_VERSION_MINOR 34
#define UEVR_PLUGIN_VERSION_MINOR 35
#define UEVR_PLUGIN_VERSION_PATCH 0

#define UEVR_RENDERER_D3D11 0
Expand Down Expand Up @@ -254,6 +254,8 @@ typedef struct {
void (*execute_command_ex)(UEVR_UObjectHandle world, const wchar_t* command, void* output_device);

UEVR_FConsoleManagerHandle (*get_console_manager)();

UEVR_UObjectHandle (*add_component_by_class)(UEVR_UObjectHandle actor, UEVR_UClassHandle klass, bool deferred);
} UEVR_SDKFunctions;

typedef struct {
Expand Down
5 changes: 5 additions & 0 deletions include/uevr/API.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ class API {
return (UObject*)fn(klass->to_handle(), outer->to_handle());
}

UObject* add_component_by_class(UObject* actor, UClass* klass, bool deferred = false) {
static const auto fn = sdk()->functions->add_component_by_class;
return (UObject*)fn(actor->to_handle(), klass->to_handle(), deferred);
}

void execute_command(std::wstring_view command) {
static const auto fn = sdk()->functions->execute_command;
fn(command.data());
Expand Down
14 changes: 14 additions & 0 deletions lua-api/lib/src/ScriptContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,20 @@ int ScriptContext::setup_bindings() {

return sol::make_object(s, obj);
},
"add_component_by_class", [](sol::this_state s, uevr::API* api, API::UObject* actor, API::UClass* klass, sol::object deferred_obj) -> sol::object {
bool deferred = false;
if (deferred_obj.is<bool>()) {
deferred = deferred_obj.as<bool>();
}

auto comp = api->add_component_by_class(actor, klass, deferred);

if (comp == nullptr) {
return sol::make_object(s, sol::lua_nil);
}

return sol::make_object(s, comp);
},
"execute_command", [](uevr::API* api, const std::wstring& s) { api->execute_command(s.data()); },
"get_uobject_array", &uevr::API::get_uobject_array,
"get_console_manager", &uevr::API::get_console_manager
Expand Down

0 comments on commit 30ed0de

Please sign in to comment.