From fb4cf4f39ac7cf2c6fef88e747ea12d6f4c96411 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 28 Jun 2026 03:08:54 +0100 Subject: [PATCH] Move Eve state-ref resolution out of state reader --- Aetheria.State.Verify/Program.cs | 30 +- .../Runtime/AetheriaRuntimeStateReader.cs | 287 +++++++++++------- .../Runtime/AetheriaRuntimeVerseClient.cs | 7 +- 3 files changed, 216 insertions(+), 108 deletions(-) diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index b24485134..6aea53ea3 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -9283,7 +9283,7 @@ static void RequireAetheriaRuntimeVerseClientContract(string root) "VerseHostSettingsAsync()", "AetheriaRuntimeLoadoutTemplatesDocument", "CreateEveSurfaceStateRefResolver(", - "AetheriaRuntimeStateReader.CreateEveSurfaceCultMeshStateRefResolver(", + "AetheriaRuntimeStateRefResolver.CreateEveSurfaceCultMeshStateRefResolver(", "SubmitDaemonCommandAsync(", "SubmitEveCommandAsync(", "AetheriaRuntimeVerseRecordKeys.DaemonCommand(command.CommandId)", @@ -9316,6 +9316,13 @@ static void RequireAetheriaRuntimeVerseClientContract(string root) string.Join(", ", missingStateReaderSymbols)); } + if (client.Contains("AetheriaRuntimeStateReader.CreateEveSurfaceCultMeshStateRefResolver", StringComparison.Ordinal) || + client.Contains("AetheriaRuntimeStateReader.CreateEveSurfaceStateRefResolver", StringComparison.Ordinal)) + { + throw new InvalidOperationException( + "AetheriaRuntimeVerseClient still routes Eve state-ref resolution through the file-backed compatibility reader."); + } + if (client.Contains("public async Task SubmitDaemonCommandAsync(", StringComparison.Ordinal) || client.Contains("public async Task SubmitEveCommandAsync(", StringComparison.Ordinal)) { @@ -12725,6 +12732,7 @@ static void RequireRuntimeStateReaderOwnsUnityStateAcquisition(string root) var requiredReaderSymbols = new[] { "public static class AetheriaRuntimeStateReader", + "public static class AetheriaRuntimeStateRefResolver", "OpenRuntimeCatalog", "ReadPlayerSettings", "ReadVerseHostSettings", @@ -12756,7 +12764,7 @@ static void RequireRuntimeStateReaderOwnsUnityStateAcquisition(string root) "ResolveSurfaceStateRefs(stateFilePath, surface)", "public static Func CreateEveSurfaceStateRefResolver(string stateFilePath)", "public static CultMeshStateRefResolver CreateEveSurfaceCultMeshStateRefResolver(", - "private static CultMeshStateRefResolver CreateStateRefResolver(string stateFilePath, string runtimeId)", + "AetheriaRuntimeStateRefResolver.CreateEveSurfaceCultMeshStateRefResolver(", "CultMeshStateRefResolver.Empty", "CultMesh.StateRefResolver(", ".AsFunc()", @@ -13203,6 +13211,24 @@ static void RequireRuntimeStateReaderOwnsUnityStateAcquisition(string root) "Unity Eve surface host still resolves default state refs through the file reader instead of the managed runtime client provider."); } + var runtimeVerseClientPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeVerseClient.cs"); + var runtimeVerseClient = File.Exists(runtimeVerseClientPath) + ? File.ReadAllText(runtimeVerseClientPath) + : throw new InvalidOperationException("Cannot verify managed state-ref resolver ownership; AetheriaRuntimeVerseClient.cs is missing."); + + if (!runtimeVerseClient.Contains("AetheriaRuntimeStateRefResolver.CreateEveSurfaceCultMeshStateRefResolver(", StringComparison.Ordinal)) + { + throw new InvalidOperationException( + "Managed Verse client no longer resolves Eve state refs through the typed runtime state-ref resolver."); + } + + if (runtimeVerseClient.Contains("AetheriaRuntimeStateReader.CreateEveSurfaceCultMeshStateRefResolver", StringComparison.Ordinal) || + runtimeVerseClient.Contains("AetheriaRuntimeStateReader.CreateEveSurfaceStateRefResolver", StringComparison.Ordinal)) + { + throw new InvalidOperationException( + "Managed Verse client still routes Eve state-ref resolution through the file-backed compatibility reader."); + } + var forbiddenDirectStoreSymbols = new Dictionary { [actionGameManagerPath] = new[] diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeStateReader.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeStateReader.cs index ef232f458..0f62f96a4 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeStateReader.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeStateReader.cs @@ -118,16 +118,181 @@ namespace GameCult.Aetheria.State.Verse public static string ResolveEveSurfaceStateRef(string stateFilePath, string stateRef) { - return TryResolveEveSurfaceStateRef(stateFilePath, stateRef, out var value) ? value : ""; + return AetheriaRuntimeStateRefResolver.ResolveEveSurfaceStateRef( + stateFilePath, + stateRef, + OpenRuntimeCatalog); } public static bool TryResolveEveSurfaceStateRef(string stateFilePath, string stateRef, out string value) + { + return AetheriaRuntimeStateRefResolver.TryResolveEveSurfaceStateRef( + stateFilePath, + stateRef, + OpenRuntimeCatalog, + out value); + } + + public static bool TryResolveDaemonStateRef( + AetheriaRuntimeDaemonFrameDocument? frame, + AetheriaRuntimeDaemonHealthDocument? health, + AetheriaRuntimeDaemonCommandBoundaryDocument? commandBoundary, + string stateRef, + out string value) + { + return AetheriaRuntimeStateRefResolver.TryResolveDaemonStateRef( + frame, + health, + commandBoundary, + stateRef, + out value); + } + + public static bool TryResolveDaemonItemStatRef( + AetheriaRuntimeDaemonFrameDocument? frame, + AetheriaRuntimeCatalogSnapshot? catalog, + string stateRef, + out string value) + { + return AetheriaRuntimeStateRefResolver.TryResolveDaemonItemStatRef( + frame, + catalog, + stateRef, + out value); + } + + public static bool TryReadDaemonGameSurface( + string stateFilePath, + out EveSurfaceDocument document) + { + if (!AetheriaRuntimeDaemonPublicationStore.TryReadGameSurface(stateFilePath, out var surface)) + { + document = EmptySurface(AetheriaRuntimeDaemonGameSurfaceBuilder.SurfaceId); + return false; + } + + document = ToResolvedEveSurfaceDocument(stateFilePath, surface); + return true; + } + + public static bool TryReadDaemonGameTuiSurface( + string stateFilePath, + out EveSurfaceDocument document) + { + if (!AetheriaRuntimeDaemonPublicationStore.TryReadGameTuiSurface(stateFilePath, out var surface)) + { + document = EmptySurface(AetheriaRuntimeDaemonGameSurfaceBuilder.TuiSurfaceId); + return false; + } + + document = ToResolvedEveSurfaceDocument(stateFilePath, surface); + return true; + } + + public static bool TryReadDaemonEditorSurface( + string stateFilePath, + out EveSurfaceDocument document) + { + if (!AetheriaRuntimeDaemonPublicationStore.TryReadEditorSurface(stateFilePath, out var surface)) + { + document = EmptySurface(AetheriaRuntimeDaemonEditorSurfaceBuilder.SurfaceId); + return false; + } + + document = ToResolvedEveSurfaceDocument(stateFilePath, surface); + return true; + } + + public static bool TryReadDaemonEditorTuiSurface( + string stateFilePath, + out EveSurfaceDocument document) + { + if (!AetheriaRuntimeDaemonPublicationStore.TryReadEditorTuiSurface(stateFilePath, out var surface)) + { + document = EmptySurface(AetheriaRuntimeDaemonEditorSurfaceBuilder.TuiSurfaceId); + return false; + } + + document = ToResolvedEveSurfaceDocument(stateFilePath, surface); + return true; + } + + private static EveSurfaceDocument EmptySurface(string surfaceId) + { + return AetheriaRuntimeEveSurfaceAdapter.EmptySurface(surfaceId); + } + + public static Func CreateEveSurfaceStateRefResolver(string stateFilePath) + { + return CreateEveSurfaceCultMeshStateRefResolver(stateFilePath).AsFunc(); + } + + public static CultMeshStateRefResolver CreateEveSurfaceCultMeshStateRefResolver( + string stateFilePath, + string runtimeId = AetheriaRuntimeVerseClient.DefaultRuntimeId) + { + return AetheriaRuntimeStateRefResolver.CreateEveSurfaceCultMeshStateRefResolver( + stateFilePath, + runtimeId, + OpenRuntimeCatalog); + } + + public static CultMeshStateRefResolver CreateEveSurfaceCultMeshStateRefResolver( + AetheriaRuntimeDaemonFrameDocument? frame, + AetheriaRuntimeDaemonHealthDocument? health, + AetheriaRuntimeDaemonCommandBoundaryDocument? commandBoundary, + Func? catalogProvider = null, + CultMeshRouteHint? routeHint = null) + { + return AetheriaRuntimeStateRefResolver.CreateEveSurfaceCultMeshStateRefResolver( + frame, + health, + commandBoundary, + catalogProvider, + routeHint); + } + + private static EveSurfaceDocument ToResolvedEveSurfaceDocument( + string stateFilePath, + AetheriaRuntimeSurfaceDocument surface) + { + return AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument( + surface, + CreateEveSurfaceStateRefResolver(stateFilePath)); + } + + private static EveSurfaceDocument ResolveSurfaceStateRefs( + string stateFilePath, + EveSurfaceDocument surface) + { + return AetheriaRuntimeEveSurfaceAdapter.ResolveStateRefs( + surface, + CreateEveSurfaceStateRefResolver(stateFilePath)); + } + + } + + public static class AetheriaRuntimeStateRefResolver + { + public static string ResolveEveSurfaceStateRef( + string stateFilePath, + string stateRef, + Func catalogProvider) + { + return TryResolveEveSurfaceStateRef(stateFilePath, stateRef, catalogProvider, out var value) ? value : ""; + } + + public static bool TryResolveEveSurfaceStateRef( + string stateFilePath, + string stateRef, + Func catalogProvider, + out string value) { value = ""; if (string.IsNullOrWhiteSpace(stateRef)) return false; - TryReadDaemonFrame(stateFilePath, out var frame); + AetheriaRuntimeDaemonFrameStore.TryReadFrame(stateFilePath, out var frame); if (stateRef.StartsWith(AetheriaRuntimeDaemonStateRefs.Prefix + "/", StringComparison.Ordinal)) { AetheriaRuntimeDaemonPublicationStore.TryReadHealth(stateFilePath, out var health); @@ -139,7 +304,7 @@ namespace GameCult.Aetheria.State.Verse { return TryResolveDaemonItemStatRef( frame, - OpenRuntimeCatalog(stateFilePath), + catalogProvider(stateFilePath), stateRef, out value); } @@ -264,80 +429,28 @@ namespace GameCult.Aetheria.State.Verse return true; } - public static bool TryReadDaemonGameSurface( - string stateFilePath, - out EveSurfaceDocument document) - { - if (!AetheriaRuntimeDaemonPublicationStore.TryReadGameSurface(stateFilePath, out var surface)) - { - document = EmptySurface(AetheriaRuntimeDaemonGameSurfaceBuilder.SurfaceId); - return false; - } - - document = ToResolvedEveSurfaceDocument(stateFilePath, surface); - return true; - } - - public static bool TryReadDaemonGameTuiSurface( - string stateFilePath, - out EveSurfaceDocument document) - { - if (!AetheriaRuntimeDaemonPublicationStore.TryReadGameTuiSurface(stateFilePath, out var surface)) - { - document = EmptySurface(AetheriaRuntimeDaemonGameSurfaceBuilder.TuiSurfaceId); - return false; - } - - document = ToResolvedEveSurfaceDocument(stateFilePath, surface); - return true; - } - - public static bool TryReadDaemonEditorSurface( - string stateFilePath, - out EveSurfaceDocument document) - { - if (!AetheriaRuntimeDaemonPublicationStore.TryReadEditorSurface(stateFilePath, out var surface)) - { - document = EmptySurface(AetheriaRuntimeDaemonEditorSurfaceBuilder.SurfaceId); - return false; - } - - document = ToResolvedEveSurfaceDocument(stateFilePath, surface); - return true; - } - - public static bool TryReadDaemonEditorTuiSurface( - string stateFilePath, - out EveSurfaceDocument document) - { - if (!AetheriaRuntimeDaemonPublicationStore.TryReadEditorTuiSurface(stateFilePath, out var surface)) - { - document = EmptySurface(AetheriaRuntimeDaemonEditorSurfaceBuilder.TuiSurfaceId); - return false; - } - - document = ToResolvedEveSurfaceDocument(stateFilePath, surface); - return true; - } - - private static EveSurfaceDocument EmptySurface(string surfaceId) - { - return AetheriaRuntimeEveSurfaceAdapter.EmptySurface(surfaceId); - } - - public static Func CreateEveSurfaceStateRefResolver(string stateFilePath) - { - return CreateEveSurfaceCultMeshStateRefResolver(stateFilePath).AsFunc(); - } - public static CultMeshStateRefResolver CreateEveSurfaceCultMeshStateRefResolver( string stateFilePath, - string runtimeId = AetheriaRuntimeVerseClient.DefaultRuntimeId) + string runtimeId, + Func catalogProvider) { if (string.IsNullOrWhiteSpace(stateFilePath)) return CultMeshStateRefResolver.Empty; - return CreateStateRefResolver(stateFilePath, runtimeId); + AetheriaRuntimeDaemonFrameStore.TryReadFrame(stateFilePath, out var frame); + AetheriaRuntimeDaemonPublicationStore.TryReadHealth(stateFilePath, out var health); + AetheriaRuntimeDaemonPublicationStore.TryReadCommandBoundary(stateFilePath, out var commandBoundary); + + return CreateEveSurfaceCultMeshStateRefResolver( + frame, + health, + commandBoundary, + () => catalogProvider(stateFilePath), + new CultMeshRouteHint( + CultMeshLocalityKind.InProcess, + string.IsNullOrWhiteSpace(runtimeId) + ? AetheriaRuntimeVerseClient.DefaultRuntimeId + : runtimeId)); } public static CultMeshStateRefResolver CreateEveSurfaceCultMeshStateRefResolver( @@ -384,38 +497,6 @@ namespace GameCult.Aetheria.State.Verse return daemonRefs.Or(itemStatRefs); } - private static EveSurfaceDocument ToResolvedEveSurfaceDocument( - string stateFilePath, - AetheriaRuntimeSurfaceDocument surface) - { - return AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument( - surface, - CreateEveSurfaceStateRefResolver(stateFilePath)); - } - - private static EveSurfaceDocument ResolveSurfaceStateRefs( - string stateFilePath, - EveSurfaceDocument surface) - { - return AetheriaRuntimeEveSurfaceAdapter.ResolveStateRefs( - surface, - CreateEveSurfaceStateRefResolver(stateFilePath)); - } - - private static CultMeshStateRefResolver CreateStateRefResolver(string stateFilePath, string runtimeId) - { - TryReadDaemonFrame(stateFilePath, out var frame); - AetheriaRuntimeDaemonPublicationStore.TryReadHealth(stateFilePath, out var health); - AetheriaRuntimeDaemonPublicationStore.TryReadCommandBoundary(stateFilePath, out var commandBoundary); - - return CreateEveSurfaceCultMeshStateRefResolver( - frame, - health, - commandBoundary, - () => OpenRuntimeCatalog(stateFilePath), - new CultMeshRouteHint(CultMeshLocalityKind.InProcess, runtimeId)); - } - private static AetheriaRuntimeLoadoutItemCommit? FindDaemonItem( AetheriaRuntimeRunCheckpointCommit? run, string itemKey) diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeVerseClient.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeVerseClient.cs index 4edebb13c..8680e9eea 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeVerseClient.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeVerseClient.cs @@ -197,9 +197,10 @@ namespace GameCult.Aetheria.State.Verse string statePath, string runtimeId = DefaultRuntimeId) { - return AetheriaRuntimeStateReader.CreateEveSurfaceCultMeshStateRefResolver( + return AetheriaRuntimeStateRefResolver.CreateEveSurfaceCultMeshStateRefResolver( statePath, - string.IsNullOrWhiteSpace(runtimeId) ? DefaultRuntimeId : runtimeId); + string.IsNullOrWhiteSpace(runtimeId) ? DefaultRuntimeId : runtimeId, + AetheriaRuntimeCatalogStore.OpenReadOnly); } public Task GetProviderAdvertisementAsync() @@ -324,7 +325,7 @@ namespace GameCult.Aetheria.State.Verse await Task.WhenAll(frameTask, healthTask, commandBoundaryTask).ConfigureAwait(false); - return AetheriaRuntimeStateReader.CreateEveSurfaceCultMeshStateRefResolver( + return AetheriaRuntimeStateRefResolver.CreateEveSurfaceCultMeshStateRefResolver( frameTask.Result, healthTask.Result, commandBoundaryTask.Result,