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

InputSource, replaces #558 #749

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a201c80
InputSource: add dep to DynamicOutput
Yangff Jun 11, 2024
003ab95
Input Source: add windows platform code
Yangff Jun 11, 2024
224f744
Input Source: add SPSC ring buffer for key queue
Yangff Jun 11, 2024
033d771
Remove old code to refactor
Yangff Jun 11, 2024
e5fa329
Input Source: GLFW3
Yangff Jun 11, 2024
c197050
Input Source: Win32 Async
Yangff Jun 11, 2024
863d93e
Input Source: Common Queued Source
Yangff Jun 11, 2024
bd22994
Input Source: ModifierKeys ops
Yangff Jun 11, 2024
cd1f88b
Input Source: Platform Init for input sources
Yangff Jun 11, 2024
2b4d02b
Input Source: Platform Input Abstract
Yangff Jun 11, 2024
3dd7e8c
Input Source: Refactor Input Source Handler
Yangff Jun 11, 2024
4dd83b6
Input Source: Input Handler in UE4SS
Yangff Jun 11, 2024
943a9cd
Input Source: Apply HAS_INPUT macro
Yangff Jun 11, 2024
3ed1d50
Input Source: Use safe getter for input event
Yangff Jun 11, 2024
9a84288
Removed SYSSTR usages
UE4SS Jan 8, 2025
6dbf117
Various fixes, probably from broken cherry-pick
UE4SS Jan 8, 2025
4c6676c
Input: clang-format
UE4SS Jan 8, 2025
e0d7f68
Input Source: use new input_handler in UVTD
Yangff Jun 11, 2024
8f64196
Input: Fix UVTD
UE4SS Jan 8, 2025
22b7399
Make public APIs not disappear if HAS_INPUT isn't defined
UE4SS Jan 9, 2025
1b939bb
Made Handler.hpp always be the correct header to include
UE4SS Jan 9, 2025
0d83373
Fixed build when --ue4ssInput=n
UE4SS Jan 9, 2025
0524dc8
Moved back various definitions from KeyDef.hpp to Handler.hpp
UE4SS Jan 9, 2025
e6ccaad
Replaced include-guard with #pragma once for Handler.hpp
UE4SS Jan 9, 2025
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
1 change: 1 addition & 0 deletions UE4SS/include/SettingsManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace RC
bool EnableDebugKeyBindings{false};
int64_t SecondsToScanBeforeGivingUp{30};
bool UseUObjectArrayCache{true};
StringType InputSource{STR("Default")};
} General;

struct SectionEngineVersionOverride
Expand Down
5 changes: 4 additions & 1 deletion UE4SS/include/UE4SSProgram.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <GUI/GUI.hpp>
#include <GUI/GUITab.hpp>
#include <Input/Handler.hpp>

#include <LuaLibrary.hpp>
#include <MProgram.hpp>
#include <Mod/CppMod.hpp>
Expand Down Expand Up @@ -98,7 +99,9 @@ namespace RC
bool m_is_program_started;

protected:
Input::Handler m_input_handler{L"ConsoleWindowClass", L"UnrealWindow"};
#ifdef HAS_INPUT
Input::Handler m_input_handler;
#endif
std::jthread m_event_loop;

public:
Expand Down
19 changes: 11 additions & 8 deletions UE4SS/src/Mod/CppUserModBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <UE4SSProgram.hpp>
#include <String/StringType.hpp>

#include <vector>

namespace RC
{
CppUserModBase::CppUserModBase()
Expand All @@ -24,12 +26,12 @@ namespace RC
}
GUITabs.clear();

auto& key_events = UE4SSProgram::get_program().m_input_handler.get_events();
std::erase_if(key_events, [&](Input::KeySet& input_event) -> bool {
bool were_all_events_registered_from_this_mod = true;
for (auto& [key, vector_of_key_data] : input_event.key_data)
{
std::erase_if(vector_of_key_data, [&](Input::KeyData& key_data) -> bool {
#ifdef HAS_INPUT
UE4SSProgram::get_program().m_input_handler.get_events_safe([&](auto& key_set) {
std::erase_if(key_set.key_data, [&](auto& item) -> bool {
auto& [_, key_data] = item;
bool were_all_events_registered_from_this_mod = true;
std::erase_if(key_data, [&](Input::KeyData& key_data) -> bool {
// custom_data == 1: Bind came from Lua, and custom_data2 is nullptr.
// custom_data == 2: Bind came from C++, and custom_data2 is a pointer to KeyDownEventData. Must free it.
auto event_data = static_cast<KeyDownEventData*>(key_data.custom_data2);
Expand All @@ -44,10 +46,11 @@ namespace RC
return false;
}
});
}

return were_all_events_registered_from_this_mod;
return were_all_events_registered_from_this_mod;
});
});
#endif
}

auto CppUserModBase::register_tab(StringViewType tab_name, GUI::GUITab::RenderFunctionType render_function) -> void
Expand Down
2 changes: 2 additions & 0 deletions UE4SS/src/Mod/LuaMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include <ExceptionHandling.hpp>
#include <Helpers/Format.hpp>
#include <Helpers/String.hpp>

#include <Input/Handler.hpp>

#include <LuaLibrary.hpp>
#include <LuaMadeSimple/LuaMadeSimple.hpp>
#include <LuaType/LuaAActor.hpp>
Expand Down
61 changes: 43 additions & 18 deletions UE4SS/src/UE4SSProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,8 +824,7 @@ namespace RC
{
m_debugging_gui.get_live_view().set_listeners_allowed(false);
}

m_input_handler.register_keydown_event(Input::Key::O, {Input::ModifierKey::CONTROL}, [&]() {
register_keydown_event(Input::Key::O, {Input::ModifierKey::CONTROL}, [&]() {
TRY([&] {
auto was_gui_open = get_debugging_ui().is_open();
stop_render_thread();
Expand All @@ -839,7 +838,7 @@ namespace RC
}

#ifdef TIME_FUNCTION_MACRO_ENABLED
m_input_handler.register_keydown_event(Input::Key::Y, {Input::ModifierKey::CONTROL}, [&]() {
register_keydown_event(Input::Key::Y, {Input::ModifierKey::CONTROL}, [&]() {
if (FunctionTimerFrame::s_timer_enabled)
{
FunctionTimerFrame::stop_profiling();
Expand All @@ -856,16 +855,14 @@ namespace RC

TRY([&] {
ObjectDumper::init();

if (settings_manager.General.EnableHotReloadSystem)
{
m_input_handler.register_keydown_event(Input::Key::R, {Input::ModifierKey::CONTROL}, [&]() {
register_keydown_event(Input::Key::R, {Input::ModifierKey::CONTROL}, [&]() {
TRY([&] {
reinstall_mods();
});
});
}

if ((settings_manager.ObjectDumper.LoadAllAssetsBeforeDumpingObjects || settings_manager.CXXHeaderGenerator.LoadAllAssetsBeforeGeneratingCXXHeaders) &&
Unreal::Version::IsBelow(4, 17))
{
Expand All @@ -878,6 +875,21 @@ namespace RC
STR("FAssetData not available, ignoring 'LoadAllAssetsBeforeDumpingObjects' & 'LoadAllAssetsBeforeGeneratingCXXHeaders'."));
}

#ifdef HAS_INPUT
m_input_handler.init();
if (!settings_manager.General.InputSource.empty())
{
if (m_input_handler.set_input_source(to_string(settings_manager.General.InputSource)))
{
Output::send(STR("Input source set to: {}\n"), to_generic_string(m_input_handler.get_current_input_source()));
}
else
{
Output::send<LogLevel::Error>(STR("Failed to set input source to: {}\n"), settings_manager.General.InputSource);
}
}
#endif

install_lua_mods();
LuaMod::on_program_start();
fire_program_start_for_cpp_mods();
Expand All @@ -886,7 +898,7 @@ namespace RC

if (settings_manager.General.EnableDebugKeyBindings)
{
m_input_handler.register_keydown_event(Input::Key::NUM_NINE, {Input::ModifierKey::CONTROL}, [&]() {
register_keydown_event(Input::Key::NUM_NINE, {Input::ModifierKey::CONTROL}, [&]() {
generate_uht_compatible_headers();
});
}
Expand Down Expand Up @@ -948,9 +960,9 @@ namespace RC
}
}
//*/

#ifdef HAS_INPUT
m_input_handler.process_event();

#endif
{
ProfilerScopeNamed("mod update processing");

Expand Down Expand Up @@ -1318,13 +1330,13 @@ namespace RC

uninstall_mods();

// Remove key binds that were set from Lua scripts
auto& key_events = m_input_handler.get_events();
std::erase_if(key_events, [](Input::KeySet& input_event) -> bool {
bool were_all_events_registered_from_lua = true;
for (auto& [key, vector_of_key_data] : input_event.key_data)
{
std::erase_if(vector_of_key_data, [&](Input::KeyData& key_data) -> bool {
// Remove key binds that were set from Lua scripts
#ifdef HAS_INPUT
m_input_handler.get_events_safe([&](auto& key_set) {
std::erase_if(key_set.key_data, [&](auto& item) -> bool {
auto& [_, key_data] = item;
bool were_all_events_registered_from_lua = true;
std::erase_if(key_data, [&](Input::KeyData& key_data) -> bool {
// custom_data == 1: Bind came from Lua, and custom_data2 is nullptr.
// custom_data == 2: Bind came from C++, and custom_data2 is a pointer to KeyDownEventData. Must free it.
if (key_data.custom_data == 1)
Expand All @@ -1337,10 +1349,11 @@ namespace RC
return false;
}
});
}

return were_all_events_registered_from_lua;
return were_all_events_registered_from_lua;
});
});
#endif

// Remove all custom properties
// Uncomment when custom properties are working
Expand Down Expand Up @@ -1509,7 +1522,9 @@ namespace RC

auto UE4SSProgram::register_keydown_event(Input::Key key, const Input::EventCallbackCallable& callback, uint8_t custom_data, void* custom_data2) -> void
{
#ifdef HAS_INPUT
m_input_handler.register_keydown_event(key, callback, custom_data, custom_data2);
#endif
}

auto UE4SSProgram::register_keydown_event(Input::Key key,
Expand All @@ -1518,17 +1533,27 @@ namespace RC
uint8_t custom_data,
void* custom_data2) -> void
{
#ifdef HAS_INPUT
m_input_handler.register_keydown_event(key, modifier_keys, callback, custom_data, custom_data2);
#endif
}

auto UE4SSProgram::is_keydown_event_registered(Input::Key key) -> bool
{
#ifdef HAS_INPUT
return m_input_handler.is_keydown_event_registered(key);
#else
return false;
#endif
}

auto UE4SSProgram::is_keydown_event_registered(Input::Key key, const Input::Handler::ModifierKeyArray& modifier_keys) -> bool
{
#ifdef HAS_INPUT
return m_input_handler.is_keydown_event_registered(key, modifier_keys);
#else
return false;
#endif
}

auto UE4SSProgram::find_mod_by_name_internal(StringViewType mod_name, IsInstalled is_installed, IsStarted is_started, FMBNI_ExtraPredicate extra_predicate) -> Mod*
Expand Down
4 changes: 2 additions & 2 deletions UE4SS/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ target(projectName)
set_default(true)
add_rules("ue4ss.defines.exports")
add_rules("ue4ss.check.minimum.version")
add_options("ue4ssBetaIsStarted", "ue4ssIsBeta", "allowAllVersions")
add_options("ue4ssBetaIsStarted", "ue4ssIsBeta", "allowAllVersions", "ue4ssInput")
add_includedirs("include", { public = true })
add_includedirs("generated_include", { public = true })
add_headerfiles("include/**.hpp")
Expand All @@ -74,7 +74,7 @@ target(projectName)
"ScopedTimer", "Profiler", "patternsleuth_bind",
"glad", { public = true }
)

add_packages("fmt", { public = true })

add_packages("imgui", "ImGuiTextEdit", "IconFontCppHeaders", "glfw", "opengl", { public = true })
Expand Down
1 change: 0 additions & 1 deletion UVTD/include/UVTD/UVTD.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
namespace RC::UVTD
{
extern bool processing_events;
extern Input::Handler input_handler;

auto main(DumpSettings) -> void;
} // namespace RC::UVTD
Expand Down
10 changes: 0 additions & 10 deletions UVTD/src/UVTD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@
namespace RC::UVTD
{
bool processing_events{false};
Input::Handler input_handler{STR("ConsoleWindowClass"), STR("UnrealWindow")};

auto static event_loop_update() -> void
{
for (processing_events = true; processing_events;)
{
input_handler.process_event();
std::this_thread::sleep_for(std::chrono::milliseconds(5));
}
}

auto main(DumpSettings dump_settings) -> void
{
Expand Down
Loading
Loading