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 all 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
5 changes: 5 additions & 0 deletions .github/workflows/dev-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
- name: Build plugin nullifier
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target vr-plugin-nullifier

- name: Build Lua API (shared DLL)
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target LuaVR

- name: Checkout frontend
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
Expand All @@ -47,13 +50,15 @@ jobs:
path: |
${{github.workspace}}/build/bin/${{matrix.target}}/*
${{github.workspace}}/build/bin/vr-plugin-nullifier/UEVRPluginNullifier.dll
${{github.workspace}}/build/bin/LuaVR/LuaVR.dll
if-no-files-found: error

- name: Compress artifacts
run: |
echo ${{github.sha}} > ${{github.workspace}}/revision.txt
7z a ${{github.workspace}}/${{matrix.target}}.zip ${{github.workspace}}/build/bin/${{matrix.target}}/*
7z a ${{github.workspace}}/${{matrix.target}}.zip ${{github.workspace}}/build/bin/vr-plugin-nullifier/UEVRPluginNullifier.dll
7z a ${{github.workspace}}/${{matrix.target}}.zip ${{github.workspace}}/build/bin/LuaVR/LuaVR.dll
7z a ${{github.workspace}}/${{matrix.target}}.zip ${{github.workspace}}/revision.txt

- name: Hash zip
Expand Down
63 changes: 58 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -590,14 +590,67 @@ 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/src/ScriptUtility.cpp"
"lua-api/lib/src/datatypes/StructObject.cpp"
"lua-api/lib/src/datatypes/Vector.cpp"
"lua-api/lib/include/ScriptContext.hpp"
"lua-api/lib/include/ScriptState.hpp"
"lua-api/lib/include/ScriptUtility.hpp"
"lua-api/lib/include/datatypes/StructObject.hpp"
"lua-api/lib/include/datatypes/Vector.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
glm
)

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 +681,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 +720,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 +840,7 @@ target_link_libraries(uevr PUBLIC
DirectXTK12
sdkgenny
asmjit
luavrlib
)

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

[target.luavrlib]
type = "static"
compile-features = ["cxx_std_23"]
compile-options = ["/bigobj", "/EHa", "/MP"]
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",
"glm"
]

[target.LuaVR]
type = "shared"
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"]
sources = ["lua-api/Main.cpp"]
link-libraries = [
"lua",
"sol2",
"kananlib"
"luavrlib"
]

[target.LuaVR.properties]
Expand Down Expand Up @@ -241,7 +252,8 @@ link-libraries = [
"DirectXTK",
"DirectXTK12",
"sdkgenny",
"asmjit"
"asmjit",
"luavrlib"
]

[template.ue4template.properties]
Expand Down
15 changes: 15 additions & 0 deletions include/uevr/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ DECLARE_UEVR_HANDLE(UEVR_FRHITexture2DHandle);
DECLARE_UEVR_HANDLE(UEVR_UScriptStructHandle);
DECLARE_UEVR_HANDLE(UEVR_FArrayPropertyHandle);
DECLARE_UEVR_HANDLE(UEVR_FBoolPropertyHandle);
DECLARE_UEVR_HANDLE(UEVR_FStructPropertyHandle);
DECLARE_UEVR_HANDLE(UEVR_FEnumPropertyHandle);
DECLARE_UEVR_HANDLE(UEVR_UEnumHandle);
DECLARE_UEVR_HANDLE(UEVR_FNumericPropertyHandle);

/* OpenXR stuff */
DECLARE_UEVR_HANDLE(UEVR_XrInstance);
Expand Down Expand Up @@ -413,6 +417,15 @@ typedef struct {
void (*set_value_in_propbase)(UEVR_FBoolPropertyHandle prop, void* addr, bool value);
} UEVR_FBoolPropertyFunctions;

typedef struct {
UEVR_UScriptStructHandle (*get_struct)(UEVR_FStructPropertyHandle prop);
} UEVR_FStructPropertyFunctions;

typedef struct {
UEVR_FNumericPropertyHandle (*get_underlying_prop)(UEVR_FEnumPropertyHandle prop);
UEVR_UEnumHandle (*get_enum)(UEVR_FEnumPropertyHandle prop);
} UEVR_FEnumPropertyFunctions;

typedef struct {
const UEVR_SDKFunctions* functions;
const UEVR_SDKCallbacks* callbacks;
Expand All @@ -434,6 +447,8 @@ typedef struct {
const UEVR_UScriptStructFunctions* uscriptstruct;
const UEVR_FArrayPropertyFunctions* farrayproperty;
const UEVR_FBoolPropertyFunctions* fboolproperty;
const UEVR_FStructPropertyFunctions* fstructproperty;
const UEVR_FEnumPropertyFunctions* fenumproperty;
} UEVR_SDKData;

DECLARE_UEVR_HANDLE(UEVR_IVRSystem);
Expand Down
53 changes: 53 additions & 0 deletions include/uevr/API.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,59 @@ class API {
}
};

struct FStructProperty : public FProperty {
inline UEVR_FStructPropertyHandle to_handle() { return (UEVR_FStructPropertyHandle)this; }
inline UEVR_FStructPropertyHandle to_handle() const { return (UEVR_FStructPropertyHandle)this; }

UScriptStruct* get_struct() const {
static const auto fn = initialize()->get_struct;
return (UScriptStruct*)fn(to_handle());
}

private:
static inline const UEVR_FStructPropertyFunctions* s_functions{nullptr};
static inline const UEVR_FStructPropertyFunctions* initialize() {
if (s_functions == nullptr) {
s_functions = API::get()->sdk()->fstructproperty;
}

return s_functions;
}
};

struct UEnum : public UObject {

};

struct FNumericProperty : public FProperty {

};

struct FEnumProperty : public FProperty {
inline UEVR_FEnumPropertyHandle to_handle() { return (UEVR_FEnumPropertyHandle)this; }
inline UEVR_FEnumPropertyHandle to_handle() const { return (UEVR_FEnumPropertyHandle)this; }

FNumericProperty* get_underlying_prop() const {
static const auto fn = initialize()->get_underlying_prop;
return (FNumericProperty*)fn(to_handle());
}

UEnum* get_enum() const {
static const auto fn = initialize()->get_enum;
return (UEnum*)fn(to_handle());
}

private:
static inline const UEVR_FEnumPropertyFunctions* s_functions{nullptr};
static inline const UEVR_FEnumPropertyFunctions* initialize() {
if (s_functions == nullptr) {
s_functions = API::get()->sdk()->fenumproperty;
}

return s_functions;
}
};

struct FFieldClass {
inline UEVR_FFieldClassHandle to_handle() { return (UEVR_FFieldClassHandle)this; }
inline UEVR_FFieldClassHandle to_handle() const { return (UEVR_FFieldClassHandle)this; }
Expand Down
16 changes: 8 additions & 8 deletions lua-api/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
// 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...");

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