-
Notifications
You must be signed in to change notification settings - Fork 194
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
Fixed keybinds created from C++ mods executing multiple times #446
Conversation
This only happened if the hot-reload feature was used to reload all mods. This was fixed by introducing CppUserModBase::register_keydown_event. It's identical to the one in UE4SSProgram, except it keeps track of which C++ mod registered the event so that it can be "unregistered" when the mod is reloaded. Mods that continue to use the UE4SSProgram version will continue to have the same problem. Updated changelog
Can you send the code responsible for registering the keybind? I'm trying to replicate but am having troubles with it due to getting "failed to load dll" due to that part of the code being erreonous somehow (removing that code causes the mod.dll to load fine). Admittedly I have never written ue4ss c++ mod code before as xmake branch is the first time I can actually compile ue4ss since c++ api was added. I figured the following code would work inside of the mod's constructor: const Input::EventCallbackCallable callback = [&] {
Output::send<LogLevel::Verbose>(STR("P key was pressed\n"));
};
register_keydown_event(Input::P, callback, 2); // I assume custom_data is 2 because it means the bind came from c++ |
This code is functioning, but wrong in the assumption that the last param should be 2. As far as your problem is concerned: Are you sure that you moved both UE4SS.dll and your mod dll after building ? EDIT: For the record, this is my event registration code: register_keydown_event(Input::Key::Q, {Input::ModifierKey::CONTROL}, [&]() {
Output::send<LogLevel::Warning>(STR("test\n"));
}); |
Ahhh yeah I was forgetting to replace the UE4SS.dll as well! Apologies! Thanks for the explanation though, I appreciate it. I can replicate your fix, so I think this is fine. btw, I searched at least 30 ue4ss cpp mods for this function (which already existed under the same name but only through |
Description
This only happened if the hot-reload feature was used to reload all mods.
This was fixed by introducing
CppUserModBase::register_keydown_event
.It's identical to the one in UE4SSProgram, except it keeps track of which C++ mod registered the event so that it can be "unregistered" when the mod is reloaded.
Mods that continue to use the UE4SSProgram version will continue to have the same problem.
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
I created a C++ mod that registered a keybind with the new function that output something to the console, and verified that only one message in the console appeared after using the bind after spamming the "Restart All Mods" button.
Checklist