Skip to content

Commit 11b0743

Browse files
committed
fix(Lua): fix outparm/return handling for script hooks
1 parent a058bda commit 11b0743

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

UE4SS/src/Mod/LuaMod.cpp

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,17 @@ namespace RC
360360
if (LuaType::StaticState::m_property_value_pushers.contains(name_comparison_index))
361361
{
362362
// Non-typed pointer to the current parameter value
363-
// void* data = &context.TheStack.Locals[current_param_offset];
364-
void* data = func_prop->ContainerPtrToValuePtr<void>(context.TheStack.Locals());
363+
void* data{};
364+
if (func_prop->HasAnyPropertyFlags(Unreal::EPropertyFlags::CPF_OutParm))
365+
{
366+
// For out params (including ref params), get the modified value from OutParms
367+
data = Unreal::FindOutParamValueAddress(context.TheStack, func_prop);
368+
}
369+
else
370+
{
371+
// For regular input params, read from Locals
372+
data = func_prop->ContainerPtrToValuePtr<void>(context.TheStack.Locals());
373+
}
365374

366375
// Keeping track of where in the 'Locals' array the next property is
367376
// current_param_offset += func_prop->GetSize();
@@ -4208,25 +4217,7 @@ No overload found for function 'FPackageName:IsValidLongPackageName'.
42084217
erase_from_container(this, m_local_player_exec_post_callbacks);
42094218
erase_from_container(this, m_script_hook_callbacks);
42104219

4211-
UE4SSProgram::get_program().get_all_input_events([&](auto& key_set) {
4212-
std::erase_if(key_set.key_data, [&](auto& item) -> bool {
4213-
auto& [_, key_data] = item;
4214-
std::erase_if(key_data, [&](Input::KeyData& key_data) -> bool {
4215-
// custom_data == 1: Bind came from Lua, and custom_data2 is a pointer to LuaMod.
4216-
// custom_data == 2: Bind came from C++, and custom_data2 is a pointer to KeyDownEventData. Must free it.
4217-
if (key_data.custom_data == 1)
4218-
{
4219-
return key_data.custom_data2 == this;
4220-
}
4221-
else
4222-
{
4223-
return false;
4224-
}
4225-
});
4226-
4227-
return key_data.empty();
4228-
});
4229-
});
4220+
UE4SSProgram::get_program().unregister_keydown_events_for_lua_mod(this);
42304221

42314222
if (m_hook_lua != nullptr)
42324223
{

0 commit comments

Comments
 (0)