From df0263b26efc94e25c49b1f87a4ac8ff8479e5c3 Mon Sep 17 00:00:00 2001 From: Cristian Cerroni Date: Mon, 26 Oct 2026 21:45:57 -0400 Subject: [PATCH] Recover and verify static collision traversal and body contracts --- AGENTS.md | 6 +- docs/architecture.md | 9 +- docs/checkpoint/README.md | 6 + docs/checkpoint/collision-body-probe.md | 117 ++++++++ .../checkpoint/collision-contact-callbacks.md | 253 ++++++++++++++++ docs/checkpoint/collision-grid-traversal.md | 142 +++++++++ .../collision-integration-review.md | 64 ++++ docs/checkpoint/coverage.md | 2 +- docs/checkpoint/implementation-plan.md | 16 + .../checkpoint/player-phase-implementation.md | 11 +- docs/compatibility.md | 16 + docs/decisions.md | 9 + docs/progress.md | 47 +++ docs/reverse-engineering.md | 4 + docs/tasks.md | 7 +- scripts/test.sh | 1 + src/GamePort/Assets/Mesh.cs | 13 +- src/GamePort/Game/LabSimulation.cs | 5 +- src/GamePort/Game/OriginalCameraRay.cs | 4 +- src/GamePort/Game/OriginalStaticCollision.cs | 154 ++++++++++ .../GamePort.StaticCollisionTests.csproj | 9 + .../GamePort.StaticCollisionTests/Program.cs | 103 +++++++ tests/test_body_step_evidence.py | 21 ++ tests/test_collision_contact_callbacks.py | 110 +++++++ tests/test_collision_dispatch.py | 19 ++ tests/test_collision_grid_traversal.py | 79 +++++ tests/test_collision_material_identity.py | 42 +++ tools/binary/body_step_evidence.py | 50 ++++ tools/binary/body_step_probe.c | 106 +++++++ tools/binary/collision_contact_callbacks.py | 275 ++++++++++++++++++ tools/binary/collision_dispatch.py | 46 +++ tools/binary/collision_dispatch_probe.c | 72 +++++ tools/binary/collision_grid_traversal.py | 151 ++++++++++ tools/extractors/omt.py | 10 +- 34 files changed, 1962 insertions(+), 17 deletions(-) create mode 100644 docs/checkpoint/collision-body-probe.md create mode 100644 docs/checkpoint/collision-contact-callbacks.md create mode 100644 docs/checkpoint/collision-grid-traversal.md create mode 100644 docs/checkpoint/collision-integration-review.md create mode 100644 src/GamePort/Game/OriginalStaticCollision.cs create mode 100644 tests/GamePort.StaticCollisionTests/GamePort.StaticCollisionTests.csproj create mode 100644 tests/GamePort.StaticCollisionTests/Program.cs create mode 100644 tests/test_body_step_evidence.py create mode 100644 tests/test_collision_contact_callbacks.py create mode 100644 tests/test_collision_dispatch.py create mode 100644 tests/test_collision_grid_traversal.py create mode 100644 tests/test_collision_material_identity.py create mode 100644 tools/binary/body_step_evidence.py create mode 100644 tools/binary/body_step_probe.c create mode 100644 tools/binary/collision_contact_callbacks.py create mode 100644 tools/binary/collision_dispatch.py create mode 100644 tools/binary/collision_dispatch_probe.c create mode 100644 tools/binary/collision_grid_traversal.py diff --git a/AGENTS.md b/AGENTS.md index 7c6e193..7a7abe0 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -55,4 +55,8 @@ are in its final section and the implementation ledger. Current C4 follow-up is docs/checkpoint/collision-response.md with ceiling-wrapper, body-root-registration and camera-handoff reports. The source sphere kernel is isolated/probed; do not treat it as live capsule replacement. Next integration -gates are grid/normal callbacks/support/friction and shared camera state. +report is collision-body-probe.md: source grid/retry component and seven original +dispatcher comparisons, contact/material/friction contracts and ten ordinary-body +observations are recorded. Next: compose ordinary body against those references, +then explicit VR04 live integration. Lab/outside additionally need special contacts +and dynamic reclip/shared-state ownership; shared camera state remains separate. diff --git a/docs/architecture.md b/docs/architecture.md index fe472d0..7bfc0ba 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -25,7 +25,14 @@ fly camera or rendered model alone does not satisfy the playable-scene requireme Collision continuation separates the recovered one-triangle47BD80 kernel (`OriginalSphereResponse`) from the live capsule adapter. Its explicit nearest -state is caller-owned; source grid/callback/support integration remains gated. +state is caller-owned. `OriginalStaticCollision` composes source FIFO cell visits, +retry and support-grid reduction as an isolated component. Its caller owns body +integration, terminal callbacks and shared nearest/last-polygon reset timing. +Prepared collision metadata retains signed material archive identities and an +explicit completeness flag; source body callers must account for special contacts. +Seven original dispatcher comparisons and ten original ordinary-body reference +observations are in checkpoint/collision-body-probe.md. Live body composition, +special callbacks and dynamic reclipping remain gated. The source-root upward ray is supplied separately from the camera debug query: Jimmy's wrapper reflects upward velocity/cancels mode1 jump/fire before movement, including while uncontrolled. Fresh input precedes this wrapper; retained input diff --git a/docs/checkpoint/README.md b/docs/checkpoint/README.md index 6d2907f..8afde72 100644 --- a/docs/checkpoint/README.md +++ b/docs/checkpoint/README.md @@ -33,6 +33,12 @@ C4 continuation: [sphere response](collision-response.md), [ceiling wrapper](ceiling-wrapper.md) and [physical re-registration](body-root-registration.md). The source kernel is isolated/probed; live capsule replacement remains gated. [Shared camera handoff](camera-handoff.md) records the next C5 state correction. +The next C4 chunk adds [grid traversal](collision-grid-traversal.md), +[contact/material/friction ownership](collision-contact-callbacks.md) and +[dispatcher/body component probes](collision-body-probe.md). The source dispatcher +is implemented and compared with isolated original outputs; whole-body/live +integration and special contacts remain gated. [Independent review](collision-integration-review.md) +records corrections and remaining limits. Evidence labels used throughout: diff --git a/docs/checkpoint/collision-body-probe.md b/docs/checkpoint/collision-body-probe.md new file mode 100644 index 0000000..036816d --- /dev/null +++ b/docs/checkpoint/collision-body-probe.md @@ -0,0 +1,117 @@ +# C4 dispatcher and ordinary-body component evidence + +2026-10-26 continuation, verified2026-10-27 UTC. Original EXE SHA256 +`f5281076e1a2492f2d61f87aae3f4544b6d0f535ebe33f9fbb6f78710fe1aea8`. +Originals remain unchanged. This report separates copied-code component execution +from the playable port, full original game behavior and native Windows testing. + +## Recovered contracts and evidence + +The [grid report](collision-grid-traversal.md) recovers47B4B0 recursion, frozen +query bounds, repeated FIFO cell visits and terminal callback ownership. The +[contact report](collision-contact-callbacks.md) recovers370/374/37C, special +material identity, separate published speed and friction. Those reports retain +addresses, file offsets, byte guards, callers, structures and REA Evidence. + +Additional closed/exported REA sessions in artifacts/collision-integration/: + +| Procedure | Evidence | Contract | +|---|---|---| +|47A330|ev_8be4a538fe941bcf0ba77ce64f552d4f0e17969ea87713cec5d37d39bc560735|Supported/nonzero-linear friction; published160 gates caller.| +|47C6E0|ev_ad96a93792dcf00534130fbd428fb52fa25e2cf9c2492df43f89f425b80c3f08|All-grid strict nearest support reduction, initial segment magnitude.| +|471120|ev_90314124d5ab1c88911198ef9e8d43ad7cc9e096ca075757d29c5e15cf1f86eb|Authored float8 writes live suppression scale through234.| +|470540|ev_c16f95e608194a8f9fb029430f1c6a01512d34099ebf447cf944946c79631166|Init copies authored flags/scalars through virtual setters.| + +Body479D20 remains anchored by ev_5439072b32ae9f9208795ad2b07bc524e2407b46da487072fb3dfd8c10e7c4b0 +in artifacts/collision-response/rea-response/. Generated source.json reports +PE-mapped offsets; the five added body hashes cover479D20/47A330/47B890/47C6E0/ +469A10, alongside ten existing dispatcher/kernel bodies. Hashes and relocation +sites are checked by test_body_step_evidence.py; no arbitrary scan of executable +values is used at execution time. Short accessor recognition failures in rea-body +are retained beside successful replies, not represented as decompilation success. + +## Isolated execution boundary + +tools/binary/collision_dispatch_probe.c and body_step_probe.c map a generated, +hash-checked EXE copy into their own32bit process. Preferred-base mapping was +unavailable; existing guarded mapper rebases only explicit in-memory operands. +Fixtures supply synthetic grids, shape/polygon/corner arrays and virtual methods; +the body fixture supplies ordinary flags, radius60, factor1.265, friction0.8, +suppression scale0.5 and gravity(0,−800,0). No game entry point, full Jimmy +instance, source window/input/audio/script lifecycle or dynamic body pass runs. +Landing37C is an observer fixture; real ordinary Jimmy37C is a no-op. + +reference_capture.py runs a separate generated Wine prefix/copy with no network +and no original-directory mount. Sources/header/identity metadata and logs are +under artifacts/collision-integration/dispatch/ and body-probe/. Initial fixture +failures are preserved: a missing Euler328 virtual was diagnosed and supplied, +and direct member42C has allocated zero storage. Those were harness omissions, +not original game defects. Automatic approval review temporarily failed due its +usage limit; after its stated reset time, a normal reviewed retry succeeded. + +## Observed dispatcher results + +All seven original fixtures completed with DISPATCH_COMPONENT_COMPLETE. Managed +OriginalStaticCollision regressions compare these positions and exact counts. + +| Fixture | RootXYZ | Passes / primitive visits | Terminal callback | +|---|---|---|---| +|face retry|0,20,10|2 /4|wall0| +|edge retry|107.071068,100,7.07106781|2 /2|wall0| +|edges disabled|105,100,5|1 /1|none| +|zero motion|0,20,20|0 /0|none| +|forced zero/member42C|0,20,20|1 /2|none| +|corner retry|5,20,10.000001|2 /8|wall0| +|ceiling retry|0,90,0|2 /8|ceiling0| + +## Observed body results + +All ten copied479D20/support fixtures completed with BODY_COMPONENT_COMPLETE; +finite-output assertions pass. These are observations for the next body adapter, +not claims that a managed full-body equivalent already exists. dt is float1/60; +all unspecified vectors are zero. Initial previous support is false except jump. + +| Fixture | Initial distinction | Observed result | +|---|---|---| +|floor support|RootY75.9|Y75.9000015, supported, callback sees Vy−13.333334/support=false.| +|spawn settle|RootY26|Same support root/landing observation.| +|pending jump|Supported, impulseY550, accelerationY−264|Y84.7711105, Vy532.266663, unsupported; impulse consumed.| +|fall above floor|Y100, Vy−200|Y96.4444427, Vy−213.333328, unsupported.| +|fall land|Y76, Vy−200|Y75.9000015, Vy0; callback sees old Vy−213.333328/support=false.| +|ground friction|V(100,0,50), angularY12, published speed0|Root(1.66666675,75.9000015,0.833333373); V(98.6666641,0,49.3333321), angularY11.8400002.| +|published speed|Same vectors, published speed100|Same root; V(100,0,50), angularY12, no friction.| +|stationary angular|Linear0, angularY12|AngularY12 remains; zero linear magnitude skips angular friction.| +|small motion|Vx0.125|RootX0.00208333344 then velocity suppressed to0.| +|geometry disabled|Vy200, accelerationY−264|Y75.9000015, Vy0, accelerationY800, supported, no landing callback.| + +The geometry-disabled branch479DF7..479E54 sets supported, anchor and acceleration +before impulse/integration. It does not test prior grounded state. This corrects +the earlier C3 support-cancellation interpretation. With geometry enabled, the +jump fixture applies acceleration and gravity normally. + +## Implementation and remaining gate + +OriginalStaticCollision is currently an isolated source dispatcher/support-grid +component, invoked by tests. It preserves duplicate visits, retry state, negative +Z upper-bound quirk and terminal publication. Its explicit geometry-enable input +skips primitive calls but preserves terminal callback. TraceSupport uses strict +nearest reduction. The256-pass rejection is a defensive port boundary; original +recursion has no recovered depth limit. Double cell intermediates/modern quick +magnitude tables do not promise exact x87 boundary equivalence. Triangular route +metadata is required; general polygon fans are rejected by duplicate identity. + +Prepared scenes now include signed3DMa archive IDs. Mesh keeps an explicit +identity-completeness flag; source grid construction rejects old prepared metadata. +Camera behavior is unchanged. Lab/outside contain special fence/climb/ladder IDs; +VR04 contains none. This is a scene-data fact, not proof every lab trajectory +contacts one or that all Player374 policies are implemented. + +Next coherent implementation: combine the proven dispatcher with ordinary body +integration, negative-Y horizontal-first split, callback370, support/landing order, +published160 friction and suppression, comparing the ten references above. Start +with an explicit ordinary-contact subset (VR04); reject unsupported special policy +rather than silently discarding it. Then test model/root support, airborne input, +ceiling and tutorial/RETURN through the live adapter. Lab/outside require recovered +special160/164/FENCE/LADDER policies and dynamic shared nearest/last-polygon/reclip +ownership before replacement. Whole-scene registry/base transforms, camera shared +eye, original end-to-end comparison and native Windows validation remain open. diff --git a/docs/checkpoint/collision-contact-callbacks.md b/docs/checkpoint/collision-contact-callbacks.md new file mode 100644 index 0000000..b88e02a --- /dev/null +++ b/docs/checkpoint/collision-contact-callbacks.md @@ -0,0 +1,253 @@ +# C4 contact callbacks, landing and friction + +2026-10-26. Static recovery for original EXE SHA256 +`f5281076e1a2492f2d61f87aae3f4544b6d0f535ebe33f9fbb6f78710fe1aea8`. +Addresses below are preferred VAs; these text offsets are VA−400000. The helper +maps PE sections independently and retains exact bytes, offsets, 20 virtual +targets and six complete callback hashes in +`artifacts/collision-integration/contacts/source-contract.json`. + +## Recovered dispatch and state ownership + +The game-interface pointer is complete object+C0. Slots below are relative to +that interface, not the complete-object movement slots130/134. + +| Class/interface table |370|374|378|37C| +|---|---|---|---|---| +|C3DObject4D3154|472690|458890|472750|472970| +|C3DAnimated48FE1C|472690|458890|472750|472970| +|C3DPlayer4AF6C4|472690|43AA40|472750|472970| +|C3DJimmy4A373C|472690|42A660|472750|472970| + +Static traversal47B4B0 publishes its candidate current root at47B7B1..BD, +then reads last-hit polygon695D4C. If present, it copies polygon+8..14 normal +and dispatches374 at47B80F if normal.Y is strictly greater than float32−0.7 +(4A3148, bytes333333BF); otherwise370 at47B82E. Equality dispatches370. +The arguments are a by-value four-float normal and polygon pointer. This occurs +after grid/triangle response, before the body's later support/friction phase; +the supplied original stored normal is not derived from triangle winding. + +370→472690 (raw72690, lengthBA) independently reads live velocity2BC and +acceleration270. A strictly positive Y is set to zero through2C0/274; +nonpositive Y and X/Z/W are preserved. It does not project against the supplied +normal or change movement mode, jump latch, fire timer or horizontal speed. + +Generic374→458890 (raw58890, length3D) checks interface1D8, then forwards the +four-float normal to378→472750. Jimmy overrides374:42A660 (raw2A660,lengthB4) +forwards to Player43AA40 at42A70B on the ordinary path. It does **not** enter +generic374/378 on that path. Therefore generic reflection/projection must not be +attached to every Jimmy wall contact merely because base378 exists. +No-selection−1 and selected-jetpack3 both take this ordinary branch because +neither equals7 (selection identities recovered in retained-return-cleanup.md). +For a nonspecial metadata ID, neither state adds velocity, position, orientation, +mode, jump or gadget-side effects through374. This bounds the route's supported +states; it does not imply every material on the route is nonspecial. + +Jimmy's gadget7 branch additionally checks global4F8210. When set, it invokes +Player contact, zeros global4F82BC/C0, tests their prior two-component magnitude +against60, and may invoke complete-object204 and set interface1D65. Those +gadget effects remain outside ordinary-contact integration. + +## Player material handler + +43AA40 (raw3AA40,length5A3) first requires interface774 elapsed>3.0. The signed +discriminator comes from polygon+4 → material+0C → database chunk+8; missing +records produce no ordinary effect. The follow-up below proves this is the +3DMa archive resource ID, not an additional custom payload flag. It remains +distinct from a merged render-array index or texture resource ID. + +| Metadata ID | Effect after elapsed gate | +|---|---| +|120..129|Calls complete-object160 with supplied normal.| +|110..119|Calls complete-object164.| +|60..69, only mode704==0|Additional rays/orientation/root/action handling ending in FENCE.| +|180, only mode704==0|Additional rays/orientation/root/action handling ending in LADDER.| +|Others|Returns without generic velocity projection or mode/jump reset.| + +These are dispatch facts, not complete recovery of the four special policies. +Complete160/164 effects and all ray success/failure transitions need separate +tracing before implementation. The ordinary callback has no raw-control5099E4 +gate; controller ownership alone cannot justify suppressing contact effects. + +## Material database identity and actual route coverage + +OMT2.dll SHA256 is +`3ec41ead011adf56387a6dbd4580e5b5a9721b5f8020c8a56420f42824354943`. +The EXE chain above reaches OMediaDBObject's inherited database association: + +| DLL VA / raw offset | Proven role | +|---|---| +|10030070 /30070, exported db_link|Arguments are database, OMediaFSChunk*, type.1003007F stores that chunk pointer in material/object+0C; chunk+0C is the reciprocal object pointer.| +|10030260 /30260, DBObjectStreamLink::read_class|Reads link fourcc through100302B3 and signed long ID through100302BF;100302EE calls database get_object(type,ID), stores resulting material pointer in temporary streamlink+4.| +|10003E20 /3E20, Polygon::read_class|10003F56 reads a temporary stream link;10003F5B obtains its pointer at temporary+4;10004277 calls set_material100043F0.10004408 publishes it in polygon+4, with material reference-count bookkeeping. The legacy-version path10004252..5E also uses set_material.| +|1002DEF0 /2DEF0, DataBase::get_object(type,long)|Looks up the requested chunk through formatted-stream slots6C/74, then passes that chunk to object's virtual18/db_link at1002E0B0.| +|10045B70 /45B70, FormattedStream::get_chunk(node,long)|Looks up signed ID in the chunk map, returns the corresponding chunk record (list-node+8).| +|100464C0 /464C0, FormattedStream::load_header|100465A7 reads ID into stack58;100465B4/C1 read offset/size into stack50/54;10046638..46 insert record starting stack50. Thus ID is chunk record+8.| + +The on-disk source is the 0MF2 resource-table entry's big-endian32 identity, +not a field inside the 3DMa material payload. The payload parser's trailing BE16 +is3 for every used material in all three archives, including special and +ordinary contacts. The helper records each material's exact table ID byte offset, +separate payload offset/size/hash, archive hash, and source shape/polygon identity. +Negative on-disk IDs require signed32 interpretation for policy comparisons; +all special route IDs below are positive. + +| Archive | Special ID | Non-NC polygons using ID | Wall-grid polygons eligible for374 | +|---|---:|---:|---:| +|level1b.omt|61|23|20| +|level1b.omt|62|24|24| +|level1b.omt|63|4|4| +|level1b.omt|120|4|4| +|level1b.omt|121|32|20| +|level1b.omt|122|3|3| +|level1b.omt|180|6|6| +|VR04.omt|none|0|0| +|level1.omt|60|62|62| +|level1.omt|61|51|38| +|level1.omt|62|38|26| +|level1.omt|180|32|20| + +Eligibility means registered shape and strictly−0.7−0.7, otherwise370; equality selects370. +Both callbacks receive normal Vec4 and polygon pointer. Actor logical position +is written later by the enclosing movement caller's virtual314, so publication +through a stack vector does not itself prove the actor transform has changed. + +The body integrator479D20 clears last polygon at47A038, initializes face distance +to **130000** at47A03E (bits47FDE800), and edge distance to radius at47A062. +The isolated primitive's −1 face sentinel is not the body-entry initialization. +Dynamic reclip47B364 calls this same dispatcher with edges=false (47B30B), then +publishes actor root through314 at47B399. It inherits nearest state: dynamic +entry separately sets edge=radius at47AB3F and face=−1 at47AB4B. No dynamic clear +of695D4C was found; identified absolute writes are47A038 and47BD65. Its caller +schedule remains relevant when interpreting retained last-polygon callbacks. + +## Registration and source layout + +479140 walks shape polygon array begin+88/end+8C in48byte strides; it applies +checkpoint4794C0 and game-specific4797A0 filters before registration. Existing +[camera-ray evidence](camera-ray-predicate.md) establishes scene44DBF0's ascending +shape resource-index traversal. No new decorative/material rule is inferred here. +Game filter4797A0 calls the game's virtual134 at4797EC. + +Each polygon's **all-corner** X/Z extrema determine registration cells using the +same conversion and inclusive X-outer/Z-inner order. Registration upper Z is a +conventional maximum, unlike query zmax. A28byte registration allocation stores +polygon0, shape4, centerXYZ8/C/10, W14 and radius18; bounds/candidate traversal do +not use this center/radius as a per-visit cull. Record is shared across its cells. +479800 rejects a duplicate polygon pointer within one cell (47985E..479866), +irrespective of shape pointer. New nodes append FIFO to all-grid5CFC7C +(47989F..4798A8), and wall-grid509B24 only when stored normal.Y<0.7 +(4798B3..4798CF); equality is excluded. There is no query-wide deduplication. + +477F10(out,shape,polygon,signed-short corner) reads polygon+24 corner records, +20bytes each. Their first DWORD is a vertex index into shape+68 Vec4 vertices, +16bytes each. It copies the selected Vec4 without transforming it. The wrapper +uses corners0/1/2 even though registration bounds use all corners. + +## Evidence and implementation boundary + +Owned REA CLI session used a generated copy, closed normally and retained complete +replies/export/snapshot in artifacts/collision-integration/grid/rea/: + +| Procedure | Evidence ID | +|---|---| +|47B4B0|ev_f39128dafc2a3a20b5768613ce22b3c3168fe8653908837d92ad9a69ef5f2ad8| +|479140|ev_c6bffe721e0751327ecdb5e62c27137752574be6624c190a833c5b2c0f5be7b0| +|4797A0|ev_277ddc7e6b8383ea4245072e395a3dda51cd530c56fb160b917823803f55d33f| + +dispatcher.instructions.txt retains the reachable retry instructions; +source-anchors.json records raw anchors, offsets, constants and four function-body +hashes. tests/test_collision_grid_traversal.py guards source bytes plus five +fixture groups: asymmetric bounds, clipped/inclusive order, per-cell duplicate +rules, mutable candidate and retained nearest/last-polygon across passes. + +Minimal integration: build source-order wall cells; pass an explicit shared nearest +state into existing OriginalSphereResponse; scan frozen bounds with a mutable +candidate; retry revised displacement against unchanged previous root; then publish +and dispatch the last-polygon normal callback once. Reuse this dispatcher for +dynamic reclip without adding implicit state resets. A defensive port recursion +limit would be a documented implementation deviation, not recovered behavior. + +Follow-up original dispatcher execution completed seven synthetic grid cases; +see collision-body-probe.md for outputs, fixture boundaries and managed comparison. +OriginalStaticCollision implements the bounded traversal as an isolated component; +it is not yet the live player solver. Geometry-disabled traversal preserves +terminal publication and retained callback; it skips primitive calls per visit. +TraceSupport initializes its strict nearest limit to quick_magnitude(end−start). +Prepared route geometry carries signed archive material IDs and rejects missing +identity metadata before special-contact coverage is assessed. + +Unresolved: x87 cell +conversion at integer boundaries and extreme signed-short wrap; full scheduler +ownership of global collision toggles and retained dynamic last-polygon state. +The local projection does not establish numerical identity at those boundaries +or runtime correctness of the integrated port. diff --git a/docs/checkpoint/collision-integration-review.md b/docs/checkpoint/collision-integration-review.md new file mode 100644 index 0000000..ac7fefe --- /dev/null +++ b/docs/checkpoint/collision-integration-review.md @@ -0,0 +1,64 @@ +# C4 static dispatcher review + +2026-10-26. Independent source review of the uncommitted static dispatcher, +its managed fixtures, saved REA replies and retained original-component output. +No original code was executed and no new REA session was opened by this review. +File ownership for this report only; primary owns integration and corrections. + +## Findings and disposition + +- **Corrected during review:** `TraceSupport` initially accepted its first + triangle hit without the source's initial nearest-distance limit. Retained + REA support reply `artifacts/collision-integration/rea-support/00.json`, + Evidence `ev_ad96a93792dcf00534130fbd428fb52fa25e2cf9c2492df43f89f425b80c3f08`, + initializes47C6E0's nearest distance to quick_magnitude(end−start), then + requires a strictly smaller hit magnitude. The kernel's parameter-distance + check is separate from the returned hit's magnitude. Primary added that + initial limit and strict comparison. This closes a source-contract omission; + no original numeric boundary probe is claimed. +- **Corrected during review:** old prepared meshes could omit material IDs and + appear ordinary-only. Primary added explicit material-identity completeness + metadata and a `FromRouteScene` rejection requiring newly prepared scenes. + Resolved null-material identity remains distinct from missing metadata. +- **Corrected after review:** `Move` now accepts the source geometry-enable state. + Source47B4B0 reads4F69E5 per node, while its final publication and retained + last-polygon callback can still occur when geometry is disabled. A caller + must not equate disabling geometry with skipping `Move` when it reuses a + context. The added regression checks publication and retained callback without + primitive visits. Dynamic shared-state/reset timing remains a live gate. +- **Live integration gate:** the dispatcher returns a candidate and terminal + polygon; it does not publish the logical actor transform or execute callback + 370/374, support, friction or speed publication. Jimmy ordinary374 must retain + the special-material boundary. LV1B/LEV1 contain such materials; VR04's + absence of them is a bounded route-data result, not a general player policy. +- **Documented port limits:** iterative retry rejection after256 passes, + finite inputs, triangular polygons and approximate x87 cell conversion are + explicit boundaries. Do not promote this component to whole-body identity + or claim the source has a recursion cap. + +## Verification + +`source scripts/env.sh && dotnet run --project +tests/GamePort.StaticCollisionTests` passed seven groups during review. The +seven printed copied-original dispatcher cases in +`artifacts/collision-integration/dispatch/wine.log` match the managed fixtures' +positions, pass/visit counts and terminal polygon observations. The retained +marker is `DISPATCH_COMPONENT_COMPLETE`; the reviewer did not rerun that probe. +This verifies a bounded original component comparison, not live port gameplay. +Primary's subsequent focused run passes eleven groups, adding actual prepared +route material coverage, legacy metadata rejection, geometry-disabled retained +context, equal support ties and zero-length limits. Full integration passes122 +Python checks plus HUD/managed/GPU/audio/hash checks; see progress.md for scope. + +Registration sorting, X-outer/Z-inner traversal, per-cell duplicate visits, +frozen bounds including source MIN upper-Z, unchanged previous root across +retries, persistent nearest state and terminal-only callback selection agree +with collision-grid-traversal.md and its retained instruction/REA evidence. + +Before enabling live body response, extend regression coverage to inherited +nearest/last-polygon state across separate dynamic reclip calls, equal-distance +support ties, and callback ownership/order after publication. Complete the +source contact policies and route/root checks identified by the implementation +ledger. After the stated review reset time, primary retried through normal +approval review and completed the ten-fixture isolated body probe. This closes +that execution blocker, but does not establish live whole-body equivalence. diff --git a/docs/checkpoint/coverage.md b/docs/checkpoint/coverage.md index aee1518..12768fc 100644 --- a/docs/checkpoint/coverage.md +++ b/docs/checkpoint/coverage.md @@ -16,7 +16,7 @@ runtime comparison. Coverage does not mean implementation completeness. | INPUT | Game interface+8C slot3C4→44DF80→475A70 reads controlled5099E4 and calls3CC; Jimmy interface+C0→426030. | SDL arrows/jump aliases; control gate, modern debug override; mouse/controller incomplete. | S/M/R, user Windows route. Input occurs in object traversal after physics; device sampling/focus and latency open. | Trace event pump, key/mouse and focus gates alongside retained registry order. | | MOVE |437940/439900 ground/air arithmetic; physics479D20 consumes queued impulse once before acceleration/gravity. | Player body/fire continue without ownership; input/controller gated; fresh/retained input order explicit. Root overhead wrapper now runs before movement/fire. Fixed dt and custom yaw/model conventions remain. | S/P/M/R. Bounded phases/ceiling implemented; complete base/registry and body response open. | Continue C4 traversal/callback/support integration and C3 base transforms. | | JET |437F90 controller;421FB0 effect; fresh constructor order places fire after Jimmy, both after global physics. States0..5, hold>.4,8s, energy. | Explicit state table with post-collision effect ticking and VR immunity. | S/M/R. Fresh same-pass countdown recovered; retained child lifecycle, sound and expiry→animation open. | Trace retained Jimmy/fire resets and phase end events before scheduler integration. | -| COLL |479D20/47BD80 body response; face/edge nearest state and helpers; root+150 overhead bounce/cancel; support and quick magnitude; dynamic boxes; NC exclusion. | Isolated source sphere kernel with original component references; route overhead wrapper integrated. Live swept24-unit capsule/feet and dynamic response remain provisional. | S/P/M/R. Ten isolated original kernel cases; byte/managed checks. Grid/normal callbacks/support/friction, masks/stairs/root render remain open; radius60 is not capsule24. | C4: integrate traversal/callback/support order before replacing live adapter; doorway/corner is first route case. | +| COLL |479D20/47BD80 body;47B4B0 FIFO grid/retries;370/374/37C; signed material IDs; separate160 friction gate; support/suppression; overhead; dynamic boxes. | Source sphere and static dispatcher/support grid implemented as isolated components; route overhead wrapper live. Prepared IDs retained. Live24-unit capsule/feet and dynamic response remain provisional. | S/P/M/R. Ten original kernel, seven dispatcher and ten ordinary-body observations; managed dispatcher comparisons. Special contacts, live body composition, dynamic shared context and root rendering open. | C4: compose ordinary-body adapter against ten references, then explicit VR04 live subset. Lab/outside need special160/164/FENCE/LADDER and dynamic reclip ownership. | | ANIM | Engine morph10002DB0; linear interpolation10002F9A; game logical→OMT sync4624B0. | ASE sample timing, unconditional loop closure, pose/action aliases,1/60 advance. | S/P/M/R. Playback flags, rate, completion callbacks, transition order open. | Recover one-shot/loop/end notifications before more aliases. | | SCRIPT | Source AI/CAM/MCA dispatch and chains; task45F990 objective406F50 BEFORE records BEFORE per-entity424. | Pre-assignment objective selection and per-actor Carl override implemented; bounded synchronous director. | S/M/R. Script callbacks recovered for route; generic class coverage and reentrancy incomplete. | Continue other class-specific callbacks and reentrancy under the recovered owner/phase boundaries. | | CONTROL | Global5099E4 null during valid CAM/MCA; PlayerControlled completion target; DEFAULT447D..447F restores camera/UI/music. | Director raw ownership plus explicit debug effective override; eligible player body/fire continue; only input/controller tail is gated. | S/M/R. Raw/effective control and ordered preparation are implemented; full base/class wrappers and scheduler remain incomplete. | Continue full wrapper/base and collision contact phases around deferred LOAD. | diff --git a/docs/checkpoint/implementation-plan.md b/docs/checkpoint/implementation-plan.md index c31c3c4..92af939 100644 --- a/docs/checkpoint/implementation-plan.md +++ b/docs/checkpoint/implementation-plan.md @@ -155,3 +155,19 @@ allowed where it resolves a core-system question, without waiting for every leve nondefault tutorial/RETURN checks. Release validation unavailable, enabled source/native checks separate. Package logs in artifacts/collision-response/; baseline untouched and Windows cross-published only. +- C4 static composition: independent REA grid/contact investigations recover + FIFO duplicate traversal, reachable retries, normal/landing ownership, signed + material archive IDs, separate published160 speed and friction/suppression. + Seven isolated original dispatcher fixtures match the managed component's + positions/counts/callbacks. Ten copied479D20/support fixtures completed; no + managed whole-body equivalent is claimed yet. Reports: collision-body-probe.md, + collision-grid-traversal.md, collision-contact-callbacks.md and independent review. +- Prepared scenes now retain material IDs and completeness; legacy metadata cannot + masquerade as ordinary-only. Actual VR04 has no special contacts; LV1B/LEV1 do. + Geometry-disabled publication/retained callback and strict initial support + distance are explicit. Original geometry-off branch supersedes C3's earlier + support-hit gravity-cancellation inference. Playable body remains baseline. +- Next C4 chunk: ordinary-body composition and ten numeric comparisons, negative-Y + horizontal-first split,370, landing-before-velocity-clear, published160 friction + and suppression; then VR04 live root/input/ceiling/RETURN checks. Trace special + callbacks and dynamic reclip/global context before lab/outside replacement. diff --git a/docs/checkpoint/player-phase-implementation.md b/docs/checkpoint/player-phase-implementation.md index 8b5b4c8..1f4385f 100644 --- a/docs/checkpoint/player-phase-implementation.md +++ b/docs/checkpoint/player-phase-implementation.md @@ -47,11 +47,12 @@ navigation still reaches SCENE35→50→60 and the outside LOAD. This is port ev not original timing/latency fidelity. Source nominal frame rate remains unproven; the port keeps its explicit60Hz policy. -The existing capsule/gravity adapter remains. Source479DF7..479E54 can cancel -gravity on a support hit before a queued jump, giving a different first takeoff -velocity. Applying that cancellation to the provisional capsule's prior support -flag caused false support transitions in the port; it must be integrated with -the recovered pre-integration support/response in C4, not bolted onto that flag. +The existing capsule/gravity adapter remains. C4 follow-up corrects the earlier +support-hit interpretation: source479DF7..479E54 cancels gravity and clears +vertical velocity only when global geometry4F69E5 is disabled. It is not a +prior-grounded or support-hit branch. The isolated body probe confirms the normal +pending-jump fixture consumes550 impulse and applies both−264 acceleration and +−800 gravity, producing Vy532.266663 at dt1/60. See collision-body-probe.md. No source-fidelity claim is made for jump apex, stairs, wall response or visual pivot. The underground replay checks clearance of the recovered radius60 body, not raw209-unit standing-mesh bounds, which are a separate provisional render diff --git a/docs/compatibility.md b/docs/compatibility.md index ef2aeb1..0887859 100644 --- a/docs/compatibility.md +++ b/docs/compatibility.md @@ -3,6 +3,22 @@ Compilation, native runtime, original behavior and full feature completion are separate evidence categories. **The game is not fully reconstructed/playable yet.** +C4 static composition follow-up: seven copied-original dispatcher fixtures match +the isolated managed grid/retry component; ten copied479D20/support fixtures +complete as references for future body composition. No live capsule replacement +is claimed. Prepared scenes retain signed material IDs; actual lab/outside special +contacts prevent ordinary-only assumptions. See checkpoint/collision-body-probe.md. +The temporary automatic approval usage-limit failure was resolved through normal +review after its stated reset; original component execution then completed. +Full scripts/test.sh passes122 Python plus2 HUD checks, managed suites and27 +zero-error enabled-validation GPU completions;11 focused dispatcher groups pass. +SDL dummy lifecycle and539 original hashes pass. Evidence is under +artifacts/collision-integration/. No new native Windows or whole-game original +comparison; preserved baseline and prior release packages are unchanged. +Linux-x64 and win-x64 self-contained publish succeeds into separate build artifact +directories. Restore's NU1900 records unavailable vulnerability metadata; compile/ +publish succeeds. No new distribution package or native Windows execution claimed. + C4 continuation (2026-10-26): REA/bytes recover the bounded47BD80 sphere kernel; ten isolated original Wine32 synthetic cases pass with explicitly guarded fixture rebasing. The managed component matches numeric references; live capsule replacement diff --git a/docs/decisions.md b/docs/decisions.md index f28ecc4..09255e6 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -173,3 +173,12 @@ overhead wrapper using its root ray and mode-specific cancellation, retaining fresh/retained input order. Modern camera debug controls affect camera queries only. Do not reinterpret this partial correction as complete original physics. +34. **Compose body response only inside recovered contact coverage.** Preserve + signed material database IDs in collision metadata and reject legacy prepared + data lacking identities. An ordinary-only adapter may start with VR04, whose + static materials have no special Player374 policies; lab/outside contain + special contacts. The tested grid dispatcher is an isolated component until + body/landing/friction order and root visuals are compared; dynamic reclip + must explicitly own shared nearest/last-polygon state. Keep source published + speed160 separate from controller608. Geometry-off gravity cancellation must + not be reinterpreted as an ordinary prior-grounded jump rule. diff --git a/docs/progress.md b/docs/progress.md index 60f48f4..6bd3284 100644 --- a/docs/progress.md +++ b/docs/progress.md @@ -1,5 +1,52 @@ # Progress — 2026-10-26 +## C4 static dispatcher, contacts and ordinary-body probe + +Independent REA investigations and primary integration recover47B4B0's reachable +retry, source-order cell/FIFO duplicates, mutable nearest/last-polygon state and +terminal normal callback. OriginalStaticCollision implements this bounded grid +dispatcher and strict nearest support query as an isolated component. It remains +outside the playable body path. Seven copied-original dispatcher fixtures match +managed positions, pass/visit counts and callback polygon observations. Review +corrected initial nearest-distance gating and geometry-disabled publication with +retained callbacks. All investigator file ownership returned to primary. + +Recovered370/374/37C, landing-before-velocity-clear, published160 versus controller608 +and friction/suppression. The Player material discriminator is linked3DMa archive +ID, proven through OMT2.dll loader/database/chunk layout, not payload flags or a +render index. Scene preparation and Mesh now preserve signed IDs/completeness; +old metadata is rejected by the new source dispatcher. Actual LV1B/LEV1 contain +special climb/fence/ladder IDs; VR04 contains none. Special policies remain open. + +Ten copied479D20/support fixtures completed in an isolated Wine32 harness with +synthetic ordinary-body virtual contracts. Results cover support/settling, +pending jump, falling/landing, friction versus published speed, stationary angular +motion, suppression and geometry disabled. They are numeric references for the +next adapter, not verification of a managed whole-body implementation. Corrected +C3's earlier support-hit inference:479DF7..479E54 cancels gravity/vertical velocity +when global geometry4F69E5 is disabled, not on ordinary grounded jumps. Prior +harness omissions/logs and temporary approval-review usage failure are retained; +after the stated reset, normal approval review succeeded and the probe completed. + +Full scripts/test.sh passes:122 Python checks plus2 HUD checks, all managed groups, +27 GPU completions with zero enabled Vulkan validation errors, SDL dummy lifecycle +and539 unchanged originals. Eleven focused dispatcher groups pass, including actual +route material coverage, legacy metadata rejection, retained context and support +ties. Logs: artifacts/collision-integration/integration.log, dispatcher-tests.log, +dispatch/wine.log and body-probe/wine.log. No new native Windows or whole-original +game comparison is claimed. Existing baseline/release packages remain untouched. +Both self-contained RID builds succeed into separate artifacts/collision-integration/ +build directories. Restore emitted NU1900 for unavailable vulnerability metadata; +compilation/publish succeeded. These are build artifacts, not a new package release +or native Windows runtime verification. Logs: build-linux.log/build-windows.log. + +Reports: checkpoint/collision-grid-traversal.md, collision-contact-callbacks.md, +collision-body-probe.md and collision-integration-review.md. Next: ordinary body +composition against the ten references, then an explicit VR04 live subset with +root/input/ceiling/RETURN checks. Lab/outside replacement additionally requires +special callbacks and dynamic shared-context/reclip order. Shared camera eye, +audio clock/banks and remaining plan chunks follow their existing gates. + ## C4 sphere response and ceiling continuation REA investigated47BD80,479D20,47BBB0,47B4B0 and projection helpers on a generated diff --git a/docs/reverse-engineering.md b/docs/reverse-engineering.md index bed1121..185739e 100644 --- a/docs/reverse-engineering.md +++ b/docs/reverse-engineering.md @@ -19,6 +19,10 @@ probes and modern runtime checks are recorded separately. sphere kernel/original component probe, root-ray cancellation, retained physical re-registration/repeated Init and shared scripted/follow eye. Source-byte guards, port implementation and unresolved integration gates remain separate. +- `checkpoint/collision-grid-traversal.md`, `collision-contact-callbacks.md`, + `collision-body-probe.md`, `collision-integration-review.md`: REA/static grid, + contact material linkage/landing/friction and seven dispatcher/ten ordinary-body + component observations. Managed dispatcher is isolated; live capsule remains. - `save-format.md`: full supplied TSK layout, task query/assignment and activation gates. - `analysis/lab-progression.md`: CAM/MCA/AI dispatch, original lab chain and skip/camera formulas. - `analysis/scene-entities.md`: exact entity-resource preparation and contact/sprite evidence. diff --git a/docs/tasks.md b/docs/tasks.md index e76337d..07bd2b6 100644 --- a/docs/tasks.md +++ b/docs/tasks.md @@ -86,7 +86,12 @@ plan in verified chunks. Earlier priorities below are a backlog. the three route scenes, independently of raw control and camera debug switch. - [x] Retained physical re-registration/repeated Init chain and shared camera-eye handoff documented with byte guards and retained REA successes/provider gaps. -- [ ] Next: C4 grid/normal-callback/support/friction and dynamic response integration; +- [x] C4 static grid/retry dispatcher recovered and isolated managed component + compared against seven original fixtures; route material IDs and metadata gate. +- [x] Contact/landing/published-speed/friction contracts and actual special material + coverage recovered with REA. Ten isolated original body fixtures completed. +- [ ] Next: C4 ordinary body composition against ten numeric references, then + VR04 live integration; special contact policies/dynamic reclip before lab/outside; full Jimmy/base wrapper/helper traversal and shared viewport/DEFAULT handoff. Physical re-registration chain is recovered; full implementation/order remains. C6 source channel allocation/ diff --git a/scripts/test.sh b/scripts/test.sh index 7c034e6..c3d40ce 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -10,6 +10,7 @@ dotnet run --project tests/GamePort.DirectorTests -- ../Original dotnet run --project tests/GamePort.PatrolTests -- ../Original dotnet run --project tests/GamePort.SupportTests -- ../Original dotnet run --project tests/GamePort.SphereResponseTests +dotnet run --project tests/GamePort.StaticCollisionTests dotnet run --project tests/GamePort.CameraRayTests dotnet run --project tests/GamePort.InteractionTests -- ../Original dotnet run --project tests/GamePort.CheckpointTests -- ../Original diff --git a/src/GamePort/Assets/Mesh.cs b/src/GamePort/Assets/Mesh.cs index 4ec5512..331dd30 100644 --- a/src/GamePort/Assets/Mesh.cs +++ b/src/GamePort/Assets/Mesh.cs @@ -15,6 +15,7 @@ public struct MeshVertex(Vector3 position, Vector2 uv, Vector3 color) public sealed record Mesh(MeshVertex[] Vertices, uint[] Indices) { public MeshPolygonSource[] CollisionPolygons { get; init; } = []; + public bool HasCollisionMaterialIds { get; init; } public MeshDraw[] Draws { get; init; } = []; public bool HasExplicitDraws { get; init; } public Dictionary Textures { get; init; } = []; @@ -55,7 +56,9 @@ public sealed record Mesh(MeshVertex[] Vertices, uint[] Indices) ? polygonList.EnumerateArray().Select(p => new MeshPolygonSource(p.GetProperty("shapeId").GetInt32(), p.GetProperty("polygonIndex").GetInt32(), new Vector3(p.GetProperty("normal")[0].GetSingle(), p.GetProperty("normal")[1].GetSingle(), p.GetProperty("normal")[2].GetSingle()), - p.GetProperty("materialName").GetString(), shapeNames.GetValueOrDefault(p.GetProperty("shapeId").GetInt32()))).ToArray() : []; + p.GetProperty("materialName").GetString(), shapeNames.GetValueOrDefault(p.GetProperty("shapeId").GetInt32()), + p.TryGetProperty("materialId", out var materialId) && materialId.ValueKind == JsonValueKind.Number + ? materialId.GetInt32() : null)).ToArray() : []; if (collisionPolygons.Length != 0 && (collisionPolygons.Length != indices.Length / 3 || collisionPolygons.Any(p => !float.IsFinite(p.Normal.X + p.Normal.Y + p.Normal.Z)))) throw new InvalidDataException("Invalid source collision polygon metadata"); @@ -92,11 +95,15 @@ public sealed record Mesh(MeshVertex[] Vertices, uint[] Indices) for(var i=first;i p.TryGetProperty("materialId", out var id) + && id.ValueKind is JsonValueKind.Number or JsonValueKind.Null)}; } } -public readonly record struct MeshPolygonSource(int ShapeId, int PolygonIndex, Vector3 Normal, string? MaterialName, string? ShapeName = null) +public readonly record struct MeshPolygonSource(int ShapeId, int PolygonIndex, Vector3 Normal, string? MaterialName, + string? ShapeName = null, int? MaterialId = null) { public bool TerrainCollision => ShapeName?.StartsWith("nc", StringComparison.OrdinalIgnoreCase) != true; } diff --git a/src/GamePort/Game/LabSimulation.cs b/src/GamePort/Game/LabSimulation.cs index bb5acbc..62e8afe 100644 --- a/src/GamePort/Game/LabSimulation.cs +++ b/src/GamePort/Game/LabSimulation.cs @@ -325,8 +325,9 @@ public sealed class LabSimulation var wasGrounded = Grounded; var velocity = Velocity; // Keep the existing capsule/gravity adapter until C4 recovers Jimmy's - // pre-integration support/response. Source479DF7..479E54 can cancel - // gravity before a supported impulse; this adapter does not model that. + // support/response. Source479DF7..479E54 cancels gravity and vertical + // velocity when global geometry4F69E5 is disabled, not when grounded. + // This adapter does not model that separate source debug/global gate. var displacement = RecoveredMotion.Integrate(ref velocity, ref pendingImpulse, Vector3.UnitY * extraAirAcceleration, RecoveredMotion.Gravity, dt); var before = Position; diff --git a/src/GamePort/Game/OriginalCameraRay.cs b/src/GamePort/Game/OriginalCameraRay.cs index c9ac38d..c893de9 100644 --- a/src/GamePort/Game/OriginalCameraRay.cs +++ b/src/GamePort/Game/OriginalCameraRay.cs @@ -4,7 +4,7 @@ using GamePort.Assets; namespace GamePort.Game; public readonly record struct CameraRayPolygon(SupportTriangle Triangle, Vector3 StoredNormal, - string? ShapeName = null, string? MaterialName = null); + string? ShapeName = null, string? MaterialName = null, int? MaterialId = null); public readonly record struct CameraRayResult(Vector3 Eye, float Gain, SupportHit? Hit); /// @@ -77,7 +77,7 @@ public sealed class OriginalCameraRay if (a >= mesh.Vertices.Length || b >= mesh.Vertices.Length || c >= mesh.Vertices.Length) throw new InvalidDataException("Camera triangle index outside vertex table"); polygons[i] = new(new(mesh.Vertices[a].Position, mesh.Vertices[b].Position, mesh.Vertices[c].Position, - source.ShapeId, source.PolygonIndex), source.Normal, source.ShapeName, source.MaterialName); + source.ShapeId, source.PolygonIndex), source.Normal, source.ShapeName, source.MaterialName, source.MaterialId); } return new(polygons); } diff --git a/src/GamePort/Game/OriginalStaticCollision.cs b/src/GamePort/Game/OriginalStaticCollision.cs new file mode 100644 index 0000000..b551209 --- /dev/null +++ b/src/GamePort/Game/OriginalStaticCollision.cs @@ -0,0 +1,154 @@ +using System.Numerics; +using GamePort.Assets; + +namespace GamePort.Game; + +public sealed class StaticCollisionContext(float radius, float faceDistance = 130000) +{ + public SphereResponseState Nearest { get; internal set; } = new(faceDistance, radius, null); + public CameraRayPolygon? LastPolygon { get; internal set; } + public int Passes { get; internal set; } + public int TriangleTests { get; internal set; } +} + +public readonly record struct StaticCollisionMove(Vector3 Position, CameraRayPolygon? CallbackPolygon, bool Published); +public readonly record struct CollisionCells(int MinX, int MaxX, int MinZ, int MaxZ); + +/// +/// Source47B4B0/47BBB0 static dispatcher. Preserves cell/FIFO duplicates, mutable +/// candidate, shared nearest state and retries. Callers own normal callbacks, +/// integration, support and scene-wide state. See collision-grid-traversal.md. +/// +public sealed class OriginalStaticCollision +{ + private readonly Dictionary> walls = []; + private readonly Dictionary> all = []; + public int PolygonCount { get; } + public int WallPolygonCount { get; } + public bool HasSpecialPlayerContacts { get; } + + public OriginalStaticCollision(IEnumerable polygons) + { + var identities = new HashSet<(int, int)>(); + foreach (var polygon in polygons.OrderBy(p => p.Triangle.ShapeId).ThenBy(p => p.Triangle.PolygonId)) + { + if (polygon.ShapeName?.StartsWith("nc", StringComparison.OrdinalIgnoreCase) == true + || Checkpoint(polygon.MaterialName)) continue; + var t = polygon.Triangle; + Finite(t.A); Finite(t.B); Finite(t.C); Finite(polygon.StoredNormal); + if (!identities.Add((t.ShapeId, t.PolygonId))) + throw new InvalidDataException("Source static collision needs one triangle per polygon"); + var min = Vector3.Min(t.A, Vector3.Min(t.B, t.C)); + var max = Vector3.Max(t.A, Vector3.Max(t.B, t.C)); + foreach (var cell in Rectangle(new(Cell(min.X), Cell(max.X), Cell(min.Z), Cell(max.Z)))) + { + if (!all.TryGetValue(cell, out var support)) all.Add(cell, support = []); + support.Add(t); + if (polygon.StoredNormal.Y >= .7f) continue; + if (!walls.TryGetValue(cell, out var list)) walls.Add(cell, list = []); + list.Add(polygon); + } + PolygonCount++; + if (polygon.StoredNormal.Y < .7f) WallPolygonCount++; + if (polygon.StoredNormal.Y > -.7f && polygon.StoredNormal.Y < .7f + && polygon.MaterialId is >= 60 and <= 69 or >= 110 and <= 129 or 180) + HasSpecialPlayerContacts = true; + } + } + + public static OriginalStaticCollision FromRouteScene(Mesh mesh, string level) + { + ArgumentNullException.ThrowIfNull(mesh); + if (level is not ("LV1B" or "VR04" or "LEV1")) + throw new NotSupportedException("Original static game-filter recovery covers only the three route scenes"); + if (mesh.Indices.Length % 3 != 0 || mesh.CollisionPolygons.Length != mesh.Indices.Length / 3) + throw new InvalidDataException("Source static collision requires original polygon metadata"); + if (!mesh.HasCollisionMaterialIds) + throw new InvalidDataException("Source static collision requires material identities; prepare the scene again"); + return new(Enumerable.Range(0, mesh.CollisionPolygons.Length).Select(i => { + var p = mesh.CollisionPolygons[i]; + if (mesh.Indices[i * 3] >= mesh.Vertices.Length || mesh.Indices[i * 3 + 1] >= mesh.Vertices.Length + || mesh.Indices[i * 3 + 2] >= mesh.Vertices.Length) + throw new InvalidDataException("Collision triangle index outside vertex table"); + return new CameraRayPolygon(new(mesh.Vertices[mesh.Indices[i * 3]].Position, + mesh.Vertices[mesh.Indices[i * 3 + 1]].Position, mesh.Vertices[mesh.Indices[i * 3 + 2]].Position, + p.ShapeId, p.PolygonIndex), p.Normal, p.ShapeName, p.MaterialName, p.MaterialId); + })); + } + + public StaticCollisionMove Move(Vector3 previous, Vector3 delta, float radius, + StaticCollisionContext context, bool edges = true, bool lowerEdges = false, bool geometryEnabled = true) + { + Finite(previous); Finite(delta); + if (!float.IsFinite(radius) || radius <= 0) throw new ArgumentOutOfRangeException(nameof(radius)); + ArgumentNullException.ThrowIfNull(context); + // The source recurses with no explicit depth limit. This iterative form + // keeps the same state, and rejects paths outside the bounded contract + // instead of silently inventing a final collision position. + for (var retry = 0; retry < 256; retry++) + { + var length = OriginalBodySupport.QuickMagnitude(delta); + if (!lowerEdges && length < 1.1920928955078125e-7f) return new(previous, null, false); + context.Passes++; + var candidate = previous + delta; + var accepted = false; + foreach (var cell in Rectangle(Bounds(previous, candidate, radius + length))) + if (walls.TryGetValue(cell, out var polygons)) + foreach (var polygon in polygons) + { + if (!geometryEnabled) continue; + context.TriangleTests++; + var result = OriginalSphereResponse.Resolve(polygon.Triangle, polygon.StoredNormal, + previous, candidate, radius, context.Nearest, edges, lowerEdges); + if (result.Contact == SphereContact.None) continue; + candidate = result.Position; context.Nearest = result.State; + context.LastPolygon = polygon; accepted = true; + } + if (!accepted) return new(candidate, context.LastPolygon, true); + delta = candidate - previous; + } + throw new InvalidOperationException("Source collision retry exceeds the verified finite-motion contract"); + } + + /// 47C6E0 nearest reduction; equal hits retain cell/FIFO order. + public SupportHit? TraceSupport(Vector3 start, Vector3 end, bool twoSided = false) + { + Finite(start); Finite(end); + SupportHit? nearest = null; + var nearestDistance = OriginalBodySupport.QuickMagnitude(end - start); + foreach (var cell in Rectangle(new(Math.Min(Cell(start.X), Cell(end.X)), Math.Max(Cell(start.X), Cell(end.X)), + Math.Min(Cell(start.Z), Cell(end.Z)), Math.Max(Cell(start.Z), Cell(end.Z))))) + if (all.TryGetValue(cell, out var triangles)) + foreach (var triangle in triangles) + if (OriginalBodySupport.IntersectSegment(triangle, start, end, twoSided) is { } hit + && hit.Distance < nearestDistance) + { + nearest = hit; + nearestDistance = hit.Distance; + } + return nearest; + } + + /// 47B53A..47B62A: the Z upper bound intentionally uses MIN. + public static CollisionCells Bounds(Vector3 previous, Vector3 candidate, float expansion) => new( + Math.Min(Cell(previous.X - expansion), Cell(candidate.X - expansion)), + Math.Max(Cell(previous.X + expansion), Cell(candidate.X + expansion)), + Math.Min(Cell(previous.Z - expansion), Cell(candidate.Z - expansion)), + Math.Min(Cell(previous.Z + expansion), Cell(candidate.Z + expansion))); + + private static int Cell(float value) => OriginalCameraRay.CellCoordinate(value); + private static IEnumerable Rectangle(CollisionCells bounds) + { + for (var x = Math.Max(0, bounds.MinX); x <= Math.Min(259, bounds.MaxX); x++) + for (var z = Math.Max(0, bounds.MinZ); z <= Math.Min(259, bounds.MaxZ); z++) yield return 260 * x + z; + } + private static bool Checkpoint(string? value) => value != null + && (value.Equals("cstart", StringComparison.OrdinalIgnoreCase) + || value.Length == 7 && value.StartsWith("ccheck", StringComparison.OrdinalIgnoreCase) + && value[6] is >= '1' and <= '9'); + private static void Finite(Vector3 value) + { + if (!float.IsFinite(value.X) || !float.IsFinite(value.Y) || !float.IsFinite(value.Z)) + throw new ArgumentOutOfRangeException(nameof(value)); + } +} diff --git a/tests/GamePort.StaticCollisionTests/GamePort.StaticCollisionTests.csproj b/tests/GamePort.StaticCollisionTests/GamePort.StaticCollisionTests.csproj new file mode 100644 index 0000000..6c4ead0 --- /dev/null +++ b/tests/GamePort.StaticCollisionTests/GamePort.StaticCollisionTests.csproj @@ -0,0 +1,9 @@ + + Exenet10.0 + enableenable + false + + + + + diff --git a/tests/GamePort.StaticCollisionTests/Program.cs b/tests/GamePort.StaticCollisionTests/Program.cs new file mode 100644 index 0000000..a725c31 --- /dev/null +++ b/tests/GamePort.StaticCollisionTests/Program.cs @@ -0,0 +1,103 @@ +using System.Numerics; +using GamePort.Game; +using GamePort.Assets; +using System.Text.Json; + +void Check(bool value, string message) { if (!value) throw new Exception(message); } +void Near(Vector3 actual, Vector3 expected, string message) +{ Check(Vector3.Distance(actual, expected) < .002f, $"{message}: {actual} != {expected}"); } +var wall = new CameraRayPolygon(new(new(-100,-100,0),new(-100,100,0),new(100,100,0),0,0),Vector3.UnitZ); +var world = new OriginalStaticCollision([wall]); +(StaticCollisionMove Move, StaticCollisionContext Context) Run(OriginalStaticCollision scene, Vector3 before, Vector3 delta, + bool edges=true, bool lower=false) +{ + var context = new StaticCollisionContext(10); + return (scene.Move(before, delta, 10, context, edges, lower), context); +} +// References are copied-original dispatcher47B4B0 results, not just the kernel. +var face=Run(world,new(0,20,20),new(0,0,-15)); +Near(face.Move.Position,new(0,20,10),"source face retry"); +Check(face.Context.Passes==2 && face.Context.TriangleTests==4 && face.Move.CallbackPolygon==wall, + "source retry count, duplicate visits and final callback"); +Console.WriteLine("PASS original face retry/publication and per-cell duplicate visits"); +var edge=Run(world,new(105,100,20),new(0,0,-15)); +Near(edge.Move.Position,new(107.071068f,100,7.07106781f),"source edge retry"); +Check(edge.Context.Passes==2 && edge.Context.TriangleTests==2,"original edge retry statistics"); +var disabled=Run(world,new(105,100,20),new(0,0,-15),edges:false); +Near(disabled.Move.Position,new(105,100,5),"source disabled edge"); +Check(disabled.Context.Passes==1 && disabled.Context.TriangleTests==1 && disabled.Move.CallbackPolygon==null, + "disabled edges still scan and publish"); +Console.WriteLine("PASS original edge and edge-disabled dispatcher references"); +var zero=Run(world,new(0,20,20),Vector3.Zero); +Check(zero.Context.Passes==0 && !zero.Move.Published,"zero delta early exit"); +var forced=Run(world,new(0,20,20),Vector3.Zero,lower:true); +Check(forced.Context.Passes==1 && forced.Context.TriangleTests==2 && forced.Move.Published,"source member42C forced zero"); +Console.WriteLine("PASS zero-motion and forced-processing source boundaries"); +var side=new CameraRayPolygon(new(new(0,-100,-100),new(0,-100,100),new(0,100,100),1,0),Vector3.UnitX); +var corner=Run(new([wall,side]),new(20,20,20),new(-30,0,-30)); +Near(corner.Move.Position,new(5,20,10.000001f),"source corner/edge-below rejection"); +Check(corner.Context.Passes==2 && corner.Context.TriangleTests==8 && corner.Move.CallbackPolygon==wall, + "terminal normal belongs to last accepted polygon, not last tested polygon"); +Console.WriteLine("PASS original corner order and retained last polygon"); +var ceiling=new CameraRayPolygon(new(new(-100,100,-100),new(100,100,100),new(100,100,-100)), -Vector3.UnitY); +var under=Run(new([ceiling]),new(0,80,0),new(0,15,0)); +Near(under.Move.Position,new(0,90,0),"source ceiling retry"); +Check(under.Context.Passes==2 && under.Context.TriangleTests==8 && under.Move.CallbackPolygon==ceiling, + "source ceiling terminal callback"); +Console.WriteLine("PASS original ceiling dispatch reference"); +Check(OriginalStaticCollision.Bounds(Vector3.Zero,new(1000,0,1000),1010)==new CollisionCells(127,134,127,132), + "source asymmetric Z upper bound"); +var masked=new OriginalStaticCollision([wall with { ShapeName="ncwall" },side with { MaterialName="cstart" }]); +Check(masked.PolygonCount==0 && masked.TraceSupport(new(0,20,20),new(0,20,-20))==null,"source registration masks"); +Console.WriteLine("PASS asymmetric source bounds and registration exclusions"); +var floor=new CameraRayPolygon(new(new(-100,0,-100),new(100,0,-100),new(0,0,100),3,0),Vector3.UnitY); +var supported=new OriginalStaticCollision([floor]); +Check(supported.WallPolygonCount==0 && supported.TraceSupport(new(0,100,0),new(0,-100,0))?.ShapeId==3, + "general support grid remains separate from wall registration"); +Console.WriteLine("PASS separate general-grid nearest support query"); +var retained = new StaticCollisionContext(10); +world.Move(new(0,20,20),new(0,0,-15),10,retained); +var retainedNearest = retained.Nearest; +var withoutGeometry = world.Move(new(0,20,10),new(0,0,-15),10,retained,geometryEnabled:false); +Near(withoutGeometry.Position,new(0,20,-5),"disabled geometry publishes unclipped candidate"); +Check(withoutGeometry.CallbackPolygon==wall && retained.TriangleTests==4 && retained.Nearest==retainedNearest, + "disabled geometry preserves retained last-polygon callback without testing triangles"); +Console.WriteLine("PASS disabled geometry and retained callback state"); +Check(new OriginalStaticCollision([wall with {MaterialId=61}]).HasSpecialPlayerContacts, + "fence material archive ID must require special callback handling"); +Check(!new OriginalStaticCollision([wall with {MaterialId=17}]).HasSpecialPlayerContacts + && !new OriginalStaticCollision([ceiling with {MaterialId=61}]).HasSpecialPlayerContacts + && !new OriginalStaticCollision([wall with {MaterialId=61,ShapeName="ncwall"}]).HasSpecialPlayerContacts, + "ordinary material, ceiling370 and excluded shapes cannot trigger player374 special handling"); +var fixture = Path.Combine(Path.GetTempPath(), $"neutron-material-{Guid.NewGuid():N}.json"); +try +{ + var source = new { vertices=new[] {new[]{0,0,0},new[]{1,0,0},new[]{0,1,0}},indices=new[]{0,1,2}, + collisionPolygons=new[]{new{shapeId=0,polygonIndex=0,normal=new[]{0,0,1},materialName="fence",materialId=61}} }; + File.WriteAllText(fixture,JsonSerializer.Serialize(source)); + var loaded=Mesh.LoadSceneJson(fixture); + Check(loaded.HasCollisionMaterialIds && OriginalStaticCollision.FromRouteScene(loaded,"LV1B").HasSpecialPlayerContacts, + "prepared material identity must survive loader and source grid construction"); + File.WriteAllText(fixture,File.ReadAllText(fixture).Replace(",\"materialId\":61", "")); + loaded=Mesh.LoadSceneJson(fixture); + Check(!loaded.HasCollisionMaterialIds,"legacy metadata must remain distinguishable from unresolved material"); + try { OriginalStaticCollision.FromRouteScene(loaded,"LV1B"); throw new Exception("legacy metadata silently accepted"); } + catch(InvalidDataException) { } +} +finally { File.Delete(fixture); } +Console.WriteLine("PASS material policy IDs and legacy prepared-data rejection"); +foreach(var (level,directory,special) in new[]{("LV1B","level1b",true),("VR04","VR04",false),("LEV1","level1",true)}) +{ + var scene=Mesh.LoadSceneJson(Path.Combine("artifacts/extracted",directory,"scene.json")); + Check(OriginalStaticCollision.FromRouteScene(scene,level).HasSpecialPlayerContacts==special, + $"actual {level} special-contact coverage differs from original archive inventory"); +} +Console.WriteLine("PASS prepared lab/tutorial/outside contact coverage"); +var tiedFloor = floor with {Triangle=floor.Triangle with {ShapeId=4}}; +var supportTies = new OriginalStaticCollision([tiedFloor,floor]); +Check(supportTies.TraceSupport(new(0,100,0),new(0,-100,0))?.ShapeId==3, + "equal-distance support retains original shape/cell/FIFO order"); +Check(supportTies.TraceSupport(Vector3.Zero,Vector3.Zero)==null, + "zero-length support has no strictly nearer hit"); +Console.WriteLine("PASS support nearest ties and zero-length limit"); +Console.WriteLine("Static dispatcher:11 groups passed; source whole-body/scene integration remains separate."); diff --git a/tests/test_body_step_evidence.py b/tests/test_body_step_evidence.py new file mode 100644 index 0000000..b81f148 --- /dev/null +++ b/tests/test_body_step_evidence.py @@ -0,0 +1,21 @@ +from pathlib import Path +import sys +import unittest + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT/'tools/binary')) +from body_step_evidence import collect + + +class BodyStepEvidenceTests(unittest.TestCase): + def test_guarded_source_bodies_and_explicit_relocations(self): + report = collect(ROOT.parent/'Original') + self.assertEqual(len(report['bodies']), 15) + operands = report['probe_operands'] + self.assertEqual(len({item['va'] for item in operands}), len(operands)) + targets = {item['target'] for item in operands} + self.assertTrue({0x4f69e5, 0x5cfc7c, 0x695d54, 0x695d58}.issubset(targets)) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_collision_contact_callbacks.py b/tests/test_collision_contact_callbacks.py new file mode 100644 index 0000000..d103c96 --- /dev/null +++ b/tests/test_collision_contact_callbacks.py @@ -0,0 +1,110 @@ +"""Bounded contact/friction source signatures and state boundary fixtures.""" +from pathlib import Path +import sys +import unittest + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / 'tools/binary')) +from collision_contact_callbacks import ( + collect, normal_callback, NORMAL_Y_THRESHOLD, ceiling_projection, + player_material_actions, jimmy_contact_actions, friction_projection, landing_phases, +) + + +class CollisionContactCallbacksTests(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.report = collect(ROOT.parent / 'Original') + + def test_exact_source_identity_targets_and_complete_callbacks(self): + self.assertEqual(len(self.report['sites']), 50) + self.assertEqual(len(self.report['tables']), 20) + self.assertEqual(len(self.report['bodies']), 6) + self.assertFalse(any(b['raw_control_reference'] for b in self.report['bodies'])) + targets = {(t['owner'], t['slot']): t['target'] for t in self.report['tables']} + self.assertEqual(targets['Jimmy', '0x374'], '0x42a660') + self.assertEqual(targets['Object', '0x374'], '0x458890') + self.assertEqual(targets['Jimmy', '0x37c'], '0x472970') + + def test_ceiling_callback_dispatch_has_strict_threshold(self): + self.assertEqual(normal_callback(NORMAL_Y_THRESHOLD), 0x370) + self.assertEqual(normal_callback(NORMAL_Y_THRESHOLD-.00001), 0x370) + self.assertEqual(normal_callback(NORMAL_Y_THRESHOLD+.00001), 0x374) + + def test_ceiling_changes_only_independently_positive_y(self): + self.assertEqual(ceiling_projection((1, 5, 3, 7), (4, -2, 6, 8)), + ((1, 0, 3, 7), (4, -2, 6, 8))) + self.assertEqual(ceiling_projection((1, -5, 3, 7), (4, 2, 6, 8)), + ((1, -5, 3, 7), (4, 0, 6, 8))) + self.assertEqual(ceiling_projection((1, 0, 3, 7), (4, 0, 6, 8)), + ((1, 0, 3, 7), (4, 0, 6, 8))) + + def test_ordinary_material_is_not_generic_velocity_projection(self): + for elapsed in (0, 3, 4): + self.assertEqual(player_material_actions(17, elapsed, 0), ()) + self.assertEqual(player_material_actions(120, 3, 0), ()) + self.assertEqual(player_material_actions(120, 3.01, 1), ('complete160',)) + self.assertEqual(player_material_actions(119, 4, 1), ('complete164',)) + self.assertEqual(player_material_actions(60, 4, 0), ('fence_query',)) + self.assertEqual(player_material_actions(69, 4, 1), ()) + self.assertEqual(player_material_actions(180, 4, 0), ('ladder_query',)) + for material in (-1, 59, 70, 109, 130, 179, 181): + self.assertEqual(player_material_actions(material, 4, 0), ()) + + def test_friction_is_gated_by_support_published_speed_and_linear_motion(self): + velocity, angular = (10, -5, 20, 7), (2, -4, 6, 8) + self.assertEqual(friction_projection(velocity, angular, .8, .25), + ((8, -5, 16, 7), (1.6, -3.2, 4.8, 8))) + for options in ({'support': False}, {'published_speed': 2}, {'published_speed': -2}): + self.assertEqual(friction_projection(velocity, angular, .8, .25, **options), + (velocity, angular)) + # No planar motion still damps angular velocity when vertical motion exists. + self.assertEqual(friction_projection((0, 5, 0), (2, 4, 6), .8, .25), + ((0, 5, 0), (1.6, 3.2, 4.8))) + self.assertEqual(friction_projection((0, 0, 0), angular, .8, .25), + ((0, 0, 0), angular)) + # The source multiplier is not clamped to prevent reversal. + self.assertEqual(friction_projection((10, 5, 20), (2, 4, 6), 2, 1), + ((-10, 5, -20), (-2, -4, -6))) + + def test_no_selection_and_jetpack_bypass_extra_gadget_effects(self): + for selected in (-1, 3): + for mode in (0, 1): + self.assertEqual(jimmy_contact_actions(selected, 17, 4, mode), ()) + self.assertEqual(jimmy_contact_actions(selected, 17, 4, mode, + gadget7_active=True), ()) + self.assertEqual(jimmy_contact_actions(7, 17, 4, 0), ()) + self.assertEqual(jimmy_contact_actions(7, 17, 4, 0, gadget7_active=True), + ('gadget7_unresolved',)) + + def test_material_discriminator_is_linked_chunk_id_and_route_has_specials(self): + identity = self.report['material_identity'] + self.assertEqual(len(identity['dll_sites']), 11) + expected = { + 'level1b.omt': {61: 20, 62: 24, 63: 4, 120: 4, 121: 20, 122: 3, 180: 6}, + 'VR04.omt': {}, + 'level1.omt': {60: 62, 61: 38, 62: 26, 180: 20}, + } + for archive in identity['archives']: + # Every used material payload has the same trailing value; the + # distinct source callback policy comes from its linked chunk ID. + self.assertEqual({m['payload_trailing'] for m in archive['materials']}, {3}) + counts = {} + for polygon in archive['special_polygons']: + if polygon['potential374_wall']: + mid = polygon['material_id'] + counts[mid] = counts.get(mid, 0) + 1 + self.assertEqual(counts, expected[archive['name']]) + material = next(m for m in archive['materials'] if m['id'] == 0) + self.assertNotEqual(material['table_id_offset'], material['payload_offset']) + + def test_landing_callback_observes_old_velocity_and_support(self): + phases = landing_phases(False) + self.assertEqual(phases, ['root318', 'acceleration278_Y0', + 'landing37C_noop_for_Jimmy', 'velocity2C4_Y0', + 'support21C_true', 'shape34C', 'polygon33C']) + self.assertNotIn('landing37C_noop_for_Jimmy', landing_phases(True)) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_collision_dispatch.py b/tests/test_collision_dispatch.py new file mode 100644 index 0000000..4d5c5d5 --- /dev/null +++ b/tests/test_collision_dispatch.py @@ -0,0 +1,19 @@ +from pathlib import Path +import sys +import unittest +ROOT=Path(__file__).resolve().parents[1] +sys.path.insert(0,str(ROOT/'tools/binary')) +from collision_dispatch import collect + + +class DispatcherProbeTests(unittest.TestCase): + def test_source_callgraph_and_fixture_relocations(self): + report=collect(ROOT.parent/'Original') + self.assertEqual(len(report['bodies']),10) + operands=report['probe_operands'] + self.assertEqual(len({p['va'] for p in operands}),len(operands)) + self.assertTrue(any(p['target']==0x509B24 for p in operands)) + self.assertTrue(any(p['target']==0x695D4C for p in operands)) + + +if __name__=='__main__':unittest.main() diff --git a/tests/test_collision_grid_traversal.py b/tests/test_collision_grid_traversal.py new file mode 100644 index 0000000..486a03b --- /dev/null +++ b/tests/test_collision_grid_traversal.py @@ -0,0 +1,79 @@ +"""Static dispatcher source guards and independent ordering/state fixtures.""" +from pathlib import Path +import sys +import unittest + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / 'tools/binary')) +from collision_grid_traversal import ( + EPSILON, NearestProjection, append_registration, cell, cells, collect, + scan_projection, traversal_bounds, visits, +) + + +class CollisionGridTraversalTests(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.report = collect(ROOT.parent / 'Original') + + def test_source_retry_and_asymmetric_upper_bound_are_guarded(self): + sites = {s['name']: s for s in self.report['sites']} + self.assertEqual(sites['z_upper_uses_min']['bytes'], '663bf8897c2418ddd87c0489442418') + self.assertEqual(sites['retry_flag_branch']['bytes'], '8a44241384c00f8597000000') + self.assertEqual(sites['retry_call_same_dispatcher']['file_offset'], '0x7b877') + self.assertEqual(sites['wrapper_stores_last_polygon_and_retry']['bytes'], '89354c5d6900c60101') + bodies = {b['name']: b for b in self.report['bodies']} + self.assertEqual(bodies['static_dispatcher']['length'], 0x3D9) + self.assertEqual(self.report['constants']['0x4d5e40'], EPSILON) + self.assertAlmostEqual(self.report['constants']['0x4a3148'], -.7, places=7) + + def test_extent_and_z_upper_min_are_distinct_from_x_upper_max(self): + self.assertEqual(cell(0), 130) + self.assertEqual(cell(-65001), 0, 'Truncate toward zero before signed-short storage') + self.assertEqual(traversal_bounds((0,0,0), (0,0,500), 50, 500), (128,131,128,131)) + self.assertEqual(traversal_bounds((0,0,0), (500,0,0), 50, 500), (128,132,128,131)) + self.assertEqual(traversal_bounds((0,0,0), (0,0,-500), 50, 500), (128,131,127,130)) + + def test_inclusive_x_outer_z_inner_and_skipped_outside_cells(self): + self.assertEqual(cells((1,2,4,5)), [(1,4),(1,5),(2,4),(2,5)]) + self.assertEqual(cells((-1,1,258,260)), [(0,258),(0,259),(1,258),(1,259)]) + self.assertEqual(cells((2,1,0,1)), []) + + def test_polygon_only_per_cell_dedup_and_fifo_across_cells(self): + grid = {} + self.assertTrue(append_registration(grid, (1,2), 100, 20)) + self.assertFalse(append_registration(grid, (1,2), 100, 99)) + self.assertTrue(append_registration(grid, (1,2), 200, 20)) + self.assertTrue(append_registration(grid, (1,3), 100, 20)) + self.assertEqual(visits(grid, (1,1,2,3)), [ + ((1,2),(100,20)), ((1,2),(200,20)), ((1,3),(100,20)), + ]) + + def test_mutable_candidate_and_nearest_survive_duplicate_visits_and_retry(self): + grid = {(1,2): [(100,20),(200,20)], (1,3): [(100,20)]} + nearest = NearestProjection(130000, 10) + observed = [] + + def first_pass(xy, polygon, candidate, state): + observed.append((xy, polygon[0], candidate, state.face, state.last_polygon)) + self.assertIs(state, nearest) + if len(observed) == 1: + state.face = 3 + return (8,9,10), True + return candidate, False + + candidate, retry = scan_projection(grid, (1,1,2,3), (0,0,0), nearest, first_pass) + self.assertTrue(retry) + self.assertEqual(candidate, (8,9,10)) + self.assertEqual(observed[1][2:], ((8,9,10),3,100)) + self.assertEqual(observed[2][1], 100, 'A repeated cell visit is retained') + candidate, retry = scan_projection( + grid, (1,1,2,3), candidate, nearest, + lambda xy, polygon, current, state: (current, False)) + self.assertFalse(retry) + self.assertEqual((nearest.face, nearest.edge, nearest.last_polygon), (3,10,100)) + self.assertEqual(candidate, (8,9,10)) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_collision_material_identity.py b/tests/test_collision_material_identity.py new file mode 100644 index 0000000..e578862 --- /dev/null +++ b/tests/test_collision_material_identity.py @@ -0,0 +1,42 @@ +from pathlib import Path +from types import SimpleNamespace +import sys +import tempfile +import unittest +from unittest.mock import patch + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / 'tools/extractors')) +from omt import Entry, export_scene + + +class CollisionMaterialIdentityTests(unittest.TestCase): + def export(self, link, identity=61): + shape = dict(vertices=[(0, 0, 0), (1, 0, 0), (0, 1, 0)], normals=[], + polygons=[dict(corners=[dict(vertex=i, normal=0, uv=(0, 0)) for i in range(3)], + normal=(0, 0, 1), material=link)]) + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + database = SimpleNamespace(path=root/'input'/'fixture.omt', data=b'fixture', + entries=[Entry('3DSh', 0, 0, 0, 'wall'), Entry('3DMa', identity, 0, 0, 'fence')], + payload=lambda entry: b'') + with patch('omt.read_shape', return_value=shape), patch('omt.read_material', return_value={}): + return export_scene(database, root/'output')['collisionPolygons'][0] + + def test_archive_identity_is_preserved_independently_of_render_index(self): + polygon = self.export(dict(type='3DMa', id=61)) + self.assertEqual((polygon['materialId'], polygon['materialName']), (61, 'fence')) + + def test_null_missing_and_wrong_type_links_are_not_materials(self): + for link in (None, dict(type='3DMa', id=999), dict(type='3DSh', id=61)): + with self.subTest(link=link): + polygon = self.export(link) + self.assertIsNone(polygon['materialId']) + self.assertIsNone(polygon['materialName']) + + def test_callback_identity_is_a_signed_long(self): + self.assertEqual(self.export(dict(type='3DMa', id=0xffffffff), 0xffffffff)['materialId'], -1) + + +if __name__ == '__main__': + unittest.main() diff --git a/tools/binary/body_step_evidence.py b/tools/binary/body_step_evidence.py new file mode 100644 index 0000000..82271cc --- /dev/null +++ b/tools/binary/body_step_evidence.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +"""Read-only full body/support callgraph guards for the isolated component probe.""" +import argparse +import hashlib +import json +from pathlib import Path +import struct +from collision_dispatch import collect as dispatch_collect, POINTERS +from collision_response import header +from checkpoint_script_state import find_case, read_va +from pe_inspect import PE + +BODIES=( + ('body_step',0x479D20,0x47A32A,'5f4b05518bef5e5f0ecc3909ff0de0b43d2c7350c6beae0c4f797d3238a77fa1'), + ('friction',0x47A330,0x47A421,'3ac4d0268edb5fa4f5689a87fdc36759c12589caf76b2286b1817f2204a91155'), + ('support',0x47B890,0x47BBB0,'5901c9475092af33db8015b58416475e9fa2c527b9e8860e36c0b4cc0ff3f25d'), + ('support_query',0x47C6E0,0x47CA8B,'0f6127ef4e4bf7986ef195340002fbd97d3b6f1151377d053b1ad8d0c096cf57'), + ('support_triangle',0x469A10,0x469B70,'6acde1608be611364a84ae8dadaa2f2675231f5ee9612445e7cb5e375e5d4e77')) +GLOBALS=sorted(set((*POINTERS,0x48D920,0x4D6A08,0x5CFC00,0x5CFC04,0x5CFC08, + 0x695D49,0x695D5C,0x695D84,0x695D54,0x695D58,0x695D68,0x5CFC7C, + *range(0x5CFC40,0x5CFC70,4)))) + + +def collect(original): + report=dispatch_collect(original);pe=PE(find_case(Path(original),'Neutron.exe')) + for name,start,end,digest in BODIES: + body=read_va(pe,start,end-start) + if hashlib.sha256(body).hexdigest()!=digest:raise ValueError(f'Changed body {name}') + report['bodies'].append(dict(name=name,va=hex(start),file_offset=hex(pe.offset(start-pe.base)),length=end-start,sha256=digest)) + for target in GLOBALS: + value=struct.pack('supported;} +static int TC support(Body*b){return b->support;} +static int TC world(Body*b){return b->world;} +static int TC pairs(Body*b){return b->pairs;} +static int TC yes(Body*b){(void)b;return 1;} +static int TC no(Body*b){(void)b;return 0;} +static int TC prevent(Body*b){return b->prevent;} +static void TC set_supported(Body*b,int value){b->supported=value;} +static float TC radius(Body*b){return b->radius;} +static float TC factor(Body*b){return b->factor;} +static float TC speed(Body*b){return b->speed;} +static float TC friction(Body*b){return b->friction;} +static float TC scale(Body*b){return b->scale;} +#define GET(name,field) static Vec *TC name(Body*b,Vec*out){*out=b->field;return out;} +GET(position,position) GET(previous,previous) GET(velocity,velocity) GET(acceleration,acceleration) +GET(impulse,impulse) GET(angular,angular) GET(rotation,rotation) +#define SET(name,field) static void TC name(Body*b,Vec v){b->field=v;} +SET(set_position,position) SET(set_previous,previous) SET(set_velocity,velocity) SET(set_acceleration,acceleration) +#define XYZ(name,field) static void TC name(Body*b,float x,float y,float z){b->field.x=x;b->field.y=y;b->field.z=z;} +XYZ(position_xyz,position) XYZ(velocity_xyz,velocity) XYZ(acceleration_xyz,acceleration) +XYZ(impulse_xyz,impulse) XYZ(angular_xyz,angular) XYZ(anchor_xyz,anchor) +#define ADD(name,field) static void TC name(Body*b,float x,float y,float z){b->field.x+=x;b->field.y+=y;b->field.z+=z;} +ADD(add_velocity,velocity) ADD(add_angular,angular) ADD(rotate,rotation) +static void TC move(Body*b,Vec v){b->position.x+=v.x;b->position.y+=v.y;b->position.z+=v.z;} +static void TC landing(Body*b){b->landings++;b->landing_velocity=b->velocity.y;b->landing_supported=b->supported;} +static void TC pointer(Body*b,void*p){(void)b;(void)p;} +static void TC contact(Body*b,Vec normal,void*p){(void)b;(void)normal;(void)p;} +static uintptr_t table[0x500/4]; +static void TC missing(Body*b) { + (void)b;uintptr_t call=(uintptr_t)__builtin_return_address(0); + fprintf(stderr,"MISSING fixture virtual after sourceVA %08lx\n",(unsigned long)(call-(uintptr_t)mapped+0x400000)); + ExitProcess(2); +} +static Node sentinels[2][260*260]; +static unsigned char polygon[0x30],shape[0x90],corners[60]; +static Vec points[3]={{-1000,0,-1000,1},{1000,0,-1000,1},{0,0,1000,1}}; +static void setup(void) { + for(unsigned i=0;inext=s->previous=s; + *(Node**)AT((g?0x5cfc7c:0x509b24)+i*12)=s; + } + *(void**)(polygon+0x24)=corners;*(Vec*)(polygon+8)=(Vec){0,1,0,0}; + *(void**)(shape+0x68)=points; + for(unsigned i=0;i<3;i++)*(unsigned*)(corners+i*20)=i; + for(int x=127;x<=132;x++)for(int z=127;z<=132;z++) { + Node*s=&sentinels[1][260*x+z],*n=calloc(1,sizeof(Node));void**r=calloc(1,0x1c); + require(n&&r,"support fixture allocation");r[0]=polygon;r[1]=shape;n->value=r; + n->next=s;n->previous=s->previous;s->previous->next=n;s->previous=n; + } + *(Vec*)AT(0x5cfc00)=(Vec){0,-800,0,0}; +} +static Body initial(void) { + Body b={0};b.table=table;b.position=(Vec){0,75.9f,0,1};b.previous=b.position; + b.support=b.world=b.pairs=b.prevent=1;b.radius=60;b.factor=1.265f;b.friction=.8f;b.scale=.5f; + return b; +} +static void run(const char*name,Body b,int geometry) { + *(unsigned char*)AT(0x4f69e5)=geometry; + ((BodyStep)AT(0x479d20))(&b,1.0f/60); + printf("CASE %s root=%.9g,%.9g,%.9g velocity=%.9g,%.9g,%.9g acceleration=%.9g,%.9g,%.9g impulseY=%.9g angularY=%.9g grounded=%d landings=%u observedVy=%.9g observedSupport=%d\n", + name,b.position.x,b.position.y,b.position.z,b.velocity.x,b.velocity.y,b.velocity.z, + b.acceleration.x,b.acceleration.y,b.acceleration.z,b.impulse.y,b.angular.y,b.supported, + b.landings,b.landing_velocity,b.landing_supported); + require(isfinite(b.position.y)&&isfinite(b.velocity.y),"finite source body output"); +} +int main(void) { + setbuf(stdout,NULL);map_copy();setup();Body b=initial(); + run("floor_support",b,1); + b=initial();b.position.y=26;b.previous=b.position;run("spawn_settle",b,1); + b=initial();b.supported=1;b.impulse.y=550;b.acceleration.y=-264;run("pending_jump",b,1); + b=initial();b.position.y=100;b.previous=b.position;b.velocity.y=-200;run("fall_above_floor",b,1); + b=initial();b.position.y=76;b.previous=b.position;b.velocity.y=-200;run("fall_land",b,1); + b=initial();b.velocity=(Vec){100,0,50,0};b.angular.y=12;run("ground_friction",b,1); + b=initial();b.velocity=(Vec){100,0,50,0};b.angular.y=12;b.speed=100;run("published_speed",b,1); + b=initial();b.angular.y=12;run("stationary_angular",b,1); + b=initial();b.velocity.x=.125f;run("small_motion",b,1); + b=initial();b.velocity.y=200;b.acceleration.y=-264;run("geometry_disabled",b,0); + puts("BODY_COMPONENT_COMPLETE: copied479D20/support with synthetic virtual contracts");return 0; +} diff --git a/tools/binary/collision_contact_callbacks.py b/tools/binary/collision_contact_callbacks.py new file mode 100644 index 0000000..2145501 --- /dev/null +++ b/tools/binary/collision_contact_callbacks.py @@ -0,0 +1,275 @@ +#!/usr/bin/env python3 +"""Read-only contact callback, friction and publication evidence; bounded projections.""" +from __future__ import annotations +import argparse +import hashlib +import json +from pathlib import Path +import struct +import sys +from checkpoint_script_state import EXE_SHA256, find_case, read_va +from pe_inspect import PE + +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'extractors')) +from omt import Database, Reader, read_material, read_shape + +DLL_SHA256 = '3ec41ead011adf56387a6dbd4580e5b5a9721b5f8020c8a56420f42824354943' +DLL_SITES = ( + ('db_link_chunk', 0x10030070, '8b4424048b54240c89411c8b44240889410c89511089480c8b410c668b502066895122c20c00'), + ('header_id_offset_size', 0x1004659f, '8b4b288d54245852e8f4d302008b4b288d44245050e837d402008d4c2454518b4b28e82ad40200'), + ('header_record_insert', 0x10046635, '8b4e148d542450528b4104508d44243450e865190000'), + ('chunk_id_lookup', 0x10045b98, '8b4c24108b500c3bca7c068d44240ceb08897424048d4424048b003bc65e740a8b401083c00859'), + ('object_lookup_chunk', 0x1002df43, '55538bceff50488b3e55538bceff576c508bceff5774538be8'), + ('object_db_link_call', 0x1002e0a5, '8b4c24108b075355518bcfff5018'), + ('link_reads_fourcc_id', 0x100302ac, '8d4c2410518bcee8383704008d5424148bce52e8dc3604008b5c24108b6c2414'), + ('link_get_object', 0x100302e8, '8b0755538bcfff50148b4c2418894104'), + ('polygon_link_read', 0x10003f4f, '8d4424388bce50e8a5fe06008b4c243c51e910030000'), + ('polygon_material_set', 0x10004275, '8bcbe874010000'), + ('material_pointer_publish', 0x10004402, '8b44240485c08941047403ff4014c20400'), +) + +# Fixed signatures from independently reviewed original instructions. +SITES = ( + ('root_before_normal', 0x47b7b1, '89038b442440894b048953088943'), + ('normal_threshold', 0x47b7e3, 'd81d48314a00'), + ('normal_strict_positive_side', 0x47b7f9, 'f6c441751f'), + ('wall374', 0x47b80f, 'ff9774030000'), + ('ceiling370', 0x47b82e, 'ff9770030000'), + ('ceiling_velocity_read', 0x47269f, 'ff90bc020000'), + ('ceiling_velocity_strict', 0x4726c0, 'f6c4417526'), + ('ceiling_velocity_write', 0x4726e3, 'ff90c0020000'), + ('ceiling_accel_read', 0x4726f6, 'ff9270020000'), + ('ceiling_accel_strict', 0x472717, 'f6c4417525'), + ('ceiling_accel_write', 0x472734, 'ff9074020000'), + ('jimmy_gadget', 0x42a660, '66833d88054f0007'), + ('jimmy_common_player_forward', 0x42a70b, 'e830030100'), + ('base_guard', 0x458895, 'ff90d801000084c0742a8b4c'), + ('base378', 0x4588c3, 'ff9078030000'), + ('player_elapsed', 0x43aa4a, 'd98674070000d81da0e54800'), + ('player_metadata', 0x43aa69, '8b400485c074658b400c85c00f84520200008b'), + ('player_mode', 0x43aad5, '6683be04070000000f85f8040000'), + ('landing_root', 0x47bb32, 'ff9018030000'), + ('landing_acceleration', 0x47bb4b, 'ff9078020000'), + ('landing_previous_ground', 0x47bb51, 'a0495d690084c0750a'), + ('landing37c', 0x47bb5e, 'ff907c030000'), + ('landing_velocity', 0x47bb74, 'ff92c4020000'), + ('landing_support', 0x47bb7c, '6a018bceff921c020000'), + ('landing_shape', 0x47bb91, 'ff904c030000'), + ('landing_polygon', 0x47bba1, 'ff923c030000'), + ('friction_speed_read', 0x47a241, 'ff9268020000'), + ('friction_equal_zero', 0x47a24f, 'f6c4407440'), + ('friction_call', 0x47a25a, 'e8d1000000'), + ('friction_support', 0x47a344, 'ff901802000084c00f84ca000000'), + ('friction_coefficient', 0x47a356, 'ff9248020000'), + ('friction_magnitude', 0x47a38e, 'ff1504d14800d81d14d94800dfe0f6c441757b'), + ('friction_linear_add', 0x47a3cb, 'ff92cc020000'), + ('friction_angular_add', 0x47a416, 'ff92b8020000'), + ('speed_getter', 0x471b50, 'd98160010000c3'), + ('speed_setter', 0x471b60, '8b442404898160010000c20400'), + ('speed_publication', 0x437c22, '8b86080600008b16508bceff926c020000'), + ('small_motion_scale', 0x471a70, 'd98144010000c3'), + ('threshold_minus07', 0x4a3148, '333333bf'), + ('threshold_zero', 0x48d914, '00000000'), + ('threshold_point1', 0x48d920, 'cdcccc3d'), + ('threshold_3', 0x48e5a0, '00004040'), + ('ctor_ebx_zero', 0x46fc08, '33db'), + ('ctor208_false', 0x46fdbc, '538bcde8ac110000'), + ('ctor1c8_true', 0x46fdc4, '6a018bcde8d3110000'), + ('ctor1d0_true', 0x46fdcd, '6a018bcde8fa110000'), + ('ctor220_true', 0x46fdf0, '6a018bcde8c7120000'), + ('ctor228_false', 0x46fdf9, '538bcde8ef120000'), + ('ctor42c_false', 0x46ffb1, '889d2c040000'), + ('player208_true', 0x43740a, '578bcee85e9b0300'), +) + +BODY_HASHES = ( + ('ceiling370', 0x472690, 0xba, 'febfe9381b19074c41b229b314307c85f95710a35c7907935f76519052d4b50c'), + ('jimmy374', 0x42a660, 0xb4, 'd52831057c35afbdb73babff81857a6a3cfb2466f639b8be0a80e6300d386b0c'), + ('player374', 0x43aa40, 0x5a3, '2acd114eb62fe67490d9301bc8e68f196830be74eb9076f52f79111467344a78'), + ('base374', 0x458890, 0x3d, '250d34ac046749aa9e6d6e22968b1139a98be46d8f31cb2dda287ddc5c2c4b6f'), + ('friction', 0x47a330, 0xf1, '3ac4d0268edb5fa4f5689a87fdc36759c12589caf76b2286b1817f2204a91155'), + ('landing37c', 0x472970, 0x1, 'ae3f4619b0413d70d3004b9131c3752153074e45725be13b9a148978895e359e'), +) + +TABLES = ( + ('Object', 0x4d3154, 0x370, 0x472690), + ('Object', 0x4d3154, 0x374, 0x458890), + ('Object', 0x4d3154, 0x378, 0x472750), + ('Object', 0x4d3154, 0x37c, 0x472970), + ('Object', 0x4d3154, 0x230, 0x471a70), + ('Animated', 0x48fe1c, 0x370, 0x472690), + ('Animated', 0x48fe1c, 0x374, 0x458890), + ('Animated', 0x48fe1c, 0x378, 0x472750), + ('Animated', 0x48fe1c, 0x37c, 0x472970), + ('Animated', 0x48fe1c, 0x230, 0x471a70), + ('Player', 0x4af6c4, 0x370, 0x472690), + ('Player', 0x4af6c4, 0x374, 0x43aa40), + ('Player', 0x4af6c4, 0x378, 0x472750), + ('Player', 0x4af6c4, 0x37c, 0x472970), + ('Player', 0x4af6c4, 0x230, 0x471a70), + ('Jimmy', 0x4a373c, 0x370, 0x472690), + ('Jimmy', 0x4a373c, 0x374, 0x42a660), + ('Jimmy', 0x4a373c, 0x378, 0x472750), + ('Jimmy', 0x4a373c, 0x37c, 0x472970), + ('Jimmy', 0x4a373c, 0x230, 0x471a70), + ) + +NORMAL_Y_THRESHOLD = struct.unpack(' NORMAL_Y_THRESHOLD else 0x370 + + +def ceiling_projection(velocity, acceleration): + """472690 changes strictly positive Y only, retaining fourth components.""" + def clear_positive_y(v): + return (v[0], 0 if v[1] > 0 else v[1], *v[2:]) + return clear_positive_y(velocity), clear_positive_y(acceleration) + + +def player_material_actions(material_id, elapsed, mode): + """Classify bounded branches, without inventing unresolved class callbacks.""" + if elapsed <= 3: + return () + actions = [] + if 120 <= material_id <= 129: + actions.append('complete160') + if 110 <= material_id <= 119: + actions.append('complete164') + if mode == 0: + if 60 <= material_id <= 69: + actions.append('fence_query') + if material_id == 180: + actions.append('ladder_query') + return tuple(actions) + + +def jimmy_contact_actions(selected, material_id, elapsed, mode, *, gadget7_active=False): + """42A660 branch contract; selected -1/3 have no extra gadget behavior.""" + actions = player_material_actions(material_id, elapsed, mode) + if selected == 7 and gadget7_active: + actions += ('gadget7_unresolved',) + return actions + + +def friction_projection(velocity, angular, coefficient, delta, *, + support=True, published_speed=0): + """47A330 with caller's268 gate; excludes later small-motion suppression. + + Finite vectors only. Nonzero quick_magnitude gate is represented by any + nonzero component, not a substitute implementation of imported magnitude. + Python arithmetic is not an x87 bit-identity oracle. No clamp is added. + """ + if published_speed != 0 or not support or not any(velocity[:3]): + return tuple(velocity), tuple(angular) + k = coefficient * delta + return ((velocity[0] - velocity[0]*k, velocity[1], + velocity[2] - velocity[2]*k, *velocity[3:]), + tuple(x-x*k for x in angular[:3]) + tuple(angular[3:])) + + +def landing_phases(previous_support): + phases = ['root318', 'acceleration278_Y0'] + if not previous_support: + phases.append('landing37C_noop_for_Jimmy') + return phases + ['velocity2C4_Y0', 'support21C_true', 'shape34C', 'polygon33C'] + + +def material_identity_report(root): + """Original table IDs linked by source chunk metadata, not payload flags. + + Eligibility is registration+normal only, not evidence a gameplay trajectory + actually contacts a polygon. Preserve explicit source shape/polygon identity. + """ + root = Path(root) + dll = PE(find_case(root, 'OMT2.dll')) + if hashlib.sha256(dll.data).hexdigest() != DLL_SHA256: + raise ValueError('Unsupported original OMT2.dll') + anchors = [] + for name, va, expected in DLL_SITES: + if read_va(dll, va, len(bytes.fromhex(expected))).hex() != expected: + raise ValueError(f'Changed DLL instruction {name}') + anchors.append(dict(name=name, va=hex(va), file_offset=hex(dll.offset(va-dll.base)), bytes=expected)) + archives = [] + for filename in ('level1b.omt', 'VR04.omt', 'level1.omt'): + db = Database(find_case(root, 'omt/' + filename)) + # Record the identity's actual table byte offset, separate from payload. + r = Reader(db.data, db.table_offset) + id_offsets = {} + for _ in range(r.count(8)): + kind = r.take(4).decode('latin1') + for _ in range(r.count(13)): + offset = r.position + identity = r.u32() + r.take(8) + r.string() + id_offsets[kind, identity] = offset + materials = {e.id: e for e in db.entries if e.type == '3DMa'} + summaries = {} + special = [] + for entry in db.entries: + if entry.type != '3DSh': + continue + shape = read_shape(db.payload(entry)) + registered = not entry.name.lower().startswith('nc') + for index, polygon in enumerate(shape['polygons']): + link = polygon['material'] + if link is None or link['type'] != '3DMa' or link['id'] not in materials: + continue + identity = link['id'] + material = materials[identity] + item = summaries.setdefault(identity, dict(id=identity, name=material.name, + table_id_offset=id_offsets['3DMa', identity], payload_offset=material.offset, + payload_size=material.size, payload_sha256=hashlib.sha256(db.payload(material)).hexdigest(), + payload_trailing=read_material(db.payload(material))['trailing'], + polygons=0, registered_polygons=0, potential374_wall_polygons=0)) + item['polygons'] += 1 + item['registered_polygons'] += int(registered) + wall374 = registered and NORMAL_Y_THRESHOLD < polygon['normal'][1] < -NORMAL_Y_THRESHOLD + item['potential374_wall_polygons'] += int(wall374) + if player_material_actions(identity, 4, 0): + special.append(dict(shape_id=entry.id, shape_name=entry.name, + shape_payload_offset=entry.offset, polygon_index=index, + material_id=identity, normal=polygon['normal'], registered=registered, + potential374_wall=wall374)) + archives.append(dict(name=filename, sha256=hashlib.sha256(db.data).hexdigest(), + materials=list(summaries.values()), special_polygons=special)) + return dict(dll_sha256=DLL_SHA256, dll_sites=anchors, archives=archives, + discriminator='signed 3DMa database chunk ID at material+0C->chunk+8; not payload trailing') + + +def collect(root): + pe = PE(find_case(Path(root), 'Neutron.exe')) + if hashlib.sha256(pe.data).hexdigest() != EXE_SHA256: + raise ValueError('Unsupported original EXE') + sites = [] + for name, va, expected in SITES: + actual = read_va(pe, va, len(bytes.fromhex(expected))).hex() + if actual != expected: + raise ValueError(f'Changed instruction {name} at {va:#x}') + sites.append(dict(name=name, va=hex(va), file_offset=hex(pe.offset(va-pe.base)), bytes=actual)) + tables = [] + for owner, table, slot, target in TABLES: + if struct.unpack('=0&&x<260&&z>=0&&z<260,"fixture grid bounds"); + Node *s=&sentinels[260*x+z],*node=calloc(1,sizeof(Node)); + void **registration=calloc(1,0x1c);require(node&®istration,"fixture nodes"); + registration[0]=polygon[id];registration[1]=shape[id];node->value=registration; + node->next=s;node->previous=s->previous;s->previous->next=node;s->previous=node; + } +} +static void wall(void) { + add_triangle(0,(Vec){-100,-100,0,1},(Vec){-100,100,0,1},(Vec){100,100,0,1},(Vec){0,0,1,0}); +} +static void run(const char *name,Vec p,Vec delta,int edges,int lower) { + *(float*)AT(0x695d5c)=130000;*(float*)AT(0x5cfbe0)=10; + *(void**)AT(0x695d4c)=NULL;*(unsigned*)AT(0x695d70)=0;*(unsigned*)AT(0x695d78)=0; + callbacks=0;callback_polygon=NULL;memset(&callback_normal,0,sizeof(Vec));actor[0x42c]=lower; + ((Dispatch)AT(0x47b4b0))(actor,&p,delta,edges); + int last=callback_polygon==polygon[0]?0:callback_polygon==polygon[1]?1:-1; + printf("CASE %s root=%.9g,%.9g,%.9g passes=%u visits=%u callbacks=%u last=%d normal=%.9g,%.9g,%.9g\n", + name,p.x,p.y,p.z,*(unsigned*)AT(0x695d78),*(unsigned*)AT(0x695d70),callbacks,last, + callback_normal.x,callback_normal.y,callback_normal.z); + require(isfinite(p.x)&&isfinite(p.y)&&isfinite(p.z)&&callbacks<=1,"finite terminal publication"); +} +int main(void) { + setbuf(stdout,NULL);map_copy(); + uintptr_t table[0x400/4]={0};table[0x260/4]=(uintptr_t)radius; + table[0x370/4]=table[0x374/4]=(uintptr_t)normal;*(uintptr_t*)actor=(uintptr_t)table; + *(unsigned char*)AT(0x4f69e5)=1;*(unsigned char*)AT(0x695d46)=0; + empty_grid();wall(); + run("face_retry",(Vec){0,20,20,1},(Vec){0,0,-15,0},1,0); + run("edge_retry",(Vec){105,100,20,1},(Vec){0,0,-15,0},1,0); + run("edge_disabled",(Vec){105,100,20,1},(Vec){0,0,-15,0},0,0); + run("zero_delta",(Vec){0,20,20,1},(Vec){0,0,0,0},1,0); + run("forced_zero",(Vec){0,20,20,1},(Vec){0,0,0,0},1,1); + add_triangle(1,(Vec){0,-100,-100,1},(Vec){0,-100,100,1},(Vec){0,100,100,1},(Vec){1,0,0,0}); + run("corner_retry",(Vec){20,20,20,1},(Vec){-30,0,-30,0},1,0); + empty_grid();add_triangle(0,(Vec){-100,100,-100,1},(Vec){100,100,100,1},(Vec){100,100,-100,1},(Vec){0,-1,0,0}); + run("ceiling_retry",(Vec){0,80,0,1},(Vec){0,15,0,0},1,0); + puts("DISPATCH_COMPONENT_COMPLETE: copied source with synthetic grid/callback fixtures"); + return 0; +} diff --git a/tools/binary/collision_grid_traversal.py b/tools/binary/collision_grid_traversal.py new file mode 100644 index 0000000..1b18bca --- /dev/null +++ b/tools/binary/collision_grid_traversal.py @@ -0,0 +1,151 @@ +#!/usr/bin/env python3 +"""Read-only source grid/dispatcher anchors and bounded ordering fixtures.""" +from __future__ import annotations + +import argparse +from dataclasses import dataclass +import hashlib +import json +import math +from pathlib import Path +import struct + +from checkpoint_script_state import EXE_SHA256, find_case, read_va +from pe_inspect import PE + +BODIES = ( + ('static_dispatcher', 0x47B4B0, 0x47B889, 'da4ca56149636d5fc5059403a0ef81a0007c96972e3c12f2a8dedfa7568dd160'), + ('register_cell', 0x479800, 0x47991C, '078ce274b0135b7fb28ada2e1fb171817683d1435a96916e22253466956b0044'), + ('polygon_filter', 0x4797A0, 0x4797FD, 'a654906ad9c89a4744e78eee2a1745e59f9978ed4d28948d18e2a14abba2f63a'), + ('corner_accessor', 0x477F10, 0x477F5F, 'b5460f170b2315a462700d585b0626321186977a7bc192ede831a1e1ba60677c'), +) +SITES = ( + ('delta_magnitude', 0x47B4BB, 'ff1504d14800'), + ('force_static_processing_field', 0x47B4C9, '8a812c04000084c07515'), + ('epsilon_threshold', 0x47B4D7, 'd81d405e4d00dfe0f6c4010f8599030000'), + ('dispatcher_call_statistic', 0x47B4E8, '8b15785d6900'), + ('candidate_x', 0x47B507, 'd803d95c2434'), + ('candidate_y', 0x47B511, 'd84304d95c2438'), + ('candidate_z', 0x47B51C, 'd84308d95c243c'), + ('radius_getter', 0x47B523, 'ff9060020000'), + ('expansion_radius_plus_magnitude', 0x47B529, 'd9542420d844241c'), + ('x_upper_uses_max', 0x47B59B, '663bc78944241c7f04897c241c'), + ('z_upper_uses_min', 0x47B61B, '663bf8897c2418ddd87c0489442418'), + ('wall_grid_cell', 0x47B697, '8b048d249b5000'), + ('per_node_collision_gate', 0x47B6B2, '803de5694f0000'), + ('allow_lower_edges', 0x47B6F4, 'c705745d690001000000'), + ('forward_edges_flag', 0x47B6FE, '8b442470'), + ('call_polygon_wrapper', 0x47B72E, 'e87d040000'), + ('clear_lower_edges', 0x47B742, 'c705745d690000000000'), + ('next_fifo_node', 0x47B74C, '8b6d00'), + ('increment_z', 0x47B76A, '4241663b542418'), + ('increment_x', 0x47B77F, '4681c704010000'), + ('retry_flag_branch', 0x47B799, '8a44241384c00f8597000000'), + ('publish_candidate_x', 0x47B7B1, '8903'), + ('publish_candidate_yz', 0x47B7B7, '894b04895308'), + ('last_accepted_polygon', 0x47B7C0, '8b0d4c5d6900'), + ('last_normal_threshold', 0x47B7E3, 'd81d48314a00'), + ('normal_callback374', 0x47B80F, 'ff9774030000'), + ('normal_callback370', 0x47B82E, 'ff9770030000'), + ('retry_delta_x', 0x47B83C, 'd9442434d823'), + ('retry_call_same_dispatcher', 0x47B877, '5350e832fcffff'), + ('wrapper_stores_last_polygon_and_retry', 0x47BD65, '89354c5d6900c60101'), + ('physics_clear_last_polygon', 0x47A038, '891d4c5d6900'), + ('physics_face_distance130000', 0x47A03E, 'c7055c5d690000e8fd47'), + ('physics_edge_distance_radius', 0x47A062, 'd91de0fb5c00'), + ('dynamic_face_distance_minus1', 0x47AB4B, 'c7055c5d6900000080bf'), + ('dynamic_reclip_edges_false', 0x47B30B, '6a00'), + ('dynamic_reclip_dispatch', 0x47B364, 'e847010000'), + ('registration_checkpoint_filter', 0x4791C9, 'e8f2020000'), + ('registration_game_filter', 0x4791DB, 'e8c0050000'), + ('registration_polygon_order', 0x479479, '83c530'), + ('game_polygon_consumer', 0x4797EC, 'ff9234010000'), + ('cell_duplicate_polygon_only', 0x47985E, '8b55008b78083b17'), + ('cell_fifo_append', 0x47989F, '8958048947048b48048901'), + ('wall_normal_strict', 0x4798BD, 'd81d74d94800'), + ('corner_records_stride20', 0x477F1C, '8d04808b5124'), + ('shape_vertices_pointer', 0x477F29, '8b5168c1e00403c2'), +) + +SCALE = struct.unpack('= 0x80000000: + material_id -= 0x100000000 first_index = len(scene['indices']) first_vertex = len(scene['vertices']) for corner in poly['corners']: @@ -282,7 +289,8 @@ def export_scene(database: Database, output: Path): for i in range(1, len(poly['corners'])-1): scene['indices'].extend((first_vertex, first_vertex+i, first_vertex+i+1)) scene['collisionPolygons'].append({'shapeId': entry.id, 'polygonIndex': polygon_index, - 'normal': poly['normal'], 'materialName': material_names.get(poly['material']['id']) if poly['material'] else None}) + 'normal': poly['normal'], 'materialName': material_names[link['id']] if resolved_material else None, + 'materialId': material_id}) if len(poly['corners']) > 3: scene['warnings'].append(f'{entry.id}: polygon with {len(poly["corners"])} corners fan triangulated; concavity not validated') material = poly['material']['id'] if poly['material'] else -1