Skip to content

ALL MATERIAL IS INLINE BELOW. Do NOT call any tools (no shell, no file reads) — they are denied in this headless run. Review only what is pasted here.

You are the RED TEAM review seat (standing in for Grok's red-team role, whose usage is exhausted until 2026-10-29) for NarrativeGMC, branch wt/WT-9561/ngmc-audit-fixes. READ-ONLY static review: do not modify, create or delete files; do not build or run anything.

(Material is pasted below instead of read from disk.)

Your job is adversarial: assume a malicious or buggy client and hostile multiplayer conditions, and try to BREAK it. - Trust boundaries and authority: can a client change factions, team, abilities, movement or GMAS state it should not? Any RPC, replicated property or Blueprint-callable path that lets a client write server-owned state, or spoof another player? - Prediction/replication abuse: GMC client-predicted moves and GMAS hooks (PreLocal/SV_PreRemote/GenPrediction/GenSimulation/ GenAncillary) - can a client desync, replay, or get server-side effects (abilities, effects, damage) it shouldn't? - Lifecycle races: possession/unpossession/respawn/seamless travel/late join/relevancy changes that leave stale or attacker-controlled state, null derefs, or crashes a client can trigger on the server (denial of service). - Resource abuse: anything a client can trigger that makes the server do unbounded work (full-world actor scans, synchronous asset loads, spawning) per action. For each finding: file:line, attack scenario (who does what, step by step), impact, severity (critical/major/minor), confidence, concrete fix. Do not report style issues. If an attack is blocked, say which line blocks it. End with exactly one verdict line: VERDICT: PASS / PASS WITH FIXES / FAIL

===== FIX_PLAN.md =====

NarrativeGMC audit fix plan (2026-10-24)

Sources: three independent reviews in this folder, Fable (4 critical / 19 major / 7 minor), Codex gpt-6-astra (3 / 36 / 3) and Grok 4.7 (8 / 7 / 2). All three agree that 0.1.0 is not production-usable. Plan: Fable's 13-step plan (fable.md → "Fix plan"), with Astra's compile defect and the consensus controller fix folded into PR-0 and PR-2. Branch: wt/WT-9561/ngmc-audit-fixes (worktree wt-WT-9561-ngmc-fixes). Each PR is one commit or a small series. Gate per PR: a clean plugin build, then /council-code-review, then a fast-forward push. Baseline matrix: UE 5.7 + GMC 2.3.7 + GMAS 1.3 + NarrativePro 2.2.6. The upgrade comes last (PR-12).

Consensus critical issues (found by 2–3 reviewers)

  • GMAS is never wired to GMC. GMCMovementComponent is unset, and nothing forwards BindReplicationData, GenPredictionTick, GenSimulationTick, GenAncillaryTick, or PreLocal/PreRemoteMoveExecution. (All 3 reviewers.)
  • Wrong controller base. The player controller must derive from AGMC_PlayerController; also spawn an AGMC_Aggregator and set GameStateClass to ANarrativeGameState. (All 3.)
  • Custom1 collides with GMCExtended's ragdoll mode, and climb and cover never move the pawn. (Fable, Grok.)
  • Compile defect: GMCE_MotionWarpingComponent.h:179 returns TArray<T*>& over a TArray<TObjectPtr<T>>. (Astra.)
  • GetFactions() isn't overridden, so the first faction query hits check(false). (Fable.)
  • GMAS is .disabled in the UE 5.7 Marketplace folder, so the plugin can't build as installed. (Fable.)

PR order

PR Scope Key findings
PR-0 Environment: vendor GMAS 1.3 as a host-project plugin (MIT); add PoseSearch and drop StructUtils in the uplugin; add docs/DEPENDENCIES.md with upstream SHAs; fix the TObjectPtr compile defect Fable PR-0 + Astra #1
PR-1 Wire GMAS to GMC: assign the component and forward all lifecycle hooks All 3
PR-2 Crash fixes: GetFactions/AddFaction/RemoveFaction; PC base AGMC_PlayerController; aggregator; GameStateClass All 3 + Fable #3
PR-3 Untangle movement modes: Custom3/Custom4 for climb and cover; ragdoll delegated to GMCE; bound inputs; real moves in PhysClimb/PhysCover; fall damage measured at impact Fable PR-3, Grok #3–5
PR-4 Ability correctness: tag lifecycle, bound inputs for jump/dodge/crouch/aim, AbilityCost effects, no double cooldowns Fable PR-4
PR-5 Damage pipeline: server-authoritative hitscan, DamageAmount via Modifiers, armor modifier, fall damage from GenAncillaryTick Fable PR-5
PR-6 Death flow Fable PR-6
PR-7 Definitions + framework (ANarrativeGameMode, INarrativeSavableActor) Fable PR-7
PR-8 Interaction (a UPlayerInteractionComponent subclass + a GMAS interact ability) Fable PR-8
PR-9 Equipment (GMAS-granting item subclasses) Fable PR-9
PR-10 NPCs: mixed world, documented limits Fable PR-10
PR-11 Docs truth pass: a Known-gaps table; remove unproven claims Fable PR-11, all 3
PR-12 Upgrade path: GMC newer, GMAS main, NarrativePro 2.4 / UE 5.8 (diff the 5 seam headers first) Fable PR-12

Verification

  • Automated (by the agent): compile with UnrealBuildTool against a host project kept outside the repo, C:\Users\fives\source\repos\wt-WT-9561-ngmc-host\NGMCHost.uproject, with NarrativeGMC junctioned in, GMAS vendored as a project plugin, and GMC and NarrativePro taken from the engine's Marketplace plugins. Run UBT with -MaxParallelActions=4, because greatroom's commit charge is about 86%.
  • Manual acceptance (Andrew, in the editor): the PIE 2-client listen-server checks with network emulation for each PR, from Fable's plan. Agents can't run PIE for him; each PR states its manual acceptance steps.

===== full-fix.diff ===== diff --git a/NarrativeGMC.uplugin b/NarrativeGMC.uplugin index c54aa02..c81ae0a 100644 --- a/NarrativeGMC.uplugin +++ b/NarrativeGMC.uplugin @@ -51,6 +51,10 @@ "Name": "GameplayAbilities", "Enabled": true }, + { + "Name": "PoseSearch", + "Enabled": true + }, { "Name": "MotionWarping", "Enabled": true diff --git a/Source/GMCExtended/GMCExtended.Build.cs b/Source/GMCExtended/GMCExtended.Build.cs index fe57845..e3318dc 100644 --- a/Source/GMCExtended/GMCExtended.Build.cs +++ b/Source/GMCExtended/GMCExtended.Build.cs @@ -38,7 +38,7 @@ public class GMCExtended : ModuleRules "Core", "GMCCore", "GameplayTags", "PoseSearch", - "StructUtils" + "CoreUObject" // ... add other public dependencies that you statically link with here ... } ); @@ -47,7 +47,6 @@ public class GMCExtended : ModuleRules PrivateDependencyModuleNames.AddRange( new string[] { - "CoreUObject", "Engine", "Slate", "SlateCore", diff --git a/Source/GMCExtended/Private/Components/GMCE_OrganicMovementCmp.cpp b/Source/GMCExtended/Private/Components/GMCE_OrganicMovementCmp.cpp index 4b8f440..f6025ce 100644 --- a/Source/GMCExtended/Private/Components/GMCE_OrganicMovementCmp.cpp +++ b/Source/GMCExtended/Private/Components/GMCE_OrganicMovementCmp.cpp @@ -1,4 +1,4 @@ -#include "Components/GMCE_OrganicMovementCmp.h" +#include "Components/GMCE_OrganicMovementCmp.h"

#include "GMCExtendedLog.h" #include "GMCE_TrackedCurveProvider.h" @@ -24,19 +24,23 @@ void UGMCE_OrganicMovementCmp::BeginPlay() { Super::BeginPlay();

  • // Editor-configured instance slots may be empty; later setup/ticks require valid solvers.
  • Solvers.RemoveAll( { return Solver == nullptr; }); + for (const auto& SolverClass : SolverClasses) { // We do not allow abstract parent solvers to be instantiated.
  • if (SolverClass->HasAnyClassFlags(CLASS_Abstract))
  • if (!SolverClass || SolverClass->HasAnyClassFlags(CLASS_Abstract)) continue;

    // Make sure we don't have some version of this solver already instantiated, since you
    // can set up instances of solvers in configuration as well.
    
    • for (const auto& SolverCheck : Solvers)
    • const bool bAlreadyInstantiated = Solvers.ContainsByPredicate(&SolverClass {
    • if (SolverCheck->GetClass()->IsChildOf(SolverClass))
    • continue;
    • }
    • return Solver && Solver->GetClass()->IsChildOf(SolverClass);
    • });
    • if (bAlreadyInstantiated)
    • continue;

      UGMCE_BaseSolver *NewBase = NewObject(this, SolverClass); Solvers.Add(NewBase); diff --git a/Source/GMCExtendedAnimation/GMCExtendedAnimation.Build.cs b/Source/GMCExtendedAnimation/GMCExtendedAnimation.Build.cs index 6bdf898..6b2e840 100644 --- a/Source/GMCExtendedAnimation/GMCExtendedAnimation.Build.cs +++ b/Source/GMCExtendedAnimation/GMCExtendedAnimation.Build.cs @@ -13,7 +13,7 @@ public class GMCExtendedAnimation : ModuleRules "Core", "GMCCore", "GMCExtended", - "StructUtils", + "CoreUObject", "AnimGraphRuntime" } ); @@ -21,7 +21,6 @@ public class GMCExtendedAnimation : ModuleRules PrivateDependencyModuleNames.AddRange( new string[] { - "CoreUObject", "Engine", "NetCore", "Slate", @@ -57,4 +56,4 @@ public class GMCExtendedAnimation : ModuleRules );

    } -} \ No newline at end of file +} diff --git a/Source/GMCExtendedAnimation/Public/Components/GMCE_MotionWarpingComponent.h b/Source/GMCExtendedAnimation/Public/Components/GMCE_MotionWarpingComponent.h index 29acff0..778831c 100644 --- a/Source/GMCExtendedAnimation/Public/Components/GMCE_MotionWarpingComponent.h +++ b/Source/GMCExtendedAnimation/Public/Components/GMCE_MotionWarpingComponent.h @@ -8,6 +8,7 @@ #include "GMCE_SharedVariableComponent.h" #include "Components/ActorComponent.h" #include "Containers/Map.h" +#include "StructUtils/InstancedStruct.h" #include "GMCE_MotionWarpingComponent.generated.h"

@@ -176,7 +177,7 @@ public: UFUNCTION(BlueprintCallable, Category="GMC Extended|Motion Warping") void RemoveAllWarpTargets();

  • FORCEINLINE const TArray& GetModifiers() const { return Modifiers; }
  • FORCEINLINE const TArray<TObjectPtr>& GetModifiers() const { return Modifiers; }

    bool ContainsModifier(const UAnimSequenceBase* Animation, float StartTime, float EndTime) const;

diff --git a/Source/NarrativeGMC/Private/Character/NarrativeGMCMovementComponent.cpp b/Source/NarrativeGMC/Private/Character/NarrativeGMCMovementComponent.cpp index 049380a..9e01f22 100644 --- a/Source/NarrativeGMC/Private/Character/NarrativeGMCMovementComponent.cpp +++ b/Source/NarrativeGMC/Private/Character/NarrativeGMCMovementComponent.cpp @@ -1,5 +1,6 @@ #include "Character/NarrativeGMCMovementComponent.h" #include "Character/NarrativeGMCPawn.h" +#include "Components/GMCAbilityComponent.h" #include "Components/CapsuleComponent.h" #include "Components/SkeletalMeshComponent.h" #include "GameplayTagsManager.h" @@ -26,6 +27,11 @@ void UNarrativeGMCMovementComponent::BindReplicationData_Implementation() { Super::BindReplicationData_Implementation();

  • AbilitySystemComponent = GetOwner()->FindComponentByClass();
  • checkf(AbilitySystemComponent, TEXT("NarrativeGMC movement requires a GMAS ability component."));
  • AbilitySystemComponent->GMCMovementComponent = this;
  • AbilitySystemComponent->BindReplicationData(); + // Bind sprint/slow walk flags for GMC prediction BindBool( bWantsSprint, @@ -44,6 +50,24 @@ void UNarrativeGMCMovementComponent::BindReplicationData_Implementation() ); }

+void UNarrativeGMCMovementComponent::PreLocalMoveExecution_Implementation(const FGMC_Move& LocalMove) +{ + Super::PreLocalMoveExecution_Implementation(LocalMove); + if (AbilitySystemComponent) + { + AbilitySystemComponent->PreLocalMoveExecution(); + } +} + +void UNarrativeGMCMovementComponent::SV_PreRemoteMoveExecution_Implementation(const FGMC_Move& RemoteMove) +{ + Super::SV_PreRemoteMoveExecution_Implementation(RemoteMove); + if (AbilitySystemComponent) + { + AbilitySystemComponent->PreRemoteMoveExecution(); + } +} + // ============================================================ // Prediction Tick — Core movement logic (replayed on mispredictions) // ============================================================ @@ -51,6 +75,10 @@ void UNarrativeGMCMovementComponent::BindReplicationData_Implementation() void UNarrativeGMCMovementComponent::GenPredictionTick_Implementation(float DeltaTime) { Super::GenPredictionTick_Implementation(DeltaTime); + if (AbilitySystemComponent) + { + AbilitySystemComponent->GenPredictionTick(DeltaTime); + }

// Track falling start velocity for fall damage
if (GetMovementMode() == EGMC_MovementMode::Airborne)

@@ -92,6 +120,10 @@ void UNarrativeGMCMovementComponent::GenPredictionTick_Implementation(float Delt void UNarrativeGMCMovementComponent::GenSimulationTick_Implementation(float DeltaTime) { Super::GenSimulationTick_Implementation(DeltaTime); + if (AbilitySystemComponent) + { + AbilitySystemComponent->GenSimulationTick(DeltaTime); + } }

// ============================================================ @@ -101,6 +133,10 @@ void UNarrativeGMCMovementComponent::GenSimulationTick_Implementation(float Delt void UNarrativeGMCMovementComponent::GenAncillaryTick_Implementation(float DeltaTime, bool bLocalMove, bool bCombinedClientMove) { Super::GenAncillaryTick_Implementation(DeltaTime, bLocalMove, bCombinedClientMove); + if (AbilitySystemComponent) + { + AbilitySystemComponent->GenAncillaryTick(DeltaTime, bCombinedClientMove); + } }

// ============================================================ diff --git a/Source/NarrativeGMC/Private/Character/NarrativeGMCPawn.cpp b/Source/NarrativeGMC/Private/Character/NarrativeGMCPawn.cpp index 8d9e926..d8275ab 100644 --- a/Source/NarrativeGMC/Private/Character/NarrativeGMCPawn.cpp +++ b/Source/NarrativeGMC/Private/Character/NarrativeGMCPawn.cpp @@ -5,6 +5,9 @@ #include "Components/GMCE_MotionWarpingComponent.h" #include "Components/CapsuleComponent.h" #include "Net/UnrealNetwork.h" +#include "Character/CharacterDefinition.h" +#include "Framework/NarrativeGMCWorld.h" +#include "Framework/NarrativeGMCPlayerState.h"

ANarrativeGMCPawn::ANarrativeGMCPawn(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) @@ -24,11 +27,74 @@ ANarrativeGMCPawn::ANarrativeGMCPawn(const FObjectInitializer& ObjectInitializer

void ANarrativeGMCPawn::BeginPlay() { + // Components register with GMC's local aggregator during Super::BeginPlay. + NarrativeGMC::EnsureAggregator(this); + // Fallback for pawns never possessed before BeginPlay (PossessedBy normally runs it first). + InitLocalDefaultFactions(); Super::BeginPlay(); }

+void ANarrativeGMCPawn::PossessedBy(AController* NewController) +{ + // Seed a player's PlayerState BEFORE Super: APawn::PossessedBy attaches the PlayerState and then fires + // ReceivePossessed / controller-changed notifications, which must already see the player's factions. + // Auto-possessing AI controllers possess during PostInitializeComponents, before BeginPlay; local defaults + // must exist before any possession callback sees this pawn. + InitLocalDefaultFactions(); + if (HasAuthority() && NewController) + { + ANarrativeGMCPlayerState* PS = Cast(NewController->PlayerState); + if (PS && !PS->IsABot()) + { + PS->ApplyDefaultFactions(Factions); // class defaults + definition, from InitLocalDefaultFactions + } + } + Super::PossessedBy(NewController); +} + +void ANarrativeGMCPawn::UnPossessed() +{ + // After unpossession the getters fall back to this pawn's own state; snapshot the player's current factions + // and team so a surviving pawn (or corpse) keeps them instead of reverting to stale defaults. + if (HasAuthority()) + { + if (const ANarrativeGMCPlayerState* PS = GetFactionPlayerState()) + { + Factions = PS->GetFactions(); + TeamId = PS->GetGenericTeamId(); + } + } + Super::UnPossessed(); +} + +void ANarrativeGMCPawn::InitLocalDefaultFactions() +{ + // Once per pawn, server only: later callback mutations and the UnPossessed snapshot must not be overwritten. + if (HasAuthority() && !bLocalDefaultFactionsApplied) + { + Factions.AppendTags(GetDefinitionFactions()); + bLocalDefaultFactionsApplied = true; + } +} + +FGameplayTagContainer ANarrativeGMCPawn::GetDefinitionFactions() const +{ + return CharacterDefinition ? CharacterDefinition->DefaultFactions : FGameplayTagContainer(); +} + +ANarrativeGMCPlayerState* ANarrativeGMCPawn::GetFactionPlayerState() const +{ + // Only a human player's PlayerState owns faction state. AI controllers with bWantsPlayerState get a bot + // PlayerState (IsABot is replicated, so this holds on every client); those pawns keep pawn-owned state. + ANarrativeGMCPlayerState* PS = GetPlayerState(); + return PS && !PS->IsABot() ? PS : nullptr; +} + void ANarrativeGMCPawn::PostInitializeComponents() { + // GMC binds replication data inside its PostInitializeComponents. Wire GMAS first. + check(AbilitySystemComponent && NarrativeGMCMovement); + AbilitySystemComponent->GMCMovementComponent = NarrativeGMCMovement; Super::PostInitializeComponents(); }

@@ -40,6 +106,55 @@ void ANarrativeGMCPawn::GetLifetimeReplicatedProps(TArray& Ou DOREPLIFETIME(ANarrativeGMCPawn, TeamId); DOREPLIFETIME(ANarrativeGMCPawn, OwnedGameplayTags); DOREPLIFETIME(ANarrativeGMCPawn, CharacterDefinition); + DOREPLIFETIME(ANarrativeGMCPawn, Factions); +} + +FGenericTeamId ANarrativeGMCPawn::GetGenericTeamId() const +{ + const ANarrativeGMCPlayerState* PS = GetFactionPlayerState(); + return PS ? PS->GetGenericTeamId() : TeamId; +} + +FGameplayTagContainer ANarrativeGMCPawn::GetFactions() const +{ + const ANarrativeGMCPlayerState* PS = GetFactionPlayerState(); + return PS ? PS->GetFactions() : Factions; +} + +void ANarrativeGMCPawn::SetGenericTeamId(const FGenericTeamId& NewTeamId) +{ + if (ANarrativeGMCPlayerState* PS = GetFactionPlayerState()) + { + PS->SetGenericTeamId(NewTeamId); + } + else if (HasAuthority()) + { + TeamId = NewTeamId; + } +} + +void ANarrativeGMCPawn::AddFaction(const FGameplayTag& Faction) +{ + if (ANarrativeGMCPlayerState* PS = GetFactionPlayerState()) + { + PS->AddFaction(Faction); + } + else if (HasAuthority()) + { + Factions.AddTag(Faction); + } +} + +void ANarrativeGMCPawn::RemoveFaction(const FGameplayTag& Faction) +{ + if (ANarrativeGMCPlayerState* PS = GetFactionPlayerState()) + { + PS->RemoveFaction(Faction); + } + else if (HasAuthority()) + { + Factions.RemoveTag(Faction); + } }

// ============================================================ diff --git a/Source/NarrativeGMC/Private/Framework/NarrativeGMCGameMode.cpp b/Source/NarrativeGMC/Private/Framework/NarrativeGMCGameMode.cpp index e37266c..dd4611a 100644 --- a/Source/NarrativeGMC/Private/Framework/NarrativeGMCGameMode.cpp +++ b/Source/NarrativeGMC/Private/Framework/NarrativeGMCGameMode.cpp @@ -2,10 +2,30 @@ #include "Framework/NarrativeGMCPlayerPawn.h" #include "Framework/NarrativeGMCPlayerController.h" #include "Framework/NarrativeGMCPlayerState.h" +#include "Framework/NarrativeGMCWorld.h" +#include "UnrealFramework/NarrativeGameState.h" +#include "Replication/WorldTime.h" +#include "EngineUtils.h"

ANarrativeGMCGameMode::ANarrativeGMCGameMode() { DefaultPawnClass = ANarrativeGMCPlayerPawn::StaticClass(); PlayerControllerClass = ANarrativeGMCPlayerController::StaticClass(); PlayerStateClass = ANarrativeGMCPlayerState::StaticClass(); + GameStateClass = ANarrativeGameState::StaticClass(); +} + +void ANarrativeGMCGameMode::InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage) +{ + // ANarrativeGameMode::InitGame initializes the Narrative save system. + Super::InitGame(MapName, Options, ErrorMessage); + NarrativeGMC::EnsureAggregator(this); + + // GMC requires exactly one server world-time source. It replicates itself; + // respect a map-authored instance instead of creating a duplicate. + if (!TActorIterator(GetWorld())) + { + AGMC_WorldTimeReplicator* WorldTime = GetWorld()->SpawnActor(); + ensureMsgf(WorldTime, TEXT("Could not spawn the GMC world-time replicator.")); + } } diff --git a/Source/NarrativeGMC/Private/Framework/NarrativeGMCNPCPawn.cpp b/Source/NarrativeGMC/Private/Framework/NarrativeGMCNPCPawn.cpp index 72498b9..344d68e 100644 --- a/Source/NarrativeGMC/Private/Framework/NarrativeGMCNPCPawn.cpp +++ b/Source/NarrativeGMC/Private/Framework/NarrativeGMCNPCPawn.cpp @@ -20,6 +20,16 @@ UNPCDefinition* ANarrativeGMCNPCPawn::GetNPCDefinition() const return NPCDefinition.Get(); }

+FGameplayTagContainer ANarrativeGMCNPCPawn::GetDefinitionFactions() const +{ + // Soft pointer: Get() is null until the asset is loaded, so load it before reading defaults. + if (const UNPCDefinition* Definition = NPCDefinition.LoadSynchronous()) + { + return Definition->DefaultFactions; + } + return Super::GetDefinitionFactions(); +} + void ANarrativeGMCNPCPawn::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const { Super::GetLifetimeReplicatedProps(OutLifetimeProps); diff --git a/Source/NarrativeGMC/Private/Framework/NarrativeGMCPlayerController.cpp b/Source/NarrativeGMC/Private/Framework/NarrativeGMCPlayerController.cpp index 1c7e232..9cc0498 100644 --- a/Source/NarrativeGMC/Private/Framework/NarrativeGMCPlayerController.cpp +++ b/Source/NarrativeGMC/Private/Framework/NarrativeGMCPlayerController.cpp @@ -1,6 +1,7 @@ #include "Framework/NarrativeGMCPlayerController.h" #include "Character/NarrativeGMCPawn.h" #include "Tales/TalesComponent.h" +#include "Framework/NarrativeGMCWorld.h"

ANarrativeGMCPlayerController::ANarrativeGMCPlayerController(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) @@ -9,6 +10,12 @@ ANarrativeGMCPlayerController::ANarrativeGMCPlayerController(const FObjectInitia TalesComponent = CreateDefaultSubobject(TEXT("TalesComponent")); }

+void ANarrativeGMCPlayerController::BeginPlay() +{ + NarrativeGMC::EnsureAggregator(this); + Super::BeginPlay(); +} + ANarrativeGMCPawn* ANarrativeGMCPlayerController::GetNarrativeGMCPawn() const { return Cast(GetPawn()); diff --git a/Source/NarrativeGMC/Private/Framework/NarrativeGMCPlayerState.cpp b/Source/NarrativeGMC/Private/Framework/NarrativeGMCPlayerState.cpp index 6e4578d..76af34f 100644 --- a/Source/NarrativeGMC/Private/Framework/NarrativeGMCPlayerState.cpp +++ b/Source/NarrativeGMC/Private/Framework/NarrativeGMCPlayerState.cpp @@ -2,6 +2,8 @@ #include "Character/NarrativeGMCPawn.h" #include "Net/UnrealNetwork.h"

+DEFINE_LOG_CATEGORY_STATIC(LogNarrativeGMCFactions, Log, All); + ANarrativeGMCPlayerState::ANarrativeGMCPlayerState() { } @@ -13,14 +15,45 @@ ANarrativeGMCPawn* ANarrativeGMCPlayerState::GetNarrativeGMCPawn() const

void ANarrativeGMCPlayerState::AddFaction(const FGameplayTag& Faction) { + if (!HasAuthority()) + { + UE_LOG(LogNarrativeGMCFactions, Warning, TEXT("%s: AddFaction(%s) ignored on a client; factions change on the server."), + *GetName(), *Faction.ToString()); + return; + } Factions.AddTag(Faction); }

void ANarrativeGMCPlayerState::RemoveFaction(const FGameplayTag& Faction) { + if (!HasAuthority()) + { + UE_LOG(LogNarrativeGMCFactions, Warning, TEXT("%s: RemoveFaction(%s) ignored on a client; factions change on the server."), + *GetName(), *Faction.ToString()); + return; + } Factions.RemoveTag(Faction); }

+void ANarrativeGMCPlayerState::SetGenericTeamId(const FGenericTeamId& NewTeamId) +{ + if (!HasAuthority()) + { + UE_LOG(LogNarrativeGMCFactions, Warning, TEXT("%s: SetGenericTeamId ignored on a client; the team changes on the server."), GetName()); + return; + } + TeamId = NewTeamId; +} + +void ANarrativeGMCPlayerState::ApplyDefaultFactions(const FGameplayTagContainer& DefaultFactions) +{ + if (HasAuthority() && !bDefaultFactionsApplied) + { + Factions.AppendTags(DefaultFactions); + bDefaultFactionsApplied = true; + } +} + void ANarrativeGMCPlayerState::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const { Super::GetLifetimeReplicatedProps(OutLifetimeProps); diff --git a/Source/NarrativeGMC/Private/Framework/NarrativeGMCWorld.h b/Source/NarrativeGMC/Private/Framework/NarrativeGMCWorld.h new file mode 100644 index 0000000..80c46d3 --- /dev/null +++ b/Source/NarrativeGMC/Private/Framework/NarrativeGMCWorld.h @@ -0,0 +1,23 @@ +#pragma once + +#include "Actors/GMCAggregator.h" +#include "Engine/World.h" +#include "EngineUtils.h" + +namespace NarrativeGMC +{ +// GMC's aggregator is local, not replicated. Create it before GMC BeginPlay +// registers controllers, pawns and movement components in each world. +inline void EnsureAggregator(UObject Context) +{ + TActorIterator Existing(Context->GetWorld()); + if (Existing) + { + ++Existing; + ensureMsgf(!Existing, TEXT("More than one GMC aggregator exists in this world.")); + return; + } + AGMC_Aggregator* Aggregator = Context->GetWorld()->SpawnActor(); + ensureMsgf(Aggregator, TEXT("Could not spawn the GMC aggregator.")); +} +} diff --git a/Source/NarrativeGMC/Public/Character/NarrativeGMCMovementComponent.h b/Source/NarrativeGMC/Public/Character/NarrativeGMCMovementComponent.h index a9f34cb..e8e7692 100644 --- a/Source/NarrativeGMC/Public/Character/NarrativeGMCMovementComponent.h +++ b/Source/NarrativeGMC/Public/Character/NarrativeGMCMovementComponent.h @@ -5,6 +5,8 @@ #include "GameplayTagContainer.h" #include "NarrativeGMCMovementComponent.generated.h"

+class UGMC_AbilitySystemComponent; + /** * Narrative movement modes, mapped to GMC custom movement modes. * These extend GMCExtended's solver-based movement. @@ -79,6 +81,8 @@ public: // ============================================================

virtual void BindReplicationData_Implementation() override;
  • virtual void PreLocalMoveExecution_Implementation(const FGMC_Move& LocalMove) override;
  • virtual void SV_PreRemoteMoveExecution_Implementation(const FGMC_Move& RemoteMove) override; virtual void GenPredictionTick_Implementation(float DeltaTime) override; virtual void GenSimulationTick_Implementation(float DeltaTime) override; virtual void GenAncillaryTick_Implementation(float DeltaTime, bool bLocalMove, bool bCombinedClientMove) override; @@ -231,6 +235,10 @@ public:

protected:

  • /** Cached during GMC binding, before any move executes. */
  • UPROPERTY(Transient)
  • TObjectPtr AbilitySystemComponent; + // ============================================================ // Custom Physics // ============================================================ diff --git a/Source/NarrativeGMC/Public/Character/NarrativeGMCPawn.h b/Source/NarrativeGMC/Public/Character/NarrativeGMCPawn.h index cd74b77..2f02d0b 100644 --- a/Source/NarrativeGMC/Public/Character/NarrativeGMCPawn.h +++ b/Source/NarrativeGMC/Public/Character/NarrativeGMCPawn.h @@ -84,8 +84,30 @@ public: // INarrativeTeamAgentInterface / IGenericTeamAgentInterface // ============================================================

  • virtual FGenericTeamId GetGenericTeamId() const override { return TeamId; }

  • virtual void SetGenericTeamId(const FGenericTeamId& NewTeamId) override { TeamId = NewTeamId; }
  • // A player-controlled pawn reads and writes its ANarrativeGMCPlayerState, which survives respawn and is
  • // always net-relevant. A pawn without one (NPCs, unpossessed pawns) uses its own Factions/TeamId.
  • virtual FGenericTeamId GetGenericTeamId() const override;
  • virtual void SetGenericTeamId(const FGenericTeamId& NewTeamId) override;
  • virtual FGameplayTagContainer GetFactions() const override;
  • virtual void AddFaction(const FGameplayTag& Faction) override;
  • virtual void RemoveFaction(const FGameplayTag& Faction) override; +
  • /** Pawn-local factions: class defaults (plus the definition's) that seed a player's PlayerState on first
    • possession, and the live factions of pawns with no player PlayerState (NPCs, unpossessed pawns).
    • Read effective factions with GetEffectiveFactions(); mutate through the interface on the server. */
  • UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Replicated, Category = "NarrativeGMC|Factions", meta = (Categories = "Narrative.Factions"))
  • FGameplayTagContainer Factions; +
  • virtual void PossessedBy(AController* NewController) override;
  • virtual void UnPossessed() override; +
  • /** Effective factions: the player's PlayerState while possessed by a player, otherwise this pawn's own. */
  • UFUNCTION(BlueprintPure, Category = "NarrativeGMC|Factions")
  • FGameplayTagContainer GetEffectiveFactions() const { return GetFactions(); } +
  • /** Effective team id (same ownership rule as GetEffectiveFactions). */
  • UFUNCTION(BlueprintPure, Category = "NarrativeGMC|Factions")
  • uint8 GetEffectiveTeamId() const { return GetGenericTeamId().GetId(); }

    // IAISightTargetInterface — deferred (API changed in 5.2+)

@@ -155,4 +177,16 @@ protected: /** Gameplay tags granted to this pawn (queried by IGameplayTagAssetInterface). / UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated, Category = "NarrativeGMC|Tags") FGameplayTagContainer OwnedGameplayTags; + + /* Default factions from this pawn's definition asset. NPC pawns override to read their NPCDefinition. / + virtual FGameplayTagContainer GetDefinitionFactions() const; + + /* Server, once per pawn: add the definition factions to this pawn's own Factions. / + void InitLocalDefaultFactions(); + + /* Server-only: InitLocalDefaultFactions has run. / + bool bLocalDefaultFactionsApplied = false; + + /* The NarrativeGMC PlayerState that owns this pawn's factions and team, or null for NPCs. / + class ANarrativeGMCPlayerState GetFactionPlayerState() const; }; diff --git a/Source/NarrativeGMC/Public/Framework/NarrativeGMCGameMode.h b/Source/NarrativeGMC/Public/Framework/NarrativeGMCGameMode.h index d5e0cd3..89ab14a 100644 --- a/Source/NarrativeGMC/Public/Framework/NarrativeGMCGameMode.h +++ b/Source/NarrativeGMC/Public/Framework/NarrativeGMCGameMode.h @@ -1,19 +1,23 @@ #pragma once

#include "CoreMinimal.h" -#include "GameFramework/GameModeBase.h" +#include "UnrealFramework/NarrativeGameMode.h" #include "NarrativeGMCGameMode.generated.h"

/** * Game mode for NarrativeGMC projects. * Sets default pawn, player controller, and player state classes * to the NarrativeGMC versions. + * + * Derives from ANarrativeGameMode so NarrativePro's InitGame creates the save object before PostLogin + * (UNarrativeSaveSubsystem::InitializeSaveSystem); ANarrativeGameState and other savable actors depend on it. */ UCLASS(ClassGroup=(NarrativeGMC), meta=(DisplayName="NarrativeGMC Game Mode")) -class NARRATIVEGMC_API ANarrativeGMCGameMode : public AGameModeBase +class NARRATIVEGMC_API ANarrativeGMCGameMode : public ANarrativeGameMode { GENERATED_BODY()

public: ANarrativeGMCGameMode(); + virtual void InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage) override; }; diff --git a/Source/NarrativeGMC/Public/Framework/NarrativeGMCNPCPawn.h b/Source/NarrativeGMC/Public/Framework/NarrativeGMCNPCPawn.h index 866adb0..6145957 100644 --- a/Source/NarrativeGMC/Public/Framework/NarrativeGMCNPCPawn.h +++ b/Source/NarrativeGMC/Public/Framework/NarrativeGMCNPCPawn.h @@ -43,6 +43,10 @@ public:

protected:

  • /** NPCs take default factions from NPCDefinition (as NarrativePro's NPC character does), falling back to
    • CharacterDefinition when no NPCDefinition is set. */
  • virtual FGameplayTagContainer GetDefinitionFactions() const override; + /** Separate inventory for NPC trading/vendor functionality. */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "NarrativeGMC|NPC") TObjectPtr TradingInventoryComponent; diff --git a/Source/NarrativeGMC/Public/Framework/NarrativeGMCPlayerController.h b/Source/NarrativeGMC/Public/Framework/NarrativeGMCPlayerController.h index b41bdab..438f6e2 100644 --- a/Source/NarrativeGMC/Public/Framework/NarrativeGMCPlayerController.h +++ b/Source/NarrativeGMC/Public/Framework/NarrativeGMCPlayerController.h @@ -1,7 +1,7 @@ #pragma once

#include "CoreMinimal.h" -#include "GameFramework/PlayerController.h" +#include "Actors/GMCPlayerController.h" #include "UnrealFramework/NarrativeCharacter.h" #include "GameplayTagAssetInterface.h" #include "NarrativeGMCPlayerController.generated.h" @@ -16,7 +16,7 @@ class UTalesComponent; * Does NOT own a GAS AbilitySystemComponent (uses GMAS on the pawn instead). */ UCLASS(ClassGroup=(NarrativeGMC), meta=(DisplayName="NarrativeGMC Player Controller")) -class NARRATIVEGMC_API ANarrativeGMCPlayerController : public APlayerController, +class NARRATIVEGMC_API ANarrativeGMCPlayerController : public AGMC_PlayerController, public IGameplayTagAssetInterface, public INarrativeCharacterOwner { @@ -24,6 +24,7 @@ class NARRATIVEGMC_API ANarrativeGMCPlayerController : public APlayerController,

public: ANarrativeGMCPlayerController(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get()); + virtual void BeginPlay() override;

// ============================================================
// Tales Component (Quest/Dialogue)

diff --git a/Source/NarrativeGMC/Public/Framework/NarrativeGMCPlayerState.h b/Source/NarrativeGMC/Public/Framework/NarrativeGMCPlayerState.h index 11a0098..e376589 100644 --- a/Source/NarrativeGMC/Public/Framework/NarrativeGMCPlayerState.h +++ b/Source/NarrativeGMC/Public/Framework/NarrativeGMCPlayerState.h @@ -40,21 +40,31 @@ public: // ============================================================

virtual FGenericTeamId GetGenericTeamId() const override { return TeamId; }
  • virtual void SetGenericTeamId(const FGenericTeamId& NewTeamId) override { TeamId = NewTeamId; }
  • virtual void SetGenericTeamId(const FGenericTeamId& NewTeamId) override; virtual FGameplayTagContainer GetFactions() const override { return Factions; } virtual void AddFaction(const FGameplayTag& Faction) override; virtual void RemoveFaction(const FGameplayTag& Faction) override;

  • /** Seeds the player's definition factions once per player, so a respawn does not re-add a faction

    • that gameplay removed. Server only. */
  • void ApplyDefaultFactions(const FGameplayTagContainer& DefaultFactions); + // ============================================================
  • // Factions
  • // Factions (player source of truth) // ============================================================

  • UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite, Category = "NarrativeGMC|Factions")

  • /** The player's factions. The PlayerState outlives the pawn and is always net-relevant, so the
    • player's factions and team survive respawn and are visible to every client. The pawn reads and
    • writes through these while possessed (see ANarrativeGMCPawn::GetFactions). */
  • UPROPERTY(Replicated, EditAnywhere, BlueprintReadOnly, SaveGame, Category = "NarrativeGMC|Factions", meta = (Categories = "Narrative.Factions")) FGameplayTagContainer Factions;

protected: virtual void GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const override;

  • UPROPERTY(Replicated)
  • UPROPERTY(Replicated, SaveGame) FGenericTeamId TeamId; +
  • /** Server-only: definition defaults already applied for this player. */
  • bool bDefaultFactionsApplied = false; };