From 0697475318920de466fe2a2ceebfa56bb0a6bc07 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 12 Nov 2026 08:24:13 +0400 Subject: fix(capture): replay actual celestial birth clocks --- tools/native-frame-capture/NativeFrameCapture.cs | 76 +++++++++++++++++++++++- tools/native-frame-capture/README.md | 2 + 2 files changed, 75 insertions(+), 3 deletions(-) (limited to 'tools/native-frame-capture') diff --git a/tools/native-frame-capture/NativeFrameCapture.cs b/tools/native-frame-capture/NativeFrameCapture.cs index 9721049c..c5311216 100644 --- a/tools/native-frame-capture/NativeFrameCapture.cs +++ b/tools/native-frame-capture/NativeFrameCapture.cs @@ -138,6 +138,13 @@ internal static partial class NativeFrameCapture private sealed class SkyUvReadback { public uint Object, Origin, RawClock, ElapsedMilliseconds, Generation, ThreadId; + public CelestialBirthReadback[] Births; + } + + private sealed class CelestialBirthReadback + { + public bool Moon; + public uint ElapsedMilliseconds, LifetimeMilliseconds; } private sealed class AtmosphereReadback @@ -818,7 +825,60 @@ internal static partial class NativeFrameCapture Log("SKY_UV_CLOCK generation=" + frame.CameraGeneration + " tid=" + threadId + " raw=" + rawClock + " origin=" + origin + " elapsed_ms=" + elapsed); return new SkyUvReadback { Object = obj, Origin = origin, RawClock = rawClock, - ElapsedMilliseconds = elapsed, Generation = frame.CameraGeneration, ThreadId = threadId }; + ElapsedMilliseconds = elapsed, Generation = frame.CameraGeneration, ThreadId = threadId, + Births = CaptureCelestialBirths(process, terrainBase, rawClock, obj, frame) }; + } + + private static CelestialBirthReadback[] CaptureCelestialBirths(IntPtr process, uint terrainBase, + uint rawClock, uint skyObject, FrameSnapshot frame) + { + AtmosphereReadback sample; + if (frame.AtmosphereByThread == null + || !frame.AtmosphereByThread.TryGetValue(frame.CameraThreadId, out sample) + || !sample.ArithmeticVerified || !sample.TerrainModuleHashVerified + || !sample.WorldTimeMatchesRawClock || sample.RawClock != rawClock) return null; + uint atmosphere = sample.AtmosphereObject; + uint array = ReadU32Exact(process, checked(atmosphere + 0x1A0)); + uint count = ReadU32Exact(process, checked(atmosphere + 0x1A4)); + uint capacity = ReadU32Exact(process, checked(atmosphere + 0x1A8)); + if (count > capacity || capacity > 64 || (count != 0 && array == 0)) + throw new InvalidOperationException("Atmosphere object array bounds changed."); + List births = new List(); + bool skyFound = false; + for (uint i = 0; i < count; i++) { + uint obj = ReadU32Exact(process, checked(array + i * 4)); + skyFound |= obj == skyObject; + if (ReadU32Exact(process, obj) != checked(terrainBase + 0x6610C)) continue; + byte[] state = new byte[0x38]; + if (!ReadExact(process, obj, state)) throw new InvalidOperationException("Celestial birth unreadable."); + float angleA = BitConverter.ToSingle(state, 0x30), angleB = BitConverter.ToSingle(state, 0x34); + bool sun = Math.Abs(angleA - Math.PI / 2) < 1e-4 && Math.Abs(angleB - Math.PI / 6) < 1e-4; + bool moon = Math.Abs(angleA) < 1e-4 && Math.Abs(angleB - 50 * Math.PI / 180) < 1e-4; + uint lifetime = BitConverter.ToUInt32(state, 0x2C); + if ((!sun && !moon) || lifetime == 0 || lifetime > Int32.MaxValue + || births.Exists(delegate(CelestialBirthReadback b) { return b.Moon == moon; })) + throw new InvalidOperationException("Celestial birth layout or role changed."); + births.Add(new CelestialBirthReadback { Moon = moon, + ElapsedMilliseconds = unchecked(rawClock - BitConverter.ToUInt32(state, 0x28)), + LifetimeMilliseconds = lifetime }); + } + if (!skyFound) throw new InvalidOperationException("Captured sky is absent from its atmosphere object array."); + return births.ToArray(); + } + + private static void AppendCelestialBirthJson(StringBuilder json, CelestialBirthReadback[] births) + { + if (births == null) { json.Append("null"); return; } + json.Append("{"); + for (int role = 0; role < 2; role++) { + if (role != 0) json.Append(", "); + json.Append(role == 0 ? "\"sun\": " : "\"moon\": "); + CelestialBirthReadback found = Array.Find(births, delegate(CelestialBirthReadback b) { return b.Moon == (role == 1); }); + if (found == null) json.Append("null"); + else json.Append("{\"elapsed_milliseconds\": " + found.ElapsedMilliseconds + + ", \"lifetime_milliseconds\": " + found.LifetimeMilliseconds + "}"); + } + json.Append("}"); } private static bool SkyUvMatchesFrame(FrameSnapshot frame) @@ -843,7 +903,10 @@ internal static partial class NativeFrameCapture json.AppendLine(" \"origin_raw_clock\": " + sky.Origin + ","); json.AppendLine(" \"frame_generation\": " + sky.Generation + ","); json.AppendLine(" \"thread_id\": " + sky.ThreadId + ","); - json.AppendLine(" \"elapsed_milliseconds\": " + sky.ElapsedMilliseconds); + json.AppendLine(" \"elapsed_milliseconds\": " + sky.ElapsedMilliseconds + ","); + json.Append(" \"celestial_births\": "); + AppendCelestialBirthJson(json, sky.Births); + json.AppendLine(); json.AppendLine(" },"); } @@ -2426,11 +2489,18 @@ internal static partial class NativeFrameCapture CameraWorldGameTimeWordReadable = true, CameraWorldGameTimeWord = 265584022, WorldGameTimeWord = 265584022, SkyUv = new SkyUvReadback { Generation = 7, ThreadId = 11, RawClock = 265584022, - Origin = 509280060, ElapsedMilliseconds = unchecked(265584022U - 509280060U) } }; + Origin = 509280060, ElapsedMilliseconds = unchecked(265584022U - 509280060U), + Births = new CelestialBirthReadback[] { new CelestialBirthReadback { + ElapsedMilliseconds = 378466, LifetimeMilliseconds = 525000 } } } }; StringBuilder json = new StringBuilder(); AppendSkyUvJson(json, frame); if (!SkyUvMatchesFrame(frame) || json.ToString().IndexOf("4051271258", StringComparison.Ordinal) < 0) throw new InvalidOperationException("Verified sky UV wrapping clock was rejected."); + if (json.ToString().IndexOf("\"elapsed_milliseconds\": 378466", StringComparison.Ordinal) < 0 + || json.ToString().IndexOf("\"moon\": null", StringComparison.Ordinal) < 0) + throw new InvalidOperationException("Celestial age or inactive role was lost."); + if (CaptureCelestialBirths(IntPtr.Zero, 0, 0, 0, new FrameSnapshot()) != null) + throw new InvalidOperationException("Unpaired celestial clock accepted."); frame.SkyUv.ThreadId++; if (SkyUvMatchesFrame(frame)) throw new InvalidOperationException("Sky UV thread mismatch accepted."); frame.SkyUv.ThreadId--; diff --git a/tools/native-frame-capture/README.md b/tools/native-frame-capture/README.md index 1f7166b4..338f3438 100644 --- a/tools/native-frame-capture/README.md +++ b/tools/native-frame-capture/README.md @@ -6,6 +6,8 @@ Capture modes attach only to the isolated GOG-compatible scratch copy of `Parkan `sky_uv_clock` records the independent scrolling-texture clock at sky render entry (`Terrain+0x48110`). It requires a verified module/prologue, the selected camera, matching render thread/generation/world clock, and zenith UV values matching all three native scroll formulas. It preserves wrapping `u32` subtraction from the sky object's origin clock. FParkan holds this phase during exact capture replay; ordinary application frames animate the cloud, star and nebula UVs with periods of 50, 100 and 300 seconds. Older captures without this object still load and report `render_coverage captured_sky_phase_unverified=1`; their sky texture phase is not a native reference. +`sky_uv_clock.celestial_births` records the actual elapsed/lifetime milliseconds of sun and moon objects at the same sky boundary. The bounded atmosphere object array, CSun vtable and native birth angles are checked before reading these clocks. A null role means that object is absent; a null `celestial_births` means the clocks were not verified. Replay uses the captured ages with its own orbit/glare calculations; it does not import rendered light colors. An explicit `--atmosphere-seconds` override keeps nominal schedule births instead. Old captures report `captured_celestial_clock_unverified`. + The JSON keeps the `fparkan-legacy-camera-v1` schema and adds `native_fog_status`, diagnostic counts, and `native_fog`. The latter is an optional passive CPU-side snapshot of the effective sink flags/RGB/range plus the paired calls to the `Terrain+0x2F230` consumer. The flags byte is raw and not a decoded fog mode. Each draw record preserves the distance argument, raw bypass dword and effective low byte, source color, output pointers, and return address. Geometry at `EBP` is included only for the verified `Terrain+0x18A6A` caller with the expected geometry vtable and slot+0x14 target; other callers have `distance_geometry: null`. The fog object is `null` unless the samples match the same render thread, camera, generation, and projection matrix and agree on sink settings. `native_fog_status` is `paired`, `conflict`, `unpaired`, or `incomplete`; `native_fog_status_reason` explains an unpaired, conflicting, or incomplete result. The counts include processed, overflow, paired, rejected, other-thread, and matrix-mismatch calls. At most 512 calls are processed per camera generation; reaching the limit stops sampling and reports an incomplete result. These fields are additive: camera-input validation continues to accept older JSON without them. This probe observes CPU consumer state; it does not set fog or change GPU state. The capture helper expects an isolated copy at `target\shadow-probe\Parkan - Iron Strategy`; the original GOG installation stays untouched. For the default local install path, create that scratch copy from the repository root with: -- cgit v1.2.3