Skip to content

Commit

Permalink
Merge e6ccaad into 48c4c45
Browse files Browse the repository at this point in the history
  • Loading branch information
UE4SS authored Jan 11, 2025
2 parents 48c4c45 + e6ccaad commit bf0926d
Show file tree
Hide file tree
Showing 23 changed files with 1,185 additions and 353 deletions.
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

0 comments on commit bf0926d

Please sign in to comment.