diff --git a/Plugins/UnLua/Source/UnLua/Private/LuaFunctionInjection.cpp b/Plugins/UnLua/Source/UnLua/Private/LuaFunctionInjection.cpp index b6fd996a..fe3108de 100644 --- a/Plugins/UnLua/Source/UnLua/Private/LuaFunctionInjection.cpp +++ b/Plugins/UnLua/Source/UnLua/Private/LuaFunctionInjection.cpp @@ -212,7 +212,11 @@ void RemoveUFunction(UFunction *Function, UClass *OuterClass) */ void OverrideUFunction(UFunction *Function, FNativeFuncPtr NativeFunc, void *Userdata, bool bInsertOpcodes) { - Function->SetNativeFunc(NativeFunc); + if (Function->HasAnyFunctionFlags(FUNC_Native)) + { + Function->SetNativeFunc(NativeFunc); + } + if (Function->Script.Num() < 1) { #if UE_BUILD_SHIPPING || UE_BUILD_TEST diff --git a/Plugins/UnLua/Source/UnLua/Private/UEReflectionUtils.cpp b/Plugins/UnLua/Source/UnLua/Private/UEReflectionUtils.cpp index 36fd8949..9a334f7e 100644 --- a/Plugins/UnLua/Source/UnLua/Private/UEReflectionUtils.cpp +++ b/Plugins/UnLua/Source/UnLua/Private/UEReflectionUtils.cpp @@ -1145,6 +1145,15 @@ int32 FFunctionDesc::CallUE(lua_State *L, int32 NumParams, void *Userdata) return 0; } +#if SUPPORTS_RPC_CALL + int32 Callspace = Object->GetFunctionCallspace(Function, nullptr); + bool bRemote = Callspace & FunctionCallspace::Remote; +#else + bool bRemote = false; +#endif + + void *Params = PreCall(L, NumParams, FirstParamIndex, Userdata, bRemote); // prepare values of properties + UFunction *FinalFunction = Function; if (bInterfaceFunc) { @@ -1167,7 +1176,7 @@ int32 FFunctionDesc::CallUE(lua_State *L, int32 NumParams, void *Userdata) #if ENABLE_CALL_OVERRIDDEN_FUNCTION else { - if (Function->HasAnyFunctionFlags(FUNC_BlueprintEvent)) + if (Function->HasAnyFunctionFlags(FUNC_BlueprintEvent) && !bRemote) { UFunction *OverriddenFunc = GReflectionRegistry.FindOverriddenFunction(Function); if (OverriddenFunc) @@ -1178,14 +1187,6 @@ int32 FFunctionDesc::CallUE(lua_State *L, int32 NumParams, void *Userdata) } #endif - bool bRemote = false; -#if SUPPORTS_RPC_CALL - int32 Callspace = Object->GetFunctionCallspace(FinalFunction, nullptr); - bRemote = Callspace & FunctionCallspace::Remote; -#endif - - void *Params = PreCall(L, NumParams, FirstParamIndex, Userdata, bRemote); // prepare values of properties - // call the UFuncton... #if !SUPPORTS_RPC_CALL && !WITH_EDITOR if (FinalFunction->HasAnyFunctionFlags(FUNC_Native)) diff --git a/Plugins/UnLua/Source/UnLua/Private/UnLuaManager.cpp b/Plugins/UnLua/Source/UnLua/Private/UnLuaManager.cpp index 16624756..7a5a9138 100644 --- a/Plugins/UnLua/Source/UnLua/Private/UnLuaManager.cpp +++ b/Plugins/UnLua/Source/UnLua/Private/UnLuaManager.cpp @@ -223,7 +223,6 @@ void UUnLuaManager::Cleanup(UWorld *InWorld, bool bFullCleanup) AttachedObjects.Empty(); } AttachedActors.Empty(); - ActorsWithoutWorld.Empty(); } ModuleNames.Empty(); @@ -494,29 +493,6 @@ void UUnLuaManager::OnMapLoaded(UWorld *World) } ENetMode NetMode = World->GetNetMode(); -#if SUPPORTS_RPC_CALL - for (AActor *Actor : ActorsWithoutWorld) - { - UClass *Class = GetTargetClass(Actor->GetClass()); - FString *ModuleName = ModuleNames.Find(Class); - check(ModuleName); - TSet *LuaFunctionsPtr = ModuleFunctions.Find(*ModuleName); - TMap *UEFunctionsPtr = OverridableFunctions.Find(Class); - check(LuaFunctionsPtr && UEFunctionsPtr); - for (const FName &LuaFuncName : (*LuaFunctionsPtr)) - { - UFunction **Func = UEFunctionsPtr->Find(LuaFuncName); - if (Func) - { - UFunction *Function = *Func; - if ((Function->HasAnyFunctionFlags(FUNC_NetClient) && NetMode == NM_Client) || (Function->HasAnyFunctionFlags(FUNC_NetServer) && (NetMode == NM_DedicatedServer || NetMode == NM_ListenServer))) - { - OverrideFunction(Function, Class, LuaFuncName); - } - } - } - } -#endif if (NetMode == NM_DedicatedServer) { return; @@ -659,8 +635,7 @@ bool UUnLuaManager::BindInternal(UObjectBaseUtility *Object, UClass *Class, cons TMap &UEFunctions = OverridableFunctions.Add(Class); GetOverridableFunctions(Class, UEFunctions); // get all overridable UFunctions - ENetMode NetMode = CheckObjectNetMode(Object, Class, bNewCreated); - OverrideFunctions(LuaFunctions, UEFunctions, Class, bNewCreated, NetMode); // try to override UFunctions + OverrideFunctions(LuaFunctions, UEFunctions, Class, bNewCreated); // try to override UFunctions return ConditionalUpdateClass(Class, LuaFunctions, UEFunctions); } @@ -726,33 +701,10 @@ bool UUnLuaManager::ConditionalUpdateClass(UClass *Class, const TSet &Lua return true; } -/** - * Check net mode of the UObject - */ -ENetMode UUnLuaManager::CheckObjectNetMode(UObjectBaseUtility *Object, UClass *Class, bool bNewCreated) -{ - ENetMode NetMode = NM_Standalone; -#if SUPPORTS_RPC_CALL - if (bNewCreated) - { - if (Class->IsChildOf() && !Object->HasAnyFlags(RF_ClassDefaultObject | RF_ArchetypeObject) && !Object->GetOuter()->HasAnyFlags(RF_BeginDestroyed) && !Object->GetOuter()->IsUnreachable()) - { - ULevel *Level = Object->GetTypedOuter(); - NetMode = Level && Level->OwningWorld ? Level->OwningWorld->GetNetMode() : NM_MAX; - } - if (NetMode == NM_MAX) - { - ActorsWithoutWorld.Add((AActor*)Object); - } - } -#endif - return NetMode; -} - /** * Override candidate UFunctions */ -void UUnLuaManager::OverrideFunctions(const TSet &LuaFunctions, TMap &UEFunctions, UClass *OuterClass, bool bCheckFuncNetMode, ENetMode NetMode) +void UUnLuaManager::OverrideFunctions(const TSet &LuaFunctions, TMap &UEFunctions, UClass *OuterClass, bool bCheckFuncNetMode) { for (const FName &LuaFuncName : LuaFunctions) { @@ -760,16 +712,6 @@ void UUnLuaManager::OverrideFunctions(const TSet &LuaFunctions, TMapHasAnyFunctionFlags(FUNC_NetClient) && (NetMode == NM_DedicatedServer || NetMode == NM_ListenServer || NetMode == NM_MAX)) || - (Function->HasAnyFunctionFlags(FUNC_NetServer) && (NetMode == NM_Client || NetMode == NM_MAX))) - { - continue; - } - } -#endif OverrideFunction(Function, OuterClass, LuaFuncName); } } diff --git a/Plugins/UnLua/Source/UnLua/Private/UnLuaManager.h b/Plugins/UnLua/Source/UnLua/Private/UnLuaManager.h index 2b63bbc5..d26f7683 100644 --- a/Plugins/UnLua/Source/UnLua/Private/UnLuaManager.h +++ b/Plugins/UnLua/Source/UnLua/Private/UnLuaManager.h @@ -82,9 +82,7 @@ class UUnLuaManager : public UObject bool BindSurvivalObject(struct lua_State *L, UObjectBaseUtility *Object, UClass *Class, const char *ModuleName); bool ConditionalUpdateClass(UClass *Class, const TSet &LuaFunctions, TMap &UEFunctions); - ENetMode CheckObjectNetMode(UObjectBaseUtility *Object, UClass *Class, bool bNewCreated); - - void OverrideFunctions(const TSet &LuaFunctions, TMap &UEFunctions, UClass *OuterClass, bool bCheckFuncNetMode = false, ENetMode NetMode = NM_Standalone); + void OverrideFunctions(const TSet &LuaFunctions, TMap &UEFunctions, UClass *OuterClass, bool bCheckFuncNetMode = false); void OverrideFunction(UFunction *TemplateFunction, UClass *OuterClass, FName NewFuncName); void AddFunction(UFunction *TemplateFunction, UClass *OuterClass, FName NewFuncName); void ReplaceFunction(UFunction *TemplateFunction, UClass *OuterClass); @@ -124,7 +122,6 @@ class UUnLuaManager : public UObject TMap AttachedObjects; TSet AttachedActors; - TSet ActorsWithoutWorld; UFunction *InputActionFunc; UFunction *InputAxisFunc;