s20-s23 much better

This commit is contained in:
Gray
2025-07-18 02:49:40 -04:00
parent d769fbc1b2
commit 8f0ce8919e
12 changed files with 229 additions and 52 deletions

View File

@@ -339,7 +339,7 @@ void UNetDriver::ServerReplicateActors_BuildConsiderList(std::vector<FNetworkObj
}
}
static UActorChannel* FindChannel(AActor * Actor, UNetConnection * Connection)
static UActorChannel* FindChannel(AActor* Actor, UNetConnection* Connection)
{
static auto OpenChannelsOffset = Connection->GetOffset("OpenChannels");
auto& OpenChannels = Connection->Get<TArray<UChannel*>>(OpenChannelsOffset);
@@ -376,20 +376,16 @@ static UActorChannel* FindChannel(AActor * Actor, UNetConnection * Connection)
return nullptr;
}
static bool IsActorRelevantToConnection(AActor * Actor, std::vector<FNetViewer>&ConnectionViewers)
static bool IsActorRelevantToConnection(AActor* Actor, std::vector<FNetViewer>&ConnectionViewers)
{
for (int32 viewerIdx = 0; viewerIdx < ConnectionViewers.size(); viewerIdx++)
for (int32 viewerIdx = 0; viewerIdx < ConnectionViewers.size(); ++viewerIdx)
{
if (!ConnectionViewers[viewerIdx].ViewTarget)
continue;
// static bool (*IsNetRelevantFor)(AActor*, AActor*, AActor*, FVector&) = decltype(IsNetRelevantFor)(__int64(GetModuleHandleW(0)) + 0x1ECC700);
static auto index = Offsets::IsNetRelevantFor;
// if (Actor->IsNetRelevantFor(ConnectionViewers[viewerIdx].InViewer, ConnectionViewers[viewerIdx].ViewTarget, ConnectionViewers[viewerIdx].ViewLocation))
// if (IsNetRelevantFor(Actor, ConnectionViewers[viewerIdx].InViewer, ConnectionViewers[viewerIdx].ViewTarget, ConnectionViewers[viewerIdx].ViewLocation))
if (reinterpret_cast<bool(*)(AActor*, AActor*, AActor*, FVector&)>(Actor->VFTable[index])(
if (reinterpret_cast<bool(*)(AActor*, AActor*, AActor*, const FVector&)>(Actor->VFTable[Offsets::IsNetRelevantFor])(
Actor, ConnectionViewers[viewerIdx].InViewer, ConnectionViewers[viewerIdx].ViewTarget, ConnectionViewers[viewerIdx].ViewLocation))
{
return true;
@@ -556,7 +552,7 @@ void SetChannelActorForDestroy(UActorChannel* Channel, FActorDestructionInfo* De
using UPackageMap = UObject;
reinterpret_cast<bool(*)(UPackageMap*, FArchive * Ar, UObject * InOuter,FNetworkGUID NetGUID, FString ObjName)>(Connection->GetPackageMap()->VFTable[0x238 / 8])(Connection->GetPackageMap(), &CloseBunch, DestructInfo->ObjOuter.Get(), DestructInfo->NetGUID, DestructInfo->PathName);
reinterpret_cast<bool(*)(UPackageMap*, FArchive* Ar, UObject* InOuter, FNetworkGUID NetGUID, FString ObjName)>(Connection->GetPackageMap()->VFTable[0x238 / 8])(Connection->GetPackageMap(), &CloseBunch, DestructInfo->ObjOuter.Get(), DestructInfo->NetGUID, DestructInfo->PathName);
// UE_LOG(LogNetTraffic, Log, TEXT("SetChannelActorForDestroy: Channel %d. NetGUID <%s> Path: %s. Bits: %d"), ChIndex, *DestructInfo->NetGUID.ToString(), *DestructInfo->PathName, CloseBunch.GetNumBits());
// UE_LOG(LogNetDormancy, Verbose, TEXT("SetChannelActorForDestroy: Channel %d. NetGUID <%s> Path: %s. Bits: %d"), ChIndex, *DestructInfo->NetGUID.ToString(), *DestructInfo->PathName, CloseBunch.GetNumBits());
@@ -606,9 +602,11 @@ int32 UNetDriver::ServerReplicateActors()
// bCPUSaturated = DeltaSeconds > 1.2f * ServerTickTime;
}
bool bUseNetworkObjectList = ShouldUseNetworkObjectList();
std::vector<FNetworkObjectInfo*> ConsiderList;
if (ShouldUseNetworkObjectList())
if (bUseNetworkObjectList)
ConsiderList.reserve(GetNetworkObjectList().ActiveNetworkObjects.Num());
auto World = GetWorld();
@@ -619,11 +617,12 @@ int32 UNetDriver::ServerReplicateActors()
static UChannel* (*CreateChannel)(UNetConnection*, int, bool, int32_t) = decltype(CreateChannel)(Addresses::CreateChannel);
static __int64 (*ReplicateActor)(UActorChannel*) = decltype(ReplicateActor)(Addresses::ReplicateActor);
static UObject* (*CreateChannelByName)(UNetConnection * Connection, FName * ChName, EChannelCreateFlags CreateFlags, int32_t ChannelIndex) = decltype(CreateChannelByName)(Addresses::CreateChannel);
static UObject* (*CreateChannelByName)(UNetConnection* Connection, FName* ChName, EChannelCreateFlags CreateFlags, int32_t ChannelIndex) = decltype(CreateChannelByName)(Addresses::CreateChannel);
static __int64 (*SetChannelActor)(UActorChannel*, AActor*) = decltype(SetChannelActor)(Addresses::SetChannelActor);
static __int64 (*SetChannelActor2)(UActorChannel*, AActor*, ESetChannelActorFlags) = decltype(SetChannelActor2)(Addresses::SetChannelActor);
static FName ActorName = UKismetStringLibrary::Conv_StringToName(L"Actor");
for (int32 i = 0; i < this->GetClientConnections().Num(); i++)
for (int32 i = 0; i < this->GetClientConnections().Num(); ++i)
{
UNetConnection* Connection = this->GetClientConnections().at(i);
@@ -694,7 +693,7 @@ int32 UNetDriver::ServerReplicateActors()
for (FActorDestructionInfo* DeletionEntry : DeletionEntries)
{
LOG_INFO(LogDev, "AA: {}", DeletionEntry->PathName.Data.Data ? DeletionEntry->PathName.ToString() : "Null");
LOG_INFO(LogDev, "PathName: {}", DeletionEntry->PathName.Data.Data ? DeletionEntry->PathName.ToString() : "Null");
if (DeletionEntry->StreamingLevelName != -1)
{
@@ -719,9 +718,6 @@ int32 UNetDriver::ServerReplicateActors()
if (Engine_Version >= 422)
{
FString ActorStr = L"Actor";
FName ActorName = UKismetStringLibrary::Conv_StringToName(ActorStr);
int ChannelIndex = -1; // 4294967295
Channel = (UActorChannel*)CreateChannelByName(Connection, &ActorName, EChannelCreateFlags::OpenedLocally, ChannelIndex);
}
@@ -807,7 +803,6 @@ int32 UNetDriver::ServerReplicateActors()
}
}
if (!Channel)
{
if (Actor->IsA(APlayerController::StaticClass()) && Actor != Connection->GetPlayerController()) // isnetrelevantfor should handle this iirc
@@ -817,9 +812,6 @@ int32 UNetDriver::ServerReplicateActors()
{
if (Engine_Version >= 422)
{
FString ActorStr = L"Actor";
FName ActorName = UKismetStringLibrary::Conv_StringToName(ActorStr);
int ChannelIndex = -1; // 4294967295
Channel = (UActorChannel*)CreateChannelByName(Connection, &ActorName, EChannelCreateFlags::OpenedLocally, ChannelIndex);
}
@@ -845,9 +837,10 @@ int32 UNetDriver::ServerReplicateActors()
if (Channel)
{
// LOG_INFO(LogDev, "Actor: {}", Actor->GetFullName());
if (ReplicateActor(Channel))
{
if (ShouldUseNetworkObjectList())
if (bUseNetworkObjectList)
{
// LOG_INFO(LogReplication, "Replicated Actor!");
auto TimeSeconds = UGameplayStatics::GetTimeSeconds(World);
@@ -864,6 +857,14 @@ int32 UNetDriver::ServerReplicateActors()
}
}
if (!bUseNetworkObjectList) // BOOM
{
for (auto info : ConsiderList)
{
delete info;
}
}
// shuffle the list of connections if not all connections were ticked
/*
if (NumClientsToTick < NetDriver->ClientConnections.Num())