From 30ed0dea7d9e97db8c15a7ceaace5129e1cbc361 Mon Sep 17 00:00:00 2001 From: praydog Date: Sun, 1 Dec 2024 15:17:21 -0800 Subject: [PATCH] Plugins/Lua: Add api:add_component_by_class(actor, class) --- include/uevr/API.h | 4 +++- include/uevr/API.hpp | 5 +++++ lua-api/lib/src/ScriptContext.cpp | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/uevr/API.h b/include/uevr/API.h index 1147a8b1..2979947a 100644 --- a/include/uevr/API.h +++ b/include/uevr/API.h @@ -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 @@ -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 { diff --git a/include/uevr/API.hpp b/include/uevr/API.hpp index 4f6dbed5..a123820a 100644 --- a/include/uevr/API.hpp +++ b/include/uevr/API.hpp @@ -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()); diff --git a/lua-api/lib/src/ScriptContext.cpp b/lua-api/lib/src/ScriptContext.cpp index 2eac1a9b..a3420b44 100644 --- a/lua-api/lib/src/ScriptContext.cpp +++ b/lua-api/lib/src/ScriptContext.cpp @@ -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()) { + deferred = deferred_obj.as(); + } + + 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