Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua API improvements + direct UEVR integration #255

Merged
merged 47 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
2347677
Lua: Add LuaLoader, Lua API improvements
praydog Mar 6, 2024
14fa2c6
Lua: Fix initial run not executing on game thread
praydog Mar 6, 2024
18e7b9e
Plugins: Fix huge bug with remove_callback
praydog Mar 6, 2024
2c44167
Lua: Stability improvements on script reset
praydog Mar 6, 2024
8fb6c3d
Lua: Fix execute_command not working
praydog Mar 6, 2024
c2994ca
Lua: improvement to UI layout
praydog Mar 6, 2024
49c3623
Merge branch 'master' into lua-api
praydog Jun 16, 2024
bca07ec
Lua: Some fixes, basic UObject property getters
praydog Jun 16, 2024
51153a4
Merge branch 'master' into lua-api
praydog Jun 16, 2024
868d9dc
Merge branch 'master' into lua-api
praydog Jun 16, 2024
fc2c32c
Merge branch 'master' into lua-api
praydog Jun 16, 2024
4800848
Lua: Add basic auto type-resolving get_property
praydog Jun 16, 2024
2ba4fe9
Merge branch 'master' into lua-api
praydog Jun 16, 2024
f06754d
Merge branch 'master' into lua-api
praydog Jun 16, 2024
a544e3d
Merge branch 'master' into lua-api
praydog Jun 16, 2024
62444ea
Lua: Add support for TArray<UObject*>
praydog Jun 16, 2024
1dfa166
Lua: Add example script
praydog Jun 16, 2024
5c281ff
Lua: Add support for directly indexing properties
praydog Jun 16, 2024
a88cab3
Lua: Add support for setting properties
praydog Jun 16, 2024
5b07a66
Merge branch 'master' into lua-api
praydog Jun 17, 2024
c18ee40
Merge branch 'master' into lua-api
praydog Jun 17, 2024
43859e5
Lua: Add basic function calling
praydog Jun 17, 2024
64e8e8c
Lua: Fix incorrect return value
praydog Jun 17, 2024
eb6f0d7
Lua: Throw error on set_property if it doesn't exist
praydog Jun 17, 2024
459eb1b
Lua: Add support for StrProperty parameters, ClassProperty
praydog Jun 19, 2024
9ccb374
Plugins: Fix cases where object finder could return default objects
praydog Jun 19, 2024
735ca89
Lua: Return class if possible, add conversion functions
praydog Jun 19, 2024
4cedaa7
Plugins: Add FStructProperty functions
praydog Jun 26, 2024
2891e90
Lua: Initial work on Vector types
praydog Jun 26, 2024
0bbc7ae
Lua: Fix Vector types returned from functions
praydog Jun 26, 2024
5286661
Lua: Initial support for passing Vector types to functions
praydog Jun 26, 2024
329001f
Lua: Migrate utility functions to separate files
praydog Jun 26, 2024
eb7f498
Lua: Add support for reading/modifying StructProperty properties
praydog Jun 26, 2024
ff35a24
Lua: Add support for passing StructObjects to functions
praydog Jun 26, 2024
525b785
Lua: update example script with more tests
praydog Jun 26, 2024
e20ba57
Lua: Add StructObject.new(UStruct*)
praydog Jun 26, 2024
ab95587
Lua: Pass correct pos/rot structs through stereo callbacks
praydog Jun 28, 2024
6eecdb9
Lua: Vector property parity with UE naming
praydog Jun 28, 2024
3d59cc8
Plugins: Activate UObjectHook if any functions are called
praydog Jun 28, 2024
a16461a
Plugins: Add FEnumProperty functions
praydog Jun 28, 2024
21aaf9a
Lua: Add support for enum properties and some other primitives
praydog Jun 28, 2024
238ef07
Lua: Use set_property for call_function args
praydog Jun 28, 2024
0aa8575
Lua: Cleanup TArray return values
praydog Jun 28, 2024
fa90052
Lua: Fix redundant param resize
praydog Jun 28, 2024
4545fe4
CI: Attempt at including LuaVR.dll in builds
praydog Jul 4, 2024
c0302b7
Lua: Fix undefined behavior when loading LuaVR.dll
praydog Jul 4, 2024
6de0fe4
Merge branch 'master' into lua-api
praydog Jul 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 51 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -590,14 +590,60 @@ target_include_directories(sol2 INTERFACE
unset(CMKR_TARGET)
unset(CMKR_SOURCES)

# Target luavrlib
set(CMKR_TARGET luavrlib)
set(luavrlib_SOURCES "")

list(APPEND luavrlib_SOURCES
"lua-api/lib/src/ScriptContext.cpp"
"lua-api/lib/src/ScriptState.cpp"
"lua-api/lib/include/ScriptContext.hpp"
"lua-api/lib/include/ScriptState.hpp"
)

list(APPEND luavrlib_SOURCES
cmake.toml
)

set(CMKR_SOURCES ${luavrlib_SOURCES})
add_library(luavrlib STATIC)

if(luavrlib_SOURCES)
target_sources(luavrlib PRIVATE ${luavrlib_SOURCES})
endif()

source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${luavrlib_SOURCES})

target_compile_features(luavrlib PUBLIC
cxx_std_23
)

target_compile_options(luavrlib PUBLIC
"/bigobj"
"/EHa"
"/MP"
)

target_include_directories(luavrlib PUBLIC
"include/"
"lua-api/lib/include"
)

target_link_libraries(luavrlib PUBLIC
lua
sol2
kananlib
)

unset(CMKR_TARGET)
unset(CMKR_SOURCES)

# Target LuaVR
set(CMKR_TARGET LuaVR)
set(LuaVR_SOURCES "")

list(APPEND LuaVR_SOURCES
"lua-api/Main.cpp"
"lua-api/ScriptContext.cpp"
"lua-api/ScriptContext.hpp"
)

list(APPEND LuaVR_SOURCES
Expand Down Expand Up @@ -628,9 +674,7 @@ target_include_directories(LuaVR PUBLIC
)

target_link_libraries(LuaVR PUBLIC
lua
sol2
kananlib
luavrlib
)

set_target_properties(LuaVR PROPERTIES
Expand Down Expand Up @@ -669,6 +713,7 @@ list(APPEND uevr_SOURCES
"src/hooks/XInputHook.cpp"
"src/mods/FrameworkConfig.cpp"
"src/mods/ImGuiThemeHelpers.cpp"
"src/mods/LuaLoader.cpp"
"src/mods/PluginLoader.cpp"
"src/mods/UObjectHook.cpp"
"src/mods/VR.cpp"
Expand Down Expand Up @@ -788,6 +833,7 @@ target_link_libraries(uevr PUBLIC
DirectXTK12
sdkgenny
asmjit
luavrlib
)

target_link_libraries(uevr PUBLIC
Expand Down
23 changes: 17 additions & 6 deletions cmake.toml
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,29 @@ include-directories = ["dependencies/lua/src"]
type = "interface"
include-directories = ["dependencies/sol2/single/single/include"]

[target.LuaVR]
type = "shared"
[target.luavrlib]
type = "static"
compile-features = ["cxx_std_23"]
compile-options = ["/bigobj", "/EHa", "/MP"]
include-directories = ["include/"]
sources = ["lua-api/**.cpp", "lua-api/**.c"]
headers = ["lua-api/**.hpp", "lua-api/**.h"]
include-directories = ["include/", "lua-api/lib/include"]
sources = ["lua-api/lib/**.cpp", "lua-api/lib/**.c"]
headers = ["lua-api/lib/**.hpp", "lua-api/lib/**.h"]
link-libraries = [
"lua",
"sol2",
"kananlib"
]

[target.LuaVR]
type = "shared"
compile-features = ["cxx_std_23"]
compile-options = ["/bigobj", "/EHa", "/MP"]
include-directories = ["include/"]
sources = ["lua-api/Main.cpp"]
link-libraries = [
"luavrlib"
]

[target.LuaVR.properties]
RUNTIME_OUTPUT_DIRECTORY_RELEASE = "${CMAKE_BINARY_DIR}/bin/${CMKR_TARGET}"
RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO = "${CMAKE_BINARY_DIR}/bin/${CMKR_TARGET}"
Expand Down Expand Up @@ -241,7 +251,8 @@ link-libraries = [
"DirectXTK",
"DirectXTK12",
"sdkgenny",
"asmjit"
"asmjit",
"luavrlib"
]

[template.ue4template.properties]
Expand Down
16 changes: 9 additions & 7 deletions lua-api/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
// Lua API to expose UEVR functionality to Lua scripts via UE4SS

#include <windows.h>
#include "ScriptContext.hpp"
#include "lib/include/ScriptContext.hpp"

std::shared_ptr<uevr::ScriptContext> g_script_context{};

// Main exported function that takes in the lua_State*
extern "C" __declspec(dllexport) int luaopen_LuaVR(lua_State* L) {
luaL_checkversion(L);

ScriptContext::log("Initializing LuaVR...");
uevr::ScriptContext::log("Initializing LuaVR...");

auto script_context = ScriptContext::reinitialize(L);
g_script_context = uevr::ScriptContext::create(L);

if (!script_context->valid()) {
ScriptContext::log("LuaVR failed to initialize! Make sure to inject VR first!");
if (!g_script_context->valid()) {
uevr::ScriptContext::log("LuaVR failed to initialize! Make sure to inject VR first!");
return 0;
}

ScriptContext::log("LuaVR initialized!");
uevr::ScriptContext::log("LuaVR initialized!");

return script_context->setup_bindings();
return g_script_context->setup_bindings();
}

BOOL APIENTRY DllMain(HMODULE module, DWORD ul_reason_for_call, LPVOID reserved) {
Expand Down
Loading
Loading