#include "FortPlayerControllerAthena.h" #include "FortPlayerPawn.h" #include "FortKismetLibrary.h" #include "SoftObjectPtr.h" #include "globals.h" #include "GameplayStatics.h" #include "hooking.h" void AFortPlayerControllerAthena::ServerRestartPlayerHook(AFortPlayerControllerAthena* Controller) { static auto FortPlayerControllerZoneDefault = FindObject(L"/Script/FortniteGame.Default__FortPlayerControllerZone"); static auto ServerRestartPlayerFn = FindObject(L"/Script/Engine.PlayerController.ServerRestartPlayer"); static auto ZoneServerRestartPlayer = __int64(FortPlayerControllerZoneDefault->VFTable[GetFunctionIdxOrPtr(ServerRestartPlayerFn) / 8]); static void (*ZoneServerRestartPlayerOriginal)(AFortPlayerController*) = decltype(ZoneServerRestartPlayerOriginal)(__int64(ZoneServerRestartPlayer)); LOG_INFO(LogDev, "Call 0x{:x}!", ZoneServerRestartPlayer - __int64(_ReturnAddress())); return ZoneServerRestartPlayerOriginal(Controller); } void AFortPlayerControllerAthena::ServerGiveCreativeItemHook(AFortPlayerControllerAthena* Controller, FFortItemEntry CreativeItem) { // Don't worry, the validate has a check if it is a creative enabled mode or not, but we need to add a volume check. auto CreativeItemPtr = &CreativeItem; auto ItemDefinition = CreativeItemPtr->GetItemDefinition(); if (!ItemDefinition) return; bool bShouldUpdate = false; auto LoadedAmmo = -1; // CreativeItemPtr->GetLoadedAmmo() Controller->GetWorldInventory()->AddItem(ItemDefinition, &bShouldUpdate, CreativeItemPtr->GetCount(), LoadedAmmo, false); if (bShouldUpdate) Controller->GetWorldInventory()->Update(Controller); } void AFortPlayerControllerAthena::ServerTeleportToPlaygroundLobbyIslandHook(AFortPlayerControllerAthena* Controller) { auto Pawn = Controller->GetMyFortPawn(); if (!Pawn) return; static auto FortPlayerStartCreativeClass = FindObject("/Script/FortniteGame.FortPlayerStartCreative"); auto AllCreativePlayerStarts = UGameplayStatics::GetAllActorsOfClass(GetWorld(), FortPlayerStartCreativeClass); for (int i = 0; i < AllCreativePlayerStarts.Num(); i++) { auto CurrentPlayerStart = AllCreativePlayerStarts.at(i); static auto PlayerStartTagsOffset = CurrentPlayerStart->GetOffset("PlayerStartTags"); auto bHasSpawnTag = CurrentPlayerStart->Get(PlayerStartTagsOffset).Contains("Playground.LobbyIsland.Spawn"); if (!bHasSpawnTag) continue; Pawn->TeleportTo(CurrentPlayerStart->GetActorLocation(), Pawn->GetActorRotation()); break; } AllCreativePlayerStarts.Free(); } void AFortPlayerControllerAthena::ServerAcknowledgePossessionHook(APlayerController* Controller, APawn* Pawn) { static auto AcknowledgedPawnOffset = Controller->GetOffset("AcknowledgedPawn"); Controller->Get(AcknowledgedPawnOffset) = Pawn; auto ControllerAsFort = Cast(Controller); auto PawnAsFort = Cast(Pawn); auto PlayerStateAsFort = Cast(Pawn->GetPlayerState()); if (Globals::bNoMCP) return; if (!PawnAsFort) return; static auto UpdatePlayerCustomCharacterPartsVisualizationFn = FindObject("/Script/FortniteGame.FortKismetLibrary.UpdatePlayerCustomCharacterPartsVisualization"); if (!UpdatePlayerCustomCharacterPartsVisualizationFn) { auto CosmeticLoadout = ControllerAsFort->GetCosmeticLoadout(); if (CosmeticLoadout) ApplyCID(PawnAsFort, CosmeticLoadout->GetCharacter()); return; } if (!PlayerStateAsFort) return; UFortKismetLibrary::StaticClass()->ProcessEvent(UpdatePlayerCustomCharacterPartsVisualizationFn, &PlayerStateAsFort); } void AFortPlayerControllerAthena::ServerPlaySquadQuickChatMessage(AFortPlayerControllerAthena* PlayerController, __int64 ChatEntry, __int64 SenderID) { using UAthenaEmojiItemDefinition = UFortItemDefinition; static auto EmojiComm = FindObject("/Game/Athena/Items/Cosmetics/Dances/Emoji/Emoji_Comm.Emoji_Comm"); PlayerController->ServerPlayEmoteItemHook(PlayerController, EmojiComm); } void AFortPlayerControllerAthena::GetPlayerViewPointHook(AFortPlayerControllerAthena* PlayerController, FVector& Location, FRotator& Rotation) { if (auto MyFortPawn = PlayerController->GetMyFortPawn()) { Location = MyFortPawn->GetActorLocation(); Rotation = PlayerController->GetControlRotation(); return; } return AFortPlayerControllerAthena::GetPlayerViewPointOriginal(PlayerController, Location, Rotation); } void AFortPlayerControllerAthena::ServerReadyToStartMatchHook(AFortPlayerControllerAthena* PlayerController) { LOG_INFO(LogDev, "ServerReadyToStartMatch!"); if (Fortnite_Version <= 2.5) // techinally we should do this at the end of OnReadyToStartMatch { static auto QuickBarsOffset = PlayerController->GetOffset("QuickBars", false); if (QuickBarsOffset != -1) { auto& QuickBars = PlayerController->Get(QuickBarsOffset); if (QuickBars) return ServerReadyToStartMatchOriginal(PlayerController); static auto FortQuickBarsClass = FindObject("/Script/FortniteGame.FortQuickBars"); QuickBars = GetWorld()->SpawnActor(FortQuickBarsClass); if (!QuickBars) return ServerReadyToStartMatchOriginal(PlayerController); PlayerController->Get(QuickBarsOffset)->SetOwner(PlayerController); } } return ServerReadyToStartMatchOriginal(PlayerController); }