From d5c95ac978d21e087280575f848214053cef61fb Mon Sep 17 00:00:00 2001 From: Milxnor Date: Sun, 7 May 2023 23:42:23 -0400 Subject: [PATCH] some ai stuff might have completely broke ai but idk --- Project Reboot 3.0/Controller.cpp | 6 + Project Reboot 3.0/Controller.h | 13 ++ Project Reboot 3.0/FortGameModeAthena.cpp | 3 + Project Reboot 3.0/PlayerController.cpp | 6 - Project Reboot 3.0/PlayerController.h | 25 ---- .../Project Reboot 3.0.vcxproj.filters | 99 ++++++++------- Project Reboot 3.0/UObjectGlobals.h | 7 + Project Reboot 3.0/ai.h | 57 ++++++++- Project Reboot 3.0/bots.h | 120 ++++++++++++------ 9 files changed, 217 insertions(+), 119 deletions(-) diff --git a/Project Reboot 3.0/Controller.cpp b/Project Reboot 3.0/Controller.cpp index 2162ff6..7eedeab 100644 --- a/Project Reboot 3.0/Controller.cpp +++ b/Project Reboot 3.0/Controller.cpp @@ -8,4 +8,10 @@ AActor* AController::GetViewTarget() AActor* ViewTarget = nullptr; this->ProcessEvent(GetViewTargetFn, &ViewTarget); return ViewTarget; +} + +void AController::Possess(class APawn* Pawn) +{ + auto PossessFn = FindFunction("Possess"); + this->ProcessEvent(PossessFn, &Pawn); } \ No newline at end of file diff --git a/Project Reboot 3.0/Controller.h b/Project Reboot 3.0/Controller.h index 8cab45b..5dd5bec 100644 --- a/Project Reboot 3.0/Controller.h +++ b/Project Reboot 3.0/Controller.h @@ -6,4 +6,17 @@ class AController : public AActor { public: AActor* GetViewTarget(); + void Possess(class APawn* Pawn); + + class APawn*& GetPawn() + { + static auto PawnOffset = this->GetOffset("Pawn"); + return this->Get(PawnOffset); + } + + class APlayerState*& GetPlayerState() + { + static auto PlayerStateOffset = this->GetOffset("PlayerState"); + return this->Get(PlayerStateOffset); + } }; \ No newline at end of file diff --git a/Project Reboot 3.0/FortGameModeAthena.cpp b/Project Reboot 3.0/FortGameModeAthena.cpp index 4e42aad..a9779bd 100644 --- a/Project Reboot 3.0/FortGameModeAthena.cpp +++ b/Project Reboot 3.0/FortGameModeAthena.cpp @@ -554,6 +554,9 @@ bool AFortGameModeAthena::Athena_ReadyToStartMatchHook(AFortGameModeAthena* Game GetWorld()->Listen(); + SetupAIDirector(); + SetupServerBotManager(); + if (AmountOfBotsToSpawn != 0) { Bots::SpawnBotsAtPlayerStarts(AmountOfBotsToSpawn); diff --git a/Project Reboot 3.0/PlayerController.cpp b/Project Reboot 3.0/PlayerController.cpp index ac77738..2b88e7f 100644 --- a/Project Reboot 3.0/PlayerController.cpp +++ b/Project Reboot 3.0/PlayerController.cpp @@ -23,12 +23,6 @@ FRotator APlayerController::GetControlRotation() return rot; } -void APlayerController::Possess(class APawn* Pawn) -{ - static auto fn = FindObject(L"/Script/Engine.Controller.Possess"); - this->ProcessEvent(fn, &Pawn); -} - void APlayerController::ServerRestartPlayer() { static auto fn = FindObject(L"/Script/Engine.PlayerController.ServerRestartPlayer"); diff --git a/Project Reboot 3.0/PlayerController.h b/Project Reboot 3.0/PlayerController.h index 5ba9913..c709417 100644 --- a/Project Reboot 3.0/PlayerController.h +++ b/Project Reboot 3.0/PlayerController.h @@ -10,30 +10,6 @@ class APlayerController : public AController { public: - /* void Possess(APawn* Pawn) - { - static auto Possess = FindObject("/Script/Engine.Controller.Possess"); - this->ProcessEvent(Possess, &Pawn); - } - - static inline void ServerAcknowledgePossessionHook(APlayerController* PlayerController, APawn* P) - { - static auto AcknowledgedPawnOffset = PlayerController->GetOffset("AcknowledgedPawn"); - PlayerController->Get(AcknowledgedPawnOffset) = P; - } */ - - class APlayerState*& GetPlayerState() - { - static auto PlayerStateOffset = this->GetOffset("PlayerState"); - return this->Get(PlayerStateOffset); - } - - class APawn*& GetPawn() - { - static auto PawnOffset = this->GetOffset("Pawn"); - return this->Get(PawnOffset); - } - UCheatManager*& GetCheatManager() { static auto CheatManagerOffset = this->GetOffset("CheatManager"); @@ -43,7 +19,6 @@ public: void ServerChangeName(FString& S); UCheatManager*& SpawnCheatManager(UClass* CheatManagerClass); FRotator GetControlRotation(); - void Possess(class APawn* Pawn); void ServerRestartPlayer(); static UClass* StaticClass(); diff --git a/Project Reboot 3.0/Project Reboot 3.0.vcxproj.filters b/Project Reboot 3.0/Project Reboot 3.0.vcxproj.filters index dcdc61a..cd76b6c 100644 --- a/Project Reboot 3.0/Project Reboot 3.0.vcxproj.filters +++ b/Project Reboot 3.0/Project Reboot 3.0.vcxproj.filters @@ -232,15 +232,6 @@ FortniteGame\Source\FortniteGame\Private - - FortniteGame\Source\FortniteGame\Private\Mutators - - - FortniteGame\Source\FortniteGame\Private\Mutators - - - FortniteGame\Source\FortniteGame\Private\Mutators - Engine\Source\Runtime\Core\Private\GenericPlatform @@ -268,6 +259,15 @@ FortniteGame\Source\FortniteGame\Private\Items + + FortniteGame\Source\FortniteGame\Private\Athena\Modifiers + + + FortniteGame\Source\FortniteGame\Private\Athena\Modifiers + + + FortniteGame\Source\FortniteGame\Private\Athena\Modifiers + @@ -745,39 +745,12 @@ FortniteGame\Source\FortniteGame\Public - - FortniteGame\Source\FortniteGame\Public\Mutators - - - FortniteGame\Source\FortniteGame\Public\Mutators - - - FortniteGame\Source\FortniteGame\Public\Mutators - - - FortniteGame\Source\FortniteGame\Public\Mutators - - - FortniteGame\Source\FortniteGame\Public\Mutators - - - FortniteGame\Source\FortniteGame\Public\Mutators - - - FortniteGame\Source\FortniteGame\Public\Mutators - - - FortniteGame\Source\FortniteGame\Public\Mutators - FortniteGame\Source\FortniteGame\Public\Building\GameplayActors\Barrier FortniteGame\Source\FortniteGame\Public\Building\GameplayActors\Barrier - - FortniteGame\Source\FortniteGame\Public\Mutators - FortniteGame\Source\FortniteGame\Public\Building\GameplayActors\Barrier @@ -826,12 +799,6 @@ FortniteGame\Source\FortniteGame\Public\Athena\Vehicle - - FortniteGame\Source\FortniteGame\Public\Mutators - - - FortniteGame\Source\FortniteGame\Public\Mutators - FortniteGame\Source\FortniteGame\Public\Building @@ -854,6 +821,39 @@ Reboot\Public + + FortniteGame\Source\FortniteGame\Public\Athena + + + FortniteGame\Source\FortniteGame\Public\Athena\Modifiers + + + FortniteGame\Source\FortniteGame\Public\Athena\Modifiers + + + FortniteGame\Source\FortniteGame\Public\Athena\Modifiers + + + FortniteGame\Source\FortniteGame\Public\Athena\Modifiers + + + FortniteGame\Source\FortniteGame\Public\Athena\Modifiers + + + FortniteGame\Source\FortniteGame\Public\Athena\Modifiers + + + FortniteGame\Source\FortniteGame\Public\Athena\Modifiers + + + FortniteGame\Source\FortniteGame\Public\Athena\Modifiers + + + FortniteGame\Source\FortniteGame\Public\Athena\Modifiers + + + FortniteGame\Source\FortniteGame\Public\Athena\Modifiers + @@ -1066,12 +1066,6 @@ {b1cc2ad4-6196-455c-bda7-d0a2e7be2e70} - - {bfeeff9b-a86e-47a9-973c-47f6d0dfe5d5} - - - {6efc7bff-2d7b-4fdb-bae8-3d2e736cc82e} - {a633ca3f-f699-4c92-8522-e49a14157b95} @@ -1090,6 +1084,15 @@ {52d438db-beaf-44be-bddd-9aeb07c2459f} + + {39656a6c-bfe1-4521-8652-aea0146564d6} + + + {411d5144-2703-4a96-a7b0-9f2a81abdead} + + + {ade44d65-f7a4-4fc9-ac38-637c84493b58} + diff --git a/Project Reboot 3.0/UObjectGlobals.h b/Project Reboot 3.0/UObjectGlobals.h index 442a533..88ad455 100644 --- a/Project Reboot 3.0/UObjectGlobals.h +++ b/Project Reboot 3.0/UObjectGlobals.h @@ -1,6 +1,7 @@ #pragma once #include "Object.h" +#include "Package.h" #define ANY_PACKAGE (UObject*)-1 @@ -11,4 +12,10 @@ static inline T* StaticFindObject(UClass* Class, UObject* InOuter, const TCHAR* { // LOG_INFO(LogDev, "StaticFindObjectOriginal: {}", __int64(StaticFindObjectOriginal)); return (T*)StaticFindObjectOriginal(Class, InOuter, Name, ExactClass); +} + +static inline UPackage* GetTransientPackage() +{ + static auto TransientPackage = StaticFindObject(nullptr, nullptr, L"/Engine/Transient"); + return TransientPackage; } \ No newline at end of file diff --git a/Project Reboot 3.0/ai.h b/Project Reboot 3.0/ai.h index 3b9d33a..a8ec7a3 100644 --- a/Project Reboot 3.0/ai.h +++ b/Project Reboot 3.0/ai.h @@ -6,7 +6,10 @@ #include "KismetStringLibrary.h" #include "GameplayStatics.h" #include "FortPlayerPawn.h" +#include "FortAthenaMutator.h" #include "FortPlayerController.h" +#include "FortGameModeAthena.h" +#include "FortGameStateAthena.h" #include "FortPlayerControllerAthena.h" using UNavigationSystemV1 = UObject; @@ -68,7 +71,57 @@ static void SetNavigationSystem(AAthenaNavSystemConfigOverride* NavSystemOverrid AddNavigationSystemToWorldOriginal(*GetWorld(), EFNavigationSystemRunMode::GameMode, NavSystemOverride->Get("NavigationSystemConfig"), true, false); } -static void SetupNavConfig() +static void SetupServerBotManager() +{ + auto GameState = Cast(GetWorld()->GetGameState()); + auto GameMode = Cast(GetWorld()->GetGameMode()); + + static auto FortServerBotManagerClass = FindObject("/Script/FortniteGame.FortServerBotManagerAthena"); // Is there a BP for this? // GameMode->ServerBotManagerClass + + if (!FortServerBotManagerClass) + return; + + static auto ServerBotManagerOffset = GameMode->GetOffset("ServerBotManager"); + UObject*& ServerBotManager = GameMode->Get(ServerBotManagerOffset); + + if (!ServerBotManager) + ServerBotManager = UGameplayStatics::SpawnObject(FortServerBotManagerClass, GetTransientPackage()); + + if (ServerBotManager) + { + static auto CachedGameModeOffset = ServerBotManager->GetOffset("CachedGameMode"); + ServerBotManager->Get(CachedGameModeOffset) = GameMode; + + static auto CachedGameStateOffset = ServerBotManager->GetOffset("CachedGameState"); + ServerBotManager->Get(CachedGameStateOffset) = GameState; + + static auto CachedBotMutatorOffset = ServerBotManager->GetOffset("CachedBotMutator"); + ServerBotManager->Get(CachedBotMutatorOffset) = FindFirstMutator(FindObject("/Script/FortniteGame.FortAthenaMutator_Bots")); + } +} + +static void SetupAIDirector() +{ + auto GameState = Cast(GetWorld()->GetGameState()); + auto GameMode = Cast(GetWorld()->GetGameMode()); + + static auto AIDirectorClass = FindObject("/Script/FortniteGame.AthenaAIDirector"); // Probably wrong class + + if (!AIDirectorClass) + return; + + static auto AIDirectorOffset = GameMode->GetOffset("AIDirector"); + + if (!GameMode->Get(AIDirectorOffset)) + GameMode->Get(AIDirectorOffset) = GetWorld()->SpawnActor(AIDirectorClass); + + if (GameMode->Get(AIDirectorOffset)) + { + + } +} + +static void SetupNavConfig(const FName& AgentName) { static auto AthenaNavSystemConfigOverrideClass = FindObject("/Script/FortniteGame.AthenaNavSystemConfigOverride"); auto NavSystemOverride = GetWorld()->SpawnActor(AthenaNavSystemConfigOverrideClass); @@ -85,7 +138,7 @@ static void SetupNavConfig() AthenaNavConfig->Get("bAutoSpawnMissingNavData") = true; // BITFIELD AthenaNavConfig->Get("bSpawnNavDataInNavBoundsLevel") = true; // BITFIELD AthenaNavConfig->Get("bUseNavigationInvokers") = false; - AthenaNavConfig->Get("DefaultAgentName") = UKismetStringLibrary::Conv_StringToName(L"Galileo"); + AthenaNavConfig->Get("DefaultAgentName") = AgentName; // NavSystemOverride->Get("OverridePolicy") = ENavSystemOverridePolicy::Append; NavSystemOverride->Get("NavigationSystemConfig") = AthenaNavConfig; diff --git a/Project Reboot 3.0/bots.h b/Project Reboot 3.0/bots.h index 8a0c16b..e36d517 100644 --- a/Project Reboot 3.0/bots.h +++ b/Project Reboot 3.0/bots.h @@ -7,22 +7,30 @@ class PlayerBot { public: - AFortPlayerControllerAthena* PlayerController = nullptr; + AController* Controller = nullptr; float NextJumpTime = 1.0f; - void Initialize(FTransform SpawnTransform) + void Initialize(const FTransform& SpawnTransform) { auto GameState = Cast(GetWorld()->GetGameState()); auto GameMode = Cast(GetWorld()->GetGameMode()); +#if 0 static auto PawnClass = FindObject("/Game/Athena/PlayerPawn_Athena.PlayerPawn_Athena_C"); + static auto ControllerClass = AFortPlayerControllerAthena::StaticClass(); +#else + static auto PawnClass = FindObject("/Game/Athena/AI/Phoebe/BP_PlayerPawn_Athena_Phoebe.BP_PlayerPawn_Athena_Phoebe_C"); + static auto ControllerClass = FindObject("/Game/Athena/AI/Phoebe/BP_PhoebePlayerController.BP_PhoebePlayerController_C"); +#endif + + static auto FortAthenaAIBotControllerClass = FindObject("/Script/FortniteGame.FortAthenaAIBotController"); FActorSpawnParameters PawnSpawnParameters{}; PawnSpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn; - PlayerController = GetWorld()->SpawnActor(AFortPlayerControllerAthena::StaticClass()); + Controller = GetWorld()->SpawnActor(ControllerClass); AFortPlayerPawnAthena* Pawn = GetWorld()->SpawnActor(PawnClass, SpawnTransform, PawnSpawnParameters); - AFortPlayerStateAthena* PlayerState = Cast(PlayerController->GetPlayerState()); + AFortPlayerStateAthena* PlayerState = Cast(Controller->GetPlayerState()); if (!Pawn || !PlayerState) return; @@ -33,10 +41,12 @@ public: FString NewName = (L"RebootBot" + BotNumWStr).c_str(); - PlayerController->ServerChangeName(NewName); + if (auto PlayerController = Cast(Controller)) + PlayerController->ServerChangeName(NewName); + PlayerState->OnRep_PlayerName(); - PlayerState->GetTeamIndex() = GameMode->Athena_PickTeamHook(GameMode, 0, PlayerController); + PlayerState->GetTeamIndex() = GameMode->Athena_PickTeamHook(GameMode, 0, Controller); static auto SquadIdOffset = PlayerState->GetOffset("SquadId", false); @@ -70,51 +80,84 @@ public: */ - PlayerController->Possess(Pawn); + Controller->Possess(Pawn); Pawn->SetHealth(100); Pawn->SetMaxHealth(100); - FActorSpawnParameters WorldInventorySpawnParameters{}; - WorldInventorySpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; - WorldInventorySpawnParameters.Owner = PlayerController; + AFortInventory** Inventory = nullptr; - FTransform WorldInventorySpawnTransform{}; - - static auto FortInventoryClass = FindObject("/Script/FortniteGame.FortInventory"); // AFortInventory::StaticClass() - PlayerController->GetWorldInventory() = GetWorld()->SpawnActor(FortInventoryClass, WorldInventorySpawnTransform, WorldInventorySpawnParameters); - - if (!PlayerController->GetWorldInventory()) + if (auto FortPlayerController = Cast(Controller)) { - LOG_ERROR(LogBots, "Failed to spawn WorldInventory!"); + Inventory = &FortPlayerController->GetWorldInventory(); + } + else + { + if (Controller->IsA(FortAthenaAIBotControllerClass)) + { + static auto InventoryOffset = Controller->GetOffset("Inventory"); + Inventory = Controller->GetPtr(InventoryOffset); + } + } + + if (!Inventory) + { + LOG_ERROR(LogBots, "No inventory pointer!"); Pawn->K2_DestroyActor(); - PlayerController->K2_DestroyActor(); + Controller->K2_DestroyActor(); return; } - PlayerController->GetWorldInventory()->GetInventoryType() = EFortInventoryType::World; + FActorSpawnParameters InventorySpawnParameters{}; + InventorySpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; + InventorySpawnParameters.Owner = Controller; - static auto bHasInitializedWorldInventoryOffset = PlayerController->GetOffset("bHasInitializedWorldInventory"); - PlayerController->Get(bHasInitializedWorldInventoryOffset) = true; + FTransform InventorySpawnTransform{}; - auto& StartingItems = GameMode->GetStartingItems(); + static auto FortInventoryClass = FindObject("/Script/FortniteGame.FortInventory"); // AFortInventory::StaticClass() + *Inventory = GetWorld()->SpawnActor(FortInventoryClass, InventorySpawnTransform, InventorySpawnParameters); - auto PickaxeInstance = PlayerController->AddPickaxeToInventory(); - - for (int i = 0; i < StartingItems.Num(); i++) + if (!*Inventory) { - auto& StartingItem = StartingItems.at(i); + LOG_ERROR(LogBots, "Failed to spawn Inventory!"); - PlayerController->GetWorldInventory()->AddItem(StartingItem.GetItem(), nullptr, StartingItem.GetCount()); + Pawn->K2_DestroyActor(); + Controller->K2_DestroyActor(); + return; } - if (PickaxeInstance) + (*Inventory)->GetInventoryType() = EFortInventoryType::World; + + if (auto FortPlayerController = Cast(Controller)) { - PlayerController->ServerExecuteInventoryItemHook(PlayerController, PickaxeInstance->GetItemEntry()->GetItemGuid()); + static auto bHasInitializedWorldInventoryOffset = FortPlayerController->GetOffset("bHasInitializedWorldInventory"); + FortPlayerController->Get(bHasInitializedWorldInventoryOffset) = true; } - PlayerController->GetWorldInventory()->Update(); + if (false) + { + if (Inventory) + { + auto& StartingItems = GameMode->GetStartingItems(); + + UFortItem* PickaxeInstance = nullptr; // PlayerController->AddPickaxeToInventory(); + + for (int i = 0; i < StartingItems.Num(); i++) + { + auto& StartingItem = StartingItems.at(i); + + (*Inventory)->AddItem(StartingItem.GetItem(), nullptr, StartingItem.GetCount()); + } + + if (PickaxeInstance) + { + // PlayerController->ServerExecuteInventoryItemHook(PlayerController, PickaxeInstance->GetItemEntry()->GetItemGuid()); + } + + (*Inventory)->Update(); + } + } /* static auto HeroType = FindObject(L"/Game/Athena/Heroes/HID_115_Athena_Commando_M_CarbideBlue.HID_115_Athena_Commando_M_CarbideBlue"); @@ -131,15 +174,16 @@ public: PlayerAbilitySet->GiveToAbilitySystem(AbilitySystemComponent); } - PlayerController->GetCosmeticLoadout()->GetCharacter() = FindObject("/Game/Athena/Items/Cosmetics/Characters/CID_263_Athena_Commando_F_MadCommander.CID_263_Athena_Commando_F_MadCommander"); - Pawn->GetCosmeticLoadout()->GetCharacter() = PlayerController->GetCosmeticLoadout()->GetCharacter(); + // PlayerController->GetCosmeticLoadout()->GetCharacter() = FindObject("/Game/Athena/Items/Cosmetics/Characters/CID_263_Athena_Commando_F_MadCommander.CID_263_Athena_Commando_F_MadCommander"); + // Pawn->GetCosmeticLoadout()->GetCharacter() = PlayerController->GetCosmeticLoadout()->GetCharacter(); - PlayerController->ApplyCosmeticLoadout(); + // PlayerController->ApplyCosmeticLoadout(); GameState->GetPlayersLeft()++; GameState->OnRep_PlayersLeft(); - GameMode->GetAlivePlayers().Add(PlayerController); + if (auto FortPlayerControllerAthena = Cast(Controller)) + GameMode->GetAlivePlayers().Add(FortPlayerControllerAthena); } }; @@ -147,12 +191,12 @@ static std::vector AllPlayerBotsToTick; namespace Bots { - static AFortPlayerControllerAthena* SpawnBot(FTransform SpawnTransform) + static AController* SpawnBot(FTransform SpawnTransform) { auto playerBot = PlayerBot(); playerBot.Initialize(SpawnTransform); AllPlayerBotsToTick.push_back(playerBot); - return playerBot.PlayerController; + return playerBot.Controller; } static void SpawnBotsAtPlayerStarts(int AmountOfBots) @@ -195,12 +239,12 @@ namespace Bots // for (int i = 0; i < GameMode->GetAlivePlayers().Num(); i++) for (auto& PlayerBot : AllPlayerBotsToTick) { - auto CurrentPlayer = PlayerBot.PlayerController; + auto CurrentPlayer = PlayerBot.Controller; if (CurrentPlayer->IsActorBeingDestroyed()) continue; - auto CurrentPawn = CurrentPlayer->GetMyFortPawn(); + auto CurrentPawn = CurrentPlayer->GetPawn(); auto CurrentPlayerState = Cast(CurrentPlayer->GetPlayerState());